>8&255]+or[e>>16&255]+or[e>>24&255]+"-"+or[n&255]+or[n>>8&255]+"-"+or[n>>16&15|64]+or[n>>24&255]+"-"+or[i&63|128]+or[i>>8&255]+"-"+or[i>>16&255]+or[i>>24&255]+or[l&255]+or[l>>8&255]+or[l>>16&255]+or[l>>24&255];return h.toUpperCase()},clamp:function(e,n,i){return Math.max(n,Math.min(i,e))},euclideanModulo:function(e,n){return(e%n+n)%n},mapLinear:function(e,n,i,l,h){return l+(e-n)*(h-l)/(i-n)},lerp:function(e,n,i){return(1-i)*e+i*n},smoothstep:function(e,n,i){return e<=n?0:e>=i?1:(e=(e-n)/(i-n),e*e*(3-2*e))},smootherstep:function(e,n,i){return e<=n?0:e>=i?1:(e=(e-n)/(i-n),e*e*e*(e*(e*6-15)+10))},randInt:function(e,n){return e+Math.floor(Math.random()*(n-e+1))},randFloat:function(e,n){return e+Math.random()*(n-e)},randFloatSpread:function(e){return e*(.5-Math.random())},degToRad:function(e){return e*Wn.DEG2RAD},radToDeg:function(e){return e*Wn.RAD2DEG},isPowerOfTwo:function(e){return(e&e-1)===0&&e!==0},ceilPowerOfTwo:function(e){return Math.pow(2,Math.ceil(Math.log(e)/Math.LN2))},floorPowerOfTwo:function(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))},setQuaternionFromProperEuler:function(e,n,i,l,h){var p=Math.cos,_=Math.sin,s=p(i/2),M=_(i/2),T=p((n+l)/2),C=_((n+l)/2),E=p((n-l)/2),L=_((n-l)/2),I=p((l-n)/2),B=_((l-n)/2);h==="XYX"?e.set(s*C,M*E,M*L,s*T):h==="YZY"?e.set(M*L,s*C,M*E,s*T):h==="ZXZ"?e.set(M*E,M*L,s*C,s*T):h==="XZX"?e.set(s*C,M*B,M*I,s*T):h==="YXY"?e.set(M*I,s*C,M*B,s*T):h==="ZYZ"?e.set(M*B,M*I,s*C,s*T):console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order.")}};function Lt(e,n){this.x=e||0,this.y=n||0}Object.defineProperties(Lt.prototype,{width:{get:function(){return this.x},set:function(e){this.x=e}},height:{get:function(){return this.y},set:function(e){this.y=e}}}),Object.assign(Lt.prototype,{isVector2:!0,set:function(e,n){return this.x=e,this.y=n,this},setScalar:function(e){return this.x=e,this.y=e,this},setX:function(e){return this.x=e,this},setY:function(e){return this.y=e,this},setComponent:function(e,n){switch(e){case 0:this.x=n;break;case 1:this.y=n;break;default:throw new Error("index is out of range: "+e)}return this},getComponent:function(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}},clone:function(){return new this.constructor(this.x,this.y)},copy:function(e){return this.x=e.x,this.y=e.y,this},add:function(e,n){return n!==void 0?(console.warn("THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(e,n)):(this.x+=e.x,this.y+=e.y,this)},addScalar:function(e){return this.x+=e,this.y+=e,this},addVectors:function(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this},addScaledVector:function(e,n){return this.x+=e.x*n,this.y+=e.y*n,this},sub:function(e,n){return n!==void 0?(console.warn("THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(e,n)):(this.x-=e.x,this.y-=e.y,this)},subScalar:function(e){return this.x-=e,this.y-=e,this},subVectors:function(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this},multiply:function(e){return this.x*=e.x,this.y*=e.y,this},multiplyScalar:function(e){return this.x*=e,this.y*=e,this},divide:function(e){return this.x/=e.x,this.y/=e.y,this},divideScalar:function(e){return this.multiplyScalar(1/e)},applyMatrix3:function(e){var n=this.x,i=this.y,l=e.elements;return this.x=l[0]*n+l[3]*i+l[6],this.y=l[1]*n+l[4]*i+l[7],this},min:function(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this},max:function(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this},clamp:function(e,n){return this.x=Math.max(e.x,Math.min(n.x,this.x)),this.y=Math.max(e.y,Math.min(n.y,this.y)),this},clampScalar:function(e,n){return this.x=Math.max(e,Math.min(n,this.x)),this.y=Math.max(e,Math.min(n,this.y)),this},clampLength:function(e,n){var i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(n,i)))},floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this},negate:function(){return this.x=-this.x,this.y=-this.y,this},dot:function(e){return this.x*e.x+this.y*e.y},cross:function(e){return this.x*e.y-this.y*e.x},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},manhattanLength:function(){return Math.abs(this.x)+Math.abs(this.y)},normalize:function(){return this.divideScalar(this.length()||1)},angle:function(){var e=Math.atan2(this.y,this.x);return e<0&&(e+=2*Math.PI),e},distanceTo:function(e){return Math.sqrt(this.distanceToSquared(e))},distanceToSquared:function(e){var n=this.x-e.x,i=this.y-e.y;return n*n+i*i},manhattanDistanceTo:function(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)},setLength:function(e){return this.normalize().multiplyScalar(e)},lerp:function(e,n){return this.x+=(e.x-this.x)*n,this.y+=(e.y-this.y)*n,this},lerpVectors:function(e,n,i){return this.subVectors(n,e).multiplyScalar(i).add(e)},equals:function(e){return e.x===this.x&&e.y===this.y},fromArray:function(e,n){return n===void 0&&(n=0),this.x=e[n],this.y=e[n+1],this},toArray:function(e,n){return e===void 0&&(e=[]),n===void 0&&(n=0),e[n]=this.x,e[n+1]=this.y,e},fromBufferAttribute:function(e,n,i){return i!==void 0&&console.warn("THREE.Vector2: offset has been removed from .fromBufferAttribute()."),this.x=e.getX(n),this.y=e.getY(n),this},rotateAround:function(e,n){var i=Math.cos(n),l=Math.sin(n),h=this.x-e.x,p=this.y-e.y;return this.x=h*i-p*l+e.x,this.y=h*l+p*i+e.y,this}});function dr(){this.elements=[1,0,0,0,1,0,0,0,1],arguments.length>0&&console.error("THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.")}Object.assign(dr.prototype,{isMatrix3:!0,set:function(e,n,i,l,h,p,_,s,M){var T=this.elements;return T[0]=e,T[1]=l,T[2]=_,T[3]=n,T[4]=h,T[5]=s,T[6]=i,T[7]=p,T[8]=M,this},identity:function(){return this.set(1,0,0,0,1,0,0,0,1),this},clone:function(){return new this.constructor().fromArray(this.elements)},copy:function(e){var n=this.elements,i=e.elements;return n[0]=i[0],n[1]=i[1],n[2]=i[2],n[3]=i[3],n[4]=i[4],n[5]=i[5],n[6]=i[6],n[7]=i[7],n[8]=i[8],this},setFromMatrix4:function(e){var n=e.elements;return this.set(n[0],n[4],n[8],n[1],n[5],n[9],n[2],n[6],n[10]),this},multiply:function(e){return this.multiplyMatrices(this,e)},premultiply:function(e){return this.multiplyMatrices(e,this)},multiplyMatrices:function(e,n){var i=e.elements,l=n.elements,h=this.elements,p=i[0],_=i[3],s=i[6],M=i[1],T=i[4],C=i[7],E=i[2],L=i[5],I=i[8],B=l[0],O=l[3],U=l[6],q=l[1],ee=l[4],he=l[7],Ce=l[2],K=l[5],ie=l[8];return h[0]=p*B+_*q+s*Ce,h[3]=p*O+_*ee+s*K,h[6]=p*U+_*he+s*ie,h[1]=M*B+T*q+C*Ce,h[4]=M*O+T*ee+C*K,h[7]=M*U+T*he+C*ie,h[2]=E*B+L*q+I*Ce,h[5]=E*O+L*ee+I*K,h[8]=E*U+L*he+I*ie,this},multiplyScalar:function(e){var n=this.elements;return n[0]*=e,n[3]*=e,n[6]*=e,n[1]*=e,n[4]*=e,n[7]*=e,n[2]*=e,n[5]*=e,n[8]*=e,this},determinant:function(){var e=this.elements,n=e[0],i=e[1],l=e[2],h=e[3],p=e[4],_=e[5],s=e[6],M=e[7],T=e[8];return n*p*T-n*_*M-i*h*T+i*_*s+l*h*M-l*p*s},getInverse:function(e,n){e&&e.isMatrix4&&console.error("THREE.Matrix3: .getInverse() no longer takes a Matrix4 argument.");var i=e.elements,l=this.elements,h=i[0],p=i[1],_=i[2],s=i[3],M=i[4],T=i[5],C=i[6],E=i[7],L=i[8],I=L*M-T*E,B=T*C-L*s,O=E*s-M*C,U=h*I+p*B+_*O;if(U===0){var q="THREE.Matrix3: .getInverse() can't invert matrix, determinant is 0";if(n===!0)throw new Error(q);return console.warn(q),this.identity()}var ee=1/U;return l[0]=I*ee,l[1]=(_*E-L*p)*ee,l[2]=(T*p-_*M)*ee,l[3]=B*ee,l[4]=(L*h-_*C)*ee,l[5]=(_*s-T*h)*ee,l[6]=O*ee,l[7]=(p*C-E*h)*ee,l[8]=(M*h-p*s)*ee,this},transpose:function(){var e,n=this.elements;return e=n[1],n[1]=n[3],n[3]=e,e=n[2],n[2]=n[6],n[6]=e,e=n[5],n[5]=n[7],n[7]=e,this},getNormalMatrix:function(e){return this.setFromMatrix4(e).getInverse(this).transpose()},transposeIntoArray:function(e){var n=this.elements;return e[0]=n[0],e[1]=n[3],e[2]=n[6],e[3]=n[1],e[4]=n[4],e[5]=n[7],e[6]=n[2],e[7]=n[5],e[8]=n[8],this},setUvTransform:function(e,n,i,l,h,p,_){var s=Math.cos(h),M=Math.sin(h);this.set(i*s,i*M,-i*(s*p+M*_)+p+e,-l*M,l*s,-l*(-M*p+s*_)+_+n,0,0,1)},scale:function(e,n){var i=this.elements;return i[0]*=e,i[3]*=e,i[6]*=e,i[1]*=n,i[4]*=n,i[7]*=n,this},rotate:function(e){var n=Math.cos(e),i=Math.sin(e),l=this.elements,h=l[0],p=l[3],_=l[6],s=l[1],M=l[4],T=l[7];return l[0]=n*h+i*s,l[3]=n*p+i*M,l[6]=n*_+i*T,l[1]=-i*h+n*s,l[4]=-i*p+n*M,l[7]=-i*_+n*T,this},translate:function(e,n){var i=this.elements;return i[0]+=e*i[2],i[3]+=e*i[5],i[6]+=e*i[8],i[1]+=n*i[2],i[4]+=n*i[5],i[7]+=n*i[8],this},equals:function(e){for(var n=this.elements,i=e.elements,l=0;l<9;l++)if(n[l]!==i[l])return!1;return!0},fromArray:function(e,n){n===void 0&&(n=0);for(var i=0;i<9;i++)this.elements[i]=e[i+n];return this},toArray:function(e,n){e===void 0&&(e=[]),n===void 0&&(n=0);var i=this.elements;return e[n]=i[0],e[n+1]=i[1],e[n+2]=i[2],e[n+3]=i[3],e[n+4]=i[4],e[n+5]=i[5],e[n+6]=i[6],e[n+7]=i[7],e[n+8]=i[8],e}});var ac,Ys={getDataURL:function(e){var n;if(typeof HTMLCanvasElement=="undefined")return e.src;if(e instanceof HTMLCanvasElement)n=e;else{ac===void 0&&(ac=document.createElementNS("http://www.w3.org/1999/xhtml","canvas")),ac.width=e.width,ac.height=e.height;var i=ac.getContext("2d");e instanceof ImageData?i.putImageData(e,0,0):i.drawImage(e,0,0,e.width,e.height),n=ac}return n.width>2048||n.height>2048?n.toDataURL("image/jpeg",.6):n.toDataURL("image/png")}},f2=0;function mi(e,n,i,l,h,p,_,s,M,T){Object.defineProperty(this,"id",{value:f2++}),this.uuid=Wn.generateUUID(),this.name="",this.image=e!==void 0?e:mi.DEFAULT_IMAGE,this.mipmaps=[],this.mapping=n!==void 0?n:mi.DEFAULT_MAPPING,this.wrapS=i!==void 0?i:wr,this.wrapT=l!==void 0?l:wr,this.magFilter=h!==void 0?h:qi,this.minFilter=p!==void 0?p:ec,this.anisotropy=M!==void 0?M:1,this.format=_!==void 0?_:Aa,this.internalFormat=null,this.type=s!==void 0?s:Wp,this.offset=new Lt(0,0),this.repeat=new Lt(1,1),this.center=new Lt(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new dr,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.encoding=T!==void 0?T:ia,this.version=0,this.onUpdate=null}mi.DEFAULT_IMAGE=void 0,mi.DEFAULT_MAPPING=Wg,mi.prototype=Object.assign(Object.create(To.prototype),{constructor:mi,isTexture:!0,updateMatrix:function(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)},clone:function(){return new this.constructor().copy(this)},copy:function(e){return this.name=e.name,this.image=e.image,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,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.encoding=e.encoding,this},toJSON:function(e){var n=e===void 0||typeof e=="string";if(!n&&e.textures[this.uuid]!==void 0)return e.textures[this.uuid];var i={metadata:{version:4.5,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,mapping:this.mapping,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,type:this.type,encoding:this.encoding,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};if(this.image!==void 0){var l=this.image;if(l.uuid===void 0&&(l.uuid=Wn.generateUUID()),!n&&e.images[l.uuid]===void 0){var h;if(Array.isArray(l)){h=[];for(var p=0,_=l.length;p<_;p++)h.push(Ys.getDataURL(l[p]))}else h=Ys.getDataURL(l);e.images[l.uuid]={uuid:l.uuid,url:h}}i.image=l.uuid}return n||(e.textures[this.uuid]=i),i},dispose:function(){this.dispatchEvent({type:"dispose"})},transformUv:function(e){if(this.mapping!==Wg)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case Zs:e.x=e.x-Math.floor(e.x);break;case wr:e.x=e.x<0?0:1;break;case sh:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case Zs:e.y=e.y-Math.floor(e.y);break;case wr:e.y=e.y<0?0:1;break;case sh:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}}),Object.defineProperty(mi.prototype,"needsUpdate",{set:function(e){e===!0&&this.version++}});function gi(e,n,i,l){this.x=e||0,this.y=n||0,this.z=i||0,this.w=l!==void 0?l:1}Object.defineProperties(gi.prototype,{width:{get:function(){return this.z},set:function(e){this.z=e}},height:{get:function(){return this.w},set:function(e){this.w=e}}}),Object.assign(gi.prototype,{isVector4:!0,set:function(e,n,i,l){return this.x=e,this.y=n,this.z=i,this.w=l,this},setScalar:function(e){return this.x=e,this.y=e,this.z=e,this.w=e,this},setX:function(e){return this.x=e,this},setY:function(e){return this.y=e,this},setZ:function(e){return this.z=e,this},setW:function(e){return this.w=e,this},setComponent:function(e,n){switch(e){case 0:this.x=n;break;case 1:this.y=n;break;case 2:this.z=n;break;case 3:this.w=n;break;default:throw new Error("index is out of range: "+e)}return this},getComponent:function(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}},clone:function(){return new this.constructor(this.x,this.y,this.z,this.w)},copy:function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this},add:function(e,n){return n!==void 0?(console.warn("THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(e,n)):(this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this)},addScalar:function(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this},addVectors:function(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this.w=e.w+n.w,this},addScaledVector:function(e,n){return this.x+=e.x*n,this.y+=e.y*n,this.z+=e.z*n,this.w+=e.w*n,this},sub:function(e,n){return n!==void 0?(console.warn("THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(e,n)):(this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this)},subScalar:function(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this},subVectors:function(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this.w=e.w-n.w,this},multiplyScalar:function(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this},applyMatrix4:function(e){var n=this.x,i=this.y,l=this.z,h=this.w,p=e.elements;return this.x=p[0]*n+p[4]*i+p[8]*l+p[12]*h,this.y=p[1]*n+p[5]*i+p[9]*l+p[13]*h,this.z=p[2]*n+p[6]*i+p[10]*l+p[14]*h,this.w=p[3]*n+p[7]*i+p[11]*l+p[15]*h,this},divideScalar:function(e){return this.multiplyScalar(1/e)},setAxisAngleFromQuaternion:function(e){this.w=2*Math.acos(e.w);var n=Math.sqrt(1-e.w*e.w);return n<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/n,this.y=e.y/n,this.z=e.z/n),this},setAxisAngleFromRotationMatrix:function(e){var n,i,l,h,p=.01,_=.1,s=e.elements,M=s[0],T=s[4],C=s[8],E=s[1],L=s[5],I=s[9],B=s[2],O=s[6],U=s[10];if(Math.abs(T-E)ee&&q>he?q
he?ee
=0?1:-1,ee=1-U*U;if(ee>Number.EPSILON){var he=Math.sqrt(ee),Ce=Math.atan2(he,U*q);O=Math.sin(O*Ce)/he,_=Math.sin(_*Ce)/he}var K=_*q;if(s=s*O+E*K,M=M*O+L*K,T=T*O+I*K,C=C*O+B*K,O===1-_){var ie=1/Math.sqrt(s*s+M*M+T*T+C*C);s*=ie,M*=ie,T*=ie,C*=ie}}e[n]=s,e[n+1]=M,e[n+2]=T,e[n+3]=C}}),Object.defineProperties(Or.prototype,{x:{get:function(){return this._x},set:function(e){this._x=e,this._onChangeCallback()}},y:{get:function(){return this._y},set:function(e){this._y=e,this._onChangeCallback()}},z:{get:function(){return this._z},set:function(e){this._z=e,this._onChangeCallback()}},w:{get:function(){return this._w},set:function(e){this._w=e,this._onChangeCallback()}}}),Object.assign(Or.prototype,{isQuaternion:!0,set:function(e,n,i,l){return this._x=e,this._y=n,this._z=i,this._w=l,this._onChangeCallback(),this},clone:function(){return new this.constructor(this._x,this._y,this._z,this._w)},copy:function(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this},setFromEuler:function(e,n){if(!(e&&e.isEuler))throw new Error("THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.");var i=e._x,l=e._y,h=e._z,p=e.order,_=Math.cos,s=Math.sin,M=_(i/2),T=_(l/2),C=_(h/2),E=s(i/2),L=s(l/2),I=s(h/2);return p==="XYZ"?(this._x=E*T*C+M*L*I,this._y=M*L*C-E*T*I,this._z=M*T*I+E*L*C,this._w=M*T*C-E*L*I):p==="YXZ"?(this._x=E*T*C+M*L*I,this._y=M*L*C-E*T*I,this._z=M*T*I-E*L*C,this._w=M*T*C+E*L*I):p==="ZXY"?(this._x=E*T*C-M*L*I,this._y=M*L*C+E*T*I,this._z=M*T*I+E*L*C,this._w=M*T*C-E*L*I):p==="ZYX"?(this._x=E*T*C-M*L*I,this._y=M*L*C+E*T*I,this._z=M*T*I-E*L*C,this._w=M*T*C+E*L*I):p==="YZX"?(this._x=E*T*C+M*L*I,this._y=M*L*C+E*T*I,this._z=M*T*I-E*L*C,this._w=M*T*C-E*L*I):p==="XZY"&&(this._x=E*T*C-M*L*I,this._y=M*L*C-E*T*I,this._z=M*T*I+E*L*C,this._w=M*T*C+E*L*I),n!==!1&&this._onChangeCallback(),this},setFromAxisAngle:function(e,n){var i=n/2,l=Math.sin(i);return this._x=e.x*l,this._y=e.y*l,this._z=e.z*l,this._w=Math.cos(i),this._onChangeCallback(),this},setFromRotationMatrix:function(e){var n=e.elements,i=n[0],l=n[4],h=n[8],p=n[1],_=n[5],s=n[9],M=n[2],T=n[6],C=n[10],E=i+_+C,L;return E>0?(L=.5/Math.sqrt(E+1),this._w=.25/L,this._x=(T-s)*L,this._y=(h-M)*L,this._z=(p-l)*L):i>_&&i>C?(L=2*Math.sqrt(1+i-_-C),this._w=(T-s)/L,this._x=.25*L,this._y=(l+p)/L,this._z=(h+M)/L):_>C?(L=2*Math.sqrt(1+_-i-C),this._w=(h-M)/L,this._x=(l+p)/L,this._y=.25*L,this._z=(s+T)/L):(L=2*Math.sqrt(1+C-i-_),this._w=(p-l)/L,this._x=(h+M)/L,this._y=(s+T)/L,this._z=.25*L),this._onChangeCallback(),this},setFromUnitVectors:function(e,n){var i=1e-6,l=e.dot(n)+1;return lMath.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=l):(this._x=0,this._y=-e.z,this._z=e.y,this._w=l)):(this._x=e.y*n.z-e.z*n.y,this._y=e.z*n.x-e.x*n.z,this._z=e.x*n.y-e.y*n.x,this._w=l),this.normalize()},angleTo:function(e){return 2*Math.acos(Math.abs(Wn.clamp(this.dot(e),-1,1)))},rotateTowards:function(e,n){var i=this.angleTo(e);if(i===0)return this;var l=Math.min(1,n/i);return this.slerp(e,l),this},inverse:function(){return this.conjugate()},conjugate:function(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this},dot:function(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w},lengthSq:function(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w},length:function(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)},normalize:function(){var e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this},multiply:function(e,n){return n!==void 0?(console.warn("THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead."),this.multiplyQuaternions(e,n)):this.multiplyQuaternions(this,e)},premultiply:function(e){return this.multiplyQuaternions(e,this)},multiplyQuaternions:function(e,n){var i=e._x,l=e._y,h=e._z,p=e._w,_=n._x,s=n._y,M=n._z,T=n._w;return this._x=i*T+p*_+l*M-h*s,this._y=l*T+p*s+h*_-i*M,this._z=h*T+p*M+i*s-l*_,this._w=p*T-i*_-l*s-h*M,this._onChangeCallback(),this},slerp:function(e,n){if(n===0)return this;if(n===1)return this.copy(e);var i=this._x,l=this._y,h=this._z,p=this._w,_=p*e._w+i*e._x+l*e._y+h*e._z;if(_<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,_=-_):this.copy(e),_>=1)return this._w=p,this._x=i,this._y=l,this._z=h,this;var s=1-_*_;if(s<=Number.EPSILON){var M=1-n;return this._w=M*p+n*this._w,this._x=M*i+n*this._x,this._y=M*l+n*this._y,this._z=M*h+n*this._z,this.normalize(),this._onChangeCallback(),this}var T=Math.sqrt(s),C=Math.atan2(T,_),E=Math.sin((1-n)*C)/T,L=Math.sin(n*C)/T;return this._w=p*E+this._w*L,this._x=i*E+this._x*L,this._y=l*E+this._y*L,this._z=h*E+this._z*L,this._onChangeCallback(),this},equals:function(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w},fromArray:function(e,n){return n===void 0&&(n=0),this._x=e[n],this._y=e[n+1],this._z=e[n+2],this._w=e[n+3],this._onChangeCallback(),this},toArray:function(e,n){return e===void 0&&(e=[]),n===void 0&&(n=0),e[n]=this._x,e[n+1]=this._y,e[n+2]=this._z,e[n+3]=this._w,e},_onChange:function(e){return this._onChangeCallback=e,this},_onChangeCallback:function(){}});var e_=new Ee,L0=new Or;function Ee(e,n,i){this.x=e||0,this.y=n||0,this.z=i||0}Object.assign(Ee.prototype,{isVector3:!0,set:function(e,n,i){return this.x=e,this.y=n,this.z=i,this},setScalar:function(e){return this.x=e,this.y=e,this.z=e,this},setX:function(e){return this.x=e,this},setY:function(e){return this.y=e,this},setZ:function(e){return this.z=e,this},setComponent:function(e,n){switch(e){case 0:this.x=n;break;case 1:this.y=n;break;case 2:this.z=n;break;default:throw new Error("index is out of range: "+e)}return this},getComponent:function(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}},clone:function(){return new this.constructor(this.x,this.y,this.z)},copy:function(e){return this.x=e.x,this.y=e.y,this.z=e.z,this},add:function(e,n){return n!==void 0?(console.warn("THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(e,n)):(this.x+=e.x,this.y+=e.y,this.z+=e.z,this)},addScalar:function(e){return this.x+=e,this.y+=e,this.z+=e,this},addVectors:function(e,n){return this.x=e.x+n.x,this.y=e.y+n.y,this.z=e.z+n.z,this},addScaledVector:function(e,n){return this.x+=e.x*n,this.y+=e.y*n,this.z+=e.z*n,this},sub:function(e,n){return n!==void 0?(console.warn("THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(e,n)):(this.x-=e.x,this.y-=e.y,this.z-=e.z,this)},subScalar:function(e){return this.x-=e,this.y-=e,this.z-=e,this},subVectors:function(e,n){return this.x=e.x-n.x,this.y=e.y-n.y,this.z=e.z-n.z,this},multiply:function(e,n){return n!==void 0?(console.warn("THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead."),this.multiplyVectors(e,n)):(this.x*=e.x,this.y*=e.y,this.z*=e.z,this)},multiplyScalar:function(e){return this.x*=e,this.y*=e,this.z*=e,this},multiplyVectors:function(e,n){return this.x=e.x*n.x,this.y=e.y*n.y,this.z=e.z*n.z,this},applyEuler:function(e){return e&&e.isEuler||console.error("THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order."),this.applyQuaternion(L0.setFromEuler(e))},applyAxisAngle:function(e,n){return this.applyQuaternion(L0.setFromAxisAngle(e,n))},applyMatrix3:function(e){var n=this.x,i=this.y,l=this.z,h=e.elements;return this.x=h[0]*n+h[3]*i+h[6]*l,this.y=h[1]*n+h[4]*i+h[7]*l,this.z=h[2]*n+h[5]*i+h[8]*l,this},applyNormalMatrix:function(e){return this.applyMatrix3(e).normalize()},applyMatrix4:function(e){var n=this.x,i=this.y,l=this.z,h=e.elements,p=1/(h[3]*n+h[7]*i+h[11]*l+h[15]);return this.x=(h[0]*n+h[4]*i+h[8]*l+h[12])*p,this.y=(h[1]*n+h[5]*i+h[9]*l+h[13])*p,this.z=(h[2]*n+h[6]*i+h[10]*l+h[14])*p,this},applyQuaternion:function(e){var n=this.x,i=this.y,l=this.z,h=e.x,p=e.y,_=e.z,s=e.w,M=s*n+p*l-_*i,T=s*i+_*n-h*l,C=s*l+h*i-p*n,E=-h*n-p*i-_*l;return this.x=M*s+E*-h+T*-_-C*-p,this.y=T*s+E*-p+C*-h-M*-_,this.z=C*s+E*-_+M*-p-T*-h,this},project:function(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)},unproject:function(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)},transformDirection:function(e){var n=this.x,i=this.y,l=this.z,h=e.elements;return this.x=h[0]*n+h[4]*i+h[8]*l,this.y=h[1]*n+h[5]*i+h[9]*l,this.z=h[2]*n+h[6]*i+h[10]*l,this.normalize()},divide:function(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this},divideScalar:function(e){return this.multiplyScalar(1/e)},min:function(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:function(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:function(e,n){return this.x=Math.max(e.x,Math.min(n.x,this.x)),this.y=Math.max(e.y,Math.min(n.y,this.y)),this.z=Math.max(e.z,Math.min(n.z,this.z)),this},clampScalar:function(e,n){return this.x=Math.max(e,Math.min(n,this.x)),this.y=Math.max(e,Math.min(n,this.y)),this.z=Math.max(e,Math.min(n,this.z)),this},clampLength:function(e,n){var i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(n,i)))},floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this},negate:function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},dot:function(e){return this.x*e.x+this.y*e.y+this.z*e.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},manhattanLength:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length()||1)},setLength:function(e){return this.normalize().multiplyScalar(e)},lerp:function(e,n){return this.x+=(e.x-this.x)*n,this.y+=(e.y-this.y)*n,this.z+=(e.z-this.z)*n,this},lerpVectors:function(e,n,i){return this.subVectors(n,e).multiplyScalar(i).add(e)},cross:function(e,n){return n!==void 0?(console.warn("THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead."),this.crossVectors(e,n)):this.crossVectors(this,e)},crossVectors:function(e,n){var i=e.x,l=e.y,h=e.z,p=n.x,_=n.y,s=n.z;return this.x=l*s-h*_,this.y=h*p-i*s,this.z=i*_-l*p,this},projectOnVector:function(e){var n=e.lengthSq();if(n===0)return this.set(0,0,0);var i=e.dot(this)/n;return this.copy(e).multiplyScalar(i)},projectOnPlane:function(e){return e_.copy(this).projectOnVector(e),this.sub(e_)},reflect:function(e){return this.sub(e_.copy(e).multiplyScalar(2*this.dot(e)))},angleTo:function(e){var n=Math.sqrt(this.lengthSq()*e.lengthSq());if(n===0)return Math.PI/2;var i=this.dot(e)/n;return Math.acos(Wn.clamp(i,-1,1))},distanceTo:function(e){return Math.sqrt(this.distanceToSquared(e))},distanceToSquared:function(e){var n=this.x-e.x,i=this.y-e.y,l=this.z-e.z;return n*n+i*i+l*l},manhattanDistanceTo:function(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)},setFromSpherical:function(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)},setFromSphericalCoords:function(e,n,i){var l=Math.sin(n)*e;return this.x=l*Math.sin(i),this.y=Math.cos(n)*e,this.z=l*Math.cos(i),this},setFromCylindrical:function(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)},setFromCylindricalCoords:function(e,n,i){return this.x=e*Math.sin(n),this.y=i,this.z=e*Math.cos(n),this},setFromMatrixPosition:function(e){var n=e.elements;return this.x=n[12],this.y=n[13],this.z=n[14],this},setFromMatrixScale:function(e){var n=this.setFromMatrixColumn(e,0).length(),i=this.setFromMatrixColumn(e,1).length(),l=this.setFromMatrixColumn(e,2).length();return this.x=n,this.y=i,this.z=l,this},setFromMatrixColumn:function(e,n){return this.fromArray(e.elements,n*4)},setFromMatrix3Column:function(e,n){return this.fromArray(e.elements,n*3)},equals:function(e){return e.x===this.x&&e.y===this.y&&e.z===this.z},fromArray:function(e,n){return n===void 0&&(n=0),this.x=e[n],this.y=e[n+1],this.z=e[n+2],this},toArray:function(e,n){return e===void 0&&(e=[]),n===void 0&&(n=0),e[n]=this.x,e[n+1]=this.y,e[n+2]=this.z,e},fromBufferAttribute:function(e,n,i){return i!==void 0&&console.warn("THREE.Vector3: offset has been removed from .fromBufferAttribute()."),this.x=e.getX(n),this.y=e.getY(n),this.z=e.getZ(n),this}});var oc=new Ee,Ca=new jn,m2=new Ee(0,0,0),g2=new Ee(1,1,1),es=new Ee,Yp=new Ee,ra=new Ee;function jn(){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],arguments.length>0&&console.error("THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.")}Object.assign(jn.prototype,{isMatrix4:!0,set:function(e,n,i,l,h,p,_,s,M,T,C,E,L,I,B,O){var U=this.elements;return U[0]=e,U[4]=n,U[8]=i,U[12]=l,U[1]=h,U[5]=p,U[9]=_,U[13]=s,U[2]=M,U[6]=T,U[10]=C,U[14]=E,U[3]=L,U[7]=I,U[11]=B,U[15]=O,this},identity:function(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this},clone:function(){return new jn().fromArray(this.elements)},copy:function(e){var n=this.elements,i=e.elements;return n[0]=i[0],n[1]=i[1],n[2]=i[2],n[3]=i[3],n[4]=i[4],n[5]=i[5],n[6]=i[6],n[7]=i[7],n[8]=i[8],n[9]=i[9],n[10]=i[10],n[11]=i[11],n[12]=i[12],n[13]=i[13],n[14]=i[14],n[15]=i[15],this},copyPosition:function(e){var n=this.elements,i=e.elements;return n[12]=i[12],n[13]=i[13],n[14]=i[14],this},extractBasis:function(e,n,i){return e.setFromMatrixColumn(this,0),n.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this},makeBasis:function(e,n,i){return this.set(e.x,n.x,i.x,0,e.y,n.y,i.y,0,e.z,n.z,i.z,0,0,0,0,1),this},extractRotation:function(e){var n=this.elements,i=e.elements,l=1/oc.setFromMatrixColumn(e,0).length(),h=1/oc.setFromMatrixColumn(e,1).length(),p=1/oc.setFromMatrixColumn(e,2).length();return n[0]=i[0]*l,n[1]=i[1]*l,n[2]=i[2]*l,n[3]=0,n[4]=i[4]*h,n[5]=i[5]*h,n[6]=i[6]*h,n[7]=0,n[8]=i[8]*p,n[9]=i[9]*p,n[10]=i[10]*p,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,this},makeRotationFromEuler:function(e){e&&e.isEuler||console.error("THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.");var n=this.elements,i=e.x,l=e.y,h=e.z,p=Math.cos(i),_=Math.sin(i),s=Math.cos(l),M=Math.sin(l),T=Math.cos(h),C=Math.sin(h);if(e.order==="XYZ"){var E=p*T,L=p*C,I=_*T,B=_*C;n[0]=s*T,n[4]=-s*C,n[8]=M,n[1]=L+I*M,n[5]=E-B*M,n[9]=-_*s,n[2]=B-E*M,n[6]=I+L*M,n[10]=p*s}else if(e.order==="YXZ"){var O=s*T,U=s*C,q=M*T,ee=M*C;n[0]=O+ee*_,n[4]=q*_-U,n[8]=p*M,n[1]=p*C,n[5]=p*T,n[9]=-_,n[2]=U*_-q,n[6]=ee+O*_,n[10]=p*s}else if(e.order==="ZXY"){var O=s*T,U=s*C,q=M*T,ee=M*C;n[0]=O-ee*_,n[4]=-p*C,n[8]=q+U*_,n[1]=U+q*_,n[5]=p*T,n[9]=ee-O*_,n[2]=-p*M,n[6]=_,n[10]=p*s}else if(e.order==="ZYX"){var E=p*T,L=p*C,I=_*T,B=_*C;n[0]=s*T,n[4]=I*M-L,n[8]=E*M+B,n[1]=s*C,n[5]=B*M+E,n[9]=L*M-I,n[2]=-M,n[6]=_*s,n[10]=p*s}else if(e.order==="YZX"){var he=p*s,Ce=p*M,K=_*s,ie=_*M;n[0]=s*T,n[4]=ie-he*C,n[8]=K*C+Ce,n[1]=C,n[5]=p*T,n[9]=-_*T,n[2]=-M*T,n[6]=Ce*C+K,n[10]=he-ie*C}else if(e.order==="XZY"){var he=p*s,Ce=p*M,K=_*s,ie=_*M;n[0]=s*T,n[4]=-C,n[8]=M*T,n[1]=he*C+ie,n[5]=p*T,n[9]=Ce*C-K,n[2]=K*C-Ce,n[6]=_*T,n[10]=ie*C+he}return n[3]=0,n[7]=0,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,this},makeRotationFromQuaternion:function(e){return this.compose(m2,e,g2)},lookAt:function(e,n,i){var l=this.elements;return ra.subVectors(e,n),ra.lengthSq()===0&&(ra.z=1),ra.normalize(),es.crossVectors(i,ra),es.lengthSq()===0&&(Math.abs(i.z)===1?ra.x+=1e-4:ra.z+=1e-4,ra.normalize(),es.crossVectors(i,ra)),es.normalize(),Yp.crossVectors(ra,es),l[0]=es.x,l[4]=Yp.x,l[8]=ra.x,l[1]=es.y,l[5]=Yp.y,l[9]=ra.y,l[2]=es.z,l[6]=Yp.z,l[10]=ra.z,this},multiply:function(e,n){return n!==void 0?(console.warn("THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead."),this.multiplyMatrices(e,n)):this.multiplyMatrices(this,e)},premultiply:function(e){return this.multiplyMatrices(e,this)},multiplyMatrices:function(e,n){var i=e.elements,l=n.elements,h=this.elements,p=i[0],_=i[4],s=i[8],M=i[12],T=i[1],C=i[5],E=i[9],L=i[13],I=i[2],B=i[6],O=i[10],U=i[14],q=i[3],ee=i[7],he=i[11],Ce=i[15],K=l[0],ie=l[4],ue=l[8],ae=l[12],le=l[1],De=l[5],ye=l[9],se=l[13],Ue=l[2],Oe=l[6],We=l[10],st=l[14],St=l[3],gt=l[7],At=l[11],Dt=l[15];return h[0]=p*K+_*le+s*Ue+M*St,h[4]=p*ie+_*De+s*Oe+M*gt,h[8]=p*ue+_*ye+s*We+M*At,h[12]=p*ae+_*se+s*st+M*Dt,h[1]=T*K+C*le+E*Ue+L*St,h[5]=T*ie+C*De+E*Oe+L*gt,h[9]=T*ue+C*ye+E*We+L*At,h[13]=T*ae+C*se+E*st+L*Dt,h[2]=I*K+B*le+O*Ue+U*St,h[6]=I*ie+B*De+O*Oe+U*gt,h[10]=I*ue+B*ye+O*We+U*At,h[14]=I*ae+B*se+O*st+U*Dt,h[3]=q*K+ee*le+he*Ue+Ce*St,h[7]=q*ie+ee*De+he*Oe+Ce*gt,h[11]=q*ue+ee*ye+he*We+Ce*At,h[15]=q*ae+ee*se+he*st+Ce*Dt,this},multiplyScalar:function(e){var n=this.elements;return n[0]*=e,n[4]*=e,n[8]*=e,n[12]*=e,n[1]*=e,n[5]*=e,n[9]*=e,n[13]*=e,n[2]*=e,n[6]*=e,n[10]*=e,n[14]*=e,n[3]*=e,n[7]*=e,n[11]*=e,n[15]*=e,this},determinant:function(){var e=this.elements,n=e[0],i=e[4],l=e[8],h=e[12],p=e[1],_=e[5],s=e[9],M=e[13],T=e[2],C=e[6],E=e[10],L=e[14],I=e[3],B=e[7],O=e[11],U=e[15];return I*(+h*s*C-l*M*C-h*_*E+i*M*E+l*_*L-i*s*L)+B*(+n*s*L-n*M*E+h*p*E-l*p*L+l*M*T-h*s*T)+O*(+n*M*C-n*_*L-h*p*C+i*p*L+h*_*T-i*M*T)+U*(-l*_*T-n*s*C+n*_*E+l*p*C-i*p*E+i*s*T)},transpose:function(){var e=this.elements,n;return n=e[1],e[1]=e[4],e[4]=n,n=e[2],e[2]=e[8],e[8]=n,n=e[6],e[6]=e[9],e[9]=n,n=e[3],e[3]=e[12],e[12]=n,n=e[7],e[7]=e[13],e[13]=n,n=e[11],e[11]=e[14],e[14]=n,this},setPosition:function(e,n,i){var l=this.elements;return e.isVector3?(l[12]=e.x,l[13]=e.y,l[14]=e.z):(l[12]=e,l[13]=n,l[14]=i),this},getInverse:function(e,n){var i=this.elements,l=e.elements,h=l[0],p=l[1],_=l[2],s=l[3],M=l[4],T=l[5],C=l[6],E=l[7],L=l[8],I=l[9],B=l[10],O=l[11],U=l[12],q=l[13],ee=l[14],he=l[15],Ce=I*ee*E-q*B*E+q*C*O-T*ee*O-I*C*he+T*B*he,K=U*B*E-L*ee*E-U*C*O+M*ee*O+L*C*he-M*B*he,ie=L*q*E-U*I*E+U*T*O-M*q*O-L*T*he+M*I*he,ue=U*I*C-L*q*C-U*T*B+M*q*B+L*T*ee-M*I*ee,ae=h*Ce+p*K+_*ie+s*ue;if(ae===0){var le="THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";if(n===!0)throw new Error(le);return console.warn(le),this.identity()}var De=1/ae;return i[0]=Ce*De,i[1]=(q*B*s-I*ee*s-q*_*O+p*ee*O+I*_*he-p*B*he)*De,i[2]=(T*ee*s-q*C*s+q*_*E-p*ee*E-T*_*he+p*C*he)*De,i[3]=(I*C*s-T*B*s-I*_*E+p*B*E+T*_*O-p*C*O)*De,i[4]=K*De,i[5]=(L*ee*s-U*B*s+U*_*O-h*ee*O-L*_*he+h*B*he)*De,i[6]=(U*C*s-M*ee*s-U*_*E+h*ee*E+M*_*he-h*C*he)*De,i[7]=(M*B*s-L*C*s+L*_*E-h*B*E-M*_*O+h*C*O)*De,i[8]=ie*De,i[9]=(U*I*s-L*q*s-U*p*O+h*q*O+L*p*he-h*I*he)*De,i[10]=(M*q*s-U*T*s+U*p*E-h*q*E-M*p*he+h*T*he)*De,i[11]=(L*T*s-M*I*s-L*p*E+h*I*E+M*p*O-h*T*O)*De,i[12]=ue*De,i[13]=(L*q*_-U*I*_+U*p*B-h*q*B-L*p*ee+h*I*ee)*De,i[14]=(U*T*_-M*q*_-U*p*C+h*q*C+M*p*ee-h*T*ee)*De,i[15]=(M*I*_-L*T*_+L*p*C-h*I*C-M*p*B+h*T*B)*De,this},scale:function(e){var n=this.elements,i=e.x,l=e.y,h=e.z;return n[0]*=i,n[4]*=l,n[8]*=h,n[1]*=i,n[5]*=l,n[9]*=h,n[2]*=i,n[6]*=l,n[10]*=h,n[3]*=i,n[7]*=l,n[11]*=h,this},getMaxScaleOnAxis:function(){var e=this.elements,n=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],i=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],l=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(n,i,l))},makeTranslation:function(e,n,i){return this.set(1,0,0,e,0,1,0,n,0,0,1,i,0,0,0,1),this},makeRotationX:function(e){var n=Math.cos(e),i=Math.sin(e);return this.set(1,0,0,0,0,n,-i,0,0,i,n,0,0,0,0,1),this},makeRotationY:function(e){var n=Math.cos(e),i=Math.sin(e);return this.set(n,0,i,0,0,1,0,0,-i,0,n,0,0,0,0,1),this},makeRotationZ:function(e){var n=Math.cos(e),i=Math.sin(e);return this.set(n,-i,0,0,i,n,0,0,0,0,1,0,0,0,0,1),this},makeRotationAxis:function(e,n){var i=Math.cos(n),l=Math.sin(n),h=1-i,p=e.x,_=e.y,s=e.z,M=h*p,T=h*_;return this.set(M*p+i,M*_-l*s,M*s+l*_,0,M*_+l*s,T*_+i,T*s-l*p,0,M*s-l*_,T*s+l*p,h*s*s+i,0,0,0,0,1),this},makeScale:function(e,n,i){return this.set(e,0,0,0,0,n,0,0,0,0,i,0,0,0,0,1),this},makeShear:function(e,n,i){return this.set(1,n,i,0,e,1,i,0,e,n,1,0,0,0,0,1),this},compose:function(e,n,i){var l=this.elements,h=n._x,p=n._y,_=n._z,s=n._w,M=h+h,T=p+p,C=_+_,E=h*M,L=h*T,I=h*C,B=p*T,O=p*C,U=_*C,q=s*M,ee=s*T,he=s*C,Ce=i.x,K=i.y,ie=i.z;return l[0]=(1-(B+U))*Ce,l[1]=(L+he)*Ce,l[2]=(I-ee)*Ce,l[3]=0,l[4]=(L-he)*K,l[5]=(1-(E+U))*K,l[6]=(O+q)*K,l[7]=0,l[8]=(I+ee)*ie,l[9]=(O-q)*ie,l[10]=(1-(E+B))*ie,l[11]=0,l[12]=e.x,l[13]=e.y,l[14]=e.z,l[15]=1,this},decompose:function(e,n,i){var l=this.elements,h=oc.set(l[0],l[1],l[2]).length(),p=oc.set(l[4],l[5],l[6]).length(),_=oc.set(l[8],l[9],l[10]).length(),s=this.determinant();s<0&&(h=-h),e.x=l[12],e.y=l[13],e.z=l[14],Ca.copy(this);var M=1/h,T=1/p,C=1/_;return Ca.elements[0]*=M,Ca.elements[1]*=M,Ca.elements[2]*=M,Ca.elements[4]*=T,Ca.elements[5]*=T,Ca.elements[6]*=T,Ca.elements[8]*=C,Ca.elements[9]*=C,Ca.elements[10]*=C,n.setFromRotationMatrix(Ca),i.x=h,i.y=p,i.z=_,this},makePerspective:function(e,n,i,l,h,p){p===void 0&&console.warn("THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.");var _=this.elements,s=2*h/(n-e),M=2*h/(i-l),T=(n+e)/(n-e),C=(i+l)/(i-l),E=-(p+h)/(p-h),L=-2*p*h/(p-h);return _[0]=s,_[4]=0,_[8]=T,_[12]=0,_[1]=0,_[5]=M,_[9]=C,_[13]=0,_[2]=0,_[6]=0,_[10]=E,_[14]=L,_[3]=0,_[7]=0,_[11]=-1,_[15]=0,this},makeOrthographic:function(e,n,i,l,h,p){var _=this.elements,s=1/(n-e),M=1/(i-l),T=1/(p-h),C=(n+e)*s,E=(i+l)*M,L=(p+h)*T;return _[0]=2*s,_[4]=0,_[8]=0,_[12]=-C,_[1]=0,_[5]=2*M,_[9]=0,_[13]=-E,_[2]=0,_[6]=0,_[10]=-2*T,_[14]=-L,_[3]=0,_[7]=0,_[11]=0,_[15]=1,this},equals:function(e){for(var n=this.elements,i=e.elements,l=0;l<16;l++)if(n[l]!==i[l])return!1;return!0},fromArray:function(e,n){n===void 0&&(n=0);for(var i=0;i<16;i++)this.elements[i]=e[i+n];return this},toArray:function(e,n){e===void 0&&(e=[]),n===void 0&&(n=0);var i=this.elements;return e[n]=i[0],e[n+1]=i[1],e[n+2]=i[2],e[n+3]=i[3],e[n+4]=i[4],e[n+5]=i[5],e[n+6]=i[6],e[n+7]=i[7],e[n+8]=i[8],e[n+9]=i[9],e[n+10]=i[10],e[n+11]=i[11],e[n+12]=i[12],e[n+13]=i[13],e[n+14]=i[14],e[n+15]=i[15],e}});var D0=new jn,I0=new Or;function sc(e,n,i,l){this._x=e||0,this._y=n||0,this._z=i||0,this._order=l||sc.DefaultOrder}sc.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"],sc.DefaultOrder="XYZ",Object.defineProperties(sc.prototype,{x:{get:function(){return this._x},set:function(e){this._x=e,this._onChangeCallback()}},y:{get:function(){return this._y},set:function(e){this._y=e,this._onChangeCallback()}},z:{get:function(){return this._z},set:function(e){this._z=e,this._onChangeCallback()}},order:{get:function(){return this._order},set:function(e){this._order=e,this._onChangeCallback()}}}),Object.assign(sc.prototype,{isEuler:!0,set:function(e,n,i,l){return this._x=e,this._y=n,this._z=i,this._order=l||this._order,this._onChangeCallback(),this},clone:function(){return new this.constructor(this._x,this._y,this._z,this._order)},copy:function(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this},setFromRotationMatrix:function(e,n,i){var l=Wn.clamp,h=e.elements,p=h[0],_=h[4],s=h[8],M=h[1],T=h[5],C=h[9],E=h[2],L=h[6],I=h[10];return n=n||this._order,n==="XYZ"?(this._y=Math.asin(l(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(-C,I),this._z=Math.atan2(-_,p)):(this._x=Math.atan2(L,T),this._z=0)):n==="YXZ"?(this._x=Math.asin(-l(C,-1,1)),Math.abs(C)<.9999999?(this._y=Math.atan2(s,I),this._z=Math.atan2(M,T)):(this._y=Math.atan2(-E,p),this._z=0)):n==="ZXY"?(this._x=Math.asin(l(L,-1,1)),Math.abs(L)<.9999999?(this._y=Math.atan2(-E,I),this._z=Math.atan2(-_,T)):(this._y=0,this._z=Math.atan2(M,p))):n==="ZYX"?(this._y=Math.asin(-l(E,-1,1)),Math.abs(E)<.9999999?(this._x=Math.atan2(L,I),this._z=Math.atan2(M,p)):(this._x=0,this._z=Math.atan2(-_,T))):n==="YZX"?(this._z=Math.asin(l(M,-1,1)),Math.abs(M)<.9999999?(this._x=Math.atan2(-C,T),this._y=Math.atan2(-E,p)):(this._x=0,this._y=Math.atan2(s,I))):n==="XZY"?(this._z=Math.asin(-l(_,-1,1)),Math.abs(_)<.9999999?(this._x=Math.atan2(L,T),this._y=Math.atan2(s,p)):(this._x=Math.atan2(-C,I),this._y=0)):console.warn("THREE.Euler: .setFromRotationMatrix() given unsupported order: "+n),this._order=n,i!==!1&&this._onChangeCallback(),this},setFromQuaternion:function(e,n,i){return D0.makeRotationFromQuaternion(e),this.setFromRotationMatrix(D0,n,i)},setFromVector3:function(e,n){return this.set(e.x,e.y,e.z,n||this._order)},reorder:function(e){return I0.setFromEuler(this),this.setFromQuaternion(I0,e)},equals:function(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order},fromArray:function(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:function(e,n){return e===void 0&&(e=[]),n===void 0&&(n=0),e[n]=this._x,e[n+1]=this._y,e[n+2]=this._z,e[n+3]=this._order,e},toVector3:function(e){return e?e.set(this._x,this._y,this._z):new Ee(this._x,this._y,this._z)},_onChange:function(e){return this._onChangeCallback=e,this},_onChangeCallback:function(){}});function R0(){this.mask=1}Object.assign(R0.prototype,{set:function(e){this.mask=1<1){for(var n=0;n1){for(var n=0;n0){l.children=[];for(var s=0;s0&&(i.geometries=E),L.length>0&&(i.materials=L),I.length>0&&(i.textures=I),B.length>0&&(i.images=B),_.length>0&&(i.shapes=_)}return i.object=l,i;function O(U){var q=[];for(var ee in U){var he=U[ee];delete he.metadata,q.push(he)}return q}},clone:function(e){return new this.constructor().copy(this,e)},copy:function(e,n){if(n===void 0&&(n=!0),this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),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.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.userData=JSON.parse(JSON.stringify(e.userData)),n===!0)for(var i=0;ih&&(h=T),C>p&&(p=C),E>_&&(_=E)}return this.min.set(n,i,l),this.max.set(h,p,_),this},setFromBufferAttribute:function(e){for(var n=1/0,i=1/0,l=1/0,h=-1/0,p=-1/0,_=-1/0,s=0,M=e.count;sh&&(h=T),C>p&&(p=C),E>_&&(_=E)}return this.min.set(n,i,l),this.max.set(h,p,_),this},setFromPoints:function(e){this.makeEmpty();for(var n=0,i=e.length;nthis.max.x||e.ythis.max.y||e.zthis.max.z)},containsBox:function(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:function(e,n){return n===void 0&&(console.warn("THREE.Box3: .getParameter() target is now required"),n=new Ee),n.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:function(e){return!(e.max.xthis.max.x||e.max.ythis.max.y||e.max.zthis.max.z)},intersectsSphere:function(e){return this.clampPoint(e.center,mh),mh.distanceToSquared(e.center)<=e.radius*e.radius},intersectsPlane:function(e){var n,i;return e.normal.x>0?(n=e.normal.x*this.min.x,i=e.normal.x*this.max.x):(n=e.normal.x*this.max.x,i=e.normal.x*this.min.x),e.normal.y>0?(n+=e.normal.y*this.min.y,i+=e.normal.y*this.max.y):(n+=e.normal.y*this.max.y,i+=e.normal.y*this.min.y),e.normal.z>0?(n+=e.normal.z*this.min.z,i+=e.normal.z*this.max.z):(n+=e.normal.z*this.max.z,i+=e.normal.z*this.min.z),n<=-e.constant&&i>=-e.constant},intersectsTriangle:function(e){if(this.isEmpty())return!1;this.getCenter(gh),Kp.subVectors(this.max,gh),cc.subVectors(e.a,gh),uc.subVectors(e.b,gh),hc.subVectors(e.c,gh),ts.subVectors(uc,cc),ns.subVectors(hc,uc),$s.subVectors(cc,hc);var n=[0,-ts.z,ts.y,0,-ns.z,ns.y,0,-$s.z,$s.y,ts.z,0,-ts.x,ns.z,0,-ns.x,$s.z,0,-$s.x,-ts.y,ts.x,0,-ns.y,ns.x,0,-$s.y,$s.x,0];return!t_(n,cc,uc,hc,Kp)||(n=[1,0,0,0,1,0,0,0,1],!t_(n,cc,uc,hc,Kp))?!1:(Qp.crossVectors(ts,ns),n=[Qp.x,Qp.y,Qp.z],t_(n,cc,uc,hc,Kp))},clampPoint:function(e,n){return n===void 0&&(console.warn("THREE.Box3: .clampPoint() target is now required"),n=new Ee),n.copy(e).clamp(this.min,this.max)},distanceToPoint:function(e){var n=mh.copy(e).clamp(this.min,this.max);return n.sub(e).length()},getBoundingSphere:function(e){return e===void 0&&console.error("THREE.Box3: .getBoundingSphere() target is now required"),this.getCenter(e.center),e.radius=this.getSize(mh).length()*.5,e},intersect:function(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this},union:function(e){return this.min.min(e.min),this.max.max(e.max),this},applyMatrix4:function(e){return this.isEmpty()?this:(Ao[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Ao[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Ao[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Ao[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Ao[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Ao[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Ao[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Ao[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Ao),this)},translate:function(e){return this.min.add(e),this.max.add(e),this},equals:function(e){return e.min.equals(this.min)&&e.max.equals(this.max)}});function t_(e,n,i,l,h){var p,_;for(p=0,_=e.length-3;p<=_;p+=3){Js.fromArray(e,p);var s=h.x*Math.abs(Js.x)+h.y*Math.abs(Js.y)+h.z*Math.abs(Js.z),M=n.dot(Js),T=i.dot(Js),C=l.dot(Js);if(Math.max(-Math.max(M,T,C),Math.min(M,T,C))>s)return!1}return!0}var w2=new Pa;function Co(e,n){this.center=e!==void 0?e:new Ee,this.radius=n!==void 0?n:0}Object.assign(Co.prototype,{set:function(e,n){return this.center.copy(e),this.radius=n,this},setFromPoints:function(e,n){var i=this.center;n!==void 0?i.copy(n):w2.setFromPoints(e).getCenter(i);for(var l=0,h=0,p=e.length;hthis.radius*this.radius&&(n.sub(this.center).normalize(),n.multiplyScalar(this.radius).add(this.center)),n},getBoundingBox:function(e){return e===void 0&&(console.warn("THREE.Sphere: .getBoundingBox() target is now required"),e=new Pa),e.set(this.center,this.center),e.expandByScalar(this.radius),e},applyMatrix4:function(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this},translate:function(e){return this.center.add(e),this},equals:function(e){return e.center.equals(this.center)&&e.radius===this.radius}});var Po=new Ee,n_=new Ee,ef=new Ee,is=new Ee,i_=new Ee,tf=new Ee,r_=new Ee;function dc(e,n){this.origin=e!==void 0?e:new Ee,this.direction=n!==void 0?n:new Ee(0,0,-1)}Object.assign(dc.prototype,{set:function(e,n){return this.origin.copy(e),this.direction.copy(n),this},clone:function(){return new this.constructor().copy(this)},copy:function(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this},at:function(e,n){return n===void 0&&(console.warn("THREE.Ray: .at() target is now required"),n=new Ee),n.copy(this.direction).multiplyScalar(e).add(this.origin)},lookAt:function(e){return this.direction.copy(e).sub(this.origin).normalize(),this},recast:function(e){return this.origin.copy(this.at(e,Po)),this},closestPointToPoint:function(e,n){n===void 0&&(console.warn("THREE.Ray: .closestPointToPoint() target is now required"),n=new Ee),n.subVectors(e,this.origin);var i=n.dot(this.direction);return i<0?n.copy(this.origin):n.copy(this.direction).multiplyScalar(i).add(this.origin)},distanceToPoint:function(e){return Math.sqrt(this.distanceSqToPoint(e))},distanceSqToPoint:function(e){var n=Po.subVectors(e,this.origin).dot(this.direction);return n<0?this.origin.distanceToSquared(e):(Po.copy(this.direction).multiplyScalar(n).add(this.origin),Po.distanceToSquared(e))},distanceSqToSegment:function(e,n,i,l){n_.copy(e).add(n).multiplyScalar(.5),ef.copy(n).sub(e).normalize(),is.copy(this.origin).sub(n_);var h=e.distanceTo(n)*.5,p=-this.direction.dot(ef),_=is.dot(this.direction),s=-is.dot(ef),M=is.lengthSq(),T=Math.abs(1-p*p),C,E,L,I;if(T>0)if(C=p*s-_,E=p*_-s,I=h*T,C>=0)if(E>=-I)if(E<=I){var B=1/T;C*=B,E*=B,L=C*(C+p*E+2*_)+E*(p*C+E+2*s)+M}else E=h,C=Math.max(0,-(p*E+_)),L=-C*C+E*(E+2*s)+M;else E=-h,C=Math.max(0,-(p*E+_)),L=-C*C+E*(E+2*s)+M;else E<=-I?(C=Math.max(0,-(-p*h+_)),E=C>0?-h:Math.min(Math.max(-h,-s),h),L=-C*C+E*(E+2*s)+M):E<=I?(C=0,E=Math.min(Math.max(-h,-s),h),L=E*(E+2*s)+M):(C=Math.max(0,-(p*h+_)),E=C>0?h:Math.min(Math.max(-h,-s),h),L=-C*C+E*(E+2*s)+M);else E=p>0?-h:h,C=Math.max(0,-(p*E+_)),L=-C*C+E*(E+2*s)+M;return i&&i.copy(this.direction).multiplyScalar(C).add(this.origin),l&&l.copy(ef).multiplyScalar(E).add(n_),L},intersectSphere:function(e,n){Po.subVectors(e.center,this.origin);var i=Po.dot(this.direction),l=Po.dot(Po)-i*i,h=e.radius*e.radius;if(l>h)return null;var p=Math.sqrt(h-l),_=i-p,s=i+p;return _<0&&s<0?null:_<0?this.at(s,n):this.at(_,n)},intersectsSphere:function(e){return this.distanceSqToPoint(e.center)<=e.radius*e.radius},distanceToPlane:function(e){var n=e.normal.dot(this.direction);if(n===0)return e.distanceToPoint(this.origin)===0?0:null;var i=-(this.origin.dot(e.normal)+e.constant)/n;return i>=0?i:null},intersectPlane:function(e,n){var i=this.distanceToPlane(e);return i===null?null:this.at(i,n)},intersectsPlane:function(e){var n=e.distanceToPoint(this.origin);if(n===0)return!0;var i=e.normal.dot(this.direction);return i*n<0},intersectBox:function(e,n){var i,l,h,p,_,s,M=1/this.direction.x,T=1/this.direction.y,C=1/this.direction.z,E=this.origin;return M>=0?(i=(e.min.x-E.x)*M,l=(e.max.x-E.x)*M):(i=(e.max.x-E.x)*M,l=(e.min.x-E.x)*M),T>=0?(h=(e.min.y-E.y)*T,p=(e.max.y-E.y)*T):(h=(e.max.y-E.y)*T,p=(e.min.y-E.y)*T),i>p||h>l||((h>i||i!==i)&&(i=h),(p=0?(_=(e.min.z-E.z)*C,s=(e.max.z-E.z)*C):(_=(e.max.z-E.z)*C,s=(e.min.z-E.z)*C),i>s||_>l)||((_>i||i!==i)&&(i=_),(s=0?i:l,n)},intersectsBox:function(e){return this.intersectBox(e,Po)!==null},intersectTriangle:function(e,n,i,l,h){i_.subVectors(n,e),tf.subVectors(i,e),r_.crossVectors(i_,tf);var p=this.direction.dot(r_),_;if(p>0){if(l)return null;_=1}else if(p<0)_=-1,p=-p;else return null;is.subVectors(this.origin,e);var s=_*this.direction.dot(tf.crossVectors(is,tf));if(s<0)return null;var M=_*this.direction.dot(i_.cross(is));if(M<0||s+M>p)return null;var T=-_*is.dot(r_);return T<0?null:this.at(T/p,h)},applyMatrix4:function(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this},equals:function(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}});var a_=new Ee,M2=new Ee,T2=new dr;function ja(e,n){this.normal=e!==void 0?e:new Ee(1,0,0),this.constant=n!==void 0?n:0}Object.assign(ja.prototype,{isPlane:!0,set:function(e,n){return this.normal.copy(e),this.constant=n,this},setComponents:function(e,n,i,l){return this.normal.set(e,n,i),this.constant=l,this},setFromNormalAndCoplanarPoint:function(e,n){return this.normal.copy(e),this.constant=-n.dot(this.normal),this},setFromCoplanarPoints:function(e,n,i){var l=a_.subVectors(i,n).cross(M2.subVectors(e,n)).normalize();return this.setFromNormalAndCoplanarPoint(l,e),this},clone:function(){return new this.constructor().copy(this)},copy:function(e){return this.normal.copy(e.normal),this.constant=e.constant,this},normalize:function(){var e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this},negate:function(){return this.constant*=-1,this.normal.negate(),this},distanceToPoint:function(e){return this.normal.dot(e)+this.constant},distanceToSphere:function(e){return this.distanceToPoint(e.center)-e.radius},projectPoint:function(e,n){return n===void 0&&(console.warn("THREE.Plane: .projectPoint() target is now required"),n=new Ee),n.copy(this.normal).multiplyScalar(-this.distanceToPoint(e)).add(e)},intersectLine:function(e,n){n===void 0&&(console.warn("THREE.Plane: .intersectLine() target is now required"),n=new Ee);var i=e.delta(a_),l=this.normal.dot(i);if(l===0)return this.distanceToPoint(e.start)===0?n.copy(e.start):void 0;var h=-(e.start.dot(this.normal)+this.constant)/l;if(!(h<0||h>1))return n.copy(i).multiplyScalar(h).add(e.start)},intersectsLine:function(e){var n=this.distanceToPoint(e.start),i=this.distanceToPoint(e.end);return n<0&&i>0||i<0&&n>0},intersectsBox:function(e){return e.intersectsPlane(this)},intersectsSphere:function(e){return e.intersectsPlane(this)},coplanarPoint:function(e){return e===void 0&&(console.warn("THREE.Plane: .coplanarPoint() target is now required"),e=new Ee),e.copy(this.normal).multiplyScalar(-this.constant)},applyMatrix4:function(e,n){var i=n||T2.getNormalMatrix(e),l=this.coplanarPoint(a_).applyMatrix4(e),h=this.normal.applyMatrix3(i).normalize();return this.constant=-l.dot(h),this},translate:function(e){return this.constant-=e.dot(this.normal),this},equals:function(e){return e.normal.equals(this.normal)&&e.constant===this.constant}});var La=new Ee,Lo=new Ee,o_=new Ee,Do=new Ee,pc=new Ee,fc=new Ee,O0=new Ee,s_=new Ee,l_=new Ee,c_=new Ee;function sr(e,n,i){this.a=e!==void 0?e:new Ee,this.b=n!==void 0?n:new Ee,this.c=i!==void 0?i:new Ee}Object.assign(sr,{getNormal:function(e,n,i,l){l===void 0&&(console.warn("THREE.Triangle: .getNormal() target is now required"),l=new Ee),l.subVectors(i,n),La.subVectors(e,n),l.cross(La);var h=l.lengthSq();return h>0?l.multiplyScalar(1/Math.sqrt(h)):l.set(0,0,0)},getBarycoord:function(e,n,i,l,h){La.subVectors(l,n),Lo.subVectors(i,n),o_.subVectors(e,n);var p=La.dot(La),_=La.dot(Lo),s=La.dot(o_),M=Lo.dot(Lo),T=Lo.dot(o_),C=p*M-_*_;if(h===void 0&&(console.warn("THREE.Triangle: .getBarycoord() target is now required"),h=new Ee),C===0)return h.set(-2,-1,-1);var E=1/C,L=(M*s-_*T)*E,I=(p*T-_*s)*E;return h.set(1-L-I,I,L)},containsPoint:function(e,n,i,l){return sr.getBarycoord(e,n,i,l,Do),Do.x>=0&&Do.y>=0&&Do.x+Do.y<=1},getUV:function(e,n,i,l,h,p,_,s){return this.getBarycoord(e,n,i,l,Do),s.set(0,0),s.addScaledVector(h,Do.x),s.addScaledVector(p,Do.y),s.addScaledVector(_,Do.z),s},isFrontFacing:function(e,n,i,l){return La.subVectors(i,n),Lo.subVectors(e,n),La.cross(Lo).dot(l)<0}}),Object.assign(sr.prototype,{set:function(e,n,i){return this.a.copy(e),this.b.copy(n),this.c.copy(i),this},setFromPointsAndIndices:function(e,n,i,l){return this.a.copy(e[n]),this.b.copy(e[i]),this.c.copy(e[l]),this},clone:function(){return new this.constructor().copy(this)},copy:function(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this},getArea:function(){return La.subVectors(this.c,this.b),Lo.subVectors(this.a,this.b),La.cross(Lo).length()*.5},getMidpoint:function(e){return e===void 0&&(console.warn("THREE.Triangle: .getMidpoint() target is now required"),e=new Ee),e.addVectors(this.a,this.b).add(this.c).multiplyScalar(.3333333333333333)},getNormal:function(e){return sr.getNormal(this.a,this.b,this.c,e)},getPlane:function(e){return e===void 0&&(console.warn("THREE.Triangle: .getPlane() target is now required"),e=new ja),e.setFromCoplanarPoints(this.a,this.b,this.c)},getBarycoord:function(e,n){return sr.getBarycoord(e,this.a,this.b,this.c,n)},getUV:function(e,n,i,l,h){return sr.getUV(e,this.a,this.b,this.c,n,i,l,h)},containsPoint:function(e){return sr.containsPoint(e,this.a,this.b,this.c)},isFrontFacing:function(e){return sr.isFrontFacing(this.a,this.b,this.c,e)},intersectsBox:function(e){return e.intersectsTriangle(this)},closestPointToPoint:function(e,n){n===void 0&&(console.warn("THREE.Triangle: .closestPointToPoint() target is now required"),n=new Ee);var i=this.a,l=this.b,h=this.c,p,_;pc.subVectors(l,i),fc.subVectors(h,i),s_.subVectors(e,i);var s=pc.dot(s_),M=fc.dot(s_);if(s<=0&&M<=0)return n.copy(i);l_.subVectors(e,l);var T=pc.dot(l_),C=fc.dot(l_);if(T>=0&&C<=T)return n.copy(l);var E=s*C-T*M;if(E<=0&&s>=0&&T<=0)return p=s/(s-T),n.copy(i).addScaledVector(pc,p);c_.subVectors(e,h);var L=pc.dot(c_),I=fc.dot(c_);if(I>=0&&L<=I)return n.copy(h);var B=L*M-s*I;if(B<=0&&M>=0&&I<=0)return _=M/(M-I),n.copy(i).addScaledVector(fc,_);var O=T*I-L*C;if(O<=0&&C-T>=0&&L-I>=0)return O0.subVectors(h,l),_=(C-T)/(C-T+(L-I)),n.copy(l).addScaledVector(O0,_);var U=1/(O+B+E);return p=B*U,_=E*U,n.copy(i).addScaledVector(pc,p).addScaledVector(fc,_)},equals:function(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}});var N0={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},Da={h:0,s:0,l:0},nf={h:0,s:0,l:0};function en(e,n,i){return n===void 0&&i===void 0?this.set(e):this.setRGB(e,n,i)}function u_(e,n,i){return i<0&&(i+=1),i>1&&(i-=1),i<.16666666666666666?e+(n-e)*6*i:i<.5?n:i<.6666666666666666?e+(n-e)*6*(.6666666666666666-i):e}function h_(e){return e<.04045?e*.0773993808:Math.pow(e*.9478672986+.0521327014,2.4)}function d_(e){return e<.0031308?e*12.92:1.055*Math.pow(e,.41666)-.055}Object.assign(en.prototype,{isColor:!0,r:1,g:1,b:1,set:function(e){return e&&e.isColor?this.copy(e):typeof e=="number"?this.setHex(e):typeof e=="string"&&this.setStyle(e),this},setScalar:function(e){return this.r=e,this.g=e,this.b=e,this},setHex:function(e){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,this},setRGB:function(e,n,i){return this.r=e,this.g=n,this.b=i,this},setHSL:function(e,n,i){if(e=Wn.euclideanModulo(e,1),n=Wn.clamp(n,0,1),i=Wn.clamp(i,0,1),n===0)this.r=this.g=this.b=i;else{var l=i<=.5?i*(1+n):i+n-i*n,h=2*i-l;this.r=u_(h,l,e+.3333333333333333),this.g=u_(h,l,e),this.b=u_(h,l,e-.3333333333333333)}return this},setStyle:function(e){function n(E){E!==void 0&&parseFloat(E)<1&&console.warn("THREE.Color: Alpha component of "+e+" will be ignored.")}var i;if(i=/^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(e)){var l,h=i[1],p=i[2];switch(h){case"rgb":case"rgba":if(l=/^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(p))return this.r=Math.min(255,parseInt(l[1],10))/255,this.g=Math.min(255,parseInt(l[2],10))/255,this.b=Math.min(255,parseInt(l[3],10))/255,n(l[5]),this;if(l=/^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(p))return this.r=Math.min(100,parseInt(l[1],10))/100,this.g=Math.min(100,parseInt(l[2],10))/100,this.b=Math.min(100,parseInt(l[3],10))/100,n(l[5]),this;break;case"hsl":case"hsla":if(l=/^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(p)){var _=parseFloat(l[1])/360,s=parseInt(l[2],10)/100,M=parseInt(l[3],10)/100;return n(l[5]),this.setHSL(_,s,M)}break}}else if(i=/^\#([A-Fa-f0-9]+)$/.exec(e)){var T=i[1],C=T.length;if(C===3)return this.r=parseInt(T.charAt(0)+T.charAt(0),16)/255,this.g=parseInt(T.charAt(1)+T.charAt(1),16)/255,this.b=parseInt(T.charAt(2)+T.charAt(2),16)/255,this;if(C===6)return this.r=parseInt(T.charAt(0)+T.charAt(1),16)/255,this.g=parseInt(T.charAt(2)+T.charAt(3),16)/255,this.b=parseInt(T.charAt(4)+T.charAt(5),16)/255,this}return e&&e.length>0?this.setColorName(e):this},setColorName:function(e){var n=N0[e];return n!==void 0?this.setHex(n):console.warn("THREE.Color: Unknown color "+e),this},clone:function(){return new this.constructor(this.r,this.g,this.b)},copy:function(e){return this.r=e.r,this.g=e.g,this.b=e.b,this},copyGammaToLinear:function(e,n){return n===void 0&&(n=2),this.r=Math.pow(e.r,n),this.g=Math.pow(e.g,n),this.b=Math.pow(e.b,n),this},copyLinearToGamma:function(e,n){n===void 0&&(n=2);var i=n>0?1/n:1;return this.r=Math.pow(e.r,i),this.g=Math.pow(e.g,i),this.b=Math.pow(e.b,i),this},convertGammaToLinear:function(e){return this.copyGammaToLinear(this,e),this},convertLinearToGamma:function(e){return this.copyLinearToGamma(this,e),this},copySRGBToLinear:function(e){return this.r=h_(e.r),this.g=h_(e.g),this.b=h_(e.b),this},copyLinearToSRGB:function(e){return this.r=d_(e.r),this.g=d_(e.g),this.b=d_(e.b),this},convertSRGBToLinear:function(){return this.copySRGBToLinear(this),this},convertLinearToSRGB:function(){return this.copyLinearToSRGB(this),this},getHex:function(){return this.r*255<<16^this.g*255<<8^this.b*255<<0},getHexString:function(){return("000000"+this.getHex().toString(16)).slice(-6)},getHSL:function(e){e===void 0&&(console.warn("THREE.Color: .getHSL() target is now required"),e={h:0,s:0,l:0});var n=this.r,i=this.g,l=this.b,h=Math.max(n,i,l),p=Math.min(n,i,l),_,s,M=(p+h)/2;if(p===h)_=0,s=0;else{var T=h-p;switch(s=M<=.5?T/(h+p):T/(2-h-p),h){case n:_=(i-l)/T+(i0&&(i.alphaTest=this.alphaTest),this.premultipliedAlpha===!0&&(i.premultipliedAlpha=this.premultipliedAlpha),this.wireframe===!0&&(i.wireframe=this.wireframe),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(i.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(i.wireframeLinejoin=this.wireframeLinejoin),this.morphTargets===!0&&(i.morphTargets=!0),this.morphNormals===!0&&(i.morphNormals=!0),this.skinning===!0&&(i.skinning=!0),this.visible===!1&&(i.visible=!1),this.toneMapped===!1&&(i.toneMapped=!1),JSON.stringify(this.userData)!=="{}"&&(i.userData=this.userData);function l(_){var s=[];for(var M in _){var T=_[M];delete T.metadata,s.push(T)}return s}if(n){var h=l(e.textures),p=l(e.images);h.length>0&&(i.textures=h),p.length>0&&(i.images=p)}return i},clone:function(){return new this.constructor().copy(this)},copy:function(e){this.name=e.name,this.fog=e.fog,this.blending=e.blending,this.side=e.side,this.flatShading=e.flatShading,this.vertexTangents=e.vertexTangents,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.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;var n=e.clippingPlanes,i=null;if(n!==null){var l=n.length;i=new Array(l);for(var h=0;h!==l;++h)i[h]=n[h].clone()}return this.clippingPlanes=i,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.premultipliedAlpha=e.premultipliedAlpha,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this},dispose:function(){this.dispatchEvent({type:"dispose"})}}),Object.defineProperty(Rn.prototype,"needsUpdate",{set:function(e){e===!0&&this.version++}});function lr(e){Rn.call(this),this.type="MeshBasicMaterial",this.color=new en(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=Up,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.skinning=!1,this.morphTargets=!1,this.setValues(e)}lr.prototype=Object.create(Rn.prototype),lr.prototype.constructor=lr,lr.prototype.isMeshBasicMaterial=!0,lr.prototype.copy=function(e){return Rn.prototype.copy.call(this,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.skinning=e.skinning,this.morphTargets=e.morphTargets,this};var pi=new Ee;function zn(e,n,i){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.name="",this.array=e,this.itemSize=n,this.count=e!==void 0?e.length/n:0,this.normalized=i===!0,this.usage=Xp,this.updateRange={offset:0,count:-1},this.version=0}Object.defineProperty(zn.prototype,"needsUpdate",{set:function(e){e===!0&&this.version++}}),Object.assign(zn.prototype,{isBufferAttribute:!0,onUploadCallback:function(){},setUsage:function(e){return this.usage=e,this},copy:function(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},copyAt:function(e,n,i){e*=this.itemSize,i*=n.itemSize;for(var l=0,h=this.itemSize;l0,p=l[1]&&l[1].length>0,_=e.morphTargets,s=_.length,M;if(s>0){M=[];for(var T=0;T0){L=[];for(var T=0;T0&&n.length===0&&console.error("THREE.DirectGeometry: Faceless geometries are not supported.");for(var T=0;Tn&&(n=e[i]);return n}var S2=1,qa=new jn,v_=new rn,mc=new Ee,aa=new Pa,vh=new Pa,Zi=new Ee;function yn(){Object.defineProperty(this,"id",{value:S2+=2}),this.uuid=Wn.generateUUID(),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={}}yn.prototype=Object.assign(Object.create(To.prototype),{constructor:yn,isBufferGeometry:!0,getIndex:function(){return this.index},setIndex:function(e){Array.isArray(e)?this.index=new(V0(e)>65535?yh:_h)(e,1):this.index=e},getAttribute:function(e){return this.attributes[e]},setAttribute:function(e,n){return this.attributes[e]=n,this},deleteAttribute:function(e){return delete this.attributes[e],this},addGroup:function(e,n,i){this.groups.push({start:e,count:n,materialIndex:i!==void 0?i:0})},clearGroups:function(){this.groups=[]},setDrawRange:function(e,n){this.drawRange.start=e,this.drawRange.count=n},applyMatrix4:function(e){var n=this.attributes.position;n!==void 0&&(n.applyMatrix4(e),n.needsUpdate=!0);var i=this.attributes.normal;if(i!==void 0){var l=new dr().getNormalMatrix(e);i.applyNormalMatrix(l),i.needsUpdate=!0}var h=this.attributes.tangent;return h!==void 0&&(h.transformDirection(e),h.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this},rotateX:function(e){return qa.makeRotationX(e),this.applyMatrix4(qa),this},rotateY:function(e){return qa.makeRotationY(e),this.applyMatrix4(qa),this},rotateZ:function(e){return qa.makeRotationZ(e),this.applyMatrix4(qa),this},translate:function(e,n,i){return qa.makeTranslation(e,n,i),this.applyMatrix4(qa),this},scale:function(e,n,i){return qa.makeScale(e,n,i),this.applyMatrix4(qa),this},lookAt:function(e){return v_.lookAt(e),v_.updateMatrix(),this.applyMatrix4(v_.matrix),this},center:function(){return this.computeBoundingBox(),this.boundingBox.getCenter(mc).negate(),this.translate(mc.x,mc.y,mc.z),this},setFromObject:function(e){var n=e.geometry;if(e.isPoints||e.isLine){var i=new sn(n.vertices.length*3,3),l=new sn(n.colors.length*3,3);if(this.setAttribute("position",i.copyVector3sArray(n.vertices)),this.setAttribute("color",l.copyColorsArray(n.colors)),n.lineDistances&&n.lineDistances.length===n.vertices.length){var h=new sn(n.lineDistances.length,1);this.setAttribute("lineDistance",h.copyArray(n.lineDistances))}n.boundingSphere!==null&&(this.boundingSphere=n.boundingSphere.clone()),n.boundingBox!==null&&(this.boundingBox=n.boundingBox.clone())}else e.isMesh&&n&&n.isGeometry&&this.fromGeometry(n);return this},setFromPoints:function(e){for(var n=[],i=0,l=e.length;i0){var i=new Float32Array(e.normals.length*3);this.setAttribute("normal",new zn(i,3).copyVector3sArray(e.normals))}if(e.colors.length>0){var l=new Float32Array(e.colors.length*3);this.setAttribute("color",new zn(l,3).copyColorsArray(e.colors))}if(e.uvs.length>0){var h=new Float32Array(e.uvs.length*2);this.setAttribute("uv",new zn(h,2).copyVector2sArray(e.uvs))}if(e.uvs2.length>0){var p=new Float32Array(e.uvs2.length*2);this.setAttribute("uv2",new zn(p,2).copyVector2sArray(e.uvs2))}this.groups=e.groups;for(var _ in e.morphTargets){for(var s=[],M=e.morphTargets[_],T=0,C=M.length;T0){var I=new sn(e.skinIndices.length*4,4);this.setAttribute("skinIndex",I.copyVector4sArray(e.skinIndices))}if(e.skinWeights.length>0){var B=new sn(e.skinWeights.length*4,4);this.setAttribute("skinWeight",B.copyVector4sArray(e.skinWeights))}return e.boundingSphere!==null&&(this.boundingSphere=e.boundingSphere.clone()),e.boundingBox!==null&&(this.boundingBox=e.boundingBox.clone()),this},computeBoundingBox:function(){this.boundingBox===null&&(this.boundingBox=new Pa);var e=this.attributes.position,n=this.morphAttributes.position;if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),n)for(var i=0,l=n.length;i0&&(e.userData=this.userData),this.parameters!==void 0){var n=this.parameters;for(var i in n)n[i]!==void 0&&(e[i]=n[i]);return e}e.data={attributes:{}};var l=this.index;l!==null&&(e.data.index={type:l.array.constructor.name,array:Array.prototype.slice.call(l.array)});var h=this.attributes;for(var i in h){var p=h[i],_=p.toJSON();p.name!==""&&(_.name=p.name),e.data.attributes[i]=_}var s={},M=!1;for(var i in this.morphAttributes){for(var T=this.morphAttributes[i],C=[],E=0,L=T.length;E0&&(s[i]=C,M=!0)}M&&(e.data.morphAttributes=s,e.data.morphTargetsRelative=this.morphTargetsRelative);var I=this.groups;I.length>0&&(e.data.groups=JSON.parse(JSON.stringify(I)));var B=this.boundingSphere;return B!==null&&(e.data.boundingSphere={center:B.center.toArray(),radius:B.radius}),e},clone:function(){return new yn().copy(this)},copy:function(e){var n,i,l;this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.name=e.name;var h=e.index;h!==null&&this.setIndex(h.clone());var p=e.attributes;for(n in p){var _=p[n];this.setAttribute(n,_.clone())}var s=e.morphAttributes;for(n in s){var M=[],T=s[n];for(i=0,l=T.length;i0){var _=h[p[0]];if(_!==void 0)for(this.morphTargetInfluences=[],this.morphTargetDictionary={},n=0,i=_.length;n0&&console.error("THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.")}},raycast:function(e,n){var i=this.geometry,l=this.material,h=this.matrixWorld;if(l!==void 0&&(i.boundingSphere===null&&i.computeBoundingSphere(),x_.copy(i.boundingSphere),x_.applyMatrix4(h),e.ray.intersectsSphere(x_)!==!1&&(G0.getInverse(h),Ks.copy(e.ray).applyMatrix4(G0),!(i.boundingBox!==null&&Ks.intersectsBox(i.boundingBox)===!1)))){var p;if(i.isBufferGeometry){var _,s,M,T=i.index,C=i.attributes.position,E=i.morphAttributes.position,L=i.morphTargetsRelative,I=i.attributes.uv,B=i.attributes.uv2,O=i.groups,U=i.drawRange,q,ee,he,Ce,K,ie,ue,ae;if(T!==null)if(Array.isArray(l))for(q=0,he=O.length;q0&&(We=st);for(var St=0,gt=Oe.length;Sti.far?null:{distance:T,point:lf.clone(),object:e}}function cf(e,n,i,l,h,p,_,s,M,T,C,E){Qs.fromBufferAttribute(h,T),el.fromBufferAttribute(h,C),tl.fromBufferAttribute(h,E);var L=e.morphTargetInfluences;if(n.morphTargets&&p&&L){af.set(0,0,0),of.set(0,0,0),sf.set(0,0,0);for(var I=0,B=p.length;I0)for(var T=0;T0&&(this.normalsNeedUpdate=!0)},computeFlatVertexNormals:function(){var e,n,i;for(this.computeFaceNormals(),e=0,n=this.faces.length;e0&&(this.normalsNeedUpdate=!0)},computeMorphNormals:function(){var e,n,i,l,h;for(i=0,l=this.faces.length;i=0;s--){var O=I[s];for(this.faces.splice(O,1),E=0,L=this.faceVertexUvs.length;E0,ee=I.vertexNormals.length>0,he=I.color.r!==1||I.color.g!==1||I.color.b!==1,Ce=I.vertexColors.length>0,K=0;if(K=le(K,0,0),K=le(K,1,B),K=le(K,2,O),K=le(K,3,U),K=le(K,4,q),K=le(K,5,ee),K=le(K,6,he),K=le(K,7,Ce),_.push(K),_.push(I.a,I.b,I.c),_.push(I.materialIndex),U){var ie=this.faceVertexUvs[0][h];_.push(se(ie[0]),se(ie[1]),se(ie[2]))}if(q&&_.push(De(I.normal)),ee){var ue=I.vertexNormals;_.push(De(ue[0]),De(ue[1]),De(ue[2]))}if(he&&_.push(ye(I.color)),Ce){var ae=I.vertexColors;_.push(ye(ae[0]),ye(ae[1]),ye(ae[2]))}}function le(Ue,Oe,We){return We?Ue|1<0&&(e.data.colors=T),E.length>0&&(e.data.uvs=[E]),e.data.faces=_,e},clone:function(){return new Fn().copy(this)},copy:function(e){var n,i,l,h,p,_;this.vertices=[],this.colors=[],this.faces=[],this.faceVertexUvs=[[]],this.morphTargets=[],this.morphNormals=[],this.skinWeights=[],this.skinIndices=[],this.lineDistances=[],this.boundingBox=null,this.boundingSphere=null,this.name=e.name;var s=e.vertices;for(n=0,i=s.length;n0?1:-1,C.push(Ot.x,Ot.y,Ot.z),E.push(At/ue),E.push(1-Dt/ae),St+=1}}for(Dt=0;Dt0&&(n.defines=this.defines),n.vertexShader=this.vertexShader,n.fragmentShader=this.fragmentShader;var p={};for(var _ in this.extensions)this.extensions[_]===!0&&(p[_]=!0);return Object.keys(p).length>0&&(n.extensions=p),n};function Io(){rn.call(this),this.type="Camera",this.matrixWorldInverse=new jn,this.projectionMatrix=new jn,this.projectionMatrixInverse=new jn}Io.prototype=Object.assign(Object.create(rn.prototype),{constructor:Io,isCamera:!0,copy:function(e,n){return rn.prototype.copy.call(this,e,n),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this},getWorldDirection:function(e){e===void 0&&(console.warn("THREE.Camera: .getWorldDirection() target is now required"),e=new Ee),this.updateMatrixWorld(!0);var n=this.matrixWorld.elements;return e.set(-n[8],-n[9],-n[10]).normalize()},updateMatrixWorld:function(e){rn.prototype.updateMatrixWorld.call(this,e),this.matrixWorldInverse.getInverse(this.matrixWorld)},updateWorldMatrix:function(e,n){rn.prototype.updateWorldMatrix.call(this,e,n),this.matrixWorldInverse.getInverse(this.matrixWorld)},clone:function(){return new this.constructor().copy(this)}});function Xi(e,n,i,l){Io.call(this),this.type="PerspectiveCamera",this.fov=e!==void 0?e:50,this.zoom=1,this.near=i!==void 0?i:.1,this.far=l!==void 0?l:2e3,this.focus=10,this.aspect=n!==void 0?n:1,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}Xi.prototype=Object.assign(Object.create(Io.prototype),{constructor:Xi,isPerspectiveCamera:!0,copy:function(e,n){return Io.prototype.copy.call(this,e,n),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:function(e){var n=.5*this.getFilmHeight()/e;this.fov=Wn.RAD2DEG*2*Math.atan(n),this.updateProjectionMatrix()},getFocalLength:function(){var e=Math.tan(Wn.DEG2RAD*.5*this.fov);return .5*this.getFilmHeight()/e},getEffectiveFOV:function(){return Wn.RAD2DEG*2*Math.atan(Math.tan(Wn.DEG2RAD*.5*this.fov)/this.zoom)},getFilmWidth:function(){return this.filmGauge*Math.min(this.aspect,1)},getFilmHeight:function(){return this.filmGauge/Math.max(this.aspect,1)},setViewOffset:function(e,n,i,l,h,p){this.aspect=e/n,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=n,this.view.offsetX=i,this.view.offsetY=l,this.view.width=h,this.view.height=p,this.updateProjectionMatrix()},clearViewOffset:function(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()},updateProjectionMatrix:function(){var e=this.near,n=e*Math.tan(Wn.DEG2RAD*.5*this.fov)/this.zoom,i=2*n,l=this.aspect*i,h=-.5*l,p=this.view;if(this.view!==null&&this.view.enabled){var _=p.fullWidth,s=p.fullHeight;h+=p.offsetX*l/_,n-=p.offsetY*i/s,l*=p.width/_,i*=p.height/s}var M=this.filmOffset;M!==0&&(h+=e*M/this.getFilmWidth()),this.projectionMatrix.makePerspective(h,h+l,n,n-i,e,this.far),this.projectionMatrixInverse.getInverse(this.projectionMatrix)},toJSON:function(e){var n=rn.prototype.toJSON.call(this,e);return n.object.fov=this.fov,n.object.zoom=this.zoom,n.object.near=this.near,n.object.far=this.far,n.object.focus=this.focus,n.object.aspect=this.aspect,this.view!==null&&(n.object.view=Object.assign({},this.view)),n.object.filmGauge=this.filmGauge,n.object.filmOffset=this.filmOffset,n}});var xc=90,bc=1;function bh(e,n,i,l){rn.call(this),this.type="CubeCamera";var h=new Xi(xc,bc,e,n);h.up.set(0,-1,0),h.lookAt(new Ee(1,0,0)),this.add(h);var p=new Xi(xc,bc,e,n);p.up.set(0,-1,0),p.lookAt(new Ee(-1,0,0)),this.add(p);var _=new Xi(xc,bc,e,n);_.up.set(0,0,1),_.lookAt(new Ee(0,1,0)),this.add(_);var s=new Xi(xc,bc,e,n);s.up.set(0,0,-1),s.lookAt(new Ee(0,-1,0)),this.add(s);var M=new Xi(xc,bc,e,n);M.up.set(0,-1,0),M.lookAt(new Ee(0,0,1)),this.add(M);var T=new Xi(xc,bc,e,n);T.up.set(0,-1,0),T.lookAt(new Ee(0,0,-1)),this.add(T),l=l||{format:Mo,magFilter:qi,minFilter:qi},this.renderTarget=new wc(i,l),this.renderTarget.texture.name="CubeCamera",this.update=function(C,E){this.parent===null&&this.updateMatrixWorld();var L=C.getRenderTarget(),I=this.renderTarget,B=I.texture.generateMipmaps;I.texture.generateMipmaps=!1,C.setRenderTarget(I,0),C.render(E,h),C.setRenderTarget(I,1),C.render(E,p),C.setRenderTarget(I,2),C.render(E,_),C.setRenderTarget(I,3),C.render(E,s),C.setRenderTarget(I,4),C.render(E,M),I.texture.generateMipmaps=B,C.setRenderTarget(I,5),C.render(E,T),C.setRenderTarget(L)},this.clear=function(C,E,L,I){for(var B=C.getRenderTarget(),O=this.renderTarget,U=0;U<6;U++)C.setRenderTarget(O,U),C.clear(E,L,I);C.setRenderTarget(B)}}bh.prototype=Object.create(rn.prototype),bh.prototype.constructor=bh;function wc(e,n,i){Number.isInteger(n)&&(console.warn("THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )"),n=i),Mr.call(this,e,e,n)}wc.prototype=Object.create(Mr.prototype),wc.prototype.constructor=wc,wc.prototype.isWebGLCubeRenderTarget=!0,wc.prototype.fromEquirectangularTexture=function(e,n){this.texture.type=n.type,this.texture.format=n.format,this.texture.encoding=n.encoding;var i=new So,l={uniforms:{tEquirect:{value:null}},vertexShader:["varying vec3 vWorldDirection;","vec3 transformDirection( in vec3 dir, in mat4 matrix ) {"," return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );","}","void main() {"," vWorldDirection = transformDirection( position, modelMatrix );"," #include "," #include ","}"].join(`
`),fragmentShader:["uniform sampler2D tEquirect;","varying vec3 vWorldDirection;","#define RECIPROCAL_PI 0.31830988618","#define RECIPROCAL_PI2 0.15915494","void main() {"," vec3 direction = normalize( vWorldDirection );"," vec2 sampleUV;"," sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;"," sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;"," gl_FragColor = texture2D( tEquirect, sampleUV );","}"].join(`
`)},h=new Nr({type:"CubemapFromEquirect",uniforms:vc(l.uniforms),vertexShader:l.vertexShader,fragmentShader:l.fragmentShader,side:tr,blending:Qo});h.uniforms.tEquirect.value=n;var p=new Ai(new hf(5,5,5),h);i.add(p);var _=new bh(1,10,1);return _.renderTarget=this,_.renderTarget.texture.name="CubeCameraTexture",_.update(e,i),p.geometry.dispose(),p.material.dispose(),this};function Mc(e,n,i,l,h,p,_,s,M,T,C,E){mi.call(this,null,p,_,s,M,T,l,h,C,E),this.image={data:e||null,width:n||1,height:i||1},this.magFilter=M!==void 0?M:Ui,this.minFilter=T!==void 0?T:Ui,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.needsUpdate=!0}Mc.prototype=Object.create(mi.prototype),Mc.prototype.constructor=Mc,Mc.prototype.isDataTexture=!0;var Tc=new Co,df=new Ee;function wh(e,n,i,l,h,p){this.planes=[e!==void 0?e:new ja,n!==void 0?n:new ja,i!==void 0?i:new ja,l!==void 0?l:new ja,h!==void 0?h:new ja,p!==void 0?p:new ja]}Object.assign(wh.prototype,{set:function(e,n,i,l,h,p){var _=this.planes;return _[0].copy(e),_[1].copy(n),_[2].copy(i),_[3].copy(l),_[4].copy(h),_[5].copy(p),this},clone:function(){return new this.constructor().copy(this)},copy:function(e){for(var n=this.planes,i=0;i<6;i++)n[i].copy(e.planes[i]);return this},setFromProjectionMatrix:function(e){var n=this.planes,i=e.elements,l=i[0],h=i[1],p=i[2],_=i[3],s=i[4],M=i[5],T=i[6],C=i[7],E=i[8],L=i[9],I=i[10],B=i[11],O=i[12],U=i[13],q=i[14],ee=i[15];return n[0].setComponents(_-l,C-s,B-E,ee-O).normalize(),n[1].setComponents(_+l,C+s,B+E,ee+O).normalize(),n[2].setComponents(_+h,C+M,B+L,ee+U).normalize(),n[3].setComponents(_-h,C-M,B-L,ee-U).normalize(),n[4].setComponents(_-p,C-T,B-I,ee-q).normalize(),n[5].setComponents(_+p,C+T,B+I,ee+q).normalize(),this},intersectsObject:function(e){var n=e.geometry;return n.boundingSphere===null&&n.computeBoundingSphere(),Tc.copy(n.boundingSphere).applyMatrix4(e.matrixWorld),this.intersectsSphere(Tc)},intersectsSprite:function(e){return Tc.center.set(0,0,0),Tc.radius=.7071067811865476,Tc.applyMatrix4(e.matrixWorld),this.intersectsSphere(Tc)},intersectsSphere:function(e){for(var n=this.planes,i=e.center,l=-e.radius,h=0;h<6;h++){var p=n[h].distanceToPoint(i);if(p0?e.max.x:e.min.x,df.y=l.normal.y>0?e.max.y:e.min.y,df.z=l.normal.z>0?e.max.z:e.min.z,l.distanceToPoint(df)<0)return!1}return!0},containsPoint:function(e){for(var n=this.planes,i=0;i<6;i++)if(n[i].distanceToPoint(e)<0)return!1;return!0}});var an={common:{diffuse:{value:new en(15658734)},opacity:{value:1},map:{value:null},uvTransform:{value:new dr},uv2Transform:{value:new dr},alphaMap:{value:null}},specularmap:{specularMap:{value:null}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},refractionRatio:{value:.98},maxMipLevel:{value:0}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1}},emissivemap:{emissiveMap:{value:null}},bumpmap:{bumpMap:{value:null},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalScale:{value:new Lt(1,1)}},displacementmap:{displacementMap:{value:null},displacementScale:{value:1},displacementBias:{value:0}},roughnessmap:{roughnessMap:{value:null}},metalnessmap:{metalnessMap:{value:null}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new en(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{},shadow:{},shadowBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{},shadow:{},shadowBias:{},shadowRadius:{},shadowMapSize:{}}},spotShadowMap:{value:[]},spotShadowMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{},shadow:{},shadowBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}}},points:{diffuse:{value:new en(15658734)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},uvTransform:{value:new dr}},sprite:{diffuse:{value:new en(15658734)},opacity:{value:1},center:{value:new Lt(.5,.5)},rotation:{value:0},map:{value:null},alphaMap:{value:null},uvTransform:{value:new dr}}};function W0(){var e=null,n=!1,i=null;function l(h,p){n!==!1&&(i(h,p),e.requestAnimationFrame(l))}return{start:function(){n!==!0&&i!==null&&(e.requestAnimationFrame(l),n=!0)},stop:function(){n=!1},setAnimationLoop:function(h){i=h},setContext:function(h){e=h}}}function I2(e,n){var i=n.isWebGL2,l=new WeakMap;function h(T,C){var E=T.array,L=T.usage,I=e.createBuffer();e.bindBuffer(C,I),e.bufferData(C,E,L),T.onUploadCallback();var B=5126;return E instanceof Float32Array?B=5126:E instanceof Float64Array?console.warn("THREE.WebGLAttributes: Unsupported data buffer format: Float64Array."):E instanceof Uint16Array?B=5123:E instanceof Int16Array?B=5122:E instanceof Uint32Array?B=5125:E instanceof Int32Array?B=5124:E instanceof Int8Array?B=5120:E instanceof Uint8Array&&(B=5121),{buffer:I,type:B,bytesPerElement:E.BYTES_PER_ELEMENT,version:T.version}}function p(T,C,E){var L=C.array,I=C.updateRange;e.bindBuffer(E,T),I.count===-1?e.bufferSubData(E,0,L):(i?e.bufferSubData(E,I.offset*L.BYTES_PER_ELEMENT,L,I.offset,I.count):e.bufferSubData(E,I.offset*L.BYTES_PER_ELEMENT,L.subarray(I.offset,I.offset+I.count)),I.count=-1)}function _(T){return T.isInterleavedBufferAttribute&&(T=T.data),l.get(T)}function s(T){T.isInterleavedBufferAttribute&&(T=T.data);var C=l.get(T);C&&(e.deleteBuffer(C.buffer),l.delete(T))}function M(T,C){T.isInterleavedBufferAttribute&&(T=T.data);var E=l.get(T);E===void 0?l.set(T,h(T,C)):E.version 0.0 ) {
distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
}
return distanceFalloff;
#else
if( cutoffDistance > 0.0 && decayExponent > 0.0 ) {
return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );
}
return 1.0;
#endif
}
vec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {
return RECIPROCAL_PI * diffuseColor;
}
vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {
float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );
return ( 1.0 - specularColor ) * fresnel + specularColor;
}
vec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {
float fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );
vec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;
return Fr * fresnel + F0;
}
float G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {
float a2 = pow2( alpha );
float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
return 1.0 / ( gl * gv );
}
float G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
float a2 = pow2( alpha );
float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
return 0.5 / max( gv + gl, EPSILON );
}
float D_GGX( const in float alpha, const in float dotNH ) {
float a2 = pow2( alpha );
float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
return RECIPROCAL_PI * a2 / pow2( denom );
}
vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {
float alpha = pow2( roughness );
vec3 halfDir = normalize( incidentLight.direction + viewDir );
float dotNL = saturate( dot( normal, incidentLight.direction ) );
float dotNV = saturate( dot( normal, viewDir ) );
float dotNH = saturate( dot( normal, halfDir ) );
float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
vec3 F = F_Schlick( specularColor, dotLH );
float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );
float D = D_GGX( alpha, dotNH );
return F * ( G * D );
}
vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
const float LUT_SIZE = 64.0;
const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
const float LUT_BIAS = 0.5 / LUT_SIZE;
float dotNV = saturate( dot( N, V ) );
vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
uv = uv * LUT_SCALE + LUT_BIAS;
return uv;
}
float LTC_ClippedSphereFormFactor( const in vec3 f ) {
float l = length( f );
return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
}
vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
float x = dot( v1, v2 );
float y = abs( x );
float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
float b = 3.4175940 + ( 4.1616724 + y ) * y;
float v = a / b;
float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
return cross( v1, v2 ) * theta_sintheta;
}
vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
vec3 lightNormal = cross( v1, v2 );
if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
vec3 T1, T2;
T1 = normalize( V - N * dot( V, N ) );
T2 = - cross( N, T1 );
mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );
vec3 coords[ 4 ];
coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
coords[ 0 ] = normalize( coords[ 0 ] );
coords[ 1 ] = normalize( coords[ 1 ] );
coords[ 2 ] = normalize( coords[ 2 ] );
coords[ 3 ] = normalize( coords[ 3 ] );
vec3 vectorFormFactor = vec3( 0.0 );
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
return vec3( result );
}
vec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {
float dotNV = saturate( dot( normal, viewDir ) );
vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
return specularColor * brdf.x + brdf.y;
}
void BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
vec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );
vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
vec3 FssEss = F * brdf.x + brdf.y;
float Ess = brdf.x + brdf.y;
float Ems = 1.0 - Ess;
vec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
singleScatter += FssEss;
multiScatter += Fms * Ems;
}
float G_BlinnPhong_Implicit( ) {
return 0.25;
}
float D_BlinnPhong( const in float shininess, const in float dotNH ) {
return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
}
vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {
vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
float dotNH = saturate( dot( geometry.normal, halfDir ) );
float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
vec3 F = F_Schlick( specularColor, dotLH );
float G = G_BlinnPhong_Implicit( );
float D = D_BlinnPhong( shininess, dotNH );
return F * ( G * D );
}
float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {
return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );
}
float BlinnExponentToGGXRoughness( const in float blinnExponent ) {
return sqrt( 2.0 / ( blinnExponent + 2.0 ) );
}
#if defined( USE_SHEEN )
float D_Charlie(float roughness, float NoH) {
float invAlpha = 1.0 / roughness;
float cos2h = NoH * NoH;
float sin2h = max(1.0 - cos2h, 0.0078125); return (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);
}
float V_Neubelt(float NoV, float NoL) {
return saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));
}
vec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {
vec3 N = geometry.normal;
vec3 V = geometry.viewDir;
vec3 H = normalize( V + L );
float dotNH = saturate( dot( N, H ) );
return specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );
}
#endif`,V2=`#ifdef USE_BUMPMAP
uniform sampler2D bumpMap;
uniform float bumpScale;
vec2 dHdxy_fwd() {
vec2 dSTdx = dFdx( vUv );
vec2 dSTdy = dFdy( vUv );
float Hll = bumpScale * texture2D( bumpMap, vUv ).x;
float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;
float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;
return vec2( dBx, dBy );
}
vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {
vec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );
vec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );
vec3 vN = surf_norm;
vec3 R1 = cross( vSigmaY, vN );
vec3 R2 = cross( vN, vSigmaX );
float fDet = dot( vSigmaX, R1 );
fDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
return normalize( abs( fDet ) * surf_norm - vGrad );
}
#endif`,G2=`#if NUM_CLIPPING_PLANES > 0
vec4 plane;
#pragma unroll_loop
for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
plane = clippingPlanes[ i ];
if ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;
}
#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
bool clipped = true;
#pragma unroll_loop
for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
plane = clippingPlanes[ i ];
clipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;
}
if ( clipped ) discard;
#endif
#endif`,H2=`#if NUM_CLIPPING_PLANES > 0
#if ! defined( STANDARD ) && ! defined( PHONG ) && ! defined( MATCAP )
varying vec3 vViewPosition;
#endif
uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
#endif`,W2=`#if NUM_CLIPPING_PLANES > 0 && ! defined( STANDARD ) && ! defined( PHONG ) && ! defined( MATCAP )
varying vec3 vViewPosition;
#endif`,j2=`#if NUM_CLIPPING_PLANES > 0 && ! defined( STANDARD ) && ! defined( PHONG ) && ! defined( MATCAP )
vViewPosition = - mvPosition.xyz;
#endif`,q2=`#ifdef USE_COLOR
diffuseColor.rgb *= vColor;
#endif`,Z2=`#ifdef USE_COLOR
varying vec3 vColor;
#endif`,X2=`#ifdef USE_COLOR
varying vec3 vColor;
#endif`,Y2=`#ifdef USE_COLOR
vColor.xyz = color.xyz;
#endif`,$2=`#define PI 3.14159265359
#define PI2 6.28318530718
#define PI_HALF 1.5707963267949
#define RECIPROCAL_PI 0.31830988618
#define RECIPROCAL_PI2 0.15915494
#define LOG2 1.442695
#define EPSILON 1e-6
#ifndef saturate
#define saturate(a) clamp( a, 0.0, 1.0 )
#endif
#define whiteComplement(a) ( 1.0 - saturate( a ) )
float pow2( const in float x ) { return x*x; }
float pow3( const in float x ) { return x*x*x; }
float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
highp float rand( const in vec2 uv ) {
const highp float a = 12.9898, b = 78.233, c = 43758.5453;
highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
return fract(sin(sn) * c);
}
#ifdef HIGH_PRECISION
float precisionSafeLength( vec3 v ) { return length( v ); }
#else
float max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }
float precisionSafeLength( vec3 v ) {
float maxComponent = max3( abs( v ) );
return length( v / maxComponent ) * maxComponent;
}
#endif
struct IncidentLight {
vec3 color;
vec3 direction;
bool visible;
};
struct ReflectedLight {
vec3 directDiffuse;
vec3 directSpecular;
vec3 indirectDiffuse;
vec3 indirectSpecular;
};
struct GeometricContext {
vec3 position;
vec3 normal;
vec3 viewDir;
#ifdef CLEARCOAT
vec3 clearcoatNormal;
#endif
};
vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
}
vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
}
vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
float distance = dot( planeNormal, point - pointOnPlane );
return - distance * planeNormal + point;
}
float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
return sign( dot( point - pointOnPlane, planeNormal ) );
}
vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;
}
mat3 transposeMat3( const in mat3 m ) {
mat3 tmp;
tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );
tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );
tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );
return tmp;
}
float linearToRelativeLuminance( const in vec3 color ) {
vec3 weights = vec3( 0.2126, 0.7152, 0.0722 );
return dot( weights, color.rgb );
}
bool isPerspectiveMatrix( mat4 m ) {
return m[ 2 ][ 3 ] == - 1.0;
}`,J2=`#ifdef ENVMAP_TYPE_CUBE_UV
#define cubeUV_maxMipLevel 8.0
#define cubeUV_minMipLevel 4.0
#define cubeUV_maxTileSize 256.0
#define cubeUV_minTileSize 16.0
float getFace(vec3 direction) {
vec3 absDirection = abs(direction);
float face = -1.0;
if (absDirection.x > absDirection.z) {
if (absDirection.x > absDirection.y)
face = direction.x > 0.0 ? 0.0 : 3.0;
else
face = direction.y > 0.0 ? 1.0 : 4.0;
} else {
if (absDirection.z > absDirection.y)
face = direction.z > 0.0 ? 2.0 : 5.0;
else
face = direction.y > 0.0 ? 1.0 : 4.0;
}
return face;
}
vec2 getUV(vec3 direction, float face) {
vec2 uv;
if (face == 0.0) {
uv = vec2(-direction.z, direction.y) / abs(direction.x);
} else if (face == 1.0) {
uv = vec2(direction.x, -direction.z) / abs(direction.y);
} else if (face == 2.0) {
uv = direction.xy / abs(direction.z);
} else if (face == 3.0) {
uv = vec2(direction.z, direction.y) / abs(direction.x);
} else if (face == 4.0) {
uv = direction.xz / abs(direction.y);
} else {
uv = vec2(-direction.x, direction.y) / abs(direction.z);
}
return 0.5 * (uv + 1.0);
}
vec3 bilinearCubeUV(sampler2D envMap, vec3 direction, float mipInt) {
float face = getFace(direction);
float filterInt = max(cubeUV_minMipLevel - mipInt, 0.0);
mipInt = max(mipInt, cubeUV_minMipLevel);
float faceSize = exp2(mipInt);
float texelSize = 1.0 / (3.0 * cubeUV_maxTileSize);
vec2 uv = getUV(direction, face) * (faceSize - 1.0);
vec2 f = fract(uv);
uv += 0.5 - f;
if (face > 2.0) {
uv.y += faceSize;
face -= 3.0;
}
uv.x += face * faceSize;
if(mipInt < cubeUV_maxMipLevel){
uv.y += 2.0 * cubeUV_maxTileSize;
}
uv.y += filterInt * 2.0 * cubeUV_minTileSize;
uv.x += 3.0 * max(0.0, cubeUV_maxTileSize - 2.0 * faceSize);
uv *= texelSize;
vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
uv.x += texelSize;
vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
uv.y += texelSize;
vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
uv.x -= texelSize;
vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
vec3 tm = mix(tl, tr, f.x);
vec3 bm = mix(bl, br, f.x);
return mix(tm, bm, f.y);
}
#define r0 1.0
#define v0 0.339
#define m0 -2.0
#define r1 0.8
#define v1 0.276
#define m1 -1.0
#define r4 0.4
#define v4 0.046
#define m4 2.0
#define r5 0.305
#define v5 0.016
#define m5 3.0
#define r6 0.21
#define v6 0.0038
#define m6 4.0
float roughnessToMip(float roughness) {
float mip = 0.0;
if (roughness >= r1) {
mip = (r0 - roughness) * (m1 - m0) / (r0 - r1) + m0;
} else if (roughness >= r4) {
mip = (r1 - roughness) * (m4 - m1) / (r1 - r4) + m1;
} else if (roughness >= r5) {
mip = (r4 - roughness) * (m5 - m4) / (r4 - r5) + m4;
} else if (roughness >= r6) {
mip = (r5 - roughness) * (m6 - m5) / (r5 - r6) + m5;
} else {
mip = -2.0 * log2(1.16 * roughness); }
return mip;
}
vec4 textureCubeUV(sampler2D envMap, vec3 sampleDir, float roughness) {
float mip = clamp(roughnessToMip(roughness), m0, cubeUV_maxMipLevel);
float mipF = fract(mip);
float mipInt = floor(mip);
vec3 color0 = bilinearCubeUV(envMap, sampleDir, mipInt);
if (mipF == 0.0) {
return vec4(color0, 1.0);
} else {
vec3 color1 = bilinearCubeUV(envMap, sampleDir, mipInt + 1.0);
return vec4(mix(color0, color1, mipF), 1.0);
}
}
#endif`,K2=`vec3 transformedNormal = objectNormal;
#ifdef USE_INSTANCING
transformedNormal = mat3( instanceMatrix ) * transformedNormal;
#endif
transformedNormal = normalMatrix * transformedNormal;
#ifdef FLIP_SIDED
transformedNormal = - transformedNormal;
#endif
#ifdef USE_TANGENT
vec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;
#ifdef FLIP_SIDED
transformedTangent = - transformedTangent;
#endif
#endif`,Q2=`#ifdef USE_DISPLACEMENTMAP
uniform sampler2D displacementMap;
uniform float displacementScale;
uniform float displacementBias;
#endif`,eE=`#ifdef USE_DISPLACEMENTMAP
transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );
#endif`,tE=`#ifdef USE_EMISSIVEMAP
vec4 emissiveColor = texture2D( emissiveMap, vUv );
emissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;
totalEmissiveRadiance *= emissiveColor.rgb;
#endif`,nE=`#ifdef USE_EMISSIVEMAP
uniform sampler2D emissiveMap;
#endif`,iE="gl_FragColor = linearToOutputTexel( gl_FragColor );",rE=`
vec4 LinearToLinear( in vec4 value ) {
return value;
}
vec4 GammaToLinear( in vec4 value, in float gammaFactor ) {
return vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );
}
vec4 LinearToGamma( in vec4 value, in float gammaFactor ) {
return vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );
}
vec4 sRGBToLinear( in vec4 value ) {
return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );
}
vec4 LinearTosRGB( in vec4 value ) {
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 );
}
vec4 RGBEToLinear( in vec4 value ) {
return vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );
}
vec4 LinearToRGBE( in vec4 value ) {
float maxComponent = max( max( value.r, value.g ), value.b );
float fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );
return vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );
}
vec4 RGBMToLinear( in vec4 value, in float maxRange ) {
return vec4( value.rgb * value.a * maxRange, 1.0 );
}
vec4 LinearToRGBM( in vec4 value, in float maxRange ) {
float maxRGB = max( value.r, max( value.g, value.b ) );
float M = clamp( maxRGB / maxRange, 0.0, 1.0 );
M = ceil( M * 255.0 ) / 255.0;
return vec4( value.rgb / ( M * maxRange ), M );
}
vec4 RGBDToLinear( in vec4 value, in float maxRange ) {
return vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );
}
vec4 LinearToRGBD( in vec4 value, in float maxRange ) {
float maxRGB = max( value.r, max( value.g, value.b ) );
float D = max( maxRange / maxRGB, 1.0 );
D = clamp( floor( D ) / 255.0, 0.0, 1.0 );
return vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );
}
const mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );
vec4 LinearToLogLuv( in vec4 value ) {
vec3 Xp_Y_XYZp = cLogLuvM * value.rgb;
Xp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );
vec4 vResult;
vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;
float Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;
vResult.w = fract( Le );
vResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;
return vResult;
}
const mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );
vec4 LogLuvToLinear( in vec4 value ) {
float Le = value.z * 255.0 + value.w;
vec3 Xp_Y_XYZp;
Xp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );
Xp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;
Xp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;
vec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;
return vec4( max( vRGB, 0.0 ), 1.0 );
}`,aE=`#ifdef USE_ENVMAP
#ifdef ENV_WORLDPOS
vec3 cameraToFrag;
if ( isOrthographic ) {
cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
} else {
cameraToFrag = normalize( vWorldPosition - cameraPosition );
}
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
#ifdef ENVMAP_MODE_REFLECTION
vec3 reflectVec = reflect( cameraToFrag, worldNormal );
#else
vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
#endif
#else
vec3 reflectVec = vReflect;
#endif
#ifdef ENVMAP_TYPE_CUBE
vec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
#elif defined( ENVMAP_TYPE_CUBE_UV )
vec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );
#elif defined( ENVMAP_TYPE_EQUIREC )
vec2 sampleUV;
reflectVec = normalize( reflectVec );
sampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
sampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
vec4 envColor = texture2D( envMap, sampleUV );
#elif defined( ENVMAP_TYPE_SPHERE )
reflectVec = normalize( reflectVec );
vec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );
vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );
#else
vec4 envColor = vec4( 0.0 );
#endif
#ifndef ENVMAP_TYPE_CUBE_UV
envColor = envMapTexelToLinear( envColor );
#endif
#ifdef ENVMAP_BLENDING_MULTIPLY
outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
#elif defined( ENVMAP_BLENDING_MIX )
outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
#elif defined( ENVMAP_BLENDING_ADD )
outgoingLight += envColor.xyz * specularStrength * reflectivity;
#endif
#endif`,oE=`#ifdef USE_ENVMAP
uniform float envMapIntensity;
uniform float flipEnvMap;
uniform int maxMipLevel;
#ifdef ENVMAP_TYPE_CUBE
uniform samplerCube envMap;
#else
uniform sampler2D envMap;
#endif
#endif`,sE=`#ifdef USE_ENVMAP
uniform float reflectivity;
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )
#define ENV_WORLDPOS
#endif
#ifdef ENV_WORLDPOS
varying vec3 vWorldPosition;
uniform float refractionRatio;
#else
varying vec3 vReflect;
#endif
#endif`,lE=`#ifdef USE_ENVMAP
#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )
#define ENV_WORLDPOS
#endif
#ifdef ENV_WORLDPOS
varying vec3 vWorldPosition;
#else
varying vec3 vReflect;
uniform float refractionRatio;
#endif
#endif`,cE=`#ifdef USE_ENVMAP
#ifdef ENV_WORLDPOS
vWorldPosition = worldPosition.xyz;
#else
vec3 cameraToVertex;
if ( isOrthographic ) {
cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
} else {
cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
}
vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
#ifdef ENVMAP_MODE_REFLECTION
vReflect = reflect( cameraToVertex, worldNormal );
#else
vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
#endif
#endif
#endif`,uE=`#ifdef USE_FOG
fogDepth = -mvPosition.z;
#endif`,hE=`#ifdef USE_FOG
varying float fogDepth;
#endif`,dE=`#ifdef USE_FOG
#ifdef FOG_EXP2
float fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );
#else
float fogFactor = smoothstep( fogNear, fogFar, fogDepth );
#endif
gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
#endif`,pE=`#ifdef USE_FOG
uniform vec3 fogColor;
varying float fogDepth;
#ifdef FOG_EXP2
uniform float fogDensity;
#else
uniform float fogNear;
uniform float fogFar;
#endif
#endif`,fE=`#ifdef USE_GRADIENTMAP
uniform sampler2D gradientMap;
#endif
vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
float dotNL = dot( normal, lightDirection );
vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );
#ifdef USE_GRADIENTMAP
return texture2D( gradientMap, coord ).rgb;
#else
return ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );
#endif
}`,mE=`#ifdef USE_LIGHTMAP
vec4 lightMapTexel= texture2D( lightMap, vUv2 );
reflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;
#endif`,gE=`#ifdef USE_LIGHTMAP
uniform sampler2D lightMap;
uniform float lightMapIntensity;
#endif`,_E=`vec3 diffuse = vec3( 1.0 );
GeometricContext geometry;
geometry.position = mvPosition.xyz;
geometry.normal = normalize( transformedNormal );
geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );
GeometricContext backGeometry;
backGeometry.position = geometry.position;
backGeometry.normal = -geometry.normal;
backGeometry.viewDir = geometry.viewDir;
vLightFront = vec3( 0.0 );
vIndirectFront = vec3( 0.0 );
#ifdef DOUBLE_SIDED
vLightBack = vec3( 0.0 );
vIndirectBack = vec3( 0.0 );
#endif
IncidentLight directLight;
float dotNL;
vec3 directLightColor_Diffuse;
#if NUM_POINT_LIGHTS > 0
#pragma unroll_loop
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
getPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );
dotNL = dot( geometry.normal, directLight.direction );
directLightColor_Diffuse = PI * directLight.color;
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
#ifdef DOUBLE_SIDED
vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;
#endif
}
#endif
#if NUM_SPOT_LIGHTS > 0
#pragma unroll_loop
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
getSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );
dotNL = dot( geometry.normal, directLight.direction );
directLightColor_Diffuse = PI * directLight.color;
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
#ifdef DOUBLE_SIDED
vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;
#endif
}
#endif
#if NUM_DIR_LIGHTS > 0
#pragma unroll_loop
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
getDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );
dotNL = dot( geometry.normal, directLight.direction );
directLightColor_Diffuse = PI * directLight.color;
vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
#ifdef DOUBLE_SIDED
vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;
#endif
}
#endif
#if NUM_HEMI_LIGHTS > 0
#pragma unroll_loop
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
vIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );
#ifdef DOUBLE_SIDED
vIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );
#endif
}
#endif`,yE=`uniform bool receiveShadow;
uniform vec3 ambientLightColor;
uniform vec3 lightProbe[ 9 ];
vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
float x = normal.x, y = normal.y, z = normal.z;
vec3 result = shCoefficients[ 0 ] * 0.886227;
result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
return result;
}
vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {
vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
return irradiance;
}
vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
vec3 irradiance = ambientLightColor;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI;
#endif
return irradiance;
}
#if NUM_DIR_LIGHTS > 0
struct DirectionalLight {
vec3 direction;
vec3 color;
int shadow;
float shadowBias;
float shadowRadius;
vec2 shadowMapSize;
};
uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
void getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {
directLight.color = directionalLight.color;
directLight.direction = directionalLight.direction;
directLight.visible = true;
}
#endif
#if NUM_POINT_LIGHTS > 0
struct PointLight {
vec3 position;
vec3 color;
float distance;
float decay;
int shadow;
float shadowBias;
float shadowRadius;
vec2 shadowMapSize;
float shadowCameraNear;
float shadowCameraFar;
};
uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
void getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {
vec3 lVector = pointLight.position - geometry.position;
directLight.direction = normalize( lVector );
float lightDistance = length( lVector );
directLight.color = pointLight.color;
directLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );
directLight.visible = ( directLight.color != vec3( 0.0 ) );
}
#endif
#if NUM_SPOT_LIGHTS > 0
struct SpotLight {
vec3 position;
vec3 direction;
vec3 color;
float distance;
float decay;
float coneCos;
float penumbraCos;
int shadow;
float shadowBias;
float shadowRadius;
vec2 shadowMapSize;
};
uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
void getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {
vec3 lVector = spotLight.position - geometry.position;
directLight.direction = normalize( lVector );
float lightDistance = length( lVector );
float angleCos = dot( directLight.direction, spotLight.direction );
if ( angleCos > spotLight.coneCos ) {
float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );
directLight.color = spotLight.color;
directLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );
directLight.visible = true;
} else {
directLight.color = vec3( 0.0 );
directLight.visible = false;
}
}
#endif
#if NUM_RECT_AREA_LIGHTS > 0
struct RectAreaLight {
vec3 color;
vec3 position;
vec3 halfWidth;
vec3 halfHeight;
};
uniform sampler2D ltc_1; uniform sampler2D ltc_2;
uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];
#endif
#if NUM_HEMI_LIGHTS > 0
struct HemisphereLight {
vec3 direction;
vec3 skyColor;
vec3 groundColor;
};
uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];
vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {
float dotNL = dot( geometry.normal, hemiLight.direction );
float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI;
#endif
return irradiance;
}
#endif`,vE=`#if defined( USE_ENVMAP )
#ifdef ENVMAP_MODE_REFRACTION
uniform float refractionRatio;
#endif
vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {
vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
#ifdef ENVMAP_TYPE_CUBE
vec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );
#ifdef TEXTURE_LOD_EXT
vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );
#else
vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );
#endif
envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
#elif defined( ENVMAP_TYPE_CUBE_UV )
vec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );
#else
vec4 envMapColor = vec4( 0.0 );
#endif
return PI * envMapColor.rgb * envMapIntensity;
}
float getSpecularMIPLevel( const in float roughness, const in int maxMIPLevel ) {
float maxMIPLevelScalar = float( maxMIPLevel );
float sigma = PI * roughness * roughness / ( 1.0 + roughness );
float desiredMIPLevel = maxMIPLevelScalar + log2( sigma );
return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );
}
vec3 getLightProbeIndirectRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {
#ifdef ENVMAP_MODE_REFLECTION
vec3 reflectVec = reflect( -viewDir, normal );
reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
#else
vec3 reflectVec = refract( -viewDir, normal, refractionRatio );
#endif
reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
float specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );
#ifdef ENVMAP_TYPE_CUBE
vec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
#ifdef TEXTURE_LOD_EXT
vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );
#else
vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );
#endif
envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
#elif defined( ENVMAP_TYPE_CUBE_UV )
vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );
#elif defined( ENVMAP_TYPE_EQUIREC )
vec2 sampleUV;
sampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
sampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
#ifdef TEXTURE_LOD_EXT
vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );
#else
vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );
#endif
envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
#elif defined( ENVMAP_TYPE_SPHERE )
vec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );
#ifdef TEXTURE_LOD_EXT
vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
#else
vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
#endif
envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
#endif
return envMapColor.rgb * envMapIntensity;
}
#endif`,xE=`ToonMaterial material;
material.diffuseColor = diffuseColor.rgb;
material.specularColor = specular;
material.specularShininess = shininess;
material.specularStrength = specularStrength;`,bE=`varying vec3 vViewPosition;
#ifndef FLAT_SHADED
varying vec3 vNormal;
#endif
struct ToonMaterial {
vec3 diffuseColor;
vec3 specularColor;
float specularShininess;
float specularStrength;
};
void RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
vec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI;
#endif
reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
reflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;
}
void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
}
#define RE_Direct RE_Direct_Toon
#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon
#define Material_LightProbeLOD( material ) (0)`,wE=`BlinnPhongMaterial material;
material.diffuseColor = diffuseColor.rgb;
material.specularColor = specular;
material.specularShininess = shininess;
material.specularStrength = specularStrength;`,ME=`varying vec3 vViewPosition;
#ifndef FLAT_SHADED
varying vec3 vNormal;
#endif
struct BlinnPhongMaterial {
vec3 diffuseColor;
vec3 specularColor;
float specularShininess;
float specularStrength;
};
void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
vec3 irradiance = dotNL * directLight.color;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI;
#endif
reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
reflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;
}
void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
}
#define RE_Direct RE_Direct_BlinnPhong
#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong
#define Material_LightProbeLOD( material ) (0)`,TE=`PhysicalMaterial material;
material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );
float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
material.specularRoughness = max( roughnessFactor, 0.0525 );material.specularRoughness += geometryRoughness;
material.specularRoughness = min( material.specularRoughness, 1.0 );
#ifdef REFLECTIVITY
material.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );
#else
material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );
#endif
#ifdef CLEARCOAT
material.clearcoat = saturate( clearcoat ); material.clearcoatRoughness = max( clearcoatRoughness, 0.0525 );
material.clearcoatRoughness += geometryRoughness;
material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
#endif
#ifdef USE_SHEEN
material.sheenColor = sheen;
#endif`,EE=`struct PhysicalMaterial {
vec3 diffuseColor;
float specularRoughness;
vec3 specularColor;
#ifdef CLEARCOAT
float clearcoat;
float clearcoatRoughness;
#endif
#ifdef USE_SHEEN
vec3 sheenColor;
#endif
};
#define MAXIMUM_SPECULAR_COEFFICIENT 0.16
#define DEFAULT_SPECULAR_COEFFICIENT 0.04
float clearcoatDHRApprox( const in float roughness, const in float dotNL ) {
return DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );
}
#if NUM_RECT_AREA_LIGHTS > 0
void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
vec3 normal = geometry.normal;
vec3 viewDir = geometry.viewDir;
vec3 position = geometry.position;
vec3 lightPos = rectAreaLight.position;
vec3 halfWidth = rectAreaLight.halfWidth;
vec3 halfHeight = rectAreaLight.halfHeight;
vec3 lightColor = rectAreaLight.color;
float roughness = material.specularRoughness;
vec3 rectCoords[ 4 ];
rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
vec2 uv = LTC_Uv( normal, viewDir, roughness );
vec4 t1 = texture2D( ltc_1, uv );
vec4 t2 = texture2D( ltc_2, uv );
mat3 mInv = mat3(
vec3( t1.x, 0, t1.y ),
vec3( 0, 1, 0 ),
vec3( t1.z, 0, t1.w )
);
vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );
reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
}
#endif
void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
vec3 irradiance = dotNL * directLight.color;
#ifndef PHYSICALLY_CORRECT_LIGHTS
irradiance *= PI;
#endif
#ifdef CLEARCOAT
float ccDotNL = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );
vec3 ccIrradiance = ccDotNL * directLight.color;
#ifndef PHYSICALLY_CORRECT_LIGHTS
ccIrradiance *= PI;
#endif
float clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );
reflectedLight.directSpecular += ccIrradiance * material.clearcoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );
#else
float clearcoatDHR = 0.0;
#endif
#ifdef USE_SHEEN
reflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_Sheen(
material.specularRoughness,
directLight.direction,
geometry,
material.sheenColor
);
#else
reflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness);
#endif
reflectedLight.directDiffuse += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
}
void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
}
void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
#ifdef CLEARCOAT
float ccDotNV = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );
reflectedLight.indirectSpecular += clearcoatRadiance * material.clearcoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );
float ccDotNL = ccDotNV;
float clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );
#else
float clearcoatDHR = 0.0;
#endif
float clearcoatInv = 1.0 - clearcoatDHR;
vec3 singleScattering = vec3( 0.0 );
vec3 multiScattering = vec3( 0.0 );
vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
BRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );
vec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );
reflectedLight.indirectSpecular += clearcoatInv * radiance * singleScattering;
reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;
reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;
}
#define RE_Direct RE_Direct_Physical
#define RE_Direct_RectArea RE_Direct_RectArea_Physical
#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical
#define RE_IndirectSpecular RE_IndirectSpecular_Physical
float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
}`,SE=`
GeometricContext geometry;
geometry.position = - vViewPosition;
geometry.normal = normal;
geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
#ifdef CLEARCOAT
geometry.clearcoatNormal = clearcoatNormal;
#endif
IncidentLight directLight;
#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
PointLight pointLight;
#pragma unroll_loop
for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
pointLight = pointLights[ i ];
getPointDirectLightIrradiance( pointLight, geometry, directLight );
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
directLight.color *= all( bvec3( pointLight.shadow, directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
#endif
RE_Direct( directLight, geometry, material, reflectedLight );
}
#endif
#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
SpotLight spotLight;
#pragma unroll_loop
for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
spotLight = spotLights[ i ];
getSpotDirectLightIrradiance( spotLight, geometry, directLight );
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
directLight.color *= all( bvec3( spotLight.shadow, directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
#endif
RE_Direct( directLight, geometry, material, reflectedLight );
}
#endif
#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
DirectionalLight directionalLight;
#pragma unroll_loop
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
directionalLight = directionalLights[ i ];
getDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
directLight.color *= all( bvec3( directionalLight.shadow, directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
#endif
RE_Direct( directLight, geometry, material, reflectedLight );
}
#endif
#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
RectAreaLight rectAreaLight;
#pragma unroll_loop
for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
rectAreaLight = rectAreaLights[ i ];
RE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );
}
#endif
#if defined( RE_IndirectDiffuse )
vec3 iblIrradiance = vec3( 0.0 );
vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
irradiance += getLightProbeIrradiance( lightProbe, geometry );
#if ( NUM_HEMI_LIGHTS > 0 )
#pragma unroll_loop
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );
}
#endif
#endif
#if defined( RE_IndirectSpecular )
vec3 radiance = vec3( 0.0 );
vec3 clearcoatRadiance = vec3( 0.0 );
#endif`,AE=`#if defined( RE_IndirectDiffuse )
#ifdef USE_LIGHTMAP
vec4 lightMapTexel= texture2D( lightMap, vUv2 );
vec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;
#ifndef PHYSICALLY_CORRECT_LIGHTS
lightMapIrradiance *= PI;
#endif
irradiance += lightMapIrradiance;
#endif
#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
iblIrradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );
#endif
#endif
#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
radiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, material.specularRoughness, maxMipLevel );
#ifdef CLEARCOAT
clearcoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness, maxMipLevel );
#endif
#endif`,CE=`#if defined( RE_IndirectDiffuse )
RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );
#endif
#if defined( RE_IndirectSpecular )
RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );
#endif`,PE=`#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )
gl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
#endif`,LE=`#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )
uniform float logDepthBufFC;
varying float vFragDepth;
varying float vIsPerspective;
#endif`,DE=`#ifdef USE_LOGDEPTHBUF
#ifdef USE_LOGDEPTHBUF_EXT
varying float vFragDepth;
varying float vIsPerspective;
#else
uniform float logDepthBufFC;
#endif
#endif`,IE=`#ifdef USE_LOGDEPTHBUF
#ifdef USE_LOGDEPTHBUF_EXT
vFragDepth = 1.0 + gl_Position.w;
vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
#else
if ( isPerspectiveMatrix( projectionMatrix ) ) {
gl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;
gl_Position.z *= gl_Position.w;
}
#endif
#endif`,RE=`#ifdef USE_MAP
vec4 texelColor = texture2D( map, vUv );
texelColor = mapTexelToLinear( texelColor );
diffuseColor *= texelColor;
#endif`,zE=`#ifdef USE_MAP
uniform sampler2D map;
#endif`,kE=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
#endif
#ifdef USE_MAP
vec4 mapTexel = texture2D( map, uv );
diffuseColor *= mapTexelToLinear( mapTexel );
#endif
#ifdef USE_ALPHAMAP
diffuseColor.a *= texture2D( alphaMap, uv ).g;
#endif`,BE=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
uniform mat3 uvTransform;
#endif
#ifdef USE_MAP
uniform sampler2D map;
#endif
#ifdef USE_ALPHAMAP
uniform sampler2D alphaMap;
#endif`,FE=`float metalnessFactor = metalness;
#ifdef USE_METALNESSMAP
vec4 texelMetalness = texture2D( metalnessMap, vUv );
metalnessFactor *= texelMetalness.b;
#endif`,OE=`#ifdef USE_METALNESSMAP
uniform sampler2D metalnessMap;
#endif`,NE=`#ifdef USE_MORPHNORMALS
objectNormal *= morphTargetBaseInfluence;
objectNormal += morphNormal0 * morphTargetInfluences[ 0 ];
objectNormal += morphNormal1 * morphTargetInfluences[ 1 ];
objectNormal += morphNormal2 * morphTargetInfluences[ 2 ];
objectNormal += morphNormal3 * morphTargetInfluences[ 3 ];
#endif`,UE=`#ifdef USE_MORPHTARGETS
uniform float morphTargetBaseInfluence;
#ifndef USE_MORPHNORMALS
uniform float morphTargetInfluences[ 8 ];
#else
uniform float morphTargetInfluences[ 4 ];
#endif
#endif`,VE=`#ifdef USE_MORPHTARGETS
transformed *= morphTargetBaseInfluence;
transformed += morphTarget0 * morphTargetInfluences[ 0 ];
transformed += morphTarget1 * morphTargetInfluences[ 1 ];
transformed += morphTarget2 * morphTargetInfluences[ 2 ];
transformed += morphTarget3 * morphTargetInfluences[ 3 ];
#ifndef USE_MORPHNORMALS
transformed += morphTarget4 * morphTargetInfluences[ 4 ];
transformed += morphTarget5 * morphTargetInfluences[ 5 ];
transformed += morphTarget6 * morphTargetInfluences[ 6 ];
transformed += morphTarget7 * morphTargetInfluences[ 7 ];
#endif
#endif`,GE=`#ifdef FLAT_SHADED
vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );
vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
vec3 normal = normalize( cross( fdx, fdy ) );
#else
vec3 normal = normalize( vNormal );
#ifdef DOUBLE_SIDED
normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
#endif
#ifdef USE_TANGENT
vec3 tangent = normalize( vTangent );
vec3 bitangent = normalize( vBitangent );
#ifdef DOUBLE_SIDED
tangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
bitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
#endif
#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )
mat3 vTBN = mat3( tangent, bitangent, normal );
#endif
#endif
#endif
vec3 geometryNormal = normal;`,HE=`#ifdef OBJECTSPACE_NORMALMAP
normal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
#ifdef FLIP_SIDED
normal = - normal;
#endif
#ifdef DOUBLE_SIDED
normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
#endif
normal = normalize( normalMatrix * normal );
#elif defined( TANGENTSPACE_NORMALMAP )
vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
mapN.xy *= normalScale;
#ifdef USE_TANGENT
normal = normalize( vTBN * mapN );
#else
normal = perturbNormal2Arb( -vViewPosition, normal, mapN );
#endif
#elif defined( USE_BUMPMAP )
normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );
#endif`,WE=`#ifdef USE_NORMALMAP
uniform sampler2D normalMap;
uniform vec2 normalScale;
#endif
#ifdef OBJECTSPACE_NORMALMAP
uniform mat3 normalMatrix;
#endif
#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )
vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {
vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
vec2 st0 = dFdx( vUv.st );
vec2 st1 = dFdy( vUv.st );
float scale = sign( st1.t * st0.s - st0.t * st1.s );
vec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );
vec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );
vec3 N = normalize( surf_norm );
mat3 tsn = mat3( S, T, N );
mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
return normalize( tsn * mapN );
}
#endif`,jE=`#ifdef CLEARCOAT
vec3 clearcoatNormal = geometryNormal;
#endif`,qE=`#ifdef USE_CLEARCOAT_NORMALMAP
vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;
clearcoatMapN.xy *= clearcoatNormalScale;
#ifdef USE_TANGENT
clearcoatNormal = normalize( vTBN * clearcoatMapN );
#else
clearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN );
#endif
#endif`,ZE=`#ifdef USE_CLEARCOAT_NORMALMAP
uniform sampler2D clearcoatNormalMap;
uniform vec2 clearcoatNormalScale;
#endif`,XE=`vec3 packNormalToRGB( const in vec3 normal ) {
return normalize( normal ) * 0.5 + 0.5;
}
vec3 unpackRGBToNormal( const in vec3 rgb ) {
return 2.0 * rgb.xyz - 1.0;
}
const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;
const vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );
const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );
const float ShiftRight8 = 1. / 256.;
vec4 packDepthToRGBA( const in float v ) {
vec4 r = vec4( fract( v * PackFactors ), v );
r.yzw -= r.xyz * ShiftRight8; return r * PackUpscale;
}
float unpackRGBAToDepth( const in vec4 v ) {
return dot( v, UnpackFactors );
}
vec4 pack2HalfToRGBA( vec2 v ) {
vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));
return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);
}
vec2 unpackRGBATo2Half( vec4 v ) {
return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
}
float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
return ( viewZ + near ) / ( near - far );
}
float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {
return linearClipZ * ( near - far ) - near;
}
float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
return (( near + viewZ ) * far ) / (( far - near ) * viewZ );
}
float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {
return ( near * far ) / ( ( far - near ) * invClipZ - far );
}`,YE=`#ifdef PREMULTIPLIED_ALPHA
gl_FragColor.rgb *= gl_FragColor.a;
#endif`,$E=`vec4 mvPosition = vec4( transformed, 1.0 );
#ifdef USE_INSTANCING
mvPosition = instanceMatrix * mvPosition;
#endif
mvPosition = modelViewMatrix * mvPosition;
gl_Position = projectionMatrix * mvPosition;`,JE=`#ifdef DITHERING
gl_FragColor.rgb = dithering( gl_FragColor.rgb );
#endif`,KE=`#ifdef DITHERING
vec3 dithering( vec3 color ) {
float grid_position = rand( gl_FragCoord.xy );
vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
return color + dither_shift_RGB;
}
#endif`,QE=`float roughnessFactor = roughness;
#ifdef USE_ROUGHNESSMAP
vec4 texelRoughness = texture2D( roughnessMap, vUv );
roughnessFactor *= texelRoughness.g;
#endif`,eS=`#ifdef USE_ROUGHNESSMAP
uniform sampler2D roughnessMap;
#endif`,tS=`#ifdef USE_SHADOWMAP
#if NUM_DIR_LIGHT_SHADOWS > 0
uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
#endif
#if NUM_SPOT_LIGHT_SHADOWS > 0
uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];
#endif
#if NUM_POINT_LIGHT_SHADOWS > 0
uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
#endif
float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
}
vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {
return unpackRGBATo2Half( texture2D( shadow, uv ) );
}
float VSMShadow (sampler2D shadow, vec2 uv, float compare ){
float occlusion = 1.0;
vec2 distribution = texture2DDistribution( shadow, uv );
float hard_shadow = step( compare , distribution.x );
if (hard_shadow != 1.0 ) {
float distance = compare - distribution.x ;
float variance = max( 0.00000, distribution.y * distribution.y );
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 );
}
return occlusion;
}
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
float shadow = 1.0;
shadowCoord.xyz /= shadowCoord.w;
shadowCoord.z += shadowBias;
bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );
bool inFrustum = all( inFrustumVec );
bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );
bool frustumTest = all( frustumTestVec );
if ( frustumTest ) {
#if defined( SHADOWMAP_TYPE_PCF )
vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
float dx0 = - texelSize.x * shadowRadius;
float dy0 = - texelSize.y * shadowRadius;
float dx1 = + texelSize.x * shadowRadius;
float dy1 = + texelSize.y * shadowRadius;
float dx2 = dx0 / 2.0;
float dy2 = dy0 / 2.0;
float dx3 = dx1 / 2.0;
float dy3 = dy1 / 2.0;
shadow = (
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +
texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )
) * ( 1.0 / 17.0 );
#elif defined( SHADOWMAP_TYPE_PCF_SOFT )
vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
float dx = texelSize.x;
float dy = texelSize.y;
vec2 uv = shadowCoord.xy;
vec2 f = fract( uv * shadowMapSize + 0.5 );
uv -= f * texelSize;
shadow = (
texture2DCompare( shadowMap, uv, shadowCoord.z ) +
texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
f.x ) +
mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
f.x ) +
mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
f.y ) +
mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
f.y ) +
mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
f.x ),
mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),
texture2DCompare( shadowMap, uv + + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
f.x ),
f.y )
) * ( 1.0 / 9.0 );
#elif defined( SHADOWMAP_TYPE_VSM )
shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );
#else
shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );
#endif
}
return shadow;
}
vec2 cubeToUV( vec3 v, float texelSizeY ) {
vec3 absV = abs( v );
float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );
absV *= scaleToCube;
v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );
vec2 planar = v.xy;
float almostATexel = 1.5 * texelSizeY;
float almostOne = 1.0 - almostATexel;
if ( absV.z >= almostOne ) {
if ( v.z > 0.0 )
planar.x = 4.0 - v.x;
} else if ( absV.x >= almostOne ) {
float signX = sign( v.x );
planar.x = v.z * signX + 2.0 * signX;
} else if ( absV.y >= almostOne ) {
float signY = sign( v.y );
planar.x = v.x + 2.0 * signY + 2.0;
planar.y = v.z * signY - 2.0;
}
return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );
}
float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
vec3 lightToPosition = shadowCoord.xyz;
float dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias;
vec3 bd3D = normalize( lightToPosition );
#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
return (
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
) * ( 1.0 / 9.0 );
#else
return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
#endif
}
#endif`,nS=`#ifdef USE_SHADOWMAP
#if NUM_DIR_LIGHT_SHADOWS > 0
uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
#endif
#if NUM_SPOT_LIGHT_SHADOWS > 0
uniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];
varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];
#endif
#if NUM_POINT_LIGHT_SHADOWS > 0
uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
#endif
#endif`,iS=`#ifdef USE_SHADOWMAP
#if NUM_DIR_LIGHT_SHADOWS > 0
#pragma unroll_loop
for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;
}
#endif
#if NUM_SPOT_LIGHT_SHADOWS > 0
#pragma unroll_loop
for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
vSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;
}
#endif
#if NUM_POINT_LIGHT_SHADOWS > 0
#pragma unroll_loop
for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;
}
#endif
#endif`,rS=`float getShadowMask() {
float shadow = 1.0;
#ifdef USE_SHADOWMAP
#if NUM_DIR_LIGHT_SHADOWS > 0
DirectionalLight directionalLight;
#pragma unroll_loop
for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
directionalLight = directionalLights[ i ];
shadow *= all( bvec2( directionalLight.shadow, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
}
#endif
#if NUM_SPOT_LIGHT_SHADOWS > 0
SpotLight spotLight;
#pragma unroll_loop
for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
spotLight = spotLights[ i ];
shadow *= all( bvec2( spotLight.shadow, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
}
#endif
#if NUM_POINT_LIGHT_SHADOWS > 0
PointLight pointLight;
#pragma unroll_loop
for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
pointLight = pointLights[ i ];
shadow *= all( bvec2( pointLight.shadow, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
}
#endif
#endif
return shadow;
}`,aS=`#ifdef USE_SKINNING
mat4 boneMatX = getBoneMatrix( skinIndex.x );
mat4 boneMatY = getBoneMatrix( skinIndex.y );
mat4 boneMatZ = getBoneMatrix( skinIndex.z );
mat4 boneMatW = getBoneMatrix( skinIndex.w );
#endif`,oS=`#ifdef USE_SKINNING
uniform mat4 bindMatrix;
uniform mat4 bindMatrixInverse;
#ifdef BONE_TEXTURE
uniform highp sampler2D boneTexture;
uniform int boneTextureSize;
mat4 getBoneMatrix( const in float i ) {
float j = i * 4.0;
float x = mod( j, float( boneTextureSize ) );
float y = floor( j / float( boneTextureSize ) );
float dx = 1.0 / float( boneTextureSize );
float dy = 1.0 / float( boneTextureSize );
y = dy * ( y + 0.5 );
vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );
vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );
vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );
vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );
mat4 bone = mat4( v1, v2, v3, v4 );
return bone;
}
#else
uniform mat4 boneMatrices[ MAX_BONES ];
mat4 getBoneMatrix( const in float i ) {
mat4 bone = boneMatrices[ int(i) ];
return bone;
}
#endif
#endif`,sS=`#ifdef USE_SKINNING
vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
vec4 skinned = vec4( 0.0 );
skinned += boneMatX * skinVertex * skinWeight.x;
skinned += boneMatY * skinVertex * skinWeight.y;
skinned += boneMatZ * skinVertex * skinWeight.z;
skinned += boneMatW * skinVertex * skinWeight.w;
transformed = ( bindMatrixInverse * skinned ).xyz;
#endif`,lS=`#ifdef USE_SKINNING
mat4 skinMatrix = mat4( 0.0 );
skinMatrix += skinWeight.x * boneMatX;
skinMatrix += skinWeight.y * boneMatY;
skinMatrix += skinWeight.z * boneMatZ;
skinMatrix += skinWeight.w * boneMatW;
skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
#ifdef USE_TANGENT
objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
#endif
#endif`,cS=`float specularStrength;
#ifdef USE_SPECULARMAP
vec4 texelSpecular = texture2D( specularMap, vUv );
specularStrength = texelSpecular.r;
#else
specularStrength = 1.0;
#endif`,uS=`#ifdef USE_SPECULARMAP
uniform sampler2D specularMap;
#endif`,hS=`#if defined( TONE_MAPPING )
gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
#endif`,dS=`#ifndef saturate
#define saturate(a) clamp( a, 0.0, 1.0 )
#endif
uniform float toneMappingExposure;
uniform float toneMappingWhitePoint;
vec3 LinearToneMapping( vec3 color ) {
return toneMappingExposure * color;
}
vec3 ReinhardToneMapping( vec3 color ) {
color *= toneMappingExposure;
return saturate( color / ( vec3( 1.0 ) + color ) );
}
#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )
vec3 Uncharted2ToneMapping( vec3 color ) {
color *= toneMappingExposure;
return saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );
}
vec3 OptimizedCineonToneMapping( vec3 color ) {
color *= toneMappingExposure;
color = max( vec3( 0.0 ), color - 0.004 );
return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
}
vec3 ACESFilmicToneMapping( vec3 color ) {
color *= toneMappingExposure;
return saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );
}`,pS=`#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )
varying vec2 vUv;
#endif`,fS=`#ifdef USE_UV
#ifdef UVS_VERTEX_ONLY
vec2 vUv;
#else
varying vec2 vUv;
#endif
uniform mat3 uvTransform;
#endif`,mS=`#ifdef USE_UV
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
#endif`,gS=`#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
varying vec2 vUv2;
#endif`,_S=`#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
attribute vec2 uv2;
varying vec2 vUv2;
uniform mat3 uv2Transform;
#endif`,yS=`#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
vUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;
#endif`,vS=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )
vec4 worldPosition = vec4( transformed, 1.0 );
#ifdef USE_INSTANCING
worldPosition = instanceMatrix * worldPosition;
#endif
worldPosition = modelMatrix * worldPosition;
#endif`,xS=`uniform sampler2D t2D;
varying vec2 vUv;
void main() {
vec4 texColor = texture2D( t2D, vUv );
gl_FragColor = mapTexelToLinear( texColor );
#include
#include
}`,bS=`varying vec2 vUv;
uniform mat3 uvTransform;
void main() {
vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
gl_Position = vec4( position.xy, 1.0, 1.0 );
}`,wS=`#include
uniform float opacity;
varying vec3 vWorldDirection;
#include
void main() {
vec3 vReflect = vWorldDirection;
#include
gl_FragColor = envColor;
gl_FragColor.a *= opacity;
#include
#include
}`,MS=`varying vec3 vWorldDirection;
#include
void main() {
vWorldDirection = transformDirection( position, modelMatrix );
#include
#include
gl_Position.z = gl_Position.w;
}`,TS=`#if DEPTH_PACKING == 3200
uniform float opacity;
#endif
#include
#include
#include
#include
#include
#include
#include
void main() {
#include
vec4 diffuseColor = vec4( 1.0 );
#if DEPTH_PACKING == 3200
diffuseColor.a = opacity;
#endif
#include
#include
#include
#include
#if DEPTH_PACKING == 3200
gl_FragColor = vec4( vec3( 1.0 - gl_FragCoord.z ), opacity );
#elif DEPTH_PACKING == 3201
gl_FragColor = packDepthToRGBA( gl_FragCoord.z );
#endif
}`,ES=`#include
#include
#include
#include
#include
#include
#include
void main() {
#include
#include
#ifdef USE_DISPLACEMENTMAP
#include
#include
#include
#endif
#include
#include
#include
#include
#include
#include
#include
}`,SS=`#define DISTANCE
uniform vec3 referencePosition;
uniform float nearDistance;
uniform float farDistance;
varying vec3 vWorldPosition;
#include
#include
#include
#include
#include
#include
void main () {
#include
vec4 diffuseColor = vec4( 1.0 );
#include
#include
#include
float dist = length( vWorldPosition - referencePosition );
dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
dist = saturate( dist );
gl_FragColor = packDepthToRGBA( dist );
}`,AS=`#define DISTANCE
varying vec3 vWorldPosition;
#include
#include
#include
#include
#include
#include
void main() {
#include
#include
#ifdef USE_DISPLACEMENTMAP
#include
#include
#include
#endif
#include
#include
#include
#include
#include
#include
#include
vWorldPosition = worldPosition.xyz;
}`,CS=`uniform sampler2D tEquirect;
varying vec3 vWorldDirection;
#include
void main() {
vec3 direction = normalize( vWorldDirection );
vec2 sampleUV;
sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;
vec4 texColor = texture2D( tEquirect, sampleUV );
gl_FragColor = mapTexelToLinear( texColor );
#include
#include
}`,PS=`varying vec3 vWorldDirection;
#include
void main() {
vWorldDirection = transformDirection( position, modelMatrix );
#include
#include
}`,LS=`uniform vec3 diffuse;
uniform float opacity;
uniform float dashSize;
uniform float totalSize;
varying float vLineDistance;
#include
#include
#include
#include
#include
void main() {
#include
if ( mod( vLineDistance, totalSize ) > dashSize ) {
discard;
}
vec3 outgoingLight = vec3( 0.0 );
vec4 diffuseColor = vec4( diffuse, opacity );
#include
#include
outgoingLight = diffuseColor.rgb;
gl_FragColor = vec4( outgoingLight, diffuseColor.a );
#include
#include
#include
#include
}`,DS=`uniform float scale;
attribute float lineDistance;
varying float vLineDistance;
#include
#include
#include
#include
#include
void main() {
#include
vLineDistance = scale * lineDistance;
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
gl_Position = projectionMatrix * mvPosition;
#include
#include
#include
}`,IS=`uniform vec3 diffuse;
uniform float opacity;
#ifndef FLAT_SHADED
varying vec3 vNormal;
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
void main() {
#include
vec4 diffuseColor = vec4( diffuse, opacity );
#include
#include
#include
#include
#include
#include
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
#ifdef USE_LIGHTMAP
vec4 lightMapTexel= texture2D( lightMap, vUv2 );
reflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;
#else
reflectedLight.indirectDiffuse += vec3( 1.0 );
#endif
#include
reflectedLight.indirectDiffuse *= diffuseColor.rgb;
vec3 outgoingLight = reflectedLight.indirectDiffuse;
#include
gl_FragColor = vec4( outgoingLight, diffuseColor.a );
#include
#include
#include
#include
}`,RS=`#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
void main() {
#include
#include
#include
#include
#ifdef USE_ENVMAP
#include
#include
#include
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
}`,zS=`uniform vec3 diffuse;
uniform vec3 emissive;
uniform float opacity;
varying vec3 vLightFront;
varying vec3 vIndirectFront;
#ifdef DOUBLE_SIDED
varying vec3 vLightBack;
varying vec3 vIndirectBack;
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
void main() {
#include
vec4 diffuseColor = vec4( diffuse, opacity );
ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
vec3 totalEmissiveRadiance = emissive;
#include
#include
#include
#include
#include
#include
#include
reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );
#ifdef DOUBLE_SIDED
reflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;
#else
reflectedLight.indirectDiffuse += vIndirectFront;
#endif
#include
reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );
#ifdef DOUBLE_SIDED
reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;
#else
reflectedLight.directDiffuse = vLightFront;
#endif
reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();
#include
vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
#include
gl_FragColor = vec4( outgoingLight, diffuseColor.a );
#include
#include
#include
#include
#include
}`,kS=`#define LAMBERT
varying vec3 vLightFront;
varying vec3 vIndirectFront;
#ifdef DOUBLE_SIDED
varying vec3 vLightBack;
varying vec3 vIndirectBack;
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
void main() {
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include