@wemap/viewer 0.0.0-stage → 14.8.0-beta.4

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.
@@ -0,0 +1,3676 @@
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@wemap/geo"),require("@wemap/core")):typeof define==`function`&&define.amd?define([`exports`,`@wemap/geo`,`@wemap/core`],t):(e=typeof globalThis<`u`?globalThis:e||self,t((e.Wemap=e.Wemap||{},e.Wemap.Viewer={}),e.Wemap.Geo,e.Wemap.Core))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=1e3,i=1001,a=1002,o=1003,s=1004,c=1005,l=1006,u=1007,d=1008,f=1009,p=1014,m=1015,h=1016,g=1020,_=1023,v=1026,y=1027,b=2300,x=2301,S=2302,C=2400,w=2401,T=2402,E=3e3,D=3001,O=3200,k=3201,A=`srgb`,ee=`srgb-linear`,te=`display-p3`,j=`display-p3-linear`,ne=`linear`,M=`srgb`,N=`rec709`,P=7680,re=35044,ie=1035,ae=2e3,F=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let n=this._listeners;n[e]===void 0&&(n[e]=[]),n[e].indexOf(t)===-1&&n[e].push(t)}hasEventListener(e,t){if(this._listeners===void 0)return!1;let n=this._listeners;return n[e]!==void 0&&n[e].indexOf(t)!==-1}removeEventListener(e,t){if(this._listeners===void 0)return;let n=this._listeners[e];if(n!==void 0){let e=n.indexOf(t);e!==-1&&n.splice(e,1)}}dispatchEvent(e){if(this._listeners===void 0)return;let t=this._listeners[e.type];if(t!==void 0){e.target=this;let n=t.slice(0);for(let t=0,r=n.length;t<r;t++)n[t].call(this,e);e.target=null}}},I=`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`.split(`.`),oe=1234567,se=Math.PI/180,L=180/Math.PI;function R(){let e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(I[e&255]+I[e>>8&255]+I[e>>16&255]+I[e>>24&255]+`-`+I[t&255]+I[t>>8&255]+`-`+I[t>>16&15|64]+I[t>>24&255]+`-`+I[n&63|128]+I[n>>8&255]+`-`+I[n>>16&255]+I[n>>24&255]+I[r&255]+I[r>>8&255]+I[r>>16&255]+I[r>>24&255]).toLowerCase()}function z(e,t,n){return Math.max(t,Math.min(n,e))}function ce(e,t){return(e%t+t)%t}function le(e,t,n,r,i){return r+(e-t)*(i-r)/(n-t)}function ue(e,t,n){return e===t?0:(n-e)/(t-e)}function de(e,t,n){return(1-n)*e+n*t}function B(e,t,n,r){return de(e,t,1-Math.exp(-n*r))}function fe(e,t=1){return t-Math.abs(ce(e,t*2)-t)}function V(e,t,n){return e<=t?0:e>=n?1:(e=(e-t)/(n-t),e*e*(3-2*e))}function H(e,t,n){return e<=t?0:e>=n?1:(e=(e-t)/(n-t),e*e*e*(e*(e*6-15)+10))}function U(e,t){return e+Math.floor(Math.random()*(t-e+1))}function pe(e,t){return e+Math.random()*(t-e)}function W(e){return e*(.5-Math.random())}function G(e){e!==void 0&&(oe=e);let t=oe+=1831565813;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}function me(e){return e*se}function he(e){return e*L}function ge(e){return(e&e-1)==0&&e!==0}function _e(e){return 2**Math.ceil(Math.log(e)/Math.LN2)}function ve(e){return 2**Math.floor(Math.log(e)/Math.LN2)}function ye(e,t,n,r,i){let a=Math.cos,o=Math.sin,s=a(n/2),c=o(n/2),l=a((t+r)/2),u=o((t+r)/2),d=a((t-r)/2),f=o((t-r)/2),p=a((r-t)/2),m=o((r-t)/2);switch(i){case`XYX`:e.set(s*u,c*d,c*f,s*l);break;case`YZY`:e.set(c*f,s*u,c*d,s*l);break;case`ZXZ`:e.set(c*d,c*f,s*u,s*l);break;case`XZX`:e.set(s*u,c*m,c*p,s*l);break;case`YXY`:e.set(c*p,s*u,c*m,s*l);break;case`ZYZ`:e.set(c*m,c*p,s*u,s*l);break;default:console.warn(`THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: `+i)}}function be(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return e/4294967295;case Uint16Array:return e/65535;case Uint8Array:return e/255;case Int32Array:return Math.max(e/2147483647,-1);case Int16Array:return Math.max(e/32767,-1);case Int8Array:return Math.max(e/127,-1);default:throw Error(`Invalid component type.`)}}function xe(e,t){switch(t.constructor){case Float32Array:return e;case Uint32Array:return Math.round(e*4294967295);case Uint16Array:return Math.round(e*65535);case Uint8Array:return Math.round(e*255);case Int32Array:return Math.round(e*2147483647);case Int16Array:return Math.round(e*32767);case Int8Array:return Math.round(e*127);default:throw Error(`Invalid component type.`)}}var Se={DEG2RAD:se,RAD2DEG:L,generateUUID:R,clamp:z,euclideanModulo:ce,mapLinear:le,inverseLerp:ue,lerp:de,damp:B,pingpong:fe,smoothstep:V,smootherstep:H,randInt:U,randFloat:pe,randFloatSpread:W,seededRandom:G,degToRad:me,radToDeg:he,isPowerOfTwo:ge,ceilPowerOfTwo:_e,floorPowerOfTwo:ve,setQuaternionFromProperEuler:ye,normalize:xe,denormalize:be},K=class e{constructor(t=0,n=0){e.prototype.isVector2=!0,this.x=t,this.y=n}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){let t=this.x,n=this.y,r=e.elements;return this.x=r[0]*t+r[3]*n+r[6],this.y=r[1]*t+r[4]*n+r[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(z(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){let n=Math.cos(t),r=Math.sin(t),i=this.x-e.x,a=this.y-e.y;return this.x=i*n-a*r+e.x,this.y=i*r+a*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}},q=class e{constructor(t,n,r,i,a,o,s,c,l){e.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],t!==void 0&&this.set(t,n,r,i,a,o,s,c,l)}set(e,t,n,r,i,a,o,s,c){let l=this.elements;return l[0]=e,l[1]=r,l[2]=o,l[3]=t,l[4]=i,l[5]=s,l[6]=n,l[7]=a,l[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){let t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,r=t.elements,i=this.elements,a=n[0],o=n[3],s=n[6],c=n[1],l=n[4],u=n[7],d=n[2],f=n[5],p=n[8],m=r[0],h=r[3],g=r[6],_=r[1],v=r[4],y=r[7],b=r[2],x=r[5],S=r[8];return i[0]=a*m+o*_+s*b,i[3]=a*h+o*v+s*x,i[6]=a*g+o*y+s*S,i[1]=c*m+l*_+u*b,i[4]=c*h+l*v+u*x,i[7]=c*g+l*y+u*S,i[2]=d*m+f*_+p*b,i[5]=d*h+f*v+p*x,i[8]=d*g+f*y+p*S,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8];return t*a*l-t*o*c-n*i*l+n*o*s+r*i*c-r*a*s}invert(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=l*a-o*c,d=o*s-l*i,f=c*i-a*s,p=t*u+n*d+r*f;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);let m=1/p;return e[0]=u*m,e[1]=(r*c-l*n)*m,e[2]=(o*n-r*a)*m,e[3]=d*m,e[4]=(l*t-r*s)*m,e[5]=(r*i-o*t)*m,e[6]=f*m,e[7]=(n*s-c*t)*m,e[8]=(a*t-n*i)*m,this}transpose(){let e,t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){let t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,r,i,a,o){let s=Math.cos(i),c=Math.sin(i);return this.set(n*s,n*c,-n*(s*a+c*o)+a+e,-r*c,r*s,-r*(-c*a+s*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(J.makeScale(e,t)),this}rotate(e){return this.premultiply(J.makeRotation(-e)),this}translate(e,t){return this.premultiply(J.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){let t=this.elements,n=e.elements;for(let e=0;e<9;e++)if(t[e]!==n[e])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new this.constructor().fromArray(this.elements)}},J=new q;function Ce(e){for(let t=e.length-1;t>=0;--t)if(e[t]>=65535)return!0;return!1}function we(e){return document.createElementNS(`http://www.w3.org/1999/xhtml`,e)}function Te(){let e=we(`canvas`);return e.style.display=`block`,e}var Ee={};function De(e){e in Ee||(Ee[e]=!0,console.warn(e))}var Oe=new q().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),ke=new q().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),Ae={[ee]:{transfer:ne,primaries:N,toReference:e=>e,fromReference:e=>e},[A]:{transfer:M,primaries:N,toReference:e=>e.convertSRGBToLinear(),fromReference:e=>e.convertLinearToSRGB()},[j]:{transfer:ne,primaries:`p3`,toReference:e=>e.applyMatrix3(ke),fromReference:e=>e.applyMatrix3(Oe)},[te]:{transfer:M,primaries:`p3`,toReference:e=>e.convertSRGBToLinear().applyMatrix3(ke),fromReference:e=>e.applyMatrix3(Oe).convertLinearToSRGB()}},je=new Set([ee,j]),Y={enabled:!0,_workingColorSpace:ee,get legacyMode(){return console.warn(`THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150.`),!this.enabled},set legacyMode(e){console.warn(`THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150.`),this.enabled=!e},get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(e){if(!je.has(e))throw Error(`Unsupported working color space, "${e}".`);this._workingColorSpace=e},convert:function(e,t,n){if(this.enabled===!1||t===n||!t||!n)return e;let r=Ae[t].toReference,i=Ae[n].fromReference;return i(r(e))},fromWorkingColorSpace:function(e,t){return this.convert(e,this._workingColorSpace,t)},toWorkingColorSpace:function(e,t){return this.convert(e,t,this._workingColorSpace)},getPrimaries:function(e){return Ae[e].primaries},getTransfer:function(e){return e===``?ne:Ae[e].transfer}};function Me(e){return e<.04045?e*.0773993808:(e*.9478672986+.0521327014)**2.4}function Ne(e){return e<.0031308?e*12.92:1.055*e**.41666-.055}var Pe,Fe=class{static getDataURL(e){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>`u`)return e.src;let t;if(e instanceof HTMLCanvasElement)t=e;else{Pe===void 0&&(Pe=we(`canvas`)),Pe.width=e.width,Pe.height=e.height;let n=Pe.getContext(`2d`);e instanceof ImageData?n.putImageData(e,0,0):n.drawImage(e,0,0,e.width,e.height),t=Pe}return t.width>2048||t.height>2048?(console.warn(`THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons`,e),t.toDataURL(`image/jpeg`,.6)):t.toDataURL(`image/png`)}static sRGBToLinear(e){if(typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap){let t=we(`canvas`);t.width=e.width,t.height=e.height;let n=t.getContext(`2d`);n.drawImage(e,0,0,e.width,e.height);let r=n.getImageData(0,0,e.width,e.height),i=r.data;for(let e=0;e<i.length;e++)i[e]=Me(i[e]/255)*255;return n.putImageData(r,0,0),t}else if(e.data){let t=e.data.slice(0);for(let e=0;e<t.length;e++)t instanceof Uint8Array||t instanceof Uint8ClampedArray?t[e]=Math.floor(Me(t[e]/255)*255):t[e]=Me(t[e]);return{data:t,width:e.width,height:e.height}}else return console.warn(`THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.`),e}},Ie=0,Le=class{constructor(e=null){this.isSource=!0,Object.defineProperty(this,"id",{value:Ie++}),this.uuid=R(),this.data=e,this.version=0}set needsUpdate(e){e===!0&&this.version++}toJSON(e){let t=e===void 0||typeof e==`string`;if(!t&&e.images[this.uuid]!==void 0)return e.images[this.uuid];let n={uuid:this.uuid,url:``},r=this.data;if(r!==null){let e;if(Array.isArray(r)){e=[];for(let t=0,n=r.length;t<n;t++)r[t].isDataTexture?e.push(Re(r[t].image)):e.push(Re(r[t]))}else e=Re(r);n.url=e}return t||(e.images[this.uuid]=n),n}};function Re(e){return typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap?Fe.getDataURL(e):e.data?{data:Array.from(e.data),width:e.width,height:e.height,type:e.data.constructor.name}:(console.warn(`THREE.Texture: Unable to serialize Texture.`),{})}var ze=0,Be=class e extends F{constructor(t=e.DEFAULT_IMAGE,n=e.DEFAULT_MAPPING,r=i,a=i,o=l,s=d,c=_,u=f,p=e.DEFAULT_ANISOTROPY,m=``){super(),this.isTexture=!0,Object.defineProperty(this,"id",{value:ze++}),this.uuid=R(),this.name=``,this.source=new Le(t),this.mipmaps=[],this.mapping=n,this.channel=0,this.wrapS=r,this.wrapT=a,this.magFilter=o,this.minFilter=s,this.anisotropy=p,this.format=c,this.internalFormat=null,this.type=u,this.offset=new K(0,0),this.repeat=new K(1,1),this.center=new K(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new q,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,typeof m==`string`?this.colorSpace=m:(De(`THREE.Texture: Property .encoding has been replaced by .colorSpace.`),this.colorSpace=m===3001?A:``),this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1,this.needsPMREMUpdate=!1}get image(){return this.source.data}set image(e=null){this.source.data=e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}toJSON(e){let t=e===void 0||typeof e==`string`;if(!t&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];let n={metadata:{version:4.6,type:`Texture`,generator:`Texture.toJSON`},uuid:this.uuid,name:this.name,image:this.source.toJSON(e).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),t||(e.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:`dispose`})}transformUv(e){if(this.mapping!==300)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case r:e.x-=Math.floor(e.x);break;case i:e.x=e.x<0?0:1;break;case a:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x-=Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case r:e.y-=Math.floor(e.y);break;case i:e.y=e.y<0?0:1;break;case a:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y-=Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}get encoding(){return De(`THREE.Texture: Property .encoding has been replaced by .colorSpace.`),this.colorSpace===`srgb`?D:E}set encoding(e){De(`THREE.Texture: Property .encoding has been replaced by .colorSpace.`),this.colorSpace=e===3001?A:``}};Be.DEFAULT_IMAGE=null,Be.DEFAULT_MAPPING=300,Be.DEFAULT_ANISOTROPY=1;var Ve=class e{constructor(t=0,n=0,r=0,i=1){e.prototype.isVector4=!0,this.x=t,this.y=n,this.z=r,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,r){return this.x=e,this.y=t,this.z=n,this.w=r,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w===void 0?1:e.w,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){let t=this.x,n=this.y,r=this.z,i=this.w,a=e.elements;return this.x=a[0]*t+a[4]*n+a[8]*r+a[12]*i,this.y=a[1]*t+a[5]*n+a[9]*r+a[13]*i,this.z=a[2]*t+a[6]*n+a[10]*r+a[14]*i,this.w=a[3]*t+a[7]*n+a[11]*r+a[15]*i,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);let t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,r,i,a=.01,o=.1,s=e.elements,c=s[0],l=s[4],u=s[8],d=s[1],f=s[5],p=s[9],m=s[2],h=s[6],g=s[10];if(Math.abs(l-d)<a&&Math.abs(u-m)<a&&Math.abs(p-h)<a){if(Math.abs(l+d)<o&&Math.abs(u+m)<o&&Math.abs(p+h)<o&&Math.abs(c+f+g-3)<o)return this.set(1,0,0,0),this;t=Math.PI;let e=(c+1)/2,s=(f+1)/2,_=(g+1)/2,v=(l+d)/4,y=(u+m)/4,b=(p+h)/4;return e>s&&e>_?e<a?(n=0,r=.707106781,i=.707106781):(n=Math.sqrt(e),r=v/n,i=y/n):s>_?s<a?(n=.707106781,r=0,i=.707106781):(r=Math.sqrt(s),n=v/r,i=b/r):_<a?(n=.707106781,r=.707106781,i=0):(i=Math.sqrt(_),n=y/i,r=b/i),this.set(n,r,i,t),this}let _=Math.sqrt((h-p)*(h-p)+(u-m)*(u-m)+(d-l)*(d-l));return Math.abs(_)<.001&&(_=1),this.x=(h-p)/_,this.y=(u-m)/_,this.z=(d-l)/_,this.w=Math.acos((c+f+g-1)/2),this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}},He=class extends F{constructor(e=1,t=1,n={}){super(),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=1,this.scissor=new Ve(0,0,e,t),this.scissorTest=!1,this.viewport=new Ve(0,0,e,t);let r={width:e,height:t,depth:1};n.encoding!==void 0&&(De(`THREE.WebGLRenderTarget: option.encoding has been replaced by option.colorSpace.`),n.colorSpace=n.encoding===3001?A:``),n=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:l,depthBuffer:!0,stencilBuffer:!1,depthTexture:null,samples:0},n),this.texture=new Be(r,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.flipY=!1,this.texture.generateMipmaps=n.generateMipmaps,this.texture.internalFormat=n.internalFormat,this.depthBuffer=n.depthBuffer,this.stencilBuffer=n.stencilBuffer,this.depthTexture=n.depthTexture,this.samples=n.samples}setSize(e,t,n=1){(this.width!==e||this.height!==t||this.depth!==n)&&(this.width=e,this.height=t,this.depth=n,this.texture.image.width=e,this.texture.image.height=t,this.texture.image.depth=n,this.dispose()),this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.texture=e.texture.clone(),this.texture.isRenderTargetTexture=!0;let t=Object.assign({},e.texture.image);return this.texture.source=new Le(t),this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this}dispose(){this.dispatchEvent({type:`dispose`})}},Ue=class extends He{constructor(e=1,t=1,n={}){super(e,t,n),this.isWebGLRenderTarget=!0}},We=class extends Be{constructor(e=null,t=1,n=1,r=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:n,depth:r},this.magFilter=o,this.minFilter=o,this.wrapR=i,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}},Ge=class extends Be{constructor(e=null,t=1,n=1,r=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:n,depth:r},this.magFilter=o,this.minFilter=o,this.wrapR=i,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}},Ke=class{constructor(e=0,t=0,n=0,r=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=r}static slerpFlat(e,t,n,r,i,a,o){let s=n[r+0],c=n[r+1],l=n[r+2],u=n[r+3],d=i[a+0],f=i[a+1],p=i[a+2],m=i[a+3];if(o===0){e[t+0]=s,e[t+1]=c,e[t+2]=l,e[t+3]=u;return}if(o===1){e[t+0]=d,e[t+1]=f,e[t+2]=p,e[t+3]=m;return}if(u!==m||s!==d||c!==f||l!==p){let e=1-o,t=s*d+c*f+l*p+u*m,n=t>=0?1:-1,r=1-t*t;if(r>2**-52){let i=Math.sqrt(r),a=Math.atan2(i,t*n);e=Math.sin(e*a)/i,o=Math.sin(o*a)/i}let i=o*n;if(s=s*e+d*i,c=c*e+f*i,l=l*e+p*i,u=u*e+m*i,e===1-o){let e=1/Math.sqrt(s*s+c*c+l*l+u*u);s*=e,c*=e,l*=e,u*=e}}e[t]=s,e[t+1]=c,e[t+2]=l,e[t+3]=u}static multiplyQuaternionsFlat(e,t,n,r,i,a){let o=n[r],s=n[r+1],c=n[r+2],l=n[r+3],u=i[a],d=i[a+1],f=i[a+2],p=i[a+3];return e[t]=o*p+l*u+s*f-c*d,e[t+1]=s*p+l*d+c*u-o*f,e[t+2]=c*p+l*f+o*d-s*u,e[t+3]=l*p-o*u-s*d-c*f,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,r){return this._x=e,this._y=t,this._z=n,this._w=r,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t){let n=e._x,r=e._y,i=e._z,a=e._order,o=Math.cos,s=Math.sin,c=o(n/2),l=o(r/2),u=o(i/2),d=s(n/2),f=s(r/2),p=s(i/2);switch(a){case`XYZ`:this._x=d*l*u+c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u-d*f*p;break;case`YXZ`:this._x=d*l*u+c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u+d*f*p;break;case`ZXY`:this._x=d*l*u-c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u-d*f*p;break;case`ZYX`:this._x=d*l*u-c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u+d*f*p;break;case`YZX`:this._x=d*l*u+c*f*p,this._y=c*f*u+d*l*p,this._z=c*l*p-d*f*u,this._w=c*l*u-d*f*p;break;case`XZY`:this._x=d*l*u-c*f*p,this._y=c*f*u-d*l*p,this._z=c*l*p+d*f*u,this._w=c*l*u+d*f*p;break;default:console.warn(`THREE.Quaternion: .setFromEuler() encountered an unknown order: `+a)}return t!==!1&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let n=t/2,r=Math.sin(n);return this._x=e.x*r,this._y=e.y*r,this._z=e.z*r,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,n=t[0],r=t[4],i=t[8],a=t[1],o=t[5],s=t[9],c=t[2],l=t[6],u=t[10],d=n+o+u;if(d>0){let e=.5/Math.sqrt(d+1);this._w=.25/e,this._x=(l-s)*e,this._y=(i-c)*e,this._z=(a-r)*e}else if(n>o&&n>u){let e=2*Math.sqrt(1+n-o-u);this._w=(l-s)/e,this._x=.25*e,this._y=(r+a)/e,this._z=(i+c)/e}else if(o>u){let e=2*Math.sqrt(1+o-n-u);this._w=(i-c)/e,this._x=(r+a)/e,this._y=.25*e,this._z=(s+l)/e}else{let e=2*Math.sqrt(1+u-n-o);this._w=(a-r)/e,this._x=(i+c)/e,this._y=(s+l)/e,this._z=.25*e}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<2**-52?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(z(this.dot(e),-1,1)))}rotateTowards(e,t){let n=this.angleTo(e);if(n===0)return this;let r=Math.min(1,t/n);return this.slerp(e,r),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(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x*=e,this._y*=e,this._z*=e,this._w*=e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){let n=e._x,r=e._y,i=e._z,a=e._w,o=t._x,s=t._y,c=t._z,l=t._w;return this._x=n*l+a*o+r*c-i*s,this._y=r*l+a*s+i*o-n*c,this._z=i*l+a*c+n*s-r*o,this._w=a*l-n*o-r*s-i*c,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);let n=this._x,r=this._y,i=this._z,a=this._w,o=a*e._w+n*e._x+r*e._y+i*e._z;if(o<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,o=-o):this.copy(e),o>=1)return this._w=a,this._x=n,this._y=r,this._z=i,this;let s=1-o*o;if(s<=2**-52){let e=1-t;return this._w=e*a+t*this._w,this._x=e*n+t*this._x,this._y=e*r+t*this._y,this._z=e*i+t*this._z,this.normalize(),this._onChangeCallback(),this}let c=Math.sqrt(s),l=Math.atan2(c,o),u=Math.sin((1-t)*l)/c,d=Math.sin(t*l)/c;return this._w=a*u+this._w*d,this._x=n*u+this._x*d,this._y=r*u+this._y*d,this._z=i*u+this._z*d,this._onChangeCallback(),this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){let e=Math.random(),t=Math.sqrt(1-e),n=Math.sqrt(e),r=2*Math.PI*Math.random(),i=2*Math.PI*Math.random();return this.set(t*Math.cos(r),n*Math.sin(i),n*Math.cos(i),t*Math.sin(r))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}},X=class e{constructor(t=0,n=0,r=0){e.prototype.isVector3=!0,this.x=t,this.y=n,this.z=r}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw Error(`index is out of range: `+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw Error(`index is out of range: `+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Je.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Je.setFromAxisAngle(e,t))}applyMatrix3(e){let t=this.x,n=this.y,r=this.z,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6]*r,this.y=i[1]*t+i[4]*n+i[7]*r,this.z=i[2]*t+i[5]*n+i[8]*r,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){let t=this.x,n=this.y,r=this.z,i=e.elements,a=1/(i[3]*t+i[7]*n+i[11]*r+i[15]);return this.x=(i[0]*t+i[4]*n+i[8]*r+i[12])*a,this.y=(i[1]*t+i[5]*n+i[9]*r+i[13])*a,this.z=(i[2]*t+i[6]*n+i[10]*r+i[14])*a,this}applyQuaternion(e){let t=this.x,n=this.y,r=this.z,i=e.x,a=e.y,o=e.z,s=e.w,c=2*(a*r-o*n),l=2*(o*t-i*r),u=2*(i*n-a*t);return this.x=t+s*c+a*u-o*l,this.y=n+s*l+o*c-i*u,this.z=r+s*u+i*l-a*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){let t=this.x,n=this.y,r=this.z,i=e.elements;return this.x=i[0]*t+i[4]*n+i[8]*r,this.y=i[1]*t+i[5]*n+i[9]*r,this.z=i[2]*t+i[6]*n+i[10]*r,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){let n=e.x,r=e.y,i=e.z,a=t.x,o=t.y,s=t.z;return this.x=r*s-i*o,this.y=i*a-n*s,this.z=n*o-r*a,this}projectOnVector(e){let t=e.lengthSq();if(t===0)return this.set(0,0,0);let n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return qe.copy(this).projectOnVector(e),this.sub(qe)}reflect(e){return this.sub(qe.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(z(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y,r=this.z-e.z;return t*t+n*n+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,n){let r=Math.sin(t)*e;return this.x=r*Math.sin(n),this.y=Math.cos(t)*e,this.z=r*Math.cos(n),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){let t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),r=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=r,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){let e=(Math.random()-.5)*2,t=Math.random()*Math.PI*2,n=Math.sqrt(1-e**2);return this.x=n*Math.cos(t),this.y=n*Math.sin(t),this.z=e,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},qe=new X,Je=new Ke,Ye=class{constructor(e=new X(1/0,1/0,1/0),t=new X(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t+=3)this.expandByPoint(Ze.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,n=e.count;t<n;t++)this.expandByPoint(Ze.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){let n=Ze.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(n),this.max.copy(e).add(n),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.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(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);let n=e.geometry;if(n!==void 0){let r=n.getAttribute(`position`);if(t===!0&&r!==void 0&&e.isInstancedMesh!==!0)for(let t=0,n=r.count;t<n;t++)e.isMesh===!0?e.getVertexPosition(t,Ze):Ze.fromBufferAttribute(r,t),Ze.applyMatrix4(e.matrixWorld),this.expandByPoint(Ze);else e.boundingBox===void 0?(n.boundingBox===null&&n.computeBoundingBox(),Qe.copy(n.boundingBox)):(e.boundingBox===null&&e.computeBoundingBox(),Qe.copy(e.boundingBox)),Qe.applyMatrix4(e.matrixWorld),this.union(Qe)}let r=e.children;for(let e=0,n=r.length;e<n;e++)this.expandByObject(r[e],t);return this}containsPoint(e){return!(e.x<this.min.x||e.x>this.max.x||e.y<this.min.y||e.y>this.max.y||e.z<this.min.z||e.z>this.max.z)}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return!(e.max.x<this.min.x||e.min.x>this.max.x||e.max.y<this.min.y||e.min.y>this.max.y||e.max.z<this.min.z||e.min.z>this.max.z)}intersectsSphere(e){return this.clampPoint(e.center,Ze),Ze.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,n;return e.normal.x>0?(t=e.normal.x*this.min.x,n=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,n=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,n+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,n+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,n+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,n+=e.normal.z*this.min.z),t<=-e.constant&&n>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(at),ot.subVectors(this.max,at),$e.subVectors(e.a,at),et.subVectors(e.b,at),tt.subVectors(e.c,at),nt.subVectors(et,$e),rt.subVectors(tt,et),it.subVectors($e,tt);let t=[0,-nt.z,nt.y,0,-rt.z,rt.y,0,-it.z,it.y,nt.z,0,-nt.x,rt.z,0,-rt.x,it.z,0,-it.x,-nt.y,nt.x,0,-rt.y,rt.x,0,-it.y,it.x,0];return!lt(t,$e,et,tt,ot)||(t=[1,0,0,0,1,0,0,0,1],!lt(t,$e,et,tt,ot))?!1:(st.crossVectors(nt,rt),t=[st.x,st.y,st.z],lt(t,$e,et,tt,ot))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,Ze).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(Ze).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(Xe[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Xe[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Xe[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Xe[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Xe[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Xe[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Xe[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Xe[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Xe),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}},Xe=[new X,new X,new X,new X,new X,new X,new X,new X],Ze=new X,Qe=new Ye,$e=new X,et=new X,tt=new X,nt=new X,rt=new X,it=new X,at=new X,ot=new X,st=new X,ct=new X;function lt(e,t,n,r,i){for(let a=0,o=e.length-3;a<=o;a+=3){ct.fromArray(e,a);let o=i.x*Math.abs(ct.x)+i.y*Math.abs(ct.y)+i.z*Math.abs(ct.z),s=t.dot(ct),c=n.dot(ct),l=r.dot(ct);if(Math.max(-Math.max(s,c,l),Math.min(s,c,l))>o)return!1}return!0}var ut=new Ye,dt=new X,ft=new X,pt=class{constructor(e=new X,t=-1){this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){let n=this.center;t===void 0?ut.setFromPoints(e).getCenter(n):n.copy(t);let r=0;for(let t=0,i=e.length;t<i;t++)r=Math.max(r,n.distanceToSquared(e[t]));return this.radius=Math.sqrt(r),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){let t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){let n=this.center.distanceToSquared(e);return t.copy(e),n>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius*=e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;dt.subVectors(e,this.center);let t=dt.lengthSq();if(t>this.radius*this.radius){let e=Math.sqrt(t),n=(e-this.radius)*.5;this.center.addScaledVector(dt,n/e),this.radius+=n}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(ft.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(dt.copy(e.center).add(ft)),this.expandByPoint(dt.copy(e.center).sub(ft))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}},mt=new X,ht=new X,gt=new X,_t=new X,vt=new X,yt=new X,bt=new X,xt=class{constructor(e=new X,t=new X(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,mt)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);let n=t.dot(this.direction);return n<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){let t=mt.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(mt.copy(this.origin).addScaledVector(this.direction,t),mt.distanceToSquared(e))}distanceSqToSegment(e,t,n,r){ht.copy(e).add(t).multiplyScalar(.5),gt.copy(t).sub(e).normalize(),_t.copy(this.origin).sub(ht);let i=e.distanceTo(t)*.5,a=-this.direction.dot(gt),o=_t.dot(this.direction),s=-_t.dot(gt),c=_t.lengthSq(),l=Math.abs(1-a*a),u,d,f,p;if(l>0)if(u=a*s-o,d=a*o-s,p=i*l,u>=0)if(d>=-p)if(d<=p){let e=1/l;u*=e,d*=e,f=u*(u+a*d+2*o)+d*(a*u+d+2*s)+c}else d=i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;else d=-i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;else d<=-p?(u=Math.max(0,-(-a*i+o)),d=u>0?-i:Math.min(Math.max(-i,-s),i),f=-u*u+d*(d+2*s)+c):d<=p?(u=0,d=Math.min(Math.max(-i,-s),i),f=d*(d+2*s)+c):(u=Math.max(0,-(a*i+o)),d=u>0?i:Math.min(Math.max(-i,-s),i),f=-u*u+d*(d+2*s)+c);else d=a>0?-i:i,u=Math.max(0,-(a*d+o)),f=-u*u+d*(d+2*s)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,u),r&&r.copy(ht).addScaledVector(gt,d),f}intersectSphere(e,t){mt.subVectors(e.center,this.origin);let n=mt.dot(this.direction),r=mt.dot(mt)-n*n,i=e.radius*e.radius;if(r>i)return null;let a=Math.sqrt(i-r),o=n-a,s=n+a;return s<0?null:o<0?this.at(s,t):this.at(o,t)}intersectsSphere(e){return this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){let t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;let n=-(this.origin.dot(e.normal)+e.constant)/t;return n>=0?n:null}intersectPlane(e,t){let n=this.distanceToPlane(e);return n===null?null:this.at(n,t)}intersectsPlane(e){let t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let n,r,i,a,o,s,c=1/this.direction.x,l=1/this.direction.y,u=1/this.direction.z,d=this.origin;return c>=0?(n=(e.min.x-d.x)*c,r=(e.max.x-d.x)*c):(n=(e.max.x-d.x)*c,r=(e.min.x-d.x)*c),l>=0?(i=(e.min.y-d.y)*l,a=(e.max.y-d.y)*l):(i=(e.max.y-d.y)*l,a=(e.min.y-d.y)*l),n>a||i>r||((i>n||isNaN(n))&&(n=i),(a<r||isNaN(r))&&(r=a),u>=0?(o=(e.min.z-d.z)*u,s=(e.max.z-d.z)*u):(o=(e.max.z-d.z)*u,s=(e.min.z-d.z)*u),n>s||o>r)||((o>n||n!==n)&&(n=o),(s<r||r!==r)&&(r=s),r<0)?null:this.at(n>=0?n:r,t)}intersectsBox(e){return this.intersectBox(e,mt)!==null}intersectTriangle(e,t,n,r,i){vt.subVectors(t,e),yt.subVectors(n,e),bt.crossVectors(vt,yt);let a=this.direction.dot(bt),o;if(a>0){if(r)return null;o=1}else if(a<0)o=-1,a=-a;else return null;_t.subVectors(this.origin,e);let s=o*this.direction.dot(yt.crossVectors(_t,yt));if(s<0)return null;let c=o*this.direction.dot(vt.cross(_t));if(c<0||s+c>a)return null;let l=-o*_t.dot(bt);return l<0?null:this.at(l/a,i)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}},St=class e{constructor(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g){e.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],t!==void 0&&this.set(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g)}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){let g=this.elements;return g[0]=e,g[4]=t,g[8]=n,g[12]=r,g[1]=i,g[5]=a,g[9]=o,g[13]=s,g[2]=c,g[6]=l,g[10]=u,g[14]=d,g[3]=f,g[7]=p,g[11]=m,g[15]=h,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 e().fromArray(this.elements)}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){let t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){let t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){let t=this.elements,n=e.elements,r=1/Ct.setFromMatrixColumn(e,0).length(),i=1/Ct.setFromMatrixColumn(e,1).length(),a=1/Ct.setFromMatrixColumn(e,2).length();return t[0]=n[0]*r,t[1]=n[1]*r,t[2]=n[2]*r,t[3]=0,t[4]=n[4]*i,t[5]=n[5]*i,t[6]=n[6]*i,t[7]=0,t[8]=n[8]*a,t[9]=n[9]*a,t[10]=n[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){let t=this.elements,n=e.x,r=e.y,i=e.z,a=Math.cos(n),o=Math.sin(n),s=Math.cos(r),c=Math.sin(r),l=Math.cos(i),u=Math.sin(i);if(e.order===`XYZ`){let e=a*l,n=a*u,r=o*l,i=o*u;t[0]=s*l,t[4]=-s*u,t[8]=c,t[1]=n+r*c,t[5]=e-i*c,t[9]=-o*s,t[2]=i-e*c,t[6]=r+n*c,t[10]=a*s}else if(e.order===`YXZ`){let e=s*l,n=s*u,r=c*l,i=c*u;t[0]=e+i*o,t[4]=r*o-n,t[8]=a*c,t[1]=a*u,t[5]=a*l,t[9]=-o,t[2]=n*o-r,t[6]=i+e*o,t[10]=a*s}else if(e.order===`ZXY`){let e=s*l,n=s*u,r=c*l,i=c*u;t[0]=e-i*o,t[4]=-a*u,t[8]=r+n*o,t[1]=n+r*o,t[5]=a*l,t[9]=i-e*o,t[2]=-a*c,t[6]=o,t[10]=a*s}else if(e.order===`ZYX`){let e=a*l,n=a*u,r=o*l,i=o*u;t[0]=s*l,t[4]=r*c-n,t[8]=e*c+i,t[1]=s*u,t[5]=i*c+e,t[9]=n*c-r,t[2]=-c,t[6]=o*s,t[10]=a*s}else if(e.order===`YZX`){let e=a*s,n=a*c,r=o*s,i=o*c;t[0]=s*l,t[4]=i-e*u,t[8]=r*u+n,t[1]=u,t[5]=a*l,t[9]=-o*l,t[2]=-c*l,t[6]=n*u+r,t[10]=e-i*u}else if(e.order===`XZY`){let e=a*s,n=a*c,r=o*s,i=o*c;t[0]=s*l,t[4]=-u,t[8]=c*l,t[1]=e*u+i,t[5]=a*l,t[9]=n*u-r,t[2]=r*u-n,t[6]=o*l,t[10]=i*u+e}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(Tt,e,Et)}lookAt(e,t,n){let r=this.elements;return kt.subVectors(e,t),kt.lengthSq()===0&&(kt.z=1),kt.normalize(),Dt.crossVectors(n,kt),Dt.lengthSq()===0&&(Math.abs(n.z)===1?kt.x+=1e-4:kt.z+=1e-4,kt.normalize(),Dt.crossVectors(n,kt)),Dt.normalize(),Ot.crossVectors(kt,Dt),r[0]=Dt.x,r[4]=Ot.x,r[8]=kt.x,r[1]=Dt.y,r[5]=Ot.y,r[9]=kt.y,r[2]=Dt.z,r[6]=Ot.z,r[10]=kt.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,r=t.elements,i=this.elements,a=n[0],o=n[4],s=n[8],c=n[12],l=n[1],u=n[5],d=n[9],f=n[13],p=n[2],m=n[6],h=n[10],g=n[14],_=n[3],v=n[7],y=n[11],b=n[15],x=r[0],S=r[4],C=r[8],w=r[12],T=r[1],E=r[5],D=r[9],O=r[13],k=r[2],A=r[6],ee=r[10],te=r[14],j=r[3],ne=r[7],M=r[11],N=r[15];return i[0]=a*x+o*T+s*k+c*j,i[4]=a*S+o*E+s*A+c*ne,i[8]=a*C+o*D+s*ee+c*M,i[12]=a*w+o*O+s*te+c*N,i[1]=l*x+u*T+d*k+f*j,i[5]=l*S+u*E+d*A+f*ne,i[9]=l*C+u*D+d*ee+f*M,i[13]=l*w+u*O+d*te+f*N,i[2]=p*x+m*T+h*k+g*j,i[6]=p*S+m*E+h*A+g*ne,i[10]=p*C+m*D+h*ee+g*M,i[14]=p*w+m*O+h*te+g*N,i[3]=_*x+v*T+y*k+b*j,i[7]=_*S+v*E+y*A+b*ne,i[11]=_*C+v*D+y*ee+b*M,i[15]=_*w+v*O+y*te+b*N,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[4],r=e[8],i=e[12],a=e[1],o=e[5],s=e[9],c=e[13],l=e[2],u=e[6],d=e[10],f=e[14],p=e[3],m=e[7],h=e[11],g=e[15];return p*(+i*s*u-r*c*u-i*o*d+n*c*d+r*o*f-n*s*f)+m*(+t*s*f-t*c*d+i*a*d-r*a*f+r*c*l-i*s*l)+h*(+t*c*u-t*o*f-i*a*u+n*a*f+i*o*l-n*c*l)+g*(-r*o*l-t*s*u+t*o*d+r*a*u-n*a*d+n*s*l)}transpose(){let e=this.elements,t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){let r=this.elements;return e.isVector3?(r[12]=e.x,r[13]=e.y,r[14]=e.z):(r[12]=e,r[13]=t,r[14]=n),this}invert(){let e=this.elements,t=e[0],n=e[1],r=e[2],i=e[3],a=e[4],o=e[5],s=e[6],c=e[7],l=e[8],u=e[9],d=e[10],f=e[11],p=e[12],m=e[13],h=e[14],g=e[15],_=u*h*c-m*d*c+m*s*f-o*h*f-u*s*g+o*d*g,v=p*d*c-l*h*c-p*s*f+a*h*f+l*s*g-a*d*g,y=l*m*c-p*u*c+p*o*f-a*m*f-l*o*g+a*u*g,b=p*u*s-l*m*s-p*o*d+a*m*d+l*o*h-a*u*h,x=t*_+n*v+r*y+i*b;if(x===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let S=1/x;return e[0]=_*S,e[1]=(m*d*i-u*h*i-m*r*f+n*h*f+u*r*g-n*d*g)*S,e[2]=(o*h*i-m*s*i+m*r*c-n*h*c-o*r*g+n*s*g)*S,e[3]=(u*s*i-o*d*i-u*r*c+n*d*c+o*r*f-n*s*f)*S,e[4]=v*S,e[5]=(l*h*i-p*d*i+p*r*f-t*h*f-l*r*g+t*d*g)*S,e[6]=(p*s*i-a*h*i-p*r*c+t*h*c+a*r*g-t*s*g)*S,e[7]=(a*d*i-l*s*i+l*r*c-t*d*c-a*r*f+t*s*f)*S,e[8]=y*S,e[9]=(p*u*i-l*m*i-p*n*f+t*m*f+l*n*g-t*u*g)*S,e[10]=(a*m*i-p*o*i+p*n*c-t*m*c-a*n*g+t*o*g)*S,e[11]=(l*o*i-a*u*i-l*n*c+t*u*c+a*n*f-t*o*f)*S,e[12]=b*S,e[13]=(l*m*r-p*u*r+p*n*d-t*m*d-l*n*h+t*u*h)*S,e[14]=(p*o*r-a*m*r-p*n*s+t*m*s+a*n*h-t*o*h)*S,e[15]=(a*u*r-l*o*r+l*n*s-t*u*s-a*n*d+t*o*d)*S,this}scale(e){let t=this.elements,n=e.x,r=e.y,i=e.z;return t[0]*=n,t[4]*=r,t[8]*=i,t[1]*=n,t[5]*=r,t[9]*=i,t[2]*=n,t[6]*=r,t[10]*=i,t[3]*=n,t[7]*=r,t[11]*=i,this}getMaxScaleOnAxis(){let e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],r=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,r))}makeTranslation(e,t,n){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){let t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){let n=Math.cos(t),r=Math.sin(t),i=1-n,a=e.x,o=e.y,s=e.z,c=i*a,l=i*o;return this.set(c*a+n,c*o-r*s,c*s+r*o,0,c*o+r*s,l*o+n,l*s-r*a,0,c*s-r*o,l*s+r*a,i*s*s+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,r,i,a){return this.set(1,n,i,0,e,1,a,0,t,r,1,0,0,0,0,1),this}compose(e,t,n){let r=this.elements,i=t._x,a=t._y,o=t._z,s=t._w,c=i+i,l=a+a,u=o+o,d=i*c,f=i*l,p=i*u,m=a*l,h=a*u,g=o*u,_=s*c,v=s*l,y=s*u,b=n.x,x=n.y,S=n.z;return r[0]=(1-(m+g))*b,r[1]=(f+y)*b,r[2]=(p-v)*b,r[3]=0,r[4]=(f-y)*x,r[5]=(1-(d+g))*x,r[6]=(h+_)*x,r[7]=0,r[8]=(p+v)*S,r[9]=(h-_)*S,r[10]=(1-(d+m))*S,r[11]=0,r[12]=e.x,r[13]=e.y,r[14]=e.z,r[15]=1,this}decompose(e,t,n){let r=this.elements,i=Ct.set(r[0],r[1],r[2]).length(),a=Ct.set(r[4],r[5],r[6]).length(),o=Ct.set(r[8],r[9],r[10]).length();this.determinant()<0&&(i=-i),e.x=r[12],e.y=r[13],e.z=r[14],wt.copy(this);let s=1/i,c=1/a,l=1/o;return wt.elements[0]*=s,wt.elements[1]*=s,wt.elements[2]*=s,wt.elements[4]*=c,wt.elements[5]*=c,wt.elements[6]*=c,wt.elements[8]*=l,wt.elements[9]*=l,wt.elements[10]*=l,t.setFromRotationMatrix(wt),n.x=i,n.y=a,n.z=o,this}makePerspective(e,t,n,r,i,a,o=ae){let s=this.elements,c=2*i/(t-e),l=2*i/(n-r),u=(t+e)/(t-e),d=(n+r)/(n-r),f,p;if(o===2e3)f=-(a+i)/(a-i),p=-2*a*i/(a-i);else if(o===2001)f=-a/(a-i),p=-a*i/(a-i);else throw Error(`THREE.Matrix4.makePerspective(): Invalid coordinate system: `+o);return s[0]=c,s[4]=0,s[8]=u,s[12]=0,s[1]=0,s[5]=l,s[9]=d,s[13]=0,s[2]=0,s[6]=0,s[10]=f,s[14]=p,s[3]=0,s[7]=0,s[11]=-1,s[15]=0,this}makeOrthographic(e,t,n,r,i,a,o=ae){let s=this.elements,c=1/(t-e),l=1/(n-r),u=1/(a-i),d=(t+e)*c,f=(n+r)*l,p,m;if(o===2e3)p=(a+i)*u,m=-2*u;else if(o===2001)p=i*u,m=-1*u;else throw Error(`THREE.Matrix4.makeOrthographic(): Invalid coordinate system: `+o);return s[0]=2*c,s[4]=0,s[8]=0,s[12]=-d,s[1]=0,s[5]=2*l,s[9]=0,s[13]=-f,s[2]=0,s[6]=0,s[10]=m,s[14]=-p,s[3]=0,s[7]=0,s[11]=0,s[15]=1,this}equals(e){let t=this.elements,n=e.elements;for(let e=0;e<16;e++)if(t[e]!==n[e])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}},Ct=new X,wt=new St,Tt=new X(0,0,0),Et=new X(1,1,1),Dt=new X,Ot=new X,kt=new X,At=new St,jt=new Ke,Mt=class e{constructor(t=0,n=0,r=0,i=e.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=n,this._z=r,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,r=this._order){return this._x=e,this._y=t,this._z=n,this._order=r,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){let r=e.elements,i=r[0],a=r[4],o=r[8],s=r[1],c=r[5],l=r[9],u=r[2],d=r[6],f=r[10];switch(t){case`XYZ`:this._y=Math.asin(z(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-l,f),this._z=Math.atan2(-a,i)):(this._x=Math.atan2(d,c),this._z=0);break;case`YXZ`:this._x=Math.asin(-z(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(s,c)):(this._y=Math.atan2(-u,i),this._z=0);break;case`ZXY`:this._x=Math.asin(z(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-a,c)):(this._y=0,this._z=Math.atan2(s,i));break;case`ZYX`:this._y=Math.asin(-z(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,f),this._z=Math.atan2(s,i)):(this._x=0,this._z=Math.atan2(-a,c));break;case`YZX`:this._z=Math.asin(z(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(-l,c),this._y=Math.atan2(-u,i)):(this._x=0,this._y=Math.atan2(o,f));break;case`XZY`:this._z=Math.asin(-z(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,c),this._y=Math.atan2(o,i)):(this._x=Math.atan2(-l,f),this._y=0);break;default:console.warn(`THREE.Euler: .setFromRotationMatrix() encountered an unknown order: `+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return At.makeRotationFromQuaternion(e),this.setFromRotationMatrix(At,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return jt.setFromEuler(this),this.setFromQuaternion(jt,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}};Mt.DEFAULT_ORDER=`XYZ`;var Nt=class{constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!=0}},Pt=0,Ft=new X,It=new Ke,Lt=new St,Rt=new X,zt=new X,Bt=new X,Vt=new Ke,Ht=new X(1,0,0),Ut=new X(0,1,0),Wt=new X(0,0,1),Gt={type:`added`},Kt={type:`removed`},qt=class e extends F{constructor(){super(),this.isObject3D=!0,Object.defineProperty(this,"id",{value:Pt++}),this.uuid=R(),this.name=``,this.type=`Object3D`,this.parent=null,this.children=[],this.up=e.DEFAULT_UP.clone();let t=new X,n=new Mt,r=new Ke,i=new X(1,1,1);function a(){r.setFromEuler(n,!1)}function o(){n.setFromQuaternion(r,void 0,!1)}n._onChange(a),r._onChange(o),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:n},quaternion:{configurable:!0,enumerable:!0,value:r},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new St},normalMatrix:{value:new q}}),this.matrix=new St,this.matrixWorld=new St,this.matrixAutoUpdate=e.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=e.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new Nt,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeShadow(){}onAfterShadow(){}onBeforeRender(){}onAfterRender(){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return It.setFromAxisAngle(e,t),this.quaternion.multiply(It),this}rotateOnWorldAxis(e,t){return It.setFromAxisAngle(e,t),this.quaternion.premultiply(It),this}rotateX(e){return this.rotateOnAxis(Ht,e)}rotateY(e){return this.rotateOnAxis(Ut,e)}rotateZ(e){return this.rotateOnAxis(Wt,e)}translateOnAxis(e,t){return Ft.copy(e).applyQuaternion(this.quaternion),this.position.add(Ft.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(Ht,e)}translateY(e){return this.translateOnAxis(Ut,e)}translateZ(e){return this.translateOnAxis(Wt,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(Lt.copy(this.matrixWorld).invert())}lookAt(e,t,n){e.isVector3?Rt.copy(e):Rt.set(e,t,n);let r=this.parent;this.updateWorldMatrix(!0,!1),zt.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?Lt.lookAt(zt,Rt,this.up):Lt.lookAt(Rt,zt,this.up),this.quaternion.setFromRotationMatrix(Lt),r&&(Lt.extractRotation(r.matrixWorld),It.setFromRotationMatrix(Lt),this.quaternion.premultiply(It.invert()))}add(e){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return e===this?(console.error(`THREE.Object3D.add: object can't be added as a child of itself.`,e),this):(e&&e.isObject3D?(e.parent!==null&&e.parent.remove(e),e.parent=this,this.children.push(e),e.dispatchEvent(Gt)):console.error(`THREE.Object3D.add: object not an instance of THREE.Object3D.`,e),this)}remove(e){if(arguments.length>1){for(let e=0;e<arguments.length;e++)this.remove(arguments[e]);return this}let t=this.children.indexOf(e);return t!==-1&&(e.parent=null,this.children.splice(t,1),e.dispatchEvent(Kt)),this}removeFromParent(){let e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),Lt.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),Lt.multiply(e.parent.matrixWorld)),e.applyMatrix4(Lt),this.add(e),e.updateWorldMatrix(!1,!0),this}getObjectById(e){return this.getObjectByProperty(`id`,e)}getObjectByName(e){return this.getObjectByProperty(`name`,e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let n=0,r=this.children.length;n<r;n++){let r=this.children[n].getObjectByProperty(e,t);if(r!==void 0)return r}}getObjectsByProperty(e,t,n=[]){this[e]===t&&n.push(this);let r=this.children;for(let i=0,a=r.length;i<a;i++)r[i].getObjectsByProperty(e,t,n);return n}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(zt,e,Bt),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(zt,Vt,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);let t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}raycast(){}traverse(e){e(this);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);let t=this.children;for(let n=0,r=t.length;n<r;n++)t[n].traverseVisible(e)}traverseAncestors(e){let t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1,e=!0);let t=this.children;for(let n=0,r=t.length;n<r;n++){let r=t[n];(r.matrixWorldAutoUpdate===!0||e===!0)&&r.updateMatrixWorld(e)}}updateWorldMatrix(e,t){let n=this.parent;if(e===!0&&n!==null&&n.matrixWorldAutoUpdate===!0&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),t===!0){let e=this.children;for(let t=0,n=e.length;t<n;t++){let n=e[t];n.matrixWorldAutoUpdate===!0&&n.updateWorldMatrix(!1,!0)}}}toJSON(e){let t=e===void 0||typeof e==`string`,n={};t&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n.metadata={version:4.6,type:`Object`,generator:`Object3D.toJSON`});let r={};r.uuid=this.uuid,r.type=this.type,this.name!==``&&(r.name=this.name),this.castShadow===!0&&(r.castShadow=!0),this.receiveShadow===!0&&(r.receiveShadow=!0),this.visible===!1&&(r.visible=!1),this.frustumCulled===!1&&(r.frustumCulled=!1),this.renderOrder!==0&&(r.renderOrder=this.renderOrder),Object.keys(this.userData).length>0&&(r.userData=this.userData),r.layers=this.layers.mask,r.matrix=this.matrix.toArray(),r.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(r.matrixAutoUpdate=!1),this.isInstancedMesh&&(r.type=`InstancedMesh`,r.count=this.count,r.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(r.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(r.type=`BatchedMesh`,r.perObjectFrustumCulled=this.perObjectFrustumCulled,r.sortObjects=this.sortObjects,r.drawRanges=this._drawRanges,r.reservedRanges=this._reservedRanges,r.visibility=this._visibility,r.active=this._active,r.bounds=this._bounds.map(e=>({boxInitialized:e.boxInitialized,boxMin:e.box.min.toArray(),boxMax:e.box.max.toArray(),sphereInitialized:e.sphereInitialized,sphereRadius:e.sphere.radius,sphereCenter:e.sphere.center.toArray()})),r.maxGeometryCount=this._maxGeometryCount,r.maxVertexCount=this._maxVertexCount,r.maxIndexCount=this._maxIndexCount,r.geometryInitialized=this._geometryInitialized,r.geometryCount=this._geometryCount,r.matricesTexture=this._matricesTexture.toJSON(e),this.boundingSphere!==null&&(r.boundingSphere={center:r.boundingSphere.center.toArray(),radius:r.boundingSphere.radius}),this.boundingBox!==null&&(r.boundingBox={min:r.boundingBox.min.toArray(),max:r.boundingBox.max.toArray()}));function i(t,n){return t[n.uuid]===void 0&&(t[n.uuid]=n.toJSON(e)),n.uuid}if(this.isScene)this.background&&(this.background.isColor?r.background=this.background.toJSON():this.background.isTexture&&(r.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(r.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){r.geometry=i(e.geometries,this.geometry);let t=this.geometry.parameters;if(t!==void 0&&t.shapes!==void 0){let n=t.shapes;if(Array.isArray(n))for(let t=0,r=n.length;t<r;t++){let r=n[t];i(e.shapes,r)}else i(e.shapes,n)}}if(this.isSkinnedMesh&&(r.bindMode=this.bindMode,r.bindMatrix=this.bindMatrix.toArray(),this.skeleton!==void 0&&(i(e.skeletons,this.skeleton),r.skeleton=this.skeleton.uuid)),this.material!==void 0)if(Array.isArray(this.material)){let t=[];for(let n=0,r=this.material.length;n<r;n++)t.push(i(e.materials,this.material[n]));r.material=t}else r.material=i(e.materials,this.material);if(this.children.length>0){r.children=[];for(let t=0;t<this.children.length;t++)r.children.push(this.children[t].toJSON(e).object)}if(this.animations.length>0){r.animations=[];for(let t=0;t<this.animations.length;t++){let n=this.animations[t];r.animations.push(i(e.animations,n))}}if(t){let t=a(e.geometries),r=a(e.materials),i=a(e.textures),o=a(e.images),s=a(e.shapes),c=a(e.skeletons),l=a(e.animations),u=a(e.nodes);t.length>0&&(n.geometries=t),r.length>0&&(n.materials=r),i.length>0&&(n.textures=i),o.length>0&&(n.images=o),s.length>0&&(n.shapes=s),c.length>0&&(n.skeletons=c),l.length>0&&(n.animations=l),u.length>0&&(n.nodes=u)}return n.object=r,n;function a(e){let t=[];for(let n in e){let r=e[n];delete r.metadata,t.push(r)}return t}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let t=0;t<e.children.length;t++){let n=e.children[t];this.add(n.clone())}return this}};qt.DEFAULT_UP=new X(0,1,0),qt.DEFAULT_MATRIX_AUTO_UPDATE=!0,qt.DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;var Jt=new X,Yt=new X,Xt=new X,Zt=new X,Qt=new X,$t=new X,en=new X,tn=new X,nn=new X,rn=new X,an=!1,on=class e{constructor(e=new X,t=new X,n=new X){this.a=e,this.b=t,this.c=n}static getNormal(e,t,n,r){r.subVectors(n,t),Jt.subVectors(e,t),r.cross(Jt);let i=r.lengthSq();return i>0?r.multiplyScalar(1/Math.sqrt(i)):r.set(0,0,0)}static getBarycoord(e,t,n,r,i){Jt.subVectors(r,t),Yt.subVectors(n,t),Xt.subVectors(e,t);let a=Jt.dot(Jt),o=Jt.dot(Yt),s=Jt.dot(Xt),c=Yt.dot(Yt),l=Yt.dot(Xt),u=a*c-o*o;if(u===0)return i.set(-2,-1,-1);let d=1/u,f=(c*s-o*l)*d,p=(a*l-o*s)*d;return i.set(1-f-p,p,f)}static containsPoint(e,t,n,r){return this.getBarycoord(e,t,n,r,Zt),Zt.x>=0&&Zt.y>=0&&Zt.x+Zt.y<=1}static getUV(e,t,n,r,i,a,o,s){return an===!1&&(console.warn(`THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation().`),an=!0),this.getInterpolation(e,t,n,r,i,a,o,s)}static getInterpolation(e,t,n,r,i,a,o,s){return this.getBarycoord(e,t,n,r,Zt),s.setScalar(0),s.addScaledVector(i,Zt.x),s.addScaledVector(a,Zt.y),s.addScaledVector(o,Zt.z),s}static isFrontFacing(e,t,n,r){return Jt.subVectors(n,t),Yt.subVectors(e,t),Jt.cross(Yt).dot(r)<0}set(e,t,n){return this.a.copy(e),this.b.copy(t),this.c.copy(n),this}setFromPointsAndIndices(e,t,n,r){return this.a.copy(e[t]),this.b.copy(e[n]),this.c.copy(e[r]),this}setFromAttributeAndIndices(e,t,n,r){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,n),this.c.fromBufferAttribute(e,r),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return Jt.subVectors(this.c,this.b),Yt.subVectors(this.a,this.b),Jt.cross(Yt).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return e.getNormal(this.a,this.b,this.c,t)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,n){return e.getBarycoord(t,this.a,this.b,this.c,n)}getUV(t,n,r,i,a){return an===!1&&(console.warn(`THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation().`),an=!0),e.getInterpolation(t,this.a,this.b,this.c,n,r,i,a)}getInterpolation(t,n,r,i,a){return e.getInterpolation(t,this.a,this.b,this.c,n,r,i,a)}containsPoint(t){return e.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return e.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){let n=this.a,r=this.b,i=this.c,a,o;Qt.subVectors(r,n),$t.subVectors(i,n),tn.subVectors(e,n);let s=Qt.dot(tn),c=$t.dot(tn);if(s<=0&&c<=0)return t.copy(n);nn.subVectors(e,r);let l=Qt.dot(nn),u=$t.dot(nn);if(l>=0&&u<=l)return t.copy(r);let d=s*u-l*c;if(d<=0&&s>=0&&l<=0)return a=s/(s-l),t.copy(n).addScaledVector(Qt,a);rn.subVectors(e,i);let f=Qt.dot(rn),p=$t.dot(rn);if(p>=0&&f<=p)return t.copy(i);let m=f*c-s*p;if(m<=0&&c>=0&&p<=0)return o=c/(c-p),t.copy(n).addScaledVector($t,o);let h=l*p-f*u;if(h<=0&&u-l>=0&&f-p>=0)return en.subVectors(i,r),o=(u-l)/(u-l+(f-p)),t.copy(r).addScaledVector(en,o);let g=1/(h+m+d);return a=m*g,o=d*g,t.copy(n).addScaledVector(Qt,a).addScaledVector($t,o)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}},sn={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},cn={h:0,s:0,l:0},ln={h:0,s:0,l:0};function un(e,t,n){return n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*6*(2/3-n):e}var Z=class{constructor(e,t,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,n)}set(e,t,n){if(t===void 0&&n===void 0){let t=e;t&&t.isColor?this.copy(t):typeof t==`number`?this.setHex(t):typeof t==`string`&&this.setStyle(t)}else this.setRGB(e,t,n);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=A){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Y.toWorkingColorSpace(this,t),this}setRGB(e,t,n,r=Y.workingColorSpace){return this.r=e,this.g=t,this.b=n,Y.toWorkingColorSpace(this,r),this}setHSL(e,t,n,r=Y.workingColorSpace){if(e=ce(e,1),t=z(t,0,1),n=z(n,0,1),t===0)this.r=this.g=this.b=n;else{let r=n<=.5?n*(1+t):n+t-n*t,i=2*n-r;this.r=un(i,r,e+1/3),this.g=un(i,r,e),this.b=un(i,r,e-1/3)}return Y.toWorkingColorSpace(this,r),this}setStyle(e,t=A){function n(t){t!==void 0&&parseFloat(t)<1&&console.warn(`THREE.Color: Alpha component of `+e+` will be ignored.`)}let r;if(r=/^(\w+)\(([^\)]*)\)/.exec(e)){let i,a=r[1],o=r[2];switch(a){case`rgb`:case`rgba`:if(i=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(i[4]),this.setRGB(Math.min(255,parseInt(i[1],10))/255,Math.min(255,parseInt(i[2],10))/255,Math.min(255,parseInt(i[3],10))/255,t);if(i=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(i[4]),this.setRGB(Math.min(100,parseInt(i[1],10))/100,Math.min(100,parseInt(i[2],10))/100,Math.min(100,parseInt(i[3],10))/100,t);break;case`hsl`:case`hsla`:if(i=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(o))return n(i[4]),this.setHSL(parseFloat(i[1])/360,parseFloat(i[2])/100,parseFloat(i[3])/100,t);break;default:console.warn(`THREE.Color: Unknown color model `+e)}}else if(r=/^\#([A-Fa-f\d]+)$/.exec(e)){let n=r[1],i=n.length;if(i===3)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,t);if(i===6)return this.setHex(parseInt(n,16),t);console.warn(`THREE.Color: Invalid hex color `+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=A){let n=sn[e.toLowerCase()];return n===void 0?console.warn(`THREE.Color: Unknown color `+e):this.setHex(n,t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=Me(e.r),this.g=Me(e.g),this.b=Me(e.b),this}copyLinearToSRGB(e){return this.r=Ne(e.r),this.g=Ne(e.g),this.b=Ne(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=A){return Y.fromWorkingColorSpace(dn.copy(this),e),Math.round(z(dn.r*255,0,255))*65536+Math.round(z(dn.g*255,0,255))*256+Math.round(z(dn.b*255,0,255))}getHexString(e=A){return(`000000`+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Y.workingColorSpace){Y.fromWorkingColorSpace(dn.copy(this),t);let n=dn.r,r=dn.g,i=dn.b,a=Math.max(n,r,i),o=Math.min(n,r,i),s,c,l=(o+a)/2;if(o===a)s=0,c=0;else{let e=a-o;switch(c=l<=.5?e/(a+o):e/(2-a-o),a){case n:s=(r-i)/e+(r<i?6:0);break;case r:s=(i-n)/e+2;break;case i:s=(n-r)/e+4;break}s/=6}return e.h=s,e.s=c,e.l=l,e}getRGB(e,t=Y.workingColorSpace){return Y.fromWorkingColorSpace(dn.copy(this),t),e.r=dn.r,e.g=dn.g,e.b=dn.b,e}getStyle(e=A){Y.fromWorkingColorSpace(dn.copy(this),e);let t=dn.r,n=dn.g,r=dn.b;return e===`srgb`?`rgb(${Math.round(t*255)},${Math.round(n*255)},${Math.round(r*255)})`:`color(${e} ${t.toFixed(3)} ${n.toFixed(3)} ${r.toFixed(3)})`}offsetHSL(e,t,n){return this.getHSL(cn),this.setHSL(cn.h+e,cn.s+t,cn.l+n)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,n){return this.r=e.r+(t.r-e.r)*n,this.g=e.g+(t.g-e.g)*n,this.b=e.b+(t.b-e.b)*n,this}lerpHSL(e,t){this.getHSL(cn),e.getHSL(ln);let n=de(cn.h,ln.h,t),r=de(cn.s,ln.s,t),i=de(cn.l,ln.l,t);return this.setHSL(n,r,i),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){let t=this.r,n=this.g,r=this.b,i=e.elements;return this.r=i[0]*t+i[3]*n+i[6]*r,this.g=i[1]*t+i[4]*n+i[7]*r,this.b=i[2]*t+i[5]*n+i[8]*r,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}},dn=new Z;Z.NAMES=sn;var fn=0,pn=class extends F{constructor(){super(),this.isMaterial=!0,Object.defineProperty(this,"id",{value:fn++}),this.uuid=R(),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=100,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new Z(0,0,0),this.blendAlpha=0,this.depthFunc=3,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=P,this.stencilZFail=P,this.stencilZPass=P,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(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(let t in e){let n=e[t];if(n===void 0){console.warn(`THREE.Material: parameter '${t}' has value of undefined.`);continue}let r=this[t];if(r===void 0){console.warn(`THREE.Material: '${t}' is not a property of THREE.${this.type}.`);continue}r&&r.isColor?r.set(n):r&&r.isVector3&&n&&n.isVector3?r.copy(n):this[t]=n}}toJSON(e){let t=e===void 0||typeof e==`string`;t&&(e={textures:{},images:{}});let n={metadata:{version:4.6,type:`Material`,generator:`Material.toJSON`}};n.uuid=this.uuid,n.type=this.type,this.name!==``&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),this.roughness!==void 0&&(n.roughness=this.roughness),this.metalness!==void 0&&(n.metalness=this.metalness),this.sheen!==void 0&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),this.emissiveIntensity&&this.emissiveIntensity!==1&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(n.shininess=this.shininess),this.clearcoat!==void 0&&(n.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.iridescence!==void 0&&(n.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(n.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(n.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(e).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(e).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(e).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(e).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(e).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(n.combine=this.combine)),this.envMapIntensity!==void 0&&(n.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(n.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(n.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(n.size=this.size),this.shadowSide!==null&&(n.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(n.sizeAttenuation=this.sizeAttenuation),this.blending!==1&&(n.blending=this.blending),this.side!==0&&(n.side=this.side),this.vertexColors===!0&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),this.transparent===!0&&(n.transparent=!0),this.blendSrc!==204&&(n.blendSrc=this.blendSrc),this.blendDst!==205&&(n.blendDst=this.blendDst),this.blendEquation!==100&&(n.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(n.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(n.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(n.blendAlpha=this.blendAlpha),this.depthFunc!==3&&(n.depthFunc=this.depthFunc),this.depthTest===!1&&(n.depthTest=this.depthTest),this.depthWrite===!1&&(n.depthWrite=this.depthWrite),this.colorWrite===!1&&(n.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(n.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==519&&(n.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(n.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==7680&&(n.stencilFail=this.stencilFail),this.stencilZFail!==7680&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==7680&&(n.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(n.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(n.rotation=this.rotation),this.polygonOffset===!0&&(n.polygonOffset=!0),this.polygonOffsetFactor!==0&&(n.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(n.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(n.linewidth=this.linewidth),this.dashSize!==void 0&&(n.dashSize=this.dashSize),this.gapSize!==void 0&&(n.gapSize=this.gapSize),this.scale!==void 0&&(n.scale=this.scale),this.dithering===!0&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),this.alphaHash===!0&&(n.alphaHash=!0),this.alphaToCoverage===!0&&(n.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(n.premultipliedAlpha=!0),this.forceSinglePass===!0&&(n.forceSinglePass=!0),this.wireframe===!0&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!==`round`&&(n.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!==`round`&&(n.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(n.flatShading=!0),this.visible===!1&&(n.visible=!1),this.toneMapped===!1&&(n.toneMapped=!1),this.fog===!1&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData);function r(e){let t=[];for(let n in e){let r=e[n];delete r.metadata,t.push(r)}return t}if(t){let t=r(e.textures),i=r(e.images);t.length>0&&(n.textures=t),i.length>0&&(n.images=i)}return n}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;let t=e.clippingPlanes,n=null;if(t!==null){let e=t.length;n=Array(e);for(let r=0;r!==e;++r)n[r]=t[r].clone()}return this.clippingPlanes=n,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:`dispose`})}set needsUpdate(e){e===!0&&this.version++}},mn=class extends pn{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type=`MeshBasicMaterial`,this.color=new Z(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(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}},hn=new X,gn=new K,_n=class{constructor(e,t,n=!1){if(Array.isArray(e))throw TypeError(`THREE.BufferAttribute: array should be a Typed Array.`);this.isBufferAttribute=!0,this.name=``,this.array=e,this.itemSize=t,this.count=e===void 0?0:e.length/t,this.normalized=n,this.usage=re,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.gpuType=m,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}get updateRange(){return console.warn(`THREE.BufferAttribute: "updateRange" is deprecated and removed in r169. Use "addUpdateRange()" instead.`),this._updateRange}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,n){e*=this.itemSize,n*=t.itemSize;for(let r=0,i=this.itemSize;r<i;r++)this.array[e+r]=t.array[n+r];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,n=this.count;t<n;t++)gn.fromBufferAttribute(this,t),gn.applyMatrix3(e),this.setXY(t,gn.x,gn.y);else if(this.itemSize===3)for(let t=0,n=this.count;t<n;t++)hn.fromBufferAttribute(this,t),hn.applyMatrix3(e),this.setXYZ(t,hn.x,hn.y,hn.z);return this}applyMatrix4(e){for(let t=0,n=this.count;t<n;t++)hn.fromBufferAttribute(this,t),hn.applyMatrix4(e),this.setXYZ(t,hn.x,hn.y,hn.z);return this}applyNormalMatrix(e){for(let t=0,n=this.count;t<n;t++)hn.fromBufferAttribute(this,t),hn.applyNormalMatrix(e),this.setXYZ(t,hn.x,hn.y,hn.z);return this}transformDirection(e){for(let t=0,n=this.count;t<n;t++)hn.fromBufferAttribute(this,t),hn.transformDirection(e),this.setXYZ(t,hn.x,hn.y,hn.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let n=this.array[e*this.itemSize+t];return this.normalized&&(n=be(n,this.array)),n}setComponent(e,t,n){return this.normalized&&(n=xe(n,this.array)),this.array[e*this.itemSize+t]=n,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=be(t,this.array)),t}setX(e,t){return this.normalized&&(t=xe(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=be(t,this.array)),t}setY(e,t){return this.normalized&&(t=xe(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=be(t,this.array)),t}setZ(e,t){return this.normalized&&(t=xe(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=be(t,this.array)),t}setW(e,t){return this.normalized&&(t=xe(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=xe(t,this.array),n=xe(n,this.array)),this.array[e+0]=t,this.array[e+1]=n,this}setXYZ(e,t,n,r){return e*=this.itemSize,this.normalized&&(t=xe(t,this.array),n=xe(n,this.array),r=xe(r,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=r,this}setXYZW(e,t,n,r,i){return e*=this.itemSize,this.normalized&&(t=xe(t,this.array),n=xe(n,this.array),r=xe(r,this.array),i=xe(i,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=r,this.array[e+3]=i,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){let e={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.from(this.array),normalized:this.normalized};return this.name!==``&&(e.name=this.name),this.usage!==35044&&(e.usage=this.usage),e}},vn=class extends _n{constructor(e,t,n){super(new Uint16Array(e),t,n)}},yn=class extends _n{constructor(e,t,n){super(new Uint32Array(e),t,n)}},bn=class extends _n{constructor(e,t,n){super(new Float32Array(e),t,n)}},xn=0,Sn=new St,Cn=new qt,wn=new X,Tn=new Ye,En=new Ye,Dn=new X,On=class e extends F{constructor(){super(),this.isBufferGeometry=!0,Object.defineProperty(this,"id",{value:xn++}),this.uuid=R(),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(e){return Array.isArray(e)?this.index=new(Ce(e)?yn:vn)(e,1):this.index=e,this}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,n=0){this.groups.push({start:e,count:t,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){let t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);let n=this.attributes.normal;if(n!==void 0){let t=new q().getNormalMatrix(e);n.applyNormalMatrix(t),n.needsUpdate=!0}let r=this.attributes.tangent;return r!==void 0&&(r.transformDirection(e),r.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(e){return Sn.makeRotationFromQuaternion(e),this.applyMatrix4(Sn),this}rotateX(e){return Sn.makeRotationX(e),this.applyMatrix4(Sn),this}rotateY(e){return Sn.makeRotationY(e),this.applyMatrix4(Sn),this}rotateZ(e){return Sn.makeRotationZ(e),this.applyMatrix4(Sn),this}translate(e,t,n){return Sn.makeTranslation(e,t,n),this.applyMatrix4(Sn),this}scale(e,t,n){return Sn.makeScale(e,t,n),this.applyMatrix4(Sn),this}lookAt(e){return Cn.lookAt(e),Cn.updateMatrix(),this.applyMatrix4(Cn.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(wn).negate(),this.translate(wn.x,wn.y,wn.z),this}setFromPoints(e){let t=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];t.push(r.x,r.y,r.z||0)}return this.setAttribute(`position`,new bn(t,3)),this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Ye);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){console.error(`THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".`,this),this.boundingBox.set(new X(-1/0,-1/0,-1/0),new X(1/0,1/0,1/0));return}if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let e=0,n=t.length;e<n;e++){let n=t[e];Tn.setFromBufferAttribute(n),this.morphTargetsRelative?(Dn.addVectors(this.boundingBox.min,Tn.min),this.boundingBox.expandByPoint(Dn),Dn.addVectors(this.boundingBox.max,Tn.max),this.boundingBox.expandByPoint(Dn)):(this.boundingBox.expandByPoint(Tn.min),this.boundingBox.expandByPoint(Tn.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error(`THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.`,this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new pt);let e=this.attributes.position,t=this.morphAttributes.position;if(e&&e.isGLBufferAttribute){console.error(`THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".`,this),this.boundingSphere.set(new X,1/0);return}if(e){let n=this.boundingSphere.center;if(Tn.setFromBufferAttribute(e),t)for(let e=0,n=t.length;e<n;e++){let n=t[e];En.setFromBufferAttribute(n),this.morphTargetsRelative?(Dn.addVectors(Tn.min,En.min),Tn.expandByPoint(Dn),Dn.addVectors(Tn.max,En.max),Tn.expandByPoint(Dn)):(Tn.expandByPoint(En.min),Tn.expandByPoint(En.max))}Tn.getCenter(n);let r=0;for(let t=0,i=e.count;t<i;t++)Dn.fromBufferAttribute(e,t),r=Math.max(r,n.distanceToSquared(Dn));if(t)for(let i=0,a=t.length;i<a;i++){let a=t[i],o=this.morphTargetsRelative;for(let t=0,i=a.count;t<i;t++)Dn.fromBufferAttribute(a,t),o&&(wn.fromBufferAttribute(e,t),Dn.add(wn)),r=Math.max(r,n.distanceToSquared(Dn))}this.boundingSphere.radius=Math.sqrt(r),isNaN(this.boundingSphere.radius)&&console.error(`THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.`,this)}}computeTangents(){let e=this.index,t=this.attributes;if(e===null||t.position===void 0||t.normal===void 0||t.uv===void 0){console.error(`THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)`);return}let n=e.array,r=t.position.array,i=t.normal.array,a=t.uv.array,o=r.length/3;this.hasAttribute(`tangent`)===!1&&this.setAttribute(`tangent`,new _n(new Float32Array(4*o),4));let s=this.getAttribute(`tangent`).array,c=[],l=[];for(let e=0;e<o;e++)c[e]=new X,l[e]=new X;let u=new X,d=new X,f=new X,p=new K,m=new K,h=new K,g=new X,_=new X;function v(e,t,n){u.fromArray(r,e*3),d.fromArray(r,t*3),f.fromArray(r,n*3),p.fromArray(a,e*2),m.fromArray(a,t*2),h.fromArray(a,n*2),d.sub(u),f.sub(u),m.sub(p),h.sub(p);let i=1/(m.x*h.y-h.x*m.y);isFinite(i)&&(g.copy(d).multiplyScalar(h.y).addScaledVector(f,-m.y).multiplyScalar(i),_.copy(f).multiplyScalar(m.x).addScaledVector(d,-h.x).multiplyScalar(i),c[e].add(g),c[t].add(g),c[n].add(g),l[e].add(_),l[t].add(_),l[n].add(_))}let y=this.groups;y.length===0&&(y=[{start:0,count:n.length}]);for(let e=0,t=y.length;e<t;++e){let t=y[e],r=t.start,i=t.count;for(let e=r,t=r+i;e<t;e+=3)v(n[e+0],n[e+1],n[e+2])}let b=new X,x=new X,S=new X,C=new X;function w(e){S.fromArray(i,e*3),C.copy(S);let t=c[e];b.copy(t),b.sub(S.multiplyScalar(S.dot(t))).normalize(),x.crossVectors(C,t);let n=x.dot(l[e])<0?-1:1;s[e*4]=b.x,s[e*4+1]=b.y,s[e*4+2]=b.z,s[e*4+3]=n}for(let e=0,t=y.length;e<t;++e){let t=y[e],r=t.start,i=t.count;for(let e=r,t=r+i;e<t;e+=3)w(n[e+0]),w(n[e+1]),w(n[e+2])}}computeVertexNormals(){let e=this.index,t=this.getAttribute(`position`);if(t!==void 0){let n=this.getAttribute(`normal`);if(n===void 0)n=new _n(new Float32Array(t.count*3),3),this.setAttribute(`normal`,n);else for(let e=0,t=n.count;e<t;e++)n.setXYZ(e,0,0,0);let r=new X,i=new X,a=new X,o=new X,s=new X,c=new X,l=new X,u=new X;if(e)for(let d=0,f=e.count;d<f;d+=3){let f=e.getX(d+0),p=e.getX(d+1),m=e.getX(d+2);r.fromBufferAttribute(t,f),i.fromBufferAttribute(t,p),a.fromBufferAttribute(t,m),l.subVectors(a,i),u.subVectors(r,i),l.cross(u),o.fromBufferAttribute(n,f),s.fromBufferAttribute(n,p),c.fromBufferAttribute(n,m),o.add(l),s.add(l),c.add(l),n.setXYZ(f,o.x,o.y,o.z),n.setXYZ(p,s.x,s.y,s.z),n.setXYZ(m,c.x,c.y,c.z)}else for(let e=0,o=t.count;e<o;e+=3)r.fromBufferAttribute(t,e+0),i.fromBufferAttribute(t,e+1),a.fromBufferAttribute(t,e+2),l.subVectors(a,i),u.subVectors(r,i),l.cross(u),n.setXYZ(e+0,l.x,l.y,l.z),n.setXYZ(e+1,l.x,l.y,l.z),n.setXYZ(e+2,l.x,l.y,l.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){let e=this.attributes.normal;for(let t=0,n=e.count;t<n;t++)Dn.fromBufferAttribute(e,t),Dn.normalize(),e.setXYZ(t,Dn.x,Dn.y,Dn.z)}toNonIndexed(){function t(e,t){let n=e.array,r=e.itemSize,i=e.normalized,a=new n.constructor(t.length*r),o=0,s=0;for(let i=0,c=t.length;i<c;i++){o=e.isInterleavedBufferAttribute?t[i]*e.data.stride+e.offset:t[i]*r;for(let e=0;e<r;e++)a[s++]=n[o++]}return new _n(a,r,i)}if(this.index===null)return console.warn(`THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.`),this;let n=new e,r=this.index.array,i=this.attributes;for(let e in i){let a=i[e],o=t(a,r);n.setAttribute(e,o)}let a=this.morphAttributes;for(let e in a){let i=[],o=a[e];for(let e=0,n=o.length;e<n;e++){let n=o[e],a=t(n,r);i.push(a)}n.morphAttributes[e]=i}n.morphTargetsRelative=this.morphTargetsRelative;let o=this.groups;for(let e=0,t=o.length;e<t;e++){let t=o[e];n.addGroup(t.start,t.count,t.materialIndex)}return n}toJSON(){let e={metadata:{version:4.6,type:`BufferGeometry`,generator:`BufferGeometry.toJSON`}};if(e.uuid=this.uuid,e.type=this.type,this.name!==``&&(e.name=this.name),Object.keys(this.userData).length>0&&(e.userData=this.userData),this.parameters!==void 0){let t=this.parameters;for(let n in t)t[n]!==void 0&&(e[n]=t[n]);return e}e.data={attributes:{}};let t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});let n=this.attributes;for(let t in n){let r=n[t];e.data.attributes[t]=r.toJSON(e.data)}let r={},i=!1;for(let t in this.morphAttributes){let n=this.morphAttributes[t],a=[];for(let t=0,r=n.length;t<r;t++){let r=n[t];a.push(r.toJSON(e.data))}a.length>0&&(r[t]=a,i=!0)}i&&(e.data.morphAttributes=r,e.data.morphTargetsRelative=this.morphTargetsRelative);let a=this.groups;a.length>0&&(e.data.groups=JSON.parse(JSON.stringify(a)));let o=this.boundingSphere;return o!==null&&(e.data.boundingSphere={center:o.center.toArray(),radius:o.radius}),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;let t={};this.name=e.name;let n=e.index;n!==null&&this.setIndex(n.clone(t));let r=e.attributes;for(let e in r){let n=r[e];this.setAttribute(e,n.clone(t))}let i=e.morphAttributes;for(let e in i){let n=[],r=i[e];for(let e=0,i=r.length;e<i;e++)n.push(r[e].clone(t));this.morphAttributes[e]=n}this.morphTargetsRelative=e.morphTargetsRelative;let a=e.groups;for(let e=0,t=a.length;e<t;e++){let t=a[e];this.addGroup(t.start,t.count,t.materialIndex)}let o=e.boundingBox;o!==null&&(this.boundingBox=o.clone());let s=e.boundingSphere;return s!==null&&(this.boundingSphere=s.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this}dispose(){this.dispatchEvent({type:`dispose`})}},kn=new St,An=new xt,jn=new pt,Mn=new X,Nn=new X,Pn=new X,Fn=new X,In=new X,Ln=new X,Rn=new K,zn=new K,Bn=new K,Vn=new X,Hn=new X,Un=new X,Wn=new X,Gn=new X,Kn=class extends qt{constructor(e=new On,t=new mn){super(),this.isMesh=!0,this.type=`Mesh`,this.geometry=e,this.material=t,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){let e=this.geometry.morphAttributes,t=Object.keys(e);if(t.length>0){let n=e[t[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=n.length;e<t;e++){let t=n[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[t]=e}}}}getVertexPosition(e,t){let n=this.geometry,r=n.attributes.position,i=n.morphAttributes.position,a=n.morphTargetsRelative;t.fromBufferAttribute(r,e);let o=this.morphTargetInfluences;if(i&&o){Ln.set(0,0,0);for(let n=0,r=i.length;n<r;n++){let r=o[n],s=i[n];r!==0&&(In.fromBufferAttribute(s,e),a?Ln.addScaledVector(In,r):Ln.addScaledVector(In.sub(t),r))}t.add(Ln)}return t}raycast(e,t){let n=this.geometry,r=this.material,i=this.matrixWorld;r!==void 0&&(n.boundingSphere===null&&n.computeBoundingSphere(),jn.copy(n.boundingSphere),jn.applyMatrix4(i),An.copy(e.ray).recast(e.near),!(jn.containsPoint(An.origin)===!1&&(An.intersectSphere(jn,Mn)===null||An.origin.distanceToSquared(Mn)>(e.far-e.near)**2))&&(kn.copy(i).invert(),An.copy(e.ray).applyMatrix4(kn),!(n.boundingBox!==null&&An.intersectsBox(n.boundingBox)===!1)&&this._computeIntersections(e,t,An)))}_computeIntersections(e,t,n){let r,i=this.geometry,a=this.material,o=i.index,s=i.attributes.position,c=i.attributes.uv,l=i.attributes.uv1,u=i.attributes.normal,d=i.groups,f=i.drawRange;if(o!==null)if(Array.isArray(a))for(let i=0,s=d.length;i<s;i++){let s=d[i],p=a[s.materialIndex],m=Math.max(s.start,f.start),h=Math.min(o.count,Math.min(s.start+s.count,f.start+f.count));for(let i=m,a=h;i<a;i+=3){let a=o.getX(i),d=o.getX(i+1),f=o.getX(i+2);r=Jn(this,p,e,n,c,l,u,a,d,f),r&&(r.faceIndex=Math.floor(i/3),r.face.materialIndex=s.materialIndex,t.push(r))}}else{let i=Math.max(0,f.start),s=Math.min(o.count,f.start+f.count);for(let d=i,f=s;d<f;d+=3){let i=o.getX(d),s=o.getX(d+1),f=o.getX(d+2);r=Jn(this,a,e,n,c,l,u,i,s,f),r&&(r.faceIndex=Math.floor(d/3),t.push(r))}}else if(s!==void 0)if(Array.isArray(a))for(let i=0,o=d.length;i<o;i++){let o=d[i],p=a[o.materialIndex],m=Math.max(o.start,f.start),h=Math.min(s.count,Math.min(o.start+o.count,f.start+f.count));for(let i=m,a=h;i<a;i+=3){let a=i,s=i+1,d=i+2;r=Jn(this,p,e,n,c,l,u,a,s,d),r&&(r.faceIndex=Math.floor(i/3),r.face.materialIndex=o.materialIndex,t.push(r))}}else{let i=Math.max(0,f.start),o=Math.min(s.count,f.start+f.count);for(let s=i,d=o;s<d;s+=3){let i=s,o=s+1,d=s+2;r=Jn(this,a,e,n,c,l,u,i,o,d),r&&(r.faceIndex=Math.floor(s/3),t.push(r))}}}};function qn(e,t,n,r,i,a,o,s){let c;if(c=t.side===1?r.intersectTriangle(o,a,i,!0,s):r.intersectTriangle(i,a,o,t.side===0,s),c===null)return null;Gn.copy(s),Gn.applyMatrix4(e.matrixWorld);let l=n.ray.origin.distanceTo(Gn);return l<n.near||l>n.far?null:{distance:l,point:Gn.clone(),object:e}}function Jn(e,t,n,r,i,a,o,s,c,l){e.getVertexPosition(s,Nn),e.getVertexPosition(c,Pn),e.getVertexPosition(l,Fn);let u=qn(e,t,n,r,Nn,Pn,Fn,Wn);if(u){i&&(Rn.fromBufferAttribute(i,s),zn.fromBufferAttribute(i,c),Bn.fromBufferAttribute(i,l),u.uv=on.getInterpolation(Wn,Nn,Pn,Fn,Rn,zn,Bn,new K)),a&&(Rn.fromBufferAttribute(a,s),zn.fromBufferAttribute(a,c),Bn.fromBufferAttribute(a,l),u.uv1=on.getInterpolation(Wn,Nn,Pn,Fn,Rn,zn,Bn,new K),u.uv2=u.uv1),o&&(Vn.fromBufferAttribute(o,s),Hn.fromBufferAttribute(o,c),Un.fromBufferAttribute(o,l),u.normal=on.getInterpolation(Wn,Nn,Pn,Fn,Vn,Hn,Un,new X),u.normal.dot(r.direction)>0&&u.normal.multiplyScalar(-1));let e={a:s,b:c,c:l,normal:new X,materialIndex:0};on.getNormal(Nn,Pn,Fn,e.normal),u.face=e}return u}var Yn=class e extends On{constructor(e=1,t=1,n=1,r=1,i=1,a=1){super(),this.type=`BoxGeometry`,this.parameters={width:e,height:t,depth:n,widthSegments:r,heightSegments:i,depthSegments:a};let o=this;r=Math.floor(r),i=Math.floor(i),a=Math.floor(a);let s=[],c=[],l=[],u=[],d=0,f=0;p(`z`,`y`,`x`,-1,-1,n,t,e,a,i,0),p(`z`,`y`,`x`,1,-1,n,t,-e,a,i,1),p(`x`,`z`,`y`,1,1,e,n,t,r,a,2),p(`x`,`z`,`y`,1,-1,e,n,-t,r,a,3),p(`x`,`y`,`z`,1,-1,e,t,n,r,i,4),p(`x`,`y`,`z`,-1,-1,e,t,-n,r,i,5),this.setIndex(s),this.setAttribute(`position`,new bn(c,3)),this.setAttribute(`normal`,new bn(l,3)),this.setAttribute(`uv`,new bn(u,2));function p(e,t,n,r,i,a,p,m,h,g,_){let v=a/h,y=p/g,b=a/2,x=p/2,S=m/2,C=h+1,w=g+1,T=0,E=0,D=new X;for(let a=0;a<w;a++){let o=a*y-x;for(let s=0;s<C;s++)D[e]=(s*v-b)*r,D[t]=o*i,D[n]=S,c.push(D.x,D.y,D.z),D[e]=0,D[t]=0,D[n]=m>0?1:-1,l.push(D.x,D.y,D.z),u.push(s/h),u.push(1-a/g),T+=1}for(let e=0;e<g;e++)for(let t=0;t<h;t++){let n=d+t+C*e,r=d+t+C*(e+1),i=d+(t+1)+C*(e+1),a=d+(t+1)+C*e;s.push(n,r,a),s.push(r,i,a),E+=6}o.addGroup(f,E,_),f+=E,d+=T}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(t){return new e(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}};function Xn(e){let t={};for(let n in e){t[n]={};for(let r in e[n]){let i=e[n][r];i&&(i.isColor||i.isMatrix3||i.isMatrix4||i.isVector2||i.isVector3||i.isVector4||i.isTexture||i.isQuaternion)?i.isRenderTargetTexture?(console.warn(`UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().`),t[n][r]=null):t[n][r]=i.clone():Array.isArray(i)?t[n][r]=i.slice():t[n][r]=i}}return t}function Zn(e){let t={};for(let n=0;n<e.length;n++){let r=Xn(e[n]);for(let e in r)t[e]=r[e]}return t}function Qn(e){let t=[];for(let n=0;n<e.length;n++)t.push(e[n].clone());return t}function $n(e){return e.getRenderTarget()===null?e.outputColorSpace:Y.workingColorSpace}var er={clone:Xn,merge:Zn},tr=`void main() {
2
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
3
+ }`,nr=`void main() {
4
+ gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
5
+ }`,rr=class extends pn{constructor(e){super(),this.isShaderMaterial=!0,this.type=`ShaderMaterial`,this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=tr,this.fragmentShader=nr,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,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=Xn(e.uniforms),this.uniformsGroups=Qn(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this}toJSON(e){let t=super.toJSON(e);t.glslVersion=this.glslVersion,t.uniforms={};for(let n in this.uniforms){let r=this.uniforms[n].value;r&&r.isTexture?t.uniforms[n]={type:`t`,value:r.toJSON(e).uuid}:r&&r.isColor?t.uniforms[n]={type:`c`,value:r.getHex()}:r&&r.isVector2?t.uniforms[n]={type:`v2`,value:r.toArray()}:r&&r.isVector3?t.uniforms[n]={type:`v3`,value:r.toArray()}:r&&r.isVector4?t.uniforms[n]={type:`v4`,value:r.toArray()}:r&&r.isMatrix3?t.uniforms[n]={type:`m3`,value:r.toArray()}:r&&r.isMatrix4?t.uniforms[n]={type:`m4`,value:r.toArray()}:t.uniforms[n]={value:r}}Object.keys(this.defines).length>0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;let n={};for(let e in this.extensions)this.extensions[e]===!0&&(n[e]=!0);return Object.keys(n).length>0&&(t.extensions=n),t}},ir=class extends qt{constructor(){super(),this.isCamera=!0,this.type=`Camera`,this.matrixWorldInverse=new St,this.projectionMatrix=new St,this.projectionMatrixInverse=new St,this.coordinateSystem=ae}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}},ar=class extends ir{constructor(e=50,t=1,n=.1,r=2e3){super(),this.isPerspectiveCamera=!0,this.type=`PerspectiveCamera`,this.fov=e,this.zoom=1,this.near=n,this.far=r,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){let t=.5*this.getFilmHeight()/e;this.fov=L*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){let e=Math.tan(se*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return L*2*Math.atan(Math.tan(se*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}setViewOffset(e,t,n,r,i,a){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=r,this.view.width=i,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=this.near,t=e*Math.tan(se*.5*this.fov)/this.zoom,n=2*t,r=this.aspect*n,i=-.5*r,a=this.view;if(this.view!==null&&this.view.enabled){let e=a.fullWidth,o=a.fullHeight;i+=a.offsetX*r/e,t-=a.offsetY*n/o,r*=a.width/e,n*=a.height/o}let o=this.filmOffset;o!==0&&(i+=e*o/this.getFilmWidth()),this.projectionMatrix.makePerspective(i,i+r,t,t-n,e,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}},or=-90,sr=1,cr=class extends qt{constructor(e,t,n){super(),this.type=`CubeCamera`,this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;let r=new ar(or,sr,e,t);r.layers=this.layers,this.add(r);let i=new ar(or,sr,e,t);i.layers=this.layers,this.add(i);let a=new ar(or,sr,e,t);a.layers=this.layers,this.add(a);let o=new ar(or,sr,e,t);o.layers=this.layers,this.add(o);let s=new ar(or,sr,e,t);s.layers=this.layers,this.add(s);let c=new ar(or,sr,e,t);c.layers=this.layers,this.add(c)}updateCoordinateSystem(){let e=this.coordinateSystem,t=this.children.concat(),[n,r,i,a,o,s]=t;for(let e of t)this.remove(e);if(e===2e3)n.up.set(0,1,0),n.lookAt(1,0,0),r.up.set(0,1,0),r.lookAt(-1,0,0),i.up.set(0,0,-1),i.lookAt(0,1,0),a.up.set(0,0,1),a.lookAt(0,-1,0),o.up.set(0,1,0),o.lookAt(0,0,1),s.up.set(0,1,0),s.lookAt(0,0,-1);else if(e===2001)n.up.set(0,-1,0),n.lookAt(-1,0,0),r.up.set(0,-1,0),r.lookAt(1,0,0),i.up.set(0,0,1),i.lookAt(0,1,0),a.up.set(0,0,-1),a.lookAt(0,-1,0),o.up.set(0,-1,0),o.lookAt(0,0,1),s.up.set(0,-1,0),s.lookAt(0,0,-1);else throw Error(`THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: `+e);for(let e of t)this.add(e),e.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();let{renderTarget:n,activeMipmapLevel:r}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());let[i,a,o,s,c,l]=this.children,u=e.getRenderTarget(),d=e.getActiveCubeFace(),f=e.getActiveMipmapLevel(),p=e.xr.enabled;e.xr.enabled=!1;let m=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,e.setRenderTarget(n,0,r),e.render(t,i),e.setRenderTarget(n,1,r),e.render(t,a),e.setRenderTarget(n,2,r),e.render(t,o),e.setRenderTarget(n,3,r),e.render(t,s),e.setRenderTarget(n,4,r),e.render(t,c),n.texture.generateMipmaps=m,e.setRenderTarget(n,5,r),e.render(t,l),e.setRenderTarget(u,d,f),e.xr.enabled=p,n.texture.needsPMREMUpdate=!0}},lr=class extends Be{constructor(e,t,n,r,i,a,o,s,c,l){e=e===void 0?[]:e,t=t===void 0?301:t,super(e,t,n,r,i,a,o,s,c,l),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}},ur=class extends Ue{constructor(e=1,t={}){super(e,e,t),this.isWebGLCubeRenderTarget=!0;let n={width:e,height:e,depth:1},r=[n,n,n,n,n,n];t.encoding!==void 0&&(De(`THREE.WebGLCubeRenderTarget: option.encoding has been replaced by option.colorSpace.`),t.colorSpace=t.encoding===3001?A:``),this.texture=new lr(r,t.mapping,t.wrapS,t.wrapT,t.magFilter,t.minFilter,t.format,t.type,t.anisotropy,t.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=t.generateMipmaps!==void 0&&t.generateMipmaps,this.texture.minFilter=t.minFilter===void 0?l:t.minFilter}fromEquirectangularTexture(e,t){this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;let n={uniforms:{tEquirect:{value:null}},vertexShader:`
6
+
7
+ varying vec3 vWorldDirection;
8
+
9
+ vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
10
+
11
+ return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
12
+
13
+ }
14
+
15
+ void main() {
16
+
17
+ vWorldDirection = transformDirection( position, modelMatrix );
18
+
19
+ #include <begin_vertex>
20
+ #include <project_vertex>
21
+
22
+ }
23
+ `,fragmentShader:`
24
+
25
+ uniform sampler2D tEquirect;
26
+
27
+ varying vec3 vWorldDirection;
28
+
29
+ #include <common>
30
+
31
+ void main() {
32
+
33
+ vec3 direction = normalize( vWorldDirection );
34
+
35
+ vec2 sampleUV = equirectUv( direction );
36
+
37
+ gl_FragColor = texture2D( tEquirect, sampleUV );
38
+
39
+ }
40
+ `},r=new Yn(5,5,5),i=new rr({name:`CubemapFromEquirect`,uniforms:Xn(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:1,blending:0});i.uniforms.tEquirect.value=t;let a=new Kn(r,i),o=t.minFilter;return t.minFilter===1008&&(t.minFilter=l),new cr(1,10,this).update(e,a),t.minFilter=o,a.geometry.dispose(),a.material.dispose(),this}clear(e,t,n,r){let i=e.getRenderTarget();for(let i=0;i<6;i++)e.setRenderTarget(this,i),e.clear(t,n,r);e.setRenderTarget(i)}},dr=new X,fr=new X,pr=new q,mr=class{constructor(e=new X(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,n,r){return this.normal.set(e,t,n),this.constant=r,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,n){let r=dr.subVectors(n,t).cross(fr.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(r,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){let e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t){let n=e.delta(dr),r=this.normal.dot(n);if(r===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;let i=-(e.start.dot(this.normal)+this.constant)/r;return i<0||i>1?null:t.copy(e.start).addScaledVector(n,i)}intersectsLine(e){let t=this.distanceToPoint(e.start),n=this.distanceToPoint(e.end);return t<0&&n>0||n<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){let n=t||pr.getNormalMatrix(e),r=this.coplanarPoint(dr).applyMatrix4(e),i=this.normal.applyMatrix3(n).normalize();return this.constant=-r.dot(i),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}},hr=new pt,gr=new X,_r=class{constructor(e=new mr,t=new mr,n=new mr,r=new mr,i=new mr,a=new mr){this.planes=[e,t,n,r,i,a]}set(e,t,n,r,i,a){let o=this.planes;return o[0].copy(e),o[1].copy(t),o[2].copy(n),o[3].copy(r),o[4].copy(i),o[5].copy(a),this}copy(e){let t=this.planes;for(let n=0;n<6;n++)t[n].copy(e.planes[n]);return this}setFromProjectionMatrix(e,t=ae){let n=this.planes,r=e.elements,i=r[0],a=r[1],o=r[2],s=r[3],c=r[4],l=r[5],u=r[6],d=r[7],f=r[8],p=r[9],m=r[10],h=r[11],g=r[12],_=r[13],v=r[14],y=r[15];if(n[0].setComponents(s-i,d-c,h-f,y-g).normalize(),n[1].setComponents(s+i,d+c,h+f,y+g).normalize(),n[2].setComponents(s+a,d+l,h+p,y+_).normalize(),n[3].setComponents(s-a,d-l,h-p,y-_).normalize(),n[4].setComponents(s-o,d-u,h-m,y-v).normalize(),t===2e3)n[5].setComponents(s+o,d+u,h+m,y+v).normalize();else if(t===2001)n[5].setComponents(o,u,m,v).normalize();else throw Error(`THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: `+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),hr.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{let t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),hr.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(hr)}intersectsSprite(e){return hr.center.set(0,0,0),hr.radius=.7071067811865476,hr.applyMatrix4(e.matrixWorld),this.intersectsSphere(hr)}intersectsSphere(e){let t=this.planes,n=e.center,r=-e.radius;for(let e=0;e<6;e++)if(t[e].distanceToPoint(n)<r)return!1;return!0}intersectsBox(e){let t=this.planes;for(let n=0;n<6;n++){let r=t[n];if(gr.x=r.normal.x>0?e.max.x:e.min.x,gr.y=r.normal.y>0?e.max.y:e.min.y,gr.z=r.normal.z>0?e.max.z:e.min.z,r.distanceToPoint(gr)<0)return!1}return!0}containsPoint(e){let t=this.planes;for(let n=0;n<6;n++)if(t[n].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}};function vr(){let e=null,t=!1,n=null,r=null;function i(t,a){n(t,a),r=e.requestAnimationFrame(i)}return{start:function(){t!==!0&&n!==null&&(r=e.requestAnimationFrame(i),t=!0)},stop:function(){e.cancelAnimationFrame(r),t=!1},setAnimationLoop:function(e){n=e},setContext:function(t){e=t}}}function yr(e,t){let n=t.isWebGL2,r=new WeakMap;function i(t,r){let i=t.array,a=t.usage,o=i.byteLength,s=e.createBuffer();e.bindBuffer(r,s),e.bufferData(r,i,a),t.onUploadCallback();let c;if(i instanceof Float32Array)c=e.FLOAT;else if(i instanceof Uint16Array)if(t.isFloat16BufferAttribute)if(n)c=e.HALF_FLOAT;else throw Error(`THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.`);else c=e.UNSIGNED_SHORT;else if(i instanceof Int16Array)c=e.SHORT;else if(i instanceof Uint32Array)c=e.UNSIGNED_INT;else if(i instanceof Int32Array)c=e.INT;else if(i instanceof Int8Array)c=e.BYTE;else if(i instanceof Uint8Array)c=e.UNSIGNED_BYTE;else if(i instanceof Uint8ClampedArray)c=e.UNSIGNED_BYTE;else throw Error(`THREE.WebGLAttributes: Unsupported buffer data format: `+i);return{buffer:s,type:c,bytesPerElement:i.BYTES_PER_ELEMENT,version:t.version,size:o}}function a(t,r,i){let a=r.array,o=r._updateRange,s=r.updateRanges;if(e.bindBuffer(i,t),o.count===-1&&s.length===0&&e.bufferSubData(i,0,a),s.length!==0){for(let t=0,r=s.length;t<r;t++){let r=s[t];n?e.bufferSubData(i,r.start*a.BYTES_PER_ELEMENT,a,r.start,r.count):e.bufferSubData(i,r.start*a.BYTES_PER_ELEMENT,a.subarray(r.start,r.start+r.count))}r.clearUpdateRanges()}o.count!==-1&&(n?e.bufferSubData(i,o.offset*a.BYTES_PER_ELEMENT,a,o.offset,o.count):e.bufferSubData(i,o.offset*a.BYTES_PER_ELEMENT,a.subarray(o.offset,o.offset+o.count)),o.count=-1),r.onUploadCallback()}function o(e){return e.isInterleavedBufferAttribute&&(e=e.data),r.get(e)}function s(t){t.isInterleavedBufferAttribute&&(t=t.data);let n=r.get(t);n&&(e.deleteBuffer(n.buffer),r.delete(t))}function c(e,t){if(e.isGLBufferAttribute){let t=r.get(e);(!t||t.version<e.version)&&r.set(e,{buffer:e.buffer,type:e.type,bytesPerElement:e.elementSize,version:e.version});return}e.isInterleavedBufferAttribute&&(e=e.data);let n=r.get(e);if(n===void 0)r.set(e,i(e,t));else if(n.version<e.version){if(n.size!==e.array.byteLength)throw Error(`THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.`);a(n.buffer,e,t),n.version=e.version}}return{get:o,remove:s,update:c}}var br=class e extends On{constructor(e=1,t=1,n=1,r=1){super(),this.type=`PlaneGeometry`,this.parameters={width:e,height:t,widthSegments:n,heightSegments:r};let i=e/2,a=t/2,o=Math.floor(n),s=Math.floor(r),c=o+1,l=s+1,u=e/o,d=t/s,f=[],p=[],m=[],h=[];for(let e=0;e<l;e++){let t=e*d-a;for(let n=0;n<c;n++){let r=n*u-i;p.push(r,-t,0),m.push(0,0,1),h.push(n/o),h.push(1-e/s)}}for(let e=0;e<s;e++)for(let t=0;t<o;t++){let n=t+c*e,r=t+c*(e+1),i=t+1+c*(e+1),a=t+1+c*e;f.push(n,r,a),f.push(r,i,a)}this.setIndex(f),this.setAttribute(`position`,new bn(p,3)),this.setAttribute(`normal`,new bn(m,3)),this.setAttribute(`uv`,new bn(h,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(t){return new e(t.width,t.height,t.widthSegments,t.heightSegments)}},Q={alphahash_fragment:`#ifdef USE_ALPHAHASH
41
+ if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
42
+ #endif`,alphahash_pars_fragment:`#ifdef USE_ALPHAHASH
43
+ const float ALPHA_HASH_SCALE = 0.05;
44
+ float hash2D( vec2 value ) {
45
+ return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );
46
+ }
47
+ float hash3D( vec3 value ) {
48
+ return hash2D( vec2( hash2D( value.xy ), value.z ) );
49
+ }
50
+ float getAlphaHashThreshold( vec3 position ) {
51
+ float maxDeriv = max(
52
+ length( dFdx( position.xyz ) ),
53
+ length( dFdy( position.xyz ) )
54
+ );
55
+ float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );
56
+ vec2 pixScales = vec2(
57
+ exp2( floor( log2( pixScale ) ) ),
58
+ exp2( ceil( log2( pixScale ) ) )
59
+ );
60
+ vec2 alpha = vec2(
61
+ hash3D( floor( pixScales.x * position.xyz ) ),
62
+ hash3D( floor( pixScales.y * position.xyz ) )
63
+ );
64
+ float lerpFactor = fract( log2( pixScale ) );
65
+ float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;
66
+ float a = min( lerpFactor, 1.0 - lerpFactor );
67
+ vec3 cases = vec3(
68
+ x * x / ( 2.0 * a * ( 1.0 - a ) ),
69
+ ( x - 0.5 * a ) / ( 1.0 - a ),
70
+ 1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )
71
+ );
72
+ float threshold = ( x < ( 1.0 - a ) )
73
+ ? ( ( x < a ) ? cases.x : cases.y )
74
+ : cases.z;
75
+ return clamp( threshold , 1.0e-6, 1.0 );
76
+ }
77
+ #endif`,alphamap_fragment:`#ifdef USE_ALPHAMAP
78
+ diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;
79
+ #endif`,alphamap_pars_fragment:`#ifdef USE_ALPHAMAP
80
+ uniform sampler2D alphaMap;
81
+ #endif`,alphatest_fragment:`#ifdef USE_ALPHATEST
82
+ if ( diffuseColor.a < alphaTest ) discard;
83
+ #endif`,alphatest_pars_fragment:`#ifdef USE_ALPHATEST
84
+ uniform float alphaTest;
85
+ #endif`,aomap_fragment:`#ifdef USE_AOMAP
86
+ float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;
87
+ reflectedLight.indirectDiffuse *= ambientOcclusion;
88
+ #if defined( USE_CLEARCOAT )
89
+ clearcoatSpecularIndirect *= ambientOcclusion;
90
+ #endif
91
+ #if defined( USE_SHEEN )
92
+ sheenSpecularIndirect *= ambientOcclusion;
93
+ #endif
94
+ #if defined( USE_ENVMAP ) && defined( STANDARD )
95
+ float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
96
+ reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
97
+ #endif
98
+ #endif`,aomap_pars_fragment:`#ifdef USE_AOMAP
99
+ uniform sampler2D aoMap;
100
+ uniform float aoMapIntensity;
101
+ #endif`,batching_pars_vertex:`#ifdef USE_BATCHING
102
+ attribute float batchId;
103
+ uniform highp sampler2D batchingTexture;
104
+ mat4 getBatchingMatrix( const in float i ) {
105
+ int size = textureSize( batchingTexture, 0 ).x;
106
+ int j = int( i ) * 4;
107
+ int x = j % size;
108
+ int y = j / size;
109
+ vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
110
+ vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
111
+ vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
112
+ vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
113
+ return mat4( v1, v2, v3, v4 );
114
+ }
115
+ #endif`,batching_vertex:`#ifdef USE_BATCHING
116
+ mat4 batchingMatrix = getBatchingMatrix( batchId );
117
+ #endif`,begin_vertex:`vec3 transformed = vec3( position );
118
+ #ifdef USE_ALPHAHASH
119
+ vPosition = vec3( position );
120
+ #endif`,beginnormal_vertex:`vec3 objectNormal = vec3( normal );
121
+ #ifdef USE_TANGENT
122
+ vec3 objectTangent = vec3( tangent.xyz );
123
+ #endif`,bsdfs:`float G_BlinnPhong_Implicit( ) {
124
+ return 0.25;
125
+ }
126
+ float D_BlinnPhong( const in float shininess, const in float dotNH ) {
127
+ return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
128
+ }
129
+ vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {
130
+ vec3 halfDir = normalize( lightDir + viewDir );
131
+ float dotNH = saturate( dot( normal, halfDir ) );
132
+ float dotVH = saturate( dot( viewDir, halfDir ) );
133
+ vec3 F = F_Schlick( specularColor, 1.0, dotVH );
134
+ float G = G_BlinnPhong_Implicit( );
135
+ float D = D_BlinnPhong( shininess, dotNH );
136
+ return F * ( G * D );
137
+ } // validated`,iridescence_fragment:`#ifdef USE_IRIDESCENCE
138
+ const mat3 XYZ_TO_REC709 = mat3(
139
+ 3.2404542, -0.9692660, 0.0556434,
140
+ -1.5371385, 1.8760108, -0.2040259,
141
+ -0.4985314, 0.0415560, 1.0572252
142
+ );
143
+ vec3 Fresnel0ToIor( vec3 fresnel0 ) {
144
+ vec3 sqrtF0 = sqrt( fresnel0 );
145
+ return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
146
+ }
147
+ vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {
148
+ return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
149
+ }
150
+ float IorToFresnel0( float transmittedIor, float incidentIor ) {
151
+ return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));
152
+ }
153
+ vec3 evalSensitivity( float OPD, vec3 shift ) {
154
+ float phase = 2.0 * PI * OPD * 1.0e-9;
155
+ vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
156
+ vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
157
+ vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
158
+ vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );
159
+ xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );
160
+ xyz /= 1.0685e-7;
161
+ vec3 rgb = XYZ_TO_REC709 * xyz;
162
+ return rgb;
163
+ }
164
+ vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
165
+ vec3 I;
166
+ float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
167
+ float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );
168
+ float cosTheta2Sq = 1.0 - sinTheta2Sq;
169
+ if ( cosTheta2Sq < 0.0 ) {
170
+ return vec3( 1.0 );
171
+ }
172
+ float cosTheta2 = sqrt( cosTheta2Sq );
173
+ float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );
174
+ float R12 = F_Schlick( R0, 1.0, cosTheta1 );
175
+ float T121 = 1.0 - R12;
176
+ float phi12 = 0.0;
177
+ if ( iridescenceIOR < outsideIOR ) phi12 = PI;
178
+ float phi21 = PI - phi12;
179
+ vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );
180
+ vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );
181
+ vec3 phi23 = vec3( 0.0 );
182
+ if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;
183
+ if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;
184
+ if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;
185
+ float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;
186
+ vec3 phi = vec3( phi21 ) + phi23;
187
+ vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
188
+ vec3 r123 = sqrt( R123 );
189
+ vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
190
+ vec3 C0 = R12 + Rs;
191
+ I = C0;
192
+ vec3 Cm = Rs - T121;
193
+ for ( int m = 1; m <= 2; ++ m ) {
194
+ Cm *= r123;
195
+ vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
196
+ I += Cm * Sm;
197
+ }
198
+ return max( I, vec3( 0.0 ) );
199
+ }
200
+ #endif`,bumpmap_pars_fragment:`#ifdef USE_BUMPMAP
201
+ uniform sampler2D bumpMap;
202
+ uniform float bumpScale;
203
+ vec2 dHdxy_fwd() {
204
+ vec2 dSTdx = dFdx( vBumpMapUv );
205
+ vec2 dSTdy = dFdy( vBumpMapUv );
206
+ float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;
207
+ float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;
208
+ float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;
209
+ return vec2( dBx, dBy );
210
+ }
211
+ vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
212
+ vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );
213
+ vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );
214
+ vec3 vN = surf_norm;
215
+ vec3 R1 = cross( vSigmaY, vN );
216
+ vec3 R2 = cross( vN, vSigmaX );
217
+ float fDet = dot( vSigmaX, R1 ) * faceDirection;
218
+ vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
219
+ return normalize( abs( fDet ) * surf_norm - vGrad );
220
+ }
221
+ #endif`,clipping_planes_fragment:`#if NUM_CLIPPING_PLANES > 0
222
+ vec4 plane;
223
+ #pragma unroll_loop_start
224
+ for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
225
+ plane = clippingPlanes[ i ];
226
+ if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;
227
+ }
228
+ #pragma unroll_loop_end
229
+ #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
230
+ bool clipped = true;
231
+ #pragma unroll_loop_start
232
+ for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
233
+ plane = clippingPlanes[ i ];
234
+ clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;
235
+ }
236
+ #pragma unroll_loop_end
237
+ if ( clipped ) discard;
238
+ #endif
239
+ #endif`,clipping_planes_pars_fragment:`#if NUM_CLIPPING_PLANES > 0
240
+ varying vec3 vClipPosition;
241
+ uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
242
+ #endif`,clipping_planes_pars_vertex:`#if NUM_CLIPPING_PLANES > 0
243
+ varying vec3 vClipPosition;
244
+ #endif`,clipping_planes_vertex:`#if NUM_CLIPPING_PLANES > 0
245
+ vClipPosition = - mvPosition.xyz;
246
+ #endif`,color_fragment:`#if defined( USE_COLOR_ALPHA )
247
+ diffuseColor *= vColor;
248
+ #elif defined( USE_COLOR )
249
+ diffuseColor.rgb *= vColor;
250
+ #endif`,color_pars_fragment:`#if defined( USE_COLOR_ALPHA )
251
+ varying vec4 vColor;
252
+ #elif defined( USE_COLOR )
253
+ varying vec3 vColor;
254
+ #endif`,color_pars_vertex:`#if defined( USE_COLOR_ALPHA )
255
+ varying vec4 vColor;
256
+ #elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )
257
+ varying vec3 vColor;
258
+ #endif`,color_vertex:`#if defined( USE_COLOR_ALPHA )
259
+ vColor = vec4( 1.0 );
260
+ #elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )
261
+ vColor = vec3( 1.0 );
262
+ #endif
263
+ #ifdef USE_COLOR
264
+ vColor *= color;
265
+ #endif
266
+ #ifdef USE_INSTANCING_COLOR
267
+ vColor.xyz *= instanceColor.xyz;
268
+ #endif`,common:`#define PI 3.141592653589793
269
+ #define PI2 6.283185307179586
270
+ #define PI_HALF 1.5707963267948966
271
+ #define RECIPROCAL_PI 0.3183098861837907
272
+ #define RECIPROCAL_PI2 0.15915494309189535
273
+ #define EPSILON 1e-6
274
+ #ifndef saturate
275
+ #define saturate( a ) clamp( a, 0.0, 1.0 )
276
+ #endif
277
+ #define whiteComplement( a ) ( 1.0 - saturate( a ) )
278
+ float pow2( const in float x ) { return x*x; }
279
+ vec3 pow2( const in vec3 x ) { return x*x; }
280
+ float pow3( const in float x ) { return x*x*x; }
281
+ float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
282
+ float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
283
+ float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }
284
+ highp float rand( const in vec2 uv ) {
285
+ const highp float a = 12.9898, b = 78.233, c = 43758.5453;
286
+ highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
287
+ return fract( sin( sn ) * c );
288
+ }
289
+ #ifdef HIGH_PRECISION
290
+ float precisionSafeLength( vec3 v ) { return length( v ); }
291
+ #else
292
+ float precisionSafeLength( vec3 v ) {
293
+ float maxComponent = max3( abs( v ) );
294
+ return length( v / maxComponent ) * maxComponent;
295
+ }
296
+ #endif
297
+ struct IncidentLight {
298
+ vec3 color;
299
+ vec3 direction;
300
+ bool visible;
301
+ };
302
+ struct ReflectedLight {
303
+ vec3 directDiffuse;
304
+ vec3 directSpecular;
305
+ vec3 indirectDiffuse;
306
+ vec3 indirectSpecular;
307
+ };
308
+ #ifdef USE_ALPHAHASH
309
+ varying vec3 vPosition;
310
+ #endif
311
+ vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
312
+ return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
313
+ }
314
+ vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
315
+ return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
316
+ }
317
+ mat3 transposeMat3( const in mat3 m ) {
318
+ mat3 tmp;
319
+ tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );
320
+ tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );
321
+ tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );
322
+ return tmp;
323
+ }
324
+ float luminance( const in vec3 rgb ) {
325
+ const vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 );
326
+ return dot( weights, rgb );
327
+ }
328
+ bool isPerspectiveMatrix( mat4 m ) {
329
+ return m[ 2 ][ 3 ] == - 1.0;
330
+ }
331
+ vec2 equirectUv( in vec3 dir ) {
332
+ float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
333
+ float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
334
+ return vec2( u, v );
335
+ }
336
+ vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
337
+ return RECIPROCAL_PI * diffuseColor;
338
+ }
339
+ vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
340
+ float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
341
+ return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
342
+ }
343
+ float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
344
+ float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
345
+ return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
346
+ } // validated`,cube_uv_reflection_fragment:`#ifdef ENVMAP_TYPE_CUBE_UV
347
+ #define cubeUV_minMipLevel 4.0
348
+ #define cubeUV_minTileSize 16.0
349
+ float getFace( vec3 direction ) {
350
+ vec3 absDirection = abs( direction );
351
+ float face = - 1.0;
352
+ if ( absDirection.x > absDirection.z ) {
353
+ if ( absDirection.x > absDirection.y )
354
+ face = direction.x > 0.0 ? 0.0 : 3.0;
355
+ else
356
+ face = direction.y > 0.0 ? 1.0 : 4.0;
357
+ } else {
358
+ if ( absDirection.z > absDirection.y )
359
+ face = direction.z > 0.0 ? 2.0 : 5.0;
360
+ else
361
+ face = direction.y > 0.0 ? 1.0 : 4.0;
362
+ }
363
+ return face;
364
+ }
365
+ vec2 getUV( vec3 direction, float face ) {
366
+ vec2 uv;
367
+ if ( face == 0.0 ) {
368
+ uv = vec2( direction.z, direction.y ) / abs( direction.x );
369
+ } else if ( face == 1.0 ) {
370
+ uv = vec2( - direction.x, - direction.z ) / abs( direction.y );
371
+ } else if ( face == 2.0 ) {
372
+ uv = vec2( - direction.x, direction.y ) / abs( direction.z );
373
+ } else if ( face == 3.0 ) {
374
+ uv = vec2( - direction.z, direction.y ) / abs( direction.x );
375
+ } else if ( face == 4.0 ) {
376
+ uv = vec2( - direction.x, direction.z ) / abs( direction.y );
377
+ } else {
378
+ uv = vec2( direction.x, direction.y ) / abs( direction.z );
379
+ }
380
+ return 0.5 * ( uv + 1.0 );
381
+ }
382
+ vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {
383
+ float face = getFace( direction );
384
+ float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );
385
+ mipInt = max( mipInt, cubeUV_minMipLevel );
386
+ float faceSize = exp2( mipInt );
387
+ highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;
388
+ if ( face > 2.0 ) {
389
+ uv.y += faceSize;
390
+ face -= 3.0;
391
+ }
392
+ uv.x += face * faceSize;
393
+ uv.x += filterInt * 3.0 * cubeUV_minTileSize;
394
+ uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );
395
+ uv.x *= CUBEUV_TEXEL_WIDTH;
396
+ uv.y *= CUBEUV_TEXEL_HEIGHT;
397
+ #ifdef texture2DGradEXT
398
+ return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;
399
+ #else
400
+ return texture2D( envMap, uv ).rgb;
401
+ #endif
402
+ }
403
+ #define cubeUV_r0 1.0
404
+ #define cubeUV_v0 0.339
405
+ #define cubeUV_m0 - 2.0
406
+ #define cubeUV_r1 0.8
407
+ #define cubeUV_v1 0.276
408
+ #define cubeUV_m1 - 1.0
409
+ #define cubeUV_r4 0.4
410
+ #define cubeUV_v4 0.046
411
+ #define cubeUV_m4 2.0
412
+ #define cubeUV_r5 0.305
413
+ #define cubeUV_v5 0.016
414
+ #define cubeUV_m5 3.0
415
+ #define cubeUV_r6 0.21
416
+ #define cubeUV_v6 0.0038
417
+ #define cubeUV_m6 4.0
418
+ float roughnessToMip( float roughness ) {
419
+ float mip = 0.0;
420
+ if ( roughness >= cubeUV_r1 ) {
421
+ mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;
422
+ } else if ( roughness >= cubeUV_r4 ) {
423
+ mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;
424
+ } else if ( roughness >= cubeUV_r5 ) {
425
+ mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;
426
+ } else if ( roughness >= cubeUV_r6 ) {
427
+ mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;
428
+ } else {
429
+ mip = - 2.0 * log2( 1.16 * roughness ); }
430
+ return mip;
431
+ }
432
+ vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {
433
+ float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );
434
+ float mipF = fract( mip );
435
+ float mipInt = floor( mip );
436
+ vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );
437
+ if ( mipF == 0.0 ) {
438
+ return vec4( color0, 1.0 );
439
+ } else {
440
+ vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );
441
+ return vec4( mix( color0, color1, mipF ), 1.0 );
442
+ }
443
+ }
444
+ #endif`,defaultnormal_vertex:`vec3 transformedNormal = objectNormal;
445
+ #ifdef USE_TANGENT
446
+ vec3 transformedTangent = objectTangent;
447
+ #endif
448
+ #ifdef USE_BATCHING
449
+ mat3 bm = mat3( batchingMatrix );
450
+ transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );
451
+ transformedNormal = bm * transformedNormal;
452
+ #ifdef USE_TANGENT
453
+ transformedTangent = bm * transformedTangent;
454
+ #endif
455
+ #endif
456
+ #ifdef USE_INSTANCING
457
+ mat3 im = mat3( instanceMatrix );
458
+ transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );
459
+ transformedNormal = im * transformedNormal;
460
+ #ifdef USE_TANGENT
461
+ transformedTangent = im * transformedTangent;
462
+ #endif
463
+ #endif
464
+ transformedNormal = normalMatrix * transformedNormal;
465
+ #ifdef FLIP_SIDED
466
+ transformedNormal = - transformedNormal;
467
+ #endif
468
+ #ifdef USE_TANGENT
469
+ transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;
470
+ #ifdef FLIP_SIDED
471
+ transformedTangent = - transformedTangent;
472
+ #endif
473
+ #endif`,displacementmap_pars_vertex:`#ifdef USE_DISPLACEMENTMAP
474
+ uniform sampler2D displacementMap;
475
+ uniform float displacementScale;
476
+ uniform float displacementBias;
477
+ #endif`,displacementmap_vertex:`#ifdef USE_DISPLACEMENTMAP
478
+ transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
479
+ #endif`,emissivemap_fragment:`#ifdef USE_EMISSIVEMAP
480
+ vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
481
+ totalEmissiveRadiance *= emissiveColor.rgb;
482
+ #endif`,emissivemap_pars_fragment:`#ifdef USE_EMISSIVEMAP
483
+ uniform sampler2D emissiveMap;
484
+ #endif`,colorspace_fragment:`gl_FragColor = linearToOutputTexel( gl_FragColor );`,colorspace_pars_fragment:`
485
+ const mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(
486
+ vec3( 0.8224621, 0.177538, 0.0 ),
487
+ vec3( 0.0331941, 0.9668058, 0.0 ),
488
+ vec3( 0.0170827, 0.0723974, 0.9105199 )
489
+ );
490
+ const mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3(
491
+ vec3( 1.2249401, - 0.2249404, 0.0 ),
492
+ vec3( - 0.0420569, 1.0420571, 0.0 ),
493
+ vec3( - 0.0196376, - 0.0786361, 1.0982735 )
494
+ );
495
+ vec4 LinearSRGBToLinearDisplayP3( in vec4 value ) {
496
+ return vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a );
497
+ }
498
+ vec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) {
499
+ return vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a );
500
+ }
501
+ vec4 LinearTransferOETF( in vec4 value ) {
502
+ return value;
503
+ }
504
+ vec4 sRGBTransferOETF( in vec4 value ) {
505
+ return 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 );
506
+ }
507
+ vec4 LinearToLinear( in vec4 value ) {
508
+ return value;
509
+ }
510
+ vec4 LinearTosRGB( in vec4 value ) {
511
+ return sRGBTransferOETF( value );
512
+ }`,envmap_fragment:`#ifdef USE_ENVMAP
513
+ #ifdef ENV_WORLDPOS
514
+ vec3 cameraToFrag;
515
+ if ( isOrthographic ) {
516
+ cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
517
+ } else {
518
+ cameraToFrag = normalize( vWorldPosition - cameraPosition );
519
+ }
520
+ vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
521
+ #ifdef ENVMAP_MODE_REFLECTION
522
+ vec3 reflectVec = reflect( cameraToFrag, worldNormal );
523
+ #else
524
+ vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
525
+ #endif
526
+ #else
527
+ vec3 reflectVec = vReflect;
528
+ #endif
529
+ #ifdef ENVMAP_TYPE_CUBE
530
+ vec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
531
+ #else
532
+ vec4 envColor = vec4( 0.0 );
533
+ #endif
534
+ #ifdef ENVMAP_BLENDING_MULTIPLY
535
+ outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
536
+ #elif defined( ENVMAP_BLENDING_MIX )
537
+ outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
538
+ #elif defined( ENVMAP_BLENDING_ADD )
539
+ outgoingLight += envColor.xyz * specularStrength * reflectivity;
540
+ #endif
541
+ #endif`,envmap_common_pars_fragment:`#ifdef USE_ENVMAP
542
+ uniform float envMapIntensity;
543
+ uniform float flipEnvMap;
544
+ #ifdef ENVMAP_TYPE_CUBE
545
+ uniform samplerCube envMap;
546
+ #else
547
+ uniform sampler2D envMap;
548
+ #endif
549
+
550
+ #endif`,envmap_pars_fragment:`#ifdef USE_ENVMAP
551
+ uniform float reflectivity;
552
+ #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
553
+ #define ENV_WORLDPOS
554
+ #endif
555
+ #ifdef ENV_WORLDPOS
556
+ varying vec3 vWorldPosition;
557
+ uniform float refractionRatio;
558
+ #else
559
+ varying vec3 vReflect;
560
+ #endif
561
+ #endif`,envmap_pars_vertex:`#ifdef USE_ENVMAP
562
+ #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
563
+ #define ENV_WORLDPOS
564
+ #endif
565
+ #ifdef ENV_WORLDPOS
566
+
567
+ varying vec3 vWorldPosition;
568
+ #else
569
+ varying vec3 vReflect;
570
+ uniform float refractionRatio;
571
+ #endif
572
+ #endif`,envmap_physical_pars_fragment:`#ifdef USE_ENVMAP
573
+ vec3 getIBLIrradiance( const in vec3 normal ) {
574
+ #ifdef ENVMAP_TYPE_CUBE_UV
575
+ vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
576
+ vec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );
577
+ return PI * envMapColor.rgb * envMapIntensity;
578
+ #else
579
+ return vec3( 0.0 );
580
+ #endif
581
+ }
582
+ vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
583
+ #ifdef ENVMAP_TYPE_CUBE_UV
584
+ vec3 reflectVec = reflect( - viewDir, normal );
585
+ reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
586
+ reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
587
+ vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );
588
+ return envMapColor.rgb * envMapIntensity;
589
+ #else
590
+ return vec3( 0.0 );
591
+ #endif
592
+ }
593
+ #ifdef USE_ANISOTROPY
594
+ vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
595
+ #ifdef ENVMAP_TYPE_CUBE_UV
596
+ vec3 bentNormal = cross( bitangent, viewDir );
597
+ bentNormal = normalize( cross( bentNormal, bitangent ) );
598
+ bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
599
+ return getIBLRadiance( viewDir, bentNormal, roughness );
600
+ #else
601
+ return vec3( 0.0 );
602
+ #endif
603
+ }
604
+ #endif
605
+ #endif`,envmap_vertex:`#ifdef USE_ENVMAP
606
+ #ifdef ENV_WORLDPOS
607
+ vWorldPosition = worldPosition.xyz;
608
+ #else
609
+ vec3 cameraToVertex;
610
+ if ( isOrthographic ) {
611
+ cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
612
+ } else {
613
+ cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
614
+ }
615
+ vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
616
+ #ifdef ENVMAP_MODE_REFLECTION
617
+ vReflect = reflect( cameraToVertex, worldNormal );
618
+ #else
619
+ vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
620
+ #endif
621
+ #endif
622
+ #endif`,fog_vertex:`#ifdef USE_FOG
623
+ vFogDepth = - mvPosition.z;
624
+ #endif`,fog_pars_vertex:`#ifdef USE_FOG
625
+ varying float vFogDepth;
626
+ #endif`,fog_fragment:`#ifdef USE_FOG
627
+ #ifdef FOG_EXP2
628
+ float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
629
+ #else
630
+ float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
631
+ #endif
632
+ gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
633
+ #endif`,fog_pars_fragment:`#ifdef USE_FOG
634
+ uniform vec3 fogColor;
635
+ varying float vFogDepth;
636
+ #ifdef FOG_EXP2
637
+ uniform float fogDensity;
638
+ #else
639
+ uniform float fogNear;
640
+ uniform float fogFar;
641
+ #endif
642
+ #endif`,gradientmap_pars_fragment:`#ifdef USE_GRADIENTMAP
643
+ uniform sampler2D gradientMap;
644
+ #endif
645
+ vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
646
+ float dotNL = dot( normal, lightDirection );
647
+ vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );
648
+ #ifdef USE_GRADIENTMAP
649
+ return vec3( texture2D( gradientMap, coord ).r );
650
+ #else
651
+ vec2 fw = fwidth( coord ) * 0.5;
652
+ return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );
653
+ #endif
654
+ }`,lightmap_fragment:`#ifdef USE_LIGHTMAP
655
+ vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
656
+ vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
657
+ reflectedLight.indirectDiffuse += lightMapIrradiance;
658
+ #endif`,lightmap_pars_fragment:`#ifdef USE_LIGHTMAP
659
+ uniform sampler2D lightMap;
660
+ uniform float lightMapIntensity;
661
+ #endif`,lights_lambert_fragment:`LambertMaterial material;
662
+ material.diffuseColor = diffuseColor.rgb;
663
+ material.specularStrength = specularStrength;`,lights_lambert_pars_fragment:`varying vec3 vViewPosition;
664
+ struct LambertMaterial {
665
+ vec3 diffuseColor;
666
+ float specularStrength;
667
+ };
668
+ void 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 ) {
669
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
670
+ vec3 irradiance = dotNL * directLight.color;
671
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
672
+ }
673
+ void 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 ) {
674
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
675
+ }
676
+ #define RE_Direct RE_Direct_Lambert
677
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,lights_pars_begin:`uniform bool receiveShadow;
678
+ uniform vec3 ambientLightColor;
679
+ #if defined( USE_LIGHT_PROBES )
680
+ uniform vec3 lightProbe[ 9 ];
681
+ #endif
682
+ vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
683
+ float x = normal.x, y = normal.y, z = normal.z;
684
+ vec3 result = shCoefficients[ 0 ] * 0.886227;
685
+ result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
686
+ result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
687
+ result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
688
+ result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
689
+ result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
690
+ result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
691
+ result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
692
+ result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
693
+ return result;
694
+ }
695
+ vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
696
+ vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
697
+ vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
698
+ return irradiance;
699
+ }
700
+ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
701
+ vec3 irradiance = ambientLightColor;
702
+ return irradiance;
703
+ }
704
+ float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
705
+ #if defined ( LEGACY_LIGHTS )
706
+ if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {
707
+ return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );
708
+ }
709
+ return 1.0;
710
+ #else
711
+ float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
712
+ if ( cutoffDistance > 0.0 ) {
713
+ distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
714
+ }
715
+ return distanceFalloff;
716
+ #endif
717
+ }
718
+ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
719
+ return smoothstep( coneCosine, penumbraCosine, angleCosine );
720
+ }
721
+ #if NUM_DIR_LIGHTS > 0
722
+ struct DirectionalLight {
723
+ vec3 direction;
724
+ vec3 color;
725
+ };
726
+ uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
727
+ void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {
728
+ light.color = directionalLight.color;
729
+ light.direction = directionalLight.direction;
730
+ light.visible = true;
731
+ }
732
+ #endif
733
+ #if NUM_POINT_LIGHTS > 0
734
+ struct PointLight {
735
+ vec3 position;
736
+ vec3 color;
737
+ float distance;
738
+ float decay;
739
+ };
740
+ uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
741
+ void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {
742
+ vec3 lVector = pointLight.position - geometryPosition;
743
+ light.direction = normalize( lVector );
744
+ float lightDistance = length( lVector );
745
+ light.color = pointLight.color;
746
+ light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
747
+ light.visible = ( light.color != vec3( 0.0 ) );
748
+ }
749
+ #endif
750
+ #if NUM_SPOT_LIGHTS > 0
751
+ struct SpotLight {
752
+ vec3 position;
753
+ vec3 direction;
754
+ vec3 color;
755
+ float distance;
756
+ float decay;
757
+ float coneCos;
758
+ float penumbraCos;
759
+ };
760
+ uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
761
+ void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {
762
+ vec3 lVector = spotLight.position - geometryPosition;
763
+ light.direction = normalize( lVector );
764
+ float angleCos = dot( light.direction, spotLight.direction );
765
+ float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
766
+ if ( spotAttenuation > 0.0 ) {
767
+ float lightDistance = length( lVector );
768
+ light.color = spotLight.color * spotAttenuation;
769
+ light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );
770
+ light.visible = ( light.color != vec3( 0.0 ) );
771
+ } else {
772
+ light.color = vec3( 0.0 );
773
+ light.visible = false;
774
+ }
775
+ }
776
+ #endif
777
+ #if NUM_RECT_AREA_LIGHTS > 0
778
+ struct RectAreaLight {
779
+ vec3 color;
780
+ vec3 position;
781
+ vec3 halfWidth;
782
+ vec3 halfHeight;
783
+ };
784
+ uniform sampler2D ltc_1; uniform sampler2D ltc_2;
785
+ uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];
786
+ #endif
787
+ #if NUM_HEMI_LIGHTS > 0
788
+ struct HemisphereLight {
789
+ vec3 direction;
790
+ vec3 skyColor;
791
+ vec3 groundColor;
792
+ };
793
+ uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];
794
+ vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {
795
+ float dotNL = dot( normal, hemiLight.direction );
796
+ float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
797
+ vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
798
+ return irradiance;
799
+ }
800
+ #endif`,lights_toon_fragment:`ToonMaterial material;
801
+ material.diffuseColor = diffuseColor.rgb;`,lights_toon_pars_fragment:`varying vec3 vViewPosition;
802
+ struct ToonMaterial {
803
+ vec3 diffuseColor;
804
+ };
805
+ void 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 ) {
806
+ vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;
807
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
808
+ }
809
+ void 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 ) {
810
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
811
+ }
812
+ #define RE_Direct RE_Direct_Toon
813
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,lights_phong_fragment:`BlinnPhongMaterial material;
814
+ material.diffuseColor = diffuseColor.rgb;
815
+ material.specularColor = specular;
816
+ material.specularShininess = shininess;
817
+ material.specularStrength = specularStrength;`,lights_phong_pars_fragment:`varying vec3 vViewPosition;
818
+ struct BlinnPhongMaterial {
819
+ vec3 diffuseColor;
820
+ vec3 specularColor;
821
+ float specularShininess;
822
+ float specularStrength;
823
+ };
824
+ void 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 ) {
825
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
826
+ vec3 irradiance = dotNL * directLight.color;
827
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
828
+ reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;
829
+ }
830
+ void 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 ) {
831
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
832
+ }
833
+ #define RE_Direct RE_Direct_BlinnPhong
834
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,lights_physical_fragment:`PhysicalMaterial material;
835
+ material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
836
+ vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
837
+ float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
838
+ material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;
839
+ material.roughness = min( material.roughness, 1.0 );
840
+ #ifdef IOR
841
+ material.ior = ior;
842
+ #ifdef USE_SPECULAR
843
+ float specularIntensityFactor = specularIntensity;
844
+ vec3 specularColorFactor = specularColor;
845
+ #ifdef USE_SPECULAR_COLORMAP
846
+ specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;
847
+ #endif
848
+ #ifdef USE_SPECULAR_INTENSITYMAP
849
+ specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;
850
+ #endif
851
+ material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );
852
+ #else
853
+ float specularIntensityFactor = 1.0;
854
+ vec3 specularColorFactor = vec3( 1.0 );
855
+ material.specularF90 = 1.0;
856
+ #endif
857
+ material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );
858
+ #else
859
+ material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
860
+ material.specularF90 = 1.0;
861
+ #endif
862
+ #ifdef USE_CLEARCOAT
863
+ material.clearcoat = clearcoat;
864
+ material.clearcoatRoughness = clearcoatRoughness;
865
+ material.clearcoatF0 = vec3( 0.04 );
866
+ material.clearcoatF90 = 1.0;
867
+ #ifdef USE_CLEARCOATMAP
868
+ material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;
869
+ #endif
870
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
871
+ material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;
872
+ #endif
873
+ material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );
874
+ material.clearcoatRoughness += geometryRoughness;
875
+ material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
876
+ #endif
877
+ #ifdef USE_IRIDESCENCE
878
+ material.iridescence = iridescence;
879
+ material.iridescenceIOR = iridescenceIOR;
880
+ #ifdef USE_IRIDESCENCEMAP
881
+ material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;
882
+ #endif
883
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
884
+ material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;
885
+ #else
886
+ material.iridescenceThickness = iridescenceThicknessMaximum;
887
+ #endif
888
+ #endif
889
+ #ifdef USE_SHEEN
890
+ material.sheenColor = sheenColor;
891
+ #ifdef USE_SHEEN_COLORMAP
892
+ material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;
893
+ #endif
894
+ material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );
895
+ #ifdef USE_SHEEN_ROUGHNESSMAP
896
+ material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;
897
+ #endif
898
+ #endif
899
+ #ifdef USE_ANISOTROPY
900
+ #ifdef USE_ANISOTROPYMAP
901
+ mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );
902
+ vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;
903
+ vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;
904
+ #else
905
+ vec2 anisotropyV = anisotropyVector;
906
+ #endif
907
+ material.anisotropy = length( anisotropyV );
908
+ if( material.anisotropy == 0.0 ) {
909
+ anisotropyV = vec2( 1.0, 0.0 );
910
+ } else {
911
+ anisotropyV /= material.anisotropy;
912
+ material.anisotropy = saturate( material.anisotropy );
913
+ }
914
+ material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );
915
+ material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;
916
+ material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;
917
+ #endif`,lights_physical_pars_fragment:`struct PhysicalMaterial {
918
+ vec3 diffuseColor;
919
+ float roughness;
920
+ vec3 specularColor;
921
+ float specularF90;
922
+ #ifdef USE_CLEARCOAT
923
+ float clearcoat;
924
+ float clearcoatRoughness;
925
+ vec3 clearcoatF0;
926
+ float clearcoatF90;
927
+ #endif
928
+ #ifdef USE_IRIDESCENCE
929
+ float iridescence;
930
+ float iridescenceIOR;
931
+ float iridescenceThickness;
932
+ vec3 iridescenceFresnel;
933
+ vec3 iridescenceF0;
934
+ #endif
935
+ #ifdef USE_SHEEN
936
+ vec3 sheenColor;
937
+ float sheenRoughness;
938
+ #endif
939
+ #ifdef IOR
940
+ float ior;
941
+ #endif
942
+ #ifdef USE_TRANSMISSION
943
+ float transmission;
944
+ float transmissionAlpha;
945
+ float thickness;
946
+ float attenuationDistance;
947
+ vec3 attenuationColor;
948
+ #endif
949
+ #ifdef USE_ANISOTROPY
950
+ float anisotropy;
951
+ float alphaT;
952
+ vec3 anisotropyT;
953
+ vec3 anisotropyB;
954
+ #endif
955
+ };
956
+ vec3 clearcoatSpecularDirect = vec3( 0.0 );
957
+ vec3 clearcoatSpecularIndirect = vec3( 0.0 );
958
+ vec3 sheenSpecularDirect = vec3( 0.0 );
959
+ vec3 sheenSpecularIndirect = vec3(0.0 );
960
+ vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {
961
+ float x = clamp( 1.0 - dotVH, 0.0, 1.0 );
962
+ float x2 = x * x;
963
+ float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );
964
+ return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
965
+ }
966
+ float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
967
+ float a2 = pow2( alpha );
968
+ float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
969
+ float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
970
+ return 0.5 / max( gv + gl, EPSILON );
971
+ }
972
+ float D_GGX( const in float alpha, const in float dotNH ) {
973
+ float a2 = pow2( alpha );
974
+ float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
975
+ return RECIPROCAL_PI * a2 / pow2( denom );
976
+ }
977
+ #ifdef USE_ANISOTROPY
978
+ float 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 ) {
979
+ float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );
980
+ float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );
981
+ float v = 0.5 / ( gv + gl );
982
+ return saturate(v);
983
+ }
984
+ float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {
985
+ float a2 = alphaT * alphaB;
986
+ highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );
987
+ highp float v2 = dot( v, v );
988
+ float w2 = a2 / v2;
989
+ return RECIPROCAL_PI * a2 * pow2 ( w2 );
990
+ }
991
+ #endif
992
+ #ifdef USE_CLEARCOAT
993
+ vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {
994
+ vec3 f0 = material.clearcoatF0;
995
+ float f90 = material.clearcoatF90;
996
+ float roughness = material.clearcoatRoughness;
997
+ float alpha = pow2( roughness );
998
+ vec3 halfDir = normalize( lightDir + viewDir );
999
+ float dotNL = saturate( dot( normal, lightDir ) );
1000
+ float dotNV = saturate( dot( normal, viewDir ) );
1001
+ float dotNH = saturate( dot( normal, halfDir ) );
1002
+ float dotVH = saturate( dot( viewDir, halfDir ) );
1003
+ vec3 F = F_Schlick( f0, f90, dotVH );
1004
+ float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
1005
+ float D = D_GGX( alpha, dotNH );
1006
+ return F * ( V * D );
1007
+ }
1008
+ #endif
1009
+ vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
1010
+ vec3 f0 = material.specularColor;
1011
+ float f90 = material.specularF90;
1012
+ float roughness = material.roughness;
1013
+ float alpha = pow2( roughness );
1014
+ vec3 halfDir = normalize( lightDir + viewDir );
1015
+ float dotNL = saturate( dot( normal, lightDir ) );
1016
+ float dotNV = saturate( dot( normal, viewDir ) );
1017
+ float dotNH = saturate( dot( normal, halfDir ) );
1018
+ float dotVH = saturate( dot( viewDir, halfDir ) );
1019
+ vec3 F = F_Schlick( f0, f90, dotVH );
1020
+ #ifdef USE_IRIDESCENCE
1021
+ F = mix( F, material.iridescenceFresnel, material.iridescence );
1022
+ #endif
1023
+ #ifdef USE_ANISOTROPY
1024
+ float dotTL = dot( material.anisotropyT, lightDir );
1025
+ float dotTV = dot( material.anisotropyT, viewDir );
1026
+ float dotTH = dot( material.anisotropyT, halfDir );
1027
+ float dotBL = dot( material.anisotropyB, lightDir );
1028
+ float dotBV = dot( material.anisotropyB, viewDir );
1029
+ float dotBH = dot( material.anisotropyB, halfDir );
1030
+ float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );
1031
+ float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );
1032
+ #else
1033
+ float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
1034
+ float D = D_GGX( alpha, dotNH );
1035
+ #endif
1036
+ return F * ( V * D );
1037
+ }
1038
+ vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
1039
+ const float LUT_SIZE = 64.0;
1040
+ const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
1041
+ const float LUT_BIAS = 0.5 / LUT_SIZE;
1042
+ float dotNV = saturate( dot( N, V ) );
1043
+ vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
1044
+ uv = uv * LUT_SCALE + LUT_BIAS;
1045
+ return uv;
1046
+ }
1047
+ float LTC_ClippedSphereFormFactor( const in vec3 f ) {
1048
+ float l = length( f );
1049
+ return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
1050
+ }
1051
+ vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
1052
+ float x = dot( v1, v2 );
1053
+ float y = abs( x );
1054
+ float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
1055
+ float b = 3.4175940 + ( 4.1616724 + y ) * y;
1056
+ float v = a / b;
1057
+ float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
1058
+ return cross( v1, v2 ) * theta_sintheta;
1059
+ }
1060
+ vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
1061
+ vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
1062
+ vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
1063
+ vec3 lightNormal = cross( v1, v2 );
1064
+ if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
1065
+ vec3 T1, T2;
1066
+ T1 = normalize( V - N * dot( V, N ) );
1067
+ T2 = - cross( N, T1 );
1068
+ mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );
1069
+ vec3 coords[ 4 ];
1070
+ coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
1071
+ coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
1072
+ coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
1073
+ coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
1074
+ coords[ 0 ] = normalize( coords[ 0 ] );
1075
+ coords[ 1 ] = normalize( coords[ 1 ] );
1076
+ coords[ 2 ] = normalize( coords[ 2 ] );
1077
+ coords[ 3 ] = normalize( coords[ 3 ] );
1078
+ vec3 vectorFormFactor = vec3( 0.0 );
1079
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
1080
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
1081
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
1082
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
1083
+ float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
1084
+ return vec3( result );
1085
+ }
1086
+ #if defined( USE_SHEEN )
1087
+ float D_Charlie( float roughness, float dotNH ) {
1088
+ float alpha = pow2( roughness );
1089
+ float invAlpha = 1.0 / alpha;
1090
+ float cos2h = dotNH * dotNH;
1091
+ float sin2h = max( 1.0 - cos2h, 0.0078125 );
1092
+ return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
1093
+ }
1094
+ float V_Neubelt( float dotNV, float dotNL ) {
1095
+ return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
1096
+ }
1097
+ vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {
1098
+ vec3 halfDir = normalize( lightDir + viewDir );
1099
+ float dotNL = saturate( dot( normal, lightDir ) );
1100
+ float dotNV = saturate( dot( normal, viewDir ) );
1101
+ float dotNH = saturate( dot( normal, halfDir ) );
1102
+ float D = D_Charlie( sheenRoughness, dotNH );
1103
+ float V = V_Neubelt( dotNV, dotNL );
1104
+ return sheenColor * ( D * V );
1105
+ }
1106
+ #endif
1107
+ float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
1108
+ float dotNV = saturate( dot( normal, viewDir ) );
1109
+ float r2 = roughness * roughness;
1110
+ float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;
1111
+ float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;
1112
+ float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );
1113
+ return saturate( DG * RECIPROCAL_PI );
1114
+ }
1115
+ vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
1116
+ float dotNV = saturate( dot( normal, viewDir ) );
1117
+ const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
1118
+ const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
1119
+ vec4 r = roughness * c0 + c1;
1120
+ float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
1121
+ vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;
1122
+ return fab;
1123
+ }
1124
+ vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
1125
+ vec2 fab = DFGApprox( normal, viewDir, roughness );
1126
+ return specularColor * fab.x + specularF90 * fab.y;
1127
+ }
1128
+ #ifdef USE_IRIDESCENCE
1129
+ void 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 ) {
1130
+ #else
1131
+ void 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 ) {
1132
+ #endif
1133
+ vec2 fab = DFGApprox( normal, viewDir, roughness );
1134
+ #ifdef USE_IRIDESCENCE
1135
+ vec3 Fr = mix( specularColor, iridescenceF0, iridescence );
1136
+ #else
1137
+ vec3 Fr = specularColor;
1138
+ #endif
1139
+ vec3 FssEss = Fr * fab.x + specularF90 * fab.y;
1140
+ float Ess = fab.x + fab.y;
1141
+ float Ems = 1.0 - Ess;
1142
+ vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
1143
+ singleScatter += FssEss;
1144
+ multiScatter += Fms * Ems;
1145
+ }
1146
+ #if NUM_RECT_AREA_LIGHTS > 0
1147
+ void 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 ) {
1148
+ vec3 normal = geometryNormal;
1149
+ vec3 viewDir = geometryViewDir;
1150
+ vec3 position = geometryPosition;
1151
+ vec3 lightPos = rectAreaLight.position;
1152
+ vec3 halfWidth = rectAreaLight.halfWidth;
1153
+ vec3 halfHeight = rectAreaLight.halfHeight;
1154
+ vec3 lightColor = rectAreaLight.color;
1155
+ float roughness = material.roughness;
1156
+ vec3 rectCoords[ 4 ];
1157
+ rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
1158
+ rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
1159
+ rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
1160
+ vec2 uv = LTC_Uv( normal, viewDir, roughness );
1161
+ vec4 t1 = texture2D( ltc_1, uv );
1162
+ vec4 t2 = texture2D( ltc_2, uv );
1163
+ mat3 mInv = mat3(
1164
+ vec3( t1.x, 0, t1.y ),
1165
+ vec3( 0, 1, 0 ),
1166
+ vec3( t1.z, 0, t1.w )
1167
+ );
1168
+ vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );
1169
+ reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
1170
+ reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
1171
+ }
1172
+ #endif
1173
+ void 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 ) {
1174
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
1175
+ vec3 irradiance = dotNL * directLight.color;
1176
+ #ifdef USE_CLEARCOAT
1177
+ float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );
1178
+ vec3 ccIrradiance = dotNLcc * directLight.color;
1179
+ clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );
1180
+ #endif
1181
+ #ifdef USE_SHEEN
1182
+ sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );
1183
+ #endif
1184
+ reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );
1185
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
1186
+ }
1187
+ void 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 ) {
1188
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
1189
+ }
1190
+ void 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) {
1191
+ #ifdef USE_CLEARCOAT
1192
+ clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
1193
+ #endif
1194
+ #ifdef USE_SHEEN
1195
+ sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
1196
+ #endif
1197
+ vec3 singleScattering = vec3( 0.0 );
1198
+ vec3 multiScattering = vec3( 0.0 );
1199
+ vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
1200
+ #ifdef USE_IRIDESCENCE
1201
+ computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );
1202
+ #else
1203
+ computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );
1204
+ #endif
1205
+ vec3 totalScattering = singleScattering + multiScattering;
1206
+ vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
1207
+ reflectedLight.indirectSpecular += radiance * singleScattering;
1208
+ reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;
1209
+ reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;
1210
+ }
1211
+ #define RE_Direct RE_Direct_Physical
1212
+ #define RE_Direct_RectArea RE_Direct_RectArea_Physical
1213
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Physical
1214
+ #define RE_IndirectSpecular RE_IndirectSpecular_Physical
1215
+ float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
1216
+ return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
1217
+ }`,lights_fragment_begin:`
1218
+ vec3 geometryPosition = - vViewPosition;
1219
+ vec3 geometryNormal = normal;
1220
+ vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
1221
+ vec3 geometryClearcoatNormal = vec3( 0.0 );
1222
+ #ifdef USE_CLEARCOAT
1223
+ geometryClearcoatNormal = clearcoatNormal;
1224
+ #endif
1225
+ #ifdef USE_IRIDESCENCE
1226
+ float dotNVi = saturate( dot( normal, geometryViewDir ) );
1227
+ if ( material.iridescenceThickness == 0.0 ) {
1228
+ material.iridescence = 0.0;
1229
+ } else {
1230
+ material.iridescence = saturate( material.iridescence );
1231
+ }
1232
+ if ( material.iridescence > 0.0 ) {
1233
+ material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );
1234
+ material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );
1235
+ }
1236
+ #endif
1237
+ IncidentLight directLight;
1238
+ #if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
1239
+ PointLight pointLight;
1240
+ #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
1241
+ PointLightShadow pointLightShadow;
1242
+ #endif
1243
+ #pragma unroll_loop_start
1244
+ for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
1245
+ pointLight = pointLights[ i ];
1246
+ getPointLightInfo( pointLight, geometryPosition, directLight );
1247
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
1248
+ pointLightShadow = pointLightShadows[ i ];
1249
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
1250
+ #endif
1251
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1252
+ }
1253
+ #pragma unroll_loop_end
1254
+ #endif
1255
+ #if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
1256
+ SpotLight spotLight;
1257
+ vec4 spotColor;
1258
+ vec3 spotLightCoord;
1259
+ bool inSpotLightMap;
1260
+ #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
1261
+ SpotLightShadow spotLightShadow;
1262
+ #endif
1263
+ #pragma unroll_loop_start
1264
+ for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
1265
+ spotLight = spotLights[ i ];
1266
+ getSpotLightInfo( spotLight, geometryPosition, directLight );
1267
+ #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
1268
+ #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX
1269
+ #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
1270
+ #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS
1271
+ #else
1272
+ #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
1273
+ #endif
1274
+ #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )
1275
+ spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;
1276
+ inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );
1277
+ spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );
1278
+ directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;
1279
+ #endif
1280
+ #undef SPOT_LIGHT_MAP_INDEX
1281
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
1282
+ spotLightShadow = spotLightShadows[ i ];
1283
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
1284
+ #endif
1285
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1286
+ }
1287
+ #pragma unroll_loop_end
1288
+ #endif
1289
+ #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
1290
+ DirectionalLight directionalLight;
1291
+ #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
1292
+ DirectionalLightShadow directionalLightShadow;
1293
+ #endif
1294
+ #pragma unroll_loop_start
1295
+ for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
1296
+ directionalLight = directionalLights[ i ];
1297
+ getDirectionalLightInfo( directionalLight, directLight );
1298
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
1299
+ directionalLightShadow = directionalLightShadows[ i ];
1300
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
1301
+ #endif
1302
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1303
+ }
1304
+ #pragma unroll_loop_end
1305
+ #endif
1306
+ #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
1307
+ RectAreaLight rectAreaLight;
1308
+ #pragma unroll_loop_start
1309
+ for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
1310
+ rectAreaLight = rectAreaLights[ i ];
1311
+ RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1312
+ }
1313
+ #pragma unroll_loop_end
1314
+ #endif
1315
+ #if defined( RE_IndirectDiffuse )
1316
+ vec3 iblIrradiance = vec3( 0.0 );
1317
+ vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
1318
+ #if defined( USE_LIGHT_PROBES )
1319
+ irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
1320
+ #endif
1321
+ #if ( NUM_HEMI_LIGHTS > 0 )
1322
+ #pragma unroll_loop_start
1323
+ for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
1324
+ irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
1325
+ }
1326
+ #pragma unroll_loop_end
1327
+ #endif
1328
+ #endif
1329
+ #if defined( RE_IndirectSpecular )
1330
+ vec3 radiance = vec3( 0.0 );
1331
+ vec3 clearcoatRadiance = vec3( 0.0 );
1332
+ #endif`,lights_fragment_maps:`#if defined( RE_IndirectDiffuse )
1333
+ #ifdef USE_LIGHTMAP
1334
+ vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
1335
+ vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
1336
+ irradiance += lightMapIrradiance;
1337
+ #endif
1338
+ #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
1339
+ iblIrradiance += getIBLIrradiance( geometryNormal );
1340
+ #endif
1341
+ #endif
1342
+ #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
1343
+ #ifdef USE_ANISOTROPY
1344
+ radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
1345
+ #else
1346
+ radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );
1347
+ #endif
1348
+ #ifdef USE_CLEARCOAT
1349
+ clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
1350
+ #endif
1351
+ #endif`,lights_fragment_end:`#if defined( RE_IndirectDiffuse )
1352
+ RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1353
+ #endif
1354
+ #if defined( RE_IndirectSpecular )
1355
+ RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1356
+ #endif`,logdepthbuf_fragment:`#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )
1357
+ gl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
1358
+ #endif`,logdepthbuf_pars_fragment:`#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )
1359
+ uniform float logDepthBufFC;
1360
+ varying float vFragDepth;
1361
+ varying float vIsPerspective;
1362
+ #endif`,logdepthbuf_pars_vertex:`#ifdef USE_LOGDEPTHBUF
1363
+ #ifdef USE_LOGDEPTHBUF_EXT
1364
+ varying float vFragDepth;
1365
+ varying float vIsPerspective;
1366
+ #else
1367
+ uniform float logDepthBufFC;
1368
+ #endif
1369
+ #endif`,logdepthbuf_vertex:`#ifdef USE_LOGDEPTHBUF
1370
+ #ifdef USE_LOGDEPTHBUF_EXT
1371
+ vFragDepth = 1.0 + gl_Position.w;
1372
+ vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
1373
+ #else
1374
+ if ( isPerspectiveMatrix( projectionMatrix ) ) {
1375
+ gl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;
1376
+ gl_Position.z *= gl_Position.w;
1377
+ }
1378
+ #endif
1379
+ #endif`,map_fragment:`#ifdef USE_MAP
1380
+ vec4 sampledDiffuseColor = texture2D( map, vMapUv );
1381
+ #ifdef DECODE_VIDEO_TEXTURE
1382
+ sampledDiffuseColor = 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 );
1383
+
1384
+ #endif
1385
+ diffuseColor *= sampledDiffuseColor;
1386
+ #endif`,map_pars_fragment:`#ifdef USE_MAP
1387
+ uniform sampler2D map;
1388
+ #endif`,map_particle_fragment:`#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
1389
+ #if defined( USE_POINTS_UV )
1390
+ vec2 uv = vUv;
1391
+ #else
1392
+ vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
1393
+ #endif
1394
+ #endif
1395
+ #ifdef USE_MAP
1396
+ diffuseColor *= texture2D( map, uv );
1397
+ #endif
1398
+ #ifdef USE_ALPHAMAP
1399
+ diffuseColor.a *= texture2D( alphaMap, uv ).g;
1400
+ #endif`,map_particle_pars_fragment:`#if defined( USE_POINTS_UV )
1401
+ varying vec2 vUv;
1402
+ #else
1403
+ #if defined( USE_MAP ) || defined( USE_ALPHAMAP )
1404
+ uniform mat3 uvTransform;
1405
+ #endif
1406
+ #endif
1407
+ #ifdef USE_MAP
1408
+ uniform sampler2D map;
1409
+ #endif
1410
+ #ifdef USE_ALPHAMAP
1411
+ uniform sampler2D alphaMap;
1412
+ #endif`,metalnessmap_fragment:`float metalnessFactor = metalness;
1413
+ #ifdef USE_METALNESSMAP
1414
+ vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
1415
+ metalnessFactor *= texelMetalness.b;
1416
+ #endif`,metalnessmap_pars_fragment:`#ifdef USE_METALNESSMAP
1417
+ uniform sampler2D metalnessMap;
1418
+ #endif`,morphcolor_vertex:`#if defined( USE_MORPHCOLORS ) && defined( MORPHTARGETS_TEXTURE )
1419
+ vColor *= morphTargetBaseInfluence;
1420
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1421
+ #if defined( USE_COLOR_ALPHA )
1422
+ if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];
1423
+ #elif defined( USE_COLOR )
1424
+ if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
1425
+ #endif
1426
+ }
1427
+ #endif`,morphnormal_vertex:`#ifdef USE_MORPHNORMALS
1428
+ objectNormal *= morphTargetBaseInfluence;
1429
+ #ifdef MORPHTARGETS_TEXTURE
1430
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1431
+ if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];
1432
+ }
1433
+ #else
1434
+ objectNormal += morphNormal0 * morphTargetInfluences[ 0 ];
1435
+ objectNormal += morphNormal1 * morphTargetInfluences[ 1 ];
1436
+ objectNormal += morphNormal2 * morphTargetInfluences[ 2 ];
1437
+ objectNormal += morphNormal3 * morphTargetInfluences[ 3 ];
1438
+ #endif
1439
+ #endif`,morphtarget_pars_vertex:`#ifdef USE_MORPHTARGETS
1440
+ uniform float morphTargetBaseInfluence;
1441
+ #ifdef MORPHTARGETS_TEXTURE
1442
+ uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
1443
+ uniform sampler2DArray morphTargetsTexture;
1444
+ uniform ivec2 morphTargetsTextureSize;
1445
+ vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {
1446
+ int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;
1447
+ int y = texelIndex / morphTargetsTextureSize.x;
1448
+ int x = texelIndex - y * morphTargetsTextureSize.x;
1449
+ ivec3 morphUV = ivec3( x, y, morphTargetIndex );
1450
+ return texelFetch( morphTargetsTexture, morphUV, 0 );
1451
+ }
1452
+ #else
1453
+ #ifndef USE_MORPHNORMALS
1454
+ uniform float morphTargetInfluences[ 8 ];
1455
+ #else
1456
+ uniform float morphTargetInfluences[ 4 ];
1457
+ #endif
1458
+ #endif
1459
+ #endif`,morphtarget_vertex:`#ifdef USE_MORPHTARGETS
1460
+ transformed *= morphTargetBaseInfluence;
1461
+ #ifdef MORPHTARGETS_TEXTURE
1462
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1463
+ if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];
1464
+ }
1465
+ #else
1466
+ transformed += morphTarget0 * morphTargetInfluences[ 0 ];
1467
+ transformed += morphTarget1 * morphTargetInfluences[ 1 ];
1468
+ transformed += morphTarget2 * morphTargetInfluences[ 2 ];
1469
+ transformed += morphTarget3 * morphTargetInfluences[ 3 ];
1470
+ #ifndef USE_MORPHNORMALS
1471
+ transformed += morphTarget4 * morphTargetInfluences[ 4 ];
1472
+ transformed += morphTarget5 * morphTargetInfluences[ 5 ];
1473
+ transformed += morphTarget6 * morphTargetInfluences[ 6 ];
1474
+ transformed += morphTarget7 * morphTargetInfluences[ 7 ];
1475
+ #endif
1476
+ #endif
1477
+ #endif`,normal_fragment_begin:`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
1478
+ #ifdef FLAT_SHADED
1479
+ vec3 fdx = dFdx( vViewPosition );
1480
+ vec3 fdy = dFdy( vViewPosition );
1481
+ vec3 normal = normalize( cross( fdx, fdy ) );
1482
+ #else
1483
+ vec3 normal = normalize( vNormal );
1484
+ #ifdef DOUBLE_SIDED
1485
+ normal *= faceDirection;
1486
+ #endif
1487
+ #endif
1488
+ #if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )
1489
+ #ifdef USE_TANGENT
1490
+ mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
1491
+ #else
1492
+ mat3 tbn = getTangentFrame( - vViewPosition, normal,
1493
+ #if defined( USE_NORMALMAP )
1494
+ vNormalMapUv
1495
+ #elif defined( USE_CLEARCOAT_NORMALMAP )
1496
+ vClearcoatNormalMapUv
1497
+ #else
1498
+ vUv
1499
+ #endif
1500
+ );
1501
+ #endif
1502
+ #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
1503
+ tbn[0] *= faceDirection;
1504
+ tbn[1] *= faceDirection;
1505
+ #endif
1506
+ #endif
1507
+ #ifdef USE_CLEARCOAT_NORMALMAP
1508
+ #ifdef USE_TANGENT
1509
+ mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
1510
+ #else
1511
+ mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );
1512
+ #endif
1513
+ #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
1514
+ tbn2[0] *= faceDirection;
1515
+ tbn2[1] *= faceDirection;
1516
+ #endif
1517
+ #endif
1518
+ vec3 nonPerturbedNormal = normal;`,normal_fragment_maps:`#ifdef USE_NORMALMAP_OBJECTSPACE
1519
+ normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
1520
+ #ifdef FLIP_SIDED
1521
+ normal = - normal;
1522
+ #endif
1523
+ #ifdef DOUBLE_SIDED
1524
+ normal = normal * faceDirection;
1525
+ #endif
1526
+ normal = normalize( normalMatrix * normal );
1527
+ #elif defined( USE_NORMALMAP_TANGENTSPACE )
1528
+ vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
1529
+ mapN.xy *= normalScale;
1530
+ normal = normalize( tbn * mapN );
1531
+ #elif defined( USE_BUMPMAP )
1532
+ normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
1533
+ #endif`,normal_pars_fragment:`#ifndef FLAT_SHADED
1534
+ varying vec3 vNormal;
1535
+ #ifdef USE_TANGENT
1536
+ varying vec3 vTangent;
1537
+ varying vec3 vBitangent;
1538
+ #endif
1539
+ #endif`,normal_pars_vertex:`#ifndef FLAT_SHADED
1540
+ varying vec3 vNormal;
1541
+ #ifdef USE_TANGENT
1542
+ varying vec3 vTangent;
1543
+ varying vec3 vBitangent;
1544
+ #endif
1545
+ #endif`,normal_vertex:`#ifndef FLAT_SHADED
1546
+ vNormal = normalize( transformedNormal );
1547
+ #ifdef USE_TANGENT
1548
+ vTangent = normalize( transformedTangent );
1549
+ vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
1550
+ #endif
1551
+ #endif`,normalmap_pars_fragment:`#ifdef USE_NORMALMAP
1552
+ uniform sampler2D normalMap;
1553
+ uniform vec2 normalScale;
1554
+ #endif
1555
+ #ifdef USE_NORMALMAP_OBJECTSPACE
1556
+ uniform mat3 normalMatrix;
1557
+ #endif
1558
+ #if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )
1559
+ mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {
1560
+ vec3 q0 = dFdx( eye_pos.xyz );
1561
+ vec3 q1 = dFdy( eye_pos.xyz );
1562
+ vec2 st0 = dFdx( uv.st );
1563
+ vec2 st1 = dFdy( uv.st );
1564
+ vec3 N = surf_norm;
1565
+ vec3 q1perp = cross( q1, N );
1566
+ vec3 q0perp = cross( N, q0 );
1567
+ vec3 T = q1perp * st0.x + q0perp * st1.x;
1568
+ vec3 B = q1perp * st0.y + q0perp * st1.y;
1569
+ float det = max( dot( T, T ), dot( B, B ) );
1570
+ float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );
1571
+ return mat3( T * scale, B * scale, N );
1572
+ }
1573
+ #endif`,clearcoat_normal_fragment_begin:`#ifdef USE_CLEARCOAT
1574
+ vec3 clearcoatNormal = nonPerturbedNormal;
1575
+ #endif`,clearcoat_normal_fragment_maps:`#ifdef USE_CLEARCOAT_NORMALMAP
1576
+ vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
1577
+ clearcoatMapN.xy *= clearcoatNormalScale;
1578
+ clearcoatNormal = normalize( tbn2 * clearcoatMapN );
1579
+ #endif`,clearcoat_pars_fragment:`#ifdef USE_CLEARCOATMAP
1580
+ uniform sampler2D clearcoatMap;
1581
+ #endif
1582
+ #ifdef USE_CLEARCOAT_NORMALMAP
1583
+ uniform sampler2D clearcoatNormalMap;
1584
+ uniform vec2 clearcoatNormalScale;
1585
+ #endif
1586
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
1587
+ uniform sampler2D clearcoatRoughnessMap;
1588
+ #endif`,iridescence_pars_fragment:`#ifdef USE_IRIDESCENCEMAP
1589
+ uniform sampler2D iridescenceMap;
1590
+ #endif
1591
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
1592
+ uniform sampler2D iridescenceThicknessMap;
1593
+ #endif`,opaque_fragment:`#ifdef OPAQUE
1594
+ diffuseColor.a = 1.0;
1595
+ #endif
1596
+ #ifdef USE_TRANSMISSION
1597
+ diffuseColor.a *= material.transmissionAlpha;
1598
+ #endif
1599
+ gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,packing:`vec3 packNormalToRGB( const in vec3 normal ) {
1600
+ return normalize( normal ) * 0.5 + 0.5;
1601
+ }
1602
+ vec3 unpackRGBToNormal( const in vec3 rgb ) {
1603
+ return 2.0 * rgb.xyz - 1.0;
1604
+ }
1605
+ const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;
1606
+ const vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );
1607
+ const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );
1608
+ const float ShiftRight8 = 1. / 256.;
1609
+ vec4 packDepthToRGBA( const in float v ) {
1610
+ vec4 r = vec4( fract( v * PackFactors ), v );
1611
+ r.yzw -= r.xyz * ShiftRight8; return r * PackUpscale;
1612
+ }
1613
+ float unpackRGBAToDepth( const in vec4 v ) {
1614
+ return dot( v, UnpackFactors );
1615
+ }
1616
+ vec2 packDepthToRG( in highp float v ) {
1617
+ return packDepthToRGBA( v ).yx;
1618
+ }
1619
+ float unpackRGToDepth( const in highp vec2 v ) {
1620
+ return unpackRGBAToDepth( vec4( v.xy, 0.0, 0.0 ) );
1621
+ }
1622
+ vec4 pack2HalfToRGBA( vec2 v ) {
1623
+ vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );
1624
+ return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );
1625
+ }
1626
+ vec2 unpackRGBATo2Half( vec4 v ) {
1627
+ return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
1628
+ }
1629
+ float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
1630
+ return ( viewZ + near ) / ( near - far );
1631
+ }
1632
+ float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {
1633
+ return depth * ( near - far ) - near;
1634
+ }
1635
+ float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
1636
+ return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
1637
+ }
1638
+ float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {
1639
+ return ( near * far ) / ( ( far - near ) * depth - far );
1640
+ }`,premultiplied_alpha_fragment:`#ifdef PREMULTIPLIED_ALPHA
1641
+ gl_FragColor.rgb *= gl_FragColor.a;
1642
+ #endif`,project_vertex:`vec4 mvPosition = vec4( transformed, 1.0 );
1643
+ #ifdef USE_BATCHING
1644
+ mvPosition = batchingMatrix * mvPosition;
1645
+ #endif
1646
+ #ifdef USE_INSTANCING
1647
+ mvPosition = instanceMatrix * mvPosition;
1648
+ #endif
1649
+ mvPosition = modelViewMatrix * mvPosition;
1650
+ gl_Position = projectionMatrix * mvPosition;`,dithering_fragment:`#ifdef DITHERING
1651
+ gl_FragColor.rgb = dithering( gl_FragColor.rgb );
1652
+ #endif`,dithering_pars_fragment:`#ifdef DITHERING
1653
+ vec3 dithering( vec3 color ) {
1654
+ float grid_position = rand( gl_FragCoord.xy );
1655
+ vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
1656
+ dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
1657
+ return color + dither_shift_RGB;
1658
+ }
1659
+ #endif`,roughnessmap_fragment:`float roughnessFactor = roughness;
1660
+ #ifdef USE_ROUGHNESSMAP
1661
+ vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
1662
+ roughnessFactor *= texelRoughness.g;
1663
+ #endif`,roughnessmap_pars_fragment:`#ifdef USE_ROUGHNESSMAP
1664
+ uniform sampler2D roughnessMap;
1665
+ #endif`,shadowmap_pars_fragment:`#if NUM_SPOT_LIGHT_COORDS > 0
1666
+ varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
1667
+ #endif
1668
+ #if NUM_SPOT_LIGHT_MAPS > 0
1669
+ uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];
1670
+ #endif
1671
+ #ifdef USE_SHADOWMAP
1672
+ #if NUM_DIR_LIGHT_SHADOWS > 0
1673
+ uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
1674
+ varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
1675
+ struct DirectionalLightShadow {
1676
+ float shadowBias;
1677
+ float shadowNormalBias;
1678
+ float shadowRadius;
1679
+ vec2 shadowMapSize;
1680
+ };
1681
+ uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
1682
+ #endif
1683
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
1684
+ uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
1685
+ struct SpotLightShadow {
1686
+ float shadowBias;
1687
+ float shadowNormalBias;
1688
+ float shadowRadius;
1689
+ vec2 shadowMapSize;
1690
+ };
1691
+ uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
1692
+ #endif
1693
+ #if NUM_POINT_LIGHT_SHADOWS > 0
1694
+ uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
1695
+ varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
1696
+ struct PointLightShadow {
1697
+ float shadowBias;
1698
+ float shadowNormalBias;
1699
+ float shadowRadius;
1700
+ vec2 shadowMapSize;
1701
+ float shadowCameraNear;
1702
+ float shadowCameraFar;
1703
+ };
1704
+ uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
1705
+ #endif
1706
+ float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
1707
+ return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
1708
+ }
1709
+ vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {
1710
+ return unpackRGBATo2Half( texture2D( shadow, uv ) );
1711
+ }
1712
+ float VSMShadow (sampler2D shadow, vec2 uv, float compare ){
1713
+ float occlusion = 1.0;
1714
+ vec2 distribution = texture2DDistribution( shadow, uv );
1715
+ float hard_shadow = step( compare , distribution.x );
1716
+ if (hard_shadow != 1.0 ) {
1717
+ float distance = compare - distribution.x ;
1718
+ float variance = max( 0.00000, distribution.y * distribution.y );
1719
+ float softness_probability = variance / (variance + distance * distance ); softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );
1720
+ }
1721
+ return occlusion;
1722
+ }
1723
+ float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
1724
+ float shadow = 1.0;
1725
+ shadowCoord.xyz /= shadowCoord.w;
1726
+ shadowCoord.z += shadowBias;
1727
+ bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
1728
+ bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
1729
+ if ( frustumTest ) {
1730
+ #if defined( SHADOWMAP_TYPE_PCF )
1731
+ vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
1732
+ float dx0 = - texelSize.x * shadowRadius;
1733
+ float dy0 = - texelSize.y * shadowRadius;
1734
+ float dx1 = + texelSize.x * shadowRadius;
1735
+ float dy1 = + texelSize.y * shadowRadius;
1736
+ float dx2 = dx0 / 2.0;
1737
+ float dy2 = dy0 / 2.0;
1738
+ float dx3 = dx1 / 2.0;
1739
+ float dy3 = dy1 / 2.0;
1740
+ shadow = (
1741
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +
1742
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +
1743
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +
1744
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +
1745
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +
1746
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +
1747
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +
1748
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +
1749
+ texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +
1750
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +
1751
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +
1752
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +
1753
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +
1754
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +
1755
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +
1756
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +
1757
+ texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )
1758
+ ) * ( 1.0 / 17.0 );
1759
+ #elif defined( SHADOWMAP_TYPE_PCF_SOFT )
1760
+ vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
1761
+ float dx = texelSize.x;
1762
+ float dy = texelSize.y;
1763
+ vec2 uv = shadowCoord.xy;
1764
+ vec2 f = fract( uv * shadowMapSize + 0.5 );
1765
+ uv -= f * texelSize;
1766
+ shadow = (
1767
+ texture2DCompare( shadowMap, uv, shadowCoord.z ) +
1768
+ texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
1769
+ texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
1770
+ texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
1771
+ mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
1772
+ texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
1773
+ f.x ) +
1774
+ mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
1775
+ texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
1776
+ f.x ) +
1777
+ mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
1778
+ texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
1779
+ f.y ) +
1780
+ mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
1781
+ texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
1782
+ f.y ) +
1783
+ mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
1784
+ texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
1785
+ f.x ),
1786
+ mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
1787
+ texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
1788
+ f.x ),
1789
+ f.y )
1790
+ ) * ( 1.0 / 9.0 );
1791
+ #elif defined( SHADOWMAP_TYPE_VSM )
1792
+ shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );
1793
+ #else
1794
+ shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );
1795
+ #endif
1796
+ }
1797
+ return shadow;
1798
+ }
1799
+ vec2 cubeToUV( vec3 v, float texelSizeY ) {
1800
+ vec3 absV = abs( v );
1801
+ float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );
1802
+ absV *= scaleToCube;
1803
+ v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );
1804
+ vec2 planar = v.xy;
1805
+ float almostATexel = 1.5 * texelSizeY;
1806
+ float almostOne = 1.0 - almostATexel;
1807
+ if ( absV.z >= almostOne ) {
1808
+ if ( v.z > 0.0 )
1809
+ planar.x = 4.0 - v.x;
1810
+ } else if ( absV.x >= almostOne ) {
1811
+ float signX = sign( v.x );
1812
+ planar.x = v.z * signX + 2.0 * signX;
1813
+ } else if ( absV.y >= almostOne ) {
1814
+ float signY = sign( v.y );
1815
+ planar.x = v.x + 2.0 * signY + 2.0;
1816
+ planar.y = v.z * signY - 2.0;
1817
+ }
1818
+ return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );
1819
+ }
1820
+ float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
1821
+ vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
1822
+ vec3 lightToPosition = shadowCoord.xyz;
1823
+ float dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias;
1824
+ vec3 bd3D = normalize( lightToPosition );
1825
+ #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
1826
+ vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
1827
+ return (
1828
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
1829
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
1830
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
1831
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
1832
+ texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
1833
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
1834
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
1835
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
1836
+ texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
1837
+ ) * ( 1.0 / 9.0 );
1838
+ #else
1839
+ return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
1840
+ #endif
1841
+ }
1842
+ #endif`,shadowmap_pars_vertex:`#if NUM_SPOT_LIGHT_COORDS > 0
1843
+ uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];
1844
+ varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
1845
+ #endif
1846
+ #ifdef USE_SHADOWMAP
1847
+ #if NUM_DIR_LIGHT_SHADOWS > 0
1848
+ uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
1849
+ varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
1850
+ struct DirectionalLightShadow {
1851
+ float shadowBias;
1852
+ float shadowNormalBias;
1853
+ float shadowRadius;
1854
+ vec2 shadowMapSize;
1855
+ };
1856
+ uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
1857
+ #endif
1858
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
1859
+ struct SpotLightShadow {
1860
+ float shadowBias;
1861
+ float shadowNormalBias;
1862
+ float shadowRadius;
1863
+ vec2 shadowMapSize;
1864
+ };
1865
+ uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
1866
+ #endif
1867
+ #if NUM_POINT_LIGHT_SHADOWS > 0
1868
+ uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];
1869
+ varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
1870
+ struct PointLightShadow {
1871
+ float shadowBias;
1872
+ float shadowNormalBias;
1873
+ float shadowRadius;
1874
+ vec2 shadowMapSize;
1875
+ float shadowCameraNear;
1876
+ float shadowCameraFar;
1877
+ };
1878
+ uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
1879
+ #endif
1880
+ #endif`,shadowmap_vertex:`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
1881
+ vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
1882
+ vec4 shadowWorldPosition;
1883
+ #endif
1884
+ #if defined( USE_SHADOWMAP )
1885
+ #if NUM_DIR_LIGHT_SHADOWS > 0
1886
+ #pragma unroll_loop_start
1887
+ for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
1888
+ shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
1889
+ vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;
1890
+ }
1891
+ #pragma unroll_loop_end
1892
+ #endif
1893
+ #if NUM_POINT_LIGHT_SHADOWS > 0
1894
+ #pragma unroll_loop_start
1895
+ for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
1896
+ shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );
1897
+ vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;
1898
+ }
1899
+ #pragma unroll_loop_end
1900
+ #endif
1901
+ #endif
1902
+ #if NUM_SPOT_LIGHT_COORDS > 0
1903
+ #pragma unroll_loop_start
1904
+ for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {
1905
+ shadowWorldPosition = worldPosition;
1906
+ #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
1907
+ shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;
1908
+ #endif
1909
+ vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;
1910
+ }
1911
+ #pragma unroll_loop_end
1912
+ #endif`,shadowmask_pars_fragment:`float getShadowMask() {
1913
+ float shadow = 1.0;
1914
+ #ifdef USE_SHADOWMAP
1915
+ #if NUM_DIR_LIGHT_SHADOWS > 0
1916
+ DirectionalLightShadow directionalLight;
1917
+ #pragma unroll_loop_start
1918
+ for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
1919
+ directionalLight = directionalLightShadows[ i ];
1920
+ shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
1921
+ }
1922
+ #pragma unroll_loop_end
1923
+ #endif
1924
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
1925
+ SpotLightShadow spotLight;
1926
+ #pragma unroll_loop_start
1927
+ for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
1928
+ spotLight = spotLightShadows[ i ];
1929
+ shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
1930
+ }
1931
+ #pragma unroll_loop_end
1932
+ #endif
1933
+ #if NUM_POINT_LIGHT_SHADOWS > 0
1934
+ PointLightShadow pointLight;
1935
+ #pragma unroll_loop_start
1936
+ for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
1937
+ pointLight = pointLightShadows[ i ];
1938
+ shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
1939
+ }
1940
+ #pragma unroll_loop_end
1941
+ #endif
1942
+ #endif
1943
+ return shadow;
1944
+ }`,skinbase_vertex:`#ifdef USE_SKINNING
1945
+ mat4 boneMatX = getBoneMatrix( skinIndex.x );
1946
+ mat4 boneMatY = getBoneMatrix( skinIndex.y );
1947
+ mat4 boneMatZ = getBoneMatrix( skinIndex.z );
1948
+ mat4 boneMatW = getBoneMatrix( skinIndex.w );
1949
+ #endif`,skinning_pars_vertex:`#ifdef USE_SKINNING
1950
+ uniform mat4 bindMatrix;
1951
+ uniform mat4 bindMatrixInverse;
1952
+ uniform highp sampler2D boneTexture;
1953
+ mat4 getBoneMatrix( const in float i ) {
1954
+ int size = textureSize( boneTexture, 0 ).x;
1955
+ int j = int( i ) * 4;
1956
+ int x = j % size;
1957
+ int y = j / size;
1958
+ vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );
1959
+ vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );
1960
+ vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );
1961
+ vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );
1962
+ return mat4( v1, v2, v3, v4 );
1963
+ }
1964
+ #endif`,skinning_vertex:`#ifdef USE_SKINNING
1965
+ vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
1966
+ vec4 skinned = vec4( 0.0 );
1967
+ skinned += boneMatX * skinVertex * skinWeight.x;
1968
+ skinned += boneMatY * skinVertex * skinWeight.y;
1969
+ skinned += boneMatZ * skinVertex * skinWeight.z;
1970
+ skinned += boneMatW * skinVertex * skinWeight.w;
1971
+ transformed = ( bindMatrixInverse * skinned ).xyz;
1972
+ #endif`,skinnormal_vertex:`#ifdef USE_SKINNING
1973
+ mat4 skinMatrix = mat4( 0.0 );
1974
+ skinMatrix += skinWeight.x * boneMatX;
1975
+ skinMatrix += skinWeight.y * boneMatY;
1976
+ skinMatrix += skinWeight.z * boneMatZ;
1977
+ skinMatrix += skinWeight.w * boneMatW;
1978
+ skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
1979
+ objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
1980
+ #ifdef USE_TANGENT
1981
+ objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
1982
+ #endif
1983
+ #endif`,specularmap_fragment:`float specularStrength;
1984
+ #ifdef USE_SPECULARMAP
1985
+ vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
1986
+ specularStrength = texelSpecular.r;
1987
+ #else
1988
+ specularStrength = 1.0;
1989
+ #endif`,specularmap_pars_fragment:`#ifdef USE_SPECULARMAP
1990
+ uniform sampler2D specularMap;
1991
+ #endif`,tonemapping_fragment:`#if defined( TONE_MAPPING )
1992
+ gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
1993
+ #endif`,tonemapping_pars_fragment:`#ifndef saturate
1994
+ #define saturate( a ) clamp( a, 0.0, 1.0 )
1995
+ #endif
1996
+ uniform float toneMappingExposure;
1997
+ vec3 LinearToneMapping( vec3 color ) {
1998
+ return saturate( toneMappingExposure * color );
1999
+ }
2000
+ vec3 ReinhardToneMapping( vec3 color ) {
2001
+ color *= toneMappingExposure;
2002
+ return saturate( color / ( vec3( 1.0 ) + color ) );
2003
+ }
2004
+ vec3 OptimizedCineonToneMapping( vec3 color ) {
2005
+ color *= toneMappingExposure;
2006
+ color = max( vec3( 0.0 ), color - 0.004 );
2007
+ return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
2008
+ }
2009
+ vec3 RRTAndODTFit( vec3 v ) {
2010
+ vec3 a = v * ( v + 0.0245786 ) - 0.000090537;
2011
+ vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;
2012
+ return a / b;
2013
+ }
2014
+ vec3 ACESFilmicToneMapping( vec3 color ) {
2015
+ const mat3 ACESInputMat = mat3(
2016
+ vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ),
2017
+ vec3( 0.04823, 0.01566, 0.83777 )
2018
+ );
2019
+ const mat3 ACESOutputMat = mat3(
2020
+ vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ),
2021
+ vec3( -0.07367, -0.00605, 1.07602 )
2022
+ );
2023
+ color *= toneMappingExposure / 0.6;
2024
+ color = ACESInputMat * color;
2025
+ color = RRTAndODTFit( color );
2026
+ color = ACESOutputMat * color;
2027
+ return saturate( color );
2028
+ }
2029
+ vec3 CustomToneMapping( vec3 color ) { return color; }`,transmission_fragment:`#ifdef USE_TRANSMISSION
2030
+ material.transmission = transmission;
2031
+ material.transmissionAlpha = 1.0;
2032
+ material.thickness = thickness;
2033
+ material.attenuationDistance = attenuationDistance;
2034
+ material.attenuationColor = attenuationColor;
2035
+ #ifdef USE_TRANSMISSIONMAP
2036
+ material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;
2037
+ #endif
2038
+ #ifdef USE_THICKNESSMAP
2039
+ material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;
2040
+ #endif
2041
+ vec3 pos = vWorldPosition;
2042
+ vec3 v = normalize( cameraPosition - pos );
2043
+ vec3 n = inverseTransformDirection( normal, viewMatrix );
2044
+ vec4 transmitted = getIBLVolumeRefraction(
2045
+ n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,
2046
+ pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness,
2047
+ material.attenuationColor, material.attenuationDistance );
2048
+ material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
2049
+ totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );
2050
+ #endif`,transmission_pars_fragment:`#ifdef USE_TRANSMISSION
2051
+ uniform float transmission;
2052
+ uniform float thickness;
2053
+ uniform float attenuationDistance;
2054
+ uniform vec3 attenuationColor;
2055
+ #ifdef USE_TRANSMISSIONMAP
2056
+ uniform sampler2D transmissionMap;
2057
+ #endif
2058
+ #ifdef USE_THICKNESSMAP
2059
+ uniform sampler2D thicknessMap;
2060
+ #endif
2061
+ uniform vec2 transmissionSamplerSize;
2062
+ uniform sampler2D transmissionSamplerMap;
2063
+ uniform mat4 modelMatrix;
2064
+ uniform mat4 projectionMatrix;
2065
+ varying vec3 vWorldPosition;
2066
+ float w0( float a ) {
2067
+ return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );
2068
+ }
2069
+ float w1( float a ) {
2070
+ return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );
2071
+ }
2072
+ float w2( float a ){
2073
+ return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );
2074
+ }
2075
+ float w3( float a ) {
2076
+ return ( 1.0 / 6.0 ) * ( a * a * a );
2077
+ }
2078
+ float g0( float a ) {
2079
+ return w0( a ) + w1( a );
2080
+ }
2081
+ float g1( float a ) {
2082
+ return w2( a ) + w3( a );
2083
+ }
2084
+ float h0( float a ) {
2085
+ return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );
2086
+ }
2087
+ float h1( float a ) {
2088
+ return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );
2089
+ }
2090
+ vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {
2091
+ uv = uv * texelSize.zw + 0.5;
2092
+ vec2 iuv = floor( uv );
2093
+ vec2 fuv = fract( uv );
2094
+ float g0x = g0( fuv.x );
2095
+ float g1x = g1( fuv.x );
2096
+ float h0x = h0( fuv.x );
2097
+ float h1x = h1( fuv.x );
2098
+ float h0y = h0( fuv.y );
2099
+ float h1y = h1( fuv.y );
2100
+ vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
2101
+ vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
2102
+ vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
2103
+ vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
2104
+ return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +
2105
+ g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );
2106
+ }
2107
+ vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {
2108
+ vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );
2109
+ vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );
2110
+ vec2 fLodSizeInv = 1.0 / fLodSize;
2111
+ vec2 cLodSizeInv = 1.0 / cLodSize;
2112
+ vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );
2113
+ vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );
2114
+ return mix( fSample, cSample, fract( lod ) );
2115
+ }
2116
+ vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
2117
+ vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
2118
+ vec3 modelScale;
2119
+ modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
2120
+ modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
2121
+ modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
2122
+ return normalize( refractionVector ) * thickness * modelScale;
2123
+ }
2124
+ float applyIorToRoughness( const in float roughness, const in float ior ) {
2125
+ return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
2126
+ }
2127
+ vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
2128
+ float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
2129
+ return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );
2130
+ }
2131
+ vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
2132
+ if ( isinf( attenuationDistance ) ) {
2133
+ return vec3( 1.0 );
2134
+ } else {
2135
+ vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
2136
+ vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance;
2137
+ }
2138
+ }
2139
+ vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
2140
+ const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
2141
+ const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,
2142
+ const in vec3 attenuationColor, const in float attenuationDistance ) {
2143
+ vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
2144
+ vec3 refractedRayExit = position + transmissionRay;
2145
+ vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
2146
+ vec2 refractionCoords = ndcPos.xy / ndcPos.w;
2147
+ refractionCoords += 1.0;
2148
+ refractionCoords /= 2.0;
2149
+ vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
2150
+ vec3 transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
2151
+ vec3 attenuatedColor = transmittance * transmittedLight.rgb;
2152
+ vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
2153
+ float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;
2154
+ return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );
2155
+ }
2156
+ #endif`,uv_pars_fragment:`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2157
+ varying vec2 vUv;
2158
+ #endif
2159
+ #ifdef USE_MAP
2160
+ varying vec2 vMapUv;
2161
+ #endif
2162
+ #ifdef USE_ALPHAMAP
2163
+ varying vec2 vAlphaMapUv;
2164
+ #endif
2165
+ #ifdef USE_LIGHTMAP
2166
+ varying vec2 vLightMapUv;
2167
+ #endif
2168
+ #ifdef USE_AOMAP
2169
+ varying vec2 vAoMapUv;
2170
+ #endif
2171
+ #ifdef USE_BUMPMAP
2172
+ varying vec2 vBumpMapUv;
2173
+ #endif
2174
+ #ifdef USE_NORMALMAP
2175
+ varying vec2 vNormalMapUv;
2176
+ #endif
2177
+ #ifdef USE_EMISSIVEMAP
2178
+ varying vec2 vEmissiveMapUv;
2179
+ #endif
2180
+ #ifdef USE_METALNESSMAP
2181
+ varying vec2 vMetalnessMapUv;
2182
+ #endif
2183
+ #ifdef USE_ROUGHNESSMAP
2184
+ varying vec2 vRoughnessMapUv;
2185
+ #endif
2186
+ #ifdef USE_ANISOTROPYMAP
2187
+ varying vec2 vAnisotropyMapUv;
2188
+ #endif
2189
+ #ifdef USE_CLEARCOATMAP
2190
+ varying vec2 vClearcoatMapUv;
2191
+ #endif
2192
+ #ifdef USE_CLEARCOAT_NORMALMAP
2193
+ varying vec2 vClearcoatNormalMapUv;
2194
+ #endif
2195
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
2196
+ varying vec2 vClearcoatRoughnessMapUv;
2197
+ #endif
2198
+ #ifdef USE_IRIDESCENCEMAP
2199
+ varying vec2 vIridescenceMapUv;
2200
+ #endif
2201
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
2202
+ varying vec2 vIridescenceThicknessMapUv;
2203
+ #endif
2204
+ #ifdef USE_SHEEN_COLORMAP
2205
+ varying vec2 vSheenColorMapUv;
2206
+ #endif
2207
+ #ifdef USE_SHEEN_ROUGHNESSMAP
2208
+ varying vec2 vSheenRoughnessMapUv;
2209
+ #endif
2210
+ #ifdef USE_SPECULARMAP
2211
+ varying vec2 vSpecularMapUv;
2212
+ #endif
2213
+ #ifdef USE_SPECULAR_COLORMAP
2214
+ varying vec2 vSpecularColorMapUv;
2215
+ #endif
2216
+ #ifdef USE_SPECULAR_INTENSITYMAP
2217
+ varying vec2 vSpecularIntensityMapUv;
2218
+ #endif
2219
+ #ifdef USE_TRANSMISSIONMAP
2220
+ uniform mat3 transmissionMapTransform;
2221
+ varying vec2 vTransmissionMapUv;
2222
+ #endif
2223
+ #ifdef USE_THICKNESSMAP
2224
+ uniform mat3 thicknessMapTransform;
2225
+ varying vec2 vThicknessMapUv;
2226
+ #endif`,uv_pars_vertex:`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2227
+ varying vec2 vUv;
2228
+ #endif
2229
+ #ifdef USE_MAP
2230
+ uniform mat3 mapTransform;
2231
+ varying vec2 vMapUv;
2232
+ #endif
2233
+ #ifdef USE_ALPHAMAP
2234
+ uniform mat3 alphaMapTransform;
2235
+ varying vec2 vAlphaMapUv;
2236
+ #endif
2237
+ #ifdef USE_LIGHTMAP
2238
+ uniform mat3 lightMapTransform;
2239
+ varying vec2 vLightMapUv;
2240
+ #endif
2241
+ #ifdef USE_AOMAP
2242
+ uniform mat3 aoMapTransform;
2243
+ varying vec2 vAoMapUv;
2244
+ #endif
2245
+ #ifdef USE_BUMPMAP
2246
+ uniform mat3 bumpMapTransform;
2247
+ varying vec2 vBumpMapUv;
2248
+ #endif
2249
+ #ifdef USE_NORMALMAP
2250
+ uniform mat3 normalMapTransform;
2251
+ varying vec2 vNormalMapUv;
2252
+ #endif
2253
+ #ifdef USE_DISPLACEMENTMAP
2254
+ uniform mat3 displacementMapTransform;
2255
+ varying vec2 vDisplacementMapUv;
2256
+ #endif
2257
+ #ifdef USE_EMISSIVEMAP
2258
+ uniform mat3 emissiveMapTransform;
2259
+ varying vec2 vEmissiveMapUv;
2260
+ #endif
2261
+ #ifdef USE_METALNESSMAP
2262
+ uniform mat3 metalnessMapTransform;
2263
+ varying vec2 vMetalnessMapUv;
2264
+ #endif
2265
+ #ifdef USE_ROUGHNESSMAP
2266
+ uniform mat3 roughnessMapTransform;
2267
+ varying vec2 vRoughnessMapUv;
2268
+ #endif
2269
+ #ifdef USE_ANISOTROPYMAP
2270
+ uniform mat3 anisotropyMapTransform;
2271
+ varying vec2 vAnisotropyMapUv;
2272
+ #endif
2273
+ #ifdef USE_CLEARCOATMAP
2274
+ uniform mat3 clearcoatMapTransform;
2275
+ varying vec2 vClearcoatMapUv;
2276
+ #endif
2277
+ #ifdef USE_CLEARCOAT_NORMALMAP
2278
+ uniform mat3 clearcoatNormalMapTransform;
2279
+ varying vec2 vClearcoatNormalMapUv;
2280
+ #endif
2281
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
2282
+ uniform mat3 clearcoatRoughnessMapTransform;
2283
+ varying vec2 vClearcoatRoughnessMapUv;
2284
+ #endif
2285
+ #ifdef USE_SHEEN_COLORMAP
2286
+ uniform mat3 sheenColorMapTransform;
2287
+ varying vec2 vSheenColorMapUv;
2288
+ #endif
2289
+ #ifdef USE_SHEEN_ROUGHNESSMAP
2290
+ uniform mat3 sheenRoughnessMapTransform;
2291
+ varying vec2 vSheenRoughnessMapUv;
2292
+ #endif
2293
+ #ifdef USE_IRIDESCENCEMAP
2294
+ uniform mat3 iridescenceMapTransform;
2295
+ varying vec2 vIridescenceMapUv;
2296
+ #endif
2297
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
2298
+ uniform mat3 iridescenceThicknessMapTransform;
2299
+ varying vec2 vIridescenceThicknessMapUv;
2300
+ #endif
2301
+ #ifdef USE_SPECULARMAP
2302
+ uniform mat3 specularMapTransform;
2303
+ varying vec2 vSpecularMapUv;
2304
+ #endif
2305
+ #ifdef USE_SPECULAR_COLORMAP
2306
+ uniform mat3 specularColorMapTransform;
2307
+ varying vec2 vSpecularColorMapUv;
2308
+ #endif
2309
+ #ifdef USE_SPECULAR_INTENSITYMAP
2310
+ uniform mat3 specularIntensityMapTransform;
2311
+ varying vec2 vSpecularIntensityMapUv;
2312
+ #endif
2313
+ #ifdef USE_TRANSMISSIONMAP
2314
+ uniform mat3 transmissionMapTransform;
2315
+ varying vec2 vTransmissionMapUv;
2316
+ #endif
2317
+ #ifdef USE_THICKNESSMAP
2318
+ uniform mat3 thicknessMapTransform;
2319
+ varying vec2 vThicknessMapUv;
2320
+ #endif`,uv_vertex:`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2321
+ vUv = vec3( uv, 1 ).xy;
2322
+ #endif
2323
+ #ifdef USE_MAP
2324
+ vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;
2325
+ #endif
2326
+ #ifdef USE_ALPHAMAP
2327
+ vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;
2328
+ #endif
2329
+ #ifdef USE_LIGHTMAP
2330
+ vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;
2331
+ #endif
2332
+ #ifdef USE_AOMAP
2333
+ vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;
2334
+ #endif
2335
+ #ifdef USE_BUMPMAP
2336
+ vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;
2337
+ #endif
2338
+ #ifdef USE_NORMALMAP
2339
+ vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;
2340
+ #endif
2341
+ #ifdef USE_DISPLACEMENTMAP
2342
+ vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;
2343
+ #endif
2344
+ #ifdef USE_EMISSIVEMAP
2345
+ vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;
2346
+ #endif
2347
+ #ifdef USE_METALNESSMAP
2348
+ vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;
2349
+ #endif
2350
+ #ifdef USE_ROUGHNESSMAP
2351
+ vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;
2352
+ #endif
2353
+ #ifdef USE_ANISOTROPYMAP
2354
+ vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;
2355
+ #endif
2356
+ #ifdef USE_CLEARCOATMAP
2357
+ vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;
2358
+ #endif
2359
+ #ifdef USE_CLEARCOAT_NORMALMAP
2360
+ vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;
2361
+ #endif
2362
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
2363
+ vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;
2364
+ #endif
2365
+ #ifdef USE_IRIDESCENCEMAP
2366
+ vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;
2367
+ #endif
2368
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
2369
+ vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;
2370
+ #endif
2371
+ #ifdef USE_SHEEN_COLORMAP
2372
+ vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;
2373
+ #endif
2374
+ #ifdef USE_SHEEN_ROUGHNESSMAP
2375
+ vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;
2376
+ #endif
2377
+ #ifdef USE_SPECULARMAP
2378
+ vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;
2379
+ #endif
2380
+ #ifdef USE_SPECULAR_COLORMAP
2381
+ vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;
2382
+ #endif
2383
+ #ifdef USE_SPECULAR_INTENSITYMAP
2384
+ vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;
2385
+ #endif
2386
+ #ifdef USE_TRANSMISSIONMAP
2387
+ vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;
2388
+ #endif
2389
+ #ifdef USE_THICKNESSMAP
2390
+ vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;
2391
+ #endif`,worldpos_vertex:`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
2392
+ vec4 worldPosition = vec4( transformed, 1.0 );
2393
+ #ifdef USE_BATCHING
2394
+ worldPosition = batchingMatrix * worldPosition;
2395
+ #endif
2396
+ #ifdef USE_INSTANCING
2397
+ worldPosition = instanceMatrix * worldPosition;
2398
+ #endif
2399
+ worldPosition = modelMatrix * worldPosition;
2400
+ #endif`,background_vert:`varying vec2 vUv;
2401
+ uniform mat3 uvTransform;
2402
+ void main() {
2403
+ vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
2404
+ gl_Position = vec4( position.xy, 1.0, 1.0 );
2405
+ }`,background_frag:`uniform sampler2D t2D;
2406
+ uniform float backgroundIntensity;
2407
+ varying vec2 vUv;
2408
+ void main() {
2409
+ vec4 texColor = texture2D( t2D, vUv );
2410
+ #ifdef DECODE_VIDEO_TEXTURE
2411
+ texColor = 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 );
2412
+ #endif
2413
+ texColor.rgb *= backgroundIntensity;
2414
+ gl_FragColor = texColor;
2415
+ #include <tonemapping_fragment>
2416
+ #include <colorspace_fragment>
2417
+ }`,backgroundCube_vert:`varying vec3 vWorldDirection;
2418
+ #include <common>
2419
+ void main() {
2420
+ vWorldDirection = transformDirection( position, modelMatrix );
2421
+ #include <begin_vertex>
2422
+ #include <project_vertex>
2423
+ gl_Position.z = gl_Position.w;
2424
+ }`,backgroundCube_frag:`#ifdef ENVMAP_TYPE_CUBE
2425
+ uniform samplerCube envMap;
2426
+ #elif defined( ENVMAP_TYPE_CUBE_UV )
2427
+ uniform sampler2D envMap;
2428
+ #endif
2429
+ uniform float flipEnvMap;
2430
+ uniform float backgroundBlurriness;
2431
+ uniform float backgroundIntensity;
2432
+ varying vec3 vWorldDirection;
2433
+ #include <cube_uv_reflection_fragment>
2434
+ void main() {
2435
+ #ifdef ENVMAP_TYPE_CUBE
2436
+ vec4 texColor = textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );
2437
+ #elif defined( ENVMAP_TYPE_CUBE_UV )
2438
+ vec4 texColor = textureCubeUV( envMap, vWorldDirection, backgroundBlurriness );
2439
+ #else
2440
+ vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );
2441
+ #endif
2442
+ texColor.rgb *= backgroundIntensity;
2443
+ gl_FragColor = texColor;
2444
+ #include <tonemapping_fragment>
2445
+ #include <colorspace_fragment>
2446
+ }`,cube_vert:`varying vec3 vWorldDirection;
2447
+ #include <common>
2448
+ void main() {
2449
+ vWorldDirection = transformDirection( position, modelMatrix );
2450
+ #include <begin_vertex>
2451
+ #include <project_vertex>
2452
+ gl_Position.z = gl_Position.w;
2453
+ }`,cube_frag:`uniform samplerCube tCube;
2454
+ uniform float tFlip;
2455
+ uniform float opacity;
2456
+ varying vec3 vWorldDirection;
2457
+ void main() {
2458
+ vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );
2459
+ gl_FragColor = texColor;
2460
+ gl_FragColor.a *= opacity;
2461
+ #include <tonemapping_fragment>
2462
+ #include <colorspace_fragment>
2463
+ }`,depth_vert:`#include <common>
2464
+ #include <batching_pars_vertex>
2465
+ #include <uv_pars_vertex>
2466
+ #include <displacementmap_pars_vertex>
2467
+ #include <morphtarget_pars_vertex>
2468
+ #include <skinning_pars_vertex>
2469
+ #include <logdepthbuf_pars_vertex>
2470
+ #include <clipping_planes_pars_vertex>
2471
+ varying vec2 vHighPrecisionZW;
2472
+ void main() {
2473
+ #include <uv_vertex>
2474
+ #include <batching_vertex>
2475
+ #include <skinbase_vertex>
2476
+ #ifdef USE_DISPLACEMENTMAP
2477
+ #include <beginnormal_vertex>
2478
+ #include <morphnormal_vertex>
2479
+ #include <skinnormal_vertex>
2480
+ #endif
2481
+ #include <begin_vertex>
2482
+ #include <morphtarget_vertex>
2483
+ #include <skinning_vertex>
2484
+ #include <displacementmap_vertex>
2485
+ #include <project_vertex>
2486
+ #include <logdepthbuf_vertex>
2487
+ #include <clipping_planes_vertex>
2488
+ vHighPrecisionZW = gl_Position.zw;
2489
+ }`,depth_frag:`#if DEPTH_PACKING == 3200
2490
+ uniform float opacity;
2491
+ #endif
2492
+ #include <common>
2493
+ #include <packing>
2494
+ #include <uv_pars_fragment>
2495
+ #include <map_pars_fragment>
2496
+ #include <alphamap_pars_fragment>
2497
+ #include <alphatest_pars_fragment>
2498
+ #include <alphahash_pars_fragment>
2499
+ #include <logdepthbuf_pars_fragment>
2500
+ #include <clipping_planes_pars_fragment>
2501
+ varying vec2 vHighPrecisionZW;
2502
+ void main() {
2503
+ #include <clipping_planes_fragment>
2504
+ vec4 diffuseColor = vec4( 1.0 );
2505
+ #if DEPTH_PACKING == 3200
2506
+ diffuseColor.a = opacity;
2507
+ #endif
2508
+ #include <map_fragment>
2509
+ #include <alphamap_fragment>
2510
+ #include <alphatest_fragment>
2511
+ #include <alphahash_fragment>
2512
+ #include <logdepthbuf_fragment>
2513
+ float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
2514
+ #if DEPTH_PACKING == 3200
2515
+ gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
2516
+ #elif DEPTH_PACKING == 3201
2517
+ gl_FragColor = packDepthToRGBA( fragCoordZ );
2518
+ #endif
2519
+ }`,distanceRGBA_vert:`#define DISTANCE
2520
+ varying vec3 vWorldPosition;
2521
+ #include <common>
2522
+ #include <batching_pars_vertex>
2523
+ #include <uv_pars_vertex>
2524
+ #include <displacementmap_pars_vertex>
2525
+ #include <morphtarget_pars_vertex>
2526
+ #include <skinning_pars_vertex>
2527
+ #include <clipping_planes_pars_vertex>
2528
+ void main() {
2529
+ #include <uv_vertex>
2530
+ #include <batching_vertex>
2531
+ #include <skinbase_vertex>
2532
+ #ifdef USE_DISPLACEMENTMAP
2533
+ #include <beginnormal_vertex>
2534
+ #include <morphnormal_vertex>
2535
+ #include <skinnormal_vertex>
2536
+ #endif
2537
+ #include <begin_vertex>
2538
+ #include <morphtarget_vertex>
2539
+ #include <skinning_vertex>
2540
+ #include <displacementmap_vertex>
2541
+ #include <project_vertex>
2542
+ #include <worldpos_vertex>
2543
+ #include <clipping_planes_vertex>
2544
+ vWorldPosition = worldPosition.xyz;
2545
+ }`,distanceRGBA_frag:`#define DISTANCE
2546
+ uniform vec3 referencePosition;
2547
+ uniform float nearDistance;
2548
+ uniform float farDistance;
2549
+ varying vec3 vWorldPosition;
2550
+ #include <common>
2551
+ #include <packing>
2552
+ #include <uv_pars_fragment>
2553
+ #include <map_pars_fragment>
2554
+ #include <alphamap_pars_fragment>
2555
+ #include <alphatest_pars_fragment>
2556
+ #include <alphahash_pars_fragment>
2557
+ #include <clipping_planes_pars_fragment>
2558
+ void main () {
2559
+ #include <clipping_planes_fragment>
2560
+ vec4 diffuseColor = vec4( 1.0 );
2561
+ #include <map_fragment>
2562
+ #include <alphamap_fragment>
2563
+ #include <alphatest_fragment>
2564
+ #include <alphahash_fragment>
2565
+ float dist = length( vWorldPosition - referencePosition );
2566
+ dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
2567
+ dist = saturate( dist );
2568
+ gl_FragColor = packDepthToRGBA( dist );
2569
+ }`,equirect_vert:`varying vec3 vWorldDirection;
2570
+ #include <common>
2571
+ void main() {
2572
+ vWorldDirection = transformDirection( position, modelMatrix );
2573
+ #include <begin_vertex>
2574
+ #include <project_vertex>
2575
+ }`,equirect_frag:`uniform sampler2D tEquirect;
2576
+ varying vec3 vWorldDirection;
2577
+ #include <common>
2578
+ void main() {
2579
+ vec3 direction = normalize( vWorldDirection );
2580
+ vec2 sampleUV = equirectUv( direction );
2581
+ gl_FragColor = texture2D( tEquirect, sampleUV );
2582
+ #include <tonemapping_fragment>
2583
+ #include <colorspace_fragment>
2584
+ }`,linedashed_vert:`uniform float scale;
2585
+ attribute float lineDistance;
2586
+ varying float vLineDistance;
2587
+ #include <common>
2588
+ #include <uv_pars_vertex>
2589
+ #include <color_pars_vertex>
2590
+ #include <fog_pars_vertex>
2591
+ #include <morphtarget_pars_vertex>
2592
+ #include <logdepthbuf_pars_vertex>
2593
+ #include <clipping_planes_pars_vertex>
2594
+ void main() {
2595
+ vLineDistance = scale * lineDistance;
2596
+ #include <uv_vertex>
2597
+ #include <color_vertex>
2598
+ #include <morphcolor_vertex>
2599
+ #include <begin_vertex>
2600
+ #include <morphtarget_vertex>
2601
+ #include <project_vertex>
2602
+ #include <logdepthbuf_vertex>
2603
+ #include <clipping_planes_vertex>
2604
+ #include <fog_vertex>
2605
+ }`,linedashed_frag:`uniform vec3 diffuse;
2606
+ uniform float opacity;
2607
+ uniform float dashSize;
2608
+ uniform float totalSize;
2609
+ varying float vLineDistance;
2610
+ #include <common>
2611
+ #include <color_pars_fragment>
2612
+ #include <uv_pars_fragment>
2613
+ #include <map_pars_fragment>
2614
+ #include <fog_pars_fragment>
2615
+ #include <logdepthbuf_pars_fragment>
2616
+ #include <clipping_planes_pars_fragment>
2617
+ void main() {
2618
+ #include <clipping_planes_fragment>
2619
+ if ( mod( vLineDistance, totalSize ) > dashSize ) {
2620
+ discard;
2621
+ }
2622
+ vec3 outgoingLight = vec3( 0.0 );
2623
+ vec4 diffuseColor = vec4( diffuse, opacity );
2624
+ #include <logdepthbuf_fragment>
2625
+ #include <map_fragment>
2626
+ #include <color_fragment>
2627
+ outgoingLight = diffuseColor.rgb;
2628
+ #include <opaque_fragment>
2629
+ #include <tonemapping_fragment>
2630
+ #include <colorspace_fragment>
2631
+ #include <fog_fragment>
2632
+ #include <premultiplied_alpha_fragment>
2633
+ }`,meshbasic_vert:`#include <common>
2634
+ #include <batching_pars_vertex>
2635
+ #include <uv_pars_vertex>
2636
+ #include <envmap_pars_vertex>
2637
+ #include <color_pars_vertex>
2638
+ #include <fog_pars_vertex>
2639
+ #include <morphtarget_pars_vertex>
2640
+ #include <skinning_pars_vertex>
2641
+ #include <logdepthbuf_pars_vertex>
2642
+ #include <clipping_planes_pars_vertex>
2643
+ void main() {
2644
+ #include <uv_vertex>
2645
+ #include <color_vertex>
2646
+ #include <morphcolor_vertex>
2647
+ #include <batching_vertex>
2648
+ #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
2649
+ #include <beginnormal_vertex>
2650
+ #include <morphnormal_vertex>
2651
+ #include <skinbase_vertex>
2652
+ #include <skinnormal_vertex>
2653
+ #include <defaultnormal_vertex>
2654
+ #endif
2655
+ #include <begin_vertex>
2656
+ #include <morphtarget_vertex>
2657
+ #include <skinning_vertex>
2658
+ #include <project_vertex>
2659
+ #include <logdepthbuf_vertex>
2660
+ #include <clipping_planes_vertex>
2661
+ #include <worldpos_vertex>
2662
+ #include <envmap_vertex>
2663
+ #include <fog_vertex>
2664
+ }`,meshbasic_frag:`uniform vec3 diffuse;
2665
+ uniform float opacity;
2666
+ #ifndef FLAT_SHADED
2667
+ varying vec3 vNormal;
2668
+ #endif
2669
+ #include <common>
2670
+ #include <dithering_pars_fragment>
2671
+ #include <color_pars_fragment>
2672
+ #include <uv_pars_fragment>
2673
+ #include <map_pars_fragment>
2674
+ #include <alphamap_pars_fragment>
2675
+ #include <alphatest_pars_fragment>
2676
+ #include <alphahash_pars_fragment>
2677
+ #include <aomap_pars_fragment>
2678
+ #include <lightmap_pars_fragment>
2679
+ #include <envmap_common_pars_fragment>
2680
+ #include <envmap_pars_fragment>
2681
+ #include <fog_pars_fragment>
2682
+ #include <specularmap_pars_fragment>
2683
+ #include <logdepthbuf_pars_fragment>
2684
+ #include <clipping_planes_pars_fragment>
2685
+ void main() {
2686
+ #include <clipping_planes_fragment>
2687
+ vec4 diffuseColor = vec4( diffuse, opacity );
2688
+ #include <logdepthbuf_fragment>
2689
+ #include <map_fragment>
2690
+ #include <color_fragment>
2691
+ #include <alphamap_fragment>
2692
+ #include <alphatest_fragment>
2693
+ #include <alphahash_fragment>
2694
+ #include <specularmap_fragment>
2695
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
2696
+ #ifdef USE_LIGHTMAP
2697
+ vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
2698
+ reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;
2699
+ #else
2700
+ reflectedLight.indirectDiffuse += vec3( 1.0 );
2701
+ #endif
2702
+ #include <aomap_fragment>
2703
+ reflectedLight.indirectDiffuse *= diffuseColor.rgb;
2704
+ vec3 outgoingLight = reflectedLight.indirectDiffuse;
2705
+ #include <envmap_fragment>
2706
+ #include <opaque_fragment>
2707
+ #include <tonemapping_fragment>
2708
+ #include <colorspace_fragment>
2709
+ #include <fog_fragment>
2710
+ #include <premultiplied_alpha_fragment>
2711
+ #include <dithering_fragment>
2712
+ }`,meshlambert_vert:`#define LAMBERT
2713
+ varying vec3 vViewPosition;
2714
+ #include <common>
2715
+ #include <batching_pars_vertex>
2716
+ #include <uv_pars_vertex>
2717
+ #include <displacementmap_pars_vertex>
2718
+ #include <envmap_pars_vertex>
2719
+ #include <color_pars_vertex>
2720
+ #include <fog_pars_vertex>
2721
+ #include <normal_pars_vertex>
2722
+ #include <morphtarget_pars_vertex>
2723
+ #include <skinning_pars_vertex>
2724
+ #include <shadowmap_pars_vertex>
2725
+ #include <logdepthbuf_pars_vertex>
2726
+ #include <clipping_planes_pars_vertex>
2727
+ void main() {
2728
+ #include <uv_vertex>
2729
+ #include <color_vertex>
2730
+ #include <morphcolor_vertex>
2731
+ #include <batching_vertex>
2732
+ #include <beginnormal_vertex>
2733
+ #include <morphnormal_vertex>
2734
+ #include <skinbase_vertex>
2735
+ #include <skinnormal_vertex>
2736
+ #include <defaultnormal_vertex>
2737
+ #include <normal_vertex>
2738
+ #include <begin_vertex>
2739
+ #include <morphtarget_vertex>
2740
+ #include <skinning_vertex>
2741
+ #include <displacementmap_vertex>
2742
+ #include <project_vertex>
2743
+ #include <logdepthbuf_vertex>
2744
+ #include <clipping_planes_vertex>
2745
+ vViewPosition = - mvPosition.xyz;
2746
+ #include <worldpos_vertex>
2747
+ #include <envmap_vertex>
2748
+ #include <shadowmap_vertex>
2749
+ #include <fog_vertex>
2750
+ }`,meshlambert_frag:`#define LAMBERT
2751
+ uniform vec3 diffuse;
2752
+ uniform vec3 emissive;
2753
+ uniform float opacity;
2754
+ #include <common>
2755
+ #include <packing>
2756
+ #include <dithering_pars_fragment>
2757
+ #include <color_pars_fragment>
2758
+ #include <uv_pars_fragment>
2759
+ #include <map_pars_fragment>
2760
+ #include <alphamap_pars_fragment>
2761
+ #include <alphatest_pars_fragment>
2762
+ #include <alphahash_pars_fragment>
2763
+ #include <aomap_pars_fragment>
2764
+ #include <lightmap_pars_fragment>
2765
+ #include <emissivemap_pars_fragment>
2766
+ #include <envmap_common_pars_fragment>
2767
+ #include <envmap_pars_fragment>
2768
+ #include <fog_pars_fragment>
2769
+ #include <bsdfs>
2770
+ #include <lights_pars_begin>
2771
+ #include <normal_pars_fragment>
2772
+ #include <lights_lambert_pars_fragment>
2773
+ #include <shadowmap_pars_fragment>
2774
+ #include <bumpmap_pars_fragment>
2775
+ #include <normalmap_pars_fragment>
2776
+ #include <specularmap_pars_fragment>
2777
+ #include <logdepthbuf_pars_fragment>
2778
+ #include <clipping_planes_pars_fragment>
2779
+ void main() {
2780
+ #include <clipping_planes_fragment>
2781
+ vec4 diffuseColor = vec4( diffuse, opacity );
2782
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
2783
+ vec3 totalEmissiveRadiance = emissive;
2784
+ #include <logdepthbuf_fragment>
2785
+ #include <map_fragment>
2786
+ #include <color_fragment>
2787
+ #include <alphamap_fragment>
2788
+ #include <alphatest_fragment>
2789
+ #include <alphahash_fragment>
2790
+ #include <specularmap_fragment>
2791
+ #include <normal_fragment_begin>
2792
+ #include <normal_fragment_maps>
2793
+ #include <emissivemap_fragment>
2794
+ #include <lights_lambert_fragment>
2795
+ #include <lights_fragment_begin>
2796
+ #include <lights_fragment_maps>
2797
+ #include <lights_fragment_end>
2798
+ #include <aomap_fragment>
2799
+ vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
2800
+ #include <envmap_fragment>
2801
+ #include <opaque_fragment>
2802
+ #include <tonemapping_fragment>
2803
+ #include <colorspace_fragment>
2804
+ #include <fog_fragment>
2805
+ #include <premultiplied_alpha_fragment>
2806
+ #include <dithering_fragment>
2807
+ }`,meshmatcap_vert:`#define MATCAP
2808
+ varying vec3 vViewPosition;
2809
+ #include <common>
2810
+ #include <batching_pars_vertex>
2811
+ #include <uv_pars_vertex>
2812
+ #include <color_pars_vertex>
2813
+ #include <displacementmap_pars_vertex>
2814
+ #include <fog_pars_vertex>
2815
+ #include <normal_pars_vertex>
2816
+ #include <morphtarget_pars_vertex>
2817
+ #include <skinning_pars_vertex>
2818
+ #include <logdepthbuf_pars_vertex>
2819
+ #include <clipping_planes_pars_vertex>
2820
+ void main() {
2821
+ #include <uv_vertex>
2822
+ #include <color_vertex>
2823
+ #include <morphcolor_vertex>
2824
+ #include <batching_vertex>
2825
+ #include <beginnormal_vertex>
2826
+ #include <morphnormal_vertex>
2827
+ #include <skinbase_vertex>
2828
+ #include <skinnormal_vertex>
2829
+ #include <defaultnormal_vertex>
2830
+ #include <normal_vertex>
2831
+ #include <begin_vertex>
2832
+ #include <morphtarget_vertex>
2833
+ #include <skinning_vertex>
2834
+ #include <displacementmap_vertex>
2835
+ #include <project_vertex>
2836
+ #include <logdepthbuf_vertex>
2837
+ #include <clipping_planes_vertex>
2838
+ #include <fog_vertex>
2839
+ vViewPosition = - mvPosition.xyz;
2840
+ }`,meshmatcap_frag:`#define MATCAP
2841
+ uniform vec3 diffuse;
2842
+ uniform float opacity;
2843
+ uniform sampler2D matcap;
2844
+ varying vec3 vViewPosition;
2845
+ #include <common>
2846
+ #include <dithering_pars_fragment>
2847
+ #include <color_pars_fragment>
2848
+ #include <uv_pars_fragment>
2849
+ #include <map_pars_fragment>
2850
+ #include <alphamap_pars_fragment>
2851
+ #include <alphatest_pars_fragment>
2852
+ #include <alphahash_pars_fragment>
2853
+ #include <fog_pars_fragment>
2854
+ #include <normal_pars_fragment>
2855
+ #include <bumpmap_pars_fragment>
2856
+ #include <normalmap_pars_fragment>
2857
+ #include <logdepthbuf_pars_fragment>
2858
+ #include <clipping_planes_pars_fragment>
2859
+ void main() {
2860
+ #include <clipping_planes_fragment>
2861
+ vec4 diffuseColor = vec4( diffuse, opacity );
2862
+ #include <logdepthbuf_fragment>
2863
+ #include <map_fragment>
2864
+ #include <color_fragment>
2865
+ #include <alphamap_fragment>
2866
+ #include <alphatest_fragment>
2867
+ #include <alphahash_fragment>
2868
+ #include <normal_fragment_begin>
2869
+ #include <normal_fragment_maps>
2870
+ vec3 viewDir = normalize( vViewPosition );
2871
+ vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );
2872
+ vec3 y = cross( viewDir, x );
2873
+ vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;
2874
+ #ifdef USE_MATCAP
2875
+ vec4 matcapColor = texture2D( matcap, uv );
2876
+ #else
2877
+ vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );
2878
+ #endif
2879
+ vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
2880
+ #include <opaque_fragment>
2881
+ #include <tonemapping_fragment>
2882
+ #include <colorspace_fragment>
2883
+ #include <fog_fragment>
2884
+ #include <premultiplied_alpha_fragment>
2885
+ #include <dithering_fragment>
2886
+ }`,meshnormal_vert:`#define NORMAL
2887
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
2888
+ varying vec3 vViewPosition;
2889
+ #endif
2890
+ #include <common>
2891
+ #include <batching_pars_vertex>
2892
+ #include <uv_pars_vertex>
2893
+ #include <displacementmap_pars_vertex>
2894
+ #include <normal_pars_vertex>
2895
+ #include <morphtarget_pars_vertex>
2896
+ #include <skinning_pars_vertex>
2897
+ #include <logdepthbuf_pars_vertex>
2898
+ #include <clipping_planes_pars_vertex>
2899
+ void main() {
2900
+ #include <uv_vertex>
2901
+ #include <batching_vertex>
2902
+ #include <beginnormal_vertex>
2903
+ #include <morphnormal_vertex>
2904
+ #include <skinbase_vertex>
2905
+ #include <skinnormal_vertex>
2906
+ #include <defaultnormal_vertex>
2907
+ #include <normal_vertex>
2908
+ #include <begin_vertex>
2909
+ #include <morphtarget_vertex>
2910
+ #include <skinning_vertex>
2911
+ #include <displacementmap_vertex>
2912
+ #include <project_vertex>
2913
+ #include <logdepthbuf_vertex>
2914
+ #include <clipping_planes_vertex>
2915
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
2916
+ vViewPosition = - mvPosition.xyz;
2917
+ #endif
2918
+ }`,meshnormal_frag:`#define NORMAL
2919
+ uniform float opacity;
2920
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
2921
+ varying vec3 vViewPosition;
2922
+ #endif
2923
+ #include <packing>
2924
+ #include <uv_pars_fragment>
2925
+ #include <normal_pars_fragment>
2926
+ #include <bumpmap_pars_fragment>
2927
+ #include <normalmap_pars_fragment>
2928
+ #include <logdepthbuf_pars_fragment>
2929
+ #include <clipping_planes_pars_fragment>
2930
+ void main() {
2931
+ #include <clipping_planes_fragment>
2932
+ #include <logdepthbuf_fragment>
2933
+ #include <normal_fragment_begin>
2934
+ #include <normal_fragment_maps>
2935
+ gl_FragColor = vec4( packNormalToRGB( normal ), opacity );
2936
+ #ifdef OPAQUE
2937
+ gl_FragColor.a = 1.0;
2938
+ #endif
2939
+ }`,meshphong_vert:`#define PHONG
2940
+ varying vec3 vViewPosition;
2941
+ #include <common>
2942
+ #include <batching_pars_vertex>
2943
+ #include <uv_pars_vertex>
2944
+ #include <displacementmap_pars_vertex>
2945
+ #include <envmap_pars_vertex>
2946
+ #include <color_pars_vertex>
2947
+ #include <fog_pars_vertex>
2948
+ #include <normal_pars_vertex>
2949
+ #include <morphtarget_pars_vertex>
2950
+ #include <skinning_pars_vertex>
2951
+ #include <shadowmap_pars_vertex>
2952
+ #include <logdepthbuf_pars_vertex>
2953
+ #include <clipping_planes_pars_vertex>
2954
+ void main() {
2955
+ #include <uv_vertex>
2956
+ #include <color_vertex>
2957
+ #include <morphcolor_vertex>
2958
+ #include <batching_vertex>
2959
+ #include <beginnormal_vertex>
2960
+ #include <morphnormal_vertex>
2961
+ #include <skinbase_vertex>
2962
+ #include <skinnormal_vertex>
2963
+ #include <defaultnormal_vertex>
2964
+ #include <normal_vertex>
2965
+ #include <begin_vertex>
2966
+ #include <morphtarget_vertex>
2967
+ #include <skinning_vertex>
2968
+ #include <displacementmap_vertex>
2969
+ #include <project_vertex>
2970
+ #include <logdepthbuf_vertex>
2971
+ #include <clipping_planes_vertex>
2972
+ vViewPosition = - mvPosition.xyz;
2973
+ #include <worldpos_vertex>
2974
+ #include <envmap_vertex>
2975
+ #include <shadowmap_vertex>
2976
+ #include <fog_vertex>
2977
+ }`,meshphong_frag:`#define PHONG
2978
+ uniform vec3 diffuse;
2979
+ uniform vec3 emissive;
2980
+ uniform vec3 specular;
2981
+ uniform float shininess;
2982
+ uniform float opacity;
2983
+ #include <common>
2984
+ #include <packing>
2985
+ #include <dithering_pars_fragment>
2986
+ #include <color_pars_fragment>
2987
+ #include <uv_pars_fragment>
2988
+ #include <map_pars_fragment>
2989
+ #include <alphamap_pars_fragment>
2990
+ #include <alphatest_pars_fragment>
2991
+ #include <alphahash_pars_fragment>
2992
+ #include <aomap_pars_fragment>
2993
+ #include <lightmap_pars_fragment>
2994
+ #include <emissivemap_pars_fragment>
2995
+ #include <envmap_common_pars_fragment>
2996
+ #include <envmap_pars_fragment>
2997
+ #include <fog_pars_fragment>
2998
+ #include <bsdfs>
2999
+ #include <lights_pars_begin>
3000
+ #include <normal_pars_fragment>
3001
+ #include <lights_phong_pars_fragment>
3002
+ #include <shadowmap_pars_fragment>
3003
+ #include <bumpmap_pars_fragment>
3004
+ #include <normalmap_pars_fragment>
3005
+ #include <specularmap_pars_fragment>
3006
+ #include <logdepthbuf_pars_fragment>
3007
+ #include <clipping_planes_pars_fragment>
3008
+ void main() {
3009
+ #include <clipping_planes_fragment>
3010
+ vec4 diffuseColor = vec4( diffuse, opacity );
3011
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3012
+ vec3 totalEmissiveRadiance = emissive;
3013
+ #include <logdepthbuf_fragment>
3014
+ #include <map_fragment>
3015
+ #include <color_fragment>
3016
+ #include <alphamap_fragment>
3017
+ #include <alphatest_fragment>
3018
+ #include <alphahash_fragment>
3019
+ #include <specularmap_fragment>
3020
+ #include <normal_fragment_begin>
3021
+ #include <normal_fragment_maps>
3022
+ #include <emissivemap_fragment>
3023
+ #include <lights_phong_fragment>
3024
+ #include <lights_fragment_begin>
3025
+ #include <lights_fragment_maps>
3026
+ #include <lights_fragment_end>
3027
+ #include <aomap_fragment>
3028
+ vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
3029
+ #include <envmap_fragment>
3030
+ #include <opaque_fragment>
3031
+ #include <tonemapping_fragment>
3032
+ #include <colorspace_fragment>
3033
+ #include <fog_fragment>
3034
+ #include <premultiplied_alpha_fragment>
3035
+ #include <dithering_fragment>
3036
+ }`,meshphysical_vert:`#define STANDARD
3037
+ varying vec3 vViewPosition;
3038
+ #ifdef USE_TRANSMISSION
3039
+ varying vec3 vWorldPosition;
3040
+ #endif
3041
+ #include <common>
3042
+ #include <batching_pars_vertex>
3043
+ #include <uv_pars_vertex>
3044
+ #include <displacementmap_pars_vertex>
3045
+ #include <color_pars_vertex>
3046
+ #include <fog_pars_vertex>
3047
+ #include <normal_pars_vertex>
3048
+ #include <morphtarget_pars_vertex>
3049
+ #include <skinning_pars_vertex>
3050
+ #include <shadowmap_pars_vertex>
3051
+ #include <logdepthbuf_pars_vertex>
3052
+ #include <clipping_planes_pars_vertex>
3053
+ void main() {
3054
+ #include <uv_vertex>
3055
+ #include <color_vertex>
3056
+ #include <morphcolor_vertex>
3057
+ #include <batching_vertex>
3058
+ #include <beginnormal_vertex>
3059
+ #include <morphnormal_vertex>
3060
+ #include <skinbase_vertex>
3061
+ #include <skinnormal_vertex>
3062
+ #include <defaultnormal_vertex>
3063
+ #include <normal_vertex>
3064
+ #include <begin_vertex>
3065
+ #include <morphtarget_vertex>
3066
+ #include <skinning_vertex>
3067
+ #include <displacementmap_vertex>
3068
+ #include <project_vertex>
3069
+ #include <logdepthbuf_vertex>
3070
+ #include <clipping_planes_vertex>
3071
+ vViewPosition = - mvPosition.xyz;
3072
+ #include <worldpos_vertex>
3073
+ #include <shadowmap_vertex>
3074
+ #include <fog_vertex>
3075
+ #ifdef USE_TRANSMISSION
3076
+ vWorldPosition = worldPosition.xyz;
3077
+ #endif
3078
+ }`,meshphysical_frag:`#define STANDARD
3079
+ #ifdef PHYSICAL
3080
+ #define IOR
3081
+ #define USE_SPECULAR
3082
+ #endif
3083
+ uniform vec3 diffuse;
3084
+ uniform vec3 emissive;
3085
+ uniform float roughness;
3086
+ uniform float metalness;
3087
+ uniform float opacity;
3088
+ #ifdef IOR
3089
+ uniform float ior;
3090
+ #endif
3091
+ #ifdef USE_SPECULAR
3092
+ uniform float specularIntensity;
3093
+ uniform vec3 specularColor;
3094
+ #ifdef USE_SPECULAR_COLORMAP
3095
+ uniform sampler2D specularColorMap;
3096
+ #endif
3097
+ #ifdef USE_SPECULAR_INTENSITYMAP
3098
+ uniform sampler2D specularIntensityMap;
3099
+ #endif
3100
+ #endif
3101
+ #ifdef USE_CLEARCOAT
3102
+ uniform float clearcoat;
3103
+ uniform float clearcoatRoughness;
3104
+ #endif
3105
+ #ifdef USE_IRIDESCENCE
3106
+ uniform float iridescence;
3107
+ uniform float iridescenceIOR;
3108
+ uniform float iridescenceThicknessMinimum;
3109
+ uniform float iridescenceThicknessMaximum;
3110
+ #endif
3111
+ #ifdef USE_SHEEN
3112
+ uniform vec3 sheenColor;
3113
+ uniform float sheenRoughness;
3114
+ #ifdef USE_SHEEN_COLORMAP
3115
+ uniform sampler2D sheenColorMap;
3116
+ #endif
3117
+ #ifdef USE_SHEEN_ROUGHNESSMAP
3118
+ uniform sampler2D sheenRoughnessMap;
3119
+ #endif
3120
+ #endif
3121
+ #ifdef USE_ANISOTROPY
3122
+ uniform vec2 anisotropyVector;
3123
+ #ifdef USE_ANISOTROPYMAP
3124
+ uniform sampler2D anisotropyMap;
3125
+ #endif
3126
+ #endif
3127
+ varying vec3 vViewPosition;
3128
+ #include <common>
3129
+ #include <packing>
3130
+ #include <dithering_pars_fragment>
3131
+ #include <color_pars_fragment>
3132
+ #include <uv_pars_fragment>
3133
+ #include <map_pars_fragment>
3134
+ #include <alphamap_pars_fragment>
3135
+ #include <alphatest_pars_fragment>
3136
+ #include <alphahash_pars_fragment>
3137
+ #include <aomap_pars_fragment>
3138
+ #include <lightmap_pars_fragment>
3139
+ #include <emissivemap_pars_fragment>
3140
+ #include <iridescence_fragment>
3141
+ #include <cube_uv_reflection_fragment>
3142
+ #include <envmap_common_pars_fragment>
3143
+ #include <envmap_physical_pars_fragment>
3144
+ #include <fog_pars_fragment>
3145
+ #include <lights_pars_begin>
3146
+ #include <normal_pars_fragment>
3147
+ #include <lights_physical_pars_fragment>
3148
+ #include <transmission_pars_fragment>
3149
+ #include <shadowmap_pars_fragment>
3150
+ #include <bumpmap_pars_fragment>
3151
+ #include <normalmap_pars_fragment>
3152
+ #include <clearcoat_pars_fragment>
3153
+ #include <iridescence_pars_fragment>
3154
+ #include <roughnessmap_pars_fragment>
3155
+ #include <metalnessmap_pars_fragment>
3156
+ #include <logdepthbuf_pars_fragment>
3157
+ #include <clipping_planes_pars_fragment>
3158
+ void main() {
3159
+ #include <clipping_planes_fragment>
3160
+ vec4 diffuseColor = vec4( diffuse, opacity );
3161
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3162
+ vec3 totalEmissiveRadiance = emissive;
3163
+ #include <logdepthbuf_fragment>
3164
+ #include <map_fragment>
3165
+ #include <color_fragment>
3166
+ #include <alphamap_fragment>
3167
+ #include <alphatest_fragment>
3168
+ #include <alphahash_fragment>
3169
+ #include <roughnessmap_fragment>
3170
+ #include <metalnessmap_fragment>
3171
+ #include <normal_fragment_begin>
3172
+ #include <normal_fragment_maps>
3173
+ #include <clearcoat_normal_fragment_begin>
3174
+ #include <clearcoat_normal_fragment_maps>
3175
+ #include <emissivemap_fragment>
3176
+ #include <lights_physical_fragment>
3177
+ #include <lights_fragment_begin>
3178
+ #include <lights_fragment_maps>
3179
+ #include <lights_fragment_end>
3180
+ #include <aomap_fragment>
3181
+ vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
3182
+ vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
3183
+ #include <transmission_fragment>
3184
+ vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
3185
+ #ifdef USE_SHEEN
3186
+ float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
3187
+ outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;
3188
+ #endif
3189
+ #ifdef USE_CLEARCOAT
3190
+ float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
3191
+ vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
3192
+ outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
3193
+ #endif
3194
+ #include <opaque_fragment>
3195
+ #include <tonemapping_fragment>
3196
+ #include <colorspace_fragment>
3197
+ #include <fog_fragment>
3198
+ #include <premultiplied_alpha_fragment>
3199
+ #include <dithering_fragment>
3200
+ }`,meshtoon_vert:`#define TOON
3201
+ varying vec3 vViewPosition;
3202
+ #include <common>
3203
+ #include <batching_pars_vertex>
3204
+ #include <uv_pars_vertex>
3205
+ #include <displacementmap_pars_vertex>
3206
+ #include <color_pars_vertex>
3207
+ #include <fog_pars_vertex>
3208
+ #include <normal_pars_vertex>
3209
+ #include <morphtarget_pars_vertex>
3210
+ #include <skinning_pars_vertex>
3211
+ #include <shadowmap_pars_vertex>
3212
+ #include <logdepthbuf_pars_vertex>
3213
+ #include <clipping_planes_pars_vertex>
3214
+ void main() {
3215
+ #include <uv_vertex>
3216
+ #include <color_vertex>
3217
+ #include <morphcolor_vertex>
3218
+ #include <batching_vertex>
3219
+ #include <beginnormal_vertex>
3220
+ #include <morphnormal_vertex>
3221
+ #include <skinbase_vertex>
3222
+ #include <skinnormal_vertex>
3223
+ #include <defaultnormal_vertex>
3224
+ #include <normal_vertex>
3225
+ #include <begin_vertex>
3226
+ #include <morphtarget_vertex>
3227
+ #include <skinning_vertex>
3228
+ #include <displacementmap_vertex>
3229
+ #include <project_vertex>
3230
+ #include <logdepthbuf_vertex>
3231
+ #include <clipping_planes_vertex>
3232
+ vViewPosition = - mvPosition.xyz;
3233
+ #include <worldpos_vertex>
3234
+ #include <shadowmap_vertex>
3235
+ #include <fog_vertex>
3236
+ }`,meshtoon_frag:`#define TOON
3237
+ uniform vec3 diffuse;
3238
+ uniform vec3 emissive;
3239
+ uniform float opacity;
3240
+ #include <common>
3241
+ #include <packing>
3242
+ #include <dithering_pars_fragment>
3243
+ #include <color_pars_fragment>
3244
+ #include <uv_pars_fragment>
3245
+ #include <map_pars_fragment>
3246
+ #include <alphamap_pars_fragment>
3247
+ #include <alphatest_pars_fragment>
3248
+ #include <alphahash_pars_fragment>
3249
+ #include <aomap_pars_fragment>
3250
+ #include <lightmap_pars_fragment>
3251
+ #include <emissivemap_pars_fragment>
3252
+ #include <gradientmap_pars_fragment>
3253
+ #include <fog_pars_fragment>
3254
+ #include <bsdfs>
3255
+ #include <lights_pars_begin>
3256
+ #include <normal_pars_fragment>
3257
+ #include <lights_toon_pars_fragment>
3258
+ #include <shadowmap_pars_fragment>
3259
+ #include <bumpmap_pars_fragment>
3260
+ #include <normalmap_pars_fragment>
3261
+ #include <logdepthbuf_pars_fragment>
3262
+ #include <clipping_planes_pars_fragment>
3263
+ void main() {
3264
+ #include <clipping_planes_fragment>
3265
+ vec4 diffuseColor = vec4( diffuse, opacity );
3266
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3267
+ vec3 totalEmissiveRadiance = emissive;
3268
+ #include <logdepthbuf_fragment>
3269
+ #include <map_fragment>
3270
+ #include <color_fragment>
3271
+ #include <alphamap_fragment>
3272
+ #include <alphatest_fragment>
3273
+ #include <alphahash_fragment>
3274
+ #include <normal_fragment_begin>
3275
+ #include <normal_fragment_maps>
3276
+ #include <emissivemap_fragment>
3277
+ #include <lights_toon_fragment>
3278
+ #include <lights_fragment_begin>
3279
+ #include <lights_fragment_maps>
3280
+ #include <lights_fragment_end>
3281
+ #include <aomap_fragment>
3282
+ vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
3283
+ #include <opaque_fragment>
3284
+ #include <tonemapping_fragment>
3285
+ #include <colorspace_fragment>
3286
+ #include <fog_fragment>
3287
+ #include <premultiplied_alpha_fragment>
3288
+ #include <dithering_fragment>
3289
+ }`,points_vert:`uniform float size;
3290
+ uniform float scale;
3291
+ #include <common>
3292
+ #include <color_pars_vertex>
3293
+ #include <fog_pars_vertex>
3294
+ #include <morphtarget_pars_vertex>
3295
+ #include <logdepthbuf_pars_vertex>
3296
+ #include <clipping_planes_pars_vertex>
3297
+ #ifdef USE_POINTS_UV
3298
+ varying vec2 vUv;
3299
+ uniform mat3 uvTransform;
3300
+ #endif
3301
+ void main() {
3302
+ #ifdef USE_POINTS_UV
3303
+ vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
3304
+ #endif
3305
+ #include <color_vertex>
3306
+ #include <morphcolor_vertex>
3307
+ #include <begin_vertex>
3308
+ #include <morphtarget_vertex>
3309
+ #include <project_vertex>
3310
+ gl_PointSize = size;
3311
+ #ifdef USE_SIZEATTENUATION
3312
+ bool isPerspective = isPerspectiveMatrix( projectionMatrix );
3313
+ if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );
3314
+ #endif
3315
+ #include <logdepthbuf_vertex>
3316
+ #include <clipping_planes_vertex>
3317
+ #include <worldpos_vertex>
3318
+ #include <fog_vertex>
3319
+ }`,points_frag:`uniform vec3 diffuse;
3320
+ uniform float opacity;
3321
+ #include <common>
3322
+ #include <color_pars_fragment>
3323
+ #include <map_particle_pars_fragment>
3324
+ #include <alphatest_pars_fragment>
3325
+ #include <alphahash_pars_fragment>
3326
+ #include <fog_pars_fragment>
3327
+ #include <logdepthbuf_pars_fragment>
3328
+ #include <clipping_planes_pars_fragment>
3329
+ void main() {
3330
+ #include <clipping_planes_fragment>
3331
+ vec3 outgoingLight = vec3( 0.0 );
3332
+ vec4 diffuseColor = vec4( diffuse, opacity );
3333
+ #include <logdepthbuf_fragment>
3334
+ #include <map_particle_fragment>
3335
+ #include <color_fragment>
3336
+ #include <alphatest_fragment>
3337
+ #include <alphahash_fragment>
3338
+ outgoingLight = diffuseColor.rgb;
3339
+ #include <opaque_fragment>
3340
+ #include <tonemapping_fragment>
3341
+ #include <colorspace_fragment>
3342
+ #include <fog_fragment>
3343
+ #include <premultiplied_alpha_fragment>
3344
+ }`,shadow_vert:`#include <common>
3345
+ #include <batching_pars_vertex>
3346
+ #include <fog_pars_vertex>
3347
+ #include <morphtarget_pars_vertex>
3348
+ #include <skinning_pars_vertex>
3349
+ #include <logdepthbuf_pars_vertex>
3350
+ #include <shadowmap_pars_vertex>
3351
+ void main() {
3352
+ #include <batching_vertex>
3353
+ #include <beginnormal_vertex>
3354
+ #include <morphnormal_vertex>
3355
+ #include <skinbase_vertex>
3356
+ #include <skinnormal_vertex>
3357
+ #include <defaultnormal_vertex>
3358
+ #include <begin_vertex>
3359
+ #include <morphtarget_vertex>
3360
+ #include <skinning_vertex>
3361
+ #include <project_vertex>
3362
+ #include <logdepthbuf_vertex>
3363
+ #include <worldpos_vertex>
3364
+ #include <shadowmap_vertex>
3365
+ #include <fog_vertex>
3366
+ }`,shadow_frag:`uniform vec3 color;
3367
+ uniform float opacity;
3368
+ #include <common>
3369
+ #include <packing>
3370
+ #include <fog_pars_fragment>
3371
+ #include <bsdfs>
3372
+ #include <lights_pars_begin>
3373
+ #include <logdepthbuf_pars_fragment>
3374
+ #include <shadowmap_pars_fragment>
3375
+ #include <shadowmask_pars_fragment>
3376
+ void main() {
3377
+ #include <logdepthbuf_fragment>
3378
+ gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
3379
+ #include <tonemapping_fragment>
3380
+ #include <colorspace_fragment>
3381
+ #include <fog_fragment>
3382
+ }`,sprite_vert:`uniform float rotation;
3383
+ uniform vec2 center;
3384
+ #include <common>
3385
+ #include <uv_pars_vertex>
3386
+ #include <fog_pars_vertex>
3387
+ #include <logdepthbuf_pars_vertex>
3388
+ #include <clipping_planes_pars_vertex>
3389
+ void main() {
3390
+ #include <uv_vertex>
3391
+ vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );
3392
+ vec2 scale;
3393
+ scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );
3394
+ scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );
3395
+ #ifndef USE_SIZEATTENUATION
3396
+ bool isPerspective = isPerspectiveMatrix( projectionMatrix );
3397
+ if ( isPerspective ) scale *= - mvPosition.z;
3398
+ #endif
3399
+ vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;
3400
+ vec2 rotatedPosition;
3401
+ rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
3402
+ rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
3403
+ mvPosition.xy += rotatedPosition;
3404
+ gl_Position = projectionMatrix * mvPosition;
3405
+ #include <logdepthbuf_vertex>
3406
+ #include <clipping_planes_vertex>
3407
+ #include <fog_vertex>
3408
+ }`,sprite_frag:`uniform vec3 diffuse;
3409
+ uniform float opacity;
3410
+ #include <common>
3411
+ #include <uv_pars_fragment>
3412
+ #include <map_pars_fragment>
3413
+ #include <alphamap_pars_fragment>
3414
+ #include <alphatest_pars_fragment>
3415
+ #include <alphahash_pars_fragment>
3416
+ #include <fog_pars_fragment>
3417
+ #include <logdepthbuf_pars_fragment>
3418
+ #include <clipping_planes_pars_fragment>
3419
+ void main() {
3420
+ #include <clipping_planes_fragment>
3421
+ vec3 outgoingLight = vec3( 0.0 );
3422
+ vec4 diffuseColor = vec4( diffuse, opacity );
3423
+ #include <logdepthbuf_fragment>
3424
+ #include <map_fragment>
3425
+ #include <alphamap_fragment>
3426
+ #include <alphatest_fragment>
3427
+ #include <alphahash_fragment>
3428
+ outgoingLight = diffuseColor.rgb;
3429
+ #include <opaque_fragment>
3430
+ #include <tonemapping_fragment>
3431
+ #include <colorspace_fragment>
3432
+ #include <fog_fragment>
3433
+ }`},$={common:{diffuse:{value:new Z(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new q},alphaMap:{value:null},alphaMapTransform:{value:new q},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new q}},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 q}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new q}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new q},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new q},normalScale:{value:new K(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new q},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new q}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new q}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new q}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Z(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 Z(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new q},alphaTest:{value:0},uvTransform:{value:new q}},sprite:{diffuse:{value:new Z(16777215)},opacity:{value:1},center:{value:new K(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new q},alphaMap:{value:null},alphaMapTransform:{value:new q},alphaTest:{value:0}}},xr={basic:{uniforms:Zn([$.common,$.specularmap,$.envmap,$.aomap,$.lightmap,$.fog]),vertexShader:Q.meshbasic_vert,fragmentShader:Q.meshbasic_frag},lambert:{uniforms:Zn([$.common,$.specularmap,$.envmap,$.aomap,$.lightmap,$.emissivemap,$.bumpmap,$.normalmap,$.displacementmap,$.fog,$.lights,{emissive:{value:new Z(0)}}]),vertexShader:Q.meshlambert_vert,fragmentShader:Q.meshlambert_frag},phong:{uniforms:Zn([$.common,$.specularmap,$.envmap,$.aomap,$.lightmap,$.emissivemap,$.bumpmap,$.normalmap,$.displacementmap,$.fog,$.lights,{emissive:{value:new Z(0)},specular:{value:new Z(1118481)},shininess:{value:30}}]),vertexShader:Q.meshphong_vert,fragmentShader:Q.meshphong_frag},standard:{uniforms:Zn([$.common,$.envmap,$.aomap,$.lightmap,$.emissivemap,$.bumpmap,$.normalmap,$.displacementmap,$.roughnessmap,$.metalnessmap,$.fog,$.lights,{emissive:{value:new Z(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Q.meshphysical_vert,fragmentShader:Q.meshphysical_frag},toon:{uniforms:Zn([$.common,$.aomap,$.lightmap,$.emissivemap,$.bumpmap,$.normalmap,$.displacementmap,$.gradientmap,$.fog,$.lights,{emissive:{value:new Z(0)}}]),vertexShader:Q.meshtoon_vert,fragmentShader:Q.meshtoon_frag},matcap:{uniforms:Zn([$.common,$.bumpmap,$.normalmap,$.displacementmap,$.fog,{matcap:{value:null}}]),vertexShader:Q.meshmatcap_vert,fragmentShader:Q.meshmatcap_frag},points:{uniforms:Zn([$.points,$.fog]),vertexShader:Q.points_vert,fragmentShader:Q.points_frag},dashed:{uniforms:Zn([$.common,$.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Q.linedashed_vert,fragmentShader:Q.linedashed_frag},depth:{uniforms:Zn([$.common,$.displacementmap]),vertexShader:Q.depth_vert,fragmentShader:Q.depth_frag},normal:{uniforms:Zn([$.common,$.bumpmap,$.normalmap,$.displacementmap,{opacity:{value:1}}]),vertexShader:Q.meshnormal_vert,fragmentShader:Q.meshnormal_frag},sprite:{uniforms:Zn([$.sprite,$.fog]),vertexShader:Q.sprite_vert,fragmentShader:Q.sprite_frag},background:{uniforms:{uvTransform:{value:new q},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Q.background_vert,fragmentShader:Q.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1}},vertexShader:Q.backgroundCube_vert,fragmentShader:Q.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Q.cube_vert,fragmentShader:Q.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Q.equirect_vert,fragmentShader:Q.equirect_frag},distanceRGBA:{uniforms:Zn([$.common,$.displacementmap,{referencePosition:{value:new X},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Q.distanceRGBA_vert,fragmentShader:Q.distanceRGBA_frag},shadow:{uniforms:Zn([$.lights,$.fog,{color:{value:new Z(0)},opacity:{value:1}}]),vertexShader:Q.shadow_vert,fragmentShader:Q.shadow_frag}};xr.physical={uniforms:Zn([xr.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new q},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new q},clearcoatNormalScale:{value:new K(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new q},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new q},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new q},sheen:{value:0},sheenColor:{value:new Z(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new q},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new q},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new q},transmissionSamplerSize:{value:new K},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new q},attenuationDistance:{value:0},attenuationColor:{value:new Z(0)},specularColor:{value:new Z(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new q},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new q},anisotropyVector:{value:new K},anisotropyMap:{value:null},anisotropyMapTransform:{value:new q}}]),vertexShader:Q.meshphysical_vert,fragmentShader:Q.meshphysical_frag};var Sr={r:0,b:0,g:0};function Cr(e,t,n,r,i,a,o){let s=new Z(0),c=a===!0?0:1,l,u,d=null,f=0,p=null;function m(a,m){let g=!1,_=m.isScene===!0?m.background:null;_&&_.isTexture&&(_=(m.backgroundBlurriness>0?n:t).get(_)),_===null?h(s,c):_&&_.isColor&&(h(_,1),g=!0);let v=e.xr.getEnvironmentBlendMode();v===`additive`?r.buffers.color.setClear(0,0,0,1,o):v===`alpha-blend`&&r.buffers.color.setClear(0,0,0,0,o),(e.autoClear||g)&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),_&&(_.isCubeTexture||_.mapping===306)?(u===void 0&&(u=new Kn(new Yn(1,1,1),new rr({name:`BackgroundCubeMaterial`,uniforms:Xn(xr.backgroundCube.uniforms),vertexShader:xr.backgroundCube.vertexShader,fragmentShader:xr.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1})),u.geometry.deleteAttribute(`normal`),u.geometry.deleteAttribute(`uv`),u.onBeforeRender=function(e,t,n){this.matrixWorld.copyPosition(n.matrixWorld)},Object.defineProperty(u.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(u)),u.material.uniforms.envMap.value=_,u.material.uniforms.flipEnvMap.value=_.isCubeTexture&&_.isRenderTargetTexture===!1?-1:1,u.material.uniforms.backgroundBlurriness.value=m.backgroundBlurriness,u.material.uniforms.backgroundIntensity.value=m.backgroundIntensity,u.material.toneMapped=Y.getTransfer(_.colorSpace)!==M,(d!==_||f!==_.version||p!==e.toneMapping)&&(u.material.needsUpdate=!0,d=_,f=_.version,p=e.toneMapping),u.layers.enableAll(),a.unshift(u,u.geometry,u.material,0,0,null)):_&&_.isTexture&&(l===void 0&&(l=new Kn(new br(2,2),new rr({name:`BackgroundMaterial`,uniforms:Xn(xr.background.uniforms),vertexShader:xr.background.vertexShader,fragmentShader:xr.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}}),i.update(l)),l.material.uniforms.t2D.value=_,l.material.uniforms.backgroundIntensity.value=m.backgroundIntensity,l.material.toneMapped=Y.getTransfer(_.colorSpace)!==M,_.matrixAutoUpdate===!0&&_.updateMatrix(),l.material.uniforms.uvTransform.value.copy(_.matrix),(d!==_||f!==_.version||p!==e.toneMapping)&&(l.material.needsUpdate=!0,d=_,f=_.version,p=e.toneMapping),l.layers.enableAll(),a.unshift(l,l.geometry,l.material,0,0,null))}function h(t,n){t.getRGB(Sr,$n(e)),r.buffers.color.setClear(Sr.r,Sr.g,Sr.b,n,o)}return{getClearColor:function(){return s},setClearColor:function(e,t=1){s.set(e),c=t,h(s,c)},getClearAlpha:function(){return c},setClearAlpha:function(e){c=e,h(s,c)},render:m}}function wr(e,t,n,r){let i=e.getParameter(e.MAX_VERTEX_ATTRIBS),a=r.isWebGL2?null:t.get(`OES_vertex_array_object`),o=r.isWebGL2||a!==null,s={},c=g(null),l=c,u=!1;function d(t,r,i,a,s){let c=!1;if(o){let e=h(a,i,r);l!==e&&(l=e,p(l.object)),c=_(t,a,i,s),c&&v(t,a,i,s)}else{let e=r.wireframe===!0;(l.geometry!==a.id||l.program!==i.id||l.wireframe!==e)&&(l.geometry=a.id,l.program=i.id,l.wireframe=e,c=!0)}s!==null&&n.update(s,e.ELEMENT_ARRAY_BUFFER),(c||u)&&(u=!1,w(t,r,i,a),s!==null&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,n.get(s).buffer))}function f(){return r.isWebGL2?e.createVertexArray():a.createVertexArrayOES()}function p(t){return r.isWebGL2?e.bindVertexArray(t):a.bindVertexArrayOES(t)}function m(t){return r.isWebGL2?e.deleteVertexArray(t):a.deleteVertexArrayOES(t)}function h(e,t,n){let r=n.wireframe===!0,i=s[e.id];i===void 0&&(i={},s[e.id]=i);let a=i[t.id];a===void 0&&(a={},i[t.id]=a);let o=a[r];return o===void 0&&(o=g(f()),a[r]=o),o}function g(e){let t=[],n=[],r=[];for(let e=0;e<i;e++)t[e]=0,n[e]=0,r[e]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:t,enabledAttributes:n,attributeDivisors:r,object:e,attributes:{},index:null}}function _(e,t,n,r){let i=l.attributes,a=t.attributes,o=0,s=n.getAttributes();for(let t in s)if(s[t].location>=0){let n=i[t],r=a[t];if(r===void 0&&(t===`instanceMatrix`&&e.instanceMatrix&&(r=e.instanceMatrix),t===`instanceColor`&&e.instanceColor&&(r=e.instanceColor)),n===void 0||n.attribute!==r||r&&n.data!==r.data)return!0;o++}return l.attributesNum!==o||l.index!==r}function v(e,t,n,r){let i={},a=t.attributes,o=0,s=n.getAttributes();for(let t in s)if(s[t].location>=0){let n=a[t];n===void 0&&(t===`instanceMatrix`&&e.instanceMatrix&&(n=e.instanceMatrix),t===`instanceColor`&&e.instanceColor&&(n=e.instanceColor));let r={};r.attribute=n,n&&n.data&&(r.data=n.data),i[t]=r,o++}l.attributes=i,l.attributesNum=o,l.index=r}function y(){let e=l.newAttributes;for(let t=0,n=e.length;t<n;t++)e[t]=0}function b(e){x(e,0)}function x(n,i){let a=l.newAttributes,o=l.enabledAttributes,s=l.attributeDivisors;a[n]=1,o[n]===0&&(e.enableVertexAttribArray(n),o[n]=1),s[n]!==i&&((r.isWebGL2?e:t.get(`ANGLE_instanced_arrays`))[r.isWebGL2?`vertexAttribDivisor`:`vertexAttribDivisorANGLE`](n,i),s[n]=i)}function S(){let t=l.newAttributes,n=l.enabledAttributes;for(let r=0,i=n.length;r<i;r++)n[r]!==t[r]&&(e.disableVertexAttribArray(r),n[r]=0)}function C(t,n,r,i,a,o,s){s===!0?e.vertexAttribIPointer(t,n,r,a,o):e.vertexAttribPointer(t,n,r,i,a,o)}function w(i,a,o,s){if(r.isWebGL2===!1&&(i.isInstancedMesh||s.isInstancedBufferGeometry)&&t.get(`ANGLE_instanced_arrays`)===null)return;y();let c=s.attributes,l=o.getAttributes(),u=a.defaultAttributeValues;for(let t in l){let a=l[t];if(a.location>=0){let o=c[t];if(o===void 0&&(t===`instanceMatrix`&&i.instanceMatrix&&(o=i.instanceMatrix),t===`instanceColor`&&i.instanceColor&&(o=i.instanceColor)),o!==void 0){let t=o.normalized,c=o.itemSize,l=n.get(o);if(l===void 0)continue;let u=l.buffer,d=l.type,f=l.bytesPerElement,p=r.isWebGL2===!0&&(d===e.INT||d===e.UNSIGNED_INT||o.gpuType===1013);if(o.isInterleavedBufferAttribute){let n=o.data,r=n.stride,l=o.offset;if(n.isInstancedInterleavedBuffer){for(let e=0;e<a.locationSize;e++)x(a.location+e,n.meshPerAttribute);i.isInstancedMesh!==!0&&s._maxInstanceCount===void 0&&(s._maxInstanceCount=n.meshPerAttribute*n.count)}else for(let e=0;e<a.locationSize;e++)b(a.location+e);e.bindBuffer(e.ARRAY_BUFFER,u);for(let e=0;e<a.locationSize;e++)C(a.location+e,c/a.locationSize,d,t,r*f,(l+c/a.locationSize*e)*f,p)}else{if(o.isInstancedBufferAttribute){for(let e=0;e<a.locationSize;e++)x(a.location+e,o.meshPerAttribute);i.isInstancedMesh!==!0&&s._maxInstanceCount===void 0&&(s._maxInstanceCount=o.meshPerAttribute*o.count)}else for(let e=0;e<a.locationSize;e++)b(a.location+e);e.bindBuffer(e.ARRAY_BUFFER,u);for(let e=0;e<a.locationSize;e++)C(a.location+e,c/a.locationSize,d,t,c*f,c/a.locationSize*e*f,p)}}else if(u!==void 0){let n=u[t];if(n!==void 0)switch(n.length){case 2:e.vertexAttrib2fv(a.location,n);break;case 3:e.vertexAttrib3fv(a.location,n);break;case 4:e.vertexAttrib4fv(a.location,n);break;default:e.vertexAttrib1fv(a.location,n)}}}}S()}function T(){O();for(let e in s){let t=s[e];for(let e in t){let n=t[e];for(let e in n)m(n[e].object),delete n[e];delete t[e]}delete s[e]}}function E(e){if(s[e.id]===void 0)return;let t=s[e.id];for(let e in t){let n=t[e];for(let e in n)m(n[e].object),delete n[e];delete t[e]}delete s[e.id]}function D(e){for(let t in s){let n=s[t];if(n[e.id]===void 0)continue;let r=n[e.id];for(let e in r)m(r[e].object),delete r[e];delete n[e.id]}}function O(){k(),u=!0,l!==c&&(l=c,p(l.object))}function k(){c.geometry=null,c.program=null,c.wireframe=!1}return{setup:d,reset:O,resetDefaultState:k,dispose:T,releaseStatesOfGeometry:E,releaseStatesOfProgram:D,initAttributes:y,enableAttribute:b,disableUnusedAttributes:S}}function Tr(e,t,n,r){let i=r.isWebGL2,a;function o(e){a=e}function s(t,r){e.drawArrays(a,t,r),n.update(r,a,1)}function c(r,o,s){if(s===0)return;let c,l;if(i)c=e,l=`drawArraysInstanced`;else if(c=t.get(`ANGLE_instanced_arrays`),l=`drawArraysInstancedANGLE`,c===null){console.error(`THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.`);return}c[l](a,r,o,s),n.update(o,a,s)}function l(e,r,i){if(i===0)return;let o=t.get(`WEBGL_multi_draw`);if(o===null)for(let t=0;t<i;t++)this.render(e[t],r[t]);else{o.multiDrawArraysWEBGL(a,e,0,r,0,i);let t=0;for(let e=0;e<i;e++)t+=r[e];n.update(t,a,1)}}this.setMode=o,this.render=s,this.renderInstances=c,this.renderMultiDraw=l}function Er(e,t,n){let r;function i(){if(r!==void 0)return r;if(t.has(`EXT_texture_filter_anisotropic`)===!0){let n=t.get(`EXT_texture_filter_anisotropic`);r=e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else r=0;return r}function a(t){if(t===`highp`){if(e.getShaderPrecisionFormat(e.VERTEX_SHADER,e.HIGH_FLOAT).precision>0&&e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0)return`highp`;t=`mediump`}return t===`mediump`&&e.getShaderPrecisionFormat(e.VERTEX_SHADER,e.MEDIUM_FLOAT).precision>0&&e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?`mediump`:`lowp`}let o=typeof WebGL2RenderingContext<`u`&&e.constructor.name===`WebGL2RenderingContext`,s=n.precision===void 0?`highp`:n.precision,c=a(s);c!==s&&(console.warn(`THREE.WebGLRenderer:`,s,`not supported, using`,c,`instead.`),s=c);let l=o||t.has(`WEBGL_draw_buffers`),u=n.logarithmicDepthBuffer===!0,d=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),f=e.getParameter(e.MAX_VERTEX_TEXTURE_IMAGE_UNITS),p=e.getParameter(e.MAX_TEXTURE_SIZE),m=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),h=e.getParameter(e.MAX_VERTEX_ATTRIBS),g=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),_=e.getParameter(e.MAX_VARYING_VECTORS),v=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),y=f>0,b=o||t.has(`OES_texture_float`),x=y&&b,S=o?e.getParameter(e.MAX_SAMPLES):0;return{isWebGL2:o,drawBuffers:l,getMaxAnisotropy:i,getMaxPrecision:a,precision:s,logarithmicDepthBuffer:u,maxTextures:d,maxVertexTextures:f,maxTextureSize:p,maxCubemapSize:m,maxAttributes:h,maxVertexUniforms:g,maxVaryings:_,maxFragmentUniforms:v,vertexTextures:y,floatFragmentTextures:b,floatVertexTextures:x,maxSamples:S}}function Dr(e){let t=this,n=null,r=0,i=!1,a=!1,o=new mr,s=new q,c={value:null,needsUpdate:!1};this.uniform=c,this.numPlanes=0,this.numIntersection=0,this.init=function(e,t){let n=e.length!==0||t||r!==0||i;return i=t,r=e.length,n},this.beginShadows=function(){a=!0,u(null)},this.endShadows=function(){a=!1},this.setGlobalState=function(e,t){n=u(e,t,0)},this.setState=function(t,o,s){let d=t.clippingPlanes,f=t.clipIntersection,p=t.clipShadows,m=e.get(t);if(!i||d===null||d.length===0||a&&!p)a?u(null):l();else{let e=a?0:r,t=e*4,i=m.clippingState||null;c.value=i,i=u(d,o,t,s);for(let e=0;e!==t;++e)i[e]=n[e];m.clippingState=i,this.numIntersection=f?this.numPlanes:0,this.numPlanes+=e}};function l(){c.value!==n&&(c.value=n,c.needsUpdate=r>0),t.numPlanes=r,t.numIntersection=0}function u(e,n,r,i){let a=e===null?0:e.length,l=null;if(a!==0){if(l=c.value,i!==!0||l===null){let t=r+a*4,i=n.matrixWorldInverse;s.getNormalMatrix(i),(l===null||l.length<t)&&(l=new Float32Array(t));for(let t=0,n=r;t!==a;++t,n+=4)o.copy(e[t]).applyMatrix4(i,s),o.normal.toArray(l,n),l[n+3]=o.constant}c.value=l,c.needsUpdate=!0}return t.numPlanes=a,t.numIntersection=0,l}}function Or(e){let t=new WeakMap;function n(e,t){return t===303?e.mapping=301:t===304&&(e.mapping=302),e}function r(r){if(r&&r.isTexture){let a=r.mapping;if(a===303||a===304)if(t.has(r)){let e=t.get(r).texture;return n(e,r.mapping)}else{let a=r.image;if(a&&a.height>0){let o=new ur(a.height/2);return o.fromEquirectangularTexture(e,r),t.set(r,o),r.addEventListener(`dispose`,i),n(o.texture,r.mapping)}else return null}}return r}function i(e){let n=e.target;n.removeEventListener(`dispose`,i);let r=t.get(n);r!==void 0&&(t.delete(n),r.dispose())}function a(){t=new WeakMap}return{get:r,dispose:a}}var kr=class extends ir{constructor(e=-1,t=1,n=1,r=-1,i=.1,a=2e3){super(),this.isOrthographicCamera=!0,this.type=`OrthographicCamera`,this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=n,this.bottom=r,this.near=i,this.far=a,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,n,r,i,a){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=r,this.view.width=i,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,r=(this.top+this.bottom)/2,i=n-e,a=n+e,o=r+t,s=r-t;if(this.view!==null&&this.view.enabled){let e=(this.right-this.left)/this.view.fullWidth/this.zoom,t=(this.top-this.bottom)/this.view.fullHeight/this.zoom;i+=e*this.view.offsetX,a=i+e*this.view.width,o-=t*this.view.offsetY,s=o-t*this.view.height}this.projectionMatrix.makeOrthographic(i,a,o,s,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){let t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}},Ar=4,jr=[.125,.215,.35,.446,.526,.582],Mr=20,Nr=new kr,Pr=new Z,Fr=null,Ir=0,Lr=0,Rr=(1+Math.sqrt(5))/2,zr=1/Rr,Br=[new X(1,1,1),new X(-1,1,1),new X(1,1,-1),new X(-1,1,-1),new X(0,Rr,zr),new X(0,Rr,-zr),new X(zr,0,Rr),new X(-zr,0,Rr),new X(Rr,zr,0),new X(-Rr,zr,0)],Vr=class{constructor(e){this._renderer=e,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(e,t=0,n=.1,r=100){Fr=this._renderer.getRenderTarget(),Ir=this._renderer.getActiveCubeFace(),Lr=this._renderer.getActiveMipmapLevel(),this._setSize(256);let i=this._allocateTargets();return i.depthBuffer=!0,this._sceneToCubeUV(e,n,r,i),t>0&&this._blur(i,0,0,t),this._applyPMREM(i),this._cleanup(i),i}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=qr(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=Kr(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose()}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=2**this._lodMax}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e<this._lodPlanes.length;e++)this._lodPlanes[e].dispose()}_cleanup(e){this._renderer.setRenderTarget(Fr,Ir,Lr),e.scissorTest=!1,Wr(e,0,0,e.width,e.height)}_fromTexture(e,t){e.mapping===301||e.mapping===302?this._setSize(e.image.length===0?16:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4),Fr=this._renderer.getRenderTarget(),Ir=this._renderer.getActiveCubeFace(),Lr=this._renderer.getActiveMipmapLevel();let n=t||this._allocateTargets();return this._textureToCubeUV(e,n),this._applyPMREM(n),this._cleanup(n),n}_allocateTargets(){let e=3*Math.max(this._cubeSize,112),t=4*this._cubeSize,n={magFilter:l,minFilter:l,generateMipmaps:!1,type:h,format:_,colorSpace:ee,depthBuffer:!1},r=Ur(e,t,n);if(this._pingPongRenderTarget===null||this._pingPongRenderTarget.width!==e||this._pingPongRenderTarget.height!==t){this._pingPongRenderTarget!==null&&this._dispose(),this._pingPongRenderTarget=Ur(e,t,n);let{_lodMax:r}=this;({sizeLods:this._sizeLods,lodPlanes:this._lodPlanes,sigmas:this._sigmas}=Hr(r)),this._blurMaterial=Gr(r,e,t)}return r}_compileMaterial(e){let t=new Kn(this._lodPlanes[0],e);this._renderer.compile(t,Nr)}_sceneToCubeUV(e,t,n,r){let i=new ar(90,1,t,n),a=[1,-1,1,1,1,1],o=[1,1,1,-1,-1,-1],s=this._renderer,c=s.autoClear,l=s.toneMapping;s.getClearColor(Pr),s.toneMapping=0,s.autoClear=!1;let u=new mn({name:`PMREM.Background`,side:1,depthWrite:!1,depthTest:!1}),d=new Kn(new Yn,u),f=!1,p=e.background;p?p.isColor&&(u.color.copy(p),e.background=null,f=!0):(u.color.copy(Pr),f=!0);for(let t=0;t<6;t++){let n=t%3;n===0?(i.up.set(0,a[t],0),i.lookAt(o[t],0,0)):n===1?(i.up.set(0,0,a[t]),i.lookAt(0,o[t],0)):(i.up.set(0,a[t],0),i.lookAt(0,0,o[t]));let c=this._cubeSize;Wr(r,n*c,t>2?c:0,c,c),s.setRenderTarget(r),f&&s.render(d,i),s.render(e,i)}d.geometry.dispose(),d.material.dispose(),s.toneMapping=l,s.autoClear=c,e.background=p}_textureToCubeUV(e,t){let n=this._renderer,r=e.mapping===301||e.mapping===302;r?(this._cubemapMaterial===null&&(this._cubemapMaterial=qr()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=Kr());let i=r?this._cubemapMaterial:this._equirectMaterial,a=new Kn(this._lodPlanes[0],i),o=i.uniforms;o.envMap.value=e;let s=this._cubeSize;Wr(t,0,0,3*s,2*s),n.setRenderTarget(t),n.render(a,Nr)}_applyPMREM(e){let t=this._renderer,n=t.autoClear;t.autoClear=!1;for(let t=1;t<this._lodPlanes.length;t++){let n=Math.sqrt(this._sigmas[t]*this._sigmas[t]-this._sigmas[t-1]*this._sigmas[t-1]),r=Br[(t-1)%Br.length];this._blur(e,t-1,t,n,r)}t.autoClear=n}_blur(e,t,n,r,i){let a=this._pingPongRenderTarget;this._halfBlur(e,a,t,n,r,`latitudinal`,i),this._halfBlur(a,e,n,n,r,`longitudinal`,i)}_halfBlur(e,t,n,r,i,a,o){let s=this._renderer,c=this._blurMaterial;a!==`latitudinal`&&a!==`longitudinal`&&console.error(`blur direction must be either latitudinal or longitudinal!`);let l=new Kn(this._lodPlanes[r],c),u=c.uniforms,d=this._sizeLods[n]-1,f=isFinite(i)?Math.PI/(2*d):2*Math.PI/(2*Mr-1),p=i/f,m=isFinite(i)?1+Math.floor(3*p):Mr;m>Mr&&console.warn(`sigmaRadians, ${i}, is too large and will clip, as it requested ${m} samples when the maximum is set to ${Mr}`);let h=[],g=0;for(let e=0;e<Mr;++e){let t=e/p,n=Math.exp(-t*t/2);h.push(n),e===0?g+=n:e<m&&(g+=2*n)}for(let e=0;e<h.length;e++)h[e]=h[e]/g;u.envMap.value=e.texture,u.samples.value=m,u.weights.value=h,u.latitudinal.value=a===`latitudinal`,o&&(u.poleAxis.value=o);let{_lodMax:_}=this;u.dTheta.value=f,u.mipInt.value=_-n;let v=this._sizeLods[r];Wr(t,3*v*(r>_-Ar?r-_+Ar:0),4*(this._cubeSize-v),3*v,2*v),s.setRenderTarget(t),s.render(l,Nr)}};function Hr(e){let t=[],n=[],r=[],i=e,a=e-Ar+1+jr.length;for(let o=0;o<a;o++){let a=2**i;n.push(a);let s=1/a;o>e-Ar?s=jr[o-e+Ar-1]:o===0&&(s=0),r.push(s);let c=1/(a-2),l=-c,u=1+c,d=[l,l,u,l,u,u,l,l,u,u,l,u],f=new Float32Array(108),p=new Float32Array(72),m=new Float32Array(36);for(let e=0;e<6;e++){let t=e%3*2/3-1,n=e>2?0:-1,r=[t,n,0,t+2/3,n,0,t+2/3,n+1,0,t,n,0,t+2/3,n+1,0,t,n+1,0];f.set(r,18*e),p.set(d,12*e);let i=[e,e,e,e,e,e];m.set(i,6*e)}let h=new On;h.setAttribute(`position`,new _n(f,3)),h.setAttribute(`uv`,new _n(p,2)),h.setAttribute(`faceIndex`,new _n(m,1)),t.push(h),i>Ar&&i--}return{lodPlanes:t,sizeLods:n,sigmas:r}}function Ur(e,t,n){let r=new Ue(e,t,n);return r.texture.mapping=306,r.texture.name=`PMREM.cubeUv`,r.scissorTest=!0,r}function Wr(e,t,n,r,i){e.viewport.set(t,n,r,i),e.scissor.set(t,n,r,i)}function Gr(e,t,n){let r=new Float32Array(Mr),i=new X(0,1,0);return new rr({name:`SphericalGaussianBlur`,defines:{n:Mr,CUBEUV_TEXEL_WIDTH:1/t,CUBEUV_TEXEL_HEIGHT:1/n,CUBEUV_MAX_MIP:`${e}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:r},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:i}},vertexShader:Jr(),fragmentShader:`
3434
+
3435
+ precision mediump float;
3436
+ precision mediump int;
3437
+
3438
+ varying vec3 vOutputDirection;
3439
+
3440
+ uniform sampler2D envMap;
3441
+ uniform int samples;
3442
+ uniform float weights[ n ];
3443
+ uniform bool latitudinal;
3444
+ uniform float dTheta;
3445
+ uniform float mipInt;
3446
+ uniform vec3 poleAxis;
3447
+
3448
+ #define ENVMAP_TYPE_CUBE_UV
3449
+ #include <cube_uv_reflection_fragment>
3450
+
3451
+ vec3 getSample( float theta, vec3 axis ) {
3452
+
3453
+ float cosTheta = cos( theta );
3454
+ // Rodrigues' axis-angle rotation
3455
+ vec3 sampleDirection = vOutputDirection * cosTheta
3456
+ + cross( axis, vOutputDirection ) * sin( theta )
3457
+ + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );
3458
+
3459
+ return bilinearCubeUV( envMap, sampleDirection, mipInt );
3460
+
3461
+ }
3462
+
3463
+ void main() {
3464
+
3465
+ vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );
3466
+
3467
+ if ( all( equal( axis, vec3( 0.0 ) ) ) ) {
3468
+
3469
+ axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );
3470
+
3471
+ }
3472
+
3473
+ axis = normalize( axis );
3474
+
3475
+ gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
3476
+ gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );
3477
+
3478
+ for ( int i = 1; i < n; i++ ) {
3479
+
3480
+ if ( i >= samples ) {
3481
+
3482
+ break;
3483
+
3484
+ }
3485
+
3486
+ float theta = dTheta * float( i );
3487
+ gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
3488
+ gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );
3489
+
3490
+ }
3491
+
3492
+ }
3493
+ `,blending:0,depthTest:!1,depthWrite:!1})}function Kr(){return new rr({name:`EquirectangularToCubeUV`,uniforms:{envMap:{value:null}},vertexShader:Jr(),fragmentShader:`
3494
+
3495
+ precision mediump float;
3496
+ precision mediump int;
3497
+
3498
+ varying vec3 vOutputDirection;
3499
+
3500
+ uniform sampler2D envMap;
3501
+
3502
+ #include <common>
3503
+
3504
+ void main() {
3505
+
3506
+ vec3 outputDirection = normalize( vOutputDirection );
3507
+ vec2 uv = equirectUv( outputDirection );
3508
+
3509
+ gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );
3510
+
3511
+ }
3512
+ `,blending:0,depthTest:!1,depthWrite:!1})}function qr(){return new rr({name:`CubemapToCubeUV`,uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:Jr(),fragmentShader:`
3513
+
3514
+ precision mediump float;
3515
+ precision mediump int;
3516
+
3517
+ uniform float flipEnvMap;
3518
+
3519
+ varying vec3 vOutputDirection;
3520
+
3521
+ uniform samplerCube envMap;
3522
+
3523
+ void main() {
3524
+
3525
+ gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );
3526
+
3527
+ }
3528
+ `,blending:0,depthTest:!1,depthWrite:!1})}function Jr(){return`
3529
+
3530
+ precision mediump float;
3531
+ precision mediump int;
3532
+
3533
+ attribute float faceIndex;
3534
+
3535
+ varying vec3 vOutputDirection;
3536
+
3537
+ // RH coordinate system; PMREM face-indexing convention
3538
+ vec3 getDirection( vec2 uv, float face ) {
3539
+
3540
+ uv = 2.0 * uv - 1.0;
3541
+
3542
+ vec3 direction = vec3( uv, 1.0 );
3543
+
3544
+ if ( face == 0.0 ) {
3545
+
3546
+ direction = direction.zyx; // ( 1, v, u ) pos x
3547
+
3548
+ } else if ( face == 1.0 ) {
3549
+
3550
+ direction = direction.xzy;
3551
+ direction.xz *= -1.0; // ( -u, 1, -v ) pos y
3552
+
3553
+ } else if ( face == 2.0 ) {
3554
+
3555
+ direction.x *= -1.0; // ( -u, v, 1 ) pos z
3556
+
3557
+ } else if ( face == 3.0 ) {
3558
+
3559
+ direction = direction.zyx;
3560
+ direction.xz *= -1.0; // ( -1, v, -u ) neg x
3561
+
3562
+ } else if ( face == 4.0 ) {
3563
+
3564
+ direction = direction.xzy;
3565
+ direction.xy *= -1.0; // ( -u, -1, v ) neg y
3566
+
3567
+ } else if ( face == 5.0 ) {
3568
+
3569
+ direction.z *= -1.0; // ( u, v, -1 ) neg z
3570
+
3571
+ }
3572
+
3573
+ return direction;
3574
+
3575
+ }
3576
+
3577
+ void main() {
3578
+
3579
+ vOutputDirection = getDirection( uv, faceIndex );
3580
+ gl_Position = vec4( position, 1.0 );
3581
+
3582
+ }
3583
+ `}function Yr(e){let t=new WeakMap,n=null;function r(r){if(r&&r.isTexture){let o=r.mapping,s=o===303||o===304,c=o===301||o===302;if(s||c)if(r.isRenderTargetTexture&&r.needsPMREMUpdate===!0){r.needsPMREMUpdate=!1;let i=t.get(r);return n===null&&(n=new Vr(e)),i=s?n.fromEquirectangular(r,i):n.fromCubemap(r,i),t.set(r,i),i.texture}else if(t.has(r))return t.get(r).texture;else{let o=r.image;if(s&&o&&o.height>0||c&&o&&i(o)){n===null&&(n=new Vr(e));let i=s?n.fromEquirectangular(r):n.fromCubemap(r);return t.set(r,i),r.addEventListener(`dispose`,a),i.texture}else return null}}return r}function i(e){let t=0;for(let n=0;n<6;n++)e[n]!==void 0&&t++;return t===6}function a(e){let n=e.target;n.removeEventListener(`dispose`,a);let r=t.get(n);r!==void 0&&(t.delete(n),r.dispose())}function o(){t=new WeakMap,n!==null&&(n.dispose(),n=null)}return{get:r,dispose:o}}function Xr(e){let t={};function n(n){if(t[n]!==void 0)return t[n];let r;switch(n){case`WEBGL_depth_texture`:r=e.getExtension(`WEBGL_depth_texture`)||e.getExtension(`MOZ_WEBGL_depth_texture`)||e.getExtension(`WEBKIT_WEBGL_depth_texture`);break;case`EXT_texture_filter_anisotropic`:r=e.getExtension(`EXT_texture_filter_anisotropic`)||e.getExtension(`MOZ_EXT_texture_filter_anisotropic`)||e.getExtension(`WEBKIT_EXT_texture_filter_anisotropic`);break;case`WEBGL_compressed_texture_s3tc`:r=e.getExtension(`WEBGL_compressed_texture_s3tc`)||e.getExtension(`MOZ_WEBGL_compressed_texture_s3tc`)||e.getExtension(`WEBKIT_WEBGL_compressed_texture_s3tc`);break;case`WEBGL_compressed_texture_pvrtc`:r=e.getExtension(`WEBGL_compressed_texture_pvrtc`)||e.getExtension(`WEBKIT_WEBGL_compressed_texture_pvrtc`);break;default:r=e.getExtension(n)}return t[n]=r,r}return{has:function(e){return n(e)!==null},init:function(e){e.isWebGL2?n(`EXT_color_buffer_float`):(n(`WEBGL_depth_texture`),n(`OES_texture_float`),n(`OES_texture_half_float`),n(`OES_texture_half_float_linear`),n(`OES_standard_derivatives`),n(`OES_element_index_uint`),n(`OES_vertex_array_object`),n(`ANGLE_instanced_arrays`)),n(`OES_texture_float_linear`),n(`EXT_color_buffer_half_float`),n(`WEBGL_multisampled_render_to_texture`)},get:function(e){let t=n(e);return t===null&&console.warn(`THREE.WebGLRenderer: `+e+` extension not supported.`),t}}}function Zr(e,t,n,r){let i={},a=new WeakMap;function o(e){let s=e.target;s.index!==null&&t.remove(s.index);for(let e in s.attributes)t.remove(s.attributes[e]);for(let e in s.morphAttributes){let n=s.morphAttributes[e];for(let e=0,r=n.length;e<r;e++)t.remove(n[e])}s.removeEventListener(`dispose`,o),delete i[s.id];let c=a.get(s);c&&(t.remove(c),a.delete(s)),r.releaseStatesOfGeometry(s),s.isInstancedBufferGeometry===!0&&delete s._maxInstanceCount,n.memory.geometries--}function s(e,t){return i[t.id]===!0?t:(t.addEventListener(`dispose`,o),i[t.id]=!0,n.memory.geometries++,t)}function c(n){let r=n.attributes;for(let n in r)t.update(r[n],e.ARRAY_BUFFER);let i=n.morphAttributes;for(let n in i){let r=i[n];for(let n=0,i=r.length;n<i;n++)t.update(r[n],e.ARRAY_BUFFER)}}function l(e){let n=[],r=e.index,i=e.attributes.position,o=0;if(r!==null){let e=r.array;o=r.version;for(let t=0,r=e.length;t<r;t+=3){let r=e[t+0],i=e[t+1],a=e[t+2];n.push(r,i,i,a,a,r)}}else if(i!==void 0){let e=i.array;o=i.version;for(let t=0,r=e.length/3-1;t<r;t+=3){let e=t+0,r=t+1,i=t+2;n.push(e,r,r,i,i,e)}}else return;let s=new(Ce(n)?yn:vn)(n,1);s.version=o;let c=a.get(e);c&&t.remove(c),a.set(e,s)}function u(e){let t=a.get(e);if(t){let n=e.index;n!==null&&t.version<n.version&&l(e)}else l(e);return a.get(e)}return{get:s,update:c,getWireframeAttribute:u}}function Qr(e,t,n,r){let i=r.isWebGL2,a;function o(e){a=e}let s,c;function l(e){s=e.type,c=e.bytesPerElement}function u(t,r){e.drawElements(a,r,s,t*c),n.update(r,a,1)}function d(r,o,l){if(l===0)return;let u,d;if(i)u=e,d=`drawElementsInstanced`;else if(u=t.get(`ANGLE_instanced_arrays`),d=`drawElementsInstancedANGLE`,u===null){console.error(`THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.`);return}u[d](a,o,s,r*c,l),n.update(o,a,l)}function f(e,r,i){if(i===0)return;let o=t.get(`WEBGL_multi_draw`);if(o===null)for(let t=0;t<i;t++)this.render(e[t]/c,r[t]);else{o.multiDrawElementsWEBGL(a,r,0,s,e,0,i);let t=0;for(let e=0;e<i;e++)t+=r[e];n.update(t,a,1)}}this.setMode=o,this.setIndex=l,this.render=u,this.renderInstances=d,this.renderMultiDraw=f}function $r(e){let t={geometries:0,textures:0},n={frame:0,calls:0,triangles:0,points:0,lines:0};function r(t,r,i){switch(n.calls++,r){case e.TRIANGLES:n.triangles+=t/3*i;break;case e.LINES:n.lines+=t/2*i;break;case e.LINE_STRIP:n.lines+=i*(t-1);break;case e.LINE_LOOP:n.lines+=i*t;break;case e.POINTS:n.points+=i*t;break;default:console.error(`THREE.WebGLInfo: Unknown draw mode:`,r);break}}function i(){n.calls=0,n.triangles=0,n.points=0,n.lines=0}return{memory:t,render:n,programs:null,autoReset:!0,reset:i,update:r}}function ei(e,t){return e[0]-t[0]}function ti(e,t){return Math.abs(t[1])-Math.abs(e[1])}function ni(e,t,n){let r={},i=new Float32Array(8),a=new WeakMap,o=new Ve,s=[];for(let e=0;e<8;e++)s[e]=[e,0];function c(c,l,u){let d=c.morphTargetInfluences;if(t.isWebGL2===!0){let r=l.morphAttributes.position||l.morphAttributes.normal||l.morphAttributes.color,i=r===void 0?0:r.length,s=a.get(l);if(s===void 0||s.count!==i){s!==void 0&&s.texture.dispose();let e=l.morphAttributes.position!==void 0,n=l.morphAttributes.normal!==void 0,r=l.morphAttributes.color!==void 0,c=l.morphAttributes.position||[],u=l.morphAttributes.normal||[],d=l.morphAttributes.color||[],p=0;e===!0&&(p=1),n===!0&&(p=2),r===!0&&(p=3);let h=l.attributes.position.count*p,g=1;h>t.maxTextureSize&&(g=Math.ceil(h/t.maxTextureSize),h=t.maxTextureSize);let _=new Float32Array(h*g*4*i),v=new We(_,h,g,i);v.type=m,v.needsUpdate=!0;let y=p*4;for(let t=0;t<i;t++){let i=c[t],a=u[t],s=d[t],l=h*g*4*t;for(let t=0;t<i.count;t++){let c=t*y;e===!0&&(o.fromBufferAttribute(i,t),_[l+c+0]=o.x,_[l+c+1]=o.y,_[l+c+2]=o.z,_[l+c+3]=0),n===!0&&(o.fromBufferAttribute(a,t),_[l+c+4]=o.x,_[l+c+5]=o.y,_[l+c+6]=o.z,_[l+c+7]=0),r===!0&&(o.fromBufferAttribute(s,t),_[l+c+8]=o.x,_[l+c+9]=o.y,_[l+c+10]=o.z,_[l+c+11]=s.itemSize===4?o.w:1)}}s={count:i,texture:v,size:new K(h,g)},a.set(l,s);function f(){v.dispose(),a.delete(l),l.removeEventListener(`dispose`,f)}l.addEventListener(`dispose`,f)}let c=0;for(let e=0;e<d.length;e++)c+=d[e];let p=l.morphTargetsRelative?1:1-c;u.getUniforms().setValue(e,`morphTargetBaseInfluence`,p),u.getUniforms().setValue(e,`morphTargetInfluences`,d),u.getUniforms().setValue(e,`morphTargetsTexture`,s.texture,n),u.getUniforms().setValue(e,`morphTargetsTextureSize`,s.size)}else{let t=d===void 0?0:d.length,n=r[l.id];if(n===void 0||n.length!==t){n=[];for(let e=0;e<t;e++)n[e]=[e,0];r[l.id]=n}for(let e=0;e<t;e++){let t=n[e];t[0]=e,t[1]=d[e]}n.sort(ti);for(let e=0;e<8;e++)e<t&&n[e][1]?(s[e][0]=n[e][0],s[e][1]=n[e][1]):(s[e][0]=2**53-1,s[e][1]=0);s.sort(ei);let a=l.morphAttributes.position,o=l.morphAttributes.normal,c=0;for(let e=0;e<8;e++){let t=s[e],n=t[0],r=t[1];n!==2**53-1&&r?(a&&l.getAttribute(`morphTarget`+e)!==a[n]&&l.setAttribute(`morphTarget`+e,a[n]),o&&l.getAttribute(`morphNormal`+e)!==o[n]&&l.setAttribute(`morphNormal`+e,o[n]),i[e]=r,c+=r):(a&&l.hasAttribute(`morphTarget`+e)===!0&&l.deleteAttribute(`morphTarget`+e),o&&l.hasAttribute(`morphNormal`+e)===!0&&l.deleteAttribute(`morphNormal`+e),i[e]=0)}let f=l.morphTargetsRelative?1:1-c;u.getUniforms().setValue(e,`morphTargetBaseInfluence`,f),u.getUniforms().setValue(e,`morphTargetInfluences`,i)}}return{update:c}}function ri(e,t,n,r){let i=new WeakMap;function a(a){let o=r.render.frame,c=a.geometry,l=t.get(a,c);if(i.get(l)!==o&&(t.update(l),i.set(l,o)),a.isInstancedMesh&&(a.hasEventListener(`dispose`,s)===!1&&a.addEventListener(`dispose`,s),i.get(a)!==o&&(n.update(a.instanceMatrix,e.ARRAY_BUFFER),a.instanceColor!==null&&n.update(a.instanceColor,e.ARRAY_BUFFER),i.set(a,o))),a.isSkinnedMesh){let e=a.skeleton;i.get(e)!==o&&(e.update(),i.set(e,o))}return l}function o(){i=new WeakMap}function s(e){let t=e.target;t.removeEventListener(`dispose`,s),n.remove(t.instanceMatrix),t.instanceColor!==null&&n.remove(t.instanceColor)}return{update:a,dispose:o}}var ii=class extends Be{constructor(e,t,n,r,i,a,s,c,l,u){if(u=u===void 0?v:u,u!==1026&&u!==1027)throw Error(`DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat`);n===void 0&&u===1026&&(n=p),n===void 0&&u===1027&&(n=g),super(null,r,i,a,s,c,u,n,l),this.isDepthTexture=!0,this.image={width:e,height:t},this.magFilter=s===void 0?o:s,this.minFilter=c===void 0?o:c,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.compareFunction=e.compareFunction,this}toJSON(e){let t=super.toJSON(e);return this.compareFunction!==null&&(t.compareFunction=this.compareFunction),t}},ai=new Be,oi=new ii(1,1);oi.compareFunction=515;var si=new We,ci=new Ge,li=new lr,ui=[],di=[],fi=new Float32Array(16),pi=new Float32Array(9),mi=new Float32Array(4);function hi(e,t,n){let r=e[0];if(r<=0||r>0)return e;let i=t*n,a=ui[i];if(a===void 0&&(a=new Float32Array(i),ui[i]=a),t!==0){r.toArray(a,0);for(let r=1,i=0;r!==t;++r)i+=n,e[r].toArray(a,i)}return a}function gi(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}function _i(e,t){for(let n=0,r=t.length;n<r;n++)e[n]=t[n]}function vi(e,t){let n=di[t];n===void 0&&(n=new Int32Array(t),di[t]=n);for(let r=0;r!==t;++r)n[r]=e.allocateTextureUnit();return n}function yi(e,t){let n=this.cache;n[0]!==t&&(e.uniform1f(this.addr,t),n[0]=t)}function bi(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y)&&(e.uniform2f(this.addr,t.x,t.y),n[0]=t.x,n[1]=t.y);else{if(gi(n,t))return;e.uniform2fv(this.addr,t),_i(n,t)}}function xi(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z)&&(e.uniform3f(this.addr,t.x,t.y,t.z),n[0]=t.x,n[1]=t.y,n[2]=t.z);else if(t.r!==void 0)(n[0]!==t.r||n[1]!==t.g||n[2]!==t.b)&&(e.uniform3f(this.addr,t.r,t.g,t.b),n[0]=t.r,n[1]=t.g,n[2]=t.b);else{if(gi(n,t))return;e.uniform3fv(this.addr,t),_i(n,t)}}function Si(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z||n[3]!==t.w)&&(e.uniform4f(this.addr,t.x,t.y,t.z,t.w),n[0]=t.x,n[1]=t.y,n[2]=t.z,n[3]=t.w);else{if(gi(n,t))return;e.uniform4fv(this.addr,t),_i(n,t)}}function Ci(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(gi(n,t))return;e.uniformMatrix2fv(this.addr,!1,t),_i(n,t)}else{if(gi(n,r))return;mi.set(r),e.uniformMatrix2fv(this.addr,!1,mi),_i(n,r)}}function wi(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(gi(n,t))return;e.uniformMatrix3fv(this.addr,!1,t),_i(n,t)}else{if(gi(n,r))return;pi.set(r),e.uniformMatrix3fv(this.addr,!1,pi),_i(n,r)}}function Ti(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(gi(n,t))return;e.uniformMatrix4fv(this.addr,!1,t),_i(n,t)}else{if(gi(n,r))return;fi.set(r),e.uniformMatrix4fv(this.addr,!1,fi),_i(n,r)}}function Ei(e,t){let n=this.cache;n[0]!==t&&(e.uniform1i(this.addr,t),n[0]=t)}function Di(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y)&&(e.uniform2i(this.addr,t.x,t.y),n[0]=t.x,n[1]=t.y);else{if(gi(n,t))return;e.uniform2iv(this.addr,t),_i(n,t)}}function Oi(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z)&&(e.uniform3i(this.addr,t.x,t.y,t.z),n[0]=t.x,n[1]=t.y,n[2]=t.z);else{if(gi(n,t))return;e.uniform3iv(this.addr,t),_i(n,t)}}function ki(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z||n[3]!==t.w)&&(e.uniform4i(this.addr,t.x,t.y,t.z,t.w),n[0]=t.x,n[1]=t.y,n[2]=t.z,n[3]=t.w);else{if(gi(n,t))return;e.uniform4iv(this.addr,t),_i(n,t)}}function Ai(e,t){let n=this.cache;n[0]!==t&&(e.uniform1ui(this.addr,t),n[0]=t)}function ji(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y)&&(e.uniform2ui(this.addr,t.x,t.y),n[0]=t.x,n[1]=t.y);else{if(gi(n,t))return;e.uniform2uiv(this.addr,t),_i(n,t)}}function Mi(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z)&&(e.uniform3ui(this.addr,t.x,t.y,t.z),n[0]=t.x,n[1]=t.y,n[2]=t.z);else{if(gi(n,t))return;e.uniform3uiv(this.addr,t),_i(n,t)}}function Ni(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z||n[3]!==t.w)&&(e.uniform4ui(this.addr,t.x,t.y,t.z,t.w),n[0]=t.x,n[1]=t.y,n[2]=t.z,n[3]=t.w);else{if(gi(n,t))return;e.uniform4uiv(this.addr,t),_i(n,t)}}function Pi(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i);let a=this.type===e.SAMPLER_2D_SHADOW?oi:ai;n.setTexture2D(t||a,i)}function Fi(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i),n.setTexture3D(t||ci,i)}function Ii(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i),n.setTextureCube(t||li,i)}function Li(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i),n.setTexture2DArray(t||si,i)}function Ri(e){switch(e){case 5126:return yi;case 35664:return bi;case 35665:return xi;case 35666:return Si;case 35674:return Ci;case 35675:return wi;case 35676:return Ti;case 5124:case 35670:return Ei;case 35667:case 35671:return Di;case 35668:case 35672:return Oi;case 35669:case 35673:return ki;case 5125:return Ai;case 36294:return ji;case 36295:return Mi;case 36296:return Ni;case 35678:case 36198:case 36298:case 36306:case 35682:return Pi;case 35679:case 36299:case 36307:return Fi;case 35680:case 36300:case 36308:case 36293:return Ii;case 36289:case 36303:case 36311:case 36292:return Li}}function zi(e,t){e.uniform1fv(this.addr,t)}function Bi(e,t){let n=hi(t,this.size,2);e.uniform2fv(this.addr,n)}function Vi(e,t){let n=hi(t,this.size,3);e.uniform3fv(this.addr,n)}function Hi(e,t){let n=hi(t,this.size,4);e.uniform4fv(this.addr,n)}function Ui(e,t){let n=hi(t,this.size,4);e.uniformMatrix2fv(this.addr,!1,n)}function Wi(e,t){let n=hi(t,this.size,9);e.uniformMatrix3fv(this.addr,!1,n)}function Gi(e,t){let n=hi(t,this.size,16);e.uniformMatrix4fv(this.addr,!1,n)}function Ki(e,t){e.uniform1iv(this.addr,t)}function qi(e,t){e.uniform2iv(this.addr,t)}function Ji(e,t){e.uniform3iv(this.addr,t)}function Yi(e,t){e.uniform4iv(this.addr,t)}function Xi(e,t){e.uniform1uiv(this.addr,t)}function Zi(e,t){e.uniform2uiv(this.addr,t)}function Qi(e,t){e.uniform3uiv(this.addr,t)}function $i(e,t){e.uniform4uiv(this.addr,t)}function ea(e,t,n){let r=this.cache,i=t.length,a=vi(n,i);gi(r,a)||(e.uniform1iv(this.addr,a),_i(r,a));for(let e=0;e!==i;++e)n.setTexture2D(t[e]||ai,a[e])}function ta(e,t,n){let r=this.cache,i=t.length,a=vi(n,i);gi(r,a)||(e.uniform1iv(this.addr,a),_i(r,a));for(let e=0;e!==i;++e)n.setTexture3D(t[e]||ci,a[e])}function na(e,t,n){let r=this.cache,i=t.length,a=vi(n,i);gi(r,a)||(e.uniform1iv(this.addr,a),_i(r,a));for(let e=0;e!==i;++e)n.setTextureCube(t[e]||li,a[e])}function ra(e,t,n){let r=this.cache,i=t.length,a=vi(n,i);gi(r,a)||(e.uniform1iv(this.addr,a),_i(r,a));for(let e=0;e!==i;++e)n.setTexture2DArray(t[e]||si,a[e])}function ia(e){switch(e){case 5126:return zi;case 35664:return Bi;case 35665:return Vi;case 35666:return Hi;case 35674:return Ui;case 35675:return Wi;case 35676:return Gi;case 5124:case 35670:return Ki;case 35667:case 35671:return qi;case 35668:case 35672:return Ji;case 35669:case 35673:return Yi;case 5125:return Xi;case 36294:return Zi;case 36295:return Qi;case 36296:return $i;case 35678:case 36198:case 36298:case 36306:case 35682:return ea;case 35679:case 36299:case 36307:return ta;case 35680:case 36300:case 36308:case 36293:return na;case 36289:case 36303:case 36311:case 36292:return ra}}var aa=class{constructor(e,t,n){this.id=e,this.addr=n,this.cache=[],this.type=t.type,this.setValue=Ri(t.type)}},oa=class{constructor(e,t,n){this.id=e,this.addr=n,this.cache=[],this.type=t.type,this.size=t.size,this.setValue=ia(t.type)}},sa=class{constructor(e){this.id=e,this.seq=[],this.map={}}setValue(e,t,n){let r=this.seq;for(let i=0,a=r.length;i!==a;++i){let a=r[i];a.setValue(e,t[a.id],n)}}},ca=/(\w+)(\])?(\[|\.)?/g;function la(e,t){e.seq.push(t),e.map[t.id]=t}function ua(e,t,n){let r=e.name,i=r.length;for(ca.lastIndex=0;;){let a=ca.exec(r),o=ca.lastIndex,s=a[1],c=a[2]===`]`,l=a[3];if(c&&(s|=0),l===void 0||l===`[`&&o+2===i){la(n,l===void 0?new aa(s,e,t):new oa(s,e,t));break}else{let e=n.map[s];e===void 0&&(e=new sa(s),la(n,e)),n=e}}}var da=class{constructor(e,t){this.seq=[],this.map={};let n=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let r=0;r<n;++r){let n=e.getActiveUniform(t,r);ua(n,e.getUniformLocation(t,n.name),this)}}setValue(e,t,n,r){let i=this.map[t];i!==void 0&&i.setValue(e,n,r)}setOptional(e,t,n){let r=t[n];r!==void 0&&this.setValue(e,n,r)}static upload(e,t,n,r){for(let i=0,a=t.length;i!==a;++i){let a=t[i],o=n[a.id];o.needsUpdate!==!1&&a.setValue(e,o.value,r)}}static seqWithValue(e,t){let n=[];for(let r=0,i=e.length;r!==i;++r){let i=e[r];i.id in t&&n.push(i)}return n}};function fa(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}var pa=37297,ma=0;function ha(e,t){let n=e.split(`
3584
+ `),r=[],i=Math.max(t-6,0),a=Math.min(t+6,n.length);for(let e=i;e<a;e++){let i=e+1;r.push(`${i===t?`>`:` `} ${i}: ${n[e]}`)}return r.join(`
3585
+ `)}function ga(e){let t=Y.getPrimaries(Y.workingColorSpace),n=Y.getPrimaries(e),r;switch(t===n?r=``:t===`p3`&&n===`rec709`?r=`LinearDisplayP3ToLinearSRGB`:t===`rec709`&&n===`p3`&&(r=`LinearSRGBToLinearDisplayP3`),e){case ee:case j:return[r,`LinearTransferOETF`];case A:case te:return[r,`sRGBTransferOETF`];default:return console.warn(`THREE.WebGLProgram: Unsupported color space:`,e),[r,`LinearTransferOETF`]}}function _a(e,t,n){let r=e.getShaderParameter(t,e.COMPILE_STATUS),i=e.getShaderInfoLog(t).trim();if(r&&i===``)return``;let a=/ERROR: 0:(\d+)/.exec(i);if(a){let r=parseInt(a[1]);return n.toUpperCase()+`
3586
+
3587
+ `+i+`
3588
+
3589
+ `+ha(e.getShaderSource(t),r)}else return i}function va(e,t){let n=ga(t);return`vec4 ${e}( vec4 value ) { return ${n[0]}( ${n[1]}( value ) ); }`}function ya(e,t){let n;switch(t){case 1:n=`Linear`;break;case 2:n=`Reinhard`;break;case 3:n=`OptimizedCineon`;break;case 4:n=`ACESFilmic`;break;case 5:n=`Custom`;break;default:console.warn(`THREE.WebGLProgram: Unsupported toneMapping:`,t),n=`Linear`}return`vec3 `+e+`( vec3 color ) { return `+n+`ToneMapping( color ); }`}function ba(e){return[e.extensionDerivatives||e.envMapCubeUVHeight||e.bumpMap||e.normalMapTangentSpace||e.clearcoatNormalMap||e.flatShading||e.shaderID===`physical`?`#extension GL_OES_standard_derivatives : enable`:``,(e.extensionFragDepth||e.logarithmicDepthBuffer)&&e.rendererExtensionFragDepth?`#extension GL_EXT_frag_depth : enable`:``,e.extensionDrawBuffers&&e.rendererExtensionDrawBuffers?`#extension GL_EXT_draw_buffers : require`:``,(e.extensionShaderTextureLOD||e.envMap||e.transmission)&&e.rendererExtensionShaderTextureLod?`#extension GL_EXT_shader_texture_lod : enable`:``].filter(Ca).join(`
3590
+ `)}function xa(e){let t=[];for(let n in e){let r=e[n];r!==!1&&t.push(`#define `+n+` `+r)}return t.join(`
3591
+ `)}function Sa(e,t){let n={},r=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let i=0;i<r;i++){let r=e.getActiveAttrib(t,i),a=r.name,o=1;r.type===e.FLOAT_MAT2&&(o=2),r.type===e.FLOAT_MAT3&&(o=3),r.type===e.FLOAT_MAT4&&(o=4),n[a]={type:r.type,location:e.getAttribLocation(t,a),locationSize:o}}return n}function Ca(e){return e!==``}function wa(e,t){let n=t.numSpotLightShadows+t.numSpotLightMaps-t.numSpotLightShadowsWithMaps;return e.replace(/NUM_DIR_LIGHTS/g,t.numDirLights).replace(/NUM_SPOT_LIGHTS/g,t.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,t.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,n).replace(/NUM_RECT_AREA_LIGHTS/g,t.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,t.numPointLights).replace(/NUM_HEMI_LIGHTS/g,t.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,t.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,t.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,t.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,t.numPointLightShadows)}function Ta(e,t){return e.replace(/NUM_CLIPPING_PLANES/g,t.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,t.numClippingPlanes-t.numClipIntersection)}var Ea=/^[ \t]*#include +<([\w\d./]+)>/gm;function Da(e){return e.replace(Ea,ka)}var Oa=new Map([[`encodings_fragment`,`colorspace_fragment`],[`encodings_pars_fragment`,`colorspace_pars_fragment`],[`output_fragment`,`opaque_fragment`]]);function ka(e,t){let n=Q[t];if(n===void 0){let e=Oa.get(t);if(e!==void 0)n=Q[e],console.warn(`THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.`,t,e);else throw Error(`Can not resolve #include <`+t+`>`)}return Da(n)}var Aa=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function ja(e){return e.replace(Aa,Ma)}function Ma(e,t,n,r){let i=``;for(let e=parseInt(t);e<parseInt(n);e++)i+=r.replace(/\[\s*i\s*\]/g,`[ `+e+` ]`).replace(/UNROLLED_LOOP_INDEX/g,e);return i}function Na(e){let t=`precision `+e.precision+` float;
3592
+ precision `+e.precision+` int;`;return e.precision===`highp`?t+=`
3593
+ #define HIGH_PRECISION`:e.precision===`mediump`?t+=`
3594
+ #define MEDIUM_PRECISION`:e.precision===`lowp`&&(t+=`
3595
+ #define LOW_PRECISION`),t}function Pa(e){let t=`SHADOWMAP_TYPE_BASIC`;return e.shadowMapType===1?t=`SHADOWMAP_TYPE_PCF`:e.shadowMapType===2?t=`SHADOWMAP_TYPE_PCF_SOFT`:e.shadowMapType===3&&(t=`SHADOWMAP_TYPE_VSM`),t}function Fa(e){let t=`ENVMAP_TYPE_CUBE`;if(e.envMap)switch(e.envMapMode){case 301:case 302:t=`ENVMAP_TYPE_CUBE`;break;case 306:t=`ENVMAP_TYPE_CUBE_UV`;break}return t}function Ia(e){let t=`ENVMAP_MODE_REFLECTION`;if(e.envMap)switch(e.envMapMode){case 302:t=`ENVMAP_MODE_REFRACTION`;break}return t}function La(e){let t=`ENVMAP_BLENDING_NONE`;if(e.envMap)switch(e.combine){case 0:t=`ENVMAP_BLENDING_MULTIPLY`;break;case 1:t=`ENVMAP_BLENDING_MIX`;break;case 2:t=`ENVMAP_BLENDING_ADD`;break}return t}function Ra(e){let t=e.envMapCubeUVHeight;if(t===null)return null;let n=Math.log2(t)-2,r=1/t;return{texelWidth:1/(3*Math.max(2**n,112)),texelHeight:r,maxMip:n}}function za(e,t,n,r){let i=e.getContext(),a=n.defines,o=n.vertexShader,s=n.fragmentShader,c=Pa(n),l=Fa(n),u=Ia(n),d=La(n),f=Ra(n),p=n.isWebGL2?``:ba(n),m=xa(a),h=i.createProgram(),g,_,v=n.glslVersion?`#version `+n.glslVersion+`
3596
+ `:``;n.isRawShaderMaterial?(g=[`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,m].filter(Ca).join(`
3597
+ `),g.length>0&&(g+=`
3598
+ `),_=[p,`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,m].filter(Ca).join(`
3599
+ `),_.length>0&&(_+=`
3600
+ `)):(g=[Na(n),`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,m,n.batching?`#define USE_BATCHING`:``,n.instancing?`#define USE_INSTANCING`:``,n.instancingColor?`#define USE_INSTANCING_COLOR`:``,n.useFog&&n.fog?`#define USE_FOG`:``,n.useFog&&n.fogExp2?`#define FOG_EXP2`:``,n.map?`#define USE_MAP`:``,n.envMap?`#define USE_ENVMAP`:``,n.envMap?`#define `+u:``,n.lightMap?`#define USE_LIGHTMAP`:``,n.aoMap?`#define USE_AOMAP`:``,n.bumpMap?`#define USE_BUMPMAP`:``,n.normalMap?`#define USE_NORMALMAP`:``,n.normalMapObjectSpace?`#define USE_NORMALMAP_OBJECTSPACE`:``,n.normalMapTangentSpace?`#define USE_NORMALMAP_TANGENTSPACE`:``,n.displacementMap?`#define USE_DISPLACEMENTMAP`:``,n.emissiveMap?`#define USE_EMISSIVEMAP`:``,n.anisotropy?`#define USE_ANISOTROPY`:``,n.anisotropyMap?`#define USE_ANISOTROPYMAP`:``,n.clearcoatMap?`#define USE_CLEARCOATMAP`:``,n.clearcoatRoughnessMap?`#define USE_CLEARCOAT_ROUGHNESSMAP`:``,n.clearcoatNormalMap?`#define USE_CLEARCOAT_NORMALMAP`:``,n.iridescenceMap?`#define USE_IRIDESCENCEMAP`:``,n.iridescenceThicknessMap?`#define USE_IRIDESCENCE_THICKNESSMAP`:``,n.specularMap?`#define USE_SPECULARMAP`:``,n.specularColorMap?`#define USE_SPECULAR_COLORMAP`:``,n.specularIntensityMap?`#define USE_SPECULAR_INTENSITYMAP`:``,n.roughnessMap?`#define USE_ROUGHNESSMAP`:``,n.metalnessMap?`#define USE_METALNESSMAP`:``,n.alphaMap?`#define USE_ALPHAMAP`:``,n.alphaHash?`#define USE_ALPHAHASH`:``,n.transmission?`#define USE_TRANSMISSION`:``,n.transmissionMap?`#define USE_TRANSMISSIONMAP`:``,n.thicknessMap?`#define USE_THICKNESSMAP`:``,n.sheenColorMap?`#define USE_SHEEN_COLORMAP`:``,n.sheenRoughnessMap?`#define USE_SHEEN_ROUGHNESSMAP`:``,n.mapUv?`#define MAP_UV `+n.mapUv:``,n.alphaMapUv?`#define ALPHAMAP_UV `+n.alphaMapUv:``,n.lightMapUv?`#define LIGHTMAP_UV `+n.lightMapUv:``,n.aoMapUv?`#define AOMAP_UV `+n.aoMapUv:``,n.emissiveMapUv?`#define EMISSIVEMAP_UV `+n.emissiveMapUv:``,n.bumpMapUv?`#define BUMPMAP_UV `+n.bumpMapUv:``,n.normalMapUv?`#define NORMALMAP_UV `+n.normalMapUv:``,n.displacementMapUv?`#define DISPLACEMENTMAP_UV `+n.displacementMapUv:``,n.metalnessMapUv?`#define METALNESSMAP_UV `+n.metalnessMapUv:``,n.roughnessMapUv?`#define ROUGHNESSMAP_UV `+n.roughnessMapUv:``,n.anisotropyMapUv?`#define ANISOTROPYMAP_UV `+n.anisotropyMapUv:``,n.clearcoatMapUv?`#define CLEARCOATMAP_UV `+n.clearcoatMapUv:``,n.clearcoatNormalMapUv?`#define CLEARCOAT_NORMALMAP_UV `+n.clearcoatNormalMapUv:``,n.clearcoatRoughnessMapUv?`#define CLEARCOAT_ROUGHNESSMAP_UV `+n.clearcoatRoughnessMapUv:``,n.iridescenceMapUv?`#define IRIDESCENCEMAP_UV `+n.iridescenceMapUv:``,n.iridescenceThicknessMapUv?`#define IRIDESCENCE_THICKNESSMAP_UV `+n.iridescenceThicknessMapUv:``,n.sheenColorMapUv?`#define SHEEN_COLORMAP_UV `+n.sheenColorMapUv:``,n.sheenRoughnessMapUv?`#define SHEEN_ROUGHNESSMAP_UV `+n.sheenRoughnessMapUv:``,n.specularMapUv?`#define SPECULARMAP_UV `+n.specularMapUv:``,n.specularColorMapUv?`#define SPECULAR_COLORMAP_UV `+n.specularColorMapUv:``,n.specularIntensityMapUv?`#define SPECULAR_INTENSITYMAP_UV `+n.specularIntensityMapUv:``,n.transmissionMapUv?`#define TRANSMISSIONMAP_UV `+n.transmissionMapUv:``,n.thicknessMapUv?`#define THICKNESSMAP_UV `+n.thicknessMapUv:``,n.vertexTangents&&n.flatShading===!1?`#define USE_TANGENT`:``,n.vertexColors?`#define USE_COLOR`:``,n.vertexAlphas?`#define USE_COLOR_ALPHA`:``,n.vertexUv1s?`#define USE_UV1`:``,n.vertexUv2s?`#define USE_UV2`:``,n.vertexUv3s?`#define USE_UV3`:``,n.pointsUvs?`#define USE_POINTS_UV`:``,n.flatShading?`#define FLAT_SHADED`:``,n.skinning?`#define USE_SKINNING`:``,n.morphTargets?`#define USE_MORPHTARGETS`:``,n.morphNormals&&n.flatShading===!1?`#define USE_MORPHNORMALS`:``,n.morphColors&&n.isWebGL2?`#define USE_MORPHCOLORS`:``,n.morphTargetsCount>0&&n.isWebGL2?`#define MORPHTARGETS_TEXTURE`:``,n.morphTargetsCount>0&&n.isWebGL2?`#define MORPHTARGETS_TEXTURE_STRIDE `+n.morphTextureStride:``,n.morphTargetsCount>0&&n.isWebGL2?`#define MORPHTARGETS_COUNT `+n.morphTargetsCount:``,n.doubleSided?`#define DOUBLE_SIDED`:``,n.flipSided?`#define FLIP_SIDED`:``,n.shadowMapEnabled?`#define USE_SHADOWMAP`:``,n.shadowMapEnabled?`#define `+c:``,n.sizeAttenuation?`#define USE_SIZEATTENUATION`:``,n.numLightProbes>0?`#define USE_LIGHT_PROBES`:``,n.useLegacyLights?`#define LEGACY_LIGHTS`:``,n.logarithmicDepthBuffer?`#define USE_LOGDEPTHBUF`:``,n.logarithmicDepthBuffer&&n.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`,` attribute mat4 instanceMatrix;`,`#endif`,`#ifdef USE_INSTANCING_COLOR`,` attribute vec3 instanceColor;`,`#endif`,`attribute vec3 position;`,`attribute vec3 normal;`,`attribute vec2 uv;`,`#ifdef USE_UV1`,` attribute vec2 uv1;`,`#endif`,`#ifdef USE_UV2`,` attribute vec2 uv2;`,`#endif`,`#ifdef USE_UV3`,` attribute vec2 uv3;`,`#endif`,`#ifdef USE_TANGENT`,` attribute vec4 tangent;`,`#endif`,`#if defined( USE_COLOR_ALPHA )`,` attribute vec4 color;`,`#elif defined( USE_COLOR )`,` attribute vec3 color;`,`#endif`,`#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )`,` attribute vec3 morphTarget0;`,` attribute vec3 morphTarget1;`,` attribute vec3 morphTarget2;`,` attribute vec3 morphTarget3;`,` #ifdef USE_MORPHNORMALS`,` attribute vec3 morphNormal0;`,` attribute vec3 morphNormal1;`,` attribute vec3 morphNormal2;`,` attribute vec3 morphNormal3;`,` #else`,` attribute vec3 morphTarget4;`,` attribute vec3 morphTarget5;`,` attribute vec3 morphTarget6;`,` attribute vec3 morphTarget7;`,` #endif`,`#endif`,`#ifdef USE_SKINNING`,` attribute vec4 skinIndex;`,` attribute vec4 skinWeight;`,`#endif`,`
3601
+ `].filter(Ca).join(`
3602
+ `),_=[p,Na(n),`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,m,n.useFog&&n.fog?`#define USE_FOG`:``,n.useFog&&n.fogExp2?`#define FOG_EXP2`:``,n.map?`#define USE_MAP`:``,n.matcap?`#define USE_MATCAP`:``,n.envMap?`#define USE_ENVMAP`:``,n.envMap?`#define `+l:``,n.envMap?`#define `+u:``,n.envMap?`#define `+d:``,f?`#define CUBEUV_TEXEL_WIDTH `+f.texelWidth:``,f?`#define CUBEUV_TEXEL_HEIGHT `+f.texelHeight:``,f?`#define CUBEUV_MAX_MIP `+f.maxMip+`.0`:``,n.lightMap?`#define USE_LIGHTMAP`:``,n.aoMap?`#define USE_AOMAP`:``,n.bumpMap?`#define USE_BUMPMAP`:``,n.normalMap?`#define USE_NORMALMAP`:``,n.normalMapObjectSpace?`#define USE_NORMALMAP_OBJECTSPACE`:``,n.normalMapTangentSpace?`#define USE_NORMALMAP_TANGENTSPACE`:``,n.emissiveMap?`#define USE_EMISSIVEMAP`:``,n.anisotropy?`#define USE_ANISOTROPY`:``,n.anisotropyMap?`#define USE_ANISOTROPYMAP`:``,n.clearcoat?`#define USE_CLEARCOAT`:``,n.clearcoatMap?`#define USE_CLEARCOATMAP`:``,n.clearcoatRoughnessMap?`#define USE_CLEARCOAT_ROUGHNESSMAP`:``,n.clearcoatNormalMap?`#define USE_CLEARCOAT_NORMALMAP`:``,n.iridescence?`#define USE_IRIDESCENCE`:``,n.iridescenceMap?`#define USE_IRIDESCENCEMAP`:``,n.iridescenceThicknessMap?`#define USE_IRIDESCENCE_THICKNESSMAP`:``,n.specularMap?`#define USE_SPECULARMAP`:``,n.specularColorMap?`#define USE_SPECULAR_COLORMAP`:``,n.specularIntensityMap?`#define USE_SPECULAR_INTENSITYMAP`:``,n.roughnessMap?`#define USE_ROUGHNESSMAP`:``,n.metalnessMap?`#define USE_METALNESSMAP`:``,n.alphaMap?`#define USE_ALPHAMAP`:``,n.alphaTest?`#define USE_ALPHATEST`:``,n.alphaHash?`#define USE_ALPHAHASH`:``,n.sheen?`#define USE_SHEEN`:``,n.sheenColorMap?`#define USE_SHEEN_COLORMAP`:``,n.sheenRoughnessMap?`#define USE_SHEEN_ROUGHNESSMAP`:``,n.transmission?`#define USE_TRANSMISSION`:``,n.transmissionMap?`#define USE_TRANSMISSIONMAP`:``,n.thicknessMap?`#define USE_THICKNESSMAP`:``,n.vertexTangents&&n.flatShading===!1?`#define USE_TANGENT`:``,n.vertexColors||n.instancingColor?`#define USE_COLOR`:``,n.vertexAlphas?`#define USE_COLOR_ALPHA`:``,n.vertexUv1s?`#define USE_UV1`:``,n.vertexUv2s?`#define USE_UV2`:``,n.vertexUv3s?`#define USE_UV3`:``,n.pointsUvs?`#define USE_POINTS_UV`:``,n.gradientMap?`#define USE_GRADIENTMAP`:``,n.flatShading?`#define FLAT_SHADED`:``,n.doubleSided?`#define DOUBLE_SIDED`:``,n.flipSided?`#define FLIP_SIDED`:``,n.shadowMapEnabled?`#define USE_SHADOWMAP`:``,n.shadowMapEnabled?`#define `+c:``,n.premultipliedAlpha?`#define PREMULTIPLIED_ALPHA`:``,n.numLightProbes>0?`#define USE_LIGHT_PROBES`:``,n.useLegacyLights?`#define LEGACY_LIGHTS`:``,n.decodeVideoTexture?`#define DECODE_VIDEO_TEXTURE`:``,n.logarithmicDepthBuffer?`#define USE_LOGDEPTHBUF`:``,n.logarithmicDepthBuffer&&n.rendererExtensionFragDepth?`#define USE_LOGDEPTHBUF_EXT`:``,`uniform mat4 viewMatrix;`,`uniform vec3 cameraPosition;`,`uniform bool isOrthographic;`,n.toneMapping===0?``:`#define TONE_MAPPING`,n.toneMapping===0?``:Q.tonemapping_pars_fragment,n.toneMapping===0?``:ya(`toneMapping`,n.toneMapping),n.dithering?`#define DITHERING`:``,n.opaque?`#define OPAQUE`:``,Q.colorspace_pars_fragment,va(`linearToOutputTexel`,n.outputColorSpace),n.useDepthPacking?`#define DEPTH_PACKING `+n.depthPacking:``,`
3603
+ `].filter(Ca).join(`
3604
+ `)),o=Da(o),o=wa(o,n),o=Ta(o,n),s=Da(s),s=wa(s,n),s=Ta(s,n),o=ja(o),s=ja(s),n.isWebGL2&&n.isRawShaderMaterial!==!0&&(v=`#version 300 es
3605
+ `,g=[`precision mediump sampler2DArray;`,`#define attribute in`,`#define varying out`,`#define texture2D texture`].join(`
3606
+ `)+`
3607
+ `+g,_=[`precision mediump sampler2DArray;`,`#define varying in`,n.glslVersion===`300 es`?``:`layout(location = 0) out highp vec4 pc_fragColor;`,n.glslVersion===`300 es`?``:`#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(`
3608
+ `)+`
3609
+ `+_);let y=v+g+o,b=v+_+s,x=fa(i,i.VERTEX_SHADER,y),S=fa(i,i.FRAGMENT_SHADER,b);i.attachShader(h,x),i.attachShader(h,S),n.index0AttributeName===void 0?n.morphTargets===!0&&i.bindAttribLocation(h,0,`position`):i.bindAttribLocation(h,0,n.index0AttributeName),i.linkProgram(h);function C(t){if(e.debug.checkShaderErrors){let n=i.getProgramInfoLog(h).trim(),r=i.getShaderInfoLog(x).trim(),a=i.getShaderInfoLog(S).trim(),o=!0,s=!0;if(i.getProgramParameter(h,i.LINK_STATUS)===!1)if(o=!1,typeof e.debug.onShaderError==`function`)e.debug.onShaderError(i,h,x,S);else{let e=_a(i,x,`vertex`),t=_a(i,S,`fragment`);console.error(`THREE.WebGLProgram: Shader Error `+i.getError()+` - VALIDATE_STATUS `+i.getProgramParameter(h,i.VALIDATE_STATUS)+`
3610
+
3611
+ Program Info Log: `+n+`
3612
+ `+e+`
3613
+ `+t)}else n===``?(r===``||a===``)&&(s=!1):console.warn(`THREE.WebGLProgram: Program Info Log:`,n);s&&(t.diagnostics={runnable:o,programLog:n,vertexShader:{log:r,prefix:g},fragmentShader:{log:a,prefix:_}})}i.deleteShader(x),i.deleteShader(S),w=new da(i,h),T=Sa(i,h)}let w;this.getUniforms=function(){return w===void 0&&C(this),w};let T;this.getAttributes=function(){return T===void 0&&C(this),T};let E=n.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return E===!1&&(E=i.getProgramParameter(h,pa)),E},this.destroy=function(){r.releaseStatesOfProgram(this),i.deleteProgram(h),this.program=void 0},this.type=n.shaderType,this.name=n.shaderName,this.id=ma++,this.cacheKey=t,this.usedTimes=1,this.program=h,this.vertexShader=x,this.fragmentShader=S,this}var Ba=0,Va=class{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e){let t=e.vertexShader,n=e.fragmentShader,r=this._getShaderStage(t),i=this._getShaderStage(n),a=this._getShaderCacheForMaterial(e);return a.has(r)===!1&&(a.add(r),r.usedTimes++),a.has(i)===!1&&(a.add(i),i.usedTimes++),this}remove(e){let t=this.materialCache.get(e);for(let e of t)e.usedTimes--,e.usedTimes===0&&this.shaderCache.delete(e.code);return this.materialCache.delete(e),this}getVertexShaderID(e){return this._getShaderStage(e.vertexShader).id}getFragmentShaderID(e){return this._getShaderStage(e.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){let t=this.materialCache,n=t.get(e);return n===void 0&&(n=new Set,t.set(e,n)),n}_getShaderStage(e){let t=this.shaderCache,n=t.get(e);return n===void 0&&(n=new Ha(e),t.set(e,n)),n}},Ha=class{constructor(e){this.id=Ba++,this.code=e,this.usedTimes=0}};function Ua(e,t,n,r,i,a,o){let s=new Nt,c=new Va,l=[],u=i.isWebGL2,d=i.logarithmicDepthBuffer,f=i.vertexTextures,p=i.precision,m={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 h(e){return e===0?`uv`:`uv${e}`}function g(a,s,l,g,_){let v=g.fog,y=_.geometry,b=a.isMeshStandardMaterial?g.environment:null,x=(a.isMeshStandardMaterial?n:t).get(a.envMap||b),S=x&&x.mapping===306?x.image.height:null,C=m[a.type];a.precision!==null&&(p=i.getMaxPrecision(a.precision),p!==a.precision&&console.warn(`THREE.WebGLProgram.getParameters:`,a.precision,`not supported, using`,p,`instead.`));let w=y.morphAttributes.position||y.morphAttributes.normal||y.morphAttributes.color,T=w===void 0?0:w.length,E=0;y.morphAttributes.position!==void 0&&(E=1),y.morphAttributes.normal!==void 0&&(E=2),y.morphAttributes.color!==void 0&&(E=3);let D,O,k,A;if(C){let e=xr[C];D=e.vertexShader,O=e.fragmentShader}else D=a.vertexShader,O=a.fragmentShader,c.update(a),k=c.getVertexShaderID(a),A=c.getFragmentShaderID(a);let te=e.getRenderTarget(),j=_.isInstancedMesh===!0,ne=_.isBatchedMesh===!0,M=!!a.map,N=!!a.matcap,P=!!x,re=!!a.aoMap,ie=!!a.lightMap,ae=!!a.bumpMap,F=!!a.normalMap,I=!!a.displacementMap,oe=!!a.emissiveMap,se=!!a.metalnessMap,L=!!a.roughnessMap,R=a.anisotropy>0,z=a.clearcoat>0,ce=a.iridescence>0,le=a.sheen>0,ue=a.transmission>0,de=R&&!!a.anisotropyMap,B=z&&!!a.clearcoatMap,fe=z&&!!a.clearcoatNormalMap,V=z&&!!a.clearcoatRoughnessMap,H=ce&&!!a.iridescenceMap,U=ce&&!!a.iridescenceThicknessMap,pe=le&&!!a.sheenColorMap,W=le&&!!a.sheenRoughnessMap,G=!!a.specularMap,me=!!a.specularColorMap,he=!!a.specularIntensityMap,ge=ue&&!!a.transmissionMap,_e=ue&&!!a.thicknessMap,ve=!!a.gradientMap,ye=!!a.alphaMap,be=a.alphaTest>0,xe=!!a.alphaHash,Se=!!a.extensions,K=!!y.attributes.uv1,q=!!y.attributes.uv2,J=!!y.attributes.uv3,Ce=0;return a.toneMapped&&(te===null||te.isXRRenderTarget===!0)&&(Ce=e.toneMapping),{isWebGL2:u,shaderID:C,shaderType:a.type,shaderName:a.name,vertexShader:D,fragmentShader:O,defines:a.defines,customVertexShaderID:k,customFragmentShaderID:A,isRawShaderMaterial:a.isRawShaderMaterial===!0,glslVersion:a.glslVersion,precision:p,batching:ne,instancing:j,instancingColor:j&&_.instanceColor!==null,supportsVertexTextures:f,outputColorSpace:te===null?e.outputColorSpace:te.isXRRenderTarget===!0?te.texture.colorSpace:ee,map:M,matcap:N,envMap:P,envMapMode:P&&x.mapping,envMapCubeUVHeight:S,aoMap:re,lightMap:ie,bumpMap:ae,normalMap:F,displacementMap:f&&I,emissiveMap:oe,normalMapObjectSpace:F&&a.normalMapType===1,normalMapTangentSpace:F&&a.normalMapType===0,metalnessMap:se,roughnessMap:L,anisotropy:R,anisotropyMap:de,clearcoat:z,clearcoatMap:B,clearcoatNormalMap:fe,clearcoatRoughnessMap:V,iridescence:ce,iridescenceMap:H,iridescenceThicknessMap:U,sheen:le,sheenColorMap:pe,sheenRoughnessMap:W,specularMap:G,specularColorMap:me,specularIntensityMap:he,transmission:ue,transmissionMap:ge,thicknessMap:_e,gradientMap:ve,opaque:a.transparent===!1&&a.blending===1,alphaMap:ye,alphaTest:be,alphaHash:xe,combine:a.combine,mapUv:M&&h(a.map.channel),aoMapUv:re&&h(a.aoMap.channel),lightMapUv:ie&&h(a.lightMap.channel),bumpMapUv:ae&&h(a.bumpMap.channel),normalMapUv:F&&h(a.normalMap.channel),displacementMapUv:I&&h(a.displacementMap.channel),emissiveMapUv:oe&&h(a.emissiveMap.channel),metalnessMapUv:se&&h(a.metalnessMap.channel),roughnessMapUv:L&&h(a.roughnessMap.channel),anisotropyMapUv:de&&h(a.anisotropyMap.channel),clearcoatMapUv:B&&h(a.clearcoatMap.channel),clearcoatNormalMapUv:fe&&h(a.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:V&&h(a.clearcoatRoughnessMap.channel),iridescenceMapUv:H&&h(a.iridescenceMap.channel),iridescenceThicknessMapUv:U&&h(a.iridescenceThicknessMap.channel),sheenColorMapUv:pe&&h(a.sheenColorMap.channel),sheenRoughnessMapUv:W&&h(a.sheenRoughnessMap.channel),specularMapUv:G&&h(a.specularMap.channel),specularColorMapUv:me&&h(a.specularColorMap.channel),specularIntensityMapUv:he&&h(a.specularIntensityMap.channel),transmissionMapUv:ge&&h(a.transmissionMap.channel),thicknessMapUv:_e&&h(a.thicknessMap.channel),alphaMapUv:ye&&h(a.alphaMap.channel),vertexTangents:!!y.attributes.tangent&&(F||R),vertexColors:a.vertexColors,vertexAlphas:a.vertexColors===!0&&!!y.attributes.color&&y.attributes.color.itemSize===4,vertexUv1s:K,vertexUv2s:q,vertexUv3s:J,pointsUvs:_.isPoints===!0&&!!y.attributes.uv&&(M||ye),fog:!!v,useFog:a.fog===!0,fogExp2:v&&v.isFogExp2,flatShading:a.flatShading===!0,sizeAttenuation:a.sizeAttenuation===!0,logarithmicDepthBuffer:d,skinning:_.isSkinnedMesh===!0,morphTargets:y.morphAttributes.position!==void 0,morphNormals:y.morphAttributes.normal!==void 0,morphColors:y.morphAttributes.color!==void 0,morphTargetsCount:T,morphTextureStride:E,numDirLights:s.directional.length,numPointLights:s.point.length,numSpotLights:s.spot.length,numSpotLightMaps:s.spotLightMap.length,numRectAreaLights:s.rectArea.length,numHemiLights:s.hemi.length,numDirLightShadows:s.directionalShadowMap.length,numPointLightShadows:s.pointShadowMap.length,numSpotLightShadows:s.spotShadowMap.length,numSpotLightShadowsWithMaps:s.numSpotLightShadowsWithMaps,numLightProbes:s.numLightProbes,numClippingPlanes:o.numPlanes,numClipIntersection:o.numIntersection,dithering:a.dithering,shadowMapEnabled:e.shadowMap.enabled&&l.length>0,shadowMapType:e.shadowMap.type,toneMapping:Ce,useLegacyLights:e._useLegacyLights,decodeVideoTexture:M&&a.map.isVideoTexture===!0&&Y.getTransfer(a.map.colorSpace)===`srgb`,premultipliedAlpha:a.premultipliedAlpha,doubleSided:a.side===2,flipSided:a.side===1,useDepthPacking:a.depthPacking>=0,depthPacking:a.depthPacking||0,index0AttributeName:a.index0AttributeName,extensionDerivatives:Se&&a.extensions.derivatives===!0,extensionFragDepth:Se&&a.extensions.fragDepth===!0,extensionDrawBuffers:Se&&a.extensions.drawBuffers===!0,extensionShaderTextureLOD:Se&&a.extensions.shaderTextureLOD===!0,rendererExtensionFragDepth:u||r.has(`EXT_frag_depth`),rendererExtensionDrawBuffers:u||r.has(`WEBGL_draw_buffers`),rendererExtensionShaderTextureLod:u||r.has(`EXT_shader_texture_lod`),rendererExtensionParallelShaderCompile:r.has(`KHR_parallel_shader_compile`),customProgramCacheKey:a.customProgramCacheKey()}}function _(t){let n=[];if(t.shaderID?n.push(t.shaderID):(n.push(t.customVertexShaderID),n.push(t.customFragmentShaderID)),t.defines!==void 0)for(let e in t.defines)n.push(e),n.push(t.defines[e]);return t.isRawShaderMaterial===!1&&(v(n,t),y(n,t),n.push(e.outputColorSpace)),n.push(t.customProgramCacheKey),n.join()}function v(e,t){e.push(t.precision),e.push(t.outputColorSpace),e.push(t.envMapMode),e.push(t.envMapCubeUVHeight),e.push(t.mapUv),e.push(t.alphaMapUv),e.push(t.lightMapUv),e.push(t.aoMapUv),e.push(t.bumpMapUv),e.push(t.normalMapUv),e.push(t.displacementMapUv),e.push(t.emissiveMapUv),e.push(t.metalnessMapUv),e.push(t.roughnessMapUv),e.push(t.anisotropyMapUv),e.push(t.clearcoatMapUv),e.push(t.clearcoatNormalMapUv),e.push(t.clearcoatRoughnessMapUv),e.push(t.iridescenceMapUv),e.push(t.iridescenceThicknessMapUv),e.push(t.sheenColorMapUv),e.push(t.sheenRoughnessMapUv),e.push(t.specularMapUv),e.push(t.specularColorMapUv),e.push(t.specularIntensityMapUv),e.push(t.transmissionMapUv),e.push(t.thicknessMapUv),e.push(t.combine),e.push(t.fogExp2),e.push(t.sizeAttenuation),e.push(t.morphTargetsCount),e.push(t.morphAttributeCount),e.push(t.numDirLights),e.push(t.numPointLights),e.push(t.numSpotLights),e.push(t.numSpotLightMaps),e.push(t.numHemiLights),e.push(t.numRectAreaLights),e.push(t.numDirLightShadows),e.push(t.numPointLightShadows),e.push(t.numSpotLightShadows),e.push(t.numSpotLightShadowsWithMaps),e.push(t.numLightProbes),e.push(t.shadowMapType),e.push(t.toneMapping),e.push(t.numClippingPlanes),e.push(t.numClipIntersection),e.push(t.depthPacking)}function y(e,t){s.disableAll(),t.isWebGL2&&s.enable(0),t.supportsVertexTextures&&s.enable(1),t.instancing&&s.enable(2),t.instancingColor&&s.enable(3),t.matcap&&s.enable(4),t.envMap&&s.enable(5),t.normalMapObjectSpace&&s.enable(6),t.normalMapTangentSpace&&s.enable(7),t.clearcoat&&s.enable(8),t.iridescence&&s.enable(9),t.alphaTest&&s.enable(10),t.vertexColors&&s.enable(11),t.vertexAlphas&&s.enable(12),t.vertexUv1s&&s.enable(13),t.vertexUv2s&&s.enable(14),t.vertexUv3s&&s.enable(15),t.vertexTangents&&s.enable(16),t.anisotropy&&s.enable(17),t.alphaHash&&s.enable(18),t.batching&&s.enable(19),e.push(s.mask),s.disableAll(),t.fog&&s.enable(0),t.useFog&&s.enable(1),t.flatShading&&s.enable(2),t.logarithmicDepthBuffer&&s.enable(3),t.skinning&&s.enable(4),t.morphTargets&&s.enable(5),t.morphNormals&&s.enable(6),t.morphColors&&s.enable(7),t.premultipliedAlpha&&s.enable(8),t.shadowMapEnabled&&s.enable(9),t.useLegacyLights&&s.enable(10),t.doubleSided&&s.enable(11),t.flipSided&&s.enable(12),t.useDepthPacking&&s.enable(13),t.dithering&&s.enable(14),t.transmission&&s.enable(15),t.sheen&&s.enable(16),t.opaque&&s.enable(17),t.pointsUvs&&s.enable(18),t.decodeVideoTexture&&s.enable(19),e.push(s.mask)}function b(e){let t=m[e.type],n;if(t){let e=xr[t];n=er.clone(e.uniforms)}else n=e.uniforms;return n}function x(t,n){let r;for(let e=0,t=l.length;e<t;e++){let t=l[e];if(t.cacheKey===n){r=t,++r.usedTimes;break}}return r===void 0&&(r=new za(e,n,t,a),l.push(r)),r}function S(e){if(--e.usedTimes===0){let t=l.indexOf(e);l[t]=l[l.length-1],l.pop(),e.destroy()}}function C(e){c.remove(e)}function w(){c.dispose()}return{getParameters:g,getProgramCacheKey:_,getUniforms:b,acquireProgram:x,releaseProgram:S,releaseShaderCache:C,programs:l,dispose:w}}function Wa(){let e=new WeakMap;function t(t){let n=e.get(t);return n===void 0&&(n={},e.set(t,n)),n}function n(t){e.delete(t)}function r(t,n,r){e.get(t)[n]=r}function i(){e=new WeakMap}return{get:t,remove:n,update:r,dispose:i}}function Ga(e,t){return e.groupOrder===t.groupOrder?e.renderOrder===t.renderOrder?e.material.id===t.material.id?e.z===t.z?e.id-t.id:e.z-t.z:e.material.id-t.material.id:e.renderOrder-t.renderOrder:e.groupOrder-t.groupOrder}function Ka(e,t){return e.groupOrder===t.groupOrder?e.renderOrder===t.renderOrder?e.z===t.z?e.id-t.id:t.z-e.z:e.renderOrder-t.renderOrder:e.groupOrder-t.groupOrder}function qa(){let e=[],t=0,n=[],r=[],i=[];function a(){t=0,n.length=0,r.length=0,i.length=0}function o(n,r,i,a,o,s){let c=e[t];return c===void 0?(c={id:n.id,object:n,geometry:r,material:i,groupOrder:a,renderOrder:n.renderOrder,z:o,group:s},e[t]=c):(c.id=n.id,c.object=n,c.geometry=r,c.material=i,c.groupOrder=a,c.renderOrder=n.renderOrder,c.z=o,c.group=s),t++,c}function s(e,t,a,s,c,l){let u=o(e,t,a,s,c,l);a.transmission>0?r.push(u):a.transparent===!0?i.push(u):n.push(u)}function c(e,t,a,s,c,l){let u=o(e,t,a,s,c,l);a.transmission>0?r.unshift(u):a.transparent===!0?i.unshift(u):n.unshift(u)}function l(e,t){n.length>1&&n.sort(e||Ga),r.length>1&&r.sort(t||Ka),i.length>1&&i.sort(t||Ka)}function u(){for(let n=t,r=e.length;n<r;n++){let t=e[n];if(t.id===null)break;t.id=null,t.object=null,t.geometry=null,t.material=null,t.group=null}}return{opaque:n,transmissive:r,transparent:i,init:a,push:s,unshift:c,finish:u,sort:l}}function Ja(){let e=new WeakMap;function t(t,n){let r=e.get(t),i;return r===void 0?(i=new qa,e.set(t,[i])):n>=r.length?(i=new qa,r.push(i)):i=r[n],i}function n(){e=new WeakMap}return{get:t,dispose:n}}function Ya(){let e={};return{get:function(t){if(e[t.id]!==void 0)return e[t.id];let n;switch(t.type){case`DirectionalLight`:n={direction:new X,color:new Z};break;case`SpotLight`:n={position:new X,direction:new X,color:new Z,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case`PointLight`:n={position:new X,color:new Z,distance:0,decay:0};break;case`HemisphereLight`:n={direction:new X,skyColor:new Z,groundColor:new Z};break;case`RectAreaLight`:n={color:new Z,position:new X,halfWidth:new X,halfHeight:new X};break}return e[t.id]=n,n}}}function Xa(){let e={};return{get:function(t){if(e[t.id]!==void 0)return e[t.id];let n;switch(t.type){case`DirectionalLight`:n={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new K};break;case`SpotLight`:n={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new K};break;case`PointLight`:n={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new K,shadowCameraNear:1,shadowCameraFar:1e3};break}return e[t.id]=n,n}}}var Za=0;function Qa(e,t){return(t.castShadow?2:0)-(e.castShadow?2:0)+ +!!t.map-!!e.map}function $a(e,t){let n=new Ya,r=Xa(),i={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let e=0;e<9;e++)i.probe.push(new X);let a=new X,o=new St,s=new St;function c(a,o){let s=0,c=0,l=0;for(let e=0;e<9;e++)i.probe[e].set(0,0,0);let u=0,d=0,f=0,p=0,m=0,h=0,g=0,_=0,v=0,y=0,b=0;a.sort(Qa);let x=o===!0?Math.PI:1;for(let e=0,t=a.length;e<t;e++){let t=a[e],o=t.color,S=t.intensity,C=t.distance,w=t.shadow&&t.shadow.map?t.shadow.map.texture:null;if(t.isAmbientLight)s+=o.r*S*x,c+=o.g*S*x,l+=o.b*S*x;else if(t.isLightProbe){for(let e=0;e<9;e++)i.probe[e].addScaledVector(t.sh.coefficients[e],S);b++}else if(t.isDirectionalLight){let e=n.get(t);if(e.color.copy(t.color).multiplyScalar(t.intensity*x),t.castShadow){let e=t.shadow,n=r.get(t);n.shadowBias=e.bias,n.shadowNormalBias=e.normalBias,n.shadowRadius=e.radius,n.shadowMapSize=e.mapSize,i.directionalShadow[u]=n,i.directionalShadowMap[u]=w,i.directionalShadowMatrix[u]=t.shadow.matrix,h++}i.directional[u]=e,u++}else if(t.isSpotLight){let e=n.get(t);e.position.setFromMatrixPosition(t.matrixWorld),e.color.copy(o).multiplyScalar(S*x),e.distance=C,e.coneCos=Math.cos(t.angle),e.penumbraCos=Math.cos(t.angle*(1-t.penumbra)),e.decay=t.decay,i.spot[f]=e;let a=t.shadow;if(t.map&&(i.spotLightMap[v]=t.map,v++,a.updateMatrices(t),t.castShadow&&y++),i.spotLightMatrix[f]=a.matrix,t.castShadow){let e=r.get(t);e.shadowBias=a.bias,e.shadowNormalBias=a.normalBias,e.shadowRadius=a.radius,e.shadowMapSize=a.mapSize,i.spotShadow[f]=e,i.spotShadowMap[f]=w,_++}f++}else if(t.isRectAreaLight){let e=n.get(t);e.color.copy(o).multiplyScalar(S),e.halfWidth.set(t.width*.5,0,0),e.halfHeight.set(0,t.height*.5,0),i.rectArea[p]=e,p++}else if(t.isPointLight){let e=n.get(t);if(e.color.copy(t.color).multiplyScalar(t.intensity*x),e.distance=t.distance,e.decay=t.decay,t.castShadow){let e=t.shadow,n=r.get(t);n.shadowBias=e.bias,n.shadowNormalBias=e.normalBias,n.shadowRadius=e.radius,n.shadowMapSize=e.mapSize,n.shadowCameraNear=e.camera.near,n.shadowCameraFar=e.camera.far,i.pointShadow[d]=n,i.pointShadowMap[d]=w,i.pointShadowMatrix[d]=t.shadow.matrix,g++}i.point[d]=e,d++}else if(t.isHemisphereLight){let e=n.get(t);e.skyColor.copy(t.color).multiplyScalar(S*x),e.groundColor.copy(t.groundColor).multiplyScalar(S*x),i.hemi[m]=e,m++}}p>0&&(t.isWebGL2||e.has(`OES_texture_float_linear`)===!0?(i.rectAreaLTC1=$.LTC_FLOAT_1,i.rectAreaLTC2=$.LTC_FLOAT_2):e.has(`OES_texture_half_float_linear`)===!0?(i.rectAreaLTC1=$.LTC_HALF_1,i.rectAreaLTC2=$.LTC_HALF_2):console.error(`THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.`)),i.ambient[0]=s,i.ambient[1]=c,i.ambient[2]=l;let S=i.hash;(S.directionalLength!==u||S.pointLength!==d||S.spotLength!==f||S.rectAreaLength!==p||S.hemiLength!==m||S.numDirectionalShadows!==h||S.numPointShadows!==g||S.numSpotShadows!==_||S.numSpotMaps!==v||S.numLightProbes!==b)&&(i.directional.length=u,i.spot.length=f,i.rectArea.length=p,i.point.length=d,i.hemi.length=m,i.directionalShadow.length=h,i.directionalShadowMap.length=h,i.pointShadow.length=g,i.pointShadowMap.length=g,i.spotShadow.length=_,i.spotShadowMap.length=_,i.directionalShadowMatrix.length=h,i.pointShadowMatrix.length=g,i.spotLightMatrix.length=_+v-y,i.spotLightMap.length=v,i.numSpotLightShadowsWithMaps=y,i.numLightProbes=b,S.directionalLength=u,S.pointLength=d,S.spotLength=f,S.rectAreaLength=p,S.hemiLength=m,S.numDirectionalShadows=h,S.numPointShadows=g,S.numSpotShadows=_,S.numSpotMaps=v,S.numLightProbes=b,i.version=Za++)}function l(e,t){let n=0,r=0,c=0,l=0,u=0,d=t.matrixWorldInverse;for(let t=0,f=e.length;t<f;t++){let f=e[t];if(f.isDirectionalLight){let e=i.directional[n];e.direction.setFromMatrixPosition(f.matrixWorld),a.setFromMatrixPosition(f.target.matrixWorld),e.direction.sub(a),e.direction.transformDirection(d),n++}else if(f.isSpotLight){let e=i.spot[c];e.position.setFromMatrixPosition(f.matrixWorld),e.position.applyMatrix4(d),e.direction.setFromMatrixPosition(f.matrixWorld),a.setFromMatrixPosition(f.target.matrixWorld),e.direction.sub(a),e.direction.transformDirection(d),c++}else if(f.isRectAreaLight){let e=i.rectArea[l];e.position.setFromMatrixPosition(f.matrixWorld),e.position.applyMatrix4(d),s.identity(),o.copy(f.matrixWorld),o.premultiply(d),s.extractRotation(o),e.halfWidth.set(f.width*.5,0,0),e.halfHeight.set(0,f.height*.5,0),e.halfWidth.applyMatrix4(s),e.halfHeight.applyMatrix4(s),l++}else if(f.isPointLight){let e=i.point[r];e.position.setFromMatrixPosition(f.matrixWorld),e.position.applyMatrix4(d),r++}else if(f.isHemisphereLight){let e=i.hemi[u];e.direction.setFromMatrixPosition(f.matrixWorld),e.direction.transformDirection(d),u++}}}return{setup:c,setupView:l,state:i}}function eo(e,t){let n=new $a(e,t),r=[],i=[];function a(){r.length=0,i.length=0}function o(e){r.push(e)}function s(e){i.push(e)}function c(e){n.setup(r,e)}function l(e){n.setupView(r,e)}return{init:a,state:{lightsArray:r,shadowsArray:i,lights:n},setupLights:c,setupLightsView:l,pushLight:o,pushShadow:s}}function to(e,t){let n=new WeakMap;function r(r,i=0){let a=n.get(r),o;return a===void 0?(o=new eo(e,t),n.set(r,[o])):i>=a.length?(o=new eo(e,t),a.push(o)):o=a[i],o}function i(){n=new WeakMap}return{get:r,dispose:i}}var no=class extends pn{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type=`MeshDepthMaterial`,this.depthPacking=O,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}},ro=class extends pn{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type=`MeshDistanceMaterial`,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}},io=`void main() {
3614
+ gl_Position = vec4( position, 1.0 );
3615
+ }`,ao=`uniform sampler2D shadow_pass;
3616
+ uniform vec2 resolution;
3617
+ uniform float radius;
3618
+ #include <packing>
3619
+ void main() {
3620
+ const float samples = float( VSM_SAMPLES );
3621
+ float mean = 0.0;
3622
+ float squared_mean = 0.0;
3623
+ float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );
3624
+ float uvStart = samples <= 1.0 ? 0.0 : - 1.0;
3625
+ for ( float i = 0.0; i < samples; i ++ ) {
3626
+ float uvOffset = uvStart + i * uvStride;
3627
+ #ifdef HORIZONTAL_PASS
3628
+ vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );
3629
+ mean += distribution.x;
3630
+ squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
3631
+ #else
3632
+ float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );
3633
+ mean += depth;
3634
+ squared_mean += depth * depth;
3635
+ #endif
3636
+ }
3637
+ mean = mean / samples;
3638
+ squared_mean = squared_mean / samples;
3639
+ float std_dev = sqrt( squared_mean - mean * mean );
3640
+ gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );
3641
+ }`;function oo(e,t,n){let r=new _r,i=new K,a=new K,s=new Ve,c=new no({depthPacking:k}),l=new ro,u={},d=n.maxTextureSize,f={0:1,1:0,2:2},p=new rr({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new K},radius:{value:4}},vertexShader:io,fragmentShader:ao}),m=p.clone();m.defines.HORIZONTAL_PASS=1;let h=new On;h.setAttribute(`position`,new _n(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));let g=new Kn(h,p),_=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let v=this.type;this.render=function(t,n,c){if(_.enabled===!1||_.autoUpdate===!1&&_.needsUpdate===!1||t.length===0)return;let l=e.getRenderTarget(),u=e.getActiveCubeFace(),f=e.getActiveMipmapLevel(),p=e.state;p.setBlending(0),p.buffers.color.setClear(1,1,1,1),p.buffers.depth.setTest(!0),p.setScissorTest(!1);let m=v!==3&&this.type===3,h=v===3&&this.type!==3;for(let l=0,u=t.length;l<u;l++){let u=t[l],f=u.shadow;if(f===void 0){console.warn(`THREE.WebGLShadowMap:`,u,`has no shadow.`);continue}if(f.autoUpdate===!1&&f.needsUpdate===!1)continue;i.copy(f.mapSize);let g=f.getFrameExtents();if(i.multiply(g),a.copy(f.mapSize),(i.x>d||i.y>d)&&(i.x>d&&(a.x=Math.floor(d/g.x),i.x=a.x*g.x,f.mapSize.x=a.x),i.y>d&&(a.y=Math.floor(d/g.y),i.y=a.y*g.y,f.mapSize.y=a.y)),f.map===null||m===!0||h===!0){let e=this.type===3?{}:{minFilter:o,magFilter:o};f.map!==null&&f.map.dispose(),f.map=new Ue(i.x,i.y,e),f.map.texture.name=u.name+`.shadowMap`,f.camera.updateProjectionMatrix()}e.setRenderTarget(f.map),e.clear();let _=f.getViewportCount();for(let e=0;e<_;e++){let t=f.getViewport(e);s.set(a.x*t.x,a.y*t.y,a.x*t.z,a.y*t.w),p.viewport(s),f.updateMatrices(u,e),r=f.getFrustum(),x(n,c,f.camera,u,this.type)}f.isPointLightShadow!==!0&&this.type===3&&y(f,c),f.needsUpdate=!1}v=this.type,_.needsUpdate=!1,e.setRenderTarget(l,u,f)};function y(n,r){let a=t.update(g);p.defines.VSM_SAMPLES!==n.blurSamples&&(p.defines.VSM_SAMPLES=n.blurSamples,m.defines.VSM_SAMPLES=n.blurSamples,p.needsUpdate=!0,m.needsUpdate=!0),n.mapPass===null&&(n.mapPass=new Ue(i.x,i.y)),p.uniforms.shadow_pass.value=n.map.texture,p.uniforms.resolution.value=n.mapSize,p.uniforms.radius.value=n.radius,e.setRenderTarget(n.mapPass),e.clear(),e.renderBufferDirect(r,null,a,p,g,null),m.uniforms.shadow_pass.value=n.mapPass.texture,m.uniforms.resolution.value=n.mapSize,m.uniforms.radius.value=n.radius,e.setRenderTarget(n.map),e.clear(),e.renderBufferDirect(r,null,a,m,g,null)}function b(t,n,r,i){let a=null,o=r.isPointLight===!0?t.customDistanceMaterial:t.customDepthMaterial;if(o!==void 0)a=o;else if(a=r.isPointLight===!0?l:c,e.localClippingEnabled&&n.clipShadows===!0&&Array.isArray(n.clippingPlanes)&&n.clippingPlanes.length!==0||n.displacementMap&&n.displacementScale!==0||n.alphaMap&&n.alphaTest>0||n.map&&n.alphaTest>0){let e=a.uuid,t=n.uuid,r=u[e];r===void 0&&(r={},u[e]=r);let i=r[t];i===void 0&&(i=a.clone(),r[t]=i),a=i}if(a.visible=n.visible,a.wireframe=n.wireframe,i===3?a.side=n.shadowSide===null?n.side:n.shadowSide:a.side=n.shadowSide===null?f[n.side]:n.shadowSide,a.alphaMap=n.alphaMap,a.alphaTest=n.alphaTest,a.map=n.map,a.clipShadows=n.clipShadows,a.clippingPlanes=n.clippingPlanes,a.clipIntersection=n.clipIntersection,a.displacementMap=n.displacementMap,a.displacementScale=n.displacementScale,a.displacementBias=n.displacementBias,a.wireframeLinewidth=n.wireframeLinewidth,a.linewidth=n.linewidth,r.isPointLight===!0&&a.isMeshDistanceMaterial===!0){let t=e.properties.get(a);t.light=r}return a}function x(n,i,a,o,s){if(n.visible===!1)return;if(n.layers.test(i.layers)&&(n.isMesh||n.isLine||n.isPoints)&&(n.castShadow||n.receiveShadow&&s===3)&&(!n.frustumCulled||r.intersectsObject(n))){n.modelViewMatrix.multiplyMatrices(a.matrixWorldInverse,n.matrixWorld);let r=t.update(n),c=n.material;if(Array.isArray(c)){let t=r.groups;for(let l=0,u=t.length;l<u;l++){let u=t[l],d=c[u.materialIndex];if(d&&d.visible){let t=b(n,d,o,s);n.onBeforeShadow(e,n,i,a,r,t,u),e.renderBufferDirect(a,null,r,t,n,u),n.onAfterShadow(e,n,i,a,r,t,u)}}}else if(c.visible){let t=b(n,c,o,s);n.onBeforeShadow(e,n,i,a,r,t,null),e.renderBufferDirect(a,null,r,t,n,null),n.onAfterShadow(e,n,i,a,r,t,null)}}let c=n.children;for(let e=0,t=c.length;e<t;e++)x(c[e],i,a,o,s)}}function so(e,t,n){let r=n.isWebGL2;function i(){let t=!1,n=new Ve,r=null,i=new Ve(0,0,0,0);return{setMask:function(n){r!==n&&!t&&(e.colorMask(n,n,n,n),r=n)},setLocked:function(e){t=e},setClear:function(t,r,a,o,s){s===!0&&(t*=o,r*=o,a*=o),n.set(t,r,a,o),i.equals(n)===!1&&(e.clearColor(t,r,a,o),i.copy(n))},reset:function(){t=!1,r=null,i.set(-1,0,0,0)}}}function a(){let t=!1,n=null,r=null,i=null;return{setTest:function(t){t?L(e.DEPTH_TEST):R(e.DEPTH_TEST)},setMask:function(r){n!==r&&!t&&(e.depthMask(r),n=r)},setFunc:function(t){if(r!==t){switch(t){case 0:e.depthFunc(e.NEVER);break;case 1:e.depthFunc(e.ALWAYS);break;case 2:e.depthFunc(e.LESS);break;case 3:e.depthFunc(e.LEQUAL);break;case 4:e.depthFunc(e.EQUAL);break;case 5:e.depthFunc(e.GEQUAL);break;case 6:e.depthFunc(e.GREATER);break;case 7:e.depthFunc(e.NOTEQUAL);break;default:e.depthFunc(e.LEQUAL)}r=t}},setLocked:function(e){t=e},setClear:function(t){i!==t&&(e.clearDepth(t),i=t)},reset:function(){t=!1,n=null,r=null,i=null}}}function o(){let t=!1,n=null,r=null,i=null,a=null,o=null,s=null,c=null,l=null;return{setTest:function(n){t||(n?L(e.STENCIL_TEST):R(e.STENCIL_TEST))},setMask:function(r){n!==r&&!t&&(e.stencilMask(r),n=r)},setFunc:function(t,n,o){(r!==t||i!==n||a!==o)&&(e.stencilFunc(t,n,o),r=t,i=n,a=o)},setOp:function(t,n,r){(o!==t||s!==n||c!==r)&&(e.stencilOp(t,n,r),o=t,s=n,c=r)},setLocked:function(e){t=e},setClear:function(t){l!==t&&(e.clearStencil(t),l=t)},reset:function(){t=!1,n=null,r=null,i=null,a=null,o=null,s=null,c=null,l=null}}}let s=new i,c=new a,l=new o,u=new WeakMap,d=new WeakMap,f={},p={},m=new WeakMap,h=[],g=null,_=!1,v=null,y=null,b=null,x=null,S=null,C=null,w=null,T=new Z(0,0,0),E=0,D=!1,O=null,k=null,A=null,ee=null,te=null,j=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),ne=!1,M=0,N=e.getParameter(e.VERSION);N.indexOf(`WebGL`)===-1?N.indexOf(`OpenGL ES`)!==-1&&(M=parseFloat(/^OpenGL ES (\d)/.exec(N)[1]),ne=M>=2):(M=parseFloat(/^WebGL (\d)/.exec(N)[1]),ne=M>=1);let P=null,re={},ie=e.getParameter(e.SCISSOR_BOX),ae=e.getParameter(e.VIEWPORT),F=new Ve().fromArray(ie),I=new Ve().fromArray(ae);function oe(t,n,i,a){let o=new Uint8Array(4),s=e.createTexture();e.bindTexture(t,s),e.texParameteri(t,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(t,e.TEXTURE_MAG_FILTER,e.NEAREST);for(let s=0;s<i;s++)r&&(t===e.TEXTURE_3D||t===e.TEXTURE_2D_ARRAY)?e.texImage3D(n,0,e.RGBA,1,1,a,0,e.RGBA,e.UNSIGNED_BYTE,o):e.texImage2D(n+s,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,o);return s}let se={};se[e.TEXTURE_2D]=oe(e.TEXTURE_2D,e.TEXTURE_2D,1),se[e.TEXTURE_CUBE_MAP]=oe(e.TEXTURE_CUBE_MAP,e.TEXTURE_CUBE_MAP_POSITIVE_X,6),r&&(se[e.TEXTURE_2D_ARRAY]=oe(e.TEXTURE_2D_ARRAY,e.TEXTURE_2D_ARRAY,1,1),se[e.TEXTURE_3D]=oe(e.TEXTURE_3D,e.TEXTURE_3D,1,1)),s.setClear(0,0,0,1),c.setClear(1),l.setClear(0),L(e.DEPTH_TEST),c.setFunc(3),V(!1),H(1),L(e.CULL_FACE),B(0);function L(t){f[t]!==!0&&(e.enable(t),f[t]=!0)}function R(t){f[t]!==!1&&(e.disable(t),f[t]=!1)}function z(t,n){return p[t]===n?!1:(e.bindFramebuffer(t,n),p[t]=n,r&&(t===e.DRAW_FRAMEBUFFER&&(p[e.FRAMEBUFFER]=n),t===e.FRAMEBUFFER&&(p[e.DRAW_FRAMEBUFFER]=n)),!0)}function ce(r,i){let a=h,o=!1;if(r)if(a=m.get(i),a===void 0&&(a=[],m.set(i,a)),r.isWebGLMultipleRenderTargets){let t=r.texture;if(a.length!==t.length||a[0]!==e.COLOR_ATTACHMENT0){for(let n=0,r=t.length;n<r;n++)a[n]=e.COLOR_ATTACHMENT0+n;a.length=t.length,o=!0}}else a[0]!==e.COLOR_ATTACHMENT0&&(a[0]=e.COLOR_ATTACHMENT0,o=!0);else a[0]!==e.BACK&&(a[0]=e.BACK,o=!0);o&&(n.isWebGL2?e.drawBuffers(a):t.get(`WEBGL_draw_buffers`).drawBuffersWEBGL(a))}function le(t){return g===t?!1:(e.useProgram(t),g=t,!0)}let ue={100:e.FUNC_ADD,101:e.FUNC_SUBTRACT,102:e.FUNC_REVERSE_SUBTRACT};if(r)ue[103]=e.MIN,ue[104]=e.MAX;else{let e=t.get(`EXT_blend_minmax`);e!==null&&(ue[103]=e.MIN_EXT,ue[104]=e.MAX_EXT)}let de={200:e.ZERO,201:e.ONE,202:e.SRC_COLOR,204:e.SRC_ALPHA,210:e.SRC_ALPHA_SATURATE,208:e.DST_COLOR,206:e.DST_ALPHA,203:e.ONE_MINUS_SRC_COLOR,205:e.ONE_MINUS_SRC_ALPHA,209:e.ONE_MINUS_DST_COLOR,207:e.ONE_MINUS_DST_ALPHA,211:e.CONSTANT_COLOR,212:e.ONE_MINUS_CONSTANT_COLOR,213:e.CONSTANT_ALPHA,214:e.ONE_MINUS_CONSTANT_ALPHA};function B(t,n,r,i,a,o,s,c,l,u){if(t===0){_===!0&&(R(e.BLEND),_=!1);return}if(_===!1&&(L(e.BLEND),_=!0),t!==5){if(t!==v||u!==D){if((y!==100||S!==100)&&(e.blendEquation(e.FUNC_ADD),y=100,S=100),u)switch(t){case 1:e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 2:e.blendFunc(e.ONE,e.ONE);break;case 3:e.blendFuncSeparate(e.ZERO,e.ONE_MINUS_SRC_COLOR,e.ZERO,e.ONE);break;case 4:e.blendFuncSeparate(e.ZERO,e.SRC_COLOR,e.ZERO,e.SRC_ALPHA);break;default:console.error(`THREE.WebGLState: Invalid blending: `,t);break}else switch(t){case 1:e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 2:e.blendFunc(e.SRC_ALPHA,e.ONE);break;case 3:e.blendFuncSeparate(e.ZERO,e.ONE_MINUS_SRC_COLOR,e.ZERO,e.ONE);break;case 4:e.blendFunc(e.ZERO,e.SRC_COLOR);break;default:console.error(`THREE.WebGLState: Invalid blending: `,t);break}b=null,x=null,C=null,w=null,T.set(0,0,0),E=0,v=t,D=u}return}a||=n,o||=r,s||=i,(n!==y||a!==S)&&(e.blendEquationSeparate(ue[n],ue[a]),y=n,S=a),(r!==b||i!==x||o!==C||s!==w)&&(e.blendFuncSeparate(de[r],de[i],de[o],de[s]),b=r,x=i,C=o,w=s),(c.equals(T)===!1||l!==E)&&(e.blendColor(c.r,c.g,c.b,l),T.copy(c),E=l),v=t,D=!1}function fe(t,n){t.side===2?R(e.CULL_FACE):L(e.CULL_FACE);let r=t.side===1;n&&(r=!r),V(r),t.blending===1&&t.transparent===!1?B(0):B(t.blending,t.blendEquation,t.blendSrc,t.blendDst,t.blendEquationAlpha,t.blendSrcAlpha,t.blendDstAlpha,t.blendColor,t.blendAlpha,t.premultipliedAlpha),c.setFunc(t.depthFunc),c.setTest(t.depthTest),c.setMask(t.depthWrite),s.setMask(t.colorWrite);let i=t.stencilWrite;l.setTest(i),i&&(l.setMask(t.stencilWriteMask),l.setFunc(t.stencilFunc,t.stencilRef,t.stencilFuncMask),l.setOp(t.stencilFail,t.stencilZFail,t.stencilZPass)),pe(t.polygonOffset,t.polygonOffsetFactor,t.polygonOffsetUnits),t.alphaToCoverage===!0?L(e.SAMPLE_ALPHA_TO_COVERAGE):R(e.SAMPLE_ALPHA_TO_COVERAGE)}function V(t){O!==t&&(t?e.frontFace(e.CW):e.frontFace(e.CCW),O=t)}function H(t){t===0?R(e.CULL_FACE):(L(e.CULL_FACE),t!==k&&(t===1?e.cullFace(e.BACK):t===2?e.cullFace(e.FRONT):e.cullFace(e.FRONT_AND_BACK))),k=t}function U(t){t!==A&&(ne&&e.lineWidth(t),A=t)}function pe(t,n,r){t?(L(e.POLYGON_OFFSET_FILL),(ee!==n||te!==r)&&(e.polygonOffset(n,r),ee=n,te=r)):R(e.POLYGON_OFFSET_FILL)}function W(t){t?L(e.SCISSOR_TEST):R(e.SCISSOR_TEST)}function G(t){t===void 0&&(t=e.TEXTURE0+j-1),P!==t&&(e.activeTexture(t),P=t)}function me(t,n,r){r===void 0&&(r=P===null?e.TEXTURE0+j-1:P);let i=re[r];i===void 0&&(i={type:void 0,texture:void 0},re[r]=i),(i.type!==t||i.texture!==n)&&(P!==r&&(e.activeTexture(r),P=r),e.bindTexture(t,n||se[t]),i.type=t,i.texture=n)}function he(){let t=re[P];t!==void 0&&t.type!==void 0&&(e.bindTexture(t.type,null),t.type=void 0,t.texture=void 0)}function ge(){try{e.compressedTexImage2D.apply(e,arguments)}catch(e){console.error(`THREE.WebGLState:`,e)}}function _e(){try{e.compressedTexImage3D.apply(e,arguments)}catch(e){console.error(`THREE.WebGLState:`,e)}}function ve(){try{e.texSubImage2D.apply(e,arguments)}catch(e){console.error(`THREE.WebGLState:`,e)}}function ye(){try{e.texSubImage3D.apply(e,arguments)}catch(e){console.error(`THREE.WebGLState:`,e)}}function be(){try{e.compressedTexSubImage2D.apply(e,arguments)}catch(e){console.error(`THREE.WebGLState:`,e)}}function xe(){try{e.compressedTexSubImage3D.apply(e,arguments)}catch(e){console.error(`THREE.WebGLState:`,e)}}function Se(){try{e.texStorage2D.apply(e,arguments)}catch(e){console.error(`THREE.WebGLState:`,e)}}function K(){try{e.texStorage3D.apply(e,arguments)}catch(e){console.error(`THREE.WebGLState:`,e)}}function q(){try{e.texImage2D.apply(e,arguments)}catch(e){console.error(`THREE.WebGLState:`,e)}}function J(){try{e.texImage3D.apply(e,arguments)}catch(e){console.error(`THREE.WebGLState:`,e)}}function Ce(t){F.equals(t)===!1&&(e.scissor(t.x,t.y,t.z,t.w),F.copy(t))}function we(t){I.equals(t)===!1&&(e.viewport(t.x,t.y,t.z,t.w),I.copy(t))}function Te(t,n){let r=d.get(n);r===void 0&&(r=new WeakMap,d.set(n,r));let i=r.get(t);i===void 0&&(i=e.getUniformBlockIndex(n,t.name),r.set(t,i))}function Ee(t,n){let r=d.get(n).get(t);u.get(n)!==r&&(e.uniformBlockBinding(n,r,t.__bindingPointIndex),u.set(n,r))}function De(){e.disable(e.BLEND),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.POLYGON_OFFSET_FILL),e.disable(e.SCISSOR_TEST),e.disable(e.STENCIL_TEST),e.disable(e.SAMPLE_ALPHA_TO_COVERAGE),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ZERO),e.blendFuncSeparate(e.ONE,e.ZERO,e.ONE,e.ZERO),e.blendColor(0,0,0,0),e.colorMask(!0,!0,!0,!0),e.clearColor(0,0,0,0),e.depthMask(!0),e.depthFunc(e.LESS),e.clearDepth(1),e.stencilMask(4294967295),e.stencilFunc(e.ALWAYS,0,4294967295),e.stencilOp(e.KEEP,e.KEEP,e.KEEP),e.clearStencil(0),e.cullFace(e.BACK),e.frontFace(e.CCW),e.polygonOffset(0,0),e.activeTexture(e.TEXTURE0),e.bindFramebuffer(e.FRAMEBUFFER,null),r===!0&&(e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null),e.bindFramebuffer(e.READ_FRAMEBUFFER,null)),e.useProgram(null),e.lineWidth(1),e.scissor(0,0,e.canvas.width,e.canvas.height),e.viewport(0,0,e.canvas.width,e.canvas.height),f={},P=null,re={},p={},m=new WeakMap,h=[],g=null,_=!1,v=null,y=null,b=null,x=null,S=null,C=null,w=null,T=new Z(0,0,0),E=0,D=!1,O=null,k=null,A=null,ee=null,te=null,F.set(0,0,e.canvas.width,e.canvas.height),I.set(0,0,e.canvas.width,e.canvas.height),s.reset(),c.reset(),l.reset()}return{buffers:{color:s,depth:c,stencil:l},enable:L,disable:R,bindFramebuffer:z,drawBuffers:ce,useProgram:le,setBlending:B,setMaterial:fe,setFlipSided:V,setCullFace:H,setLineWidth:U,setPolygonOffset:pe,setScissorTest:W,activeTexture:G,bindTexture:me,unbindTexture:he,compressedTexImage2D:ge,compressedTexImage3D:_e,texImage2D:q,texImage3D:J,updateUBOMapping:Te,uniformBlockBinding:Ee,texStorage2D:Se,texStorage3D:K,texSubImage2D:ve,texSubImage3D:ye,compressedTexSubImage2D:be,compressedTexSubImage3D:xe,scissor:Ce,viewport:we,reset:De}}function co(e,t,n,f,m,h,_){let v=m.isWebGL2,y=m.maxTextures,b=m.maxCubemapSize,x=m.maxTextureSize,S=m.maxSamples,C=t.has(`WEBGL_multisampled_render_to_texture`)?t.get(`WEBGL_multisampled_render_to_texture`):null,w=typeof navigator>`u`?!1:/OculusBrowser/g.test(navigator.userAgent),T=new WeakMap,E,D=new WeakMap,O=!1;try{O=typeof OffscreenCanvas<`u`&&new OffscreenCanvas(1,1).getContext(`2d`)!==null}catch{}function k(e,t){return O?new OffscreenCanvas(e,t):we(`canvas`)}function A(e,t,n,r){let i=1;if((e.width>r||e.height>r)&&(i=r/Math.max(e.width,e.height)),i<1||t===!0)if(typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap){let r=t?ve:Math.floor,a=r(i*e.width),o=r(i*e.height);E===void 0&&(E=k(a,o));let s=n?k(a,o):E;return s.width=a,s.height=o,s.getContext(`2d`).drawImage(e,0,0,a,o),console.warn(`THREE.WebGLRenderer: Texture has been resized from (`+e.width+`x`+e.height+`) to (`+a+`x`+o+`).`),s}else return`data`in e&&console.warn(`THREE.WebGLRenderer: Image in DataTexture is too big (`+e.width+`x`+e.height+`).`),e;return e}function ee(e){return ge(e.width)&&ge(e.height)}function te(e){return v?!1:e.wrapS!==1001||e.wrapT!==1001||e.minFilter!==1003&&e.minFilter!==1006}function j(e,t){return e.generateMipmaps&&t&&e.minFilter!==1003&&e.minFilter!==1006}function M(t){e.generateMipmap(t)}function N(n,r,i,a,o=!1){if(v===!1)return r;if(n!==null){if(e[n]!==void 0)return e[n];console.warn(`THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '`+n+`'`)}let s=r;if(r===e.RED&&(i===e.FLOAT&&(s=e.R32F),i===e.HALF_FLOAT&&(s=e.R16F),i===e.UNSIGNED_BYTE&&(s=e.R8)),r===e.RED_INTEGER&&(i===e.UNSIGNED_BYTE&&(s=e.R8UI),i===e.UNSIGNED_SHORT&&(s=e.R16UI),i===e.UNSIGNED_INT&&(s=e.R32UI),i===e.BYTE&&(s=e.R8I),i===e.SHORT&&(s=e.R16I),i===e.INT&&(s=e.R32I)),r===e.RG&&(i===e.FLOAT&&(s=e.RG32F),i===e.HALF_FLOAT&&(s=e.RG16F),i===e.UNSIGNED_BYTE&&(s=e.RG8)),r===e.RGBA){let t=o?ne:Y.getTransfer(a);i===e.FLOAT&&(s=e.RGBA32F),i===e.HALF_FLOAT&&(s=e.RGBA16F),i===e.UNSIGNED_BYTE&&(s=t===`srgb`?e.SRGB8_ALPHA8:e.RGBA8),i===e.UNSIGNED_SHORT_4_4_4_4&&(s=e.RGBA4),i===e.UNSIGNED_SHORT_5_5_5_1&&(s=e.RGB5_A1)}return(s===e.R16F||s===e.R32F||s===e.RG16F||s===e.RG32F||s===e.RGBA16F||s===e.RGBA32F)&&t.get(`EXT_color_buffer_float`),s}function P(e,t,n){return j(e,n)===!0||e.isFramebufferTexture&&e.minFilter!==1003&&e.minFilter!==1006?Math.log2(Math.max(t.width,t.height))+1:e.mipmaps!==void 0&&e.mipmaps.length>0?e.mipmaps.length:e.isCompressedTexture&&Array.isArray(e.image)?t.mipmaps.length:1}function re(t){return t===1003||t===1004||t===1005?e.NEAREST:e.LINEAR}function ae(e){let t=e.target;t.removeEventListener(`dispose`,ae),I(t),t.isVideoTexture&&T.delete(t)}function F(e){let t=e.target;t.removeEventListener(`dispose`,F),se(t)}function I(e){let t=f.get(e);if(t.__webglInit===void 0)return;let n=e.source,r=D.get(n);if(r){let i=r[t.__cacheKey];i.usedTimes--,i.usedTimes===0&&oe(e),Object.keys(r).length===0&&D.delete(n)}f.remove(e)}function oe(t){let n=f.get(t);e.deleteTexture(n.__webglTexture);let r=t.source,i=D.get(r);delete i[n.__cacheKey],_.memory.textures--}function se(t){let n=t.texture,r=f.get(t),i=f.get(n);if(i.__webglTexture!==void 0&&(e.deleteTexture(i.__webglTexture),_.memory.textures--),t.depthTexture&&t.depthTexture.dispose(),t.isWebGLCubeRenderTarget)for(let t=0;t<6;t++){if(Array.isArray(r.__webglFramebuffer[t]))for(let n=0;n<r.__webglFramebuffer[t].length;n++)e.deleteFramebuffer(r.__webglFramebuffer[t][n]);else e.deleteFramebuffer(r.__webglFramebuffer[t]);r.__webglDepthbuffer&&e.deleteRenderbuffer(r.__webglDepthbuffer[t])}else{if(Array.isArray(r.__webglFramebuffer))for(let t=0;t<r.__webglFramebuffer.length;t++)e.deleteFramebuffer(r.__webglFramebuffer[t]);else e.deleteFramebuffer(r.__webglFramebuffer);if(r.__webglDepthbuffer&&e.deleteRenderbuffer(r.__webglDepthbuffer),r.__webglMultisampledFramebuffer&&e.deleteFramebuffer(r.__webglMultisampledFramebuffer),r.__webglColorRenderbuffer)for(let t=0;t<r.__webglColorRenderbuffer.length;t++)r.__webglColorRenderbuffer[t]&&e.deleteRenderbuffer(r.__webglColorRenderbuffer[t]);r.__webglDepthRenderbuffer&&e.deleteRenderbuffer(r.__webglDepthRenderbuffer)}if(t.isWebGLMultipleRenderTargets)for(let t=0,r=n.length;t<r;t++){let r=f.get(n[t]);r.__webglTexture&&(e.deleteTexture(r.__webglTexture),_.memory.textures--),f.remove(n[t])}f.remove(n),f.remove(t)}let L=0;function R(){L=0}function z(){let e=L;return e>=y&&console.warn(`THREE.WebGLTextures: Trying to use `+e+` texture units while this GPU supports only `+y),L+=1,e}function ce(e){let t=[];return t.push(e.wrapS),t.push(e.wrapT),t.push(e.wrapR||0),t.push(e.magFilter),t.push(e.minFilter),t.push(e.anisotropy),t.push(e.internalFormat),t.push(e.format),t.push(e.type),t.push(e.generateMipmaps),t.push(e.premultiplyAlpha),t.push(e.flipY),t.push(e.unpackAlignment),t.push(e.colorSpace),t.join()}function le(t,r){let i=f.get(t);if(t.isVideoTexture&&Ce(t),t.isRenderTargetTexture===!1&&t.version>0&&i.__version!==t.version){let e=t.image;if(e===null)console.warn(`THREE.WebGLRenderer: Texture marked for update but no image data found.`);else if(e.complete===!1)console.warn(`THREE.WebGLRenderer: Texture marked for update but image is incomplete`);else{W(i,t,r);return}}n.bindTexture(e.TEXTURE_2D,i.__webglTexture,e.TEXTURE0+r)}function ue(t,r){let i=f.get(t);if(t.version>0&&i.__version!==t.version){W(i,t,r);return}n.bindTexture(e.TEXTURE_2D_ARRAY,i.__webglTexture,e.TEXTURE0+r)}function de(t,r){let i=f.get(t);if(t.version>0&&i.__version!==t.version){W(i,t,r);return}n.bindTexture(e.TEXTURE_3D,i.__webglTexture,e.TEXTURE0+r)}function B(t,r){let i=f.get(t);if(t.version>0&&i.__version!==t.version){G(i,t,r);return}n.bindTexture(e.TEXTURE_CUBE_MAP,i.__webglTexture,e.TEXTURE0+r)}let fe={[r]:e.REPEAT,[i]:e.CLAMP_TO_EDGE,[a]:e.MIRRORED_REPEAT},V={[o]:e.NEAREST,[s]:e.NEAREST_MIPMAP_NEAREST,[c]:e.NEAREST_MIPMAP_LINEAR,[l]:e.LINEAR,[u]:e.LINEAR_MIPMAP_NEAREST,[d]:e.LINEAR_MIPMAP_LINEAR},H={512:e.NEVER,519:e.ALWAYS,513:e.LESS,515:e.LEQUAL,514:e.EQUAL,518:e.GEQUAL,516:e.GREATER,517:e.NOTEQUAL};function U(n,r,i){if(i?(e.texParameteri(n,e.TEXTURE_WRAP_S,fe[r.wrapS]),e.texParameteri(n,e.TEXTURE_WRAP_T,fe[r.wrapT]),(n===e.TEXTURE_3D||n===e.TEXTURE_2D_ARRAY)&&e.texParameteri(n,e.TEXTURE_WRAP_R,fe[r.wrapR]),e.texParameteri(n,e.TEXTURE_MAG_FILTER,V[r.magFilter]),e.texParameteri(n,e.TEXTURE_MIN_FILTER,V[r.minFilter])):(e.texParameteri(n,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(n,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),(n===e.TEXTURE_3D||n===e.TEXTURE_2D_ARRAY)&&e.texParameteri(n,e.TEXTURE_WRAP_R,e.CLAMP_TO_EDGE),(r.wrapS!==1001||r.wrapT!==1001)&&console.warn(`THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.`),e.texParameteri(n,e.TEXTURE_MAG_FILTER,re(r.magFilter)),e.texParameteri(n,e.TEXTURE_MIN_FILTER,re(r.minFilter)),r.minFilter!==1003&&r.minFilter!==1006&&console.warn(`THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.`)),r.compareFunction&&(e.texParameteri(n,e.TEXTURE_COMPARE_MODE,e.COMPARE_REF_TO_TEXTURE),e.texParameteri(n,e.TEXTURE_COMPARE_FUNC,H[r.compareFunction])),t.has(`EXT_texture_filter_anisotropic`)===!0){let i=t.get(`EXT_texture_filter_anisotropic`);if(r.magFilter===1003||r.minFilter!==1005&&r.minFilter!==1008||r.type===1015&&t.has(`OES_texture_float_linear`)===!1||v===!1&&r.type===1016&&t.has(`OES_texture_half_float_linear`)===!1)return;(r.anisotropy>1||f.get(r).__currentAnisotropy)&&(e.texParameterf(n,i.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(r.anisotropy,m.getMaxAnisotropy())),f.get(r).__currentAnisotropy=r.anisotropy)}}function pe(t,n){let r=!1;t.__webglInit===void 0&&(t.__webglInit=!0,n.addEventListener(`dispose`,ae));let i=n.source,a=D.get(i);a===void 0&&(a={},D.set(i,a));let o=ce(n);if(o!==t.__cacheKey){a[o]===void 0&&(a[o]={texture:e.createTexture(),usedTimes:0},_.memory.textures++,r=!0),a[o].usedTimes++;let i=a[t.__cacheKey];i!==void 0&&(a[t.__cacheKey].usedTimes--,i.usedTimes===0&&oe(n)),t.__cacheKey=o,t.__webglTexture=a[o].texture}return r}function W(t,r,i){let a=e.TEXTURE_2D;(r.isDataArrayTexture||r.isCompressedArrayTexture)&&(a=e.TEXTURE_2D_ARRAY),r.isData3DTexture&&(a=e.TEXTURE_3D);let o=pe(t,r),s=r.source;n.bindTexture(a,t.__webglTexture,e.TEXTURE0+i);let c=f.get(s);if(s.version!==c.__version||o===!0){n.activeTexture(e.TEXTURE0+i);let t=Y.getPrimaries(Y.workingColorSpace),l=r.colorSpace===``?null:Y.getPrimaries(r.colorSpace),u=r.colorSpace===``||t===l?e.NONE:e.BROWSER_DEFAULT_WEBGL;e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,r.flipY),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,r.premultiplyAlpha),e.pixelStorei(e.UNPACK_ALIGNMENT,r.unpackAlignment),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,u);let d=te(r)&&ee(r.image)===!1,f=A(r.image,d,!1,x);f=Te(r,f);let m=ee(f)||v,_=h.convert(r.format,r.colorSpace),y=h.convert(r.type),b=N(r.internalFormat,_,y,r.colorSpace,r.isVideoTexture);U(a,r,m);let S,C=r.mipmaps,w=v&&r.isVideoTexture!==!0&&b!==36196,T=c.__version===void 0||o===!0,E=P(r,f,m);if(r.isDepthTexture)b=e.DEPTH_COMPONENT,v?b=r.type===1015?e.DEPTH_COMPONENT32F:r.type===1014?e.DEPTH_COMPONENT24:r.type===1020?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT16:r.type===1015&&console.error(`WebGLRenderer: Floating point depth texture requires WebGL2.`),r.format===1026&&b===e.DEPTH_COMPONENT&&r.type!==1012&&r.type!==1014&&(console.warn(`THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.`),r.type=p,y=h.convert(r.type)),r.format===1027&&b===e.DEPTH_COMPONENT&&(b=e.DEPTH_STENCIL,r.type!==1020&&(console.warn(`THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.`),r.type=g,y=h.convert(r.type))),T&&(w?n.texStorage2D(e.TEXTURE_2D,1,b,f.width,f.height):n.texImage2D(e.TEXTURE_2D,0,b,f.width,f.height,0,_,y,null));else if(r.isDataTexture)if(C.length>0&&m){w&&T&&n.texStorage2D(e.TEXTURE_2D,E,b,C[0].width,C[0].height);for(let t=0,r=C.length;t<r;t++)S=C[t],w?n.texSubImage2D(e.TEXTURE_2D,t,0,0,S.width,S.height,_,y,S.data):n.texImage2D(e.TEXTURE_2D,t,b,S.width,S.height,0,_,y,S.data);r.generateMipmaps=!1}else w?(T&&n.texStorage2D(e.TEXTURE_2D,E,b,f.width,f.height),n.texSubImage2D(e.TEXTURE_2D,0,0,0,f.width,f.height,_,y,f.data)):n.texImage2D(e.TEXTURE_2D,0,b,f.width,f.height,0,_,y,f.data);else if(r.isCompressedTexture)if(r.isCompressedArrayTexture){w&&T&&n.texStorage3D(e.TEXTURE_2D_ARRAY,E,b,C[0].width,C[0].height,f.depth);for(let t=0,i=C.length;t<i;t++)S=C[t],r.format===1023?w?n.texSubImage3D(e.TEXTURE_2D_ARRAY,t,0,0,0,S.width,S.height,f.depth,_,y,S.data):n.texImage3D(e.TEXTURE_2D_ARRAY,t,b,S.width,S.height,f.depth,0,_,y,S.data):_===null?console.warn(`THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()`):w?n.compressedTexSubImage3D(e.TEXTURE_2D_ARRAY,t,0,0,0,S.width,S.height,f.depth,_,S.data,0,0):n.compressedTexImage3D(e.TEXTURE_2D_ARRAY,t,b,S.width,S.height,f.depth,0,S.data,0,0)}else{w&&T&&n.texStorage2D(e.TEXTURE_2D,E,b,C[0].width,C[0].height);for(let t=0,i=C.length;t<i;t++)S=C[t],r.format===1023?w?n.texSubImage2D(e.TEXTURE_2D,t,0,0,S.width,S.height,_,y,S.data):n.texImage2D(e.TEXTURE_2D,t,b,S.width,S.height,0,_,y,S.data):_===null?console.warn(`THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()`):w?n.compressedTexSubImage2D(e.TEXTURE_2D,t,0,0,S.width,S.height,_,S.data):n.compressedTexImage2D(e.TEXTURE_2D,t,b,S.width,S.height,0,S.data)}else if(r.isDataArrayTexture)w?(T&&n.texStorage3D(e.TEXTURE_2D_ARRAY,E,b,f.width,f.height,f.depth),n.texSubImage3D(e.TEXTURE_2D_ARRAY,0,0,0,0,f.width,f.height,f.depth,_,y,f.data)):n.texImage3D(e.TEXTURE_2D_ARRAY,0,b,f.width,f.height,f.depth,0,_,y,f.data);else if(r.isData3DTexture)w?(T&&n.texStorage3D(e.TEXTURE_3D,E,b,f.width,f.height,f.depth),n.texSubImage3D(e.TEXTURE_3D,0,0,0,0,f.width,f.height,f.depth,_,y,f.data)):n.texImage3D(e.TEXTURE_3D,0,b,f.width,f.height,f.depth,0,_,y,f.data);else if(r.isFramebufferTexture){if(T)if(w)n.texStorage2D(e.TEXTURE_2D,E,b,f.width,f.height);else{let t=f.width,r=f.height;for(let i=0;i<E;i++)n.texImage2D(e.TEXTURE_2D,i,b,t,r,0,_,y,null),t>>=1,r>>=1}}else if(C.length>0&&m){w&&T&&n.texStorage2D(e.TEXTURE_2D,E,b,C[0].width,C[0].height);for(let t=0,r=C.length;t<r;t++)S=C[t],w?n.texSubImage2D(e.TEXTURE_2D,t,0,0,_,y,S):n.texImage2D(e.TEXTURE_2D,t,b,_,y,S);r.generateMipmaps=!1}else w?(T&&n.texStorage2D(e.TEXTURE_2D,E,b,f.width,f.height),n.texSubImage2D(e.TEXTURE_2D,0,0,0,_,y,f)):n.texImage2D(e.TEXTURE_2D,0,b,_,y,f);j(r,m)&&M(a),c.__version=s.version,r.onUpdate&&r.onUpdate(r)}t.__version=r.version}function G(t,r,i){if(r.image.length!==6)return;let a=pe(t,r),o=r.source;n.bindTexture(e.TEXTURE_CUBE_MAP,t.__webglTexture,e.TEXTURE0+i);let s=f.get(o);if(o.version!==s.__version||a===!0){n.activeTexture(e.TEXTURE0+i);let t=Y.getPrimaries(Y.workingColorSpace),c=r.colorSpace===``?null:Y.getPrimaries(r.colorSpace),l=r.colorSpace===``||t===c?e.NONE:e.BROWSER_DEFAULT_WEBGL;e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,r.flipY),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,r.premultiplyAlpha),e.pixelStorei(e.UNPACK_ALIGNMENT,r.unpackAlignment),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,l);let u=r.isCompressedTexture||r.image[0].isCompressedTexture,d=r.image[0]&&r.image[0].isDataTexture,f=[];for(let e=0;e<6;e++)!u&&!d?f[e]=A(r.image[e],!1,!0,b):f[e]=d?r.image[e].image:r.image[e],f[e]=Te(r,f[e]);let p=f[0],m=ee(p)||v,g=h.convert(r.format,r.colorSpace),_=h.convert(r.type),y=N(r.internalFormat,g,_,r.colorSpace),x=v&&r.isVideoTexture!==!0,S=s.__version===void 0||a===!0,C=P(r,p,m);U(e.TEXTURE_CUBE_MAP,r,m);let w;if(u){x&&S&&n.texStorage2D(e.TEXTURE_CUBE_MAP,C,y,p.width,p.height);for(let t=0;t<6;t++){w=f[t].mipmaps;for(let i=0;i<w.length;i++){let a=w[i];r.format===1023?x?n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,i,0,0,a.width,a.height,g,_,a.data):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,i,y,a.width,a.height,0,g,_,a.data):g===null?console.warn(`THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()`):x?n.compressedTexSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,i,0,0,a.width,a.height,g,a.data):n.compressedTexImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,i,y,a.width,a.height,0,a.data)}}}else{w=r.mipmaps,x&&S&&(w.length>0&&C++,n.texStorage2D(e.TEXTURE_CUBE_MAP,C,y,f[0].width,f[0].height));for(let t=0;t<6;t++)if(d){x?n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,0,0,f[t].width,f[t].height,g,_,f[t].data):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,y,f[t].width,f[t].height,0,g,_,f[t].data);for(let r=0;r<w.length;r++){let i=w[r].image[t].image;x?n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r+1,0,0,i.width,i.height,g,_,i.data):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r+1,y,i.width,i.height,0,g,_,i.data)}}else{x?n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,0,0,g,_,f[t]):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,y,g,_,f[t]);for(let r=0;r<w.length;r++){let i=w[r];x?n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r+1,0,0,g,_,i.image[t]):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r+1,y,g,_,i.image[t])}}}j(r,m)&&M(e.TEXTURE_CUBE_MAP),s.__version=o.version,r.onUpdate&&r.onUpdate(r)}t.__version=r.version}function me(t,r,i,a,o,s){let c=h.convert(i.format,i.colorSpace),l=h.convert(i.type),u=N(i.internalFormat,c,l,i.colorSpace);if(!f.get(r).__hasExternalTextures){let t=Math.max(1,r.width>>s),i=Math.max(1,r.height>>s);o===e.TEXTURE_3D||o===e.TEXTURE_2D_ARRAY?n.texImage3D(o,s,u,t,i,r.depth,0,c,l,null):n.texImage2D(o,s,u,t,i,0,c,l,null)}n.bindFramebuffer(e.FRAMEBUFFER,t),J(r)?C.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER,a,o,f.get(i).__webglTexture,0,q(r)):(o===e.TEXTURE_2D||o>=e.TEXTURE_CUBE_MAP_POSITIVE_X&&o<=e.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&e.framebufferTexture2D(e.FRAMEBUFFER,a,o,f.get(i).__webglTexture,s),n.bindFramebuffer(e.FRAMEBUFFER,null)}function he(t,n,r){if(e.bindRenderbuffer(e.RENDERBUFFER,t),n.depthBuffer&&!n.stencilBuffer){let i=v===!0?e.DEPTH_COMPONENT24:e.DEPTH_COMPONENT16;if(r||J(n)){let t=n.depthTexture;t&&t.isDepthTexture&&(t.type===1015?i=e.DEPTH_COMPONENT32F:t.type===1014&&(i=e.DEPTH_COMPONENT24));let r=q(n);J(n)?C.renderbufferStorageMultisampleEXT(e.RENDERBUFFER,r,i,n.width,n.height):e.renderbufferStorageMultisample(e.RENDERBUFFER,r,i,n.width,n.height)}else e.renderbufferStorage(e.RENDERBUFFER,i,n.width,n.height);e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,t)}else if(n.depthBuffer&&n.stencilBuffer){let i=q(n);r&&J(n)===!1?e.renderbufferStorageMultisample(e.RENDERBUFFER,i,e.DEPTH24_STENCIL8,n.width,n.height):J(n)?C.renderbufferStorageMultisampleEXT(e.RENDERBUFFER,i,e.DEPTH24_STENCIL8,n.width,n.height):e.renderbufferStorage(e.RENDERBUFFER,e.DEPTH_STENCIL,n.width,n.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.RENDERBUFFER,t)}else{let t=n.isWebGLMultipleRenderTargets===!0?n.texture:[n.texture];for(let i=0;i<t.length;i++){let a=t[i],o=h.convert(a.format,a.colorSpace),s=h.convert(a.type),c=N(a.internalFormat,o,s,a.colorSpace),l=q(n);r&&J(n)===!1?e.renderbufferStorageMultisample(e.RENDERBUFFER,l,c,n.width,n.height):J(n)?C.renderbufferStorageMultisampleEXT(e.RENDERBUFFER,l,c,n.width,n.height):e.renderbufferStorage(e.RENDERBUFFER,c,n.width,n.height)}}e.bindRenderbuffer(e.RENDERBUFFER,null)}function _e(t,r){if(r&&r.isWebGLCubeRenderTarget)throw Error(`Depth Texture with cube render targets is not supported`);if(n.bindFramebuffer(e.FRAMEBUFFER,t),!(r.depthTexture&&r.depthTexture.isDepthTexture))throw Error(`renderTarget.depthTexture must be an instance of THREE.DepthTexture`);(!f.get(r.depthTexture).__webglTexture||r.depthTexture.image.width!==r.width||r.depthTexture.image.height!==r.height)&&(r.depthTexture.image.width=r.width,r.depthTexture.image.height=r.height,r.depthTexture.needsUpdate=!0),le(r.depthTexture,0);let i=f.get(r.depthTexture).__webglTexture,a=q(r);if(r.depthTexture.format===1026)J(r)?C.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.TEXTURE_2D,i,0,a):e.framebufferTexture2D(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.TEXTURE_2D,i,0);else if(r.depthTexture.format===1027)J(r)?C.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.TEXTURE_2D,i,0,a):e.framebufferTexture2D(e.FRAMEBUFFER,e.DEPTH_STENCIL_ATTACHMENT,e.TEXTURE_2D,i,0);else throw Error(`Unknown depthTexture format`)}function ye(t){let r=f.get(t),i=t.isWebGLCubeRenderTarget===!0;if(t.depthTexture&&!r.__autoAllocateDepthBuffer){if(i)throw Error(`target.depthTexture not supported in Cube render targets`);_e(r.__webglFramebuffer,t)}else if(i){r.__webglDepthbuffer=[];for(let i=0;i<6;i++)n.bindFramebuffer(e.FRAMEBUFFER,r.__webglFramebuffer[i]),r.__webglDepthbuffer[i]=e.createRenderbuffer(),he(r.__webglDepthbuffer[i],t,!1)}else n.bindFramebuffer(e.FRAMEBUFFER,r.__webglFramebuffer),r.__webglDepthbuffer=e.createRenderbuffer(),he(r.__webglDepthbuffer,t,!1);n.bindFramebuffer(e.FRAMEBUFFER,null)}function be(t,n,r){let i=f.get(t);n!==void 0&&me(i.__webglFramebuffer,t,t.texture,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,0),r!==void 0&&ye(t)}function xe(t){let r=t.texture,i=f.get(t),a=f.get(r);t.addEventListener(`dispose`,F),t.isWebGLMultipleRenderTargets!==!0&&(a.__webglTexture===void 0&&(a.__webglTexture=e.createTexture()),a.__version=r.version,_.memory.textures++);let o=t.isWebGLCubeRenderTarget===!0,s=t.isWebGLMultipleRenderTargets===!0,c=ee(t)||v;if(o){i.__webglFramebuffer=[];for(let t=0;t<6;t++)if(v&&r.mipmaps&&r.mipmaps.length>0){i.__webglFramebuffer[t]=[];for(let n=0;n<r.mipmaps.length;n++)i.__webglFramebuffer[t][n]=e.createFramebuffer()}else i.__webglFramebuffer[t]=e.createFramebuffer()}else{if(v&&r.mipmaps&&r.mipmaps.length>0){i.__webglFramebuffer=[];for(let t=0;t<r.mipmaps.length;t++)i.__webglFramebuffer[t]=e.createFramebuffer()}else i.__webglFramebuffer=e.createFramebuffer();if(s)if(m.drawBuffers){let n=t.texture;for(let t=0,r=n.length;t<r;t++){let r=f.get(n[t]);r.__webglTexture===void 0&&(r.__webglTexture=e.createTexture(),_.memory.textures++)}}else console.warn(`THREE.WebGLRenderer: WebGLMultipleRenderTargets can only be used with WebGL2 or WEBGL_draw_buffers extension.`);if(v&&t.samples>0&&J(t)===!1){let a=s?r:[r];i.__webglMultisampledFramebuffer=e.createFramebuffer(),i.__webglColorRenderbuffer=[],n.bindFramebuffer(e.FRAMEBUFFER,i.__webglMultisampledFramebuffer);for(let n=0;n<a.length;n++){let r=a[n];i.__webglColorRenderbuffer[n]=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,i.__webglColorRenderbuffer[n]);let o=h.convert(r.format,r.colorSpace),s=h.convert(r.type),c=N(r.internalFormat,o,s,r.colorSpace,t.isXRRenderTarget===!0),l=q(t);e.renderbufferStorageMultisample(e.RENDERBUFFER,l,c,t.width,t.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+n,e.RENDERBUFFER,i.__webglColorRenderbuffer[n])}e.bindRenderbuffer(e.RENDERBUFFER,null),t.depthBuffer&&(i.__webglDepthRenderbuffer=e.createRenderbuffer(),he(i.__webglDepthRenderbuffer,t,!0)),n.bindFramebuffer(e.FRAMEBUFFER,null)}}if(o){n.bindTexture(e.TEXTURE_CUBE_MAP,a.__webglTexture),U(e.TEXTURE_CUBE_MAP,r,c);for(let n=0;n<6;n++)if(v&&r.mipmaps&&r.mipmaps.length>0)for(let a=0;a<r.mipmaps.length;a++)me(i.__webglFramebuffer[n][a],t,r,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_X+n,a);else me(i.__webglFramebuffer[n],t,r,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_X+n,0);j(r,c)&&M(e.TEXTURE_CUBE_MAP),n.unbindTexture()}else if(s){let r=t.texture;for(let a=0,o=r.length;a<o;a++){let o=r[a],s=f.get(o);n.bindTexture(e.TEXTURE_2D,s.__webglTexture),U(e.TEXTURE_2D,o,c),me(i.__webglFramebuffer,t,o,e.COLOR_ATTACHMENT0+a,e.TEXTURE_2D,0),j(o,c)&&M(e.TEXTURE_2D)}n.unbindTexture()}else{let o=e.TEXTURE_2D;if((t.isWebGL3DRenderTarget||t.isWebGLArrayRenderTarget)&&(v?o=t.isWebGL3DRenderTarget?e.TEXTURE_3D:e.TEXTURE_2D_ARRAY:console.error(`THREE.WebGLTextures: THREE.Data3DTexture and THREE.DataArrayTexture only supported with WebGL2.`)),n.bindTexture(o,a.__webglTexture),U(o,r,c),v&&r.mipmaps&&r.mipmaps.length>0)for(let n=0;n<r.mipmaps.length;n++)me(i.__webglFramebuffer[n],t,r,e.COLOR_ATTACHMENT0,o,n);else me(i.__webglFramebuffer,t,r,e.COLOR_ATTACHMENT0,o,0);j(r,c)&&M(o),n.unbindTexture()}t.depthBuffer&&ye(t)}function Se(t){let r=ee(t)||v,i=t.isWebGLMultipleRenderTargets===!0?t.texture:[t.texture];for(let a=0,o=i.length;a<o;a++){let o=i[a];if(j(o,r)){let r=t.isWebGLCubeRenderTarget?e.TEXTURE_CUBE_MAP:e.TEXTURE_2D,i=f.get(o).__webglTexture;n.bindTexture(r,i),M(r),n.unbindTexture()}}}function K(t){if(v&&t.samples>0&&J(t)===!1){let r=t.isWebGLMultipleRenderTargets?t.texture:[t.texture],i=t.width,a=t.height,o=e.COLOR_BUFFER_BIT,s=[],c=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,l=f.get(t),u=t.isWebGLMultipleRenderTargets===!0;if(u)for(let t=0;t<r.length;t++)n.bindFramebuffer(e.FRAMEBUFFER,l.__webglMultisampledFramebuffer),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.RENDERBUFFER,null),n.bindFramebuffer(e.FRAMEBUFFER,l.__webglFramebuffer),e.framebufferTexture2D(e.DRAW_FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.TEXTURE_2D,null,0);n.bindFramebuffer(e.READ_FRAMEBUFFER,l.__webglMultisampledFramebuffer),n.bindFramebuffer(e.DRAW_FRAMEBUFFER,l.__webglFramebuffer);for(let n=0;n<r.length;n++){s.push(e.COLOR_ATTACHMENT0+n),t.depthBuffer&&s.push(c);let d=l.__ignoreDepthValues!==void 0&&l.__ignoreDepthValues;if(d===!1&&(t.depthBuffer&&(o|=e.DEPTH_BUFFER_BIT),t.stencilBuffer&&(o|=e.STENCIL_BUFFER_BIT)),u&&e.framebufferRenderbuffer(e.READ_FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.RENDERBUFFER,l.__webglColorRenderbuffer[n]),d===!0&&(e.invalidateFramebuffer(e.READ_FRAMEBUFFER,[c]),e.invalidateFramebuffer(e.DRAW_FRAMEBUFFER,[c])),u){let t=f.get(r[n]).__webglTexture;e.framebufferTexture2D(e.DRAW_FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t,0)}e.blitFramebuffer(0,0,i,a,0,0,i,a,o,e.NEAREST),w&&e.invalidateFramebuffer(e.READ_FRAMEBUFFER,s)}if(n.bindFramebuffer(e.READ_FRAMEBUFFER,null),n.bindFramebuffer(e.DRAW_FRAMEBUFFER,null),u)for(let t=0;t<r.length;t++){n.bindFramebuffer(e.FRAMEBUFFER,l.__webglMultisampledFramebuffer),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.RENDERBUFFER,l.__webglColorRenderbuffer[t]);let i=f.get(r[t]).__webglTexture;n.bindFramebuffer(e.FRAMEBUFFER,l.__webglFramebuffer),e.framebufferTexture2D(e.DRAW_FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.TEXTURE_2D,i,0)}n.bindFramebuffer(e.DRAW_FRAMEBUFFER,l.__webglMultisampledFramebuffer)}}function q(e){return Math.min(S,e.samples)}function J(e){let n=f.get(e);return v&&e.samples>0&&t.has(`WEBGL_multisampled_render_to_texture`)===!0&&n.__useRenderToTexture!==!1}function Ce(e){let t=_.render.frame;T.get(e)!==t&&(T.set(e,t),e.update())}function Te(e,n){let r=e.colorSpace,i=e.format,a=e.type;return e.isCompressedTexture===!0||e.isVideoTexture===!0||e.format===1035||r!==`srgb-linear`&&r!==``&&(Y.getTransfer(r)===`srgb`?v===!1?t.has(`EXT_sRGB`)===!0&&i===1023?(e.format=ie,e.minFilter=l,e.generateMipmaps=!1):n=Fe.sRGBToLinear(n):(i!==1023||a!==1009)&&console.warn(`THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.`):console.error(`THREE.WebGLTextures: Unsupported texture color space:`,r)),n}this.allocateTextureUnit=z,this.resetTextureUnits=R,this.setTexture2D=le,this.setTexture2DArray=ue,this.setTexture3D=de,this.setTextureCube=B,this.rebindTextures=be,this.setupRenderTarget=xe,this.updateRenderTargetMipmap=Se,this.updateMultisampleRenderTarget=K,this.setupDepthRenderbuffer=ye,this.setupFrameBufferTexture=me,this.useMultisampledRTT=J}function lo(e,t,n){let r=n.isWebGL2;function i(n,i=``){let a,o=Y.getTransfer(i);if(n===1009)return e.UNSIGNED_BYTE;if(n===1017)return e.UNSIGNED_SHORT_4_4_4_4;if(n===1018)return e.UNSIGNED_SHORT_5_5_5_1;if(n===1010)return e.BYTE;if(n===1011)return e.SHORT;if(n===1012)return e.UNSIGNED_SHORT;if(n===1013)return e.INT;if(n===1014)return e.UNSIGNED_INT;if(n===1015)return e.FLOAT;if(n===1016)return r?e.HALF_FLOAT:(a=t.get(`OES_texture_half_float`),a===null?null:a.HALF_FLOAT_OES);if(n===1021)return e.ALPHA;if(n===1023)return e.RGBA;if(n===1024)return e.LUMINANCE;if(n===1025)return e.LUMINANCE_ALPHA;if(n===1026)return e.DEPTH_COMPONENT;if(n===1027)return e.DEPTH_STENCIL;if(n===1035)return a=t.get(`EXT_sRGB`),a===null?null:a.SRGB_ALPHA_EXT;if(n===1028)return e.RED;if(n===1029)return e.RED_INTEGER;if(n===1030)return e.RG;if(n===1031)return e.RG_INTEGER;if(n===1033)return e.RGBA_INTEGER;if(n===33776||n===33777||n===33778||n===33779)if(o===`srgb`)if(a=t.get(`WEBGL_compressed_texture_s3tc_srgb`),a!==null){if(n===33776)return a.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===33777)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===33778)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===33779)return a.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(a=t.get(`WEBGL_compressed_texture_s3tc`),a!==null){if(n===33776)return a.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===33777)return a.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===33778)return a.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===33779)return a.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(n===35840||n===35841||n===35842||n===35843)if(a=t.get(`WEBGL_compressed_texture_pvrtc`),a!==null){if(n===35840)return a.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===35841)return a.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===35842)return a.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===35843)return a.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(n===36196)return a=t.get(`WEBGL_compressed_texture_etc1`),a===null?null:a.COMPRESSED_RGB_ETC1_WEBGL;if(n===37492||n===37496)if(a=t.get(`WEBGL_compressed_texture_etc`),a!==null){if(n===37492)return o===`srgb`?a.COMPRESSED_SRGB8_ETC2:a.COMPRESSED_RGB8_ETC2;if(n===37496)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:a.COMPRESSED_RGBA8_ETC2_EAC}else return null;if(n===37808||n===37809||n===37810||n===37811||n===37812||n===37813||n===37814||n===37815||n===37816||n===37817||n===37818||n===37819||n===37820||n===37821)if(a=t.get(`WEBGL_compressed_texture_astc`),a!==null){if(n===37808)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:a.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===37809)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:a.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===37810)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:a.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===37811)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:a.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===37812)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:a.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===37813)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:a.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===37814)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:a.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===37815)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:a.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===37816)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:a.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===37817)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:a.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===37818)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:a.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===37819)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:a.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===37820)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:a.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===37821)return o===`srgb`?a.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:a.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(n===36492||n===36494||n===36495)if(a=t.get(`EXT_texture_compression_bptc`),a!==null){if(n===36492)return o===`srgb`?a.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:a.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===36494)return a.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===36495)return a.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(n===36283||n===36284||n===36285||n===36286)if(a=t.get(`EXT_texture_compression_rgtc`),a!==null){if(n===36492)return a.COMPRESSED_RED_RGTC1_EXT;if(n===36284)return a.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===36285)return a.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===36286)return a.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return n===1020?r?e.UNSIGNED_INT_24_8:(a=t.get(`WEBGL_depth_texture`),a===null?null:a.UNSIGNED_INT_24_8_WEBGL):e[n]===void 0?null:e[n]}return{convert:i}}var uo=class extends ar{constructor(e=[]){super(),this.isArrayCamera=!0,this.cameras=e}},fo=class extends qt{constructor(){super(),this.isGroup=!0,this.type=`Group`}},po={type:`move`},mo=class{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new fo,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new fo,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new X,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new X),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new fo,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new X,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new X),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){let t=this._hand;if(t)for(let n of e.hand.values())this._getHandJoint(t,n)}return this.dispatchEvent({type:`connected`,data:e}),this}disconnect(e){return this.dispatchEvent({type:`disconnected`,data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,n){let r=null,i=null,a=null,o=this._targetRay,s=this._grip,c=this._hand;if(e&&t.session.visibilityState!==`visible-blurred`){if(c&&e.hand){a=!0;for(let r of e.hand.values()){let e=t.getJointPose(r,n),i=this._getHandJoint(c,r);e!==null&&(i.matrix.fromArray(e.transform.matrix),i.matrix.decompose(i.position,i.rotation,i.scale),i.matrixWorldNeedsUpdate=!0,i.jointRadius=e.radius),i.visible=e!==null}let r=c.joints[`index-finger-tip`],i=c.joints[`thumb-tip`],o=r.position.distanceTo(i.position);c.inputState.pinching&&o>.025?(c.inputState.pinching=!1,this.dispatchEvent({type:`pinchend`,handedness:e.handedness,target:this})):!c.inputState.pinching&&o<=.015&&(c.inputState.pinching=!0,this.dispatchEvent({type:`pinchstart`,handedness:e.handedness,target:this}))}else s!==null&&e.gripSpace&&(i=t.getPose(e.gripSpace,n),i!==null&&(s.matrix.fromArray(i.transform.matrix),s.matrix.decompose(s.position,s.rotation,s.scale),s.matrixWorldNeedsUpdate=!0,i.linearVelocity?(s.hasLinearVelocity=!0,s.linearVelocity.copy(i.linearVelocity)):s.hasLinearVelocity=!1,i.angularVelocity?(s.hasAngularVelocity=!0,s.angularVelocity.copy(i.angularVelocity)):s.hasAngularVelocity=!1));o!==null&&(r=t.getPose(e.targetRaySpace,n),r===null&&i!==null&&(r=i),r!==null&&(o.matrix.fromArray(r.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,r.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(r.linearVelocity)):o.hasLinearVelocity=!1,r.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(r.angularVelocity)):o.hasAngularVelocity=!1,this.dispatchEvent(po)))}return o!==null&&(o.visible=r!==null),s!==null&&(s.visible=i!==null),c!==null&&(c.visible=a!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){let n=new fo;n.matrixAutoUpdate=!1,n.visible=!1,e.joints[t.jointName]=n,e.add(n)}return e.joints[t.jointName]}},ho=class extends F{constructor(e,t){super();let n=this,r=null,i=1,a=null,o=`local-floor`,s=1,c=null,l=null,u=null,d=null,m=null,h=null,b=t.getContextAttributes(),x=null,S=null,C=[],w=[],T=new K,E=null,D=new ar;D.layers.enable(1),D.viewport=new Ve;let O=new ar;O.layers.enable(2),O.viewport=new Ve;let k=[D,O],A=new uo;A.layers.enable(1),A.layers.enable(2);let ee=null,te=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(e){let t=C[e];return t===void 0&&(t=new mo,C[e]=t),t.getTargetRaySpace()},this.getControllerGrip=function(e){let t=C[e];return t===void 0&&(t=new mo,C[e]=t),t.getGripSpace()},this.getHand=function(e){let t=C[e];return t===void 0&&(t=new mo,C[e]=t),t.getHandSpace()};function j(e){let t=w.indexOf(e.inputSource);if(t===-1)return;let n=C[t];n!==void 0&&(n.update(e.inputSource,e.frame,c||a),n.dispatchEvent({type:e.type,data:e.inputSource}))}function ne(){r.removeEventListener(`select`,j),r.removeEventListener(`selectstart`,j),r.removeEventListener(`selectend`,j),r.removeEventListener(`squeeze`,j),r.removeEventListener(`squeezestart`,j),r.removeEventListener(`squeezeend`,j),r.removeEventListener(`end`,ne),r.removeEventListener(`inputsourceschange`,M);for(let e=0;e<C.length;e++){let t=w[e];t!==null&&(w[e]=null,C[e].disconnect(t))}ee=null,te=null,e.setRenderTarget(x),m=null,d=null,u=null,r=null,S=null,oe.stop(),n.isPresenting=!1,e.setPixelRatio(E),e.setSize(T.width,T.height,!1),n.dispatchEvent({type:`sessionend`})}this.setFramebufferScaleFactor=function(e){i=e,n.isPresenting===!0&&console.warn(`THREE.WebXRManager: Cannot change framebuffer scale while presenting.`)},this.setReferenceSpaceType=function(e){o=e,n.isPresenting===!0&&console.warn(`THREE.WebXRManager: Cannot change reference space type while presenting.`)},this.getReferenceSpace=function(){return c||a},this.setReferenceSpace=function(e){c=e},this.getBaseLayer=function(){return d===null?m:d},this.getBinding=function(){return u},this.getFrame=function(){return h},this.getSession=function(){return r},this.setSession=async function(l){if(r=l,r!==null){if(x=e.getRenderTarget(),r.addEventListener(`select`,j),r.addEventListener(`selectstart`,j),r.addEventListener(`selectend`,j),r.addEventListener(`squeeze`,j),r.addEventListener(`squeezestart`,j),r.addEventListener(`squeezeend`,j),r.addEventListener(`end`,ne),r.addEventListener(`inputsourceschange`,M),b.xrCompatible!==!0&&await t.makeXRCompatible(),E=e.getPixelRatio(),e.getSize(T),r.renderState.layers===void 0||e.capabilities.isWebGL2===!1){let n={antialias:r.renderState.layers!==void 0||b.antialias,alpha:!0,depth:b.depth,stencil:b.stencil,framebufferScaleFactor:i};m=new XRWebGLLayer(r,t,n),r.updateRenderState({baseLayer:m}),e.setPixelRatio(1),e.setSize(m.framebufferWidth,m.framebufferHeight,!1),S=new Ue(m.framebufferWidth,m.framebufferHeight,{format:_,type:f,colorSpace:e.outputColorSpace,stencilBuffer:b.stencil})}else{let n=null,a=null,o=null;b.depth&&(o=b.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,n=b.stencil?y:v,a=b.stencil?g:p);let s={colorFormat:t.RGBA8,depthFormat:o,scaleFactor:i};u=new XRWebGLBinding(r,t),d=u.createProjectionLayer(s),r.updateRenderState({layers:[d]}),e.setPixelRatio(1),e.setSize(d.textureWidth,d.textureHeight,!1),S=new Ue(d.textureWidth,d.textureHeight,{format:_,type:f,depthTexture:new ii(d.textureWidth,d.textureHeight,a,void 0,void 0,void 0,void 0,void 0,void 0,n),stencilBuffer:b.stencil,colorSpace:e.outputColorSpace,samples:b.antialias?4:0});let c=e.properties.get(S);c.__ignoreDepthValues=d.ignoreDepthValues}S.isXRRenderTarget=!0,this.setFoveation(s),c=null,a=await r.requestReferenceSpace(o),oe.setContext(r),oe.start(),n.isPresenting=!0,n.dispatchEvent({type:`sessionstart`})}},this.getEnvironmentBlendMode=function(){if(r!==null)return r.environmentBlendMode};function M(e){for(let t=0;t<e.removed.length;t++){let n=e.removed[t],r=w.indexOf(n);r>=0&&(w[r]=null,C[r].disconnect(n))}for(let t=0;t<e.added.length;t++){let n=e.added[t],r=w.indexOf(n);if(r===-1){for(let e=0;e<C.length;e++)if(e>=w.length){w.push(n),r=e;break}else if(w[e]===null){w[e]=n,r=e;break}if(r===-1)break}let i=C[r];i&&i.connect(n)}}let N=new X,P=new X;function re(e,t,n){N.setFromMatrixPosition(t.matrixWorld),P.setFromMatrixPosition(n.matrixWorld);let r=N.distanceTo(P),i=t.projectionMatrix.elements,a=n.projectionMatrix.elements,o=i[14]/(i[10]-1),s=i[14]/(i[10]+1),c=(i[9]+1)/i[5],l=(i[9]-1)/i[5],u=(i[8]-1)/i[0],d=(a[8]+1)/a[0],f=o*u,p=o*d,m=r/(-u+d),h=m*-u;t.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.translateX(h),e.translateZ(m),e.matrixWorld.compose(e.position,e.quaternion,e.scale),e.matrixWorldInverse.copy(e.matrixWorld).invert();let g=o+m,_=s+m,v=f-h,y=p+(r-h),b=c*s/_*g,x=l*s/_*g;e.projectionMatrix.makePerspective(v,y,b,x,g,_),e.projectionMatrixInverse.copy(e.projectionMatrix).invert()}function ie(e,t){t===null?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}this.updateCamera=function(e){if(r===null)return;A.near=O.near=D.near=e.near,A.far=O.far=D.far=e.far,(ee!==A.near||te!==A.far)&&(r.updateRenderState({depthNear:A.near,depthFar:A.far}),ee=A.near,te=A.far);let t=e.parent,n=A.cameras;ie(A,t);for(let e=0;e<n.length;e++)ie(n[e],t);n.length===2?re(A,D,O):A.projectionMatrix.copy(D.projectionMatrix),ae(e,A,t)};function ae(e,t,n){n===null?e.matrix.copy(t.matrixWorld):(e.matrix.copy(n.matrixWorld),e.matrix.invert(),e.matrix.multiply(t.matrixWorld)),e.matrix.decompose(e.position,e.quaternion,e.scale),e.updateMatrixWorld(!0),e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse),e.isPerspectiveCamera&&(e.fov=L*2*Math.atan(1/e.projectionMatrix.elements[5]),e.zoom=1)}this.getCamera=function(){return A},this.getFoveation=function(){if(!(d===null&&m===null))return s},this.setFoveation=function(e){s=e,d!==null&&(d.fixedFoveation=e),m!==null&&m.fixedFoveation!==void 0&&(m.fixedFoveation=e)};let F=null;function I(t,r){if(l=r.getViewerPose(c||a),h=r,l!==null){let t=l.views;m!==null&&(e.setRenderTargetFramebuffer(S,m.framebuffer),e.setRenderTarget(S));let n=!1;t.length!==A.cameras.length&&(A.cameras.length=0,n=!0);for(let r=0;r<t.length;r++){let i=t[r],a=null;if(m!==null)a=m.getViewport(i);else{let t=u.getViewSubImage(d,i);a=t.viewport,r===0&&(e.setRenderTargetTextures(S,t.colorTexture,d.ignoreDepthValues?void 0:t.depthStencilTexture),e.setRenderTarget(S))}let o=k[r];o===void 0&&(o=new ar,o.layers.enable(r),o.viewport=new Ve,k[r]=o),o.matrix.fromArray(i.transform.matrix),o.matrix.decompose(o.position,o.quaternion,o.scale),o.projectionMatrix.fromArray(i.projectionMatrix),o.projectionMatrixInverse.copy(o.projectionMatrix).invert(),o.viewport.set(a.x,a.y,a.width,a.height),r===0&&(A.matrix.copy(o.matrix),A.matrix.decompose(A.position,A.quaternion,A.scale)),n===!0&&A.cameras.push(o)}}for(let e=0;e<C.length;e++){let t=w[e],n=C[e];t!==null&&n!==void 0&&n.update(t,r,c||a)}F&&F(t,r),r.detectedPlanes&&n.dispatchEvent({type:`planesdetected`,data:r}),h=null}let oe=new vr;oe.setAnimationLoop(I),this.setAnimationLoop=function(e){F=e},this.dispose=function(){}}};function go(e,t){function n(e,t){e.matrixAutoUpdate===!0&&e.updateMatrix(),t.value.copy(e.matrix)}function r(t,n){n.color.getRGB(t.fogColor.value,$n(e)),n.isFog?(t.fogNear.value=n.near,t.fogFar.value=n.far):n.isFogExp2&&(t.fogDensity.value=n.density)}function i(e,t,n,r,i){t.isMeshBasicMaterial||t.isMeshLambertMaterial?a(e,t):t.isMeshToonMaterial?(a(e,t),d(e,t)):t.isMeshPhongMaterial?(a(e,t),u(e,t)):t.isMeshStandardMaterial?(a(e,t),f(e,t),t.isMeshPhysicalMaterial&&p(e,t,i)):t.isMeshMatcapMaterial?(a(e,t),m(e,t)):t.isMeshDepthMaterial?a(e,t):t.isMeshDistanceMaterial?(a(e,t),h(e,t)):t.isMeshNormalMaterial?a(e,t):t.isLineBasicMaterial?(o(e,t),t.isLineDashedMaterial&&s(e,t)):t.isPointsMaterial?c(e,t,n,r):t.isSpriteMaterial?l(e,t):t.isShadowMaterial?(e.color.value.copy(t.color),e.opacity.value=t.opacity):t.isShaderMaterial&&(t.uniformsNeedUpdate=!1)}function a(r,i){r.opacity.value=i.opacity,i.color&&r.diffuse.value.copy(i.color),i.emissive&&r.emissive.value.copy(i.emissive).multiplyScalar(i.emissiveIntensity),i.map&&(r.map.value=i.map,n(i.map,r.mapTransform)),i.alphaMap&&(r.alphaMap.value=i.alphaMap,n(i.alphaMap,r.alphaMapTransform)),i.bumpMap&&(r.bumpMap.value=i.bumpMap,n(i.bumpMap,r.bumpMapTransform),r.bumpScale.value=i.bumpScale,i.side===1&&(r.bumpScale.value*=-1)),i.normalMap&&(r.normalMap.value=i.normalMap,n(i.normalMap,r.normalMapTransform),r.normalScale.value.copy(i.normalScale),i.side===1&&r.normalScale.value.negate()),i.displacementMap&&(r.displacementMap.value=i.displacementMap,n(i.displacementMap,r.displacementMapTransform),r.displacementScale.value=i.displacementScale,r.displacementBias.value=i.displacementBias),i.emissiveMap&&(r.emissiveMap.value=i.emissiveMap,n(i.emissiveMap,r.emissiveMapTransform)),i.specularMap&&(r.specularMap.value=i.specularMap,n(i.specularMap,r.specularMapTransform)),i.alphaTest>0&&(r.alphaTest.value=i.alphaTest);let a=t.get(i).envMap;if(a&&(r.envMap.value=a,r.flipEnvMap.value=a.isCubeTexture&&a.isRenderTargetTexture===!1?-1:1,r.reflectivity.value=i.reflectivity,r.ior.value=i.ior,r.refractionRatio.value=i.refractionRatio),i.lightMap){r.lightMap.value=i.lightMap;let t=e._useLegacyLights===!0?Math.PI:1;r.lightMapIntensity.value=i.lightMapIntensity*t,n(i.lightMap,r.lightMapTransform)}i.aoMap&&(r.aoMap.value=i.aoMap,r.aoMapIntensity.value=i.aoMapIntensity,n(i.aoMap,r.aoMapTransform))}function o(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform))}function s(e,t){e.dashSize.value=t.dashSize,e.totalSize.value=t.dashSize+t.gapSize,e.scale.value=t.scale}function c(e,t,r,i){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.size.value=t.size*r,e.scale.value=i*.5,t.map&&(e.map.value=t.map,n(t.map,e.uvTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function l(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.rotation.value=t.rotation,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function u(e,t){e.specular.value.copy(t.specular),e.shininess.value=Math.max(t.shininess,1e-4)}function d(e,t){t.gradientMap&&(e.gradientMap.value=t.gradientMap)}function f(e,r){e.metalness.value=r.metalness,r.metalnessMap&&(e.metalnessMap.value=r.metalnessMap,n(r.metalnessMap,e.metalnessMapTransform)),e.roughness.value=r.roughness,r.roughnessMap&&(e.roughnessMap.value=r.roughnessMap,n(r.roughnessMap,e.roughnessMapTransform)),t.get(r).envMap&&(e.envMapIntensity.value=r.envMapIntensity)}function p(e,t,r){e.ior.value=t.ior,t.sheen>0&&(e.sheenColor.value.copy(t.sheenColor).multiplyScalar(t.sheen),e.sheenRoughness.value=t.sheenRoughness,t.sheenColorMap&&(e.sheenColorMap.value=t.sheenColorMap,n(t.sheenColorMap,e.sheenColorMapTransform)),t.sheenRoughnessMap&&(e.sheenRoughnessMap.value=t.sheenRoughnessMap,n(t.sheenRoughnessMap,e.sheenRoughnessMapTransform))),t.clearcoat>0&&(e.clearcoat.value=t.clearcoat,e.clearcoatRoughness.value=t.clearcoatRoughness,t.clearcoatMap&&(e.clearcoatMap.value=t.clearcoatMap,n(t.clearcoatMap,e.clearcoatMapTransform)),t.clearcoatRoughnessMap&&(e.clearcoatRoughnessMap.value=t.clearcoatRoughnessMap,n(t.clearcoatRoughnessMap,e.clearcoatRoughnessMapTransform)),t.clearcoatNormalMap&&(e.clearcoatNormalMap.value=t.clearcoatNormalMap,n(t.clearcoatNormalMap,e.clearcoatNormalMapTransform),e.clearcoatNormalScale.value.copy(t.clearcoatNormalScale),t.side===1&&e.clearcoatNormalScale.value.negate())),t.iridescence>0&&(e.iridescence.value=t.iridescence,e.iridescenceIOR.value=t.iridescenceIOR,e.iridescenceThicknessMinimum.value=t.iridescenceThicknessRange[0],e.iridescenceThicknessMaximum.value=t.iridescenceThicknessRange[1],t.iridescenceMap&&(e.iridescenceMap.value=t.iridescenceMap,n(t.iridescenceMap,e.iridescenceMapTransform)),t.iridescenceThicknessMap&&(e.iridescenceThicknessMap.value=t.iridescenceThicknessMap,n(t.iridescenceThicknessMap,e.iridescenceThicknessMapTransform))),t.transmission>0&&(e.transmission.value=t.transmission,e.transmissionSamplerMap.value=r.texture,e.transmissionSamplerSize.value.set(r.width,r.height),t.transmissionMap&&(e.transmissionMap.value=t.transmissionMap,n(t.transmissionMap,e.transmissionMapTransform)),e.thickness.value=t.thickness,t.thicknessMap&&(e.thicknessMap.value=t.thicknessMap,n(t.thicknessMap,e.thicknessMapTransform)),e.attenuationDistance.value=t.attenuationDistance,e.attenuationColor.value.copy(t.attenuationColor)),t.anisotropy>0&&(e.anisotropyVector.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation)),t.anisotropyMap&&(e.anisotropyMap.value=t.anisotropyMap,n(t.anisotropyMap,e.anisotropyMapTransform))),e.specularIntensity.value=t.specularIntensity,e.specularColor.value.copy(t.specularColor),t.specularColorMap&&(e.specularColorMap.value=t.specularColorMap,n(t.specularColorMap,e.specularColorMapTransform)),t.specularIntensityMap&&(e.specularIntensityMap.value=t.specularIntensityMap,n(t.specularIntensityMap,e.specularIntensityMapTransform))}function m(e,t){t.matcap&&(e.matcap.value=t.matcap)}function h(e,n){let r=t.get(n).light;e.referencePosition.value.setFromMatrixPosition(r.matrixWorld),e.nearDistance.value=r.shadow.camera.near,e.farDistance.value=r.shadow.camera.far}return{refreshFogUniforms:r,refreshMaterialUniforms:i}}function _o(e,t,n,r){let i={},a={},o=[],s=n.isWebGL2?e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS):0;function c(e,t){let n=t.program;r.uniformBlockBinding(e,n)}function l(e,n){let o=i[e.id];o===void 0&&(m(e),o=u(e),i[e.id]=o,e.addEventListener(`dispose`,g));let s=n.program;r.updateUBOMapping(e,s);let c=t.render.frame;a[e.id]!==c&&(f(e),a[e.id]=c)}function u(t){let n=d();t.__bindingPointIndex=n;let r=e.createBuffer(),i=t.__size,a=t.usage;return e.bindBuffer(e.UNIFORM_BUFFER,r),e.bufferData(e.UNIFORM_BUFFER,i,a),e.bindBuffer(e.UNIFORM_BUFFER,null),e.bindBufferBase(e.UNIFORM_BUFFER,n,r),r}function d(){for(let e=0;e<s;e++)if(o.indexOf(e)===-1)return o.push(e),e;return console.error(`THREE.WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached.`),0}function f(t){let n=i[t.id],r=t.uniforms,a=t.__cache;e.bindBuffer(e.UNIFORM_BUFFER,n);for(let t=0,n=r.length;t<n;t++){let n=r[t];if(p(n,t,a)===!0){let t=n.__offset,r=Array.isArray(n.value)?n.value:[n.value],i=0;for(let a=0;a<r.length;a++){let o=r[a],s=h(o);typeof o==`number`?(n.__data[0]=o,e.bufferSubData(e.UNIFORM_BUFFER,t+i,n.__data)):o.isMatrix3?(n.__data[0]=o.elements[0],n.__data[1]=o.elements[1],n.__data[2]=o.elements[2],n.__data[3]=o.elements[0],n.__data[4]=o.elements[3],n.__data[5]=o.elements[4],n.__data[6]=o.elements[5],n.__data[7]=o.elements[0],n.__data[8]=o.elements[6],n.__data[9]=o.elements[7],n.__data[10]=o.elements[8],n.__data[11]=o.elements[0]):(o.toArray(n.__data,i),i+=s.storage/Float32Array.BYTES_PER_ELEMENT)}e.bufferSubData(e.UNIFORM_BUFFER,t,n.__data)}}e.bindBuffer(e.UNIFORM_BUFFER,null)}function p(e,t,n){let r=e.value;if(n[t]===void 0){if(typeof r==`number`)n[t]=r;else{let e=Array.isArray(r)?r:[r],i=[];for(let t=0;t<e.length;t++)i.push(e[t].clone());n[t]=i}return!0}else if(typeof r==`number`){if(n[t]!==r)return n[t]=r,!0}else{let e=Array.isArray(n[t])?n[t]:[n[t]],i=Array.isArray(r)?r:[r];for(let t=0;t<e.length;t++){let n=e[t];if(n.equals(i[t])===!1)return n.copy(i[t]),!0}}return!1}function m(e){let t=e.uniforms,n=0,r=0;for(let e=0,i=t.length;e<i;e++){let i=t[e],a={boundary:0,storage:0},o=Array.isArray(i.value)?i.value:[i.value];for(let e=0,t=o.length;e<t;e++){let t=o[e],n=h(t);a.boundary+=n.boundary,a.storage+=n.storage}if(i.__data=new Float32Array(a.storage/Float32Array.BYTES_PER_ELEMENT),i.__offset=n,e>0){r=n%16;let e=16-r;r!==0&&e-a.boundary<0&&(n+=16-r,i.__offset=n)}n+=a.storage}return r=n%16,r>0&&(n+=16-r),e.__size=n,e.__cache={},this}function h(e){let t={boundary:0,storage:0};return typeof e==`number`?(t.boundary=4,t.storage=4):e.isVector2?(t.boundary=8,t.storage=8):e.isVector3||e.isColor?(t.boundary=16,t.storage=12):e.isVector4?(t.boundary=16,t.storage=16):e.isMatrix3?(t.boundary=48,t.storage=48):e.isMatrix4?(t.boundary=64,t.storage=64):e.isTexture?console.warn(`THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group.`):console.warn(`THREE.WebGLRenderer: Unsupported uniform value type.`,e),t}function g(t){let n=t.target;n.removeEventListener(`dispose`,g);let r=o.indexOf(n.__bindingPointIndex);o.splice(r,1),e.deleteBuffer(i[n.id]),delete i[n.id],delete a[n.id]}function _(){for(let t in i)e.deleteBuffer(i[t]);o=[],i={},a={}}return{bind:c,update:l,dispose:_}}var vo=class{constructor(e={}){let{canvas:t=Te(),context:n=null,depth:r=!0,stencil:i=!0,alpha:a=!1,antialias:o=!1,premultipliedAlpha:s=!0,preserveDrawingBuffer:c=!1,powerPreference:l=`default`,failIfMajorPerformanceCaveat:u=!1}=e;this.isWebGLRenderer=!0;let p;p=n===null?a:n.getContextAttributes().alpha;let m=new Uint32Array(4),g=new Int32Array(4),_=null,v=null,y=[],b=[];this.domElement=t,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=A,this._useLegacyLights=!1,this.toneMapping=0,this.toneMappingExposure=1;let x=this,S=!1,C=0,w=0,T=null,E=-1,D=null,O=new Ve,k=new Ve,te=null,j=new Z(0),ne=0,M=t.width,N=t.height,P=1,re=null,ie=null,ae=new Ve(0,0,M,N),F=new Ve(0,0,M,N),I=!1,oe=new _r,se=!1,L=!1,R=null,z=new St,ce=new K,le=new X,ue={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};function de(){return T===null?P:1}let B=n;function fe(e,n){for(let r=0;r<e.length;r++){let i=e[r],a=t.getContext(i,n);if(a!==null)return a}return null}try{let e={alpha:!0,depth:r,stencil:i,antialias:o,premultipliedAlpha:s,preserveDrawingBuffer:c,powerPreference:l,failIfMajorPerformanceCaveat:u};if(`setAttribute`in t&&t.setAttribute(`data-engine`,`three.js r159`),t.addEventListener(`webglcontextlost`,Ne,!1),t.addEventListener(`webglcontextrestored`,Pe,!1),t.addEventListener(`webglcontextcreationerror`,Fe,!1),B===null){let t=[`webgl2`,`webgl`,`experimental-webgl`];if(x.isWebGL1Renderer===!0&&t.shift(),B=fe(t,e),B===null)throw fe(t)?Error(`Error creating WebGL context with your selected attributes.`):Error(`Error creating WebGL context.`)}typeof WebGLRenderingContext<`u`&&B instanceof WebGLRenderingContext&&console.warn(`THREE.WebGLRenderer: WebGL 1 support was deprecated in r153 and will be removed in r163.`),B.getShaderPrecisionFormat===void 0&&(B.getShaderPrecisionFormat=function(){return{rangeMin:1,rangeMax:1,precision:1}})}catch(e){throw console.error(`THREE.WebGLRenderer: `+e.message),e}let V,H,U,pe,W,G,me,he,ge,_e,ye,be,xe,Se,q,J,Ce,we,Ee,De,Oe,ke,Ae,je;function Y(){V=new Xr(B),H=new Er(B,V,e),V.init(H),ke=new lo(B,V,H),U=new so(B,V,H),pe=new $r(B),W=new Wa,G=new co(B,V,U,W,H,ke,pe),me=new Or(x),he=new Yr(x),ge=new yr(B,H),Ae=new wr(B,V,ge,H),_e=new Zr(B,ge,pe,Ae),ye=new ri(B,_e,ge,pe),Ee=new ni(B,H,G),J=new Dr(W),be=new Ua(x,me,he,V,H,Ae,J),xe=new go(x,W),Se=new Ja,q=new to(V,H),we=new Cr(x,me,he,U,ye,p,s),Ce=new oo(x,ye,H),je=new _o(B,pe,H,U),De=new Tr(B,V,pe,H),Oe=new Qr(B,V,pe,H),pe.programs=be.programs,x.capabilities=H,x.extensions=V,x.properties=W,x.renderLists=Se,x.shadowMap=Ce,x.state=U,x.info=pe}Y();let Me=new ho(x,B);this.xr=Me,this.getContext=function(){return B},this.getContextAttributes=function(){return B.getContextAttributes()},this.forceContextLoss=function(){let e=V.get(`WEBGL_lose_context`);e&&e.loseContext()},this.forceContextRestore=function(){let e=V.get(`WEBGL_lose_context`);e&&e.restoreContext()},this.getPixelRatio=function(){return P},this.setPixelRatio=function(e){e!==void 0&&(P=e,this.setSize(M,N,!1))},this.getSize=function(e){return e.set(M,N)},this.setSize=function(e,n,r=!0){if(Me.isPresenting){console.warn(`THREE.WebGLRenderer: Can't change size while VR device is presenting.`);return}M=e,N=n,t.width=Math.floor(e*P),t.height=Math.floor(n*P),r===!0&&(t.style.width=e+`px`,t.style.height=n+`px`),this.setViewport(0,0,e,n)},this.getDrawingBufferSize=function(e){return e.set(M*P,N*P).floor()},this.setDrawingBufferSize=function(e,n,r){M=e,N=n,P=r,t.width=Math.floor(e*r),t.height=Math.floor(n*r),this.setViewport(0,0,e,n)},this.getCurrentViewport=function(e){return e.copy(O)},this.getViewport=function(e){return e.copy(ae)},this.setViewport=function(e,t,n,r){e.isVector4?ae.set(e.x,e.y,e.z,e.w):ae.set(e,t,n,r),U.viewport(O.copy(ae).multiplyScalar(P).floor())},this.getScissor=function(e){return e.copy(F)},this.setScissor=function(e,t,n,r){e.isVector4?F.set(e.x,e.y,e.z,e.w):F.set(e,t,n,r),U.scissor(k.copy(F).multiplyScalar(P).floor())},this.getScissorTest=function(){return I},this.setScissorTest=function(e){U.setScissorTest(I=e)},this.setOpaqueSort=function(e){re=e},this.setTransparentSort=function(e){ie=e},this.getClearColor=function(e){return e.copy(we.getClearColor())},this.setClearColor=function(){we.setClearColor.apply(we,arguments)},this.getClearAlpha=function(){return we.getClearAlpha()},this.setClearAlpha=function(){we.setClearAlpha.apply(we,arguments)},this.clear=function(e=!0,t=!0,n=!0){let r=0;if(e){let e=!1;if(T!==null){let t=T.texture.format;e=t===1033||t===1031||t===1029}if(e){let e=T.texture.type,t=e===1009||e===1014||e===1012||e===1020||e===1017||e===1018,n=we.getClearColor(),r=we.getClearAlpha(),i=n.r,a=n.g,o=n.b;t?(m[0]=i,m[1]=a,m[2]=o,m[3]=r,B.clearBufferuiv(B.COLOR,0,m)):(g[0]=i,g[1]=a,g[2]=o,g[3]=r,B.clearBufferiv(B.COLOR,0,g))}else r|=B.COLOR_BUFFER_BIT}t&&(r|=B.DEPTH_BUFFER_BIT),n&&(r|=B.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),B.clear(r)},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(){t.removeEventListener(`webglcontextlost`,Ne,!1),t.removeEventListener(`webglcontextrestored`,Pe,!1),t.removeEventListener(`webglcontextcreationerror`,Fe,!1),Se.dispose(),q.dispose(),W.dispose(),me.dispose(),he.dispose(),ye.dispose(),Ae.dispose(),je.dispose(),be.dispose(),Me.dispose(),Me.removeEventListener(`sessionstart`,We),Me.removeEventListener(`sessionend`,Ge),R&&=(R.dispose(),null),Ke.stop()};function Ne(e){e.preventDefault(),console.log(`THREE.WebGLRenderer: Context Lost.`),S=!0}function Pe(){console.log(`THREE.WebGLRenderer: Context Restored.`),S=!1;let e=pe.autoReset,t=Ce.enabled,n=Ce.autoUpdate,r=Ce.needsUpdate,i=Ce.type;Y(),pe.autoReset=e,Ce.enabled=t,Ce.autoUpdate=n,Ce.needsUpdate=r,Ce.type=i}function Fe(e){console.error(`THREE.WebGLRenderer: A WebGL context could not be created. Reason: `,e.statusMessage)}function Ie(e){let t=e.target;t.removeEventListener(`dispose`,Ie),Le(t)}function Le(e){Re(e),W.remove(e)}function Re(e){let t=W.get(e).programs;t!==void 0&&(t.forEach(function(e){be.releaseProgram(e)}),e.isShaderMaterial&&be.releaseShaderCache(e))}this.renderBufferDirect=function(e,t,n,r,i,a){t===null&&(t=ue);let o=i.isMesh&&i.matrixWorld.determinant()<0,s=tt(e,t,n,r,i);U.setMaterial(r,o);let c=n.index,l=1;if(r.wireframe===!0){if(c=_e.getWireframeAttribute(n),c===void 0)return;l=2}let u=n.drawRange,d=n.attributes.position,f=u.start*l,p=(u.start+u.count)*l;a!==null&&(f=Math.max(f,a.start*l),p=Math.min(p,(a.start+a.count)*l)),c===null?d!=null&&(f=Math.max(f,0),p=Math.min(p,d.count)):(f=Math.max(f,0),p=Math.min(p,c.count));let m=p-f;if(m<0||m===1/0)return;Ae.setup(i,r,s,n,c);let h,g=De;if(c!==null&&(h=ge.get(c),g=Oe,g.setIndex(h)),i.isMesh)r.wireframe===!0?(U.setLineWidth(r.wireframeLinewidth*de()),g.setMode(B.LINES)):g.setMode(B.TRIANGLES);else if(i.isLine){let e=r.linewidth;e===void 0&&(e=1),U.setLineWidth(e*de()),i.isLineSegments?g.setMode(B.LINES):i.isLineLoop?g.setMode(B.LINE_LOOP):g.setMode(B.LINE_STRIP)}else i.isPoints?g.setMode(B.POINTS):i.isSprite&&g.setMode(B.TRIANGLES);if(i.isBatchedMesh)g.renderMultiDraw(i._multiDrawStarts,i._multiDrawCounts,i._multiDrawCount);else if(i.isInstancedMesh)g.renderInstances(f,m,i.count);else if(n.isInstancedBufferGeometry){let e=n._maxInstanceCount===void 0?1/0:n._maxInstanceCount,t=Math.min(n.instanceCount,e);g.renderInstances(f,m,t)}else g.render(f,m)};function ze(e,t,n){e.transparent===!0&&e.side===2&&e.forceSinglePass===!1?(e.side=1,e.needsUpdate=!0,Qe(e,t,n),e.side=0,e.needsUpdate=!0,Qe(e,t,n),e.side=2):Qe(e,t,n)}this.compile=function(e,t,n=null){n===null&&(n=e),v=q.get(n),v.init(),b.push(v),n.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&(v.pushLight(e),e.castShadow&&v.pushShadow(e))}),e!==n&&e.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&(v.pushLight(e),e.castShadow&&v.pushShadow(e))}),v.setupLights(x._useLegacyLights);let r=new Set;return e.traverse(function(e){let t=e.material;if(t)if(Array.isArray(t))for(let i=0;i<t.length;i++){let a=t[i];ze(a,n,e),r.add(a)}else ze(t,n,e),r.add(t)}),b.pop(),v=null,r},this.compileAsync=function(e,t,n=null){let r=this.compile(e,t,n);return new Promise(t=>{function n(){if(r.forEach(function(e){W.get(e).currentProgram.isReady()&&r.delete(e)}),r.size===0){t(e);return}setTimeout(n,10)}V.get(`KHR_parallel_shader_compile`)===null?setTimeout(n,10):n()})};let Be=null;function He(e){Be&&Be(e)}function We(){Ke.stop()}function Ge(){Ke.start()}let Ke=new vr;Ke.setAnimationLoop(He),typeof self<`u`&&Ke.setContext(self),this.setAnimationLoop=function(e){Be=e,Me.setAnimationLoop(e),e===null?Ke.stop():Ke.start()},Me.addEventListener(`sessionstart`,We),Me.addEventListener(`sessionend`,Ge),this.render=function(e,t){if(t!==void 0&&t.isCamera!==!0){console.error(`THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.`);return}if(S===!0)return;e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.parent===null&&t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld(),Me.enabled===!0&&Me.isPresenting===!0&&(Me.cameraAutoUpdate===!0&&Me.updateCamera(t),t=Me.getCamera()),e.isScene===!0&&e.onBeforeRender(x,e,t,T),v=q.get(e,b.length),v.init(),b.push(v),z.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),oe.setFromProjectionMatrix(z),L=this.localClippingEnabled,se=J.init(this.clippingPlanes,L),_=Se.get(e,y.length),_.init(),y.push(_),qe(e,t,0,x.sortObjects),_.finish(),x.sortObjects===!0&&_.sort(re,ie),this.info.render.frame++,se===!0&&J.beginShadows();let n=v.state.shadowsArray;if(Ce.render(n,e,t),se===!0&&J.endShadows(),this.info.autoReset===!0&&this.info.reset(),we.render(_,e),v.setupLights(x._useLegacyLights),t.isArrayCamera){let n=t.cameras;for(let t=0,r=n.length;t<r;t++){let r=n[t];Je(_,e,r,r.viewport)}}else Je(_,e,t);T!==null&&(G.updateMultisampleRenderTarget(T),G.updateRenderTargetMipmap(T)),e.isScene===!0&&e.onAfterRender(x,e,t),Ae.resetDefaultState(),E=-1,D=null,b.pop(),v=b.length>0?b[b.length-1]:null,y.pop(),_=y.length>0?y[y.length-1]:null};function qe(e,t,n,r){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)n=e.renderOrder;else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLight)v.pushLight(e),e.castShadow&&v.pushShadow(e);else if(e.isSprite){if(!e.frustumCulled||oe.intersectsSprite(e)){r&&le.setFromMatrixPosition(e.matrixWorld).applyMatrix4(z);let t=ye.update(e),i=e.material;i.visible&&_.push(e,t,i,n,le.z,null)}}else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||oe.intersectsObject(e))){let t=ye.update(e),i=e.material;if(r&&(e.boundingSphere===void 0?(t.boundingSphere===null&&t.computeBoundingSphere(),le.copy(t.boundingSphere.center)):(e.boundingSphere===null&&e.computeBoundingSphere(),le.copy(e.boundingSphere.center)),le.applyMatrix4(e.matrixWorld).applyMatrix4(z)),Array.isArray(i)){let r=t.groups;for(let a=0,o=r.length;a<o;a++){let o=r[a],s=i[o.materialIndex];s&&s.visible&&_.push(e,t,s,n,le.z,o)}}else i.visible&&_.push(e,t,i,n,le.z,null)}}let i=e.children;for(let e=0,a=i.length;e<a;e++)qe(i[e],t,n,r)}function Je(e,t,n,r){let i=e.opaque,a=e.transmissive,o=e.transparent;v.setupLightsView(n),se===!0&&J.setGlobalState(x.clippingPlanes,n),a.length>0&&Ye(i,a,t,n),r&&U.viewport(O.copy(r)),i.length>0&&Xe(i,t,n),a.length>0&&Xe(a,t,n),o.length>0&&Xe(o,t,n),U.buffers.depth.setTest(!0),U.buffers.depth.setMask(!0),U.buffers.color.setMask(!0),U.setPolygonOffset(!1)}function Ye(e,t,n,r){if((n.isScene===!0?n.overrideMaterial:null)!==null)return;let i=H.isWebGL2;R===null&&(R=new Ue(1,1,{generateMipmaps:!0,type:V.has(`EXT_color_buffer_half_float`)?h:f,minFilter:d,samples:i?4:0})),x.getDrawingBufferSize(ce),i?R.setSize(ce.x,ce.y):R.setSize(ve(ce.x),ve(ce.y));let a=x.getRenderTarget();x.setRenderTarget(R),x.getClearColor(j),ne=x.getClearAlpha(),ne<1&&x.setClearColor(16777215,.5),x.clear();let o=x.toneMapping;x.toneMapping=0,Xe(e,n,r),G.updateMultisampleRenderTarget(R),G.updateRenderTargetMipmap(R);let s=!1;for(let e=0,i=t.length;e<i;e++){let i=t[e],a=i.object,o=i.geometry,c=i.material,l=i.group;if(c.side===2&&a.layers.test(r.layers)){let e=c.side;c.side=1,c.needsUpdate=!0,Ze(a,n,r,o,c,l),c.side=e,c.needsUpdate=!0,s=!0}}s===!0&&(G.updateMultisampleRenderTarget(R),G.updateRenderTargetMipmap(R)),x.setRenderTarget(a),x.setClearColor(j,ne),x.toneMapping=o}function Xe(e,t,n){let r=t.isScene===!0?t.overrideMaterial:null;for(let i=0,a=e.length;i<a;i++){let a=e[i],o=a.object,s=a.geometry,c=r===null?a.material:r,l=a.group;o.layers.test(n.layers)&&Ze(o,t,n,s,c,l)}}function Ze(e,t,n,r,i,a){e.onBeforeRender(x,t,n,r,i,a),e.modelViewMatrix.multiplyMatrices(n.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix),i.onBeforeRender(x,t,n,r,e,a),i.transparent===!0&&i.side===2&&i.forceSinglePass===!1?(i.side=1,i.needsUpdate=!0,x.renderBufferDirect(n,t,r,i,e,a),i.side=0,i.needsUpdate=!0,x.renderBufferDirect(n,t,r,i,e,a),i.side=2):x.renderBufferDirect(n,t,r,i,e,a),e.onAfterRender(x,t,n,r,i,a)}function Qe(e,t,n){t.isScene!==!0&&(t=ue);let r=W.get(e),i=v.state.lights,a=v.state.shadowsArray,o=i.state.version,s=be.getParameters(e,i.state,a,t,n),c=be.getProgramCacheKey(s),l=r.programs;r.environment=e.isMeshStandardMaterial?t.environment:null,r.fog=t.fog,r.envMap=(e.isMeshStandardMaterial?he:me).get(e.envMap||r.environment),l===void 0&&(e.addEventListener(`dispose`,Ie),l=new Map,r.programs=l);let u=l.get(c);if(u!==void 0){if(r.currentProgram===u&&r.lightsStateVersion===o)return et(e,s),u}else s.uniforms=be.getUniforms(e),e.onBuild(n,s,x),e.onBeforeCompile(s,x),u=be.acquireProgram(s,c),l.set(c,u),r.uniforms=s.uniforms;let d=r.uniforms;return(!e.isShaderMaterial&&!e.isRawShaderMaterial||e.clipping===!0)&&(d.clippingPlanes=J.uniform),et(e,s),r.needsLights=rt(e),r.lightsStateVersion=o,r.needsLights&&(d.ambientLightColor.value=i.state.ambient,d.lightProbe.value=i.state.probe,d.directionalLights.value=i.state.directional,d.directionalLightShadows.value=i.state.directionalShadow,d.spotLights.value=i.state.spot,d.spotLightShadows.value=i.state.spotShadow,d.rectAreaLights.value=i.state.rectArea,d.ltc_1.value=i.state.rectAreaLTC1,d.ltc_2.value=i.state.rectAreaLTC2,d.pointLights.value=i.state.point,d.pointLightShadows.value=i.state.pointShadow,d.hemisphereLights.value=i.state.hemi,d.directionalShadowMap.value=i.state.directionalShadowMap,d.directionalShadowMatrix.value=i.state.directionalShadowMatrix,d.spotShadowMap.value=i.state.spotShadowMap,d.spotLightMatrix.value=i.state.spotLightMatrix,d.spotLightMap.value=i.state.spotLightMap,d.pointShadowMap.value=i.state.pointShadowMap,d.pointShadowMatrix.value=i.state.pointShadowMatrix),r.currentProgram=u,r.uniformsList=null,u}function $e(e){if(e.uniformsList===null){let t=e.currentProgram.getUniforms();e.uniformsList=da.seqWithValue(t.seq,e.uniforms)}return e.uniformsList}function et(e,t){let n=W.get(e);n.outputColorSpace=t.outputColorSpace,n.batching=t.batching,n.instancing=t.instancing,n.instancingColor=t.instancingColor,n.skinning=t.skinning,n.morphTargets=t.morphTargets,n.morphNormals=t.morphNormals,n.morphColors=t.morphColors,n.morphTargetsCount=t.morphTargetsCount,n.numClippingPlanes=t.numClippingPlanes,n.numIntersection=t.numClipIntersection,n.vertexAlphas=t.vertexAlphas,n.vertexTangents=t.vertexTangents,n.toneMapping=t.toneMapping}function tt(e,t,n,r,i){t.isScene!==!0&&(t=ue),G.resetTextureUnits();let a=t.fog,o=r.isMeshStandardMaterial?t.environment:null,s=T===null?x.outputColorSpace:T.isXRRenderTarget===!0?T.texture.colorSpace:ee,c=(r.isMeshStandardMaterial?he:me).get(r.envMap||o),l=r.vertexColors===!0&&!!n.attributes.color&&n.attributes.color.itemSize===4,u=!!n.attributes.tangent&&(!!r.normalMap||r.anisotropy>0),d=!!n.morphAttributes.position,f=!!n.morphAttributes.normal,p=!!n.morphAttributes.color,m=0;r.toneMapped&&(T===null||T.isXRRenderTarget===!0)&&(m=x.toneMapping);let h=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,g=h===void 0?0:h.length,_=W.get(r),y=v.state.lights;if(se===!0&&(L===!0||e!==D)){let t=e===D&&r.id===E;J.setState(r,e,t)}let b=!1;r.version===_.__version?_.needsLights&&_.lightsStateVersion!==y.state.version?b=!0:_.outputColorSpace===s?i.isBatchedMesh&&_.batching===!1||!i.isBatchedMesh&&_.batching===!0||i.isInstancedMesh&&_.instancing===!1||!i.isInstancedMesh&&_.instancing===!0||i.isSkinnedMesh&&_.skinning===!1||!i.isSkinnedMesh&&_.skinning===!0||i.isInstancedMesh&&_.instancingColor===!0&&i.instanceColor===null||i.isInstancedMesh&&_.instancingColor===!1&&i.instanceColor!==null?b=!0:_.envMap===c?r.fog===!0&&_.fog!==a||_.numClippingPlanes!==void 0&&(_.numClippingPlanes!==J.numPlanes||_.numIntersection!==J.numIntersection)?b=!0:_.vertexAlphas===l&&_.vertexTangents===u&&_.morphTargets===d&&_.morphNormals===f&&_.morphColors===p&&_.toneMapping===m?H.isWebGL2===!0&&_.morphTargetsCount!==g&&(b=!0):b=!0:b=!0:b=!0:(b=!0,_.__version=r.version);let S=_.currentProgram;b===!0&&(S=Qe(r,t,i));let C=!1,w=!1,O=!1,k=S.getUniforms(),A=_.uniforms;if(U.useProgram(S.program)&&(C=!0,w=!0,O=!0),r.id!==E&&(E=r.id,w=!0),C||D!==e){k.setValue(B,`projectionMatrix`,e.projectionMatrix),k.setValue(B,`viewMatrix`,e.matrixWorldInverse);let t=k.map.cameraPosition;t!==void 0&&t.setValue(B,le.setFromMatrixPosition(e.matrixWorld)),H.logarithmicDepthBuffer&&k.setValue(B,`logDepthBufFC`,2/(Math.log(e.far+1)/Math.LN2)),(r.isMeshPhongMaterial||r.isMeshToonMaterial||r.isMeshLambertMaterial||r.isMeshBasicMaterial||r.isMeshStandardMaterial||r.isShaderMaterial)&&k.setValue(B,`isOrthographic`,e.isOrthographicCamera===!0),D!==e&&(D=e,w=!0,O=!0)}if(i.isSkinnedMesh){k.setOptional(B,i,`bindMatrix`),k.setOptional(B,i,`bindMatrixInverse`);let e=i.skeleton;e&&(H.floatVertexTextures?(e.boneTexture===null&&e.computeBoneTexture(),k.setValue(B,`boneTexture`,e.boneTexture,G)):console.warn(`THREE.WebGLRenderer: SkinnedMesh can only be used with WebGL 2. With WebGL 1 OES_texture_float and vertex textures support is required.`))}i.isBatchedMesh&&(k.setOptional(B,i,`batchingTexture`),k.setValue(B,`batchingTexture`,i._matricesTexture,G));let te=n.morphAttributes;if((te.position!==void 0||te.normal!==void 0||te.color!==void 0&&H.isWebGL2===!0)&&Ee.update(i,n,S),(w||_.receiveShadow!==i.receiveShadow)&&(_.receiveShadow=i.receiveShadow,k.setValue(B,`receiveShadow`,i.receiveShadow)),r.isMeshGouraudMaterial&&r.envMap!==null&&(A.envMap.value=c,A.flipEnvMap.value=c.isCubeTexture&&c.isRenderTargetTexture===!1?-1:1),w&&(k.setValue(B,`toneMappingExposure`,x.toneMappingExposure),_.needsLights&&nt(A,O),a&&r.fog===!0&&xe.refreshFogUniforms(A,a),xe.refreshMaterialUniforms(A,r,P,N,R),da.upload(B,$e(_),A,G)),r.isShaderMaterial&&r.uniformsNeedUpdate===!0&&(da.upload(B,$e(_),A,G),r.uniformsNeedUpdate=!1),r.isSpriteMaterial&&k.setValue(B,`center`,i.center),k.setValue(B,`modelViewMatrix`,i.modelViewMatrix),k.setValue(B,`normalMatrix`,i.normalMatrix),k.setValue(B,`modelMatrix`,i.matrixWorld),r.isShaderMaterial||r.isRawShaderMaterial){let e=r.uniformsGroups;for(let t=0,n=e.length;t<n;t++)if(H.isWebGL2){let n=e[t];je.update(n,S),je.bind(n,S)}else console.warn(`THREE.WebGLRenderer: Uniform Buffer Objects can only be used with WebGL 2.`)}return S}function nt(e,t){e.ambientLightColor.needsUpdate=t,e.lightProbe.needsUpdate=t,e.directionalLights.needsUpdate=t,e.directionalLightShadows.needsUpdate=t,e.pointLights.needsUpdate=t,e.pointLightShadows.needsUpdate=t,e.spotLights.needsUpdate=t,e.spotLightShadows.needsUpdate=t,e.rectAreaLights.needsUpdate=t,e.hemisphereLights.needsUpdate=t}function rt(e){return e.isMeshLambertMaterial||e.isMeshToonMaterial||e.isMeshPhongMaterial||e.isMeshStandardMaterial||e.isShadowMaterial||e.isShaderMaterial&&e.lights===!0}this.getActiveCubeFace=function(){return C},this.getActiveMipmapLevel=function(){return w},this.getRenderTarget=function(){return T},this.setRenderTargetTextures=function(e,t,n){W.get(e.texture).__webglTexture=t,W.get(e.depthTexture).__webglTexture=n;let r=W.get(e);r.__hasExternalTextures=!0,r.__hasExternalTextures&&(r.__autoAllocateDepthBuffer=n===void 0,r.__autoAllocateDepthBuffer||V.has(`WEBGL_multisampled_render_to_texture`)===!0&&(console.warn(`THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided`),r.__useRenderToTexture=!1))},this.setRenderTargetFramebuffer=function(e,t){let n=W.get(e);n.__webglFramebuffer=t,n.__useDefaultFramebuffer=t===void 0},this.setRenderTarget=function(e,t=0,n=0){T=e,C=t,w=n;let r=!0,i=null,a=!1,o=!1;if(e){let s=W.get(e);s.__useDefaultFramebuffer===void 0?s.__webglFramebuffer===void 0?G.setupRenderTarget(e):s.__hasExternalTextures&&G.rebindTextures(e,W.get(e.texture).__webglTexture,W.get(e.depthTexture).__webglTexture):(U.bindFramebuffer(B.FRAMEBUFFER,null),r=!1);let c=e.texture;(c.isData3DTexture||c.isDataArrayTexture||c.isCompressedArrayTexture)&&(o=!0);let l=W.get(e).__webglFramebuffer;e.isWebGLCubeRenderTarget?(i=Array.isArray(l[t])?l[t][n]:l[t],a=!0):i=H.isWebGL2&&e.samples>0&&G.useMultisampledRTT(e)===!1?W.get(e).__webglMultisampledFramebuffer:Array.isArray(l)?l[n]:l,O.copy(e.viewport),k.copy(e.scissor),te=e.scissorTest}else O.copy(ae).multiplyScalar(P).floor(),k.copy(F).multiplyScalar(P).floor(),te=I;if(U.bindFramebuffer(B.FRAMEBUFFER,i)&&H.drawBuffers&&r&&U.drawBuffers(e,i),U.viewport(O),U.scissor(k),U.setScissorTest(te),a){let r=W.get(e.texture);B.framebufferTexture2D(B.FRAMEBUFFER,B.COLOR_ATTACHMENT0,B.TEXTURE_CUBE_MAP_POSITIVE_X+t,r.__webglTexture,n)}else if(o){let r=W.get(e.texture),i=t||0;B.framebufferTextureLayer(B.FRAMEBUFFER,B.COLOR_ATTACHMENT0,r.__webglTexture,n||0,i)}E=-1},this.readRenderTargetPixels=function(e,t,n,r,i,a,o){if(!(e&&e.isWebGLRenderTarget)){console.error(`THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.`);return}let s=W.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&o!==void 0&&(s=s[o]),s){U.bindFramebuffer(B.FRAMEBUFFER,s);try{let o=e.texture,s=o.format,c=o.type;if(s!==1023&&ke.convert(s)!==B.getParameter(B.IMPLEMENTATION_COLOR_READ_FORMAT)){console.error(`THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.`);return}let l=c===1016&&(V.has(`EXT_color_buffer_half_float`)||H.isWebGL2&&V.has(`EXT_color_buffer_float`));if(c!==1009&&ke.convert(c)!==B.getParameter(B.IMPLEMENTATION_COLOR_READ_TYPE)&&!(c===1015&&(H.isWebGL2||V.has(`OES_texture_float`)||V.has(`WEBGL_color_buffer_float`)))&&!l){console.error(`THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.`);return}t>=0&&t<=e.width-r&&n>=0&&n<=e.height-i&&B.readPixels(t,n,r,i,ke.convert(s),ke.convert(c),a)}finally{let e=T===null?null:W.get(T).__webglFramebuffer;U.bindFramebuffer(B.FRAMEBUFFER,e)}}},this.copyFramebufferToTexture=function(e,t,n=0){let r=2**-n,i=Math.floor(t.image.width*r),a=Math.floor(t.image.height*r);G.setTexture2D(t,0),B.copyTexSubImage2D(B.TEXTURE_2D,n,0,0,e.x,e.y,i,a),U.unbindTexture()},this.copyTextureToTexture=function(e,t,n,r=0){let i=t.image.width,a=t.image.height,o=ke.convert(n.format),s=ke.convert(n.type);G.setTexture2D(n,0),B.pixelStorei(B.UNPACK_FLIP_Y_WEBGL,n.flipY),B.pixelStorei(B.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n.premultiplyAlpha),B.pixelStorei(B.UNPACK_ALIGNMENT,n.unpackAlignment),t.isDataTexture?B.texSubImage2D(B.TEXTURE_2D,r,e.x,e.y,i,a,o,s,t.image.data):t.isCompressedTexture?B.compressedTexSubImage2D(B.TEXTURE_2D,r,e.x,e.y,t.mipmaps[0].width,t.mipmaps[0].height,o,t.mipmaps[0].data):B.texSubImage2D(B.TEXTURE_2D,r,e.x,e.y,o,s,t.image),r===0&&n.generateMipmaps&&B.generateMipmap(B.TEXTURE_2D),U.unbindTexture()},this.copyTextureToTexture3D=function(e,t,n,r,i=0){if(x.isWebGL1Renderer){console.warn(`THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.`);return}let a=e.max.x-e.min.x+1,o=e.max.y-e.min.y+1,s=e.max.z-e.min.z+1,c=ke.convert(r.format),l=ke.convert(r.type),u;if(r.isData3DTexture)G.setTexture3D(r,0),u=B.TEXTURE_3D;else if(r.isDataArrayTexture)G.setTexture2DArray(r,0),u=B.TEXTURE_2D_ARRAY;else{console.warn(`THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.`);return}B.pixelStorei(B.UNPACK_FLIP_Y_WEBGL,r.flipY),B.pixelStorei(B.UNPACK_PREMULTIPLY_ALPHA_WEBGL,r.premultiplyAlpha),B.pixelStorei(B.UNPACK_ALIGNMENT,r.unpackAlignment);let d=B.getParameter(B.UNPACK_ROW_LENGTH),f=B.getParameter(B.UNPACK_IMAGE_HEIGHT),p=B.getParameter(B.UNPACK_SKIP_PIXELS),m=B.getParameter(B.UNPACK_SKIP_ROWS),h=B.getParameter(B.UNPACK_SKIP_IMAGES),g=n.isCompressedTexture?n.mipmaps[0]:n.image;B.pixelStorei(B.UNPACK_ROW_LENGTH,g.width),B.pixelStorei(B.UNPACK_IMAGE_HEIGHT,g.height),B.pixelStorei(B.UNPACK_SKIP_PIXELS,e.min.x),B.pixelStorei(B.UNPACK_SKIP_ROWS,e.min.y),B.pixelStorei(B.UNPACK_SKIP_IMAGES,e.min.z),n.isDataTexture||n.isData3DTexture?B.texSubImage3D(u,i,t.x,t.y,t.z,a,o,s,c,l,g.data):n.isCompressedArrayTexture?(console.warn(`THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture.`),B.compressedTexSubImage3D(u,i,t.x,t.y,t.z,a,o,s,c,g.data)):B.texSubImage3D(u,i,t.x,t.y,t.z,a,o,s,c,l,g),B.pixelStorei(B.UNPACK_ROW_LENGTH,d),B.pixelStorei(B.UNPACK_IMAGE_HEIGHT,f),B.pixelStorei(B.UNPACK_SKIP_PIXELS,p),B.pixelStorei(B.UNPACK_SKIP_ROWS,m),B.pixelStorei(B.UNPACK_SKIP_IMAGES,h),i===0&&r.generateMipmaps&&B.generateMipmap(u),U.unbindTexture()},this.initTexture=function(e){e.isCubeTexture?G.setTextureCube(e,0):e.isData3DTexture?G.setTexture3D(e,0):e.isDataArrayTexture||e.isCompressedArrayTexture?G.setTexture2DArray(e,0):G.setTexture2D(e,0),U.unbindTexture()},this.resetState=function(){C=0,w=0,T=null,U.reset(),Ae.reset()},typeof __THREE_DEVTOOLS__<`u`&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent(`observe`,{detail:this}))}get coordinateSystem(){return ae}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;let t=this.getContext();t.drawingBufferColorSpace=e===`display-p3`?`display-p3`:`srgb`,t.unpackColorSpace=Y.workingColorSpace===`display-p3-linear`?`display-p3`:`srgb`}get physicallyCorrectLights(){return console.warn(`THREE.WebGLRenderer: The property .physicallyCorrectLights has been removed. Set renderer.useLegacyLights instead.`),!this.useLegacyLights}set physicallyCorrectLights(e){console.warn(`THREE.WebGLRenderer: The property .physicallyCorrectLights has been removed. Set renderer.useLegacyLights instead.`),this.useLegacyLights=!e}get outputEncoding(){return console.warn(`THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead.`),this.outputColorSpace===`srgb`?D:E}set outputEncoding(e){console.warn(`THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead.`),this.outputColorSpace=e===3001?A:ee}get useLegacyLights(){return console.warn(`THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.`),this._useLegacyLights}set useLegacyLights(e){console.warn(`THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733.`),this._useLegacyLights=e}},yo=class extends vo{};yo.prototype.isWebGL1Renderer=!0;var bo=class extends qt{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,typeof __THREE_DEVTOOLS__<`u`&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent(`observe`,{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){let t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t}},xo=class extends pn{constructor(e){super(),this.isLineBasicMaterial=!0,this.type=`LineBasicMaterial`,this.color=new Z(16777215),this.map=null,this.linewidth=1,this.linecap=`round`,this.linejoin=`round`,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.linewidth=e.linewidth,this.linecap=e.linecap,this.linejoin=e.linejoin,this.fog=e.fog,this}},So=new X,Co=new X,wo=new St,To=new xt,Eo=new pt,Do=class extends qt{constructor(e=new On,t=new xo){super(),this.isLine=!0,this.type=`Line`,this.geometry=e,this.material=t,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}computeLineDistances(){let e=this.geometry;if(e.index===null){let t=e.attributes.position,n=[0];for(let e=1,r=t.count;e<r;e++)So.fromBufferAttribute(t,e-1),Co.fromBufferAttribute(t,e),n[e]=n[e-1],n[e]+=So.distanceTo(Co);e.setAttribute(`lineDistance`,new bn(n,1))}else console.warn(`THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.`);return this}raycast(e,t){let n=this.geometry,r=this.matrixWorld,i=e.params.Line.threshold,a=n.drawRange;if(n.boundingSphere===null&&n.computeBoundingSphere(),Eo.copy(n.boundingSphere),Eo.applyMatrix4(r),Eo.radius+=i,e.ray.intersectsSphere(Eo)===!1)return;wo.copy(r).invert(),To.copy(e.ray).applyMatrix4(wo);let o=i/((this.scale.x+this.scale.y+this.scale.z)/3),s=o*o,c=new X,l=new X,u=new X,d=new X,f=this.isLineSegments?2:1,p=n.index,m=n.attributes.position;if(p!==null){let n=Math.max(0,a.start),r=Math.min(p.count,a.start+a.count);for(let i=n,a=r-1;i<a;i+=f){let n=p.getX(i),r=p.getX(i+1);if(c.fromBufferAttribute(m,n),l.fromBufferAttribute(m,r),To.distanceSqToSegment(c,l,d,u)>s)continue;d.applyMatrix4(this.matrixWorld);let a=e.ray.origin.distanceTo(d);a<e.near||a>e.far||t.push({distance:a,point:u.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this})}}else{let n=Math.max(0,a.start),r=Math.min(m.count,a.start+a.count);for(let i=n,a=r-1;i<a;i+=f){if(c.fromBufferAttribute(m,i),l.fromBufferAttribute(m,i+1),To.distanceSqToSegment(c,l,d,u)>s)continue;d.applyMatrix4(this.matrixWorld);let n=e.ray.origin.distanceTo(d);n<e.near||n>e.far||t.push({distance:n,point:u.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this})}}}updateMorphTargets(){let e=this.geometry.morphAttributes,t=Object.keys(e);if(t.length>0){let n=e[t[0]];if(n!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,t=n.length;e<t;e++){let t=n[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[t]=e}}}}},Oo=class extends Do{constructor(e,t){super(e,t),this.isLineLoop=!0,this.type=`LineLoop`}},ko=class{constructor(){this.type=`Curve`,this.arcLengthDivisions=200}getPoint(){return console.warn(`THREE.Curve: .getPoint() not implemented.`),null}getPointAt(e,t){let n=this.getUtoTmapping(e);return this.getPoint(n,t)}getPoints(e=5){let t=[];for(let n=0;n<=e;n++)t.push(this.getPoint(n/e));return t}getSpacedPoints(e=5){let t=[];for(let n=0;n<=e;n++)t.push(this.getPointAt(n/e));return t}getLength(){let e=this.getLengths();return e[e.length-1]}getLengths(e=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;let t=[],n,r=this.getPoint(0),i=0;t.push(0);for(let a=1;a<=e;a++)n=this.getPoint(a/e),i+=n.distanceTo(r),t.push(i),r=n;return this.cacheArcLengths=t,t}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(e,t){let n=this.getLengths(),r=0,i=n.length,a;a=t||e*n[i-1];let o=0,s=i-1,c;for(;o<=s;)if(r=Math.floor(o+(s-o)/2),c=n[r]-a,c<0)o=r+1;else if(c>0)s=r-1;else{s=r;break}if(r=s,n[r]===a)return r/(i-1);let l=n[r],u=n[r+1]-l,d=(a-l)/u;return(r+d)/(i-1)}getTangent(e,t){let n=1e-4,r=e-n,i=e+n;r<0&&(r=0),i>1&&(i=1);let a=this.getPoint(r),o=this.getPoint(i),s=t||(a.isVector2?new K:new X);return s.copy(o).sub(a).normalize(),s}getTangentAt(e,t){let n=this.getUtoTmapping(e);return this.getTangent(n,t)}computeFrenetFrames(e,t){let n=new X,r=[],i=[],a=[],o=new X,s=new St;for(let t=0;t<=e;t++){let n=t/e;r[t]=this.getTangentAt(n,new X)}i[0]=new X,a[0]=new X;let c=Number.MAX_VALUE,l=Math.abs(r[0].x),u=Math.abs(r[0].y),d=Math.abs(r[0].z);l<=c&&(c=l,n.set(1,0,0)),u<=c&&(c=u,n.set(0,1,0)),d<=c&&n.set(0,0,1),o.crossVectors(r[0],n).normalize(),i[0].crossVectors(r[0],o),a[0].crossVectors(r[0],i[0]);for(let t=1;t<=e;t++){if(i[t]=i[t-1].clone(),a[t]=a[t-1].clone(),o.crossVectors(r[t-1],r[t]),o.length()>2**-52){o.normalize();let e=Math.acos(z(r[t-1].dot(r[t]),-1,1));i[t].applyMatrix4(s.makeRotationAxis(o,e))}a[t].crossVectors(r[t],i[t])}if(t===!0){let t=Math.acos(z(i[0].dot(i[e]),-1,1));t/=e,r[0].dot(o.crossVectors(i[0],i[e]))>0&&(t=-t);for(let n=1;n<=e;n++)i[n].applyMatrix4(s.makeRotationAxis(r[n],t*n)),a[n].crossVectors(r[n],i[n])}return{tangents:r,normals:i,binormals:a}}clone(){return new this.constructor().copy(this)}copy(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}toJSON(){let e={metadata:{version:4.6,type:`Curve`,generator:`Curve.toJSON`}};return e.arcLengthDivisions=this.arcLengthDivisions,e.type=this.type,e}fromJSON(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}},Ao=class extends ko{constructor(e=0,t=0,n=1,r=1,i=0,a=Math.PI*2,o=!1,s=0){super(),this.isEllipseCurve=!0,this.type=`EllipseCurve`,this.aX=e,this.aY=t,this.xRadius=n,this.yRadius=r,this.aStartAngle=i,this.aEndAngle=a,this.aClockwise=o,this.aRotation=s}getPoint(e,t){let n=t||new K,r=Math.PI*2,i=this.aEndAngle-this.aStartAngle,a=Math.abs(i)<2**-52;for(;i<0;)i+=r;for(;i>r;)i-=r;i<2**-52&&(i=a?0:r),this.aClockwise===!0&&!a&&(i===r?i=-r:i-=r);let o=this.aStartAngle+e*i,s=this.aX+this.xRadius*Math.cos(o),c=this.aY+this.yRadius*Math.sin(o);if(this.aRotation!==0){let e=Math.cos(this.aRotation),t=Math.sin(this.aRotation),n=s-this.aX,r=c-this.aY;s=n*e-r*t+this.aX,c=n*t+r*e+this.aY}return n.set(s,c)}copy(e){return super.copy(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}toJSON(){let e=super.toJSON();return e.aX=this.aX,e.aY=this.aY,e.xRadius=this.xRadius,e.yRadius=this.yRadius,e.aStartAngle=this.aStartAngle,e.aEndAngle=this.aEndAngle,e.aClockwise=this.aClockwise,e.aRotation=this.aRotation,e}fromJSON(e){return super.fromJSON(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}},jo=class extends Ao{constructor(e,t,n,r,i,a){super(e,t,n,n,r,i,a),this.isArcCurve=!0,this.type=`ArcCurve`}};function Mo(){let e=0,t=0,n=0,r=0;function i(i,a,o,s){e=i,t=o,n=-3*i+3*a-2*o-s,r=2*i-2*a+o+s}return{initCatmullRom:function(e,t,n,r,a){i(t,n,a*(n-e),a*(r-t))},initNonuniformCatmullRom:function(e,t,n,r,a,o,s){let c=(t-e)/a-(n-e)/(a+o)+(n-t)/o,l=(n-t)/o-(r-t)/(o+s)+(r-n)/s;c*=o,l*=o,i(t,n,c,l)},calc:function(i){let a=i*i,o=a*i;return e+t*i+n*a+r*o}}}var No=new X,Po=new Mo,Fo=new Mo,Io=new Mo,Lo=class extends ko{constructor(e=[],t=!1,n=`centripetal`,r=.5){super(),this.isCatmullRomCurve3=!0,this.type=`CatmullRomCurve3`,this.points=e,this.closed=t,this.curveType=n,this.tension=r}getPoint(e,t=new X){let n=t,r=this.points,i=r.length,a=(i-+!this.closed)*e,o=Math.floor(a),s=a-o;this.closed?o+=o>0?0:(Math.floor(Math.abs(o)/i)+1)*i:s===0&&o===i-1&&(o=i-2,s=1);let c,l;this.closed||o>0?c=r[(o-1)%i]:(No.subVectors(r[0],r[1]).add(r[0]),c=No);let u=r[o%i],d=r[(o+1)%i];if(this.closed||o+2<i?l=r[(o+2)%i]:(No.subVectors(r[i-1],r[i-2]).add(r[i-1]),l=No),this.curveType===`centripetal`||this.curveType===`chordal`){let e=this.curveType===`chordal`?.5:.25,t=c.distanceToSquared(u)**+e,n=u.distanceToSquared(d)**+e,r=d.distanceToSquared(l)**+e;n<1e-4&&(n=1),t<1e-4&&(t=n),r<1e-4&&(r=n),Po.initNonuniformCatmullRom(c.x,u.x,d.x,l.x,t,n,r),Fo.initNonuniformCatmullRom(c.y,u.y,d.y,l.y,t,n,r),Io.initNonuniformCatmullRom(c.z,u.z,d.z,l.z,t,n,r)}else this.curveType===`catmullrom`&&(Po.initCatmullRom(c.x,u.x,d.x,l.x,this.tension),Fo.initCatmullRom(c.y,u.y,d.y,l.y,this.tension),Io.initCatmullRom(c.z,u.z,d.z,l.z,this.tension));return n.set(Po.calc(s),Fo.calc(s),Io.calc(s)),n}copy(e){super.copy(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){let n=e.points[t];this.points.push(n.clone())}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}toJSON(){let e=super.toJSON();e.points=[];for(let t=0,n=this.points.length;t<n;t++){let n=this.points[t];e.points.push(n.toArray())}return e.closed=this.closed,e.curveType=this.curveType,e.tension=this.tension,e}fromJSON(e){super.fromJSON(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){let n=e.points[t];this.points.push(new X().fromArray(n))}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}};function Ro(e,t,n,r,i){let a=(r-t)*.5,o=(i-n)*.5,s=e*e,c=e*s;return(2*n-2*r+a+o)*c+(-3*n+3*r-2*a-o)*s+a*e+n}function zo(e,t){let n=1-e;return n*n*t}function Bo(e,t){return 2*(1-e)*e*t}function Vo(e,t){return e*e*t}function Ho(e,t,n,r){return zo(e,t)+Bo(e,n)+Vo(e,r)}function Uo(e,t){let n=1-e;return n*n*n*t}function Wo(e,t){let n=1-e;return 3*n*n*e*t}function Go(e,t){return 3*(1-e)*e*e*t}function Ko(e,t){return e*e*e*t}function qo(e,t,n,r,i){return Uo(e,t)+Wo(e,n)+Go(e,r)+Ko(e,i)}var Jo=class extends ko{constructor(e=new K,t=new K,n=new K,r=new K){super(),this.isCubicBezierCurve=!0,this.type=`CubicBezierCurve`,this.v0=e,this.v1=t,this.v2=n,this.v3=r}getPoint(e,t=new K){let n=t,r=this.v0,i=this.v1,a=this.v2,o=this.v3;return n.set(qo(e,r.x,i.x,a.x,o.x),qo(e,r.y,i.y,a.y,o.y)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}toJSON(){let e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e.v3=this.v3.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this.v3.fromArray(e.v3),this}},Yo=class extends ko{constructor(e=new X,t=new X,n=new X,r=new X){super(),this.isCubicBezierCurve3=!0,this.type=`CubicBezierCurve3`,this.v0=e,this.v1=t,this.v2=n,this.v3=r}getPoint(e,t=new X){let n=t,r=this.v0,i=this.v1,a=this.v2,o=this.v3;return n.set(qo(e,r.x,i.x,a.x,o.x),qo(e,r.y,i.y,a.y,o.y),qo(e,r.z,i.z,a.z,o.z)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}toJSON(){let e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e.v3=this.v3.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this.v3.fromArray(e.v3),this}},Xo=class extends ko{constructor(e=new K,t=new K){super(),this.isLineCurve=!0,this.type=`LineCurve`,this.v1=e,this.v2=t}getPoint(e,t=new K){let n=t;return e===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(e).add(this.v1)),n}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new K){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){let e=super.toJSON();return e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}},Zo=class extends ko{constructor(e=new X,t=new X){super(),this.isLineCurve3=!0,this.type=`LineCurve3`,this.v1=e,this.v2=t}getPoint(e,t=new X){let n=t;return e===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(e).add(this.v1)),n}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new X){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){let e=super.toJSON();return e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}},Qo=class extends ko{constructor(e=new K,t=new K,n=new K){super(),this.isQuadraticBezierCurve=!0,this.type=`QuadraticBezierCurve`,this.v0=e,this.v1=t,this.v2=n}getPoint(e,t=new K){let n=t,r=this.v0,i=this.v1,a=this.v2;return n.set(Ho(e,r.x,i.x,a.x),Ho(e,r.y,i.y,a.y)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){let e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}},$o=class extends ko{constructor(e=new X,t=new X,n=new X){super(),this.isQuadraticBezierCurve3=!0,this.type=`QuadraticBezierCurve3`,this.v0=e,this.v1=t,this.v2=n}getPoint(e,t=new X){let n=t,r=this.v0,i=this.v1,a=this.v2;return n.set(Ho(e,r.x,i.x,a.x),Ho(e,r.y,i.y,a.y),Ho(e,r.z,i.z,a.z)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}toJSON(){let e=super.toJSON();return e.v0=this.v0.toArray(),e.v1=this.v1.toArray(),e.v2=this.v2.toArray(),e}fromJSON(e){return super.fromJSON(e),this.v0.fromArray(e.v0),this.v1.fromArray(e.v1),this.v2.fromArray(e.v2),this}},es=class extends ko{constructor(e=[]){super(),this.isSplineCurve=!0,this.type=`SplineCurve`,this.points=e}getPoint(e,t=new K){let n=t,r=this.points,i=(r.length-1)*e,a=Math.floor(i),o=i-a,s=r[a===0?a:a-1],c=r[a],l=r[a>r.length-2?r.length-1:a+1],u=r[a>r.length-3?r.length-1:a+2];return n.set(Ro(o,s.x,c.x,l.x,u.x),Ro(o,s.y,c.y,l.y,u.y)),n}copy(e){super.copy(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){let n=e.points[t];this.points.push(n.clone())}return this}toJSON(){let e=super.toJSON();e.points=[];for(let t=0,n=this.points.length;t<n;t++){let n=this.points[t];e.points.push(n.toArray())}return e}fromJSON(e){super.fromJSON(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){let n=e.points[t];this.points.push(new K().fromArray(n))}return this}},ts=Object.freeze({__proto__:null,ArcCurve:jo,CatmullRomCurve3:Lo,CubicBezierCurve:Jo,CubicBezierCurve3:Yo,EllipseCurve:Ao,LineCurve:Xo,LineCurve3:Zo,QuadraticBezierCurve:Qo,QuadraticBezierCurve3:$o,SplineCurve:es}),ns=class extends ko{constructor(){super(),this.type=`CurvePath`,this.curves=[],this.autoClose=!1}add(e){this.curves.push(e)}closePath(){let e=this.curves[0].getPoint(0),t=this.curves[this.curves.length-1].getPoint(1);if(!e.equals(t)){let n=e.isVector2===!0?`LineCurve`:`LineCurve3`;this.curves.push(new ts[n](t,e))}return this}getPoint(e,t){let n=e*this.getLength(),r=this.getCurveLengths(),i=0;for(;i<r.length;){if(r[i]>=n){let e=r[i]-n,a=this.curves[i],o=a.getLength(),s=o===0?0:1-e/o;return a.getPointAt(s,t)}i++}return null}getLength(){let e=this.getCurveLengths();return e[e.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;let e=[],t=0;for(let n=0,r=this.curves.length;n<r;n++)t+=this.curves[n].getLength(),e.push(t);return this.cacheLengths=e,e}getSpacedPoints(e=40){let t=[];for(let n=0;n<=e;n++)t.push(this.getPoint(n/e));return this.autoClose&&t.push(t[0]),t}getPoints(e=12){let t=[],n;for(let r=0,i=this.curves;r<i.length;r++){let a=i[r],o=a.isEllipseCurve?e*2:a.isLineCurve||a.isLineCurve3?1:a.isSplineCurve?e*a.points.length:e,s=a.getPoints(o);for(let e=0;e<s.length;e++){let r=s[e];n&&n.equals(r)||(t.push(r),n=r)}}return this.autoClose&&t.length>1&&!t[t.length-1].equals(t[0])&&t.push(t[0]),t}copy(e){super.copy(e),this.curves=[];for(let t=0,n=e.curves.length;t<n;t++){let n=e.curves[t];this.curves.push(n.clone())}return this.autoClose=e.autoClose,this}toJSON(){let e=super.toJSON();e.autoClose=this.autoClose,e.curves=[];for(let t=0,n=this.curves.length;t<n;t++){let n=this.curves[t];e.curves.push(n.toJSON())}return e}fromJSON(e){super.fromJSON(e),this.autoClose=e.autoClose,this.curves=[];for(let t=0,n=e.curves.length;t<n;t++){let n=e.curves[t];this.curves.push(new ts[n.type]().fromJSON(n))}return this}},rs=class extends ns{constructor(e){super(),this.type=`Path`,this.currentPoint=new K,e&&this.setFromPoints(e)}setFromPoints(e){this.moveTo(e[0].x,e[0].y);for(let t=1,n=e.length;t<n;t++)this.lineTo(e[t].x,e[t].y);return this}moveTo(e,t){return this.currentPoint.set(e,t),this}lineTo(e,t){let n=new Xo(this.currentPoint.clone(),new K(e,t));return this.curves.push(n),this.currentPoint.set(e,t),this}quadraticCurveTo(e,t,n,r){let i=new Qo(this.currentPoint.clone(),new K(e,t),new K(n,r));return this.curves.push(i),this.currentPoint.set(n,r),this}bezierCurveTo(e,t,n,r,i,a){let o=new Jo(this.currentPoint.clone(),new K(e,t),new K(n,r),new K(i,a));return this.curves.push(o),this.currentPoint.set(i,a),this}splineThru(e){let t=new es([this.currentPoint.clone()].concat(e));return this.curves.push(t),this.currentPoint.copy(e[e.length-1]),this}arc(e,t,n,r,i,a){let o=this.currentPoint.x,s=this.currentPoint.y;return this.absarc(e+o,t+s,n,r,i,a),this}absarc(e,t,n,r,i,a){return this.absellipse(e,t,n,n,r,i,a),this}ellipse(e,t,n,r,i,a,o,s){let c=this.currentPoint.x,l=this.currentPoint.y;return this.absellipse(e+c,t+l,n,r,i,a,o,s),this}absellipse(e,t,n,r,i,a,o,s){let c=new Ao(e,t,n,r,i,a,o,s);if(this.curves.length>0){let e=c.getPoint(0);e.equals(this.currentPoint)||this.lineTo(e.x,e.y)}this.curves.push(c);let l=c.getPoint(1);return this.currentPoint.copy(l),this}copy(e){return super.copy(e),this.currentPoint.copy(e.currentPoint),this}toJSON(){let e=super.toJSON();return e.currentPoint=this.currentPoint.toArray(),e}fromJSON(e){return super.fromJSON(e),this.currentPoint.fromArray(e.currentPoint),this}},is=class e extends On{constructor(e=1,t=32,n=0,r=Math.PI*2){super(),this.type=`CircleGeometry`,this.parameters={radius:e,segments:t,thetaStart:n,thetaLength:r},t=Math.max(3,t);let i=[],a=[],o=[],s=[],c=new X,l=new K;a.push(0,0,0),o.push(0,0,1),s.push(.5,.5);for(let i=0,u=3;i<=t;i++,u+=3){let d=n+i/t*r;c.x=e*Math.cos(d),c.y=e*Math.sin(d),a.push(c.x,c.y,c.z),o.push(0,0,1),l.x=(a[u]/e+1)/2,l.y=(a[u+1]/e+1)/2,s.push(l.x,l.y)}for(let e=1;e<=t;e++)i.push(e,e+1,0);this.setIndex(i),this.setAttribute(`position`,new bn(a,3)),this.setAttribute(`normal`,new bn(o,3)),this.setAttribute(`uv`,new bn(s,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(t){return new e(t.radius,t.segments,t.thetaStart,t.thetaLength)}},as=class extends rs{constructor(e){super(e),this.uuid=R(),this.type=`Shape`,this.holes=[]}getPointsHoles(e){let t=[];for(let n=0,r=this.holes.length;n<r;n++)t[n]=this.holes[n].getPoints(e);return t}extractPoints(e){return{shape:this.getPoints(e),holes:this.getPointsHoles(e)}}copy(e){super.copy(e),this.holes=[];for(let t=0,n=e.holes.length;t<n;t++){let n=e.holes[t];this.holes.push(n.clone())}return this}toJSON(){let e=super.toJSON();e.uuid=this.uuid,e.holes=[];for(let t=0,n=this.holes.length;t<n;t++){let n=this.holes[t];e.holes.push(n.toJSON())}return e}fromJSON(e){super.fromJSON(e),this.uuid=e.uuid,this.holes=[];for(let t=0,n=e.holes.length;t<n;t++){let n=e.holes[t];this.holes.push(new rs().fromJSON(n))}return this}},os={triangulate:function(e,t,n=2){let r=t&&t.length,i=r?t[0]*n:e.length,a=ss(e,0,i,n,!0),o=[];if(!a||a.next===a.prev)return o;let s,c,l,u,d,f,p;if(r&&(a=ms(e,t,a,n)),e.length>80*n){s=l=e[0],c=u=e[1];for(let t=n;t<i;t+=n)d=e[t],f=e[t+1],d<s&&(s=d),f<c&&(c=f),d>l&&(l=d),f>u&&(u=f);p=Math.max(l-s,u-c),p=p===0?0:32767/p}return ls(a,o,n,s,c,p,0),o}};function ss(e,t,n,r,i){let a,o;if(i===Ls(e,t,n,r)>0)for(a=t;a<n;a+=r)o=Ps(a,e[a],e[a+1],o);else for(a=n-r;a>=t;a-=r)o=Ps(a,e[a],e[a+1],o);return o&&Es(o,o.next)&&(Fs(o),o=o.next),o}function cs(e,t){if(!e)return e;t||=e;let n=e,r;do if(r=!1,!n.steiner&&(Es(n,n.next)||Ts(n.prev,n,n.next)===0)){if(Fs(n),n=t=n.prev,n===n.next)break;r=!0}else n=n.next;while(r||n!==t);return t}function ls(e,t,n,r,i,a,o){if(!e)return;!o&&a&&ys(e,r,i,a);let s=e,c,l;for(;e.prev!==e.next;){if(c=e.prev,l=e.next,a?ds(e,r,i,a):us(e)){t.push(c.i/n|0),t.push(e.i/n|0),t.push(l.i/n|0),Fs(e),e=l.next,s=l.next;continue}if(e=l,e===s){o?o===1?(e=fs(cs(e),t,n),ls(e,t,n,r,i,a,2)):o===2&&ps(e,t,n,r,i,a):ls(cs(e),t,n,r,i,a,1);break}}}function us(e){let t=e.prev,n=e,r=e.next;if(Ts(t,n,r)>=0)return!1;let i=t.x,a=n.x,o=r.x,s=t.y,c=n.y,l=r.y,u=i<a?i<o?i:o:a<o?a:o,d=s<c?s<l?s:l:c<l?c:l,f=i>a?i>o?i:o:a>o?a:o,p=s>c?s>l?s:l:c>l?c:l,m=r.next;for(;m!==t;){if(m.x>=u&&m.x<=f&&m.y>=d&&m.y<=p&&Cs(i,s,a,c,o,l,m.x,m.y)&&Ts(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function ds(e,t,n,r){let i=e.prev,a=e,o=e.next;if(Ts(i,a,o)>=0)return!1;let s=i.x,c=a.x,l=o.x,u=i.y,d=a.y,f=o.y,p=s<c?s<l?s:l:c<l?c:l,m=u<d?u<f?u:f:d<f?d:f,h=s>c?s>l?s:l:c>l?c:l,g=u>d?u>f?u:f:d>f?d:f,_=xs(p,m,t,n,r),v=xs(h,g,t,n,r),y=e.prevZ,b=e.nextZ;for(;y&&y.z>=_&&b&&b.z<=v;){if(y.x>=p&&y.x<=h&&y.y>=m&&y.y<=g&&y!==i&&y!==o&&Cs(s,u,c,d,l,f,y.x,y.y)&&Ts(y.prev,y,y.next)>=0||(y=y.prevZ,b.x>=p&&b.x<=h&&b.y>=m&&b.y<=g&&b!==i&&b!==o&&Cs(s,u,c,d,l,f,b.x,b.y)&&Ts(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;y&&y.z>=_;){if(y.x>=p&&y.x<=h&&y.y>=m&&y.y<=g&&y!==i&&y!==o&&Cs(s,u,c,d,l,f,y.x,y.y)&&Ts(y.prev,y,y.next)>=0)return!1;y=y.prevZ}for(;b&&b.z<=v;){if(b.x>=p&&b.x<=h&&b.y>=m&&b.y<=g&&b!==i&&b!==o&&Cs(s,u,c,d,l,f,b.x,b.y)&&Ts(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function fs(e,t,n){let r=e;do{let i=r.prev,a=r.next.next;!Es(i,a)&&Ds(i,r,r.next,a)&&js(i,a)&&js(a,i)&&(t.push(i.i/n|0),t.push(r.i/n|0),t.push(a.i/n|0),Fs(r),Fs(r.next),r=e=a),r=r.next}while(r!==e);return cs(r)}function ps(e,t,n,r,i,a){let o=e;do{let e=o.next.next;for(;e!==o.prev;){if(o.i!==e.i&&ws(o,e)){let s=Ns(o,e);o=cs(o,o.next),s=cs(s,s.next),ls(o,t,n,r,i,a,0),ls(s,t,n,r,i,a,0);return}e=e.next}o=o.next}while(o!==e)}function ms(e,t,n,r){let i=[],a,o,s,c,l;for(a=0,o=t.length;a<o;a++)s=t[a]*r,c=a<o-1?t[a+1]*r:e.length,l=ss(e,s,c,r,!1),l===l.next&&(l.steiner=!0),i.push(Ss(l));for(i.sort(hs),a=0;a<i.length;a++)n=gs(i[a],n);return n}function hs(e,t){return e.x-t.x}function gs(e,t){let n=_s(e,t);if(!n)return t;let r=Ns(n,e);return cs(r,r.next),cs(n,n.next)}function _s(e,t){let n=t,r=-1/0,i,a=e.x,o=e.y;do{if(o<=n.y&&o>=n.next.y&&n.next.y!==n.y){let e=n.x+(o-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(e<=a&&e>r&&(r=e,i=n.x<n.next.x?n:n.next,e===a))return i}n=n.next}while(n!==t);if(!i)return null;let s=i,c=i.x,l=i.y,u=1/0,d;n=i;do a>=n.x&&n.x>=c&&a!==n.x&&Cs(o<l?a:r,o,c,l,o<l?r:a,o,n.x,n.y)&&(d=Math.abs(o-n.y)/(a-n.x),js(n,e)&&(d<u||d===u&&(n.x>i.x||n.x===i.x&&vs(i,n)))&&(i=n,u=d)),n=n.next;while(n!==s);return i}function vs(e,t){return Ts(e.prev,e,t.prev)<0&&Ts(t.next,e,e.next)<0}function ys(e,t,n,r){let i=e;do i.z===0&&(i.z=xs(i.x,i.y,t,n,r)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next;while(i!==e);i.prevZ.nextZ=null,i.prevZ=null,bs(i)}function bs(e){let t,n,r,i,a,o,s,c,l=1;do{for(n=e,e=null,a=null,o=0;n;){for(o++,r=n,s=0,t=0;t<l&&(s++,r=r.nextZ,r);t++);for(c=l;s>0||c>0&&r;)s!==0&&(c===0||!r||n.z<=r.z)?(i=n,n=n.nextZ,s--):(i=r,r=r.nextZ,c--),a?a.nextZ=i:e=i,i.prevZ=a,a=i;n=r}a.nextZ=null,l*=2}while(o>1);return e}function xs(e,t,n,r,i){return e=(e-n)*i|0,t=(t-r)*i|0,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e|t<<1}function Ss(e){let t=e,n=e;do(t.x<n.x||t.x===n.x&&t.y<n.y)&&(n=t),t=t.next;while(t!==e);return n}function Cs(e,t,n,r,i,a,o,s){return(i-o)*(t-s)>=(e-o)*(a-s)&&(e-o)*(r-s)>=(n-o)*(t-s)&&(n-o)*(a-s)>=(i-o)*(r-s)}function ws(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!As(e,t)&&(js(e,t)&&js(t,e)&&Ms(e,t)&&(Ts(e.prev,e,t.prev)||Ts(e,t.prev,t))||Es(e,t)&&Ts(e.prev,e,e.next)>0&&Ts(t.prev,t,t.next)>0)}function Ts(e,t,n){return(t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y)}function Es(e,t){return e.x===t.x&&e.y===t.y}function Ds(e,t,n,r){let i=ks(Ts(e,t,n)),a=ks(Ts(e,t,r)),o=ks(Ts(n,r,e)),s=ks(Ts(n,r,t));return!!(i!==a&&o!==s||i===0&&Os(e,n,t)||a===0&&Os(e,r,t)||o===0&&Os(n,e,r)||s===0&&Os(n,t,r))}function Os(e,t,n){return t.x<=Math.max(e.x,n.x)&&t.x>=Math.min(e.x,n.x)&&t.y<=Math.max(e.y,n.y)&&t.y>=Math.min(e.y,n.y)}function ks(e){return e>0?1:e<0?-1:0}function As(e,t){let n=e;do{if(n.i!==e.i&&n.next.i!==e.i&&n.i!==t.i&&n.next.i!==t.i&&Ds(n,n.next,e,t))return!0;n=n.next}while(n!==e);return!1}function js(e,t){return Ts(e.prev,e,e.next)<0?Ts(e,t,e.next)>=0&&Ts(e,e.prev,t)>=0:Ts(e,t,e.prev)<0||Ts(e,e.next,t)<0}function Ms(e,t){let n=e,r=!1,i=(e.x+t.x)/2,a=(e.y+t.y)/2;do n.y>a!=n.next.y>a&&n.next.y!==n.y&&i<(n.next.x-n.x)*(a-n.y)/(n.next.y-n.y)+n.x&&(r=!r),n=n.next;while(n!==e);return r}function Ns(e,t){let n=new Is(e.i,e.x,e.y),r=new Is(t.i,t.x,t.y),i=e.next,a=t.prev;return e.next=t,t.prev=e,n.next=i,i.prev=n,r.next=n,n.prev=r,a.next=r,r.prev=a,r}function Ps(e,t,n,r){let i=new Is(e,t,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function Fs(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function Is(e,t,n){this.i=e,this.x=t,this.y=n,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function Ls(e,t,n,r){let i=0;for(let a=t,o=n-r;a<n;a+=r)i+=(e[o]-e[a])*(e[a+1]+e[o+1]),o=a;return i}var Rs=class e{static area(e){let t=e.length,n=0;for(let r=t-1,i=0;i<t;r=i++)n+=e[r].x*e[i].y-e[i].x*e[r].y;return n*.5}static isClockWise(t){return e.area(t)<0}static triangulateShape(e,t){let n=[],r=[],i=[];zs(e),Bs(n,e);let a=e.length;t.forEach(zs);for(let e=0;e<t.length;e++)r.push(a),a+=t[e].length,Bs(n,t[e]);let o=os.triangulate(n,r);for(let e=0;e<o.length;e+=3)i.push(o.slice(e,e+3));return i}};function zs(e){let t=e.length;t>2&&e[t-1].equals(e[0])&&e.pop()}function Bs(e,t){for(let n=0;n<t.length;n++)e.push(t[n].x),e.push(t[n].y)}var Vs=class e extends On{constructor(e=.5,t=1,n=32,r=1,i=0,a=Math.PI*2){super(),this.type=`RingGeometry`,this.parameters={innerRadius:e,outerRadius:t,thetaSegments:n,phiSegments:r,thetaStart:i,thetaLength:a},n=Math.max(3,n),r=Math.max(1,r);let o=[],s=[],c=[],l=[],u=e,d=(t-e)/r,f=new X,p=new K;for(let e=0;e<=r;e++){for(let e=0;e<=n;e++){let r=i+e/n*a;f.x=u*Math.cos(r),f.y=u*Math.sin(r),s.push(f.x,f.y,f.z),c.push(0,0,1),p.x=(f.x/t+1)/2,p.y=(f.y/t+1)/2,l.push(p.x,p.y)}u+=d}for(let e=0;e<r;e++){let t=e*(n+1);for(let e=0;e<n;e++){let r=e+t,i=r,a=r+n+1,s=r+n+2,c=r+1;o.push(i,a,c),o.push(a,s,c)}}this.setIndex(o),this.setAttribute(`position`,new bn(s,3)),this.setAttribute(`normal`,new bn(c,3)),this.setAttribute(`uv`,new bn(l,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(t){return new e(t.innerRadius,t.outerRadius,t.thetaSegments,t.phiSegments,t.thetaStart,t.thetaLength)}},Hs=class e extends On{constructor(e=new as([new K(0,.5),new K(-.5,-.5),new K(.5,-.5)]),t=12){super(),this.type=`ShapeGeometry`,this.parameters={shapes:e,curveSegments:t};let n=[],r=[],i=[],a=[],o=0,s=0;if(Array.isArray(e)===!1)c(e);else for(let t=0;t<e.length;t++)c(e[t]),this.addGroup(o,s,t),o+=s,s=0;this.setIndex(n),this.setAttribute(`position`,new bn(r,3)),this.setAttribute(`normal`,new bn(i,3)),this.setAttribute(`uv`,new bn(a,2));function c(e){let o=r.length/3,c=e.extractPoints(t),l=c.shape,u=c.holes;Rs.isClockWise(l)===!1&&(l=l.reverse());for(let e=0,t=u.length;e<t;e++){let t=u[e];Rs.isClockWise(t)===!0&&(u[e]=t.reverse())}let d=Rs.triangulateShape(l,u);for(let e=0,t=u.length;e<t;e++){let t=u[e];l=l.concat(t)}for(let e=0,t=l.length;e<t;e++){let t=l[e];r.push(t.x,t.y,0),i.push(0,0,1),a.push(t.x,t.y)}for(let e=0,t=d.length;e<t;e++){let t=d[e],r=t[0]+o,i=t[1]+o,a=t[2]+o;n.push(r,i,a),s+=3}}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){let e=super.toJSON(),t=this.parameters.shapes;return Us(t,e)}static fromJSON(t,n){let r=[];for(let e=0,i=t.shapes.length;e<i;e++){let i=n[t.shapes[e]];r.push(i)}return new e(r,t.curveSegments)}};function Us(e,t){if(t.shapes=[],Array.isArray(e))for(let n=0,r=e.length;n<r;n++){let r=e[n];t.shapes.push(r.uuid)}else t.shapes.push(e.uuid);return t}var Ws=class e extends On{constructor(e=1,t=32,n=16,r=0,i=Math.PI*2,a=0,o=Math.PI){super(),this.type=`SphereGeometry`,this.parameters={radius:e,widthSegments:t,heightSegments:n,phiStart:r,phiLength:i,thetaStart:a,thetaLength:o},t=Math.max(3,Math.floor(t)),n=Math.max(2,Math.floor(n));let s=Math.min(a+o,Math.PI),c=0,l=[],u=new X,d=new X,f=[],p=[],m=[],h=[];for(let f=0;f<=n;f++){let g=[],_=f/n,v=0;f===0&&a===0?v=.5/t:f===n&&s===Math.PI&&(v=-.5/t);for(let n=0;n<=t;n++){let s=n/t;u.x=-e*Math.cos(r+s*i)*Math.sin(a+_*o),u.y=e*Math.cos(a+_*o),u.z=e*Math.sin(r+s*i)*Math.sin(a+_*o),p.push(u.x,u.y,u.z),d.copy(u).normalize(),m.push(d.x,d.y,d.z),h.push(s+v,1-_),g.push(c++)}l.push(g)}for(let e=0;e<n;e++)for(let r=0;r<t;r++){let t=l[e][r+1],i=l[e][r],o=l[e+1][r],c=l[e+1][r+1];(e!==0||a>0)&&f.push(t,i,c),(e!==n-1||s<Math.PI)&&f.push(i,o,c)}this.setIndex(f),this.setAttribute(`position`,new bn(p,3)),this.setAttribute(`normal`,new bn(m,3)),this.setAttribute(`uv`,new bn(h,2))}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}static fromJSON(t){return new e(t.radius,t.widthSegments,t.heightSegments,t.phiStart,t.phiLength,t.thetaStart,t.thetaLength)}},Gs=class extends xo{constructor(e){super(),this.isLineDashedMaterial=!0,this.type=`LineDashedMaterial`,this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(e)}copy(e){return super.copy(e),this.scale=e.scale,this.dashSize=e.dashSize,this.gapSize=e.gapSize,this}};function Ks(e,t,n){return!e||!n&&e.constructor===t?e:typeof t.BYTES_PER_ELEMENT==`number`?new t(e):Array.prototype.slice.call(e)}function qs(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}var Js=class{constructor(e,t,n,r){this.parameterPositions=e,this._cachedIndex=0,this.resultBuffer=r===void 0?new t.constructor(n):r,this.sampleValues=t,this.valueSize=n,this.settings=null,this.DefaultSettings_={}}evaluate(e){let t=this.parameterPositions,n=this._cachedIndex,r=t[n],i=t[n-1];validate_interval:{seek:{let a;linear_scan:{forward_scan:if(!(e<r)){for(let a=n+2;;){if(r===void 0){if(e<i)break forward_scan;return n=t.length,this._cachedIndex=n,this.copySampleValue_(n-1)}if(n===a)break;if(i=r,r=t[++n],e<r)break seek}a=t.length;break linear_scan}if(!(e>=i)){let o=t[1];e<o&&(n=2,i=o);for(let a=n-2;;){if(i===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(n===a)break;if(r=i,i=t[--n-1],e>=i)break seek}a=n,n=0;break linear_scan}break validate_interval}for(;n<a;){let r=n+a>>>1;e<t[r]?a=r:n=r+1}if(r=t[n],i=t[n-1],i===void 0)return this._cachedIndex=0,this.copySampleValue_(0);if(r===void 0)return n=t.length,this._cachedIndex=n,this.copySampleValue_(n-1)}this._cachedIndex=n,this.intervalChanged_(n,i,r)}return this.interpolate_(n,i,e,r)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(e){let t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r;for(let e=0;e!==r;++e)t[e]=n[i+e];return t}interpolate_(){throw Error(`call to abstract method`)}intervalChanged_(){}},Ys=class extends Js{constructor(e,t,n,r){super(e,t,n,r),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:C,endingEnd:C}}intervalChanged_(e,t,n){let r=this.parameterPositions,i=e-2,a=e+1,o=r[i],s=r[a];if(o===void 0)switch(this.getSettings_().endingStart){case w:i=e,o=2*t-n;break;case T:i=r.length-2,o=t+r[i]-r[i+1];break;default:i=e,o=n}if(s===void 0)switch(this.getSettings_().endingEnd){case w:a=e,s=2*n-t;break;case T:a=1,s=n+r[1]-r[0];break;default:a=e-1,s=t}let c=(n-t)*.5,l=this.valueSize;this._weightPrev=c/(t-o),this._weightNext=c/(s-n),this._offsetPrev=i*l,this._offsetNext=a*l}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=e*o,c=s-o,l=this._offsetPrev,u=this._offsetNext,d=this._weightPrev,f=this._weightNext,p=(n-t)/(r-t),m=p*p,h=m*p,g=-d*h+2*d*m-d*p,_=(1+d)*h+(-1.5-2*d)*m+(-.5+d)*p+1,v=(-1-f)*h+(1.5+f)*m+.5*p,y=f*h-f*m;for(let e=0;e!==o;++e)i[e]=g*a[l+e]+_*a[c+e]+v*a[s+e]+y*a[u+e];return i}},Xs=class extends Js{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=e*o,c=s-o,l=(n-t)/(r-t),u=1-l;for(let e=0;e!==o;++e)i[e]=a[c+e]*u+a[s+e]*l;return i}},Zs=class extends Js{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e){return this.copySampleValue_(e-1)}},Qs=class{constructor(e,t,n,r){if(e===void 0)throw Error(`THREE.KeyframeTrack: track name is undefined`);if(t===void 0||t.length===0)throw Error(`THREE.KeyframeTrack: no keyframes in track named `+e);this.name=e,this.times=Ks(t,this.TimeBufferType),this.values=Ks(n,this.ValueBufferType),this.setInterpolation(r||this.DefaultInterpolation)}static toJSON(e){let t=e.constructor,n;if(t.toJSON!==this.toJSON)n=t.toJSON(e);else{n={name:e.name,times:Ks(e.times,Array),values:Ks(e.values,Array)};let t=e.getInterpolation();t!==e.DefaultInterpolation&&(n.interpolation=t)}return n.type=e.ValueTypeName,n}InterpolantFactoryMethodDiscrete(e){return new Zs(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodLinear(e){return new Xs(this.times,this.values,this.getValueSize(),e)}InterpolantFactoryMethodSmooth(e){return new Ys(this.times,this.values,this.getValueSize(),e)}setInterpolation(e){let t;switch(e){case b:t=this.InterpolantFactoryMethodDiscrete;break;case x:t=this.InterpolantFactoryMethodLinear;break;case S:t=this.InterpolantFactoryMethodSmooth;break}if(t===void 0){let t=`unsupported interpolation for `+this.ValueTypeName+` keyframe track named `+this.name;if(this.createInterpolant===void 0)if(e!==this.DefaultInterpolation)this.setInterpolation(this.DefaultInterpolation);else throw Error(t);return console.warn(`THREE.KeyframeTrack:`,t),this}return this.createInterpolant=t,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return b;case this.InterpolantFactoryMethodLinear:return x;case this.InterpolantFactoryMethodSmooth:return S}}getValueSize(){return this.values.length/this.times.length}shift(e){if(e!==0){let t=this.times;for(let n=0,r=t.length;n!==r;++n)t[n]+=e}return this}scale(e){if(e!==1){let t=this.times;for(let n=0,r=t.length;n!==r;++n)t[n]*=e}return this}trim(e,t){let n=this.times,r=n.length,i=0,a=r-1;for(;i!==r&&n[i]<e;)++i;for(;a!==-1&&n[a]>t;)--a;if(++a,i!==0||a!==r){i>=a&&(a=Math.max(a,1),i=a-1);let e=this.getValueSize();this.times=n.slice(i,a),this.values=this.values.slice(i*e,a*e)}return this}validate(){let e=!0,t=this.getValueSize();t-Math.floor(t)!==0&&(console.error(`THREE.KeyframeTrack: Invalid value size in track.`,this),e=!1);let n=this.times,r=this.values,i=n.length;i===0&&(console.error(`THREE.KeyframeTrack: Track is empty.`,this),e=!1);let a=null;for(let t=0;t!==i;t++){let r=n[t];if(typeof r==`number`&&isNaN(r)){console.error(`THREE.KeyframeTrack: Time is not a valid number.`,this,t,r),e=!1;break}if(a!==null&&a>r){console.error(`THREE.KeyframeTrack: Out of order keys.`,this,t,r,a),e=!1;break}a=r}if(r!==void 0&&qs(r))for(let t=0,n=r.length;t!==n;++t){let n=r[t];if(isNaN(n)){console.error(`THREE.KeyframeTrack: Value is not a valid number.`,this,t,n),e=!1;break}}return e}optimize(){let e=this.times.slice(),t=this.values.slice(),n=this.getValueSize(),r=this.getInterpolation()===S,i=e.length-1,a=1;for(let o=1;o<i;++o){let i=!1,s=e[o];if(s!==e[o+1]&&(o!==1||s!==e[0]))if(r)i=!0;else{let e=o*n,r=e-n,a=e+n;for(let o=0;o!==n;++o){let n=t[e+o];if(n!==t[r+o]||n!==t[a+o]){i=!0;break}}}if(i){if(o!==a){e[a]=e[o];let r=o*n,i=a*n;for(let e=0;e!==n;++e)t[i+e]=t[r+e]}++a}}if(i>0){e[a]=e[i];for(let e=i*n,r=a*n,o=0;o!==n;++o)t[r+o]=t[e+o];++a}return a===e.length?(this.times=e,this.values=t):(this.times=e.slice(0,a),this.values=t.slice(0,a*n)),this}clone(){let e=this.times.slice(),t=this.values.slice(),n=this.constructor,r=new n(this.name,e,t);return r.createInterpolant=this.createInterpolant,r}};Qs.prototype.TimeBufferType=Float32Array,Qs.prototype.ValueBufferType=Float32Array,Qs.prototype.DefaultInterpolation=x;var $s=class extends Qs{};$s.prototype.ValueTypeName=`bool`,$s.prototype.ValueBufferType=Array,$s.prototype.DefaultInterpolation=b,$s.prototype.InterpolantFactoryMethodLinear=void 0,$s.prototype.InterpolantFactoryMethodSmooth=void 0;var ec=class extends Qs{};ec.prototype.ValueTypeName=`color`;var tc=class extends Qs{};tc.prototype.ValueTypeName=`number`;var nc=class extends Js{constructor(e,t,n,r){super(e,t,n,r)}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=(n-t)/(r-t),c=e*o;for(let e=c+o;c!==e;c+=4)Ke.slerpFlat(i,0,a,c-o,a,c,s);return i}},rc=class extends Qs{InterpolantFactoryMethodLinear(e){return new nc(this.times,this.values,this.getValueSize(),e)}};rc.prototype.ValueTypeName=`quaternion`,rc.prototype.DefaultInterpolation=x,rc.prototype.InterpolantFactoryMethodSmooth=void 0;var ic=class extends Qs{};ic.prototype.ValueTypeName=`string`,ic.prototype.ValueBufferType=Array,ic.prototype.DefaultInterpolation=b,ic.prototype.InterpolantFactoryMethodLinear=void 0,ic.prototype.InterpolantFactoryMethodSmooth=void 0;var ac=class extends Qs{};ac.prototype.ValueTypeName=`vector`;var oc={enabled:!1,files:{},add:function(e,t){this.enabled!==!1&&(this.files[e]=t)},get:function(e){if(this.enabled!==!1)return this.files[e]},remove:function(e){delete this.files[e]},clear:function(){this.files={}}},sc=new class{constructor(e,t,n){let r=this,i=!1,a=0,o=0,s,c=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=n,this.itemStart=function(e){o++,i===!1&&r.onStart!==void 0&&r.onStart(e,a,o),i=!0},this.itemEnd=function(e){a++,r.onProgress!==void 0&&r.onProgress(e,a,o),a===o&&(i=!1,r.onLoad!==void 0&&r.onLoad())},this.itemError=function(e){r.onError!==void 0&&r.onError(e)},this.resolveURL=function(e){return s?s(e):e},this.setURLModifier=function(e){return s=e,this},this.addHandler=function(e,t){return c.push(e,t),this},this.removeHandler=function(e){let t=c.indexOf(e);return t!==-1&&c.splice(t,2),this},this.getHandler=function(e){for(let t=0,n=c.length;t<n;t+=2){let n=c[t],r=c[t+1];if(n.global&&(n.lastIndex=0),n.test(e))return r}return null}}},cc=class{constructor(e){this.manager=e===void 0?sc:e,this.crossOrigin=`anonymous`,this.withCredentials=!1,this.path=``,this.resourcePath=``,this.requestHeader={}}load(){}loadAsync(e,t){let n=this;return new Promise(function(r,i){n.load(e,r,t,i)})}parse(){}setCrossOrigin(e){return this.crossOrigin=e,this}setWithCredentials(e){return this.withCredentials=e,this}setPath(e){return this.path=e,this}setResourcePath(e){return this.resourcePath=e,this}setRequestHeader(e){return this.requestHeader=e,this}};cc.DEFAULT_MATERIAL_NAME=`__DEFAULT`;var lc=class extends cc{constructor(e){super(e)}load(e,t,n,r){this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);let i=this,a=oc.get(e);if(a!==void 0)return i.manager.itemStart(e),setTimeout(function(){t&&t(a),i.manager.itemEnd(e)},0),a;let o=we(`img`);function s(){l(),oc.add(e,this),t&&t(this),i.manager.itemEnd(e)}function c(t){l(),r&&r(t),i.manager.itemError(e),i.manager.itemEnd(e)}function l(){o.removeEventListener(`load`,s,!1),o.removeEventListener(`error`,c,!1)}return o.addEventListener(`load`,s,!1),o.addEventListener(`error`,c,!1),e.slice(0,5)!==`data:`&&this.crossOrigin!==void 0&&(o.crossOrigin=this.crossOrigin),i.manager.itemStart(e),o.src=e,o}},uc=class extends cc{constructor(e){super(e)}load(e,t,n,r){let i=new Be,a=new lc(this.manager);return a.setCrossOrigin(this.crossOrigin),a.setPath(this.path),a.load(e,function(e){i.image=e,i.needsUpdate=!0,t!==void 0&&t(i)},n,r),i}},dc=`\\[\\]\\.:\\/`,fc=RegExp(`[\\[\\]\\.:\\/]`,`g`),pc=`[^\\[\\]\\.:\\/]`,mc=`[^`+dc.replace(`\\.`,``)+`]`,hc=`((?:WC+[\\/:])*)`.replace(`WC`,pc),gc=`(WCOD+)?`.replace(`WCOD`,mc),_c=`(?:\\.(WC+)(?:\\[(.+)\\])?)?`.replace(`WC`,pc),vc=`\\.(WC+)(?:\\[(.+)\\])?`.replace(`WC`,pc),yc=RegExp(`^`+hc+gc+_c+vc+`$`),bc=[`material`,`materials`,`bones`,`map`],xc=class{constructor(e,t,n){let r=n||Sc.parseTrackName(t);this._targetGroup=e,this._bindings=e.subscribe_(t,r)}getValue(e,t){this.bind();let n=this._targetGroup.nCachedObjects_,r=this._bindings[n];r!==void 0&&r.getValue(e,t)}setValue(e,t){let n=this._bindings;for(let r=this._targetGroup.nCachedObjects_,i=n.length;r!==i;++r)n[r].setValue(e,t)}bind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,n=e.length;t!==n;++t)e[t].bind()}unbind(){let e=this._bindings;for(let t=this._targetGroup.nCachedObjects_,n=e.length;t!==n;++t)e[t].unbind()}},Sc=class e{constructor(t,n,r){this.path=n,this.parsedPath=r||e.parseTrackName(n),this.node=e.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,n,r){return t&&t.isAnimationObjectGroup?new e.Composite(t,n,r):new e(t,n,r)}static sanitizeNodeName(e){return e.replace(/\s/g,`_`).replace(fc,``)}static parseTrackName(e){let t=yc.exec(e);if(t===null)throw Error(`PropertyBinding: Cannot parse trackName: `+e);let n={nodeName:t[2],objectName:t[3],objectIndex:t[4],propertyName:t[5],propertyIndex:t[6]},r=n.nodeName&&n.nodeName.lastIndexOf(`.`);if(r!==void 0&&r!==-1){let e=n.nodeName.substring(r+1);bc.indexOf(e)!==-1&&(n.nodeName=n.nodeName.substring(0,r),n.objectName=e)}if(n.propertyName===null||n.propertyName.length===0)throw Error(`PropertyBinding: can not parse propertyName from trackName: `+e);return n}static findNode(e,t){if(t===void 0||t===``||t===`.`||t===-1||t===e.name||t===e.uuid)return e;if(e.skeleton){let n=e.skeleton.getBoneByName(t);if(n!==void 0)return n}if(e.children){let n=function(e){for(let r=0;r<e.length;r++){let i=e[r];if(i.name===t||i.uuid===t)return i;let a=n(i.children);if(a)return a}return null},r=n(e.children);if(r)return r}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(e,t){e[t]=this.targetObject[this.propertyName]}_getValue_array(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)e[t++]=n[r]}_getValue_arrayElement(e,t){e[t]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(e,t){this.resolvedProperty.toArray(e,t)}_setValue_direct(e,t){this.targetObject[this.propertyName]=e[t]}_setValue_direct_setNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(e,t){this.targetObject[this.propertyName]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)n[r]=e[t++]}_setValue_array_setNeedsUpdate(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)n[r]=e[t++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(e,t){let n=this.resolvedProperty;for(let r=0,i=n.length;r!==i;++r)n[r]=e[t++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(e,t){this.resolvedProperty[this.propertyIndex]=e[t]}_setValue_arrayElement_setNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty[this.propertyIndex]=e[t],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(e,t){this.resolvedProperty.fromArray(e,t)}_setValue_fromArray_setNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(e,t){this.resolvedProperty.fromArray(e,t),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(e,t){this.bind(),this.getValue(e,t)}_setValue_unbound(e,t){this.bind(),this.setValue(e,t)}bind(){let t=this.node,n=this.parsedPath,r=n.objectName,i=n.propertyName,a=n.propertyIndex;if(t||(t=e.findNode(this.rootNode,n.nodeName),this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t){console.warn(`THREE.PropertyBinding: No target node found for track: `+this.path+`.`);return}if(r){let e=n.objectIndex;switch(r){case`materials`:if(!t.material){console.error(`THREE.PropertyBinding: Can not bind to material as node does not have a material.`,this);return}if(!t.material.materials){console.error(`THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.`,this);return}t=t.material.materials;break;case`bones`:if(!t.skeleton){console.error(`THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.`,this);return}t=t.skeleton.bones;for(let n=0;n<t.length;n++)if(t[n].name===e){e=n;break}break;case`map`:if(`map`in t){t=t.map;break}if(!t.material){console.error(`THREE.PropertyBinding: Can not bind to material as node does not have a material.`,this);return}if(!t.material.map){console.error(`THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.`,this);return}t=t.material.map;break;default:if(t[r]===void 0){console.error(`THREE.PropertyBinding: Can not bind to objectName of node undefined.`,this);return}t=t[r]}if(e!==void 0){if(t[e]===void 0){console.error(`THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.`,this,t);return}t=t[e]}}let o=t[i];if(o===void 0){let e=n.nodeName;console.error(`THREE.PropertyBinding: Trying to update property for track: `+e+`.`+i+` but it wasn't found.`,t);return}let s=this.Versioning.None;this.targetObject=t,t.needsUpdate===void 0?t.matrixWorldNeedsUpdate!==void 0&&(s=this.Versioning.MatrixWorldNeedsUpdate):s=this.Versioning.NeedsUpdate;let c=this.BindingType.Direct;if(a!==void 0){if(i===`morphTargetInfluences`){if(!t.geometry){console.error(`THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.`,this);return}if(!t.geometry.morphAttributes){console.error(`THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.`,this);return}t.morphTargetDictionary[a]!==void 0&&(a=t.morphTargetDictionary[a])}c=this.BindingType.ArrayElement,this.resolvedProperty=o,this.propertyIndex=a}else o.fromArray!==void 0&&o.toArray!==void 0?(c=this.BindingType.HasFromToArray,this.resolvedProperty=o):Array.isArray(o)?(c=this.BindingType.EntireArray,this.resolvedProperty=o):this.propertyName=i;this.getValue=this.GetterByBindingType[c],this.setValue=this.SetterByBindingTypeAndVersioning[c][s]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}};Sc.Composite=xc,Sc.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},Sc.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},Sc.prototype.GetterByBindingType=[Sc.prototype._getValue_direct,Sc.prototype._getValue_array,Sc.prototype._getValue_arrayElement,Sc.prototype._getValue_toArray],Sc.prototype.SetterByBindingTypeAndVersioning=[[Sc.prototype._setValue_direct,Sc.prototype._setValue_direct_setNeedsUpdate,Sc.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[Sc.prototype._setValue_array,Sc.prototype._setValue_array_setNeedsUpdate,Sc.prototype._setValue_array_setMatrixWorldNeedsUpdate],[Sc.prototype._setValue_arrayElement,Sc.prototype._setValue_arrayElement_setNeedsUpdate,Sc.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[Sc.prototype._setValue_fromArray,Sc.prototype._setValue_fromArray_setNeedsUpdate,Sc.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];var Cc=class{constructor(e,t,n=0,r=1/0){this.ray=new xt(e,t),this.near=n,this.far=r,this.camera=null,this.layers=new Nt,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(e,t){this.ray.set(e,t)}setFromCamera(e,t){t.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(t.matrixWorld),this.ray.direction.set(e.x,e.y,.5).unproject(t).sub(this.ray.origin).normalize(),this.camera=t):t.isOrthographicCamera?(this.ray.origin.set(e.x,e.y,(t.near+t.far)/(t.near-t.far)).unproject(t),this.ray.direction.set(0,0,-1).transformDirection(t.matrixWorld),this.camera=t):console.error(`THREE.Raycaster: Unsupported camera type: `+t.type)}intersectObject(e,t=!0,n=[]){return Tc(e,this,n,t),n.sort(wc),n}intersectObjects(e,t=!0,n=[]){for(let r=0,i=e.length;r<i;r++)Tc(e[r],this,n,t);return n.sort(wc),n}};function wc(e,t){return e.distance-t.distance}function Tc(e,t,n,r){if(e.layers.test(t.layers)&&e.raycast(t,n),r===!0){let r=e.children;for(let e=0,i=r.length;e<i;e++)Tc(r[e],t,n,!0)}}typeof __THREE_DEVTOOLS__<`u`&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent(`register`,{detail:{revision:`159`}})),typeof window<`u`&&(window.__THREE__?console.warn(`WARNING: Multiple instances of Three.js being imported.`):window.__THREE__=`159`);var Ec={Linear:{None:function(e){return e}},Quadratic:{In:function(e){return e*e},Out:function(e){return e*(2-e)},InOut:function(e){return(e*=2)<1?.5*e*e:-.5*(--e*(e-2)-1)}},Cubic:{In:function(e){return e*e*e},Out:function(e){return--e*e*e+1},InOut:function(e){return(e*=2)<1?.5*e*e*e:.5*((e-=2)*e*e+2)}},Quartic:{In:function(e){return e*e*e*e},Out:function(e){return 1- --e*e*e*e},InOut:function(e){return(e*=2)<1?.5*e*e*e*e:-.5*((e-=2)*e*e*e-2)}},Quintic:{In:function(e){return e*e*e*e*e},Out:function(e){return--e*e*e*e*e+1},InOut:function(e){return(e*=2)<1?.5*e*e*e*e*e:.5*((e-=2)*e*e*e*e+2)}},Sinusoidal:{In:function(e){return 1-Math.cos(e*Math.PI/2)},Out:function(e){return Math.sin(e*Math.PI/2)},InOut:function(e){return .5*(1-Math.cos(Math.PI*e))}},Exponential:{In:function(e){return e===0?0:1024**(e-1)},Out:function(e){return e===1?1:1-2**(-10*e)},InOut:function(e){return e===0?0:e===1?1:(e*=2)<1?.5*1024**(e-1):.5*(-(2**(-10*(e-1)))+2)}},Circular:{In:function(e){return 1-Math.sqrt(1-e*e)},Out:function(e){return Math.sqrt(1- --e*e)},InOut:function(e){return(e*=2)<1?-.5*(Math.sqrt(1-e*e)-1):.5*(Math.sqrt(1-(e-=2)*e)+1)}},Elastic:{In:function(e){return e===0?0:e===1?1:-(2**(10*(e-1)))*Math.sin((e-1.1)*5*Math.PI)},Out:function(e){return e===0?0:e===1?1:2**(-10*e)*Math.sin((e-.1)*5*Math.PI)+1},InOut:function(e){return e===0?0:e===1?1:(e*=2,e<1?-.5*2**(10*(e-1))*Math.sin((e-1.1)*5*Math.PI):.5*2**(-10*(e-1))*Math.sin((e-1.1)*5*Math.PI)+1)}},Back:{In:function(e){var t=1.70158;return e*e*((t+1)*e-t)},Out:function(e){var t=1.70158;return--e*e*((t+1)*e+t)+1},InOut:function(e){var t=1.70158*1.525;return(e*=2)<1?.5*(e*e*((t+1)*e-t)):.5*((e-=2)*e*((t+1)*e+t)+2)}},Bounce:{In:function(e){return 1-Ec.Bounce.Out(1-e)},Out:function(e){return e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375},InOut:function(e){return e<.5?Ec.Bounce.In(e*2)*.5:Ec.Bounce.Out(e*2-1)*.5+.5}}},Dc=typeof self>`u`&&typeof process<`u`&&process.hrtime?function(){var e=process.hrtime();return e[0]*1e3+e[1]/1e6}:typeof self<`u`&&self.performance!==void 0&&self.performance.now!==void 0?self.performance.now.bind(self.performance):Date.now===void 0?function(){return new Date().getTime()}:Date.now,Oc=function(){function e(){this._tweens={},this._tweensAddedDuringUpdate={}}return e.prototype.getAll=function(){var e=this;return Object.keys(this._tweens).map(function(t){return e._tweens[t]})},e.prototype.removeAll=function(){this._tweens={}},e.prototype.add=function(e){this._tweens[e.getId()]=e,this._tweensAddedDuringUpdate[e.getId()]=e},e.prototype.remove=function(e){delete this._tweens[e.getId()],delete this._tweensAddedDuringUpdate[e.getId()]},e.prototype.update=function(e,t){e===void 0&&(e=Dc()),t===void 0&&(t=!1);var n=Object.keys(this._tweens);if(n.length===0)return!1;for(;n.length>0;){this._tweensAddedDuringUpdate={};for(var r=0;r<n.length;r++){var i=this._tweens[n[r]],a=!t;i&&i.update(e,a)===!1&&!t&&delete this._tweens[n[r]]}n=Object.keys(this._tweensAddedDuringUpdate)}return!0},e}(),kc={Linear:function(e,t){var n=e.length-1,r=n*t,i=Math.floor(r),a=kc.Utils.Linear;return t<0?a(e[0],e[1],r):t>1?a(e[n],e[n-1],n-r):a(e[i],e[i+1>n?n:i+1],r-i)},Bezier:function(e,t){for(var n=0,r=e.length-1,i=Math.pow,a=kc.Utils.Bernstein,o=0;o<=r;o++)n+=i(1-t,r-o)*i(t,o)*e[o]*a(r,o);return n},CatmullRom:function(e,t){var n=e.length-1,r=n*t,i=Math.floor(r),a=kc.Utils.CatmullRom;return e[0]===e[n]?(t<0&&(i=Math.floor(r=n*(1+t))),a(e[(i-1+n)%n],e[i],e[(i+1)%n],e[(i+2)%n],r-i)):t<0?e[0]-(a(e[0],e[0],e[1],e[1],-r)-e[0]):t>1?e[n]-(a(e[n],e[n],e[n-1],e[n-1],r-n)-e[n]):a(e[i?i-1:0],e[i],e[n<i+1?n:i+1],e[n<i+2?n:i+2],r-i)},Utils:{Linear:function(e,t,n){return(t-e)*n+e},Bernstein:function(e,t){var n=kc.Utils.Factorial;return n(e)/n(t)/n(e-t)},Factorial:(function(){var e=[1];return function(t){var n=1;if(e[t])return e[t];for(var r=t;r>1;r--)n*=r;return e[t]=n,n}})(),CatmullRom:function(e,t,n,r,i){var a=(n-e)*.5,o=(r-t)*.5,s=i*i,c=i*s;return(2*t-2*n+a+o)*c+(-3*t+3*n-2*a-o)*s+a*i+t}}},Ac=function(){function e(){}return e.nextId=function(){return e._nextId++},e._nextId=0,e}(),jc=new Oc,Mc=function(){function e(e,t){t===void 0&&(t=jc),this._object=e,this._group=t,this._isPaused=!1,this._pauseStart=0,this._valuesStart={},this._valuesEnd={},this._valuesStartRepeat={},this._duration=1e3,this._initialRepeat=0,this._repeat=0,this._yoyo=!1,this._isPlaying=!1,this._reversed=!1,this._delayTime=0,this._startTime=0,this._easingFunction=Ec.Linear.None,this._interpolationFunction=kc.Linear,this._chainedTweens=[],this._onStartCallbackFired=!1,this._id=Ac.nextId(),this._isChainStopped=!1,this._goToEnd=!1}return e.prototype.getId=function(){return this._id},e.prototype.isPlaying=function(){return this._isPlaying},e.prototype.isPaused=function(){return this._isPaused},e.prototype.to=function(e,t){return this._valuesEnd=Object.create(e),t!==void 0&&(this._duration=t),this},e.prototype.duration=function(e){return this._duration=e,this},e.prototype.start=function(e){if(this._isPlaying)return this;if(this._group&&this._group.add(this),this._repeat=this._initialRepeat,this._reversed)for(var t in this._reversed=!1,this._valuesStartRepeat)this._swapEndStartRepeatValues(t),this._valuesStart[t]=this._valuesStartRepeat[t];return this._isPlaying=!0,this._isPaused=!1,this._onStartCallbackFired=!1,this._isChainStopped=!1,this._startTime=e===void 0?Dc():typeof e==`string`?Dc()+parseFloat(e):e,this._startTime+=this._delayTime,this._setupProperties(this._object,this._valuesStart,this._valuesEnd,this._valuesStartRepeat),this},e.prototype._setupProperties=function(e,t,n,r){for(var i in n){var a=e[i],o=Array.isArray(a),s=o?`array`:typeof a,c=!o&&Array.isArray(n[i]);if(!(s===`undefined`||s===`function`)){if(c){var l=n[i];if(l.length===0)continue;l=l.map(this._handleRelativeValue.bind(this,a)),n[i]=[a].concat(l)}if((s===`object`||o)&&a&&!c){for(var u in t[i]=o?[]:{},a)t[i][u]=a[u];r[i]=o?[]:{},this._setupProperties(a,t[i],n[i],r[i])}else t[i]===void 0&&(t[i]=a),o||(t[i]*=1),c?r[i]=n[i].slice().reverse():r[i]=t[i]||0}}},e.prototype.stop=function(){return this._isChainStopped||(this._isChainStopped=!0,this.stopChainedTweens()),this._isPlaying?(this._group&&this._group.remove(this),this._isPlaying=!1,this._isPaused=!1,this._onStopCallback&&this._onStopCallback(this._object),this):this},e.prototype.end=function(){return this._goToEnd=!0,this.update(1/0),this},e.prototype.pause=function(e){return e===void 0&&(e=Dc()),this._isPaused||!this._isPlaying?this:(this._isPaused=!0,this._pauseStart=e,this._group&&this._group.remove(this),this)},e.prototype.resume=function(e){return e===void 0&&(e=Dc()),!this._isPaused||!this._isPlaying?this:(this._isPaused=!1,this._startTime+=e-this._pauseStart,this._pauseStart=0,this._group&&this._group.add(this),this)},e.prototype.stopChainedTweens=function(){for(var e=0,t=this._chainedTweens.length;e<t;e++)this._chainedTweens[e].stop();return this},e.prototype.group=function(e){return this._group=e,this},e.prototype.delay=function(e){return this._delayTime=e,this},e.prototype.repeat=function(e){return this._initialRepeat=e,this._repeat=e,this},e.prototype.repeatDelay=function(e){return this._repeatDelayTime=e,this},e.prototype.yoyo=function(e){return this._yoyo=e,this},e.prototype.easing=function(e){return this._easingFunction=e,this},e.prototype.interpolation=function(e){return this._interpolationFunction=e,this},e.prototype.chain=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return this._chainedTweens=e,this},e.prototype.onStart=function(e){return this._onStartCallback=e,this},e.prototype.onUpdate=function(e){return this._onUpdateCallback=e,this},e.prototype.onRepeat=function(e){return this._onRepeatCallback=e,this},e.prototype.onComplete=function(e){return this._onCompleteCallback=e,this},e.prototype.onStop=function(e){return this._onStopCallback=e,this},e.prototype.update=function(e,t){if(e===void 0&&(e=Dc()),t===void 0&&(t=!0),this._isPaused)return!0;var n,r,i=this._startTime+this._duration;if(!this._goToEnd&&!this._isPlaying){if(e>i)return!1;t&&this.start(e)}if(this._goToEnd=!1,e<this._startTime)return!0;this._onStartCallbackFired===!1&&(this._onStartCallback&&this._onStartCallback(this._object),this._onStartCallbackFired=!0),r=(e-this._startTime)/this._duration,r=this._duration===0||r>1?1:r;var a=this._easingFunction(r);if(this._updateProperties(this._object,this._valuesStart,this._valuesEnd,a),this._onUpdateCallback&&this._onUpdateCallback(this._object,r),r===1)if(this._repeat>0){for(n in isFinite(this._repeat)&&this._repeat--,this._valuesStartRepeat)!this._yoyo&&typeof this._valuesEnd[n]==`string`&&(this._valuesStartRepeat[n]=this._valuesStartRepeat[n]+parseFloat(this._valuesEnd[n])),this._yoyo&&this._swapEndStartRepeatValues(n),this._valuesStart[n]=this._valuesStartRepeat[n];return this._yoyo&&(this._reversed=!this._reversed),this._repeatDelayTime===void 0?this._startTime=e+this._delayTime:this._startTime=e+this._repeatDelayTime,this._onRepeatCallback&&this._onRepeatCallback(this._object),!0}else{this._onCompleteCallback&&this._onCompleteCallback(this._object);for(var o=0,s=this._chainedTweens.length;o<s;o++)this._chainedTweens[o].start(this._startTime+this._duration);return this._isPlaying=!1,!1}return!0},e.prototype._updateProperties=function(e,t,n,r){for(var i in n)if(t[i]!==void 0){var a=t[i]||0,o=n[i];!Array.isArray(e[i])&&Array.isArray(o)?e[i]=this._interpolationFunction(o,r):typeof o==`object`&&o?this._updateProperties(e[i],a,o,r):(o=this._handleRelativeValue(a,o),typeof o==`number`&&(e[i]=a+(o-a)*r))}},e.prototype._handleRelativeValue=function(e,t){return typeof t==`string`?t.charAt(0)===`+`||t.charAt(0)===`-`?e+parseFloat(t):parseFloat(t):t},e.prototype._swapEndStartRepeatValues=function(e){var t=this._valuesStartRepeat[e],n=this._valuesEnd[e];typeof n==`string`?this._valuesStartRepeat[e]=this._valuesStartRepeat[e]+parseFloat(n):this._valuesStartRepeat[e]=this._valuesEnd[e],this._valuesEnd[e]=t},e}();Ac.nextId;var Nc=jc;Nc.getAll.bind(Nc),Nc.removeAll.bind(Nc),Nc.add.bind(Nc),Nc.remove.bind(Nc),Nc.update.bind(Nc);var Pc=new Oc,Fc=new X(0,-1,0),Ic=new X(1,0,0),Lc=new X(0,0,-1),Rc=8,zc=e=>(e%1+1)%1,Bc=e=>(e%360+360)%360;function Vc(e){return zc(.75-e/360)}function Hc(e,t){let n=e.clone().normalize();return[zc(Math.atan2(n.z,n.x)/(2*Math.PI)+Vc(t)),1-Math.acos(Se.clamp(n.y,-1,1))/Math.PI]}function Uc(e,t,n,r){let[i,a]=Hc(e,t);return[Math.min(n-1,Math.floor(i*n)),Math.min(r-1,Math.floor((1-a)*r))]}function Wc(e,t=0,n=new Ke){return n.setFromAxisAngle(Fc,Se.degToRad(e)).multiply(new Ke().setFromAxisAngle(Ic,Se.degToRad(t)))}function Gc(e){let t=e.clone().normalize();return{heading:Bc(Se.radToDeg(Math.atan2(t.x,-t.z))),pitch:Se.radToDeg(Math.asin(Se.clamp(t.y,-1,1)))}}function Kc(e){let t=Lc.clone().applyQuaternion(e);return Bc(Se.radToDeg(Math.atan2(t.x,-t.z)))}function qc(e,t,n=new X){let r=e.distanceTo(t),i=e.bearingTo(t);return n.set(r*Math.sin(i),0,-r*Math.cos(i))}function Jc(e,t,n=new X){if(e.alt===null||t.alt===null)throw Error(`Placing a point in the panorama needs its altitude and the node's.`);return qc(e,t,n).setY(t.alt-e.alt)}function Yc(e,t){let n=t.x,r=-t.z;return e.destinationPoint(Math.hypot(n,r),Math.atan2(n,r))}function Xc(e,t){let n=new X;return e&&e.level===t.level&&qc(e.coordinates,t.coordinates,n),n.length()>Rc?n.set(0,0,0):n}var Zc=4,Qc=.95,$c=.01,el=.3,tl={type:`change`},nl={type:`start`},rl={type:`end`},il=class extends F{config;minFov=20;maxFov=100;defaultFov=65;_autoRotate=!1;autoRotateSpeed=.05;sensibility=.1;camera;sphere;_lat=0;_lon=0;isUserInteracting=!1;onMouseDownMouseX=0;onMouseDownMouseY=0;onMouseDownLon=0;onMouseDownLat=0;autoRotateTimestamp=0;isArrowKeyPressed=!1;currentTween=null;velocityLon=0;velocityLat=0;lastMouseX=0;lastMouseY=0;lastUpdateTime=0;animationFrameId=null;element;constructor(e,t,n,r={}){super(),this.camera=t,this.sphere=n,this.config=r,this.element=e,e.addEventListener(`mousedown`,this.onPointerStart,{passive:!1}),e.addEventListener(`mousemove`,this.onPointerMove,{passive:!1}),e.addEventListener(`mouseup`,this.onPointerUp,{passive:!1}),e.addEventListener(`mouseout`,this.onPointerUp,{passive:!1}),r.zoomEnable&&e.addEventListener(`wheel`,this.onDocumentMouseWheel,{passive:!1}),e.addEventListener(`touchstart`,this.onPointerStart,{passive:!1}),e.addEventListener(`touchmove`,this.onPointerMove,{passive:!1}),e.addEventListener(`touchend`,this.onPointerUp,{passive:!1}),e.tabIndex<0&&(e.tabIndex=0),e.addEventListener(`keydown`,this.onKeyDown),this.camera.position.copy(n.position),this.camera.quaternion.copy(n.quaternion),this.camera.up=n.up,this.camera.fov=this.defaultFov,this.minFov=r.minFov||this.minFov,this.maxFov=r.maxFov||this.maxFov,this.update()}dispose(){let e=this.element;e.removeEventListener(`mousedown`,this.onPointerStart),e.removeEventListener(`mousemove`,this.onPointerMove),e.removeEventListener(`mouseup`,this.onPointerUp),e.removeEventListener(`mouseout`,this.onPointerUp),e.removeEventListener(`wheel`,this.onDocumentMouseWheel),e.removeEventListener(`touchstart`,this.onPointerStart),e.removeEventListener(`touchmove`,this.onPointerMove),e.removeEventListener(`touchend`,this.onPointerUp),e.removeEventListener(`keydown`,this.onKeyDown),this.animationFrameId!==null&&cancelAnimationFrame(this.animationFrameId)}get lat(){return this._lat}set lat(e){this._lat=Math.max(-85,Math.min(85,e)),this.update()}get lon(){return this._lon}set lon(e){this._lon=e%360,this.update()}get autoRotate(){return this._autoRotate}set autoRotate(e){this._autoRotate=e,e?this.retrieveLatLonFromCamera():this.autoRotateTimestamp=0}updateFov(e){if(this.config.zoomEnable){let t={fov:this.camera.fov},n={fov:e},r=new Mc(t).to(n,400).easing(Ec.Cubic.InOut).onUpdate(e=>{this.camera.fov=e.fov,this.camera.updateProjectionMatrix()}).onComplete(()=>{Pc.remove(r)});Pc.add(r),r.start()}}retrieveLatLonFromCamera(){let e=new Mt().setFromQuaternion(this.sphere.quaternion.clone().conjugate().multiply(this.camera.quaternion),`YXZ`);this._lon=Se.radToDeg(-e.y),this._lat=Se.radToDeg(e.x)}onPointerStart=e=>{e.preventDefault(),this.element.focus({preventScroll:!0}),this.isUserInteracting=!0;let t=e instanceof MouseEvent?e.clientX:e.touches[0].screenX,n=e instanceof MouseEvent?e.clientY:e.touches[0].screenY;this.onMouseDownMouseX=t,this.onMouseDownMouseY=n,this.retrieveLatLonFromCamera(),this.onMouseDownLon=this._lon,this.onMouseDownLat=this._lat,this.animationFrameId!==null&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=null),this.velocityLon=0,this.velocityLat=0,this.dispatchEvent(nl)};onPointerMove=e=>{if(e.preventDefault(),e.stopPropagation(),this.isUserInteracting){let t=e instanceof MouseEvent?e.clientX:e.touches[0].screenX,n=e instanceof MouseEvent?e.clientY:e.touches[0].screenY,r=performance.now(),i=r-this.lastUpdateTime;if(i>0){let e=t-this.lastMouseX,r=n-this.lastMouseY;this.velocityLon=-e/i*el,this.velocityLat=r/i*el}this._lon=(this.onMouseDownMouseX-t)*this.sensibility+this.onMouseDownLon,this._lat=(n-this.onMouseDownMouseY)*this.sensibility+this.onMouseDownLat,this.lastMouseX=t,this.lastMouseY=n,this.lastUpdateTime=r,this.update(),this.dispatchEvent(tl)}};onPointerUp=e=>{e.preventDefault(),this.isUserInteracting=!1,(Math.abs(this.velocityLon)>$c||Math.abs(this.velocityLat)>$c)&&(this.animationFrameId=requestAnimationFrame(this.updateVelocity)),this.dispatchEvent(rl)};onDocumentMouseWheel=e=>{e.preventDefault();let t=this.camera.fov+e.deltaY*.05;this.camera.fov=Se.clamp(t,this.minFov,this.maxFov),this.camera.updateProjectionMatrix()};onKeyDown=e=>{let t=!0;switch(e.key){case`ArrowLeft`:this._lon=(this._lon-Zc)%360;break;case`ArrowRight`:this._lon=(this._lon+Zc)%360;break;case`ArrowUp`:this._lat=Math.max(-85,Math.min(85,this._lat+Zc));break;case`ArrowDown`:this._lat=Math.max(-85,Math.min(85,this._lat-Zc));break;default:t=!1}t&&(e.preventDefault(),this.isArrowKeyPressed=!0,this.update(),this.dispatchEvent(tl))};update(){if(this._autoRotate&&!this.isUserInteracting&&!this.isArrowKeyPressed){let e=this.autoRotateTimestamp;if(this.autoRotateTimestamp=performance.now(),e){let t=(this.autoRotateTimestamp-e)/1e3;this._lon=(this._lon+this.autoRotateSpeed*360*t)%360}}let e=Wc(this._lon,this._lat);if(this.isArrowKeyPressed){this.isArrowKeyPressed=!1;let t=this.camera.quaternion.clone(),n=this.sphere.quaternion.clone().multiply(e),r={t:0};this.currentTween&&this.currentTween.stop();let i=new Ke,a=new Mc(r).to({t:1},400).easing(Ec.Cubic.Out).onUpdate(()=>{i.slerpQuaternions(t,n,r.t),this.camera.quaternion.set(i.x,i.y,i.z,i.w)}).start().onStop(()=>{Pc.remove(a)}).onComplete(()=>{Pc.remove(a)});Pc.add(a),this.currentTween=a}else this.camera.quaternion.copy(this.sphere.quaternion.clone().multiply(e))}updateVelocity=()=>{Math.abs(this.velocityLon)>$c||Math.abs(this.velocityLat)>$c?(this._lon=(this._lon+this.velocityLon)%360,this._lat=Math.max(-85,Math.min(85,this._lat+this.velocityLat)),this.velocityLon*=Qc,this.velocityLat*=Qc,Math.abs(this.velocityLon)<$c&&(this.velocityLon=0),Math.abs(this.velocityLat)<$c&&(this.velocityLat=0),this.update(),this.dispatchEvent(tl),this.animationFrameId=requestAnimationFrame(this.updateVelocity)):this.animationFrameId=null}},al=1.5,ol=50,sl=5,cl=.01;function ll(e,t){return new as().moveTo(-t,-e).lineTo(t,-e).lineTo(t,-t).lineTo(e,-t).lineTo(e,t).lineTo(t,t).lineTo(t,e).lineTo(-t,e).lineTo(-t,t).lineTo(-e,t).lineTo(-e,-t).lineTo(-t,-t).lineTo(-t,-e)}function ul(e,t){return new mn({color:e,transparent:!0,opacity:t,side:2,depthTest:!1})}var dl=class{mode=`navigate`;scene;camera;element;callbacks;walk;raycaster=new Cc;floor=new mr(new X(0,1,0),al);pointer=new K;hit=new X;disc;cross;pressedAt=null;target=null;constructor(e,t,n,r,i=!0){this.scene=e,this.camera=t,this.element=n,this.callbacks=r,this.walk=i,this.disc=new Kn(new is(.2,48),ul(5096447,.55)),this.disc.rotation.x=-Math.PI/2,this.disc.renderOrder=999;let a=new Kn(new Hs(ll(.17,.03)),ul(16777215,.5));a.renderOrder=999;let o=new Kn(new Hs(ll(.16,.02)),ul(7105644,.75));o.renderOrder=1e3,this.cross=new qt,this.cross.add(a,o),this.cross.rotation.x=-Math.PI/2,this.hide(),e.add(this.disc,this.cross),n.addEventListener(`pointermove`,this.onPointerMove),n.addEventListener(`pointerdown`,this.onPointerDown),n.addEventListener(`pointerup`,this.onPointerUp),n.addEventListener(`pointerleave`,this.onPointerLeave)}hide(){this.disc.visible=!1,this.cross.visible=!1,this.target=null,this.element.style.cursor=``}dispose(){this.element.removeEventListener(`pointermove`,this.onPointerMove),this.element.removeEventListener(`pointerdown`,this.onPointerDown),this.element.removeEventListener(`pointerup`,this.onPointerUp),this.element.removeEventListener(`pointerleave`,this.onPointerLeave),this.scene.remove(this.disc,this.cross);for(let e of[this.disc,...this.cross.children])e.geometry.dispose(),e.material.dispose()}onPointerMove=e=>{e.pointerType===`mouse`&&this.update(e)};onPointerDown=e=>{this.pressedAt={x:e.clientX,y:e.clientY}};onPointerUp=e=>{let t=this.pressedAt;if(this.pressedAt=null,!(!t||Math.abs(e.clientX-t.x)>sl||Math.abs(e.clientY-t.y)>sl)){if(this.mode!==`navigate`){this.callbacks.current()&&(this.aim(e),this.callbacks.pick(this.raycaster.ray.direction.clone()));return}this.update(e),this.target?this.callbacks.select(this.target):this.callbacks.current()&&(this.aim(e),this.callbacks.miss(this.raycaster.ray.direction.clone()))}};onPointerLeave=()=>{this.hide()};aim(e){let t=this.element.getBoundingClientRect();this.pointer.set((e.clientX-t.left)/t.width*2-1,-((e.clientY-t.top)/t.height)*2+1),this.raycaster.setFromCamera(this.pointer,this.camera)}update(e){let t=this.callbacks.current();if(this.mode!==`navigate`){this.hide(),this.element.style.cursor=t?`crosshair`:``;return}if(!this.walk){this.hide();return}this.aim(e);let n=this.raycaster.ray.intersectPlane(this.floor,this.hit);if(!t||!n||n.length()>ol){this.hide();return}this.disc.position.set(n.x,n.y+cl,n.z),this.disc.visible=!0;let r=this.callbacks.nearest(Yc(t.coordinates,n));if(this.target=r,!r){this.cross.visible=!1,this.element.style.cursor=``;return}qc(t.coordinates,r.coordinates,this.cross.position).y=-1.49,this.cross.visible=!0,this.element.style.cursor=`pointer`}},fl=4,pl=.065,ml=.075,hl=1e3,gl=e=>(e.depthTest=!1,e.transparent=!0,e),_l=class{scene;group=new fo;constructor(e){this.scene=e,e.add(this.group)}get count(){return this.group.children.filter(e=>e instanceof fo).length}add(e){let t=e.clone().normalize().multiplyScalar(fl),n=new fo,r=new Kn(new Vs(pl,ml,48),gl(new mn({color:16777215,opacity:.8,side:2}))),i=new Kn(new is(pl,48),gl(new mn({color:16711680,side:2})));r.renderOrder=hl,i.renderOrder=hl,n.add(r,i),n.position.copy(t),n.lookAt(0,0,0),this.group.add(n);let a=this.group.children.filter(e=>e instanceof fo);if(a.length===2){let e=new Do(new On().setFromPoints([a[0].position,a[1].position]),gl(new Gs({color:16711680,dashSize:.06,gapSize:.04})));e.computeLineDistances(),e.renderOrder=hl-1,this.group.add(e)}}clear(){for(let e of[...this.group.children])e.traverse(e=>{(e instanceof Kn||e instanceof Do)&&(e.geometry.dispose(),e.material.dispose())}),this.group.remove(e)}dispose(){this.clear(),this.scene.remove(this.group)}},vl=`#2F7DE1`,yl=.25,bl=1001;function xl(e){let t=new X;e.forEach((n,r)=>{let i=e[(r+1)%e.length];t.x+=(n.y-i.y)*(n.z+i.z),t.y+=(n.z-i.z)*(n.x+i.x),t.z+=(n.x-i.x)*(n.y+i.y)}),t.normalize();let n=new X().subVectors(e[1],e[0]).normalize(),r=new X().crossVectors(t,n);return e.map(t=>{let i=new X().subVectors(t,e[0]);return new K(i.dot(n),i.dot(r))})}var Sl=class{scene;group=new fo;polygons=[];origin=null;constructor(e){this.scene=e,e.add(this.group)}set(e){this.polygons=e,this.build()}placeAt(e){e!==this.origin&&(this.origin=e,this.build())}build(){this.clear();let e=this.origin;if(e)for(let t of this.polygons){if(t.coordinates.length<3)continue;let n=t.coordinates.map(t=>Jc(e.coordinates,t)),r=new Z(t.color??vl),i=Rs.triangulateShape(xl(n),[]),a=new Kn(new On().setFromPoints(i.flat().map(e=>n[e])),new mn({color:r,opacity:t.fillOpacity??yl,transparent:!0,side:2,depthTest:!1})),o=new Oo(new On().setFromPoints(n),new xo({color:new Z(t.outlineColor??t.color??vl),transparent:!0,depthTest:!1}));a.renderOrder=bl,o.renderOrder=bl,this.group.add(a,o)}}clear(){for(let e of[...this.group.children])(e instanceof Kn||e instanceof Oo)&&(e.geometry.dispose(),e.material.dispose()),this.group.remove(e)}dispose(){this.clear(),this.scene.remove(this.group)}},Cl=700,wl=300,Tl=5,El=e=>new uc().loadAsync(e).catch(()=>{throw Error(`Failed to load panorama image: ${e}`)}),Dl=e=>e<.5?2*e*e:1-(-2*e+2)**2/2;function Ol(){return new rr({uniforms:{t1:{value:null},t2:{value:null},o1:{value:0},o2:{value:0},c2:{value:new X},radius:{value:Tl},transition:{value:0}},depthWrite:!1,depthTest:!1,vertexShader:`
3642
+ varying vec3 vWorld;
3643
+ void main() {
3644
+ vWorld = (modelMatrix * vec4(position, 1.0)).xyz;
3645
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
3646
+ }
3647
+ `,fragmentShader:`
3648
+ const float PI = 3.141592653589793;
3649
+ uniform sampler2D t1;
3650
+ uniform sampler2D t2;
3651
+ uniform float o1;
3652
+ uniform float o2;
3653
+ uniform vec3 c2;
3654
+ uniform float radius;
3655
+ uniform float transition;
3656
+ varying vec3 vWorld;
3657
+
3658
+ // Where the view ray hits the proxy sphere around \`center\`, as a direction from it.
3659
+ vec3 proxyDirection(vec3 ray, vec3 center) {
3660
+ vec3 p = cameraPosition - center;
3661
+ float b = dot(p, ray);
3662
+ return normalize(p + (-b + sqrt(b * b - dot(p, p) + radius * radius)) * ray);
3663
+ }
3664
+
3665
+ // Shader twin of SceneFrame.imageUv(): keep the two in step.
3666
+ vec2 equirect(vec3 d, float offset) {
3667
+ return vec2(atan(d.z, d.x) / (2.0 * PI) + offset, 1.0 - acos(clamp(d.y, -1.0, 1.0)) / PI);
3668
+ }
3669
+
3670
+ void main() {
3671
+ vec3 ray = normalize(vWorld - cameraPosition);
3672
+ vec4 tex1 = texture2D(t1, equirect(proxyDirection(ray, vec3(0.0)), o1));
3673
+ vec4 tex2 = texture2D(t2, equirect(proxyDirection(ray, c2), o2));
3674
+ gl_FragColor = mix(tex1, tex2, transition);
3675
+ }
3676
+ `})}var kl=class{material=Ol();shownNode=null;pending=null;fade=null;disposed=!1;cameraOffset=new X;loadImage;constructor(e=El){this.loadImage=e}get shown(){return this.shownNode}get shownImageSize(){let e=this.material.uniforms.t1.value?.image;return this.shownNode&&e?{width:e.width,height:e.height}:null}get busy(){return this.pending!==null}async show(e){this.pending=e;let t;try{t=await this.loadImage(e.image)}catch(t){if(this.pending!==e||this.disposed)return!1;throw this.pending=null,t}if(this.pending!==e||this.disposed)return t.dispose(),!1;this.fade&&this.settle(),t.wrapS=r,t.generateMipmaps=!1,t.minFilter=l;let n=Xc(this.shownNode,e),i=this.material.uniforms;return i.t2.value=t,i.o2.value=Vc(e.heading),i.c2.value.copy(n),i.radius.value=Math.max(Tl,n.length()*1.5),i.transition.value=0,this.fade={node:e,texture:t,move:n,duration:this.shownNode?Cl:wl,start:null},!0}update(e){let t=this.fade;if(!t)return this.cameraOffset.set(0,0,0);t.start??=e;let n=Math.min(1,(e-t.start)/t.duration);if(n>=1)return this.settle(),this.cameraOffset.set(0,0,0);let r=Dl(n);return this.material.uniforms.transition.value=r,this.cameraOffset.copy(t.move).multiplyScalar(r)}dispose(){this.disposed=!0,this.pending=null,this.fade=null;let e=this.material.uniforms;e.t1.value?.dispose(),e.t2.value?.dispose(),e.t1.value=null,e.t2.value=null,this.material.dispose()}settle(){let e=this.fade;this.fade=null;let t=this.material.uniforms;t.t1.value?.dispose(),t.t1.value=e.texture,t.o1.value=t.o2.value,t.t2.value=null,t.transition.value=0,t.c2.value.set(0,0,0),this.shownNode=e.node,this.pending===e.node&&(this.pending=null)}};async function Al(e,t){let n=await fetch(e,t);if(!n.ok)throw Error(`Request failed (${n.status}): ${e}`);return n.json()}function jl(e,n){return e.images.map(e=>({id:e.id,coordinates:new t.Coordinates(e.coords.lat,e.coords.lng,e.coords.alt??null,e.coords.level),level:e.coords.level,image:n(e.filename),heading:e.heading}))}var Ml=class{endpoint;constructor(e){let t=e??n.CoreConfig.getViewerOptions().vpsEndpoint;if(!t)throw Error(`No VPS endpoint configured for this livemap — the 360° viewer is unavailable. Call core.init() with an emmid that has AR/VPS enabled.`);this.endpoint=t}imageUrl(e){return`${this.endpoint}360-viewer/image/${e}`}getGraph(){return Al(`${this.endpoint}360-viewer/graph.json`)}getGraphGeojson(){return Al(`${this.endpoint}360-viewer/graph.geojson`)}async getNodes(){return jl(await this.getGraph(),e=>this.imageUrl(e))}async locate(e,n,r){let i=await Al(`${this.endpoint}360-viewer/image/${e.id}/coordinates`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({x:n,y:r})});return new t.Coordinates(i.lat,i.lng,i.alt??null,i.level??e.level)}async measure(e,t,n){let r=await Al(`${this.endpoint}360-viewer/image/${e.id}/measure`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({x1:t[0],y1:t[1],x2:n[0],y2:n[1]})}),i=typeof r==`number`?r:r?.distance;if(typeof i!=`number`||!Number.isFinite(i))throw Error(`The VPS returned no distance for this measurement.`);return i}},Nl=1e4,Pl=65,Fl=80,Il=class{container;options;scene=new bo;camera;renderer;sphereObject=new qt;sphere;transition;controls;pointer;measureOverlay;polygonOverlay;measureStart=null;measureRun=0;data=null;nodes=[];graph=null;current=null;arrival=null;geojson=null;listeners={navigate:new Set,heading:new Set,ready:new Set,locate:new Set,measure:new Set,click:new Set};turn=null;readyFired=!1;rafId=null;resizeObserver;constructor(e,t={}){this.container=e,this.options=t,this.transition=new kl;let{clientWidth:n,clientHeight:r}=e;this.camera=new ar(Pl,n/Math.max(r,1),.1,Nl*2),this.renderer=new vo({antialias:!0}),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(n,r),this.renderer.domElement.classList.add(`wemap-viewer__canvas`),e.appendChild(this.renderer.domElement),this.sphere=new Kn(new Ws(Nl,64,64),this.transition.material),this.sphere.geometry.scale(-1,1,1),this.sphereObject.add(this.sphere),this.scene.add(this.sphereObject),this.controls=new il(this.renderer.domElement,this.camera,this.sphereObject,{zoomEnable:t.zoom??!0,minFov:10,maxFov:t.maxFov??Fl}),this.controls.addEventListener(`change`,this.emitHeading),this.controls.addEventListener(`end`,this.emitHeading),this.controls.addEventListener(`start`,()=>this.turn?.stop()),this.pointer=new dl(this.scene,this.camera,this.renderer.domElement,{current:()=>this.transition.busy?null:this.current,nearest:e=>this.closestNode(e,this.current?.level,this.current),select:e=>this.navigateTo(e.id),pick:e=>{this.pointer.mode===`measure`?this.measureAt(e):this.locateAt(e)},miss:e=>{let t=this.transition.shown;if(t){let n={...Gc(e),node:t};this.options.onClick?.(n),this.emit(`click`,n)}}},t.navigation??!0),this.measureOverlay=new _l(this.scene),this.polygonOverlay=new Sl(this.scene),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(e),this.rafId=requestAnimationFrame(this.animate)}async open(e,t={}){try{let n=await this.loadGraph(),r=typeof e==`number`?n.find(t=>t.id===e):this.closestNode(e,typeof e.level==`number`?e.level:void 0);if(!r)throw Error(`No 360° node ${typeof e==`number`?e:`near this position`}.`);t.heading!==void 0&&this.face(t.heading,t.pitch??0),await this.moveTo(r)}catch(e){let t=e instanceof Error?e:Error(String(e));throw this.options.onError?.(t),t}}loadGraph(){return this.graph??=(async()=>{this.data??=new Ml;let e=await this.data.getNodes();if(!e.length)throw Error(`The 360° image graph is empty for this livemap.`);return this.nodes=e,e})().catch(e=>{throw this.graph=null,e}),this.graph}face(e,t){if(this.transition.shown){this.lookAt(e,t);return}this.turn?.stop(),this.controls.lon=e,this.controls.lat=t,this.emitHeading()}getNodes(){return this.nodes}get currentNode(){return this.current}async getGraphGeojson(){return this.data??=new Ml,this.geojson??=await this.data.getGraphGeojson(),this.geojson}on(e,t){return this.listeners[e].add(t),()=>{this.listeners[e].delete(t)}}emit(e,t){for(let n of this.listeners[e])n(t)}navigateTo(e){let t=this.nodes.find(t=>t.id===e);!t||t===this.current||this.moveTo(t).catch(e=>this.options.onError?.(e))}moveTo(e){return e===this.current&&this.arrival?this.arrival:(this.setCurrent(e),this.arrival=this.transition.show(e).then(e=>{e&&this.fireReady()},e=>{let t=this.transition.shown;throw this.arrival=t?Promise.resolve():null,t?t!==this.current&&this.setCurrent(t):this.current=null,e}),this.arrival)}fireReady(){this.readyFired||(this.readyFired=!0,this.options.onReady?.(),this.emit(`ready`,void 0),this.emitHeading())}setCurrent(e){this.current=e,this.pointer.hide(),this.clearMeasurement(),this.options.onNavigate?.(e.id),this.emit(`navigate`,e)}nearestNode(e,t){return this.closestNode(e,t)}closestNode(e,t,n){let r=null,i=1/0;for(let a of this.nodes){if(a===n||t!==void 0&&a.level!==t)continue;let o=e.distanceTo(a.coordinates);o<i&&(i=o,r=a)}return r}setPolygons(e){this.polygonOverlay.set(e)}lookAt(e,t=0){let n=this.controls;this.turn?.stop();let r={lon:n.lon,lat:n.lat},i=((e-r.lon)%360+540)%360-180,a=new Mc(r).to({lon:r.lon+i,lat:t},800).easing(Ec.Cubic.InOut).onUpdate(({lon:e,lat:t})=>{n.lon=e,n.lat=t,this.emitHeading()}).onStop(()=>Pc.remove(a)).onComplete(()=>Pc.remove(a)).start();Pc.add(a),this.turn=a}resize(){let{clientWidth:e,clientHeight:t}=this.container;!e||!t||(this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.renderer.setSize(e,t))}destroy(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.resizeObserver.disconnect(),this.turn?.stop(),this.controls.dispose(),this.pointer.dispose(),this.measureOverlay.dispose(),this.polygonOverlay.dispose(),this.transition.dispose(),this.sphere.geometry.dispose(),this.renderer.dispose(),this.renderer.domElement.remove()}get clickMode(){return this.pointer.mode}setClickMode(e){this.pointer.mode=e,this.pointer.hide(),this.clearMeasurement()}async measureAt(e){let t=this.transition.shown,n=this.transition.shownImageSize;if(!t||!n||!this.data)return;if(this.measureOverlay.count===2){this.clearMeasurement();return}let r=Uc(e,t.heading,n.width,n.height);if(this.measureOverlay.add(e),!this.measureStart){this.measureStart=r;return}let i=this.measureRun;try{let e={distance:await this.data.measure(t,this.measureStart,r),node:t};if(i!==this.measureRun)return;this.options.onMeasure?.(e),this.emit(`measure`,e)}catch(e){if(i!==this.measureRun)return;this.clearMeasurement(),this.options.onError?.(e instanceof Error?e:Error(String(e)))}}clearMeasurement(){this.measureRun+=1,this.measureStart=null,this.measureOverlay.clear()}async locateAt(e){let t=this.transition.shown,n=this.transition.shownImageSize;if(!(!t||!n||!this.data))try{let[r,i]=Uc(e,t.heading,n.width,n.height),a={coordinates:await this.data.locate(t,r,i),node:t};this.options.onLocate?.(a),this.emit(`locate`,a)}catch(e){this.options.onError?.(e instanceof Error?e:Error(String(e)))}}getHeading(){return Kc(this.camera.quaternion)}emitHeading=()=>{let e=this.getHeading();this.options.onHeadingChange?.(e),this.emit(`heading`,e)};animate=e=>{this.rafId=requestAnimationFrame(this.animate),Pc.update(e),this.camera.position.copy(this.transition.update(e)),this.polygonOverlay.placeAt(this.transition.shown),this.controls.autoRotate&&this.controls.update(),this.renderer.render(this.scene,this.camera)}};e.SphereControls=il,e.ViewerDataClient=Ml,e.WemapViewer=Il,e.graphToNodes=jl});