6 lines
1.2 MiB
6 lines
1.2 MiB
// Version 1.73.5 3d-force-graph - https://github.com/vasturiano/3d-force-graph
|
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).ForceGraph3D=e()}(this,(function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function e(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function i(t){for(var i=1;i<arguments.length;i++){var r=null!=arguments[i]?arguments[i]:{};i%2?n(Object(r),!0).forEach((function(n){e(t,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function r(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||function(e,n){if(e){if("string"==typeof e)return t(e,n);var i={}.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?t(e,n):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}!function(t,e){void 0===e&&(e={});var n=e.insertAt;if("undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===n&&i.firstChild?i.insertBefore(r,i.firstChild):i.appendChild(r),r.styleSheet?r.styleSheet.cssText=t:r.appendChild(document.createTextNode(t))}}(".graph-info-msg {\n top: 50%;\n width: 100%;\n text-align: center;\n color: lavender;\n opacity: 0.7;\n font-size: 22px;\n position: absolute;\n font-family: Sans-serif;\n}\n\n.scene-container .clickable {\n cursor: pointer;\n}\n\n.scene-container .grabbable {\n cursor: move;\n cursor: grab;\n cursor: -moz-grab;\n cursor: -webkit-grab;\n}\n\n.scene-container .grabbable:active {\n cursor: grabbing;\n cursor: -moz-grabbing;\n cursor: -webkit-grabbing;\n}");const s="170",a={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},o=0,l=1,h=2,u=3,c=0,d=1,p=2,f=100,m=101,g=102,_=200,v=201,y=202,x=203,b=204,S=205,M=206,T=207,w=208,E=209,A=210,R=211,C=212,N=213,P=214,I=0,L=1,U=2,D=3,O=4,F=5,B=6,z=7,k=301,G=302,V=306,H=1e3,j=1001,W=1002,q=1003,X=1004,$=1005,Y=1006,K=1007,Z=1008,Q=1009,J=1010,tt=1011,et=1012,nt=1013,it=1014,rt=1015,st=1016,at=1017,ot=1018,lt=1020,ht=35902,ut=1023,ct=1026,dt=1027,pt=1029,ft=1031,mt=1033,gt=33776,_t=33777,vt=33778,yt=33779,xt=35840,bt=35841,St=35842,Mt=35843,Tt=36196,wt=37492,Et=37496,At=37808,Rt=37809,Ct=37810,Nt=37811,Pt=37812,It=37813,Lt=37814,Ut=37815,Dt=37816,Ot=37817,Ft=37818,Bt=37819,zt=37820,kt=37821,Gt=36492,Vt=36494,Ht=36495,jt=36284,Wt=36285,qt=36286,Xt="",$t="srgb",Yt="srgb-linear",Kt="linear",Zt="srgb",Qt=7680,Jt=512,te=513,ee=514,ne=515,ie=516,re=517,se=518,ae=519,oe="300 es",le=2e3,he=2001;let ue=class{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const n=this._listeners;void 0===n[t]&&(n[t]=[]),-1===n[t].indexOf(e)&&n[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const n=this._listeners;return void 0!==n[t]&&-1!==n[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const n=this._listeners[t];if(void 0!==n){const t=n.indexOf(e);-1!==t&&n.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 n=e.slice(0);for(let e=0,i=n.length;e<i;e++)n[e].call(this,t);t.target=null}}};const ce=["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 de=1234567;const pe=Math.PI/180,fe=180/Math.PI;function me(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(ce[255&t]+ce[t>>8&255]+ce[t>>16&255]+ce[t>>24&255]+"-"+ce[255&e]+ce[e>>8&255]+"-"+ce[e>>16&15|64]+ce[e>>24&255]+"-"+ce[63&n|128]+ce[n>>8&255]+"-"+ce[n>>16&255]+ce[n>>24&255]+ce[255&i]+ce[i>>8&255]+ce[i>>16&255]+ce[i>>24&255]).toLowerCase()}function ge(t,e,n){return Math.max(e,Math.min(n,t))}function _e(t,e){return(t%e+e)%e}function ve(t,e,n){return(1-n)*t+n*e}function ye(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 xe(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 be={DEG2RAD:pe,RAD2DEG:fe,generateUUID:me,clamp:ge,euclideanModulo:_e,mapLinear:function(t,e,n,i,r){return i+(t-e)*(r-i)/(n-e)},inverseLerp:function(t,e,n){return t!==e?(n-t)/(e-t):0},lerp:ve,damp:function(t,e,n,i){return ve(t,e,1-Math.exp(-n*i))},pingpong:function(t,e=1){return e-Math.abs(_e(t,2*e)-e)},smoothstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-e))*t*(3-2*t)},smootherstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-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&&(de=t);let e=de+=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*pe},radToDeg:function(t){return t*fe},isPowerOfTwo:function(t){return!(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,n,i,r){const s=Math.cos,a=Math.sin,o=s(n/2),l=a(n/2),h=s((e+i)/2),u=a((e+i)/2),c=s((e-i)/2),d=a((e-i)/2),p=s((i-e)/2),f=a((i-e)/2);switch(r){case"XYX":t.set(o*u,l*c,l*d,o*h);break;case"YZY":t.set(l*d,o*u,l*c,o*h);break;case"ZXZ":t.set(l*c,l*d,o*u,o*h);break;case"XZX":t.set(o*u,l*f,l*p,o*h);break;case"YXY":t.set(l*p,o*u,l*f,o*h);break;case"ZYZ":t.set(l*f,l*p,o*u,o*h);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:xe,denormalize:ye};let Se=class t{constructor(e=0,n=0){t.prototype.isVector2=!0,this.x=e,this.y=n}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,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}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 n=this.dot(t)/e;return Math.acos(ge(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}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,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,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 n=Math.cos(e),i=Math.sin(e),r=this.x-t.x,s=this.y-t.y;return this.x=r*n-s*i+t.x,this.y=r*i+s*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},Me=class t{constructor(e,n,i,r,s,a,o,l,h){t.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==e&&this.set(e,n,i,r,s,a,o,l,h)}set(t,e,n,i,r,s,a,o,l){const h=this.elements;return h[0]=t,h[1]=i,h[2]=a,h[3]=e,h[4]=r,h[5]=o,h[6]=n,h[7]=s,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.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 n=t.elements,i=e.elements,r=this.elements,s=n[0],a=n[3],o=n[6],l=n[1],h=n[4],u=n[7],c=n[2],d=n[5],p=n[8],f=i[0],m=i[3],g=i[6],_=i[1],v=i[4],y=i[7],x=i[2],b=i[5],S=i[8];return r[0]=s*f+a*_+o*x,r[3]=s*m+a*v+o*b,r[6]=s*g+a*y+o*S,r[1]=l*f+h*_+u*x,r[4]=l*m+h*v+u*b,r[7]=l*g+h*y+u*S,r[2]=c*f+d*_+p*x,r[5]=c*m+d*v+p*b,r[8]=c*g+d*y+p*S,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],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],l=t[7],h=t[8];return e*s*h-e*a*l-n*r*h+n*a*o+i*r*l-i*s*o}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],l=t[7],h=t[8],u=h*s-a*l,c=a*o-h*r,d=l*r-s*o,p=e*u+n*c+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const f=1/p;return t[0]=u*f,t[1]=(i*l-h*n)*f,t[2]=(a*n-i*s)*f,t[3]=c*f,t[4]=(h*e-i*o)*f,t[5]=(i*r-a*e)*f,t[6]=d*f,t[7]=(n*o-l*e)*f,t[8]=(s*e-n*r)*f,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,n,i,r,s,a){const o=Math.cos(r),l=Math.sin(r);return this.set(n*o,n*l,-n*(o*s+l*a)+s+t,-i*l,i*o,-i*(-l*s+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(Te.makeScale(t,e)),this}rotate(t){return this.premultiply(Te.makeRotation(-t)),this}translate(t,e){return this.premultiply(Te.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),n=Math.sin(t);return this.set(e,-n,0,n,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,n=t.elements;for(let t=0;t<9;t++)if(e[t]!==n[t])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return(new this.constructor).fromArray(this.elements)}};const Te=new Me;function we(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}function Ee(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function Ae(){const t=Ee("canvas");return t.style.display="block",t}const Re={};function Ce(t){t in Re||(Re[t]=!0,console.warn(t))}const Ne={enabled:!0,workingColorSpace:Yt,spaces:{},convert:function(t,e,n){return!1!==this.enabled&&e!==n&&e&&n?(this.spaces[e].transfer===Zt&&(t.r=Pe(t.r),t.g=Pe(t.g),t.b=Pe(t.b)),this.spaces[e].primaries!==this.spaces[n].primaries&&(t.applyMatrix3(this.spaces[e].toXYZ),t.applyMatrix3(this.spaces[n].fromXYZ)),this.spaces[n].transfer===Zt&&(t.r=Ie(t.r),t.g=Ie(t.g),t.b=Ie(t.b)),t):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 this.spaces[t].primaries},getTransfer:function(t){return t===Xt?Kt:this.spaces[t].transfer},getLuminanceCoefficients:function(t,e=this.workingColorSpace){return t.fromArray(this.spaces[e].luminanceCoefficients)},define:function(t){Object.assign(this.spaces,t)},_getMatrix:function(t,e,n){return t.copy(this.spaces[e].toXYZ).multiply(this.spaces[n].fromXYZ)},_getDrawingBufferColorSpace:function(t){return this.spaces[t].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(t=this.workingColorSpace){return this.spaces[t].workingColorSpaceConfig.unpackColorSpace}};function Pe(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function Ie(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}const Le=[.64,.33,.3,.6,.15,.06],Ue=[.2126,.7152,.0722],De=[.3127,.329],Oe=(new Me).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Fe=(new Me).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);let Be;Ne.define({[Yt]:{primaries:Le,whitePoint:De,transfer:Kt,toXYZ:Oe,fromXYZ:Fe,luminanceCoefficients:Ue,workingColorSpaceConfig:{unpackColorSpace:$t},outputColorSpaceConfig:{drawingBufferColorSpace:$t}},[$t]:{primaries:Le,whitePoint:De,transfer:Zt,toXYZ:Oe,fromXYZ:Fe,luminanceCoefficients:Ue,outputColorSpaceConfig:{drawingBufferColorSpace:$t}}});let ze=class{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===Be&&(Be=Ee("canvas")),Be.width=t.width,Be.height=t.height;const n=Be.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),e=Be}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=Ee("canvas");e.width=t.width,e.height=t.height;const n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const i=n.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t<r.length;t++)r[t]=255*Pe(r[t]/255);return n.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*Pe(e[t]/255)):e[t]=Pe(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}},ke=0,Ge=class{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:ke++}),this.uuid=me(),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 n={uuid:this.uuid,url:""},i=this.data;if(null!==i){let t;if(Array.isArray(i)){t=[];for(let e=0,n=i.length;e<n;e++)i[e].isDataTexture?t.push(Ve(i[e].image)):t.push(Ve(i[e]))}else t=Ve(i);n.url=t}return e||(t.images[this.uuid]=n),n}};function Ve(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?ze.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 He=0,je=class t extends ue{constructor(e=t.DEFAULT_IMAGE,n=t.DEFAULT_MAPPING,i=1001,r=1001,s=1006,a=1008,o=1023,l=1009,h=t.DEFAULT_ANISOTROPY,u=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:He++}),this.uuid=me(),this.name="",this.source=new Ge(e),this.mipmaps=[],this.mapping=n,this.channel=0,this.wrapS=i,this.wrapT=r,this.magFilter=s,this.minFilter=a,this.anisotropy=h,this.format=o,this.internalFormat=null,this.type=l,this.offset=new Se(0,0),this.repeat=new Se(1,1),this.center=new Se(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Me,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 n={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&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(300!==this.mapping)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case H:t.x=t.x-Math.floor(t.x);break;case j:t.x=t.x<0?0:1;break;case W: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 H:t.y=t.y-Math.floor(t.y);break;case j:t.y=t.y<0?0:1;break;case W: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++}};je.DEFAULT_IMAGE=null,je.DEFAULT_MAPPING=300,je.DEFAULT_ANISOTROPY=1;let We=class t{constructor(e=0,n=0,i=0,r=1){t.prototype.isVector4=!0,this.x=e,this.y=n,this.z=i,this.w=r}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,n,i){return this.x=t,this.y=e,this.z=n,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,n=this.y,i=this.z,r=this.w,s=t.elements;return this.x=s[0]*e+s[4]*n+s[8]*i+s[12]*r,this.y=s[1]*e+s[5]*n+s[9]*i+s[13]*r,this.z=s[2]*e+s[6]*n+s[10]*i+s[14]*r,this.w=s[3]*e+s[7]*n+s[11]*i+s[15]*r,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,i,r;const s=.01,a=.1,o=t.elements,l=o[0],h=o[4],u=o[8],c=o[1],d=o[5],p=o[9],f=o[2],m=o[6],g=o[10];if(Math.abs(h-c)<s&&Math.abs(u-f)<s&&Math.abs(p-m)<s){if(Math.abs(h+c)<a&&Math.abs(u+f)<a&&Math.abs(p+m)<a&&Math.abs(l+d+g-3)<a)return this.set(1,0,0,0),this;e=Math.PI;const t=(l+1)/2,o=(d+1)/2,_=(g+1)/2,v=(h+c)/4,y=(u+f)/4,x=(p+m)/4;return t>o&&t>_?t<s?(n=0,i=.707106781,r=.707106781):(n=Math.sqrt(t),i=v/n,r=y/n):o>_?o<s?(n=.707106781,i=0,r=.707106781):(i=Math.sqrt(o),n=v/i,r=x/i):_<s?(n=.707106781,i=.707106781,r=0):(r=Math.sqrt(_),n=y/r,i=x/r),this.set(n,i,r,e),this}let _=Math.sqrt((m-p)*(m-p)+(u-f)*(u-f)+(c-h)*(c-h));return Math.abs(_)<.001&&(_=1),this.x=(m-p)/_,this.y=(u-f)/_,this.z=(c-h)/_,this.w=Math.acos((l+d+g-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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}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,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this.w=t.w+(e.w-t.w)*n,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}},qe=class extends ue{constructor(t=1,e=1,n={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new We(0,0,t,e),this.scissorTest=!1,this.viewport=new We(0,0,t,e);const i={width:t,height:e,depth:1};n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Y,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},n);const r=new je(i,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.colorSpace);r.flipY=!1,r.generateMipmaps=n.generateMipmaps,r.internalFormat=n.internalFormat,this.textures=[];const s=n.count;for(let t=0;t<s;t++)this.textures[t]=r.clone(),this.textures[t].isRenderTargetTexture=!0;this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.resolveDepthBuffer=n.resolveDepthBuffer,this.resolveStencilBuffer=n.resolveStencilBuffer,this.depthTexture=n.depthTexture,this.samples=n.samples}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}setSize(t,e,n=1){if(this.width!==t||this.height!==e||this.depth!==n){this.width=t,this.height=e,this.depth=n;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=n;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,n=t.textures.length;e<n;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 Ge(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"})}},Xe=class extends qe{constructor(t=1,e=1,n={}){super(t,e,n),this.isWebGLRenderTarget=!0}},$e=class extends je{constructor(t=null,e=1,n=1,i=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:n,depth:i},this.magFilter=q,this.minFilter=q,this.wrapR=j,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}};class Ye extends je{constructor(t=null,e=1,n=1,i=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:n,depth:i},this.magFilter=q,this.minFilter=q,this.wrapR=j,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}let Ke=class{constructor(t=0,e=0,n=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=n,this._w=i}static slerpFlat(t,e,n,i,r,s,a){let o=n[i+0],l=n[i+1],h=n[i+2],u=n[i+3];const c=r[s+0],d=r[s+1],p=r[s+2],f=r[s+3];if(0===a)return t[e+0]=o,t[e+1]=l,t[e+2]=h,void(t[e+3]=u);if(1===a)return t[e+0]=c,t[e+1]=d,t[e+2]=p,void(t[e+3]=f);if(u!==f||o!==c||l!==d||h!==p){let t=1-a;const e=o*c+l*d+h*p+u*f,n=e>=0?1:-1,i=1-e*e;if(i>Number.EPSILON){const r=Math.sqrt(i),s=Math.atan2(r,e*n);t=Math.sin(t*s)/r,a=Math.sin(a*s)/r}const r=a*n;if(o=o*t+c*r,l=l*t+d*r,h=h*t+p*r,u=u*t+f*r,t===1-a){const t=1/Math.sqrt(o*o+l*l+h*h+u*u);o*=t,l*=t,h*=t,u*=t}}t[e]=o,t[e+1]=l,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,n,i,r,s){const a=n[i],o=n[i+1],l=n[i+2],h=n[i+3],u=r[s],c=r[s+1],d=r[s+2],p=r[s+3];return t[e]=a*p+h*u+o*d-l*c,t[e+1]=o*p+h*c+l*u-a*d,t[e+2]=l*p+h*d+a*c-o*u,t[e+3]=h*p-a*u-o*c-l*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,n,i){return this._x=t,this._y=e,this._z=n,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 n=t._x,i=t._y,r=t._z,s=t._order,a=Math.cos,o=Math.sin,l=a(n/2),h=a(i/2),u=a(r/2),c=o(n/2),d=o(i/2),p=o(r/2);switch(s){case"XYZ":this._x=c*h*u+l*d*p,this._y=l*d*u-c*h*p,this._z=l*h*p+c*d*u,this._w=l*h*u-c*d*p;break;case"YXZ":this._x=c*h*u+l*d*p,this._y=l*d*u-c*h*p,this._z=l*h*p-c*d*u,this._w=l*h*u+c*d*p;break;case"ZXY":this._x=c*h*u-l*d*p,this._y=l*d*u+c*h*p,this._z=l*h*p+c*d*u,this._w=l*h*u-c*d*p;break;case"ZYX":this._x=c*h*u-l*d*p,this._y=l*d*u+c*h*p,this._z=l*h*p-c*d*u,this._w=l*h*u+c*d*p;break;case"YZX":this._x=c*h*u+l*d*p,this._y=l*d*u+c*h*p,this._z=l*h*p-c*d*u,this._w=l*h*u-c*d*p;break;case"XZY":this._x=c*h*u-l*d*p,this._y=l*d*u-c*h*p,this._z=l*h*p+c*d*u,this._w=l*h*u+c*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+s)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const n=e/2,i=Math.sin(n);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,n=e[0],i=e[4],r=e[8],s=e[1],a=e[5],o=e[9],l=e[2],h=e[6],u=e[10],c=n+a+u;if(c>0){const t=.5/Math.sqrt(c+1);this._w=.25/t,this._x=(h-o)*t,this._y=(r-l)*t,this._z=(s-i)*t}else if(n>a&&n>u){const t=2*Math.sqrt(1+n-a-u);this._w=(h-o)/t,this._x=.25*t,this._y=(i+s)/t,this._z=(r+l)/t}else if(a>u){const t=2*Math.sqrt(1+a-n-u);this._w=(r-l)/t,this._x=(i+s)/t,this._y=.25*t,this._z=(o+h)/t}else{const t=2*Math.sqrt(1+u-n-a);this._w=(s-i)/t,this._x=(r+l)/t,this._y=(o+h)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return n<Number.EPSILON?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(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=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(ge(this.dot(t),-1,1)))}rotateTowards(t,e){const n=this.angleTo(t);if(0===n)return this;const i=Math.min(1,e/n);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 n=t._x,i=t._y,r=t._z,s=t._w,a=e._x,o=e._y,l=e._z,h=e._w;return this._x=n*h+s*a+i*l-r*o,this._y=i*h+s*o+r*a-n*l,this._z=r*h+s*l+n*o-i*a,this._w=s*h-n*a-i*o-r*l,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const n=this._x,i=this._y,r=this._z,s=this._w;let a=s*t._w+n*t._x+i*t._y+r*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=s,this._x=n,this._y=i,this._z=r,this;const o=1-a*a;if(o<=Number.EPSILON){const t=1-e;return this._w=t*s+e*this._w,this._x=t*n+e*this._x,this._y=t*i+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const l=Math.sqrt(o),h=Math.atan2(l,a),u=Math.sin((1-e)*h)/l,c=Math.sin(e*h)/l;return this._w=s*u+this._w*c,this._x=n*u+this._x*c,this._y=i*u+this._y*c,this._z=r*u+this._z*c,this._onChangeCallback(),this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),r=Math.sqrt(n);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}},Ze=class t{constructor(e=0,n=0,i=0){t.prototype.isVector3=!0,this.x=e,this.y=n,this.z=i}set(t,e,n){return void 0===n&&(n=this.z),this.x=t,this.y=e,this.z=n,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(Je.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Je.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*i,this.y=r[1]*e+r[4]*n+r[7]*i,this.z=r[2]*e+r[5]*n+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,r=t.elements,s=1/(r[3]*e+r[7]*n+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*n+r[8]*i+r[12])*s,this.y=(r[1]*e+r[5]*n+r[9]*i+r[13])*s,this.z=(r[2]*e+r[6]*n+r[10]*i+r[14])*s,this}applyQuaternion(t){const e=this.x,n=this.y,i=this.z,r=t.x,s=t.y,a=t.z,o=t.w,l=2*(s*i-a*n),h=2*(a*e-r*i),u=2*(r*n-s*e);return this.x=e+o*l+s*u-a*h,this.y=n+o*h+a*l-r*u,this.z=i+o*u+r*h-s*l,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,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i,this.y=r[1]*e+r[5]*n+r[9]*i,this.z=r[2]*e+r[6]*n+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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}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,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const n=t.x,i=t.y,r=t.z,s=e.x,a=e.y,o=e.z;return this.x=i*o-r*a,this.y=r*s-n*o,this.z=n*a-i*s,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return Qe.copy(this).projectOnVector(t),this.sub(Qe)}reflect(t){return this.sub(Qe.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 n=this.dot(t)/e;return Math.acos(ge(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+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,n){const i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,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(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,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,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}};const Qe=new Ze,Je=new Ke;let tn=class{constructor(t=new Ze(1/0,1/0,1/0),e=new Ze(-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,n=t.length;e<n;e+=3)this.expandByPoint(nn.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,n=t.count;e<n;e++)this.expandByPoint(nn.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const n=nn.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(n),this.max.copy(t).add(n),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 n=t.geometry;if(void 0!==n){const i=n.getAttribute("position");if(!0===e&&void 0!==i&&!0!==t.isInstancedMesh)for(let e=0,n=i.count;e<n;e++)!0===t.isMesh?t.getVertexPosition(e,nn):nn.fromBufferAttribute(i,e),nn.applyMatrix4(t.matrixWorld),this.expandByPoint(nn);else void 0!==t.boundingBox?(null===t.boundingBox&&t.computeBoundingBox(),rn.copy(t.boundingBox)):(null===n.boundingBox&&n.computeBoundingBox(),rn.copy(n.boundingBox)),rn.applyMatrix4(t.matrixWorld),this.union(rn)}const i=t.children;for(let t=0,n=i.length;t<n;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,nn),nn.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(cn),dn.subVectors(this.max,cn),sn.subVectors(t.a,cn),an.subVectors(t.b,cn),on.subVectors(t.c,cn),ln.subVectors(an,sn),hn.subVectors(on,an),un.subVectors(sn,on);let e=[0,-ln.z,ln.y,0,-hn.z,hn.y,0,-un.z,un.y,ln.z,0,-ln.x,hn.z,0,-hn.x,un.z,0,-un.x,-ln.y,ln.x,0,-hn.y,hn.x,0,-un.y,un.x,0];return!!mn(e,sn,an,on,dn)&&(e=[1,0,0,0,1,0,0,0,1],!!mn(e,sn,an,on,dn)&&(pn.crossVectors(ln,hn),e=[pn.x,pn.y,pn.z],mn(e,sn,an,on,dn)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,nn).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(nn).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()||(en[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),en[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),en[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),en[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),en[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),en[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),en[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),en[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(en)),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 en=[new Ze,new Ze,new Ze,new Ze,new Ze,new Ze,new Ze,new Ze],nn=new Ze,rn=new tn,sn=new Ze,an=new Ze,on=new Ze,ln=new Ze,hn=new Ze,un=new Ze,cn=new Ze,dn=new Ze,pn=new Ze,fn=new Ze;function mn(t,e,n,i,r){for(let s=0,a=t.length-3;s<=a;s+=3){fn.fromArray(t,s);const a=r.x*Math.abs(fn.x)+r.y*Math.abs(fn.y)+r.z*Math.abs(fn.z),o=e.dot(fn),l=n.dot(fn),h=i.dot(fn);if(Math.max(-Math.max(o,l,h),Math.min(o,l,h))>a)return!1}return!0}const gn=new tn,_n=new Ze,vn=new Ze;let yn=class{constructor(t=new Ze,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 n=this.center;void 0!==e?n.copy(e):gn.setFromPoints(t).getCenter(n);let i=0;for(let e=0,r=t.length;e<r;e++)i=Math.max(i,n.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 n=this.center.distanceToSquared(t);return e.copy(t),n>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;_n.subVectors(t,this.center);const e=_n.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),n=.5*(t-this.radius);this.center.addScaledVector(_n,n/t),this.radius+=n}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):(vn.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(_n.copy(t.center).add(vn)),this.expandByPoint(_n.copy(t.center).sub(vn))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}};const xn=new Ze,bn=new Ze,Sn=new Ze,Mn=new Ze,Tn=new Ze,wn=new Ze,En=new Ze;let An=class{constructor(t=new Ze,e=new Ze(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,xn)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=xn.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(xn.copy(this.origin).addScaledVector(this.direction,e),xn.distanceToSquared(t))}distanceSqToSegment(t,e,n,i){bn.copy(t).add(e).multiplyScalar(.5),Sn.copy(e).sub(t).normalize(),Mn.copy(this.origin).sub(bn);const r=.5*t.distanceTo(e),s=-this.direction.dot(Sn),a=Mn.dot(this.direction),o=-Mn.dot(Sn),l=Mn.lengthSq(),h=Math.abs(1-s*s);let u,c,d,p;if(h>0)if(u=s*o-a,c=s*a-o,p=r*h,u>=0)if(c>=-p)if(c<=p){const t=1/h;u*=t,c*=t,d=u*(u+s*c+2*a)+c*(s*u+c+2*o)+l}else c=r,u=Math.max(0,-(s*c+a)),d=-u*u+c*(c+2*o)+l;else c=-r,u=Math.max(0,-(s*c+a)),d=-u*u+c*(c+2*o)+l;else c<=-p?(u=Math.max(0,-(-s*r+a)),c=u>0?-r:Math.min(Math.max(-r,-o),r),d=-u*u+c*(c+2*o)+l):c<=p?(u=0,c=Math.min(Math.max(-r,-o),r),d=c*(c+2*o)+l):(u=Math.max(0,-(s*r+a)),c=u>0?r:Math.min(Math.max(-r,-o),r),d=-u*u+c*(c+2*o)+l);else c=s>0?-r:r,u=Math.max(0,-(s*c+a)),d=-u*u+c*(c+2*o)+l;return n&&n.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(bn).addScaledVector(Sn,c),d}intersectSphere(t,e){xn.subVectors(t.center,this.origin);const n=xn.dot(this.direction),i=xn.dot(xn)-n*n,r=t.radius*t.radius;if(i>r)return null;const s=Math.sqrt(r-i),a=n-s,o=n+s;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){const n=this.distanceToPlane(t);return null===n?null:this.at(n,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 n,i,r,s,a,o;const l=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,c=this.origin;return l>=0?(n=(t.min.x-c.x)*l,i=(t.max.x-c.x)*l):(n=(t.max.x-c.x)*l,i=(t.min.x-c.x)*l),h>=0?(r=(t.min.y-c.y)*h,s=(t.max.y-c.y)*h):(r=(t.max.y-c.y)*h,s=(t.min.y-c.y)*h),n>s||r>i?null:((r>n||isNaN(n))&&(n=r),(s<i||isNaN(i))&&(i=s),u>=0?(a=(t.min.z-c.z)*u,o=(t.max.z-c.z)*u):(a=(t.max.z-c.z)*u,o=(t.min.z-c.z)*u),n>o||a>i?null:((a>n||n!=n)&&(n=a),(o<i||i!=i)&&(i=o),i<0?null:this.at(n>=0?n:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,xn)}intersectTriangle(t,e,n,i,r){Tn.subVectors(e,t),wn.subVectors(n,t),En.crossVectors(Tn,wn);let s,a=this.direction.dot(En);if(a>0){if(i)return null;s=1}else{if(!(a<0))return null;s=-1,a=-a}Mn.subVectors(this.origin,t);const o=s*this.direction.dot(wn.crossVectors(Mn,wn));if(o<0)return null;const l=s*this.direction.dot(Tn.cross(Mn));if(l<0)return null;if(o+l>a)return null;const h=-s*Mn.dot(En);return h<0?null:this.at(h/a,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)}},Rn=class t{constructor(e,n,i,r,s,a,o,l,h,u,c,d,p,f,m,g){t.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==e&&this.set(e,n,i,r,s,a,o,l,h,u,c,d,p,f,m,g)}set(t,e,n,i,r,s,a,o,l,h,u,c,d,p,f,m){const g=this.elements;return g[0]=t,g[4]=e,g[8]=n,g[12]=i,g[1]=r,g[5]=s,g[9]=a,g[13]=o,g[2]=l,g[6]=h,g[10]=u,g[14]=c,g[3]=d,g[7]=p,g[11]=f,g[15]=m,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 t).fromArray(this.elements)}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){const e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[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,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,n=t.elements,i=1/Cn.setFromMatrixColumn(t,0).length(),r=1/Cn.setFromMatrixColumn(t,1).length(),s=1/Cn.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*r,e[5]=n[5]*r,e[6]=n[6]*r,e[7]=0,e[8]=n[8]*s,e[9]=n[9]*s,e[10]=n[10]*s,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,n=t.x,i=t.y,r=t.z,s=Math.cos(n),a=Math.sin(n),o=Math.cos(i),l=Math.sin(i),h=Math.cos(r),u=Math.sin(r);if("XYZ"===t.order){const t=s*h,n=s*u,i=a*h,r=a*u;e[0]=o*h,e[4]=-o*u,e[8]=l,e[1]=n+i*l,e[5]=t-r*l,e[9]=-a*o,e[2]=r-t*l,e[6]=i+n*l,e[10]=s*o}else if("YXZ"===t.order){const t=o*h,n=o*u,i=l*h,r=l*u;e[0]=t+r*a,e[4]=i*a-n,e[8]=s*l,e[1]=s*u,e[5]=s*h,e[9]=-a,e[2]=n*a-i,e[6]=r+t*a,e[10]=s*o}else if("ZXY"===t.order){const t=o*h,n=o*u,i=l*h,r=l*u;e[0]=t-r*a,e[4]=-s*u,e[8]=i+n*a,e[1]=n+i*a,e[5]=s*h,e[9]=r-t*a,e[2]=-s*l,e[6]=a,e[10]=s*o}else if("ZYX"===t.order){const t=s*h,n=s*u,i=a*h,r=a*u;e[0]=o*h,e[4]=i*l-n,e[8]=t*l+r,e[1]=o*u,e[5]=r*l+t,e[9]=n*l-i,e[2]=-l,e[6]=a*o,e[10]=s*o}else if("YZX"===t.order){const t=s*o,n=s*l,i=a*o,r=a*l;e[0]=o*h,e[4]=r-t*u,e[8]=i*u+n,e[1]=u,e[5]=s*h,e[9]=-a*h,e[2]=-l*h,e[6]=n*u+i,e[10]=t-r*u}else if("XZY"===t.order){const t=s*o,n=s*l,i=a*o,r=a*l;e[0]=o*h,e[4]=-u,e[8]=l*h,e[1]=t*u+r,e[5]=s*h,e[9]=n*u-i,e[2]=i*u-n,e[6]=a*h,e[10]=r*u+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(Pn,t,In)}lookAt(t,e,n){const i=this.elements;return Dn.subVectors(t,e),0===Dn.lengthSq()&&(Dn.z=1),Dn.normalize(),Ln.crossVectors(n,Dn),0===Ln.lengthSq()&&(1===Math.abs(n.z)?Dn.x+=1e-4:Dn.z+=1e-4,Dn.normalize(),Ln.crossVectors(n,Dn)),Ln.normalize(),Un.crossVectors(Dn,Ln),i[0]=Ln.x,i[4]=Un.x,i[8]=Dn.x,i[1]=Ln.y,i[5]=Un.y,i[9]=Dn.y,i[2]=Ln.z,i[6]=Un.z,i[10]=Dn.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,r=this.elements,s=n[0],a=n[4],o=n[8],l=n[12],h=n[1],u=n[5],c=n[9],d=n[13],p=n[2],f=n[6],m=n[10],g=n[14],_=n[3],v=n[7],y=n[11],x=n[15],b=i[0],S=i[4],M=i[8],T=i[12],w=i[1],E=i[5],A=i[9],R=i[13],C=i[2],N=i[6],P=i[10],I=i[14],L=i[3],U=i[7],D=i[11],O=i[15];return r[0]=s*b+a*w+o*C+l*L,r[4]=s*S+a*E+o*N+l*U,r[8]=s*M+a*A+o*P+l*D,r[12]=s*T+a*R+o*I+l*O,r[1]=h*b+u*w+c*C+d*L,r[5]=h*S+u*E+c*N+d*U,r[9]=h*M+u*A+c*P+d*D,r[13]=h*T+u*R+c*I+d*O,r[2]=p*b+f*w+m*C+g*L,r[6]=p*S+f*E+m*N+g*U,r[10]=p*M+f*A+m*P+g*D,r[14]=p*T+f*R+m*I+g*O,r[3]=_*b+v*w+y*C+x*L,r[7]=_*S+v*E+y*N+x*U,r[11]=_*M+v*A+y*P+x*D,r[15]=_*T+v*R+y*I+x*O,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],n=t[4],i=t[8],r=t[12],s=t[1],a=t[5],o=t[9],l=t[13],h=t[2],u=t[6],c=t[10],d=t[14];return t[3]*(+r*o*u-i*l*u-r*a*c+n*l*c+i*a*d-n*o*d)+t[7]*(+e*o*d-e*l*c+r*s*c-i*s*d+i*l*h-r*o*h)+t[11]*(+e*l*u-e*a*d-r*s*u+n*s*d+r*a*h-n*l*h)+t[15]*(-i*a*h-e*o*u+e*a*c+i*s*u-n*s*c+n*o*h)}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,n){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]=n),this}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],l=t[7],h=t[8],u=t[9],c=t[10],d=t[11],p=t[12],f=t[13],m=t[14],g=t[15],_=u*m*l-f*c*l+f*o*d-a*m*d-u*o*g+a*c*g,v=p*c*l-h*m*l-p*o*d+s*m*d+h*o*g-s*c*g,y=h*f*l-p*u*l+p*a*d-s*f*d-h*a*g+s*u*g,x=p*u*o-h*f*o-p*a*c+s*f*c+h*a*m-s*u*m,b=e*_+n*v+i*y+r*x;if(0===b)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const S=1/b;return t[0]=_*S,t[1]=(f*c*r-u*m*r-f*i*d+n*m*d+u*i*g-n*c*g)*S,t[2]=(a*m*r-f*o*r+f*i*l-n*m*l-a*i*g+n*o*g)*S,t[3]=(u*o*r-a*c*r-u*i*l+n*c*l+a*i*d-n*o*d)*S,t[4]=v*S,t[5]=(h*m*r-p*c*r+p*i*d-e*m*d-h*i*g+e*c*g)*S,t[6]=(p*o*r-s*m*r-p*i*l+e*m*l+s*i*g-e*o*g)*S,t[7]=(s*c*r-h*o*r+h*i*l-e*c*l-s*i*d+e*o*d)*S,t[8]=y*S,t[9]=(p*u*r-h*f*r-p*n*d+e*f*d+h*n*g-e*u*g)*S,t[10]=(s*f*r-p*a*r+p*n*l-e*f*l-s*n*g+e*a*g)*S,t[11]=(h*a*r-s*u*r-h*n*l+e*u*l+s*n*d-e*a*d)*S,t[12]=x*S,t[13]=(h*f*i-p*u*i+p*n*c-e*f*c-h*n*m+e*u*m)*S,t[14]=(p*a*i-s*f*i-p*n*o+e*f*o+s*n*m-e*a*m)*S,t[15]=(s*u*i-h*a*i+h*n*o-e*u*o-s*n*c+e*a*c)*S,this}scale(t){const e=this.elements,n=t.x,i=t.y,r=t.z;return e[0]*=n,e[4]*=i,e[8]*=r,e[1]*=n,e[5]*=i,e[9]*=r,e[2]*=n,e[6]*=i,e[10]*=r,e[3]*=n,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],n=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,n,i))}makeTranslation(t,e,n){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,n,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const n=Math.cos(e),i=Math.sin(e),r=1-n,s=t.x,a=t.y,o=t.z,l=r*s,h=r*a;return this.set(l*s+n,l*a-i*o,l*o+i*a,0,l*a+i*o,h*a+n,h*o-i*s,0,l*o-i*a,h*o+i*s,r*o*o+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,i,r,s){return this.set(1,n,r,0,t,1,s,0,e,i,1,0,0,0,0,1),this}compose(t,e,n){const i=this.elements,r=e._x,s=e._y,a=e._z,o=e._w,l=r+r,h=s+s,u=a+a,c=r*l,d=r*h,p=r*u,f=s*h,m=s*u,g=a*u,_=o*l,v=o*h,y=o*u,x=n.x,b=n.y,S=n.z;return i[0]=(1-(f+g))*x,i[1]=(d+y)*x,i[2]=(p-v)*x,i[3]=0,i[4]=(d-y)*b,i[5]=(1-(c+g))*b,i[6]=(m+_)*b,i[7]=0,i[8]=(p+v)*S,i[9]=(m-_)*S,i[10]=(1-(c+f))*S,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,n){const i=this.elements;let r=Cn.set(i[0],i[1],i[2]).length();const s=Cn.set(i[4],i[5],i[6]).length(),a=Cn.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],Nn.copy(this);const o=1/r,l=1/s,h=1/a;return Nn.elements[0]*=o,Nn.elements[1]*=o,Nn.elements[2]*=o,Nn.elements[4]*=l,Nn.elements[5]*=l,Nn.elements[6]*=l,Nn.elements[8]*=h,Nn.elements[9]*=h,Nn.elements[10]*=h,e.setFromRotationMatrix(Nn),n.x=r,n.y=s,n.z=a,this}makePerspective(t,e,n,i,r,s,a=2e3){const o=this.elements,l=2*r/(e-t),h=2*r/(n-i),u=(e+t)/(e-t),c=(n+i)/(n-i);let d,p;if(a===le)d=-(s+r)/(s-r),p=-2*s*r/(s-r);else{if(a!==he)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);d=-s/(s-r),p=-s*r/(s-r)}return o[0]=l,o[4]=0,o[8]=u,o[12]=0,o[1]=0,o[5]=h,o[9]=c,o[13]=0,o[2]=0,o[6]=0,o[10]=d,o[14]=p,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(t,e,n,i,r,s,a=2e3){const o=this.elements,l=1/(e-t),h=1/(n-i),u=1/(s-r),c=(e+t)*l,d=(n+i)*h;let p,f;if(a===le)p=(s+r)*u,f=-2*u;else{if(a!==he)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);p=r*u,f=-1*u}return o[0]=2*l,o[4]=0,o[8]=0,o[12]=-c,o[1]=0,o[5]=2*h,o[9]=0,o[13]=-d,o[2]=0,o[6]=0,o[10]=f,o[14]=-p,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(t){const e=this.elements,n=t.elements;for(let t=0;t<16;t++)if(e[t]!==n[t])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}};const Cn=new Ze,Nn=new Rn,Pn=new Ze(0,0,0),In=new Ze(1,1,1),Ln=new Ze,Un=new Ze,Dn=new Ze,On=new Rn,Fn=new Ke;let Bn=class t{constructor(e=0,n=0,i=0,r=t.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=n,this._z=i,this._order=r}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,n,i=this._order){return this._x=t,this._y=e,this._z=n,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,n=!0){const i=t.elements,r=i[0],s=i[4],a=i[8],o=i[1],l=i[5],h=i[9],u=i[2],c=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(ge(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-s,r)):(this._x=Math.atan2(c,l),this._z=0);break;case"YXZ":this._x=Math.asin(-ge(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,l)):(this._y=Math.atan2(-u,r),this._z=0);break;case"ZXY":this._x=Math.asin(ge(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-s,l)):(this._y=0,this._z=Math.atan2(o,r));break;case"ZYX":this._y=Math.asin(-ge(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(c,d),this._z=Math.atan2(o,r)):(this._x=0,this._z=Math.atan2(-s,l));break;case"YZX":this._z=Math.asin(ge(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,r)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-ge(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(c,l),this._y=Math.atan2(a,r)):(this._x=Math.atan2(-h,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===n&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return On.makeRotationFromQuaternion(t),this.setFromRotationMatrix(On,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Fn.setFromEuler(this),this.setFromQuaternion(Fn,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}};Bn.DEFAULT_ORDER="XYZ";let zn=class{constructor(){this.mask=1}set(t){this.mask=1<<t>>>0}enable(t){this.mask|=1<<t}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t}disable(t){this.mask&=~(1<<t)}disableAll(){this.mask=0}test(t){return!!(this.mask&t.mask)}isEnabled(t){return!!(this.mask&1<<t)}},kn=0;const Gn=new Ze,Vn=new Ke,Hn=new Rn,jn=new Ze,Wn=new Ze,qn=new Ze,Xn=new Ke,$n=new Ze(1,0,0),Yn=new Ze(0,1,0),Kn=new Ze(0,0,1),Zn={type:"added"},Qn={type:"removed"},Jn={type:"childadded",child:null},ti={type:"childremoved",child:null};let ei=class t extends ue{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:kn++}),this.uuid=me(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=t.DEFAULT_UP.clone();const e=new Ze,n=new Bn,i=new Ke,r=new Ze(1,1,1);n._onChange((function(){i.setFromEuler(n,!1)})),i._onChange((function(){n.setFromQuaternion(i,void 0,!1)})),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:n},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:r},modelViewMatrix:{value:new Rn},normalMatrix:{value:new Me}}),this.matrix=new Rn,this.matrixWorld=new Rn,this.matrixAutoUpdate=t.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=t.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new zn,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 Vn.setFromAxisAngle(t,e),this.quaternion.multiply(Vn),this}rotateOnWorldAxis(t,e){return Vn.setFromAxisAngle(t,e),this.quaternion.premultiply(Vn),this}rotateX(t){return this.rotateOnAxis($n,t)}rotateY(t){return this.rotateOnAxis(Yn,t)}rotateZ(t){return this.rotateOnAxis(Kn,t)}translateOnAxis(t,e){return Gn.copy(t).applyQuaternion(this.quaternion),this.position.add(Gn.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis($n,t)}translateY(t){return this.translateOnAxis(Yn,t)}translateZ(t){return this.translateOnAxis(Kn,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(Hn.copy(this.matrixWorld).invert())}lookAt(t,e,n){t.isVector3?jn.copy(t):jn.set(t,e,n);const i=this.parent;this.updateWorldMatrix(!0,!1),Wn.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Hn.lookAt(Wn,jn,this.up):Hn.lookAt(jn,Wn,this.up),this.quaternion.setFromRotationMatrix(Hn),i&&(Hn.extractRotation(i.matrixWorld),Vn.setFromRotationMatrix(Hn),this.quaternion.premultiply(Vn.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(Zn),Jn.child=t,this.dispatchEvent(Jn),Jn.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(Qn),ti.child=t,this.dispatchEvent(ti),ti.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),Hn.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),Hn.multiply(t.parent.matrixWorld)),t.applyMatrix4(Hn),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Zn),Jn.child=t,this.dispatchEvent(Jn),Jn.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 n=0,i=this.children.length;n<i;n++){const i=this.children[n].getObjectByProperty(t,e);if(void 0!==i)return i}}getObjectsByProperty(t,e,n=[]){this[t]===e&&n.push(this);const i=this.children;for(let r=0,s=i.length;r<s;r++)i[r].getObjectsByProperty(t,e,n);return n}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Wn,t,qn),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Wn,Xn,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 n=0,i=e.length;n<i;n++)e[n].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let n=0,i=e.length;n<i;n++)e[n].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 n=0,i=e.length;n<i;n++){e[n].updateMatrixWorld(t)}}updateWorldMatrix(t,e){const n=this.parent;if(!0===t&&null!==n&&n.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,n=t.length;e<n;e++){t[e].updateWorldMatrix(!1,!0)}}}toJSON(t){const e=void 0===t||"string"==typeof t,n={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const i={};function r(e,n){return void 0===e[n.uuid]&&(e[n.uuid]=n.toJSON(t)),n.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 n=e.shapes;if(Array.isArray(n))for(let e=0,i=n.length;e<i;e++){const i=n[e];r(t.shapes,i)}else r(t.shapes,n)}}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 n=0,i=this.material.length;n<i;n++)e.push(r(t.materials,this.material[n]));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 n=this.animations[e];i.animations.push(r(t.animations,n))}}if(e){const e=s(t.geometries),i=s(t.materials),r=s(t.textures),a=s(t.images),o=s(t.shapes),l=s(t.skeletons),h=s(t.animations),u=s(t.nodes);e.length>0&&(n.geometries=e),i.length>0&&(n.materials=i),r.length>0&&(n.textures=r),a.length>0&&(n.images=a),o.length>0&&(n.shapes=o),l.length>0&&(n.skeletons=l),h.length>0&&(n.animations=h),u.length>0&&(n.nodes=u)}return n.object=i,n;function s(t){const e=[];for(const n in t){const i=t[n];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 n=t.children[e];this.add(n.clone())}return this}};ei.DEFAULT_UP=new Ze(0,1,0),ei.DEFAULT_MATRIX_AUTO_UPDATE=!0,ei.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const ni=new Ze,ii=new Ze,ri=new Ze,si=new Ze,ai=new Ze,oi=new Ze,li=new Ze,hi=new Ze,ui=new Ze,ci=new Ze,di=new We,pi=new We,fi=new We;let mi=class t{constructor(t=new Ze,e=new Ze,n=new Ze){this.a=t,this.b=e,this.c=n}static getNormal(t,e,n,i){i.subVectors(n,e),ni.subVectors(t,e),i.cross(ni);const r=i.lengthSq();return r>0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,n,i,r){ni.subVectors(i,e),ii.subVectors(n,e),ri.subVectors(t,e);const s=ni.dot(ni),a=ni.dot(ii),o=ni.dot(ri),l=ii.dot(ii),h=ii.dot(ri),u=s*l-a*a;if(0===u)return r.set(0,0,0),null;const c=1/u,d=(l*o-a*h)*c,p=(s*h-a*o)*c;return r.set(1-d-p,p,d)}static containsPoint(t,e,n,i){return null!==this.getBarycoord(t,e,n,i,si)&&(si.x>=0&&si.y>=0&&si.x+si.y<=1)}static getInterpolation(t,e,n,i,r,s,a,o){return null===this.getBarycoord(t,e,n,i,si)?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(r,si.x),o.addScaledVector(s,si.y),o.addScaledVector(a,si.z),o)}static getInterpolatedAttribute(t,e,n,i,r,s){return di.setScalar(0),pi.setScalar(0),fi.setScalar(0),di.fromBufferAttribute(t,e),pi.fromBufferAttribute(t,n),fi.fromBufferAttribute(t,i),s.setScalar(0),s.addScaledVector(di,r.x),s.addScaledVector(pi,r.y),s.addScaledVector(fi,r.z),s}static isFrontFacing(t,e,n,i){return ni.subVectors(n,e),ii.subVectors(t,e),ni.cross(ii).dot(i)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,i){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,n,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),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 ni.subVectors(this.c,this.b),ii.subVectors(this.a,this.b),.5*ni.cross(ii).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return t.getNormal(this.a,this.b,this.c,e)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,n){return t.getBarycoord(e,this.a,this.b,this.c,n)}getInterpolation(e,n,i,r,s){return t.getInterpolation(e,this.a,this.b,this.c,n,i,r,s)}containsPoint(e){return t.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return t.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const n=this.a,i=this.b,r=this.c;let s,a;ai.subVectors(i,n),oi.subVectors(r,n),hi.subVectors(t,n);const o=ai.dot(hi),l=oi.dot(hi);if(o<=0&&l<=0)return e.copy(n);ui.subVectors(t,i);const h=ai.dot(ui),u=oi.dot(ui);if(h>=0&&u<=h)return e.copy(i);const c=o*u-h*l;if(c<=0&&o>=0&&h<=0)return s=o/(o-h),e.copy(n).addScaledVector(ai,s);ci.subVectors(t,r);const d=ai.dot(ci),p=oi.dot(ci);if(p>=0&&d<=p)return e.copy(r);const f=d*l-o*p;if(f<=0&&l>=0&&p<=0)return a=l/(l-p),e.copy(n).addScaledVector(oi,a);const m=h*p-d*u;if(m<=0&&u-h>=0&&d-p>=0)return li.subVectors(r,i),a=(u-h)/(u-h+(d-p)),e.copy(i).addScaledVector(li,a);const g=1/(m+f+c);return s=f*g,a=c*g,e.copy(n).addScaledVector(ai,s).addScaledVector(oi,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}};const gi={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},_i={h:0,s:0,l:0},vi={h:0,s:0,l:0};function yi(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+6*(e-t)*(2/3-n):t}let xi=class{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(void 0===e&&void 0===n){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,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=$t){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,Ne.toWorkingColorSpace(this,e),this}setRGB(t,e,n,i=Ne.workingColorSpace){return this.r=t,this.g=e,this.b=n,Ne.toWorkingColorSpace(this,i),this}setHSL(t,e,n,i=Ne.workingColorSpace){if(t=_e(t,1),e=ge(e,0,1),n=ge(n,0,1),0===e)this.r=this.g=this.b=n;else{const i=n<=.5?n*(1+e):n+e-n*e,r=2*n-i;this.r=yi(r,i,t+1/3),this.g=yi(r,i,t),this.b=yi(r,i,t-1/3)}return Ne.toWorkingColorSpace(this,i),this}setStyle(t,e=$t){function n(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 s=i[1],a=i[2];switch(s){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(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(a))return n(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(a))return n(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 n=i[1],r=n.length;if(3===r)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(n,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=$t){const n=gi[t.toLowerCase()];return void 0!==n?this.setHex(n,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=Pe(t.r),this.g=Pe(t.g),this.b=Pe(t.b),this}copyLinearToSRGB(t){return this.r=Ie(t.r),this.g=Ie(t.g),this.b=Ie(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=$t){return Ne.fromWorkingColorSpace(bi.copy(this),t),65536*Math.round(ge(255*bi.r,0,255))+256*Math.round(ge(255*bi.g,0,255))+Math.round(ge(255*bi.b,0,255))}getHexString(t=$t){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=Ne.workingColorSpace){Ne.fromWorkingColorSpace(bi.copy(this),e);const n=bi.r,i=bi.g,r=bi.b,s=Math.max(n,i,r),a=Math.min(n,i,r);let o,l;const h=(a+s)/2;if(a===s)o=0,l=0;else{const t=s-a;switch(l=h<=.5?t/(s+a):t/(2-s-a),s){case n:o=(i-r)/t+(i<r?6:0);break;case i:o=(r-n)/t+2;break;case r:o=(n-i)/t+4}o/=6}return t.h=o,t.s=l,t.l=h,t}getRGB(t,e=Ne.workingColorSpace){return Ne.fromWorkingColorSpace(bi.copy(this),e),t.r=bi.r,t.g=bi.g,t.b=bi.b,t}getStyle(t=$t){Ne.fromWorkingColorSpace(bi.copy(this),t);const e=bi.r,n=bi.g,i=bi.b;return t!==$t?`color(${t} ${e.toFixed(3)} ${n.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*n)},${Math.round(255*i)})`}offsetHSL(t,e,n){return this.getHSL(_i),this.setHSL(_i.h+t,_i.s+e,_i.l+n)}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,n){return this.r=t.r+(e.r-t.r)*n,this.g=t.g+(e.g-t.g)*n,this.b=t.b+(e.b-t.b)*n,this}lerpHSL(t,e){this.getHSL(_i),t.getHSL(vi);const n=ve(_i.h,vi.h,e),i=ve(_i.s,vi.s,e),r=ve(_i.l,vi.l,e);return this.setHSL(n,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,n=this.g,i=this.b,r=t.elements;return this.r=r[0]*e+r[3]*n+r[6]*i,this.g=r[1]*e+r[4]*n+r[7]*i,this.b=r[2]*e+r[5]*n+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 bi=new xi;xi.NAMES=gi;let Si=0,Mi=class extends ue{static get type(){return"Material"}get type(){return this.constructor.type}set type(t){}constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:Si++}),this.uuid=me(),this.name="",this.blending=1,this.side=0,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=204,this.blendDst=205,this.blendEquation=f,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new xi(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Qt,this.stencilZFail=Qt,this.stencilZPass=Qt,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const n=t[e];if(void 0===n){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(n):i&&i.isVector3&&n&&n.isVector3?i.copy(n):this[e]=n: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 n={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}if(n.uuid=this.uuid,n.type=this.type,""!==this.name&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),void 0!==this.roughness&&(n.roughness=this.roughness),void 0!==this.metalness&&(n.metalness=this.metalness),void 0!==this.sheen&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(n.shininess=this.shininess),void 0!==this.clearcoat&&(n.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.dispersion&&(n.dispersion=this.dispersion),void 0!==this.iridescence&&(n.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(n.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(n.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(n.combine=this.combine)),void 0!==this.envMapRotation&&(n.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(n.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(n.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(n.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(n.size=this.size),null!==this.shadowSide&&(n.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(n.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(n.blending=this.blending),0!==this.side&&(n.side=this.side),!0===this.vertexColors&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),!0===this.transparent&&(n.transparent=!0),204!==this.blendSrc&&(n.blendSrc=this.blendSrc),205!==this.blendDst&&(n.blendDst=this.blendDst),this.blendEquation!==f&&(n.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(n.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(n.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(n.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(n.depthFunc=this.depthFunc),!1===this.depthTest&&(n.depthTest=this.depthTest),!1===this.depthWrite&&(n.depthWrite=this.depthWrite),!1===this.colorWrite&&(n.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(n.stencilWriteMask=this.stencilWriteMask),519!==this.stencilFunc&&(n.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(n.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Qt&&(n.stencilFail=this.stencilFail),this.stencilZFail!==Qt&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==Qt&&(n.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(n.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(n.rotation=this.rotation),!0===this.polygonOffset&&(n.polygonOffset=!0),0!==this.polygonOffsetFactor&&(n.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(n.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(n.linewidth=this.linewidth),void 0!==this.dashSize&&(n.dashSize=this.dashSize),void 0!==this.gapSize&&(n.gapSize=this.gapSize),void 0!==this.scale&&(n.scale=this.scale),!0===this.dithering&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),!0===this.alphaHash&&(n.alphaHash=!0),!0===this.alphaToCoverage&&(n.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(n.premultipliedAlpha=!0),!0===this.forceSinglePass&&(n.forceSinglePass=!0),!0===this.wireframe&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(n.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(n.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(n.flatShading=!0),!1===this.visible&&(n.visible=!1),!1===this.toneMapped&&(n.toneMapped=!1),!1===this.fog&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(n.textures=e),r.length>0&&(n.images=r)}return n}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 n=null;if(null!==e){const t=e.length;n=new Array(t);for(let i=0;i!==t;++i)n[i]=e[i].clone()}return this.clippingPlanes=n,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.")}},Ti=class extends Mi{static get type(){return"MeshBasicMaterial"}constructor(t){super(),this.isMeshBasicMaterial=!0,this.color=new xi(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 Bn,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 wi=new Ze,Ei=new Se;let Ai=class{constructor(t,e,n=!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=n,this.usage=35044,this.updateRanges=[],this.gpuType=rt,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let i=0,r=this.itemSize;i<r;i++)this.array[t+i]=e.array[n+i];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,n=this.count;e<n;e++)Ei.fromBufferAttribute(this,e),Ei.applyMatrix3(t),this.setXY(e,Ei.x,Ei.y);else if(3===this.itemSize)for(let e=0,n=this.count;e<n;e++)wi.fromBufferAttribute(this,e),wi.applyMatrix3(t),this.setXYZ(e,wi.x,wi.y,wi.z);return this}applyMatrix4(t){for(let e=0,n=this.count;e<n;e++)wi.fromBufferAttribute(this,e),wi.applyMatrix4(t),this.setXYZ(e,wi.x,wi.y,wi.z);return this}applyNormalMatrix(t){for(let e=0,n=this.count;e<n;e++)wi.fromBufferAttribute(this,e),wi.applyNormalMatrix(t),this.setXYZ(e,wi.x,wi.y,wi.z);return this}transformDirection(t){for(let e=0,n=this.count;e<n;e++)wi.fromBufferAttribute(this,e),wi.transformDirection(t),this.setXYZ(e,wi.x,wi.y,wi.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let n=this.array[t*this.itemSize+e];return this.normalized&&(n=ye(n,this.array)),n}setComponent(t,e,n){return this.normalized&&(n=xe(n,this.array)),this.array[t*this.itemSize+e]=n,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=ye(e,this.array)),e}setX(t,e){return this.normalized&&(e=xe(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=ye(e,this.array)),e}setY(t,e){return this.normalized&&(e=xe(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=ye(e,this.array)),e}setZ(t,e){return this.normalized&&(e=xe(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=ye(e,this.array)),e}setW(t,e){return this.normalized&&(e=xe(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,n){return t*=this.itemSize,this.normalized&&(e=xe(e,this.array),n=xe(n,this.array)),this.array[t+0]=e,this.array[t+1]=n,this}setXYZ(t,e,n,i){return t*=this.itemSize,this.normalized&&(e=xe(e,this.array),n=xe(n,this.array),i=xe(i,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=i,this}setXYZW(t,e,n,i,r){return t*=this.itemSize,this.normalized&&(e=xe(e,this.array),n=xe(n,this.array),i=xe(i,this.array),r=xe(r,this.array)),this.array[t+0]=e,this.array[t+1]=n,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),35044!==this.usage&&(t.usage=this.usage),t}},Ri=class extends Ai{constructor(t,e,n){super(new Uint16Array(t),e,n)}},Ci=class extends Ai{constructor(t,e,n){super(new Uint32Array(t),e,n)}},Ni=class extends Ai{constructor(t,e,n){super(new Float32Array(t),e,n)}},Pi=0;const Ii=new Rn,Li=new ei,Ui=new Ze,Di=new tn,Oi=new tn,Fi=new Ze;let Bi=class t extends ue{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:Pi++}),this.uuid=me(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(we(t)?Ci:Ri)(t,1):this.index=t,this}setIndirect(t){return this.indirect=t,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,n=0){this.groups.push({start:t,count:e,materialIndex:n})}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 n=this.attributes.normal;if(void 0!==n){const e=(new Me).getNormalMatrix(t);n.applyNormalMatrix(e),n.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 Ii.makeRotationFromQuaternion(t),this.applyMatrix4(Ii),this}rotateX(t){return Ii.makeRotationX(t),this.applyMatrix4(Ii),this}rotateY(t){return Ii.makeRotationY(t),this.applyMatrix4(Ii),this}rotateZ(t){return Ii.makeRotationZ(t),this.applyMatrix4(Ii),this}translate(t,e,n){return Ii.makeTranslation(t,e,n),this.applyMatrix4(Ii),this}scale(t,e,n){return Ii.makeScale(t,e,n),this.applyMatrix4(Ii),this}lookAt(t){return Li.lookAt(t),Li.updateMatrix(),this.applyMatrix4(Li.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Ui).negate(),this.translate(Ui.x,Ui.y,Ui.z),this}setFromPoints(t){const e=this.getAttribute("position");if(void 0===e){const e=[];for(let n=0,i=t.length;n<i;n++){const i=t[n];e.push(i.x,i.y,i.z||0)}this.setAttribute("position",new Ni(e,3))}else{for(let n=0,i=e.count;n<i;n++){const i=t[n];e.setXYZ(n,i.x,i.y,i.z||0)}t.length>e.count&&console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new tn);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 Ze(-1/0,-1/0,-1/0),new Ze(1/0,1/0,1/0));if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,n=e.length;t<n;t++){const n=e[t];Di.setFromBufferAttribute(n),this.morphTargetsRelative?(Fi.addVectors(this.boundingBox.min,Di.min),this.boundingBox.expandByPoint(Fi),Fi.addVectors(this.boundingBox.max,Di.max),this.boundingBox.expandByPoint(Fi)):(this.boundingBox.expandByPoint(Di.min),this.boundingBox.expandByPoint(Di.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 yn);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 Ze,1/0);if(t){const n=this.boundingSphere.center;if(Di.setFromBufferAttribute(t),e)for(let t=0,n=e.length;t<n;t++){const n=e[t];Oi.setFromBufferAttribute(n),this.morphTargetsRelative?(Fi.addVectors(Di.min,Oi.min),Di.expandByPoint(Fi),Fi.addVectors(Di.max,Oi.max),Di.expandByPoint(Fi)):(Di.expandByPoint(Oi.min),Di.expandByPoint(Oi.max))}Di.getCenter(n);let i=0;for(let e=0,r=t.count;e<r;e++)Fi.fromBufferAttribute(t,e),i=Math.max(i,n.distanceToSquared(Fi));if(e)for(let r=0,s=e.length;r<s;r++){const s=e[r],a=this.morphTargetsRelative;for(let e=0,r=s.count;e<r;e++)Fi.fromBufferAttribute(s,e),a&&(Ui.fromBufferAttribute(t,e),Fi.add(Ui)),i=Math.max(i,n.distanceToSquared(Fi))}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 n=e.position,i=e.normal,r=e.uv;!1===this.hasAttribute("tangent")&&this.setAttribute("tangent",new Ai(new Float32Array(4*n.count),4));const s=this.getAttribute("tangent"),a=[],o=[];for(let t=0;t<n.count;t++)a[t]=new Ze,o[t]=new Ze;const l=new Ze,h=new Ze,u=new Ze,c=new Se,d=new Se,p=new Se,f=new Ze,m=new Ze;function g(t,e,i){l.fromBufferAttribute(n,t),h.fromBufferAttribute(n,e),u.fromBufferAttribute(n,i),c.fromBufferAttribute(r,t),d.fromBufferAttribute(r,e),p.fromBufferAttribute(r,i),h.sub(l),u.sub(l),d.sub(c),p.sub(c);const s=1/(d.x*p.y-p.x*d.y);isFinite(s)&&(f.copy(h).multiplyScalar(p.y).addScaledVector(u,-d.y).multiplyScalar(s),m.copy(u).multiplyScalar(d.x).addScaledVector(h,-p.x).multiplyScalar(s),a[t].add(f),a[e].add(f),a[i].add(f),o[t].add(m),o[e].add(m),o[i].add(m))}let _=this.groups;0===_.length&&(_=[{start:0,count:t.count}]);for(let e=0,n=_.length;e<n;++e){const n=_[e],i=n.start;for(let e=i,r=i+n.count;e<r;e+=3)g(t.getX(e+0),t.getX(e+1),t.getX(e+2))}const v=new Ze,y=new Ze,x=new Ze,b=new Ze;function S(t){x.fromBufferAttribute(i,t),b.copy(x);const e=a[t];v.copy(e),v.sub(x.multiplyScalar(x.dot(e))).normalize(),y.crossVectors(b,e);const n=y.dot(o[t])<0?-1:1;s.setXYZW(t,v.x,v.y,v.z,n)}for(let e=0,n=_.length;e<n;++e){const n=_[e],i=n.start;for(let e=i,r=i+n.count;e<r;e+=3)S(t.getX(e+0)),S(t.getX(e+1)),S(t.getX(e+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let n=this.getAttribute("normal");if(void 0===n)n=new Ai(new Float32Array(3*e.count),3),this.setAttribute("normal",n);else for(let t=0,e=n.count;t<e;t++)n.setXYZ(t,0,0,0);const i=new Ze,r=new Ze,s=new Ze,a=new Ze,o=new Ze,l=new Ze,h=new Ze,u=new Ze;if(t)for(let c=0,d=t.count;c<d;c+=3){const d=t.getX(c+0),p=t.getX(c+1),f=t.getX(c+2);i.fromBufferAttribute(e,d),r.fromBufferAttribute(e,p),s.fromBufferAttribute(e,f),h.subVectors(s,r),u.subVectors(i,r),h.cross(u),a.fromBufferAttribute(n,d),o.fromBufferAttribute(n,p),l.fromBufferAttribute(n,f),a.add(h),o.add(h),l.add(h),n.setXYZ(d,a.x,a.y,a.z),n.setXYZ(p,o.x,o.y,o.z),n.setXYZ(f,l.x,l.y,l.z)}else for(let t=0,a=e.count;t<a;t+=3)i.fromBufferAttribute(e,t+0),r.fromBufferAttribute(e,t+1),s.fromBufferAttribute(e,t+2),h.subVectors(s,r),u.subVectors(i,r),h.cross(u),n.setXYZ(t+0,h.x,h.y,h.z),n.setXYZ(t+1,h.x,h.y,h.z),n.setXYZ(t+2,h.x,h.y,h.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,n=t.count;e<n;e++)Fi.fromBufferAttribute(t,e),Fi.normalize(),t.setXYZ(e,Fi.x,Fi.y,Fi.z)}toNonIndexed(){function e(t,e){const n=t.array,i=t.itemSize,r=t.normalized,s=new n.constructor(e.length*i);let a=0,o=0;for(let r=0,l=e.length;r<l;r++){a=t.isInterleavedBufferAttribute?e[r]*t.data.stride+t.offset:e[r]*i;for(let t=0;t<i;t++)s[o++]=n[a++]}return new Ai(s,i,r)}if(null===this.index)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const n=new t,i=this.index.array,r=this.attributes;for(const t in r){const s=e(r[t],i);n.setAttribute(t,s)}const s=this.morphAttributes;for(const t in s){const r=[],a=s[t];for(let t=0,n=a.length;t<n;t++){const n=e(a[t],i);r.push(n)}n.morphAttributes[t]=r}n.morphTargetsRelative=this.morphTargetsRelative;const a=this.groups;for(let t=0,e=a.length;t<e;t++){const e=a[t];n.addGroup(e.start,e.count,e.materialIndex)}return n}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 n in e)void 0!==e[n]&&(t[n]=e[n]);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 n=this.attributes;for(const e in n){const i=n[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let r=!1;for(const e in this.morphAttributes){const n=this.morphAttributes[e],s=[];for(let e=0,i=n.length;e<i;e++){const i=n[e];s.push(i.toJSON(t.data))}s.length>0&&(i[e]=s,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const s=this.groups;s.length>0&&(t.data.groups=JSON.parse(JSON.stringify(s)));const a=this.boundingSphere;return null!==a&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const n=t.index;null!==n&&this.setIndex(n.clone(e));const i=t.attributes;for(const t in i){const n=i[t];this.setAttribute(t,n.clone(e))}const r=t.morphAttributes;for(const t in r){const n=[],i=r[t];for(let t=0,r=i.length;t<r;t++)n.push(i[t].clone(e));this.morphAttributes[t]=n}this.morphTargetsRelative=t.morphTargetsRelative;const s=t.groups;for(let t=0,e=s.length;t<e;t++){const e=s[t];this.addGroup(e.start,e.count,e.materialIndex)}const a=t.boundingBox;null!==a&&(this.boundingBox=a.clone());const o=t.boundingSphere;return null!==o&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}};const zi=new Rn,ki=new An,Gi=new yn,Vi=new Ze,Hi=new Ze,ji=new Ze,Wi=new Ze,qi=new Ze,Xi=new Ze,$i=new Ze,Yi=new Ze;let Ki=class extends ei{constructor(t=new Bi,e=new Ti){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 n=t[e[0]];if(void 0!==n){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=n.length;t<e;t++){const e=n[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}getVertexPosition(t,e){const n=this.geometry,i=n.attributes.position,r=n.morphAttributes.position,s=n.morphTargetsRelative;e.fromBufferAttribute(i,t);const a=this.morphTargetInfluences;if(r&&a){Xi.set(0,0,0);for(let n=0,i=r.length;n<i;n++){const i=a[n],o=r[n];0!==i&&(qi.fromBufferAttribute(o,t),s?Xi.addScaledVector(qi,i):Xi.addScaledVector(qi.sub(e),i))}e.add(Xi)}return e}raycast(t,e){const n=this.geometry,i=this.material,r=this.matrixWorld;if(void 0!==i){if(null===n.boundingSphere&&n.computeBoundingSphere(),Gi.copy(n.boundingSphere),Gi.applyMatrix4(r),ki.copy(t.ray).recast(t.near),!1===Gi.containsPoint(ki.origin)){if(null===ki.intersectSphere(Gi,Vi))return;if(ki.origin.distanceToSquared(Vi)>(t.far-t.near)**2)return}zi.copy(r).invert(),ki.copy(t.ray).applyMatrix4(zi),null!==n.boundingBox&&!1===ki.intersectsBox(n.boundingBox)||this._computeIntersections(t,e,ki)}}_computeIntersections(t,e,n){let i;const r=this.geometry,s=this.material,a=r.index,o=r.attributes.position,l=r.attributes.uv,h=r.attributes.uv1,u=r.attributes.normal,c=r.groups,d=r.drawRange;if(null!==a)if(Array.isArray(s))for(let r=0,o=c.length;r<o;r++){const o=c[r],p=s[o.materialIndex];for(let r=Math.max(o.start,d.start),s=Math.min(a.count,Math.min(o.start+o.count,d.start+d.count));r<s;r+=3){i=Zi(this,p,t,n,l,h,u,a.getX(r),a.getX(r+1),a.getX(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=Zi(this,s,t,n,l,h,u,a.getX(r),a.getX(r+1),a.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}else if(void 0!==o)if(Array.isArray(s))for(let r=0,a=c.length;r<a;r++){const a=c[r],p=s[a.materialIndex];for(let r=Math.max(a.start,d.start),s=Math.min(o.count,Math.min(a.start+a.count,d.start+d.count));r<s;r+=3){i=Zi(this,p,t,n,l,h,u,r,r+1,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=Zi(this,s,t,n,l,h,u,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}}};function Zi(t,e,n,i,r,s,a,o,l,h){t.getVertexPosition(o,Hi),t.getVertexPosition(l,ji),t.getVertexPosition(h,Wi);const u=function(t,e,n,i,r,s,a,o){let l;if(l=1===e.side?i.intersectTriangle(a,s,r,!0,o):i.intersectTriangle(r,s,a,0===e.side,o),null===l)return null;Yi.copy(o),Yi.applyMatrix4(t.matrixWorld);const h=n.ray.origin.distanceTo(Yi);return h<n.near||h>n.far?null:{distance:h,point:Yi.clone(),object:t}}(t,e,n,i,Hi,ji,Wi,$i);if(u){const t=new Ze;mi.getBarycoord($i,Hi,ji,Wi,t),r&&(u.uv=mi.getInterpolatedAttribute(r,o,l,h,t,new Se)),s&&(u.uv1=mi.getInterpolatedAttribute(s,o,l,h,t,new Se)),a&&(u.normal=mi.getInterpolatedAttribute(a,o,l,h,t,new Ze),u.normal.dot(i.direction)>0&&u.normal.multiplyScalar(-1));const e={a:o,b:l,c:h,normal:new Ze,materialIndex:0};mi.getNormal(Hi,ji,Wi,e.normal),u.face=e,u.barycoord=t}return u}let Qi=class t extends Bi{constructor(t=1,e=1,n=1,i=1,r=1,s=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:n,widthSegments:i,heightSegments:r,depthSegments:s};const a=this;i=Math.floor(i),r=Math.floor(r),s=Math.floor(s);const o=[],l=[],h=[],u=[];let c=0,d=0;function p(t,e,n,i,r,s,p,f,m,g,_){const v=s/m,y=p/g,x=s/2,b=p/2,S=f/2,M=m+1,T=g+1;let w=0,E=0;const A=new Ze;for(let s=0;s<T;s++){const a=s*y-b;for(let o=0;o<M;o++){const c=o*v-x;A[t]=c*i,A[e]=a*r,A[n]=S,l.push(A.x,A.y,A.z),A[t]=0,A[e]=0,A[n]=f>0?1:-1,h.push(A.x,A.y,A.z),u.push(o/m),u.push(1-s/g),w+=1}}for(let t=0;t<g;t++)for(let e=0;e<m;e++){const n=c+e+M*t,i=c+e+M*(t+1),r=c+(e+1)+M*(t+1),s=c+(e+1)+M*t;o.push(n,i,s),o.push(i,r,s),E+=6}a.addGroup(d,E,_),d+=E,c+=w}p("z","y","x",-1,-1,n,e,t,s,r,0),p("z","y","x",1,-1,n,e,-t,s,r,1),p("x","z","y",1,1,t,n,e,i,s,2),p("x","z","y",1,-1,t,n,-e,i,s,3),p("x","y","z",1,-1,t,e,n,i,r,4),p("x","y","z",-1,-1,t,e,-n,i,r,5),this.setIndex(o),this.setAttribute("position",new Ni(l,3)),this.setAttribute("normal",new Ni(h,3)),this.setAttribute("uv",new Ni(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(e){return new t(e.width,e.height,e.depth,e.widthSegments,e.heightSegments,e.depthSegments)}};function Ji(t){const e={};for(const n in t){e[n]={};for(const i in t[n]){const r=t[n][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[n][i]=null):e[n][i]=r.clone():Array.isArray(r)?e[n][i]=r.slice():e[n][i]=r}}return e}function tr(t){const e={};for(let n=0;n<t.length;n++){const i=Ji(t[n]);for(const t in i)e[t]=i[t]}return e}function er(t){const e=t.getRenderTarget();return null===e?t.outputColorSpace:!0===e.isXRRenderTarget?e.texture.colorSpace:Ne.workingColorSpace}const nr={clone:Ji,merge:tr};let ir=class extends Mi{static get type(){return"ShaderMaterial"}constructor(t){super(),this.isShaderMaterial=!0,this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader="void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",this.fragmentShader="void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\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=Ji(t.uniforms),this.uniformsGroups=function(t){const e=[];for(let n=0;n<t.length;n++)e.push(t[n].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 n in this.uniforms){const i=this.uniforms[n].value;i&&i.isTexture?e.uniforms[n]={type:"t",value:i.toJSON(t).uuid}:i&&i.isColor?e.uniforms[n]={type:"c",value:i.getHex()}:i&&i.isVector2?e.uniforms[n]={type:"v2",value:i.toArray()}:i&&i.isVector3?e.uniforms[n]={type:"v3",value:i.toArray()}:i&&i.isVector4?e.uniforms[n]={type:"v4",value:i.toArray()}:i&&i.isMatrix3?e.uniforms[n]={type:"m3",value:i.toArray()}:i&&i.isMatrix4?e.uniforms[n]={type:"m4",value:i.toArray()}:e.uniforms[n]={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 n={};for(const t in this.extensions)!0===this.extensions[t]&&(n[t]=!0);return Object.keys(n).length>0&&(e.extensions=n),e}},rr=class extends ei{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Rn,this.projectionMatrix=new Rn,this.projectionMatrixInverse=new Rn,this.coordinateSystem=le}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 sr=new Ze,ar=new Se,or=new Se;let lr=class extends rr{constructor(t=50,e=1,n=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=n,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*fe*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*pe*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*fe*Math.atan(Math.tan(.5*pe*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,n){sr.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(sr.x,sr.y).multiplyScalar(-t/sr.z),sr.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(sr.x,sr.y).multiplyScalar(-t/sr.z)}getViewSize(t,e){return this.getViewBounds(t,ar,or),e.subVectors(or,ar)}setViewOffset(t,e,n,i,r,s){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=n,this.view.offsetY=i,this.view.width=r,this.view.height=s,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*pe*this.fov)/this.zoom,n=2*e,i=this.aspect*n,r=-.5*i;const s=this.view;if(null!==this.view&&this.view.enabled){const t=s.fullWidth,a=s.fullHeight;r+=s.offsetX*i/t,e-=s.offsetY*n/a,i*=s.width/t,n*=s.height/a}const a=this.filmOffset;0!==a&&(r+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-n,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 hr=-90;let ur=class extends ei{constructor(t,e,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new lr(hr,1,t,e);i.layers=this.layers,this.add(i);const r=new lr(hr,1,t,e);r.layers=this.layers,this.add(r);const s=new lr(hr,1,t,e);s.layers=this.layers,this.add(s);const a=new lr(hr,1,t,e);a.layers=this.layers,this.add(a);const o=new lr(hr,1,t,e);o.layers=this.layers,this.add(o);const l=new lr(hr,1,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[n,i,r,s,a,o]=e;for(const t of e)this.remove(t);if(t===le)n.up.set(0,1,0),n.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),s.up.set(0,0,1),s.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),o.up.set(0,1,0),o.lookAt(0,0,-1);else{if(t!==he)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);n.up.set(0,-1,0),n.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),s.up.set(0,0,-1),s.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),o.up.set(0,-1,0),o.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,s,a,o,l,h]=this.children,u=t.getRenderTarget(),c=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const f=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,t.setRenderTarget(n,0,i),t.render(e,r),t.setRenderTarget(n,1,i),t.render(e,s),t.setRenderTarget(n,2,i),t.render(e,a),t.setRenderTarget(n,3,i),t.render(e,o),t.setRenderTarget(n,4,i),t.render(e,l),n.texture.generateMipmaps=f,t.setRenderTarget(n,5,i),t.render(e,h),t.setRenderTarget(u,c,d),t.xr.enabled=p,n.texture.needsPMREMUpdate=!0}},cr=class extends je{constructor(t,e,n,i,r,s,a,o,l,h){super(t=void 0!==t?t:[],e=void 0!==e?e:k,n,i,r,s,a,o,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}},dr=class extends Xe{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const n={width:t,height:t,depth:1},i=[n,n,n,n,n,n];this.texture=new cr(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:Y}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 n={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 Qi(5,5,5),r=new ir({name:"CubemapFromEquirect",uniforms:Ji(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:1,blending:0});r.uniforms.tEquirect.value=e;const s=new Ki(i,r),a=e.minFilter;e.minFilter===Z&&(e.minFilter=Y);return new ur(1,10,this).update(t,s),e.minFilter=a,s.geometry.dispose(),s.material.dispose(),this}clear(t,e,n,i){const r=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,n,i);t.setRenderTarget(r)}};const pr=new Ze,fr=new Ze,mr=new Me;let gr=class{constructor(t=new Ze(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,n,i){return this.normal.set(t,e,n),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){const i=pr.subVectors(n,e).cross(fr.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 n=t.delta(pr),i=this.normal.dot(n);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(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<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 n=e||mr.getNormalMatrix(t),i=this.coplanarPoint(pr).applyMatrix4(t),r=this.normal.applyMatrix3(n).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 _r=new yn,vr=new Ze;let yr=class{constructor(t=new gr,e=new gr,n=new gr,i=new gr,r=new gr,s=new gr){this.planes=[t,e,n,i,r,s]}set(t,e,n,i,r,s){const a=this.planes;return a[0].copy(t),a[1].copy(e),a[2].copy(n),a[3].copy(i),a[4].copy(r),a[5].copy(s),this}copy(t){const e=this.planes;for(let n=0;n<6;n++)e[n].copy(t.planes[n]);return this}setFromProjectionMatrix(t,e=2e3){const n=this.planes,i=t.elements,r=i[0],s=i[1],a=i[2],o=i[3],l=i[4],h=i[5],u=i[6],c=i[7],d=i[8],p=i[9],f=i[10],m=i[11],g=i[12],_=i[13],v=i[14],y=i[15];if(n[0].setComponents(o-r,c-l,m-d,y-g).normalize(),n[1].setComponents(o+r,c+l,m+d,y+g).normalize(),n[2].setComponents(o+s,c+h,m+p,y+_).normalize(),n[3].setComponents(o-s,c-h,m-p,y-_).normalize(),n[4].setComponents(o-a,c-u,m-f,y-v).normalize(),e===le)n[5].setComponents(o+a,c+u,m+f,y+v).normalize();else{if(e!==he)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);n[5].setComponents(a,u,f,v).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),_r.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),_r.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(_r)}intersectsSprite(t){return _r.center.set(0,0,0),_r.radius=.7071067811865476,_r.applyMatrix4(t.matrixWorld),this.intersectsSphere(_r)}intersectsSphere(t){const e=this.planes,n=t.center,i=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(n)<i)return!1}return!0}intersectsBox(t){const e=this.planes;for(let n=0;n<6;n++){const i=e[n];if(vr.x=i.normal.x>0?t.max.x:t.min.x,vr.y=i.normal.y>0?t.max.y:t.min.y,vr.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(vr)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let n=0;n<6;n++)if(e[n].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}};function xr(){let t=null,e=!1,n=null,i=null;function r(e,s){n(e,s),i=t.requestAnimationFrame(r)}return{start:function(){!0!==e&&null!==n&&(i=t.requestAnimationFrame(r),e=!0)},stop:function(){t.cancelAnimationFrame(i),e=!1},setAnimationLoop:function(t){n=t},setContext:function(e){t=e}}}function br(t){const e=new WeakMap;return{get:function(t){return t.isInterleavedBufferAttribute&&(t=t.data),e.get(t)},remove:function(n){n.isInterleavedBufferAttribute&&(n=n.data);const i=e.get(n);i&&(t.deleteBuffer(i.buffer),e.delete(n))},update:function(n,i){if(n.isInterleavedBufferAttribute&&(n=n.data),n.isGLBufferAttribute){const t=e.get(n);return void((!t||t.version<n.version)&&e.set(n,{buffer:n.buffer,type:n.type,bytesPerElement:n.elementSize,version:n.version}))}const r=e.get(n);if(void 0===r)e.set(n,function(e,n){const i=e.array,r=e.usage,s=i.byteLength,a=t.createBuffer();let o;if(t.bindBuffer(n,a),t.bufferData(n,i,r),e.onUploadCallback(),i instanceof Float32Array)o=t.FLOAT;else if(i instanceof Uint16Array)o=e.isFloat16BufferAttribute?t.HALF_FLOAT:t.UNSIGNED_SHORT;else if(i instanceof Int16Array)o=t.SHORT;else if(i instanceof Uint32Array)o=t.UNSIGNED_INT;else if(i instanceof Int32Array)o=t.INT;else if(i instanceof Int8Array)o=t.BYTE;else if(i instanceof Uint8Array)o=t.UNSIGNED_BYTE;else{if(!(i instanceof Uint8ClampedArray))throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+i);o=t.UNSIGNED_BYTE}return{buffer:a,type:o,bytesPerElement:i.BYTES_PER_ELEMENT,version:e.version,size:s}}(n,i));else if(r.version<n.version){if(r.size!==n.array.byteLength)throw new Error("THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");!function(e,n,i){const r=n.array,s=n.updateRanges;if(t.bindBuffer(i,e),0===s.length)t.bufferSubData(i,0,r);else{s.sort(((t,e)=>t.start-e.start));let e=0;for(let t=1;t<s.length;t++){const n=s[e],i=s[t];i.start<=n.start+n.count+1?n.count=Math.max(n.count,i.start+i.count-n.start):(++e,s[e]=i)}s.length=e+1;for(let e=0,n=s.length;e<n;e++){const n=s[e];t.bufferSubData(i,n.start*r.BYTES_PER_ELEMENT,r,n.start,n.count)}n.clearUpdateRanges()}n.onUploadCallback()}(r.buffer,n,i),r.version=n.version}}}}class Sr extends Bi{constructor(t=1,e=1,n=1,i=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:n,heightSegments:i};const r=t/2,s=e/2,a=Math.floor(n),o=Math.floor(i),l=a+1,h=o+1,u=t/a,c=e/o,d=[],p=[],f=[],m=[];for(let t=0;t<h;t++){const e=t*c-s;for(let n=0;n<l;n++){const i=n*u-r;p.push(i,-e,0),f.push(0,0,1),m.push(n/a),m.push(1-t/o)}}for(let t=0;t<o;t++)for(let e=0;e<a;e++){const n=e+l*t,i=e+l*(t+1),r=e+1+l*(t+1),s=e+1+l*t;d.push(n,i,s),d.push(i,r,s)}this.setIndex(d),this.setAttribute("position",new Ni(p,3)),this.setAttribute("normal",new Ni(f,3)),this.setAttribute("uv",new Ni(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Sr(t.width,t.height,t.widthSegments,t.heightSegments)}}const Mr={alphahash_fragment:"#ifdef USE_ALPHAHASH\n\tif ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;\n#endif",alphahash_pars_fragment:"#ifdef USE_ALPHAHASH\n\tconst float ALPHA_HASH_SCALE = 0.05;\n\tfloat hash2D( vec2 value ) {\n\t\treturn fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );\n\t}\n\tfloat hash3D( vec3 value ) {\n\t\treturn hash2D( vec2( hash2D( value.xy ), value.z ) );\n\t}\n\tfloat getAlphaHashThreshold( vec3 position ) {\n\t\tfloat maxDeriv = max(\n\t\t\tlength( dFdx( position.xyz ) ),\n\t\t\tlength( dFdy( position.xyz ) )\n\t\t);\n\t\tfloat pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );\n\t\tvec2 pixScales = vec2(\n\t\t\texp2( floor( log2( pixScale ) ) ),\n\t\t\texp2( ceil( log2( pixScale ) ) )\n\t\t);\n\t\tvec2 alpha = vec2(\n\t\t\thash3D( floor( pixScales.x * position.xyz ) ),\n\t\t\thash3D( floor( pixScales.y * position.xyz ) )\n\t\t);\n\t\tfloat lerpFactor = fract( log2( pixScale ) );\n\t\tfloat x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;\n\t\tfloat a = min( lerpFactor, 1.0 - lerpFactor );\n\t\tvec3 cases = vec3(\n\t\t\tx * x / ( 2.0 * a * ( 1.0 - a ) ),\n\t\t\t( x - 0.5 * a ) / ( 1.0 - a ),\n\t\t\t1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )\n\t\t);\n\t\tfloat threshold = ( x < ( 1.0 - a ) )\n\t\t\t? ( ( x < a ) ? cases.x : cases.y )\n\t\t\t: cases.z;\n\t\treturn clamp( threshold , 1.0e-6, 1.0 );\n\t}\n#endif",alphamap_fragment:"#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;\n#endif",alphamap_pars_fragment:"#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",alphatest_fragment:"#ifdef USE_ALPHATEST\n\t#ifdef ALPHA_TO_COVERAGE\n\tdiffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );\n\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\tif ( diffuseColor.a < alphaTest ) discard;\n\t#endif\n#endif",alphatest_pars_fragment:"#ifdef USE_ALPHATEST\n\tuniform float alphaTest;\n#endif",aomap_fragment:"#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_CLEARCOAT ) \n\t\tclearcoatSpecularIndirect *= ambientOcclusion;\n\t#endif\n\t#if defined( USE_SHEEN ) \n\t\tsheenSpecularIndirect *= ambientOcclusion;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\t#endif\n#endif",aomap_pars_fragment:"#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif",batching_pars_vertex:"#ifdef USE_BATCHING\n\t#if ! defined( GL_ANGLE_multi_draw )\n\t#define gl_DrawID _gl_DrawID\n\tuniform int _gl_DrawID;\n\t#endif\n\tuniform highp sampler2D batchingTexture;\n\tuniform highp usampler2D batchingIdTexture;\n\tmat4 getBatchingMatrix( const in float i ) {\n\t\tint size = textureSize( batchingTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n\tfloat getIndirectIndex( const in int i ) {\n\t\tint size = textureSize( batchingIdTexture, 0 ).x;\n\t\tint x = i % size;\n\t\tint y = i / size;\n\t\treturn float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );\n\t}\n#endif\n#ifdef USE_BATCHING_COLOR\n\tuniform sampler2D batchingColorTexture;\n\tvec3 getBatchingColor( const in float i ) {\n\t\tint size = textureSize( batchingColorTexture, 0 ).x;\n\t\tint j = int( i );\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\treturn texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;\n\t}\n#endif",batching_vertex:"#ifdef USE_BATCHING\n\tmat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );\n#endif",begin_vertex:"vec3 transformed = vec3( position );\n#ifdef USE_ALPHAHASH\n\tvPosition = vec3( position );\n#endif",beginnormal_vertex:"vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif",bsdfs:"float G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n} // validated",iridescence_fragment:"#ifdef USE_IRIDESCENCE\n\tconst mat3 XYZ_TO_REC709 = mat3(\n\t\t 3.2404542, -0.9692660, 0.0556434,\n\t\t-1.5371385, 1.8760108, -0.2040259,\n\t\t-0.4985314, 0.0415560, 1.0572252\n\t);\n\tvec3 Fresnel0ToIor( vec3 fresnel0 ) {\n\t\tvec3 sqrtF0 = sqrt( fresnel0 );\n\t\treturn ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );\n\t}\n\tvec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {\n\t\treturn pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );\n\t}\n\tfloat IorToFresnel0( float transmittedIor, float incidentIor ) {\n\t\treturn pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));\n\t}\n\tvec3 evalSensitivity( float OPD, vec3 shift ) {\n\t\tfloat phase = 2.0 * PI * OPD * 1.0e-9;\n\t\tvec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );\n\t\tvec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );\n\t\tvec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );\n\t\tvec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );\n\t\txyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );\n\t\txyz /= 1.0685e-7;\n\t\tvec3 rgb = XYZ_TO_REC709 * xyz;\n\t\treturn rgb;\n\t}\n\tvec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {\n\t\tvec3 I;\n\t\tfloat iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );\n\t\tfloat sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );\n\t\tfloat cosTheta2Sq = 1.0 - sinTheta2Sq;\n\t\tif ( cosTheta2Sq < 0.0 ) {\n\t\t\treturn vec3( 1.0 );\n\t\t}\n\t\tfloat cosTheta2 = sqrt( cosTheta2Sq );\n\t\tfloat R0 = IorToFresnel0( iridescenceIOR, outsideIOR );\n\t\tfloat R12 = F_Schlick( R0, 1.0, cosTheta1 );\n\t\tfloat T121 = 1.0 - R12;\n\t\tfloat phi12 = 0.0;\n\t\tif ( iridescenceIOR < outsideIOR ) phi12 = PI;\n\t\tfloat phi21 = PI - phi12;\n\t\tvec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) );\t\tvec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );\n\t\tvec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );\n\t\tvec3 phi23 = vec3( 0.0 );\n\t\tif ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;\n\t\tif ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;\n\t\tif ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;\n\t\tfloat OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;\n\t\tvec3 phi = vec3( phi21 ) + phi23;\n\t\tvec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );\n\t\tvec3 r123 = sqrt( R123 );\n\t\tvec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );\n\t\tvec3 C0 = R12 + Rs;\n\t\tI = C0;\n\t\tvec3 Cm = Rs - T121;\n\t\tfor ( int m = 1; m <= 2; ++ m ) {\n\t\t\tCm *= r123;\n\t\t\tvec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );\n\t\t\tI += Cm * Sm;\n\t\t}\n\t\treturn max( I, vec3( 0.0 ) );\n\t}\n#endif",bumpmap_pars_fragment:"#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vBumpMapUv );\n\t\tvec2 dSTdy = dFdy( vBumpMapUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );\n\t\tvec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif",clipping_planes_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#ifdef ALPHA_TO_COVERAGE\n\t\tfloat distanceToPlane, distanceGradient;\n\t\tfloat clipOpacity = 1.0;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\tclipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\tif ( clipOpacity == 0.0 ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tfloat unionClipOpacity = 1.0;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\t\tunionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tclipOpacity *= 1.0 - unionClipOpacity;\n\t\t#endif\n\t\tdiffuseColor.a *= clipOpacity;\n\t\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tbool clipped = true;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tif ( clipped ) discard;\n\t\t#endif\n\t#endif\n#endif",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif",color_fragment:"#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#elif defined( USE_COLOR )\n\tdiffuseColor.rgb *= vColor;\n#endif",color_pars_fragment:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif",color_pars_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec3 vColor;\n#endif",color_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );\n\tvColor.xyz *= batchingColor.xyz;\n#endif",common:"#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n\tvarying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\thighp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tuv.x += filterInt * 3.0 * cubeUV_minTileSize;\n\t\tuv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\n\t\tuv.x *= CUBEUV_TEXEL_WIDTH;\n\t\tuv.y *= CUBEUV_TEXEL_HEIGHT;\n\t\t#ifdef texture2DGradEXT\n\t\t\treturn texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;\n\t\t#else\n\t\t\treturn texture2D( envMap, uv ).rgb;\n\t\t#endif\n\t}\n\t#define cubeUV_r0 1.0\n\t#define cubeUV_m0 - 2.0\n\t#define cubeUV_r1 0.8\n\t#define cubeUV_m1 - 1.0\n\t#define cubeUV_r4 0.4\n\t#define cubeUV_m4 2.0\n\t#define cubeUV_r5 0.305\n\t#define cubeUV_m5 3.0\n\t#define cubeUV_r6 0.21\n\t#define cubeUV_m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= cubeUV_r1 ) {\n\t\t\tmip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\n\t\t} else if ( roughness >= cubeUV_r4 ) {\n\t\t\tmip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\n\t\t} else if ( roughness >= cubeUV_r5 ) {\n\t\t\tmip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\n\t\t} else if ( roughness >= cubeUV_r6 ) {\n\t\t\tmip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif",defaultnormal_vertex:"vec3 transformedNormal = objectNormal;\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = objectTangent;\n#endif\n#ifdef USE_BATCHING\n\tmat3 bm = mat3( batchingMatrix );\n\ttransformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );\n\ttransformedNormal = bm * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = bm * transformedTangent;\n\t#endif\n#endif\n#ifdef USE_INSTANCING\n\tmat3 im = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );\n\ttransformedNormal = im * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = im * transformedTangent;\n\t#endif\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\ttransformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n\t\temissiveColor = sRGBTransferEOTF( emissiveColor );\n\t#endif\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif",colorspace_fragment:"gl_FragColor = linearToOutputTexel( gl_FragColor );",colorspace_pars_fragment:"vec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferEOTF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}",envmap_fragment:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif",envmap_common_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform mat3 envMapRotation;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif",envmap_physical_pars_fragment:"#ifdef USE_ENVMAP\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\t#ifdef USE_ANISOTROPY\n\t\tvec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\t\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\t\tvec3 bentNormal = cross( bitangent, viewDir );\n\t\t\t\tbentNormal = normalize( cross( bentNormal, bitangent ) );\n\t\t\t\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\t\t\t\treturn getIBLRadiance( viewDir, bentNormal, roughness );\n\t\t\t#else\n\t\t\t\treturn vec3( 0.0 );\n\t\t\t#endif\n\t\t}\n\t#endif\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif",fog_vertex:"#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif",fog_fragment:"#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif",fog_pars_fragment:"#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif",gradientmap_pars_fragment:"#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn vec3( texture2D( gradientMap, coord ).r );\n\t#else\n\t\tvec2 fw = fwidth( coord ) * 0.5;\n\t\treturn mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n\t#endif\n}",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif",lights_lambert_fragment:"LambertMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularStrength = specularStrength;",lights_lambert_pars_fragment:"varying vec3 vViewPosition;\nstruct LambertMaterial {\n\tvec3 diffuseColor;\n\tfloat specularStrength;\n};\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Lambert\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Lambert",lights_pars_begin:"uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n\tuniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif ( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif",lights_toon_fragment:"ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;",lights_toon_pars_fragment:"varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon",lights_phong_fragment:"BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;",lights_phong_pars_fragment:"varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong",lights_physical_fragment:"PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\tmaterial.ior = ior;\n\t#ifdef USE_SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULAR_COLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\t\t#endif\n\t\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_DISPERSION\n\tmaterial.dispersion = dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tmaterial.iridescence = iridescence;\n\tmaterial.iridescenceIOR = iridescenceIOR;\n\t#ifdef USE_IRIDESCENCEMAP\n\t\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\t#endif\n\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\t\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\t#else\n\t\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\n\t#endif\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\t#ifdef USE_ANISOTROPYMAP\n\t\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n\t\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n\t\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\t#else\n\t\tvec2 anisotropyV = anisotropyVector;\n\t#endif\n\tmaterial.anisotropy = length( anisotropyV );\n\tif( material.anisotropy == 0.0 ) {\n\t\tanisotropyV = vec2( 1.0, 0.0 );\n\t} else {\n\t\tanisotropyV /= material.anisotropy;\n\t\tmaterial.anisotropy = saturate( material.anisotropy );\n\t}\n\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n#endif",lights_physical_pars_fragment:"struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat roughness;\n\tvec3 specularColor;\n\tfloat specularF90;\n\tfloat dispersion;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tfloat iridescence;\n\t\tfloat iridescenceIOR;\n\t\tfloat iridescenceThickness;\n\t\tvec3 iridescenceFresnel;\n\t\tvec3 iridescenceF0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n\t#ifdef IOR\n\t\tfloat ior;\n\t#endif\n\t#ifdef USE_TRANSMISSION\n\t\tfloat transmission;\n\t\tfloat transmissionAlpha;\n\t\tfloat thickness;\n\t\tfloat attenuationDistance;\n\t\tvec3 attenuationColor;\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat anisotropy;\n\t\tfloat alphaT;\n\t\tvec3 anisotropyT;\n\t\tvec3 anisotropyB;\n\t#endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n\tfloat V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n\t\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n\t\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n\t\tfloat v = 0.5 / ( gv + gl );\n\t\treturn saturate(v);\n\t}\n\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\t\tfloat a2 = alphaT * alphaB;\n\t\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n\t\thighp float v2 = dot( v, v );\n\t\tfloat w2 = a2 / v2;\n\t\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\n\t}\n#endif\n#ifdef USE_CLEARCOAT\n\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\t\tvec3 f0 = material.clearcoatF0;\n\t\tfloat f90 = material.clearcoatF90;\n\t\tfloat roughness = material.clearcoatRoughness;\n\t\tfloat alpha = pow2( roughness );\n\t\tvec3 halfDir = normalize( lightDir + viewDir );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\t\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\t\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t\treturn F * ( V * D );\n\t}\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 f0 = material.specularColor;\n\tfloat f90 = material.specularF90;\n\tfloat roughness = material.roughness;\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t#ifdef USE_IRIDESCENCE\n\t\tF = mix( F, material.iridescenceFresnel, material.iridescence );\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat dotTL = dot( material.anisotropyT, lightDir );\n\t\tfloat dotTV = dot( material.anisotropyT, viewDir );\n\t\tfloat dotTH = dot( material.anisotropyT, halfDir );\n\t\tfloat dotBL = dot( material.anisotropyB, lightDir );\n\t\tfloat dotBV = dot( material.anisotropyB, viewDir );\n\t\tfloat dotBH = dot( material.anisotropyB, halfDir );\n\t\tfloat V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\t\tfloat D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n\t#else\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t#endif\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n\tfloat b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n\tfloat DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n\treturn saturate( DG * RECIPROCAL_PI );\n}\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\tvec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n\treturn fab;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\t#ifdef USE_IRIDESCENCE\n\t\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\t#else\n\t\tvec3 Fr = specularColor;\n\t#endif\n\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometryNormal;\n\t\tvec3 viewDir = geometryViewDir;\n\t\tvec3 position = geometryPosition;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n\t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t#endif\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\n\t#else\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\t#endif\n\tvec3 totalScattering = singleScattering + multiScattering;\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );\n\treflectedLight.indirectSpecular += radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}",lights_fragment_begin:"\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n\tgeometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if defined( USE_LIGHT_PROBES )\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif",lights_fragment_maps:"#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometryNormal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\t#ifdef USE_ANISOTROPY\n\t\tradiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t#else\n\t\tradiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif",lights_fragment_end:"#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif",logdepthbuf_fragment:"#if defined( USE_LOGDEPTHBUF )\n\tgl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif",logdepthbuf_pars_fragment:"#if defined( USE_LOGDEPTHBUF )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_pars_vertex:"#ifdef USE_LOGDEPTHBUF\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGDEPTHBUF\n\tvFragDepth = 1.0 + gl_Position.w;\n\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n#endif",map_fragment:"#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif",map_pars_fragment:"#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif",map_particle_fragment:"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t#if defined( USE_POINTS_UV )\n\t\tvec2 uv = vUv;\n\t#else\n\t\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tdiffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif",map_particle_pars_fragment:"#if defined( USE_POINTS_UV )\n\tvarying vec2 vUv;\n#else\n\t#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t\tuniform mat3 uvTransform;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",metalnessmap_fragment:"float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif",metalnessmap_pars_fragment:"#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif",morphinstance_vertex:"#ifdef USE_INSTANCING_MORPH\n\tfloat morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\t}\n#endif",morphcolor_vertex:"#if defined( USE_MORPHCOLORS )\n\tvColor *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t#if defined( USE_COLOR_ALPHA )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\t\t#elif defined( USE_COLOR )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\t\t#endif\n\t}\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n\t#ifndef USE_INSTANCING_MORPH\n\t\tuniform float morphTargetBaseInfluence;\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t#endif\n\tuniform sampler2DArray morphTargetsTexture;\n\tuniform ivec2 morphTargetsTextureSize;\n\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t}\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",normal_fragment_begin:"float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = dFdx( vViewPosition );\n\tvec3 fdy = dFdy( vViewPosition );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal *= faceDirection;\n\t#endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn = getTangentFrame( - vViewPosition, normal,\n\t\t#if defined( USE_NORMALMAP )\n\t\t\tvNormalMapUv\n\t\t#elif defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tvClearcoatNormalMapUv\n\t\t#else\n\t\t\tvUv\n\t\t#endif\n\t\t);\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn[0] *= faceDirection;\n\t\ttbn[1] *= faceDirection;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn2[0] *= faceDirection;\n\t\ttbn2[1] *= faceDirection;\n\t#endif\n#endif\nvec3 nonPerturbedNormal = normal;",normal_fragment_maps:"#ifdef USE_NORMALMAP_OBJECTSPACE\n\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\tnormal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif",normal_pars_fragment:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_pars_vertex:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_vertex:"#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif",normalmap_pars_fragment:"#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef USE_NORMALMAP_OBJECTSPACE\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n\tmat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n\t\tvec3 q0 = dFdx( eye_pos.xyz );\n\t\tvec3 q1 = dFdy( eye_pos.xyz );\n\t\tvec2 st0 = dFdx( uv.st );\n\t\tvec2 st1 = dFdy( uv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n\t\treturn mat3( T * scale, B * scale, N );\n\t}\n#endif",clearcoat_normal_fragment_begin:"#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = nonPerturbedNormal;\n#endif",clearcoat_normal_fragment_maps:"#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\tclearcoatNormal = normalize( tbn2 * clearcoatMapN );\n#endif",clearcoat_pars_fragment:"#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif",iridescence_pars_fragment:"#ifdef USE_IRIDESCENCEMAP\n\tuniform sampler2D iridescenceMap;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform sampler2D iridescenceThicknessMap;\n#endif",opaque_fragment:"#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );",packing:"vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\nvec4 packDepthToRGBA( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec4( 0., 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec4( 1., 1., 1., 1. );\n\tfloat vuf;\n\tfloat af = modf( v * PackFactors.a, vuf );\n\tfloat bf = modf( vuf * ShiftRight8, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\nvec3 packDepthToRGB( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec3( 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec3( 1., 1., 1. );\n\tfloat vuf;\n\tfloat bf = modf( v * PackFactors.b, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\nvec2 packDepthToRG( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec2( 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec2( 1., 1. );\n\tfloat vuf;\n\tfloat gf = modf( v * 256., vuf );\n\treturn vec2( vuf * Inv255, gf );\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors4 );\n}\nfloat unpackRGBToDepth( const in vec3 v ) {\n\treturn dot( v, UnpackFactors3 );\n}\nfloat unpackRGToDepth( const in vec2 v ) {\n\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn depth * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * depth - far );\n}",premultiplied_alpha_fragment:"#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif",project_vertex:"vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_BATCHING\n\tmvPosition = batchingMatrix * mvPosition;\n#endif\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;",dithering_fragment:"#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif",dithering_pars_fragment:"#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif",roughnessmap_fragment:"float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n\troughnessFactor *= texelRoughness.g;\n#endif",roughnessmap_pars_fragment:"#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif",shadowmap_pars_fragment:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\t\n\t\tfloat lightToPositionLength = length( lightToPosition );\n\t\tif ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\t\tdp += shadowBias;\n\t\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\t\tshadow = (\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t\t) * ( 1.0 / 9.0 );\n\t\t\t#else\n\t\t\t\tshadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n#endif",shadowmap_pars_vertex:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tuniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif",shadowmap_vertex:"#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif",shadowmask_pars_fragment:"float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}",skinbase_vertex:"#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\tuniform highp sampler2D boneTexture;\n\tmat4 getBoneMatrix( const in float i ) {\n\t\tint size = textureSize( boneTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif",skinning_vertex:"#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif",skinnormal_vertex:"#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif",specularmap_fragment:"float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif",specularmap_pars_fragment:"#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif",tonemapping_fragment:"#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif",tonemapping_pars_fragment:"#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 CineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.6605, - 0.1246, - 0.0182 ),\n\tvec3( - 0.5876, 1.1329, - 0.1006 ),\n\tvec3( - 0.0728, - 0.0083, 1.1187 )\n);\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n\tvec3( 0.6274, 0.0691, 0.0164 ),\n\tvec3( 0.3293, 0.9195, 0.0880 ),\n\tvec3( 0.0433, 0.0113, 0.8956 )\n);\nvec3 agxDefaultContrastApprox( vec3 x ) {\n\tvec3 x2 = x * x;\n\tvec3 x4 = x2 * x2;\n\treturn + 15.5 * x4 * x2\n\t\t- 40.14 * x4 * x\n\t\t+ 31.96 * x4\n\t\t- 6.868 * x2 * x\n\t\t+ 0.4298 * x2\n\t\t+ 0.1191 * x\n\t\t- 0.00232;\n}\nvec3 AgXToneMapping( vec3 color ) {\n\tconst mat3 AgXInsetMatrix = mat3(\n\t\tvec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n\t\tvec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n\t\tvec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n\t);\n\tconst mat3 AgXOutsetMatrix = mat3(\n\t\tvec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n\t\tvec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n\t\tvec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n\t);\n\tconst float AgxMinEv = - 12.47393;\tconst float AgxMaxEv = 4.026069;\n\tcolor *= toneMappingExposure;\n\tcolor = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\tcolor = AgXInsetMatrix * color;\n\tcolor = max( color, 1e-10 );\tcolor = log2( color );\n\tcolor = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\tcolor = clamp( color, 0.0, 1.0 );\n\tcolor = agxDefaultContrastApprox( color );\n\tcolor = AgXOutsetMatrix * color;\n\tcolor = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\tcolor = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\tcolor = clamp( color, 0.0, 1.0 );\n\treturn color;\n}\nvec3 NeutralToneMapping( vec3 color ) {\n\tconst float StartCompression = 0.8 - 0.04;\n\tconst float Desaturation = 0.15;\n\tcolor *= toneMappingExposure;\n\tfloat x = min( color.r, min( color.g, color.b ) );\n\tfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\tcolor -= offset;\n\tfloat peak = max( color.r, max( color.g, color.b ) );\n\tif ( peak < StartCompression ) return color;\n\tfloat d = 1. - StartCompression;\n\tfloat newPeak = 1. - d * d / ( peak + d - StartCompression );\n\tcolor *= newPeak / peak;\n\tfloat g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\treturn mix( color, vec3( newPeak ), g );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }",transmission_fragment:"#ifdef USE_TRANSMISSION\n\tmaterial.transmission = transmission;\n\tmaterial.transmissionAlpha = 1.0;\n\tmaterial.thickness = thickness;\n\tmaterial.attenuationDistance = attenuationDistance;\n\tmaterial.attenuationColor = attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmitted = getIBLVolumeRefraction(\n\t\tn, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n\t\tmaterial.attenuationColor, material.attenuationDistance );\n\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif",transmission_pars_fragment:"#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tfloat w0( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n\t}\n\tfloat w1( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n\t}\n\tfloat w2( float a ){\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n\t}\n\tfloat w3( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * a );\n\t}\n\tfloat g0( float a ) {\n\t\treturn w0( a ) + w1( a );\n\t}\n\tfloat g1( float a ) {\n\t\treturn w2( a ) + w3( a );\n\t}\n\tfloat h0( float a ) {\n\t\treturn - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n\t}\n\tfloat h1( float a ) {\n\t\treturn 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n\t}\n\tvec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n\t\tuv = uv * texelSize.zw + 0.5;\n\t\tvec2 iuv = floor( uv );\n\t\tvec2 fuv = fract( uv );\n\t\tfloat g0x = g0( fuv.x );\n\t\tfloat g1x = g1( fuv.x );\n\t\tfloat h0x = h0( fuv.x );\n\t\tfloat h1x = h1( fuv.x );\n\t\tfloat h0y = h0( fuv.y );\n\t\tfloat h1y = h1( fuv.y );\n\t\tvec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\treturn g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n\t\t\tg1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n\t}\n\tvec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n\t\tvec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n\t\tvec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n\t\tvec2 fLodSizeInv = 1.0 / fLodSize;\n\t\tvec2 cLodSizeInv = 1.0 / cLodSize;\n\t\tvec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n\t\tvec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n\t\treturn mix( fSample, cSample, fract( lod ) );\n\t}\n\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\t\tfloat lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\treturn textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n\t}\n\tvec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tif ( isinf( attenuationDistance ) ) {\n\t\t\treturn vec3( 1.0 );\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n\t\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n\t\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec4 transmittedLight;\n\t\tvec3 transmittance;\n\t\t#ifdef USE_DISPERSION\n\t\t\tfloat halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\n\t\t\tvec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\n\t\t\tfor ( int i = 0; i < 3; i ++ ) {\n\t\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\n\t\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\n\t\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\t\trefractionCoords += 1.0;\n\t\t\t\trefractionCoords /= 2.0;\n\t\t\n\t\t\t\tvec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\n\t\t\t\ttransmittedLight[ i ] = transmissionSample[ i ];\n\t\t\t\ttransmittedLight.a += transmissionSample.a;\n\t\t\t\ttransmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\n\t\t\t}\n\t\t\ttransmittedLight.a /= 3.0;\n\t\t\n\t\t#else\n\t\t\n\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\trefractionCoords += 1.0;\n\t\t\trefractionCoords /= 2.0;\n\t\t\ttransmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\t\ttransmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\t\n\t\t#endif\n\t\tvec3 attenuatedColor = transmittance * transmittedLight.rgb;\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\tfloat transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n\t}\n#endif",uv_pars_fragment:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_pars_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tuniform mat3 mapTransform;\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform mat3 alphaMapTransform;\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tuniform mat3 lightMapTransform;\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tuniform mat3 aoMapTransform;\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tuniform mat3 bumpMapTransform;\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tuniform mat3 normalMapTransform;\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tuniform mat3 displacementMapTransform;\n\tvarying vec2 vDisplacementMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tuniform mat3 emissiveMapTransform;\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tuniform mat3 metalnessMapTransform;\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tuniform mat3 roughnessMapTransform;\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tuniform mat3 anisotropyMapTransform;\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tuniform mat3 clearcoatMapTransform;\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform mat3 clearcoatNormalMapTransform;\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform mat3 clearcoatRoughnessMapTransform;\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tuniform mat3 sheenColorMapTransform;\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tuniform mat3 sheenRoughnessMapTransform;\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tuniform mat3 iridescenceMapTransform;\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform mat3 iridescenceThicknessMapTransform;\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tuniform mat3 specularMapTransform;\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tuniform mat3 specularColorMapTransform;\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tuniform mat3 specularIntensityMapTransform;\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvUv = vec3( uv, 1 ).xy;\n#endif\n#ifdef USE_MAP\n\tvMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ALPHAMAP\n\tvAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_LIGHTMAP\n\tvLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_AOMAP\n\tvAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_BUMPMAP\n\tvBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_NORMALMAP\n\tvNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tvDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_METALNESSMAP\n\tvMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULARMAP\n\tvSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tvTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_THICKNESSMAP\n\tvThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n#endif",worldpos_vertex:"#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_BATCHING\n\t\tworldPosition = batchingMatrix * worldPosition;\n\t#endif\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif",background_vert:"varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}",background_frag:"uniform sampler2D t2D;\nuniform float backgroundIntensity;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\ttexColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",backgroundCube_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}",backgroundCube_frag:"#ifdef ENVMAP_TYPE_CUBE\n\tuniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n\tuniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nuniform mat3 backgroundRotation;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );\n\t#else\n\t\tvec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",cube_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}",cube_frag:"uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = texColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",depth_vert:"#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <skinbase_vertex>\n\t#include <morphinstance_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}",depth_frag:"#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <clipping_planes_fragment>\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <logdepthbuf_fragment>\n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#elif DEPTH_PACKING == 3202\n\t\tgl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );\n\t#elif DEPTH_PACKING == 3203\n\t\tgl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );\n\t#endif\n}",distanceRGBA_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <skinbase_vertex>\n\t#include <morphinstance_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}",distanceRGBA_frag:"#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <clipping_planes_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}",equirect_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}",equirect_frag:"uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n}",linedashed_vert:"uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}",linedashed_frag:"uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",meshbasic_vert:"#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinbase_vertex>\n\t\t#include <skinnormal_vertex>\n\t\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}",meshbasic_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\treflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshlambert_vert:"#define LAMBERT\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshlambert_frag:"#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_lambert_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_lambert_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}",meshmatcap_frag:"#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t#else\n\t\tvec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshnormal_vert:"#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}",meshnormal_frag:"#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a );\n\t#ifdef OPAQUE\n\t\tgl_FragColor.a = 1.0;\n\t#endif\n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshphong_frag:"#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshphysical_vert:"#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}",meshphysical_frag:"#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_DISPERSION\n\tuniform float dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\tuniform vec2 anisotropyVector;\n\t#ifdef USE_ANISOTROPYMAP\n\t\tuniform sampler2D anisotropyMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshtoon_frag:"#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",points_vert:"uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n#ifdef USE_POINTS_UV\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\nvoid main() {\n\t#ifdef USE_POINTS_UV\n\t\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\t#endif\n\t#include <color_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphcolor_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}",points_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",shadow_vert:"#include <common>\n#include <batching_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <batching_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphinstance_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",shadow_frag:"uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <logdepthbuf_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n}",sprite_vert:"uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix[ 3 ];\n\tvec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}",sprite_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n}"},Tr={common:{diffuse:{value:new xi(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Me},alphaMap:{value:null},alphaMapTransform:{value:new Me},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Me}},envmap:{envMap:{value:null},envMapRotation:{value:new Me},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Me}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Me}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Me},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Me},normalScale:{value:new Se(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Me},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Me}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Me}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Me}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new xi(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new xi(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Me},alphaTest:{value:0},uvTransform:{value:new Me}},sprite:{diffuse:{value:new xi(16777215)},opacity:{value:1},center:{value:new Se(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Me},alphaMap:{value:null},alphaMapTransform:{value:new Me},alphaTest:{value:0}}},wr={basic:{uniforms:tr([Tr.common,Tr.specularmap,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.fog]),vertexShader:Mr.meshbasic_vert,fragmentShader:Mr.meshbasic_frag},lambert:{uniforms:tr([Tr.common,Tr.specularmap,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.fog,Tr.lights,{emissive:{value:new xi(0)}}]),vertexShader:Mr.meshlambert_vert,fragmentShader:Mr.meshlambert_frag},phong:{uniforms:tr([Tr.common,Tr.specularmap,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.fog,Tr.lights,{emissive:{value:new xi(0)},specular:{value:new xi(1118481)},shininess:{value:30}}]),vertexShader:Mr.meshphong_vert,fragmentShader:Mr.meshphong_frag},standard:{uniforms:tr([Tr.common,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.roughnessmap,Tr.metalnessmap,Tr.fog,Tr.lights,{emissive:{value:new xi(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Mr.meshphysical_vert,fragmentShader:Mr.meshphysical_frag},toon:{uniforms:tr([Tr.common,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.gradientmap,Tr.fog,Tr.lights,{emissive:{value:new xi(0)}}]),vertexShader:Mr.meshtoon_vert,fragmentShader:Mr.meshtoon_frag},matcap:{uniforms:tr([Tr.common,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.fog,{matcap:{value:null}}]),vertexShader:Mr.meshmatcap_vert,fragmentShader:Mr.meshmatcap_frag},points:{uniforms:tr([Tr.points,Tr.fog]),vertexShader:Mr.points_vert,fragmentShader:Mr.points_frag},dashed:{uniforms:tr([Tr.common,Tr.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Mr.linedashed_vert,fragmentShader:Mr.linedashed_frag},depth:{uniforms:tr([Tr.common,Tr.displacementmap]),vertexShader:Mr.depth_vert,fragmentShader:Mr.depth_frag},normal:{uniforms:tr([Tr.common,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,{opacity:{value:1}}]),vertexShader:Mr.meshnormal_vert,fragmentShader:Mr.meshnormal_frag},sprite:{uniforms:tr([Tr.sprite,Tr.fog]),vertexShader:Mr.sprite_vert,fragmentShader:Mr.sprite_frag},background:{uniforms:{uvTransform:{value:new Me},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Mr.background_vert,fragmentShader:Mr.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new Me}},vertexShader:Mr.backgroundCube_vert,fragmentShader:Mr.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Mr.cube_vert,fragmentShader:Mr.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Mr.equirect_vert,fragmentShader:Mr.equirect_frag},distanceRGBA:{uniforms:tr([Tr.common,Tr.displacementmap,{referencePosition:{value:new Ze},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Mr.distanceRGBA_vert,fragmentShader:Mr.distanceRGBA_frag},shadow:{uniforms:tr([Tr.lights,Tr.fog,{color:{value:new xi(0)},opacity:{value:1}}]),vertexShader:Mr.shadow_vert,fragmentShader:Mr.shadow_frag}};wr.physical={uniforms:tr([wr.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Me},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Me},clearcoatNormalScale:{value:new Se(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Me},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Me},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Me},sheen:{value:0},sheenColor:{value:new xi(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Me},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Me},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Me},transmissionSamplerSize:{value:new Se},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Me},attenuationDistance:{value:0},attenuationColor:{value:new xi(0)},specularColor:{value:new xi(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Me},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Me},anisotropyVector:{value:new Se},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Me}}]),vertexShader:Mr.meshphysical_vert,fragmentShader:Mr.meshphysical_frag};const Er={r:0,b:0,g:0},Ar=new Bn,Rr=new Rn;function Cr(t,e,n,i,r,s,a){const o=new xi(0);let l,h,u=!0===s?0:1,c=null,d=0,p=null;function f(t){let i=!0===t.isScene?t.background:null;if(i&&i.isTexture){i=(t.backgroundBlurriness>0?n:e).get(i)}return i}function m(e,n){e.getRGB(Er,er(t)),i.buffers.color.setClear(Er.r,Er.g,Er.b,n,a)}return{getClearColor:function(){return o},setClearColor:function(t,e=1){o.set(t),u=e,m(o,u)},getClearAlpha:function(){return u},setClearAlpha:function(t){u=t,m(o,u)},render:function(e){let n=!1;const r=f(e);null===r?m(o,u):r&&r.isColor&&(m(r,1),n=!0);const s=t.xr.getEnvironmentBlendMode();"additive"===s?i.buffers.color.setClear(0,0,0,1,a):"alpha-blend"===s&&i.buffers.color.setClear(0,0,0,0,a),(t.autoClear||n)&&(i.buffers.depth.setTest(!0),i.buffers.depth.setMask(!0),i.buffers.color.setMask(!0),t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil))},addToRenderList:function(e,n){const i=f(n);i&&(i.isCubeTexture||i.mapping===V)?(void 0===h&&(h=new Ki(new Qi(1,1,1),new ir({name:"BackgroundCubeMaterial",uniforms:Ji(wr.backgroundCube.uniforms),vertexShader:wr.backgroundCube.vertexShader,fragmentShader:wr.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1})),h.geometry.deleteAttribute("normal"),h.geometry.deleteAttribute("uv"),h.onBeforeRender=function(t,e,n){this.matrixWorld.copyPosition(n.matrixWorld)},Object.defineProperty(h.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),r.update(h)),Ar.copy(n.backgroundRotation),Ar.x*=-1,Ar.y*=-1,Ar.z*=-1,i.isCubeTexture&&!1===i.isRenderTargetTexture&&(Ar.y*=-1,Ar.z*=-1),h.material.uniforms.envMap.value=i,h.material.uniforms.flipEnvMap.value=i.isCubeTexture&&!1===i.isRenderTargetTexture?-1:1,h.material.uniforms.backgroundBlurriness.value=n.backgroundBlurriness,h.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,h.material.uniforms.backgroundRotation.value.setFromMatrix4(Rr.makeRotationFromEuler(Ar)),h.material.toneMapped=Ne.getTransfer(i.colorSpace)!==Zt,c===i&&d===i.version&&p===t.toneMapping||(h.material.needsUpdate=!0,c=i,d=i.version,p=t.toneMapping),h.layers.enableAll(),e.unshift(h,h.geometry,h.material,0,0,null)):i&&i.isTexture&&(void 0===l&&(l=new Ki(new Sr(2,2),new ir({name:"BackgroundMaterial",uniforms:Ji(wr.background.uniforms),vertexShader:wr.background.vertexShader,fragmentShader:wr.background.fragmentShader,side:0,depthTest:!1,depthWrite:!1,fog:!1})),l.geometry.deleteAttribute("normal"),Object.defineProperty(l.material,"map",{get:function(){return this.uniforms.t2D.value}}),r.update(l)),l.material.uniforms.t2D.value=i,l.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,l.material.toneMapped=Ne.getTransfer(i.colorSpace)!==Zt,!0===i.matrixAutoUpdate&&i.updateMatrix(),l.material.uniforms.uvTransform.value.copy(i.matrix),c===i&&d===i.version&&p===t.toneMapping||(l.material.needsUpdate=!0,c=i,d=i.version,p=t.toneMapping),l.layers.enableAll(),e.unshift(l,l.geometry,l.material,0,0,null))}}}function Nr(t,e){const n=t.getParameter(t.MAX_VERTEX_ATTRIBS),i={},r=h(null);let s=r,a=!1;function o(e){return t.bindVertexArray(e)}function l(e){return t.deleteVertexArray(e)}function h(t){const e=[],i=[],r=[];for(let t=0;t<n;t++)e[t]=0,i[t]=0,r[t]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:e,enabledAttributes:i,attributeDivisors:r,object:t,attributes:{},index:null}}function u(){const t=s.newAttributes;for(let e=0,n=t.length;e<n;e++)t[e]=0}function c(t){d(t,0)}function d(e,n){const i=s.newAttributes,r=s.enabledAttributes,a=s.attributeDivisors;i[e]=1,0===r[e]&&(t.enableVertexAttribArray(e),r[e]=1),a[e]!==n&&(t.vertexAttribDivisor(e,n),a[e]=n)}function p(){const e=s.newAttributes,n=s.enabledAttributes;for(let i=0,r=n.length;i<r;i++)n[i]!==e[i]&&(t.disableVertexAttribArray(i),n[i]=0)}function f(e,n,i,r,s,a,o){!0===o?t.vertexAttribIPointer(e,n,i,s,a):t.vertexAttribPointer(e,n,i,r,s,a)}function m(){g(),a=!0,s!==r&&(s=r,o(s.object))}function g(){r.geometry=null,r.program=null,r.wireframe=!1}return{setup:function(n,r,l,m,g){let _=!1;const v=function(e,n,r){const s=!0===r.wireframe;let a=i[e.id];void 0===a&&(a={},i[e.id]=a);let o=a[n.id];void 0===o&&(o={},a[n.id]=o);let l=o[s];void 0===l&&(l=h(t.createVertexArray()),o[s]=l);return l}(m,l,r);s!==v&&(s=v,o(s.object)),_=function(t,e,n,i){const r=s.attributes,a=e.attributes;let o=0;const l=n.getAttributes();for(const e in l){if(l[e].location>=0){const n=r[e];let i=a[e];if(void 0===i&&("instanceMatrix"===e&&t.instanceMatrix&&(i=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(i=t.instanceColor)),void 0===n)return!0;if(n.attribute!==i)return!0;if(i&&n.data!==i.data)return!0;o++}}return s.attributesNum!==o||s.index!==i}(n,m,l,g),_&&function(t,e,n,i){const r={},a=e.attributes;let o=0;const l=n.getAttributes();for(const e in l){if(l[e].location>=0){let n=a[e];void 0===n&&("instanceMatrix"===e&&t.instanceMatrix&&(n=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(n=t.instanceColor));const i={};i.attribute=n,n&&n.data&&(i.data=n.data),r[e]=i,o++}}s.attributes=r,s.attributesNum=o,s.index=i}(n,m,l,g),null!==g&&e.update(g,t.ELEMENT_ARRAY_BUFFER),(_||a)&&(a=!1,function(n,i,r,s){u();const a=s.attributes,o=r.getAttributes(),l=i.defaultAttributeValues;for(const i in o){const r=o[i];if(r.location>=0){let o=a[i];if(void 0===o&&("instanceMatrix"===i&&n.instanceMatrix&&(o=n.instanceMatrix),"instanceColor"===i&&n.instanceColor&&(o=n.instanceColor)),void 0!==o){const i=o.normalized,a=o.itemSize,l=e.get(o);if(void 0===l)continue;const h=l.buffer,u=l.type,p=l.bytesPerElement,m=u===t.INT||u===t.UNSIGNED_INT||o.gpuType===nt;if(o.isInterleavedBufferAttribute){const e=o.data,l=e.stride,g=o.offset;if(e.isInstancedInterleavedBuffer){for(let t=0;t<r.locationSize;t++)d(r.location+t,e.meshPerAttribute);!0!==n.isInstancedMesh&&void 0===s._maxInstanceCount&&(s._maxInstanceCount=e.meshPerAttribute*e.count)}else for(let t=0;t<r.locationSize;t++)c(r.location+t);t.bindBuffer(t.ARRAY_BUFFER,h);for(let t=0;t<r.locationSize;t++)f(r.location+t,a/r.locationSize,u,i,l*p,(g+a/r.locationSize*t)*p,m)}else{if(o.isInstancedBufferAttribute){for(let t=0;t<r.locationSize;t++)d(r.location+t,o.meshPerAttribute);!0!==n.isInstancedMesh&&void 0===s._maxInstanceCount&&(s._maxInstanceCount=o.meshPerAttribute*o.count)}else for(let t=0;t<r.locationSize;t++)c(r.location+t);t.bindBuffer(t.ARRAY_BUFFER,h);for(let t=0;t<r.locationSize;t++)f(r.location+t,a/r.locationSize,u,i,a*p,a/r.locationSize*t*p,m)}}else if(void 0!==l){const e=l[i];if(void 0!==e)switch(e.length){case 2:t.vertexAttrib2fv(r.location,e);break;case 3:t.vertexAttrib3fv(r.location,e);break;case 4:t.vertexAttrib4fv(r.location,e);break;default:t.vertexAttrib1fv(r.location,e)}}}}p()}(n,r,l,m),null!==g&&t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,e.get(g).buffer))},reset:m,resetDefaultState:g,dispose:function(){m();for(const t in i){const e=i[t];for(const t in e){const n=e[t];for(const t in n)l(n[t].object),delete n[t];delete e[t]}delete i[t]}},releaseStatesOfGeometry:function(t){if(void 0===i[t.id])return;const e=i[t.id];for(const t in e){const n=e[t];for(const t in n)l(n[t].object),delete n[t];delete e[t]}delete i[t.id]},releaseStatesOfProgram:function(t){for(const e in i){const n=i[e];if(void 0===n[t.id])continue;const r=n[t.id];for(const t in r)l(r[t].object),delete r[t];delete n[t.id]}},initAttributes:u,enableAttribute:c,disableUnusedAttributes:p}}function Pr(t,e,n){let i;function r(e,r,s){0!==s&&(t.drawArraysInstanced(i,e,r,s),n.update(r,i,s))}this.setMode=function(t){i=t},this.render=function(e,r){t.drawArrays(i,e,r),n.update(r,i,1)},this.renderInstances=r,this.renderMultiDraw=function(t,r,s){if(0===s)return;e.get("WEBGL_multi_draw").multiDrawArraysWEBGL(i,t,0,r,0,s);let a=0;for(let t=0;t<s;t++)a+=r[t];n.update(a,i,1)},this.renderMultiDrawInstances=function(t,s,a,o){if(0===a)return;const l=e.get("WEBGL_multi_draw");if(null===l)for(let e=0;e<t.length;e++)r(t[e],s[e],o[e]);else{l.multiDrawArraysInstancedWEBGL(i,t,0,s,0,o,0,a);let e=0;for(let t=0;t<a;t++)e+=s[t]*o[t];n.update(e,i,1)}}}function Ir(t,e,n,i){let r;function s(e){if("highp"===e){if(t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.HIGH_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0)return"highp";e="mediump"}return"mediump"===e&&t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let a=void 0!==n.precision?n.precision:"highp";const o=s(a);o!==a&&(console.warn("THREE.WebGLRenderer:",a,"not supported, using",o,"instead."),a=o);const l=!0===n.logarithmicDepthBuffer,h=!0===n.reverseDepthBuffer&&e.has("EXT_clip_control"),u=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),c=t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS);return{isWebGL2:!0,getMaxAnisotropy:function(){if(void 0!==r)return r;if(!0===e.has("EXT_texture_filter_anisotropic")){const n=e.get("EXT_texture_filter_anisotropic");r=t.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else r=0;return r},getMaxPrecision:s,textureFormatReadable:function(e){return e===ut||i.convert(e)===t.getParameter(t.IMPLEMENTATION_COLOR_READ_FORMAT)},textureTypeReadable:function(n){const r=n===st&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(n!==Q&&i.convert(n)!==t.getParameter(t.IMPLEMENTATION_COLOR_READ_TYPE)&&n!==rt&&!r)},precision:a,logarithmicDepthBuffer:l,reverseDepthBuffer:h,maxTextures:u,maxVertexTextures:c,maxTextureSize:t.getParameter(t.MAX_TEXTURE_SIZE),maxCubemapSize:t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE),maxAttributes:t.getParameter(t.MAX_VERTEX_ATTRIBS),maxVertexUniforms:t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS),maxVaryings:t.getParameter(t.MAX_VARYING_VECTORS),maxFragmentUniforms:t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS),vertexTextures:c>0,maxSamples:t.getParameter(t.MAX_SAMPLES)}}function Lr(t){const e=this;let n=null,i=0,r=!1,s=!1;const a=new gr,o=new Me,l={value:null,needsUpdate:!1};function h(t,n,i,r){const s=null!==t?t.length:0;let h=null;if(0!==s){if(h=l.value,!0!==r||null===h){const e=i+4*s,r=n.matrixWorldInverse;o.getNormalMatrix(r),(null===h||h.length<e)&&(h=new Float32Array(e));for(let e=0,n=i;e!==s;++e,n+=4)a.copy(t[e]).applyMatrix4(r,o),a.normal.toArray(h,n),h[n+3]=a.constant}l.value=h,l.needsUpdate=!0}return e.numPlanes=s,e.numIntersection=0,h}this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(t,e){const n=0!==t.length||e||0!==i||r;return r=e,i=t.length,n},this.beginShadows=function(){s=!0,h(null)},this.endShadows=function(){s=!1},this.setGlobalState=function(t,e){n=h(t,e,0)},this.setState=function(a,o,u){const c=a.clippingPlanes,d=a.clipIntersection,p=a.clipShadows,f=t.get(a);if(!r||null===c||0===c.length||s&&!p)s?h(null):function(){l.value!==n&&(l.value=n,l.needsUpdate=i>0);e.numPlanes=i,e.numIntersection=0}();else{const t=s?0:i,e=4*t;let r=f.clippingState||null;l.value=r,r=h(c,o,e,u);for(let t=0;t!==e;++t)r[t]=n[t];f.clippingState=r,this.numIntersection=d?this.numPlanes:0,this.numPlanes+=t}}}function Ur(t){let e=new WeakMap;function n(t,e){return 303===e?t.mapping=k:304===e&&(t.mapping=G),t}function i(t){const n=t.target;n.removeEventListener("dispose",i);const r=e.get(n);void 0!==r&&(e.delete(n),r.dispose())}return{get:function(r){if(r&&r.isTexture){const s=r.mapping;if(303===s||304===s){if(e.has(r)){return n(e.get(r).texture,r.mapping)}{const s=r.image;if(s&&s.height>0){const a=new dr(s.height);return a.fromEquirectangularTexture(t,r),e.set(r,a),r.addEventListener("dispose",i),n(a.texture,r.mapping)}return null}}}return r},dispose:function(){e=new WeakMap}}}let Dr=class extends rr{constructor(t=-1,e=1,n=1,i=-1,r=.1,s=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=n,this.bottom=i,this.near=r,this.far=s,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,n,i,r,s){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=n,this.view.offsetY=i,this.view.width=r,this.view.height=s,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),n=(this.right+this.left)/2,i=(this.top+this.bottom)/2;let r=n-t,s=n+t,a=i+e,o=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,s=r+t*this.view.width,a-=e*this.view.offsetY,o=a-e*this.view.height}this.projectionMatrix.makeOrthographic(r,s,a,o,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,null!==this.view&&(e.object.view=Object.assign({},this.view)),e}};const Or=[.125,.215,.35,.446,.526,.582],Fr=20,Br=new Dr,zr=new xi;let kr=null,Gr=0,Vr=0,Hr=!1;const jr=(1+Math.sqrt(5))/2,Wr=1/jr,qr=[new Ze(-jr,Wr,0),new Ze(jr,Wr,0),new Ze(-Wr,0,jr),new Ze(Wr,0,jr),new Ze(0,jr,-Wr),new Ze(0,jr,Wr),new Ze(-1,1,-1),new Ze(1,1,-1),new Ze(-1,1,1),new Ze(1,1,1)];let Xr=class{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(t,e=0,n=.1,i=100){kr=this._renderer.getRenderTarget(),Gr=this._renderer.getActiveCubeFace(),Vr=this._renderer.getActiveMipmapLevel(),Hr=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,n,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=Zr(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=Kr(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.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(kr,Gr,Vr),this._renderer.xr.enabled=Hr,t.scissorTest=!1,Yr(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===k||t.mapping===G?this._setSize(0===t.image.length?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),kr=this._renderer.getRenderTarget(),Gr=this._renderer.getActiveCubeFace(),Vr=this._renderer.getActiveMipmapLevel(),Hr=this._renderer.xr.enabled,this._renderer.xr.enabled=!1;const n=e||this._allocateTargets();return this._textureToCubeUV(t,n),this._applyPMREM(n),this._cleanup(n),n}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,n={magFilter:Y,minFilter:Y,generateMipmaps:!1,type:st,format:ut,colorSpace:Yt,depthBuffer:!1},i=$r(t,e,n);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=$r(t,e,n);const{_lodMax:i}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas}=function(t){const e=[],n=[],i=[];let r=t;const s=t-4+1+Or.length;for(let a=0;a<s;a++){const s=Math.pow(2,r);n.push(s);let o=1/s;a>t-4?o=Or[a-t+4-1]:0===a&&(o=0),i.push(o);const l=1/(s-2),h=-l,u=1+l,c=[h,h,u,h,u,u,h,h,u,u,h,u],d=6,p=6,f=3,m=2,g=1,_=new Float32Array(f*p*d),v=new Float32Array(m*p*d),y=new Float32Array(g*p*d);for(let t=0;t<d;t++){const e=t%3*2/3-1,n=t>2?0:-1,i=[e,n,0,e+2/3,n,0,e+2/3,n+1,0,e,n,0,e+2/3,n+1,0,e,n+1,0];_.set(i,f*p*t),v.set(c,m*p*t);const r=[t,t,t,t,t,t];y.set(r,g*p*t)}const x=new Bi;x.setAttribute("position",new Ai(_,f)),x.setAttribute("uv",new Ai(v,m)),x.setAttribute("faceIndex",new Ai(y,g)),e.push(x),r>4&&r--}return{lodPlanes:e,sizeLods:n,sigmas:i}}(i)),this._blurMaterial=function(t,e,n){const i=new Float32Array(Fr),r=new Ze(0,1,0),s=new ir({name:"SphericalGaussianBlur",defines:{n:Fr,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/n,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:i},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:r}},vertexShader:Qr(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform int samples;\n\t\t\tuniform float weights[ n ];\n\t\t\tuniform bool latitudinal;\n\t\t\tuniform float dTheta;\n\t\t\tuniform float mipInt;\n\t\t\tuniform vec3 poleAxis;\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include <cube_uv_reflection_fragment>\n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1});return s}(i,t,e)}return i}_compileMaterial(t){const e=new Ki(this._lodPlanes[0],t);this._renderer.compile(e,Br)}_sceneToCubeUV(t,e,n,i){const r=new lr(90,1,e,n),s=[1,-1,1,1,1,1],a=[1,1,1,-1,-1,-1],o=this._renderer,l=o.autoClear,h=o.toneMapping;o.getClearColor(zr),o.toneMapping=0,o.autoClear=!1;const u=new Ti({name:"PMREM.Background",side:1,depthWrite:!1,depthTest:!1}),c=new Ki(new Qi,u);let d=!1;const p=t.background;p?p.isColor&&(u.color.copy(p),t.background=null,d=!0):(u.color.copy(zr),d=!0);for(let e=0;e<6;e++){const n=e%3;0===n?(r.up.set(0,s[e],0),r.lookAt(a[e],0,0)):1===n?(r.up.set(0,0,s[e]),r.lookAt(0,a[e],0)):(r.up.set(0,s[e],0),r.lookAt(0,0,a[e]));const l=this._cubeSize;Yr(i,n*l,e>2?l:0,l,l),o.setRenderTarget(i),d&&o.render(c,r),o.render(t,r)}c.geometry.dispose(),c.material.dispose(),o.toneMapping=h,o.autoClear=l,t.background=p}_textureToCubeUV(t,e){const n=this._renderer,i=t.mapping===k||t.mapping===G;i?(null===this._cubemapMaterial&&(this._cubemapMaterial=Zr()),this._cubemapMaterial.uniforms.flipEnvMap.value=!1===t.isRenderTargetTexture?-1:1):null===this._equirectMaterial&&(this._equirectMaterial=Kr());const r=i?this._cubemapMaterial:this._equirectMaterial,s=new Ki(this._lodPlanes[0],r);r.uniforms.envMap.value=t;const a=this._cubeSize;Yr(e,0,0,3*a,2*a),n.setRenderTarget(e),n.render(s,Br)}_applyPMREM(t){const e=this._renderer,n=e.autoClear;e.autoClear=!1;const i=this._lodPlanes.length;for(let e=1;e<i;e++){const n=Math.sqrt(this._sigmas[e]*this._sigmas[e]-this._sigmas[e-1]*this._sigmas[e-1]),r=qr[(i-e-1)%qr.length];this._blur(t,e-1,e,n,r)}e.autoClear=n}_blur(t,e,n,i,r){const s=this._pingPongRenderTarget;this._halfBlur(t,s,e,n,i,"latitudinal",r),this._halfBlur(s,t,n,n,i,"longitudinal",r)}_halfBlur(t,e,n,i,r,s,a){const o=this._renderer,l=this._blurMaterial;"latitudinal"!==s&&"longitudinal"!==s&&console.error("blur direction must be either latitudinal or longitudinal!");const h=new Ki(this._lodPlanes[i],l),u=l.uniforms,c=this._sizeLods[n]-1,d=isFinite(r)?Math.PI/(2*c):2*Math.PI/39,p=r/d,f=isFinite(r)?1+Math.floor(3*p):Fr;f>Fr&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${f} samples when the maximum is set to 20`);const m=[];let g=0;for(let t=0;t<Fr;++t){const e=t/p,n=Math.exp(-e*e/2);m.push(n),0===t?g+=n:t<f&&(g+=2*n)}for(let t=0;t<m.length;t++)m[t]=m[t]/g;u.envMap.value=t.texture,u.samples.value=f,u.weights.value=m,u.latitudinal.value="latitudinal"===s,a&&(u.poleAxis.value=a);const{_lodMax:_}=this;u.dTheta.value=d,u.mipInt.value=_-n;const v=this._sizeLods[i];Yr(e,3*v*(i>_-4?i-_+4:0),4*(this._cubeSize-v),3*v,2*v),o.setRenderTarget(e),o.render(h,Br)}};function $r(t,e,n){const i=new Xe(t,e,n);return i.texture.mapping=V,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function Yr(t,e,n,i,r){t.viewport.set(e,n,i,r),t.scissor.set(e,n,i,r)}function Kr(){return new ir({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:Qr(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tgl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}function Zr(){return new ir({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:Qr(),fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tuniform float flipEnvMap;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}function Qr(){return"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t"}function Jr(t){let e=new WeakMap,n=null;function i(t){const n=t.target;n.removeEventListener("dispose",i);const r=e.get(n);void 0!==r&&(e.delete(n),r.dispose())}return{get:function(r){if(r&&r.isTexture){const s=r.mapping,a=303===s||304===s,o=s===k||s===G;if(a||o){let s=e.get(r);const l=void 0!==s?s.texture.pmremVersion:0;if(r.isRenderTargetTexture&&r.pmremVersion!==l)return null===n&&(n=new Xr(t)),s=a?n.fromEquirectangular(r,s):n.fromCubemap(r,s),s.texture.pmremVersion=r.pmremVersion,e.set(r,s),s.texture;if(void 0!==s)return s.texture;{const l=r.image;return a&&l&&l.height>0||o&&l&&function(t){let e=0;const n=6;for(let i=0;i<n;i++)void 0!==t[i]&&e++;return e===n}(l)?(null===n&&(n=new Xr(t)),s=a?n.fromEquirectangular(r):n.fromCubemap(r),s.texture.pmremVersion=r.pmremVersion,e.set(r,s),r.addEventListener("dispose",i),s.texture):null}}}return r},dispose:function(){e=new WeakMap,null!==n&&(n.dispose(),n=null)}}}function ts(t){const e={};function n(n){if(void 0!==e[n])return e[n];let i;switch(n){case"WEBGL_depth_texture":i=t.getExtension("WEBGL_depth_texture")||t.getExtension("MOZ_WEBGL_depth_texture")||t.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":i=t.getExtension("EXT_texture_filter_anisotropic")||t.getExtension("MOZ_EXT_texture_filter_anisotropic")||t.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":i=t.getExtension("WEBGL_compressed_texture_s3tc")||t.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":i=t.getExtension("WEBGL_compressed_texture_pvrtc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:i=t.getExtension(n)}return e[n]=i,i}return{has:function(t){return null!==n(t)},init:function(){n("EXT_color_buffer_float"),n("WEBGL_clip_cull_distance"),n("OES_texture_float_linear"),n("EXT_color_buffer_half_float"),n("WEBGL_multisampled_render_to_texture"),n("WEBGL_render_shared_exponent")},get:function(t){const e=n(t);return null===e&&Ce("THREE.WebGLRenderer: "+t+" extension not supported."),e}}}function es(t,e,n,i){const r={},s=new WeakMap;function a(t){const o=t.target;null!==o.index&&e.remove(o.index);for(const t in o.attributes)e.remove(o.attributes[t]);for(const t in o.morphAttributes){const n=o.morphAttributes[t];for(let t=0,i=n.length;t<i;t++)e.remove(n[t])}o.removeEventListener("dispose",a),delete r[o.id];const l=s.get(o);l&&(e.remove(l),s.delete(o)),i.releaseStatesOfGeometry(o),!0===o.isInstancedBufferGeometry&&delete o._maxInstanceCount,n.memory.geometries--}function o(t){const n=[],i=t.index,r=t.attributes.position;let a=0;if(null!==i){const t=i.array;a=i.version;for(let e=0,i=t.length;e<i;e+=3){const i=t[e+0],r=t[e+1],s=t[e+2];n.push(i,r,r,s,s,i)}}else{if(void 0===r)return;{const t=r.array;a=r.version;for(let e=0,i=t.length/3-1;e<i;e+=3){const t=e+0,i=e+1,r=e+2;n.push(t,i,i,r,r,t)}}}const o=new(we(n)?Ci:Ri)(n,1);o.version=a;const l=s.get(t);l&&e.remove(l),s.set(t,o)}return{get:function(t,e){return!0===r[e.id]||(e.addEventListener("dispose",a),r[e.id]=!0,n.memory.geometries++),e},update:function(n){const i=n.attributes;for(const n in i)e.update(i[n],t.ARRAY_BUFFER);const r=n.morphAttributes;for(const n in r){const i=r[n];for(let n=0,r=i.length;n<r;n++)e.update(i[n],t.ARRAY_BUFFER)}},getWireframeAttribute:function(t){const e=s.get(t);if(e){const n=t.index;null!==n&&e.version<n.version&&o(t)}else o(t);return s.get(t)}}}function ns(t,e,n){let i,r,s;function a(e,a,o){0!==o&&(t.drawElementsInstanced(i,a,r,e*s,o),n.update(a,i,o))}this.setMode=function(t){i=t},this.setIndex=function(t){r=t.type,s=t.bytesPerElement},this.render=function(e,a){t.drawElements(i,a,r,e*s),n.update(a,i,1)},this.renderInstances=a,this.renderMultiDraw=function(t,s,a){if(0===a)return;e.get("WEBGL_multi_draw").multiDrawElementsWEBGL(i,s,0,r,t,0,a);let o=0;for(let t=0;t<a;t++)o+=s[t];n.update(o,i,1)},this.renderMultiDrawInstances=function(t,o,l,h){if(0===l)return;const u=e.get("WEBGL_multi_draw");if(null===u)for(let e=0;e<t.length;e++)a(t[e]/s,o[e],h[e]);else{u.multiDrawElementsInstancedWEBGL(i,o,0,r,t,0,h,0,l);let e=0;for(let t=0;t<l;t++)e+=o[t]*h[t];n.update(e,i,1)}}}function is(t){const e={frame:0,calls:0,triangles:0,points:0,lines:0};return{memory:{geometries:0,textures:0},render:e,programs:null,autoReset:!0,reset:function(){e.calls=0,e.triangles=0,e.points=0,e.lines=0},update:function(n,i,r){switch(e.calls++,i){case t.TRIANGLES:e.triangles+=r*(n/3);break;case t.LINES:e.lines+=r*(n/2);break;case t.LINE_STRIP:e.lines+=r*(n-1);break;case t.LINE_LOOP:e.lines+=r*n;break;case t.POINTS:e.points+=r*n;break;default:console.error("THREE.WebGLInfo: Unknown draw mode:",i)}}}}function rs(t,e,n){const i=new WeakMap,r=new We;return{update:function(s,a,o){const l=s.morphTargetInfluences,h=a.morphAttributes.position||a.morphAttributes.normal||a.morphAttributes.color,u=void 0!==h?h.length:0;let c=i.get(a);if(void 0===c||c.count!==u){void 0!==c&&c.texture.dispose();const d=void 0!==a.morphAttributes.position,p=void 0!==a.morphAttributes.normal,f=void 0!==a.morphAttributes.color,m=a.morphAttributes.position||[],g=a.morphAttributes.normal||[],_=a.morphAttributes.color||[];let v=0;!0===d&&(v=1),!0===p&&(v=2),!0===f&&(v=3);let y=a.attributes.position.count*v,x=1;y>e.maxTextureSize&&(x=Math.ceil(y/e.maxTextureSize),y=e.maxTextureSize);const b=new Float32Array(y*x*4*u),S=new $e(b,y,x,u);S.type=rt,S.needsUpdate=!0;const M=4*v;for(let w=0;w<u;w++){const E=m[w],A=g[w],R=_[w],C=y*x*4*w;for(let N=0;N<E.count;N++){const P=N*M;!0===d&&(r.fromBufferAttribute(E,N),b[C+P+0]=r.x,b[C+P+1]=r.y,b[C+P+2]=r.z,b[C+P+3]=0),!0===p&&(r.fromBufferAttribute(A,N),b[C+P+4]=r.x,b[C+P+5]=r.y,b[C+P+6]=r.z,b[C+P+7]=0),!0===f&&(r.fromBufferAttribute(R,N),b[C+P+8]=r.x,b[C+P+9]=r.y,b[C+P+10]=r.z,b[C+P+11]=4===R.itemSize?r.w:1)}}function T(){S.dispose(),i.delete(a),a.removeEventListener("dispose",T)}c={count:u,texture:S,size:new Se(y,x)},i.set(a,c),a.addEventListener("dispose",T)}if(!0===s.isInstancedMesh&&null!==s.morphTexture)o.getUniforms().setValue(t,"morphTexture",s.morphTexture,n);else{let I=0;for(let U=0;U<l.length;U++)I+=l[U];const L=a.morphTargetsRelative?1:1-I;o.getUniforms().setValue(t,"morphTargetBaseInfluence",L),o.getUniforms().setValue(t,"morphTargetInfluences",l)}o.getUniforms().setValue(t,"morphTargetsTexture",c.texture,n),o.getUniforms().setValue(t,"morphTargetsTextureSize",c.size)}}}function ss(t,e,n,i){let r=new WeakMap;function s(t){const e=t.target;e.removeEventListener("dispose",s),n.remove(e.instanceMatrix),null!==e.instanceColor&&n.remove(e.instanceColor)}return{update:function(a){const o=i.render.frame,l=a.geometry,h=e.get(a,l);if(r.get(h)!==o&&(e.update(h),r.set(h,o)),a.isInstancedMesh&&(!1===a.hasEventListener("dispose",s)&&a.addEventListener("dispose",s),r.get(a)!==o&&(n.update(a.instanceMatrix,t.ARRAY_BUFFER),null!==a.instanceColor&&n.update(a.instanceColor,t.ARRAY_BUFFER),r.set(a,o))),a.isSkinnedMesh){const t=a.skeleton;r.get(t)!==o&&(t.update(),r.set(t,o))}return h},dispose:function(){r=new WeakMap}}}let as=class extends je{constructor(t,e,n,i,r,s,a,o,l,h=1026){if(h!==ct&&h!==dt)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===n&&h===ct&&(n=it),void 0===n&&h===dt&&(n=lt),super(null,i,r,s,a,o,h,n,l),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=void 0!==a?a:q,this.minFilter=void 0!==o?o:q,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}};const os=new je,ls=new as(1,1),hs=new $e,us=new Ye,cs=new cr,ds=[],ps=[],fs=new Float32Array(16),ms=new Float32Array(9),gs=new Float32Array(4);function _s(t,e,n){const i=t[0];if(i<=0||i>0)return t;const r=e*n;let s=ds[r];if(void 0===s&&(s=new Float32Array(r),ds[r]=s),0!==e){i.toArray(s,0);for(let i=1,r=0;i!==e;++i)r+=n,t[i].toArray(s,r)}return s}function vs(t,e){if(t.length!==e.length)return!1;for(let n=0,i=t.length;n<i;n++)if(t[n]!==e[n])return!1;return!0}function ys(t,e){for(let n=0,i=e.length;n<i;n++)t[n]=e[n]}function xs(t,e){let n=ps[e];void 0===n&&(n=new Int32Array(e),ps[e]=n);for(let i=0;i!==e;++i)n[i]=t.allocateTextureUnit();return n}function bs(t,e){const n=this.cache;n[0]!==e&&(t.uniform1f(this.addr,e),n[0]=e)}function Ss(t,e){const n=this.cache;if(void 0!==e.x)n[0]===e.x&&n[1]===e.y||(t.uniform2f(this.addr,e.x,e.y),n[0]=e.x,n[1]=e.y);else{if(vs(n,e))return;t.uniform2fv(this.addr,e),ys(n,e)}}function Ms(t,e){const n=this.cache;if(void 0!==e.x)n[0]===e.x&&n[1]===e.y&&n[2]===e.z||(t.uniform3f(this.addr,e.x,e.y,e.z),n[0]=e.x,n[1]=e.y,n[2]=e.z);else if(void 0!==e.r)n[0]===e.r&&n[1]===e.g&&n[2]===e.b||(t.uniform3f(this.addr,e.r,e.g,e.b),n[0]=e.r,n[1]=e.g,n[2]=e.b);else{if(vs(n,e))return;t.uniform3fv(this.addr,e),ys(n,e)}}function Ts(t,e){const n=this.cache;if(void 0!==e.x)n[0]===e.x&&n[1]===e.y&&n[2]===e.z&&n[3]===e.w||(t.uniform4f(this.addr,e.x,e.y,e.z,e.w),n[0]=e.x,n[1]=e.y,n[2]=e.z,n[3]=e.w);else{if(vs(n,e))return;t.uniform4fv(this.addr,e),ys(n,e)}}function ws(t,e){const n=this.cache,i=e.elements;if(void 0===i){if(vs(n,e))return;t.uniformMatrix2fv(this.addr,!1,e),ys(n,e)}else{if(vs(n,i))return;gs.set(i),t.uniformMatrix2fv(this.addr,!1,gs),ys(n,i)}}function Es(t,e){const n=this.cache,i=e.elements;if(void 0===i){if(vs(n,e))return;t.uniformMatrix3fv(this.addr,!1,e),ys(n,e)}else{if(vs(n,i))return;ms.set(i),t.uniformMatrix3fv(this.addr,!1,ms),ys(n,i)}}function As(t,e){const n=this.cache,i=e.elements;if(void 0===i){if(vs(n,e))return;t.uniformMatrix4fv(this.addr,!1,e),ys(n,e)}else{if(vs(n,i))return;fs.set(i),t.uniformMatrix4fv(this.addr,!1,fs),ys(n,i)}}function Rs(t,e){const n=this.cache;n[0]!==e&&(t.uniform1i(this.addr,e),n[0]=e)}function Cs(t,e){const n=this.cache;if(void 0!==e.x)n[0]===e.x&&n[1]===e.y||(t.uniform2i(this.addr,e.x,e.y),n[0]=e.x,n[1]=e.y);else{if(vs(n,e))return;t.uniform2iv(this.addr,e),ys(n,e)}}function Ns(t,e){const n=this.cache;if(void 0!==e.x)n[0]===e.x&&n[1]===e.y&&n[2]===e.z||(t.uniform3i(this.addr,e.x,e.y,e.z),n[0]=e.x,n[1]=e.y,n[2]=e.z);else{if(vs(n,e))return;t.uniform3iv(this.addr,e),ys(n,e)}}function Ps(t,e){const n=this.cache;if(void 0!==e.x)n[0]===e.x&&n[1]===e.y&&n[2]===e.z&&n[3]===e.w||(t.uniform4i(this.addr,e.x,e.y,e.z,e.w),n[0]=e.x,n[1]=e.y,n[2]=e.z,n[3]=e.w);else{if(vs(n,e))return;t.uniform4iv(this.addr,e),ys(n,e)}}function Is(t,e){const n=this.cache;n[0]!==e&&(t.uniform1ui(this.addr,e),n[0]=e)}function Ls(t,e){const n=this.cache;if(void 0!==e.x)n[0]===e.x&&n[1]===e.y||(t.uniform2ui(this.addr,e.x,e.y),n[0]=e.x,n[1]=e.y);else{if(vs(n,e))return;t.uniform2uiv(this.addr,e),ys(n,e)}}function Us(t,e){const n=this.cache;if(void 0!==e.x)n[0]===e.x&&n[1]===e.y&&n[2]===e.z||(t.uniform3ui(this.addr,e.x,e.y,e.z),n[0]=e.x,n[1]=e.y,n[2]=e.z);else{if(vs(n,e))return;t.uniform3uiv(this.addr,e),ys(n,e)}}function Ds(t,e){const n=this.cache;if(void 0!==e.x)n[0]===e.x&&n[1]===e.y&&n[2]===e.z&&n[3]===e.w||(t.uniform4ui(this.addr,e.x,e.y,e.z,e.w),n[0]=e.x,n[1]=e.y,n[2]=e.z,n[3]=e.w);else{if(vs(n,e))return;t.uniform4uiv(this.addr,e),ys(n,e)}}function Os(t,e,n){const i=this.cache,r=n.allocateTextureUnit();let s;i[0]!==r&&(t.uniform1i(this.addr,r),i[0]=r),this.type===t.SAMPLER_2D_SHADOW?(ls.compareFunction=515,s=ls):s=os,n.setTexture2D(e||s,r)}function Fs(t,e,n){const i=this.cache,r=n.allocateTextureUnit();i[0]!==r&&(t.uniform1i(this.addr,r),i[0]=r),n.setTexture3D(e||us,r)}function Bs(t,e,n){const i=this.cache,r=n.allocateTextureUnit();i[0]!==r&&(t.uniform1i(this.addr,r),i[0]=r),n.setTextureCube(e||cs,r)}function zs(t,e,n){const i=this.cache,r=n.allocateTextureUnit();i[0]!==r&&(t.uniform1i(this.addr,r),i[0]=r),n.setTexture2DArray(e||hs,r)}function ks(t,e){t.uniform1fv(this.addr,e)}function Gs(t,e){const n=_s(e,this.size,2);t.uniform2fv(this.addr,n)}function Vs(t,e){const n=_s(e,this.size,3);t.uniform3fv(this.addr,n)}function Hs(t,e){const n=_s(e,this.size,4);t.uniform4fv(this.addr,n)}function js(t,e){const n=_s(e,this.size,4);t.uniformMatrix2fv(this.addr,!1,n)}function Ws(t,e){const n=_s(e,this.size,9);t.uniformMatrix3fv(this.addr,!1,n)}function qs(t,e){const n=_s(e,this.size,16);t.uniformMatrix4fv(this.addr,!1,n)}function Xs(t,e){t.uniform1iv(this.addr,e)}function $s(t,e){t.uniform2iv(this.addr,e)}function Ys(t,e){t.uniform3iv(this.addr,e)}function Ks(t,e){t.uniform4iv(this.addr,e)}function Zs(t,e){t.uniform1uiv(this.addr,e)}function Qs(t,e){t.uniform2uiv(this.addr,e)}function Js(t,e){t.uniform3uiv(this.addr,e)}function ta(t,e){t.uniform4uiv(this.addr,e)}function ea(t,e,n){const i=this.cache,r=e.length,s=xs(n,r);vs(i,s)||(t.uniform1iv(this.addr,s),ys(i,s));for(let t=0;t!==r;++t)n.setTexture2D(e[t]||os,s[t])}function na(t,e,n){const i=this.cache,r=e.length,s=xs(n,r);vs(i,s)||(t.uniform1iv(this.addr,s),ys(i,s));for(let t=0;t!==r;++t)n.setTexture3D(e[t]||us,s[t])}function ia(t,e,n){const i=this.cache,r=e.length,s=xs(n,r);vs(i,s)||(t.uniform1iv(this.addr,s),ys(i,s));for(let t=0;t!==r;++t)n.setTextureCube(e[t]||cs,s[t])}function ra(t,e,n){const i=this.cache,r=e.length,s=xs(n,r);vs(i,s)||(t.uniform1iv(this.addr,s),ys(i,s));for(let t=0;t!==r;++t)n.setTexture2DArray(e[t]||hs,s[t])}class sa{constructor(t,e,n){this.id=t,this.addr=n,this.cache=[],this.type=e.type,this.setValue=function(t){switch(t){case 5126:return bs;case 35664:return Ss;case 35665:return Ms;case 35666:return Ts;case 35674:return ws;case 35675:return Es;case 35676:return As;case 5124:case 35670:return Rs;case 35667:case 35671:return Cs;case 35668:case 35672:return Ns;case 35669:case 35673:return Ps;case 5125:return Is;case 36294:return Ls;case 36295:return Us;case 36296:return Ds;case 35678:case 36198:case 36298:case 36306:case 35682:return Os;case 35679:case 36299:case 36307:return Fs;case 35680:case 36300:case 36308:case 36293:return Bs;case 36289:case 36303:case 36311:case 36292:return zs}}(e.type)}}class aa{constructor(t,e,n){this.id=t,this.addr=n,this.cache=[],this.type=e.type,this.size=e.size,this.setValue=function(t){switch(t){case 5126:return ks;case 35664:return Gs;case 35665:return Vs;case 35666:return Hs;case 35674:return js;case 35675:return Ws;case 35676:return qs;case 5124:case 35670:return Xs;case 35667:case 35671:return $s;case 35668:case 35672:return Ys;case 35669:case 35673:return Ks;case 5125:return Zs;case 36294:return Qs;case 36295:return Js;case 36296:return ta;case 35678:case 36198:case 36298:case 36306:case 35682:return ea;case 35679:case 36299:case 36307:return na;case 35680:case 36300:case 36308:case 36293:return ia;case 36289:case 36303:case 36311:case 36292:return ra}}(e.type)}}class oa{constructor(t){this.id=t,this.seq=[],this.map={}}setValue(t,e,n){const i=this.seq;for(let r=0,s=i.length;r!==s;++r){const s=i[r];s.setValue(t,e[s.id],n)}}}const la=/(\w+)(\])?(\[|\.)?/g;function ha(t,e){t.seq.push(e),t.map[e.id]=e}function ua(t,e,n){const i=t.name,r=i.length;for(la.lastIndex=0;;){const s=la.exec(i),a=la.lastIndex;let o=s[1];const l="]"===s[2],h=s[3];if(l&&(o|=0),void 0===h||"["===h&&a+2===r){ha(n,void 0===h?new sa(o,t,e):new aa(o,t,e));break}{let t=n.map[o];void 0===t&&(t=new oa(o),ha(n,t)),n=t}}}class ca{constructor(t,e){this.seq=[],this.map={};const n=t.getProgramParameter(e,t.ACTIVE_UNIFORMS);for(let i=0;i<n;++i){const n=t.getActiveUniform(e,i);ua(n,t.getUniformLocation(e,n.name),this)}}setValue(t,e,n,i){const r=this.map[e];void 0!==r&&r.setValue(t,n,i)}setOptional(t,e,n){const i=e[n];void 0!==i&&this.setValue(t,n,i)}static upload(t,e,n,i){for(let r=0,s=e.length;r!==s;++r){const s=e[r],a=n[s.id];!1!==a.needsUpdate&&s.setValue(t,a.value,i)}}static seqWithValue(t,e){const n=[];for(let i=0,r=t.length;i!==r;++i){const r=t[i];r.id in e&&n.push(r)}return n}}function da(t,e,n){const i=t.createShader(e);return t.shaderSource(i,n),t.compileShader(i),i}let pa=0;const fa=new Me;function ma(t,e,n){const i=t.getShaderParameter(e,t.COMPILE_STATUS),r=t.getShaderInfoLog(e).trim();if(i&&""===r)return"";const s=/ERROR: 0:(\d+)/.exec(r);if(s){const i=parseInt(s[1]);return n.toUpperCase()+"\n\n"+r+"\n\n"+function(t,e){const n=t.split("\n"),i=[],r=Math.max(e-6,0),s=Math.min(e+6,n.length);for(let t=r;t<s;t++){const r=t+1;i.push(`${r===e?">":" "} ${r}: ${n[t]}`)}return i.join("\n")}(t.getShaderSource(e),i)}return r}function ga(t,e){const n=function(t){Ne._getMatrix(fa,Ne.workingColorSpace,t);const e=`mat3( ${fa.elements.map((t=>t.toFixed(4)))} )`;switch(Ne.getTransfer(t)){case Kt:return[e,"LinearTransferOETF"];case Zt:return[e,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space: ",t),[e,"LinearTransferOETF"]}}(e);return[`vec4 ${t}( vec4 value ) {`,`\treturn ${n[1]}( vec4( value.rgb * ${n[0]}, value.a ) );`,"}"].join("\n")}function _a(t,e){let n;switch(e){case 1:n="Linear";break;case 2:n="Reinhard";break;case 3:n="Cineon";break;case 4:n="ACESFilmic";break;case 6:n="AgX";break;case 7:n="Neutral";break;case 5:n="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",e),n="Linear"}return"vec3 "+t+"( vec3 color ) { return "+n+"ToneMapping( color ); }"}const va=new Ze;function ya(){Ne.getLuminanceCoefficients(va);return["float luminance( const in vec3 rgb ) {",`\tconst vec3 weights = vec3( ${va.x.toFixed(4)}, ${va.y.toFixed(4)}, ${va.z.toFixed(4)} );`,"\treturn dot( weights, rgb );","}"].join("\n")}function xa(t){return""!==t}function ba(t,e){const n=e.numSpotLightShadows+e.numSpotLightMaps-e.numSpotLightShadowsWithMaps;return t.replace(/NUM_DIR_LIGHTS/g,e.numDirLights).replace(/NUM_SPOT_LIGHTS/g,e.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,e.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,n).replace(/NUM_RECT_AREA_LIGHTS/g,e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,e.numPointLights).replace(/NUM_HEMI_LIGHTS/g,e.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,e.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,e.numPointLightShadows)}function Sa(t,e){return t.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const Ma=/^[ \t]*#include +<([\w\d./]+)>/gm;function Ta(t){return t.replace(Ma,Ea)}const wa=new Map;function Ea(t,e){let n=Mr[e];if(void 0===n){const t=wa.get(e);if(void 0===t)throw new Error("Can not resolve #include <"+e+">");n=Mr[t],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',e,t)}return Ta(n)}const Aa=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Ra(t){return t.replace(Aa,Ca)}function Ca(t,e,n,i){let r="";for(let t=parseInt(e);t<parseInt(n);t++)r+=i.replace(/\[\s*i\s*\]/g,"[ "+t+" ]").replace(/UNROLLED_LOOP_INDEX/g,t);return r}function Na(t){let e=`precision ${t.precision} float;\n\tprecision ${t.precision} int;\n\tprecision ${t.precision} sampler2D;\n\tprecision ${t.precision} samplerCube;\n\tprecision ${t.precision} sampler3D;\n\tprecision ${t.precision} sampler2DArray;\n\tprecision ${t.precision} sampler2DShadow;\n\tprecision ${t.precision} samplerCubeShadow;\n\tprecision ${t.precision} sampler2DArrayShadow;\n\tprecision ${t.precision} isampler2D;\n\tprecision ${t.precision} isampler3D;\n\tprecision ${t.precision} isamplerCube;\n\tprecision ${t.precision} isampler2DArray;\n\tprecision ${t.precision} usampler2D;\n\tprecision ${t.precision} usampler3D;\n\tprecision ${t.precision} usamplerCube;\n\tprecision ${t.precision} usampler2DArray;\n\t`;return"highp"===t.precision?e+="\n#define HIGH_PRECISION":"mediump"===t.precision?e+="\n#define MEDIUM_PRECISION":"lowp"===t.precision&&(e+="\n#define LOW_PRECISION"),e}function Pa(t,e,n,i){const r=t.getContext(),s=n.defines;let a=n.vertexShader,o=n.fragmentShader;const l=function(t){let e="SHADOWMAP_TYPE_BASIC";return 1===t.shadowMapType?e="SHADOWMAP_TYPE_PCF":2===t.shadowMapType?e="SHADOWMAP_TYPE_PCF_SOFT":3===t.shadowMapType&&(e="SHADOWMAP_TYPE_VSM"),e}(n),h=function(t){let e="ENVMAP_TYPE_CUBE";if(t.envMap)switch(t.envMapMode){case k:case G:e="ENVMAP_TYPE_CUBE";break;case V:e="ENVMAP_TYPE_CUBE_UV"}return e}(n),u=function(t){let e="ENVMAP_MODE_REFLECTION";t.envMap&&t.envMapMode===G&&(e="ENVMAP_MODE_REFRACTION");return e}(n),c=function(t){let e="ENVMAP_BLENDING_NONE";if(t.envMap)switch(t.combine){case 0:e="ENVMAP_BLENDING_MULTIPLY";break;case 1:e="ENVMAP_BLENDING_MIX";break;case 2:e="ENVMAP_BLENDING_ADD"}return e}(n),d=function(t){const e=t.envMapCubeUVHeight;if(null===e)return null;const n=Math.log2(e)-2,i=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,n),112)),texelHeight:i,maxMip:n}}(n),p=function(t){return[t.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",t.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(xa).join("\n")}(n),f=function(t){const e=[];for(const n in t){const i=t[n];!1!==i&&e.push("#define "+n+" "+i)}return e.join("\n")}(s),m=r.createProgram();let g,_,v=n.glslVersion?"#version "+n.glslVersion+"\n":"";n.isRawShaderMaterial?(g=["#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,f].filter(xa).join("\n"),g.length>0&&(g+="\n"),_=["#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,f].filter(xa).join("\n"),_.length>0&&(_+="\n")):(g=[Na(n),"#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,f,n.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",n.batching?"#define USE_BATCHING":"",n.batchingColor?"#define USE_BATCHING_COLOR":"",n.instancing?"#define USE_INSTANCING":"",n.instancingColor?"#define USE_INSTANCING_COLOR":"",n.instancingMorph?"#define USE_INSTANCING_MORPH":"",n.useFog&&n.fog?"#define USE_FOG":"",n.useFog&&n.fogExp2?"#define FOG_EXP2":"",n.map?"#define USE_MAP":"",n.envMap?"#define USE_ENVMAP":"",n.envMap?"#define "+u:"",n.lightMap?"#define USE_LIGHTMAP":"",n.aoMap?"#define USE_AOMAP":"",n.bumpMap?"#define USE_BUMPMAP":"",n.normalMap?"#define USE_NORMALMAP":"",n.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",n.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",n.displacementMap?"#define USE_DISPLACEMENTMAP":"",n.emissiveMap?"#define USE_EMISSIVEMAP":"",n.anisotropy?"#define USE_ANISOTROPY":"",n.anisotropyMap?"#define USE_ANISOTROPYMAP":"",n.clearcoatMap?"#define USE_CLEARCOATMAP":"",n.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",n.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",n.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",n.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",n.specularMap?"#define USE_SPECULARMAP":"",n.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",n.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",n.roughnessMap?"#define USE_ROUGHNESSMAP":"",n.metalnessMap?"#define USE_METALNESSMAP":"",n.alphaMap?"#define USE_ALPHAMAP":"",n.alphaHash?"#define USE_ALPHAHASH":"",n.transmission?"#define USE_TRANSMISSION":"",n.transmissionMap?"#define USE_TRANSMISSIONMAP":"",n.thicknessMap?"#define USE_THICKNESSMAP":"",n.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",n.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",n.mapUv?"#define MAP_UV "+n.mapUv:"",n.alphaMapUv?"#define ALPHAMAP_UV "+n.alphaMapUv:"",n.lightMapUv?"#define LIGHTMAP_UV "+n.lightMapUv:"",n.aoMapUv?"#define AOMAP_UV "+n.aoMapUv:"",n.emissiveMapUv?"#define EMISSIVEMAP_UV "+n.emissiveMapUv:"",n.bumpMapUv?"#define BUMPMAP_UV "+n.bumpMapUv:"",n.normalMapUv?"#define NORMALMAP_UV "+n.normalMapUv:"",n.displacementMapUv?"#define DISPLACEMENTMAP_UV "+n.displacementMapUv:"",n.metalnessMapUv?"#define METALNESSMAP_UV "+n.metalnessMapUv:"",n.roughnessMapUv?"#define ROUGHNESSMAP_UV "+n.roughnessMapUv:"",n.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+n.anisotropyMapUv:"",n.clearcoatMapUv?"#define CLEARCOATMAP_UV "+n.clearcoatMapUv:"",n.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+n.clearcoatNormalMapUv:"",n.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+n.clearcoatRoughnessMapUv:"",n.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+n.iridescenceMapUv:"",n.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+n.iridescenceThicknessMapUv:"",n.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+n.sheenColorMapUv:"",n.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+n.sheenRoughnessMapUv:"",n.specularMapUv?"#define SPECULARMAP_UV "+n.specularMapUv:"",n.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+n.specularColorMapUv:"",n.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+n.specularIntensityMapUv:"",n.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+n.transmissionMapUv:"",n.thicknessMapUv?"#define THICKNESSMAP_UV "+n.thicknessMapUv:"",n.vertexTangents&&!1===n.flatShading?"#define USE_TANGENT":"",n.vertexColors?"#define USE_COLOR":"",n.vertexAlphas?"#define USE_COLOR_ALPHA":"",n.vertexUv1s?"#define USE_UV1":"",n.vertexUv2s?"#define USE_UV2":"",n.vertexUv3s?"#define USE_UV3":"",n.pointsUvs?"#define USE_POINTS_UV":"",n.flatShading?"#define FLAT_SHADED":"",n.skinning?"#define USE_SKINNING":"",n.morphTargets?"#define USE_MORPHTARGETS":"",n.morphNormals&&!1===n.flatShading?"#define USE_MORPHNORMALS":"",n.morphColors?"#define USE_MORPHCOLORS":"",n.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+n.morphTextureStride:"",n.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+n.morphTargetsCount:"",n.doubleSided?"#define DOUBLE_SIDED":"",n.flipSided?"#define FLIP_SIDED":"",n.shadowMapEnabled?"#define USE_SHADOWMAP":"",n.shadowMapEnabled?"#define "+l:"",n.sizeAttenuation?"#define USE_SIZEATTENUATION":"",n.numLightProbes>0?"#define USE_LIGHT_PROBES":"",n.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",n.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING","\tattribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR","\tattribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH","\tuniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1","\tattribute vec2 uv1;","#endif","#ifdef USE_UV2","\tattribute vec2 uv2;","#endif","#ifdef USE_UV3","\tattribute vec2 uv3;","#endif","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )","\tattribute vec4 color;","#elif defined( USE_COLOR )","\tattribute vec3 color;","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(xa).join("\n"),_=[Na(n),"#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,f,n.useFog&&n.fog?"#define USE_FOG":"",n.useFog&&n.fogExp2?"#define FOG_EXP2":"",n.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",n.map?"#define USE_MAP":"",n.matcap?"#define USE_MATCAP":"",n.envMap?"#define USE_ENVMAP":"",n.envMap?"#define "+h:"",n.envMap?"#define "+u:"",n.envMap?"#define "+c:"",d?"#define CUBEUV_TEXEL_WIDTH "+d.texelWidth:"",d?"#define CUBEUV_TEXEL_HEIGHT "+d.texelHeight:"",d?"#define CUBEUV_MAX_MIP "+d.maxMip+".0":"",n.lightMap?"#define USE_LIGHTMAP":"",n.aoMap?"#define USE_AOMAP":"",n.bumpMap?"#define USE_BUMPMAP":"",n.normalMap?"#define USE_NORMALMAP":"",n.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",n.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",n.emissiveMap?"#define USE_EMISSIVEMAP":"",n.anisotropy?"#define USE_ANISOTROPY":"",n.anisotropyMap?"#define USE_ANISOTROPYMAP":"",n.clearcoat?"#define USE_CLEARCOAT":"",n.clearcoatMap?"#define USE_CLEARCOATMAP":"",n.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",n.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",n.dispersion?"#define USE_DISPERSION":"",n.iridescence?"#define USE_IRIDESCENCE":"",n.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",n.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",n.specularMap?"#define USE_SPECULARMAP":"",n.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",n.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",n.roughnessMap?"#define USE_ROUGHNESSMAP":"",n.metalnessMap?"#define USE_METALNESSMAP":"",n.alphaMap?"#define USE_ALPHAMAP":"",n.alphaTest?"#define USE_ALPHATEST":"",n.alphaHash?"#define USE_ALPHAHASH":"",n.sheen?"#define USE_SHEEN":"",n.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",n.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",n.transmission?"#define USE_TRANSMISSION":"",n.transmissionMap?"#define USE_TRANSMISSIONMAP":"",n.thicknessMap?"#define USE_THICKNESSMAP":"",n.vertexTangents&&!1===n.flatShading?"#define USE_TANGENT":"",n.vertexColors||n.instancingColor||n.batchingColor?"#define USE_COLOR":"",n.vertexAlphas?"#define USE_COLOR_ALPHA":"",n.vertexUv1s?"#define USE_UV1":"",n.vertexUv2s?"#define USE_UV2":"",n.vertexUv3s?"#define USE_UV3":"",n.pointsUvs?"#define USE_POINTS_UV":"",n.gradientMap?"#define USE_GRADIENTMAP":"",n.flatShading?"#define FLAT_SHADED":"",n.doubleSided?"#define DOUBLE_SIDED":"",n.flipSided?"#define FLIP_SIDED":"",n.shadowMapEnabled?"#define USE_SHADOWMAP":"",n.shadowMapEnabled?"#define "+l:"",n.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",n.numLightProbes>0?"#define USE_LIGHT_PROBES":"",n.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",n.decodeVideoTextureEmissive?"#define DECODE_VIDEO_TEXTURE_EMISSIVE":"",n.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",n.reverseDepthBuffer?"#define USE_REVERSEDEPTHBUF":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",0!==n.toneMapping?"#define TONE_MAPPING":"",0!==n.toneMapping?Mr.tonemapping_pars_fragment:"",0!==n.toneMapping?_a("toneMapping",n.toneMapping):"",n.dithering?"#define DITHERING":"",n.opaque?"#define OPAQUE":"",Mr.colorspace_pars_fragment,ga("linearToOutputTexel",n.outputColorSpace),ya(),n.useDepthPacking?"#define DEPTH_PACKING "+n.depthPacking:"","\n"].filter(xa).join("\n")),a=Ta(a),a=ba(a,n),a=Sa(a,n),o=Ta(o),o=ba(o,n),o=Sa(o,n),a=Ra(a),o=Ra(o),!0!==n.isRawShaderMaterial&&(v="#version 300 es\n",g=[p,"#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+g,_=["#define varying in",n.glslVersion===oe?"":"layout(location = 0) out highp vec4 pc_fragColor;",n.glslVersion===oe?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join("\n")+"\n"+_);const y=v+g+a,x=v+_+o,b=da(r,r.VERTEX_SHADER,y),S=da(r,r.FRAGMENT_SHADER,x);function M(e){if(t.debug.checkShaderErrors){const n=r.getProgramInfoLog(m).trim(),i=r.getShaderInfoLog(b).trim(),s=r.getShaderInfoLog(S).trim();let a=!0,o=!0;if(!1===r.getProgramParameter(m,r.LINK_STATUS))if(a=!1,"function"==typeof t.debug.onShaderError)t.debug.onShaderError(r,m,b,S);else{const t=ma(r,b,"vertex"),i=ma(r,S,"fragment");console.error("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(m,r.VALIDATE_STATUS)+"\n\nMaterial Name: "+e.name+"\nMaterial Type: "+e.type+"\n\nProgram Info Log: "+n+"\n"+t+"\n"+i)}else""!==n?console.warn("THREE.WebGLProgram: Program Info Log:",n):""!==i&&""!==s||(o=!1);o&&(e.diagnostics={runnable:a,programLog:n,vertexShader:{log:i,prefix:g},fragmentShader:{log:s,prefix:_}})}r.deleteShader(b),r.deleteShader(S),T=new ca(r,m),w=function(t,e){const n={},i=t.getProgramParameter(e,t.ACTIVE_ATTRIBUTES);for(let r=0;r<i;r++){const i=t.getActiveAttrib(e,r),s=i.name;let a=1;i.type===t.FLOAT_MAT2&&(a=2),i.type===t.FLOAT_MAT3&&(a=3),i.type===t.FLOAT_MAT4&&(a=4),n[s]={type:i.type,location:t.getAttribLocation(e,s),locationSize:a}}return n}(r,m)}let T,w;r.attachShader(m,b),r.attachShader(m,S),void 0!==n.index0AttributeName?r.bindAttribLocation(m,0,n.index0AttributeName):!0===n.morphTargets&&r.bindAttribLocation(m,0,"position"),r.linkProgram(m),this.getUniforms=function(){return void 0===T&&M(this),T},this.getAttributes=function(){return void 0===w&&M(this),w};let E=!1===n.rendererExtensionParallelShaderCompile;return this.isReady=function(){return!1===E&&(E=r.getProgramParameter(m,37297)),E},this.destroy=function(){i.releaseStatesOfProgram(this),r.deleteProgram(m),this.program=void 0},this.type=n.shaderType,this.name=n.shaderName,this.id=pa++,this.cacheKey=e,this.usedTimes=1,this.program=m,this.vertexShader=b,this.fragmentShader=S,this}let Ia=0;class La{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,n=t.fragmentShader,i=this._getShaderStage(e),r=this._getShaderStage(n),s=this._getShaderCacheForMaterial(t);return!1===s.has(i)&&(s.add(i),i.usedTimes++),!1===s.has(r)&&(s.add(r),r.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const t of e)t.usedTimes--,0===t.usedTimes&&this.shaderCache.delete(t.code);return this.materialCache.delete(t),this}getVertexShaderID(t){return this._getShaderStage(t.vertexShader).id}getFragmentShaderID(t){return this._getShaderStage(t.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;let n=e.get(t);return void 0===n&&(n=new Set,e.set(t,n)),n}_getShaderStage(t){const e=this.shaderCache;let n=e.get(t);return void 0===n&&(n=new Ua(t),e.set(t,n)),n}}class Ua{constructor(t){this.id=Ia++,this.code=t,this.usedTimes=0}}function Da(t,e,n,i,r,s,a){const o=new zn,l=new La,h=new Set,u=[],c=r.logarithmicDepthBuffer,d=r.vertexTextures;let p=r.precision;const f={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function m(t){return h.add(t),0===t?"uv":`uv${t}`}return{getParameters:function(s,o,u,g,_){const v=g.fog,y=_.geometry,x=s.isMeshStandardMaterial?g.environment:null,b=(s.isMeshStandardMaterial?n:e).get(s.envMap||x),S=b&&b.mapping===V?b.image.height:null,M=f[s.type];null!==s.precision&&(p=r.getMaxPrecision(s.precision),p!==s.precision&&console.warn("THREE.WebGLProgram.getParameters:",s.precision,"not supported, using",p,"instead."));const T=y.morphAttributes.position||y.morphAttributes.normal||y.morphAttributes.color,w=void 0!==T?T.length:0;let E,A,R,C,N=0;if(void 0!==y.morphAttributes.position&&(N=1),void 0!==y.morphAttributes.normal&&(N=2),void 0!==y.morphAttributes.color&&(N=3),M){const t=wr[M];E=t.vertexShader,A=t.fragmentShader}else E=s.vertexShader,A=s.fragmentShader,l.update(s),R=l.getVertexShaderID(s),C=l.getFragmentShaderID(s);const P=t.getRenderTarget(),I=t.state.buffers.depth.getReversed(),L=!0===_.isInstancedMesh,U=!0===_.isBatchedMesh,D=!!s.map,O=!!s.matcap,F=!!b,B=!!s.aoMap,z=!!s.lightMap,k=!!s.bumpMap,G=!!s.normalMap,H=!!s.displacementMap,j=!!s.emissiveMap,W=!!s.metalnessMap,q=!!s.roughnessMap,X=s.anisotropy>0,$=s.clearcoat>0,Y=s.dispersion>0,K=s.iridescence>0,Z=s.sheen>0,Q=s.transmission>0,J=X&&!!s.anisotropyMap,tt=$&&!!s.clearcoatMap,et=$&&!!s.clearcoatNormalMap,nt=$&&!!s.clearcoatRoughnessMap,it=K&&!!s.iridescenceMap,rt=K&&!!s.iridescenceThicknessMap,st=Z&&!!s.sheenColorMap,at=Z&&!!s.sheenRoughnessMap,ot=!!s.specularMap,lt=!!s.specularColorMap,ht=!!s.specularIntensityMap,ut=Q&&!!s.transmissionMap,ct=Q&&!!s.thicknessMap,dt=!!s.gradientMap,pt=!!s.alphaMap,ft=s.alphaTest>0,mt=!!s.alphaHash,gt=!!s.extensions;let _t=0;s.toneMapped&&(null!==P&&!0!==P.isXRRenderTarget||(_t=t.toneMapping));const vt={shaderID:M,shaderType:s.type,shaderName:s.name,vertexShader:E,fragmentShader:A,defines:s.defines,customVertexShaderID:R,customFragmentShaderID:C,isRawShaderMaterial:!0===s.isRawShaderMaterial,glslVersion:s.glslVersion,precision:p,batching:U,batchingColor:U&&null!==_._colorsTexture,instancing:L,instancingColor:L&&null!==_.instanceColor,instancingMorph:L&&null!==_.morphTexture,supportsVertexTextures:d,outputColorSpace:null===P?t.outputColorSpace:!0===P.isXRRenderTarget?P.texture.colorSpace:Yt,alphaToCoverage:!!s.alphaToCoverage,map:D,matcap:O,envMap:F,envMapMode:F&&b.mapping,envMapCubeUVHeight:S,aoMap:B,lightMap:z,bumpMap:k,normalMap:G,displacementMap:d&&H,emissiveMap:j,normalMapObjectSpace:G&&1===s.normalMapType,normalMapTangentSpace:G&&0===s.normalMapType,metalnessMap:W,roughnessMap:q,anisotropy:X,anisotropyMap:J,clearcoat:$,clearcoatMap:tt,clearcoatNormalMap:et,clearcoatRoughnessMap:nt,dispersion:Y,iridescence:K,iridescenceMap:it,iridescenceThicknessMap:rt,sheen:Z,sheenColorMap:st,sheenRoughnessMap:at,specularMap:ot,specularColorMap:lt,specularIntensityMap:ht,transmission:Q,transmissionMap:ut,thicknessMap:ct,gradientMap:dt,opaque:!1===s.transparent&&1===s.blending&&!1===s.alphaToCoverage,alphaMap:pt,alphaTest:ft,alphaHash:mt,combine:s.combine,mapUv:D&&m(s.map.channel),aoMapUv:B&&m(s.aoMap.channel),lightMapUv:z&&m(s.lightMap.channel),bumpMapUv:k&&m(s.bumpMap.channel),normalMapUv:G&&m(s.normalMap.channel),displacementMapUv:H&&m(s.displacementMap.channel),emissiveMapUv:j&&m(s.emissiveMap.channel),metalnessMapUv:W&&m(s.metalnessMap.channel),roughnessMapUv:q&&m(s.roughnessMap.channel),anisotropyMapUv:J&&m(s.anisotropyMap.channel),clearcoatMapUv:tt&&m(s.clearcoatMap.channel),clearcoatNormalMapUv:et&&m(s.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:nt&&m(s.clearcoatRoughnessMap.channel),iridescenceMapUv:it&&m(s.iridescenceMap.channel),iridescenceThicknessMapUv:rt&&m(s.iridescenceThicknessMap.channel),sheenColorMapUv:st&&m(s.sheenColorMap.channel),sheenRoughnessMapUv:at&&m(s.sheenRoughnessMap.channel),specularMapUv:ot&&m(s.specularMap.channel),specularColorMapUv:lt&&m(s.specularColorMap.channel),specularIntensityMapUv:ht&&m(s.specularIntensityMap.channel),transmissionMapUv:ut&&m(s.transmissionMap.channel),thicknessMapUv:ct&&m(s.thicknessMap.channel),alphaMapUv:pt&&m(s.alphaMap.channel),vertexTangents:!!y.attributes.tangent&&(G||X),vertexColors:s.vertexColors,vertexAlphas:!0===s.vertexColors&&!!y.attributes.color&&4===y.attributes.color.itemSize,pointsUvs:!0===_.isPoints&&!!y.attributes.uv&&(D||pt),fog:!!v,useFog:!0===s.fog,fogExp2:!!v&&v.isFogExp2,flatShading:!0===s.flatShading,sizeAttenuation:!0===s.sizeAttenuation,logarithmicDepthBuffer:c,reverseDepthBuffer:I,skinning:!0===_.isSkinnedMesh,morphTargets:void 0!==y.morphAttributes.position,morphNormals:void 0!==y.morphAttributes.normal,morphColors:void 0!==y.morphAttributes.color,morphTargetsCount:w,morphTextureStride:N,numDirLights:o.directional.length,numPointLights:o.point.length,numSpotLights:o.spot.length,numSpotLightMaps:o.spotLightMap.length,numRectAreaLights:o.rectArea.length,numHemiLights:o.hemi.length,numDirLightShadows:o.directionalShadowMap.length,numPointLightShadows:o.pointShadowMap.length,numSpotLightShadows:o.spotShadowMap.length,numSpotLightShadowsWithMaps:o.numSpotLightShadowsWithMaps,numLightProbes:o.numLightProbes,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,dithering:s.dithering,shadowMapEnabled:t.shadowMap.enabled&&u.length>0,shadowMapType:t.shadowMap.type,toneMapping:_t,decodeVideoTexture:D&&!0===s.map.isVideoTexture&&Ne.getTransfer(s.map.colorSpace)===Zt,decodeVideoTextureEmissive:j&&!0===s.emissiveMap.isVideoTexture&&Ne.getTransfer(s.emissiveMap.colorSpace)===Zt,premultipliedAlpha:s.premultipliedAlpha,doubleSided:2===s.side,flipSided:1===s.side,useDepthPacking:s.depthPacking>=0,depthPacking:s.depthPacking||0,index0AttributeName:s.index0AttributeName,extensionClipCullDistance:gt&&!0===s.extensions.clipCullDistance&&i.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(gt&&!0===s.extensions.multiDraw||U)&&i.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:i.has("KHR_parallel_shader_compile"),customProgramCacheKey:s.customProgramCacheKey()};return vt.vertexUv1s=h.has(1),vt.vertexUv2s=h.has(2),vt.vertexUv3s=h.has(3),h.clear(),vt},getProgramCacheKey:function(e){const n=[];if(e.shaderID?n.push(e.shaderID):(n.push(e.customVertexShaderID),n.push(e.customFragmentShaderID)),void 0!==e.defines)for(const t in e.defines)n.push(t),n.push(e.defines[t]);return!1===e.isRawShaderMaterial&&(!function(t,e){t.push(e.precision),t.push(e.outputColorSpace),t.push(e.envMapMode),t.push(e.envMapCubeUVHeight),t.push(e.mapUv),t.push(e.alphaMapUv),t.push(e.lightMapUv),t.push(e.aoMapUv),t.push(e.bumpMapUv),t.push(e.normalMapUv),t.push(e.displacementMapUv),t.push(e.emissiveMapUv),t.push(e.metalnessMapUv),t.push(e.roughnessMapUv),t.push(e.anisotropyMapUv),t.push(e.clearcoatMapUv),t.push(e.clearcoatNormalMapUv),t.push(e.clearcoatRoughnessMapUv),t.push(e.iridescenceMapUv),t.push(e.iridescenceThicknessMapUv),t.push(e.sheenColorMapUv),t.push(e.sheenRoughnessMapUv),t.push(e.specularMapUv),t.push(e.specularColorMapUv),t.push(e.specularIntensityMapUv),t.push(e.transmissionMapUv),t.push(e.thicknessMapUv),t.push(e.combine),t.push(e.fogExp2),t.push(e.sizeAttenuation),t.push(e.morphTargetsCount),t.push(e.morphAttributeCount),t.push(e.numDirLights),t.push(e.numPointLights),t.push(e.numSpotLights),t.push(e.numSpotLightMaps),t.push(e.numHemiLights),t.push(e.numRectAreaLights),t.push(e.numDirLightShadows),t.push(e.numPointLightShadows),t.push(e.numSpotLightShadows),t.push(e.numSpotLightShadowsWithMaps),t.push(e.numLightProbes),t.push(e.shadowMapType),t.push(e.toneMapping),t.push(e.numClippingPlanes),t.push(e.numClipIntersection),t.push(e.depthPacking)}(n,e),function(t,e){o.disableAll(),e.supportsVertexTextures&&o.enable(0);e.instancing&&o.enable(1);e.instancingColor&&o.enable(2);e.instancingMorph&&o.enable(3);e.matcap&&o.enable(4);e.envMap&&o.enable(5);e.normalMapObjectSpace&&o.enable(6);e.normalMapTangentSpace&&o.enable(7);e.clearcoat&&o.enable(8);e.iridescence&&o.enable(9);e.alphaTest&&o.enable(10);e.vertexColors&&o.enable(11);e.vertexAlphas&&o.enable(12);e.vertexUv1s&&o.enable(13);e.vertexUv2s&&o.enable(14);e.vertexUv3s&&o.enable(15);e.vertexTangents&&o.enable(16);e.anisotropy&&o.enable(17);e.alphaHash&&o.enable(18);e.batching&&o.enable(19);e.dispersion&&o.enable(20);e.batchingColor&&o.enable(21);t.push(o.mask),o.disableAll(),e.fog&&o.enable(0);e.useFog&&o.enable(1);e.flatShading&&o.enable(2);e.logarithmicDepthBuffer&&o.enable(3);e.reverseDepthBuffer&&o.enable(4);e.skinning&&o.enable(5);e.morphTargets&&o.enable(6);e.morphNormals&&o.enable(7);e.morphColors&&o.enable(8);e.premultipliedAlpha&&o.enable(9);e.shadowMapEnabled&&o.enable(10);e.doubleSided&&o.enable(11);e.flipSided&&o.enable(12);e.useDepthPacking&&o.enable(13);e.dithering&&o.enable(14);e.transmission&&o.enable(15);e.sheen&&o.enable(16);e.opaque&&o.enable(17);e.pointsUvs&&o.enable(18);e.decodeVideoTexture&&o.enable(19);e.decodeVideoTextureEmissive&&o.enable(20);e.alphaToCoverage&&o.enable(21);t.push(o.mask)}(n,e),n.push(t.outputColorSpace)),n.push(e.customProgramCacheKey),n.join()},getUniforms:function(t){const e=f[t.type];let n;if(e){const t=wr[e];n=nr.clone(t.uniforms)}else n=t.uniforms;return n},acquireProgram:function(e,n){let i;for(let t=0,e=u.length;t<e;t++){const e=u[t];if(e.cacheKey===n){i=e,++i.usedTimes;break}}return void 0===i&&(i=new Pa(t,n,e,s),u.push(i)),i},releaseProgram:function(t){if(0==--t.usedTimes){const e=u.indexOf(t);u[e]=u[u.length-1],u.pop(),t.destroy()}},releaseShaderCache:function(t){l.remove(t)},programs:u,dispose:function(){l.dispose()}}}function Oa(){let t=new WeakMap;return{has:function(e){return t.has(e)},get:function(e){let n=t.get(e);return void 0===n&&(n={},t.set(e,n)),n},remove:function(e){t.delete(e)},update:function(e,n,i){t.get(e)[n]=i},dispose:function(){t=new WeakMap}}}function Fa(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 Ba(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}function za(){const t=[];let e=0;const n=[],i=[],r=[];function s(n,i,r,s,a,o){let l=t[e];return void 0===l?(l={id:n.id,object:n,geometry:i,material:r,groupOrder:s,renderOrder:n.renderOrder,z:a,group:o},t[e]=l):(l.id=n.id,l.object=n,l.geometry=i,l.material=r,l.groupOrder=s,l.renderOrder=n.renderOrder,l.z=a,l.group=o),e++,l}return{opaque:n,transmissive:i,transparent:r,init:function(){e=0,n.length=0,i.length=0,r.length=0},push:function(t,e,a,o,l,h){const u=s(t,e,a,o,l,h);a.transmission>0?i.push(u):!0===a.transparent?r.push(u):n.push(u)},unshift:function(t,e,a,o,l,h){const u=s(t,e,a,o,l,h);a.transmission>0?i.unshift(u):!0===a.transparent?r.unshift(u):n.unshift(u)},finish:function(){for(let n=e,i=t.length;n<i;n++){const e=t[n];if(null===e.id)break;e.id=null,e.object=null,e.geometry=null,e.material=null,e.group=null}},sort:function(t,e){n.length>1&&n.sort(t||Fa),i.length>1&&i.sort(e||Ba),r.length>1&&r.sort(e||Ba)}}}function ka(){let t=new WeakMap;return{get:function(e,n){const i=t.get(e);let r;return void 0===i?(r=new za,t.set(e,[r])):n>=i.length?(r=new za,i.push(r)):r=i[n],r},dispose:function(){t=new WeakMap}}}function Ga(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let n;switch(e.type){case"DirectionalLight":n={direction:new Ze,color:new xi};break;case"SpotLight":n={position:new Ze,direction:new Ze,color:new xi,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":n={position:new Ze,color:new xi,distance:0,decay:0};break;case"HemisphereLight":n={direction:new Ze,skyColor:new xi,groundColor:new xi};break;case"RectAreaLight":n={color:new xi,position:new Ze,halfWidth:new Ze,halfHeight:new Ze}}return t[e.id]=n,n}}}let Va=0;function Ha(t,e){return(e.castShadow?2:0)-(t.castShadow?2:0)+(e.map?1:0)-(t.map?1:0)}function ja(t){const e=new Ga,n=function(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let n;switch(e.type){case"DirectionalLight":case"SpotLight":n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Se};break;case"PointLight":n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Se,shadowCameraNear:1,shadowCameraFar:1e3}}return t[e.id]=n,n}}}(),i={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let t=0;t<9;t++)i.probe.push(new Ze);const r=new Ze,s=new Rn,a=new Rn;return{setup:function(r){let s=0,a=0,o=0;for(let t=0;t<9;t++)i.probe[t].set(0,0,0);let l=0,h=0,u=0,c=0,d=0,p=0,f=0,m=0,g=0,_=0,v=0;r.sort(Ha);for(let t=0,y=r.length;t<y;t++){const y=r[t],x=y.color,b=y.intensity,S=y.distance,M=y.shadow&&y.shadow.map?y.shadow.map.texture:null;if(y.isAmbientLight)s+=x.r*b,a+=x.g*b,o+=x.b*b;else if(y.isLightProbe){for(let t=0;t<9;t++)i.probe[t].addScaledVector(y.sh.coefficients[t],b);v++}else if(y.isDirectionalLight){const t=e.get(y);if(t.color.copy(y.color).multiplyScalar(y.intensity),y.castShadow){const t=y.shadow,e=n.get(y);e.shadowIntensity=t.intensity,e.shadowBias=t.bias,e.shadowNormalBias=t.normalBias,e.shadowRadius=t.radius,e.shadowMapSize=t.mapSize,i.directionalShadow[l]=e,i.directionalShadowMap[l]=M,i.directionalShadowMatrix[l]=y.shadow.matrix,p++}i.directional[l]=t,l++}else if(y.isSpotLight){const t=e.get(y);t.position.setFromMatrixPosition(y.matrixWorld),t.color.copy(x).multiplyScalar(b),t.distance=S,t.coneCos=Math.cos(y.angle),t.penumbraCos=Math.cos(y.angle*(1-y.penumbra)),t.decay=y.decay,i.spot[u]=t;const r=y.shadow;if(y.map&&(i.spotLightMap[g]=y.map,g++,r.updateMatrices(y),y.castShadow&&_++),i.spotLightMatrix[u]=r.matrix,y.castShadow){const t=n.get(y);t.shadowIntensity=r.intensity,t.shadowBias=r.bias,t.shadowNormalBias=r.normalBias,t.shadowRadius=r.radius,t.shadowMapSize=r.mapSize,i.spotShadow[u]=t,i.spotShadowMap[u]=M,m++}u++}else if(y.isRectAreaLight){const t=e.get(y);t.color.copy(x).multiplyScalar(b),t.halfWidth.set(.5*y.width,0,0),t.halfHeight.set(0,.5*y.height,0),i.rectArea[c]=t,c++}else if(y.isPointLight){const t=e.get(y);if(t.color.copy(y.color).multiplyScalar(y.intensity),t.distance=y.distance,t.decay=y.decay,y.castShadow){const t=y.shadow,e=n.get(y);e.shadowIntensity=t.intensity,e.shadowBias=t.bias,e.shadowNormalBias=t.normalBias,e.shadowRadius=t.radius,e.shadowMapSize=t.mapSize,e.shadowCameraNear=t.camera.near,e.shadowCameraFar=t.camera.far,i.pointShadow[h]=e,i.pointShadowMap[h]=M,i.pointShadowMatrix[h]=y.shadow.matrix,f++}i.point[h]=t,h++}else if(y.isHemisphereLight){const t=e.get(y);t.skyColor.copy(y.color).multiplyScalar(b),t.groundColor.copy(y.groundColor).multiplyScalar(b),i.hemi[d]=t,d++}}c>0&&(!0===t.has("OES_texture_float_linear")?(i.rectAreaLTC1=Tr.LTC_FLOAT_1,i.rectAreaLTC2=Tr.LTC_FLOAT_2):(i.rectAreaLTC1=Tr.LTC_HALF_1,i.rectAreaLTC2=Tr.LTC_HALF_2)),i.ambient[0]=s,i.ambient[1]=a,i.ambient[2]=o;const y=i.hash;y.directionalLength===l&&y.pointLength===h&&y.spotLength===u&&y.rectAreaLength===c&&y.hemiLength===d&&y.numDirectionalShadows===p&&y.numPointShadows===f&&y.numSpotShadows===m&&y.numSpotMaps===g&&y.numLightProbes===v||(i.directional.length=l,i.spot.length=u,i.rectArea.length=c,i.point.length=h,i.hemi.length=d,i.directionalShadow.length=p,i.directionalShadowMap.length=p,i.pointShadow.length=f,i.pointShadowMap.length=f,i.spotShadow.length=m,i.spotShadowMap.length=m,i.directionalShadowMatrix.length=p,i.pointShadowMatrix.length=f,i.spotLightMatrix.length=m+g-_,i.spotLightMap.length=g,i.numSpotLightShadowsWithMaps=_,i.numLightProbes=v,y.directionalLength=l,y.pointLength=h,y.spotLength=u,y.rectAreaLength=c,y.hemiLength=d,y.numDirectionalShadows=p,y.numPointShadows=f,y.numSpotShadows=m,y.numSpotMaps=g,y.numLightProbes=v,i.version=Va++)},setupView:function(t,e){let n=0,o=0,l=0,h=0,u=0;const c=e.matrixWorldInverse;for(let e=0,d=t.length;e<d;e++){const d=t[e];if(d.isDirectionalLight){const t=i.directional[n];t.direction.setFromMatrixPosition(d.matrixWorld),r.setFromMatrixPosition(d.target.matrixWorld),t.direction.sub(r),t.direction.transformDirection(c),n++}else if(d.isSpotLight){const t=i.spot[l];t.position.setFromMatrixPosition(d.matrixWorld),t.position.applyMatrix4(c),t.direction.setFromMatrixPosition(d.matrixWorld),r.setFromMatrixPosition(d.target.matrixWorld),t.direction.sub(r),t.direction.transformDirection(c),l++}else if(d.isRectAreaLight){const t=i.rectArea[h];t.position.setFromMatrixPosition(d.matrixWorld),t.position.applyMatrix4(c),a.identity(),s.copy(d.matrixWorld),s.premultiply(c),a.extractRotation(s),t.halfWidth.set(.5*d.width,0,0),t.halfHeight.set(0,.5*d.height,0),t.halfWidth.applyMatrix4(a),t.halfHeight.applyMatrix4(a),h++}else if(d.isPointLight){const t=i.point[o];t.position.setFromMatrixPosition(d.matrixWorld),t.position.applyMatrix4(c),o++}else if(d.isHemisphereLight){const t=i.hemi[u];t.direction.setFromMatrixPosition(d.matrixWorld),t.direction.transformDirection(c),u++}}},state:i}}function Wa(t){const e=new ja(t),n=[],i=[];const r={lightsArray:n,shadowsArray:i,camera:null,lights:e,transmissionRenderTarget:{}};return{init:function(t){r.camera=t,n.length=0,i.length=0},state:r,setupLights:function(){e.setup(n)},setupLightsView:function(t){e.setupView(n,t)},pushLight:function(t){n.push(t)},pushShadow:function(t){i.push(t)}}}function qa(t){let e=new WeakMap;return{get:function(n,i=0){const r=e.get(n);let s;return void 0===r?(s=new Wa(t),e.set(n,[s])):i>=r.length?(s=new Wa(t),r.push(s)):s=r[i],s},dispose:function(){e=new WeakMap}}}class Xa extends Mi{static get type(){return"MeshDepthMaterial"}constructor(t){super(),this.isMeshDepthMaterial=!0,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 $a extends Mi{static get type(){return"MeshDistanceMaterial"}constructor(t){super(),this.isMeshDistanceMaterial=!0,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}}function Ya(t,e,n){let i=new yr;const r=new Se,s=new Se,a=new We,o=new Xa({depthPacking:3201}),l=new $a,h={},u=n.maxTextureSize,f={[c]:1,[d]:0,[p]:2},m=new ir({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new Se},radius:{value:4}},vertexShader:"void main() {\n\tgl_Position = vec4( position, 1.0 );\n}",fragmentShader:"uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}"}),g=m.clone();g.defines.HORIZONTAL_PASS=1;const _=new Bi;_.setAttribute("position",new Ai(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const v=new Ki(_,m),y=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let x=this.type;function b(n,i){const s=e.update(v);m.defines.VSM_SAMPLES!==n.blurSamples&&(m.defines.VSM_SAMPLES=n.blurSamples,g.defines.VSM_SAMPLES=n.blurSamples,m.needsUpdate=!0,g.needsUpdate=!0),null===n.mapPass&&(n.mapPass=new Xe(r.x,r.y)),m.uniforms.shadow_pass.value=n.map.texture,m.uniforms.resolution.value=n.mapSize,m.uniforms.radius.value=n.radius,t.setRenderTarget(n.mapPass),t.clear(),t.renderBufferDirect(i,null,s,m,v,null),g.uniforms.shadow_pass.value=n.mapPass.texture,g.uniforms.resolution.value=n.mapSize,g.uniforms.radius.value=n.radius,t.setRenderTarget(n.map),t.clear(),t.renderBufferDirect(i,null,s,g,v,null)}function S(e,n,i,r){let s=null;const a=!0===i.isPointLight?e.customDistanceMaterial:e.customDepthMaterial;if(void 0!==a)s=a;else if(s=!0===i.isPointLight?l:o,t.localClippingEnabled&&!0===n.clipShadows&&Array.isArray(n.clippingPlanes)&&0!==n.clippingPlanes.length||n.displacementMap&&0!==n.displacementScale||n.alphaMap&&n.alphaTest>0||n.map&&n.alphaTest>0){const t=s.uuid,e=n.uuid;let i=h[t];void 0===i&&(i={},h[t]=i);let r=i[e];void 0===r&&(r=s.clone(),i[e]=r,n.addEventListener("dispose",T)),s=r}if(s.visible=n.visible,s.wireframe=n.wireframe,s.side=3===r?null!==n.shadowSide?n.shadowSide:n.side:null!==n.shadowSide?n.shadowSide:f[n.side],s.alphaMap=n.alphaMap,s.alphaTest=n.alphaTest,s.map=n.map,s.clipShadows=n.clipShadows,s.clippingPlanes=n.clippingPlanes,s.clipIntersection=n.clipIntersection,s.displacementMap=n.displacementMap,s.displacementScale=n.displacementScale,s.displacementBias=n.displacementBias,s.wireframeLinewidth=n.wireframeLinewidth,s.linewidth=n.linewidth,!0===i.isPointLight&&!0===s.isMeshDistanceMaterial){t.properties.get(s).light=i}return s}function M(n,r,s,a,o){if(!1===n.visible)return;if(n.layers.test(r.layers)&&(n.isMesh||n.isLine||n.isPoints)&&(n.castShadow||n.receiveShadow&&3===o)&&(!n.frustumCulled||i.intersectsObject(n))){n.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,n.matrixWorld);const i=e.update(n),l=n.material;if(Array.isArray(l)){const e=i.groups;for(let h=0,u=e.length;h<u;h++){const u=e[h],c=l[u.materialIndex];if(c&&c.visible){const e=S(n,c,a,o);n.onBeforeShadow(t,n,r,s,i,e,u),t.renderBufferDirect(s,null,i,e,n,u),n.onAfterShadow(t,n,r,s,i,e,u)}}}else if(l.visible){const e=S(n,l,a,o);n.onBeforeShadow(t,n,r,s,i,e,null),t.renderBufferDirect(s,null,i,e,n,null),n.onAfterShadow(t,n,r,s,i,e,null)}}const l=n.children;for(let t=0,e=l.length;t<e;t++)M(l[t],r,s,a,o)}function T(t){t.target.removeEventListener("dispose",T);for(const e in h){const n=h[e],i=t.target.uuid;if(i in n){n[i].dispose(),delete n[i]}}}this.render=function(e,n,o){if(!1===y.enabled)return;if(!1===y.autoUpdate&&!1===y.needsUpdate)return;if(0===e.length)return;const l=t.getRenderTarget(),h=t.getActiveCubeFace(),c=t.getActiveMipmapLevel(),d=t.state;d.setBlending(0),d.buffers.color.setClear(1,1,1,1),d.buffers.depth.setTest(!0),d.setScissorTest(!1);const p=3!==x&&3===this.type,f=3===x&&3!==this.type;for(let l=0,h=e.length;l<h;l++){const h=e[l],c=h.shadow;if(void 0===c){console.warn("THREE.WebGLShadowMap:",h,"has no shadow.");continue}if(!1===c.autoUpdate&&!1===c.needsUpdate)continue;r.copy(c.mapSize);const m=c.getFrameExtents();if(r.multiply(m),s.copy(c.mapSize),(r.x>u||r.y>u)&&(r.x>u&&(s.x=Math.floor(u/m.x),r.x=s.x*m.x,c.mapSize.x=s.x),r.y>u&&(s.y=Math.floor(u/m.y),r.y=s.y*m.y,c.mapSize.y=s.y)),null===c.map||!0===p||!0===f){const t=3!==this.type?{minFilter:q,magFilter:q}:{};null!==c.map&&c.map.dispose(),c.map=new Xe(r.x,r.y,t),c.map.texture.name=h.name+".shadowMap",c.camera.updateProjectionMatrix()}t.setRenderTarget(c.map),t.clear();const g=c.getViewportCount();for(let t=0;t<g;t++){const e=c.getViewport(t);a.set(s.x*e.x,s.y*e.y,s.x*e.z,s.y*e.w),d.viewport(a),c.updateMatrices(h,t),i=c.getFrustum(),M(n,o,c.camera,h,this.type)}!0!==c.isPointLightShadow&&3===this.type&&b(c,o),c.needsUpdate=!1}x=this.type,y.needsUpdate=!1,t.setRenderTarget(l,h,c)}}const Ka={[I]:1,[U]:6,[O]:7,[D]:5,[L]:0,[B]:2,[z]:4,[F]:3};function Za(t,e){const n=new function(){let e=!1;const n=new We;let i=null;const r=new We(0,0,0,0);return{setMask:function(n){i===n||e||(t.colorMask(n,n,n,n),i=n)},setLocked:function(t){e=t},setClear:function(e,i,s,a,o){!0===o&&(e*=a,i*=a,s*=a),n.set(e,i,s,a),!1===r.equals(n)&&(t.clearColor(e,i,s,a),r.copy(n))},reset:function(){e=!1,i=null,r.set(-1,0,0,0)}}},i=new function(){let n=!1,i=!1,r=null,s=null,a=null;return{setReversed:function(t){if(i!==t){const t=e.get("EXT_clip_control");i?t.clipControlEXT(t.LOWER_LEFT_EXT,t.ZERO_TO_ONE_EXT):t.clipControlEXT(t.LOWER_LEFT_EXT,t.NEGATIVE_ONE_TO_ONE_EXT);const n=a;a=null,this.setClear(n)}i=t},getReversed:function(){return i},setTest:function(e){e?rt(t.DEPTH_TEST):st(t.DEPTH_TEST)},setMask:function(e){r===e||n||(t.depthMask(e),r=e)},setFunc:function(e){if(i&&(e=Ka[e]),s!==e){switch(e){case 0:t.depthFunc(t.NEVER);break;case 1:t.depthFunc(t.ALWAYS);break;case 2:t.depthFunc(t.LESS);break;case 3:default:t.depthFunc(t.LEQUAL);break;case 4:t.depthFunc(t.EQUAL);break;case 5:t.depthFunc(t.GEQUAL);break;case 6:t.depthFunc(t.GREATER);break;case 7:t.depthFunc(t.NOTEQUAL)}s=e}},setLocked:function(t){n=t},setClear:function(e){a!==e&&(i&&(e=1-e),t.clearDepth(e),a=e)},reset:function(){n=!1,r=null,s=null,a=null,i=!1}}},r=new function(){let e=!1,n=null,i=null,r=null,s=null,a=null,o=null,l=null,h=null;return{setTest:function(n){e||(n?rt(t.STENCIL_TEST):st(t.STENCIL_TEST))},setMask:function(i){n===i||e||(t.stencilMask(i),n=i)},setFunc:function(e,n,a){i===e&&r===n&&s===a||(t.stencilFunc(e,n,a),i=e,r=n,s=a)},setOp:function(e,n,i){a===e&&o===n&&l===i||(t.stencilOp(e,n,i),a=e,o=n,l=i)},setLocked:function(t){e=t},setClear:function(e){h!==e&&(t.clearStencil(e),h=e)},reset:function(){e=!1,n=null,i=null,r=null,s=null,a=null,o=null,l=null,h=null}}},s=new WeakMap,a=new WeakMap;let o={},l={},h=new WeakMap,u=[],c=null,d=!1,p=null,I=null,L=null,U=null,D=null,O=null,F=null,B=new xi(0,0,0),z=0,k=!1,G=null,V=null,H=null,j=null,W=null;const q=t.getParameter(t.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let X=!1,$=0;const Y=t.getParameter(t.VERSION);-1!==Y.indexOf("WebGL")?($=parseFloat(/^WebGL (\d)/.exec(Y)[1]),X=$>=1):-1!==Y.indexOf("OpenGL ES")&&($=parseFloat(/^OpenGL ES (\d)/.exec(Y)[1]),X=$>=2);let K=null,Z={};const Q=t.getParameter(t.SCISSOR_BOX),J=t.getParameter(t.VIEWPORT),tt=(new We).fromArray(Q),et=(new We).fromArray(J);function nt(e,n,i,r){const s=new Uint8Array(4),a=t.createTexture();t.bindTexture(e,a),t.texParameteri(e,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(e,t.TEXTURE_MAG_FILTER,t.NEAREST);for(let a=0;a<i;a++)e===t.TEXTURE_3D||e===t.TEXTURE_2D_ARRAY?t.texImage3D(n,0,t.RGBA,1,1,r,0,t.RGBA,t.UNSIGNED_BYTE,s):t.texImage2D(n+a,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,s);return a}const it={};function rt(e){!0!==o[e]&&(t.enable(e),o[e]=!0)}function st(e){!1!==o[e]&&(t.disable(e),o[e]=!1)}it[t.TEXTURE_2D]=nt(t.TEXTURE_2D,t.TEXTURE_2D,1),it[t.TEXTURE_CUBE_MAP]=nt(t.TEXTURE_CUBE_MAP,t.TEXTURE_CUBE_MAP_POSITIVE_X,6),it[t.TEXTURE_2D_ARRAY]=nt(t.TEXTURE_2D_ARRAY,t.TEXTURE_2D_ARRAY,1,1),it[t.TEXTURE_3D]=nt(t.TEXTURE_3D,t.TEXTURE_3D,1,1),n.setClear(0,0,0,1),i.setClear(1),r.setClear(0),rt(t.DEPTH_TEST),i.setFunc(3),ht(!1),ut(1),rt(t.CULL_FACE),lt(0);const at={[f]:t.FUNC_ADD,[m]:t.FUNC_SUBTRACT,[g]:t.FUNC_REVERSE_SUBTRACT};at[103]=t.MIN,at[104]=t.MAX;const ot={[_]:t.ZERO,[v]:t.ONE,[y]:t.SRC_COLOR,[b]:t.SRC_ALPHA,[A]:t.SRC_ALPHA_SATURATE,[w]:t.DST_COLOR,[M]:t.DST_ALPHA,[x]:t.ONE_MINUS_SRC_COLOR,[S]:t.ONE_MINUS_SRC_ALPHA,[E]:t.ONE_MINUS_DST_COLOR,[T]:t.ONE_MINUS_DST_ALPHA,[R]:t.CONSTANT_COLOR,[C]:t.ONE_MINUS_CONSTANT_COLOR,[N]:t.CONSTANT_ALPHA,[P]:t.ONE_MINUS_CONSTANT_ALPHA};function lt(e,n,i,r,s,a,o,l,h,u){if(0!==e){if(!1===d&&(rt(t.BLEND),d=!0),5===e)s=s||n,a=a||i,o=o||r,n===I&&s===D||(t.blendEquationSeparate(at[n],at[s]),I=n,D=s),i===L&&r===U&&a===O&&o===F||(t.blendFuncSeparate(ot[i],ot[r],ot[a],ot[o]),L=i,U=r,O=a,F=o),!1!==l.equals(B)&&h===z||(t.blendColor(l.r,l.g,l.b,h),B.copy(l),z=h),p=e,k=!1;else if(e!==p||u!==k){if(I===f&&D===f||(t.blendEquation(t.FUNC_ADD),I=f,D=f),u)switch(e){case 1:t.blendFuncSeparate(t.ONE,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA);break;case 2:t.blendFunc(t.ONE,t.ONE);break;case 3:t.blendFuncSeparate(t.ZERO,t.ONE_MINUS_SRC_COLOR,t.ZERO,t.ONE);break;case 4:t.blendFuncSeparate(t.ZERO,t.SRC_COLOR,t.ZERO,t.SRC_ALPHA);break;default:console.error("THREE.WebGLState: Invalid blending: ",e)}else switch(e){case 1:t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA);break;case 2:t.blendFunc(t.SRC_ALPHA,t.ONE);break;case 3:t.blendFuncSeparate(t.ZERO,t.ONE_MINUS_SRC_COLOR,t.ZERO,t.ONE);break;case 4:t.blendFunc(t.ZERO,t.SRC_COLOR);break;default:console.error("THREE.WebGLState: Invalid blending: ",e)}L=null,U=null,O=null,F=null,B.set(0,0,0),z=0,p=e,k=u}}else!0===d&&(st(t.BLEND),d=!1)}function ht(e){G!==e&&(e?t.frontFace(t.CW):t.frontFace(t.CCW),G=e)}function ut(e){0!==e?(rt(t.CULL_FACE),e!==V&&(1===e?t.cullFace(t.BACK):2===e?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):st(t.CULL_FACE),V=e}function ct(e,n,i){e?(rt(t.POLYGON_OFFSET_FILL),j===n&&W===i||(t.polygonOffset(n,i),j=n,W=i)):st(t.POLYGON_OFFSET_FILL)}return{buffers:{color:n,depth:i,stencil:r},enable:rt,disable:st,bindFramebuffer:function(e,n){return l[e]!==n&&(t.bindFramebuffer(e,n),l[e]=n,e===t.DRAW_FRAMEBUFFER&&(l[t.FRAMEBUFFER]=n),e===t.FRAMEBUFFER&&(l[t.DRAW_FRAMEBUFFER]=n),!0)},drawBuffers:function(e,n){let i=u,r=!1;if(e){i=h.get(n),void 0===i&&(i=[],h.set(n,i));const s=e.textures;if(i.length!==s.length||i[0]!==t.COLOR_ATTACHMENT0){for(let e=0,n=s.length;e<n;e++)i[e]=t.COLOR_ATTACHMENT0+e;i.length=s.length,r=!0}}else i[0]!==t.BACK&&(i[0]=t.BACK,r=!0);r&&t.drawBuffers(i)},useProgram:function(e){return c!==e&&(t.useProgram(e),c=e,!0)},setBlending:lt,setMaterial:function(e,s){2===e.side?st(t.CULL_FACE):rt(t.CULL_FACE);let a=1===e.side;s&&(a=!a),ht(a),1===e.blending&&!1===e.transparent?lt(0):lt(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.blendColor,e.blendAlpha,e.premultipliedAlpha),i.setFunc(e.depthFunc),i.setTest(e.depthTest),i.setMask(e.depthWrite),n.setMask(e.colorWrite);const o=e.stencilWrite;r.setTest(o),o&&(r.setMask(e.stencilWriteMask),r.setFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),r.setOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),ct(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),!0===e.alphaToCoverage?rt(t.SAMPLE_ALPHA_TO_COVERAGE):st(t.SAMPLE_ALPHA_TO_COVERAGE)},setFlipSided:ht,setCullFace:ut,setLineWidth:function(e){e!==H&&(X&&t.lineWidth(e),H=e)},setPolygonOffset:ct,setScissorTest:function(e){e?rt(t.SCISSOR_TEST):st(t.SCISSOR_TEST)},activeTexture:function(e){void 0===e&&(e=t.TEXTURE0+q-1),K!==e&&(t.activeTexture(e),K=e)},bindTexture:function(e,n,i){void 0===i&&(i=null===K?t.TEXTURE0+q-1:K);let r=Z[i];void 0===r&&(r={type:void 0,texture:void 0},Z[i]=r),r.type===e&&r.texture===n||(K!==i&&(t.activeTexture(i),K=i),t.bindTexture(e,n||it[e]),r.type=e,r.texture=n)},unbindTexture:function(){const e=Z[K];void 0!==e&&void 0!==e.type&&(t.bindTexture(e.type,null),e.type=void 0,e.texture=void 0)},compressedTexImage2D:function(){try{t.compressedTexImage2D.apply(t,arguments)}catch(t){console.error("THREE.WebGLState:",t)}},compressedTexImage3D:function(){try{t.compressedTexImage3D.apply(t,arguments)}catch(t){console.error("THREE.WebGLState:",t)}},texImage2D:function(){try{t.texImage2D.apply(t,arguments)}catch(t){console.error("THREE.WebGLState:",t)}},texImage3D:function(){try{t.texImage3D.apply(t,arguments)}catch(t){console.error("THREE.WebGLState:",t)}},updateUBOMapping:function(e,n){let i=a.get(n);void 0===i&&(i=new WeakMap,a.set(n,i));let r=i.get(e);void 0===r&&(r=t.getUniformBlockIndex(n,e.name),i.set(e,r))},uniformBlockBinding:function(e,n){const i=a.get(n).get(e);s.get(n)!==i&&(t.uniformBlockBinding(n,i,e.__bindingPointIndex),s.set(n,i))},texStorage2D:function(){try{t.texStorage2D.apply(t,arguments)}catch(t){console.error("THREE.WebGLState:",t)}},texStorage3D:function(){try{t.texStorage3D.apply(t,arguments)}catch(t){console.error("THREE.WebGLState:",t)}},texSubImage2D:function(){try{t.texSubImage2D.apply(t,arguments)}catch(t){console.error("THREE.WebGLState:",t)}},texSubImage3D:function(){try{t.texSubImage3D.apply(t,arguments)}catch(t){console.error("THREE.WebGLState:",t)}},compressedTexSubImage2D:function(){try{t.compressedTexSubImage2D.apply(t,arguments)}catch(t){console.error("THREE.WebGLState:",t)}},compressedTexSubImage3D:function(){try{t.compressedTexSubImage3D.apply(t,arguments)}catch(t){console.error("THREE.WebGLState:",t)}},scissor:function(e){!1===tt.equals(e)&&(t.scissor(e.x,e.y,e.z,e.w),tt.copy(e))},viewport:function(e){!1===et.equals(e)&&(t.viewport(e.x,e.y,e.z,e.w),et.copy(e))},reset:function(){t.disable(t.BLEND),t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST),t.disable(t.POLYGON_OFFSET_FILL),t.disable(t.SCISSOR_TEST),t.disable(t.STENCIL_TEST),t.disable(t.SAMPLE_ALPHA_TO_COVERAGE),t.blendEquation(t.FUNC_ADD),t.blendFunc(t.ONE,t.ZERO),t.blendFuncSeparate(t.ONE,t.ZERO,t.ONE,t.ZERO),t.blendColor(0,0,0,0),t.colorMask(!0,!0,!0,!0),t.clearColor(0,0,0,0),t.depthMask(!0),t.depthFunc(t.LESS),i.setReversed(!1),t.clearDepth(1),t.stencilMask(4294967295),t.stencilFunc(t.ALWAYS,0,4294967295),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),t.clearStencil(0),t.cullFace(t.BACK),t.frontFace(t.CCW),t.polygonOffset(0,0),t.activeTexture(t.TEXTURE0),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),t.bindFramebuffer(t.READ_FRAMEBUFFER,null),t.useProgram(null),t.lineWidth(1),t.scissor(0,0,t.canvas.width,t.canvas.height),t.viewport(0,0,t.canvas.width,t.canvas.height),o={},K=null,Z={},l={},h=new WeakMap,u=[],c=null,d=!1,p=null,I=null,L=null,U=null,D=null,O=null,F=null,B=new xi(0,0,0),z=0,k=!1,G=null,V=null,H=null,j=null,W=null,tt.set(0,0,t.canvas.width,t.canvas.height),et.set(0,0,t.canvas.width,t.canvas.height),n.reset(),i.reset(),r.reset()}}}function Qa(t,e,n,i){const r=function(t){switch(t){case Q:case J:return{byteLength:1,components:1};case et:case tt:case st:return{byteLength:2,components:1};case at:case ot:return{byteLength:2,components:4};case it:case nt:case rt:return{byteLength:4,components:1};case ht:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${t}.`)}(i);switch(n){case 1021:case 1024:return t*e;case 1025:return t*e*2;case 1028:case pt:return t*e/r.components*r.byteLength;case 1030:case ft:return t*e*2/r.components*r.byteLength;case 1022:return t*e*3/r.components*r.byteLength;case ut:case mt:return t*e*4/r.components*r.byteLength;case gt:case _t:return Math.floor((t+3)/4)*Math.floor((e+3)/4)*8;case vt:case yt:return Math.floor((t+3)/4)*Math.floor((e+3)/4)*16;case bt:case Mt:return Math.max(t,16)*Math.max(e,8)/4;case xt:case St:return Math.max(t,8)*Math.max(e,8)/2;case Tt:case wt:return Math.floor((t+3)/4)*Math.floor((e+3)/4)*8;case Et:case At:return Math.floor((t+3)/4)*Math.floor((e+3)/4)*16;case Rt:return Math.floor((t+4)/5)*Math.floor((e+3)/4)*16;case Ct:return Math.floor((t+4)/5)*Math.floor((e+4)/5)*16;case Nt:return Math.floor((t+5)/6)*Math.floor((e+4)/5)*16;case Pt:return Math.floor((t+5)/6)*Math.floor((e+5)/6)*16;case It:return Math.floor((t+7)/8)*Math.floor((e+4)/5)*16;case Lt:return Math.floor((t+7)/8)*Math.floor((e+5)/6)*16;case Ut:return Math.floor((t+7)/8)*Math.floor((e+7)/8)*16;case Dt:return Math.floor((t+9)/10)*Math.floor((e+4)/5)*16;case Ot:return Math.floor((t+9)/10)*Math.floor((e+5)/6)*16;case Ft:return Math.floor((t+9)/10)*Math.floor((e+7)/8)*16;case Bt:return Math.floor((t+9)/10)*Math.floor((e+9)/10)*16;case zt:return Math.floor((t+11)/12)*Math.floor((e+9)/10)*16;case kt:return Math.floor((t+11)/12)*Math.floor((e+11)/12)*16;case Gt:case Vt:case Ht:return Math.ceil(t/4)*Math.ceil(e/4)*16;case 36283:case jt:return Math.ceil(t/4)*Math.ceil(e/4)*8;case Wt:case qt:return Math.ceil(t/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${n} format.`)}function Ja(t,e,n,i,r,s,a){const o=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l="undefined"!=typeof navigator&&/OculusBrowser/g.test(navigator.userAgent),h=new Se,u=new WeakMap;let c;const d=new WeakMap;let p=!1;try{p="undefined"!=typeof OffscreenCanvas&&null!==new OffscreenCanvas(1,1).getContext("2d")}catch(t){}function f(t,e){return p?new OffscreenCanvas(t,e):Ee("canvas")}function m(t,e,n){let i=1;const r=G(t);if((r.width>n||r.height>n)&&(i=n/Math.max(r.width,r.height)),i<1){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap||"undefined"!=typeof VideoFrame&&t instanceof VideoFrame){const n=Math.floor(i*r.width),s=Math.floor(i*r.height);void 0===c&&(c=f(n,s));const a=e?f(n,s):c;a.width=n,a.height=s;return a.getContext("2d").drawImage(t,0,0,n,s),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+r.width+"x"+r.height+") to ("+n+"x"+s+")."),a}return"data"in t&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+r.width+"x"+r.height+")."),t}return t}function g(t){return t.generateMipmaps}function _(e){t.generateMipmap(e)}function v(e){return e.isWebGLCubeRenderTarget?t.TEXTURE_CUBE_MAP:e.isWebGL3DRenderTarget?t.TEXTURE_3D:e.isWebGLArrayRenderTarget||e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:t.TEXTURE_2D}function y(n,i,r,s,a=!1){if(null!==n){if(void 0!==t[n])return t[n];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+n+"'")}let o=i;if(i===t.RED&&(r===t.FLOAT&&(o=t.R32F),r===t.HALF_FLOAT&&(o=t.R16F),r===t.UNSIGNED_BYTE&&(o=t.R8)),i===t.RED_INTEGER&&(r===t.UNSIGNED_BYTE&&(o=t.R8UI),r===t.UNSIGNED_SHORT&&(o=t.R16UI),r===t.UNSIGNED_INT&&(o=t.R32UI),r===t.BYTE&&(o=t.R8I),r===t.SHORT&&(o=t.R16I),r===t.INT&&(o=t.R32I)),i===t.RG&&(r===t.FLOAT&&(o=t.RG32F),r===t.HALF_FLOAT&&(o=t.RG16F),r===t.UNSIGNED_BYTE&&(o=t.RG8)),i===t.RG_INTEGER&&(r===t.UNSIGNED_BYTE&&(o=t.RG8UI),r===t.UNSIGNED_SHORT&&(o=t.RG16UI),r===t.UNSIGNED_INT&&(o=t.RG32UI),r===t.BYTE&&(o=t.RG8I),r===t.SHORT&&(o=t.RG16I),r===t.INT&&(o=t.RG32I)),i===t.RGB_INTEGER&&(r===t.UNSIGNED_BYTE&&(o=t.RGB8UI),r===t.UNSIGNED_SHORT&&(o=t.RGB16UI),r===t.UNSIGNED_INT&&(o=t.RGB32UI),r===t.BYTE&&(o=t.RGB8I),r===t.SHORT&&(o=t.RGB16I),r===t.INT&&(o=t.RGB32I)),i===t.RGBA_INTEGER&&(r===t.UNSIGNED_BYTE&&(o=t.RGBA8UI),r===t.UNSIGNED_SHORT&&(o=t.RGBA16UI),r===t.UNSIGNED_INT&&(o=t.RGBA32UI),r===t.BYTE&&(o=t.RGBA8I),r===t.SHORT&&(o=t.RGBA16I),r===t.INT&&(o=t.RGBA32I)),i===t.RGB&&r===t.UNSIGNED_INT_5_9_9_9_REV&&(o=t.RGB9_E5),i===t.RGBA){const e=a?Kt:Ne.getTransfer(s);r===t.FLOAT&&(o=t.RGBA32F),r===t.HALF_FLOAT&&(o=t.RGBA16F),r===t.UNSIGNED_BYTE&&(o=e===Zt?t.SRGB8_ALPHA8:t.RGBA8),r===t.UNSIGNED_SHORT_4_4_4_4&&(o=t.RGBA4),r===t.UNSIGNED_SHORT_5_5_5_1&&(o=t.RGB5_A1)}return o!==t.R16F&&o!==t.R32F&&o!==t.RG16F&&o!==t.RG32F&&o!==t.RGBA16F&&o!==t.RGBA32F||e.get("EXT_color_buffer_float"),o}function x(e,n){let i;return e?null===n||n===it||n===lt?i=t.DEPTH24_STENCIL8:n===rt?i=t.DEPTH32F_STENCIL8:n===et&&(i=t.DEPTH24_STENCIL8,console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):null===n||n===it||n===lt?i=t.DEPTH_COMPONENT24:n===rt?i=t.DEPTH_COMPONENT32F:n===et&&(i=t.DEPTH_COMPONENT16),i}function b(t,e){return!0===g(t)||t.isFramebufferTexture&&t.minFilter!==q&&t.minFilter!==Y?Math.log2(Math.max(e.width,e.height))+1:void 0!==t.mipmaps&&t.mipmaps.length>0?t.mipmaps.length:t.isCompressedTexture&&Array.isArray(t.image)?e.mipmaps.length:1}function S(t){const e=t.target;e.removeEventListener("dispose",S),function(t){const e=i.get(t);if(void 0===e.__webglInit)return;const n=t.source,r=d.get(n);if(r){const i=r[e.__cacheKey];i.usedTimes--,0===i.usedTimes&&T(t),0===Object.keys(r).length&&d.delete(n)}i.remove(t)}(e),e.isVideoTexture&&u.delete(e)}function M(e){const n=e.target;n.removeEventListener("dispose",M),function(e){const n=i.get(e);e.depthTexture&&(e.depthTexture.dispose(),i.remove(e.depthTexture));if(e.isWebGLCubeRenderTarget)for(let e=0;e<6;e++){if(Array.isArray(n.__webglFramebuffer[e]))for(let i=0;i<n.__webglFramebuffer[e].length;i++)t.deleteFramebuffer(n.__webglFramebuffer[e][i]);else t.deleteFramebuffer(n.__webglFramebuffer[e]);n.__webglDepthbuffer&&t.deleteRenderbuffer(n.__webglDepthbuffer[e])}else{if(Array.isArray(n.__webglFramebuffer))for(let e=0;e<n.__webglFramebuffer.length;e++)t.deleteFramebuffer(n.__webglFramebuffer[e]);else t.deleteFramebuffer(n.__webglFramebuffer);if(n.__webglDepthbuffer&&t.deleteRenderbuffer(n.__webglDepthbuffer),n.__webglMultisampledFramebuffer&&t.deleteFramebuffer(n.__webglMultisampledFramebuffer),n.__webglColorRenderbuffer)for(let e=0;e<n.__webglColorRenderbuffer.length;e++)n.__webglColorRenderbuffer[e]&&t.deleteRenderbuffer(n.__webglColorRenderbuffer[e]);n.__webglDepthRenderbuffer&&t.deleteRenderbuffer(n.__webglDepthRenderbuffer)}const r=e.textures;for(let e=0,n=r.length;e<n;e++){const n=i.get(r[e]);n.__webglTexture&&(t.deleteTexture(n.__webglTexture),a.memory.textures--),i.remove(r[e])}i.remove(e)}(n)}function T(e){const n=i.get(e);t.deleteTexture(n.__webglTexture);const r=e.source;delete d.get(r)[n.__cacheKey],a.memory.textures--}let w=0;function E(e,r){const s=i.get(e);if(e.isVideoTexture&&function(t){const e=a.render.frame;u.get(t)!==e&&(u.set(t,e),t.update())}(e),!1===e.isRenderTargetTexture&&e.version>0&&s.__version!==e.version){const t=e.image;if(null===t)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else{if(!1!==t.complete)return void I(s,e,r);console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete")}}n.bindTexture(t.TEXTURE_2D,s.__webglTexture,t.TEXTURE0+r)}const A={[H]:t.REPEAT,[j]:t.CLAMP_TO_EDGE,[W]:t.MIRRORED_REPEAT},R={[q]:t.NEAREST,[X]:t.NEAREST_MIPMAP_NEAREST,[$]:t.NEAREST_MIPMAP_LINEAR,[Y]:t.LINEAR,[K]:t.LINEAR_MIPMAP_NEAREST,[Z]:t.LINEAR_MIPMAP_LINEAR},C={[Jt]:t.NEVER,[ae]:t.ALWAYS,[te]:t.LESS,[ne]:t.LEQUAL,[ee]:t.EQUAL,[se]:t.GEQUAL,[ie]:t.GREATER,[re]:t.NOTEQUAL};function N(n,s){if(s.type!==rt||!1!==e.has("OES_texture_float_linear")||s.magFilter!==Y&&s.magFilter!==K&&s.magFilter!==$&&s.magFilter!==Z&&s.minFilter!==Y&&s.minFilter!==K&&s.minFilter!==$&&s.minFilter!==Z||console.warn("THREE.WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),t.texParameteri(n,t.TEXTURE_WRAP_S,A[s.wrapS]),t.texParameteri(n,t.TEXTURE_WRAP_T,A[s.wrapT]),n!==t.TEXTURE_3D&&n!==t.TEXTURE_2D_ARRAY||t.texParameteri(n,t.TEXTURE_WRAP_R,A[s.wrapR]),t.texParameteri(n,t.TEXTURE_MAG_FILTER,R[s.magFilter]),t.texParameteri(n,t.TEXTURE_MIN_FILTER,R[s.minFilter]),s.compareFunction&&(t.texParameteri(n,t.TEXTURE_COMPARE_MODE,t.COMPARE_REF_TO_TEXTURE),t.texParameteri(n,t.TEXTURE_COMPARE_FUNC,C[s.compareFunction])),!0===e.has("EXT_texture_filter_anisotropic")){if(s.magFilter===q)return;if(s.minFilter!==$&&s.minFilter!==Z)return;if(s.type===rt&&!1===e.has("OES_texture_float_linear"))return;if(s.anisotropy>1||i.get(s).__currentAnisotropy){const a=e.get("EXT_texture_filter_anisotropic");t.texParameterf(n,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(s.anisotropy,r.getMaxAnisotropy())),i.get(s).__currentAnisotropy=s.anisotropy}}}function P(e,n){let i=!1;void 0===e.__webglInit&&(e.__webglInit=!0,n.addEventListener("dispose",S));const r=n.source;let s=d.get(r);void 0===s&&(s={},d.set(r,s));const o=function(t){const e=[];return e.push(t.wrapS),e.push(t.wrapT),e.push(t.wrapR||0),e.push(t.magFilter),e.push(t.minFilter),e.push(t.anisotropy),e.push(t.internalFormat),e.push(t.format),e.push(t.type),e.push(t.generateMipmaps),e.push(t.premultiplyAlpha),e.push(t.flipY),e.push(t.unpackAlignment),e.push(t.colorSpace),e.join()}(n);if(o!==e.__cacheKey){void 0===s[o]&&(s[o]={texture:t.createTexture(),usedTimes:0},a.memory.textures++,i=!0),s[o].usedTimes++;const r=s[e.__cacheKey];void 0!==r&&(s[e.__cacheKey].usedTimes--,0===r.usedTimes&&T(n)),e.__cacheKey=o,e.__webglTexture=s[o].texture}return i}function I(e,a,o){let l=t.TEXTURE_2D;(a.isDataArrayTexture||a.isCompressedArrayTexture)&&(l=t.TEXTURE_2D_ARRAY),a.isData3DTexture&&(l=t.TEXTURE_3D);const h=P(e,a),u=a.source;n.bindTexture(l,e.__webglTexture,t.TEXTURE0+o);const c=i.get(u);if(u.version!==c.__version||!0===h){n.activeTexture(t.TEXTURE0+o);const e=Ne.getPrimaries(Ne.workingColorSpace),i=a.colorSpace===Xt?null:Ne.getPrimaries(a.colorSpace),d=a.colorSpace===Xt||e===i?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,a.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,a.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,d);let p=m(a.image,!1,r.maxTextureSize);p=k(a,p);const f=s.convert(a.format,a.colorSpace),v=s.convert(a.type);let S,M=y(a.internalFormat,f,v,a.colorSpace,a.isVideoTexture);N(l,a);const T=a.mipmaps,w=!0!==a.isVideoTexture,E=void 0===c.__version||!0===h,A=u.dataReady,R=b(a,p);if(a.isDepthTexture)M=x(a.format===dt,a.type),E&&(w?n.texStorage2D(t.TEXTURE_2D,1,M,p.width,p.height):n.texImage2D(t.TEXTURE_2D,0,M,p.width,p.height,0,f,v,null));else if(a.isDataTexture)if(T.length>0){w&&E&&n.texStorage2D(t.TEXTURE_2D,R,M,T[0].width,T[0].height);for(let e=0,i=T.length;e<i;e++)S=T[e],w?A&&n.texSubImage2D(t.TEXTURE_2D,e,0,0,S.width,S.height,f,v,S.data):n.texImage2D(t.TEXTURE_2D,e,M,S.width,S.height,0,f,v,S.data);a.generateMipmaps=!1}else w?(E&&n.texStorage2D(t.TEXTURE_2D,R,M,p.width,p.height),A&&n.texSubImage2D(t.TEXTURE_2D,0,0,0,p.width,p.height,f,v,p.data)):n.texImage2D(t.TEXTURE_2D,0,M,p.width,p.height,0,f,v,p.data);else if(a.isCompressedTexture)if(a.isCompressedArrayTexture){w&&E&&n.texStorage3D(t.TEXTURE_2D_ARRAY,R,M,T[0].width,T[0].height,p.depth);for(let e=0,i=T.length;e<i;e++)if(S=T[e],a.format!==ut)if(null!==f)if(w){if(A)if(a.layerUpdates.size>0){const i=Qa(S.width,S.height,a.format,a.type);for(const r of a.layerUpdates){const s=S.data.subarray(r*i/S.data.BYTES_PER_ELEMENT,(r+1)*i/S.data.BYTES_PER_ELEMENT);n.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,r,S.width,S.height,1,f,s)}a.clearLayerUpdates()}else n.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,S.width,S.height,p.depth,f,S.data)}else n.compressedTexImage3D(t.TEXTURE_2D_ARRAY,e,M,S.width,S.height,p.depth,0,S.data,0,0);else console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else w?A&&n.texSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,S.width,S.height,p.depth,f,v,S.data):n.texImage3D(t.TEXTURE_2D_ARRAY,e,M,S.width,S.height,p.depth,0,f,v,S.data)}else{w&&E&&n.texStorage2D(t.TEXTURE_2D,R,M,T[0].width,T[0].height);for(let e=0,i=T.length;e<i;e++)S=T[e],a.format!==ut?null!==f?w?A&&n.compressedTexSubImage2D(t.TEXTURE_2D,e,0,0,S.width,S.height,f,S.data):n.compressedTexImage2D(t.TEXTURE_2D,e,M,S.width,S.height,0,S.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):w?A&&n.texSubImage2D(t.TEXTURE_2D,e,0,0,S.width,S.height,f,v,S.data):n.texImage2D(t.TEXTURE_2D,e,M,S.width,S.height,0,f,v,S.data)}else if(a.isDataArrayTexture)if(w){if(E&&n.texStorage3D(t.TEXTURE_2D_ARRAY,R,M,p.width,p.height,p.depth),A)if(a.layerUpdates.size>0){const e=Qa(p.width,p.height,a.format,a.type);for(const i of a.layerUpdates){const r=p.data.subarray(i*e/p.data.BYTES_PER_ELEMENT,(i+1)*e/p.data.BYTES_PER_ELEMENT);n.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,i,p.width,p.height,1,f,v,r)}a.clearLayerUpdates()}else n.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,0,p.width,p.height,p.depth,f,v,p.data)}else n.texImage3D(t.TEXTURE_2D_ARRAY,0,M,p.width,p.height,p.depth,0,f,v,p.data);else if(a.isData3DTexture)w?(E&&n.texStorage3D(t.TEXTURE_3D,R,M,p.width,p.height,p.depth),A&&n.texSubImage3D(t.TEXTURE_3D,0,0,0,0,p.width,p.height,p.depth,f,v,p.data)):n.texImage3D(t.TEXTURE_3D,0,M,p.width,p.height,p.depth,0,f,v,p.data);else if(a.isFramebufferTexture){if(E)if(w)n.texStorage2D(t.TEXTURE_2D,R,M,p.width,p.height);else{let e=p.width,i=p.height;for(let r=0;r<R;r++)n.texImage2D(t.TEXTURE_2D,r,M,e,i,0,f,v,null),e>>=1,i>>=1}}else if(T.length>0){if(w&&E){const e=G(T[0]);n.texStorage2D(t.TEXTURE_2D,R,M,e.width,e.height)}for(let e=0,i=T.length;e<i;e++)S=T[e],w?A&&n.texSubImage2D(t.TEXTURE_2D,e,0,0,f,v,S):n.texImage2D(t.TEXTURE_2D,e,M,f,v,S);a.generateMipmaps=!1}else if(w){if(E){const e=G(p);n.texStorage2D(t.TEXTURE_2D,R,M,e.width,e.height)}A&&n.texSubImage2D(t.TEXTURE_2D,0,0,0,f,v,p)}else n.texImage2D(t.TEXTURE_2D,0,M,f,v,p);g(a)&&_(l),c.__version=u.version,a.onUpdate&&a.onUpdate(a)}e.__version=a.version}function L(e,r,a,l,h,u){const c=s.convert(a.format,a.colorSpace),d=s.convert(a.type),p=y(a.internalFormat,c,d,a.colorSpace),f=i.get(r),m=i.get(a);if(m.__renderTarget=r,!f.__hasExternalTextures){const e=Math.max(1,r.width>>u),i=Math.max(1,r.height>>u);h===t.TEXTURE_3D||h===t.TEXTURE_2D_ARRAY?n.texImage3D(h,u,p,e,i,r.depth,0,c,d,null):n.texImage2D(h,u,p,e,i,0,c,d,null)}n.bindFramebuffer(t.FRAMEBUFFER,e),z(r)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,l,h,m.__webglTexture,0,B(r)):(h===t.TEXTURE_2D||h>=t.TEXTURE_CUBE_MAP_POSITIVE_X&&h<=t.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&t.framebufferTexture2D(t.FRAMEBUFFER,l,h,m.__webglTexture,u),n.bindFramebuffer(t.FRAMEBUFFER,null)}function U(e,n,i){if(t.bindRenderbuffer(t.RENDERBUFFER,e),n.depthBuffer){const r=n.depthTexture,s=r&&r.isDepthTexture?r.type:null,a=x(n.stencilBuffer,s),l=n.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,h=B(n);z(n)?o.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,h,a,n.width,n.height):i?t.renderbufferStorageMultisample(t.RENDERBUFFER,h,a,n.width,n.height):t.renderbufferStorage(t.RENDERBUFFER,a,n.width,n.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,l,t.RENDERBUFFER,e)}else{const e=n.textures;for(let r=0;r<e.length;r++){const a=e[r],l=s.convert(a.format,a.colorSpace),h=s.convert(a.type),u=y(a.internalFormat,l,h,a.colorSpace),c=B(n);i&&!1===z(n)?t.renderbufferStorageMultisample(t.RENDERBUFFER,c,u,n.width,n.height):z(n)?o.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,c,u,n.width,n.height):t.renderbufferStorage(t.RENDERBUFFER,u,n.width,n.height)}}t.bindRenderbuffer(t.RENDERBUFFER,null)}function D(e){const r=i.get(e),s=!0===e.isWebGLCubeRenderTarget;if(r.__boundDepthTexture!==e.depthTexture){const t=e.depthTexture;if(r.__depthDisposeCallback&&r.__depthDisposeCallback(),t){const e=()=>{delete r.__boundDepthTexture,delete r.__depthDisposeCallback,t.removeEventListener("dispose",e)};t.addEventListener("dispose",e),r.__depthDisposeCallback=e}r.__boundDepthTexture=t}if(e.depthTexture&&!r.__autoAllocateDepthBuffer){if(s)throw new Error("target.depthTexture not supported in Cube render targets");!function(e,r){if(r&&r.isWebGLCubeRenderTarget)throw new Error("Depth Texture with cube render targets is not supported");if(n.bindFramebuffer(t.FRAMEBUFFER,e),!r.depthTexture||!r.depthTexture.isDepthTexture)throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");const s=i.get(r.depthTexture);s.__renderTarget=r,s.__webglTexture&&r.depthTexture.image.width===r.width&&r.depthTexture.image.height===r.height||(r.depthTexture.image.width=r.width,r.depthTexture.image.height=r.height,r.depthTexture.needsUpdate=!0),E(r.depthTexture,0);const a=s.__webglTexture,l=B(r);if(r.depthTexture.format===ct)z(r)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.TEXTURE_2D,a,0,l):t.framebufferTexture2D(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.TEXTURE_2D,a,0);else{if(r.depthTexture.format!==dt)throw new Error("Unknown depthTexture format");z(r)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.TEXTURE_2D,a,0,l):t.framebufferTexture2D(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.TEXTURE_2D,a,0)}}(r.__webglFramebuffer,e)}else if(s){r.__webglDepthbuffer=[];for(let i=0;i<6;i++)if(n.bindFramebuffer(t.FRAMEBUFFER,r.__webglFramebuffer[i]),void 0===r.__webglDepthbuffer[i])r.__webglDepthbuffer[i]=t.createRenderbuffer(),U(r.__webglDepthbuffer[i],e,!1);else{const n=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,s=r.__webglDepthbuffer[i];t.bindRenderbuffer(t.RENDERBUFFER,s),t.framebufferRenderbuffer(t.FRAMEBUFFER,n,t.RENDERBUFFER,s)}}else if(n.bindFramebuffer(t.FRAMEBUFFER,r.__webglFramebuffer),void 0===r.__webglDepthbuffer)r.__webglDepthbuffer=t.createRenderbuffer(),U(r.__webglDepthbuffer,e,!1);else{const n=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,i=r.__webglDepthbuffer;t.bindRenderbuffer(t.RENDERBUFFER,i),t.framebufferRenderbuffer(t.FRAMEBUFFER,n,t.RENDERBUFFER,i)}n.bindFramebuffer(t.FRAMEBUFFER,null)}const O=[],F=[];function B(t){return Math.min(r.maxSamples,t.samples)}function z(t){const n=i.get(t);return t.samples>0&&!0===e.has("WEBGL_multisampled_render_to_texture")&&!1!==n.__useRenderToTexture}function k(t,e){const n=t.colorSpace,i=t.format,r=t.type;return!0===t.isCompressedTexture||!0===t.isVideoTexture||n!==Yt&&n!==Xt&&(Ne.getTransfer(n)===Zt?i===ut&&r===Q||console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",n)),e}function G(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement?(h.width=t.naturalWidth||t.width,h.height=t.naturalHeight||t.height):"undefined"!=typeof VideoFrame&&t instanceof VideoFrame?(h.width=t.displayWidth,h.height=t.displayHeight):(h.width=t.width,h.height=t.height),h}this.allocateTextureUnit=function(){const t=w;return t>=r.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+t+" texture units while this GPU supports only "+r.maxTextures),w+=1,t},this.resetTextureUnits=function(){w=0},this.setTexture2D=E,this.setTexture2DArray=function(e,r){const s=i.get(e);e.version>0&&s.__version!==e.version?I(s,e,r):n.bindTexture(t.TEXTURE_2D_ARRAY,s.__webglTexture,t.TEXTURE0+r)},this.setTexture3D=function(e,r){const s=i.get(e);e.version>0&&s.__version!==e.version?I(s,e,r):n.bindTexture(t.TEXTURE_3D,s.__webglTexture,t.TEXTURE0+r)},this.setTextureCube=function(e,a){const o=i.get(e);e.version>0&&o.__version!==e.version?function(e,a,o){if(6!==a.image.length)return;const l=P(e,a),h=a.source;n.bindTexture(t.TEXTURE_CUBE_MAP,e.__webglTexture,t.TEXTURE0+o);const u=i.get(h);if(h.version!==u.__version||!0===l){n.activeTexture(t.TEXTURE0+o);const e=Ne.getPrimaries(Ne.workingColorSpace),i=a.colorSpace===Xt?null:Ne.getPrimaries(a.colorSpace),c=a.colorSpace===Xt||e===i?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,a.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,a.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,c);const d=a.isCompressedTexture||a.image[0].isCompressedTexture,p=a.image[0]&&a.image[0].isDataTexture,f=[];for(let t=0;t<6;t++)f[t]=d||p?p?a.image[t].image:a.image[t]:m(a.image[t],!0,r.maxCubemapSize),f[t]=k(a,f[t]);const v=f[0],x=s.convert(a.format,a.colorSpace),S=s.convert(a.type),M=y(a.internalFormat,x,S,a.colorSpace),T=!0!==a.isVideoTexture,w=void 0===u.__version||!0===l,E=h.dataReady;let A,R=b(a,v);if(N(t.TEXTURE_CUBE_MAP,a),d){T&&w&&n.texStorage2D(t.TEXTURE_CUBE_MAP,R,M,v.width,v.height);for(let e=0;e<6;e++){A=f[e].mipmaps;for(let i=0;i<A.length;i++){const r=A[i];a.format!==ut?null!==x?T?E&&n.compressedTexSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,i,0,0,r.width,r.height,x,r.data):n.compressedTexImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,i,M,r.width,r.height,0,r.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"):T?E&&n.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,i,0,0,r.width,r.height,x,S,r.data):n.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,i,M,r.width,r.height,0,x,S,r.data)}}}else{if(A=a.mipmaps,T&&w){A.length>0&&R++;const e=G(f[0]);n.texStorage2D(t.TEXTURE_CUBE_MAP,R,M,e.width,e.height)}for(let e=0;e<6;e++)if(p){T?E&&n.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,f[e].width,f[e].height,x,S,f[e].data):n.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,M,f[e].width,f[e].height,0,x,S,f[e].data);for(let i=0;i<A.length;i++){const r=A[i].image[e].image;T?E&&n.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,i+1,0,0,r.width,r.height,x,S,r.data):n.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,i+1,M,r.width,r.height,0,x,S,r.data)}}else{T?E&&n.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,x,S,f[e]):n.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,M,x,S,f[e]);for(let i=0;i<A.length;i++){const r=A[i];T?E&&n.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,i+1,0,0,x,S,r.image[e]):n.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,i+1,M,x,S,r.image[e])}}}g(a)&&_(t.TEXTURE_CUBE_MAP),u.__version=h.version,a.onUpdate&&a.onUpdate(a)}e.__version=a.version}(o,e,a):n.bindTexture(t.TEXTURE_CUBE_MAP,o.__webglTexture,t.TEXTURE0+a)},this.rebindTextures=function(e,n,r){const s=i.get(e);void 0!==n&&L(s.__webglFramebuffer,e,e.texture,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,0),void 0!==r&&D(e)},this.setupRenderTarget=function(e){const r=e.texture,o=i.get(e),l=i.get(r);e.addEventListener("dispose",M);const h=e.textures,u=!0===e.isWebGLCubeRenderTarget,c=h.length>1;if(c||(void 0===l.__webglTexture&&(l.__webglTexture=t.createTexture()),l.__version=r.version,a.memory.textures++),u){o.__webglFramebuffer=[];for(let e=0;e<6;e++)if(r.mipmaps&&r.mipmaps.length>0){o.__webglFramebuffer[e]=[];for(let n=0;n<r.mipmaps.length;n++)o.__webglFramebuffer[e][n]=t.createFramebuffer()}else o.__webglFramebuffer[e]=t.createFramebuffer()}else{if(r.mipmaps&&r.mipmaps.length>0){o.__webglFramebuffer=[];for(let e=0;e<r.mipmaps.length;e++)o.__webglFramebuffer[e]=t.createFramebuffer()}else o.__webglFramebuffer=t.createFramebuffer();if(c)for(let e=0,n=h.length;e<n;e++){const n=i.get(h[e]);void 0===n.__webglTexture&&(n.__webglTexture=t.createTexture(),a.memory.textures++)}if(e.samples>0&&!1===z(e)){o.__webglMultisampledFramebuffer=t.createFramebuffer(),o.__webglColorRenderbuffer=[],n.bindFramebuffer(t.FRAMEBUFFER,o.__webglMultisampledFramebuffer);for(let n=0;n<h.length;n++){const i=h[n];o.__webglColorRenderbuffer[n]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,o.__webglColorRenderbuffer[n]);const r=s.convert(i.format,i.colorSpace),a=s.convert(i.type),l=y(i.internalFormat,r,a,i.colorSpace,!0===e.isXRRenderTarget),u=B(e);t.renderbufferStorageMultisample(t.RENDERBUFFER,u,l,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+n,t.RENDERBUFFER,o.__webglColorRenderbuffer[n])}t.bindRenderbuffer(t.RENDERBUFFER,null),e.depthBuffer&&(o.__webglDepthRenderbuffer=t.createRenderbuffer(),U(o.__webglDepthRenderbuffer,e,!0)),n.bindFramebuffer(t.FRAMEBUFFER,null)}}if(u){n.bindTexture(t.TEXTURE_CUBE_MAP,l.__webglTexture),N(t.TEXTURE_CUBE_MAP,r);for(let n=0;n<6;n++)if(r.mipmaps&&r.mipmaps.length>0)for(let i=0;i<r.mipmaps.length;i++)L(o.__webglFramebuffer[n][i],e,r,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+n,i);else L(o.__webglFramebuffer[n],e,r,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+n,0);g(r)&&_(t.TEXTURE_CUBE_MAP),n.unbindTexture()}else if(c){for(let r=0,s=h.length;r<s;r++){const s=h[r],a=i.get(s);n.bindTexture(t.TEXTURE_2D,a.__webglTexture),N(t.TEXTURE_2D,s),L(o.__webglFramebuffer,e,s,t.COLOR_ATTACHMENT0+r,t.TEXTURE_2D,0),g(s)&&_(t.TEXTURE_2D)}n.unbindTexture()}else{let i=t.TEXTURE_2D;if((e.isWebGL3DRenderTarget||e.isWebGLArrayRenderTarget)&&(i=e.isWebGL3DRenderTarget?t.TEXTURE_3D:t.TEXTURE_2D_ARRAY),n.bindTexture(i,l.__webglTexture),N(i,r),r.mipmaps&&r.mipmaps.length>0)for(let n=0;n<r.mipmaps.length;n++)L(o.__webglFramebuffer[n],e,r,t.COLOR_ATTACHMENT0,i,n);else L(o.__webglFramebuffer,e,r,t.COLOR_ATTACHMENT0,i,0);g(r)&&_(i),n.unbindTexture()}e.depthBuffer&&D(e)},this.updateRenderTargetMipmap=function(t){const e=t.textures;for(let r=0,s=e.length;r<s;r++){const s=e[r];if(g(s)){const e=v(t),r=i.get(s).__webglTexture;n.bindTexture(e,r),_(e),n.unbindTexture()}}},this.updateMultisampleRenderTarget=function(e){if(e.samples>0)if(!1===z(e)){const r=e.textures,s=e.width,a=e.height;let o=t.COLOR_BUFFER_BIT;const h=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,u=i.get(e),c=r.length>1;if(c)for(let e=0;e<r.length;e++)n.bindFramebuffer(t.FRAMEBUFFER,u.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,null),n.bindFramebuffer(t.FRAMEBUFFER,u.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,null,0);n.bindFramebuffer(t.READ_FRAMEBUFFER,u.__webglMultisampledFramebuffer),n.bindFramebuffer(t.DRAW_FRAMEBUFFER,u.__webglFramebuffer);for(let n=0;n<r.length;n++){if(e.resolveDepthBuffer&&(e.depthBuffer&&(o|=t.DEPTH_BUFFER_BIT),e.stencilBuffer&&e.resolveStencilBuffer&&(o|=t.STENCIL_BUFFER_BIT)),c){t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,u.__webglColorRenderbuffer[n]);const e=i.get(r[n]).__webglTexture;t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0)}t.blitFramebuffer(0,0,s,a,0,0,s,a,o,t.NEAREST),!0===l&&(O.length=0,F.length=0,O.push(t.COLOR_ATTACHMENT0+n),e.depthBuffer&&!1===e.resolveDepthBuffer&&(O.push(h),F.push(h),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,F)),t.invalidateFramebuffer(t.READ_FRAMEBUFFER,O))}if(n.bindFramebuffer(t.READ_FRAMEBUFFER,null),n.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),c)for(let e=0;e<r.length;e++){n.bindFramebuffer(t.FRAMEBUFFER,u.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,u.__webglColorRenderbuffer[e]);const s=i.get(r[e]).__webglTexture;n.bindFramebuffer(t.FRAMEBUFFER,u.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,s,0)}n.bindFramebuffer(t.DRAW_FRAMEBUFFER,u.__webglMultisampledFramebuffer)}else if(e.depthBuffer&&!1===e.resolveDepthBuffer&&l){const n=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,[n])}},this.setupDepthRenderbuffer=D,this.setupFrameBufferTexture=L,this.useMultisampledRTT=z}function to(t,e){return{convert:function(n,i=""){let r;const s=Ne.getTransfer(i);if(n===Q)return t.UNSIGNED_BYTE;if(n===at)return t.UNSIGNED_SHORT_4_4_4_4;if(n===ot)return t.UNSIGNED_SHORT_5_5_5_1;if(n===ht)return t.UNSIGNED_INT_5_9_9_9_REV;if(n===J)return t.BYTE;if(n===tt)return t.SHORT;if(n===et)return t.UNSIGNED_SHORT;if(n===nt)return t.INT;if(n===it)return t.UNSIGNED_INT;if(n===rt)return t.FLOAT;if(n===st)return t.HALF_FLOAT;if(1021===n)return t.ALPHA;if(1022===n)return t.RGB;if(n===ut)return t.RGBA;if(1024===n)return t.LUMINANCE;if(1025===n)return t.LUMINANCE_ALPHA;if(n===ct)return t.DEPTH_COMPONENT;if(n===dt)return t.DEPTH_STENCIL;if(1028===n)return t.RED;if(n===pt)return t.RED_INTEGER;if(1030===n)return t.RG;if(n===ft)return t.RG_INTEGER;if(n===mt)return t.RGBA_INTEGER;if(n===gt||n===_t||n===vt||n===yt)if(s===Zt){if(r=e.get("WEBGL_compressed_texture_s3tc_srgb"),null===r)return null;if(n===gt)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===_t)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===vt)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===yt)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(r=e.get("WEBGL_compressed_texture_s3tc"),null===r)return null;if(n===gt)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===_t)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===vt)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===yt)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(n===xt||n===bt||n===St||n===Mt){if(r=e.get("WEBGL_compressed_texture_pvrtc"),null===r)return null;if(n===xt)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===bt)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===St)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===Mt)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(n===Tt||n===wt||n===Et){if(r=e.get("WEBGL_compressed_texture_etc"),null===r)return null;if(n===Tt||n===wt)return s===Zt?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(n===Et)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}if(n===At||n===Rt||n===Ct||n===Nt||n===Pt||n===It||n===Lt||n===Ut||n===Dt||n===Ot||n===Ft||n===Bt||n===zt||n===kt){if(r=e.get("WEBGL_compressed_texture_astc"),null===r)return null;if(n===At)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===Rt)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===Ct)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===Nt)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===Pt)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===It)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===Lt)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===Ut)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===Dt)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===Ot)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===Ft)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===Bt)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===zt)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===kt)return s===Zt?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}if(n===Gt||n===Vt||n===Ht){if(r=e.get("EXT_texture_compression_bptc"),null===r)return null;if(n===Gt)return s===Zt?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===Vt)return r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===Ht)return r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}if(36283===n||n===jt||n===Wt||n===qt){if(r=e.get("EXT_texture_compression_rgtc"),null===r)return null;if(n===Gt)return r.COMPRESSED_RED_RGTC1_EXT;if(n===jt)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===Wt)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===qt)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return n===lt?t.UNSIGNED_INT_24_8:void 0!==t[n]?t[n]:null}}}class eo extends lr{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}let no=class extends ei{constructor(){super(),this.isGroup=!0,this.type="Group"}};const io={type:"move"};class ro{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return null===this._hand&&(this._hand=new no,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return null===this._targetRay&&(this._targetRay=new no,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new Ze,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new Ze),this._targetRay}getGripSpace(){return null===this._grip&&(this._grip=new no,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new Ze,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new Ze),this._grip}dispatchEvent(t){return null!==this._targetRay&&this._targetRay.dispatchEvent(t),null!==this._grip&&this._grip.dispatchEvent(t),null!==this._hand&&this._hand.dispatchEvent(t),this}connect(t){if(t&&t.hand){const e=this._hand;if(e)for(const n of t.hand.values())this._getHandJoint(e,n)}return this.dispatchEvent({type:"connected",data:t}),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),null!==this._targetRay&&(this._targetRay.visible=!1),null!==this._grip&&(this._grip.visible=!1),null!==this._hand&&(this._hand.visible=!1),this}update(t,e,n){let i=null,r=null,s=null;const a=this._targetRay,o=this._grip,l=this._hand;if(t&&"visible-blurred"!==e.session.visibilityState){if(l&&t.hand){s=!0;for(const i of t.hand.values()){const t=e.getJointPose(i,n),r=this._getHandJoint(l,i);null!==t&&(r.matrix.fromArray(t.transform.matrix),r.matrix.decompose(r.position,r.rotation,r.scale),r.matrixWorldNeedsUpdate=!0,r.jointRadius=t.radius),r.visible=null!==t}const i=l.joints["index-finger-tip"],r=l.joints["thumb-tip"],a=i.position.distanceTo(r.position),o=.02,h=.005;l.inputState.pinching&&a>o+h?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&a<=o-h&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else null!==o&&t.gripSpace&&(r=e.getPose(t.gripSpace,n),null!==r&&(o.matrix.fromArray(r.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,r.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(r.linearVelocity)):o.hasLinearVelocity=!1,r.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(r.angularVelocity)):o.hasAngularVelocity=!1));null!==a&&(i=e.getPose(t.targetRaySpace,n),null===i&&null!==r&&(i=r),null!==i&&(a.matrix.fromArray(i.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,i.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(i.linearVelocity)):a.hasLinearVelocity=!1,i.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(i.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(io)))}return null!==a&&(a.visible=null!==i),null!==o&&(o.visible=null!==r),null!==l&&(l.visible=null!==s),this}_getHandJoint(t,e){if(void 0===t.joints[e.jointName]){const n=new no;n.matrixAutoUpdate=!1,n.visible=!1,t.joints[e.jointName]=n,t.add(n)}return t.joints[e.jointName]}}class so{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(t,e,n){if(null===this.texture){const i=new je;t.properties.get(i).__webglTexture=e.texture,e.depthNear==n.depthNear&&e.depthFar==n.depthFar||(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=i}}getMesh(t){if(null!==this.texture&&null===this.mesh){const e=t.cameras[0].viewport,n=new ir({vertexShader:"\nvoid main() {\n\n\tgl_Position = vec4( position, 1.0 );\n\n}",fragmentShader:"\nuniform sampler2DArray depthColor;\nuniform float depthWidth;\nuniform float depthHeight;\n\nvoid main() {\n\n\tvec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );\n\n\tif ( coord.x >= 1.0 ) {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;\n\n\t} else {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;\n\n\t}\n\n}",uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new Ki(new Sr(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class ao extends ue{constructor(t,e){super();const n=this;let i=null,r=1,s=null,a="local-floor",o=1,l=null,h=null,u=null,c=null,d=null,p=null;const f=new so,m=e.getContextAttributes();let g=null,_=null;const v=[],y=[],x=new Se;let b=null;const S=new lr;S.viewport=new We;const M=new lr;M.viewport=new We;const T=[S,M],w=new eo;let E=null,A=null;function R(t){const e=y.indexOf(t.inputSource);if(-1===e)return;const n=v[e];void 0!==n&&(n.update(t.inputSource,t.frame,l||s),n.dispatchEvent({type:t.type,data:t.inputSource}))}function C(){i.removeEventListener("select",R),i.removeEventListener("selectstart",R),i.removeEventListener("selectend",R),i.removeEventListener("squeeze",R),i.removeEventListener("squeezestart",R),i.removeEventListener("squeezeend",R),i.removeEventListener("end",C),i.removeEventListener("inputsourceschange",N);for(let t=0;t<v.length;t++){const e=y[t];null!==e&&(y[t]=null,v[t].disconnect(e))}E=null,A=null,f.reset(),t.setRenderTarget(g),d=null,c=null,u=null,i=null,_=null,D.stop(),n.isPresenting=!1,t.setPixelRatio(b),t.setSize(x.width,x.height,!1),n.dispatchEvent({type:"sessionend"})}function N(t){for(let e=0;e<t.removed.length;e++){const n=t.removed[e],i=y.indexOf(n);i>=0&&(y[i]=null,v[i].disconnect(n))}for(let e=0;e<t.added.length;e++){const n=t.added[e];let i=y.indexOf(n);if(-1===i){for(let t=0;t<v.length;t++){if(t>=y.length){y.push(n),i=t;break}if(null===y[t]){y[t]=n,i=t;break}}if(-1===i)break}const r=v[i];r&&r.connect(n)}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(t){let e=v[t];return void 0===e&&(e=new ro,v[t]=e),e.getTargetRaySpace()},this.getControllerGrip=function(t){let e=v[t];return void 0===e&&(e=new ro,v[t]=e),e.getGripSpace()},this.getHand=function(t){let e=v[t];return void 0===e&&(e=new ro,v[t]=e),e.getHandSpace()},this.setFramebufferScaleFactor=function(t){r=t,!0===n.isPresenting&&console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(t){a=t,!0===n.isPresenting&&console.warn("THREE.WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return l||s},this.setReferenceSpace=function(t){l=t},this.getBaseLayer=function(){return null!==c?c:d},this.getBinding=function(){return u},this.getFrame=function(){return p},this.getSession=function(){return i},this.setSession=async function(h){if(i=h,null!==i){if(g=t.getRenderTarget(),i.addEventListener("select",R),i.addEventListener("selectstart",R),i.addEventListener("selectend",R),i.addEventListener("squeeze",R),i.addEventListener("squeezestart",R),i.addEventListener("squeezeend",R),i.addEventListener("end",C),i.addEventListener("inputsourceschange",N),!0!==m.xrCompatible&&await e.makeXRCompatible(),b=t.getPixelRatio(),t.getSize(x),void 0===i.renderState.layers){const n={antialias:m.antialias,alpha:!0,depth:m.depth,stencil:m.stencil,framebufferScaleFactor:r};d=new XRWebGLLayer(i,e,n),i.updateRenderState({baseLayer:d}),t.setPixelRatio(1),t.setSize(d.framebufferWidth,d.framebufferHeight,!1),_=new Xe(d.framebufferWidth,d.framebufferHeight,{format:ut,type:Q,colorSpace:t.outputColorSpace,stencilBuffer:m.stencil})}else{let n=null,s=null,a=null;m.depth&&(a=m.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,n=m.stencil?dt:ct,s=m.stencil?lt:it);const o={colorFormat:e.RGBA8,depthFormat:a,scaleFactor:r};u=new XRWebGLBinding(i,e),c=u.createProjectionLayer(o),i.updateRenderState({layers:[c]}),t.setPixelRatio(1),t.setSize(c.textureWidth,c.textureHeight,!1),_=new Xe(c.textureWidth,c.textureHeight,{format:ut,type:Q,depthTexture:new as(c.textureWidth,c.textureHeight,s,void 0,void 0,void 0,void 0,void 0,void 0,n),stencilBuffer:m.stencil,colorSpace:t.outputColorSpace,samples:m.antialias?4:0,resolveDepthBuffer:!1===c.ignoreDepthValues})}_.isXRRenderTarget=!0,this.setFoveation(o),l=null,s=await i.requestReferenceSpace(a),D.setContext(i),D.start(),n.isPresenting=!0,n.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(null!==i)return i.environmentBlendMode},this.getDepthTexture=function(){return f.getDepthTexture()};const P=new Ze,I=new Ze;function L(t,e){null===e?t.matrixWorld.copy(t.matrix):t.matrixWorld.multiplyMatrices(e.matrixWorld,t.matrix),t.matrixWorldInverse.copy(t.matrixWorld).invert()}this.updateCamera=function(t){if(null===i)return;let e=t.near,n=t.far;null!==f.texture&&(f.depthNear>0&&(e=f.depthNear),f.depthFar>0&&(n=f.depthFar)),w.near=M.near=S.near=e,w.far=M.far=S.far=n,E===w.near&&A===w.far||(i.updateRenderState({depthNear:w.near,depthFar:w.far}),E=w.near,A=w.far),S.layers.mask=2|t.layers.mask,M.layers.mask=4|t.layers.mask,w.layers.mask=S.layers.mask|M.layers.mask;const r=t.parent,s=w.cameras;L(w,r);for(let t=0;t<s.length;t++)L(s[t],r);2===s.length?function(t,e,n){P.setFromMatrixPosition(e.matrixWorld),I.setFromMatrixPosition(n.matrixWorld);const i=P.distanceTo(I),r=e.projectionMatrix.elements,s=n.projectionMatrix.elements,a=r[14]/(r[10]-1),o=r[14]/(r[10]+1),l=(r[9]+1)/r[5],h=(r[9]-1)/r[5],u=(r[8]-1)/r[0],c=(s[8]+1)/s[0],d=a*u,p=a*c,f=i/(-u+c),m=f*-u;if(e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.translateX(m),t.translateZ(f),t.matrixWorld.compose(t.position,t.quaternion,t.scale),t.matrixWorldInverse.copy(t.matrixWorld).invert(),-1===r[10])t.projectionMatrix.copy(e.projectionMatrix),t.projectionMatrixInverse.copy(e.projectionMatrixInverse);else{const e=a+f,n=o+f,r=d-m,s=p+(i-m),u=l*o/n*e,c=h*o/n*e;t.projectionMatrix.makePerspective(r,s,u,c,e,n),t.projectionMatrixInverse.copy(t.projectionMatrix).invert()}}(w,S,M):w.projectionMatrix.copy(S.projectionMatrix),function(t,e,n){null===n?t.matrix.copy(e.matrixWorld):(t.matrix.copy(n.matrixWorld),t.matrix.invert(),t.matrix.multiply(e.matrixWorld));t.matrix.decompose(t.position,t.quaternion,t.scale),t.updateMatrixWorld(!0),t.projectionMatrix.copy(e.projectionMatrix),t.projectionMatrixInverse.copy(e.projectionMatrixInverse),t.isPerspectiveCamera&&(t.fov=2*fe*Math.atan(1/t.projectionMatrix.elements[5]),t.zoom=1)}(t,w,r)},this.getCamera=function(){return w},this.getFoveation=function(){if(null!==c||null!==d)return o},this.setFoveation=function(t){o=t,null!==c&&(c.fixedFoveation=t),null!==d&&void 0!==d.fixedFoveation&&(d.fixedFoveation=t)},this.hasDepthSensing=function(){return null!==f.texture},this.getDepthSensingMesh=function(){return f.getMesh(w)};let U=null;const D=new xr;D.setAnimationLoop((function(e,r){if(h=r.getViewerPose(l||s),p=r,null!==h){const e=h.views;null!==d&&(t.setRenderTargetFramebuffer(_,d.framebuffer),t.setRenderTarget(_));let n=!1;e.length!==w.cameras.length&&(w.cameras.length=0,n=!0);for(let i=0;i<e.length;i++){const r=e[i];let s=null;if(null!==d)s=d.getViewport(r);else{const e=u.getViewSubImage(c,r);s=e.viewport,0===i&&(t.setRenderTargetTextures(_,e.colorTexture,c.ignoreDepthValues?void 0:e.depthStencilTexture),t.setRenderTarget(_))}let a=T[i];void 0===a&&(a=new lr,a.layers.enable(i),a.viewport=new We,T[i]=a),a.matrix.fromArray(r.transform.matrix),a.matrix.decompose(a.position,a.quaternion,a.scale),a.projectionMatrix.fromArray(r.projectionMatrix),a.projectionMatrixInverse.copy(a.projectionMatrix).invert(),a.viewport.set(s.x,s.y,s.width,s.height),0===i&&(w.matrix.copy(a.matrix),w.matrix.decompose(w.position,w.quaternion,w.scale)),!0===n&&w.cameras.push(a)}const r=i.enabledFeatures;if(r&&r.includes("depth-sensing")){const n=u.getDepthInformation(e[0]);n&&n.isValid&&n.texture&&f.init(t,n,i.renderState)}}for(let t=0;t<v.length;t++){const e=y[t],n=v[t];null!==e&&void 0!==n&&n.update(e,r,l||s)}U&&U(e,r),r.detectedPlanes&&n.dispatchEvent({type:"planesdetected",data:r}),p=null})),this.setAnimationLoop=function(t){U=t},this.dispose=function(){}}}const oo=new Bn,lo=new Rn;function ho(t,e){function n(t,e){!0===t.matrixAutoUpdate&&t.updateMatrix(),e.value.copy(t.matrix)}function i(t,i){t.opacity.value=i.opacity,i.color&&t.diffuse.value.copy(i.color),i.emissive&&t.emissive.value.copy(i.emissive).multiplyScalar(i.emissiveIntensity),i.map&&(t.map.value=i.map,n(i.map,t.mapTransform)),i.alphaMap&&(t.alphaMap.value=i.alphaMap,n(i.alphaMap,t.alphaMapTransform)),i.bumpMap&&(t.bumpMap.value=i.bumpMap,n(i.bumpMap,t.bumpMapTransform),t.bumpScale.value=i.bumpScale,1===i.side&&(t.bumpScale.value*=-1)),i.normalMap&&(t.normalMap.value=i.normalMap,n(i.normalMap,t.normalMapTransform),t.normalScale.value.copy(i.normalScale),1===i.side&&t.normalScale.value.negate()),i.displacementMap&&(t.displacementMap.value=i.displacementMap,n(i.displacementMap,t.displacementMapTransform),t.displacementScale.value=i.displacementScale,t.displacementBias.value=i.displacementBias),i.emissiveMap&&(t.emissiveMap.value=i.emissiveMap,n(i.emissiveMap,t.emissiveMapTransform)),i.specularMap&&(t.specularMap.value=i.specularMap,n(i.specularMap,t.specularMapTransform)),i.alphaTest>0&&(t.alphaTest.value=i.alphaTest);const r=e.get(i),s=r.envMap,a=r.envMapRotation;s&&(t.envMap.value=s,oo.copy(a),oo.x*=-1,oo.y*=-1,oo.z*=-1,s.isCubeTexture&&!1===s.isRenderTargetTexture&&(oo.y*=-1,oo.z*=-1),t.envMapRotation.value.setFromMatrix4(lo.makeRotationFromEuler(oo)),t.flipEnvMap.value=s.isCubeTexture&&!1===s.isRenderTargetTexture?-1:1,t.reflectivity.value=i.reflectivity,t.ior.value=i.ior,t.refractionRatio.value=i.refractionRatio),i.lightMap&&(t.lightMap.value=i.lightMap,t.lightMapIntensity.value=i.lightMapIntensity,n(i.lightMap,t.lightMapTransform)),i.aoMap&&(t.aoMap.value=i.aoMap,t.aoMapIntensity.value=i.aoMapIntensity,n(i.aoMap,t.aoMapTransform))}return{refreshFogUniforms:function(e,n){n.color.getRGB(e.fogColor.value,er(t)),n.isFog?(e.fogNear.value=n.near,e.fogFar.value=n.far):n.isFogExp2&&(e.fogDensity.value=n.density)},refreshMaterialUniforms:function(t,r,s,a,o){r.isMeshBasicMaterial||r.isMeshLambertMaterial?i(t,r):r.isMeshToonMaterial?(i(t,r),function(t,e){e.gradientMap&&(t.gradientMap.value=e.gradientMap)}(t,r)):r.isMeshPhongMaterial?(i(t,r),function(t,e){t.specular.value.copy(e.specular),t.shininess.value=Math.max(e.shininess,1e-4)}(t,r)):r.isMeshStandardMaterial?(i(t,r),function(t,e){t.metalness.value=e.metalness,e.metalnessMap&&(t.metalnessMap.value=e.metalnessMap,n(e.metalnessMap,t.metalnessMapTransform));t.roughness.value=e.roughness,e.roughnessMap&&(t.roughnessMap.value=e.roughnessMap,n(e.roughnessMap,t.roughnessMapTransform));e.envMap&&(t.envMapIntensity.value=e.envMapIntensity)}(t,r),r.isMeshPhysicalMaterial&&function(t,e,i){t.ior.value=e.ior,e.sheen>0&&(t.sheenColor.value.copy(e.sheenColor).multiplyScalar(e.sheen),t.sheenRoughness.value=e.sheenRoughness,e.sheenColorMap&&(t.sheenColorMap.value=e.sheenColorMap,n(e.sheenColorMap,t.sheenColorMapTransform)),e.sheenRoughnessMap&&(t.sheenRoughnessMap.value=e.sheenRoughnessMap,n(e.sheenRoughnessMap,t.sheenRoughnessMapTransform)));e.clearcoat>0&&(t.clearcoat.value=e.clearcoat,t.clearcoatRoughness.value=e.clearcoatRoughness,e.clearcoatMap&&(t.clearcoatMap.value=e.clearcoatMap,n(e.clearcoatMap,t.clearcoatMapTransform)),e.clearcoatRoughnessMap&&(t.clearcoatRoughnessMap.value=e.clearcoatRoughnessMap,n(e.clearcoatRoughnessMap,t.clearcoatRoughnessMapTransform)),e.clearcoatNormalMap&&(t.clearcoatNormalMap.value=e.clearcoatNormalMap,n(e.clearcoatNormalMap,t.clearcoatNormalMapTransform),t.clearcoatNormalScale.value.copy(e.clearcoatNormalScale),1===e.side&&t.clearcoatNormalScale.value.negate()));e.dispersion>0&&(t.dispersion.value=e.dispersion);e.iridescence>0&&(t.iridescence.value=e.iridescence,t.iridescenceIOR.value=e.iridescenceIOR,t.iridescenceThicknessMinimum.value=e.iridescenceThicknessRange[0],t.iridescenceThicknessMaximum.value=e.iridescenceThicknessRange[1],e.iridescenceMap&&(t.iridescenceMap.value=e.iridescenceMap,n(e.iridescenceMap,t.iridescenceMapTransform)),e.iridescenceThicknessMap&&(t.iridescenceThicknessMap.value=e.iridescenceThicknessMap,n(e.iridescenceThicknessMap,t.iridescenceThicknessMapTransform)));e.transmission>0&&(t.transmission.value=e.transmission,t.transmissionSamplerMap.value=i.texture,t.transmissionSamplerSize.value.set(i.width,i.height),e.transmissionMap&&(t.transmissionMap.value=e.transmissionMap,n(e.transmissionMap,t.transmissionMapTransform)),t.thickness.value=e.thickness,e.thicknessMap&&(t.thicknessMap.value=e.thicknessMap,n(e.thicknessMap,t.thicknessMapTransform)),t.attenuationDistance.value=e.attenuationDistance,t.attenuationColor.value.copy(e.attenuationColor));e.anisotropy>0&&(t.anisotropyVector.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation)),e.anisotropyMap&&(t.anisotropyMap.value=e.anisotropyMap,n(e.anisotropyMap,t.anisotropyMapTransform)));t.specularIntensity.value=e.specularIntensity,t.specularColor.value.copy(e.specularColor),e.specularColorMap&&(t.specularColorMap.value=e.specularColorMap,n(e.specularColorMap,t.specularColorMapTransform));e.specularIntensityMap&&(t.specularIntensityMap.value=e.specularIntensityMap,n(e.specularIntensityMap,t.specularIntensityMapTransform))}(t,r,o)):r.isMeshMatcapMaterial?(i(t,r),function(t,e){e.matcap&&(t.matcap.value=e.matcap)}(t,r)):r.isMeshDepthMaterial?i(t,r):r.isMeshDistanceMaterial?(i(t,r),function(t,n){const i=e.get(n).light;t.referencePosition.value.setFromMatrixPosition(i.matrixWorld),t.nearDistance.value=i.shadow.camera.near,t.farDistance.value=i.shadow.camera.far}(t,r)):r.isMeshNormalMaterial?i(t,r):r.isLineBasicMaterial?(function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,e.map&&(t.map.value=e.map,n(e.map,t.mapTransform))}(t,r),r.isLineDashedMaterial&&function(t,e){t.dashSize.value=e.dashSize,t.totalSize.value=e.dashSize+e.gapSize,t.scale.value=e.scale}(t,r)):r.isPointsMaterial?function(t,e,i,r){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.size.value=e.size*i,t.scale.value=.5*r,e.map&&(t.map.value=e.map,n(e.map,t.uvTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,n(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,r,s,a):r.isSpriteMaterial?function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.rotation.value=e.rotation,e.map&&(t.map.value=e.map,n(e.map,t.mapTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,n(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,r):r.isShadowMaterial?(t.color.value.copy(r.color),t.opacity.value=r.opacity):r.isShaderMaterial&&(r.uniformsNeedUpdate=!1)}}}function uo(t,e,n,i){let r={},s={},a=[];const o=t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS);function l(t,e,n,i){const r=t.value,s=e+"_"+n;if(void 0===i[s])return i[s]="number"==typeof r||"boolean"==typeof r?r:r.clone(),!0;{const t=i[s];if("number"==typeof r||"boolean"==typeof r){if(t!==r)return i[s]=r,!0}else if(!1===t.equals(r))return t.copy(r),!0}return!1}function h(t){const e={boundary:0,storage:0};return"number"==typeof t||"boolean"==typeof t?(e.boundary=4,e.storage=4):t.isVector2?(e.boundary=8,e.storage=8):t.isVector3||t.isColor?(e.boundary=16,e.storage=12):t.isVector4?(e.boundary=16,e.storage=16):t.isMatrix3?(e.boundary=48,e.storage=48):t.isMatrix4?(e.boundary=64,e.storage=64):t.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",t),e}function u(e){const n=e.target;n.removeEventListener("dispose",u);const i=a.indexOf(n.__bindingPointIndex);a.splice(i,1),t.deleteBuffer(r[n.id]),delete r[n.id],delete s[n.id]}return{bind:function(t,e){const n=e.program;i.uniformBlockBinding(t,n)},update:function(n,c){let d=r[n.id];void 0===d&&(!function(t){const e=t.uniforms;let n=0;const i=16;for(let t=0,r=e.length;t<r;t++){const r=Array.isArray(e[t])?e[t]:[e[t]];for(let t=0,e=r.length;t<e;t++){const e=r[t],s=Array.isArray(e.value)?e.value:[e.value];for(let t=0,r=s.length;t<r;t++){const r=h(s[t]),a=n%i,o=a%r.boundary,l=a+o;n+=o,0!==l&&i-l<r.storage&&(n+=i-l),e.__data=new Float32Array(r.storage/Float32Array.BYTES_PER_ELEMENT),e.__offset=n,n+=r.storage}}}const r=n%i;r>0&&(n+=i-r);t.__size=n,t.__cache={}}(n),d=function(e){const n=function(){for(let t=0;t<o;t++)if(-1===a.indexOf(t))return a.push(t),t;return console.error("THREE.WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."),0}();e.__bindingPointIndex=n;const i=t.createBuffer(),r=e.__size,s=e.usage;return t.bindBuffer(t.UNIFORM_BUFFER,i),t.bufferData(t.UNIFORM_BUFFER,r,s),t.bindBuffer(t.UNIFORM_BUFFER,null),t.bindBufferBase(t.UNIFORM_BUFFER,n,i),i}(n),r[n.id]=d,n.addEventListener("dispose",u));const p=c.program;i.updateUBOMapping(n,p);const f=e.render.frame;s[n.id]!==f&&(!function(e){const n=r[e.id],i=e.uniforms,s=e.__cache;t.bindBuffer(t.UNIFORM_BUFFER,n);for(let e=0,n=i.length;e<n;e++){const n=Array.isArray(i[e])?i[e]:[i[e]];for(let i=0,r=n.length;i<r;i++){const r=n[i];if(!0===l(r,e,i,s)){const e=r.__offset,n=Array.isArray(r.value)?r.value:[r.value];let i=0;for(let s=0;s<n.length;s++){const a=n[s],o=h(a);"number"==typeof a||"boolean"==typeof a?(r.__data[0]=a,t.bufferSubData(t.UNIFORM_BUFFER,e+i,r.__data)):a.isMatrix3?(r.__data[0]=a.elements[0],r.__data[1]=a.elements[1],r.__data[2]=a.elements[2],r.__data[3]=0,r.__data[4]=a.elements[3],r.__data[5]=a.elements[4],r.__data[6]=a.elements[5],r.__data[7]=0,r.__data[8]=a.elements[6],r.__data[9]=a.elements[7],r.__data[10]=a.elements[8],r.__data[11]=0):(a.toArray(r.__data,i),i+=o.storage/Float32Array.BYTES_PER_ELEMENT)}t.bufferSubData(t.UNIFORM_BUFFER,e,r.__data)}}}t.bindBuffer(t.UNIFORM_BUFFER,null)}(n),s[n.id]=f)},dispose:function(){for(const e in r)t.deleteBuffer(r[e]);a=[],r={},s={}}}}let co=class extends Mi{static get type(){return"LineBasicMaterial"}constructor(t){super(),this.isLineBasicMaterial=!0,this.color=new xi(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 po=new Ze,fo=new Ze,mo=new Rn,go=new An,_o=new yn,vo=new Ze,yo=new Ze;function xo(t,e,n,i,r,s){const a=t.geometry.attributes.position;po.fromBufferAttribute(a,r),fo.fromBufferAttribute(a,s);if(n.distanceSqToSegment(po,fo,vo,yo)>i)return;vo.applyMatrix4(t.matrixWorld);const o=e.ray.origin.distanceTo(vo);return o<e.near||o>e.far?void 0:{distance:o,point:yo.clone().applyMatrix4(t.matrixWorld),index:r,face:null,faceIndex:null,barycoord:null,object:t}}class bo{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(t,e){const n=this.getUtoTmapping(t);return this.getPoint(n,e)}getPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPoint(n/t));return e}getSpacedPoints(t=5){const e=[];for(let n=0;n<=t;n++)e.push(this.getPointAt(n/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 n,i=this.getPoint(0),r=0;e.push(0);for(let s=1;s<=t;s++)n=this.getPoint(s/t),r+=n.distanceTo(i),e.push(r),i=n;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const n=this.getLengths();let i=0;const r=n.length;let s;s=e||t*n[r-1];let a,o=0,l=r-1;for(;o<=l;)if(i=Math.floor(o+(l-o)/2),a=n[i]-s,a<0)o=i+1;else{if(!(a>0)){l=i;break}l=i-1}if(i=l,n[i]===s)return i/(r-1);const h=n[i];return(i+(s-h)/(n[i+1]-h))/(r-1)}getTangent(t,e){const n=1e-4;let i=t-n,r=t+n;i<0&&(i=0),r>1&&(r=1);const s=this.getPoint(i),a=this.getPoint(r),o=e||(s.isVector2?new Se:new Ze);return o.copy(a).sub(s).normalize(),o}getTangentAt(t,e){const n=this.getUtoTmapping(t);return this.getTangent(n,e)}computeFrenetFrames(t,e){const n=new Ze,i=[],r=[],s=[],a=new Ze,o=new Rn;for(let e=0;e<=t;e++){const n=e/t;i[e]=this.getTangentAt(n,new Ze)}r[0]=new Ze,s[0]=new Ze;let l=Number.MAX_VALUE;const h=Math.abs(i[0].x),u=Math.abs(i[0].y),c=Math.abs(i[0].z);h<=l&&(l=h,n.set(1,0,0)),u<=l&&(l=u,n.set(0,1,0)),c<=l&&n.set(0,0,1),a.crossVectors(i[0],n).normalize(),r[0].crossVectors(i[0],a),s[0].crossVectors(i[0],r[0]);for(let e=1;e<=t;e++){if(r[e]=r[e-1].clone(),s[e]=s[e-1].clone(),a.crossVectors(i[e-1],i[e]),a.length()>Number.EPSILON){a.normalize();const t=Math.acos(ge(i[e-1].dot(i[e]),-1,1));r[e].applyMatrix4(o.makeRotationAxis(a,t))}s[e].crossVectors(i[e],r[e])}if(!0===e){let e=Math.acos(ge(r[0].dot(r[t]),-1,1));e/=t,i[0].dot(a.crossVectors(r[0],r[t]))>0&&(e=-e);for(let n=1;n<=t;n++)r[n].applyMatrix4(o.makeRotationAxis(i[n],e*n)),s[n].crossVectors(i[n],r[n])}return{tangents:i,normals:r,binormals:s}}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 So extends bo{constructor(t=0,e=0,n=1,i=1,r=0,s=2*Math.PI,a=!1,o=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=n,this.yRadius=i,this.aStartAngle=r,this.aEndAngle=s,this.aClockwise=a,this.aRotation=o}getPoint(t,e=new Se){const n=e,i=2*Math.PI;let r=this.aEndAngle-this.aStartAngle;const s=Math.abs(r)<Number.EPSILON;for(;r<0;)r+=i;for(;r>i;)r-=i;r<Number.EPSILON&&(r=s?0:i),!0!==this.aClockwise||s||(r===i?r=-i:r-=i);const a=this.aStartAngle+t*r;let o=this.aX+this.xRadius*Math.cos(a),l=this.aY+this.yRadius*Math.sin(a);if(0!==this.aRotation){const t=Math.cos(this.aRotation),e=Math.sin(this.aRotation),n=o-this.aX,i=l-this.aY;o=n*t-i*e+this.aX,l=n*e+i*t+this.aY}return n.set(o,l)}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}}function Mo(){let t=0,e=0,n=0,i=0;function r(r,s,a,o){t=r,e=a,n=-3*r+3*s-2*a-o,i=2*r-2*s+a+o}return{initCatmullRom:function(t,e,n,i,s){r(e,n,s*(n-t),s*(i-e))},initNonuniformCatmullRom:function(t,e,n,i,s,a,o){let l=(e-t)/s-(n-t)/(s+a)+(n-e)/a,h=(n-e)/a-(i-e)/(a+o)+(i-n)/o;l*=a,h*=a,r(e,n,l,h)},calc:function(r){const s=r*r;return t+e*r+n*s+i*(s*r)}}}const To=new Ze,wo=new Mo,Eo=new Mo,Ao=new Mo;function Ro(t,e,n,i,r){const s=.5*(i-e),a=.5*(r-n),o=t*t;return(2*n-2*i+s+a)*(t*o)+(-3*n+3*i-2*s-a)*o+s*t+n}function Co(t,e,n,i){return function(t,e){const n=1-t;return n*n*e}(t,e)+function(t,e){return 2*(1-t)*t*e}(t,n)+function(t,e){return t*t*e}(t,i)}function No(t,e,n,i,r){return function(t,e){const n=1-t;return n*n*n*e}(t,e)+function(t,e){const n=1-t;return 3*n*n*t*e}(t,n)+function(t,e){return 3*(1-t)*t*t*e}(t,i)+function(t,e){return t*t*t*e}(t,r)}class Po extends bo{constructor(t=new Ze,e=new Ze,n=new Ze,i=new Ze){super(),this.isCubicBezierCurve3=!0,this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=n,this.v3=i}getPoint(t,e=new Ze){const n=e,i=this.v0,r=this.v1,s=this.v2,a=this.v3;return n.set(No(t,i.x,r.x,s.x,a.x),No(t,i.y,r.y,s.y,a.y),No(t,i.z,r.z,s.z,a.z)),n}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 Io extends bo{constructor(t=new Ze,e=new Ze,n=new Ze){super(),this.isQuadraticBezierCurve3=!0,this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new Ze){const n=e,i=this.v0,r=this.v1,s=this.v2;return n.set(Co(t,i.x,r.x,s.x),Co(t,i.y,r.y,s.y),Co(t,i.z,r.z,s.z)),n}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}}var Lo=Object.freeze({__proto__:null,ArcCurve:class extends So{constructor(t,e,n,i,r,s){super(t,e,n,n,i,r,s),this.isArcCurve=!0,this.type="ArcCurve"}},CatmullRomCurve3:class extends bo{constructor(t=[],e=!1,n="centripetal",i=.5){super(),this.isCatmullRomCurve3=!0,this.type="CatmullRomCurve3",this.points=t,this.closed=e,this.curveType=n,this.tension=i}getPoint(t,e=new Ze){const n=e,i=this.points,r=i.length,s=(r-(this.closed?0:1))*t;let a,o,l=Math.floor(s),h=s-l;this.closed?l+=l>0?0:(Math.floor(Math.abs(l)/r)+1)*r:0===h&&l===r-1&&(l=r-2,h=1),this.closed||l>0?a=i[(l-1)%r]:(To.subVectors(i[0],i[1]).add(i[0]),a=To);const u=i[l%r],c=i[(l+1)%r];if(this.closed||l+2<r?o=i[(l+2)%r]:(To.subVectors(i[r-1],i[r-2]).add(i[r-1]),o=To),"centripetal"===this.curveType||"chordal"===this.curveType){const t="chordal"===this.curveType?.5:.25;let e=Math.pow(a.distanceToSquared(u),t),n=Math.pow(u.distanceToSquared(c),t),i=Math.pow(c.distanceToSquared(o),t);n<1e-4&&(n=1),e<1e-4&&(e=n),i<1e-4&&(i=n),wo.initNonuniformCatmullRom(a.x,u.x,c.x,o.x,e,n,i),Eo.initNonuniformCatmullRom(a.y,u.y,c.y,o.y,e,n,i),Ao.initNonuniformCatmullRom(a.z,u.z,c.z,o.z,e,n,i)}else"catmullrom"===this.curveType&&(wo.initCatmullRom(a.x,u.x,c.x,o.x,this.tension),Eo.initCatmullRom(a.y,u.y,c.y,o.y,this.tension),Ao.initCatmullRom(a.z,u.z,c.z,o.z,this.tension));return n.set(wo.calc(h),Eo.calc(h),Ao.calc(h)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push(n.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,n=this.points.length;e<n;e++){const n=this.points[e];t.points.push(n.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,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push((new Ze).fromArray(n))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}},CubicBezierCurve:class extends bo{constructor(t=new Se,e=new Se,n=new Se,i=new Se){super(),this.isCubicBezierCurve=!0,this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=n,this.v3=i}getPoint(t,e=new Se){const n=e,i=this.v0,r=this.v1,s=this.v2,a=this.v3;return n.set(No(t,i.x,r.x,s.x,a.x),No(t,i.y,r.y,s.y,a.y)),n}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}},CubicBezierCurve3:Po,EllipseCurve:So,LineCurve:class extends bo{constructor(t=new Se,e=new Se){super(),this.isLineCurve=!0,this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new Se){const n=e;return 1===t?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(t).add(this.v1)),n}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new Se){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}},LineCurve3:class extends bo{constructor(t=new Ze,e=new Ze){super(),this.isLineCurve3=!0,this.type="LineCurve3",this.v1=t,this.v2=e}getPoint(t,e=new Ze){const n=e;return 1===t?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(t).add(this.v1)),n}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e=new Ze){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}},QuadraticBezierCurve:class extends bo{constructor(t=new Se,e=new Se,n=new Se){super(),this.isQuadraticBezierCurve=!0,this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=n}getPoint(t,e=new Se){const n=e,i=this.v0,r=this.v1,s=this.v2;return n.set(Co(t,i.x,r.x,s.x),Co(t,i.y,r.y,s.y)),n}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}},QuadraticBezierCurve3:Io,SplineCurve:class extends bo{constructor(t=[]){super(),this.isSplineCurve=!0,this.type="SplineCurve",this.points=t}getPoint(t,e=new Se){const n=e,i=this.points,r=(i.length-1)*t,s=Math.floor(r),a=r-s,o=i[0===s?s:s-1],l=i[s],h=i[s>i.length-2?i.length-1:s+1],u=i[s>i.length-3?i.length-1:s+2];return n.set(Ro(a,o.x,l.x,h.x,u.x),Ro(a,o.y,l.y,h.y,u.y)),n}copy(t){super.copy(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push(n.clone())}return this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,n=this.points.length;e<n;e++){const n=this.points[e];t.points.push(n.toArray())}return t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,n=t.points.length;e<n;e++){const n=t.points[e];this.points.push((new Se).fromArray(n))}return this}}});class Uo extends Bi{constructor(t=1,e=1,n=1,i=32,r=1,s=!1,a=0,o=2*Math.PI){super(),this.type="CylinderGeometry",this.parameters={radiusTop:t,radiusBottom:e,height:n,radialSegments:i,heightSegments:r,openEnded:s,thetaStart:a,thetaLength:o};const l=this;i=Math.floor(i),r=Math.floor(r);const h=[],u=[],c=[],d=[];let p=0;const f=[],m=n/2;let g=0;function _(n){const r=p,s=new Se,f=new Ze;let _=0;const v=!0===n?t:e,y=!0===n?1:-1;for(let t=1;t<=i;t++)u.push(0,m*y,0),c.push(0,y,0),d.push(.5,.5),p++;const x=p;for(let t=0;t<=i;t++){const e=t/i*o+a,n=Math.cos(e),r=Math.sin(e);f.x=v*r,f.y=m*y,f.z=v*n,u.push(f.x,f.y,f.z),c.push(0,y,0),s.x=.5*n+.5,s.y=.5*r*y+.5,d.push(s.x,s.y),p++}for(let t=0;t<i;t++){const e=r+t,i=x+t;!0===n?h.push(i,i+1,e):h.push(i+1,i,e),_+=3}l.addGroup(g,_,!0===n?1:2),g+=_}!function(){const s=new Ze,_=new Ze;let v=0;const y=(e-t)/n;for(let l=0;l<=r;l++){const h=[],g=l/r,v=g*(e-t)+t;for(let t=0;t<=i;t++){const e=t/i,r=e*o+a,l=Math.sin(r),f=Math.cos(r);_.x=v*l,_.y=-g*n+m,_.z=v*f,u.push(_.x,_.y,_.z),s.set(l,y,f).normalize(),c.push(s.x,s.y,s.z),d.push(e,1-g),h.push(p++)}f.push(h)}for(let n=0;n<i;n++)for(let i=0;i<r;i++){const s=f[i][n],a=f[i+1][n],o=f[i+1][n+1],l=f[i][n+1];(t>0||0!==i)&&(h.push(s,a,l),v+=3),(e>0||i!==r-1)&&(h.push(a,o,l),v+=3)}l.addGroup(g,v,0),g+=v}(),!1===s&&(t>0&&_(!0),e>0&&_(!1)),this.setIndex(h),this.setAttribute("position",new Ni(u,3)),this.setAttribute("normal",new Ni(c,3)),this.setAttribute("uv",new Ni(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new Uo(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class Do extends Uo{constructor(t=1,e=1,n=32,i=1,r=!1,s=0,a=2*Math.PI){super(0,t,e,n,i,r,s,a),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:n,heightSegments:i,openEnded:r,thetaStart:s,thetaLength:a}}static fromJSON(t){return new Do(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}let Oo=class t extends Bi{constructor(t=1,e=32,n=16,i=0,r=2*Math.PI,s=0,a=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:n,phiStart:i,phiLength:r,thetaStart:s,thetaLength:a},e=Math.max(3,Math.floor(e)),n=Math.max(2,Math.floor(n));const o=Math.min(s+a,Math.PI);let l=0;const h=[],u=new Ze,c=new Ze,d=[],p=[],f=[],m=[];for(let d=0;d<=n;d++){const g=[],_=d/n;let v=0;0===d&&0===s?v=.5/e:d===n&&o===Math.PI&&(v=-.5/e);for(let n=0;n<=e;n++){const o=n/e;u.x=-t*Math.cos(i+o*r)*Math.sin(s+_*a),u.y=t*Math.cos(s+_*a),u.z=t*Math.sin(i+o*r)*Math.sin(s+_*a),p.push(u.x,u.y,u.z),c.copy(u).normalize(),f.push(c.x,c.y,c.z),m.push(o+v,1-_),g.push(l++)}h.push(g)}for(let t=0;t<n;t++)for(let i=0;i<e;i++){const e=h[t][i+1],r=h[t][i],a=h[t+1][i],l=h[t+1][i+1];(0!==t||s>0)&&d.push(e,r,l),(t!==n-1||o<Math.PI)&&d.push(r,a,l)}this.setIndex(d),this.setAttribute("position",new Ni(p,3)),this.setAttribute("normal",new Ni(f,3)),this.setAttribute("uv",new Ni(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(e){return new t(e.radius,e.widthSegments,e.heightSegments,e.phiStart,e.phiLength,e.thetaStart,e.thetaLength)}};class Fo extends Bi{constructor(t=new Io(new Ze(-1,-1,0),new Ze(-1,1,0),new Ze(1,1,0)),e=64,n=1,i=8,r=!1){super(),this.type="TubeGeometry",this.parameters={path:t,tubularSegments:e,radius:n,radialSegments:i,closed:r};const s=t.computeFrenetFrames(e,r);this.tangents=s.tangents,this.normals=s.normals,this.binormals=s.binormals;const a=new Ze,o=new Ze,l=new Se;let h=new Ze;const u=[],c=[],d=[],p=[];function f(r){h=t.getPointAt(r/e,h);const l=s.normals[r],d=s.binormals[r];for(let t=0;t<=i;t++){const e=t/i*Math.PI*2,r=Math.sin(e),s=-Math.cos(e);o.x=s*l.x+r*d.x,o.y=s*l.y+r*d.y,o.z=s*l.z+r*d.z,o.normalize(),c.push(o.x,o.y,o.z),a.x=h.x+n*o.x,a.y=h.y+n*o.y,a.z=h.z+n*o.z,u.push(a.x,a.y,a.z)}}!function(){for(let t=0;t<e;t++)f(t);f(!1===r?e:0),function(){for(let t=0;t<=e;t++)for(let n=0;n<=i;n++)l.x=t/e,l.y=n/i,d.push(l.x,l.y)}(),function(){for(let t=1;t<=e;t++)for(let e=1;e<=i;e++){const n=(i+1)*(t-1)+(e-1),r=(i+1)*t+(e-1),s=(i+1)*t+e,a=(i+1)*(t-1)+e;p.push(n,r,a),p.push(r,s,a)}}()}(),this.setIndex(p),this.setAttribute("position",new Ni(u,3)),this.setAttribute("normal",new Ni(c,3)),this.setAttribute("uv",new Ni(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 Fo((new Lo[t.path.type]).fromJSON(t.path),t.tubularSegments,t.radius,t.radialSegments,t.closed)}}const Bo={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 zo{constructor(t,e,n){const i=this;let r,s=!1,a=0,o=0;const l=[];this.onStart=void 0,this.onLoad=t,this.onProgress=e,this.onError=n,this.itemStart=function(t){o++,!1===s&&void 0!==i.onStart&&i.onStart(t,a,o),s=!0},this.itemEnd=function(t){a++,void 0!==i.onProgress&&i.onProgress(t,a,o),a===o&&(s=!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 l.push(t,e),this},this.removeHandler=function(t){const e=l.indexOf(t);return-1!==e&&l.splice(e,2),this},this.getHandler=function(t){for(let e=0,n=l.length;e<n;e+=2){const n=l[e],i=l[e+1];if(n.global&&(n.lastIndex=0),n.test(t))return i}return null}}}const ko=new zo;class Go{constructor(t){this.manager=void 0!==t?t:ko,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(t,e){const n=this;return new Promise((function(i,r){n.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}}Go.DEFAULT_MATERIAL_NAME="__DEFAULT";class Vo extends Go{constructor(t){super(t)}load(t,e,n,i){void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const r=this,s=Bo.get(t);if(void 0!==s)return r.manager.itemStart(t),setTimeout((function(){e&&e(s),r.manager.itemEnd(t)}),0),s;const a=Ee("img");function o(){h(),Bo.add(t,this),e&&e(this),r.manager.itemEnd(t)}function l(e){h(),i&&i(e),r.manager.itemError(t),r.manager.itemEnd(t)}function h(){a.removeEventListener("load",o,!1),a.removeEventListener("error",l,!1)}return a.addEventListener("load",o,!1),a.addEventListener("error",l,!1),"data:"!==t.slice(0,5)&&void 0!==this.crossOrigin&&(a.crossOrigin=this.crossOrigin),r.manager.itemStart(t),a.src=t,a}}let Ho=class extends ei{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new xi(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}};const jo=new Rn,Wo=new Ze,qo=new Ze;let Xo=class{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new Se(512,512),this.map=null,this.mapPass=null,this.matrix=new Rn,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new yr,this._frameExtents=new Se(1,1),this._viewportCount=1,this._viewports=[new We(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,n=this.matrix;Wo.setFromMatrixPosition(t.matrixWorld),e.position.copy(Wo),qo.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(qo),e.updateMatrixWorld(),jo.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(jo),n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(jo)}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}},$o=class extends Xo{constructor(){super(new Dr(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}};class Yo{constructor(t=!0){this.autoStart=t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=Ko(),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=Ko();t=(e-this.oldTime)/1e3,this.oldTime=e,this.elapsedTime+=t}return t}}function Ko(){return performance.now()}const Zo=new Rn;class Qo{constructor(t,e,n=0,i=1/0){this.ray=new An(t,e),this.near=n,this.far=i,this.camera=null,this.layers=new zn,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 Zo.identity().extractRotation(t.matrixWorld),this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(0,0,-1).applyMatrix4(Zo),this}intersectObject(t,e=!0,n=[]){return tl(t,this,n,e),n.sort(Jo),n}intersectObjects(t,e=!0,n=[]){for(let i=0,r=t.length;i<r;i++)tl(t[i],this,n,e);return n.sort(Jo),n}}function Jo(t,e){return t.distance-e.distance}function tl(t,e,n,i){let r=!0;if(t.layers.test(e.layers)){!1===t.raycast(e,n)&&(r=!1)}if(!0===r&&!0===i){const i=t.children;for(let t=0,r=i.length;t<r;t++)tl(i[t],e,n,!0)}}class el{constructor(t=1,e=0,n=0){return this.radius=t,this.phi=e,this.theta=n,this}set(t,e,n){return this.radius=t,this.phi=e,this.theta=n,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,n){return this.radius=Math.sqrt(t*t+e*e+n*n),0===this.radius?(this.theta=0,this.phi=0):(this.theta=Math.atan2(t,n),this.phi=Math.acos(ge(e/this.radius,-1,1))),this}clone(){return(new this.constructor).copy(this)}}class nl extends ue{constructor(t,e=null){super(),this.object=t,this.domElement=e,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(){}disconnect(){}dispose(){}update(){}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:s}})),"undefined"!=typeof window&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=s);const il=new gr,rl=new Se,sl=new Ze,al=new Se,ol=new Se,ll=new Ze,hl=new Ze,ul=new Rn,cl=new Ze,dl=new Ze;let pl=null,fl=null;const ml=[],gl=-1,_l=0,vl=1;class yl extends nl{constructor(t,e,n=null){super(e,n),this.objects=t,this.recursive=!0,this.transformGroup=!1,this.rotateSpeed=1,this.raycaster=new Qo,this.mouseButtons={LEFT:a.PAN,MIDDLE:a.PAN,RIGHT:a.ROTATE},this.touches={ONE:l},this._onPointerMove=xl.bind(this),this._onPointerDown=bl.bind(this),this._onPointerCancel=Sl.bind(this),this._onContextMenu=Ml.bind(this),null!==n&&this.connect()}connect(){this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointerup",this._onPointerCancel),this.domElement.addEventListener("pointerleave",this._onPointerCancel),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointerup",this._onPointerCancel),this.domElement.removeEventListener("pointerleave",this._onPointerCancel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="auto",this.domElement.style.cursor=""}dispose(){this.disconnect()}_updatePointer(t){const e=this.domElement.getBoundingClientRect();rl.x=(t.clientX-e.left)/e.width*2-1,rl.y=-(t.clientY-e.top)/e.height*2+1}_updateState(t){let e;if("touch"===t.pointerType)e=this.touches.ONE;else switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=null}switch(e){case a.PAN:case l:this.state=_l;break;case a.ROTATE:case o:this.state=vl;break;default:this.state=gl}}getRaycaster(){return console.warn("THREE.DragControls: getRaycaster() has been deprecated. Use controls.raycaster instead."),this.raycaster}setObjects(t){console.warn("THREE.DragControls: setObjects() has been deprecated. Use controls.objects instead."),this.objects=t}getObjects(){return console.warn("THREE.DragControls: getObjects() has been deprecated. Use controls.objects instead."),this.objects}activate(){console.warn("THREE.DragControls: activate() has been renamed to connect()."),this.connect()}deactivate(){console.warn("THREE.DragControls: deactivate() has been renamed to disconnect()."),this.disconnect()}set mode(t){console.warn("THREE.DragControls: The .mode property has been removed. Define the type of transformation via the .mouseButtons or .touches properties.")}get mode(){console.warn("THREE.DragControls: The .mode property has been removed. Define the type of transformation via the .mouseButtons or .touches properties.")}}function xl(t){const e=this.object,n=this.domElement,i=this.raycaster;if(!1!==this.enabled){if(this._updatePointer(t),i.setFromCamera(rl,e),pl)this.state===_l?i.ray.intersectPlane(il,ll)&&pl.position.copy(ll.sub(sl).applyMatrix4(ul)):this.state===vl&&(al.subVectors(rl,ol).multiplyScalar(this.rotateSpeed),pl.rotateOnWorldAxis(cl,al.x),pl.rotateOnWorldAxis(dl.normalize(),-al.y)),this.dispatchEvent({type:"drag",object:pl}),ol.copy(rl);else if("mouse"===t.pointerType||"pen"===t.pointerType)if(ml.length=0,i.setFromCamera(rl,e),i.intersectObjects(this.objects,this.recursive,ml),ml.length>0){const t=ml[0].object;il.setFromNormalAndCoplanarPoint(e.getWorldDirection(il.normal),hl.setFromMatrixPosition(t.matrixWorld)),fl!==t&&null!==fl&&(this.dispatchEvent({type:"hoveroff",object:fl}),n.style.cursor="auto",fl=null),fl!==t&&(this.dispatchEvent({type:"hoveron",object:t}),n.style.cursor="pointer",fl=t)}else null!==fl&&(this.dispatchEvent({type:"hoveroff",object:fl}),n.style.cursor="auto",fl=null);ol.copy(rl)}}function bl(t){const e=this.object,n=this.domElement,i=this.raycaster;!1!==this.enabled&&(this._updatePointer(t),this._updateState(t),ml.length=0,i.setFromCamera(rl,e),i.intersectObjects(this.objects,this.recursive,ml),ml.length>0&&(pl=!0===this.transformGroup?Tl(ml[0].object):ml[0].object,il.setFromNormalAndCoplanarPoint(e.getWorldDirection(il.normal),hl.setFromMatrixPosition(pl.matrixWorld)),i.ray.intersectPlane(il,ll)&&(this.state===_l?(ul.copy(pl.parent.matrixWorld).invert(),sl.copy(ll).sub(hl.setFromMatrixPosition(pl.matrixWorld))):this.state===vl&&(cl.set(0,1,0).applyQuaternion(e.quaternion).normalize(),dl.set(1,0,0).applyQuaternion(e.quaternion).normalize())),n.style.cursor="move",this.dispatchEvent({type:"dragstart",object:pl})),ol.copy(rl))}function Sl(){!1!==this.enabled&&(pl&&(this.dispatchEvent({type:"dragend",object:pl}),pl=null),this.domElement.style.cursor=fl?"pointer":"auto",this.state=gl)}function Ml(t){!1!==this.enabled&&t.preventDefault()}function Tl(t,e=null){return t.isGroup&&(e=t),null===t.parent?e:Tl(t.parent,e)}function wl(t,e,n){var i,r=1;function s(){var s,a,o=i.length,l=0,h=0,u=0;for(s=0;s<o;++s)l+=(a=i[s]).x||0,h+=a.y||0,u+=a.z||0;for(l=(l/o-t)*r,h=(h/o-e)*r,u=(u/o-n)*r,s=0;s<o;++s)a=i[s],l&&(a.x-=l),h&&(a.y-=h),u&&(a.z-=u)}return null==t&&(t=0),null==e&&(e=0),null==n&&(n=0),s.initialize=function(t){i=t},s.x=function(e){return arguments.length?(t=+e,s):t},s.y=function(t){return arguments.length?(e=+t,s):e},s.z=function(t){return arguments.length?(n=+t,s):n},s.strength=function(t){return arguments.length?(r=+t,s):r},s}function El(t,e,n){if(isNaN(e))return t;var i,r,s,a,o,l,h=t._root,u={data:n},c=t._x0,d=t._x1;if(!h)return t._root=u,t;for(;h.length;)if((a=e>=(r=(c+d)/2))?c=r:d=r,i=h,!(h=h[o=+a]))return i[o]=u,t;if(e===(s=+t._x.call(null,h.data)))return u.next=h,i?i[o]=u:t._root=u,t;do{i=i?i[o]=new Array(2):t._root=new Array(2),(a=e>=(r=(c+d)/2))?c=r:d=r}while((o=+a)==(l=+(s>=r)));return i[l]=h,i[o]=u,t}function Al(t,e,n){this.node=t,this.x0=e,this.x1=n}function Rl(t){return t[0]}function Cl(t,e){var n=new Nl(null==e?Rl:e,NaN,NaN);return null==t?n:n.addAll(t)}function Nl(t,e,n){this._x=t,this._x0=e,this._x1=n,this._root=void 0}function Pl(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var Il=Cl.prototype=Nl.prototype;function Ll(t,e,n,i){if(isNaN(e)||isNaN(n))return t;var r,s,a,o,l,h,u,c,d,p=t._root,f={data:i},m=t._x0,g=t._y0,_=t._x1,v=t._y1;if(!p)return t._root=f,t;for(;p.length;)if((h=e>=(s=(m+_)/2))?m=s:_=s,(u=n>=(a=(g+v)/2))?g=a:v=a,r=p,!(p=p[c=u<<1|h]))return r[c]=f,t;if(o=+t._x.call(null,p.data),l=+t._y.call(null,p.data),e===o&&n===l)return f.next=p,r?r[c]=f:t._root=f,t;do{r=r?r[c]=new Array(4):t._root=new Array(4),(h=e>=(s=(m+_)/2))?m=s:_=s,(u=n>=(a=(g+v)/2))?g=a:v=a}while((c=u<<1|h)==(d=(l>=a)<<1|o>=s));return r[d]=p,r[c]=f,t}function Ul(t,e,n,i,r){this.node=t,this.x0=e,this.y0=n,this.x1=i,this.y1=r}function Dl(t){return t[0]}function Ol(t){return t[1]}function Fl(t,e,n){var i=new Bl(null==e?Dl:e,null==n?Ol:n,NaN,NaN,NaN,NaN);return null==t?i:i.addAll(t)}function Bl(t,e,n,i,r,s){this._x=t,this._y=e,this._x0=n,this._y0=i,this._x1=r,this._y1=s,this._root=void 0}function zl(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}Il.copy=function(){var t,e,n=new Nl(this._x,this._x0,this._x1),i=this._root;if(!i)return n;if(!i.length)return n._root=Pl(i),n;for(t=[{source:i,target:n._root=new Array(2)}];i=t.pop();)for(var r=0;r<2;++r)(e=i.source[r])&&(e.length?t.push({source:e,target:i.target[r]=new Array(2)}):i.target[r]=Pl(e));return n},Il.add=function(t){const e=+this._x.call(null,t);return El(this.cover(e),e,t)},Il.addAll=function(t){Array.isArray(t)||(t=Array.from(t));const e=t.length,n=new Float64Array(e);let i=1/0,r=-1/0;for(let s,a=0;a<e;++a)isNaN(s=+this._x.call(null,t[a]))||(n[a]=s,s<i&&(i=s),s>r&&(r=s));if(i>r)return this;this.cover(i).cover(r);for(let i=0;i<e;++i)El(this,n[i],t[i]);return this},Il.cover=function(t){if(isNaN(t=+t))return this;var e=this._x0,n=this._x1;if(isNaN(e))n=(e=Math.floor(t))+1;else{for(var i,r,s=n-e||1,a=this._root;e>t||t>=n;)switch(r=+(t<e),(i=new Array(2))[r]=a,a=i,s*=2,r){case 0:n=e+s;break;case 1:e=n-s}this._root&&this._root.length&&(this._root=a)}return this._x0=e,this._x1=n,this},Il.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},Il.extent=function(t){return arguments.length?this.cover(+t[0][0]).cover(+t[1][0]):isNaN(this._x0)?void 0:[[this._x0],[this._x1]]},Il.find=function(t,e){var n,i,r,s,a,o=this._x0,l=this._x1,h=[],u=this._root;for(u&&h.push(new Al(u,o,l)),null==e?e=1/0:(o=t-e,l=t+e);s=h.pop();)if(!(!(u=s.node)||(i=s.x0)>l||(r=s.x1)<o))if(u.length){var c=(i+r)/2;h.push(new Al(u[1],c,r),new Al(u[0],i,c)),(a=+(t>=c))&&(s=h[h.length-1],h[h.length-1]=h[h.length-1-a],h[h.length-1-a]=s)}else{var d=Math.abs(t-+this._x.call(null,u.data));d<e&&(e=d,o=t-d,l=t+d,n=u.data)}return n},Il.remove=function(t){if(isNaN(s=+this._x.call(null,t)))return this;var e,n,i,r,s,a,o,l,h,u=this._root,c=this._x0,d=this._x1;if(!u)return this;if(u.length)for(;;){if((o=s>=(a=(c+d)/2))?c=a:d=a,e=u,!(u=u[l=+o]))return this;if(!u.length)break;e[l+1&1]&&(n=e,h=l)}for(;u.data!==t;)if(i=u,!(u=u.next))return this;return(r=u.next)&&delete u.next,i?(r?i.next=r:delete i.next,this):e?(r?e[l]=r:delete e[l],(u=e[0]||e[1])&&u===(e[1]||e[0])&&!u.length&&(n?n[h]=u:this._root=u),this):(this._root=r,this)},Il.removeAll=function(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this},Il.root=function(){return this._root},Il.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},Il.visit=function(t){var e,n,i,r,s=[],a=this._root;for(a&&s.push(new Al(a,this._x0,this._x1));e=s.pop();)if(!t(a=e.node,i=e.x0,r=e.x1)&&a.length){var o=(i+r)/2;(n=a[1])&&s.push(new Al(n,o,r)),(n=a[0])&&s.push(new Al(n,i,o))}return this},Il.visitAfter=function(t){var e,n=[],i=[];for(this._root&&n.push(new Al(this._root,this._x0,this._x1));e=n.pop();){var r=e.node;if(r.length){var s,a=e.x0,o=e.x1,l=(a+o)/2;(s=r[0])&&n.push(new Al(s,a,l)),(s=r[1])&&n.push(new Al(s,l,o))}i.push(e)}for(;e=i.pop();)t(e.node,e.x0,e.x1);return this},Il.x=function(t){return arguments.length?(this._x=t,this):this._x};var kl=Fl.prototype=Bl.prototype;function Gl(t,e,n,i,r){if(isNaN(e)||isNaN(n)||isNaN(i))return t;var s,a,o,l,h,u,c,d,p,f,m,g,_=t._root,v={data:r},y=t._x0,x=t._y0,b=t._z0,S=t._x1,M=t._y1,T=t._z1;if(!_)return t._root=v,t;for(;_.length;)if((d=e>=(a=(y+S)/2))?y=a:S=a,(p=n>=(o=(x+M)/2))?x=o:M=o,(f=i>=(l=(b+T)/2))?b=l:T=l,s=_,!(_=_[m=f<<2|p<<1|d]))return s[m]=v,t;if(h=+t._x.call(null,_.data),u=+t._y.call(null,_.data),c=+t._z.call(null,_.data),e===h&&n===u&&i===c)return v.next=_,s?s[m]=v:t._root=v,t;do{s=s?s[m]=new Array(8):t._root=new Array(8),(d=e>=(a=(y+S)/2))?y=a:S=a,(p=n>=(o=(x+M)/2))?x=o:M=o,(f=i>=(l=(b+T)/2))?b=l:T=l}while((m=f<<2|p<<1|d)==(g=(c>=l)<<2|(u>=o)<<1|h>=a));return s[g]=_,s[m]=v,t}function Vl(t,e,n,i,r,s,a){this.node=t,this.x0=e,this.y0=n,this.z0=i,this.x1=r,this.y1=s,this.z1=a}function Hl(t){return t[0]}function jl(t){return t[1]}function Wl(t){return t[2]}function ql(t,e,n,i){var r=new Xl(null==e?Hl:e,null==n?jl:n,null==i?Wl:i,NaN,NaN,NaN,NaN,NaN,NaN);return null==t?r:r.addAll(t)}function Xl(t,e,n,i,r,s,a,o,l){this._x=t,this._y=e,this._z=n,this._x0=i,this._y0=r,this._z0=s,this._x1=a,this._y1=o,this._z1=l,this._root=void 0}function $l(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}kl.copy=function(){var t,e,n=new Bl(this._x,this._y,this._x0,this._y0,this._x1,this._y1),i=this._root;if(!i)return n;if(!i.length)return n._root=zl(i),n;for(t=[{source:i,target:n._root=new Array(4)}];i=t.pop();)for(var r=0;r<4;++r)(e=i.source[r])&&(e.length?t.push({source:e,target:i.target[r]=new Array(4)}):i.target[r]=zl(e));return n},kl.add=function(t){const e=+this._x.call(null,t),n=+this._y.call(null,t);return Ll(this.cover(e,n),e,n,t)},kl.addAll=function(t){var e,n,i,r,s=t.length,a=new Array(s),o=new Array(s),l=1/0,h=1/0,u=-1/0,c=-1/0;for(n=0;n<s;++n)isNaN(i=+this._x.call(null,e=t[n]))||isNaN(r=+this._y.call(null,e))||(a[n]=i,o[n]=r,i<l&&(l=i),i>u&&(u=i),r<h&&(h=r),r>c&&(c=r));if(l>u||h>c)return this;for(this.cover(l,h).cover(u,c),n=0;n<s;++n)Ll(this,a[n],o[n],t[n]);return this},kl.cover=function(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,i=this._y0,r=this._x1,s=this._y1;if(isNaN(n))r=(n=Math.floor(t))+1,s=(i=Math.floor(e))+1;else{for(var a,o,l=r-n||1,h=this._root;n>t||t>=r||i>e||e>=s;)switch(o=(e<i)<<1|t<n,(a=new Array(4))[o]=h,h=a,l*=2,o){case 0:r=n+l,s=i+l;break;case 1:n=r-l,s=i+l;break;case 2:r=n+l,i=s-l;break;case 3:n=r-l,i=s-l}this._root&&this._root.length&&(this._root=h)}return this._x0=n,this._y0=i,this._x1=r,this._y1=s,this},kl.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},kl.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]},kl.find=function(t,e,n){var i,r,s,a,o,l,h,u=this._x0,c=this._y0,d=this._x1,p=this._y1,f=[],m=this._root;for(m&&f.push(new Ul(m,u,c,d,p)),null==n?n=1/0:(u=t-n,c=e-n,d=t+n,p=e+n,n*=n);l=f.pop();)if(!(!(m=l.node)||(r=l.x0)>d||(s=l.y0)>p||(a=l.x1)<u||(o=l.y1)<c))if(m.length){var g=(r+a)/2,_=(s+o)/2;f.push(new Ul(m[3],g,_,a,o),new Ul(m[2],r,_,g,o),new Ul(m[1],g,s,a,_),new Ul(m[0],r,s,g,_)),(h=(e>=_)<<1|t>=g)&&(l=f[f.length-1],f[f.length-1]=f[f.length-1-h],f[f.length-1-h]=l)}else{var v=t-+this._x.call(null,m.data),y=e-+this._y.call(null,m.data),x=v*v+y*y;if(x<n){var b=Math.sqrt(n=x);u=t-b,c=e-b,d=t+b,p=e+b,i=m.data}}return i},kl.remove=function(t){if(isNaN(s=+this._x.call(null,t))||isNaN(a=+this._y.call(null,t)))return this;var e,n,i,r,s,a,o,l,h,u,c,d,p=this._root,f=this._x0,m=this._y0,g=this._x1,_=this._y1;if(!p)return this;if(p.length)for(;;){if((h=s>=(o=(f+g)/2))?f=o:g=o,(u=a>=(l=(m+_)/2))?m=l:_=l,e=p,!(p=p[c=u<<1|h]))return this;if(!p.length)break;(e[c+1&3]||e[c+2&3]||e[c+3&3])&&(n=e,d=c)}for(;p.data!==t;)if(i=p,!(p=p.next))return this;return(r=p.next)&&delete p.next,i?(r?i.next=r:delete i.next,this):e?(r?e[c]=r:delete e[c],(p=e[0]||e[1]||e[2]||e[3])&&p===(e[3]||e[2]||e[1]||e[0])&&!p.length&&(n?n[d]=p:this._root=p),this):(this._root=r,this)},kl.removeAll=function(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this},kl.root=function(){return this._root},kl.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},kl.visit=function(t){var e,n,i,r,s,a,o=[],l=this._root;for(l&&o.push(new Ul(l,this._x0,this._y0,this._x1,this._y1));e=o.pop();)if(!t(l=e.node,i=e.x0,r=e.y0,s=e.x1,a=e.y1)&&l.length){var h=(i+s)/2,u=(r+a)/2;(n=l[3])&&o.push(new Ul(n,h,u,s,a)),(n=l[2])&&o.push(new Ul(n,i,u,h,a)),(n=l[1])&&o.push(new Ul(n,h,r,s,u)),(n=l[0])&&o.push(new Ul(n,i,r,h,u))}return this},kl.visitAfter=function(t){var e,n=[],i=[];for(this._root&&n.push(new Ul(this._root,this._x0,this._y0,this._x1,this._y1));e=n.pop();){var r=e.node;if(r.length){var s,a=e.x0,o=e.y0,l=e.x1,h=e.y1,u=(a+l)/2,c=(o+h)/2;(s=r[0])&&n.push(new Ul(s,a,o,u,c)),(s=r[1])&&n.push(new Ul(s,u,o,l,c)),(s=r[2])&&n.push(new Ul(s,a,c,u,h)),(s=r[3])&&n.push(new Ul(s,u,c,l,h))}i.push(e)}for(;e=i.pop();)t(e.node,e.x0,e.y0,e.x1,e.y1);return this},kl.x=function(t){return arguments.length?(this._x=t,this):this._x},kl.y=function(t){return arguments.length?(this._y=t,this):this._y};var Yl=ql.prototype=Xl.prototype;function Kl(t){return function(){return t}}function Zl(t){return 1e-6*(t()-.5)}function Ql(t){return t.index}function Jl(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function th(t){var e,n,i,r,s,a,o,l=Ql,h=function(t){return 1/Math.min(s[t.source.index],s[t.target.index])},u=Kl(30),c=1;function d(i){for(var s=0,l=t.length;s<c;++s)for(var h,u,d,p,f,m=0,g=0,_=0,v=0;m<l;++m)u=(h=t[m]).source,g=(d=h.target).x+d.vx-u.x-u.vx||Zl(o),r>1&&(_=d.y+d.vy-u.y-u.vy||Zl(o)),r>2&&(v=d.z+d.vz-u.z-u.vz||Zl(o)),g*=p=((p=Math.sqrt(g*g+_*_+v*v))-n[m])/p*i*e[m],_*=p,v*=p,d.vx-=g*(f=a[m]),r>1&&(d.vy-=_*f),r>2&&(d.vz-=v*f),u.vx+=g*(f=1-f),r>1&&(u.vy+=_*f),r>2&&(u.vz+=v*f)}function p(){if(i){var r,o,h=i.length,u=t.length,c=new Map(i.map(((t,e)=>[l(t,e,i),t])));for(r=0,s=new Array(h);r<u;++r)(o=t[r]).index=r,"object"!=typeof o.source&&(o.source=Jl(c,o.source)),"object"!=typeof o.target&&(o.target=Jl(c,o.target)),s[o.source.index]=(s[o.source.index]||0)+1,s[o.target.index]=(s[o.target.index]||0)+1;for(r=0,a=new Array(u);r<u;++r)o=t[r],a[r]=s[o.source.index]/(s[o.source.index]+s[o.target.index]);e=new Array(u),f(),n=new Array(u),m()}}function f(){if(i)for(var n=0,r=t.length;n<r;++n)e[n]=+h(t[n],n,t)}function m(){if(i)for(var e=0,r=t.length;e<r;++e)n[e]=+u(t[e],e,t)}return null==t&&(t=[]),d.initialize=function(t,...e){i=t,o=e.find((t=>"function"==typeof t))||Math.random,r=e.find((t=>[1,2,3].includes(t)))||2,p()},d.links=function(e){return arguments.length?(t=e,p(),d):t},d.id=function(t){return arguments.length?(l=t,d):l},d.iterations=function(t){return arguments.length?(c=+t,d):c},d.strength=function(t){return arguments.length?(h="function"==typeof t?t:Kl(+t),f(),d):h},d.distance=function(t){return arguments.length?(u="function"==typeof t?t:Kl(+t),m(),d):u},d}Yl.copy=function(){var t,e,n=new Xl(this._x,this._y,this._z,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1),i=this._root;if(!i)return n;if(!i.length)return n._root=$l(i),n;for(t=[{source:i,target:n._root=new Array(8)}];i=t.pop();)for(var r=0;r<8;++r)(e=i.source[r])&&(e.length?t.push({source:e,target:i.target[r]=new Array(8)}):i.target[r]=$l(e));return n},Yl.add=function(t){const e=+this._x.call(null,t),n=+this._y.call(null,t),i=+this._z.call(null,t);return Gl(this.cover(e,n,i),e,n,i,t)},Yl.addAll=function(t){Array.isArray(t)||(t=Array.from(t));const e=t.length,n=new Float64Array(e),i=new Float64Array(e),r=new Float64Array(e);let s=1/0,a=1/0,o=1/0,l=-1/0,h=-1/0,u=-1/0;for(let c,d,p,f,m=0;m<e;++m)isNaN(d=+this._x.call(null,c=t[m]))||isNaN(p=+this._y.call(null,c))||isNaN(f=+this._z.call(null,c))||(n[m]=d,i[m]=p,r[m]=f,d<s&&(s=d),d>l&&(l=d),p<a&&(a=p),p>h&&(h=p),f<o&&(o=f),f>u&&(u=f));if(s>l||a>h||o>u)return this;this.cover(s,a,o).cover(l,h,u);for(let s=0;s<e;++s)Gl(this,n[s],i[s],r[s],t[s]);return this},Yl.cover=function(t,e,n){if(isNaN(t=+t)||isNaN(e=+e)||isNaN(n=+n))return this;var i=this._x0,r=this._y0,s=this._z0,a=this._x1,o=this._y1,l=this._z1;if(isNaN(i))a=(i=Math.floor(t))+1,o=(r=Math.floor(e))+1,l=(s=Math.floor(n))+1;else{for(var h,u,c=a-i||1,d=this._root;i>t||t>=a||r>e||e>=o||s>n||n>=l;)switch(u=(n<s)<<2|(e<r)<<1|t<i,(h=new Array(8))[u]=d,d=h,c*=2,u){case 0:a=i+c,o=r+c,l=s+c;break;case 1:i=a-c,o=r+c,l=s+c;break;case 2:a=i+c,r=o-c,l=s+c;break;case 3:i=a-c,r=o-c,l=s+c;break;case 4:a=i+c,o=r+c,s=l-c;break;case 5:i=a-c,o=r+c,s=l-c;break;case 6:a=i+c,r=o-c,s=l-c;break;case 7:i=a-c,r=o-c,s=l-c}this._root&&this._root.length&&(this._root=d)}return this._x0=i,this._y0=r,this._z0=s,this._x1=a,this._y1=o,this._z1=l,this},Yl.data=function(){var t=[];return this.visit((function(e){if(!e.length)do{t.push(e.data)}while(e=e.next)})),t},Yl.extent=function(t){return arguments.length?this.cover(+t[0][0],+t[0][1],+t[0][2]).cover(+t[1][0],+t[1][1],+t[1][2]):isNaN(this._x0)?void 0:[[this._x0,this._y0,this._z0],[this._x1,this._y1,this._z1]]},Yl.find=function(t,e,n,i){var r,s,a,o,l,h,u,c,d,p=this._x0,f=this._y0,m=this._z0,g=this._x1,_=this._y1,v=this._z1,y=[],x=this._root;for(x&&y.push(new Vl(x,p,f,m,g,_,v)),null==i?i=1/0:(p=t-i,f=e-i,m=n-i,g=t+i,_=e+i,v=n+i,i*=i);c=y.pop();)if(!(!(x=c.node)||(s=c.x0)>g||(a=c.y0)>_||(o=c.z0)>v||(l=c.x1)<p||(h=c.y1)<f||(u=c.z1)<m))if(x.length){var b=(s+l)/2,S=(a+h)/2,M=(o+u)/2;y.push(new Vl(x[7],b,S,M,l,h,u),new Vl(x[6],s,S,M,b,h,u),new Vl(x[5],b,a,M,l,S,u),new Vl(x[4],s,a,M,b,S,u),new Vl(x[3],b,S,o,l,h,M),new Vl(x[2],s,S,o,b,h,M),new Vl(x[1],b,a,o,l,S,M),new Vl(x[0],s,a,o,b,S,M)),(d=(n>=M)<<2|(e>=S)<<1|t>=b)&&(c=y[y.length-1],y[y.length-1]=y[y.length-1-d],y[y.length-1-d]=c)}else{var T=t-+this._x.call(null,x.data),w=e-+this._y.call(null,x.data),E=n-+this._z.call(null,x.data),A=T*T+w*w+E*E;if(A<i){var R=Math.sqrt(i=A);p=t-R,f=e-R,m=n-R,g=t+R,_=e+R,v=n+R,r=x.data}}return r},Yl.remove=function(t){if(isNaN(s=+this._x.call(null,t))||isNaN(a=+this._y.call(null,t))||isNaN(o=+this._z.call(null,t)))return this;var e,n,i,r,s,a,o,l,h,u,c,d,p,f,m,g=this._root,_=this._x0,v=this._y0,y=this._z0,x=this._x1,b=this._y1,S=this._z1;if(!g)return this;if(g.length)for(;;){if((c=s>=(l=(_+x)/2))?_=l:x=l,(d=a>=(h=(v+b)/2))?v=h:b=h,(p=o>=(u=(y+S)/2))?y=u:S=u,e=g,!(g=g[f=p<<2|d<<1|c]))return this;if(!g.length)break;(e[f+1&7]||e[f+2&7]||e[f+3&7]||e[f+4&7]||e[f+5&7]||e[f+6&7]||e[f+7&7])&&(n=e,m=f)}for(;g.data!==t;)if(i=g,!(g=g.next))return this;return(r=g.next)&&delete g.next,i?(r?i.next=r:delete i.next,this):e?(r?e[f]=r:delete e[f],(g=e[0]||e[1]||e[2]||e[3]||e[4]||e[5]||e[6]||e[7])&&g===(e[7]||e[6]||e[5]||e[4]||e[3]||e[2]||e[1]||e[0])&&!g.length&&(n?n[m]=g:this._root=g),this):(this._root=r,this)},Yl.removeAll=function(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this},Yl.root=function(){return this._root},Yl.size=function(){var t=0;return this.visit((function(e){if(!e.length)do{++t}while(e=e.next)})),t},Yl.visit=function(t){var e,n,i,r,s,a,o,l,h=[],u=this._root;for(u&&h.push(new Vl(u,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));e=h.pop();)if(!t(u=e.node,i=e.x0,r=e.y0,s=e.z0,a=e.x1,o=e.y1,l=e.z1)&&u.length){var c=(i+a)/2,d=(r+o)/2,p=(s+l)/2;(n=u[7])&&h.push(new Vl(n,c,d,p,a,o,l)),(n=u[6])&&h.push(new Vl(n,i,d,p,c,o,l)),(n=u[5])&&h.push(new Vl(n,c,r,p,a,d,l)),(n=u[4])&&h.push(new Vl(n,i,r,p,c,d,l)),(n=u[3])&&h.push(new Vl(n,c,d,s,a,o,p)),(n=u[2])&&h.push(new Vl(n,i,d,s,c,o,p)),(n=u[1])&&h.push(new Vl(n,c,r,s,a,d,p)),(n=u[0])&&h.push(new Vl(n,i,r,s,c,d,p))}return this},Yl.visitAfter=function(t){var e,n=[],i=[];for(this._root&&n.push(new Vl(this._root,this._x0,this._y0,this._z0,this._x1,this._y1,this._z1));e=n.pop();){var r=e.node;if(r.length){var s,a=e.x0,o=e.y0,l=e.z0,h=e.x1,u=e.y1,c=e.z1,d=(a+h)/2,p=(o+u)/2,f=(l+c)/2;(s=r[0])&&n.push(new Vl(s,a,o,l,d,p,f)),(s=r[1])&&n.push(new Vl(s,d,o,l,h,p,f)),(s=r[2])&&n.push(new Vl(s,a,p,l,d,u,f)),(s=r[3])&&n.push(new Vl(s,d,p,l,h,u,f)),(s=r[4])&&n.push(new Vl(s,a,o,f,d,p,c)),(s=r[5])&&n.push(new Vl(s,d,o,f,h,p,c)),(s=r[6])&&n.push(new Vl(s,a,p,f,d,u,c)),(s=r[7])&&n.push(new Vl(s,d,p,f,h,u,c))}i.push(e)}for(;e=i.pop();)t(e.node,e.x0,e.y0,e.z0,e.x1,e.y1,e.z1);return this},Yl.x=function(t){return arguments.length?(this._x=t,this):this._x},Yl.y=function(t){return arguments.length?(this._y=t,this):this._y},Yl.z=function(t){return arguments.length?(this._z=t,this):this._z};var eh={value:()=>{}};function nh(){for(var t,e=0,n=arguments.length,i={};e<n;++e){if(!(t=arguments[e]+"")||t in i||/[\s.]/.test(t))throw new Error("illegal type: "+t);i[t]=[]}return new ih(i)}function ih(t){this._=t}function rh(t,e){for(var n,i=0,r=t.length;i<r;++i)if((n=t[i]).name===e)return n.value}function sh(t,e,n){for(var i=0,r=t.length;i<r;++i)if(t[i].name===e){t[i]=eh,t=t.slice(0,i).concat(t.slice(i+1));break}return null!=n&&t.push({name:e,value:n}),t}ih.prototype=nh.prototype={constructor:ih,on:function(t,e){var n,i,r=this._,s=(i=r,(t+"").trim().split(/^|\s+/).map((function(t){var e="",n=t.indexOf(".");if(n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!i.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}}))),a=-1,o=s.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++a<o;)if(n=(t=s[a]).type)r[n]=sh(r[n],t.name,e);else if(null==e)for(n in r)r[n]=sh(r[n],t.name,null);return this}for(;++a<o;)if((n=(t=s[a]).type)&&(n=rh(r[n],t.name)))return n},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new ih(t)},call:function(t,e){if((n=arguments.length-2)>0)for(var n,i,r=new Array(n),s=0;s<n;++s)r[s]=arguments[s+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(s=0,n=(i=this._[t]).length;s<n;++s)i[s].value.apply(e,r)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var i=this._[t],r=0,s=i.length;r<s;++r)i[r].value.apply(e,n)}};var ah,oh,lh=0,hh=0,uh=0,ch=0,dh=0,ph=0,fh="object"==typeof performance&&performance.now?performance:Date,mh="object"==typeof window&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function gh(){return dh||(mh(_h),dh=fh.now()+ph)}function _h(){dh=0}function vh(){this._call=this._time=this._next=null}function yh(t,e,n){var i=new vh;return i.restart(t,e,n),i}function xh(){dh=(ch=fh.now())+ph,lh=hh=0;try{!function(){gh(),++lh;for(var t,e=ah;e;)(t=dh-e._time)>=0&&e._call.call(void 0,t),e=e._next;--lh}()}finally{lh=0,function(){var t,e,n=ah,i=1/0;for(;n;)n._call?(i>n._time&&(i=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:ah=e);oh=t,Sh(i)}(),dh=0}}function bh(){var t=fh.now(),e=t-ch;e>1e3&&(ph-=e,ch=t)}function Sh(t){lh||(hh&&(hh=clearTimeout(hh)),t-dh>24?(t<1/0&&(hh=setTimeout(xh,t-fh.now()-ph)),uh&&(uh=clearInterval(uh))):(uh||(ch=fh.now(),uh=setInterval(bh,1e3)),lh=1,mh(xh)))}vh.prototype=yh.prototype={constructor:vh,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?gh():+n)+(null==e?0:+e),this._next||oh===this||(oh?oh._next=this:ah=this,oh=this),this._call=t,this._time=n,Sh()},stop:function(){this._call&&(this._call=null,this._time=1/0,Sh())}};const Mh=4294967296;function Th(t){return t.x}function wh(t){return t.y}function Eh(t){return t.z}var Ah,Rh,Ch,Nh,Ph=Math.PI*(3-Math.sqrt(5)),Ih=20*Math.PI/(9+Math.sqrt(221));function Lh(t,e){e=e||2;var n,i=Math.min(3,Math.max(1,Math.round(e))),r=1,s=.001,a=1-Math.pow(s,1/300),o=0,l=.6,h=new Map,u=yh(p),c=nh("tick","end"),d=function(){let t=1;return()=>(t=(1664525*t+1013904223)%Mh)/Mh}();function p(){f(),c.call("tick",n),r<s&&(u.stop(),c.call("end",n))}function f(e){var s,u,c=t.length;void 0===e&&(e=1);for(var d=0;d<e;++d)for(r+=(o-r)*a,h.forEach((function(t){t(r)})),s=0;s<c;++s)null==(u=t[s]).fx?u.x+=u.vx*=l:(u.x=u.fx,u.vx=0),i>1&&(null==u.fy?u.y+=u.vy*=l:(u.y=u.fy,u.vy=0)),i>2&&(null==u.fz?u.z+=u.vz*=l:(u.z=u.fz,u.vz=0));return n}function m(){for(var e,n=0,r=t.length;n<r;++n){if((e=t[n]).index=n,null!=e.fx&&(e.x=e.fx),null!=e.fy&&(e.y=e.fy),null!=e.fz&&(e.z=e.fz),isNaN(e.x)||i>1&&isNaN(e.y)||i>2&&isNaN(e.z)){var s=10*(i>2?Math.cbrt(.5+n):i>1?Math.sqrt(.5+n):n),a=n*Ph,o=n*Ih;1===i?e.x=s:2===i?(e.x=s*Math.cos(a),e.y=s*Math.sin(a)):(e.x=s*Math.sin(a)*Math.cos(o),e.y=s*Math.cos(a),e.z=s*Math.sin(a)*Math.sin(o))}(isNaN(e.vx)||i>1&&isNaN(e.vy)||i>2&&isNaN(e.vz))&&(e.vx=0,i>1&&(e.vy=0),i>2&&(e.vz=0))}}function g(e){return e.initialize&&e.initialize(t,d,i),e}return null==t&&(t=[]),m(),n={tick:f,restart:function(){return u.restart(p),n},stop:function(){return u.stop(),n},numDimensions:function(t){return arguments.length?(i=Math.min(3,Math.max(1,Math.round(t))),h.forEach(g),n):i},nodes:function(e){return arguments.length?(t=e,m(),h.forEach(g),n):t},alpha:function(t){return arguments.length?(r=+t,n):r},alphaMin:function(t){return arguments.length?(s=+t,n):s},alphaDecay:function(t){return arguments.length?(a=+t,n):+a},alphaTarget:function(t){return arguments.length?(o=+t,n):o},velocityDecay:function(t){return arguments.length?(l=1-t,n):1-l},randomSource:function(t){return arguments.length?(d=t,h.forEach(g),n):d},force:function(t,e){return arguments.length>1?(null==e?h.delete(t):h.set(t,g(e)),n):h.get(t)},find:function(){var e,n,r,s,a,o,l=Array.prototype.slice.call(arguments),h=l.shift()||0,u=(i>1?l.shift():null)||0,c=(i>2?l.shift():null)||0,d=l.shift()||1/0,p=0,f=t.length;for(d*=d,p=0;p<f;++p)(s=(e=h-(a=t[p]).x)*e+(n=u-(a.y||0))*n+(r=c-(a.z||0))*r)<d&&(o=a,d=s);return o},on:function(t,e){return arguments.length>1?(c.on(t,e),n):c.on(t)}}}function Uh(){var t,e,n,i,r,s,a=Kl(-30),o=1,l=1/0,h=.81;function u(i){var s,a=t.length,o=(1===e?Cl(t,Th):2===e?Fl(t,Th,wh):3===e?ql(t,Th,wh,Eh):null).visitAfter(d);for(r=i,s=0;s<a;++s)n=t[s],o.visit(p)}function c(){if(t){var e,n,i=t.length;for(s=new Array(i),e=0;e<i;++e)n=t[e],s[n.index]=+a(n,e,t)}}function d(t){var n,i,r,a,o,l,h=0,u=0,c=t.length;if(c){for(r=a=o=l=0;l<c;++l)(n=t[l])&&(i=Math.abs(n.value))&&(h+=n.value,u+=i,r+=i*(n.x||0),a+=i*(n.y||0),o+=i*(n.z||0));h*=Math.sqrt(4/c),t.x=r/u,e>1&&(t.y=a/u),e>2&&(t.z=o/u)}else{(n=t).x=n.data.x,e>1&&(n.y=n.data.y),e>2&&(n.z=n.data.z);do{h+=s[n.data.index]}while(n=n.next)}t.value=h}function p(t,a,u,c,d){if(!t.value)return!0;var p=[u,c,d][e-1],f=t.x-n.x,m=e>1?t.y-n.y:0,g=e>2?t.z-n.z:0,_=p-a,v=f*f+m*m+g*g;if(_*_/h<v)return v<l&&(0===f&&(v+=(f=Zl(i))*f),e>1&&0===m&&(v+=(m=Zl(i))*m),e>2&&0===g&&(v+=(g=Zl(i))*g),v<o&&(v=Math.sqrt(o*v)),n.vx+=f*t.value*r/v,e>1&&(n.vy+=m*t.value*r/v),e>2&&(n.vz+=g*t.value*r/v)),!0;if(!(t.length||v>=l)){(t.data!==n||t.next)&&(0===f&&(v+=(f=Zl(i))*f),e>1&&0===m&&(v+=(m=Zl(i))*m),e>2&&0===g&&(v+=(g=Zl(i))*g),v<o&&(v=Math.sqrt(o*v)));do{t.data!==n&&(_=s[t.data.index]*r/v,n.vx+=f*_,e>1&&(n.vy+=m*_),e>2&&(n.vz+=g*_))}while(t=t.next)}}return u.initialize=function(n,...r){t=n,i=r.find((t=>"function"==typeof t))||Math.random,e=r.find((t=>[1,2,3].includes(t)))||2,c()},u.strength=function(t){return arguments.length?(a="function"==typeof t?t:Kl(+t),c(),u):a},u.distanceMin=function(t){return arguments.length?(o=t*t,u):Math.sqrt(o)},u.distanceMax=function(t){return arguments.length?(l=t*t,u):Math.sqrt(l)},u.theta=function(t){return arguments.length?(h=t*t,u):Math.sqrt(h)},u}function Dh(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function Oh(){if(Rh)return Ah;return Rh=1,Ah=function(t){!function(t){if(!t)throw new Error("Eventify cannot use falsy object as events subject");for(var e=["on","fire","off"],n=0;n<e.length;++n)if(t.hasOwnProperty(e[n]))throw new Error("Subject cannot be eventified, since it already has property '"+e[n]+"'")}(t);var e=function(t){var e=Object.create(null);return{on:function(n,i,r){if("function"!=typeof i)throw new Error("callback is expected to be a function");var s=e[n];return s||(s=e[n]=[]),s.push({callback:i,ctx:r}),t},off:function(n,i){if(void 0===n)return e=Object.create(null),t;if(e[n])if("function"!=typeof i)delete e[n];else for(var r=e[n],s=0;s<r.length;++s)r[s].callback===i&&r.splice(s,1);return t},fire:function(n){var i,r=e[n];if(!r)return t;arguments.length>1&&(i=Array.prototype.splice.call(arguments,1));for(var s=0;s<r.length;++s){var a=r[s];a.callback.apply(a.ctx,i)}return t}}}(t);return t.on=e.on,t.off=e.off,t.fire=e.fire,t},Ah}var Fh,Bh,zh,kh,Gh,Vh=function(){if(Nh)return Ch;Nh=1,Ch=function(s){"uniqueLinkId"in(s=s||{})&&(console.warn("ngraph.graph: Starting from version 0.14 `uniqueLinkId` is deprecated.\nUse `multigraph` option instead\n","\n","Note: there is also change in default behavior: From now on each graph\nis considered to be not a multigraph by default (each edge is unique)."),s.multigraph=s.uniqueLinkId);void 0===s.multigraph&&(s.multigraph=!1);if("function"!=typeof Map)throw new Error("ngraph.graph requires `Map` to be defined. Please polyfill it before using ngraph");var a=new Map,o=new Map,l={},h=0,u=s.multigraph?function(t,e,n){var s=r(t,e),a=l.hasOwnProperty(s);if(a||w(t,e)){a||(l[s]=0);var o="@"+ ++l[s];s=r(t+o,e+o)}return new i(t,e,n,s)}:function(t,e,n){var s=r(t,e),a=o.get(s);if(a)return a.data=n,a;return new i(t,e,n,s)},c=[],d=E,p=E,f=E,m=E,g={version:20,addNode:y,addLink:function(t,e,i){f();var r=x(t)||y(t),s=x(e)||y(e),a=u(t,e,i),l=o.has(a.id);o.set(a.id,a),n(r,a),t!==e&&n(s,a);return d(a,l?"update":"add"),m(),a},removeLink:function(t,e){void 0!==e&&(t=w(t,e));return T(t)},removeNode:b,getNode:x,getNodeCount:S,getLinkCount:M,getEdgeCount:M,getLinksCount:M,getNodesCount:S,getLinks:function(t){var e=x(t);return e?e.links:null},forEachNode:C,forEachLinkedNode:function(t,e,n){var i=x(t);if(i&&i.links&&"function"==typeof e)return n?function(t,e,n){var i=t.values(),r=i.next();for(;!r.done;){var s=r.value;if(s.fromId===e&&n(a.get(s.toId),s))return!0;r=i.next()}}(i.links,t,e):function(t,e,n){var i=t.values(),r=i.next();for(;!r.done;){var s=r.value,o=s.fromId===e?s.toId:s.fromId;if(n(a.get(o),s))return!0;r=i.next()}}(i.links,t,e)},forEachLink:function(t){if("function"==typeof t)for(var e=o.values(),n=e.next();!n.done;){if(t(n.value))return!0;n=e.next()}},beginUpdate:f,endUpdate:m,clear:function(){f(),C((function(t){b(t.id)})),m()},hasLink:w,hasNode:x,getLink:w};return t(g),function(){var t=g.on;function e(){return g.beginUpdate=f=A,g.endUpdate=m=R,d=_,p=v,g.on=t,t.apply(g,arguments)}g.on=e}(),g;function _(t,e){c.push({link:t,changeType:e})}function v(t,e){c.push({node:t,changeType:e})}function y(t,n){if(void 0===t)throw new Error("Invalid node identifier");f();var i=x(t);return i?(i.data=n,p(i,"update")):(i=new e(t,n),p(i,"add")),a.set(t,i),m(),i}function x(t){return a.get(t)}function b(t){var e=x(t);if(!e)return!1;f();var n=e.links;return n&&(n.forEach(T),e.links=null),a.delete(t),p(e,"remove"),m(),!0}function S(){return a.size}function M(){return o.size}function T(t){if(!t)return!1;if(!o.get(t.id))return!1;f(),o.delete(t.id);var e=x(t.fromId),n=x(t.toId);return e&&e.links.delete(t),n&&n.links.delete(t),d(t,"remove"),m(),!0}function w(t,e){if(void 0!==t&&void 0!==e)return o.get(r(t,e))}function E(){}function A(){h+=1}function R(){0===(h-=1)&&c.length>0&&(g.fire("changed",c),c.length=0)}function C(t){if("function"!=typeof t)throw new Error("Function is expected to iterate over graph nodes. You passed "+t);for(var e=a.values(),n=e.next();!n.done;){if(t(n.value))return!0;n=e.next()}}};var t=Oh();function e(t,e){this.id=t,this.links=null,this.data=e}function n(t,e){t.links?t.links.add(e):t.links=new Set([e])}function i(t,e,n,i){this.fromId=t,this.toId=e,this.data=n,this.id=i}function r(t,e){return t.toString()+"👉 "+e.toString()}return Ch}(),Hh=Dh(Vh),jh={exports:{}},Wh={exports:{}};function qh(){return Bh||(Bh=1,Fh=function(t){return 0===t?"x":1===t?"y":2===t?"z":"c"+(t+1)}),Fh}function Xh(){if(kh)return zh;kh=1;const t=qh();return zh=function(e){return function(n,i){let r=i&&i.indent||0,s=i&&void 0!==i.join?i.join:"\n",a=Array(r+1).join(" "),o=[];for(let i=0;i<e;++i){let e=t(i),r=0===i?"":a;o.push(r+n.replace(/{var}/g,e))}return o.join(s)}},zh}var $h,Yh={exports:{}};var Kh,Zh={exports:{}};var Qh,Jh={exports:{}};var tu,eu={exports:{}};var nu,iu,ru,su,au,ou={exports:{}};var lu,hu,uu,cu,du={exports:{}};function pu(){if(uu)return hu;uu=1,hu=function(l){var h=(ru||(ru=1,iu=function(t,e,n,i){this.from=t,this.to=e,this.length=n,this.coefficient=i}),iu),u=(au||(au=1,su=function t(e,n){var i;if(e||(e={}),n)for(i in n)if(n.hasOwnProperty(i)){var r=e.hasOwnProperty(i),s=typeof n[i];r&&typeof e[i]===s?"object"===s&&(e[i]=t(e[i],n[i])):e[i]=n[i]}return e}),su),c=Oh();if(l){if(void 0!==l.springCoeff)throw new Error("springCoeff was renamed to springCoefficient");if(void 0!==l.dragCoeff)throw new Error("dragCoeff was renamed to dragCoefficient")}l=u(l,{springLength:10,springCoefficient:.8,gravity:-12,theta:.8,dragCoefficient:.9,timeStep:.5,adaptiveTimeStepWeight:0,dimensions:2,debug:!1});var d=a[l.dimensions];if(!d){var p=l.dimensions;d={Body:t(p,l.debug),createQuadTree:e(p),createBounds:n(p),createDragForce:i(p),createSpringForce:r(p),integrate:s(p)},a[p]=d}var f=d.Body,m=d.createQuadTree,g=d.createBounds,_=d.createDragForce,v=d.createSpringForce,y=d.integrate,x=function(){if(lu)return du.exports;function t(t){return new e("number"==typeof t?t:+new Date)}function e(t){this.seed=t}function n(t){return Math.sqrt(2*Math.PI/t)*Math.pow(1/Math.E*(t+1/(12*t-1/(10*t))),t)}function i(){var t=this.seed;return t=4294967295&(3042594569^(t=4251993797+(t=4294967295&(3550635116+(t=374761393+(t=4294967295&(3345072700^(t=t+2127912214+(t<<12)&4294967295)^t>>>19))+(t<<5)&4294967295)^t<<9))+(t<<3)&4294967295)^t>>>16),this.seed=t,(268435455&t)/268435456}return lu=1,du.exports=t,du.exports.random=t,du.exports.randomIterator=function(e,n){var i=n||t();if("function"!=typeof i.next)throw new Error("customRandom does not match expected API: next() function is missing");return{forEach:function(t){var n,r,s;for(n=e.length-1;n>0;--n)r=i.next(n+1),s=e[r],e[r]=e[n],e[n]=s,t(s);e.length&&t(e[0])},shuffle:function(){var t,n,r;for(t=e.length-1;t>0;--t)n=i.next(t+1),r=e[n],e[n]=e[t],e[t]=r;return e}}},e.prototype.next=function(t){return Math.floor(this.nextDouble()*t)},e.prototype.nextDouble=i,e.prototype.uniform=i,e.prototype.gaussian=function(){var t,e,n;do{t=(e=2*this.nextDouble()-1)*e+(n=2*this.nextDouble()-1)*n}while(t>=1||0===t);return e*Math.sqrt(-2*Math.log(t)/t)},e.prototype.levy=function(){var t=1.5,e=Math.pow(n(2.5)*Math.sin(Math.PI*t/2)/(n(1.25)*t*Math.pow(2,.25)),1/t);return this.gaussian()*e/Math.pow(Math.abs(this.gaussian()),1/t)},du.exports}().random(42),b=[],S=[],M=m(l,x),T=g(b,l,x),w=v(l,x),E=_(l),A=[],R=new Map,C=0;I("nbody",(function(){if(0===b.length)return;M.insertBodies(b);var t=b.length;for(;t--;){var e=b[t];e.isPinned||(e.reset(),M.updateBodyForce(e),E.update(e))}})),I("spring",(function(){var t=S.length;for(;t--;)w.update(S[t])}));var N={bodies:b,quadTree:M,springs:S,settings:l,addForce:I,removeForce:function(t){var e=A.indexOf(R.get(t));if(e<0)return;A.splice(e,1),R.delete(t)},getForces:function(){return R},step:function(){for(var t=0;t<A.length;++t)A[t](C);var e=y(b,l.timeStep,l.adaptiveTimeStepWeight);return C+=1,e},addBody:function(t){if(!t)throw new Error("Body is required");return b.push(t),t},addBodyAt:function(t){if(!t)throw new Error("Body position is required");var e=(t=>new f(t))(t);return b.push(e),e},removeBody:function(t){if(t){var e=b.indexOf(t);if(!(e<0))return b.splice(e,1),0===b.length&&T.reset(),!0}},addSpring:function(t,e,n,i){if(!t||!e)throw new Error("Cannot add null spring to force simulator");"number"!=typeof n&&(n=-1);var r=new h(t,e,n,i>=0?i:-1);return S.push(r),r},getTotalMovement:function(){return 0},removeSpring:function(t){if(t){var e=S.indexOf(t);return e>-1?(S.splice(e,1),!0):void 0}},getBestNewBodyPosition:function(t){return T.getBestNewPosition(t)},getBBox:P,getBoundingBox:P,invalidateBBox:function(){console.warn("invalidateBBox() is deprecated, bounds always recomputed on `getBBox()` call")},gravity:function(t){return void 0!==t?(l.gravity=t,M.options({gravity:t}),this):l.gravity},theta:function(t){return void 0!==t?(l.theta=t,M.options({theta:t}),this):l.theta},random:x};return function(t,e){for(var n in t)o(t,e,n)}(l,N),c(N),N;function P(){return T.update(),T.box}function I(t,e){if(R.has(t))throw new Error("Force "+t+" is already added");R.set(t,e),A.push(e)}};var t=function(){if(Gh)return Wh.exports;Gh=1;const t=Xh();function e(t,e){return`\n${i(t,e)}\n${n(t)}\nreturn {Body: Body, Vector: Vector};\n`}function n(e){let n=t(e),i=n("{var}",{join:", "});return`\nfunction Body(${i}) {\n this.isPinned = false;\n this.pos = new Vector(${i});\n this.force = new Vector();\n this.velocity = new Vector();\n this.mass = 1;\n\n this.springCount = 0;\n this.springLength = 0;\n}\n\nBody.prototype.reset = function() {\n this.force.reset();\n this.springCount = 0;\n this.springLength = 0;\n}\n\nBody.prototype.setPosition = function (${i}) {\n ${n("this.pos.{var} = {var} || 0;",{indent:2})}\n};`}function i(e,n){let i=t(e),r="";return n&&(r=`${i("\n\t var v{var};\n\tObject.defineProperty(this, '{var}', {\n\t set: function(v) { \n\t if (!Number.isFinite(v)) throw new Error('Cannot set non-numbers to {var}');\n\t v{var} = v; \n\t },\n\t get: function() { return v{var}; }\n\t});")}`),`function Vector(${i("{var}",{join:", "})}) {\n ${r}\n if (typeof arguments[0] === 'object') {\n // could be another vector\n let v = arguments[0];\n ${i('if (!Number.isFinite(v.{var})) throw new Error("Expected value is not a finite number at Vector constructor ({var})");',{indent:4})}\n ${i("this.{var} = v.{var};",{indent:4})}\n } else {\n ${i('this.{var} = typeof {var} === "number" ? {var} : 0;',{indent:4})}\n }\n }\n \n Vector.prototype.reset = function () {\n ${i("this.{var} = ",{join:""})}0;\n };`}return Wh.exports=function(t,n){let i=e(t,n),{Body:r}=new Function(i)();return r},Wh.exports.generateCreateBodyFunctionBody=e,Wh.exports.getVectorCode=i,Wh.exports.getBodyCode=n,Wh.exports}(),e=function(){if($h)return Yh.exports;$h=1;const t=Xh(),e=qh();function n(n){let l=t(n),h=Math.pow(2,n);return`\n${o()}\n${a(n)}\n${i(n)}\n${s(n)}\n${r(n)}\n\nfunction createQuadTree(options, random) {\n options = options || {};\n options.gravity = typeof options.gravity === 'number' ? options.gravity : -1;\n options.theta = typeof options.theta === 'number' ? options.theta : 0.8;\n\n var gravity = options.gravity;\n var updateQueue = [];\n var insertStack = new InsertStack();\n var theta = options.theta;\n\n var nodesCache = [];\n var currentInCache = 0;\n var root = newNode();\n\n return {\n insertBodies: insertBodies,\n\n /**\n * Gets root node if it is present\n */\n getRoot: function() {\n return root;\n },\n\n updateBodyForce: update,\n\n options: function(newOptions) {\n if (newOptions) {\n if (typeof newOptions.gravity === 'number') {\n gravity = newOptions.gravity;\n }\n if (typeof newOptions.theta === 'number') {\n theta = newOptions.theta;\n }\n\n return this;\n }\n\n return {\n gravity: gravity,\n theta: theta\n };\n }\n };\n\n function newNode() {\n // To avoid pressure on GC we reuse nodes.\n var node = nodesCache[currentInCache];\n if (node) {\n${function(t){let e=[];for(let n=0;n<h;++n)e.push(`${t}quad${n} = null;`);return e.join("\n")}(" node.")}\n node.body = null;\n node.mass = ${l("node.mass_{var} = ",{join:""})}0;\n ${l("node.min_{var} = node.max_{var} = ",{join:""})}0;\n } else {\n node = new QuadNode();\n nodesCache[currentInCache] = node;\n }\n\n ++currentInCache;\n return node;\n }\n\n function update(sourceBody) {\n var queue = updateQueue;\n var v;\n ${l("var d{var};",{indent:4})}\n var r; \n ${l("var f{var} = 0;",{indent:4})}\n var queueLength = 1;\n var shiftIdx = 0;\n var pushIdx = 1;\n\n queue[0] = root;\n\n while (queueLength) {\n var node = queue[shiftIdx];\n var body = node.body;\n\n queueLength -= 1;\n shiftIdx += 1;\n var differentBody = (body !== sourceBody);\n if (body && differentBody) {\n // If the current node is a leaf node (and it is not source body),\n // calculate the force exerted by the current node on body, and add this\n // amount to body's net force.\n ${l("d{var} = body.pos.{var} - sourceBody.pos.{var};",{indent:8})}\n r = Math.sqrt(${l("d{var} * d{var}",{join:" + "})});\n\n if (r === 0) {\n // Poor man's protection against zero distance.\n ${l("d{var} = (random.nextDouble() - 0.5) / 50;",{indent:10})}\n r = Math.sqrt(${l("d{var} * d{var}",{join:" + "})});\n }\n\n // This is standard gravitation force calculation but we divide\n // by r^3 to save two operations when normalizing force vector.\n v = gravity * body.mass * sourceBody.mass / (r * r * r);\n ${l("f{var} += v * d{var};",{indent:8})}\n } else if (differentBody) {\n // Otherwise, calculate the ratio s / r, where s is the width of the region\n // represented by the internal node, and r is the distance between the body\n // and the node's center-of-mass\n ${l("d{var} = node.mass_{var} / node.mass - sourceBody.pos.{var};",{indent:8})}\n r = Math.sqrt(${l("d{var} * d{var}",{join:" + "})});\n\n if (r === 0) {\n // Sorry about code duplication. I don't want to create many functions\n // right away. Just want to see performance first.\n ${l("d{var} = (random.nextDouble() - 0.5) / 50;",{indent:10})}\n r = Math.sqrt(${l("d{var} * d{var}",{join:" + "})});\n }\n // If s / r < θ, treat this internal node as a single body, and calculate the\n // force it exerts on sourceBody, and add this amount to sourceBody's net force.\n if ((node.max_${e(0)} - node.min_${e(0)}) / r < theta) {\n // in the if statement above we consider node's width only\n // because the region was made into square during tree creation.\n // Thus there is no difference between using width or height.\n v = gravity * node.mass * sourceBody.mass / (r * r * r);\n ${l("f{var} += v * d{var};",{indent:10})}\n } else {\n // Otherwise, run the procedure recursively on each of the current node's children.\n\n // I intentionally unfolded this loop, to save several CPU cycles.\n${function(){let t=Array(11).join(" "),e=[];for(let n=0;n<h;++n)e.push(t+`if (node.quad${n}) {`),e.push(t+` queue[pushIdx] = node.quad${n};`),e.push(t+" queueLength += 1;"),e.push(t+" pushIdx += 1;"),e.push(t+"}");return e.join("\n")}()}\n }\n }\n }\n\n ${l("sourceBody.force.{var} += f{var};",{indent:4})}\n }\n\n function insertBodies(bodies) {\n ${l("var {var}min = Number.MAX_VALUE;",{indent:4})}\n ${l("var {var}max = Number.MIN_VALUE;",{indent:4})}\n var i = bodies.length;\n\n // To reduce quad tree depth we are looking for exact bounding box of all particles.\n while (i--) {\n var pos = bodies[i].pos;\n ${l("if (pos.{var} < {var}min) {var}min = pos.{var};",{indent:6})}\n ${l("if (pos.{var} > {var}max) {var}max = pos.{var};",{indent:6})}\n }\n\n // Makes the bounds square.\n var maxSideLength = -Infinity;\n ${l("if ({var}max - {var}min > maxSideLength) maxSideLength = {var}max - {var}min ;",{indent:4})}\n\n currentInCache = 0;\n root = newNode();\n ${l("root.min_{var} = {var}min;",{indent:4})}\n ${l("root.max_{var} = {var}min + maxSideLength;",{indent:4})}\n\n i = bodies.length - 1;\n if (i >= 0) {\n root.body = bodies[i];\n }\n while (i--) {\n insert(bodies[i], root);\n }\n }\n\n function insert(newBody) {\n insertStack.reset();\n insertStack.push(root, newBody);\n\n while (!insertStack.isEmpty()) {\n var stackItem = insertStack.pop();\n var node = stackItem.node;\n var body = stackItem.body;\n\n if (!node.body) {\n // This is internal node. Update the total mass of the node and center-of-mass.\n ${l("var {var} = body.pos.{var};",{indent:8})}\n node.mass += body.mass;\n ${l("node.mass_{var} += body.mass * {var};",{indent:8})}\n\n // Recursively insert the body in the appropriate quadrant.\n // But first find the appropriate quadrant.\n var quadIdx = 0; // Assume we are in the 0's quad.\n ${l("var min_{var} = node.min_{var};",{indent:8})}\n ${l("var max_{var} = (min_{var} + node.max_{var}) / 2;",{indent:8})}\n\n${function(){let t=[],i=Array(8+1).join(" ");for(let r=0;r<n;++r)t.push(i+`if (${e(r)} > max_${e(r)}) {`),t.push(i+` quadIdx = quadIdx + ${Math.pow(2,r)};`),t.push(i+` min_${e(r)} = max_${e(r)};`),t.push(i+` max_${e(r)} = node.max_${e(r)};`),t.push(i+"}");return t.join("\n")}()}\n\n var child = getChild(node, quadIdx);\n\n if (!child) {\n // The node is internal but this quadrant is not taken. Add\n // subnode to it.\n child = newNode();\n ${l("child.min_{var} = min_{var};",{indent:10})}\n ${l("child.max_{var} = max_{var};",{indent:10})}\n child.body = body;\n\n setChild(node, quadIdx, child);\n } else {\n // continue searching in this quadrant.\n insertStack.push(child, body);\n }\n } else {\n // We are trying to add to the leaf node.\n // We have to convert current leaf into internal node\n // and continue adding two nodes.\n var oldBody = node.body;\n node.body = null; // internal nodes do not cary bodies\n\n if (isSamePosition(oldBody.pos, body.pos)) {\n // Prevent infinite subdivision by bumping one node\n // anywhere in this quadrant\n var retriesCount = 3;\n do {\n var offset = random.nextDouble();\n ${l("var d{var} = (node.max_{var} - node.min_{var}) * offset;",{indent:12})}\n\n ${l("oldBody.pos.{var} = node.min_{var} + d{var};",{indent:12})}\n retriesCount -= 1;\n // Make sure we don't bump it out of the box. If we do, next iteration should fix it\n } while (retriesCount > 0 && isSamePosition(oldBody.pos, body.pos));\n\n if (retriesCount === 0 && isSamePosition(oldBody.pos, body.pos)) {\n // This is very bad, we ran out of precision.\n // if we do not return from the method we'll get into\n // infinite loop here. So we sacrifice correctness of layout, and keep the app running\n // Next layout iteration should get larger bounding box in the first step and fix this\n return;\n }\n }\n // Next iteration should subdivide node further.\n insertStack.push(node, oldBody);\n insertStack.push(node, body);\n }\n }\n }\n}\nreturn createQuadTree;\n\n`}function i(e){let n=t(e);return`\n function isSamePosition(point1, point2) {\n ${n("var d{var} = Math.abs(point1.{var} - point2.{var});",{indent:2})}\n \n return ${n("d{var} < 1e-8",{join:" && "})};\n } \n`}function r(t){var e=Math.pow(2,t);return`\nfunction setChild(node, idx, child) {\n ${function(){let t=[];for(let n=0;n<e;++n){let e=0===n?" ":" else ";t.push(`${e}if (idx === ${n}) node.quad${n} = child;`)}return t.join("\n")}()}\n}`}function s(t){return`function getChild(node, idx) {\n${function(){let e=[],n=Math.pow(2,t);for(let t=0;t<n;++t)e.push(` if (idx === ${t}) return node.quad${t};`);return e.join("\n")}()}\n return null;\n}`}function a(e){let n=t(e),i=Math.pow(2,e);return`\nfunction QuadNode() {\n // body stored inside this node. In quad tree only leaf nodes (by construction)\n // contain bodies:\n this.body = null;\n\n // Child nodes are stored in quads. Each quad is presented by number:\n // 0 | 1\n // -----\n // 2 | 3\n${function(t){let e=[];for(let n=0;n<i;++n)e.push(`${t}quad${n} = null;`);return e.join("\n")}(" this.")}\n\n // Total mass of current node\n this.mass = 0;\n\n // Center of mass coordinates\n ${n("this.mass_{var} = 0;",{indent:2})}\n\n // bounding box coordinates\n ${n("this.min_{var} = 0;",{indent:2})}\n ${n("this.max_{var} = 0;",{indent:2})}\n}\n`}function o(){return"\n/**\n * Our implementation of QuadTree is non-recursive to avoid GC hit\n * This data structure represent stack of elements\n * which we are trying to insert into quad tree.\n */\nfunction InsertStack () {\n this.stack = [];\n this.popIdx = 0;\n}\n\nInsertStack.prototype = {\n isEmpty: function() {\n return this.popIdx === 0;\n },\n push: function (node, body) {\n var item = this.stack[this.popIdx];\n if (!item) {\n // we are trying to avoid memory pressure: create new element\n // only when absolutely necessary\n this.stack[this.popIdx] = new InsertStackElement(node, body);\n } else {\n item.node = node;\n item.body = body;\n }\n ++this.popIdx;\n },\n pop: function () {\n if (this.popIdx > 0) {\n return this.stack[--this.popIdx];\n }\n },\n reset: function () {\n this.popIdx = 0;\n }\n};\n\nfunction InsertStackElement(node, body) {\n this.node = node; // QuadTree node\n this.body = body; // physical body which needs to be inserted to node\n}\n"}return Yh.exports=function(t){let e=n(t);return new Function(e)()},Yh.exports.generateQuadTreeFunctionBody=n,Yh.exports.getInsertStackCode=o,Yh.exports.getQuadNodeCode=a,Yh.exports.isSamePosition=i,Yh.exports.getChildBodyCode=s,Yh.exports.setChildBodyCode=r,Yh.exports}(),n=function(){if(Kh)return Zh.exports;Kh=1,Zh.exports=function(t){let n=e(t);return new Function("bodies","settings","random",n)},Zh.exports.generateFunctionBody=e;const t=Xh();function e(e){let n=t(e);return`\n var boundingBox = {\n ${n("min_{var}: 0, max_{var}: 0,",{indent:4})}\n };\n\n return {\n box: boundingBox,\n\n update: updateBoundingBox,\n\n reset: resetBoundingBox,\n\n getBestNewPosition: function (neighbors) {\n var ${n("base_{var} = 0",{join:", "})};\n\n if (neighbors.length) {\n for (var i = 0; i < neighbors.length; ++i) {\n let neighborPos = neighbors[i].pos;\n ${n("base_{var} += neighborPos.{var};",{indent:10})}\n }\n\n ${n("base_{var} /= neighbors.length;",{indent:8})}\n } else {\n ${n("base_{var} = (boundingBox.min_{var} + boundingBox.max_{var}) / 2;",{indent:8})}\n }\n\n var springLength = settings.springLength;\n return {\n ${n("{var}: base_{var} + (random.nextDouble() - 0.5) * springLength,",{indent:8})}\n };\n }\n };\n\n function updateBoundingBox() {\n var i = bodies.length;\n if (i === 0) return; // No bodies - no borders.\n\n ${n("var max_{var} = -Infinity;",{indent:4})}\n ${n("var min_{var} = Infinity;",{indent:4})}\n\n while(i--) {\n // this is O(n), it could be done faster with quadtree, if we check the root node bounds\n var bodyPos = bodies[i].pos;\n ${n("if (bodyPos.{var} < min_{var}) min_{var} = bodyPos.{var};",{indent:6})}\n ${n("if (bodyPos.{var} > max_{var}) max_{var} = bodyPos.{var};",{indent:6})}\n }\n\n ${n("boundingBox.min_{var} = min_{var};",{indent:4})}\n ${n("boundingBox.max_{var} = max_{var};",{indent:4})}\n }\n\n function resetBoundingBox() {\n ${n("boundingBox.min_{var} = boundingBox.max_{var} = 0;",{indent:4})}\n }\n`}return Zh.exports}(),i=function(){if(Qh)return Jh.exports;Qh=1;const t=Xh();function e(e){return`\n if (!Number.isFinite(options.dragCoefficient)) throw new Error('dragCoefficient is not a finite number');\n\n return {\n update: function(body) {\n ${t(e)("body.force.{var} -= options.dragCoefficient * body.velocity.{var};",{indent:6})}\n }\n };\n`}return Jh.exports=function(t){let n=e(t);return new Function("options",n)},Jh.exports.generateCreateDragForceFunctionBody=e,Jh.exports}(),r=function(){if(tu)return eu.exports;tu=1;const t=Xh();function e(e){let n=t(e);return`\n if (!Number.isFinite(options.springCoefficient)) throw new Error('Spring coefficient is not a number');\n if (!Number.isFinite(options.springLength)) throw new Error('Spring length is not a number');\n\n return {\n /**\n * Updates forces acting on a spring\n */\n update: function (spring) {\n var body1 = spring.from;\n var body2 = spring.to;\n var length = spring.length < 0 ? options.springLength : spring.length;\n ${n("var d{var} = body2.pos.{var} - body1.pos.{var};",{indent:6})}\n var r = Math.sqrt(${n("d{var} * d{var}",{join:" + "})});\n\n if (r === 0) {\n ${n("d{var} = (random.nextDouble() - 0.5) / 50;",{indent:8})}\n r = Math.sqrt(${n("d{var} * d{var}",{join:" + "})});\n }\n\n var d = r - length;\n var coefficient = ((spring.coefficient > 0) ? spring.coefficient : options.springCoefficient) * d / r;\n\n ${n("body1.force.{var} += coefficient * d{var}",{indent:6})};\n body1.springCount += 1;\n body1.springLength += r;\n\n ${n("body2.force.{var} -= coefficient * d{var}",{indent:6})};\n body2.springCount += 1;\n body2.springLength += r;\n }\n };\n`}return eu.exports=function(t){let n=e(t);return new Function("options","random",n)},eu.exports.generateCreateSpringForceFunctionBody=e,eu.exports}(),s=function(){if(nu)return ou.exports;nu=1;const t=Xh();function e(e){let n=t(e);return`\n var length = bodies.length;\n if (length === 0) return 0;\n\n ${n("var d{var} = 0, t{var} = 0;",{indent:2})}\n\n for (var i = 0; i < length; ++i) {\n var body = bodies[i];\n if (body.isPinned) continue;\n\n if (adaptiveTimeStepWeight && body.springCount) {\n timeStep = (adaptiveTimeStepWeight * body.springLength/body.springCount);\n }\n\n var coeff = timeStep / body.mass;\n\n ${n("body.velocity.{var} += coeff * body.force.{var};",{indent:4})}\n ${n("var v{var} = body.velocity.{var};",{indent:4})}\n var v = Math.sqrt(${n("v{var} * v{var}",{join:" + "})});\n\n if (v > 1) {\n // We normalize it so that we move within timeStep range. \n // for the case when v <= 1 - we let velocity to fade out.\n ${n("body.velocity.{var} = v{var} / v;",{indent:6})}\n }\n\n ${n("d{var} = timeStep * body.velocity.{var};",{indent:4})}\n\n ${n("body.pos.{var} += d{var};",{indent:4})}\n\n ${n("t{var} += Math.abs(d{var});",{indent:4})}\n }\n\n return (${n("t{var} * t{var}",{join:" + "})})/length;\n`}return ou.exports=function(t){let n=e(t);return new Function("bodies","timeStep","adaptiveTimeStepWeight",n)},ou.exports.generateIntegratorFunctionBody=e,ou.exports}(),a={};function o(t,e,n){if(t.hasOwnProperty(n)&&"function"!=typeof e[n]){var i=Number.isFinite(t[n]);e[n]=i?function(i){if(void 0!==i){if(!Number.isFinite(i))throw new Error("Value of "+n+" should be a valid number.");return t[n]=i,e}return t[n]}:function(i){return void 0!==i?(t[n]=i,e):t[n]}}}return hu}var fu=function(){if(cu)return jh.exports;cu=1,jh.exports=function(n,i){if(!n)throw new Error("Graph structure cannot be undefined");var r=(i&&i.createSimulator||pu())(i);if(Array.isArray(i))throw new Error("Physics settings is expected to be an object");var s=n.version>19?function(t){var e=n.getLinks(t);return e?1+e.size/3:1}:function(t){var e=n.getLinks(t);return e?1+e.length/3:1};i&&"function"==typeof i.nodeMass&&(s=i.nodeMass);var a=new Map,o={},l=0,h=r.settings.springTransform||e;l=0,n.forEachNode((function(t){m(t.id),l+=1})),n.forEachLink(_),n.on("changed",f);var u=!1,c={step:function(){if(0===l)return d(!0),!0;var t=r.step();c.lastMove=t,c.fire("step");var e=t/l<=.01;return d(e),e},getNodePosition:function(t){return x(t).pos},setNodePosition:function(t){var e=x(t);e.setPosition.apply(e,Array.prototype.slice.call(arguments,1))},getLinkPosition:function(t){var e=o[t];if(e)return{from:e.from.pos,to:e.to.pos}},getGraphRect:function(){return r.getBBox()},forEachBody:p,pinNode:function(t,e){x(t.id).isPinned=!!e},isNodePinned:function(t){return x(t.id).isPinned},dispose:function(){n.off("changed",f),c.fire("disposed")},getBody:function(t){return a.get(t)},getSpring:function(t,e){var i;if(void 0===e)i="object"!=typeof t?t:t.id;else{var r=n.hasLink(t,e);if(!r)return;i=r.id}return o[i]},getForceVectorLength:function(){var t=0,e=0;return p((function(n){t+=Math.abs(n.force.x),e+=Math.abs(n.force.y)})),Math.sqrt(t*t+e*e)},simulator:r,graph:n,lastMove:0};return t(c),c;function d(t){var e;u!==t&&(u=t,e=t,c.fire("stable",e))}function p(t){a.forEach(t)}function f(t){for(var e=0;e<t.length;++e){var i=t[e];"add"===i.changeType?(i.node&&m(i.node.id),i.link&&_(i.link)):"remove"===i.changeType&&(i.node&&g(i.node),i.link&&v(i.link))}l=n.getNodesCount()}function m(t){var e=a.get(t);if(!e){var i=n.getNode(t);if(!i)throw new Error("initBody() was called with unknown node id");var s=i.position;if(!s){var o=function(t){var e=[];if(!t.links)return e;for(var n=Math.min(t.links.length,2),i=0;i<n;++i){var r=t.links[i],s=r.fromId!==t.id?a.get(r.fromId):a.get(r.toId);s&&s.pos&&e.push(s)}return e}(i);s=r.getBestNewBodyPosition(o)}(e=r.addBodyAt(s)).id=t,a.set(t,e),y(t),function(t){return t&&(t.isPinned||t.data&&t.data.isPinned)}(i)&&(e.isPinned=!0)}}function g(t){var e=t.id,n=a.get(e);n&&(a.delete(e),r.removeBody(n))}function _(t){y(t.fromId),y(t.toId);var e=a.get(t.fromId),n=a.get(t.toId),i=r.addSpring(e,n,t.length);h(t,i),o[t.id]=i}function v(t){var e=o[t.id];if(e){var i=n.getNode(t.fromId),s=n.getNode(t.toId);i&&y(i.id),s&&y(s.id),delete o[t.id],r.removeSpring(e)}}function y(t){var e=a.get(t);if(e.mass=s(t),Number.isNaN(e.mass))throw new Error("Node mass should be a number")}function x(t){var e=a.get(t);return e||(m(t),e=a.get(t)),e}},jh.exports.simulator=pu();var t=Oh();function e(){}return jh.exports}(),mu=Dh(fu);function gu(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var _u="object"==typeof global&&global&&global.Object===Object&&global,vu="object"==typeof self&&self&&self.Object===Object&&self,yu=_u||vu||Function("return this")(),xu=function(){return yu.Date.now()},bu=/\s/;var Su=/^\s+/;function Mu(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&bu.test(t.charAt(e)););return e}(t)+1).replace(Su,""):t}var Tu=yu.Symbol,wu=Object.prototype,Eu=wu.hasOwnProperty,Au=wu.toString,Ru=Tu?Tu.toStringTag:void 0;var Cu=Object.prototype.toString;var Nu=Tu?Tu.toStringTag:void 0;function Pu(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Nu&&Nu in Object(t)?function(t){var e=Eu.call(t,Ru),n=t[Ru];try{t[Ru]=void 0;var i=!0}catch(t){}var r=Au.call(t);return i&&(e?t[Ru]=n:delete t[Ru]),r}(t):function(t){return Cu.call(t)}(t)}var Iu=/^[-+]0x[0-9a-f]+$/i,Lu=/^0b[01]+$/i,Uu=/^0o[0-7]+$/i,Du=parseInt;function Ou(t){if("number"==typeof t)return t;if(function(t){return"symbol"==typeof t||function(t){return null!=t&&"object"==typeof t}(t)&&"[object Symbol]"==Pu(t)}(t))return NaN;if(gu(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=gu(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Mu(t);var n=Lu.test(t);return n||Uu.test(t)?Du(t.slice(2),n?2:8):Iu.test(t)?NaN:+t}var Fu=Math.max,Bu=Math.min;function zu(t,e,n){var i,r,s,a,o,l,h=0,u=!1,c=!1,d=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function p(e){var n=i,s=r;return i=r=void 0,h=e,a=t.apply(s,n)}function f(t){var n=t-l;return void 0===l||n>=e||n<0||c&&t-h>=s}function m(){var t=xu();if(f(t))return g(t);o=setTimeout(m,function(t){var n=e-(t-l);return c?Bu(n,s-(t-h)):n}(t))}function g(t){return o=void 0,d&&i?p(t):(i=r=void 0,a)}function _(){var t=xu(),n=f(t);if(i=arguments,r=this,l=t,n){if(void 0===o)return function(t){return h=t,o=setTimeout(m,e),u?p(t):a}(l);if(c)return clearTimeout(o),o=setTimeout(m,e),p(l)}return void 0===o&&(o=setTimeout(m,e)),a}return e=Ou(e)||0,gu(n)&&(u=!!n.leading,s=(c="maxWait"in n)?Fu(Ou(n.maxWait)||0,e):s,d="trailing"in n?!!n.trailing:d),_.cancel=function(){void 0!==o&&clearTimeout(o),h=0,i=l=r=o=void 0},_.flush=function(){return void 0===o?a:g(xu())},_}function ku(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function Gu(t,e,n){return Object.defineProperty(t,"prototype",{writable:!1}),t}function Vu(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var i,r,s,a,o=[],l=!0,h=!1;try{if(s=(n=n.call(t)).next,0===e);else for(;!(l=(i=s.call(n)).done)&&(o.push(i.value),o.length!==e);l=!0);}catch(t){h=!0,r=t}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(h)throw r}}return o}}(t,e)||function(t,e){if(t){if("string"==typeof t)return ku(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ku(t,e):void 0}}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var Hu=Gu((function t(e,n){var i=n.default,r=void 0===i?null:i,s=n.triggerUpdate,a=void 0===s||s,o=n.onChange,l=void 0===o?function(t,e){}:o;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.name=e,this.defaultVal=r,this.triggerUpdate=a,this.onChange=l}));function ju(t){var e=t.stateInit,n=void 0===e?function(){return{}}:e,i=t.props,r=void 0===i?{}:i,s=t.methods,a=void 0===s?{}:s,o=t.aliases,l=void 0===o?{}:o,h=t.init,u=void 0===h?function(){}:h,c=t.update,d=void 0===c?function(){}:c,p=Object.keys(r).map((function(t){return new Hu(t,r[t])}));return function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=Object.assign({},n instanceof Function?n(t):n,{initialised:!1}),i={};function r(e){return s(e,t),o(),r}var s=function(t,n){u.call(r,t,e,n),e.initialised=!0},o=zu((function(){e.initialised&&(d.call(r,e,i),i={})}),1);return p.forEach((function(t){r[t.name]=function(t){var n=t.name,s=t.triggerUpdate,a=void 0!==s&&s,l=t.onChange,h=void 0===l?function(t,e){}:l,u=t.defaultVal,c=void 0===u?null:u;return function(t){var s=e[n];if(!arguments.length)return s;var l=void 0===t?c:t;return e[n]=l,h.call(r,l,e,s),!i.hasOwnProperty(n)&&(i[n]=s),a&&o(),r}}(t)})),Object.keys(a).forEach((function(t){r[t]=function(){for(var n,i=arguments.length,s=new Array(i),o=0;o<i;o++)s[o]=arguments[o];return(n=a[t]).call.apply(n,[r,e].concat(s))}})),Object.entries(l).forEach((function(t){var e=Vu(t,2),n=e[0],i=e[1];return r[n]=r[i]})),r.resetProps=function(){return p.forEach((function(t){r[t.name](t.defaultVal)})),r},r.resetProps(),e._rerender=o,r}}var Wu=function(t){return"function"==typeof t?t:"string"==typeof t?function(e){return e[t]}:function(e){return t}};class qu extends Map{constructor(t,e=$u){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:e}}),null!=t)for(const[e,n]of t)this.set(e,n)}get(t){return super.get(Xu(this,t))}has(t){return super.has(Xu(this,t))}set(t,e){return super.set(function({_intern:t,_key:e},n){const i=e(n);return t.has(i)?t.get(i):(t.set(i,n),n)}(this,t),e)}delete(t){return super.delete(function({_intern:t,_key:e},n){const i=e(n);t.has(i)&&(n=t.get(i),t.delete(i));return n}(this,t))}}function Xu({_intern:t,_key:e},n){const i=e(n);return t.has(i)?t.get(i):n}function $u(t){return null!==t&&"object"==typeof t?t.valueOf():t}function Yu(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n<e||void 0===n&&e>=e)&&(n=e);else{let i=-1;for(let r of t)null!=(r=e(r,++i,t))&&(n<r||void 0===n&&r>=r)&&(n=r)}return n}function Ku(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n>e||void 0===n&&e>=e)&&(n=e);else{let i=-1;for(let r of t)null!=(r=e(r,++i,t))&&(n>r||void 0===n&&r>=r)&&(n=r)}return n}function Zu(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function Qu(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var i,r,s,a,o=[],l=!0,h=!1;try{if(s=(n=n.call(t)).next,0===e);else for(;!(l=(i=s.call(n)).done)&&(o.push(i.value),o.length!==e);l=!0);}catch(t){h=!0,r=t}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(h)throw r}}return o}}(t,e)||ec(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function Ju(t){return function(t){if(Array.isArray(t))return Zu(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||ec(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function tc(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e);if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}function ec(t,e){if(t){if("string"==typeof t)return Zu(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Zu(t,e):void 0}}var nc=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],r=(e instanceof Array?e.length?e:[void 0]:[e]).map((function(t){return{keyAccessor:t,isProp:!(t instanceof Function)}})),s=t.reduce((function(t,e){var i=t,s=e;return r.forEach((function(t,e){var a,o=t.keyAccessor;if(t.isProp){var l=s,h=l[o],u=function(t,e){if(null==t)return{};var n,i,r=function(t,e){if(null==t)return{};var n={};for(var i in t)if({}.hasOwnProperty.call(t,i)){if(e.includes(i))continue;n[i]=t[i]}return n}(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(i=0;i<s.length;i++)n=s[i],e.includes(n)||{}.propertyIsEnumerable.call(t,n)&&(r[n]=t[n])}return r}(l,[o].map(tc));a=h,s=u}else a=o(s,e);e+1<r.length?(i.hasOwnProperty(a)||(i[a]={}),i=i[a]):n?(i.hasOwnProperty(a)||(i[a]=[]),i[a].push(s)):i[a]=s})),t}),{});n instanceof Function&&function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;i===r.length?Object.keys(e).forEach((function(t){return e[t]=n(e[t])})):Object.values(e).forEach((function(e){return t(e,i+1)}))}(s);var a=s;return i&&(a=[],function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];n.length===r.length?a.push({keys:n,vals:e}):Object.entries(e).forEach((function(e){var i=Qu(e,2),r=i[0],s=i[1];return t(s,[].concat(Ju(n),[r]))}))}(s),e instanceof Array&&0===e.length&&1===a.length&&(a[0].keys=[])),a};function ic(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function rc(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function sc(t,e){if(null==t)return{};var n,i,r=function(t,e){if(null==t)return{};var n,i,r={},s=Object.keys(t);for(i=0;i<s.length;i++)n=s[i],e.indexOf(n)>=0||(r[n]=t[n]);return r}(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(i=0;i<s.length;i++)n=s[i],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(r[n]=t[n])}return r}function ac(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var i,r,s,a,o=[],l=!0,h=!1;try{if(s=(n=n.call(t)).next,0===e);else for(;!(l=(i=s.call(n)).done)&&(o.push(i.value),o.length!==e);l=!0);}catch(t){h=!0,r=t}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(h)throw r}}return o}}(t,e)||lc(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function oc(t){return function(t){if(Array.isArray(t))return hc(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||lc(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function lc(t,e){if(t){if("string"==typeof t)return hc(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?hc(t,e):void 0}}function hc(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}var uc=["createObj","updateObj","exitObj","objBindAttr","dataBindAttr"];function cc(t,e,n){var i=n.objBindAttr,r=void 0===i?"__obj":i,s=n.dataBindAttr,a=void 0===s?"__data":s,o=n.idAccessor,l=n.purge,h=void 0!==l&&l,u=function(t){return t.hasOwnProperty(a)},c=e.filter((function(t){return!u(t)})),d=e.filter(u).map((function(t){return t[a]})),p=h?{enter:t,exit:d,update:[]}:function(t,e,n){var i={enter:[],update:[],exit:[]};if(n){var r=nc(t,n,!1),s=nc(e,n,!1),a=Object.assign({},r,s);Object.entries(a).forEach((function(t){var e=ac(t,2),n=e[0],a=e[1],o=r.hasOwnProperty(n)?s.hasOwnProperty(n)?"update":"exit":"enter";i[o].push("update"===o?[r[n],s[n]]:a)}))}else{var o=new Set(t),l=new Set(e);new Set([].concat(oc(o),oc(l))).forEach((function(t){var e=o.has(t)?l.has(t)?"update":"exit":"enter";i[e].push("update"===e?[t,t]:t)}))}return i}(d,t,o);return p.update=p.update.map((function(t){var e=ac(t,2),n=e[0],i=e[1];return n!==i&&(i[r]=n[r],i[r][a]=i),i})),p.exit=p.exit.concat(c.map((function(t){return rc({},r,t)}))),p}function dc(t,e,n,i,r){var s=r.createObj,a=void 0===s?function(t){return{}}:s,o=r.updateObj,l=void 0===o?function(t,e){}:o,h=r.exitObj,u=void 0===h?function(t){}:h,c=r.objBindAttr,d=void 0===c?"__obj":c,p=r.dataBindAttr,f=void 0===p?"__data":p,m=sc(r,uc),g=cc(t,e,function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ic(Object(n),!0).forEach((function(e){rc(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ic(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}({objBindAttr:d,dataBindAttr:f},m)),_=g.enter,v=g.update;g.exit.forEach((function(t){var e=t[d];delete t[d],u(e),i(e)}));var y=function(t){var e=[];return t.forEach((function(t){var n=a(t);n&&(n[f]=t,t[d]=n,e.push(n))})),e}(_);!function(t){t.forEach((function(t){var e=t[d];e&&(e[f]=t,l(e,t))}))}([].concat(oc(_),oc(v))),y.forEach(n)}function pc(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}const fc=Symbol("implicit");var mc=function(t){for(var e=t.length/6|0,n=new Array(e),i=0;i<e;)n[i]="#"+t.slice(6*i,6*++i);return n}("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928");function gc(t){return gc="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},gc(t)}var _c=/^\s+/,vc=/\s+$/;function yc(t,e){if(e=e||{},(t=t||"")instanceof yc)return t;if(!(this instanceof yc))return new yc(t,e);var n=function(t){var e={r:0,g:0,b:0},n=1,i=null,r=null,s=null,a=!1,o=!1;"string"==typeof t&&(t=function(t){t=t.replace(_c,"").replace(vc,"").toLowerCase();var e,n=!1;if(Oc[t])t=Oc[t],n=!0;else if("transparent"==t)return{r:0,g:0,b:0,a:0,format:"name"};if(e=Yc.rgb.exec(t))return{r:e[1],g:e[2],b:e[3]};if(e=Yc.rgba.exec(t))return{r:e[1],g:e[2],b:e[3],a:e[4]};if(e=Yc.hsl.exec(t))return{h:e[1],s:e[2],l:e[3]};if(e=Yc.hsla.exec(t))return{h:e[1],s:e[2],l:e[3],a:e[4]};if(e=Yc.hsv.exec(t))return{h:e[1],s:e[2],v:e[3]};if(e=Yc.hsva.exec(t))return{h:e[1],s:e[2],v:e[3],a:e[4]};if(e=Yc.hex8.exec(t))return{r:Gc(e[1]),g:Gc(e[2]),b:Gc(e[3]),a:Wc(e[4]),format:n?"name":"hex8"};if(e=Yc.hex6.exec(t))return{r:Gc(e[1]),g:Gc(e[2]),b:Gc(e[3]),format:n?"name":"hex"};if(e=Yc.hex4.exec(t))return{r:Gc(e[1]+""+e[1]),g:Gc(e[2]+""+e[2]),b:Gc(e[3]+""+e[3]),a:Wc(e[4]+""+e[4]),format:n?"name":"hex8"};if(e=Yc.hex3.exec(t))return{r:Gc(e[1]+""+e[1]),g:Gc(e[2]+""+e[2]),b:Gc(e[3]+""+e[3]),format:n?"name":"hex"};return!1}(t));"object"==gc(t)&&(Kc(t.r)&&Kc(t.g)&&Kc(t.b)?(l=t.r,h=t.g,u=t.b,e={r:255*zc(l,255),g:255*zc(h,255),b:255*zc(u,255)},a=!0,o="%"===String(t.r).substr(-1)?"prgb":"rgb"):Kc(t.h)&&Kc(t.s)&&Kc(t.v)?(i=Hc(t.s),r=Hc(t.v),e=function(t,e,n){t=6*zc(t,360),e=zc(e,100),n=zc(n,100);var i=Math.floor(t),r=t-i,s=n*(1-e),a=n*(1-r*e),o=n*(1-(1-r)*e),l=i%6,h=[n,a,s,s,o,n][l],u=[o,n,n,a,s,s][l],c=[s,s,o,n,n,a][l];return{r:255*h,g:255*u,b:255*c}}(t.h,i,r),a=!0,o="hsv"):Kc(t.h)&&Kc(t.s)&&Kc(t.l)&&(i=Hc(t.s),s=Hc(t.l),e=function(t,e,n){var i,r,s;function a(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+(e-t)*(2/3-n)*6:t}if(t=zc(t,360),e=zc(e,100),n=zc(n,100),0===e)i=r=s=n;else{var o=n<.5?n*(1+e):n+e-n*e,l=2*n-o;i=a(l,o,t+1/3),r=a(l,o,t),s=a(l,o,t-1/3)}return{r:255*i,g:255*r,b:255*s}}(t.h,i,s),a=!0,o="hsl"),t.hasOwnProperty("a")&&(n=t.a));var l,h,u;return n=Bc(n),{ok:a,format:t.format||o,r:Math.min(255,Math.max(e.r,0)),g:Math.min(255,Math.max(e.g,0)),b:Math.min(255,Math.max(e.b,0)),a:n}}(t);this._originalInput=t,this._r=n.r,this._g=n.g,this._b=n.b,this._a=n.a,this._roundA=Math.round(100*this._a)/100,this._format=e.format||n.format,this._gradientType=e.gradientType,this._r<1&&(this._r=Math.round(this._r)),this._g<1&&(this._g=Math.round(this._g)),this._b<1&&(this._b=Math.round(this._b)),this._ok=n.ok}function xc(t,e,n){t=zc(t,255),e=zc(e,255),n=zc(n,255);var i,r,s=Math.max(t,e,n),a=Math.min(t,e,n),o=(s+a)/2;if(s==a)i=r=0;else{var l=s-a;switch(r=o>.5?l/(2-s-a):l/(s+a),s){case t:i=(e-n)/l+(e<n?6:0);break;case e:i=(n-t)/l+2;break;case n:i=(t-e)/l+4}i/=6}return{h:i,s:r,l:o}}function bc(t,e,n){t=zc(t,255),e=zc(e,255),n=zc(n,255);var i,r,s=Math.max(t,e,n),a=Math.min(t,e,n),o=s,l=s-a;if(r=0===s?0:l/s,s==a)i=0;else{switch(s){case t:i=(e-n)/l+(e<n?6:0);break;case e:i=(n-t)/l+2;break;case n:i=(t-e)/l+4}i/=6}return{h:i,s:r,v:o}}function Sc(t,e,n,i){var r=[Vc(Math.round(t).toString(16)),Vc(Math.round(e).toString(16)),Vc(Math.round(n).toString(16))];return i&&r[0].charAt(0)==r[0].charAt(1)&&r[1].charAt(0)==r[1].charAt(1)&&r[2].charAt(0)==r[2].charAt(1)?r[0].charAt(0)+r[1].charAt(0)+r[2].charAt(0):r.join("")}function Mc(t,e,n,i){return[Vc(jc(i)),Vc(Math.round(t).toString(16)),Vc(Math.round(e).toString(16)),Vc(Math.round(n).toString(16))].join("")}function Tc(t,e){e=0===e?0:e||10;var n=yc(t).toHsl();return n.s-=e/100,n.s=kc(n.s),yc(n)}function wc(t,e){e=0===e?0:e||10;var n=yc(t).toHsl();return n.s+=e/100,n.s=kc(n.s),yc(n)}function Ec(t){return yc(t).desaturate(100)}function Ac(t,e){e=0===e?0:e||10;var n=yc(t).toHsl();return n.l+=e/100,n.l=kc(n.l),yc(n)}function Rc(t,e){e=0===e?0:e||10;var n=yc(t).toRgb();return n.r=Math.max(0,Math.min(255,n.r-Math.round(-e/100*255))),n.g=Math.max(0,Math.min(255,n.g-Math.round(-e/100*255))),n.b=Math.max(0,Math.min(255,n.b-Math.round(-e/100*255))),yc(n)}function Cc(t,e){e=0===e?0:e||10;var n=yc(t).toHsl();return n.l-=e/100,n.l=kc(n.l),yc(n)}function Nc(t,e){var n=yc(t).toHsl(),i=(n.h+e)%360;return n.h=i<0?360+i:i,yc(n)}function Pc(t){var e=yc(t).toHsl();return e.h=(e.h+180)%360,yc(e)}function Ic(t,e){if(isNaN(e)||e<=0)throw new Error("Argument to polyad must be a positive number");for(var n=yc(t).toHsl(),i=[yc(t)],r=360/e,s=1;s<e;s++)i.push(yc({h:(n.h+s*r)%360,s:n.s,l:n.l}));return i}function Lc(t){var e=yc(t).toHsl(),n=e.h;return[yc(t),yc({h:(n+72)%360,s:e.s,l:e.l}),yc({h:(n+216)%360,s:e.s,l:e.l})]}function Uc(t,e,n){e=e||6,n=n||30;var i=yc(t).toHsl(),r=360/n,s=[yc(t)];for(i.h=(i.h-(r*e>>1)+720)%360;--e;)i.h=(i.h+r)%360,s.push(yc(i));return s}function Dc(t,e){e=e||6;for(var n=yc(t).toHsv(),i=n.h,r=n.s,s=n.v,a=[],o=1/e;e--;)a.push(yc({h:i,s:r,v:s})),s=(s+o)%1;return a}yc.prototype={isDark:function(){return this.getBrightness()<128},isLight:function(){return!this.isDark()},isValid:function(){return this._ok},getOriginalInput:function(){return this._originalInput},getFormat:function(){return this._format},getAlpha:function(){return this._a},getBrightness:function(){var t=this.toRgb();return(299*t.r+587*t.g+114*t.b)/1e3},getLuminance:function(){var t,e,n,i=this.toRgb();return t=i.r/255,e=i.g/255,n=i.b/255,.2126*(t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4))+.7152*(e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4))+.0722*(n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4))},setAlpha:function(t){return this._a=Bc(t),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var t=bc(this._r,this._g,this._b);return{h:360*t.h,s:t.s,v:t.v,a:this._a}},toHsvString:function(){var t=bc(this._r,this._g,this._b),e=Math.round(360*t.h),n=Math.round(100*t.s),i=Math.round(100*t.v);return 1==this._a?"hsv("+e+", "+n+"%, "+i+"%)":"hsva("+e+", "+n+"%, "+i+"%, "+this._roundA+")"},toHsl:function(){var t=xc(this._r,this._g,this._b);return{h:360*t.h,s:t.s,l:t.l,a:this._a}},toHslString:function(){var t=xc(this._r,this._g,this._b),e=Math.round(360*t.h),n=Math.round(100*t.s),i=Math.round(100*t.l);return 1==this._a?"hsl("+e+", "+n+"%, "+i+"%)":"hsla("+e+", "+n+"%, "+i+"%, "+this._roundA+")"},toHex:function(t){return Sc(this._r,this._g,this._b,t)},toHexString:function(t){return"#"+this.toHex(t)},toHex8:function(t){return function(t,e,n,i,r){var s=[Vc(Math.round(t).toString(16)),Vc(Math.round(e).toString(16)),Vc(Math.round(n).toString(16)),Vc(jc(i))];if(r&&s[0].charAt(0)==s[0].charAt(1)&&s[1].charAt(0)==s[1].charAt(1)&&s[2].charAt(0)==s[2].charAt(1)&&s[3].charAt(0)==s[3].charAt(1))return s[0].charAt(0)+s[1].charAt(0)+s[2].charAt(0)+s[3].charAt(0);return s.join("")}(this._r,this._g,this._b,this._a,t)},toHex8String:function(t){return"#"+this.toHex8(t)},toRgb:function(){return{r:Math.round(this._r),g:Math.round(this._g),b:Math.round(this._b),a:this._a}},toRgbString:function(){return 1==this._a?"rgb("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+")":"rgba("+Math.round(this._r)+", "+Math.round(this._g)+", "+Math.round(this._b)+", "+this._roundA+")"},toPercentageRgb:function(){return{r:Math.round(100*zc(this._r,255))+"%",g:Math.round(100*zc(this._g,255))+"%",b:Math.round(100*zc(this._b,255))+"%",a:this._a}},toPercentageRgbString:function(){return 1==this._a?"rgb("+Math.round(100*zc(this._r,255))+"%, "+Math.round(100*zc(this._g,255))+"%, "+Math.round(100*zc(this._b,255))+"%)":"rgba("+Math.round(100*zc(this._r,255))+"%, "+Math.round(100*zc(this._g,255))+"%, "+Math.round(100*zc(this._b,255))+"%, "+this._roundA+")"},toName:function(){return 0===this._a?"transparent":!(this._a<1)&&(Fc[Sc(this._r,this._g,this._b,!0)]||!1)},toFilter:function(t){var e="#"+Mc(this._r,this._g,this._b,this._a),n=e,i=this._gradientType?"GradientType = 1, ":"";if(t){var r=yc(t);n="#"+Mc(r._r,r._g,r._b,r._a)}return"progid:DXImageTransform.Microsoft.gradient("+i+"startColorstr="+e+",endColorstr="+n+")"},toString:function(t){var e=!!t;t=t||this._format;var n=!1,i=this._a<1&&this._a>=0;return e||!i||"hex"!==t&&"hex6"!==t&&"hex3"!==t&&"hex4"!==t&&"hex8"!==t&&"name"!==t?("rgb"===t&&(n=this.toRgbString()),"prgb"===t&&(n=this.toPercentageRgbString()),"hex"!==t&&"hex6"!==t||(n=this.toHexString()),"hex3"===t&&(n=this.toHexString(!0)),"hex4"===t&&(n=this.toHex8String(!0)),"hex8"===t&&(n=this.toHex8String()),"name"===t&&(n=this.toName()),"hsl"===t&&(n=this.toHslString()),"hsv"===t&&(n=this.toHsvString()),n||this.toHexString()):"name"===t&&0===this._a?this.toName():this.toRgbString()},clone:function(){return yc(this.toString())},_applyModification:function(t,e){var n=t.apply(null,[this].concat([].slice.call(e)));return this._r=n._r,this._g=n._g,this._b=n._b,this.setAlpha(n._a),this},lighten:function(){return this._applyModification(Ac,arguments)},brighten:function(){return this._applyModification(Rc,arguments)},darken:function(){return this._applyModification(Cc,arguments)},desaturate:function(){return this._applyModification(Tc,arguments)},saturate:function(){return this._applyModification(wc,arguments)},greyscale:function(){return this._applyModification(Ec,arguments)},spin:function(){return this._applyModification(Nc,arguments)},_applyCombination:function(t,e){return t.apply(null,[this].concat([].slice.call(e)))},analogous:function(){return this._applyCombination(Uc,arguments)},complement:function(){return this._applyCombination(Pc,arguments)},monochromatic:function(){return this._applyCombination(Dc,arguments)},splitcomplement:function(){return this._applyCombination(Lc,arguments)},triad:function(){return this._applyCombination(Ic,[3])},tetrad:function(){return this._applyCombination(Ic,[4])}},yc.fromRatio=function(t,e){if("object"==gc(t)){var n={};for(var i in t)t.hasOwnProperty(i)&&(n[i]="a"===i?t[i]:Hc(t[i]));t=n}return yc(t,e)},yc.equals=function(t,e){return!(!t||!e)&&yc(t).toRgbString()==yc(e).toRgbString()},yc.random=function(){return yc.fromRatio({r:Math.random(),g:Math.random(),b:Math.random()})},yc.mix=function(t,e,n){n=0===n?0:n||50;var i=yc(t).toRgb(),r=yc(e).toRgb(),s=n/100;return yc({r:(r.r-i.r)*s+i.r,g:(r.g-i.g)*s+i.g,b:(r.b-i.b)*s+i.b,a:(r.a-i.a)*s+i.a})},
|
|
// <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
|
|
// Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
|
|
yc.readability=function(t,e){var n=yc(t),i=yc(e);return(Math.max(n.getLuminance(),i.getLuminance())+.05)/(Math.min(n.getLuminance(),i.getLuminance())+.05)},yc.isReadable=function(t,e,n){var i,r,s=yc.readability(t,e);switch(r=!1,(i=function(t){var e,n;e=((t=t||{level:"AA",size:"small"}).level||"AA").toUpperCase(),n=(t.size||"small").toLowerCase(),"AA"!==e&&"AAA"!==e&&(e="AA");"small"!==n&&"large"!==n&&(n="small");return{level:e,size:n}}(n)).level+i.size){case"AAsmall":case"AAAlarge":r=s>=4.5;break;case"AAlarge":r=s>=3;break;case"AAAsmall":r=s>=7}return r},yc.mostReadable=function(t,e,n){var i,r,s,a,o=null,l=0;r=(n=n||{}).includeFallbackColors,s=n.level,a=n.size;for(var h=0;h<e.length;h++)(i=yc.readability(t,e[h]))>l&&(l=i,o=yc(e[h]));return yc.isReadable(t,o,{level:s,size:a})||!r?o:(n.includeFallbackColors=!1,yc.mostReadable(t,["#fff","#000"],n))};var Oc=yc.names={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"663399",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},Fc=yc.hexNames=function(t){var e={};for(var n in t)t.hasOwnProperty(n)&&(e[t[n]]=n);return e}(Oc);function Bc(t){return t=parseFloat(t),(isNaN(t)||t<0||t>1)&&(t=1),t}function zc(t,e){(function(t){return"string"==typeof t&&-1!=t.indexOf(".")&&1===parseFloat(t)})(t)&&(t="100%");var n=function(t){return"string"==typeof t&&-1!=t.indexOf("%")}(t);return t=Math.min(e,Math.max(0,parseFloat(t))),n&&(t=parseInt(t*e,10)/100),Math.abs(t-e)<1e-6?1:t%e/parseFloat(e)}function kc(t){return Math.min(1,Math.max(0,t))}function Gc(t){return parseInt(t,16)}function Vc(t){return 1==t.length?"0"+t:""+t}function Hc(t){return t<=1&&(t=100*t+"%"),t}function jc(t){return Math.round(255*parseFloat(t)).toString(16)}function Wc(t){return Gc(t)/255}var qc,Xc,$c,Yc=(Xc="[\\s|\\(]+("+(qc="(?:[-\\+]?\\d*\\.\\d+%?)|(?:[-\\+]?\\d+%?)")+")[,|\\s]+("+qc+")[,|\\s]+("+qc+")\\s*\\)?",$c="[\\s|\\(]+("+qc+")[,|\\s]+("+qc+")[,|\\s]+("+qc+")[,|\\s]+("+qc+")\\s*\\)?",{CSS_UNIT:new RegExp(qc),rgb:new RegExp("rgb"+Xc),rgba:new RegExp("rgba"+$c),hsl:new RegExp("hsl"+Xc),hsla:new RegExp("hsla"+$c),hsv:new RegExp("hsv"+Xc),hsva:new RegExp("hsva"+$c),hex3:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex6:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,hex4:/^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,hex8:/^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/});function Kc(t){return!!Yc.CSS_UNIT.exec(t)}function Zc(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function Qc(t,e,n){return e=td(e),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,ed()?Reflect.construct(e,n||[],td(t).constructor):e.apply(t,n))}function Jc(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function td(t){return td=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},td(t)}function ed(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(ed=function(){return!!t})()}function nd(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function id(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?nd(Object(n),!0).forEach((function(e){Jc(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):nd(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function rd(t,e){return rd=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},rd(t,e)}function sd(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var i,r,s,a,o=[],l=!0,h=!1;try{if(s=(n=n.call(t)).next,0===e);else for(;!(l=(i=s.call(n)).done)&&(o.push(i.value),o.length!==e);l=!0);}catch(t){h=!0,r=t}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(h)throw r}}return o}}(t,e)||ld(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function ad(t){return function(t){if(Array.isArray(t))return Zc(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||ld(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function od(t){return od="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},od(t)}function ld(t,e){if(t){if("string"==typeof t)return Zc(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Zc(t,e):void 0}}var hd=function(t){t instanceof Array?t.forEach(hd):(t.map&&t.map.dispose(),t.dispose())},ud=function(t){t.geometry&&t.geometry.dispose(),t.material&&hd(t.material),t.texture&&t.texture.dispose(),t.children&&t.children.forEach(ud)},cd=function(t){for(;t.children.length;){var e=t.children[0];t.remove(e),ud(e)}},dd=["objFilter"];function pd(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=n.objFilter,r=void 0===i?function(){return!0}:i,s=function(t,e){if(null==t)return{};var n,i,r=function(t,e){if(null==t)return{};var n={};for(var i in t)if({}.hasOwnProperty.call(t,i)){if(e.includes(i))continue;n[i]=t[i]}return n}(t,e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(t);for(i=0;i<s.length;i++)n=s[i],e.includes(n)||{}.propertyIsEnumerable.call(t,n)&&(r[n]=t[n])}return r}(n,dd);return dc(t,e.children.filter(r),(function(t){return e.add(t)}),(function(t){e.remove(t),cd(t)}),id({objBindAttr:"__threeObj"},s))}var fd=function(t){return isNaN(t)?parseInt(yc(t).toHex(),16):t},md=function(t){return isNaN(t)?yc(t).getAlpha():1},gd=function t(){var e=new qu,n=[],i=[],r=fc;function s(t){let s=e.get(t);if(void 0===s){if(r!==fc)return r;e.set(t,s=n.push(t)-1)}return i[s%i.length]}return s.domain=function(t){if(!arguments.length)return n.slice();n=[],e=new qu;for(const i of t)e.has(i)||e.set(i,n.push(i)-1);return s},s.range=function(t){return arguments.length?(i=Array.from(t),s):i.slice()},s.unknown=function(t){return arguments.length?(r=t,s):r},s.copy=function(){return t(n,i).unknown(r)},pc.apply(s,arguments),s}(mc);function _d(t,e,n){e&&"string"==typeof n&&t.filter((function(t){return!t[n]})).forEach((function(t){t[n]=gd(e(t))}))}var vd=window.THREE?window.THREE:{Group:no,Mesh:Ki,MeshLambertMaterial:class extends Mi{static get type(){return"MeshLambertMaterial"}constructor(t){super(),this.isMeshLambertMaterial=!0,this.color=new xi(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new xi(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new Se(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Bn,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}},Color:xi,BufferGeometry:Bi,BufferAttribute:Ai,Matrix4:Rn,Vector3:Ze,SphereGeometry:Oo,CylinderGeometry:Uo,TubeGeometry:Fo,ConeGeometry:Do,Line:class extends ei{constructor(t=new Bi,e=new co){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,n=[0];for(let t=1,i=e.count;t<i;t++)po.fromBufferAttribute(e,t-1),fo.fromBufferAttribute(e,t),n[t]=n[t-1],n[t]+=po.distanceTo(fo);t.setAttribute("lineDistance",new Ni(n,1))}else console.warn("THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.");return this}raycast(t,e){const n=this.geometry,i=this.matrixWorld,r=t.params.Line.threshold,s=n.drawRange;if(null===n.boundingSphere&&n.computeBoundingSphere(),_o.copy(n.boundingSphere),_o.applyMatrix4(i),_o.radius+=r,!1===t.ray.intersectsSphere(_o))return;mo.copy(i).invert(),go.copy(t.ray).applyMatrix4(mo);const a=r/((this.scale.x+this.scale.y+this.scale.z)/3),o=a*a,l=this.isLineSegments?2:1,h=n.index,u=n.attributes.position;if(null!==h){const n=Math.max(0,s.start),i=Math.min(h.count,s.start+s.count);for(let r=n,s=i-1;r<s;r+=l){const n=h.getX(r),i=h.getX(r+1),s=xo(this,t,go,o,n,i);s&&e.push(s)}if(this.isLineLoop){const r=h.getX(i-1),s=h.getX(n),a=xo(this,t,go,o,r,s);a&&e.push(a)}}else{const n=Math.max(0,s.start),i=Math.min(u.count,s.start+s.count);for(let r=n,s=i-1;r<s;r+=l){const n=xo(this,t,go,o,r,r+1);n&&e.push(n)}if(this.isLineLoop){const r=xo(this,t,go,o,i-1,n);r&&e.push(r)}}}updateMorphTargets(){const t=this.geometry.morphAttributes,e=Object.keys(t);if(e.length>0){const n=t[e[0]];if(void 0!==n){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=n.length;t<e;t++){const e=n[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}},LineBasicMaterial:co,QuadraticBezierCurve3:Io,CubicBezierCurve3:Po,Box3:tn},yd={graph:Hh,forcelayout:mu},xd=(new vd.BufferGeometry).setAttribute?"setAttribute":"addAttribute",bd=(new vd.BufferGeometry).applyMatrix4?"applyMatrix4":"applyMatrix",Sd=ju({props:{jsonUrl:{onChange:function(t,e){var n=this;t&&!e.fetchingJson&&(e.fetchingJson=!0,e.onLoading(),fetch(t).then((function(t){return t.json()})).then((function(t){e.fetchingJson=!1,e.onFinishLoading(t),n.graphData(t)})))},triggerUpdate:!1},graphData:{default:{nodes:[],links:[]},onChange:function(t,e){e.engineRunning=!1}},numDimensions:{default:3,onChange:function(t,e){var n=e.d3ForceLayout.force("charge");function i(t,e){t.forEach((function(t){delete t[e],delete t["v".concat(e)]}))}n&&n.strength(t>2?-60:-30),t<3&&i(e.graphData.nodes,"z"),t<2&&i(e.graphData.nodes,"y")}},dagMode:{onChange:function(t,e){!t&&"d3"===e.forceEngine&&(e.graphData.nodes||[]).forEach((function(t){return t.fx=t.fy=t.fz=void 0}))}},dagLevelDistance:{},dagNodeFilter:{default:function(t){return!0}},onDagError:{triggerUpdate:!1},nodeRelSize:{default:4},nodeId:{default:"id"},nodeVal:{default:"val"},nodeResolution:{default:8},nodeColor:{default:"color"},nodeAutoColorBy:{},nodeOpacity:{default:.75},nodeVisibility:{default:!0},nodeThreeObject:{},nodeThreeObjectExtend:{default:!1},nodePositionUpdate:{triggerUpdate:!1},linkSource:{default:"source"},linkTarget:{default:"target"},linkVisibility:{default:!0},linkColor:{default:"color"},linkAutoColorBy:{},linkOpacity:{default:.2},linkWidth:{},linkResolution:{default:6},linkCurvature:{default:0,triggerUpdate:!1},linkCurveRotation:{default:0,triggerUpdate:!1},linkMaterial:{},linkThreeObject:{},linkThreeObjectExtend:{default:!1},linkPositionUpdate:{triggerUpdate:!1},linkDirectionalArrowLength:{default:0},linkDirectionalArrowColor:{},linkDirectionalArrowRelPos:{default:.5,triggerUpdate:!1},linkDirectionalArrowResolution:{default:8},linkDirectionalParticles:{default:0},linkDirectionalParticleSpeed:{default:.01,triggerUpdate:!1},linkDirectionalParticleWidth:{default:.5},linkDirectionalParticleColor:{},linkDirectionalParticleResolution:{default:4},forceEngine:{default:"d3"},d3AlphaMin:{default:0},d3AlphaDecay:{default:.0228,triggerUpdate:!1,onChange:function(t,e){e.d3ForceLayout.alphaDecay(t)}},d3AlphaTarget:{default:0,triggerUpdate:!1,onChange:function(t,e){e.d3ForceLayout.alphaTarget(t)}},d3VelocityDecay:{default:.4,triggerUpdate:!1,onChange:function(t,e){e.d3ForceLayout.velocityDecay(t)}},ngraphPhysics:{default:{timeStep:20,gravity:-1.2,theta:.8,springLength:30,springCoefficient:8e-4,dragCoefficient:.02}},warmupTicks:{default:0,triggerUpdate:!1},cooldownTicks:{default:1/0,triggerUpdate:!1},cooldownTime:{default:15e3,triggerUpdate:!1},onLoading:{default:function(){},triggerUpdate:!1},onFinishLoading:{default:function(){},triggerUpdate:!1},onUpdate:{default:function(){},triggerUpdate:!1},onFinishUpdate:{default:function(){},triggerUpdate:!1},onEngineTick:{default:function(){},triggerUpdate:!1},onEngineStop:{default:function(){},triggerUpdate:!1}},methods:{refresh:function(t){return t._flushObjects=!0,t._rerender(),this},d3Force:function(t,e,n){return void 0===n?t.d3ForceLayout.force(e):(t.d3ForceLayout.force(e,n),this)},d3ReheatSimulation:function(t){return t.d3ForceLayout.alpha(1),this.resetCountdown(),this},resetCountdown:function(t){return t.cntTicks=0,t.startTickTime=new Date,t.engineRunning=!0,this},tickFrame:function(t){var e,n,i,r,s="ngraph"!==t.forceEngine;return t.engineRunning&&function(){++t.cntTicks>t.cooldownTicks||new Date-t.startTickTime>t.cooldownTime||s&&t.d3AlphaMin>0&&t.d3ForceLayout.alpha()<t.d3AlphaMin?(t.engineRunning=!1,t.onEngineStop()):(t.layout[s?"tick":"step"](),t.onEngineTick());var e=Wu(t.nodeThreeObjectExtend);t.graphData.nodes.forEach((function(n){var i=n.__threeObj;if(i){var r=s?n:t.layout.getNodePosition(n[t.nodeId]),a=e(n);t.nodePositionUpdate&&t.nodePositionUpdate(a?i.children[0]:i,{x:r.x,y:r.y,z:r.z},n)&&!a||(i.position.x=r.x,i.position.y=r.y||0,i.position.z=r.z||0)}}));var n=Wu(t.linkWidth),i=Wu(t.linkCurvature),r=Wu(t.linkCurveRotation),a=Wu(t.linkThreeObjectExtend);function o(e){var n=s?e:t.layout.getLinkPosition(t.layout.graph.getLink(e.source,e.target).id),a=n[s?"source":"from"],o=n[s?"target":"to"];if(a&&o&&a.hasOwnProperty("x")&&o.hasOwnProperty("x")){var l=i(e);if(l){var h,u=new vd.Vector3(a.x,a.y||0,a.z||0),c=new vd.Vector3(o.x,o.y||0,o.z||0),d=u.distanceTo(c),p=r(e);if(d>0){var f=o.x-a.x,m=o.y-a.y||0,g=(new vd.Vector3).subVectors(c,u),_=g.clone().multiplyScalar(l).cross(0!==f||0!==m?new vd.Vector3(0,0,1):new vd.Vector3(0,1,0)).applyAxisAngle(g.normalize(),p).add((new vd.Vector3).addVectors(u,c).divideScalar(2));h=new vd.QuadraticBezierCurve3(u,_,c)}else{var v=70*l,y=-p,x=y+Math.PI/2;h=new vd.CubicBezierCurve3(u,new vd.Vector3(v*Math.cos(x),v*Math.sin(x),0).add(u),new vd.Vector3(v*Math.cos(y),v*Math.sin(y),0).add(u),c)}e.__curve=h}else e.__curve=null}}t.graphData.links.forEach((function(e){var i=e.__lineObj;if(i){var r=s?e:t.layout.getLinkPosition(t.layout.graph.getLink(e.source,e.target).id),l=r[s?"source":"from"],h=r[s?"target":"to"];if(l&&h&&l.hasOwnProperty("x")&&h.hasOwnProperty("x")){o(e);var u=a(e);if(!t.linkPositionUpdate||!t.linkPositionUpdate(u?i.children[1]:i,{start:{x:l.x,y:l.y,z:l.z},end:{x:h.x,y:h.y,z:h.z}},e)||u){var c=30,d=e.__curve,p=i.children.length?i.children[0]:i;if("Line"===p.type){if(d)p.geometry.setFromPoints(d.getPoints(c));else{var f=p.geometry.getAttribute("position");f&&f.array&&6===f.array.length||p.geometry[xd]("position",f=new vd.BufferAttribute(new Float32Array(6),3)),f.array[0]=l.x,f.array[1]=l.y||0,f.array[2]=l.z||0,f.array[3]=h.x,f.array[4]=h.y||0,f.array[5]=h.z||0,f.needsUpdate=!0}p.geometry.computeBoundingSphere()}else if("Mesh"===p.type)if(d){p.geometry.type.match(/^Tube(Buffer)?Geometry$/)||(p.position.set(0,0,0),p.rotation.set(0,0,0),p.scale.set(1,1,1));var m=Math.ceil(10*n(e))/10/2,g=new vd.TubeGeometry(d,c,m,t.linkResolution,!1);p.geometry.dispose(),p.geometry=g}else{if(!p.geometry.type.match(/^Cylinder(Buffer)?Geometry$/)){var _=Math.ceil(10*n(e))/10/2,v=new vd.CylinderGeometry(_,_,1,t.linkResolution,1,!1);v[bd]((new vd.Matrix4).makeTranslation(0,.5,0)),v[bd]((new vd.Matrix4).makeRotationX(Math.PI/2)),p.geometry.dispose(),p.geometry=v}var y=new vd.Vector3(l.x,l.y||0,l.z||0),x=new vd.Vector3(h.x,h.y||0,h.z||0),b=y.distanceTo(x);p.position.x=y.x,p.position.y=y.y,p.position.z=y.z,p.scale.z=b,p.parent.localToWorld(x),p.lookAt(x)}}}}}))}(),e=Wu(t.linkDirectionalArrowRelPos),n=Wu(t.linkDirectionalArrowLength),i=Wu(t.nodeVal),t.graphData.links.forEach((function(r){var a=r.__arrowObj;if(a){var o=s?r:t.layout.getLinkPosition(t.layout.graph.getLink(r.source,r.target).id),l=o[s?"source":"from"],h=o[s?"target":"to"];if(l&&h&&l.hasOwnProperty("x")&&h.hasOwnProperty("x")){var u=Math.cbrt(Math.max(0,i(l)||1))*t.nodeRelSize,c=Math.cbrt(Math.max(0,i(h)||1))*t.nodeRelSize,d=n(r),p=e(r),f=r.__curve?function(t){return r.__curve.getPoint(t)}:function(t){var e=function(t,e,n,i){return e[t]+(n[t]-e[t])*i||0};return{x:e("x",l,h,t),y:e("y",l,h,t),z:e("z",l,h,t)}},m=r.__curve?r.__curve.getLength():Math.sqrt(["x","y","z"].map((function(t){return Math.pow((h[t]||0)-(l[t]||0),2)})).reduce((function(t,e){return t+e}),0)),g=u+d+(m-u-c-d)*p,_=f(g/m),v=f((g-d)/m);["x","y","z"].forEach((function(t){return a.position[t]=v[t]}));var y=function(t,e,n){if(ed())return Reflect.construct.apply(null,arguments);var i=[null];return i.push.apply(i,e),new(t.bind.apply(t,i))}(vd.Vector3,ad(["x","y","z"].map((function(t){return _[t]}))));a.parent.localToWorld(y),a.lookAt(y)}}})),r=Wu(t.linkDirectionalParticleSpeed),t.graphData.links.forEach((function(e){var n=e.__photonsObj&&e.__photonsObj.children,i=e.__singleHopPhotonsObj&&e.__singleHopPhotonsObj.children;if(i&&i.length||n&&n.length){var a=s?e:t.layout.getLinkPosition(t.layout.graph.getLink(e.source,e.target).id),o=a[s?"source":"from"],l=a[s?"target":"to"];if(o&&l&&o.hasOwnProperty("x")&&l.hasOwnProperty("x")){var h=r(e),u=e.__curve?function(t){return e.__curve.getPoint(t)}:function(t){var e=function(t,e,n,i){return e[t]+(n[t]-e[t])*i||0};return{x:e("x",o,l,t),y:e("y",o,l,t),z:e("z",o,l,t)}};[].concat(ad(n||[]),ad(i||[])).forEach((function(t,e){var i="singleHopPhotons"===t.parent.__linkThreeObjType;if(t.hasOwnProperty("__progressRatio")||(t.__progressRatio=i?0:e/n.length),t.__progressRatio+=h,t.__progressRatio>=1){if(i)return t.parent.remove(t),void cd(t);t.__progressRatio=t.__progressRatio%1}var r=t.__progressRatio,s=u(r);["x","y","z"].forEach((function(e){return t.position[e]=s[e]}))}))}}})),this},emitParticle:function(t,e){if(e&&t.graphData.links.includes(e)){if(!e.__singleHopPhotonsObj){var n=new vd.Group;n.__linkThreeObjType="singleHopPhotons",e.__singleHopPhotonsObj=n,t.graphScene.add(n)}var i=Wu(t.linkDirectionalParticleWidth),r=Math.ceil(10*i(e))/10/2,s=t.linkDirectionalParticleResolution,a=new vd.SphereGeometry(r,s,s),o=Wu(t.linkColor),l=Wu(t.linkDirectionalParticleColor)(e)||o(e)||"#f0f0f0",h=new vd.Color(fd(l)),u=3*t.linkOpacity,c=new vd.MeshLambertMaterial({color:h,transparent:!0,opacity:u});e.__singleHopPhotonsObj.add(new vd.Mesh(a,c))}return this},getGraphBbox:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){return!0};if(!t.initialised)return null;var n=function t(n){var i=[];if(n.geometry){n.geometry.computeBoundingBox();var r=new vd.Box3;r.copy(n.geometry.boundingBox).applyMatrix4(n.matrixWorld),i.push(r)}return i.concat.apply(i,ad((n.children||[]).filter((function(t){return!t.hasOwnProperty("__graphObjType")||"node"===t.__graphObjType&&e(t.__data)})).map(t)))}(t.graphScene);return n.length?Object.assign.apply(Object,ad(["x","y","z"].map((function(t){return Jc({},t,[Ku(n,(function(e){return e.min[t]})),Yu(n,(function(e){return e.max[t]}))])})))):null}},stateInit:function(){return{d3ForceLayout:Lh().force("link",th()).force("charge",Uh()).force("center",wl()).force("dagRadial",null).stop(),engineRunning:!1}},init:function(t,e){e.graphScene=t},update:function(t,e){var n=function(t){return t.some((function(t){return e.hasOwnProperty(t)}))};if(t.engineRunning=!1,t.onUpdate(),null!==t.nodeAutoColorBy&&n(["nodeAutoColorBy","graphData","nodeColor"])&&_d(t.graphData.nodes,Wu(t.nodeAutoColorBy),t.nodeColor),null!==t.linkAutoColorBy&&n(["linkAutoColorBy","graphData","linkColor"])&&_d(t.graphData.links,Wu(t.linkAutoColorBy),t.linkColor),t._flushObjects||n(["graphData","nodeThreeObject","nodeThreeObjectExtend","nodeVal","nodeColor","nodeVisibility","nodeRelSize","nodeResolution","nodeOpacity"])){var i=Wu(t.nodeThreeObject),r=Wu(t.nodeThreeObjectExtend),s=Wu(t.nodeVal),a=Wu(t.nodeColor),o=Wu(t.nodeVisibility),l={},h={};pd(t.graphData.nodes.filter(o),t.graphScene,{purge:t._flushObjects||n(["nodeThreeObject","nodeThreeObjectExtend"]),objFilter:function(t){return"node"===t.__graphObjType},createObj:function(e){var n,s=i(e),a=r(e);return s&&t.nodeThreeObject===s&&(s=s.clone()),s&&!a?n=s:((n=new vd.Mesh).__graphDefaultObj=!0,s&&a&&n.add(s)),n.__graphObjType="node",n},updateObj:function(e,n){if(e.__graphDefaultObj){var i=s(n)||1,r=Math.cbrt(i)*t.nodeRelSize,o=t.nodeResolution;e.geometry.type.match(/^Sphere(Buffer)?Geometry$/)&&e.geometry.parameters.radius===r&&e.geometry.parameters.widthSegments===o||(l.hasOwnProperty(i)||(l[i]=new vd.SphereGeometry(r,o,o)),e.geometry.dispose(),e.geometry=l[i]);var u=a(n),c=new vd.Color(fd(u||"#ffffaa")),d=t.nodeOpacity*md(u);"MeshLambertMaterial"===e.material.type&&e.material.color.equals(c)&&e.material.opacity===d||(h.hasOwnProperty(u)||(h[u]=new vd.MeshLambertMaterial({color:c,transparent:!0,opacity:d})),e.material.dispose(),e.material=h[u])}}})}if(t._flushObjects||n(["graphData","linkThreeObject","linkThreeObjectExtend","linkMaterial","linkColor","linkWidth","linkVisibility","linkResolution","linkOpacity","linkDirectionalArrowLength","linkDirectionalArrowColor","linkDirectionalArrowResolution","linkDirectionalParticles","linkDirectionalParticleWidth","linkDirectionalParticleColor","linkDirectionalParticleResolution"])){var u=Wu(t.linkThreeObject),c=Wu(t.linkThreeObjectExtend),d=Wu(t.linkMaterial),p=Wu(t.linkVisibility),f=Wu(t.linkColor),m=Wu(t.linkWidth),g={},_={},v={},y=t.graphData.links.filter(p);if(pd(y,t.graphScene,{objBindAttr:"__lineObj",purge:t._flushObjects||n(["linkThreeObject","linkThreeObjectExtend","linkWidth"]),objFilter:function(t){return"link"===t.__graphObjType},exitObj:function(t){var e=t.__data&&t.__data.__singleHopPhotonsObj;e&&(e.parent.remove(e),cd(e),delete t.__data.__singleHopPhotonsObj)},createObj:function(e){var n,i,r=u(e),s=c(e);if(r&&t.linkThreeObject===r&&(r=r.clone()),!r||s)if(!!m(e))n=new vd.Mesh;else{var a=new vd.BufferGeometry;a[xd]("position",new vd.BufferAttribute(new Float32Array(6),3)),n=new vd.Line(a)}return r?s?((i=new vd.Group).__graphDefaultObj=!0,i.add(n),i.add(r)):i=r:(i=n).__graphDefaultObj=!0,i.renderOrder=10,i.__graphObjType="link",i},updateObj:function(e,n){if(e.__graphDefaultObj){var i=e.children.length?e.children[0]:e,r=Math.ceil(10*m(n))/10,s=!!r;if(s){var a=r/2,o=t.linkResolution;if(!i.geometry.type.match(/^Cylinder(Buffer)?Geometry$/)||i.geometry.parameters.radiusTop!==a||i.geometry.parameters.radialSegments!==o){if(!g.hasOwnProperty(r)){var l=new vd.CylinderGeometry(a,a,1,o,1,!1);l[bd]((new vd.Matrix4).makeTranslation(0,.5,0)),l[bd]((new vd.Matrix4).makeRotationX(Math.PI/2)),g[r]=l}i.geometry.dispose(),i.geometry=g[r]}}var h=d(n);if(h)i.material=h;else{var u=f(n),c=new vd.Color(fd(u||"#f0f0f0")),p=t.linkOpacity*md(u),y=s?"MeshLambertMaterial":"LineBasicMaterial";if(i.material.type!==y||!i.material.color.equals(c)||i.material.opacity!==p){var x=s?_:v;x.hasOwnProperty(u)||(x[u]=new vd[y]({color:c,transparent:p<1,opacity:p,depthWrite:p>=1})),i.material.dispose(),i.material=x[u]}}}}}),t.linkDirectionalArrowLength||e.hasOwnProperty("linkDirectionalArrowLength")){var x=Wu(t.linkDirectionalArrowLength),b=Wu(t.linkDirectionalArrowColor);pd(y.filter(x),t.graphScene,{objBindAttr:"__arrowObj",objFilter:function(t){return"arrow"===t.__linkThreeObjType},createObj:function(){var t=new vd.Mesh(void 0,new vd.MeshLambertMaterial({transparent:!0}));return t.__linkThreeObjType="arrow",t},updateObj:function(e,n){var i=x(n),r=t.linkDirectionalArrowResolution;if(!e.geometry.type.match(/^Cone(Buffer)?Geometry$/)||e.geometry.parameters.height!==i||e.geometry.parameters.radialSegments!==r){var s=new vd.ConeGeometry(.25*i,i,r);s.translate(0,i/2,0),s.rotateX(Math.PI/2),e.geometry.dispose(),e.geometry=s}var a=b(n)||f(n)||"#f0f0f0";e.material.color=new vd.Color(fd(a)),e.material.opacity=3*t.linkOpacity*md(a)}})}if(t.linkDirectionalParticles||e.hasOwnProperty("linkDirectionalParticles")){var S=Wu(t.linkDirectionalParticles),M=Wu(t.linkDirectionalParticleWidth),T=Wu(t.linkDirectionalParticleColor),w={},E={};pd(y.filter(S),t.graphScene,{objBindAttr:"__photonsObj",objFilter:function(t){return"photons"===t.__linkThreeObjType},createObj:function(){var t=new vd.Group;return t.__linkThreeObjType="photons",t},updateObj:function(e,n){var i,r=Math.round(Math.abs(S(n))),s=!!e.children.length&&e.children[0],a=Math.ceil(10*M(n))/10/2,o=t.linkDirectionalParticleResolution;s&&s.geometry.parameters.radius===a&&s.geometry.parameters.widthSegments===o?i=s.geometry:(E.hasOwnProperty(a)||(E[a]=new vd.SphereGeometry(a,o,o)),i=E[a],s&&s.geometry.dispose());var l,h=T(n)||f(n)||"#f0f0f0",u=new vd.Color(fd(h)),c=3*t.linkOpacity;s&&s.material.color.equals(u)&&s.material.opacity===c?l=s.material:(w.hasOwnProperty(h)||(w[h]=new vd.MeshLambertMaterial({color:u,transparent:!0,opacity:c})),l=w[h],s&&s.material.dispose()),pd(ad(new Array(r)).map((function(t,e){return{idx:e}})),e,{idAccessor:function(t){return t.idx},createObj:function(){return new vd.Mesh(i,l)},updateObj:function(t){t.geometry=i,t.material=l}})}})}}if(t._flushObjects=!1,n(["graphData","nodeId","linkSource","linkTarget","numDimensions","forceEngine","dagMode","dagNodeFilter","dagLevelDistance"])){t.engineRunning=!1,t.graphData.links.forEach((function(e){e.source=e[t.linkSource],e.target=e[t.linkTarget]}));var A,R="ngraph"!==t.forceEngine;if(R){(A=t.d3ForceLayout).stop().alpha(1).numDimensions(t.numDimensions).nodes(t.graphData.nodes);var C=t.d3ForceLayout.force("link");C&&C.id((function(e){return e[t.nodeId]})).links(t.graphData.links);var N=t.dagMode&&function(t,e){var n=t.nodes,i=t.links,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=r.nodeFilter,a=void 0===s?function(){return!0}:s,o=r.onLoopError,l=void 0===o?function(t){throw"Invalid DAG structure! Found cycle in node path: ".concat(t.join(" -> "),".")}:o,h={};n.forEach((function(t){return h[e(t)]={data:t,out:[],depth:-1,skip:!a(t)}})),i.forEach((function(t){var n=t.source,i=t.target,r=l(n),s=l(i);if(!h.hasOwnProperty(r))throw"Missing source node with id: ".concat(r);if(!h.hasOwnProperty(s))throw"Missing target node with id: ".concat(s);var a=h[r],o=h[s];function l(t){return"object"===od(t)?e(t):t}a.out.push(o)}));var u=[];return function t(n){for(var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=function(){var s=n[a];if(-1!==i.indexOf(s)){var o=[].concat(ad(i.slice(i.indexOf(s))),[s]).map((function(t){return e(t.data)}));return u.some((function(t){return t.length===o.length&&t.every((function(t,e){return t===o[e]}))}))||(u.push(o),l(o)),1}r>s.depth&&(s.depth=r,t(s.out,[].concat(ad(i),[s]),r+(s.skip?0:1)))},a=0,o=n.length;a<o;a++)s()}(Object.values(h)),Object.assign.apply(Object,[{}].concat(ad(Object.entries(h).filter((function(t){return!sd(t,2)[1].skip})).map((function(t){var e=sd(t,2);return Jc({},e[0],e[1].depth)})))))}(t.graphData,(function(e){return e[t.nodeId]}),{nodeFilter:t.dagNodeFilter,onLoopError:t.onDagError||void 0}),P=Math.max.apply(Math,ad(Object.values(N||[]))),I=t.dagLevelDistance||t.graphData.nodes.length/(P||1)*2*(-1!==["radialin","radialout"].indexOf(t.dagMode)?.7:1);if(["lr","rl","td","bu","zin","zout"].includes(e.dagMode)){var L=["lr","rl"].includes(e.dagMode)?"fx":["td","bu"].includes(e.dagMode)?"fy":"fz";t.graphData.nodes.filter(t.dagNodeFilter).forEach((function(t){return delete t[L]}))}if(["lr","rl","td","bu","zin","zout"].includes(t.dagMode)){var U=["rl","td","zout"].includes(t.dagMode),D=["lr","rl"].includes(t.dagMode)?"fx":["td","bu"].includes(t.dagMode)?"fy":"fz";t.graphData.nodes.filter(t.dagNodeFilter).forEach((function(e){return e[D]=function(e){return(N[e[t.nodeId]]-P/2)*I*(U?-1:1)}(e)}))}t.d3ForceLayout.force("dagRadial",-1!==["radialin","radialout"].indexOf(t.dagMode)?function(t,e,n,i){var r,s,a,o,l=Kl(.1);function h(t){for(var l=0,h=r.length;l<h;++l){var u=r[l],c=u.x-e||1e-6,d=(u.y||0)-n||1e-6,p=(u.z||0)-i||1e-6,f=Math.sqrt(c*c+d*d+p*p),m=(o[l]-f)*a[l]*t/f;u.vx+=c*m,s>1&&(u.vy+=d*m),s>2&&(u.vz+=p*m)}}function u(){if(r){var e,n=r.length;for(a=new Array(n),o=new Array(n),e=0;e<n;++e)o[e]=+t(r[e],e,r),a[e]=isNaN(o[e])?0:+l(r[e],e,r)}}return"function"!=typeof t&&(t=Kl(+t)),null==e&&(e=0),null==n&&(n=0),null==i&&(i=0),h.initialize=function(t,...e){r=t,s=e.find((t=>[1,2,3].includes(t)))||2,u()},h.strength=function(t){return arguments.length?(l="function"==typeof t?t:Kl(+t),u(),h):l},h.radius=function(e){return arguments.length?(t="function"==typeof e?e:Kl(+e),u(),h):t},h.x=function(t){return arguments.length?(e=+t,h):e},h.y=function(t){return arguments.length?(n=+t,h):n},h.z=function(t){return arguments.length?(i=+t,h):i},h}((function(e){var n=N[e[t.nodeId]]||-1;return("radialin"===t.dagMode?P-n:n)*I})).strength((function(e){return t.dagNodeFilter(e)?1:0})):null)}else{var O=yd.graph();t.graphData.nodes.forEach((function(e){O.addNode(e[t.nodeId])})),t.graphData.links.forEach((function(t){O.addLink(t.source,t.target)})),(A=yd.forcelayout(O,id({dimensions:t.numDimensions},t.ngraphPhysics))).graph=O}for(var F=0;F<t.warmupTicks&&!(R&&t.d3AlphaMin>0&&t.d3ForceLayout.alpha()<t.d3AlphaMin);F++)A[R?"tick":"step"]();t.layout=A,this.resetCountdown()}t.engineRunning=!0,t.onFinishUpdate()}});var Md=function(t){var e=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=function(n){function i(){var n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i);for(var r=arguments.length,s=new Array(r),a=0;a<r;a++)s[a]=arguments[a];return(n=Qc(this,i,[].concat(s))).__kapsuleInstance=t().apply(void 0,[].concat(ad(e?[n]:[]),s)),n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&rd(t,e)}(i,n),r=i,Object.defineProperty(r,"prototype",{writable:!1}),r;var r}(arguments.length>1&&void 0!==arguments[1]?arguments[1]:Object);return Object.keys(t()).forEach((function(t){return n.prototype[t]=function(){var e,n=(e=this.__kapsuleInstance)[t].apply(e,arguments);return n===this.__kapsuleInstance?this:n}})),n}(Sd,(window.THREE?window.THREE:{Group:no}).Group,!0);const Td="170",wd=100,Ed=101,Ad=102,Rd=200,Cd=201,Nd=202,Pd=203,Id=204,Ld=205,Ud=206,Dd=207,Od=208,Fd=209,Bd=210,zd=301,kd=302,Gd=303,Vd=304,Hd=1e3,jd=1001,Wd=1002,qd=1003,Xd=1004,$d=1005,Yd=1006,Kd=1007,Zd=1008,Qd=1009,Jd=1010,tp=1011,ep=1012,np=1013,ip=1014,rp=1015,sp=1016,ap=1020,op=1022,lp=1023,hp=1026,up=1027,cp=1028,dp=1029,pp=1030,fp=1031,mp=1033,gp=33776,_p=33777,vp=33778,yp=33779,xp=37492,bp=37496,Sp=37808,Mp=37809,Tp=37810,wp=37811,Ep=37812,Ap=37813,Rp=37814,Cp=37815,Np=37816,Pp=37817,Ip=37818,Lp=37819,Up=37820,Dp=37821,Op=36492,Fp="",Bp="srgb",zp="srgb-linear",kp="linear",Gp="srgb",Vp=7680,Hp=512,jp=513,Wp=514,qp=515,Xp=516,$p=517,Yp=518,Kp=519,Zp=35044,Qp=35048,Jp=2e3,tf=2001;class ef{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const n=this._listeners;void 0===n[t]&&(n[t]=[]),-1===n[t].indexOf(e)&&n[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const n=this._listeners;return void 0!==n[t]&&-1!==n[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const n=this._listeners[t];if(void 0!==n){const t=n.indexOf(e);-1!==t&&n.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 n=e.slice(0);for(let e=0,i=n.length;e<i;e++)n[e].call(this,t);t.target=null}}}const nf=["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 rf=1234567;const sf=Math.PI/180,af=180/Math.PI;function of(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(nf[255&t]+nf[t>>8&255]+nf[t>>16&255]+nf[t>>24&255]+"-"+nf[255&e]+nf[e>>8&255]+"-"+nf[e>>16&15|64]+nf[e>>24&255]+"-"+nf[63&n|128]+nf[n>>8&255]+"-"+nf[n>>16&255]+nf[n>>24&255]+nf[255&i]+nf[i>>8&255]+nf[i>>16&255]+nf[i>>24&255]).toLowerCase()}function lf(t,e,n){return Math.max(e,Math.min(n,t))}function hf(t,e){return(t%e+e)%e}function uf(t,e,n){return(1-n)*t+n*e}function cf(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 df(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 pf={DEG2RAD:sf,RAD2DEG:af,generateUUID:of,clamp:lf,euclideanModulo:hf,mapLinear:function(t,e,n,i,r){return i+(t-e)*(r-i)/(n-e)},inverseLerp:function(t,e,n){return t!==e?(n-t)/(e-t):0},lerp:uf,damp:function(t,e,n,i){return uf(t,e,1-Math.exp(-n*i))},pingpong:function(t,e=1){return e-Math.abs(hf(t,2*e)-e)},smoothstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-e))*t*(3-2*t)},smootherstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-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&&(rf=t);let e=rf+=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*sf},radToDeg:function(t){return t*af},isPowerOfTwo:function(t){return!(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,n,i,r){const s=Math.cos,a=Math.sin,o=s(n/2),l=a(n/2),h=s((e+i)/2),u=a((e+i)/2),c=s((e-i)/2),d=a((e-i)/2),p=s((i-e)/2),f=a((i-e)/2);switch(r){case"XYX":t.set(o*u,l*c,l*d,o*h);break;case"YZY":t.set(l*d,o*u,l*c,o*h);break;case"ZXZ":t.set(l*c,l*d,o*u,o*h);break;case"XZX":t.set(o*u,l*f,l*p,o*h);break;case"YXY":t.set(l*p,o*u,l*f,o*h);break;case"ZYZ":t.set(l*f,l*p,o*u,o*h);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}},normalize:df,denormalize:cf};class ff{constructor(t=0,e=0){ff.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,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}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 n=this.dot(t)/e;return Math.acos(lf(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}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,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,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 n=Math.cos(e),i=Math.sin(e),r=this.x-t.x,s=this.y-t.y;return this.x=r*n-s*i+t.x,this.y=r*i+s*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class mf{constructor(t,e,n,i,r,s,a,o,l){mf.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,n,i,r,s,a,o,l)}set(t,e,n,i,r,s,a,o,l){const h=this.elements;return h[0]=t,h[1]=i,h[2]=a,h[3]=e,h[4]=r,h[5]=o,h[6]=n,h[7]=s,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.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 n=t.elements,i=e.elements,r=this.elements,s=n[0],a=n[3],o=n[6],l=n[1],h=n[4],u=n[7],c=n[2],d=n[5],p=n[8],f=i[0],m=i[3],g=i[6],_=i[1],v=i[4],y=i[7],x=i[2],b=i[5],S=i[8];return r[0]=s*f+a*_+o*x,r[3]=s*m+a*v+o*b,r[6]=s*g+a*y+o*S,r[1]=l*f+h*_+u*x,r[4]=l*m+h*v+u*b,r[7]=l*g+h*y+u*S,r[2]=c*f+d*_+p*x,r[5]=c*m+d*v+p*b,r[8]=c*g+d*y+p*S,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],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],l=t[7],h=t[8];return e*s*h-e*a*l-n*r*h+n*a*o+i*r*l-i*s*o}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],l=t[7],h=t[8],u=h*s-a*l,c=a*o-h*r,d=l*r-s*o,p=e*u+n*c+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const f=1/p;return t[0]=u*f,t[1]=(i*l-h*n)*f,t[2]=(a*n-i*s)*f,t[3]=c*f,t[4]=(h*e-i*o)*f,t[5]=(i*r-a*e)*f,t[6]=d*f,t[7]=(n*o-l*e)*f,t[8]=(s*e-n*r)*f,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,n,i,r,s,a){const o=Math.cos(r),l=Math.sin(r);return this.set(n*o,n*l,-n*(o*s+l*a)+s+t,-i*l,i*o,-i*(-l*s+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(gf.makeScale(t,e)),this}rotate(t){return this.premultiply(gf.makeRotation(-t)),this}translate(t,e){return this.premultiply(gf.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),n=Math.sin(t);return this.set(e,-n,0,n,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,n=t.elements;for(let t=0;t<9;t++)if(e[t]!==n[t])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const gf=new mf;function _f(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}const vf={};const yf={enabled:!0,workingColorSpace:zp,spaces:{},convert:function(t,e,n){return!1!==this.enabled&&e!==n&&e&&n?(this.spaces[e].transfer===Gp&&(t.r=xf(t.r),t.g=xf(t.g),t.b=xf(t.b)),this.spaces[e].primaries!==this.spaces[n].primaries&&(t.applyMatrix3(this.spaces[e].toXYZ),t.applyMatrix3(this.spaces[n].fromXYZ)),this.spaces[n].transfer===Gp&&(t.r=bf(t.r),t.g=bf(t.g),t.b=bf(t.b)),t):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 this.spaces[t].primaries},getTransfer:function(t){return t===Fp?kp:this.spaces[t].transfer},getLuminanceCoefficients:function(t,e=this.workingColorSpace){return t.fromArray(this.spaces[e].luminanceCoefficients)},define:function(t){Object.assign(this.spaces,t)},_getMatrix:function(t,e,n){return t.copy(this.spaces[e].toXYZ).multiply(this.spaces[n].fromXYZ)},_getDrawingBufferColorSpace:function(t){return this.spaces[t].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(t=this.workingColorSpace){return this.spaces[t].workingColorSpaceConfig.unpackColorSpace}};function xf(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function bf(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}const Sf=[.64,.33,.3,.6,.15,.06],Mf=[.2126,.7152,.0722],Tf=[.3127,.329],wf=(new mf).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),Ef=(new mf).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);let Af;yf.define({[zp]:{primaries:Sf,whitePoint:Tf,transfer:kp,toXYZ:wf,fromXYZ:Ef,luminanceCoefficients:Mf,workingColorSpaceConfig:{unpackColorSpace:Bp},outputColorSpaceConfig:{drawingBufferColorSpace:Bp}},[Bp]:{primaries:Sf,whitePoint:Tf,transfer:Gp,toXYZ:wf,fromXYZ:Ef,luminanceCoefficients:Mf,outputColorSpaceConfig:{drawingBufferColorSpace:Bp}}});class Rf{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===Af&&(Af=_f("canvas")),Af.width=t.width,Af.height=t.height;const n=Af.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),e=Af}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=_f("canvas");e.width=t.width,e.height=t.height;const n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const i=n.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t<r.length;t++)r[t]=255*xf(r[t]/255);return n.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*xf(e[t]/255)):e[t]=xf(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 Cf=0;class Nf{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Cf++}),this.uuid=of(),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 n={uuid:this.uuid,url:""},i=this.data;if(null!==i){let t;if(Array.isArray(i)){t=[];for(let e=0,n=i.length;e<n;e++)i[e].isDataTexture?t.push(Pf(i[e].image)):t.push(Pf(i[e]))}else t=Pf(i);n.url=t}return e||(t.images[this.uuid]=n),n}}function Pf(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?Rf.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 If=0;class Lf extends ef{constructor(t=Lf.DEFAULT_IMAGE,e=Lf.DEFAULT_MAPPING,n=1001,i=1001,r=1006,s=1008,a=1023,o=1009,l=Lf.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:If++}),this.uuid=of(),this.name="",this.source=new Nf(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=n,this.wrapT=i,this.magFilter=r,this.minFilter=s,this.anisotropy=l,this.format=a,this.internalFormat=null,this.type=o,this.offset=new ff(0,0),this.repeat=new ff(1,1),this.center=new ff(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new mf,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=h,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 n={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&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(300!==this.mapping)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case Hd:t.x=t.x-Math.floor(t.x);break;case jd:t.x=t.x<0?0:1;break;case Wd: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 Hd:t.y=t.y-Math.floor(t.y);break;case jd:t.y=t.y<0?0:1;break;case Wd: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++}}Lf.DEFAULT_IMAGE=null,Lf.DEFAULT_MAPPING=300,Lf.DEFAULT_ANISOTROPY=1;class Uf{constructor(t=0,e=0,n=0,i=1){Uf.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,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,n,i){return this.x=t,this.y=e,this.z=n,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,n=this.y,i=this.z,r=this.w,s=t.elements;return this.x=s[0]*e+s[4]*n+s[8]*i+s[12]*r,this.y=s[1]*e+s[5]*n+s[9]*i+s[13]*r,this.z=s[2]*e+s[6]*n+s[10]*i+s[14]*r,this.w=s[3]*e+s[7]*n+s[11]*i+s[15]*r,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,i,r;const s=.01,a=.1,o=t.elements,l=o[0],h=o[4],u=o[8],c=o[1],d=o[5],p=o[9],f=o[2],m=o[6],g=o[10];if(Math.abs(h-c)<s&&Math.abs(u-f)<s&&Math.abs(p-m)<s){if(Math.abs(h+c)<a&&Math.abs(u+f)<a&&Math.abs(p+m)<a&&Math.abs(l+d+g-3)<a)return this.set(1,0,0,0),this;e=Math.PI;const t=(l+1)/2,o=(d+1)/2,_=(g+1)/2,v=(h+c)/4,y=(u+f)/4,x=(p+m)/4;return t>o&&t>_?t<s?(n=0,i=.707106781,r=.707106781):(n=Math.sqrt(t),i=v/n,r=y/n):o>_?o<s?(n=.707106781,i=0,r=.707106781):(i=Math.sqrt(o),n=v/i,r=x/i):_<s?(n=.707106781,i=.707106781,r=0):(r=Math.sqrt(_),n=y/r,i=x/r),this.set(n,i,r,e),this}let _=Math.sqrt((m-p)*(m-p)+(u-f)*(u-f)+(c-h)*(c-h));return Math.abs(_)<.001&&(_=1),this.x=(m-p)/_,this.y=(u-f)/_,this.z=(c-h)/_,this.w=Math.acos((l+d+g-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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}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,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this.w=t.w+(e.w-t.w)*n,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 Df extends ef{constructor(t=1,e=1,n={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new Uf(0,0,t,e),this.scissorTest=!1,this.viewport=new Uf(0,0,t,e);const i={width:t,height:e,depth:1};n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:Yd,depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1},n);const r=new Lf(i,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.colorSpace);r.flipY=!1,r.generateMipmaps=n.generateMipmaps,r.internalFormat=n.internalFormat,this.textures=[];const s=n.count;for(let t=0;t<s;t++)this.textures[t]=r.clone(),this.textures[t].isRenderTargetTexture=!0;this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.resolveDepthBuffer=n.resolveDepthBuffer,this.resolveStencilBuffer=n.resolveStencilBuffer,this.depthTexture=n.depthTexture,this.samples=n.samples}get texture(){return this.textures[0]}set texture(t){this.textures[0]=t}setSize(t,e,n=1){if(this.width!==t||this.height!==e||this.depth!==n){this.width=t,this.height=e,this.depth=n;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=n;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,n=t.textures.length;e<n;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 Nf(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 Of extends Df{constructor(t=1,e=1,n={}){super(t,e,n),this.isWebGLRenderTarget=!0}}class Ff extends Lf{constructor(t=null,e=1,n=1,i=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:n,depth:i},this.magFilter=qd,this.minFilter=qd,this.wrapR=jd,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.layerUpdates=new Set}addLayerUpdate(t){this.layerUpdates.add(t)}clearLayerUpdates(){this.layerUpdates.clear()}}class Bf{constructor(t=0,e=0,n=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=n,this._w=i}static slerpFlat(t,e,n,i,r,s,a){let o=n[i+0],l=n[i+1],h=n[i+2],u=n[i+3];const c=r[s+0],d=r[s+1],p=r[s+2],f=r[s+3];if(0===a)return t[e+0]=o,t[e+1]=l,t[e+2]=h,void(t[e+3]=u);if(1===a)return t[e+0]=c,t[e+1]=d,t[e+2]=p,void(t[e+3]=f);if(u!==f||o!==c||l!==d||h!==p){let t=1-a;const e=o*c+l*d+h*p+u*f,n=e>=0?1:-1,i=1-e*e;if(i>Number.EPSILON){const r=Math.sqrt(i),s=Math.atan2(r,e*n);t=Math.sin(t*s)/r,a=Math.sin(a*s)/r}const r=a*n;if(o=o*t+c*r,l=l*t+d*r,h=h*t+p*r,u=u*t+f*r,t===1-a){const t=1/Math.sqrt(o*o+l*l+h*h+u*u);o*=t,l*=t,h*=t,u*=t}}t[e]=o,t[e+1]=l,t[e+2]=h,t[e+3]=u}static multiplyQuaternionsFlat(t,e,n,i,r,s){const a=n[i],o=n[i+1],l=n[i+2],h=n[i+3],u=r[s],c=r[s+1],d=r[s+2],p=r[s+3];return t[e]=a*p+h*u+o*d-l*c,t[e+1]=o*p+h*c+l*u-a*d,t[e+2]=l*p+h*d+a*c-o*u,t[e+3]=h*p-a*u-o*c-l*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,n,i){return this._x=t,this._y=e,this._z=n,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 n=t._x,i=t._y,r=t._z,s=t._order,a=Math.cos,o=Math.sin,l=a(n/2),h=a(i/2),u=a(r/2),c=o(n/2),d=o(i/2),p=o(r/2);switch(s){case"XYZ":this._x=c*h*u+l*d*p,this._y=l*d*u-c*h*p,this._z=l*h*p+c*d*u,this._w=l*h*u-c*d*p;break;case"YXZ":this._x=c*h*u+l*d*p,this._y=l*d*u-c*h*p,this._z=l*h*p-c*d*u,this._w=l*h*u+c*d*p;break;case"ZXY":this._x=c*h*u-l*d*p,this._y=l*d*u+c*h*p,this._z=l*h*p+c*d*u,this._w=l*h*u-c*d*p;break;case"ZYX":this._x=c*h*u-l*d*p,this._y=l*d*u+c*h*p,this._z=l*h*p-c*d*u,this._w=l*h*u+c*d*p;break;case"YZX":this._x=c*h*u+l*d*p,this._y=l*d*u+c*h*p,this._z=l*h*p-c*d*u,this._w=l*h*u-c*d*p;break;case"XZY":this._x=c*h*u-l*d*p,this._y=l*d*u-c*h*p,this._z=l*h*p+c*d*u,this._w=l*h*u+c*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+s)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const n=e/2,i=Math.sin(n);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,n=e[0],i=e[4],r=e[8],s=e[1],a=e[5],o=e[9],l=e[2],h=e[6],u=e[10],c=n+a+u;if(c>0){const t=.5/Math.sqrt(c+1);this._w=.25/t,this._x=(h-o)*t,this._y=(r-l)*t,this._z=(s-i)*t}else if(n>a&&n>u){const t=2*Math.sqrt(1+n-a-u);this._w=(h-o)/t,this._x=.25*t,this._y=(i+s)/t,this._z=(r+l)/t}else if(a>u){const t=2*Math.sqrt(1+a-n-u);this._w=(r-l)/t,this._x=(i+s)/t,this._y=.25*t,this._z=(o+h)/t}else{const t=2*Math.sqrt(1+u-n-a);this._w=(s-i)/t,this._x=(r+l)/t,this._y=(o+h)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return n<Number.EPSILON?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(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=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(lf(this.dot(t),-1,1)))}rotateTowards(t,e){const n=this.angleTo(t);if(0===n)return this;const i=Math.min(1,e/n);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 n=t._x,i=t._y,r=t._z,s=t._w,a=e._x,o=e._y,l=e._z,h=e._w;return this._x=n*h+s*a+i*l-r*o,this._y=i*h+s*o+r*a-n*l,this._z=r*h+s*l+n*o-i*a,this._w=s*h-n*a-i*o-r*l,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const n=this._x,i=this._y,r=this._z,s=this._w;let a=s*t._w+n*t._x+i*t._y+r*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=s,this._x=n,this._y=i,this._z=r,this;const o=1-a*a;if(o<=Number.EPSILON){const t=1-e;return this._w=t*s+e*this._w,this._x=t*n+e*this._x,this._y=t*i+e*this._y,this._z=t*r+e*this._z,this.normalize(),this}const l=Math.sqrt(o),h=Math.atan2(l,a),u=Math.sin((1-e)*h)/l,c=Math.sin(e*h)/l;return this._w=s*u+this._w*c,this._x=n*u+this._x*c,this._y=i*u+this._y*c,this._z=r*u+this._z*c,this._onChangeCallback(),this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),r=Math.sqrt(n);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 zf{constructor(t=0,e=0,n=0){zf.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return void 0===n&&(n=this.z),this.x=t,this.y=e,this.z=n,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(Gf.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Gf.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*i,this.y=r[1]*e+r[4]*n+r[7]*i,this.z=r[2]*e+r[5]*n+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,r=t.elements,s=1/(r[3]*e+r[7]*n+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*n+r[8]*i+r[12])*s,this.y=(r[1]*e+r[5]*n+r[9]*i+r[13])*s,this.z=(r[2]*e+r[6]*n+r[10]*i+r[14])*s,this}applyQuaternion(t){const e=this.x,n=this.y,i=this.z,r=t.x,s=t.y,a=t.z,o=t.w,l=2*(s*i-a*n),h=2*(a*e-r*i),u=2*(r*n-s*e);return this.x=e+o*l+s*u-a*h,this.y=n+o*h+a*l-r*u,this.z=i+o*u+r*h-s*l,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,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i,this.y=r[1]*e+r[5]*n+r[9]*i,this.z=r[2]*e+r[6]*n+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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))}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,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const n=t.x,i=t.y,r=t.z,s=e.x,a=e.y,o=e.z;return this.x=i*o-r*a,this.y=r*s-n*o,this.z=n*a-i*s,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return kf.copy(this).projectOnVector(t),this.sub(kf)}reflect(t){return this.sub(kf.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 n=this.dot(t)/e;return Math.acos(lf(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+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,n){const i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,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(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,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,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const kf=new zf,Gf=new Bf;class Vf{constructor(t=new zf(1/0,1/0,1/0),e=new zf(-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,n=t.length;e<n;e+=3)this.expandByPoint(jf.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,n=t.count;e<n;e++)this.expandByPoint(jf.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,n=t.length;e<n;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const n=jf.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(n),this.max.copy(t).add(n),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 n=t.geometry;if(void 0!==n){const i=n.getAttribute("position");if(!0===e&&void 0!==i&&!0!==t.isInstancedMesh)for(let e=0,n=i.count;e<n;e++)!0===t.isMesh?t.getVertexPosition(e,jf):jf.fromBufferAttribute(i,e),jf.applyMatrix4(t.matrixWorld),this.expandByPoint(jf);else void 0!==t.boundingBox?(null===t.boundingBox&&t.computeBoundingBox(),Wf.copy(t.boundingBox)):(null===n.boundingBox&&n.computeBoundingBox(),Wf.copy(n.boundingBox)),Wf.applyMatrix4(t.matrixWorld),this.union(Wf)}const i=t.children;for(let t=0,n=i.length;t<n;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,jf),jf.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Qf),Jf.subVectors(this.max,Qf),qf.subVectors(t.a,Qf),Xf.subVectors(t.b,Qf),$f.subVectors(t.c,Qf),Yf.subVectors(Xf,qf),Kf.subVectors($f,Xf),Zf.subVectors(qf,$f);let e=[0,-Yf.z,Yf.y,0,-Kf.z,Kf.y,0,-Zf.z,Zf.y,Yf.z,0,-Yf.x,Kf.z,0,-Kf.x,Zf.z,0,-Zf.x,-Yf.y,Yf.x,0,-Kf.y,Kf.x,0,-Zf.y,Zf.x,0];return!!nm(e,qf,Xf,$f,Jf)&&(e=[1,0,0,0,1,0,0,0,1],!!nm(e,qf,Xf,$f,Jf)&&(tm.crossVectors(Yf,Kf),e=[tm.x,tm.y,tm.z],nm(e,qf,Xf,$f,Jf)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,jf).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(jf).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()||(Hf[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Hf[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Hf[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Hf[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Hf[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Hf[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Hf[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Hf[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Hf)),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 Hf=[new zf,new zf,new zf,new zf,new zf,new zf,new zf,new zf],jf=new zf,Wf=new Vf,qf=new zf,Xf=new zf,$f=new zf,Yf=new zf,Kf=new zf,Zf=new zf,Qf=new zf,Jf=new zf,tm=new zf,em=new zf;function nm(t,e,n,i,r){for(let s=0,a=t.length-3;s<=a;s+=3){em.fromArray(t,s);const a=r.x*Math.abs(em.x)+r.y*Math.abs(em.y)+r.z*Math.abs(em.z),o=e.dot(em),l=n.dot(em),h=i.dot(em);if(Math.max(-Math.max(o,l,h),Math.min(o,l,h))>a)return!1}return!0}const im=new Vf,rm=new zf,sm=new zf;class am{constructor(t=new zf,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 n=this.center;void 0!==e?n.copy(e):im.setFromPoints(t).getCenter(n);let i=0;for(let e=0,r=t.length;e<r;e++)i=Math.max(i,n.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 n=this.center.distanceToSquared(t);return e.copy(t),n>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;rm.subVectors(t,this.center);const e=rm.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),n=.5*(t-this.radius);this.center.addScaledVector(rm,n/t),this.radius+=n}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):(sm.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(rm.copy(t.center).add(sm)),this.expandByPoint(rm.copy(t.center).sub(sm))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const om=new zf,lm=new zf,hm=new zf,um=new zf,cm=new zf,dm=new zf,pm=new zf;class fm{constructor(t=new zf,e=new zf(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,om)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=om.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(om.copy(this.origin).addScaledVector(this.direction,e),om.distanceToSquared(t))}distanceSqToSegment(t,e,n,i){lm.copy(t).add(e).multiplyScalar(.5),hm.copy(e).sub(t).normalize(),um.copy(this.origin).sub(lm);const r=.5*t.distanceTo(e),s=-this.direction.dot(hm),a=um.dot(this.direction),o=-um.dot(hm),l=um.lengthSq(),h=Math.abs(1-s*s);let u,c,d,p;if(h>0)if(u=s*o-a,c=s*a-o,p=r*h,u>=0)if(c>=-p)if(c<=p){const t=1/h;u*=t,c*=t,d=u*(u+s*c+2*a)+c*(s*u+c+2*o)+l}else c=r,u=Math.max(0,-(s*c+a)),d=-u*u+c*(c+2*o)+l;else c=-r,u=Math.max(0,-(s*c+a)),d=-u*u+c*(c+2*o)+l;else c<=-p?(u=Math.max(0,-(-s*r+a)),c=u>0?-r:Math.min(Math.max(-r,-o),r),d=-u*u+c*(c+2*o)+l):c<=p?(u=0,c=Math.min(Math.max(-r,-o),r),d=c*(c+2*o)+l):(u=Math.max(0,-(s*r+a)),c=u>0?r:Math.min(Math.max(-r,-o),r),d=-u*u+c*(c+2*o)+l);else c=s>0?-r:r,u=Math.max(0,-(s*c+a)),d=-u*u+c*(c+2*o)+l;return n&&n.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(lm).addScaledVector(hm,c),d}intersectSphere(t,e){om.subVectors(t.center,this.origin);const n=om.dot(this.direction),i=om.dot(om)-n*n,r=t.radius*t.radius;if(i>r)return null;const s=Math.sqrt(r-i),a=n-s,o=n+s;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){const n=this.distanceToPlane(t);return null===n?null:this.at(n,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 n,i,r,s,a,o;const l=1/this.direction.x,h=1/this.direction.y,u=1/this.direction.z,c=this.origin;return l>=0?(n=(t.min.x-c.x)*l,i=(t.max.x-c.x)*l):(n=(t.max.x-c.x)*l,i=(t.min.x-c.x)*l),h>=0?(r=(t.min.y-c.y)*h,s=(t.max.y-c.y)*h):(r=(t.max.y-c.y)*h,s=(t.min.y-c.y)*h),n>s||r>i?null:((r>n||isNaN(n))&&(n=r),(s<i||isNaN(i))&&(i=s),u>=0?(a=(t.min.z-c.z)*u,o=(t.max.z-c.z)*u):(a=(t.max.z-c.z)*u,o=(t.min.z-c.z)*u),n>o||a>i?null:((a>n||n!=n)&&(n=a),(o<i||i!=i)&&(i=o),i<0?null:this.at(n>=0?n:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,om)}intersectTriangle(t,e,n,i,r){cm.subVectors(e,t),dm.subVectors(n,t),pm.crossVectors(cm,dm);let s,a=this.direction.dot(pm);if(a>0){if(i)return null;s=1}else{if(!(a<0))return null;s=-1,a=-a}um.subVectors(this.origin,t);const o=s*this.direction.dot(dm.crossVectors(um,dm));if(o<0)return null;const l=s*this.direction.dot(cm.cross(um));if(l<0)return null;if(o+l>a)return null;const h=-s*um.dot(pm);return h<0?null:this.at(h/a,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 mm{constructor(t,e,n,i,r,s,a,o,l,h,u,c,d,p,f,m){mm.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,n,i,r,s,a,o,l,h,u,c,d,p,f,m)}set(t,e,n,i,r,s,a,o,l,h,u,c,d,p,f,m){const g=this.elements;return g[0]=t,g[4]=e,g[8]=n,g[12]=i,g[1]=r,g[5]=s,g[9]=a,g[13]=o,g[2]=l,g[6]=h,g[10]=u,g[14]=c,g[3]=d,g[7]=p,g[11]=f,g[15]=m,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 mm).fromArray(this.elements)}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){const e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[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,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,n=t.elements,i=1/gm.setFromMatrixColumn(t,0).length(),r=1/gm.setFromMatrixColumn(t,1).length(),s=1/gm.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*r,e[5]=n[5]*r,e[6]=n[6]*r,e[7]=0,e[8]=n[8]*s,e[9]=n[9]*s,e[10]=n[10]*s,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,n=t.x,i=t.y,r=t.z,s=Math.cos(n),a=Math.sin(n),o=Math.cos(i),l=Math.sin(i),h=Math.cos(r),u=Math.sin(r);if("XYZ"===t.order){const t=s*h,n=s*u,i=a*h,r=a*u;e[0]=o*h,e[4]=-o*u,e[8]=l,e[1]=n+i*l,e[5]=t-r*l,e[9]=-a*o,e[2]=r-t*l,e[6]=i+n*l,e[10]=s*o}else if("YXZ"===t.order){const t=o*h,n=o*u,i=l*h,r=l*u;e[0]=t+r*a,e[4]=i*a-n,e[8]=s*l,e[1]=s*u,e[5]=s*h,e[9]=-a,e[2]=n*a-i,e[6]=r+t*a,e[10]=s*o}else if("ZXY"===t.order){const t=o*h,n=o*u,i=l*h,r=l*u;e[0]=t-r*a,e[4]=-s*u,e[8]=i+n*a,e[1]=n+i*a,e[5]=s*h,e[9]=r-t*a,e[2]=-s*l,e[6]=a,e[10]=s*o}else if("ZYX"===t.order){const t=s*h,n=s*u,i=a*h,r=a*u;e[0]=o*h,e[4]=i*l-n,e[8]=t*l+r,e[1]=o*u,e[5]=r*l+t,e[9]=n*l-i,e[2]=-l,e[6]=a*o,e[10]=s*o}else if("YZX"===t.order){const t=s*o,n=s*l,i=a*o,r=a*l;e[0]=o*h,e[4]=r-t*u,e[8]=i*u+n,e[1]=u,e[5]=s*h,e[9]=-a*h,e[2]=-l*h,e[6]=n*u+i,e[10]=t-r*u}else if("XZY"===t.order){const t=s*o,n=s*l,i=a*o,r=a*l;e[0]=o*h,e[4]=-u,e[8]=l*h,e[1]=t*u+r,e[5]=s*h,e[9]=n*u-i,e[2]=i*u-n,e[6]=a*h,e[10]=r*u+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(vm,t,ym)}lookAt(t,e,n){const i=this.elements;return Sm.subVectors(t,e),0===Sm.lengthSq()&&(Sm.z=1),Sm.normalize(),xm.crossVectors(n,Sm),0===xm.lengthSq()&&(1===Math.abs(n.z)?Sm.x+=1e-4:Sm.z+=1e-4,Sm.normalize(),xm.crossVectors(n,Sm)),xm.normalize(),bm.crossVectors(Sm,xm),i[0]=xm.x,i[4]=bm.x,i[8]=Sm.x,i[1]=xm.y,i[5]=bm.y,i[9]=Sm.y,i[2]=xm.z,i[6]=bm.z,i[10]=Sm.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,r=this.elements,s=n[0],a=n[4],o=n[8],l=n[12],h=n[1],u=n[5],c=n[9],d=n[13],p=n[2],f=n[6],m=n[10],g=n[14],_=n[3],v=n[7],y=n[11],x=n[15],b=i[0],S=i[4],M=i[8],T=i[12],w=i[1],E=i[5],A=i[9],R=i[13],C=i[2],N=i[6],P=i[10],I=i[14],L=i[3],U=i[7],D=i[11],O=i[15];return r[0]=s*b+a*w+o*C+l*L,r[4]=s*S+a*E+o*N+l*U,r[8]=s*M+a*A+o*P+l*D,r[12]=s*T+a*R+o*I+l*O,r[1]=h*b+u*w+c*C+d*L,r[5]=h*S+u*E+c*N+d*U,r[9]=h*M+u*A+c*P+d*D,r[13]=h*T+u*R+c*I+d*O,r[2]=p*b+f*w+m*C+g*L,r[6]=p*S+f*E+m*N+g*U,r[10]=p*M+f*A+m*P+g*D,r[14]=p*T+f*R+m*I+g*O,r[3]=_*b+v*w+y*C+x*L,r[7]=_*S+v*E+y*N+x*U,r[11]=_*M+v*A+y*P+x*D,r[15]=_*T+v*R+y*I+x*O,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],n=t[4],i=t[8],r=t[12],s=t[1],a=t[5],o=t[9],l=t[13],h=t[2],u=t[6],c=t[10],d=t[14];return t[3]*(+r*o*u-i*l*u-r*a*c+n*l*c+i*a*d-n*o*d)+t[7]*(+e*o*d-e*l*c+r*s*c-i*s*d+i*l*h-r*o*h)+t[11]*(+e*l*u-e*a*d-r*s*u+n*s*d+r*a*h-n*l*h)+t[15]*(-i*a*h-e*o*u+e*a*c+i*s*u-n*s*c+n*o*h)}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,n){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]=n),this}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],l=t[7],h=t[8],u=t[9],c=t[10],d=t[11],p=t[12],f=t[13],m=t[14],g=t[15],_=u*m*l-f*c*l+f*o*d-a*m*d-u*o*g+a*c*g,v=p*c*l-h*m*l-p*o*d+s*m*d+h*o*g-s*c*g,y=h*f*l-p*u*l+p*a*d-s*f*d-h*a*g+s*u*g,x=p*u*o-h*f*o-p*a*c+s*f*c+h*a*m-s*u*m,b=e*_+n*v+i*y+r*x;if(0===b)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const S=1/b;return t[0]=_*S,t[1]=(f*c*r-u*m*r-f*i*d+n*m*d+u*i*g-n*c*g)*S,t[2]=(a*m*r-f*o*r+f*i*l-n*m*l-a*i*g+n*o*g)*S,t[3]=(u*o*r-a*c*r-u*i*l+n*c*l+a*i*d-n*o*d)*S,t[4]=v*S,t[5]=(h*m*r-p*c*r+p*i*d-e*m*d-h*i*g+e*c*g)*S,t[6]=(p*o*r-s*m*r-p*i*l+e*m*l+s*i*g-e*o*g)*S,t[7]=(s*c*r-h*o*r+h*i*l-e*c*l-s*i*d+e*o*d)*S,t[8]=y*S,t[9]=(p*u*r-h*f*r-p*n*d+e*f*d+h*n*g-e*u*g)*S,t[10]=(s*f*r-p*a*r+p*n*l-e*f*l-s*n*g+e*a*g)*S,t[11]=(h*a*r-s*u*r-h*n*l+e*u*l+s*n*d-e*a*d)*S,t[12]=x*S,t[13]=(h*f*i-p*u*i+p*n*c-e*f*c-h*n*m+e*u*m)*S,t[14]=(p*a*i-s*f*i-p*n*o+e*f*o+s*n*m-e*a*m)*S,t[15]=(s*u*i-h*a*i+h*n*o-e*u*o-s*n*c+e*a*c)*S,this}scale(t){const e=this.elements,n=t.x,i=t.y,r=t.z;return e[0]*=n,e[4]*=i,e[8]*=r,e[1]*=n,e[5]*=i,e[9]*=r,e[2]*=n,e[6]*=i,e[10]*=r,e[3]*=n,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],n=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,n,i))}makeTranslation(t,e,n){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,n,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const n=Math.cos(e),i=Math.sin(e),r=1-n,s=t.x,a=t.y,o=t.z,l=r*s,h=r*a;return this.set(l*s+n,l*a-i*o,l*o+i*a,0,l*a+i*o,h*a+n,h*o-i*s,0,l*o-i*a,h*o+i*s,r*o*o+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,i,r,s){return this.set(1,n,r,0,t,1,s,0,e,i,1,0,0,0,0,1),this}compose(t,e,n){const i=this.elements,r=e._x,s=e._y,a=e._z,o=e._w,l=r+r,h=s+s,u=a+a,c=r*l,d=r*h,p=r*u,f=s*h,m=s*u,g=a*u,_=o*l,v=o*h,y=o*u,x=n.x,b=n.y,S=n.z;return i[0]=(1-(f+g))*x,i[1]=(d+y)*x,i[2]=(p-v)*x,i[3]=0,i[4]=(d-y)*b,i[5]=(1-(c+g))*b,i[6]=(m+_)*b,i[7]=0,i[8]=(p+v)*S,i[9]=(m-_)*S,i[10]=(1-(c+f))*S,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,n){const i=this.elements;let r=gm.set(i[0],i[1],i[2]).length();const s=gm.set(i[4],i[5],i[6]).length(),a=gm.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],_m.copy(this);const o=1/r,l=1/s,h=1/a;return _m.elements[0]*=o,_m.elements[1]*=o,_m.elements[2]*=o,_m.elements[4]*=l,_m.elements[5]*=l,_m.elements[6]*=l,_m.elements[8]*=h,_m.elements[9]*=h,_m.elements[10]*=h,e.setFromRotationMatrix(_m),n.x=r,n.y=s,n.z=a,this}makePerspective(t,e,n,i,r,s,a=2e3){const o=this.elements,l=2*r/(e-t),h=2*r/(n-i),u=(e+t)/(e-t),c=(n+i)/(n-i);let d,p;if(a===Jp)d=-(s+r)/(s-r),p=-2*s*r/(s-r);else{if(a!==tf)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);d=-s/(s-r),p=-s*r/(s-r)}return o[0]=l,o[4]=0,o[8]=u,o[12]=0,o[1]=0,o[5]=h,o[9]=c,o[13]=0,o[2]=0,o[6]=0,o[10]=d,o[14]=p,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(t,e,n,i,r,s,a=2e3){const o=this.elements,l=1/(e-t),h=1/(n-i),u=1/(s-r),c=(e+t)*l,d=(n+i)*h;let p,f;if(a===Jp)p=(s+r)*u,f=-2*u;else{if(a!==tf)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);p=r*u,f=-1*u}return o[0]=2*l,o[4]=0,o[8]=0,o[12]=-c,o[1]=0,o[5]=2*h,o[9]=0,o[13]=-d,o[2]=0,o[6]=0,o[10]=f,o[14]=-p,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(t){const e=this.elements,n=t.elements;for(let t=0;t<16;t++)if(e[t]!==n[t])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}}const gm=new zf,_m=new mm,vm=new zf(0,0,0),ym=new zf(1,1,1),xm=new zf,bm=new zf,Sm=new zf,Mm=new mm,Tm=new Bf;class wm{constructor(t=0,e=0,n=0,i=wm.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,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,n,i=this._order){return this._x=t,this._y=e,this._z=n,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,n=!0){const i=t.elements,r=i[0],s=i[4],a=i[8],o=i[1],l=i[5],h=i[9],u=i[2],c=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(lf(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-s,r)):(this._x=Math.atan2(c,l),this._z=0);break;case"YXZ":this._x=Math.asin(-lf(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,l)):(this._y=Math.atan2(-u,r),this._z=0);break;case"ZXY":this._x=Math.asin(lf(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-s,l)):(this._y=0,this._z=Math.atan2(o,r));break;case"ZYX":this._y=Math.asin(-lf(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(c,d),this._z=Math.atan2(o,r)):(this._x=0,this._z=Math.atan2(-s,l));break;case"YZX":this._z=Math.asin(lf(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,r)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-lf(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(c,l),this._y=Math.atan2(a,r)):(this._x=Math.atan2(-h,d),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===n&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return Mm.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Mm,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Tm.setFromEuler(this),this.setFromQuaternion(Tm,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}}wm.DEFAULT_ORDER="XYZ";class Em{constructor(){this.mask=1}set(t){this.mask=1<<t>>>0}enable(t){this.mask|=1<<t}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t}disable(t){this.mask&=~(1<<t)}disableAll(){this.mask=0}test(t){return!!(this.mask&t.mask)}isEnabled(t){return!!(this.mask&1<<t)}}let Am=0;const Rm=new zf,Cm=new Bf,Nm=new mm,Pm=new zf,Im=new zf,Lm=new zf,Um=new Bf,Dm=new zf(1,0,0),Om=new zf(0,1,0),Fm=new zf(0,0,1),Bm={type:"added"},zm={type:"removed"},km={type:"childadded",child:null},Gm={type:"childremoved",child:null};class Vm extends ef{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:Am++}),this.uuid=of(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=Vm.DEFAULT_UP.clone();const t=new zf,e=new wm,n=new Bf,i=new zf(1,1,1);e._onChange((function(){n.setFromEuler(e,!1)})),n._onChange((function(){e.setFromQuaternion(n,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:n},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new mm},normalMatrix:{value:new mf}}),this.matrix=new mm,this.matrixWorld=new mm,this.matrixAutoUpdate=Vm.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=Vm.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Em,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 Cm.setFromAxisAngle(t,e),this.quaternion.multiply(Cm),this}rotateOnWorldAxis(t,e){return Cm.setFromAxisAngle(t,e),this.quaternion.premultiply(Cm),this}rotateX(t){return this.rotateOnAxis(Dm,t)}rotateY(t){return this.rotateOnAxis(Om,t)}rotateZ(t){return this.rotateOnAxis(Fm,t)}translateOnAxis(t,e){return Rm.copy(t).applyQuaternion(this.quaternion),this.position.add(Rm.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Dm,t)}translateY(t){return this.translateOnAxis(Om,t)}translateZ(t){return this.translateOnAxis(Fm,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(Nm.copy(this.matrixWorld).invert())}lookAt(t,e,n){t.isVector3?Pm.copy(t):Pm.set(t,e,n);const i=this.parent;this.updateWorldMatrix(!0,!1),Im.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Nm.lookAt(Im,Pm,this.up):Nm.lookAt(Pm,Im,this.up),this.quaternion.setFromRotationMatrix(Nm),i&&(Nm.extractRotation(i.matrixWorld),Cm.setFromRotationMatrix(Nm),this.quaternion.premultiply(Cm.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(Bm),km.child=t,this.dispatchEvent(km),km.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(zm),Gm.child=t,this.dispatchEvent(Gm),Gm.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),Nm.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),Nm.multiply(t.parent.matrixWorld)),t.applyMatrix4(Nm),t.removeFromParent(),t.parent=this,this.children.push(t),t.updateWorldMatrix(!1,!0),t.dispatchEvent(Bm),km.child=t,this.dispatchEvent(km),km.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 n=0,i=this.children.length;n<i;n++){const i=this.children[n].getObjectByProperty(t,e);if(void 0!==i)return i}}getObjectsByProperty(t,e,n=[]){this[t]===e&&n.push(this);const i=this.children;for(let r=0,s=i.length;r<s;r++)i[r].getObjectsByProperty(t,e,n);return n}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Im,t,Lm),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Im,Um,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 n=0,i=e.length;n<i;n++)e[n].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let n=0,i=e.length;n<i;n++)e[n].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 n=0,i=e.length;n<i;n++){e[n].updateMatrixWorld(t)}}updateWorldMatrix(t,e){const n=this.parent;if(!0===t&&null!==n&&n.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,n=t.length;e<n;e++){t[e].updateWorldMatrix(!1,!0)}}}toJSON(t){const e=void 0===t||"string"==typeof t,n={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const i={};function r(e,n){return void 0===e[n.uuid]&&(e[n.uuid]=n.toJSON(t)),n.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 n=e.shapes;if(Array.isArray(n))for(let e=0,i=n.length;e<i;e++){const i=n[e];r(t.shapes,i)}else r(t.shapes,n)}}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 n=0,i=this.material.length;n<i;n++)e.push(r(t.materials,this.material[n]));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 n=this.animations[e];i.animations.push(r(t.animations,n))}}if(e){const e=s(t.geometries),i=s(t.materials),r=s(t.textures),a=s(t.images),o=s(t.shapes),l=s(t.skeletons),h=s(t.animations),u=s(t.nodes);e.length>0&&(n.geometries=e),i.length>0&&(n.materials=i),r.length>0&&(n.textures=r),a.length>0&&(n.images=a),o.length>0&&(n.shapes=o),l.length>0&&(n.skeletons=l),h.length>0&&(n.animations=h),u.length>0&&(n.nodes=u)}return n.object=i,n;function s(t){const e=[];for(const n in t){const i=t[n];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 n=t.children[e];this.add(n.clone())}return this}}Vm.DEFAULT_UP=new zf(0,1,0),Vm.DEFAULT_MATRIX_AUTO_UPDATE=!0,Vm.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const Hm=new zf,jm=new zf,Wm=new zf,qm=new zf,Xm=new zf,$m=new zf,Ym=new zf,Km=new zf,Zm=new zf,Qm=new zf,Jm=new Uf,tg=new Uf,eg=new Uf;class ng{constructor(t=new zf,e=new zf,n=new zf){this.a=t,this.b=e,this.c=n}static getNormal(t,e,n,i){i.subVectors(n,e),Hm.subVectors(t,e),i.cross(Hm);const r=i.lengthSq();return r>0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,n,i,r){Hm.subVectors(i,e),jm.subVectors(n,e),Wm.subVectors(t,e);const s=Hm.dot(Hm),a=Hm.dot(jm),o=Hm.dot(Wm),l=jm.dot(jm),h=jm.dot(Wm),u=s*l-a*a;if(0===u)return r.set(0,0,0),null;const c=1/u,d=(l*o-a*h)*c,p=(s*h-a*o)*c;return r.set(1-d-p,p,d)}static containsPoint(t,e,n,i){return null!==this.getBarycoord(t,e,n,i,qm)&&(qm.x>=0&&qm.y>=0&&qm.x+qm.y<=1)}static getInterpolation(t,e,n,i,r,s,a,o){return null===this.getBarycoord(t,e,n,i,qm)?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(r,qm.x),o.addScaledVector(s,qm.y),o.addScaledVector(a,qm.z),o)}static getInterpolatedAttribute(t,e,n,i,r,s){return Jm.setScalar(0),tg.setScalar(0),eg.setScalar(0),Jm.fromBufferAttribute(t,e),tg.fromBufferAttribute(t,n),eg.fromBufferAttribute(t,i),s.setScalar(0),s.addScaledVector(Jm,r.x),s.addScaledVector(tg,r.y),s.addScaledVector(eg,r.z),s}static isFrontFacing(t,e,n,i){return Hm.subVectors(n,e),jm.subVectors(t,e),Hm.cross(jm).dot(i)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,i){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,n,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),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 Hm.subVectors(this.c,this.b),jm.subVectors(this.a,this.b),.5*Hm.cross(jm).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return ng.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return ng.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,i,r){return ng.getInterpolation(t,this.a,this.b,this.c,e,n,i,r)}containsPoint(t){return ng.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return ng.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const n=this.a,i=this.b,r=this.c;let s,a;Xm.subVectors(i,n),$m.subVectors(r,n),Km.subVectors(t,n);const o=Xm.dot(Km),l=$m.dot(Km);if(o<=0&&l<=0)return e.copy(n);Zm.subVectors(t,i);const h=Xm.dot(Zm),u=$m.dot(Zm);if(h>=0&&u<=h)return e.copy(i);const c=o*u-h*l;if(c<=0&&o>=0&&h<=0)return s=o/(o-h),e.copy(n).addScaledVector(Xm,s);Qm.subVectors(t,r);const d=Xm.dot(Qm),p=$m.dot(Qm);if(p>=0&&d<=p)return e.copy(r);const f=d*l-o*p;if(f<=0&&l>=0&&p<=0)return a=l/(l-p),e.copy(n).addScaledVector($m,a);const m=h*p-d*u;if(m<=0&&u-h>=0&&d-p>=0)return Ym.subVectors(r,i),a=(u-h)/(u-h+(d-p)),e.copy(i).addScaledVector(Ym,a);const g=1/(m+f+c);return s=f*g,a=c*g,e.copy(n).addScaledVector(Xm,s).addScaledVector($m,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const ig={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},rg={h:0,s:0,l:0},sg={h:0,s:0,l:0};function ag(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+6*(e-t)*(2/3-n):t}class og{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(void 0===e&&void 0===n){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,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Bp){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,yf.toWorkingColorSpace(this,e),this}setRGB(t,e,n,i=yf.workingColorSpace){return this.r=t,this.g=e,this.b=n,yf.toWorkingColorSpace(this,i),this}setHSL(t,e,n,i=yf.workingColorSpace){if(t=hf(t,1),e=lf(e,0,1),n=lf(n,0,1),0===e)this.r=this.g=this.b=n;else{const i=n<=.5?n*(1+e):n+e-n*e,r=2*n-i;this.r=ag(r,i,t+1/3),this.g=ag(r,i,t),this.b=ag(r,i,t-1/3)}return yf.toWorkingColorSpace(this,i),this}setStyle(t,e=Bp){function n(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 s=i[1],a=i[2];switch(s){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(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(a))return n(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(a))return n(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 n=i[1],r=n.length;if(3===r)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(n,16),e);console.warn("THREE.Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Bp){const n=ig[t.toLowerCase()];return void 0!==n?this.setHex(n,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=xf(t.r),this.g=xf(t.g),this.b=xf(t.b),this}copyLinearToSRGB(t){return this.r=bf(t.r),this.g=bf(t.g),this.b=bf(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Bp){return yf.fromWorkingColorSpace(lg.copy(this),t),65536*Math.round(lf(255*lg.r,0,255))+256*Math.round(lf(255*lg.g,0,255))+Math.round(lf(255*lg.b,0,255))}getHexString(t=Bp){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=yf.workingColorSpace){yf.fromWorkingColorSpace(lg.copy(this),e);const n=lg.r,i=lg.g,r=lg.b,s=Math.max(n,i,r),a=Math.min(n,i,r);let o,l;const h=(a+s)/2;if(a===s)o=0,l=0;else{const t=s-a;switch(l=h<=.5?t/(s+a):t/(2-s-a),s){case n:o=(i-r)/t+(i<r?6:0);break;case i:o=(r-n)/t+2;break;case r:o=(n-i)/t+4}o/=6}return t.h=o,t.s=l,t.l=h,t}getRGB(t,e=yf.workingColorSpace){return yf.fromWorkingColorSpace(lg.copy(this),e),t.r=lg.r,t.g=lg.g,t.b=lg.b,t}getStyle(t=Bp){yf.fromWorkingColorSpace(lg.copy(this),t);const e=lg.r,n=lg.g,i=lg.b;return t!==Bp?`color(${t} ${e.toFixed(3)} ${n.toFixed(3)} ${i.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*n)},${Math.round(255*i)})`}offsetHSL(t,e,n){return this.getHSL(rg),this.setHSL(rg.h+t,rg.s+e,rg.l+n)}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,n){return this.r=t.r+(e.r-t.r)*n,this.g=t.g+(e.g-t.g)*n,this.b=t.b+(e.b-t.b)*n,this}lerpHSL(t,e){this.getHSL(rg),t.getHSL(sg);const n=uf(rg.h,sg.h,e),i=uf(rg.s,sg.s,e),r=uf(rg.l,sg.l,e);return this.setHSL(n,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,n=this.g,i=this.b,r=t.elements;return this.r=r[0]*e+r[3]*n+r[6]*i,this.g=r[1]*e+r[4]*n+r[7]*i,this.b=r[2]*e+r[5]*n+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 lg=new og;og.NAMES=ig;let hg=0;class ug extends ef{static get type(){return"Material"}get type(){return this.constructor.type}set type(t){}constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:hg++}),this.uuid=of(),this.name="",this.blending=1,this.side=0,this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc=Id,this.blendDst=Ld,this.blendEquation=wd,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new og(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Vp,this.stencilZFail=Vp,this.stencilZPass=Vp,this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const n=t[e];if(void 0===n){console.warn(`THREE.Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(n):i&&i.isVector3&&n&&n.isVector3?i.copy(n):this[e]=n: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 n={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}if(n.uuid=this.uuid,n.type=this.type,""!==this.name&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),void 0!==this.roughness&&(n.roughness=this.roughness),void 0!==this.metalness&&(n.metalness=this.metalness),void 0!==this.sheen&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(n.shininess=this.shininess),void 0!==this.clearcoat&&(n.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.dispersion&&(n.dispersion=this.dispersion),void 0!==this.iridescence&&(n.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(n.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(n.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(n.combine=this.combine)),void 0!==this.envMapRotation&&(n.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(n.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(n.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(n.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(n.size=this.size),null!==this.shadowSide&&(n.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(n.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(n.blending=this.blending),0!==this.side&&(n.side=this.side),!0===this.vertexColors&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),!0===this.transparent&&(n.transparent=!0),this.blendSrc!==Id&&(n.blendSrc=this.blendSrc),this.blendDst!==Ld&&(n.blendDst=this.blendDst),this.blendEquation!==wd&&(n.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(n.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(n.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(n.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(n.depthFunc=this.depthFunc),!1===this.depthTest&&(n.depthTest=this.depthTest),!1===this.depthWrite&&(n.depthWrite=this.depthWrite),!1===this.colorWrite&&(n.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(n.stencilWriteMask=this.stencilWriteMask),519!==this.stencilFunc&&(n.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(n.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==Vp&&(n.stencilFail=this.stencilFail),this.stencilZFail!==Vp&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==Vp&&(n.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(n.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(n.rotation=this.rotation),!0===this.polygonOffset&&(n.polygonOffset=!0),0!==this.polygonOffsetFactor&&(n.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(n.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(n.linewidth=this.linewidth),void 0!==this.dashSize&&(n.dashSize=this.dashSize),void 0!==this.gapSize&&(n.gapSize=this.gapSize),void 0!==this.scale&&(n.scale=this.scale),!0===this.dithering&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),!0===this.alphaHash&&(n.alphaHash=!0),!0===this.alphaToCoverage&&(n.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(n.premultipliedAlpha=!0),!0===this.forceSinglePass&&(n.forceSinglePass=!0),!0===this.wireframe&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(n.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(n.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(n.flatShading=!0),!1===this.visible&&(n.visible=!1),!1===this.toneMapped&&(n.toneMapped=!1),!1===this.fog&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(n.textures=e),r.length>0&&(n.images=r)}return n}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 n=null;if(null!==e){const t=e.length;n=new Array(t);for(let i=0;i!==t;++i)n[i]=e[i].clone()}return this.clippingPlanes=n,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.")}}class cg extends ug{static get type(){return"MeshBasicMaterial"}constructor(t){super(),this.isMeshBasicMaterial=!0,this.color=new og(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 wm,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 dg=pg();function pg(){const t=new ArrayBuffer(4),e=new Float32Array(t),n=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 s=new Uint32Array(2048),a=new Uint32Array(64),o=new Uint32Array(64);for(let t=1;t<1024;++t){let e=t<<13,n=0;for(;!(8388608&e);)e<<=1,n-=8388608;e&=-8388609,n+=947912704,s[t]=e|n}for(let t=1024;t<2048;++t)s[t]=939524096+(t-1024<<13);for(let t=1;t<31;++t)a[t]=t<<23;a[31]=1199570944,a[32]=2147483648;for(let t=33;t<63;++t)a[t]=2147483648+(t-32<<23);a[63]=3347054592;for(let t=1;t<64;++t)32!==t&&(o[t]=1024);return{floatView:e,uint32View:n,baseTable:i,shiftTable:r,mantissaTable:s,exponentTable:a,offsetTable:o}}function fg(t){Math.abs(t)>65504&&console.warn("THREE.DataUtils.toHalfFloat(): Value out of range."),t=lf(t,-65504,65504),dg.floatView[0]=t;const e=dg.uint32View[0],n=e>>23&511;return dg.baseTable[n]+((8388607&e)>>dg.shiftTable[n])}function mg(t){const e=t>>10;return dg.uint32View[0]=dg.mantissaTable[dg.offsetTable[e]+(1023&t)]+dg.exponentTable[e],dg.floatView[0]}const gg=new zf,_g=new ff;class vg{constructor(t,e,n=!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=n,this.usage=Zp,this.updateRanges=[],this.gpuType=rp,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let i=0,r=this.itemSize;i<r;i++)this.array[t+i]=e.array[n+i];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,n=this.count;e<n;e++)_g.fromBufferAttribute(this,e),_g.applyMatrix3(t),this.setXY(e,_g.x,_g.y);else if(3===this.itemSize)for(let e=0,n=this.count;e<n;e++)gg.fromBufferAttribute(this,e),gg.applyMatrix3(t),this.setXYZ(e,gg.x,gg.y,gg.z);return this}applyMatrix4(t){for(let e=0,n=this.count;e<n;e++)gg.fromBufferAttribute(this,e),gg.applyMatrix4(t),this.setXYZ(e,gg.x,gg.y,gg.z);return this}applyNormalMatrix(t){for(let e=0,n=this.count;e<n;e++)gg.fromBufferAttribute(this,e),gg.applyNormalMatrix(t),this.setXYZ(e,gg.x,gg.y,gg.z);return this}transformDirection(t){for(let e=0,n=this.count;e<n;e++)gg.fromBufferAttribute(this,e),gg.transformDirection(t),this.setXYZ(e,gg.x,gg.y,gg.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let n=this.array[t*this.itemSize+e];return this.normalized&&(n=cf(n,this.array)),n}setComponent(t,e,n){return this.normalized&&(n=df(n,this.array)),this.array[t*this.itemSize+e]=n,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=cf(e,this.array)),e}setX(t,e){return this.normalized&&(e=df(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=cf(e,this.array)),e}setY(t,e){return this.normalized&&(e=df(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=cf(e,this.array)),e}setZ(t,e){return this.normalized&&(e=df(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=cf(e,this.array)),e}setW(t,e){return this.normalized&&(e=df(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,n){return t*=this.itemSize,this.normalized&&(e=df(e,this.array),n=df(n,this.array)),this.array[t+0]=e,this.array[t+1]=n,this}setXYZ(t,e,n,i){return t*=this.itemSize,this.normalized&&(e=df(e,this.array),n=df(n,this.array),i=df(i,this.array)),this.array[t+0]=e,this.array[t+1]=n,this.array[t+2]=i,this}setXYZW(t,e,n,i,r){return t*=this.itemSize,this.normalized&&(e=df(e,this.array),n=df(n,this.array),i=df(i,this.array),r=df(r,this.array)),this.array[t+0]=e,this.array[t+1]=n,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!==Zp&&(t.usage=this.usage),t}}class yg extends vg{constructor(t,e,n){super(new Uint16Array(t),e,n)}}class xg extends vg{constructor(t,e,n){super(new Uint32Array(t),e,n)}}class bg extends vg{constructor(t,e,n){super(new Uint16Array(t),e,n),this.isFloat16BufferAttribute=!0}getX(t){let e=mg(this.array[t*this.itemSize]);return this.normalized&&(e=cf(e,this.array)),e}setX(t,e){return this.normalized&&(e=df(e,this.array)),this.array[t*this.itemSize]=fg(e),this}getY(t){let e=mg(this.array[t*this.itemSize+1]);return this.normalized&&(e=cf(e,this.array)),e}setY(t,e){return this.normalized&&(e=df(e,this.array)),this.array[t*this.itemSize+1]=fg(e),this}getZ(t){let e=mg(this.array[t*this.itemSize+2]);return this.normalized&&(e=cf(e,this.array)),e}setZ(t,e){return this.normalized&&(e=df(e,this.array)),this.array[t*this.itemSize+2]=fg(e),this}getW(t){let e=mg(this.array[t*this.itemSize+3]);return this.normalized&&(e=cf(e,this.array)),e}setW(t,e){return this.normalized&&(e=df(e,this.array)),this.array[t*this.itemSize+3]=fg(e),this}setXY(t,e,n){return t*=this.itemSize,this.normalized&&(e=df(e,this.array),n=df(n,this.array)),this.array[t+0]=fg(e),this.array[t+1]=fg(n),this}setXYZ(t,e,n,i){return t*=this.itemSize,this.normalized&&(e=df(e,this.array),n=df(n,this.array),i=df(i,this.array)),this.array[t+0]=fg(e),this.array[t+1]=fg(n),this.array[t+2]=fg(i),this}setXYZW(t,e,n,i,r){return t*=this.itemSize,this.normalized&&(e=df(e,this.array),n=df(n,this.array),i=df(i,this.array),r=df(r,this.array)),this.array[t+0]=fg(e),this.array[t+1]=fg(n),this.array[t+2]=fg(i),this.array[t+3]=fg(r),this}}class Sg extends vg{constructor(t,e,n){super(new Float32Array(t),e,n)}}let Mg=0;const Tg=new mm,wg=new Vm,Eg=new zf,Ag=new Vf,Rg=new Vf,Cg=new zf;class Ng extends ef{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:Mg++}),this.uuid=of(),this.name="",this.type="BufferGeometry",this.index=null,this.indirect=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(function(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}(t)?xg:yg)(t,1):this.index=t,this}setIndirect(t){return this.indirect=t,this}getIndirect(){return this.indirect}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,n=0){this.groups.push({start:t,count:e,materialIndex:n})}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 n=this.attributes.normal;if(void 0!==n){const e=(new mf).getNormalMatrix(t);n.applyNormalMatrix(e),n.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 Tg.makeRotationFromQuaternion(t),this.applyMatrix4(Tg),this}rotateX(t){return Tg.makeRotationX(t),this.applyMatrix4(Tg),this}rotateY(t){return Tg.makeRotationY(t),this.applyMatrix4(Tg),this}rotateZ(t){return Tg.makeRotationZ(t),this.applyMatrix4(Tg),this}translate(t,e,n){return Tg.makeTranslation(t,e,n),this.applyMatrix4(Tg),this}scale(t,e,n){return Tg.makeScale(t,e,n),this.applyMatrix4(Tg),this}lookAt(t){return wg.lookAt(t),wg.updateMatrix(),this.applyMatrix4(wg.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Eg).negate(),this.translate(Eg.x,Eg.y,Eg.z),this}setFromPoints(t){const e=this.getAttribute("position");if(void 0===e){const e=[];for(let n=0,i=t.length;n<i;n++){const i=t[n];e.push(i.x,i.y,i.z||0)}this.setAttribute("position",new Sg(e,3))}else{for(let n=0,i=e.count;n<i;n++){const i=t[n];e.setXYZ(n,i.x,i.y,i.z||0)}t.length>e.count&&console.warn("THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new Vf);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 zf(-1/0,-1/0,-1/0),new zf(1/0,1/0,1/0));if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,n=e.length;t<n;t++){const n=e[t];Ag.setFromBufferAttribute(n),this.morphTargetsRelative?(Cg.addVectors(this.boundingBox.min,Ag.min),this.boundingBox.expandByPoint(Cg),Cg.addVectors(this.boundingBox.max,Ag.max),this.boundingBox.expandByPoint(Cg)):(this.boundingBox.expandByPoint(Ag.min),this.boundingBox.expandByPoint(Ag.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 am);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 zf,1/0);if(t){const n=this.boundingSphere.center;if(Ag.setFromBufferAttribute(t),e)for(let t=0,n=e.length;t<n;t++){const n=e[t];Rg.setFromBufferAttribute(n),this.morphTargetsRelative?(Cg.addVectors(Ag.min,Rg.min),Ag.expandByPoint(Cg),Cg.addVectors(Ag.max,Rg.max),Ag.expandByPoint(Cg)):(Ag.expandByPoint(Rg.min),Ag.expandByPoint(Rg.max))}Ag.getCenter(n);let i=0;for(let e=0,r=t.count;e<r;e++)Cg.fromBufferAttribute(t,e),i=Math.max(i,n.distanceToSquared(Cg));if(e)for(let r=0,s=e.length;r<s;r++){const s=e[r],a=this.morphTargetsRelative;for(let e=0,r=s.count;e<r;e++)Cg.fromBufferAttribute(s,e),a&&(Eg.fromBufferAttribute(t,e),Cg.add(Eg)),i=Math.max(i,n.distanceToSquared(Cg))}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 n=e.position,i=e.normal,r=e.uv;!1===this.hasAttribute("tangent")&&this.setAttribute("tangent",new vg(new Float32Array(4*n.count),4));const s=this.getAttribute("tangent"),a=[],o=[];for(let t=0;t<n.count;t++)a[t]=new zf,o[t]=new zf;const l=new zf,h=new zf,u=new zf,c=new ff,d=new ff,p=new ff,f=new zf,m=new zf;function g(t,e,i){l.fromBufferAttribute(n,t),h.fromBufferAttribute(n,e),u.fromBufferAttribute(n,i),c.fromBufferAttribute(r,t),d.fromBufferAttribute(r,e),p.fromBufferAttribute(r,i),h.sub(l),u.sub(l),d.sub(c),p.sub(c);const s=1/(d.x*p.y-p.x*d.y);isFinite(s)&&(f.copy(h).multiplyScalar(p.y).addScaledVector(u,-d.y).multiplyScalar(s),m.copy(u).multiplyScalar(d.x).addScaledVector(h,-p.x).multiplyScalar(s),a[t].add(f),a[e].add(f),a[i].add(f),o[t].add(m),o[e].add(m),o[i].add(m))}let _=this.groups;0===_.length&&(_=[{start:0,count:t.count}]);for(let e=0,n=_.length;e<n;++e){const n=_[e],i=n.start;for(let e=i,r=i+n.count;e<r;e+=3)g(t.getX(e+0),t.getX(e+1),t.getX(e+2))}const v=new zf,y=new zf,x=new zf,b=new zf;function S(t){x.fromBufferAttribute(i,t),b.copy(x);const e=a[t];v.copy(e),v.sub(x.multiplyScalar(x.dot(e))).normalize(),y.crossVectors(b,e);const n=y.dot(o[t])<0?-1:1;s.setXYZW(t,v.x,v.y,v.z,n)}for(let e=0,n=_.length;e<n;++e){const n=_[e],i=n.start;for(let e=i,r=i+n.count;e<r;e+=3)S(t.getX(e+0)),S(t.getX(e+1)),S(t.getX(e+2))}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let n=this.getAttribute("normal");if(void 0===n)n=new vg(new Float32Array(3*e.count),3),this.setAttribute("normal",n);else for(let t=0,e=n.count;t<e;t++)n.setXYZ(t,0,0,0);const i=new zf,r=new zf,s=new zf,a=new zf,o=new zf,l=new zf,h=new zf,u=new zf;if(t)for(let c=0,d=t.count;c<d;c+=3){const d=t.getX(c+0),p=t.getX(c+1),f=t.getX(c+2);i.fromBufferAttribute(e,d),r.fromBufferAttribute(e,p),s.fromBufferAttribute(e,f),h.subVectors(s,r),u.subVectors(i,r),h.cross(u),a.fromBufferAttribute(n,d),o.fromBufferAttribute(n,p),l.fromBufferAttribute(n,f),a.add(h),o.add(h),l.add(h),n.setXYZ(d,a.x,a.y,a.z),n.setXYZ(p,o.x,o.y,o.z),n.setXYZ(f,l.x,l.y,l.z)}else for(let t=0,a=e.count;t<a;t+=3)i.fromBufferAttribute(e,t+0),r.fromBufferAttribute(e,t+1),s.fromBufferAttribute(e,t+2),h.subVectors(s,r),u.subVectors(i,r),h.cross(u),n.setXYZ(t+0,h.x,h.y,h.z),n.setXYZ(t+1,h.x,h.y,h.z),n.setXYZ(t+2,h.x,h.y,h.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,n=t.count;e<n;e++)Cg.fromBufferAttribute(t,e),Cg.normalize(),t.setXYZ(e,Cg.x,Cg.y,Cg.z)}toNonIndexed(){function t(t,e){const n=t.array,i=t.itemSize,r=t.normalized,s=new n.constructor(e.length*i);let a=0,o=0;for(let r=0,l=e.length;r<l;r++){a=t.isInterleavedBufferAttribute?e[r]*t.data.stride+t.offset:e[r]*i;for(let t=0;t<i;t++)s[o++]=n[a++]}return new vg(s,i,r)}if(null===this.index)return console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."),this;const e=new Ng,n=this.index.array,i=this.attributes;for(const r in i){const s=t(i[r],n);e.setAttribute(r,s)}const r=this.morphAttributes;for(const i in r){const s=[],a=r[i];for(let e=0,i=a.length;e<i;e++){const i=t(a[e],n);s.push(i)}e.morphAttributes[i]=s}e.morphTargetsRelative=this.morphTargetsRelative;const s=this.groups;for(let t=0,n=s.length;t<n;t++){const n=s[t];e.addGroup(n.start,n.count,n.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 n in e)void 0!==e[n]&&(t[n]=e[n]);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 n=this.attributes;for(const e in n){const i=n[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let r=!1;for(const e in this.morphAttributes){const n=this.morphAttributes[e],s=[];for(let e=0,i=n.length;e<i;e++){const i=n[e];s.push(i.toJSON(t.data))}s.length>0&&(i[e]=s,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const s=this.groups;s.length>0&&(t.data.groups=JSON.parse(JSON.stringify(s)));const a=this.boundingSphere;return null!==a&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const n=t.index;null!==n&&this.setIndex(n.clone(e));const i=t.attributes;for(const t in i){const n=i[t];this.setAttribute(t,n.clone(e))}const r=t.morphAttributes;for(const t in r){const n=[],i=r[t];for(let t=0,r=i.length;t<r;t++)n.push(i[t].clone(e));this.morphAttributes[t]=n}this.morphTargetsRelative=t.morphTargetsRelative;const s=t.groups;for(let t=0,e=s.length;t<e;t++){const e=s[t];this.addGroup(e.start,e.count,e.materialIndex)}const a=t.boundingBox;null!==a&&(this.boundingBox=a.clone());const o=t.boundingSphere;return null!==o&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}}const Pg=new mm,Ig=new fm,Lg=new am,Ug=new zf,Dg=new zf,Og=new zf,Fg=new zf,Bg=new zf,zg=new zf,kg=new zf,Gg=new zf;class Vg extends Vm{constructor(t=new Ng,e=new cg){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 n=t[e[0]];if(void 0!==n){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=n.length;t<e;t++){const e=n[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}getVertexPosition(t,e){const n=this.geometry,i=n.attributes.position,r=n.morphAttributes.position,s=n.morphTargetsRelative;e.fromBufferAttribute(i,t);const a=this.morphTargetInfluences;if(r&&a){zg.set(0,0,0);for(let n=0,i=r.length;n<i;n++){const i=a[n],o=r[n];0!==i&&(Bg.fromBufferAttribute(o,t),s?zg.addScaledVector(Bg,i):zg.addScaledVector(Bg.sub(e),i))}e.add(zg)}return e}raycast(t,e){const n=this.geometry,i=this.material,r=this.matrixWorld;if(void 0!==i){if(null===n.boundingSphere&&n.computeBoundingSphere(),Lg.copy(n.boundingSphere),Lg.applyMatrix4(r),Ig.copy(t.ray).recast(t.near),!1===Lg.containsPoint(Ig.origin)){if(null===Ig.intersectSphere(Lg,Ug))return;if(Ig.origin.distanceToSquared(Ug)>(t.far-t.near)**2)return}Pg.copy(r).invert(),Ig.copy(t.ray).applyMatrix4(Pg),null!==n.boundingBox&&!1===Ig.intersectsBox(n.boundingBox)||this._computeIntersections(t,e,Ig)}}_computeIntersections(t,e,n){let i;const r=this.geometry,s=this.material,a=r.index,o=r.attributes.position,l=r.attributes.uv,h=r.attributes.uv1,u=r.attributes.normal,c=r.groups,d=r.drawRange;if(null!==a)if(Array.isArray(s))for(let r=0,o=c.length;r<o;r++){const o=c[r],p=s[o.materialIndex];for(let r=Math.max(o.start,d.start),s=Math.min(a.count,Math.min(o.start+o.count,d.start+d.count));r<s;r+=3){i=Hg(this,p,t,n,l,h,u,a.getX(r),a.getX(r+1),a.getX(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=Hg(this,s,t,n,l,h,u,a.getX(r),a.getX(r+1),a.getX(r+2)),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}else if(void 0!==o)if(Array.isArray(s))for(let r=0,a=c.length;r<a;r++){const a=c[r],p=s[a.materialIndex];for(let r=Math.max(a.start,d.start),s=Math.min(o.count,Math.min(a.start+a.count,d.start+d.count));r<s;r+=3){i=Hg(this,p,t,n,l,h,u,r,r+1,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=Hg(this,s,t,n,l,h,u,r,r+1,r+2),i&&(i.faceIndex=Math.floor(r/3),e.push(i))}}}}function Hg(t,e,n,i,r,s,a,o,l,h){t.getVertexPosition(o,Dg),t.getVertexPosition(l,Og),t.getVertexPosition(h,Fg);const u=function(t,e,n,i,r,s,a,o){let l;if(l=1===e.side?i.intersectTriangle(a,s,r,!0,o):i.intersectTriangle(r,s,a,0===e.side,o),null===l)return null;Gg.copy(o),Gg.applyMatrix4(t.matrixWorld);const h=n.ray.origin.distanceTo(Gg);return h<n.near||h>n.far?null:{distance:h,point:Gg.clone(),object:t}}(t,e,n,i,Dg,Og,Fg,kg);if(u){const t=new zf;ng.getBarycoord(kg,Dg,Og,Fg,t),r&&(u.uv=ng.getInterpolatedAttribute(r,o,l,h,t,new ff)),s&&(u.uv1=ng.getInterpolatedAttribute(s,o,l,h,t,new ff)),a&&(u.normal=ng.getInterpolatedAttribute(a,o,l,h,t,new zf),u.normal.dot(i.direction)>0&&u.normal.multiplyScalar(-1));const e={a:o,b:l,c:h,normal:new zf,materialIndex:0};ng.getNormal(Dg,Og,Fg,e.normal),u.face=e,u.barycoord=t}return u}class jg extends Ng{constructor(t=1,e=1,n=1,i=1,r=1,s=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:n,widthSegments:i,heightSegments:r,depthSegments:s};const a=this;i=Math.floor(i),r=Math.floor(r),s=Math.floor(s);const o=[],l=[],h=[],u=[];let c=0,d=0;function p(t,e,n,i,r,s,p,f,m,g,_){const v=s/m,y=p/g,x=s/2,b=p/2,S=f/2,M=m+1,T=g+1;let w=0,E=0;const A=new zf;for(let s=0;s<T;s++){const a=s*y-b;for(let o=0;o<M;o++){const c=o*v-x;A[t]=c*i,A[e]=a*r,A[n]=S,l.push(A.x,A.y,A.z),A[t]=0,A[e]=0,A[n]=f>0?1:-1,h.push(A.x,A.y,A.z),u.push(o/m),u.push(1-s/g),w+=1}}for(let t=0;t<g;t++)for(let e=0;e<m;e++){const n=c+e+M*t,i=c+e+M*(t+1),r=c+(e+1)+M*(t+1),s=c+(e+1)+M*t;o.push(n,i,s),o.push(i,r,s),E+=6}a.addGroup(d,E,_),d+=E,c+=w}p("z","y","x",-1,-1,n,e,t,s,r,0),p("z","y","x",1,-1,n,e,-t,s,r,1),p("x","z","y",1,1,t,n,e,i,s,2),p("x","z","y",1,-1,t,n,-e,i,s,3),p("x","y","z",1,-1,t,e,n,i,r,4),p("x","y","z",-1,-1,t,e,-n,i,r,5),this.setIndex(o),this.setAttribute("position",new Sg(l,3)),this.setAttribute("normal",new Sg(h,3)),this.setAttribute("uv",new Sg(u,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new jg(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function Wg(t){const e={};for(const n in t){e[n]={};for(const i in t[n]){const r=t[n][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[n][i]=null):e[n][i]=r.clone():Array.isArray(r)?e[n][i]=r.slice():e[n][i]=r}}return e}class qg extends ug{static get type(){return"ShaderMaterial"}constructor(t){super(),this.isShaderMaterial=!0,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=Wg(t.uniforms),this.uniformsGroups=function(t){const e=[];for(let n=0;n<t.length;n++)e.push(t[n].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 n in this.uniforms){const i=this.uniforms[n].value;i&&i.isTexture?e.uniforms[n]={type:"t",value:i.toJSON(t).uuid}:i&&i.isColor?e.uniforms[n]={type:"c",value:i.getHex()}:i&&i.isVector2?e.uniforms[n]={type:"v2",value:i.toArray()}:i&&i.isVector3?e.uniforms[n]={type:"v3",value:i.toArray()}:i&&i.isVector4?e.uniforms[n]={type:"v4",value:i.toArray()}:i&&i.isMatrix3?e.uniforms[n]={type:"m3",value:i.toArray()}:i&&i.isMatrix4?e.uniforms[n]={type:"m4",value:i.toArray()}:e.uniforms[n]={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 n={};for(const t in this.extensions)!0===this.extensions[t]&&(n[t]=!0);return Object.keys(n).length>0&&(e.extensions=n),e}}class Xg extends Vm{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new mm,this.projectionMatrix=new mm,this.projectionMatrixInverse=new mm,this.coordinateSystem=Jp}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 $g=new zf,Yg=new ff,Kg=new ff;class Zg extends Xg{constructor(t=50,e=1,n=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=n,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*af*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*sf*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*af*Math.atan(Math.tan(.5*sf*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,n){$g.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set($g.x,$g.y).multiplyScalar(-t/$g.z),$g.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set($g.x,$g.y).multiplyScalar(-t/$g.z)}getViewSize(t,e){return this.getViewBounds(t,Yg,Kg),e.subVectors(Kg,Yg)}setViewOffset(t,e,n,i,r,s){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=n,this.view.offsetY=i,this.view.width=r,this.view.height=s,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*sf*this.fov)/this.zoom,n=2*e,i=this.aspect*n,r=-.5*i;const s=this.view;if(null!==this.view&&this.view.enabled){const t=s.fullWidth,a=s.fullHeight;r+=s.offsetX*i/t,e-=s.offsetY*n/a,i*=s.width/t,n*=s.height/a}const a=this.filmOffset;0!==a&&(r+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-n,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 Qg=-90;class Jg extends Vm{constructor(t,e,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new Zg(Qg,1,t,e);i.layers=this.layers,this.add(i);const r=new Zg(Qg,1,t,e);r.layers=this.layers,this.add(r);const s=new Zg(Qg,1,t,e);s.layers=this.layers,this.add(s);const a=new Zg(Qg,1,t,e);a.layers=this.layers,this.add(a);const o=new Zg(Qg,1,t,e);o.layers=this.layers,this.add(o);const l=new Zg(Qg,1,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[n,i,r,s,a,o]=e;for(const t of e)this.remove(t);if(t===Jp)n.up.set(0,1,0),n.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),s.up.set(0,0,1),s.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),o.up.set(0,1,0),o.lookAt(0,0,-1);else{if(t!==tf)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);n.up.set(0,-1,0),n.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),s.up.set(0,0,-1),s.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),o.up.set(0,-1,0),o.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,s,a,o,l,h]=this.children,u=t.getRenderTarget(),c=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const f=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,t.setRenderTarget(n,0,i),t.render(e,r),t.setRenderTarget(n,1,i),t.render(e,s),t.setRenderTarget(n,2,i),t.render(e,a),t.setRenderTarget(n,3,i),t.render(e,o),t.setRenderTarget(n,4,i),t.render(e,l),n.texture.generateMipmaps=f,t.setRenderTarget(n,5,i),t.render(e,h),t.setRenderTarget(u,c,d),t.xr.enabled=p,n.texture.needsPMREMUpdate=!0}}class t_ extends Lf{constructor(t,e,n,i,r,s,a,o,l,h){super(t=void 0!==t?t:[],e=void 0!==e?e:zd,n,i,r,s,a,o,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class e_ extends Of{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const n={width:t,height:t,depth:1},i=[n,n,n,n,n,n];this.texture=new t_(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:Yd}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 n={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 jg(5,5,5),r=new qg({name:"CubemapFromEquirect",uniforms:Wg(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:1,blending:0});r.uniforms.tEquirect.value=e;const s=new Vg(i,r),a=e.minFilter;e.minFilter===Zd&&(e.minFilter=Yd);return new Jg(1,10,this).update(t,s),e.minFilter=a,s.geometry.dispose(),s.material.dispose(),this}clear(t,e,n,i){const r=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,n,i);t.setRenderTarget(r)}}class n_ extends Vm{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 wm,this.environmentIntensity=1,this.environmentRotation=new wm,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 i_{constructor(t,e){this.isInterleavedBuffer=!0,this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=Zp,this.updateRanges=[],this.version=0,this.uuid=of()}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,n){t*=this.stride,n*=e.stride;for(let i=0,r=this.stride;i<r;i++)this.array[t+i]=e.array[n+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=of()),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]),n=new this.constructor(e,this.stride);return n.setUsage(this.usage),n}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=of()),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 r_=new zf;class s_{constructor(t,e,n,i=!1){this.isInterleavedBufferAttribute=!0,this.name="",this.data=t,this.itemSize=e,this.offset=n,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,n=this.data.count;e<n;e++)r_.fromBufferAttribute(this,e),r_.applyMatrix4(t),this.setXYZ(e,r_.x,r_.y,r_.z);return this}applyNormalMatrix(t){for(let e=0,n=this.count;e<n;e++)r_.fromBufferAttribute(this,e),r_.applyNormalMatrix(t),this.setXYZ(e,r_.x,r_.y,r_.z);return this}transformDirection(t){for(let e=0,n=this.count;e<n;e++)r_.fromBufferAttribute(this,e),r_.transformDirection(t),this.setXYZ(e,r_.x,r_.y,r_.z);return this}getComponent(t,e){let n=this.array[t*this.data.stride+this.offset+e];return this.normalized&&(n=cf(n,this.array)),n}setComponent(t,e,n){return this.normalized&&(n=df(n,this.array)),this.data.array[t*this.data.stride+this.offset+e]=n,this}setX(t,e){return this.normalized&&(e=df(e,this.array)),this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.normalized&&(e=df(e,this.array)),this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.normalized&&(e=df(e,this.array)),this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.normalized&&(e=df(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=cf(e,this.array)),e}getY(t){let e=this.data.array[t*this.data.stride+this.offset+1];return this.normalized&&(e=cf(e,this.array)),e}getZ(t){let e=this.data.array[t*this.data.stride+this.offset+2];return this.normalized&&(e=cf(e,this.array)),e}getW(t){let e=this.data.array[t*this.data.stride+this.offset+3];return this.normalized&&(e=cf(e,this.array)),e}setXY(t,e,n){return t=t*this.data.stride+this.offset,this.normalized&&(e=df(e,this.array),n=df(n,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=n,this}setXYZ(t,e,n,i){return t=t*this.data.stride+this.offset,this.normalized&&(e=df(e,this.array),n=df(n,this.array),i=df(i,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=n,this.data.array[t+2]=i,this}setXYZW(t,e,n,i,r){return t=t*this.data.stride+this.offset,this.normalized&&(e=df(e,this.array),n=df(n,this.array),i=df(i,this.array),r=df(r,this.array)),this.data.array[t+0]=e,this.data.array[t+1]=n,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 n=e*this.data.stride+this.offset;for(let e=0;e<this.itemSize;e++)t.push(this.data.array[n+e])}return new vg(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 s_(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 n=e*this.data.stride+this.offset;for(let e=0;e<this.itemSize;e++)t.push(this.data.array[n+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 a_ extends ug{static get type(){return"SpriteMaterial"}constructor(t){super(),this.isSpriteMaterial=!0,this.color=new og(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}}class o_ extends Lf{constructor(t=null,e=1,n=1,i,r,s,a,o,l=1003,h=1003,u,c){super(null,s,a,o,l,h,i,r,u,c),this.isDataTexture=!0,this.image={data:t,width:e,height:n},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class l_ extends vg{constructor(t,e,n,i=1){super(t,e,n),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 h_=new zf,u_=new zf,c_=new mf;class d_{constructor(t=new zf(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,n,i){return this.normal.set(t,e,n),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){const i=h_.subVectors(n,e).cross(u_.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 n=t.delta(h_),i=this.normal.dot(n);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(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<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 n=e||c_.getNormalMatrix(t),i=this.coplanarPoint(h_).applyMatrix4(t),r=this.normal.applyMatrix3(n).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 p_=new am,f_=new zf;class m_{constructor(t=new d_,e=new d_,n=new d_,i=new d_,r=new d_,s=new d_){this.planes=[t,e,n,i,r,s]}set(t,e,n,i,r,s){const a=this.planes;return a[0].copy(t),a[1].copy(e),a[2].copy(n),a[3].copy(i),a[4].copy(r),a[5].copy(s),this}copy(t){const e=this.planes;for(let n=0;n<6;n++)e[n].copy(t.planes[n]);return this}setFromProjectionMatrix(t,e=2e3){const n=this.planes,i=t.elements,r=i[0],s=i[1],a=i[2],o=i[3],l=i[4],h=i[5],u=i[6],c=i[7],d=i[8],p=i[9],f=i[10],m=i[11],g=i[12],_=i[13],v=i[14],y=i[15];if(n[0].setComponents(o-r,c-l,m-d,y-g).normalize(),n[1].setComponents(o+r,c+l,m+d,y+g).normalize(),n[2].setComponents(o+s,c+h,m+p,y+_).normalize(),n[3].setComponents(o-s,c-h,m-p,y-_).normalize(),n[4].setComponents(o-a,c-u,m-f,y-v).normalize(),e===Jp)n[5].setComponents(o+a,c+u,m+f,y+v).normalize();else{if(e!==tf)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);n[5].setComponents(a,u,f,v).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),p_.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),p_.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(p_)}intersectsSprite(t){return p_.center.set(0,0,0),p_.radius=.7071067811865476,p_.applyMatrix4(t.matrixWorld),this.intersectsSphere(p_)}intersectsSphere(t){const e=this.planes,n=t.center,i=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(n)<i)return!1}return!0}intersectsBox(t){const e=this.planes;for(let n=0;n<6;n++){const i=e[n];if(f_.x=i.normal.x>0?t.max.x:t.min.x,f_.y=i.normal.y>0?t.max.y:t.min.y,f_.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(f_)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let n=0;n<6;n++)if(e[n].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}class g_ extends ug{static get type(){return"LineBasicMaterial"}constructor(t){super(),this.isLineBasicMaterial=!0,this.color=new og(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}}class __ extends ug{static get type(){return"PointsMaterial"}constructor(t){super(),this.isPointsMaterial=!0,this.color=new og(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}}class v_ extends Lf{constructor(t,e){super({width:t,height:e}),this.isFramebufferTexture=!0,this.magFilter=qd,this.minFilter=qd,this.generateMipmaps=!1,this.needsUpdate=!0}}class y_ extends Lf{constructor(t,e,n,i,r,s,a,o,l,h=1026){if(h!==hp&&h!==up)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===n&&h===hp&&(n=ip),void 0===n&&h===up&&(n=ap),super(null,i,r,s,a,o,h,n,l),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=void 0!==a?a:qd,this.minFilter=void 0!==o?o:qd,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 x_ extends Ng{constructor(t=1,e=32,n=16,i=0,r=2*Math.PI,s=0,a=Math.PI){super(),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:n,phiStart:i,phiLength:r,thetaStart:s,thetaLength:a},e=Math.max(3,Math.floor(e)),n=Math.max(2,Math.floor(n));const o=Math.min(s+a,Math.PI);let l=0;const h=[],u=new zf,c=new zf,d=[],p=[],f=[],m=[];for(let d=0;d<=n;d++){const g=[],_=d/n;let v=0;0===d&&0===s?v=.5/e:d===n&&o===Math.PI&&(v=-.5/e);for(let n=0;n<=e;n++){const o=n/e;u.x=-t*Math.cos(i+o*r)*Math.sin(s+_*a),u.y=t*Math.cos(s+_*a),u.z=t*Math.sin(i+o*r)*Math.sin(s+_*a),p.push(u.x,u.y,u.z),c.copy(u).normalize(),f.push(c.x,c.y,c.z),m.push(o+v,1-_),g.push(l++)}h.push(g)}for(let t=0;t<n;t++)for(let i=0;i<e;i++){const e=h[t][i+1],r=h[t][i],a=h[t+1][i],l=h[t+1][i+1];(0!==t||s>0)&&d.push(e,r,l),(t!==n-1||o<Math.PI)&&d.push(r,a,l)}this.setIndex(d),this.setAttribute("position",new Sg(p,3)),this.setAttribute("normal",new Sg(f,3)),this.setAttribute("uv",new Sg(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new x_(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}}class b_ extends ug{static get type(){return"ShadowMaterial"}constructor(t){super(),this.isShadowMaterial=!0,this.color=new og(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 S_ extends ug{static get type(){return"MeshStandardMaterial"}constructor(t){super(),this.isMeshStandardMaterial=!0,this.defines={STANDARD:""},this.color=new og(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 og(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ff(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 wm,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 M_ extends S_{static get type(){return"MeshPhysicalMaterial"}constructor(t){super(),this.isMeshPhysicalMaterial=!0,this.defines={STANDARD:"",PHYSICAL:""},this.anisotropyRotation=0,this.anisotropyMap=null,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new ff(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return lf(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 og(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 og(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new og(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 T_ extends ug{static get type(){return"MeshPhongMaterial"}constructor(t){super(),this.isMeshPhongMaterial=!0,this.color=new og(16777215),this.specular=new og(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new og(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ff(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new wm,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 w_ extends ug{static get type(){return"MeshToonMaterial"}constructor(t){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.color=new og(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new og(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ff(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 E_ extends ug{static get type(){return"MeshNormalMaterial"}constructor(t){super(),this.isMeshNormalMaterial=!0,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ff(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 A_ extends ug{static get type(){return"MeshLambertMaterial"}constructor(t){super(),this.isMeshLambertMaterial=!0,this.color=new og(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new og(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ff(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new wm,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 R_ extends ug{static get type(){return"MeshMatcapMaterial"}constructor(t){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.color=new og(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new ff(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 C_ extends g_{static get type(){return"LineDashedMaterial"}constructor(t){super(),this.isLineDashedMaterial=!0,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}}class N_ extends Vm{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new og(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 P_ extends N_{constructor(t,e,n){super(t,n),this.isHemisphereLight=!0,this.type="HemisphereLight",this.position.copy(Vm.DEFAULT_UP),this.updateMatrix(),this.groundColor=new og(e)}copy(t,e){return super.copy(t,e),this.groundColor.copy(t.groundColor),this}}const I_=new mm,L_=new zf,U_=new zf;class D_{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new ff(512,512),this.map=null,this.mapPass=null,this.matrix=new mm,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new m_,this._frameExtents=new ff(1,1),this._viewportCount=1,this._viewports=[new Uf(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,n=this.matrix;L_.setFromMatrixPosition(t.matrixWorld),e.position.copy(L_),U_.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(U_),e.updateMatrixWorld(),I_.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(I_),n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(I_)}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 O_ extends D_{constructor(){super(new Zg(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1}updateMatrices(t){const e=this.camera,n=2*af*t.angle*this.focus,i=this.mapSize.width/this.mapSize.height,r=t.distance||e.far;n===e.fov&&i===e.aspect&&r===e.far||(e.fov=n,e.aspect=i,e.far=r,e.updateProjectionMatrix()),super.updateMatrices(t)}copy(t){return super.copy(t),this.focus=t.focus,this}}class F_ extends N_{constructor(t,e,n=0,i=Math.PI/3,r=0,s=2){super(t,e),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(Vm.DEFAULT_UP),this.updateMatrix(),this.target=new Vm,this.distance=n,this.angle=i,this.penumbra=r,this.decay=s,this.map=null,this.shadow=new O_}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 B_=new mm,z_=new zf,k_=new zf;class G_ extends D_{constructor(){super(new Zg(90,1,.5,500)),this.isPointLightShadow=!0,this._frameExtents=new ff(4,2),this._viewportCount=6,this._viewports=[new Uf(2,1,1,1),new Uf(0,1,1,1),new Uf(3,1,1,1),new Uf(1,1,1,1),new Uf(3,0,1,1),new Uf(1,0,1,1)],this._cubeDirections=[new zf(1,0,0),new zf(-1,0,0),new zf(0,0,1),new zf(0,0,-1),new zf(0,1,0),new zf(0,-1,0)],this._cubeUps=[new zf(0,1,0),new zf(0,1,0),new zf(0,1,0),new zf(0,1,0),new zf(0,0,1),new zf(0,0,-1)]}updateMatrices(t,e=0){const n=this.camera,i=this.matrix,r=t.distance||n.far;r!==n.far&&(n.far=r,n.updateProjectionMatrix()),z_.setFromMatrixPosition(t.matrixWorld),n.position.copy(z_),k_.copy(n.position),k_.add(this._cubeDirections[e]),n.up.copy(this._cubeUps[e]),n.lookAt(k_),n.updateMatrixWorld(),i.makeTranslation(-z_.x,-z_.y,-z_.z),B_.multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse),this._frustum.setFromProjectionMatrix(B_)}}class V_ extends N_{constructor(t,e,n=0,i=2){super(t,e),this.isPointLight=!0,this.type="PointLight",this.distance=n,this.decay=i,this.shadow=new G_}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 H_ extends Xg{constructor(t=-1,e=1,n=1,i=-1,r=.1,s=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=n,this.bottom=i,this.near=r,this.far=s,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,n,i,r,s){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=n,this.view.offsetY=i,this.view.width=r,this.view.height=s,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),n=(this.right+this.left)/2,i=(this.top+this.bottom)/2;let r=n-t,s=n+t,a=i+e,o=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,s=r+t*this.view.width,a-=e*this.view.offsetY,o=a-e*this.view.height}this.projectionMatrix.makeOrthographic(r,s,a,o,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,null!==this.view&&(e.object.view=Object.assign({},this.view)),e}}class j_ extends D_{constructor(){super(new H_(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class W_ extends N_{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(Vm.DEFAULT_UP),this.updateMatrix(),this.target=new Vm,this.shadow=new j_}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class q_ extends N_{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}}class X_ extends N_{constructor(t,e,n=10,i=10){super(t,e),this.isRectAreaLight=!0,this.type="RectAreaLight",this.width=n,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 $_{constructor(){this.isSphericalHarmonics3=!0,this.coefficients=[];for(let t=0;t<9;t++)this.coefficients.push(new zf)}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 n=t.x,i=t.y,r=t.z,s=this.coefficients;return e.copy(s[0]).multiplyScalar(.282095),e.addScaledVector(s[1],.488603*i),e.addScaledVector(s[2],.488603*r),e.addScaledVector(s[3],.488603*n),e.addScaledVector(s[4],n*i*1.092548),e.addScaledVector(s[5],i*r*1.092548),e.addScaledVector(s[6],.315392*(3*r*r-1)),e.addScaledVector(s[7],n*r*1.092548),e.addScaledVector(s[8],.546274*(n*n-i*i)),e}getIrradianceAt(t,e){const n=t.x,i=t.y,r=t.z,s=this.coefficients;return e.copy(s[0]).multiplyScalar(.886227),e.addScaledVector(s[1],1.023328*i),e.addScaledVector(s[2],1.023328*r),e.addScaledVector(s[3],1.023328*n),e.addScaledVector(s[4],.858086*n*i),e.addScaledVector(s[5],.858086*i*r),e.addScaledVector(s[6],.743125*r*r-.247708),e.addScaledVector(s[7],.858086*n*r),e.addScaledVector(s[8],.429043*(n*n-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 n=0;n<9;n++)this.coefficients[n].addScaledVector(t.coefficients[n],e);return this}scale(t){for(let e=0;e<9;e++)this.coefficients[e].multiplyScalar(t);return this}lerp(t,e){for(let n=0;n<9;n++)this.coefficients[n].lerp(t.coefficients[n],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 n=this.coefficients;for(let i=0;i<9;i++)n[i].fromArray(t,e+3*i);return this}toArray(t=[],e=0){const n=this.coefficients;for(let i=0;i<9;i++)n[i].toArray(t,e+3*i);return t}static getBasisAt(t,e){const n=t.x,i=t.y,r=t.z;e[0]=.282095,e[1]=.488603*i,e[2]=.488603*r,e[3]=.488603*n,e[4]=1.092548*n*i,e[5]=1.092548*i*r,e[6]=.315392*(3*r*r-1),e[7]=1.092548*n*r,e[8]=.546274*(n*n-i*i)}}class Y_ extends N_{constructor(t=new $_,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 K_ extends i_{constructor(t,e,n=1){super(t,e),this.isInstancedInterleavedBuffer=!0,this.meshPerAttribute=n}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}}const Z_=["alphaMap","alphaTest","anisotropy","anisotropyMap","anisotropyRotation","aoMap","attenuationColor","attenuationDistance","bumpMap","clearcoat","clearcoatMap","clearcoatNormalMap","clearcoatNormalScale","clearcoatRoughness","color","dispersion","displacementMap","emissive","emissiveMap","envMap","gradientMap","ior","iridescence","iridescenceIOR","iridescenceMap","iridescenceThicknessMap","lightMap","map","matcap","metalness","metalnessMap","normalMap","normalScale","opacity","roughness","roughnessMap","sheen","sheenColor","sheenColorMap","sheenRoughnessMap","shininess","specular","specularColor","specularColorMap","specularIntensity","specularIntensityMap","specularMap","thickness","transmission","transmissionMap"];class Q_{constructor(t){this.renderObjects=new WeakMap,this.hasNode=this.containsNode(t),this.hasAnimation=!0===t.object.isSkinnedMesh,this.refreshUniforms=Z_,this.renderId=0}firstInitialization(t){return!1===this.renderObjects.has(t)&&(this.getRenderObjectData(t),!0)}getRenderObjectData(t){let e=this.renderObjects.get(t);if(void 0===e){const{geometry:n,material:i}=t;if(e={material:this.getMaterialData(i),geometry:{attributes:this.getAttributesData(n.attributes),indexVersion:n.index?n.index.version:null,drawRange:{start:n.drawRange.start,count:n.drawRange.count}},worldMatrix:t.object.matrixWorld.clone()},t.object.center&&(e.center=t.object.center.clone()),t.object.morphTargetInfluences&&(e.morphTargetInfluences=t.object.morphTargetInfluences.slice()),null!==t.bundle&&(e.version=t.bundle.version),e.material.transmission>0){const{width:n,height:i}=t.context;e.bufferWidth=n,e.bufferHeight=i}this.renderObjects.set(t,e)}return e}getAttributesData(t){const e={};for(const n in t){const i=t[n];e[n]={version:i.version}}return e}containsNode(t){const e=t.material;for(const t in e)if(e[t]&&e[t].isNode)return!0;return null!==t.renderer.nodes.modelViewMatrix||null!==t.renderer.nodes.modelNormalViewMatrix}getMaterialData(t){const e={};for(const n of this.refreshUniforms){const i=t[n];null!=i&&("object"==typeof i&&void 0!==i.clone?!0===i.isTexture?e[n]={id:i.id,version:i.version}:e[n]=i.clone():e[n]=i)}return e}equals(t){const{object:e,material:n,geometry:i}=t,r=this.getRenderObjectData(t);if(!0!==r.worldMatrix.equals(e.matrixWorld))return r.worldMatrix.copy(e.matrixWorld),!1;const s=r.material;for(const t in s){const e=s[t],i=n[t];if(void 0!==e.equals){if(!1===e.equals(i))return e.copy(i),!1}else if(!0===i.isTexture){if(e.id!==i.id||e.version!==i.version)return e.id=i.id,e.version=i.version,!1}else if(e!==i)return s[t]=i,!1}if(s.transmission>0){const{width:e,height:n}=t.context;if(r.bufferWidth!==e||r.bufferHeight!==n)return r.bufferWidth=e,r.bufferHeight=n,!1}const a=r.geometry,o=i.attributes,l=a.attributes,h=Object.keys(l),u=Object.keys(o);if(h.length!==u.length)return r.geometry.attributes=this.getAttributesData(o),!1;for(const t of h){const e=l[t],n=o[t];if(void 0===n)return delete l[t],!1;if(e.version!==n.version)return e.version=n.version,!1}const c=i.index,d=a.indexVersion,p=c?c.version:null;if(d!==p)return a.indexVersion=p,!1;if(a.drawRange.start!==i.drawRange.start||a.drawRange.count!==i.drawRange.count)return a.drawRange.start=i.drawRange.start,a.drawRange.count=i.drawRange.count,!1;if(r.morphTargetInfluences){let t=!1;for(let n=0;n<r.morphTargetInfluences.length;n++)r.morphTargetInfluences[n]!==e.morphTargetInfluences[n]&&(t=!0);if(t)return!0}return r.center&&!1===r.center.equals(e.center)?(r.center.copy(e.center),!0):(null!==t.bundle&&(r.version=t.bundle.version),!0)}needsRefresh(t,e){if(this.hasNode||this.hasAnimation||this.firstInitialization(t))return!0;const{renderId:n}=e;if(this.renderId!==n)return this.renderId=n,!0;const i=!0===t.object.static,r=null!==t.bundle&&!0===t.bundle.static&&this.getRenderObjectData(t).version===t.bundle.version;if(i||r)return!1;return!0!==this.equals(t)}}function J_(t,e=0){let n=3735928559^e,i=1103547991^e;if(t instanceof Array)for(let e,r=0;r<t.length;r++)e=t[r],n=Math.imul(n^e,2654435761),i=Math.imul(i^e,1597334677);else for(let e,r=0;r<t.length;r++)e=t.charCodeAt(r),n=Math.imul(n^e,2654435761),i=Math.imul(i^e,1597334677);return n=Math.imul(n^n>>>16,2246822507),n^=Math.imul(i^i>>>13,3266489909),i=Math.imul(i^i>>>16,2246822507),i^=Math.imul(n^n>>>13,3266489909),4294967296*(2097151&i)+(n>>>0)}const tv=t=>J_(t),ev=(...t)=>J_(t);function nv(t,e=!1){const n=[];!0===t.isNode&&(n.push(t.id),t=t.getSelf());for(const{property:i,childNode:r}of iv(t))n.push(n,J_(i.slice(0,-4)),r.getCacheKey(e));return J_(n)}function*iv(t,e=!1){for(const n in t){if(!0===n.startsWith("_"))continue;const i=t[n];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:n,index:t,childNode:r})}else if(i&&!0===i.isNode)yield{property:n,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:n,index:t,childNode:r})}}}function rv(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 sv(t,...e){const n=t?t.slice(-4):void 0;return 1===e.length&&("vec2"===n?e=[e[0],e[0]]:"vec3"===n?e=[e[0],e[0],e[0]]:"vec4"===n&&(e=[e[0],e[0],e[0],e[0]])),"color"===t?new og(...e):"vec2"===n?new ff(...e):"vec3"===n?new zf(...e):"vec4"===n?new Uf(...e):"mat3"===n?new mf(...e):"mat4"===n?new mm(...e):"bool"===t?e[0]||!1:"float"===t||"int"===t||"uint"===t?e[0]||0:"string"===t?e[0]||"":"ArrayBuffer"===t?(i=e[0],Uint8Array.from(atob(i),(t=>t.charCodeAt(0))).buffer):null;var i}const av="vertex",ov="none",lv="frame",hv="render",uv="object",cv=["setup","analyze","generate"],dv=["fragment","vertex","compute"],pv=["x","y","z","w"];let fv=0;class mv extends ef{static get type(){return"Node"}constructor(t=null){super(),this.nodeType=t,this.updateType=ov,this.updateBeforeType=ov,this.updateAfterType=ov,this.uuid=pf.generateUUID(),this.version=0,this._cacheKey=null,this._cacheKeyVersion=0,this.global=!1,this.isNode=!0,Object.defineProperty(this,"id",{value:fv++})}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,lv)}onRenderUpdate(t){return this.onUpdate(t,hv)}onObjectUpdate(t){return this.onUpdate(t,uv)}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 iv(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=nv(this,t),this._cacheKeyVersion=this.version),this._cacheKey}getScope(){return this}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 n=0;for(const t of this.getChildren())e["node"+n++]=t;return null}analyze(t){if(1===t.increaseUsage(this)){const e=t.getNodeProperties(this);for(const n of Object.values(e))n&&!0===n.isNode&&n.build(t)}}generate(t,e){const{outputNode:n}=t.getNodeProperties(this);if(n&&!0===n.isNode)return n.build(t,e)}updateBefore(){console.warn("Abstract function.")}updateAfter(){console.warn("Abstract function.")}update(){console.warn("Abstract function.")}build(t,e=null){const n=this.getShared(t);if(this!==n)return n.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){t.stack.nodes.length;e.initialized=!0,e.outputNode=this.setup(t),null!==e.outputNode&&t.stack.nodes.length;for(const n of Object.values(e))n&&!0===n.isNode&&n.build(t)}}else if("analyze"===r)this.analyze(t);else if("generate"===r){if(1===this.generate.length){const n=this.getNodeType(t),r=t.getDataFromNode(this);i=r.snippet,void 0===i?(i=this.generate(t)||"",r.snippet=i):void 0!==r.flowCodes&&void 0!==t.context.nodeBlock&&t.addFlowCodeHierarchy(this,t.context.nodeBlock),i=t.format(i,n,e)}else i=this.generate(t,e)||""}return t.removeChain(this),t.addSequentialNode(this),i}getSerializeChildren(){return iv(this)}serialize(t){const e=this.getSerializeChildren(),n={};for(const{property:i,index:r,childNode:s}of e)void 0!==r?(void 0===n[i]&&(n[i]=Number.isInteger(r)?[]:{}),n[i][r]=s.toJSON(t.meta).uuid):n[i]=s.toJSON(t.meta).uuid;Object.keys(n).length>0&&(t.inputNodes=n)}deserialize(t){if(void 0!==t.inputNodes){const e=t.meta.nodes;for(const n in t.inputNodes)if(Array.isArray(t.inputNodes[n])){const i=[];for(const r of t.inputNodes[n])i.push(e[r]);this[n]=i}else if("object"==typeof t.inputNodes[n]){const i={};for(const r in t.inputNodes[n]){const s=t.inputNodes[n][r];i[r]=e[s]}this[n]=i}else{const i=t.inputNodes[n];this[n]=e[i]}}}toJSON(t){const{uuid:e,type:n}=this,i=void 0===t||"string"==typeof t;i&&(t={textures:{},images:{},nodes:{}});let r=t.nodes[e];function s(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}if(void 0===r&&(r={uuid:e,type:n,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=s(t.textures),n=s(t.images),i=s(t.nodes);e.length>0&&(r.textures=e),n.length>0&&(r.images=n),i.length>0&&(r.nodes=i)}return r}}class gv extends mv{static get type(){return"ArrayElementNode"}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")} ]`}}class _v extends mv{static get type(){return"ConvertNode"}constructor(t,e){super(),this.node=t,this.convertTo=e}getNodeType(t){const e=this.node.getNodeType(t);let n=null;for(const i of this.convertTo.split("|"))null!==n&&t.getTypeLength(e)!==t.getTypeLength(i)||(n=i);return n}serialize(t){super.serialize(t),t.convertTo=this.convertTo}deserialize(t){super.deserialize(t),this.convertTo=t.convertTo}generate(t,e){const n=this.node,i=this.getNodeType(t),r=n.build(t,i);return t.format(r,i,e)}}class vv extends mv{static get type(){return"TempNode"}constructor(t){super(t),this.isTempNode=!0}hasDependencies(t){return t.getDataFromNode(this).usageCount>1}build(t,e){if("generate"===t.getBuildStage()){const n=t.getVectorType(this.getNodeType(t,e)),i=t.getDataFromNode(this);if(void 0!==i.propertyName)return t.format(i.propertyName,n,e);if("void"!==n&&"void"!==e&&this.hasDependencies(t)){const r=super.build(t,n),s=t.getVarFromNode(this,null,n),a=t.getPropertyName(s);return t.addLineFlowCode(`${a} = ${r}`,this),i.snippet=r,i.propertyName=a,t.format(i.propertyName,n,e)}}return super.build(t,e)}}class yv extends vv{static get type(){return"JoinNode"}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,n)=>e+t.getTypeLength(n.getNodeType(t))),0))}generate(t,e){const n=this.getNodeType(t),i=this.nodes,r=t.getComponentType(n),s=[];for(const e of i){let n=e.build(t);const i=t.getComponentType(e.getNodeType(t));i!==r&&(n=t.format(n,i,r)),s.push(n)}const a=`${t.getType(n)}( ${s.join(", ")} )`;return t.format(a,n,e)}}const xv=pv.join("");class bv extends mv{static get type(){return"SplitNode"}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(pv.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 n=this.node,i=t.getTypeLength(n.getNodeType(t));let r=null;if(i>1){let s=null;this.getVectorLength()>=i&&(s=t.getTypeFromLength(this.getVectorLength(),this.getComponentType(t)));const a=n.build(t,s);r=this.components.length===i&&this.components===xv.slice(0,this.components.length)?t.format(a,s,e):t.format(`${a}.${this.components}`,this.getNodeType(t),e)}else r=n.build(t,e);return r}serialize(t){super.serialize(t),t.components=this.components}deserialize(t){super.deserialize(t),this.components=t.components}}class Sv extends vv{static get type(){return"SetNode"}constructor(t,e,n){super(),this.sourceNode=t,this.components=e,this.targetNode=n}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{sourceNode:e,components:n,targetNode:i}=this,r=this.getNodeType(t),s=t.getTypeFromLength(n.length,i.getNodeType(t)),a=i.build(t,s),o=e.build(t,r),l=t.getTypeLength(r),h=[];for(let t=0;t<l;t++){const e=pv[t];e===n[0]?(h.push(a),t+=n.length-1):h.push(o+"."+e)}return`${t.getType(r)}( ${h.join(", ")} )`}}class Mv extends vv{static get type(){return"FlipNode"}constructor(t,e){super(),this.sourceNode=t,this.components=e}getNodeType(t){return this.sourceNode.getNodeType(t)}generate(t){const{components:e,sourceNode:n}=this,i=this.getNodeType(t),r=n.build(t),s=t.getVarFromNode(this),a=t.getPropertyName(s);t.addLineFlowCode(a+" = "+r,this);const o=t.getTypeLength(i),l=[];let h=0;for(let t=0;t<o;t++){const n=pv[t];n===e[h]?(l.push("1.0 - "+a+"."+n),h++):l.push(a+"."+n)}return`${t.getType(i)}( ${l.join(", ")} )`}}class Tv extends mv{static get type(){return"InputNode"}constructor(t,e=null){super(e),this.isInputNode=!0,this.value=t,this.precision=null}getNodeType(){return null===this.nodeType?rv(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=rv(this.value),t.nodeType=this.nodeType,"ArrayBuffer"===t.valueType&&(t.value=function(t){let e="";const n=new Uint8Array(t);for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return btoa(e)}(t.value)),t.precision=this.precision}deserialize(t){super.deserialize(t),this.nodeType=t.nodeType,this.value=Array.isArray(t.value)?sv(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.")}}class wv extends Tv{static get type(){return"ConstNode"}constructor(t,e=null){super(t,e),this.isConstNode=!0}generateConst(t){return t.generateConst(this.getNodeType(t),this.value)}generate(t,e){const n=this.getNodeType(t);return t.format(this.generateConst(t),n,e)}}let Ev=null;const Av=new Map;function Rv(t,e){if(Av.has(t))console.warn(`Redefinition of method chaining ${t}`);else{if("function"!=typeof e)throw new Error(`Node element ${t} is not a function`);Av.set(t,e)}}const Cv=t=>t.replace(/r|s/g,"x").replace(/g|t/g,"y").replace(/b|p/g,"z").replace(/a|q/g,"w"),Nv=t=>Cv(t).split("").sort().join(""),Pv={setup(t,e){const n=e.shift();return t(ey(n),...e)},get(t,e,n){if("string"==typeof e&&void 0===t[e]){if(!0!==t.isStackNode&&"assign"===e)return(...t)=>(Ev.assign(n,...t),n);if(Av.has(e)){const i=Av.get(e);return t.isStackNode?(...t)=>n.add(i(...t)):(...t)=>i(n,...t)}if("self"===e)return t;if(e.endsWith("Assign")&&Av.has(e.slice(0,e.length-6))){const i=Av.get(e.slice(0,e.length-6));return t.isStackNode?(...t)=>n.assign(t[0],i(...t)):(...t)=>n.assign(i(n,...t))}if(!0===/^[xyzwrgbastpq]{1,4}$/.test(e))return e=Cv(e),ty(new bv(n,e));if(!0===/^set[XYZWRGBASTPQ]{1,4}$/.test(e))return e=Nv(e.slice(3).toLowerCase()),n=>ty(new Sv(t,e,n));if(!0===/^flip[XYZWRGBASTPQ]{1,4}$/.test(e))return e=Nv(e.slice(4).toLowerCase()),()=>ty(new Mv(ty(t),e));if("width"===e||"height"===e||"depth"===e)return"width"===e?e="x":"height"===e?e="y":"depth"===e&&(e="z"),ty(new bv(t,e));if(!0===/^\d+$/.test(e))return ty(new gv(n,new wv(Number(e),"uint")))}return Reflect.get(t,e,n)},set:(t,e,n,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,n,i):(i[e].assign(n),!0)},Iv=new WeakMap,Lv=new WeakMap,Uv=function(t,e=null){for(const n in t)t[n]=ty(t[n],e);return t},Dv=function(t,e=null){const n=t.length;for(let i=0;i<n;i++)t[i]=ty(t[i],e);return t},Ov=function(t,e=null,n=null,i=null){const r=t=>ty(null!==i?Object.assign(t,i):t);return null===e?(...e)=>r(new t(...ny(e))):null!==n?(n=ty(n),(...i)=>r(new t(e,...ny(i),n))):(...n)=>r(new t(e,...ny(n)))},Fv=function(t,...e){return ty(new t(...ny(e)))};class Bv extends mv{constructor(t,e){super(),this.shaderNode=t,this.inputNodes=e}getNodeType(t){return this.shaderNode.nodeType||this.getOutputNode(t).getNodeType(t)}call(t){const{shaderNode:e,inputNodes:n}=this,i=t.getNodeProperties(e);if(i.onceOutput)return i.onceOutput;let r=null;if(e.layout){let i=Lv.get(t.constructor);void 0===i&&(i=new WeakMap,Lv.set(t.constructor,i));let s=i.get(e);void 0===s&&(s=ty(t.buildFunctionNode(e)),i.set(e,s)),null!==t.currentFunctionNode&&t.currentFunctionNode.includes.push(s),r=ty(s.call(n))}else{const i=e.jsFunc,s=null!==n?i(n,t):i(t);r=ty(s)}return e.once&&(i.onceOutput=r),r}getOutputNode(t){const e=t.getNodeProperties(this);return null===e.outputNode&&(e.outputNode=this.setupOutput(t)),e.outputNode}setup(t){return this.getOutputNode(t)}setupOutput(t){return t.addStack(),t.stack.outputNode=this.call(t),t.removeStack()}generate(t,e){return this.getOutputNode(t).build(t,e)}}class zv extends mv{constructor(t,e){super(e),this.jsFunc=t,this.layout=null,this.global=!0,this.once=!1}setLayout(t){return this.layout=t,this}call(t=null){return ey(t),ty(new Bv(this,t))}setup(){return this.call()}}const kv=[!1,!0],Gv=[0,1,2,3],Vv=[-1,-2],Hv=[.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],jv=new Map;for(const t of kv)jv.set(t,new wv(t));const Wv=new Map;for(const t of Gv)Wv.set(t,new wv(t,"uint"));const qv=new Map([...Wv].map((t=>new wv(t.value,"int"))));for(const t of Vv)qv.set(t,new wv(t,"int"));const Xv=new Map([...qv].map((t=>new wv(t.value))));for(const t of Hv)Xv.set(t,new wv(t));for(const t of Hv)Xv.set(-t,new wv(-t));const $v={bool:jv,uint:Wv,ints:qv,float:Xv},Yv=new Map([...jv,...Xv]),Kv=(t,e)=>Yv.has(t)?Yv.get(t):!0===t.isNode?t:new wv(t,e),Zv=function(t,e=null){return(...n)=>{if((0===n.length||!["bool","float","int","uint"].includes(t)&&n.every((t=>"object"!=typeof t)))&&(n=[sv(t,...n)]),1===n.length&&null!==e&&e.has(n[0]))return ty(e.get(n[0]));if(1===n.length){const e=Kv(n[0],t);return(t=>{try{return t.getNodeType()}catch(t){return}})(e)===t?ty(e):ty(new _v(e,t))}const i=n.map((t=>Kv(t)));return ty(new yv(i,t))}},Qv=t=>"object"==typeof t&&null!==t?t.value:t;function Jv(t,e){return new Proxy(new zv(t,e),Pv)}const ty=(t,e=null)=>function(t,e=null){const n=rv(t);if("node"===n){let e=Iv.get(t);return void 0===e&&(e=new Proxy(t,Pv),Iv.set(t,e),Iv.set(e,e)),e}return null===e&&("float"===n||"boolean"===n)||n&&"shader"!==n&&"string"!==n?ty(Kv(t,e)):"shader"===n?sy(t):t}(t,e),ey=(t,e=null)=>new Uv(t,e),ny=(t,e=null)=>new Dv(t,e),iy=(...t)=>new Ov(...t),ry=(...t)=>new Fv(...t),sy=(t,e)=>{const n=new Jv(t,e),i=(...t)=>{let e;return ey(t),e=t[0]&&t[0].isNode?[...t]:t[0],n.call(e)};return i.shaderNode=n,i.setLayout=t=>(n.setLayout(t),i),i.once=()=>(n.once=!0,i),i};Rv("toGlobal",(t=>(t.global=!0,t)));const ay=t=>{Ev=t},oy=()=>Ev,ly=(...t)=>Ev.If(...t);Rv("append",(function(t){return Ev&&Ev.add(t),t}));const hy=new Zv("color"),uy=new Zv("float",$v.float),cy=new Zv("int",$v.ints),dy=new Zv("uint",$v.uint),py=new Zv("bool",$v.bool),fy=new Zv("vec2"),my=new Zv("ivec2"),gy=new Zv("uvec2"),_y=new Zv("bvec2"),vy=new Zv("vec3"),yy=new Zv("ivec3"),xy=new Zv("uvec3"),by=new Zv("bvec3"),Sy=new Zv("vec4"),My=new Zv("ivec4"),Ty=new Zv("uvec4"),wy=new Zv("bvec4"),Ey=new Zv("mat2"),Ay=new Zv("mat3"),Ry=new Zv("mat4");Rv("toColor",hy),Rv("toFloat",uy),Rv("toInt",cy),Rv("toUint",dy),Rv("toBool",py),Rv("toVec2",fy),Rv("toIVec2",my),Rv("toUVec2",gy),Rv("toBVec2",_y),Rv("toVec3",vy),Rv("toIVec3",yy),Rv("toUVec3",xy),Rv("toBVec3",by),Rv("toVec4",Sy),Rv("toIVec4",My),Rv("toUVec4",Ty),Rv("toBVec4",wy),Rv("toMat2",Ey),Rv("toMat3",Ay),Rv("toMat4",Ry);Rv("element",iy(gv)),Rv("convert",((t,e)=>ty(new _v(ty(t),e))));class Cy extends mv{static get type(){return"UniformGroupNode"}constructor(t,e=!1,n=1){super("string"),this.name=t,this.version=0,this.shared=e,this.order=n,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 Ny=t=>new Cy(t),Py=(t,e=0)=>new Cy(t,!0,e),Iy=Py("frame"),Ly=Py("render"),Uy=Ny("object");class Dy extends Tv{static get type(){return"UniformNode"}constructor(t,e=null){super(t,e),this.isUniformNode=!0,this.name="",this.groupNode=Uy}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 n=this.getSelf();return t=t.bind(n),super.onUpdate((e=>{const i=t(e,n);void 0!==i&&(this.value=i)}),e)}generate(t,e){const n=this.getNodeType(t),i=this.getUniformHash(t);let r=t.getNodeFromHash(i);void 0===r&&(t.setHashNode(this,i),r=this);const s=r.getInputType(t),a=t.getUniformFromNode(r,s,t.shaderStage,this.name||t.context.label),o=t.getPropertyName(a);return void 0!==t.context.label&&delete t.context.label,t.format(o,n,e)}}const Oy=(t,e)=>{const n=(t=>null!=t?t.nodeType||t.convertTo||("string"==typeof t?t:null):null)(e||t),i=t&&!0===t.isNode?t.node&&t.node.value||t.value:t;return ty(new Dy(i,n))};class Fy extends mv{static get type(){return"PropertyNode"}constructor(t,e=null,n=!1){super(t),this.name=e,this.varying=n,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 By=(t,e)=>ty(new Fy(t,e)),zy=(t,e)=>ty(new Fy(t,e,!0)),ky=ry(Fy,"vec4","DiffuseColor"),Gy=ry(Fy,"vec3","EmissiveColor"),Vy=ry(Fy,"float","Roughness"),Hy=ry(Fy,"float","Metalness"),jy=ry(Fy,"float","Clearcoat"),Wy=ry(Fy,"float","ClearcoatRoughness"),qy=ry(Fy,"vec3","Sheen"),Xy=ry(Fy,"float","SheenRoughness"),$y=ry(Fy,"float","Iridescence"),Yy=ry(Fy,"float","IridescenceIOR"),Ky=ry(Fy,"float","IridescenceThickness"),Zy=ry(Fy,"float","AlphaT"),Qy=ry(Fy,"float","Anisotropy"),Jy=ry(Fy,"vec3","AnisotropyT"),tx=ry(Fy,"vec3","AnisotropyB"),ex=ry(Fy,"color","SpecularColor"),nx=ry(Fy,"float","SpecularF90"),ix=ry(Fy,"float","Shininess"),rx=ry(Fy,"vec4","Output"),sx=ry(Fy,"float","dashSize"),ax=ry(Fy,"float","gapSize"),ox=ry(Fy,"float","IOR"),lx=ry(Fy,"float","Transmission"),hx=ry(Fy,"float","Thickness"),ux=ry(Fy,"float","AttenuationDistance"),cx=ry(Fy,"color","AttenuationColor"),dx=ry(Fy,"float","Dispersion");class px extends vv{static get type(){return"AssignNode"}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 n=t.getTypeLength(e.node.getNodeType(t));return pv.join("").slice(0,n)!==e.components}return!1}generate(t,e){const{targetNode:n,sourceNode:i}=this,r=this.needsSplitAssign(t),s=n.getNodeType(t),a=n.context({assign:!0}).build(t),o=i.build(t,s),l=i.getNodeType(t),h=t.getDataFromNode(this);let u;if(!0===h.initialized)"void"!==e&&(u=a);else if(r){const i=t.getVarFromNode(this,null,s),r=t.getPropertyName(i);t.addLineFlowCode(`${r} = ${o}`,this);const l=n.node.context({assign:!0}).build(t);for(let e=0;e<n.components.length;e++){const i=n.components[e];t.addLineFlowCode(`${l}.${i} = ${r}[ ${e} ]`,this)}"void"!==e&&(u=a)}else u=`${a} = ${o}`,"void"!==e&&"void"!==l||(t.addLineFlowCode(u,this),"void"!==e&&(u=a));return h.initialized=!0,t.format(u,s,e)}}Rv("assign",iy(px));class fx extends vv{static get type(){return"FunctionCallNode"}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=[],n=this.functionNode,i=n.getInputs(t),r=this.parameters,s=(e,n)=>{const i=n.type;let r;return r="pointer"===i?"&"+e.build(t):e.build(t,i),r};if(Array.isArray(r))for(let t=0;t<r.length;t++)e.push(s(r[t],i[t]));else for(const t of i){const n=r[t.name];if(void 0===n)throw new Error(`FunctionCallNode: Input '${t.name}' not found in FunctionNode.`);e.push(s(n,t))}return`${n.build(t,"property")}( ${e.join(", ")} )`}}Rv("call",((t,...e)=>(e=e.length>1||e[0]&&!0===e[0].isNode?ny(e):ey(e[0]),ty(new fx(ty(t),e)))));class mx extends vv{static get type(){return"OperatorNode"}constructor(t,e,n,...i){if(super(),i.length>0){let r=new mx(t,e,n);for(let e=0;e<i.length-1;e++)r=new mx(t,r,i[e]);e=r,n=i[i.length-1]}this.op=t,this.aNode=e,this.bNode=n}getNodeType(t,e){const n=this.op,i=this.aNode,r=this.bNode,s=i.getNodeType(t),a=void 0!==r?r.getNodeType(t):null;if("void"===s||"void"===a)return"void";if("%"===n)return s;if("~"===n||"&"===n||"|"===n||"^"===n||">>"===n||"<<"===n)return t.getIntegerType(s);if("!"===n||"=="===n||"&&"===n||"||"===n||"^^"===n)return"bool";if("<"===n||">"===n||"<="===n||">="===n){const n=e?t.getTypeLength(e):Math.max(t.getTypeLength(s),t.getTypeLength(a));return n>1?`bvec${n}`:"bool"}return"float"===s&&t.isMatrix(a)?a:t.isMatrix(s)&&t.isVector(a)?t.getVectorFromMatrix(s):t.isVector(s)&&t.isMatrix(a)?t.getVectorFromMatrix(a):t.getTypeLength(a)>t.getTypeLength(s)?a:s}generate(t,e){const n=this.op,i=this.aNode,r=this.bNode,s=this.getNodeType(t,e);let a=null,o=null;"void"!==s?(a=i.getNodeType(t),o=void 0!==r?r.getNodeType(t):null,"<"===n||">"===n||"<="===n||">="===n||"=="===n?t.isVector(a)?o=a:a!==o&&(a=o="float"):">>"===n||"<<"===n?(a=s,o=t.changeComponentType(o,"uint")):t.isMatrix(a)&&t.isVector(o)?o=t.getVectorFromMatrix(a):a=t.isVector(a)&&t.isMatrix(o)?t.getVectorFromMatrix(o):o=s):a=o=s;const l=i.build(t,a),h=void 0!==r?r.build(t,o):null,u=t.getTypeLength(e),c=t.getFunctionOperator(n);return"void"!==e?"<"===n&&u>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThan",e)}( ${l}, ${h} )`,s,e):t.format(`( ${l} < ${h} )`,s,e):"<="===n&&u>1?t.useComparisonMethod?t.format(`${t.getMethod("lessThanEqual",e)}( ${l}, ${h} )`,s,e):t.format(`( ${l} <= ${h} )`,s,e):">"===n&&u>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThan",e)}( ${l}, ${h} )`,s,e):t.format(`( ${l} > ${h} )`,s,e):">="===n&&u>1?t.useComparisonMethod?t.format(`${t.getMethod("greaterThanEqual",e)}( ${l}, ${h} )`,s,e):t.format(`( ${l} >= ${h} )`,s,e):"!"===n||"~"===n?t.format(`(${n}${l})`,a,e):c?t.format(`${c}( ${l}, ${h} )`,s,e):t.format(`( ${l} ${n} ${h} )`,s,e):"void"!==a?c?t.format(`${c}( ${l}, ${h} )`,s,e):t.format(`${l} ${n} ${h}`,s,e):void 0}serialize(t){super.serialize(t),t.op=this.op}deserialize(t){super.deserialize(t),this.op=t.op}}const gx=iy(mx,"+"),_x=iy(mx,"-"),vx=iy(mx,"*"),yx=iy(mx,"/"),xx=iy(mx,"%"),bx=iy(mx,"=="),Sx=iy(mx,"!="),Mx=iy(mx,"<"),Tx=iy(mx,">"),wx=iy(mx,"<="),Ex=iy(mx,">="),Ax=iy(mx,"&&"),Rx=iy(mx,"||"),Cx=iy(mx,"!"),Nx=iy(mx,"^^"),Px=iy(mx,"&"),Ix=iy(mx,"~"),Lx=iy(mx,"|"),Ux=iy(mx,"^"),Dx=iy(mx,"<<"),Ox=iy(mx,">>");Rv("add",gx),Rv("sub",_x),Rv("mul",vx),Rv("div",yx),Rv("modInt",xx),Rv("equal",bx),Rv("notEqual",Sx),Rv("lessThan",Mx),Rv("greaterThan",Tx),Rv("lessThanEqual",wx),Rv("greaterThanEqual",Ex),Rv("and",Ax),Rv("or",Rx),Rv("not",Cx),Rv("xor",Nx),Rv("bitAnd",Px),Rv("bitNot",Ix),Rv("bitOr",Lx),Rv("bitXor",Ux),Rv("shiftLeft",Dx),Rv("shiftRight",Ox);Rv("remainder",((...t)=>(console.warn("TSL.OperatorNode: .remainder() has been renamed to .modInt()."),xx(...t))));class Fx extends vv{static get type(){return"MathNode"}constructor(t,e,n=null,i=null){super(),this.method=t,this.aNode=e,this.bNode=n,this.cNode=i}getInputType(t){const e=this.aNode.getNodeType(t),n=this.bNode?this.bNode.getNodeType(t):null,i=this.cNode?this.cNode.getNodeType(t):null,r=t.isMatrix(e)?0:t.getTypeLength(e),s=t.isMatrix(n)?0:t.getTypeLength(n),a=t.isMatrix(i)?0:t.getTypeLength(i);return r>s&&r>a?e:s>a?n:a>r?i:e}getNodeType(t){const e=this.method;return e===Fx.LENGTH||e===Fx.DISTANCE||e===Fx.DOT?"float":e===Fx.CROSS?"vec3":e===Fx.ALL?"bool":e===Fx.EQUALS?t.changeComponentType(this.aNode.getNodeType(t),"bool"):e===Fx.MOD?this.aNode.getNodeType(t):this.getInputType(t)}generate(t,e){const n=this.method,i=this.getNodeType(t),r=this.getInputType(t),s=this.aNode,a=this.bNode,o=this.cNode,l=!0===t.renderer.isWebGLRenderer;if(n===Fx.TRANSFORM_DIRECTION){let n=s,i=a;t.isMatrix(n.getNodeType(t))?i=Sy(vy(i),0):n=Sy(vy(n),0);const r=vx(n,i).xyz;return Jx(r).build(t,e)}if(n===Fx.NEGATE)return t.format("( - "+s.build(t,r)+" )",i,e);if(n===Fx.ONE_MINUS)return _x(1,s).build(t,e);if(n===Fx.RECIPROCAL)return yx(1,s).build(t,e);if(n===Fx.DIFFERENCE)return ob(_x(s,a)).build(t,e);{const h=[];return n===Fx.CROSS||n===Fx.MOD?h.push(s.build(t,i),a.build(t,i)):l&&n===Fx.STEP?h.push(s.build(t,1===t.getTypeLength(s.getNodeType(t))?"float":r),a.build(t,r)):l&&(n===Fx.MIN||n===Fx.MAX)||n===Fx.MOD?h.push(s.build(t,r),a.build(t,1===t.getTypeLength(a.getNodeType(t))?"float":r)):n===Fx.REFRACT?h.push(s.build(t,r),a.build(t,r),o.build(t,"float")):n===Fx.MIX?h.push(s.build(t,r),a.build(t,r),o.build(t,1===t.getTypeLength(o.getNodeType(t))?"float":r)):(h.push(s.build(t,r)),null!==a&&h.push(a.build(t,r)),null!==o&&h.push(o.build(t,r))),t.format(`${t.getMethod(n,i)}( ${h.join(", ")} )`,i,e)}}serialize(t){super.serialize(t),t.method=this.method}deserialize(t){super.deserialize(t),this.method=t.method}}Fx.ALL="all",Fx.ANY="any",Fx.EQUALS="equals",Fx.RADIANS="radians",Fx.DEGREES="degrees",Fx.EXP="exp",Fx.EXP2="exp2",Fx.LOG="log",Fx.LOG2="log2",Fx.SQRT="sqrt",Fx.INVERSE_SQRT="inversesqrt",Fx.FLOOR="floor",Fx.CEIL="ceil",Fx.NORMALIZE="normalize",Fx.FRACT="fract",Fx.SIN="sin",Fx.COS="cos",Fx.TAN="tan",Fx.ASIN="asin",Fx.ACOS="acos",Fx.ATAN="atan",Fx.ABS="abs",Fx.SIGN="sign",Fx.LENGTH="length",Fx.NEGATE="negate",Fx.ONE_MINUS="oneMinus",Fx.DFDX="dFdx",Fx.DFDY="dFdy",Fx.ROUND="round",Fx.RECIPROCAL="reciprocal",Fx.TRUNC="trunc",Fx.FWIDTH="fwidth",Fx.BITCAST="bitcast",Fx.TRANSPOSE="transpose",Fx.ATAN2="atan2",Fx.MIN="min",Fx.MAX="max",Fx.MOD="mod",Fx.STEP="step",Fx.REFLECT="reflect",Fx.DISTANCE="distance",Fx.DIFFERENCE="difference",Fx.DOT="dot",Fx.CROSS="cross",Fx.POW="pow",Fx.TRANSFORM_DIRECTION="transformDirection",Fx.MIX="mix",Fx.CLAMP="clamp",Fx.REFRACT="refract",Fx.SMOOTHSTEP="smoothstep",Fx.FACEFORWARD="faceforward";const Bx=uy(1e-6),zx=uy(Math.PI),kx=iy(Fx,Fx.ALL),Gx=iy(Fx,Fx.ANY),Vx=iy(Fx,Fx.EQUALS),Hx=iy(Fx,Fx.RADIANS),jx=iy(Fx,Fx.DEGREES),Wx=iy(Fx,Fx.EXP),qx=iy(Fx,Fx.EXP2),Xx=iy(Fx,Fx.LOG),$x=iy(Fx,Fx.LOG2),Yx=iy(Fx,Fx.SQRT),Kx=iy(Fx,Fx.INVERSE_SQRT),Zx=iy(Fx,Fx.FLOOR),Qx=iy(Fx,Fx.CEIL),Jx=iy(Fx,Fx.NORMALIZE),tb=iy(Fx,Fx.FRACT),eb=iy(Fx,Fx.SIN),nb=iy(Fx,Fx.COS),ib=iy(Fx,Fx.TAN),rb=iy(Fx,Fx.ASIN),sb=iy(Fx,Fx.ACOS),ab=iy(Fx,Fx.ATAN),ob=iy(Fx,Fx.ABS),lb=iy(Fx,Fx.SIGN),hb=iy(Fx,Fx.LENGTH),ub=iy(Fx,Fx.NEGATE),cb=iy(Fx,Fx.ONE_MINUS),db=iy(Fx,Fx.DFDX),pb=iy(Fx,Fx.DFDY),fb=iy(Fx,Fx.ROUND),mb=iy(Fx,Fx.RECIPROCAL),gb=iy(Fx,Fx.TRUNC),_b=iy(Fx,Fx.FWIDTH);Fx.BITCAST;const vb=iy(Fx,Fx.TRANSPOSE),yb=iy(Fx,Fx.ATAN2),xb=iy(Fx,Fx.MIN),bb=iy(Fx,Fx.MAX),Sb=iy(Fx,Fx.MOD),Mb=iy(Fx,Fx.STEP),Tb=iy(Fx,Fx.REFLECT),wb=iy(Fx,Fx.DISTANCE),Eb=iy(Fx,Fx.DIFFERENCE),Ab=iy(Fx,Fx.DOT),Rb=iy(Fx,Fx.CROSS),Cb=iy(Fx,Fx.POW),Nb=iy(Fx,Fx.POW,2),Pb=iy(Fx,Fx.POW,3),Ib=iy(Fx,Fx.POW,4),Lb=iy(Fx,Fx.TRANSFORM_DIRECTION),Ub=iy(Fx,Fx.MIX),Db=(t,e=0,n=1)=>ty(new Fx(Fx.CLAMP,ty(t),ty(e),ty(n))),Ob=iy(Fx,Fx.REFRACT),Fb=iy(Fx,Fx.SMOOTHSTEP),Bb=iy(Fx,Fx.FACEFORWARD),zb=sy((([t])=>{const e=Ab(t.xy,fy(12.9898,78.233)),n=Sb(e,zx);return tb(eb(n).mul(43758.5453))}));Rv("all",kx),Rv("any",Gx),Rv("equals",Vx),Rv("radians",Hx),Rv("degrees",jx),Rv("exp",Wx),Rv("exp2",qx),Rv("log",Xx),Rv("log2",$x),Rv("sqrt",Yx),Rv("inverseSqrt",Kx),Rv("floor",Zx),Rv("ceil",Qx),Rv("normalize",Jx),Rv("fract",tb),Rv("sin",eb),Rv("cos",nb),Rv("tan",ib),Rv("asin",rb),Rv("acos",sb),Rv("atan",ab),Rv("abs",ob),Rv("sign",lb),Rv("length",hb),Rv("lengthSq",(t=>Ab(t,t))),Rv("negate",ub),Rv("oneMinus",cb),Rv("dFdx",db),Rv("dFdy",pb),Rv("round",fb),Rv("reciprocal",mb),Rv("trunc",gb),Rv("fwidth",_b),Rv("atan2",yb),Rv("min",xb),Rv("max",bb),Rv("mod",Sb),Rv("step",Mb),Rv("reflect",Tb),Rv("distance",wb),Rv("dot",Ab),Rv("cross",Rb),Rv("pow",Cb),Rv("pow2",Nb),Rv("pow3",Pb),Rv("pow4",Ib),Rv("transformDirection",Lb),Rv("mix",((t,e,n)=>Ub(e,n,t))),Rv("clamp",Db),Rv("refract",Ob),Rv("smoothstep",((t,e,n)=>Fb(e,n,t))),Rv("faceForward",Bb),Rv("difference",Eb),Rv("saturate",(t=>Db(t))),Rv("cbrt",(t=>vx(lb(t),Cb(ob(t),1/3)))),Rv("transpose",vb),Rv("rand",zb);class kb extends mv{static get type(){return"ConditionalNode"}constructor(t,e,n=null){super(),this.condNode=t,this.ifNode=e,this.elseNode=n}getNodeType(t){const e=this.ifNode.getNodeType(t);if(null!==this.elseNode){const n=this.elseNode.getNodeType(t);if(t.getTypeLength(n)>t.getTypeLength(e))return n}return e}setup(t){const e=this.condNode.cache(),n=this.ifNode.cache(),i=this.elseNode?this.elseNode.cache():null,r=t.context.nodeBlock;t.getDataFromNode(n).parentNodeBlock=r,null!==i&&(t.getDataFromNode(i).parentNodeBlock=r);const s=t.getNodeProperties(this);s.condNode=e,s.ifNode=n.context({nodeBlock:n}),s.elseNode=i?i.context({nodeBlock:i}):null}generate(t,e){const n=this.getNodeType(t),i=t.getDataFromNode(this);if(void 0!==i.nodeProperty)return i.nodeProperty;const{condNode:r,ifNode:s,elseNode:a}=t.getNodeProperties(this),o="void"!==e,l=o?By(n).build(t):"";i.nodeProperty=l;const h=r.build(t,"bool");t.addFlowCode(`\n${t.tab}if ( ${h} ) {\n\n`).addFlowTab();let u=s.build(t,n);if(u&&(u=o?l+" = "+u+";":"return "+u+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+u+"\n\n"+t.tab+"}"),null!==a){t.addFlowCode(" else {\n\n").addFlowTab();let e=a.build(t,n);e&&(e=o?l+" = "+e+";":"return "+e+";"),t.removeFlowTab().addFlowCode(t.tab+"\t"+e+"\n\n"+t.tab+"}\n\n")}else t.addFlowCode("\n\n");return t.format(l,n,e)}}const Gb=iy(kb);Rv("select",Gb);Rv("cond",((...t)=>(console.warn("TSL.ConditionalNode: cond() has been renamed to select()."),Gb(...t))));class Vb extends mv{static get type(){return"ContextNode"}constructor(t,e={}){super(),this.isContextNode=!0,this.node=t,this.value=e}getScope(){return this.node.getScope()}getNodeType(t){return this.node.getNodeType(t)}analyze(t){this.node.build(t)}setup(t){const e=t.getContext();t.setContext({...t.context,...this.value});const n=this.node.build(t);return t.setContext(e),n}generate(t,e){const n=t.getContext();t.setContext({...t.context,...this.value});const i=this.node.build(t,e);return t.setContext(n),i}}const Hb=iy(Vb);Rv("context",Hb),Rv("label",((t,e)=>Hb(t,{label:e})));class jb extends mv{static get type(){return"VarNode"}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:n}=this,i=t.getVarFromNode(this,n,t.getVectorType(this.getNodeType(t))),r=t.getPropertyName(i),s=e.build(t,i.type);return t.addLineFlowCode(`${r} = ${s}`,this),r}}const Wb=iy(jb);Rv("toVar",((...t)=>Wb(...t).append()));Rv("temp",(t=>(console.warn('TSL: "temp" is deprecated. Use ".toVar()" instead.'),Wb(t))));class qb extends mv{static get type(){return"VaryingNode"}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 n=e.varying;if(void 0===n){const i=this.name,r=this.getNodeType(t);e.varying=n=t.getVaryingFromNode(this,i,r),e.node=this.node}return n.needsInterpolation||(n.needsInterpolation="fragment"===t.shaderStage),n}setup(t){this.setupVarying(t)}analyze(t){return this.setupVarying(t),this.node.analyze(t)}generate(t){const e=t.getNodeProperties(this),n=this.setupVarying(t);if(void 0===e.propertyName){const i=this.getNodeType(t),r=t.getPropertyName(n,av);t.flowNodeFromShaderStage(av,this.node,i,r),e.propertyName=r}return t.getPropertyName(n)}}const Xb=iy(qb);Rv("varying",Xb);const $b=sy((([t])=>{const e=t.mul(.9478672986).add(.0521327014).pow(2.4),n=t.mul(.0773993808),i=t.lessThanEqual(.04045);return Ub(e,n,i)})).setLayout({name:"sRGBTransferEOTF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Yb=sy((([t])=>{const e=t.pow(.41666).mul(1.055).sub(.055),n=t.mul(12.92),i=t.lessThanEqual(.0031308);return Ub(e,n,i)})).setLayout({name:"sRGBTransferOETF",type:"vec3",inputs:[{name:"color",type:"vec3"}]}),Kb="WorkingColorSpace",Zb="OutputColorSpace";class Qb extends vv{static get type(){return"ColorSpaceNode"}constructor(t,e,n){super("vec4"),this.colorNode=t,this.source=e,this.target=n}resolveColorSpace(t,e){return e===Kb?yf.workingColorSpace:e===Zb?t.context.outputColorSpace||t.renderer.outputColorSpace:e}setup(t){const{colorNode:e}=this,n=this.resolveColorSpace(t,this.source),i=this.resolveColorSpace(t,this.target);let r=e;return!1!==yf.enabled&&n!==i&&n&&i?(yf.getTransfer(n)===Gp&&(r=Sy($b(r.rgb),r.a)),yf.getPrimaries(n)!==yf.getPrimaries(i)&&(r=Sy(Ay(yf._getMatrix(new mf,n,i)).mul(r.rgb),r.a)),yf.getTransfer(i)===Gp&&(r=Sy(Yb(r.rgb),r.a)),r):r}}const Jb=(t,e)=>ty(new Qb(ty(t),e,Kb));Rv("toOutputColorSpace",(t=>ty(new Qb(ty(t),Kb,Zb)))),Rv("toWorkingColorSpace",(t=>ty(new Qb(ty(t),Zb,Kb)))),Rv("workingToColorSpace",((t,e)=>ty(new Qb(ty(t),Kb,e)))),Rv("colorSpaceToWorking",Jb);let tS=class extends gv{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),n=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,n,i)}};class eS extends mv{static get type(){return"ReferenceBaseNode"}constructor(t,e,n=null,i=null){super(),this.property=t,this.uniformType=e,this.object=n,this.count=i,this.properties=t.split("."),this.reference=n,this.node=null,this.group=null,this.updateType=uv}setGroup(t){return this.group=t,this}element(t){return ty(new tS(this,ty(t)))}setNodeType(t){const e=Oy(null,t).getSelf();null!==this.group&&e.setGroup(this.group),this.node=e}getNodeType(t){return null===this.node&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let n=t[e[0]];for(let t=1;t<e.length;t++)n=n[e[t]];return n}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}}class nS extends eS{static get type(){return"RendererReferenceNode"}constructor(t,e,n=null){super(t,e,n),this.renderer=n,this.setGroup(Ly)}updateReference(t){return this.reference=null!==this.renderer?this.renderer:t.renderer,this.reference}}const iS=(t,e,n)=>ty(new nS(t,e,n));class rS extends vv{static get type(){return"ToneMappingNode"}constructor(t,e=sS,n=null){super("vec3"),this.toneMapping=t,this.exposureNode=e,this.colorNode=n}getCacheKey(){return ev(super.getCacheKey(),this.toneMapping)}setup(t){const e=this.colorNode||t.context.color,n=this.toneMapping;if(0===n)return e;let i=null;const r=t.renderer.library.getToneMappingFunction(n);return null!==r?i=Sy(r(e.rgb,this.exposureNode),e.a):(console.error("ToneMappingNode: Unsupported Tone Mapping configuration.",n),i=e),i}}const sS=iS("toneMappingExposure","float");Rv("toneMapping",((t,e,n)=>((t,e,n)=>ty(new rS(t,ty(e),ty(n))))(e,n,t)));class aS extends Tv{static get type(){return"BufferAttributeNode"}constructor(t,e=null,n=0,i=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferStride=n,this.bufferOffset=i,this.usage=Zp,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),n=this.value,i=t.getTypeLength(e),r=this.bufferStride||i,s=this.bufferOffset,a=!0===n.isInterleavedBuffer?n:new i_(n,r),o=new s_(a,i,s);a.setUsage(this.usage),this.attribute=o,this.attribute.isInstancedBufferAttribute=this.instanced}generate(t){const e=this.getNodeType(t),n=t.getBufferAttributeFromNode(this,e),i=t.getPropertyName(n);let r=null;if("vertex"===t.shaderStage||"compute"===t.shaderStage)this.name=i,r=i;else{r=Xb(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 oS=(t,e,n,i)=>ty(new aS(t,e,n,i)),lS=(t,e,n,i)=>oS(t,e,n,i).setInstanced(!0),hS=(t,e,n,i)=>((t,e,n,i)=>oS(t,e,n,i).setUsage(Qp))(t,e,n,i).setInstanced(!0);Rv("toAttribute",(t=>oS(t.value)));class uS extends mv{static get type(){return"ComputeNode"}constructor(t,e,n=[64]){super("void"),this.isComputeNode=!0,this.computeNode=t,this.count=e,this.workgroupSize=n,this.dispatchCount=0,this.version=1,this.updateBeforeType=uv,this.onInitFunction=null,this.updateDispatchCount()}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}updateDispatchCount(){const{count:t,workgroupSize:e}=this;let n=e[0];for(let t=1;t<e.length;t++)n*=e[t];this.dispatchCount=Math.ceil(t/n)}onInit(t){return this.onInitFunction=t,this}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,this)}}}Rv("compute",((t,e,n)=>ty(new uS(ty(t),e,n))));class cS extends mv{static get type(){return"CacheNode"}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 n=t.getCache(),i=t.getCacheFromNode(this,this.parent);t.setCache(i);const r=this.node.build(t,...e);return t.setCache(n),r}}const dS=(t,...e)=>ty(new cS(ty(t),...e));Rv("cache",dS);class pS extends mv{static get type(){return"BypassNode"}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),this.outputNode.build(t)}}Rv("bypass",iy(pS));class fS extends mv{static get type(){return"RemapNode"}constructor(t,e,n,i=uy(0),r=uy(1)){super(),this.node=t,this.inLowNode=e,this.inHighNode=n,this.outLowNode=i,this.outHighNode=r,this.doClamp=!0}setup(){const{node:t,inLowNode:e,inHighNode:n,outLowNode:i,outHighNode:r,doClamp:s}=this;let a=t.sub(e).div(n.sub(e));return!0===s&&(a=a.clamp()),a.mul(r.sub(i)).add(i)}}const mS=iy(fS,null,null,{doClamp:!1}),gS=iy(fS);Rv("remap",mS),Rv("remapClamp",gS);class _S extends mv{static get type(){return"ExpressionNode"}constructor(t="",e="void"){super(e),this.snippet=t}generate(t,e){const n=this.getNodeType(t),i=this.snippet;if("void"!==n)return t.format(`( ${i} )`,n,e);t.addLineFlowCode(i,this)}}const vS=iy(_S);Rv("discard",(t=>(t?Gb(t,vS("discard")):vS("discard")).append()));class yS extends vv{static get type(){return"RenderOutputNode"}constructor(t,e,n){super("vec4"),this.colorNode=t,this.toneMapping=e,this.outputColorSpace=n,this.isRenderOutput=!0}setup({context:t}){let e=this.colorNode||t.color;const n=(null!==this.toneMapping?this.toneMapping:t.toneMapping)||0,i=(null!==this.outputColorSpace?this.outputColorSpace:t.outputColorSpace)||Fp;return 0!==n&&(e=e.toneMapping(n)),i!==Fp&&i!==yf.workingColorSpace&&(e=e.workingToColorSpace(i)),e}}Rv("renderOutput",((t,e=null,n=null)=>ty(new yS(ty(t),e,n))));class xS extends mv{static get type(){return"AttributeNode"}constructor(t,e=null){super(e),this.global=!0,this._attributeName=t}getHash(t){return this.getAttributeName(t)}getNodeType(t){let e=this.nodeType;if(null===e){const n=this.getAttributeName(t);if(t.hasGeometryAttribute(n)){const i=t.geometry.getAttribute(n);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),n=this.getNodeType(t);if(!0===t.hasGeometryAttribute(e)){const i=t.geometry.getAttribute(e),r=t.getTypeFromAttribute(i),s=t.getAttribute(e,r);if("vertex"===t.shaderStage)return t.format(s.name,r,n);return Xb(this).build(t,n)}return console.warn(`AttributeNode: Vertex attribute "${e}" not found on geometry.`),t.generateConst(n)}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 bS=(t,e)=>ty(new xS(t,e)),SS=t=>bS("uv"+(t>0?t:""),"vec2");class MS extends mv{static get type(){return"TextureSizeNode"}constructor(t,e=null){super("uvec2"),this.isTextureSizeNode=!0,this.textureNode=t,this.levelNode=e}generate(t,e){const n=this.textureNode.build(t,"property"),i=null===this.levelNode?"0":this.levelNode.build(t,"int");return t.format(`${t.getMethod("textureDimensions")}( ${n}, ${i} )`,this.getNodeType(t),e)}}const TS=iy(MS);class wS extends Dy{static get type(){return"MaxMipLevelNode"}constructor(t){super(0),this._textureNode=t,this.updateType=lv}get textureNode(){return this._textureNode}get texture(){return this._textureNode.value}update(){const t=this.texture,e=t.images,n=e&&e.length>0?e[0]&&e[0].image||e[0]:t.image;if(n&&void 0!==n.width){const{width:t,height:e}=n;this.value=Math.log2(Math.max(t,e))}}}const ES=iy(wS);class AS extends Dy{static get type(){return"TextureNode"}constructor(t,e=null,n=null,i=null){super(t),this.isTextureNode=!0,this.uvNode=e,this.levelNode=n,this.biasNode=i,this.compareNode=null,this.depthNode=null,this.gradNode=null,this.sampler=!0,this.updateMatrix=!1,this.updateType=ov,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===ip?"uvec4":this.value.type===np?"ivec4":"vec4"}getInputType(){return"texture"}getDefaultUV(){return SS(this.value.channel)}updateReference(){return this.value}getTransformedUV(t){return null===this._matrixUniform&&(this._matrixUniform=Oy(this.value.matrix)),this._matrixUniform.mul(vy(t,1)).xy}setUpdateMatrix(t){return this.updateMatrix=t,this.updateType=t?lv:ov,this}setupUV(t,e){const n=this.value;return!t.isFlipY()||!0!==n.isRenderTargetTexture&&!0!==n.isFramebufferTexture&&!0!==n.isDepthTexture||(e=this.sampler?e.flipY():e.setY(cy(TS(this,this.levelNode).y).sub(e.y).sub(1))),e}setup(t){const e=t.getNodeProperties(this);e.referenceNode=this.referenceNode;let n=this.uvNode;null!==n&&!0!==t.context.forceUVContext||!t.context.getUV||(n=t.context.getUV(this)),n||(n=this.getDefaultUV()),!0===this.updateMatrix&&(n=this.getTransformedUV(n)),n=this.setupUV(t,n);let i=this.levelNode;null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),e.uvNode=n,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,n,i,r,s,a,o){const l=this.value;let h;return h=i?t.generateTextureLevel(l,e,n,i,s):r?t.generateTextureBias(l,e,n,r,s):o?t.generateTextureGrad(l,e,n,o,s):a?t.generateTextureCompare(l,e,n,a,s):!1===this.sampler?t.generateTextureLoad(l,e,n,s):t.generateTexture(l,e,n,s),h}generate(t,e){const n=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 s=t.getDataFromNode(this);let a=s.propertyName;if(void 0===a){const{uvNode:e,levelNode:i,biasNode:o,compareNode:l,depthNode:h,gradNode:u}=n,c=this.generateUV(t,e),d=i?i.build(t,"float"):null,p=o?o.build(t,"float"):null,f=h?h.build(t,"int"):null,m=l?l.build(t,"float"):null,g=u?[u[0].build(t,"vec2"),u[1].build(t,"vec2")]:null,_=t.getVarFromNode(this);a=t.getPropertyName(_);const v=this.generateSnippet(t,r,c,d,p,f,m,g);t.addLineFlowCode(`${a} = ${v}`,this),s.snippet=v,s.propertyName=a}let o=a;const l=this.getNodeType(t);return t.needsToWorkingColorSpace(i)&&(o=Jb(vS(o,l),i.colorSpace).setup(t).build(t,l)),t.format(o,l,e)}}setSampler(t){return this.sampler=t,this}getSampler(){return this.sampler}uv(t){const e=this.clone();return e.uvNode=ty(t),e.referenceNode=this.getSelf(),ty(e)}blur(t){const e=this.clone();return e.biasNode=ty(t).mul(ES(e)),e.referenceNode=this.getSelf(),ty(e)}level(t){const e=this.clone();return e.levelNode=ty(t),e.referenceNode=this.getSelf(),ty(e)}size(t){return TS(this,t)}bias(t){const e=this.clone();return e.biasNode=ty(t),e.referenceNode=this.getSelf(),ty(e)}compare(t){const e=this.clone();return e.compareNode=ty(t),e.referenceNode=this.getSelf(),ty(e)}grad(t,e){const n=this.clone();return n.gradNode=[ty(t),ty(e)],n.referenceNode=this.getSelf(),ty(n)}depth(t){const e=this.clone();return e.depthNode=ty(t),e.referenceNode=this.getSelf(),ty(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 RS=iy(AS),CS=(...t)=>RS(...t).setSampler(!1),NS=Oy("float").label("cameraNear").setGroup(Ly).onRenderUpdate((({camera:t})=>t.near)),PS=Oy("float").label("cameraFar").setGroup(Ly).onRenderUpdate((({camera:t})=>t.far)),IS=Oy("mat4").label("cameraProjectionMatrix").setGroup(Ly).onRenderUpdate((({camera:t})=>t.projectionMatrix)),LS=Oy("mat4").label("cameraViewMatrix").setGroup(Ly).onRenderUpdate((({camera:t})=>t.matrixWorldInverse)),US=Oy(new zf).label("cameraPosition").setGroup(Ly).onRenderUpdate((({camera:t},e)=>e.value.setFromMatrixPosition(t.matrixWorld)));class DS extends mv{static get type(){return"Object3DNode"}constructor(t,e=null){super(),this.scope=t,this.object3d=e,this.updateType=uv,this._uniformNode=new Dy(null)}getNodeType(){const t=this.scope;return t===DS.WORLD_MATRIX?"mat4":t===DS.POSITION||t===DS.VIEW_POSITION||t===DS.DIRECTION||t===DS.SCALE?"vec3":void 0}update(t){const e=this.object3d,n=this._uniformNode,i=this.scope;if(i===DS.WORLD_MATRIX)n.value=e.matrixWorld;else if(i===DS.POSITION)n.value=n.value||new zf,n.value.setFromMatrixPosition(e.matrixWorld);else if(i===DS.SCALE)n.value=n.value||new zf,n.value.setFromMatrixScale(e.matrixWorld);else if(i===DS.DIRECTION)n.value=n.value||new zf,e.getWorldDirection(n.value);else if(i===DS.VIEW_POSITION){const i=t.camera;n.value=n.value||new zf,n.value.setFromMatrixPosition(e.matrixWorld),n.value.applyMatrix4(i.matrixWorldInverse)}}generate(t){const e=this.scope;return e===DS.WORLD_MATRIX?this._uniformNode.nodeType="mat4":e!==DS.POSITION&&e!==DS.VIEW_POSITION&&e!==DS.DIRECTION&&e!==DS.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}}DS.WORLD_MATRIX="worldMatrix",DS.POSITION="position",DS.SCALE="scale",DS.VIEW_POSITION="viewPosition",DS.DIRECTION="direction",DS.DIRECTION,DS.WORLD_MATRIX,DS.POSITION,DS.SCALE,DS.VIEW_POSITION;class OS extends DS{static get type(){return"ModelNode"}constructor(t){super(t)}update(t){this.object3d=t.object,super.update(t)}}const FS=ry(OS,OS.WORLD_MATRIX),BS=Oy(new mf).onObjectUpdate((({object:t},e)=>e.value.getNormalMatrix(t.matrixWorld))),zS=LS.mul(FS).toVar("modelViewMatrix"),kS=bS("position","vec3"),GS=kS.varying("positionLocal"),VS=kS.varying("positionPrevious"),HS=FS.mul(GS).xyz.varying("v_positionWorld"),jS=GS.transformDirection(FS).varying("v_positionWorldDirection").normalize().toVar("positionWorldDirection"),WS=zS.mul(GS).xyz.varying("v_positionView"),qS=WS.negate().varying("v_positionViewDirection").normalize().toVar("positionViewDirection");class XS extends mv{static get type(){return"FrontFacingNode"}constructor(){super("bool"),this.isFrontFacingNode=!0}generate(t){const{renderer:e,material:n}=t;return e.coordinateSystem===Jp&&1===n.side?"false":t.getFrontFacing()}}const $S=uy(ry(XS)).mul(2).sub(1),YS=bS("normal","vec3"),KS=sy((t=>!1===t.geometry.hasAttribute("normal")?(console.warn('TSL.NormalNode: Vertex attribute "normal" not found on geometry.'),vy(0,1,0)):YS),"vec3").once()().toVar("normalLocal"),ZS=WS.dFdx().cross(WS.dFdy()).normalize().toVar("normalFlat"),QS=sy((t=>{let e;return e=!0===t.material.flatShading?ZS:Xb(rM(KS),"v_normalView").normalize(),e}),"vec3").once()().toVar("normalView"),JS=Xb(QS.transformDirection(LS),"v_normalWorld").normalize().toVar("normalWorld"),tM=sy((t=>t.context.setupNormal()),"vec3").once()().mul($S).toVar("transformedNormalView"),eM=tM.transformDirection(LS).toVar("transformedNormalWorld"),nM=sy((t=>t.context.setupClearcoatNormal()),"vec3").once()().mul($S).toVar("transformedClearcoatNormalView"),iM=sy((([t,e=FS])=>{const n=Ay(e),i=t.div(vy(n[0].dot(n[0]),n[1].dot(n[1]),n[2].dot(n[2])));return n.mul(i).xyz})),rM=sy((([t],e)=>{const n=e.renderer.nodes.modelNormalViewMatrix;if(null!==n)return n.transformDirection(t);const i=BS.mul(t);return LS.transformDirection(i)})),sM=Oy(0).onReference((({material:t})=>t)).onRenderUpdate((({material:t})=>t.refractionRatio)),aM=qS.negate().reflect(tM),oM=qS.negate().refract(tM,sM),lM=aM.transformDirection(LS).toVar("reflectVector"),hM=oM.transformDirection(LS).toVar("reflectVector");class uM extends AS{static get type(){return"CubeTextureNode"}constructor(t,e=null,n=null,i=null){super(t,e,n,i),this.isCubeTextureNode=!0}getInputType(){return"cubeTexture"}getDefaultUV(){const t=this.value;return t.mapping===zd?lM:t.mapping===kd?hM:(console.error('THREE.CubeTextureNode: Mapping "%s" not supported.',t.mapping),vy(0,0,0))}setUpdateMatrix(){}setupUV(t,e){const n=this.value;return t.renderer.coordinateSystem!==tf&&n.isRenderTargetTexture?e:vy(e.x.negate(),e.yz)}generateUV(t,e){return e.build(t,"vec3")}}const cM=iy(uM);class dM extends Dy{static get type(){return"BufferNode"}constructor(t,e,n=0){super(t,e),this.isBufferNode=!0,this.bufferType=e,this.bufferCount=n}getElementType(t){return this.getNodeType(t)}getInputType(){return"buffer"}}const pM=(t,e,n)=>ty(new dM(t,e,n));class fM extends gv{static get type(){return"UniformArrayElementNode"}constructor(t,e){super(t,e),this.isArrayBufferElementNode=!0}generate(t){const e=super.generate(t),n=this.getNodeType();return t.format(e,"vec4",n)}}class mM extends dM{static get type(){return"UniformArrayNode"}constructor(t,e=null){super(null,"vec4"),this.array=t,this.elementType=e,this._elementType=null,this._elementLength=0,this.updateType=hv,this.isArrayBufferNode=!0}getElementType(){return this.elementType||this._elementType}getElementLength(){return this._elementLength}update(){const{array:t,value:e}=this,n=this.getElementLength(),i=this.getElementType();if(1===n)for(let n=0;n<t.length;n++){e[4*n]=t[n]}else if("color"===i)for(let n=0;n<t.length;n++){const i=4*n,r=t[n];e[i]=r.r,e[i+1]=r.g,e[i+2]=r.b||0}else for(let n=0;n<t.length;n++){const i=4*n,r=t[n];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?rv(this.array[0]):this.elementType,this._elementLength=t.getTypeLength(this._elementType);let n=Float32Array;return"i"===this._elementType.charAt(0)?n=Int32Array:"u"===this._elementType.charAt(0)&&(n=Uint32Array),this.value=new n(4*e),this.bufferCount=e,this.bufferType=t.changeComponentType("vec4",t.getComponentType(this._elementType)),super.setup(t)}element(t){return ty(new fM(this,ty(t)))}}const gM=(t,e)=>ty(new mM(t,e));class _M extends gv{static get type(){return"ReferenceElementNode"}constructor(t,e){super(t,e),this.referenceNode=t,this.isReferenceElementNode=!0}getNodeType(){return this.referenceNode.uniformType}generate(t){const e=super.generate(t),n=this.referenceNode.getNodeType(),i=this.getNodeType();return t.format(e,n,i)}}class vM extends mv{static get type(){return"ReferenceNode"}constructor(t,e,n=null,i=null){super(),this.property=t,this.uniformType=e,this.object=n,this.count=i,this.properties=t.split("."),this.reference=n,this.node=null,this.group=null,this.name=null,this.updateType=uv}element(t){return ty(new _M(this,ty(t)))}setGroup(t){return this.group=t,this}label(t){return this.name=t,this}setNodeType(t){let e=null;e=null!==this.count?pM(null,t,this.count):Array.isArray(this.getValueFromReference())?gM(null,t):"texture"===t?RS(null):"cubeTexture"===t?cM(null):Oy(null,t),null!==this.group&&e.setGroup(this.group),null!==this.name&&e.label(this.name),this.node=e.getSelf()}getNodeType(t){return null===this.node&&(this.updateReference(t),this.updateValue()),this.node.getNodeType(t)}getValueFromReference(t=this.reference){const{properties:e}=this;let n=t[e[0]];for(let t=1;t<e.length;t++)n=n[e[t]];return n}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 yM=(t,e,n)=>ty(new vM(t,e,n)),xM=(t,e,n,i)=>ty(new vM(t,e,i,n));class bM extends vM{static get type(){return"MaterialReferenceNode"}constructor(t,e,n=null){super(t,e,n),this.material=n,this.isMaterialReferenceNode=!0}updateReference(t){return this.reference=null!==this.material?this.material:t.material,this.reference}}const SM=(t,e,n)=>ty(new bM(t,e,n)),MM=sy((t=>(!1===t.geometry.hasAttribute("tangent")&&t.geometry.computeTangents(),bS("tangent","vec4"))))(),TM=MM.xyz.toVar("tangentLocal"),wM=zS.mul(Sy(TM,0)).xyz.varying("v_tangentView").normalize().toVar("tangentView");var EM;const AM=Ay(wM,Xb((EM=QS.cross(wM),EM.mul(MM.w).xyz),"v_bitangentView").normalize().toVar("bitangentView"),QS),RM=(()=>{let t=tx.cross(qS);return t=t.cross(tx).normalize(),t=Ub(t,tM,Qy.mul(Vy.oneMinus()).oneMinus().pow2().pow2()).normalize(),t})(),CM=sy((t=>{const{eye_pos:e,surf_norm:n,mapN:i,uv:r}=t,s=e.dFdx(),a=e.dFdy(),o=r.dFdx(),l=r.dFdy(),h=n,u=a.cross(h),c=h.cross(s),d=u.mul(o.x).add(c.mul(l.x)),p=u.mul(o.y).add(c.mul(l.y)),f=d.dot(d).max(p.dot(p)),m=$S.mul(f.inverseSqrt());return gx(d.mul(i.x,m),p.mul(i.y,m),h.mul(i.z)).normalize()}));class NM extends vv{static get type(){return"NormalMapNode"}constructor(t,e=null){super("vec3"),this.node=t,this.scaleNode=e,this.normalMapType=0}setup(t){const{normalMapType:e,scaleNode:n}=this;let i=this.node.mul(2).sub(1);null!==n&&(i=vy(i.xy.mul(n),i.z));let r=null;if(1===e)r=rM(i);else if(0===e){r=!0===t.hasGeometryAttribute("tangent")?AM.mul(i).normalize():CM({eye_pos:WS,surf_norm:QS,mapN:i,uv:SS()})}return r}}const PM=iy(NM),IM=sy((({textureNode:t,bumpScale:e})=>{const n=e=>t.cache().context({getUV:t=>e(t.uvNode||SS()),forceUVContext:!0}),i=uy(n((t=>t)));return fy(uy(n((t=>t.add(t.dFdx())))).sub(i),uy(n((t=>t.add(t.dFdy())))).sub(i)).mul(e)})),LM=sy((t=>{const{surf_pos:e,surf_norm:n,dHdxy:i}=t,r=e.dFdx().normalize(),s=n,a=e.dFdy().normalize().cross(s),o=s.cross(r),l=r.dot(a).mul($S),h=l.sign().mul(i.x.mul(a).add(i.y.mul(o)));return l.abs().mul(n).sub(h).normalize()}));class UM extends vv{static get type(){return"BumpMapNode"}constructor(t,e=null){super("vec3"),this.textureNode=t,this.scaleNode=e}setup(){const t=null!==this.scaleNode?this.scaleNode:1,e=IM({textureNode:this.textureNode,bumpScale:t});return LM({surf_pos:WS,surf_norm:QS,dHdxy:e})}}const DM=iy(UM),OM=new Map;class FM extends mv{static get type(){return"MaterialNode"}constructor(t){super(),this.scope=t}getCache(t,e){let n=OM.get(t);return void 0===n&&(n=SM(t,e),OM.set(t,n)),n}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,n=this.scope;let i=null;if(n===FM.COLOR){const t=void 0!==e.color?this.getColor(n):vy();i=e.map&&!0===e.map.isTexture?t.mul(this.getTexture("map")):t}else if(n===FM.OPACITY){const t=this.getFloat(n);i=e.alphaMap&&!0===e.alphaMap.isTexture?t.mul(this.getTexture("alpha")):t}else if(n===FM.SPECULAR_STRENGTH)i=e.specularMap&&!0===e.specularMap.isTexture?this.getTexture("specular").r:uy(1);else if(n===FM.SPECULAR_INTENSITY){const t=this.getFloat(n);i=e.specularMap?t.mul(this.getTexture(n).a):t}else if(n===FM.SPECULAR_COLOR){const t=this.getColor(n);i=e.specularColorMap&&!0===e.specularColorMap.isTexture?t.mul(this.getTexture(n).rgb):t}else if(n===FM.ROUGHNESS){const t=this.getFloat(n);i=e.roughnessMap&&!0===e.roughnessMap.isTexture?t.mul(this.getTexture(n).g):t}else if(n===FM.METALNESS){const t=this.getFloat(n);i=e.metalnessMap&&!0===e.metalnessMap.isTexture?t.mul(this.getTexture(n).b):t}else if(n===FM.EMISSIVE){const t=this.getFloat("emissiveIntensity"),r=this.getColor(n).mul(t);i=e.emissiveMap&&!0===e.emissiveMap.isTexture?r.mul(this.getTexture(n)):r}else if(n===FM.NORMAL)e.normalMap?(i=PM(this.getTexture("normal"),this.getCache("normalScale","vec2")),i.normalMapType=e.normalMapType):i=e.bumpMap?DM(this.getTexture("bump").r,this.getFloat("bumpScale")):QS;else if(n===FM.CLEARCOAT){const t=this.getFloat(n);i=e.clearcoatMap&&!0===e.clearcoatMap.isTexture?t.mul(this.getTexture(n).r):t}else if(n===FM.CLEARCOAT_ROUGHNESS){const t=this.getFloat(n);i=e.clearcoatRoughnessMap&&!0===e.clearcoatRoughnessMap.isTexture?t.mul(this.getTexture(n).r):t}else if(n===FM.CLEARCOAT_NORMAL)i=e.clearcoatNormalMap?PM(this.getTexture(n),this.getCache(n+"Scale","vec2")):QS;else if(n===FM.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(n===FM.SHEEN_ROUGHNESS){const t=this.getFloat(n);i=e.sheenRoughnessMap&&!0===e.sheenRoughnessMap.isTexture?t.mul(this.getTexture(n).a):t,i=i.clamp(.07,1)}else if(n===FM.ANISOTROPY)if(e.anisotropyMap&&!0===e.anisotropyMap.isTexture){const t=this.getTexture(n);i=Ey(vT.x,vT.y,vT.y.negate(),vT.x).mul(t.rg.mul(2).sub(fy(1)).normalize().mul(t.b))}else i=vT;else if(n===FM.IRIDESCENCE_THICKNESS){const t=yM("1","float",e.iridescenceThicknessRange);if(e.iridescenceThicknessMap){const r=yM("0","float",e.iridescenceThicknessRange);i=t.sub(r).mul(this.getTexture(n).g).add(r)}else i=t}else if(n===FM.TRANSMISSION){const t=this.getFloat(n);i=e.transmissionMap?t.mul(this.getTexture(n).r):t}else if(n===FM.THICKNESS){const t=this.getFloat(n);i=e.thicknessMap?t.mul(this.getTexture(n).g):t}else if(n===FM.IOR)i=this.getFloat(n);else if(n===FM.LIGHT_MAP)i=this.getTexture(n).rgb.mul(this.getFloat("lightMapIntensity"));else if(n===FM.AO_MAP)i=this.getTexture(n).r.sub(1).mul(this.getFloat("aoMapIntensity")).add(1);else{const e=this.getNodeType(t);i=this.getCache(n,e)}return i}}FM.ALPHA_TEST="alphaTest",FM.COLOR="color",FM.OPACITY="opacity",FM.SHININESS="shininess",FM.SPECULAR="specular",FM.SPECULAR_STRENGTH="specularStrength",FM.SPECULAR_INTENSITY="specularIntensity",FM.SPECULAR_COLOR="specularColor",FM.REFLECTIVITY="reflectivity",FM.ROUGHNESS="roughness",FM.METALNESS="metalness",FM.NORMAL="normal",FM.CLEARCOAT="clearcoat",FM.CLEARCOAT_ROUGHNESS="clearcoatRoughness",FM.CLEARCOAT_NORMAL="clearcoatNormal",FM.EMISSIVE="emissive",FM.ROTATION="rotation",FM.SHEEN="sheen",FM.SHEEN_ROUGHNESS="sheenRoughness",FM.ANISOTROPY="anisotropy",FM.IRIDESCENCE="iridescence",FM.IRIDESCENCE_IOR="iridescenceIOR",FM.IRIDESCENCE_THICKNESS="iridescenceThickness",FM.IOR="ior",FM.TRANSMISSION="transmission",FM.THICKNESS="thickness",FM.ATTENUATION_DISTANCE="attenuationDistance",FM.ATTENUATION_COLOR="attenuationColor",FM.LINE_SCALE="scale",FM.LINE_DASH_SIZE="dashSize",FM.LINE_GAP_SIZE="gapSize",FM.LINE_WIDTH="linewidth",FM.LINE_DASH_OFFSET="dashOffset",FM.POINT_WIDTH="pointWidth",FM.DISPERSION="dispersion",FM.LIGHT_MAP="light",FM.AO_MAP="ao";const BM=ry(FM,FM.ALPHA_TEST),zM=ry(FM,FM.COLOR),kM=ry(FM,FM.SHININESS),GM=ry(FM,FM.EMISSIVE),VM=ry(FM,FM.OPACITY),HM=ry(FM,FM.SPECULAR),jM=ry(FM,FM.SPECULAR_INTENSITY),WM=ry(FM,FM.SPECULAR_COLOR),qM=ry(FM,FM.SPECULAR_STRENGTH),XM=ry(FM,FM.REFLECTIVITY),$M=ry(FM,FM.ROUGHNESS),YM=ry(FM,FM.METALNESS),KM=ry(FM,FM.NORMAL).context({getUV:null}),ZM=ry(FM,FM.CLEARCOAT),QM=ry(FM,FM.CLEARCOAT_ROUGHNESS),JM=ry(FM,FM.CLEARCOAT_NORMAL).context({getUV:null}),tT=ry(FM,FM.ROTATION),eT=ry(FM,FM.SHEEN),nT=ry(FM,FM.SHEEN_ROUGHNESS),iT=ry(FM,FM.ANISOTROPY),rT=ry(FM,FM.IRIDESCENCE),sT=ry(FM,FM.IRIDESCENCE_IOR),aT=ry(FM,FM.IRIDESCENCE_THICKNESS),oT=ry(FM,FM.TRANSMISSION),lT=ry(FM,FM.THICKNESS),hT=ry(FM,FM.IOR),uT=ry(FM,FM.ATTENUATION_DISTANCE),cT=ry(FM,FM.ATTENUATION_COLOR),dT=ry(FM,FM.LINE_SCALE),pT=ry(FM,FM.LINE_DASH_SIZE),fT=ry(FM,FM.LINE_GAP_SIZE);FM.LINE_WIDTH,FM.LINE_DASH_OFFSET,FM.POINT_WIDTH;const mT=ry(FM,FM.DISPERSION),gT=ry(FM,FM.LIGHT_MAP),_T=ry(FM,FM.AO_MAP),vT=Oy(new ff).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))}));class yT extends vv{static get type(){return"ModelViewProjectionNode"}constructor(t=null){super("vec4"),this.positionNode=t}setup(t){if("fragment"===t.shaderStage)return Xb(t.context.mvp);const e=this.positionNode||GS,n=t.renderer.nodes.modelViewMatrix||zS;return IS.mul(n).mul(e)}}const xT=iy(yT);class bT extends mv{static get type(){return"IndexNode"}constructor(t){super("uint"),this.scope=t,this.isInstanceIndexNode=!0}generate(t){const e=this.getNodeType(t),n=this.scope;let i,r;if(n===bT.VERTEX)i=t.getVertexIndex();else if(n===bT.INSTANCE)i=t.getInstanceIndex();else if(n===bT.DRAW)i=t.getDrawIndex();else if(n===bT.INVOCATION_LOCAL)i=t.getInvocationLocalIndex();else if(n===bT.INVOCATION_SUBGROUP)i=t.getInvocationSubgroupIndex();else{if(n!==bT.SUBGROUP)throw new Error("THREE.IndexNode: Unknown scope: "+n);i=t.getSubgroupIndex()}if("vertex"===t.shaderStage||"compute"===t.shaderStage)r=i;else{r=Xb(this).build(t,e)}return r}}bT.VERTEX="vertex",bT.INSTANCE="instance",bT.SUBGROUP="subgroup",bT.INVOCATION_LOCAL="invocationLocal",bT.INVOCATION_SUBGROUP="invocationSubgroup",bT.DRAW="draw";const ST=ry(bT,bT.VERTEX),MT=ry(bT,bT.INSTANCE);bT.SUBGROUP,bT.INVOCATION_SUBGROUP,bT.INVOCATION_LOCAL;const TT=ry(bT,bT.DRAW);class wT extends mv{static get type(){return"InstanceNode"}constructor(t){super("void"),this.instanceMesh=t,this.instanceMatrixNode=null,this.instanceColorNode=null,this.updateType=lv,this.buffer=null,this.bufferColor=null}setup(t){let e=this.instanceMatrixNode,n=this.instanceColorNode;const i=this.instanceMesh;if(null===e){const t=i.instanceMatrix;if(i.count<=1e3)e=pM(t.array,"mat4",Math.max(i.count,1)).element(MT);else{const n=new K_(t.array,16,1);this.buffer=n;const i=t.usage===Qp?hS:lS,r=[i(n,"vec4",16,0),i(n,"vec4",16,4),i(n,"vec4",16,8),i(n,"vec4",16,12)];e=Ry(...r)}this.instanceMatrixNode=e}const r=i.instanceColor;if(r&&null===n){const t=new l_(r.array,3),e=r.usage===Qp?hS:lS;this.bufferColor=t,n=vy(e(t,"vec3",3,0)),this.instanceColorNode=n}const s=e.mul(GS).xyz;if(GS.assign(s),t.hasGeometryAttribute("normal")){const t=iM(KS,e);KS.assign(t)}null!==this.instanceColorNode&&zy("vec3","vInstanceColor").assign(this.instanceColorNode)}update(){this.instanceMesh.instanceMatrix.usage!==Qp&&null!=this.buffer&&this.instanceMesh.instanceMatrix.version!==this.buffer.version&&(this.buffer.version=this.instanceMesh.instanceMatrix.version),this.instanceMesh.instanceColor&&this.instanceMesh.instanceColor.usage!==Qp&&null!=this.bufferColor&&this.instanceMesh.instanceColor.version!==this.bufferColor.version&&(this.bufferColor.version=this.instanceMesh.instanceColor.version)}}const ET=iy(wT);class AT extends mv{static get type(){return"BatchNode"}constructor(t){super("void"),this.batchMesh=t,this.batchingIdNode=null}setup(t){null===this.batchingIdNode&&(null===t.getDrawIndex()?this.batchingIdNode=MT:this.batchingIdNode=TT);const e=sy((([t])=>{const e=TS(CS(this.batchMesh._indirectTexture),0),n=cy(t).modInt(cy(e)),i=cy(t).div(cy(e));return CS(this.batchMesh._indirectTexture,my(n,i)).x})).setLayout({name:"getIndirectIndex",type:"uint",inputs:[{name:"id",type:"int"}]}),n=e(cy(this.batchingIdNode)),i=this.batchMesh._matricesTexture,r=TS(CS(i),0),s=uy(n).mul(4).toInt().toVar(),a=s.modInt(r),o=s.div(cy(r)),l=Ry(CS(i,my(a,o)),CS(i,my(a.add(1),o)),CS(i,my(a.add(2),o)),CS(i,my(a.add(3),o))),h=this.batchMesh._colorsTexture;if(null!==h){const t=sy((([t])=>{const e=TS(CS(h),0).x,n=t,i=n.modInt(e),r=n.div(e);return CS(h,my(i,r)).rgb})).setLayout({name:"getBatchingColor",type:"vec3",inputs:[{name:"id",type:"int"}]}),e=t(n);zy("vec3","vBatchColor").assign(e)}const u=Ay(l);GS.assign(l.mul(GS));const c=KS.div(vy(u[0].dot(u[0]),u[1].dot(u[1]),u[2].dot(u[2]))),d=u.mul(c).xyz;KS.assign(d),t.hasGeometryAttribute("tangent")&&TM.mulAssign(u)}}const RT=iy(AT),CT=new WeakMap;class NT extends mv{static get type(){return"SkinningNode"}constructor(t,e=!1){let n,i,r;super("void"),this.skinnedMesh=t,this.useReference=e,this.updateType=uv,this.skinIndexNode=bS("skinIndex","uvec4"),this.skinWeightNode=bS("skinWeight","vec4"),e?(n=yM("bindMatrix","mat4"),i=yM("bindMatrixInverse","mat4"),r=xM("skeleton.boneMatrices","mat4",t.skeleton.bones.length)):(n=Oy(t.bindMatrix,"mat4"),i=Oy(t.bindMatrixInverse,"mat4"),r=pM(t.skeleton.boneMatrices,"mat4",t.skeleton.bones.length)),this.bindMatrixNode=n,this.bindMatrixInverseNode=i,this.boneMatricesNode=r,this.previousBoneMatricesNode=null}getSkinnedPosition(t=this.boneMatricesNode,e=GS){const{skinIndexNode:n,skinWeightNode:i,bindMatrixNode:r,bindMatrixInverseNode:s}=this,a=t.element(n.x),o=t.element(n.y),l=t.element(n.z),h=t.element(n.w),u=r.mul(e),c=gx(a.mul(i.x).mul(u),o.mul(i.y).mul(u),l.mul(i.z).mul(u),h.mul(i.w).mul(u));return s.mul(c).xyz}getSkinnedNormal(t=this.boneMatricesNode,e=KS){const{skinIndexNode:n,skinWeightNode:i,bindMatrixNode:r,bindMatrixInverseNode:s}=this,a=t.element(n.x),o=t.element(n.y),l=t.element(n.z),h=t.element(n.w);let u=gx(i.x.mul(a),i.y.mul(o),i.z.mul(l),i.w.mul(h));return u=s.mul(u).mul(r),u.transformDirection(e).xyz}getPreviousSkinnedPosition(t){const e=t.object;return null===this.previousBoneMatricesNode&&(e.skeleton.previousBoneMatrices=new Float32Array(e.skeleton.boneMatrices),this.previousBoneMatricesNode=xM("skeleton.previousBoneMatrices","mat4",e.skeleton.bones.length)),this.getSkinnedPosition(this.previousBoneMatricesNode,VS)}needsPreviousBoneMatrices(t){const e=t.renderer.getMRT();return e&&e.has("velocity")}setup(t){this.needsPreviousBoneMatrices(t)&&VS.assign(this.getPreviousSkinnedPosition(t));const e=this.getSkinnedPosition();if(GS.assign(e),t.hasGeometryAttribute("normal")){const e=this.getSkinnedNormal();KS.assign(e),t.hasGeometryAttribute("tangent")&&TM.assign(e)}}generate(t,e){if("void"!==e)return GS.build(t,e)}update(t){const e=(this.useReference?t.object:this.skinnedMesh).skeleton;CT.get(e)!==t.frameId&&(CT.set(e,t.frameId),null!==this.previousBoneMatricesNode&&e.previousBoneMatrices.set(e.boneMatrices),e.update())}}class PT extends mv{static get type(){return"LoopNode"}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 n={};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";n[i]=vS(i,r)}const i=t.addStack();return e.returnsNode=this.params[this.params.length-1](n,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),n=this.params,i=e.stackNode;for(let e=0,i=n.length-1;e<i;e++){const i=n[e];let r=null,s=null,a=null,o=null,l=null,h=null;i.isNode?(o="int",a=this.getVarName(e),r="0",s=i.build(t,o),l="<"):(o=i.type||"int",a=i.name||this.getVarName(e),r=i.start,s=i.end,l=i.condition,h=i.update,"number"==typeof r?r=t.generateConst(o,r):r&&r.isNode&&(r=r.build(t,o)),"number"==typeof s?s=t.generateConst(o,s):s&&s.isNode&&(s=s.build(t,o)),void 0!==r&&void 0===s?(r+=" - 1",s="0",l=">="):void 0!==s&&void 0===r&&(r="0",l="<"),void 0===l&&(l=Number(r)>Number(s)?">=":"<"));const u={start:r,end:s,condition:l},c=u.start,d=u.end;let p="",f="",m="";h||(h="int"===o||"uint"===o?l.includes("<")?"++":"--":l.includes("<")?"+= 1.":"-= 1."),p+=t.getVar(o,a)+" = "+c,f+=a+" "+l+" "+d,m+=a+" "+h;const g=`for ( ${p}; ${f}; ${m} )`;t.addFlowCode((0===e?"\n":"")+t.tab+g+" {\n\n").addFlowTab()}const r=i.build(t,"void"),s=e.returnsNode?e.returnsNode.build(t):"";t.removeFlowTab().addFlowCode("\n"+t.tab+r);for(let e=0,n=this.params.length-1;e<n;e++)t.addFlowCode((0===e?"":t.tab)+"}\n\n").removeFlowTab();return t.addFlowTab(),s}}const IT=(...t)=>ty(new PT(ny(t,"int"))).append(),LT=new WeakMap,UT=new Uf,DT=sy((({bufferMap:t,influence:e,stride:n,width:i,depth:r,offset:s})=>{const a=cy(ST).mul(n).add(s),o=a.div(i),l=a.sub(o.mul(i));return CS(t,my(l,o)).depth(r).mul(e)}));class OT extends mv{static get type(){return"MorphNode"}constructor(t){super("void"),this.mesh=t,this.morphBaseInfluence=Oy(1),this.updateType=uv}setup(t){const{geometry:e}=t,n=void 0!==e.morphAttributes.position,i=e.hasAttribute("normal")&&void 0!==e.morphAttributes.normal,r=e.morphAttributes.position||e.morphAttributes.normal||e.morphAttributes.color,s=void 0!==r?r.length:0,{texture:a,stride:o,size:l}=function(t){const e=void 0!==t.morphAttributes.position,n=void 0!==t.morphAttributes.normal,i=void 0!==t.morphAttributes.color,r=t.morphAttributes.position||t.morphAttributes.normal||t.morphAttributes.color,s=void 0!==r?r.length:0;let a=LT.get(t);if(void 0===a||a.count!==s){void 0!==a&&a.texture.dispose();const o=t.morphAttributes.position||[],l=t.morphAttributes.normal||[],h=t.morphAttributes.color||[];let u=0;!0===e&&(u=1),!0===n&&(u=2),!0===i&&(u=3);let c=t.attributes.position.count*u,d=1;const p=4096;c>p&&(d=Math.ceil(c/p),c=p);const f=new Float32Array(c*d*4*s),m=new Ff(f,c,d,s);m.type=rp,m.needsUpdate=!0;const g=4*u;for(let v=0;v<s;v++){const y=o[v],x=l[v],b=h[v],S=c*d*4*v;for(let M=0;M<y.count;M++){const T=M*g;!0===e&&(UT.fromBufferAttribute(y,M),f[S+T+0]=UT.x,f[S+T+1]=UT.y,f[S+T+2]=UT.z,f[S+T+3]=0),!0===n&&(UT.fromBufferAttribute(x,M),f[S+T+4]=UT.x,f[S+T+5]=UT.y,f[S+T+6]=UT.z,f[S+T+7]=0),!0===i&&(UT.fromBufferAttribute(b,M),f[S+T+8]=UT.x,f[S+T+9]=UT.y,f[S+T+10]=UT.z,f[S+T+11]=4===b.itemSize?UT.w:1)}}function _(){m.dispose(),LT.delete(t),t.removeEventListener("dispose",_)}a={count:s,texture:m,stride:u,size:new ff(c,d)},LT.set(t,a),t.addEventListener("dispose",_)}return a}(e);!0===n&&GS.mulAssign(this.morphBaseInfluence),!0===i&&KS.mulAssign(this.morphBaseInfluence);const h=cy(l.width);IT(s,(({i:t})=>{const e=uy(0).toVar();this.mesh.count>1&&null!==this.mesh.morphTexture&&void 0!==this.mesh.morphTexture?e.assign(CS(this.mesh.morphTexture,my(cy(t).add(1),cy(MT))).r):e.assign(yM("morphTargetInfluences","float").element(t).toVar()),!0===n&&GS.addAssign(DT({bufferMap:a,influence:e,stride:o,width:h,depth:t,offset:cy(0)})),!0===i&&KS.addAssign(DT({bufferMap:a,influence:e,stride:o,width:h,depth:t,offset:cy(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 FT=iy(OT);class BT extends mv{static get type(){return"LightingNode"}constructor(){super("vec3"),this.isLightingNode=!0}generate(){console.warn("Abstract function.")}}class zT extends BT{static get type(){return"AONode"}constructor(t=null){super(),this.aoNode=t}setup(t){t.context.ambientOcclusion.mulAssign(this.aoNode)}}class kT extends Vb{static get type(){return"LightingContextNode"}constructor(t,e=null,n=null,i=null){super(t),this.lightingModel=e,this.backdropNode=n,this.backdropAlphaNode=i,this._value=null}getContext(){const{backdropNode:t,backdropAlphaNode:e}=this,n={directDiffuse:vy().toVar("directDiffuse"),directSpecular:vy().toVar("directSpecular"),indirectDiffuse:vy().toVar("indirectDiffuse"),indirectSpecular:vy().toVar("indirectSpecular")};return{radiance:vy().toVar("radiance"),irradiance:vy().toVar("irradiance"),iblIrradiance:vy().toVar("iblIrradiance"),ambientOcclusion:uy(1).toVar("ambientOcclusion"),reflectedLight:n,backdrop:t,backdropAlpha:e}}setup(t){return this.value=this._value||(this._value=this.getContext()),this.value.lightingModel=this.lightingModel||t.context.lightingModel,super.setup(t)}}const GT=iy(kT);class VT extends BT{static get type(){return"IrradianceNode"}constructor(t){super(),this.node=t}setup(t){t.context.irradiance.addAssign(this.node)}}let HT,jT;class WT extends mv{static get type(){return"ScreenNode"}constructor(t){super(),this.scope=t,this.isViewportNode=!0}getNodeType(){return this.scope===WT.VIEWPORT?"vec4":"vec2"}getUpdateType(){let t=ov;return this.scope!==WT.SIZE&&this.scope!==WT.VIEWPORT||(t=hv),this.updateType=t,t}update({renderer:t}){const e=t.getRenderTarget();this.scope===WT.VIEWPORT?null!==e?jT.copy(e.viewport):(t.getViewport(jT),jT.multiplyScalar(t.getPixelRatio())):null!==e?(HT.width=e.width,HT.height=e.height):t.getDrawingBufferSize(HT)}setup(){const t=this.scope;let e=null;return e=t===WT.SIZE?Oy(HT||(HT=new ff)):t===WT.VIEWPORT?Oy(jT||(jT=new Uf)):fy($T.div(XT)),e}generate(t){if(this.scope===WT.COORDINATE){let e=t.getFragCoord();if(t.isFlipY()){const n=t.getNodeProperties(XT).outputNode.build(t);e=`${t.getType("vec2")}( ${e}.x, ${n}.y - ${e}.y )`}return e}return super.generate(t)}}WT.COORDINATE="coordinate",WT.VIEWPORT="viewport",WT.SIZE="size",WT.UV="uv";const qT=ry(WT,WT.UV),XT=ry(WT,WT.SIZE),$T=ry(WT,WT.COORDINATE),YT=ry(WT,WT.VIEWPORT);YT.zw,YT.xy;const KT=new ff;class ZT extends AS{static get type(){return"ViewportTextureNode"}constructor(t=qT,e=null,n=null){null===n&&((n=new v_).minFilter=Zd),super(n,t,e),this.generateMipmaps=!1,this.isOutputTextureNode=!0,this.updateBeforeType=lv}updateBefore(t){const e=t.renderer;e.getDrawingBufferSize(KT);const n=this.value;n.image.width===KT.width&&n.image.height===KT.height||(n.image.width=KT.width,n.image.height=KT.height,n.needsUpdate=!0);const i=n.generateMipmaps;n.generateMipmaps=this.generateMipmaps,e.copyFramebufferToTexture(n),n.generateMipmaps=i}clone(){const t=new this.constructor(this.uvNode,this.levelNode,this.value);return t.generateMipmaps=this.generateMipmaps,t}}const QT=iy(ZT,null,null,{generateMipmaps:!0});let JT=null;class tw extends ZT{static get type(){return"ViewportDepthTextureNode"}constructor(t=qT,e=null){null===JT&&(JT=new y_),super(t,e,JT)}}const ew=iy(tw);class nw extends mv{static get type(){return"ViewportDepthNode"}constructor(t,e=null){super("float"),this.scope=t,this.valueNode=e,this.isViewportDepthNode=!0}generate(t){const{scope:e}=this;return e===nw.DEPTH_BASE?t.getFragDepth():super.generate(t)}setup({camera:t}){const{scope:e}=this,n=this.valueNode;let i=null;if(e===nw.DEPTH_BASE)null!==n&&(i=ow().assign(n));else if(e===nw.DEPTH)i=t.isPerspectiveCamera?rw(WS.z,NS,PS):iw(WS.z,NS,PS);else if(e===nw.LINEAR_DEPTH)if(null!==n)if(t.isPerspectiveCamera){const t=sw(n,NS,PS);i=iw(t,NS,PS)}else i=n;else i=iw(WS.z,NS,PS);return i}}nw.DEPTH_BASE="depthBase",nw.DEPTH="depth",nw.LINEAR_DEPTH="linearDepth";const iw=(t,e,n)=>t.add(e).div(e.sub(n)),rw=(t,e,n)=>e.add(t).mul(n).div(n.sub(e).mul(t)),sw=(t,e,n)=>e.mul(n).div(n.sub(e).mul(t).sub(n)),aw=(t,e,n)=>{e=e.max(1e-6).toVar();const i=$x(t.div(e).add(1)),r=$x(n.div(e).add(1));return i.div(r)},ow=iy(nw,nw.DEPTH_BASE),lw=ry(nw,nw.DEPTH);nw.LINEAR_DEPTH;ew(),lw.assign=t=>ow(t);class hw extends mv{static get type(){return"ClippingNode"}constructor(t=hw.DEFAULT){super(),this.scope=t}setup(t){super.setup(t);const e=t.clippingContext,{localClipIntersection:n,localClippingCount:i,globalClippingCount:r}=e,s=r+i,a=n?s-i:s;return this.scope===hw.ALPHA_TO_COVERAGE?this.setupAlphaToCoverage(e.planes,s,a):this.setupDefault(e.planes,s,a)}setupAlphaToCoverage(t,e,n){return sy((()=>{const i=gM(t),r=By("float","distanceToPlane"),s=By("float","distanceToGradient"),a=By("float","clipOpacity");let o;if(a.assign(1),IT(n,(({i:t})=>{o=i.element(t),r.assign(WS.dot(o.xyz).negate().add(o.w)),s.assign(r.fwidth().div(2)),a.mulAssign(Fb(s.negate(),s,r)),a.equal(0).discard()})),n<e){const t=By("float","unionclipOpacity");t.assign(1),IT({start:n,end:e},(({i:e})=>{o=i.element(e),r.assign(WS.dot(o.xyz).negate().add(o.w)),s.assign(r.fwidth().div(2)),t.mulAssign(Fb(s.negate(),s,r).oneMinus())})),a.mulAssign(t.oneMinus())}ky.a.mulAssign(a),ky.a.equal(0).discard()}))()}setupDefault(t,e,n){return sy((()=>{const i=gM(t);let r;if(IT(n,(({i:t})=>{r=i.element(t),WS.dot(r.xyz).greaterThan(r.w).discard()})),n<e){const t=By("bool","clipped");t.assign(!0),IT({start:n,end:e},(({i:e})=>{r=i.element(e),t.assign(WS.dot(r.xyz).greaterThan(r.w).and(t))})),t.discard()}}))()}}hw.ALPHA_TO_COVERAGE="alphaToCoverage",hw.DEFAULT="default";const uw=sy((([t])=>tb(vx(1e4,eb(vx(17,t.x).add(vx(.1,t.y)))).mul(gx(.1,ob(eb(vx(13,t.y).add(t.x)))))))),cw=sy((([t])=>uw(fy(uw(t.xy),t.z)))),dw=sy((([t])=>{const e=bb(hb(db(t.xyz)),hb(pb(t.xyz))).toVar("maxDeriv"),n=uy(1).div(uy(.05).mul(e)).toVar("pixScale"),i=fy(qx(Zx($x(n))),qx(Qx($x(n)))).toVar("pixScales"),r=fy(cw(Zx(i.x.mul(t.xyz))),cw(Zx(i.y.mul(t.xyz)))).toVar("alpha"),s=tb($x(n)).toVar("lerpFactor"),a=gx(vx(s.oneMinus(),r.x),vx(s,r.y)).toVar("x"),o=xb(s,s.oneMinus()).toVar("a"),l=vy(a.mul(a).div(vx(2,o).mul(_x(1,o))),a.sub(vx(.5,o)).div(_x(1,o)),_x(1,_x(1,a).mul(_x(1,a)).div(vx(2,o).mul(_x(1,o))))).toVar("cases"),h=a.lessThan(o.oneMinus()).select(a.lessThan(o).select(l.x,l.y),l.z);return Db(h,1e-6,1)}));class pw extends ug{static get type(){return"NodeMaterial"}constructor(){super(),this.isNodeMaterial=!0,this.type=this.constructor.type,this.forceSinglePass=!1,this.fog=!0,this.lights=!1,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.geometryNode=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+nv(this)}build(t){this.setup(t)}setupObserver(t){return new Q_(t)}setup(t){let e;t.context.setupNormal=()=>this.setupNormal(t),t.addStack(),t.stack.outputNode=this.vertexNode||this.setupPosition(t),null!==this.geometryNode&&(t.stack.outputNode=t.stack.outputNode.bypass(this.geometryNode)),t.addFlow("vertex",t.removeStack()),t.addStack();const n=this.setupClipping(t);if(!0===this.depthWrite&&this.setupDepth(t),null===this.fragmentNode){this.setupDiffuseColor(t),this.setupVariants(t);const i=this.setupLighting(t);null!==n&&t.stack.add(n);const r=Sy(i,ky.a).max(0);e=this.setupOutput(t,r),rx.assign(e),null!==this.outputNode&&(e=this.outputNode);if(null!==t.renderer.getRenderTarget()){const n=t.renderer.getMRT(),i=this.mrtNode;null!==n?(e=n,null!==i&&(e=n.merge(i))):null!==i&&(e=i)}}else{let n=this.fragmentNode;!0!==n.isOutputStructNode&&(n=Sy(n)),e=this.setupOutput(t,n)}t.stack.outputNode=e,t.addFlow("fragment",t.removeStack()),t.monitor=this.setupObserver(t)}setupClipping(t){if(null===t.clippingContext)return null;const{globalClippingCount:e,localClippingCount:n}=t.clippingContext;let i=null;if(e||n){const e=t.renderer.samples;this.alphaToCoverage&&e>1?i=ty(new hw(hw.ALPHA_TO_COVERAGE)):t.stack.add(ty(new hw))}return i}setupDepth(t){const{renderer:e,camera:n}=t;let i=this.depthNode;if(null===i){const t=e.getMRT();t&&t.has("depth")?i=t.get("depth"):!0===e.logarithmicDepthBuffer&&(i=n.isPerspectiveCamera?aw(xT().w,NS,PS):iw(WS.z,NS,PS))}null!==i&&lw.assign(i).append()}setupPosition(t){const{object:e}=t,n=e.geometry;var i;if(t.addStack(),(n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color)&&FT(e).append(),!0===e.isSkinnedMesh&&(i=e,ty(new NT(i,!0))).append(),this.displacementMap){const t=SM("displacementMap","texture"),e=SM("displacementScale","float"),n=SM("displacementBias","float");GS.addAssign(KS.normalize().mul(t.x.mul(e).add(n)))}e.isBatchedMesh&&RT(e).append(),e.instanceMatrix&&!0===e.instanceMatrix.isInstancedBufferAttribute&&ET(e).append(),null!==this.positionNode&&GS.assign(this.positionNode);const r=xT();return t.context.vertex=t.removeStack(),t.context.mvp=r,r}setupDiffuseColor({object:t,geometry:e}){let n=this.colorNode?Sy(this.colorNode):zM;if(!0===this.vertexColors&&e.hasAttribute("color")&&(n=Sy(n.xyz.mul(bS("color","vec3")),n.a)),t.instanceColor){n=zy("vec3","vInstanceColor").mul(n)}if(t.isBatchedMesh&&t._colorsTexture){n=zy("vec3","vBatchColor").mul(n)}ky.assign(n);const i=this.opacityNode?uy(this.opacityNode):VM;if(ky.a.assign(ky.a.mul(i)),null!==this.alphaTestNode||this.alphaTest>0){const t=null!==this.alphaTestNode?uy(this.alphaTestNode):BM;ky.a.lessThanEqual(t).discard()}!0===this.alphaHash&&ky.a.lessThan(dw(GS)).discard(),!1===this.transparent&&1===this.blending&&!1===this.alphaToCoverage&&ky.a.assign(1)}setupVariants(){}setupOutgoingLight(){return!0===this.lights?vy(0):ky.rgb}setupNormal(){return this.normalNode?vy(this.normalNode):KM}setupEnvironment(){let t=null;return this.envNode?t=this.envNode:this.envMap&&(t=this.envMap.isCubeTexture?SM("envMap","cubeTexture"):SM("envMap","texture")),t}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new VT(gT)),e}setupLights(t){const e=[],n=this.setupEnvironment(t);n&&n.isLightingNode&&e.push(n);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:_T;e.push(new zT(t))}let r=this.lightsNode||t.lightsNode;return e.length>0&&(r=t.renderer.lighting.createNode([...r.getLights(),...e])),r}setupLightingModel(){}setupLighting(t){const{material:e}=t,{backdropNode:n,backdropAlphaNode:i,emissiveNode:r}=this,s=!0===this.lights||null!==this.lightsNode?this.setupLights(t):null;let a=this.setupOutgoingLight(t);if(s&&s.getScope().hasLights){const e=this.setupLightingModel(t);a=GT(s,e,n,i)}else null!==n&&(a=vy(null!==i?Ub(a,n,i):n));return(r&&!0===r.isNode||e.emissive&&!0===e.emissive.isColor)&&(Gy.assign(vy(r||GM)),a=a.add(Gy)),a}setupOutput(t,e){if(!0===this.fog){const n=t.fogNode;n&&(e=Sy(n.mix(e.rgb,n.colorNode),e.a))}return e}setDefaultValues(t){for(const e in t){const n=t[e];void 0===this[e]&&(this[e]=n,n&&n.clone&&(this[e]=n.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 n=ug.prototype.toJSON.call(this,t),i=iv(this);n.inputNodes={};for(const{property:e,childNode:r}of i)n.inputNodes[e]=r.toJSON(t).uuid;function r(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}if(e){const e=r(t.textures),i=r(t.images),s=r(t.nodes);e.length>0&&(n.textures=e),i.length>0&&(n.images=i),s.length>0&&(n.nodes=s)}return n}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.geometryNode=t.geometryNode,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)}}const fw=new g_;class mw extends pw{static get type(){return"LineBasicNodeMaterial"}constructor(t){super(),this.isLineBasicNodeMaterial=!0,this.lights=!1,this.setDefaultValues(fw),this.setValues(t)}}const gw=new C_;class _w extends pw{static get type(){return"LineDashedNodeMaterial"}constructor(t){super(),this.isLineDashedNodeMaterial=!0,this.lights=!1,this.setDefaultValues(gw),this.offsetNode=null,this.dashScaleNode=null,this.dashSizeNode=null,this.gapSizeNode=null,this.setValues(t)}setupVariants(){const t=this.offsetNode,e=this.dashScaleNode?uy(this.dashScaleNode):dT,n=this.dashSizeNode?uy(this.dashSizeNode):pT,i=this.dashSizeNode?uy(this.dashGapNode):fT;sx.assign(n),ax.assign(i);const r=Xb(bS("lineDistance").mul(e));(t?r.add(t):r).mod(sx.add(ax)).greaterThan(sx).discard()}}const vw=new E_;class yw extends pw{static get type(){return"MeshNormalNodeMaterial"}constructor(t){super(),this.lights=!1,this.isMeshNormalNodeMaterial=!0,this.setDefaultValues(vw),this.setValues(t)}setupDiffuseColor(){const t=this.opacityNode?uy(this.opacityNode):VM;ky.assign(Sy(ty(tM).mul(.5).add(.5),t))}}class xw extends vv{static get type(){return"EquirectUVNode"}constructor(t=jS){super("vec2"),this.dirNode=t}setup(){const t=this.dirNode,e=t.z.atan2(t.x).mul(1/(2*Math.PI)).add(.5),n=t.y.clamp(-1,1).asin().mul(1/Math.PI).add(.5);return fy(e,n)}}const bw=iy(xw);class Sw extends e_{constructor(t=1,e={}){super(t,e),this.isCubeRenderTarget=!0}fromEquirectangularTexture(t,e){const n=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 jg(5,5,5),s=bw(jS),a=new pw;a.colorNode=RS(e,s,0),a.side=1,a.blending=0;const o=new Vg(r,a),l=new n_;l.add(o),e.minFilter===Zd&&(e.minFilter=Yd);const h=new Jg(1,10,this),u=t.getMRT();return t.setMRT(null),h.update(t,l),t.setMRT(u),e.minFilter=n,e.currentGenerateMipmaps=i,o.geometry.dispose(),o.material.dispose(),this}}const Mw=new WeakMap;class Tw extends vv{static get type(){return"CubeMapNode"}constructor(t){super("vec3"),this.envNode=t,this._cubeTexture=null,this._cubeTextureNode=cM();const e=new t_;e.isRenderTargetTexture=!0,this._defaultTexture=e,this.updateBeforeType=hv}updateBefore(t){const{renderer:e,material:n}=t,i=this.envNode;if(i.isTextureNode||i.isMaterialReferenceNode){const t=i.isTextureNode?i.value:n[i.property];if(t&&t.isTexture){const n=t.mapping;if(n===Gd||n===Vd){if(Mw.has(t)){const e=Mw.get(t);Ew(e,t.mapping),this._cubeTexture=e}else{const n=t.image;if(function(t){return null!=t&&t.height>0}(n)){const i=new Sw(n.height);i.fromEquirectangularTexture(e,t),Ew(i.texture,t.mapping),this._cubeTexture=i.texture,Mw.set(t,i.texture),t.addEventListener("dispose",ww)}else this._cubeTexture=this._defaultTexture}this._cubeTextureNode.value=this._cubeTexture}else this._cubeTextureNode=this.envNode}}}setup(t){return this.updateBefore(t),this._cubeTextureNode}}function ww(t){const e=t.target;e.removeEventListener("dispose",ww);const n=Mw.get(e);void 0!==n&&(Mw.delete(e),n.dispose())}function Ew(t,e){e===Gd?t.mapping=zd:e===Vd&&(t.mapping=kd)}const Aw=iy(Tw);class Rw extends BT{static get type(){return"BasicEnvironmentNode"}constructor(t=null){super(),this.envNode=t}setup(t){t.context.environment=Aw(this.envNode)}}class Cw extends BT{static get type(){return"BasicLightMapNode"}constructor(t=null){super(),this.lightMapNode=t}setup(t){const e=uy(1/Math.PI);t.context.irradianceLightMap=this.lightMapNode.mul(e)}}class Nw{start(){}finish(){}direct(){}directRectArea(){}indirect(){}ambientOcclusion(){}}class Pw extends Nw{constructor(){super()}indirect(t,e,n){const i=t.ambientOcclusion,r=t.reflectedLight,s=n.context.irradianceLightMap;r.indirectDiffuse.assign(Sy(0)),s?r.indirectDiffuse.addAssign(s):r.indirectDiffuse.addAssign(Sy(1,1,1,0)),r.indirectDiffuse.mulAssign(i),r.indirectDiffuse.mulAssign(ky.rgb)}finish(t,e,n){const i=n.material,r=t.outgoingLight,s=n.context.environment;if(s)switch(i.combine){case 0:r.rgb.assign(Ub(r.rgb,r.rgb.mul(s.rgb),qM.mul(XM)));break;case 1:r.rgb.assign(Ub(r.rgb,s.rgb,qM.mul(XM)));break;case 2:r.rgb.addAssign(s.rgb.mul(qM.mul(XM)));break;default:console.warn("THREE.BasicLightingModel: Unsupported .combine value:",i.combine)}}}const Iw=new cg;class Lw extends pw{static get type(){return"MeshBasicNodeMaterial"}constructor(t){super(),this.isMeshBasicNodeMaterial=!0,this.lights=!0,this.setDefaultValues(Iw),this.setValues(t)}setupNormal(){return QS}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new Rw(e):null}setupLightMap(t){let e=null;return t.material.lightMap&&(e=new Cw(gT)),e}setupOutgoingLight(){return ky.rgb}setupLightingModel(){return new Pw}}const Uw=sy((({f0:t,f90:e,dotVH:n})=>{const i=n.mul(-5.55473).sub(6.98316).mul(n).exp2();return t.mul(i.oneMinus()).add(e.mul(i))})),Dw=sy((t=>t.diffuseColor.mul(1/Math.PI))),Ow=sy((({dotNH:t})=>ix.mul(uy(.5)).add(1).mul(uy(1/Math.PI)).mul(t.pow(ix)))),Fw=sy((({lightDirection:t})=>{const e=t.add(qS).normalize(),n=tM.dot(e).clamp(),i=qS.dot(e).clamp(),r=Uw({f0:ex,f90:1,dotVH:i}),s=uy(.25),a=Ow({dotNH:n});return r.mul(s).mul(a)}));class Bw extends Pw{constructor(t=!0){super(),this.specular=t}direct({lightDirection:t,lightColor:e,reflectedLight:n}){const i=tM.dot(t).clamp().mul(e);n.directDiffuse.addAssign(i.mul(Dw({diffuseColor:ky.rgb}))),!0===this.specular&&n.directSpecular.addAssign(i.mul(Fw({lightDirection:t})).mul(qM))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:n}){n.indirectDiffuse.addAssign(e.mul(Dw({diffuseColor:ky}))),n.indirectDiffuse.mulAssign(t)}}const zw=new A_;class kw extends pw{static get type(){return"MeshLambertNodeMaterial"}constructor(t){super(),this.isMeshLambertNodeMaterial=!0,this.lights=!0,this.setDefaultValues(zw),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new Rw(e):null}setupLightingModel(){return new Bw(!1)}}const Gw=new T_;class Vw extends pw{static get type(){return"MeshPhongNodeMaterial"}constructor(t){super(),this.isMeshPhongNodeMaterial=!0,this.lights=!0,this.shininessNode=null,this.specularNode=null,this.setDefaultValues(Gw),this.setValues(t)}setupEnvironment(t){const e=super.setupEnvironment(t);return e?new Rw(e):null}setupLightingModel(){return new Bw}setupVariants(){const t=(this.shininessNode?uy(this.shininessNode):kM).max(1e-4);ix.assign(t);const e=this.specularNode||HM;ex.assign(e)}copy(t){return this.shininessNode=t.shininessNode,this.specularNode=t.specularNode,super.copy(t)}}const Hw=sy((t=>{if(!1===t.geometry.hasAttribute("normal"))return uy(0);const e=QS.dFdx().abs().max(QS.dFdy().abs());return e.x.max(e.y).max(e.z)})),jw=sy((t=>{const{roughness:e}=t,n=Hw();let i=e.max(.0525);return i=i.add(n),i=i.min(1),i})),Ww=sy((({alpha:t,dotNL:e,dotNV:n})=>{const i=t.pow2(),r=e.mul(i.add(i.oneMinus().mul(n.pow2())).sqrt()),s=n.mul(i.add(i.oneMinus().mul(e.pow2())).sqrt());return yx(.5,r.add(s).max(Bx))})).setLayout({name:"V_GGX_SmithCorrelated",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNL",type:"float"},{name:"dotNV",type:"float"}]}),qw=sy((({alphaT:t,alphaB:e,dotTV:n,dotBV:i,dotTL:r,dotBL:s,dotNV:a,dotNL:o})=>{const l=o.mul(vy(t.mul(n),e.mul(i),a).length()),h=a.mul(vy(t.mul(r),e.mul(s),o).length());return yx(.5,l.add(h)).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"}]}),Xw=sy((({alpha:t,dotNH:e})=>{const n=t.pow2(),i=e.pow2().mul(n.oneMinus()).oneMinus();return n.div(i.pow2()).mul(1/Math.PI)})).setLayout({name:"D_GGX",type:"float",inputs:[{name:"alpha",type:"float"},{name:"dotNH",type:"float"}]}),$w=uy(1/Math.PI),Yw=sy((({alphaT:t,alphaB:e,dotNH:n,dotTH:i,dotBH:r})=>{const s=t.mul(e),a=vy(e.mul(i),t.mul(r),s.mul(n)),o=a.dot(a),l=s.div(o);return $w.mul(s.mul(l.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"}]}),Kw=sy((t=>{const{lightDirection:e,f0:n,f90:i,roughness:r,f:s,USE_IRIDESCENCE:a,USE_ANISOTROPY:o}=t,l=t.normalView||tM,h=r.pow2(),u=e.add(qS).normalize(),c=l.dot(e).clamp(),d=l.dot(qS).clamp(),p=l.dot(u).clamp(),f=qS.dot(u).clamp();let m,g,_=Uw({f0:n,f90:i,dotVH:f});if(Qv(a)&&(_=$y.mix(_,s)),Qv(o)){const t=Jy.dot(e),n=Jy.dot(qS),i=Jy.dot(u),r=tx.dot(e),s=tx.dot(qS),a=tx.dot(u);m=qw({alphaT:Zy,alphaB:h,dotTV:n,dotBV:s,dotTL:t,dotBL:r,dotNV:d,dotNL:c}),g=Yw({alphaT:Zy,alphaB:h,dotNH:p,dotTH:i,dotBH:a})}else m=Ww({alpha:h,dotNL:c,dotNV:d}),g=Xw({alpha:h,dotNH:p});return _.mul(m).mul(g)})),Zw=sy((({roughness:t,dotNV:e})=>{const n=Sy(-1,-.0275,-.572,.022),i=Sy(1,.0425,1.04,-.04),r=t.mul(n).add(i),s=r.x.mul(r.x).min(e.mul(-9.28).exp2()).mul(r.x).add(r.y);return fy(-1.04,1.04).mul(s).add(r.zw)})).setLayout({name:"DFGApprox",type:"vec2",inputs:[{name:"roughness",type:"float"},{name:"dotNV",type:"vec3"}]}),Qw=sy((t=>{const{dotNV:e,specularColor:n,specularF90:i,roughness:r}=t,s=Zw({dotNV:e,roughness:r});return n.mul(s.x).add(i.mul(s.y))})),Jw=sy((({f:t,f90:e,dotVH:n})=>{const i=n.oneMinus().saturate(),r=i.mul(i),s=i.mul(r,r).clamp(0,.9999);return t.sub(vy(e).mul(s)).div(s.oneMinus())})).setLayout({name:"Schlick_to_F0",type:"vec3",inputs:[{name:"f",type:"vec3"},{name:"f90",type:"float"},{name:"dotVH",type:"float"}]}),tE=sy((({roughness:t,dotNH:e})=>{const n=t.pow2(),i=uy(1).div(n),r=e.pow2().oneMinus().max(.0078125);return uy(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"}]}),eE=sy((({dotNV:t,dotNL:e})=>uy(1).div(uy(4).mul(e.add(t).sub(e.mul(t)))))).setLayout({name:"V_Neubelt",type:"float",inputs:[{name:"dotNV",type:"float"},{name:"dotNL",type:"float"}]}),nE=sy((({lightDirection:t})=>{const e=t.add(qS).normalize(),n=tM.dot(t).clamp(),i=tM.dot(qS).clamp(),r=tM.dot(e).clamp(),s=tE({roughness:Xy,dotNH:r}),a=eE({dotNV:i,dotNL:n});return qy.mul(s).mul(a)})),iE=sy((({N:t,V:e,roughness:n})=>{const i=t.dot(e).saturate(),r=fy(n,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"}]}),rE=sy((({f:t})=>{const e=t.length();return bb(e.mul(e).add(t.z).div(e.add(1)),0)})).setLayout({name:"LTC_ClippedSphereFormFactor",type:"float",inputs:[{name:"f",type:"vec3"}]}),sE=sy((({v1:t,v2:e})=>{const n=t.dot(e),i=n.abs().toVar(),r=i.mul(.0145206).add(.4965155).mul(i).add(.8543985).toVar(),s=i.add(4.1616724).mul(i).add(3.417594).toVar(),a=r.div(s),o=n.greaterThan(0).select(a,bb(n.mul(n).oneMinus(),1e-7).inverseSqrt().mul(.5).sub(a));return t.cross(e).mul(o)})).setLayout({name:"LTC_EdgeVectorFormFactor",type:"vec3",inputs:[{name:"v1",type:"vec3"},{name:"v2",type:"vec3"}]}),aE=sy((({N:t,V:e,P:n,mInv:i,p0:r,p1:s,p2:a,p3:o})=>{const l=s.sub(r).toVar(),h=o.sub(r).toVar(),u=l.cross(h),c=vy().toVar();return ly(u.dot(n.sub(r)).greaterThanEqual(0),(()=>{const l=e.sub(t.mul(e.dot(t))).normalize(),h=t.cross(l).negate(),u=i.mul(Ay(l,h,t).transpose()).toVar(),d=u.mul(r.sub(n)).normalize().toVar(),p=u.mul(s.sub(n)).normalize().toVar(),f=u.mul(a.sub(n)).normalize().toVar(),m=u.mul(o.sub(n)).normalize().toVar(),g=vy(0).toVar();g.addAssign(sE({v1:d,v2:p})),g.addAssign(sE({v1:p,v2:f})),g.addAssign(sE({v1:f,v2:m})),g.addAssign(sE({v1:m,v2:d})),c.assign(vy(rE({f:g})))})),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"}]}),oE=1/6,lE=t=>vx(oE,vx(t,vx(t,t.negate().add(3)).sub(3)).add(1)),hE=t=>vx(oE,vx(t,vx(t,vx(3,t).sub(6))).add(4)),uE=t=>vx(oE,vx(t,vx(t,vx(-3,t).add(3)).add(3)).add(1)),cE=t=>vx(oE,Cb(t,3)),dE=t=>lE(t).add(hE(t)),pE=t=>uE(t).add(cE(t)),fE=t=>gx(-1,hE(t).div(lE(t).add(hE(t)))),mE=t=>gx(1,cE(t).div(uE(t).add(cE(t)))),gE=(t,e,n)=>{const i=t.uvNode,r=vx(i,e.zw).add(.5),s=Zx(r),a=tb(r),o=dE(a.x),l=pE(a.x),h=fE(a.x),u=mE(a.x),c=fE(a.y),d=mE(a.y),p=fy(s.x.add(h),s.y.add(c)).sub(.5).mul(e.xy),f=fy(s.x.add(u),s.y.add(c)).sub(.5).mul(e.xy),m=fy(s.x.add(h),s.y.add(d)).sub(.5).mul(e.xy),g=fy(s.x.add(u),s.y.add(d)).sub(.5).mul(e.xy),_=dE(a.y).mul(gx(o.mul(t.uv(p).level(n)),l.mul(t.uv(f).level(n)))),v=pE(a.y).mul(gx(o.mul(t.uv(m).level(n)),l.mul(t.uv(g).level(n))));return _.add(v)},_E=sy((([t,e=uy(3)])=>{const n=fy(t.size(cy(e))),i=fy(t.size(cy(e.add(1)))),r=yx(1,n),s=yx(1,i),a=gE(t,Sy(r,n),Zx(e)),o=gE(t,Sy(s,i),Qx(e));return tb(e).mix(a,o)})),vE=sy((([t,e,n,i,r])=>{const s=vy(Ob(e.negate(),Jx(t),yx(1,i))),a=vy(hb(r[0].xyz),hb(r[1].xyz),hb(r[2].xyz));return Jx(s).mul(n.mul(a))})).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"}]}),yE=sy((([t,e])=>t.mul(Db(e.mul(2).sub(2),0,1)))).setLayout({name:"applyIorToRoughness",type:"float",inputs:[{name:"roughness",type:"float"},{name:"ior",type:"float"}]}),xE=QT(),bE=QT(),SE=sy((([t,e,n],{material:i})=>{const r=(1==i.side?xE:bE).uv(t),s=$x(XT.x).mul(yE(e,n));return _E(r,s)})),ME=sy((([t,e,n])=>(ly(n.notEqual(0),(()=>{const i=Xx(e).negate().div(n);return Wx(i.negate().mul(t))})),vy(1)))).setLayout({name:"volumeAttenuation",type:"vec3",inputs:[{name:"transmissionDistance",type:"float"},{name:"attenuationColor",type:"vec3"},{name:"attenuationDistance",type:"float"}]}),TE=sy((([t,e,n,i,r,s,a,o,l,h,u,c,d,p,f])=>{let m,g;if(f){m=Sy().toVar(),g=vy().toVar();const r=u.sub(1).mul(f.mul(.025)),s=vy(u.sub(r),u,u.add(r));IT({start:0,end:3},(({i:r})=>{const u=s.element(r),f=vE(t,e,c,u,o),_=a.add(f),v=h.mul(l.mul(Sy(_,1))),y=fy(v.xy.div(v.w)).toVar();y.addAssign(1),y.divAssign(2),y.assign(fy(y.x,y.y.oneMinus()));const x=SE(y,n,u);m.element(r).assign(x.element(r)),m.a.addAssign(x.a),g.element(r).assign(i.element(r).mul(ME(hb(f),d,p).element(r)))})),m.a.divAssign(3)}else{const r=vE(t,e,c,u,o),s=a.add(r),f=h.mul(l.mul(Sy(s,1))),_=fy(f.xy.div(f.w)).toVar();_.addAssign(1),_.divAssign(2),_.assign(fy(_.x,_.y.oneMinus())),m=SE(_,n,u),g=i.mul(ME(hb(r),d,p))}const _=g.rgb.mul(m.rgb),v=t.dot(e).clamp(),y=vy(Qw({dotNV:v,specularColor:r,specularF90:s,roughness:n})),x=g.r.add(g.g,g.b).div(3);return Sy(y.oneMinus().mul(_),m.a.oneMinus().mul(x).oneMinus())})),wE=Ay(3.2404542,-.969266,.0556434,-1.5371385,1.8760108,-.2040259,-.4985314,.041556,1.0572252),EE=(t,e)=>t.sub(e).div(t.add(e)).pow2(),AE=sy((({outsideIOR:t,eta2:e,cosTheta1:n,thinFilmThickness:i,baseF0:r})=>{const s=Ub(t,e,Fb(0,.03,i)),a=t.div(s).pow2().mul(n.pow2().oneMinus()).oneMinus();ly(a.lessThan(0),(()=>vy(1)));const o=a.sqrt(),l=EE(s,t),h=Uw({f0:l,f90:1,dotVH:n}),u=h.oneMinus(),c=s.lessThan(t).select(Math.PI,0),d=uy(Math.PI).sub(c),p=(t=>{const e=t.sqrt();return vy(1).add(e).div(vy(1).sub(e))})(r.clamp(0,.9999)),f=EE(p,s.toVec3()),m=Uw({f0:f,f90:1,dotVH:o}),g=vy(p.x.lessThan(s).select(Math.PI,0),p.y.lessThan(s).select(Math.PI,0),p.z.lessThan(s).select(Math.PI,0)),_=s.mul(i,o,2),v=vy(d).add(g),y=h.mul(m).clamp(1e-5,.9999),x=y.sqrt(),b=u.pow2().mul(m).div(vy(1).sub(y)),S=h.add(b).toVar(),M=b.sub(u).toVar();return IT({start:1,end:2,condition:"<=",name:"m"},(({m:t})=>{M.mulAssign(x);const e=((t,e)=>{const n=t.mul(2*Math.PI*1e-9),i=vy(54856e-17,44201e-17,52481e-17),r=vy(1681e3,1795300,2208400),s=vy(43278e5,93046e5,66121e5),a=uy(9747e-17*Math.sqrt(2*Math.PI*45282e5)).mul(n.mul(2239900).add(e.x).cos()).mul(n.pow2().mul(-45282e5).exp());let o=i.mul(s.mul(2*Math.PI).sqrt()).mul(r.mul(n).add(e).cos()).mul(n.pow2().negate().mul(s).exp());return o=vy(o.x.add(a),o.y,o.z).div(1.0685e-7),wE.mul(o)})(uy(t).mul(_),uy(t).mul(v)).mul(2);S.addAssign(M.mul(e))})),S.max(vy(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"}]}),RE=sy((({normal:t,viewDir:e,roughness:n})=>{const i=t.dot(e).saturate(),r=n.pow2(),s=Gb(n.lessThan(.25),uy(-339.2).mul(r).add(uy(161.4).mul(n)).sub(25.9),uy(-8.48).mul(r).add(uy(14.3).mul(n)).sub(9.95)),a=Gb(n.lessThan(.25),uy(44).mul(r).sub(uy(23.7).mul(n)).add(3.26),uy(1.97).mul(r).sub(uy(3.27).mul(n)).add(.72));return Gb(n.lessThan(.25),0,uy(.1).mul(n).sub(.025)).add(s.mul(i).add(a).exp()).mul(1/Math.PI).saturate()})),CE=vy(.04),NE=uy(1);class PE extends Nw{constructor(t=!1,e=!1,n=!1,i=!1,r=!1,s=!1){super(),this.clearcoat=t,this.sheen=e,this.iridescence=n,this.anisotropy=i,this.transmission=r,this.dispersion=s,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=vy().toVar("clearcoatRadiance"),this.clearcoatSpecularDirect=vy().toVar("clearcoatSpecularDirect"),this.clearcoatSpecularIndirect=vy().toVar("clearcoatSpecularIndirect")),!0===this.sheen&&(this.sheenSpecularDirect=vy().toVar("sheenSpecularDirect"),this.sheenSpecularIndirect=vy().toVar("sheenSpecularIndirect")),!0===this.iridescence){const t=tM.dot(qS).clamp();this.iridescenceFresnel=AE({outsideIOR:uy(1),eta2:Yy,cosTheta1:t,thinFilmThickness:Ky,baseF0:ex}),this.iridescenceF0=Jw({f:this.iridescenceFresnel,f90:1,dotVH:t})}if(!0===this.transmission){const e=HS,n=US.sub(HS).normalize(),i=eM;t.backdrop=TE(i,n,Vy,ky,ex,nx,e,FS,LS,IS,ox,hx,cx,ux,this.dispersion?dx:null),t.backdropAlpha=lx,ky.a.mulAssign(Ub(1,t.backdrop.a,lx))}}computeMultiscattering(t,e,n){const i=tM.dot(qS).clamp(),r=Zw({roughness:Vy,dotNV:i}),s=(this.iridescenceF0?$y.mix(ex,this.iridescenceF0):ex).mul(r.x).add(n.mul(r.y)),a=r.x.add(r.y).oneMinus(),o=ex.add(ex.oneMinus().mul(.047619)),l=s.mul(o).div(a.mul(o).oneMinus());t.addAssign(s),e.addAssign(l.mul(a))}direct({lightDirection:t,lightColor:e,reflectedLight:n}){const i=tM.dot(t).clamp().mul(e);if(!0===this.sheen&&this.sheenSpecularDirect.addAssign(i.mul(nE({lightDirection:t}))),!0===this.clearcoat){const n=nM.dot(t).clamp().mul(e);this.clearcoatSpecularDirect.addAssign(n.mul(Kw({lightDirection:t,f0:CE,f90:NE,roughness:Wy,normalView:nM})))}n.directDiffuse.addAssign(i.mul(Dw({diffuseColor:ky.rgb}))),n.directSpecular.addAssign(i.mul(Kw({lightDirection:t,f0:ex,f90:1,roughness:Vy,iridescence:this.iridescence,f:this.iridescenceFresnel,USE_IRIDESCENCE:this.iridescence,USE_ANISOTROPY:this.anisotropy})))}directRectArea({lightColor:t,lightPosition:e,halfWidth:n,halfHeight:i,reflectedLight:r,ltc_1:s,ltc_2:a}){const o=e.add(n).sub(i),l=e.sub(n).sub(i),h=e.sub(n).add(i),u=e.add(n).add(i),c=tM,d=qS,p=WS.toVar(),f=iE({N:c,V:d,roughness:Vy}),m=s.uv(f).toVar(),g=a.uv(f).toVar(),_=Ay(vy(m.x,0,m.y),vy(0,1,0),vy(m.z,0,m.w)).toVar(),v=ex.mul(g.x).add(ex.oneMinus().mul(g.y)).toVar();r.directSpecular.addAssign(t.mul(v).mul(aE({N:c,V:d,P:p,mInv:_,p0:o,p1:l,p2:h,p3:u}))),r.directDiffuse.addAssign(t.mul(ky).mul(aE({N:c,V:d,P:p,mInv:Ay(1,0,0,0,1,0,0,0,1),p0:o,p1:l,p2:h,p3:u})))}indirect(t,e,n){this.indirectDiffuse(t,e,n),this.indirectSpecular(t,e,n),this.ambientOcclusion(t,e,n)}indirectDiffuse({irradiance:t,reflectedLight:e}){e.indirectDiffuse.addAssign(t.mul(Dw({diffuseColor:ky})))}indirectSpecular({radiance:t,iblIrradiance:e,reflectedLight:n}){if(!0===this.sheen&&this.sheenSpecularIndirect.addAssign(e.mul(qy,RE({normal:tM,viewDir:qS,roughness:Xy}))),!0===this.clearcoat){const t=nM.dot(qS).clamp(),e=Qw({dotNV:t,specularColor:CE,specularF90:NE,roughness:Wy});this.clearcoatSpecularIndirect.addAssign(this.clearcoatRadiance.mul(e))}const i=vy().toVar("singleScattering"),r=vy().toVar("multiScattering"),s=e.mul(1/Math.PI);this.computeMultiscattering(i,r,nx);const a=i.add(r),o=ky.mul(a.r.max(a.g).max(a.b).oneMinus());n.indirectSpecular.addAssign(t.mul(i)),n.indirectSpecular.addAssign(r.mul(s)),n.indirectDiffuse.addAssign(o.mul(s))}ambientOcclusion({ambientOcclusion:t,reflectedLight:e}){const n=tM.dot(qS).clamp().add(t),i=Vy.mul(-16).oneMinus().negate().exp2(),r=t.sub(n.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=nM.dot(qS).clamp(),n=Uw({dotVH:t,f0:CE,f90:NE}),i=e.mul(jy.mul(n).oneMinus()).add(this.clearcoatSpecularDirect.add(this.clearcoatSpecularIndirect).mul(jy));e.assign(i)}if(!0===this.sheen){const t=qy.r.max(qy.g).max(qy.b).mul(.157).oneMinus(),n=e.mul(t).add(this.sheenSpecularDirect,this.sheenSpecularIndirect);e.assign(n)}}}const IE=uy(1),LE=uy(-2),UE=uy(.8),DE=uy(-1),OE=uy(.4),FE=uy(2),BE=uy(.305),zE=uy(3),kE=uy(.21),GE=uy(4),VE=uy(4),HE=uy(16),jE=sy((([t])=>{const e=vy(ob(t)).toVar(),n=uy(-1).toVar();return ly(e.x.greaterThan(e.z),(()=>{ly(e.x.greaterThan(e.y),(()=>{n.assign(Gb(t.x.greaterThan(0),0,3))})).Else((()=>{n.assign(Gb(t.y.greaterThan(0),1,4))}))})).Else((()=>{ly(e.z.greaterThan(e.y),(()=>{n.assign(Gb(t.z.greaterThan(0),2,5))})).Else((()=>{n.assign(Gb(t.y.greaterThan(0),1,4))}))})),n})).setLayout({name:"getFace",type:"float",inputs:[{name:"direction",type:"vec3"}]}),WE=sy((([t,e])=>{const n=fy().toVar();return ly(e.equal(0),(()=>{n.assign(fy(t.z,t.y).div(ob(t.x)))})).ElseIf(e.equal(1),(()=>{n.assign(fy(t.x.negate(),t.z.negate()).div(ob(t.y)))})).ElseIf(e.equal(2),(()=>{n.assign(fy(t.x.negate(),t.y).div(ob(t.z)))})).ElseIf(e.equal(3),(()=>{n.assign(fy(t.z.negate(),t.y).div(ob(t.x)))})).ElseIf(e.equal(4),(()=>{n.assign(fy(t.x.negate(),t.z).div(ob(t.y)))})).Else((()=>{n.assign(fy(t.x,t.y).div(ob(t.z)))})),vx(.5,n.add(1))})).setLayout({name:"getUV",type:"vec2",inputs:[{name:"direction",type:"vec3"},{name:"face",type:"float"}]}),qE=sy((([t])=>{const e=uy(0).toVar();return ly(t.greaterThanEqual(UE),(()=>{e.assign(IE.sub(t).mul(DE.sub(LE)).div(IE.sub(UE)).add(LE))})).ElseIf(t.greaterThanEqual(OE),(()=>{e.assign(UE.sub(t).mul(FE.sub(DE)).div(UE.sub(OE)).add(DE))})).ElseIf(t.greaterThanEqual(BE),(()=>{e.assign(OE.sub(t).mul(zE.sub(FE)).div(OE.sub(BE)).add(FE))})).ElseIf(t.greaterThanEqual(kE),(()=>{e.assign(BE.sub(t).mul(GE.sub(zE)).div(BE.sub(kE)).add(zE))})).Else((()=>{e.assign(uy(-2).mul($x(vx(1.16,t))))})),e})).setLayout({name:"roughnessToMip",type:"float",inputs:[{name:"roughness",type:"float"}]}),XE=sy((([t,e])=>{const n=t.toVar();n.assign(vx(2,n).sub(1));const i=vy(n,1).toVar();return ly(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"}]}),$E=sy((([t,e,n,i,r,s])=>{const a=uy(n),o=vy(e),l=Db(qE(a),LE,s),h=tb(l),u=Zx(l),c=vy(YE(t,o,u,i,r,s)).toVar();return ly(h.notEqual(0),(()=>{const e=vy(YE(t,o,u.add(1),i,r,s)).toVar();c.assign(Ub(c,e,h))})),c})),YE=sy((([t,e,n,i,r,s])=>{const a=uy(n).toVar(),o=vy(e),l=uy(jE(o)).toVar(),h=uy(bb(VE.sub(a),0)).toVar();a.assign(bb(a,VE));const u=uy(qx(a)).toVar(),c=fy(WE(o,l).mul(u.sub(2)).add(1)).toVar();return ly(l.greaterThan(2),(()=>{c.y.addAssign(u),l.subAssign(3)})),c.x.addAssign(l.mul(u)),c.x.addAssign(h.mul(vx(3,HE))),c.y.addAssign(vx(4,qx(s).sub(u))),c.x.mulAssign(i),c.y.mulAssign(r),t.uv(c).grad(fy(),fy())})),KE=sy((({envMap:t,mipInt:e,outputDirection:n,theta:i,axis:r,CUBEUV_TEXEL_WIDTH:s,CUBEUV_TEXEL_HEIGHT:a,CUBEUV_MAX_MIP:o})=>{const l=nb(i),h=n.mul(l).add(r.cross(n).mul(eb(i))).add(r.mul(r.dot(n).mul(l.oneMinus())));return YE(t,h,e,s,a,o)})),ZE=sy((({n:t,latitudinal:e,poleAxis:n,outputDirection:i,weights:r,samples:s,dTheta:a,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:c})=>{const d=vy(Gb(e,n,Rb(n,i))).toVar();ly(kx(d.equals(vy(0))),(()=>{d.assign(vy(i.z,0,i.x.negate()))})),d.assign(Jx(d));const p=vy().toVar();return p.addAssign(r.element(cy(0)).mul(KE({theta:0,axis:d,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:c}))),IT({start:cy(1),end:t},(({i:t})=>{ly(t.greaterThanEqual(s),(()=>{vS("break").append()}));const e=uy(a.mul(uy(t))).toVar();p.addAssign(r.element(t).mul(KE({theta:e.mul(-1),axis:d,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:c}))),p.addAssign(r.element(t).mul(KE({theta:e,axis:d,outputDirection:i,mipInt:o,envMap:l,CUBEUV_TEXEL_WIDTH:h,CUBEUV_TEXEL_HEIGHT:u,CUBEUV_MAX_MIP:c})))})),Sy(p,1)}));let QE=null;const JE=new WeakMap;function tA(t){let e=JE.get(t);if((void 0!==e?e.pmremVersion:-1)!==t.pmremVersion){const n=t.image;if(t.isCubeTexture){if(!function(t){if(null==t)return!1;let e=0;const n=6;for(let i=0;i<n;i++)void 0!==t[i]&&e++;return e===n}(n))return null;e=QE.fromCubemap(t,e)}else{if(!function(t){return null!=t&&t.height>0}(n))return null;e=QE.fromEquirectangular(t,e)}e.pmremVersion=t.pmremVersion,JE.set(t,e)}return e.texture}class eA extends vv{static get type(){return"PMREMNode"}constructor(t,e=null,n=null){super("vec3"),this._value=t,this._pmrem=null,this.uvNode=e,this.levelNode=n,this._generator=null;const i=new Lf;i.isRenderTargetTexture=!0,this._texture=RS(i),this._width=Oy(0),this._height=Oy(0),this._maxMip=Oy(0),this.updateBeforeType=hv}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,n=1/t;return{texelWidth:1/(3*Math.max(Math.pow(2,e),112)),texelHeight:n,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,n=this._value;e!==n.pmremVersion&&(t=!0===n.isPMREMTexture?n:tA(n),null!==t&&(this._pmrem=t,this.updateFromTexture(t)))}setup(t){null===QE&&(QE=t.createPMREMGenerator()),this.updateBefore(t);let e=this.uvNode;null===e&&t.context.getUV&&(e=t.context.getUV(this));const n=this.value;t.renderer.coordinateSystem===Jp&&!0!==n.isPMREMTexture&&!0===n.isRenderTargetTexture&&(e=vy(e.x.negate(),e.yz));let i=this.levelNode;return null===i&&t.context.getTextureLevel&&(i=t.context.getTextureLevel(this)),$E(this._texture,e,i,this._width,this._height,this._maxMip)}}const nA=iy(eA),iA=new WeakMap;class rA extends BT{static get type(){return"EnvironmentNode"}constructor(t=null){super(),this.envNode=t}setup(t){const{material:e}=t;let n=this.envNode;if(n.isTextureNode||n.isMaterialReferenceNode){const t=n.isTextureNode?n.value:e[n.property];let i=iA.get(t);void 0===i&&(i=nA(t),iA.set(t,i)),n=i}const i=e.envMap?yM("envMapIntensity","float",t.material):yM("environmentIntensity","float",t.scene),r=!0===e.useAnisotropy||e.anisotropy>0?RM:tM,s=n.context(sA(Vy,r)).mul(i),a=n.context(aA(eM)).mul(Math.PI).mul(i),o=dS(s),l=dS(a);t.context.radiance.addAssign(o),t.context.iblIrradiance.addAssign(l);const h=t.context.lightingModel.clearcoatRadiance;if(h){const t=n.context(sA(Wy,nM)).mul(i),e=dS(t);h.addAssign(e)}}}const sA=(t,e)=>{let n=null;return{getUV:()=>(null===n&&(n=qS.negate().reflect(e),n=t.mul(t).mix(n,e).normalize(),n=n.transformDirection(LS)),n),getTextureLevel:()=>t}},aA=t=>({getUV:()=>t,getTextureLevel:()=>uy(1)}),oA=new S_;class lA extends pw{static get type(){return"MeshStandardNodeMaterial"}constructor(t){super(),this.isMeshStandardNodeMaterial=!0,this.lights=!0,this.emissiveNode=null,this.metalnessNode=null,this.roughnessNode=null,this.setDefaultValues(oA),this.setValues(t)}setupEnvironment(t){let e=super.setupEnvironment(t);return null===e&&t.environmentNode&&(e=t.environmentNode),e?new rA(e):null}setupLightingModel(){return new PE}setupSpecular(){const t=Ub(vy(.04),ky.rgb,Hy);ex.assign(t),nx.assign(1)}setupVariants(){const t=this.metalnessNode?uy(this.metalnessNode):YM;Hy.assign(t);let e=this.roughnessNode?uy(this.roughnessNode):$M;e=jw({roughness:e}),Vy.assign(e),this.setupSpecular(),ky.assign(Sy(ky.rgb.mul(t.oneMinus()),ky.a))}copy(t){return this.emissiveNode=t.emissiveNode,this.metalnessNode=t.metalnessNode,this.roughnessNode=t.roughnessNode,super.copy(t)}}const hA=new M_;class uA extends lA{static get type(){return"MeshPhysicalNodeMaterial"}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(hA),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?uy(this.iorNode):hT;ox.assign(t),ex.assign(Ub(xb(Nb(ox.sub(1).div(ox.add(1))).mul(WM),vy(1)).mul(jM),ky.rgb,Hy)),nx.assign(Ub(jM,1,Hy))}setupLightingModel(){return new PE(this.useClearcoat,this.useSheen,this.useIridescence,this.useAnisotropy,this.useTransmission,this.useDispersion)}setupVariants(t){if(super.setupVariants(t),this.useClearcoat){const t=this.clearcoatNode?uy(this.clearcoatNode):ZM,e=this.clearcoatRoughnessNode?uy(this.clearcoatRoughnessNode):QM;jy.assign(t),Wy.assign(jw({roughness:e}))}if(this.useSheen){const t=this.sheenNode?vy(this.sheenNode):eT,e=this.sheenRoughnessNode?uy(this.sheenRoughnessNode):nT;qy.assign(t),Xy.assign(e)}if(this.useIridescence){const t=this.iridescenceNode?uy(this.iridescenceNode):rT,e=this.iridescenceIORNode?uy(this.iridescenceIORNode):sT,n=this.iridescenceThicknessNode?uy(this.iridescenceThicknessNode):aT;$y.assign(t),Yy.assign(e),Ky.assign(n)}if(this.useAnisotropy){const t=(this.anisotropyNode?fy(this.anisotropyNode):iT).toVar();Qy.assign(t.length()),ly(Qy.equal(0),(()=>{t.assign(fy(1,0))})).Else((()=>{t.divAssign(fy(Qy)),Qy.assign(Qy.saturate())})),Zy.assign(Qy.pow2().mix(Vy.pow2(),1)),Jy.assign(AM[0].mul(t.x).add(AM[1].mul(t.y))),tx.assign(AM[1].mul(t.x).sub(AM[0].mul(t.y)))}if(this.useTransmission){const t=this.transmissionNode?uy(this.transmissionNode):oT,e=this.thicknessNode?uy(this.thicknessNode):lT,n=this.attenuationDistanceNode?uy(this.attenuationDistanceNode):uT,i=this.attenuationColorNode?vy(this.attenuationColorNode):cT;if(lx.assign(t),hx.assign(e),ux.assign(n),cx.assign(i),this.useDispersion){const t=this.dispersionNode?uy(this.dispersionNode):mT;dx.assign(t)}}}setupClearcoatNormal(){return this.clearcoatNormalNode?vy(this.clearcoatNormalNode):JM}setup(t){t.context.setupClearcoatNormal=()=>this.setupClearcoatNormal(t),super.setup(t)}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)}}const cA=sy((({normal:t,lightDirection:e,builder:n})=>{const i=t.dot(e),r=fy(i.mul(.5).add(.5),0);if(n.material.gradientMap){const t=SM("gradientMap","texture").context({getUV:()=>r});return vy(t.r)}{const t=r.fwidth().mul(.5);return Ub(vy(.7),vy(1),Fb(uy(.7).sub(t.x),uy(.7).add(t.x),r.x))}}));class dA extends Nw{direct({lightDirection:t,lightColor:e,reflectedLight:n},i,r){const s=cA({normal:YS,lightDirection:t,builder:r}).mul(e);n.directDiffuse.addAssign(s.mul(Dw({diffuseColor:ky.rgb})))}indirect({ambientOcclusion:t,irradiance:e,reflectedLight:n}){n.indirectDiffuse.addAssign(e.mul(Dw({diffuseColor:ky}))),n.indirectDiffuse.mulAssign(t)}}const pA=new w_;class fA extends pw{static get type(){return"MeshToonNodeMaterial"}constructor(t){super(),this.isMeshToonNodeMaterial=!0,this.lights=!0,this.setDefaultValues(pA),this.setValues(t)}setupLightingModel(){return new dA}}class mA extends vv{static get type(){return"MatcapUVNode"}constructor(){super("vec2")}setup(){const t=vy(qS.z,0,qS.x.negate()).normalize(),e=qS.cross(t);return fy(t.dot(tM),e.dot(tM)).mul(.495).add(.5)}}const gA=ry(mA),_A=new R_;class vA extends pw{static get type(){return"MeshMatcapNodeMaterial"}constructor(t){super(),this.lights=!1,this.isMeshMatcapNodeMaterial=!0,this.setDefaultValues(_A),this.setValues(t)}setupVariants(t){const e=gA;let n;n=t.material.matcap?SM("matcap","texture").context({getUV:()=>e}):vy(Ub(.2,.8,e.y)),ky.rgb.mulAssign(n.rgb)}}const yA=new __;class xA extends pw{static get type(){return"PointsNodeMaterial"}constructor(t){super(),this.isPointsNodeMaterial=!0,this.lights=!1,this.transparent=!0,this.sizeNode=null,this.setDefaultValues(yA),this.setValues(t)}copy(t){return this.sizeNode=t.sizeNode,super.copy(t)}}class bA extends vv{static get type(){return"RotateNode"}constructor(t,e){super(),this.positionNode=t,this.rotationNode=e}getNodeType(t){return this.positionNode.getNodeType(t)}setup(t){const{rotationNode:e,positionNode:n}=this;if("vec2"===this.getNodeType(t)){const t=e.cos(),i=e.sin();return Ey(t,i,i.negate(),t).mul(n)}{const t=e,i=Ry(Sy(1,0,0,0),Sy(0,nb(t.x),eb(t.x).negate(),0),Sy(0,eb(t.x),nb(t.x),0),Sy(0,0,0,1)),r=Ry(Sy(nb(t.y),0,eb(t.y),0),Sy(0,1,0,0),Sy(eb(t.y).negate(),0,nb(t.y),0),Sy(0,0,0,1)),s=Ry(Sy(nb(t.z),eb(t.z).negate(),0,0),Sy(eb(t.z),nb(t.z),0,0),Sy(0,0,1,0),Sy(0,0,0,1));return i.mul(r).mul(s).mul(Sy(n,1)).xyz}}}const SA=iy(bA),MA=new a_;class TA extends pw{static get type(){return"SpriteNodeMaterial"}constructor(t){super(),this.isSpriteNodeMaterial=!0,this.lights=!1,this._useSizeAttenuation=!0,this.positionNode=null,this.rotationNode=null,this.scaleNode=null,this.setDefaultValues(MA),this.setValues(t)}setupPosition({object:t,camera:e,context:n}){const i=this.sizeAttenuation,{positionNode:r,rotationNode:s,scaleNode:a}=this,o=GS;let l=zS.mul(vy(r||0)),h=fy(FS[0].xyz.length(),FS[1].xyz.length());if(null!==a&&(h=h.mul(a)),!i)if(e.isPerspectiveCamera)h=h.mul(l.z.negate());else{const t=uy(2).div(IS.element(1).element(1));h=h.mul(t.mul(2))}let u=o.xy;if(t.center&&!0===t.center.isVector2){const t=((t,e,n)=>ty(new eS(t,e,n)))("center","vec2");u=u.sub(t.sub(.5))}u=u.mul(h);const c=uy(s||tT),d=SA(u,c);l=Sy(l.xy.add(d),l.zw);const p=IS.mul(l);return n.vertex=o,p}copy(t){return this.positionNode=t.positionNode,this.rotationNode=t.rotationNode,this.scaleNode=t.scaleNode,super.copy(t)}get sizeAttenuation(){return this._useSizeAttenuation}set sizeAttenuation(t){this._useSizeAttenuation!==t&&(this._useSizeAttenuation=t,this.needsUpdate=!0)}}class wA extends Nw{constructor(){super(),this.shadowNode=uy(1).toVar("shadowMask")}direct({shadowMask:t}){this.shadowNode.mulAssign(t)}finish(t){ky.a.mulAssign(this.shadowNode.oneMinus()),t.outgoingLight.rgb.assign(ky.rgb)}}const EA=new b_;class AA extends pw{static get type(){return"ShadowNodeMaterial"}constructor(t){super(),this.isShadowNodeMaterial=!0,this.lights=!0,this.setDefaultValues(EA),this.setValues(t)}setupLightingModel(){return new wA}}sy((({texture:t,uv:e})=>{const n=1e-4,i=vy().toVar();return ly(e.x.lessThan(n),(()=>{i.assign(vy(1,0,0))})).ElseIf(e.y.lessThan(n),(()=>{i.assign(vy(0,1,0))})).ElseIf(e.z.lessThan(n),(()=>{i.assign(vy(0,0,1))})).ElseIf(e.x.greaterThan(.9999),(()=>{i.assign(vy(-1,0,0))})).ElseIf(e.y.greaterThan(.9999),(()=>{i.assign(vy(0,-1,0))})).ElseIf(e.z.greaterThan(.9999),(()=>{i.assign(vy(0,0,-1))})).Else((()=>{const n=.01,r=t.uv(e.add(vy(-.01,0,0))).r.sub(t.uv(e.add(vy(n,0,0))).r),s=t.uv(e.add(vy(0,-.01,0))).r.sub(t.uv(e.add(vy(0,n,0))).r),a=t.uv(e.add(vy(0,0,-.01))).r.sub(t.uv(e.add(vy(0,0,n))).r);i.assign(vy(r,s,a))})),i.normalize()}));class RA{constructor(t,e){this.nodes=t,this.info=e,this.animationLoop=null,this.requestId=null,this._init()}_init(){const t=(e,n)=>{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,n)};t()}dispose(){self.cancelAnimationFrame(this.requestId),this.requestId=null}setAnimationLoop(t){this.animationLoop=t}}class CA{constructor(){this.weakMap=new WeakMap}get(t){let e=this.weakMap;for(let n=0;n<t.length;n++)if(e=e.get(t[n]),void 0===e)return;return e.get(t[t.length-1])}set(t,e){let n=this.weakMap;for(let e=0;e<t.length;e++){const i=t[e];!1===n.has(i)&&n.set(i,new WeakMap),n=n.get(i)}return n.set(t[t.length-1],e)}delete(t){let e=this.weakMap;for(let n=0;n<t.length;n++)if(e=e.get(t[n]),void 0===e)return!1;return e.delete(t[t.length-1])}}const NA=new d_;class PA{constructor(){this.version=0,this.globalClippingCount=0,this.localClippingCount=0,this.localClippingEnabled=!1,this.localClipIntersection=!1,this.planes=[],this.parentVersion=0,this.viewNormalMatrix=new mf,this.cacheKey=0}projectPlanes(t,e){const n=t.length,i=this.planes;for(let r=0;r<n;r++){NA.copy(t[r]).applyMatrix4(this.viewMatrix,this.viewNormalMatrix);const n=i[e+r],s=NA.normal;n.x=-s.x,n.y=-s.y,n.z=-s.z,n.w=NA.constant}}updateGlobal(t,e){const n=t.clippingPlanes;this.viewMatrix=e.matrixWorldInverse,this.viewNormalMatrix.getNormalMatrix(this.viewMatrix);let i=!1;if(Array.isArray(n)&&0!==n.length){const t=n.length;if(t!==this.globalClippingCount){const e=[];for(let n=0;n<t;n++)e.push(new Uf);this.globalClippingCount=t,this.planes=e,i=!0}this.projectPlanes(n,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++,this.cacheKey=ev(this.globalClippingCount,!0===this.localClippingEnabled?1:0))}update(t,e){let n=!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,n=!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(n||e!==this.localClippingCount){i.length=r+e;for(let t=0;t<e;t++)i[r+t]=new Uf;this.localClippingCount=e,n=!0}this.projectPlanes(t,r)}else 0!==this.localClippingCount&&(this.localClippingCount=0,n=!0);this.localClipIntersection!==e.clipIntersection&&(this.localClipIntersection=e.clipIntersection,n=!0)}n&&(this.version+=t.version,this.cacheKey=ev(t.cacheKey,this.localClippingCount,!0===this.localClipIntersection?1:0))}}let IA=0;class LA{constructor(t,e,n,i,r,s,a,o,l){this._nodes=t,this._geometries=e,this.id=IA++,this.renderer=n,this.object=i,this.material=r,this.scene=s,this.camera=a,this.lightsNode=o,this.context=l,this.geometry=i.geometry,this.version=r.version,this.drawRange=null,this.attributes=null,this.pipeline=null,this.vertexBuffers=null,this.drawParams=null,this.bundle=null,this.updateClipping(l.clippingContext),this.clippingContextVersion=this.clippingContext.version,this.initialNodesCacheKey=this.getDynamicCacheKey(),this.initialCacheKey=this.getCacheKey(),this._nodeBuilderState=null,this._bindings=null,this._monitor=null,this.onDispose=null,this.isRenderObject=!0,this.onMaterialDispose=()=>{this.dispose()},this.material.addEventListener("dispose",this.onMaterialDispose)}updateClipping(t){const e=this.material;let n=this.clippingContext;Array.isArray(e.clippingPlanes)?(n!==t&&n||(n=new PA,this.clippingContext=n),n.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))}getMonitor(){return this._monitor||(this._monitor=this.getNodeBuilderState().monitor)}getBindings(){return this._bindings||(this._bindings=this.getNodeBuilderState().createBindings())}getIndex(){return this._geometries.getIndex(this)}getIndirect(){return this._geometries.getIndirect(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,n=[],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;n.push(t);const s=t.isInterleavedBufferAttribute?t.data:t;i.add(s)}return this.attributes=n,this.vertexBuffers=Array.from(i.values()),n}getVertexBuffers(){return null===this.vertexBuffers&&this.getAttributes(),this.vertexBuffers}getDrawParameters(){const{object:t,material:e,geometry:n,group:i,drawRange:r}=this,s=this.drawParams||(this.drawParams={vertexCount:0,firstVertex:0,instanceCount:0,firstInstance:0}),a=this.getIndex(),o=null!==a,l=n.isInstancedBufferGeometry?n.instanceCount:t.count>1?t.count:1;if(0===l)return null;if(s.instanceCount=l,!0===t.isBatchedMesh)return s;let h=1;!0!==e.wireframe||t.isPoints||t.isLineSegments||t.isLine||t.isLineLoop||(h=2);let u=r.start*h,c=(r.start+r.count)*h;null!==i&&(u=Math.max(u,i.start*h),c=Math.min(c,(i.start+i.count)*h));const d=n.attributes.position;let p=1/0;o?p=a.count:null!=d&&(p=d.count),u=Math.max(u,0),c=Math.min(c,p);const f=c-u;return f<0||f===1/0?null:(s.vertexCount=f,s.firstVertex=u,s)}getGeometryCacheKey(){const{geometry:t}=this;let e="";for(const n of Object.keys(t.attributes).sort()){const i=t.attributes[n];e+=n+",",i.data&&(e+=i.data.stride+","),i.offset&&(e+=i.offset+","),i.itemSize&&(e+=i.itemSize+","),i.normalized&&(e+="n,")}return t.index&&(e+="index,"),e}getMaterialCacheKey(){const{object:t,material:e}=this;let n=e.customProgramCacheKey();for(const t of function(t){const e=Object.keys(t);let n=Object.getPrototypeOf(t);for(;n;){const t=Object.getOwnPropertyDescriptors(n);for(const n in t)if(void 0!==t[n]){const i=t[n];i&&"function"==typeof i.get&&e.push(n)}n=Object.getPrototypeOf(n)}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);n+=r+","}return n+=this.clippingContext.cacheKey+",",t.geometry&&(n+=this.getGeometryCacheKey()),t.skeleton&&(n+=t.skeleton.bones.length+","),t.morphTargetInfluences&&(n+=t.morphTargetInfluences.length+","),t.isBatchedMesh&&(n+=t._matricesTexture.uuid+",",null!==t._colorsTexture&&(n+=t._colorsTexture.uuid+",")),t.count>1&&(n+=t.uuid+","),J_(n)}get needsUpdate(){return this.initialNodesCacheKey!==this.getDynamicCacheKey()||this.clippingNeedsUpdate}getDynamicCacheKey(){let t=this._nodes.getCacheKey(this.scene,this.lightsNode);return this.object.receiveShadow&&(t+=1),t}getCacheKey(){return this.getMaterialCacheKey()+this.getDynamicCacheKey()}dispose(){this.material.removeEventListener("dispose",this.onMaterialDispose),this.onDispose()}}const UA=[];class DA{constructor(t,e,n,i,r,s){this.renderer=t,this.nodes=e,this.geometries=n,this.pipelines=i,this.bindings=r,this.info=s,this.chainMaps={}}get(t,e,n,i,r,s,a){const o=this.getChainMap(a);UA[0]=t,UA[1]=e,UA[2]=s,UA[3]=r;let l=o.get(UA);return void 0===l?(l=this.createRenderObject(this.nodes,this.geometries,this.renderer,t,e,n,i,r,s,a),o.set(UA,l)):(l.updateClipping(s.clippingContext),(l.version!==e.version||l.needsUpdate)&&(l.initialCacheKey!==l.getCacheKey()?(l.dispose(),l=this.get(t,e,n,i,r,s,a)):l.version=e.version)),l}getChainMap(t="default"){return this.chainMaps[t]||(this.chainMaps[t]=new CA)}dispose(){this.chainMaps={}}createRenderObject(t,e,n,i,r,s,a,o,l,h){const u=this.getChainMap(h),c=new LA(t,e,n,i,r,s,a,o,l);return c.onDispose=()=>{this.pipelines.delete(c),this.bindings.delete(c),this.nodes.delete(c),u.delete(c.getChainArray())},c}}class OA{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 FA=1,BA=2,zA=3,kA=4,GA=16;class VA extends OA{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 n=this.get(t);if(void 0===n.version)e===FA?this.backend.createAttribute(t):e===BA?this.backend.createIndexAttribute(t):e===zA?this.backend.createStorageAttribute(t):e===kA&&this.backend.createIndirectStorageAttribute(t),n.version=this._getBufferAttribute(t).version;else{const e=this._getBufferAttribute(t);(n.version<e.version||e.usage===Qp)&&(this.backend.updateAttribute(t),n.version=e.version)}}_getBufferAttribute(t){return t.isInterleavedBufferAttribute&&(t=t.data),t}}function HA(t){return null!==t.index?t.index.version:t.attributes.position.version}function jA(t){const e=[],n=t.index,i=t.attributes.position;if(null!==n){const t=n.array;for(let n=0,i=t.length;n<i;n+=3){const i=t[n+0],r=t[n+1],s=t[n+2];e.push(i,r,r,s,s,i)}}else{for(let t=0,n=i.array.length/3-1;t<n;t+=3){const n=t+0,i=t+1,r=t+2;e.push(n,i,i,r,r,n)}}const r=new(function(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}(e)?xg:yg)(e,1);return r.version=HA(t),r}class WA extends OA{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 n=()=>{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 s=this.wireframes.get(e);void 0!==s&&this.attributes.delete(s),e.removeEventListener("dispose",n)};e.addEventListener("dispose",n)}updateAttributes(t){const e=t.getAttributes();for(const t of e)t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute?this.updateAttribute(t,zA):this.updateAttribute(t,FA);const n=this.getIndex(t);null!==n&&this.updateAttribute(n,BA);const i=t.geometry.indirect;null!==i&&this.updateAttribute(i,kA)}updateAttribute(t,e){const n=this.info.render.calls;t.isInterleavedBufferAttribute?void 0===this.attributeCall.get(t)?(this.attributes.update(t,e),this.attributeCall.set(t,n)):this.attributeCall.get(t.data)!==n&&(this.attributes.update(t,e),this.attributeCall.set(t.data,n),this.attributeCall.set(t,n)):this.attributeCall.get(t)!==n&&(this.attributes.update(t,e),this.attributeCall.set(t,n))}getIndirect(t){return t.geometry.indirect}getIndex(t){const{geometry:e,material:n}=t;let i=e.index;if(!0===n.wireframe){const t=this.wireframes;let n=t.get(e);void 0===n?(n=jA(e),t.set(e,n)):n.version!==HA(e)&&(this.attributes.delete(n),n=jA(e),t.set(e,n)),i=n}return i}}class qA{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,n){this.render.drawCalls++,t.isMesh||t.isSprite?this.render.triangles+=n*(e/3):t.isPoints?this.render.points+=n*e:t.isLineSegments?this.render.lines+=n*(e/2):t.isLine?this.render.lines+=n*(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 XA{constructor(t){this.cacheKey=t,this.usedTimes=0}}class $A extends XA{constructor(t,e,n){super(t),this.vertexProgram=e,this.fragmentProgram=n}}class YA extends XA{constructor(t,e){super(t),this.computeProgram=e,this.isComputePipeline=!0}}let KA=0;class ZA{constructor(t,e,n=null,i=null){this.id=KA++,this.code=t,this.stage=e,this.transforms=n,this.attributes=i,this.usedTimes=0}}class QA extends OA{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:n}=this,i=this.get(t);if(this._needsComputeUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.computeProgram.usedTimes--);const s=this.nodes.getForCompute(t);let a=this.programs.compute.get(s.computeShader);void 0===a&&(r&&0===r.computeProgram.usedTimes&&this._releaseProgram(r.computeProgram),a=new ZA(s.computeShader,"compute",s.transforms,s.nodeAttributes),this.programs.compute.set(s.computeShader,a),n.createProgram(a));const o=this._getComputeCacheKey(t,a);let l=this.caches.get(o);void 0===l&&(r&&0===r.usedTimes&&this._releasePipeline(r),l=this._getComputePipeline(t,a,o,e)),l.usedTimes++,a.usedTimes++,i.version=t.version,i.pipeline=l}return i.pipeline}getForRender(t,e=null){const{backend:n}=this,i=this.get(t);if(this._needsRenderUpdate(t)){const r=i.pipeline;r&&(r.usedTimes--,r.vertexProgram.usedTimes--,r.fragmentProgram.usedTimes--);const s=t.getNodeBuilderState();let a=this.programs.vertex.get(s.vertexShader);void 0===a&&(r&&0===r.vertexProgram.usedTimes&&this._releaseProgram(r.vertexProgram),a=new ZA(s.vertexShader,"vertex"),this.programs.vertex.set(s.vertexShader,a),n.createProgram(a));let o=this.programs.fragment.get(s.fragmentShader);void 0===o&&(r&&0===r.fragmentProgram.usedTimes&&this._releaseProgram(r.fragmentProgram),o=new ZA(s.fragmentShader,"fragment"),this.programs.fragment.set(s.fragmentShader,o),n.createProgram(o));const l=this._getRenderCacheKey(t,a,o);let h=this.caches.get(l);void 0===h?(r&&0===r.usedTimes&&this._releasePipeline(r),h=this._getRenderPipeline(t,a,o,l,e)):t.pipeline=h,h.usedTimes++,a.usedTimes++,o.usedTimes++,i.pipeline=h}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,n,i){n=n||this._getComputeCacheKey(t,e);let r=this.caches.get(n);return void 0===r&&(r=new YA(n,e),this.caches.set(n,r),this.backend.createComputePipeline(r,i)),r}_getRenderPipeline(t,e,n,i,r){i=i||this._getRenderCacheKey(t,e,n);let s=this.caches.get(i);return void 0===s&&(s=new $A(i,e,n),this.caches.set(i,s),t.pipeline=s,this.backend.createRenderPipeline(t,r)),s}_getComputeCacheKey(t,e){return t.id+","+e.id}_getRenderCacheKey(t,e,n){return e.id+","+n.id+","+this.backend.getRenderCacheKey(t)}_releasePipeline(t){this.caches.delete(t.cacheKey)}_releaseProgram(t){const e=t.code,n=t.stage;this.programs[n].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 JA extends OA{constructor(t,e,n,i,r,s){super(),this.backend=t,this.textures=n,this.pipelines=r,this.attributes=i,this.nodes=e,this.info=s,this.pipelines.bindings=this}getForRender(t){const e=t.getBindings();for(const t of e){const n=this.get(t);void 0===n.bindGroup&&(this._init(t),this.backend.createBindings(t,e),n.bindGroup=t)}return e}getForCompute(t){const e=this.nodes.getForCompute(t).bindings;for(const t of e){const n=this.get(t);void 0===n.bindGroup&&(this._init(t),this.backend.createBindings(t,e),n.bindGroup=t)}return e}updateForCompute(t){this._updateBindings(this.getForCompute(t))}updateForRender(t){this._updateBindings(this.getForRender(t))}_updateBindings(t){for(const e of t)this._update(e,t)}_init(t){for(const e of t.bindings)if(e.isSampledTexture)this.textures.updateTexture(e.texture);else if(e.isStorageBuffer){const t=e.attribute,n=t.isIndirectStorageBufferAttribute?kA:zA;this.attributes.update(t,n)}}_update(t,e){const{backend:n}=this;let i=!1;for(const e of t.bindings){if(e.isNodeUniformsGroup){if(!this.nodes.updateGroup(e))continue}if(e.isUniformBuffer){e.update()&&n.updateBinding(e)}else if(e.isSampler)e.update();else if(e.isSampledTexture){e.needsBindingsUpdate(this.textures.get(e.texture).generation)&&(i=!0);const t=e.update(),r=e.texture;t&&this.textures.updateTexture(r);const s=n.get(r);if(!0===n.isWebGPUBackend&&void 0===s.texture&&void 0===s.externalTexture&&(console.error("Bindings._update: binding should be available:",e,t,r,e.textureNode.value,i),this.textures.updateTexture(r),i=!0),!0===r.isStorageTexture){const t=this.get(r);!0===e.store?t.needsMipmap=!0:this.textures.needsMipmaps(r)&&!0===t.needsMipmap&&(this.backend.generateMipmaps(r),t.needsMipmap=!1)}}}!0===i&&this.backend.updateBindings(t,e)}}function tR(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 eR(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}function nR(t){return(t.transmission>0||t.transmissionNode)&&2===t.side&&!1===t.forceSinglePass}class iR{constructor(t,e,n){this.renderItems=[],this.renderItemsIndex=0,this.opaque=[],this.transparentDoublePass=[],this.transparent=[],this.bundles=[],this.lightsNode=t.getNode(e,n),this.lightsArray=[],this.scene=e,this.camera=n,this.occlusionQueryCount=0}begin(){return this.renderItemsIndex=0,this.opaque.length=0,this.transparentDoublePass.length=0,this.transparent.length=0,this.bundles.length=0,this.lightsArray.length=0,this.occlusionQueryCount=0,this}getNextRenderItem(t,e,n,i,r,s){let a=this.renderItems[this.renderItemsIndex];return void 0===a?(a={id:t.id,object:t,geometry:e,material:n,groupOrder:i,renderOrder:t.renderOrder,z:r,group:s},this.renderItems[this.renderItemsIndex]=a):(a.id=t.id,a.object=t,a.geometry=e,a.material=n,a.groupOrder=i,a.renderOrder=t.renderOrder,a.z=r,a.group=s),this.renderItemsIndex++,a}push(t,e,n,i,r,s){const a=this.getNextRenderItem(t,e,n,i,r,s);!0===t.occlusionTest&&this.occlusionQueryCount++,!0===n.transparent||n.transmission>0?(nR(n)&&this.transparentDoublePass.push(a),this.transparent.push(a)):this.opaque.push(a)}unshift(t,e,n,i,r,s){const a=this.getNextRenderItem(t,e,n,i,r,s);!0===n.transparent||n.transmission>0?(nR(n)&&this.transparentDoublePass.unshift(a),this.transparent.unshift(a)):this.opaque.unshift(a)}pushBundle(t){this.bundles.push(t)}pushLight(t){this.lightsArray.push(t)}sort(t,e){this.opaque.length>1&&this.opaque.sort(t||tR),this.transparentDoublePass.length>1&&this.transparentDoublePass.sort(e||eR),this.transparent.length>1&&this.transparent.sort(e||eR)}finish(){this.lightsNode.setLights(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 rR{constructor(t){this.lighting=t,this.lists=new CA}get(t,e){const n=this.lists,i=[t,e];let r=n.get(i);return void 0===r&&(r=new iR(this.lighting,t,e),n.set(i,r)),r}dispose(){this.lists=new CA}}let sR=0;class aR{constructor(){this.id=sR++,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 Uf,this.scissor=!1,this.scissorValue=new Uf,this.textures=null,this.depthTexture=null,this.activeCubeFace=0,this.sampleCount=1,this.width=0,this.height=0,this.isRenderContext=!0}getCacheKey(){return oR(this)}}function oR(t){const{textures:e,activeCubeFace:n}=t,i=[n];for(const t of e)i.push(t.id);return tv(i)}class lR{constructor(){this.chainMaps={}}get(t,e,n=null){const i=[t,e];let r;if(null===n)r="default";else{const t=n.texture.format;r=`${n.textures.length}:${t}:${n.samples}:${n.depthBuffer}:${n.stencilBuffer}`}const s=this.getChainMap(r);let a=s.get(i);return void 0===a&&(a=new aR,s.set(i,a)),null!==n&&(a.sampleCount=0===n.samples?1:n.samples),a}getChainMap(t){return this.chainMaps[t]||(this.chainMaps[t]=new CA)}dispose(){this.chainMaps={}}}const hR=new zf;class uR extends OA{constructor(t,e,n){super(),this.renderer=t,this.backend=e,this.info=n}updateRenderTarget(t,e=0){const n=this.get(t),i=0===t.samples?1:t.samples,r=n.depthTextureMips||(n.depthTextureMips={}),s=t.textures,a=this.getSize(s[0]),o=a.width>>e,l=a.height>>e;let h=t.depthTexture||r[e];const u=!0===t.depthBuffer||!0===t.stencilBuffer;let c=!1;void 0===h&&u&&(h=new y_,h.format=t.stencilBuffer?up:hp,h.type=t.stencilBuffer?ap:ip,h.image.width=o,h.image.height=l,r[e]=h),n.width===a.width&&a.height===n.height||(c=!0,h&&(h.needsUpdate=!0,h.image.width=o,h.image.height=l)),n.width=a.width,n.height=a.height,n.textures=s,n.depthTexture=h||null,n.depth=t.depthBuffer,n.stencil=t.stencilBuffer,n.renderTarget=t,n.sampleCount!==i&&(c=!0,h&&(h.needsUpdate=!0),n.sampleCount=i);const d={sampleCount:i};for(let t=0;t<s.length;t++){const e=s[t];c&&(e.needsUpdate=!0),this.updateTexture(e,d)}if(h&&this.updateTexture(h,d),!0!==n.initialized){n.initialized=!0;const e=()=>{t.removeEventListener("dispose",e);for(let t=0;t<s.length;t++)this._destroyTexture(s[t]);h&&this._destroyTexture(h),this.delete(t)};t.addEventListener("dispose",e)}}updateTexture(t,e={}){const n=this.get(t);if(!0===n.initialized&&n.version===t.version)return;const i=t.isRenderTargetTexture||t.isDepthTexture||t.isFramebufferTexture,r=this.backend;if(i&&!0===n.initialized&&(r.destroySampler(t),r.destroyTexture(t)),t.isFramebufferTexture){const e=this.renderer.getRenderTarget();t.type=e?e.texture.type:Qd}const{width:s,height:a,depth:o}=this.getSize(t);if(e.width=s,e.height=a,e.depth=o,e.needsMipmaps=this.needsMipmaps(t),e.levels=e.needsMipmaps?this.getMipLevels(t,s,a):1,i||!0===t.isStorageTexture)r.createSampler(t),r.createTexture(t,e),n.generation=t.version;else{if(!0!==n.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 n=[];for(const e of t.images)n.push(e);e.images=n}else e.image=i;void 0!==n.isDefaultTexture&&!0!==n.isDefaultTexture||(r.createTexture(t,e),n.isDefaultTexture=!1,n.generation=t.version),!0===t.source.dataReady&&r.updateTexture(t,e),e.needsMipmaps&&0===t.mipmaps.length&&r.generateMipmaps(t)}}else r.createDefaultTexture(t),n.isDefaultTexture=!0,n.generation=t.version}if(!0!==n.initialized){n.initialized=!0,n.generation=t.version,this.info.memory.textures++;const e=()=>{t.removeEventListener("dispose",e),this._destroyTexture(t),this.info.memory.textures--};t.addEventListener("dispose",e)}n.version=t.version}getSize(t,e=hR){let n=t.images?t.images[0]:t.image;return n?(void 0!==n.image&&(n=n.image),e.width=n.width,e.height=n.height,e.depth=t.isCubeTexture?6:n.depth||1):e.width=e.height=e.depth=1,e}getMipLevels(t,e,n){let i;return i=t.isCompressedTexture?t.mipmaps.length:Math.floor(Math.log2(Math.max(e,n)))+1,i}needsMipmaps(t){return this.isEnvironmentTexture(t)||!0===t.isCompressedTexture||t.generateMipmaps}isEnvironmentTexture(t){const e=t.mapping;return e===Gd||e===Vd||e===zd||e===kd}_destroyTexture(t){this.backend.destroySampler(t),this.backend.destroyTexture(t),this.delete(t)}}class cR extends og{constructor(t,e,n,i=1){super(t,e,n),this.a=i}set(t,e,n,i=1){return this.a=i,super.set(t,e,n)}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)}}class dR extends Fy{static get type(){return"ParameterNode"}constructor(t,e=null){super(t,e),this.isParameterNode=!0}getHash(){return this.uuid}generate(){return this.name}}class pR extends mv{static get type(){return"StackNode"}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 n=new Jv(e);return this._currentCond=Gb(t,n),this.add(this._currentCond)}ElseIf(t,e){const n=new Jv(e),i=Gb(t,n);return this._currentCond.elseNode=i,this._currentCond=i,this}Else(t){return this._currentCond.elseNode=new Jv(t),this}build(t,...e){const n=oy();ay(this);for(const e of this.nodes)e.build(t,"void");return ay(n),this.outputNode?this.outputNode.build(t,...e):super.build(t,...e)}else(...t){return console.warn("TSL.StackNode: .else() has been renamed to .Else()."),this.Else(...t)}elseif(...t){return console.warn("TSL.StackNode: .elseif() has been renamed to .ElseIf()."),this.ElseIf(...t)}}const fR=iy(pR);new d_,new zf,new zf,new zf,new mm,new zf(0,0,-1),new Uf,new zf,new zf,new Uf,new ff;const mR=new Df;qT.flipX(),mR.depthTexture=new y_(1,1);const gR=new H_(-1,1,1,-1,0,1);class _R extends Ng{constructor(t=!1){super();const e=!1===t?[0,-1,0,1,2,1]:[0,2,0,0,2,0];this.setAttribute("position",new Sg([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new Sg(e,2))}}const vR=new _R;class yR extends Vg{constructor(t=null){super(vR,t),this.camera=gR,this.isQuadMesh=!0}renderAsync(t){return t.renderAsync(this,gR)}render(t){t.render(this,gR)}}const xR=new wm,bR=new mm;class SR extends mv{static get type(){return"SceneNode"}constructor(t=SR.BACKGROUND_BLURRINESS,e=null){super(),this.scope=t,this.scene=e}setup(t){const e=this.scope,n=null!==this.scene?this.scene:t.scene;let i;return e===SR.BACKGROUND_BLURRINESS?i=yM("backgroundBlurriness","float",n):e===SR.BACKGROUND_INTENSITY?i=yM("backgroundIntensity","float",n):e===SR.BACKGROUND_ROTATION?i=Oy("mat4").label("backgroundRotation").setGroup(Ly).onRenderUpdate((()=>{const t=n.background;return null!==t&&t.isTexture&&300!==t.mapping?(xR.copy(n.backgroundRotation),xR.x*=-1,xR.y*=-1,xR.z*=-1,bR.makeRotationFromEuler(xR)):bR.identity(),bR})):console.error("THREE.SceneNode: Unknown scope:",e),i}}SR.BACKGROUND_BLURRINESS="backgroundBlurriness",SR.BACKGROUND_INTENSITY="backgroundIntensity",SR.BACKGROUND_ROTATION="backgroundRotation";const MR=ry(SR,SR.BACKGROUND_BLURRINESS),TR=ry(SR,SR.BACKGROUND_INTENSITY),wR=ry(SR,SR.BACKGROUND_ROTATION),ER="point-list",AR="line-list",RR="line-strip",CR="triangle-list",NR="triangle-strip",PR="never",IR="less",LR="equal",UR="less-equal",DR="greater",OR="not-equal",FR="greater-equal",BR="always",zR="store",kR="load",GR="clear",VR="ccw",HR="none",jR="front",WR="back",qR="uint16",XR="uint32",$R={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"},YR="clamp-to-edge",KR="repeat",ZR="mirror-repeat",QR="linear",JR="nearest",tC="zero",eC="one",nC="src",iC="one-minus-src",rC="src-alpha",sC="one-minus-src-alpha",aC="dst",oC="one-minus-dst",lC="dst-alpha",hC="one-minus-dst-alpha",uC="src-alpha-saturated",cC="constant",dC="one-minus-constant",pC="add",fC="subtract",mC="reverse-subtract",gC="min",_C="max",vC=0,yC=15,xC="keep",bC="zero",SC="replace",MC="invert",TC="increment-clamp",wC="decrement-clamp",EC="increment-wrap",AC="decrement-wrap",RC="storage",CC="read-only-storage",NC="write-only",PC="read-only",IC="float",LC="unfilterable-float",UC="depth",DC="sint",OC="uint",FC="2d",BC="3d",zC="2d",kC="2d-array",GC="cube",VC="3d",HC="all",jC="vertex",WC="instance",qC={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",Subgroups:"subgroups"},XC=new ff;class $C extends AS{static get type(){return"PassTextureNode"}constructor(t,e){super(e),this.passNode=t,this.setUpdateMatrix(!1)}setup(t){return t.object.isQuadMesh&&this.passNode.build(t),super.setup(t)}clone(){return new this.constructor(this.passNode,this.value)}}class YC extends $C{static get type(){return"PassMultipleTextureNode"}constructor(t,e,n=!1){super(t,null),this.textureName=e,this.previousTexture=n}updateTexture(){this.value=this.previousTexture?this.passNode.getPreviousTexture(this.textureName):this.passNode.getTexture(this.textureName)}setup(t){return this.updateTexture(),super.setup(t)}clone(){return new this.constructor(this.passNode,this.textureName,this.previousTexture)}}class KC extends vv{static get type(){return"PassNode"}constructor(t,e,n,i={}){super("vec4"),this.scope=t,this.scene=e,this.camera=n,this.options=i,this._pixelRatio=1,this._width=1,this._height=1;const r=new y_;r.isRenderTargetTexture=!0,r.name="depth";const s=new Df(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:sp,...i});s.texture.name="output",s.depthTexture=r,this.renderTarget=s,this.updateBeforeType=lv,this._textures={output:s.texture,depth:r},this._textureNodes={},this._linearDepthNodes={},this._viewZNodes={},this._previousTextures={},this._previousTextureNodes={},this._cameraNear=Oy(0),this._cameraFar=Oy(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}getPreviousTexture(t){let e=this._previousTextures[t];return void 0===e&&(e=this.getTexture(t).clone(),e.isRenderTargetTexture=!0,this._previousTextures[t]=e),e}toggleTexture(t){const e=this._previousTextures[t];if(void 0!==e){const n=this._textures[t],i=this.renderTarget.textures.indexOf(n);this.renderTarget.textures[i]=e,this._textures[t]=e,this._previousTextures[t]=n,this._textureNodes[t].updateTexture(),this._previousTextureNodes[t].updateTexture()}}getTextureNode(t="output"){let e=this._textureNodes[t];return void 0===e&&(e=ty(new YC(this,t)),e.updateTexture(),this._textureNodes[t]=e),e}getPreviousTextureNode(t="output"){let e=this._previousTextureNodes[t];return void 0===e&&(void 0===this._textureNodes[t]&&this.getTextureNode(t),e=ty(new YC(this,t,!0)),e.updateTexture(),this._previousTextureNodes[t]=e),e}getViewZNode(t="depth"){let e=this._viewZNodes[t];if(void 0===e){const n=this._cameraNear,i=this._cameraFar;this._viewZNodes[t]=e=sw(this.getTextureNode(t),n,i)}return e}getLinearDepthNode(t="depth"){let e=this._linearDepthNodes[t];if(void 0===e){const n=this._cameraNear,i=this._cameraFar,r=this.getViewZNode(t);this._linearDepthNodes[t]=e=iw(r,n,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===KC.COLOR?this.getTextureNode():this.getLinearDepthNode()}updateBefore(t){const{renderer:e}=t,{scene:n,camera:i}=this;this._pixelRatio=e.getPixelRatio();const r=e.getSize(XC);this.setSize(r.width,r.height);const s=e.getRenderTarget(),a=e.getMRT();this._cameraNear.value=i.near,this._cameraFar.value=i.far;for(const t in this._previousTextures)this.toggleTexture(t);e.setRenderTarget(this.renderTarget),e.setMRT(this._mrt),e.render(n,i),e.setRenderTarget(s),e.setMRT(a)}setSize(t,e){this._width=t,this._height=e;const n=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget.setSize(n,i)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget.dispose()}}KC.COLOR="color",KC.DEPTH="depth";const ZC=sy((([t,e])=>t.mul(e).clamp())).setLayout({name:"linearToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),QC=sy((([t,e])=>(t=t.mul(e)).div(t.add(1)).clamp())).setLayout({name:"reinhardToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),JC=sy((([t,e])=>{const n=(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 n.div(i).pow(2.2)})).setLayout({name:"cineonToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),tN=sy((([t])=>{const e=t.mul(t.add(.0245786)).sub(90537e-9),n=t.mul(t.add(.432951).mul(.983729)).add(.238081);return e.div(n)})),eN=sy((([t,e])=>{const n=Ay(.59719,.35458,.04823,.076,.90834,.01566,.0284,.13383,.83777),i=Ay(1.60475,-.53108,-.07367,-.10208,1.10813,-.00605,-.00327,-.07276,1.07602);return t=t.mul(e).div(.6),t=n.mul(t),t=tN(t),(t=i.mul(t)).clamp()})).setLayout({name:"acesFilmicToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),nN=Ay(vy(1.6605,-.1246,-.0182),vy(-.5876,1.1329,-.1006),vy(-.0728,-.0083,1.1187)),iN=Ay(vy(.6274,.0691,.0164),vy(.3293,.9195,.088),vy(.0433,.0113,.8956)),rN=sy((([t])=>{const e=vy(t).toVar(),n=vy(e.mul(e)).toVar(),i=vy(n.mul(n)).toVar();return uy(15.5).mul(i.mul(n)).sub(vx(40.14,i.mul(e))).add(vx(31.96,i).sub(vx(6.868,n.mul(e))).add(vx(.4298,n).add(vx(.1191,e).sub(.00232))))})),sN=sy((([t,e])=>{const n=vy(t).toVar(),i=Ay(vy(.856627153315983,.137318972929847,.11189821299995),vy(.0951212405381588,.761241990602591,.0767994186031903),vy(.0482516061458583,.101439036467562,.811302368396859)),r=Ay(vy(1.1271005818144368,-.1413297634984383,-.14132976349843826),vy(-.11060664309660323,1.157823702216272,-.11060664309660294),vy(-.016493938717834573,-.016493938717834257,1.2519364065950405)),s=uy(-12.47393),a=uy(4.026069);return n.mulAssign(e),n.assign(iN.mul(n)),n.assign(i.mul(n)),n.assign(bb(n,1e-10)),n.assign($x(n)),n.assign(n.sub(s).div(a.sub(s))),n.assign(Db(n,0,1)),n.assign(rN(n)),n.assign(r.mul(n)),n.assign(Cb(bb(vy(0),n),vy(2.2))),n.assign(nN.mul(n)),n.assign(Db(n,0,1)),n})).setLayout({name:"agxToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]}),aN=sy((([t,e])=>{const n=uy(.76),i=uy(.15);t=t.mul(e);const r=xb(t.r,xb(t.g,t.b)),s=Gb(r.lessThan(.08),r.sub(vx(6.25,r.mul(r))),.04);t.subAssign(s);const a=bb(t.r,bb(t.g,t.b));ly(a.lessThan(n),(()=>t));const o=_x(1,n),l=_x(1,o.mul(o).div(a.add(o.sub(n))));t.mulAssign(l.div(a));const h=_x(1,yx(1,i.mul(a.sub(l)).add(1)));return Ub(t,vy(l),h)})).setLayout({name:"neutralToneMapping",type:"vec3",inputs:[{name:"color",type:"vec3"},{name:"exposure",type:"float"}]});class oN extends mv{static get type(){return"CodeNode"}constructor(t="",e=[],n=""){super("code"),this.isCodeNode=!0,this.code=t,this.language=n,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 n of e)n.build(t);const n=t.getCodeFromNode(this,this.getNodeType(t));return n.code=this.code,n.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}}class lN extends oN{static get type(){return"FunctionNode"}constructor(t="",e=[],n=""){super(t,e,n)}getNodeType(t){return this.getNodeFunction(t).type}getInputs(t){return this.getNodeFunction(t).inputs}getNodeFunction(t){const e=t.getDataFromNode(this);let n=e.nodeFunction;return void 0===n&&(n=t.parser.parseFunction(this.code),e.nodeFunction=n),n}generate(t,e){super.generate(t);const n=this.getNodeFunction(t),i=n.name,r=n.type,s=t.getCodeFromNode(this,r);""!==i&&(s.name=i);const a=t.getPropertyName(s),o=this.getNodeFunction(t).getCode(a);return s.code=o+"\n","property"===e?a:t.format(`${a}()`,r,e)}}class hN extends mv{static get type(){return"FogNode"}constructor(t,e){super("float"),this.isFogNode=!0,this.colorNode=t,this.factorNode=e}getViewZNode(t){let e;const n=t.context.getViewZ;return void 0!==n&&(e=n(this)),(e||WS.z).negate()}setup(){return this.factorNode}}class uN extends hN{static get type(){return"FogRangeNode"}constructor(t,e,n){super(t),this.isFogRangeNode=!0,this.nearNode=e,this.farNode=n}setup(t){const e=this.getViewZNode(t);return Fb(this.nearNode,this.farNode,e)}}const cN=iy(uN);class dN extends hN{static get type(){return"FogExp2Node"}constructor(t,e){super(t),this.isFogExp2Node=!0,this.densityNode=e}setup(t){const e=this.getViewZNode(t),n=this.densityNode;return n.mul(n,e,e).negate().exp().oneMinus()}}const pN=iy(dN);iy(class extends mv{constructor(t){super(),this.scope=t}generate(t){const{scope:e}=this,{renderer:n}=t;!0===n.backend.isWebGLBackend?t.addFlowCode(`\t// ${e}Barrier \n`):t.addLineFlowCode(`${e}Barrier()`,this)}});class fN extends vv{static get type(){return"AtomicFunctionNode"}constructor(t,e,n,i=null){super("uint"),this.method=t,this.pointerNode=e,this.valueNode=n,this.storeNode=i}getInputType(t){return this.pointerNode.getNodeType(t)}getNodeType(t){return this.getInputType(t)}generate(t){const e=this.method,n=this.getNodeType(t),i=this.getInputType(t),r=this.pointerNode,s=this.valueNode,a=[];a.push(`&${r.build(t,i)}`),a.push(s.build(t,i));const o=`${t.getMethod(e,n)}( ${a.join(", ")} )`;if(null!==this.storeNode){const e=this.storeNode.build(t,i);t.addLineFlowCode(`${e} = ${o}`,this)}else t.addLineFlowCode(o,this)}}let mN;function gN(t){mN=mN||new WeakMap;let e=mN.get(t);return void 0===e&&mN.set(t,e={}),e}function _N(t){const e=gN(t);return e.position||(e.position=Oy(new zf).setGroup(Ly).onRenderUpdate(((e,n)=>n.value.setFromMatrixPosition(t.matrixWorld))))}function vN(t){const e=gN(t);return e.viewPosition||(e.viewPosition=Oy(new zf).setGroup(Ly).onRenderUpdate((({camera:e},n)=>{n.value=n.value||new zf,n.value.setFromMatrixPosition(t.matrixWorld),n.value.applyMatrix4(e.matrixWorldInverse)})))}fN.ATOMIC_LOAD="atomicLoad",fN.ATOMIC_STORE="atomicStore",fN.ATOMIC_ADD="atomicAdd",fN.ATOMIC_SUB="atomicSub",fN.ATOMIC_MAX="atomicMax",fN.ATOMIC_MIN="atomicMin",fN.ATOMIC_AND="atomicAnd",fN.ATOMIC_OR="atomicOr",fN.ATOMIC_XOR="atomicXor",iy(fN);const yN=t=>LS.transformDirection(_N(t).sub(function(t){const e=gN(t);return e.targetPosition||(e.targetPosition=Oy(new zf).setGroup(Ly).onRenderUpdate(((e,n)=>n.value.setFromMatrixPosition(t.target.matrixWorld))))}(t))),xN=(t,e)=>{for(const n of e)if(n.isAnalyticLightNode&&n.light.id===t)return n;return null},bN=new WeakMap;class SN extends mv{static get type(){return"LightsNode"}constructor(){super("vec3"),this.totalDiffuseNode=vy().toVar("totalDiffuse"),this.totalSpecularNode=vy().toVar("totalSpecular"),this.outgoingLightNode=vy().toVar("outgoingLight"),this._lights=[],this._lightNodes=null,this._lightNodesHash=null,this.global=!0}getHash(t){if(null===this._lightNodesHash){null===this._lightNodes&&this.setupLightsNode(t);const e=[];for(const t of this._lightNodes)e.push(t.getSelf().getHash());this._lightNodesHash="lights-"+e.join(",")}return this._lightNodesHash}analyze(t){const e=t.getDataFromNode(this);for(const n of e.nodes)n.build(t)}setupLightsNode(t){const e=[],n=this._lightNodes,i=(t=>t.sort(((t,e)=>t.id-e.id)))(this._lights),r=t.renderer.library;for(const t of i)if(t.isNode)e.push(ty(t));else{let i=null;if(null!==n&&(i=xN(t.id,n)),null===i){const n=r.getLightNodeClass(t.constructor);if(null===n){console.warn(`LightsNode.setupNodeLights: Light node not found for ${t.constructor.name}`);continue}let i=null;bN.has(t)?i=bN.get(t):(i=ty(new n(t)),bN.set(t,i)),e.push(i)}}this._lightNodes=e}setupLights(t,e){for(const n of e)n.build(t)}setup(t){null===this._lightNodes&&this.setupLightsNode(t);const e=t.context,n=e.lightingModel;let i=this.outgoingLightNode;if(n){const{_lightNodes:r,totalDiffuseNode:s,totalSpecularNode:a}=this;e.outgoingLight=i;const o=t.addStack();t.getDataFromNode(this).nodes=o.nodes,n.start(e,o,t),this.setupLights(t,r),n.indirect(e,o,t);const{backdrop:l,backdropAlpha:h}=e,{directDiffuse:u,directSpecular:c,indirectDiffuse:d,indirectSpecular:p}=e.reflectedLight;let f=u.add(d);null!==l&&(f=vy(null!==h?h.mix(f,l):l),e.material.transparent=!0),s.assign(f),a.assign(c.add(p)),i.assign(s.add(a)),n.finish(e,o,t),i=i.bypass(t.removeStack())}return i}setLights(t){return this._lights=t,this._lightNodes=null,this._lightNodesHash=null,this}getLights(){return this._lights}get hasLights(){return this._lights.length>0}}const MN=sy((({depthTexture:t,shadowCoord:e})=>RS(t,e.xy).compare(e.z))),TN=sy((({depthTexture:t,shadowCoord:e,shadow:n})=>{const i=(e,n)=>RS(t,e).compare(n),r=yM("mapSize","vec2",n).setGroup(Ly),s=yM("radius","float",n).setGroup(Ly),a=fy(1).div(r),o=a.x.negate().mul(s),l=a.y.negate().mul(s),h=a.x.mul(s),u=a.y.mul(s),c=o.div(2),d=l.div(2),p=h.div(2),f=u.div(2);return gx(i(e.xy.add(fy(o,l)),e.z),i(e.xy.add(fy(0,l)),e.z),i(e.xy.add(fy(h,l)),e.z),i(e.xy.add(fy(c,d)),e.z),i(e.xy.add(fy(0,d)),e.z),i(e.xy.add(fy(p,d)),e.z),i(e.xy.add(fy(o,0)),e.z),i(e.xy.add(fy(c,0)),e.z),i(e.xy,e.z),i(e.xy.add(fy(p,0)),e.z),i(e.xy.add(fy(h,0)),e.z),i(e.xy.add(fy(c,f)),e.z),i(e.xy.add(fy(0,f)),e.z),i(e.xy.add(fy(p,f)),e.z),i(e.xy.add(fy(o,u)),e.z),i(e.xy.add(fy(0,u)),e.z),i(e.xy.add(fy(h,u)),e.z)).mul(1/17)})),wN=sy((({depthTexture:t,shadowCoord:e,shadow:n})=>{const i=(e,n)=>RS(t,e).compare(n),r=yM("mapSize","vec2",n).setGroup(Ly),s=fy(1).div(r),a=s.x,o=s.y,l=e.xy,h=tb(l.mul(r).add(.5));return l.subAssign(h.mul(s)),gx(i(l,e.z),i(l.add(fy(a,0)),e.z),i(l.add(fy(0,o)),e.z),i(l.add(s),e.z),Ub(i(l.add(fy(a.negate(),0)),e.z),i(l.add(fy(a.mul(2),0)),e.z),h.x),Ub(i(l.add(fy(a.negate(),o)),e.z),i(l.add(fy(a.mul(2),o)),e.z),h.x),Ub(i(l.add(fy(0,o.negate())),e.z),i(l.add(fy(0,o.mul(2))),e.z),h.y),Ub(i(l.add(fy(a,o.negate())),e.z),i(l.add(fy(a,o.mul(2))),e.z),h.y),Ub(Ub(i(l.add(fy(a.negate(),o.negate())),e.z),i(l.add(fy(a.mul(2),o.negate())),e.z),h.x),Ub(i(l.add(fy(a.negate(),o.mul(2))),e.z),i(l.add(fy(a.mul(2),o.mul(2))),e.z),h.x),h.y)).mul(1/9)})),EN=sy((({depthTexture:t,shadowCoord:e})=>{const n=uy(1).toVar(),i=RS(t).uv(e.xy).rg,r=Mb(e.z,i.x);return ly(r.notEqual(uy(1)),(()=>{const t=e.z.sub(i.x),s=bb(0,i.y.mul(i.y));let a=s.div(s.add(t.mul(t)));a=Db(_x(a,.3).div(.95-.3)),n.assign(Db(bb(r,a)))})),n})),AN=sy((({samples:t,radius:e,size:n,shadowPass:i})=>{const r=uy(0).toVar(),s=uy(0).toVar(),a=t.lessThanEqual(uy(1)).select(uy(0),uy(2).div(t.sub(1))),o=t.lessThanEqual(uy(1)).select(uy(0),uy(-1));IT({start:cy(0),end:cy(t),type:"int",condition:"<"},(({i:t})=>{const l=o.add(uy(t).mul(a)),h=i.uv(gx($T.xy,fy(0,l).mul(e)).div(n)).x;r.addAssign(h),s.addAssign(h.mul(h))})),r.divAssign(t),s.divAssign(t);const l=Yx(s.sub(r.mul(r)));return fy(r,l)})),RN=sy((({samples:t,radius:e,size:n,shadowPass:i})=>{const r=uy(0).toVar(),s=uy(0).toVar(),a=t.lessThanEqual(uy(1)).select(uy(0),uy(2).div(t.sub(1))),o=t.lessThanEqual(uy(1)).select(uy(0),uy(-1));IT({start:cy(0),end:cy(t),type:"int",condition:"<"},(({i:t})=>{const l=o.add(uy(t).mul(a)),h=i.uv(gx($T.xy,fy(l,0).mul(e)).div(n));r.addAssign(h.x),s.addAssign(gx(h.y.mul(h.y),h.x.mul(h.x)))})),r.divAssign(t),s.divAssign(t);const l=Yx(s.sub(r.mul(r)));return fy(r,l)})),CN=[MN,TN,wN,EN];let NN=null;const PN=new yR;class IN extends mv{static get type(){return"ShadowNode"}constructor(t,e=null){super(),this.light=t,this.shadow=e||t.shadow,this.shadowMap=null,this.vsmShadowMapVertical=null,this.vsmShadowMapHorizontal=null,this.vsmMaterialVertical=null,this.vsmMaterialHorizontal=null,this.updateBeforeType=hv,this._node=null,this.isShadowNode=!0}setupShadow(t){const{object:e,renderer:n}=t;null===NN&&(NN=new pw,NN.fragmentNode=Sy(0,0,0,1),NN.isShadowNodeMaterial=!0,NN.name="ShadowMaterial");const i=this.shadow,r=n.shadowMap.type,s=new y_(i.mapSize.width,i.mapSize.height);s.compareFunction=513;const a=t.createRenderTarget(i.mapSize.width,i.mapSize.height);if(a.depthTexture=s,i.camera.updateProjectionMatrix(),3===r){s.compareFunction=null,this.vsmShadowMapVertical=t.createRenderTarget(i.mapSize.width,i.mapSize.height,{format:pp,type:sp}),this.vsmShadowMapHorizontal=t.createRenderTarget(i.mapSize.width,i.mapSize.height,{format:pp,type:sp});const e=RS(s),n=RS(this.vsmShadowMapVertical.texture),r=yM("blurSamples","float",i).setGroup(Ly),a=yM("radius","float",i).setGroup(Ly),o=yM("mapSize","vec2",i).setGroup(Ly);let l=this.vsmMaterialVertical||(this.vsmMaterialVertical=new pw);l.fragmentNode=AN({samples:r,radius:a,size:o,shadowPass:e}).context(t.getSharedContext()),l.name="VSMVertical",l=this.vsmMaterialHorizontal||(this.vsmMaterialHorizontal=new pw),l.fragmentNode=RN({samples:r,radius:a,size:o,shadowPass:n}).context(t.getSharedContext()),l.name="VSMHorizontal"}const o=yM("intensity","float",i).setGroup(Ly),l=yM("bias","float",i).setGroup(Ly),h=yM("normalBias","float",i).setGroup(Ly),u=e.material.shadowPositionNode||HS;let c,d=Oy(i.matrix).setGroup(Ly).mul(u.add(eM.mul(h)));if(i.camera.isOrthographicCamera||!0!==n.logarithmicDepthBuffer)d=d.xyz.div(d.w),c=d.z,n.coordinateSystem===tf&&(c=c.mul(2).sub(1));else{const t=d.w;d=d.xy.div(t);const e=Oy("float").onRenderUpdate((()=>i.camera.near)),n=Oy("float").onRenderUpdate((()=>i.camera.far));c=aw(t,e,n)}d=vy(d.x,d.y.oneMinus(),c.add(l));const p=d.x.greaterThanEqual(0).and(d.x.lessThanEqual(1)).and(d.y.greaterThanEqual(0)).and(d.y.lessThanEqual(1)).and(d.z.lessThanEqual(1)),f=i.filterNode||CN[n.shadowMap.type]||null;if(null===f)throw new Error("THREE.WebGPURenderer: Shadow map type not supported yet.");const m=RS(a.texture,d),g=p.select(f({depthTexture:3===r?this.vsmShadowMapHorizontal.texture:s,shadowCoord:d,shadow:i}),uy(1));return this.shadowMap=a,this.shadow.map=a,Ub(1,g.rgb.mix(m,1),o.mul(m.a))}setup(t){if(!1!==t.renderer.shadowMap.enabled)return null!==this._node?this._node:this._node=this.setupShadow(t)}updateShadow(t){const{shadowMap:e,light:n,shadow:i}=this,{renderer:r,scene:s,camera:a}=t,o=r.shadowMap.type,l=e.depthTexture.version;this._depthVersionCached=l;const h=s.overrideMaterial;s.overrideMaterial=NN,e.setSize(i.mapSize.width,i.mapSize.height),i.updateMatrices(n),i.camera.layers.mask=a.layers.mask;const u=r.getRenderTarget(),c=r.getRenderObjectFunction();r.setRenderObjectFunction(((t,...e)=>{(!0===t.castShadow||t.receiveShadow&&3===o)&&r.renderObject(t,...e)})),r.setRenderTarget(e),r.render(s,i.camera),r.setRenderObjectFunction(c),!0!==n.isPointLight&&3===o&&this.vsmPass(r),r.setRenderTarget(u),s.overrideMaterial=h}vsmPass(t){const{shadow:e}=this;this.vsmShadowMapVertical.setSize(e.mapSize.width,e.mapSize.height),this.vsmShadowMapHorizontal.setSize(e.mapSize.width,e.mapSize.height),t.setRenderTarget(this.vsmShadowMapVertical),PN.material=this.vsmMaterialVertical,PN.render(t),t.setRenderTarget(this.vsmShadowMapHorizontal),PN.material=this.vsmMaterialHorizontal,PN.render(t)}dispose(){this.shadowMap.dispose(),this.shadowMap=null,null!==this.vsmShadowMapVertical&&(this.vsmShadowMapVertical.dispose(),this.vsmShadowMapVertical=null,this.vsmMaterialVertical.dispose(),this.vsmMaterialVertical=null),null!==this.vsmShadowMapHorizontal&&(this.vsmShadowMapHorizontal.dispose(),this.vsmShadowMapHorizontal=null,this.vsmMaterialHorizontal.dispose(),this.vsmMaterialHorizontal=null),this.updateBeforeType=ov}updateBefore(t){const{shadow:e}=this;(e.needsUpdate||e.autoUpdate)&&(this.updateShadow(t),this.shadowMap.depthTexture.version===this._depthVersionCached&&(e.needsUpdate=!1))}}class LN extends BT{static get type(){return"AnalyticLightNode"}constructor(t=null){super(),this.updateType=lv,this.light=t,this.color=new og,this.colorNode=Oy(this.color).setGroup(Ly),this.baseColorNode=null,this.shadowNode=null,this.shadowColorNode=null,this.isAnalyticLightNode=!0}getCacheKey(){return ev(super.getCacheKey(),this.light.id,this.light.castShadow?1:0)}getHash(){return this.light.uuid}setupShadow(t){const{renderer:e}=t;if(!1===e.shadowMap.enabled)return;let n=this.shadowColorNode;if(null===n){const t=this.light.shadow.shadowNode;let e;e=void 0!==t?ty(t):((t,e)=>ty(new IN(t,e)))(this.light),this.shadowNode=e,this.shadowColorNode=n=this.colorNode.mul(e),this.baseColorNode=this.colorNode}this.colorNode=n}setup(t){this.colorNode=this.baseColorNode||this.colorNode,this.light.castShadow?t.object.receiveShadow&&this.setupShadow(t):null!==this.shadowNode&&this.shadowNode.dispose()}update(){const{light:t}=this;this.color.copy(t.color).multiplyScalar(t.intensity)}}const UN=sy((t=>{const{lightDistance:e,cutoffDistance:n,decayExponent:i}=t,r=e.pow(i).max(.01).reciprocal();return n.greaterThan(0).select(r.mul(e.div(n).pow4().oneMinus().clamp().pow2()),r)})),DN=sy((({color:t,lightViewPosition:e,cutoffDistance:n,decayExponent:i},r)=>{const s=r.context.lightingModel,a=e.sub(WS),o=a.normalize(),l=a.length(),h=UN({lightDistance:l,cutoffDistance:n,decayExponent:i}),u=t.mul(h),c=r.context.reflectedLight;s.direct({lightDirection:o,lightColor:u,reflectedLight:c},r.stack,r)}));class ON extends LN{static get type(){return"PointLightNode"}constructor(t=null){super(t),this.cutoffDistanceNode=Oy(0).setGroup(Ly),this.decayExponentNode=Oy(0).setGroup(Ly)}update(t){const{light:e}=this;super.update(t),this.cutoffDistanceNode.value=e.distance,this.decayExponentNode.value=e.decay}setup(){DN({color:this.colorNode,lightViewPosition:vN(this.light),cutoffDistance:this.cutoffDistanceNode,decayExponent:this.decayExponentNode}).append()}}const FN=sy((([t,e])=>{const n=t.x,i=t.y,r=t.z;let s=e.element(0).mul(.886227);return s=s.add(e.element(1).mul(1.023328).mul(i)),s=s.add(e.element(2).mul(1.023328).mul(r)),s=s.add(e.element(3).mul(1.023328).mul(n)),s=s.add(e.element(4).mul(.858086).mul(n).mul(i)),s=s.add(e.element(5).mul(.858086).mul(i).mul(r)),s=s.add(e.element(6).mul(r.mul(r).mul(.743125).sub(.247708))),s=s.add(e.element(7).mul(.858086).mul(n).mul(r)),s=s.add(e.element(8).mul(.429043).mul(vx(n,n).sub(vx(i,i)))),s})),BN=new cR;class zN extends OA{constructor(t,e){super(),this.renderer=t,this.nodes=e}update(t,e,n){const i=this.renderer,r=this.nodes.getBackgroundNode(t)||t.background;let s=!1;if(null===r)i._clearColor.getRGB(BN,zp),BN.a=i._clearColor.a;else if(!0===r.isColor)r.getRGB(BN,zp),BN.a=1,s=!0;else if(!0===r.isNode){const n=this.get(t),s=r;BN.copy(i._clearColor);let a=n.backgroundMesh;if(void 0===a){const t=Hb(Sy(s).mul(TR),{getUV:()=>wR.mul(JS),getTextureLevel:()=>MR});let e=xT();e=e.setZ(e.w);const i=new pw;i.name="Background.material",i.side=1,i.depthTest=!1,i.depthWrite=!1,i.fog=!1,i.lights=!1,i.vertexNode=e,i.colorNode=t,n.backgroundMeshNode=t,n.backgroundMesh=a=new Vg(new x_(1,32,32),i),a.frustumCulled=!1,a.name="Background.mesh",a.onBeforeRender=function(t,e,n){this.matrixWorld.copyPosition(n.matrixWorld)}}const o=s.getCacheKey();n.backgroundCacheKey!==o&&(n.backgroundMeshNode.node=Sy(s).mul(TR),n.backgroundMeshNode.needsUpdate=!0,a.material.needsUpdate=!0,n.backgroundCacheKey=o),e.unshift(a,a.geometry,a.material,0,0,null)}else console.error("THREE.Renderer: Unsupported background configuration.",r);if(!0===i.autoClear||!0===s){const t=n.clearColorValue;t.r=BN.r,t.g=BN.g,t.b=BN.b,t.a=BN.a,!0!==i.backend.isWebGLBackend&&!0!==i.alpha||(t.r*=t.a,t.g*=t.a,t.b*=t.a),n.depthClearValue=i._clearDepth,n.stencilClearValue=i._clearStencil,n.clearColor=!0===i.autoClearColor,n.clearDepth=!0===i.autoClearDepth,n.clearStencil=!0===i.autoClearStencil}else n.clearColor=!1,n.clearDepth=!1,n.clearStencil=!1}}let kN=0;class GN{constructor(t="",e=[],n=0,i=[]){this.name=t,this.bindings=e,this.index=n,this.bindingsReference=i,this.id=kN++}}class VN{constructor(t,e,n,i,r,s,a,o,l,h=[]){this.vertexShader=t,this.fragmentShader=e,this.computeShader=n,this.transforms=h,this.nodeAttributes=i,this.bindings=r,this.updateNodes=s,this.updateBeforeNodes=a,this.updateAfterNodes=o,this.monitor=l,this.usedTimes=0}createBindings(){const t=[];for(const e of this.bindings){if(!0!==e.bindings[0].groupNode.shared){const n=new GN(e.name,[],e.index,e);t.push(n);for(const t of e.bindings)n.bindings.push(t.clone())}else t.push(e)}return t}}class HN{constructor(t,e,n=null){this.isNodeAttribute=!0,this.name=t,this.type=e,this.node=n}}class jN{constructor(t,e,n){this.isNodeUniform=!0,this.name=t,this.type=e,this.node=n.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 WN{constructor(t,e){this.isNodeVar=!0,this.name=t,this.type=e}}class qN extends WN{constructor(t,e){super(t,e),this.needsInterpolation=!1,this.isNodeVarying=!0}}class XN{constructor(t,e,n=""){this.name=t,this.type=e,this.code=n,Object.defineProperty(this,"isNodeCode",{value:!0})}}let $N=0;class YN{constructor(t=null){this.id=$N++,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 KN{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 ZN extends KN{constructor(t,e=0){super(t,e),this.isNumberUniform=!0,this.boundary=4,this.itemSize=1}}class QN extends KN{constructor(t,e=new ff){super(t,e),this.isVector2Uniform=!0,this.boundary=8,this.itemSize=2}}class JN extends KN{constructor(t,e=new zf){super(t,e),this.isVector3Uniform=!0,this.boundary=16,this.itemSize=3}}class tP extends KN{constructor(t,e=new Uf){super(t,e),this.isVector4Uniform=!0,this.boundary=16,this.itemSize=4}}class eP extends KN{constructor(t,e=new og){super(t,e),this.isColorUniform=!0,this.boundary=16,this.itemSize=3}}class nP extends KN{constructor(t,e=new mf){super(t,e),this.isMatrix3Uniform=!0,this.boundary=48,this.itemSize=12}}class iP extends KN{constructor(t,e=new mm){super(t,e),this.isMatrix4Uniform=!0,this.boundary=64,this.itemSize=16}}class rP extends ZN{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class sP extends QN{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class aP extends JN{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class oP extends tP{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class lP extends eP{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class hP extends nP{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}class uP extends iP{constructor(t){super(t.name,t.value),this.nodeUniform=t}getValue(){return this.nodeUniform.value}}const cP=[.125,.215,.35,.446,.526,.582],dP=20,pP=new H_(-1,1,1,-1,0,1),fP=new Zg(90,1),mP=new og;let gP=null,_P=0,vP=0;const yP=(1+Math.sqrt(5))/2,xP=1/yP,bP=[new zf(-yP,xP,0),new zf(yP,xP,0),new zf(-xP,0,yP),new zf(xP,0,yP),new zf(0,yP,-xP),new zf(0,yP,xP),new zf(-1,1,-1),new zf(1,1,-1),new zf(-1,1,1),new zf(1,1,1)],SP=[3,1,5,0,4,2],MP=XE(SS(),bS("faceIndex")).normalize(),TP=vy(MP.x,MP.y.negate(),MP.z);class wP{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,n=.1,i=100){gP=this._renderer.getRenderTarget(),_P=this._renderer.getActiveCubeFace(),vP=this._renderer.getActiveMipmapLevel(),this._setSize(256);const r=this._allocateTargets();return r.depthBuffer=!0,this._sceneToCubeUV(t,n,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)}async compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=CP(),await this._compileMaterial(this._cubemapMaterial))}async compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=NP(),await 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(gP,_P,vP),t.scissorTest=!1,AP(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===zd||t.mapping===kd?this._setSize(0===t.image.length?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),gP=this._renderer.getRenderTarget(),_P=this._renderer.getActiveCubeFace(),vP=this._renderer.getActiveMipmapLevel();const n=e||this._allocateTargets();return this._textureToCubeUV(t,n),this._applyPMREM(n),this._cleanup(n),n}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,n={magFilter:Yd,minFilter:Yd,generateMipmaps:!1,type:sp,format:lp,colorSpace:zp},i=EP(t,e,n);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=EP(t,e,n);const{_lodMax:i}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas,lodMeshes:this._lodMeshes}=function(t){const e=[],n=[],i=[],r=[];let s=t;const a=t-4+1+cP.length;for(let o=0;o<a;o++){const a=Math.pow(2,s);n.push(a);let l=1/a;o>t-4?l=cP[o-t+4-1]:0===o&&(l=0),i.push(l);const h=1/(a-2),u=-h,c=1+h,d=[u,u,c,u,c,c,u,u,c,c,u,c],p=6,f=6,m=3,g=2,_=1,v=new Float32Array(m*f*p),y=new Float32Array(g*f*p),x=new Float32Array(_*f*p);for(let t=0;t<p;t++){const e=t%3*2/3-1,n=t>2?0:-1,i=[e,n,0,e+2/3,n,0,e+2/3,n+1,0,e,n,0,e+2/3,n+1,0,e,n+1,0],r=SP[t];v.set(i,m*f*r),y.set(d,g*f*r);const s=[r,r,r,r,r,r];x.set(s,_*f*r)}const b=new Ng;b.setAttribute("position",new vg(v,m)),b.setAttribute("uv",new vg(y,g)),b.setAttribute("faceIndex",new vg(x,_)),e.push(b),r.push(new Vg(b,null)),s>4&&s--}return{lodPlanes:e,sizeLods:n,sigmas:i,lodMeshes:r}}(i)),this._blurMaterial=function(t,e,n){const i=gM(new Array(dP).fill(0)),r=Oy(new zf(0,1,0)),s=Oy(0),a=uy(dP),o=Oy(0),l=Oy(1),h=RS(null),u=Oy(0),c=uy(1/e),d=uy(1/n),p=uy(t),f={n:a,latitudinal:o,weights:i,poleAxis:r,outputDirection:TP,dTheta:s,samples:l,envMap:h,mipInt:u,CUBEUV_TEXEL_WIDTH:c,CUBEUV_TEXEL_HEIGHT:d,CUBEUV_MAX_MIP:p},m=RP("blur");return m.uniforms=f,m.fragmentNode=ZE({...f,latitudinal:o.equal(1)}),m}(i,t,e)}return i}async _compileMaterial(t){const e=new Vg(this._lodPlanes[0],t);await this._renderer.compile(e,pP)}_sceneToCubeUV(t,e,n,i){const r=fP;r.near=e,r.far=n;const s=[-1,1,-1,-1,-1,-1],a=[1,1,1,-1,-1,-1],o=this._renderer,l=o.autoClear;o.getClearColor(mP),o.autoClear=!1;let h=this._backgroundBox;if(null===h){const t=new cg({name:"PMREM.Background",side:1,depthWrite:!1,depthTest:!1});h=new Vg(new jg,t)}let u=!1;const c=t.background;c?c.isColor&&(h.material.color.copy(c),t.background=null,u=!0):(h.material.color.copy(mP),u=!0),o.setRenderTarget(i),o.clear(),u&&o.render(h,r);for(let e=0;e<6;e++){const n=e%3;0===n?(r.up.set(0,s[e],0),r.lookAt(a[e],0,0)):1===n?(r.up.set(0,0,s[e]),r.lookAt(0,a[e],0)):(r.up.set(0,s[e],0),r.lookAt(0,0,a[e]));const l=this._cubeSize;AP(i,n*l,e>2?l:0,l,l),o.render(t,r)}o.autoClear=l,t.background=c}_textureToCubeUV(t,e){const n=this._renderer,i=t.mapping===zd||t.mapping===kd;i?null===this._cubemapMaterial&&(this._cubemapMaterial=CP(t)):null===this._equirectMaterial&&(this._equirectMaterial=NP(t));const r=i?this._cubemapMaterial:this._equirectMaterial;r.fragmentNode.value=t;const s=this._lodMeshes[0];s.material=r;const a=this._cubeSize;AP(e,0,0,3*a,2*a),n.setRenderTarget(e),n.render(s,pP)}_applyPMREM(t){const e=this._renderer,n=e.autoClear;e.autoClear=!1;const i=this._lodPlanes.length;for(let e=1;e<i;e++){const n=Math.sqrt(this._sigmas[e]*this._sigmas[e]-this._sigmas[e-1]*this._sigmas[e-1]),r=bP[(i-e-1)%bP.length];this._blur(t,e-1,e,n,r)}e.autoClear=n}_blur(t,e,n,i,r){const s=this._pingPongRenderTarget;this._halfBlur(t,s,e,n,i,"latitudinal",r),this._halfBlur(s,t,n,n,i,"longitudinal",r)}_halfBlur(t,e,n,i,r,s,a){const o=this._renderer,l=this._blurMaterial;"latitudinal"!==s&&"longitudinal"!==s&&console.error("blur direction must be either latitudinal or longitudinal!");const h=this._lodMeshes[i];h.material=l;const u=l.uniforms,c=this._sizeLods[n]-1,d=isFinite(r)?Math.PI/(2*c):2*Math.PI/39,p=r/d,f=isFinite(r)?1+Math.floor(3*p):dP;f>dP&&console.warn(`sigmaRadians, ${r}, is too large and will clip, as it requested ${f} samples when the maximum is set to 20`);const m=[];let g=0;for(let t=0;t<dP;++t){const e=t/p,n=Math.exp(-e*e/2);m.push(n),0===t?g+=n:t<f&&(g+=2*n)}for(let t=0;t<m.length;t++)m[t]=m[t]/g;t.texture.frame=(t.texture.frame||0)+1,u.envMap.value=t.texture,u.samples.value=f,u.weights.array=m,u.latitudinal.value="latitudinal"===s?1:0,a&&(u.poleAxis.value=a);const{_lodMax:_}=this;u.dTheta.value=d,u.mipInt.value=_-n;const v=this._sizeLods[i];AP(e,3*v*(i>_-4?i-_+4:0),4*(this._cubeSize-v),3*v,2*v),o.setRenderTarget(e),o.render(h,pP)}}function EP(t,e,n){const i=new Df(t,e,n);return i.texture.mapping=306,i.texture.name="PMREM.cubeUv",i.texture.isPMREMTexture=!0,i.scissorTest=!0,i}function AP(t,e,n,i,r){t.viewport.set(e,n,i,r),t.scissor.set(e,n,i,r)}function RP(t){const e=new pw;return e.depthTest=!1,e.depthWrite=!1,e.blending=0,e.name=`PMREM_${t}`,e}function CP(t){const e=RP("cubemap");return e.fragmentNode=cM(t,TP),e}function NP(t){const e=RP("equirect");return e.fragmentNode=RS(t,bw(TP),0),e}const PP=new WeakMap,IP=new Map([[2,"vec2"],[3,"vec3"],[4,"vec4"],[9,"mat3"],[16,"mat4"]]),LP=new Map([[Int8Array,"int"],[Int16Array,"int"],[Int32Array,"int"],[Uint8Array,"uint"],[Uint16Array,"uint"],[Uint32Array,"uint"],[Float32Array,"float"]]),UP=t=>/e/g.test(t)?String(t).replace(/\+/g,""):(t=Number(t))+(t%1?"":".0");class DP{constructor(t,e,n){this.object=t,this.material=t&&t.material||null,this.geometry=t&&t.geometry||null,this.renderer=e,this.parser=n,this.scene=null,this.camera=null,this.nodes=[],this.sequentialNodes=[],this.updateNodes=[],this.updateBeforeNodes=[],this.updateAfterNodes=[],this.hashNodes={},this.monitor=null,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=fR(),this.stacks=[],this.tab="\t",this.currentFunctionNode=null,this.context={material:this.material},this.cache=new YN,this.globalCache=this.cache,this.flowsData=new WeakMap,this.shaderStage=null,this.buildStage=null,this.useComparisonMethod=!1}getBindGroupsCache(){let t=PP.get(this.renderer);return void 0===t&&(t=new CA,PP.set(this.renderer,t)),t}createRenderTarget(t,e,n){return new Df(t,e,n)}createCubeRenderTarget(t,e){return new Sw(t,e)}createPMREMGenerator(){return new wP(this.renderer)}includes(t){return this.nodes.includes(t)}_getBindGroup(t,e){const n=this.getBindGroupsCache(),i=[];let r,s=!0;for(const t of e)i.push(t),s=s&&!0!==t.groupNode.shared;return s?(r=n.get(i),void 0===r&&(r=new GN(t,i,this.bindingsIndexes[t].group,i),n.set(i,r))):r=new GN(t,i,this.bindingsIndexes[t].group,i),r}getBindGroupArray(t,e){const n=this.bindings[e];let i=n[t];return void 0===i&&(void 0===this.bindingsIndexes[t]&&(this.bindingsIndexes[t]={binding:0,group:Object.keys(this.bindingsIndexes).length}),n[t]=i=[]),i}getBindings(){let t=this.bindGroups;if(null===t){const e={},n=this.bindings;for(const t of dv)for(const i in n[t]){const r=n[t][i];(e[i]||(e[i]=[])).push(...r)}t=[];for(const n in e){const i=e[n],r=this._getBindGroup(n,i);t.push(r)}this.bindGroups=t}return t}sortBindingGroups(){const t=this.getBindings();t.sort(((t,e)=>t.bindings[0].groupNode.order-e.bindings[0].groupNode.order));for(let e=0;e<t.length;e++){const n=t[e];this.bindingsIndexes[n.name].group=e,n.index=e}}setHashNode(t,e){this.hashNodes[e]=t}addNode(t){!1===this.nodes.includes(t)&&(this.nodes.push(t),this.setHashNode(t,t.getHash(this)))}addSequentialNode(t){!1===this.sequentialNodes.includes(t)&&this.sequentialNodes.push(t)}buildUpdateNodes(){for(const t of this.nodes){t.getUpdateType()!==ov&&this.updateNodes.push(t.getSelf())}for(const t of this.sequentialNodes){const e=t.getUpdateBeforeType(),n=t.getUpdateAfterType();e!==ov&&this.updateBeforeNodes.push(t.getSelf()),n!==ov&&this.updateAfterNodes.push(t.getSelf())}}get currentNode(){return this.chaining[this.chaining.length-1]}isFilteredTexture(t){return t.magFilter===Yd||t.magFilter===Kd||t.magFilter===$d||t.magFilter===Zd||t.minFilter===Yd||t.minFilter===Kd||t.minFilter===$d||t.minFilter===Zd}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 n=this.getDataFromNode(t);return void 0===n.cache&&(n.cache=new YN(e?this.getCache():null)),n.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}increaseUsage(t){const e=this.getDataFromNode(t);return e.usageCount=void 0===e.usageCount?1:e.usageCount+1,e.usageCount}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 og:"vec2"===t?e=new ff:"vec3"===t?e=new zf:"vec4"===t&&(e=new Uf)),"float"===t)return UP(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")}( ${UP(e.r)}, ${UP(e.g)}, ${UP(e.b)} )`;const n=this.getTypeLength(t),i=this.getComponentType(t),r=t=>this.generateConst(i,t);if(2===n)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)} )`;if(3===n)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)} )`;if(4===n)return`${this.getType(t)}( ${r(e.x)}, ${r(e.y)}, ${r(e.z)}, ${r(e.w)} )`;if(n>4&&e&&(e.isMatrix3||e.isMatrix4))return`${this.getType(t)}( ${e.elements.map(r).join(", ")} )`;if(n>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 n=this.attributes;for(const e of n)if(e.name===t)return e;const i=new HN(t,e);return n.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}needsToWorkingColorSpace(){return!1}getComponentTypeFromTexture(t){const e=t.type;if(t.isDataTexture){if(e===np)return"int";if(e===ip)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 n=IP.get(t);return("float"===e?"":e[0])+n}getTypeFromArray(t){return LP.get(t.constructor)}getTypeFromAttribute(t){let e=t;t.isInterleavedBufferAttribute&&(e=t.data);const n=e.array,i=t.itemSize,r=t.normalized;let s;return t instanceof bg||!0===r||(s=this.getTypeFromArray(n)),this.getTypeFromLength(i,s)}getTypeLength(t){const e=this.getVectorType(t),n=/vec([2-4])/.exec(e);return null!==n?Number(n[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=fR(this.stack),this.stacks.push(oy()||this.stack),ay(this.stack),this.stack}removeStack(){const t=this.stack;return this.stack=t.parent,ay(this.stacks.pop()),t}getDataFromNode(t,e=this.shaderStage,n=null){let i=(n=null===n?t.isGlobal(this)?this.globalCache:this.cache:n).getData(t);return void 0===i&&(i={},n.setData(t,i)),void 0===i[e]&&(i[e]={}),i[e]}getNodeProperties(t,e="any"){const n=this.getDataFromNode(t,e);return n.properties||(n.properties={outputNode:null})}getBufferAttributeFromNode(t,e){const n=this.getDataFromNode(t);let i=n.bufferAttribute;if(void 0===i){const r=this.uniforms.index++;i=new HN("nodeAttribute"+r,e,t),this.bufferAttributes.push(i),n.bufferAttribute=i}return i}getStructTypeFromNode(t,e=this.shaderStage){const n=this.getDataFromNode(t,e);if(void 0===n.structType){const i=this.structs.index++;t.name=`StructType${i}`,this.structs[e].push(t),n.structType=t}return t}getUniformFromNode(t,e,n=this.shaderStage,i=null){const r=this.getDataFromNode(t,n,this.globalCache);let s=r.uniform;if(void 0===s){const a=this.uniforms.index++;s=new jN(i||"nodeUniform"+a,e,t),this.uniforms[n].push(s),r.uniform=s}return s}getVarFromNode(t,e=null,n=t.getNodeType(this),i=this.shaderStage){const r=this.getDataFromNode(t,i);let s=r.variable;if(void 0===s){const t=this.vars[i]||(this.vars[i]=[]);null===e&&(e="nodeVar"+t.length),s=new WN(e,n),t.push(s),r.variable=s}return s}getVaryingFromNode(t,e=null,n=t.getNodeType(this)){const i=this.getDataFromNode(t,"any");let r=i.varying;if(void 0===r){const t=this.varyings,s=t.length;null===e&&(e="nodeVarying"+s),r=new qN(e,n),t.push(r),i.varying=r}return r}getCodeFromNode(t,e,n=this.shaderStage){const i=this.getDataFromNode(t);let r=i.code;if(void 0===r){const t=this.codes[n]||(this.codes[n]=[]),s=t.length;r=new XN("nodeCode"+s,e),t.push(r),i.code=r}return r}addFlowCodeHierarchy(t,e){const{flowCodes:n,flowCodeBlock:i}=this.getDataFromNode(t);let r=!0,s=e;for(;s;){if(!0===i.get(s)){r=!1;break}s=this.getDataFromNode(s).parentNodeBlock}if(r)for(const t of n)this.addLineFlowCode(t)}addLineFlowCodeBlock(t,e,n){const i=this.getDataFromNode(t),r=i.flowCodes||(i.flowCodes=[]),s=i.flowCodeBlock||(i.flowCodeBlock=new WeakMap);r.push(e),s.set(n,!0)}addLineFlowCode(t,e=null){return""===t||(null!==e&&this.context.nodeBlock&&this.addLineFlowCodeBlock(e,t,this.context.nodeBlock),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),n=this.flowChildNode(t,e);return this.flowsData.set(t,n),n}buildFunctionNode(t){const e=new lN,n=this.currentFunctionNode;return this.currentFunctionNode=e,e.code=this.buildFunctionCode(t),this.currentFunctionNode=n,e}flowShaderNode(t){const e=t.layout,n={[Symbol.iterator](){let t=0;const e=Object.values(this);return{next:()=>({value:e[t],done:t++>=e.length})}}};for(const t of e.inputs)n[t.name]=new dR(t.type,t.name);t.layout=null;const i=t.call(n),r=this.flowStagesNode(i,e.type);return t.layout=e,r}flowStagesNode(t,e=null){const n=this.flow,i=this.vars,r=this.cache,s=this.buildStage,a=this.stack,o={code:""};this.flow=o,this.vars={},this.cache=new YN,this.stack=fR();for(const n of cv)this.setBuildStage(n),o.result=t.build(this,e);return o.vars=this.getVars(this.shaderStage),this.flow=n,this.vars=i,this.cache=r,this.stack=a,this.setBuildStage(s),o}getFunctionOperator(){return null}flowChildNode(t,e=null){const n=this.flow,i={code:""};return this.flow=i,i.result=t.build(this,e),this.flow=n,i}flowNodeFromShaderStage(t,e,n=null,i=null){const r=this.shaderStage;this.setShaderStage(t);const s=this.flowChildNode(e,n);return null!==i&&(s.code+=`${this.tab+i} = ${s.result};\n`),this.flowCode[t]=this.flowCode[t]+s.code,this.setShaderStage(r),s}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 n=this.vars[t];if(void 0!==n)for(const t of n)e+=`${this.getVar(t.type,t.name)}; `;return e}getUniforms(){console.warn("Abstract function.")}getCodes(t){const e=this.codes[t];let n="";if(void 0!==e)for(const t of e)n+=t.code+"\n";return n}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,renderer:n}=this;if(null!==e){let t=n.library.fromMaterial(e);null===t&&(console.error(`NodeMaterial: Material "${e.type}" is not compatible.`),t=new pw),t.build(this)}else this.addFlow("compute",t);for(const t of cv){this.setBuildStage(t),this.context.vertex&&this.context.vertex.isNode&&this.flowNodeFromShaderStage("vertex",this.context.vertex);for(const e of dv){this.setShaderStage(e);const n=this.flowNodes[e];for(const e of n)"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 rP(t);if("vec2"===e||"ivec2"===e||"uvec2"===e)return new sP(t);if("vec3"===e||"ivec3"===e||"uvec3"===e)return new aP(t);if("vec4"===e||"ivec4"===e||"uvec4"===e)return new oP(t);if("color"===e)return new lP(t);if("mat3"===e)return new hP(t);if("mat4"===e)return new uP(t);throw new Error(`Uniform "${e}" not declared.`)}createNodeMaterial(t="NodeMaterial"){throw new Error(`THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${t}() instead.`)}format(t,e,n){if((e=this.getVectorType(e))===(n=this.getVectorType(n))||null===n||this.isReference(n))return t;const i=this.getTypeLength(e),r=this.getTypeLength(n);return 16===i&&9===r?`${this.getType(n)}(${t}[0].xyz, ${t}[1].xyz, ${t}[2].xyz)`:9===i&&4===r?`${this.getType(n)}(${t}[0].xy, ${t}[1].xy)`:i>4||r>4||0===r?t:i===r?`${this.getType(n)}( ${t} )`:i>r?this.format(`${t}.${"xyz".slice(0,r)}`,this.getTypeFromLength(r,this.getComponentType(e)),n):4===r&&i>1?`${this.getType(n)}( ${this.format(t,e,"vec3")}, 1.0 )`:2===i?`${this.getType(n)}( ${this.format(t,e,"vec2")}, 0.0 )`:(1===i&&r>1&&e!==this.getComponentType(n)&&(t=`${this.getType(this.getComponentType(n))}( ${t} )`),`${this.getType(n)}( ${t} )`)}getSignature(){return`// Three.js r${Td} - Node System\n`}}class OP{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 n=t.get(e);return void 0===n&&(n={renderMap:new WeakMap,frameMap:new WeakMap},t.set(e,n)),n}updateBeforeNode(t){const e=t.getUpdateBeforeType(),n=t.updateReference(this);if(e===lv){const{frameMap:e}=this._getMaps(this.updateBeforeMap,n);e.get(n)!==this.frameId&&!1!==t.updateBefore(this)&&e.set(n,this.frameId)}else if(e===hv){const{renderMap:e}=this._getMaps(this.updateBeforeMap,n);e.get(n)!==this.renderId&&!1!==t.updateBefore(this)&&e.set(n,this.renderId)}else e===uv&&t.updateBefore(this)}updateAfterNode(t){const e=t.getUpdateAfterType(),n=t.updateReference(this);if(e===lv){const{frameMap:e}=this._getMaps(this.updateAfterMap,n);e.get(n)!==this.frameId&&!1!==t.updateAfter(this)&&e.set(n,this.frameId)}else if(e===hv){const{renderMap:e}=this._getMaps(this.updateAfterMap,n);e.get(n)!==this.renderId&&!1!==t.updateAfter(this)&&e.set(n,this.renderId)}else e===uv&&t.updateAfter(this)}updateNode(t){const e=t.getUpdateType(),n=t.updateReference(this);if(e===lv){const{frameMap:e}=this._getMaps(this.updateMap,n);e.get(n)!==this.frameId&&!1!==t.update(this)&&e.set(n,this.frameId)}else if(e===hv){const{renderMap:e}=this._getMaps(this.updateMap,n);e.get(n)!==this.renderId&&!1!==t.update(this)&&e.set(n,this.renderId)}else e===uv&&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 FP{constructor(t,e,n=null,i="",r=!1){this.type=t,this.name=e,this.count=n,this.qualifier=i,this.isConst=r}}FP.isNodeFunctionInput=!0;class BP extends LN{static get type(){return"DirectionalLightNode"}constructor(t=null){super(t)}setup(t){super.setup(t);const e=t.context.lightingModel,n=this.colorNode,i=yN(this.light),r=t.context.reflectedLight;e.direct({lightDirection:i,lightColor:n,reflectedLight:r},t.stack,t)}}const zP=new mm,kP=new mm;let GP=null;class VP extends LN{static get type(){return"RectAreaLightNode"}constructor(t=null){super(t),this.halfHeight=Oy(new zf).setGroup(Ly),this.halfWidth=Oy(new zf).setGroup(Ly),this.updateType=hv}update(t){super.update(t);const{light:e}=this,n=t.camera.matrixWorldInverse;kP.identity(),zP.copy(e.matrixWorld),zP.premultiply(n),kP.extractRotation(zP),this.halfWidth.value.set(.5*e.width,0,0),this.halfHeight.value.set(0,.5*e.height,0),this.halfWidth.value.applyMatrix4(kP),this.halfHeight.value.applyMatrix4(kP)}setup(t){let e,n;super.setup(t),t.isAvailable("float32Filterable")?(e=RS(GP.LTC_FLOAT_1),n=RS(GP.LTC_FLOAT_2)):(e=RS(GP.LTC_HALF_1),n=RS(GP.LTC_HALF_2));const{colorNode:i,light:r}=this,s=t.context.lightingModel,a=vN(r),o=t.context.reflectedLight;s.directRectArea({lightColor:i,lightPosition:a,halfWidth:this.halfWidth,halfHeight:this.halfHeight,reflectedLight:o,ltc_1:e,ltc_2:n},t.stack,t)}static setLTC(t){GP=t}}class HP extends LN{static get type(){return"SpotLightNode"}constructor(t=null){super(t),this.coneCosNode=Oy(0).setGroup(Ly),this.penumbraCosNode=Oy(0).setGroup(Ly),this.cutoffDistanceNode=Oy(0).setGroup(Ly),this.decayExponentNode=Oy(0).setGroup(Ly)}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:n}=this;return Fb(e,n,t)}setup(t){super.setup(t);const e=t.context.lightingModel,{colorNode:n,cutoffDistanceNode:i,decayExponentNode:r,light:s}=this,a=vN(s).sub(WS),o=a.normalize(),l=o.dot(yN(s)),h=this.getSpotAttenuation(l),u=a.length(),c=UN({lightDistance:u,cutoffDistance:i,decayExponent:r}),d=n.mul(h).mul(c),p=t.context.reflectedLight;e.direct({lightDirection:o,lightColor:d,reflectedLight:p},t.stack,t)}}class jP extends HP{static get type(){return"IESSpotLightNode"}getSpotAttenuation(t){const e=this.light.iesMap;let n=null;if(e&&!0===e.isTexture){const i=t.acos().mul(1/Math.PI);n=RS(e,fy(i,0),0).r}else n=super.getSpotAttenuation(t);return n}}class WP extends LN{static get type(){return"AmbientLightNode"}constructor(t=null){super(t)}setup({context:t}){t.irradiance.addAssign(this.colorNode)}}class qP extends LN{static get type(){return"HemisphereLightNode"}constructor(t=null){super(t),this.lightPositionNode=_N(t),this.lightDirectionNode=this.lightPositionNode.normalize(),this.groundColorNode=Oy(new og).setGroup(Ly)}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:n,lightDirectionNode:i}=this,r=QS.dot(i).mul(.5).add(.5),s=Ub(n,e,r);t.context.irradiance.addAssign(s)}}class XP extends LN{static get type(){return"LightProbeNode"}constructor(t=null){super(t);const e=[];for(let t=0;t<9;t++)e.push(new zf);this.lightProbe=gM(e)}update(t){const{light:e}=this;super.update(t);for(let t=0;t<9;t++)this.lightProbe.array[t].copy(e.sh.coefficients[t]).multiplyScalar(e.intensity)}setup(t){const e=FN(JS,this.lightProbe);t.context.irradiance.addAssign(e)}}class $P{parseFunction(){console.warn("Abstract function.")}}class YP{constructor(t,e,n="",i=""){this.type=t,this.inputs=e,this.name=n,this.precision=i}getCode(){console.warn("Abstract function.")}}YP.isNodeFunction=!0;const KP=/^\s*(highp|mediump|lowp)?\s*([a-z_0-9]+)\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)/i,ZP=/[a-z_0-9]+/gi,QP="#pragma main";class JP extends YP{constructor(t){const{type:e,inputs:n,name:i,precision:r,inputsCode:s,blockCode:a,headerCode:o}=(t=>{const e=(t=t.trim()).indexOf(QP),n=-1!==e?t.slice(e+12):t,i=n.match(KP);if(null!==i&&5===i.length){const r=i[4],s=[];let a=null;for(;null!==(a=ZP.exec(r));)s.push(a);const o=[];let l=0;for(;l<s.length;){const t="const"===s[l][0];!0===t&&l++;let e=s[l][0];"in"===e||"out"===e||"inout"===e?l++:e="";const n=s[l++][0];let i=Number.parseInt(s[l][0]);!1===Number.isNaN(i)?l++:i=null;const r=s[l++][0];o.push(new FP(n,r,i,e,t))}const h=n.substring(i[0].length),u=void 0!==i[3]?i[3]:"";return{type:i[2],inputs:o,name:u,precision:void 0!==i[1]?i[1]:"",inputsCode:r,blockCode:h,headerCode:-1!==e?t.slice(0,e):""}}throw new Error("FunctionNode: Function is not a GLSL code.")})(t);super(e,n,i,r),this.inputsCode=s,this.blockCode=a,this.headerCode=o}getCode(t=this.name){let e;const n=this.blockCode;if(""!==n){const{type:i,inputsCode:r,headerCode:s,precision:a}=this;let o=`${i} ${t} ( ${r.trim()} )`;""!==a&&(o=`${a} ${o}`),e=s+o+n}else e="";return e}}class tI extends $P{parseFunction(t){return new JP(t)}}const eI=new WeakMap;class nI extends OA{constructor(t,e){super(),this.renderer=t,this.backend=e,this.nodeFrame=new OP,this.nodeBuilderCache=new Map,this.callHashCache=new CA,this.groupsData=new CA}updateGroup(t){const e=t.groupNode,n=e.name;if(n===Uy.name)return!0;if(n===Ly.name){const e=this.get(t),n=this.nodeFrame.renderId;return e.renderId!==n&&(e.renderId=n,!0)}if(n===Iy.name){const e=this.get(t),n=this.nodeFrame.frameId;return e.frameId!==n&&(e.frameId=n,!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 n=e.nodeBuilderState;if(void 0===n){const{nodeBuilderCache:i}=this,r=this.getForRenderCacheKey(t);if(n=i.get(r),void 0===n){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(),n=this._createNodeBuilderState(e),i.set(r,n)}n.usedTimes++,e.nodeBuilderState=n}return n}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 n=e.nodeBuilderState;if(void 0===n){const i=this.backend.createNodeBuilder(t,this.renderer);i.build(),n=this._createNodeBuilderState(i),e.nodeBuilderState=n}return n}_createNodeBuilderState(t){return new VN(t.vertexShader,t.fragmentShader,t.computeShader,t.getAttributesArray(),t.getBindings(),t.updateNodes,t.updateBeforeNodes,t.updateAfterNodes,t.monitor,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 n=[t,e],i=this.renderer.info.calls;let r=this.callHashCache.get(n);if(void 0===r||r.callId!==i){const s=this.getEnvironmentNode(t),a=this.getFogNode(t),o=[];e&&o.push(e.getCacheKey(!0)),s&&o.push(s.getCacheKey()),a&&o.push(a.getCacheKey()),o.push(this.renderer.shadowMap.enabled?1:0),r={callId:i,cacheKey:tv(o)},this.callHashCache.set(n,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),n=t.background;if(n){const i=0===t.backgroundBlurriness&&e.backgroundBlurriness>0||t.backgroundBlurriness>0&&0===e.backgroundBlurriness;if(e.background!==n||i){let i=null;if(!0===n.isCubeTexture||n.mapping===Gd||n.mapping===Vd||306===n.mapping)if(t.backgroundBlurriness>0||306===n.mapping)i=nA(n);else{let t;t=!0===n.isCubeTexture?cM(n):RS(n),i=Aw(t)}else!0===n.isTexture?i=RS(n,qT.flipY()).setUpdateMatrix(!0):!0!==n.isColor&&console.error("WebGPUNodes: Unsupported background configuration.",n);e.backgroundNode=i,e.background=n,e.backgroundBlurriness=t.backgroundBlurriness}}else e.backgroundNode&&(delete e.backgroundNode,delete e.background)}updateFog(t){const e=this.get(t),n=t.fog;if(n){if(e.fog!==n){let t=null;if(n.isFogExp2){const e=yM("color","color",n).setGroup(Ly),i=yM("density","float",n).setGroup(Ly);t=pN(e,i)}else if(n.isFog){const e=yM("color","color",n).setGroup(Ly),i=yM("near","float",n).setGroup(Ly),r=yM("far","float",n).setGroup(Ly);t=cN(e,i,r)}else console.error("WebGPUNodes: Unsupported fog configuration.",n);e.fogNode=t,e.fog=n}}else delete e.fogNode,delete e.fog}updateEnvironment(t){const e=this.get(t),n=t.environment;if(n){if(e.environment!==n){let t=null;!0===n.isCubeTexture?t=cM(n):!0===n.isTexture?t=RS(n):console.error("Nodes: Unsupported environment configuration.",n),e.environmentNode=t,e.environment=n}}else e.environmentNode&&(delete e.environmentNode,delete e.environment)}getNodeFrame(t=this.renderer,e=null,n=null,i=null,r=null){const s=this.nodeFrame;return s.renderer=t,s.scene=e,s.object=n,s.camera=i,s.material=r,s}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,n=this.getOutputCacheKey(),i=RS(t,qT).renderOutput(e.toneMapping,e.currentColorSpace);return eI.set(t,n),i}updateBefore(t){const e=t.getNodeBuilderState();for(const n of e.updateBeforeNodes)this.getNodeFrameForRender(t).updateBeforeNode(n)}updateAfter(t){const e=t.getNodeBuilderState();for(const n of e.updateAfterNodes)this.getNodeFrameForRender(t).updateAfterNode(n)}updateForCompute(t){const e=this.getNodeFrame(),n=this.getForCompute(t);for(const t of n.updateNodes)e.updateNode(t)}updateForRender(t){const e=this.getNodeFrameForRender(t),n=t.getNodeBuilderState();for(const t of n.updateNodes)e.updateNode(t)}needsRefresh(t){const e=this.getNodeFrameForRender(t);return t.getMonitor().needsRefresh(t,e)}dispose(){super.dispose(),this.nodeFrame=new OP,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 CA}get(t,e){const n=this.lists,i=[t,e];let r=n.get(i);return void 0===r&&(r=new iI(t,e),n.set(i,r)),r}dispose(){this.lists=new CA}}class sI{constructor(){this.lightNodes=new WeakMap,this.materialNodes=new Map,this.toneMappingNodes=new Map}fromMaterial(t){if(t.isNodeMaterial)return t;let e=null;const n=this.getMaterialNodeClass(t.type);if(null!==n){e=new n;for(const n in t)e[n]=t[n]}return e}addToneMapping(t,e){this.addType(t,e,this.toneMappingNodes)}getToneMappingFunction(t){return this.toneMappingNodes.get(t)||null}getMaterialNodeClass(t){return this.materialNodes.get(t)||null}addMaterial(t,e){this.addType(t,e.type,this.materialNodes)}getLightNodeClass(t){return this.lightNodes.get(t)||null}addLight(t,e){this.addClass(t,e,this.lightNodes)}addType(t,e,n){if(n.has(e))console.warn(`Redefinition of node ${e}`);else{if("function"!=typeof t)throw new Error(`Node class ${t.name} is not a class.`);if("function"==typeof e||"object"==typeof e)throw new Error(`Base class ${e} is not a class.`);n.set(e,t)}}addClass(t,e,n){if(n.has(e))console.warn(`Redefinition of node ${e.name}`);else{if("function"!=typeof t)throw new Error(`Node class ${t.name} is not a class.`);if("function"!=typeof e)throw new Error(`Base class ${e.name} is not a class.`);n.set(e,t)}}}const aI=new SN;class oI extends CA{constructor(){super()}createNode(t=[]){return(new SN).setLights(t)}getNode(t,e){if(t.isQuadMesh)return aI;const n=[t,e];let i=this.get(n);return void 0===i&&(i=this.createNode(),this.set(n,i)),i}}const lI=new n_,hI=new ff,uI=new Uf,cI=new m_,dI=new mm,pI=new Uf;class fI{constructor(t,e={}){this.isRenderer=!0;const{logarithmicDepthBuffer:n=!1,alpha:i=!0,depth:r=!0,stencil:s=!1,antialias:a=!1,samples:o=0,getFallback:l=null}=e;this.domElement=t.getDomElement(),this.backend=t,this.samples=o||!0===a?4:0,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.alpha=i,this.logarithmicDepthBuffer=n,this.outputColorSpace=Bp,this.toneMapping=0,this.toneMappingExposure=1,this.sortObjects=!0,this.depth=r,this.stencil=s,this.clippingPlanes=[],this.info=new qA,this.nodes={modelViewMatrix:null,modelNormalViewMatrix:null},this.library=new sI,this.lighting=new oI,this._getFallback=l,this._pixelRatio=1,this._width=this.domElement.width,this._height=this.domElement.height,this._viewport=new Uf(0,0,this._width,this._height),this._scissor=new Uf(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 yR(new pw),this._quad.material.type="Renderer_output",this._currentRenderContext=null,this._opaqueSort=null,this._transparentSort=null,this._frameBufferTarget=null;const h=!0===this.alpha?0:1;this._clearColor=new cR(0,0,0,h),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._isDeviceLost=!1,this.onDeviceLost=this._onDeviceLost,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,getShaderAsync:async(t,e,n)=>{await this.compileAsync(t,e);const i=this._renderLists.get(t,e),r=this._renderContexts.get(t,e,this._renderTarget),s=t.overrideMaterial||n.material,a=this._objects.get(n,s,t,e,i.lightsNode,r),{fragmentShader:o,vertexShader:l}=a.getNodeBuilderState();return{fragmentShader:o,vertexShader:l}}}}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)=>{let n=this.backend;try{await n.init(this)}catch(t){if(null===this._getFallback)return void e(t);try{this.backend=n=this._getFallback(t),await n.init(this)}catch(t){return void e(t)}}this._nodes=new nI(this,n),this._animation=new RA(this._nodes,this.info),this._attributes=new VA(n),this._background=new zN(this,this._nodes),this._geometries=new WA(this._attributes,this.info),this._textures=new uR(this,n,this.info),this._pipelines=new QA(n,this._nodes),this._bindings=new JA(n,this._nodes,this._textures,this._attributes,this._pipelines,this.info),this._objects=new DA(this,this._nodes,this._geometries,this._pipelines,this._bindings,this.info),this._renderLists=new rR(this.lighting),this._bundles=new rI,this._renderContexts=new lR,this._initialized=!0,t()}))),this._initPromise}get coordinateSystem(){return this.backend.coordinateSystem}async compileAsync(t,e,n=null){if(!0===this._isDeviceLost)return;!1===this._initialized&&await this.init();const i=this._nodes.nodeFrame,r=i.renderId,s=this._currentRenderContext,a=this._currentRenderObjectFunction,o=this._compilationPromises,l=!0===t.isScene?t:lI;null===n&&(n=t);const h=this._renderTarget,u=this._renderContexts.get(n,e,h),c=this._activeMipmapLevel,d=[];this._currentRenderContext=u,this._currentRenderObjectFunction=this.renderObject,this._handleObjectFunction=this._createObjectPipeline,this._compilationPromises=d,i.renderId++,i.update(),u.depth=this.depth,u.stencil=this.stencil,u.clippingContext||(u.clippingContext=new PA),u.clippingContext.updateGlobal(this,e),l.onBeforeRender(this,t,e,h);const p=this._renderLists.get(t,e);if(p.begin(),this._projectObject(t,e,0,p),n!==t&&n.traverseVisible((function(t){t.isLight&&t.layers.test(e.layers)&&p.pushLight(t)})),p.finish(),null!==h){this._textures.updateRenderTarget(h,c);const t=this._textures.get(h);u.textures=t.textures,u.depthTexture=t.depthTexture}else u.textures=null,u.depthTexture=null;this._nodes.updateScene(l),this._background.update(l,p,u);const f=p.opaque,m=p.transparent,g=p.lightsNode;!0===this.opaque&&f.length>0&&this._renderObjects(f,e,l,g),!0===this.transparent&&m.length>0&&this._renderTransparents(m,e,l,g),i.renderId=r,this._currentRenderContext=s,this._currentRenderObjectFunction=a,this._compilationPromises=o,this._handleObjectFunction=this._renderObjectDirect,await Promise.all(d)}async renderAsync(t,e){!1===this._initialized&&await this.init();const n=this._renderScene(t,e);await this.backend.resolveTimestampAsync(n,"render")}async waitForGPU(){await this.backend.waitForGPU()}setMRT(t){return this._mrt=t,this}getMRT(){return this._mrt}_onDeviceLost(t){let e=`THREE.WebGPURenderer: ${t.api} Device Lost:\n\nMessage: ${t.message}`;t.reason&&(e+=`\nReason: ${t.reason}`),console.error(e),this._isDeviceLost=!0}_renderBundle(t,e,n){const{bundleGroup:i,camera:r,renderList:s}=t,a=this._currentRenderContext,o=this._bundles.get(i,r),l=this.backend.get(o);void 0===l.renderContexts&&(l.renderContexts=new Set);const h=i.version!==l.version,u=!1===l.renderContexts.has(a)||h;if(l.renderContexts.add(a),u){this.backend.beginBundle(a),(void 0===l.renderObjects||h)&&(l.renderObjects=[]),this._currentRenderBundle=o;const t=s.opaque;!0===this.opaque&&t.length>0&&this._renderObjects(t,r,e,n),this._currentRenderBundle=null,this.backend.finishBundle(a,o),l.version=i.version}else{const{renderObjects:t}=l;for(let e=0,n=t.length;e<n;e++){const n=t[e];this._nodes.needsRefresh(n)&&(this._nodes.updateBefore(n),this._nodes.updateForRender(n),this._bindings.updateForRender(n),this._nodes.updateAfter(n))}}this.backend.addBundle(a,o)}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{currentToneMapping:t,currentColorSpace:e}=this;if(!1===(0!==t)&&!1===(e!==zp))return null;const{width:n,height:i}=this.getDrawingBufferSize(hI),{depth:r,stencil:s}=this;let a=this._frameBufferTarget;return null===a&&(a=new Df(n,i,{depthBuffer:r,stencilBuffer:s,type:sp,format:lp,colorSpace:zp,generateMipmaps:!1,minFilter:Yd,magFilter:Yd,samples:this.samples}),a.isPostProcessingRenderTarget=!0,this._frameBufferTarget=a),a.depthBuffer=r,a.stencilBuffer=s,a.setSize(n,i),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,n=!0){if(!0===this._isDeviceLost)return;const i=n?this._getFrameBufferTarget():null,r=this._nodes.nodeFrame,s=r.renderId,a=this._currentRenderContext,o=this._currentRenderObjectFunction,l=!0===t.isScene?t:lI,h=this._renderTarget,u=this._activeCubeFace,c=this._activeMipmapLevel;let d;null!==i?(d=i,this.setRenderTarget(d)):d=h;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 f=this.coordinateSystem;e.coordinateSystem!==f&&(e.coordinateSystem=f,e.updateProjectionMatrix()),!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld(),null===e.parent&&!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld();let m=this._viewport,g=this._scissor,_=this._pixelRatio;null!==d&&(m=d.viewport,g=d.scissor,_=1),this.getDrawingBufferSize(hI),uI.set(0,0,hI.width,hI.height);const v=void 0===m.minDepth?0:m.minDepth,y=void 0===m.maxDepth?1:m.maxDepth;p.viewportValue.copy(m).multiplyScalar(_).floor(),p.viewportValue.width>>=c,p.viewportValue.height>>=c,p.viewportValue.minDepth=v,p.viewportValue.maxDepth=y,p.viewport=!1===p.viewportValue.equals(uI),p.scissorValue.copy(g).multiplyScalar(_).floor(),p.scissor=this._scissorTest&&!1===p.scissorValue.equals(uI),p.scissorValue.width>>=c,p.scissorValue.height>>=c,p.clippingContext||(p.clippingContext=new PA),p.clippingContext.updateGlobal(this,e),l.onBeforeRender(this,t,e,d),dI.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),cI.setFromProjectionMatrix(dI,f);const x=this._renderLists.get(t,e);if(x.begin(),this._projectObject(t,e,0,x),x.finish(),!0===this.sortObjects&&x.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=u,p.activeMipmapLevel=c,p.occlusionQueryCount=x.occlusionQueryCount,this._nodes.updateScene(l),this._background.update(l,x,p),this.backend.beginRender(p);const{bundles:b,lightsNode:S,transparentDoublePass:M,transparent:T,opaque:w}=x;if(b.length>0&&this._renderBundles(b,l,S),!0===this.opaque&&w.length>0&&this._renderObjects(w,e,l,S),!0===this.transparent&&T.length>0&&this._renderTransparents(T,M,e,l,S),this.backend.finishRender(p),r.renderId=s,this._currentRenderContext=a,this._currentRenderObjectFunction=o,null!==i){this.setRenderTarget(h,u,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 l.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._pixelRatio=t,this.setSize(this._width,this._height,!1))}setDrawingBufferSize(t,e,n){this._width=t,this._height=e,this._pixelRatio=n,this.domElement.width=Math.floor(t*n),this.domElement.height=Math.floor(e*n),this.setViewport(0,0,t,e),this._initialized&&this.backend.updateSize()}setSize(t,e,n=!0){this._width=t,this._height=e,this.domElement.width=Math.floor(t*this._pixelRatio),this.domElement.height=Math.floor(e*this._pixelRatio),!0===n&&(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,n,i){const r=this._scissor;t.isVector4?r.copy(t):r.set(t,e,n,i)}getScissorTest(){return this._scissorTest}setScissorTest(t){this._scissorTest=t,this.backend.setScissorTest(t)}getViewport(t){return t.copy(this._viewport)}setViewport(t,e,n,i,r=0,s=1){const a=this._viewport;t.isVector4?a.copy(t):a.set(t,e,n,i),a.minDepth=r,a.maxDepth=s}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,n=!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,n);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,n,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,n=!0){!1===this._initialized&&await this.init(),this.clear(t,e,n)}clearColorAsync(){return this.clearAsync(!0,!1,!1)}clearDepthAsync(){return this.clearAsync(!1,!0,!1)}clearStencilAsync(){return this.clearAsync(!1,!1,!0)}get currentToneMapping(){return null!==this._renderTarget?0:this.toneMapping}get currentColorSpace(){return null!==this._renderTarget?zp:this.outputColorSpace}dispose(){this.info.dispose(),this.backend.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,n=0){this._renderTarget=t,this._activeCubeFace=e,this._activeMipmapLevel=n}getRenderTarget(){return this._renderTarget}setRenderObjectFunction(t){this._renderObjectFunction=t}getRenderObjectFunction(){return this._renderObjectFunction}compute(t){if(!0===this.isDeviceLost)return;if(!1===this._initialized)return console.warn("THREE.Renderer: .compute() called before the backend is initialized. Try using .computeAsync() instead."),this.computeAsync(t);const e=this._nodes.nodeFrame,n=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,s=this._bindings,a=this._nodes,o=Array.isArray(t)?t:[t];if(void 0===o[0]||!0!==o[0].isComputeNode)throw new Error("THREE.Renderer: .compute() expects a ComputeNode.");i.beginCompute(t);for(const e of o){if(!1===r.has(e)){const t=()=>{e.removeEventListener("dispose",t),r.delete(e),s.delete(e),a.delete(e)};e.addEventListener("dispose",t);const n=e.onInitFunction;null!==n&&n.call(e,{renderer:this})}a.updateForCompute(e),s.updateForCompute(e);const n=s.getForCompute(e),o=r.getForCompute(e,n);i.compute(t,e,n,o)}i.finishCompute(t),e.renderId=n}async computeAsync(t){!1===this._initialized&&await this.init(),this.compute(t),await this.backend.resolveTimestampAsync(t,"compute")}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,e=null){if(null!==e)if(e.isVector2)e=pI.set(e.x,e.y,t.image.width,t.image.height).floor();else{if(!e.isVector4)return void console.error("THREE.Renderer.copyFramebufferToTexture: Invalid rectangle.");e=pI.copy(e).floor()}else e=pI.set(0,0,t.image.width,t.image.height);let n,i=this._currentRenderContext;null!==i?n=i.renderTarget:(n=this._renderTarget||this._getFrameBufferTarget(),null!==n&&(this._textures.updateRenderTarget(n),i=this._textures.get(n))),this._textures.updateTexture(t,{renderTarget:n}),this.backend.copyFramebufferToTexture(t,i,e)}copyTextureToTexture(t,e,n=null,i=null,r=0){this._textures.updateTexture(t),this._textures.updateTexture(e),this.backend.copyTextureToTexture(t,e,n,i,r)}readRenderTargetPixelsAsync(t,e,n,i,r,s=0,a=0){return this.backend.copyTextureToBuffer(t.textures[s],e,n,i,r,a)}_projectObject(t,e,n,i){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)n=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||cI.intersectsSprite(t)){!0===this.sortObjects&&pI.setFromMatrixPosition(t.matrixWorld).applyMatrix4(dI);const{geometry:e,material:r}=t;r.visible&&i.push(t,e,r,n,pI.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||cI.intersectsObject(t))){const{geometry:e,material:r}=t;if(!0===this.sortObjects&&(null===e.boundingSphere&&e.computeBoundingSphere(),pI.copy(e.boundingSphere.center).applyMatrix4(t.matrixWorld).applyMatrix4(dI)),Array.isArray(r)){const s=e.groups;for(let a=0,o=s.length;a<o;a++){const o=s[a],l=r[o.materialIndex];l&&l.visible&&i.push(t,e,l,n,pI.z,o)}}else r.visible&&i.push(t,e,r,n,pI.z,null)}if(!0===t.isBundleGroup&&void 0!==this.backend.beginBundle){const n=i;(i=this._renderLists.get(t,e)).begin(),n.pushBundle({bundleGroup:t,camera:e,renderList:i}),i.finish()}const r=t.children;for(let t=0,s=r.length;t<s;t++)this._projectObject(r[t],e,n,i)}_renderBundles(t,e,n){for(const i of t)this._renderBundle(i,e,n)}_renderTransparents(t,e,n,i,r){if(e.length>0){for(const{material:t}of e)t.side=1;this._renderObjects(e,n,i,r,"backSide");for(const{material:t}of e)t.side=0;this._renderObjects(t,n,i,r);for(const{material:t}of e)t.side=2}else this._renderObjects(t,n,i,r)}_renderObjects(t,e,n,i,r=null){for(let s=0,a=t.length;s<a;s++){const a=t[s],{object:o,geometry:l,material:h,group:u}=a;if(e.isArrayCamera){const t=e.cameras;for(let e=0,s=t.length;e<s;e++){const s=t[e];if(o.layers.test(s.layers)){const t=s.viewport,e=void 0===t.minDepth?0:t.minDepth,a=void 0===t.maxDepth?1:t.maxDepth,c=this._currentRenderContext.viewportValue;c.copy(t).multiplyScalar(this._pixelRatio).floor(),c.minDepth=e,c.maxDepth=a,this.backend.updateViewport(this._currentRenderContext),this._currentRenderObjectFunction(o,n,s,l,h,u,i,r)}}}else this._currentRenderObjectFunction(o,n,e,l,h,u,i,r)}}renderObject(t,e,n,i,r,s,a,o=null){let l,h,u;if(t.onBeforeRender(this,e,n,i,r,s),null!==e.overrideMaterial){const t=e.overrideMaterial;r.positionNode&&r.positionNode.isNode&&(l=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=1,this._handleObjectFunction(t,r,e,n,a,s,"backSide"),r.side=0,this._handleObjectFunction(t,r,e,n,a,s,o),r.side=2):this._handleObjectFunction(t,r,e,n,a,s,o),void 0!==l&&(e.overrideMaterial.positionNode=l),void 0!==u&&(e.overrideMaterial.depthNode=u),void 0!==h&&(e.overrideMaterial.fragmentNode=h),t.onAfterRender(this,e,n,i,r,s)}_renderObjectDirect(t,e,n,i,r,s,a){const o=this._objects.get(t,e,n,i,r,this._currentRenderContext,a);o.drawRange=t.geometry.drawRange,o.group=s;const l=this._nodes.needsRefresh(o);if(l&&(this._nodes.updateBefore(o),this._geometries.updateForRender(o),this._nodes.updateForRender(o),this._bindings.updateForRender(o)),this._pipelines.updateForRender(o),null!==this._currentRenderBundle){this.backend.get(this._currentRenderBundle).renderObjects.push(o),o.bundle=this._currentRenderBundle.scene}this.backend.draw(o,this.info),l&&this._nodes.updateAfter(o)}_createObjectPipeline(t,e,n,i,r,s){const a=this._objects.get(t,e,n,i,r,this._currentRenderContext,s);this._nodes.updateBefore(a),this._geometries.updateForRender(a),this._nodes.updateForRender(a),this._bindings.updateForRender(a),this._pipelines.getForRender(a,this._compilationPromises),this._nodes.updateAfter(a)}get compile(){return this.compileAsync}}class mI{constructor(t=""){this.name=t,this.visibility=0}setVisibility(t){this.visibility|=t}clone(){return Object.assign(new this.constructor,this)}}class gI extends mI{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)+(GA-t%GA)%GA;var t}get buffer(){return this._buffer}update(){return!0}}class _I extends gI{constructor(t,e=null){super(t,e),this.isUniformBuffer=!0}}let vI=0;class yI extends _I{constructor(t,e){super("UniformBuffer_"+vI++,t?t.value:null),this.nodeUniform=t,this.groupNode=e}get buffer(){return this.nodeUniform.value}}class xI extends _I{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,n=this.uniforms.length;e<n;e++){const n=this.uniforms[e],{boundary:i,itemSize:r}=n,s=t%GA;0!==s&&GA-s-i<0?t+=GA-s:s%i!=0&&(t+=s%i),n.offset=t/this.bytesPerElement,t+=r*this.bytesPerElement}return Math.ceil(t/GA)*GA}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 n=this.values,i=t.getValue(),r=t.offset;if(n[r]!==i){this.buffer[r]=n[r]=i,e=!0}return e}updateVector2(t){let e=!1;const n=this.values,i=t.getValue(),r=t.offset;if(n[r+0]!==i.x||n[r+1]!==i.y){const t=this.buffer;t[r+0]=n[r+0]=i.x,t[r+1]=n[r+1]=i.y,e=!0}return e}updateVector3(t){let e=!1;const n=this.values,i=t.getValue(),r=t.offset;if(n[r+0]!==i.x||n[r+1]!==i.y||n[r+2]!==i.z){const t=this.buffer;t[r+0]=n[r+0]=i.x,t[r+1]=n[r+1]=i.y,t[r+2]=n[r+2]=i.z,e=!0}return e}updateVector4(t){let e=!1;const n=this.values,i=t.getValue(),r=t.offset;if(n[r+0]!==i.x||n[r+1]!==i.y||n[r+2]!==i.z||n[r+4]!==i.w){const t=this.buffer;t[r+0]=n[r+0]=i.x,t[r+1]=n[r+1]=i.y,t[r+2]=n[r+2]=i.z,t[r+3]=n[r+3]=i.w,e=!0}return e}updateColor(t){let e=!1;const n=this.values,i=t.getValue(),r=t.offset;if(n[r+0]!==i.r||n[r+1]!==i.g||n[r+2]!==i.b){const t=this.buffer;t[r+0]=n[r+0]=i.r,t[r+1]=n[r+1]=i.g,t[r+2]=n[r+2]=i.b,e=!0}return e}updateMatrix3(t){let e=!1;const n=this.values,i=t.getValue().elements,r=t.offset;if(n[r+0]!==i[0]||n[r+1]!==i[1]||n[r+2]!==i[2]||n[r+4]!==i[3]||n[r+5]!==i[4]||n[r+6]!==i[5]||n[r+8]!==i[6]||n[r+9]!==i[7]||n[r+10]!==i[8]){const t=this.buffer;t[r+0]=n[r+0]=i[0],t[r+1]=n[r+1]=i[1],t[r+2]=n[r+2]=i[2],t[r+4]=n[r+4]=i[3],t[r+5]=n[r+5]=i[4],t[r+6]=n[r+6]=i[5],t[r+8]=n[r+8]=i[6],t[r+9]=n[r+9]=i[7],t[r+10]=n[r+10]=i[8],e=!0}return e}updateMatrix4(t){let e=!1;const n=this.values,i=t.getValue().elements,r=t.offset;if(!1===function(t,e,n){for(let i=0,r=e.length;i<r;i++)if(t[n+i]!==e[i])return!1;return!0}(n,i,r)){this.buffer.set(i,r),function(t,e,n){for(let i=0,r=e.length;i<r;i++)t[n+i]=e[i]}(n,i,r),e=!0}return e}}let bI=0;class SI extends xI{constructor(t,e){super(t),this.id=bI++,this.groupNode=e,this.isNodeUniformsGroup=!0}getNodes(){const t=[];for(const e of this.uniforms){const n=e.nodeUniform.node;if(!n)throw new Error("NodeUniformsGroup: Uniform has no node.");t.push(n)}return t}}let MI=0;class TI extends mI{constructor(t,e){super(t),this.id=MI++,this.texture=e,this.version=e?e.version:0,this.store=!1,this.generation=null,this.isSampledTexture=!0}needsBindingsUpdate(t){const{texture:e}=this;return t!==this.generation?(this.generation=t,!0):e.isVideoTexture}update(){const{texture:t,version:e}=this;return e!==t.version&&(this.version=t.version,!0)}}class wI extends TI{constructor(t,e,n,i=null){super(t,e?e.value:null),this.textureNode=e,this.groupNode=n,this.access=i}needsBindingsUpdate(t){return this.textureNode.value!==this.texture||super.needsBindingsUpdate(t)}update(){const{textureNode:t}=this;return this.texture!==t.value?(this.texture=t.value,!0):super.update()}}class EI extends wI{constructor(t,e,n,i){super(t,e,n,i),this.isSampledCubeTexture=!0}}class AI extends wI{constructor(t,e,n,i){super(t,e,n,i),this.isSampledTexture3D=!0}}const RI={atan2:"atan",textureDimensions:"textureSize",equals:"equal"},CI={low:"lowp",medium:"mediump",high:"highp"},NI={swizzleAssign:!0,storageBuffer:!1},PI="\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 II extends DP{constructor(t,e){super(t,e,new tI),this.uniformGroups={},this.transforms=[],this.extensions={},this.useComparisonMethod=!0}needsColorSpaceToLinearSRGB(t){return!0===t.isVideoTexture&&t.colorSpace!==Fp}getMethod(t){return RI[t]||t}getOutputStructName(){return""}buildFunctionCode(t){const e=t.layout,n=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${n.vars}\n\n${n.code}\n\treturn ${n.result};\n\n}`}setupPBO(t){const e=t.value;if(void 0===e.pbo){const t=e.array,n=e.count*e.itemSize,{itemSize:i}=e,r=e.array.constructor.name.toLowerCase().includes("int");let s=r?dp:cp;2===i?s=r?fp:pp:3===i?s=r?1032:op:4===i&&(s=r?mp:lp);const a={Float32Array:rp,Uint8Array:Qd,Uint16Array:ep,Uint32Array:ip,Int8Array:Jd,Int16Array:tp,Int32Array:np,Uint8ClampedArray:Qd},o=Math.pow(2,Math.ceil(Math.log2(Math.sqrt(n/i))));let l=Math.ceil(n/i/o);o*l*i<n&&l++;const h=o*l*i,u=new t.constructor(h);u.set(t,0),e.array=u;const c=new o_(e.array,o,l,s,a[e.array.constructor.name]||rp);c.needsUpdate=!0,c.isPBOTexture=!0;const d=new AS(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:n}=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),s=this.getPropertyName(r);this.increaseUsage(n);const a=n.build(this,"uint"),o=this.getDataFromNode(t);let l=o.propertyName;if(void 0===l){const n=this.getVarFromNode(t);l=this.getPropertyName(n);const r=this.getDataFromNode(e);let h=r.propertySizeName;void 0===h&&(h=l+"Size",this.getVarFromNode(e,h,"uint"),this.addLineFlowCode(`${h} = uint( textureSize( ${s}, 0 ).x )`,t),r.propertySizeName=h);const{itemSize:u}=i,c="."+pv.join("").slice(0,u),d=`ivec2(${a} % ${h}, ${a} / ${h})`,p=this.generateTextureLoad(null,s,d,null,"0");let f="vec4";i.pbo.type===ip?f="uvec4":i.pbo.type===np&&(f="ivec4"),this.addLineFlowCode(`${l} = ${f}(${p})${c}`,t),o.propertyName=l}return l}generateTextureLoad(t,e,n,i,r="0"){return i?`texelFetch( ${e}, ivec3( ${n}, ${i} ), ${r} )`:`texelFetch( ${e}, ${n}, ${r} )`}generateTexture(t,e,n,i){return t.isDepthTexture?`texture( ${e}, ${n} ).x`:(i&&(n=`vec3( ${n}, ${i} )`),`texture( ${e}, ${n} )`)}generateTextureLevel(t,e,n,i){return`textureLod( ${e}, ${n}, ${i} )`}generateTextureBias(t,e,n,i){return`texture( ${e}, ${n}, ${i} )`}generateTextureGrad(t,e,n,i){return`textureGrad( ${e}, ${n}, ${i[0]}, ${i[1]} )`}generateTextureCompare(t,e,n,i,r,s=this.shaderStage){if("fragment"===s)return`texture( ${e}, vec3( ${n}, ${i} ) )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${s} shader.`)}getVars(t){const e=[],n=this.vars[t];if(void 0!==n)for(const t of n)e.push(`${this.getVar(t.type,t.name)};`);return e.join("\n\t")}getUniforms(t){const e=this.uniforms[t],n=[],i={};for(const r of e){let e=null,s=!1;if("texture"===r.type){const t=r.node.value;let n="";!0===t.isDataTexture&&(t.type===ip?n="u":t.type===np&&(n="i")),e=t.compareFunction?`sampler2DShadow ${r.name};`:!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture?`${n}sampler2DArray ${r.name};`:`${n}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,n=this.getType(t.bufferType),i=t.bufferCount,s=i>0?i:"";e=`${t.name} {\n\t${n} ${r.name}[${s}];\n};\n`}else{e=`${this.getVectorType(r.type)} ${this.getPropertyName(r,t)};`,s=!0}const a=r.node.precision;if(null!==a&&(e=CI[a]+" "+e),s){e="\t"+e;const t=r.groupNode.name;(i[t]||(i[t]=[])).push(e)}else e="uniform "+e,n.push(e)}let r="";for(const e in i){const n=i[e];r+=this._getGLSLUniformStruct(t+"_"+e,n.join("\n"))+"\n"}return r+=n.join("\n"),r}getTypeFromAttribute(t){let e=super.getTypeFromAttribute(t);if(/^[iu]/.test(e)&&t.gpuType!==np){let n=t;t.isInterleavedBufferAttribute&&(n=t.data);const i=n.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 n=0;for(const i of t)e+=`layout( location = ${n++} ) in ${i.type} ${i.name};\n`}return e}getStructMembers(t){const e=[],n=t.getMemberTypes();for(let t=0;t<n.length;t++){const i=n[t];e.push(`layout( location = ${t} ) out ${i} m${t};`)}return e.join("\n")}getStructs(t){const e=[],n=this.structs[t];if(0===n.length)return"layout( location = 0 ) out vec4 fragColor;\n";for(let t=0,i=n.length;t<i;t++){const i=n[t];let r="\n";r+=this.getStructMembers(i),r+="\n",e.push(r)}return e.join("\n\n")}getVaryings(t){let e="";const n=this.varyings;if("vertex"===t||"compute"===t)for(const i of n){"compute"===t&&(i.needsInterpolation=!0);const n=i.type;e+=`${n.includes("int")||n.includes("uv")||n.includes("iv")?"flat ":""}${i.needsInterpolation?"out":"/*out*/"} ${n} ${i.name};\n`}else if("fragment"===t)for(const t of n)if(t.needsInterpolation){const n=t.type;e+=`${n.includes("int")||n.includes("uv")||n.includes("iv")?"flat ":""}in ${n} ${t.name};\n`}return e}getVertexIndex(){return"uint( gl_VertexID )"}getInstanceIndex(){return"uint( gl_InstanceID )"}getInvocationLocalIndex(){return`uint( gl_InstanceID ) % ${this.object.workgroupSize.reduce(((t,e)=>t*e),1)}u`}getDrawIndex(){return this.renderer.backend.extensions.has("WEBGL_multi_draw")?"uint( gl_DrawID )":null}getFrontFacing(){return"gl_FrontFacing"}getFragCoord(){return"gl_FragCoord.xy"}getFragDepth(){return"gl_FragDepth"}enableExtension(t,e,n=this.shaderStage){const i=this.extensions[n]||(this.extensions[n]=new Map);!1===i.has(t)&&i.set(t,{name:t,behavior:e})}getExtensions(t){const e=[];if("vertex"===t){const e=this.renderer.backend.extensions;this.object.isBatchedMesh&&e.has("WEBGL_multi_draw")&&this.enableExtension("GL_ANGLE_multi_draw","require",t)}const n=this.extensions[t];if(void 0!==n)for(const{name:t,behavior:i}of n.values())e.push(`#extension ${t} : ${i}`);return e.join("\n")}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 n=0;n<t.length;n++){const i=t[n],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${this.getSignature()}\n\n// extensions \n${t.extensions}\n\n// precision\n${PI}\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${PI}\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:{}};this.sortBindingGroups();for(const e in t){let n="// code\n\n";n+=this.flowCode[e];const i=this.flowNodes[e],r=i[i.length-1];for(const t of i){const i=this.getFlowData(t),s=t.name;s&&(n.length>0&&(n+="\n"),n+=`\t// flow -> ${s}\n\t`),n+=`${i.code}\n\t`,t===r&&"compute"!==e&&(n+="// result\n\t","vertex"===e?(n+="gl_Position = ",n+=`${i.result};`):"fragment"===e&&(t.outputNode.isOutputStructNode||(n+="fragColor = ",n+=`${i.result};`)))}const s=t[e];s.extensions=this.getExtensions(e),s.uniforms=this.getUniforms(e),s.attributes=this.getAttributes(e),s.varyings=this.getVaryings(e),s.vars=this.getVars(e),s.structs=this.getStructs(e),s.codes=this.getCodes(e),s.transforms=this.getTransforms(e),s.flow=n}null!==this.material?(this.vertexShader=this._getGLSLVertexCode(t.vertex),this.fragmentShader=this._getGLSLFragmentCode(t.fragment)):this.computeShader=this._getGLSLVertexCode(t.compute)}getUniformFromNode(t,e,n,i=null){const r=super.getUniformFromNode(t,e,n,i),s=this.getDataFromNode(t,n,this.globalCache);let a=s.uniformGPU;if(void 0===a){const i=t.groupNode,o=i.name,l=this.getBindGroupArray(o,n);if("texture"===e)a=new wI(r.name,r.node,i),l.push(a);else if("cubeTexture"===e)a=new EI(r.name,r.node,i),l.push(a);else if("texture3D"===e)a=new AI(r.name,r.node,i),l.push(a);else if("buffer"===e){t.name=`NodeBuffer_${t.id}`,r.name=`buffer${t.id}`;const e=new yI(t,i);e.name=t.name,l.push(e),a=e}else{const t=this.uniformGroups[n]||(this.uniformGroups[n]={});let s=t[o];void 0===s&&(s=new SI(n+"_"+o,i),t[o]=s,l.push(s)),a=this.getNodeUniform(r,e),s.addUniform(a)}s.uniformGPU=a}return r}}let LI=null,UI=null,DI=null;class OI{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:n}=t;return n.isInstancedBufferGeometry?n.instanceCount:e.count>1?e.count:1}getDrawingBufferSize(){return LI=LI||new ff,this.renderer.getDrawingBufferSize(LI)}getScissor(){return UI=UI||new Uf,this.renderer.getScissor(UI)}setScissorTest(){}getClearColor(){const t=this.renderer;return DI=DI||new cR,t.getClearColor(DI),DI.getRGB(DI,this.renderer.currentColorSpace),DI}getDomElement(){let t=this.domElement;return null===t&&(t=void 0!==this.parameters.canvas?this.parameters.canvas:function(){const t=_f("canvas");return t.style.display="block",t}(),"setAttribute"in t&&t.setAttribute("data-engine",`three.js r${Td} webgpu`),this.domElement=t),t}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)}dispose(){}}let FI=0;class BI{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 n=this.backend,{gl:i}=n,r=t.array,s=t.usage||i.STATIC_DRAW,a=t.isInterleavedBufferAttribute?t.data:t,o=n.get(a);let l,h=o.bufferGPU;if(void 0===h&&(h=this._createBuffer(i,e,r,s),o.bufferGPU=h,o.bufferType=e,o.version=a.version),r instanceof Float32Array)l=i.FLOAT;else if(r instanceof Uint16Array)l=t.isFloat16BufferAttribute?i.HALF_FLOAT:i.UNSIGNED_SHORT;else if(r instanceof Int16Array)l=i.SHORT;else if(r instanceof Uint32Array)l=i.UNSIGNED_INT;else if(r instanceof Int32Array)l=i.INT;else if(r instanceof Int8Array)l=i.BYTE;else if(r instanceof Uint8Array)l=i.UNSIGNED_BYTE;else{if(!(r instanceof Uint8ClampedArray))throw new Error("THREE.WebGLBackend: Unsupported buffer data format: "+r);l=i.UNSIGNED_BYTE}let u={bufferGPU:h,bufferType:e,type:l,byteLength:r.byteLength,bytesPerElement:r.BYTES_PER_ELEMENT,version:t.version,pbo:t.pbo,isInteger:l===i.INT||l===i.UNSIGNED_INT||t.gpuType===np,id:FI++};if(t.isStorageBufferAttribute||t.isStorageInstancedBufferAttribute){const t=this._createBuffer(i,e,r,s);u=new BI(u,t)}n.set(t,u)}updateAttribute(t){const e=this.backend,{gl:n}=e,i=t.array,r=t.isInterleavedBufferAttribute?t.data:t,s=e.get(r),a=s.bufferType,o=t.isInterleavedBufferAttribute?t.data.updateRanges:t.updateRanges;if(n.bindBuffer(a,s.bufferGPU),0===o.length)n.bufferSubData(a,0,i);else{for(let t=0,e=o.length;t<e;t++){const e=o[t];n.bufferSubData(a,e.start*i.BYTES_PER_ELEMENT,i,e.start,e.count)}r.clearUpdateRanges()}n.bindBuffer(a,null),s.version=r.version}destroyAttribute(t){const e=this.backend,{gl:n}=e;t.isInterleavedBufferAttribute&&e.delete(t.data);const i=e.get(t);n.deleteBuffer(i.bufferGPU),e.delete(t)}async getArrayBufferAsync(t){const e=this.backend,{gl:n}=e,i=t.isInterleavedBufferAttribute?t.data:t,{bufferGPU:r}=e.get(i),s=t.array,a=s.byteLength;n.bindBuffer(n.COPY_READ_BUFFER,r);const o=n.createBuffer();n.bindBuffer(n.COPY_WRITE_BUFFER,o),n.bufferData(n.COPY_WRITE_BUFFER,a,n.STREAM_READ),n.copyBufferSubData(n.COPY_READ_BUFFER,n.COPY_WRITE_BUFFER,0,0,a),await e.utils._clientWaitAsync();const l=new t.array.constructor(s.length);return n.bindBuffer(n.COPY_WRITE_BUFFER,o),n.getBufferSubData(n.COPY_WRITE_BUFFER,0,l),n.deleteBuffer(o),n.bindBuffer(n.COPY_READ_BUFFER,null),n.bindBuffer(n.COPY_WRITE_BUFFER,null),l.buffer}_createBuffer(t,e,n,i){const r=t.createBuffer();return t.bindBuffer(e,r),t.bufferData(e,n,i),t.bindBuffer(e,null),r}}let kI,GI,VI=!1;class HI{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={},this.currentBoundBufferBases={},!1===VI&&(this._init(this.gl),VI=!0)}_init(t){kI={[wd]:t.FUNC_ADD,[Ed]:t.FUNC_SUBTRACT,[Ad]:t.FUNC_REVERSE_SUBTRACT},GI={[Rd]:t.ZERO,[Cd]:t.ONE,[Nd]:t.SRC_COLOR,[Id]:t.SRC_ALPHA,[Bd]:t.SRC_ALPHA_SATURATE,[Od]:t.DST_COLOR,[Ud]:t.DST_ALPHA,[Pd]:t.ONE_MINUS_SRC_COLOR,[Ld]:t.ONE_MINUS_SRC_ALPHA,[Fd]:t.ONE_MINUS_DST_COLOR,[Dd]: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:n}=this;t!==e&&(n.lineWidth(t),this.currentLineWidth=t)}setBlending(t,e,n,i,r,s,a,o){const{gl:l}=this;if(0!==t){if(!1===this.currentBlendingEnabled&&(this.enable(l.BLEND),this.currentBlendingEnabled=!0),5===t)r=r||e,s=s||n,a=a||i,e===this.currentBlendEquation&&r===this.currentBlendEquationAlpha||(l.blendEquationSeparate(kI[e],kI[r]),this.currentBlendEquation=e,this.currentBlendEquationAlpha=r),n===this.currentBlendSrc&&i===this.currentBlendDst&&s===this.currentBlendSrcAlpha&&a===this.currentBlendDstAlpha||(l.blendFuncSeparate(GI[n],GI[i],GI[s],GI[a]),this.currentBlendSrc=n,this.currentBlendDst=i,this.currentBlendSrcAlpha=s,this.currentBlendDstAlpha=a),this.currentBlending=t,this.currentPremultipledAlpha=!1;else if(t!==this.currentBlending||o!==this.currentPremultipledAlpha){if(this.currentBlendEquation===wd&&this.currentBlendEquationAlpha===wd||(l.blendEquation(l.FUNC_ADD),this.currentBlendEquation=wd,this.currentBlendEquationAlpha=wd),o)switch(t){case 1:l.blendFuncSeparate(l.ONE,l.ONE_MINUS_SRC_ALPHA,l.ONE,l.ONE_MINUS_SRC_ALPHA);break;case 2:l.blendFunc(l.ONE,l.ONE);break;case 3:l.blendFuncSeparate(l.ZERO,l.ONE_MINUS_SRC_COLOR,l.ZERO,l.ONE);break;case 4:l.blendFuncSeparate(l.ZERO,l.SRC_COLOR,l.ZERO,l.SRC_ALPHA);break;default:console.error("THREE.WebGLState: Invalid blending: ",t)}else switch(t){case 1:l.blendFuncSeparate(l.SRC_ALPHA,l.ONE_MINUS_SRC_ALPHA,l.ONE,l.ONE_MINUS_SRC_ALPHA);break;case 2:l.blendFunc(l.SRC_ALPHA,l.ONE);break;case 3:l.blendFuncSeparate(l.ZERO,l.ONE_MINUS_SRC_COLOR,l.ZERO,l.ONE);break;case 4:l.blendFunc(l.ZERO,l.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=o}}else!0===this.currentBlendingEnabled&&(this.disable(l.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,n){this.currentStencilFunc===t&&this.currentStencilRef===e&&this.currentStencilFuncMask===n||(this.gl.stencilFunc(t,e,n),this.currentStencilFunc=t,this.currentStencilRef=e,this.currentStencilFuncMask=n)}setStencilOp(t,e,n){this.currentStencilFail===t&&this.currentStencilZFail===e&&this.currentStencilZPass===n||(this.gl.stencilOp(t,e,n),this.currentStencilFail=t,this.currentStencilZFail=e,this.currentStencilZPass=n)}setMaterial(t,e){const{gl:n}=this;2===t.side?this.disable(n.CULL_FACE):this.enable(n.CULL_FACE);let i=1===t.side;e&&(i=!i),this.setFlipSided(i),1===t.blending&&!1===t.transparent?this.setBlending(0):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.backend.renderer.samples>1?this.enable(n.SAMPLE_ALPHA_TO_COVERAGE):this.disable(n.SAMPLE_ALPHA_TO_COVERAGE)}setPolygonOffset(t,e,n){const{gl:i}=this;t?(this.enable(i.POLYGON_OFFSET_FILL),this.currentPolygonOffsetFactor===e&&this.currentPolygonOffsetUnits===n||(i.polygonOffset(e,n),this.currentPolygonOffsetFactor=e,this.currentPolygonOffsetUnits=n)):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:n,currentBoundFramebuffers:i}=this;return i[t]!==e&&(n.bindFramebuffer(t,e),i[t]=e,t===n.DRAW_FRAMEBUFFER&&(i[n.FRAMEBUFFER]=e),t===n.FRAMEBUFFER&&(i[n.DRAW_FRAMEBUFFER]=e),!0)}drawBuffers(t,e){const{gl:n}=this;let i=[],r=!1;if(null!==t.textures){i=this.currentDrawbuffers.get(e),void 0===i&&(i=[],this.currentDrawbuffers.set(e,i));const s=t.textures;if(i.length!==s.length||i[0]!==n.COLOR_ATTACHMENT0){for(let t=0,e=s.length;t<e;t++)i[t]=n.COLOR_ATTACHMENT0+t;i.length=s.length,r=!0}}else i[0]!==n.BACK&&(i[0]=n.BACK,r=!0);r&&n.drawBuffers(i)}activeTexture(t){const{gl:e,currentTextureSlot:n,maxTextures:i}=this;void 0===t&&(t=e.TEXTURE0+i-1),n!==t&&(e.activeTexture(t),this.currentTextureSlot=t)}bindTexture(t,e,n){const{gl:i,currentTextureSlot:r,currentBoundTextures:s,maxTextures:a}=this;void 0===n&&(n=null===r?i.TEXTURE0+a-1:r);let o=s[n];void 0===o&&(o={type:void 0,texture:void 0},s[n]=o),o.type===t&&o.texture===e||(r!==n&&(i.activeTexture(n),this.currentTextureSlot=n),i.bindTexture(t,e),o.type=t,o.texture=e)}bindBufferBase(t,e,n){const{gl:i}=this,r=`${t}-${e}`;return this.currentBoundBufferBases[r]!==n&&(i.bindBufferBase(t,e,n),this.currentBoundBufferBases[r]=n,!0)}unbindTexture(){const{gl:t,currentTextureSlot:e,currentBoundTextures:n}=this,i=n[e];void 0!==i&&void 0!==i.type&&(t.bindTexture(i.type,null),i.type=void 0,i.texture=void 0)}}class jI{constructor(t){this.backend=t,this.gl=this.backend.gl,this.extensions=t.extensions}convert(t,e=""){const{gl:n,extensions:i}=this;let r;if(t===Qd)return n.UNSIGNED_BYTE;if(1017===t)return n.UNSIGNED_SHORT_4_4_4_4;if(1018===t)return n.UNSIGNED_SHORT_5_5_5_1;if(35902===t)return n.UNSIGNED_INT_5_9_9_9_REV;if(t===Jd)return n.BYTE;if(t===tp)return n.SHORT;if(t===ep)return n.UNSIGNED_SHORT;if(t===np)return n.INT;if(t===ip)return n.UNSIGNED_INT;if(t===rp)return n.FLOAT;if(t===sp)return n.HALF_FLOAT;if(1021===t)return n.ALPHA;if(t===op)return n.RGB;if(t===lp)return n.RGBA;if(1024===t)return n.LUMINANCE;if(1025===t)return n.LUMINANCE_ALPHA;if(t===hp)return n.DEPTH_COMPONENT;if(t===up)return n.DEPTH_STENCIL;if(t===cp)return n.RED;if(t===dp)return n.RED_INTEGER;if(t===pp)return n.RG;if(t===fp)return n.RG_INTEGER;if(t===mp)return n.RGBA_INTEGER;if(t===gp||t===_p||t===vp||t===yp)if(e===Bp){if(r=i.get("WEBGL_compressed_texture_s3tc_srgb"),null===r)return null;if(t===gp)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(t===_p)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(t===vp)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(t===yp)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(r=i.get("WEBGL_compressed_texture_s3tc"),null===r)return null;if(t===gp)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(t===_p)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(t===vp)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(t===yp)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===t||35841===t||35842===t||35843===t){if(r=i.get("WEBGL_compressed_texture_pvrtc"),null===r)return null;if(35840===t)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===t)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===t)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===t)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===t||t===xp||t===bp){if(r=i.get("WEBGL_compressed_texture_etc"),null===r)return null;if(36196===t||t===xp)return e===Bp?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(t===bp)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}if(t===Sp||t===Mp||t===Tp||t===wp||t===Ep||t===Ap||t===Rp||t===Cp||t===Np||t===Pp||t===Ip||t===Lp||t===Up||t===Dp){if(r=i.get("WEBGL_compressed_texture_astc"),null===r)return null;if(t===Sp)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(t===Mp)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(t===Tp)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(t===wp)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(t===Ep)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(t===Ap)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(t===Rp)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(t===Cp)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(t===Np)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(t===Pp)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(t===Ip)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(t===Lp)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(t===Up)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(t===Dp)return e===Bp?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}if(t===Op){if(r=i.get("EXT_texture_compression_bptc"),null===r)return null;if(t===Op)return e===Bp?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT}if(36283===t||36284===t||36285===t||36286===t){if(r=i.get("EXT_texture_compression_rgtc"),null===r)return null;if(t===Op)return r.COMPRESSED_RED_RGTC1_EXT;if(36284===t)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(36285===t)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(36286===t)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return t===ap?n.UNSIGNED_INT_24_8:void 0!==n[t]?n[t]:null}_clientWaitAsync(){const{gl:t}=this,e=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0);return t.flush(),new Promise(((n,i)=>{!function r(){const s=t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0);if(s===t.WAIT_FAILED)return t.deleteSync(e),void i();s!==t.TIMEOUT_EXPIRED?(t.deleteSync(e),n()):requestAnimationFrame(r)}()}))}}let WI,qI,XI,$I=!1;class YI{constructor(t){this.backend=t,this.gl=t.gl,this.extensions=t.extensions,this.defaultTextures={},!1===$I&&(this._init(this.gl),$I=!0)}_init(t){WI={[Hd]:t.REPEAT,[jd]:t.CLAMP_TO_EDGE,[Wd]:t.MIRRORED_REPEAT},qI={[qd]:t.NEAREST,[Xd]:t.NEAREST_MIPMAP_NEAREST,[$d]:t.NEAREST_MIPMAP_LINEAR,[Yd]:t.LINEAR,[Kd]:t.LINEAR_MIPMAP_NEAREST,[Zd]:t.LINEAR_MIPMAP_LINEAR},XI={[Hp]:t.NEVER,[Kp]:t.ALWAYS,[jp]:t.LESS,[qp]:t.LEQUAL,[Wp]:t.EQUAL,[Yp]:t.GEQUAL,[Xp]:t.GREATER,[$p]:t.NOTEQUAL}}filterFallback(t){const{gl:e}=this;return t===qd||t===Xd||t===$d?e.NEAREST:e.LINEAR}getGLTextureType(t){const{gl:e}=this;let n;return n=!0===t.isCubeTexture?e.TEXTURE_CUBE_MAP:!0===t.isDataArrayTexture||!0===t.isCompressedArrayTexture?e.TEXTURE_2D_ARRAY:!0===t.isData3DTexture?e.TEXTURE_3D:e.TEXTURE_2D,n}getInternalFormat(t,e,n,i,r=!1){const{gl:s,extensions:a}=this;if(null!==t){if(void 0!==s[t])return s[t];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+t+"'")}let o=e;return e===s.RED&&(n===s.FLOAT&&(o=s.R32F),n===s.HALF_FLOAT&&(o=s.R16F),n===s.UNSIGNED_BYTE&&(o=s.R8),n===s.UNSIGNED_SHORT&&(o=s.R16),n===s.UNSIGNED_INT&&(o=s.R32UI),n===s.BYTE&&(o=s.R8I),n===s.SHORT&&(o=s.R16I),n===s.INT&&(o=s.R32I)),e===s.RED_INTEGER&&(n===s.UNSIGNED_BYTE&&(o=s.R8UI),n===s.UNSIGNED_SHORT&&(o=s.R16UI),n===s.UNSIGNED_INT&&(o=s.R32UI),n===s.BYTE&&(o=s.R8I),n===s.SHORT&&(o=s.R16I),n===s.INT&&(o=s.R32I)),e===s.RG&&(n===s.FLOAT&&(o=s.RG32F),n===s.HALF_FLOAT&&(o=s.RG16F),n===s.UNSIGNED_BYTE&&(o=s.RG8),n===s.UNSIGNED_SHORT&&(o=s.RG16),n===s.UNSIGNED_INT&&(o=s.RG32UI),n===s.BYTE&&(o=s.RG8I),n===s.SHORT&&(o=s.RG16I),n===s.INT&&(o=s.RG32I)),e===s.RG_INTEGER&&(n===s.UNSIGNED_BYTE&&(o=s.RG8UI),n===s.UNSIGNED_SHORT&&(o=s.RG16UI),n===s.UNSIGNED_INT&&(o=s.RG32UI),n===s.BYTE&&(o=s.RG8I),n===s.SHORT&&(o=s.RG16I),n===s.INT&&(o=s.RG32I)),e===s.RGB&&(n===s.FLOAT&&(o=s.RGB32F),n===s.HALF_FLOAT&&(o=s.RGB16F),n===s.UNSIGNED_BYTE&&(o=s.RGB8),n===s.UNSIGNED_SHORT&&(o=s.RGB16),n===s.UNSIGNED_INT&&(o=s.RGB32UI),n===s.BYTE&&(o=s.RGB8I),n===s.SHORT&&(o=s.RGB16I),n===s.INT&&(o=s.RGB32I),n===s.UNSIGNED_BYTE&&(o=i===Bp&&!1===r?s.SRGB8:s.RGB8),n===s.UNSIGNED_SHORT_5_6_5&&(o=s.RGB565),n===s.UNSIGNED_SHORT_5_5_5_1&&(o=s.RGB5_A1),n===s.UNSIGNED_SHORT_4_4_4_4&&(o=s.RGB4),n===s.UNSIGNED_INT_5_9_9_9_REV&&(o=s.RGB9_E5)),e===s.RGB_INTEGER&&(n===s.UNSIGNED_BYTE&&(o=s.RGB8UI),n===s.UNSIGNED_SHORT&&(o=s.RGB16UI),n===s.UNSIGNED_INT&&(o=s.RGB32UI),n===s.BYTE&&(o=s.RGB8I),n===s.SHORT&&(o=s.RGB16I),n===s.INT&&(o=s.RGB32I)),e===s.RGBA&&(n===s.FLOAT&&(o=s.RGBA32F),n===s.HALF_FLOAT&&(o=s.RGBA16F),n===s.UNSIGNED_BYTE&&(o=s.RGBA8),n===s.UNSIGNED_SHORT&&(o=s.RGBA16),n===s.UNSIGNED_INT&&(o=s.RGBA32UI),n===s.BYTE&&(o=s.RGBA8I),n===s.SHORT&&(o=s.RGBA16I),n===s.INT&&(o=s.RGBA32I),n===s.UNSIGNED_BYTE&&(o=i===Bp&&!1===r?s.SRGB8_ALPHA8:s.RGBA8),n===s.UNSIGNED_SHORT_4_4_4_4&&(o=s.RGBA4),n===s.UNSIGNED_SHORT_5_5_5_1&&(o=s.RGB5_A1)),e===s.RGBA_INTEGER&&(n===s.UNSIGNED_BYTE&&(o=s.RGBA8UI),n===s.UNSIGNED_SHORT&&(o=s.RGBA16UI),n===s.UNSIGNED_INT&&(o=s.RGBA32UI),n===s.BYTE&&(o=s.RGBA8I),n===s.SHORT&&(o=s.RGBA16I),n===s.INT&&(o=s.RGBA32I)),e===s.DEPTH_COMPONENT&&(n===s.UNSIGNED_INT&&(o=s.DEPTH24_STENCIL8),n===s.FLOAT&&(o=s.DEPTH_COMPONENT32F)),e===s.DEPTH_STENCIL&&n===s.UNSIGNED_INT_24_8&&(o=s.DEPTH24_STENCIL8),o!==s.R16F&&o!==s.R32F&&o!==s.RG16F&&o!==s.RG32F&&o!==s.RGBA16F&&o!==s.RGBA32F||a.get("EXT_color_buffer_float"),o}setTextureParameters(t,e){const{gl:n,extensions:i,backend:r}=this;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),n.pixelStorei(n.UNPACK_COLORSPACE_CONVERSION_WEBGL,n.NONE),n.texParameteri(t,n.TEXTURE_WRAP_S,WI[e.wrapS]),n.texParameteri(t,n.TEXTURE_WRAP_T,WI[e.wrapT]),t!==n.TEXTURE_3D&&t!==n.TEXTURE_2D_ARRAY||n.texParameteri(t,n.TEXTURE_WRAP_R,WI[e.wrapR]),n.texParameteri(t,n.TEXTURE_MAG_FILTER,qI[e.magFilter]);const s=void 0!==e.mipmaps&&e.mipmaps.length>0,a=e.minFilter===Yd&&s?Zd:e.minFilter;if(n.texParameteri(t,n.TEXTURE_MIN_FILTER,qI[a]),e.compareFunction&&(n.texParameteri(t,n.TEXTURE_COMPARE_MODE,n.COMPARE_REF_TO_TEXTURE),n.texParameteri(t,n.TEXTURE_COMPARE_FUNC,XI[e.compareFunction])),!0===i.has("EXT_texture_filter_anisotropic")){if(e.magFilter===qd)return;if(e.minFilter!==$d&&e.minFilter!==Zd)return;if(e.type===rp&&!1===i.has("OES_texture_float_linear"))return;if(e.anisotropy>1){const s=i.get("EXT_texture_filter_anisotropic");n.texParameterf(t,s.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e.anisotropy,r.getMaxAnisotropy()))}}}createDefaultTexture(t){const{gl:e,backend:n,defaultTextures:i}=this,r=this.getGLTextureType(t);let s=i[r];void 0===s&&(s=e.createTexture(),n.state.bindTexture(r,s),e.texParameteri(r,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(r,e.TEXTURE_MAG_FILTER,e.NEAREST),i[r]=s),n.set(t,{textureGPU:s,glTextureType:r,isDefault:!0})}createTexture(t,e){const{gl:n,backend:i}=this,{levels:r,width:s,height:a,depth:o}=e,l=i.utils.convert(t.format,t.colorSpace),h=i.utils.convert(t.type),u=this.getInternalFormat(t.internalFormat,l,h,t.colorSpace,t.isVideoTexture),c=n.createTexture(),d=this.getGLTextureType(t);i.state.bindTexture(d,c),this.setTextureParameters(d,t),t.isDataArrayTexture||t.isCompressedArrayTexture?n.texStorage3D(n.TEXTURE_2D_ARRAY,r,u,s,a,o):t.isData3DTexture?n.texStorage3D(n.TEXTURE_3D,r,u,s,a,o):t.isVideoTexture||n.texStorage2D(d,r,u,s,a),i.set(t,{textureGPU:c,glTextureType:d,glFormat:l,glType:h,glInternalFormat:u})}copyBufferToTexture(t,e){const{gl:n,backend:i}=this,{textureGPU:r,glTextureType:s,glFormat:a,glType:o}=i.get(e),{width:l,height:h}=e.source.data;n.bindBuffer(n.PIXEL_UNPACK_BUFFER,t),i.state.bindTexture(s,r),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,!1),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),n.texSubImage2D(s,0,0,0,l,h,a,o,0),n.bindBuffer(n.PIXEL_UNPACK_BUFFER,null),i.state.unbindTexture()}updateTexture(t,e){const{gl:n}=this,{width:i,height:r}=e,{textureGPU:s,glTextureType:a,glFormat:o,glType:l,glInternalFormat:h}=this.backend.get(t);if(t.isRenderTargetTexture||void 0===s)return;const u=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(a,s),this.setTextureParameters(a,t),t.isCompressedTexture){const i=t.mipmaps,r=e.image;for(let e=0;e<i.length;e++){const s=i[e];t.isCompressedArrayTexture?t.format!==n.RGBA?null!==o?n.compressedTexSubImage3D(n.TEXTURE_2D_ARRAY,e,0,0,0,s.width,s.height,r.depth,o,s.data):console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"):n.texSubImage3D(n.TEXTURE_2D_ARRAY,e,0,0,0,s.width,s.height,r.depth,o,l,s.data):null!==o?n.compressedTexSubImage2D(n.TEXTURE_2D,e,0,0,s.width,s.height,o,s.data):console.warn("Unsupported compressed texture format")}}else if(t.isCubeTexture){const t=e.images;for(let e=0;e<6;e++){const s=u(t[e]);n.texSubImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,i,r,o,l,s)}}else if(t.isDataArrayTexture){const t=e.image;n.texSubImage3D(n.TEXTURE_2D_ARRAY,0,0,0,0,t.width,t.height,t.depth,o,l,t.data)}else if(t.isData3DTexture){const t=e.image;n.texSubImage3D(n.TEXTURE_3D,0,0,0,0,t.width,t.height,t.depth,o,l,t.data)}else if(t.isVideoTexture)t.update(),n.texImage2D(a,0,h,o,l,e.image);else{const t=u(e.image);n.texSubImage2D(a,0,0,0,i,r,o,l,t)}}generateMipmaps(t){const{gl:e,backend:n}=this,{textureGPU:i,glTextureType:r}=n.get(t);n.state.bindTexture(r,i),e.generateMipmap(r)}deallocateRenderBuffers(t){const{gl:e,backend:n}=this;if(t){const i=n.get(t);if(i.renderBufferStorageSetup=void 0,i.framebuffers){for(const t in i.framebuffers)e.deleteFramebuffer(i.framebuffers[t]);delete i.framebuffers}if(i.depthRenderbuffer&&(e.deleteRenderbuffer(i.depthRenderbuffer),delete i.depthRenderbuffer),i.stencilRenderbuffer&&(e.deleteRenderbuffer(i.stencilRenderbuffer),delete i.stencilRenderbuffer),i.msaaFrameBuffer&&(e.deleteFramebuffer(i.msaaFrameBuffer),delete i.msaaFrameBuffer),i.msaaRenderbuffers){for(let t=0;t<i.msaaRenderbuffers.length;t++)e.deleteRenderbuffer(i.msaaRenderbuffers[t]);delete i.msaaRenderbuffers}}}destroyTexture(t){const{gl:e,backend:n}=this,{textureGPU:i,renderTarget:r}=n.get(t);this.deallocateRenderBuffers(r),e.deleteTexture(i),n.delete(t)}copyTextureToTexture(t,e,n=null,i=null,r=0){const{gl:s,backend:a}=this,{state:o}=this.backend,{textureGPU:l,glTextureType:h,glType:u,glFormat:c}=a.get(e);let d,p,f,m,g,_;null!==n?(d=n.max.x-n.min.x,p=n.max.y-n.min.y,f=n.min.x,m=n.min.y):(d=t.image.width,p=t.image.height,f=0,m=0),null!==i?(g=i.x,_=i.y):(g=0,_=0),o.bindTexture(h,l),s.pixelStorei(s.UNPACK_ALIGNMENT,e.unpackAlignment),s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,e.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,e.unpackAlignment);const v=s.getParameter(s.UNPACK_ROW_LENGTH),y=s.getParameter(s.UNPACK_IMAGE_HEIGHT),x=s.getParameter(s.UNPACK_SKIP_PIXELS),b=s.getParameter(s.UNPACK_SKIP_ROWS),S=s.getParameter(s.UNPACK_SKIP_IMAGES),M=t.isCompressedTexture?t.mipmaps[r]:t.image;if(s.pixelStorei(s.UNPACK_ROW_LENGTH,M.width),s.pixelStorei(s.UNPACK_IMAGE_HEIGHT,M.height),s.pixelStorei(s.UNPACK_SKIP_PIXELS,f),s.pixelStorei(s.UNPACK_SKIP_ROWS,m),t.isRenderTargetTexture||t.isDepthTexture){const n=a.get(t),i=a.get(e),r=a.get(n.renderTarget),l=a.get(i.renderTarget),h=r.framebuffers[n.cacheKey],u=l.framebuffers[i.cacheKey];o.bindFramebuffer(s.READ_FRAMEBUFFER,h),o.bindFramebuffer(s.DRAW_FRAMEBUFFER,u);let c=s.COLOR_BUFFER_BIT;t.isDepthTexture&&(c=s.DEPTH_BUFFER_BIT),s.blitFramebuffer(f,m,d,p,g,_,d,p,c,s.NEAREST),o.bindFramebuffer(s.READ_FRAMEBUFFER,null),o.bindFramebuffer(s.DRAW_FRAMEBUFFER,null)}else t.isDataTexture?s.texSubImage2D(s.TEXTURE_2D,r,g,_,d,p,c,u,M.data):t.isCompressedTexture?s.compressedTexSubImage2D(s.TEXTURE_2D,r,g,_,M.width,M.height,c,M.data):s.texSubImage2D(s.TEXTURE_2D,r,g,_,d,p,c,u,M);s.pixelStorei(s.UNPACK_ROW_LENGTH,v),s.pixelStorei(s.UNPACK_IMAGE_HEIGHT,y),s.pixelStorei(s.UNPACK_SKIP_PIXELS,x),s.pixelStorei(s.UNPACK_SKIP_ROWS,b),s.pixelStorei(s.UNPACK_SKIP_IMAGES,S),0===r&&e.generateMipmaps&&s.generateMipmap(s.TEXTURE_2D),o.unbindTexture()}copyFramebufferToTexture(t,e,n){const{gl:i}=this,{state:r}=this.backend,{textureGPU:s}=this.backend.get(t),{x:a,y:o,z:l,w:h}=n,u=!0===t.isDepthTexture||e.renderTarget&&e.renderTarget.samples>0,c=e.renderTarget?e.renderTarget.height:this.backend.gerDrawingBufferSize().y;if(u){const n=0!==a||0!==o;let u,d;if(!0===t.isDepthTexture?(u=i.DEPTH_BUFFER_BIT,d=i.DEPTH_ATTACHMENT,e.stencil&&(u|=i.STENCIL_BUFFER_BIT)):(u=i.COLOR_BUFFER_BIT,d=i.COLOR_ATTACHMENT0),n){const t=this.backend.get(e.renderTarget),n=t.framebuffers[e.getCacheKey()],d=t.msaaFrameBuffer;r.bindFramebuffer(i.DRAW_FRAMEBUFFER,n),r.bindFramebuffer(i.READ_FRAMEBUFFER,d);const p=c-o-h;i.blitFramebuffer(a,p,a+l,p+h,a,p,a+l,p+h,u,i.NEAREST),r.bindFramebuffer(i.READ_FRAMEBUFFER,n),r.bindTexture(i.TEXTURE_2D,s),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,p,l,h),r.unbindTexture()}else{const t=i.createFramebuffer();r.bindFramebuffer(i.DRAW_FRAMEBUFFER,t),i.framebufferTexture2D(i.DRAW_FRAMEBUFFER,d,i.TEXTURE_2D,s,0),i.blitFramebuffer(0,0,l,h,0,0,l,h,u,i.NEAREST),i.deleteFramebuffer(t)}}else r.bindTexture(i.TEXTURE_2D,s),i.copyTexSubImage2D(i.TEXTURE_2D,0,0,0,a,c-h-o,l,h),r.unbindTexture();t.generateMipmaps&&this.generateMipmaps(t),this.backend._setFramebuffer(e)}setupRenderBufferStorage(t,e){const{gl:n}=this,i=e.renderTarget,{samples:r,depthTexture:s,depthBuffer:a,stencilBuffer:o,width:l,height:h}=i;if(n.bindRenderbuffer(n.RENDERBUFFER,t),a&&!o){let e=n.DEPTH_COMPONENT24;r>0?(s&&s.isDepthTexture&&s.type===n.FLOAT&&(e=n.DEPTH_COMPONENT32F),n.renderbufferStorageMultisample(n.RENDERBUFFER,r,e,l,h)):n.renderbufferStorage(n.RENDERBUFFER,e,l,h),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_ATTACHMENT,n.RENDERBUFFER,t)}else a&&o&&(r>0?n.renderbufferStorageMultisample(n.RENDERBUFFER,r,n.DEPTH24_STENCIL8,l,h):n.renderbufferStorage(n.RENDERBUFFER,n.DEPTH_STENCIL,l,h),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.DEPTH_STENCIL_ATTACHMENT,n.RENDERBUFFER,t))}async copyTextureToBuffer(t,e,n,i,r,s){const{backend:a,gl:o}=this,{textureGPU:l,glFormat:h,glType:u}=this.backend.get(t),c=o.createFramebuffer();o.bindFramebuffer(o.READ_FRAMEBUFFER,c);const d=t.isCubeTexture?o.TEXTURE_CUBE_MAP_POSITIVE_X+s:o.TEXTURE_2D;o.framebufferTexture2D(o.READ_FRAMEBUFFER,o.COLOR_ATTACHMENT0,d,l,0);const p=this._getTypedArrayType(u),f=i*r*this._getBytesPerTexel(u,h),m=o.createBuffer();o.bindBuffer(o.PIXEL_PACK_BUFFER,m),o.bufferData(o.PIXEL_PACK_BUFFER,f,o.STREAM_READ),o.readPixels(e,n,i,r,h,u,0),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),await a.utils._clientWaitAsync();const g=new p(f/p.BYTES_PER_ELEMENT);return o.bindBuffer(o.PIXEL_PACK_BUFFER,m),o.getBufferSubData(o.PIXEL_PACK_BUFFER,0,g),o.bindBuffer(o.PIXEL_PACK_BUFFER,null),o.deleteFramebuffer(c),g}_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.HALF_FLOAT)return Uint16Array;if(t===e.FLOAT)return Float32Array;throw new Error(`Unsupported WebGL type: ${t}`)}_getBytesPerTexel(t,e){const{gl:n}=this;let i=0;return t===n.UNSIGNED_BYTE&&(i=1),t!==n.UNSIGNED_SHORT_4_4_4_4&&t!==n.UNSIGNED_SHORT_5_5_5_1&&t!==n.UNSIGNED_SHORT_5_6_5&&t!==n.UNSIGNED_SHORT&&t!==n.HALF_FLOAT||(i=2),t!==n.UNSIGNED_INT&&t!==n.FLOAT||(i=4),e===n.RGBA?4*i:e===n.RGB?3*i:e===n.ALPHA?i:void 0}}class KI{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 ZI{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 n=e.get("EXT_texture_filter_anisotropic");this.maxAnisotropy=t.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else this.maxAnisotropy=0;return this.maxAnisotropy}}const QI={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:n,mode:i,object:r,type:s,info:a,index:o}=this;0!==o?n.drawElements(i,e,s,t):n.drawArrays(i,t,e),a.update(r,e,i,1)}renderInstances(t,e,n){const{gl:i,mode:r,type:s,index:a,object:o,info:l}=this;0!==n&&(0!==a?i.drawElementsInstanced(r,e,s,t,n):i.drawArraysInstanced(r,t,e,n),l.update(o,e,r,n))}renderMultiDraw(t,e,n){const{extensions:i,mode:r,object:s,info:a}=this;if(0===n)return;const o=i.get("WEBGL_multi_draw");if(null===o)for(let i=0;i<n;i++)this.render(t[i],e[i]);else{0!==this.index?o.multiDrawElementsWEBGL(r,e,0,this.type,t,0,n):o.multiDrawArraysWEBGL(r,t,0,e,0,n);let i=0;for(let t=0;t<n;t++)i+=e[t];a.update(s,i,r,1)}}renderMultiDrawInstances(t,e,n,i){const{extensions:r,mode:s,object:a,info:o}=this;if(0===n)return;const l=r.get("WEBGL_multi_draw");if(null===l)for(let r=0;r<n;r++)this.renderInstances(t[r],e[r],i[r]);else{0!==this.index?l.multiDrawElementsInstancedWEBGL(s,e,0,this.type,t,0,i,0,n):l.multiDrawArraysInstancedWEBGL(s,t,0,e,0,i,0,n);let r=0;for(let t=0;t<n;t++)r+=e[t]*i[t];o.update(a,r,s,1)}}}class tL extends OI{constructor(t={}){super(t),this.isWebGLBackend=!0}init(t){super.init(t);const e=this.parameters,n=void 0!==e.context?e.context:t.domElement.getContext("webgl2");function i(e){e.preventDefault();const n={api:"WebGL",message:e.statusMessage||"Unknown reason",reason:null,originalEvent:e};t.onDeviceLost(n)}this._onContextLost=i,t.domElement.addEventListener("webglcontextlost",i,!1),this.gl=n,this.extensions=new KI(this),this.capabilities=new ZI(this),this.attributeUtils=new zI(this),this.textureUtils=new YI(this),this.bufferRenderer=new JI(this),this.state=new HI(this),this.utils=new jI(this),this.vaoCache={},this.transformFeedbackCache={},this.discard=!1,this.trackTimestamp=!0===e.trackTimestamp,this.extensions.get("EXT_color_buffer_float"),this.extensions.get("WEBGL_clip_cull_distance"),this.extensions.get("OES_texture_float_linear"),this.extensions.get("EXT_color_buffer_half_float"),this.extensions.get("WEBGL_multisampled_render_to_texture"),this.extensions.get("WEBGL_render_shared_exponent"),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._knownBindings=new WeakSet,this._currentContext=null}get coordinateSystem(){return Jp}async getArrayBufferAsync(t){return await this.attributeUtils.getArrayBufferAsync(t)}async waitForGPU(){await this.utils._clientWaitAsync()}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 n=this.get(t);n.gpuQueries||(n.gpuQueries=[]);for(let t=0;t<n.gpuQueries.length;t++){const i=n.gpuQueries[t],r=this.gl.getQueryParameter(i.query,this.gl.QUERY_RESULT_AVAILABLE),s=this.gl.getParameter(this.disjoint.GPU_DISJOINT_EXT);if(r&&!s){const r=this.gl.getQueryParameter(i.query,this.gl.QUERY_RESULT),s=Number(r)/1e6;this.gl.deleteQuery(i.query),n.gpuQueries.splice(t,1),t--,this.renderer.info.updateTimestamp(e,s)}}}getContext(){return this.gl}beginRender(t){const{gl:e}=this,n=this.get(t);if(this.initTimestampQuery(t),n.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:n,y:i,width:r,height:s}=t.scissorValue;e.scissor(n,t.height-s-i,r,s)}const i=t.occlusionQueryCount;i>0&&(n.currentOcclusionQueries=n.occlusionQueries,n.currentOcclusionQueryObjects=n.occlusionQueryObjects,n.lastOcclusionObject=null,n.occlusionQueries=new Array(i),n.occlusionQueryObjects=new Array(i),n.occlusionQueryIndex=0)}finishRender(t){const{gl:e,state:n}=this,i=this.get(t),r=i.previousContext,s=t.occlusionQueryCount;s>0&&(s>i.occlusionQueryIndex&&e.endQuery(e.ANY_SAMPLES_PASSED),this.resolveOccludedAsync(t));const a=t.textures;if(null!==a)for(let t=0;t<a.length;t++){const e=a[t];e.generateMipmaps&&this.generateMipmaps(e)}if(this._currentContext=r,null!==t.textures&&t.renderTarget){const i=this.get(t.renderTarget),{samples:r}=t.renderTarget;if(r>0){const r=i.framebuffers[t.getCacheKey()],s=e.COLOR_BUFFER_BIT,a=i.msaaFrameBuffer,o=t.textures;n.bindFramebuffer(e.READ_FRAMEBUFFER,a),n.bindFramebuffer(e.DRAW_FRAMEBUFFER,r);for(let n=0;n<o.length;n++)if(t.scissor){const{x:n,y:r,width:a,height:o}=t.scissorValue,l=t.height-o-r;e.blitFramebuffer(n,l,n+a,l+o,n,l,n+a,l+o,s,e.NEAREST),e.invalidateSubFramebuffer(e.READ_FRAMEBUFFER,i.invalidationArray,n,l,a,o)}else e.blitFramebuffer(0,0,t.width,t.height,0,0,t.width,t.height,s,e.NEAREST),e.invalidateFramebuffer(e.READ_FRAMEBUFFER,i.invalidationArray)}}null!==r&&(this._setFramebuffer(r),r.viewport?this.updateViewport(r):e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight)),this.prepareTimestampBuffer(t)}resolveOccludedAsync(t){const e=this.get(t),{currentOcclusionQueries:n,currentOcclusionQueryObjects:i}=e;if(n&&i){const t=new WeakSet,{gl:r}=this;e.currentOcclusionQueryObjects=null,e.currentOcclusionQueries=null;const s=()=>{let a=0;for(let e=0;e<n.length;e++){const s=n[e];null!==s&&(r.getQueryParameter(s,r.QUERY_RESULT_AVAILABLE)&&(r.getQueryParameter(s,r.QUERY_RESULT)>0&&t.add(i[e]),n[e]=null,r.deleteQuery(s),a++))}a<n.length?requestAnimationFrame(s):e.occluded=t};s()}}isOccluded(t,e){const n=this.get(t);return n.occluded&&n.occluded.has(e)}updateViewport(t){const e=this.gl,{x:n,y:i,width:r,height:s}=t.viewportValue;e.viewport(n,t.height-s-i,r,s)}setScissorTest(t){const e=this.gl;t?e.enable(e.SCISSOR_TEST):e.disable(e.SCISSOR_TEST)}clear(t,e,n,i=null,r=!0){const{gl:s}=this;if(null===i){const t=this.getClearColor();t.r*=t.a,t.g*=t.a,t.b*=t.a,i={textures:null,clearColorValue:t}}let a=0;if(t&&(a|=s.COLOR_BUFFER_BIT),e&&(a|=s.DEPTH_BUFFER_BIT),n&&(a|=s.STENCIL_BUFFER_BIT),0!==a){let o;if(i.clearColorValue?o=i.clearColorValue:(o=this.getClearColor(),o.r*=o.a,o.g*=o.a,o.b*=o.a),e&&this.state.setDepthMask(!0),null===i.textures)s.clearColor(o.r,o.g,o.b,o.a),s.clear(a);else{if(r&&this._setFramebuffer(i),t)for(let t=0;t<i.textures.length;t++)s.clearBufferfv(s.COLOR,t,[o.r,o.g,o.b,o.a]);e&&n?s.clearBufferfi(s.DEPTH_STENCIL,0,1,0):e?s.clearBufferfv(s.DEPTH,0,[1]):n&&s.clearBufferiv(s.STENCIL,0,[0])}}}beginCompute(t){const{state:e,gl:n}=this;e.bindFramebuffer(n.FRAMEBUFFER,null),this.initTimestampQuery(t)}compute(t,e,n,i){const{state:r,gl:s}=this;this.discard||(s.enable(s.RASTERIZER_DISCARD),this.discard=!0);const{programGPU:a,transformBuffers:o,attributes:l}=this.get(i),h=this._getVaoKey(null,l),u=this.vaoCache[h];void 0===u?this._createVao(null,l):s.bindVertexArray(u),r.useProgram(a),this._bindUniforms(n);const c=this._getTransformFeedback(o);s.bindTransformFeedback(s.TRANSFORM_FEEDBACK,c),s.beginTransformFeedback(s.POINTS),l[0].isStorageInstancedBufferAttribute?s.drawArraysInstanced(s.POINTS,0,1,e.count):s.drawArrays(s.POINTS,0,e.count),s.endTransformFeedback(),s.bindTransformFeedback(s.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),this._currentContext&&this._setFramebuffer(this._currentContext)}draw(t){const{object:e,pipeline:n,material:i,context:r}=t,{programGPU:s}=this.get(n),{gl:a,state:o}=this,l=this.get(r),h=t.getDrawParameters();if(null===h)return;this._bindUniforms(t.getBindings());const u=e.isMesh&&e.matrixWorld.determinant()<0;o.setMaterial(i,u),o.useProgram(s);let c=t.staticVao;if(void 0===c){const e=this._getVaoKey(t.getIndex(),t.getAttributes());if(c=this.vaoCache[e],void 0===c){let e;({vaoGPU:c,staticVao:e}=this._createVao(t.getIndex(),t.getAttributes())),e&&(t.staticVao=c)}}a.bindVertexArray(c);const d=t.getIndex(),p=l.lastOcclusionObject;if(p!==e&&void 0!==p){if(null!==p&&!0===p.occlusionTest&&(a.endQuery(a.ANY_SAMPLES_PASSED),l.occlusionQueryIndex++),!0===e.occlusionTest){const t=a.createQuery();a.beginQuery(a.ANY_SAMPLES_PASSED,t),l.occlusionQueries[l.occlusionQueryIndex]=t,l.occlusionQueryObjects[l.occlusionQueryIndex]=e}l.lastOcclusionObject=e}const f=this.bufferRenderer;e.isPoints?f.mode=a.POINTS:e.isLineSegments?f.mode=a.LINES:e.isLine?f.mode=a.LINE_STRIP:e.isLineLoop?f.mode=a.LINE_LOOP:!0===i.wireframe?(o.setLineWidth(i.wireframeLinewidth*this.renderer.getPixelRatio()),f.mode=a.LINES):f.mode=a.TRIANGLES;const{vertexCount:m,instanceCount:g}=h;let{firstVertex:_}=h;if(f.object=e,null!==d){_*=d.array.BYTES_PER_ELEMENT;const t=this.get(d);f.index=d.count,f.type=t.type}else f.index=0;var v;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):(v="THREE.WebGLRenderer: WEBGL_multi_draw not supported.")in vf||(vf[v]=!0,console.warn(v)):g>1?f.renderInstances(_,m,g):f.render(_,m),a.bindVertexArray(null)}needsRenderUpdate(){return!1}getRenderCacheKey(){return""}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,n,i,r,s){return this.textureUtils.copyTextureToBuffer(t,e,n,i,r,s)}createSampler(){}destroySampler(){}createNodeBuilder(t,e){return new II(t,e)}createProgram(t){const e=this.gl,{stage:n,code:i}=t,r="fragment"===n?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 n=this.gl,i=t.pipeline,{fragmentProgram:r,vertexProgram:s}=i,a=n.createProgram(),o=this.get(r).shaderGPU,l=this.get(s).shaderGPU;if(n.attachShader(a,o),n.attachShader(a,l),n.linkProgram(a),this.set(i,{programGPU:a,fragmentShader:o,vertexShader:l}),null!==e&&this.parallel){const r=new Promise((e=>{const r=this.parallel,s=()=>{n.getProgramParameter(a,r.COMPLETION_STATUS_KHR)?(this._completeCompile(t,i),e()):requestAnimationFrame(s)};s()}));e.push(r)}else this._completeCompile(t,i)}_handleSource(t,e){const n=t.split("\n"),i=[],r=Math.max(e-6,0),s=Math.min(e+6,n.length);for(let t=r;t<s;t++){const r=t+1;i.push(`${r===e?">":" "} ${r}: ${n[t]}`)}return i.join("\n")}_getShaderErrors(t,e,n){const i=t.getShaderParameter(e,t.COMPILE_STATUS),r=t.getShaderInfoLog(e).trim();if(i&&""===r)return"";const s=/ERROR: 0:(\d+)/.exec(r);if(s){const i=parseInt(s[1]);return n.toUpperCase()+"\n\n"+r+"\n\n"+this._handleSource(t.getShaderSource(e),i)}return r}_logProgramError(t,e,n){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,n,e);else{const s=this._getShaderErrors(i,n,"vertex"),a=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"+s+"\n"+a)}else""!==r&&console.warn("THREE.WebGLProgram: Program Info Log:",r)}}_completeCompile(t,e){const{state:n,gl:i}=this,r=this.get(e),{programGPU:s,fragmentShader:a,vertexShader:o}=r;!1===i.getProgramParameter(s,i.LINK_STATUS)&&this._logProgramError(s,a,o),n.useProgram(s);const l=t.getBindings();this._setupBindings(l,s),this.set(e,{programGPU:s})}createComputePipeline(t,e){const{state:n,gl:i}=this,r={stage:"fragment",code:"#version 300 es\nprecision highp float;\nvoid main() {}"};this.createProgram(r);const{computeProgram:s}=t,a=i.createProgram(),o=this.get(r).shaderGPU,l=this.get(s).shaderGPU,h=s.transforms,u=[],c=[];for(let t=0;t<h.length;t++){const e=h[t];u.push(e.varyingName),c.push(e.attributeNode)}i.attachShader(a,o),i.attachShader(a,l),i.transformFeedbackVaryings(a,u,i.SEPARATE_ATTRIBS),i.linkProgram(a),!1===i.getProgramParameter(a,i.LINK_STATUS)&&this._logProgramError(a,o,l),n.useProgram(a),this._setupBindings(e,a);const d=s.attributes,p=[],f=[];for(let t=0;t<d.length;t++){const e=d[t].node.attribute;p.push(e),this.has(e)||this.attributeUtils.createAttribute(e,i.ARRAY_BUFFER)}for(let t=0;t<c.length;t++){const e=c[t].attribute;this.has(e)||this.attributeUtils.createAttribute(e,i.ARRAY_BUFFER);const n=this.get(e);f.push(n)}this.set(t,{programGPU:a,transformBuffers:f,attributes:p})}createBindings(t,e){if(!1===this._knownBindings.has(e)){this._knownBindings.add(e);let t=0,n=0;for(const i of e){this.set(i,{textures:n,uniformBuffers:t});for(const e of i.bindings)e.isUniformBuffer&&t++,e.isSampledTexture&&n++}}this.updateBindings(t,e)}updateBindings(t){const{gl:e}=this,n=this.get(t);let i=n.uniformBuffers,r=n.textures;for(const n of t.bindings)if(n.isUniformsGroup||n.isUniformBuffer){const t=n.buffer,r=e.createBuffer();e.bindBuffer(e.UNIFORM_BUFFER,r),e.bufferData(e.UNIFORM_BUFFER,t,e.DYNAMIC_DRAW),this.set(n,{index:i++,bufferGPU:r})}else if(n.isSampledTexture){const{textureGPU:t,glTextureType:e}=this.get(n.texture);this.set(n,{index:r++,textureGPU:t,glTextureType:e})}}updateBinding(t){const e=this.gl;if(t.isUniformsGroup||t.isUniformBuffer){const n=this.get(t).bufferGPU,i=t.buffer;e.bindBuffer(e.UNIFORM_BUFFER,n),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(QI).filter((e=>QI[e]===t)),n=this.extensions;for(let t=0;t<e.length;t++)if(n.has(e[t]))return!0;return!1}getMaxAnisotropy(){return this.capabilities.getMaxAnisotropy()}copyTextureToTexture(t,e,n,i,r){this.textureUtils.copyTextureToTexture(t,e,n,i,r)}copyFramebufferToTexture(t,e,n){this.textureUtils.copyFramebufferToTexture(t,e,n)}_setFramebuffer(t){const{gl:e,state:n}=this;let i=null;if(null!==t.textures){const r=t.renderTarget,s=this.get(r),{samples:a,depthBuffer:o,stencilBuffer:l}=r,h=!0===r.isWebGLCubeRenderTarget;let u=s.msaaFrameBuffer,c=s.depthRenderbuffer;const d=oR(t);let p;if(h?(s.cubeFramebuffers||(s.cubeFramebuffers={}),p=s.cubeFramebuffers[d]):(s.framebuffers||(s.framebuffers={}),p=s.framebuffers[d]),void 0===p){p=e.createFramebuffer(),n.bindFramebuffer(e.FRAMEBUFFER,p);const i=t.textures;if(h){s.cubeFramebuffers[d]=p;const{textureGPU:t}=this.get(i[0]),n=this.renderer._activeCubeFace;e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_X+n,t,0)}else{s.framebuffers[d]=p;for(let n=0;n<i.length;n++){const r=i[n],s=this.get(r);s.renderTarget=t.renderTarget,s.cacheKey=d;const a=e.COLOR_ATTACHMENT0+n;e.framebufferTexture2D(e.FRAMEBUFFER,a,e.TEXTURE_2D,s.textureGPU,0)}n.drawBuffers(t,p)}if(null!==t.depthTexture){const n=this.get(t.depthTexture),i=l?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;n.renderTarget=t.renderTarget,n.cacheKey=d,e.framebufferTexture2D(e.FRAMEBUFFER,i,e.TEXTURE_2D,n.textureGPU,0)}}if(a>0){if(void 0===u){const i=[];u=e.createFramebuffer(),n.bindFramebuffer(e.FRAMEBUFFER,u);const r=[],h=t.textures;for(let n=0;n<h.length;n++){if(r[n]=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,r[n]),i.push(e.COLOR_ATTACHMENT0+n),o){const t=l?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;i.push(t)}const s=t.textures[n],h=this.get(s);e.renderbufferStorageMultisample(e.RENDERBUFFER,a,h.glInternalFormat,t.width,t.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+n,e.RENDERBUFFER,r[n])}if(s.msaaFrameBuffer=u,s.msaaRenderbuffers=r,void 0===c){c=e.createRenderbuffer(),this.textureUtils.setupRenderBufferStorage(c,t),s.depthRenderbuffer=c;const n=l?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;i.push(n)}s.invalidationArray=i}i=s.msaaFrameBuffer}else i=p}n.bindFramebuffer(e.FRAMEBUFFER,i)}_getVaoKey(t,e){let n=[];if(null!==t){n+=":"+this.get(t).id}for(let t=0;t<e.length;t++){n+=":"+this.get(e[t]).id}return n}_createVao(t,e){const{gl:n}=this,i=n.createVertexArray();let r="",s=!0;if(n.bindVertexArray(i),null!==t){const e=this.get(t);n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,e.bufferGPU),r+=":"+e.id}for(let t=0;t<e.length;t++){const i=e[t],a=this.get(i);let o,l;r+=":"+a.id,n.bindBuffer(n.ARRAY_BUFFER,a.bufferGPU),n.enableVertexAttribArray(t),(i.isStorageBufferAttribute||i.isStorageInstancedBufferAttribute)&&(s=!1),!0===i.isInterleavedBufferAttribute?(o=i.data.stride*a.bytesPerElement,l=i.offset*a.bytesPerElement):(o=0,l=0),a.isInteger?n.vertexAttribIPointer(t,i.itemSize,a.type,o,l):n.vertexAttribPointer(t,i.itemSize,a.type,i.normalized,o,l),i.isInstancedBufferAttribute&&!i.isInterleavedBufferAttribute?n.vertexAttribDivisor(t,i.meshPerAttribute):i.isInterleavedBufferAttribute&&i.data.isInstancedInterleavedBuffer&&n.vertexAttribDivisor(t,i.data.meshPerAttribute)}return n.bindBuffer(n.ARRAY_BUFFER,null),this.vaoCache[r]=i,{vaoGPU:i,staticVao:s}}_getTransformFeedback(t){let e="";for(let n=0;n<t.length;n++)e+=":"+t[n].id;let n=this.transformFeedbackCache[e];if(void 0!==n)return n;const{gl:i}=this;n=i.createTransformFeedback(),i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,n);for(let e=0;e<t.length;e++){const n=t[e];i.bindBufferBase(i.TRANSFORM_FEEDBACK_BUFFER,e,n.transformBuffer)}return i.bindTransformFeedback(i.TRANSFORM_FEEDBACK,null),this.transformFeedbackCache[e]=n,n}_setupBindings(t,e){const n=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=n.getUniformBlockIndex(e,t.name);n.uniformBlockBinding(e,r,i)}else if(t.isSampledTexture){const r=n.getUniformLocation(e,t.name);n.uniform1i(r,i)}}}_bindUniforms(t){const{gl:e,state:n}=this;for(const i of t)for(const t of i.bindings){const i=this.get(t),r=i.index;t.isUniformsGroup||t.isUniformBuffer?n.bindBufferBase(e.UNIFORM_BUFFER,r,i.bufferGPU):t.isSampledTexture&&n.bindTexture(i.glTextureType,i.textureGPU,e.TEXTURE0+r)}}dispose(){this.renderer.domElement.removeEventListener("webglcontextlost",this._onContextLost)}}class eL extends mI{constructor(t,e){super(t),this.texture=e,this.version=e?e.version:0,this.isSampler=!0}}class nL extends eL{constructor(t,e,n){super(t,e?e.value:null),this.textureNode=e,this.groupNode=n}update(){this.texture=this.textureNode.value}}class iL extends gI{constructor(t,e){super(t,e?e.array:null),this.attribute=e,this.isStorageBuffer=!0}}let rL=0;class sL extends iL{constructor(t,e){super("StorageBuffer_"+rL++,t?t.value:null),this.nodeUniform=t,this.access=t?t.access:RC,this.groupNode=e}get buffer(){return this.nodeUniform.value}}class aL extends OA{constructor(t){super(),this.device=t;this.mipmapSampler=t.createSampler({minFilter:QR}),this.flipYSampler=t.createSampler({minFilter:JR}),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({label:`mipmap-${t}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.mipmapFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:NR,stripIndexFormat:XR},layout:"auto"}),this.transferPipelines[t]=e),e}getFlipYPipeline(t){let e=this.flipYPipelines[t];return void 0===e&&(e=this.device.createRenderPipeline({label:`flipY-${t}`,vertex:{module:this.mipmapVertexShaderModule,entryPoint:"main"},fragment:{module:this.flipYFragmentShaderModule,entryPoint:"main",targets:[{format:t}]},primitive:{topology:NR,stripIndexFormat:XR},layout:"auto"}),this.flipYPipelines[t]=e),e}flipY(t,e,n=0){const i=e.format,{width:r,height:s}=e.size,a=this.getTransferPipeline(i),o=this.getFlipYPipeline(i),l=this.device.createTexture({size:{width:r,height:s,depthOrArrayLayers:1},format:i,usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.TEXTURE_BINDING}),h=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:zC,baseArrayLayer:n}),u=l.createView({baseMipLevel:0,mipLevelCount:1,dimension:zC,baseArrayLayer:0}),c=this.device.createCommandEncoder({}),d=(t,e,n)=>{const i=t.getBindGroupLayout(0),r=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:this.flipYSampler},{binding:1,resource:e}]}),s=c.beginRenderPass({colorAttachments:[{view:n,loadOp:GR,storeOp:zR,clearValue:[0,0,0,0]}]});s.setPipeline(t),s.setBindGroup(0,r),s.draw(4,1,0,0),s.end()};d(a,h,u),d(o,u,h),this.device.queue.submit([c.finish()]),l.destroy()}generateMipmaps(t,e,n=0){const i=this.get(t);void 0===i.useCount&&(i.useCount=0,i.layers=[]);const r=i.layers[n]||this._mipmapCreateBundles(t,e,n),s=this.device.createCommandEncoder({});this._mipmapRunBundles(s,r),this.device.queue.submit([s.finish()]),0!==i.useCount&&(i.layers[n]=r),i.useCount++}_mipmapCreateBundles(t,e,n){const i=this.getTransferPipeline(e.format),r=i.getBindGroupLayout(0);let s=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:zC,baseArrayLayer:n});const a=[];for(let o=1;o<e.mipLevelCount;o++){const l=this.device.createBindGroup({layout:r,entries:[{binding:0,resource:this.mipmapSampler},{binding:1,resource:s}]}),h=t.createView({baseMipLevel:o,mipLevelCount:1,dimension:zC,baseArrayLayer:n}),u={colorAttachments:[{view:h,loadOp:GR,storeOp:zR,clearValue:[0,0,0,0]}]},c=this.device.createRenderBundleEncoder({colorFormats:[e.format]});c.setPipeline(i),c.setBindGroup(0,l),c.draw(4,1,0,0),a.push({renderBundles:[c.finish()],passDescriptor:u}),s=h}return a}_mipmapRunBundles(t,e){const n=e.length;for(let i=0;i<n;i++){const n=e[i],r=t.beginRenderPass(n.passDescriptor);r.executeBundles(n.renderBundles),r.end()}}}const oL={[Hp]:"never",[jp]:"less",[Wp]:"equal",[qp]:"less-equal",[Xp]:"greater",[Yp]:"greater-equal",[Kp]:"always",[$p]:"not-equal"},lL=[0,1,3,2,4,5];class hL{constructor(t){this.backend=t,this._passUtils=null,this.defaultTexture={},this.defaultCubeTexture={},this.defaultVideoFrame=null,this.colorBuffer=null,this.depthTexture=new y_,this.depthTexture.name="depthBuffer"}createSampler(t){const e=this.backend,n=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:1};r.magFilter===QR&&r.minFilter===QR&&r.mipmapFilter===QR&&(r.maxAnisotropy=t.anisotropy),t.isDepthTexture&&null!==t.compareFunction&&(r.compare=oL[t.compareFunction]),i.sampler=n.createSampler(r)}createDefaultTexture(t){let e;const n=uL(t);t.isCubeTexture?e=this._getDefaultCubeTextureGPU(n):t.isVideoTexture?this.backend.get(t).externalTexture=this._getDefaultVideoFrame():e=this._getDefaultTextureGPU(n),this.backend.get(t).texture=e}createTexture(t,e={}){const n=this.backend,i=n.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:s,depth:a,levels:o}=e;t.isFramebufferTexture&&(e.renderTarget?e.format=this.backend.utils.getCurrentColorFormat(e.renderTarget):e.format=this.backend.utils.getPreferredCanvasFormat());const l=this._getDimension(t),h=t.internalFormat||e.format||uL(t,n.device);i.format=h;let u=void 0!==e.sampleCount?e.sampleCount:1;u=n.utils.getSampleCount(u);const c=t.isRenderTargetTexture&&!t.isMultisampleRenderTargetTexture?1:u;let d=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC;!0===t.isStorageTexture&&(d|=GPUTextureUsage.STORAGE_BINDING),!0!==t.isCompressedTexture&&!0!==t.isCompressedArrayTexture&&(d|=GPUTextureUsage.RENDER_ATTACHMENT);const p={label:t.name,size:{width:r,height:s,depthOrArrayLayers:a},mipLevelCount:o,sampleCount:c,dimension:l,format:h,usage:d};if(t.isVideoTexture){const e=t.source.data,n=new VideoFrame(e);p.size.width=n.displayWidth,p.size.height=n.displayHeight,n.close(),i.externalTexture=e}else{if(void 0===h)return console.warn("WebGPURenderer: Texture format not supported."),this.createDefaultTexture(t);i.texture=n.device.createTexture(p)}if(t.isRenderTargetTexture&&u>1&&!t.isMultisampleRenderTargetTexture){const t=Object.assign({},p);t.label=t.label+"-msaa",t.sampleCount=u,i.msaaTexture=n.device.createTexture(t)}i.initialized=!0,i.textureDescriptorGPU=p}destroyTexture(t){const e=this.backend,n=e.get(t);n.texture.destroy(),void 0!==n.msaaTexture&&n.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{const n=t.image.depth||1;for(let t=0;t<n;t++)this._generateMipmaps(e.texture,e.textureDescriptorGPU,t)}}getColorBuffer(){this.colorBuffer&&this.colorBuffer.destroy();const t=this.backend,{width:e,height:n}=t.getDrawingBufferSize();return this.colorBuffer=t.device.createTexture({label:"colorBuffer",size:{width:e,height:n,depthOrArrayLayers:1},sampleCount:t.utils.getSampleCount(t.renderer.samples),format:t.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC}),this.colorBuffer}getDepthBuffer(t=!0,e=!1){const n=this.backend,{width:i,height:r}=n.getDrawingBufferSize(),s=this.depthTexture,a=n.get(s).texture;let o,l;if(e?(o=up,l=ap):t&&(o=hp,l=ip),void 0!==a){if(s.image.width===i&&s.image.height===r&&s.format===o&&s.type===l)return a;this.destroyTexture(s)}return s.name="depthBuffer",s.format=o,s.type=l,s.image.width=i,s.image.height=r,this.createTexture(s,{sampleCount:n.utils.getSampleCount(n.renderer.samples),width:i,height:r}),n.get(s).texture}updateTexture(t,e){const n=this.backend.get(t),{textureDescriptorGPU:i}=n;if(!t.isRenderTargetTexture&&void 0!==i){if(t.isDataTexture)this._copyBufferToTexture(e.image,n.texture,i,0,t.flipY);else if(t.isDataArrayTexture||t.isData3DTexture)for(let r=0;r<e.image.depth;r++)this._copyBufferToTexture(e.image,n.texture,i,r,t.flipY,r);else if(t.isCompressedTexture||t.isCompressedArrayTexture)this._copyCompressedBufferToTexture(t.mipmaps,n.texture,i);else if(t.isCubeTexture)this._copyCubeMapToTexture(e.images,n.texture,i,t.flipY);else if(t.isVideoTexture){const e=t.source.data;n.externalTexture=e}else this._copyImageToTexture(e.image,n.texture,i,0,t.flipY);n.version=t.version,t.onUpdate&&t.onUpdate(t)}}async copyTextureToBuffer(t,e,n,i,r,s){const a=this.backend.device,o=this.backend.get(t),l=o.texture,h=o.textureDescriptorGPU.format,u=this._getBytesPerTexel(h);let c=i*u;c=256*Math.ceil(c/256);const d=a.createBuffer({size:i*r*u,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),p=a.createCommandEncoder();p.copyTextureToBuffer({texture:l,origin:{x:e,y:n,z:s}},{buffer:d,bytesPerRow:c},{width:i,height:r});const f=this._getTypedArrayType(h);a.queue.submit([p.finish()]),await d.mapAsync(GPUMapMode.READ);return new f(d.getMappedRange())}_isEnvironmentTexture(t){const e=t.mapping;return e===Gd||e===Vd||e===zd||e===kd}_getDefaultTextureGPU(t){let e=this.defaultTexture[t];if(void 0===e){const n=new Lf;n.minFilter=qd,n.magFilter=qd,this.createTexture(n,{width:1,height:1,format:t}),this.defaultTexture[t]=e=n}return this.backend.get(e).texture}_getDefaultCubeTextureGPU(t){let e=this.defaultTexture[t];if(void 0===e){const n=new t_;n.minFilter=qd,n.magFilter=qd,this.createTexture(n,{width:1,height:1,depth:6}),this.defaultCubeTexture[t]=e=n}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,n,i){for(let r=0;r<6;r++){const s=t[r],a=!0===i?lL[r]:r;s.isDataTexture?this._copyBufferToTexture(s.image,e,n,a,i):this._copyImageToTexture(s,e,n,a,i)}}_copyImageToTexture(t,e,n,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,n,i)}_getPassUtils(){let t=this._passUtils;return null===t&&(this._passUtils=t=new aL(this.backend.device)),t}_generateMipmaps(t,e,n=0){this._getPassUtils().generateMipmaps(t,e,n)}_flipY(t,e,n=0){this._getPassUtils().flipY(t,e,n)}_copyBufferToTexture(t,e,n,i,r,s=0){const a=this.backend.device,o=t.data,l=this._getBytesPerTexel(n.format),h=t.width*l;a.queue.writeTexture({texture:e,mipLevel:0,origin:{x:0,y:0,z:i}},o,{offset:t.width*t.height*l*s,bytesPerRow:h},{width:t.width,height:t.height,depthOrArrayLayers:1}),!0===r&&this._flipY(e,n,i)}_copyCompressedBufferToTexture(t,e,n){const i=this.backend.device,r=this._getBlockData(n.format),s=n.size.depthOrArrayLayers>1;for(let a=0;a<t.length;a++){const o=t[a],l=o.width,h=o.height,u=s?n.size.depthOrArrayLayers:1,c=Math.ceil(l/r.width)*r.byteLength,d=c*Math.ceil(h/r.height);for(let t=0;t<u;t++)i.queue.writeTexture({texture:e,mipLevel:a,origin:{x:0,y:0,z:t}},o.data,{offset:t*d,bytesPerRow:c,rowsPerImage:Math.ceil(h/r.height)},{width:Math.ceil(l/r.width)*r.width,height:Math.ceil(h/r.height)*r.height,depthOrArrayLayers:1})}}_getBlockData(t){return t===$R.BC1RGBAUnorm||t===$R.BC1RGBAUnormSRGB?{byteLength:8,width:4,height:4}:t===$R.BC2RGBAUnorm||t===$R.BC2RGBAUnormSRGB||t===$R.BC3RGBAUnorm||t===$R.BC3RGBAUnormSRGB?{byteLength:16,width:4,height:4}:t===$R.BC4RUnorm||t===$R.BC4RSNorm?{byteLength:8,width:4,height:4}:t===$R.BC5RGUnorm||t===$R.BC5RGSnorm||t===$R.BC6HRGBUFloat||t===$R.BC6HRGBFloat||t===$R.BC7RGBAUnorm||t===$R.BC7RGBAUnormSRGB?{byteLength:16,width:4,height:4}:t===$R.ETC2RGB8Unorm||t===$R.ETC2RGB8UnormSRGB||t===$R.ETC2RGB8A1Unorm||t===$R.ETC2RGB8A1UnormSRGB?{byteLength:8,width:4,height:4}:t===$R.ETC2RGBA8Unorm||t===$R.ETC2RGBA8UnormSRGB?{byteLength:16,width:4,height:4}:t===$R.EACR11Unorm||t===$R.EACR11Snorm?{byteLength:8,width:4,height:4}:t===$R.EACRG11Unorm||t===$R.EACRG11Snorm||t===$R.ASTC4x4Unorm||t===$R.ASTC4x4UnormSRGB?{byteLength:16,width:4,height:4}:t===$R.ASTC5x4Unorm||t===$R.ASTC5x4UnormSRGB?{byteLength:16,width:5,height:4}:t===$R.ASTC5x5Unorm||t===$R.ASTC5x5UnormSRGB?{byteLength:16,width:5,height:5}:t===$R.ASTC6x5Unorm||t===$R.ASTC6x5UnormSRGB?{byteLength:16,width:6,height:5}:t===$R.ASTC6x6Unorm||t===$R.ASTC6x6UnormSRGB?{byteLength:16,width:6,height:6}:t===$R.ASTC8x5Unorm||t===$R.ASTC8x5UnormSRGB?{byteLength:16,width:8,height:5}:t===$R.ASTC8x6Unorm||t===$R.ASTC8x6UnormSRGB?{byteLength:16,width:8,height:6}:t===$R.ASTC8x8Unorm||t===$R.ASTC8x8UnormSRGB?{byteLength:16,width:8,height:8}:t===$R.ASTC10x5Unorm||t===$R.ASTC10x5UnormSRGB?{byteLength:16,width:10,height:5}:t===$R.ASTC10x6Unorm||t===$R.ASTC10x6UnormSRGB?{byteLength:16,width:10,height:6}:t===$R.ASTC10x8Unorm||t===$R.ASTC10x8UnormSRGB?{byteLength:16,width:10,height:8}:t===$R.ASTC10x10Unorm||t===$R.ASTC10x10UnormSRGB?{byteLength:16,width:10,height:10}:t===$R.ASTC12x10Unorm||t===$R.ASTC12x10UnormSRGB?{byteLength:16,width:12,height:10}:t===$R.ASTC12x12Unorm||t===$R.ASTC12x12UnormSRGB?{byteLength:16,width:12,height:12}:void 0}_convertAddressMode(t){let e=YR;return t===Hd?e=KR:t===Wd&&(e=ZR),e}_convertFilterMode(t){let e=QR;return t!==qd&&t!==Xd&&t!==$d||(e=JR),e}_getBytesPerTexel(t){return t===$R.R8Unorm||t===$R.R8Snorm||t===$R.R8Uint||t===$R.R8Sint?1:t===$R.R16Uint||t===$R.R16Sint||t===$R.R16Float||t===$R.RG8Unorm||t===$R.RG8Snorm||t===$R.RG8Uint||t===$R.RG8Sint?2:t===$R.R32Uint||t===$R.R32Sint||t===$R.R32Float||t===$R.RG16Uint||t===$R.RG16Sint||t===$R.RG16Float||t===$R.RGBA8Unorm||t===$R.RGBA8UnormSRGB||t===$R.RGBA8Snorm||t===$R.RGBA8Uint||t===$R.RGBA8Sint||t===$R.BGRA8Unorm||t===$R.BGRA8UnormSRGB||t===$R.RGB9E5UFloat||t===$R.RGB10A2Unorm||t===$R.RG11B10UFloat||t===$R.Depth32Float||t===$R.Depth24Plus||t===$R.Depth24PlusStencil8||t===$R.Depth32FloatStencil8?4:t===$R.RG32Uint||t===$R.RG32Sint||t===$R.RG32Float||t===$R.RGBA16Uint||t===$R.RGBA16Sint||t===$R.RGBA16Float?8:t===$R.RGBA32Uint||t===$R.RGBA32Sint||t===$R.RGBA32Float?16:void 0}_getTypedArrayType(t){return t===$R.R8Uint?Uint8Array:t===$R.R8Sint?Int8Array:t===$R.R8Unorm?Uint8Array:t===$R.R8Snorm?Int8Array:t===$R.RG8Uint?Uint8Array:t===$R.RG8Sint?Int8Array:t===$R.RG8Unorm?Uint8Array:t===$R.RG8Snorm?Int8Array:t===$R.RGBA8Uint?Uint8Array:t===$R.RGBA8Sint?Int8Array:t===$R.RGBA8Unorm?Uint8Array:t===$R.RGBA8Snorm?Int8Array:t===$R.R16Uint?Uint16Array:t===$R.R16Sint?Int16Array:t===$R.RG16Uint?Uint16Array:t===$R.RG16Sint?Int16Array:t===$R.RGBA16Uint?Uint16Array:t===$R.RGBA16Sint?Int16Array:t===$R.R16Float||t===$R.RG16Float||t===$R.RGBA16Float?Uint16Array:t===$R.R32Uint?Uint32Array:t===$R.R32Sint?Int32Array:t===$R.R32Float?Float32Array:t===$R.RG32Uint?Uint32Array:t===$R.RG32Sint?Int32Array:t===$R.RG32Float?Float32Array:t===$R.RGBA32Uint?Uint32Array:t===$R.RGBA32Sint?Int32Array:t===$R.RGBA32Float?Float32Array:t===$R.BGRA8Unorm||t===$R.BGRA8UnormSRGB?Uint8Array:t===$R.RGB10A2Unorm||t===$R.RGB9E5UFloat||t===$R.RG11B10UFloat?Uint32Array:t===$R.Depth32Float?Float32Array:t===$R.Depth24Plus||t===$R.Depth24PlusStencil8?Uint32Array:t===$R.Depth32FloatStencil8?Float32Array:void 0}_getDimension(t){let e;return e=t.isData3DTexture?BC:FC,e}}function uL(t,e=null){const n=t.format,i=t.type,r=t.colorSpace;let s;if(!0===t.isCompressedTexture||!0===t.isCompressedArrayTexture)switch(n){case _p:s=r===Bp?$R.BC1RGBAUnormSRGB:$R.BC1RGBAUnorm;break;case vp:s=r===Bp?$R.BC2RGBAUnormSRGB:$R.BC2RGBAUnorm;break;case yp:s=r===Bp?$R.BC3RGBAUnormSRGB:$R.BC3RGBAUnorm;break;case xp:s=r===Bp?$R.ETC2RGB8UnormSRGB:$R.ETC2RGB8Unorm;break;case bp:s=r===Bp?$R.ETC2RGBA8UnormSRGB:$R.ETC2RGBA8Unorm;break;case Sp:s=r===Bp?$R.ASTC4x4UnormSRGB:$R.ASTC4x4Unorm;break;case Mp:s=r===Bp?$R.ASTC5x4UnormSRGB:$R.ASTC5x4Unorm;break;case Tp:s=r===Bp?$R.ASTC5x5UnormSRGB:$R.ASTC5x5Unorm;break;case wp:s=r===Bp?$R.ASTC6x5UnormSRGB:$R.ASTC6x5Unorm;break;case Ep:s=r===Bp?$R.ASTC6x6UnormSRGB:$R.ASTC6x6Unorm;break;case Ap:s=r===Bp?$R.ASTC8x5UnormSRGB:$R.ASTC8x5Unorm;break;case Rp:s=r===Bp?$R.ASTC8x6UnormSRGB:$R.ASTC8x6Unorm;break;case Cp:s=r===Bp?$R.ASTC8x8UnormSRGB:$R.ASTC8x8Unorm;break;case Np:s=r===Bp?$R.ASTC10x5UnormSRGB:$R.ASTC10x5Unorm;break;case Pp:s=r===Bp?$R.ASTC10x6UnormSRGB:$R.ASTC10x6Unorm;break;case Ip:s=r===Bp?$R.ASTC10x8UnormSRGB:$R.ASTC10x8Unorm;break;case Lp:s=r===Bp?$R.ASTC10x10UnormSRGB:$R.ASTC10x10Unorm;break;case Up:s=r===Bp?$R.ASTC12x10UnormSRGB:$R.ASTC12x10Unorm;break;case Dp:s=r===Bp?$R.ASTC12x12UnormSRGB:$R.ASTC12x12Unorm;break;default:console.error("WebGPURenderer: Unsupported texture format.",n)}else switch(n){case lp:switch(i){case Jd:s=$R.RGBA8Snorm;break;case tp:s=$R.RGBA16Sint;break;case ep:s=$R.RGBA16Uint;break;case ip:s=$R.RGBA32Uint;break;case np:s=$R.RGBA32Sint;break;case Qd:s=r===Bp?$R.RGBA8UnormSRGB:$R.RGBA8Unorm;break;case sp:s=$R.RGBA16Float;break;case rp:s=$R.RGBA32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAFormat.",i)}break;case op:if(35902===i)s=$R.RGB9E5UFloat;else console.error("WebGPURenderer: Unsupported texture type with RGBFormat.",i);break;case cp:switch(i){case Jd:s=$R.R8Snorm;break;case tp:s=$R.R16Sint;break;case ep:s=$R.R16Uint;break;case ip:s=$R.R32Uint;break;case np:s=$R.R32Sint;break;case Qd:s=$R.R8Unorm;break;case sp:s=$R.R16Float;break;case rp:s=$R.R32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RedFormat.",i)}break;case pp:switch(i){case Jd:s=$R.RG8Snorm;break;case tp:s=$R.RG16Sint;break;case ep:s=$R.RG16Uint;break;case ip:s=$R.RG32Uint;break;case np:s=$R.RG32Sint;break;case Qd:s=$R.RG8Unorm;break;case sp:s=$R.RG16Float;break;case rp:s=$R.RG32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with RGFormat.",i)}break;case hp:switch(i){case ep:s=$R.Depth16Unorm;break;case ip:s=$R.Depth24Plus;break;case rp:s=$R.Depth32Float;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthFormat.",i)}break;case up:switch(i){case ap:s=$R.Depth24PlusStencil8;break;case rp:e&&!1===e.features.has(qC.Depth32FloatStencil8)&&console.error('WebGPURenderer: Depth textures with DepthStencilFormat + FloatType can only be used with the "depth32float-stencil8" GPU feature.'),s=$R.Depth32FloatStencil8;break;default:console.error("WebGPURenderer: Unsupported texture type with DepthStencilFormat.",i)}break;case dp:switch(i){case np:s=$R.R32Sint;break;case ip:s=$R.R32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RedIntegerFormat.",i)}break;case fp:switch(i){case np:s=$R.RG32Sint;break;case ip:s=$R.RG32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGIntegerFormat.",i)}break;case mp:switch(i){case np:s=$R.RGBA32Sint;break;case ip:s=$R.RGBA32Uint;break;default:console.error("WebGPURenderer: Unsupported texture type with RGBAIntegerFormat.",i)}break;default:console.error("WebGPURenderer: Unsupported texture format.",n)}return s}const cL=/^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/i,dL=/([a-z_0-9]+)\s*:\s*([a-z_0-9]+(?:<[\s\S]+?>)?)/gi,pL={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 fL extends YP{constructor(t){const{type:e,inputs:n,name:i,inputsCode:r,blockCode:s,outputType:a}=(t=>{const e=(t=t.trim()).match(cL);if(null!==e&&4===e.length){const n=e[2],i=[];let r=null;for(;null!==(r=dL.exec(n));)i.push({name:r[1],type:r[2]});const s=[];for(let t=0;t<i.length;t++){const{name:e,type:n}=i[t];let r=n;r.startsWith("ptr")?r="pointer":(r.startsWith("texture")&&(r=n.split("<")[0]),r=pL[r]),s.push(new FP(r,e))}const a=t.substring(e[0].length),o=e[3]||"void",l=void 0!==e[1]?e[1]:"";return{type:pL[o]||o,inputs:s,name:l,inputsCode:n,blockCode:a,outputType:o}}throw new Error("FunctionNode: Function is not a WGSL code.")})(t);super(e,n,i),this.inputsCode=r,this.blockCode=s,this.outputType=a}getCode(t=this.name){const e="void"!==this.outputType?"-> "+this.outputType:"";return`fn ${t} ( ${this.inputsCode.trim()} ) ${e}`+this.blockCode}}class mL extends $P{parseFunction(t){return new fL(t)}}const gL=self.GPUShaderStage,_L={vertex:gL?gL.VERTEX:1,fragment:gL?gL.FRAGMENT:2,compute:gL?gL.COMPUTE:4},vL={instance:!0,swizzleAssign:!1,storageBuffer:!0},yL={"^^":"tsl_xor"},xL={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>",mat3:"mat3x3<f32>",mat4:"mat4x4<f32>"},bL={tsl_xor:new oN("fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }"),mod_float:new oN("fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }"),mod_vec2:new oN("fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }"),mod_vec3:new oN("fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }"),mod_vec4:new oN("fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }"),equals_bool:new oN("fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }"),equals_bvec2:new oN("fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }"),equals_bvec3:new oN("fn tsl_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 oN("fn tsl_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 oN("\nfn tsl_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 oN("\nfn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {\n\n\tlet iRes = vec2i( textureDimensions( map, level ) );\n\tlet res = vec2f( iRes );\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 ) ) % iRes, level );\n\tlet rg2 = textureLoad( map, vec2i( iuv + vec2( 1.5, 0.5 ) ) % iRes, level );\n\tlet rg3 = textureLoad( map, vec2i( iuv + vec2( 0.5, 1.5 ) ) % iRes, level );\n\tlet rg4 = textureLoad( map, vec2i( iuv + vec2( 1.5, 1.5 ) ) % iRes, level );\n\n\treturn mix( mix( rg1, rg2, f.x ), mix( rg3, rg4, f.x ), f.y );\n\n}\n")},SL={dFdx:"dpdx",dFdy:"- dpdy",mod_float:"tsl_mod_float",mod_vec2:"tsl_mod_vec2",mod_vec3:"tsl_mod_vec3",mod_vec4:"tsl_mod_vec4",equals_bool:"tsl_equals_bool",equals_bvec2:"tsl_equals_bvec2",equals_bvec3:"tsl_equals_bvec3",equals_bvec4:"tsl_equals_bvec4",inversesqrt:"inverseSqrt",bitcast:"bitcast<f32>"};/Windows/g.test(navigator.userAgent)&&(bL.pow_float=new oN("fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }"),bL.pow_vec2=new oN("fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }",[bL.pow_float]),bL.pow_vec3=new oN("fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }",[bL.pow_float]),bL.pow_vec4=new oN("fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }",[bL.pow_float]),SL.pow_float="tsl_pow_float",SL.pow_vec2="tsl_pow_vec2",SL.pow_vec3="tsl_pow_vec3",SL.pow_vec4="tsl_pow_vec4");let ML="";!0!==/Firefox|Deno/g.test(navigator.userAgent)&&(ML+="diagnostic( off, derivative_uniformity );\n");class TL extends DP{constructor(t,e){super(t,e,new mL),this.uniformGroups={},this.builtins={},this.directives={},this.scopedArrays=new Map}needsToWorkingColorSpace(t){return!0===t.isVideoTexture&&t.colorSpace!==Fp}_generateTextureSample(t,e,n,i,r=this.shaderStage){return"fragment"===r?i?`textureSample( ${e}, ${e}_sampler, ${n}, ${i} )`:`textureSample( ${e}, ${e}_sampler, ${n} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,n):this.generateTextureLod(t,e,n,"0")}_generateVideoSample(t,e,n=this.shaderStage){if("fragment"===n)return`textureSampleBaseClampToEdge( ${t}, ${t}_sampler, vec2<f32>( ${e}.x, 1.0 - ${e}.y ) )`;console.error(`WebGPURenderer: THREE.VideoTexture does not support ${n} shader.`)}_generateTextureSampleLevel(t,e,n,i,r,s=this.shaderStage){return"fragment"===s&&!1===this.isUnfilterable(t)?`textureSampleLevel( ${e}, ${e}_sampler, ${n}, ${i} )`:this.isFilteredTexture(t)?this.generateFilteredTexture(t,e,n,i):this.generateTextureLod(t,e,n,i)}generateFilteredTexture(t,e,n,i="0"){return this._include("biquadraticTexture"),`tsl_biquadraticTexture( ${e}, ${n}, i32( ${i} ) )`}generateTextureLod(t,e,n,i="0"){this._include("repeatWrapping");return`textureLoad( ${e}, tsl_repeatWrapping( ${n}, ${!0===t.isMultisampleRenderTargetTexture?`textureDimensions( ${e} )`:`textureDimensions( ${e}, 0 )`} ), i32( ${i} ) )`}generateTextureLoad(t,e,n,i,r="0u"){return i?`textureLoad( ${e}, ${n}, ${i}, ${r} )`:`textureLoad( ${e}, ${n}, ${r} )`}generateTextureStore(t,e,n,i){return`textureStore( ${e}, ${n}, ${i} )`}isUnfilterable(t){return"float"!==this.getComponentTypeFromTexture(t)||!this.isAvailable("float32Filterable")&&!0===t.isDataTexture&&t.type===rp||!0===t.isMultisampleRenderTargetTexture}generateTexture(t,e,n,i,r=this.shaderStage){let s=null;return s=!0===t.isVideoTexture?this._generateVideoSample(e,n,r):this.isUnfilterable(t)?this.generateTextureLod(t,e,n,"0",i,r):this._generateTextureSample(t,e,n,i,r),s}generateTextureGrad(t,e,n,i,r,s=this.shaderStage){if("fragment"===s)return`textureSampleGrad( ${e}, ${e}_sampler, ${n}, ${i[0]}, ${i[1]} )`;console.error(`WebGPURenderer: THREE.TextureNode.gradient() does not support ${s} shader.`)}generateTextureCompare(t,e,n,i,r,s=this.shaderStage){if("fragment"===s)return`textureSampleCompare( ${e}, ${e}_sampler, ${n}, ${i} )`;console.error(`WebGPURenderer: THREE.DepthTexture.compareFunction() does not support ${s} shader.`)}generateTextureLevel(t,e,n,i,r,s=this.shaderStage){let a=null;return a=!0===t.isVideoTexture?this._generateVideoSample(e,n,s):this._generateTextureSampleLevel(t,e,n,i,r,s),a}generateTextureBias(t,e,n,i,r,s=this.shaderStage){if("fragment"===s)return`textureSampleBias( ${e}, ${e}_sampler, ${n}, ${i} )`;console.error(`WebGPURenderer: THREE.TextureNode.biasNode does not support ${s} 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,n=t.type;return"texture"===n||"cubeTexture"===n||"storageTexture"===n||"texture3D"===n?e:"buffer"===n||"storageBuffer"===n||"indirectStorageBuffer"===n?`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=yL[t];return void 0!==e?(this._include(e),e):null}getStorageAccess(t){if(t.isStorageTextureNode)switch(t.access){case PC:return"read";case NC:return"write";default:return"read_write"}else switch(t.access){case RC:return"read_write";case CC:return"read";default:return"write"}}getUniformFromNode(t,e,n,i=null){const r=super.getUniformFromNode(t,e,n,i),s=this.getDataFromNode(t,n,this.globalCache);if(void 0===s.uniformGPU){let i;const a=t.groupNode,o=a.name,l=this.getBindGroupArray(o,n);if("texture"===e||"cubeTexture"===e||"storageTexture"===e||"texture3D"===e){let s=null;if("texture"===e||"storageTexture"===e?s=new wI(r.name,r.node,a,t.access?t.access:null):"cubeTexture"===e?s=new EI(r.name,r.node,a,t.access?t.access:null):"texture3D"===e&&(s=new AI(r.name,r.node,a,t.access?t.access:null)),s.store=!0===t.isStorageTextureNode,s.setVisibility(_L[n]),"fragment"===n&&!1===this.isUnfilterable(t.value)&&!1===s.store){const t=new nL(`${r.name}_sampler`,r.node,a);t.setVisibility(_L[n]),l.push(t,s),i=[t,s]}else l.push(s),i=[s]}else if("buffer"===e||"storageBuffer"===e||"indirectStorageBuffer"===e){const r=new("buffer"===e?yI:sL)(t,a);r.setVisibility(_L[n]),l.push(r),i=r}else{const t=this.uniformGroups[n]||(this.uniformGroups[n]={});let s=t[o];void 0===s&&(s=new SI(o,a),s.setVisibility(_L[n]),t[o]=s,l.push(s)),i=this.getNodeUniform(r,e),s.addUniform(i)}s.uniformGPU=i}return r}getBuiltin(t,e,n,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:n}),e}hasBuiltin(t,e=this.shaderStage){return void 0!==this.builtins[e]&&this.builtins[e].has(t)}getVertexIndex(){return"vertex"===this.shaderStage?this.getBuiltin("vertex_index","vertexIndex","u32","attribute"):"vertexIndex"}buildFunctionCode(t){const e=t.layout,n=this.flowShaderNode(t),i=[];for(const t of e.inputs)i.push(t.name+" : "+this.getType(t.type));let r=`fn ${e.name}( ${i.join(", ")} ) -> ${this.getType(e.type)} {\n${n.vars}\n${n.code}\n`;return n.result&&(r+=`\treturn ${n.result};\n`),r+="\n}\n",r}getInstanceIndex(){return"vertex"===this.shaderStage?this.getBuiltin("instance_index","instanceIndex","u32","attribute"):"instanceIndex"}getInvocationLocalIndex(){return this.getBuiltin("local_invocation_index","invocationLocalIndex","u32","attribute")}getSubgroupSize(){return this.enableSubGroups(),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute")}getInvocationSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_invocation_id","invocationSubgroupIndex","u32","attribute")}getSubgroupIndex(){return this.enableSubGroups(),this.getBuiltin("subgroup_id","subgroupIndex","u32","attribute")}getDrawIndex(){return null}getFrontFacing(){return this.getBuiltin("front_facing","isFront","bool")}getFragCoord(){return this.getBuiltin("position","fragCoord","vec4<f32>")+".xy"}getFragDepth(){return"output."+this.getBuiltin("frag_depth","depth","f32","output")}isFlipY(){return!1}enableDirective(t,e=this.shaderStage){(this.directives[e]||(this.directives[e]=new Set)).add(t)}getDirectives(t){const e=[],n=this.directives[t];if(void 0!==n)for(const t of n)e.push(`enable ${t};`);return e.join("\n")}enableSubGroups(){this.enableDirective("subgroups")}enableSubgroupsF16(){this.enableDirective("subgroups-f16")}enableClipDistances(){this.enableDirective("clip_distances")}enableShaderF16(){this.enableDirective("f16")}enableDualSourceBlending(){this.enableDirective("dual_source_blending")}getBuiltins(t){const e=[],n=this.builtins[t];if(void 0!==n)for(const{name:t,property:i,type:r}of n.values())e.push(`@builtin( ${t} ) ${i} : ${r}`);return e.join(",\n\t")}getScopedArray(t,e,n,i){return!1===this.scopedArrays.has(t)&&this.scopedArrays.set(t,{name:t,scope:e,bufferType:n,bufferCount:i}),t}getScopedArrays(t){if("compute"!==t)return;const e=[];for(const{name:t,scope:n,bufferType:i,bufferCount:r}of this.scopedArrays.values()){const s=this.getType(i);e.push(`var<${n}> ${t}: array< ${s}, ${r} >;`)}return e.join("\n")}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"),this.renderer.hasFeature("subgroups")&&(this.enableDirective("subgroups",t),this.getBuiltin("subgroup_size","subgroupSize","u32","attribute"))),"vertex"===t||"compute"===t){const t=this.getBuiltins("attribute");t&&e.push(t);const n=this.getAttributesArray();for(let t=0,i=n.length;t<i;t++){const i=n[t],r=i.name,s=this.getType(i.type);e.push(`@location( ${t} ) ${r} : ${s}`)}}return e.join(",\n\t")}getStructMembers(t){const e=[],n=t.getMemberTypes();for(let t=0;t<n.length;t++){const i=n[t];e.push(`\t@location( ${t} ) m${t} : ${i}<f32>`)}const i=this.getBuiltins("output");return i&&e.push("\t"+i),e.join(",\n")}getStructs(t){const e=[],n=this.structs[t];for(let t=0,i=n.length;t<i;t++){const i=n[t],r=i.name;let s=`struct ${r} {\n`;s+=this.getStructMembers(i),s+="\n}",e.push(s),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=[],n=this.vars[t];if(void 0!==n)for(const t of n)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 n=this.varyings,i=this.vars[t];for(let r=0;r<n.length;r++){const s=n[r];if(s.needsInterpolation){let t=`@location( ${r} )`;/^(int|uint|ivec|uvec)/.test(s.type)&&(t+=" @interpolate( flat )"),e.push(`${t} ${s.name} : ${this.getType(s.type)}`)}else"vertex"===t&&!1===i.includes(s)&&i.push(s)}}const n=this.getBuiltins(t);n&&e.push(n);const i=e.join(",\n\t");return"vertex"===t?this._getWGSLStruct("VaryingsStruct","\t"+i):i}getUniforms(t){const e=this.uniforms[t],n=[],i=[],r=[],s={};for(const r of e){const e=r.groupNode.name,a=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?n.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var ${r.name}_sampler : sampler_comparison;`):n.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var ${r.name}_sampler : sampler;`));let s="";if(!0===e.isMultisampleRenderTargetTexture&&(s="_multisampled"),!0===e.isCubeTexture)i="texture_cube<f32>";else if(!0===e.isDataArrayTexture||!0===e.isCompressedArrayTexture)i="texture_2d_array<f32>";else if(!0===e.isDepthTexture)i=`texture_depth${s}_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<${uL(e)}, ${this.getStorageAccess(r.node)}>`}else{i=`texture${s}_2d<${this.getComponentTypeFromTexture(e).charAt(0)}32>`}n.push(`@binding( ${a.binding++} ) @group( ${a.group} ) var ${r.name} : ${i};`)}else if("buffer"===r.type||"storageBuffer"===r.type||"indirectStorageBuffer"===r.type){const t=r.node,e=this.getType(t.bufferType),n=t.bufferCount,s=n>0&&"buffer"===r.type?", "+n:"",o=t.isAtomic?`atomic<${e}>`:`${e}`,l=`\t${r.name} : array< ${o}${s} >\n`,h=t.isStorageBufferNode?`storage, ${this.getStorageAccess(t)}`:"uniform";i.push(this._getWGSLStructBinding("NodeBuffer_"+t.id,l,h,a.binding++,a.group))}else{const t=this.getType(this.getVectorType(r.type)),e=r.groupNode.name;(s[e]||(s[e]={index:a.binding++,id:a.group,snippets:[]})).snippets.push(`\t${r.name} : ${t}`)}}for(const t in s){const e=s[t];r.push(this._getWGSLStructBinding(t,e.snippets.join(",\n"),"uniform",e.index,e.id))}let a=n.join("\n");return a+=i.join("\n"),a+=r.join("\n"),a}buildCode(){const t=null!==this.material?{fragment:{},vertex:{}}:{compute:{}};this.sortBindingGroups();for(const e in t){const n=t[e];n.uniforms=this.getUniforms(e),n.attributes=this.getAttributes(e),n.varyings=this.getVaryings(e),n.structs=this.getStructs(e),n.vars=this.getVars(e),n.codes=this.getCodes(e),n.directives=this.getDirectives(e),n.scopedArrays=this.getScopedArrays(e);let i="// code\n\n";i+=this.flowCode[e];const r=this.flowNodes[e],s=r[r.length-1],a=s.outputNode,o=void 0!==a&&!0===a.isOutputStructNode;for(const t of r){const r=this.getFlowData(t),l=t.name;if(l&&(i.length>0&&(i+="\n"),i+=`\t// flow -> ${l}\n\t`),i+=`${r.code}\n\t`,t===s&&"compute"!==e)if(i+="// result\n\n\t","vertex"===e)i+=`varyings.Vertex = ${r.result};`;else if("fragment"===e)if(o)n.returnType=a.nodeType,i+=`return ${r.result};`;else{let t="\t@location(0) color: vec4<f32>";const e=this.getBuiltins("output");e&&(t+=",\n\t"+e),n.returnType="OutputStruct",n.structs+=this._getWGSLStruct("OutputStruct",t),n.structs+="\nvar<private> output : OutputStruct;\n\n",i+=`output.color = ${r.result};\n\n\treturn output;`}}n.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 n;return null!==e&&(n=this._getWGSLMethod(t+"_"+e)),void 0===n&&(n=this._getWGSLMethod(t)),n||t}getType(t){return xL[t]||t}isAvailable(t){let e=vL[t];return void 0===e&&("float32Filterable"===t&&(e=this.renderer.hasFeature("float32-filterable")),vL[t]=e),e}_getWGSLMethod(t){return void 0!==bL[t]&&this._include(t),SL[t]}_include(t){const e=bL[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// global\n${ML}\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// locals\n${t.scopedArrays}\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,n,i=0,r=0){const s=t+"Struct";return`${this._getWGSLStruct(s,e)}\n@binding( ${i} ) @group( ${r} )\nvar<${n}> ${t} : ${s};`}}class wL{constructor(t){this.backend=t}getCurrentDepthStencilFormat(t){let e;return null!==t.depthTexture?e=this.getTextureFormatGPU(t.depthTexture):t.depth&&t.stencil?e=$R.Depth24PlusStencil8:t.depth&&(e=$R.Depth24Plus),e}getTextureFormatGPU(t){return this.backend.get(t).format}getCurrentColorFormat(t){let e;return e=null!==t.textures?this.getTextureFormatGPU(t.textures[0]):this.getPreferredCanvasFormat(),e}getCurrentColorSpace(t){return null!==t.textures?t.textures[0].colorSpace:this.backend.renderer.outputColorSpace}getPrimitiveTopology(t,e){return t.isPoints?ER:t.isLineSegments||t.isMesh&&!0===e.wireframe?AR:t.isLine?RR:t.isMesh?CR: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)}getPreferredCanvasFormat(){return navigator.userAgent.includes("Quest")?$R.BGRA8Unorm:navigator.gpu.getPreferredCanvasFormat()}}const EL=new Map([[Int8Array,["sint8","snorm8"]],[Uint8Array,["uint8","unorm8"]],[Int16Array,["sint16","snorm16"]],[Uint16Array,["uint16","unorm16"]],[Int32Array,["sint32","snorm32"]],[Uint32Array,["uint32","unorm32"]],[Float32Array,["float32"]]]),AL=new Map([[bg,["float16"]]]),RL=new Map([[Int32Array,"sint32"],[Int16Array,"sint32"],[Uint32Array,"uint32"],[Uint16Array,"uint32"],[Float32Array,"float32"]]);class CL{constructor(t){this.backend=t}createAttribute(t,e){const n=this._getBufferAttribute(t),i=this.backend,r=i.get(n);let s=r.buffer;if(void 0===s){const a=i.device;let o=n.array;if(!1===t.normalized&&(o.constructor===Int16Array||o.constructor===Uint16Array)){const t=new Uint32Array(o.length);for(let e=0;e<o.length;e++)t[e]=o[e];o=t}if(n.array=o,(n.isStorageBufferAttribute||n.isStorageInstancedBufferAttribute)&&3===n.itemSize){o=new o.constructor(4*n.count);for(let t=0;t<n.count;t++)o.set(n.array.subarray(3*t,3*t+3),4*t);n.itemSize=4,n.array=o}const l=o.byteLength+(4-o.byteLength%4)%4;s=a.createBuffer({label:n.name,size:l,usage:e,mappedAtCreation:!0}),new o.constructor(s.getMappedRange()).set(o),s.unmap(),r.buffer=s}}updateAttribute(t){const e=this._getBufferAttribute(t),n=this.backend,i=n.device,r=n.get(e).buffer,s=e.array,a=e.updateRanges;if(0===a.length)i.queue.writeBuffer(r,0,s,0);else{for(let t=0,e=a.length;t<e;t++){const e=a[t];i.queue.writeBuffer(r,0,s,e.start*s.BYTES_PER_ELEMENT,e.count*s.BYTES_PER_ELEMENT)}e.clearUpdateRanges()}}createShaderVertexBuffers(t){const e=t.getAttributes(),n=new Map;for(let t=0;t<e.length;t++){const i=e[t],r=i.array.BYTES_PER_ELEMENT,s=this._getBufferAttribute(i);let a=n.get(s);if(void 0===a){let t,e;!0===i.isInterleavedBufferAttribute?(t=i.data.stride*r,e=i.data.isInstancedInterleavedBuffer?WC:jC):(t=i.itemSize*r,e=i.isInstancedBufferAttribute?WC:jC),!1!==i.normalized||i.array.constructor!==Int16Array&&i.array.constructor!==Uint16Array||(t=4),a={arrayStride:t,attributes:[],stepMode:e},n.set(s,a)}const o=this._getVertexFormat(i),l=!0===i.isInterleavedBufferAttribute?i.offset*r:0;a.attributes.push({shaderLocation:t,offset:l,format:o})}return Array.from(n.values())}destroyAttribute(t){const e=this.backend;e.get(this._getBufferAttribute(t)).buffer.destroy(),e.delete(t)}async getArrayBufferAsync(t){const e=this.backend,n=e.device,i=e.get(this._getBufferAttribute(t)).buffer,r=i.size,s=n.createBuffer({label:t.name,size:r,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ}),a=n.createCommandEncoder({});a.copyBufferToBuffer(i,0,s,0,r),s.unmap();const o=a.finish();n.queue.submit([o]),await s.mapAsync(GPUMapMode.READ);return s.getMappedRange()}_getVertexFormat(t){const{itemSize:e,normalized:n}=t,i=t.array.constructor,r=t.constructor;let s;if(1==e)s=RL.get(i);else{const t=(AL.get(r)||EL.get(i))[n?1:0];if(t){const n=i.BYTES_PER_ELEMENT*e,r=4*Math.floor((n+3)/4)/i.BYTES_PER_ELEMENT;if(r%1)throw new Error("THREE.WebGPUAttributeUtils: Bad vertex format item size.");s=`${t}x${r}`}}return s||console.error("THREE.WebGPUAttributeUtils: Vertex format not supported yet."),s}_getBufferAttribute(t){return t.isInterleavedBufferAttribute&&(t=t.data),t}}class NL{constructor(t){this.backend=t,this.bindGroupLayoutCache=new WeakMap}createBindingsLayout(t){const e=this.backend.device,n=[];let i=0;for(const e of t.bindings){const t={binding:i++,visibility:e.visibility};if(e.isUniformBuffer||e.isStorageBuffer){const n={};e.isStorageBuffer&&(n.type=e.access),t.buffer=n}else if(e.isSampler){const n={};e.texture.isDepthTexture&&null!==e.texture.compareFunction&&(n.type="comparison"),t.sampler=n}else if(e.isSampledTexture&&e.texture.isVideoTexture)t.externalTexture={};else if(e.isSampledTexture&&e.store){const n=this.backend.get(e.texture).texture.format,i=e.access;t.storageTexture={format:n,access:i}}else if(e.isSampledTexture){const n={};if(!0===e.texture.isMultisampleRenderTargetTexture&&(n.multisampled=!0),e.texture.isDepthTexture)n.sampleType=UC;else if(e.texture.isDataTexture||e.texture.isDataArrayTexture||e.texture.isData3DTexture){const t=e.texture.type;t===np?n.sampleType=DC:t===ip?n.sampleType=OC:t===rp&&(this.backend.hasFeature("float32-filterable")?n.sampleType=IC:n.sampleType=LC)}e.isSampledCubeTexture?n.viewDimension=GC:e.texture.isDataArrayTexture||e.texture.isCompressedArrayTexture?n.viewDimension=kC:e.isSampledTexture3D&&(n.viewDimension=VC),t.texture=n}else console.error(`WebGPUBindingUtils: Unsupported binding "${e}".`);n.push(t)}return e.createBindGroupLayout({entries:n})}createBindings(t){const{backend:e,bindGroupLayoutCache:n}=this,i=e.get(t);let r=n.get(t.bindingsReference);void 0===r&&(r=this.createBindingsLayout(t),n.set(t.bindingsReference,r));const s=this.createBindGroup(t,r);i.layout=r,i.group=s}updateBinding(t){const e=this.backend,n=e.device,i=t.buffer,r=e.get(t).buffer;n.queue.writeBuffer(r,0,i,0)}createBindGroup(t,e){const n=this.backend,i=n.device;let r=0;const s=[];for(const e of t.bindings){if(e.isUniformBuffer){const t=n.get(e);if(void 0===t.buffer){const n=e.byteLength,r=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,s=i.createBuffer({label:"bindingBuffer_"+e.name,size:n,usage:r});t.buffer=s}s.push({binding:r,resource:{buffer:t.buffer}})}else if(e.isStorageBuffer){const t=n.get(e);if(void 0===t.buffer){const i=e.attribute;t.buffer=n.get(i).buffer}s.push({binding:r,resource:{buffer:t.buffer}})}else if(e.isSampler){const t=n.get(e.texture);s.push({binding:r,resource:t.sampler})}else if(e.isSampledTexture){const t=n.get(e.texture);let a;if(void 0!==t.externalTexture)a=i.importExternalTexture({source:t.externalTexture});else{const n=e.store?1:t.texture.mipLevelCount,i=`view-${t.texture.width}-${t.texture.height}-${n}`;if(a=t[i],void 0===a){const r=HC;let s;s=e.isSampledCubeTexture?GC:e.isSampledTexture3D?VC:e.texture.isDataArrayTexture||e.texture.isCompressedArrayTexture?kC:zC,a=t[i]=t.texture.createView({aspect:r,dimension:s,mipLevelCount:n})}}s.push({binding:r,resource:a})}r++}return i.createBindGroup({label:"bindGroup_"+t.name,layout:e,entries:s})}}class PL{constructor(t){this.backend=t}_getSampleCount(t){return this.backend.utils.getSampleCountRenderContext(t)}createRenderPipeline(t,e){const{object:n,material:i,geometry:r,pipeline:s}=t,{vertexProgram:a,fragmentProgram:o}=s,l=this.backend,h=l.device,u=l.utils,c=l.get(s),d=[];for(const e of t.getBindings()){const t=l.get(e);d.push(t.layout)}const p=l.attributeUtils.createShaderVertexBuffers(t);let f;!0===i.transparent&&0!==i.blending&&(f=this._getBlending(i));let m={};!0===i.stencilWrite&&(m={compare:this._getStencilCompare(i),failOp:this._getStencilOperation(i.stencilFail),depthFailOp:this._getStencilOperation(i.stencilZFail),passOp:this._getStencilOperation(i.stencilZPass)});const g=this._getColorWriteMask(i),_=[];if(null!==t.context.textures){const e=t.context.textures;for(let t=0;t<e.length;t++){const n=u.getTextureFormatGPU(e[t]);_.push({format:n,blend:f,writeMask:g})}}else{const e=u.getCurrentColorFormat(t.context);_.push({format:e,blend:f,writeMask:g})}const v=l.get(a).module,y=l.get(o).module,x=this._getPrimitiveState(n,r,i),b=this._getDepthCompare(i),S=u.getCurrentDepthStencilFormat(t.context),M=this._getSampleCount(t.context),T={label:`renderPipeline_${i.name||i.type}_${i.id}`,vertex:Object.assign({},v,{buffers:p}),fragment:Object.assign({},y,{targets:_}),primitive:x,multisample:{count:M,alphaToCoverageEnabled:i.alphaToCoverage&&M>1},layout:h.createPipelineLayout({bindGroupLayouts:d})},w={},E=t.context.depth,A=t.context.stencil;if(!0!==E&&!0!==A||(!0===E&&(w.format=S,w.depthWriteEnabled=i.depthWrite,w.depthCompare=b),!0===A&&(w.stencilFront=m,w.stencilBack={},w.stencilReadMask=i.stencilFuncMask,w.stencilWriteMask=i.stencilWriteMask),T.depthStencil=w),null===e)c.pipeline=h.createRenderPipeline(T);else{const t=new Promise((t=>{h.createRenderPipelineAsync(T).then((e=>{c.pipeline=e,t()}))}));e.push(t)}}createBundleEncoder(t){const e=this.backend,{utils:n,device:i}=e,r=n.getCurrentDepthStencilFormat(t),s={label:"renderBundleEncoder",colorFormats:[n.getCurrentColorFormat(t)],depthStencilFormat:r,sampleCount:this._getSampleCount(t)};return i.createRenderBundleEncoder(s)}createComputePipeline(t,e){const n=this.backend,i=n.device,r=n.get(t.computeProgram).module,s=n.get(t),a=[];for(const t of e){const e=n.get(t);a.push(e.layout)}s.pipeline=i.createComputePipeline({compute:r,layout:i.createPipelineLayout({bindGroupLayouts:a})})}_getBlending(t){let e,n;const i=t.blending,r=t.blendSrc,s=t.blendDst,a=t.blendEquation;if(5===i){const i=null!==t.blendSrcAlpha?t.blendSrcAlpha:r,o=null!==t.blendDstAlpha?t.blendDstAlpha:s,l=null!==t.blendEquationAlpha?t.blendEquationAlpha:a;e={srcFactor:this._getBlendFactor(r),dstFactor:this._getBlendFactor(s),operation:this._getBlendOperation(a)},n={srcFactor:this._getBlendFactor(i),dstFactor:this._getBlendFactor(o),operation:this._getBlendOperation(l)}}else{const r=(t,i,r,s)=>{e={srcFactor:t,dstFactor:i,operation:pC},n={srcFactor:r,dstFactor:s,operation:pC}};if(t.premultipliedAlpha)switch(i){case 1:r(eC,sC,eC,sC);break;case 2:r(eC,eC,eC,eC);break;case 3:r(tC,iC,tC,eC);break;case 4:r(tC,nC,tC,rC)}else switch(i){case 1:r(rC,sC,eC,sC);break;case 2:r(rC,eC,rC,eC);break;case 3:r(tC,iC,tC,eC);break;case 4:r(tC,nC,tC,nC)}}if(void 0!==e&&void 0!==n)return{color:e,alpha:n};console.error("THREE.WebGPURenderer: Invalid blending: ",i)}_getBlendFactor(t){let e;switch(t){case 200:e=tC;break;case 201:e=eC;break;case 202:e=nC;break;case 203:e=iC;break;case Id:e=rC;break;case Ld:e=sC;break;case 208:e=aC;break;case 209:e=oC;break;case 206:e=lC;break;case 207:e=hC;break;case 210:e=uC;break;case 211:e=cC;break;case 212:e=dC;break;default:console.error("THREE.WebGPURenderer: Blend factor not supported.",t)}return e}_getStencilCompare(t){let e;const n=t.stencilFunc;switch(n){case 512:e=PR;break;case 519:e=BR;break;case 513:e=IR;break;case 515:e=UR;break;case 514:e=LR;break;case 518:e=FR;break;case 516:e=DR;break;case 517:e=OR;break;default:console.error("THREE.WebGPURenderer: Invalid stencil function.",n)}return e}_getStencilOperation(t){let e;switch(t){case Vp:e=xC;break;case 0:e=bC;break;case 7681:e=SC;break;case 5386:e=MC;break;case 7682:e=TC;break;case 7683:e=wC;break;case 34055:e=EC;break;case 34056:e=AC;break;default:console.error("THREE.WebGPURenderer: Invalid stencil operation.",e)}return e}_getBlendOperation(t){let e;switch(t){case wd:e=pC;break;case 101:e=fC;break;case 102:e=mC;break;case 103:e=gC;break;case 104:e=_C;break;default:console.error("THREE.WebGPUPipelineUtils: Blend equation not supported.",t)}return e}_getPrimitiveState(t,e,n){const i={},r=this.backend.utils;switch(i.topology=r.getPrimitiveTopology(t,n),null!==e.index&&!0===t.isLine&&!0!==t.isLineSegments&&(i.stripIndexFormat=e.index.array instanceof Uint16Array?qR:XR),n.side){case 0:i.frontFace=VR,i.cullMode=WR;break;case 1:i.frontFace=VR,i.cullMode=jR;break;case 2:i.frontFace=VR,i.cullMode=HR;break;default:console.error("THREE.WebGPUPipelineUtils: Unknown material.side value.",n.side)}return i}_getColorWriteMask(t){return!0===t.colorWrite?yC:vC}_getDepthCompare(t){let e;if(!1===t.depthTest)e=BR;else{const n=t.depthFunc;switch(n){case 0:e=PR;break;case 1:e=BR;break;case 2:e=IR;break;case 3:e=UR;break;case 4:e=LR;break;case 5:e=FR;break;case 6:e=DR;break;case 7:e=OR;break;default:console.error("THREE.WebGPUPipelineUtils: Invalid depth function.",n)}}return e}}class IL extends OI{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 wL(this),this.attributeUtils=new CL(this),this.bindingUtils=new NL(this),this.pipelineUtils=new PL(this),this.textureUtils=new hL(this),this.occludedResolveCache=new Map}async init(t){await super.init(t);const e=this.parameters;let n;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(qC),s=[];for(const t of r)i.features.has(t)&&s.push(t);const a={requiredFeatures:s,requiredLimits:e.requiredLimits};n=await i.requestDevice(a)}else n=e.device;n.lost.then((e=>{const n={api:"WebGPU",message:e.message||"Unknown reason",reason:e.reason||null,originalEvent:e};t.onDeviceLost(n)}));const i=void 0!==e.context?e.context:t.domElement.getContext("webgpu");this.device=n,this.context=i;const r=e.alpha?"premultiplied":"opaque";this.trackTimestamp=this.trackTimestamp&&this.hasFeature(qC.TimestampQuery),this.context.configure({device:this.device,format:this.utils.getPreferredCanvasFormat(),usage:GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,alphaMode:r}),this.updateSize()}get coordinateSystem(){return tf}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}]},!0!==this.renderer.depth&&!0!==this.renderer.stencil||(t.depthStencilAttachment={view:this.textureUtils.getDepthBuffer(e.depth,e.stencil).createView()});const n=t.colorAttachments[0];this.renderer.samples>0?n.view=this.colorBuffer.createView():n.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,n=this.get(e);let i=n.descriptors;if(void 0===i||n.width!==e.width||n.height!==e.height||n.activeMipmapLevel!==e.activeMipmapLevel||n.samples!==e.samples){i={},n.descriptors=i;const t=()=>{e.removeEventListener("dispose",t),this.delete(e)};e.addEventListener("dispose",t)}const r=t.getCacheKey();let s=i[r];if(void 0===s){const a=t.textures,o=[];for(let e=0;e<a.length;e++){const n=this.get(a[e]),i=n.texture.createView({baseMipLevel:t.activeMipmapLevel,mipLevelCount:1,baseArrayLayer:t.activeCubeFace,dimension:zC});let r,s;void 0!==n.msaaTexture?(r=n.msaaTexture.createView(),s=i):(r=i,s=void 0),o.push({view:r,resolveTarget:s,loadOp:kR,storeOp:zR})}if(s={colorAttachments:o},t.depth){const e={view:this.get(t.depthTexture).texture.createView()};s.depthStencilAttachment=e}i[r]=s,n.width=e.width,n.height=e.height,n.samples=e.samples,n.activeMipmapLevel=e.activeMipmapLevel}return s}beginRender(t){const e=this.get(t),n=this.device,i=t.occlusionQueryCount;let r,s;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=n.createQuerySet({type:"occlusion",count:i}),e.occlusionQuerySet=r,e.occlusionQueryIndex=0,e.occlusionQueryObjects=new Array(i),e.lastOcclusionObject=null),s=null===t.textures?this._getDefaultRenderPassDescriptor():this._getRenderPassDescriptor(t),this.initTimestampQuery(t,s),s.occlusionQuerySet=r;const a=s.depthStencilAttachment;if(null!==t.textures){const e=s.colorAttachments;for(let n=0;n<e.length;n++){const i=e[n];t.clearColor?(i.clearValue=0===n?t.clearColorValue:{r:0,g:0,b:0,a:1},i.loadOp=GR,i.storeOp=zR):(i.loadOp=kR,i.storeOp=zR)}}else{const e=s.colorAttachments[0];t.clearColor?(e.clearValue=t.clearColorValue,e.loadOp=GR,e.storeOp=zR):(e.loadOp=kR,e.storeOp=zR)}t.depth&&(t.clearDepth?(a.depthClearValue=t.clearDepthValue,a.depthLoadOp=GR,a.depthStoreOp=zR):(a.depthLoadOp=kR,a.depthStoreOp=zR)),t.stencil&&(t.clearStencil?(a.stencilClearValue=t.clearStencilValue,a.stencilLoadOp=GR,a.stencilStoreOp=zR):(a.stencilLoadOp=kR,a.stencilStoreOp=zR));const o=n.createCommandEncoder({label:"renderContext_"+t.id}),l=o.beginRenderPass(s);if(e.descriptor=s,e.encoder=o,e.currentPass=l,e.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},e.renderBundles=[],t.viewport&&this.updateViewport(t),t.scissor){const{x:e,y:n,width:i,height:r}=t.scissorValue;l.setScissorRect(e,n,i,r)}}finishRender(t){const e=this.get(t),n=t.occlusionQueryCount;if(e.renderBundles.length>0&&e.currentPass.executeBundles(e.renderBundles),n>e.occlusionQueryIndex&&e.currentPass.endOcclusionQuery(),e.currentPass.end(),n>0){const i=8*n;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 s=this.device.createBuffer({size:i,usage:GPUBufferUsage.COPY_DST|GPUBufferUsage.MAP_READ});e.encoder.resolveQuerySet(e.occlusionQuerySet,0,n,r,0),e.encoder.copyBufferToBuffer(r,0,s,0,i),e.occlusionQueryBuffer=s,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 n=e[t];!0===n.generateMipmaps&&this.textureUtils.generateMipmaps(n)}}}isOccluded(t,e){const n=this.get(t);return n.occluded&&n.occluded.has(e)}async resolveOccludedAsync(t){const e=this.get(t),{currentOcclusionQueryBuffer:n,currentOcclusionQueryObjects:i}=e;if(n&&i){const t=new WeakSet;e.currentOcclusionQueryObjects=null,e.currentOcclusionQueryBuffer=null,await n.mapAsync(GPUMapMode.READ);const r=n.getMappedRange(),s=new BigUint64Array(r);for(let e=0;e<i.length;e++)s[e]!==BigInt(0)&&t.add(i[e]);n.destroy(),e.occluded=t}}updateViewport(t){const{currentPass:e}=this.get(t),{x:n,y:i,width:r,height:s,minDepth:a,maxDepth:o}=t.viewportValue;e.setViewport(n,i,r,s,a,o)}clear(t,e,n,i=null){const r=this.device,s=this.renderer;let a,o,l,h,u=[];if(t){const t=this.getClearColor();if(!0===this.renderer.alpha){const e=t.a;o={r:t.r*e,g:t.g*e,b:t.b*e,a:e}}else o={r:t.r,g:t.g,b:t.b,a:t.a}}if(null===i){l=s.depth,h=s.stencil;const e=this._getDefaultRenderPassDescriptor();if(t){u=e.colorAttachments;const t=u[0];t.clearValue=o,t.loadOp=GR,t.storeOp=zR}(l||h)&&(a=e.depthStencilAttachment)}else{if(l=i.depth,h=i.stencil,t)for(const t of i.textures){const e=this.get(t),n=e.texture.createView();let i,r;void 0!==e.msaaTexture?(i=e.msaaTexture.createView(),r=n):(i=n,r=void 0),u.push({view:i,resolveTarget:r,clearValue:o,loadOp:GR,storeOp:zR})}if(l||h){a={view:this.get(i.depthTexture).texture.createView()}}}l&&(e?(a.depthLoadOp=GR,a.depthClearValue=s.getClearDepth(),a.depthStoreOp=zR):(a.depthLoadOp=kR,a.depthStoreOp=zR)),h&&(n?(a.stencilLoadOp=GR,a.stencilClearValue=s.getClearStencil(),a.stencilStoreOp=zR):(a.stencilLoadOp=kR,a.stencilStoreOp=zR));const c=r.createCommandEncoder({});c.beginRenderPass({colorAttachments:u,depthStencilAttachment:a}).end(),r.queue.submit([c.finish()])}beginCompute(t){const e=this.get(t),n={};this.initTimestampQuery(t,n),e.cmdEncoderGPU=this.device.createCommandEncoder(),e.passEncoderGPU=e.cmdEncoderGPU.beginComputePass(n)}compute(t,e,n,i){const{passEncoderGPU:r}=this.get(t),s=this.get(i).pipeline;r.setPipeline(s);for(let t=0,e=n.length;t<e;t++){const e=n[t],i=this.get(e);r.setBindGroup(t,i.group)}const a=this.device.limits.maxComputeWorkgroupsPerDimension,o=this.get(e);void 0===o.dispatchSize&&(o.dispatchSize={x:0,y:1,z:1});const{dispatchSize:l}=o;e.dispatchCount>a?(l.x=Math.min(e.dispatchCount,a),l.y=Math.ceil(e.dispatchCount/a)):l.x=e.dispatchCount,r.dispatchWorkgroups(l.x,l.y,l.z)}finishCompute(t){const e=this.get(t);e.passEncoderGPU.end(),this.prepareTimestampBuffer(t,e.cmdEncoderGPU),this.device.queue.submit([e.cmdEncoderGPU.finish()])}async waitForGPU(){await this.device.queue.onSubmittedWorkDone()}draw(t,e){const{object:n,context:i,pipeline:r}=t,s=t.getBindings(),a=this.get(i),o=this.get(r).pipeline,l=a.currentSets,h=a.currentPass,u=t.getDrawParameters();if(null===u)return;l.pipeline!==o&&(h.setPipeline(o),l.pipeline=o);const c=l.bindingGroups;for(let t=0,e=s.length;t<e;t++){const e=s[t],n=this.get(e);c[e.index]!==e.id&&(h.setBindGroup(e.index,n.group),c[e.index]=e.id)}const d=t.getIndex(),p=null!==d;if(!0===p&&l.index!==d){const t=this.get(d).buffer,e=d.array instanceof Uint16Array?qR:XR;h.setIndexBuffer(t,e),l.index=d}const f=t.getVertexBuffers();for(let t=0,e=f.length;t<e;t++){const e=f[t];if(l.attributes[t]!==e){const n=this.get(e).buffer;h.setVertexBuffer(t,n),l.attributes[t]=e}}if(void 0!==a.occlusionQuerySet){const t=a.lastOcclusionObject;t!==n&&(null!==t&&!0===t.occlusionTest&&(h.endOcclusionQuery(),a.occlusionQueryIndex++),!0===n.occlusionTest&&(h.beginOcclusionQuery(a.occlusionQueryIndex),a.occlusionQueryObjects[a.occlusionQueryIndex]=n),a.lastOcclusionObject=n)}if(!0===n.isBatchedMesh){const t=n._multiDrawStarts,e=n._multiDrawCounts,i=n._multiDrawCount,r=n._multiDrawInstances,s=p?d.array.BYTES_PER_ELEMENT:1;for(let n=0;n<i;n++){const i=r?r[n]:1,a=i>1?0:n;h.drawIndexed(e[n],i,t[n]/s,0,a)}}else if(!0===p){const{vertexCount:i,instanceCount:r,firstVertex:s}=u,a=t.getIndirect();if(null!==a){const t=this.get(a).buffer;h.drawIndexedIndirect(t,0)}else h.drawIndexed(i,r,s,0,0);e.update(n,i,r)}else{const{vertexCount:i,instanceCount:r,firstVertex:s}=u,a=t.getIndirect();if(null!==a){const t=this.get(a).buffer;h.drawIndirect(t,0)}else h.draw(i,r,s,0);e.update(n,i,r)}}needsRenderUpdate(t){const e=this.get(t),{object:n,material:i}=t,r=this.utils,s=r.getSampleCountRenderContext(t.context),a=r.getCurrentColorSpace(t.context),o=r.getCurrentColorFormat(t.context),l=r.getCurrentDepthStencilFormat(t.context),h=r.getPrimitiveTopology(n,i);let u=!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===s&&e.colorSpace===a&&e.colorFormat===o&&e.depthStencilFormat===l&&e.primitiveTopology===h&&e.clippingContextCacheKey===t.clippingContext.cacheKey||(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=s,e.colorSpace=a,e.colorFormat=o,e.depthStencilFormat=l,e.primitiveTopology=h,e.clippingContextCacheKey=t.clippingContext.cacheKey,u=!0),u}getRenderCacheKey(t){const{object:e,material:n}=t,i=this.utils,r=t.context;return[n.transparent,n.blending,n.premultipliedAlpha,n.blendSrc,n.blendDst,n.blendEquation,n.blendSrcAlpha,n.blendDstAlpha,n.blendEquationAlpha,n.colorWrite,n.depthWrite,n.depthTest,n.depthFunc,n.stencilWrite,n.stencilFunc,n.stencilFail,n.stencilZFail,n.stencilZPass,n.stencilFuncMask,n.stencilWriteMask,n.side,i.getSampleCountRenderContext(r),i.getCurrentColorSpace(r),i.getCurrentColorFormat(r),i.getCurrentDepthStencilFormat(r),i.getPrimitiveTopology(e,n),t.getGeometryCacheKey(),t.clippingContext.cacheKey].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,n,i,r,s){return this.textureUtils.copyTextureToBuffer(t,e,n,i,r,s)}initTimestampQuery(t,e){if(!this.trackTimestamp)return;const n=this.get(t);if(!n.timeStampQuerySet){const t=this.device.createQuerySet({type:"timestamp",count:2}),i={querySet:t,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1};Object.assign(e,{timestampWrites:i}),n.timeStampQuerySet=t}}prepareTimestampBuffer(t,e){if(!this.trackTimestamp)return;const n=this.get(t),i=2*BigInt64Array.BYTES_PER_ELEMENT;void 0===n.currentTimestampQueryBuffers&&(n.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:s,isMappingPending:a}=n.currentTimestampQueryBuffers;!0!==a&&(e.resolveQuerySet(n.timeStampQuerySet,0,2,r,0),e.copyBufferToBuffer(r,0,s,0,i))}async resolveTimestampAsync(t,e="render"){if(!this.trackTimestamp)return;const n=this.get(t);if(void 0===n.currentTimestampQueryBuffers)return;const{resultBuffer:i,isMappingPending:r}=n.currentTimestampQueryBuffers;!0!==r&&(n.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(),n.currentTimestampQueryBuffers.isMappingPending=!1})))}createNodeBuilder(t,e){return new TL(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)}beginBundle(t){const e=this.get(t);e._currentPass=e.currentPass,e._currentSets=e.currentSets,e.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null},e.currentPass=this.pipelineUtils.createBundleEncoder(t)}finishBundle(t,e){const n=this.get(t),i=n.currentPass.finish();this.get(e).bundleGPU=i,n.currentSets=n._currentSets,n.currentPass=n._currentPass}addBundle(t,e){this.get(t).renderBundles.push(this.get(e).bundleGPU)}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)}createIndirectStorageAttribute(t){this.attributeUtils.createAttribute(t,GPUBufferUsage.STORAGE|GPUBufferUsage.INDIRECT|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,n=null,i=null,r=0){let s=0,a=0,o=0,l=0,h=0,u=0,c=t.image.width,d=t.image.height;null!==n&&(l=n.x,h=n.y,u=n.z||0,c=n.width,d=n.height),null!==i&&(s=i.x,a=i.y,o=i.z||0);const p=this.device.createCommandEncoder({label:"copyTextureToTexture_"+t.id+"_"+e.id}),f=this.get(t).texture,m=this.get(e).texture;p.copyTextureToTexture({texture:f,mipLevel:r,origin:{x:l,y:h,z:u}},{texture:m,mipLevel:r,origin:{x:s,y:a,z:o}},[c,d,1]),this.device.queue.submit([p.finish()])}copyFramebufferToTexture(t,e,n){const i=this.get(e);let r=null;r=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 s=this.get(t).texture;if(r.format!==s.format)return void console.error("WebGPUBackend: copyFramebufferToTexture: Source and destination formats do not match.",r.format,s.format);let a;if(i.currentPass?(i.currentPass.end(),a=i.encoder):a=this.device.createCommandEncoder({label:"copyFramebufferToTexture_"+t.id}),a.copyTextureToTexture({texture:r,origin:{x:n.x,y:n.y,z:0}},{texture:s},[n.z,n.w]),t.generateMipmaps&&this.textureUtils.generateMipmaps(t),i.currentPass){const{descriptor:t}=i;for(let e=0;e<t.colorAttachments.length;e++)t.colorAttachments[e].loadOp=kR;e.depth&&(t.depthStencilAttachment.depthLoadOp=kR),e.stencil&&(t.depthStencilAttachment.stencilLoadOp=kR),i.currentPass=a.beginRenderPass(t),i.currentSets={attributes:{},bindingGroups:[],pipeline:null,index:null}}else this.device.queue.submit([a.finish()])}}class LL extends F_{constructor(t,e,n,i,r,s){super(t,e,n,i,r,s),this.iesMap=null}copy(t,e){return super.copy(t,e),this.iesMap=t.iesMap,this}}class UL extends sI{constructor(){super(),this.addMaterial(Vw,T_),this.addMaterial(lA,S_),this.addMaterial(uA,M_),this.addMaterial(fA,w_),this.addMaterial(Lw,cg),this.addMaterial(kw,A_),this.addMaterial(yw,E_),this.addMaterial(vA,R_),this.addMaterial(mw,g_),this.addMaterial(_w,C_),this.addMaterial(xA,__),this.addMaterial(TA,a_),this.addMaterial(AA,b_),this.addLight(ON,V_),this.addLight(BP,W_),this.addLight(VP,X_),this.addLight(HP,F_),this.addLight(WP,q_),this.addLight(qP,P_),this.addLight(XP,Y_),this.addLight(jP,LL),this.addToneMapping(ZC,1),this.addToneMapping(QC,2),this.addToneMapping(JC,3),this.addToneMapping(eN,4),this.addToneMapping(sN,6),this.addToneMapping(aN,7)}}class DL extends fI{constructor(t={}){let e;t.forceWebGL?e=tL:(e=IL,t.getFallback=()=>(console.warn("THREE.WebGPURenderer: WebGPU is not available, running under WebGL2 backend."),new tL(t)));super(new e(t),t),this.library=new UL,this.isWebGPURenderer=!0}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:Td}})),"undefined"!=typeof window&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=Td);const OL={type:"change"},FL={type:"start"},BL={type:"end"},zL=1e-6,kL=-1,GL=0,VL=1,HL=2,jL=3,WL=4,qL=new Se,XL=new Se,$L=new Ze,YL=new Ze,KL=new Ze,ZL=new Ke,QL=new Ze,JL=new Ze,tU=new Ze,eU=new Ze;class nU extends nl{constructor(t,e=null){super(t,e),this.enabled=!0,this.screen={left:0,top:0,width:0,height:0},this.rotateSpeed=1,this.zoomSpeed=1.2,this.panSpeed=.3,this.noRotate=!1,this.noZoom=!1,this.noPan=!1,this.staticMoving=!1,this.dynamicDampingFactor=.2,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.keys=["KeyA","KeyS","KeyD"],this.mouseButtons={LEFT:a.ROTATE,MIDDLE:a.DOLLY,RIGHT:a.PAN},this.state=kL,this.keyState=kL,this.target=new Ze,this._lastPosition=new Ze,this._lastZoom=1,this._touchZoomDistanceStart=0,this._touchZoomDistanceEnd=0,this._lastAngle=0,this._eye=new Ze,this._movePrev=new Se,this._moveCurr=new Se,this._lastAxis=new Ze,this._zoomStart=new Se,this._zoomEnd=new Se,this._panStart=new Se,this._panEnd=new Se,this._pointers=[],this._pointerPositions={},this._onPointerMove=rU.bind(this),this._onPointerDown=iU.bind(this),this._onPointerUp=sU.bind(this),this._onPointerCancel=aU.bind(this),this._onContextMenu=pU.bind(this),this._onMouseWheel=dU.bind(this),this._onKeyDown=lU.bind(this),this._onKeyUp=oU.bind(this),this._onTouchStart=fU.bind(this),this._onTouchMove=mU.bind(this),this._onTouchEnd=gU.bind(this),this._onMouseDown=hU.bind(this),this._onMouseMove=uU.bind(this),this._onMouseUp=cU.bind(this),this._target0=this.target.clone(),this._position0=this.object.position.clone(),this._up0=this.object.up.clone(),this._zoom0=this.object.zoom,null!==e&&(this.connect(),this.handleResize()),this.update()}connect(){window.addEventListener("keydown",this._onKeyDown),window.addEventListener("keyup",this._onKeyUp),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerCancel),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="none"}disconnect(){window.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("keyup",this._onKeyUp),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerCancel),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}handleResize(){const t=this.domElement.getBoundingClientRect(),e=this.domElement.ownerDocument.documentElement;this.screen.left=t.left+window.pageXOffset-e.clientLeft,this.screen.top=t.top+window.pageYOffset-e.clientTop,this.screen.width=t.width,this.screen.height=t.height}update(){this._eye.subVectors(this.object.position,this.target),this.noRotate||this._rotateCamera(),this.noZoom||this._zoomCamera(),this.noPan||this._panCamera(),this.object.position.addVectors(this.target,this._eye),this.object.isPerspectiveCamera?(this._checkDistances(),this.object.lookAt(this.target),this._lastPosition.distanceToSquared(this.object.position)>zL&&(this.dispatchEvent(OL),this._lastPosition.copy(this.object.position))):this.object.isOrthographicCamera?(this.object.lookAt(this.target),(this._lastPosition.distanceToSquared(this.object.position)>zL||this._lastZoom!==this.object.zoom)&&(this.dispatchEvent(OL),this._lastPosition.copy(this.object.position),this._lastZoom=this.object.zoom)):console.warn("THREE.TrackballControls: Unsupported camera type.")}reset(){this.state=kL,this.keyState=kL,this.target.copy(this._target0),this.object.position.copy(this._position0),this.object.up.copy(this._up0),this.object.zoom=this._zoom0,this.object.updateProjectionMatrix(),this._eye.subVectors(this.object.position,this.target),this.object.lookAt(this.target),this.dispatchEvent(OL),this._lastPosition.copy(this.object.position),this._lastZoom=this.object.zoom}_panCamera(){if(XL.copy(this._panEnd).sub(this._panStart),XL.lengthSq()){if(this.object.isOrthographicCamera){const t=(this.object.right-this.object.left)/this.object.zoom/this.domElement.clientWidth,e=(this.object.top-this.object.bottom)/this.object.zoom/this.domElement.clientWidth;XL.x*=t,XL.y*=e}XL.multiplyScalar(this._eye.length()*this.panSpeed),YL.copy(this._eye).cross(this.object.up).setLength(XL.x),YL.add($L.copy(this.object.up).setLength(XL.y)),this.object.position.add(YL),this.target.add(YL),this.staticMoving?this._panStart.copy(this._panEnd):this._panStart.add(XL.subVectors(this._panEnd,this._panStart).multiplyScalar(this.dynamicDampingFactor))}}_rotateCamera(){eU.set(this._moveCurr.x-this._movePrev.x,this._moveCurr.y-this._movePrev.y,0);let t=eU.length();t?(this._eye.copy(this.object.position).sub(this.target),QL.copy(this._eye).normalize(),JL.copy(this.object.up).normalize(),tU.crossVectors(JL,QL).normalize(),JL.setLength(this._moveCurr.y-this._movePrev.y),tU.setLength(this._moveCurr.x-this._movePrev.x),eU.copy(JL.add(tU)),KL.crossVectors(eU,this._eye).normalize(),t*=this.rotateSpeed,ZL.setFromAxisAngle(KL,t),this._eye.applyQuaternion(ZL),this.object.up.applyQuaternion(ZL),this._lastAxis.copy(KL),this._lastAngle=t):!this.staticMoving&&this._lastAngle&&(this._lastAngle*=Math.sqrt(1-this.dynamicDampingFactor),this._eye.copy(this.object.position).sub(this.target),ZL.setFromAxisAngle(this._lastAxis,this._lastAngle),this._eye.applyQuaternion(ZL),this.object.up.applyQuaternion(ZL)),this._movePrev.copy(this._moveCurr)}_zoomCamera(){let t;this.state===WL?(t=this._touchZoomDistanceStart/this._touchZoomDistanceEnd,this._touchZoomDistanceStart=this._touchZoomDistanceEnd,this.object.isPerspectiveCamera?this._eye.multiplyScalar(t):this.object.isOrthographicCamera?(this.object.zoom=be.clamp(this.object.zoom/t,this.minZoom,this.maxZoom),this._lastZoom!==this.object.zoom&&this.object.updateProjectionMatrix()):console.warn("THREE.TrackballControls: Unsupported camera type")):(t=1+(this._zoomEnd.y-this._zoomStart.y)*this.zoomSpeed,1!==t&&t>0&&(this.object.isPerspectiveCamera?this._eye.multiplyScalar(t):this.object.isOrthographicCamera?(this.object.zoom=be.clamp(this.object.zoom/t,this.minZoom,this.maxZoom),this._lastZoom!==this.object.zoom&&this.object.updateProjectionMatrix()):console.warn("THREE.TrackballControls: Unsupported camera type")),this.staticMoving?this._zoomStart.copy(this._zoomEnd):this._zoomStart.y+=(this._zoomEnd.y-this._zoomStart.y)*this.dynamicDampingFactor)}_getMouseOnScreen(t,e){return qL.set((t-this.screen.left)/this.screen.width,(e-this.screen.top)/this.screen.height),qL}_getMouseOnCircle(t,e){return qL.set((t-.5*this.screen.width-this.screen.left)/(.5*this.screen.width),(this.screen.height+2*(this.screen.top-e))/this.screen.width),qL}_addPointer(t){this._pointers.push(t)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e].pointerId==t.pointerId)return void this._pointers.splice(e,1)}_trackPointer(t){let e=this._pointerPositions[t.pointerId];void 0===e&&(e=new Se,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0].pointerId?this._pointers[1]:this._pointers[0];return this._pointerPositions[e.pointerId]}_checkDistances(){this.noZoom&&this.noPan||(this._eye.lengthSq()>this.maxDistance*this.maxDistance&&(this.object.position.addVectors(this.target,this._eye.setLength(this.maxDistance)),this._zoomStart.copy(this._zoomEnd)),this._eye.lengthSq()<this.minDistance*this.minDistance&&(this.object.position.addVectors(this.target,this._eye.setLength(this.minDistance)),this._zoomStart.copy(this._zoomEnd)))}}function iU(t){!1!==this.enabled&&(0===this._pointers.length&&(this.domElement.setPointerCapture(t.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),this._addPointer(t),"touch"===t.pointerType?this._onTouchStart(t):this._onMouseDown(t))}function rU(t){!1!==this.enabled&&("touch"===t.pointerType?this._onTouchMove(t):this._onMouseMove(t))}function sU(t){!1!==this.enabled&&("touch"===t.pointerType?this._onTouchEnd(t):this._onMouseUp(),this._removePointer(t),0===this._pointers.length&&(this.domElement.releasePointerCapture(t.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp)))}function aU(t){this._removePointer(t)}function oU(){!1!==this.enabled&&(this.keyState=kL,window.addEventListener("keydown",this._onKeyDown))}function lU(t){!1!==this.enabled&&(window.removeEventListener("keydown",this._onKeyDown),this.keyState===kL&&(t.code!==this.keys[GL]||this.noRotate?t.code!==this.keys[VL]||this.noZoom?t.code!==this.keys[HL]||this.noPan||(this.keyState=HL):this.keyState=VL:this.keyState=GL))}function hU(t){let e;switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case a.DOLLY:this.state=VL;break;case a.ROTATE:this.state=GL;break;case a.PAN:this.state=HL;break;default:this.state=kL}const n=this.keyState!==kL?this.keyState:this.state;n!==GL||this.noRotate?n!==VL||this.noZoom?n!==HL||this.noPan||(this._panStart.copy(this._getMouseOnScreen(t.pageX,t.pageY)),this._panEnd.copy(this._panStart)):(this._zoomStart.copy(this._getMouseOnScreen(t.pageX,t.pageY)),this._zoomEnd.copy(this._zoomStart)):(this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)),this._movePrev.copy(this._moveCurr)),this.dispatchEvent(FL)}function uU(t){const e=this.keyState!==kL?this.keyState:this.state;e!==GL||this.noRotate?e!==VL||this.noZoom?e!==HL||this.noPan||this._panEnd.copy(this._getMouseOnScreen(t.pageX,t.pageY)):this._zoomEnd.copy(this._getMouseOnScreen(t.pageX,t.pageY)):(this._movePrev.copy(this._moveCurr),this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)))}function cU(){this.state=kL,this.dispatchEvent(BL)}function dU(t){if(!1!==this.enabled&&!0!==this.noZoom){switch(t.preventDefault(),t.deltaMode){case 2:this._zoomStart.y-=.025*t.deltaY;break;case 1:this._zoomStart.y-=.01*t.deltaY;break;default:this._zoomStart.y-=25e-5*t.deltaY}this.dispatchEvent(FL),this.dispatchEvent(BL)}}function pU(t){!1!==this.enabled&&t.preventDefault()}function fU(t){if(this._trackPointer(t),1===this._pointers.length)this.state=jL,this._moveCurr.copy(this._getMouseOnCircle(this._pointers[0].pageX,this._pointers[0].pageY)),this._movePrev.copy(this._moveCurr);else{this.state=WL;const t=this._pointers[0].pageX-this._pointers[1].pageX,e=this._pointers[0].pageY-this._pointers[1].pageY;this._touchZoomDistanceEnd=this._touchZoomDistanceStart=Math.sqrt(t*t+e*e);const n=(this._pointers[0].pageX+this._pointers[1].pageX)/2,i=(this._pointers[0].pageY+this._pointers[1].pageY)/2;this._panStart.copy(this._getMouseOnScreen(n,i)),this._panEnd.copy(this._panStart)}this.dispatchEvent(FL)}function mU(t){if(this._trackPointer(t),1===this._pointers.length)this._movePrev.copy(this._moveCurr),this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY));else{const e=this._getSecondPointerPosition(t),n=t.pageX-e.x,i=t.pageY-e.y;this._touchZoomDistanceEnd=Math.sqrt(n*n+i*i);const r=(t.pageX+e.x)/2,s=(t.pageY+e.y)/2;this._panEnd.copy(this._getMouseOnScreen(r,s))}}function gU(t){switch(this._pointers.length){case 0:this.state=kL;break;case 1:this.state=jL,this._moveCurr.copy(this._getMouseOnCircle(t.pageX,t.pageY)),this._movePrev.copy(this._moveCurr);break;case 2:this.state=WL;for(let e=0;e<this._pointers.length;e++)if(this._pointers[e].pointerId!==t.pointerId){const t=this._pointerPositions[this._pointers[e].pointerId];this._moveCurr.copy(this._getMouseOnCircle(t.x,t.y)),this._movePrev.copy(this._moveCurr);break}}this.dispatchEvent(BL)}const _U={type:"change"},vU={type:"start"},yU={type:"end"},xU=new An,bU=new gr,SU=Math.cos(70*be.DEG2RAD),MU=new Ze,TU=2*Math.PI,wU=-1,EU=0,AU=1,RU=2,CU=3,NU=4,PU=5,IU=6,LU=1e-6;class UU extends nl{constructor(t,e=null){super(t,e),this.state=wU,this.enabled=!0,this.target=new Ze,this.cursor=new Ze,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:a.ROTATE,MIDDLE:a.DOLLY,RIGHT:a.PAN},this.touches={ONE:o,TWO:h},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new Ze,this._lastQuaternion=new Ke,this._lastTargetPosition=new Ze,this._quat=(new Ke).setFromUnitVectors(t.up,new Ze(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new el,this._sphericalDelta=new el,this._scale=1,this._panOffset=new Ze,this._rotateStart=new Se,this._rotateEnd=new Se,this._rotateDelta=new Se,this._panStart=new Se,this._panEnd=new Se,this._panDelta=new Se,this._dollyStart=new Se,this._dollyEnd=new Se,this._dollyDelta=new Se,this._dollyDirection=new Ze,this._mouse=new Se,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=OU.bind(this),this._onPointerDown=DU.bind(this),this._onPointerUp=FU.bind(this),this._onContextMenu=jU.bind(this),this._onMouseWheel=kU.bind(this),this._onKeyDown=GU.bind(this),this._onTouchStart=VU.bind(this),this._onTouchMove=HU.bind(this),this._onMouseDown=BU.bind(this),this._onMouseMove=zU.bind(this),this._interceptControlDown=WU.bind(this),this._interceptControlUp=qU.bind(this),null!==this.domElement&&this.connect(),this.update()}connect(){this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1});this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents();this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(t){t.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=t}stopListenToKeyEvents(){null!==this._domElementKeyEvents&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(_U),this.update(),this.state=wU}update(t=null){const e=this.object.position;MU.copy(e).sub(this.target),MU.applyQuaternion(this._quat),this._spherical.setFromVector3(MU),this.autoRotate&&this.state===wU&&this._rotateLeft(this._getAutoRotationAngle(t)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let n=this.minAzimuthAngle,i=this.maxAzimuthAngle;isFinite(n)&&isFinite(i)&&(n<-Math.PI?n+=TU:n>Math.PI&&(n-=TU),i<-Math.PI?i+=TU:i>Math.PI&&(i-=TU),this._spherical.theta=n<=i?Math.max(n,Math.min(i,this._spherical.theta)):this._spherical.theta>(n+i)/2?Math.max(n,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),!0===this.enableDamping?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let r=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const t=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),r=t!=this._spherical.radius}if(MU.setFromSpherical(this._spherical),MU.applyQuaternion(this._quatInverse),e.copy(this.target).add(MU),this.object.lookAt(this.target),!0===this.enableDamping?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let t=null;if(this.object.isPerspectiveCamera){const e=MU.length();t=this._clampDistance(e*this._scale);const n=e-t;this.object.position.addScaledVector(this._dollyDirection,n),this.object.updateMatrixWorld(),r=!!n}else if(this.object.isOrthographicCamera){const e=new Ze(this._mouse.x,this._mouse.y,0);e.unproject(this.object);const n=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),r=n!==this.object.zoom;const i=new Ze(this._mouse.x,this._mouse.y,0);i.unproject(this.object),this.object.position.sub(i).add(e),this.object.updateMatrixWorld(),t=MU.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;null!==t&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(t).add(this.object.position):(xU.origin.copy(this.object.position),xU.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(xU.direction))<SU?this.object.lookAt(this.target):(bU.setFromNormalAndCoplanarPoint(this.object.up,this.target),xU.intersectPlane(bU,this.target))))}else if(this.object.isOrthographicCamera){const t=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),t!==this.object.zoom&&(this.object.updateProjectionMatrix(),r=!0)}return this._scale=1,this._performCursorZoom=!1,!!(r||this._lastPosition.distanceToSquared(this.object.position)>LU||8*(1-this._lastQuaternion.dot(this.object.quaternion))>LU||this._lastTargetPosition.distanceToSquared(this.target)>LU)&&(this.dispatchEvent(_U),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0)}_getAutoRotationAngle(t){return null!==t?TU/60*this.autoRotateSpeed*t:TU/60/60*this.autoRotateSpeed}_getZoomScale(t){const e=Math.abs(.01*t);return Math.pow(.95,this.zoomSpeed*e)}_rotateLeft(t){this._sphericalDelta.theta-=t}_rotateUp(t){this._sphericalDelta.phi-=t}_panLeft(t,e){MU.setFromMatrixColumn(e,0),MU.multiplyScalar(-t),this._panOffset.add(MU)}_panUp(t,e){!0===this.screenSpacePanning?MU.setFromMatrixColumn(e,1):(MU.setFromMatrixColumn(e,0),MU.crossVectors(this.object.up,MU)),MU.multiplyScalar(t),this._panOffset.add(MU)}_pan(t,e){const n=this.domElement;if(this.object.isPerspectiveCamera){const i=this.object.position;MU.copy(i).sub(this.target);let r=MU.length();r*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*t*r/n.clientHeight,this.object.matrix),this._panUp(2*e*r/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(t*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(e*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(t,e){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),i=t-n.left,r=e-n.top,s=n.width,a=n.height;this._mouse.x=i/s*2-1,this._mouse.y=-r/a*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}_handleMouseDownRotate(t){this._rotateStart.set(t.clientX,t.clientY)}_handleMouseDownDolly(t){this._updateZoomParameters(t.clientX,t.clientX),this._dollyStart.set(t.clientX,t.clientY)}_handleMouseDownPan(t){this._panStart.set(t.clientX,t.clientY)}_handleMouseMoveRotate(t){this._rotateEnd.set(t.clientX,t.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(TU*this._rotateDelta.x/e.clientHeight),this._rotateUp(TU*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(t){this._dollyEnd.set(t.clientX,t.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(t){this._panEnd.set(t.clientX,t.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(t){this._updateZoomParameters(t.clientX,t.clientY),t.deltaY<0?this._dollyIn(this._getZoomScale(t.deltaY)):t.deltaY>0&&this._dollyOut(this._getZoomScale(t.deltaY)),this.update()}_handleKeyDown(t){let e=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateUp(TU*this.rotateSpeed/this.domElement.clientHeight):this._pan(0,this.keyPanSpeed),e=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateUp(-TU*this.rotateSpeed/this.domElement.clientHeight):this._pan(0,-this.keyPanSpeed),e=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateLeft(TU*this.rotateSpeed/this.domElement.clientHeight):this._pan(this.keyPanSpeed,0),e=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this._rotateLeft(-TU*this.rotateSpeed/this.domElement.clientHeight):this._pan(-this.keyPanSpeed,0),e=!0}e&&(t.preventDefault(),this.update())}_handleTouchStartRotate(t){if(1===this._pointers.length)this._rotateStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._rotateStart.set(n,i)}}_handleTouchStartPan(t){if(1===this._pointers.length)this._panStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._panStart.set(n,i)}}_handleTouchStartDolly(t){const e=this._getSecondPointerPosition(t),n=t.pageX-e.x,i=t.pageY-e.y,r=Math.sqrt(n*n+i*i);this._dollyStart.set(0,r)}_handleTouchStartDollyPan(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enablePan&&this._handleTouchStartPan(t)}_handleTouchStartDollyRotate(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enableRotate&&this._handleTouchStartRotate(t)}_handleTouchMoveRotate(t){if(1==this._pointers.length)this._rotateEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._rotateEnd.set(n,i)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(TU*this._rotateDelta.x/e.clientHeight),this._rotateUp(TU*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(t){if(1===this._pointers.length)this._panEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._panEnd.set(n,i)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(t){const e=this._getSecondPointerPosition(t),n=t.pageX-e.x,i=t.pageY-e.y,r=Math.sqrt(n*n+i*i);this._dollyEnd.set(0,r),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const s=.5*(t.pageX+e.x),a=.5*(t.pageY+e.y);this._updateZoomParameters(s,a)}_handleTouchMoveDollyPan(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enablePan&&this._handleTouchMovePan(t)}_handleTouchMoveDollyRotate(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enableRotate&&this._handleTouchMoveRotate(t)}_addPointer(t){this._pointers.push(t.pointerId)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return void this._pointers.splice(e,1)}_isTrackingPointer(t){for(let e=0;e<this._pointers.length;e++)if(this._pointers[e]==t.pointerId)return!0;return!1}_trackPointer(t){let e=this._pointerPositions[t.pointerId];void 0===e&&(e=new Se,this._pointerPositions[t.pointerId]=e),e.set(t.pageX,t.pageY)}_getSecondPointerPosition(t){const e=t.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[e]}_customWheelEvent(t){const e=t.deltaMode,n={clientX:t.clientX,clientY:t.clientY,deltaY:t.deltaY};switch(e){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100}return t.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}}function DU(t){!1!==this.enabled&&(0===this._pointers.length&&(this.domElement.setPointerCapture(t.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),this._isTrackingPointer(t)||(this._addPointer(t),"touch"===t.pointerType?this._onTouchStart(t):this._onMouseDown(t)))}function OU(t){!1!==this.enabled&&("touch"===t.pointerType?this._onTouchMove(t):this._onMouseMove(t))}function FU(t){switch(this._removePointer(t),this._pointers.length){case 0:this.domElement.releasePointerCapture(t.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(yU),this.state=wU;break;case 1:const e=this._pointers[0],n=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:n.x,pageY:n.y})}}function BU(t){let e;switch(t.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case a.DOLLY:if(!1===this.enableZoom)return;this._handleMouseDownDolly(t),this.state=AU;break;case a.ROTATE:if(t.ctrlKey||t.metaKey||t.shiftKey){if(!1===this.enablePan)return;this._handleMouseDownPan(t),this.state=RU}else{if(!1===this.enableRotate)return;this._handleMouseDownRotate(t),this.state=EU}break;case a.PAN:if(t.ctrlKey||t.metaKey||t.shiftKey){if(!1===this.enableRotate)return;this._handleMouseDownRotate(t),this.state=EU}else{if(!1===this.enablePan)return;this._handleMouseDownPan(t),this.state=RU}break;default:this.state=wU}this.state!==wU&&this.dispatchEvent(vU)}function zU(t){switch(this.state){case EU:if(!1===this.enableRotate)return;this._handleMouseMoveRotate(t);break;case AU:if(!1===this.enableZoom)return;this._handleMouseMoveDolly(t);break;case RU:if(!1===this.enablePan)return;this._handleMouseMovePan(t)}}function kU(t){!1!==this.enabled&&!1!==this.enableZoom&&this.state===wU&&(t.preventDefault(),this.dispatchEvent(vU),this._handleMouseWheel(this._customWheelEvent(t)),this.dispatchEvent(yU))}function GU(t){!1!==this.enabled&&!1!==this.enablePan&&this._handleKeyDown(t)}function VU(t){switch(this._trackPointer(t),this._pointers.length){case 1:switch(this.touches.ONE){case o:if(!1===this.enableRotate)return;this._handleTouchStartRotate(t),this.state=CU;break;case l:if(!1===this.enablePan)return;this._handleTouchStartPan(t),this.state=NU;break;default:this.state=wU}break;case 2:switch(this.touches.TWO){case h:if(!1===this.enableZoom&&!1===this.enablePan)return;this._handleTouchStartDollyPan(t),this.state=PU;break;case u:if(!1===this.enableZoom&&!1===this.enableRotate)return;this._handleTouchStartDollyRotate(t),this.state=IU;break;default:this.state=wU}break;default:this.state=wU}this.state!==wU&&this.dispatchEvent(vU)}function HU(t){switch(this._trackPointer(t),this.state){case CU:if(!1===this.enableRotate)return;this._handleTouchMoveRotate(t),this.update();break;case NU:if(!1===this.enablePan)return;this._handleTouchMovePan(t),this.update();break;case PU:if(!1===this.enableZoom&&!1===this.enablePan)return;this._handleTouchMoveDollyPan(t),this.update();break;case IU:if(!1===this.enableZoom&&!1===this.enableRotate)return;this._handleTouchMoveDollyRotate(t),this.update();break;default:this.state=wU}}function jU(t){!1!==this.enabled&&t.preventDefault()}function WU(t){if("Control"===t.key){this._controlActive=!0;this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0})}}function qU(t){if("Control"===t.key){this._controlActive=!1;this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0})}}const XU={type:"change"},$U=1e-6,YU=new Ke;class KU extends nl{constructor(t,e=null){super(t,e),this.movementSpeed=1,this.rollSpeed=.005,this.dragToLook=!1,this.autoForward=!1,this._moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0},this._moveVector=new Ze(0,0,0),this._rotationVector=new Ze(0,0,0),this._lastQuaternion=new Ke,this._lastPosition=new Ze,this._status=0,this._onKeyDown=ZU.bind(this),this._onKeyUp=QU.bind(this),this._onPointerMove=tD.bind(this),this._onPointerDown=JU.bind(this),this._onPointerUp=eD.bind(this),this._onPointerCancel=nD.bind(this),this._onContextMenu=iD.bind(this),null!==e&&this.connect()}connect(){window.addEventListener("keydown",this._onKeyDown),window.addEventListener("keyup",this._onKeyUp),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointerup",this._onPointerUp),this.domElement.addEventListener("pointercancel",this._onPointerCancel),this.domElement.addEventListener("contextmenu",this._onContextMenu)}disconnect(){window.removeEventListener("keydown",this._onKeyDown),window.removeEventListener("keyup",this._onKeyUp),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerCancel),this.domElement.removeEventListener("contextmenu",this._onContextMenu)}dispose(){this.disconnect()}update(t){if(!1===this.enabled)return;const e=this.object,n=t*this.movementSpeed,i=t*this.rollSpeed;e.translateX(this._moveVector.x*n),e.translateY(this._moveVector.y*n),e.translateZ(this._moveVector.z*n),YU.set(this._rotationVector.x*i,this._rotationVector.y*i,this._rotationVector.z*i,1).normalize(),e.quaternion.multiply(YU),(this._lastPosition.distanceToSquared(e.position)>$U||8*(1-this._lastQuaternion.dot(e.quaternion))>$U)&&(this.dispatchEvent(XU),this._lastQuaternion.copy(e.quaternion),this._lastPosition.copy(e.position))}_updateMovementVector(){const t=this._moveState.forward||this.autoForward&&!this._moveState.back?1:0;this._moveVector.x=-this._moveState.left+this._moveState.right,this._moveVector.y=-this._moveState.down+this._moveState.up,this._moveVector.z=-t+this._moveState.back}_updateRotationVector(){this._rotationVector.x=-this._moveState.pitchDown+this._moveState.pitchUp,this._rotationVector.y=-this._moveState.yawRight+this._moveState.yawLeft,this._rotationVector.z=-this._moveState.rollRight+this._moveState.rollLeft}_getContainerDimensions(){return this.domElement!=document?{size:[this.domElement.offsetWidth,this.domElement.offsetHeight],offset:[this.domElement.offsetLeft,this.domElement.offsetTop]}:{size:[window.innerWidth,window.innerHeight],offset:[0,0]}}}function ZU(t){if(!t.altKey&&!1!==this.enabled){switch(t.code){case"ShiftLeft":case"ShiftRight":this.movementSpeedMultiplier=.1;break;case"KeyW":this._moveState.forward=1;break;case"KeyS":this._moveState.back=1;break;case"KeyA":this._moveState.left=1;break;case"KeyD":this._moveState.right=1;break;case"KeyR":this._moveState.up=1;break;case"KeyF":this._moveState.down=1;break;case"ArrowUp":this._moveState.pitchUp=1;break;case"ArrowDown":this._moveState.pitchDown=1;break;case"ArrowLeft":this._moveState.yawLeft=1;break;case"ArrowRight":this._moveState.yawRight=1;break;case"KeyQ":this._moveState.rollLeft=1;break;case"KeyE":this._moveState.rollRight=1}this._updateMovementVector(),this._updateRotationVector()}}function QU(t){if(!1!==this.enabled){switch(t.code){case"ShiftLeft":case"ShiftRight":this.movementSpeedMultiplier=1;break;case"KeyW":this._moveState.forward=0;break;case"KeyS":this._moveState.back=0;break;case"KeyA":this._moveState.left=0;break;case"KeyD":this._moveState.right=0;break;case"KeyR":this._moveState.up=0;break;case"KeyF":this._moveState.down=0;break;case"ArrowUp":this._moveState.pitchUp=0;break;case"ArrowDown":this._moveState.pitchDown=0;break;case"ArrowLeft":this._moveState.yawLeft=0;break;case"ArrowRight":this._moveState.yawRight=0;break;case"KeyQ":this._moveState.rollLeft=0;break;case"KeyE":this._moveState.rollRight=0}this._updateMovementVector(),this._updateRotationVector()}}function JU(t){if(!1!==this.enabled)if(this.dragToLook)this._status++;else{switch(t.button){case 0:this._moveState.forward=1;break;case 2:this._moveState.back=1}this._updateMovementVector()}}function tD(t){if(!1!==this.enabled&&(!this.dragToLook||this._status>0)){const e=this._getContainerDimensions(),n=e.size[0]/2,i=e.size[1]/2;this._moveState.yawLeft=-(t.pageX-e.offset[0]-n)/n,this._moveState.pitchDown=(t.pageY-e.offset[1]-i)/i,this._updateRotationVector()}}function eD(t){if(!1!==this.enabled){if(this.dragToLook)this._status--,this._moveState.yawLeft=this._moveState.pitchDown=0;else{switch(t.button){case 0:this._moveState.forward=0;break;case 2:this._moveState.back=0}this._updateMovementVector()}this._updateRotationVector()}}function nD(){!1!==this.enabled&&(this.dragToLook?(this._status=0,this._moveState.yawLeft=this._moveState.pitchDown=0):(this._moveState.forward=0,this._moveState.back=0,this._updateMovementVector()),this._updateRotationVector())}function iD(t){!1!==this.enabled&&t.preventDefault()}const rD={name:"CopyShader",uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\n\t\tuniform float opacity;\n\n\t\tuniform sampler2D tDiffuse;\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvec4 texel = texture2D( tDiffuse, vUv );\n\t\t\tgl_FragColor = opacity * texel;\n\n\n\t\t}"};class sD{constructor(){this.isPass=!0,this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error("THREE.Pass: .render() must be implemented in derived pass.")}dispose(){}}const aD=new Dr(-1,1,1,-1,0,1);const oD=new class extends Bi{constructor(){super(),this.setAttribute("position",new Ni([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new Ni([0,2,0,0,2,0],2))}};class lD{constructor(t){this._mesh=new Ki(oD,t)}dispose(){this._mesh.geometry.dispose()}render(t){t.render(this._mesh,aD)}get material(){return this._mesh.material}set material(t){this._mesh.material=t}}class hD extends sD{constructor(t,e){super(),this.textureID=void 0!==e?e:"tDiffuse",t instanceof ir?(this.uniforms=t.uniforms,this.material=t):t&&(this.uniforms=nr.clone(t.uniforms),this.material=new ir({name:void 0!==t.name?t.name:"unspecified",defines:Object.assign({},t.defines),uniforms:this.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader})),this.fsQuad=new lD(this.material)}render(t,e,n){this.uniforms[this.textureID]&&(this.uniforms[this.textureID].value=n.texture),this.fsQuad.material=this.material,this.renderToScreen?(t.setRenderTarget(null),this.fsQuad.render(t)):(t.setRenderTarget(e),this.clear&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),this.fsQuad.render(t))}dispose(){this.material.dispose(),this.fsQuad.dispose()}}class uD extends sD{constructor(t,e){super(),this.scene=t,this.camera=e,this.clear=!0,this.needsSwap=!1,this.inverse=!1}render(t,e,n){const i=t.getContext(),r=t.state;let s,a;r.buffers.color.setMask(!1),r.buffers.depth.setMask(!1),r.buffers.color.setLocked(!0),r.buffers.depth.setLocked(!0),this.inverse?(s=0,a=1):(s=1,a=0),r.buffers.stencil.setTest(!0),r.buffers.stencil.setOp(i.REPLACE,i.REPLACE,i.REPLACE),r.buffers.stencil.setFunc(i.ALWAYS,s,4294967295),r.buffers.stencil.setClear(a),r.buffers.stencil.setLocked(!0),t.setRenderTarget(n),this.clear&&t.clear(),t.render(this.scene,this.camera),t.setRenderTarget(e),this.clear&&t.clear(),t.render(this.scene,this.camera),r.buffers.color.setLocked(!1),r.buffers.depth.setLocked(!1),r.buffers.color.setMask(!0),r.buffers.depth.setMask(!0),r.buffers.stencil.setLocked(!1),r.buffers.stencil.setFunc(i.EQUAL,1,4294967295),r.buffers.stencil.setOp(i.KEEP,i.KEEP,i.KEEP),r.buffers.stencil.setLocked(!0)}}class cD extends sD{constructor(){super(),this.needsSwap=!1}render(t){t.state.buffers.stencil.setLocked(!1),t.state.buffers.stencil.setTest(!1)}}class dD{constructor(t,e){if(this.renderer=t,this._pixelRatio=t.getPixelRatio(),void 0===e){const n=t.getSize(new Se);this._width=n.width,this._height=n.height,(e=new Xe(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:st})).texture.name="EffectComposer.rt1"}else this._width=e.width,this._height=e.height;this.renderTarget1=e,this.renderTarget2=e.clone(),this.renderTarget2.texture.name="EffectComposer.rt2",this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2,this.renderToScreen=!0,this.passes=[],this.copyPass=new hD(rD),this.copyPass.material.blending=0,this.clock=new Yo}swapBuffers(){const t=this.readBuffer;this.readBuffer=this.writeBuffer,this.writeBuffer=t}addPass(t){this.passes.push(t),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}insertPass(t,e){this.passes.splice(e,0,t),t.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}removePass(t){const e=this.passes.indexOf(t);-1!==e&&this.passes.splice(e,1)}isLastEnabledPass(t){for(let e=t+1;e<this.passes.length;e++)if(this.passes[e].enabled)return!1;return!0}render(t){void 0===t&&(t=this.clock.getDelta());const e=this.renderer.getRenderTarget();let n=!1;for(let e=0,i=this.passes.length;e<i;e++){const i=this.passes[e];if(!1!==i.enabled){if(i.renderToScreen=this.renderToScreen&&this.isLastEnabledPass(e),i.render(this.renderer,this.writeBuffer,this.readBuffer,t,n),i.needsSwap){if(n){const e=this.renderer.getContext(),n=this.renderer.state.buffers.stencil;n.setFunc(e.NOTEQUAL,1,4294967295),this.copyPass.render(this.renderer,this.writeBuffer,this.readBuffer,t),n.setFunc(e.EQUAL,1,4294967295)}this.swapBuffers()}void 0!==uD&&(i instanceof uD?n=!0:i instanceof cD&&(n=!1))}}this.renderer.setRenderTarget(e)}reset(t){if(void 0===t){const e=this.renderer.getSize(new Se);this._pixelRatio=this.renderer.getPixelRatio(),this._width=e.width,this._height=e.height,(t=this.renderTarget1.clone()).setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.renderTarget1=t,this.renderTarget2=t.clone(),this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2}setSize(t,e){this._width=t,this._height=e;const n=this._width*this._pixelRatio,i=this._height*this._pixelRatio;this.renderTarget1.setSize(n,i),this.renderTarget2.setSize(n,i);for(let t=0;t<this.passes.length;t++)this.passes[t].setSize(n,i)}setPixelRatio(t){this._pixelRatio=t,this.setSize(this._width,this._height)}dispose(){this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.copyPass.dispose()}}class pD extends sD{constructor(t,e,n=null,i=null,r=null){super(),this.scene=t,this.camera=e,this.overrideMaterial=n,this.clearColor=i,this.clearAlpha=r,this.clear=!0,this.clearDepth=!1,this.needsSwap=!1,this._oldClearColor=new xi}render(t,e,n){const i=t.autoClear;let r,s;t.autoClear=!1,null!==this.overrideMaterial&&(s=this.scene.overrideMaterial,this.scene.overrideMaterial=this.overrideMaterial),null!==this.clearColor&&(t.getClearColor(this._oldClearColor),t.setClearColor(this.clearColor,t.getClearAlpha())),null!==this.clearAlpha&&(r=t.getClearAlpha(),t.setClearAlpha(this.clearAlpha)),1==this.clearDepth&&t.clearDepth(),t.setRenderTarget(this.renderToScreen?null:n),!0===this.clear&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),t.render(this.scene,this.camera),null!==this.clearColor&&t.setClearColor(this._oldClearColor),null!==this.clearAlpha&&t.setClearAlpha(r),null!==this.overrideMaterial&&(this.scene.overrideMaterial=s),t.autoClear=i}}function fD(){return fD=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)({}).hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},fD.apply(null,arguments)}function mD(t,e){return mD=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},mD(t,e)}function gD(t){return gD=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},gD(t)}function _D(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(_D=function(){return!!t})()}function vD(t){var e="function"==typeof Map?new Map:void 0;return vD=function(t){if(null===t||!function(t){try{return-1!==Function.toString.call(t).indexOf("[native code]")}catch(e){return"function"==typeof t}}(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return function(t,e,n){if(_D())return Reflect.construct.apply(null,arguments);var i=[null];i.push.apply(i,e);var r=new(t.bind.apply(t,i));return n&&mD(r,n.prototype),r}(t,arguments,gD(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),mD(n,t)},vD(t)}var yD={1:"Passed invalid arguments to hsl, please pass multiple numbers e.g. hsl(360, 0.75, 0.4) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75 }).\n\n",2:"Passed invalid arguments to hsla, please pass multiple numbers e.g. hsla(360, 0.75, 0.4, 0.7) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75, alpha: 0.7 }).\n\n",3:"Passed an incorrect argument to a color function, please pass a string representation of a color.\n\n",4:"Couldn't generate valid rgb string from %s, it returned %s.\n\n",5:"Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation.\n\n",6:"Passed invalid arguments to rgb, please pass multiple numbers e.g. rgb(255, 205, 100) or an object e.g. rgb({ red: 255, green: 205, blue: 100 }).\n\n",7:"Passed invalid arguments to rgba, please pass multiple numbers e.g. rgb(255, 205, 100, 0.75) or an object e.g. rgb({ red: 255, green: 205, blue: 100, alpha: 0.75 }).\n\n",8:"Passed invalid argument to toColorString, please pass a RgbColor, RgbaColor, HslColor or HslaColor object.\n\n",9:"Please provide a number of steps to the modularScale helper.\n\n",10:"Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",11:'Invalid value passed as base to modularScale, expected number or em string but got "%s"\n\n',12:'Expected a string ending in "px" or a number passed as the first argument to %s(), got "%s" instead.\n\n',13:'Expected a string ending in "px" or a number passed as the second argument to %s(), got "%s" instead.\n\n',14:'Passed invalid pixel value ("%s") to %s(), please pass a value like "12px" or 12.\n\n',15:'Passed invalid base value ("%s") to %s(), please pass a value like "12px" or 12.\n\n',16:"You must provide a template to this method.\n\n",17:"You passed an unsupported selector state to this method.\n\n",18:"minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",19:"fromSize and toSize must be provided as stringified numbers with the same units.\n\n",20:"expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",21:"expects the objects in the first argument array to have the properties `prop`, `fromSize`, and `toSize`.\n\n",22:"expects the first argument object to have the properties `prop`, `fromSize`, and `toSize`.\n\n",23:"fontFace expects a name of a font-family.\n\n",24:"fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",25:"fontFace expects localFonts to be an array.\n\n",26:"fontFace expects fileFormats to be an array.\n\n",27:"radialGradient requries at least 2 color-stops to properly render.\n\n",28:"Please supply a filename to retinaImage() as the first argument.\n\n",29:"Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",30:"Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",31:"The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation\n\n",32:"To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s')\n\n",33:"The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation\n\n",34:"borderRadius expects a radius value as a string or number as the second argument.\n\n",35:'borderRadius expects one of "top", "bottom", "left" or "right" as the first argument.\n\n',36:"Property must be a string value.\n\n",37:"Syntax Error at %s.\n\n",38:"Formula contains a function that needs parentheses at %s.\n\n",39:"Formula is missing closing parenthesis at %s.\n\n",40:"Formula has too many closing parentheses at %s.\n\n",41:"All values in a formula must have the same unit or be unitless.\n\n",42:"Please provide a number of steps to the modularScale helper.\n\n",43:"Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n",44:"Invalid value passed as base to modularScale, expected number or em/rem string but got %s.\n\n",45:"Passed invalid argument to hslToColorString, please pass a HslColor or HslaColor object.\n\n",46:"Passed invalid argument to rgbToColorString, please pass a RgbColor or RgbaColor object.\n\n",47:"minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n",48:"fromSize and toSize must be provided as stringified numbers with the same units.\n\n",49:"Expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n",50:"Expects the objects in the first argument array to have the properties prop, fromSize, and toSize.\n\n",51:"Expects the first argument object to have the properties prop, fromSize, and toSize.\n\n",52:"fontFace expects either the path to the font file(s) or a name of a local copy.\n\n",53:"fontFace expects localFonts to be an array.\n\n",54:"fontFace expects fileFormats to be an array.\n\n",55:"fontFace expects a name of a font-family.\n\n",56:"linearGradient requries at least 2 color-stops to properly render.\n\n",57:"radialGradient requries at least 2 color-stops to properly render.\n\n",58:"Please supply a filename to retinaImage() as the first argument.\n\n",59:"Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n",60:"Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n",61:"Property must be a string value.\n\n",62:"borderRadius expects a radius value as a string or number as the second argument.\n\n",63:'borderRadius expects one of "top", "bottom", "left" or "right" as the first argument.\n\n',64:"The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation.\n\n",65:"To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s').\n\n",66:"The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation.\n\n",67:"You must provide a template to this method.\n\n",68:"You passed an unsupported selector state to this method.\n\n",69:'Expected a string ending in "px" or a number passed as the first argument to %s(), got %s instead.\n\n',70:'Expected a string ending in "px" or a number passed as the second argument to %s(), got %s instead.\n\n',71:'Passed invalid pixel value %s to %s(), please pass a value like "12px" or 12.\n\n',72:'Passed invalid base value %s to %s(), please pass a value like "12px" or 12.\n\n',73:"Please provide a valid CSS variable.\n\n",74:"CSS variable not found and no default was provided.\n\n",75:"important requires a valid style object, got a %s instead.\n\n",76:"fromSize and toSize must be provided as stringified numbers with the same units as minScreen and maxScreen.\n\n",77:'remToPx expects a value in "rem" but you provided it in "%s".\n\n',78:'base must be set in "px" or "%" but you set it in "%s".\n'};function xD(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var i,r=e[0],s=[];for(i=1;i<e.length;i+=1)s.push(e[i]);return s.forEach((function(t){r=r.replace(/%[a-z]/,t)})),r}var bD=function(t){var e,n;function i(e){var n;if("production"===process.env.NODE_ENV)n=t.call(this,"An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#"+e+" for more information.")||this;else{for(var i=arguments.length,r=new Array(i>1?i-1:0),s=1;s<i;s++)r[s-1]=arguments[s];n=t.call(this,xD.apply(void 0,[yD[e]].concat(r)))||this}return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(n)}return n=t,(e=i).prototype=Object.create(n.prototype),e.prototype.constructor=e,mD(e,n),i}(vD(Error));function SD(t){return Math.round(255*t)}function MD(t,e,n){return SD(t)+","+SD(e)+","+SD(n)}function TD(t,e,n,i){if(void 0===i&&(i=MD),0===e)return i(n,n,n);var r=(t%360+360)%360/60,s=(1-Math.abs(2*n-1))*e,a=s*(1-Math.abs(r%2-1)),o=0,l=0,h=0;r>=0&&r<1?(o=s,l=a):r>=1&&r<2?(o=a,l=s):r>=2&&r<3?(l=s,h=a):r>=3&&r<4?(l=a,h=s):r>=4&&r<5?(o=a,h=s):r>=5&&r<6&&(o=s,h=a);var u=n-s/2;return i(o+u,l+u,h+u)}var wD={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"00ffff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",blue:"0000ff",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"00ffff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"ff00ff",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",rebeccapurple:"639",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"};var ED=/^#[a-fA-F0-9]{6}$/,AD=/^#[a-fA-F0-9]{8}$/,RD=/^#[a-fA-F0-9]{3}$/,CD=/^#[a-fA-F0-9]{4}$/,ND=/^rgb\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*\)$/i,PD=/^rgb(?:a)?\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i,ID=/^hsl\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i,LD=/^hsl(?:a)?\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i;function UD(t){if("string"!=typeof t)throw new bD(3);var e=function(t){if("string"!=typeof t)return t;var e=t.toLowerCase();return wD[e]?"#"+wD[e]:t}(t);if(e.match(ED))return{red:parseInt(""+e[1]+e[2],16),green:parseInt(""+e[3]+e[4],16),blue:parseInt(""+e[5]+e[6],16)};if(e.match(AD)){var n=parseFloat((parseInt(""+e[7]+e[8],16)/255).toFixed(2));return{red:parseInt(""+e[1]+e[2],16),green:parseInt(""+e[3]+e[4],16),blue:parseInt(""+e[5]+e[6],16),alpha:n}}if(e.match(RD))return{red:parseInt(""+e[1]+e[1],16),green:parseInt(""+e[2]+e[2],16),blue:parseInt(""+e[3]+e[3],16)};if(e.match(CD)){var i=parseFloat((parseInt(""+e[4]+e[4],16)/255).toFixed(2));return{red:parseInt(""+e[1]+e[1],16),green:parseInt(""+e[2]+e[2],16),blue:parseInt(""+e[3]+e[3],16),alpha:i}}var r=ND.exec(e);if(r)return{red:parseInt(""+r[1],10),green:parseInt(""+r[2],10),blue:parseInt(""+r[3],10)};var s=PD.exec(e.substring(0,50));if(s)return{red:parseInt(""+s[1],10),green:parseInt(""+s[2],10),blue:parseInt(""+s[3],10),alpha:parseFloat(""+s[4])>1?parseFloat(""+s[4])/100:parseFloat(""+s[4])};var a=ID.exec(e);if(a){var o="rgb("+TD(parseInt(""+a[1],10),parseInt(""+a[2],10)/100,parseInt(""+a[3],10)/100)+")",l=ND.exec(o);if(!l)throw new bD(4,e,o);return{red:parseInt(""+l[1],10),green:parseInt(""+l[2],10),blue:parseInt(""+l[3],10)}}var h=LD.exec(e.substring(0,50));if(h){var u="rgb("+TD(parseInt(""+h[1],10),parseInt(""+h[2],10)/100,parseInt(""+h[3],10)/100)+")",c=ND.exec(u);if(!c)throw new bD(4,e,u);return{red:parseInt(""+c[1],10),green:parseInt(""+c[2],10),blue:parseInt(""+c[3],10),alpha:parseFloat(""+h[4])>1?parseFloat(""+h[4])/100:parseFloat(""+h[4])}}throw new bD(5)}function DD(t){return function(t){var e,n=t.red/255,i=t.green/255,r=t.blue/255,s=Math.max(n,i,r),a=Math.min(n,i,r),o=(s+a)/2;if(s===a)return void 0!==t.alpha?{hue:0,saturation:0,lightness:o,alpha:t.alpha}:{hue:0,saturation:0,lightness:o};var l=s-a,h=o>.5?l/(2-s-a):l/(s+a);switch(s){case n:e=(i-r)/l+(i<r?6:0);break;case i:e=(r-n)/l+2;break;default:e=(n-i)/l+4}return e*=60,void 0!==t.alpha?{hue:e,saturation:h,lightness:o,alpha:t.alpha}:{hue:e,saturation:h,lightness:o}}(UD(t))}var OD=function(t){return 7===t.length&&t[1]===t[2]&&t[3]===t[4]&&t[5]===t[6]?"#"+t[1]+t[3]+t[5]:t};function FD(t){var e=t.toString(16);return 1===e.length?"0"+e:e}function BD(t){return FD(Math.round(255*t))}function zD(t,e,n){return OD("#"+BD(t)+BD(e)+BD(n))}function kD(t,e,n){return TD(t,e,n,zD)}function GD(t,e,n){if("number"==typeof t&&"number"==typeof e&&"number"==typeof n)return OD("#"+FD(t)+FD(e)+FD(n));if("object"==typeof t&&void 0===e&&void 0===n)return OD("#"+FD(t.red)+FD(t.green)+FD(t.blue));throw new bD(6)}function VD(t,e,n,i){if("string"==typeof t&&"number"==typeof e){var r=UD(t);return"rgba("+r.red+","+r.green+","+r.blue+","+e+")"}if("number"==typeof t&&"number"==typeof e&&"number"==typeof n&&"number"==typeof i)return i>=1?GD(t,e,n):"rgba("+t+","+e+","+n+","+i+")";if("object"==typeof t&&void 0===e&&void 0===n&&void 0===i)return t.alpha>=1?GD(t.red,t.green,t.blue):"rgba("+t.red+","+t.green+","+t.blue+","+t.alpha+")";throw new bD(7)}function HD(t){if("object"!=typeof t)throw new bD(8);if(function(t){return"number"==typeof t.red&&"number"==typeof t.green&&"number"==typeof t.blue&&"number"==typeof t.alpha}(t))return VD(t);if(function(t){return"number"==typeof t.red&&"number"==typeof t.green&&"number"==typeof t.blue&&("number"!=typeof t.alpha||void 0===t.alpha)}(t))return GD(t);if(function(t){return"number"==typeof t.hue&&"number"==typeof t.saturation&&"number"==typeof t.lightness&&"number"==typeof t.alpha}(t))return function(t,e,n,i){if("number"==typeof t&&"number"==typeof e&&"number"==typeof n&&"number"==typeof i)return i>=1?kD(t,e,n):"rgba("+TD(t,e,n)+","+i+")";if("object"==typeof t&&void 0===e&&void 0===n&&void 0===i)return t.alpha>=1?kD(t.hue,t.saturation,t.lightness):"rgba("+TD(t.hue,t.saturation,t.lightness)+","+t.alpha+")";throw new bD(2)}(t);if(function(t){return"number"==typeof t.hue&&"number"==typeof t.saturation&&"number"==typeof t.lightness&&("number"!=typeof t.alpha||void 0===t.alpha)}(t))return function(t,e,n){if("number"==typeof t&&"number"==typeof e&&"number"==typeof n)return kD(t,e,n);if("object"==typeof t&&void 0===e&&void 0===n)return kD(t.hue,t.saturation,t.lightness);throw new bD(1)}(t);throw new bD(8)}function jD(t,e,n){return function(){var i=n.concat(Array.prototype.slice.call(arguments));return i.length>=e?t.apply(this,i):jD(t,e,i)}}function WD(t){return jD(t,t.length,[])}function qD(t,e,n){return Math.max(t,Math.min(e,n))}WD((function(t,e){if("transparent"===e)return e;var n=DD(e);return HD(fD({},n,{hue:n.hue+parseFloat(t)}))})),WD((function(t,e){if("transparent"===e)return e;var n=DD(e);return HD(fD({},n,{lightness:qD(0,1,n.lightness-parseFloat(t))}))})),WD((function(t,e){if("transparent"===e)return e;var n=DD(e);return HD(fD({},n,{saturation:qD(0,1,n.saturation-parseFloat(t))}))})),WD((function(t,e){if("transparent"===e)return e;var n=DD(e);return HD(fD({},n,{lightness:qD(0,1,n.lightness+parseFloat(t))}))}));var XD=WD((function(t,e,n){if("transparent"===e)return n;if("transparent"===n)return e;if(0===t)return n;var i=UD(e),r=fD({},i,{alpha:"number"==typeof i.alpha?i.alpha:1}),s=UD(n),a=fD({},s,{alpha:"number"==typeof s.alpha?s.alpha:1}),o=r.alpha-a.alpha,l=2*parseFloat(t)-1,h=((l*o==-1?l:l+o)/(1+l*o)+1)/2,u=1-h;return VD({red:Math.floor(r.red*h+a.red*u),green:Math.floor(r.green*h+a.green*u),blue:Math.floor(r.blue*h+a.blue*u),alpha:r.alpha*parseFloat(t)+a.alpha*(1-parseFloat(t))})})),$D=XD;var YD=WD((function(t,e){if("transparent"===e)return e;var n=UD(e);return VD(fD({},n,{alpha:qD(0,1,(100*("number"==typeof n.alpha?n.alpha:1)+100*parseFloat(t))/100)}))})),KD=YD;WD((function(t,e){if("transparent"===e)return e;var n=DD(e);return HD(fD({},n,{saturation:qD(0,1,n.saturation+parseFloat(t))}))})),WD((function(t,e){return"transparent"===e?e:HD(fD({},DD(e),{hue:parseFloat(t)}))})),WD((function(t,e){return"transparent"===e?e:HD(fD({},DD(e),{lightness:parseFloat(t)}))})),WD((function(t,e){return"transparent"===e?e:HD(fD({},DD(e),{saturation:parseFloat(t)}))})),WD((function(t,e){return"transparent"===e?e:$D(parseFloat(t),"rgb(0, 0, 0)",e)})),WD((function(t,e){return"transparent"===e?e:$D(parseFloat(t),"rgb(255, 255, 255)",e)})),WD((function(t,e){if("transparent"===e)return e;var n=UD(e);return VD(fD({},n,{alpha:qD(0,1,+(100*("number"==typeof n.alpha?n.alpha:1)-100*parseFloat(t)).toFixed(2)/100)}))}));var ZD=Object.freeze({Linear:Object.freeze({None:function(t){return t},In:function(t){return t},Out:function(t){return t},InOut:function(t){return t}}),Quadratic:Object.freeze({In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}}),Cubic:Object.freeze({In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}}),Quartic:Object.freeze({In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}}),Quintic:Object.freeze({In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}}),Sinusoidal:Object.freeze({In:function(t){return 1-Math.sin((1-t)*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.sin(Math.PI*(.5-t)))}}),Exponential:Object.freeze({In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}}),Circular:Object.freeze({In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}}),Elastic:Object.freeze({In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}}),Back:Object.freeze({In:function(t){var e=1.70158;return 1===t?1:t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return 0===t?0:--t*t*((e+1)*t+e)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}}),Bounce:Object.freeze({In:function(t){return 1-ZD.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*ZD.Bounce.In(2*t):.5*ZD.Bounce.Out(2*t-1)+.5}}),generatePow:function(t){return void 0===t&&(t=4),t=(t=t<Number.EPSILON?Number.EPSILON:t)>1e4?1e4:t,{In:function(e){return Math.pow(e,t)},Out:function(e){return 1-Math.pow(1-e,t)},InOut:function(e){return e<.5?Math.pow(2*e,t)/2:(1-Math.pow(2-2*e,t))/2+.5}}}}),QD=function(){return performance.now()},JD=function(){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._tweens={},this._tweensAddedDuringUpdate={},this.add.apply(this,t)}return t.prototype.getAll=function(){var t=this;return Object.keys(this._tweens).map((function(e){return t._tweens[e]}))},t.prototype.removeAll=function(){this._tweens={}},t.prototype.add=function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];for(var i=0,r=e;i<r.length;i++){var s=r[i];null===(t=s._group)||void 0===t||t.remove(s),s._group=this,this._tweens[s.getId()]=s,this._tweensAddedDuringUpdate[s.getId()]=s}},t.prototype.remove=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=0,i=t;n<i.length;n++){var r=i[n];r._group=void 0,delete this._tweens[r.getId()],delete this._tweensAddedDuringUpdate[r.getId()]}},t.prototype.allStopped=function(){return this.getAll().every((function(t){return!t.isPlaying()}))},t.prototype.update=function(t,e){void 0===t&&(t=QD()),void 0===e&&(e=!0);var n=Object.keys(this._tweens);if(0!==n.length)for(;n.length>0;){this._tweensAddedDuringUpdate={};for(var i=0;i<n.length;i++){var r=this._tweens[n[i]],s=!e;r&&!1===r.update(t,s)&&!e&&this.remove(r)}n=Object.keys(this._tweensAddedDuringUpdate)}},t}(),tO={Linear:function(t,e){var n=t.length-1,i=n*e,r=Math.floor(i),s=tO.Utils.Linear;return e<0?s(t[0],t[1],i):e>1?s(t[n],t[n-1],n-i):s(t[r],t[r+1>n?n:r+1],i-r)},Bezier:function(t,e){for(var n=0,i=t.length-1,r=Math.pow,s=tO.Utils.Bernstein,a=0;a<=i;a++)n+=r(1-e,i-a)*r(e,a)*t[a]*s(i,a);return n},CatmullRom:function(t,e){var n=t.length-1,i=n*e,r=Math.floor(i),s=tO.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(r=Math.floor(i=n*(1+e))),s(t[(r-1+n)%n],t[r],t[(r+1)%n],t[(r+2)%n],i-r)):e<0?t[0]-(s(t[0],t[0],t[1],t[1],-i)-t[0]):e>1?t[n]-(s(t[n],t[n],t[n-1],t[n-1],i-n)-t[n]):s(t[r?r-1:0],t[r],t[n<r+1?n:r+1],t[n<r+2?n:r+2],i-r)},Utils:{Linear:function(t,e,n){return(e-t)*n+t},Bernstein:function(t,e){var n=tO.Utils.Factorial;return n(t)/n(e)/n(t-e)},Factorial:function(){var t=[1];return function(e){var n=1;if(t[e])return t[e];for(var i=e;i>1;i--)n*=i;return t[e]=n,n}}(),CatmullRom:function(t,e,n,i,r){var s=.5*(n-t),a=.5*(i-e),o=r*r;return(2*e-2*n+s+a)*(r*o)+(-3*e+3*n-2*s-a)*o+s*r+e}}},eO=function(){function t(){}return t.nextId=function(){return t._nextId++},t._nextId=0,t}(),nO=new JD,iO=function(){function t(t,e){this._isPaused=!1,this._pauseStart=0,this._valuesStart={},this._valuesEnd={},this._valuesStartRepeat={},this._duration=1e3,this._isDynamic=!1,this._initialRepeat=0,this._repeat=0,this._yoyo=!1,this._isPlaying=!1,this._reversed=!1,this._delayTime=0,this._startTime=0,this._easingFunction=ZD.Linear.None,this._interpolationFunction=tO.Linear,this._chainedTweens=[],this._onStartCallbackFired=!1,this._onEveryStartCallbackFired=!1,this._id=eO.nextId(),this._isChainStopped=!1,this._propertiesAreSetUp=!1,this._goToEnd=!1,this._object=t,"object"==typeof e?(this._group=e,e.add(this)):!0===e&&(this._group=nO,nO.add(this))}return t.prototype.getId=function(){return this._id},t.prototype.isPlaying=function(){return this._isPlaying},t.prototype.isPaused=function(){return this._isPaused},t.prototype.getDuration=function(){return this._duration},t.prototype.to=function(t,e){if(void 0===e&&(e=1e3),this._isPlaying)throw new Error("Can not call Tween.to() while Tween is already started or paused. Stop the Tween first.");return this._valuesEnd=t,this._propertiesAreSetUp=!1,this._duration=e<0?0:e,this},t.prototype.duration=function(t){return void 0===t&&(t=1e3),this._duration=t<0?0:t,this},t.prototype.dynamic=function(t){return void 0===t&&(t=!1),this._isDynamic=t,this},t.prototype.start=function(t,e){if(void 0===t&&(t=QD()),void 0===e&&(e=!1),this._isPlaying)return this;if(this._repeat=this._initialRepeat,this._reversed)for(var n in this._reversed=!1,this._valuesStartRepeat)this._swapEndStartRepeatValues(n),this._valuesStart[n]=this._valuesStartRepeat[n];if(this._isPlaying=!0,this._isPaused=!1,this._onStartCallbackFired=!1,this._onEveryStartCallbackFired=!1,this._isChainStopped=!1,this._startTime=t,this._startTime+=this._delayTime,!this._propertiesAreSetUp||e){if(this._propertiesAreSetUp=!0,!this._isDynamic){var i={};for(var r in this._valuesEnd)i[r]=this._valuesEnd[r];this._valuesEnd=i}this._setupProperties(this._object,this._valuesStart,this._valuesEnd,this._valuesStartRepeat,e)}return this},t.prototype.startFromCurrentValues=function(t){return this.start(t,!0)},t.prototype._setupProperties=function(t,e,n,i,r){for(var s in n){var a=t[s],o=Array.isArray(a),l=o?"array":typeof a,h=!o&&Array.isArray(n[s]);if("undefined"!==l&&"function"!==l){if(h){if(0===(g=n[s]).length)continue;for(var u=[a],c=0,d=g.length;c<d;c+=1){var p=this._handleRelativeValue(a,g[c]);if(isNaN(p)){h=!1,console.warn("Found invalid interpolation list. Skipping.");break}u.push(p)}h&&(n[s]=u)}if("object"!==l&&!o||!a||h)(void 0===e[s]||r)&&(e[s]=a),o||(e[s]*=1),i[s]=h?n[s].slice().reverse():e[s]||0;else{e[s]=o?[]:{};var f=a;for(var m in f)e[s][m]=f[m];i[s]=o?[]:{};var g=n[s];if(!this._isDynamic){var _={};for(var m in g)_[m]=g[m];n[s]=g=_}this._setupProperties(f,e[s],g,i[s],r)}}}},t.prototype.stop=function(){return this._isChainStopped||(this._isChainStopped=!0,this.stopChainedTweens()),this._isPlaying?(this._isPlaying=!1,this._isPaused=!1,this._onStopCallback&&this._onStopCallback(this._object),this):this},t.prototype.end=function(){return this._goToEnd=!0,this.update(this._startTime+this._duration),this},t.prototype.pause=function(t){return void 0===t&&(t=QD()),this._isPaused||!this._isPlaying||(this._isPaused=!0,this._pauseStart=t),this},t.prototype.resume=function(t){return void 0===t&&(t=QD()),this._isPaused&&this._isPlaying?(this._isPaused=!1,this._startTime+=t-this._pauseStart,this._pauseStart=0,this):this},t.prototype.stopChainedTweens=function(){for(var t=0,e=this._chainedTweens.length;t<e;t++)this._chainedTweens[t].stop();return this},t.prototype.group=function(t){return t?(t.add(this),this):(console.warn("tween.group() without args has been removed, use group.add(tween) instead."),this)},t.prototype.remove=function(){var t;return null===(t=this._group)||void 0===t||t.remove(this),this},t.prototype.delay=function(t){return void 0===t&&(t=0),this._delayTime=t,this},t.prototype.repeat=function(t){return void 0===t&&(t=0),this._initialRepeat=t,this._repeat=t,this},t.prototype.repeatDelay=function(t){return this._repeatDelayTime=t,this},t.prototype.yoyo=function(t){return void 0===t&&(t=!1),this._yoyo=t,this},t.prototype.easing=function(t){return void 0===t&&(t=ZD.Linear.None),this._easingFunction=t,this},t.prototype.interpolation=function(t){return void 0===t&&(t=tO.Linear),this._interpolationFunction=t,this},t.prototype.chain=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._chainedTweens=t,this},t.prototype.onStart=function(t){return this._onStartCallback=t,this},t.prototype.onEveryStart=function(t){return this._onEveryStartCallback=t,this},t.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},t.prototype.onRepeat=function(t){return this._onRepeatCallback=t,this},t.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},t.prototype.onStop=function(t){return this._onStopCallback=t,this},t.prototype.update=function(e,n){var i,r,s=this;if(void 0===e&&(e=QD()),void 0===n&&(n=t.autoStartOnUpdate),this._isPaused)return!0;if(!this._goToEnd&&!this._isPlaying){if(!n)return!1;this.start(e,!0)}if(this._goToEnd=!1,e<this._startTime)return!0;!1===this._onStartCallbackFired&&(this._onStartCallback&&this._onStartCallback(this._object),this._onStartCallbackFired=!0),!1===this._onEveryStartCallbackFired&&(this._onEveryStartCallback&&this._onEveryStartCallback(this._object),this._onEveryStartCallbackFired=!0);var a=e-this._startTime,o=this._duration+(null!==(i=this._repeatDelayTime)&&void 0!==i?i:this._delayTime),l=this._duration+this._repeat*o,h=function(){if(0===s._duration)return 1;if(a>l)return 1;var t=Math.trunc(a/o),e=a-t*o,n=Math.min(e/s._duration,1);return 0===n&&a===s._duration?1:n}(),u=this._easingFunction(h);if(this._updateProperties(this._object,this._valuesStart,this._valuesEnd,u),this._onUpdateCallback&&this._onUpdateCallback(this._object,h),0===this._duration||a>=this._duration){if(this._repeat>0){var c=Math.min(Math.trunc((a-this._duration)/o)+1,this._repeat);for(r in isFinite(this._repeat)&&(this._repeat-=c),this._valuesStartRepeat)this._yoyo||"string"!=typeof this._valuesEnd[r]||(this._valuesStartRepeat[r]=this._valuesStartRepeat[r]+parseFloat(this._valuesEnd[r])),this._yoyo&&this._swapEndStartRepeatValues(r),this._valuesStart[r]=this._valuesStartRepeat[r];return this._yoyo&&(this._reversed=!this._reversed),this._startTime+=o*c,this._onRepeatCallback&&this._onRepeatCallback(this._object),this._onEveryStartCallbackFired=!1,!0}this._onCompleteCallback&&this._onCompleteCallback(this._object);for(var d=0,p=this._chainedTweens.length;d<p;d++)this._chainedTweens[d].start(this._startTime+this._duration,!1);return this._isPlaying=!1,!1}return!0},t.prototype._updateProperties=function(t,e,n,i){for(var r in n)if(void 0!==e[r]){var s=e[r]||0,a=n[r],o=Array.isArray(t[r]),l=Array.isArray(a);!o&&l?t[r]=this._interpolationFunction(a,i):"object"==typeof a&&a?this._updateProperties(t[r],s,a,i):"number"==typeof(a=this._handleRelativeValue(s,a))&&(t[r]=s+(a-s)*i)}},t.prototype._handleRelativeValue=function(t,e){return"string"!=typeof e?e:"+"===e.charAt(0)||"-"===e.charAt(0)?t+parseFloat(e):parseFloat(e)},t.prototype._swapEndStartRepeatValues=function(t){var e=this._valuesStartRepeat[t],n=this._valuesEnd[t];this._valuesStartRepeat[t]="string"==typeof n?this._valuesStartRepeat[t]+parseFloat(n):this._valuesEnd[t],this._valuesEnd[t]=e},t.autoStartOnUpdate=!1,t}(),rO=nO;rO.getAll.bind(rO),rO.removeAll.bind(rO),rO.add.bind(rO),rO.remove.bind(rO),rO.update.bind(rO);function sO(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=Array(e);n<e;n++)i[n]=t[n];return i}function aO(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function oO(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var i,r,s,a,o=[],l=!0,h=!1;try{if(s=(n=n.call(t)).next,0===e);else for(;!(l=(i=s.call(n)).done)&&(o.push(i.value),o.length!==e);l=!0);}catch(t){h=!0,r=t}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(h)throw r}}return o}}(t,e)||hO(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function lO(t){return function(t){if(Array.isArray(t))return sO(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||hO(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function hO(t,e){if(t){if("string"==typeof t)return sO(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?sO(t,e):void 0}}!function(t,e){void 0===e&&(e={});var n=e.insertAt;if("undefined"!=typeof document){var i=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===n&&i.firstChild?i.insertBefore(r,i.firstChild):i.appendChild(r),r.styleSheet?r.styleSheet.cssText=t:r.appendChild(document.createTextNode(t))}}(".scene-nav-info {\n bottom: 5px;\n width: 100%;\n text-align: center;\n color: slategrey;\n opacity: 0.7;\n font-size: 10px;\n}\n\n.scene-tooltip {\n top: 0;\n color: lavender;\n font-size: 15px;\n}\n\n.scene-nav-info, .scene-tooltip {\n position: absolute;\n font-family: sans-serif;\n pointer-events: none;\n user-select: none;\n}\n\n.scene-container canvas:focus {\n outline: none;\n}");var uO=window.THREE?window.THREE:{WebGLRenderer:class{constructor(t={}){const{canvas:e=Ae(),context:n=null,depth:i=!0,stencil:r=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:l=!0,preserveDrawingBuffer:h=!1,powerPreference:u="default",failIfMajorPerformanceCaveat:c=!1,reverseDepthBuffer:d=!1}=t;let p;if(this.isWebGLRenderer=!0,null!==n){if("undefined"!=typeof WebGLRenderingContext&&n instanceof WebGLRenderingContext)throw new Error("THREE.WebGLRenderer: WebGL 1 is not supported since r163.");p=n.getContextAttributes().alpha}else p=a;const f=new Uint32Array(4),m=new Int32Array(4);let g=null,_=null;const v=[],y=[];this.domElement=e,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this._outputColorSpace=$t,this.toneMapping=0,this.toneMappingExposure=1;const x=this;let b=!1,S=0,M=0,T=null,w=-1,E=null;const A=new We,R=new We;let C=null;const N=new xi(0);let P=0,I=e.width,L=e.height,U=1,D=null,O=null;const F=new We(0,0,I,L),B=new We(0,0,I,L);let z=!1;const k=new yr;let G=!1,V=!1;const H=new Rn,j=new Rn,W=new Ze,q=new We,X={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};let $=!1;function Y(){return null===T?U:1}let K,J,tt,nt,rt,ht,ut,ct,dt,gt,_t,vt,yt,xt,bt,St,Mt,Tt,wt,Et,At,Rt,Ct,Nt,Pt=n;function It(t,n){return e.getContext(t,n)}try{const t={alpha:!0,depth:i,stencil:r,antialias:o,premultipliedAlpha:l,preserveDrawingBuffer:h,powerPreference:u,failIfMajorPerformanceCaveat:c};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${s}`),e.addEventListener("webglcontextlost",Dt,!1),e.addEventListener("webglcontextrestored",Ot,!1),e.addEventListener("webglcontextcreationerror",Ft,!1),null===Pt){const e="webgl2";if(Pt=It(e,t),null===Pt)throw It(e)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(t){throw console.error("THREE.WebGLRenderer: "+t.message),t}function Lt(){K=new ts(Pt),K.init(),Rt=new to(Pt,K),J=new Ir(Pt,K,t,Rt),tt=new Za(Pt,K),J.reverseDepthBuffer&&d&&tt.buffers.depth.setReversed(!0),nt=new is(Pt),rt=new Oa,ht=new Ja(Pt,K,tt,rt,J,Rt,nt),ut=new Ur(x),ct=new Jr(x),dt=new br(Pt),Ct=new Nr(Pt,dt),gt=new es(Pt,dt,nt,Ct),_t=new ss(Pt,gt,dt,nt),wt=new rs(Pt,J,ht),St=new Lr(rt),vt=new Da(x,ut,ct,K,J,Ct,St),yt=new ho(x,rt),xt=new ka,bt=new qa(K),Tt=new Cr(x,ut,ct,tt,_t,p,l),Mt=new Ya(x,_t,J),Nt=new uo(Pt,nt,J,tt),Et=new Pr(Pt,K,nt),At=new ns(Pt,K,nt),nt.programs=vt.programs,x.capabilities=J,x.extensions=K,x.properties=rt,x.renderLists=xt,x.shadowMap=Mt,x.state=tt,x.info=nt}Lt();const Ut=new ao(x,Pt);function Dt(t){t.preventDefault(),console.log("THREE.WebGLRenderer: Context Lost."),b=!0}function Ot(){console.log("THREE.WebGLRenderer: Context Restored."),b=!1;const t=nt.autoReset,e=Mt.enabled,n=Mt.autoUpdate,i=Mt.needsUpdate,r=Mt.type;Lt(),nt.autoReset=t,Mt.enabled=e,Mt.autoUpdate=n,Mt.needsUpdate=i,Mt.type=r}function Ft(t){console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ",t.statusMessage)}function Bt(t){const e=t.target;e.removeEventListener("dispose",Bt),function(t){(function(t){const e=rt.get(t).programs;void 0!==e&&(e.forEach((function(t){vt.releaseProgram(t)})),t.isShaderMaterial&&vt.releaseShaderCache(t))})(t),rt.remove(t)}(e)}function zt(t,e,n){!0===t.transparent&&2===t.side&&!1===t.forceSinglePass?(t.side=1,t.needsUpdate=!0,Zt(t,e,n),t.side=0,t.needsUpdate=!0,Zt(t,e,n),t.side=2):Zt(t,e,n)}this.xr=Ut,this.getContext=function(){return Pt},this.getContextAttributes=function(){return Pt.getContextAttributes()},this.forceContextLoss=function(){const t=K.get("WEBGL_lose_context");t&&t.loseContext()},this.forceContextRestore=function(){const t=K.get("WEBGL_lose_context");t&&t.restoreContext()},this.getPixelRatio=function(){return U},this.setPixelRatio=function(t){void 0!==t&&(U=t,this.setSize(I,L,!1))},this.getSize=function(t){return t.set(I,L)},this.setSize=function(t,n,i=!0){Ut.isPresenting?console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting."):(I=t,L=n,e.width=Math.floor(t*U),e.height=Math.floor(n*U),!0===i&&(e.style.width=t+"px",e.style.height=n+"px"),this.setViewport(0,0,t,n))},this.getDrawingBufferSize=function(t){return t.set(I*U,L*U).floor()},this.setDrawingBufferSize=function(t,n,i){I=t,L=n,U=i,e.width=Math.floor(t*i),e.height=Math.floor(n*i),this.setViewport(0,0,t,n)},this.getCurrentViewport=function(t){return t.copy(A)},this.getViewport=function(t){return t.copy(F)},this.setViewport=function(t,e,n,i){t.isVector4?F.set(t.x,t.y,t.z,t.w):F.set(t,e,n,i),tt.viewport(A.copy(F).multiplyScalar(U).round())},this.getScissor=function(t){return t.copy(B)},this.setScissor=function(t,e,n,i){t.isVector4?B.set(t.x,t.y,t.z,t.w):B.set(t,e,n,i),tt.scissor(R.copy(B).multiplyScalar(U).round())},this.getScissorTest=function(){return z},this.setScissorTest=function(t){tt.setScissorTest(z=t)},this.setOpaqueSort=function(t){D=t},this.setTransparentSort=function(t){O=t},this.getClearColor=function(t){return t.copy(Tt.getClearColor())},this.setClearColor=function(){Tt.setClearColor.apply(Tt,arguments)},this.getClearAlpha=function(){return Tt.getClearAlpha()},this.setClearAlpha=function(){Tt.setClearAlpha.apply(Tt,arguments)},this.clear=function(t=!0,e=!0,n=!0){let i=0;if(t){let t=!1;if(null!==T){const e=T.texture.format;t=e===mt||e===ft||e===pt}if(t){const t=T.texture.type,e=t===Q||t===it||t===et||t===lt||t===at||t===ot,n=Tt.getClearColor(),i=Tt.getClearAlpha(),r=n.r,s=n.g,a=n.b;e?(f[0]=r,f[1]=s,f[2]=a,f[3]=i,Pt.clearBufferuiv(Pt.COLOR,0,f)):(m[0]=r,m[1]=s,m[2]=a,m[3]=i,Pt.clearBufferiv(Pt.COLOR,0,m))}else i|=Pt.COLOR_BUFFER_BIT}e&&(i|=Pt.DEPTH_BUFFER_BIT),n&&(i|=Pt.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),Pt.clear(i)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){e.removeEventListener("webglcontextlost",Dt,!1),e.removeEventListener("webglcontextrestored",Ot,!1),e.removeEventListener("webglcontextcreationerror",Ft,!1),xt.dispose(),bt.dispose(),rt.dispose(),ut.dispose(),ct.dispose(),_t.dispose(),Ct.dispose(),Nt.dispose(),vt.dispose(),Ut.dispose(),Ut.removeEventListener("sessionstart",Gt),Ut.removeEventListener("sessionend",Vt),Ht.stop()},this.renderBufferDirect=function(t,e,n,i,r,s){null===e&&(e=X);const a=r.isMesh&&r.matrixWorld.determinant()<0,o=function(t,e,n,i,r){!0!==e.isScene&&(e=X);ht.resetTextureUnits();const s=e.fog,a=i.isMeshStandardMaterial?e.environment:null,o=null===T?x.outputColorSpace:!0===T.isXRRenderTarget?T.texture.colorSpace:Yt,l=(i.isMeshStandardMaterial?ct:ut).get(i.envMap||a),h=!0===i.vertexColors&&!!n.attributes.color&&4===n.attributes.color.itemSize,u=!!n.attributes.tangent&&(!!i.normalMap||i.anisotropy>0),c=!!n.morphAttributes.position,d=!!n.morphAttributes.normal,p=!!n.morphAttributes.color;let f=0;i.toneMapped&&(null!==T&&!0!==T.isXRRenderTarget||(f=x.toneMapping));const m=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,g=void 0!==m?m.length:0,v=rt.get(i),y=_.state.lights;if(!0===G&&(!0===V||t!==E)){const e=t===E&&i.id===w;St.setState(i,t,e)}let b=!1;i.version===v.__version?v.needsLights&&v.lightsStateVersion!==y.state.version||v.outputColorSpace!==o||r.isBatchedMesh&&!1===v.batching?b=!0:r.isBatchedMesh||!0!==v.batching?r.isBatchedMesh&&!0===v.batchingColor&&null===r.colorTexture||r.isBatchedMesh&&!1===v.batchingColor&&null!==r.colorTexture||r.isInstancedMesh&&!1===v.instancing?b=!0:r.isInstancedMesh||!0!==v.instancing?r.isSkinnedMesh&&!1===v.skinning?b=!0:r.isSkinnedMesh||!0!==v.skinning?r.isInstancedMesh&&!0===v.instancingColor&&null===r.instanceColor||r.isInstancedMesh&&!1===v.instancingColor&&null!==r.instanceColor||r.isInstancedMesh&&!0===v.instancingMorph&&null===r.morphTexture||r.isInstancedMesh&&!1===v.instancingMorph&&null!==r.morphTexture||v.envMap!==l||!0===i.fog&&v.fog!==s?b=!0:void 0===v.numClippingPlanes||v.numClippingPlanes===St.numPlanes&&v.numIntersection===St.numIntersection?(v.vertexAlphas!==h||v.vertexTangents!==u||v.morphTargets!==c||v.morphNormals!==d||v.morphColors!==p||v.toneMapping!==f||v.morphTargetsCount!==g)&&(b=!0):b=!0:b=!0:b=!0:b=!0:(b=!0,v.__version=i.version);let S=v.currentProgram;!0===b&&(S=Zt(i,e,r));let M=!1,A=!1,R=!1;const C=S.getUniforms(),N=v.uniforms;tt.useProgram(S.program)&&(M=!0,A=!0,R=!0);i.id!==w&&(w=i.id,A=!0);if(M||E!==t){tt.buffers.depth.getReversed()?(H.copy(t.projectionMatrix),function(t){const e=t.elements;e[2]=.5*e[2]+.5*e[3],e[6]=.5*e[6]+.5*e[7],e[10]=.5*e[10]+.5*e[11],e[14]=.5*e[14]+.5*e[15]}(H),function(t){const e=t.elements;-1===e[11]?(e[10]=-e[10]-1,e[14]=-e[14]):(e[10]=-e[10],e[14]=1-e[14])}(H),C.setValue(Pt,"projectionMatrix",H)):C.setValue(Pt,"projectionMatrix",t.projectionMatrix),C.setValue(Pt,"viewMatrix",t.matrixWorldInverse);const e=C.map.cameraPosition;void 0!==e&&e.setValue(Pt,W.setFromMatrixPosition(t.matrixWorld)),J.logarithmicDepthBuffer&&C.setValue(Pt,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),(i.isMeshPhongMaterial||i.isMeshToonMaterial||i.isMeshLambertMaterial||i.isMeshBasicMaterial||i.isMeshStandardMaterial||i.isShaderMaterial)&&C.setValue(Pt,"isOrthographic",!0===t.isOrthographicCamera),E!==t&&(E=t,A=!0,R=!0)}if(r.isSkinnedMesh){C.setOptional(Pt,r,"bindMatrix"),C.setOptional(Pt,r,"bindMatrixInverse");const t=r.skeleton;t&&(null===t.boneTexture&&t.computeBoneTexture(),C.setValue(Pt,"boneTexture",t.boneTexture,ht))}r.isBatchedMesh&&(C.setOptional(Pt,r,"batchingTexture"),C.setValue(Pt,"batchingTexture",r._matricesTexture,ht),C.setOptional(Pt,r,"batchingIdTexture"),C.setValue(Pt,"batchingIdTexture",r._indirectTexture,ht),C.setOptional(Pt,r,"batchingColorTexture"),null!==r._colorsTexture&&C.setValue(Pt,"batchingColorTexture",r._colorsTexture,ht));const P=n.morphAttributes;void 0===P.position&&void 0===P.normal&&void 0===P.color||wt.update(r,n,S);(A||v.receiveShadow!==r.receiveShadow)&&(v.receiveShadow=r.receiveShadow,C.setValue(Pt,"receiveShadow",r.receiveShadow));i.isMeshGouraudMaterial&&null!==i.envMap&&(N.envMap.value=l,N.flipEnvMap.value=l.isCubeTexture&&!1===l.isRenderTargetTexture?-1:1);i.isMeshStandardMaterial&&null===i.envMap&&null!==e.environment&&(N.envMapIntensity.value=e.environmentIntensity);A&&(C.setValue(Pt,"toneMappingExposure",x.toneMappingExposure),v.needsLights&&(D=R,(I=N).ambientLightColor.needsUpdate=D,I.lightProbe.needsUpdate=D,I.directionalLights.needsUpdate=D,I.directionalLightShadows.needsUpdate=D,I.pointLights.needsUpdate=D,I.pointLightShadows.needsUpdate=D,I.spotLights.needsUpdate=D,I.spotLightShadows.needsUpdate=D,I.rectAreaLights.needsUpdate=D,I.hemisphereLights.needsUpdate=D),s&&!0===i.fog&&yt.refreshFogUniforms(N,s),yt.refreshMaterialUniforms(N,i,U,L,_.state.transmissionRenderTarget[t.id]),ca.upload(Pt,Qt(v),N,ht));var I,D;i.isShaderMaterial&&!0===i.uniformsNeedUpdate&&(ca.upload(Pt,Qt(v),N,ht),i.uniformsNeedUpdate=!1);i.isSpriteMaterial&&C.setValue(Pt,"center",r.center);if(C.setValue(Pt,"modelViewMatrix",r.modelViewMatrix),C.setValue(Pt,"normalMatrix",r.normalMatrix),C.setValue(Pt,"modelMatrix",r.matrixWorld),i.isShaderMaterial||i.isRawShaderMaterial){const t=i.uniformsGroups;for(let e=0,n=t.length;e<n;e++){const n=t[e];Nt.update(n,S),Nt.bind(n,S)}}return S}(t,e,n,i,r);tt.setMaterial(i,a);let l=n.index,h=1;if(!0===i.wireframe){if(l=gt.getWireframeAttribute(n),void 0===l)return;h=2}const u=n.drawRange,c=n.attributes.position;let d=u.start*h,p=(u.start+u.count)*h;null!==s&&(d=Math.max(d,s.start*h),p=Math.min(p,(s.start+s.count)*h)),null!==l?(d=Math.max(d,0),p=Math.min(p,l.count)):null!=c&&(d=Math.max(d,0),p=Math.min(p,c.count));const f=p-d;if(f<0||f===1/0)return;let m;Ct.setup(r,i,o,n,l);let g=Et;if(null!==l&&(m=dt.get(l),g=At,g.setIndex(m)),r.isMesh)!0===i.wireframe?(tt.setLineWidth(i.wireframeLinewidth*Y()),g.setMode(Pt.LINES)):g.setMode(Pt.TRIANGLES);else if(r.isLine){let t=i.linewidth;void 0===t&&(t=1),tt.setLineWidth(t*Y()),r.isLineSegments?g.setMode(Pt.LINES):r.isLineLoop?g.setMode(Pt.LINE_LOOP):g.setMode(Pt.LINE_STRIP)}else r.isPoints?g.setMode(Pt.POINTS):r.isSprite&&g.setMode(Pt.TRIANGLES);if(r.isBatchedMesh)if(null!==r._multiDrawInstances)g.renderMultiDrawInstances(r._multiDrawStarts,r._multiDrawCounts,r._multiDrawCount,r._multiDrawInstances);else if(K.get("WEBGL_multi_draw"))g.renderMultiDraw(r._multiDrawStarts,r._multiDrawCounts,r._multiDrawCount);else{const t=r._multiDrawStarts,e=r._multiDrawCounts,n=r._multiDrawCount,s=l?dt.get(l).bytesPerElement:1,a=rt.get(i).currentProgram.getUniforms();for(let i=0;i<n;i++)a.setValue(Pt,"_gl_DrawID",i),g.render(t[i]/s,e[i])}else if(r.isInstancedMesh)g.renderInstances(d,f,r.count);else if(n.isInstancedBufferGeometry){const t=void 0!==n._maxInstanceCount?n._maxInstanceCount:1/0,e=Math.min(n.instanceCount,t);g.renderInstances(d,f,e)}else g.render(d,f)},this.compile=function(t,e,n=null){null===n&&(n=t),_=bt.get(n),_.init(e),y.push(_),n.traverseVisible((function(t){t.isLight&&t.layers.test(e.layers)&&(_.pushLight(t),t.castShadow&&_.pushShadow(t))})),t!==n&&t.traverseVisible((function(t){t.isLight&&t.layers.test(e.layers)&&(_.pushLight(t),t.castShadow&&_.pushShadow(t))})),_.setupLights();const i=new Set;return t.traverse((function(t){if(!(t.isMesh||t.isPoints||t.isLine||t.isSprite))return;const e=t.material;if(e)if(Array.isArray(e))for(let r=0;r<e.length;r++){const s=e[r];zt(s,n,t),i.add(s)}else zt(e,n,t),i.add(e)})),y.pop(),_=null,i},this.compileAsync=function(t,e,n=null){const i=this.compile(t,e,n);return new Promise((e=>{function n(){i.forEach((function(t){rt.get(t).currentProgram.isReady()&&i.delete(t)})),0!==i.size?setTimeout(n,10):e(t)}null!==K.get("KHR_parallel_shader_compile")?n():setTimeout(n,10)}))};let kt=null;function Gt(){Ht.stop()}function Vt(){Ht.start()}const Ht=new xr;function jt(t,e,n,i){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)n=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)_.pushLight(t),t.castShadow&&_.pushShadow(t);else if(t.isSprite){if(!t.frustumCulled||k.intersectsSprite(t)){i&&q.setFromMatrixPosition(t.matrixWorld).applyMatrix4(j);const e=_t.update(t),r=t.material;r.visible&&g.push(t,e,r,n,q.z,null)}}else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||k.intersectsObject(t))){const e=_t.update(t),r=t.material;if(i&&(void 0!==t.boundingSphere?(null===t.boundingSphere&&t.computeBoundingSphere(),q.copy(t.boundingSphere.center)):(null===e.boundingSphere&&e.computeBoundingSphere(),q.copy(e.boundingSphere.center)),q.applyMatrix4(t.matrixWorld).applyMatrix4(j)),Array.isArray(r)){const i=e.groups;for(let s=0,a=i.length;s<a;s++){const a=i[s],o=r[a.materialIndex];o&&o.visible&&g.push(t,e,o,n,q.z,a)}}else r.visible&&g.push(t,e,r,n,q.z,null)}const r=t.children;for(let t=0,s=r.length;t<s;t++)jt(r[t],e,n,i)}function Wt(t,e,n,i){const r=t.opaque,s=t.transmissive,a=t.transparent;_.setupLightsView(n),!0===G&&St.setGlobalState(x.clippingPlanes,n),i&&tt.viewport(A.copy(i)),r.length>0&&Xt(r,e,n),s.length>0&&Xt(s,e,n),a.length>0&&Xt(a,e,n),tt.buffers.depth.setTest(!0),tt.buffers.depth.setMask(!0),tt.buffers.color.setMask(!0),tt.setPolygonOffset(!1)}function qt(t,e,n,i){if(null!==(!0===n.isScene?n.overrideMaterial:null))return;void 0===_.state.transmissionRenderTarget[i.id]&&(_.state.transmissionRenderTarget[i.id]=new Xe(1,1,{generateMipmaps:!0,type:K.has("EXT_color_buffer_half_float")||K.has("EXT_color_buffer_float")?st:Q,minFilter:Z,samples:4,stencilBuffer:r,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Ne.workingColorSpace}));const s=_.state.transmissionRenderTarget[i.id],a=i.viewport||A;s.setSize(a.z,a.w);const o=x.getRenderTarget();x.setRenderTarget(s),x.getClearColor(N),P=x.getClearAlpha(),P<1&&x.setClearColor(16777215,.5),x.clear(),$&&Tt.render(n);const l=x.toneMapping;x.toneMapping=0;const h=i.viewport;if(void 0!==i.viewport&&(i.viewport=void 0),_.setupLightsView(i),!0===G&&St.setGlobalState(x.clippingPlanes,i),Xt(t,n,i),ht.updateMultisampleRenderTarget(s),ht.updateRenderTargetMipmap(s),!1===K.has("WEBGL_multisampled_render_to_texture")){let t=!1;for(let r=0,s=e.length;r<s;r++){const s=e[r],a=s.object,o=s.geometry,l=s.material,h=s.group;if(2===l.side&&a.layers.test(i.layers)){const e=l.side;l.side=1,l.needsUpdate=!0,Kt(a,n,i,o,l,h),l.side=e,l.needsUpdate=!0,t=!0}}!0===t&&(ht.updateMultisampleRenderTarget(s),ht.updateRenderTargetMipmap(s))}x.setRenderTarget(o),x.setClearColor(N,P),void 0!==h&&(i.viewport=h),x.toneMapping=l}function Xt(t,e,n){const i=!0===e.isScene?e.overrideMaterial:null;for(let r=0,s=t.length;r<s;r++){const s=t[r],a=s.object,o=s.geometry,l=null===i?s.material:i,h=s.group;a.layers.test(n.layers)&&Kt(a,e,n,o,l,h)}}function Kt(t,e,n,i,r,s){t.onBeforeRender(x,e,n,i,r,s),t.modelViewMatrix.multiplyMatrices(n.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix),r.onBeforeRender(x,e,n,i,t,s),!0===r.transparent&&2===r.side&&!1===r.forceSinglePass?(r.side=1,r.needsUpdate=!0,x.renderBufferDirect(n,e,i,r,t,s),r.side=0,r.needsUpdate=!0,x.renderBufferDirect(n,e,i,r,t,s),r.side=2):x.renderBufferDirect(n,e,i,r,t,s),t.onAfterRender(x,e,n,i,r,s)}function Zt(t,e,n){!0!==e.isScene&&(e=X);const i=rt.get(t),r=_.state.lights,s=_.state.shadowsArray,a=r.state.version,o=vt.getParameters(t,r.state,s,e,n),l=vt.getProgramCacheKey(o);let h=i.programs;i.environment=t.isMeshStandardMaterial?e.environment:null,i.fog=e.fog,i.envMap=(t.isMeshStandardMaterial?ct:ut).get(t.envMap||i.environment),i.envMapRotation=null!==i.environment&&null===t.envMap?e.environmentRotation:t.envMapRotation,void 0===h&&(t.addEventListener("dispose",Bt),h=new Map,i.programs=h);let u=h.get(l);if(void 0!==u){if(i.currentProgram===u&&i.lightsStateVersion===a)return Jt(t,o),u}else o.uniforms=vt.getUniforms(t),t.onBeforeCompile(o,x),u=vt.acquireProgram(o,l),h.set(l,u),i.uniforms=o.uniforms;const c=i.uniforms;return(t.isShaderMaterial||t.isRawShaderMaterial)&&!0!==t.clipping||(c.clippingPlanes=St.uniform),Jt(t,o),i.needsLights=function(t){return t.isMeshLambertMaterial||t.isMeshToonMaterial||t.isMeshPhongMaterial||t.isMeshStandardMaterial||t.isShadowMaterial||t.isShaderMaterial&&!0===t.lights}(t),i.lightsStateVersion=a,i.needsLights&&(c.ambientLightColor.value=r.state.ambient,c.lightProbe.value=r.state.probe,c.directionalLights.value=r.state.directional,c.directionalLightShadows.value=r.state.directionalShadow,c.spotLights.value=r.state.spot,c.spotLightShadows.value=r.state.spotShadow,c.rectAreaLights.value=r.state.rectArea,c.ltc_1.value=r.state.rectAreaLTC1,c.ltc_2.value=r.state.rectAreaLTC2,c.pointLights.value=r.state.point,c.pointLightShadows.value=r.state.pointShadow,c.hemisphereLights.value=r.state.hemi,c.directionalShadowMap.value=r.state.directionalShadowMap,c.directionalShadowMatrix.value=r.state.directionalShadowMatrix,c.spotShadowMap.value=r.state.spotShadowMap,c.spotLightMatrix.value=r.state.spotLightMatrix,c.spotLightMap.value=r.state.spotLightMap,c.pointShadowMap.value=r.state.pointShadowMap,c.pointShadowMatrix.value=r.state.pointShadowMatrix),i.currentProgram=u,i.uniformsList=null,u}function Qt(t){if(null===t.uniformsList){const e=t.currentProgram.getUniforms();t.uniformsList=ca.seqWithValue(e.seq,t.uniforms)}return t.uniformsList}function Jt(t,e){const n=rt.get(t);n.outputColorSpace=e.outputColorSpace,n.batching=e.batching,n.batchingColor=e.batchingColor,n.instancing=e.instancing,n.instancingColor=e.instancingColor,n.instancingMorph=e.instancingMorph,n.skinning=e.skinning,n.morphTargets=e.morphTargets,n.morphNormals=e.morphNormals,n.morphColors=e.morphColors,n.morphTargetsCount=e.morphTargetsCount,n.numClippingPlanes=e.numClippingPlanes,n.numIntersection=e.numClipIntersection,n.vertexAlphas=e.vertexAlphas,n.vertexTangents=e.vertexTangents,n.toneMapping=e.toneMapping}Ht.setAnimationLoop((function(t){kt&&kt(t)})),"undefined"!=typeof self&&Ht.setContext(self),this.setAnimationLoop=function(t){kt=t,Ut.setAnimationLoop(t),null===t?Ht.stop():Ht.start()},Ut.addEventListener("sessionstart",Gt),Ut.addEventListener("sessionend",Vt),this.render=function(t,e){if(void 0!==e&&!0!==e.isCamera)return void console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");if(!0===b)return;if(!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld(),null===e.parent&&!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),!0===Ut.enabled&&!0===Ut.isPresenting&&(!0===Ut.cameraAutoUpdate&&Ut.updateCamera(e),e=Ut.getCamera()),!0===t.isScene&&t.onBeforeRender(x,t,e,T),_=bt.get(t,y.length),_.init(e),y.push(_),j.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),k.setFromProjectionMatrix(j),V=this.localClippingEnabled,G=St.init(this.clippingPlanes,V),g=xt.get(t,v.length),g.init(),v.push(g),!0===Ut.enabled&&!0===Ut.isPresenting){const t=x.xr.getDepthSensingMesh();null!==t&&jt(t,e,-1/0,x.sortObjects)}jt(t,e,0,x.sortObjects),g.finish(),!0===x.sortObjects&&g.sort(D,O),$=!1===Ut.enabled||!1===Ut.isPresenting||!1===Ut.hasDepthSensing(),$&&Tt.addToRenderList(g,t),this.info.render.frame++,!0===G&&St.beginShadows();const n=_.state.shadowsArray;Mt.render(n,t,e),!0===G&&St.endShadows(),!0===this.info.autoReset&&this.info.reset();const i=g.opaque,r=g.transmissive;if(_.setupLights(),e.isArrayCamera){const n=e.cameras;if(r.length>0)for(let e=0,s=n.length;e<s;e++){qt(i,r,t,n[e])}$&&Tt.render(t);for(let e=0,i=n.length;e<i;e++){const i=n[e];Wt(g,t,i,i.viewport)}}else r.length>0&&qt(i,r,t,e),$&&Tt.render(t),Wt(g,t,e);null!==T&&(ht.updateMultisampleRenderTarget(T),ht.updateRenderTargetMipmap(T)),!0===t.isScene&&t.onAfterRender(x,t,e),Ct.resetDefaultState(),w=-1,E=null,y.pop(),y.length>0?(_=y[y.length-1],!0===G&&St.setGlobalState(x.clippingPlanes,_.state.camera)):_=null,v.pop(),g=v.length>0?v[v.length-1]:null},this.getActiveCubeFace=function(){return S},this.getActiveMipmapLevel=function(){return M},this.getRenderTarget=function(){return T},this.setRenderTargetTextures=function(t,e,n){rt.get(t.texture).__webglTexture=e,rt.get(t.depthTexture).__webglTexture=n;const i=rt.get(t);i.__hasExternalTextures=!0,i.__autoAllocateDepthBuffer=void 0===n,i.__autoAllocateDepthBuffer||!0===K.has("WEBGL_multisampled_render_to_texture")&&(console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"),i.__useRenderToTexture=!1)},this.setRenderTargetFramebuffer=function(t,e){const n=rt.get(t);n.__webglFramebuffer=e,n.__useDefaultFramebuffer=void 0===e},this.setRenderTarget=function(t,e=0,n=0){T=t,S=e,M=n;let i=!0,r=null,s=!1,a=!1;if(t){const o=rt.get(t);if(void 0!==o.__useDefaultFramebuffer)tt.bindFramebuffer(Pt.FRAMEBUFFER,null),i=!1;else if(void 0===o.__webglFramebuffer)ht.setupRenderTarget(t);else if(o.__hasExternalTextures)ht.rebindTextures(t,rt.get(t.texture).__webglTexture,rt.get(t.depthTexture).__webglTexture);else if(t.depthBuffer){const e=t.depthTexture;if(o.__boundDepthTexture!==e){if(null!==e&&rt.has(e)&&(t.width!==e.image.width||t.height!==e.image.height))throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");ht.setupDepthRenderbuffer(t)}}const l=t.texture;(l.isData3DTexture||l.isDataArrayTexture||l.isCompressedArrayTexture)&&(a=!0);const h=rt.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(r=Array.isArray(h[e])?h[e][n]:h[e],s=!0):r=t.samples>0&&!1===ht.useMultisampledRTT(t)?rt.get(t).__webglMultisampledFramebuffer:Array.isArray(h)?h[n]:h,A.copy(t.viewport),R.copy(t.scissor),C=t.scissorTest}else A.copy(F).multiplyScalar(U).floor(),R.copy(B).multiplyScalar(U).floor(),C=z;if(tt.bindFramebuffer(Pt.FRAMEBUFFER,r)&&i&&tt.drawBuffers(t,r),tt.viewport(A),tt.scissor(R),tt.setScissorTest(C),s){const i=rt.get(t.texture);Pt.framebufferTexture2D(Pt.FRAMEBUFFER,Pt.COLOR_ATTACHMENT0,Pt.TEXTURE_CUBE_MAP_POSITIVE_X+e,i.__webglTexture,n)}else if(a){const i=rt.get(t.texture),r=e||0;Pt.framebufferTextureLayer(Pt.FRAMEBUFFER,Pt.COLOR_ATTACHMENT0,i.__webglTexture,n||0,r)}w=-1},this.readRenderTargetPixels=function(t,e,n,i,r,s,a){if(!t||!t.isWebGLRenderTarget)return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let o=rt.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(o=o[a]),o){tt.bindFramebuffer(Pt.FRAMEBUFFER,o);try{const a=t.texture,o=a.format,l=a.type;if(!J.textureFormatReadable(o))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");if(!J.textureTypeReadable(l))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");e>=0&&e<=t.width-i&&n>=0&&n<=t.height-r&&Pt.readPixels(e,n,i,r,Rt.convert(o),Rt.convert(l),s)}finally{const t=null!==T?rt.get(T).__webglFramebuffer:null;tt.bindFramebuffer(Pt.FRAMEBUFFER,t)}}},this.readRenderTargetPixelsAsync=async function(t,e,n,i,r,s,a){if(!t||!t.isWebGLRenderTarget)throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let o=rt.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(o=o[a]),o){const a=t.texture,l=a.format,h=a.type;if(!J.textureFormatReadable(l))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!J.textureTypeReadable(h))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");if(e>=0&&e<=t.width-i&&n>=0&&n<=t.height-r){tt.bindFramebuffer(Pt.FRAMEBUFFER,o);const t=Pt.createBuffer();Pt.bindBuffer(Pt.PIXEL_PACK_BUFFER,t),Pt.bufferData(Pt.PIXEL_PACK_BUFFER,s.byteLength,Pt.STREAM_READ),Pt.readPixels(e,n,i,r,Rt.convert(l),Rt.convert(h),0);const a=null!==T?rt.get(T).__webglFramebuffer:null;tt.bindFramebuffer(Pt.FRAMEBUFFER,a);const u=Pt.fenceSync(Pt.SYNC_GPU_COMMANDS_COMPLETE,0);return Pt.flush(),await function(t,e,n){return new Promise((function(i,r){setTimeout((function s(){switch(t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0)){case t.WAIT_FAILED:r();break;case t.TIMEOUT_EXPIRED:setTimeout(s,n);break;default:i()}}),n)}))}(Pt,u,4),Pt.bindBuffer(Pt.PIXEL_PACK_BUFFER,t),Pt.getBufferSubData(Pt.PIXEL_PACK_BUFFER,0,s),Pt.deleteBuffer(t),Pt.deleteSync(u),s}throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")}},this.copyFramebufferToTexture=function(t,e=null,n=0){!0!==t.isTexture&&(Ce("WebGLRenderer: copyFramebufferToTexture function signature has changed."),e=arguments[0]||null,t=arguments[1]);const i=Math.pow(2,-n),r=Math.floor(t.image.width*i),s=Math.floor(t.image.height*i),a=null!==e?e.x:0,o=null!==e?e.y:0;ht.setTexture2D(t,0),Pt.copyTexSubImage2D(Pt.TEXTURE_2D,n,0,0,a,o,r,s),tt.unbindTexture()},this.copyTextureToTexture=function(t,e,n=null,i=null,r=0){let s,a,o,l,h,u,c,d,p;!0!==t.isTexture&&(Ce("WebGLRenderer: copyTextureToTexture function signature has changed."),i=arguments[0]||null,t=arguments[1],e=arguments[2],r=arguments[3]||0,n=null);const f=t.isCompressedTexture?t.mipmaps[r]:t.image;null!==n?(s=n.max.x-n.min.x,a=n.max.y-n.min.y,o=n.isBox3?n.max.z-n.min.z:1,l=n.min.x,h=n.min.y,u=n.isBox3?n.min.z:0):(s=f.width,a=f.height,o=f.depth||1,l=0,h=0,u=0),null!==i?(c=i.x,d=i.y,p=i.z):(c=0,d=0,p=0);const m=Rt.convert(e.format),g=Rt.convert(e.type);let _;e.isData3DTexture?(ht.setTexture3D(e,0),_=Pt.TEXTURE_3D):e.isDataArrayTexture||e.isCompressedArrayTexture?(ht.setTexture2DArray(e,0),_=Pt.TEXTURE_2D_ARRAY):(ht.setTexture2D(e,0),_=Pt.TEXTURE_2D),Pt.pixelStorei(Pt.UNPACK_FLIP_Y_WEBGL,e.flipY),Pt.pixelStorei(Pt.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),Pt.pixelStorei(Pt.UNPACK_ALIGNMENT,e.unpackAlignment);const v=Pt.getParameter(Pt.UNPACK_ROW_LENGTH),y=Pt.getParameter(Pt.UNPACK_IMAGE_HEIGHT),x=Pt.getParameter(Pt.UNPACK_SKIP_PIXELS),b=Pt.getParameter(Pt.UNPACK_SKIP_ROWS),S=Pt.getParameter(Pt.UNPACK_SKIP_IMAGES);Pt.pixelStorei(Pt.UNPACK_ROW_LENGTH,f.width),Pt.pixelStorei(Pt.UNPACK_IMAGE_HEIGHT,f.height),Pt.pixelStorei(Pt.UNPACK_SKIP_PIXELS,l),Pt.pixelStorei(Pt.UNPACK_SKIP_ROWS,h),Pt.pixelStorei(Pt.UNPACK_SKIP_IMAGES,u);const M=t.isDataArrayTexture||t.isData3DTexture,T=e.isDataArrayTexture||e.isData3DTexture;if(t.isRenderTargetTexture||t.isDepthTexture){const n=rt.get(t),i=rt.get(e),f=rt.get(n.__renderTarget),m=rt.get(i.__renderTarget);tt.bindFramebuffer(Pt.READ_FRAMEBUFFER,f.__webglFramebuffer),tt.bindFramebuffer(Pt.DRAW_FRAMEBUFFER,m.__webglFramebuffer);for(let n=0;n<o;n++)M&&Pt.framebufferTextureLayer(Pt.READ_FRAMEBUFFER,Pt.COLOR_ATTACHMENT0,rt.get(t).__webglTexture,r,u+n),t.isDepthTexture?(T&&Pt.framebufferTextureLayer(Pt.DRAW_FRAMEBUFFER,Pt.COLOR_ATTACHMENT0,rt.get(e).__webglTexture,r,p+n),Pt.blitFramebuffer(l,h,s,a,c,d,s,a,Pt.DEPTH_BUFFER_BIT,Pt.NEAREST)):T?Pt.copyTexSubImage3D(_,r,c,d,p+n,l,h,s,a):Pt.copyTexSubImage2D(_,r,c,d,p+n,l,h,s,a);tt.bindFramebuffer(Pt.READ_FRAMEBUFFER,null),tt.bindFramebuffer(Pt.DRAW_FRAMEBUFFER,null)}else T?t.isDataTexture||t.isData3DTexture?Pt.texSubImage3D(_,r,c,d,p,s,a,o,m,g,f.data):e.isCompressedArrayTexture?Pt.compressedTexSubImage3D(_,r,c,d,p,s,a,o,m,f.data):Pt.texSubImage3D(_,r,c,d,p,s,a,o,m,g,f):t.isDataTexture?Pt.texSubImage2D(Pt.TEXTURE_2D,r,c,d,s,a,m,g,f.data):t.isCompressedTexture?Pt.compressedTexSubImage2D(Pt.TEXTURE_2D,r,c,d,f.width,f.height,m,f.data):Pt.texSubImage2D(Pt.TEXTURE_2D,r,c,d,s,a,m,g,f);Pt.pixelStorei(Pt.UNPACK_ROW_LENGTH,v),Pt.pixelStorei(Pt.UNPACK_IMAGE_HEIGHT,y),Pt.pixelStorei(Pt.UNPACK_SKIP_PIXELS,x),Pt.pixelStorei(Pt.UNPACK_SKIP_ROWS,b),Pt.pixelStorei(Pt.UNPACK_SKIP_IMAGES,S),0===r&&e.generateMipmaps&&Pt.generateMipmap(_),tt.unbindTexture()},this.copyTextureToTexture3D=function(t,e,n=null,i=null,r=0){return!0!==t.isTexture&&(Ce("WebGLRenderer: copyTextureToTexture3D function signature has changed."),n=arguments[0]||null,i=arguments[1]||null,t=arguments[2],e=arguments[3],r=arguments[4]||0),Ce('WebGLRenderer: copyTextureToTexture3D function has been deprecated. Use "copyTextureToTexture" instead.'),this.copyTextureToTexture(t,e,n,i,r)},this.initRenderTarget=function(t){void 0===rt.get(t).__webglFramebuffer&&ht.setupRenderTarget(t)},this.initTexture=function(t){t.isCubeTexture?ht.setTextureCube(t,0):t.isData3DTexture?ht.setTexture3D(t,0):t.isDataArrayTexture||t.isCompressedArrayTexture?ht.setTexture2DArray(t,0):ht.setTexture2D(t,0),tt.unbindTexture()},this.resetState=function(){S=0,M=0,T=null,tt.reset(),Ct.reset()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return le}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorspace=Ne._getDrawingBufferColorSpace(t),e.unpackColorSpace=Ne._getUnpackColorSpace()}},Scene:class extends ei{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 Bn,this.environmentIntensity=1,this.environmentRotation=new Bn,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}},PerspectiveCamera:lr,Raycaster:Qo,SRGBColorSpace:$t,TextureLoader:class extends Go{constructor(t){super(t)}load(t,e,n,i){const r=new je,s=new Vo(this.manager);return s.setCrossOrigin(this.crossOrigin),s.setPath(this.path),s.load(t,(function(t){r.image=t,r.needsUpdate=!0,void 0!==e&&e(r)}),n,i),r}},Vector2:Se,Vector3:Ze,Box3:tn,Color:xi,Mesh:Ki,SphereGeometry:Oo,MeshBasicMaterial:Ti,BackSide:1,EventDispatcher:ue,MOUSE:a,Quaternion:Ke,Spherical:el,Clock:Yo},cO=ju({props:{width:{default:window.innerWidth,onChange:function(t,e,n){isNaN(t)&&(e.width=n)}},height:{default:window.innerHeight,onChange:function(t,e,n){isNaN(t)&&(e.height=n)}},backgroundColor:{default:"#000011"},backgroundImageUrl:{},onBackgroundImageLoaded:{},showNavInfo:{default:!0},skyRadius:{default:5e4},objects:{default:[]},lights:{default:[]},enablePointerInteraction:{default:!0,onChange:function(t,e){e.hoverObj=null,e.toolTipElem&&(e.toolTipElem.innerHTML="")},triggerUpdate:!1},lineHoverPrecision:{default:1,triggerUpdate:!1},hoverOrderComparator:{default:function(){return-1},triggerUpdate:!1},hoverFilter:{default:function(){return!0},triggerUpdate:!1},tooltipContent:{triggerUpdate:!1},hoverDuringDrag:{default:!1,triggerUpdate:!1},clickAfterDrag:{default:!1,triggerUpdate:!1},onHover:{default:function(){},triggerUpdate:!1},onClick:{default:function(){},triggerUpdate:!1},onRightClick:{triggerUpdate:!1}},methods:{tick:function(t){if(t.initialised){if(t.controls.update&&t.controls.update(Math.min(1,t.clock.getDelta())),t.postProcessingComposer?t.postProcessingComposer.render():t.renderer.render(t.scene,t.camera),t.extraRenderers.forEach((function(e){return e.render(t.scene,t.camera)})),t.enablePointerInteraction){var e=null;if(t.hoverDuringDrag||!t.isPointerDragging){var n=this.intersectingObjects(t.pointerPos.x,t.pointerPos.y).filter((function(e){return t.hoverFilter(e.object)})).sort((function(e,n){return t.hoverOrderComparator(e.object,n.object)})),i=n.length?n[0]:null;e=i?i.object:null,t.intersectionPoint=i?i.point:null}e!==t.hoverObj&&(t.onHover(e,t.hoverObj),t.toolTipElem.innerHTML=e&&Wu(t.tooltipContent)(e)||"",t.hoverObj=e)}t.tweenGroup.update()}return this},getPointerPos:function(t){var e=t.pointerPos;return{x:e.x,y:e.y}},cameraPosition:function(t,e,n,i){var r=t.camera;if(e&&t.initialised){var s=e,a=n||{x:0,y:0,z:0};if(i){var o=Object.assign({},r.position),l=c();t.tweenGroup.add(new iO(o).to(s,i).easing(ZD.Quadratic.Out).onUpdate(h).start()),t.tweenGroup.add(new iO(l).to(a,i/3).easing(ZD.Quadratic.Out).onUpdate(u).start())}else h(s),u(a);return this}return Object.assign({},r.position,{lookAt:c()});function h(t){var e=t.x,n=t.y,i=t.z;void 0!==e&&(r.position.x=e),void 0!==n&&(r.position.y=n),void 0!==i&&(r.position.z=i)}function u(e){var n=new uO.Vector3(e.x,e.y,e.z);t.controls.target?t.controls.target=n:r.lookAt(n)}function c(){return Object.assign(new uO.Vector3(0,0,-1e3).applyQuaternion(r.quaternion).add(r.position))}},zoomToFit:function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10,i=arguments.length,r=new Array(i>3?i-3:0),s=3;s<i;s++)r[s-3]=arguments[s];return this.fitToBbox(this.getBbox.apply(this,r),e,n)},fitToBbox:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10,r=t.camera;if(e){var s=new uO.Vector3(0,0,0),a=2*Math.max.apply(Math,lO(Object.entries(e).map((function(t){var e=oO(t,2),n=e[0],i=e[1];return Math.max.apply(Math,lO(i.map((function(t){return Math.abs(s[n]-t)}))))})))),o=(1-2*i/t.height)*r.fov,l=a/Math.atan(o*Math.PI/180),h=l/r.aspect,u=Math.max(l,h);if(u>0){var c=s.clone().sub(r.position).normalize().multiplyScalar(-u);this.cameraPosition(c,s,n)}}return this},getBbox:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){return!0},n=new uO.Box3(new uO.Vector3(0,0,0),new uO.Vector3(0,0,0)),i=t.objects.filter(e);return i.length?(i.forEach((function(t){return n.expandByObject(t)})),Object.assign.apply(Object,lO(["x","y","z"].map((function(t){return aO({},t,[n.min[t],n.max[t]])}))))):null},getScreenCoords:function(t,e,n,i){var r=new uO.Vector3(e,n,i);return r.project(this.camera()),{x:(r.x+1)*t.width/2,y:-(r.y-1)*t.height/2}},getSceneCoords:function(t,e,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,r=new uO.Vector2(e/t.width*2-1,-n/t.height*2+1),s=new uO.Raycaster;return s.setFromCamera(r,t.camera),Object.assign({},s.ray.at(i,new uO.Vector3))},intersectingObjects:function(t,e,n){var i=new uO.Vector2(e/t.width*2-1,-n/t.height*2+1),r=new uO.Raycaster;return r.params.Line.threshold=t.lineHoverPrecision,r.setFromCamera(i,t.camera),r.intersectObjects(t.objects,!0)},renderer:function(t){return t.renderer},scene:function(t){return t.scene},camera:function(t){return t.camera},postProcessingComposer:function(t){return t.postProcessingComposer},controls:function(t){return t.controls},tbControls:function(t){return t.controls}},stateInit:function(){return{scene:new uO.Scene,camera:new uO.PerspectiveCamera,clock:new uO.Clock,tweenGroup:new JD}},init:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=n.controlType,r=void 0===i?"trackball":i,s=n.useWebGPU,a=void 0!==s&&s,o=n.rendererConfig,l=void 0===o?{}:o,h=n.extraRenderers,u=void 0===h?[]:h,c=n.waitForLoadComplete,d=void 0===c||c;t.innerHTML="",t.appendChild(e.container=document.createElement("div")),e.container.className="scene-container",e.container.style.position="relative",e.container.appendChild(e.navInfo=document.createElement("div")),e.navInfo.className="scene-nav-info",e.navInfo.textContent={orbit:"Left-click: rotate, Mouse-wheel/middle-click: zoom, Right-click: pan",trackball:"Left-click: rotate, Mouse-wheel/middle-click: zoom, Right-click: pan",fly:"WASD: move, R|F: up | down, Q|E: roll, up|down: pitch, left|right: yaw"}[r]||"",e.navInfo.style.display=e.showNavInfo?null:"none",e.toolTipElem=document.createElement("div"),e.toolTipElem.classList.add("scene-tooltip"),e.container.appendChild(e.toolTipElem),e.pointerPos=new uO.Vector2,e.pointerPos.x=-2,e.pointerPos.y=-2,["pointermove","pointerdown"].forEach((function(t){return e.container.addEventListener(t,(function(n){if("pointerdown"===t&&(e.isPointerPressed=!0),!e.isPointerDragging&&"pointermove"===n.type&&(n.pressure>0||e.isPointerPressed)&&("touch"!==n.pointerType||void 0===n.movementX||[n.movementX,n.movementY].some((function(t){return Math.abs(t)>1})))&&(e.isPointerDragging=!0),e.enablePointerInteraction){var i=(r=e.container,s=r.getBoundingClientRect(),a=window.pageXOffset||document.documentElement.scrollLeft,o=window.pageYOffset||document.documentElement.scrollTop,{top:s.top+o,left:s.left+a});e.pointerPos.x=n.pageX-i.left,e.pointerPos.y=n.pageY-i.top,e.toolTipElem.style.top="".concat(e.pointerPos.y,"px"),e.toolTipElem.style.left="".concat(e.pointerPos.x,"px"),e.toolTipElem.style.transform="translate(-".concat(e.pointerPos.x/e.width*100,"%, ").concat(e.height-e.pointerPos.y<100?"calc(-100% - 8px)":"21px",")")}var r,s,a,o}),{passive:!0})})),e.container.addEventListener("pointerup",(function(t){e.isPointerPressed=!1,e.isPointerDragging&&(e.isPointerDragging=!1,!e.clickAfterDrag)||requestAnimationFrame((function(){0===t.button&&e.onClick(e.hoverObj||null,t,e.intersectionPoint),2===t.button&&e.onRightClick&&e.onRightClick(e.hoverObj||null,t,e.intersectionPoint)}))}),{passive:!0,capture:!0}),e.container.addEventListener("contextmenu",(function(t){e.onRightClick&&t.preventDefault()})),e.renderer=new(a?DL:uO.WebGLRenderer)(Object.assign({antialias:!0,alpha:!0},l)),e.renderer.setPixelRatio(Math.min(2,window.devicePixelRatio)),e.container.appendChild(e.renderer.domElement),e.extraRenderers=u,e.extraRenderers.forEach((function(t){t.domElement.style.position="absolute",t.domElement.style.top="0px",t.domElement.style.pointerEvents="none",e.container.appendChild(t.domElement)})),e.postProcessingComposer=new dD(e.renderer),e.postProcessingComposer.addPass(new pD(e.scene,e.camera)),e.controls=new{trackball:nU,orbit:UU,fly:KU}[r](e.camera,e.renderer.domElement),"fly"===r&&(e.controls.movementSpeed=300,e.controls.rollSpeed=Math.PI/6,e.controls.dragToLook=!0),"trackball"!==r&&"orbit"!==r||(e.controls.minDistance=.1,e.controls.maxDistance=e.skyRadius,e.controls.addEventListener("start",(function(){e.controlsEngaged=!0})),e.controls.addEventListener("change",(function(){e.controlsEngaged&&(e.controlsDragging=!0)})),e.controls.addEventListener("end",(function(){e.controlsEngaged=!1,e.controlsDragging=!1}))),[e.renderer,e.postProcessingComposer].concat(lO(e.extraRenderers)).forEach((function(t){return t.setSize(e.width,e.height)})),e.camera.aspect=e.width/e.height,e.camera.updateProjectionMatrix(),e.camera.position.z=1e3,e.scene.add(e.skysphere=new uO.Mesh),e.skysphere.visible=!1,e.loadComplete=e.scene.visible=!d,window.scene=e.scene},update:function(t,e){if(t.width&&t.height&&(e.hasOwnProperty("width")||e.hasOwnProperty("height"))&&(t.container.style.width="".concat(t.width,"px"),t.container.style.height="".concat(t.height,"px"),[t.renderer,t.postProcessingComposer].concat(lO(t.extraRenderers)).forEach((function(e){return e.setSize(t.width,t.height)})),t.camera.aspect=t.width/t.height,t.camera.updateProjectionMatrix()),e.hasOwnProperty("skyRadius")&&t.skyRadius&&(t.controls.hasOwnProperty("maxDistance")&&e.skyRadius&&(t.controls.maxDistance=Math.min(t.controls.maxDistance,t.skyRadius)),t.camera.far=2.5*t.skyRadius,t.camera.updateProjectionMatrix(),t.skysphere.geometry=new uO.SphereGeometry(t.skyRadius)),e.hasOwnProperty("backgroundColor")){var n=UD(t.backgroundColor).alpha;void 0===n&&(n=1),t.renderer.setClearColor(new uO.Color(KD(1,t.backgroundColor)),n)}function i(){t.loadComplete=t.scene.visible=!0}e.hasOwnProperty("backgroundImageUrl")&&(t.backgroundImageUrl?(new uO.TextureLoader).load(t.backgroundImageUrl,(function(e){e.colorSpace=uO.SRGBColorSpace,t.skysphere.material=new uO.MeshBasicMaterial({map:e,side:uO.BackSide}),t.skysphere.visible=!0,t.onBackgroundImageLoaded&&setTimeout(t.onBackgroundImageLoaded),!t.loadComplete&&i()})):(t.skysphere.visible=!1,t.skysphere.material.map=null,!t.loadComplete&&i())),e.hasOwnProperty("showNavInfo")&&(t.navInfo.style.display=t.showNavInfo?null:"none"),e.hasOwnProperty("lights")&&((e.lights||[]).forEach((function(e){return t.scene.remove(e)})),t.lights.forEach((function(e){return t.scene.add(e)}))),e.hasOwnProperty("objects")&&((e.objects||[]).forEach((function(e){return t.scene.remove(e)})),t.objects.forEach((function(e){return t.scene.add(e)})))}});function dO(t,e){var n=new e;return n._destructor&&n._destructor(),{linkProp:function(e){return{default:n[e](),onChange:function(n,i){i[t][e](n)},triggerUpdate:!1}},linkMethod:function(e){return function(n){for(var i=n[t],r=arguments.length,s=new Array(r>1?r-1:0),a=1;a<r;a++)s[a-1]=arguments[a];var o=i[e].apply(i,s);return o===i?this:o}}}}var pO=window.THREE?window.THREE:{AmbientLight:class extends Ho{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}},DirectionalLight:class extends Ho{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(ei.DEFAULT_UP),this.updateMatrix(),this.target=new ei,this.shadow=new $o}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}},Vector3:Ze,REVISION:s},fO=dO("forceGraph",Md),mO=Object.assign.apply(Object,r(["jsonUrl","graphData","numDimensions","dagMode","dagLevelDistance","dagNodeFilter","onDagError","nodeRelSize","nodeId","nodeVal","nodeResolution","nodeColor","nodeAutoColorBy","nodeOpacity","nodeVisibility","nodeThreeObject","nodeThreeObjectExtend","linkSource","linkTarget","linkVisibility","linkColor","linkAutoColorBy","linkOpacity","linkWidth","linkResolution","linkCurvature","linkCurveRotation","linkMaterial","linkThreeObject","linkThreeObjectExtend","linkPositionUpdate","linkDirectionalArrowLength","linkDirectionalArrowColor","linkDirectionalArrowRelPos","linkDirectionalArrowResolution","linkDirectionalParticles","linkDirectionalParticleSpeed","linkDirectionalParticleWidth","linkDirectionalParticleColor","linkDirectionalParticleResolution","forceEngine","d3AlphaDecay","d3VelocityDecay","d3AlphaMin","ngraphPhysics","warmupTicks","cooldownTicks","cooldownTime","onEngineTick","onEngineStop"].map((function(t){return e({},t,fO.linkProp(t))})))),gO=Object.assign.apply(Object,r(["refresh","getGraphBbox","d3Force","d3ReheatSimulation","emitParticle"].map((function(t){return e({},t,fO.linkMethod(t))})))),_O=dO("renderObjs",cO),vO=Object.assign.apply(Object,r(["width","height","backgroundColor","showNavInfo","enablePointerInteraction"].map((function(t){return e({},t,_O.linkProp(t))})))),yO=Object.assign.apply(Object,r(["lights","cameraPosition","postProcessingComposer"].map((function(t){return e({},t,_O.linkMethod(t))}))).concat([{graph2ScreenCoords:_O.linkMethod("getScreenCoords"),screen2GraphCoords:_O.linkMethod("getSceneCoords")}])),xO=ju({props:i(i({nodeLabel:{default:"name",triggerUpdate:!1},linkLabel:{default:"name",triggerUpdate:!1},linkHoverPrecision:{default:1,onChange:function(t,e){return e.renderObjs.lineHoverPrecision(t)},triggerUpdate:!1},enableNavigationControls:{default:!0,onChange:function(t,e){var n=e.renderObjs.controls();n&&(n.enabled=t,t&&n.domElement&&n.domElement.dispatchEvent(new PointerEvent("pointerup")))},triggerUpdate:!1},enableNodeDrag:{default:!0,triggerUpdate:!1},onNodeDrag:{default:function(){},triggerUpdate:!1},onNodeDragEnd:{default:function(){},triggerUpdate:!1},onNodeClick:{triggerUpdate:!1},onNodeRightClick:{triggerUpdate:!1},onNodeHover:{triggerUpdate:!1},onLinkClick:{triggerUpdate:!1},onLinkRightClick:{triggerUpdate:!1},onLinkHover:{triggerUpdate:!1},onBackgroundClick:{triggerUpdate:!1},onBackgroundRightClick:{triggerUpdate:!1}},mO),vO),methods:i(i({zoomToFit:function(t,e,n){for(var i,r=arguments.length,s=new Array(r>3?r-3:0),a=3;a<r;a++)s[a-3]=arguments[a];return t.renderObjs.fitToBbox((i=t.forceGraph).getGraphBbox.apply(i,s),e,n),this},pauseAnimation:function(t){return null!==t.animationFrameRequestId&&(cancelAnimationFrame(t.animationFrameRequestId),t.animationFrameRequestId=null),this},resumeAnimation:function(t){return null===t.animationFrameRequestId&&this._animationCycle(),this},_animationCycle:function(t){t.enablePointerInteraction&&(this.renderer().domElement.style.cursor=null),t.forceGraph.tickFrame(),t.renderObjs.tick(),t.animationFrameRequestId=requestAnimationFrame(this._animationCycle)},scene:function(t){return t.renderObjs.scene()},camera:function(t){return t.renderObjs.camera()},renderer:function(t){return t.renderObjs.renderer()},controls:function(t){return t.renderObjs.controls()},tbControls:function(t){return t.renderObjs.tbControls()},_destructor:function(){this.pauseAnimation(),this.graphData({nodes:[],links:[]})}},gO),yO),stateInit:function(t){var e=t.controlType,n=t.rendererConfig,i=t.extraRenderers,r=new Md;return{forceGraph:r,renderObjs:cO({controlType:e,rendererConfig:n,extraRenderers:i}).objects([r]).lights([new pO.AmbientLight(13421772,Math.PI),new pO.DirectionalLight(16777215,.6*Math.PI)])}},init:function(t,e){t.innerHTML="",t.appendChild(e.container=document.createElement("div")),e.container.style.position="relative";var n=document.createElement("div");e.container.appendChild(n),e.renderObjs(n);var i,r=e.renderObjs.camera(),s=e.renderObjs.renderer(),a=e.renderObjs.controls();a.enabled=!!e.enableNavigationControls,e.lastSetCameraZ=r.position.z,e.container.appendChild(i=document.createElement("div")),i.className="graph-info-msg",i.textContent="",e.forceGraph.onLoading((function(){i.textContent="Loading..."})).onFinishLoading((function(){i.textContent=""})).onUpdate((function(){e.graphData=e.forceGraph.graphData(),0===r.position.x&&0===r.position.y&&r.position.z===e.lastSetCameraZ&&e.graphData.nodes.length&&(r.lookAt(e.forceGraph.position),e.lastSetCameraZ=r.position.z=170*Math.cbrt(e.graphData.nodes.length))})).onFinishUpdate((function(){if(e._dragControls){var t=e.graphData.nodes.find((function(t){return t.__initialFixedPos&&!t.__disposeControlsAfterDrag}));t?t.__disposeControlsAfterDrag=!0:e._dragControls.dispose(),e._dragControls=void 0}if(e.enableNodeDrag&&e.enablePointerInteraction&&"d3"===e.forceEngine){var n=e._dragControls=new yl(e.graphData.nodes.map((function(t){return t.__threeObj})).filter((function(t){return t})),r,s.domElement);n.addEventListener("dragstart",(function(t){a.enabled=!1,t.object.__initialPos=t.object.position.clone(),t.object.__prevPos=t.object.position.clone();var e=bO(t.object).__data;!e.__initialFixedPos&&(e.__initialFixedPos={fx:e.fx,fy:e.fy,fz:e.fz}),!e.__initialPos&&(e.__initialPos={x:e.x,y:e.y,z:e.z}),["x","y","z"].forEach((function(t){return e["f".concat(t)]=e[t]})),s.domElement.classList.add("grabbable")})),n.addEventListener("drag",(function(t){var n=bO(t.object);if(!t.object.hasOwnProperty("__graphObjType")){var i=t.object.__initialPos,r=t.object.__prevPos,s=t.object.position;n.position.add(s.clone().sub(r)),r.copy(s),s.copy(i)}var a=n.__data,o=n.position,l={x:o.x-a.x,y:o.y-a.y,z:o.z-a.z};["x","y","z"].forEach((function(t){return a["f".concat(t)]=a[t]=o[t]})),e.forceGraph.d3AlphaTarget(.3).resetCountdown(),a.__dragged=!0,e.onNodeDrag(a,l)})),n.addEventListener("dragend",(function(t){delete t.object.__initialPos,delete t.object.__prevPos;var i=bO(t.object).__data;i.__disposeControlsAfterDrag&&(n.dispose(),delete i.__disposeControlsAfterDrag);var r=i.__initialFixedPos,o=i.__initialPos,l={x:o.x-i.x,y:o.y-i.y,z:o.z-i.z};r&&(["x","y","z"].forEach((function(t){var e="f".concat(t);void 0===r[e]&&delete i[e]})),delete i.__initialFixedPos,delete i.__initialPos,i.__dragged&&(delete i.__dragged,e.onNodeDragEnd(i,l))),e.forceGraph.d3AlphaTarget(0).resetCountdown(),e.enableNavigationControls&&(a.enabled=!0,a.domElement&&a.domElement.ownerDocument&&a.domElement.ownerDocument.dispatchEvent(new PointerEvent("pointerup",{pointerType:"touch"}))),s.domElement.classList.remove("grabbable")}))}})),pO.REVISION<155&&(e.renderObjs.renderer().useLegacyLights=!1),e.renderObjs.hoverOrderComparator((function(t,e){var n=bO(t);if(!n)return 1;var i=bO(e);if(!i)return-1;var r=function(t){return"node"===t.__graphObjType};return r(i)-r(n)})).tooltipContent((function(t){var n=bO(t);return n&&Wu(e["".concat(n.__graphObjType,"Label")])(n.__data)||""})).hoverDuringDrag(!1).onHover((function(t){var n=bO(t);if(n!==e.hoverObj){var i=e.hoverObj?e.hoverObj.__graphObjType:null,r=e.hoverObj?e.hoverObj.__data:null,a=n?n.__graphObjType:null,o=n?n.__data:null;if(i&&i!==a){var l=e["on".concat("node"===i?"Node":"Link","Hover")];l&&l(null,r)}if(a){var h=e["on".concat("node"===a?"Node":"Link","Hover")];h&&h(o,i===a?r:null)}s.domElement.classList[n&&e["on".concat("node"===a?"Node":"Link","Click")]||!n&&e.onBackgroundClick?"add":"remove"]("clickable"),e.hoverObj=n}})).clickAfterDrag(!1).onClick((function(t,n){var i=bO(t);if(i){var r=e["on".concat("node"===i.__graphObjType?"Node":"Link","Click")];r&&r(i.__data,n)}else e.onBackgroundClick&&e.onBackgroundClick(n)})).onRightClick((function(t,n){var i=bO(t);if(i){var r=e["on".concat("node"===i.__graphObjType?"Node":"Link","RightClick")];r&&r(i.__data,n)}else e.onBackgroundRightClick&&e.onBackgroundRightClick(n)})),this._animationCycle()}});function bO(t){for(var e=t;e&&!e.hasOwnProperty("__graphObjType");)e=e.parent;return e}return xO}));
|