0&&(m[t]=j,E=!0)}E&&(A.data.morphAttributes=m,A.data.morphTargetsRelative=this.morphTargetsRelative);const G=this.groups;G.length>0&&(A.data.groups=JSON.parse(JSON.stringify(G)));const C=this.boundingSphere;return C!==null&&(A.data.boundingSphere={center:C.center.toArray(),radius:C.radius}),A}clone(){return new this.constructor().copy(this)}copy(A){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const n={};this.name=A.name;const i=A.index;i!==null&&this.setIndex(i.clone(n));const m=A.attributes;for(const I in m){const j=m[I];this.setAttribute(I,j.clone(n))}const E=A.morphAttributes;for(const I in E){const j=[],H=E[I];for(let h=0,p=H.length;h0){const m=n[i[0]];if(m!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let E=0,G=m.length;E(A.far-A.near)**2))&&(rs.copy(E).invert(),Be.copy(A.ray).applyMatrix4(rs),!(i.boundingBox!==null&&Be.intersectsBox(i.boundingBox)===!1)&&this._computeIntersections(A,n,Be)))}_computeIntersections(A,n,i){let m;const E=this.geometry,G=this.material,C=E.index,t=E.attributes.position,I=E.attributes.uv,j=E.attributes.uv1,H=E.attributes.normal,h=E.groups,p=E.drawRange;if(C!==null)if(Array.isArray(G))for(let B=0,J=h.length;Bn.far?null:{distance:I,point:bI.clone(),object:o}}function UI(o,A,n,i,m,E,G,C,t,I){o.getVertexPosition(C,RI),o.getVertexPosition(t,yI),o.getVertexPosition(I,OI);const j=rK(o,A,n,i,RI,yI,OI,gs);if(j){const H=new _;gl.getBarycoord(gs,RI,yI,OI,H),m&&(j.uv=gl.getInterpolatedAttribute(m,C,t,I,H,new kn)),E&&(j.uv1=gl.getInterpolatedAttribute(E,C,t,I,H,new kn)),G&&(j.normal=gl.getInterpolatedAttribute(G,C,t,I,H,new _),j.normal.dot(i.direction)>0&&j.normal.multiplyScalar(-1));const h={a:C,b:t,c:I,normal:new _,materialIndex:0};gl.getNormal(RI,yI,OI,h.normal),j.face=h,j.barycoord=H}return j}class _e extends ci{constructor(A=1,n=1,i=1,m=1,E=1,G=1){super(),this.type="BoxGeometry",this.parameters={width:A,height:n,depth:i,widthSegments:m,heightSegments:E,depthSegments:G};const C=this;m=Math.floor(m),E=Math.floor(E),G=Math.floor(G);const t=[],I=[],j=[],H=[];let h=0,p=0;B("z","y","x",-1,-1,i,n,A,G,E,0),B("z","y","x",1,-1,i,n,-A,G,E,1),B("x","z","y",1,1,A,i,n,m,G,2),B("x","z","y",1,-1,A,i,-n,m,G,3),B("x","y","z",1,-1,A,n,i,m,E,4),B("x","y","z",-1,-1,A,n,-i,m,E,5),this.setIndex(t),this.setAttribute("position",new _n(I,3)),this.setAttribute("normal",new _n(j,3)),this.setAttribute("uv",new _n(H,2));function B(J,u,s,K,d,v,O,x,b,Q,P){const T=v/b,W=O/Q,sA=v/2,pA=O/2,LA=x/2,fA=b+1,iA=Q+1;let M=0,Y=0;const FA=new _;for(let GA=0;GA0?1:-1,j.push(FA.x,FA.y,FA.z),H.push(IA/b),H.push(1-GA/Q),M+=1}}for(let GA=0;GA0&&(n.defines=this.defines),n.vertexShader=this.vertexShader,n.fragmentShader=this.fragmentShader,n.lights=this.lights,n.clipping=this.clipping;const i={};for(const m in this.extensions)this.extensions[m]===!0&&(i[m]=!0);return Object.keys(i).length>0&&(n.extensions=i),n}}class JD extends Li{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Ei,this.projectionMatrix=new Ei,this.projectionMatrixInverse=new Ei,this.coordinateSystem=sE}copy(A,n){return super.copy(A,n),this.matrixWorldInverse.copy(A.matrixWorldInverse),this.projectionMatrix.copy(A.projectionMatrix),this.projectionMatrixInverse.copy(A.projectionMatrixInverse),this.coordinateSystem=A.coordinateSystem,this}getWorldDirection(A){return super.getWorldDirection(A).negate()}updateMatrixWorld(A){super.updateMatrixWorld(A),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(A,n){super.updateWorldMatrix(A,n),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}}const JG=new _,ps=new kn,ss=new kn;class Co extends JD{constructor(A=50,n=1,i=.1,m=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=A,this.zoom=1,this.near=i,this.far=m,this.focus=10,this.aspect=n,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(A,n){return super.copy(A,n),this.fov=A.fov,this.zoom=A.zoom,this.near=A.near,this.far=A.far,this.focus=A.focus,this.aspect=A.aspect,this.view=A.view===null?null:Object.assign({},A.view),this.filmGauge=A.filmGauge,this.filmOffset=A.filmOffset,this}setFocalLength(A){const n=.5*this.getFilmHeight()/A;this.fov=sF*2*Math.atan(n),this.updateProjectionMatrix()}getFocalLength(){const A=Math.tan(be*.5*this.fov);return .5*this.getFilmHeight()/A}getEffectiveFOV(){return sF*2*Math.atan(Math.tan(be*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(A,n,i){JG.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(JG.x,JG.y).multiplyScalar(-A/JG.z),JG.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),i.set(JG.x,JG.y).multiplyScalar(-A/JG.z)}getViewSize(A,n){return this.getViewBounds(A,ps,ss),n.subVectors(ss,ps)}setViewOffset(A,n,i,m,E,G){this.aspect=A/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=A,this.view.fullHeight=n,this.view.offsetX=i,this.view.offsetY=m,this.view.width=E,this.view.height=G,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const A=this.near;let n=A*Math.tan(be*.5*this.fov)/this.zoom,i=2*n,m=this.aspect*i,E=-.5*m;const G=this.view;if(this.view!==null&&this.view.enabled){const t=G.fullWidth,I=G.fullHeight;E+=G.offsetX*m/t,n-=G.offsetY*i/I,m*=G.width/t,i*=G.height/I}const C=this.filmOffset;C!==0&&(E+=A*C/this.getFilmWidth()),this.projectionMatrix.makePerspective(E,E+m,n,n-i,A,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(A){const n=super.toJSON(A);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}}const AF=-90,nF=1;class uu extends Li{constructor(A,n,i){super(),this.type="CubeCamera",this.renderTarget=i,this.coordinateSystem=null,this.activeMipmapLevel=0;const m=new Co(AF,nF,A,n);m.layers=this.layers,this.add(m);const E=new Co(AF,nF,A,n);E.layers=this.layers,this.add(E);const G=new Co(AF,nF,A,n);G.layers=this.layers,this.add(G);const C=new Co(AF,nF,A,n);C.layers=this.layers,this.add(C);const t=new Co(AF,nF,A,n);t.layers=this.layers,this.add(t);const I=new Co(AF,nF,A,n);I.layers=this.layers,this.add(I)}updateCoordinateSystem(){const A=this.coordinateSystem,n=this.children.concat(),[i,m,E,G,C,t]=n;for(const I of n)this.remove(I);if(A===sE)i.up.set(0,1,0),i.lookAt(1,0,0),m.up.set(0,1,0),m.lookAt(-1,0,0),E.up.set(0,0,-1),E.lookAt(0,1,0),G.up.set(0,0,1),G.lookAt(0,-1,0),C.up.set(0,1,0),C.lookAt(0,0,1),t.up.set(0,1,0),t.lookAt(0,0,-1);else if(A===eD)i.up.set(0,-1,0),i.lookAt(-1,0,0),m.up.set(0,-1,0),m.lookAt(1,0,0),E.up.set(0,0,1),E.lookAt(0,1,0),G.up.set(0,0,-1),G.lookAt(0,-1,0),C.up.set(0,-1,0),C.lookAt(0,0,1),t.up.set(0,-1,0),t.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+A);for(const I of n)this.add(I),I.updateMatrixWorld()}update(A,n){this.parent===null&&this.updateMatrixWorld();const{renderTarget:i,activeMipmapLevel:m}=this;this.coordinateSystem!==A.coordinateSystem&&(this.coordinateSystem=A.coordinateSystem,this.updateCoordinateSystem());const[E,G,C,t,I,j]=this.children,H=A.getRenderTarget(),h=A.getActiveCubeFace(),p=A.getActiveMipmapLevel(),B=A.xr.enabled;A.xr.enabled=!1;const J=i.texture.generateMipmaps;i.texture.generateMipmaps=!1,A.setRenderTarget(i,0,m),A.render(n,E),A.setRenderTarget(i,1,m),A.render(n,G),A.setRenderTarget(i,2,m),A.render(n,C),A.setRenderTarget(i,3,m),A.render(n,t),A.setRenderTarget(i,4,m),A.render(n,I),i.texture.generateMipmaps=J,A.setRenderTarget(i,5,m),A.render(n,j),A.setRenderTarget(H,h,p),A.xr.enabled=B,i.texture.needsPMREMUpdate=!0}}class qD extends Jm{constructor(A,n,i,m,E,G,C,t,I,j){A=A!==void 0?A:[],n=n!==void 0?n:Ok,super(A,n,i,m,E,G,C,t,I,j),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(A){this.image=A}}class cu extends wE{constructor(A=1,n={}){super(A,A,n),this.isWebGLCubeRenderTarget=!0;const i={width:A,height:A,depth:1},m=[i,i,i,i,i,i];this.texture=new qD(m,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=n.generateMipmaps!==void 0?n.generateMipmaps:!1,this.texture.minFilter=n.minFilter!==void 0?n.minFilter:zm}fromEquirectangularTexture(A,n){this.texture.type=n.type,this.texture.colorSpace=n.colorSpace,this.texture.generateMipmaps=n.generateMipmaps,this.texture.minFilter=n.minFilter,this.texture.magFilter=n.magFilter;const i={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
+
+ }
+ `,fragmentShader:`
+
+ uniform sampler2D tEquirect;
+
+ varying vec3 vWorldDirection;
+
+ #include
+
+ void main() {
+
+ vec3 direction = normalize( vWorldDirection );
+
+ vec2 sampleUV = equirectUv( direction );
+
+ gl_FragColor = texture2D( tEquirect, sampleUV );
+
+ }
+ `},m=new _e(5,5,5),E=new aE({name:"CubemapFromEquirect",uniforms:BF(i.uniforms),vertexShader:i.vertexShader,fragmentShader:i.fragmentShader,side:$o,blending:Pk});E.uniforms.tEquirect.value=n;const G=new Lm(m,E),C=n.minFilter;return n.minFilter===yE&&(n.minFilter=zm),new uu(1,10,this).update(A,G),n.minFilter=C,G.geometry.dispose(),G.material.dispose(),this}clear(A,n,i,m){const E=A.getRenderTarget();for(let G=0;G<6;G++)A.setRenderTarget(this,G),A.clear(n,i,m);A.setRenderTarget(E)}}class NH{constructor(A,n=25e-5){this.isFogExp2=!0,this.name="",this.color=new bn(A),this.density=n}clone(){return new NH(this.color,this.density)}toJSON(){return{type:"FogExp2",name:this.name,color:this.color.getHex(),density:this.density}}}class TH{constructor(A,n=1,i=1e3){this.isFog=!0,this.name="",this.color=new bn(A),this.near=n,this.far=i}clone(){return new TH(this.color,this.near,this.far)}toJSON(){return{type:"Fog",name:this.name,color:this.color.getHex(),near:this.near,far:this.far}}}class Sg extends Li{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new To,this.environmentIntensity=1,this.environmentRotation=new To,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(A,n){return super.copy(A,n),A.background!==null&&(this.background=A.background.clone()),A.environment!==null&&(this.environment=A.environment.clone()),A.fog!==null&&(this.fog=A.fog.clone()),this.backgroundBlurriness=A.backgroundBlurriness,this.backgroundIntensity=A.backgroundIntensity,this.backgroundRotation.copy(A.backgroundRotation),this.environmentIntensity=A.environmentIntensity,this.environmentRotation.copy(A.environmentRotation),A.overrideMaterial!==null&&(this.overrideMaterial=A.overrideMaterial.clone()),this.matrixAutoUpdate=A.matrixAutoUpdate,this}toJSON(A){const n=super.toJSON(A);return this.fog!==null&&(n.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(n.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(n.object.backgroundIntensity=this.backgroundIntensity),n.object.backgroundRotation=this.backgroundRotation.toArray(),this.environmentIntensity!==1&&(n.object.environmentIntensity=this.environmentIntensity),n.object.environmentRotation=this.environmentRotation.toArray(),n}}class PH{constructor(A,n){this.isInterleavedBuffer=!0,this.array=A,this.stride=n,this.count=A!==void 0?A.length/n:0,this.usage=GD,this.updateRanges=[],this.version=0,this.uuid=Sl()}onUploadCallback(){}set needsUpdate(A){A===!0&&this.version++}setUsage(A){return this.usage=A,this}addUpdateRange(A,n){this.updateRanges.push({start:A,count:n})}clearUpdateRanges(){this.updateRanges.length=0}copy(A){return this.array=new A.array.constructor(A.array),this.count=A.count,this.stride=A.stride,this.usage=A.usage,this}copyAt(A,n,i){A*=this.stride,i*=n.stride;for(let m=0,E=this.stride;mA.far||n.push({distance:t,point:Mt.clone(),uv:gl.getInterpolation(Mt,wI,vt,VI,Bs,kh,as,new kn),face:null,object:this})}copy(A,n){return super.copy(A,n),A.center!==void 0&&this.center.copy(A.center),this.material=A.material,this}};function QI(o,A,n,i,m,E){lF.subVectors(o,n).addScalar(.5).multiply(i),m!==void 0?(Lt.x=E*lF.x-m*lF.y,Lt.y=m*lF.x+E*lF.y):Lt.copy(lF),o.copy(A),o.x+=Lt.x,o.y+=Lt.y,o.applyMatrix4(Ju)}const WI=new _,us=new _;class qu extends Li{constructor(){super(),this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]},isLOD:{value:!0}}),this.autoUpdate=!0}copy(A){super.copy(A,!1);const n=A.levels;for(let i=0,m=n.length;i0){let i,m;for(i=1,m=n.length;i0){WI.setFromMatrixPosition(this.matrixWorld);const m=A.ray.origin.distanceTo(WI);this.getObjectForDistance(m).raycast(A,n)}}update(A){const n=this.levels;if(n.length>1){WI.setFromMatrixPosition(A.matrixWorld),us.setFromMatrixPosition(this.matrixWorld);const i=WI.distanceTo(us)/A.zoom;n[0].object.visible=!0;let m,E;for(m=1,E=n.length;m=G)n[m-1].object.visible=!1,n[m].object.visible=!0;else break}for(this._currentLevel=m-1;m1?null:n.copy(A.start).addScaledVector(i,E)}intersectsLine(A){const n=this.distanceToPoint(A.start),i=this.distanceToPoint(A.end);return n<0&&i>0||i<0&&n>0}intersectsBox(A){return A.intersectsPlane(this)}intersectsSphere(A){return A.intersectsPlane(this)}coplanarPoint(A){return A.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(A,n){const i=n||cK.getNormalMatrix(A),m=this.coplanarPoint(Ch).applyMatrix4(A),E=this.normal.applyMatrix3(i).normalize();return this.constant=-m.dot(E),this}translate(A){return this.constant-=A.dot(this.normal),this}equals(A){return A.normal.equals(this.normal)&&A.constant===this.constant}clone(){return new this.constructor().copy(this)}}const ae=new No,ZI=new _;class fD{constructor(A=new KG,n=new KG,i=new KG,m=new KG,E=new KG,G=new KG){this.planes=[A,n,i,m,E,G]}set(A,n,i,m,E,G){const C=this.planes;return C[0].copy(A),C[1].copy(n),C[2].copy(i),C[3].copy(m),C[4].copy(E),C[5].copy(G),this}copy(A){const n=this.planes;for(let i=0;i<6;i++)n[i].copy(A.planes[i]);return this}setFromProjectionMatrix(A,n=sE){const i=this.planes,m=A.elements,E=m[0],G=m[1],C=m[2],t=m[3],I=m[4],j=m[5],H=m[6],h=m[7],p=m[8],B=m[9],J=m[10],u=m[11],s=m[12],K=m[13],d=m[14],v=m[15];if(i[0].setComponents(t-E,h-I,u-p,v-s).normalize(),i[1].setComponents(t+E,h+I,u+p,v+s).normalize(),i[2].setComponents(t+G,h+j,u+B,v+K).normalize(),i[3].setComponents(t-G,h-j,u-B,v-K).normalize(),i[4].setComponents(t-C,h-H,u-J,v-d).normalize(),n===sE)i[5].setComponents(t+C,h+H,u+J,v+d).normalize();else if(n===eD)i[5].setComponents(C,H,J,d).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+n);return this}intersectsObject(A){if(A.boundingSphere!==void 0)A.boundingSphere===null&&A.computeBoundingSphere(),ae.copy(A.boundingSphere).applyMatrix4(A.matrixWorld);else{const n=A.geometry;n.boundingSphere===null&&n.computeBoundingSphere(),ae.copy(n.boundingSphere).applyMatrix4(A.matrixWorld)}return this.intersectsSphere(ae)}intersectsSprite(A){return ae.center.set(0,0,0),ae.radius=.7071067811865476,ae.applyMatrix4(A.matrixWorld),this.intersectsSphere(ae)}intersectsSphere(A){const n=this.planes,i=A.center,m=-A.radius;for(let E=0;E<6;E++)if(n[E].distanceToPoint(i)0?A.max.x:A.min.x,ZI.y=m.normal.y>0?A.max.y:A.min.y,ZI.z=m.normal.z>0?A.max.z:A.min.z,m.distanceToPoint(ZI)<0)return!1}return!0}containsPoint(A){const n=this.planes;for(let i=0;i<6;i++)if(n[i].distanceToPoint(A)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}function Fh(o,A){return o-A}function JK(o,A){return o.z-A.z}function qK(o,A){return A.z-o.z}class fK{constructor(){this.index=0,this.pool=[],this.list=[]}push(A,n,i,m){const E=this.pool,G=this.list;this.index>=E.length&&E.push({start:-1,count:-1,z:-1,index:-1});const C=E[this.index];G.push(C),this.index++,C.start=A,C.count=n,C.z=i,C.index=m}reset(){this.list.length=0,this.index=0}}const Hl=new Ei,KK=new bn(1,1,1),th=new fD,zI=new Al,ue=new No,Tt=new _,vs=new _,dK=new _,Dh=new fK,vo=new Lm,_I=[];function MK(o,A,n=0){const i=A.itemSize;if(o.isInterleavedBufferAttribute||o.array.constructor!==A.array.constructor){const m=o.count;for(let E=0;E65535?new Uint32Array(m):new Uint16Array(m);n.setIndex(new bi(E,1))}this._geometryInitialized=!0}}_validateGeometry(A){const n=this.geometry;if(!!A.getIndex()!=!!n.getIndex())throw new Error('THREE.BatchedMesh: All geometries must consistently have "index".');for(const i in n.attributes){if(!A.hasAttribute(i))throw new Error(`THREE.BatchedMesh: Added geometry missing "${i}". All geometries must have consistent attributes.`);const m=A.getAttribute(i),E=n.getAttribute(i);if(m.itemSize!==E.itemSize||m.normalized!==E.normalized)throw new Error("THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.")}}validateInstanceId(A){const n=this._instanceInfo;if(A<0||A>=n.length||n[A].active===!1)throw new Error(`THREE.BatchedMesh: Invalid instanceId ${A}. Instance is either out of range or has been deleted.`)}validateGeometryId(A){const n=this._geometryInfo;if(A<0||A>=n.length||n[A].active===!1)throw new Error(`THREE.BatchedMesh: Invalid geometryId ${A}. Geometry is either out of range or has been deleted.`)}setCustomSort(A){return this.customSort=A,this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new Al);const A=this.boundingBox,n=this._instanceInfo;A.makeEmpty();for(let i=0,m=n.length;i=this.maxInstanceCount&&this._availableInstanceIds.length===0)throw new Error("THREE.BatchedMesh: Maximum item count reached.");const i={visible:!0,active:!0,geometryIndex:A};let m=null;this._availableInstanceIds.length>0?(this._availableInstanceIds.sort(Fh),m=this._availableInstanceIds.shift(),this._instanceInfo[m]=i):(m=this._instanceInfo.length,this._instanceInfo.push(i));const E=this._matricesTexture;Hl.identity().toArray(E.image.data,m*16),E.needsUpdate=!0;const G=this._colorsTexture;return G&&(KK.toArray(G.image.data,m*4),G.needsUpdate=!0),this._visibilityChanged=!0,m}addGeometry(A,n=-1,i=-1){this._initializeGeometry(A),this._validateGeometry(A);const m={vertexStart:-1,vertexCount:-1,reservedVertexCount:-1,indexStart:-1,indexCount:-1,reservedIndexCount:-1,start:-1,count:-1,boundingBox:null,boundingSphere:null,active:!0},E=this._geometryInfo;m.vertexStart=this._nextVertexStart,m.reservedVertexCount=n===-1?A.getAttribute("position").count:n;const G=A.getIndex();if(G!==null&&(m.indexStart=this._nextIndexStart,m.reservedIndexCount=i===-1?G.count:i),m.indexStart!==-1&&m.indexStart+m.reservedIndexCount>this._maxIndexCount||m.vertexStart+m.reservedVertexCount>this._maxVertexCount)throw new Error("THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.");let t;return this._availableGeometryIds.length>0?(this._availableGeometryIds.sort(Fh),t=this._availableGeometryIds.shift(),E[t]=m):(t=this._geometryCount,this._geometryCount++,E.push(m)),this.setGeometryAt(t,A),this._nextIndexStart=m.indexStart+m.reservedIndexCount,this._nextVertexStart=m.vertexStart+m.reservedVertexCount,t}setGeometryAt(A,n){if(A>=this._geometryCount)throw new Error("THREE.BatchedMesh: Maximum geometry count reached.");this._validateGeometry(n);const i=this.geometry,m=i.getIndex()!==null,E=i.getIndex(),G=n.getIndex(),C=this._geometryInfo[A];if(m&&G.count>C.reservedIndexCount||n.attributes.position.count>C.reservedVertexCount)throw new Error("THREE.BatchedMesh: Reserved space not large enough for provided geometry.");const t=C.vertexStart,I=C.reservedVertexCount;C.vertexCount=n.getAttribute("position").count;for(const j in i.attributes){const H=n.getAttribute(j),h=i.getAttribute(j);MK(H,h,t);const p=H.itemSize;for(let B=H.count,J=I;B=n.length||n[A].active===!1)return this;const i=this._instanceInfo;for(let m=0,E=i.length;mC).sort((G,C)=>i[G].vertexStart-i[C].vertexStart),E=this.geometry;for(let G=0,C=i.length;G=this._geometryCount)return null;const i=this.geometry,m=this._geometryInfo[A];if(m.boundingBox===null){const E=new Al,G=i.index,C=i.attributes.position;for(let t=m.start,I=m.start+m.count;t=this._geometryCount)return null;const i=this.geometry,m=this._geometryInfo[A];if(m.boundingSphere===null){const E=new No;this.getBoundingBoxAt(A,zI),zI.getCenter(E.center);const G=i.index,C=i.attributes.position;let t=0;for(let I=m.start,j=m.start+m.count;IC.active);if(Math.max(...i.map(C=>C.vertexStart+C.reservedVertexCount))>A)throw new Error(`BatchedMesh: Geometry vertex values are being used outside the range ${n}. Cannot shrink further.`);if(this.geometry.index&&Math.max(...i.map(t=>t.indexStart+t.reservedIndexCount))>n)throw new Error(`BatchedMesh: Geometry index values are being used outside the range ${n}. Cannot shrink further.`);const E=this.geometry;E.dispose(),this._maxVertexCount=A,this._maxIndexCount=n,this._geometryInitialized&&(this._geometryInitialized=!1,this.geometry=new ci,this._initializeGeometry(E));const G=this.geometry;E.index&&ce(E.index.array,G.index.array);for(const C in E.attributes)ce(E.attributes[C].array,G.attributes[C].array)}raycast(A,n){const i=this._instanceInfo,m=this._geometryInfo,E=this.matrixWorld,G=this.geometry;vo.material=this.material,vo.geometry.index=G.index,vo.geometry.attributes=G.attributes,vo.geometry.boundingBox===null&&(vo.geometry.boundingBox=new Al),vo.geometry.boundingSphere===null&&(vo.geometry.boundingSphere=new No);for(let C=0,t=i.length;C({...n,boundingBox:n.boundingBox!==null?n.boundingBox.clone():null,boundingSphere:n.boundingSphere!==null?n.boundingSphere.clone():null})),this._instanceInfo=A._instanceInfo.map(n=>({...n})),this._maxInstanceCount=A._maxInstanceCount,this._maxVertexCount=A._maxVertexCount,this._maxIndexCount=A._maxIndexCount,this._geometryInitialized=A._geometryInitialized,this._geometryCount=A._geometryCount,this._multiDrawCounts=A._multiDrawCounts.slice(),this._multiDrawStarts=A._multiDrawStarts.slice(),this._matricesTexture=A._matricesTexture.clone(),this._matricesTexture.image.data=this._matricesTexture.image.data.slice(),this._colorsTexture!==null&&(this._colorsTexture=A._colorsTexture.clone(),this._colorsTexture.image.data=this._colorsTexture.image.data.slice()),this}dispose(){return this.geometry.dispose(),this._matricesTexture.dispose(),this._matricesTexture=null,this._indirectTexture.dispose(),this._indirectTexture=null,this._colorsTexture!==null&&(this._colorsTexture.dispose(),this._colorsTexture=null),this}onBeforeRender(A,n,i,m,E){if(!this._visibilityChanged&&!this.perObjectFrustumCulled&&!this.sortObjects)return;const G=m.getIndex(),C=G===null?1:G.array.BYTES_PER_ELEMENT,t=this._instanceInfo,I=this._multiDrawStarts,j=this._multiDrawCounts,H=this._geometryInfo,h=this.perObjectFrustumCulled,p=this._indirectTexture,B=p.image.data;h&&(Hl.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse).multiply(this.matrixWorld),th.setFromProjectionMatrix(Hl,A.coordinateSystem));let J=0;if(this.sortObjects){Hl.copy(this.matrixWorld).invert(),Tt.setFromMatrixPosition(i.matrixWorld).applyMatrix4(Hl),vs.set(0,0,-1).transformDirection(i.matrixWorld).transformDirection(Hl);for(let K=0,d=t.length;K0){const m=n[i[0]];if(m!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let E=0,G=m.length;Ei)return;Ih.applyMatrix4(o.matrixWorld);const t=A.ray.origin.distanceTo(Ih);if(!(tA.far))return{distance:t,point:Ns.clone().applyMatrix4(o.matrixWorld),index:m,face:null,faceIndex:null,barycoord:null,object:o}}const Ts=new _,Ps=new _;class WE extends SG{constructor(A,n){super(A,n),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const A=this.geometry;if(A.index===null){const n=A.attributes.position,i=[];for(let m=0,E=n.count;m0){const m=n[i[0]];if(m!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let E=0,G=m.length;Em.far)return;E.push({distance:I,distanceToRay:Math.sqrt(C),point:t,index:A,face:null,faceIndex:null,barycoord:null,object:G})}}class HF extends Li{constructor(){super(),this.isGroup=!0,this.type="Group"}}class LK extends Jm{constructor(A,n,i,m,E,G,C,t,I){super(A,n,i,m,E,G,C,t,I),this.isVideoTexture=!0,this.minFilter=G!==void 0?G:zm,this.magFilter=E!==void 0?E:zm,this.generateMipmaps=!1;const j=this;function H(){j.needsUpdate=!0,A.requestVideoFrameCallback(H)}"requestVideoFrameCallback"in A&&A.requestVideoFrameCallback(H)}clone(){return new this.constructor(this.image).copy(this)}update(){const A=this.image;"requestVideoFrameCallback"in A===!1&&A.readyState>=A.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}class vK extends Jm{constructor(A,n){super({width:A,height:n}),this.isFramebufferTexture=!0,this.magFilter=Bo,this.minFilter=Bo,this.generateMipmaps=!1,this.needsUpdate=!0}}class OH extends Jm{constructor(A,n,i,m,E,G,C,t,I,j,H,h){super(null,G,C,t,I,j,m,E,H,h),this.isCompressedTexture=!0,this.image={width:n,height:i},this.mipmaps=A,this.flipY=!1,this.generateMipmaps=!1}}class SK extends OH{constructor(A,n,i,m,E,G){super(A,n,i,E,G),this.isCompressedArrayTexture=!0,this.image.depth=m,this.wrapR=Vl,this.layerUpdates=new Set}addLayerUpdate(A){this.layerUpdates.add(A)}clearLayerUpdates(){this.layerUpdates.clear()}}class NK extends OH{constructor(A,n,i){super(void 0,A[0].width,A[0].height,n,i,Ok),this.isCompressedCubeTexture=!0,this.isCubeTexture=!0,this.image=A}}class TK extends Jm{constructor(A,n,i,m,E,G,C,t,I){super(A,n,i,m,E,G,C,t,I),this.isCanvasTexture=!0,this.needsUpdate=!0}}class Pg extends Jm{constructor(A,n,i,m,E,G,C,t,I,j=xe){if(j!==xe&&j!==We)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");i===void 0&&j===xe&&(i=xk),i===void 0&&j===We&&(i=Qe),super(null,m,E,G,C,t,j,i,I),this.isDepthTexture=!0,this.image={width:A,height:n},this.magFilter=C!==void 0?C:Bo,this.minFilter=t!==void 0?t:Bo,this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(A){return super.copy(A),this.compareFunction=A.compareFunction,this}toJSON(A){const n=super.toJSON(A);return this.compareFunction!==null&&(n.compareFunction=this.compareFunction),n}}class uE{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return console.warn("THREE.Curve: .getPoint() not implemented."),null}getPointAt(A,n){const i=this.getUtoTmapping(A);return this.getPoint(i,n)}getPoints(A=5){const n=[];for(let i=0;i<=A;i++)n.push(this.getPoint(i/A));return n}getSpacedPoints(A=5){const n=[];for(let i=0;i<=A;i++)n.push(this.getPointAt(i/A));return n}getLength(){const A=this.getLengths();return A[A.length-1]}getLengths(A=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===A+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const n=[];let i,m=this.getPoint(0),E=0;n.push(0);for(let G=1;G<=A;G++)i=this.getPoint(G/A),E+=i.distanceTo(m),n.push(E),m=i;return this.cacheArcLengths=n,n}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(A,n){const i=this.getLengths();let m=0;const E=i.length;let G;n?G=n:G=A*i[E-1];let C=0,t=E-1,I;for(;C<=t;)if(m=Math.floor(C+(t-C)/2),I=i[m]-G,I<0)C=m+1;else if(I>0)t=m-1;else{t=m;break}if(m=t,i[m]===G)return m/(E-1);const j=i[m],h=i[m+1]-j,p=(G-j)/h;return(m+p)/(E-1)}getTangent(A,n){let m=A-1e-4,E=A+1e-4;m<0&&(m=0),E>1&&(E=1);const G=this.getPoint(m),C=this.getPoint(E),t=n||(G.isVector2?new kn:new _);return t.copy(C).sub(G).normalize(),t}getTangentAt(A,n){const i=this.getUtoTmapping(A);return this.getTangent(i,n)}computeFrenetFrames(A,n){const i=new _,m=[],E=[],G=[],C=new _,t=new Ei;for(let p=0;p<=A;p++){const B=p/A;m[p]=this.getTangentAt(B,new _)}E[0]=new _,G[0]=new _;let I=Number.MAX_VALUE;const j=Math.abs(m[0].x),H=Math.abs(m[0].y),h=Math.abs(m[0].z);j<=I&&(I=j,i.set(1,0,0)),H<=I&&(I=H,i.set(0,1,0)),h<=I&&i.set(0,0,1),C.crossVectors(m[0],i).normalize(),E[0].crossVectors(m[0],C),G[0].crossVectors(m[0],E[0]);for(let p=1;p<=A;p++){if(E[p]=E[p-1].clone(),G[p]=G[p-1].clone(),C.crossVectors(m[p-1],m[p]),C.length()>Number.EPSILON){C.normalize();const B=Math.acos(gi(m[p-1].dot(m[p]),-1,1));E[p].applyMatrix4(t.makeRotationAxis(C,B))}G[p].crossVectors(m[p],E[p])}if(n===!0){let p=Math.acos(gi(E[0].dot(E[A]),-1,1));p/=A,m[0].dot(C.crossVectors(E[0],E[A]))>0&&(p=-p);for(let B=1;B<=A;B++)E[B].applyMatrix4(t.makeRotationAxis(m[B],p*B)),G[B].crossVectors(m[B],E[B])}return{tangents:m,normals:E,binormals:G}}clone(){return new this.constructor().copy(this)}copy(A){return this.arcLengthDivisions=A.arcLengthDivisions,this}toJSON(){const A={metadata:{version:4.6,type:"Curve",generator:"Curve.toJSON"}};return A.arcLengthDivisions=this.arcLengthDivisions,A.type=this.type,A}fromJSON(A){return this.arcLengthDivisions=A.arcLengthDivisions,this}}class xH extends uE{constructor(A=0,n=0,i=1,m=1,E=0,G=Math.PI*2,C=!1,t=0){super(),this.isEllipseCurve=!0,this.type="EllipseCurve",this.aX=A,this.aY=n,this.xRadius=i,this.yRadius=m,this.aStartAngle=E,this.aEndAngle=G,this.aClockwise=C,this.aRotation=t}getPoint(A,n=new kn){const i=n,m=Math.PI*2;let E=this.aEndAngle-this.aStartAngle;const G=Math.abs(E)m;)E-=m;E0?0:(Math.floor(Math.abs(C)/E)+1)*E:t===0&&C===E-1&&(C=E-2,t=1);let I,j;this.closed||C>0?I=m[(C-1)%E]:(mj.subVectors(m[0],m[1]).add(m[0]),I=mj);const H=m[C%E],h=m[(C+1)%E];if(this.closed||C+2m.length-2?m.length-1:G+1],H=m[G>m.length-3?m.length-1:G+2];return i.set(Os(C,t.x,I.x,j.x,H.x),Os(C,t.y,I.y,j.y,H.y)),i}copy(A){super.copy(A),this.points=[];for(let n=0,i=A.points.length;n=i){const G=m[E]-i,C=this.curves[E],t=C.getLength(),I=t===0?0:1-G/t;return C.getPointAt(I,n)}E++}return null}getLength(){const A=this.getCurveLengths();return A[A.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const A=[];let n=0;for(let i=0,m=this.curves.length;i1&&!n[n.length-1].equals(n[0])&&n.push(n[0]),n}copy(A){super.copy(A),this.curves=[];for(let n=0,i=A.curves.length;n0){const H=I.getPoint(0);H.equals(this.currentPoint)||this.lineTo(H.x,H.y)}this.curves.push(I);const j=I.getPoint(1);return this.currentPoint.copy(j),this}copy(A){return super.copy(A),this.currentPoint.copy(A.currentPoint),this}toJSON(){const A=super.toJSON();return A.currentPoint=this.currentPoint.toArray(),A}fromJSON(A){return super.fromJSON(A),this.currentPoint.fromArray(A.currentPoint),this}}class KD extends ci{constructor(A=[new kn(0,-.5),new kn(.5,0),new kn(0,.5)],n=12,i=0,m=Math.PI*2){super(),this.type="LatheGeometry",this.parameters={points:A,segments:n,phiStart:i,phiLength:m},n=Math.floor(n),m=gi(m,0,Math.PI*2);const E=[],G=[],C=[],t=[],I=[],j=1/n,H=new _,h=new kn,p=new _,B=new _,J=new _;let u=0,s=0;for(let K=0;K<=A.length-1;K++)switch(K){case 0:u=A[K+1].x-A[K].x,s=A[K+1].y-A[K].y,p.x=s*1,p.y=-u,p.z=s*0,J.copy(p),p.normalize(),t.push(p.x,p.y,p.z);break;case A.length-1:t.push(J.x,J.y,J.z);break;default:u=A[K+1].x-A[K].x,s=A[K+1].y-A[K].y,p.x=s*1,p.y=-u,p.z=s*0,B.copy(p),p.x+=J.x,p.y+=J.y,p.z+=J.z,p.normalize(),t.push(p.x,p.y,p.z),J.copy(B)}for(let K=0;K<=n;K++){const d=i+K*j*m,v=Math.sin(d),O=Math.cos(d);for(let x=0;x<=A.length-1;x++){H.x=A[x].x*v,H.y=A[x].y,H.z=A[x].x*O,G.push(H.x,H.y,H.z),h.x=K/n,h.y=x/(A.length-1),C.push(h.x,h.y);const b=t[3*x+0]*v,Q=t[3*x+1],P=t[3*x+0]*O;I.push(b,Q,P)}}for(let K=0;K0&&d(!0),n>0&&d(!1)),this.setIndex(j),this.setAttribute("position",new _n(H,3)),this.setAttribute("normal",new _n(h,3)),this.setAttribute("uv",new _n(p,2));function K(){const v=new _,O=new _;let x=0;const b=(n-A)/i;for(let Q=0;Q<=E;Q++){const P=[],T=Q/E,W=T*(n-A)+A;for(let sA=0;sA<=m;sA++){const pA=sA/m,LA=pA*t+C,fA=Math.sin(LA),iA=Math.cos(LA);O.x=W*fA,O.y=-T*i+u,O.z=W*iA,H.push(O.x,O.y,O.z),v.set(fA,b,iA).normalize(),h.push(v.x,v.y,v.z),p.push(pA,1-T),P.push(B++)}J.push(P)}for(let Q=0;Q0||P!==0)&&(j.push(T,W,pA),x+=3),(n>0||P!==E-1)&&(j.push(W,sA,pA),x+=3)}I.addGroup(s,x,0),s+=x}function d(v){const O=B,x=new kn,b=new _;let Q=0;const P=v===!0?A:n,T=v===!0?1:-1;for(let sA=1;sA<=m;sA++)H.push(0,u*T,0),h.push(0,T,0),p.push(.5,.5),B++;const W=B;for(let sA=0;sA<=m;sA++){const LA=sA/m*t+C,fA=Math.cos(LA),iA=Math.sin(LA);b.x=P*iA,b.y=u*T,b.z=P*fA,H.push(b.x,b.y,b.z),h.push(0,T,0),x.x=fA*.5+.5,x.y=iA*.5*T+.5,p.push(x.x,x.y),B++}for(let sA=0;sA.9&&b<.1&&(d<.2&&(G[K+0]+=1),v<.2&&(G[K+2]+=1),O<.2&&(G[K+4]+=1))}}function h(K){E.push(K.x,K.y,K.z)}function p(K,d){const v=K*3;d.x=A[v+0],d.y=A[v+1],d.z=A[v+2]}function B(){const K=new _,d=new _,v=new _,O=new _,x=new kn,b=new kn,Q=new kn;for(let P=0,T=0;P80*n){C=I=o[0],t=j=o[1];for(let B=n;BI&&(I=H),h>j&&(j=h);p=Math.max(I-C,j-t),p=p!==0?32767/p:0}return tD(E,G,n,C,t,p,0),G}};function yu(o,A,n,i,m){let E,G;if(m===Ed(o,A,n,i)>0)for(E=A;E=A;E-=i)G=xs(E,o[E],o[E+1],G);return G&&QH(G,G.next)&&(ID(G),G=G.next),G}function Ze(o,A){if(!o)return o;A||(A=o);let n=o,i;do if(i=!1,!n.steiner&&(QH(n,n.next)||rm(n.prev,n,n.next)===0)){if(ID(n),n=A=n.prev,n===n.next)break;i=!0}else n=n.next;while(i||n!==A);return A}function tD(o,A,n,i,m,E,G){if(!o)return;!G&&E&&Ad(o,i,m,E);let C=o,t,I;for(;o.prev!==o.next;){if(t=o.prev,I=o.next,E?QK(o,i,m,E):VK(o)){A.push(t.i/n|0),A.push(o.i/n|0),A.push(I.i/n|0),ID(o),o=I.next,C=I.next;continue}if(o=I,o===C){G?G===1?(o=WK(Ze(o),A,n),tD(o,A,n,i,m,E,2)):G===2&&XK(o,A,n,i,m,E):tD(Ze(o),A,n,i,m,E,1);break}}}function VK(o){const A=o.prev,n=o,i=o.next;if(rm(A,n,i)>=0)return!1;const m=A.x,E=n.x,G=i.x,C=A.y,t=n.y,I=i.y,j=mE?m>G?m:G:E>G?E:G,p=C>t?C>I?C:I:t>I?t:I;let B=i.next;for(;B!==A;){if(B.x>=j&&B.x<=h&&B.y>=H&&B.y<=p&&rF(m,C,E,t,G,I,B.x,B.y)&&rm(B.prev,B,B.next)>=0)return!1;B=B.next}return!0}function QK(o,A,n,i){const m=o.prev,E=o,G=o.next;if(rm(m,E,G)>=0)return!1;const C=m.x,t=E.x,I=G.x,j=m.y,H=E.y,h=G.y,p=Ct?C>I?C:I:t>I?t:I,u=j>H?j>h?j:h:H>h?H:h,s=ig(p,B,A,n,i),K=ig(J,u,A,n,i);let d=o.prevZ,v=o.nextZ;for(;d&&d.z>=s&&v&&v.z<=K;){if(d.x>=p&&d.x<=J&&d.y>=B&&d.y<=u&&d!==m&&d!==G&&rF(C,j,t,H,I,h,d.x,d.y)&&rm(d.prev,d,d.next)>=0||(d=d.prevZ,v.x>=p&&v.x<=J&&v.y>=B&&v.y<=u&&v!==m&&v!==G&&rF(C,j,t,H,I,h,v.x,v.y)&&rm(v.prev,v,v.next)>=0))return!1;v=v.nextZ}for(;d&&d.z>=s;){if(d.x>=p&&d.x<=J&&d.y>=B&&d.y<=u&&d!==m&&d!==G&&rF(C,j,t,H,I,h,d.x,d.y)&&rm(d.prev,d,d.next)>=0)return!1;d=d.prevZ}for(;v&&v.z<=K;){if(v.x>=p&&v.x<=J&&v.y>=B&&v.y<=u&&v!==m&&v!==G&&rF(C,j,t,H,I,h,v.x,v.y)&&rm(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function WK(o,A,n){let i=o;do{const m=i.prev,E=i.next.next;!QH(m,E)&&Ou(m,i,i.next,E)&&DD(m,E)&&DD(E,m)&&(A.push(m.i/n|0),A.push(i.i/n|0),A.push(E.i/n|0),ID(i),ID(i.next),i=o=E),i=i.next}while(i!==o);return Ze(i)}function XK(o,A,n,i,m,E){let G=o;do{let C=G.next.next;for(;C!==G.prev;){if(G.i!==C.i&&md(G,C)){let t=xu(G,C);G=Ze(G,G.next),t=Ze(t,t.next),tD(G,A,n,i,m,E,0),tD(t,A,n,i,m,E,0);return}C=C.next}G=G.next}while(G!==o)}function YK(o,A,n,i){const m=[];let E,G,C,t,I;for(E=0,G=A.length;E=n.next.y&&n.next.y!==n.y){const h=n.x+(G-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(h<=E&&h>i&&(i=h,m=n.x=n.x&&n.x>=t&&E!==n.x&&rF(Gm.x||n.x===m.x&&$K(m,n)))&&(m=n,j=H)),n=n.next;while(n!==C);return m}function $K(o,A){return rm(o.prev,o,A.prev)<0&&rm(A.next,o,o.next)<0}function Ad(o,A,n,i){let m=o;do m.z===0&&(m.z=ig(m.x,m.y,A,n,i)),m.prevZ=m.prev,m.nextZ=m.next,m=m.next;while(m!==o);m.prevZ.nextZ=null,m.prevZ=null,nd(m)}function nd(o){let A,n,i,m,E,G,C,t,I=1;do{for(n=o,o=null,E=null,G=0;n;){for(G++,i=n,C=0,A=0;A0||t>0&&i;)C!==0&&(t===0||!i||n.z<=i.z)?(m=n,n=n.nextZ,C--):(m=i,i=i.nextZ,t--),E?E.nextZ=m:o=m,m.prevZ=E,E=m;n=i}E.nextZ=null,I*=2}while(G>1);return o}function ig(o,A,n,i,m){return o=(o-n)*m|0,A=(A-i)*m|0,o=(o|o<<8)&16711935,o=(o|o<<4)&252645135,o=(o|o<<2)&858993459,o=(o|o<<1)&1431655765,A=(A|A<<8)&16711935,A=(A|A<<4)&252645135,A=(A|A<<2)&858993459,A=(A|A<<1)&1431655765,o|A<<1}function id(o){let A=o,n=o;do(A.x=(o-G)*(E-C)&&(o-G)*(i-C)>=(n-G)*(A-C)&&(n-G)*(E-C)>=(m-G)*(i-C)}function md(o,A){return o.next.i!==A.i&&o.prev.i!==A.i&&!od(o,A)&&(DD(o,A)&&DD(A,o)&&ld(o,A)&&(rm(o.prev,o,A.prev)||rm(o,A.prev,A))||QH(o,A)&&rm(o.prev,o,o.next)>0&&rm(A.prev,A,A.next)>0)}function rm(o,A,n){return(A.y-o.y)*(n.x-A.x)-(A.x-o.x)*(n.y-A.y)}function QH(o,A){return o.x===A.x&&o.y===A.y}function Ou(o,A,n,i){const m=Gj(rm(o,A,n)),E=Gj(rm(o,A,i)),G=Gj(rm(n,i,o)),C=Gj(rm(n,i,A));return!!(m!==E&&G!==C||m===0&&kj(o,n,A)||E===0&&kj(o,i,A)||G===0&&kj(n,o,i)||C===0&&kj(n,A,i))}function kj(o,A,n){return A.x<=Math.max(o.x,n.x)&&A.x>=Math.min(o.x,n.x)&&A.y<=Math.max(o.y,n.y)&&A.y>=Math.min(o.y,n.y)}function Gj(o){return o>0?1:o<0?-1:0}function od(o,A){let n=o;do{if(n.i!==o.i&&n.next.i!==o.i&&n.i!==A.i&&n.next.i!==A.i&&Ou(n,n.next,o,A))return!0;n=n.next}while(n!==o);return!1}function DD(o,A){return rm(o.prev,o,o.next)<0?rm(o,A,o.next)>=0&&rm(o,o.prev,A)>=0:rm(o,A,o.prev)<0||rm(o,o.next,A)<0}function ld(o,A){let n=o,i=!1;const m=(o.x+A.x)/2,E=(o.y+A.y)/2;do n.y>E!=n.next.y>E&&n.next.y!==n.y&&m<(n.next.x-n.x)*(E-n.y)/(n.next.y-n.y)+n.x&&(i=!i),n=n.next;while(n!==o);return i}function xu(o,A){const n=new mg(o.i,o.x,o.y),i=new mg(A.i,A.x,A.y),m=o.next,E=A.prev;return o.next=A,A.prev=o,n.next=m,m.prev=n,i.next=n,n.prev=i,E.next=i,i.prev=E,i}function xs(o,A,n,i){const m=new mg(o,A,n);return i?(m.next=i.next,m.prev=i,i.next.prev=m,i.next=m):(m.prev=m,m.next=m),m}function ID(o){o.next.prev=o.prev,o.prev.next=o.next,o.prevZ&&(o.prevZ.nextZ=o.nextZ),o.nextZ&&(o.nextZ.prevZ=o.prevZ)}function mg(o,A,n){this.i=o,this.x=A,this.y=n,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}function Ed(o,A,n,i){let m=0;for(let E=A,G=n-i;E2&&o[A-1].equals(o[0])&&o.pop()}function Us(o,A){for(let n=0;nNumber.EPSILON){const wA=Math.sqrt(R),zA=Math.sqrt(Gn*Gn+U*U),_A=on.x-Qn/wA,En=on.y+rn/wA,hn=AA.x-U/zA,Mn=AA.y+Gn/zA,ni=((hn-_A)*U-(Mn-En)*Gn)/(rn*U-Qn*Gn);wn=_A+rn*ni-nn.x,tn=En+Qn*ni-nn.y;const en=wn*wn+tn*tn;if(en<=2)return new kn(wn,tn);Sn=Math.sqrt(en/2)}else{let wA=!1;rn>Number.EPSILON?Gn>Number.EPSILON&&(wA=!0):rn<-Number.EPSILON?Gn<-Number.EPSILON&&(wA=!0):Math.sign(Qn)===Math.sign(U)&&(wA=!0),wA?(wn=-Qn,tn=rn,Sn=Math.sqrt(R)):(wn=rn,tn=Qn,Sn=Math.sqrt(R/2))}return new kn(wn/Sn,tn/Sn)}const FA=[];for(let nn=0,on=LA.length,AA=on-1,wn=nn+1;nn=0;nn--){const on=nn/u,AA=p*Math.cos(on*Math.PI/2),wn=B*Math.sin(on*Math.PI/2)+J;for(let tn=0,Sn=LA.length;tn=0;){const wn=AA;let tn=AA-1;tn<0&&(tn=nn.length-1);for(let Sn=0,rn=j+u*2;Sn0)&&p.push(d,v,x),(s!==i-1||t0!=A>0&&this.version++,this._anisotropy=A}get clearcoat(){return this._clearcoat}set clearcoat(A){this._clearcoat>0!=A>0&&this.version++,this._clearcoat=A}get iridescence(){return this._iridescence}set iridescence(A){this._iridescence>0!=A>0&&this.version++,this._iridescence=A}get dispersion(){return this._dispersion}set dispersion(A){this._dispersion>0!=A>0&&this.version++,this._dispersion=A}get sheen(){return this._sheen}set sheen(A){this._sheen>0!=A>0&&this.version++,this._sheen=A}get transmission(){return this._transmission}set transmission(A){this._transmission>0!=A>0&&this.version++,this._transmission=A}copy(A){return super.copy(A),this.defines={STANDARD:"",PHYSICAL:""},this.anisotropy=A.anisotropy,this.anisotropyRotation=A.anisotropyRotation,this.anisotropyMap=A.anisotropyMap,this.clearcoat=A.clearcoat,this.clearcoatMap=A.clearcoatMap,this.clearcoatRoughness=A.clearcoatRoughness,this.clearcoatRoughnessMap=A.clearcoatRoughnessMap,this.clearcoatNormalMap=A.clearcoatNormalMap,this.clearcoatNormalScale.copy(A.clearcoatNormalScale),this.dispersion=A.dispersion,this.ior=A.ior,this.iridescence=A.iridescence,this.iridescenceMap=A.iridescenceMap,this.iridescenceIOR=A.iridescenceIOR,this.iridescenceThicknessRange=[...A.iridescenceThicknessRange],this.iridescenceThicknessMap=A.iridescenceThicknessMap,this.sheen=A.sheen,this.sheenColor.copy(A.sheenColor),this.sheenColorMap=A.sheenColorMap,this.sheenRoughness=A.sheenRoughness,this.sheenRoughnessMap=A.sheenRoughnessMap,this.transmission=A.transmission,this.transmissionMap=A.transmissionMap,this.thickness=A.thickness,this.thicknessMap=A.thicknessMap,this.attenuationDistance=A.attenuationDistance,this.attenuationColor.copy(A.attenuationColor),this.specularIntensity=A.specularIntensity,this.specularIntensityMap=A.specularIntensityMap,this.specularColor.copy(A.specularColor),this.specularColorMap=A.specularColorMap,this}}class Qu extends Po{constructor(A){super(),this.isMeshPhongMaterial=!0,this.type="MeshPhongMaterial",this.color=new bn(16777215),this.specular=new bn(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new bn(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=NG,this.normalScale=new kn(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new To,this.combine=aD,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(A)}copy(A){return super.copy(A),this.color.copy(A.color),this.specular.copy(A.specular),this.shininess=A.shininess,this.map=A.map,this.lightMap=A.lightMap,this.lightMapIntensity=A.lightMapIntensity,this.aoMap=A.aoMap,this.aoMapIntensity=A.aoMapIntensity,this.emissive.copy(A.emissive),this.emissiveMap=A.emissiveMap,this.emissiveIntensity=A.emissiveIntensity,this.bumpMap=A.bumpMap,this.bumpScale=A.bumpScale,this.normalMap=A.normalMap,this.normalMapType=A.normalMapType,this.normalScale.copy(A.normalScale),this.displacementMap=A.displacementMap,this.displacementScale=A.displacementScale,this.displacementBias=A.displacementBias,this.specularMap=A.specularMap,this.alphaMap=A.alphaMap,this.envMap=A.envMap,this.envMapRotation.copy(A.envMapRotation),this.combine=A.combine,this.reflectivity=A.reflectivity,this.refractionRatio=A.refractionRatio,this.wireframe=A.wireframe,this.wireframeLinewidth=A.wireframeLinewidth,this.wireframeLinecap=A.wireframeLinecap,this.wireframeLinejoin=A.wireframeLinejoin,this.flatShading=A.flatShading,this.fog=A.fog,this}}class Wu extends Po{constructor(A){super(),this.isMeshToonMaterial=!0,this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new bn(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new bn(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=NG,this.normalScale=new kn(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(A)}copy(A){return super.copy(A),this.color.copy(A.color),this.map=A.map,this.gradientMap=A.gradientMap,this.lightMap=A.lightMap,this.lightMapIntensity=A.lightMapIntensity,this.aoMap=A.aoMap,this.aoMapIntensity=A.aoMapIntensity,this.emissive.copy(A.emissive),this.emissiveMap=A.emissiveMap,this.emissiveIntensity=A.emissiveIntensity,this.bumpMap=A.bumpMap,this.bumpScale=A.bumpScale,this.normalMap=A.normalMap,this.normalMapType=A.normalMapType,this.normalScale.copy(A.normalScale),this.displacementMap=A.displacementMap,this.displacementScale=A.displacementScale,this.displacementBias=A.displacementBias,this.alphaMap=A.alphaMap,this.wireframe=A.wireframe,this.wireframeLinewidth=A.wireframeLinewidth,this.wireframeLinecap=A.wireframeLinecap,this.wireframeLinejoin=A.wireframeLinejoin,this.fog=A.fog,this}}class Xu extends Po{constructor(A){super(),this.isMeshNormalMaterial=!0,this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=NG,this.normalScale=new kn(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.flatShading=!1,this.setValues(A)}copy(A){return super.copy(A),this.bumpMap=A.bumpMap,this.bumpScale=A.bumpScale,this.normalMap=A.normalMap,this.normalMapType=A.normalMapType,this.normalScale.copy(A.normalScale),this.displacementMap=A.displacementMap,this.displacementScale=A.displacementScale,this.displacementBias=A.displacementBias,this.wireframe=A.wireframe,this.wireframeLinewidth=A.wireframeLinewidth,this.flatShading=A.flatShading,this}}class Vg extends Po{constructor(A){super(),this.isMeshLambertMaterial=!0,this.type="MeshLambertMaterial",this.color=new bn(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new bn(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=NG,this.normalScale=new kn(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new To,this.combine=aD,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(A)}copy(A){return super.copy(A),this.color.copy(A.color),this.map=A.map,this.lightMap=A.lightMap,this.lightMapIntensity=A.lightMapIntensity,this.aoMap=A.aoMap,this.aoMapIntensity=A.aoMapIntensity,this.emissive.copy(A.emissive),this.emissiveMap=A.emissiveMap,this.emissiveIntensity=A.emissiveIntensity,this.bumpMap=A.bumpMap,this.bumpScale=A.bumpScale,this.normalMap=A.normalMap,this.normalMapType=A.normalMapType,this.normalScale.copy(A.normalScale),this.displacementMap=A.displacementMap,this.displacementScale=A.displacementScale,this.displacementBias=A.displacementBias,this.specularMap=A.specularMap,this.alphaMap=A.alphaMap,this.envMap=A.envMap,this.envMapRotation.copy(A.envMapRotation),this.combine=A.combine,this.reflectivity=A.reflectivity,this.refractionRatio=A.refractionRatio,this.wireframe=A.wireframe,this.wireframeLinewidth=A.wireframeLinewidth,this.wireframeLinecap=A.wireframeLinecap,this.wireframeLinejoin=A.wireframeLinejoin,this.flatShading=A.flatShading,this.fog=A.fog,this}}class Qg extends Po{constructor(A){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=Gu,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(A)}copy(A){return super.copy(A),this.depthPacking=A.depthPacking,this.map=A.map,this.alphaMap=A.alphaMap,this.displacementMap=A.displacementMap,this.displacementScale=A.displacementScale,this.displacementBias=A.displacementBias,this.wireframe=A.wireframe,this.wireframeLinewidth=A.wireframeLinewidth,this}}class Wg extends Po{constructor(A){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(A)}copy(A){return super.copy(A),this.map=A.map,this.alphaMap=A.alphaMap,this.displacementMap=A.displacementMap,this.displacementScale=A.displacementScale,this.displacementBias=A.displacementBias,this}}class Yu extends Po{constructor(A){super(),this.isMeshMatcapMaterial=!0,this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new bn(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=NG,this.normalScale=new kn(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.fog=!0,this.setValues(A)}copy(A){return super.copy(A),this.defines={MATCAP:""},this.color.copy(A.color),this.matcap=A.matcap,this.map=A.map,this.bumpMap=A.bumpMap,this.bumpScale=A.bumpScale,this.normalMap=A.normalMap,this.normalMapType=A.normalMapType,this.normalScale.copy(A.normalScale),this.displacementMap=A.displacementMap,this.displacementScale=A.displacementScale,this.displacementBias=A.displacementBias,this.alphaMap=A.alphaMap,this.flatShading=A.flatShading,this.fog=A.fog,this}}class Zu extends nl{constructor(A){super(),this.isLineDashedMaterial=!0,this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(A)}copy(A){return super.copy(A),this.scale=A.scale,this.dashSize=A.dashSize,this.gapSize=A.gapSize,this}}function Oe(o,A,n){return!o||!n&&o.constructor===A?o:typeof A.BYTES_PER_ELEMENT=="number"?new A(o):Array.prototype.slice.call(o)}function zu(o){return ArrayBuffer.isView(o)&&!(o instanceof DataView)}function _u(o){function A(m,E){return o[m]-o[E]}const n=o.length,i=new Array(n);for(let m=0;m!==n;++m)i[m]=m;return i.sort(A),i}function og(o,A,n){const i=o.length,m=new o.constructor(i);for(let E=0,G=0;G!==i;++E){const C=n[E]*A;for(let t=0;t!==A;++t)m[G++]=o[C+t]}return m}function Xg(o,A,n,i){let m=1,E=o[0];for(;E!==void 0&&E[i]===void 0;)E=o[m++];if(E===void 0)return;let G=E[i];if(G!==void 0)if(Array.isArray(G))do G=E[i],G!==void 0&&(A.push(E.time),n.push.apply(n,G)),E=o[m++];while(E!==void 0);else if(G.toArray!==void 0)do G=E[i],G!==void 0&&(A.push(E.time),G.toArray(n,n.length)),E=o[m++];while(E!==void 0);else do G=E[i],G!==void 0&&(A.push(E.time),n.push(G)),E=o[m++];while(E!==void 0)}function Cd(o,A,n,i,m=30){const E=o.clone();E.name=A;const G=[];for(let t=0;t=i)){H.push(I.times[p]);for(let J=0;JE.tracks[t].times[0]&&(C=E.tracks[t].times[0]);for(let t=0;t=C.times[B]){const s=B*H+j,K=s+H-j;J=C.values.slice(s,K)}else{const s=C.createInterpolant(),K=j,d=H-j;s.evaluate(E),J=s.resultBuffer.slice(K,d)}t==="quaternion"&&new cm().fromArray(J).normalize().conjugate().toArray(J);const u=I.times.length;for(let s=0;s=E)){const C=n[1];A=E)break n}G=i,i=0;break i}break A}for(;i>>1;An;)--G;if(++G,E!==0||G!==m){E>=G&&(G=Math.max(G,1),E=G-1);const C=this.getValueSize();this.times=i.slice(E,G),this.values=this.values.slice(E*C,G*C)}return this}validate(){let A=!0;const n=this.getValueSize();n-Math.floor(n)!==0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),A=!1);const i=this.times,m=this.values,E=i.length;E===0&&(console.error("THREE.KeyframeTrack: Track is empty.",this),A=!1);let G=null;for(let C=0;C!==E;C++){const t=i[C];if(typeof t=="number"&&isNaN(t)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,C,t),A=!1;break}if(G!==null&&G>t){console.error("THREE.KeyframeTrack: Out of order keys.",this,C,t,G),A=!1;break}G=t}if(m!==void 0&&zu(m))for(let C=0,t=m.length;C!==t;++C){const I=m[C];if(isNaN(I)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,C,I),A=!1;break}}return A}optimize(){const A=this.times.slice(),n=this.values.slice(),i=this.getValueSize(),m=this.getInterpolation()===uj,E=A.length-1;let G=1;for(let C=1;C0){A[G]=A[E];for(let C=E*i,t=G*i,I=0;I!==i;++I)n[t+I]=n[C+I];++G}return G!==A.length?(this.times=A.slice(0,G),this.values=n.slice(0,G*i)):(this.times=A,this.values=n),this}clone(){const A=this.times.slice(),n=this.values.slice(),i=this.constructor,m=new i(this.name,A,n);return m.createInterpolant=this.createInterpolant,m}}cE.prototype.TimeBufferType=Float32Array;cE.prototype.ValueBufferType=Float32Array;cE.prototype.DefaultInterpolation=DH;class $e extends cE{constructor(A,n,i){super(A,n,i)}}$e.prototype.ValueTypeName="bool";$e.prototype.ValueBufferType=Array;$e.prototype.DefaultInterpolation=lD;$e.prototype.InterpolantFactoryMethodLinear=void 0;$e.prototype.InterpolantFactoryMethodSmooth=void 0;class Zg extends cE{}Zg.prototype.ValueTypeName="color";class jD extends cE{}jD.prototype.ValueTypeName="number";class nc extends LD{constructor(A,n,i,m){super(A,n,i,m)}interpolate_(A,n,i,m){const E=this.resultBuffer,G=this.sampleValues,C=this.valueSize,t=(i-n)/(m-n);let I=A*C;for(let j=I+C;I!==j;I+=4)cm.slerpFlat(E,0,G,I-C,G,I,t);return E}}class vD extends cE{InterpolantFactoryMethodLinear(A){return new nc(this.times,this.values,this.getValueSize(),A)}}vD.prototype.ValueTypeName="quaternion";vD.prototype.InterpolantFactoryMethodSmooth=void 0;class AC extends cE{constructor(A,n,i){super(A,n,i)}}AC.prototype.ValueTypeName="string";AC.prototype.ValueBufferType=Array;AC.prototype.DefaultInterpolation=lD;AC.prototype.InterpolantFactoryMethodLinear=void 0;AC.prototype.InterpolantFactoryMethodSmooth=void 0;class HD extends cE{}HD.prototype.ValueTypeName="vector";class rD{constructor(A="",n=-1,i=[],m=LH){this.name=A,this.tracks=i,this.duration=n,this.blendMode=m,this.uuid=Sl(),this.duration<0&&this.resetDuration()}static parse(A){const n=[],i=A.tracks,m=1/(A.fps||1);for(let G=0,C=i.length;G!==C;++G)n.push(Id(i[G]).scale(m));const E=new this(A.name,A.duration,n,A.blendMode);return E.uuid=A.uuid,E}static toJSON(A){const n=[],i=A.tracks,m={name:A.name,duration:A.duration,tracks:n,uuid:A.uuid,blendMode:A.blendMode};for(let E=0,G=i.length;E!==G;++E)n.push(cE.toJSON(i[E]));return m}static CreateFromMorphTargetSequence(A,n,i,m){const E=n.length,G=[];for(let C=0;C1){const H=j[1];let h=m[H];h||(m[H]=h=[]),h.push(I)}}const G=[];for(const C in m)G.push(this.CreateFromMorphTargetSequence(C,m[C],n,i));return G}static parseAnimation(A,n){if(!A)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;const i=function(H,h,p,B,J){if(p.length!==0){const u=[],s=[];Xg(p,u,s,B),u.length!==0&&J.push(new H(h,u,s))}},m=[],E=A.name||"default",G=A.fps||30,C=A.blendMode;let t=A.length||-1;const I=A.hierarchy||[];for(let H=0;H{n&&n(E),this.manager.itemEnd(A)},0),E;if(Mk[A]!==void 0){Mk[A].push({onLoad:n,onProgress:i,onError:m});return}Mk[A]=[],Mk[A].push({onLoad:n,onProgress:i,onError:m});const G=new Request(A,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"}),C=this.mimeType,t=this.responseType;fetch(G).then(I=>{if(I.status===200||I.status===0){if(I.status===0&&console.warn("THREE.FileLoader: HTTP Status 0 received."),typeof ReadableStream>"u"||I.body===void 0||I.body.getReader===void 0)return I;const j=Mk[A],H=I.body.getReader(),h=I.headers.get("X-File-Size")||I.headers.get("Content-Length"),p=h?parseInt(h):0,B=p!==0;let J=0;const u=new ReadableStream({start(s){K();function K(){H.read().then(({done:d,value:v})=>{if(d)s.close();else{J+=v.byteLength;const O=new ProgressEvent("progress",{lengthComputable:B,loaded:J,total:p});for(let x=0,b=j.length;x{s.error(d)})}}});return new Response(u)}else throw new jd(`fetch for "${I.url}" responded with ${I.status}: ${I.statusText}`,I)}).then(I=>{switch(t){case"arraybuffer":return I.arrayBuffer();case"blob":return I.blob();case"document":return I.text().then(j=>new DOMParser().parseFromString(j,C));case"json":return I.json();default:if(C===void 0)return I.text();{const H=/charset="?([^;"\s]*)"?/i.exec(C),h=H&&H[1]?H[1].toLowerCase():void 0,p=new TextDecoder(h);return I.arrayBuffer().then(B=>p.decode(B))}}}).then(I=>{Nk.add(A,I);const j=Mk[A];delete Mk[A];for(let H=0,h=j.length;H{const j=Mk[A];if(j===void 0)throw this.manager.itemError(A),I;delete Mk[A];for(let H=0,h=j.length;H{this.manager.itemEnd(A)}),this.manager.itemStart(A)}setResponseType(A){return this.responseType=A,this}setMimeType(A){return this.mimeType=A,this}}class Hd extends sl{constructor(A){super(A)}load(A,n,i,m){const E=this,G=new bk(this.manager);G.setPath(this.path),G.setRequestHeader(this.requestHeader),G.setWithCredentials(this.withCredentials),G.load(A,function(C){try{n(E.parse(JSON.parse(C)))}catch(t){m?m(t):console.error(t),E.manager.itemError(A)}},i,m)}parse(A){const n=[];for(let i=0;i0:m.vertexColors=A.vertexColors),A.uniforms!==void 0)for(const E in A.uniforms){const G=A.uniforms[E];switch(m.uniforms[E]={},G.type){case"t":m.uniforms[E].value=i(G.value);break;case"c":m.uniforms[E].value=new bn().setHex(G.value);break;case"v2":m.uniforms[E].value=new kn().fromArray(G.value);break;case"v3":m.uniforms[E].value=new _().fromArray(G.value);break;case"v4":m.uniforms[E].value=new di().fromArray(G.value);break;case"m3":m.uniforms[E].value=new si().fromArray(G.value);break;case"m4":m.uniforms[E].value=new Ei().fromArray(G.value);break;default:m.uniforms[E].value=G.value}}if(A.defines!==void 0&&(m.defines=A.defines),A.vertexShader!==void 0&&(m.vertexShader=A.vertexShader),A.fragmentShader!==void 0&&(m.fragmentShader=A.fragmentShader),A.glslVersion!==void 0&&(m.glslVersion=A.glslVersion),A.extensions!==void 0)for(const E in A.extensions)m.extensions[E]=A.extensions[E];if(A.lights!==void 0&&(m.lights=A.lights),A.clipping!==void 0&&(m.clipping=A.clipping),A.size!==void 0&&(m.size=A.size),A.sizeAttenuation!==void 0&&(m.sizeAttenuation=A.sizeAttenuation),A.map!==void 0&&(m.map=i(A.map)),A.matcap!==void 0&&(m.matcap=i(A.matcap)),A.alphaMap!==void 0&&(m.alphaMap=i(A.alphaMap)),A.bumpMap!==void 0&&(m.bumpMap=i(A.bumpMap)),A.bumpScale!==void 0&&(m.bumpScale=A.bumpScale),A.normalMap!==void 0&&(m.normalMap=i(A.normalMap)),A.normalMapType!==void 0&&(m.normalMapType=A.normalMapType),A.normalScale!==void 0){let E=A.normalScale;Array.isArray(E)===!1&&(E=[E,E]),m.normalScale=new kn().fromArray(E)}return A.displacementMap!==void 0&&(m.displacementMap=i(A.displacementMap)),A.displacementScale!==void 0&&(m.displacementScale=A.displacementScale),A.displacementBias!==void 0&&(m.displacementBias=A.displacementBias),A.roughnessMap!==void 0&&(m.roughnessMap=i(A.roughnessMap)),A.metalnessMap!==void 0&&(m.metalnessMap=i(A.metalnessMap)),A.emissiveMap!==void 0&&(m.emissiveMap=i(A.emissiveMap)),A.emissiveIntensity!==void 0&&(m.emissiveIntensity=A.emissiveIntensity),A.specularMap!==void 0&&(m.specularMap=i(A.specularMap)),A.specularIntensityMap!==void 0&&(m.specularIntensityMap=i(A.specularIntensityMap)),A.specularColorMap!==void 0&&(m.specularColorMap=i(A.specularColorMap)),A.envMap!==void 0&&(m.envMap=i(A.envMap)),A.envMapRotation!==void 0&&m.envMapRotation.fromArray(A.envMapRotation),A.envMapIntensity!==void 0&&(m.envMapIntensity=A.envMapIntensity),A.reflectivity!==void 0&&(m.reflectivity=A.reflectivity),A.refractionRatio!==void 0&&(m.refractionRatio=A.refractionRatio),A.lightMap!==void 0&&(m.lightMap=i(A.lightMap)),A.lightMapIntensity!==void 0&&(m.lightMapIntensity=A.lightMapIntensity),A.aoMap!==void 0&&(m.aoMap=i(A.aoMap)),A.aoMapIntensity!==void 0&&(m.aoMapIntensity=A.aoMapIntensity),A.gradientMap!==void 0&&(m.gradientMap=i(A.gradientMap)),A.clearcoatMap!==void 0&&(m.clearcoatMap=i(A.clearcoatMap)),A.clearcoatRoughnessMap!==void 0&&(m.clearcoatRoughnessMap=i(A.clearcoatRoughnessMap)),A.clearcoatNormalMap!==void 0&&(m.clearcoatNormalMap=i(A.clearcoatNormalMap)),A.clearcoatNormalScale!==void 0&&(m.clearcoatNormalScale=new kn().fromArray(A.clearcoatNormalScale)),A.iridescenceMap!==void 0&&(m.iridescenceMap=i(A.iridescenceMap)),A.iridescenceThicknessMap!==void 0&&(m.iridescenceThicknessMap=i(A.iridescenceThicknessMap)),A.transmissionMap!==void 0&&(m.transmissionMap=i(A.transmissionMap)),A.thicknessMap!==void 0&&(m.thicknessMap=i(A.thicknessMap)),A.anisotropyMap!==void 0&&(m.anisotropyMap=i(A.anisotropyMap)),A.sheenColorMap!==void 0&&(m.sheenColorMap=i(A.sheenColorMap)),A.sheenRoughnessMap!==void 0&&(m.sheenRoughnessMap=i(A.sheenRoughnessMap)),m}setTextures(A){return this.textures=A,this}createMaterialFromType(A){return nr.createMaterialFromType(A)}static createMaterialFromType(A){const n={ShadowMaterial:Uu,SpriteMaterial:RH,RawShaderMaterial:wu,ShaderMaterial:aE,PointsMaterial:Tg,MeshPhysicalMaterial:Vu,MeshStandardMaterial:wg,MeshPhongMaterial:Qu,MeshToonMaterial:Wu,MeshNormalMaterial:Xu,MeshLambertMaterial:Vg,MeshDepthMaterial:Qg,MeshDistanceMaterial:Wg,MeshBasicMaterial:TG,MeshMatcapMaterial:Yu,LineDashedMaterial:Zu,LineBasicMaterial:nl,Material:Po};return new n[A]}}class lg{static decodeText(A){if(console.warn("THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead."),typeof TextDecoder<"u")return new TextDecoder().decode(A);let n="";for(let i=0,m=A.length;i0){const t=new zg(n);E=new hD(t),E.setCrossOrigin(this.crossOrigin);for(let I=0,j=A.length;I0){m=new hD(this.manager),m.setCrossOrigin(this.crossOrigin);for(let G=0,C=A.length;G{const u=new Al;u.min.fromArray(J.boxMin),u.max.fromArray(J.boxMax);const s=new No;return s.radius=J.sphereRadius,s.center.fromArray(J.sphereCenter),{boxInitialized:J.boxInitialized,box:u,sphereInitialized:J.sphereInitialized,sphere:s}}),G._maxInstanceCount=A.maxInstanceCount,G._maxVertexCount=A.maxVertexCount,G._maxIndexCount=A.maxIndexCount,G._geometryInitialized=A.geometryInitialized,G._geometryCount=A.geometryCount,G._matricesTexture=I(A.matricesTexture.uuid),A.colorsTexture!==void 0&&(G._colorsTexture=I(A.colorsTexture.uuid));break;case"LOD":G=new qu;break;case"Line":G=new SG(C(A.geometry),t(A.material));break;case"LineLoop":G=new Mu(C(A.geometry),t(A.material));break;case"LineSegments":G=new WE(C(A.geometry),t(A.material));break;case"PointCloud":case"Points":G=new Lu(C(A.geometry),t(A.material));break;case"Sprite":G=new IH(t(A.material));break;case"Group":G=new HF;break;case"Bone":G=new Ng;break;default:G=new Li}if(G.uuid=A.uuid,A.name!==void 0&&(G.name=A.name),A.matrix!==void 0?(G.matrix.fromArray(A.matrix),A.matrixAutoUpdate!==void 0&&(G.matrixAutoUpdate=A.matrixAutoUpdate),G.matrixAutoUpdate&&G.matrix.decompose(G.position,G.quaternion,G.scale)):(A.position!==void 0&&G.position.fromArray(A.position),A.rotation!==void 0&&G.rotation.fromArray(A.rotation),A.quaternion!==void 0&&G.quaternion.fromArray(A.quaternion),A.scale!==void 0&&G.scale.fromArray(A.scale)),A.up!==void 0&&G.up.fromArray(A.up),A.castShadow!==void 0&&(G.castShadow=A.castShadow),A.receiveShadow!==void 0&&(G.receiveShadow=A.receiveShadow),A.shadow&&(A.shadow.intensity!==void 0&&(G.shadow.intensity=A.shadow.intensity),A.shadow.bias!==void 0&&(G.shadow.bias=A.shadow.bias),A.shadow.normalBias!==void 0&&(G.shadow.normalBias=A.shadow.normalBias),A.shadow.radius!==void 0&&(G.shadow.radius=A.shadow.radius),A.shadow.mapSize!==void 0&&G.shadow.mapSize.fromArray(A.shadow.mapSize),A.shadow.camera!==void 0&&(G.shadow.camera=this.parseObject(A.shadow.camera))),A.visible!==void 0&&(G.visible=A.visible),A.frustumCulled!==void 0&&(G.frustumCulled=A.frustumCulled),A.renderOrder!==void 0&&(G.renderOrder=A.renderOrder),A.userData!==void 0&&(G.userData=A.userData),A.layers!==void 0&&(G.layers.mask=A.layers),A.children!==void 0){const h=A.children;for(let p=0;p"u"&&console.warn("THREE.ImageBitmapLoader: createImageBitmap() not supported."),typeof fetch>"u"&&console.warn("THREE.ImageBitmapLoader: fetch() not supported."),this.options={premultiplyAlpha:"none"}}setOptions(A){return this.options=A,this}load(A,n,i,m){A===void 0&&(A=""),this.path!==void 0&&(A=this.path+A),A=this.manager.resolveURL(A);const E=this,G=Nk.get(A);if(G!==void 0){if(E.manager.itemStart(A),G.then){G.then(I=>{n&&n(I),E.manager.itemEnd(A)}).catch(I=>{m&&m(I)});return}return setTimeout(function(){n&&n(G),E.manager.itemEnd(A)},0),G}const C={};C.credentials=this.crossOrigin==="anonymous"?"same-origin":"include",C.headers=this.requestHeader;const t=fetch(A,C).then(function(I){return I.blob()}).then(function(I){return createImageBitmap(I,Object.assign(E.options,{colorSpaceConversion:"none"}))}).then(function(I){return Nk.add(A,I),n&&n(I),E.manager.itemEnd(A),I}).catch(function(I){m&&m(I),Nk.remove(A),E.manager.itemError(A),E.manager.itemEnd(A)});Nk.add(A,t),E.manager.itemStart(A)}}let ej;class np{static getContext(){return ej===void 0&&(ej=new(window.AudioContext||window.webkitAudioContext)),ej}static setContext(A){ej=A}}class Jd extends sl{constructor(A){super(A)}load(A,n,i,m){const E=this,G=new bk(this.manager);G.setResponseType("arraybuffer"),G.setPath(this.path),G.setRequestHeader(this.requestHeader),G.setWithCredentials(this.withCredentials),G.load(A,function(t){try{const I=t.slice(0);np.getContext().decodeAudioData(I,function(H){n(H)}).catch(C)}catch(I){C(I)}},i,m);function C(t){m?m(t):console.error(t),E.manager.itemError(A)}}}const zs=new Ei,_s=new Ei,Je=new Ei;class qd{constructor(){this.type="StereoCamera",this.aspect=1,this.eyeSep=.064,this.cameraL=new Co,this.cameraL.layers.enable(1),this.cameraL.matrixAutoUpdate=!1,this.cameraR=new Co,this.cameraR.layers.enable(2),this.cameraR.matrixAutoUpdate=!1,this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null}}update(A){const n=this._cache;if(n.focus!==A.focus||n.fov!==A.fov||n.aspect!==A.aspect*this.aspect||n.near!==A.near||n.far!==A.far||n.zoom!==A.zoom||n.eyeSep!==this.eyeSep){n.focus=A.focus,n.fov=A.fov,n.aspect=A.aspect*this.aspect,n.near=A.near,n.far=A.far,n.zoom=A.zoom,n.eyeSep=this.eyeSep,Je.copy(A.projectionMatrix);const m=n.eyeSep/2,E=m*n.near/n.focus,G=n.near*Math.tan(be*n.fov*.5)/n.zoom;let C,t;_s.elements[12]=-m,zs.elements[12]=m,C=-G*n.aspect+E,t=G*n.aspect+E,Je.elements[0]=2*n.near/(t-C),Je.elements[8]=(t+C)/(t-C),this.cameraL.projectionMatrix.copy(Je),C=-G*n.aspect-E,t=G*n.aspect-E,Je.elements[0]=2*n.near/(t-C),Je.elements[8]=(t+C)/(t-C),this.cameraR.projectionMatrix.copy(Je)}this.cameraL.matrixWorld.copy(A.matrixWorld).multiply(_s),this.cameraR.matrixWorld.copy(A.matrixWorld).multiply(zs)}}class tc extends Co{constructor(A=[]){super(),this.isArrayCamera=!0,this.cameras=A}}class ip{constructor(A=!0){this.autoStart=A,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1}start(){this.startTime=$s(),this.oldTime=this.startTime,this.elapsedTime=0,this.running=!0}stop(){this.getElapsedTime(),this.running=!1,this.autoStart=!1}getElapsedTime(){return this.getDelta(),this.elapsedTime}getDelta(){let A=0;if(this.autoStart&&!this.running)return this.start(),0;if(this.running){const n=$s();A=(n-this.oldTime)/1e3,this.oldTime=n,this.elapsedTime+=A}return A}}function $s(){return performance.now()}const qe=new _,AB=new cm,fd=new _,fe=new _;class Kd extends Li{constructor(){super(),this.type="AudioListener",this.context=np.getContext(),this.gain=this.context.createGain(),this.gain.connect(this.context.destination),this.filter=null,this.timeDelta=0,this._clock=new ip}getInput(){return this.gain}removeFilter(){return this.filter!==null&&(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination),this.gain.connect(this.context.destination),this.filter=null),this}getFilter(){return this.filter}setFilter(A){return this.filter!==null?(this.gain.disconnect(this.filter),this.filter.disconnect(this.context.destination)):this.gain.disconnect(this.context.destination),this.filter=A,this.gain.connect(this.filter),this.filter.connect(this.context.destination),this}getMasterVolume(){return this.gain.gain.value}setMasterVolume(A){return this.gain.gain.setTargetAtTime(A,this.context.currentTime,.01),this}updateMatrixWorld(A){super.updateMatrixWorld(A);const n=this.context.listener,i=this.up;if(this.timeDelta=this._clock.getDelta(),this.matrixWorld.decompose(qe,AB,fd),fe.set(0,0,-1).applyQuaternion(AB),n.positionX){const m=this.context.currentTime+this.timeDelta;n.positionX.linearRampToValueAtTime(qe.x,m),n.positionY.linearRampToValueAtTime(qe.y,m),n.positionZ.linearRampToValueAtTime(qe.z,m),n.forwardX.linearRampToValueAtTime(fe.x,m),n.forwardY.linearRampToValueAtTime(fe.y,m),n.forwardZ.linearRampToValueAtTime(fe.z,m),n.upX.linearRampToValueAtTime(i.x,m),n.upY.linearRampToValueAtTime(i.y,m),n.upZ.linearRampToValueAtTime(i.z,m)}else n.setPosition(qe.x,qe.y,qe.z),n.setOrientation(fe.x,fe.y,fe.z,i.x,i.y,i.z)}}class Dc extends Li{constructor(A){super(),this.type="Audio",this.listener=A,this.context=A.context,this.gain=this.context.createGain(),this.gain.connect(A.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(A){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=A,this.connect(),this}setMediaElementSource(A){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(A),this.connect(),this}setMediaStreamSource(A){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(A),this.connect(),this}setBuffer(A){return this.buffer=A,this.sourceType="buffer",this.autoplay&&this.play(),this}play(A=0){if(this.isPlaying===!0){console.warn("THREE.Audio: Audio is already playing.");return}if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}this._startedAt=this.context.currentTime+A;const n=this.context.createBufferSource();return n.buffer=this.buffer,n.loop=this.loop,n.loopStart=this.loopStart,n.loopEnd=this.loopEnd,n.onended=this.onEnded.bind(this),n.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=n,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}return this.isPlaying===!0&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,this.loop===!0&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this}stop(A=0){if(this.hasPlaybackControl===!1){console.warn("THREE.Audio: this Audio has no playback control.");return}return this._progress=0,this.source!==null&&(this.source.stop(this.context.currentTime+A),this.source.onended=null),this.isPlaying=!1,this}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let A=1,n=this.filters.length;A0){this.source.disconnect(this.filters[0]);for(let A=1,n=this.filters.length;A0&&this._mixBufferRegionAdditive(i,m,this._addIndex*n,1,n);for(let t=n,I=n+n;t!==I;++t)if(i[t]!==i[t+n]){C.setValue(i,m);break}}saveOriginalState(){const A=this.binding,n=this.buffer,i=this.valueSize,m=i*this._origIndex;A.getValue(n,m);for(let E=i,G=m;E!==G;++E)n[E]=n[m+E%i];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const A=this.valueSize*3;this.binding.setValue(this.buffer,A)}_setAdditiveIdentityNumeric(){const A=this._addIndex*this.valueSize,n=A+this.valueSize;for(let i=A;i=.5)for(let G=0;G!==E;++G)A[n+G]=A[i+G]}_slerp(A,n,i,m){cm.slerpFlat(A,n,A,n,A,i,m)}_slerpAdditive(A,n,i,m,E){const G=this._workIndex*E;cm.multiplyQuaternionsFlat(A,G,A,n,A,i),cm.slerpFlat(A,n,A,n,A,G,m)}_lerp(A,n,i,m,E){const G=1-m;for(let C=0;C!==E;++C){const t=n+C;A[t]=A[t]*G+A[i+C]*m}}_lerpAdditive(A,n,i,m,E){for(let G=0;G!==E;++G){const C=n+G;A[C]=A[C]+A[i+G]*m}}}const mp="\\[\\]\\.:\\/",vd=new RegExp("["+mp+"]","g"),op="[^"+mp+"]",Sd="[^"+mp.replace("\\.","")+"]",Nd=/((?:WC+[\/:])*)/.source.replace("WC",op),Td=/(WCOD+)?/.source.replace("WCOD",Sd),Pd=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",op),Rd=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",op),yd=new RegExp("^"+Nd+Td+Pd+Rd+"$"),Od=["material","materials","bones","map"];class xd{constructor(A,n,i){const m=i||Oi.parseTrackName(n);this._targetGroup=A,this._bindings=A.subscribe_(n,m)}getValue(A,n){this.bind();const i=this._targetGroup.nCachedObjects_,m=this._bindings[i];m!==void 0&&m.getValue(A,n)}setValue(A,n){const i=this._bindings;for(let m=this._targetGroup.nCachedObjects_,E=i.length;m!==E;++m)i[m].setValue(A,n)}bind(){const A=this._bindings;for(let n=this._targetGroup.nCachedObjects_,i=A.length;n!==i;++n)A[n].bind()}unbind(){const A=this._bindings;for(let n=this._targetGroup.nCachedObjects_,i=A.length;n!==i;++n)A[n].unbind()}}class Oi{constructor(A,n,i){this.path=n,this.parsedPath=i||Oi.parseTrackName(n),this.node=Oi.findNode(A,this.parsedPath.nodeName),this.rootNode=A,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(A,n,i){return A&&A.isAnimationObjectGroup?new Oi.Composite(A,n,i):new Oi(A,n,i)}static sanitizeNodeName(A){return A.replace(/\s/g,"_").replace(vd,"")}static parseTrackName(A){const n=yd.exec(A);if(n===null)throw new Error("PropertyBinding: Cannot parse trackName: "+A);const i={nodeName:n[2],objectName:n[3],objectIndex:n[4],propertyName:n[5],propertyIndex:n[6]},m=i.nodeName&&i.nodeName.lastIndexOf(".");if(m!==void 0&&m!==-1){const E=i.nodeName.substring(m+1);Od.indexOf(E)!==-1&&(i.nodeName=i.nodeName.substring(0,m),i.objectName=E)}if(i.propertyName===null||i.propertyName.length===0)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+A);return i}static findNode(A,n){if(n===void 0||n===""||n==="."||n===-1||n===A.name||n===A.uuid)return A;if(A.skeleton){const i=A.skeleton.getBoneByName(n);if(i!==void 0)return i}if(A.children){const i=function(E){for(let G=0;G=E){const H=E++,h=A[H];n[h.uuid]=j,A[j]=h,n[I]=H,A[H]=t;for(let p=0,B=m;p!==B;++p){const J=i[p],u=J[H],s=J[j];J[j]=u,J[H]=s}}}this.nCachedObjects_=E}uncache(){const A=this._objects,n=this._indicesByUUID,i=this._bindings,m=i.length;let E=this.nCachedObjects_,G=A.length;for(let C=0,t=arguments.length;C!==t;++C){const I=arguments[C],j=I.uuid,H=n[j];if(H!==void 0)if(delete n[j],H0&&(n[p.uuid]=H),A[H]=p,A.pop();for(let B=0,J=m;B!==J;++B){const u=i[B];u[H]=u[h],u.pop()}}}this.nCachedObjects_=E}subscribe_(A,n){const i=this._bindingsIndicesByPath;let m=i[A];const E=this._bindings;if(m!==void 0)return E[m];const G=this._paths,C=this._parsedPaths,t=this._objects,I=t.length,j=this.nCachedObjects_,H=new Array(I);m=E.length,i[A]=m,G.push(A),C.push(n),E.push(H);for(let h=j,p=t.length;h!==p;++h){const B=t[h];H[h]=new Oi(B,A,n)}return H}unsubscribe_(A){const n=this._bindingsIndicesByPath,i=n[A];if(i!==void 0){const m=this._paths,E=this._parsedPaths,G=this._bindings,C=G.length-1,t=G[C],I=A[C];n[I]=i,G[i]=t,G.pop(),E[i]=E[C],E.pop(),m[i]=m[C],m.pop()}}}class jc{constructor(A,n,i=null,m=n.blendMode){this._mixer=A,this._clip=n,this._localRoot=i,this.blendMode=m;const E=n.tracks,G=E.length,C=new Array(G),t={endingStart:Pe,endingEnd:Pe};for(let I=0;I!==G;++I){const j=E[I].createInterpolant(null);C[I]=j,j.settings=t}this._interpolantSettings=t,this._interpolants=C,this._propertyBindings=new Array(G),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=Eu,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&this.timeScale!==0&&this._startTime===null&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(A){return this._startTime=A,this}setLoop(A,n){return this.loop=A,this.repetitions=n,this}setEffectiveWeight(A){return this.weight=A,this._effectiveWeight=this.enabled?A:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(A){return this._scheduleFading(A,0,1)}fadeOut(A){return this._scheduleFading(A,1,0)}crossFadeFrom(A,n,i){if(A.fadeOut(n),this.fadeIn(n),i){const m=this._clip.duration,E=A._clip.duration,G=E/m,C=m/E;A.warp(1,G,n),this.warp(C,1,n)}return this}crossFadeTo(A,n,i){return A.crossFadeFrom(this,n,i)}stopFading(){const A=this._weightInterpolant;return A!==null&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(A)),this}setEffectiveTimeScale(A){return this.timeScale=A,this._effectiveTimeScale=this.paused?0:A,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(A){return this.timeScale=this._clip.duration/A,this.stopWarping()}syncWith(A){return this.time=A.time,this.timeScale=A.timeScale,this.stopWarping()}halt(A){return this.warp(this._effectiveTimeScale,0,A)}warp(A,n,i){const m=this._mixer,E=m.time,G=this.timeScale;let C=this._timeScaleInterpolant;C===null&&(C=m._lendControlInterpolant(),this._timeScaleInterpolant=C);const t=C.parameterPositions,I=C.sampleValues;return t[0]=E,t[1]=E+i,I[0]=A/G,I[1]=n/G,this}stopWarping(){const A=this._timeScaleInterpolant;return A!==null&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(A)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(A,n,i,m){if(!this.enabled){this._updateWeight(A);return}const E=this._startTime;if(E!==null){const t=(A-E)*i;t<0||i===0?n=0:(this._startTime=null,n=i*t)}n*=this._updateTimeScale(A);const G=this._updateTime(n),C=this._updateWeight(A);if(C>0){const t=this._interpolants,I=this._propertyBindings;switch(this.blendMode){case Kg:for(let j=0,H=t.length;j!==H;++j)t[j].evaluate(G),I[j].accumulateAdditive(C);break;case LH:default:for(let j=0,H=t.length;j!==H;++j)t[j].evaluate(G),I[j].accumulate(m,C)}}}_updateWeight(A){let n=0;if(this.enabled){n=this.weight;const i=this._weightInterpolant;if(i!==null){const m=i.evaluate(A)[0];n*=m,A>i.parameterPositions[1]&&(this.stopFading(),m===0&&(this.enabled=!1))}}return this._effectiveWeight=n,n}_updateTimeScale(A){let n=0;if(!this.paused){n=this.timeScale;const i=this._timeScaleInterpolant;if(i!==null){const m=i.evaluate(A)[0];n*=m,A>i.parameterPositions[1]&&(this.stopWarping(),n===0?this.paused=!0:this.timeScale=n)}}return this._effectiveTimeScale=n,n}_updateTime(A){const n=this._clip.duration,i=this.loop;let m=this.time+A,E=this._loopCount;const G=i===ku;if(A===0)return E===-1?m:G&&(E&1)===1?n-m:m;if(i===lu){E===-1&&(this._loopCount=0,this._setEndings(!0,!0,!1));A:{if(m>=n)m=n;else if(m<0)m=0;else{this.time=m;break A}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=m,this._mixer.dispatchEvent({type:"finished",action:this,direction:A<0?-1:1})}}else{if(E===-1&&(A>=0?(E=0,this._setEndings(!0,this.repetitions===0,G)):this._setEndings(this.repetitions===0,!0,G)),m>=n||m<0){const C=Math.floor(m/n);m-=n*C,E+=Math.abs(C);const t=this.repetitions-E;if(t<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,m=A>0?n:0,this.time=m,this._mixer.dispatchEvent({type:"finished",action:this,direction:A>0?1:-1});else{if(t===1){const I=A<0;this._setEndings(I,!I,G)}else this._setEndings(!1,!1,G);this._loopCount=E,this.time=m,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:C})}}else this.time=m;if(G&&(E&1)===1)return n-m}return m}_setEndings(A,n,i){const m=this._interpolantSettings;i?(m.endingStart=Re,m.endingEnd=Re):(A?m.endingStart=this.zeroSlopeAtStart?Re:Pe:m.endingStart=ED,n?m.endingEnd=this.zeroSlopeAtEnd?Re:Pe:m.endingEnd=ED)}_scheduleFading(A,n,i){const m=this._mixer,E=m.time;let G=this._weightInterpolant;G===null&&(G=m._lendControlInterpolant(),this._weightInterpolant=G);const C=G.parameterPositions,t=G.sampleValues;return C[0]=E,t[0]=n,C[1]=E+A,t[1]=i,this}}const Ud=new Float32Array(1);class wd extends QE{constructor(A){super(),this._root=A,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(A,n){const i=A._localRoot||this._root,m=A._clip.tracks,E=m.length,G=A._propertyBindings,C=A._interpolants,t=i.uuid,I=this._bindingsByRootAndName;let j=I[t];j===void 0&&(j={},I[t]=j);for(let H=0;H!==E;++H){const h=m[H],p=h.name;let B=j[p];if(B!==void 0)++B.referenceCount,G[H]=B;else{if(B=G[H],B!==void 0){B._cacheIndex===null&&(++B.referenceCount,this._addInactiveBinding(B,t,p));continue}const J=n&&n._propertyBindings[H].binding.parsedPath;B=new Ic(Oi.create(i,p,J),h.ValueTypeName,h.getValueSize()),++B.referenceCount,this._addInactiveBinding(B,t,p),G[H]=B}C[H].resultBuffer=B.buffer}}_activateAction(A){if(!this._isActiveAction(A)){if(A._cacheIndex===null){const i=(A._localRoot||this._root).uuid,m=A._clip.uuid,E=this._actionsByClip[m];this._bindAction(A,E&&E.knownActions[0]),this._addInactiveAction(A,m,i)}const n=A._propertyBindings;for(let i=0,m=n.length;i!==m;++i){const E=n[i];E.useCount++===0&&(this._lendBinding(E),E.saveOriginalState())}this._lendAction(A)}}_deactivateAction(A){if(this._isActiveAction(A)){const n=A._propertyBindings;for(let i=0,m=n.length;i!==m;++i){const E=n[i];--E.useCount===0&&(E.restoreOriginalState(),this._takeBackBinding(E))}this._takeBackAction(A)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const A=this;this.stats={actions:{get total(){return A._actions.length},get inUse(){return A._nActiveActions}},bindings:{get total(){return A._bindings.length},get inUse(){return A._nActiveBindings}},controlInterpolants:{get total(){return A._controlInterpolants.length},get inUse(){return A._nActiveControlInterpolants}}}}_isActiveAction(A){const n=A._cacheIndex;return n!==null&&n=0;--i)A[i].stop();return this}update(A){A*=this.timeScale;const n=this._actions,i=this._nActiveActions,m=this.time+=A,E=Math.sign(A),G=this._accuIndex^=1;for(let I=0;I!==i;++I)n[I]._update(m,A,E,G);const C=this._bindings,t=this._nActiveBindings;for(let I=0;I!==t;++I)C[I].apply(G);return this}setTime(A){this.time=0;for(let n=0;n=this.min.x&&A.x<=this.max.x&&A.y>=this.min.y&&A.y<=this.max.y}containsBox(A){return this.min.x<=A.min.x&&A.max.x<=this.max.x&&this.min.y<=A.min.y&&A.max.y<=this.max.y}getParameter(A,n){return n.set((A.x-this.min.x)/(this.max.x-this.min.x),(A.y-this.min.y)/(this.max.y-this.min.y))}intersectsBox(A){return A.max.x>=this.min.x&&A.min.x<=this.max.x&&A.max.y>=this.min.y&&A.min.y<=this.max.y}clampPoint(A,n){return n.copy(A).clamp(this.min,this.max)}distanceToPoint(A){return this.clampPoint(A,oB).distanceTo(A)}intersect(A){return this.min.max(A.min),this.max.min(A.max),this.isEmpty()&&this.makeEmpty(),this}union(A){return this.min.min(A.min),this.max.max(A.max),this}translate(A){return this.min.add(A),this.max.add(A),this}equals(A){return A.min.equals(this.min)&&A.max.equals(this.max)}}const lB=new _,Cj=new _;class AM{constructor(A=new _,n=new _){this.start=A,this.end=n}set(A,n){return this.start.copy(A),this.end.copy(n),this}copy(A){return this.start.copy(A.start),this.end.copy(A.end),this}getCenter(A){return A.addVectors(this.start,this.end).multiplyScalar(.5)}delta(A){return A.subVectors(this.end,this.start)}distanceSq(){return this.start.distanceToSquared(this.end)}distance(){return this.start.distanceTo(this.end)}at(A,n){return this.delta(n).multiplyScalar(A).add(this.start)}closestPointToPointParameter(A,n){lB.subVectors(A,this.start),Cj.subVectors(this.end,this.start);const i=Cj.dot(Cj);let E=Cj.dot(lB)/i;return n&&(E=gi(E,0,1)),E}closestPointToPoint(A,n,i){const m=this.closestPointToPointParameter(A,n);return this.delta(i).multiplyScalar(m).add(this.start)}applyMatrix4(A){return this.start.applyMatrix4(A),this.end.applyMatrix4(A),this}equals(A){return A.start.equals(this.start)&&A.end.equals(this.end)}clone(){return new this.constructor().copy(this)}}const EB=new _;class nM extends Li{constructor(A,n){super(),this.light=A,this.matrixAutoUpdate=!1,this.color=n,this.type="SpotLightHelper";const i=new ci,m=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(let G=0,C=1,t=32;G1)for(let H=0;H.99999)this.quaternion.set(0,0,0,1);else if(A.y<-.99999)this.quaternion.set(1,0,0,0);else{FB.set(A.z,0,-A.x).normalize();const n=Math.acos(A.y);this.quaternion.setFromAxisAngle(FB,n)}}setLength(A,n=A*.2,i=n*.2){this.line.scale.set(1,Math.max(1e-4,A-n),1),this.line.updateMatrix(),this.cone.scale.set(i,n,i),this.cone.position.y=A,this.cone.updateMatrix()}setColor(A){this.line.material.color.set(A),this.cone.material.color.set(A)}copy(A){return super.copy(A,!1),this.line.copy(A.line),this.cone.copy(A.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}}class IM extends WE{constructor(A=1){const n=[0,0,0,A,0,0,0,0,0,0,A,0,0,0,0,0,0,A],i=[1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],m=new ci;m.setAttribute("position",new _n(n,3)),m.setAttribute("color",new _n(i,3));const E=new nl({vertexColors:!0,toneMapped:!1});super(m,E),this.type="AxesHelper"}setColors(A,n,i){const m=new bn,E=this.geometry.attributes.color.array;return m.set(A),m.toArray(E,0),m.toArray(E,3),m.set(n),m.toArray(E,6),m.toArray(E,9),m.set(i),m.toArray(E,12),m.toArray(E,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class jM{constructor(){this.type="ShapePath",this.color=new bn,this.subPaths=[],this.currentPath=null}moveTo(A,n){return this.currentPath=new FD,this.subPaths.push(this.currentPath),this.currentPath.moveTo(A,n),this}lineTo(A,n){return this.currentPath.lineTo(A,n),this}quadraticCurveTo(A,n,i,m){return this.currentPath.quadraticCurveTo(A,n,i,m),this}bezierCurveTo(A,n,i,m,E,G){return this.currentPath.bezierCurveTo(A,n,i,m,E,G),this}splineThru(A){return this.currentPath.splineThru(A),this}toShapes(A){function n(s){const K=[];for(let d=0,v=s.length;dNumber.EPSILON){if(T<0&&(b=K[x],P=-P,Q=K[O],T=-T),s.yQ.y)continue;if(s.y===b.y){if(s.x===b.x)return!0}else{const W=T*(s.x-b.x)-P*(s.y-b.y);if(W===0)return!0;if(W<0)continue;v=!v}}else{if(s.y!==b.y)continue;if(Q.x<=s.x&&s.x<=b.x||b.x<=s.x&&s.x<=Q.x)return!0}}return v}const m=bE.isClockWise,E=this.subPaths;if(E.length===0)return[];let G,C,t;const I=[];if(E.length===1)return C=E[0],t=new we,t.curves=C.curves,I.push(t),I;let j=!m(E[0].getPoints());j=A?!j:j;const H=[],h=[];let p=[],B=0,J;h[B]=void 0,p[B]=[];for(let s=0,K=E.length;s1){let s=!1,K=0;for(let d=0,v=h.length;d0&&s===!1&&(p=H)}let u;for(let s=0,K=h.length;sA?(o.repeat.x=1,o.repeat.y=n/A,o.offset.x=0,o.offset.y=(1-o.repeat.y)/2):(o.repeat.x=A/n,o.repeat.y=1,o.offset.x=(1-o.repeat.x)/2,o.offset.y=0),o}function hM(o,A){const n=o.image&&o.image.width?o.image.width/o.image.height:1;return n>A?(o.repeat.x=A/n,o.repeat.y=1,o.offset.x=(1-o.repeat.x)/2,o.offset.y=0):(o.repeat.x=1,o.repeat.y=n/A,o.offset.x=0,o.offset.y=(1-o.repeat.y)/2),o}function gM(o){return o.repeat.x=1,o.repeat.y=1,o.offset.x=0,o.offset.y=0,o}function kg(o,A,n,i){const m=pM(i);switch(n){case ag:return o*A;case cg:return o*A;case Jg:return o*A*2;case KH:return o*A/m.components*m.byteLength;case uD:return o*A/m.components*m.byteLength;case qg:return o*A*2/m.components*m.byteLength;case dH:return o*A*2/m.components*m.byteLength;case ug:return o*A*3/m.components*m.byteLength;case So:return o*A*4/m.components*m.byteLength;case MH:return o*A*4/m.components*m.byteLength;case Qt:case Wt:return Math.floor((o+3)/4)*Math.floor((A+3)/4)*8;case Xt:case Yt:return Math.floor((o+3)/4)*Math.floor((A+3)/4)*16;case bj:case wj:return Math.max(o,16)*Math.max(A,8)/4;case xj:case Uj:return Math.max(o,8)*Math.max(A,8)/2;case Vj:case Qj:return Math.floor((o+3)/4)*Math.floor((A+3)/4)*8;case Wj:return Math.floor((o+3)/4)*Math.floor((A+3)/4)*16;case Xj:return Math.floor((o+3)/4)*Math.floor((A+3)/4)*16;case Yj:return Math.floor((o+4)/5)*Math.floor((A+3)/4)*16;case Zj:return Math.floor((o+4)/5)*Math.floor((A+4)/5)*16;case zj:return Math.floor((o+5)/6)*Math.floor((A+4)/5)*16;case _j:return Math.floor((o+5)/6)*Math.floor((A+5)/6)*16;case $j:return Math.floor((o+7)/8)*Math.floor((A+4)/5)*16;case AH:return Math.floor((o+7)/8)*Math.floor((A+5)/6)*16;case nH:return Math.floor((o+7)/8)*Math.floor((A+7)/8)*16;case iH:return Math.floor((o+9)/10)*Math.floor((A+4)/5)*16;case mH:return Math.floor((o+9)/10)*Math.floor((A+5)/6)*16;case oH:return Math.floor((o+9)/10)*Math.floor((A+7)/8)*16;case lH:return Math.floor((o+9)/10)*Math.floor((A+9)/10)*16;case EH:return Math.floor((o+11)/12)*Math.floor((A+9)/10)*16;case kH:return Math.floor((o+11)/12)*Math.floor((A+11)/12)*16;case Zt:case GH:case eH:return Math.ceil(o/4)*Math.ceil(A/4)*16;case fg:case CH:return Math.ceil(o/4)*Math.ceil(A/4)*8;case FH:case tH:return Math.ceil(o/4)*Math.ceil(A/4)*16}throw new Error(`Unable to determine texture byte length for ${n} format.`)}function pM(o){switch(o){case BE:case pg:return{byteLength:1,components:1};case pF:case sg:case fF:return{byteLength:2,components:1};case qH:case fH:return{byteLength:2,components:4};case xk:case JH:case pl:return{byteLength:4,components:1};case Bg:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${o}.`)}const sM={contain:rM,cover:hM,fill:gM,getByteLength:kg};typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:aH}}));typeof window<"u"&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=aH);/**
+ * @license
+ * Copyright 2010-2024 Three.js Authors
+ * SPDX-License-Identifier: MIT
+ */function hc(){let o=null,A=!1,n=null,i=null;function m(E,G){n(E,G),i=o.requestAnimationFrame(m)}return{start:function(){A!==!0&&n!==null&&(i=o.requestAnimationFrame(m),A=!0)},stop:function(){o.cancelAnimationFrame(i),A=!1},setAnimationLoop:function(E){n=E},setContext:function(E){o=E}}}function BM(o){const A=new WeakMap;function n(C,t){const I=C.array,j=C.usage,H=I.byteLength,h=o.createBuffer();o.bindBuffer(t,h),o.bufferData(t,I,j),C.onUploadCallback();let p;if(I instanceof Float32Array)p=o.FLOAT;else if(I instanceof Uint16Array)C.isFloat16BufferAttribute?p=o.HALF_FLOAT:p=o.UNSIGNED_SHORT;else if(I instanceof Int16Array)p=o.SHORT;else if(I instanceof Uint32Array)p=o.UNSIGNED_INT;else if(I instanceof Int32Array)p=o.INT;else if(I instanceof Int8Array)p=o.BYTE;else if(I instanceof Uint8Array)p=o.UNSIGNED_BYTE;else if(I instanceof Uint8ClampedArray)p=o.UNSIGNED_BYTE;else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+I);return{buffer:h,type:p,bytesPerElement:I.BYTES_PER_ELEMENT,version:C.version,size:H}}function i(C,t,I){const j=t.array,H=t.updateRanges;if(o.bindBuffer(I,C),H.length===0)o.bufferSubData(I,0,j);else{H.sort((p,B)=>p.start-B.start);let h=0;for(let p=1;p 0
+ vec4 plane;
+ #ifdef ALPHA_TO_COVERAGE
+ float distanceToPlane, distanceGradient;
+ float clipOpacity = 1.0;
+ #pragma unroll_loop_start
+ for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
+ plane = clippingPlanes[ i ];
+ distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
+ distanceGradient = fwidth( distanceToPlane ) / 2.0;
+ clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
+ if ( clipOpacity == 0.0 ) discard;
+ }
+ #pragma unroll_loop_end
+ #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
+ float unionClipOpacity = 1.0;
+ #pragma unroll_loop_start
+ for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
+ plane = clippingPlanes[ i ];
+ distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
+ distanceGradient = fwidth( distanceToPlane ) / 2.0;
+ unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
+ }
+ #pragma unroll_loop_end
+ clipOpacity *= 1.0 - unionClipOpacity;
+ #endif
+ diffuseColor.a *= clipOpacity;
+ if ( diffuseColor.a == 0.0 ) discard;
+ #else
+ #pragma unroll_loop_start
+ for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
+ plane = clippingPlanes[ i ];
+ if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;
+ }
+ #pragma unroll_loop_end
+ #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
+ bool clipped = true;
+ #pragma unroll_loop_start
+ for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
+ plane = clippingPlanes[ i ];
+ clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;
+ }
+ #pragma unroll_loop_end
+ if ( clipped ) discard;
+ #endif
+ #endif
+#endif`,yM=`#if NUM_CLIPPING_PLANES > 0
+ varying vec3 vClipPosition;
+ uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
+#endif`,OM=`#if NUM_CLIPPING_PLANES > 0
+ varying vec3 vClipPosition;
+#endif`,xM=`#if NUM_CLIPPING_PLANES > 0
+ vClipPosition = - mvPosition.xyz;
+#endif`,bM=`#if defined( USE_COLOR_ALPHA )
+ diffuseColor *= vColor;
+#elif defined( USE_COLOR )
+ diffuseColor.rgb *= vColor;
+#endif`,UM=`#if defined( USE_COLOR_ALPHA )
+ varying vec4 vColor;
+#elif defined( USE_COLOR )
+ varying vec3 vColor;
+#endif`,wM=`#if defined( USE_COLOR_ALPHA )
+ varying vec4 vColor;
+#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
+ varying vec3 vColor;
+#endif`,VM=`#if defined( USE_COLOR_ALPHA )
+ vColor = vec4( 1.0 );
+#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
+ vColor = vec3( 1.0 );
+#endif
+#ifdef USE_COLOR
+ vColor *= color;
+#endif
+#ifdef USE_INSTANCING_COLOR
+ vColor.xyz *= instanceColor.xyz;
+#endif
+#ifdef USE_BATCHING_COLOR
+ vec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );
+ vColor.xyz *= batchingColor.xyz;
+#endif`,QM=`#define PI 3.141592653589793
+#define PI2 6.283185307179586
+#define PI_HALF 1.5707963267948966
+#define RECIPROCAL_PI 0.3183098861837907
+#define RECIPROCAL_PI2 0.15915494309189535
+#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; }
+vec3 pow2( const in vec3 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 max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
+float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }
+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 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;
+};
+#ifdef USE_ALPHAHASH
+ varying vec3 vPosition;
+#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 );
+}
+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;
+}
+bool isPerspectiveMatrix( mat4 m ) {
+ return m[ 2 ][ 3 ] == - 1.0;
+}
+vec2 equirectUv( in vec3 dir ) {
+ float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
+ float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
+ return vec2( u, v );
+}
+vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
+ return RECIPROCAL_PI * diffuseColor;
+}
+vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
+ float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
+ return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
+}
+float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
+ float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
+ return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
+} // validated`,WM=`#ifdef ENVMAP_TYPE_CUBE_UV
+ #define cubeUV_minMipLevel 4.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 = vec2( - direction.x, direction.y ) / abs( direction.z );
+ } else if ( face == 3.0 ) {
+ uv = vec2( - direction.z, direction.y ) / abs( direction.x );
+ } else if ( face == 4.0 ) {
+ uv = vec2( - direction.x, direction.z ) / 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 );
+ highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;
+ if ( face > 2.0 ) {
+ uv.y += faceSize;
+ face -= 3.0;
+ }
+ uv.x += face * faceSize;
+ uv.x += filterInt * 3.0 * cubeUV_minTileSize;
+ uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );
+ uv.x *= CUBEUV_TEXEL_WIDTH;
+ uv.y *= CUBEUV_TEXEL_HEIGHT;
+ #ifdef texture2DGradEXT
+ return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;
+ #else
+ return texture2D( envMap, uv ).rgb;
+ #endif
+ }
+ #define cubeUV_r0 1.0
+ #define cubeUV_m0 - 2.0
+ #define cubeUV_r1 0.8
+ #define cubeUV_m1 - 1.0
+ #define cubeUV_r4 0.4
+ #define cubeUV_m4 2.0
+ #define cubeUV_r5 0.305
+ #define cubeUV_m5 3.0
+ #define cubeUV_r6 0.21
+ #define cubeUV_m6 4.0
+ float roughnessToMip( float roughness ) {
+ float mip = 0.0;
+ if ( roughness >= cubeUV_r1 ) {
+ mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;
+ } else if ( roughness >= cubeUV_r4 ) {
+ mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;
+ } else if ( roughness >= cubeUV_r5 ) {
+ mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;
+ } else if ( roughness >= cubeUV_r6 ) {
+ mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;
+ } else {
+ mip = - 2.0 * log2( 1.16 * roughness ); }
+ return mip;
+ }
+ vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {
+ float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );
+ 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`,XM=`vec3 transformedNormal = objectNormal;
+#ifdef USE_TANGENT
+ vec3 transformedTangent = objectTangent;
+#endif
+#ifdef USE_BATCHING
+ mat3 bm = mat3( batchingMatrix );
+ transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );
+ transformedNormal = bm * transformedNormal;
+ #ifdef USE_TANGENT
+ transformedTangent = bm * transformedTangent;
+ #endif
+#endif
+#ifdef USE_INSTANCING
+ mat3 im = mat3( instanceMatrix );
+ transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );
+ transformedNormal = im * transformedNormal;
+ #ifdef USE_TANGENT
+ transformedTangent = im * transformedTangent;
+ #endif
+#endif
+transformedNormal = normalMatrix * transformedNormal;
+#ifdef FLIP_SIDED
+ transformedNormal = - transformedNormal;
+#endif
+#ifdef USE_TANGENT
+ transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;
+ #ifdef FLIP_SIDED
+ transformedTangent = - transformedTangent;
+ #endif
+#endif`,YM=`#ifdef USE_DISPLACEMENTMAP
+ uniform sampler2D displacementMap;
+ uniform float displacementScale;
+ uniform float displacementBias;
+#endif`,ZM=`#ifdef USE_DISPLACEMENTMAP
+ transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
+#endif`,zM=`#ifdef USE_EMISSIVEMAP
+ vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
+ #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE
+ emissiveColor = sRGBTransferEOTF( emissiveColor );
+ #endif
+ totalEmissiveRadiance *= emissiveColor.rgb;
+#endif`,_M=`#ifdef USE_EMISSIVEMAP
+ uniform sampler2D emissiveMap;
+#endif`,$M="gl_FragColor = linearToOutputTexel( gl_FragColor );",AL=`vec4 LinearTransferOETF( in vec4 value ) {
+ return value;
+}
+vec4 sRGBTransferEOTF( 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 sRGBTransferOETF( 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 );
+}`,nL=`#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, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
+ #else
+ vec4 envColor = vec4( 0.0 );
+ #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`,iL=`#ifdef USE_ENVMAP
+ uniform float envMapIntensity;
+ uniform float flipEnvMap;
+ uniform mat3 envMapRotation;
+ #ifdef ENVMAP_TYPE_CUBE
+ uniform samplerCube envMap;
+ #else
+ uniform sampler2D envMap;
+ #endif
+
+#endif`,mL=`#ifdef USE_ENVMAP
+ uniform float reflectivity;
+ #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
+ #define ENV_WORLDPOS
+ #endif
+ #ifdef ENV_WORLDPOS
+ varying vec3 vWorldPosition;
+ uniform float refractionRatio;
+ #else
+ varying vec3 vReflect;
+ #endif
+#endif`,oL=`#ifdef USE_ENVMAP
+ #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
+ #define ENV_WORLDPOS
+ #endif
+ #ifdef ENV_WORLDPOS
+
+ varying vec3 vWorldPosition;
+ #else
+ varying vec3 vReflect;
+ uniform float refractionRatio;
+ #endif
+#endif`,lL=`#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`,EL=`#ifdef USE_FOG
+ vFogDepth = - mvPosition.z;
+#endif`,kL=`#ifdef USE_FOG
+ varying float vFogDepth;
+#endif`,GL=`#ifdef USE_FOG
+ #ifdef FOG_EXP2
+ float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
+ #else
+ float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
+ #endif
+ gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
+#endif`,eL=`#ifdef USE_FOG
+ uniform vec3 fogColor;
+ varying float vFogDepth;
+ #ifdef FOG_EXP2
+ uniform float fogDensity;
+ #else
+ uniform float fogNear;
+ uniform float fogFar;
+ #endif
+#endif`,CL=`#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 vec3( texture2D( gradientMap, coord ).r );
+ #else
+ vec2 fw = fwidth( coord ) * 0.5;
+ return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );
+ #endif
+}`,FL=`#ifdef USE_LIGHTMAP
+ uniform sampler2D lightMap;
+ uniform float lightMapIntensity;
+#endif`,tL=`LambertMaterial material;
+material.diffuseColor = diffuseColor.rgb;
+material.specularStrength = specularStrength;`,DL=`varying vec3 vViewPosition;
+struct LambertMaterial {
+ vec3 diffuseColor;
+ float specularStrength;
+};
+void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
+ vec3 irradiance = dotNL * directLight.color;
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
+}
+void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
+}
+#define RE_Direct RE_Direct_Lambert
+#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,IL=`uniform bool receiveShadow;
+uniform vec3 ambientLightColor;
+#if defined( USE_LIGHT_PROBES )
+ uniform vec3 lightProbe[ 9 ];
+#endif
+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 vec3 normal ) {
+ vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
+ vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
+ return irradiance;
+}
+vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
+ vec3 irradiance = ambientLightColor;
+ return irradiance;
+}
+float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
+ float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
+ if ( cutoffDistance > 0.0 ) {
+ distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
+ }
+ return distanceFalloff;
+}
+float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
+ return smoothstep( coneCosine, penumbraCosine, angleCosine );
+}
+#if NUM_DIR_LIGHTS > 0
+ struct DirectionalLight {
+ vec3 direction;
+ vec3 color;
+ };
+ uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
+ void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {
+ light.color = directionalLight.color;
+ light.direction = directionalLight.direction;
+ light.visible = true;
+ }
+#endif
+#if NUM_POINT_LIGHTS > 0
+ struct PointLight {
+ vec3 position;
+ vec3 color;
+ float distance;
+ float decay;
+ };
+ uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
+ void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {
+ vec3 lVector = pointLight.position - geometryPosition;
+ light.direction = normalize( lVector );
+ float lightDistance = length( lVector );
+ light.color = pointLight.color;
+ light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
+ light.visible = ( light.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;
+ };
+ uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
+ void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {
+ vec3 lVector = spotLight.position - geometryPosition;
+ light.direction = normalize( lVector );
+ float angleCos = dot( light.direction, spotLight.direction );
+ float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
+ if ( spotAttenuation > 0.0 ) {
+ float lightDistance = length( lVector );
+ light.color = spotLight.color * spotAttenuation;
+ light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );
+ light.visible = ( light.color != vec3( 0.0 ) );
+ } else {
+ light.color = vec3( 0.0 );
+ light.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 vec3 normal ) {
+ float dotNL = dot( normal, hemiLight.direction );
+ float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
+ vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
+ return irradiance;
+ }
+#endif`,jL=`#ifdef USE_ENVMAP
+ vec3 getIBLIrradiance( const in vec3 normal ) {
+ #ifdef ENVMAP_TYPE_CUBE_UV
+ vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
+ vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );
+ return PI * envMapColor.rgb * envMapIntensity;
+ #else
+ return vec3( 0.0 );
+ #endif
+ }
+ vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
+ #ifdef ENVMAP_TYPE_CUBE_UV
+ vec3 reflectVec = reflect( - viewDir, normal );
+ reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
+ reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
+ vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );
+ return envMapColor.rgb * envMapIntensity;
+ #else
+ return vec3( 0.0 );
+ #endif
+ }
+ #ifdef USE_ANISOTROPY
+ vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
+ #ifdef ENVMAP_TYPE_CUBE_UV
+ vec3 bentNormal = cross( bitangent, viewDir );
+ bentNormal = normalize( cross( bentNormal, bitangent ) );
+ bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
+ return getIBLRadiance( viewDir, bentNormal, roughness );
+ #else
+ return vec3( 0.0 );
+ #endif
+ }
+ #endif
+#endif`,HL=`ToonMaterial material;
+material.diffuseColor = diffuseColor.rgb;`,rL=`varying vec3 vViewPosition;
+struct ToonMaterial {
+ vec3 diffuseColor;
+};
+void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
+ vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
+}
+void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
+}
+#define RE_Direct RE_Direct_Toon
+#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,hL=`BlinnPhongMaterial material;
+material.diffuseColor = diffuseColor.rgb;
+material.specularColor = specular;
+material.specularShininess = shininess;
+material.specularStrength = specularStrength;`,gL=`varying vec3 vViewPosition;
+struct BlinnPhongMaterial {
+ vec3 diffuseColor;
+ vec3 specularColor;
+ float specularShininess;
+ float specularStrength;
+};
+void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
+ vec3 irradiance = dotNL * directLight.color;
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
+ reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;
+}
+void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
+}
+#define RE_Direct RE_Direct_BlinnPhong
+#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,pL=`PhysicalMaterial material;
+material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
+vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
+float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
+material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;
+material.roughness = min( material.roughness, 1.0 );
+#ifdef IOR
+ material.ior = ior;
+ #ifdef USE_SPECULAR
+ float specularIntensityFactor = specularIntensity;
+ vec3 specularColorFactor = specularColor;
+ #ifdef USE_SPECULAR_COLORMAP
+ specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;
+ #endif
+ #ifdef USE_SPECULAR_INTENSITYMAP
+ specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;
+ #endif
+ material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );
+ #else
+ float specularIntensityFactor = 1.0;
+ vec3 specularColorFactor = vec3( 1.0 );
+ material.specularF90 = 1.0;
+ #endif
+ material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );
+#else
+ material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
+ material.specularF90 = 1.0;
+#endif
+#ifdef USE_CLEARCOAT
+ material.clearcoat = clearcoat;
+ material.clearcoatRoughness = clearcoatRoughness;
+ material.clearcoatF0 = vec3( 0.04 );
+ material.clearcoatF90 = 1.0;
+ #ifdef USE_CLEARCOATMAP
+ material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;
+ #endif
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
+ material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;
+ #endif
+ material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );
+ material.clearcoatRoughness += geometryRoughness;
+ material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
+#endif
+#ifdef USE_DISPERSION
+ material.dispersion = dispersion;
+#endif
+#ifdef USE_IRIDESCENCE
+ material.iridescence = iridescence;
+ material.iridescenceIOR = iridescenceIOR;
+ #ifdef USE_IRIDESCENCEMAP
+ material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;
+ #endif
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
+ material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;
+ #else
+ material.iridescenceThickness = iridescenceThicknessMaximum;
+ #endif
+#endif
+#ifdef USE_SHEEN
+ material.sheenColor = sheenColor;
+ #ifdef USE_SHEEN_COLORMAP
+ material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;
+ #endif
+ material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );
+ #ifdef USE_SHEEN_ROUGHNESSMAP
+ material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;
+ #endif
+#endif
+#ifdef USE_ANISOTROPY
+ #ifdef USE_ANISOTROPYMAP
+ mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );
+ vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;
+ vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;
+ #else
+ vec2 anisotropyV = anisotropyVector;
+ #endif
+ material.anisotropy = length( anisotropyV );
+ if( material.anisotropy == 0.0 ) {
+ anisotropyV = vec2( 1.0, 0.0 );
+ } else {
+ anisotropyV /= material.anisotropy;
+ material.anisotropy = saturate( material.anisotropy );
+ }
+ material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );
+ material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;
+ material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;
+#endif`,sL=`struct PhysicalMaterial {
+ vec3 diffuseColor;
+ float roughness;
+ vec3 specularColor;
+ float specularF90;
+ float dispersion;
+ #ifdef USE_CLEARCOAT
+ float clearcoat;
+ float clearcoatRoughness;
+ vec3 clearcoatF0;
+ float clearcoatF90;
+ #endif
+ #ifdef USE_IRIDESCENCE
+ float iridescence;
+ float iridescenceIOR;
+ float iridescenceThickness;
+ vec3 iridescenceFresnel;
+ vec3 iridescenceF0;
+ #endif
+ #ifdef USE_SHEEN
+ vec3 sheenColor;
+ float sheenRoughness;
+ #endif
+ #ifdef IOR
+ float ior;
+ #endif
+ #ifdef USE_TRANSMISSION
+ float transmission;
+ float transmissionAlpha;
+ float thickness;
+ float attenuationDistance;
+ vec3 attenuationColor;
+ #endif
+ #ifdef USE_ANISOTROPY
+ float anisotropy;
+ float alphaT;
+ vec3 anisotropyT;
+ vec3 anisotropyB;
+ #endif
+};
+vec3 clearcoatSpecularDirect = vec3( 0.0 );
+vec3 clearcoatSpecularIndirect = vec3( 0.0 );
+vec3 sheenSpecularDirect = vec3( 0.0 );
+vec3 sheenSpecularIndirect = vec3(0.0 );
+vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {
+ float x = clamp( 1.0 - dotVH, 0.0, 1.0 );
+ float x2 = x * x;
+ float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );
+ return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
+}
+float V_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 );
+}
+#ifdef USE_ANISOTROPY
+ float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {
+ float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );
+ float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );
+ float v = 0.5 / ( gv + gl );
+ return saturate(v);
+ }
+ float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {
+ float a2 = alphaT * alphaB;
+ highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );
+ highp float v2 = dot( v, v );
+ float w2 = a2 / v2;
+ return RECIPROCAL_PI * a2 * pow2 ( w2 );
+ }
+#endif
+#ifdef USE_CLEARCOAT
+ vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {
+ vec3 f0 = material.clearcoatF0;
+ float f90 = material.clearcoatF90;
+ float roughness = material.clearcoatRoughness;
+ float alpha = pow2( roughness );
+ vec3 halfDir = normalize( lightDir + viewDir );
+ float dotNL = saturate( dot( normal, lightDir ) );
+ float dotNV = saturate( dot( normal, viewDir ) );
+ float dotNH = saturate( dot( normal, halfDir ) );
+ float dotVH = saturate( dot( viewDir, halfDir ) );
+ vec3 F = F_Schlick( f0, f90, dotVH );
+ float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
+ float D = D_GGX( alpha, dotNH );
+ return F * ( V * D );
+ }
+#endif
+vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
+ vec3 f0 = material.specularColor;
+ float f90 = material.specularF90;
+ float roughness = material.roughness;
+ float alpha = pow2( roughness );
+ vec3 halfDir = normalize( lightDir + viewDir );
+ float dotNL = saturate( dot( normal, lightDir ) );
+ float dotNV = saturate( dot( normal, viewDir ) );
+ float dotNH = saturate( dot( normal, halfDir ) );
+ float dotVH = saturate( dot( viewDir, halfDir ) );
+ vec3 F = F_Schlick( f0, f90, dotVH );
+ #ifdef USE_IRIDESCENCE
+ F = mix( F, material.iridescenceFresnel, material.iridescence );
+ #endif
+ #ifdef USE_ANISOTROPY
+ float dotTL = dot( material.anisotropyT, lightDir );
+ float dotTV = dot( material.anisotropyT, viewDir );
+ float dotTH = dot( material.anisotropyT, halfDir );
+ float dotBL = dot( material.anisotropyB, lightDir );
+ float dotBV = dot( material.anisotropyB, viewDir );
+ float dotBH = dot( material.anisotropyB, halfDir );
+ float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );
+ float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );
+ #else
+ float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
+ float D = D_GGX( alpha, dotNH );
+ #endif
+ return F * ( V * 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 );
+}
+#if defined( USE_SHEEN )
+float D_Charlie( float roughness, float dotNH ) {
+ float alpha = pow2( roughness );
+ float invAlpha = 1.0 / alpha;
+ float cos2h = dotNH * dotNH;
+ float sin2h = max( 1.0 - cos2h, 0.0078125 );
+ return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
+}
+float V_Neubelt( float dotNV, float dotNL ) {
+ return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
+}
+vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {
+ vec3 halfDir = normalize( lightDir + viewDir );
+ float dotNL = saturate( dot( normal, lightDir ) );
+ float dotNV = saturate( dot( normal, viewDir ) );
+ float dotNH = saturate( dot( normal, halfDir ) );
+ float D = D_Charlie( sheenRoughness, dotNH );
+ float V = V_Neubelt( dotNV, dotNL );
+ return sheenColor * ( D * V );
+}
+#endif
+float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
+ float dotNV = saturate( dot( normal, viewDir ) );
+ float r2 = roughness * roughness;
+ float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;
+ float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;
+ float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );
+ return saturate( DG * RECIPROCAL_PI );
+}
+vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
+ float dotNV = saturate( dot( normal, viewDir ) );
+ const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
+ const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
+ vec4 r = roughness * c0 + c1;
+ float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
+ vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;
+ return fab;
+}
+vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
+ vec2 fab = DFGApprox( normal, viewDir, roughness );
+ return specularColor * fab.x + specularF90 * fab.y;
+}
+#ifdef USE_IRIDESCENCE
+void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
+#else
+void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
+#endif
+ vec2 fab = DFGApprox( normal, viewDir, roughness );
+ #ifdef USE_IRIDESCENCE
+ vec3 Fr = mix( specularColor, iridescenceF0, iridescence );
+ #else
+ vec3 Fr = specularColor;
+ #endif
+ vec3 FssEss = Fr * fab.x + specularF90 * fab.y;
+ float Ess = fab.x + fab.y;
+ float Ems = 1.0 - Ess;
+ vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
+ singleScatter += FssEss;
+ multiScatter += Fms * Ems;
+}
+#if NUM_RECT_AREA_LIGHTS > 0
+ void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
+ vec3 normal = geometryNormal;
+ vec3 viewDir = geometryViewDir;
+ vec3 position = geometryPosition;
+ vec3 lightPos = rectAreaLight.position;
+ vec3 halfWidth = rectAreaLight.halfWidth;
+ vec3 halfHeight = rectAreaLight.halfHeight;
+ vec3 lightColor = rectAreaLight.color;
+ float roughness = material.roughness;
+ 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 vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
+ vec3 irradiance = dotNL * directLight.color;
+ #ifdef USE_CLEARCOAT
+ float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );
+ vec3 ccIrradiance = dotNLcc * directLight.color;
+ clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );
+ #endif
+ #ifdef USE_SHEEN
+ sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );
+ #endif
+ reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
+}
+void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
+}
+void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
+ #ifdef USE_CLEARCOAT
+ clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
+ #endif
+ #ifdef USE_SHEEN
+ sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
+ #endif
+ vec3 singleScattering = vec3( 0.0 );
+ vec3 multiScattering = vec3( 0.0 );
+ vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
+ #ifdef USE_IRIDESCENCE
+ computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );
+ #else
+ computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );
+ #endif
+ vec3 totalScattering = singleScattering + multiScattering;
+ vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
+ reflectedLight.indirectSpecular += 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 );
+}`,BL=`
+vec3 geometryPosition = - vViewPosition;
+vec3 geometryNormal = normal;
+vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
+vec3 geometryClearcoatNormal = vec3( 0.0 );
+#ifdef USE_CLEARCOAT
+ geometryClearcoatNormal = clearcoatNormal;
+#endif
+#ifdef USE_IRIDESCENCE
+ float dotNVi = saturate( dot( normal, geometryViewDir ) );
+ if ( material.iridescenceThickness == 0.0 ) {
+ material.iridescence = 0.0;
+ } else {
+ material.iridescence = saturate( material.iridescence );
+ }
+ if ( material.iridescence > 0.0 ) {
+ material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );
+ material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );
+ }
+#endif
+IncidentLight directLight;
+#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
+ PointLight pointLight;
+ #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
+ PointLightShadow pointLightShadow;
+ #endif
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
+ pointLight = pointLights[ i ];
+ getPointLightInfo( pointLight, geometryPosition, directLight );
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
+ pointLightShadow = pointLightShadows[ i ];
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
+ #endif
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
+ }
+ #pragma unroll_loop_end
+#endif
+#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
+ SpotLight spotLight;
+ vec4 spotColor;
+ vec3 spotLightCoord;
+ bool inSpotLightMap;
+ #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
+ SpotLightShadow spotLightShadow;
+ #endif
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
+ spotLight = spotLights[ i ];
+ getSpotLightInfo( spotLight, geometryPosition, directLight );
+ #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
+ #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX
+ #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
+ #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS
+ #else
+ #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
+ #endif
+ #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )
+ spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;
+ inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );
+ spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );
+ directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;
+ #endif
+ #undef SPOT_LIGHT_MAP_INDEX
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
+ spotLightShadow = spotLightShadows[ i ];
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
+ #endif
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
+ }
+ #pragma unroll_loop_end
+#endif
+#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
+ DirectionalLight directionalLight;
+ #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
+ DirectionalLightShadow directionalLightShadow;
+ #endif
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
+ directionalLight = directionalLights[ i ];
+ getDirectionalLightInfo( directionalLight, directLight );
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
+ directionalLightShadow = directionalLightShadows[ i ];
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
+ #endif
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
+ }
+ #pragma unroll_loop_end
+#endif
+#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
+ RectAreaLight rectAreaLight;
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
+ rectAreaLight = rectAreaLights[ i ];
+ RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
+ }
+ #pragma unroll_loop_end
+#endif
+#if defined( RE_IndirectDiffuse )
+ vec3 iblIrradiance = vec3( 0.0 );
+ vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
+ #if defined( USE_LIGHT_PROBES )
+ irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
+ #endif
+ #if ( NUM_HEMI_LIGHTS > 0 )
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
+ irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
+ }
+ #pragma unroll_loop_end
+ #endif
+#endif
+#if defined( RE_IndirectSpecular )
+ vec3 radiance = vec3( 0.0 );
+ vec3 clearcoatRadiance = vec3( 0.0 );
+#endif`,aL=`#if defined( RE_IndirectDiffuse )
+ #ifdef USE_LIGHTMAP
+ vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
+ vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
+ irradiance += lightMapIrradiance;
+ #endif
+ #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
+ iblIrradiance += getIBLIrradiance( geometryNormal );
+ #endif
+#endif
+#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
+ #ifdef USE_ANISOTROPY
+ radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
+ #else
+ radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );
+ #endif
+ #ifdef USE_CLEARCOAT
+ clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
+ #endif
+#endif`,uL=`#if defined( RE_IndirectDiffuse )
+ RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
+#endif
+#if defined( RE_IndirectSpecular )
+ RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
+#endif`,cL=`#if defined( USE_LOGDEPTHBUF )
+ gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
+#endif`,JL=`#if defined( USE_LOGDEPTHBUF )
+ uniform float logDepthBufFC;
+ varying float vFragDepth;
+ varying float vIsPerspective;
+#endif`,qL=`#ifdef USE_LOGDEPTHBUF
+ varying float vFragDepth;
+ varying float vIsPerspective;
+#endif`,fL=`#ifdef USE_LOGDEPTHBUF
+ vFragDepth = 1.0 + gl_Position.w;
+ vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
+#endif`,KL=`#ifdef USE_MAP
+ vec4 sampledDiffuseColor = texture2D( map, vMapUv );
+ #ifdef DECODE_VIDEO_TEXTURE
+ sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );
+ #endif
+ diffuseColor *= sampledDiffuseColor;
+#endif`,dL=`#ifdef USE_MAP
+ uniform sampler2D map;
+#endif`,ML=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
+ #if defined( USE_POINTS_UV )
+ vec2 uv = vUv;
+ #else
+ vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
+ #endif
+#endif
+#ifdef USE_MAP
+ diffuseColor *= texture2D( map, uv );
+#endif
+#ifdef USE_ALPHAMAP
+ diffuseColor.a *= texture2D( alphaMap, uv ).g;
+#endif`,LL=`#if defined( USE_POINTS_UV )
+ varying vec2 vUv;
+#else
+ #if defined( USE_MAP ) || defined( USE_ALPHAMAP )
+ uniform mat3 uvTransform;
+ #endif
+#endif
+#ifdef USE_MAP
+ uniform sampler2D map;
+#endif
+#ifdef USE_ALPHAMAP
+ uniform sampler2D alphaMap;
+#endif`,vL=`float metalnessFactor = metalness;
+#ifdef USE_METALNESSMAP
+ vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
+ metalnessFactor *= texelMetalness.b;
+#endif`,SL=`#ifdef USE_METALNESSMAP
+ uniform sampler2D metalnessMap;
+#endif`,NL=`#ifdef USE_INSTANCING_MORPH
+ float morphTargetInfluences[ MORPHTARGETS_COUNT ];
+ float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
+ morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;
+ }
+#endif`,TL=`#if defined( USE_MORPHCOLORS )
+ vColor *= morphTargetBaseInfluence;
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
+ #if defined( USE_COLOR_ALPHA )
+ if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];
+ #elif defined( USE_COLOR )
+ if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
+ #endif
+ }
+#endif`,PL=`#ifdef USE_MORPHNORMALS
+ objectNormal *= morphTargetBaseInfluence;
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
+ if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];
+ }
+#endif`,RL=`#ifdef USE_MORPHTARGETS
+ #ifndef USE_INSTANCING_MORPH
+ uniform float morphTargetBaseInfluence;
+ uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
+ #endif
+ uniform sampler2DArray morphTargetsTexture;
+ uniform ivec2 morphTargetsTextureSize;
+ vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {
+ int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;
+ int y = texelIndex / morphTargetsTextureSize.x;
+ int x = texelIndex - y * morphTargetsTextureSize.x;
+ ivec3 morphUV = ivec3( x, y, morphTargetIndex );
+ return texelFetch( morphTargetsTexture, morphUV, 0 );
+ }
+#endif`,yL=`#ifdef USE_MORPHTARGETS
+ transformed *= morphTargetBaseInfluence;
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
+ if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];
+ }
+#endif`,OL=`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
+#ifdef FLAT_SHADED
+ vec3 fdx = dFdx( vViewPosition );
+ vec3 fdy = dFdy( vViewPosition );
+ vec3 normal = normalize( cross( fdx, fdy ) );
+#else
+ vec3 normal = normalize( vNormal );
+ #ifdef DOUBLE_SIDED
+ normal *= faceDirection;
+ #endif
+#endif
+#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )
+ #ifdef USE_TANGENT
+ mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
+ #else
+ mat3 tbn = getTangentFrame( - vViewPosition, normal,
+ #if defined( USE_NORMALMAP )
+ vNormalMapUv
+ #elif defined( USE_CLEARCOAT_NORMALMAP )
+ vClearcoatNormalMapUv
+ #else
+ vUv
+ #endif
+ );
+ #endif
+ #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
+ tbn[0] *= faceDirection;
+ tbn[1] *= faceDirection;
+ #endif
+#endif
+#ifdef USE_CLEARCOAT_NORMALMAP
+ #ifdef USE_TANGENT
+ mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
+ #else
+ mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );
+ #endif
+ #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )
+ tbn2[0] *= faceDirection;
+ tbn2[1] *= faceDirection;
+ #endif
+#endif
+vec3 nonPerturbedNormal = normal;`,xL=`#ifdef USE_NORMALMAP_OBJECTSPACE
+ normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
+ #ifdef FLIP_SIDED
+ normal = - normal;
+ #endif
+ #ifdef DOUBLE_SIDED
+ normal = normal * faceDirection;
+ #endif
+ normal = normalize( normalMatrix * normal );
+#elif defined( USE_NORMALMAP_TANGENTSPACE )
+ vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
+ mapN.xy *= normalScale;
+ normal = normalize( tbn * mapN );
+#elif defined( USE_BUMPMAP )
+ normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
+#endif`,bL=`#ifndef FLAT_SHADED
+ varying vec3 vNormal;
+ #ifdef USE_TANGENT
+ varying vec3 vTangent;
+ varying vec3 vBitangent;
+ #endif
+#endif`,UL=`#ifndef FLAT_SHADED
+ varying vec3 vNormal;
+ #ifdef USE_TANGENT
+ varying vec3 vTangent;
+ varying vec3 vBitangent;
+ #endif
+#endif`,wL=`#ifndef FLAT_SHADED
+ vNormal = normalize( transformedNormal );
+ #ifdef USE_TANGENT
+ vTangent = normalize( transformedTangent );
+ vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
+ #endif
+#endif`,VL=`#ifdef USE_NORMALMAP
+ uniform sampler2D normalMap;
+ uniform vec2 normalScale;
+#endif
+#ifdef USE_NORMALMAP_OBJECTSPACE
+ uniform mat3 normalMatrix;
+#endif
+#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )
+ mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {
+ vec3 q0 = dFdx( eye_pos.xyz );
+ vec3 q1 = dFdy( eye_pos.xyz );
+ vec2 st0 = dFdx( uv.st );
+ vec2 st1 = dFdy( uv.st );
+ vec3 N = surf_norm;
+ vec3 q1perp = cross( q1, N );
+ vec3 q0perp = cross( N, q0 );
+ vec3 T = q1perp * st0.x + q0perp * st1.x;
+ vec3 B = q1perp * st0.y + q0perp * st1.y;
+ float det = max( dot( T, T ), dot( B, B ) );
+ float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );
+ return mat3( T * scale, B * scale, N );
+ }
+#endif`,QL=`#ifdef USE_CLEARCOAT
+ vec3 clearcoatNormal = nonPerturbedNormal;
+#endif`,WL=`#ifdef USE_CLEARCOAT_NORMALMAP
+ vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
+ clearcoatMapN.xy *= clearcoatNormalScale;
+ clearcoatNormal = normalize( tbn2 * clearcoatMapN );
+#endif`,XL=`#ifdef USE_CLEARCOATMAP
+ uniform sampler2D clearcoatMap;
+#endif
+#ifdef USE_CLEARCOAT_NORMALMAP
+ uniform sampler2D clearcoatNormalMap;
+ uniform vec2 clearcoatNormalScale;
+#endif
+#ifdef USE_CLEARCOAT_ROUGHNESSMAP
+ uniform sampler2D clearcoatRoughnessMap;
+#endif`,YL=`#ifdef USE_IRIDESCENCEMAP
+ uniform sampler2D iridescenceMap;
+#endif
+#ifdef USE_IRIDESCENCE_THICKNESSMAP
+ uniform sampler2D iridescenceThicknessMap;
+#endif`,ZL=`#ifdef OPAQUE
+diffuseColor.a = 1.0;
+#endif
+#ifdef USE_TRANSMISSION
+diffuseColor.a *= material.transmissionAlpha;
+#endif
+gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,zL=`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 float ShiftRight8 = 1. / 256.;
+const float Inv255 = 1. / 255.;
+const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );
+const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );
+const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );
+const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );
+vec4 packDepthToRGBA( const in float v ) {
+ if( v <= 0.0 )
+ return vec4( 0., 0., 0., 0. );
+ if( v >= 1.0 )
+ return vec4( 1., 1., 1., 1. );
+ float vuf;
+ float af = modf( v * PackFactors.a, vuf );
+ float bf = modf( vuf * ShiftRight8, vuf );
+ float gf = modf( vuf * ShiftRight8, vuf );
+ return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );
+}
+vec3 packDepthToRGB( const in float v ) {
+ if( v <= 0.0 )
+ return vec3( 0., 0., 0. );
+ if( v >= 1.0 )
+ return vec3( 1., 1., 1. );
+ float vuf;
+ float bf = modf( v * PackFactors.b, vuf );
+ float gf = modf( vuf * ShiftRight8, vuf );
+ return vec3( vuf * Inv255, gf * PackUpscale, bf );
+}
+vec2 packDepthToRG( const in float v ) {
+ if( v <= 0.0 )
+ return vec2( 0., 0. );
+ if( v >= 1.0 )
+ return vec2( 1., 1. );
+ float vuf;
+ float gf = modf( v * 256., vuf );
+ return vec2( vuf * Inv255, gf );
+}
+float unpackRGBAToDepth( const in vec4 v ) {
+ return dot( v, UnpackFactors4 );
+}
+float unpackRGBToDepth( const in vec3 v ) {
+ return dot( v, UnpackFactors3 );
+}
+float unpackRGToDepth( const in vec2 v ) {
+ return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;
+}
+vec4 pack2HalfToRGBA( const in 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( const in 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 depth, const in float near, const in float far ) {
+ return depth * ( 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 depth, const in float near, const in float far ) {
+ return ( near * far ) / ( ( far - near ) * depth - far );
+}`,_L=`#ifdef PREMULTIPLIED_ALPHA
+ gl_FragColor.rgb *= gl_FragColor.a;
+#endif`,$L=`vec4 mvPosition = vec4( transformed, 1.0 );
+#ifdef USE_BATCHING
+ mvPosition = batchingMatrix * mvPosition;
+#endif
+#ifdef USE_INSTANCING
+ mvPosition = instanceMatrix * mvPosition;
+#endif
+mvPosition = modelViewMatrix * mvPosition;
+gl_Position = projectionMatrix * mvPosition;`,Av=`#ifdef DITHERING
+ gl_FragColor.rgb = dithering( gl_FragColor.rgb );
+#endif`,nv=`#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`,iv=`float roughnessFactor = roughness;
+#ifdef USE_ROUGHNESSMAP
+ vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
+ roughnessFactor *= texelRoughness.g;
+#endif`,mv=`#ifdef USE_ROUGHNESSMAP
+ uniform sampler2D roughnessMap;
+#endif`,ov=`#if NUM_SPOT_LIGHT_COORDS > 0
+ varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
+#endif
+#if NUM_SPOT_LIGHT_MAPS > 0
+ uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];
+#endif
+#ifdef USE_SHADOWMAP
+ #if NUM_DIR_LIGHT_SHADOWS > 0
+ uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
+ varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
+ struct DirectionalLightShadow {
+ float shadowIntensity;
+ float shadowBias;
+ float shadowNormalBias;
+ float shadowRadius;
+ vec2 shadowMapSize;
+ };
+ uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
+ #endif
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
+ uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
+ struct SpotLightShadow {
+ float shadowIntensity;
+ float shadowBias;
+ float shadowNormalBias;
+ float shadowRadius;
+ vec2 shadowMapSize;
+ };
+ uniform SpotLightShadow spotLightShadows[ 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 ];
+ struct PointLightShadow {
+ float shadowIntensity;
+ float shadowBias;
+ float shadowNormalBias;
+ float shadowRadius;
+ vec2 shadowMapSize;
+ float shadowCameraNear;
+ float shadowCameraFar;
+ };
+ uniform PointLightShadow pointLightShadows[ 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 shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
+ float shadow = 1.0;
+ shadowCoord.xyz /= shadowCoord.w;
+ shadowCoord.z += shadowBias;
+ bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
+ bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
+ 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 mix( 1.0, shadow, shadowIntensity );
+ }
+ 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 shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
+ float shadow = 1.0;
+ vec3 lightToPosition = shadowCoord.xyz;
+
+ float lightToPositionLength = length( lightToPosition );
+ if ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {
+ float dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias;
+ vec3 bd3D = normalize( lightToPosition );
+ vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
+ #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
+ vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
+ shadow = (
+ 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
+ shadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
+ #endif
+ }
+ return mix( 1.0, shadow, shadowIntensity );
+ }
+#endif`,lv=`#if NUM_SPOT_LIGHT_COORDS > 0
+ uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];
+ varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
+#endif
+#ifdef USE_SHADOWMAP
+ #if NUM_DIR_LIGHT_SHADOWS > 0
+ uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
+ varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
+ struct DirectionalLightShadow {
+ float shadowIntensity;
+ float shadowBias;
+ float shadowNormalBias;
+ float shadowRadius;
+ vec2 shadowMapSize;
+ };
+ uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
+ #endif
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
+ struct SpotLightShadow {
+ float shadowIntensity;
+ float shadowBias;
+ float shadowNormalBias;
+ float shadowRadius;
+ vec2 shadowMapSize;
+ };
+ uniform SpotLightShadow spotLightShadows[ 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 ];
+ struct PointLightShadow {
+ float shadowIntensity;
+ float shadowBias;
+ float shadowNormalBias;
+ float shadowRadius;
+ vec2 shadowMapSize;
+ float shadowCameraNear;
+ float shadowCameraFar;
+ };
+ uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
+ #endif
+#endif`,Ev=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
+ vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
+ vec4 shadowWorldPosition;
+#endif
+#if defined( USE_SHADOWMAP )
+ #if NUM_DIR_LIGHT_SHADOWS > 0
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
+ shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
+ vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;
+ }
+ #pragma unroll_loop_end
+ #endif
+ #if NUM_POINT_LIGHT_SHADOWS > 0
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
+ shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );
+ vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;
+ }
+ #pragma unroll_loop_end
+ #endif
+#endif
+#if NUM_SPOT_LIGHT_COORDS > 0
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {
+ shadowWorldPosition = worldPosition;
+ #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
+ shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;
+ #endif
+ vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;
+ }
+ #pragma unroll_loop_end
+#endif`,kv=`float getShadowMask() {
+ float shadow = 1.0;
+ #ifdef USE_SHADOWMAP
+ #if NUM_DIR_LIGHT_SHADOWS > 0
+ DirectionalLightShadow directionalLight;
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
+ directionalLight = directionalLightShadows[ i ];
+ shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
+ }
+ #pragma unroll_loop_end
+ #endif
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
+ SpotLightShadow spotLight;
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
+ spotLight = spotLightShadows[ i ];
+ shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
+ }
+ #pragma unroll_loop_end
+ #endif
+ #if NUM_POINT_LIGHT_SHADOWS > 0
+ PointLightShadow pointLight;
+ #pragma unroll_loop_start
+ for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
+ pointLight = pointLightShadows[ i ];
+ shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
+ }
+ #pragma unroll_loop_end
+ #endif
+ #endif
+ return shadow;
+}`,Gv=`#ifdef USE_SKINNING
+ mat4 boneMatX = getBoneMatrix( skinIndex.x );
+ mat4 boneMatY = getBoneMatrix( skinIndex.y );
+ mat4 boneMatZ = getBoneMatrix( skinIndex.z );
+ mat4 boneMatW = getBoneMatrix( skinIndex.w );
+#endif`,ev=`#ifdef USE_SKINNING
+ uniform mat4 bindMatrix;
+ uniform mat4 bindMatrixInverse;
+ uniform highp sampler2D boneTexture;
+ mat4 getBoneMatrix( const in float i ) {
+ int size = textureSize( boneTexture, 0 ).x;
+ int j = int( i ) * 4;
+ int x = j % size;
+ int y = j / size;
+ vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );
+ vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );
+ vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );
+ vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );
+ return mat4( v1, v2, v3, v4 );
+ }
+#endif`,Cv=`#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`,Fv=`#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`,tv=`float specularStrength;
+#ifdef USE_SPECULARMAP
+ vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
+ specularStrength = texelSpecular.r;
+#else
+ specularStrength = 1.0;
+#endif`,Dv=`#ifdef USE_SPECULARMAP
+ uniform sampler2D specularMap;
+#endif`,Iv=`#if defined( TONE_MAPPING )
+ gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
+#endif`,jv=`#ifndef saturate
+#define saturate( a ) clamp( a, 0.0, 1.0 )
+#endif
+uniform float toneMappingExposure;
+vec3 LinearToneMapping( vec3 color ) {
+ return saturate( toneMappingExposure * color );
+}
+vec3 ReinhardToneMapping( vec3 color ) {
+ color *= toneMappingExposure;
+ return saturate( color / ( vec3( 1.0 ) + color ) );
+}
+vec3 CineonToneMapping( 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 RRTAndODTFit( vec3 v ) {
+ vec3 a = v * ( v + 0.0245786 ) - 0.000090537;
+ vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;
+ return a / b;
+}
+vec3 ACESFilmicToneMapping( vec3 color ) {
+ const mat3 ACESInputMat = mat3(
+ vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ),
+ vec3( 0.04823, 0.01566, 0.83777 )
+ );
+ const mat3 ACESOutputMat = mat3(
+ vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ),
+ vec3( -0.07367, -0.00605, 1.07602 )
+ );
+ color *= toneMappingExposure / 0.6;
+ color = ACESInputMat * color;
+ color = RRTAndODTFit( color );
+ color = ACESOutputMat * color;
+ return saturate( color );
+}
+const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(
+ vec3( 1.6605, - 0.1246, - 0.0182 ),
+ vec3( - 0.5876, 1.1329, - 0.1006 ),
+ vec3( - 0.0728, - 0.0083, 1.1187 )
+);
+const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
+ vec3( 0.6274, 0.0691, 0.0164 ),
+ vec3( 0.3293, 0.9195, 0.0880 ),
+ vec3( 0.0433, 0.0113, 0.8956 )
+);
+vec3 agxDefaultContrastApprox( vec3 x ) {
+ vec3 x2 = x * x;
+ vec3 x4 = x2 * x2;
+ return + 15.5 * x4 * x2
+ - 40.14 * x4 * x
+ + 31.96 * x4
+ - 6.868 * x2 * x
+ + 0.4298 * x2
+ + 0.1191 * x
+ - 0.00232;
+}
+vec3 AgXToneMapping( vec3 color ) {
+ const mat3 AgXInsetMatrix = mat3(
+ vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),
+ vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),
+ vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )
+ );
+ const mat3 AgXOutsetMatrix = mat3(
+ vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),
+ vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),
+ vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )
+ );
+ const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069;
+ color *= toneMappingExposure;
+ color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
+ color = AgXInsetMatrix * color;
+ color = max( color, 1e-10 ); color = log2( color );
+ color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );
+ color = clamp( color, 0.0, 1.0 );
+ color = agxDefaultContrastApprox( color );
+ color = AgXOutsetMatrix * color;
+ color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );
+ color = LINEAR_REC2020_TO_LINEAR_SRGB * color;
+ color = clamp( color, 0.0, 1.0 );
+ return color;
+}
+vec3 NeutralToneMapping( vec3 color ) {
+ const float StartCompression = 0.8 - 0.04;
+ const float Desaturation = 0.15;
+ color *= toneMappingExposure;
+ float x = min( color.r, min( color.g, color.b ) );
+ float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
+ color -= offset;
+ float peak = max( color.r, max( color.g, color.b ) );
+ if ( peak < StartCompression ) return color;
+ float d = 1. - StartCompression;
+ float newPeak = 1. - d * d / ( peak + d - StartCompression );
+ color *= newPeak / peak;
+ float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
+ return mix( color, vec3( newPeak ), g );
+}
+vec3 CustomToneMapping( vec3 color ) { return color; }`,Hv=`#ifdef USE_TRANSMISSION
+ material.transmission = transmission;
+ material.transmissionAlpha = 1.0;
+ material.thickness = thickness;
+ material.attenuationDistance = attenuationDistance;
+ material.attenuationColor = attenuationColor;
+ #ifdef USE_TRANSMISSIONMAP
+ material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;
+ #endif
+ #ifdef USE_THICKNESSMAP
+ material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;
+ #endif
+ vec3 pos = vWorldPosition;
+ vec3 v = normalize( cameraPosition - pos );
+ vec3 n = inverseTransformDirection( normal, viewMatrix );
+ vec4 transmitted = getIBLVolumeRefraction(
+ n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,
+ pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,
+ material.attenuationColor, material.attenuationDistance );
+ material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
+ totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );
+#endif`,rv=`#ifdef USE_TRANSMISSION
+ uniform float transmission;
+ uniform float thickness;
+ uniform float attenuationDistance;
+ uniform vec3 attenuationColor;
+ #ifdef USE_TRANSMISSIONMAP
+ uniform sampler2D transmissionMap;
+ #endif
+ #ifdef USE_THICKNESSMAP
+ uniform sampler2D thicknessMap;
+ #endif
+ uniform vec2 transmissionSamplerSize;
+ uniform sampler2D transmissionSamplerMap;
+ uniform mat4 modelMatrix;
+ uniform mat4 projectionMatrix;
+ varying vec3 vWorldPosition;
+ float w0( float a ) {
+ return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );
+ }
+ float w1( float a ) {
+ return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );
+ }
+ float w2( float a ){
+ return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );
+ }
+ float w3( float a ) {
+ return ( 1.0 / 6.0 ) * ( a * a * a );
+ }
+ float g0( float a ) {
+ return w0( a ) + w1( a );
+ }
+ float g1( float a ) {
+ return w2( a ) + w3( a );
+ }
+ float h0( float a ) {
+ return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );
+ }
+ float h1( float a ) {
+ return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );
+ }
+ vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {
+ uv = uv * texelSize.zw + 0.5;
+ vec2 iuv = floor( uv );
+ vec2 fuv = fract( uv );
+ float g0x = g0( fuv.x );
+ float g1x = g1( fuv.x );
+ float h0x = h0( fuv.x );
+ float h1x = h1( fuv.x );
+ float h0y = h0( fuv.y );
+ float h1y = h1( fuv.y );
+ vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
+ vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
+ vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
+ vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
+ return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +
+ g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );
+ }
+ vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {
+ vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );
+ vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );
+ vec2 fLodSizeInv = 1.0 / fLodSize;
+ vec2 cLodSizeInv = 1.0 / cLodSize;
+ vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );
+ vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );
+ return mix( fSample, cSample, fract( lod ) );
+ }
+ vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
+ vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
+ vec3 modelScale;
+ modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
+ modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
+ modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
+ return normalize( refractionVector ) * thickness * modelScale;
+ }
+ float applyIorToRoughness( const in float roughness, const in float ior ) {
+ return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
+ }
+ vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
+ float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
+ return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );
+ }
+ vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
+ if ( isinf( attenuationDistance ) ) {
+ return vec3( 1.0 );
+ } else {
+ vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
+ vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance;
+ }
+ }
+ vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
+ const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
+ const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,
+ const in vec3 attenuationColor, const in float attenuationDistance ) {
+ vec4 transmittedLight;
+ vec3 transmittance;
+ #ifdef USE_DISPERSION
+ float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;
+ vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );
+ for ( int i = 0; i < 3; i ++ ) {
+ vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );
+ vec3 refractedRayExit = position + transmissionRay;
+ vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
+ vec2 refractionCoords = ndcPos.xy / ndcPos.w;
+ refractionCoords += 1.0;
+ refractionCoords /= 2.0;
+ vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );
+ transmittedLight[ i ] = transmissionSample[ i ];
+ transmittedLight.a += transmissionSample.a;
+ transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];
+ }
+ transmittedLight.a /= 3.0;
+ #else
+ vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
+ vec3 refractedRayExit = position + transmissionRay;
+ vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
+ vec2 refractionCoords = ndcPos.xy / ndcPos.w;
+ refractionCoords += 1.0;
+ refractionCoords /= 2.0;
+ transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
+ transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
+ #endif
+ vec3 attenuatedColor = transmittance * transmittedLight.rgb;
+ vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
+ float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;
+ return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );
+ }
+#endif`,hv=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
+ varying vec2 vUv;
+#endif
+#ifdef USE_MAP
+ varying vec2 vMapUv;
+#endif
+#ifdef USE_ALPHAMAP
+ varying vec2 vAlphaMapUv;
+#endif
+#ifdef USE_LIGHTMAP
+ varying vec2 vLightMapUv;
+#endif
+#ifdef USE_AOMAP
+ varying vec2 vAoMapUv;
+#endif
+#ifdef USE_BUMPMAP
+ varying vec2 vBumpMapUv;
+#endif
+#ifdef USE_NORMALMAP
+ varying vec2 vNormalMapUv;
+#endif
+#ifdef USE_EMISSIVEMAP
+ varying vec2 vEmissiveMapUv;
+#endif
+#ifdef USE_METALNESSMAP
+ varying vec2 vMetalnessMapUv;
+#endif
+#ifdef USE_ROUGHNESSMAP
+ varying vec2 vRoughnessMapUv;
+#endif
+#ifdef USE_ANISOTROPYMAP
+ varying vec2 vAnisotropyMapUv;
+#endif
+#ifdef USE_CLEARCOATMAP
+ varying vec2 vClearcoatMapUv;
+#endif
+#ifdef USE_CLEARCOAT_NORMALMAP
+ varying vec2 vClearcoatNormalMapUv;
+#endif
+#ifdef USE_CLEARCOAT_ROUGHNESSMAP
+ varying vec2 vClearcoatRoughnessMapUv;
+#endif
+#ifdef USE_IRIDESCENCEMAP
+ varying vec2 vIridescenceMapUv;
+#endif
+#ifdef USE_IRIDESCENCE_THICKNESSMAP
+ varying vec2 vIridescenceThicknessMapUv;
+#endif
+#ifdef USE_SHEEN_COLORMAP
+ varying vec2 vSheenColorMapUv;
+#endif
+#ifdef USE_SHEEN_ROUGHNESSMAP
+ varying vec2 vSheenRoughnessMapUv;
+#endif
+#ifdef USE_SPECULARMAP
+ varying vec2 vSpecularMapUv;
+#endif
+#ifdef USE_SPECULAR_COLORMAP
+ varying vec2 vSpecularColorMapUv;
+#endif
+#ifdef USE_SPECULAR_INTENSITYMAP
+ varying vec2 vSpecularIntensityMapUv;
+#endif
+#ifdef USE_TRANSMISSIONMAP
+ uniform mat3 transmissionMapTransform;
+ varying vec2 vTransmissionMapUv;
+#endif
+#ifdef USE_THICKNESSMAP
+ uniform mat3 thicknessMapTransform;
+ varying vec2 vThicknessMapUv;
+#endif`,gv=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
+ varying vec2 vUv;
+#endif
+#ifdef USE_MAP
+ uniform mat3 mapTransform;
+ varying vec2 vMapUv;
+#endif
+#ifdef USE_ALPHAMAP
+ uniform mat3 alphaMapTransform;
+ varying vec2 vAlphaMapUv;
+#endif
+#ifdef USE_LIGHTMAP
+ uniform mat3 lightMapTransform;
+ varying vec2 vLightMapUv;
+#endif
+#ifdef USE_AOMAP
+ uniform mat3 aoMapTransform;
+ varying vec2 vAoMapUv;
+#endif
+#ifdef USE_BUMPMAP
+ uniform mat3 bumpMapTransform;
+ varying vec2 vBumpMapUv;
+#endif
+#ifdef USE_NORMALMAP
+ uniform mat3 normalMapTransform;
+ varying vec2 vNormalMapUv;
+#endif
+#ifdef USE_DISPLACEMENTMAP
+ uniform mat3 displacementMapTransform;
+ varying vec2 vDisplacementMapUv;
+#endif
+#ifdef USE_EMISSIVEMAP
+ uniform mat3 emissiveMapTransform;
+ varying vec2 vEmissiveMapUv;
+#endif
+#ifdef USE_METALNESSMAP
+ uniform mat3 metalnessMapTransform;
+ varying vec2 vMetalnessMapUv;
+#endif
+#ifdef USE_ROUGHNESSMAP
+ uniform mat3 roughnessMapTransform;
+ varying vec2 vRoughnessMapUv;
+#endif
+#ifdef USE_ANISOTROPYMAP
+ uniform mat3 anisotropyMapTransform;
+ varying vec2 vAnisotropyMapUv;
+#endif
+#ifdef USE_CLEARCOATMAP
+ uniform mat3 clearcoatMapTransform;
+ varying vec2 vClearcoatMapUv;
+#endif
+#ifdef USE_CLEARCOAT_NORMALMAP
+ uniform mat3 clearcoatNormalMapTransform;
+ varying vec2 vClearcoatNormalMapUv;
+#endif
+#ifdef USE_CLEARCOAT_ROUGHNESSMAP
+ uniform mat3 clearcoatRoughnessMapTransform;
+ varying vec2 vClearcoatRoughnessMapUv;
+#endif
+#ifdef USE_SHEEN_COLORMAP
+ uniform mat3 sheenColorMapTransform;
+ varying vec2 vSheenColorMapUv;
+#endif
+#ifdef USE_SHEEN_ROUGHNESSMAP
+ uniform mat3 sheenRoughnessMapTransform;
+ varying vec2 vSheenRoughnessMapUv;
+#endif
+#ifdef USE_IRIDESCENCEMAP
+ uniform mat3 iridescenceMapTransform;
+ varying vec2 vIridescenceMapUv;
+#endif
+#ifdef USE_IRIDESCENCE_THICKNESSMAP
+ uniform mat3 iridescenceThicknessMapTransform;
+ varying vec2 vIridescenceThicknessMapUv;
+#endif
+#ifdef USE_SPECULARMAP
+ uniform mat3 specularMapTransform;
+ varying vec2 vSpecularMapUv;
+#endif
+#ifdef USE_SPECULAR_COLORMAP
+ uniform mat3 specularColorMapTransform;
+ varying vec2 vSpecularColorMapUv;
+#endif
+#ifdef USE_SPECULAR_INTENSITYMAP
+ uniform mat3 specularIntensityMapTransform;
+ varying vec2 vSpecularIntensityMapUv;
+#endif
+#ifdef USE_TRANSMISSIONMAP
+ uniform mat3 transmissionMapTransform;
+ varying vec2 vTransmissionMapUv;
+#endif
+#ifdef USE_THICKNESSMAP
+ uniform mat3 thicknessMapTransform;
+ varying vec2 vThicknessMapUv;
+#endif`,pv=`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
+ vUv = vec3( uv, 1 ).xy;
+#endif
+#ifdef USE_MAP
+ vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_ALPHAMAP
+ vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_LIGHTMAP
+ vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_AOMAP
+ vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_BUMPMAP
+ vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_NORMALMAP
+ vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_DISPLACEMENTMAP
+ vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_EMISSIVEMAP
+ vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_METALNESSMAP
+ vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_ROUGHNESSMAP
+ vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_ANISOTROPYMAP
+ vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_CLEARCOATMAP
+ vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_CLEARCOAT_NORMALMAP
+ vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_CLEARCOAT_ROUGHNESSMAP
+ vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_IRIDESCENCEMAP
+ vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_IRIDESCENCE_THICKNESSMAP
+ vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_SHEEN_COLORMAP
+ vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_SHEEN_ROUGHNESSMAP
+ vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_SPECULARMAP
+ vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_SPECULAR_COLORMAP
+ vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_SPECULAR_INTENSITYMAP
+ vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_TRANSMISSIONMAP
+ vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;
+#endif
+#ifdef USE_THICKNESSMAP
+ vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;
+#endif`,sv=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
+ vec4 worldPosition = vec4( transformed, 1.0 );
+ #ifdef USE_BATCHING
+ worldPosition = batchingMatrix * worldPosition;
+ #endif
+ #ifdef USE_INSTANCING
+ worldPosition = instanceMatrix * worldPosition;
+ #endif
+ worldPosition = modelMatrix * worldPosition;
+#endif`;const Bv=`varying vec2 vUv;
+uniform mat3 uvTransform;
+void main() {
+ vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
+ gl_Position = vec4( position.xy, 1.0, 1.0 );
+}`,av=`uniform sampler2D t2D;
+uniform float backgroundIntensity;
+varying vec2 vUv;
+void main() {
+ vec4 texColor = texture2D( t2D, vUv );
+ #ifdef DECODE_VIDEO_TEXTURE
+ texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
+ #endif
+ texColor.rgb *= backgroundIntensity;
+ gl_FragColor = texColor;
+ #include
+ #include
+}`,uv=`varying vec3 vWorldDirection;
+#include
+void main() {
+ vWorldDirection = transformDirection( position, modelMatrix );
+ #include
+ #include
+ gl_Position.z = gl_Position.w;
+}`,cv=`#ifdef ENVMAP_TYPE_CUBE
+ uniform samplerCube envMap;
+#elif defined( ENVMAP_TYPE_CUBE_UV )
+ uniform sampler2D envMap;
+#endif
+uniform float flipEnvMap;
+uniform float backgroundBlurriness;
+uniform float backgroundIntensity;
+uniform mat3 backgroundRotation;
+varying vec3 vWorldDirection;
+#include
+void main() {
+ #ifdef ENVMAP_TYPE_CUBE
+ vec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );
+ #elif defined( ENVMAP_TYPE_CUBE_UV )
+ vec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );
+ #else
+ vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );
+ #endif
+ texColor.rgb *= backgroundIntensity;
+ gl_FragColor = texColor;
+ #include
+ #include
+}`,Jv=`varying vec3 vWorldDirection;
+#include
+void main() {
+ vWorldDirection = transformDirection( position, modelMatrix );
+ #include
+ #include
+ gl_Position.z = gl_Position.w;
+}`,qv=`uniform samplerCube tCube;
+uniform float tFlip;
+uniform float opacity;
+varying vec3 vWorldDirection;
+void main() {
+ vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );
+ gl_FragColor = texColor;
+ gl_FragColor.a *= opacity;
+ #include
+ #include
+}`,fv=`#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+varying vec2 vHighPrecisionZW;
+void main() {
+ #include
+ #include
+ #include
+ #include
+ #ifdef USE_DISPLACEMENTMAP
+ #include
+ #include
+ #include
+ #endif
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
+ vHighPrecisionZW = gl_Position.zw;
+}`,Kv=`#if DEPTH_PACKING == 3200
+ uniform float opacity;
+#endif
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+varying vec2 vHighPrecisionZW;
+void main() {
+ vec4 diffuseColor = vec4( 1.0 );
+ #include
+ #if DEPTH_PACKING == 3200
+ diffuseColor.a = opacity;
+ #endif
+ #include
+ #include
+ #include
+ #include
+ #include
+ float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
+ #if DEPTH_PACKING == 3200
+ gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
+ #elif DEPTH_PACKING == 3201
+ gl_FragColor = packDepthToRGBA( fragCoordZ );
+ #elif DEPTH_PACKING == 3202
+ gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );
+ #elif DEPTH_PACKING == 3203
+ gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );
+ #endif
+}`,dv=`#define DISTANCE
+varying vec3 vWorldPosition;
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+void main() {
+ #include
+ #include
+ #include
+ #include
+ #ifdef USE_DISPLACEMENTMAP
+ #include
+ #include
+ #include
+ #endif
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
+ #include
+ vWorldPosition = worldPosition.xyz;
+}`,Mv=`#define DISTANCE
+uniform vec3 referencePosition;
+uniform float nearDistance;
+uniform float farDistance;
+varying vec3 vWorldPosition;
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+void main () {
+ vec4 diffuseColor = vec4( 1.0 );
+ #include
+ #include
+ #include
+ #include
+ #include
+ float dist = length( vWorldPosition - referencePosition );
+ dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
+ dist = saturate( dist );
+ gl_FragColor = packDepthToRGBA( dist );
+}`,Lv=`varying vec3 vWorldDirection;
+#include
+void main() {
+ vWorldDirection = transformDirection( position, modelMatrix );
+ #include
+ #include
+}`,vv=`uniform sampler2D tEquirect;
+varying vec3 vWorldDirection;
+#include
+void main() {
+ vec3 direction = normalize( vWorldDirection );
+ vec2 sampleUV = equirectUv( direction );
+ gl_FragColor = texture2D( tEquirect, sampleUV );
+ #include
+ #include
+}`,Sv=`uniform float scale;
+attribute float lineDistance;
+varying float vLineDistance;
+#include