@heliguy-xyz/splat-viewer 1.0.0-rc.4 → 1.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web-component/FlyCameraScript.d.ts.map +1 -1
- package/dist/web-component/splat-viewer.esm.js +78 -25
- package/dist/web-component/splat-viewer.esm.min.js +1 -1
- package/dist/web-component/splat-viewer.js +78 -25
- package/dist/web-component/splat-viewer.min.js +1 -1
- package/dist/web-component/types/FlyCameraScript.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2010-2023 Three.js Authors
|
|
5
5
|
* SPDX-License-Identifier: MIT
|
|
6
|
-
*/const sD="157",nD=0,rD=1,aD=2,oD=100,lD=101,hD=102,cD=200,dD=201,uD=202,fD=203,pD=204,mD=205,_D=206,gD=207,vD=208,SD=209,yD=210,xD=301,TD=302,ED=306,bD=1e3,wD=1001,AD=1002,CD=1003,MD=1004,PD=1005,RD=1006,LD=1007,DD=1008,ID=1009,OD=1012,ND=1013,FD=1014,UD=1015,BD=1016,zD=1020,kD=1023,VD=1026,HD=1027,GD=33776,WD=33777,XD=33778,YD=33779,qD=36492,jD=3001,$D="",KD="srgb",ZD="srgb-linear",QD="display-p3",JD="display-p3-linear",tI="linear",eI="srgb",iI="rec709",sI="p3",nI=7680,rI=512,aI=513,oI=514,lI=515,hI=516,cI=517,dI=518,uI=519,fI="300 es",pI=1035,mI=2e3,_I=2001;class gI{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const i=this._listeners;void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(e)&&i[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const i=this._listeners;return void 0!==i[t]&&-1!==i[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const i=this._listeners[t];if(void 0!==i){const t=i.indexOf(e);-1!==t&&i.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 i=e.slice(0);for(let e=0,s=i.length;e<s;e++)i[e].call(this,t);t.target=null}}}const vI=["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"],SI=Math.PI/180,yI=180/Math.PI;function xI(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0;return(vI[255&t]+vI[t>>8&255]+vI[t>>16&255]+vI[t>>24&255]+"-"+vI[255&e]+vI[e>>8&255]+"-"+vI[e>>16&15|64]+vI[e>>24&255]+"-"+vI[63&i|128]+vI[i>>8&255]+"-"+vI[i>>16&255]+vI[i>>24&255]+vI[255&s]+vI[s>>8&255]+vI[s>>16&255]+vI[s>>24&255]).toLowerCase()}function TI(t,e,i){return Math.max(e,Math.min(i,t))}function EI(t,e,i){return(1-i)*t+i*e}function bI(t){return!(t&t-1)&&0!==t}function wI(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function AI(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 CI(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.")}}class MI{constructor(t=0,e=0){MI.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=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 i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(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 i=this.dot(t)/e;return Math.acos(TI(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class PI{constructor(t,e,i,s,n,r,a,o,l){PI.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,i,s,n,r,a,o,l)}set(t,e,i,s,n,r,a,o,l){const h=this.elements;return h[0]=t,h[1]=s,h[2]=a,h[3]=e,h[4]=n,h[5]=o,h[6]=i,h[7]=r,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[3],o=i[6],l=i[1],h=i[4],c=i[7],d=i[2],u=i[5],f=i[8],p=s[0],m=s[3],_=s[6],g=s[1],v=s[4],S=s[7],y=s[2],x=s[5],T=s[8];return n[0]=r*p+a*g+o*y,n[3]=r*m+a*v+o*x,n[6]=r*_+a*S+o*T,n[1]=l*p+h*g+c*y,n[4]=l*m+h*v+c*x,n[7]=l*_+h*S+c*T,n[2]=d*p+u*g+f*y,n[5]=d*m+u*v+f*x,n[8]=d*_+u*S+f*T,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8];return e*r*h-e*a*l-i*n*h+i*a*o+s*n*l-s*r*o}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8],c=h*r-a*l,d=a*o-h*n,u=l*n-r*o,f=e*c+i*d+s*u;if(0===f)return this.set(0,0,0,0,0,0,0,0,0);const p=1/f;return t[0]=c*p,t[1]=(s*l-h*i)*p,t[2]=(a*i-s*r)*p,t[3]=d*p,t[4]=(h*e-s*o)*p,t[5]=(s*n-a*e)*p,t[6]=u*p,t[7]=(i*o-l*e)*p,t[8]=(r*e-i*n)*p,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,s,n,r,a){const o=Math.cos(n),l=Math.sin(n);return this.set(i*o,i*l,-i*(o*r+l*a)+r+t,-s*l,s*o,-s*(-l*r+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(RI.makeScale(t,e)),this}rotate(t){return this.premultiply(RI.makeRotation(-t)),this}translate(t,e){return this.premultiply(RI.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let t=0;t<9;t++)if(e[t]!==i[t])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const RI=new PI;function LI(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}function DI(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function II(){const t=DI("canvas");return t.style.display="block",t}const OI={};function NI(t){t in OI||(OI[t]=!0)}const FI=(new PI).set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),UI=(new PI).set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),BI={[ZD]:{transfer:tI,primaries:iI,toReference:t=>t,fromReference:t=>t},[KD]:{transfer:eI,primaries:iI,toReference:t=>t.convertSRGBToLinear(),fromReference:t=>t.convertLinearToSRGB()},[JD]:{transfer:tI,primaries:sI,toReference:t=>t.applyMatrix3(UI),fromReference:t=>t.applyMatrix3(FI)},[QD]:{transfer:eI,primaries:sI,toReference:t=>t.convertSRGBToLinear().applyMatrix3(UI),fromReference:t=>t.applyMatrix3(FI).convertLinearToSRGB()}},zI=new Set([ZD,JD]),kI={enabled:!0,_workingColorSpace:ZD,get legacyMode(){return!this.enabled},set legacyMode(t){this.enabled=!t},get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(t){if(!zI.has(t))throw new Error(`Unsupported working color space, "${t}".`);this._workingColorSpace=t},convert:function(t,e,i){if(!1===this.enabled||e===i||!e||!i)return t;const s=BI[e].toReference;return(0,BI[i].fromReference)(s(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 BI[t].primaries},getTransfer:function(t){return t===$D?tI:BI[t].transfer}};function VI(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function HI(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let GI;class WI{static getDataURL(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===GI&&(GI=DI("canvas")),GI.width=t.width,GI.height=t.height;const i=GI.getContext("2d");t instanceof ImageData?i.putImageData(t,0,0):i.drawImage(t,0,0,t.width,t.height),e=GI}return e.width>2048||e.height>2048?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=DI("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const s=i.getImageData(0,0,t.width,t.height),n=s.data;for(let t=0;t<n.length;t++)n[t]=255*VI(n[t]/255);return i.putImageData(s,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*VI(e[t]/255)):e[t]=VI(e[t]);return{data:e,width:t.width,height:t.height}}return t}}let XI=0;class YI{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:XI++}),this.uuid=xI(),this.data=t,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 i={uuid:this.uuid,url:""},s=this.data;if(null!==s){let t;if(Array.isArray(s)){t=[];for(let e=0,i=s.length;e<i;e++)s[e].isDataTexture?t.push(qI(s[e].image)):t.push(qI(s[e]))}else t=qI(s);i.url=t}return e||(t.images[this.uuid]=i),i}}function qI(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?WI.getDataURL(t):t.data?{data:Array.from(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:{}}let jI=0;class $I extends gI{constructor(t=$I.DEFAULT_IMAGE,e=$I.DEFAULT_MAPPING,i=1001,s=1001,n=1006,r=1008,a=1023,o=1009,l=$I.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:jI++}),this.uuid=xI(),this.name="",this.source=new YI(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=n,this.minFilter=r,this.anisotropy=l,this.format=a,this.internalFormat=null,this.type=o,this.offset=new MI(0,0),this.repeat=new MI(1,1),this.center=new MI(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new PI,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,"string"==typeof h?this.colorSpace=h:(NI("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace=h===jD?KD:$D),this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.needsPMREMUpdate=!1}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 i={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(300!==this.mapping)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case bD:t.x=t.x-Math.floor(t.x);break;case wD:t.x=t.x<0?0:1;break;case AD: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 bD:t.y=t.y-Math.floor(t.y);break;case wD:t.y=t.y<0?0:1;break;case AD: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)}get encoding(){return NI("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace===KD?jD:3e3}set encoding(t){NI("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace=t===jD?KD:$D}}$I.DEFAULT_IMAGE=null,$I.DEFAULT_MAPPING=300,$I.DEFAULT_ANISOTROPY=1;class KI{constructor(t=0,e=0,i=0,s=1){KI.prototype.isVector4=!0,this.x=t,this.y=e,this.z=i,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,s){return this.x=t,this.y=e,this.z=i,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=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,i=this.y,s=this.z,n=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s+r[12]*n,this.y=r[1]*e+r[5]*i+r[9]*s+r[13]*n,this.z=r[2]*e+r[6]*i+r[10]*s+r[14]*n,this.w=r[3]*e+r[7]*i+r[11]*s+r[15]*n,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,s,n;const r=.01,a=.1,o=t.elements,l=o[0],h=o[4],c=o[8],d=o[1],u=o[5],f=o[9],p=o[2],m=o[6],_=o[10];if(Math.abs(h-d)<r&&Math.abs(c-p)<r&&Math.abs(f-m)<r){if(Math.abs(h+d)<a&&Math.abs(c+p)<a&&Math.abs(f+m)<a&&Math.abs(l+u+_-3)<a)return this.set(1,0,0,0),this;e=Math.PI;const t=(l+1)/2,o=(u+1)/2,g=(_+1)/2,v=(h+d)/4,S=(c+p)/4,y=(f+m)/4;return t>o&&t>g?t<r?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(t),s=v/i,n=S/i):o>g?o<r?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(o),i=v/s,n=y/s):g<r?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(g),i=S/n,s=y/n),this.set(i,s,n,e),this}let g=Math.sqrt((m-f)*(m-f)+(c-p)*(c-p)+(d-h)*(d-h));return Math.abs(g)<.001&&(g=1),this.x=(m-f)/g,this.y=(c-p)/g,this.z=(d-h)/g,this.w=Math.acos((l+u+_-1)/2),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 i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class ZI extends gI{constructor(t=1,e=1,i={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new KI(0,0,t,e),this.scissorTest=!1,this.viewport=new KI(0,0,t,e);const s={width:t,height:e,depth:1};void 0!==i.encoding&&(NI("THREE.WebGLRenderTarget: option.encoding has been replaced by option.colorSpace."),i.colorSpace=i.encoding===jD?KD:$D),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:RD,depthBuffer:!0,stencilBuffer:!1,depthTexture:null,samples:0},i),this.texture=new $I(s,i.mapping,i.wrapS,i.wrapT,i.magFilter,i.minFilter,i.format,i.type,i.anisotropy,i.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.flipY=!1,this.texture.generateMipmaps=i.generateMipmaps,this.texture.internalFormat=i.internalFormat,this.depthBuffer=i.depthBuffer,this.stencilBuffer=i.stencilBuffer,this.depthTexture=i.depthTexture,this.samples=i.samples}setSize(t,e,i=1){this.width===t&&this.height===e&&this.depth===i||(this.width=t,this.height=e,this.depth=i,this.texture.image.width=t,this.texture.image.height=e,this.texture.image.depth=i,this.dispose()),this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return(new this.constructor).copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.texture=t.texture.clone(),this.texture.isRenderTargetTexture=!0;const e=Object.assign({},t.texture.image);return this.texture.source=new YI(e),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,null!==t.depthTexture&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class QI extends ZI{constructor(t=1,e=1,i={}){super(t,e,i),this.isWebGLRenderTarget=!0}}class JI extends $I{constructor(t=null,e=1,i=1,s=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:i,depth:s},this.magFilter=CD,this.minFilter=CD,this.wrapR=wD,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class tO extends $I{constructor(t=null,e=1,i=1,s=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:i,depth:s},this.magFilter=CD,this.minFilter=CD,this.wrapR=wD,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class eO{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let o=i[s+0],l=i[s+1],h=i[s+2],c=i[s+3];const d=n[r+0],u=n[r+1],f=n[r+2],p=n[r+3];if(0===a)return t[e+0]=o,t[e+1]=l,t[e+2]=h,void(t[e+3]=c);if(1===a)return t[e+0]=d,t[e+1]=u,t[e+2]=f,void(t[e+3]=p);if(c!==p||o!==d||l!==u||h!==f){let t=1-a;const e=o*d+l*u+h*f+c*p,i=e>=0?1:-1,s=1-e*e;if(s>Number.EPSILON){const n=Math.sqrt(s),r=Math.atan2(n,e*i);t=Math.sin(t*r)/n,a=Math.sin(a*r)/n}const n=a*i;if(o=o*t+d*n,l=l*t+u*n,h=h*t+f*n,c=c*t+p*n,t===1-a){const t=1/Math.sqrt(o*o+l*l+h*h+c*c);o*=t,l*=t,h*=t,c*=t}}t[e]=o,t[e+1]=l,t[e+2]=h,t[e+3]=c}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],o=i[s+1],l=i[s+2],h=i[s+3],c=n[r],d=n[r+1],u=n[r+2],f=n[r+3];return t[e]=a*f+h*c+o*u-l*d,t[e+1]=o*f+h*d+l*c-a*u,t[e+2]=l*f+h*u+a*d-o*c,t[e+3]=h*f-a*c-o*d-l*u,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,s){return this._x=t,this._y=e,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e){const i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,l=a(i/2),h=a(s/2),c=a(n/2),d=o(i/2),u=o(s/2),f=o(n/2);switch(r){case"XYZ":this._x=d*h*c+l*u*f,this._y=l*u*c-d*h*f,this._z=l*h*f+d*u*c,this._w=l*h*c-d*u*f;break;case"YXZ":this._x=d*h*c+l*u*f,this._y=l*u*c-d*h*f,this._z=l*h*f-d*u*c,this._w=l*h*c+d*u*f;break;case"ZXY":this._x=d*h*c-l*u*f,this._y=l*u*c+d*h*f,this._z=l*h*f+d*u*c,this._w=l*h*c-d*u*f;break;case"ZYX":this._x=d*h*c-l*u*f,this._y=l*u*c+d*h*f,this._z=l*h*f-d*u*c,this._w=l*h*c+d*u*f;break;case"YZX":this._x=d*h*c+l*u*f,this._y=l*u*c+d*h*f,this._z=l*h*f-d*u*c,this._w=l*h*c-d*u*f;break;case"XZY":this._x=d*h*c-l*u*f,this._y=l*u*c-d*h*f,this._z=l*h*f+d*u*c,this._w=l*h*c+d*u*f}return!1!==e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],o=e[9],l=e[2],h=e[6],c=e[10],d=i+a+c;if(d>0){const t=.5/Math.sqrt(d+1);this._w=.25/t,this._x=(h-o)*t,this._y=(n-l)*t,this._z=(r-s)*t}else if(i>a&&i>c){const t=2*Math.sqrt(1+i-a-c);this._w=(h-o)/t,this._x=.25*t,this._y=(s+r)/t,this._z=(n+l)/t}else if(a>c){const t=2*Math.sqrt(1+a-i-c);this._w=(n-l)/t,this._x=(s+r)/t,this._y=.25*t,this._z=(o+h)/t}else{const t=2*Math.sqrt(1+c-i-a);this._w=(r-s)/t,this._x=(n+l)/t,this._y=(o+h)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<Number.EPSILON?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(TI(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(0===i)return this;const s=Math.min(1,e/i);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 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 i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,o=e._y,l=e._z,h=e._w;return this._x=i*h+r*a+s*l-n*o,this._y=s*h+r*o+n*a-i*l,this._z=n*h+r*l+i*o-s*a,this._w=r*h-i*a-s*o-n*l,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const i=this._x,s=this._y,n=this._z,r=this._w;let a=r*t._w+i*t._x+s*t._y+n*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=r,this._x=i,this._y=s,this._z=n,this;const o=1-a*a;if(o<=Number.EPSILON){const t=1-e;return this._w=t*r+e*this._w,this._x=t*i+e*this._x,this._y=t*s+e*this._y,this._z=t*n+e*this._z,this.normalize(),this._onChangeCallback(),this}const l=Math.sqrt(o),h=Math.atan2(l,a),c=Math.sin((1-e)*h)/l,d=Math.sin(e*h)/l;return this._w=r*c+this._w*d,this._x=i*c+this._x*d,this._y=s*c+this._y*d,this._z=n*c+this._z*d,this._onChangeCallback(),this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=Math.random(),e=Math.sqrt(1-t),i=Math.sqrt(t),s=2*Math.PI*Math.random(),n=2*Math.PI*Math.random();return this.set(e*Math.cos(s),i*Math.sin(n),i*Math.cos(n),e*Math.sin(s))}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}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 iO{constructor(t=0,e=0,i=0){iO.prototype.isVector3=!0,this.x=t,this.y=e,this.z=i}set(t,e,i){return void 0===i&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(nO.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(nO.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,o=t.w,l=o*e+r*s-a*i,h=o*i+a*e-n*s,c=o*s+n*i-r*e,d=-n*e-r*i-a*s;return this.x=l*o+d*-n+h*-a-c*-r,this.y=h*o+d*-r+c*-n-l*-a,this.z=c*o+d*-a+l*-r-h*-n,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=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 i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,o=e.z;return this.x=s*o-n*a,this.y=n*r-i*o,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return sO.copy(this).projectOnVector(t),this.sub(sO)}reflect(t){return this.sub(sO.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 i=this.dot(t)/e;return Math.acos(TI(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,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=2*(Math.random()-.5),e=Math.random()*Math.PI*2,i=Math.sqrt(1-t**2);return this.x=i*Math.cos(e),this.y=i*Math.sin(e),this.z=t,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const sO=new iO,nO=new eO;class rO{constructor(t=new iO(1/0,1/0,1/0),e=new iO(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e+=3)this.expandByPoint(oO.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(oO.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=oO.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return(new this.constructor).copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){if(t.updateWorldMatrix(!1,!1),void 0!==t.boundingBox)null===t.boundingBox&&t.computeBoundingBox(),lO.copy(t.boundingBox),lO.applyMatrix4(t.matrixWorld),this.union(lO);else{const i=t.geometry;if(void 0!==i)if(e&&void 0!==i.attributes&&void 0!==i.attributes.position){const e=i.attributes.position;for(let i=0,s=e.count;i<s;i++)oO.fromBufferAttribute(e,i).applyMatrix4(t.matrixWorld),this.expandByPoint(oO)}else null===i.boundingBox&&i.computeBoundingBox(),lO.copy(i.boundingBox),lO.applyMatrix4(t.matrixWorld),this.union(lO)}const i=t.children;for(let t=0,s=i.length;t<s;t++)this.expandByObject(i[t],e);return this}containsPoint(t){return!(t.x<this.min.x||t.x>this.max.x||t.y<this.min.y||t.y>this.max.y||t.z<this.min.z||t.z>this.max.z)}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return!(t.max.x<this.min.x||t.min.x>this.max.x||t.max.y<this.min.y||t.min.y>this.max.y||t.max.z<this.min.z||t.min.z>this.max.z)}intersectsSphere(t){return this.clampPoint(t.center,oO),oO.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(mO),_O.subVectors(this.max,mO),hO.subVectors(t.a,mO),cO.subVectors(t.b,mO),dO.subVectors(t.c,mO),uO.subVectors(cO,hO),fO.subVectors(dO,cO),pO.subVectors(hO,dO);let e=[0,-uO.z,uO.y,0,-fO.z,fO.y,0,-pO.z,pO.y,uO.z,0,-uO.x,fO.z,0,-fO.x,pO.z,0,-pO.x,-uO.y,uO.x,0,-fO.y,fO.x,0,-pO.y,pO.x,0];return!!SO(e,hO,cO,dO,_O)&&(e=[1,0,0,0,1,0,0,0,1],!!SO(e,hO,cO,dO,_O)&&(gO.crossVectors(uO,fO),e=[gO.x,gO.y,gO.z],SO(e,hO,cO,dO,_O)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,oO).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(oO).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()||(aO[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),aO[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),aO[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),aO[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),aO[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),aO[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),aO[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),aO[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(aO)),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 aO=[new iO,new iO,new iO,new iO,new iO,new iO,new iO,new iO],oO=new iO,lO=new rO,hO=new iO,cO=new iO,dO=new iO,uO=new iO,fO=new iO,pO=new iO,mO=new iO,_O=new iO,gO=new iO,vO=new iO;function SO(t,e,i,s,n){for(let r=0,a=t.length-3;r<=a;r+=3){vO.fromArray(t,r);const a=n.x*Math.abs(vO.x)+n.y*Math.abs(vO.y)+n.z*Math.abs(vO.z),o=e.dot(vO),l=i.dot(vO),h=s.dot(vO);if(Math.max(-Math.max(o,l,h),Math.min(o,l,h))>a)return!1}return!0}const yO=new rO,xO=new iO,TO=new iO;class EO{constructor(t=new iO,e=-1){this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;void 0!==e?i.copy(e):yO.setFromPoints(t).getCenter(i);let s=0;for(let e=0,n=t.length;e<n;e++)s=Math.max(s,i.distanceToSquared(t[e]));return this.radius=Math.sqrt(s),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const i=this.center.distanceToSquared(t);return e.copy(t),i>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;xO.subVectors(t,this.center);const e=xO.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),i=.5*(t-this.radius);this.center.addScaledVector(xO,i/t),this.radius+=i}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):(TO.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(xO.copy(t.center).add(TO)),this.expandByPoint(xO.copy(t.center).sub(TO))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const bO=new iO,wO=new iO,AO=new iO,CO=new iO,MO=new iO,PO=new iO,RO=new iO;class LO{constructor(t=new iO,e=new iO(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,bO)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=bO.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(bO.copy(this.origin).addScaledVector(this.direction,e),bO.distanceToSquared(t))}distanceSqToSegment(t,e,i,s){wO.copy(t).add(e).multiplyScalar(.5),AO.copy(e).sub(t).normalize(),CO.copy(this.origin).sub(wO);const n=.5*t.distanceTo(e),r=-this.direction.dot(AO),a=CO.dot(this.direction),o=-CO.dot(AO),l=CO.lengthSq(),h=Math.abs(1-r*r);let c,d,u,f;if(h>0)if(c=r*o-a,d=r*a-o,f=n*h,c>=0)if(d>=-f)if(d<=f){const t=1/h;c*=t,d*=t,u=c*(c+r*d+2*a)+d*(r*c+d+2*o)+l}else d=n,c=Math.max(0,-(r*d+a)),u=-c*c+d*(d+2*o)+l;else d=-n,c=Math.max(0,-(r*d+a)),u=-c*c+d*(d+2*o)+l;else d<=-f?(c=Math.max(0,-(-r*n+a)),d=c>0?-n:Math.min(Math.max(-n,-o),n),u=-c*c+d*(d+2*o)+l):d<=f?(c=0,d=Math.min(Math.max(-n,-o),n),u=d*(d+2*o)+l):(c=Math.max(0,-(r*n+a)),d=c>0?n:Math.min(Math.max(-n,-o),n),u=-c*c+d*(d+2*o)+l);else d=r>0?-n:n,c=Math.max(0,-(r*d+a)),u=-c*c+d*(d+2*o)+l;return i&&i.copy(this.origin).addScaledVector(this.direction,c),s&&s.copy(wO).addScaledVector(AO,d),u}intersectSphere(t,e){bO.subVectors(t.center,this.origin);const i=bO.dot(this.direction),s=bO.dot(bO)-i*i,n=t.radius*t.radius;if(s>n)return null;const r=Math.sqrt(n-s),a=i-r,o=i+r;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return null===i?null:this.at(i,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 i,s,n,r,a,o;const l=1/this.direction.x,h=1/this.direction.y,c=1/this.direction.z,d=this.origin;return l>=0?(i=(t.min.x-d.x)*l,s=(t.max.x-d.x)*l):(i=(t.max.x-d.x)*l,s=(t.min.x-d.x)*l),h>=0?(n=(t.min.y-d.y)*h,r=(t.max.y-d.y)*h):(n=(t.max.y-d.y)*h,r=(t.min.y-d.y)*h),i>r||n>s?null:((n>i||isNaN(i))&&(i=n),(r<s||isNaN(s))&&(s=r),c>=0?(a=(t.min.z-d.z)*c,o=(t.max.z-d.z)*c):(a=(t.max.z-d.z)*c,o=(t.min.z-d.z)*c),i>o||a>s?null:((a>i||i!=i)&&(i=a),(o<s||s!=s)&&(s=o),s<0?null:this.at(i>=0?i:s,e)))}intersectsBox(t){return null!==this.intersectBox(t,bO)}intersectTriangle(t,e,i,s,n){MO.subVectors(e,t),PO.subVectors(i,t),RO.crossVectors(MO,PO);let r,a=this.direction.dot(RO);if(a>0){if(s)return null;r=1}else{if(!(a<0))return null;r=-1,a=-a}CO.subVectors(this.origin,t);const o=r*this.direction.dot(PO.crossVectors(CO,PO));if(o<0)return null;const l=r*this.direction.dot(MO.cross(CO));if(l<0)return null;if(o+l>a)return null;const h=-r*CO.dot(RO);return h<0?null:this.at(h/a,n)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class DO{constructor(t,e,i,s,n,r,a,o,l,h,c,d,u,f,p,m){DO.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,i,s,n,r,a,o,l,h,c,d,u,f,p,m)}set(t,e,i,s,n,r,a,o,l,h,c,d,u,f,p,m){const _=this.elements;return _[0]=t,_[4]=e,_[8]=i,_[12]=s,_[1]=n,_[5]=r,_[9]=a,_[13]=o,_[2]=l,_[6]=h,_[10]=c,_[14]=d,_[3]=u,_[7]=f,_[11]=p,_[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 DO).fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,i=t.elements,s=1/IO.setFromMatrixColumn(t,0).length(),n=1/IO.setFromMatrixColumn(t,1).length(),r=1/IO.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(s),l=Math.sin(s),h=Math.cos(n),c=Math.sin(n);if("XYZ"===t.order){const t=r*h,i=r*c,s=a*h,n=a*c;e[0]=o*h,e[4]=-o*c,e[8]=l,e[1]=i+s*l,e[5]=t-n*l,e[9]=-a*o,e[2]=n-t*l,e[6]=s+i*l,e[10]=r*o}else if("YXZ"===t.order){const t=o*h,i=o*c,s=l*h,n=l*c;e[0]=t+n*a,e[4]=s*a-i,e[8]=r*l,e[1]=r*c,e[5]=r*h,e[9]=-a,e[2]=i*a-s,e[6]=n+t*a,e[10]=r*o}else if("ZXY"===t.order){const t=o*h,i=o*c,s=l*h,n=l*c;e[0]=t-n*a,e[4]=-r*c,e[8]=s+i*a,e[1]=i+s*a,e[5]=r*h,e[9]=n-t*a,e[2]=-r*l,e[6]=a,e[10]=r*o}else if("ZYX"===t.order){const t=r*h,i=r*c,s=a*h,n=a*c;e[0]=o*h,e[4]=s*l-i,e[8]=t*l+n,e[1]=o*c,e[5]=n*l+t,e[9]=i*l-s,e[2]=-l,e[6]=a*o,e[10]=r*o}else if("YZX"===t.order){const t=r*o,i=r*l,s=a*o,n=a*l;e[0]=o*h,e[4]=n-t*c,e[8]=s*c+i,e[1]=c,e[5]=r*h,e[9]=-a*h,e[2]=-l*h,e[6]=i*c+s,e[10]=t-n*c}else if("XZY"===t.order){const t=r*o,i=r*l,s=a*o,n=a*l;e[0]=o*h,e[4]=-c,e[8]=l*h,e[1]=t*c+n,e[5]=r*h,e[9]=i*c-s,e[2]=s*c-i,e[6]=a*h,e[10]=n*c+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(NO,t,FO)}lookAt(t,e,i){const s=this.elements;return zO.subVectors(t,e),0===zO.lengthSq()&&(zO.z=1),zO.normalize(),UO.crossVectors(i,zO),0===UO.lengthSq()&&(1===Math.abs(i.z)?zO.x+=1e-4:zO.z+=1e-4,zO.normalize(),UO.crossVectors(i,zO)),UO.normalize(),BO.crossVectors(zO,UO),s[0]=UO.x,s[4]=BO.x,s[8]=zO.x,s[1]=UO.y,s[5]=BO.y,s[9]=zO.y,s[2]=UO.z,s[6]=BO.z,s[10]=zO.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],o=i[8],l=i[12],h=i[1],c=i[5],d=i[9],u=i[13],f=i[2],p=i[6],m=i[10],_=i[14],g=i[3],v=i[7],S=i[11],y=i[15],x=s[0],T=s[4],E=s[8],b=s[12],w=s[1],A=s[5],C=s[9],M=s[13],P=s[2],R=s[6],L=s[10],D=s[14],I=s[3],O=s[7],N=s[11],F=s[15];return n[0]=r*x+a*w+o*P+l*I,n[4]=r*T+a*A+o*R+l*O,n[8]=r*E+a*C+o*L+l*N,n[12]=r*b+a*M+o*D+l*F,n[1]=h*x+c*w+d*P+u*I,n[5]=h*T+c*A+d*R+u*O,n[9]=h*E+c*C+d*L+u*N,n[13]=h*b+c*M+d*D+u*F,n[2]=f*x+p*w+m*P+_*I,n[6]=f*T+p*A+m*R+_*O,n[10]=f*E+p*C+m*L+_*N,n[14]=f*b+p*M+m*D+_*F,n[3]=g*x+v*w+S*P+y*I,n[7]=g*T+v*A+S*R+y*O,n[11]=g*E+v*C+S*L+y*N,n[15]=g*b+v*M+S*D+y*F,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[12],r=t[1],a=t[5],o=t[9],l=t[13],h=t[2],c=t[6],d=t[10],u=t[14];return t[3]*(+n*o*c-s*l*c-n*a*d+i*l*d+s*a*u-i*o*u)+t[7]*(+e*o*u-e*l*d+n*r*d-s*r*u+s*l*h-n*o*h)+t[11]*(+e*l*c-e*a*u-n*r*c+i*r*u+n*a*h-i*l*h)+t[15]*(-s*a*h-e*o*c+e*a*d+s*r*c-i*r*d+i*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,i){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8],c=t[9],d=t[10],u=t[11],f=t[12],p=t[13],m=t[14],_=t[15],g=c*m*l-p*d*l+p*o*u-a*m*u-c*o*_+a*d*_,v=f*d*l-h*m*l-f*o*u+r*m*u+h*o*_-r*d*_,S=h*p*l-f*c*l+f*a*u-r*p*u-h*a*_+r*c*_,y=f*c*o-h*p*o-f*a*d+r*p*d+h*a*m-r*c*m,x=e*g+i*v+s*S+n*y;if(0===x)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const T=1/x;return t[0]=g*T,t[1]=(p*d*n-c*m*n-p*s*u+i*m*u+c*s*_-i*d*_)*T,t[2]=(a*m*n-p*o*n+p*s*l-i*m*l-a*s*_+i*o*_)*T,t[3]=(c*o*n-a*d*n-c*s*l+i*d*l+a*s*u-i*o*u)*T,t[4]=v*T,t[5]=(h*m*n-f*d*n+f*s*u-e*m*u-h*s*_+e*d*_)*T,t[6]=(f*o*n-r*m*n-f*s*l+e*m*l+r*s*_-e*o*_)*T,t[7]=(r*d*n-h*o*n+h*s*l-e*d*l-r*s*u+e*o*u)*T,t[8]=S*T,t[9]=(f*c*n-h*p*n-f*i*u+e*p*u+h*i*_-e*c*_)*T,t[10]=(r*p*n-f*a*n+f*i*l-e*p*l-r*i*_+e*a*_)*T,t[11]=(h*a*n-r*c*n-h*i*l+e*c*l+r*i*u-e*a*u)*T,t[12]=y*T,t[13]=(h*p*s-f*c*s+f*i*d-e*p*d-h*i*m+e*c*m)*T,t[14]=(f*a*s-r*p*s-f*i*o+e*p*o+r*i*m-e*a*m)*T,t[15]=(r*c*s-h*a*s+h*i*o-e*c*o-r*i*d+e*a*d)*T,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),s=Math.sin(e),n=1-i,r=t.x,a=t.y,o=t.z,l=n*r,h=n*a;return this.set(l*r+i,l*a-s*o,l*o+s*a,0,l*a+s*o,h*a+i,h*o-s*r,0,l*o-s*a,h*o+s*r,n*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,o=e._w,l=n+n,h=r+r,c=a+a,d=n*l,u=n*h,f=n*c,p=r*h,m=r*c,_=a*c,g=o*l,v=o*h,S=o*c,y=i.x,x=i.y,T=i.z;return s[0]=(1-(p+_))*y,s[1]=(u+S)*y,s[2]=(f-v)*y,s[3]=0,s[4]=(u-S)*x,s[5]=(1-(d+_))*x,s[6]=(m+g)*x,s[7]=0,s[8]=(f+v)*T,s[9]=(m-g)*T,s[10]=(1-(d+p))*T,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;let n=IO.set(s[0],s[1],s[2]).length();const r=IO.set(s[4],s[5],s[6]).length(),a=IO.set(s[8],s[9],s[10]).length();this.determinant()<0&&(n=-n),t.x=s[12],t.y=s[13],t.z=s[14],OO.copy(this);const o=1/n,l=1/r,h=1/a;return OO.elements[0]*=o,OO.elements[1]*=o,OO.elements[2]*=o,OO.elements[4]*=l,OO.elements[5]*=l,OO.elements[6]*=l,OO.elements[8]*=h,OO.elements[9]*=h,OO.elements[10]*=h,e.setFromRotationMatrix(OO),i.x=n,i.y=r,i.z=a,this}makePerspective(t,e,i,s,n,r,a=2e3){const o=this.elements,l=2*n/(e-t),h=2*n/(i-s),c=(e+t)/(e-t),d=(i+s)/(i-s);let u,f;if(a===mI)u=-(r+n)/(r-n),f=-2*r*n/(r-n);else{if(a!==_I)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);u=-r/(r-n),f=-r*n/(r-n)}return o[0]=l,o[4]=0,o[8]=c,o[12]=0,o[1]=0,o[5]=h,o[9]=d,o[13]=0,o[2]=0,o[6]=0,o[10]=u,o[14]=f,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=2e3){const o=this.elements,l=1/(e-t),h=1/(i-s),c=1/(r-n),d=(e+t)*l,u=(i+s)*h;let f,p;if(a===mI)f=(r+n)*c,p=-2*c;else{if(a!==_I)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);f=n*c,p=-1*c}return o[0]=2*l,o[4]=0,o[8]=0,o[12]=-d,o[1]=0,o[5]=2*h,o[9]=0,o[13]=-u,o[2]=0,o[6]=0,o[10]=p,o[14]=-f,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let t=0;t<16;t++)if(e[t]!==i[t])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}const IO=new iO,OO=new DO,NO=new iO(0,0,0),FO=new iO(1,1,1),UO=new iO,BO=new iO,zO=new iO,kO=new DO,VO=new eO;class HO{constructor(t=0,e=0,i=0,s=HO.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const s=t.elements,n=s[0],r=s[4],a=s[8],o=s[1],l=s[5],h=s[9],c=s[2],d=s[6],u=s[10];switch(e){case"XYZ":this._y=Math.asin(TI(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,u),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-TI(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,u),this._z=Math.atan2(o,l)):(this._y=Math.atan2(-c,n),this._z=0);break;case"ZXY":this._x=Math.asin(TI(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-c,u),this._z=Math.atan2(-r,l)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-TI(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(d,u),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,l));break;case"YZX":this._z=Math.asin(TI(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-c,n)):(this._x=0,this._y=Math.atan2(a,u));break;case"XZY":this._z=Math.asin(-TI(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-h,u),this._y=0)}return this._order=e,!0===i&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return kO.makeRotationFromQuaternion(t),this.setFromRotationMatrix(kO,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return VO.setFromEuler(this),this.setFromQuaternion(VO,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}}HO.DEFAULT_ORDER="XYZ";class GO{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 0!==(this.mask&t.mask)}isEnabled(t){return!!(this.mask&1<<t)}}let WO=0;const XO=new iO,YO=new eO,qO=new DO,jO=new iO,$O=new iO,KO=new iO,ZO=new eO,QO=new iO(1,0,0),JO=new iO(0,1,0),tN=new iO(0,0,1),eN={type:"added"},iN={type:"removed"};class sN extends gI{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:WO++}),this.uuid=xI(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=sN.DEFAULT_UP.clone();const t=new iO,e=new HO,i=new eO,s=new iO(1,1,1);e._onChange(function(){i.setFromEuler(e,!1)}),i._onChange(function(){e.setFromQuaternion(i,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:i},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new DO},normalMatrix:{value:new PI}}),this.matrix=new DO,this.matrixWorld=new DO,this.matrixAutoUpdate=sN.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.matrixWorldAutoUpdate=sN.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.layers=new GO,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}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 YO.setFromAxisAngle(t,e),this.quaternion.multiply(YO),this}rotateOnWorldAxis(t,e){return YO.setFromAxisAngle(t,e),this.quaternion.premultiply(YO),this}rotateX(t){return this.rotateOnAxis(QO,t)}rotateY(t){return this.rotateOnAxis(JO,t)}rotateZ(t){return this.rotateOnAxis(tN,t)}translateOnAxis(t,e){return XO.copy(t).applyQuaternion(this.quaternion),this.position.add(XO.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(QO,t)}translateY(t){return this.translateOnAxis(JO,t)}translateZ(t){return this.translateOnAxis(tN,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(qO.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?jO.copy(t):jO.set(t,e,i);const s=this.parent;this.updateWorldMatrix(!0,!1),$O.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?qO.lookAt($O,jO,this.up):qO.lookAt(jO,$O,this.up),this.quaternion.setFromRotationMatrix(qO),s&&(qO.extractRotation(s.matrixWorld),YO.setFromRotationMatrix(qO),this.quaternion.premultiply(YO.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return t===this||t&&t.isObject3D&&(null!==t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t),t.dispatchEvent(eN)),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(iN)),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),qO.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),qO.multiply(t.parent.matrixWorld)),t.applyMatrix4(qO),this.add(t),t.updateWorldMatrix(!1,!0),this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let i=0,s=this.children.length;i<s;i++){const s=this.children[i].getObjectByProperty(t,e);if(void 0!==s)return s}}getObjectsByProperty(t,e){let i=[];this[t]===e&&i.push(this);for(let s=0,n=this.children.length;s<n;s++){const n=this.children[s].getObjectsByProperty(t,e);n.length>0&&(i=i.concat(n))}return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose($O,t,KO),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose($O,ZO,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;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)&&(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 i=0,s=e.length;i<s;i++){const s=e[i];!0!==s.matrixWorldAutoUpdate&&!0!==t||s.updateMatrixWorld(t)}}updateWorldMatrix(t,e){const i=this.parent;if(!0===t&&null!==i&&!0===i.matrixWorldAutoUpdate&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),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,i=t.length;e<i;e++){const i=t[e];!0===i.matrixWorldAutoUpdate&&i.updateWorldMatrix(!1,!0)}}}toJSON(t){const e=void 0===t||"string"==typeof t,i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const s={};function n(e,i){return void 0===e[i.uuid]&&(e[i.uuid]=i.toJSON(t)),i.uuid}if(s.uuid=this.uuid,s.type=this.type,""!==this.name&&(s.name=this.name),!0===this.castShadow&&(s.castShadow=!0),!0===this.receiveShadow&&(s.receiveShadow=!0),!1===this.visible&&(s.visible=!1),!1===this.frustumCulled&&(s.frustumCulled=!1),0!==this.renderOrder&&(s.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(s.matrixAutoUpdate=!1),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(s.instanceColor=this.instanceColor.toJSON())),this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=n(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const i=e.shapes;if(Array.isArray(i))for(let e=0,s=i.length;e<s;e++){const s=i[e];n(t.shapes,s)}else n(t.shapes,i)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),void 0!==this.skeleton&&(n(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),void 0!==this.material)if(Array.isArray(this.material)){const e=[];for(let i=0,s=this.material.length;i<s;i++)e.push(n(t.materials,this.material[i]));s.material=e}else s.material=n(t.materials,this.material);if(this.children.length>0){s.children=[];for(let e=0;e<this.children.length;e++)s.children.push(this.children[e].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let e=0;e<this.animations.length;e++){const i=this.animations[e];s.animations.push(n(t.animations,i))}}if(e){const e=r(t.geometries),s=r(t.materials),n=r(t.textures),a=r(t.images),o=r(t.shapes),l=r(t.skeletons),h=r(t.animations),c=r(t.nodes);e.length>0&&(i.geometries=e),s.length>0&&(i.materials=s),n.length>0&&(i.textures=n),a.length>0&&(i.images=a),o.length>0&&(i.shapes=o),l.length>0&&(i.skeletons=l),h.length>0&&(i.animations=h),c.length>0&&(i.nodes=c)}return i.object=s,i;function r(t){const e=[];for(const i in t){const s=t[i];delete s.metadata,e.push(s)}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.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,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 i=t.children[e];this.add(i.clone())}return this}}sN.DEFAULT_UP=new iO(0,1,0),sN.DEFAULT_MATRIX_AUTO_UPDATE=!0,sN.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const nN=new iO,rN=new iO,aN=new iO,oN=new iO,lN=new iO,hN=new iO,cN=new iO,dN=new iO,uN=new iO,fN=new iO;let pN=!1;class mN{constructor(t=new iO,e=new iO,i=new iO){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,s){s.subVectors(i,e),nN.subVectors(t,e),s.cross(nN);const n=s.lengthSq();return n>0?s.multiplyScalar(1/Math.sqrt(n)):s.set(0,0,0)}static getBarycoord(t,e,i,s,n){nN.subVectors(s,e),rN.subVectors(i,e),aN.subVectors(t,e);const r=nN.dot(nN),a=nN.dot(rN),o=nN.dot(aN),l=rN.dot(rN),h=rN.dot(aN),c=r*l-a*a;if(0===c)return n.set(-2,-1,-1);const d=1/c,u=(l*o-a*h)*d,f=(r*h-a*o)*d;return n.set(1-u-f,f,u)}static containsPoint(t,e,i,s){return this.getBarycoord(t,e,i,s,oN),oN.x>=0&&oN.y>=0&&oN.x+oN.y<=1}static getUV(t,e,i,s,n,r,a,o){return!1===pN&&(pN=!0),this.getInterpolation(t,e,i,s,n,r,a,o)}static getInterpolation(t,e,i,s,n,r,a,o){return this.getBarycoord(t,e,i,s,oN),o.setScalar(0),o.addScaledVector(n,oN.x),o.addScaledVector(r,oN.y),o.addScaledVector(a,oN.z),o}static isFrontFacing(t,e,i,s){return nN.subVectors(i,e),rN.subVectors(t,e),nN.cross(rN).dot(s)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,s){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,i,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,s),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return nN.subVectors(this.c,this.b),rN.subVectors(this.a,this.b),.5*nN.cross(rN).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return mN.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return mN.getBarycoord(t,this.a,this.b,this.c,e)}getUV(t,e,i,s,n){return!1===pN&&(pN=!0),mN.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}getInterpolation(t,e,i,s,n){return mN.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}containsPoint(t){return mN.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return mN.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,s=this.b,n=this.c;let r,a;lN.subVectors(s,i),hN.subVectors(n,i),dN.subVectors(t,i);const o=lN.dot(dN),l=hN.dot(dN);if(o<=0&&l<=0)return e.copy(i);uN.subVectors(t,s);const h=lN.dot(uN),c=hN.dot(uN);if(h>=0&&c<=h)return e.copy(s);const d=o*c-h*l;if(d<=0&&o>=0&&h<=0)return r=o/(o-h),e.copy(i).addScaledVector(lN,r);fN.subVectors(t,n);const u=lN.dot(fN),f=hN.dot(fN);if(f>=0&&u<=f)return e.copy(n);const p=u*l-o*f;if(p<=0&&l>=0&&f<=0)return a=l/(l-f),e.copy(i).addScaledVector(hN,a);const m=h*f-u*c;if(m<=0&&c-h>=0&&u-f>=0)return cN.subVectors(n,s),a=(c-h)/(c-h+(u-f)),e.copy(s).addScaledVector(cN,a);const _=1/(m+p+d);return r=p*_,a=d*_,e.copy(i).addScaledVector(lN,r).addScaledVector(hN,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}let _N=0;class gN extends gI{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:_N++}),this.uuid=xI(),this.name="",this.type="Material",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=oD,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=nI,this.stencilZFail=nI,this.stencilZPass=nI,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}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const i=t[e];if(void 0===i)continue;const s=this[e];void 0!==s&&(s&&s.isColor?s.set(i):s&&s.isVector3&&i&&i.isVector3?s.copy(i):this[e]=i)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const i={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function s(t){const e=[];for(const i in t){const s=t[i];delete s.metadata,e.push(s)}return e}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),void 0!==this.roughness&&(i.roughness=this.roughness),void 0!==this.metalness&&(i.metalness=this.metalness),void 0!==this.sheen&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity&&1!==this.emissiveIntensity&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(i.shininess=this.shininess),void 0!==this.clearcoat&&(i.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.iridescence&&(i.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(i.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(i.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(t).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(t).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(t).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(t).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(t).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(i.combine=this.combine)),void 0!==this.envMapIntensity&&(i.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(i.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(i.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(i.size=this.size),null!==this.shadowSide&&(i.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(i.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(i.blending=this.blending),0!==this.side&&(i.side=this.side),!0===this.vertexColors&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),!0===this.transparent&&(i.transparent=!0),i.depthFunc=this.depthFunc,i.depthTest=this.depthTest,i.depthWrite=this.depthWrite,i.colorWrite=this.colorWrite,i.stencilWrite=this.stencilWrite,i.stencilWriteMask=this.stencilWriteMask,i.stencilFunc=this.stencilFunc,i.stencilRef=this.stencilRef,i.stencilFuncMask=this.stencilFuncMask,i.stencilFail=this.stencilFail,i.stencilZFail=this.stencilZFail,i.stencilZPass=this.stencilZPass,void 0!==this.rotation&&0!==this.rotation&&(i.rotation=this.rotation),!0===this.polygonOffset&&(i.polygonOffset=!0),0!==this.polygonOffsetFactor&&(i.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(i.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(i.linewidth=this.linewidth),void 0!==this.dashSize&&(i.dashSize=this.dashSize),void 0!==this.gapSize&&(i.gapSize=this.gapSize),void 0!==this.scale&&(i.scale=this.scale),!0===this.dithering&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),!0===this.alphaHash&&(i.alphaHash=!0),!0===this.alphaToCoverage&&(i.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(i.premultipliedAlpha=!0),!0===this.forceSinglePass&&(i.forceSinglePass=!0),!0===this.wireframe&&(i.wireframe=!0),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(i.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(i.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(i.flatShading=!0),!1===this.visible&&(i.visible=!1),!1===this.toneMapped&&(i.toneMapped=!1),!1===this.fog&&(i.fog=!1),Object.keys(this.userData).length>0&&(i.userData=this.userData),e){const e=s(t.textures),n=s(t.images);e.length>0&&(i.textures=e),n.length>0&&(i.images=n)}return i}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let i=null;if(null!==e){const t=e.length;i=new Array(t);for(let s=0;s!==t;++s)i[s]=e[s].clone()}return this.clippingPlanes=i,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}}const vN={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},SN={h:0,s:0,l:0},yN={h:0,s:0,l:0};function xN(t,e,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+6*(e-t)*(2/3-i):t}class TN{constructor(t,e,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,i)}set(t,e,i){if(void 0===e&&void 0===i){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,i);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=KD){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,kI.toWorkingColorSpace(this,e),this}setRGB(t,e,i,s=kI.workingColorSpace){return this.r=t,this.g=e,this.b=i,kI.toWorkingColorSpace(this,s),this}setHSL(t,e,i,s=kI.workingColorSpace){var n;if(t=(t%(n=1)+n)%n,e=TI(e,0,1),i=TI(i,0,1),0===e)this.r=this.g=this.b=i;else{const s=i<=.5?i*(1+e):i+e-i*e,n=2*i-s;this.r=xN(n,s,t+1/3),this.g=xN(n,s,t),this.b=xN(n,s,t-1/3)}return kI.toWorkingColorSpace(this,s),this}setStyle(t,e=KD){function i(t){void 0!==t&&parseFloat(t)}let s;if(s=/^(\w+)\(([^\)]*)\)/.exec(t)){let t;const n=s[1],r=s[2];switch(n){case"rgb":case"rgba":if(t=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))return i(t[4]),this.setRGB(Math.min(255,parseInt(t[1],10))/255,Math.min(255,parseInt(t[2],10))/255,Math.min(255,parseInt(t[3],10))/255,e);if(t=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))return i(t[4]),this.setRGB(Math.min(100,parseInt(t[1],10))/100,Math.min(100,parseInt(t[2],10))/100,Math.min(100,parseInt(t[3],10))/100,e);break;case"hsl":case"hsla":if(t=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))return i(t[4]),this.setHSL(parseFloat(t[1])/360,parseFloat(t[2])/100,parseFloat(t[3])/100,e)}}else if(s=/^\#([A-Fa-f\d]+)$/.exec(t)){const t=s[1],i=t.length;if(3===i)return this.setRGB(parseInt(t.charAt(0),16)/15,parseInt(t.charAt(1),16)/15,parseInt(t.charAt(2),16)/15,e);if(6===i)return this.setHex(parseInt(t,16),e)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=KD){const i=vN[t.toLowerCase()];return void 0!==i&&this.setHex(i,e),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=VI(t.r),this.g=VI(t.g),this.b=VI(t.b),this}copyLinearToSRGB(t){return this.r=HI(t.r),this.g=HI(t.g),this.b=HI(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=KD){return kI.fromWorkingColorSpace(EN.copy(this),t),65536*Math.round(TI(255*EN.r,0,255))+256*Math.round(TI(255*EN.g,0,255))+Math.round(TI(255*EN.b,0,255))}getHexString(t=KD){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=kI.workingColorSpace){kI.fromWorkingColorSpace(EN.copy(this),e);const i=EN.r,s=EN.g,n=EN.b,r=Math.max(i,s,n),a=Math.min(i,s,n);let o,l;const h=(a+r)/2;if(a===r)o=0,l=0;else{const t=r-a;switch(l=h<=.5?t/(r+a):t/(2-r-a),r){case i:o=(s-n)/t+(s<n?6:0);break;case s:o=(n-i)/t+2;break;case n:o=(i-s)/t+4}o/=6}return t.h=o,t.s=l,t.l=h,t}getRGB(t,e=kI.workingColorSpace){return kI.fromWorkingColorSpace(EN.copy(this),e),t.r=EN.r,t.g=EN.g,t.b=EN.b,t}getStyle(t=KD){kI.fromWorkingColorSpace(EN.copy(this),t);const e=EN.r,i=EN.g,s=EN.b;return t!==KD?`color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${s.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*i)},${Math.round(255*s)})`}offsetHSL(t,e,i){return this.getHSL(SN),this.setHSL(SN.h+t,SN.s+e,SN.l+i)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,i){return this.r=t.r+(e.r-t.r)*i,this.g=t.g+(e.g-t.g)*i,this.b=t.b+(e.b-t.b)*i,this}lerpHSL(t,e){this.getHSL(SN),t.getHSL(yN);const i=EI(SN.h,yN.h,e),s=EI(SN.s,yN.s,e),n=EI(SN.l,yN.l,e);return this.setHSL(i,s,n),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,i=this.g,s=this.b,n=t.elements;return this.r=n[0]*e+n[3]*i+n[6]*s,this.g=n[1]*e+n[4]*i+n[7]*s,this.b=n[2]*e+n[5]*i+n[8]*s,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const EN=new TN;TN.NAMES=vN;class bN extends gN{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new TN(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.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.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 wN=new iO,AN=new MI;class CN{constructor(t,e,i=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=i,this.usage=35044,this.updateRange={offset:0,count:-1},this.gpuType=UD,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let s=0,n=this.itemSize;s<n;s++)this.array[t+s]=e.array[i+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,i=this.count;e<i;e++)AN.fromBufferAttribute(this,e),AN.applyMatrix3(t),this.setXY(e,AN.x,AN.y);else if(3===this.itemSize)for(let e=0,i=this.count;e<i;e++)wN.fromBufferAttribute(this,e),wN.applyMatrix3(t),this.setXYZ(e,wN.x,wN.y,wN.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)wN.fromBufferAttribute(this,e),wN.applyMatrix4(t),this.setXYZ(e,wN.x,wN.y,wN.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)wN.fromBufferAttribute(this,e),wN.applyNormalMatrix(t),this.setXYZ(e,wN.x,wN.y,wN.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)wN.fromBufferAttribute(this,e),wN.transformDirection(t),this.setXYZ(e,wN.x,wN.y,wN.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=AI(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=CI(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=AI(e,this.array)),e}setX(t,e){return this.normalized&&(e=CI(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=AI(e,this.array)),e}setY(t,e){return this.normalized&&(e=CI(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=AI(e,this.array)),e}setZ(t,e){return this.normalized&&(e=CI(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=AI(e,this.array)),e}setW(t,e){return this.normalized&&(e=CI(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=CI(e,this.array),i=CI(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,s){return t*=this.itemSize,this.normalized&&(e=CI(e,this.array),i=CI(i,this.array),s=CI(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this}setXYZW(t,e,i,s,n){return t*=this.itemSize,this.normalized&&(e=CI(e,this.array),i=CI(i,this.array),s=CI(s,this.array),n=CI(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this.array[t+3]=n,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return""!==this.name&&(t.name=this.name),35044!==this.usage&&(t.usage=this.usage),0===this.updateRange.offset&&-1===this.updateRange.count||(t.updateRange=this.updateRange),t}}class MN extends CN{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class PN extends CN{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class RN extends CN{constructor(t,e,i){super(new Float32Array(t),e,i)}}let LN=0;const DN=new DO,IN=new sN,ON=new iO,NN=new rO,FN=new rO,UN=new iO;class BN extends gI{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:LN++}),this.uuid=xI(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(LI(t)?PN:MN)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(void 0!==i){const e=(new PI).getNormalMatrix(t);i.applyNormalMatrix(e),i.needsUpdate=!0}const s=this.attributes.tangent;return void 0!==s&&(s.transformDirection(t),s.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return DN.makeRotationFromQuaternion(t),this.applyMatrix4(DN),this}rotateX(t){return DN.makeRotationX(t),this.applyMatrix4(DN),this}rotateY(t){return DN.makeRotationY(t),this.applyMatrix4(DN),this}rotateZ(t){return DN.makeRotationZ(t),this.applyMatrix4(DN),this}translate(t,e,i){return DN.makeTranslation(t,e,i),this.applyMatrix4(DN),this}scale(t,e,i){return DN.makeScale(t,e,i),this.applyMatrix4(DN),this}lookAt(t){return IN.lookAt(t),IN.updateMatrix(),this.applyMatrix4(IN.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ON).negate(),this.translate(ON.x,ON.y,ON.z),this}setFromPoints(t){const e=[];for(let i=0,s=t.length;i<s;i++){const s=t[i];e.push(s.x,s.y,s.z||0)}return this.setAttribute("position",new RN(e,3)),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new rO);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)this.boundingBox.set(new iO(-1/0,-1/0,-1/0),new iO(1/0,1/0,1/0));else{if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,i=e.length;t<i;t++){const i=e[t];NN.setFromBufferAttribute(i),this.morphTargetsRelative?(UN.addVectors(this.boundingBox.min,NN.min),this.boundingBox.expandByPoint(UN),UN.addVectors(this.boundingBox.max,NN.max),this.boundingBox.expandByPoint(UN)):(this.boundingBox.expandByPoint(NN.min),this.boundingBox.expandByPoint(NN.max))}}else this.boundingBox.makeEmpty();isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z)}}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new EO);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)this.boundingSphere.set(new iO,1/0);else if(t){const i=this.boundingSphere.center;if(NN.setFromBufferAttribute(t),e)for(let t=0,i=e.length;t<i;t++){const i=e[t];FN.setFromBufferAttribute(i),this.morphTargetsRelative?(UN.addVectors(NN.min,FN.min),NN.expandByPoint(UN),UN.addVectors(NN.max,FN.max),NN.expandByPoint(UN)):(NN.expandByPoint(FN.min),NN.expandByPoint(FN.max))}NN.getCenter(i);let s=0;for(let e=0,n=t.count;e<n;e++)UN.fromBufferAttribute(t,e),s=Math.max(s,i.distanceToSquared(UN));if(e)for(let n=0,r=e.length;n<r;n++){const r=e[n],a=this.morphTargetsRelative;for(let e=0,n=r.count;e<n;e++)UN.fromBufferAttribute(r,e),a&&(ON.fromBufferAttribute(t,e),UN.add(ON)),s=Math.max(s,i.distanceToSquared(UN))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)}}computeTangents(){const t=this.index,e=this.attributes;if(null===t||void 0===e.position||void 0===e.normal||void 0===e.uv)return;const i=t.array,s=e.position.array,n=e.normal.array,r=e.uv.array,a=s.length/3;!1===this.hasAttribute("tangent")&&this.setAttribute("tangent",new CN(new Float32Array(4*a),4));const o=this.getAttribute("tangent").array,l=[],h=[];for(let t=0;t<a;t++)l[t]=new iO,h[t]=new iO;const c=new iO,d=new iO,u=new iO,f=new MI,p=new MI,m=new MI,_=new iO,g=new iO;function v(t,e,i){c.fromArray(s,3*t),d.fromArray(s,3*e),u.fromArray(s,3*i),f.fromArray(r,2*t),p.fromArray(r,2*e),m.fromArray(r,2*i),d.sub(c),u.sub(c),p.sub(f),m.sub(f);const n=1/(p.x*m.y-m.x*p.y);isFinite(n)&&(_.copy(d).multiplyScalar(m.y).addScaledVector(u,-p.y).multiplyScalar(n),g.copy(u).multiplyScalar(p.x).addScaledVector(d,-m.x).multiplyScalar(n),l[t].add(_),l[e].add(_),l[i].add(_),h[t].add(g),h[e].add(g),h[i].add(g))}let S=this.groups;0===S.length&&(S=[{start:0,count:i.length}]);for(let t=0,e=S.length;t<e;++t){const e=S[t],s=e.start;for(let t=s,n=s+e.count;t<n;t+=3)v(i[t+0],i[t+1],i[t+2])}const y=new iO,x=new iO,T=new iO,E=new iO;function b(t){T.fromArray(n,3*t),E.copy(T);const e=l[t];y.copy(e),y.sub(T.multiplyScalar(T.dot(e))).normalize(),x.crossVectors(E,e);const i=x.dot(h[t])<0?-1:1;o[4*t]=y.x,o[4*t+1]=y.y,o[4*t+2]=y.z,o[4*t+3]=i}for(let t=0,e=S.length;t<e;++t){const e=S[t],s=e.start;for(let t=s,n=s+e.count;t<n;t+=3)b(i[t+0]),b(i[t+1]),b(i[t+2])}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let i=this.getAttribute("normal");if(void 0===i)i=new CN(new Float32Array(3*e.count),3),this.setAttribute("normal",i);else for(let t=0,e=i.count;t<e;t++)i.setXYZ(t,0,0,0);const s=new iO,n=new iO,r=new iO,a=new iO,o=new iO,l=new iO,h=new iO,c=new iO;if(t)for(let d=0,u=t.count;d<u;d+=3){const u=t.getX(d+0),f=t.getX(d+1),p=t.getX(d+2);s.fromBufferAttribute(e,u),n.fromBufferAttribute(e,f),r.fromBufferAttribute(e,p),h.subVectors(r,n),c.subVectors(s,n),h.cross(c),a.fromBufferAttribute(i,u),o.fromBufferAttribute(i,f),l.fromBufferAttribute(i,p),a.add(h),o.add(h),l.add(h),i.setXYZ(u,a.x,a.y,a.z),i.setXYZ(f,o.x,o.y,o.z),i.setXYZ(p,l.x,l.y,l.z)}else for(let t=0,a=e.count;t<a;t+=3)s.fromBufferAttribute(e,t+0),n.fromBufferAttribute(e,t+1),r.fromBufferAttribute(e,t+2),h.subVectors(r,n),c.subVectors(s,n),h.cross(c),i.setXYZ(t+0,h.x,h.y,h.z),i.setXYZ(t+1,h.x,h.y,h.z),i.setXYZ(t+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)UN.fromBufferAttribute(t,e),UN.normalize(),t.setXYZ(e,UN.x,UN.y,UN.z)}toNonIndexed(){function t(t,e){const i=t.array,s=t.itemSize,n=t.normalized,r=new i.constructor(e.length*s);let a=0,o=0;for(let n=0,l=e.length;n<l;n++){a=t.isInterleavedBufferAttribute?e[n]*t.data.stride+t.offset:e[n]*s;for(let t=0;t<s;t++)r[o++]=i[a++]}return new CN(r,s,n)}if(null===this.index)return this;const e=new BN,i=this.index.array,s=this.attributes;for(const n in s){const r=t(s[n],i);e.setAttribute(n,r)}const n=this.morphAttributes;for(const s in n){const r=[],a=n[s];for(let e=0,s=a.length;e<s;e++){const s=t(a[e],i);r.push(s)}e.morphAttributes[s]=r}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let t=0,i=r.length;t<i;t++){const i=r[t];e.addGroup(i.start,i.count,i.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 i in e)void 0!==e[i]&&(t[i]=e[i]);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 i=this.attributes;for(const e in i){const s=i[e];t.data.attributes[e]=s.toJSON(t.data)}const s={};let n=!1;for(const e in this.morphAttributes){const i=this.morphAttributes[e],r=[];for(let e=0,s=i.length;e<s;e++){const s=i[e];r.push(s.toJSON(t.data))}r.length>0&&(s[e]=r,n=!0)}n&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return 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 i=t.index;null!==i&&this.setIndex(i.clone(e));const s=t.attributes;for(const t in s){const i=s[t];this.setAttribute(t,i.clone(e))}const n=t.morphAttributes;for(const t in n){const i=[],s=n[t];for(let t=0,n=s.length;t<n;t++)i.push(s[t].clone(e));this.morphAttributes[t]=i}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let t=0,e=r.length;t<e;t++){const e=r[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 zN=new DO,kN=new LO,VN=new EO,HN=new iO,GN=new iO,WN=new iO,XN=new iO,YN=new iO,qN=new iO,jN=new MI,$N=new MI,KN=new MI,ZN=new iO,QN=new iO,JN=new iO,tF=new iO,eF=new iO;class iF extends sN{constructor(t=new BN,e=new bN){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 i=t[e[0]];if(void 0!==i){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=i.length;t<e;t++){const e=i[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}getVertexPosition(t,e){const i=this.geometry,s=i.attributes.position,n=i.morphAttributes.position,r=i.morphTargetsRelative;e.fromBufferAttribute(s,t);const a=this.morphTargetInfluences;if(n&&a){qN.set(0,0,0);for(let i=0,s=n.length;i<s;i++){const s=a[i],o=n[i];0!==s&&(YN.fromBufferAttribute(o,t),r?qN.addScaledVector(YN,s):qN.addScaledVector(YN.sub(e),s))}e.add(qN)}return e}raycast(t,e){const i=this.geometry,s=this.material,n=this.matrixWorld;if(void 0!==s){if(null===i.boundingSphere&&i.computeBoundingSphere(),VN.copy(i.boundingSphere),VN.applyMatrix4(n),kN.copy(t.ray).recast(t.near),!1===VN.containsPoint(kN.origin)){if(null===kN.intersectSphere(VN,HN))return;if(kN.origin.distanceToSquared(HN)>(t.far-t.near)**2)return}zN.copy(n).invert(),kN.copy(t.ray).applyMatrix4(zN),null!==i.boundingBox&&!1===kN.intersectsBox(i.boundingBox)||this._computeIntersections(t,e,kN)}}_computeIntersections(t,e,i){let s;const n=this.geometry,r=this.material,a=n.index,o=n.attributes.position,l=n.attributes.uv,h=n.attributes.uv1,c=n.attributes.normal,d=n.groups,u=n.drawRange;if(null!==a)if(Array.isArray(r))for(let n=0,o=d.length;n<o;n++){const o=d[n],f=r[o.materialIndex];for(let n=Math.max(o.start,u.start),r=Math.min(a.count,Math.min(o.start+o.count,u.start+u.count));n<r;n+=3){s=sF(this,f,t,i,l,h,c,a.getX(n),a.getX(n+1),a.getX(n+2)),s&&(s.faceIndex=Math.floor(n/3),s.face.materialIndex=o.materialIndex,e.push(s))}}else{for(let n=Math.max(0,u.start),o=Math.min(a.count,u.start+u.count);n<o;n+=3){s=sF(this,r,t,i,l,h,c,a.getX(n),a.getX(n+1),a.getX(n+2)),s&&(s.faceIndex=Math.floor(n/3),e.push(s))}}else if(void 0!==o)if(Array.isArray(r))for(let n=0,a=d.length;n<a;n++){const a=d[n],f=r[a.materialIndex];for(let n=Math.max(a.start,u.start),r=Math.min(o.count,Math.min(a.start+a.count,u.start+u.count));n<r;n+=3){s=sF(this,f,t,i,l,h,c,n,n+1,n+2),s&&(s.faceIndex=Math.floor(n/3),s.face.materialIndex=a.materialIndex,e.push(s))}}else{for(let n=Math.max(0,u.start),a=Math.min(o.count,u.start+u.count);n<a;n+=3){s=sF(this,r,t,i,l,h,c,n,n+1,n+2),s&&(s.faceIndex=Math.floor(n/3),e.push(s))}}}}function sF(t,e,i,s,n,r,a,o,l,h){t.getVertexPosition(o,GN),t.getVertexPosition(l,WN),t.getVertexPosition(h,XN);const c=function(t,e,i,s,n,r,a,o){let l;if(l=1===e.side?s.intersectTriangle(a,r,n,!0,o):s.intersectTriangle(n,r,a,0===e.side,o),null===l)return null;eF.copy(o),eF.applyMatrix4(t.matrixWorld);const h=i.ray.origin.distanceTo(eF);return h<i.near||h>i.far?null:{distance:h,point:eF.clone(),object:t}}(t,e,i,s,GN,WN,XN,tF);if(c){n&&(jN.fromBufferAttribute(n,o),$N.fromBufferAttribute(n,l),KN.fromBufferAttribute(n,h),c.uv=mN.getInterpolation(tF,GN,WN,XN,jN,$N,KN,new MI)),r&&(jN.fromBufferAttribute(r,o),$N.fromBufferAttribute(r,l),KN.fromBufferAttribute(r,h),c.uv1=mN.getInterpolation(tF,GN,WN,XN,jN,$N,KN,new MI),c.uv2=c.uv1),a&&(ZN.fromBufferAttribute(a,o),QN.fromBufferAttribute(a,l),JN.fromBufferAttribute(a,h),c.normal=mN.getInterpolation(tF,GN,WN,XN,ZN,QN,JN,new iO),c.normal.dot(s.direction)>0&&c.normal.multiplyScalar(-1));const t={a:o,b:l,c:h,normal:new iO,materialIndex:0};mN.getNormal(GN,WN,XN,t.normal),c.face=t}return c}class nF extends BN{constructor(t=1,e=1,i=1,s=1,n=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:i,widthSegments:s,heightSegments:n,depthSegments:r};const a=this;s=Math.floor(s),n=Math.floor(n),r=Math.floor(r);const o=[],l=[],h=[],c=[];let d=0,u=0;function f(t,e,i,s,n,r,f,p,m,_,g){const v=r/m,S=f/_,y=r/2,x=f/2,T=p/2,E=m+1,b=_+1;let w=0,A=0;const C=new iO;for(let r=0;r<b;r++){const a=r*S-x;for(let o=0;o<E;o++){const d=o*v-y;C[t]=d*s,C[e]=a*n,C[i]=T,l.push(C.x,C.y,C.z),C[t]=0,C[e]=0,C[i]=p>0?1:-1,h.push(C.x,C.y,C.z),c.push(o/m),c.push(1-r/_),w+=1}}for(let t=0;t<_;t++)for(let e=0;e<m;e++){const i=d+e+E*t,s=d+e+E*(t+1),n=d+(e+1)+E*(t+1),r=d+(e+1)+E*t;o.push(i,s,r),o.push(s,n,r),A+=6}a.addGroup(u,A,g),u+=A,d+=w}f("z","y","x",-1,-1,i,e,t,r,n,0),f("z","y","x",1,-1,i,e,-t,r,n,1),f("x","z","y",1,1,t,i,e,s,r,2),f("x","z","y",1,-1,t,i,-e,s,r,3),f("x","y","z",1,-1,t,e,i,s,n,4),f("x","y","z",-1,-1,t,e,-i,s,n,5),this.setIndex(o),this.setAttribute("position",new RN(l,3)),this.setAttribute("normal",new RN(h,3)),this.setAttribute("uv",new RN(c,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new nF(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function rF(t){const e={};for(const i in t){e[i]={};for(const s in t[i]){const n=t[i][s];n&&(n.isColor||n.isMatrix3||n.isMatrix4||n.isVector2||n.isVector3||n.isVector4||n.isTexture||n.isQuaternion)?n.isRenderTargetTexture?e[i][s]=null:e[i][s]=n.clone():Array.isArray(n)?e[i][s]=n.slice():e[i][s]=n}}return e}function aF(t){const e={};for(let i=0;i<t.length;i++){const s=rF(t[i]);for(const t in s)e[t]=s[t]}return e}function oF(t){return null===t.getRenderTarget()?t.outputColorSpace:kI.workingColorSpace}const lF={clone:rF,merge:aF};class hF extends gN{constructor(t){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",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={derivatives:!1,fragDepth:!1,drawBuffers:!1,shaderTextureLOD:!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=rF(t.uniforms),this.uniformsGroups=function(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].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 i in this.uniforms){const s=this.uniforms[i].value;s&&s.isTexture?e.uniforms[i]={type:"t",value:s.toJSON(t).uuid}:s&&s.isColor?e.uniforms[i]={type:"c",value:s.getHex()}:s&&s.isVector2?e.uniforms[i]={type:"v2",value:s.toArray()}:s&&s.isVector3?e.uniforms[i]={type:"v3",value:s.toArray()}:s&&s.isVector4?e.uniforms[i]={type:"v4",value:s.toArray()}:s&&s.isMatrix3?e.uniforms[i]={type:"m3",value:s.toArray()}:s&&s.isMatrix4?e.uniforms[i]={type:"m4",value:s.toArray()}:e.uniforms[i]={value:s}}Object.keys(this.defines).length>0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const i={};for(const t in this.extensions)!0===this.extensions[t]&&(i[t]=!0);return Object.keys(i).length>0&&(e.extensions=i),e}}class cF extends sN{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new DO,this.projectionMatrix=new DO,this.projectionMatrixInverse=new DO,this.coordinateSystem=mI}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)}}class dF extends cF{constructor(t=50,e=1,i=.1,s=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=i,this.far=s,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=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*yI*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*SI*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*yI*Math.atan(Math.tan(.5*SI*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}setViewOffset(t,e,i,s,n,r){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=i,this.view.offsetY=s,this.view.width=n,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*SI*this.fov)/this.zoom,i=2*e,s=this.aspect*i,n=-.5*s;const r=this.view;if(null!==this.view&&this.view.enabled){const t=r.fullWidth,a=r.fullHeight;n+=r.offsetX*s/t,e-=r.offsetY*i/a,s*=r.width/t,i*=r.height/a}const a=this.filmOffset;0!==a&&(n+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(n,n+s,e,e-i,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const uF=-90;class fF extends sN{constructor(t,e,i){super(),this.type="CubeCamera",this.renderTarget=i,this.coordinateSystem=null,this.activeMipmapLevel=0;const s=new dF(uF,1,t,e);s.layers=this.layers,this.add(s);const n=new dF(uF,1,t,e);n.layers=this.layers,this.add(n);const r=new dF(uF,1,t,e);r.layers=this.layers,this.add(r);const a=new dF(uF,1,t,e);a.layers=this.layers,this.add(a);const o=new dF(uF,1,t,e);o.layers=this.layers,this.add(o);const l=new dF(uF,1,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[i,s,n,r,a,o]=e;for(const t of e)this.remove(t);if(t===mI)i.up.set(0,1,0),i.lookAt(1,0,0),s.up.set(0,1,0),s.lookAt(-1,0,0),n.up.set(0,0,-1),n.lookAt(0,1,0),r.up.set(0,0,1),r.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),o.up.set(0,1,0),o.lookAt(0,0,-1);else{if(t!==_I)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);i.up.set(0,-1,0),i.lookAt(-1,0,0),s.up.set(0,-1,0),s.lookAt(1,0,0),n.up.set(0,0,1),n.lookAt(0,1,0),r.up.set(0,0,-1),r.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),o.up.set(0,-1,0),o.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:i,activeMipmapLevel:s}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[n,r,a,o,l,h]=this.children,c=t.getRenderTarget(),d=t.getActiveCubeFace(),u=t.getActiveMipmapLevel(),f=t.xr.enabled;t.xr.enabled=!1;const p=i.texture.generateMipmaps;i.texture.generateMipmaps=!1,t.setRenderTarget(i,0,s),t.render(e,n),t.setRenderTarget(i,1,s),t.render(e,r),t.setRenderTarget(i,2,s),t.render(e,a),t.setRenderTarget(i,3,s),t.render(e,o),t.setRenderTarget(i,4,s),t.render(e,l),i.texture.generateMipmaps=p,t.setRenderTarget(i,5,s),t.render(e,h),t.setRenderTarget(c,d,u),t.xr.enabled=f,i.texture.needsPMREMUpdate=!0}}class pF extends $I{constructor(t,e,i,s,n,r,a,o,l,h){super(t=void 0!==t?t:[],e=void 0!==e?e:xD,i,s,n,r,a,o,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class mF extends QI{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const i={width:t,height:t,depth:1},s=[i,i,i,i,i,i];void 0!==e.encoding&&(NI("THREE.WebGLCubeRenderTarget: option.encoding has been replaced by option.colorSpace."),e.colorSpace=e.encoding===jD?KD:$D),this.texture=new pF(s,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==e.generateMipmaps&&e.generateMipmaps,this.texture.minFilter=void 0!==e.minFilter?e.minFilter:RD}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const i={uniforms:{tEquirect:{value:null}},vertexShader:"\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"},s=new nF(5,5,5),n=new hF({name:"CubemapFromEquirect",uniforms:rF(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:1,blending:0});n.uniforms.tEquirect.value=e;const r=new iF(s,n),a=e.minFilter;e.minFilter===DD&&(e.minFilter=RD);return new fF(1,10,this).update(t,r),e.minFilter=a,r.geometry.dispose(),r.material.dispose(),this}clear(t,e,i,s){const n=t.getRenderTarget();for(let n=0;n<6;n++)t.setRenderTarget(this,n),t.clear(e,i,s);t.setRenderTarget(n)}}const _F=new iO,gF=new iO,vF=new PI;class SF{constructor(t=new iO(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,s){return this.normal.set(t,e,i),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const s=_F.subVectors(i,e).cross(gF.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const i=t.delta(_F),s=this.normal.dot(i);if(0===s)return 0===this.distanceToPoint(t.start)?e.copy(t.start):null;const n=-(t.start.dot(this.normal)+this.constant)/s;return n<0||n>1?null:e.copy(t.start).addScaledVector(i,n)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const i=e||vF.getNormalMatrix(t),s=this.coplanarPoint(_F).applyMatrix4(t),n=this.normal.applyMatrix3(i).normalize();return this.constant=-s.dot(n),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}const yF=new EO,xF=new iO;class TF{constructor(t=new SF,e=new SF,i=new SF,s=new SF,n=new SF,r=new SF){this.planes=[t,e,i,s,n,r]}set(t,e,i,s,n,r){const a=this.planes;return a[0].copy(t),a[1].copy(e),a[2].copy(i),a[3].copy(s),a[4].copy(n),a[5].copy(r),this}copy(t){const e=this.planes;for(let i=0;i<6;i++)e[i].copy(t.planes[i]);return this}setFromProjectionMatrix(t,e=2e3){const i=this.planes,s=t.elements,n=s[0],r=s[1],a=s[2],o=s[3],l=s[4],h=s[5],c=s[6],d=s[7],u=s[8],f=s[9],p=s[10],m=s[11],_=s[12],g=s[13],v=s[14],S=s[15];if(i[0].setComponents(o-n,d-l,m-u,S-_).normalize(),i[1].setComponents(o+n,d+l,m+u,S+_).normalize(),i[2].setComponents(o+r,d+h,m+f,S+g).normalize(),i[3].setComponents(o-r,d-h,m-f,S-g).normalize(),i[4].setComponents(o-a,d-c,m-p,S-v).normalize(),e===mI)i[5].setComponents(o+a,d+c,m+p,S+v).normalize();else{if(e!==_I)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);i[5].setComponents(a,c,p,v).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),yF.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),yF.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(yF)}intersectsSprite(t){return yF.center.set(0,0,0),yF.radius=.7071067811865476,yF.applyMatrix4(t.matrixWorld),this.intersectsSphere(yF)}intersectsSphere(t){const e=this.planes,i=t.center,s=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(i)<s)return!1}return!0}intersectsBox(t){const e=this.planes;for(let i=0;i<6;i++){const s=e[i];if(xF.x=s.normal.x>0?t.max.x:t.min.x,xF.y=s.normal.y>0?t.max.y:t.min.y,xF.z=s.normal.z>0?t.max.z:t.min.z,s.distanceToPoint(xF)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let i=0;i<6;i++)if(e[i].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function EF(){let t=null,e=!1,i=null,s=null;function n(e,r){i(e,r),s=t.requestAnimationFrame(n)}return{start:function(){!0!==e&&null!==i&&(s=t.requestAnimationFrame(n),e=!0)},stop:function(){t.cancelAnimationFrame(s),e=!1},setAnimationLoop:function(t){i=t},setContext:function(e){t=e}}}function bF(t,e){const i=e.isWebGL2,s=new WeakMap;return{get:function(t){return t.isInterleavedBufferAttribute&&(t=t.data),s.get(t)},remove:function(e){e.isInterleavedBufferAttribute&&(e=e.data);const i=s.get(e);i&&(t.deleteBuffer(i.buffer),s.delete(e))},update:function(e,n){if(e.isGLBufferAttribute){const t=s.get(e);return void((!t||t.version<e.version)&&s.set(e,{buffer:e.buffer,type:e.type,bytesPerElement:e.elementSize,version:e.version}))}e.isInterleavedBufferAttribute&&(e=e.data);const r=s.get(e);void 0===r?s.set(e,function(e,s){const n=e.array,r=e.usage,a=t.createBuffer();let o;if(t.bindBuffer(s,a),t.bufferData(s,n,r),e.onUploadCallback(),n instanceof Float32Array)o=t.FLOAT;else if(n instanceof Uint16Array)if(e.isFloat16BufferAttribute){if(!i)throw new Error("THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.");o=t.HALF_FLOAT}else o=t.UNSIGNED_SHORT;else if(n instanceof Int16Array)o=t.SHORT;else if(n instanceof Uint32Array)o=t.UNSIGNED_INT;else if(n instanceof Int32Array)o=t.INT;else if(n instanceof Int8Array)o=t.BYTE;else if(n instanceof Uint8Array)o=t.UNSIGNED_BYTE;else{if(!(n instanceof Uint8ClampedArray))throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+n);o=t.UNSIGNED_BYTE}return{buffer:a,type:o,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version}}(e,n)):r.version<e.version&&(!function(e,s,n){const r=s.array,a=s.updateRange;t.bindBuffer(n,e),-1===a.count?t.bufferSubData(n,0,r):(i?t.bufferSubData(n,a.offset*r.BYTES_PER_ELEMENT,r,a.offset,a.count):t.bufferSubData(n,a.offset*r.BYTES_PER_ELEMENT,r.subarray(a.offset,a.offset+a.count)),a.count=-1),s.onUploadCallback()}(r.buffer,e,n),r.version=e.version)}}}class wF extends BN{constructor(t=1,e=1,i=1,s=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:i,heightSegments:s};const n=t/2,r=e/2,a=Math.floor(i),o=Math.floor(s),l=a+1,h=o+1,c=t/a,d=e/o,u=[],f=[],p=[],m=[];for(let t=0;t<h;t++){const e=t*d-r;for(let i=0;i<l;i++){const s=i*c-n;f.push(s,-e,0),p.push(0,0,1),m.push(i/a),m.push(1-t/o)}}for(let t=0;t<o;t++)for(let e=0;e<a;e++){const i=e+l*t,s=e+l*(t+1),n=e+1+l*(t+1),r=e+1+l*t;u.push(i,s,r),u.push(s,n,r)}this.setIndex(u),this.setAttribute("position",new RN(f,3)),this.setAttribute("normal",new RN(p,3)),this.setAttribute("uv",new RN(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new wF(t.width,t.height,t.widthSegments,t.heightSegments)}}const AF={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\tif ( diffuseColor.a < alphaTest ) discard;\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_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",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 = dFdx( surf_pos.xyz );\n\t\tvec3 vSigmaY = 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#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\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 )\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 )\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",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}\nfloat luminance( const in vec3 rgb ) {\n\tconst vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 );\n\treturn dot( weights, rgb );\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_v0 0.339\n\t#define cubeUV_m0 - 2.0\n\t#define cubeUV_r1 0.8\n\t#define cubeUV_v1 0.276\n\t#define cubeUV_m1 - 1.0\n\t#define cubeUV_r4 0.4\n\t#define cubeUV_v4 0.046\n\t#define cubeUV_m4 2.0\n\t#define cubeUV_r5 0.305\n\t#define cubeUV_v5 0.016\n\t#define cubeUV_m5 3.0\n\t#define cubeUV_r6 0.21\n\t#define cubeUV_v6 0.0038\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_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 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\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:"\nconst mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(\n\tvec3( 0.8224621, 0.177538, 0.0 ),\n\tvec3( 0.0331941, 0.9668058, 0.0 ),\n\tvec3( 0.0170827, 0.0723974, 0.9105199 )\n);\nconst mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.2249401, - 0.2249404, 0.0 ),\n\tvec3( - 0.0420569, 1.0420571, 0.0 ),\n\tvec3( - 0.0196376, - 0.0786361, 1.0982735 )\n);\nvec4 LinearSRGBToLinearDisplayP3( in vec4 value ) {\n\treturn vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a );\n}\nvec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) {\n\treturn vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a );\n}\nvec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\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}\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn sRGBTransferOETF( value );\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, 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\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, 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, 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_fragment:"#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\treflectedLight.indirectDiffuse += lightMapIrradiance;\n#endif",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\t#if defined ( LEGACY_LIGHTS )\n\t\tif ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\t\treturn pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t\t}\n\t\treturn 1.0;\n\t#else\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\t\tif ( cutoffDistance > 0.0 ) {\n\t\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t\t}\n\t\treturn distanceFalloff;\n\t#endif\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_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\tanisotropyV /= material.anisotropy;\n\tmaterial.anisotropy = saturate( material.anisotropy );\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\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 clearcoatSpecular = vec3( 0.0 );\nvec3 sheenSpecular = 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\tclearcoatSpecular += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecular += 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\tclearcoatSpecular += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecular += 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;\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.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.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.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 ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif",logdepthbuf_pars_fragment:"#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_pars_vertex:"#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif",map_fragment:"#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );\n\t\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",morphcolor_vertex:"#if defined( USE_MORPHCOLORS ) && defined( MORPHTARGETS_TEXTURE )\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\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t\t}\n\t#else\n\t\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\t\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\t\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\t\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n\t#endif\n#endif",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t\tuniform sampler2DArray morphTargetsTexture;\n\t\tuniform ivec2 morphTargetsTextureSize;\n\t\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t\t}\n\t#else\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\tuniform float morphTargetInfluences[ 8 ];\n\t\t#else\n\t\t\tuniform float morphTargetInfluences[ 4 ];\n\t\t#endif\n\t#endif\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t\t}\n\t#else\n\t\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\t\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\t\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\t\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t\t#endif\n\t#endif\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.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec2 packDepthToRG( in highp float v ) {\n\treturn packDepthToRGBA( v ).yx;\n}\nfloat unpackRGToDepth( const in highp vec2 v ) {\n\treturn unpackRGBAToDepth( vec4( v.xy, 0.0, 0.0 ) );\n}\nvec4 pack2HalfToRGBA( 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( 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_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 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 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 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 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 shadow;\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 shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\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 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 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 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.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.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.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\tuniform int boneTextureSize;\n\tmat4 getBoneMatrix( const in float i ) {\n\t\tfloat j = i * 4.0;\n\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\ty = dy * ( y + 0.5 );\n\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\treturn bone;\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 OptimizedCineonToneMapping( 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}\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.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 ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\trefractionCoords += 1.0;\n\t\trefractionCoords /= 2.0;\n\t\tvec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\tvec3 transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\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_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;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, 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 <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 <skinbase_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\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#endif\n}",distanceRGBA_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\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 <skinbase_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\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 <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\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <morphcolor_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <morphcolor_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <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#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\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 ), opacity );\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 <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 <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}",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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <morphcolor_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_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 + sheenSpecular;\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 ) + clearcoatSpecular * 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 <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 <morphcolor_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <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 <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 * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\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\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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}"},CF={common:{diffuse:{value:new TN(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new PI},alphaMap:{value:null},alphaMapTransform:{value:new PI},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new PI}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new PI}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new PI}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new PI},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new PI},normalScale:{value:new MI(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new PI},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new PI}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new PI}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new PI}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new TN(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{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 TN(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new PI},alphaTest:{value:0},uvTransform:{value:new PI}},sprite:{diffuse:{value:new TN(16777215)},opacity:{value:1},center:{value:new MI(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new PI},alphaMap:{value:null},alphaMapTransform:{value:new PI},alphaTest:{value:0}}},MF={basic:{uniforms:aF([CF.common,CF.specularmap,CF.envmap,CF.aomap,CF.lightmap,CF.fog]),vertexShader:AF.meshbasic_vert,fragmentShader:AF.meshbasic_frag},lambert:{uniforms:aF([CF.common,CF.specularmap,CF.envmap,CF.aomap,CF.lightmap,CF.emissivemap,CF.bumpmap,CF.normalmap,CF.displacementmap,CF.fog,CF.lights,{emissive:{value:new TN(0)}}]),vertexShader:AF.meshlambert_vert,fragmentShader:AF.meshlambert_frag},phong:{uniforms:aF([CF.common,CF.specularmap,CF.envmap,CF.aomap,CF.lightmap,CF.emissivemap,CF.bumpmap,CF.normalmap,CF.displacementmap,CF.fog,CF.lights,{emissive:{value:new TN(0)},specular:{value:new TN(1118481)},shininess:{value:30}}]),vertexShader:AF.meshphong_vert,fragmentShader:AF.meshphong_frag},standard:{uniforms:aF([CF.common,CF.envmap,CF.aomap,CF.lightmap,CF.emissivemap,CF.bumpmap,CF.normalmap,CF.displacementmap,CF.roughnessmap,CF.metalnessmap,CF.fog,CF.lights,{emissive:{value:new TN(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:AF.meshphysical_vert,fragmentShader:AF.meshphysical_frag},toon:{uniforms:aF([CF.common,CF.aomap,CF.lightmap,CF.emissivemap,CF.bumpmap,CF.normalmap,CF.displacementmap,CF.gradientmap,CF.fog,CF.lights,{emissive:{value:new TN(0)}}]),vertexShader:AF.meshtoon_vert,fragmentShader:AF.meshtoon_frag},matcap:{uniforms:aF([CF.common,CF.bumpmap,CF.normalmap,CF.displacementmap,CF.fog,{matcap:{value:null}}]),vertexShader:AF.meshmatcap_vert,fragmentShader:AF.meshmatcap_frag},points:{uniforms:aF([CF.points,CF.fog]),vertexShader:AF.points_vert,fragmentShader:AF.points_frag},dashed:{uniforms:aF([CF.common,CF.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:AF.linedashed_vert,fragmentShader:AF.linedashed_frag},depth:{uniforms:aF([CF.common,CF.displacementmap]),vertexShader:AF.depth_vert,fragmentShader:AF.depth_frag},normal:{uniforms:aF([CF.common,CF.bumpmap,CF.normalmap,CF.displacementmap,{opacity:{value:1}}]),vertexShader:AF.meshnormal_vert,fragmentShader:AF.meshnormal_frag},sprite:{uniforms:aF([CF.sprite,CF.fog]),vertexShader:AF.sprite_vert,fragmentShader:AF.sprite_frag},background:{uniforms:{uvTransform:{value:new PI},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:AF.background_vert,fragmentShader:AF.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1}},vertexShader:AF.backgroundCube_vert,fragmentShader:AF.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:AF.cube_vert,fragmentShader:AF.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:AF.equirect_vert,fragmentShader:AF.equirect_frag},distanceRGBA:{uniforms:aF([CF.common,CF.displacementmap,{referencePosition:{value:new iO},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:AF.distanceRGBA_vert,fragmentShader:AF.distanceRGBA_frag},shadow:{uniforms:aF([CF.lights,CF.fog,{color:{value:new TN(0)},opacity:{value:1}}]),vertexShader:AF.shadow_vert,fragmentShader:AF.shadow_frag}};MF.physical={uniforms:aF([MF.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new PI},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new PI},clearcoatNormalScale:{value:new MI(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new PI},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new PI},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new PI},sheen:{value:0},sheenColor:{value:new TN(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new PI},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new PI},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new PI},transmissionSamplerSize:{value:new MI},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new PI},attenuationDistance:{value:0},attenuationColor:{value:new TN(0)},specularColor:{value:new TN(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new PI},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new PI},anisotropyVector:{value:new MI},anisotropyMap:{value:null},anisotropyMapTransform:{value:new PI}}]),vertexShader:AF.meshphysical_vert,fragmentShader:AF.meshphysical_frag};const PF={r:0,b:0,g:0};function RF(t,e,i,s,n,r,a){const o=new TN(0);let l,h,c=!0===r?0:1,d=null,u=0,f=null;function p(e,i){e.getRGB(PF,oF(t)),s.buffers.color.setClear(PF.r,PF.g,PF.b,i,a)}return{getClearColor:function(){return o},setClearColor:function(t,e=1){o.set(t),c=e,p(o,c)},getClearAlpha:function(){return c},setClearAlpha:function(t){c=t,p(o,c)},render:function(r,m){let _=!1,g=!0===m.isScene?m.background:null;if(g&&g.isTexture){g=(m.backgroundBlurriness>0?i:e).get(g)}null===g?p(o,c):g&&g.isColor&&(p(g,1),_=!0);const v=t.xr.getEnvironmentBlendMode();"additive"===v?s.buffers.color.setClear(0,0,0,1,a):"alpha-blend"===v&&s.buffers.color.setClear(0,0,0,0,a),(t.autoClear||_)&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),g&&(g.isCubeTexture||g.mapping===ED)?(void 0===h&&(h=new iF(new nF(1,1,1),new hF({name:"BackgroundCubeMaterial",uniforms:rF(MF.backgroundCube.uniforms),vertexShader:MF.backgroundCube.vertexShader,fragmentShader:MF.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1})),h.geometry.deleteAttribute("normal"),h.geometry.deleteAttribute("uv"),h.onBeforeRender=function(t,e,i){this.matrixWorld.copyPosition(i.matrixWorld)},Object.defineProperty(h.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),n.update(h)),h.material.uniforms.envMap.value=g,h.material.uniforms.flipEnvMap.value=g.isCubeTexture&&!1===g.isRenderTargetTexture?-1:1,h.material.uniforms.backgroundBlurriness.value=m.backgroundBlurriness,h.material.uniforms.backgroundIntensity.value=m.backgroundIntensity,h.material.toneMapped=kI.getTransfer(g.colorSpace)!==eI,d===g&&u===g.version&&f===t.toneMapping||(h.material.needsUpdate=!0,d=g,u=g.version,f=t.toneMapping),h.layers.enableAll(),r.unshift(h,h.geometry,h.material,0,0,null)):g&&g.isTexture&&(void 0===l&&(l=new iF(new wF(2,2),new hF({name:"BackgroundMaterial",uniforms:rF(MF.background.uniforms),vertexShader:MF.background.vertexShader,fragmentShader:MF.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}}),n.update(l)),l.material.uniforms.t2D.value=g,l.material.uniforms.backgroundIntensity.value=m.backgroundIntensity,l.material.toneMapped=kI.getTransfer(g.colorSpace)!==eI,!0===g.matrixAutoUpdate&&g.updateMatrix(),l.material.uniforms.uvTransform.value.copy(g.matrix),d===g&&u===g.version&&f===t.toneMapping||(l.material.needsUpdate=!0,d=g,u=g.version,f=t.toneMapping),l.layers.enableAll(),r.unshift(l,l.geometry,l.material,0,0,null))}}}function LF(t,e,i,s){const n=t.getParameter(t.MAX_VERTEX_ATTRIBS),r=s.isWebGL2?null:e.get("OES_vertex_array_object"),a=s.isWebGL2||null!==r,o={},l=f(null);let h=l,c=!1;function d(e){return s.isWebGL2?t.bindVertexArray(e):r.bindVertexArrayOES(e)}function u(e){return s.isWebGL2?t.deleteVertexArray(e):r.deleteVertexArrayOES(e)}function f(t){const e=[],i=[],s=[];for(let t=0;t<n;t++)e[t]=0,i[t]=0,s[t]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:e,enabledAttributes:i,attributeDivisors:s,object:t,attributes:{},index:null}}function p(){const t=h.newAttributes;for(let e=0,i=t.length;e<i;e++)t[e]=0}function m(t){_(t,0)}function _(i,n){const r=h.newAttributes,a=h.enabledAttributes,o=h.attributeDivisors;if(r[i]=1,0===a[i]&&(t.enableVertexAttribArray(i),a[i]=1),o[i]!==n){(s.isWebGL2?t:e.get("ANGLE_instanced_arrays"))[s.isWebGL2?"vertexAttribDivisor":"vertexAttribDivisorANGLE"](i,n),o[i]=n}}function g(){const e=h.newAttributes,i=h.enabledAttributes;for(let s=0,n=i.length;s<n;s++)i[s]!==e[s]&&(t.disableVertexAttribArray(s),i[s]=0)}function v(e,i,s,n,r,a,o){!0===o?t.vertexAttribIPointer(e,i,s,r,a):t.vertexAttribPointer(e,i,s,n,r,a)}function S(){y(),c=!0,h!==l&&(h=l,d(h.object))}function y(){l.geometry=null,l.program=null,l.wireframe=!1}return{setup:function(n,l,u,S,y){let x=!1;if(a){const e=function(e,i,n){const a=!0===n.wireframe;let l=o[e.id];void 0===l&&(l={},o[e.id]=l);let h=l[i.id];void 0===h&&(h={},l[i.id]=h);let c=h[a];void 0===c&&(c=f(s.isWebGL2?t.createVertexArray():r.createVertexArrayOES()),h[a]=c);return c}(S,u,l);h!==e&&(h=e,d(h.object)),x=function(t,e,i,s){const n=h.attributes,r=e.attributes;let a=0;const o=i.getAttributes();for(const e in o){if(o[e].location>=0){const i=n[e];let s=r[e];if(void 0===s&&("instanceMatrix"===e&&t.instanceMatrix&&(s=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(s=t.instanceColor)),void 0===i)return!0;if(i.attribute!==s)return!0;if(s&&i.data!==s.data)return!0;a++}}return h.attributesNum!==a||h.index!==s}(n,S,u,y),x&&function(t,e,i,s){const n={},r=e.attributes;let a=0;const o=i.getAttributes();for(const e in o){if(o[e].location>=0){let i=r[e];void 0===i&&("instanceMatrix"===e&&t.instanceMatrix&&(i=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(i=t.instanceColor));const s={};s.attribute=i,i&&i.data&&(s.data=i.data),n[e]=s,a++}}h.attributes=n,h.attributesNum=a,h.index=s}(n,S,u,y)}else{const t=!0===l.wireframe;h.geometry===S.id&&h.program===u.id&&h.wireframe===t||(h.geometry=S.id,h.program=u.id,h.wireframe=t,x=!0)}null!==y&&i.update(y,t.ELEMENT_ARRAY_BUFFER),(x||c)&&(c=!1,function(n,r,a,o){if(!1===s.isWebGL2&&(n.isInstancedMesh||o.isInstancedBufferGeometry)&&null===e.get("ANGLE_instanced_arrays"))return;p();const l=o.attributes,h=a.getAttributes(),c=r.defaultAttributeValues;for(const e in h){const r=h[e];if(r.location>=0){let a=l[e];if(void 0===a&&("instanceMatrix"===e&&n.instanceMatrix&&(a=n.instanceMatrix),"instanceColor"===e&&n.instanceColor&&(a=n.instanceColor)),void 0!==a){const e=a.normalized,l=a.itemSize,h=i.get(a);if(void 0===h)continue;const c=h.buffer,d=h.type,u=h.bytesPerElement,f=!0===s.isWebGL2&&(d===t.INT||d===t.UNSIGNED_INT||a.gpuType===ND);if(a.isInterleavedBufferAttribute){const i=a.data,s=i.stride,h=a.offset;if(i.isInstancedInterleavedBuffer){for(let t=0;t<r.locationSize;t++)_(r.location+t,i.meshPerAttribute);!0!==n.isInstancedMesh&&void 0===o._maxInstanceCount&&(o._maxInstanceCount=i.meshPerAttribute*i.count)}else for(let t=0;t<r.locationSize;t++)m(r.location+t);t.bindBuffer(t.ARRAY_BUFFER,c);for(let t=0;t<r.locationSize;t++)v(r.location+t,l/r.locationSize,d,e,s*u,(h+l/r.locationSize*t)*u,f)}else{if(a.isInstancedBufferAttribute){for(let t=0;t<r.locationSize;t++)_(r.location+t,a.meshPerAttribute);!0!==n.isInstancedMesh&&void 0===o._maxInstanceCount&&(o._maxInstanceCount=a.meshPerAttribute*a.count)}else for(let t=0;t<r.locationSize;t++)m(r.location+t);t.bindBuffer(t.ARRAY_BUFFER,c);for(let t=0;t<r.locationSize;t++)v(r.location+t,l/r.locationSize,d,e,l*u,l/r.locationSize*t*u,f)}}else if(void 0!==c){const i=c[e];if(void 0!==i)switch(i.length){case 2:t.vertexAttrib2fv(r.location,i);break;case 3:t.vertexAttrib3fv(r.location,i);break;case 4:t.vertexAttrib4fv(r.location,i);break;default:t.vertexAttrib1fv(r.location,i)}}}}g()}(n,l,u,S),null!==y&&t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,i.get(y).buffer))},reset:S,resetDefaultState:y,dispose:function(){S();for(const t in o){const e=o[t];for(const t in e){const i=e[t];for(const t in i)u(i[t].object),delete i[t];delete e[t]}delete o[t]}},releaseStatesOfGeometry:function(t){if(void 0===o[t.id])return;const e=o[t.id];for(const t in e){const i=e[t];for(const t in i)u(i[t].object),delete i[t];delete e[t]}delete o[t.id]},releaseStatesOfProgram:function(t){for(const e in o){const i=o[e];if(void 0===i[t.id])continue;const s=i[t.id];for(const t in s)u(s[t].object),delete s[t];delete i[t.id]}},initAttributes:p,enableAttribute:m,disableUnusedAttributes:g}}function DF(t,e,i,s){const n=s.isWebGL2;let r;this.setMode=function(t){r=t},this.render=function(e,s){t.drawArrays(r,e,s),i.update(s,r,1)},this.renderInstances=function(s,a,o){if(0===o)return;let l,h;if(n)l=t,h="drawArraysInstanced";else if(l=e.get("ANGLE_instanced_arrays"),h="drawArraysInstancedANGLE",null===l)return;l[h](r,s,a,o),i.update(a,r,o)}}function IF(t,e,i){let s;function n(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"}const r="undefined"!=typeof WebGL2RenderingContext&&"WebGL2RenderingContext"===t.constructor.name;let a=void 0!==i.precision?i.precision:"highp";const o=n(a);o!==a&&(a=o);const l=r||e.has("WEBGL_draw_buffers"),h=!0===i.logarithmicDepthBuffer,c=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),d=t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS),u=t.getParameter(t.MAX_TEXTURE_SIZE),f=t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE),p=t.getParameter(t.MAX_VERTEX_ATTRIBS),m=t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS),_=t.getParameter(t.MAX_VARYING_VECTORS),g=t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS),v=d>0,S=r||e.has("OES_texture_float");return{isWebGL2:r,drawBuffers:l,getMaxAnisotropy:function(){if(void 0!==s)return s;if(!0===e.has("EXT_texture_filter_anisotropic")){const i=e.get("EXT_texture_filter_anisotropic");s=t.getParameter(i.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else s=0;return s},getMaxPrecision:n,precision:a,logarithmicDepthBuffer:h,maxTextures:c,maxVertexTextures:d,maxTextureSize:u,maxCubemapSize:f,maxAttributes:p,maxVertexUniforms:m,maxVaryings:_,maxFragmentUniforms:g,vertexTextures:v,floatFragmentTextures:S,floatVertexTextures:v&&S,maxSamples:r?t.getParameter(t.MAX_SAMPLES):0}}function OF(t){const e=this;let i=null,s=0,n=!1,r=!1;const a=new SF,o=new PI,l={value:null,needsUpdate:!1};function h(t,i,s,n){const r=null!==t?t.length:0;let h=null;if(0!==r){if(h=l.value,!0!==n||null===h){const e=s+4*r,n=i.matrixWorldInverse;o.getNormalMatrix(n),(null===h||h.length<e)&&(h=new Float32Array(e));for(let e=0,i=s;e!==r;++e,i+=4)a.copy(t[e]).applyMatrix4(n,o),a.normal.toArray(h,i),h[i+3]=a.constant}l.value=h,l.needsUpdate=!0}return e.numPlanes=r,e.numIntersection=0,h}this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(t,e){const i=0!==t.length||e||0!==s||n;return n=e,s=t.length,i},this.beginShadows=function(){r=!0,h(null)},this.endShadows=function(){r=!1},this.setGlobalState=function(t,e){i=h(t,e,0)},this.setState=function(a,o,c){const d=a.clippingPlanes,u=a.clipIntersection,f=a.clipShadows,p=t.get(a);if(!n||null===d||0===d.length||r&&!f)r?h(null):function(){l.value!==i&&(l.value=i,l.needsUpdate=s>0);e.numPlanes=s,e.numIntersection=0}();else{const t=r?0:s,e=4*t;let n=p.clippingState||null;l.value=n,n=h(d,o,e,c);for(let t=0;t!==e;++t)n[t]=i[t];p.clippingState=n,this.numIntersection=u?this.numPlanes:0,this.numPlanes+=t}}}function NF(t){let e=new WeakMap;function i(t,e){return 303===e?t.mapping=xD:304===e&&(t.mapping=TD),t}function s(t){const i=t.target;i.removeEventListener("dispose",s);const n=e.get(i);void 0!==n&&(e.delete(i),n.dispose())}return{get:function(n){if(n&&n.isTexture&&!1===n.isRenderTargetTexture){const r=n.mapping;if(303===r||304===r){if(e.has(n)){return i(e.get(n).texture,n.mapping)}{const r=n.image;if(r&&r.height>0){const a=new mF(r.height/2);return a.fromEquirectangularTexture(t,n),e.set(n,a),n.addEventListener("dispose",s),i(a.texture,n.mapping)}return null}}}return n},dispose:function(){e=new WeakMap}}}class FF extends cF{constructor(t=-1,e=1,i=1,s=-1,n=.1,r=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=i,this.bottom=s,this.near=n,this.far=r,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=null===t.view?null:Object.assign({},t.view),this}setViewOffset(t,e,i,s,n,r){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=i,this.view.offsetY=s,this.view.width=n,this.view.height=r,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),i=(this.right+this.left)/2,s=(this.top+this.bottom)/2;let n=i-t,r=i+t,a=s+e,o=s-e;if(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;n+=t*this.view.offsetX,r=n+t*this.view.width,a-=e*this.view.offsetY,o=a-e*this.view.height}this.projectionMatrix.makeOrthographic(n,r,a,o,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,null!==this.view&&(e.object.view=Object.assign({},this.view)),e}}const UF=[.125,.215,.35,.446,.526,.582],BF=20,zF=new FF,kF=new TN;let VF=null;const HF=(1+Math.sqrt(5))/2,GF=1/HF,WF=[new iO(1,1,1),new iO(-1,1,1),new iO(1,1,-1),new iO(-1,1,-1),new iO(0,HF,GF),new iO(0,HF,-GF),new iO(GF,0,HF),new iO(-GF,0,HF),new iO(HF,GF,0),new iO(-HF,GF,0)];class XF{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,i=.1,s=100){VF=this._renderer.getRenderTarget(),this._setSize(256);const n=this._allocateTargets();return n.depthBuffer=!0,this._sceneToCubeUV(t,i,s,n),e>0&&this._blur(n,0,0,e),this._applyPMREM(n),this._cleanup(n),n}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=$F(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=jF(),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(VF),t.scissorTest=!1,qF(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===xD||t.mapping===TD?this._setSize(0===t.image.length?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),VF=this._renderer.getRenderTarget();const i=e||this._allocateTargets();return this._textureToCubeUV(t,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,i={magFilter:RD,minFilter:RD,generateMipmaps:!1,type:BD,format:kD,colorSpace:ZD,depthBuffer:!1},s=YF(t,e,i);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=YF(t,e,i);const{_lodMax:s}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas}=function(t){const e=[],i=[],s=[];let n=t;const r=t-4+1+UF.length;for(let a=0;a<r;a++){const r=Math.pow(2,n);i.push(r);let o=1/r;a>t-4?o=UF[a-t+4-1]:0===a&&(o=0),s.push(o);const l=1/(r-2),h=-l,c=1+l,d=[h,h,c,h,c,c,h,h,c,c,h,c],u=6,f=6,p=3,m=2,_=1,g=new Float32Array(p*f*u),v=new Float32Array(m*f*u),S=new Float32Array(_*f*u);for(let t=0;t<u;t++){const e=t%3*2/3-1,i=t>2?0:-1,s=[e,i,0,e+2/3,i,0,e+2/3,i+1,0,e,i,0,e+2/3,i+1,0,e,i+1,0];g.set(s,p*f*t),v.set(d,m*f*t);const n=[t,t,t,t,t,t];S.set(n,_*f*t)}const y=new BN;y.setAttribute("position",new CN(g,p)),y.setAttribute("uv",new CN(v,m)),y.setAttribute("faceIndex",new CN(S,_)),e.push(y),n>4&&n--}return{lodPlanes:e,sizeLods:i,sigmas:s}}(s)),this._blurMaterial=function(t,e,i){const s=new Float32Array(BF),n=new iO(0,1,0),r=new hF({name:"SphericalGaussianBlur",defines:{n:BF,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/i,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:s},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:n}},vertexShader:KF(),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 r}(s,t,e)}return s}_compileMaterial(t){const e=new iF(this._lodPlanes[0],t);this._renderer.compile(e,zF)}_sceneToCubeUV(t,e,i,s){const n=new dF(90,1,e,i),r=[1,-1,1,1,1,1],a=[1,1,1,-1,-1,-1],o=this._renderer,l=o.autoClear,h=o.toneMapping;o.getClearColor(kF),o.toneMapping=0,o.autoClear=!1;const c=new bN({name:"PMREM.Background",side:1,depthWrite:!1,depthTest:!1}),d=new iF(new nF,c);let u=!1;const f=t.background;f?f.isColor&&(c.color.copy(f),t.background=null,u=!0):(c.color.copy(kF),u=!0);for(let e=0;e<6;e++){const i=e%3;0===i?(n.up.set(0,r[e],0),n.lookAt(a[e],0,0)):1===i?(n.up.set(0,0,r[e]),n.lookAt(0,a[e],0)):(n.up.set(0,r[e],0),n.lookAt(0,0,a[e]));const l=this._cubeSize;qF(s,i*l,e>2?l:0,l,l),o.setRenderTarget(s),u&&o.render(d,n),o.render(t,n)}d.geometry.dispose(),d.material.dispose(),o.toneMapping=h,o.autoClear=l,t.background=f}_textureToCubeUV(t,e){const i=this._renderer,s=t.mapping===xD||t.mapping===TD;s?(null===this._cubemapMaterial&&(this._cubemapMaterial=$F()),this._cubemapMaterial.uniforms.flipEnvMap.value=!1===t.isRenderTargetTexture?-1:1):null===this._equirectMaterial&&(this._equirectMaterial=jF());const n=s?this._cubemapMaterial:this._equirectMaterial,r=new iF(this._lodPlanes[0],n);n.uniforms.envMap.value=t;const a=this._cubeSize;qF(e,0,0,3*a,2*a),i.setRenderTarget(e),i.render(r,zF)}_applyPMREM(t){const e=this._renderer,i=e.autoClear;e.autoClear=!1;for(let e=1;e<this._lodPlanes.length;e++){const i=Math.sqrt(this._sigmas[e]*this._sigmas[e]-this._sigmas[e-1]*this._sigmas[e-1]),s=WF[(e-1)%WF.length];this._blur(t,e-1,e,i,s)}e.autoClear=i}_blur(t,e,i,s,n){const r=this._pingPongRenderTarget;this._halfBlur(t,r,e,i,s,"latitudinal",n),this._halfBlur(r,t,i,i,s,"longitudinal",n)}_halfBlur(t,e,i,s,n,r,a){const o=this._renderer,l=this._blurMaterial,h=new iF(this._lodPlanes[s],l),c=l.uniforms,d=this._sizeLods[i]-1,u=isFinite(n)?Math.PI/(2*d):2*Math.PI/39,f=n/u,p=isFinite(n)?1+Math.floor(3*f):BF,m=[];let _=0;for(let t=0;t<BF;++t){const e=t/f,i=Math.exp(-e*e/2);m.push(i),0===t?_+=i:t<p&&(_+=2*i)}for(let t=0;t<m.length;t++)m[t]=m[t]/_;c.envMap.value=t.texture,c.samples.value=p,c.weights.value=m,c.latitudinal.value="latitudinal"===r,a&&(c.poleAxis.value=a);const{_lodMax:g}=this;c.dTheta.value=u,c.mipInt.value=g-i;const v=this._sizeLods[s];qF(e,3*v*(s>g-4?s-g+4:0),4*(this._cubeSize-v),3*v,2*v),o.setRenderTarget(e),o.render(h,zF)}}function YF(t,e,i){const s=new QI(t,e,i);return s.texture.mapping=ED,s.texture.name="PMREM.cubeUv",s.scissorTest=!0,s}function qF(t,e,i,s,n){t.viewport.set(e,i,s,n),t.scissor.set(e,i,s,n)}function jF(){return new hF({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:KF(),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 $F(){return new hF({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:KF(),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 KF(){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 ZF(t){let e=new WeakMap,i=null;function s(t){const i=t.target;i.removeEventListener("dispose",s);const n=e.get(i);void 0!==n&&(e.delete(i),n.dispose())}return{get:function(n){if(n&&n.isTexture){const r=n.mapping,a=303===r||304===r,o=r===xD||r===TD;if(a||o){if(n.isRenderTargetTexture&&!0===n.needsPMREMUpdate){n.needsPMREMUpdate=!1;let s=e.get(n);return null===i&&(i=new XF(t)),s=a?i.fromEquirectangular(n,s):i.fromCubemap(n,s),e.set(n,s),s.texture}if(e.has(n))return e.get(n).texture;{const r=n.image;if(a&&r&&r.height>0||o&&r&&function(t){let e=0;const i=6;for(let s=0;s<i;s++)void 0!==t[s]&&e++;return e===i}(r)){null===i&&(i=new XF(t));const r=a?i.fromEquirectangular(n):i.fromCubemap(n);return e.set(n,r),n.addEventListener("dispose",s),r.texture}return null}}}return n},dispose:function(){e=new WeakMap,null!==i&&(i.dispose(),i=null)}}}function QF(t){const e={};function i(i){if(void 0!==e[i])return e[i];let s;switch(i){case"WEBGL_depth_texture":s=t.getExtension("WEBGL_depth_texture")||t.getExtension("MOZ_WEBGL_depth_texture")||t.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":s=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":s=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":s=t.getExtension("WEBGL_compressed_texture_pvrtc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:s=t.getExtension(i)}return e[i]=s,s}return{has:function(t){return null!==i(t)},init:function(t){t.isWebGL2?i("EXT_color_buffer_float"):(i("WEBGL_depth_texture"),i("OES_texture_float"),i("OES_texture_half_float"),i("OES_texture_half_float_linear"),i("OES_standard_derivatives"),i("OES_element_index_uint"),i("OES_vertex_array_object"),i("ANGLE_instanced_arrays")),i("OES_texture_float_linear"),i("EXT_color_buffer_half_float"),i("WEBGL_multisampled_render_to_texture")},get:function(t){const e=i(t);return e}}}function JF(t,e,i,s){const n={},r=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 i=o.morphAttributes[t];for(let t=0,s=i.length;t<s;t++)e.remove(i[t])}o.removeEventListener("dispose",a),delete n[o.id];const l=r.get(o);l&&(e.remove(l),r.delete(o)),s.releaseStatesOfGeometry(o),!0===o.isInstancedBufferGeometry&&delete o._maxInstanceCount,i.memory.geometries--}function o(t){const i=[],s=t.index,n=t.attributes.position;let a=0;if(null!==s){const t=s.array;a=s.version;for(let e=0,s=t.length;e<s;e+=3){const s=t[e+0],n=t[e+1],r=t[e+2];i.push(s,n,n,r,r,s)}}else{if(void 0===n)return;{const t=n.array;a=n.version;for(let e=0,s=t.length/3-1;e<s;e+=3){const t=e+0,s=e+1,n=e+2;i.push(t,s,s,n,n,t)}}}const o=new(LI(i)?PN:MN)(i,1);o.version=a;const l=r.get(t);l&&e.remove(l),r.set(t,o)}return{get:function(t,e){return!0===n[e.id]||(e.addEventListener("dispose",a),n[e.id]=!0,i.memory.geometries++),e},update:function(i){const s=i.attributes;for(const i in s)e.update(s[i],t.ARRAY_BUFFER);const n=i.morphAttributes;for(const i in n){const s=n[i];for(let i=0,n=s.length;i<n;i++)e.update(s[i],t.ARRAY_BUFFER)}},getWireframeAttribute:function(t){const e=r.get(t);if(e){const i=t.index;null!==i&&e.version<i.version&&o(t)}else o(t);return r.get(t)}}}function tU(t,e,i,s){const n=s.isWebGL2;let r,a,o;this.setMode=function(t){r=t},this.setIndex=function(t){a=t.type,o=t.bytesPerElement},this.render=function(e,s){t.drawElements(r,s,a,e*o),i.update(s,r,1)},this.renderInstances=function(s,l,h){if(0===h)return;let c,d;if(n)c=t,d="drawElementsInstanced";else if(c=e.get("ANGLE_instanced_arrays"),d="drawElementsInstancedANGLE",null===c)return;c[d](r,l,a,s*o,h),i.update(l,r,h)}}function eU(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(i,s,n){switch(e.calls++,s){case t.TRIANGLES:e.triangles+=n*(i/3);break;case t.LINES:e.lines+=n*(i/2);break;case t.LINE_STRIP:e.lines+=n*(i-1);break;case t.LINE_LOOP:e.lines+=n*i;break;case t.POINTS:e.points+=n*i}}}}function iU(t,e){return t[0]-e[0]}function sU(t,e){return Math.abs(e[1])-Math.abs(t[1])}function nU(t,e,i){const s={},n=new Float32Array(8),r=new WeakMap,a=new KI,o=[];for(let t=0;t<8;t++)o[t]=[t,0];return{update:function(l,h,c){const d=l.morphTargetInfluences;if(!0===e.isWebGL2){const u=h.morphAttributes.position||h.morphAttributes.normal||h.morphAttributes.color,f=void 0!==u?u.length:0;let p=r.get(h);if(void 0===p||p.count!==f){void 0!==p&&p.texture.dispose();const g=void 0!==h.morphAttributes.position,v=void 0!==h.morphAttributes.normal,S=void 0!==h.morphAttributes.color,y=h.morphAttributes.position||[],x=h.morphAttributes.normal||[],T=h.morphAttributes.color||[];let E=0;!0===g&&(E=1),!0===v&&(E=2),!0===S&&(E=3);let b=h.attributes.position.count*E,w=1;b>e.maxTextureSize&&(w=Math.ceil(b/e.maxTextureSize),b=e.maxTextureSize);const A=new Float32Array(b*w*4*f),C=new JI(A,b,w,f);C.type=UD,C.needsUpdate=!0;const M=4*E;for(let R=0;R<f;R++){const L=y[R],D=x[R],I=T[R],O=b*w*4*R;for(let N=0;N<L.count;N++){const F=N*M;!0===g&&(a.fromBufferAttribute(L,N),A[O+F+0]=a.x,A[O+F+1]=a.y,A[O+F+2]=a.z,A[O+F+3]=0),!0===v&&(a.fromBufferAttribute(D,N),A[O+F+4]=a.x,A[O+F+5]=a.y,A[O+F+6]=a.z,A[O+F+7]=0),!0===S&&(a.fromBufferAttribute(I,N),A[O+F+8]=a.x,A[O+F+9]=a.y,A[O+F+10]=a.z,A[O+F+11]=4===I.itemSize?a.w:1)}}function P(){C.dispose(),r.delete(h),h.removeEventListener("dispose",P)}p={count:f,texture:C,size:new MI(b,w)},r.set(h,p),h.addEventListener("dispose",P)}let m=0;for(let U=0;U<d.length;U++)m+=d[U];const _=h.morphTargetsRelative?1:1-m;c.getUniforms().setValue(t,"morphTargetBaseInfluence",_),c.getUniforms().setValue(t,"morphTargetInfluences",d),c.getUniforms().setValue(t,"morphTargetsTexture",p.texture,i),c.getUniforms().setValue(t,"morphTargetsTextureSize",p.size)}else{const B=void 0===d?0:d.length;let z=s[h.id];if(void 0===z||z.length!==B){z=[];for(let W=0;W<B;W++)z[W]=[W,0];s[h.id]=z}for(let X=0;X<B;X++){const Y=z[X];Y[0]=X,Y[1]=d[X]}z.sort(sU);for(let q=0;q<8;q++)q<B&&z[q][1]?(o[q][0]=z[q][0],o[q][1]=z[q][1]):(o[q][0]=Number.MAX_SAFE_INTEGER,o[q][1]=0);o.sort(iU);const k=h.morphAttributes.position,V=h.morphAttributes.normal;let H=0;for(let j=0;j<8;j++){const $=o[j],K=$[0],Z=$[1];K!==Number.MAX_SAFE_INTEGER&&Z?(k&&h.getAttribute("morphTarget"+j)!==k[K]&&h.setAttribute("morphTarget"+j,k[K]),V&&h.getAttribute("morphNormal"+j)!==V[K]&&h.setAttribute("morphNormal"+j,V[K]),n[j]=Z,H+=Z):(k&&!0===h.hasAttribute("morphTarget"+j)&&h.deleteAttribute("morphTarget"+j),V&&!0===h.hasAttribute("morphNormal"+j)&&h.deleteAttribute("morphNormal"+j),n[j]=0)}const G=h.morphTargetsRelative?1:1-H;c.getUniforms().setValue(t,"morphTargetBaseInfluence",G),c.getUniforms().setValue(t,"morphTargetInfluences",n)}}}}function rU(t,e,i,s){let n=new WeakMap;function r(t){const e=t.target;e.removeEventListener("dispose",r),i.remove(e.instanceMatrix),null!==e.instanceColor&&i.remove(e.instanceColor)}return{update:function(a){const o=s.render.frame,l=a.geometry,h=e.get(a,l);if(n.get(h)!==o&&(e.update(h),n.set(h,o)),a.isInstancedMesh&&(!1===a.hasEventListener("dispose",r)&&a.addEventListener("dispose",r),n.get(a)!==o&&(i.update(a.instanceMatrix,t.ARRAY_BUFFER),null!==a.instanceColor&&i.update(a.instanceColor,t.ARRAY_BUFFER),n.set(a,o))),a.isSkinnedMesh){const t=a.skeleton;n.get(t)!==o&&(t.update(),n.set(t,o))}return h},dispose:function(){n=new WeakMap}}}const aU=new $I,oU=new JI,lU=new tO,hU=new pF,cU=[],dU=[],uU=new Float32Array(16),fU=new Float32Array(9),pU=new Float32Array(4);function mU(t,e,i){const s=t[0];if(s<=0||s>0)return t;const n=e*i;let r=cU[n];if(void 0===r&&(r=new Float32Array(n),cU[n]=r),0!==e){s.toArray(r,0);for(let s=1,n=0;s!==e;++s)n+=i,t[s].toArray(r,n)}return r}function _U(t,e){if(t.length!==e.length)return!1;for(let i=0,s=t.length;i<s;i++)if(t[i]!==e[i])return!1;return!0}function gU(t,e){for(let i=0,s=e.length;i<s;i++)t[i]=e[i]}function vU(t,e){let i=dU[e];void 0===i&&(i=new Int32Array(e),dU[e]=i);for(let s=0;s!==e;++s)i[s]=t.allocateTextureUnit();return i}function SU(t,e){const i=this.cache;i[0]!==e&&(t.uniform1f(this.addr,e),i[0]=e)}function yU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2f(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(_U(i,e))return;t.uniform2fv(this.addr,e),gU(i,e)}}function xU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3f(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else if(void 0!==e.r)i[0]===e.r&&i[1]===e.g&&i[2]===e.b||(t.uniform3f(this.addr,e.r,e.g,e.b),i[0]=e.r,i[1]=e.g,i[2]=e.b);else{if(_U(i,e))return;t.uniform3fv(this.addr,e),gU(i,e)}}function TU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4f(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(_U(i,e))return;t.uniform4fv(this.addr,e),gU(i,e)}}function EU(t,e){const i=this.cache,s=e.elements;if(void 0===s){if(_U(i,e))return;t.uniformMatrix2fv(this.addr,!1,e),gU(i,e)}else{if(_U(i,s))return;pU.set(s),t.uniformMatrix2fv(this.addr,!1,pU),gU(i,s)}}function bU(t,e){const i=this.cache,s=e.elements;if(void 0===s){if(_U(i,e))return;t.uniformMatrix3fv(this.addr,!1,e),gU(i,e)}else{if(_U(i,s))return;fU.set(s),t.uniformMatrix3fv(this.addr,!1,fU),gU(i,s)}}function wU(t,e){const i=this.cache,s=e.elements;if(void 0===s){if(_U(i,e))return;t.uniformMatrix4fv(this.addr,!1,e),gU(i,e)}else{if(_U(i,s))return;uU.set(s),t.uniformMatrix4fv(this.addr,!1,uU),gU(i,s)}}function AU(t,e){const i=this.cache;i[0]!==e&&(t.uniform1i(this.addr,e),i[0]=e)}function CU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2i(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(_U(i,e))return;t.uniform2iv(this.addr,e),gU(i,e)}}function MU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3i(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else{if(_U(i,e))return;t.uniform3iv(this.addr,e),gU(i,e)}}function PU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4i(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(_U(i,e))return;t.uniform4iv(this.addr,e),gU(i,e)}}function RU(t,e){const i=this.cache;i[0]!==e&&(t.uniform1ui(this.addr,e),i[0]=e)}function LU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2ui(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(_U(i,e))return;t.uniform2uiv(this.addr,e),gU(i,e)}}function DU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3ui(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else{if(_U(i,e))return;t.uniform3uiv(this.addr,e),gU(i,e)}}function IU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4ui(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(_U(i,e))return;t.uniform4uiv(this.addr,e),gU(i,e)}}function OU(t,e,i){const s=this.cache,n=i.allocateTextureUnit();s[0]!==n&&(t.uniform1i(this.addr,n),s[0]=n),i.setTexture2D(e||aU,n)}function NU(t,e,i){const s=this.cache,n=i.allocateTextureUnit();s[0]!==n&&(t.uniform1i(this.addr,n),s[0]=n),i.setTexture3D(e||lU,n)}function FU(t,e,i){const s=this.cache,n=i.allocateTextureUnit();s[0]!==n&&(t.uniform1i(this.addr,n),s[0]=n),i.setTextureCube(e||hU,n)}function UU(t,e,i){const s=this.cache,n=i.allocateTextureUnit();s[0]!==n&&(t.uniform1i(this.addr,n),s[0]=n),i.setTexture2DArray(e||oU,n)}function BU(t,e){t.uniform1fv(this.addr,e)}function zU(t,e){const i=mU(e,this.size,2);t.uniform2fv(this.addr,i)}function kU(t,e){const i=mU(e,this.size,3);t.uniform3fv(this.addr,i)}function VU(t,e){const i=mU(e,this.size,4);t.uniform4fv(this.addr,i)}function HU(t,e){const i=mU(e,this.size,4);t.uniformMatrix2fv(this.addr,!1,i)}function GU(t,e){const i=mU(e,this.size,9);t.uniformMatrix3fv(this.addr,!1,i)}function WU(t,e){const i=mU(e,this.size,16);t.uniformMatrix4fv(this.addr,!1,i)}function XU(t,e){t.uniform1iv(this.addr,e)}function YU(t,e){t.uniform2iv(this.addr,e)}function qU(t,e){t.uniform3iv(this.addr,e)}function jU(t,e){t.uniform4iv(this.addr,e)}function $U(t,e){t.uniform1uiv(this.addr,e)}function KU(t,e){t.uniform2uiv(this.addr,e)}function ZU(t,e){t.uniform3uiv(this.addr,e)}function QU(t,e){t.uniform4uiv(this.addr,e)}function JU(t,e,i){const s=this.cache,n=e.length,r=vU(i,n);_U(s,r)||(t.uniform1iv(this.addr,r),gU(s,r));for(let t=0;t!==n;++t)i.setTexture2D(e[t]||aU,r[t])}function tB(t,e,i){const s=this.cache,n=e.length,r=vU(i,n);_U(s,r)||(t.uniform1iv(this.addr,r),gU(s,r));for(let t=0;t!==n;++t)i.setTexture3D(e[t]||lU,r[t])}function eB(t,e,i){const s=this.cache,n=e.length,r=vU(i,n);_U(s,r)||(t.uniform1iv(this.addr,r),gU(s,r));for(let t=0;t!==n;++t)i.setTextureCube(e[t]||hU,r[t])}function iB(t,e,i){const s=this.cache,n=e.length,r=vU(i,n);_U(s,r)||(t.uniform1iv(this.addr,r),gU(s,r));for(let t=0;t!==n;++t)i.setTexture2DArray(e[t]||oU,r[t])}class sB{constructor(t,e,i){this.id=t,this.addr=i,this.cache=[],this.setValue=function(t){switch(t){case 5126:return SU;case 35664:return yU;case 35665:return xU;case 35666:return TU;case 35674:return EU;case 35675:return bU;case 35676:return wU;case 5124:case 35670:return AU;case 35667:case 35671:return CU;case 35668:case 35672:return MU;case 35669:case 35673:return PU;case 5125:return RU;case 36294:return LU;case 36295:return DU;case 36296:return IU;case 35678:case 36198:case 36298:case 36306:case 35682:return OU;case 35679:case 36299:case 36307:return NU;case 35680:case 36300:case 36308:case 36293:return FU;case 36289:case 36303:case 36311:case 36292:return UU}}(e.type)}}class nB{constructor(t,e,i){this.id=t,this.addr=i,this.cache=[],this.size=e.size,this.setValue=function(t){switch(t){case 5126:return BU;case 35664:return zU;case 35665:return kU;case 35666:return VU;case 35674:return HU;case 35675:return GU;case 35676:return WU;case 5124:case 35670:return XU;case 35667:case 35671:return YU;case 35668:case 35672:return qU;case 35669:case 35673:return jU;case 5125:return $U;case 36294:return KU;case 36295:return ZU;case 36296:return QU;case 35678:case 36198:case 36298:case 36306:case 35682:return JU;case 35679:case 36299:case 36307:return tB;case 35680:case 36300:case 36308:case 36293:return eB;case 36289:case 36303:case 36311:case 36292:return iB}}(e.type)}}class rB{constructor(t){this.id=t,this.seq=[],this.map={}}setValue(t,e,i){const s=this.seq;for(let n=0,r=s.length;n!==r;++n){const r=s[n];r.setValue(t,e[r.id],i)}}}const aB=/(\w+)(\])?(\[|\.)?/g;function oB(t,e){t.seq.push(e),t.map[e.id]=e}function lB(t,e,i){const s=t.name,n=s.length;for(aB.lastIndex=0;;){const r=aB.exec(s),a=aB.lastIndex;let o=r[1];const l="]"===r[2],h=r[3];if(l&&(o|=0),void 0===h||"["===h&&a+2===n){oB(i,void 0===h?new sB(o,t,e):new nB(o,t,e));break}{let t=i.map[o];void 0===t&&(t=new rB(o),oB(i,t)),i=t}}}class hB{constructor(t,e){this.seq=[],this.map={};const i=t.getProgramParameter(e,t.ACTIVE_UNIFORMS);for(let s=0;s<i;++s){const i=t.getActiveUniform(e,s);lB(i,t.getUniformLocation(e,i.name),this)}}setValue(t,e,i,s){const n=this.map[e];void 0!==n&&n.setValue(t,i,s)}setOptional(t,e,i){const s=e[i];void 0!==s&&this.setValue(t,i,s)}static upload(t,e,i,s){for(let n=0,r=e.length;n!==r;++n){const r=e[n],a=i[r.id];!1!==a.needsUpdate&&r.setValue(t,a.value,s)}}static seqWithValue(t,e){const i=[];for(let s=0,n=t.length;s!==n;++s){const n=t[s];n.id in e&&i.push(n)}return i}}function cB(t,e,i){const s=t.createShader(e);return t.shaderSource(s,i),t.compileShader(s),s}let dB=0;function uB(t,e,i){const s=t.getShaderParameter(e,t.COMPILE_STATUS),n=t.getShaderInfoLog(e).trim();if(s&&""===n)return"";const r=/ERROR: 0:(\d+)/.exec(n);if(r){const s=parseInt(r[1]);return i.toUpperCase()+"\n\n"+n+"\n\n"+function(t,e){const i=t.split("\n"),s=[],n=Math.max(e-6,0),r=Math.min(e+6,i.length);for(let t=n;t<r;t++){const n=t+1;s.push(`${n===e?">":" "} ${n}: ${i[t]}`)}return s.join("\n")}(t.getShaderSource(e),s)}return n}function fB(t,e){const i=function(t){const e=kI.getPrimaries(kI.workingColorSpace),i=kI.getPrimaries(t);let s;switch(e===i?s="":e===sI&&i===iI?s="LinearDisplayP3ToLinearSRGB":e===iI&&i===sI&&(s="LinearSRGBToLinearDisplayP3"),t){case ZD:case JD:return[s,"LinearTransferOETF"];case KD:case QD:return[s,"sRGBTransferOETF"];default:return[s,"LinearTransferOETF"]}}(e);return`vec4 ${t}( vec4 value ) { return ${i[0]}( ${i[1]}( value ) ); }`}function pB(t,e){let i;switch(e){case 1:default:i="Linear";break;case 2:i="Reinhard";break;case 3:i="OptimizedCineon";break;case 4:i="ACESFilmic";break;case 5:i="Custom"}return"vec3 "+t+"( vec3 color ) { return "+i+"ToneMapping( color ); }"}function mB(t){return""!==t}function _B(t,e){const i=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,i).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 gB(t,e){return t.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const vB=/^[ \t]*#include +<([\w\d./]+)>/gm;function SB(t){return t.replace(vB,xB)}const yB=new Map([["encodings_fragment","colorspace_fragment"],["encodings_pars_fragment","colorspace_pars_fragment"],["output_fragment","opaque_fragment"]]);function xB(t,e){let i=AF[e];if(void 0===i){const t=yB.get(e);if(void 0===t)throw new Error("Can not resolve #include <"+e+">");i=AF[t]}return SB(i)}const TB=/#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 EB(t){return t.replace(TB,bB)}function bB(t,e,i,s){let n="";for(let t=parseInt(e);t<parseInt(i);t++)n+=s.replace(/\[\s*i\s*\]/g,"[ "+t+" ]").replace(/UNROLLED_LOOP_INDEX/g,t);return n}function wB(t){let e="precision "+t.precision+" float;\nprecision "+t.precision+" int;";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 AB(t,e,i,s){const n=t.getContext(),r=i.defines;let a=i.vertexShader,o=i.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}(i),h=function(t){let e="ENVMAP_TYPE_CUBE";if(t.envMap)switch(t.envMapMode){case xD:case TD:e="ENVMAP_TYPE_CUBE";break;case ED:e="ENVMAP_TYPE_CUBE_UV"}return e}(i),c=function(t){let e="ENVMAP_MODE_REFLECTION";t.envMap&&t.envMapMode===TD&&(e="ENVMAP_MODE_REFRACTION");return e}(i),d=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}(i),u=function(t){const e=t.envMapCubeUVHeight;if(null===e)return null;const i=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,i),112)),texelHeight:s,maxMip:i}}(i),f=i.isWebGL2?"":function(t){return[t.extensionDerivatives||t.envMapCubeUVHeight||t.bumpMap||t.normalMapTangentSpace||t.clearcoatNormalMap||t.flatShading||"physical"===t.shaderID?"#extension GL_OES_standard_derivatives : enable":"",(t.extensionFragDepth||t.logarithmicDepthBuffer)&&t.rendererExtensionFragDepth?"#extension GL_EXT_frag_depth : enable":"",t.extensionDrawBuffers&&t.rendererExtensionDrawBuffers?"#extension GL_EXT_draw_buffers : require":"",(t.extensionShaderTextureLOD||t.envMap||t.transmission)&&t.rendererExtensionShaderTextureLod?"#extension GL_EXT_shader_texture_lod : enable":""].filter(mB).join("\n")}(i),p=function(t){const e=[];for(const i in t){const s=t[i];!1!==s&&e.push("#define "+i+" "+s)}return e.join("\n")}(r),m=n.createProgram();let _,g,v=i.glslVersion?"#version "+i.glslVersion+"\n":"";i.isRawShaderMaterial?(_=["#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,p].filter(mB).join("\n"),_.length>0&&(_+="\n"),g=[f,"#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,p].filter(mB).join("\n"),g.length>0&&(g+="\n")):(_=[wB(i),"#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,p,i.instancing?"#define USE_INSTANCING":"",i.instancingColor?"#define USE_INSTANCING_COLOR":"",i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+c:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",i.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",i.displacementMap?"#define USE_DISPLACEMENTMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.anisotropy?"#define USE_ANISOTROPY":"",i.anisotropyMap?"#define USE_ANISOTROPYMAP":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",i.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",i.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.alphaHash?"#define USE_ALPHAHASH":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",i.mapUv?"#define MAP_UV "+i.mapUv:"",i.alphaMapUv?"#define ALPHAMAP_UV "+i.alphaMapUv:"",i.lightMapUv?"#define LIGHTMAP_UV "+i.lightMapUv:"",i.aoMapUv?"#define AOMAP_UV "+i.aoMapUv:"",i.emissiveMapUv?"#define EMISSIVEMAP_UV "+i.emissiveMapUv:"",i.bumpMapUv?"#define BUMPMAP_UV "+i.bumpMapUv:"",i.normalMapUv?"#define NORMALMAP_UV "+i.normalMapUv:"",i.displacementMapUv?"#define DISPLACEMENTMAP_UV "+i.displacementMapUv:"",i.metalnessMapUv?"#define METALNESSMAP_UV "+i.metalnessMapUv:"",i.roughnessMapUv?"#define ROUGHNESSMAP_UV "+i.roughnessMapUv:"",i.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+i.anisotropyMapUv:"",i.clearcoatMapUv?"#define CLEARCOATMAP_UV "+i.clearcoatMapUv:"",i.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+i.clearcoatNormalMapUv:"",i.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+i.clearcoatRoughnessMapUv:"",i.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+i.iridescenceMapUv:"",i.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+i.iridescenceThicknessMapUv:"",i.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+i.sheenColorMapUv:"",i.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+i.sheenRoughnessMapUv:"",i.specularMapUv?"#define SPECULARMAP_UV "+i.specularMapUv:"",i.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+i.specularColorMapUv:"",i.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+i.specularIntensityMapUv:"",i.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+i.transmissionMapUv:"",i.thicknessMapUv?"#define THICKNESSMAP_UV "+i.thicknessMapUv:"",i.vertexTangents&&!1===i.flatShading?"#define USE_TANGENT":"",i.vertexColors?"#define USE_COLOR":"",i.vertexAlphas?"#define USE_COLOR_ALPHA":"",i.vertexUv1s?"#define USE_UV1":"",i.vertexUv2s?"#define USE_UV2":"",i.vertexUv3s?"#define USE_UV3":"",i.pointsUvs?"#define USE_POINTS_UV":"",i.flatShading?"#define FLAT_SHADED":"",i.skinning?"#define USE_SKINNING":"",i.morphTargets?"#define USE_MORPHTARGETS":"",i.morphNormals&&!1===i.flatShading?"#define USE_MORPHNORMALS":"",i.morphColors&&i.isWebGL2?"#define USE_MORPHCOLORS":"",i.morphTargetsCount>0&&i.isWebGL2?"#define MORPHTARGETS_TEXTURE":"",i.morphTargetsCount>0&&i.isWebGL2?"#define MORPHTARGETS_TEXTURE_STRIDE "+i.morphTextureStride:"",i.morphTargetsCount>0&&i.isWebGL2?"#define MORPHTARGETS_COUNT "+i.morphTargetsCount:"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.sizeAttenuation?"#define USE_SIZEATTENUATION":"",i.numLightProbes>0?"#define USE_LIGHT_PROBES":"",i.useLegacyLights?"#define LEGACY_LIGHTS":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&i.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","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","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","#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )","\tattribute vec3 morphTarget0;","\tattribute vec3 morphTarget1;","\tattribute vec3 morphTarget2;","\tattribute vec3 morphTarget3;","\t#ifdef USE_MORPHNORMALS","\t\tattribute vec3 morphNormal0;","\t\tattribute vec3 morphNormal1;","\t\tattribute vec3 morphNormal2;","\t\tattribute vec3 morphNormal3;","\t#else","\t\tattribute vec3 morphTarget4;","\t\tattribute vec3 morphTarget5;","\t\tattribute vec3 morphTarget6;","\t\tattribute vec3 morphTarget7;","\t#endif","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(mB).join("\n"),g=[f,wB(i),"#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,p,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.matcap?"#define USE_MATCAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+h:"",i.envMap?"#define "+c:"",i.envMap?"#define "+d:"",u?"#define CUBEUV_TEXEL_WIDTH "+u.texelWidth:"",u?"#define CUBEUV_TEXEL_HEIGHT "+u.texelHeight:"",u?"#define CUBEUV_MAX_MIP "+u.maxMip+".0":"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",i.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.anisotropy?"#define USE_ANISOTROPY":"",i.anisotropyMap?"#define USE_ANISOTROPYMAP":"",i.clearcoat?"#define USE_CLEARCOAT":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.iridescence?"#define USE_IRIDESCENCE":"",i.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",i.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",i.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.alphaTest?"#define USE_ALPHATEST":"",i.alphaHash?"#define USE_ALPHAHASH":"",i.sheen?"#define USE_SHEEN":"",i.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.vertexTangents&&!1===i.flatShading?"#define USE_TANGENT":"",i.vertexColors||i.instancingColor?"#define USE_COLOR":"",i.vertexAlphas?"#define USE_COLOR_ALPHA":"",i.vertexUv1s?"#define USE_UV1":"",i.vertexUv2s?"#define USE_UV2":"",i.vertexUv3s?"#define USE_UV3":"",i.pointsUvs?"#define USE_POINTS_UV":"",i.gradientMap?"#define USE_GRADIENTMAP":"",i.flatShading?"#define FLAT_SHADED":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",i.numLightProbes>0?"#define USE_LIGHT_PROBES":"",i.useLegacyLights?"#define LEGACY_LIGHTS":"",i.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&i.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",0!==i.toneMapping?"#define TONE_MAPPING":"",0!==i.toneMapping?AF.tonemapping_pars_fragment:"",0!==i.toneMapping?pB("toneMapping",i.toneMapping):"",i.dithering?"#define DITHERING":"",i.opaque?"#define OPAQUE":"",AF.colorspace_pars_fragment,fB("linearToOutputTexel",i.outputColorSpace),i.useDepthPacking?"#define DEPTH_PACKING "+i.depthPacking:"","\n"].filter(mB).join("\n")),a=SB(a),a=_B(a,i),a=gB(a,i),o=SB(o),o=_B(o,i),o=gB(o,i),a=EB(a),o=EB(o),i.isWebGL2&&!0!==i.isRawShaderMaterial&&(v="#version 300 es\n",_=["precision mediump sampler2DArray;","#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+_,g=["#define varying in",i.glslVersion===fI?"":"layout(location = 0) out highp vec4 pc_fragColor;",i.glslVersion===fI?"":"#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"+g);const S=v+_+a,y=v+g+o,x=cB(n,n.VERTEX_SHADER,S),T=cB(n,n.FRAGMENT_SHADER,y);if(n.attachShader(m,x),n.attachShader(m,T),void 0!==i.index0AttributeName?n.bindAttribLocation(m,0,i.index0AttributeName):!0===i.morphTargets&&n.bindAttribLocation(m,0,"position"),n.linkProgram(m),t.debug.checkShaderErrors){const e=n.getProgramInfoLog(m).trim(),i=n.getShaderInfoLog(x).trim(),s=n.getShaderInfoLog(T).trim();let r=!0,a=!0;if(!1===n.getProgramParameter(m,n.LINK_STATUS))if(r=!1,"function"==typeof t.debug.onShaderError)t.debug.onShaderError(n,m,x,T);else{uB(n,x,"vertex"),uB(n,T,"fragment")}else""!==e||""!==i&&""!==s||(a=!1);a&&(this.diagnostics={runnable:r,programLog:e,vertexShader:{log:i,prefix:_},fragmentShader:{log:s,prefix:g}})}let E,b;return n.deleteShader(x),n.deleteShader(T),this.getUniforms=function(){return void 0===E&&(E=new hB(n,m)),E},this.getAttributes=function(){return void 0===b&&(b=function(t,e){const i={},s=t.getProgramParameter(e,t.ACTIVE_ATTRIBUTES);for(let n=0;n<s;n++){const s=t.getActiveAttrib(e,n),r=s.name;let a=1;s.type===t.FLOAT_MAT2&&(a=2),s.type===t.FLOAT_MAT3&&(a=3),s.type===t.FLOAT_MAT4&&(a=4),i[r]={type:s.type,location:t.getAttribLocation(e,r),locationSize:a}}return i}(n,m)),b},this.destroy=function(){s.releaseStatesOfProgram(this),n.deleteProgram(m),this.program=void 0},this.type=i.shaderType,this.name=i.shaderName,this.id=dB++,this.cacheKey=e,this.usedTimes=1,this.program=m,this.vertexShader=x,this.fragmentShader=T,this}let CB=0;class MB{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,i=t.fragmentShader,s=this._getShaderStage(e),n=this._getShaderStage(i),r=this._getShaderCacheForMaterial(t);return!1===r.has(s)&&(r.add(s),s.usedTimes++),!1===r.has(n)&&(r.add(n),n.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 i=e.get(t);return void 0===i&&(i=new Set,e.set(t,i)),i}_getShaderStage(t){const e=this.shaderCache;let i=e.get(t);return void 0===i&&(i=new PB(t),e.set(t,i)),i}}class PB{constructor(t){this.id=CB++,this.code=t,this.usedTimes=0}}function RB(t,e,i,s,n,r,a){const o=new GO,l=new MB,h=[],c=n.isWebGL2,d=n.logarithmicDepthBuffer,u=n.vertexTextures;let f=n.precision;const p={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 0===t?"uv":`uv${t}`}return{getParameters:function(r,o,h,_,g){const v=_.fog,S=g.geometry,y=r.isMeshStandardMaterial?_.environment:null,x=(r.isMeshStandardMaterial?i:e).get(r.envMap||y),T=x&&x.mapping===ED?x.image.height:null,E=p[r.type];null!==r.precision&&(f=n.getMaxPrecision(r.precision),r.precision);const b=S.morphAttributes.position||S.morphAttributes.normal||S.morphAttributes.color,w=void 0!==b?b.length:0;let A,C,M,P,R=0;if(void 0!==S.morphAttributes.position&&(R=1),void 0!==S.morphAttributes.normal&&(R=2),void 0!==S.morphAttributes.color&&(R=3),E){const t=MF[E];A=t.vertexShader,C=t.fragmentShader}else A=r.vertexShader,C=r.fragmentShader,l.update(r),M=l.getVertexShaderID(r),P=l.getFragmentShaderID(r);const L=t.getRenderTarget(),D=!0===g.isInstancedMesh,I=!!r.map,O=!!r.matcap,N=!!x,F=!!r.aoMap,U=!!r.lightMap,B=!!r.bumpMap,z=!!r.normalMap,k=!!r.displacementMap,V=!!r.emissiveMap,H=!!r.metalnessMap,G=!!r.roughnessMap,W=r.anisotropy>0,X=r.clearcoat>0,Y=r.iridescence>0,q=r.sheen>0,j=r.transmission>0,$=W&&!!r.anisotropyMap,K=X&&!!r.clearcoatMap,Z=X&&!!r.clearcoatNormalMap,Q=X&&!!r.clearcoatRoughnessMap,J=Y&&!!r.iridescenceMap,tt=Y&&!!r.iridescenceThicknessMap,et=q&&!!r.sheenColorMap,it=q&&!!r.sheenRoughnessMap,st=!!r.specularMap,nt=!!r.specularColorMap,rt=!!r.specularIntensityMap,at=j&&!!r.transmissionMap,ot=j&&!!r.thicknessMap,lt=!!r.gradientMap,ht=!!r.alphaMap,ct=r.alphaTest>0,dt=!!r.alphaHash,ut=!!r.extensions,ft=!!S.attributes.uv1,pt=!!S.attributes.uv2,mt=!!S.attributes.uv3;let _t=0;return r.toneMapped&&(null!==L&&!0!==L.isXRRenderTarget||(_t=t.toneMapping)),{isWebGL2:c,shaderID:E,shaderType:r.type,shaderName:r.name,vertexShader:A,fragmentShader:C,defines:r.defines,customVertexShaderID:M,customFragmentShaderID:P,isRawShaderMaterial:!0===r.isRawShaderMaterial,glslVersion:r.glslVersion,precision:f,instancing:D,instancingColor:D&&null!==g.instanceColor,supportsVertexTextures:u,outputColorSpace:null===L?t.outputColorSpace:!0===L.isXRRenderTarget?L.texture.colorSpace:ZD,map:I,matcap:O,envMap:N,envMapMode:N&&x.mapping,envMapCubeUVHeight:T,aoMap:F,lightMap:U,bumpMap:B,normalMap:z,displacementMap:u&&k,emissiveMap:V,normalMapObjectSpace:z&&1===r.normalMapType,normalMapTangentSpace:z&&0===r.normalMapType,metalnessMap:H,roughnessMap:G,anisotropy:W,anisotropyMap:$,clearcoat:X,clearcoatMap:K,clearcoatNormalMap:Z,clearcoatRoughnessMap:Q,iridescence:Y,iridescenceMap:J,iridescenceThicknessMap:tt,sheen:q,sheenColorMap:et,sheenRoughnessMap:it,specularMap:st,specularColorMap:nt,specularIntensityMap:rt,transmission:j,transmissionMap:at,thicknessMap:ot,gradientMap:lt,opaque:!1===r.transparent&&1===r.blending,alphaMap:ht,alphaTest:ct,alphaHash:dt,combine:r.combine,mapUv:I&&m(r.map.channel),aoMapUv:F&&m(r.aoMap.channel),lightMapUv:U&&m(r.lightMap.channel),bumpMapUv:B&&m(r.bumpMap.channel),normalMapUv:z&&m(r.normalMap.channel),displacementMapUv:k&&m(r.displacementMap.channel),emissiveMapUv:V&&m(r.emissiveMap.channel),metalnessMapUv:H&&m(r.metalnessMap.channel),roughnessMapUv:G&&m(r.roughnessMap.channel),anisotropyMapUv:$&&m(r.anisotropyMap.channel),clearcoatMapUv:K&&m(r.clearcoatMap.channel),clearcoatNormalMapUv:Z&&m(r.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:Q&&m(r.clearcoatRoughnessMap.channel),iridescenceMapUv:J&&m(r.iridescenceMap.channel),iridescenceThicknessMapUv:tt&&m(r.iridescenceThicknessMap.channel),sheenColorMapUv:et&&m(r.sheenColorMap.channel),sheenRoughnessMapUv:it&&m(r.sheenRoughnessMap.channel),specularMapUv:st&&m(r.specularMap.channel),specularColorMapUv:nt&&m(r.specularColorMap.channel),specularIntensityMapUv:rt&&m(r.specularIntensityMap.channel),transmissionMapUv:at&&m(r.transmissionMap.channel),thicknessMapUv:ot&&m(r.thicknessMap.channel),alphaMapUv:ht&&m(r.alphaMap.channel),vertexTangents:!!S.attributes.tangent&&(z||W),vertexColors:r.vertexColors,vertexAlphas:!0===r.vertexColors&&!!S.attributes.color&&4===S.attributes.color.itemSize,vertexUv1s:ft,vertexUv2s:pt,vertexUv3s:mt,pointsUvs:!0===g.isPoints&&!!S.attributes.uv&&(I||ht),fog:!!v,useFog:!0===r.fog,fogExp2:v&&v.isFogExp2,flatShading:!0===r.flatShading,sizeAttenuation:!0===r.sizeAttenuation,logarithmicDepthBuffer:d,skinning:!0===g.isSkinnedMesh,morphTargets:void 0!==S.morphAttributes.position,morphNormals:void 0!==S.morphAttributes.normal,morphColors:void 0!==S.morphAttributes.color,morphTargetsCount:w,morphTextureStride:R,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:r.dithering,shadowMapEnabled:t.shadowMap.enabled&&h.length>0,shadowMapType:t.shadowMap.type,toneMapping:_t,useLegacyLights:t._useLegacyLights,decodeVideoTexture:I&&!0===r.map.isVideoTexture&&kI.getTransfer(r.map.colorSpace)===eI,premultipliedAlpha:r.premultipliedAlpha,doubleSided:2===r.side,flipSided:1===r.side,useDepthPacking:r.depthPacking>=0,depthPacking:r.depthPacking||0,index0AttributeName:r.index0AttributeName,extensionDerivatives:ut&&!0===r.extensions.derivatives,extensionFragDepth:ut&&!0===r.extensions.fragDepth,extensionDrawBuffers:ut&&!0===r.extensions.drawBuffers,extensionShaderTextureLOD:ut&&!0===r.extensions.shaderTextureLOD,rendererExtensionFragDepth:c||s.has("EXT_frag_depth"),rendererExtensionDrawBuffers:c||s.has("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:c||s.has("EXT_shader_texture_lod"),customProgramCacheKey:r.customProgramCacheKey()}},getProgramCacheKey:function(e){const i=[];if(e.shaderID?i.push(e.shaderID):(i.push(e.customVertexShaderID),i.push(e.customFragmentShaderID)),void 0!==e.defines)for(const t in e.defines)i.push(t),i.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)}(i,e),function(t,e){o.disableAll(),e.isWebGL2&&o.enable(0);e.supportsVertexTextures&&o.enable(1);e.instancing&&o.enable(2);e.instancingColor&&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);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.skinning&&o.enable(4);e.morphTargets&&o.enable(5);e.morphNormals&&o.enable(6);e.morphColors&&o.enable(7);e.premultipliedAlpha&&o.enable(8);e.shadowMapEnabled&&o.enable(9);e.useLegacyLights&&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);t.push(o.mask)}(i,e),i.push(t.outputColorSpace)),i.push(e.customProgramCacheKey),i.join()},getUniforms:function(t){const e=p[t.type];let i;if(e){const t=MF[e];i=lF.clone(t.uniforms)}else i=t.uniforms;return i},acquireProgram:function(e,i){let s;for(let t=0,e=h.length;t<e;t++){const e=h[t];if(e.cacheKey===i){s=e,++s.usedTimes;break}}return void 0===s&&(s=new AB(t,i,e,r),h.push(s)),s},releaseProgram:function(t){if(0===--t.usedTimes){const e=h.indexOf(t);h[e]=h[h.length-1],h.pop(),t.destroy()}},releaseShaderCache:function(t){l.remove(t)},programs:h,dispose:function(){l.dispose()}}}function LB(){let t=new WeakMap;return{get:function(e){let i=t.get(e);return void 0===i&&(i={},t.set(e,i)),i},remove:function(e){t.delete(e)},update:function(e,i,s){t.get(e)[i]=s},dispose:function(){t=new WeakMap}}}function DB(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 IB(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 OB(){const t=[];let e=0;const i=[],s=[],n=[];function r(i,s,n,r,a,o){let l=t[e];return void 0===l?(l={id:i.id,object:i,geometry:s,material:n,groupOrder:r,renderOrder:i.renderOrder,z:a,group:o},t[e]=l):(l.id=i.id,l.object=i,l.geometry=s,l.material=n,l.groupOrder=r,l.renderOrder=i.renderOrder,l.z=a,l.group=o),e++,l}return{opaque:i,transmissive:s,transparent:n,init:function(){e=0,i.length=0,s.length=0,n.length=0},push:function(t,e,a,o,l,h){const c=r(t,e,a,o,l,h);a.transmission>0?s.push(c):!0===a.transparent?n.push(c):i.push(c)},unshift:function(t,e,a,o,l,h){const c=r(t,e,a,o,l,h);a.transmission>0?s.unshift(c):!0===a.transparent?n.unshift(c):i.unshift(c)},finish:function(){for(let i=e,s=t.length;i<s;i++){const e=t[i];if(null===e.id)break;e.id=null,e.object=null,e.geometry=null,e.material=null,e.group=null}},sort:function(t,e){i.length>1&&i.sort(t||DB),s.length>1&&s.sort(e||IB),n.length>1&&n.sort(e||IB)}}}function NB(){let t=new WeakMap;return{get:function(e,i){const s=t.get(e);let n;return void 0===s?(n=new OB,t.set(e,[n])):i>=s.length?(n=new OB,s.push(n)):n=s[i],n},dispose:function(){t=new WeakMap}}}function FB(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":i={direction:new iO,color:new TN};break;case"SpotLight":i={position:new iO,direction:new iO,color:new TN,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":i={position:new iO,color:new TN,distance:0,decay:0};break;case"HemisphereLight":i={direction:new iO,skyColor:new TN,groundColor:new TN};break;case"RectAreaLight":i={color:new TN,position:new iO,halfWidth:new iO,halfHeight:new iO}}return t[e.id]=i,i}}}let UB=0;function BB(t,e){return(e.castShadow?2:0)-(t.castShadow?2:0)+(e.map?1:0)-(t.map?1:0)}function zB(t,e){const i=new FB,s=function(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":case"SpotLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new MI};break;case"PointLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new MI,shadowCameraNear:1,shadowCameraFar:1e3}}return t[e.id]=i,i}}}(),n={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++)n.probe.push(new iO);const r=new iO,a=new DO,o=new DO;return{setup:function(r,a){let o=0,l=0,h=0;for(let t=0;t<9;t++)n.probe[t].set(0,0,0);let c=0,d=0,u=0,f=0,p=0,m=0,_=0,g=0,v=0,S=0,y=0;r.sort(BB);const x=!0===a?Math.PI:1;for(let t=0,e=r.length;t<e;t++){const e=r[t],a=e.color,T=e.intensity,E=e.distance,b=e.shadow&&e.shadow.map?e.shadow.map.texture:null;if(e.isAmbientLight)o+=a.r*T*x,l+=a.g*T*x,h+=a.b*T*x;else if(e.isLightProbe){for(let t=0;t<9;t++)n.probe[t].addScaledVector(e.sh.coefficients[t],T);y++}else if(e.isDirectionalLight){const t=i.get(e);if(t.color.copy(e.color).multiplyScalar(e.intensity*x),e.castShadow){const t=e.shadow,i=s.get(e);i.shadowBias=t.bias,i.shadowNormalBias=t.normalBias,i.shadowRadius=t.radius,i.shadowMapSize=t.mapSize,n.directionalShadow[c]=i,n.directionalShadowMap[c]=b,n.directionalShadowMatrix[c]=e.shadow.matrix,m++}n.directional[c]=t,c++}else if(e.isSpotLight){const t=i.get(e);t.position.setFromMatrixPosition(e.matrixWorld),t.color.copy(a).multiplyScalar(T*x),t.distance=E,t.coneCos=Math.cos(e.angle),t.penumbraCos=Math.cos(e.angle*(1-e.penumbra)),t.decay=e.decay,n.spot[u]=t;const r=e.shadow;if(e.map&&(n.spotLightMap[v]=e.map,v++,r.updateMatrices(e),e.castShadow&&S++),n.spotLightMatrix[u]=r.matrix,e.castShadow){const t=s.get(e);t.shadowBias=r.bias,t.shadowNormalBias=r.normalBias,t.shadowRadius=r.radius,t.shadowMapSize=r.mapSize,n.spotShadow[u]=t,n.spotShadowMap[u]=b,g++}u++}else if(e.isRectAreaLight){const t=i.get(e);t.color.copy(a).multiplyScalar(T),t.halfWidth.set(.5*e.width,0,0),t.halfHeight.set(0,.5*e.height,0),n.rectArea[f]=t,f++}else if(e.isPointLight){const t=i.get(e);if(t.color.copy(e.color).multiplyScalar(e.intensity*x),t.distance=e.distance,t.decay=e.decay,e.castShadow){const t=e.shadow,i=s.get(e);i.shadowBias=t.bias,i.shadowNormalBias=t.normalBias,i.shadowRadius=t.radius,i.shadowMapSize=t.mapSize,i.shadowCameraNear=t.camera.near,i.shadowCameraFar=t.camera.far,n.pointShadow[d]=i,n.pointShadowMap[d]=b,n.pointShadowMatrix[d]=e.shadow.matrix,_++}n.point[d]=t,d++}else if(e.isHemisphereLight){const t=i.get(e);t.skyColor.copy(e.color).multiplyScalar(T*x),t.groundColor.copy(e.groundColor).multiplyScalar(T*x),n.hemi[p]=t,p++}}f>0&&(e.isWebGL2||!0===t.has("OES_texture_float_linear")?(n.rectAreaLTC1=CF.LTC_FLOAT_1,n.rectAreaLTC2=CF.LTC_FLOAT_2):!0===t.has("OES_texture_half_float_linear")&&(n.rectAreaLTC1=CF.LTC_HALF_1,n.rectAreaLTC2=CF.LTC_HALF_2)),n.ambient[0]=o,n.ambient[1]=l,n.ambient[2]=h;const T=n.hash;T.directionalLength===c&&T.pointLength===d&&T.spotLength===u&&T.rectAreaLength===f&&T.hemiLength===p&&T.numDirectionalShadows===m&&T.numPointShadows===_&&T.numSpotShadows===g&&T.numSpotMaps===v&&T.numLightProbes===y||(n.directional.length=c,n.spot.length=u,n.rectArea.length=f,n.point.length=d,n.hemi.length=p,n.directionalShadow.length=m,n.directionalShadowMap.length=m,n.pointShadow.length=_,n.pointShadowMap.length=_,n.spotShadow.length=g,n.spotShadowMap.length=g,n.directionalShadowMatrix.length=m,n.pointShadowMatrix.length=_,n.spotLightMatrix.length=g+v-S,n.spotLightMap.length=v,n.numSpotLightShadowsWithMaps=S,n.numLightProbes=y,T.directionalLength=c,T.pointLength=d,T.spotLength=u,T.rectAreaLength=f,T.hemiLength=p,T.numDirectionalShadows=m,T.numPointShadows=_,T.numSpotShadows=g,T.numSpotMaps=v,T.numLightProbes=y,n.version=UB++)},setupView:function(t,e){let i=0,s=0,l=0,h=0,c=0;const d=e.matrixWorldInverse;for(let e=0,u=t.length;e<u;e++){const u=t[e];if(u.isDirectionalLight){const t=n.directional[i];t.direction.setFromMatrixPosition(u.matrixWorld),r.setFromMatrixPosition(u.target.matrixWorld),t.direction.sub(r),t.direction.transformDirection(d),i++}else if(u.isSpotLight){const t=n.spot[l];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),t.direction.setFromMatrixPosition(u.matrixWorld),r.setFromMatrixPosition(u.target.matrixWorld),t.direction.sub(r),t.direction.transformDirection(d),l++}else if(u.isRectAreaLight){const t=n.rectArea[h];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),o.identity(),a.copy(u.matrixWorld),a.premultiply(d),o.extractRotation(a),t.halfWidth.set(.5*u.width,0,0),t.halfHeight.set(0,.5*u.height,0),t.halfWidth.applyMatrix4(o),t.halfHeight.applyMatrix4(o),h++}else if(u.isPointLight){const t=n.point[s];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),s++}else if(u.isHemisphereLight){const t=n.hemi[c];t.direction.setFromMatrixPosition(u.matrixWorld),t.direction.transformDirection(d),c++}}},state:n}}function kB(t,e){const i=new zB(t,e),s=[],n=[];return{init:function(){s.length=0,n.length=0},state:{lightsArray:s,shadowsArray:n,lights:i},setupLights:function(t){i.setup(s,t)},setupLightsView:function(t){i.setupView(s,t)},pushLight:function(t){s.push(t)},pushShadow:function(t){n.push(t)}}}function VB(t,e){let i=new WeakMap;return{get:function(s,n=0){const r=i.get(s);let a;return void 0===r?(a=new kB(t,e),i.set(s,[a])):n>=r.length?(a=new kB(t,e),r.push(a)):a=r[n],a},dispose:function(){i=new WeakMap}}}class HB extends gN{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class GB extends gN{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}function WB(t,e,i){let s=new TF;const n=new MI,r=new MI,a=new KI,o=new HB({depthPacking:3201}),l=new GB,h={},c=i.maxTextureSize,d={[nD]:1,[rD]:0,[aD]:2},u=new hF({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new MI},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}"}),f=u.clone();f.defines.HORIZONTAL_PASS=1;const p=new BN;p.setAttribute("position",new CN(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const m=new iF(p,u),_=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let g=this.type;function v(i,s){const r=e.update(m);u.defines.VSM_SAMPLES!==i.blurSamples&&(u.defines.VSM_SAMPLES=i.blurSamples,f.defines.VSM_SAMPLES=i.blurSamples,u.needsUpdate=!0,f.needsUpdate=!0),null===i.mapPass&&(i.mapPass=new QI(n.x,n.y)),u.uniforms.shadow_pass.value=i.map.texture,u.uniforms.resolution.value=i.mapSize,u.uniforms.radius.value=i.radius,t.setRenderTarget(i.mapPass),t.clear(),t.renderBufferDirect(s,null,r,u,m,null),f.uniforms.shadow_pass.value=i.mapPass.texture,f.uniforms.resolution.value=i.mapSize,f.uniforms.radius.value=i.radius,t.setRenderTarget(i.map),t.clear(),t.renderBufferDirect(s,null,r,f,m,null)}function S(e,i,s,n){let r=null;const a=!0===s.isPointLight?e.customDistanceMaterial:e.customDepthMaterial;if(void 0!==a)r=a;else if(r=!0===s.isPointLight?l:o,t.localClippingEnabled&&!0===i.clipShadows&&Array.isArray(i.clippingPlanes)&&0!==i.clippingPlanes.length||i.displacementMap&&0!==i.displacementScale||i.alphaMap&&i.alphaTest>0||i.map&&i.alphaTest>0){const t=r.uuid,e=i.uuid;let s=h[t];void 0===s&&(s={},h[t]=s);let n=s[e];void 0===n&&(n=r.clone(),s[e]=n),r=n}if(r.visible=i.visible,r.wireframe=i.wireframe,r.side=3===n?null!==i.shadowSide?i.shadowSide:i.side:null!==i.shadowSide?i.shadowSide:d[i.side],r.alphaMap=i.alphaMap,r.alphaTest=i.alphaTest,r.map=i.map,r.clipShadows=i.clipShadows,r.clippingPlanes=i.clippingPlanes,r.clipIntersection=i.clipIntersection,r.displacementMap=i.displacementMap,r.displacementScale=i.displacementScale,r.displacementBias=i.displacementBias,r.wireframeLinewidth=i.wireframeLinewidth,r.linewidth=i.linewidth,!0===s.isPointLight&&!0===r.isMeshDistanceMaterial){t.properties.get(r).light=s}return r}function y(i,n,r,a,o){if(!1===i.visible)return;if(i.layers.test(n.layers)&&(i.isMesh||i.isLine||i.isPoints)&&(i.castShadow||i.receiveShadow&&3===o)&&(!i.frustumCulled||s.intersectsObject(i))){i.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,i.matrixWorld);const s=e.update(i),n=i.material;if(Array.isArray(n)){const e=s.groups;for(let l=0,h=e.length;l<h;l++){const h=e[l],c=n[h.materialIndex];if(c&&c.visible){const e=S(i,c,a,o);t.renderBufferDirect(r,null,s,e,i,h)}}}else if(n.visible){const e=S(i,n,a,o);t.renderBufferDirect(r,null,s,e,i,null)}}const l=i.children;for(let t=0,e=l.length;t<e;t++)y(l[t],n,r,a,o)}this.render=function(e,i,o){if(!1===_.enabled)return;if(!1===_.autoUpdate&&!1===_.needsUpdate)return;if(0===e.length)return;const l=t.getRenderTarget(),h=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),u=t.state;u.setBlending(0),u.buffers.color.setClear(1,1,1,1),u.buffers.depth.setTest(!0),u.setScissorTest(!1);const f=3!==g&&3===this.type,p=3===g&&3!==this.type;for(let l=0,h=e.length;l<h;l++){const h=e[l],d=h.shadow;if(void 0===d)continue;if(!1===d.autoUpdate&&!1===d.needsUpdate)continue;n.copy(d.mapSize);const m=d.getFrameExtents();if(n.multiply(m),r.copy(d.mapSize),(n.x>c||n.y>c)&&(n.x>c&&(r.x=Math.floor(c/m.x),n.x=r.x*m.x,d.mapSize.x=r.x),n.y>c&&(r.y=Math.floor(c/m.y),n.y=r.y*m.y,d.mapSize.y=r.y)),null===d.map||!0===f||!0===p){const t=3!==this.type?{minFilter:CD,magFilter:CD}:{};null!==d.map&&d.map.dispose(),d.map=new QI(n.x,n.y,t),d.map.texture.name=h.name+".shadowMap",d.camera.updateProjectionMatrix()}t.setRenderTarget(d.map),t.clear();const _=d.getViewportCount();for(let t=0;t<_;t++){const e=d.getViewport(t);a.set(r.x*e.x,r.y*e.y,r.x*e.z,r.y*e.w),u.viewport(a),d.updateMatrices(h,t),s=d.getFrustum(),y(i,o,d.camera,h,this.type)}!0!==d.isPointLightShadow&&3===this.type&&v(d,o),d.needsUpdate=!1}g=this.type,_.needsUpdate=!1,t.setRenderTarget(l,h,d)}}function XB(t,e,i){const s=i.isWebGL2;const n=new function(){let e=!1;const i=new KI;let s=null;const n=new KI(0,0,0,0);return{setMask:function(i){s===i||e||(t.colorMask(i,i,i,i),s=i)},setLocked:function(t){e=t},setClear:function(e,s,r,a,o){!0===o&&(e*=a,s*=a,r*=a),i.set(e,s,r,a),!1===n.equals(i)&&(t.clearColor(e,s,r,a),n.copy(i))},reset:function(){e=!1,s=null,n.set(-1,0,0,0)}}},r=new function(){let e=!1,i=null,s=null,n=null;return{setTest:function(e){e?k(t.DEPTH_TEST):V(t.DEPTH_TEST)},setMask:function(s){i===s||e||(t.depthMask(s),i=s)},setFunc:function(e){if(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){e=t},setClear:function(e){n!==e&&(t.clearDepth(e),n=e)},reset:function(){e=!1,i=null,s=null,n=null}}},a=new function(){let e=!1,i=null,s=null,n=null,r=null,a=null,o=null,l=null,h=null;return{setTest:function(i){e||(i?k(t.STENCIL_TEST):V(t.STENCIL_TEST))},setMask:function(s){i===s||e||(t.stencilMask(s),i=s)},setFunc:function(e,i,a){s===e&&n===i&&r===a||(t.stencilFunc(e,i,a),s=e,n=i,r=a)},setOp:function(e,i,s){a===e&&o===i&&l===s||(t.stencilOp(e,i,s),a=e,o=i,l=s)},setLocked:function(t){e=t},setClear:function(e){h!==e&&(t.clearStencil(e),h=e)},reset:function(){e=!1,i=null,s=null,n=null,r=null,a=null,o=null,l=null,h=null}}},o=new WeakMap,l=new WeakMap;let h={},c={},d=new WeakMap,u=[],f=null,p=!1,m=null,_=null,g=null,v=null,S=null,y=null,x=null,T=!1,E=null,b=null,w=null,A=null,C=null;const M=t.getParameter(t.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let P=!1,R=0;const L=t.getParameter(t.VERSION);-1!==L.indexOf("WebGL")?(R=parseFloat(/^WebGL (\d)/.exec(L)[1]),P=R>=1):-1!==L.indexOf("OpenGL ES")&&(R=parseFloat(/^OpenGL ES (\d)/.exec(L)[1]),P=R>=2);let D=null,I={};const O=t.getParameter(t.SCISSOR_BOX),N=t.getParameter(t.VIEWPORT),F=(new KI).fromArray(O),U=(new KI).fromArray(N);function B(e,i,n,r){const a=new Uint8Array(4),o=t.createTexture();t.bindTexture(e,o),t.texParameteri(e,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(e,t.TEXTURE_MAG_FILTER,t.NEAREST);for(let o=0;o<n;o++)!s||e!==t.TEXTURE_3D&&e!==t.TEXTURE_2D_ARRAY?t.texImage2D(i+o,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,a):t.texImage3D(i,0,t.RGBA,1,1,r,0,t.RGBA,t.UNSIGNED_BYTE,a);return o}const z={};function k(e){!0!==h[e]&&(t.enable(e),h[e]=!0)}function V(e){!1!==h[e]&&(t.disable(e),h[e]=!1)}z[t.TEXTURE_2D]=B(t.TEXTURE_2D,t.TEXTURE_2D,1),z[t.TEXTURE_CUBE_MAP]=B(t.TEXTURE_CUBE_MAP,t.TEXTURE_CUBE_MAP_POSITIVE_X,6),s&&(z[t.TEXTURE_2D_ARRAY]=B(t.TEXTURE_2D_ARRAY,t.TEXTURE_2D_ARRAY,1,1),z[t.TEXTURE_3D]=B(t.TEXTURE_3D,t.TEXTURE_3D,1,1)),n.setClear(0,0,0,1),r.setClear(1),a.setClear(0),k(t.DEPTH_TEST),r.setFunc(3),X(!1),Y(1),k(t.CULL_FACE),W(0);const H={[oD]:t.FUNC_ADD,[lD]:t.FUNC_SUBTRACT,[hD]:t.FUNC_REVERSE_SUBTRACT};if(s)H[103]=t.MIN,H[104]=t.MAX;else{const t=e.get("EXT_blend_minmax");null!==t&&(H[103]=t.MIN_EXT,H[104]=t.MAX_EXT)}const G={[cD]:t.ZERO,[dD]:t.ONE,[uD]:t.SRC_COLOR,[pD]:t.SRC_ALPHA,[yD]:t.SRC_ALPHA_SATURATE,[vD]:t.DST_COLOR,[_D]:t.DST_ALPHA,[fD]:t.ONE_MINUS_SRC_COLOR,[mD]:t.ONE_MINUS_SRC_ALPHA,[SD]:t.ONE_MINUS_DST_COLOR,[gD]:t.ONE_MINUS_DST_ALPHA};function W(e,i,s,n,r,a,o,l){if(0!==e){if(!1===p&&(k(t.BLEND),p=!0),5===e)r=r||i,a=a||s,o=o||n,i===_&&r===S||(t.blendEquationSeparate(H[i],H[r]),_=i,S=r),s===g&&n===v&&a===y&&o===x||(t.blendFuncSeparate(G[s],G[n],G[a],G[o]),g=s,v=n,y=a,x=o),m=e,T=!1;else if(e!==m||l!==T){if(_===oD&&S===oD||(t.blendEquation(t.FUNC_ADD),_=oD,S=oD),l)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)}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)}g=null,v=null,y=null,x=null,m=e,T=l}}else!0===p&&(V(t.BLEND),p=!1)}function X(e){E!==e&&(e?t.frontFace(t.CW):t.frontFace(t.CCW),E=e)}function Y(e){0!==e?(k(t.CULL_FACE),e!==b&&(1===e?t.cullFace(t.BACK):2===e?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):V(t.CULL_FACE),b=e}function q(e,i,s){e?(k(t.POLYGON_OFFSET_FILL),A===i&&C===s||(t.polygonOffset(i,s),A=i,C=s)):V(t.POLYGON_OFFSET_FILL)}return{buffers:{color:n,depth:r,stencil:a},enable:k,disable:V,bindFramebuffer:function(e,i){return c[e]!==i&&(t.bindFramebuffer(e,i),c[e]=i,s&&(e===t.DRAW_FRAMEBUFFER&&(c[t.FRAMEBUFFER]=i),e===t.FRAMEBUFFER&&(c[t.DRAW_FRAMEBUFFER]=i)),!0)},drawBuffers:function(s,n){let r=u,a=!1;if(s)if(r=d.get(n),void 0===r&&(r=[],d.set(n,r)),s.isWebGLMultipleRenderTargets){const e=s.texture;if(r.length!==e.length||r[0]!==t.COLOR_ATTACHMENT0){for(let i=0,s=e.length;i<s;i++)r[i]=t.COLOR_ATTACHMENT0+i;r.length=e.length,a=!0}}else r[0]!==t.COLOR_ATTACHMENT0&&(r[0]=t.COLOR_ATTACHMENT0,a=!0);else r[0]!==t.BACK&&(r[0]=t.BACK,a=!0);a&&(i.isWebGL2?t.drawBuffers(r):e.get("WEBGL_draw_buffers").drawBuffersWEBGL(r))},useProgram:function(e){return f!==e&&(t.useProgram(e),f=e,!0)},setBlending:W,setMaterial:function(e,i){2===e.side?V(t.CULL_FACE):k(t.CULL_FACE);let s=1===e.side;i&&(s=!s),X(s),1===e.blending&&!1===e.transparent?W(0):W(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.premultipliedAlpha),r.setFunc(e.depthFunc),r.setTest(e.depthTest),r.setMask(e.depthWrite),n.setMask(e.colorWrite);const o=e.stencilWrite;a.setTest(o),o&&(a.setMask(e.stencilWriteMask),a.setFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),a.setOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),q(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),!0===e.alphaToCoverage?k(t.SAMPLE_ALPHA_TO_COVERAGE):V(t.SAMPLE_ALPHA_TO_COVERAGE)},setFlipSided:X,setCullFace:Y,setLineWidth:function(e){e!==w&&(P&&t.lineWidth(e),w=e)},setPolygonOffset:q,setScissorTest:function(e){e?k(t.SCISSOR_TEST):V(t.SCISSOR_TEST)},activeTexture:function(e){void 0===e&&(e=t.TEXTURE0+M-1),D!==e&&(t.activeTexture(e),D=e)},bindTexture:function(e,i,s){void 0===s&&(s=null===D?t.TEXTURE0+M-1:D);let n=I[s];void 0===n&&(n={type:void 0,texture:void 0},I[s]=n),n.type===e&&n.texture===i||(D!==s&&(t.activeTexture(s),D=s),t.bindTexture(e,i||z[e]),n.type=e,n.texture=i)},unbindTexture:function(){const e=I[D];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){}},compressedTexImage3D:function(){try{t.compressedTexImage3D.apply(t,arguments)}catch(t){}},texImage2D:function(){try{t.texImage2D.apply(t,arguments)}catch(t){}},texImage3D:function(){try{t.texImage3D.apply(t,arguments)}catch(t){}},updateUBOMapping:function(e,i){let s=l.get(i);void 0===s&&(s=new WeakMap,l.set(i,s));let n=s.get(e);void 0===n&&(n=t.getUniformBlockIndex(i,e.name),s.set(e,n))},uniformBlockBinding:function(e,i){const s=l.get(i).get(e);o.get(i)!==s&&(t.uniformBlockBinding(i,s,e.__bindingPointIndex),o.set(i,s))},texStorage2D:function(){try{t.texStorage2D.apply(t,arguments)}catch(t){}},texStorage3D:function(){try{t.texStorage3D.apply(t,arguments)}catch(t){}},texSubImage2D:function(){try{t.texSubImage2D.apply(t,arguments)}catch(t){}},texSubImage3D:function(){try{t.texSubImage3D.apply(t,arguments)}catch(t){}},compressedTexSubImage2D:function(){try{t.compressedTexSubImage2D.apply(t,arguments)}catch(t){}},compressedTexSubImage3D:function(){try{t.compressedTexSubImage3D.apply(t,arguments)}catch(t){}},scissor:function(e){!1===F.equals(e)&&(t.scissor(e.x,e.y,e.z,e.w),F.copy(e))},viewport:function(e){!1===U.equals(e)&&(t.viewport(e.x,e.y,e.z,e.w),U.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.colorMask(!0,!0,!0,!0),t.clearColor(0,0,0,0),t.depthMask(!0),t.depthFunc(t.LESS),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),!0===s&&(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),h={},D=null,I={},c={},d=new WeakMap,u=[],f=null,p=!1,m=null,_=null,g=null,v=null,S=null,y=null,x=null,T=!1,E=null,b=null,w=null,A=null,C=null,F.set(0,0,t.canvas.width,t.canvas.height),U.set(0,0,t.canvas.width,t.canvas.height),n.reset(),r.reset(),a.reset()}}}function YB(t,e,i,s,n,r,a){const o=n.isWebGL2,l=(n.maxTextures,n.maxCubemapSize),h=n.maxTextureSize,c=n.maxSamples,d=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,u="undefined"!=typeof navigator&&/OculusBrowser/g.test(navigator.userAgent),f=new WeakMap;let p;const m=new WeakMap;let _=!1;try{_="undefined"!=typeof OffscreenCanvas&&null!==new OffscreenCanvas(1,1).getContext("2d")}catch(t){}function g(t,e){return _?new OffscreenCanvas(t,e):DI("canvas")}function v(t,e,i,s){let n=1;if((t.width>s||t.height>s)&&(n=s/Math.max(t.width,t.height)),n<1||!0===e){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const s=e?wI:Math.floor,r=s(n*t.width),a=s(n*t.height);void 0===p&&(p=g(r,a));const o=i?g(r,a):p;o.width=r,o.height=a;return o.getContext("2d").drawImage(t,0,0,r,a),o}return t}return t}function S(t){return bI(t.width)&&bI(t.height)}function y(t,e){return t.generateMipmaps&&e&&t.minFilter!==CD&&t.minFilter!==RD}function x(e){t.generateMipmap(e)}function T(i,s,n,r,a=!1){if(!1===o)return s;if(null!==i&&void 0!==t[i])return t[i];let l=s;if(s===t.RED&&(n===t.FLOAT&&(l=t.R32F),n===t.HALF_FLOAT&&(l=t.R16F),n===t.UNSIGNED_BYTE&&(l=t.R8)),s===t.RED_INTEGER&&(n===t.UNSIGNED_BYTE&&(l=t.R8UI),n===t.UNSIGNED_SHORT&&(l=t.R16UI),n===t.UNSIGNED_INT&&(l=t.R32UI),n===t.BYTE&&(l=t.R8I),n===t.SHORT&&(l=t.R16I),n===t.INT&&(l=t.R32I)),s===t.RG&&(n===t.FLOAT&&(l=t.RG32F),n===t.HALF_FLOAT&&(l=t.RG16F),n===t.UNSIGNED_BYTE&&(l=t.RG8)),s===t.RGBA){const e=a?tI:kI.getTransfer(r);n===t.FLOAT&&(l=t.RGBA32F),n===t.HALF_FLOAT&&(l=t.RGBA16F),n===t.UNSIGNED_BYTE&&(l=e===eI?t.SRGB8_ALPHA8:t.RGBA8),n===t.UNSIGNED_SHORT_4_4_4_4&&(l=t.RGBA4),n===t.UNSIGNED_SHORT_5_5_5_1&&(l=t.RGB5_A1)}return l!==t.R16F&&l!==t.R32F&&l!==t.RG16F&&l!==t.RG32F&&l!==t.RGBA16F&&l!==t.RGBA32F||e.get("EXT_color_buffer_float"),l}function E(t,e,i){return!0===y(t,i)||t.isFramebufferTexture&&t.minFilter!==CD&&t.minFilter!==RD?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 b(e){return e===CD||1004===e||e===PD?t.NEAREST:t.LINEAR}function w(t){const e=t.target;e.removeEventListener("dispose",w),function(t){const e=s.get(t);if(void 0===e.__webglInit)return;const i=t.source,n=m.get(i);if(n){const s=n[e.__cacheKey];s.usedTimes--,0===s.usedTimes&&C(t),0===Object.keys(n).length&&m.delete(i)}s.remove(t)}(e),e.isVideoTexture&&f.delete(e)}function A(e){const i=e.target;i.removeEventListener("dispose",A),function(e){const i=e.texture,n=s.get(e),r=s.get(i);void 0!==r.__webglTexture&&(t.deleteTexture(r.__webglTexture),a.memory.textures--);e.depthTexture&&e.depthTexture.dispose();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)}if(e.isWebGLMultipleRenderTargets)for(let e=0,n=i.length;e<n;e++){const n=s.get(i[e]);n.__webglTexture&&(t.deleteTexture(n.__webglTexture),a.memory.textures--),s.remove(i[e])}s.remove(i),s.remove(e)}(i)}function C(e){const i=s.get(e);t.deleteTexture(i.__webglTexture);const n=e.source;delete m.get(n)[i.__cacheKey],a.memory.textures--}let M=0;function P(e,n){const r=s.get(e);if(e.isVideoTexture&&function(t){const e=a.render.frame;f.get(t)!==e&&(f.set(t,e),t.update())}(e),!1===e.isRenderTargetTexture&&e.version>0&&r.__version!==e.version){const t=e.image;if(null===t);else if(!1!==t.complete)return void N(r,e,n)}i.bindTexture(t.TEXTURE_2D,r.__webglTexture,t.TEXTURE0+n)}const R={[bD]:t.REPEAT,[wD]:t.CLAMP_TO_EDGE,[AD]:t.MIRRORED_REPEAT},L={[CD]:t.NEAREST,[MD]:t.NEAREST_MIPMAP_NEAREST,[PD]:t.NEAREST_MIPMAP_LINEAR,[RD]:t.LINEAR,[LD]:t.LINEAR_MIPMAP_NEAREST,[DD]:t.LINEAR_MIPMAP_LINEAR},D={[rI]:t.NEVER,[uI]:t.ALWAYS,[aI]:t.LESS,[lI]:t.LEQUAL,[oI]:t.EQUAL,[dI]:t.GEQUAL,[hI]:t.GREATER,[cI]:t.NOTEQUAL};function I(i,r,a){if(a?(t.texParameteri(i,t.TEXTURE_WRAP_S,R[r.wrapS]),t.texParameteri(i,t.TEXTURE_WRAP_T,R[r.wrapT]),i!==t.TEXTURE_3D&&i!==t.TEXTURE_2D_ARRAY||t.texParameteri(i,t.TEXTURE_WRAP_R,R[r.wrapR]),t.texParameteri(i,t.TEXTURE_MAG_FILTER,L[r.magFilter]),t.texParameteri(i,t.TEXTURE_MIN_FILTER,L[r.minFilter])):(t.texParameteri(i,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(i,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),i!==t.TEXTURE_3D&&i!==t.TEXTURE_2D_ARRAY||t.texParameteri(i,t.TEXTURE_WRAP_R,t.CLAMP_TO_EDGE),r.wrapS!==wD||r.wrapT,t.texParameteri(i,t.TEXTURE_MAG_FILTER,b(r.magFilter)),t.texParameteri(i,t.TEXTURE_MIN_FILTER,b(r.minFilter)),r.minFilter!==CD&&r.minFilter),r.compareFunction&&(t.texParameteri(i,t.TEXTURE_COMPARE_MODE,t.COMPARE_REF_TO_TEXTURE),t.texParameteri(i,t.TEXTURE_COMPARE_FUNC,D[r.compareFunction])),!0===e.has("EXT_texture_filter_anisotropic")){const a=e.get("EXT_texture_filter_anisotropic");if(r.magFilter===CD)return;if(r.minFilter!==PD&&r.minFilter!==DD)return;if(r.type===UD&&!1===e.has("OES_texture_float_linear"))return;if(!1===o&&r.type===BD&&!1===e.has("OES_texture_half_float_linear"))return;(r.anisotropy>1||s.get(r).__currentAnisotropy)&&(t.texParameterf(i,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(r.anisotropy,n.getMaxAnisotropy())),s.get(r).__currentAnisotropy=r.anisotropy)}}function O(e,i){let s=!1;void 0===e.__webglInit&&(e.__webglInit=!0,i.addEventListener("dispose",w));const n=i.source;let r=m.get(n);void 0===r&&(r={},m.set(n,r));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()}(i);if(o!==e.__cacheKey){void 0===r[o]&&(r[o]={texture:t.createTexture(),usedTimes:0},a.memory.textures++,s=!0),r[o].usedTimes++;const n=r[e.__cacheKey];void 0!==n&&(r[e.__cacheKey].usedTimes--,0===n.usedTimes&&C(i)),e.__cacheKey=o,e.__webglTexture=r[o].texture}return s}function N(e,n,a){let l=t.TEXTURE_2D;(n.isDataArrayTexture||n.isCompressedArrayTexture)&&(l=t.TEXTURE_2D_ARRAY),n.isData3DTexture&&(l=t.TEXTURE_3D);const c=O(e,n),d=n.source;i.bindTexture(l,e.__webglTexture,t.TEXTURE0+a);const u=s.get(d);if(d.version!==u.__version||!0===c){i.activeTexture(t.TEXTURE0+a);const e=kI.getPrimaries(kI.workingColorSpace),s=n.colorSpace===$D?null:kI.getPrimaries(n.colorSpace),f=n.colorSpace===$D||e===s?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,n.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,n.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,f);const p=function(t){return!o&&(t.wrapS!==wD||t.wrapT!==wD||t.minFilter!==CD&&t.minFilter!==RD)}(n)&&!1===S(n.image);let m=v(n.image,p,!1,h);m=V(n,m);const _=S(m)||o,g=r.convert(n.format,n.colorSpace);let b,w=r.convert(n.type),A=T(n.internalFormat,g,w,n.colorSpace,n.isVideoTexture);I(l,n,_);const C=n.mipmaps,M=o&&!0!==n.isVideoTexture,P=void 0===u.__version||!0===c,R=E(n,m,_);if(n.isDepthTexture)A=t.DEPTH_COMPONENT,o?A=n.type===UD?t.DEPTH_COMPONENT32F:n.type===FD?t.DEPTH_COMPONENT24:n.type===zD?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT16:n.type,n.format===VD&&A===t.DEPTH_COMPONENT&&n.type!==OD&&n.type!==FD&&(n.type=FD,w=r.convert(n.type)),n.format===HD&&A===t.DEPTH_COMPONENT&&(A=t.DEPTH_STENCIL,n.type!==zD&&(n.type=zD,w=r.convert(n.type))),P&&(M?i.texStorage2D(t.TEXTURE_2D,1,A,m.width,m.height):i.texImage2D(t.TEXTURE_2D,0,A,m.width,m.height,0,g,w,null));else if(n.isDataTexture)if(C.length>0&&_){M&&P&&i.texStorage2D(t.TEXTURE_2D,R,A,C[0].width,C[0].height);for(let e=0,s=C.length;e<s;e++)b=C[e],M?i.texSubImage2D(t.TEXTURE_2D,e,0,0,b.width,b.height,g,w,b.data):i.texImage2D(t.TEXTURE_2D,e,A,b.width,b.height,0,g,w,b.data);n.generateMipmaps=!1}else M?(P&&i.texStorage2D(t.TEXTURE_2D,R,A,m.width,m.height),i.texSubImage2D(t.TEXTURE_2D,0,0,0,m.width,m.height,g,w,m.data)):i.texImage2D(t.TEXTURE_2D,0,A,m.width,m.height,0,g,w,m.data);else if(n.isCompressedTexture)if(n.isCompressedArrayTexture){M&&P&&i.texStorage3D(t.TEXTURE_2D_ARRAY,R,A,C[0].width,C[0].height,m.depth);for(let e=0,s=C.length;e<s;e++)b=C[e],n.format!==kD?null!==g&&(M?i.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,b.width,b.height,m.depth,g,b.data,0,0):i.compressedTexImage3D(t.TEXTURE_2D_ARRAY,e,A,b.width,b.height,m.depth,0,b.data,0,0)):M?i.texSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,b.width,b.height,m.depth,g,w,b.data):i.texImage3D(t.TEXTURE_2D_ARRAY,e,A,b.width,b.height,m.depth,0,g,w,b.data)}else{M&&P&&i.texStorage2D(t.TEXTURE_2D,R,A,C[0].width,C[0].height);for(let e=0,s=C.length;e<s;e++)b=C[e],n.format!==kD?null!==g&&(M?i.compressedTexSubImage2D(t.TEXTURE_2D,e,0,0,b.width,b.height,g,b.data):i.compressedTexImage2D(t.TEXTURE_2D,e,A,b.width,b.height,0,b.data)):M?i.texSubImage2D(t.TEXTURE_2D,e,0,0,b.width,b.height,g,w,b.data):i.texImage2D(t.TEXTURE_2D,e,A,b.width,b.height,0,g,w,b.data)}else if(n.isDataArrayTexture)M?(P&&i.texStorage3D(t.TEXTURE_2D_ARRAY,R,A,m.width,m.height,m.depth),i.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,0,m.width,m.height,m.depth,g,w,m.data)):i.texImage3D(t.TEXTURE_2D_ARRAY,0,A,m.width,m.height,m.depth,0,g,w,m.data);else if(n.isData3DTexture)M?(P&&i.texStorage3D(t.TEXTURE_3D,R,A,m.width,m.height,m.depth),i.texSubImage3D(t.TEXTURE_3D,0,0,0,0,m.width,m.height,m.depth,g,w,m.data)):i.texImage3D(t.TEXTURE_3D,0,A,m.width,m.height,m.depth,0,g,w,m.data);else if(n.isFramebufferTexture){if(P)if(M)i.texStorage2D(t.TEXTURE_2D,R,A,m.width,m.height);else{let e=m.width,s=m.height;for(let n=0;n<R;n++)i.texImage2D(t.TEXTURE_2D,n,A,e,s,0,g,w,null),e>>=1,s>>=1}}else if(C.length>0&&_){M&&P&&i.texStorage2D(t.TEXTURE_2D,R,A,C[0].width,C[0].height);for(let e=0,s=C.length;e<s;e++)b=C[e],M?i.texSubImage2D(t.TEXTURE_2D,e,0,0,g,w,b):i.texImage2D(t.TEXTURE_2D,e,A,g,w,b);n.generateMipmaps=!1}else M?(P&&i.texStorage2D(t.TEXTURE_2D,R,A,m.width,m.height),i.texSubImage2D(t.TEXTURE_2D,0,0,0,g,w,m)):i.texImage2D(t.TEXTURE_2D,0,A,g,w,m);y(n,_)&&x(l),u.__version=d.version,n.onUpdate&&n.onUpdate(n)}e.__version=n.version}function F(e,n,a,o,l,h){const c=r.convert(a.format,a.colorSpace),u=r.convert(a.type),f=T(a.internalFormat,c,u,a.colorSpace);if(!s.get(n).__hasExternalTextures){const e=Math.max(1,n.width>>h),s=Math.max(1,n.height>>h);l===t.TEXTURE_3D||l===t.TEXTURE_2D_ARRAY?i.texImage3D(l,h,f,e,s,n.depth,0,c,u,null):i.texImage2D(l,h,f,e,s,0,c,u,null)}i.bindFramebuffer(t.FRAMEBUFFER,e),k(n)?d.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,o,l,s.get(a).__webglTexture,0,z(n)):(l===t.TEXTURE_2D||l>=t.TEXTURE_CUBE_MAP_POSITIVE_X&&l<=t.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&t.framebufferTexture2D(t.FRAMEBUFFER,o,l,s.get(a).__webglTexture,h),i.bindFramebuffer(t.FRAMEBUFFER,null)}function U(e,i,s){if(t.bindRenderbuffer(t.RENDERBUFFER,e),i.depthBuffer&&!i.stencilBuffer){let n=!0===o?t.DEPTH_COMPONENT24:t.DEPTH_COMPONENT16;if(s||k(i)){const e=i.depthTexture;e&&e.isDepthTexture&&(e.type===UD?n=t.DEPTH_COMPONENT32F:e.type===FD&&(n=t.DEPTH_COMPONENT24));const s=z(i);k(i)?d.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,s,n,i.width,i.height):t.renderbufferStorageMultisample(t.RENDERBUFFER,s,n,i.width,i.height)}else t.renderbufferStorage(t.RENDERBUFFER,n,i.width,i.height);t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,e)}else if(i.depthBuffer&&i.stencilBuffer){const n=z(i);s&&!1===k(i)?t.renderbufferStorageMultisample(t.RENDERBUFFER,n,t.DEPTH24_STENCIL8,i.width,i.height):k(i)?d.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,n,t.DEPTH24_STENCIL8,i.width,i.height):t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_STENCIL,i.width,i.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.RENDERBUFFER,e)}else{const e=!0===i.isWebGLMultipleRenderTargets?i.texture:[i.texture];for(let n=0;n<e.length;n++){const a=e[n],o=r.convert(a.format,a.colorSpace),l=r.convert(a.type),h=T(a.internalFormat,o,l,a.colorSpace),c=z(i);s&&!1===k(i)?t.renderbufferStorageMultisample(t.RENDERBUFFER,c,h,i.width,i.height):k(i)?d.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,c,h,i.width,i.height):t.renderbufferStorage(t.RENDERBUFFER,h,i.width,i.height)}}t.bindRenderbuffer(t.RENDERBUFFER,null)}function B(e){const n=s.get(e),r=!0===e.isWebGLCubeRenderTarget;if(e.depthTexture&&!n.__autoAllocateDepthBuffer){if(r)throw new Error("target.depthTexture not supported in Cube render targets");!function(e,n){if(n&&n.isWebGLCubeRenderTarget)throw new Error("Depth Texture with cube render targets is not supported");if(i.bindFramebuffer(t.FRAMEBUFFER,e),!n.depthTexture||!n.depthTexture.isDepthTexture)throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");s.get(n.depthTexture).__webglTexture&&n.depthTexture.image.width===n.width&&n.depthTexture.image.height===n.height||(n.depthTexture.image.width=n.width,n.depthTexture.image.height=n.height,n.depthTexture.needsUpdate=!0),P(n.depthTexture,0);const r=s.get(n.depthTexture).__webglTexture,a=z(n);if(n.depthTexture.format===VD)k(n)?d.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.TEXTURE_2D,r,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.TEXTURE_2D,r,0);else{if(n.depthTexture.format!==HD)throw new Error("Unknown depthTexture format");k(n)?d.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.TEXTURE_2D,r,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.TEXTURE_2D,r,0)}}(n.__webglFramebuffer,e)}else if(r){n.__webglDepthbuffer=[];for(let s=0;s<6;s++)i.bindFramebuffer(t.FRAMEBUFFER,n.__webglFramebuffer[s]),n.__webglDepthbuffer[s]=t.createRenderbuffer(),U(n.__webglDepthbuffer[s],e,!1)}else i.bindFramebuffer(t.FRAMEBUFFER,n.__webglFramebuffer),n.__webglDepthbuffer=t.createRenderbuffer(),U(n.__webglDepthbuffer,e,!1);i.bindFramebuffer(t.FRAMEBUFFER,null)}function z(t){return Math.min(c,t.samples)}function k(t){const i=s.get(t);return o&&t.samples>0&&!0===e.has("WEBGL_multisampled_render_to_texture")&&!1!==i.__useRenderToTexture}function V(t,i){const s=t.colorSpace,n=t.format;t.type;return!0===t.isCompressedTexture||!0===t.isVideoTexture||t.format===pI||s!==ZD&&s!==$D&&kI.getTransfer(s)===eI&&!1===o&&(!0===e.has("EXT_sRGB")&&n===kD?(t.format=pI,t.minFilter=RD,t.generateMipmaps=!1):i=WI.sRGBToLinear(i)),i}this.allocateTextureUnit=function(){const t=M;return M+=1,t},this.resetTextureUnits=function(){M=0},this.setTexture2D=P,this.setTexture2DArray=function(e,n){const r=s.get(e);e.version>0&&r.__version!==e.version?N(r,e,n):i.bindTexture(t.TEXTURE_2D_ARRAY,r.__webglTexture,t.TEXTURE0+n)},this.setTexture3D=function(e,n){const r=s.get(e);e.version>0&&r.__version!==e.version?N(r,e,n):i.bindTexture(t.TEXTURE_3D,r.__webglTexture,t.TEXTURE0+n)},this.setTextureCube=function(e,n){const a=s.get(e);e.version>0&&a.__version!==e.version?function(e,n,a){if(6!==n.image.length)return;const h=O(e,n),c=n.source;i.bindTexture(t.TEXTURE_CUBE_MAP,e.__webglTexture,t.TEXTURE0+a);const d=s.get(c);if(c.version!==d.__version||!0===h){i.activeTexture(t.TEXTURE0+a);const e=kI.getPrimaries(kI.workingColorSpace),s=n.colorSpace===$D?null:kI.getPrimaries(n.colorSpace),u=n.colorSpace===$D||e===s?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,n.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,n.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,u);const f=n.isCompressedTexture||n.image[0].isCompressedTexture,p=n.image[0]&&n.image[0].isDataTexture,m=[];for(let t=0;t<6;t++)m[t]=f||p?p?n.image[t].image:n.image[t]:v(n.image[t],!1,!0,l),m[t]=V(n,m[t]);const _=m[0],g=S(_)||o,b=r.convert(n.format,n.colorSpace),w=r.convert(n.type),A=T(n.internalFormat,b,w,n.colorSpace),C=o&&!0!==n.isVideoTexture,M=void 0===d.__version||!0===h;let P,R=E(n,_,g);if(I(t.TEXTURE_CUBE_MAP,n,g),f){C&&M&&i.texStorage2D(t.TEXTURE_CUBE_MAP,R,A,_.width,_.height);for(let e=0;e<6;e++){P=m[e].mipmaps;for(let s=0;s<P.length;s++){const r=P[s];n.format!==kD?null!==b&&(C?i.compressedTexSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s,0,0,r.width,r.height,b,r.data):i.compressedTexImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s,A,r.width,r.height,0,r.data)):C?i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s,0,0,r.width,r.height,b,w,r.data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s,A,r.width,r.height,0,b,w,r.data)}}}else{P=n.mipmaps,C&&M&&(P.length>0&&R++,i.texStorage2D(t.TEXTURE_CUBE_MAP,R,A,m[0].width,m[0].height));for(let e=0;e<6;e++)if(p){C?i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,m[e].width,m[e].height,b,w,m[e].data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,A,m[e].width,m[e].height,0,b,w,m[e].data);for(let s=0;s<P.length;s++){const n=P[s].image[e].image;C?i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s+1,0,0,n.width,n.height,b,w,n.data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s+1,A,n.width,n.height,0,b,w,n.data)}}else{C?i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,b,w,m[e]):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,A,b,w,m[e]);for(let s=0;s<P.length;s++){const n=P[s];C?i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s+1,0,0,b,w,n.image[e]):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s+1,A,b,w,n.image[e])}}}y(n,g)&&x(t.TEXTURE_CUBE_MAP),d.__version=c.version,n.onUpdate&&n.onUpdate(n)}e.__version=n.version}(a,e,n):i.bindTexture(t.TEXTURE_CUBE_MAP,a.__webglTexture,t.TEXTURE0+n)},this.rebindTextures=function(e,i,n){const r=s.get(e);void 0!==i&&F(r.__webglFramebuffer,e,e.texture,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,0),void 0!==n&&B(e)},this.setupRenderTarget=function(e){const l=e.texture,h=s.get(e),c=s.get(l);e.addEventListener("dispose",A),!0!==e.isWebGLMultipleRenderTargets&&(void 0===c.__webglTexture&&(c.__webglTexture=t.createTexture()),c.__version=l.version,a.memory.textures++);const d=!0===e.isWebGLCubeRenderTarget,u=!0===e.isWebGLMultipleRenderTargets,f=S(e)||o;if(d){h.__webglFramebuffer=[];for(let e=0;e<6;e++)if(o&&l.mipmaps&&l.mipmaps.length>0){h.__webglFramebuffer[e]=[];for(let i=0;i<l.mipmaps.length;i++)h.__webglFramebuffer[e][i]=t.createFramebuffer()}else h.__webglFramebuffer[e]=t.createFramebuffer()}else{if(o&&l.mipmaps&&l.mipmaps.length>0){h.__webglFramebuffer=[];for(let e=0;e<l.mipmaps.length;e++)h.__webglFramebuffer[e]=t.createFramebuffer()}else h.__webglFramebuffer=t.createFramebuffer();if(u&&n.drawBuffers){const i=e.texture;for(let e=0,n=i.length;e<n;e++){const n=s.get(i[e]);void 0===n.__webglTexture&&(n.__webglTexture=t.createTexture(),a.memory.textures++)}}if(o&&e.samples>0&&!1===k(e)){const s=u?l:[l];h.__webglMultisampledFramebuffer=t.createFramebuffer(),h.__webglColorRenderbuffer=[],i.bindFramebuffer(t.FRAMEBUFFER,h.__webglMultisampledFramebuffer);for(let i=0;i<s.length;i++){const n=s[i];h.__webglColorRenderbuffer[i]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,h.__webglColorRenderbuffer[i]);const a=r.convert(n.format,n.colorSpace),o=r.convert(n.type),l=T(n.internalFormat,a,o,n.colorSpace,!0===e.isXRRenderTarget),c=z(e);t.renderbufferStorageMultisample(t.RENDERBUFFER,c,l,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+i,t.RENDERBUFFER,h.__webglColorRenderbuffer[i])}t.bindRenderbuffer(t.RENDERBUFFER,null),e.depthBuffer&&(h.__webglDepthRenderbuffer=t.createRenderbuffer(),U(h.__webglDepthRenderbuffer,e,!0)),i.bindFramebuffer(t.FRAMEBUFFER,null)}}if(d){i.bindTexture(t.TEXTURE_CUBE_MAP,c.__webglTexture),I(t.TEXTURE_CUBE_MAP,l,f);for(let i=0;i<6;i++)if(o&&l.mipmaps&&l.mipmaps.length>0)for(let s=0;s<l.mipmaps.length;s++)F(h.__webglFramebuffer[i][s],e,l,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+i,s);else F(h.__webglFramebuffer[i],e,l,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+i,0);y(l,f)&&x(t.TEXTURE_CUBE_MAP),i.unbindTexture()}else if(u){const n=e.texture;for(let r=0,a=n.length;r<a;r++){const a=n[r],o=s.get(a);i.bindTexture(t.TEXTURE_2D,o.__webglTexture),I(t.TEXTURE_2D,a,f),F(h.__webglFramebuffer,e,a,t.COLOR_ATTACHMENT0+r,t.TEXTURE_2D,0),y(a,f)&&x(t.TEXTURE_2D)}i.unbindTexture()}else{let s=t.TEXTURE_2D;if((e.isWebGL3DRenderTarget||e.isWebGLArrayRenderTarget)&&o&&(s=e.isWebGL3DRenderTarget?t.TEXTURE_3D:t.TEXTURE_2D_ARRAY),i.bindTexture(s,c.__webglTexture),I(s,l,f),o&&l.mipmaps&&l.mipmaps.length>0)for(let i=0;i<l.mipmaps.length;i++)F(h.__webglFramebuffer[i],e,l,t.COLOR_ATTACHMENT0,s,i);else F(h.__webglFramebuffer,e,l,t.COLOR_ATTACHMENT0,s,0);y(l,f)&&x(s),i.unbindTexture()}e.depthBuffer&&B(e)},this.updateRenderTargetMipmap=function(e){const n=S(e)||o,r=!0===e.isWebGLMultipleRenderTargets?e.texture:[e.texture];for(let a=0,o=r.length;a<o;a++){const o=r[a];if(y(o,n)){const n=e.isWebGLCubeRenderTarget?t.TEXTURE_CUBE_MAP:t.TEXTURE_2D,r=s.get(o).__webglTexture;i.bindTexture(n,r),x(n),i.unbindTexture()}}},this.updateMultisampleRenderTarget=function(e){if(o&&e.samples>0&&!1===k(e)){const n=e.isWebGLMultipleRenderTargets?e.texture:[e.texture],r=e.width,a=e.height;let o=t.COLOR_BUFFER_BIT;const l=[],h=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,c=s.get(e),d=!0===e.isWebGLMultipleRenderTargets;if(d)for(let e=0;e<n.length;e++)i.bindFramebuffer(t.FRAMEBUFFER,c.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,null),i.bindFramebuffer(t.FRAMEBUFFER,c.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,null,0);i.bindFramebuffer(t.READ_FRAMEBUFFER,c.__webglMultisampledFramebuffer),i.bindFramebuffer(t.DRAW_FRAMEBUFFER,c.__webglFramebuffer);for(let i=0;i<n.length;i++){l.push(t.COLOR_ATTACHMENT0+i),e.depthBuffer&&l.push(h);const f=void 0!==c.__ignoreDepthValues&&c.__ignoreDepthValues;if(!1===f&&(e.depthBuffer&&(o|=t.DEPTH_BUFFER_BIT),e.stencilBuffer&&(o|=t.STENCIL_BUFFER_BIT)),d&&t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,c.__webglColorRenderbuffer[i]),!0===f&&(t.invalidateFramebuffer(t.READ_FRAMEBUFFER,[h]),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,[h])),d){const e=s.get(n[i]).__webglTexture;t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0)}t.blitFramebuffer(0,0,r,a,0,0,r,a,o,t.NEAREST),u&&t.invalidateFramebuffer(t.READ_FRAMEBUFFER,l)}if(i.bindFramebuffer(t.READ_FRAMEBUFFER,null),i.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),d)for(let e=0;e<n.length;e++){i.bindFramebuffer(t.FRAMEBUFFER,c.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,c.__webglColorRenderbuffer[e]);const r=s.get(n[e]).__webglTexture;i.bindFramebuffer(t.FRAMEBUFFER,c.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,r,0)}i.bindFramebuffer(t.DRAW_FRAMEBUFFER,c.__webglMultisampledFramebuffer)}},this.setupDepthRenderbuffer=B,this.setupFrameBufferTexture=F,this.useMultisampledRTT=k}function qB(t,e,i){const s=i.isWebGL2;return{convert:function(i,n=""){let r;const a=kI.getTransfer(n);if(i===ID)return t.UNSIGNED_BYTE;if(1017===i)return t.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return t.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return t.BYTE;if(1011===i)return t.SHORT;if(i===OD)return t.UNSIGNED_SHORT;if(i===ND)return t.INT;if(i===FD)return t.UNSIGNED_INT;if(i===UD)return t.FLOAT;if(i===BD)return s?t.HALF_FLOAT:(r=e.get("OES_texture_half_float"),null!==r?r.HALF_FLOAT_OES:null);if(1021===i)return t.ALPHA;if(i===kD)return t.RGBA;if(1024===i)return t.LUMINANCE;if(1025===i)return t.LUMINANCE_ALPHA;if(i===VD)return t.DEPTH_COMPONENT;if(i===HD)return t.DEPTH_STENCIL;if(i===pI)return r=e.get("EXT_sRGB"),null!==r?r.SRGB_ALPHA_EXT:null;if(1028===i)return t.RED;if(1029===i)return t.RED_INTEGER;if(1030===i)return t.RG;if(1031===i)return t.RG_INTEGER;if(1033===i)return t.RGBA_INTEGER;if(i===GD||i===WD||i===XD||i===YD)if(a===eI){if(r=e.get("WEBGL_compressed_texture_s3tc_srgb"),null===r)return null;if(i===GD)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===WD)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===XD)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===YD)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(r=e.get("WEBGL_compressed_texture_s3tc"),null===r)return null;if(i===GD)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===WD)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===XD)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===YD)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){if(r=e.get("WEBGL_compressed_texture_pvrtc"),null===r)return null;if(35840===i)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i)return r=e.get("WEBGL_compressed_texture_etc1"),null!==r?r.COMPRESSED_RGB_ETC1_WEBGL:null;if(37492===i||37496===i){if(r=e.get("WEBGL_compressed_texture_etc"),null===r)return null;if(37492===i)return a===eI?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(37496===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){if(r=e.get("WEBGL_compressed_texture_astc"),null===r)return null;if(37808===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}if(i===qD||36494===i||36495===i){if(r=e.get("EXT_texture_compression_bptc"),null===r)return null;if(i===qD)return a===eI?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(36494===i)return r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(36495===i)return r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}if(36283===i||36284===i||36285===i||36286===i){if(r=e.get("EXT_texture_compression_rgtc"),null===r)return null;if(i===qD)return r.COMPRESSED_RED_RGTC1_EXT;if(36284===i)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(36285===i)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(36286===i)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return i===zD?s?t.UNSIGNED_INT_24_8:(r=e.get("WEBGL_depth_texture"),null!==r?r.UNSIGNED_INT_24_8_WEBGL:null):void 0!==t[i]?t[i]:null}}}class jB extends dF{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class $B extends sN{constructor(){super(),this.isGroup=!0,this.type="Group"}}const KB={type:"move"};class ZB{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return null===this._hand&&(this._hand=new $B,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 $B,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new iO,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new iO),this._targetRay}getGripSpace(){return null===this._grip&&(this._grip=new $B,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new iO,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new iO),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 i of t.hand.values())this._getHandJoint(e,i)}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,i){let s=null,n=null,r=null;const a=this._targetRay,o=this._grip,l=this._hand;if(t&&"visible-blurred"!==e.session.visibilityState){if(l&&t.hand){r=!0;for(const s of t.hand.values()){const t=e.getJointPose(s,i),n=this._getHandJoint(l,s);null!==t&&(n.matrix.fromArray(t.transform.matrix),n.matrix.decompose(n.position,n.rotation,n.scale),n.matrixWorldNeedsUpdate=!0,n.jointRadius=t.radius),n.visible=null!==t}const s=l.joints["index-finger-tip"],n=l.joints["thumb-tip"],a=s.position.distanceTo(n.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&&(n=e.getPose(t.gripSpace,i),null!==n&&(o.matrix.fromArray(n.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,n.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(n.linearVelocity)):o.hasLinearVelocity=!1,n.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(n.angularVelocity)):o.hasAngularVelocity=!1));null!==a&&(s=e.getPose(t.targetRaySpace,i),null===s&&null!==n&&(s=n),null!==s&&(a.matrix.fromArray(s.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,s.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(s.linearVelocity)):a.hasLinearVelocity=!1,s.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(s.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(KB)))}return null!==a&&(a.visible=null!==s),null!==o&&(o.visible=null!==n),null!==l&&(l.visible=null!==r),this}_getHandJoint(t,e){if(void 0===t.joints[e.jointName]){const i=new $B;i.matrixAutoUpdate=!1,i.visible=!1,t.joints[e.jointName]=i,t.add(i)}return t.joints[e.jointName]}}class QB extends $I{constructor(t,e,i,s,n,r,a,o,l,h){if((h=void 0!==h?h:VD)!==VD&&h!==HD)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===i&&h===VD&&(i=FD),void 0===i&&h===HD&&(i=zD),super(null,s,n,r,a,o,h,i,l),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=void 0!==a?a:CD,this.minFilter=void 0!==o?o:CD,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 JB extends gI{constructor(t,e){super();const i=this;let s=null,n=1,r=null,a="local-floor",o=1,l=null,h=null,c=null,d=null,u=null,f=null;const p=e.getContextAttributes();let m=null,_=null;const g=[],v=[],S=new dF;S.layers.enable(1),S.viewport=new KI;const y=new dF;y.layers.enable(2),y.viewport=new KI;const x=[S,y],T=new jB;T.layers.enable(1),T.layers.enable(2);let E=null,b=null;function w(t){const e=v.indexOf(t.inputSource);if(-1===e)return;const i=g[e];void 0!==i&&(i.update(t.inputSource,t.frame,l||r),i.dispatchEvent({type:t.type,data:t.inputSource}))}function A(){s.removeEventListener("select",w),s.removeEventListener("selectstart",w),s.removeEventListener("selectend",w),s.removeEventListener("squeeze",w),s.removeEventListener("squeezestart",w),s.removeEventListener("squeezeend",w),s.removeEventListener("end",A),s.removeEventListener("inputsourceschange",C);for(let t=0;t<g.length;t++){const e=v[t];null!==e&&(v[t]=null,g[t].disconnect(e))}E=null,b=null,t.setRenderTarget(m),u=null,d=null,c=null,s=null,_=null,D.stop(),i.isPresenting=!1,i.dispatchEvent({type:"sessionend"})}function C(t){for(let e=0;e<t.removed.length;e++){const i=t.removed[e],s=v.indexOf(i);s>=0&&(v[s]=null,g[s].disconnect(i))}for(let e=0;e<t.added.length;e++){const i=t.added[e];let s=v.indexOf(i);if(-1===s){for(let t=0;t<g.length;t++){if(t>=v.length){v.push(i),s=t;break}if(null===v[t]){v[t]=i,s=t;break}}if(-1===s)break}const n=g[s];n&&n.connect(i)}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(t){let e=g[t];return void 0===e&&(e=new ZB,g[t]=e),e.getTargetRaySpace()},this.getControllerGrip=function(t){let e=g[t];return void 0===e&&(e=new ZB,g[t]=e),e.getGripSpace()},this.getHand=function(t){let e=g[t];return void 0===e&&(e=new ZB,g[t]=e),e.getHandSpace()},this.setFramebufferScaleFactor=function(t){n=t,i.isPresenting},this.setReferenceSpaceType=function(t){a=t,i.isPresenting},this.getReferenceSpace=function(){return l||r},this.setReferenceSpace=function(t){l=t},this.getBaseLayer=function(){return null!==d?d:u},this.getBinding=function(){return c},this.getFrame=function(){return f},this.getSession=function(){return s},this.setSession=async function(h){if(s=h,null!==s){if(m=t.getRenderTarget(),s.addEventListener("select",w),s.addEventListener("selectstart",w),s.addEventListener("selectend",w),s.addEventListener("squeeze",w),s.addEventListener("squeezestart",w),s.addEventListener("squeezeend",w),s.addEventListener("end",A),s.addEventListener("inputsourceschange",C),!0!==p.xrCompatible&&await e.makeXRCompatible(),void 0===s.renderState.layers||!1===t.capabilities.isWebGL2){const i={antialias:void 0!==s.renderState.layers||p.antialias,alpha:!0,depth:p.depth,stencil:p.stencil,framebufferScaleFactor:n};u=new XRWebGLLayer(s,e,i),s.updateRenderState({baseLayer:u}),_=new QI(u.framebufferWidth,u.framebufferHeight,{format:kD,type:ID,colorSpace:t.outputColorSpace,stencilBuffer:p.stencil})}else{let i=null,r=null,a=null;p.depth&&(a=p.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,i=p.stencil?HD:VD,r=p.stencil?zD:FD);const o={colorFormat:e.RGBA8,depthFormat:a,scaleFactor:n};c=new XRWebGLBinding(s,e),d=c.createProjectionLayer(o),s.updateRenderState({layers:[d]}),_=new QI(d.textureWidth,d.textureHeight,{format:kD,type:ID,depthTexture:new QB(d.textureWidth,d.textureHeight,r,void 0,void 0,void 0,void 0,void 0,void 0,i),stencilBuffer:p.stencil,colorSpace:t.outputColorSpace,samples:p.antialias?4:0});t.properties.get(_).__ignoreDepthValues=d.ignoreDepthValues}_.isXRRenderTarget=!0,this.setFoveation(o),l=null,r=await s.requestReferenceSpace(a),D.setContext(s),D.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(null!==s)return s.environmentBlendMode};const M=new iO,P=new iO;function R(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===s)return;T.near=y.near=S.near=t.near,T.far=y.far=S.far=t.far,E===T.near&&b===T.far||(s.updateRenderState({depthNear:T.near,depthFar:T.far}),E=T.near,b=T.far);const e=t.parent,i=T.cameras;R(T,e);for(let t=0;t<i.length;t++)R(i[t],e);2===i.length?function(t,e,i){M.setFromMatrixPosition(e.matrixWorld),P.setFromMatrixPosition(i.matrixWorld);const s=M.distanceTo(P),n=e.projectionMatrix.elements,r=i.projectionMatrix.elements,a=n[14]/(n[10]-1),o=n[14]/(n[10]+1),l=(n[9]+1)/n[5],h=(n[9]-1)/n[5],c=(n[8]-1)/n[0],d=(r[8]+1)/r[0],u=a*c,f=a*d,p=s/(-c+d),m=p*-c;e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.translateX(m),t.translateZ(p),t.matrixWorld.compose(t.position,t.quaternion,t.scale),t.matrixWorldInverse.copy(t.matrixWorld).invert();const _=a+p,g=o+p,v=u-m,S=f+(s-m),y=l*o/g*_,x=h*o/g*_;t.projectionMatrix.makePerspective(v,S,y,x,_,g),t.projectionMatrixInverse.copy(t.projectionMatrix).invert()}(T,S,y):T.projectionMatrix.copy(S.projectionMatrix),function(t,e,i){null===i?t.matrix.copy(e.matrixWorld):(t.matrix.copy(i.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*yI*Math.atan(1/t.projectionMatrix.elements[5]),t.zoom=1)}(t,T,e)},this.getCamera=function(){return T},this.getFoveation=function(){if(null!==d||null!==u)return o},this.setFoveation=function(t){o=t,null!==d&&(d.fixedFoveation=t),null!==u&&void 0!==u.fixedFoveation&&(u.fixedFoveation=t)};let L=null;const D=new EF;D.setAnimationLoop(function(e,s){if(h=s.getViewerPose(l||r),f=s,null!==h){const e=h.views;null!==u&&(t.setRenderTargetFramebuffer(_,u.framebuffer),t.setRenderTarget(_));let i=!1;e.length!==T.cameras.length&&(T.cameras.length=0,i=!0);for(let s=0;s<e.length;s++){const n=e[s];let r=null;if(null!==u)r=u.getViewport(n);else{const e=c.getViewSubImage(d,n);r=e.viewport,0===s&&(t.setRenderTargetTextures(_,e.colorTexture,d.ignoreDepthValues?void 0:e.depthStencilTexture),t.setRenderTarget(_))}let a=x[s];void 0===a&&(a=new dF,a.layers.enable(s),a.viewport=new KI,x[s]=a),a.matrix.fromArray(n.transform.matrix),a.matrix.decompose(a.position,a.quaternion,a.scale),a.projectionMatrix.fromArray(n.projectionMatrix),a.projectionMatrixInverse.copy(a.projectionMatrix).invert(),a.viewport.set(r.x,r.y,r.width,r.height),0===s&&(T.matrix.copy(a.matrix),T.matrix.decompose(T.position,T.quaternion,T.scale)),!0===i&&T.cameras.push(a)}}for(let t=0;t<g.length;t++){const e=v[t],i=g[t];null!==e&&void 0!==i&&i.update(e,s,l||r)}L&&L(e,s),s.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:s}),f=null}),this.setAnimationLoop=function(t){L=t},this.dispose=function(){}}}function tz(t,e){function i(t,e){!0===t.matrixAutoUpdate&&t.updateMatrix(),e.value.copy(t.matrix)}function s(s,n){s.opacity.value=n.opacity,n.color&&s.diffuse.value.copy(n.color),n.emissive&&s.emissive.value.copy(n.emissive).multiplyScalar(n.emissiveIntensity),n.map&&(s.map.value=n.map,i(n.map,s.mapTransform)),n.alphaMap&&(s.alphaMap.value=n.alphaMap,i(n.alphaMap,s.alphaMapTransform)),n.bumpMap&&(s.bumpMap.value=n.bumpMap,i(n.bumpMap,s.bumpMapTransform),s.bumpScale.value=n.bumpScale,1===n.side&&(s.bumpScale.value*=-1)),n.normalMap&&(s.normalMap.value=n.normalMap,i(n.normalMap,s.normalMapTransform),s.normalScale.value.copy(n.normalScale),1===n.side&&s.normalScale.value.negate()),n.displacementMap&&(s.displacementMap.value=n.displacementMap,i(n.displacementMap,s.displacementMapTransform),s.displacementScale.value=n.displacementScale,s.displacementBias.value=n.displacementBias),n.emissiveMap&&(s.emissiveMap.value=n.emissiveMap,i(n.emissiveMap,s.emissiveMapTransform)),n.specularMap&&(s.specularMap.value=n.specularMap,i(n.specularMap,s.specularMapTransform)),n.alphaTest>0&&(s.alphaTest.value=n.alphaTest);const r=e.get(n).envMap;if(r&&(s.envMap.value=r,s.flipEnvMap.value=r.isCubeTexture&&!1===r.isRenderTargetTexture?-1:1,s.reflectivity.value=n.reflectivity,s.ior.value=n.ior,s.refractionRatio.value=n.refractionRatio),n.lightMap){s.lightMap.value=n.lightMap;const e=!0===t._useLegacyLights?Math.PI:1;s.lightMapIntensity.value=n.lightMapIntensity*e,i(n.lightMap,s.lightMapTransform)}n.aoMap&&(s.aoMap.value=n.aoMap,s.aoMapIntensity.value=n.aoMapIntensity,i(n.aoMap,s.aoMapTransform))}return{refreshFogUniforms:function(e,i){i.color.getRGB(e.fogColor.value,oF(t)),i.isFog?(e.fogNear.value=i.near,e.fogFar.value=i.far):i.isFogExp2&&(e.fogDensity.value=i.density)},refreshMaterialUniforms:function(t,n,r,a,o){n.isMeshBasicMaterial||n.isMeshLambertMaterial?s(t,n):n.isMeshToonMaterial?(s(t,n),function(t,e){e.gradientMap&&(t.gradientMap.value=e.gradientMap)}(t,n)):n.isMeshPhongMaterial?(s(t,n),function(t,e){t.specular.value.copy(e.specular),t.shininess.value=Math.max(e.shininess,1e-4)}(t,n)):n.isMeshStandardMaterial?(s(t,n),function(t,s){t.metalness.value=s.metalness,s.metalnessMap&&(t.metalnessMap.value=s.metalnessMap,i(s.metalnessMap,t.metalnessMapTransform));t.roughness.value=s.roughness,s.roughnessMap&&(t.roughnessMap.value=s.roughnessMap,i(s.roughnessMap,t.roughnessMapTransform));const n=e.get(s).envMap;n&&(t.envMapIntensity.value=s.envMapIntensity)}(t,n),n.isMeshPhysicalMaterial&&function(t,e,s){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,i(e.sheenColorMap,t.sheenColorMapTransform)),e.sheenRoughnessMap&&(t.sheenRoughnessMap.value=e.sheenRoughnessMap,i(e.sheenRoughnessMap,t.sheenRoughnessMapTransform)));e.clearcoat>0&&(t.clearcoat.value=e.clearcoat,t.clearcoatRoughness.value=e.clearcoatRoughness,e.clearcoatMap&&(t.clearcoatMap.value=e.clearcoatMap,i(e.clearcoatMap,t.clearcoatMapTransform)),e.clearcoatRoughnessMap&&(t.clearcoatRoughnessMap.value=e.clearcoatRoughnessMap,i(e.clearcoatRoughnessMap,t.clearcoatRoughnessMapTransform)),e.clearcoatNormalMap&&(t.clearcoatNormalMap.value=e.clearcoatNormalMap,i(e.clearcoatNormalMap,t.clearcoatNormalMapTransform),t.clearcoatNormalScale.value.copy(e.clearcoatNormalScale),1===e.side&&t.clearcoatNormalScale.value.negate()));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,i(e.iridescenceMap,t.iridescenceMapTransform)),e.iridescenceThicknessMap&&(t.iridescenceThicknessMap.value=e.iridescenceThicknessMap,i(e.iridescenceThicknessMap,t.iridescenceThicknessMapTransform)));e.transmission>0&&(t.transmission.value=e.transmission,t.transmissionSamplerMap.value=s.texture,t.transmissionSamplerSize.value.set(s.width,s.height),e.transmissionMap&&(t.transmissionMap.value=e.transmissionMap,i(e.transmissionMap,t.transmissionMapTransform)),t.thickness.value=e.thickness,e.thicknessMap&&(t.thicknessMap.value=e.thicknessMap,i(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,i(e.anisotropyMap,t.anisotropyMapTransform)));t.specularIntensity.value=e.specularIntensity,t.specularColor.value.copy(e.specularColor),e.specularColorMap&&(t.specularColorMap.value=e.specularColorMap,i(e.specularColorMap,t.specularColorMapTransform));e.specularIntensityMap&&(t.specularIntensityMap.value=e.specularIntensityMap,i(e.specularIntensityMap,t.specularIntensityMapTransform))}(t,n,o)):n.isMeshMatcapMaterial?(s(t,n),function(t,e){e.matcap&&(t.matcap.value=e.matcap)}(t,n)):n.isMeshDepthMaterial?s(t,n):n.isMeshDistanceMaterial?(s(t,n),function(t,i){const s=e.get(i).light;t.referencePosition.value.setFromMatrixPosition(s.matrixWorld),t.nearDistance.value=s.shadow.camera.near,t.farDistance.value=s.shadow.camera.far}(t,n)):n.isMeshNormalMaterial?s(t,n):n.isLineBasicMaterial?(function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,e.map&&(t.map.value=e.map,i(e.map,t.mapTransform))}(t,n),n.isLineDashedMaterial&&function(t,e){t.dashSize.value=e.dashSize,t.totalSize.value=e.dashSize+e.gapSize,t.scale.value=e.scale}(t,n)):n.isPointsMaterial?function(t,e,s,n){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.size.value=e.size*s,t.scale.value=.5*n,e.map&&(t.map.value=e.map,i(e.map,t.uvTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,i(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,n,r,a):n.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,i(e.map,t.mapTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,i(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,n):n.isShadowMaterial?(t.color.value.copy(n.color),t.opacity.value=n.opacity):n.isShaderMaterial&&(n.uniformsNeedUpdate=!1)}}}function ez(t,e,i,s){let n={},r={},a=[];const o=i.isWebGL2?t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS):0;function l(t,e,i){const s=t.value;if(void 0===i[e]){if("number"==typeof s)i[e]=s;else{const t=Array.isArray(s)?s:[s],n=[];for(let e=0;e<t.length;e++)n.push(t[e].clone());i[e]=n}return!0}if("number"==typeof s){if(i[e]!==s)return i[e]=s,!0}else{const t=Array.isArray(i[e])?i[e]:[i[e]],n=Array.isArray(s)?s:[s];for(let e=0;e<t.length;e++){const i=t[e];if(!1===i.equals(n[e]))return i.copy(n[e]),!0}}return!1}function h(t){const e={boundary:0,storage:0};return"number"==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,e}function c(e){const i=e.target;i.removeEventListener("dispose",c);const s=a.indexOf(i.__bindingPointIndex);a.splice(s,1),t.deleteBuffer(n[i.id]),delete n[i.id],delete r[i.id]}return{bind:function(t,e){const i=e.program;s.uniformBlockBinding(t,i)},update:function(i,d){let u=n[i.id];void 0===u&&(!function(t){const e=t.uniforms;let i=0;const s=16;let n=0;for(let t=0,r=e.length;t<r;t++){const r=e[t],a={boundary:0,storage:0},o=Array.isArray(r.value)?r.value:[r.value];for(let t=0,e=o.length;t<e;t++){const e=h(o[t]);a.boundary+=e.boundary,a.storage+=e.storage}if(r.__data=new Float32Array(a.storage/Float32Array.BYTES_PER_ELEMENT),r.__offset=i,t>0){n=i%s;0!==n&&s-n-a.boundary<0&&(i+=s-n,r.__offset=i)}i+=a.storage}n=i%s,n>0&&(i+=s-n);t.__size=i,t.__cache={}}(i),u=function(e){const i=function(){for(let t=0;t<o;t++)if(-1===a.indexOf(t))return a.push(t),t;return 0}();e.__bindingPointIndex=i;const s=t.createBuffer(),n=e.__size,r=e.usage;return t.bindBuffer(t.UNIFORM_BUFFER,s),t.bufferData(t.UNIFORM_BUFFER,n,r),t.bindBuffer(t.UNIFORM_BUFFER,null),t.bindBufferBase(t.UNIFORM_BUFFER,i,s),s}(i),n[i.id]=u,i.addEventListener("dispose",c));const f=d.program;s.updateUBOMapping(i,f);const p=e.render.frame;r[i.id]!==p&&(!function(e){const i=n[e.id],s=e.uniforms,r=e.__cache;t.bindBuffer(t.UNIFORM_BUFFER,i);for(let e=0,i=s.length;e<i;e++){const i=s[e];if(!0===l(i,e,r)){const e=i.__offset,s=Array.isArray(i.value)?i.value:[i.value];let n=0;for(let r=0;r<s.length;r++){const a=s[r],o=h(a);"number"==typeof a?(i.__data[0]=a,t.bufferSubData(t.UNIFORM_BUFFER,e+n,i.__data)):a.isMatrix3?(i.__data[0]=a.elements[0],i.__data[1]=a.elements[1],i.__data[2]=a.elements[2],i.__data[3]=a.elements[0],i.__data[4]=a.elements[3],i.__data[5]=a.elements[4],i.__data[6]=a.elements[5],i.__data[7]=a.elements[0],i.__data[8]=a.elements[6],i.__data[9]=a.elements[7],i.__data[10]=a.elements[8],i.__data[11]=a.elements[0]):(a.toArray(i.__data,n),n+=o.storage/Float32Array.BYTES_PER_ELEMENT)}t.bufferSubData(t.UNIFORM_BUFFER,e,i.__data)}}t.bindBuffer(t.UNIFORM_BUFFER,null)}(i),r[i.id]=p)},dispose:function(){for(const e in n)t.deleteBuffer(n[e]);a=[],n={},r={}}}}class iz{constructor(t={}){const{canvas:e=II(),context:i=null,depth:s=!0,stencil:n=!0,alpha:r=!1,antialias:a=!1,premultipliedAlpha:o=!0,preserveDrawingBuffer:l=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:c=!1}=t;let d;this.isWebGLRenderer=!0,d=null!==i?i.getContextAttributes().alpha:r;const u=new Uint32Array(4),f=new Int32Array(4);let p=null,m=null;const _=[],g=[];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=KD,this._useLegacyLights=!1,this.toneMapping=0,this.toneMappingExposure=1;const v=this;let S=!1,y=0,x=0,T=null,E=-1,b=null;const w=new KI,A=new KI;let C=null;const M=new TN(0);let P=0,R=e.width,L=e.height,D=1,I=null,O=null;const N=new KI(0,0,R,L),F=new KI(0,0,R,L);let U=!1;const B=new TF;let z=!1,k=!1,V=null;const H=new DO,G=new MI,W=new iO,X={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};function Y(){return null===T?D:1}let q,j,$,K,Z,Q,J,tt,et,it,st,nt,rt,at,ot,lt,ht,ct,dt,ut,ft,pt,mt,_t,gt=i;function vt(t,i){for(let s=0;s<t.length;s++){const n=t[s],r=e.getContext(n,i);if(null!==r)return r}return null}try{const t={alpha:!0,depth:s,stencil:n,antialias:a,premultipliedAlpha:o,preserveDrawingBuffer:l,powerPreference:h,failIfMajorPerformanceCaveat:c};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${sD}`),e.addEventListener("webglcontextlost",xt,!1),e.addEventListener("webglcontextrestored",Tt,!1),e.addEventListener("webglcontextcreationerror",Et,!1),null===gt){const e=["webgl2","webgl","experimental-webgl"];if(!0===v.isWebGL1Renderer&&e.shift(),gt=vt(e,t),null===gt)throw vt(e)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}"undefined"!=typeof WebGLRenderingContext&&WebGLRenderingContext,void 0===gt.getShaderPrecisionFormat&&(gt.getShaderPrecisionFormat=function(){return{rangeMin:1,rangeMax:1,precision:1}})}catch(t){throw t}function St(){q=new QF(gt),j=new IF(gt,q,t),q.init(j),pt=new qB(gt,q,j),$=new XB(gt,q,j),K=new eU(gt),Z=new LB,Q=new YB(gt,q,$,Z,j,pt,K),J=new NF(v),tt=new ZF(v),et=new bF(gt,j),mt=new LF(gt,q,et,j),it=new JF(gt,et,K,mt),st=new rU(gt,it,et,K),dt=new nU(gt,j,Q),lt=new OF(Z),nt=new RB(v,J,tt,q,j,mt,lt),rt=new tz(v,Z),at=new NB,ot=new VB(q,j),ct=new RF(v,J,tt,$,st,d,o),ht=new WB(v,st,j),_t=new ez(gt,K,j,$),ut=new DF(gt,q,K,j),ft=new tU(gt,q,K,j),K.programs=nt.programs,v.capabilities=j,v.extensions=q,v.properties=Z,v.renderLists=at,v.shadowMap=ht,v.state=$,v.info=K}St();const yt=new JB(v,gt);function xt(t){t.preventDefault(),S=!0}function Tt(){S=!1;const t=K.autoReset,e=ht.enabled,i=ht.autoUpdate,s=ht.needsUpdate,n=ht.type;St(),K.autoReset=t,ht.enabled=e,ht.autoUpdate=i,ht.needsUpdate=s,ht.type=n}function Et(t){}function bt(t){const e=t.target;e.removeEventListener("dispose",bt),function(t){(function(t){const e=Z.get(t).programs;void 0!==e&&(e.forEach(function(t){nt.releaseProgram(t)}),t.isShaderMaterial&&nt.releaseShaderCache(t))})(t),Z.remove(t)}(e)}this.xr=yt,this.getContext=function(){return gt},this.getContextAttributes=function(){return gt.getContextAttributes()},this.forceContextLoss=function(){const t=q.get("WEBGL_lose_context");t&&t.loseContext()},this.forceContextRestore=function(){const t=q.get("WEBGL_lose_context");t&&t.restoreContext()},this.getPixelRatio=function(){return D},this.setPixelRatio=function(t){void 0!==t&&(D=t,this.setSize(R,L,!1))},this.getSize=function(t){return t.set(R,L)},this.setSize=function(t,i,s=!0){yt.isPresenting||(R=t,L=i,e.width=Math.floor(t*D),e.height=Math.floor(i*D),!0===s&&(e.style.width=t+"px",e.style.height=i+"px"),this.setViewport(0,0,t,i))},this.getDrawingBufferSize=function(t){return t.set(R*D,L*D).floor()},this.setDrawingBufferSize=function(t,i,s){R=t,L=i,D=s,e.width=Math.floor(t*s),e.height=Math.floor(i*s),this.setViewport(0,0,t,i)},this.getCurrentViewport=function(t){return t.copy(w)},this.getViewport=function(t){return t.copy(N)},this.setViewport=function(t,e,i,s){t.isVector4?N.set(t.x,t.y,t.z,t.w):N.set(t,e,i,s),$.viewport(w.copy(N).multiplyScalar(D).floor())},this.getScissor=function(t){return t.copy(F)},this.setScissor=function(t,e,i,s){t.isVector4?F.set(t.x,t.y,t.z,t.w):F.set(t,e,i,s),$.scissor(A.copy(F).multiplyScalar(D).floor())},this.getScissorTest=function(){return U},this.setScissorTest=function(t){$.setScissorTest(U=t)},this.setOpaqueSort=function(t){I=t},this.setTransparentSort=function(t){O=t},this.getClearColor=function(t){return t.copy(ct.getClearColor())},this.setClearColor=function(){ct.setClearColor.apply(ct,arguments)},this.getClearAlpha=function(){return ct.getClearAlpha()},this.setClearAlpha=function(){ct.setClearAlpha.apply(ct,arguments)},this.clear=function(t=!0,e=!0,i=!0){let s=0;if(t){let t=!1;if(null!==T){const e=T.texture.format;t=1033===e||1031===e||1029===e}if(t){const t=T.texture.type,e=t===ID||t===FD||t===OD||t===zD||1017===t||1018===t,i=ct.getClearColor(),s=ct.getClearAlpha(),n=i.r,r=i.g,a=i.b;e?(u[0]=n,u[1]=r,u[2]=a,u[3]=s,gt.clearBufferuiv(gt.COLOR,0,u)):(f[0]=n,f[1]=r,f[2]=a,f[3]=s,gt.clearBufferiv(gt.COLOR,0,f))}else s|=gt.COLOR_BUFFER_BIT}e&&(s|=gt.DEPTH_BUFFER_BIT),i&&(s|=gt.STENCIL_BUFFER_BIT),gt.clear(s)},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",xt,!1),e.removeEventListener("webglcontextrestored",Tt,!1),e.removeEventListener("webglcontextcreationerror",Et,!1),at.dispose(),ot.dispose(),Z.dispose(),J.dispose(),tt.dispose(),st.dispose(),mt.dispose(),_t.dispose(),nt.dispose(),yt.dispose(),yt.removeEventListener("sessionstart",At),yt.removeEventListener("sessionend",Ct),V&&(V.dispose(),V=null),Mt.stop()},this.renderBufferDirect=function(t,e,i,s,n,r){null===e&&(e=X);const a=n.isMesh&&n.matrixWorld.determinant()<0,o=function(t,e,i,s,n){!0!==e.isScene&&(e=X);Q.resetTextureUnits();const r=e.fog,a=s.isMeshStandardMaterial?e.environment:null,o=null===T?v.outputColorSpace:!0===T.isXRRenderTarget?T.texture.colorSpace:ZD,l=(s.isMeshStandardMaterial?tt:J).get(s.envMap||a),h=!0===s.vertexColors&&!!i.attributes.color&&4===i.attributes.color.itemSize,c=!!i.attributes.tangent&&(!!s.normalMap||s.anisotropy>0),d=!!i.morphAttributes.position,u=!!i.morphAttributes.normal,f=!!i.morphAttributes.color;let p=0;s.toneMapped&&(null!==T&&!0!==T.isXRRenderTarget||(p=v.toneMapping));const _=i.morphAttributes.position||i.morphAttributes.normal||i.morphAttributes.color,g=void 0!==_?_.length:0,S=Z.get(s),y=m.state.lights;if(!0===z&&(!0===k||t!==b)){const e=t===b&&s.id===E;lt.setState(s,t,e)}let x=!1;s.version===S.__version?S.needsLights&&S.lightsStateVersion!==y.state.version||S.outputColorSpace!==o||n.isInstancedMesh&&!1===S.instancing?x=!0:n.isInstancedMesh||!0!==S.instancing?n.isSkinnedMesh&&!1===S.skinning?x=!0:n.isSkinnedMesh||!0!==S.skinning?n.isInstancedMesh&&!0===S.instancingColor&&null===n.instanceColor||n.isInstancedMesh&&!1===S.instancingColor&&null!==n.instanceColor||S.envMap!==l||!0===s.fog&&S.fog!==r?x=!0:void 0===S.numClippingPlanes||S.numClippingPlanes===lt.numPlanes&&S.numIntersection===lt.numIntersection?(S.vertexAlphas!==h||S.vertexTangents!==c||S.morphTargets!==d||S.morphNormals!==u||S.morphColors!==f||S.toneMapping!==p||!0===j.isWebGL2&&S.morphTargetsCount!==g)&&(x=!0):x=!0:x=!0:x=!0:(x=!0,S.__version=s.version);let w=S.currentProgram;!0===x&&(w=It(s,e,n));let A=!1,C=!1,M=!1;const P=w.getUniforms(),R=S.uniforms;$.useProgram(w.program)&&(A=!0,C=!0,M=!0);s.id!==E&&(E=s.id,C=!0);if(A||b!==t){P.setValue(gt,"projectionMatrix",t.projectionMatrix),P.setValue(gt,"viewMatrix",t.matrixWorldInverse);const e=P.map.cameraPosition;void 0!==e&&e.setValue(gt,W.setFromMatrixPosition(t.matrixWorld)),j.logarithmicDepthBuffer&&P.setValue(gt,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),(s.isMeshPhongMaterial||s.isMeshToonMaterial||s.isMeshLambertMaterial||s.isMeshBasicMaterial||s.isMeshStandardMaterial||s.isShaderMaterial)&&P.setValue(gt,"isOrthographic",!0===t.isOrthographicCamera),b!==t&&(b=t,C=!0,M=!0)}if(n.isSkinnedMesh){P.setOptional(gt,n,"bindMatrix"),P.setOptional(gt,n,"bindMatrixInverse");const t=n.skeleton;t&&j.floatVertexTextures&&(null===t.boneTexture&&t.computeBoneTexture(),P.setValue(gt,"boneTexture",t.boneTexture,Q),P.setValue(gt,"boneTextureSize",t.boneTextureSize))}const I=i.morphAttributes;(void 0!==I.position||void 0!==I.normal||void 0!==I.color&&!0===j.isWebGL2)&&dt.update(n,i,w);(C||S.receiveShadow!==n.receiveShadow)&&(S.receiveShadow=n.receiveShadow,P.setValue(gt,"receiveShadow",n.receiveShadow));s.isMeshGouraudMaterial&&null!==s.envMap&&(R.envMap.value=l,R.flipEnvMap.value=l.isCubeTexture&&!1===l.isRenderTargetTexture?-1:1);C&&(P.setValue(gt,"toneMappingExposure",v.toneMappingExposure),S.needsLights&&(N=M,(O=R).ambientLightColor.needsUpdate=N,O.lightProbe.needsUpdate=N,O.directionalLights.needsUpdate=N,O.directionalLightShadows.needsUpdate=N,O.pointLights.needsUpdate=N,O.pointLightShadows.needsUpdate=N,O.spotLights.needsUpdate=N,O.spotLightShadows.needsUpdate=N,O.rectAreaLights.needsUpdate=N,O.hemisphereLights.needsUpdate=N),r&&!0===s.fog&&rt.refreshFogUniforms(R,r),rt.refreshMaterialUniforms(R,s,D,L,V),hB.upload(gt,S.uniformsList,R,Q));var O,N;s.isShaderMaterial&&!0===s.uniformsNeedUpdate&&(hB.upload(gt,S.uniformsList,R,Q),s.uniformsNeedUpdate=!1);s.isSpriteMaterial&&P.setValue(gt,"center",n.center);if(P.setValue(gt,"modelViewMatrix",n.modelViewMatrix),P.setValue(gt,"normalMatrix",n.normalMatrix),P.setValue(gt,"modelMatrix",n.matrixWorld),s.isShaderMaterial||s.isRawShaderMaterial){const t=s.uniformsGroups;for(let e=0,i=t.length;e<i;e++)if(j.isWebGL2){const i=t[e];_t.update(i,w),_t.bind(i,w)}}return w}(t,e,i,s,n);$.setMaterial(s,a);let l=i.index,h=1;if(!0===s.wireframe){if(l=it.getWireframeAttribute(i),void 0===l)return;h=2}const c=i.drawRange,d=i.attributes.position;let u=c.start*h,f=(c.start+c.count)*h;null!==r&&(u=Math.max(u,r.start*h),f=Math.min(f,(r.start+r.count)*h)),null!==l?(u=Math.max(u,0),f=Math.min(f,l.count)):null!=d&&(u=Math.max(u,0),f=Math.min(f,d.count));const p=f-u;if(p<0||p===1/0)return;let _;mt.setup(n,s,o,i,l);let g=ut;if(null!==l&&(_=et.get(l),g=ft,g.setIndex(_)),n.isMesh)!0===s.wireframe?($.setLineWidth(s.wireframeLinewidth*Y()),g.setMode(gt.LINES)):g.setMode(gt.TRIANGLES);else if(n.isLine){let t=s.linewidth;void 0===t&&(t=1),$.setLineWidth(t*Y()),n.isLineSegments?g.setMode(gt.LINES):n.isLineLoop?g.setMode(gt.LINE_LOOP):g.setMode(gt.LINE_STRIP)}else n.isPoints?g.setMode(gt.POINTS):n.isSprite&&g.setMode(gt.TRIANGLES);if(n.isInstancedMesh)g.renderInstances(u,p,n.count);else if(i.isInstancedBufferGeometry){const t=void 0!==i._maxInstanceCount?i._maxInstanceCount:1/0,e=Math.min(i.instanceCount,t);g.renderInstances(u,p,e)}else g.render(u,p)},this.compile=function(t,e){function i(t,e,i){!0===t.transparent&&2===t.side&&!1===t.forceSinglePass?(t.side=1,t.needsUpdate=!0,It(t,e,i),t.side=0,t.needsUpdate=!0,It(t,e,i),t.side=2):It(t,e,i)}m=ot.get(t),m.init(),g.push(m),t.traverseVisible(function(t){t.isLight&&t.layers.test(e.layers)&&(m.pushLight(t),t.castShadow&&m.pushShadow(t))}),m.setupLights(v._useLegacyLights),t.traverse(function(e){const s=e.material;if(s)if(Array.isArray(s))for(let n=0;n<s.length;n++){i(s[n],t,e)}else i(s,t,e)}),g.pop(),m=null};let wt=null;function At(){Mt.stop()}function Ct(){Mt.start()}const Mt=new EF;function Pt(t,e,i,s){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)i=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)m.pushLight(t),t.castShadow&&m.pushShadow(t);else if(t.isSprite){if(!t.frustumCulled||B.intersectsSprite(t)){s&&W.setFromMatrixPosition(t.matrixWorld).applyMatrix4(H);const e=st.update(t),n=t.material;n.visible&&p.push(t,e,n,i,W.z,null)}}else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||B.intersectsObject(t))){const e=st.update(t),n=t.material;if(s&&(void 0!==t.boundingSphere?(null===t.boundingSphere&&t.computeBoundingSphere(),W.copy(t.boundingSphere.center)):(null===e.boundingSphere&&e.computeBoundingSphere(),W.copy(e.boundingSphere.center)),W.applyMatrix4(t.matrixWorld).applyMatrix4(H)),Array.isArray(n)){const s=e.groups;for(let r=0,a=s.length;r<a;r++){const a=s[r],o=n[a.materialIndex];o&&o.visible&&p.push(t,e,o,i,W.z,a)}}else n.visible&&p.push(t,e,n,i,W.z,null)}const n=t.children;for(let t=0,r=n.length;t<r;t++)Pt(n[t],e,i,s)}function Rt(t,e,i,s){const n=t.opaque,r=t.transmissive,a=t.transparent;m.setupLightsView(i),!0===z&<.setGlobalState(v.clippingPlanes,i),r.length>0&&function(t,e,i,s){const n=j.isWebGL2;null===V&&(V=new QI(1,1,{generateMipmaps:!0,type:q.has("EXT_color_buffer_half_float")?BD:ID,minFilter:DD,samples:n?4:0}));v.getDrawingBufferSize(G),n?V.setSize(G.x,G.y):V.setSize(wI(G.x),wI(G.y));const r=v.getRenderTarget();v.setRenderTarget(V),v.getClearColor(M),P=v.getClearAlpha(),P<1&&v.setClearColor(16777215,.5);v.clear();const a=v.toneMapping;v.toneMapping=0,Lt(t,i,s),Q.updateMultisampleRenderTarget(V),Q.updateRenderTargetMipmap(V);let o=!1;for(let t=0,n=e.length;t<n;t++){const n=e[t],r=n.object,a=n.geometry,l=n.material,h=n.group;if(2===l.side&&r.layers.test(s.layers)){const t=l.side;l.side=1,l.needsUpdate=!0,Dt(r,i,s,a,l,h),l.side=t,l.needsUpdate=!0,o=!0}}!0===o&&(Q.updateMultisampleRenderTarget(V),Q.updateRenderTargetMipmap(V));v.setRenderTarget(r),v.setClearColor(M,P),v.toneMapping=a}(n,r,e,i),s&&$.viewport(w.copy(s)),n.length>0&&Lt(n,e,i),r.length>0&&Lt(r,e,i),a.length>0&&Lt(a,e,i),$.buffers.depth.setTest(!0),$.buffers.depth.setMask(!0),$.buffers.color.setMask(!0),$.setPolygonOffset(!1)}function Lt(t,e,i){const s=!0===e.isScene?e.overrideMaterial:null;for(let n=0,r=t.length;n<r;n++){const r=t[n],a=r.object,o=r.geometry,l=null===s?r.material:s,h=r.group;a.layers.test(i.layers)&&Dt(a,e,i,o,l,h)}}function Dt(t,e,i,s,n,r){t.onBeforeRender(v,e,i,s,n,r),t.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix),n.onBeforeRender(v,e,i,s,t,r),!0===n.transparent&&2===n.side&&!1===n.forceSinglePass?(n.side=1,n.needsUpdate=!0,v.renderBufferDirect(i,e,s,n,t,r),n.side=0,n.needsUpdate=!0,v.renderBufferDirect(i,e,s,n,t,r),n.side=2):v.renderBufferDirect(i,e,s,n,t,r),t.onAfterRender(v,e,i,s,n,r)}function It(t,e,i){!0!==e.isScene&&(e=X);const s=Z.get(t),n=m.state.lights,r=m.state.shadowsArray,a=n.state.version,o=nt.getParameters(t,n.state,r,e,i),l=nt.getProgramCacheKey(o);let h=s.programs;s.environment=t.isMeshStandardMaterial?e.environment:null,s.fog=e.fog,s.envMap=(t.isMeshStandardMaterial?tt:J).get(t.envMap||s.environment),void 0===h&&(t.addEventListener("dispose",bt),h=new Map,s.programs=h);let c=h.get(l);if(void 0!==c){if(s.currentProgram===c&&s.lightsStateVersion===a)return Ot(t,o),c}else o.uniforms=nt.getUniforms(t),t.onBuild(i,o,v),t.onBeforeCompile(o,v),c=nt.acquireProgram(o,l),h.set(l,c),s.uniforms=o.uniforms;const d=s.uniforms;(t.isShaderMaterial||t.isRawShaderMaterial)&&!0!==t.clipping||(d.clippingPlanes=lt.uniform),Ot(t,o),s.needsLights=function(t){return t.isMeshLambertMaterial||t.isMeshToonMaterial||t.isMeshPhongMaterial||t.isMeshStandardMaterial||t.isShadowMaterial||t.isShaderMaterial&&!0===t.lights}(t),s.lightsStateVersion=a,s.needsLights&&(d.ambientLightColor.value=n.state.ambient,d.lightProbe.value=n.state.probe,d.directionalLights.value=n.state.directional,d.directionalLightShadows.value=n.state.directionalShadow,d.spotLights.value=n.state.spot,d.spotLightShadows.value=n.state.spotShadow,d.rectAreaLights.value=n.state.rectArea,d.ltc_1.value=n.state.rectAreaLTC1,d.ltc_2.value=n.state.rectAreaLTC2,d.pointLights.value=n.state.point,d.pointLightShadows.value=n.state.pointShadow,d.hemisphereLights.value=n.state.hemi,d.directionalShadowMap.value=n.state.directionalShadowMap,d.directionalShadowMatrix.value=n.state.directionalShadowMatrix,d.spotShadowMap.value=n.state.spotShadowMap,d.spotLightMatrix.value=n.state.spotLightMatrix,d.spotLightMap.value=n.state.spotLightMap,d.pointShadowMap.value=n.state.pointShadowMap,d.pointShadowMatrix.value=n.state.pointShadowMatrix);const u=c.getUniforms(),f=hB.seqWithValue(u.seq,d);return s.currentProgram=c,s.uniformsList=f,c}function Ot(t,e){const i=Z.get(t);i.outputColorSpace=e.outputColorSpace,i.instancing=e.instancing,i.instancingColor=e.instancingColor,i.skinning=e.skinning,i.morphTargets=e.morphTargets,i.morphNormals=e.morphNormals,i.morphColors=e.morphColors,i.morphTargetsCount=e.morphTargetsCount,i.numClippingPlanes=e.numClippingPlanes,i.numIntersection=e.numClipIntersection,i.vertexAlphas=e.vertexAlphas,i.vertexTangents=e.vertexTangents,i.toneMapping=e.toneMapping}Mt.setAnimationLoop(function(t){wt&&wt(t)}),"undefined"!=typeof self&&Mt.setContext(self),this.setAnimationLoop=function(t){wt=t,yt.setAnimationLoop(t),null===t?Mt.stop():Mt.start()},yt.addEventListener("sessionstart",At),yt.addEventListener("sessionend",Ct),this.render=function(t,e){if(void 0!==e&&!0!==e.isCamera)return;if(!0===S)return;!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld(),null===e.parent&&!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),!0===yt.enabled&&!0===yt.isPresenting&&(!0===yt.cameraAutoUpdate&&yt.updateCamera(e),e=yt.getCamera()),!0===t.isScene&&t.onBeforeRender(v,t,e,T),m=ot.get(t,g.length),m.init(),g.push(m),H.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),B.setFromProjectionMatrix(H),k=this.localClippingEnabled,z=lt.init(this.clippingPlanes,k),p=at.get(t,_.length),p.init(),_.push(p),Pt(t,e,0,v.sortObjects),p.finish(),!0===v.sortObjects&&p.sort(I,O),this.info.render.frame++,!0===z&<.beginShadows();const i=m.state.shadowsArray;if(ht.render(i,t,e),!0===z&<.endShadows(),!0===this.info.autoReset&&this.info.reset(),ct.render(p,t),m.setupLights(v._useLegacyLights),e.isArrayCamera){const i=e.cameras;for(let e=0,s=i.length;e<s;e++){const s=i[e];Rt(p,t,s,s.viewport)}}else Rt(p,t,e);null!==T&&(Q.updateMultisampleRenderTarget(T),Q.updateRenderTargetMipmap(T)),!0===t.isScene&&t.onAfterRender(v,t,e),mt.resetDefaultState(),E=-1,b=null,g.pop(),m=g.length>0?g[g.length-1]:null,_.pop(),p=_.length>0?_[_.length-1]:null},this.getActiveCubeFace=function(){return y},this.getActiveMipmapLevel=function(){return x},this.getRenderTarget=function(){return T},this.setRenderTargetTextures=function(t,e,i){Z.get(t.texture).__webglTexture=e,Z.get(t.depthTexture).__webglTexture=i;const s=Z.get(t);s.__hasExternalTextures=!0,s.__hasExternalTextures&&(s.__autoAllocateDepthBuffer=void 0===i,s.__autoAllocateDepthBuffer||!0===q.has("WEBGL_multisampled_render_to_texture")&&(s.__useRenderToTexture=!1))},this.setRenderTargetFramebuffer=function(t,e){const i=Z.get(t);i.__webglFramebuffer=e,i.__useDefaultFramebuffer=void 0===e},this.setRenderTarget=function(t,e=0,i=0){T=t,y=e,x=i;let s=!0,n=null,r=!1,a=!1;if(t){const o=Z.get(t);void 0!==o.__useDefaultFramebuffer?($.bindFramebuffer(gt.FRAMEBUFFER,null),s=!1):void 0===o.__webglFramebuffer?Q.setupRenderTarget(t):o.__hasExternalTextures&&Q.rebindTextures(t,Z.get(t.texture).__webglTexture,Z.get(t.depthTexture).__webglTexture);const l=t.texture;(l.isData3DTexture||l.isDataArrayTexture||l.isCompressedArrayTexture)&&(a=!0);const h=Z.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(n=Array.isArray(h[e])?h[e][i]:h[e],r=!0):n=j.isWebGL2&&t.samples>0&&!1===Q.useMultisampledRTT(t)?Z.get(t).__webglMultisampledFramebuffer:Array.isArray(h)?h[i]:h,w.copy(t.viewport),A.copy(t.scissor),C=t.scissorTest}else w.copy(N).multiplyScalar(D).floor(),A.copy(F).multiplyScalar(D).floor(),C=U;if($.bindFramebuffer(gt.FRAMEBUFFER,n)&&j.drawBuffers&&s&&$.drawBuffers(t,n),$.viewport(w),$.scissor(A),$.setScissorTest(C),r){const s=Z.get(t.texture);gt.framebufferTexture2D(gt.FRAMEBUFFER,gt.COLOR_ATTACHMENT0,gt.TEXTURE_CUBE_MAP_POSITIVE_X+e,s.__webglTexture,i)}else if(a){const s=Z.get(t.texture),n=e||0;gt.framebufferTextureLayer(gt.FRAMEBUFFER,gt.COLOR_ATTACHMENT0,s.__webglTexture,i||0,n)}E=-1},this.readRenderTargetPixels=function(t,e,i,s,n,r,a){if(!t||!t.isWebGLRenderTarget)return;let o=Z.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(o=o[a]),o){$.bindFramebuffer(gt.FRAMEBUFFER,o);try{const a=t.texture,o=a.format,l=a.type;if(o!==kD&&pt.convert(o)!==gt.getParameter(gt.IMPLEMENTATION_COLOR_READ_FORMAT))return;const h=l===BD&&(q.has("EXT_color_buffer_half_float")||j.isWebGL2&&q.has("EXT_color_buffer_float"));if(!(l===ID||pt.convert(l)===gt.getParameter(gt.IMPLEMENTATION_COLOR_READ_TYPE)||l===UD&&(j.isWebGL2||q.has("OES_texture_float")||q.has("WEBGL_color_buffer_float"))||h))return;e>=0&&e<=t.width-s&&i>=0&&i<=t.height-n&>.readPixels(e,i,s,n,pt.convert(o),pt.convert(l),r)}finally{const t=null!==T?Z.get(T).__webglFramebuffer:null;$.bindFramebuffer(gt.FRAMEBUFFER,t)}}},this.copyFramebufferToTexture=function(t,e,i=0){const s=Math.pow(2,-i),n=Math.floor(e.image.width*s),r=Math.floor(e.image.height*s);Q.setTexture2D(e,0),gt.copyTexSubImage2D(gt.TEXTURE_2D,i,0,0,t.x,t.y,n,r),$.unbindTexture()},this.copyTextureToTexture=function(t,e,i,s=0){const n=e.image.width,r=e.image.height,a=pt.convert(i.format),o=pt.convert(i.type);Q.setTexture2D(i,0),gt.pixelStorei(gt.UNPACK_FLIP_Y_WEBGL,i.flipY),gt.pixelStorei(gt.UNPACK_PREMULTIPLY_ALPHA_WEBGL,i.premultiplyAlpha),gt.pixelStorei(gt.UNPACK_ALIGNMENT,i.unpackAlignment),e.isDataTexture?gt.texSubImage2D(gt.TEXTURE_2D,s,t.x,t.y,n,r,a,o,e.image.data):e.isCompressedTexture?gt.compressedTexSubImage2D(gt.TEXTURE_2D,s,t.x,t.y,e.mipmaps[0].width,e.mipmaps[0].height,a,e.mipmaps[0].data):gt.texSubImage2D(gt.TEXTURE_2D,s,t.x,t.y,a,o,e.image),0===s&&i.generateMipmaps&>.generateMipmap(gt.TEXTURE_2D),$.unbindTexture()},this.copyTextureToTexture3D=function(t,e,i,s,n=0){if(v.isWebGL1Renderer)return;const r=t.max.x-t.min.x+1,a=t.max.y-t.min.y+1,o=t.max.z-t.min.z+1,l=pt.convert(s.format),h=pt.convert(s.type);let c;if(s.isData3DTexture)Q.setTexture3D(s,0),c=gt.TEXTURE_3D;else{if(!s.isDataArrayTexture)return;Q.setTexture2DArray(s,0),c=gt.TEXTURE_2D_ARRAY}gt.pixelStorei(gt.UNPACK_FLIP_Y_WEBGL,s.flipY),gt.pixelStorei(gt.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s.premultiplyAlpha),gt.pixelStorei(gt.UNPACK_ALIGNMENT,s.unpackAlignment);const d=gt.getParameter(gt.UNPACK_ROW_LENGTH),u=gt.getParameter(gt.UNPACK_IMAGE_HEIGHT),f=gt.getParameter(gt.UNPACK_SKIP_PIXELS),p=gt.getParameter(gt.UNPACK_SKIP_ROWS),m=gt.getParameter(gt.UNPACK_SKIP_IMAGES),_=i.isCompressedTexture?i.mipmaps[0]:i.image;gt.pixelStorei(gt.UNPACK_ROW_LENGTH,_.width),gt.pixelStorei(gt.UNPACK_IMAGE_HEIGHT,_.height),gt.pixelStorei(gt.UNPACK_SKIP_PIXELS,t.min.x),gt.pixelStorei(gt.UNPACK_SKIP_ROWS,t.min.y),gt.pixelStorei(gt.UNPACK_SKIP_IMAGES,t.min.z),i.isDataTexture||i.isData3DTexture?gt.texSubImage3D(c,n,e.x,e.y,e.z,r,a,o,l,h,_.data):i.isCompressedArrayTexture?gt.compressedTexSubImage3D(c,n,e.x,e.y,e.z,r,a,o,l,_.data):gt.texSubImage3D(c,n,e.x,e.y,e.z,r,a,o,l,h,_),gt.pixelStorei(gt.UNPACK_ROW_LENGTH,d),gt.pixelStorei(gt.UNPACK_IMAGE_HEIGHT,u),gt.pixelStorei(gt.UNPACK_SKIP_PIXELS,f),gt.pixelStorei(gt.UNPACK_SKIP_ROWS,p),gt.pixelStorei(gt.UNPACK_SKIP_IMAGES,m),0===n&&s.generateMipmaps&>.generateMipmap(c),$.unbindTexture()},this.initTexture=function(t){t.isCubeTexture?Q.setTextureCube(t,0):t.isData3DTexture?Q.setTexture3D(t,0):t.isDataArrayTexture||t.isCompressedArrayTexture?Q.setTexture2DArray(t,0):Q.setTexture2D(t,0),$.unbindTexture()},this.resetState=function(){y=0,x=0,T=null,$.reset(),mt.reset()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return mI}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorSpace=t===QD?"display-p3":"srgb",e.unpackColorSpace=kI.workingColorSpace===JD?"display-p3":"srgb"}get physicallyCorrectLights(){return!this.useLegacyLights}set physicallyCorrectLights(t){this.useLegacyLights=!t}get outputEncoding(){return this.outputColorSpace===KD?jD:3e3}set outputEncoding(t){this.outputColorSpace=t===jD?KD:ZD}get useLegacyLights(){return this._useLegacyLights}set useLegacyLights(t){this._useLegacyLights=t}}(class extends iz{}).prototype.isWebGL1Renderer=!0;class sz extends sN{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,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,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}}class nz extends gN{constructor(t){super(),this.isMeshStandardMaterial=!0,this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new TN(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 TN(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new MI(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,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.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 rz extends sN{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new TN(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()),e}}const az=new DO,oz=new iO,lz=new iO;class hz{constructor(t){this.camera=t,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new MI(512,512),this.map=null,this.mapPass=null,this.matrix=new DO,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new TF,this._frameExtents=new MI(1,1),this._viewportCount=1,this._viewports=[new KI(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,i=this.matrix;oz.setFromMatrixPosition(t.matrixWorld),e.position.copy(oz),lz.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(lz),e.updateMatrixWorld(),az.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(az),i.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),i.multiply(az)}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.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this}clone(){return(new this.constructor).copy(this)}toJSON(){const t={};return 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 cz extends hz{constructor(){super(new FF(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class dz extends rz{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(sN.DEFAULT_UP),this.updateMatrix(),this.target=new sN,this.shadow=new cz}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class uz extends rz{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:sD}})),"undefined"!=typeof window&&(window.__THREE__||(window.__THREE__=sD));class fz{constructor(t){this.scene=null,this.camera=null,this.renderer=null,this.cube=null,this.directionalLight=null,this.ambientLight=null,this.canvas=null,this.initialized=!1,this.visible=!0,this.animationFrameId=null,this.needsRender=!1,this.resizeObserver=null,this.config=t}initialize(t){try{this.canvas=t,this.scene=new sz,this.scene.background=null;const e=t.clientWidth||t.width,i=e/(t.clientHeight||t.height)||1,s=4.5;this.camera=new FF(s*i/-2,s*i/2,s/2,s/-2,.1,1e3),this.camera.position.set(5,0,0),this.camera.lookAt(0,0,0),this.camera.updateProjectionMatrix(),this.renderer=new iz({canvas:t,alpha:!0,antialias:!0});const n=t.clientWidth||t.width,r=t.clientHeight||t.height;if(this.renderer.setSize(n,r,!1),this.renderer.setPixelRatio(window.devicePixelRatio||1),!this.renderer.getContext())throw new Error("Failed to create WebGL context");const a=new nF(1,1,1),o=new nz({color:11184810,metalness:.7,roughness:.3,emissive:1710623,emissiveIntensity:.1});this.cube=new iF(a,o),this.cube.position.set(0,0,0),this.scene.add(this.cube),this.directionalLight=new dz(16777215,2.2),this.directionalLight.position.set(2,3,2),this.scene.add(this.directionalLight);const l=new dz(16777215,.8);l.position.set(-1,.5,-1),this.scene.add(l);const h=new dz(16777215,1.2);h.position.set(-2,-1.5,2),this.scene.add(h);const c=new dz(16777215,1.2);c.position.set(2,-1.5,2),this.scene.add(c);const d=new dz(16777215,.4);d.position.set(0,-1,-2),this.scene.add(d),this.ambientLight=new uz(13421789,.35),this.scene.add(this.ambientLight),this.setupResizeObserver(),this.requestRender(),this.initialized=!0}catch(t){throw this.initialized=!1,this.cleanup(),t}}setRotation(t,e){if(!this.initialized||!this.camera)return;if(!isFinite(t)||!isFinite(e))return;const i=t*(Math.PI/180),s=e*(Math.PI/180),n=5*Math.sin(s)*Math.cos(i),r=5*Math.sin(i),a=5*Math.cos(s)*Math.cos(i);this.camera.position.set(n,r,a),this.camera.lookAt(0,0,0),this.requestRender()}setVisible(t){this.visible=t,this.canvas&&(this.canvas.style.display=t?"block":"none",t&&this.initialized&&this.requestRender())}setupResizeObserver(){this.canvas&&(this.resizeObserver=new ResizeObserver(t=>{for(const e of t){const{width:t,height:i}=e.contentRect;this.onCanvasResize(t,i)}}),this.resizeObserver.observe(this.canvas))}onCanvasResize(t,e){if(!this.camera||!this.renderer)return;const i=t/e||1,s=4.5;this.camera.left=s*i/-2,this.camera.right=s*i/2,this.camera.top=2.25,this.camera.bottom=-2.25,this.camera.updateProjectionMatrix(),this.renderer.setSize(t,e,!1),this.requestRender()}requestRender(){this.needsRender||(this.needsRender=!0,this.animationFrameId=requestAnimationFrame(()=>{this.render(),this.needsRender=!1,this.animationFrameId=null}))}render(){this.initialized&&this.visible&&this.scene&&this.camera&&this.renderer&&this.renderer.render(this.scene,this.camera)}cleanup(){null!==this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.needsRender=!1,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.cube&&(this.cube.geometry&&this.cube.geometry.dispose(),this.cube.material&&(Array.isArray(this.cube.material)?this.cube.material.forEach(t=>t.dispose()):this.cube.material.dispose()),this.cube=null),this.scene&&(this.scene.clear(),this.scene=null),this.renderer&&(this.renderer.dispose(),this.renderer=null),this.camera=null,this.directionalLight=null,this.ambientLight=null,this.canvas=null}destroy(){this.cleanup(),this.initialized=!1}isInitialized(){return this.initialized}isVisible(){return this.visible}}class pz{constructor(t,e){this.cubeEntity=null,this.cubeMaterial=null,this.cubeCamera=null,this.directionalLight=null,this.ambientLight=null,this.cubeRoot=null,this.initialized=!1,this.visible=!0,this.MIN_CANVAS_SIZE=200,this.MIN_PARENT_DIV_SIZE=100,this.cubeLayer=null,this.separateCanvas=null,this.parentDiv=null,this.resizeObserver=null,this.useParentDiv=!1,this.onResizeCallback=null,this.threeJsRenderer=null,this.useThreeJs=!1,this.mainApp=t,this.app=t,this.config=e,this.useParentDiv=!!e.parentElementId}initialize(){if(!this.initialized)try{this.useParentDiv&&this.config.parentElementId?this.initializeInParentDiv():this.initializeInMainCanvas(),this.initialized=!0}catch(t){throw this.cleanup(),t}}initializeInMainCanvas(){this.setupCubeLayer(),this.cubeRoot=new U_("NavigationCubeRoot"),this.app.root.addChild(this.cubeRoot),this.cubeMaterial=this.createCubeMaterial(),this.cubeEntity=this.createCubeGeometry(),this.cubeCamera=this.setupCubeCamera(),this.setupCubeLighting(),this.updateViewport()}initializeInParentDiv(){const t=this.config.parentElementId;if(this.parentDiv=document.getElementById(t),!this.parentDiv)return this.useParentDiv=!1,void this.initializeInMainCanvas();const e=this.parentDiv.querySelector("#navigation-cube-canvas");e&&e.remove(),this.separateCanvas=document.createElement("canvas"),this.separateCanvas.id="navigation-cube-canvas",this.separateCanvas.style.width="100%",this.separateCanvas.style.height="100%",this.separateCanvas.style.display="block",this.separateCanvas.style.position="absolute",this.separateCanvas.style.top="0",this.separateCanvas.style.left="0",this.parentDiv.appendChild(this.separateCanvas);const i=this.parentDiv.getBoundingClientRect();this.separateCanvas.width=Math.floor(i.width),this.separateCanvas.height=Math.floor(i.height);try{this.threeJsRenderer=new fz(this.config),this.threeJsRenderer.initialize(this.separateCanvas),this.useThreeJs=!0,this.useParentDiv=!0}catch(t){return this.useParentDiv=!1,this.useThreeJs=!1,this.app=this.mainApp,void this.initializeInMainCanvas()}}setupCubeLayer(){this.cubeLayer=new tu({name:"NavigationCubeLayer",opaqueSortMode:0,transparentSortMode:0});this.app.scene.layers.push(this.cubeLayer)}createCubeGeometry(){const t=new U_("NavigationCube");return t.addComponent("render",{type:"box",material:this.cubeMaterial,castShadows:!1,receiveShadows:!1,layers:[this.cubeLayer.id]}),t.setLocalPosition(0,0,0),this.cubeRoot.addChild(t),t}createCubeMaterial(){const t=new Gp;return t.diffuse=new H(.6,.6,.65),t.metalness=.5,t.gloss=.5,t.useMetalness=!0,t.emissive=new H(.1,.1,.12),t.emissiveIntensity=.15,t.update(),t}setupCubeCamera(){const t=new U_("NavigationCubeCamera"),e=this.useParentDiv,i=new H(0,0,0,e?1:0);return t.addComponent("camera",{projection:1,orthoHeight:1.5,clearColor:i,clearColorBuffer:e,clearDepthBuffer:!0,priority:100,farClip:100,nearClip:.1,layers:[this.cubeLayer.id]}),t.setLocalPosition(0,0,5),t.lookAt(0,0,0),this.cubeRoot.addChild(t),t}setupCubeLighting(){this.directionalLight=new U_("CubeDirectionalLight");const t={type:"directional",color:new H(1,1,1),intensity:1.5,castShadows:!1};this.cubeLayer&&(t.layers=[this.cubeLayer.id]),this.directionalLight.addComponent("light",t),this.directionalLight.setLocalEulerAngles(45,45,0),this.cubeCamera.addChild(this.directionalLight),this.ambientLight=new U_("CubeAmbientLight");const e={type:"directional",color:new H(.8,.8,.85),intensity:.7,castShadows:!1};this.cubeLayer&&(e.layers=[this.cubeLayer.id]),this.ambientLight.addComponent("light",e),this.ambientLight.setLocalEulerAngles(-45,-135,0),this.cubeCamera.addChild(this.ambientLight)}setRotation(t,e){if(this.initialized)if(this.useThreeJs&&this.threeJsRenderer)this.threeJsRenderer.setRotation(t,e);else if(this.cubeCamera&&"number"==typeof t&&"number"==typeof e)try{const i=5,s=t*(Math.PI/180),n=e*(Math.PI/180),r=i*Math.sin(n)*Math.cos(s),a=i*Math.sin(s),o=i*Math.cos(n)*Math.cos(s);this.cubeCamera.setLocalPosition(r,a,o),this.cubeCamera.lookAt(0,0,0)}catch(t){}}render(){this.initialized&&this.visible&&this.useThreeJs}setVisible(t){this.visible=t,this.useThreeJs&&this.threeJsRenderer?this.threeJsRenderer.setVisible(t):this.initialized&&this.cubeRoot&&(this.cubeRoot.enabled=t)}isVisible(){return this.visible}updateSize(t){if("number"!=typeof t||!isFinite(t))return;const e=Math.max(50,Math.min(500,t));this.config.cubeSize=e,this.initialized&&this.cubeCamera&&this.updateViewport()}shouldShowCube(){if(this.useParentDiv&&this.parentDiv){const t=this.parentDiv.clientWidth,e=this.parentDiv.clientHeight;return t>=this.MIN_PARENT_DIV_SIZE&&e>=this.MIN_PARENT_DIV_SIZE}const t=this.app.graphicsDevice.canvas;if(!t)return!1;const e=t.width,i=t.height;return e>=this.MIN_CANVAS_SIZE&&i>=this.MIN_CANVAS_SIZE}updateViewport(){if(!this.cubeCamera||!this.cubeCamera.camera)return;const t=this.app.graphicsDevice.canvas;if(!t)return;const e=t.width,i=t.height;if(e<=0||i<=0)return;if(!this.shouldShowCube())return void(this.cubeRoot&&(this.cubeRoot.enabled=!1));this.cubeRoot&&!this.cubeRoot.enabled&&this.visible&&(this.cubeRoot.enabled=!0);const s=this.config.cubeSize;let n=s/e,r=s/i,a=1-n-this.config.padding.x/e,o=1-r-this.config.padding.y/i;a=Math.max(0,Math.min(a,1-n)),o=Math.max(0,Math.min(o,1-r)),n=Math.max(0,Math.min(n,1-a)),r=Math.max(0,Math.min(r,1-o)),this.cubeCamera.camera.rect=new J(a,o,n,r)}onCanvasResize(){this.initialized&&(this.updateViewport(),this.onResizeCallback&&this.onResizeCallback())}setResizeCallback(t){this.onResizeCallback=t}cleanup(){if(this.threeJsRenderer&&(this.threeJsRenderer.destroy(),this.threeJsRenderer=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.ambientLight&&(this.ambientLight.destroy(),this.ambientLight=null),this.directionalLight&&(this.directionalLight.destroy(),this.directionalLight=null),this.cubeCamera&&(this.cubeCamera.destroy(),this.cubeCamera=null),this.cubeEntity&&(this.cubeEntity.destroy(),this.cubeEntity=null),this.cubeMaterial&&(this.cubeMaterial.destroy(),this.cubeMaterial=null),this.cubeRoot&&(this.cubeRoot.destroy(),this.cubeRoot=null),this.cubeLayer){const t=this.app.scene.layers,e=t.getLayerById(this.cubeLayer.id);e&&t.remove(e),this.cubeLayer=null}this.useParentDiv&&this.separateCanvas&&(this.separateCanvas.parentElement&&this.separateCanvas.parentElement.removeChild(this.separateCanvas),this.separateCanvas=null,this.parentDiv=null),this.app=this.mainApp,this.initialized=!1}destroy(){if(this.initialized)try{this.cleanup()}catch(t){this.initialized=!1}}isInitialized(){return this.initialized}getMinimumCanvasSize(){return this.useParentDiv?this.MIN_PARENT_DIV_SIZE:this.MIN_CANVAS_SIZE}isVisibleOnCanvas(){return this.visible&&this.initialized&&this.shouldShowCube()}getCanvasDimensions(){const t=this.app.graphicsDevice.canvas;return t?{width:t.width,height:t.height}:null}getViewport(){if(!this.cubeCamera||!this.cubeCamera.camera)return null;if(this.useParentDiv)return{x:0,y:0,width:1,height:1};const t=this.cubeCamera.camera.rect;return{x:t.x,y:t.y,width:t.z,height:t.w}}getCanvas(){return this.useParentDiv&&this.separateCanvas?this.separateCanvas:this.app.graphicsDevice.canvas}getParentDiv(){return this.parentDiv}isUsingParentDiv(){return this.useParentDiv}}const mz={enableStats:!1,autoFocus:!0,maxSplats:2e6,camera:{position:{x:0,y:0,z:10},target:{x:0,y:0,z:0},distance:10,minDistance:.1,maxDistance:1e5,orbitSensitivity:.3,panSensitivity:1,zoomSensitivity:.1},navigationCube:{enabled:!1,cubeSize:150,position:{x:0,y:0},padding:{x:50,y:100},transitionDuration:600,controlPointRadius:6,controlPointColor:{normal:"#ffffff",hover:"#FB7347"},continuousRotationSpeed:45}};function _z(t){if(!t)return null;try{return JSON.parse(t)}catch(t){return null}}function gz(t){return"boolean"==typeof t?t:"string"==typeof t&&("true"===t.toLowerCase()||"1"===t)}function vz(t,e=0){if("number"==typeof t)return t;if("string"==typeof t){const i=parseFloat(t);return isNaN(i)?e:i}return e}class Sz{constructor(t={}){this._app=null,this._mainCamera=null,this._orbitScript=null,this.emitEvent=null,this.initialized=!1,this.cubeRenderer=null,this.controlPointManager=null,this.transitionController=null;const e=mz.navigationCube;if(!e)throw new Error("NavigationCubeController: DEFAULT_CONFIG.navigationCube is not defined");this.config={...e,...t},this._enabled=this.config.enabled}get enabled(){return this._enabled}initialize(t,e,i,s){if(!this.initialized&&this._enabled&&t&&e&&i){this._app=t,this._mainCamera=e,this._orbitScript=i,this.emitEvent=s||null;try{this.cubeRenderer=new pz(t,this.config),this.cubeRenderer.initialize(),this.cubeRenderer.setResizeCallback(()=>{this.updateControlPointPositions()});const e=this.cubeRenderer.getCanvas()||t.graphicsDevice.canvas,s=this.cubeRenderer.getParentDiv();this.controlPointManager=new iD(this.config,e,this.onControlPointClick.bind(this),this.onControlPointPressStart.bind(this),this.onControlPointPressEnd.bind(this),s),this.controlPointManager.initialize(),this.updateControlPointPositions(),this.transitionController=new eD(i,this.config.transitionDuration),void 0!==this.config.continuousRotationSpeed&&this.transitionController.setContinuousRotationSpeed(this.config.continuousRotationSpeed),this.initialized=!0}catch(t){this.cleanup(),this.initialized=!1}}}update(t){if(this.initialized&&this._enabled&&!("number"!=typeof t||t<0)&&isFinite(t))try{this.cubeRenderer&&this.cubeRenderer.render(),this.transitionController&&this.transitionController.update(t)}catch(t){}}updateControlPointPositions(){if(!this.controlPointManager||!this.cubeRenderer)return;const t=this.cubeRenderer.getViewport();t?this.controlPointManager.updateControlPointPositions(t):this.controlPointManager.updateControlPointPositions()}onControlPointClick(t){if(this.initialized&&this._enabled)try{this.snapToView(t)}catch(t){}}onControlPointPressStart(t){if(this.initialized&&this._enabled)try{this.transitionController&&this.transitionController.startContinuousRotation(t),this.emitEvent&&this.emitEvent("navigation-cube:continuous-rotation-start",{direction:t})}catch(t){}}onControlPointPressEnd(t){if(this.initialized&&this._enabled)try{this.transitionController&&this.transitionController.stopContinuousRotation(),this.emitEvent&&this.emitEvent("navigation-cube:continuous-rotation-end",{direction:t})}catch(t){}}syncWithCamera(t,e){if(this.initialized&&this._enabled&&"number"==typeof t&&"number"==typeof e)try{this.cubeRenderer&&this.cubeRenderer.setRotation(t,e)}catch(t){}}async snapToView(t){if(!this.initialized||!this._enabled)return Promise.reject(new Error("NavigationCubeController not initialized or disabled"));if(![tD.TOP,tD.BOTTOM,tD.LEFT,tD.RIGHT].includes(t))return Promise.reject(new Error(`Invalid direction: ${t}`));try{if(this.transitionController?.isTransitionActive()&&this.transitionController.cancelTransition("interrupted"),this.controlPointManager){const e=this.controlPointManager.getControlPoint(t);if(e?.element){const t=e.element,i=t.style.transform;t.style.transition="transform 100ms ease-out",t.style.transform="scale(1.4)",setTimeout(()=>{t.style.transition="background-color 200ms ease-in-out, transform 200ms ease-in-out, box-shadow 200ms ease-in-out",t.style.transform=i},100)}}if(!this.transitionController)throw new Error("TransitionController not initialized");const e=this.transitionController.calculateTargetState(t);if(!this.transitionController.validateTargetState(e))throw new Error("Invalid target state calculated");this.emitEvent&&this.emitEvent("navigation-cube:view-change-start",{direction:t});try{await this.transitionController.startTransition(e),this.emitEvent&&this.emitEvent("navigation-cube:view-change-complete",{direction:t})}catch(e){throw this.emitEvent&&this.emitEvent("navigation-cube:view-change-cancel",{direction:t,reason:e.message||"unknown"}),e}}catch(e){return this.emitEvent&&this.emitEvent("navigation-cube:view-change-cancel",{direction:t,reason:e instanceof Error?e.message:"unknown error"}),Promise.reject(e)}}setEnabled(t){if(this._enabled!==t&&(this._enabled=t,this.initialized))try{t?(this.cubeRenderer?.setVisible(!0),this.controlPointManager?.setVisible(!0)):(this.cubeRenderer?.setVisible(!1),this.controlPointManager?.setVisible(!1),this.transitionController?.cancelTransition("disabled"))}catch(t){}}updateConfig(t){const e=this.validateConfig(t);if(this.config={...this.config,...e},this.initialized)try{void 0!==e.cubeSize&&this.cubeRenderer&&(this.cubeRenderer.updateSize(e.cubeSize),this.updateControlPointPositions()),void 0!==e.controlPointColor&&this.controlPointManager&&this.controlPointManager.updateColors(e.controlPointColor),void 0!==e.controlPointRadius&&this.controlPointManager&&this.controlPointManager.updateRadius(e.controlPointRadius),void 0===e.padding&&void 0===e.position&&void 0===e.cubeSize||!this.controlPointManager||this.updateControlPointPositions(),void 0!==e.transitionDuration&&this.transitionController&&this.transitionController.setDuration(e.transitionDuration),void 0!==e.continuousRotationSpeed&&this.transitionController&&this.transitionController.setContinuousRotationSpeed(e.continuousRotationSpeed)}catch(t){}}validateConfig(t){const e={};if(void 0!==t.cubeSize&&"number"==typeof t.cubeSize&&isFinite(t.cubeSize)&&(e.cubeSize=Math.max(50,Math.min(500,t.cubeSize)),e.cubeSize,t.cubeSize),void 0!==t.controlPointRadius&&"number"==typeof t.controlPointRadius&&isFinite(t.controlPointRadius)&&(e.controlPointRadius=Math.max(4,Math.min(20,t.controlPointRadius)),e.controlPointRadius,t.controlPointRadius),void 0!==t.transitionDuration&&"number"==typeof t.transitionDuration&&isFinite(t.transitionDuration)&&(e.transitionDuration=Math.max(100,Math.min(3e3,t.transitionDuration)),e.transitionDuration,t.transitionDuration),void 0!==t.padding&&"object"==typeof t.padding&&null!==t.padding&&"number"==typeof t.padding.x&&"number"==typeof t.padding.y){const i=Math.max(0,Math.min(500,t.padding.x)),s=Math.max(0,Math.min(500,t.padding.y));e.padding={x:i,y:s},i!==t.padding.x||t.padding.y}if(void 0!==t.position&&"object"==typeof t.position&&null!==t.position&&"number"==typeof t.position.x&&"number"==typeof t.position.y){const i=Math.max(0,Math.min(1,t.position.x)),s=Math.max(0,Math.min(1,t.position.y));e.position={x:i,y:s},i!==t.position.x||t.position.y}return void 0!==t.controlPointColor&&"object"==typeof t.controlPointColor&&null!==t.controlPointColor&&"string"==typeof t.controlPointColor.normal&&"string"==typeof t.controlPointColor.hover&&this.isValidColor(t.controlPointColor.normal)&&this.isValidColor(t.controlPointColor.hover)&&(e.controlPointColor={normal:t.controlPointColor.normal,hover:t.controlPointColor.hover}),void 0!==t.enabled&&"boolean"==typeof t.enabled&&(e.enabled=t.enabled),void 0!==t.continuousRotationSpeed&&"number"==typeof t.continuousRotationSpeed&&isFinite(t.continuousRotationSpeed)&&(e.continuousRotationSpeed=Math.max(10,Math.min(180,t.continuousRotationSpeed)),e.continuousRotationSpeed,t.continuousRotationSpeed),e}isValidColor(t){if(/^#([0-9A-F]{3}|[0-9A-F]{6}|[0-9A-F]{8})$/i.test(t))return!0;if(/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*[\d.]+\s*)?\)$/i.test(t))return!0;if(/^hsla?\(\s*\d+\s*,\s*\d+%\s*,\s*\d+%\s*(,\s*[\d.]+\s*)?\)$/i.test(t))return!0;return!!["white","black","red","green","blue","yellow","orange","purple","pink","gray","grey","transparent"].includes(t.toLowerCase())}cancelTransition(t="manual-interaction"){if(this.initialized)try{this.transitionController&&this.transitionController.cancelTransition(t)}catch(t){}}onCanvasResize(){if(this.initialized&&this._enabled)try{this.cubeRenderer&&this.cubeRenderer.onCanvasResize(),this.controlPointManager&&this.updateControlPointPositions()}catch(t){}}cleanup(){this.transitionController&&(this.transitionController.cancelTransition("cleanup"),this.transitionController=null),this.controlPointManager&&(this.controlPointManager.destroy(),this.controlPointManager=null),this.cubeRenderer&&(this.cubeRenderer.destroy(),this.cubeRenderer=null),this._app=null,this._mainCamera=null,this._orbitScript=null}destroy(){if(this.initialized)try{this.cleanup(),this.initialized=!1}catch(t){this.initialized=!1}}getConfig(){return{...this.config}}isInitialized(){return this.initialized}}class yz{constructor(t,e,i){this.app=t,this.camera=e,this.emit=i}setCameraFOV(t){this.validateFOV(t),this.camera.camera.fov=t,this.emit("camera-fov-changed",{fov:t,previousFov:t})}getCameraFOV(){return this.camera.camera?.fov??60}async animateCameraFOV(t,e){this.validateFOV(t);const i=this.camera.camera,s=i.fov,n=t;if(e<=0)return i.fov=n,void this.emit("camera-fov-changed",{fov:n,previousFov:s});const r=performance.now();await new Promise(t=>{const a=()=>{const o=(performance.now()-r)/e,l=this.easeInOutCubic(Math.min(1,Math.max(0,o)));i.fov=s+(n-s)*l,o<1?requestAnimationFrame(a):(i.fov=n,this.emit("camera-fov-changed",{fov:n,previousFov:s}),t())};requestAnimationFrame(a)})}validateFOV(t){if("number"!=typeof t||isNaN(t)||t<1||t>179)throw new Error("SceneConfigManager.validateFOV: FOV must be between 1 and 179 degrees")}setBackgroundColor(t){const e=this.parseColor(t),i=new H(e.r/255,e.g/255,e.b/255,e.a);this.camera.camera.clearColor=i,this.emit("background-color-changed",{color:e,previousColor:e})}getBackgroundColor(){const t=this.camera.camera?.clearColor;return t?{r:Math.round(255*(t.r??0)),g:Math.round(255*(t.g??0)),b:Math.round(255*(t.b??0)),a:"number"==typeof t.a?t.a:1}:{r:26,g:26,b:26,a:1}}async animateBackgroundColor(t,e){const i=this.getBackgroundColor(),s=this.parseColor(t);if(e<=0)return this.setBackgroundColor(s),void this.emit("background-color-changed",{color:s,previousColor:i});const n=performance.now();await new Promise(t=>{const r=()=>{const a=(performance.now()-n)/e,o=this.easeInOutCubic(Math.min(1,Math.max(0,a))),l=this.interpolateColor(i,s,o),h=new H(l.r/255,l.g/255,l.b/255,l.a);this.camera.camera.clearColor=h,a<1?requestAnimationFrame(r):(this.emit("background-color-changed",{color:s,previousColor:i}),t())};requestAnimationFrame(r)})}parseColor(t){if("string"==typeof t)return this.parseColorString(t);if(Array.isArray(t)){if(3===t.length)return{r:t[0],g:t[1],b:t[2],a:1};if(4===t.length)return{r:t[0],g:t[1],b:t[2],a:t[3]};throw new Error("SceneConfigManager.parseColor: Invalid color array length")}if("object"==typeof t&&null!==t){if("a"in t)return t;const e=t;return{r:e.r,g:e.g,b:e.b,a:1}}throw new Error("SceneConfigManager.parseColor: Unsupported color input")}parseColorString(t){const e=t.trim().toLowerCase();if(e.startsWith("#")){const t=e.slice(1);if(3===t.length){return{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:1}}if(6===t.length){return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16),a:1}}throw new Error("SceneConfigManager.parseColorString: Invalid hex color")}const i={black:[0,0,0],white:[255,255,255],red:[255,0,0],green:[0,128,0],blue:[0,0,255],gray:[128,128,128],grey:[128,128,128],orange:[255,165,0],purple:[128,0,128]};if(i[e]){const[t,s,n]=i[e];return{r:t,g:s,b:n,a:1}}throw new Error(`SceneConfigManager.parseColorString: Unsupported color string "${t}"`)}interpolateColor(t,e,i){const s=Math.min(1,Math.max(0,i)),n=(t,e)=>t+(e-t)*s;return{r:Math.round(n(t.r,e.r)),g:Math.round(n(t.g,e.g)),b:Math.round(n(t.b,e.b)),a:n(t.a,e.a)}}easeInOutCubic(t){return t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2}}class xz{constructor(t){this._eventEmitter=t}applyTransformMatrix(t,e,i){const s=new rt;s.data.set(e);const{pos:n,rot:r,scale:a}=this.decomposeMatrix(s);t.setLocalPosition(n),t.setLocalRotation(r),t.setLocalScale(a);const o=this.getTransform(t);this.emitTransformEvent(i,o)}getTransformMatrix(t){const e=t.getLocalTransform().data;return[e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8],e[9],e[10],e[11],e[12],e[13],e[14],e[15]]}setPosition(t,e,i){t.setLocalPosition(e.x,e.y,e.z);const s=this.getTransform(t);this.emitTransformEvent(i,s)}setRotation(t,e,i){const s=this.eulerToQuat(e);t.setLocalRotation(s);const n=this.getTransform(t);this.emitTransformEvent(i,n)}setScale(t,e,i){t.setLocalScale(e.x,e.y,e.z);const s=this.getTransform(t);this.emitTransformEvent(i,s)}getTransform(t){const e=t.getLocalPosition(),i=t.getLocalRotation(),s=t.getLocalScale(),n=this.quatToEuler(i),r=this.getTransformMatrix(t);return{position:{x:e.x,y:e.y,z:e.z},rotation:n,scale:{x:s.x,y:s.y,z:s.z},matrix:r}}resetTransform(t,e){t.setLocalPosition(0,0,0),t.setLocalRotation(0,0,0,1),t.setLocalScale(1,1,1);const i=this.getTransform(t);this.emitTransformEvent(e,i)}decomposeMatrix(t){const e=new K,i=new at,s=new K;t.getTranslation(e);const n=t.data,r=Math.sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]),a=Math.sqrt(n[4]*n[4]+n[5]*n[5]+n[6]*n[6]),o=Math.sqrt(n[8]*n[8]+n[9]*n[9]+n[10]*n[10]);s.set(r,a,o);const l=new rt;l.data[0]=n[0]/r,l.data[1]=n[1]/r,l.data[2]=n[2]/r,l.data[3]=0,l.data[4]=n[4]/a,l.data[5]=n[5]/a,l.data[6]=n[6]/a,l.data[7]=0,l.data[8]=n[8]/o,l.data[9]=n[9]/o,l.data[10]=n[10]/o,l.data[11]=0,l.data[12]=0,l.data[13]=0,l.data[14]=0,l.data[15]=1,l.getEulerAngles(i);const h=i;return i.setFromEulerAngles(h.x,h.y,h.z),{pos:e,rot:i,scale:s}}eulerToQuat(t){const e=new at;return e.setFromEulerAngles(t.x,t.y,t.z),e}quatToEuler(t){const e=new K;return t.getEulerAngles(e),{x:e.x,y:e.y,z:e.z}}emitTransformEvent(t,e){this._eventEmitter&&this._eventEmitter("model-transform-changed",{modelId:t,transform:e})}}var Tz;!function(t){t.ORBIT="orbit",t.FLY="fly"}(Tz||(Tz={}));const Ez={moveSpeed:5,fastSpeedMultiplier:3,slowSpeedMultiplier:.3,lookSensitivity:.2,invertY:!1,keyBindings:{forward:"KeyW",backward:"KeyS",left:"KeyA",right:"KeyD",up:"KeyE",down:"KeyQ",fastMove:"ShiftLeft",slowMove:"ControlLeft"},smoothing:.8,friction:.85,enableCollision:!1,minHeight:null,maxHeight:null};class SplatViewerCore{constructor(t={}){this.canvas=null,this.app=null,this.entities={camera:null,light:null,splat:null},this.enableStats=!1,this.autoFocus=!0,this.isLoading=!1,this.hasModel=!1,this.error=null,this._orbit=null,this._fly=null,this._cameraModeManager=null,this._statsHandler=null,this._asset=null,this._blobUrl=null,this._resizeObserver=null,this._resizeHandler=null,this.initialCameraPosition=null,this._navigationCubeConfig=null,this._modelManager=null,this._transformSystem=null,this._sceneConfigManager=null,this._eventListeners=new Map,this.canvas=t.canvas||null,this.enableStats=t.enableStats||!1,this.autoFocus=!1!==t.autoFocus,this._navigationCubeConfig=t.navigationCube||null,void 0!==t.onStatsUpdate&&(this._onStatsUpdate=t.onStatsUpdate),void 0!==t.onError&&(this._onError=t.onError),void 0!==t.onLoadingStart&&(this._onLoadingStart=t.onLoadingStart),void 0!==t.onLoaded&&(this._onLoaded=t.onLoaded)}init(t){if(this.canvas=t||this.canvas,!this.canvas)throw new Error("SplatViewerCore.init: canvas is required");return this.app=new oC(this.canvas,{mouse:new Ua(this.canvas),touch:new Ja(this.canvas),graphicsDeviceOptions:{antialias:!1,alpha:!1,preserveDrawingBuffer:!0,powerPreference:"high-performance",stencil:!1,depth:!0}}),this.app.start(),this._setupResolution(),this._setupScene(),this._setupCamera(),this._setupLighting(),this._setupOrbitCamera(),this._setupStats(),this._modelManager=new JL(this.app,(t,e)=>{this.emit({type:t,detail:e})}),this._transformSystem=new xz((t,e)=>{"model-transform-changed"===t&&this._modelManager&&this._modelManager.updateModelTransform(e.modelId,e.transform),this.emit({type:t,detail:e})}),this.entities.camera&&(this._sceneConfigManager=new yz(this.app,this.entities.camera,(t,e)=>this.emit({type:t,detail:e}))),this}async load(t,e={}){if(!this.app)throw new Error("SplatViewerCore.load: call init() first");this.clear(),this.isLoading=!0,this.error=null,this._onLoadingStart?.(),this.emit({type:"loading-start",detail:{source:"string"==typeof t?t:"file/blob"}}),this.emit({type:"loading-progress",detail:{progress:.1}});try{let i;try{i=$L(t)}catch(t){}if(i&&KL(i.ext))try{this.emit({type:"loading-progress",detail:{progress:.3}});const s={applyRotation:!1,..."number"==typeof e.maxSplats&&{maxSplats:e.maxSplats}},n=await QL(this.app,t,s);if(this.entities.splat=n.entity,this._asset=n.asset,i.url&&i.blob)try{URL.revokeObjectURL(i.url)}catch(t){}return await new Promise(t=>{this.app.once("frameupdate",()=>{this.autoFocus&&(this.focus(n.entity),setTimeout(()=>{this.debugInfo().boundsRadius||this.focus(n.entity)},100)),this.isLoading=!1,this.hasModel=!0,this._onLoaded?.(n),this.emit({type:"loaded",detail:{entity:n.entity,asset:n.asset}}),t(n)})})}catch(t){throw t instanceof jL?(this.error=t.code||"UNKNOWN_LOADER_ERROR",this._onError?.(this.error)):(this.error="UNKNOWN_LOADER_ERROR",this._onError?.(this.error)),this.isLoading=!1,this.emit({type:"error",detail:{message:this.error,code:t instanceof jL?t.code:"UNKNOWN_ERROR"}}),t}let s=null,n="gsplat";if("string"==typeof t)s=t,n=t.split("/").pop()||"gsplat";else{if(!(t instanceof Blob))throw new Error("Unsupported source type");s=URL.createObjectURL(t),this._blobUrl=s,n="local.ply"}try{this.emit({type:"loading-progress",detail:{progress:.5}});const t=new y_(n,"gsplat",{url:s}),e=new lC([t],this.app.assets);if(await new Promise(t=>e.load(()=>t())),this.emit({type:"loading-progress",detail:{progress:.8}}),!t||!1===t.loaded||!t.resource)throw new Error("GSplat asset failed to load");const i=new U_("splat");return i.addComponent("gsplat",{asset:t}),i.setLocalEulerAngles(270,0,0),this.app.root.addChild(i),this.entities.splat=i,this._asset=t,await new Promise(e=>{this.app.once("frameupdate",()=>{this.autoFocus&&(this.focus(i),setTimeout(()=>{this.debugInfo().boundsRadius||this.focus(i)},100)),this.isLoading=!1,this.hasModel=!0;const s={entity:i,asset:t};this._onLoaded?.(s),this.emit({type:"loaded",detail:{entity:s.entity,asset:s.asset}}),e(s)})})}catch(t){throw this.error="Failed to load splat",this._onError?.(this.error),this.isLoading=!1,this.emit({type:"error",detail:{message:this.error,code:"LOAD_FAILED"}}),t}}catch(t){throw this.isLoading=!1,t}}focus(t){const e=t||this.entities.splat||this.app?.root;if(e&&this._orbit)try{const t=new ut;this.calcSceneBounds(t,e);const i=t.halfExtents.length();if(this._orbit&&void 0!==this._orbit.distance){const t=2.5*i;this._orbit.distance=t}const s=this.calcFocalPoint(t);if(this.initialCameraPosition)return this.initialCameraPosition=null,void(this._orbit&&void 0!==this._orbit.target&&(this._orbit.target=s));this._orbit&&void 0!==this._orbit.target&&(this._orbit.target=s),"function"==typeof this._orbit.focus&&this._orbit.focus(e)}catch(t){"function"==typeof this._orbit.focus&&this._orbit.focus(e)}}calcSceneBounds(t,e){if(e)if(t.center.set(0,0,0),t.halfExtents.set(0,0,0),e.getWorldTransform&&e.getWorldTransform(),e._calculateHierarchyBounds)e._calculateHierarchyBounds(t);else if(e.gsplat){const i=e.gsplat;i.bounds?t.copy(i.bounds):i.boundingBox&&t.copy(i.boundingBox)}}calcFocalPoint(t){return t.center.clone()}async addModel(t,e={}){if(!this._modelManager)throw new Error("SplatViewerCore.addModel: ModelManager not initialized");return await this._modelManager.addModel(t,e)}removeModel(t){if(!this._modelManager)throw new Error("SplatViewerCore.removeModel: ModelManager not initialized");this._modelManager.removeModel(t)}getModels(){return this._modelManager?this._modelManager.getModels():[]}getModelStats(t){if(!this._modelManager)throw new Error("SplatViewerCore.getModelStats: ModelManager not initialized");return this._modelManager.getModelStats(t)}getAllModelStats(){return this._modelManager?this._modelManager.getAllModelStats():{}}getSceneStats(){return this._modelManager?this._modelManager.getSceneStats():{modelCount:0,totalSplats:0,totalFileSize:0,totalMemoryUsage:0,bounds:{center:{x:0,y:0,z:0},halfExtents:{x:0,y:0,z:0}}}}applyTransformMatrix(t,e){if(!this._transformSystem)throw new Error("SplatViewerCore.applyTransformMatrix: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.applyTransformMatrix: ModelManager not initialized");const i=this._modelManager.getModelById(t);if(!i)throw new Error(`SplatViewerCore.applyTransformMatrix: Model with ID "${t}" not found`);this._transformSystem.applyTransformMatrix(i.entity,e,t)}setModelPosition(t,e){if(!this._transformSystem)throw new Error("SplatViewerCore.setModelPosition: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.setModelPosition: ModelManager not initialized");const i=this._modelManager.getModelById(t);if(!i)throw new Error(`SplatViewerCore.setModelPosition: Model with ID "${t}" not found`);this._transformSystem.setPosition(i.entity,e,t)}setModelRotation(t,e){if(!this._transformSystem)throw new Error("SplatViewerCore.setModelRotation: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.setModelRotation: ModelManager not initialized");const i=this._modelManager.getModelById(t);if(!i)throw new Error(`SplatViewerCore.setModelRotation: Model with ID "${t}" not found`);this._transformSystem.setRotation(i.entity,e,t)}setModelScale(t,e){if(!this._transformSystem)throw new Error("SplatViewerCore.setModelScale: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.setModelScale: ModelManager not initialized");const i=this._modelManager.getModelById(t);if(!i)throw new Error(`SplatViewerCore.setModelScale: Model with ID "${t}" not found`);this._transformSystem.setScale(i.entity,e,t)}getModelTransform(t){if(!this._transformSystem)throw new Error("SplatViewerCore.getModelTransform: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.getModelTransform: ModelManager not initialized");const e=this._modelManager.getModelById(t);if(!e)throw new Error(`SplatViewerCore.getModelTransform: Model with ID "${t}" not found`);return this._transformSystem.getTransform(e.entity)}resetModelTransform(t){if(!this._transformSystem)throw new Error("SplatViewerCore.resetModelTransform: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.resetModelTransform: ModelManager not initialized");const e=this._modelManager.getModelById(t);if(!e)throw new Error(`SplatViewerCore.resetModelTransform: Model with ID "${t}" not found`);this._transformSystem.resetTransform(e.entity,t)}clear(){this._modelManager&&this._modelManager.clear(),this.entities.splat&&(this.entities.splat.destroy(),this.entities.splat=null),this._asset&&(this._asset.unload(),this._asset.destroy(),this._asset=null),this._blobUrl&&(URL.revokeObjectURL(this._blobUrl),this._blobUrl=null),this.hasModel=!1,this.error=null}destroy(){if(this.app){this.clear(),this._modelManager=null,this._statsHandler&&(this.app.off("frameend",this._statsHandler),this._statsHandler=null),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),this._resizeHandler&&(window.removeEventListener("resize",this._resizeHandler),this._resizeHandler=null);try{this.entities.camera&&(this.entities.camera.destroy(),this.entities.camera=null)}catch(t){}try{this.entities.light&&(this.entities.light.destroy(),this.entities.light=null)}catch(t){}try{this.app.destroy()}catch(t){throw t}this.app=null,this._orbit=null}}debugInfo(){const t=this._asset,e=this.entities.splat,i=!!e?.gsplat;let s=null,n=null;if(e){const t=e.gsplat;if(t){const e=t.bounds||t.boundingBox||null;e?.halfExtents?(s=Math.max(1,e.halfExtents.length()),n="gsplat.bounds"):"number"==typeof t.radius&&(s=Math.max(1,t.radius),n="gsplat.radius")}if(null==s&&e._calculateHierarchyBounds){const t=new ut;e.getWorldTransform(),e._calculateHierarchyBounds(t),t.halfExtents.length()>0&&(s=Math.max(1,t.halfExtents.length()),n="hierarchy")}}return{assetName:t?.name||null,assetUrl:t?.file?.url||t?.url||null,hasEntity:!!e,hasGsplatComponent:i,cameraDistance:this._orbit?.distance??null,boundsRadius:s,boundsSource:n,cameraTarget:this._orbit?.target?this._orbit.target.toString():null}}on(t,e){this._eventListeners.has(t)||this._eventListeners.set(t,new Set),this._eventListeners.get(t).add(e)}off(t,e){const i=this._eventListeners.get(t);i&&(i.delete(e),0===i.size&&this._eventListeners.delete(t))}emit(t){const e=this._eventListeners.get(t.type);e&&e.forEach(e=>{try{e(t)}catch(t){}})}setCameraPosition(t){this.entities.camera&&(this.entities.camera.setPosition(t),this.emit({type:"camera-change",detail:{position:t,target:this._orbit?.target||{x:0,y:0,z:0}}}))}setCameraTarget(t){this._orbit&&(this._orbit.target=t,this._orbit.updateCameraPosition?.(),this.emit({type:"camera-change",detail:{position:this.entities.camera?.getPosition?.()||{x:0,y:0,z:0},target:t}}))}resetCamera(){this._orbit&&(this._orbit.target={x:0,y:0,z:0},this._orbit.distance=10,this._orbit.pitch=-15,this._orbit.yaw=45,this._orbit.updateCameraPosition?.(),this.emit({type:"camera-change",detail:{position:this.entities.camera?.getPosition?.()||{x:0,y:0,z:0},target:{x:0,y:0,z:0}}}))}setCameraMode(t){this._cameraModeManager&&this._cameraModeManager.setMode(t)}setCameraFOV(t){this._sceneConfigManager&&this._sceneConfigManager.setCameraFOV(t)}getCameraFOV(){return this._sceneConfigManager?this._sceneConfigManager.getCameraFOV():this.entities.camera?.camera?.fov??60}async animateCameraFOV(t,e){this._sceneConfigManager&&await this._sceneConfigManager.animateCameraFOV(t,e)}setBackgroundColor(t){this._sceneConfigManager&&this._sceneConfigManager.setBackgroundColor(t)}getBackgroundColor(){return this._sceneConfigManager?this._sceneConfigManager.getBackgroundColor():{r:26,g:26,b:26,a:1}}async animateBackgroundColor(t,e){this._sceneConfigManager&&await this._sceneConfigManager.animateBackgroundColor(t,e)}getCameraMode(){return this._cameraModeManager?.getMode()||"orbit"}setFlyCameraConfig(t){this._cameraModeManager?.setFlyConfig(t)}getFlyCameraConfig(){return this._cameraModeManager?.getFlyConfig()||null}getFlyCameraState(){return this._cameraModeManager?.getFlyState()||null}_setupScene(){this.app&&(this.app.scene.ambientLight=new H(.2,.2,.2))}_setupCamera(){if(!this.app)return;const t=new U_("camera");t.addComponent("camera",{clearColor:new H(.1,.1,.1),nearClip:.01,farClip:1e6}),this.app.root.addChild(t),this.entities.camera=t}_setupLighting(){if(!this.app)return;const t=new U_("light");t.addComponent("light",{type:0,color:new H(1,1,1),intensity:1,castShadows:!0}),t.setLocalEulerAngles(45,30,0),this.app.root.addChild(t),this.entities.light=t}_setupOrbitCamera(){if(!this.app||!this.entities.camera)return;!function(){if(void 0===YL)return;if(!i_)return;if(i_?.scripts?.has("orbitCamera"))return;const t=Cw("orbitCamera");t&&(t.attributes.add("distance",{type:"number",default:10}),t.attributes.add("minDistance",{type:"number",default:.1}),t.attributes.add("maxDistance",{type:"number",default:1e5}),t.attributes.add("orbitSensitivity",{type:"number",default:.3}),t.attributes.add("panSensitivity",{type:"number",default:1}),t.attributes.add("zoomSensitivity",{type:"number",default:.1}),t.attributes.add("enableNavigationCube",{type:"boolean",default:!1}),t.attributes.add("navigationCubeConfig",{type:"json",default:null}),t.prototype.initialize=function(){if(this.target=new K(0,0,0),this.distance=this.distance||10,this.pitch=-15,this.yaw=45,this.isOrbiting=!1,this.isPanning=!1,this.setupContextMenuPrevention(),this.app.mouse.on(lM,this.onMouseDown,this),this.app.mouse.on(cM,this.onMouseUp,this),this.app.mouse.on(hM,this.onMouseMove,this),this.app.mouse.on(dM,this.onMouseWheel,this),this.updateCameraPosition(),this.enableNavigationCube)try{let t=this.navigationCubeConfig||{};this.entity._navigationCubeConfig&&(t=this.entity._navigationCubeConfig),this.navigationCube=new Sz(t),this.navigationCube.initialize(this.app,this.entity,this,this.emitInteractionEvent)}catch(t){delete this.navigationCube}},t.prototype.update=function(t){this.navigationCube&&"function"==typeof this.navigationCube.update&&this.navigationCube.update(t)},t.prototype.onMouseDown=function(t){this.navigationCube&&"function"==typeof this.navigationCube.cancelTransition&&this.navigationCube.cancelTransition("manual-interaction"),0===t.button?(this.isOrbiting=!0,this.emitInteractionEvent?.("interaction-start","rotate")):2!==t.button&&1!==t.button||(this.isPanning=!0,this.emitInteractionEvent?.("interaction-start","pan"))},t.prototype.onMouseUp=function(){this.isOrbiting&&(this.isOrbiting=!1,this.emitInteractionEvent?.("interaction-end","rotate")),this.isPanning&&(this.isPanning=!1,this.emitInteractionEvent?.("interaction-end","pan"))},t.prototype.onMouseMove=function(t){if(this.isOrbiting){const e=t.dx*this.orbitSensitivity,i=t.dy*this.orbitSensitivity;this.yaw-=e,this.pitch+=i,this.pitch=Math.max(-89,Math.min(89,this.pitch)),this.updateCameraPosition()}else if(this.isPanning){const e=this.distance*this.panSensitivity*.001,i=this.entity.getWorldTransform(),s=new K,n=new K;i.getX(s),i.getY(n);const r=s.clone().mulScalar(-t.dx*e).add(n.clone().mulScalar(t.dy*e));this.target.add(r),this.updateCameraPosition()}},t.prototype.onMouseWheel=function(t){this.navigationCube&&"function"==typeof this.navigationCube.cancelTransition&&this.navigationCube.cancelTransition("manual-interaction"),this.emitInteractionEvent?.("interaction-start","zoom");const e=Math.sign(t.wheel)*this.distance*this.zoomSensitivity;this.distance=Math.max(this.minDistance,Math.min(this.maxDistance,this.distance-e)),this.updateCameraPosition(),this.emitInteractionEvent?.("interaction-end","zoom")},t.prototype.updateCameraPosition=function(){const t=this.pitch*Math.PI/180,e=this.yaw*Math.PI/180,i=this.distance*Math.cos(t)*Math.sin(e),s=this.distance*Math.sin(t),n=this.distance*Math.cos(t)*Math.cos(e);this.entity.setPosition(new K(i,s,n).add(this.target)),this.entity.lookAt(this.target,K.UP),this.navigationCube&&"function"==typeof this.navigationCube.syncWithCamera&&this.navigationCube.syncWithCamera(this.pitch,this.yaw)},t.prototype.focus=function(t){const e=new K(0,0,0);let i=10,s=!1;if(t){const n=t.gsplat;if(n){const t=n.bounds||n.boundingBox;t?.center&&t.halfExtents?(e.copy(t.center),i=Math.max(1,t.halfExtents.length()),s=!0):"number"==typeof n.radius&&n.center&&(e.copy(n.center),i=Math.max(1,n.radius),s=!0)}if(!s&&t._calculateHierarchyBounds){const n=new ut;t.getWorldTransform(),t._calculateHierarchyBounds(n),n.halfExtents.length()>0&&(e.copy(n.center),i=Math.max(1,n.halfExtents.length()),s=!0)}}const n=this.entity.camera.fov*Math.PI/180,r=i/Math.sin(n/2)*1.5;this.target.copy(e),this.distance=Math.max(this.minDistance,Math.min(this.maxDistance,r)),this.pitch=-15,this.yaw=45,this.updateCameraPosition()},t.prototype.setupContextMenuPrevention=function(){[this.app.graphicsDevice.canvas,document.querySelector("canvas")].filter(Boolean).forEach(t=>{this._contextMenuHandler&&(t.removeEventListener("contextmenu",this._contextMenuHandler),t.removeEventListener("mousedown",this._mouseDownHandler),t.removeEventListener("mouseup",this._mouseUpHandler)),this._contextMenuHandler=t=>(t.preventDefault(),t.stopPropagation(),!1),this._mouseDownHandler=t=>{2===t.button&&(t.preventDefault(),t.stopPropagation())},this._mouseUpHandler=t=>{2===t.button&&(t.preventDefault(),t.stopPropagation())},t.addEventListener("contextmenu",this._contextMenuHandler,{passive:!1}),t.addEventListener("mousedown",this._mouseDownHandler,{passive:!1}),t.addEventListener("mouseup",this._mouseUpHandler,{passive:!1})})},t.prototype.destroy=function(){if(this.navigationCube&&"function"==typeof this.navigationCube.destroy){try{this.navigationCube.destroy()}catch(t){}delete this.navigationCube}[this.app?.graphicsDevice?.canvas,document.querySelector("canvas")].filter(Boolean).forEach(t=>{this._contextMenuHandler&&t.removeEventListener("contextmenu",this._contextMenuHandler),this._mouseDownHandler&&t.removeEventListener("mousedown",this._mouseDownHandler),this._mouseUpHandler&&t.removeEventListener("mouseup",this._mouseUpHandler)}),this.app?.mouse&&(this.app.mouse.off(lM,this.onMouseDown,this),this.app.mouse.off(cM,this.onMouseUp,this),this.app.mouse.off(hM,this.onMouseMove,this),this.app.mouse.off(dM,this.onMouseWheel,this))})}(),this.entities.camera.addComponent("script");const t={distance:10,minDistance:.1,maxDistance:1e5,orbitSensitivity:.3,panSensitivity:1,zoomSensitivity:.1};this._navigationCubeConfig&&(t.enableNavigationCube=this._navigationCubeConfig.enabled||!1,this.entities.camera._navigationCubeConfig=this._navigationCubeConfig),this._orbit=this.entities.camera.script.create("orbitCamera",{attributes:t}),this._orbit.emitInteractionEvent=(t,e)=>{this.emit({type:t,detail:{type:e}})},this.entities.camera.setPosition(0,0,10),this.entities.camera.lookAt(K.ZERO);try{!function(){if(void 0===YL)return;if(!i_)return;if(i_?.scripts?.has("flyCamera"))return;const t=Cw("flyCamera");t&&(t.attributes.add("moveSpeed",{type:"number",default:5}),t.attributes.add("fastSpeedMultiplier",{type:"number",default:3}),t.attributes.add("slowSpeedMultiplier",{type:"number",default:.3}),t.attributes.add("lookSensitivity",{type:"number",default:.2}),t.attributes.add("invertY",{type:"boolean",default:!1}),t.attributes.add("keyBindings",{type:"json",default:{forward:"KeyW",backward:"KeyS",left:"KeyA",right:"KeyD",up:"KeyE",down:"KeyQ",fastMove:"ShiftLeft",slowMove:"ControlLeft"}}),t.attributes.add("smoothing",{type:"number",default:.8}),t.attributes.add("friction",{type:"number",default:.85}),t.attributes.add("enableCollision",{type:"boolean",default:!1}),t.attributes.add("minHeight",{type:"number",default:null}),t.attributes.add("maxHeight",{type:"number",default:null}),t.prototype.initialize=function(){this._isActive=!0,this._isPointerLocked=!1,this._pressed=new Set,this._velocity=new K(0,0,0),this._targetVelocity=new K(0,0,0),this._pitch=0,this._yaw=0;try{const t=this.entity.getEulerAngles?this.entity.getEulerAngles():{x:0,y:0,z:0};this._pitch=t.x||0,this._yaw=t.y||0}catch{}this._onKeyDown=this._handleKeyDown.bind(this),this._onKeyUp=this._handleKeyUp.bind(this),document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this._onMouseMove=this._handleMouseMove.bind(this),document.addEventListener("mousemove",this._onMouseMove),this._onPointerLockChange=this._handlePointerLockChange.bind(this),document.addEventListener("pointerlockchange",this._onPointerLockChange);const t=this.app.graphicsDevice.canvas;this._onClickToLock=t=>{0===t.button&&this._isActive&&this._requestPointerLock()},t.addEventListener("mousedown",this._onClickToLock)},t.prototype.update=function(t){if(!this._isActive)return;this._updateVelocity(t),this._applyMovement(t),this._applyRotation(),this._applyConstraints();const e=performance.now();if(!this._lastMoveEmitTime||e-this._lastMoveEmitTime>=100){const t=this.entity.getPosition?this.entity.getPosition():{x:0,y:0,z:0};this.emitFlyEvent?.("fly-camera-move",{position:{x:t.x,y:t.y,z:t.z},velocity:{x:this._velocity.x,y:this._velocity.y,z:this._velocity.z}}),this._lastMoveEmitTime=e}(!this._lastLookEmitTime||e-this._lastLookEmitTime>=100)&&(this.emitFlyEvent?.("fly-camera-look",{pitch:this._pitch,yaw:this._yaw}),this._lastLookEmitTime=e)},t.prototype.destroy=function(){this.deactivate()},t.prototype.activate=function(){if(this._isActive)return;this._isActive=!0,this._onKeyDown=this._onKeyDown||this._handleKeyDown.bind(this),this._onKeyUp=this._onKeyUp||this._handleKeyUp.bind(this),this._onMouseMove=this._onMouseMove||this._handleMouseMove.bind(this),this._onPointerLockChange=this._onPointerLockChange||this._handlePointerLockChange.bind(this),document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),document.addEventListener("mousemove",this._onMouseMove),document.addEventListener("pointerlockchange",this._onPointerLockChange);const t=this.app.graphicsDevice.canvas;this._onClickToLock=this._onClickToLock||(()=>this._requestPointerLock()),t.addEventListener("mousedown",this._onClickToLock)},t.prototype.deactivate=function(){if(!this._isActive)return;this._isActive=!1,this._exitPointerLock(),document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),document.removeEventListener("mousemove",this._onMouseMove),document.removeEventListener("pointerlockchange",this._onPointerLockChange);const t=this.app?.graphicsDevice?.canvas;t&&this._onClickToLock&&t.removeEventListener("mousedown",this._onClickToLock)},t.prototype.setConfig=function(t){void 0!==t.moveSpeed&&(this.moveSpeed=t.moveSpeed),void 0!==t.fastSpeedMultiplier&&(this.fastSpeedMultiplier=t.fastSpeedMultiplier),void 0!==t.slowSpeedMultiplier&&(this.slowSpeedMultiplier=t.slowSpeedMultiplier),void 0!==t.lookSensitivity&&(this.lookSensitivity=t.lookSensitivity),void 0!==t.invertY&&(this.invertY=t.invertY),void 0!==t.keyBindings&&(this.keyBindings=t.keyBindings),void 0!==t.smoothing&&(this.smoothing=t.smoothing),void 0!==t.friction&&(this.friction=t.friction),void 0!==t.enableCollision&&(this.enableCollision=t.enableCollision),void 0!==t.minHeight&&(this.minHeight=t.minHeight),void 0!==t.maxHeight&&(this.maxHeight=t.maxHeight)},t.prototype.getState=function(){const t=this.entity.getPosition?this.entity.getPosition():{x:0,y:0,z:0};return{position:{x:t.x,y:t.y,z:t.z},rotation:{pitch:this._pitch,yaw:this._yaw},velocity:{x:this._velocity.x,y:this._velocity.y,z:this._velocity.z},isMoving:Math.abs(this._velocity.x)+Math.abs(this._velocity.y)+Math.abs(this._velocity.z)>1e-4}},t.prototype._handleKeyDown=function(t){this._pressed.add(t.code)},t.prototype._handleKeyUp=function(t){this._pressed.delete(t.code)},t.prototype._handleMouseMove=function(t){if(!this._isPointerLocked||!this._isActive)return;const e=t.movementX*this.lookSensitivity,i=t.movementY*this.lookSensitivity*(this.invertY?1:-1);this._yaw=(this._yaw+e)%360,this._pitch=Math.max(-89,Math.min(89,this._pitch+i))},t.prototype._handlePointerLockChange=function(){const t=this.app.graphicsDevice.canvas;this._isPointerLocked=document.pointerLockElement===t},t.prototype._requestPointerLock=function(){const t=this.app.graphicsDevice.canvas;t.requestPointerLock&&t.requestPointerLock()},t.prototype._exitPointerLock=function(){if(document.exitPointerLock)try{document.exitPointerLock()}catch{}},t.prototype._updateVelocity=function(t){const e=this.keyBindings,i=this._pressed.has(e.forward)?1:0,s=this._pressed.has(e.backward)?1:0,n=this._pressed.has(e.left)?1:0,r=i-s,a=(this._pressed.has(e.right)?1:0)-n,o=(this._pressed.has(e.up)?1:0)-(this._pressed.has(e.down)?1:0),l=Math.hypot(a,r),h=l>0?a/l:0,c=l>0?r/l:0,d=this._getEffectiveSpeed(),u=this._yaw*Math.PI/180,f=this._pitch*Math.PI/180,p=new K(Math.cos(f)*Math.sin(u),Math.sin(f),Math.cos(f)*Math.cos(u)),m=new K(Math.sin(u-Math.PI/2),0,Math.cos(u-Math.PI/2)),_=K.UP.clone(),g=new K(0,0,0);g.add(p.mulScalar(c*d)),g.add(m.mulScalar(h*d)),g.add(_.mulScalar(o*d)),this._targetVelocity.copy(g),this._velocity.lerp(this._velocity,this._targetVelocity,Math.min(1,this.smoothing)),0===h&&0===c&&0===o&&(this._velocity.mulScalar(this.friction),this._velocity.length()<1e-4&&this._velocity.set(0,0,0))},t.prototype._applyMovement=function(t){if(0===this._velocity.length())return;const e=this.entity.getPosition?this.entity.getPosition().clone():new K(0,0,0);e.add(this._velocity.clone().mulScalar(t)),this.entity.setPosition(e)},t.prototype._applyRotation=function(){this.entity.setLocalEulerAngles?this.entity.setLocalEulerAngles(this._pitch,this._yaw,0):this.entity.setEulerAngles&&this.entity.setEulerAngles(this._pitch,this._yaw,0)},t.prototype._applyConstraints=function(){if(!this.enableCollision&&null==this.minHeight&&null==this.maxHeight)return;const t=this.entity.getPosition?this.entity.getPosition().clone():new K(0,0,0);null!=this.minHeight&&(t.y=Math.max(t.y,this.minHeight)),null!=this.maxHeight&&(t.y=Math.min(t.y,this.maxHeight)),this.entity.setPosition(t)},t.prototype._getEffectiveSpeed=function(){const t=this._pressed.has(this.keyBindings.fastMove),e=this._pressed.has(this.keyBindings.slowMove);let i=this.moveSpeed;return t&&(i*=this.fastSpeedMultiplier),e&&(i*=this.slowSpeedMultiplier),i})}();const t={moveSpeed:Ez.moveSpeed,fastSpeedMultiplier:Ez.fastSpeedMultiplier,slowSpeedMultiplier:Ez.slowSpeedMultiplier,lookSensitivity:Ez.lookSensitivity,invertY:Ez.invertY,keyBindings:Ez.keyBindings,smoothing:Ez.smoothing,friction:Ez.friction,enableCollision:Ez.enableCollision,minHeight:Ez.minHeight,maxHeight:Ez.maxHeight};this._fly=this.entities.camera.script.create("flyCamera",{attributes:t}),this._fly&&(this._fly.emitFlyEvent=(t,e)=>{this.emit({type:t,detail:e})}),this._fly?.deactivate&&this._fly.deactivate(),this._cameraModeManager=new qL(this.app,this.entities.camera,this._orbit,this._fly,(t,e)=>{this.emit({type:t,detail:e})},"orbit")}catch(t){}}_setupStats(){if(!this.app||!this.enableStats||!this._onStatsUpdate)return;let t=0,e=performance.now();this._statsHandler=()=>{t++;const i=performance.now(),s=i-e;if(s>=1e3){const n=Math.round(1e3*t/s),r=t=>"object"==typeof t&&null!==t?t.total||0:Number(t)||0,a=r(this.app.stats.triangles),o=r(this.app.stats.drawCalls),l={fps:n,frameTime:Math.round(s/t*100)/100,triangles:a,drawCalls:o,memoryUsage:performance.memory?Math.round(performance.memory.usedJSHeapSize/1024/1024):0};this._onStatsUpdate(l),this.emit({type:"stats-update",detail:l}),t=0,e=i}},this.app.on("frameend",this._statsHandler)}_setupResolution(){if(!this.app)return;const t=this.app.graphicsDevice.canvas;if(t.style.display||(t.style.display="block"),t.style.width||(t.style.width="100%"),t.style.height||(t.style.height="100%"),t.parentElement){const e=t.parentElement.style;e.width||(e.width="100%"),e.height||(e.height="100%")}const e=(e,i)=>{t.width===e&&t.height===i||(t.width=e,t.height=i,this.app.resizeCanvas(e,i),this._orbit&&this._orbit.navigationCube&&"function"==typeof this._orbit.navigationCube.onCanvasResize&&this._orbit.navigationCube.onCanvasResize())},i=()=>{const i=t.getBoundingClientRect(),s=window.devicePixelRatio||1,n=Math.floor(i.width*s),r=Math.floor(i.height*s);e(n,r)},s=t=>{let s=null,n=null;const r=t.devicePixelContentBoxSize;if(r&&r.length>0)s=Math.ceil(r[0].inlineSize),n=Math.ceil(r[0].blockSize);else{const e=t.contentBoxSize;if(e&&e.length>0){const t=window.devicePixelRatio||1;s=Math.ceil(e[0].inlineSize*t),n=Math.ceil(e[0].blockSize*t)}}null!==s&&null!==n?e(s,n):i()};if(i(),window.ResizeObserver){this._resizeObserver=new ResizeObserver(e=>{if(!e||0===e.length)return void i();const n=e.find(e=>e.target===t);if(n)s(n);else if(e.length>0){const t=e[0];t?s(t):i()}else i()});try{this._resizeObserver.observe(t,{box:"device-pixel-content-box"})}catch{this._resizeObserver.observe(t)}t.parentElement&&this._resizeObserver.observe(t.parentElement)}const n=()=>{i()};window.addEventListener("resize",n),this._resizeHandler=n}updateCanvasResolution(){if(!this.app)return;const t=this.app.graphicsDevice.canvas,e=t.getBoundingClientRect(),i=window.devicePixelRatio||1,s=Math.floor(e.width*i),n=Math.floor(e.height*i);t.width===s&&t.height===n||(t.width=s,t.height=n,this.app.resizeCanvas(s,n),this._orbit&&this._orbit.navigationCube&&"function"==typeof this._orbit.navigationCube.onCanvasResize&&this._orbit.navigationCube.onCanvasResize())}}function bz(t,e){return new CustomEvent(t,{detail:e})}class SplatViewerElement extends HTMLElement{constructor(){super(...arguments),this._core=null,this._canvas=null,this._config={...mz},this._isInitialized=!1,this._isDestroyed=!1,this._hostResizeObserver=null}static get observedAttributes(){return["src","width","height","enable-stats","auto-focus","max-splats","camera-position","camera-target","orbit-sensitivity","pan-sensitivity","zoom-sensitivity","min-distance","max-distance","enable-navigation-cube","navigation-cube-size","navigation-cube-transition","navigation-cube-parent-id"]}get src(){return this.getAttribute("src")}get width(){return this.getAttribute("width")}get height(){return this.getAttribute("height")}get enableStats(){return this.hasAttribute("enable-stats")}get autoFocus(){return this.hasAttribute("auto-focus")}get maxSplats(){return this.getAttribute("max-splats")}get cameraPosition(){return this.getAttribute("camera-position")}get cameraTarget(){return this.getAttribute("camera-target")}get orbitSensitivity(){return this.getAttribute("orbit-sensitivity")}get panSensitivity(){return this.getAttribute("pan-sensitivity")}get zoomSensitivity(){return this.getAttribute("zoom-sensitivity")}get minDistance(){return this.getAttribute("min-distance")}get maxDistance(){return this.getAttribute("max-distance")}get enableNavigationCube(){return this.hasAttribute("enable-navigation-cube")}get navigationCubeSize(){return this.getAttribute("navigation-cube-size")}get navigationCubeTransition(){return this.getAttribute("navigation-cube-transition")}get navigationCubeParentId(){return this.getAttribute("navigation-cube-parent-id")}set src(t){null===t?this.removeAttribute("src"):this.setAttribute("src",t)}set width(t){null===t?this.removeAttribute("width"):this.setAttribute("width",t)}set height(t){null===t?this.removeAttribute("height"):this.setAttribute("height",t)}set enableStats(t){t?this.setAttribute("enable-stats",""):this.removeAttribute("enable-stats")}set autoFocus(t){t?this.setAttribute("auto-focus",""):this.removeAttribute("auto-focus")}set maxSplats(t){null===t?this.removeAttribute("max-splats"):this.setAttribute("max-splats",t)}set cameraPosition(t){null===t?this.removeAttribute("camera-position"):this.setAttribute("camera-position",t)}set cameraTarget(t){null===t?this.removeAttribute("camera-target"):this.setAttribute("camera-target",t)}set orbitSensitivity(t){null===t?this.removeAttribute("orbit-sensitivity"):this.setAttribute("orbit-sensitivity",t)}set panSensitivity(t){null===t?this.removeAttribute("pan-sensitivity"):this.setAttribute("pan-sensitivity",t)}set zoomSensitivity(t){null===t?this.removeAttribute("zoom-sensitivity"):this.setAttribute("zoom-sensitivity",t)}set minDistance(t){null===t?this.removeAttribute("min-distance"):this.setAttribute("min-distance",t)}set maxDistance(t){null===t?this.removeAttribute("max-distance"):this.setAttribute("max-distance",t)}set enableNavigationCube(t){t?this.setAttribute("enable-navigation-cube",""):this.removeAttribute("enable-navigation-cube")}set navigationCubeSize(t){null===t?this.removeAttribute("navigation-cube-size"):this.setAttribute("navigation-cube-size",t)}set navigationCubeTransition(t){null===t?this.removeAttribute("navigation-cube-transition"):this.setAttribute("navigation-cube-transition",t)}set navigationCubeParentId(t){null===t?this.removeAttribute("navigation-cube-parent-id"):this.setAttribute("navigation-cube-parent-id",t)}connectedCallback(){this._isDestroyed||this._initialize()}disconnectedCallback(){this._destroy()}attributeChangedCallback(t,e,i){if(e!==i&&(null===i||this._validateAttribute(t,i)))switch(this._updateConfigFromAttributes(),t){case"src":this._handleSrcChange(i);break;case"width":case"height":this._handleSizeChange();break;case"enable-stats":this._handleStatsChange()}}_validateAttribute(t,e){switch(t){case"width":case"height":return/^(\d+(\.\d+)?(px|%|em|rem|vh|vw|vmin|vmax)?|\d+)$/.test(e);case"max-splats":const t=parseInt(e,10);return!isNaN(t)&&t>0;case"orbit-sensitivity":case"pan-sensitivity":case"zoom-sensitivity":const i=parseFloat(e);return!isNaN(i)&&i>0;case"min-distance":case"max-distance":const s=parseFloat(e);return!isNaN(s)&&s>0;case"camera-position":case"camera-target":try{const t=JSON.parse(e);return Array.isArray(t)&&3===t.length&&t.every(t=>"number"==typeof t&&!isNaN(t))}catch{return!1}case"src":return e.length>0;case"enable-stats":case"auto-focus":case"enable-navigation-cube":return!0;case"navigation-cube-size":const n=parseFloat(e);return!isNaN(n)&&n>0;case"navigation-cube-transition":const r=parseFloat(e);return!isNaN(r)&&r>0;case"navigation-cube-parent-id":return e.length>0;default:return!0}}async _initialize(){if(!this._isInitialized)try{this.style.display="block",this.style.position="relative",this.style.overflow="hidden",this.hasAttribute("width")||this.style.width||(this.style.width="100%"),this.hasAttribute("height")||this.style.height||(this.style.height="100%"),this._canvas=document.createElement("canvas"),this._canvas.style.display="block",this._canvas.style.width="100%",this._canvas.style.height="100%",this._canvas.style.outline="none",this._canvas.style.userSelect="none",this._canvas.style.touchAction="none",this._canvas.setAttribute("tabindex","0"),this._canvas.setAttribute("role","img"),this._canvas.setAttribute("aria-label","3D Splat Viewer"),this.appendChild(this._canvas);try{window.ResizeObserver&&(this._hostResizeObserver=new ResizeObserver(()=>{try{this._core?.updateCanvasResolution()}catch{}}),this._hostResizeObserver.observe(this),this.parentElement&&this._hostResizeObserver.observe(this.parentElement))}catch{}this._updateConfigFromAttributes(),this._core=new SplatViewerCore(this._config),this._core.init(this._canvas),this._setupEventListeners(),this._handleSizeChange();const t=this.src;t&&await this.load(t),this._isInitialized=!0,this.dispatchEvent(bz("ready",void 0))}catch(t){this._cleanupOnError(),this.dispatchEvent(bz("error",{message:`Failed to initialize: ${t instanceof Error?t.message:"Unknown error"}`,code:"INIT_FAILED"}))}}_cleanupOnError(){try{this._core&&(this._core.destroy(),this._core=null),this._canvas&&this._canvas.parentNode&&(this._canvas.parentNode.removeChild(this._canvas),this._canvas=null),this._isInitialized=!1}catch(t){}}_destroy(){if(!this._isDestroyed)try{this._hostResizeObserver&&(this._hostResizeObserver.disconnect(),this._hostResizeObserver=null),this._core&&(this._core.destroy(),this._core=null),this._canvas&&this._canvas.parentNode&&(this._canvas.parentNode.removeChild(this._canvas),this._canvas=null),this._isDestroyed=!0,this._isInitialized=!1}catch(t){}}_updateConfigFromAttributes(){const t=function(t){const e={},i=t.getAttribute("auto-focus");null!==i&&(e.autoFocus=gz(i));const s=t.getAttribute("enable-stats");null!==s&&(e.enableStats=gz(s));const n=t.getAttribute("max-splats");null!==n&&(e.maxSplats=vz(n,mz.maxSplats));const r=t.getAttribute("camera-position"),a=t.getAttribute("camera-target");if(r||a){const t=_z(r),i=_z(a);e.camera={...mz.camera,...t&&{position:t},...i&&{target:i}}}const o=t.getAttribute("enable-navigation-cube");null!==o&&(e.navigationCube={...mz.navigationCube,enabled:gz(o)});const l=t.getAttribute("navigation-cube-size");null!==l&&(e.navigationCube={...mz.navigationCube,...e.navigationCube,cubeSize:vz(l,mz.navigationCube.cubeSize)});const h=t.getAttribute("navigation-cube-transition");null!==h&&(e.navigationCube={...mz.navigationCube,...e.navigationCube,transitionDuration:vz(h,mz.navigationCube.transitionDuration)});const c=t.getAttribute("navigation-cube-parent-id");null!==c&&(e.navigationCube={...mz.navigationCube,...e.navigationCube,enabled:!0,parentElementId:c});const d=t.getAttribute("navigation-cube-rotation-speed");return null!==d&&(e.navigationCube={...mz.navigationCube,...e.navigationCube,continuousRotationSpeed:vz(d,mz.navigationCube.continuousRotationSpeed)}),e}(this);var e,i;this._config=(e=mz,i=t,{...e,...i,camera:{...e.camera,...i.camera},navigationCube:{...e.navigationCube,...i.navigationCube}})}_validateSource(t){if(!t||"string"!=typeof t)return!1;if(0===t.trim().length)return!1;try{return new URL(t),!0}catch{return!!t.startsWith("data:")||!(!t.startsWith("./")&&!t.startsWith("../")&&t.includes("://"))}}async _handleSrcChange(t){if(this._core&&t)if(this._validateSource(t))try{await this.load(t)}catch(t){await this._handleError(t,"LOAD_FAILED")}else this.dispatchEvent(bz("error",{message:`Invalid source: ${t}`,code:"INVALID_SOURCE"}))}_handleSizeChange(){if(!this._canvas)return;const t=this.width,e=this.height;if(t){const e=/(px|%|em|rem|vh|vw|vmin|vmax)$/.test(t);this.style.width=e?t:`${t}px`}else this.style.width="100%";if(e){const t=/(px|%|em|rem|vh|vw|vmin|vmax)$/.test(e);this.style.height=t?e:`${e}px`}else this.style.height="100%";this._canvas.style.width="100%",this._canvas.style.height="100%"}_handleStatsChange(){this._core}_setupEventListeners(){this._core&&(this._core.on("loading-start",t=>{this.dispatchEvent(bz("loading-start",t.detail))}),this._core.on("loading-progress",t=>{this.dispatchEvent(bz("loading-progress",t.detail))}),this._core.on("loaded",t=>{this.dispatchEvent(bz("loaded",t.detail))}),this._core.on("error",t=>{this.dispatchEvent(bz("error",t.detail))}),this._core.on("camera-change",t=>{this.dispatchEvent(bz("camera-change",t.detail))}),this._core.on("interaction-start",t=>{this.dispatchEvent(bz("interaction-start",t.detail))}),this._core.on("interaction-end",t=>{this.dispatchEvent(bz("interaction-end",t.detail))}),this._core.on("camera-mode-changed",t=>{this.dispatchEvent(bz("camera-mode-changed",t.detail))}),this._core.on("fly-camera-move",t=>{this.dispatchEvent(bz("fly-camera-move",t.detail))}),this._core.on("fly-camera-look",t=>{this.dispatchEvent(bz("fly-camera-look",t.detail))}),this._core.on("camera-fov-changed",t=>{this.dispatchEvent(bz("camera-fov-changed",t.detail))}),this._core.on("background-color-changed",t=>{this.dispatchEvent(bz("background-color-changed",t.detail))}),this._core.on("model-added",t=>{this.dispatchEvent(bz("model-added",t.detail))}),this._core.on("model-removed",t=>{this.dispatchEvent(bz("model-removed",t.detail))}),this._core.on("scene-cleared",t=>{this.dispatchEvent(bz("scene-cleared",t.detail))}))}async load(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");if("string"==typeof t){if(!this._validateSource(t))throw new Error(`Invalid source string: ${t}`)}else if(t instanceof File){if(0===t.size)throw new Error("File is empty")}else{if(!(t instanceof Blob))throw new Error("Invalid source type. Expected string, File, or Blob.");if(0===t.size)throw new Error("Blob is empty")}try{return await this._core.load(t,e)}catch(t){if(await this._handleError(t,"LOAD_FAILED"),t instanceof Error)throw new Error(`Failed to load model: ${t.message}`);throw new Error("Failed to load model: Unknown error")}}async loadFile(t,e){return this.load(t,e)}async loadBlob(t,e){return this.load(t,e)}focus(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.focus(t)}setCameraPosition(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setCameraPosition(t)}setCameraTarget(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setCameraTarget(t)}resetCamera(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.resetCamera()}clear(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.clear()}getDebugInfo(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.debugInfo()}get isReady(){return this._isInitialized&&!this._isDestroyed&&null!==this._core}get config(){return{...this._config}}async _handleError(t,e){const i="string"==typeof t?t:t?.message||"Unknown error";this.dispatchEvent(bz("error",{message:e?`${e}: ${i}`:i,code:e||"ERROR"}))}async addModel(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return await this._core.addModel(t,e)}removeModel(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.removeModel(t)}getModels(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getModels()}getModelStats(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getModelStats(t)}getAllModelStats(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getAllModelStats()}getSceneStats(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getSceneStats()}setCameraMode(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setCameraMode(t)}getCameraMode(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getCameraMode()}setFlyCameraConfig(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setFlyCameraConfig(t)}getFlyCameraConfig(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getFlyCameraConfig()}getFlyCameraState(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getFlyCameraState()}setCameraFOV(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setCameraFOV(t)}getCameraFOV(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getCameraFOV()}async animateCameraFOV(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");await this._core.animateCameraFOV(t,e)}setBackgroundColor(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setBackgroundColor(t)}getBackgroundColor(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getBackgroundColor()}async animateBackgroundColor(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");await this._core.animateBackgroundColor(t,e)}applyTransformMatrix(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.applyTransformMatrix(t,e)}setModelPosition(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setModelPosition(t,e)}setModelRotation(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setModelRotation(t,e)}setModelScale(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setModelScale(t,e)}getModelTransform(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getModelTransform(t)}resetModelTransform(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.resetModelTransform(t)}}customElements.get("splat-viewer")||customElements.define("splat-viewer",SplatViewerElement),t.SplatViewerElement=SplatViewerElement,t.default=SplatViewerElement,Object.defineProperty(t,"__esModule",{value:!0})});
|
|
6
|
+
*/const sD="157",nD=0,rD=1,aD=2,oD=100,lD=101,hD=102,cD=200,dD=201,uD=202,fD=203,pD=204,mD=205,_D=206,gD=207,vD=208,SD=209,yD=210,xD=301,TD=302,ED=306,bD=1e3,wD=1001,AD=1002,CD=1003,MD=1004,PD=1005,RD=1006,LD=1007,DD=1008,ID=1009,OD=1012,ND=1013,FD=1014,UD=1015,BD=1016,zD=1020,kD=1023,VD=1026,HD=1027,GD=33776,WD=33777,XD=33778,YD=33779,qD=36492,jD=3001,$D="",KD="srgb",ZD="srgb-linear",QD="display-p3",JD="display-p3-linear",tI="linear",eI="srgb",iI="rec709",sI="p3",nI=7680,rI=512,aI=513,oI=514,lI=515,hI=516,cI=517,dI=518,uI=519,fI="300 es",pI=1035,mI=2e3,_I=2001;class gI{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const i=this._listeners;void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(e)&&i[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const i=this._listeners;return void 0!==i[t]&&-1!==i[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const i=this._listeners[t];if(void 0!==i){const t=i.indexOf(e);-1!==t&&i.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 i=e.slice(0);for(let e=0,s=i.length;e<s;e++)i[e].call(this,t);t.target=null}}}const vI=["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"],SI=Math.PI/180,yI=180/Math.PI;function xI(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,s=4294967295*Math.random()|0;return(vI[255&t]+vI[t>>8&255]+vI[t>>16&255]+vI[t>>24&255]+"-"+vI[255&e]+vI[e>>8&255]+"-"+vI[e>>16&15|64]+vI[e>>24&255]+"-"+vI[63&i|128]+vI[i>>8&255]+"-"+vI[i>>16&255]+vI[i>>24&255]+vI[255&s]+vI[s>>8&255]+vI[s>>16&255]+vI[s>>24&255]).toLowerCase()}function TI(t,e,i){return Math.max(e,Math.min(i,t))}function EI(t,e,i){return(1-i)*t+i*e}function bI(t){return!(t&t-1)&&0!==t}function wI(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function AI(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 CI(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.")}}class MI{constructor(t=0,e=0){MI.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6],this.y=s[1]*e+s[4]*i+s[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=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 i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(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 i=this.dot(t)/e;return Math.acos(TI(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),s=Math.sin(e),n=this.x-t.x,r=this.y-t.y;return this.x=n*i-r*s+t.x,this.y=n*s+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class PI{constructor(t,e,i,s,n,r,a,o,l){PI.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,i,s,n,r,a,o,l)}set(t,e,i,s,n,r,a,o,l){const h=this.elements;return h[0]=t,h[1]=s,h[2]=a,h[3]=e,h[4]=n,h[5]=o,h[6]=i,h[7]=r,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[3],o=i[6],l=i[1],h=i[4],c=i[7],d=i[2],u=i[5],f=i[8],p=s[0],m=s[3],_=s[6],g=s[1],v=s[4],S=s[7],y=s[2],x=s[5],T=s[8];return n[0]=r*p+a*g+o*y,n[3]=r*m+a*v+o*x,n[6]=r*_+a*S+o*T,n[1]=l*p+h*g+c*y,n[4]=l*m+h*v+c*x,n[7]=l*_+h*S+c*T,n[2]=d*p+u*g+f*y,n[5]=d*m+u*v+f*x,n[8]=d*_+u*S+f*T,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8];return e*r*h-e*a*l-i*n*h+i*a*o+s*n*l-s*r*o}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8],c=h*r-a*l,d=a*o-h*n,u=l*n-r*o,f=e*c+i*d+s*u;if(0===f)return this.set(0,0,0,0,0,0,0,0,0);const p=1/f;return t[0]=c*p,t[1]=(s*l-h*i)*p,t[2]=(a*i-s*r)*p,t[3]=d*p,t[4]=(h*e-s*o)*p,t[5]=(s*n-a*e)*p,t[6]=u*p,t[7]=(i*o-l*e)*p,t[8]=(r*e-i*n)*p,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,s,n,r,a){const o=Math.cos(n),l=Math.sin(n);return this.set(i*o,i*l,-i*(o*r+l*a)+r+t,-s*l,s*o,-s*(-l*r+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(RI.makeScale(t,e)),this}rotate(t){return this.premultiply(RI.makeRotation(-t)),this}translate(t,e){return this.premultiply(RI.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,i,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,i=t.elements;for(let t=0;t<9;t++)if(e[t]!==i[t])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const RI=new PI;function LI(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}function DI(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function II(){const t=DI("canvas");return t.style.display="block",t}const OI={};function NI(t){t in OI||(OI[t]=!0)}const FI=(new PI).set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),UI=(new PI).set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),BI={[ZD]:{transfer:tI,primaries:iI,toReference:t=>t,fromReference:t=>t},[KD]:{transfer:eI,primaries:iI,toReference:t=>t.convertSRGBToLinear(),fromReference:t=>t.convertLinearToSRGB()},[JD]:{transfer:tI,primaries:sI,toReference:t=>t.applyMatrix3(UI),fromReference:t=>t.applyMatrix3(FI)},[QD]:{transfer:eI,primaries:sI,toReference:t=>t.convertSRGBToLinear().applyMatrix3(UI),fromReference:t=>t.applyMatrix3(FI).convertLinearToSRGB()}},zI=new Set([ZD,JD]),kI={enabled:!0,_workingColorSpace:ZD,get legacyMode(){return!this.enabled},set legacyMode(t){this.enabled=!t},get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(t){if(!zI.has(t))throw new Error(`Unsupported working color space, "${t}".`);this._workingColorSpace=t},convert:function(t,e,i){if(!1===this.enabled||e===i||!e||!i)return t;const s=BI[e].toReference;return(0,BI[i].fromReference)(s(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 BI[t].primaries},getTransfer:function(t){return t===$D?tI:BI[t].transfer}};function VI(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function HI(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let GI;class WI{static getDataURL(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===GI&&(GI=DI("canvas")),GI.width=t.width,GI.height=t.height;const i=GI.getContext("2d");t instanceof ImageData?i.putImageData(t,0,0):i.drawImage(t,0,0,t.width,t.height),e=GI}return e.width>2048||e.height>2048?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=DI("canvas");e.width=t.width,e.height=t.height;const i=e.getContext("2d");i.drawImage(t,0,0,t.width,t.height);const s=i.getImageData(0,0,t.width,t.height),n=s.data;for(let t=0;t<n.length;t++)n[t]=255*VI(n[t]/255);return i.putImageData(s,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*VI(e[t]/255)):e[t]=VI(e[t]);return{data:e,width:t.width,height:t.height}}return t}}let XI=0;class YI{constructor(t=null){this.isSource=!0,Object.defineProperty(this,"id",{value:XI++}),this.uuid=xI(),this.data=t,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 i={uuid:this.uuid,url:""},s=this.data;if(null!==s){let t;if(Array.isArray(s)){t=[];for(let e=0,i=s.length;e<i;e++)s[e].isDataTexture?t.push(qI(s[e].image)):t.push(qI(s[e]))}else t=qI(s);i.url=t}return e||(t.images[this.uuid]=i),i}}function qI(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?WI.getDataURL(t):t.data?{data:Array.from(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:{}}let jI=0;class $I extends gI{constructor(t=$I.DEFAULT_IMAGE,e=$I.DEFAULT_MAPPING,i=1001,s=1001,n=1006,r=1008,a=1023,o=1009,l=$I.DEFAULT_ANISOTROPY,h=""){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:jI++}),this.uuid=xI(),this.name="",this.source=new YI(t),this.mipmaps=[],this.mapping=e,this.channel=0,this.wrapS=i,this.wrapT=s,this.magFilter=n,this.minFilter=r,this.anisotropy=l,this.format=a,this.internalFormat=null,this.type=o,this.offset=new MI(0,0),this.repeat=new MI(1,1),this.center=new MI(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new PI,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,"string"==typeof h?this.colorSpace=h:(NI("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace=h===jD?KD:$D),this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.needsPMREMUpdate=!1}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 i={metadata:{version:4.6,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(300!==this.mapping)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case bD:t.x=t.x-Math.floor(t.x);break;case wD:t.x=t.x<0?0:1;break;case AD: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 bD:t.y=t.y-Math.floor(t.y);break;case wD:t.y=t.y<0?0:1;break;case AD: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)}get encoding(){return NI("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace===KD?jD:3e3}set encoding(t){NI("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace=t===jD?KD:$D}}$I.DEFAULT_IMAGE=null,$I.DEFAULT_MAPPING=300,$I.DEFAULT_ANISOTROPY=1;class KI{constructor(t=0,e=0,i=0,s=1){KI.prototype.isVector4=!0,this.x=t,this.y=e,this.z=i,this.w=s}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,s){return this.x=t,this.y=e,this.z=i,this.w=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=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,i=this.y,s=this.z,n=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*s+r[12]*n,this.y=r[1]*e+r[5]*i+r[9]*s+r[13]*n,this.z=r[2]*e+r[6]*i+r[10]*s+r[14]*n,this.w=r[3]*e+r[7]*i+r[11]*s+r[15]*n,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,s,n;const r=.01,a=.1,o=t.elements,l=o[0],h=o[4],c=o[8],d=o[1],u=o[5],f=o[9],p=o[2],m=o[6],_=o[10];if(Math.abs(h-d)<r&&Math.abs(c-p)<r&&Math.abs(f-m)<r){if(Math.abs(h+d)<a&&Math.abs(c+p)<a&&Math.abs(f+m)<a&&Math.abs(l+u+_-3)<a)return this.set(1,0,0,0),this;e=Math.PI;const t=(l+1)/2,o=(u+1)/2,g=(_+1)/2,v=(h+d)/4,S=(c+p)/4,y=(f+m)/4;return t>o&&t>g?t<r?(i=0,s=.707106781,n=.707106781):(i=Math.sqrt(t),s=v/i,n=S/i):o>g?o<r?(i=.707106781,s=0,n=.707106781):(s=Math.sqrt(o),i=v/s,n=y/s):g<r?(i=.707106781,s=.707106781,n=0):(n=Math.sqrt(g),i=S/n,s=y/n),this.set(i,s,n,e),this}let g=Math.sqrt((m-f)*(m-f)+(c-p)*(c-p)+(d-h)*(d-h));return Math.abs(g)<.001&&(g=1),this.x=(m-f)/g,this.y=(c-p)/g,this.z=(d-h)/g,this.w=Math.acos((l+u+_-1)/2),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 i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class ZI extends gI{constructor(t=1,e=1,i={}){super(),this.isRenderTarget=!0,this.width=t,this.height=e,this.depth=1,this.scissor=new KI(0,0,t,e),this.scissorTest=!1,this.viewport=new KI(0,0,t,e);const s={width:t,height:e,depth:1};void 0!==i.encoding&&(NI("THREE.WebGLRenderTarget: option.encoding has been replaced by option.colorSpace."),i.colorSpace=i.encoding===jD?KD:$D),i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:RD,depthBuffer:!0,stencilBuffer:!1,depthTexture:null,samples:0},i),this.texture=new $I(s,i.mapping,i.wrapS,i.wrapT,i.magFilter,i.minFilter,i.format,i.type,i.anisotropy,i.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.flipY=!1,this.texture.generateMipmaps=i.generateMipmaps,this.texture.internalFormat=i.internalFormat,this.depthBuffer=i.depthBuffer,this.stencilBuffer=i.stencilBuffer,this.depthTexture=i.depthTexture,this.samples=i.samples}setSize(t,e,i=1){this.width===t&&this.height===e&&this.depth===i||(this.width=t,this.height=e,this.depth=i,this.texture.image.width=t,this.texture.image.height=e,this.texture.image.depth=i,this.dispose()),this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return(new this.constructor).copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.texture=t.texture.clone(),this.texture.isRenderTargetTexture=!0;const e=Object.assign({},t.texture.image);return this.texture.source=new YI(e),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,null!==t.depthTexture&&(this.depthTexture=t.depthTexture.clone()),this.samples=t.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class QI extends ZI{constructor(t=1,e=1,i={}){super(t,e,i),this.isWebGLRenderTarget=!0}}class JI extends $I{constructor(t=null,e=1,i=1,s=1){super(null),this.isDataArrayTexture=!0,this.image={data:t,width:e,height:i,depth:s},this.magFilter=CD,this.minFilter=CD,this.wrapR=wD,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class tO extends $I{constructor(t=null,e=1,i=1,s=1){super(null),this.isData3DTexture=!0,this.image={data:t,width:e,height:i,depth:s},this.magFilter=CD,this.minFilter=CD,this.wrapR=wD,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class eO{constructor(t=0,e=0,i=0,s=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=i,this._w=s}static slerpFlat(t,e,i,s,n,r,a){let o=i[s+0],l=i[s+1],h=i[s+2],c=i[s+3];const d=n[r+0],u=n[r+1],f=n[r+2],p=n[r+3];if(0===a)return t[e+0]=o,t[e+1]=l,t[e+2]=h,void(t[e+3]=c);if(1===a)return t[e+0]=d,t[e+1]=u,t[e+2]=f,void(t[e+3]=p);if(c!==p||o!==d||l!==u||h!==f){let t=1-a;const e=o*d+l*u+h*f+c*p,i=e>=0?1:-1,s=1-e*e;if(s>Number.EPSILON){const n=Math.sqrt(s),r=Math.atan2(n,e*i);t=Math.sin(t*r)/n,a=Math.sin(a*r)/n}const n=a*i;if(o=o*t+d*n,l=l*t+u*n,h=h*t+f*n,c=c*t+p*n,t===1-a){const t=1/Math.sqrt(o*o+l*l+h*h+c*c);o*=t,l*=t,h*=t,c*=t}}t[e]=o,t[e+1]=l,t[e+2]=h,t[e+3]=c}static multiplyQuaternionsFlat(t,e,i,s,n,r){const a=i[s],o=i[s+1],l=i[s+2],h=i[s+3],c=n[r],d=n[r+1],u=n[r+2],f=n[r+3];return t[e]=a*f+h*c+o*u-l*d,t[e+1]=o*f+h*d+l*c-a*u,t[e+2]=l*f+h*u+a*d-o*c,t[e+3]=h*f-a*c-o*d-l*u,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,s){return this._x=t,this._y=e,this._z=i,this._w=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e){const i=t._x,s=t._y,n=t._z,r=t._order,a=Math.cos,o=Math.sin,l=a(i/2),h=a(s/2),c=a(n/2),d=o(i/2),u=o(s/2),f=o(n/2);switch(r){case"XYZ":this._x=d*h*c+l*u*f,this._y=l*u*c-d*h*f,this._z=l*h*f+d*u*c,this._w=l*h*c-d*u*f;break;case"YXZ":this._x=d*h*c+l*u*f,this._y=l*u*c-d*h*f,this._z=l*h*f-d*u*c,this._w=l*h*c+d*u*f;break;case"ZXY":this._x=d*h*c-l*u*f,this._y=l*u*c+d*h*f,this._z=l*h*f+d*u*c,this._w=l*h*c-d*u*f;break;case"ZYX":this._x=d*h*c-l*u*f,this._y=l*u*c+d*h*f,this._z=l*h*f-d*u*c,this._w=l*h*c+d*u*f;break;case"YZX":this._x=d*h*c+l*u*f,this._y=l*u*c+d*h*f,this._z=l*h*f-d*u*c,this._w=l*h*c-d*u*f;break;case"XZY":this._x=d*h*c-l*u*f,this._y=l*u*c-d*h*f,this._z=l*h*f+d*u*c,this._w=l*h*c+d*u*f}return!1!==e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,s=Math.sin(i);return this._x=t.x*s,this._y=t.y*s,this._z=t.z*s,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],s=e[4],n=e[8],r=e[1],a=e[5],o=e[9],l=e[2],h=e[6],c=e[10],d=i+a+c;if(d>0){const t=.5/Math.sqrt(d+1);this._w=.25/t,this._x=(h-o)*t,this._y=(n-l)*t,this._z=(r-s)*t}else if(i>a&&i>c){const t=2*Math.sqrt(1+i-a-c);this._w=(h-o)/t,this._x=.25*t,this._y=(s+r)/t,this._z=(n+l)/t}else if(a>c){const t=2*Math.sqrt(1+a-i-c);this._w=(n-l)/t,this._x=(s+r)/t,this._y=.25*t,this._z=(o+h)/t}else{const t=2*Math.sqrt(1+c-i-a);this._w=(r-s)/t,this._x=(n+l)/t,this._y=(o+h)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<Number.EPSILON?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(TI(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(0===i)return this;const s=Math.min(1,e/i);return this.slerp(t,s),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 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 i=t._x,s=t._y,n=t._z,r=t._w,a=e._x,o=e._y,l=e._z,h=e._w;return this._x=i*h+r*a+s*l-n*o,this._y=s*h+r*o+n*a-i*l,this._z=n*h+r*l+i*o-s*a,this._w=r*h-i*a-s*o-n*l,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const i=this._x,s=this._y,n=this._z,r=this._w;let a=r*t._w+i*t._x+s*t._y+n*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=r,this._x=i,this._y=s,this._z=n,this;const o=1-a*a;if(o<=Number.EPSILON){const t=1-e;return this._w=t*r+e*this._w,this._x=t*i+e*this._x,this._y=t*s+e*this._y,this._z=t*n+e*this._z,this.normalize(),this._onChangeCallback(),this}const l=Math.sqrt(o),h=Math.atan2(l,a),c=Math.sin((1-e)*h)/l,d=Math.sin(e*h)/l;return this._w=r*c+this._w*d,this._x=i*c+this._x*d,this._y=s*c+this._y*d,this._z=n*c+this._z*d,this._onChangeCallback(),this}slerpQuaternions(t,e,i){return this.copy(t).slerp(e,i)}random(){const t=Math.random(),e=Math.sqrt(1-t),i=Math.sqrt(t),s=2*Math.PI*Math.random(),n=2*Math.PI*Math.random();return this.set(e*Math.cos(s),i*Math.sin(n),i*Math.cos(n),e*Math.sin(s))}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}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 iO{constructor(t=0,e=0,i=0){iO.prototype.isVector3=!0,this.x=t,this.y=e,this.z=i}set(t,e,i){return void 0===i&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(nO.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(nO.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6]*s,this.y=n[1]*e+n[4]*i+n[7]*s,this.z=n[2]*e+n[5]*i+n[8]*s,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,s=this.z,n=t.elements,r=1/(n[3]*e+n[7]*i+n[11]*s+n[15]);return this.x=(n[0]*e+n[4]*i+n[8]*s+n[12])*r,this.y=(n[1]*e+n[5]*i+n[9]*s+n[13])*r,this.z=(n[2]*e+n[6]*i+n[10]*s+n[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,s=this.z,n=t.x,r=t.y,a=t.z,o=t.w,l=o*e+r*s-a*i,h=o*i+a*e-n*s,c=o*s+n*i-r*e,d=-n*e-r*i-a*s;return this.x=l*o+d*-n+h*-a-c*-r,this.y=h*o+d*-r+c*-n-l*-a,this.z=c*o+d*-a+l*-r-h*-n,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,s=this.z,n=t.elements;return this.x=n[0]*e+n[4]*i+n[8]*s,this.y=n[1]*e+n[5]*i+n[9]*s,this.z=n[2]*e+n[6]*i+n[10]*s,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=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 i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,s=t.y,n=t.z,r=e.x,a=e.y,o=e.z;return this.x=s*o-n*a,this.y=n*r-i*o,this.z=i*a-s*r,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return sO.copy(this).projectOnVector(t),this.sub(sO)}reflect(t){return this.sub(sO.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 i=this.dot(t)/e;return Math.acos(TI(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,s=this.z-t.z;return e*e+i*i+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const s=Math.sin(e)*t;return this.x=s*Math.sin(i),this.y=Math.cos(e)*t,this.z=s*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),s=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=s,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,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=2*(Math.random()-.5),e=Math.random()*Math.PI*2,i=Math.sqrt(1-t**2);return this.x=i*Math.cos(e),this.y=i*Math.sin(e),this.z=t,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const sO=new iO,nO=new eO;class rO{constructor(t=new iO(1/0,1/0,1/0),e=new iO(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e+=3)this.expandByPoint(oO.fromArray(t,e));return this}setFromBufferAttribute(t){this.makeEmpty();for(let e=0,i=t.count;e<i;e++)this.expandByPoint(oO.fromBufferAttribute(t,e));return this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=oO.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t,e=!1){return this.makeEmpty(),this.expandByObject(t,e)}clone(){return(new this.constructor).copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t,e=!1){if(t.updateWorldMatrix(!1,!1),void 0!==t.boundingBox)null===t.boundingBox&&t.computeBoundingBox(),lO.copy(t.boundingBox),lO.applyMatrix4(t.matrixWorld),this.union(lO);else{const i=t.geometry;if(void 0!==i)if(e&&void 0!==i.attributes&&void 0!==i.attributes.position){const e=i.attributes.position;for(let i=0,s=e.count;i<s;i++)oO.fromBufferAttribute(e,i).applyMatrix4(t.matrixWorld),this.expandByPoint(oO)}else null===i.boundingBox&&i.computeBoundingBox(),lO.copy(i.boundingBox),lO.applyMatrix4(t.matrixWorld),this.union(lO)}const i=t.children;for(let t=0,s=i.length;t<s;t++)this.expandByObject(i[t],e);return this}containsPoint(t){return!(t.x<this.min.x||t.x>this.max.x||t.y<this.min.y||t.y>this.max.y||t.z<this.min.z||t.z>this.max.z)}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return!(t.max.x<this.min.x||t.min.x>this.max.x||t.max.y<this.min.y||t.min.y>this.max.y||t.max.z<this.min.z||t.min.z>this.max.z)}intersectsSphere(t){return this.clampPoint(t.center,oO),oO.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(mO),_O.subVectors(this.max,mO),hO.subVectors(t.a,mO),cO.subVectors(t.b,mO),dO.subVectors(t.c,mO),uO.subVectors(cO,hO),fO.subVectors(dO,cO),pO.subVectors(hO,dO);let e=[0,-uO.z,uO.y,0,-fO.z,fO.y,0,-pO.z,pO.y,uO.z,0,-uO.x,fO.z,0,-fO.x,pO.z,0,-pO.x,-uO.y,uO.x,0,-fO.y,fO.x,0,-pO.y,pO.x,0];return!!SO(e,hO,cO,dO,_O)&&(e=[1,0,0,0,1,0,0,0,1],!!SO(e,hO,cO,dO,_O)&&(gO.crossVectors(uO,fO),e=[gO.x,gO.y,gO.z],SO(e,hO,cO,dO,_O)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,oO).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(oO).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()||(aO[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),aO[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),aO[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),aO[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),aO[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),aO[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),aO[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),aO[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(aO)),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 aO=[new iO,new iO,new iO,new iO,new iO,new iO,new iO,new iO],oO=new iO,lO=new rO,hO=new iO,cO=new iO,dO=new iO,uO=new iO,fO=new iO,pO=new iO,mO=new iO,_O=new iO,gO=new iO,vO=new iO;function SO(t,e,i,s,n){for(let r=0,a=t.length-3;r<=a;r+=3){vO.fromArray(t,r);const a=n.x*Math.abs(vO.x)+n.y*Math.abs(vO.y)+n.z*Math.abs(vO.z),o=e.dot(vO),l=i.dot(vO),h=s.dot(vO);if(Math.max(-Math.max(o,l,h),Math.min(o,l,h))>a)return!1}return!0}const yO=new rO,xO=new iO,TO=new iO;class EO{constructor(t=new iO,e=-1){this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;void 0!==e?i.copy(e):yO.setFromPoints(t).getCenter(i);let s=0;for(let e=0,n=t.length;e<n;e++)s=Math.max(s,i.distanceToSquared(t[e]));return this.radius=Math.sqrt(s),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const i=this.center.distanceToSquared(t);return e.copy(t),i>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;xO.subVectors(t,this.center);const e=xO.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),i=.5*(t-this.radius);this.center.addScaledVector(xO,i/t),this.radius+=i}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):(TO.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(xO.copy(t.center).add(TO)),this.expandByPoint(xO.copy(t.center).sub(TO))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const bO=new iO,wO=new iO,AO=new iO,CO=new iO,MO=new iO,PO=new iO,RO=new iO;class LO{constructor(t=new iO,e=new iO(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,bO)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,i)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=bO.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(bO.copy(this.origin).addScaledVector(this.direction,e),bO.distanceToSquared(t))}distanceSqToSegment(t,e,i,s){wO.copy(t).add(e).multiplyScalar(.5),AO.copy(e).sub(t).normalize(),CO.copy(this.origin).sub(wO);const n=.5*t.distanceTo(e),r=-this.direction.dot(AO),a=CO.dot(this.direction),o=-CO.dot(AO),l=CO.lengthSq(),h=Math.abs(1-r*r);let c,d,u,f;if(h>0)if(c=r*o-a,d=r*a-o,f=n*h,c>=0)if(d>=-f)if(d<=f){const t=1/h;c*=t,d*=t,u=c*(c+r*d+2*a)+d*(r*c+d+2*o)+l}else d=n,c=Math.max(0,-(r*d+a)),u=-c*c+d*(d+2*o)+l;else d=-n,c=Math.max(0,-(r*d+a)),u=-c*c+d*(d+2*o)+l;else d<=-f?(c=Math.max(0,-(-r*n+a)),d=c>0?-n:Math.min(Math.max(-n,-o),n),u=-c*c+d*(d+2*o)+l):d<=f?(c=0,d=Math.min(Math.max(-n,-o),n),u=d*(d+2*o)+l):(c=Math.max(0,-(r*n+a)),d=c>0?n:Math.min(Math.max(-n,-o),n),u=-c*c+d*(d+2*o)+l);else d=r>0?-n:n,c=Math.max(0,-(r*d+a)),u=-c*c+d*(d+2*o)+l;return i&&i.copy(this.origin).addScaledVector(this.direction,c),s&&s.copy(wO).addScaledVector(AO,d),u}intersectSphere(t,e){bO.subVectors(t.center,this.origin);const i=bO.dot(this.direction),s=bO.dot(bO)-i*i,n=t.radius*t.radius;if(s>n)return null;const r=Math.sqrt(n-s),a=i-r,o=i+r;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return null===i?null:this.at(i,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 i,s,n,r,a,o;const l=1/this.direction.x,h=1/this.direction.y,c=1/this.direction.z,d=this.origin;return l>=0?(i=(t.min.x-d.x)*l,s=(t.max.x-d.x)*l):(i=(t.max.x-d.x)*l,s=(t.min.x-d.x)*l),h>=0?(n=(t.min.y-d.y)*h,r=(t.max.y-d.y)*h):(n=(t.max.y-d.y)*h,r=(t.min.y-d.y)*h),i>r||n>s?null:((n>i||isNaN(i))&&(i=n),(r<s||isNaN(s))&&(s=r),c>=0?(a=(t.min.z-d.z)*c,o=(t.max.z-d.z)*c):(a=(t.max.z-d.z)*c,o=(t.min.z-d.z)*c),i>o||a>s?null:((a>i||i!=i)&&(i=a),(o<s||s!=s)&&(s=o),s<0?null:this.at(i>=0?i:s,e)))}intersectsBox(t){return null!==this.intersectBox(t,bO)}intersectTriangle(t,e,i,s,n){MO.subVectors(e,t),PO.subVectors(i,t),RO.crossVectors(MO,PO);let r,a=this.direction.dot(RO);if(a>0){if(s)return null;r=1}else{if(!(a<0))return null;r=-1,a=-a}CO.subVectors(this.origin,t);const o=r*this.direction.dot(PO.crossVectors(CO,PO));if(o<0)return null;const l=r*this.direction.dot(MO.cross(CO));if(l<0)return null;if(o+l>a)return null;const h=-r*CO.dot(RO);return h<0?null:this.at(h/a,n)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class DO{constructor(t,e,i,s,n,r,a,o,l,h,c,d,u,f,p,m){DO.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,i,s,n,r,a,o,l,h,c,d,u,f,p,m)}set(t,e,i,s,n,r,a,o,l,h,c,d,u,f,p,m){const _=this.elements;return _[0]=t,_[4]=e,_[8]=i,_[12]=s,_[1]=n,_[5]=r,_[9]=a,_[13]=o,_[2]=l,_[6]=h,_[10]=c,_[14]=d,_[3]=u,_[7]=f,_[11]=p,_[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 DO).fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,i=t.elements,s=1/IO.setFromMatrixColumn(t,0).length(),n=1/IO.setFromMatrixColumn(t,1).length(),r=1/IO.setFromMatrixColumn(t,2).length();return e[0]=i[0]*s,e[1]=i[1]*s,e[2]=i[2]*s,e[3]=0,e[4]=i[4]*n,e[5]=i[5]*n,e[6]=i[6]*n,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,i=t.x,s=t.y,n=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(s),l=Math.sin(s),h=Math.cos(n),c=Math.sin(n);if("XYZ"===t.order){const t=r*h,i=r*c,s=a*h,n=a*c;e[0]=o*h,e[4]=-o*c,e[8]=l,e[1]=i+s*l,e[5]=t-n*l,e[9]=-a*o,e[2]=n-t*l,e[6]=s+i*l,e[10]=r*o}else if("YXZ"===t.order){const t=o*h,i=o*c,s=l*h,n=l*c;e[0]=t+n*a,e[4]=s*a-i,e[8]=r*l,e[1]=r*c,e[5]=r*h,e[9]=-a,e[2]=i*a-s,e[6]=n+t*a,e[10]=r*o}else if("ZXY"===t.order){const t=o*h,i=o*c,s=l*h,n=l*c;e[0]=t-n*a,e[4]=-r*c,e[8]=s+i*a,e[1]=i+s*a,e[5]=r*h,e[9]=n-t*a,e[2]=-r*l,e[6]=a,e[10]=r*o}else if("ZYX"===t.order){const t=r*h,i=r*c,s=a*h,n=a*c;e[0]=o*h,e[4]=s*l-i,e[8]=t*l+n,e[1]=o*c,e[5]=n*l+t,e[9]=i*l-s,e[2]=-l,e[6]=a*o,e[10]=r*o}else if("YZX"===t.order){const t=r*o,i=r*l,s=a*o,n=a*l;e[0]=o*h,e[4]=n-t*c,e[8]=s*c+i,e[1]=c,e[5]=r*h,e[9]=-a*h,e[2]=-l*h,e[6]=i*c+s,e[10]=t-n*c}else if("XZY"===t.order){const t=r*o,i=r*l,s=a*o,n=a*l;e[0]=o*h,e[4]=-c,e[8]=l*h,e[1]=t*c+n,e[5]=r*h,e[9]=i*c-s,e[2]=s*c-i,e[6]=a*h,e[10]=n*c+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(NO,t,FO)}lookAt(t,e,i){const s=this.elements;return zO.subVectors(t,e),0===zO.lengthSq()&&(zO.z=1),zO.normalize(),UO.crossVectors(i,zO),0===UO.lengthSq()&&(1===Math.abs(i.z)?zO.x+=1e-4:zO.z+=1e-4,zO.normalize(),UO.crossVectors(i,zO)),UO.normalize(),BO.crossVectors(zO,UO),s[0]=UO.x,s[4]=BO.x,s[8]=zO.x,s[1]=UO.y,s[5]=BO.y,s[9]=zO.y,s[2]=UO.z,s[6]=BO.z,s[10]=zO.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,s=e.elements,n=this.elements,r=i[0],a=i[4],o=i[8],l=i[12],h=i[1],c=i[5],d=i[9],u=i[13],f=i[2],p=i[6],m=i[10],_=i[14],g=i[3],v=i[7],S=i[11],y=i[15],x=s[0],T=s[4],E=s[8],b=s[12],w=s[1],A=s[5],C=s[9],M=s[13],P=s[2],R=s[6],L=s[10],D=s[14],I=s[3],O=s[7],N=s[11],F=s[15];return n[0]=r*x+a*w+o*P+l*I,n[4]=r*T+a*A+o*R+l*O,n[8]=r*E+a*C+o*L+l*N,n[12]=r*b+a*M+o*D+l*F,n[1]=h*x+c*w+d*P+u*I,n[5]=h*T+c*A+d*R+u*O,n[9]=h*E+c*C+d*L+u*N,n[13]=h*b+c*M+d*D+u*F,n[2]=f*x+p*w+m*P+_*I,n[6]=f*T+p*A+m*R+_*O,n[10]=f*E+p*C+m*L+_*N,n[14]=f*b+p*M+m*D+_*F,n[3]=g*x+v*w+S*P+y*I,n[7]=g*T+v*A+S*R+y*O,n[11]=g*E+v*C+S*L+y*N,n[15]=g*b+v*M+S*D+y*F,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],s=t[8],n=t[12],r=t[1],a=t[5],o=t[9],l=t[13],h=t[2],c=t[6],d=t[10],u=t[14];return t[3]*(+n*o*c-s*l*c-n*a*d+i*l*d+s*a*u-i*o*u)+t[7]*(+e*o*u-e*l*d+n*r*d-s*r*u+s*l*h-n*o*h)+t[11]*(+e*l*c-e*a*u-n*r*c+i*r*u+n*a*h-i*l*h)+t[15]*(-s*a*h-e*o*c+e*a*d+s*r*c-i*r*d+i*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,i){const s=this.elements;return t.isVector3?(s[12]=t.x,s[13]=t.y,s[14]=t.z):(s[12]=t,s[13]=e,s[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],s=t[2],n=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8],c=t[9],d=t[10],u=t[11],f=t[12],p=t[13],m=t[14],_=t[15],g=c*m*l-p*d*l+p*o*u-a*m*u-c*o*_+a*d*_,v=f*d*l-h*m*l-f*o*u+r*m*u+h*o*_-r*d*_,S=h*p*l-f*c*l+f*a*u-r*p*u-h*a*_+r*c*_,y=f*c*o-h*p*o-f*a*d+r*p*d+h*a*m-r*c*m,x=e*g+i*v+s*S+n*y;if(0===x)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const T=1/x;return t[0]=g*T,t[1]=(p*d*n-c*m*n-p*s*u+i*m*u+c*s*_-i*d*_)*T,t[2]=(a*m*n-p*o*n+p*s*l-i*m*l-a*s*_+i*o*_)*T,t[3]=(c*o*n-a*d*n-c*s*l+i*d*l+a*s*u-i*o*u)*T,t[4]=v*T,t[5]=(h*m*n-f*d*n+f*s*u-e*m*u-h*s*_+e*d*_)*T,t[6]=(f*o*n-r*m*n-f*s*l+e*m*l+r*s*_-e*o*_)*T,t[7]=(r*d*n-h*o*n+h*s*l-e*d*l-r*s*u+e*o*u)*T,t[8]=S*T,t[9]=(f*c*n-h*p*n-f*i*u+e*p*u+h*i*_-e*c*_)*T,t[10]=(r*p*n-f*a*n+f*i*l-e*p*l-r*i*_+e*a*_)*T,t[11]=(h*a*n-r*c*n-h*i*l+e*c*l+r*i*u-e*a*u)*T,t[12]=y*T,t[13]=(h*p*s-f*c*s+f*i*d-e*p*d-h*i*m+e*c*m)*T,t[14]=(f*a*s-r*p*s-f*i*o+e*p*o+r*i*m-e*a*m)*T,t[15]=(r*c*s-h*a*s+h*i*o-e*c*o-r*i*d+e*a*d)*T,this}scale(t){const e=this.elements,i=t.x,s=t.y,n=t.z;return e[0]*=i,e[4]*=s,e[8]*=n,e[1]*=i,e[5]*=s,e[9]*=n,e[2]*=i,e[6]*=s,e[10]*=n,e[3]*=i,e[7]*=s,e[11]*=n,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],s=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,s))}makeTranslation(t,e,i){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),s=Math.sin(e),n=1-i,r=t.x,a=t.y,o=t.z,l=n*r,h=n*a;return this.set(l*r+i,l*a-s*o,l*o+s*a,0,l*a+s*o,h*a+i,h*o-s*r,0,l*o-s*a,h*o+s*r,n*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,s,n,r){return this.set(1,i,n,0,t,1,r,0,e,s,1,0,0,0,0,1),this}compose(t,e,i){const s=this.elements,n=e._x,r=e._y,a=e._z,o=e._w,l=n+n,h=r+r,c=a+a,d=n*l,u=n*h,f=n*c,p=r*h,m=r*c,_=a*c,g=o*l,v=o*h,S=o*c,y=i.x,x=i.y,T=i.z;return s[0]=(1-(p+_))*y,s[1]=(u+S)*y,s[2]=(f-v)*y,s[3]=0,s[4]=(u-S)*x,s[5]=(1-(d+_))*x,s[6]=(m+g)*x,s[7]=0,s[8]=(f+v)*T,s[9]=(m-g)*T,s[10]=(1-(d+p))*T,s[11]=0,s[12]=t.x,s[13]=t.y,s[14]=t.z,s[15]=1,this}decompose(t,e,i){const s=this.elements;let n=IO.set(s[0],s[1],s[2]).length();const r=IO.set(s[4],s[5],s[6]).length(),a=IO.set(s[8],s[9],s[10]).length();this.determinant()<0&&(n=-n),t.x=s[12],t.y=s[13],t.z=s[14],OO.copy(this);const o=1/n,l=1/r,h=1/a;return OO.elements[0]*=o,OO.elements[1]*=o,OO.elements[2]*=o,OO.elements[4]*=l,OO.elements[5]*=l,OO.elements[6]*=l,OO.elements[8]*=h,OO.elements[9]*=h,OO.elements[10]*=h,e.setFromRotationMatrix(OO),i.x=n,i.y=r,i.z=a,this}makePerspective(t,e,i,s,n,r,a=2e3){const o=this.elements,l=2*n/(e-t),h=2*n/(i-s),c=(e+t)/(e-t),d=(i+s)/(i-s);let u,f;if(a===mI)u=-(r+n)/(r-n),f=-2*r*n/(r-n);else{if(a!==_I)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);u=-r/(r-n),f=-r*n/(r-n)}return o[0]=l,o[4]=0,o[8]=c,o[12]=0,o[1]=0,o[5]=h,o[9]=d,o[13]=0,o[2]=0,o[6]=0,o[10]=u,o[14]=f,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this}makeOrthographic(t,e,i,s,n,r,a=2e3){const o=this.elements,l=1/(e-t),h=1/(i-s),c=1/(r-n),d=(e+t)*l,u=(i+s)*h;let f,p;if(a===mI)f=(r+n)*c,p=-2*c;else{if(a!==_I)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);f=n*c,p=-1*c}return o[0]=2*l,o[4]=0,o[8]=0,o[12]=-d,o[1]=0,o[5]=2*h,o[9]=0,o[13]=-u,o[2]=0,o[6]=0,o[10]=p,o[14]=-f,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let t=0;t<16;t++)if(e[t]!==i[t])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}const IO=new iO,OO=new DO,NO=new iO(0,0,0),FO=new iO(1,1,1),UO=new iO,BO=new iO,zO=new iO,kO=new DO,VO=new eO;class HO{constructor(t=0,e=0,i=0,s=HO.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=i,this._order=s}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,s=this._order){return this._x=t,this._y=e,this._z=i,this._order=s,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const s=t.elements,n=s[0],r=s[4],a=s[8],o=s[1],l=s[5],h=s[9],c=s[2],d=s[6],u=s[10];switch(e){case"XYZ":this._y=Math.asin(TI(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,u),this._z=Math.atan2(-r,n)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-TI(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,u),this._z=Math.atan2(o,l)):(this._y=Math.atan2(-c,n),this._z=0);break;case"ZXY":this._x=Math.asin(TI(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-c,u),this._z=Math.atan2(-r,l)):(this._y=0,this._z=Math.atan2(o,n));break;case"ZYX":this._y=Math.asin(-TI(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(d,u),this._z=Math.atan2(o,n)):(this._x=0,this._z=Math.atan2(-r,l));break;case"YZX":this._z=Math.asin(TI(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-c,n)):(this._x=0,this._y=Math.atan2(a,u));break;case"XZY":this._z=Math.asin(-TI(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(a,n)):(this._x=Math.atan2(-h,u),this._y=0)}return this._order=e,!0===i&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return kO.makeRotationFromQuaternion(t),this.setFromRotationMatrix(kO,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return VO.setFromEuler(this),this.setFromQuaternion(VO,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}}HO.DEFAULT_ORDER="XYZ";class GO{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 0!==(this.mask&t.mask)}isEnabled(t){return!!(this.mask&1<<t)}}let WO=0;const XO=new iO,YO=new eO,qO=new DO,jO=new iO,$O=new iO,KO=new iO,ZO=new eO,QO=new iO(1,0,0),JO=new iO(0,1,0),tN=new iO(0,0,1),eN={type:"added"},iN={type:"removed"};class sN extends gI{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:WO++}),this.uuid=xI(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=sN.DEFAULT_UP.clone();const t=new iO,e=new HO,i=new eO,s=new iO(1,1,1);e._onChange(function(){i.setFromEuler(e,!1)}),i._onChange(function(){e.setFromQuaternion(i,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:i},scale:{configurable:!0,enumerable:!0,value:s},modelViewMatrix:{value:new DO},normalMatrix:{value:new PI}}),this.matrix=new DO,this.matrixWorld=new DO,this.matrixAutoUpdate=sN.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.matrixWorldAutoUpdate=sN.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.layers=new GO,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}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 YO.setFromAxisAngle(t,e),this.quaternion.multiply(YO),this}rotateOnWorldAxis(t,e){return YO.setFromAxisAngle(t,e),this.quaternion.premultiply(YO),this}rotateX(t){return this.rotateOnAxis(QO,t)}rotateY(t){return this.rotateOnAxis(JO,t)}rotateZ(t){return this.rotateOnAxis(tN,t)}translateOnAxis(t,e){return XO.copy(t).applyQuaternion(this.quaternion),this.position.add(XO.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(QO,t)}translateY(t){return this.translateOnAxis(JO,t)}translateZ(t){return this.translateOnAxis(tN,t)}localToWorld(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return this.updateWorldMatrix(!0,!1),t.applyMatrix4(qO.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?jO.copy(t):jO.set(t,e,i);const s=this.parent;this.updateWorldMatrix(!0,!1),$O.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?qO.lookAt($O,jO,this.up):qO.lookAt(jO,$O,this.up),this.quaternion.setFromRotationMatrix(qO),s&&(qO.extractRotation(s.matrixWorld),YO.setFromRotationMatrix(qO),this.quaternion.premultiply(YO.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return t===this||t&&t.isObject3D&&(null!==t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t),t.dispatchEvent(eN)),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(iN)),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),qO.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),qO.multiply(t.parent.matrixWorld)),t.applyMatrix4(qO),this.add(t),t.updateWorldMatrix(!1,!0),this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let i=0,s=this.children.length;i<s;i++){const s=this.children[i].getObjectByProperty(t,e);if(void 0!==s)return s}}getObjectsByProperty(t,e){let i=[];this[t]===e&&i.push(this);for(let s=0,n=this.children.length;s<n;s++){const n=this.children[s].getObjectsByProperty(t,e);n.length>0&&(i=i.concat(n))}return i}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose($O,t,KO),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose($O,ZO,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let i=0,s=e.length;i<s;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;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)&&(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 i=0,s=e.length;i<s;i++){const s=e[i];!0!==s.matrixWorldAutoUpdate&&!0!==t||s.updateMatrixWorld(t)}}updateWorldMatrix(t,e){const i=this.parent;if(!0===t&&null!==i&&!0===i.matrixWorldAutoUpdate&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),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,i=t.length;e<i;e++){const i=t[e];!0===i.matrixWorldAutoUpdate&&i.updateWorldMatrix(!1,!0)}}}toJSON(t){const e=void 0===t||"string"==typeof t,i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},i.metadata={version:4.6,type:"Object",generator:"Object3D.toJSON"});const s={};function n(e,i){return void 0===e[i.uuid]&&(e[i.uuid]=i.toJSON(t)),i.uuid}if(s.uuid=this.uuid,s.type=this.type,""!==this.name&&(s.name=this.name),!0===this.castShadow&&(s.castShadow=!0),!0===this.receiveShadow&&(s.receiveShadow=!0),!1===this.visible&&(s.visible=!1),!1===this.frustumCulled&&(s.frustumCulled=!1),0!==this.renderOrder&&(s.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(s.userData=this.userData),s.layers=this.layers.mask,s.matrix=this.matrix.toArray(),s.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(s.matrixAutoUpdate=!1),this.isInstancedMesh&&(s.type="InstancedMesh",s.count=this.count,s.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(s.instanceColor=this.instanceColor.toJSON())),this.isScene)this.background&&(this.background.isColor?s.background=this.background.toJSON():this.background.isTexture&&(s.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(s.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){s.geometry=n(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const i=e.shapes;if(Array.isArray(i))for(let e=0,s=i.length;e<s;e++){const s=i[e];n(t.shapes,s)}else n(t.shapes,i)}}if(this.isSkinnedMesh&&(s.bindMode=this.bindMode,s.bindMatrix=this.bindMatrix.toArray(),void 0!==this.skeleton&&(n(t.skeletons,this.skeleton),s.skeleton=this.skeleton.uuid)),void 0!==this.material)if(Array.isArray(this.material)){const e=[];for(let i=0,s=this.material.length;i<s;i++)e.push(n(t.materials,this.material[i]));s.material=e}else s.material=n(t.materials,this.material);if(this.children.length>0){s.children=[];for(let e=0;e<this.children.length;e++)s.children.push(this.children[e].toJSON(t).object)}if(this.animations.length>0){s.animations=[];for(let e=0;e<this.animations.length;e++){const i=this.animations[e];s.animations.push(n(t.animations,i))}}if(e){const e=r(t.geometries),s=r(t.materials),n=r(t.textures),a=r(t.images),o=r(t.shapes),l=r(t.skeletons),h=r(t.animations),c=r(t.nodes);e.length>0&&(i.geometries=e),s.length>0&&(i.materials=s),n.length>0&&(i.textures=n),a.length>0&&(i.images=a),o.length>0&&(i.shapes=o),l.length>0&&(i.skeletons=l),h.length>0&&(i.animations=h),c.length>0&&(i.nodes=c)}return i.object=s,i;function r(t){const e=[];for(const i in t){const s=t[i];delete s.metadata,e.push(s)}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.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,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 i=t.children[e];this.add(i.clone())}return this}}sN.DEFAULT_UP=new iO(0,1,0),sN.DEFAULT_MATRIX_AUTO_UPDATE=!0,sN.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;const nN=new iO,rN=new iO,aN=new iO,oN=new iO,lN=new iO,hN=new iO,cN=new iO,dN=new iO,uN=new iO,fN=new iO;let pN=!1;class mN{constructor(t=new iO,e=new iO,i=new iO){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,s){s.subVectors(i,e),nN.subVectors(t,e),s.cross(nN);const n=s.lengthSq();return n>0?s.multiplyScalar(1/Math.sqrt(n)):s.set(0,0,0)}static getBarycoord(t,e,i,s,n){nN.subVectors(s,e),rN.subVectors(i,e),aN.subVectors(t,e);const r=nN.dot(nN),a=nN.dot(rN),o=nN.dot(aN),l=rN.dot(rN),h=rN.dot(aN),c=r*l-a*a;if(0===c)return n.set(-2,-1,-1);const d=1/c,u=(l*o-a*h)*d,f=(r*h-a*o)*d;return n.set(1-u-f,f,u)}static containsPoint(t,e,i,s){return this.getBarycoord(t,e,i,s,oN),oN.x>=0&&oN.y>=0&&oN.x+oN.y<=1}static getUV(t,e,i,s,n,r,a,o){return!1===pN&&(pN=!0),this.getInterpolation(t,e,i,s,n,r,a,o)}static getInterpolation(t,e,i,s,n,r,a,o){return this.getBarycoord(t,e,i,s,oN),o.setScalar(0),o.addScaledVector(n,oN.x),o.addScaledVector(r,oN.y),o.addScaledVector(a,oN.z),o}static isFrontFacing(t,e,i,s){return nN.subVectors(i,e),rN.subVectors(t,e),nN.cross(rN).dot(s)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,s){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[s]),this}setFromAttributeAndIndices(t,e,i,s){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,s),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return nN.subVectors(this.c,this.b),rN.subVectors(this.a,this.b),.5*nN.cross(rN).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return mN.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return mN.getBarycoord(t,this.a,this.b,this.c,e)}getUV(t,e,i,s,n){return!1===pN&&(pN=!0),mN.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}getInterpolation(t,e,i,s,n){return mN.getInterpolation(t,this.a,this.b,this.c,e,i,s,n)}containsPoint(t){return mN.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return mN.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,s=this.b,n=this.c;let r,a;lN.subVectors(s,i),hN.subVectors(n,i),dN.subVectors(t,i);const o=lN.dot(dN),l=hN.dot(dN);if(o<=0&&l<=0)return e.copy(i);uN.subVectors(t,s);const h=lN.dot(uN),c=hN.dot(uN);if(h>=0&&c<=h)return e.copy(s);const d=o*c-h*l;if(d<=0&&o>=0&&h<=0)return r=o/(o-h),e.copy(i).addScaledVector(lN,r);fN.subVectors(t,n);const u=lN.dot(fN),f=hN.dot(fN);if(f>=0&&u<=f)return e.copy(n);const p=u*l-o*f;if(p<=0&&l>=0&&f<=0)return a=l/(l-f),e.copy(i).addScaledVector(hN,a);const m=h*f-u*c;if(m<=0&&c-h>=0&&u-f>=0)return cN.subVectors(n,s),a=(c-h)/(c-h+(u-f)),e.copy(s).addScaledVector(cN,a);const _=1/(m+p+d);return r=p*_,a=d*_,e.copy(i).addScaledVector(lN,r).addScaledVector(hN,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}let _N=0;class gN extends gI{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:_N++}),this.uuid=xI(),this.name="",this.type="Material",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=oD,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=nI,this.stencilZFail=nI,this.stencilZPass=nI,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}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const i=t[e];if(void 0===i)continue;const s=this[e];void 0!==s&&(s&&s.isColor?s.set(i):s&&s.isVector3&&i&&i.isVector3?s.copy(i):this[e]=i)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const i={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};function s(t){const e=[];for(const i in t){const s=t[i];delete s.metadata,e.push(s)}return e}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),void 0!==this.roughness&&(i.roughness=this.roughness),void 0!==this.metalness&&(i.metalness=this.metalness),void 0!==this.sheen&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity&&1!==this.emissiveIntensity&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(i.shininess=this.shininess),void 0!==this.clearcoat&&(i.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),void 0!==this.iridescence&&(i.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(i.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(i.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(i.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(i.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(i.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(i.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(i.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(t).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(t).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(t).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(t).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(t).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(i.combine=this.combine)),void 0!==this.envMapIntensity&&(i.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(i.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(i.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(i.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(i.size=this.size),null!==this.shadowSide&&(i.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(i.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(i.blending=this.blending),0!==this.side&&(i.side=this.side),!0===this.vertexColors&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),!0===this.transparent&&(i.transparent=!0),i.depthFunc=this.depthFunc,i.depthTest=this.depthTest,i.depthWrite=this.depthWrite,i.colorWrite=this.colorWrite,i.stencilWrite=this.stencilWrite,i.stencilWriteMask=this.stencilWriteMask,i.stencilFunc=this.stencilFunc,i.stencilRef=this.stencilRef,i.stencilFuncMask=this.stencilFuncMask,i.stencilFail=this.stencilFail,i.stencilZFail=this.stencilZFail,i.stencilZPass=this.stencilZPass,void 0!==this.rotation&&0!==this.rotation&&(i.rotation=this.rotation),!0===this.polygonOffset&&(i.polygonOffset=!0),0!==this.polygonOffsetFactor&&(i.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(i.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(i.linewidth=this.linewidth),void 0!==this.dashSize&&(i.dashSize=this.dashSize),void 0!==this.gapSize&&(i.gapSize=this.gapSize),void 0!==this.scale&&(i.scale=this.scale),!0===this.dithering&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),!0===this.alphaHash&&(i.alphaHash=!0),!0===this.alphaToCoverage&&(i.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(i.premultipliedAlpha=!0),!0===this.forceSinglePass&&(i.forceSinglePass=!0),!0===this.wireframe&&(i.wireframe=!0),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(i.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(i.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(i.flatShading=!0),!1===this.visible&&(i.visible=!1),!1===this.toneMapped&&(i.toneMapped=!1),!1===this.fog&&(i.fog=!1),Object.keys(this.userData).length>0&&(i.userData=this.userData),e){const e=s(t.textures),n=s(t.images);e.length>0&&(i.textures=e),n.length>0&&(i.images=n)}return i}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let i=null;if(null!==e){const t=e.length;i=new Array(t);for(let s=0;s!==t;++s)i[s]=e[s].clone()}return this.clippingPlanes=i,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}}const vN={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},SN={h:0,s:0,l:0},yN={h:0,s:0,l:0};function xN(t,e,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+6*(e-t)*(2/3-i):t}class TN{constructor(t,e,i){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,i)}set(t,e,i){if(void 0===e&&void 0===i){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,i);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=KD){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,kI.toWorkingColorSpace(this,e),this}setRGB(t,e,i,s=kI.workingColorSpace){return this.r=t,this.g=e,this.b=i,kI.toWorkingColorSpace(this,s),this}setHSL(t,e,i,s=kI.workingColorSpace){var n;if(t=(t%(n=1)+n)%n,e=TI(e,0,1),i=TI(i,0,1),0===e)this.r=this.g=this.b=i;else{const s=i<=.5?i*(1+e):i+e-i*e,n=2*i-s;this.r=xN(n,s,t+1/3),this.g=xN(n,s,t),this.b=xN(n,s,t-1/3)}return kI.toWorkingColorSpace(this,s),this}setStyle(t,e=KD){function i(t){void 0!==t&&parseFloat(t)}let s;if(s=/^(\w+)\(([^\)]*)\)/.exec(t)){let t;const n=s[1],r=s[2];switch(n){case"rgb":case"rgba":if(t=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))return i(t[4]),this.setRGB(Math.min(255,parseInt(t[1],10))/255,Math.min(255,parseInt(t[2],10))/255,Math.min(255,parseInt(t[3],10))/255,e);if(t=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))return i(t[4]),this.setRGB(Math.min(100,parseInt(t[1],10))/100,Math.min(100,parseInt(t[2],10))/100,Math.min(100,parseInt(t[3],10))/100,e);break;case"hsl":case"hsla":if(t=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(r))return i(t[4]),this.setHSL(parseFloat(t[1])/360,parseFloat(t[2])/100,parseFloat(t[3])/100,e)}}else if(s=/^\#([A-Fa-f\d]+)$/.exec(t)){const t=s[1],i=t.length;if(3===i)return this.setRGB(parseInt(t.charAt(0),16)/15,parseInt(t.charAt(1),16)/15,parseInt(t.charAt(2),16)/15,e);if(6===i)return this.setHex(parseInt(t,16),e)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=KD){const i=vN[t.toLowerCase()];return void 0!==i&&this.setHex(i,e),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=VI(t.r),this.g=VI(t.g),this.b=VI(t.b),this}copyLinearToSRGB(t){return this.r=HI(t.r),this.g=HI(t.g),this.b=HI(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=KD){return kI.fromWorkingColorSpace(EN.copy(this),t),65536*Math.round(TI(255*EN.r,0,255))+256*Math.round(TI(255*EN.g,0,255))+Math.round(TI(255*EN.b,0,255))}getHexString(t=KD){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=kI.workingColorSpace){kI.fromWorkingColorSpace(EN.copy(this),e);const i=EN.r,s=EN.g,n=EN.b,r=Math.max(i,s,n),a=Math.min(i,s,n);let o,l;const h=(a+r)/2;if(a===r)o=0,l=0;else{const t=r-a;switch(l=h<=.5?t/(r+a):t/(2-r-a),r){case i:o=(s-n)/t+(s<n?6:0);break;case s:o=(n-i)/t+2;break;case n:o=(i-s)/t+4}o/=6}return t.h=o,t.s=l,t.l=h,t}getRGB(t,e=kI.workingColorSpace){return kI.fromWorkingColorSpace(EN.copy(this),e),t.r=EN.r,t.g=EN.g,t.b=EN.b,t}getStyle(t=KD){kI.fromWorkingColorSpace(EN.copy(this),t);const e=EN.r,i=EN.g,s=EN.b;return t!==KD?`color(${t} ${e.toFixed(3)} ${i.toFixed(3)} ${s.toFixed(3)})`:`rgb(${Math.round(255*e)},${Math.round(255*i)},${Math.round(255*s)})`}offsetHSL(t,e,i){return this.getHSL(SN),this.setHSL(SN.h+t,SN.s+e,SN.l+i)}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,i){return this.r=t.r+(e.r-t.r)*i,this.g=t.g+(e.g-t.g)*i,this.b=t.b+(e.b-t.b)*i,this}lerpHSL(t,e){this.getHSL(SN),t.getHSL(yN);const i=EI(SN.h,yN.h,e),s=EI(SN.s,yN.s,e),n=EI(SN.l,yN.l,e);return this.setHSL(i,s,n),this}setFromVector3(t){return this.r=t.x,this.g=t.y,this.b=t.z,this}applyMatrix3(t){const e=this.r,i=this.g,s=this.b,n=t.elements;return this.r=n[0]*e+n[3]*i+n[6]*s,this.g=n[1]*e+n[4]*i+n[7]*s,this.b=n[2]*e+n[5]*i+n[8]*s,this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}}const EN=new TN;TN.NAMES=vN;class bN extends gN{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new TN(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.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.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 wN=new iO,AN=new MI;class CN{constructor(t,e,i=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=i,this.usage=35044,this.updateRange={offset:0,count:-1},this.gpuType=UD,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let s=0,n=this.itemSize;s<n;s++)this.array[t+s]=e.array[i+s];return this}copyArray(t){return this.array.set(t),this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,i=this.count;e<i;e++)AN.fromBufferAttribute(this,e),AN.applyMatrix3(t),this.setXY(e,AN.x,AN.y);else if(3===this.itemSize)for(let e=0,i=this.count;e<i;e++)wN.fromBufferAttribute(this,e),wN.applyMatrix3(t),this.setXYZ(e,wN.x,wN.y,wN.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)wN.fromBufferAttribute(this,e),wN.applyMatrix4(t),this.setXYZ(e,wN.x,wN.y,wN.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)wN.fromBufferAttribute(this,e),wN.applyNormalMatrix(t),this.setXYZ(e,wN.x,wN.y,wN.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)wN.fromBufferAttribute(this,e),wN.transformDirection(t),this.setXYZ(e,wN.x,wN.y,wN.z);return this}set(t,e=0){return this.array.set(t,e),this}getComponent(t,e){let i=this.array[t*this.itemSize+e];return this.normalized&&(i=AI(i,this.array)),i}setComponent(t,e,i){return this.normalized&&(i=CI(i,this.array)),this.array[t*this.itemSize+e]=i,this}getX(t){let e=this.array[t*this.itemSize];return this.normalized&&(e=AI(e,this.array)),e}setX(t,e){return this.normalized&&(e=CI(e,this.array)),this.array[t*this.itemSize]=e,this}getY(t){let e=this.array[t*this.itemSize+1];return this.normalized&&(e=AI(e,this.array)),e}setY(t,e){return this.normalized&&(e=CI(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=AI(e,this.array)),e}setZ(t,e){return this.normalized&&(e=CI(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=AI(e,this.array)),e}setW(t,e){return this.normalized&&(e=CI(e,this.array)),this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.normalized&&(e=CI(e,this.array),i=CI(i,this.array)),this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,s){return t*=this.itemSize,this.normalized&&(e=CI(e,this.array),i=CI(i,this.array),s=CI(s,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this}setXYZW(t,e,i,s,n){return t*=this.itemSize,this.normalized&&(e=CI(e,this.array),i=CI(i,this.array),s=CI(s,this.array),n=CI(n,this.array)),this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=s,this.array[t+3]=n,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return""!==this.name&&(t.name=this.name),35044!==this.usage&&(t.usage=this.usage),0===this.updateRange.offset&&-1===this.updateRange.count||(t.updateRange=this.updateRange),t}}class MN extends CN{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class PN extends CN{constructor(t,e,i){super(new Uint32Array(t),e,i)}}class RN extends CN{constructor(t,e,i){super(new Float32Array(t),e,i)}}let LN=0;const DN=new DO,IN=new sN,ON=new iO,NN=new rO,FN=new rO,UN=new iO;class BN extends gI{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:LN++}),this.uuid=xI(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(LI(t)?PN:MN)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(void 0!==i){const e=(new PI).getNormalMatrix(t);i.applyNormalMatrix(e),i.needsUpdate=!0}const s=this.attributes.tangent;return void 0!==s&&(s.transformDirection(t),s.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return DN.makeRotationFromQuaternion(t),this.applyMatrix4(DN),this}rotateX(t){return DN.makeRotationX(t),this.applyMatrix4(DN),this}rotateY(t){return DN.makeRotationY(t),this.applyMatrix4(DN),this}rotateZ(t){return DN.makeRotationZ(t),this.applyMatrix4(DN),this}translate(t,e,i){return DN.makeTranslation(t,e,i),this.applyMatrix4(DN),this}scale(t,e,i){return DN.makeScale(t,e,i),this.applyMatrix4(DN),this}lookAt(t){return IN.lookAt(t),IN.updateMatrix(),this.applyMatrix4(IN.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ON).negate(),this.translate(ON.x,ON.y,ON.z),this}setFromPoints(t){const e=[];for(let i=0,s=t.length;i<s;i++){const s=t[i];e.push(s.x,s.y,s.z||0)}return this.setAttribute("position",new RN(e,3)),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new rO);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)this.boundingBox.set(new iO(-1/0,-1/0,-1/0),new iO(1/0,1/0,1/0));else{if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,i=e.length;t<i;t++){const i=e[t];NN.setFromBufferAttribute(i),this.morphTargetsRelative?(UN.addVectors(this.boundingBox.min,NN.min),this.boundingBox.expandByPoint(UN),UN.addVectors(this.boundingBox.max,NN.max),this.boundingBox.expandByPoint(UN)):(this.boundingBox.expandByPoint(NN.min),this.boundingBox.expandByPoint(NN.max))}}else this.boundingBox.makeEmpty();isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z)}}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new EO);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)this.boundingSphere.set(new iO,1/0);else if(t){const i=this.boundingSphere.center;if(NN.setFromBufferAttribute(t),e)for(let t=0,i=e.length;t<i;t++){const i=e[t];FN.setFromBufferAttribute(i),this.morphTargetsRelative?(UN.addVectors(NN.min,FN.min),NN.expandByPoint(UN),UN.addVectors(NN.max,FN.max),NN.expandByPoint(UN)):(NN.expandByPoint(FN.min),NN.expandByPoint(FN.max))}NN.getCenter(i);let s=0;for(let e=0,n=t.count;e<n;e++)UN.fromBufferAttribute(t,e),s=Math.max(s,i.distanceToSquared(UN));if(e)for(let n=0,r=e.length;n<r;n++){const r=e[n],a=this.morphTargetsRelative;for(let e=0,n=r.count;e<n;e++)UN.fromBufferAttribute(r,e),a&&(ON.fromBufferAttribute(t,e),UN.add(ON)),s=Math.max(s,i.distanceToSquared(UN))}this.boundingSphere.radius=Math.sqrt(s),isNaN(this.boundingSphere.radius)}}computeTangents(){const t=this.index,e=this.attributes;if(null===t||void 0===e.position||void 0===e.normal||void 0===e.uv)return;const i=t.array,s=e.position.array,n=e.normal.array,r=e.uv.array,a=s.length/3;!1===this.hasAttribute("tangent")&&this.setAttribute("tangent",new CN(new Float32Array(4*a),4));const o=this.getAttribute("tangent").array,l=[],h=[];for(let t=0;t<a;t++)l[t]=new iO,h[t]=new iO;const c=new iO,d=new iO,u=new iO,f=new MI,p=new MI,m=new MI,_=new iO,g=new iO;function v(t,e,i){c.fromArray(s,3*t),d.fromArray(s,3*e),u.fromArray(s,3*i),f.fromArray(r,2*t),p.fromArray(r,2*e),m.fromArray(r,2*i),d.sub(c),u.sub(c),p.sub(f),m.sub(f);const n=1/(p.x*m.y-m.x*p.y);isFinite(n)&&(_.copy(d).multiplyScalar(m.y).addScaledVector(u,-p.y).multiplyScalar(n),g.copy(u).multiplyScalar(p.x).addScaledVector(d,-m.x).multiplyScalar(n),l[t].add(_),l[e].add(_),l[i].add(_),h[t].add(g),h[e].add(g),h[i].add(g))}let S=this.groups;0===S.length&&(S=[{start:0,count:i.length}]);for(let t=0,e=S.length;t<e;++t){const e=S[t],s=e.start;for(let t=s,n=s+e.count;t<n;t+=3)v(i[t+0],i[t+1],i[t+2])}const y=new iO,x=new iO,T=new iO,E=new iO;function b(t){T.fromArray(n,3*t),E.copy(T);const e=l[t];y.copy(e),y.sub(T.multiplyScalar(T.dot(e))).normalize(),x.crossVectors(E,e);const i=x.dot(h[t])<0?-1:1;o[4*t]=y.x,o[4*t+1]=y.y,o[4*t+2]=y.z,o[4*t+3]=i}for(let t=0,e=S.length;t<e;++t){const e=S[t],s=e.start;for(let t=s,n=s+e.count;t<n;t+=3)b(i[t+0]),b(i[t+1]),b(i[t+2])}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let i=this.getAttribute("normal");if(void 0===i)i=new CN(new Float32Array(3*e.count),3),this.setAttribute("normal",i);else for(let t=0,e=i.count;t<e;t++)i.setXYZ(t,0,0,0);const s=new iO,n=new iO,r=new iO,a=new iO,o=new iO,l=new iO,h=new iO,c=new iO;if(t)for(let d=0,u=t.count;d<u;d+=3){const u=t.getX(d+0),f=t.getX(d+1),p=t.getX(d+2);s.fromBufferAttribute(e,u),n.fromBufferAttribute(e,f),r.fromBufferAttribute(e,p),h.subVectors(r,n),c.subVectors(s,n),h.cross(c),a.fromBufferAttribute(i,u),o.fromBufferAttribute(i,f),l.fromBufferAttribute(i,p),a.add(h),o.add(h),l.add(h),i.setXYZ(u,a.x,a.y,a.z),i.setXYZ(f,o.x,o.y,o.z),i.setXYZ(p,l.x,l.y,l.z)}else for(let t=0,a=e.count;t<a;t+=3)s.fromBufferAttribute(e,t+0),n.fromBufferAttribute(e,t+1),r.fromBufferAttribute(e,t+2),h.subVectors(r,n),c.subVectors(s,n),h.cross(c),i.setXYZ(t+0,h.x,h.y,h.z),i.setXYZ(t+1,h.x,h.y,h.z),i.setXYZ(t+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)UN.fromBufferAttribute(t,e),UN.normalize(),t.setXYZ(e,UN.x,UN.y,UN.z)}toNonIndexed(){function t(t,e){const i=t.array,s=t.itemSize,n=t.normalized,r=new i.constructor(e.length*s);let a=0,o=0;for(let n=0,l=e.length;n<l;n++){a=t.isInterleavedBufferAttribute?e[n]*t.data.stride+t.offset:e[n]*s;for(let t=0;t<s;t++)r[o++]=i[a++]}return new CN(r,s,n)}if(null===this.index)return this;const e=new BN,i=this.index.array,s=this.attributes;for(const n in s){const r=t(s[n],i);e.setAttribute(n,r)}const n=this.morphAttributes;for(const s in n){const r=[],a=n[s];for(let e=0,s=a.length;e<s;e++){const s=t(a[e],i);r.push(s)}e.morphAttributes[s]=r}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let t=0,i=r.length;t<i;t++){const i=r[t];e.addGroup(i.start,i.count,i.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 i in e)void 0!==e[i]&&(t[i]=e[i]);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 i=this.attributes;for(const e in i){const s=i[e];t.data.attributes[e]=s.toJSON(t.data)}const s={};let n=!1;for(const e in this.morphAttributes){const i=this.morphAttributes[e],r=[];for(let e=0,s=i.length;e<s;e++){const s=i[e];r.push(s.toJSON(t.data))}r.length>0&&(s[e]=r,n=!0)}n&&(t.data.morphAttributes=s,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return 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 i=t.index;null!==i&&this.setIndex(i.clone(e));const s=t.attributes;for(const t in s){const i=s[t];this.setAttribute(t,i.clone(e))}const n=t.morphAttributes;for(const t in n){const i=[],s=n[t];for(let t=0,n=s.length;t<n;t++)i.push(s[t].clone(e));this.morphAttributes[t]=i}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let t=0,e=r.length;t<e;t++){const e=r[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 zN=new DO,kN=new LO,VN=new EO,HN=new iO,GN=new iO,WN=new iO,XN=new iO,YN=new iO,qN=new iO,jN=new MI,$N=new MI,KN=new MI,ZN=new iO,QN=new iO,JN=new iO,tF=new iO,eF=new iO;class iF extends sN{constructor(t=new BN,e=new bN){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 i=t[e[0]];if(void 0!==i){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=i.length;t<e;t++){const e=i[t].name||String(t);this.morphTargetInfluences.push(0),this.morphTargetDictionary[e]=t}}}}getVertexPosition(t,e){const i=this.geometry,s=i.attributes.position,n=i.morphAttributes.position,r=i.morphTargetsRelative;e.fromBufferAttribute(s,t);const a=this.morphTargetInfluences;if(n&&a){qN.set(0,0,0);for(let i=0,s=n.length;i<s;i++){const s=a[i],o=n[i];0!==s&&(YN.fromBufferAttribute(o,t),r?qN.addScaledVector(YN,s):qN.addScaledVector(YN.sub(e),s))}e.add(qN)}return e}raycast(t,e){const i=this.geometry,s=this.material,n=this.matrixWorld;if(void 0!==s){if(null===i.boundingSphere&&i.computeBoundingSphere(),VN.copy(i.boundingSphere),VN.applyMatrix4(n),kN.copy(t.ray).recast(t.near),!1===VN.containsPoint(kN.origin)){if(null===kN.intersectSphere(VN,HN))return;if(kN.origin.distanceToSquared(HN)>(t.far-t.near)**2)return}zN.copy(n).invert(),kN.copy(t.ray).applyMatrix4(zN),null!==i.boundingBox&&!1===kN.intersectsBox(i.boundingBox)||this._computeIntersections(t,e,kN)}}_computeIntersections(t,e,i){let s;const n=this.geometry,r=this.material,a=n.index,o=n.attributes.position,l=n.attributes.uv,h=n.attributes.uv1,c=n.attributes.normal,d=n.groups,u=n.drawRange;if(null!==a)if(Array.isArray(r))for(let n=0,o=d.length;n<o;n++){const o=d[n],f=r[o.materialIndex];for(let n=Math.max(o.start,u.start),r=Math.min(a.count,Math.min(o.start+o.count,u.start+u.count));n<r;n+=3){s=sF(this,f,t,i,l,h,c,a.getX(n),a.getX(n+1),a.getX(n+2)),s&&(s.faceIndex=Math.floor(n/3),s.face.materialIndex=o.materialIndex,e.push(s))}}else{for(let n=Math.max(0,u.start),o=Math.min(a.count,u.start+u.count);n<o;n+=3){s=sF(this,r,t,i,l,h,c,a.getX(n),a.getX(n+1),a.getX(n+2)),s&&(s.faceIndex=Math.floor(n/3),e.push(s))}}else if(void 0!==o)if(Array.isArray(r))for(let n=0,a=d.length;n<a;n++){const a=d[n],f=r[a.materialIndex];for(let n=Math.max(a.start,u.start),r=Math.min(o.count,Math.min(a.start+a.count,u.start+u.count));n<r;n+=3){s=sF(this,f,t,i,l,h,c,n,n+1,n+2),s&&(s.faceIndex=Math.floor(n/3),s.face.materialIndex=a.materialIndex,e.push(s))}}else{for(let n=Math.max(0,u.start),a=Math.min(o.count,u.start+u.count);n<a;n+=3){s=sF(this,r,t,i,l,h,c,n,n+1,n+2),s&&(s.faceIndex=Math.floor(n/3),e.push(s))}}}}function sF(t,e,i,s,n,r,a,o,l,h){t.getVertexPosition(o,GN),t.getVertexPosition(l,WN),t.getVertexPosition(h,XN);const c=function(t,e,i,s,n,r,a,o){let l;if(l=1===e.side?s.intersectTriangle(a,r,n,!0,o):s.intersectTriangle(n,r,a,0===e.side,o),null===l)return null;eF.copy(o),eF.applyMatrix4(t.matrixWorld);const h=i.ray.origin.distanceTo(eF);return h<i.near||h>i.far?null:{distance:h,point:eF.clone(),object:t}}(t,e,i,s,GN,WN,XN,tF);if(c){n&&(jN.fromBufferAttribute(n,o),$N.fromBufferAttribute(n,l),KN.fromBufferAttribute(n,h),c.uv=mN.getInterpolation(tF,GN,WN,XN,jN,$N,KN,new MI)),r&&(jN.fromBufferAttribute(r,o),$N.fromBufferAttribute(r,l),KN.fromBufferAttribute(r,h),c.uv1=mN.getInterpolation(tF,GN,WN,XN,jN,$N,KN,new MI),c.uv2=c.uv1),a&&(ZN.fromBufferAttribute(a,o),QN.fromBufferAttribute(a,l),JN.fromBufferAttribute(a,h),c.normal=mN.getInterpolation(tF,GN,WN,XN,ZN,QN,JN,new iO),c.normal.dot(s.direction)>0&&c.normal.multiplyScalar(-1));const t={a:o,b:l,c:h,normal:new iO,materialIndex:0};mN.getNormal(GN,WN,XN,t.normal),c.face=t}return c}class nF extends BN{constructor(t=1,e=1,i=1,s=1,n=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:i,widthSegments:s,heightSegments:n,depthSegments:r};const a=this;s=Math.floor(s),n=Math.floor(n),r=Math.floor(r);const o=[],l=[],h=[],c=[];let d=0,u=0;function f(t,e,i,s,n,r,f,p,m,_,g){const v=r/m,S=f/_,y=r/2,x=f/2,T=p/2,E=m+1,b=_+1;let w=0,A=0;const C=new iO;for(let r=0;r<b;r++){const a=r*S-x;for(let o=0;o<E;o++){const d=o*v-y;C[t]=d*s,C[e]=a*n,C[i]=T,l.push(C.x,C.y,C.z),C[t]=0,C[e]=0,C[i]=p>0?1:-1,h.push(C.x,C.y,C.z),c.push(o/m),c.push(1-r/_),w+=1}}for(let t=0;t<_;t++)for(let e=0;e<m;e++){const i=d+e+E*t,s=d+e+E*(t+1),n=d+(e+1)+E*(t+1),r=d+(e+1)+E*t;o.push(i,s,r),o.push(s,n,r),A+=6}a.addGroup(u,A,g),u+=A,d+=w}f("z","y","x",-1,-1,i,e,t,r,n,0),f("z","y","x",1,-1,i,e,-t,r,n,1),f("x","z","y",1,1,t,i,e,s,r,2),f("x","z","y",1,-1,t,i,-e,s,r,3),f("x","y","z",1,-1,t,e,i,s,n,4),f("x","y","z",-1,-1,t,e,-i,s,n,5),this.setIndex(o),this.setAttribute("position",new RN(l,3)),this.setAttribute("normal",new RN(h,3)),this.setAttribute("uv",new RN(c,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new nF(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function rF(t){const e={};for(const i in t){e[i]={};for(const s in t[i]){const n=t[i][s];n&&(n.isColor||n.isMatrix3||n.isMatrix4||n.isVector2||n.isVector3||n.isVector4||n.isTexture||n.isQuaternion)?n.isRenderTargetTexture?e[i][s]=null:e[i][s]=n.clone():Array.isArray(n)?e[i][s]=n.slice():e[i][s]=n}}return e}function aF(t){const e={};for(let i=0;i<t.length;i++){const s=rF(t[i]);for(const t in s)e[t]=s[t]}return e}function oF(t){return null===t.getRenderTarget()?t.outputColorSpace:kI.workingColorSpace}const lF={clone:rF,merge:aF};class hF extends gN{constructor(t){super(),this.isShaderMaterial=!0,this.type="ShaderMaterial",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={derivatives:!1,fragDepth:!1,drawBuffers:!1,shaderTextureLOD:!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=rF(t.uniforms),this.uniformsGroups=function(t){const e=[];for(let i=0;i<t.length;i++)e.push(t[i].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 i in this.uniforms){const s=this.uniforms[i].value;s&&s.isTexture?e.uniforms[i]={type:"t",value:s.toJSON(t).uuid}:s&&s.isColor?e.uniforms[i]={type:"c",value:s.getHex()}:s&&s.isVector2?e.uniforms[i]={type:"v2",value:s.toArray()}:s&&s.isVector3?e.uniforms[i]={type:"v3",value:s.toArray()}:s&&s.isVector4?e.uniforms[i]={type:"v4",value:s.toArray()}:s&&s.isMatrix3?e.uniforms[i]={type:"m3",value:s.toArray()}:s&&s.isMatrix4?e.uniforms[i]={type:"m4",value:s.toArray()}:e.uniforms[i]={value:s}}Object.keys(this.defines).length>0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const i={};for(const t in this.extensions)!0===this.extensions[t]&&(i[t]=!0);return Object.keys(i).length>0&&(e.extensions=i),e}}class cF extends sN{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new DO,this.projectionMatrix=new DO,this.projectionMatrixInverse=new DO,this.coordinateSystem=mI}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)}}class dF extends cF{constructor(t=50,e=1,i=.1,s=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=i,this.far=s,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=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*yI*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*SI*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*yI*Math.atan(Math.tan(.5*SI*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}setViewOffset(t,e,i,s,n,r){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=i,this.view.offsetY=s,this.view.width=n,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*SI*this.fov)/this.zoom,i=2*e,s=this.aspect*i,n=-.5*s;const r=this.view;if(null!==this.view&&this.view.enabled){const t=r.fullWidth,a=r.fullHeight;n+=r.offsetX*s/t,e-=r.offsetY*i/a,s*=r.width/t,i*=r.height/a}const a=this.filmOffset;0!==a&&(n+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(n,n+s,e,e-i,t,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const uF=-90;class fF extends sN{constructor(t,e,i){super(),this.type="CubeCamera",this.renderTarget=i,this.coordinateSystem=null,this.activeMipmapLevel=0;const s=new dF(uF,1,t,e);s.layers=this.layers,this.add(s);const n=new dF(uF,1,t,e);n.layers=this.layers,this.add(n);const r=new dF(uF,1,t,e);r.layers=this.layers,this.add(r);const a=new dF(uF,1,t,e);a.layers=this.layers,this.add(a);const o=new dF(uF,1,t,e);o.layers=this.layers,this.add(o);const l=new dF(uF,1,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[i,s,n,r,a,o]=e;for(const t of e)this.remove(t);if(t===mI)i.up.set(0,1,0),i.lookAt(1,0,0),s.up.set(0,1,0),s.lookAt(-1,0,0),n.up.set(0,0,-1),n.lookAt(0,1,0),r.up.set(0,0,1),r.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),o.up.set(0,1,0),o.lookAt(0,0,-1);else{if(t!==_I)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);i.up.set(0,-1,0),i.lookAt(-1,0,0),s.up.set(0,-1,0),s.lookAt(1,0,0),n.up.set(0,0,1),n.lookAt(0,1,0),r.up.set(0,0,-1),r.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),o.up.set(0,-1,0),o.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:i,activeMipmapLevel:s}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[n,r,a,o,l,h]=this.children,c=t.getRenderTarget(),d=t.getActiveCubeFace(),u=t.getActiveMipmapLevel(),f=t.xr.enabled;t.xr.enabled=!1;const p=i.texture.generateMipmaps;i.texture.generateMipmaps=!1,t.setRenderTarget(i,0,s),t.render(e,n),t.setRenderTarget(i,1,s),t.render(e,r),t.setRenderTarget(i,2,s),t.render(e,a),t.setRenderTarget(i,3,s),t.render(e,o),t.setRenderTarget(i,4,s),t.render(e,l),i.texture.generateMipmaps=p,t.setRenderTarget(i,5,s),t.render(e,h),t.setRenderTarget(c,d,u),t.xr.enabled=f,i.texture.needsPMREMUpdate=!0}}class pF extends $I{constructor(t,e,i,s,n,r,a,o,l,h){super(t=void 0!==t?t:[],e=void 0!==e?e:xD,i,s,n,r,a,o,l,h),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class mF extends QI{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const i={width:t,height:t,depth:1},s=[i,i,i,i,i,i];void 0!==e.encoding&&(NI("THREE.WebGLCubeRenderTarget: option.encoding has been replaced by option.colorSpace."),e.colorSpace=e.encoding===jD?KD:$D),this.texture=new pF(s,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==e.generateMipmaps&&e.generateMipmaps,this.texture.minFilter=void 0!==e.minFilter?e.minFilter:RD}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const i={uniforms:{tEquirect:{value:null}},vertexShader:"\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"},s=new nF(5,5,5),n=new hF({name:"CubemapFromEquirect",uniforms:rF(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:1,blending:0});n.uniforms.tEquirect.value=e;const r=new iF(s,n),a=e.minFilter;e.minFilter===DD&&(e.minFilter=RD);return new fF(1,10,this).update(t,r),e.minFilter=a,r.geometry.dispose(),r.material.dispose(),this}clear(t,e,i,s){const n=t.getRenderTarget();for(let n=0;n<6;n++)t.setRenderTarget(this,n),t.clear(e,i,s);t.setRenderTarget(n)}}const _F=new iO,gF=new iO,vF=new PI;class SF{constructor(t=new iO(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,s){return this.normal.set(t,e,i),this.constant=s,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const s=_F.subVectors(i,e).cross(gF.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(s,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const i=t.delta(_F),s=this.normal.dot(i);if(0===s)return 0===this.distanceToPoint(t.start)?e.copy(t.start):null;const n=-(t.start.dot(this.normal)+this.constant)/s;return n<0||n>1?null:e.copy(t.start).addScaledVector(i,n)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const i=e||vF.getNormalMatrix(t),s=this.coplanarPoint(_F).applyMatrix4(t),n=this.normal.applyMatrix3(i).normalize();return this.constant=-s.dot(n),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}const yF=new EO,xF=new iO;class TF{constructor(t=new SF,e=new SF,i=new SF,s=new SF,n=new SF,r=new SF){this.planes=[t,e,i,s,n,r]}set(t,e,i,s,n,r){const a=this.planes;return a[0].copy(t),a[1].copy(e),a[2].copy(i),a[3].copy(s),a[4].copy(n),a[5].copy(r),this}copy(t){const e=this.planes;for(let i=0;i<6;i++)e[i].copy(t.planes[i]);return this}setFromProjectionMatrix(t,e=2e3){const i=this.planes,s=t.elements,n=s[0],r=s[1],a=s[2],o=s[3],l=s[4],h=s[5],c=s[6],d=s[7],u=s[8],f=s[9],p=s[10],m=s[11],_=s[12],g=s[13],v=s[14],S=s[15];if(i[0].setComponents(o-n,d-l,m-u,S-_).normalize(),i[1].setComponents(o+n,d+l,m+u,S+_).normalize(),i[2].setComponents(o+r,d+h,m+f,S+g).normalize(),i[3].setComponents(o-r,d-h,m-f,S-g).normalize(),i[4].setComponents(o-a,d-c,m-p,S-v).normalize(),e===mI)i[5].setComponents(o+a,d+c,m+p,S+v).normalize();else{if(e!==_I)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);i[5].setComponents(a,c,p,v).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),yF.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),yF.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(yF)}intersectsSprite(t){return yF.center.set(0,0,0),yF.radius=.7071067811865476,yF.applyMatrix4(t.matrixWorld),this.intersectsSphere(yF)}intersectsSphere(t){const e=this.planes,i=t.center,s=-t.radius;for(let t=0;t<6;t++){if(e[t].distanceToPoint(i)<s)return!1}return!0}intersectsBox(t){const e=this.planes;for(let i=0;i<6;i++){const s=e[i];if(xF.x=s.normal.x>0?t.max.x:t.min.x,xF.y=s.normal.y>0?t.max.y:t.min.y,xF.z=s.normal.z>0?t.max.z:t.min.z,s.distanceToPoint(xF)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let i=0;i<6;i++)if(e[i].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function EF(){let t=null,e=!1,i=null,s=null;function n(e,r){i(e,r),s=t.requestAnimationFrame(n)}return{start:function(){!0!==e&&null!==i&&(s=t.requestAnimationFrame(n),e=!0)},stop:function(){t.cancelAnimationFrame(s),e=!1},setAnimationLoop:function(t){i=t},setContext:function(e){t=e}}}function bF(t,e){const i=e.isWebGL2,s=new WeakMap;return{get:function(t){return t.isInterleavedBufferAttribute&&(t=t.data),s.get(t)},remove:function(e){e.isInterleavedBufferAttribute&&(e=e.data);const i=s.get(e);i&&(t.deleteBuffer(i.buffer),s.delete(e))},update:function(e,n){if(e.isGLBufferAttribute){const t=s.get(e);return void((!t||t.version<e.version)&&s.set(e,{buffer:e.buffer,type:e.type,bytesPerElement:e.elementSize,version:e.version}))}e.isInterleavedBufferAttribute&&(e=e.data);const r=s.get(e);void 0===r?s.set(e,function(e,s){const n=e.array,r=e.usage,a=t.createBuffer();let o;if(t.bindBuffer(s,a),t.bufferData(s,n,r),e.onUploadCallback(),n instanceof Float32Array)o=t.FLOAT;else if(n instanceof Uint16Array)if(e.isFloat16BufferAttribute){if(!i)throw new Error("THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.");o=t.HALF_FLOAT}else o=t.UNSIGNED_SHORT;else if(n instanceof Int16Array)o=t.SHORT;else if(n instanceof Uint32Array)o=t.UNSIGNED_INT;else if(n instanceof Int32Array)o=t.INT;else if(n instanceof Int8Array)o=t.BYTE;else if(n instanceof Uint8Array)o=t.UNSIGNED_BYTE;else{if(!(n instanceof Uint8ClampedArray))throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+n);o=t.UNSIGNED_BYTE}return{buffer:a,type:o,bytesPerElement:n.BYTES_PER_ELEMENT,version:e.version}}(e,n)):r.version<e.version&&(!function(e,s,n){const r=s.array,a=s.updateRange;t.bindBuffer(n,e),-1===a.count?t.bufferSubData(n,0,r):(i?t.bufferSubData(n,a.offset*r.BYTES_PER_ELEMENT,r,a.offset,a.count):t.bufferSubData(n,a.offset*r.BYTES_PER_ELEMENT,r.subarray(a.offset,a.offset+a.count)),a.count=-1),s.onUploadCallback()}(r.buffer,e,n),r.version=e.version)}}}class wF extends BN{constructor(t=1,e=1,i=1,s=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:i,heightSegments:s};const n=t/2,r=e/2,a=Math.floor(i),o=Math.floor(s),l=a+1,h=o+1,c=t/a,d=e/o,u=[],f=[],p=[],m=[];for(let t=0;t<h;t++){const e=t*d-r;for(let i=0;i<l;i++){const s=i*c-n;f.push(s,-e,0),p.push(0,0,1),m.push(i/a),m.push(1-t/o)}}for(let t=0;t<o;t++)for(let e=0;e<a;e++){const i=e+l*t,s=e+l*(t+1),n=e+1+l*(t+1),r=e+1+l*t;u.push(i,s,r),u.push(s,n,r)}this.setIndex(u),this.setAttribute("position",new RN(f,3)),this.setAttribute("normal",new RN(p,3)),this.setAttribute("uv",new RN(m,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new wF(t.width,t.height,t.widthSegments,t.heightSegments)}}const AF={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\tif ( diffuseColor.a < alphaTest ) discard;\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_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",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 = dFdx( surf_pos.xyz );\n\t\tvec3 vSigmaY = 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#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\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 )\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 )\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",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}\nfloat luminance( const in vec3 rgb ) {\n\tconst vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 );\n\treturn dot( weights, rgb );\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_v0 0.339\n\t#define cubeUV_m0 - 2.0\n\t#define cubeUV_r1 0.8\n\t#define cubeUV_v1 0.276\n\t#define cubeUV_m1 - 1.0\n\t#define cubeUV_r4 0.4\n\t#define cubeUV_v4 0.046\n\t#define cubeUV_m4 2.0\n\t#define cubeUV_r5 0.305\n\t#define cubeUV_v5 0.016\n\t#define cubeUV_m5 3.0\n\t#define cubeUV_r6 0.21\n\t#define cubeUV_v6 0.0038\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_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 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\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:"\nconst mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(\n\tvec3( 0.8224621, 0.177538, 0.0 ),\n\tvec3( 0.0331941, 0.9668058, 0.0 ),\n\tvec3( 0.0170827, 0.0723974, 0.9105199 )\n);\nconst mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.2249401, - 0.2249404, 0.0 ),\n\tvec3( - 0.0420569, 1.0420571, 0.0 ),\n\tvec3( - 0.0196376, - 0.0786361, 1.0982735 )\n);\nvec4 LinearSRGBToLinearDisplayP3( in vec4 value ) {\n\treturn vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a );\n}\nvec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) {\n\treturn vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a );\n}\nvec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\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}\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn sRGBTransferOETF( value );\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, 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\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, 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, 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_fragment:"#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\treflectedLight.indirectDiffuse += lightMapIrradiance;\n#endif",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\t#if defined ( LEGACY_LIGHTS )\n\t\tif ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\t\treturn pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t\t}\n\t\treturn 1.0;\n\t#else\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\t\tif ( cutoffDistance > 0.0 ) {\n\t\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t\t}\n\t\treturn distanceFalloff;\n\t#endif\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_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\tanisotropyV /= material.anisotropy;\n\tmaterial.anisotropy = saturate( material.anisotropy );\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\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 clearcoatSpecular = vec3( 0.0 );\nvec3 sheenSpecular = 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\tclearcoatSpecular += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecular += 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\tclearcoatSpecular += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecular += 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;\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.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.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.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 ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif",logdepthbuf_pars_fragment:"#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_pars_vertex:"#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif",map_fragment:"#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );\n\t\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",morphcolor_vertex:"#if defined( USE_MORPHCOLORS ) && defined( MORPHTARGETS_TEXTURE )\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\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t\t}\n\t#else\n\t\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\t\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\t\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\t\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n\t#endif\n#endif",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t\tuniform sampler2DArray morphTargetsTexture;\n\t\tuniform ivec2 morphTargetsTextureSize;\n\t\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t\t}\n\t#else\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\tuniform float morphTargetInfluences[ 8 ];\n\t\t#else\n\t\t\tuniform float morphTargetInfluences[ 4 ];\n\t\t#endif\n\t#endif\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t\t}\n\t#else\n\t\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\t\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\t\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\t\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t\t#endif\n\t#endif\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.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec2 packDepthToRG( in highp float v ) {\n\treturn packDepthToRGBA( v ).yx;\n}\nfloat unpackRGToDepth( const in highp vec2 v ) {\n\treturn unpackRGBAToDepth( vec4( v.xy, 0.0, 0.0 ) );\n}\nvec4 pack2HalfToRGBA( 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( 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_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 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 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 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 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 shadow;\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 shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\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 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 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 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.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.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.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\tuniform int boneTextureSize;\n\tmat4 getBoneMatrix( const in float i ) {\n\t\tfloat j = i * 4.0;\n\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\ty = dy * ( y + 0.5 );\n\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\treturn bone;\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 OptimizedCineonToneMapping( 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}\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.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 ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\trefractionCoords += 1.0;\n\t\trefractionCoords /= 2.0;\n\t\tvec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\tvec3 transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\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_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;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, 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 <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 <skinbase_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\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#endif\n}",distanceRGBA_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\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 <skinbase_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\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 <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\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <morphcolor_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <morphcolor_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <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#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\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 ), opacity );\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 <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 <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}",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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <morphcolor_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_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 + sheenSpecular;\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 ) + clearcoatSpecular * 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 <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 <morphcolor_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\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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 <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 <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 <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 * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\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\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\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}"},CF={common:{diffuse:{value:new TN(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new PI},alphaMap:{value:null},alphaMapTransform:{value:new PI},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new PI}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new PI}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new PI}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new PI},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new PI},normalScale:{value:new MI(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new PI},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new PI}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new PI}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new PI}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new TN(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{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 TN(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new PI},alphaTest:{value:0},uvTransform:{value:new PI}},sprite:{diffuse:{value:new TN(16777215)},opacity:{value:1},center:{value:new MI(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new PI},alphaMap:{value:null},alphaMapTransform:{value:new PI},alphaTest:{value:0}}},MF={basic:{uniforms:aF([CF.common,CF.specularmap,CF.envmap,CF.aomap,CF.lightmap,CF.fog]),vertexShader:AF.meshbasic_vert,fragmentShader:AF.meshbasic_frag},lambert:{uniforms:aF([CF.common,CF.specularmap,CF.envmap,CF.aomap,CF.lightmap,CF.emissivemap,CF.bumpmap,CF.normalmap,CF.displacementmap,CF.fog,CF.lights,{emissive:{value:new TN(0)}}]),vertexShader:AF.meshlambert_vert,fragmentShader:AF.meshlambert_frag},phong:{uniforms:aF([CF.common,CF.specularmap,CF.envmap,CF.aomap,CF.lightmap,CF.emissivemap,CF.bumpmap,CF.normalmap,CF.displacementmap,CF.fog,CF.lights,{emissive:{value:new TN(0)},specular:{value:new TN(1118481)},shininess:{value:30}}]),vertexShader:AF.meshphong_vert,fragmentShader:AF.meshphong_frag},standard:{uniforms:aF([CF.common,CF.envmap,CF.aomap,CF.lightmap,CF.emissivemap,CF.bumpmap,CF.normalmap,CF.displacementmap,CF.roughnessmap,CF.metalnessmap,CF.fog,CF.lights,{emissive:{value:new TN(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:AF.meshphysical_vert,fragmentShader:AF.meshphysical_frag},toon:{uniforms:aF([CF.common,CF.aomap,CF.lightmap,CF.emissivemap,CF.bumpmap,CF.normalmap,CF.displacementmap,CF.gradientmap,CF.fog,CF.lights,{emissive:{value:new TN(0)}}]),vertexShader:AF.meshtoon_vert,fragmentShader:AF.meshtoon_frag},matcap:{uniforms:aF([CF.common,CF.bumpmap,CF.normalmap,CF.displacementmap,CF.fog,{matcap:{value:null}}]),vertexShader:AF.meshmatcap_vert,fragmentShader:AF.meshmatcap_frag},points:{uniforms:aF([CF.points,CF.fog]),vertexShader:AF.points_vert,fragmentShader:AF.points_frag},dashed:{uniforms:aF([CF.common,CF.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:AF.linedashed_vert,fragmentShader:AF.linedashed_frag},depth:{uniforms:aF([CF.common,CF.displacementmap]),vertexShader:AF.depth_vert,fragmentShader:AF.depth_frag},normal:{uniforms:aF([CF.common,CF.bumpmap,CF.normalmap,CF.displacementmap,{opacity:{value:1}}]),vertexShader:AF.meshnormal_vert,fragmentShader:AF.meshnormal_frag},sprite:{uniforms:aF([CF.sprite,CF.fog]),vertexShader:AF.sprite_vert,fragmentShader:AF.sprite_frag},background:{uniforms:{uvTransform:{value:new PI},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:AF.background_vert,fragmentShader:AF.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1}},vertexShader:AF.backgroundCube_vert,fragmentShader:AF.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:AF.cube_vert,fragmentShader:AF.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:AF.equirect_vert,fragmentShader:AF.equirect_frag},distanceRGBA:{uniforms:aF([CF.common,CF.displacementmap,{referencePosition:{value:new iO},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:AF.distanceRGBA_vert,fragmentShader:AF.distanceRGBA_frag},shadow:{uniforms:aF([CF.lights,CF.fog,{color:{value:new TN(0)},opacity:{value:1}}]),vertexShader:AF.shadow_vert,fragmentShader:AF.shadow_frag}};MF.physical={uniforms:aF([MF.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new PI},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new PI},clearcoatNormalScale:{value:new MI(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new PI},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new PI},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new PI},sheen:{value:0},sheenColor:{value:new TN(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new PI},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new PI},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new PI},transmissionSamplerSize:{value:new MI},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new PI},attenuationDistance:{value:0},attenuationColor:{value:new TN(0)},specularColor:{value:new TN(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new PI},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new PI},anisotropyVector:{value:new MI},anisotropyMap:{value:null},anisotropyMapTransform:{value:new PI}}]),vertexShader:AF.meshphysical_vert,fragmentShader:AF.meshphysical_frag};const PF={r:0,b:0,g:0};function RF(t,e,i,s,n,r,a){const o=new TN(0);let l,h,c=!0===r?0:1,d=null,u=0,f=null;function p(e,i){e.getRGB(PF,oF(t)),s.buffers.color.setClear(PF.r,PF.g,PF.b,i,a)}return{getClearColor:function(){return o},setClearColor:function(t,e=1){o.set(t),c=e,p(o,c)},getClearAlpha:function(){return c},setClearAlpha:function(t){c=t,p(o,c)},render:function(r,m){let _=!1,g=!0===m.isScene?m.background:null;if(g&&g.isTexture){g=(m.backgroundBlurriness>0?i:e).get(g)}null===g?p(o,c):g&&g.isColor&&(p(g,1),_=!0);const v=t.xr.getEnvironmentBlendMode();"additive"===v?s.buffers.color.setClear(0,0,0,1,a):"alpha-blend"===v&&s.buffers.color.setClear(0,0,0,0,a),(t.autoClear||_)&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),g&&(g.isCubeTexture||g.mapping===ED)?(void 0===h&&(h=new iF(new nF(1,1,1),new hF({name:"BackgroundCubeMaterial",uniforms:rF(MF.backgroundCube.uniforms),vertexShader:MF.backgroundCube.vertexShader,fragmentShader:MF.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1})),h.geometry.deleteAttribute("normal"),h.geometry.deleteAttribute("uv"),h.onBeforeRender=function(t,e,i){this.matrixWorld.copyPosition(i.matrixWorld)},Object.defineProperty(h.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),n.update(h)),h.material.uniforms.envMap.value=g,h.material.uniforms.flipEnvMap.value=g.isCubeTexture&&!1===g.isRenderTargetTexture?-1:1,h.material.uniforms.backgroundBlurriness.value=m.backgroundBlurriness,h.material.uniforms.backgroundIntensity.value=m.backgroundIntensity,h.material.toneMapped=kI.getTransfer(g.colorSpace)!==eI,d===g&&u===g.version&&f===t.toneMapping||(h.material.needsUpdate=!0,d=g,u=g.version,f=t.toneMapping),h.layers.enableAll(),r.unshift(h,h.geometry,h.material,0,0,null)):g&&g.isTexture&&(void 0===l&&(l=new iF(new wF(2,2),new hF({name:"BackgroundMaterial",uniforms:rF(MF.background.uniforms),vertexShader:MF.background.vertexShader,fragmentShader:MF.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}}),n.update(l)),l.material.uniforms.t2D.value=g,l.material.uniforms.backgroundIntensity.value=m.backgroundIntensity,l.material.toneMapped=kI.getTransfer(g.colorSpace)!==eI,!0===g.matrixAutoUpdate&&g.updateMatrix(),l.material.uniforms.uvTransform.value.copy(g.matrix),d===g&&u===g.version&&f===t.toneMapping||(l.material.needsUpdate=!0,d=g,u=g.version,f=t.toneMapping),l.layers.enableAll(),r.unshift(l,l.geometry,l.material,0,0,null))}}}function LF(t,e,i,s){const n=t.getParameter(t.MAX_VERTEX_ATTRIBS),r=s.isWebGL2?null:e.get("OES_vertex_array_object"),a=s.isWebGL2||null!==r,o={},l=f(null);let h=l,c=!1;function d(e){return s.isWebGL2?t.bindVertexArray(e):r.bindVertexArrayOES(e)}function u(e){return s.isWebGL2?t.deleteVertexArray(e):r.deleteVertexArrayOES(e)}function f(t){const e=[],i=[],s=[];for(let t=0;t<n;t++)e[t]=0,i[t]=0,s[t]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:e,enabledAttributes:i,attributeDivisors:s,object:t,attributes:{},index:null}}function p(){const t=h.newAttributes;for(let e=0,i=t.length;e<i;e++)t[e]=0}function m(t){_(t,0)}function _(i,n){const r=h.newAttributes,a=h.enabledAttributes,o=h.attributeDivisors;if(r[i]=1,0===a[i]&&(t.enableVertexAttribArray(i),a[i]=1),o[i]!==n){(s.isWebGL2?t:e.get("ANGLE_instanced_arrays"))[s.isWebGL2?"vertexAttribDivisor":"vertexAttribDivisorANGLE"](i,n),o[i]=n}}function g(){const e=h.newAttributes,i=h.enabledAttributes;for(let s=0,n=i.length;s<n;s++)i[s]!==e[s]&&(t.disableVertexAttribArray(s),i[s]=0)}function v(e,i,s,n,r,a,o){!0===o?t.vertexAttribIPointer(e,i,s,r,a):t.vertexAttribPointer(e,i,s,n,r,a)}function S(){y(),c=!0,h!==l&&(h=l,d(h.object))}function y(){l.geometry=null,l.program=null,l.wireframe=!1}return{setup:function(n,l,u,S,y){let x=!1;if(a){const e=function(e,i,n){const a=!0===n.wireframe;let l=o[e.id];void 0===l&&(l={},o[e.id]=l);let h=l[i.id];void 0===h&&(h={},l[i.id]=h);let c=h[a];void 0===c&&(c=f(s.isWebGL2?t.createVertexArray():r.createVertexArrayOES()),h[a]=c);return c}(S,u,l);h!==e&&(h=e,d(h.object)),x=function(t,e,i,s){const n=h.attributes,r=e.attributes;let a=0;const o=i.getAttributes();for(const e in o){if(o[e].location>=0){const i=n[e];let s=r[e];if(void 0===s&&("instanceMatrix"===e&&t.instanceMatrix&&(s=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(s=t.instanceColor)),void 0===i)return!0;if(i.attribute!==s)return!0;if(s&&i.data!==s.data)return!0;a++}}return h.attributesNum!==a||h.index!==s}(n,S,u,y),x&&function(t,e,i,s){const n={},r=e.attributes;let a=0;const o=i.getAttributes();for(const e in o){if(o[e].location>=0){let i=r[e];void 0===i&&("instanceMatrix"===e&&t.instanceMatrix&&(i=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(i=t.instanceColor));const s={};s.attribute=i,i&&i.data&&(s.data=i.data),n[e]=s,a++}}h.attributes=n,h.attributesNum=a,h.index=s}(n,S,u,y)}else{const t=!0===l.wireframe;h.geometry===S.id&&h.program===u.id&&h.wireframe===t||(h.geometry=S.id,h.program=u.id,h.wireframe=t,x=!0)}null!==y&&i.update(y,t.ELEMENT_ARRAY_BUFFER),(x||c)&&(c=!1,function(n,r,a,o){if(!1===s.isWebGL2&&(n.isInstancedMesh||o.isInstancedBufferGeometry)&&null===e.get("ANGLE_instanced_arrays"))return;p();const l=o.attributes,h=a.getAttributes(),c=r.defaultAttributeValues;for(const e in h){const r=h[e];if(r.location>=0){let a=l[e];if(void 0===a&&("instanceMatrix"===e&&n.instanceMatrix&&(a=n.instanceMatrix),"instanceColor"===e&&n.instanceColor&&(a=n.instanceColor)),void 0!==a){const e=a.normalized,l=a.itemSize,h=i.get(a);if(void 0===h)continue;const c=h.buffer,d=h.type,u=h.bytesPerElement,f=!0===s.isWebGL2&&(d===t.INT||d===t.UNSIGNED_INT||a.gpuType===ND);if(a.isInterleavedBufferAttribute){const i=a.data,s=i.stride,h=a.offset;if(i.isInstancedInterleavedBuffer){for(let t=0;t<r.locationSize;t++)_(r.location+t,i.meshPerAttribute);!0!==n.isInstancedMesh&&void 0===o._maxInstanceCount&&(o._maxInstanceCount=i.meshPerAttribute*i.count)}else for(let t=0;t<r.locationSize;t++)m(r.location+t);t.bindBuffer(t.ARRAY_BUFFER,c);for(let t=0;t<r.locationSize;t++)v(r.location+t,l/r.locationSize,d,e,s*u,(h+l/r.locationSize*t)*u,f)}else{if(a.isInstancedBufferAttribute){for(let t=0;t<r.locationSize;t++)_(r.location+t,a.meshPerAttribute);!0!==n.isInstancedMesh&&void 0===o._maxInstanceCount&&(o._maxInstanceCount=a.meshPerAttribute*a.count)}else for(let t=0;t<r.locationSize;t++)m(r.location+t);t.bindBuffer(t.ARRAY_BUFFER,c);for(let t=0;t<r.locationSize;t++)v(r.location+t,l/r.locationSize,d,e,l*u,l/r.locationSize*t*u,f)}}else if(void 0!==c){const i=c[e];if(void 0!==i)switch(i.length){case 2:t.vertexAttrib2fv(r.location,i);break;case 3:t.vertexAttrib3fv(r.location,i);break;case 4:t.vertexAttrib4fv(r.location,i);break;default:t.vertexAttrib1fv(r.location,i)}}}}g()}(n,l,u,S),null!==y&&t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,i.get(y).buffer))},reset:S,resetDefaultState:y,dispose:function(){S();for(const t in o){const e=o[t];for(const t in e){const i=e[t];for(const t in i)u(i[t].object),delete i[t];delete e[t]}delete o[t]}},releaseStatesOfGeometry:function(t){if(void 0===o[t.id])return;const e=o[t.id];for(const t in e){const i=e[t];for(const t in i)u(i[t].object),delete i[t];delete e[t]}delete o[t.id]},releaseStatesOfProgram:function(t){for(const e in o){const i=o[e];if(void 0===i[t.id])continue;const s=i[t.id];for(const t in s)u(s[t].object),delete s[t];delete i[t.id]}},initAttributes:p,enableAttribute:m,disableUnusedAttributes:g}}function DF(t,e,i,s){const n=s.isWebGL2;let r;this.setMode=function(t){r=t},this.render=function(e,s){t.drawArrays(r,e,s),i.update(s,r,1)},this.renderInstances=function(s,a,o){if(0===o)return;let l,h;if(n)l=t,h="drawArraysInstanced";else if(l=e.get("ANGLE_instanced_arrays"),h="drawArraysInstancedANGLE",null===l)return;l[h](r,s,a,o),i.update(a,r,o)}}function IF(t,e,i){let s;function n(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"}const r="undefined"!=typeof WebGL2RenderingContext&&"WebGL2RenderingContext"===t.constructor.name;let a=void 0!==i.precision?i.precision:"highp";const o=n(a);o!==a&&(a=o);const l=r||e.has("WEBGL_draw_buffers"),h=!0===i.logarithmicDepthBuffer,c=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),d=t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS),u=t.getParameter(t.MAX_TEXTURE_SIZE),f=t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE),p=t.getParameter(t.MAX_VERTEX_ATTRIBS),m=t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS),_=t.getParameter(t.MAX_VARYING_VECTORS),g=t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS),v=d>0,S=r||e.has("OES_texture_float");return{isWebGL2:r,drawBuffers:l,getMaxAnisotropy:function(){if(void 0!==s)return s;if(!0===e.has("EXT_texture_filter_anisotropic")){const i=e.get("EXT_texture_filter_anisotropic");s=t.getParameter(i.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else s=0;return s},getMaxPrecision:n,precision:a,logarithmicDepthBuffer:h,maxTextures:c,maxVertexTextures:d,maxTextureSize:u,maxCubemapSize:f,maxAttributes:p,maxVertexUniforms:m,maxVaryings:_,maxFragmentUniforms:g,vertexTextures:v,floatFragmentTextures:S,floatVertexTextures:v&&S,maxSamples:r?t.getParameter(t.MAX_SAMPLES):0}}function OF(t){const e=this;let i=null,s=0,n=!1,r=!1;const a=new SF,o=new PI,l={value:null,needsUpdate:!1};function h(t,i,s,n){const r=null!==t?t.length:0;let h=null;if(0!==r){if(h=l.value,!0!==n||null===h){const e=s+4*r,n=i.matrixWorldInverse;o.getNormalMatrix(n),(null===h||h.length<e)&&(h=new Float32Array(e));for(let e=0,i=s;e!==r;++e,i+=4)a.copy(t[e]).applyMatrix4(n,o),a.normal.toArray(h,i),h[i+3]=a.constant}l.value=h,l.needsUpdate=!0}return e.numPlanes=r,e.numIntersection=0,h}this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(t,e){const i=0!==t.length||e||0!==s||n;return n=e,s=t.length,i},this.beginShadows=function(){r=!0,h(null)},this.endShadows=function(){r=!1},this.setGlobalState=function(t,e){i=h(t,e,0)},this.setState=function(a,o,c){const d=a.clippingPlanes,u=a.clipIntersection,f=a.clipShadows,p=t.get(a);if(!n||null===d||0===d.length||r&&!f)r?h(null):function(){l.value!==i&&(l.value=i,l.needsUpdate=s>0);e.numPlanes=s,e.numIntersection=0}();else{const t=r?0:s,e=4*t;let n=p.clippingState||null;l.value=n,n=h(d,o,e,c);for(let t=0;t!==e;++t)n[t]=i[t];p.clippingState=n,this.numIntersection=u?this.numPlanes:0,this.numPlanes+=t}}}function NF(t){let e=new WeakMap;function i(t,e){return 303===e?t.mapping=xD:304===e&&(t.mapping=TD),t}function s(t){const i=t.target;i.removeEventListener("dispose",s);const n=e.get(i);void 0!==n&&(e.delete(i),n.dispose())}return{get:function(n){if(n&&n.isTexture&&!1===n.isRenderTargetTexture){const r=n.mapping;if(303===r||304===r){if(e.has(n)){return i(e.get(n).texture,n.mapping)}{const r=n.image;if(r&&r.height>0){const a=new mF(r.height/2);return a.fromEquirectangularTexture(t,n),e.set(n,a),n.addEventListener("dispose",s),i(a.texture,n.mapping)}return null}}}return n},dispose:function(){e=new WeakMap}}}class FF extends cF{constructor(t=-1,e=1,i=1,s=-1,n=.1,r=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=i,this.bottom=s,this.near=n,this.far=r,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=null===t.view?null:Object.assign({},t.view),this}setViewOffset(t,e,i,s,n,r){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=i,this.view.offsetY=s,this.view.width=n,this.view.height=r,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),i=(this.right+this.left)/2,s=(this.top+this.bottom)/2;let n=i-t,r=i+t,a=s+e,o=s-e;if(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;n+=t*this.view.offsetX,r=n+t*this.view.width,a-=e*this.view.offsetY,o=a-e*this.view.height}this.projectionMatrix.makeOrthographic(n,r,a,o,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,null!==this.view&&(e.object.view=Object.assign({},this.view)),e}}const UF=[.125,.215,.35,.446,.526,.582],BF=20,zF=new FF,kF=new TN;let VF=null;const HF=(1+Math.sqrt(5))/2,GF=1/HF,WF=[new iO(1,1,1),new iO(-1,1,1),new iO(1,1,-1),new iO(-1,1,-1),new iO(0,HF,GF),new iO(0,HF,-GF),new iO(GF,0,HF),new iO(-GF,0,HF),new iO(HF,GF,0),new iO(-HF,GF,0)];class XF{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,i=.1,s=100){VF=this._renderer.getRenderTarget(),this._setSize(256);const n=this._allocateTargets();return n.depthBuffer=!0,this._sceneToCubeUV(t,i,s,n),e>0&&this._blur(n,0,0,e),this._applyPMREM(n),this._cleanup(n),n}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=$F(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=jF(),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(VF),t.scissorTest=!1,qF(t,0,0,t.width,t.height)}_fromTexture(t,e){t.mapping===xD||t.mapping===TD?this._setSize(0===t.image.length?16:t.image[0].width||t.image[0].image.width):this._setSize(t.image.width/4),VF=this._renderer.getRenderTarget();const i=e||this._allocateTargets();return this._textureToCubeUV(t,i),this._applyPMREM(i),this._cleanup(i),i}_allocateTargets(){const t=3*Math.max(this._cubeSize,112),e=4*this._cubeSize,i={magFilter:RD,minFilter:RD,generateMipmaps:!1,type:BD,format:kD,colorSpace:ZD,depthBuffer:!1},s=YF(t,e,i);if(null===this._pingPongRenderTarget||this._pingPongRenderTarget.width!==t||this._pingPongRenderTarget.height!==e){null!==this._pingPongRenderTarget&&this._dispose(),this._pingPongRenderTarget=YF(t,e,i);const{_lodMax:s}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas}=function(t){const e=[],i=[],s=[];let n=t;const r=t-4+1+UF.length;for(let a=0;a<r;a++){const r=Math.pow(2,n);i.push(r);let o=1/r;a>t-4?o=UF[a-t+4-1]:0===a&&(o=0),s.push(o);const l=1/(r-2),h=-l,c=1+l,d=[h,h,c,h,c,c,h,h,c,c,h,c],u=6,f=6,p=3,m=2,_=1,g=new Float32Array(p*f*u),v=new Float32Array(m*f*u),S=new Float32Array(_*f*u);for(let t=0;t<u;t++){const e=t%3*2/3-1,i=t>2?0:-1,s=[e,i,0,e+2/3,i,0,e+2/3,i+1,0,e,i,0,e+2/3,i+1,0,e,i+1,0];g.set(s,p*f*t),v.set(d,m*f*t);const n=[t,t,t,t,t,t];S.set(n,_*f*t)}const y=new BN;y.setAttribute("position",new CN(g,p)),y.setAttribute("uv",new CN(v,m)),y.setAttribute("faceIndex",new CN(S,_)),e.push(y),n>4&&n--}return{lodPlanes:e,sizeLods:i,sigmas:s}}(s)),this._blurMaterial=function(t,e,i){const s=new Float32Array(BF),n=new iO(0,1,0),r=new hF({name:"SphericalGaussianBlur",defines:{n:BF,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/i,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:s},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:n}},vertexShader:KF(),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 r}(s,t,e)}return s}_compileMaterial(t){const e=new iF(this._lodPlanes[0],t);this._renderer.compile(e,zF)}_sceneToCubeUV(t,e,i,s){const n=new dF(90,1,e,i),r=[1,-1,1,1,1,1],a=[1,1,1,-1,-1,-1],o=this._renderer,l=o.autoClear,h=o.toneMapping;o.getClearColor(kF),o.toneMapping=0,o.autoClear=!1;const c=new bN({name:"PMREM.Background",side:1,depthWrite:!1,depthTest:!1}),d=new iF(new nF,c);let u=!1;const f=t.background;f?f.isColor&&(c.color.copy(f),t.background=null,u=!0):(c.color.copy(kF),u=!0);for(let e=0;e<6;e++){const i=e%3;0===i?(n.up.set(0,r[e],0),n.lookAt(a[e],0,0)):1===i?(n.up.set(0,0,r[e]),n.lookAt(0,a[e],0)):(n.up.set(0,r[e],0),n.lookAt(0,0,a[e]));const l=this._cubeSize;qF(s,i*l,e>2?l:0,l,l),o.setRenderTarget(s),u&&o.render(d,n),o.render(t,n)}d.geometry.dispose(),d.material.dispose(),o.toneMapping=h,o.autoClear=l,t.background=f}_textureToCubeUV(t,e){const i=this._renderer,s=t.mapping===xD||t.mapping===TD;s?(null===this._cubemapMaterial&&(this._cubemapMaterial=$F()),this._cubemapMaterial.uniforms.flipEnvMap.value=!1===t.isRenderTargetTexture?-1:1):null===this._equirectMaterial&&(this._equirectMaterial=jF());const n=s?this._cubemapMaterial:this._equirectMaterial,r=new iF(this._lodPlanes[0],n);n.uniforms.envMap.value=t;const a=this._cubeSize;qF(e,0,0,3*a,2*a),i.setRenderTarget(e),i.render(r,zF)}_applyPMREM(t){const e=this._renderer,i=e.autoClear;e.autoClear=!1;for(let e=1;e<this._lodPlanes.length;e++){const i=Math.sqrt(this._sigmas[e]*this._sigmas[e]-this._sigmas[e-1]*this._sigmas[e-1]),s=WF[(e-1)%WF.length];this._blur(t,e-1,e,i,s)}e.autoClear=i}_blur(t,e,i,s,n){const r=this._pingPongRenderTarget;this._halfBlur(t,r,e,i,s,"latitudinal",n),this._halfBlur(r,t,i,i,s,"longitudinal",n)}_halfBlur(t,e,i,s,n,r,a){const o=this._renderer,l=this._blurMaterial,h=new iF(this._lodPlanes[s],l),c=l.uniforms,d=this._sizeLods[i]-1,u=isFinite(n)?Math.PI/(2*d):2*Math.PI/39,f=n/u,p=isFinite(n)?1+Math.floor(3*f):BF,m=[];let _=0;for(let t=0;t<BF;++t){const e=t/f,i=Math.exp(-e*e/2);m.push(i),0===t?_+=i:t<p&&(_+=2*i)}for(let t=0;t<m.length;t++)m[t]=m[t]/_;c.envMap.value=t.texture,c.samples.value=p,c.weights.value=m,c.latitudinal.value="latitudinal"===r,a&&(c.poleAxis.value=a);const{_lodMax:g}=this;c.dTheta.value=u,c.mipInt.value=g-i;const v=this._sizeLods[s];qF(e,3*v*(s>g-4?s-g+4:0),4*(this._cubeSize-v),3*v,2*v),o.setRenderTarget(e),o.render(h,zF)}}function YF(t,e,i){const s=new QI(t,e,i);return s.texture.mapping=ED,s.texture.name="PMREM.cubeUv",s.scissorTest=!0,s}function qF(t,e,i,s,n){t.viewport.set(e,i,s,n),t.scissor.set(e,i,s,n)}function jF(){return new hF({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:KF(),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 $F(){return new hF({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:KF(),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 KF(){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 ZF(t){let e=new WeakMap,i=null;function s(t){const i=t.target;i.removeEventListener("dispose",s);const n=e.get(i);void 0!==n&&(e.delete(i),n.dispose())}return{get:function(n){if(n&&n.isTexture){const r=n.mapping,a=303===r||304===r,o=r===xD||r===TD;if(a||o){if(n.isRenderTargetTexture&&!0===n.needsPMREMUpdate){n.needsPMREMUpdate=!1;let s=e.get(n);return null===i&&(i=new XF(t)),s=a?i.fromEquirectangular(n,s):i.fromCubemap(n,s),e.set(n,s),s.texture}if(e.has(n))return e.get(n).texture;{const r=n.image;if(a&&r&&r.height>0||o&&r&&function(t){let e=0;const i=6;for(let s=0;s<i;s++)void 0!==t[s]&&e++;return e===i}(r)){null===i&&(i=new XF(t));const r=a?i.fromEquirectangular(n):i.fromCubemap(n);return e.set(n,r),n.addEventListener("dispose",s),r.texture}return null}}}return n},dispose:function(){e=new WeakMap,null!==i&&(i.dispose(),i=null)}}}function QF(t){const e={};function i(i){if(void 0!==e[i])return e[i];let s;switch(i){case"WEBGL_depth_texture":s=t.getExtension("WEBGL_depth_texture")||t.getExtension("MOZ_WEBGL_depth_texture")||t.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":s=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":s=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":s=t.getExtension("WEBGL_compressed_texture_pvrtc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:s=t.getExtension(i)}return e[i]=s,s}return{has:function(t){return null!==i(t)},init:function(t){t.isWebGL2?i("EXT_color_buffer_float"):(i("WEBGL_depth_texture"),i("OES_texture_float"),i("OES_texture_half_float"),i("OES_texture_half_float_linear"),i("OES_standard_derivatives"),i("OES_element_index_uint"),i("OES_vertex_array_object"),i("ANGLE_instanced_arrays")),i("OES_texture_float_linear"),i("EXT_color_buffer_half_float"),i("WEBGL_multisampled_render_to_texture")},get:function(t){const e=i(t);return e}}}function JF(t,e,i,s){const n={},r=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 i=o.morphAttributes[t];for(let t=0,s=i.length;t<s;t++)e.remove(i[t])}o.removeEventListener("dispose",a),delete n[o.id];const l=r.get(o);l&&(e.remove(l),r.delete(o)),s.releaseStatesOfGeometry(o),!0===o.isInstancedBufferGeometry&&delete o._maxInstanceCount,i.memory.geometries--}function o(t){const i=[],s=t.index,n=t.attributes.position;let a=0;if(null!==s){const t=s.array;a=s.version;for(let e=0,s=t.length;e<s;e+=3){const s=t[e+0],n=t[e+1],r=t[e+2];i.push(s,n,n,r,r,s)}}else{if(void 0===n)return;{const t=n.array;a=n.version;for(let e=0,s=t.length/3-1;e<s;e+=3){const t=e+0,s=e+1,n=e+2;i.push(t,s,s,n,n,t)}}}const o=new(LI(i)?PN:MN)(i,1);o.version=a;const l=r.get(t);l&&e.remove(l),r.set(t,o)}return{get:function(t,e){return!0===n[e.id]||(e.addEventListener("dispose",a),n[e.id]=!0,i.memory.geometries++),e},update:function(i){const s=i.attributes;for(const i in s)e.update(s[i],t.ARRAY_BUFFER);const n=i.morphAttributes;for(const i in n){const s=n[i];for(let i=0,n=s.length;i<n;i++)e.update(s[i],t.ARRAY_BUFFER)}},getWireframeAttribute:function(t){const e=r.get(t);if(e){const i=t.index;null!==i&&e.version<i.version&&o(t)}else o(t);return r.get(t)}}}function tU(t,e,i,s){const n=s.isWebGL2;let r,a,o;this.setMode=function(t){r=t},this.setIndex=function(t){a=t.type,o=t.bytesPerElement},this.render=function(e,s){t.drawElements(r,s,a,e*o),i.update(s,r,1)},this.renderInstances=function(s,l,h){if(0===h)return;let c,d;if(n)c=t,d="drawElementsInstanced";else if(c=e.get("ANGLE_instanced_arrays"),d="drawElementsInstancedANGLE",null===c)return;c[d](r,l,a,s*o,h),i.update(l,r,h)}}function eU(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(i,s,n){switch(e.calls++,s){case t.TRIANGLES:e.triangles+=n*(i/3);break;case t.LINES:e.lines+=n*(i/2);break;case t.LINE_STRIP:e.lines+=n*(i-1);break;case t.LINE_LOOP:e.lines+=n*i;break;case t.POINTS:e.points+=n*i}}}}function iU(t,e){return t[0]-e[0]}function sU(t,e){return Math.abs(e[1])-Math.abs(t[1])}function nU(t,e,i){const s={},n=new Float32Array(8),r=new WeakMap,a=new KI,o=[];for(let t=0;t<8;t++)o[t]=[t,0];return{update:function(l,h,c){const d=l.morphTargetInfluences;if(!0===e.isWebGL2){const u=h.morphAttributes.position||h.morphAttributes.normal||h.morphAttributes.color,f=void 0!==u?u.length:0;let p=r.get(h);if(void 0===p||p.count!==f){void 0!==p&&p.texture.dispose();const g=void 0!==h.morphAttributes.position,v=void 0!==h.morphAttributes.normal,S=void 0!==h.morphAttributes.color,y=h.morphAttributes.position||[],x=h.morphAttributes.normal||[],T=h.morphAttributes.color||[];let E=0;!0===g&&(E=1),!0===v&&(E=2),!0===S&&(E=3);let b=h.attributes.position.count*E,w=1;b>e.maxTextureSize&&(w=Math.ceil(b/e.maxTextureSize),b=e.maxTextureSize);const A=new Float32Array(b*w*4*f),C=new JI(A,b,w,f);C.type=UD,C.needsUpdate=!0;const M=4*E;for(let R=0;R<f;R++){const L=y[R],D=x[R],I=T[R],O=b*w*4*R;for(let N=0;N<L.count;N++){const F=N*M;!0===g&&(a.fromBufferAttribute(L,N),A[O+F+0]=a.x,A[O+F+1]=a.y,A[O+F+2]=a.z,A[O+F+3]=0),!0===v&&(a.fromBufferAttribute(D,N),A[O+F+4]=a.x,A[O+F+5]=a.y,A[O+F+6]=a.z,A[O+F+7]=0),!0===S&&(a.fromBufferAttribute(I,N),A[O+F+8]=a.x,A[O+F+9]=a.y,A[O+F+10]=a.z,A[O+F+11]=4===I.itemSize?a.w:1)}}function P(){C.dispose(),r.delete(h),h.removeEventListener("dispose",P)}p={count:f,texture:C,size:new MI(b,w)},r.set(h,p),h.addEventListener("dispose",P)}let m=0;for(let U=0;U<d.length;U++)m+=d[U];const _=h.morphTargetsRelative?1:1-m;c.getUniforms().setValue(t,"morphTargetBaseInfluence",_),c.getUniforms().setValue(t,"morphTargetInfluences",d),c.getUniforms().setValue(t,"morphTargetsTexture",p.texture,i),c.getUniforms().setValue(t,"morphTargetsTextureSize",p.size)}else{const B=void 0===d?0:d.length;let z=s[h.id];if(void 0===z||z.length!==B){z=[];for(let W=0;W<B;W++)z[W]=[W,0];s[h.id]=z}for(let X=0;X<B;X++){const Y=z[X];Y[0]=X,Y[1]=d[X]}z.sort(sU);for(let q=0;q<8;q++)q<B&&z[q][1]?(o[q][0]=z[q][0],o[q][1]=z[q][1]):(o[q][0]=Number.MAX_SAFE_INTEGER,o[q][1]=0);o.sort(iU);const k=h.morphAttributes.position,V=h.morphAttributes.normal;let H=0;for(let j=0;j<8;j++){const $=o[j],K=$[0],Z=$[1];K!==Number.MAX_SAFE_INTEGER&&Z?(k&&h.getAttribute("morphTarget"+j)!==k[K]&&h.setAttribute("morphTarget"+j,k[K]),V&&h.getAttribute("morphNormal"+j)!==V[K]&&h.setAttribute("morphNormal"+j,V[K]),n[j]=Z,H+=Z):(k&&!0===h.hasAttribute("morphTarget"+j)&&h.deleteAttribute("morphTarget"+j),V&&!0===h.hasAttribute("morphNormal"+j)&&h.deleteAttribute("morphNormal"+j),n[j]=0)}const G=h.morphTargetsRelative?1:1-H;c.getUniforms().setValue(t,"morphTargetBaseInfluence",G),c.getUniforms().setValue(t,"morphTargetInfluences",n)}}}}function rU(t,e,i,s){let n=new WeakMap;function r(t){const e=t.target;e.removeEventListener("dispose",r),i.remove(e.instanceMatrix),null!==e.instanceColor&&i.remove(e.instanceColor)}return{update:function(a){const o=s.render.frame,l=a.geometry,h=e.get(a,l);if(n.get(h)!==o&&(e.update(h),n.set(h,o)),a.isInstancedMesh&&(!1===a.hasEventListener("dispose",r)&&a.addEventListener("dispose",r),n.get(a)!==o&&(i.update(a.instanceMatrix,t.ARRAY_BUFFER),null!==a.instanceColor&&i.update(a.instanceColor,t.ARRAY_BUFFER),n.set(a,o))),a.isSkinnedMesh){const t=a.skeleton;n.get(t)!==o&&(t.update(),n.set(t,o))}return h},dispose:function(){n=new WeakMap}}}const aU=new $I,oU=new JI,lU=new tO,hU=new pF,cU=[],dU=[],uU=new Float32Array(16),fU=new Float32Array(9),pU=new Float32Array(4);function mU(t,e,i){const s=t[0];if(s<=0||s>0)return t;const n=e*i;let r=cU[n];if(void 0===r&&(r=new Float32Array(n),cU[n]=r),0!==e){s.toArray(r,0);for(let s=1,n=0;s!==e;++s)n+=i,t[s].toArray(r,n)}return r}function _U(t,e){if(t.length!==e.length)return!1;for(let i=0,s=t.length;i<s;i++)if(t[i]!==e[i])return!1;return!0}function gU(t,e){for(let i=0,s=e.length;i<s;i++)t[i]=e[i]}function vU(t,e){let i=dU[e];void 0===i&&(i=new Int32Array(e),dU[e]=i);for(let s=0;s!==e;++s)i[s]=t.allocateTextureUnit();return i}function SU(t,e){const i=this.cache;i[0]!==e&&(t.uniform1f(this.addr,e),i[0]=e)}function yU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2f(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(_U(i,e))return;t.uniform2fv(this.addr,e),gU(i,e)}}function xU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3f(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else if(void 0!==e.r)i[0]===e.r&&i[1]===e.g&&i[2]===e.b||(t.uniform3f(this.addr,e.r,e.g,e.b),i[0]=e.r,i[1]=e.g,i[2]=e.b);else{if(_U(i,e))return;t.uniform3fv(this.addr,e),gU(i,e)}}function TU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4f(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(_U(i,e))return;t.uniform4fv(this.addr,e),gU(i,e)}}function EU(t,e){const i=this.cache,s=e.elements;if(void 0===s){if(_U(i,e))return;t.uniformMatrix2fv(this.addr,!1,e),gU(i,e)}else{if(_U(i,s))return;pU.set(s),t.uniformMatrix2fv(this.addr,!1,pU),gU(i,s)}}function bU(t,e){const i=this.cache,s=e.elements;if(void 0===s){if(_U(i,e))return;t.uniformMatrix3fv(this.addr,!1,e),gU(i,e)}else{if(_U(i,s))return;fU.set(s),t.uniformMatrix3fv(this.addr,!1,fU),gU(i,s)}}function wU(t,e){const i=this.cache,s=e.elements;if(void 0===s){if(_U(i,e))return;t.uniformMatrix4fv(this.addr,!1,e),gU(i,e)}else{if(_U(i,s))return;uU.set(s),t.uniformMatrix4fv(this.addr,!1,uU),gU(i,s)}}function AU(t,e){const i=this.cache;i[0]!==e&&(t.uniform1i(this.addr,e),i[0]=e)}function CU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2i(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(_U(i,e))return;t.uniform2iv(this.addr,e),gU(i,e)}}function MU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3i(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else{if(_U(i,e))return;t.uniform3iv(this.addr,e),gU(i,e)}}function PU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4i(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(_U(i,e))return;t.uniform4iv(this.addr,e),gU(i,e)}}function RU(t,e){const i=this.cache;i[0]!==e&&(t.uniform1ui(this.addr,e),i[0]=e)}function LU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2ui(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(_U(i,e))return;t.uniform2uiv(this.addr,e),gU(i,e)}}function DU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3ui(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else{if(_U(i,e))return;t.uniform3uiv(this.addr,e),gU(i,e)}}function IU(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4ui(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(_U(i,e))return;t.uniform4uiv(this.addr,e),gU(i,e)}}function OU(t,e,i){const s=this.cache,n=i.allocateTextureUnit();s[0]!==n&&(t.uniform1i(this.addr,n),s[0]=n),i.setTexture2D(e||aU,n)}function NU(t,e,i){const s=this.cache,n=i.allocateTextureUnit();s[0]!==n&&(t.uniform1i(this.addr,n),s[0]=n),i.setTexture3D(e||lU,n)}function FU(t,e,i){const s=this.cache,n=i.allocateTextureUnit();s[0]!==n&&(t.uniform1i(this.addr,n),s[0]=n),i.setTextureCube(e||hU,n)}function UU(t,e,i){const s=this.cache,n=i.allocateTextureUnit();s[0]!==n&&(t.uniform1i(this.addr,n),s[0]=n),i.setTexture2DArray(e||oU,n)}function BU(t,e){t.uniform1fv(this.addr,e)}function zU(t,e){const i=mU(e,this.size,2);t.uniform2fv(this.addr,i)}function kU(t,e){const i=mU(e,this.size,3);t.uniform3fv(this.addr,i)}function VU(t,e){const i=mU(e,this.size,4);t.uniform4fv(this.addr,i)}function HU(t,e){const i=mU(e,this.size,4);t.uniformMatrix2fv(this.addr,!1,i)}function GU(t,e){const i=mU(e,this.size,9);t.uniformMatrix3fv(this.addr,!1,i)}function WU(t,e){const i=mU(e,this.size,16);t.uniformMatrix4fv(this.addr,!1,i)}function XU(t,e){t.uniform1iv(this.addr,e)}function YU(t,e){t.uniform2iv(this.addr,e)}function qU(t,e){t.uniform3iv(this.addr,e)}function jU(t,e){t.uniform4iv(this.addr,e)}function $U(t,e){t.uniform1uiv(this.addr,e)}function KU(t,e){t.uniform2uiv(this.addr,e)}function ZU(t,e){t.uniform3uiv(this.addr,e)}function QU(t,e){t.uniform4uiv(this.addr,e)}function JU(t,e,i){const s=this.cache,n=e.length,r=vU(i,n);_U(s,r)||(t.uniform1iv(this.addr,r),gU(s,r));for(let t=0;t!==n;++t)i.setTexture2D(e[t]||aU,r[t])}function tB(t,e,i){const s=this.cache,n=e.length,r=vU(i,n);_U(s,r)||(t.uniform1iv(this.addr,r),gU(s,r));for(let t=0;t!==n;++t)i.setTexture3D(e[t]||lU,r[t])}function eB(t,e,i){const s=this.cache,n=e.length,r=vU(i,n);_U(s,r)||(t.uniform1iv(this.addr,r),gU(s,r));for(let t=0;t!==n;++t)i.setTextureCube(e[t]||hU,r[t])}function iB(t,e,i){const s=this.cache,n=e.length,r=vU(i,n);_U(s,r)||(t.uniform1iv(this.addr,r),gU(s,r));for(let t=0;t!==n;++t)i.setTexture2DArray(e[t]||oU,r[t])}class sB{constructor(t,e,i){this.id=t,this.addr=i,this.cache=[],this.setValue=function(t){switch(t){case 5126:return SU;case 35664:return yU;case 35665:return xU;case 35666:return TU;case 35674:return EU;case 35675:return bU;case 35676:return wU;case 5124:case 35670:return AU;case 35667:case 35671:return CU;case 35668:case 35672:return MU;case 35669:case 35673:return PU;case 5125:return RU;case 36294:return LU;case 36295:return DU;case 36296:return IU;case 35678:case 36198:case 36298:case 36306:case 35682:return OU;case 35679:case 36299:case 36307:return NU;case 35680:case 36300:case 36308:case 36293:return FU;case 36289:case 36303:case 36311:case 36292:return UU}}(e.type)}}class nB{constructor(t,e,i){this.id=t,this.addr=i,this.cache=[],this.size=e.size,this.setValue=function(t){switch(t){case 5126:return BU;case 35664:return zU;case 35665:return kU;case 35666:return VU;case 35674:return HU;case 35675:return GU;case 35676:return WU;case 5124:case 35670:return XU;case 35667:case 35671:return YU;case 35668:case 35672:return qU;case 35669:case 35673:return jU;case 5125:return $U;case 36294:return KU;case 36295:return ZU;case 36296:return QU;case 35678:case 36198:case 36298:case 36306:case 35682:return JU;case 35679:case 36299:case 36307:return tB;case 35680:case 36300:case 36308:case 36293:return eB;case 36289:case 36303:case 36311:case 36292:return iB}}(e.type)}}class rB{constructor(t){this.id=t,this.seq=[],this.map={}}setValue(t,e,i){const s=this.seq;for(let n=0,r=s.length;n!==r;++n){const r=s[n];r.setValue(t,e[r.id],i)}}}const aB=/(\w+)(\])?(\[|\.)?/g;function oB(t,e){t.seq.push(e),t.map[e.id]=e}function lB(t,e,i){const s=t.name,n=s.length;for(aB.lastIndex=0;;){const r=aB.exec(s),a=aB.lastIndex;let o=r[1];const l="]"===r[2],h=r[3];if(l&&(o|=0),void 0===h||"["===h&&a+2===n){oB(i,void 0===h?new sB(o,t,e):new nB(o,t,e));break}{let t=i.map[o];void 0===t&&(t=new rB(o),oB(i,t)),i=t}}}class hB{constructor(t,e){this.seq=[],this.map={};const i=t.getProgramParameter(e,t.ACTIVE_UNIFORMS);for(let s=0;s<i;++s){const i=t.getActiveUniform(e,s);lB(i,t.getUniformLocation(e,i.name),this)}}setValue(t,e,i,s){const n=this.map[e];void 0!==n&&n.setValue(t,i,s)}setOptional(t,e,i){const s=e[i];void 0!==s&&this.setValue(t,i,s)}static upload(t,e,i,s){for(let n=0,r=e.length;n!==r;++n){const r=e[n],a=i[r.id];!1!==a.needsUpdate&&r.setValue(t,a.value,s)}}static seqWithValue(t,e){const i=[];for(let s=0,n=t.length;s!==n;++s){const n=t[s];n.id in e&&i.push(n)}return i}}function cB(t,e,i){const s=t.createShader(e);return t.shaderSource(s,i),t.compileShader(s),s}let dB=0;function uB(t,e,i){const s=t.getShaderParameter(e,t.COMPILE_STATUS),n=t.getShaderInfoLog(e).trim();if(s&&""===n)return"";const r=/ERROR: 0:(\d+)/.exec(n);if(r){const s=parseInt(r[1]);return i.toUpperCase()+"\n\n"+n+"\n\n"+function(t,e){const i=t.split("\n"),s=[],n=Math.max(e-6,0),r=Math.min(e+6,i.length);for(let t=n;t<r;t++){const n=t+1;s.push(`${n===e?">":" "} ${n}: ${i[t]}`)}return s.join("\n")}(t.getShaderSource(e),s)}return n}function fB(t,e){const i=function(t){const e=kI.getPrimaries(kI.workingColorSpace),i=kI.getPrimaries(t);let s;switch(e===i?s="":e===sI&&i===iI?s="LinearDisplayP3ToLinearSRGB":e===iI&&i===sI&&(s="LinearSRGBToLinearDisplayP3"),t){case ZD:case JD:return[s,"LinearTransferOETF"];case KD:case QD:return[s,"sRGBTransferOETF"];default:return[s,"LinearTransferOETF"]}}(e);return`vec4 ${t}( vec4 value ) { return ${i[0]}( ${i[1]}( value ) ); }`}function pB(t,e){let i;switch(e){case 1:default:i="Linear";break;case 2:i="Reinhard";break;case 3:i="OptimizedCineon";break;case 4:i="ACESFilmic";break;case 5:i="Custom"}return"vec3 "+t+"( vec3 color ) { return "+i+"ToneMapping( color ); }"}function mB(t){return""!==t}function _B(t,e){const i=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,i).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 gB(t,e){return t.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const vB=/^[ \t]*#include +<([\w\d./]+)>/gm;function SB(t){return t.replace(vB,xB)}const yB=new Map([["encodings_fragment","colorspace_fragment"],["encodings_pars_fragment","colorspace_pars_fragment"],["output_fragment","opaque_fragment"]]);function xB(t,e){let i=AF[e];if(void 0===i){const t=yB.get(e);if(void 0===t)throw new Error("Can not resolve #include <"+e+">");i=AF[t]}return SB(i)}const TB=/#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 EB(t){return t.replace(TB,bB)}function bB(t,e,i,s){let n="";for(let t=parseInt(e);t<parseInt(i);t++)n+=s.replace(/\[\s*i\s*\]/g,"[ "+t+" ]").replace(/UNROLLED_LOOP_INDEX/g,t);return n}function wB(t){let e="precision "+t.precision+" float;\nprecision "+t.precision+" int;";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 AB(t,e,i,s){const n=t.getContext(),r=i.defines;let a=i.vertexShader,o=i.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}(i),h=function(t){let e="ENVMAP_TYPE_CUBE";if(t.envMap)switch(t.envMapMode){case xD:case TD:e="ENVMAP_TYPE_CUBE";break;case ED:e="ENVMAP_TYPE_CUBE_UV"}return e}(i),c=function(t){let e="ENVMAP_MODE_REFLECTION";t.envMap&&t.envMapMode===TD&&(e="ENVMAP_MODE_REFRACTION");return e}(i),d=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}(i),u=function(t){const e=t.envMapCubeUVHeight;if(null===e)return null;const i=Math.log2(e)-2,s=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,i),112)),texelHeight:s,maxMip:i}}(i),f=i.isWebGL2?"":function(t){return[t.extensionDerivatives||t.envMapCubeUVHeight||t.bumpMap||t.normalMapTangentSpace||t.clearcoatNormalMap||t.flatShading||"physical"===t.shaderID?"#extension GL_OES_standard_derivatives : enable":"",(t.extensionFragDepth||t.logarithmicDepthBuffer)&&t.rendererExtensionFragDepth?"#extension GL_EXT_frag_depth : enable":"",t.extensionDrawBuffers&&t.rendererExtensionDrawBuffers?"#extension GL_EXT_draw_buffers : require":"",(t.extensionShaderTextureLOD||t.envMap||t.transmission)&&t.rendererExtensionShaderTextureLod?"#extension GL_EXT_shader_texture_lod : enable":""].filter(mB).join("\n")}(i),p=function(t){const e=[];for(const i in t){const s=t[i];!1!==s&&e.push("#define "+i+" "+s)}return e.join("\n")}(r),m=n.createProgram();let _,g,v=i.glslVersion?"#version "+i.glslVersion+"\n":"";i.isRawShaderMaterial?(_=["#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,p].filter(mB).join("\n"),_.length>0&&(_+="\n"),g=[f,"#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,p].filter(mB).join("\n"),g.length>0&&(g+="\n")):(_=[wB(i),"#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,p,i.instancing?"#define USE_INSTANCING":"",i.instancingColor?"#define USE_INSTANCING_COLOR":"",i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+c:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",i.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",i.displacementMap?"#define USE_DISPLACEMENTMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.anisotropy?"#define USE_ANISOTROPY":"",i.anisotropyMap?"#define USE_ANISOTROPYMAP":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",i.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",i.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.alphaHash?"#define USE_ALPHAHASH":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",i.mapUv?"#define MAP_UV "+i.mapUv:"",i.alphaMapUv?"#define ALPHAMAP_UV "+i.alphaMapUv:"",i.lightMapUv?"#define LIGHTMAP_UV "+i.lightMapUv:"",i.aoMapUv?"#define AOMAP_UV "+i.aoMapUv:"",i.emissiveMapUv?"#define EMISSIVEMAP_UV "+i.emissiveMapUv:"",i.bumpMapUv?"#define BUMPMAP_UV "+i.bumpMapUv:"",i.normalMapUv?"#define NORMALMAP_UV "+i.normalMapUv:"",i.displacementMapUv?"#define DISPLACEMENTMAP_UV "+i.displacementMapUv:"",i.metalnessMapUv?"#define METALNESSMAP_UV "+i.metalnessMapUv:"",i.roughnessMapUv?"#define ROUGHNESSMAP_UV "+i.roughnessMapUv:"",i.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+i.anisotropyMapUv:"",i.clearcoatMapUv?"#define CLEARCOATMAP_UV "+i.clearcoatMapUv:"",i.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+i.clearcoatNormalMapUv:"",i.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+i.clearcoatRoughnessMapUv:"",i.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+i.iridescenceMapUv:"",i.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+i.iridescenceThicknessMapUv:"",i.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+i.sheenColorMapUv:"",i.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+i.sheenRoughnessMapUv:"",i.specularMapUv?"#define SPECULARMAP_UV "+i.specularMapUv:"",i.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+i.specularColorMapUv:"",i.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+i.specularIntensityMapUv:"",i.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+i.transmissionMapUv:"",i.thicknessMapUv?"#define THICKNESSMAP_UV "+i.thicknessMapUv:"",i.vertexTangents&&!1===i.flatShading?"#define USE_TANGENT":"",i.vertexColors?"#define USE_COLOR":"",i.vertexAlphas?"#define USE_COLOR_ALPHA":"",i.vertexUv1s?"#define USE_UV1":"",i.vertexUv2s?"#define USE_UV2":"",i.vertexUv3s?"#define USE_UV3":"",i.pointsUvs?"#define USE_POINTS_UV":"",i.flatShading?"#define FLAT_SHADED":"",i.skinning?"#define USE_SKINNING":"",i.morphTargets?"#define USE_MORPHTARGETS":"",i.morphNormals&&!1===i.flatShading?"#define USE_MORPHNORMALS":"",i.morphColors&&i.isWebGL2?"#define USE_MORPHCOLORS":"",i.morphTargetsCount>0&&i.isWebGL2?"#define MORPHTARGETS_TEXTURE":"",i.morphTargetsCount>0&&i.isWebGL2?"#define MORPHTARGETS_TEXTURE_STRIDE "+i.morphTextureStride:"",i.morphTargetsCount>0&&i.isWebGL2?"#define MORPHTARGETS_COUNT "+i.morphTargetsCount:"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.sizeAttenuation?"#define USE_SIZEATTENUATION":"",i.numLightProbes>0?"#define USE_LIGHT_PROBES":"",i.useLegacyLights?"#define LEGACY_LIGHTS":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&i.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","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","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","#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )","\tattribute vec3 morphTarget0;","\tattribute vec3 morphTarget1;","\tattribute vec3 morphTarget2;","\tattribute vec3 morphTarget3;","\t#ifdef USE_MORPHNORMALS","\t\tattribute vec3 morphNormal0;","\t\tattribute vec3 morphNormal1;","\t\tattribute vec3 morphNormal2;","\t\tattribute vec3 morphNormal3;","\t#else","\t\tattribute vec3 morphTarget4;","\t\tattribute vec3 morphTarget5;","\t\tattribute vec3 morphTarget6;","\t\tattribute vec3 morphTarget7;","\t#endif","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(mB).join("\n"),g=[f,wB(i),"#define SHADER_TYPE "+i.shaderType,"#define SHADER_NAME "+i.shaderName,p,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.matcap?"#define USE_MATCAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+h:"",i.envMap?"#define "+c:"",i.envMap?"#define "+d:"",u?"#define CUBEUV_TEXEL_WIDTH "+u.texelWidth:"",u?"#define CUBEUV_TEXEL_HEIGHT "+u.texelHeight:"",u?"#define CUBEUV_MAX_MIP "+u.maxMip+".0":"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",i.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.anisotropy?"#define USE_ANISOTROPY":"",i.anisotropyMap?"#define USE_ANISOTROPYMAP":"",i.clearcoat?"#define USE_CLEARCOAT":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.iridescence?"#define USE_IRIDESCENCE":"",i.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",i.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",i.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.alphaTest?"#define USE_ALPHATEST":"",i.alphaHash?"#define USE_ALPHAHASH":"",i.sheen?"#define USE_SHEEN":"",i.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.vertexTangents&&!1===i.flatShading?"#define USE_TANGENT":"",i.vertexColors||i.instancingColor?"#define USE_COLOR":"",i.vertexAlphas?"#define USE_COLOR_ALPHA":"",i.vertexUv1s?"#define USE_UV1":"",i.vertexUv2s?"#define USE_UV2":"",i.vertexUv3s?"#define USE_UV3":"",i.pointsUvs?"#define USE_POINTS_UV":"",i.gradientMap?"#define USE_GRADIENTMAP":"",i.flatShading?"#define FLAT_SHADED":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",i.numLightProbes>0?"#define USE_LIGHT_PROBES":"",i.useLegacyLights?"#define LEGACY_LIGHTS":"",i.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&i.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",0!==i.toneMapping?"#define TONE_MAPPING":"",0!==i.toneMapping?AF.tonemapping_pars_fragment:"",0!==i.toneMapping?pB("toneMapping",i.toneMapping):"",i.dithering?"#define DITHERING":"",i.opaque?"#define OPAQUE":"",AF.colorspace_pars_fragment,fB("linearToOutputTexel",i.outputColorSpace),i.useDepthPacking?"#define DEPTH_PACKING "+i.depthPacking:"","\n"].filter(mB).join("\n")),a=SB(a),a=_B(a,i),a=gB(a,i),o=SB(o),o=_B(o,i),o=gB(o,i),a=EB(a),o=EB(o),i.isWebGL2&&!0!==i.isRawShaderMaterial&&(v="#version 300 es\n",_=["precision mediump sampler2DArray;","#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+_,g=["#define varying in",i.glslVersion===fI?"":"layout(location = 0) out highp vec4 pc_fragColor;",i.glslVersion===fI?"":"#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"+g);const S=v+_+a,y=v+g+o,x=cB(n,n.VERTEX_SHADER,S),T=cB(n,n.FRAGMENT_SHADER,y);if(n.attachShader(m,x),n.attachShader(m,T),void 0!==i.index0AttributeName?n.bindAttribLocation(m,0,i.index0AttributeName):!0===i.morphTargets&&n.bindAttribLocation(m,0,"position"),n.linkProgram(m),t.debug.checkShaderErrors){const e=n.getProgramInfoLog(m).trim(),i=n.getShaderInfoLog(x).trim(),s=n.getShaderInfoLog(T).trim();let r=!0,a=!0;if(!1===n.getProgramParameter(m,n.LINK_STATUS))if(r=!1,"function"==typeof t.debug.onShaderError)t.debug.onShaderError(n,m,x,T);else{uB(n,x,"vertex"),uB(n,T,"fragment")}else""!==e||""!==i&&""!==s||(a=!1);a&&(this.diagnostics={runnable:r,programLog:e,vertexShader:{log:i,prefix:_},fragmentShader:{log:s,prefix:g}})}let E,b;return n.deleteShader(x),n.deleteShader(T),this.getUniforms=function(){return void 0===E&&(E=new hB(n,m)),E},this.getAttributes=function(){return void 0===b&&(b=function(t,e){const i={},s=t.getProgramParameter(e,t.ACTIVE_ATTRIBUTES);for(let n=0;n<s;n++){const s=t.getActiveAttrib(e,n),r=s.name;let a=1;s.type===t.FLOAT_MAT2&&(a=2),s.type===t.FLOAT_MAT3&&(a=3),s.type===t.FLOAT_MAT4&&(a=4),i[r]={type:s.type,location:t.getAttribLocation(e,r),locationSize:a}}return i}(n,m)),b},this.destroy=function(){s.releaseStatesOfProgram(this),n.deleteProgram(m),this.program=void 0},this.type=i.shaderType,this.name=i.shaderName,this.id=dB++,this.cacheKey=e,this.usedTimes=1,this.program=m,this.vertexShader=x,this.fragmentShader=T,this}let CB=0;class MB{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,i=t.fragmentShader,s=this._getShaderStage(e),n=this._getShaderStage(i),r=this._getShaderCacheForMaterial(t);return!1===r.has(s)&&(r.add(s),s.usedTimes++),!1===r.has(n)&&(r.add(n),n.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 i=e.get(t);return void 0===i&&(i=new Set,e.set(t,i)),i}_getShaderStage(t){const e=this.shaderCache;let i=e.get(t);return void 0===i&&(i=new PB(t),e.set(t,i)),i}}class PB{constructor(t){this.id=CB++,this.code=t,this.usedTimes=0}}function RB(t,e,i,s,n,r,a){const o=new GO,l=new MB,h=[],c=n.isWebGL2,d=n.logarithmicDepthBuffer,u=n.vertexTextures;let f=n.precision;const p={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 0===t?"uv":`uv${t}`}return{getParameters:function(r,o,h,_,g){const v=_.fog,S=g.geometry,y=r.isMeshStandardMaterial?_.environment:null,x=(r.isMeshStandardMaterial?i:e).get(r.envMap||y),T=x&&x.mapping===ED?x.image.height:null,E=p[r.type];null!==r.precision&&(f=n.getMaxPrecision(r.precision),r.precision);const b=S.morphAttributes.position||S.morphAttributes.normal||S.morphAttributes.color,w=void 0!==b?b.length:0;let A,C,M,P,R=0;if(void 0!==S.morphAttributes.position&&(R=1),void 0!==S.morphAttributes.normal&&(R=2),void 0!==S.morphAttributes.color&&(R=3),E){const t=MF[E];A=t.vertexShader,C=t.fragmentShader}else A=r.vertexShader,C=r.fragmentShader,l.update(r),M=l.getVertexShaderID(r),P=l.getFragmentShaderID(r);const L=t.getRenderTarget(),D=!0===g.isInstancedMesh,I=!!r.map,O=!!r.matcap,N=!!x,F=!!r.aoMap,U=!!r.lightMap,B=!!r.bumpMap,z=!!r.normalMap,k=!!r.displacementMap,V=!!r.emissiveMap,H=!!r.metalnessMap,G=!!r.roughnessMap,W=r.anisotropy>0,X=r.clearcoat>0,Y=r.iridescence>0,q=r.sheen>0,j=r.transmission>0,$=W&&!!r.anisotropyMap,K=X&&!!r.clearcoatMap,Z=X&&!!r.clearcoatNormalMap,Q=X&&!!r.clearcoatRoughnessMap,J=Y&&!!r.iridescenceMap,tt=Y&&!!r.iridescenceThicknessMap,et=q&&!!r.sheenColorMap,it=q&&!!r.sheenRoughnessMap,st=!!r.specularMap,nt=!!r.specularColorMap,rt=!!r.specularIntensityMap,at=j&&!!r.transmissionMap,ot=j&&!!r.thicknessMap,lt=!!r.gradientMap,ht=!!r.alphaMap,ct=r.alphaTest>0,dt=!!r.alphaHash,ut=!!r.extensions,ft=!!S.attributes.uv1,pt=!!S.attributes.uv2,mt=!!S.attributes.uv3;let _t=0;return r.toneMapped&&(null!==L&&!0!==L.isXRRenderTarget||(_t=t.toneMapping)),{isWebGL2:c,shaderID:E,shaderType:r.type,shaderName:r.name,vertexShader:A,fragmentShader:C,defines:r.defines,customVertexShaderID:M,customFragmentShaderID:P,isRawShaderMaterial:!0===r.isRawShaderMaterial,glslVersion:r.glslVersion,precision:f,instancing:D,instancingColor:D&&null!==g.instanceColor,supportsVertexTextures:u,outputColorSpace:null===L?t.outputColorSpace:!0===L.isXRRenderTarget?L.texture.colorSpace:ZD,map:I,matcap:O,envMap:N,envMapMode:N&&x.mapping,envMapCubeUVHeight:T,aoMap:F,lightMap:U,bumpMap:B,normalMap:z,displacementMap:u&&k,emissiveMap:V,normalMapObjectSpace:z&&1===r.normalMapType,normalMapTangentSpace:z&&0===r.normalMapType,metalnessMap:H,roughnessMap:G,anisotropy:W,anisotropyMap:$,clearcoat:X,clearcoatMap:K,clearcoatNormalMap:Z,clearcoatRoughnessMap:Q,iridescence:Y,iridescenceMap:J,iridescenceThicknessMap:tt,sheen:q,sheenColorMap:et,sheenRoughnessMap:it,specularMap:st,specularColorMap:nt,specularIntensityMap:rt,transmission:j,transmissionMap:at,thicknessMap:ot,gradientMap:lt,opaque:!1===r.transparent&&1===r.blending,alphaMap:ht,alphaTest:ct,alphaHash:dt,combine:r.combine,mapUv:I&&m(r.map.channel),aoMapUv:F&&m(r.aoMap.channel),lightMapUv:U&&m(r.lightMap.channel),bumpMapUv:B&&m(r.bumpMap.channel),normalMapUv:z&&m(r.normalMap.channel),displacementMapUv:k&&m(r.displacementMap.channel),emissiveMapUv:V&&m(r.emissiveMap.channel),metalnessMapUv:H&&m(r.metalnessMap.channel),roughnessMapUv:G&&m(r.roughnessMap.channel),anisotropyMapUv:$&&m(r.anisotropyMap.channel),clearcoatMapUv:K&&m(r.clearcoatMap.channel),clearcoatNormalMapUv:Z&&m(r.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:Q&&m(r.clearcoatRoughnessMap.channel),iridescenceMapUv:J&&m(r.iridescenceMap.channel),iridescenceThicknessMapUv:tt&&m(r.iridescenceThicknessMap.channel),sheenColorMapUv:et&&m(r.sheenColorMap.channel),sheenRoughnessMapUv:it&&m(r.sheenRoughnessMap.channel),specularMapUv:st&&m(r.specularMap.channel),specularColorMapUv:nt&&m(r.specularColorMap.channel),specularIntensityMapUv:rt&&m(r.specularIntensityMap.channel),transmissionMapUv:at&&m(r.transmissionMap.channel),thicknessMapUv:ot&&m(r.thicknessMap.channel),alphaMapUv:ht&&m(r.alphaMap.channel),vertexTangents:!!S.attributes.tangent&&(z||W),vertexColors:r.vertexColors,vertexAlphas:!0===r.vertexColors&&!!S.attributes.color&&4===S.attributes.color.itemSize,vertexUv1s:ft,vertexUv2s:pt,vertexUv3s:mt,pointsUvs:!0===g.isPoints&&!!S.attributes.uv&&(I||ht),fog:!!v,useFog:!0===r.fog,fogExp2:v&&v.isFogExp2,flatShading:!0===r.flatShading,sizeAttenuation:!0===r.sizeAttenuation,logarithmicDepthBuffer:d,skinning:!0===g.isSkinnedMesh,morphTargets:void 0!==S.morphAttributes.position,morphNormals:void 0!==S.morphAttributes.normal,morphColors:void 0!==S.morphAttributes.color,morphTargetsCount:w,morphTextureStride:R,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:r.dithering,shadowMapEnabled:t.shadowMap.enabled&&h.length>0,shadowMapType:t.shadowMap.type,toneMapping:_t,useLegacyLights:t._useLegacyLights,decodeVideoTexture:I&&!0===r.map.isVideoTexture&&kI.getTransfer(r.map.colorSpace)===eI,premultipliedAlpha:r.premultipliedAlpha,doubleSided:2===r.side,flipSided:1===r.side,useDepthPacking:r.depthPacking>=0,depthPacking:r.depthPacking||0,index0AttributeName:r.index0AttributeName,extensionDerivatives:ut&&!0===r.extensions.derivatives,extensionFragDepth:ut&&!0===r.extensions.fragDepth,extensionDrawBuffers:ut&&!0===r.extensions.drawBuffers,extensionShaderTextureLOD:ut&&!0===r.extensions.shaderTextureLOD,rendererExtensionFragDepth:c||s.has("EXT_frag_depth"),rendererExtensionDrawBuffers:c||s.has("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:c||s.has("EXT_shader_texture_lod"),customProgramCacheKey:r.customProgramCacheKey()}},getProgramCacheKey:function(e){const i=[];if(e.shaderID?i.push(e.shaderID):(i.push(e.customVertexShaderID),i.push(e.customFragmentShaderID)),void 0!==e.defines)for(const t in e.defines)i.push(t),i.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)}(i,e),function(t,e){o.disableAll(),e.isWebGL2&&o.enable(0);e.supportsVertexTextures&&o.enable(1);e.instancing&&o.enable(2);e.instancingColor&&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);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.skinning&&o.enable(4);e.morphTargets&&o.enable(5);e.morphNormals&&o.enable(6);e.morphColors&&o.enable(7);e.premultipliedAlpha&&o.enable(8);e.shadowMapEnabled&&o.enable(9);e.useLegacyLights&&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);t.push(o.mask)}(i,e),i.push(t.outputColorSpace)),i.push(e.customProgramCacheKey),i.join()},getUniforms:function(t){const e=p[t.type];let i;if(e){const t=MF[e];i=lF.clone(t.uniforms)}else i=t.uniforms;return i},acquireProgram:function(e,i){let s;for(let t=0,e=h.length;t<e;t++){const e=h[t];if(e.cacheKey===i){s=e,++s.usedTimes;break}}return void 0===s&&(s=new AB(t,i,e,r),h.push(s)),s},releaseProgram:function(t){if(0===--t.usedTimes){const e=h.indexOf(t);h[e]=h[h.length-1],h.pop(),t.destroy()}},releaseShaderCache:function(t){l.remove(t)},programs:h,dispose:function(){l.dispose()}}}function LB(){let t=new WeakMap;return{get:function(e){let i=t.get(e);return void 0===i&&(i={},t.set(e,i)),i},remove:function(e){t.delete(e)},update:function(e,i,s){t.get(e)[i]=s},dispose:function(){t=new WeakMap}}}function DB(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 IB(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 OB(){const t=[];let e=0;const i=[],s=[],n=[];function r(i,s,n,r,a,o){let l=t[e];return void 0===l?(l={id:i.id,object:i,geometry:s,material:n,groupOrder:r,renderOrder:i.renderOrder,z:a,group:o},t[e]=l):(l.id=i.id,l.object=i,l.geometry=s,l.material=n,l.groupOrder=r,l.renderOrder=i.renderOrder,l.z=a,l.group=o),e++,l}return{opaque:i,transmissive:s,transparent:n,init:function(){e=0,i.length=0,s.length=0,n.length=0},push:function(t,e,a,o,l,h){const c=r(t,e,a,o,l,h);a.transmission>0?s.push(c):!0===a.transparent?n.push(c):i.push(c)},unshift:function(t,e,a,o,l,h){const c=r(t,e,a,o,l,h);a.transmission>0?s.unshift(c):!0===a.transparent?n.unshift(c):i.unshift(c)},finish:function(){for(let i=e,s=t.length;i<s;i++){const e=t[i];if(null===e.id)break;e.id=null,e.object=null,e.geometry=null,e.material=null,e.group=null}},sort:function(t,e){i.length>1&&i.sort(t||DB),s.length>1&&s.sort(e||IB),n.length>1&&n.sort(e||IB)}}}function NB(){let t=new WeakMap;return{get:function(e,i){const s=t.get(e);let n;return void 0===s?(n=new OB,t.set(e,[n])):i>=s.length?(n=new OB,s.push(n)):n=s[i],n},dispose:function(){t=new WeakMap}}}function FB(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":i={direction:new iO,color:new TN};break;case"SpotLight":i={position:new iO,direction:new iO,color:new TN,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":i={position:new iO,color:new TN,distance:0,decay:0};break;case"HemisphereLight":i={direction:new iO,skyColor:new TN,groundColor:new TN};break;case"RectAreaLight":i={color:new TN,position:new iO,halfWidth:new iO,halfHeight:new iO}}return t[e.id]=i,i}}}let UB=0;function BB(t,e){return(e.castShadow?2:0)-(t.castShadow?2:0)+(e.map?1:0)-(t.map?1:0)}function zB(t,e){const i=new FB,s=function(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":case"SpotLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new MI};break;case"PointLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new MI,shadowCameraNear:1,shadowCameraFar:1e3}}return t[e.id]=i,i}}}(),n={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++)n.probe.push(new iO);const r=new iO,a=new DO,o=new DO;return{setup:function(r,a){let o=0,l=0,h=0;for(let t=0;t<9;t++)n.probe[t].set(0,0,0);let c=0,d=0,u=0,f=0,p=0,m=0,_=0,g=0,v=0,S=0,y=0;r.sort(BB);const x=!0===a?Math.PI:1;for(let t=0,e=r.length;t<e;t++){const e=r[t],a=e.color,T=e.intensity,E=e.distance,b=e.shadow&&e.shadow.map?e.shadow.map.texture:null;if(e.isAmbientLight)o+=a.r*T*x,l+=a.g*T*x,h+=a.b*T*x;else if(e.isLightProbe){for(let t=0;t<9;t++)n.probe[t].addScaledVector(e.sh.coefficients[t],T);y++}else if(e.isDirectionalLight){const t=i.get(e);if(t.color.copy(e.color).multiplyScalar(e.intensity*x),e.castShadow){const t=e.shadow,i=s.get(e);i.shadowBias=t.bias,i.shadowNormalBias=t.normalBias,i.shadowRadius=t.radius,i.shadowMapSize=t.mapSize,n.directionalShadow[c]=i,n.directionalShadowMap[c]=b,n.directionalShadowMatrix[c]=e.shadow.matrix,m++}n.directional[c]=t,c++}else if(e.isSpotLight){const t=i.get(e);t.position.setFromMatrixPosition(e.matrixWorld),t.color.copy(a).multiplyScalar(T*x),t.distance=E,t.coneCos=Math.cos(e.angle),t.penumbraCos=Math.cos(e.angle*(1-e.penumbra)),t.decay=e.decay,n.spot[u]=t;const r=e.shadow;if(e.map&&(n.spotLightMap[v]=e.map,v++,r.updateMatrices(e),e.castShadow&&S++),n.spotLightMatrix[u]=r.matrix,e.castShadow){const t=s.get(e);t.shadowBias=r.bias,t.shadowNormalBias=r.normalBias,t.shadowRadius=r.radius,t.shadowMapSize=r.mapSize,n.spotShadow[u]=t,n.spotShadowMap[u]=b,g++}u++}else if(e.isRectAreaLight){const t=i.get(e);t.color.copy(a).multiplyScalar(T),t.halfWidth.set(.5*e.width,0,0),t.halfHeight.set(0,.5*e.height,0),n.rectArea[f]=t,f++}else if(e.isPointLight){const t=i.get(e);if(t.color.copy(e.color).multiplyScalar(e.intensity*x),t.distance=e.distance,t.decay=e.decay,e.castShadow){const t=e.shadow,i=s.get(e);i.shadowBias=t.bias,i.shadowNormalBias=t.normalBias,i.shadowRadius=t.radius,i.shadowMapSize=t.mapSize,i.shadowCameraNear=t.camera.near,i.shadowCameraFar=t.camera.far,n.pointShadow[d]=i,n.pointShadowMap[d]=b,n.pointShadowMatrix[d]=e.shadow.matrix,_++}n.point[d]=t,d++}else if(e.isHemisphereLight){const t=i.get(e);t.skyColor.copy(e.color).multiplyScalar(T*x),t.groundColor.copy(e.groundColor).multiplyScalar(T*x),n.hemi[p]=t,p++}}f>0&&(e.isWebGL2||!0===t.has("OES_texture_float_linear")?(n.rectAreaLTC1=CF.LTC_FLOAT_1,n.rectAreaLTC2=CF.LTC_FLOAT_2):!0===t.has("OES_texture_half_float_linear")&&(n.rectAreaLTC1=CF.LTC_HALF_1,n.rectAreaLTC2=CF.LTC_HALF_2)),n.ambient[0]=o,n.ambient[1]=l,n.ambient[2]=h;const T=n.hash;T.directionalLength===c&&T.pointLength===d&&T.spotLength===u&&T.rectAreaLength===f&&T.hemiLength===p&&T.numDirectionalShadows===m&&T.numPointShadows===_&&T.numSpotShadows===g&&T.numSpotMaps===v&&T.numLightProbes===y||(n.directional.length=c,n.spot.length=u,n.rectArea.length=f,n.point.length=d,n.hemi.length=p,n.directionalShadow.length=m,n.directionalShadowMap.length=m,n.pointShadow.length=_,n.pointShadowMap.length=_,n.spotShadow.length=g,n.spotShadowMap.length=g,n.directionalShadowMatrix.length=m,n.pointShadowMatrix.length=_,n.spotLightMatrix.length=g+v-S,n.spotLightMap.length=v,n.numSpotLightShadowsWithMaps=S,n.numLightProbes=y,T.directionalLength=c,T.pointLength=d,T.spotLength=u,T.rectAreaLength=f,T.hemiLength=p,T.numDirectionalShadows=m,T.numPointShadows=_,T.numSpotShadows=g,T.numSpotMaps=v,T.numLightProbes=y,n.version=UB++)},setupView:function(t,e){let i=0,s=0,l=0,h=0,c=0;const d=e.matrixWorldInverse;for(let e=0,u=t.length;e<u;e++){const u=t[e];if(u.isDirectionalLight){const t=n.directional[i];t.direction.setFromMatrixPosition(u.matrixWorld),r.setFromMatrixPosition(u.target.matrixWorld),t.direction.sub(r),t.direction.transformDirection(d),i++}else if(u.isSpotLight){const t=n.spot[l];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),t.direction.setFromMatrixPosition(u.matrixWorld),r.setFromMatrixPosition(u.target.matrixWorld),t.direction.sub(r),t.direction.transformDirection(d),l++}else if(u.isRectAreaLight){const t=n.rectArea[h];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),o.identity(),a.copy(u.matrixWorld),a.premultiply(d),o.extractRotation(a),t.halfWidth.set(.5*u.width,0,0),t.halfHeight.set(0,.5*u.height,0),t.halfWidth.applyMatrix4(o),t.halfHeight.applyMatrix4(o),h++}else if(u.isPointLight){const t=n.point[s];t.position.setFromMatrixPosition(u.matrixWorld),t.position.applyMatrix4(d),s++}else if(u.isHemisphereLight){const t=n.hemi[c];t.direction.setFromMatrixPosition(u.matrixWorld),t.direction.transformDirection(d),c++}}},state:n}}function kB(t,e){const i=new zB(t,e),s=[],n=[];return{init:function(){s.length=0,n.length=0},state:{lightsArray:s,shadowsArray:n,lights:i},setupLights:function(t){i.setup(s,t)},setupLightsView:function(t){i.setupView(s,t)},pushLight:function(t){s.push(t)},pushShadow:function(t){n.push(t)}}}function VB(t,e){let i=new WeakMap;return{get:function(s,n=0){const r=i.get(s);let a;return void 0===r?(a=new kB(t,e),i.set(s,[a])):n>=r.length?(a=new kB(t,e),r.push(a)):a=r[n],a},dispose:function(){i=new WeakMap}}}class HB extends gN{constructor(t){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}class GB extends gN{constructor(t){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(t)}copy(t){return super.copy(t),this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}function WB(t,e,i){let s=new TF;const n=new MI,r=new MI,a=new KI,o=new HB({depthPacking:3201}),l=new GB,h={},c=i.maxTextureSize,d={[nD]:1,[rD]:0,[aD]:2},u=new hF({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new MI},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}"}),f=u.clone();f.defines.HORIZONTAL_PASS=1;const p=new BN;p.setAttribute("position",new CN(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const m=new iF(p,u),_=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let g=this.type;function v(i,s){const r=e.update(m);u.defines.VSM_SAMPLES!==i.blurSamples&&(u.defines.VSM_SAMPLES=i.blurSamples,f.defines.VSM_SAMPLES=i.blurSamples,u.needsUpdate=!0,f.needsUpdate=!0),null===i.mapPass&&(i.mapPass=new QI(n.x,n.y)),u.uniforms.shadow_pass.value=i.map.texture,u.uniforms.resolution.value=i.mapSize,u.uniforms.radius.value=i.radius,t.setRenderTarget(i.mapPass),t.clear(),t.renderBufferDirect(s,null,r,u,m,null),f.uniforms.shadow_pass.value=i.mapPass.texture,f.uniforms.resolution.value=i.mapSize,f.uniforms.radius.value=i.radius,t.setRenderTarget(i.map),t.clear(),t.renderBufferDirect(s,null,r,f,m,null)}function S(e,i,s,n){let r=null;const a=!0===s.isPointLight?e.customDistanceMaterial:e.customDepthMaterial;if(void 0!==a)r=a;else if(r=!0===s.isPointLight?l:o,t.localClippingEnabled&&!0===i.clipShadows&&Array.isArray(i.clippingPlanes)&&0!==i.clippingPlanes.length||i.displacementMap&&0!==i.displacementScale||i.alphaMap&&i.alphaTest>0||i.map&&i.alphaTest>0){const t=r.uuid,e=i.uuid;let s=h[t];void 0===s&&(s={},h[t]=s);let n=s[e];void 0===n&&(n=r.clone(),s[e]=n),r=n}if(r.visible=i.visible,r.wireframe=i.wireframe,r.side=3===n?null!==i.shadowSide?i.shadowSide:i.side:null!==i.shadowSide?i.shadowSide:d[i.side],r.alphaMap=i.alphaMap,r.alphaTest=i.alphaTest,r.map=i.map,r.clipShadows=i.clipShadows,r.clippingPlanes=i.clippingPlanes,r.clipIntersection=i.clipIntersection,r.displacementMap=i.displacementMap,r.displacementScale=i.displacementScale,r.displacementBias=i.displacementBias,r.wireframeLinewidth=i.wireframeLinewidth,r.linewidth=i.linewidth,!0===s.isPointLight&&!0===r.isMeshDistanceMaterial){t.properties.get(r).light=s}return r}function y(i,n,r,a,o){if(!1===i.visible)return;if(i.layers.test(n.layers)&&(i.isMesh||i.isLine||i.isPoints)&&(i.castShadow||i.receiveShadow&&3===o)&&(!i.frustumCulled||s.intersectsObject(i))){i.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,i.matrixWorld);const s=e.update(i),n=i.material;if(Array.isArray(n)){const e=s.groups;for(let l=0,h=e.length;l<h;l++){const h=e[l],c=n[h.materialIndex];if(c&&c.visible){const e=S(i,c,a,o);t.renderBufferDirect(r,null,s,e,i,h)}}}else if(n.visible){const e=S(i,n,a,o);t.renderBufferDirect(r,null,s,e,i,null)}}const l=i.children;for(let t=0,e=l.length;t<e;t++)y(l[t],n,r,a,o)}this.render=function(e,i,o){if(!1===_.enabled)return;if(!1===_.autoUpdate&&!1===_.needsUpdate)return;if(0===e.length)return;const l=t.getRenderTarget(),h=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),u=t.state;u.setBlending(0),u.buffers.color.setClear(1,1,1,1),u.buffers.depth.setTest(!0),u.setScissorTest(!1);const f=3!==g&&3===this.type,p=3===g&&3!==this.type;for(let l=0,h=e.length;l<h;l++){const h=e[l],d=h.shadow;if(void 0===d)continue;if(!1===d.autoUpdate&&!1===d.needsUpdate)continue;n.copy(d.mapSize);const m=d.getFrameExtents();if(n.multiply(m),r.copy(d.mapSize),(n.x>c||n.y>c)&&(n.x>c&&(r.x=Math.floor(c/m.x),n.x=r.x*m.x,d.mapSize.x=r.x),n.y>c&&(r.y=Math.floor(c/m.y),n.y=r.y*m.y,d.mapSize.y=r.y)),null===d.map||!0===f||!0===p){const t=3!==this.type?{minFilter:CD,magFilter:CD}:{};null!==d.map&&d.map.dispose(),d.map=new QI(n.x,n.y,t),d.map.texture.name=h.name+".shadowMap",d.camera.updateProjectionMatrix()}t.setRenderTarget(d.map),t.clear();const _=d.getViewportCount();for(let t=0;t<_;t++){const e=d.getViewport(t);a.set(r.x*e.x,r.y*e.y,r.x*e.z,r.y*e.w),u.viewport(a),d.updateMatrices(h,t),s=d.getFrustum(),y(i,o,d.camera,h,this.type)}!0!==d.isPointLightShadow&&3===this.type&&v(d,o),d.needsUpdate=!1}g=this.type,_.needsUpdate=!1,t.setRenderTarget(l,h,d)}}function XB(t,e,i){const s=i.isWebGL2;const n=new function(){let e=!1;const i=new KI;let s=null;const n=new KI(0,0,0,0);return{setMask:function(i){s===i||e||(t.colorMask(i,i,i,i),s=i)},setLocked:function(t){e=t},setClear:function(e,s,r,a,o){!0===o&&(e*=a,s*=a,r*=a),i.set(e,s,r,a),!1===n.equals(i)&&(t.clearColor(e,s,r,a),n.copy(i))},reset:function(){e=!1,s=null,n.set(-1,0,0,0)}}},r=new function(){let e=!1,i=null,s=null,n=null;return{setTest:function(e){e?k(t.DEPTH_TEST):V(t.DEPTH_TEST)},setMask:function(s){i===s||e||(t.depthMask(s),i=s)},setFunc:function(e){if(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){e=t},setClear:function(e){n!==e&&(t.clearDepth(e),n=e)},reset:function(){e=!1,i=null,s=null,n=null}}},a=new function(){let e=!1,i=null,s=null,n=null,r=null,a=null,o=null,l=null,h=null;return{setTest:function(i){e||(i?k(t.STENCIL_TEST):V(t.STENCIL_TEST))},setMask:function(s){i===s||e||(t.stencilMask(s),i=s)},setFunc:function(e,i,a){s===e&&n===i&&r===a||(t.stencilFunc(e,i,a),s=e,n=i,r=a)},setOp:function(e,i,s){a===e&&o===i&&l===s||(t.stencilOp(e,i,s),a=e,o=i,l=s)},setLocked:function(t){e=t},setClear:function(e){h!==e&&(t.clearStencil(e),h=e)},reset:function(){e=!1,i=null,s=null,n=null,r=null,a=null,o=null,l=null,h=null}}},o=new WeakMap,l=new WeakMap;let h={},c={},d=new WeakMap,u=[],f=null,p=!1,m=null,_=null,g=null,v=null,S=null,y=null,x=null,T=!1,E=null,b=null,w=null,A=null,C=null;const M=t.getParameter(t.MAX_COMBINED_TEXTURE_IMAGE_UNITS);let P=!1,R=0;const L=t.getParameter(t.VERSION);-1!==L.indexOf("WebGL")?(R=parseFloat(/^WebGL (\d)/.exec(L)[1]),P=R>=1):-1!==L.indexOf("OpenGL ES")&&(R=parseFloat(/^OpenGL ES (\d)/.exec(L)[1]),P=R>=2);let D=null,I={};const O=t.getParameter(t.SCISSOR_BOX),N=t.getParameter(t.VIEWPORT),F=(new KI).fromArray(O),U=(new KI).fromArray(N);function B(e,i,n,r){const a=new Uint8Array(4),o=t.createTexture();t.bindTexture(e,o),t.texParameteri(e,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(e,t.TEXTURE_MAG_FILTER,t.NEAREST);for(let o=0;o<n;o++)!s||e!==t.TEXTURE_3D&&e!==t.TEXTURE_2D_ARRAY?t.texImage2D(i+o,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,a):t.texImage3D(i,0,t.RGBA,1,1,r,0,t.RGBA,t.UNSIGNED_BYTE,a);return o}const z={};function k(e){!0!==h[e]&&(t.enable(e),h[e]=!0)}function V(e){!1!==h[e]&&(t.disable(e),h[e]=!1)}z[t.TEXTURE_2D]=B(t.TEXTURE_2D,t.TEXTURE_2D,1),z[t.TEXTURE_CUBE_MAP]=B(t.TEXTURE_CUBE_MAP,t.TEXTURE_CUBE_MAP_POSITIVE_X,6),s&&(z[t.TEXTURE_2D_ARRAY]=B(t.TEXTURE_2D_ARRAY,t.TEXTURE_2D_ARRAY,1,1),z[t.TEXTURE_3D]=B(t.TEXTURE_3D,t.TEXTURE_3D,1,1)),n.setClear(0,0,0,1),r.setClear(1),a.setClear(0),k(t.DEPTH_TEST),r.setFunc(3),X(!1),Y(1),k(t.CULL_FACE),W(0);const H={[oD]:t.FUNC_ADD,[lD]:t.FUNC_SUBTRACT,[hD]:t.FUNC_REVERSE_SUBTRACT};if(s)H[103]=t.MIN,H[104]=t.MAX;else{const t=e.get("EXT_blend_minmax");null!==t&&(H[103]=t.MIN_EXT,H[104]=t.MAX_EXT)}const G={[cD]:t.ZERO,[dD]:t.ONE,[uD]:t.SRC_COLOR,[pD]:t.SRC_ALPHA,[yD]:t.SRC_ALPHA_SATURATE,[vD]:t.DST_COLOR,[_D]:t.DST_ALPHA,[fD]:t.ONE_MINUS_SRC_COLOR,[mD]:t.ONE_MINUS_SRC_ALPHA,[SD]:t.ONE_MINUS_DST_COLOR,[gD]:t.ONE_MINUS_DST_ALPHA};function W(e,i,s,n,r,a,o,l){if(0!==e){if(!1===p&&(k(t.BLEND),p=!0),5===e)r=r||i,a=a||s,o=o||n,i===_&&r===S||(t.blendEquationSeparate(H[i],H[r]),_=i,S=r),s===g&&n===v&&a===y&&o===x||(t.blendFuncSeparate(G[s],G[n],G[a],G[o]),g=s,v=n,y=a,x=o),m=e,T=!1;else if(e!==m||l!==T){if(_===oD&&S===oD||(t.blendEquation(t.FUNC_ADD),_=oD,S=oD),l)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)}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)}g=null,v=null,y=null,x=null,m=e,T=l}}else!0===p&&(V(t.BLEND),p=!1)}function X(e){E!==e&&(e?t.frontFace(t.CW):t.frontFace(t.CCW),E=e)}function Y(e){0!==e?(k(t.CULL_FACE),e!==b&&(1===e?t.cullFace(t.BACK):2===e?t.cullFace(t.FRONT):t.cullFace(t.FRONT_AND_BACK))):V(t.CULL_FACE),b=e}function q(e,i,s){e?(k(t.POLYGON_OFFSET_FILL),A===i&&C===s||(t.polygonOffset(i,s),A=i,C=s)):V(t.POLYGON_OFFSET_FILL)}return{buffers:{color:n,depth:r,stencil:a},enable:k,disable:V,bindFramebuffer:function(e,i){return c[e]!==i&&(t.bindFramebuffer(e,i),c[e]=i,s&&(e===t.DRAW_FRAMEBUFFER&&(c[t.FRAMEBUFFER]=i),e===t.FRAMEBUFFER&&(c[t.DRAW_FRAMEBUFFER]=i)),!0)},drawBuffers:function(s,n){let r=u,a=!1;if(s)if(r=d.get(n),void 0===r&&(r=[],d.set(n,r)),s.isWebGLMultipleRenderTargets){const e=s.texture;if(r.length!==e.length||r[0]!==t.COLOR_ATTACHMENT0){for(let i=0,s=e.length;i<s;i++)r[i]=t.COLOR_ATTACHMENT0+i;r.length=e.length,a=!0}}else r[0]!==t.COLOR_ATTACHMENT0&&(r[0]=t.COLOR_ATTACHMENT0,a=!0);else r[0]!==t.BACK&&(r[0]=t.BACK,a=!0);a&&(i.isWebGL2?t.drawBuffers(r):e.get("WEBGL_draw_buffers").drawBuffersWEBGL(r))},useProgram:function(e){return f!==e&&(t.useProgram(e),f=e,!0)},setBlending:W,setMaterial:function(e,i){2===e.side?V(t.CULL_FACE):k(t.CULL_FACE);let s=1===e.side;i&&(s=!s),X(s),1===e.blending&&!1===e.transparent?W(0):W(e.blending,e.blendEquation,e.blendSrc,e.blendDst,e.blendEquationAlpha,e.blendSrcAlpha,e.blendDstAlpha,e.premultipliedAlpha),r.setFunc(e.depthFunc),r.setTest(e.depthTest),r.setMask(e.depthWrite),n.setMask(e.colorWrite);const o=e.stencilWrite;a.setTest(o),o&&(a.setMask(e.stencilWriteMask),a.setFunc(e.stencilFunc,e.stencilRef,e.stencilFuncMask),a.setOp(e.stencilFail,e.stencilZFail,e.stencilZPass)),q(e.polygonOffset,e.polygonOffsetFactor,e.polygonOffsetUnits),!0===e.alphaToCoverage?k(t.SAMPLE_ALPHA_TO_COVERAGE):V(t.SAMPLE_ALPHA_TO_COVERAGE)},setFlipSided:X,setCullFace:Y,setLineWidth:function(e){e!==w&&(P&&t.lineWidth(e),w=e)},setPolygonOffset:q,setScissorTest:function(e){e?k(t.SCISSOR_TEST):V(t.SCISSOR_TEST)},activeTexture:function(e){void 0===e&&(e=t.TEXTURE0+M-1),D!==e&&(t.activeTexture(e),D=e)},bindTexture:function(e,i,s){void 0===s&&(s=null===D?t.TEXTURE0+M-1:D);let n=I[s];void 0===n&&(n={type:void 0,texture:void 0},I[s]=n),n.type===e&&n.texture===i||(D!==s&&(t.activeTexture(s),D=s),t.bindTexture(e,i||z[e]),n.type=e,n.texture=i)},unbindTexture:function(){const e=I[D];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){}},compressedTexImage3D:function(){try{t.compressedTexImage3D.apply(t,arguments)}catch(t){}},texImage2D:function(){try{t.texImage2D.apply(t,arguments)}catch(t){}},texImage3D:function(){try{t.texImage3D.apply(t,arguments)}catch(t){}},updateUBOMapping:function(e,i){let s=l.get(i);void 0===s&&(s=new WeakMap,l.set(i,s));let n=s.get(e);void 0===n&&(n=t.getUniformBlockIndex(i,e.name),s.set(e,n))},uniformBlockBinding:function(e,i){const s=l.get(i).get(e);o.get(i)!==s&&(t.uniformBlockBinding(i,s,e.__bindingPointIndex),o.set(i,s))},texStorage2D:function(){try{t.texStorage2D.apply(t,arguments)}catch(t){}},texStorage3D:function(){try{t.texStorage3D.apply(t,arguments)}catch(t){}},texSubImage2D:function(){try{t.texSubImage2D.apply(t,arguments)}catch(t){}},texSubImage3D:function(){try{t.texSubImage3D.apply(t,arguments)}catch(t){}},compressedTexSubImage2D:function(){try{t.compressedTexSubImage2D.apply(t,arguments)}catch(t){}},compressedTexSubImage3D:function(){try{t.compressedTexSubImage3D.apply(t,arguments)}catch(t){}},scissor:function(e){!1===F.equals(e)&&(t.scissor(e.x,e.y,e.z,e.w),F.copy(e))},viewport:function(e){!1===U.equals(e)&&(t.viewport(e.x,e.y,e.z,e.w),U.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.colorMask(!0,!0,!0,!0),t.clearColor(0,0,0,0),t.depthMask(!0),t.depthFunc(t.LESS),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),!0===s&&(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),h={},D=null,I={},c={},d=new WeakMap,u=[],f=null,p=!1,m=null,_=null,g=null,v=null,S=null,y=null,x=null,T=!1,E=null,b=null,w=null,A=null,C=null,F.set(0,0,t.canvas.width,t.canvas.height),U.set(0,0,t.canvas.width,t.canvas.height),n.reset(),r.reset(),a.reset()}}}function YB(t,e,i,s,n,r,a){const o=n.isWebGL2,l=(n.maxTextures,n.maxCubemapSize),h=n.maxTextureSize,c=n.maxSamples,d=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,u="undefined"!=typeof navigator&&/OculusBrowser/g.test(navigator.userAgent),f=new WeakMap;let p;const m=new WeakMap;let _=!1;try{_="undefined"!=typeof OffscreenCanvas&&null!==new OffscreenCanvas(1,1).getContext("2d")}catch(t){}function g(t,e){return _?new OffscreenCanvas(t,e):DI("canvas")}function v(t,e,i,s){let n=1;if((t.width>s||t.height>s)&&(n=s/Math.max(t.width,t.height)),n<1||!0===e){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const s=e?wI:Math.floor,r=s(n*t.width),a=s(n*t.height);void 0===p&&(p=g(r,a));const o=i?g(r,a):p;o.width=r,o.height=a;return o.getContext("2d").drawImage(t,0,0,r,a),o}return t}return t}function S(t){return bI(t.width)&&bI(t.height)}function y(t,e){return t.generateMipmaps&&e&&t.minFilter!==CD&&t.minFilter!==RD}function x(e){t.generateMipmap(e)}function T(i,s,n,r,a=!1){if(!1===o)return s;if(null!==i&&void 0!==t[i])return t[i];let l=s;if(s===t.RED&&(n===t.FLOAT&&(l=t.R32F),n===t.HALF_FLOAT&&(l=t.R16F),n===t.UNSIGNED_BYTE&&(l=t.R8)),s===t.RED_INTEGER&&(n===t.UNSIGNED_BYTE&&(l=t.R8UI),n===t.UNSIGNED_SHORT&&(l=t.R16UI),n===t.UNSIGNED_INT&&(l=t.R32UI),n===t.BYTE&&(l=t.R8I),n===t.SHORT&&(l=t.R16I),n===t.INT&&(l=t.R32I)),s===t.RG&&(n===t.FLOAT&&(l=t.RG32F),n===t.HALF_FLOAT&&(l=t.RG16F),n===t.UNSIGNED_BYTE&&(l=t.RG8)),s===t.RGBA){const e=a?tI:kI.getTransfer(r);n===t.FLOAT&&(l=t.RGBA32F),n===t.HALF_FLOAT&&(l=t.RGBA16F),n===t.UNSIGNED_BYTE&&(l=e===eI?t.SRGB8_ALPHA8:t.RGBA8),n===t.UNSIGNED_SHORT_4_4_4_4&&(l=t.RGBA4),n===t.UNSIGNED_SHORT_5_5_5_1&&(l=t.RGB5_A1)}return l!==t.R16F&&l!==t.R32F&&l!==t.RG16F&&l!==t.RG32F&&l!==t.RGBA16F&&l!==t.RGBA32F||e.get("EXT_color_buffer_float"),l}function E(t,e,i){return!0===y(t,i)||t.isFramebufferTexture&&t.minFilter!==CD&&t.minFilter!==RD?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 b(e){return e===CD||1004===e||e===PD?t.NEAREST:t.LINEAR}function w(t){const e=t.target;e.removeEventListener("dispose",w),function(t){const e=s.get(t);if(void 0===e.__webglInit)return;const i=t.source,n=m.get(i);if(n){const s=n[e.__cacheKey];s.usedTimes--,0===s.usedTimes&&C(t),0===Object.keys(n).length&&m.delete(i)}s.remove(t)}(e),e.isVideoTexture&&f.delete(e)}function A(e){const i=e.target;i.removeEventListener("dispose",A),function(e){const i=e.texture,n=s.get(e),r=s.get(i);void 0!==r.__webglTexture&&(t.deleteTexture(r.__webglTexture),a.memory.textures--);e.depthTexture&&e.depthTexture.dispose();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)}if(e.isWebGLMultipleRenderTargets)for(let e=0,n=i.length;e<n;e++){const n=s.get(i[e]);n.__webglTexture&&(t.deleteTexture(n.__webglTexture),a.memory.textures--),s.remove(i[e])}s.remove(i),s.remove(e)}(i)}function C(e){const i=s.get(e);t.deleteTexture(i.__webglTexture);const n=e.source;delete m.get(n)[i.__cacheKey],a.memory.textures--}let M=0;function P(e,n){const r=s.get(e);if(e.isVideoTexture&&function(t){const e=a.render.frame;f.get(t)!==e&&(f.set(t,e),t.update())}(e),!1===e.isRenderTargetTexture&&e.version>0&&r.__version!==e.version){const t=e.image;if(null===t);else if(!1!==t.complete)return void N(r,e,n)}i.bindTexture(t.TEXTURE_2D,r.__webglTexture,t.TEXTURE0+n)}const R={[bD]:t.REPEAT,[wD]:t.CLAMP_TO_EDGE,[AD]:t.MIRRORED_REPEAT},L={[CD]:t.NEAREST,[MD]:t.NEAREST_MIPMAP_NEAREST,[PD]:t.NEAREST_MIPMAP_LINEAR,[RD]:t.LINEAR,[LD]:t.LINEAR_MIPMAP_NEAREST,[DD]:t.LINEAR_MIPMAP_LINEAR},D={[rI]:t.NEVER,[uI]:t.ALWAYS,[aI]:t.LESS,[lI]:t.LEQUAL,[oI]:t.EQUAL,[dI]:t.GEQUAL,[hI]:t.GREATER,[cI]:t.NOTEQUAL};function I(i,r,a){if(a?(t.texParameteri(i,t.TEXTURE_WRAP_S,R[r.wrapS]),t.texParameteri(i,t.TEXTURE_WRAP_T,R[r.wrapT]),i!==t.TEXTURE_3D&&i!==t.TEXTURE_2D_ARRAY||t.texParameteri(i,t.TEXTURE_WRAP_R,R[r.wrapR]),t.texParameteri(i,t.TEXTURE_MAG_FILTER,L[r.magFilter]),t.texParameteri(i,t.TEXTURE_MIN_FILTER,L[r.minFilter])):(t.texParameteri(i,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(i,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),i!==t.TEXTURE_3D&&i!==t.TEXTURE_2D_ARRAY||t.texParameteri(i,t.TEXTURE_WRAP_R,t.CLAMP_TO_EDGE),r.wrapS!==wD||r.wrapT,t.texParameteri(i,t.TEXTURE_MAG_FILTER,b(r.magFilter)),t.texParameteri(i,t.TEXTURE_MIN_FILTER,b(r.minFilter)),r.minFilter!==CD&&r.minFilter),r.compareFunction&&(t.texParameteri(i,t.TEXTURE_COMPARE_MODE,t.COMPARE_REF_TO_TEXTURE),t.texParameteri(i,t.TEXTURE_COMPARE_FUNC,D[r.compareFunction])),!0===e.has("EXT_texture_filter_anisotropic")){const a=e.get("EXT_texture_filter_anisotropic");if(r.magFilter===CD)return;if(r.minFilter!==PD&&r.minFilter!==DD)return;if(r.type===UD&&!1===e.has("OES_texture_float_linear"))return;if(!1===o&&r.type===BD&&!1===e.has("OES_texture_half_float_linear"))return;(r.anisotropy>1||s.get(r).__currentAnisotropy)&&(t.texParameterf(i,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(r.anisotropy,n.getMaxAnisotropy())),s.get(r).__currentAnisotropy=r.anisotropy)}}function O(e,i){let s=!1;void 0===e.__webglInit&&(e.__webglInit=!0,i.addEventListener("dispose",w));const n=i.source;let r=m.get(n);void 0===r&&(r={},m.set(n,r));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()}(i);if(o!==e.__cacheKey){void 0===r[o]&&(r[o]={texture:t.createTexture(),usedTimes:0},a.memory.textures++,s=!0),r[o].usedTimes++;const n=r[e.__cacheKey];void 0!==n&&(r[e.__cacheKey].usedTimes--,0===n.usedTimes&&C(i)),e.__cacheKey=o,e.__webglTexture=r[o].texture}return s}function N(e,n,a){let l=t.TEXTURE_2D;(n.isDataArrayTexture||n.isCompressedArrayTexture)&&(l=t.TEXTURE_2D_ARRAY),n.isData3DTexture&&(l=t.TEXTURE_3D);const c=O(e,n),d=n.source;i.bindTexture(l,e.__webglTexture,t.TEXTURE0+a);const u=s.get(d);if(d.version!==u.__version||!0===c){i.activeTexture(t.TEXTURE0+a);const e=kI.getPrimaries(kI.workingColorSpace),s=n.colorSpace===$D?null:kI.getPrimaries(n.colorSpace),f=n.colorSpace===$D||e===s?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,n.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,n.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,f);const p=function(t){return!o&&(t.wrapS!==wD||t.wrapT!==wD||t.minFilter!==CD&&t.minFilter!==RD)}(n)&&!1===S(n.image);let m=v(n.image,p,!1,h);m=V(n,m);const _=S(m)||o,g=r.convert(n.format,n.colorSpace);let b,w=r.convert(n.type),A=T(n.internalFormat,g,w,n.colorSpace,n.isVideoTexture);I(l,n,_);const C=n.mipmaps,M=o&&!0!==n.isVideoTexture,P=void 0===u.__version||!0===c,R=E(n,m,_);if(n.isDepthTexture)A=t.DEPTH_COMPONENT,o?A=n.type===UD?t.DEPTH_COMPONENT32F:n.type===FD?t.DEPTH_COMPONENT24:n.type===zD?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT16:n.type,n.format===VD&&A===t.DEPTH_COMPONENT&&n.type!==OD&&n.type!==FD&&(n.type=FD,w=r.convert(n.type)),n.format===HD&&A===t.DEPTH_COMPONENT&&(A=t.DEPTH_STENCIL,n.type!==zD&&(n.type=zD,w=r.convert(n.type))),P&&(M?i.texStorage2D(t.TEXTURE_2D,1,A,m.width,m.height):i.texImage2D(t.TEXTURE_2D,0,A,m.width,m.height,0,g,w,null));else if(n.isDataTexture)if(C.length>0&&_){M&&P&&i.texStorage2D(t.TEXTURE_2D,R,A,C[0].width,C[0].height);for(let e=0,s=C.length;e<s;e++)b=C[e],M?i.texSubImage2D(t.TEXTURE_2D,e,0,0,b.width,b.height,g,w,b.data):i.texImage2D(t.TEXTURE_2D,e,A,b.width,b.height,0,g,w,b.data);n.generateMipmaps=!1}else M?(P&&i.texStorage2D(t.TEXTURE_2D,R,A,m.width,m.height),i.texSubImage2D(t.TEXTURE_2D,0,0,0,m.width,m.height,g,w,m.data)):i.texImage2D(t.TEXTURE_2D,0,A,m.width,m.height,0,g,w,m.data);else if(n.isCompressedTexture)if(n.isCompressedArrayTexture){M&&P&&i.texStorage3D(t.TEXTURE_2D_ARRAY,R,A,C[0].width,C[0].height,m.depth);for(let e=0,s=C.length;e<s;e++)b=C[e],n.format!==kD?null!==g&&(M?i.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,b.width,b.height,m.depth,g,b.data,0,0):i.compressedTexImage3D(t.TEXTURE_2D_ARRAY,e,A,b.width,b.height,m.depth,0,b.data,0,0)):M?i.texSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,b.width,b.height,m.depth,g,w,b.data):i.texImage3D(t.TEXTURE_2D_ARRAY,e,A,b.width,b.height,m.depth,0,g,w,b.data)}else{M&&P&&i.texStorage2D(t.TEXTURE_2D,R,A,C[0].width,C[0].height);for(let e=0,s=C.length;e<s;e++)b=C[e],n.format!==kD?null!==g&&(M?i.compressedTexSubImage2D(t.TEXTURE_2D,e,0,0,b.width,b.height,g,b.data):i.compressedTexImage2D(t.TEXTURE_2D,e,A,b.width,b.height,0,b.data)):M?i.texSubImage2D(t.TEXTURE_2D,e,0,0,b.width,b.height,g,w,b.data):i.texImage2D(t.TEXTURE_2D,e,A,b.width,b.height,0,g,w,b.data)}else if(n.isDataArrayTexture)M?(P&&i.texStorage3D(t.TEXTURE_2D_ARRAY,R,A,m.width,m.height,m.depth),i.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,0,m.width,m.height,m.depth,g,w,m.data)):i.texImage3D(t.TEXTURE_2D_ARRAY,0,A,m.width,m.height,m.depth,0,g,w,m.data);else if(n.isData3DTexture)M?(P&&i.texStorage3D(t.TEXTURE_3D,R,A,m.width,m.height,m.depth),i.texSubImage3D(t.TEXTURE_3D,0,0,0,0,m.width,m.height,m.depth,g,w,m.data)):i.texImage3D(t.TEXTURE_3D,0,A,m.width,m.height,m.depth,0,g,w,m.data);else if(n.isFramebufferTexture){if(P)if(M)i.texStorage2D(t.TEXTURE_2D,R,A,m.width,m.height);else{let e=m.width,s=m.height;for(let n=0;n<R;n++)i.texImage2D(t.TEXTURE_2D,n,A,e,s,0,g,w,null),e>>=1,s>>=1}}else if(C.length>0&&_){M&&P&&i.texStorage2D(t.TEXTURE_2D,R,A,C[0].width,C[0].height);for(let e=0,s=C.length;e<s;e++)b=C[e],M?i.texSubImage2D(t.TEXTURE_2D,e,0,0,g,w,b):i.texImage2D(t.TEXTURE_2D,e,A,g,w,b);n.generateMipmaps=!1}else M?(P&&i.texStorage2D(t.TEXTURE_2D,R,A,m.width,m.height),i.texSubImage2D(t.TEXTURE_2D,0,0,0,g,w,m)):i.texImage2D(t.TEXTURE_2D,0,A,g,w,m);y(n,_)&&x(l),u.__version=d.version,n.onUpdate&&n.onUpdate(n)}e.__version=n.version}function F(e,n,a,o,l,h){const c=r.convert(a.format,a.colorSpace),u=r.convert(a.type),f=T(a.internalFormat,c,u,a.colorSpace);if(!s.get(n).__hasExternalTextures){const e=Math.max(1,n.width>>h),s=Math.max(1,n.height>>h);l===t.TEXTURE_3D||l===t.TEXTURE_2D_ARRAY?i.texImage3D(l,h,f,e,s,n.depth,0,c,u,null):i.texImage2D(l,h,f,e,s,0,c,u,null)}i.bindFramebuffer(t.FRAMEBUFFER,e),k(n)?d.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,o,l,s.get(a).__webglTexture,0,z(n)):(l===t.TEXTURE_2D||l>=t.TEXTURE_CUBE_MAP_POSITIVE_X&&l<=t.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&t.framebufferTexture2D(t.FRAMEBUFFER,o,l,s.get(a).__webglTexture,h),i.bindFramebuffer(t.FRAMEBUFFER,null)}function U(e,i,s){if(t.bindRenderbuffer(t.RENDERBUFFER,e),i.depthBuffer&&!i.stencilBuffer){let n=!0===o?t.DEPTH_COMPONENT24:t.DEPTH_COMPONENT16;if(s||k(i)){const e=i.depthTexture;e&&e.isDepthTexture&&(e.type===UD?n=t.DEPTH_COMPONENT32F:e.type===FD&&(n=t.DEPTH_COMPONENT24));const s=z(i);k(i)?d.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,s,n,i.width,i.height):t.renderbufferStorageMultisample(t.RENDERBUFFER,s,n,i.width,i.height)}else t.renderbufferStorage(t.RENDERBUFFER,n,i.width,i.height);t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,e)}else if(i.depthBuffer&&i.stencilBuffer){const n=z(i);s&&!1===k(i)?t.renderbufferStorageMultisample(t.RENDERBUFFER,n,t.DEPTH24_STENCIL8,i.width,i.height):k(i)?d.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,n,t.DEPTH24_STENCIL8,i.width,i.height):t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_STENCIL,i.width,i.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.RENDERBUFFER,e)}else{const e=!0===i.isWebGLMultipleRenderTargets?i.texture:[i.texture];for(let n=0;n<e.length;n++){const a=e[n],o=r.convert(a.format,a.colorSpace),l=r.convert(a.type),h=T(a.internalFormat,o,l,a.colorSpace),c=z(i);s&&!1===k(i)?t.renderbufferStorageMultisample(t.RENDERBUFFER,c,h,i.width,i.height):k(i)?d.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,c,h,i.width,i.height):t.renderbufferStorage(t.RENDERBUFFER,h,i.width,i.height)}}t.bindRenderbuffer(t.RENDERBUFFER,null)}function B(e){const n=s.get(e),r=!0===e.isWebGLCubeRenderTarget;if(e.depthTexture&&!n.__autoAllocateDepthBuffer){if(r)throw new Error("target.depthTexture not supported in Cube render targets");!function(e,n){if(n&&n.isWebGLCubeRenderTarget)throw new Error("Depth Texture with cube render targets is not supported");if(i.bindFramebuffer(t.FRAMEBUFFER,e),!n.depthTexture||!n.depthTexture.isDepthTexture)throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");s.get(n.depthTexture).__webglTexture&&n.depthTexture.image.width===n.width&&n.depthTexture.image.height===n.height||(n.depthTexture.image.width=n.width,n.depthTexture.image.height=n.height,n.depthTexture.needsUpdate=!0),P(n.depthTexture,0);const r=s.get(n.depthTexture).__webglTexture,a=z(n);if(n.depthTexture.format===VD)k(n)?d.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.TEXTURE_2D,r,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.TEXTURE_2D,r,0);else{if(n.depthTexture.format!==HD)throw new Error("Unknown depthTexture format");k(n)?d.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.TEXTURE_2D,r,0,a):t.framebufferTexture2D(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.TEXTURE_2D,r,0)}}(n.__webglFramebuffer,e)}else if(r){n.__webglDepthbuffer=[];for(let s=0;s<6;s++)i.bindFramebuffer(t.FRAMEBUFFER,n.__webglFramebuffer[s]),n.__webglDepthbuffer[s]=t.createRenderbuffer(),U(n.__webglDepthbuffer[s],e,!1)}else i.bindFramebuffer(t.FRAMEBUFFER,n.__webglFramebuffer),n.__webglDepthbuffer=t.createRenderbuffer(),U(n.__webglDepthbuffer,e,!1);i.bindFramebuffer(t.FRAMEBUFFER,null)}function z(t){return Math.min(c,t.samples)}function k(t){const i=s.get(t);return o&&t.samples>0&&!0===e.has("WEBGL_multisampled_render_to_texture")&&!1!==i.__useRenderToTexture}function V(t,i){const s=t.colorSpace,n=t.format;t.type;return!0===t.isCompressedTexture||!0===t.isVideoTexture||t.format===pI||s!==ZD&&s!==$D&&kI.getTransfer(s)===eI&&!1===o&&(!0===e.has("EXT_sRGB")&&n===kD?(t.format=pI,t.minFilter=RD,t.generateMipmaps=!1):i=WI.sRGBToLinear(i)),i}this.allocateTextureUnit=function(){const t=M;return M+=1,t},this.resetTextureUnits=function(){M=0},this.setTexture2D=P,this.setTexture2DArray=function(e,n){const r=s.get(e);e.version>0&&r.__version!==e.version?N(r,e,n):i.bindTexture(t.TEXTURE_2D_ARRAY,r.__webglTexture,t.TEXTURE0+n)},this.setTexture3D=function(e,n){const r=s.get(e);e.version>0&&r.__version!==e.version?N(r,e,n):i.bindTexture(t.TEXTURE_3D,r.__webglTexture,t.TEXTURE0+n)},this.setTextureCube=function(e,n){const a=s.get(e);e.version>0&&a.__version!==e.version?function(e,n,a){if(6!==n.image.length)return;const h=O(e,n),c=n.source;i.bindTexture(t.TEXTURE_CUBE_MAP,e.__webglTexture,t.TEXTURE0+a);const d=s.get(c);if(c.version!==d.__version||!0===h){i.activeTexture(t.TEXTURE0+a);const e=kI.getPrimaries(kI.workingColorSpace),s=n.colorSpace===$D?null:kI.getPrimaries(n.colorSpace),u=n.colorSpace===$D||e===s?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,n.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,n.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,u);const f=n.isCompressedTexture||n.image[0].isCompressedTexture,p=n.image[0]&&n.image[0].isDataTexture,m=[];for(let t=0;t<6;t++)m[t]=f||p?p?n.image[t].image:n.image[t]:v(n.image[t],!1,!0,l),m[t]=V(n,m[t]);const _=m[0],g=S(_)||o,b=r.convert(n.format,n.colorSpace),w=r.convert(n.type),A=T(n.internalFormat,b,w,n.colorSpace),C=o&&!0!==n.isVideoTexture,M=void 0===d.__version||!0===h;let P,R=E(n,_,g);if(I(t.TEXTURE_CUBE_MAP,n,g),f){C&&M&&i.texStorage2D(t.TEXTURE_CUBE_MAP,R,A,_.width,_.height);for(let e=0;e<6;e++){P=m[e].mipmaps;for(let s=0;s<P.length;s++){const r=P[s];n.format!==kD?null!==b&&(C?i.compressedTexSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s,0,0,r.width,r.height,b,r.data):i.compressedTexImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s,A,r.width,r.height,0,r.data)):C?i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s,0,0,r.width,r.height,b,w,r.data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s,A,r.width,r.height,0,b,w,r.data)}}}else{P=n.mipmaps,C&&M&&(P.length>0&&R++,i.texStorage2D(t.TEXTURE_CUBE_MAP,R,A,m[0].width,m[0].height));for(let e=0;e<6;e++)if(p){C?i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,m[e].width,m[e].height,b,w,m[e].data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,A,m[e].width,m[e].height,0,b,w,m[e].data);for(let s=0;s<P.length;s++){const n=P[s].image[e].image;C?i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s+1,0,0,n.width,n.height,b,w,n.data):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s+1,A,n.width,n.height,0,b,w,n.data)}}else{C?i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,b,w,m[e]):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,A,b,w,m[e]);for(let s=0;s<P.length;s++){const n=P[s];C?i.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s+1,0,0,b,w,n.image[e]):i.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,s+1,A,b,w,n.image[e])}}}y(n,g)&&x(t.TEXTURE_CUBE_MAP),d.__version=c.version,n.onUpdate&&n.onUpdate(n)}e.__version=n.version}(a,e,n):i.bindTexture(t.TEXTURE_CUBE_MAP,a.__webglTexture,t.TEXTURE0+n)},this.rebindTextures=function(e,i,n){const r=s.get(e);void 0!==i&&F(r.__webglFramebuffer,e,e.texture,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,0),void 0!==n&&B(e)},this.setupRenderTarget=function(e){const l=e.texture,h=s.get(e),c=s.get(l);e.addEventListener("dispose",A),!0!==e.isWebGLMultipleRenderTargets&&(void 0===c.__webglTexture&&(c.__webglTexture=t.createTexture()),c.__version=l.version,a.memory.textures++);const d=!0===e.isWebGLCubeRenderTarget,u=!0===e.isWebGLMultipleRenderTargets,f=S(e)||o;if(d){h.__webglFramebuffer=[];for(let e=0;e<6;e++)if(o&&l.mipmaps&&l.mipmaps.length>0){h.__webglFramebuffer[e]=[];for(let i=0;i<l.mipmaps.length;i++)h.__webglFramebuffer[e][i]=t.createFramebuffer()}else h.__webglFramebuffer[e]=t.createFramebuffer()}else{if(o&&l.mipmaps&&l.mipmaps.length>0){h.__webglFramebuffer=[];for(let e=0;e<l.mipmaps.length;e++)h.__webglFramebuffer[e]=t.createFramebuffer()}else h.__webglFramebuffer=t.createFramebuffer();if(u&&n.drawBuffers){const i=e.texture;for(let e=0,n=i.length;e<n;e++){const n=s.get(i[e]);void 0===n.__webglTexture&&(n.__webglTexture=t.createTexture(),a.memory.textures++)}}if(o&&e.samples>0&&!1===k(e)){const s=u?l:[l];h.__webglMultisampledFramebuffer=t.createFramebuffer(),h.__webglColorRenderbuffer=[],i.bindFramebuffer(t.FRAMEBUFFER,h.__webglMultisampledFramebuffer);for(let i=0;i<s.length;i++){const n=s[i];h.__webglColorRenderbuffer[i]=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,h.__webglColorRenderbuffer[i]);const a=r.convert(n.format,n.colorSpace),o=r.convert(n.type),l=T(n.internalFormat,a,o,n.colorSpace,!0===e.isXRRenderTarget),c=z(e);t.renderbufferStorageMultisample(t.RENDERBUFFER,c,l,e.width,e.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+i,t.RENDERBUFFER,h.__webglColorRenderbuffer[i])}t.bindRenderbuffer(t.RENDERBUFFER,null),e.depthBuffer&&(h.__webglDepthRenderbuffer=t.createRenderbuffer(),U(h.__webglDepthRenderbuffer,e,!0)),i.bindFramebuffer(t.FRAMEBUFFER,null)}}if(d){i.bindTexture(t.TEXTURE_CUBE_MAP,c.__webglTexture),I(t.TEXTURE_CUBE_MAP,l,f);for(let i=0;i<6;i++)if(o&&l.mipmaps&&l.mipmaps.length>0)for(let s=0;s<l.mipmaps.length;s++)F(h.__webglFramebuffer[i][s],e,l,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+i,s);else F(h.__webglFramebuffer[i],e,l,t.COLOR_ATTACHMENT0,t.TEXTURE_CUBE_MAP_POSITIVE_X+i,0);y(l,f)&&x(t.TEXTURE_CUBE_MAP),i.unbindTexture()}else if(u){const n=e.texture;for(let r=0,a=n.length;r<a;r++){const a=n[r],o=s.get(a);i.bindTexture(t.TEXTURE_2D,o.__webglTexture),I(t.TEXTURE_2D,a,f),F(h.__webglFramebuffer,e,a,t.COLOR_ATTACHMENT0+r,t.TEXTURE_2D,0),y(a,f)&&x(t.TEXTURE_2D)}i.unbindTexture()}else{let s=t.TEXTURE_2D;if((e.isWebGL3DRenderTarget||e.isWebGLArrayRenderTarget)&&o&&(s=e.isWebGL3DRenderTarget?t.TEXTURE_3D:t.TEXTURE_2D_ARRAY),i.bindTexture(s,c.__webglTexture),I(s,l,f),o&&l.mipmaps&&l.mipmaps.length>0)for(let i=0;i<l.mipmaps.length;i++)F(h.__webglFramebuffer[i],e,l,t.COLOR_ATTACHMENT0,s,i);else F(h.__webglFramebuffer,e,l,t.COLOR_ATTACHMENT0,s,0);y(l,f)&&x(s),i.unbindTexture()}e.depthBuffer&&B(e)},this.updateRenderTargetMipmap=function(e){const n=S(e)||o,r=!0===e.isWebGLMultipleRenderTargets?e.texture:[e.texture];for(let a=0,o=r.length;a<o;a++){const o=r[a];if(y(o,n)){const n=e.isWebGLCubeRenderTarget?t.TEXTURE_CUBE_MAP:t.TEXTURE_2D,r=s.get(o).__webglTexture;i.bindTexture(n,r),x(n),i.unbindTexture()}}},this.updateMultisampleRenderTarget=function(e){if(o&&e.samples>0&&!1===k(e)){const n=e.isWebGLMultipleRenderTargets?e.texture:[e.texture],r=e.width,a=e.height;let o=t.COLOR_BUFFER_BIT;const l=[],h=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,c=s.get(e),d=!0===e.isWebGLMultipleRenderTargets;if(d)for(let e=0;e<n.length;e++)i.bindFramebuffer(t.FRAMEBUFFER,c.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,null),i.bindFramebuffer(t.FRAMEBUFFER,c.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,null,0);i.bindFramebuffer(t.READ_FRAMEBUFFER,c.__webglMultisampledFramebuffer),i.bindFramebuffer(t.DRAW_FRAMEBUFFER,c.__webglFramebuffer);for(let i=0;i<n.length;i++){l.push(t.COLOR_ATTACHMENT0+i),e.depthBuffer&&l.push(h);const f=void 0!==c.__ignoreDepthValues&&c.__ignoreDepthValues;if(!1===f&&(e.depthBuffer&&(o|=t.DEPTH_BUFFER_BIT),e.stencilBuffer&&(o|=t.STENCIL_BUFFER_BIT)),d&&t.framebufferRenderbuffer(t.READ_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.RENDERBUFFER,c.__webglColorRenderbuffer[i]),!0===f&&(t.invalidateFramebuffer(t.READ_FRAMEBUFFER,[h]),t.invalidateFramebuffer(t.DRAW_FRAMEBUFFER,[h])),d){const e=s.get(n[i]).__webglTexture;t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,e,0)}t.blitFramebuffer(0,0,r,a,0,0,r,a,o,t.NEAREST),u&&t.invalidateFramebuffer(t.READ_FRAMEBUFFER,l)}if(i.bindFramebuffer(t.READ_FRAMEBUFFER,null),i.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),d)for(let e=0;e<n.length;e++){i.bindFramebuffer(t.FRAMEBUFFER,c.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,c.__webglColorRenderbuffer[e]);const r=s.get(n[e]).__webglTexture;i.bindFramebuffer(t.FRAMEBUFFER,c.__webglFramebuffer),t.framebufferTexture2D(t.DRAW_FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.TEXTURE_2D,r,0)}i.bindFramebuffer(t.DRAW_FRAMEBUFFER,c.__webglMultisampledFramebuffer)}},this.setupDepthRenderbuffer=B,this.setupFrameBufferTexture=F,this.useMultisampledRTT=k}function qB(t,e,i){const s=i.isWebGL2;return{convert:function(i,n=""){let r;const a=kI.getTransfer(n);if(i===ID)return t.UNSIGNED_BYTE;if(1017===i)return t.UNSIGNED_SHORT_4_4_4_4;if(1018===i)return t.UNSIGNED_SHORT_5_5_5_1;if(1010===i)return t.BYTE;if(1011===i)return t.SHORT;if(i===OD)return t.UNSIGNED_SHORT;if(i===ND)return t.INT;if(i===FD)return t.UNSIGNED_INT;if(i===UD)return t.FLOAT;if(i===BD)return s?t.HALF_FLOAT:(r=e.get("OES_texture_half_float"),null!==r?r.HALF_FLOAT_OES:null);if(1021===i)return t.ALPHA;if(i===kD)return t.RGBA;if(1024===i)return t.LUMINANCE;if(1025===i)return t.LUMINANCE_ALPHA;if(i===VD)return t.DEPTH_COMPONENT;if(i===HD)return t.DEPTH_STENCIL;if(i===pI)return r=e.get("EXT_sRGB"),null!==r?r.SRGB_ALPHA_EXT:null;if(1028===i)return t.RED;if(1029===i)return t.RED_INTEGER;if(1030===i)return t.RG;if(1031===i)return t.RG_INTEGER;if(1033===i)return t.RGBA_INTEGER;if(i===GD||i===WD||i===XD||i===YD)if(a===eI){if(r=e.get("WEBGL_compressed_texture_s3tc_srgb"),null===r)return null;if(i===GD)return r.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(i===WD)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(i===XD)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(i===YD)return r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else{if(r=e.get("WEBGL_compressed_texture_s3tc"),null===r)return null;if(i===GD)return r.COMPRESSED_RGB_S3TC_DXT1_EXT;if(i===WD)return r.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(i===XD)return r.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(i===YD)return r.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===i||35841===i||35842===i||35843===i){if(r=e.get("WEBGL_compressed_texture_pvrtc"),null===r)return null;if(35840===i)return r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===i)return r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===i)return r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===i)return r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===i)return r=e.get("WEBGL_compressed_texture_etc1"),null!==r?r.COMPRESSED_RGB_ETC1_WEBGL:null;if(37492===i||37496===i){if(r=e.get("WEBGL_compressed_texture_etc"),null===r)return null;if(37492===i)return a===eI?r.COMPRESSED_SRGB8_ETC2:r.COMPRESSED_RGB8_ETC2;if(37496===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:r.COMPRESSED_RGBA8_ETC2_EAC}if(37808===i||37809===i||37810===i||37811===i||37812===i||37813===i||37814===i||37815===i||37816===i||37817===i||37818===i||37819===i||37820===i||37821===i){if(r=e.get("WEBGL_compressed_texture_astc"),null===r)return null;if(37808===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:r.COMPRESSED_RGBA_ASTC_4x4_KHR;if(37809===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:r.COMPRESSED_RGBA_ASTC_5x4_KHR;if(37810===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:r.COMPRESSED_RGBA_ASTC_5x5_KHR;if(37811===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:r.COMPRESSED_RGBA_ASTC_6x5_KHR;if(37812===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:r.COMPRESSED_RGBA_ASTC_6x6_KHR;if(37813===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:r.COMPRESSED_RGBA_ASTC_8x5_KHR;if(37814===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:r.COMPRESSED_RGBA_ASTC_8x6_KHR;if(37815===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:r.COMPRESSED_RGBA_ASTC_8x8_KHR;if(37816===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:r.COMPRESSED_RGBA_ASTC_10x5_KHR;if(37817===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:r.COMPRESSED_RGBA_ASTC_10x6_KHR;if(37818===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:r.COMPRESSED_RGBA_ASTC_10x8_KHR;if(37819===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:r.COMPRESSED_RGBA_ASTC_10x10_KHR;if(37820===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:r.COMPRESSED_RGBA_ASTC_12x10_KHR;if(37821===i)return a===eI?r.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:r.COMPRESSED_RGBA_ASTC_12x12_KHR}if(i===qD||36494===i||36495===i){if(r=e.get("EXT_texture_compression_bptc"),null===r)return null;if(i===qD)return a===eI?r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:r.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(36494===i)return r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(36495===i)return r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}if(36283===i||36284===i||36285===i||36286===i){if(r=e.get("EXT_texture_compression_rgtc"),null===r)return null;if(i===qD)return r.COMPRESSED_RED_RGTC1_EXT;if(36284===i)return r.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(36285===i)return r.COMPRESSED_RED_GREEN_RGTC2_EXT;if(36286===i)return r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}return i===zD?s?t.UNSIGNED_INT_24_8:(r=e.get("WEBGL_depth_texture"),null!==r?r.UNSIGNED_INT_24_8_WEBGL:null):void 0!==t[i]?t[i]:null}}}class jB extends dF{constructor(t=[]){super(),this.isArrayCamera=!0,this.cameras=t}}class $B extends sN{constructor(){super(),this.isGroup=!0,this.type="Group"}}const KB={type:"move"};class ZB{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return null===this._hand&&(this._hand=new $B,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 $B,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new iO,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new iO),this._targetRay}getGripSpace(){return null===this._grip&&(this._grip=new $B,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new iO,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new iO),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 i of t.hand.values())this._getHandJoint(e,i)}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,i){let s=null,n=null,r=null;const a=this._targetRay,o=this._grip,l=this._hand;if(t&&"visible-blurred"!==e.session.visibilityState){if(l&&t.hand){r=!0;for(const s of t.hand.values()){const t=e.getJointPose(s,i),n=this._getHandJoint(l,s);null!==t&&(n.matrix.fromArray(t.transform.matrix),n.matrix.decompose(n.position,n.rotation,n.scale),n.matrixWorldNeedsUpdate=!0,n.jointRadius=t.radius),n.visible=null!==t}const s=l.joints["index-finger-tip"],n=l.joints["thumb-tip"],a=s.position.distanceTo(n.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&&(n=e.getPose(t.gripSpace,i),null!==n&&(o.matrix.fromArray(n.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,n.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(n.linearVelocity)):o.hasLinearVelocity=!1,n.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(n.angularVelocity)):o.hasAngularVelocity=!1));null!==a&&(s=e.getPose(t.targetRaySpace,i),null===s&&null!==n&&(s=n),null!==s&&(a.matrix.fromArray(s.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,s.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(s.linearVelocity)):a.hasLinearVelocity=!1,s.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(s.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(KB)))}return null!==a&&(a.visible=null!==s),null!==o&&(o.visible=null!==n),null!==l&&(l.visible=null!==r),this}_getHandJoint(t,e){if(void 0===t.joints[e.jointName]){const i=new $B;i.matrixAutoUpdate=!1,i.visible=!1,t.joints[e.jointName]=i,t.add(i)}return t.joints[e.jointName]}}class QB extends $I{constructor(t,e,i,s,n,r,a,o,l,h){if((h=void 0!==h?h:VD)!==VD&&h!==HD)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===i&&h===VD&&(i=FD),void 0===i&&h===HD&&(i=zD),super(null,s,n,r,a,o,h,i,l),this.isDepthTexture=!0,this.image={width:t,height:e},this.magFilter=void 0!==a?a:CD,this.minFilter=void 0!==o?o:CD,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 JB extends gI{constructor(t,e){super();const i=this;let s=null,n=1,r=null,a="local-floor",o=1,l=null,h=null,c=null,d=null,u=null,f=null;const p=e.getContextAttributes();let m=null,_=null;const g=[],v=[],S=new dF;S.layers.enable(1),S.viewport=new KI;const y=new dF;y.layers.enable(2),y.viewport=new KI;const x=[S,y],T=new jB;T.layers.enable(1),T.layers.enable(2);let E=null,b=null;function w(t){const e=v.indexOf(t.inputSource);if(-1===e)return;const i=g[e];void 0!==i&&(i.update(t.inputSource,t.frame,l||r),i.dispatchEvent({type:t.type,data:t.inputSource}))}function A(){s.removeEventListener("select",w),s.removeEventListener("selectstart",w),s.removeEventListener("selectend",w),s.removeEventListener("squeeze",w),s.removeEventListener("squeezestart",w),s.removeEventListener("squeezeend",w),s.removeEventListener("end",A),s.removeEventListener("inputsourceschange",C);for(let t=0;t<g.length;t++){const e=v[t];null!==e&&(v[t]=null,g[t].disconnect(e))}E=null,b=null,t.setRenderTarget(m),u=null,d=null,c=null,s=null,_=null,D.stop(),i.isPresenting=!1,i.dispatchEvent({type:"sessionend"})}function C(t){for(let e=0;e<t.removed.length;e++){const i=t.removed[e],s=v.indexOf(i);s>=0&&(v[s]=null,g[s].disconnect(i))}for(let e=0;e<t.added.length;e++){const i=t.added[e];let s=v.indexOf(i);if(-1===s){for(let t=0;t<g.length;t++){if(t>=v.length){v.push(i),s=t;break}if(null===v[t]){v[t]=i,s=t;break}}if(-1===s)break}const n=g[s];n&&n.connect(i)}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(t){let e=g[t];return void 0===e&&(e=new ZB,g[t]=e),e.getTargetRaySpace()},this.getControllerGrip=function(t){let e=g[t];return void 0===e&&(e=new ZB,g[t]=e),e.getGripSpace()},this.getHand=function(t){let e=g[t];return void 0===e&&(e=new ZB,g[t]=e),e.getHandSpace()},this.setFramebufferScaleFactor=function(t){n=t,i.isPresenting},this.setReferenceSpaceType=function(t){a=t,i.isPresenting},this.getReferenceSpace=function(){return l||r},this.setReferenceSpace=function(t){l=t},this.getBaseLayer=function(){return null!==d?d:u},this.getBinding=function(){return c},this.getFrame=function(){return f},this.getSession=function(){return s},this.setSession=async function(h){if(s=h,null!==s){if(m=t.getRenderTarget(),s.addEventListener("select",w),s.addEventListener("selectstart",w),s.addEventListener("selectend",w),s.addEventListener("squeeze",w),s.addEventListener("squeezestart",w),s.addEventListener("squeezeend",w),s.addEventListener("end",A),s.addEventListener("inputsourceschange",C),!0!==p.xrCompatible&&await e.makeXRCompatible(),void 0===s.renderState.layers||!1===t.capabilities.isWebGL2){const i={antialias:void 0!==s.renderState.layers||p.antialias,alpha:!0,depth:p.depth,stencil:p.stencil,framebufferScaleFactor:n};u=new XRWebGLLayer(s,e,i),s.updateRenderState({baseLayer:u}),_=new QI(u.framebufferWidth,u.framebufferHeight,{format:kD,type:ID,colorSpace:t.outputColorSpace,stencilBuffer:p.stencil})}else{let i=null,r=null,a=null;p.depth&&(a=p.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,i=p.stencil?HD:VD,r=p.stencil?zD:FD);const o={colorFormat:e.RGBA8,depthFormat:a,scaleFactor:n};c=new XRWebGLBinding(s,e),d=c.createProjectionLayer(o),s.updateRenderState({layers:[d]}),_=new QI(d.textureWidth,d.textureHeight,{format:kD,type:ID,depthTexture:new QB(d.textureWidth,d.textureHeight,r,void 0,void 0,void 0,void 0,void 0,void 0,i),stencilBuffer:p.stencil,colorSpace:t.outputColorSpace,samples:p.antialias?4:0});t.properties.get(_).__ignoreDepthValues=d.ignoreDepthValues}_.isXRRenderTarget=!0,this.setFoveation(o),l=null,r=await s.requestReferenceSpace(a),D.setContext(s),D.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(null!==s)return s.environmentBlendMode};const M=new iO,P=new iO;function R(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===s)return;T.near=y.near=S.near=t.near,T.far=y.far=S.far=t.far,E===T.near&&b===T.far||(s.updateRenderState({depthNear:T.near,depthFar:T.far}),E=T.near,b=T.far);const e=t.parent,i=T.cameras;R(T,e);for(let t=0;t<i.length;t++)R(i[t],e);2===i.length?function(t,e,i){M.setFromMatrixPosition(e.matrixWorld),P.setFromMatrixPosition(i.matrixWorld);const s=M.distanceTo(P),n=e.projectionMatrix.elements,r=i.projectionMatrix.elements,a=n[14]/(n[10]-1),o=n[14]/(n[10]+1),l=(n[9]+1)/n[5],h=(n[9]-1)/n[5],c=(n[8]-1)/n[0],d=(r[8]+1)/r[0],u=a*c,f=a*d,p=s/(-c+d),m=p*-c;e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.translateX(m),t.translateZ(p),t.matrixWorld.compose(t.position,t.quaternion,t.scale),t.matrixWorldInverse.copy(t.matrixWorld).invert();const _=a+p,g=o+p,v=u-m,S=f+(s-m),y=l*o/g*_,x=h*o/g*_;t.projectionMatrix.makePerspective(v,S,y,x,_,g),t.projectionMatrixInverse.copy(t.projectionMatrix).invert()}(T,S,y):T.projectionMatrix.copy(S.projectionMatrix),function(t,e,i){null===i?t.matrix.copy(e.matrixWorld):(t.matrix.copy(i.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*yI*Math.atan(1/t.projectionMatrix.elements[5]),t.zoom=1)}(t,T,e)},this.getCamera=function(){return T},this.getFoveation=function(){if(null!==d||null!==u)return o},this.setFoveation=function(t){o=t,null!==d&&(d.fixedFoveation=t),null!==u&&void 0!==u.fixedFoveation&&(u.fixedFoveation=t)};let L=null;const D=new EF;D.setAnimationLoop(function(e,s){if(h=s.getViewerPose(l||r),f=s,null!==h){const e=h.views;null!==u&&(t.setRenderTargetFramebuffer(_,u.framebuffer),t.setRenderTarget(_));let i=!1;e.length!==T.cameras.length&&(T.cameras.length=0,i=!0);for(let s=0;s<e.length;s++){const n=e[s];let r=null;if(null!==u)r=u.getViewport(n);else{const e=c.getViewSubImage(d,n);r=e.viewport,0===s&&(t.setRenderTargetTextures(_,e.colorTexture,d.ignoreDepthValues?void 0:e.depthStencilTexture),t.setRenderTarget(_))}let a=x[s];void 0===a&&(a=new dF,a.layers.enable(s),a.viewport=new KI,x[s]=a),a.matrix.fromArray(n.transform.matrix),a.matrix.decompose(a.position,a.quaternion,a.scale),a.projectionMatrix.fromArray(n.projectionMatrix),a.projectionMatrixInverse.copy(a.projectionMatrix).invert(),a.viewport.set(r.x,r.y,r.width,r.height),0===s&&(T.matrix.copy(a.matrix),T.matrix.decompose(T.position,T.quaternion,T.scale)),!0===i&&T.cameras.push(a)}}for(let t=0;t<g.length;t++){const e=v[t],i=g[t];null!==e&&void 0!==i&&i.update(e,s,l||r)}L&&L(e,s),s.detectedPlanes&&i.dispatchEvent({type:"planesdetected",data:s}),f=null}),this.setAnimationLoop=function(t){L=t},this.dispose=function(){}}}function tz(t,e){function i(t,e){!0===t.matrixAutoUpdate&&t.updateMatrix(),e.value.copy(t.matrix)}function s(s,n){s.opacity.value=n.opacity,n.color&&s.diffuse.value.copy(n.color),n.emissive&&s.emissive.value.copy(n.emissive).multiplyScalar(n.emissiveIntensity),n.map&&(s.map.value=n.map,i(n.map,s.mapTransform)),n.alphaMap&&(s.alphaMap.value=n.alphaMap,i(n.alphaMap,s.alphaMapTransform)),n.bumpMap&&(s.bumpMap.value=n.bumpMap,i(n.bumpMap,s.bumpMapTransform),s.bumpScale.value=n.bumpScale,1===n.side&&(s.bumpScale.value*=-1)),n.normalMap&&(s.normalMap.value=n.normalMap,i(n.normalMap,s.normalMapTransform),s.normalScale.value.copy(n.normalScale),1===n.side&&s.normalScale.value.negate()),n.displacementMap&&(s.displacementMap.value=n.displacementMap,i(n.displacementMap,s.displacementMapTransform),s.displacementScale.value=n.displacementScale,s.displacementBias.value=n.displacementBias),n.emissiveMap&&(s.emissiveMap.value=n.emissiveMap,i(n.emissiveMap,s.emissiveMapTransform)),n.specularMap&&(s.specularMap.value=n.specularMap,i(n.specularMap,s.specularMapTransform)),n.alphaTest>0&&(s.alphaTest.value=n.alphaTest);const r=e.get(n).envMap;if(r&&(s.envMap.value=r,s.flipEnvMap.value=r.isCubeTexture&&!1===r.isRenderTargetTexture?-1:1,s.reflectivity.value=n.reflectivity,s.ior.value=n.ior,s.refractionRatio.value=n.refractionRatio),n.lightMap){s.lightMap.value=n.lightMap;const e=!0===t._useLegacyLights?Math.PI:1;s.lightMapIntensity.value=n.lightMapIntensity*e,i(n.lightMap,s.lightMapTransform)}n.aoMap&&(s.aoMap.value=n.aoMap,s.aoMapIntensity.value=n.aoMapIntensity,i(n.aoMap,s.aoMapTransform))}return{refreshFogUniforms:function(e,i){i.color.getRGB(e.fogColor.value,oF(t)),i.isFog?(e.fogNear.value=i.near,e.fogFar.value=i.far):i.isFogExp2&&(e.fogDensity.value=i.density)},refreshMaterialUniforms:function(t,n,r,a,o){n.isMeshBasicMaterial||n.isMeshLambertMaterial?s(t,n):n.isMeshToonMaterial?(s(t,n),function(t,e){e.gradientMap&&(t.gradientMap.value=e.gradientMap)}(t,n)):n.isMeshPhongMaterial?(s(t,n),function(t,e){t.specular.value.copy(e.specular),t.shininess.value=Math.max(e.shininess,1e-4)}(t,n)):n.isMeshStandardMaterial?(s(t,n),function(t,s){t.metalness.value=s.metalness,s.metalnessMap&&(t.metalnessMap.value=s.metalnessMap,i(s.metalnessMap,t.metalnessMapTransform));t.roughness.value=s.roughness,s.roughnessMap&&(t.roughnessMap.value=s.roughnessMap,i(s.roughnessMap,t.roughnessMapTransform));const n=e.get(s).envMap;n&&(t.envMapIntensity.value=s.envMapIntensity)}(t,n),n.isMeshPhysicalMaterial&&function(t,e,s){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,i(e.sheenColorMap,t.sheenColorMapTransform)),e.sheenRoughnessMap&&(t.sheenRoughnessMap.value=e.sheenRoughnessMap,i(e.sheenRoughnessMap,t.sheenRoughnessMapTransform)));e.clearcoat>0&&(t.clearcoat.value=e.clearcoat,t.clearcoatRoughness.value=e.clearcoatRoughness,e.clearcoatMap&&(t.clearcoatMap.value=e.clearcoatMap,i(e.clearcoatMap,t.clearcoatMapTransform)),e.clearcoatRoughnessMap&&(t.clearcoatRoughnessMap.value=e.clearcoatRoughnessMap,i(e.clearcoatRoughnessMap,t.clearcoatRoughnessMapTransform)),e.clearcoatNormalMap&&(t.clearcoatNormalMap.value=e.clearcoatNormalMap,i(e.clearcoatNormalMap,t.clearcoatNormalMapTransform),t.clearcoatNormalScale.value.copy(e.clearcoatNormalScale),1===e.side&&t.clearcoatNormalScale.value.negate()));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,i(e.iridescenceMap,t.iridescenceMapTransform)),e.iridescenceThicknessMap&&(t.iridescenceThicknessMap.value=e.iridescenceThicknessMap,i(e.iridescenceThicknessMap,t.iridescenceThicknessMapTransform)));e.transmission>0&&(t.transmission.value=e.transmission,t.transmissionSamplerMap.value=s.texture,t.transmissionSamplerSize.value.set(s.width,s.height),e.transmissionMap&&(t.transmissionMap.value=e.transmissionMap,i(e.transmissionMap,t.transmissionMapTransform)),t.thickness.value=e.thickness,e.thicknessMap&&(t.thicknessMap.value=e.thicknessMap,i(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,i(e.anisotropyMap,t.anisotropyMapTransform)));t.specularIntensity.value=e.specularIntensity,t.specularColor.value.copy(e.specularColor),e.specularColorMap&&(t.specularColorMap.value=e.specularColorMap,i(e.specularColorMap,t.specularColorMapTransform));e.specularIntensityMap&&(t.specularIntensityMap.value=e.specularIntensityMap,i(e.specularIntensityMap,t.specularIntensityMapTransform))}(t,n,o)):n.isMeshMatcapMaterial?(s(t,n),function(t,e){e.matcap&&(t.matcap.value=e.matcap)}(t,n)):n.isMeshDepthMaterial?s(t,n):n.isMeshDistanceMaterial?(s(t,n),function(t,i){const s=e.get(i).light;t.referencePosition.value.setFromMatrixPosition(s.matrixWorld),t.nearDistance.value=s.shadow.camera.near,t.farDistance.value=s.shadow.camera.far}(t,n)):n.isMeshNormalMaterial?s(t,n):n.isLineBasicMaterial?(function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,e.map&&(t.map.value=e.map,i(e.map,t.mapTransform))}(t,n),n.isLineDashedMaterial&&function(t,e){t.dashSize.value=e.dashSize,t.totalSize.value=e.dashSize+e.gapSize,t.scale.value=e.scale}(t,n)):n.isPointsMaterial?function(t,e,s,n){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.size.value=e.size*s,t.scale.value=.5*n,e.map&&(t.map.value=e.map,i(e.map,t.uvTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,i(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,n,r,a):n.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,i(e.map,t.mapTransform));e.alphaMap&&(t.alphaMap.value=e.alphaMap,i(e.alphaMap,t.alphaMapTransform));e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,n):n.isShadowMaterial?(t.color.value.copy(n.color),t.opacity.value=n.opacity):n.isShaderMaterial&&(n.uniformsNeedUpdate=!1)}}}function ez(t,e,i,s){let n={},r={},a=[];const o=i.isWebGL2?t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS):0;function l(t,e,i){const s=t.value;if(void 0===i[e]){if("number"==typeof s)i[e]=s;else{const t=Array.isArray(s)?s:[s],n=[];for(let e=0;e<t.length;e++)n.push(t[e].clone());i[e]=n}return!0}if("number"==typeof s){if(i[e]!==s)return i[e]=s,!0}else{const t=Array.isArray(i[e])?i[e]:[i[e]],n=Array.isArray(s)?s:[s];for(let e=0;e<t.length;e++){const i=t[e];if(!1===i.equals(n[e]))return i.copy(n[e]),!0}}return!1}function h(t){const e={boundary:0,storage:0};return"number"==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,e}function c(e){const i=e.target;i.removeEventListener("dispose",c);const s=a.indexOf(i.__bindingPointIndex);a.splice(s,1),t.deleteBuffer(n[i.id]),delete n[i.id],delete r[i.id]}return{bind:function(t,e){const i=e.program;s.uniformBlockBinding(t,i)},update:function(i,d){let u=n[i.id];void 0===u&&(!function(t){const e=t.uniforms;let i=0;const s=16;let n=0;for(let t=0,r=e.length;t<r;t++){const r=e[t],a={boundary:0,storage:0},o=Array.isArray(r.value)?r.value:[r.value];for(let t=0,e=o.length;t<e;t++){const e=h(o[t]);a.boundary+=e.boundary,a.storage+=e.storage}if(r.__data=new Float32Array(a.storage/Float32Array.BYTES_PER_ELEMENT),r.__offset=i,t>0){n=i%s;0!==n&&s-n-a.boundary<0&&(i+=s-n,r.__offset=i)}i+=a.storage}n=i%s,n>0&&(i+=s-n);t.__size=i,t.__cache={}}(i),u=function(e){const i=function(){for(let t=0;t<o;t++)if(-1===a.indexOf(t))return a.push(t),t;return 0}();e.__bindingPointIndex=i;const s=t.createBuffer(),n=e.__size,r=e.usage;return t.bindBuffer(t.UNIFORM_BUFFER,s),t.bufferData(t.UNIFORM_BUFFER,n,r),t.bindBuffer(t.UNIFORM_BUFFER,null),t.bindBufferBase(t.UNIFORM_BUFFER,i,s),s}(i),n[i.id]=u,i.addEventListener("dispose",c));const f=d.program;s.updateUBOMapping(i,f);const p=e.render.frame;r[i.id]!==p&&(!function(e){const i=n[e.id],s=e.uniforms,r=e.__cache;t.bindBuffer(t.UNIFORM_BUFFER,i);for(let e=0,i=s.length;e<i;e++){const i=s[e];if(!0===l(i,e,r)){const e=i.__offset,s=Array.isArray(i.value)?i.value:[i.value];let n=0;for(let r=0;r<s.length;r++){const a=s[r],o=h(a);"number"==typeof a?(i.__data[0]=a,t.bufferSubData(t.UNIFORM_BUFFER,e+n,i.__data)):a.isMatrix3?(i.__data[0]=a.elements[0],i.__data[1]=a.elements[1],i.__data[2]=a.elements[2],i.__data[3]=a.elements[0],i.__data[4]=a.elements[3],i.__data[5]=a.elements[4],i.__data[6]=a.elements[5],i.__data[7]=a.elements[0],i.__data[8]=a.elements[6],i.__data[9]=a.elements[7],i.__data[10]=a.elements[8],i.__data[11]=a.elements[0]):(a.toArray(i.__data,n),n+=o.storage/Float32Array.BYTES_PER_ELEMENT)}t.bufferSubData(t.UNIFORM_BUFFER,e,i.__data)}}t.bindBuffer(t.UNIFORM_BUFFER,null)}(i),r[i.id]=p)},dispose:function(){for(const e in n)t.deleteBuffer(n[e]);a=[],n={},r={}}}}class iz{constructor(t={}){const{canvas:e=II(),context:i=null,depth:s=!0,stencil:n=!0,alpha:r=!1,antialias:a=!1,premultipliedAlpha:o=!0,preserveDrawingBuffer:l=!1,powerPreference:h="default",failIfMajorPerformanceCaveat:c=!1}=t;let d;this.isWebGLRenderer=!0,d=null!==i?i.getContextAttributes().alpha:r;const u=new Uint32Array(4),f=new Int32Array(4);let p=null,m=null;const _=[],g=[];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=KD,this._useLegacyLights=!1,this.toneMapping=0,this.toneMappingExposure=1;const v=this;let S=!1,y=0,x=0,T=null,E=-1,b=null;const w=new KI,A=new KI;let C=null;const M=new TN(0);let P=0,R=e.width,L=e.height,D=1,I=null,O=null;const N=new KI(0,0,R,L),F=new KI(0,0,R,L);let U=!1;const B=new TF;let z=!1,k=!1,V=null;const H=new DO,G=new MI,W=new iO,X={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};function Y(){return null===T?D:1}let q,j,$,K,Z,Q,J,tt,et,it,st,nt,rt,at,ot,lt,ht,ct,dt,ut,ft,pt,mt,_t,gt=i;function vt(t,i){for(let s=0;s<t.length;s++){const n=t[s],r=e.getContext(n,i);if(null!==r)return r}return null}try{const t={alpha:!0,depth:s,stencil:n,antialias:a,premultipliedAlpha:o,preserveDrawingBuffer:l,powerPreference:h,failIfMajorPerformanceCaveat:c};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${sD}`),e.addEventListener("webglcontextlost",xt,!1),e.addEventListener("webglcontextrestored",Tt,!1),e.addEventListener("webglcontextcreationerror",Et,!1),null===gt){const e=["webgl2","webgl","experimental-webgl"];if(!0===v.isWebGL1Renderer&&e.shift(),gt=vt(e,t),null===gt)throw vt(e)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}"undefined"!=typeof WebGLRenderingContext&&WebGLRenderingContext,void 0===gt.getShaderPrecisionFormat&&(gt.getShaderPrecisionFormat=function(){return{rangeMin:1,rangeMax:1,precision:1}})}catch(t){throw t}function St(){q=new QF(gt),j=new IF(gt,q,t),q.init(j),pt=new qB(gt,q,j),$=new XB(gt,q,j),K=new eU(gt),Z=new LB,Q=new YB(gt,q,$,Z,j,pt,K),J=new NF(v),tt=new ZF(v),et=new bF(gt,j),mt=new LF(gt,q,et,j),it=new JF(gt,et,K,mt),st=new rU(gt,it,et,K),dt=new nU(gt,j,Q),lt=new OF(Z),nt=new RB(v,J,tt,q,j,mt,lt),rt=new tz(v,Z),at=new NB,ot=new VB(q,j),ct=new RF(v,J,tt,$,st,d,o),ht=new WB(v,st,j),_t=new ez(gt,K,j,$),ut=new DF(gt,q,K,j),ft=new tU(gt,q,K,j),K.programs=nt.programs,v.capabilities=j,v.extensions=q,v.properties=Z,v.renderLists=at,v.shadowMap=ht,v.state=$,v.info=K}St();const yt=new JB(v,gt);function xt(t){t.preventDefault(),S=!0}function Tt(){S=!1;const t=K.autoReset,e=ht.enabled,i=ht.autoUpdate,s=ht.needsUpdate,n=ht.type;St(),K.autoReset=t,ht.enabled=e,ht.autoUpdate=i,ht.needsUpdate=s,ht.type=n}function Et(t){}function bt(t){const e=t.target;e.removeEventListener("dispose",bt),function(t){(function(t){const e=Z.get(t).programs;void 0!==e&&(e.forEach(function(t){nt.releaseProgram(t)}),t.isShaderMaterial&&nt.releaseShaderCache(t))})(t),Z.remove(t)}(e)}this.xr=yt,this.getContext=function(){return gt},this.getContextAttributes=function(){return gt.getContextAttributes()},this.forceContextLoss=function(){const t=q.get("WEBGL_lose_context");t&&t.loseContext()},this.forceContextRestore=function(){const t=q.get("WEBGL_lose_context");t&&t.restoreContext()},this.getPixelRatio=function(){return D},this.setPixelRatio=function(t){void 0!==t&&(D=t,this.setSize(R,L,!1))},this.getSize=function(t){return t.set(R,L)},this.setSize=function(t,i,s=!0){yt.isPresenting||(R=t,L=i,e.width=Math.floor(t*D),e.height=Math.floor(i*D),!0===s&&(e.style.width=t+"px",e.style.height=i+"px"),this.setViewport(0,0,t,i))},this.getDrawingBufferSize=function(t){return t.set(R*D,L*D).floor()},this.setDrawingBufferSize=function(t,i,s){R=t,L=i,D=s,e.width=Math.floor(t*s),e.height=Math.floor(i*s),this.setViewport(0,0,t,i)},this.getCurrentViewport=function(t){return t.copy(w)},this.getViewport=function(t){return t.copy(N)},this.setViewport=function(t,e,i,s){t.isVector4?N.set(t.x,t.y,t.z,t.w):N.set(t,e,i,s),$.viewport(w.copy(N).multiplyScalar(D).floor())},this.getScissor=function(t){return t.copy(F)},this.setScissor=function(t,e,i,s){t.isVector4?F.set(t.x,t.y,t.z,t.w):F.set(t,e,i,s),$.scissor(A.copy(F).multiplyScalar(D).floor())},this.getScissorTest=function(){return U},this.setScissorTest=function(t){$.setScissorTest(U=t)},this.setOpaqueSort=function(t){I=t},this.setTransparentSort=function(t){O=t},this.getClearColor=function(t){return t.copy(ct.getClearColor())},this.setClearColor=function(){ct.setClearColor.apply(ct,arguments)},this.getClearAlpha=function(){return ct.getClearAlpha()},this.setClearAlpha=function(){ct.setClearAlpha.apply(ct,arguments)},this.clear=function(t=!0,e=!0,i=!0){let s=0;if(t){let t=!1;if(null!==T){const e=T.texture.format;t=1033===e||1031===e||1029===e}if(t){const t=T.texture.type,e=t===ID||t===FD||t===OD||t===zD||1017===t||1018===t,i=ct.getClearColor(),s=ct.getClearAlpha(),n=i.r,r=i.g,a=i.b;e?(u[0]=n,u[1]=r,u[2]=a,u[3]=s,gt.clearBufferuiv(gt.COLOR,0,u)):(f[0]=n,f[1]=r,f[2]=a,f[3]=s,gt.clearBufferiv(gt.COLOR,0,f))}else s|=gt.COLOR_BUFFER_BIT}e&&(s|=gt.DEPTH_BUFFER_BIT),i&&(s|=gt.STENCIL_BUFFER_BIT),gt.clear(s)},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",xt,!1),e.removeEventListener("webglcontextrestored",Tt,!1),e.removeEventListener("webglcontextcreationerror",Et,!1),at.dispose(),ot.dispose(),Z.dispose(),J.dispose(),tt.dispose(),st.dispose(),mt.dispose(),_t.dispose(),nt.dispose(),yt.dispose(),yt.removeEventListener("sessionstart",At),yt.removeEventListener("sessionend",Ct),V&&(V.dispose(),V=null),Mt.stop()},this.renderBufferDirect=function(t,e,i,s,n,r){null===e&&(e=X);const a=n.isMesh&&n.matrixWorld.determinant()<0,o=function(t,e,i,s,n){!0!==e.isScene&&(e=X);Q.resetTextureUnits();const r=e.fog,a=s.isMeshStandardMaterial?e.environment:null,o=null===T?v.outputColorSpace:!0===T.isXRRenderTarget?T.texture.colorSpace:ZD,l=(s.isMeshStandardMaterial?tt:J).get(s.envMap||a),h=!0===s.vertexColors&&!!i.attributes.color&&4===i.attributes.color.itemSize,c=!!i.attributes.tangent&&(!!s.normalMap||s.anisotropy>0),d=!!i.morphAttributes.position,u=!!i.morphAttributes.normal,f=!!i.morphAttributes.color;let p=0;s.toneMapped&&(null!==T&&!0!==T.isXRRenderTarget||(p=v.toneMapping));const _=i.morphAttributes.position||i.morphAttributes.normal||i.morphAttributes.color,g=void 0!==_?_.length:0,S=Z.get(s),y=m.state.lights;if(!0===z&&(!0===k||t!==b)){const e=t===b&&s.id===E;lt.setState(s,t,e)}let x=!1;s.version===S.__version?S.needsLights&&S.lightsStateVersion!==y.state.version||S.outputColorSpace!==o||n.isInstancedMesh&&!1===S.instancing?x=!0:n.isInstancedMesh||!0!==S.instancing?n.isSkinnedMesh&&!1===S.skinning?x=!0:n.isSkinnedMesh||!0!==S.skinning?n.isInstancedMesh&&!0===S.instancingColor&&null===n.instanceColor||n.isInstancedMesh&&!1===S.instancingColor&&null!==n.instanceColor||S.envMap!==l||!0===s.fog&&S.fog!==r?x=!0:void 0===S.numClippingPlanes||S.numClippingPlanes===lt.numPlanes&&S.numIntersection===lt.numIntersection?(S.vertexAlphas!==h||S.vertexTangents!==c||S.morphTargets!==d||S.morphNormals!==u||S.morphColors!==f||S.toneMapping!==p||!0===j.isWebGL2&&S.morphTargetsCount!==g)&&(x=!0):x=!0:x=!0:x=!0:(x=!0,S.__version=s.version);let w=S.currentProgram;!0===x&&(w=It(s,e,n));let A=!1,C=!1,M=!1;const P=w.getUniforms(),R=S.uniforms;$.useProgram(w.program)&&(A=!0,C=!0,M=!0);s.id!==E&&(E=s.id,C=!0);if(A||b!==t){P.setValue(gt,"projectionMatrix",t.projectionMatrix),P.setValue(gt,"viewMatrix",t.matrixWorldInverse);const e=P.map.cameraPosition;void 0!==e&&e.setValue(gt,W.setFromMatrixPosition(t.matrixWorld)),j.logarithmicDepthBuffer&&P.setValue(gt,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),(s.isMeshPhongMaterial||s.isMeshToonMaterial||s.isMeshLambertMaterial||s.isMeshBasicMaterial||s.isMeshStandardMaterial||s.isShaderMaterial)&&P.setValue(gt,"isOrthographic",!0===t.isOrthographicCamera),b!==t&&(b=t,C=!0,M=!0)}if(n.isSkinnedMesh){P.setOptional(gt,n,"bindMatrix"),P.setOptional(gt,n,"bindMatrixInverse");const t=n.skeleton;t&&j.floatVertexTextures&&(null===t.boneTexture&&t.computeBoneTexture(),P.setValue(gt,"boneTexture",t.boneTexture,Q),P.setValue(gt,"boneTextureSize",t.boneTextureSize))}const I=i.morphAttributes;(void 0!==I.position||void 0!==I.normal||void 0!==I.color&&!0===j.isWebGL2)&&dt.update(n,i,w);(C||S.receiveShadow!==n.receiveShadow)&&(S.receiveShadow=n.receiveShadow,P.setValue(gt,"receiveShadow",n.receiveShadow));s.isMeshGouraudMaterial&&null!==s.envMap&&(R.envMap.value=l,R.flipEnvMap.value=l.isCubeTexture&&!1===l.isRenderTargetTexture?-1:1);C&&(P.setValue(gt,"toneMappingExposure",v.toneMappingExposure),S.needsLights&&(N=M,(O=R).ambientLightColor.needsUpdate=N,O.lightProbe.needsUpdate=N,O.directionalLights.needsUpdate=N,O.directionalLightShadows.needsUpdate=N,O.pointLights.needsUpdate=N,O.pointLightShadows.needsUpdate=N,O.spotLights.needsUpdate=N,O.spotLightShadows.needsUpdate=N,O.rectAreaLights.needsUpdate=N,O.hemisphereLights.needsUpdate=N),r&&!0===s.fog&&rt.refreshFogUniforms(R,r),rt.refreshMaterialUniforms(R,s,D,L,V),hB.upload(gt,S.uniformsList,R,Q));var O,N;s.isShaderMaterial&&!0===s.uniformsNeedUpdate&&(hB.upload(gt,S.uniformsList,R,Q),s.uniformsNeedUpdate=!1);s.isSpriteMaterial&&P.setValue(gt,"center",n.center);if(P.setValue(gt,"modelViewMatrix",n.modelViewMatrix),P.setValue(gt,"normalMatrix",n.normalMatrix),P.setValue(gt,"modelMatrix",n.matrixWorld),s.isShaderMaterial||s.isRawShaderMaterial){const t=s.uniformsGroups;for(let e=0,i=t.length;e<i;e++)if(j.isWebGL2){const i=t[e];_t.update(i,w),_t.bind(i,w)}}return w}(t,e,i,s,n);$.setMaterial(s,a);let l=i.index,h=1;if(!0===s.wireframe){if(l=it.getWireframeAttribute(i),void 0===l)return;h=2}const c=i.drawRange,d=i.attributes.position;let u=c.start*h,f=(c.start+c.count)*h;null!==r&&(u=Math.max(u,r.start*h),f=Math.min(f,(r.start+r.count)*h)),null!==l?(u=Math.max(u,0),f=Math.min(f,l.count)):null!=d&&(u=Math.max(u,0),f=Math.min(f,d.count));const p=f-u;if(p<0||p===1/0)return;let _;mt.setup(n,s,o,i,l);let g=ut;if(null!==l&&(_=et.get(l),g=ft,g.setIndex(_)),n.isMesh)!0===s.wireframe?($.setLineWidth(s.wireframeLinewidth*Y()),g.setMode(gt.LINES)):g.setMode(gt.TRIANGLES);else if(n.isLine){let t=s.linewidth;void 0===t&&(t=1),$.setLineWidth(t*Y()),n.isLineSegments?g.setMode(gt.LINES):n.isLineLoop?g.setMode(gt.LINE_LOOP):g.setMode(gt.LINE_STRIP)}else n.isPoints?g.setMode(gt.POINTS):n.isSprite&&g.setMode(gt.TRIANGLES);if(n.isInstancedMesh)g.renderInstances(u,p,n.count);else if(i.isInstancedBufferGeometry){const t=void 0!==i._maxInstanceCount?i._maxInstanceCount:1/0,e=Math.min(i.instanceCount,t);g.renderInstances(u,p,e)}else g.render(u,p)},this.compile=function(t,e){function i(t,e,i){!0===t.transparent&&2===t.side&&!1===t.forceSinglePass?(t.side=1,t.needsUpdate=!0,It(t,e,i),t.side=0,t.needsUpdate=!0,It(t,e,i),t.side=2):It(t,e,i)}m=ot.get(t),m.init(),g.push(m),t.traverseVisible(function(t){t.isLight&&t.layers.test(e.layers)&&(m.pushLight(t),t.castShadow&&m.pushShadow(t))}),m.setupLights(v._useLegacyLights),t.traverse(function(e){const s=e.material;if(s)if(Array.isArray(s))for(let n=0;n<s.length;n++){i(s[n],t,e)}else i(s,t,e)}),g.pop(),m=null};let wt=null;function At(){Mt.stop()}function Ct(){Mt.start()}const Mt=new EF;function Pt(t,e,i,s){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)i=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)m.pushLight(t),t.castShadow&&m.pushShadow(t);else if(t.isSprite){if(!t.frustumCulled||B.intersectsSprite(t)){s&&W.setFromMatrixPosition(t.matrixWorld).applyMatrix4(H);const e=st.update(t),n=t.material;n.visible&&p.push(t,e,n,i,W.z,null)}}else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||B.intersectsObject(t))){const e=st.update(t),n=t.material;if(s&&(void 0!==t.boundingSphere?(null===t.boundingSphere&&t.computeBoundingSphere(),W.copy(t.boundingSphere.center)):(null===e.boundingSphere&&e.computeBoundingSphere(),W.copy(e.boundingSphere.center)),W.applyMatrix4(t.matrixWorld).applyMatrix4(H)),Array.isArray(n)){const s=e.groups;for(let r=0,a=s.length;r<a;r++){const a=s[r],o=n[a.materialIndex];o&&o.visible&&p.push(t,e,o,i,W.z,a)}}else n.visible&&p.push(t,e,n,i,W.z,null)}const n=t.children;for(let t=0,r=n.length;t<r;t++)Pt(n[t],e,i,s)}function Rt(t,e,i,s){const n=t.opaque,r=t.transmissive,a=t.transparent;m.setupLightsView(i),!0===z&<.setGlobalState(v.clippingPlanes,i),r.length>0&&function(t,e,i,s){const n=j.isWebGL2;null===V&&(V=new QI(1,1,{generateMipmaps:!0,type:q.has("EXT_color_buffer_half_float")?BD:ID,minFilter:DD,samples:n?4:0}));v.getDrawingBufferSize(G),n?V.setSize(G.x,G.y):V.setSize(wI(G.x),wI(G.y));const r=v.getRenderTarget();v.setRenderTarget(V),v.getClearColor(M),P=v.getClearAlpha(),P<1&&v.setClearColor(16777215,.5);v.clear();const a=v.toneMapping;v.toneMapping=0,Lt(t,i,s),Q.updateMultisampleRenderTarget(V),Q.updateRenderTargetMipmap(V);let o=!1;for(let t=0,n=e.length;t<n;t++){const n=e[t],r=n.object,a=n.geometry,l=n.material,h=n.group;if(2===l.side&&r.layers.test(s.layers)){const t=l.side;l.side=1,l.needsUpdate=!0,Dt(r,i,s,a,l,h),l.side=t,l.needsUpdate=!0,o=!0}}!0===o&&(Q.updateMultisampleRenderTarget(V),Q.updateRenderTargetMipmap(V));v.setRenderTarget(r),v.setClearColor(M,P),v.toneMapping=a}(n,r,e,i),s&&$.viewport(w.copy(s)),n.length>0&&Lt(n,e,i),r.length>0&&Lt(r,e,i),a.length>0&&Lt(a,e,i),$.buffers.depth.setTest(!0),$.buffers.depth.setMask(!0),$.buffers.color.setMask(!0),$.setPolygonOffset(!1)}function Lt(t,e,i){const s=!0===e.isScene?e.overrideMaterial:null;for(let n=0,r=t.length;n<r;n++){const r=t[n],a=r.object,o=r.geometry,l=null===s?r.material:s,h=r.group;a.layers.test(i.layers)&&Dt(a,e,i,o,l,h)}}function Dt(t,e,i,s,n,r){t.onBeforeRender(v,e,i,s,n,r),t.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix),n.onBeforeRender(v,e,i,s,t,r),!0===n.transparent&&2===n.side&&!1===n.forceSinglePass?(n.side=1,n.needsUpdate=!0,v.renderBufferDirect(i,e,s,n,t,r),n.side=0,n.needsUpdate=!0,v.renderBufferDirect(i,e,s,n,t,r),n.side=2):v.renderBufferDirect(i,e,s,n,t,r),t.onAfterRender(v,e,i,s,n,r)}function It(t,e,i){!0!==e.isScene&&(e=X);const s=Z.get(t),n=m.state.lights,r=m.state.shadowsArray,a=n.state.version,o=nt.getParameters(t,n.state,r,e,i),l=nt.getProgramCacheKey(o);let h=s.programs;s.environment=t.isMeshStandardMaterial?e.environment:null,s.fog=e.fog,s.envMap=(t.isMeshStandardMaterial?tt:J).get(t.envMap||s.environment),void 0===h&&(t.addEventListener("dispose",bt),h=new Map,s.programs=h);let c=h.get(l);if(void 0!==c){if(s.currentProgram===c&&s.lightsStateVersion===a)return Ot(t,o),c}else o.uniforms=nt.getUniforms(t),t.onBuild(i,o,v),t.onBeforeCompile(o,v),c=nt.acquireProgram(o,l),h.set(l,c),s.uniforms=o.uniforms;const d=s.uniforms;(t.isShaderMaterial||t.isRawShaderMaterial)&&!0!==t.clipping||(d.clippingPlanes=lt.uniform),Ot(t,o),s.needsLights=function(t){return t.isMeshLambertMaterial||t.isMeshToonMaterial||t.isMeshPhongMaterial||t.isMeshStandardMaterial||t.isShadowMaterial||t.isShaderMaterial&&!0===t.lights}(t),s.lightsStateVersion=a,s.needsLights&&(d.ambientLightColor.value=n.state.ambient,d.lightProbe.value=n.state.probe,d.directionalLights.value=n.state.directional,d.directionalLightShadows.value=n.state.directionalShadow,d.spotLights.value=n.state.spot,d.spotLightShadows.value=n.state.spotShadow,d.rectAreaLights.value=n.state.rectArea,d.ltc_1.value=n.state.rectAreaLTC1,d.ltc_2.value=n.state.rectAreaLTC2,d.pointLights.value=n.state.point,d.pointLightShadows.value=n.state.pointShadow,d.hemisphereLights.value=n.state.hemi,d.directionalShadowMap.value=n.state.directionalShadowMap,d.directionalShadowMatrix.value=n.state.directionalShadowMatrix,d.spotShadowMap.value=n.state.spotShadowMap,d.spotLightMatrix.value=n.state.spotLightMatrix,d.spotLightMap.value=n.state.spotLightMap,d.pointShadowMap.value=n.state.pointShadowMap,d.pointShadowMatrix.value=n.state.pointShadowMatrix);const u=c.getUniforms(),f=hB.seqWithValue(u.seq,d);return s.currentProgram=c,s.uniformsList=f,c}function Ot(t,e){const i=Z.get(t);i.outputColorSpace=e.outputColorSpace,i.instancing=e.instancing,i.instancingColor=e.instancingColor,i.skinning=e.skinning,i.morphTargets=e.morphTargets,i.morphNormals=e.morphNormals,i.morphColors=e.morphColors,i.morphTargetsCount=e.morphTargetsCount,i.numClippingPlanes=e.numClippingPlanes,i.numIntersection=e.numClipIntersection,i.vertexAlphas=e.vertexAlphas,i.vertexTangents=e.vertexTangents,i.toneMapping=e.toneMapping}Mt.setAnimationLoop(function(t){wt&&wt(t)}),"undefined"!=typeof self&&Mt.setContext(self),this.setAnimationLoop=function(t){wt=t,yt.setAnimationLoop(t),null===t?Mt.stop():Mt.start()},yt.addEventListener("sessionstart",At),yt.addEventListener("sessionend",Ct),this.render=function(t,e){if(void 0!==e&&!0!==e.isCamera)return;if(!0===S)return;!0===t.matrixWorldAutoUpdate&&t.updateMatrixWorld(),null===e.parent&&!0===e.matrixWorldAutoUpdate&&e.updateMatrixWorld(),!0===yt.enabled&&!0===yt.isPresenting&&(!0===yt.cameraAutoUpdate&&yt.updateCamera(e),e=yt.getCamera()),!0===t.isScene&&t.onBeforeRender(v,t,e,T),m=ot.get(t,g.length),m.init(),g.push(m),H.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),B.setFromProjectionMatrix(H),k=this.localClippingEnabled,z=lt.init(this.clippingPlanes,k),p=at.get(t,_.length),p.init(),_.push(p),Pt(t,e,0,v.sortObjects),p.finish(),!0===v.sortObjects&&p.sort(I,O),this.info.render.frame++,!0===z&<.beginShadows();const i=m.state.shadowsArray;if(ht.render(i,t,e),!0===z&<.endShadows(),!0===this.info.autoReset&&this.info.reset(),ct.render(p,t),m.setupLights(v._useLegacyLights),e.isArrayCamera){const i=e.cameras;for(let e=0,s=i.length;e<s;e++){const s=i[e];Rt(p,t,s,s.viewport)}}else Rt(p,t,e);null!==T&&(Q.updateMultisampleRenderTarget(T),Q.updateRenderTargetMipmap(T)),!0===t.isScene&&t.onAfterRender(v,t,e),mt.resetDefaultState(),E=-1,b=null,g.pop(),m=g.length>0?g[g.length-1]:null,_.pop(),p=_.length>0?_[_.length-1]:null},this.getActiveCubeFace=function(){return y},this.getActiveMipmapLevel=function(){return x},this.getRenderTarget=function(){return T},this.setRenderTargetTextures=function(t,e,i){Z.get(t.texture).__webglTexture=e,Z.get(t.depthTexture).__webglTexture=i;const s=Z.get(t);s.__hasExternalTextures=!0,s.__hasExternalTextures&&(s.__autoAllocateDepthBuffer=void 0===i,s.__autoAllocateDepthBuffer||!0===q.has("WEBGL_multisampled_render_to_texture")&&(s.__useRenderToTexture=!1))},this.setRenderTargetFramebuffer=function(t,e){const i=Z.get(t);i.__webglFramebuffer=e,i.__useDefaultFramebuffer=void 0===e},this.setRenderTarget=function(t,e=0,i=0){T=t,y=e,x=i;let s=!0,n=null,r=!1,a=!1;if(t){const o=Z.get(t);void 0!==o.__useDefaultFramebuffer?($.bindFramebuffer(gt.FRAMEBUFFER,null),s=!1):void 0===o.__webglFramebuffer?Q.setupRenderTarget(t):o.__hasExternalTextures&&Q.rebindTextures(t,Z.get(t.texture).__webglTexture,Z.get(t.depthTexture).__webglTexture);const l=t.texture;(l.isData3DTexture||l.isDataArrayTexture||l.isCompressedArrayTexture)&&(a=!0);const h=Z.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(n=Array.isArray(h[e])?h[e][i]:h[e],r=!0):n=j.isWebGL2&&t.samples>0&&!1===Q.useMultisampledRTT(t)?Z.get(t).__webglMultisampledFramebuffer:Array.isArray(h)?h[i]:h,w.copy(t.viewport),A.copy(t.scissor),C=t.scissorTest}else w.copy(N).multiplyScalar(D).floor(),A.copy(F).multiplyScalar(D).floor(),C=U;if($.bindFramebuffer(gt.FRAMEBUFFER,n)&&j.drawBuffers&&s&&$.drawBuffers(t,n),$.viewport(w),$.scissor(A),$.setScissorTest(C),r){const s=Z.get(t.texture);gt.framebufferTexture2D(gt.FRAMEBUFFER,gt.COLOR_ATTACHMENT0,gt.TEXTURE_CUBE_MAP_POSITIVE_X+e,s.__webglTexture,i)}else if(a){const s=Z.get(t.texture),n=e||0;gt.framebufferTextureLayer(gt.FRAMEBUFFER,gt.COLOR_ATTACHMENT0,s.__webglTexture,i||0,n)}E=-1},this.readRenderTargetPixels=function(t,e,i,s,n,r,a){if(!t||!t.isWebGLRenderTarget)return;let o=Z.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(o=o[a]),o){$.bindFramebuffer(gt.FRAMEBUFFER,o);try{const a=t.texture,o=a.format,l=a.type;if(o!==kD&&pt.convert(o)!==gt.getParameter(gt.IMPLEMENTATION_COLOR_READ_FORMAT))return;const h=l===BD&&(q.has("EXT_color_buffer_half_float")||j.isWebGL2&&q.has("EXT_color_buffer_float"));if(!(l===ID||pt.convert(l)===gt.getParameter(gt.IMPLEMENTATION_COLOR_READ_TYPE)||l===UD&&(j.isWebGL2||q.has("OES_texture_float")||q.has("WEBGL_color_buffer_float"))||h))return;e>=0&&e<=t.width-s&&i>=0&&i<=t.height-n&>.readPixels(e,i,s,n,pt.convert(o),pt.convert(l),r)}finally{const t=null!==T?Z.get(T).__webglFramebuffer:null;$.bindFramebuffer(gt.FRAMEBUFFER,t)}}},this.copyFramebufferToTexture=function(t,e,i=0){const s=Math.pow(2,-i),n=Math.floor(e.image.width*s),r=Math.floor(e.image.height*s);Q.setTexture2D(e,0),gt.copyTexSubImage2D(gt.TEXTURE_2D,i,0,0,t.x,t.y,n,r),$.unbindTexture()},this.copyTextureToTexture=function(t,e,i,s=0){const n=e.image.width,r=e.image.height,a=pt.convert(i.format),o=pt.convert(i.type);Q.setTexture2D(i,0),gt.pixelStorei(gt.UNPACK_FLIP_Y_WEBGL,i.flipY),gt.pixelStorei(gt.UNPACK_PREMULTIPLY_ALPHA_WEBGL,i.premultiplyAlpha),gt.pixelStorei(gt.UNPACK_ALIGNMENT,i.unpackAlignment),e.isDataTexture?gt.texSubImage2D(gt.TEXTURE_2D,s,t.x,t.y,n,r,a,o,e.image.data):e.isCompressedTexture?gt.compressedTexSubImage2D(gt.TEXTURE_2D,s,t.x,t.y,e.mipmaps[0].width,e.mipmaps[0].height,a,e.mipmaps[0].data):gt.texSubImage2D(gt.TEXTURE_2D,s,t.x,t.y,a,o,e.image),0===s&&i.generateMipmaps&>.generateMipmap(gt.TEXTURE_2D),$.unbindTexture()},this.copyTextureToTexture3D=function(t,e,i,s,n=0){if(v.isWebGL1Renderer)return;const r=t.max.x-t.min.x+1,a=t.max.y-t.min.y+1,o=t.max.z-t.min.z+1,l=pt.convert(s.format),h=pt.convert(s.type);let c;if(s.isData3DTexture)Q.setTexture3D(s,0),c=gt.TEXTURE_3D;else{if(!s.isDataArrayTexture)return;Q.setTexture2DArray(s,0),c=gt.TEXTURE_2D_ARRAY}gt.pixelStorei(gt.UNPACK_FLIP_Y_WEBGL,s.flipY),gt.pixelStorei(gt.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s.premultiplyAlpha),gt.pixelStorei(gt.UNPACK_ALIGNMENT,s.unpackAlignment);const d=gt.getParameter(gt.UNPACK_ROW_LENGTH),u=gt.getParameter(gt.UNPACK_IMAGE_HEIGHT),f=gt.getParameter(gt.UNPACK_SKIP_PIXELS),p=gt.getParameter(gt.UNPACK_SKIP_ROWS),m=gt.getParameter(gt.UNPACK_SKIP_IMAGES),_=i.isCompressedTexture?i.mipmaps[0]:i.image;gt.pixelStorei(gt.UNPACK_ROW_LENGTH,_.width),gt.pixelStorei(gt.UNPACK_IMAGE_HEIGHT,_.height),gt.pixelStorei(gt.UNPACK_SKIP_PIXELS,t.min.x),gt.pixelStorei(gt.UNPACK_SKIP_ROWS,t.min.y),gt.pixelStorei(gt.UNPACK_SKIP_IMAGES,t.min.z),i.isDataTexture||i.isData3DTexture?gt.texSubImage3D(c,n,e.x,e.y,e.z,r,a,o,l,h,_.data):i.isCompressedArrayTexture?gt.compressedTexSubImage3D(c,n,e.x,e.y,e.z,r,a,o,l,_.data):gt.texSubImage3D(c,n,e.x,e.y,e.z,r,a,o,l,h,_),gt.pixelStorei(gt.UNPACK_ROW_LENGTH,d),gt.pixelStorei(gt.UNPACK_IMAGE_HEIGHT,u),gt.pixelStorei(gt.UNPACK_SKIP_PIXELS,f),gt.pixelStorei(gt.UNPACK_SKIP_ROWS,p),gt.pixelStorei(gt.UNPACK_SKIP_IMAGES,m),0===n&&s.generateMipmaps&>.generateMipmap(c),$.unbindTexture()},this.initTexture=function(t){t.isCubeTexture?Q.setTextureCube(t,0):t.isData3DTexture?Q.setTexture3D(t,0):t.isDataArrayTexture||t.isCompressedArrayTexture?Q.setTexture2DArray(t,0):Q.setTexture2D(t,0),$.unbindTexture()},this.resetState=function(){y=0,x=0,T=null,$.reset(),mt.reset()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return mI}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(t){this._outputColorSpace=t;const e=this.getContext();e.drawingBufferColorSpace=t===QD?"display-p3":"srgb",e.unpackColorSpace=kI.workingColorSpace===JD?"display-p3":"srgb"}get physicallyCorrectLights(){return!this.useLegacyLights}set physicallyCorrectLights(t){this.useLegacyLights=!t}get outputEncoding(){return this.outputColorSpace===KD?jD:3e3}set outputEncoding(t){this.outputColorSpace=t===jD?KD:ZD}get useLegacyLights(){return this._useLegacyLights}set useLegacyLights(t){this._useLegacyLights=t}}(class extends iz{}).prototype.isWebGL1Renderer=!0;class sz extends sN{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,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,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}}class nz extends gN{constructor(t){super(),this.isMeshStandardMaterial=!0,this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new TN(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 TN(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new MI(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,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.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 rz extends sN{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new TN(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()),e}}const az=new DO,oz=new iO,lz=new iO;class hz{constructor(t){this.camera=t,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new MI(512,512),this.map=null,this.mapPass=null,this.matrix=new DO,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new TF,this._frameExtents=new MI(1,1),this._viewportCount=1,this._viewports=[new KI(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,i=this.matrix;oz.setFromMatrixPosition(t.matrixWorld),e.position.copy(oz),lz.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(lz),e.updateMatrixWorld(),az.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(az),i.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),i.multiply(az)}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.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this}clone(){return(new this.constructor).copy(this)}toJSON(){const t={};return 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 cz extends hz{constructor(){super(new FF(-5,5,5,-5,.5,500)),this.isDirectionalLightShadow=!0}}class dz extends rz{constructor(t,e){super(t,e),this.isDirectionalLight=!0,this.type="DirectionalLight",this.position.copy(sN.DEFAULT_UP),this.updateMatrix(),this.target=new sN,this.shadow=new cz}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class uz extends rz{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}}"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:sD}})),"undefined"!=typeof window&&(window.__THREE__||(window.__THREE__=sD));class fz{constructor(t){this.scene=null,this.camera=null,this.renderer=null,this.cube=null,this.directionalLight=null,this.ambientLight=null,this.canvas=null,this.initialized=!1,this.visible=!0,this.animationFrameId=null,this.needsRender=!1,this.resizeObserver=null,this.config=t}initialize(t){try{this.canvas=t,this.scene=new sz,this.scene.background=null;const e=t.clientWidth||t.width,i=e/(t.clientHeight||t.height)||1,s=4.5;this.camera=new FF(s*i/-2,s*i/2,s/2,s/-2,.1,1e3),this.camera.position.set(5,0,0),this.camera.lookAt(0,0,0),this.camera.updateProjectionMatrix(),this.renderer=new iz({canvas:t,alpha:!0,antialias:!0});const n=t.clientWidth||t.width,r=t.clientHeight||t.height;if(this.renderer.setSize(n,r,!1),this.renderer.setPixelRatio(window.devicePixelRatio||1),!this.renderer.getContext())throw new Error("Failed to create WebGL context");const a=new nF(1,1,1),o=new nz({color:11184810,metalness:.7,roughness:.3,emissive:1710623,emissiveIntensity:.1});this.cube=new iF(a,o),this.cube.position.set(0,0,0),this.scene.add(this.cube),this.directionalLight=new dz(16777215,2.2),this.directionalLight.position.set(2,3,2),this.scene.add(this.directionalLight);const l=new dz(16777215,.8);l.position.set(-1,.5,-1),this.scene.add(l);const h=new dz(16777215,1.2);h.position.set(-2,-1.5,2),this.scene.add(h);const c=new dz(16777215,1.2);c.position.set(2,-1.5,2),this.scene.add(c);const d=new dz(16777215,.4);d.position.set(0,-1,-2),this.scene.add(d),this.ambientLight=new uz(13421789,.35),this.scene.add(this.ambientLight),this.setupResizeObserver(),this.requestRender(),this.initialized=!0}catch(t){throw this.initialized=!1,this.cleanup(),t}}setRotation(t,e){if(!this.initialized||!this.camera)return;if(!isFinite(t)||!isFinite(e))return;const i=t*(Math.PI/180),s=e*(Math.PI/180),n=5*Math.sin(s)*Math.cos(i),r=5*Math.sin(i),a=5*Math.cos(s)*Math.cos(i);this.camera.position.set(n,r,a),this.camera.lookAt(0,0,0),this.requestRender()}setVisible(t){this.visible=t,this.canvas&&(this.canvas.style.display=t?"block":"none",t&&this.initialized&&this.requestRender())}setupResizeObserver(){this.canvas&&(this.resizeObserver=new ResizeObserver(t=>{for(const e of t){const{width:t,height:i}=e.contentRect;this.onCanvasResize(t,i)}}),this.resizeObserver.observe(this.canvas))}onCanvasResize(t,e){if(!this.camera||!this.renderer)return;const i=t/e||1,s=4.5;this.camera.left=s*i/-2,this.camera.right=s*i/2,this.camera.top=2.25,this.camera.bottom=-2.25,this.camera.updateProjectionMatrix(),this.renderer.setSize(t,e,!1),this.requestRender()}requestRender(){this.needsRender||(this.needsRender=!0,this.animationFrameId=requestAnimationFrame(()=>{this.render(),this.needsRender=!1,this.animationFrameId=null}))}render(){this.initialized&&this.visible&&this.scene&&this.camera&&this.renderer&&this.renderer.render(this.scene,this.camera)}cleanup(){null!==this.animationFrameId&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.needsRender=!1,this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.cube&&(this.cube.geometry&&this.cube.geometry.dispose(),this.cube.material&&(Array.isArray(this.cube.material)?this.cube.material.forEach(t=>t.dispose()):this.cube.material.dispose()),this.cube=null),this.scene&&(this.scene.clear(),this.scene=null),this.renderer&&(this.renderer.dispose(),this.renderer=null),this.camera=null,this.directionalLight=null,this.ambientLight=null,this.canvas=null}destroy(){this.cleanup(),this.initialized=!1}isInitialized(){return this.initialized}isVisible(){return this.visible}}class pz{constructor(t,e){this.cubeEntity=null,this.cubeMaterial=null,this.cubeCamera=null,this.directionalLight=null,this.ambientLight=null,this.cubeRoot=null,this.initialized=!1,this.visible=!0,this.MIN_CANVAS_SIZE=200,this.MIN_PARENT_DIV_SIZE=100,this.cubeLayer=null,this.separateCanvas=null,this.parentDiv=null,this.resizeObserver=null,this.useParentDiv=!1,this.onResizeCallback=null,this.threeJsRenderer=null,this.useThreeJs=!1,this.mainApp=t,this.app=t,this.config=e,this.useParentDiv=!!e.parentElementId}initialize(){if(!this.initialized)try{this.useParentDiv&&this.config.parentElementId?this.initializeInParentDiv():this.initializeInMainCanvas(),this.initialized=!0}catch(t){throw this.cleanup(),t}}initializeInMainCanvas(){this.setupCubeLayer(),this.cubeRoot=new U_("NavigationCubeRoot"),this.app.root.addChild(this.cubeRoot),this.cubeMaterial=this.createCubeMaterial(),this.cubeEntity=this.createCubeGeometry(),this.cubeCamera=this.setupCubeCamera(),this.setupCubeLighting(),this.updateViewport()}initializeInParentDiv(){const t=this.config.parentElementId;if(this.parentDiv=document.getElementById(t),!this.parentDiv)return this.useParentDiv=!1,void this.initializeInMainCanvas();const e=this.parentDiv.querySelector("#navigation-cube-canvas");e&&e.remove(),this.separateCanvas=document.createElement("canvas"),this.separateCanvas.id="navigation-cube-canvas",this.separateCanvas.style.width="100%",this.separateCanvas.style.height="100%",this.separateCanvas.style.display="block",this.separateCanvas.style.position="absolute",this.separateCanvas.style.top="0",this.separateCanvas.style.left="0",this.parentDiv.appendChild(this.separateCanvas);const i=this.parentDiv.getBoundingClientRect();this.separateCanvas.width=Math.floor(i.width),this.separateCanvas.height=Math.floor(i.height);try{this.threeJsRenderer=new fz(this.config),this.threeJsRenderer.initialize(this.separateCanvas),this.useThreeJs=!0,this.useParentDiv=!0}catch(t){return this.useParentDiv=!1,this.useThreeJs=!1,this.app=this.mainApp,void this.initializeInMainCanvas()}}setupCubeLayer(){this.cubeLayer=new tu({name:"NavigationCubeLayer",opaqueSortMode:0,transparentSortMode:0});this.app.scene.layers.push(this.cubeLayer)}createCubeGeometry(){const t=new U_("NavigationCube");return t.addComponent("render",{type:"box",material:this.cubeMaterial,castShadows:!1,receiveShadows:!1,layers:[this.cubeLayer.id]}),t.setLocalPosition(0,0,0),this.cubeRoot.addChild(t),t}createCubeMaterial(){const t=new Gp;return t.diffuse=new H(.6,.6,.65),t.metalness=.5,t.gloss=.5,t.useMetalness=!0,t.emissive=new H(.1,.1,.12),t.emissiveIntensity=.15,t.update(),t}setupCubeCamera(){const t=new U_("NavigationCubeCamera"),e=this.useParentDiv,i=new H(0,0,0,e?1:0);return t.addComponent("camera",{projection:1,orthoHeight:1.5,clearColor:i,clearColorBuffer:e,clearDepthBuffer:!0,priority:100,farClip:100,nearClip:.1,layers:[this.cubeLayer.id]}),t.setLocalPosition(0,0,5),t.lookAt(0,0,0),this.cubeRoot.addChild(t),t}setupCubeLighting(){this.directionalLight=new U_("CubeDirectionalLight");const t={type:"directional",color:new H(1,1,1),intensity:1.5,castShadows:!1};this.cubeLayer&&(t.layers=[this.cubeLayer.id]),this.directionalLight.addComponent("light",t),this.directionalLight.setLocalEulerAngles(45,45,0),this.cubeCamera.addChild(this.directionalLight),this.ambientLight=new U_("CubeAmbientLight");const e={type:"directional",color:new H(.8,.8,.85),intensity:.7,castShadows:!1};this.cubeLayer&&(e.layers=[this.cubeLayer.id]),this.ambientLight.addComponent("light",e),this.ambientLight.setLocalEulerAngles(-45,-135,0),this.cubeCamera.addChild(this.ambientLight)}setRotation(t,e){if(this.initialized)if(this.useThreeJs&&this.threeJsRenderer)this.threeJsRenderer.setRotation(t,e);else if(this.cubeCamera&&"number"==typeof t&&"number"==typeof e)try{const i=5,s=t*(Math.PI/180),n=e*(Math.PI/180),r=i*Math.sin(n)*Math.cos(s),a=i*Math.sin(s),o=i*Math.cos(n)*Math.cos(s);this.cubeCamera.setLocalPosition(r,a,o),this.cubeCamera.lookAt(0,0,0)}catch(t){}}render(){this.initialized&&this.visible&&this.useThreeJs}setVisible(t){this.visible=t,this.useThreeJs&&this.threeJsRenderer?this.threeJsRenderer.setVisible(t):this.initialized&&this.cubeRoot&&(this.cubeRoot.enabled=t)}isVisible(){return this.visible}updateSize(t){if("number"!=typeof t||!isFinite(t))return;const e=Math.max(50,Math.min(500,t));this.config.cubeSize=e,this.initialized&&this.cubeCamera&&this.updateViewport()}shouldShowCube(){if(this.useParentDiv&&this.parentDiv){const t=this.parentDiv.clientWidth,e=this.parentDiv.clientHeight;return t>=this.MIN_PARENT_DIV_SIZE&&e>=this.MIN_PARENT_DIV_SIZE}const t=this.app.graphicsDevice.canvas;if(!t)return!1;const e=t.width,i=t.height;return e>=this.MIN_CANVAS_SIZE&&i>=this.MIN_CANVAS_SIZE}updateViewport(){if(!this.cubeCamera||!this.cubeCamera.camera)return;const t=this.app.graphicsDevice.canvas;if(!t)return;const e=t.width,i=t.height;if(e<=0||i<=0)return;if(!this.shouldShowCube())return void(this.cubeRoot&&(this.cubeRoot.enabled=!1));this.cubeRoot&&!this.cubeRoot.enabled&&this.visible&&(this.cubeRoot.enabled=!0);const s=this.config.cubeSize;let n=s/e,r=s/i,a=1-n-this.config.padding.x/e,o=1-r-this.config.padding.y/i;a=Math.max(0,Math.min(a,1-n)),o=Math.max(0,Math.min(o,1-r)),n=Math.max(0,Math.min(n,1-a)),r=Math.max(0,Math.min(r,1-o)),this.cubeCamera.camera.rect=new J(a,o,n,r)}onCanvasResize(){this.initialized&&(this.updateViewport(),this.onResizeCallback&&this.onResizeCallback())}setResizeCallback(t){this.onResizeCallback=t}cleanup(){if(this.threeJsRenderer&&(this.threeJsRenderer.destroy(),this.threeJsRenderer=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.ambientLight&&(this.ambientLight.destroy(),this.ambientLight=null),this.directionalLight&&(this.directionalLight.destroy(),this.directionalLight=null),this.cubeCamera&&(this.cubeCamera.destroy(),this.cubeCamera=null),this.cubeEntity&&(this.cubeEntity.destroy(),this.cubeEntity=null),this.cubeMaterial&&(this.cubeMaterial.destroy(),this.cubeMaterial=null),this.cubeRoot&&(this.cubeRoot.destroy(),this.cubeRoot=null),this.cubeLayer){const t=this.app.scene.layers,e=t.getLayerById(this.cubeLayer.id);e&&t.remove(e),this.cubeLayer=null}this.useParentDiv&&this.separateCanvas&&(this.separateCanvas.parentElement&&this.separateCanvas.parentElement.removeChild(this.separateCanvas),this.separateCanvas=null,this.parentDiv=null),this.app=this.mainApp,this.initialized=!1}destroy(){if(this.initialized)try{this.cleanup()}catch(t){this.initialized=!1}}isInitialized(){return this.initialized}getMinimumCanvasSize(){return this.useParentDiv?this.MIN_PARENT_DIV_SIZE:this.MIN_CANVAS_SIZE}isVisibleOnCanvas(){return this.visible&&this.initialized&&this.shouldShowCube()}getCanvasDimensions(){const t=this.app.graphicsDevice.canvas;return t?{width:t.width,height:t.height}:null}getViewport(){if(!this.cubeCamera||!this.cubeCamera.camera)return null;if(this.useParentDiv)return{x:0,y:0,width:1,height:1};const t=this.cubeCamera.camera.rect;return{x:t.x,y:t.y,width:t.z,height:t.w}}getCanvas(){return this.useParentDiv&&this.separateCanvas?this.separateCanvas:this.app.graphicsDevice.canvas}getParentDiv(){return this.parentDiv}isUsingParentDiv(){return this.useParentDiv}}const mz={enableStats:!1,autoFocus:!0,maxSplats:2e6,camera:{position:{x:0,y:0,z:10},target:{x:0,y:0,z:0},distance:10,minDistance:.1,maxDistance:1e5,orbitSensitivity:.3,panSensitivity:1,zoomSensitivity:.1},navigationCube:{enabled:!1,cubeSize:150,position:{x:0,y:0},padding:{x:50,y:100},transitionDuration:600,controlPointRadius:6,controlPointColor:{normal:"#ffffff",hover:"#FB7347"},continuousRotationSpeed:45}};function _z(t){if(!t)return null;try{return JSON.parse(t)}catch(t){return null}}function gz(t){return"boolean"==typeof t?t:"string"==typeof t&&("true"===t.toLowerCase()||"1"===t)}function vz(t,e=0){if("number"==typeof t)return t;if("string"==typeof t){const i=parseFloat(t);return isNaN(i)?e:i}return e}class Sz{constructor(t={}){this._app=null,this._mainCamera=null,this._orbitScript=null,this.emitEvent=null,this.initialized=!1,this.cubeRenderer=null,this.controlPointManager=null,this.transitionController=null;const e=mz.navigationCube;if(!e)throw new Error("NavigationCubeController: DEFAULT_CONFIG.navigationCube is not defined");this.config={...e,...t},this._enabled=this.config.enabled}get enabled(){return this._enabled}initialize(t,e,i,s){if(!this.initialized&&this._enabled&&t&&e&&i){this._app=t,this._mainCamera=e,this._orbitScript=i,this.emitEvent=s||null;try{this.cubeRenderer=new pz(t,this.config),this.cubeRenderer.initialize(),this.cubeRenderer.setResizeCallback(()=>{this.updateControlPointPositions()});const e=this.cubeRenderer.getCanvas()||t.graphicsDevice.canvas,s=this.cubeRenderer.getParentDiv();this.controlPointManager=new iD(this.config,e,this.onControlPointClick.bind(this),this.onControlPointPressStart.bind(this),this.onControlPointPressEnd.bind(this),s),this.controlPointManager.initialize(),this.updateControlPointPositions(),this.transitionController=new eD(i,this.config.transitionDuration),void 0!==this.config.continuousRotationSpeed&&this.transitionController.setContinuousRotationSpeed(this.config.continuousRotationSpeed),this.initialized=!0}catch(t){this.cleanup(),this.initialized=!1}}}update(t){if(this.initialized&&this._enabled&&!("number"!=typeof t||t<0)&&isFinite(t))try{this.cubeRenderer&&this.cubeRenderer.render(),this.transitionController&&this.transitionController.update(t)}catch(t){}}updateControlPointPositions(){if(!this.controlPointManager||!this.cubeRenderer)return;const t=this.cubeRenderer.getViewport();t?this.controlPointManager.updateControlPointPositions(t):this.controlPointManager.updateControlPointPositions()}onControlPointClick(t){if(this.initialized&&this._enabled)try{this.snapToView(t)}catch(t){}}onControlPointPressStart(t){if(this.initialized&&this._enabled)try{this.transitionController&&this.transitionController.startContinuousRotation(t),this.emitEvent&&this.emitEvent("navigation-cube:continuous-rotation-start",{direction:t})}catch(t){}}onControlPointPressEnd(t){if(this.initialized&&this._enabled)try{this.transitionController&&this.transitionController.stopContinuousRotation(),this.emitEvent&&this.emitEvent("navigation-cube:continuous-rotation-end",{direction:t})}catch(t){}}syncWithCamera(t,e){if(this.initialized&&this._enabled&&"number"==typeof t&&"number"==typeof e)try{this.cubeRenderer&&this.cubeRenderer.setRotation(t,e)}catch(t){}}async snapToView(t){if(!this.initialized||!this._enabled)return Promise.reject(new Error("NavigationCubeController not initialized or disabled"));if(![tD.TOP,tD.BOTTOM,tD.LEFT,tD.RIGHT].includes(t))return Promise.reject(new Error(`Invalid direction: ${t}`));try{if(this.transitionController?.isTransitionActive()&&this.transitionController.cancelTransition("interrupted"),this.controlPointManager){const e=this.controlPointManager.getControlPoint(t);if(e?.element){const t=e.element,i=t.style.transform;t.style.transition="transform 100ms ease-out",t.style.transform="scale(1.4)",setTimeout(()=>{t.style.transition="background-color 200ms ease-in-out, transform 200ms ease-in-out, box-shadow 200ms ease-in-out",t.style.transform=i},100)}}if(!this.transitionController)throw new Error("TransitionController not initialized");const e=this.transitionController.calculateTargetState(t);if(!this.transitionController.validateTargetState(e))throw new Error("Invalid target state calculated");this.emitEvent&&this.emitEvent("navigation-cube:view-change-start",{direction:t});try{await this.transitionController.startTransition(e),this.emitEvent&&this.emitEvent("navigation-cube:view-change-complete",{direction:t})}catch(e){throw this.emitEvent&&this.emitEvent("navigation-cube:view-change-cancel",{direction:t,reason:e.message||"unknown"}),e}}catch(e){return this.emitEvent&&this.emitEvent("navigation-cube:view-change-cancel",{direction:t,reason:e instanceof Error?e.message:"unknown error"}),Promise.reject(e)}}setEnabled(t){if(this._enabled!==t&&(this._enabled=t,this.initialized))try{t?(this.cubeRenderer?.setVisible(!0),this.controlPointManager?.setVisible(!0)):(this.cubeRenderer?.setVisible(!1),this.controlPointManager?.setVisible(!1),this.transitionController?.cancelTransition("disabled"))}catch(t){}}updateConfig(t){const e=this.validateConfig(t);if(this.config={...this.config,...e},this.initialized)try{void 0!==e.cubeSize&&this.cubeRenderer&&(this.cubeRenderer.updateSize(e.cubeSize),this.updateControlPointPositions()),void 0!==e.controlPointColor&&this.controlPointManager&&this.controlPointManager.updateColors(e.controlPointColor),void 0!==e.controlPointRadius&&this.controlPointManager&&this.controlPointManager.updateRadius(e.controlPointRadius),void 0===e.padding&&void 0===e.position&&void 0===e.cubeSize||!this.controlPointManager||this.updateControlPointPositions(),void 0!==e.transitionDuration&&this.transitionController&&this.transitionController.setDuration(e.transitionDuration),void 0!==e.continuousRotationSpeed&&this.transitionController&&this.transitionController.setContinuousRotationSpeed(e.continuousRotationSpeed)}catch(t){}}validateConfig(t){const e={};if(void 0!==t.cubeSize&&"number"==typeof t.cubeSize&&isFinite(t.cubeSize)&&(e.cubeSize=Math.max(50,Math.min(500,t.cubeSize)),e.cubeSize,t.cubeSize),void 0!==t.controlPointRadius&&"number"==typeof t.controlPointRadius&&isFinite(t.controlPointRadius)&&(e.controlPointRadius=Math.max(4,Math.min(20,t.controlPointRadius)),e.controlPointRadius,t.controlPointRadius),void 0!==t.transitionDuration&&"number"==typeof t.transitionDuration&&isFinite(t.transitionDuration)&&(e.transitionDuration=Math.max(100,Math.min(3e3,t.transitionDuration)),e.transitionDuration,t.transitionDuration),void 0!==t.padding&&"object"==typeof t.padding&&null!==t.padding&&"number"==typeof t.padding.x&&"number"==typeof t.padding.y){const i=Math.max(0,Math.min(500,t.padding.x)),s=Math.max(0,Math.min(500,t.padding.y));e.padding={x:i,y:s},i!==t.padding.x||t.padding.y}if(void 0!==t.position&&"object"==typeof t.position&&null!==t.position&&"number"==typeof t.position.x&&"number"==typeof t.position.y){const i=Math.max(0,Math.min(1,t.position.x)),s=Math.max(0,Math.min(1,t.position.y));e.position={x:i,y:s},i!==t.position.x||t.position.y}return void 0!==t.controlPointColor&&"object"==typeof t.controlPointColor&&null!==t.controlPointColor&&"string"==typeof t.controlPointColor.normal&&"string"==typeof t.controlPointColor.hover&&this.isValidColor(t.controlPointColor.normal)&&this.isValidColor(t.controlPointColor.hover)&&(e.controlPointColor={normal:t.controlPointColor.normal,hover:t.controlPointColor.hover}),void 0!==t.enabled&&"boolean"==typeof t.enabled&&(e.enabled=t.enabled),void 0!==t.continuousRotationSpeed&&"number"==typeof t.continuousRotationSpeed&&isFinite(t.continuousRotationSpeed)&&(e.continuousRotationSpeed=Math.max(10,Math.min(180,t.continuousRotationSpeed)),e.continuousRotationSpeed,t.continuousRotationSpeed),e}isValidColor(t){if(/^#([0-9A-F]{3}|[0-9A-F]{6}|[0-9A-F]{8})$/i.test(t))return!0;if(/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*[\d.]+\s*)?\)$/i.test(t))return!0;if(/^hsla?\(\s*\d+\s*,\s*\d+%\s*,\s*\d+%\s*(,\s*[\d.]+\s*)?\)$/i.test(t))return!0;return!!["white","black","red","green","blue","yellow","orange","purple","pink","gray","grey","transparent"].includes(t.toLowerCase())}cancelTransition(t="manual-interaction"){if(this.initialized)try{this.transitionController&&this.transitionController.cancelTransition(t)}catch(t){}}onCanvasResize(){if(this.initialized&&this._enabled)try{this.cubeRenderer&&this.cubeRenderer.onCanvasResize(),this.controlPointManager&&this.updateControlPointPositions()}catch(t){}}cleanup(){this.transitionController&&(this.transitionController.cancelTransition("cleanup"),this.transitionController=null),this.controlPointManager&&(this.controlPointManager.destroy(),this.controlPointManager=null),this.cubeRenderer&&(this.cubeRenderer.destroy(),this.cubeRenderer=null),this._app=null,this._mainCamera=null,this._orbitScript=null}destroy(){if(this.initialized)try{this.cleanup(),this.initialized=!1}catch(t){this.initialized=!1}}getConfig(){return{...this.config}}isInitialized(){return this.initialized}}class yz{constructor(t,e,i){this.app=t,this.camera=e,this.emit=i}setCameraFOV(t){this.validateFOV(t),this.camera.camera.fov=t,this.emit("camera-fov-changed",{fov:t,previousFov:t})}getCameraFOV(){return this.camera.camera?.fov??60}async animateCameraFOV(t,e){this.validateFOV(t);const i=this.camera.camera,s=i.fov,n=t;if(e<=0)return i.fov=n,void this.emit("camera-fov-changed",{fov:n,previousFov:s});const r=performance.now();await new Promise(t=>{const a=()=>{const o=(performance.now()-r)/e,l=this.easeInOutCubic(Math.min(1,Math.max(0,o)));i.fov=s+(n-s)*l,o<1?requestAnimationFrame(a):(i.fov=n,this.emit("camera-fov-changed",{fov:n,previousFov:s}),t())};requestAnimationFrame(a)})}validateFOV(t){if("number"!=typeof t||isNaN(t)||t<1||t>179)throw new Error("SceneConfigManager.validateFOV: FOV must be between 1 and 179 degrees")}setBackgroundColor(t){const e=this.parseColor(t),i=new H(e.r/255,e.g/255,e.b/255,e.a);this.camera.camera.clearColor=i,this.emit("background-color-changed",{color:e,previousColor:e})}getBackgroundColor(){const t=this.camera.camera?.clearColor;return t?{r:Math.round(255*(t.r??0)),g:Math.round(255*(t.g??0)),b:Math.round(255*(t.b??0)),a:"number"==typeof t.a?t.a:1}:{r:26,g:26,b:26,a:1}}async animateBackgroundColor(t,e){const i=this.getBackgroundColor(),s=this.parseColor(t);if(e<=0)return this.setBackgroundColor(s),void this.emit("background-color-changed",{color:s,previousColor:i});const n=performance.now();await new Promise(t=>{const r=()=>{const a=(performance.now()-n)/e,o=this.easeInOutCubic(Math.min(1,Math.max(0,a))),l=this.interpolateColor(i,s,o),h=new H(l.r/255,l.g/255,l.b/255,l.a);this.camera.camera.clearColor=h,a<1?requestAnimationFrame(r):(this.emit("background-color-changed",{color:s,previousColor:i}),t())};requestAnimationFrame(r)})}parseColor(t){if("string"==typeof t)return this.parseColorString(t);if(Array.isArray(t)){if(3===t.length)return{r:t[0],g:t[1],b:t[2],a:1};if(4===t.length)return{r:t[0],g:t[1],b:t[2],a:t[3]};throw new Error("SceneConfigManager.parseColor: Invalid color array length")}if("object"==typeof t&&null!==t){if("a"in t)return t;const e=t;return{r:e.r,g:e.g,b:e.b,a:1}}throw new Error("SceneConfigManager.parseColor: Unsupported color input")}parseColorString(t){const e=t.trim().toLowerCase();if(e.startsWith("#")){const t=e.slice(1);if(3===t.length){return{r:parseInt(t[0]+t[0],16),g:parseInt(t[1]+t[1],16),b:parseInt(t[2]+t[2],16),a:1}}if(6===t.length){return{r:parseInt(t.slice(0,2),16),g:parseInt(t.slice(2,4),16),b:parseInt(t.slice(4,6),16),a:1}}throw new Error("SceneConfigManager.parseColorString: Invalid hex color")}const i={black:[0,0,0],white:[255,255,255],red:[255,0,0],green:[0,128,0],blue:[0,0,255],gray:[128,128,128],grey:[128,128,128],orange:[255,165,0],purple:[128,0,128]};if(i[e]){const[t,s,n]=i[e];return{r:t,g:s,b:n,a:1}}throw new Error(`SceneConfigManager.parseColorString: Unsupported color string "${t}"`)}interpolateColor(t,e,i){const s=Math.min(1,Math.max(0,i)),n=(t,e)=>t+(e-t)*s;return{r:Math.round(n(t.r,e.r)),g:Math.round(n(t.g,e.g)),b:Math.round(n(t.b,e.b)),a:n(t.a,e.a)}}easeInOutCubic(t){return t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2}}class xz{constructor(t){this._eventEmitter=t}applyTransformMatrix(t,e,i){const s=new rt;s.data.set(e);const{pos:n,rot:r,scale:a}=this.decomposeMatrix(s);t.setLocalPosition(n),t.setLocalRotation(r),t.setLocalScale(a);const o=this.getTransform(t);this.emitTransformEvent(i,o)}getTransformMatrix(t){const e=t.getLocalTransform().data;return[e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8],e[9],e[10],e[11],e[12],e[13],e[14],e[15]]}setPosition(t,e,i){t.setLocalPosition(e.x,e.y,e.z);const s=this.getTransform(t);this.emitTransformEvent(i,s)}setRotation(t,e,i){const s=this.eulerToQuat(e);t.setLocalRotation(s);const n=this.getTransform(t);this.emitTransformEvent(i,n)}setScale(t,e,i){t.setLocalScale(e.x,e.y,e.z);const s=this.getTransform(t);this.emitTransformEvent(i,s)}getTransform(t){const e=t.getLocalPosition(),i=t.getLocalRotation(),s=t.getLocalScale(),n=this.quatToEuler(i),r=this.getTransformMatrix(t);return{position:{x:e.x,y:e.y,z:e.z},rotation:n,scale:{x:s.x,y:s.y,z:s.z},matrix:r}}resetTransform(t,e){t.setLocalPosition(0,0,0),t.setLocalRotation(0,0,0,1),t.setLocalScale(1,1,1);const i=this.getTransform(t);this.emitTransformEvent(e,i)}decomposeMatrix(t){const e=new K,i=new at,s=new K;t.getTranslation(e);const n=t.data,r=Math.sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]),a=Math.sqrt(n[4]*n[4]+n[5]*n[5]+n[6]*n[6]),o=Math.sqrt(n[8]*n[8]+n[9]*n[9]+n[10]*n[10]);s.set(r,a,o);const l=new rt;l.data[0]=n[0]/r,l.data[1]=n[1]/r,l.data[2]=n[2]/r,l.data[3]=0,l.data[4]=n[4]/a,l.data[5]=n[5]/a,l.data[6]=n[6]/a,l.data[7]=0,l.data[8]=n[8]/o,l.data[9]=n[9]/o,l.data[10]=n[10]/o,l.data[11]=0,l.data[12]=0,l.data[13]=0,l.data[14]=0,l.data[15]=1,l.getEulerAngles(i);const h=i;return i.setFromEulerAngles(h.x,h.y,h.z),{pos:e,rot:i,scale:s}}eulerToQuat(t){const e=new at;return e.setFromEulerAngles(t.x,t.y,t.z),e}quatToEuler(t){const e=new K;return t.getEulerAngles(e),{x:e.x,y:e.y,z:e.z}}emitTransformEvent(t,e){this._eventEmitter&&this._eventEmitter("model-transform-changed",{modelId:t,transform:e})}}var Tz;!function(t){t.ORBIT="orbit",t.FLY="fly"}(Tz||(Tz={}));const Ez={moveSpeed:5,fastSpeedMultiplier:3,slowSpeedMultiplier:.3,lookSensitivity:.2,invertY:!1,keyBindings:{forward:"KeyW",backward:"KeyS",left:"KeyA",right:"KeyD",up:"KeyE",down:"KeyQ",fastMove:"ShiftLeft",slowMove:"ControlLeft"},smoothing:.8,friction:.85,enableCollision:!1,minHeight:null,maxHeight:null};class SplatViewerCore{constructor(t={}){this.canvas=null,this.app=null,this.entities={camera:null,light:null,splat:null},this.enableStats=!1,this.autoFocus=!0,this.isLoading=!1,this.hasModel=!1,this.error=null,this._orbit=null,this._fly=null,this._cameraModeManager=null,this._statsHandler=null,this._asset=null,this._blobUrl=null,this._resizeObserver=null,this._resizeHandler=null,this.initialCameraPosition=null,this._navigationCubeConfig=null,this._modelManager=null,this._transformSystem=null,this._sceneConfigManager=null,this._eventListeners=new Map,this.canvas=t.canvas||null,this.enableStats=t.enableStats||!1,this.autoFocus=!1!==t.autoFocus,this._navigationCubeConfig=t.navigationCube||null,void 0!==t.onStatsUpdate&&(this._onStatsUpdate=t.onStatsUpdate),void 0!==t.onError&&(this._onError=t.onError),void 0!==t.onLoadingStart&&(this._onLoadingStart=t.onLoadingStart),void 0!==t.onLoaded&&(this._onLoaded=t.onLoaded)}init(t){if(this.canvas=t||this.canvas,!this.canvas)throw new Error("SplatViewerCore.init: canvas is required");return this.app=new oC(this.canvas,{mouse:new Ua(this.canvas),touch:new Ja(this.canvas),graphicsDeviceOptions:{antialias:!1,alpha:!1,preserveDrawingBuffer:!0,powerPreference:"high-performance",stencil:!1,depth:!0}}),this.app.start(),this._setupResolution(),this._setupScene(),this._setupCamera(),this._setupLighting(),this._setupOrbitCamera(),this._setupStats(),this._modelManager=new JL(this.app,(t,e)=>{this.emit({type:t,detail:e})}),this._transformSystem=new xz((t,e)=>{"model-transform-changed"===t&&this._modelManager&&this._modelManager.updateModelTransform(e.modelId,e.transform),this.emit({type:t,detail:e})}),this.entities.camera&&(this._sceneConfigManager=new yz(this.app,this.entities.camera,(t,e)=>this.emit({type:t,detail:e}))),this}async load(t,e={}){if(!this.app)throw new Error("SplatViewerCore.load: call init() first");this.clear(),this.isLoading=!0,this.error=null,this._onLoadingStart?.(),this.emit({type:"loading-start",detail:{source:"string"==typeof t?t:"file/blob"}}),this.emit({type:"loading-progress",detail:{progress:.1}});try{let i;try{i=$L(t)}catch(t){}if(i&&KL(i.ext))try{this.emit({type:"loading-progress",detail:{progress:.3}});const s={applyRotation:!1,..."number"==typeof e.maxSplats&&{maxSplats:e.maxSplats}},n=await QL(this.app,t,s);if(this.entities.splat=n.entity,this._asset=n.asset,i.url&&i.blob)try{URL.revokeObjectURL(i.url)}catch(t){}return await new Promise(t=>{this.app.once("frameupdate",()=>{this.autoFocus&&(this.focus(n.entity),setTimeout(()=>{this.debugInfo().boundsRadius||this.focus(n.entity)},100)),this.isLoading=!1,this.hasModel=!0,this._onLoaded?.(n),this.emit({type:"loaded",detail:{entity:n.entity,asset:n.asset}}),t(n)})})}catch(t){throw t instanceof jL?(this.error=t.code||"UNKNOWN_LOADER_ERROR",this._onError?.(this.error)):(this.error="UNKNOWN_LOADER_ERROR",this._onError?.(this.error)),this.isLoading=!1,this.emit({type:"error",detail:{message:this.error,code:t instanceof jL?t.code:"UNKNOWN_ERROR"}}),t}let s=null,n="gsplat";if("string"==typeof t)s=t,n=t.split("/").pop()||"gsplat";else{if(!(t instanceof Blob))throw new Error("Unsupported source type");s=URL.createObjectURL(t),this._blobUrl=s,n="local.ply"}try{this.emit({type:"loading-progress",detail:{progress:.5}});const t=new y_(n,"gsplat",{url:s}),e=new lC([t],this.app.assets);if(await new Promise(t=>e.load(()=>t())),this.emit({type:"loading-progress",detail:{progress:.8}}),!t||!1===t.loaded||!t.resource)throw new Error("GSplat asset failed to load");const i=new U_("splat");return i.addComponent("gsplat",{asset:t}),i.setLocalEulerAngles(270,0,0),this.app.root.addChild(i),this.entities.splat=i,this._asset=t,await new Promise(e=>{this.app.once("frameupdate",()=>{this.autoFocus&&(this.focus(i),setTimeout(()=>{this.debugInfo().boundsRadius||this.focus(i)},100)),this.isLoading=!1,this.hasModel=!0;const s={entity:i,asset:t};this._onLoaded?.(s),this.emit({type:"loaded",detail:{entity:s.entity,asset:s.asset}}),e(s)})})}catch(t){throw this.error="Failed to load splat",this._onError?.(this.error),this.isLoading=!1,this.emit({type:"error",detail:{message:this.error,code:"LOAD_FAILED"}}),t}}catch(t){throw this.isLoading=!1,t}}focus(t){const e=t||this.entities.splat||this.app?.root;if(e&&this._orbit)try{const t=new ut;this.calcSceneBounds(t,e);const i=t.halfExtents.length();if(this._orbit&&void 0!==this._orbit.distance){const t=2.5*i;this._orbit.distance=t}const s=this.calcFocalPoint(t);if(this.initialCameraPosition)return this.initialCameraPosition=null,void(this._orbit&&void 0!==this._orbit.target&&(this._orbit.target=s));this._orbit&&void 0!==this._orbit.target&&(this._orbit.target=s),"function"==typeof this._orbit.focus&&this._orbit.focus(e)}catch(t){"function"==typeof this._orbit.focus&&this._orbit.focus(e)}}calcSceneBounds(t,e){if(e)if(t.center.set(0,0,0),t.halfExtents.set(0,0,0),e.getWorldTransform&&e.getWorldTransform(),e._calculateHierarchyBounds)e._calculateHierarchyBounds(t);else if(e.gsplat){const i=e.gsplat;i.bounds?t.copy(i.bounds):i.boundingBox&&t.copy(i.boundingBox)}}calcFocalPoint(t){return t.center.clone()}async addModel(t,e={}){if(!this._modelManager)throw new Error("SplatViewerCore.addModel: ModelManager not initialized");return await this._modelManager.addModel(t,e)}removeModel(t){if(!this._modelManager)throw new Error("SplatViewerCore.removeModel: ModelManager not initialized");this._modelManager.removeModel(t)}getModels(){return this._modelManager?this._modelManager.getModels():[]}getModelStats(t){if(!this._modelManager)throw new Error("SplatViewerCore.getModelStats: ModelManager not initialized");return this._modelManager.getModelStats(t)}getAllModelStats(){return this._modelManager?this._modelManager.getAllModelStats():{}}getSceneStats(){return this._modelManager?this._modelManager.getSceneStats():{modelCount:0,totalSplats:0,totalFileSize:0,totalMemoryUsage:0,bounds:{center:{x:0,y:0,z:0},halfExtents:{x:0,y:0,z:0}}}}applyTransformMatrix(t,e){if(!this._transformSystem)throw new Error("SplatViewerCore.applyTransformMatrix: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.applyTransformMatrix: ModelManager not initialized");const i=this._modelManager.getModelById(t);if(!i)throw new Error(`SplatViewerCore.applyTransformMatrix: Model with ID "${t}" not found`);this._transformSystem.applyTransformMatrix(i.entity,e,t)}setModelPosition(t,e){if(!this._transformSystem)throw new Error("SplatViewerCore.setModelPosition: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.setModelPosition: ModelManager not initialized");const i=this._modelManager.getModelById(t);if(!i)throw new Error(`SplatViewerCore.setModelPosition: Model with ID "${t}" not found`);this._transformSystem.setPosition(i.entity,e,t)}setModelRotation(t,e){if(!this._transformSystem)throw new Error("SplatViewerCore.setModelRotation: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.setModelRotation: ModelManager not initialized");const i=this._modelManager.getModelById(t);if(!i)throw new Error(`SplatViewerCore.setModelRotation: Model with ID "${t}" not found`);this._transformSystem.setRotation(i.entity,e,t)}setModelScale(t,e){if(!this._transformSystem)throw new Error("SplatViewerCore.setModelScale: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.setModelScale: ModelManager not initialized");const i=this._modelManager.getModelById(t);if(!i)throw new Error(`SplatViewerCore.setModelScale: Model with ID "${t}" not found`);this._transformSystem.setScale(i.entity,e,t)}getModelTransform(t){if(!this._transformSystem)throw new Error("SplatViewerCore.getModelTransform: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.getModelTransform: ModelManager not initialized");const e=this._modelManager.getModelById(t);if(!e)throw new Error(`SplatViewerCore.getModelTransform: Model with ID "${t}" not found`);return this._transformSystem.getTransform(e.entity)}resetModelTransform(t){if(!this._transformSystem)throw new Error("SplatViewerCore.resetModelTransform: TransformSystem not initialized");if(!this._modelManager)throw new Error("SplatViewerCore.resetModelTransform: ModelManager not initialized");const e=this._modelManager.getModelById(t);if(!e)throw new Error(`SplatViewerCore.resetModelTransform: Model with ID "${t}" not found`);this._transformSystem.resetTransform(e.entity,t)}clear(){this._modelManager&&this._modelManager.clear(),this.entities.splat&&(this.entities.splat.destroy(),this.entities.splat=null),this._asset&&(this._asset.unload(),this._asset.destroy(),this._asset=null),this._blobUrl&&(URL.revokeObjectURL(this._blobUrl),this._blobUrl=null),this.hasModel=!1,this.error=null}destroy(){if(this.app){this.clear(),this._modelManager=null,this._statsHandler&&(this.app.off("frameend",this._statsHandler),this._statsHandler=null),this._resizeObserver&&(this._resizeObserver.disconnect(),this._resizeObserver=null),this._resizeHandler&&(window.removeEventListener("resize",this._resizeHandler),this._resizeHandler=null);try{this.entities.camera&&(this.entities.camera.destroy(),this.entities.camera=null)}catch(t){}try{this.entities.light&&(this.entities.light.destroy(),this.entities.light=null)}catch(t){}try{this.app.destroy()}catch(t){throw t}this.app=null,this._orbit=null}}debugInfo(){const t=this._asset,e=this.entities.splat,i=!!e?.gsplat;let s=null,n=null;if(e){const t=e.gsplat;if(t){const e=t.bounds||t.boundingBox||null;e?.halfExtents?(s=Math.max(1,e.halfExtents.length()),n="gsplat.bounds"):"number"==typeof t.radius&&(s=Math.max(1,t.radius),n="gsplat.radius")}if(null==s&&e._calculateHierarchyBounds){const t=new ut;e.getWorldTransform(),e._calculateHierarchyBounds(t),t.halfExtents.length()>0&&(s=Math.max(1,t.halfExtents.length()),n="hierarchy")}}return{assetName:t?.name||null,assetUrl:t?.file?.url||t?.url||null,hasEntity:!!e,hasGsplatComponent:i,cameraDistance:this._orbit?.distance??null,boundsRadius:s,boundsSource:n,cameraTarget:this._orbit?.target?this._orbit.target.toString():null}}on(t,e){this._eventListeners.has(t)||this._eventListeners.set(t,new Set),this._eventListeners.get(t).add(e)}off(t,e){const i=this._eventListeners.get(t);i&&(i.delete(e),0===i.size&&this._eventListeners.delete(t))}emit(t){const e=this._eventListeners.get(t.type);e&&e.forEach(e=>{try{e(t)}catch(t){}})}setCameraPosition(t){this.entities.camera&&(this.entities.camera.setPosition(t),this.emit({type:"camera-change",detail:{position:t,target:this._orbit?.target||{x:0,y:0,z:0}}}))}setCameraTarget(t){this._orbit&&(this._orbit.target=t,this._orbit.updateCameraPosition?.(),this.emit({type:"camera-change",detail:{position:this.entities.camera?.getPosition?.()||{x:0,y:0,z:0},target:t}}))}resetCamera(){this._orbit&&(this._orbit.target={x:0,y:0,z:0},this._orbit.distance=10,this._orbit.pitch=-15,this._orbit.yaw=45,this._orbit.updateCameraPosition?.(),this.emit({type:"camera-change",detail:{position:this.entities.camera?.getPosition?.()||{x:0,y:0,z:0},target:{x:0,y:0,z:0}}}))}setCameraMode(t){this._cameraModeManager&&this._cameraModeManager.setMode(t)}setCameraFOV(t){this._sceneConfigManager&&this._sceneConfigManager.setCameraFOV(t)}getCameraFOV(){return this._sceneConfigManager?this._sceneConfigManager.getCameraFOV():this.entities.camera?.camera?.fov??60}async animateCameraFOV(t,e){this._sceneConfigManager&&await this._sceneConfigManager.animateCameraFOV(t,e)}setBackgroundColor(t){this._sceneConfigManager&&this._sceneConfigManager.setBackgroundColor(t)}getBackgroundColor(){return this._sceneConfigManager?this._sceneConfigManager.getBackgroundColor():{r:26,g:26,b:26,a:1}}async animateBackgroundColor(t,e){this._sceneConfigManager&&await this._sceneConfigManager.animateBackgroundColor(t,e)}getCameraMode(){return this._cameraModeManager?.getMode()||"orbit"}setFlyCameraConfig(t){this._cameraModeManager?.setFlyConfig(t)}getFlyCameraConfig(){return this._cameraModeManager?.getFlyConfig()||null}getFlyCameraState(){return this._cameraModeManager?.getFlyState()||null}_setupScene(){this.app&&(this.app.scene.ambientLight=new H(.2,.2,.2))}_setupCamera(){if(!this.app)return;const t=new U_("camera");t.addComponent("camera",{clearColor:new H(.1,.1,.1),nearClip:.01,farClip:1e6}),this.app.root.addChild(t),this.entities.camera=t}_setupLighting(){if(!this.app)return;const t=new U_("light");t.addComponent("light",{type:0,color:new H(1,1,1),intensity:1,castShadows:!0}),t.setLocalEulerAngles(45,30,0),this.app.root.addChild(t),this.entities.light=t}_setupOrbitCamera(){if(!this.app||!this.entities.camera)return;!function(){if(void 0===YL)return;if(!i_)return;if(i_?.scripts?.has("orbitCamera"))return;const t=Cw("orbitCamera");t&&(t.attributes.add("distance",{type:"number",default:10}),t.attributes.add("minDistance",{type:"number",default:.1}),t.attributes.add("maxDistance",{type:"number",default:1e5}),t.attributes.add("orbitSensitivity",{type:"number",default:.3}),t.attributes.add("panSensitivity",{type:"number",default:1}),t.attributes.add("zoomSensitivity",{type:"number",default:.1}),t.attributes.add("enableNavigationCube",{type:"boolean",default:!1}),t.attributes.add("navigationCubeConfig",{type:"json",default:null}),t.prototype.initialize=function(){if(this.target=new K(0,0,0),this.distance=this.distance||10,this.pitch=-15,this.yaw=45,this.isOrbiting=!1,this.isPanning=!1,this.setupContextMenuPrevention(),this.app.mouse.on(lM,this.onMouseDown,this),this.app.mouse.on(cM,this.onMouseUp,this),this.app.mouse.on(hM,this.onMouseMove,this),this.app.mouse.on(dM,this.onMouseWheel,this),this.updateCameraPosition(),this.enableNavigationCube)try{let t=this.navigationCubeConfig||{};this.entity._navigationCubeConfig&&(t=this.entity._navigationCubeConfig),this.navigationCube=new Sz(t),this.navigationCube.initialize(this.app,this.entity,this,this.emitInteractionEvent)}catch(t){delete this.navigationCube}},t.prototype.update=function(t){this.navigationCube&&"function"==typeof this.navigationCube.update&&this.navigationCube.update(t)},t.prototype.onMouseDown=function(t){this.navigationCube&&"function"==typeof this.navigationCube.cancelTransition&&this.navigationCube.cancelTransition("manual-interaction"),0===t.button?(this.isOrbiting=!0,this.emitInteractionEvent?.("interaction-start","rotate")):2!==t.button&&1!==t.button||(this.isPanning=!0,this.emitInteractionEvent?.("interaction-start","pan"))},t.prototype.onMouseUp=function(){this.isOrbiting&&(this.isOrbiting=!1,this.emitInteractionEvent?.("interaction-end","rotate")),this.isPanning&&(this.isPanning=!1,this.emitInteractionEvent?.("interaction-end","pan"))},t.prototype.onMouseMove=function(t){if(this.isOrbiting){const e=t.dx*this.orbitSensitivity,i=t.dy*this.orbitSensitivity;this.yaw-=e,this.pitch+=i,this.pitch=Math.max(-89,Math.min(89,this.pitch)),this.updateCameraPosition()}else if(this.isPanning){const e=this.distance*this.panSensitivity*.001,i=this.entity.getWorldTransform(),s=new K,n=new K;i.getX(s),i.getY(n);const r=s.clone().mulScalar(-t.dx*e).add(n.clone().mulScalar(t.dy*e));this.target.add(r),this.updateCameraPosition()}},t.prototype.onMouseWheel=function(t){this.navigationCube&&"function"==typeof this.navigationCube.cancelTransition&&this.navigationCube.cancelTransition("manual-interaction"),this.emitInteractionEvent?.("interaction-start","zoom");const e=Math.sign(t.wheel)*this.distance*this.zoomSensitivity;this.distance=Math.max(this.minDistance,Math.min(this.maxDistance,this.distance-e)),this.updateCameraPosition(),this.emitInteractionEvent?.("interaction-end","zoom")},t.prototype.updateCameraPosition=function(){const t=this.pitch*Math.PI/180,e=this.yaw*Math.PI/180,i=this.distance*Math.cos(t)*Math.sin(e),s=this.distance*Math.sin(t),n=this.distance*Math.cos(t)*Math.cos(e);this.entity.setPosition(new K(i,s,n).add(this.target)),this.entity.lookAt(this.target,K.UP),this.navigationCube&&"function"==typeof this.navigationCube.syncWithCamera&&this.navigationCube.syncWithCamera(this.pitch,this.yaw)},t.prototype.focus=function(t){const e=new K(0,0,0);let i=10,s=!1;if(t){const n=t.gsplat;if(n){const t=n.bounds||n.boundingBox;t?.center&&t.halfExtents?(e.copy(t.center),i=Math.max(1,t.halfExtents.length()),s=!0):"number"==typeof n.radius&&n.center&&(e.copy(n.center),i=Math.max(1,n.radius),s=!0)}if(!s&&t._calculateHierarchyBounds){const n=new ut;t.getWorldTransform(),t._calculateHierarchyBounds(n),n.halfExtents.length()>0&&(e.copy(n.center),i=Math.max(1,n.halfExtents.length()),s=!0)}}const n=this.entity.camera.fov*Math.PI/180,r=i/Math.sin(n/2)*1.5;this.target.copy(e),this.distance=Math.max(this.minDistance,Math.min(this.maxDistance,r)),this.pitch=-15,this.yaw=45,this.updateCameraPosition()},t.prototype.setupContextMenuPrevention=function(){[this.app.graphicsDevice.canvas,document.querySelector("canvas")].filter(Boolean).forEach(t=>{this._contextMenuHandler&&(t.removeEventListener("contextmenu",this._contextMenuHandler),t.removeEventListener("mousedown",this._mouseDownHandler),t.removeEventListener("mouseup",this._mouseUpHandler)),this._contextMenuHandler=t=>(t.preventDefault(),t.stopPropagation(),!1),this._mouseDownHandler=t=>{2===t.button&&(t.preventDefault(),t.stopPropagation())},this._mouseUpHandler=t=>{2===t.button&&(t.preventDefault(),t.stopPropagation())},t.addEventListener("contextmenu",this._contextMenuHandler,{passive:!1}),t.addEventListener("mousedown",this._mouseDownHandler,{passive:!1}),t.addEventListener("mouseup",this._mouseUpHandler,{passive:!1})})},t.prototype.destroy=function(){if(this.navigationCube&&"function"==typeof this.navigationCube.destroy){try{this.navigationCube.destroy()}catch(t){}delete this.navigationCube}[this.app?.graphicsDevice?.canvas,document.querySelector("canvas")].filter(Boolean).forEach(t=>{this._contextMenuHandler&&t.removeEventListener("contextmenu",this._contextMenuHandler),this._mouseDownHandler&&t.removeEventListener("mousedown",this._mouseDownHandler),this._mouseUpHandler&&t.removeEventListener("mouseup",this._mouseUpHandler)}),this.app?.mouse&&(this.app.mouse.off(lM,this.onMouseDown,this),this.app.mouse.off(cM,this.onMouseUp,this),this.app.mouse.off(hM,this.onMouseMove,this),this.app.mouse.off(dM,this.onMouseWheel,this))})}(),this.entities.camera.addComponent("script");const t={distance:10,minDistance:.1,maxDistance:1e5,orbitSensitivity:.3,panSensitivity:1,zoomSensitivity:.1};this._navigationCubeConfig&&(t.enableNavigationCube=this._navigationCubeConfig.enabled||!1,this.entities.camera._navigationCubeConfig=this._navigationCubeConfig),this._orbit=this.entities.camera.script.create("orbitCamera",{attributes:t}),this._orbit.emitInteractionEvent=(t,e)=>{this.emit({type:t,detail:{type:e}})},this.entities.camera.setPosition(0,0,10),this.entities.camera.lookAt(K.ZERO);try{!function(){if(void 0===YL)return;if(!i_)return;if(i_?.scripts?.has("flyCamera"))return;const t=Cw("flyCamera");t&&(t.attributes.add("moveSpeed",{type:"number",default:5}),t.attributes.add("fastSpeedMultiplier",{type:"number",default:3}),t.attributes.add("slowSpeedMultiplier",{type:"number",default:.3}),t.attributes.add("lookSensitivity",{type:"number",default:.2}),t.attributes.add("invertY",{type:"boolean",default:!1}),t.attributes.add("keyBindings",{type:"json",default:{forward:"KeyW",backward:"KeyS",left:"KeyA",right:"KeyD",up:"KeyE",down:"KeyQ",fastMove:"ShiftLeft",slowMove:"ControlLeft"}}),t.attributes.add("smoothing",{type:"number",default:.8}),t.attributes.add("friction",{type:"number",default:.85}),t.attributes.add("enableCollision",{type:"boolean",default:!1}),t.attributes.add("minHeight",{type:"number",default:null}),t.attributes.add("maxHeight",{type:"number",default:null}),t.prototype.initialize=function(){this._isActive=!0,this._isPointerLocked=!1,this._pressed=new Set,this._velocity=new K(0,0,0),this._targetVelocity=new K(0,0,0),this._pitch=0,this._yaw=0;try{const t=this.entity.getEulerAngles?this.entity.getEulerAngles():{x:0,y:0,z:0};this._pitch=t.x||0,this._yaw=t.y||0}catch{}this._onKeyDown=this._handleKeyDown.bind(this),this._onKeyUp=this._handleKeyUp.bind(this),document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),this._onMouseMove=this._handleMouseMove.bind(this),document.addEventListener("mousemove",this._onMouseMove),this._onPointerLockChange=this._handlePointerLockChange.bind(this),document.addEventListener("pointerlockchange",this._onPointerLockChange);const t=this.app.graphicsDevice.canvas;this._onClickToLock=t=>{0===t.button&&this._isActive&&this._requestPointerLock()},t.addEventListener("mousedown",this._onClickToLock)},t.prototype.update=function(t){if(!this._isActive)return;this._updateVelocity(t),this._applyMovement(t),this._applyRotation(),this._applyConstraints();const e=performance.now();if(!this._lastMoveEmitTime||e-this._lastMoveEmitTime>=100){const t=this.entity.getPosition?this.entity.getPosition():{x:0,y:0,z:0};this.emitFlyEvent?.("fly-camera-move",{position:{x:t.x,y:t.y,z:t.z},velocity:{x:this._velocity.x,y:this._velocity.y,z:this._velocity.z}}),this._lastMoveEmitTime=e}(!this._lastLookEmitTime||e-this._lastLookEmitTime>=100)&&(this.emitFlyEvent?.("fly-camera-look",{pitch:this._pitch,yaw:this._yaw}),this._lastLookEmitTime=e)},t.prototype.destroy=function(){this.deactivate()},t.prototype.activate=function(){if(this._isActive)return;this._isActive=!0,this._onKeyDown=this._onKeyDown||this._handleKeyDown.bind(this),this._onKeyUp=this._onKeyUp||this._handleKeyUp.bind(this),this._onMouseMove=this._onMouseMove||this._handleMouseMove.bind(this),this._onPointerLockChange=this._onPointerLockChange||this._handlePointerLockChange.bind(this),document.addEventListener("keydown",this._onKeyDown),document.addEventListener("keyup",this._onKeyUp),document.addEventListener("mousemove",this._onMouseMove),document.addEventListener("pointerlockchange",this._onPointerLockChange);const t=this.app.graphicsDevice.canvas;this._onClickToLock=this._onClickToLock||(()=>this._requestPointerLock()),t.addEventListener("mousedown",this._onClickToLock)},t.prototype.deactivate=function(){if(!this._isActive)return;this._isActive=!1,this._exitPointerLock(),document.removeEventListener("keydown",this._onKeyDown),document.removeEventListener("keyup",this._onKeyUp),document.removeEventListener("mousemove",this._onMouseMove),document.removeEventListener("pointerlockchange",this._onPointerLockChange);const t=this.app?.graphicsDevice?.canvas;t&&this._onClickToLock&&t.removeEventListener("mousedown",this._onClickToLock)},t.prototype.setConfig=function(t){void 0!==t.moveSpeed&&(this.moveSpeed=t.moveSpeed),void 0!==t.fastSpeedMultiplier&&(this.fastSpeedMultiplier=t.fastSpeedMultiplier),void 0!==t.slowSpeedMultiplier&&(this.slowSpeedMultiplier=t.slowSpeedMultiplier),void 0!==t.lookSensitivity&&(this.lookSensitivity=t.lookSensitivity),void 0!==t.invertY&&(this.invertY=t.invertY),void 0!==t.keyBindings&&(this.keyBindings=t.keyBindings),void 0!==t.smoothing&&(this.smoothing=t.smoothing),void 0!==t.friction&&(this.friction=t.friction),void 0!==t.enableCollision&&(this.enableCollision=t.enableCollision),void 0!==t.minHeight&&(this.minHeight=t.minHeight),void 0!==t.maxHeight&&(this.maxHeight=t.maxHeight)},t.prototype.getState=function(){const t=this.entity.getPosition?this.entity.getPosition():{x:0,y:0,z:0};return{position:{x:t.x,y:t.y,z:t.z},rotation:{pitch:this._pitch,yaw:this._yaw},velocity:{x:this._velocity.x,y:this._velocity.y,z:this._velocity.z},isMoving:Math.abs(this._velocity.x)+Math.abs(this._velocity.y)+Math.abs(this._velocity.z)>1e-4}},t.prototype._handleKeyDown=function(t){const e=[];t.code&&e.push(t.code),t.key&&(e.push(t.key),1===t.key.length&&(e.push(`Key${t.key.toUpperCase()}`),e.push(t.key.toUpperCase()),e.push(t.key.toLowerCase())));for(const t of e)this._pressed.add(t)},t.prototype._handleKeyUp=function(t){const e=[];t.code&&e.push(t.code),t.key&&(e.push(t.key),1===t.key.length&&(e.push(`Key${t.key.toUpperCase()}`),e.push(t.key.toUpperCase()),e.push(t.key.toLowerCase())));for(const t of e)this._pressed.delete(t)},t.prototype._handleMouseMove=function(t){if(!this._isPointerLocked||!this._isActive)return;const e=t.movementX*this.lookSensitivity,i=t.movementY*this.lookSensitivity*(this.invertY?1:-1);this._yaw=(this._yaw-e)%360,this._pitch=Math.max(-89,Math.min(89,this._pitch+i))},t.prototype._handlePointerLockChange=function(){const t=this.app.graphicsDevice.canvas;this._isPointerLocked=document.pointerLockElement===t},t.prototype._requestPointerLock=function(){const t=this.app.graphicsDevice.canvas;t.requestPointerLock&&t.requestPointerLock()},t.prototype._exitPointerLock=function(){if(document.exitPointerLock)try{document.exitPointerLock()}catch{}},t.prototype._updateVelocity=function(t){const e=this.keyBindings,i=(t,e)=>[t,...e].filter(Boolean).some(t=>this._pressed.has(t)),s=i(e.forward,["KeyW","w","W"])?1:0,n=i(e.backward,["KeyS","s","S"])?1:0,r=i(e.left,["KeyA","a","A"])?1:0,a=s-n,o=(i(e.right,["KeyD","d","D"])?1:0)-r,l=(i(e.up,["KeyE","e","E"])?1:0)-(i(e.down,["KeyQ","q","Q"])?1:0),h=Math.hypot(o,a),c=h>0?o/h:0,d=h>0?a/h:0,u=2*this._getEffectiveSpeed(),f=this.entity,p=f?.forward&&f.forward.clone?f.forward.clone():f?.forward?new K(f.forward.x,f.forward.y,f.forward.z):new K(0,0,-1),m=f?.right&&f.right.clone?f.right.clone():f?.right?new K(f.right.x,f.right.y,f.right.z):new K(1,0,0),_=f?.up&&f.up.clone?f.up.clone():f?.up?new K(f.up.x,f.up.y,f.up.z):K.UP.clone(),g=new K(0,0,0);g.add(p.mulScalar(d*u)),g.add(m.mulScalar(c*u)),g.add(_.mulScalar(l*u)),this._targetVelocity.copy(g),this._velocity.lerp(this._velocity,this._targetVelocity,Math.min(1,this.smoothing)),0===c&&0===d&&0===l&&(this._velocity.mulScalar(this.friction),this._velocity.length()<1e-4&&this._velocity.set(0,0,0))},t.prototype._applyMovement=function(t){if(0===this._velocity.length())return;const e=this.entity.getPosition?this.entity.getPosition().clone():new K(0,0,0);e.add(this._velocity.clone().mulScalar(t)),this.entity.setPosition(e)},t.prototype._applyRotation=function(){this.entity.setLocalEulerAngles?this.entity.setLocalEulerAngles(this._pitch,this._yaw,0):this.entity.setEulerAngles&&this.entity.setEulerAngles(this._pitch,this._yaw,0)},t.prototype._applyConstraints=function(){if(!this.enableCollision&&null==this.minHeight&&null==this.maxHeight)return;const t=this.entity.getPosition?this.entity.getPosition().clone():new K(0,0,0);null!=this.minHeight&&(t.y=Math.max(t.y,this.minHeight)),null!=this.maxHeight&&(t.y=Math.min(t.y,this.maxHeight)),this.entity.setPosition(t)},t.prototype._getEffectiveSpeed=function(){const t=this._pressed.has(this.keyBindings.fastMove),e=this._pressed.has(this.keyBindings.slowMove);let i=this.moveSpeed;return t&&(i*=this.fastSpeedMultiplier),e&&(i*=this.slowSpeedMultiplier),i})}();const t={moveSpeed:Ez.moveSpeed,fastSpeedMultiplier:Ez.fastSpeedMultiplier,slowSpeedMultiplier:Ez.slowSpeedMultiplier,lookSensitivity:Ez.lookSensitivity,invertY:Ez.invertY,keyBindings:Ez.keyBindings,smoothing:Ez.smoothing,friction:Ez.friction,enableCollision:Ez.enableCollision,minHeight:Ez.minHeight,maxHeight:Ez.maxHeight};this._fly=this.entities.camera.script.create("flyCamera",{attributes:t}),this._fly&&(this._fly.emitFlyEvent=(t,e)=>{this.emit({type:t,detail:e})}),this._fly?.deactivate&&this._fly.deactivate(),this._cameraModeManager=new qL(this.app,this.entities.camera,this._orbit,this._fly,(t,e)=>{this.emit({type:t,detail:e})},"orbit")}catch(t){}}_setupStats(){if(!this.app||!this.enableStats||!this._onStatsUpdate)return;let t=0,e=performance.now();this._statsHandler=()=>{t++;const i=performance.now(),s=i-e;if(s>=1e3){const n=Math.round(1e3*t/s),r=t=>"object"==typeof t&&null!==t?t.total||0:Number(t)||0,a=r(this.app.stats.triangles),o=r(this.app.stats.drawCalls),l={fps:n,frameTime:Math.round(s/t*100)/100,triangles:a,drawCalls:o,memoryUsage:performance.memory?Math.round(performance.memory.usedJSHeapSize/1024/1024):0};this._onStatsUpdate(l),this.emit({type:"stats-update",detail:l}),t=0,e=i}},this.app.on("frameend",this._statsHandler)}_setupResolution(){if(!this.app)return;const t=this.app.graphicsDevice.canvas;if(t.style.display||(t.style.display="block"),t.style.width||(t.style.width="100%"),t.style.height||(t.style.height="100%"),t.parentElement){const e=t.parentElement.style;e.width||(e.width="100%"),e.height||(e.height="100%")}const e=(e,i)=>{t.width===e&&t.height===i||(t.width=e,t.height=i,this.app.resizeCanvas(e,i),this._orbit&&this._orbit.navigationCube&&"function"==typeof this._orbit.navigationCube.onCanvasResize&&this._orbit.navigationCube.onCanvasResize())},i=()=>{const i=t.getBoundingClientRect(),s=window.devicePixelRatio||1,n=Math.floor(i.width*s),r=Math.floor(i.height*s);e(n,r)},s=t=>{let s=null,n=null;const r=t.devicePixelContentBoxSize;if(r&&r.length>0)s=Math.ceil(r[0].inlineSize),n=Math.ceil(r[0].blockSize);else{const e=t.contentBoxSize;if(e&&e.length>0){const t=window.devicePixelRatio||1;s=Math.ceil(e[0].inlineSize*t),n=Math.ceil(e[0].blockSize*t)}}null!==s&&null!==n?e(s,n):i()};if(i(),window.ResizeObserver){this._resizeObserver=new ResizeObserver(e=>{if(!e||0===e.length)return void i();const n=e.find(e=>e.target===t);if(n)s(n);else if(e.length>0){const t=e[0];t?s(t):i()}else i()});try{this._resizeObserver.observe(t,{box:"device-pixel-content-box"})}catch{this._resizeObserver.observe(t)}t.parentElement&&this._resizeObserver.observe(t.parentElement)}const n=()=>{i()};window.addEventListener("resize",n),this._resizeHandler=n}updateCanvasResolution(){if(!this.app)return;const t=this.app.graphicsDevice.canvas,e=t.getBoundingClientRect(),i=window.devicePixelRatio||1,s=Math.floor(e.width*i),n=Math.floor(e.height*i);t.width===s&&t.height===n||(t.width=s,t.height=n,this.app.resizeCanvas(s,n),this._orbit&&this._orbit.navigationCube&&"function"==typeof this._orbit.navigationCube.onCanvasResize&&this._orbit.navigationCube.onCanvasResize())}}function bz(t,e){return new CustomEvent(t,{detail:e})}class SplatViewerElement extends HTMLElement{constructor(){super(...arguments),this._core=null,this._canvas=null,this._config={...mz},this._isInitialized=!1,this._isDestroyed=!1,this._hostResizeObserver=null}static get observedAttributes(){return["src","width","height","enable-stats","auto-focus","max-splats","camera-position","camera-target","orbit-sensitivity","pan-sensitivity","zoom-sensitivity","min-distance","max-distance","enable-navigation-cube","navigation-cube-size","navigation-cube-transition","navigation-cube-parent-id"]}get src(){return this.getAttribute("src")}get width(){return this.getAttribute("width")}get height(){return this.getAttribute("height")}get enableStats(){return this.hasAttribute("enable-stats")}get autoFocus(){return this.hasAttribute("auto-focus")}get maxSplats(){return this.getAttribute("max-splats")}get cameraPosition(){return this.getAttribute("camera-position")}get cameraTarget(){return this.getAttribute("camera-target")}get orbitSensitivity(){return this.getAttribute("orbit-sensitivity")}get panSensitivity(){return this.getAttribute("pan-sensitivity")}get zoomSensitivity(){return this.getAttribute("zoom-sensitivity")}get minDistance(){return this.getAttribute("min-distance")}get maxDistance(){return this.getAttribute("max-distance")}get enableNavigationCube(){return this.hasAttribute("enable-navigation-cube")}get navigationCubeSize(){return this.getAttribute("navigation-cube-size")}get navigationCubeTransition(){return this.getAttribute("navigation-cube-transition")}get navigationCubeParentId(){return this.getAttribute("navigation-cube-parent-id")}set src(t){null===t?this.removeAttribute("src"):this.setAttribute("src",t)}set width(t){null===t?this.removeAttribute("width"):this.setAttribute("width",t)}set height(t){null===t?this.removeAttribute("height"):this.setAttribute("height",t)}set enableStats(t){t?this.setAttribute("enable-stats",""):this.removeAttribute("enable-stats")}set autoFocus(t){t?this.setAttribute("auto-focus",""):this.removeAttribute("auto-focus")}set maxSplats(t){null===t?this.removeAttribute("max-splats"):this.setAttribute("max-splats",t)}set cameraPosition(t){null===t?this.removeAttribute("camera-position"):this.setAttribute("camera-position",t)}set cameraTarget(t){null===t?this.removeAttribute("camera-target"):this.setAttribute("camera-target",t)}set orbitSensitivity(t){null===t?this.removeAttribute("orbit-sensitivity"):this.setAttribute("orbit-sensitivity",t)}set panSensitivity(t){null===t?this.removeAttribute("pan-sensitivity"):this.setAttribute("pan-sensitivity",t)}set zoomSensitivity(t){null===t?this.removeAttribute("zoom-sensitivity"):this.setAttribute("zoom-sensitivity",t)}set minDistance(t){null===t?this.removeAttribute("min-distance"):this.setAttribute("min-distance",t)}set maxDistance(t){null===t?this.removeAttribute("max-distance"):this.setAttribute("max-distance",t)}set enableNavigationCube(t){t?this.setAttribute("enable-navigation-cube",""):this.removeAttribute("enable-navigation-cube")}set navigationCubeSize(t){null===t?this.removeAttribute("navigation-cube-size"):this.setAttribute("navigation-cube-size",t)}set navigationCubeTransition(t){null===t?this.removeAttribute("navigation-cube-transition"):this.setAttribute("navigation-cube-transition",t)}set navigationCubeParentId(t){null===t?this.removeAttribute("navigation-cube-parent-id"):this.setAttribute("navigation-cube-parent-id",t)}connectedCallback(){this._isDestroyed||this._initialize()}disconnectedCallback(){this._destroy()}attributeChangedCallback(t,e,i){if(e!==i&&(null===i||this._validateAttribute(t,i)))switch(this._updateConfigFromAttributes(),t){case"src":this._handleSrcChange(i);break;case"width":case"height":this._handleSizeChange();break;case"enable-stats":this._handleStatsChange()}}_validateAttribute(t,e){switch(t){case"width":case"height":return/^(\d+(\.\d+)?(px|%|em|rem|vh|vw|vmin|vmax)?|\d+)$/.test(e);case"max-splats":const t=parseInt(e,10);return!isNaN(t)&&t>0;case"orbit-sensitivity":case"pan-sensitivity":case"zoom-sensitivity":const i=parseFloat(e);return!isNaN(i)&&i>0;case"min-distance":case"max-distance":const s=parseFloat(e);return!isNaN(s)&&s>0;case"camera-position":case"camera-target":try{const t=JSON.parse(e);return Array.isArray(t)&&3===t.length&&t.every(t=>"number"==typeof t&&!isNaN(t))}catch{return!1}case"src":return e.length>0;case"enable-stats":case"auto-focus":case"enable-navigation-cube":return!0;case"navigation-cube-size":const n=parseFloat(e);return!isNaN(n)&&n>0;case"navigation-cube-transition":const r=parseFloat(e);return!isNaN(r)&&r>0;case"navigation-cube-parent-id":return e.length>0;default:return!0}}async _initialize(){if(!this._isInitialized)try{this.style.display="block",this.style.position="relative",this.style.overflow="hidden",this.hasAttribute("width")||this.style.width||(this.style.width="100%"),this.hasAttribute("height")||this.style.height||(this.style.height="100%"),this._canvas=document.createElement("canvas"),this._canvas.style.display="block",this._canvas.style.width="100%",this._canvas.style.height="100%",this._canvas.style.outline="none",this._canvas.style.userSelect="none",this._canvas.style.touchAction="none",this._canvas.setAttribute("tabindex","0"),this._canvas.setAttribute("role","img"),this._canvas.setAttribute("aria-label","3D Splat Viewer"),this.appendChild(this._canvas);try{window.ResizeObserver&&(this._hostResizeObserver=new ResizeObserver(()=>{try{this._core?.updateCanvasResolution()}catch{}}),this._hostResizeObserver.observe(this),this.parentElement&&this._hostResizeObserver.observe(this.parentElement))}catch{}this._updateConfigFromAttributes(),this._core=new SplatViewerCore(this._config),this._core.init(this._canvas),this._setupEventListeners(),this._handleSizeChange();const t=this.src;t&&await this.load(t),this._isInitialized=!0,this.dispatchEvent(bz("ready",void 0))}catch(t){this._cleanupOnError(),this.dispatchEvent(bz("error",{message:`Failed to initialize: ${t instanceof Error?t.message:"Unknown error"}`,code:"INIT_FAILED"}))}}_cleanupOnError(){try{this._core&&(this._core.destroy(),this._core=null),this._canvas&&this._canvas.parentNode&&(this._canvas.parentNode.removeChild(this._canvas),this._canvas=null),this._isInitialized=!1}catch(t){}}_destroy(){if(!this._isDestroyed)try{this._hostResizeObserver&&(this._hostResizeObserver.disconnect(),this._hostResizeObserver=null),this._core&&(this._core.destroy(),this._core=null),this._canvas&&this._canvas.parentNode&&(this._canvas.parentNode.removeChild(this._canvas),this._canvas=null),this._isDestroyed=!0,this._isInitialized=!1}catch(t){}}_updateConfigFromAttributes(){const t=function(t){const e={},i=t.getAttribute("auto-focus");null!==i&&(e.autoFocus=gz(i));const s=t.getAttribute("enable-stats");null!==s&&(e.enableStats=gz(s));const n=t.getAttribute("max-splats");null!==n&&(e.maxSplats=vz(n,mz.maxSplats));const r=t.getAttribute("camera-position"),a=t.getAttribute("camera-target");if(r||a){const t=_z(r),i=_z(a);e.camera={...mz.camera,...t&&{position:t},...i&&{target:i}}}const o=t.getAttribute("enable-navigation-cube");null!==o&&(e.navigationCube={...mz.navigationCube,enabled:gz(o)});const l=t.getAttribute("navigation-cube-size");null!==l&&(e.navigationCube={...mz.navigationCube,...e.navigationCube,cubeSize:vz(l,mz.navigationCube.cubeSize)});const h=t.getAttribute("navigation-cube-transition");null!==h&&(e.navigationCube={...mz.navigationCube,...e.navigationCube,transitionDuration:vz(h,mz.navigationCube.transitionDuration)});const c=t.getAttribute("navigation-cube-parent-id");null!==c&&(e.navigationCube={...mz.navigationCube,...e.navigationCube,enabled:!0,parentElementId:c});const d=t.getAttribute("navigation-cube-rotation-speed");return null!==d&&(e.navigationCube={...mz.navigationCube,...e.navigationCube,continuousRotationSpeed:vz(d,mz.navigationCube.continuousRotationSpeed)}),e}(this);var e,i;this._config=(e=mz,i=t,{...e,...i,camera:{...e.camera,...i.camera},navigationCube:{...e.navigationCube,...i.navigationCube}})}_validateSource(t){if(!t||"string"!=typeof t)return!1;if(0===t.trim().length)return!1;try{return new URL(t),!0}catch{return!!t.startsWith("data:")||!(!t.startsWith("./")&&!t.startsWith("../")&&t.includes("://"))}}async _handleSrcChange(t){if(this._core&&t)if(this._validateSource(t))try{await this.load(t)}catch(t){await this._handleError(t,"LOAD_FAILED")}else this.dispatchEvent(bz("error",{message:`Invalid source: ${t}`,code:"INVALID_SOURCE"}))}_handleSizeChange(){if(!this._canvas)return;const t=this.width,e=this.height;if(t){const e=/(px|%|em|rem|vh|vw|vmin|vmax)$/.test(t);this.style.width=e?t:`${t}px`}else this.style.width="100%";if(e){const t=/(px|%|em|rem|vh|vw|vmin|vmax)$/.test(e);this.style.height=t?e:`${e}px`}else this.style.height="100%";this._canvas.style.width="100%",this._canvas.style.height="100%"}_handleStatsChange(){this._core}_setupEventListeners(){this._core&&(this._core.on("loading-start",t=>{this.dispatchEvent(bz("loading-start",t.detail))}),this._core.on("loading-progress",t=>{this.dispatchEvent(bz("loading-progress",t.detail))}),this._core.on("loaded",t=>{this.dispatchEvent(bz("loaded",t.detail))}),this._core.on("error",t=>{this.dispatchEvent(bz("error",t.detail))}),this._core.on("camera-change",t=>{this.dispatchEvent(bz("camera-change",t.detail))}),this._core.on("interaction-start",t=>{this.dispatchEvent(bz("interaction-start",t.detail))}),this._core.on("interaction-end",t=>{this.dispatchEvent(bz("interaction-end",t.detail))}),this._core.on("camera-mode-changed",t=>{this.dispatchEvent(bz("camera-mode-changed",t.detail))}),this._core.on("fly-camera-move",t=>{this.dispatchEvent(bz("fly-camera-move",t.detail))}),this._core.on("fly-camera-look",t=>{this.dispatchEvent(bz("fly-camera-look",t.detail))}),this._core.on("camera-fov-changed",t=>{this.dispatchEvent(bz("camera-fov-changed",t.detail))}),this._core.on("background-color-changed",t=>{this.dispatchEvent(bz("background-color-changed",t.detail))}),this._core.on("model-added",t=>{this.dispatchEvent(bz("model-added",t.detail))}),this._core.on("model-removed",t=>{this.dispatchEvent(bz("model-removed",t.detail))}),this._core.on("scene-cleared",t=>{this.dispatchEvent(bz("scene-cleared",t.detail))}))}async load(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");if("string"==typeof t){if(!this._validateSource(t))throw new Error(`Invalid source string: ${t}`)}else if(t instanceof File){if(0===t.size)throw new Error("File is empty")}else{if(!(t instanceof Blob))throw new Error("Invalid source type. Expected string, File, or Blob.");if(0===t.size)throw new Error("Blob is empty")}try{return await this._core.load(t,e)}catch(t){if(await this._handleError(t,"LOAD_FAILED"),t instanceof Error)throw new Error(`Failed to load model: ${t.message}`);throw new Error("Failed to load model: Unknown error")}}async loadFile(t,e){return this.load(t,e)}async loadBlob(t,e){return this.load(t,e)}focus(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.focus(t)}setCameraPosition(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setCameraPosition(t)}setCameraTarget(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setCameraTarget(t)}resetCamera(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.resetCamera()}clear(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.clear()}getDebugInfo(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.debugInfo()}get isReady(){return this._isInitialized&&!this._isDestroyed&&null!==this._core}get config(){return{...this._config}}async _handleError(t,e){const i="string"==typeof t?t:t?.message||"Unknown error";this.dispatchEvent(bz("error",{message:e?`${e}: ${i}`:i,code:e||"ERROR"}))}async addModel(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return await this._core.addModel(t,e)}removeModel(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.removeModel(t)}getModels(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getModels()}getModelStats(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getModelStats(t)}getAllModelStats(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getAllModelStats()}getSceneStats(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getSceneStats()}setCameraMode(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setCameraMode(t)}getCameraMode(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getCameraMode()}setFlyCameraConfig(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setFlyCameraConfig(t)}getFlyCameraConfig(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getFlyCameraConfig()}getFlyCameraState(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getFlyCameraState()}setCameraFOV(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setCameraFOV(t)}getCameraFOV(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getCameraFOV()}async animateCameraFOV(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");await this._core.animateCameraFOV(t,e)}setBackgroundColor(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setBackgroundColor(t)}getBackgroundColor(){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getBackgroundColor()}async animateBackgroundColor(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");await this._core.animateBackgroundColor(t,e)}applyTransformMatrix(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.applyTransformMatrix(t,e)}setModelPosition(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setModelPosition(t,e)}setModelRotation(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setModelRotation(t,e)}setModelScale(t,e){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.setModelScale(t,e)}getModelTransform(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");return this._core.getModelTransform(t)}resetModelTransform(t){if(!this._core)throw new Error("SplatViewerElement: Core not initialized. Call connectedCallback first.");this._core.resetModelTransform(t)}}customElements.get("splat-viewer")||customElements.define("splat-viewer",SplatViewerElement),t.SplatViewerElement=SplatViewerElement,t.default=SplatViewerElement,Object.defineProperty(t,"__esModule",{value:!0})});
|