@kerf-js/keel 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +16 -0
- package/README.md +306 -2
- package/package.json +59 -3
- package/src/blend-inset.ts +79 -0
- package/src/blend.ts +120 -0
- package/src/client.d.ts +9 -0
- package/src/generate/bust.ts +24 -0
- package/src/generate/bust.worker.ts +4 -0
- package/src/generate/pack.ts +69 -0
- package/src/generate/plate.ts +51 -0
- package/src/generate/plate.worker.ts +4 -0
- package/src/generate/serve.ts +56 -0
- package/src/generate/surface.ts +16 -0
- package/src/generate/surface.worker.ts +4 -0
- package/src/generate.ts +133 -0
- package/src/governor.ts +87 -0
- package/src/index.d.ts +15 -0
- package/src/index.mjs +63 -0
- package/src/lit.d.ts +384 -0
- package/src/paint-live.ts +60 -0
- package/src/paint-recipe.d.mts +29 -0
- package/src/paint-recipe.mjs +29 -0
- package/src/paint-worker.mjs +20 -0
- package/src/paint.d.mts +37 -0
- package/src/paint.mjs +180 -0
- package/src/runtime.ts +35 -0
- package/src/scene.ts +289 -0
- package/src/stage.ts +192 -0
- package/vendor/LICENSE +21 -0
- package/vendor/LICENSE-modules +21 -0
- package/vendor/NOTICE +24 -0
- package/vendor/README.md +13 -0
- package/vendor/lit.d.mts +1 -0
- package/vendor/lit.mjs +2 -0
- package/vendor/lock.json +177 -0
- package/vendor/modules/band/events.d.ts +20 -0
- package/vendor/modules/band/index.d.ts +29 -0
- package/vendor/modules/band/player.d.ts +43 -0
- package/vendor/modules/band/roll.d.ts +14 -0
- package/vendor/modules/band/score.d.ts +45 -0
- package/vendor/modules/band/styles.data.d.ts +37 -0
- package/vendor/modules/band/voices.d.ts +33 -0
- package/vendor/modules/band.d.mts +1 -0
- package/vendor/modules/band.mjs +2 -0
- package/vendor/modules/butterflies/butterflies.glsl.d.ts +2 -0
- package/vendor/modules/butterflies/flight.d.ts +68 -0
- package/vendor/modules/butterflies/index.d.ts +79 -0
- package/vendor/modules/butterflies/wing.d.ts +38 -0
- package/vendor/modules/butterflies.d.mts +1 -0
- package/vendor/modules/butterflies.inputs.json +73 -0
- package/vendor/modules/butterflies.mjs +39 -0
- package/vendor/modules/camera-rail/index.d.ts +113 -0
- package/vendor/modules/camera-rail.d.mts +1 -0
- package/vendor/modules/camera-rail.mjs +2 -0
- package/vendor/modules/device-profile/index.d.ts +47 -0
- package/vendor/modules/device-profile.d.mts +1 -0
- package/vendor/modules/device-profile.mjs +2 -0
- package/vendor/modules/lit-finish/dress.d.ts +34 -0
- package/vendor/modules/lit-finish/finish.glsl.d.ts +15 -0
- package/vendor/modules/lit-finish/index.d.ts +33 -0
- package/vendor/modules/lit-finish/lit.d.ts +52 -0
- package/vendor/modules/lit-finish/pass.d.ts +35 -0
- package/vendor/modules/lit-finish/settings.d.ts +88 -0
- package/vendor/modules/lit-finish.d.mts +1 -0
- package/vendor/modules/lit-finish.inputs.json +200 -0
- package/vendor/modules/lit-finish.mjs +267 -0
- package/vendor/modules/look/index.d.ts +159 -0
- package/vendor/modules/look.d.mts +1 -0
- package/vendor/modules/look.inputs.json +23 -0
- package/vendor/modules/look.mjs +2 -0
- package/vendor/modules/motes/index.d.ts +83 -0
- package/vendor/modules/motes/motes.glsl.d.ts +9 -0
- package/vendor/modules/motes/place.d.ts +59 -0
- package/vendor/modules/motes.d.mts +1 -0
- package/vendor/modules/motes.inputs.json +116 -0
- package/vendor/modules/motes.mjs +68 -0
- package/vendor/modules/plate-painter/dab.d.ts +44 -0
- package/vendor/modules/plate-painter/exact.d.ts +19 -0
- package/vendor/modules/plate-painter/foliage.d.ts +4 -0
- package/vendor/modules/plate-painter/gpu.d.ts +65 -0
- package/vendor/modules/plate-painter/index.d.ts +14 -0
- package/vendor/modules/plate-painter/paint.glsl.d.ts +14 -0
- package/vendor/modules/plate-painter/plan.d.ts +42 -0
- package/vendor/modules/plate-painter/recipe.d.ts +136 -0
- package/vendor/modules/plate-painter/scene.d.ts +4 -0
- package/vendor/modules/plate-painter.d.mts +1 -0
- package/vendor/modules/plate-painter.inputs.json +50 -0
- package/vendor/modules/plate-painter.mjs +384 -0
- package/vendor/modules/portrait/body.d.ts +25 -0
- package/vendor/modules/portrait/bust.d.ts +67 -0
- package/vendor/modules/portrait/cap.d.ts +12 -0
- package/vendor/modules/portrait/compile.d.ts +8 -0
- package/vendor/modules/portrait/exact.d.ts +17 -0
- package/vendor/modules/portrait/hair.d.ts +26 -0
- package/vendor/modules/portrait/hand.d.ts +30 -0
- package/vendor/modules/portrait/head.d.ts +18 -0
- package/vendor/modules/portrait/index.d.ts +12 -0
- package/vendor/modules/portrait/mesh.d.ts +24 -0
- package/vendor/modules/portrait/parts.d.ts +33 -0
- package/vendor/modules/portrait/portrait.glsl.d.ts +4 -0
- package/vendor/modules/portrait/render.d.ts +125 -0
- package/vendor/modules/portrait/sdf.d.ts +75 -0
- package/vendor/modules/portrait/settings.d.ts +27 -0
- package/vendor/modules/portrait.d.mts +1 -0
- package/vendor/modules/portrait.inputs.json +111 -0
- package/vendor/modules/portrait.mjs +2 -0
- package/vendor/modules/quality/index.d.ts +130 -0
- package/vendor/modules/quality.d.mts +1 -0
- package/vendor/modules/quality.inputs.json +34 -0
- package/vendor/modules/quality.mjs +2 -0
- package/vendor/modules/scene-blend/blend.d.ts +54 -0
- package/vendor/modules/scene-blend/blend.glsl.d.ts +8 -0
- package/vendor/modules/scene-blend/index.d.ts +25 -0
- package/vendor/modules/scene-blend/lit.d.ts +61 -0
- package/vendor/modules/scene-blend/noise.d.ts +13 -0
- package/vendor/modules/scene-blend/settings.d.ts +63 -0
- package/vendor/modules/scene-blend.d.mts +1 -0
- package/vendor/modules/scene-blend.inputs.json +133 -0
- package/vendor/modules/scene-blend.mjs +2 -0
- package/vendor/modules/section-post/index.d.ts +23 -0
- package/vendor/modules/section-post/lit.d.ts +47 -0
- package/vendor/modules/section-post/noise.d.ts +14 -0
- package/vendor/modules/section-post/post.d.ts +31 -0
- package/vendor/modules/section-post/post.glsl.d.ts +8 -0
- package/vendor/modules/section-post/settings.d.ts +84 -0
- package/vendor/modules/section-post.d.mts +1 -0
- package/vendor/modules/section-post.inputs.json +107 -0
- package/vendor/modules/section-post.mjs +53 -0
- package/vendor/modules/surfaces/exact.d.ts +8 -0
- package/vendor/modules/surfaces/field.d.ts +7 -0
- package/vendor/modules/surfaces/gpu.d.ts +19 -0
- package/vendor/modules/surfaces/index.d.ts +17 -0
- package/vendor/modules/surfaces/paint.d.ts +28 -0
- package/vendor/modules/surfaces/plan.d.ts +39 -0
- package/vendor/modules/surfaces/print.d.ts +55 -0
- package/vendor/modules/surfaces/recipe.d.ts +143 -0
- package/vendor/modules/surfaces/surface.glsl.d.ts +4 -0
- package/vendor/modules/surfaces.d.mts +1 -0
- package/vendor/modules/surfaces.inputs.json +54 -0
- package/vendor/modules/surfaces.mjs +172 -0
- package/vendor/modules/tracks/index.d.ts +66 -0
- package/vendor/modules/tracks.d.mts +1 -0
- package/vendor/modules/tracks.mjs +2 -0
- package/vendor/modules/tree-growth/bend.d.ts +28 -0
- package/vendor/modules/tree-growth/frame.d.ts +60 -0
- package/vendor/modules/tree-growth/index.d.ts +23 -0
- package/vendor/modules/tree-growth/light.d.ts +13 -0
- package/vendor/modules/tree-growth/math.d.ts +19 -0
- package/vendor/modules/tree-growth/model.d.ts +100 -0
- package/vendor/modules/tree-growth/sectors.d.ts +10 -0
- package/vendor/modules/tree-growth/simulation.d.ts +58 -0
- package/vendor/modules/tree-growth/species.d.ts +117 -0
- package/vendor/modules/tree-growth/species.data.d.ts +2 -0
- package/vendor/modules/tree-growth/year.d.ts +38 -0
- package/vendor/modules/tree-growth.d.mts +1 -0
- package/vendor/modules/tree-growth.inputs.json +75 -0
- package/vendor/modules/tree-growth.mjs +2 -0
- package/vendor/modules/tree-render/features.d.ts +9 -0
- package/vendor/modules/tree-render/forest/bake.d.ts +41 -0
- package/vendor/modules/tree-render/forest/cards.d.ts +28 -0
- package/vendor/modules/tree-render/forest/forest.d.ts +156 -0
- package/vendor/modules/tree-render/index.d.ts +52 -0
- package/vendor/modules/tree-render/inputs.d.ts +260 -0
- package/vendor/modules/tree-render/instances.d.ts +66 -0
- package/vendor/modules/tree-render/math.d.ts +8 -0
- package/vendor/modules/tree-render/tree/bark.d.ts +20 -0
- package/vendor/modules/tree-render/tree/leaves.d.ts +29 -0
- package/vendor/modules/tree-render/tree/litter.d.ts +21 -0
- package/vendor/modules/tree-render/tree/ornaments.d.ts +36 -0
- package/vendor/modules/tree-render/tree/roots.d.ts +75 -0
- package/vendor/modules/tree-render/tree/shapes.d.ts +49 -0
- package/vendor/modules/tree-render/tree/tree.d.ts +239 -0
- package/vendor/modules/tree-render/tree/wood.d.ts +27 -0
- package/vendor/modules/tree-render/wind.d.ts +51 -0
- package/vendor/modules/tree-render.d.mts +1 -0
- package/vendor/modules/tree-render.inputs.json +45 -0
- package/vendor/modules/tree-render.mjs +2 -0
- package/vendor/modules/voxel-dither/dither.glsl.d.ts +9 -0
- package/vendor/modules/voxel-dither/index.d.ts +35 -0
- package/vendor/modules/voxel-dither/light.d.ts +33 -0
- package/vendor/modules/voxel-dither/lit.d.ts +86 -0
- package/vendor/modules/voxel-dither/pass.d.ts +46 -0
- package/vendor/modules/voxel-dither/screens.d.ts +21 -0
- package/vendor/modules/voxel-dither/settings.d.ts +307 -0
- package/vendor/modules/voxel-dither/signals.d.ts +35 -0
- package/vendor/modules/voxel-dither.d.mts +1 -0
- package/vendor/modules/voxel-dither.inputs.json +295 -0
- package/vendor/modules/voxel-dither.mjs +452 -0
- package/vendor/modules/world-light/index.d.ts +133 -0
- package/vendor/modules/world-light.d.mts +1 -0
- package/vendor/modules/world-light.inputs.json +68 -0
- package/vendor/modules/world-light.mjs +2 -0
package/vendor/lit.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// keel/lit from keel-engine af03486 (MIT). Ports Three.js r180 (MIT): see NOTICE. Generated: don't edit.
|
|
2
|
+
var za=Object.defineProperty;var Ba=(r,e)=>{for(var t in e)za(r,t,{get:e[t],enumerable:!0})};var to=795580957;function Ye(){let r=to+=1831565813;return r=Math.imul(r^r>>>15,r|1),r^=r+Math.imul(r^r>>>7,r|61),((r^r>>>14)>>>0)/4294967296}function Ga(r){to=r|0}var ft=Array.from({length:256},(r,e)=>(e<16?"0":"")+e.toString(16)),eo=1234567,Tr=Math.PI/180,kr=180/Math.PI;function yt(){let r=Ye()*4294967295|0,e=Ye()*4294967295|0,t=Ye()*4294967295|0,n=Ye()*4294967295|0;return(ft[r&255]+ft[r>>8&255]+ft[r>>16&255]+ft[r>>24&255]+"-"+ft[e&255]+ft[e>>8&255]+"-"+ft[e>>16&15|64]+ft[e>>24&255]+"-"+ft[t&63|128]+ft[t>>8&255]+"-"+ft[t>>16&255]+ft[t>>24&255]+ft[n&255]+ft[n>>8&255]+ft[n>>16&255]+ft[n>>24&255]).toLowerCase()}function ve(r,e,t){return Math.max(e,Math.min(t,r))}function pn(r,e){return(r%e+e)%e}function Ha(r,e,t,n,i){return n+(r-e)*(i-n)/(t-e)}function Wa(r,e,t){return r!==e?(t-r)/(e-r):0}function Ar(r,e,t){return(1-t)*r+t*e}function Xa(r,e,t,n){return Ar(r,e,1-Math.exp(-t*n))}function qa(r,e=1){return e-Math.abs(pn(r,e*2)-e)}function Ya(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function ja(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function Za(r,e){return r+Math.floor(Ye()*(e-r+1))}function Ka(r,e){return r+Ye()*(e-r)}function Qa(r){return r*(.5-Ye())}function $a(r){r!==void 0&&(eo=r);let e=eo+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function Ja(r){return r*Tr}function es(r){return r*kr}function ts(r){return(r&r-1)===0&&r!==0}function rs(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function ns(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function is(r,e,t,n,i){let o=Math.cos,a=Math.sin,s=o(t/2),l=a(t/2),c=o((e+n)/2),d=a((e+n)/2),u=o((e-n)/2),h=a((e-n)/2),m=o((n-e)/2),f=a((n-e)/2);switch(i){case"XYX":r.set(s*d,l*u,l*h,s*c);break;case"YZY":r.set(l*h,s*d,l*u,s*c);break;case"ZXZ":r.set(l*u,l*h,s*d,s*c);break;case"XZX":r.set(s*d,l*f,l*m,s*c);break;case"YXY":r.set(l*m,s*d,l*f,s*c);break;case"ZYZ":r.set(l*f,l*m,s*d,s*c);break;default:console.warn("keel/lit mathUtils: setQuaternionFromProperEuler() met an unknown order: "+i)}}function sr(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function pt(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}var os={DEG2RAD:Tr,RAD2DEG:kr,generateUUID:yt,clamp:ve,euclideanModulo:pn,mapLinear:Ha,inverseLerp:Wa,lerp:Ar,damp:Xa,pingpong:qa,smoothstep:Ya,smootherstep:ja,randInt:Za,randFloat:Ka,randFloatSpread:Qa,seededRandom:$a,degToRad:Ja,radToDeg:es,isPowerOfTwo:ts,ceilPowerOfTwo:rs,floorPowerOfTwo:ns,setQuaternionFromProperEuler:is,normalize:pt,denormalize:sr,reseedRandom:Ga};var W=class{x;y;constructor(e=0,t=0){this.x=e,this.y=t}get isVector2(){return!0}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){let t=this.x,n=this.y,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6],this.y=i[1]*t+i[4]*n+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=ve(this.x,e.x,t.x),this.y=ve(this.y,e.y,t.y),this}clampScalar(e,t){return this.x=ve(this.x,e,t),this.y=ve(this.y,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(ve(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(ve(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){let n=Math.cos(t),i=Math.sin(t),o=this.x-e.x,a=this.y-e.y;return this.x=o*n-a*i+e.x,this.y=o*i+a*n+e.y,this}random(){return this.x=Ye(),this.y=Ye(),this}*[Symbol.iterator](){yield this.x,yield this.y}};var Pt=class{isQuaternion=!0;_x;_y;_z;_w;constructor(e=0,t=0,n=0,i=1){this._x=e,this._y=t,this._z=n,this._w=i}static slerpFlat(e,t,n,i,o,a,s){let l=n[i+0],c=n[i+1],d=n[i+2],u=n[i+3],h=o[a+0],m=o[a+1],f=o[a+2],g=o[a+3];if(s===0){e[t+0]=l,e[t+1]=c,e[t+2]=d,e[t+3]=u;return}if(s===1){e[t+0]=h,e[t+1]=m,e[t+2]=f,e[t+3]=g;return}if(u!==g||l!==h||c!==m||d!==f){let v=1-s,M=l*h+c*m+d*f+u*g,T=M>=0?1:-1,_=1-M*M;if(_>Number.EPSILON){let U=Math.sqrt(_),w=Math.atan2(U,M*T);v=Math.sin(v*w)/U,s=Math.sin(s*w)/U}let A=s*T;if(l=l*v+h*A,c=c*v+m*A,d=d*v+f*A,u=u*v+g*A,v===1-s){let U=1/Math.sqrt(l*l+c*c+d*d+u*u);l*=U,c*=U,d*=U,u*=U}}e[t]=l,e[t+1]=c,e[t+2]=d,e[t+3]=u}static multiplyQuaternionsFlat(e,t,n,i,o,a){let s=n[i],l=n[i+1],c=n[i+2],d=n[i+3],u=o[a],h=o[a+1],m=o[a+2],f=o[a+3];return e[t]=s*f+d*u+l*m-c*h,e[t+1]=l*f+d*h+c*u-s*m,e[t+2]=c*f+d*m+s*h-l*u,e[t+3]=d*f-s*u-l*h-c*m,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,i){return this._x=e,this._y=t,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){let n=e._x,i=e._y,o=e._z,a=e._order,s=Math.cos,l=Math.sin,c=s(n/2),d=s(i/2),u=s(o/2),h=l(n/2),m=l(i/2),f=l(o/2);switch(a){case"XYZ":this._x=h*d*u+c*m*f,this._y=c*m*u-h*d*f,this._z=c*d*f+h*m*u,this._w=c*d*u-h*m*f;break;case"YXZ":this._x=h*d*u+c*m*f,this._y=c*m*u-h*d*f,this._z=c*d*f-h*m*u,this._w=c*d*u+h*m*f;break;case"ZXY":this._x=h*d*u-c*m*f,this._y=c*m*u+h*d*f,this._z=c*d*f+h*m*u,this._w=c*d*u-h*m*f;break;case"ZYX":this._x=h*d*u-c*m*f,this._y=c*m*u+h*d*f,this._z=c*d*f-h*m*u,this._w=c*d*u+h*m*f;break;case"YZX":this._x=h*d*u+c*m*f,this._y=c*m*u+h*d*f,this._z=c*d*f-h*m*u,this._w=c*d*u-h*m*f;break;case"XZY":this._x=h*d*u-c*m*f,this._y=c*m*u-h*d*f,this._z=c*d*f+h*m*u,this._w=c*d*u+h*m*f;break;default:console.warn("keel/lit Quaternion: setFromEuler() met an unknown order: "+String(a))}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){let n=t/2,i=Math.sin(n);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){let t=e.elements,n=t[0],i=t[4],o=t[8],a=t[1],s=t[5],l=t[9],c=t[2],d=t[6],u=t[10],h=n+s+u;if(h>0){let m=.5/Math.sqrt(h+1);this._w=.25/m,this._x=(d-l)*m,this._y=(o-c)*m,this._z=(a-i)*m}else if(n>s&&n>u){let m=2*Math.sqrt(1+n-s-u);this._w=(d-l)/m,this._x=.25*m,this._y=(i+a)/m,this._z=(o+c)/m}else if(s>u){let m=2*Math.sqrt(1+s-n-u);this._w=(o-c)/m,this._x=(i+a)/m,this._y=.25*m,this._z=(l+d)/m}else{let m=2*Math.sqrt(1+u-n-s);this._w=(a-i)/m,this._x=(o+c)/m,this._y=(l+d)/m,this._z=.25*m}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<1e-8?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(ve(this.dot(e),-1,1)))}rotateTowards(e,t){let n=this.angleTo(e);if(n===0)return this;let i=Math.min(1,t/n);return this.slerp(e,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){let n=e._x,i=e._y,o=e._z,a=e._w,s=t._x,l=t._y,c=t._z,d=t._w;return this._x=n*d+a*s+i*c-o*l,this._y=i*d+a*l+o*s-n*c,this._z=o*d+a*c+n*l-i*s,this._w=a*d-n*s-i*l-o*c,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);let n=this._x,i=this._y,o=this._z,a=this._w,s=a*e._w+n*e._x+i*e._y+o*e._z;if(s<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,s=-s):this.copy(e),s>=1)return this._w=a,this._x=n,this._y=i,this._z=o,this;let l=1-s*s;if(l<=Number.EPSILON){let m=1-t;return this._w=m*a+t*this._w,this._x=m*n+t*this._x,this._y=m*i+t*this._y,this._z=m*o+t*this._z,this.normalize(),this}let c=Math.sqrt(l),d=Math.atan2(c,s),u=Math.sin((1-t)*d)/c,h=Math.sin(t*d)/c;return this._w=a*u+this._w*h,this._x=n*u+this._x*h,this._y=i*u+this._y*h,this._z=o*u+this._z*h,this._onChangeCallback(),this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){let e=2*Math.PI*Ye(),t=2*Math.PI*Ye(),n=Ye(),i=Math.sqrt(1-n),o=Math.sqrt(n);return this.set(i*Math.sin(e),i*Math.cos(e),o*Math.sin(t),o*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}};var L=class{x;y;z;constructor(e=0,t=0,n=0){this.x=e,this.y=t,this.z=n}get isVector3(){return!0}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(ro.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(ro.setFromAxisAngle(e,t))}applyMatrix3(e){let t=this.x,n=this.y,i=this.z,o=e.elements;return this.x=o[0]*t+o[3]*n+o[6]*i,this.y=o[1]*t+o[4]*n+o[7]*i,this.z=o[2]*t+o[5]*n+o[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){let t=this.x,n=this.y,i=this.z,o=e.elements,a=1/(o[3]*t+o[7]*n+o[11]*i+o[15]);return this.x=(o[0]*t+o[4]*n+o[8]*i+o[12])*a,this.y=(o[1]*t+o[5]*n+o[9]*i+o[13])*a,this.z=(o[2]*t+o[6]*n+o[10]*i+o[14])*a,this}applyQuaternion(e){let t=this.x,n=this.y,i=this.z,o=e.x,a=e.y,s=e.z,l=e.w,c=2*(a*i-s*n),d=2*(s*t-o*i),u=2*(o*n-a*t);return this.x=t+l*c+a*u-s*d,this.y=n+l*d+s*c-o*u,this.z=i+l*u+o*d-a*c,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){let t=this.x,n=this.y,i=this.z,o=e.elements;return this.x=o[0]*t+o[4]*n+o[8]*i,this.y=o[1]*t+o[5]*n+o[9]*i,this.z=o[2]*t+o[6]*n+o[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=ve(this.x,e.x,t.x),this.y=ve(this.y,e.y,t.y),this.z=ve(this.z,e.z,t.z),this}clampScalar(e,t){return this.x=ve(this.x,e,t),this.y=ve(this.y,e,t),this.z=ve(this.z,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(ve(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){let n=e.x,i=e.y,o=e.z,a=t.x,s=t.y,l=t.z;return this.x=i*l-o*s,this.y=o*a-n*l,this.z=n*s-i*a,this}projectOnVector(e){let t=e.lengthSq();if(t===0)return this.set(0,0,0);let n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return Xn.copy(this).projectOnVector(e),this.sub(Xn)}reflect(e){return this.sub(Xn.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){let t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;let n=this.dot(e)/t;return Math.acos(ve(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){let t=this.x-e.x,n=this.y-e.y,i=this.z-e.z;return t*t+n*n+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,n){let i=Math.sin(t)*e;return this.x=i*Math.sin(n),this.y=Math.cos(t)*e,this.z=i*Math.cos(n),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){let t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Ye(),this.y=Ye(),this.z=Ye(),this}randomDirection(){let e=Ye()*Math.PI*2,t=Ye()*2-1,n=Math.sqrt(1-t*t);return this.x=n*Math.cos(e),this.y=t,this.z=n*Math.sin(e),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}},Xn=new L,ro=new Pt;var Ze=class{x;y;z;w;constructor(e=0,t=0,n=0,i=1){this.x=e,this.y=t,this.z=n,this.w=i}get isVector4(){return!0}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,i){return this.x=e,this.y=t,this.z=n,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){let t=this.x,n=this.y,i=this.z,o=this.w,a=e.elements;return this.x=a[0]*t+a[4]*n+a[8]*i+a[12]*o,this.y=a[1]*t+a[5]*n+a[9]*i+a[13]*o,this.z=a[2]*t+a[6]*n+a[10]*i+a[14]*o,this.w=a[3]*t+a[7]*n+a[11]*i+a[15]*o,this}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this.w/=e.w,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);let t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,i,o,l=e.elements,c=l[0],d=l[4],u=l[8],h=l[1],m=l[5],f=l[9],g=l[2],v=l[6],M=l[10];if(Math.abs(d-h)<.01&&Math.abs(u-g)<.01&&Math.abs(f-v)<.01){if(Math.abs(d+h)<.1&&Math.abs(u+g)<.1&&Math.abs(f+v)<.1&&Math.abs(c+m+M-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;let _=(c+1)/2,A=(m+1)/2,U=(M+1)/2,w=(d+h)/4,E=(u+g)/4,p=(f+v)/4;return _>A&&_>U?_<.01?(n=0,i=.707106781,o=.707106781):(n=Math.sqrt(_),i=w/n,o=E/n):A>U?A<.01?(n=.707106781,i=0,o=.707106781):(i=Math.sqrt(A),n=w/i,o=p/i):U<.01?(n=.707106781,i=.707106781,o=0):(o=Math.sqrt(U),n=E/o,i=p/o),this.set(n,i,o,t),this}let T=Math.sqrt((v-f)*(v-f)+(u-g)*(u-g)+(h-d)*(h-d));return Math.abs(T)<.001&&(T=1),this.x=(v-f)/T,this.y=(u-g)/T,this.z=(h-d)/T,this.w=Math.acos((c+m+M-1)/2),this}setFromMatrixPosition(e){let t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this.w=t[15],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=ve(this.x,e.x,t.x),this.y=ve(this.y,e.y,t.y),this.z=ve(this.z,e.z,t.z),this.w=ve(this.w,e.w,t.w),this}clampScalar(e,t){return this.x=ve(this.x,e,t),this.y=ve(this.y,e,t),this.z=ve(this.z,e,t),this.w=ve(this.w,e,t),this}clampLength(e,t){let n=this.length();return this.divideScalar(n||1).multiplyScalar(ve(n,e,t))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Ye(),this.y=Ye(),this.z=Ye(),this.w=Ye(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}};var rt=class{elements;constructor(e,t,n,i,o,a,s,l,c){this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,i,o,a,s,l,c)}get isMatrix3(){return!0}set(e,t,n,i,o,a,s,l,c){let d=this.elements;return d[0]=e,d[1]=i,d[2]=s,d[3]=t,d[4]=o,d[5]=l,d[6]=n,d[7]=a,d[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){let t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,i=t.elements,o=this.elements,a=n[0],s=n[3],l=n[6],c=n[1],d=n[4],u=n[7],h=n[2],m=n[5],f=n[8],g=i[0],v=i[3],M=i[6],T=i[1],_=i[4],A=i[7],U=i[2],w=i[5],E=i[8];return o[0]=a*g+s*T+l*U,o[3]=a*v+s*_+l*w,o[6]=a*M+s*A+l*E,o[1]=c*g+d*T+u*U,o[4]=c*v+d*_+u*w,o[7]=c*M+d*A+u*E,o[2]=h*g+m*T+f*U,o[5]=h*v+m*_+f*w,o[8]=h*M+m*A+f*E,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[1],i=e[2],o=e[3],a=e[4],s=e[5],l=e[6],c=e[7],d=e[8];return t*a*d-t*s*c-n*o*d+n*s*l+i*o*c-i*a*l}invert(){let e=this.elements,t=e[0],n=e[1],i=e[2],o=e[3],a=e[4],s=e[5],l=e[6],c=e[7],d=e[8],u=d*a-s*c,h=s*l-d*o,m=c*o-a*l,f=t*u+n*h+i*m;if(f===0)return this.set(0,0,0,0,0,0,0,0,0);let g=1/f;return e[0]=u*g,e[1]=(i*c-d*n)*g,e[2]=(s*n-i*a)*g,e[3]=h*g,e[4]=(d*t-i*l)*g,e[5]=(i*o-s*t)*g,e[6]=m*g,e[7]=(n*l-c*t)*g,e[8]=(a*t-n*o)*g,this}transpose(){let e,t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){let t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,i,o,a,s){let l=Math.cos(o),c=Math.sin(o);return this.set(n*l,n*c,-n*(l*a+c*s)+a+e,-i*c,i*l,-i*(-c*a+l*s)+s+t,0,0,1),this}scale(e,t){return this.premultiply(qn.makeScale(e,t)),this}rotate(e){return this.premultiply(qn.makeRotation(-e)),this}translate(e,t){return this.premultiply(qn.makeTranslation(e,t)),this}makeTranslation(e,t){return typeof e=="object"&&e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){let t=this.elements,n=e.elements;for(let i=0;i<9;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new this.constructor().fromArray(this.elements)}},qn=new rt;var Ve=class r{elements;constructor(e,t,n,i,o,a,s,l,c,d,u,h,m,f,g,v){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,n,i,o,a,s,l,c,d,u,h,m,f,g,v)}get isMatrix4(){return!0}set(e,t,n,i,o,a,s,l,c,d,u,h,m,f,g,v){let M=this.elements;return M[0]=e,M[4]=t,M[8]=n,M[12]=i,M[1]=o,M[5]=a,M[9]=s,M[13]=l,M[2]=c,M[6]=d,M[10]=u,M[14]=h,M[3]=m,M[7]=f,M[11]=g,M[15]=v,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new r().fromArray(this.elements)}copy(e){let t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){let t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){let t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){let t=this.elements,n=e.elements,i=1/Er.setFromMatrixColumn(e,0).length(),o=1/Er.setFromMatrixColumn(e,1).length(),a=1/Er.setFromMatrixColumn(e,2).length();return t[0]=n[0]*i,t[1]=n[1]*i,t[2]=n[2]*i,t[3]=0,t[4]=n[4]*o,t[5]=n[5]*o,t[6]=n[6]*o,t[7]=0,t[8]=n[8]*a,t[9]=n[9]*a,t[10]=n[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){let t=this.elements,n=e.x,i=e.y,o=e.z,a=Math.cos(n),s=Math.sin(n),l=Math.cos(i),c=Math.sin(i),d=Math.cos(o),u=Math.sin(o);if(e.order==="XYZ"){let h=a*d,m=a*u,f=s*d,g=s*u;t[0]=l*d,t[4]=-l*u,t[8]=c,t[1]=m+f*c,t[5]=h-g*c,t[9]=-s*l,t[2]=g-h*c,t[6]=f+m*c,t[10]=a*l}else if(e.order==="YXZ"){let h=l*d,m=l*u,f=c*d,g=c*u;t[0]=h+g*s,t[4]=f*s-m,t[8]=a*c,t[1]=a*u,t[5]=a*d,t[9]=-s,t[2]=m*s-f,t[6]=g+h*s,t[10]=a*l}else if(e.order==="ZXY"){let h=l*d,m=l*u,f=c*d,g=c*u;t[0]=h-g*s,t[4]=-a*u,t[8]=f+m*s,t[1]=m+f*s,t[5]=a*d,t[9]=g-h*s,t[2]=-a*c,t[6]=s,t[10]=a*l}else if(e.order==="ZYX"){let h=a*d,m=a*u,f=s*d,g=s*u;t[0]=l*d,t[4]=f*c-m,t[8]=h*c+g,t[1]=l*u,t[5]=g*c+h,t[9]=m*c-f,t[2]=-c,t[6]=s*l,t[10]=a*l}else if(e.order==="YZX"){let h=a*l,m=a*c,f=s*l,g=s*c;t[0]=l*d,t[4]=g-h*u,t[8]=f*u+m,t[1]=u,t[5]=a*d,t[9]=-s*d,t[2]=-c*d,t[6]=m*u+f,t[10]=h-g*u}else if(e.order==="XZY"){let h=a*l,m=a*c,f=s*l,g=s*c;t[0]=l*d,t[4]=-u,t[8]=c*d,t[1]=h*u+g,t[5]=a*d,t[9]=m*u-f,t[2]=f*u-m,t[6]=s*d,t[10]=g*u+h}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(as,e,ss)}lookAt(e,t,n){let i=this.elements;return Mt.subVectors(e,t),Mt.lengthSq()===0&&(Mt.z=1),Mt.normalize(),Kt.crossVectors(n,Mt),Kt.lengthSq()===0&&(Math.abs(n.z)===1?Mt.x+=1e-4:Mt.z+=1e-4,Mt.normalize(),Kt.crossVectors(n,Mt)),Kt.normalize(),gn.crossVectors(Mt,Kt),i[0]=Kt.x,i[4]=gn.x,i[8]=Mt.x,i[1]=Kt.y,i[5]=gn.y,i[9]=Mt.y,i[2]=Kt.z,i[6]=gn.z,i[10]=Mt.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){let n=e.elements,i=t.elements,o=this.elements,a=n[0],s=n[4],l=n[8],c=n[12],d=n[1],u=n[5],h=n[9],m=n[13],f=n[2],g=n[6],v=n[10],M=n[14],T=n[3],_=n[7],A=n[11],U=n[15],w=i[0],E=i[4],p=i[8],y=i[12],R=i[1],D=i[5],F=i[9],G=i[13],B=i[2],Z=i[6],re=i[10],oe=i[14],Y=i[3],ae=i[7],he=i[11],me=i[15];return o[0]=a*w+s*R+l*B+c*Y,o[4]=a*E+s*D+l*Z+c*ae,o[8]=a*p+s*F+l*re+c*he,o[12]=a*y+s*G+l*oe+c*me,o[1]=d*w+u*R+h*B+m*Y,o[5]=d*E+u*D+h*Z+m*ae,o[9]=d*p+u*F+h*re+m*he,o[13]=d*y+u*G+h*oe+m*me,o[2]=f*w+g*R+v*B+M*Y,o[6]=f*E+g*D+v*Z+M*ae,o[10]=f*p+g*F+v*re+M*he,o[14]=f*y+g*G+v*oe+M*me,o[3]=T*w+_*R+A*B+U*Y,o[7]=T*E+_*D+A*Z+U*ae,o[11]=T*p+_*F+A*re+U*he,o[15]=T*y+_*G+A*oe+U*me,this}multiplyScalar(e){let t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){let e=this.elements,t=e[0],n=e[4],i=e[8],o=e[12],a=e[1],s=e[5],l=e[9],c=e[13],d=e[2],u=e[6],h=e[10],m=e[14],f=e[3],g=e[7],v=e[11],M=e[15];return f*(+o*l*u-i*c*u-o*s*h+n*c*h+i*s*m-n*l*m)+g*(+t*l*m-t*c*h+o*a*h-i*a*m+i*c*d-o*l*d)+v*(+t*c*u-t*s*m-o*a*u+n*a*m+o*s*d-n*c*d)+M*(-i*s*d-t*l*u+t*s*h+i*a*u-n*a*h+n*l*d)}transpose(){let e=this.elements,t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){let i=this.elements;return typeof e=="object"&&e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=n),this}invert(){let e=this.elements,t=e[0],n=e[1],i=e[2],o=e[3],a=e[4],s=e[5],l=e[6],c=e[7],d=e[8],u=e[9],h=e[10],m=e[11],f=e[12],g=e[13],v=e[14],M=e[15],T=u*v*c-g*h*c+g*l*m-s*v*m-u*l*M+s*h*M,_=f*h*c-d*v*c-f*l*m+a*v*m+d*l*M-a*h*M,A=d*g*c-f*u*c+f*s*m-a*g*m-d*s*M+a*u*M,U=f*u*l-d*g*l-f*s*h+a*g*h+d*s*v-a*u*v,w=t*T+n*_+i*A+o*U;if(w===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);let E=1/w;return e[0]=T*E,e[1]=(g*h*o-u*v*o-g*i*m+n*v*m+u*i*M-n*h*M)*E,e[2]=(s*v*o-g*l*o+g*i*c-n*v*c-s*i*M+n*l*M)*E,e[3]=(u*l*o-s*h*o-u*i*c+n*h*c+s*i*m-n*l*m)*E,e[4]=_*E,e[5]=(d*v*o-f*h*o+f*i*m-t*v*m-d*i*M+t*h*M)*E,e[6]=(f*l*o-a*v*o-f*i*c+t*v*c+a*i*M-t*l*M)*E,e[7]=(a*h*o-d*l*o+d*i*c-t*h*c-a*i*m+t*l*m)*E,e[8]=A*E,e[9]=(f*u*o-d*g*o-f*n*m+t*g*m+d*n*M-t*u*M)*E,e[10]=(a*g*o-f*s*o+f*n*c-t*g*c-a*n*M+t*s*M)*E,e[11]=(d*s*o-a*u*o-d*n*c+t*u*c+a*n*m-t*s*m)*E,e[12]=U*E,e[13]=(d*g*i-f*u*i+f*n*h-t*g*h-d*n*v+t*u*v)*E,e[14]=(f*s*i-a*g*i-f*n*l+t*g*l+a*n*v-t*s*v)*E,e[15]=(a*u*i-d*s*i+d*n*l-t*u*l-a*n*h+t*s*h)*E,this}scale(e){let t=this.elements,n=e.x,i=e.y,o=e.z;return t[0]*=n,t[4]*=i,t[8]*=o,t[1]*=n,t[5]*=i,t[9]*=o,t[2]*=n,t[6]*=i,t[10]*=o,t[3]*=n,t[7]*=i,t[11]*=o,this}getMaxScaleOnAxis(){let e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,i))}makeTranslation(e,t,n){return typeof e=="object"&&e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){let t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){let t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){let n=Math.cos(t),i=Math.sin(t),o=1-n,a=e.x,s=e.y,l=e.z,c=o*a,d=o*s;return this.set(c*a+n,c*s-i*l,c*l+i*s,0,c*s+i*l,d*s+n,d*l-i*a,0,c*l-i*s,d*l+i*a,o*l*l+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,i,o,a){return this.set(1,n,o,0,e,1,a,0,t,i,1,0,0,0,0,1),this}compose(e,t,n){let i=this.elements,o=t._x,a=t._y,s=t._z,l=t._w,c=o+o,d=a+a,u=s+s,h=o*c,m=o*d,f=o*u,g=a*d,v=a*u,M=s*u,T=l*c,_=l*d,A=l*u,U=n.x,w=n.y,E=n.z;return i[0]=(1-(g+M))*U,i[1]=(m+A)*U,i[2]=(f-_)*U,i[3]=0,i[4]=(m-A)*w,i[5]=(1-(h+M))*w,i[6]=(v+T)*w,i[7]=0,i[8]=(f+_)*E,i[9]=(v-T)*E,i[10]=(1-(h+g))*E,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,n){let i=this.elements,o=Er.set(i[0],i[1],i[2]).length(),a=Er.set(i[4],i[5],i[6]).length(),s=Er.set(i[8],i[9],i[10]).length();this.determinant()<0&&(o=-o),e.x=i[12],e.y=i[13],e.z=i[14],Ut.copy(this);let c=1/o,d=1/a,u=1/s;return Ut.elements[0]*=c,Ut.elements[1]*=c,Ut.elements[2]*=c,Ut.elements[4]*=d,Ut.elements[5]*=d,Ut.elements[6]*=d,Ut.elements[8]*=u,Ut.elements[9]*=u,Ut.elements[10]*=u,t.setFromRotationMatrix(Ut),n.x=o,n.y=a,n.z=s,this}makePerspective(e,t,n,i,o,a,s="webgl",l=!1){let c=this.elements,d=2*o/(t-e),u=2*o/(n-i),h=(t+e)/(t-e),m=(n+i)/(n-i),f,g;if(l)f=o/(a-o),g=a*o/(a-o);else if(s==="webgl")f=-(a+o)/(a-o),g=-2*a*o/(a-o);else if(s==="webgpu")f=-a/(a-o),g=-a*o/(a-o);else throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+String(s));return c[0]=d,c[4]=0,c[8]=h,c[12]=0,c[1]=0,c[5]=u,c[9]=m,c[13]=0,c[2]=0,c[6]=0,c[10]=f,c[14]=g,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,i,o,a,s="webgl",l=!1){let c=this.elements,d=2/(t-e),u=2/(n-i),h=-(t+e)/(t-e),m=-(n+i)/(n-i),f,g;if(l)f=1/(a-o),g=a/(a-o);else if(s==="webgl")f=-2/(a-o),g=-(a+o)/(a-o);else if(s==="webgpu")f=-1/(a-o),g=-o/(a-o);else throw new Error("Matrix4.makeOrthographic(): Invalid coordinate system: "+String(s));return c[0]=d,c[4]=0,c[8]=0,c[12]=h,c[1]=0,c[5]=u,c[9]=0,c[13]=m,c[2]=0,c[6]=0,c[10]=f,c[14]=g,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){let t=this.elements,n=e.elements;for(let i=0;i<16;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){let n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}},Er=new L,Ut=new Ve,as=new L(0,0,0),ss=new L(1,1,1),Kt=new L,gn=new L,Mt=new L;var vt=class r{static DEFAULT_ORDER="XYZ";isEuler=!0;_x;_y;_z;_order;constructor(e=0,t=0,n=0,i=r.DEFAULT_ORDER){this._x=e,this._y=t,this._z=n,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,i=this._order){return this._x=e,this._y=t,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){let i=e.elements,o=i[0],a=i[4],s=i[8],l=i[1],c=i[5],d=i[9],u=i[2],h=i[6],m=i[10];switch(t){case"XYZ":this._y=Math.asin(ve(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(-d,m),this._z=Math.atan2(-a,o)):(this._x=Math.atan2(h,c),this._z=0);break;case"YXZ":this._x=Math.asin(-ve(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(s,m),this._z=Math.atan2(l,c)):(this._y=Math.atan2(-u,o),this._z=0);break;case"ZXY":this._x=Math.asin(ve(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(-u,m),this._z=Math.atan2(-a,c)):(this._y=0,this._z=Math.atan2(l,o));break;case"ZYX":this._y=Math.asin(-ve(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(h,m),this._z=Math.atan2(l,o)):(this._x=0,this._z=Math.atan2(-a,c));break;case"YZX":this._z=Math.asin(ve(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(-d,c),this._y=Math.atan2(-u,o)):(this._x=0,this._y=Math.atan2(s,m));break;case"XZY":this._z=Math.asin(-ve(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(h,c),this._y=Math.atan2(s,o)):(this._x=Math.atan2(-d,m),this._y=0);break;default:console.warn("keel/lit Euler: setFromRotationMatrix() met an unknown order: "+String(t))}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return no.makeRotationFromQuaternion(e),this.setFromRotationMatrix(no,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return io.setFromEuler(this),this.setFromQuaternion(io,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}},no=new Ve,io=new Pt;var oo=new rt().set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),ao=new rt().set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function ls(){let r={enabled:!0,workingColorSpace:"linear",spaces:{},convert(i,o,a){if(this.enabled===!1||o===a||!o||!a)return i;let s=this.spaces[o],l=this.spaces[a];return s.transfer==="srgb"&&(i.r=Qt(i.r),i.g=Qt(i.g),i.b=Qt(i.b)),s.primaries!==l.primaries&&(i.applyMatrix3(s.toXYZ),i.applyMatrix3(l.fromXYZ)),l.transfer==="srgb"&&(i.r=$t(i.r),i.g=$t(i.g),i.b=$t(i.b)),i},workingToColorSpace(i,o){return this.convert(i,this.workingColorSpace,o)},colorSpaceToWorking(i,o){return this.convert(i,o,this.workingColorSpace)},getPrimaries(i){return this.spaces[i].primaries},getTransfer(i){return i===""?"linear":this.spaces[i].transfer},getToneMappingMode(i){return this.spaces[i].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients(i,o){return o===void 0&&(o=this.workingColorSpace),i.fromArray(this.spaces[o].luminanceCoefficients)},define(i){Object.assign(this.spaces,i)},_getMatrix(i,o,a){return i.copy(this.spaces[o].toXYZ).multiply(this.spaces[a].fromXYZ)},_getDrawingBufferColorSpace(i){return this.spaces[i].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace(i){return i===void 0&&(i=this.workingColorSpace),this.spaces[i].workingColorSpaceConfig.unpackColorSpace}},e=[.64,.33,.3,.6,.15,.06],t=[.2126,.7152,.0722],n=[.3127,.329];return r.define({linear:{primaries:e,whitePoint:n,transfer:"linear",toXYZ:oo,fromXYZ:ao,luminanceCoefficients:t,workingColorSpaceConfig:{unpackColorSpace:"srgb"},outputColorSpaceConfig:{drawingBufferColorSpace:"srgb"}},srgb:{primaries:e,whitePoint:n,transfer:"srgb",toXYZ:oo,fromXYZ:ao,luminanceCoefficients:t,outputColorSpaceConfig:{drawingBufferColorSpace:"srgb"}}}),r}var Ne=ls();function Qt(r){return r<.04045?r*.0773993808:Math.pow(r*.9478672986+.0521327014,2.4)}function $t(r){return r<.0031308?r*12.92:1.055*Math.pow(r,.41666)-.055}var so={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},us={linear:"srgb-linear"},Jt={h:0,s:0,l:0},bn={h:0,s:0,l:0};function Yn(r,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?r+(e-r)*6*t:t<1/2?e:t<2/3?r+(e-r)*6*(2/3-t):r}var Pe=class{static NAMES=so;isColor=!0;r;g;b;constructor(e,t,n){this.r=1,this.g=1,this.b=1,this.set(e,t,n)}set(e,t,n){if(t===void 0&&n===void 0){let i=e;i&&i.isColor?this.copy(i):typeof i=="number"?this.setHex(i):typeof i=="string"&&this.setStyle(i)}else this.setRGB(e,t,n);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t="srgb"){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,Ne.colorSpaceToWorking(this,t),this}setRGB(e,t,n,i=Ne.workingColorSpace){return this.r=e,this.g=t,this.b=n,Ne.colorSpaceToWorking(this,i),this}setHSL(e,t,n,i=Ne.workingColorSpace){if(e=pn(e,1),t=ve(t,0,1),n=ve(n,0,1),t===0)this.r=this.g=this.b=n;else{let o=n<=.5?n*(1+t):n+t-n*t,a=2*n-o;this.r=Yn(a,o,e+1/3),this.g=Yn(a,o,e),this.b=Yn(a,o,e-1/3)}return Ne.colorSpaceToWorking(this,i),this}setStyle(e,t="srgb"){function n(o){o!==void 0&&parseFloat(o)<1&&console.warn("keel/lit Color: Alpha component of "+e+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(e)){let o,a=i[1],s=i[2];switch(a){case"rgb":case"rgba":if(o=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return n(o[4]),this.setRGB(Math.min(255,parseInt(o[1],10))/255,Math.min(255,parseInt(o[2],10))/255,Math.min(255,parseInt(o[3],10))/255,t);if(o=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return n(o[4]),this.setRGB(Math.min(100,parseInt(o[1],10))/100,Math.min(100,parseInt(o[2],10))/100,Math.min(100,parseInt(o[3],10))/100,t);break;case"hsl":case"hsla":if(o=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(s))return n(o[4]),this.setHSL(parseFloat(o[1])/360,parseFloat(o[2])/100,parseFloat(o[3])/100,t);break;default:console.warn("keel/lit Color: Unknown color model "+e)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(e)){let o=i[1],a=o.length;if(a===3)return this.setRGB(parseInt(o.charAt(0),16)/15,parseInt(o.charAt(1),16)/15,parseInt(o.charAt(2),16)/15,t);if(a===6)return this.setHex(parseInt(o,16),t);console.warn("keel/lit Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t="srgb"){let n=so[e.toLowerCase()];return n!==void 0?this.setHex(n,t):console.warn("keel/lit Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=Qt(e.r),this.g=Qt(e.g),this.b=Qt(e.b),this}copyLinearToSRGB(e){return this.r=$t(e.r),this.g=$t(e.g),this.b=$t(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e="srgb"){return Ne.workingToColorSpace(gt.copy(this),e),Math.round(ve(gt.r*255,0,255))*65536+Math.round(ve(gt.g*255,0,255))*256+Math.round(ve(gt.b*255,0,255))}getHexString(e="srgb"){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=Ne.workingColorSpace){Ne.workingToColorSpace(gt.copy(this),t);let n=gt.r,i=gt.g,o=gt.b,a=Math.max(n,i,o),s=Math.min(n,i,o),l,c,d=(s+a)/2;if(s===a)l=0,c=0;else{let u=a-s;switch(c=d<=.5?u/(a+s):u/(2-a-s),a){case n:l=(i-o)/u+(i<o?6:0);break;case i:l=(o-n)/u+2;break;case o:l=(n-i)/u+4;break}l/=6}return e.h=l,e.s=c,e.l=d,e}getRGB(e,t=Ne.workingColorSpace){return Ne.workingToColorSpace(gt.copy(this),t),e.r=gt.r,e.g=gt.g,e.b=gt.b,e}getStyle(e="srgb"){Ne.workingToColorSpace(gt.copy(this),e);let t=gt.r,n=gt.g,i=gt.b;return e!=="srgb"?"color(".concat(us[e]??e," ").concat(t.toFixed(3)," ").concat(n.toFixed(3)," ").concat(i.toFixed(3),")"):"rgb(".concat(Math.round(t*255),",").concat(Math.round(n*255),",").concat(Math.round(i*255),")")}offsetHSL(e,t,n){return this.getHSL(Jt),this.setHSL(Jt.h+e,Jt.s+t,Jt.l+n)}add(e){return this.r+=e.r,this.g+=e.g,this.b+=e.b,this}addColors(e,t){return this.r=e.r+t.r,this.g=e.g+t.g,this.b=e.b+t.b,this}addScalar(e){return this.r+=e,this.g+=e,this.b+=e,this}sub(e){return this.r=Math.max(0,this.r-e.r),this.g=Math.max(0,this.g-e.g),this.b=Math.max(0,this.b-e.b),this}multiply(e){return this.r*=e.r,this.g*=e.g,this.b*=e.b,this}multiplyScalar(e){return this.r*=e,this.g*=e,this.b*=e,this}lerp(e,t){return this.r+=(e.r-this.r)*t,this.g+=(e.g-this.g)*t,this.b+=(e.b-this.b)*t,this}lerpColors(e,t,n){return this.r=e.r+(t.r-e.r)*n,this.g=e.g+(t.g-e.g)*n,this.b=e.b+(t.b-e.b)*n,this}lerpHSL(e,t){this.getHSL(Jt),e.getHSL(bn);let n=Ar(Jt.h,bn.h,t),i=Ar(Jt.s,bn.s,t),o=Ar(Jt.l,bn.l,t);return this.setHSL(n,i,o),this}setFromVector3(e){return this.r=e.x,this.g=e.y,this.b=e.z,this}applyMatrix3(e){let t=this.r,n=this.g,i=this.b,o=e.elements;return this.r=o[0]*t+o[3]*n+o[6]*i,this.g=o[1]*t+o[4]*n+o[7]*i,this.b=o[2]*t+o[5]*n+o[8]*i,this}equals(e){return e.r===this.r&&e.g===this.g&&e.b===this.b}fromArray(e,t=0){return this.r=e[t],this.g=e[t+1],this.b=e[t+2],this}toArray(e=[],t=0){return e[t]=this.r,e[t+1]=this.g,e[t+2]=this.b,e}fromBufferAttribute(e,t){return this.r=e.getX(t),this.g=e.getY(t),this.b=e.getZ(t),this}toJSON(){return this.getHex()}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}},gt=new Pe;var St=class{isBox3=!0;min;max;constructor(e=new L(1/0,1/0,1/0),t=new L(-1/0,-1/0,-1/0)){this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t+=3)this.expandByPoint(It.fromArray(e,t));return this}setFromBufferAttribute(e){this.makeEmpty();for(let t=0,n=e.count;t<n;t++)this.expandByPoint(It.fromBufferAttribute(e,t));return this}setFromPoints(e){this.makeEmpty();for(let t=0,n=e.length;t<n;t++)this.expandByPoint(e[t]);return this}setFromCenterAndSize(e,t){let n=It.copy(t).multiplyScalar(.5);return this.min.copy(e).sub(n),this.max.copy(e).add(n),this}setFromObject(e,t=!1){return this.makeEmpty(),this.expandByObject(e,t)}clone(){return new this.constructor().copy(this)}copy(e){return this.min.copy(e.min),this.max.copy(e.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(e){return this.isEmpty()?e.set(0,0,0):e.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(e){return this.isEmpty()?e.set(0,0,0):e.subVectors(this.max,this.min)}expandByPoint(e){return this.min.min(e),this.max.max(e),this}expandByVector(e){return this.min.sub(e),this.max.add(e),this}expandByScalar(e){return this.min.addScalar(-e),this.max.addScalar(e),this}expandByObject(e,t=!1){e.updateWorldMatrix(!1,!1);let n=e.geometry;if(n!==void 0){let o=n.getAttribute("position");if(t===!0&&o!==void 0&&e.isInstancedMesh!==!0)for(let a=0,s=o.count;a<s;a++)e.isMesh===!0?e.getVertexPosition(a,It):It.fromBufferAttribute(o,a),It.applyMatrix4(e.matrixWorld),this.expandByPoint(It);else e.boundingBox!==void 0?(e.boundingBox===null&&e.computeBoundingBox(),xn.copy(e.boundingBox)):(n.boundingBox===null&&n.computeBoundingBox(),xn.copy(n.boundingBox)),xn.applyMatrix4(e.matrixWorld),this.union(xn)}let i=e.children;for(let o=0,a=i.length;o<a;o++)this.expandByObject(i[o],t);return this}containsPoint(e){return e.x>=this.min.x&&e.x<=this.max.x&&e.y>=this.min.y&&e.y<=this.max.y&&e.z>=this.min.z&&e.z<=this.max.z}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return e.max.x>=this.min.x&&e.min.x<=this.max.x&&e.max.y>=this.min.y&&e.min.y<=this.max.y&&e.max.z>=this.min.z&&e.min.z<=this.max.z}intersectsSphere(e){return this.clampPoint(e.center,It),It.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,n;return e.normal.x>0?(t=e.normal.x*this.min.x,n=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,n=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,n+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,n+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,n+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,n+=e.normal.z*this.min.z),t<=-e.constant&&n>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(zr),vn.subVectors(this.max,zr),wr.subVectors(e.a,zr),Cr.subVectors(e.b,zr),Lr.subVectors(e.c,zr),er.subVectors(Cr,wr),tr.subVectors(Lr,Cr),lr.subVectors(wr,Lr);let t=[0,-er.z,er.y,0,-tr.z,tr.y,0,-lr.z,lr.y,er.z,0,-er.x,tr.z,0,-tr.x,lr.z,0,-lr.x,-er.y,er.x,0,-tr.y,tr.x,0,-lr.y,lr.x,0];return!jn(t,wr,Cr,Lr,vn)||(t=[1,0,0,0,1,0,0,0,1],!jn(t,wr,Cr,Lr,vn))?!1:(yn.crossVectors(er,tr),t=[yn.x,yn.y,yn.z],jn(t,wr,Cr,Lr,vn))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,It).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(It).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(Gt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),Gt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),Gt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),Gt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),Gt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),Gt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),Gt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),Gt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(Gt),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(e){return this.min.fromArray(e.min),this.max.fromArray(e.max),this}},Gt=[new L,new L,new L,new L,new L,new L,new L,new L],It=new L,xn=new St,wr=new L,Cr=new L,Lr=new L,er=new L,tr=new L,lr=new L,zr=new L,vn=new L,yn=new L,ur=new L;function jn(r,e,t,n,i){for(let o=0,a=r.length-3;o<=a;o+=3){ur.fromArray(r,o);let s=i.x*Math.abs(ur.x)+i.y*Math.abs(ur.y)+i.z*Math.abs(ur.z),l=e.dot(ur),c=t.dot(ur),d=n.dot(ur);if(Math.max(-Math.max(l,c,d),Math.min(l,c,d))>s)return!1}return!0}var cs=new St,Br=new L,Zn=new L,Ot=class{isSphere=!0;center;radius;constructor(e=new L,t=-1){this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){let n=this.center;t!==void 0?n.copy(t):cs.setFromPoints(e).getCenter(n);let i=0;for(let o=0,a=e.length;o<a;o++)i=Math.max(i,n.distanceToSquared(e[o]));return this.radius=Math.sqrt(i),this}copy(e){return this.center.copy(e.center),this.radius=e.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(e){return e.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(e){return e.distanceTo(this.center)-this.radius}intersectsSphere(e){let t=this.radius+e.radius;return e.center.distanceToSquared(this.center)<=t*t}intersectsBox(e){return e.intersectsSphere(this)}intersectsPlane(e){return Math.abs(e.distanceToPoint(this.center))<=this.radius}clampPoint(e,t){let n=this.center.distanceToSquared(e);return t.copy(e),n>this.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;Br.subVectors(e,this.center);let t=Br.lengthSq();if(t>this.radius*this.radius){let n=Math.sqrt(t),i=(n-this.radius)*.5;this.center.addScaledVector(Br,i/n),this.radius+=i}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(Zn.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(Br.copy(e.center).add(Zn)),this.expandByPoint(Br.copy(e.center).sub(Zn))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(e){return this.radius=e.radius,this.center.fromArray(e.center),this}};var Kn=new L,ds=new L,hs=new rt,wt=class{isPlane=!0;normal;constant;constructor(e=new L(1,0,0),t=0){this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,n,i){return this.normal.set(e,t,n),this.constant=i,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,n){let i=Kn.subVectors(n,t).cross(ds.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(i,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){let e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t){let n=e.delta(Kn),i=this.normal.dot(n);if(i===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;let o=-(e.start.dot(this.normal)+this.constant)/i;return o<0||o>1?null:t.copy(e.start).addScaledVector(n,o)}intersectsLine(e){let t=this.distanceToPoint(e.start),n=this.distanceToPoint(e.end);return t<0&&n>0||n<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){let n=t||hs.getNormalMatrix(e),i=this.coplanarPoint(Kn).applyMatrix4(e),o=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(o),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}};var cr=new Ot,ms=new W(.5,.5),Mn=new L,Ht=class{planes;constructor(e=new wt,t=new wt,n=new wt,i=new wt,o=new wt,a=new wt){this.planes=[e,t,n,i,o,a]}set(e,t,n,i,o,a){let s=this.planes;return s[0].copy(e),s[1].copy(t),s[2].copy(n),s[3].copy(i),s[4].copy(o),s[5].copy(a),this}copy(e){let t=this.planes;for(let n=0;n<6;n++)t[n].copy(e.planes[n]);return this}setFromProjectionMatrix(e,t="webgl",n=!1){let i=this.planes,o=e.elements,a=o[0],s=o[1],l=o[2],c=o[3],d=o[4],u=o[5],h=o[6],m=o[7],f=o[8],g=o[9],v=o[10],M=o[11],T=o[12],_=o[13],A=o[14],U=o[15];if(i[0].setComponents(c-a,m-d,M-f,U-T).normalize(),i[1].setComponents(c+a,m+d,M+f,U+T).normalize(),i[2].setComponents(c+s,m+u,M+g,U+_).normalize(),i[3].setComponents(c-s,m-u,M-g,U-_).normalize(),n)i[4].setComponents(l,h,v,A).normalize(),i[5].setComponents(c-l,m-h,M-v,U-A).normalize();else if(i[4].setComponents(c-l,m-h,M-v,U-A).normalize(),t==="webgl")i[5].setComponents(c+l,m+h,M+v,U+A).normalize();else if(t==="webgpu")i[5].setComponents(l,h,v,A).normalize();else throw new Error("Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+String(t));return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),cr.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{let t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),cr.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(cr)}intersectsSprite(e){cr.center.set(0,0,0);let t=ms.distanceTo(e.center);return cr.radius=.7071067811865476+t,cr.applyMatrix4(e.matrixWorld),this.intersectsSphere(cr)}intersectsSphere(e){let t=this.planes,n=e.center,i=-e.radius;for(let o=0;o<6;o++)if(t[o].distanceToPoint(n)<i)return!1;return!0}intersectsBox(e){let t=this.planes;for(let n=0;n<6;n++){let i=t[n];if(Mn.x=i.normal.x>0?e.max.x:e.min.x,Mn.y=i.normal.y>0?e.max.y:e.min.y,Mn.z=i.normal.z>0?e.max.z:e.min.z,i.distanceToPoint(Mn)<0)return!1}return!0}containsPoint(e){let t=this.planes;for(let n=0;n<6;n++)if(t[n].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}};var Wt=new L,Qn=new L,Sn=new L,rr=new L,$n=new L,_n=new L,Jn=new L,ei=class{origin;direction;constructor(e=new L,t=new L(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,Wt)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);let n=t.dot(this.direction);return n<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){let t=Wt.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(Wt.copy(this.origin).addScaledVector(this.direction,t),Wt.distanceToSquared(e))}distanceSqToSegment(e,t,n,i){Qn.copy(e).add(t).multiplyScalar(.5),Sn.copy(t).sub(e).normalize(),rr.copy(this.origin).sub(Qn);let o=e.distanceTo(t)*.5,a=-this.direction.dot(Sn),s=rr.dot(this.direction),l=-rr.dot(Sn),c=rr.lengthSq(),d=Math.abs(1-a*a),u,h,m,f;if(d>0)if(u=a*l-s,h=a*s-l,f=o*d,u>=0)if(h>=-f)if(h<=f){let g=1/d;u*=g,h*=g,m=u*(u+a*h+2*s)+h*(a*u+h+2*l)+c}else h=o,u=Math.max(0,-(a*h+s)),m=-u*u+h*(h+2*l)+c;else h=-o,u=Math.max(0,-(a*h+s)),m=-u*u+h*(h+2*l)+c;else h<=-f?(u=Math.max(0,-(-a*o+s)),h=u>0?-o:Math.min(Math.max(-o,-l),o),m=-u*u+h*(h+2*l)+c):h<=f?(u=0,h=Math.min(Math.max(-o,-l),o),m=h*(h+2*l)+c):(u=Math.max(0,-(a*o+s)),h=u>0?o:Math.min(Math.max(-o,-l),o),m=-u*u+h*(h+2*l)+c);else h=a>0?-o:o,u=Math.max(0,-(a*h+s)),m=-u*u+h*(h+2*l)+c;return n&&n.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(Qn).addScaledVector(Sn,h),m}intersectSphere(e,t){Wt.subVectors(e.center,this.origin);let n=Wt.dot(this.direction),i=Wt.dot(Wt)-n*n,o=e.radius*e.radius;if(i>o)return null;let a=Math.sqrt(o-i),s=n-a,l=n+a;return l<0?null:s<0?this.at(l,t):this.at(s,t)}intersectsSphere(e){return e.radius<0?!1:this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){let t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;let n=-(this.origin.dot(e.normal)+e.constant)/t;return n>=0?n:null}intersectPlane(e,t){let n=this.distanceToPlane(e);return n===null?null:this.at(n,t)}intersectsPlane(e){let t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let n,i,o,a,s,l,c=1/this.direction.x,d=1/this.direction.y,u=1/this.direction.z,h=this.origin;return c>=0?(n=(e.min.x-h.x)*c,i=(e.max.x-h.x)*c):(n=(e.max.x-h.x)*c,i=(e.min.x-h.x)*c),d>=0?(o=(e.min.y-h.y)*d,a=(e.max.y-h.y)*d):(o=(e.max.y-h.y)*d,a=(e.min.y-h.y)*d),n>a||o>i||((o>n||isNaN(n))&&(n=o),(a<i||isNaN(i))&&(i=a),u>=0?(s=(e.min.z-h.z)*u,l=(e.max.z-h.z)*u):(s=(e.max.z-h.z)*u,l=(e.min.z-h.z)*u),n>l||s>i)||((s>n||n!==n)&&(n=s),(l<i||i!==i)&&(i=l),i<0)?null:this.at(n>=0?n:i,t)}intersectsBox(e){return this.intersectBox(e,Wt)!==null}intersectTriangle(e,t,n,i,o){$n.subVectors(t,e),_n.subVectors(n,e),Jn.crossVectors($n,_n);let a=this.direction.dot(Jn),s;if(a>0){if(i)return null;s=1}else if(a<0)s=-1,a=-a;else return null;rr.subVectors(this.origin,e);let l=s*this.direction.dot(_n.crossVectors(rr,_n));if(l<0)return null;let c=s*this.direction.dot($n.cross(rr));if(c<0||l+c>a)return null;let d=-s*rr.dot(Jn);return d<0?null:this.at(d/a,o)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}};var fs=Object.freeze({front:0,back:1,both:2}),ps=Object.freeze({none:0,normal:1,add:2,subtract:3,multiply:4,custom:5}),gs=Object.freeze({add:100,subtract:101,"reverse-subtract":102,min:103,max:104}),bs=Object.freeze({zero:200,one:201,"src-color":202,"one-minus-src-color":203,"src-alpha":204,"one-minus-src-alpha":205,"dst-alpha":206,"one-minus-dst-alpha":207,"dst-color":208,"one-minus-dst-color":209,"src-alpha-saturate":210,"constant-color":211,"one-minus-constant-color":212,"constant-alpha":213,"one-minus-constant-alpha":214}),xs=Object.freeze({never:0,always:1,less:2,"less-equal":3,equal:4,"greater-equal":5,greater:6,"not-equal":7}),ti=Object.freeze({never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519}),Gr=Object.freeze({zero:0,keep:7680,replace:7681,increment:7682,decrement:7683,"increment-wrap":34055,"decrement-wrap":34056,invert:5386}),vs=Object.freeze({multiply:0,mix:1,add:2}),ys=Object.freeze({tangent:0,object:1}),Ms=Object.freeze({basic:3200,rgba:3201,rgb:3202,rg:3203}),Ss=Object.freeze({uv:300,"cube-reflection":301,"cube-refraction":302,"equirect-reflection":303,"equirect-refraction":304,"cube-uv-reflection":306}),_s=Object.freeze({repeat:1e3,clamp:1001,mirror:1002}),Ts=Object.freeze({nearest:1003,"nearest-mipmap-nearest":1004,"nearest-mipmap-linear":1005,linear:1006,"linear-mipmap-nearest":1007,"linear-mipmap-linear":1008}),bt=Object.freeze({u8:1009,i8:1010,i16:1011,u16:1012,int:1013,uint:1014,float:1015,half:1016,u4444:1017,u5551:1018,"depth24-stencil8":1020,u5999:35902,u101111:35899}),_t=Object.freeze({alpha:1021,rgb:1022,rgba:1023,depth:1026,"depth-stencil":1027,red:1028,"red-integer":1029,rg:1030,"rg-integer":1031,"rgb-integer":1032,"rgba-integer":1033}),ri=Object.freeze({static:35044,dynamic:35048,stream:35040,"static-read":35045,"dynamic-read":35049,"stream-read":35041,"static-copy":35046,"dynamic-copy":35050,"stream-copy":35042}),As=Object.freeze({basic:0,pcf:1,"pcf-soft":2,vsm:3}),Es=Object.freeze({none:0,linear:1,reinhard:2,cineon:3,"aces-filmic":4,custom:5,agx:6,neutral:7}),ws=Object.freeze({none:0,back:1,front:2,"front-back":3}),ni=Object.freeze({"":"",srgb:"srgb",linear:"srgb-linear"}),Cs=Object.freeze({webgl:2e3,webgpu:2001}),dr=Object.freeze({side:fs,blending:ps,blendEquation:gs,blendFactor:bs,depthFunc:xs,compareFunc:ti,stencilOp:Gr,combine:vs,normalMapType:ys,depthPacking:Ms,mapping:Ss,wrapping:_s,filter:Ts,textureType:bt,pixelFormat:_t,usage:ri,shadowMapType:As,toneMapping:Es,cullFace:ws,coordinateSystem:Cs});var Tt=class{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});let n=this._listeners;n[e]===void 0&&(n[e]=[]);let i=n[e];i.indexOf(t)===-1&&i.push(t)}hasEventListener(e,t){let n=this._listeners;return n===void 0?!1:n[e]!==void 0&&n[e].indexOf(t)!==-1}removeEventListener(e,t){let n=this._listeners;if(n===void 0)return;let i=n[e];if(i!==void 0){let o=i.indexOf(t);o!==-1&&i.splice(o,1)}}dispatchEvent(e){let t=this._listeners;if(t===void 0)return;let n=t[e.type];if(n!==void 0){e.target=this;let i=n.slice(0);for(let o=0,a=i.length;o<a;o++)i[o].call(this,e);e.target=null}}};var hr=class{mask;constructor(){this.mask=1}set(e){this.mask=(1<<e|0)>>>0}enable(e){this.mask|=1<<e|0}enableAll(){this.mask=-1}toggle(e){this.mask^=1<<e|0}disable(e){this.mask&=~(1<<e|0)}disableAll(){this.mask=0}test(e){return(this.mask&e.mask)!==0}isEnabled(e){return(this.mask&(1<<e|0))!==0}};var it=new L,Tn=new W,Ls=0,de=class{isBufferAttribute=!0;isAttribute=!0;name;array;itemSize;count;normalized;usage;updateRanges;gpuType;version;constructor(e,t,n=!1){if(Array.isArray(e))throw new TypeError("keel/lit Attribute: array should be a Typed Array.");Object.defineProperty(this,"id",{value:Ls++}),this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=n,this.usage="static",this.updateRanges=[],this.gpuType="float",this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,n){e*=this.itemSize,n*=t.itemSize;for(let i=0,o=this.itemSize;i<o;i++)this.array[e+i]=t.array[n+i];return this}copyArray(e){return this.array.set(e),this}applyMatrix3(e){if(this.itemSize===2)for(let t=0,n=this.count;t<n;t++)Tn.fromBufferAttribute(this,t),Tn.applyMatrix3(e),this.setXY(t,Tn.x,Tn.y);else if(this.itemSize===3)for(let t=0,n=this.count;t<n;t++)it.fromBufferAttribute(this,t),it.applyMatrix3(e),this.setXYZ(t,it.x,it.y,it.z);return this}applyMatrix4(e){for(let t=0,n=this.count;t<n;t++)it.fromBufferAttribute(this,t),it.applyMatrix4(e),this.setXYZ(t,it.x,it.y,it.z);return this}applyNormalMatrix(e){for(let t=0,n=this.count;t<n;t++)it.fromBufferAttribute(this,t),it.applyNormalMatrix(e),this.setXYZ(t,it.x,it.y,it.z);return this}transformDirection(e){for(let t=0,n=this.count;t<n;t++)it.fromBufferAttribute(this,t),it.transformDirection(e),this.setXYZ(t,it.x,it.y,it.z);return this}set(e,t=0){return this.array.set(e,t),this}getComponent(e,t){let n=this.array[e*this.itemSize+t];return this.normalized&&(n=sr(n,this.array)),n}setComponent(e,t,n){return this.normalized&&(n=pt(n,this.array)),this.array[e*this.itemSize+t]=n,this}getX(e){let t=this.array[e*this.itemSize];return this.normalized&&(t=sr(t,this.array)),t}setX(e,t){return this.normalized&&(t=pt(t,this.array)),this.array[e*this.itemSize]=t,this}getY(e){let t=this.array[e*this.itemSize+1];return this.normalized&&(t=sr(t,this.array)),t}setY(e,t){return this.normalized&&(t=pt(t,this.array)),this.array[e*this.itemSize+1]=t,this}getZ(e){let t=this.array[e*this.itemSize+2];return this.normalized&&(t=sr(t,this.array)),t}setZ(e,t){return this.normalized&&(t=pt(t,this.array)),this.array[e*this.itemSize+2]=t,this}getW(e){let t=this.array[e*this.itemSize+3];return this.normalized&&(t=sr(t,this.array)),t}setW(e,t){return this.normalized&&(t=pt(t,this.array)),this.array[e*this.itemSize+3]=t,this}setXY(e,t,n){return e*=this.itemSize,this.normalized&&(t=pt(t,this.array),n=pt(n,this.array)),this.array[e+0]=t,this.array[e+1]=n,this}setXYZ(e,t,n,i){return e*=this.itemSize,this.normalized&&(t=pt(t,this.array),n=pt(n,this.array),i=pt(i,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=i,this}setXYZW(e,t,n,i,o){return e*=this.itemSize,this.normalized&&(t=pt(t,this.array),n=pt(n,this.array),i=pt(i,this.array),o=pt(o,this.array)),this.array[e+0]=t,this.array[e+1]=n,this.array[e+2]=i,this.array[e+3]=o,this}onUpload(e){return this.onUploadCallback=e,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}},Rr=class extends de{isInstancedBufferAttribute=!0;isInstanceAttribute=!0;meshPerAttribute;constructor(e,t,n,i=1){super(e,t,n),this.meshPerAttribute=i}copy(e){return super.copy(e),this.meshPerAttribute=e.meshPerAttribute,this}};var Rs=0,lo=new L,Pr=new Pt,Xt=new Ve,An=new L,Hr=new L,Ps=new L,Us=new Pt,uo=new L(1,0,0),co=new L(0,1,0),ho=new L(0,0,1),mo={type:"added"},Is={type:"removed"},Ur={type:"childadded",child:null},ii={type:"childremoved",child:null},nt=class r extends Tt{static DEFAULT_UP=new L(0,1,0);static DEFAULT_MATRIX_AUTO_UPDATE=!0;static DEFAULT_MATRIX_WORLD_AUTO_UPDATE=!0;constructor(){super(),this.isObject3D=!0,this.isNode=!0,Object.defineProperty(this,"id",{value:Rs++}),this.uuid=yt(),this.name="",this.type="Node",this.parent=null,this.children=[],this.up=r.DEFAULT_UP.clone();let e=new L,t=new vt,n=new Pt,i=new L(1,1,1);function o(){n.setFromEuler(t,!1)}function a(){t.setFromQuaternion(n,void 0,!1)}t._onChange(o),n._onChange(a),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:e},rotation:{configurable:!0,enumerable:!0,value:t},quaternion:{configurable:!0,enumerable:!0,value:n},scale:{configurable:!0,enumerable:!0,value:i},modelViewMatrix:{value:new Ve},normalMatrix:{value:new rt}}),this.matrix=new Ve,this.matrixWorld=new Ve,this.matrixAutoUpdate=r.DEFAULT_MATRIX_AUTO_UPDATE,this.matrixWorldAutoUpdate=r.DEFAULT_MATRIX_WORLD_AUTO_UPDATE,this.matrixWorldNeedsUpdate=!1,this.layers=new hr,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.customDepthMaterial=void 0,this.customDistanceMaterial=void 0,this.userData={}}onBeforeShadow(e,t,n,i,o,a,s){}onAfterShadow(e,t,n,i,o,a,s){}onBeforeRender(e,t,n,i,o,a){}onAfterRender(e,t,n,i,o,a){}applyMatrix4(e){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(e),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(e){return this.quaternion.premultiply(e),this}setRotationFromAxisAngle(e,t){this.quaternion.setFromAxisAngle(e,t)}setRotationFromEuler(e){this.quaternion.setFromEuler(e,!0)}setRotationFromMatrix(e){this.quaternion.setFromRotationMatrix(e)}setRotationFromQuaternion(e){this.quaternion.copy(e)}rotateOnAxis(e,t){return Pr.setFromAxisAngle(e,t),this.quaternion.multiply(Pr),this}rotateOnWorldAxis(e,t){return Pr.setFromAxisAngle(e,t),this.quaternion.premultiply(Pr),this}rotateX(e){return this.rotateOnAxis(uo,e)}rotateY(e){return this.rotateOnAxis(co,e)}rotateZ(e){return this.rotateOnAxis(ho,e)}translateOnAxis(e,t){return lo.copy(e).applyQuaternion(this.quaternion),this.position.add(lo.multiplyScalar(t)),this}translateX(e){return this.translateOnAxis(uo,e)}translateY(e){return this.translateOnAxis(co,e)}translateZ(e){return this.translateOnAxis(ho,e)}localToWorld(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)}worldToLocal(e){return this.updateWorldMatrix(!0,!1),e.applyMatrix4(Xt.copy(this.matrixWorld).invert())}lookAt(e,t,n){typeof e=="object"&&e.isVector3?An.copy(e):An.set(e,t,n);let i=this.parent;this.updateWorldMatrix(!0,!1),Hr.setFromMatrixPosition(this.matrixWorld);let o=this;o.isCamera||o.isLight?Xt.lookAt(Hr,An,this.up):Xt.lookAt(An,Hr,this.up),this.quaternion.setFromRotationMatrix(Xt),i&&(Xt.extractRotation(i.matrixWorld),Pr.setFromRotationMatrix(Xt),this.quaternion.premultiply(Pr.invert()))}add(...e){if(e.length>1){for(let n=0;n<e.length;n++)this.add(e[n]);return this}let t=e[0];return t===this?(console.error("keel/lit Node.add: object can't be added as a child of itself.",t),this):(t&&t.isObject3D?(t.removeFromParent(),t.parent=this,this.children.push(t),t.dispatchEvent(mo),Ur.child=t,this.dispatchEvent(Ur),Ur.child=null):console.error("keel/lit Node.add: object not an instance of Node.",t),this)}remove(...e){if(e.length>1){for(let i=0;i<e.length;i++)this.remove(e[i]);return this}let t=e[0],n=this.children.indexOf(t);return n!==-1&&(t.parent=null,this.children.splice(n,1),t.dispatchEvent(Is),ii.child=t,this.dispatchEvent(ii),ii.child=null),this}removeFromParent(){let e=this.parent;return e!==null&&e.remove(this),this}clear(){return this.remove(...this.children)}attach(e){return this.updateWorldMatrix(!0,!1),Xt.copy(this.matrixWorld).invert(),e.parent!==null&&(e.parent.updateWorldMatrix(!0,!1),Xt.multiply(e.parent.matrixWorld)),e.applyMatrix4(Xt),e.removeFromParent(),e.parent=this,this.children.push(e),e.updateWorldMatrix(!1,!0),e.dispatchEvent(mo),Ur.child=e,this.dispatchEvent(Ur),Ur.child=null,this}getObjectById(e){return this.getObjectByProperty("id",e)}getObjectByName(e){return this.getObjectByProperty("name",e)}getObjectByProperty(e,t){if(this[e]===t)return this;for(let n=0,i=this.children.length;n<i;n++){let a=this.children[n].getObjectByProperty(e,t);if(a!==void 0)return a}}getObjectsByProperty(e,t,n=[]){this[e]===t&&n.push(this);let i=this.children;for(let o=0,a=i.length;o<a;o++)i[o].getObjectsByProperty(e,t,n);return n}getWorldPosition(e){return this.updateWorldMatrix(!0,!1),e.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Hr,e,Ps),e}getWorldScale(e){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Hr,Us,e),e}getWorldDirection(e){this.updateWorldMatrix(!0,!1);let t=this.matrixWorld.elements;return e.set(t[8],t[9],t[10]).normalize()}traverse(e){e(this);let t=this.children;for(let n=0,i=t.length;n<i;n++)t[n].traverse(e)}traverseVisible(e){if(this.visible===!1)return;e(this);let t=this.children;for(let n=0,i=t.length;n<i;n++)t[n].traverseVisible(e)}traverseAncestors(e){let t=this.parent;t!==null&&(e(t),t.traverseAncestors(e))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(e){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||e)&&(this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),this.matrixWorldNeedsUpdate=!1,e=!0);let t=this.children;for(let n=0,i=t.length;n<i;n++)t[n].updateMatrixWorld(e)}updateWorldMatrix(e,t){let n=this.parent;if(e===!0&&n!==null&&n.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),this.matrixWorldAutoUpdate===!0&&(this.parent===null?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix)),t===!0){let i=this.children;for(let o=0,a=i.length;o<a;o++)i[o].updateWorldMatrix(!1,!0)}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let n=0;n<e.children.length;n++){let i=e.children[n];this.add(i.clone())}return this}};function Ds(r){for(let e=r.length-1;e>=0;--e)if(r[e]>=65535)return!0;return!1}var Fs=0,Ct=new Ve,oi=new nt,Ir=new L,At=new St,Wr=new St,ct=new L,Dt=class r extends Tt{isBufferGeometry=!0;isGeometry=!0;uuid;name;type;index;indirect;attributes;morphAttributes;morphTargetsRelative;groups;boundingBox;boundingSphere;drawRange;userData;constructor(){super(),Object.defineProperty(this,"id",{value:Fs++}),this.uuid=yt(),this.name="",this.type="Geometry",this.index=null,this.indirect=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:1/0},this.userData={}}getIndex(){return this.index}setIndex(e){if(Array.isArray(e)){let t=e;this.index=new de(Ds(t)?new Uint32Array(t):new Uint16Array(t),1)}else this.index=e;return this}getAttribute(e){return this.attributes[e]}setAttribute(e,t){return this.attributes[e]=t,this}deleteAttribute(e){return delete this.attributes[e],this}hasAttribute(e){return this.attributes[e]!==void 0}addGroup(e,t,n=0){this.groups.push({start:e,count:t,materialIndex:n})}clearGroups(){this.groups=[]}setDrawRange(e,t){this.drawRange.start=e,this.drawRange.count=t}applyMatrix4(e){let t=this.attributes.position;t!==void 0&&(t.applyMatrix4(e),t.needsUpdate=!0);let n=this.attributes.normal;if(n!==void 0){let o=new rt().getNormalMatrix(e);n.applyNormalMatrix(o),n.needsUpdate=!0}let i=this.attributes.tangent;return i!==void 0&&(i.transformDirection(e),i.needsUpdate=!0),this.boundingBox!==null&&this.computeBoundingBox(),this.boundingSphere!==null&&this.computeBoundingSphere(),this}applyQuaternion(e){return Ct.makeRotationFromQuaternion(e),this.applyMatrix4(Ct),this}rotateX(e){return Ct.makeRotationX(e),this.applyMatrix4(Ct),this}rotateY(e){return Ct.makeRotationY(e),this.applyMatrix4(Ct),this}rotateZ(e){return Ct.makeRotationZ(e),this.applyMatrix4(Ct),this}translate(e,t,n){return Ct.makeTranslation(e,t,n),this.applyMatrix4(Ct),this}scale(e,t,n){return Ct.makeScale(e,t,n),this.applyMatrix4(Ct),this}lookAt(e){return oi.lookAt(e),oi.updateMatrix(),this.applyMatrix4(oi.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Ir).negate(),this.translate(Ir.x,Ir.y,Ir.z),this}setFromPoints(e){let t=this.getAttribute("position");if(t===void 0){let n=[];for(let i=0,o=e.length;i<o;i++){let a=e[i];n.push(a.x,a.y,a.z||0)}this.setAttribute("position",new de(new Float32Array(n),3))}else{let n=Math.min(e.length,t.count);for(let i=0;i<n;i++){let o=e[i];t.setXYZ(i,o.x,o.y,o.z||0)}e.length>t.count&&console.warn("keel/lit Geometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),t.needsUpdate=!0}return this}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new St);let e=this.attributes.position,t=this.morphAttributes.position;if(e!==void 0){if(this.boundingBox.setFromBufferAttribute(e),t)for(let n=0,i=t.length;n<i;n++){let o=t[n];At.setFromBufferAttribute(o),this.morphTargetsRelative?(ct.addVectors(this.boundingBox.min,At.min),this.boundingBox.expandByPoint(ct),ct.addVectors(this.boundingBox.max,At.max),this.boundingBox.expandByPoint(ct)):(this.boundingBox.expandByPoint(At.min),this.boundingBox.expandByPoint(At.max))}}else this.boundingBox.makeEmpty();(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z))&&console.error('keel/lit Geometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this)}computeBoundingSphere(){this.boundingSphere===null&&(this.boundingSphere=new Ot);let e=this.attributes.position,t=this.morphAttributes.position;if(e){let n=this.boundingSphere.center;if(At.setFromBufferAttribute(e),t)for(let o=0,a=t.length;o<a;o++){let s=t[o];Wr.setFromBufferAttribute(s),this.morphTargetsRelative?(ct.addVectors(At.min,Wr.min),At.expandByPoint(ct),ct.addVectors(At.max,Wr.max),At.expandByPoint(ct)):(At.expandByPoint(Wr.min),At.expandByPoint(Wr.max))}At.getCenter(n);let i=0;for(let o=0,a=e.count;o<a;o++)ct.fromBufferAttribute(e,o),i=Math.max(i,n.distanceToSquared(ct));if(t)for(let o=0,a=t.length;o<a;o++){let s=t[o],l=this.morphTargetsRelative;for(let c=0,d=s.count;c<d;c++)ct.fromBufferAttribute(s,c),l&&(Ir.fromBufferAttribute(e,c),ct.add(Ir)),i=Math.max(i,n.distanceToSquared(ct))}this.boundingSphere.radius=Math.sqrt(i),isNaN(this.boundingSphere.radius)&&console.error('keel/lit Geometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this)}}computeVertexNormals(){let e=this.index,t=this.getAttribute("position");if(t!==void 0){let n=this.getAttribute("normal");if(n===void 0)n=new de(new Float32Array(t.count*3),3),this.setAttribute("normal",n);else for(let h=0,m=n.count;h<m;h++)n.setXYZ(h,0,0,0);let i=new L,o=new L,a=new L,s=new L,l=new L,c=new L,d=new L,u=new L;if(e)for(let h=0,m=e.count;h<m;h+=3){let f=e.getX(h+0),g=e.getX(h+1),v=e.getX(h+2);i.fromBufferAttribute(t,f),o.fromBufferAttribute(t,g),a.fromBufferAttribute(t,v),d.subVectors(a,o),u.subVectors(i,o),d.cross(u),s.fromBufferAttribute(n,f),l.fromBufferAttribute(n,g),c.fromBufferAttribute(n,v),s.add(d),l.add(d),c.add(d),n.setXYZ(f,s.x,s.y,s.z),n.setXYZ(g,l.x,l.y,l.z),n.setXYZ(v,c.x,c.y,c.z)}else for(let h=0,m=t.count;h<m;h+=3)i.fromBufferAttribute(t,h+0),o.fromBufferAttribute(t,h+1),a.fromBufferAttribute(t,h+2),d.subVectors(a,o),u.subVectors(i,o),d.cross(u),n.setXYZ(h+0,d.x,d.y,d.z),n.setXYZ(h+1,d.x,d.y,d.z),n.setXYZ(h+2,d.x,d.y,d.z);this.normalizeNormals(),n.needsUpdate=!0}}normalizeNormals(){let e=this.attributes.normal;for(let t=0,n=e.count;t<n;t++)ct.fromBufferAttribute(e,t),ct.normalize(),e.setXYZ(t,ct.x,ct.y,ct.z)}toNonIndexed(){function e(s,l){let c=s.array,d=s.itemSize,u=s.normalized,h=new c.constructor(l.length*d),m=0,f=0;for(let g=0,v=l.length;g<v;g++){m=l[g]*d;for(let M=0;M<d;M++)h[f++]=c[m++]}return new de(h,d,u)}if(this.index===null)return console.warn("keel/lit Geometry.toNonIndexed(): Geometry is already non-indexed."),this;let t=new r,n=this.index.array,i=this.attributes;for(let s in i){let l=i[s],c=e(l,n);t.setAttribute(s,c)}let o=this.morphAttributes;for(let s in o){let l=[],c=o[s];for(let d=0,u=c.length;d<u;d++){let h=c[d],m=e(h,n);l.push(m)}t.morphAttributes[s]=l}t.morphTargetsRelative=this.morphTargetsRelative;let a=this.groups;for(let s=0,l=a.length;s<l;s++){let c=a[s];t.addGroup(c.start,c.count,c.materialIndex)}return t}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.name=e.name;let t=e.index;t!==null&&this.setIndex(t.clone());let n=e.attributes;for(let l in n){let c=n[l];this.setAttribute(l,c.clone())}let i=e.morphAttributes;for(let l in i){let c=[],d=i[l];for(let u=0,h=d.length;u<h;u++)c.push(d[u].clone());this.morphAttributes[l]=c}this.morphTargetsRelative=e.morphTargetsRelative;let o=e.groups;for(let l=0,c=o.length;l<c;l++){let d=o[l];this.addGroup(d.start,d.count,d.materialIndex)}let a=e.boundingBox;a!==null&&(this.boundingBox=a.clone());let s=e.boundingSphere;return s!==null&&(this.boundingSphere=s.clone()),this.drawRange.start=e.drawRange.start,this.drawRange.count=e.drawRange.count,this.userData=e.userData,this}dispose(){this.dispatchEvent({type:"dispose"})}};function Ke(r,e){let t=new Dt;return t.type=r,t.parameters=e,t}function Ns(r=1,e=1,t=1,n=1,i=1,o=1){let a=Ke("box",{width:r,height:e,depth:t,widthSegments:n,heightSegments:i,depthSegments:o});n=Math.floor(n),i=Math.floor(i),o=Math.floor(o);let s=[],l=[],c=[],d=[],u=0,h=0;return m("z","y","x",-1,-1,t,e,r,o,i,0),m("z","y","x",1,-1,t,e,-r,o,i,1),m("x","z","y",1,1,r,t,e,n,o,2),m("x","z","y",1,-1,r,t,-e,n,o,3),m("x","y","z",1,-1,r,e,t,n,i,4),m("x","y","z",-1,-1,r,e,-t,n,i,5),a.setIndex(s),a.setAttribute("position",new de(new Float32Array(l),3)),a.setAttribute("normal",new de(new Float32Array(c),3)),a.setAttribute("uv",new de(new Float32Array(d),2)),a;function m(f,g,v,M,T,_,A,U,w,E,p){let y=_/w,R=A/E,D=_/2,F=A/2,G=U/2,B=w+1,Z=E+1,re=0,oe=0,Y=new L;for(let ae=0;ae<Z;ae++){let he=ae*R-F;for(let me=0;me<B;me++){let Ue=me*y-D;Y[f]=Ue*M,Y[g]=he*T,Y[v]=G,l.push(Y.x,Y.y,Y.z),Y[f]=0,Y[g]=0,Y[v]=U>0?1:-1,c.push(Y.x,Y.y,Y.z),d.push(me/w),d.push(1-ae/E),re+=1}}for(let ae=0;ae<E;ae++)for(let he=0;he<w;he++){let me=u+he+B*ae,Ue=u+he+B*(ae+1),Ge=u+(he+1)+B*(ae+1),ze=u+(he+1)+B*ae;s.push(me,Ue,ze),s.push(Ue,Ge,ze),oe+=6}a.addGroup(h,oe,p),h+=oe,u+=re}}function fo(r=1,e=1,t=1,n=32,i=1,o=!1,a=0,s=Math.PI*2){let l=Ke("cylinder",{radiusTop:r,radiusBottom:e,height:t,radialSegments:n,heightSegments:i,openEnded:o,thetaStart:a,thetaLength:s});n=Math.floor(n),i=Math.floor(i);let c=[],d=[],u=[],h=[],m=0,f=[],g=t/2,v=0;return M(),o===!1&&(r>0&&T(!0),e>0&&T(!1)),l.setIndex(c),l.setAttribute("position",new de(new Float32Array(d),3)),l.setAttribute("normal",new de(new Float32Array(u),3)),l.setAttribute("uv",new de(new Float32Array(h),2)),l;function M(){let _=new L,A=new L,U=0,w=(e-r)/t;for(let E=0;E<=i;E++){let p=[],y=E/i,R=y*(e-r)+r;for(let D=0;D<=n;D++){let F=D/n,G=F*s+a,B=Math.sin(G),Z=Math.cos(G);A.x=R*B,A.y=-y*t+g,A.z=R*Z,d.push(A.x,A.y,A.z),_.set(B,w,Z).normalize(),u.push(_.x,_.y,_.z),h.push(F,1-y),p.push(m++)}f.push(p)}for(let E=0;E<n;E++)for(let p=0;p<i;p++){let y=f[p][E],R=f[p+1][E],D=f[p+1][E+1],F=f[p][E+1];(r>0||p!==0)&&(c.push(y,R,F),U+=3),(e>0||p!==i-1)&&(c.push(R,D,F),U+=3)}l.addGroup(v,U,0),v+=U}function T(_){let A=m,U=new W,w=new L,E=0,p=_===!0?r:e,y=_===!0?1:-1;for(let D=1;D<=n;D++)d.push(0,g*y,0),u.push(0,y,0),h.push(.5,.5),m++;let R=m;for(let D=0;D<=n;D++){let G=D/n*s+a,B=Math.cos(G),Z=Math.sin(G);w.x=p*Z,w.y=g*y,w.z=p*B,d.push(w.x,w.y,w.z),u.push(0,y,0),U.x=B*.5+.5,U.y=Z*.5*y+.5,h.push(U.x,U.y),m++}for(let D=0;D<n;D++){let F=A+D,G=R+D;_===!0?c.push(G,G+1,F):c.push(G+1,G,F),E+=3}l.addGroup(v,E,_===!0?1:2),v+=E}}function Vs(r=1,e=1,t=32,n=1,i=!1,o=0,a=Math.PI*2){let s=fo(0,r,e,t,n,i,o,a);return s.type="cone",s.parameters={radius:r,height:e,radialSegments:t,heightSegments:n,openEnded:i,thetaStart:o,thetaLength:a},s}function Os(r=1,e=32,t=16,n=0,i=Math.PI*2,o=0,a=Math.PI){let s=Ke("sphere",{radius:r,widthSegments:e,heightSegments:t,phiStart:n,phiLength:i,thetaStart:o,thetaLength:a});e=Math.max(3,Math.floor(e)),t=Math.max(2,Math.floor(t));let l=Math.min(o+a,Math.PI),c=0,d=[],u=new L,h=new L,m=[],f=[],g=[],v=[];for(let M=0;M<=t;M++){let T=[],_=M/t,A=0;M===0&&o===0?A=.5/e:M===t&&l===Math.PI&&(A=-.5/e);for(let U=0;U<=e;U++){let w=U/e;u.x=-r*Math.cos(n+w*i)*Math.sin(o+_*a),u.y=r*Math.cos(o+_*a),u.z=r*Math.sin(n+w*i)*Math.sin(o+_*a),f.push(u.x,u.y,u.z),h.copy(u).normalize(),g.push(h.x,h.y,h.z),v.push(w+A,1-_),T.push(c++)}d.push(T)}for(let M=0;M<t;M++)for(let T=0;T<e;T++){let _=d[M][T+1],A=d[M][T],U=d[M+1][T],w=d[M+1][T+1];(M!==0||o>0)&&m.push(_,A,w),(M!==t-1||l<Math.PI)&&m.push(A,U,w)}return s.setIndex(m),s.setAttribute("position",new de(new Float32Array(f),3)),s.setAttribute("normal",new de(new Float32Array(g),3)),s.setAttribute("uv",new de(new Float32Array(v),2)),s}function po(r=[],e=[],t=1,n=0){let i=Ke("polyhedron",{vertices:r,indices:e,radius:t,detail:n}),o=[],a=[];return s(n),c(t),d(),i.setAttribute("position",new de(new Float32Array(o),3)),i.setAttribute("normal",new de(new Float32Array(o.slice()),3)),i.setAttribute("uv",new de(new Float32Array(a),2)),n===0?i.computeVertexNormals():i.normalizeNormals(),i;function s(T){let _=new L,A=new L,U=new L;for(let w=0;w<e.length;w+=3)m(e[w+0],_),m(e[w+1],A),m(e[w+2],U),l(_,A,U,T)}function l(T,_,A,U){let w=U+1,E=[];for(let p=0;p<=w;p++){E[p]=[];let y=T.clone().lerp(A,p/w),R=_.clone().lerp(A,p/w),D=w-p;for(let F=0;F<=D;F++)F===0&&p===w?E[p][F]=y:E[p][F]=y.clone().lerp(R,F/D)}for(let p=0;p<w;p++)for(let y=0;y<2*(w-p)-1;y++){let R=Math.floor(y/2);y%2===0?(h(E[p][R+1]),h(E[p+1][R]),h(E[p][R])):(h(E[p][R+1]),h(E[p+1][R+1]),h(E[p+1][R]))}}function c(T){let _=new L;for(let A=0;A<o.length;A+=3)_.x=o[A+0],_.y=o[A+1],_.z=o[A+2],_.normalize().multiplyScalar(T),o[A+0]=_.x,o[A+1]=_.y,o[A+2]=_.z}function d(){let T=new L;for(let _=0;_<o.length;_+=3){T.x=o[_+0],T.y=o[_+1],T.z=o[_+2];let A=v(T)/2/Math.PI+.5,U=M(T)/Math.PI+.5;a.push(A,1-U)}f(),u()}function u(){for(let T=0;T<a.length;T+=6){let _=a[T+0],A=a[T+2],U=a[T+4],w=Math.max(_,A,U),E=Math.min(_,A,U);w>.9&&E<.1&&(_<.2&&(a[T+0]+=1),A<.2&&(a[T+2]+=1),U<.2&&(a[T+4]+=1))}}function h(T){o.push(T.x,T.y,T.z)}function m(T,_){let A=T*3;_.x=r[A+0],_.y=r[A+1],_.z=r[A+2]}function f(){let T=new L,_=new L,A=new L,U=new L,w=new W,E=new W,p=new W;for(let y=0,R=0;y<o.length;y+=9,R+=6){T.set(o[y+0],o[y+1],o[y+2]),_.set(o[y+3],o[y+4],o[y+5]),A.set(o[y+6],o[y+7],o[y+8]),w.set(a[R+0],a[R+1]),E.set(a[R+2],a[R+3]),p.set(a[R+4],a[R+5]),U.copy(T).add(_).add(A).divideScalar(3);let D=v(U);g(w,R+0,T,D),g(E,R+2,_,D),g(p,R+4,A,D)}}function g(T,_,A,U){U<0&&T.x===1&&(a[_]=T.x-1),A.x===0&&A.z===0&&(a[_]=U/2/Math.PI+.5)}function v(T){return Math.atan2(T.z,-T.x)}function M(T){return Math.atan2(-T.y,Math.sqrt(T.x*T.x+T.z*T.z))}}function En(r,e,t,n,i){let o=po(e,t,n,i);return o.type=r,o.parameters={radius:n,detail:i},o}function ks(r=1,e=0){let t=(1+Math.sqrt(5))/2,n=[-1,t,0,1,t,0,-1,-t,0,1,-t,0,0,-1,t,0,1,t,0,-1,-t,0,1,-t,t,0,-1,t,0,1,-t,0,-1,-t,0,1];return En("icosahedron",n,[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1],r,e)}function zs(r=1,e=0){return En("octahedron",[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],r,e)}function Bs(r=1,e=0){let t=(1+Math.sqrt(5))/2,n=1/t,i=[-1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,0,-n,-t,0,-n,t,0,n,-t,0,n,t,-n,-t,0,-n,t,0,n,-t,0,n,t,0,-t,0,-n,t,0,-n,-t,0,n,t,0,n];return En("dodecahedron",i,[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9],r,e)}function Gs(r=1,e=0){return En("tetrahedron",[1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],r,e)}function ai(r=1,e=1,t=1,n=1){let i=Ke("plane",{width:r,height:e,widthSegments:t,heightSegments:n}),o=r/2,a=e/2,s=Math.floor(t),l=Math.floor(n),c=s+1,d=l+1,u=r/s,h=e/l,m=[],f=[],g=[],v=[];for(let M=0;M<d;M++){let T=M*h-a;for(let _=0;_<c;_++){let A=_*u-o;f.push(A,-T,0),g.push(0,0,1),v.push(_/s),v.push(1-M/l)}}for(let M=0;M<l;M++)for(let T=0;T<s;T++){let _=T+c*M,A=T+c*(M+1),U=T+1+c*(M+1),w=T+1+c*M;m.push(_,A,w),m.push(A,U,w)}return i.setIndex(m),i.setAttribute("position",new de(new Float32Array(f),3)),i.setAttribute("normal",new de(new Float32Array(g),3)),i.setAttribute("uv",new de(new Float32Array(v),2)),i}function Hs(r=.5,e=1,t=32,n=1,i=0,o=Math.PI*2){let a=Ke("ring",{innerRadius:r,outerRadius:e,thetaSegments:t,phiSegments:n,thetaStart:i,thetaLength:o});t=Math.max(3,t),n=Math.max(1,n);let s=[],l=[],c=[],d=[],u=r,h=(e-r)/n,m=new L,f=new W;for(let g=0;g<=n;g++){for(let v=0;v<=t;v++){let M=i+v/t*o;m.x=u*Math.cos(M),m.y=u*Math.sin(M),l.push(m.x,m.y,m.z),c.push(0,0,1),f.x=(m.x/e+1)/2,f.y=(m.y/e+1)/2,d.push(f.x,f.y)}u+=h}for(let g=0;g<n;g++){let v=g*(t+1);for(let M=0;M<t;M++){let T=M+v,_=T,A=T+t+1,U=T+t+2,w=T+1;s.push(_,A,w),s.push(A,U,w)}}return a.setIndex(s),a.setAttribute("position",new de(new Float32Array(l),3)),a.setAttribute("normal",new de(new Float32Array(c),3)),a.setAttribute("uv",new de(new Float32Array(d),2)),a}function Ws(r=1,e=.4,t=12,n=48,i=Math.PI*2){let o=Ke("torus",{radius:r,tube:e,radialSegments:t,tubularSegments:n,arc:i});t=Math.floor(t),n=Math.floor(n);let a=[],s=[],l=[],c=[],d=new L,u=new L,h=new L;for(let m=0;m<=t;m++)for(let f=0;f<=n;f++){let g=f/n*i,v=m/t*Math.PI*2;u.x=(r+e*Math.cos(v))*Math.cos(g),u.y=(r+e*Math.cos(v))*Math.sin(g),u.z=e*Math.sin(v),s.push(u.x,u.y,u.z),d.x=r*Math.cos(g),d.y=r*Math.sin(g),h.subVectors(u,d).normalize(),l.push(h.x,h.y,h.z),c.push(f/n),c.push(m/t)}for(let m=1;m<=t;m++)for(let f=1;f<=n;f++){let g=(n+1)*m+f-1,v=(n+1)*(m-1)+f-1,M=(n+1)*(m-1)+f,T=(n+1)*m+f;a.push(g,v,T),a.push(v,M,T)}return o.setIndex(a),o.setAttribute("position",new de(new Float32Array(s),3)),o.setAttribute("normal",new de(new Float32Array(l),3)),o.setAttribute("uv",new de(new Float32Array(c),2)),o}var Qe=class{type;arcLengthDivisions;needsUpdate;cacheArcLengths;constructor(){this.type="Curve",this.arcLengthDivisions=200,this.needsUpdate=!1,this.cacheArcLengths=null}getPointAt(e,t){let n=this.getUtoTmapping(e);return this.getPoint(n,t)}getPoints(e=5){let t=[];for(let n=0;n<=e;n++)t.push(this.getPoint(n/e));return t}getSpacedPoints(e=5){let t=[];for(let n=0;n<=e;n++)t.push(this.getPointAt(n/e));return t}getLength(){let e=this.getLengths();return e[e.length-1]}getLengths(e=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===e+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;let t=[],n,i=this.getPoint(0),o=0;t.push(0);for(let a=1;a<=e;a++)n=this.getPoint(a/e),o+=n.distanceTo(i),t.push(o),i=n;return this.cacheArcLengths=t,t}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(e,t=null){let n=this.getLengths(),i=0,o=n.length,a;t?a=t:a=e*n[o-1];let s=0,l=o-1,c;for(;s<=l;)if(i=Math.floor(s+(l-s)/2),c=n[i]-a,c<0)s=i+1;else if(c>0)l=i-1;else{l=i;break}if(i=l,n[i]===a)return i/(o-1);let d=n[i],h=n[i+1]-d,m=(a-d)/h;return(i+m)/(o-1)}getTangent(e,t){let i=e-1e-4,o=e+1e-4;i<0&&(i=0),o>1&&(o=1);let a=this.getPoint(i),s=this.getPoint(o),l=t||(a.isVector2?new W:new L);return l.copy(s).sub(a).normalize(),l}getTangentAt(e,t){let n=this.getUtoTmapping(e);return this.getTangent(n,t)}computeFrenetFrames(e,t=!1){let n=new L,i=[],o=[],a=[],s=new L,l=new Ve;for(let m=0;m<=e;m++){let f=m/e;i[m]=this.getTangentAt(f,new L)}o[0]=new L,a[0]=new L;let c=Number.MAX_VALUE,d=Math.abs(i[0].x),u=Math.abs(i[0].y),h=Math.abs(i[0].z);d<=c&&(c=d,n.set(1,0,0)),u<=c&&(c=u,n.set(0,1,0)),h<=c&&n.set(0,0,1),s.crossVectors(i[0],n).normalize(),o[0].crossVectors(i[0],s),a[0].crossVectors(i[0],o[0]);for(let m=1;m<=e;m++){if(o[m]=o[m-1].clone(),a[m]=a[m-1].clone(),s.crossVectors(i[m-1],i[m]),s.length()>Number.EPSILON){s.normalize();let f=Math.acos(ve(i[m-1].dot(i[m]),-1,1));o[m].applyMatrix4(l.makeRotationAxis(s,f))}a[m].crossVectors(i[m],o[m])}if(t===!0){let m=Math.acos(ve(o[0].dot(o[e]),-1,1));m/=e,i[0].dot(s.crossVectors(o[0],o[e]))>0&&(m=-m);for(let f=1;f<=e;f++)o[f].applyMatrix4(l.makeRotationAxis(i[f],m*f)),a[f].crossVectors(i[f],o[f])}return{tangents:i,normals:o,binormals:a}}clone(){return new this.constructor().copy(this)}copy(e){return this.arcLengthDivisions=e.arcLengthDivisions,this}};var go={};Ba(go,{CatmullRom:()=>wn,CubicBezier:()=>ir,QuadraticBezier:()=>nr});function wn(r,e,t,n,i){let o=(n-e)*.5,a=(i-t)*.5,s=r*r,l=r*s;return(2*t-2*n+o+a)*l+(-3*t+3*n-2*o-a)*s+o*r+t}function Xs(r,e){let t=1-r;return t*t*e}function qs(r,e){return 2*(1-r)*r*e}function Ys(r,e){return r*r*e}function nr(r,e,t,n){return Xs(r,e)+qs(r,t)+Ys(r,n)}function js(r,e){let t=1-r;return t*t*t*e}function Zs(r,e){let t=1-r;return 3*t*t*r*e}function Ks(r,e){return 3*(1-r)*r*r*e}function Qs(r,e){return r*r*r*e}function ir(r,e,t,n,i){return js(r,e)+Zs(r,t)+Ks(r,n)+Qs(r,i)}var Xr=class extends Qe{isQuadraticBezierCurve3=!0;v0;v1;v2;constructor(e=new L,t=new L,n=new L){super(),this.type="QuadraticBezierCurve3",this.v0=e,this.v1=t,this.v2=n}getPoint(e,t=new L){let n=t,i=this.v0,o=this.v1,a=this.v2;return n.set(nr(e,i.x,o.x,a.x),nr(e,i.y,o.y,a.y),nr(e,i.z,o.z,a.z)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}};function $s(r=new Xr(new L(-1,-1,0),new L(-1,1,0),new L(1,1,0)),e=64,t=1,n=8,i=!1){let o=Ke("tube",{path:r,tubularSegments:e,radius:t,radialSegments:n,closed:i}),a=r.computeFrenetFrames(e,i);o.tangents=a.tangents,o.normals=a.normals,o.binormals=a.binormals;let s=new L,l=new L,c=new W,d=new L,u=[],h=[],m=[],f=[];return g(),o.setIndex(f),o.setAttribute("position",new de(new Float32Array(u),3)),o.setAttribute("normal",new de(new Float32Array(h),3)),o.setAttribute("uv",new de(new Float32Array(m),2)),o;function g(){for(let _=0;_<e;_++)v(_);v(i===!1?e:0),T(),M()}function v(_){d=r.getPointAt(_/e,d);let A=a.normals[_],U=a.binormals[_];for(let w=0;w<=n;w++){let E=w/n*Math.PI*2,p=Math.sin(E),y=-Math.cos(E);l.x=y*A.x+p*U.x,l.y=y*A.y+p*U.y,l.z=y*A.z+p*U.z,l.normalize(),h.push(l.x,l.y,l.z),s.x=d.x+t*l.x,s.y=d.y+t*l.y,s.z=d.z+t*l.z,u.push(s.x,s.y,s.z)}}function M(){for(let _=1;_<=e;_++)for(let A=1;A<=n;A++){let U=(n+1)*(_-1)+(A-1),w=(n+1)*_+(A-1),E=(n+1)*_+A,p=(n+1)*(_-1)+A;f.push(U,w,p),f.push(w,E,p)}}function T(){for(let _=0;_<=e;_++)for(let A=0;A<=n;A++)c.x=_/e,c.y=A/n,m.push(c.x,c.y)}}function Js(r=[new W(0,-.5),new W(.5,0),new W(0,.5)],e=12,t=0,n=Math.PI*2){let i=Ke("lathe",{points:r,segments:e,phiStart:t,phiLength:n});e=Math.floor(e),n=ve(n,0,Math.PI*2);let o=[],a=[],s=[],l=[],c=[],d=1/e,u=new L,h=new W,m=new L,f=new L,g=new L,v=0,M=0;for(let T=0;T<=r.length-1;T++)switch(T){case 0:v=r[T+1].x-r[T].x,M=r[T+1].y-r[T].y,m.x=M*1,m.y=-v,m.z=M*0,g.copy(m),m.normalize(),l.push(m.x,m.y,m.z);break;case r.length-1:l.push(g.x,g.y,g.z);break;default:v=r[T+1].x-r[T].x,M=r[T+1].y-r[T].y,m.x=M*1,m.y=-v,m.z=M*0,f.copy(m),m.x+=g.x,m.y+=g.y,m.z+=g.z,m.normalize(),l.push(m.x,m.y,m.z),g.copy(f)}for(let T=0;T<=e;T++){let _=t+T*d*n,A=Math.sin(_),U=Math.cos(_);for(let w=0;w<=r.length-1;w++){u.x=r[w].x*A,u.y=r[w].y,u.z=r[w].x*U,a.push(u.x,u.y,u.z),h.x=T/e,h.y=w/(r.length-1),s.push(h.x,h.y);let E=l[3*w+0]*A,p=l[3*w+1],y=l[3*w+0]*U;c.push(E,p,y)}}for(let T=0;T<e;T++)for(let _=0;_<r.length-1;_++){let A=_+T*r.length,U=A,w=A+r.length,E=A+r.length+1,p=A+1;o.push(U,w,p),o.push(E,p,w)}return i.setIndex(o),i.setAttribute("position",new de(new Float32Array(a),3)),i.setAttribute("uv",new de(new Float32Array(s),2)),i.setAttribute("normal",new de(new Float32Array(c),3)),i}var mr=class extends Qe{isLineCurve=!0;v1;v2;constructor(e=new W,t=new W){super(),this.type="LineCurve",this.v1=e,this.v2=t}getPoint(e,t=new W){let n=t;return e===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(e).add(this.v1)),n}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new W){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}};var qr=class extends Qe{isLineCurve3=!0;v1;v2;constructor(e=new L,t=new L){super(),this.type="LineCurve3",this.v1=e,this.v2=t}getPoint(e,t=new L){let n=t;return e===1?n.copy(this.v2):(n.copy(this.v2).sub(this.v1),n.multiplyScalar(e).add(this.v1)),n}getPointAt(e,t){return this.getPoint(e,t)}getTangent(e,t=new L){return t.subVectors(this.v2,this.v1).normalize()}getTangentAt(e,t){return this.getTangent(e,t)}copy(e){return super.copy(e),this.v1.copy(e.v1),this.v2.copy(e.v2),this}};var Yr=class extends Qe{curves;autoClose;cacheLengths=null;constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(e){this.curves.push(e)}closePath(){let e=this.curves[0].getPoint(0),t=this.curves[this.curves.length-1].getPoint(1);if(!e.equals(t)){let n=e.isVector2===!0?new mr(t,e):new qr(t,e);this.curves.push(n)}return this}getPoint(e,t){let n=e*this.getLength(),i=this.getCurveLengths(),o=0;for(;o<i.length;){if(i[o]>=n){let a=i[o]-n,s=this.curves[o],l=s.getLength(),c=l===0?0:1-a/l;return s.getPointAt(c,t)}o++}return null}getLength(){let e=this.getCurveLengths();return e[e.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;let e=[],t=0;for(let n=0,i=this.curves.length;n<i;n++)t+=this.curves[n].getLength(),e.push(t);return this.cacheLengths=e,e}getSpacedPoints(e=40){let t=[];for(let n=0;n<=e;n++)t.push(this.getPoint(n/e));return this.autoClose&&t.push(t[0]),t}getPoints(e=12){let t=[],n;for(let i=0,o=this.curves;i<o.length;i++){let a=o[i],s=a,l=s.isEllipseCurve?e*2:s.isLineCurve||s.isLineCurve3?1:s.isSplineCurve?e*s.points.length:e,c=a.getPoints(l);for(let d=0;d<c.length;d++){let u=c[d];n&&n.equals(u)||(t.push(u),n=u)}}return this.autoClose&&t.length>1&&!t[t.length-1].equals(t[0])&&t.push(t[0]),t}copy(e){super.copy(e),this.curves=[];for(let t=0,n=e.curves.length;t<n;t++){let i=e.curves[t];this.curves.push(i.clone())}return this.autoClose=e.autoClose,this}};var fr=class extends Qe{isEllipseCurve=!0;aX;aY;xRadius;yRadius;aStartAngle;aEndAngle;aClockwise;aRotation;constructor(e=0,t=0,n=1,i=1,o=0,a=Math.PI*2,s=!1,l=0){super(),this.type="EllipseCurve",this.aX=e,this.aY=t,this.xRadius=n,this.yRadius=i,this.aStartAngle=o,this.aEndAngle=a,this.aClockwise=s,this.aRotation=l}getPoint(e,t=new W){let n=t,i=Math.PI*2,o=this.aEndAngle-this.aStartAngle,a=Math.abs(o)<Number.EPSILON;for(;o<0;)o+=i;for(;o>i;)o-=i;o<Number.EPSILON&&(a?o=0:o=i),this.aClockwise===!0&&!a&&(o===i?o=-i:o=o-i);let s=this.aStartAngle+e*o,l=this.aX+this.xRadius*Math.cos(s),c=this.aY+this.yRadius*Math.sin(s);if(this.aRotation!==0){let d=Math.cos(this.aRotation),u=Math.sin(this.aRotation),h=l-this.aX,m=c-this.aY;l=h*d-m*u+this.aX,c=h*u+m*d+this.aY}return n.set(l,c)}copy(e){return super.copy(e),this.aX=e.aX,this.aY=e.aY,this.xRadius=e.xRadius,this.yRadius=e.yRadius,this.aStartAngle=e.aStartAngle,this.aEndAngle=e.aEndAngle,this.aClockwise=e.aClockwise,this.aRotation=e.aRotation,this}};var jr=class extends Qe{isSplineCurve=!0;points;constructor(e=[]){super(),this.type="SplineCurve",this.points=e}getPoint(e,t=new W){let n=t,i=this.points,o=(i.length-1)*e,a=Math.floor(o),s=o-a,l=i[a===0?a:a-1],c=i[a],d=i[a>i.length-2?i.length-1:a+1],u=i[a>i.length-3?i.length-1:a+2];return n.set(wn(s,l.x,c.x,d.x,u.x),wn(s,l.y,c.y,d.y,u.y)),n}copy(e){super.copy(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){let i=e.points[t];this.points.push(i.clone())}return this}};var Zr=class extends Qe{isCubicBezierCurve=!0;v0;v1;v2;v3;constructor(e=new W,t=new W,n=new W,i=new W){super(),this.type="CubicBezierCurve",this.v0=e,this.v1=t,this.v2=n,this.v3=i}getPoint(e,t=new W){let n=t,i=this.v0,o=this.v1,a=this.v2,s=this.v3;return n.set(ir(e,i.x,o.x,a.x,s.x),ir(e,i.y,o.y,a.y,s.y)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}};var Kr=class extends Qe{isQuadraticBezierCurve=!0;v0;v1;v2;constructor(e=new W,t=new W,n=new W){super(),this.type="QuadraticBezierCurve",this.v0=e,this.v1=t,this.v2=n}getPoint(e,t=new W){let n=t,i=this.v0,o=this.v1,a=this.v2;return n.set(nr(e,i.x,o.x,a.x),nr(e,i.y,o.y,a.y)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this}};var Qr=class extends Yr{currentPoint;constructor(e){super(),this.type="Path",this.currentPoint=new W,e&&this.setFromPoints(e)}setFromPoints(e){this.moveTo(e[0].x,e[0].y);for(let t=1,n=e.length;t<n;t++)this.lineTo(e[t].x,e[t].y);return this}moveTo(e,t){return this.currentPoint.set(e,t),this}lineTo(e,t){let n=new mr(this.currentPoint.clone(),new W(e,t));return this.curves.push(n),this.currentPoint.set(e,t),this}quadraticCurveTo(e,t,n,i){let o=new Kr(this.currentPoint.clone(),new W(e,t),new W(n,i));return this.curves.push(o),this.currentPoint.set(n,i),this}bezierCurveTo(e,t,n,i,o,a){let s=new Zr(this.currentPoint.clone(),new W(e,t),new W(n,i),new W(o,a));return this.curves.push(s),this.currentPoint.set(o,a),this}splineThru(e){let t=[this.currentPoint.clone()].concat(e),n=new jr(t);return this.curves.push(n),this.currentPoint.copy(e[e.length-1]),this}arc(e,t,n,i,o,a){let s=this.currentPoint.x,l=this.currentPoint.y;return this.absarc(e+s,t+l,n,i,o,a),this}absarc(e,t,n,i,o,a){return this.absellipse(e,t,n,n,i,o,a),this}ellipse(e,t,n,i,o,a,s,l){let c=this.currentPoint.x,d=this.currentPoint.y;return this.absellipse(e+c,t+d,n,i,o,a,s,l),this}absellipse(e,t,n,i,o,a,s,l){let c=new fr(e,t,n,i,o,a,s,l);if(this.curves.length>0){let u=c.getPoint(0);u.equals(this.currentPoint)||this.lineTo(u.x,u.y)}this.curves.push(c);let d=c.getPoint(1);return this.currentPoint.copy(d),this}copy(e){return super.copy(e),this.currentPoint.copy(e.currentPoint),this}};var pr=class extends Qr{uuid;holes;constructor(e){super(e),this.uuid=yt(),this.type="Shape",this.holes=[]}getPointsHoles(e){let t=[];for(let n=0,i=this.holes.length;n<i;n++)t[n]=this.holes[n].getPoints(e);return t}extractPoints(e){return{shape:this.getPoints(e),holes:this.getPointsHoles(e)}}copy(e){super.copy(e),this.holes=[];for(let t=0,n=e.holes.length;t<n;t++){let i=e.holes[t];this.holes.push(i.clone())}return this}};function xo(r,e,t=2){let n=e&&e.length,i=n?e[0]*t:r.length,o=vo(r,0,i,t,!0),a=[];if(!o||o.next===o.prev)return a;let s=0,l=0,c=0;if(n&&(o=il(r,e,o,t)),r.length>80*t){s=1/0,l=1/0;let d=-1/0,u=-1/0;for(let h=t;h<i;h+=t){let m=r[h],f=r[h+1];m<s&&(s=m),f<l&&(l=f),m>d&&(d=m),f>u&&(u=f)}c=Math.max(d-s,u-l),c=c!==0?32767/c:0}return Jr(o,a,t,s,l,c,0),a}var ci={triangulate(r,e,t=2){return xo(r,e,t)}};function vo(r,e,t,n,i){let o;if(i===ui(r,e,t,n)>0)for(let a=e;a<t;a+=n)o=bo(a/n|0,r[a],r[a+1],o);else for(let a=t-n;a>=e;a-=n)o=bo(a/n|0,r[a],r[a+1],o);return o&&Dr(o,o.next)&&(tn(o),o=o.next),o}function gr(r,e){if(!r)return r;e||(e=r);let t=r,n;do if(n=!1,!t.steiner&&(Dr(t,t.next)||$e(t.prev,t,t.next)===0)){if(tn(t),t=e=t.prev,t===t.next)break;n=!0}else t=t.next;while(n||t!==e);return e}function Jr(r,e,t,n,i,o,a){if(!r)return;let s=r;!a&&o&&ul(s,n,i,o);let l=s;for(;s.prev!==s.next;){let c=s.prev,d=s.next;if(o?tl(s,n,i,o):el(s)){e.push(c.i,s.i,d.i),tn(s),s=d.next,l=d.next;continue}if(s=d,s===l){a?a===1?Jr(rl(gr(s),e),e,t,n,i,o,2):a===2&&nl(s,e,t,n,i,o):Jr(gr(s),e,t,n,i,o,1);break}}}function el(r){let e=r.prev,t=r,n=r.next;if($e(e,t,n)>=0)return!1;let i=e.x,o=t.x,a=n.x,s=e.y,l=t.y,c=n.y,d=Math.min(i,o,a),u=Math.min(s,l,c),h=Math.max(i,o,a),m=Math.max(s,l,c),f=n.next;for(;f!==e;){if(f.x>=d&&f.x<=h&&f.y>=u&&f.y<=m&&$r(i,s,o,l,a,c,f.x,f.y)&&$e(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function tl(r,e,t,n){let i=r.prev,o=r,a=r.next;if($e(i,o,a)>=0)return!1;let s=i.x,l=o.x,c=a.x,d=i.y,u=o.y,h=a.y,m=Math.min(s,l,c),f=Math.min(d,u,h),g=Math.max(s,l,c),v=Math.max(d,u,h),M=si(m,f,e,t,n),T=si(g,v,e,t,n),_=r.prevZ,A=r.nextZ;for(;_&&_.z>=M&&A&&A.z<=T;){if(_.x>=m&&_.x<=g&&_.y>=f&&_.y<=v&&_!==i&&_!==a&&$r(s,d,l,u,c,h,_.x,_.y)&&$e(_.prev,_,_.next)>=0||(_=_.prevZ,A.x>=m&&A.x<=g&&A.y>=f&&A.y<=v&&A!==i&&A!==a&&$r(s,d,l,u,c,h,A.x,A.y)&&$e(A.prev,A,A.next)>=0))return!1;A=A.nextZ}for(;_&&_.z>=M;){if(_.x>=m&&_.x<=g&&_.y>=f&&_.y<=v&&_!==i&&_!==a&&$r(s,d,l,u,c,h,_.x,_.y)&&$e(_.prev,_,_.next)>=0)return!1;_=_.prevZ}for(;A&&A.z<=T;){if(A.x>=m&&A.x<=g&&A.y>=f&&A.y<=v&&A!==i&&A!==a&&$r(s,d,l,u,c,h,A.x,A.y)&&$e(A.prev,A,A.next)>=0)return!1;A=A.nextZ}return!0}function rl(r,e){let t=r;do{let n=t.prev,i=t.next.next;!Dr(n,i)&&Mo(n,t,t.next,i)&&en(n,i)&&en(i,n)&&(e.push(n.i,t.i,i.i),tn(t),tn(t.next),t=r=i),t=t.next}while(t!==r);return gr(t)}function nl(r,e,t,n,i,o){let a=r;do{let s=a.next.next;for(;s!==a.prev;){if(a.i!==s.i&&hl(a,s)){let l=So(a,s),c=gr(a,a.next);l=gr(l,l.next),Jr(c,e,t,n,i,o,0),Jr(l,e,t,n,i,o,0);return}s=s.next}a=a.next}while(a!==r)}function il(r,e,t,n){let i=[];for(let o=0,a=e.length;o<a;o++){let s=e[o]*n,l=o<a-1?e[o+1]*n:r.length,c=vo(r,s,l,n,!1);c===c.next&&(c.steiner=!0),i.push(dl(c))}i.sort(ol);for(let o=0;o<i.length;o++)t=al(i[o],t);return t}function ol(r,e){let t=r.x-e.x;if(t===0&&(t=r.y-e.y,t===0)){let n=(r.next.y-r.y)/(r.next.x-r.x),i=(e.next.y-e.y)/(e.next.x-e.x);t=n-i}return t}function al(r,e){let t=sl(r,e);if(!t)return e;let n=So(t,r);return gr(n,n.next),gr(t,t.next)}function sl(r,e){let t=e,n=r.x,i=r.y,o=-1/0,a;if(Dr(r,t))return t;do{if(Dr(r,t.next))return t.next;if(i<=t.y&&i>=t.next.y&&t.next.y!==t.y){let u=t.x+(i-t.y)*(t.next.x-t.x)/(t.next.y-t.y);if(u<=n&&u>o&&(o=u,a=t.x<t.next.x?t:t.next,u===n))return a}t=t.next}while(t!==e);if(!a)return null;let s=a,l=a.x,c=a.y,d=1/0;t=a;do{if(n>=t.x&&t.x>=l&&n!==t.x&&yo(i<c?n:o,i,l,c,i<c?o:n,i,t.x,t.y)){let u=Math.abs(i-t.y)/(n-t.x);en(t,r)&&(u<d||u===d&&(t.x>a.x||t.x===a.x&&ll(a,t)))&&(a=t,d=u)}t=t.next}while(t!==s);return a}function ll(r,e){return $e(r.prev,r,e.prev)<0&&$e(e.next,r,r.next)<0}function ul(r,e,t,n){let i=r;do i.z===0&&(i.z=si(i.x,i.y,e,t,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next;while(i!==r);i.prevZ.nextZ=null,i.prevZ=null,cl(i)}function cl(r){let e,t=1;do{let n=r,i;r=null;let o=null;for(e=0;n;){e++;let a=n,s=0;for(let c=0;c<t&&(s++,a=a.nextZ,!!a);c++);let l=t;for(;s>0||l>0&&a;)s!==0&&(l===0||!a||n.z<=a.z)?(i=n,n=n.nextZ,s--):(i=a,a=a.nextZ,l--),o?o.nextZ=i:r=i,i.prevZ=o,o=i;n=a}o.nextZ=null,t*=2}while(e>1);return r}function si(r,e,t,n,i){return r=(r-t)*i|0,e=(e-n)*i|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,r|e<<1}function dl(r){let e=r,t=r;do(e.x<t.x||e.x===t.x&&e.y<t.y)&&(t=e),e=e.next;while(e!==r);return t}function yo(r,e,t,n,i,o,a,s){return(i-a)*(e-s)>=(r-a)*(o-s)&&(r-a)*(n-s)>=(t-a)*(e-s)&&(t-a)*(o-s)>=(i-a)*(n-s)}function $r(r,e,t,n,i,o,a,s){return!(r===a&&e===s)&&yo(r,e,t,n,i,o,a,s)}function hl(r,e){return r.next.i!==e.i&&r.prev.i!==e.i&&!ml(r,e)&&(en(r,e)&&en(e,r)&&fl(r,e)&&!!($e(r.prev,r,e.prev)||$e(r,e.prev,e))||Dr(r,e)&&$e(r.prev,r,r.next)>0&&$e(e.prev,e,e.next)>0)}function $e(r,e,t){return(e.y-r.y)*(t.x-e.x)-(e.x-r.x)*(t.y-e.y)}function Dr(r,e){return r.x===e.x&&r.y===e.y}function Mo(r,e,t,n){let i=Ln($e(r,e,t)),o=Ln($e(r,e,n)),a=Ln($e(t,n,r)),s=Ln($e(t,n,e));return!!(i!==o&&a!==s||i===0&&Cn(r,t,e)||o===0&&Cn(r,n,e)||a===0&&Cn(t,r,n)||s===0&&Cn(t,e,n))}function Cn(r,e,t){return e.x<=Math.max(r.x,t.x)&&e.x>=Math.min(r.x,t.x)&&e.y<=Math.max(r.y,t.y)&&e.y>=Math.min(r.y,t.y)}function Ln(r){return r>0?1:r<0?-1:0}function ml(r,e){let t=r;do{if(t.i!==r.i&&t.next.i!==r.i&&t.i!==e.i&&t.next.i!==e.i&&Mo(t,t.next,r,e))return!0;t=t.next}while(t!==r);return!1}function en(r,e){return $e(r.prev,r,r.next)<0?$e(r,e,r.next)>=0&&$e(r,r.prev,e)>=0:$e(r,e,r.prev)<0||$e(r,r.next,e)<0}function fl(r,e){let t=r,n=!1,i=(r.x+e.x)/2,o=(r.y+e.y)/2;do t.y>o!=t.next.y>o&&t.next.y!==t.y&&i<(t.next.x-t.x)*(o-t.y)/(t.next.y-t.y)+t.x&&(n=!n),t=t.next;while(t!==r);return n}function So(r,e){let t=li(r.i,r.x,r.y),n=li(e.i,e.x,e.y),i=r.next,o=e.prev;return r.next=e,e.prev=r,t.next=i,i.prev=t,n.next=t,t.prev=n,o.next=n,n.prev=o,n}function bo(r,e,t,n){let i=li(r,e,t);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}function tn(r){r.next.prev=r.prev,r.prev.next=r.next,r.prevZ&&(r.prevZ.nextZ=r.nextZ),r.nextZ&&(r.nextZ.prevZ=r.prevZ)}function li(r,e,t){return{i:r,x:e,y:t,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function pl(r,e,t,n){let i=e&&e.length,o=i?e[0]*t:r.length,a=Math.abs(ui(r,0,o,t));if(i)for(let l=0,c=e.length;l<c;l++){let d=e[l]*t,u=l<c-1?e[l+1]*t:r.length;a-=Math.abs(ui(r,d,u,t))}let s=0;for(let l=0;l<n.length;l+=3){let c=n[l]*t,d=n[l+1]*t,u=n[l+2]*t;s+=Math.abs((r[c]-r[u])*(r[d+1]-r[c+1])-(r[c]-r[d])*(r[u+1]-r[c+1]))}return a===0&&s===0?0:Math.abs((s-a)/a)}function ui(r,e,t,n){let i=0;for(let o=e,a=t-n;o<t;o+=n)i+=(r[a]-r[o])*(r[o+1]+r[a+1]),a=o;return i}function Ao(r){let e=r.length,t=0;for(let n=e-1,i=0;i<e;n=i++)t+=r[n].x*r[i].y-r[i].x*r[n].y;return t*.5}function gl(r){return Ao(r)<0}function bl(r,e){let t=[],n=[],i=[];_o(r),To(t,r);let o=r.length;e.forEach(_o);for(let s=0;s<e.length;s++)n.push(o),o+=e[s].length,To(t,e[s]);let a=ci.triangulate(t,n);for(let s=0;s<a.length;s+=3)i.push(a.slice(s,s+3));return i}function _o(r){let e=r.length;e>2&&r[e-1].equals(r[0])&&r.pop()}function To(r,e){for(let t=0;t<e.length;t++)r.push(e[t].x),r.push(e[t].y)}var kt={area:Ao,isClockWise:gl,triangulateShape:bl};var Eo={generateTopUV:function(r,e,t,n,i){let o=e[t*3],a=e[t*3+1],s=e[n*3],l=e[n*3+1],c=e[i*3],d=e[i*3+1];return[new W(o,a),new W(s,l),new W(c,d)]},generateSideWallUV:function(r,e,t,n,i,o){let a=e[t*3],s=e[t*3+1],l=e[t*3+2],c=e[n*3],d=e[n*3+1],u=e[n*3+2],h=e[i*3],m=e[i*3+1],f=e[i*3+2],g=e[o*3],v=e[o*3+1],M=e[o*3+2];return Math.abs(s-d)<Math.abs(a-c)?[new W(a,1-l),new W(c,1-u),new W(h,1-f),new W(g,1-M)]:[new W(s,1-l),new W(d,1-u),new W(m,1-f),new W(v,1-M)]}};function xl(r=new pr([new W(.5,.5),new W(-.5,.5),new W(-.5,-.5),new W(.5,-.5)]),e={}){let t=Ke("extrude",{shapes:r,options:e}),n=Array.isArray(r)?r:[r],i=[],o=[];for(let s=0,l=n.length;s<l;s++){let c=n[s];a(c)}return t.setAttribute("position",new de(new Float32Array(i),3)),t.setAttribute("uv",new de(new Float32Array(o),2)),t.computeVertexNormals(),t;function a(s){let l=[],c=e.curveSegments!==void 0?e.curveSegments:12,d=e.steps!==void 0?e.steps:1,u=e.depth!==void 0?e.depth:1,h=e.bevelEnabled!==void 0?e.bevelEnabled:!0,m=e.bevelThickness!==void 0?e.bevelThickness:.2,f=e.bevelSize!==void 0?e.bevelSize:m-.1,g=e.bevelOffset!==void 0?e.bevelOffset:0,v=e.bevelSegments!==void 0?e.bevelSegments:3,M=e.extrudePath,T=e.UVGenerator!==void 0?e.UVGenerator:Eo,_=[],A=!1,U={tangents:[],normals:[],binormals:[]},w=new L,E=new L,p=new L;M&&(_=M.getSpacedPoints(d),A=!0,h=!1,U=M.computeFrenetFrames(d,!1),w=new L,E=new L,p=new L),h||(v=0,m=0,f=0,g=0);let y=s.extractPoints(c),R=y.shape,D=y.holes;if(!kt.isClockWise(R)){R=R.reverse();for(let H=0,ee=D.length;H<ee;H++){let k=D[H];kt.isClockWise(k)&&(D[H]=k.reverse())}}function G(H){let k=10000000000000001e-36,te=H[0];for(let j=1;j<=H.length;j++){let ue=j%H.length,ce=H[ue],Ae=ce.x-te.x,_e=ce.y-te.y,S=Ae*Ae+_e*_e,b=Math.max(Math.abs(ce.x),Math.abs(ce.y),Math.abs(te.x),Math.abs(te.y)),P=k*b*b;if(S<=P){H.splice(ue,1),j--;continue}te=ce}}G(R),D.forEach(G);let B=D.length,Z=R;for(let H=0;H<B;H++){let ee=D[H];R=R.concat(ee)}function re(H,ee,k){return ee||console.error("keel/lit extrude: vec does not exist"),H.clone().addScaledVector(ee,k)}let oe=R.length;function Y(H,ee,k){let te,j,ue,ce=H.x-ee.x,Ae=H.y-ee.y,_e=k.x-H.x,S=k.y-H.y,b=ce*ce+Ae*Ae,P=ce*S-Ae*_e;if(Math.abs(P)>Number.EPSILON){let X=Math.sqrt(b),K=Math.sqrt(_e*_e+S*S),N=ee.x-Ae/X,Q=ee.y+ce/X,pe=k.x-S/K,be=k.y+_e/K,Oe=((pe-N)*S-(be-Q)*_e)/(ce*S-Ae*_e);te=N+ce*Oe-H.x,j=Q+Ae*Oe-H.y;let ie=te*te+j*j;if(ie<=2)return new W(te,j);ue=Math.sqrt(ie/2)}else{let X=!1;ce>Number.EPSILON?_e>Number.EPSILON&&(X=!0):ce<-Number.EPSILON?_e<-Number.EPSILON&&(X=!0):Math.sign(Ae)===Math.sign(S)&&(X=!0),X?(te=-Ae,j=ce,ue=Math.sqrt(b)):(te=ce,j=Ae,ue=Math.sqrt(b/2))}return new W(te/ue,j/ue)}let ae=[];for(let H=0,ee=Z.length,k=ee-1,te=H+1;H<ee;H++,k++,te++)k===ee&&(k=0),te===ee&&(te=0),ae[H]=Y(Z[H],Z[k],Z[te]);let he=[],me,Ue=ae.concat();for(let H=0,ee=B;H<ee;H++){let k=D[H];me=[];for(let te=0,j=k.length,ue=j-1,ce=te+1;te<j;te++,ue++,ce++)ue===j&&(ue=0),ce===j&&(ce=0),me[te]=Y(k[te],k[ue],k[ce]);he.push(me),Ue=Ue.concat(me)}let Ge;if(v===0)Ge=kt.triangulateShape(Z,D);else{let H=[],ee=[];for(let k=0;k<v;k++){let te=k/v,j=m*Math.cos(te*Math.PI/2),ue=f*Math.sin(te*Math.PI/2)+g;for(let ce=0,Ae=Z.length;ce<Ae;ce++){let _e=re(Z[ce],ae[ce],ue);He(_e.x,_e.y,-j),te===0&&H.push(_e)}for(let ce=0,Ae=B;ce<Ae;ce++){let _e=D[ce];me=he[ce];let S=[];for(let b=0,P=_e.length;b<P;b++){let X=re(_e[b],me[b],ue);He(X.x,X.y,-j),te===0&&S.push(X)}te===0&&ee.push(S)}}Ge=kt.triangulateShape(H,ee)}let ze=Ge.length,ot=f+g;for(let H=0;H<oe;H++){let ee=h?re(R[H],Ue[H],ot):R[H];A?(E.copy(U.normals[0]).multiplyScalar(ee.x),w.copy(U.binormals[0]).multiplyScalar(ee.y),p.copy(_[0]).add(E).add(w),He(p.x,p.y,p.z)):He(ee.x,ee.y,0)}for(let H=1;H<=d;H++)for(let ee=0;ee<oe;ee++){let k=h?re(R[ee],Ue[ee],ot):R[ee];A?(E.copy(U.normals[H]).multiplyScalar(k.x),w.copy(U.binormals[H]).multiplyScalar(k.y),p.copy(_[H]).add(E).add(w),He(p.x,p.y,p.z)):He(k.x,k.y,u/d*H)}for(let H=v-1;H>=0;H--){let ee=H/v,k=m*Math.cos(ee*Math.PI/2),te=f*Math.sin(ee*Math.PI/2)+g;for(let j=0,ue=Z.length;j<ue;j++){let ce=re(Z[j],ae[j],te);He(ce.x,ce.y,u+k)}for(let j=0,ue=D.length;j<ue;j++){let ce=D[j];me=he[j];for(let Ae=0,_e=ce.length;Ae<_e;Ae++){let S=re(ce[Ae],me[Ae],te);A?He(S.x,S.y+_[d-1].y,_[d-1].x+k):He(S.x,S.y,u+k)}}}je(),Fe();function je(){let H=i.length/3;if(h){let ee=0,k=oe*ee;for(let te=0;te<ze;te++){let j=Ge[te];lt(j[2]+k,j[1]+k,j[0]+k)}ee=d+v*2,k=oe*ee;for(let te=0;te<ze;te++){let j=Ge[te];lt(j[0]+k,j[1]+k,j[2]+k)}}else{for(let ee=0;ee<ze;ee++){let k=Ge[ee];lt(k[2],k[1],k[0])}for(let ee=0;ee<ze;ee++){let k=Ge[ee];lt(k[0]+oe*d,k[1]+oe*d,k[2]+oe*d)}}t.addGroup(H,i.length/3-H,0)}function Fe(){let H=i.length/3,ee=0;Be(Z,ee),ee+=Z.length;for(let k=0,te=D.length;k<te;k++){let j=D[k];Be(j,ee),ee+=j.length}t.addGroup(H,i.length/3-H,1)}function Be(H,ee){let k=H.length;for(;--k>=0;){let te=k,j=k-1;j<0&&(j=H.length-1);for(let ue=0,ce=d+v*2;ue<ce;ue++){let Ae=oe*ue,_e=oe*(ue+1),S=ee+te+Ae,b=ee+j+Ae,P=ee+j+_e,X=ee+te+_e;Nt(S,b,P,X)}}}function He(H,ee,k){l.push(H),l.push(ee),l.push(k)}function lt(H,ee,k){J(H),J(ee),J(k);let te=i.length/3,j=T.generateTopUV(t,i,te-3,te-2,te-1);Je(j[0]),Je(j[1]),Je(j[2])}function Nt(H,ee,k,te){J(H),J(ee),J(te),J(ee),J(k),J(te);let j=i.length/3,ue=T.generateSideWallUV(t,i,j-6,j-3,j-2,j-1);Je(ue[0]),Je(ue[1]),Je(ue[3]),Je(ue[1]),Je(ue[2]),Je(ue[3])}function J(H){i.push(l[H*3+0]),i.push(l[H*3+1]),i.push(l[H*3+2])}function Je(H){o.push(H.x),o.push(H.y)}}}function vl(r=new pr([new W(0,.5),new W(-.5,-.5),new W(.5,-.5)]),e=12){let t=Ke("shape",{shapes:r,curveSegments:e}),n=[],i=[],o=[],a=[],s=0,l=0;if(Array.isArray(r)===!1)c(r);else{let d=r;for(let u=0;u<d.length;u++)c(d[u]),t.addGroup(s,l,u),s+=l,l=0}return t.setIndex(n),t.setAttribute("position",new de(new Float32Array(i),3)),t.setAttribute("normal",new de(new Float32Array(o),3)),t.setAttribute("uv",new de(new Float32Array(a),2)),t;function c(d){let u=i.length/3,h=d.extractPoints(e),m=h.shape,f=h.holes;kt.isClockWise(m)===!1&&(m=m.reverse());for(let v=0,M=f.length;v<M;v++){let T=f[v];kt.isClockWise(T)===!0&&(f[v]=T.reverse())}let g=kt.triangulateShape(m,f);for(let v=0,M=f.length;v<M;v++){let T=f[v];m=m.concat(T)}for(let v=0,M=m.length;v<M;v++){let T=m[v];i.push(T.x,T.y,0),o.push(0,0,1),a.push(T.x,T.y)}for(let v=0,M=g.length;v<M;v++){let T=g[v],_=T[0]+u,A=T[1]+u,U=T[2]+u;n.push(_,A,U),l+=3}}}var di=class extends Qe{isCubicBezierCurve3=!0;v0;v1;v2;v3;constructor(e=new L,t=new L,n=new L,i=new L){super(),this.type="CubicBezierCurve3",this.v0=e,this.v1=t,this.v2=n,this.v3=i}getPoint(e,t=new L){let n=t,i=this.v0,o=this.v1,a=this.v2,s=this.v3;return n.set(ir(e,i.x,o.x,a.x,s.x),ir(e,i.y,o.y,a.y,s.y),ir(e,i.z,o.z,a.z,s.z)),n}copy(e){return super.copy(e),this.v0.copy(e.v0),this.v1.copy(e.v1),this.v2.copy(e.v2),this.v3.copy(e.v3),this}};var hi=class extends fr{isArcCurve=!0;constructor(e,t,n,i,o,a){super(e,t,n,n,i,o,a),this.type="ArcCurve"}};function bi(){let r=0,e=0,t=0,n=0;function i(o,a,s,l){r=o,e=s,t=-3*o+3*a-2*s-l,n=2*o-2*a+s+l}return{initCatmullRom:function(o,a,s,l,c){i(a,s,c*(s-o),c*(l-a))},initNonuniformCatmullRom:function(o,a,s,l,c,d,u){let h=(a-o)/c-(s-o)/(c+d)+(s-a)/d,m=(s-a)/d-(l-a)/(d+u)+(l-s)/u;h*=d,m*=d,i(a,s,h,m)},calc:function(o){let a=o*o,s=a*o;return r+e*o+t*a+n*s}}}var Rn=new L,mi=bi(),fi=bi(),pi=bi(),gi=class extends Qe{isCatmullRomCurve3=!0;points;closed;curveType;tension;constructor(e=[],t=!1,n="centripetal",i=.5){super(),this.type="CatmullRomCurve3",this.points=e,this.closed=t,this.curveType=n,this.tension=i}getPoint(e,t=new L){let n=t,i=this.points,o=i.length,a=(o-(this.closed?0:1))*e,s=Math.floor(a),l=a-s;this.closed?s+=s>0?0:(Math.floor(Math.abs(s)/o)+1)*o:l===0&&s===o-1&&(s=o-2,l=1);let c,d;this.closed||s>0?c=i[(s-1)%o]:(Rn.subVectors(i[0],i[1]).add(i[0]),c=Rn);let u=i[s%o],h=i[(s+1)%o];if(this.closed||s+2<o?d=i[(s+2)%o]:(Rn.subVectors(i[o-1],i[o-2]).add(i[o-1]),d=Rn),this.curveType==="centripetal"||this.curveType==="chordal"){let m=this.curveType==="chordal"?.5:.25,f=Math.pow(c.distanceToSquared(u),m),g=Math.pow(u.distanceToSquared(h),m),v=Math.pow(h.distanceToSquared(d),m);g<1e-4&&(g=1),f<1e-4&&(f=g),v<1e-4&&(v=g),mi.initNonuniformCatmullRom(c.x,u.x,h.x,d.x,f,g,v),fi.initNonuniformCatmullRom(c.y,u.y,h.y,d.y,f,g,v),pi.initNonuniformCatmullRom(c.z,u.z,h.z,d.z,f,g,v)}else this.curveType==="catmullrom"&&(mi.initCatmullRom(c.x,u.x,h.x,d.x,this.tension),fi.initCatmullRom(c.y,u.y,h.y,d.y,this.tension),pi.initCatmullRom(c.z,u.z,h.z,d.z,this.tension));return n.set(mi.calc(l),fi.calc(l),pi.calc(l)),n}copy(e){super.copy(e),this.points=[];for(let t=0,n=e.points.length;t<n;t++){let i=e.points[t];this.points.push(i.clone())}return this.closed=e.closed,this.curveType=e.curveType,this.tension=e.tension,this}};var xi=class extends nt{isGroup=!0;constructor(){super(),this.type="Group"}};var vi=class extends nt{isScene=!0;isStage=!0;background;environment;fog;backgroundBlurriness;backgroundIntensity;backgroundRotation;environmentIntensity;environmentRotation;overrideMaterial;constructor(){super(),this.type="Stage",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new vt,this.environmentIntensity=1,this.environmentRotation=new vt,this.overrideMaterial=null}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,this.backgroundRotation.copy(e.backgroundRotation),this.environmentIntensity=e.environmentIntensity,this.environmentRotation.copy(e.environmentRotation),e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}};var yi=class r{isFog=!0;name;color;near;far;constructor(e,t=1,n=1e3){this.name="",this.color=new Pe(e),this.near=t,this.far=n}clone(){return new r(this.color,this.near,this.far)}},Mi=class r{isFogExp2=!0;name;color;density;constructor(e,t=25e-5){this.name="",this.color=new Pe(e),this.density=t}clone(){return new r(this.color,this.density)}};var yl=0,ht=class extends Tt{isMaterial=!0;uuid;name;type;blending;side;vertexColors;opacity;transparent;alphaHash;blendSrc;blendDst;blendEquation;blendSrcAlpha;blendDstAlpha;blendEquationAlpha;blendColor;blendAlpha;depthFunc;depthTest;depthWrite;stencilWriteMask;stencilFunc;stencilRef;stencilFuncMask;stencilFail;stencilZFail;stencilZPass;stencilWrite;clippingPlanes;clipIntersection;clipShadows;shadowSide;colorWrite;precision;polygonOffset;polygonOffsetFactor;polygonOffsetUnits;dithering;alphaToCoverage;premultipliedAlpha;forceSinglePass;allowOverride;visible;toneMapped;userData;version;_alphaTest;constructor(){super(),Object.defineProperty(this,"id",{value:yl++}),this.uuid=yt(),this.name="",this.type="Material",this.blending="normal",this.side="front",this.vertexColors=!1,this.opacity=1,this.transparent=!1,this.alphaHash=!1,this.blendSrc="src-alpha",this.blendDst="one-minus-src-alpha",this.blendEquation="add",this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.blendColor=new Pe(0,0,0),this.blendAlpha=0,this.depthFunc="less-equal",this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc="always",this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail="keep",this.stencilZFail="keep",this.stencilZPass="keep",this.stencilWrite=!1,this.clippingPlanes=null,this.clipIntersection=!1,this.clipShadows=!1,this.shadowSide=null,this.colorWrite=!0,this.precision=null,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.dithering=!1,this.alphaToCoverage=!1,this.premultipliedAlpha=!1,this.forceSinglePass=!1,this.allowOverride=!0,this.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(e){this._alphaTest>0!=e>0&&this.version++,this._alphaTest=e}onBeforeRender(e,t,n,i,o,a){}onCompile(e,t){}customProgramCacheKey(){return this.onCompile.toString()}setValues(e){if(e===void 0)return;let t=this;for(let n in e){let i=e[n];if(i===void 0){console.warn("keel/lit Material: parameter '".concat(n,"' has value of undefined."));continue}let o=t[n];if(o===void 0){console.warn("keel/lit Material: '".concat(n,"' is not a property of ").concat(this.type,"."));continue}o&&o.isColor?o.set(i):o&&o.isVector3&&i&&i.isVector3?o.copy(i):t[n]=i}}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;let t=e.clippingPlanes,n=null;if(t!==null){let i=t.length;n=new Array(i);for(let o=0;o!==i;++o)n[o]=t[o].clone()}return this.clippingPlanes=n,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}};var rn=class extends ht{isMeshBasicMaterial=!0;isFlatMaterial=!0;color;map;lightMap;lightMapIntensity;aoMap;aoMapIntensity;specularMap;alphaMap;envMap;envMapRotation;combine;reflectivity;refractionRatio;wireframe;wireframeLinewidth;wireframeLinecap;wireframeLinejoin;fog;constructor(e){super(),this.type="FlatMaterial",this.color=new Pe(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new vt,this.combine="multiply",this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}};var Si=new L,Pn=new L,qt=class extends nt{isMesh=!0;geometry;material;morphTargetDictionary;morphTargetInfluences;count;constructor(e=new Dt,t=new rn){super(),this.type="Mesh",this.geometry=e,this.material=t,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.count=1,this.updateMorphTargets()}copy(e,t){return super.copy(e,t),e.morphTargetInfluences!==void 0&&(this.morphTargetInfluences=e.morphTargetInfluences.slice()),e.morphTargetDictionary!==void 0&&(this.morphTargetDictionary=Object.assign({},e.morphTargetDictionary)),this.material=Array.isArray(e.material)?e.material.slice():e.material,this.geometry=e.geometry,this}updateMorphTargets(){let t=this.geometry.morphAttributes,n=Object.keys(t);if(n.length>0){let i=t[n[0]];if(i!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let o=0,a=i.length;o<a;o++){let s=i[o].name||String(o);this.morphTargetInfluences.push(0),this.morphTargetDictionary[s]=o}}}}getVertexPosition(e,t){let n=this.geometry,i=n.attributes.position,o=n.morphAttributes.position,a=n.morphTargetsRelative;t.fromBufferAttribute(i,e);let s=this.morphTargetInfluences;if(o&&s){Pn.set(0,0,0);for(let l=0,c=o.length;l<c;l++){let d=s[l],u=o[l];d!==0&&(Si.fromBufferAttribute(u,e),a?Pn.addScaledVector(Si,d):Pn.addScaledVector(Si.sub(t),d))}t.add(Pn)}return t}};var Ml=0,Yt=class{isSource=!0;uuid;data;dataReady;version;constructor(e=null){Object.defineProperty(this,"id",{value:Ml++}),this.uuid=yt(),this.data=e,this.dataReady=!0,this.version=0}getSize(e){let t=this.data;return typeof HTMLVideoElement<"u"&&t instanceof HTMLVideoElement?e.set(t.videoWidth,t.videoHeight,0):typeof VideoFrame<"u"&&t instanceof VideoFrame?e.set(t.displayHeight,t.displayWidth,0):t!==null?e.set(t.width,t.height,t.depth||0):e.set(0,0,0),e}set needsUpdate(e){e===!0&&this.version++}};var Sl=0,_i=new L,dt=class r extends Tt{static DEFAULT_IMAGE=null;static DEFAULT_MAPPING="uv";static DEFAULT_ANISOTROPY=1;isTexture=!0;uuid;name;source;mipmaps;mapping;channel;wrapS;wrapT;magFilter;minFilter;anisotropy;format;internalFormat;type;offset;repeat;center;rotation;matrixAutoUpdate;matrix;generateMipmaps;premultiplyAlpha;flipY;unpackAlignment;colorSpace;userData;updateRanges;version;onUpdate;renderTarget;isRenderTargetTexture;isArrayTexture;pmremVersion;constructor(e=r.DEFAULT_IMAGE,t=r.DEFAULT_MAPPING,n="clamp",i="clamp",o="linear",a="linear-mipmap-linear",s="rgba",l="u8",c=r.DEFAULT_ANISOTROPY,d=""){super(),Object.defineProperty(this,"id",{value:Sl++}),this.uuid=yt(),this.name="",this.source=new Yt(e),this.mipmaps=[],this.mapping=t,this.channel=0,this.wrapS=n,this.wrapT=i,this.magFilter=o,this.minFilter=a,this.anisotropy=c,this.format=s,this.internalFormat=null,this.type=l,this.offset=new W(0,0),this.repeat=new W(1,1),this.center=new W(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new rt,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.colorSpace=d,this.userData={},this.updateRanges=[],this.version=0,this.onUpdate=null,this.renderTarget=null,this.isRenderTargetTexture=!1;let u=e;this.isArrayTexture=!!(u&&u.depth&&u.depth>1),this.pmremVersion=0}get width(){return this.source.getSize(_i).x}get height(){return this.source.getSize(_i).y}get depth(){return this.source.getSize(_i).z}get image(){return this.source.data}set image(e){this.source.data=e===void 0?null:e}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return new this.constructor().copy(this)}copy(e){return this.name=e.name,this.source=e.source,this.mipmaps=e.mipmaps.slice(0),this.mapping=e.mapping,this.channel=e.channel,this.wrapS=e.wrapS,this.wrapT=e.wrapT,this.magFilter=e.magFilter,this.minFilter=e.minFilter,this.anisotropy=e.anisotropy,this.format=e.format,this.internalFormat=e.internalFormat,this.type=e.type,this.offset.copy(e.offset),this.repeat.copy(e.repeat),this.center.copy(e.center),this.rotation=e.rotation,this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrix.copy(e.matrix),this.generateMipmaps=e.generateMipmaps,this.premultiplyAlpha=e.premultiplyAlpha,this.flipY=e.flipY,this.unpackAlignment=e.unpackAlignment,this.colorSpace=e.colorSpace,this.renderTarget=e.renderTarget,this.isRenderTargetTexture=e.isRenderTargetTexture,this.isArrayTexture=e.isArrayTexture,this.userData=JSON.parse(JSON.stringify(e.userData)),this.needsUpdate=!0,this}setValues(e){let t=this;for(let n in e){let i=e[n];if(i===void 0){console.warn("keel/lit Texture.setValues(): parameter '".concat(n,"' has value of undefined."));continue}let o=t[n];if(o===void 0){console.warn("keel/lit Texture.setValues(): property '".concat(n,"' does not exist."));continue}o&&i&&o.isVector2&&i.isVector2||o&&i&&o.isVector3&&i.isVector3||o&&i&&o.isMatrix3&&i.isMatrix3?o.copy(i):t[n]=i}}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!=="uv")return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case"repeat":e.x=e.x-Math.floor(e.x);break;case"clamp":e.x=e.x<0?0:1;break;case"mirror":Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case"repeat":e.y=e.y-Math.floor(e.y);break;case"clamp":e.y=e.y<0?0:1;break;case"mirror":Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(e){e===!0&&this.pmremVersion++}};var nn=class extends dt{isDataTexture=!0;constructor(e=null,t=1,n=1,i,o,a,s,l,c="nearest",d="nearest",u,h){super(null,a,s,l,c,d,i,o,u,h),this.image={data:e,width:t,height:n},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}get image(){return this.source.data}set image(e){this.source.data=e===void 0?null:e}};var Un=new Ve,wo=new St,_l=new Ve,Co=new Ot,Ti=class extends qt{isInstancedMesh=!0;isInstances=!0;instanceMatrix;instanceColor;morphTexture;boundingBox;boundingSphere;constructor(e,t,n){super(e,t),this.type="Instances",this.instanceMatrix=new Rr(new Float32Array(n*16),16),this.instanceColor=null,this.morphTexture=null,this.count=n,this.boundingBox=null,this.boundingSphere=null;for(let i=0;i<n;i++)this.setMatrixAt(i,_l)}computeBoundingBox(){let e=this.geometry,t=this.count;this.boundingBox===null&&(this.boundingBox=new St),e.boundingBox===null&&e.computeBoundingBox(),this.boundingBox.makeEmpty();for(let n=0;n<t;n++)this.getMatrixAt(n,Un),wo.copy(e.boundingBox).applyMatrix4(Un),this.boundingBox.union(wo)}computeBoundingSphere(){let e=this.geometry,t=this.count;this.boundingSphere===null&&(this.boundingSphere=new Ot),e.boundingSphere===null&&e.computeBoundingSphere(),this.boundingSphere.makeEmpty();for(let n=0;n<t;n++)this.getMatrixAt(n,Un),Co.copy(e.boundingSphere).applyMatrix4(Un),this.boundingSphere.union(Co)}copy(e,t){return super.copy(e,t),this.instanceMatrix.copy(e.instanceMatrix),e.morphTexture!==null&&(this.morphTexture=e.morphTexture.clone()),e.instanceColor!==null&&(this.instanceColor=e.instanceColor.clone()),this.count=e.count,e.boundingBox!==null&&(this.boundingBox=e.boundingBox.clone()),e.boundingSphere!==null&&(this.boundingSphere=e.boundingSphere.clone()),this}getColorAt(e,t){t.fromArray(this.instanceColor.array,e*3)}getMatrixAt(e,t){t.fromArray(this.instanceMatrix.array,e*16)}getMorphAt(e,t){let n=t.morphTargetInfluences,i=this.morphTexture.source.data.data,o=n.length+1,a=e*o+1;for(let s=0;s<n.length;s++)n[s]=i[a+s]}setColorAt(e,t){this.instanceColor===null&&(this.instanceColor=new Rr(new Float32Array(this.instanceMatrix.count*3).fill(1),3)),t.toArray(this.instanceColor.array,e*3)}setMatrixAt(e,t){t.toArray(this.instanceMatrix.array,e*16)}setMorphAt(e,t){let n=t.morphTargetInfluences,i=n.length+1;this.morphTexture===null&&(this.morphTexture=new nn(new Float32Array(i*this.count),i,this.count,"red","float"));let o=this.morphTexture.source.data.data,a=0;for(let c=0;c<n.length;c++)a+=n[c];let s=this.geometry.morphTargetsRelative?1:1-a,l=i*e;o[l]=s,o.set(n,l+1)}updateMorphTargets(){}dispose(){this.dispatchEvent({type:"dispose"}),this.morphTexture!==null&&(this.morphTexture.dispose(),this.morphTexture=null)}};var on=class extends ht{isSpriteMaterial=!0;isBillboardMaterial=!0;color;map;alphaMap;rotation;sizeAttenuation;fog;constructor(e){super(),this.type="BillboardMaterial",this.color=new Pe(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.alphaMap=e.alphaMap,this.rotation=e.rotation,this.sizeAttenuation=e.sizeAttenuation,this.fog=e.fog,this}};var Fr,Ai=class extends nt{isSprite=!0;isBillboard=!0;geometry;material;center;count;constructor(e=new on){if(super(),this.type="Billboard",Fr===void 0){Fr=new Dt;let t=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),n=new Float32Array([0,0,1,0,1,1,0,1]);Fr.setIndex([0,1,2,0,2,3]),Fr.setAttribute("position",new de(t,3,!1)),Fr.setAttribute("uv",new de(n,2,!1))}this.geometry=Fr,this.material=e,this.center=new W(.5,.5),this.count=1}copy(e,t){return super.copy(e,t),e.center!==void 0&&this.center.copy(e.center),this.material=e.material,this}};var br=class extends nt{isCamera=!0;matrixWorldInverse;projectionMatrix;projectionMatrixInverse;coordinateSystem;_reversedDepth;constructor(){super(),this.type="Camera",this.matrixWorldInverse=new Ve,this.projectionMatrix=new Ve,this.projectionMatrixInverse=new Ve,this.coordinateSystem="webgl",this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}};var or=new L,Lo=new W,Ro=new W,Ei=class extends br{isPerspectiveCamera=!0;fov;zoom;near;far;focus;aspect;view;filmGauge;filmOffset;constructor(e=50,t=1,n=.1,i=2e3){super(),this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=n,this.far=i,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){let t=.5*this.getFilmHeight()/e;this.fov=kr*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){let e=Math.tan(Tr*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return kr*2*Math.atan(Math.tan(Tr*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(e,t,n){or.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),t.set(or.x,or.y).multiplyScalar(-e/or.z),or.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(or.x,or.y).multiplyScalar(-e/or.z)}getViewSize(e,t){return this.getViewBounds(e,Lo,Ro),t.subVectors(Ro,Lo)}setViewOffset(e,t,n,i,o,a){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=i,this.view.width=o,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=this.near,t=e*Math.tan(Tr*.5*this.fov)/this.zoom,n=2*t,i=this.aspect*n,o=-.5*i,a=this.view;if(this.view!==null&&this.view.enabled){let l=a.fullWidth,c=a.fullHeight;o+=a.offsetX*i/l,t-=a.offsetY*n/c,i*=a.width/l,n*=a.height/c}let s=this.filmOffset;s!==0&&(o+=e*s/this.getFilmWidth()),this.projectionMatrix.makePerspective(o,o+i,t,t-n,e,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}};var xr=class extends br{isOrthographicCamera=!0;isOrthoCamera=!0;zoom;view;left;right;top;bottom;near;far;constructor(e=-1,t=1,n=1,i=-1,o=.1,a=2e3){super(),this.type="OrthoCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=n,this.bottom=i,this.near=o,this.far=a,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,n,i,o,a){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=n,this.view.offsetY=i,this.view.width=o,this.view.height=a,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){let e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,i=(this.top+this.bottom)/2,o=n-e,a=n+e,s=i+t,l=i-t;if(this.view!==null&&this.view.enabled){let c=(this.right-this.left)/this.view.fullWidth/this.zoom,d=(this.top-this.bottom)/this.view.fullHeight/this.zoom;o+=c*this.view.offsetX,a=o+c*this.view.width,s-=d*this.view.offsetY,l=s-d*this.view.height}this.projectionMatrix.makeOrthographic(o,a,s,l,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}};var vr=class extends nt{isLight=!0;color;intensity;constructor(e,t=1){super(),this.type="Light",this.color=new Pe(e),this.intensity=t}dispose(){}copy(e,t){return super.copy(e,t),this.color.copy(e.color),this.intensity=e.intensity,this}},wi=class extends vr{isAmbientLight=!0;constructor(e,t){super(e,t),this.type="AmbientLight"}},Ci=class extends vr{isHemisphereLight=!0;isSkyLight=!0;groundColor;constructor(e,t,n){super(e,n),this.type="SkyLight",this.position.copy(nt.DEFAULT_UP),this.updateMatrix(),this.groundColor=new Pe(t)}copy(e,t){return super.copy(e,t),this.groundColor.copy(e.groundColor),this}};var Li=new Ve,Po=new L,Uo=new L,In=class{camera;intensity;bias;normalBias;radius;blurSamples;mapSize;mapType;map;mapPass;matrix;autoUpdate;needsUpdate;_frustum;_frameExtents;_viewportCount;_viewports;constructor(e){this.camera=e,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new W(512,512),this.mapType="u8",this.map=null,this.mapPass=null,this.matrix=new Ve,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Ht,this._frameExtents=new W(1,1),this._viewportCount=1,this._viewports=[new Ze(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(e){let t=this.camera,n=this.matrix;Po.setFromMatrixPosition(e.matrixWorld),t.position.copy(Po),Uo.setFromMatrixPosition(e.target.matrixWorld),t.lookAt(Uo),t.updateMatrixWorld(),Li.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Li,t.coordinateSystem,t.reversedDepth),t.reversedDepth?n.set(.5,0,0,.5,0,.5,0,.5,0,0,1,0,0,0,0,1):n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(Li)}getViewport(e){return this._viewports[e]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(e){return this.camera=e.camera.clone(),this.intensity=e.intensity,this.bias=e.bias,this.radius=e.radius,this.autoUpdate=e.autoUpdate,this.needsUpdate=e.needsUpdate,this.normalBias=e.normalBias,this.blurSamples=e.blurSamples,this.mapSize.copy(e.mapSize),this}clone(){return new this.constructor().copy(this)}},an=class extends In{isDirectionalLightShadow=!0;isSunShadow=!0;constructor(){super(new xr(-5,5,5,-5,.5,500))}};var Ri=class extends vr{isDirectionalLight=!0;isSunLight=!0;target;shadow;constructor(e,t){super(e,t),this.type="SunLight",this.position.copy(nt.DEFAULT_UP),this.updateMatrix(),this.target=new nt,this.shadow=new an}dispose(){this.shadow.dispose()}copy(e){return super.copy(e),this.target=e.target.clone(),this.shadow=e.shadow.clone(),this}};var Pi=class extends ht{isMeshStandardMaterial=!0;isLitMaterial=!0;defines;color;roughness;metalness;map;lightMap;lightMapIntensity;aoMap;aoMapIntensity;emissive;emissiveIntensity;emissiveMap;bumpMap;bumpScale;normalMap;normalMapType;normalScale;displacementMap;displacementScale;displacementBias;roughnessMap;metalnessMap;alphaMap;envMap;envMapRotation;envMapIntensity;wireframe;wireframeLinewidth;wireframeLinecap;wireframeLinejoin;flatShading;fog;constructor(e){super(),this.type="LitMaterial",this.defines={STANDARD:""},this.color=new Pe(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Pe(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType="tangent",this.normalScale=new W(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new vt,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:""},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapRotation.copy(e.envMapRotation),this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}};var Ui=class extends ht{isMeshToonMaterial=!0;isToonMaterial=!0;defines;color;map;gradientMap;lightMap;lightMapIntensity;aoMap;aoMapIntensity;emissive;emissiveIntensity;emissiveMap;bumpMap;bumpScale;normalMap;normalMapType;normalScale;displacementMap;displacementScale;displacementBias;alphaMap;wireframe;wireframeLinewidth;wireframeLinecap;wireframeLinejoin;fog;constructor(e){super(),this.defines={TOON:""},this.type="ToonMaterial",this.color=new Pe(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Pe(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType="tangent",this.normalScale=new W(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(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.gradientMap=e.gradientMap,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.alphaMap=e.alphaMap,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}};var sn=r=>Object.freeze({kind:"color",value:r}),Ii=(r,e)=>Object.freeze({kind:"vec2",value:Object.freeze([r,e])}),Tl=(r,e,t)=>Object.freeze({kind:"vec3",value:Object.freeze([r,e,t])}),mt=Object.freeze({kind:"mat3"}),Al=Object.freeze({kind:"mat4"}),Ft=Object.freeze({kind:"list"}),Io=Object.freeze({color:sn,vec2:Ii,vec3:Tl,mat3:mt,mat4:Al,list:Ft}),ne=r=>({value:r}),ar=r=>({value:Ft,properties:Object.freeze(r)});function xt(r){for(let e in r)Object.freeze(r[e]);return Object.freeze(r)}var Ce=Object.freeze({common:xt({diffuse:ne(sn(16777215)),opacity:ne(1),map:ne(null),mapTransform:ne(mt),alphaMap:ne(null),alphaMapTransform:ne(mt),alphaTest:ne(0)}),specularmap:xt({specularMap:ne(null),specularMapTransform:ne(mt)}),envmap:xt({envMap:ne(null),envMapRotation:ne(mt),flipEnvMap:ne(-1),reflectivity:ne(1),ior:ne(1.5),refractionRatio:ne(.98)}),aomap:xt({aoMap:ne(null),aoMapIntensity:ne(1),aoMapTransform:ne(mt)}),lightmap:xt({lightMap:ne(null),lightMapIntensity:ne(1),lightMapTransform:ne(mt)}),bumpmap:xt({bumpMap:ne(null),bumpMapTransform:ne(mt),bumpScale:ne(1)}),normalmap:xt({normalMap:ne(null),normalMapTransform:ne(mt),normalScale:ne(Ii(1,1))}),displacementmap:xt({displacementMap:ne(null),displacementMapTransform:ne(mt),displacementScale:ne(1),displacementBias:ne(0)}),emissivemap:xt({emissiveMap:ne(null),emissiveMapTransform:ne(mt)}),metalnessmap:xt({metalnessMap:ne(null),metalnessMapTransform:ne(mt)}),roughnessmap:xt({roughnessMap:ne(null),roughnessMapTransform:ne(mt)}),gradientmap:xt({gradientMap:ne(null)}),fog:xt({fogDensity:ne(25e-5),fogNear:ne(1),fogFar:ne(2e3),fogColor:ne(sn(16777215))}),lights:xt({ambientLightColor:ne(Ft),lightProbe:ne(Ft),directionalLights:ar({direction:{},color:{}}),directionalLightShadows:ar({shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}),directionalShadowMap:ne(Ft),directionalShadowMatrix:ne(Ft),spotLights:ar({color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}),spotLightShadows:ar({shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}),spotLightMap:ne(Ft),spotShadowMap:ne(Ft),spotLightMatrix:ne(Ft),pointLights:ar({color:{},position:{},decay:{},distance:{}}),pointLightShadows:ar({shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}),pointShadowMap:ne(Ft),pointShadowMatrix:ne(Ft),hemisphereLights:ar({direction:{},skyColor:{},groundColor:{}}),rectAreaLights:ar({color:{},position:{},width:{},height:{}}),ltc_1:ne(null),ltc_2:ne(null)}),points:xt({diffuse:ne(sn(16777215)),opacity:ne(1),size:ne(1),scale:ne(1),map:ne(null),alphaMap:ne(null),alphaMapTransform:ne(mt),alphaTest:ne(0),uvTransform:ne(mt)}),sprite:xt({diffuse:ne(sn(16777215)),opacity:ne(1),center:ne(Ii(.5,.5)),rotation:ne(0),map:ne(null),mapTransform:ne(mt),alphaMap:ne(null),alphaMapTransform:ne(mt),alphaTest:ne(0)})});function El(r){if(!r||typeof r!="object")return!1;let e=r;return!!(e.isColor||e.isMatrix3||e.isMatrix4||e.isVector2||e.isVector3||e.isVector4||e.isTexture||e.isQuaternion)}function Dn(r){let e={};for(let t in r){let n=r[t],i={};e[t]=i;for(let o in n){let a=n[o];El(a)?a.isRenderTargetTexture?(console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."),i[o]=null):i[o]=a.clone():Array.isArray(a)?i[o]=a.slice():i[o]=a}}return e}function jt(r){let e={};for(let t of r){let n=Dn(t);for(let i in n)e[i]=n[i]}return e}function Do(r){let e=[];for(let t of r)e.push(t.clone());return e}var Mg=Object.freeze({clone:Dn,merge:jt});function Fo(r,e){let t={};for(let n in r){let i=r[n],o=i.value,a;if(o===null||typeof o=="number")a=o;else switch(o.kind){case"color":a=e.color(o.value);break;case"vec2":a=e.vec2(o.value[0],o.value[1]);break;case"vec3":a=e.vec3(o.value[0],o.value[1],o.value[2]);break;case"mat3":a=e.mat3();break;case"mat4":a=e.mat4();break;case"list":a=[];break}let s={value:a};i.properties!==void 0&&(s.properties=i.properties),t[n]=s}return t}var wl="\nvoid main() {\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}\n",Cl="\nvoid main() {\n gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}\n",yr=class extends ht{isShaderMaterial=!0;isCustomMaterial=!0;defines;uniforms;uniformsGroups;vertexShader;fragmentShader;linewidth;wireframe;wireframeLinewidth;fog;lights;clipping;extensions;defaultAttributeValues;index0AttributeName;uniformsNeedUpdate;glslVersion;constructor(e){super(),this.type="CustomMaterial",this.defines={},this.uniforms={},this.uniformsGroups=[],this.vertexShader=wl,this.fragmentShader=Cl,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.forceSinglePass=!0,this.extensions={clipCullDistance:!1,multiDraw:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv1:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,e!==void 0&&this.setValues(e)}copy(e){return super.copy(e),this.fragmentShader=e.fragmentShader,this.vertexShader=e.vertexShader,this.uniforms=Dn(e.uniforms),this.uniformsGroups=Do(e.uniformsGroups),this.defines=Object.assign({},e.defines),this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.fog=e.fog,this.lights=e.lights,this.clipping=e.clipping,this.extensions=Object.assign({},e.extensions),this.glslVersion=e.glslVersion,this}};var ln=class extends ht{isMeshDepthMaterial=!0;isDepthMaterial=!0;depthPacking;map;alphaMap;displacementMap;displacementScale;displacementBias;wireframe;wireframeLinewidth;constructor(e){super(),this.type="DepthMaterial",this.depthPacking="basic",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}};var un=class extends ht{isMeshDistanceMaterial=!0;isDistanceMaterial=!0;map;alphaMap;displacementMap;displacementScale;displacementBias;constructor(e){super(),this.type="DistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}};var Di=class extends dt{isCanvasTexture=!0;constructor(e,t,n,i,o,a,s,l,c){super(e,t,n,i,o,a,s,l,c),this.needsUpdate=!0}};var cn=class extends dt{isDepthTexture=!0;compareFunction;constructor(e,t,n="uint",i,o,a,s="nearest",l="nearest",c,d="depth",u=1){if(d!=="depth"&&d!=="depth-stencil")throw new Error('keel/lit DepthTexture: format must be "depth" or "depth-stencil"');let h={width:e,height:t,depth:u};super(h,i,o,a,s,l,d,n,c),this.flipY=!1,this.generateMipmaps=!1,this.compareFunction=null}copy(e){return super.copy(e),this.source=new Yt(Object.assign({},e.image)),this.compareFunction=e.compareFunction,this}};var Mr=class extends Tt{isRenderTarget=!0;width;height;depth;scissor;scissorTest;viewport;textures;depthBuffer;stencilBuffer;resolveDepthBuffer;resolveStencilBuffer;_depthTexture;samples;multiview;isWebGLRenderTarget=!0;constructor(e=1,t=1,n={}){super();let i=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:"linear",depthBuffer:!0,stencilBuffer:!1,resolveDepthBuffer:!0,resolveStencilBuffer:!0,depthTexture:null,samples:0,count:1,depth:1,multiview:!1},n);this.width=e,this.height=t,this.depth=i.depth,this.scissor=new Ze(0,0,e,t),this.scissorTest=!1,this.viewport=new Ze(0,0,e,t);let o={width:e,height:t,depth:i.depth},a=new dt(o);this.textures=[];let s=i.count;for(let l=0;l<s;l++){let c=a.clone();this.textures[l]=c,c.isRenderTargetTexture=!0,c.renderTarget=this}this._setTextureOptions(i),this.depthBuffer=i.depthBuffer,this.stencilBuffer=i.stencilBuffer,this.resolveDepthBuffer=i.resolveDepthBuffer,this.resolveStencilBuffer=i.resolveStencilBuffer,this._depthTexture=null,this.depthTexture=i.depthTexture,this.samples=i.samples,this.multiview=i.multiview}_setTextureOptions(e={}){let t={minFilter:"linear",generateMipmaps:!1,flipY:!1,internalFormat:null};e.mapping!==void 0&&(t.mapping=e.mapping),e.wrapS!==void 0&&(t.wrapS=e.wrapS),e.wrapT!==void 0&&(t.wrapT=e.wrapT),e.wrapR!==void 0&&(t.wrapR=e.wrapR),e.magFilter!==void 0&&(t.magFilter=e.magFilter),e.minFilter!==void 0&&(t.minFilter=e.minFilter),e.format!==void 0&&(t.format=e.format),e.type!==void 0&&(t.type=e.type),e.anisotropy!==void 0&&(t.anisotropy=e.anisotropy),e.colorSpace!==void 0&&(t.colorSpace=e.colorSpace),e.flipY!==void 0&&(t.flipY=e.flipY),e.generateMipmaps!==void 0&&(t.generateMipmaps=e.generateMipmaps),e.internalFormat!==void 0&&(t.internalFormat=e.internalFormat);for(let n=0;n<this.textures.length;n++)this.textures[n].setValues(t)}get texture(){return this.textures[0]}set texture(e){this.textures[0]=e}set depthTexture(e){this._depthTexture!==null&&(this._depthTexture.renderTarget=null),e!==null&&(e.renderTarget=this),this._depthTexture=e}get depthTexture(){return this._depthTexture}setSize(e,t,n=1){if(this.width!==e||this.height!==t||this.depth!==n){this.width=e,this.height=t,this.depth=n;for(let i=0,o=this.textures.length;i<o;i++){let a=this.textures[i],s=a.image;s.width=e,s.height=t,s.depth=n,a.isArrayTexture=s.depth>1}this.dispose()}this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.textures.length=0;for(let t=0,n=e.textures.length;t<n;t++){let i=e.textures[t].clone();this.textures[t]=i,i.isRenderTargetTexture=!0,i.renderTarget=this;let o=Object.assign({},e.textures[t].image);i.source=new Yt(o)}return this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,this.resolveDepthBuffer=e.resolveDepthBuffer,this.resolveStencilBuffer=e.resolveStencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}};var Fn=(r,e)=>[r[1]*e[2]-r[2]*e[1],r[2]*e[0]-r[0]*e[2],r[0]*e[1]-r[1]*e[0]];function dn(r){let e=Math.hypot(r[0],r[1],r[2])||1;return[r[0]/e,r[1]/e,r[2]/e]}var Nn={sky:[.06,.06,.068],horizon:[.12,.115,.12],ground:[.02,.019,.021],boxes:[{dir:[-.55,.5,.68],size:[.62,.46],colour:[1,.97,.93],intensity:4.2,soft:.35},{dir:[.08,.22,1],size:[.95,.42],colour:[1,.99,.97],intensity:1.55,soft:.5},{dir:[.95,.12,.28],size:[.08,.9],colour:[.94,.97,1],intensity:5.5,soft:.3,roll:.05},{dir:[-.97,.05,-.1],size:[.06,.85],colour:[1,.96,.92],intensity:3.2,soft:.3},{dir:[.05,1,.12],size:[.8,.36],colour:[1,1,1],intensity:2,soft:.4},{dir:[.2,-.45,.85],size:[.7,.18],colour:[1,.98,.95],intensity:.45,soft:.5}]};function No(r){let e=dn(r.dir),t=Math.abs(e[1])>.95?[0,0,1]:[0,1,0],n=dn(Fn(t,e)),i=dn(Fn(e,n)),o=r.roll??0;if(o){let a=Math.cos(o),s=Math.sin(o),l=[n[0]*a+i[0]*s,n[1]*a+i[1]*s,n[2]*a+i[2]*s];i=dn(Fn(e,l)),n=l}return{c:e,r:n,u:i}}function Fi(r){let e=i=>Number.isInteger(i)?i.toFixed(1):String(+i.toPrecision(7)),t=i=>"vec3(".concat(e(i[0]),", ").concat(e(i[1]),", ").concat(e(i[2]),")"),n=r.boxes.map(i=>{let o=No(i),a=Math.max(.001,i.soft??.2);return" c += softBox(d, ".concat(t(o.c),", ").concat(t(o.r),", ").concat(t(o.u),", vec2(").concat(e(i.size[0]),", ").concat(e(i.size[1]),"), ").concat(e(a),") * ").concat(t([i.colour[0]*i.intensity,i.colour[1]*i.intensity,i.colour[2]*i.intensity]),";")});return"\nfloat softBox(vec3 d, vec3 c, vec3 r, vec3 u, vec2 size, float soft) {\n float cz = dot(d, c);\n if (cz <= 0.01) return 0.0;\n float x = abs(dot(d, r) / cz), y = abs(dot(d, u) / cz);\n float mx = 1.0 - smoothstep(size.x * (1.0 - soft), size.x * (1.0 + soft * 0.5), x);\n float my = 1.0 - smoothstep(size.y * (1.0 - soft), size.y * (1.0 + soft * 0.5), y);\n return mx * my;\n}\nvec3 studio(vec3 d) {\n d = normalize(d);\n float up = smoothstep(0.0, 1.0, d.y), down = smoothstep(0.0, -0.6, d.y);\n vec3 c = ".concat(t(r.horizon)," * (1.0 - up - down) + ").concat(t(r.sky)," * up + ").concat(t(r.ground)," * down;\n").concat(n.join("\n"),"\n return c;\n}\n")}var Vn=[1,.8,.4,.305,.21],On=[-2,-1,2,3,4],kn=4,Vo=16,Oo=6;function Ll(r){for(let e=1;e<Vn.length;e++)if(r<=On[e])return Vn[e-1]-(r-On[e-1])*(Vn[e-1]-Vn[e])/(On[e]-On[e-1]);return Math.pow(2,-r/2)/1.16}function Rl(r){return 3*Math.max(r,Vo*(Oo+1))}function Vi(r){let e=Math.log2(r);if(!Number.isInteger(e)||e<kn)throw new Error("keel/lit Environment: size must be a power of two, 16 or more, not ".concat(r));let t=[];for(let n=e;n>=kn-Oo;n--){let i=2**Math.max(n,kn),o=Math.max(kn-n,0);t.push({x:o*3*Vo,y:4*(r-i),size:i,mip:n,roughness:n===e?0:Ll(n)})}return t}var Ni=class extends dt{isEnvironment=!0;studio;samples;constructor(e=Nn,t={}){let n=t.size??128;Vi(n),super({width:Rl(n),height:4*n},"cube-uv-reflection","clamp","clamp","linear","linear"),this.studio=e,this.samples=t.samples??384,this.generateMipmaps=!1,this.flipY=!1}get size(){return this.height/4}copy(e){return super.copy(e),this.studio=e.studio,this.samples=e.samples,this}};function ko(){let r=null,e=!1,t=null,n=null;function i(o,a){t(o,a),n=r.requestAnimationFrame(i)}return{start:function(){e!==!0&&t!==null&&(n=r.requestAnimationFrame(i),e=!0)},stop:function(){r.cancelAnimationFrame(n),e=!1},setAnimationLoop:function(o){t=o},setContext:function(o){r=o}}}function zo(r){let e=new WeakMap;function t(s,l){let c=s.array,d=s.usage,u=c.byteLength,h=r.createBuffer();r.bindBuffer(l,h),r.bufferData(l,c,ri[d]),s.onUploadCallback();let m;if(c instanceof Float32Array)m=r.FLOAT;else if(c instanceof Uint16Array)m=r.UNSIGNED_SHORT;else if(c instanceof Int16Array)m=r.SHORT;else if(c instanceof Uint32Array)m=r.UNSIGNED_INT;else if(c instanceof Int32Array)m=r.INT;else if(c instanceof Int8Array)m=r.BYTE;else if(c instanceof Uint8Array)m=r.UNSIGNED_BYTE;else if(c instanceof Uint8ClampedArray)m=r.UNSIGNED_BYTE;else throw new Error("keel/lit Attributes: Unsupported buffer data format: "+String(c));return{buffer:h,type:m,bytesPerElement:c.BYTES_PER_ELEMENT,version:s.version,size:u}}function n(s,l,c){let d=l.array,u=l.updateRanges;if(r.bindBuffer(c,s),u.length===0)r.bufferSubData(c,0,d);else{u.sort((m,f)=>m.start-f.start);let h=0;for(let m=1;m<u.length;m++){let f=u[h],g=u[m];g.start<=f.start+f.count+1?f.count=Math.max(f.count,g.start+g.count-f.start):(++h,u[h]=g)}u.length=h+1;for(let m=0,f=u.length;m<f;m++){let g=u[m];r.bufferSubData(c,g.start*d.BYTES_PER_ELEMENT,d,g.start,g.count)}l.clearUpdateRanges()}l.onUploadCallback()}function i(s){return e.get(s)}function o(s){let l=e.get(s);l&&(r.deleteBuffer(l.buffer),e.delete(s))}function a(s,l){let c=e.get(s);if(c===void 0)e.set(s,t(s,l));else if(c.version<s.version){if(c.size!==s.array.byteLength)throw new Error("keel/lit Attributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.");n(c.buffer,s,l),c.version=s.version}}return{get:i,remove:o,update:a}}var Sr=new vt,Pl=new Ve;function Oi(r){let e=r.getRenderTarget();return e===null?r.outputColorSpace:e.isXRRenderTarget===!0?e.texture.colorSpace:Ne.workingColorSpace}function Bo(r,e){function t(d,u){d.matrixAutoUpdate===!0&&d.updateMatrix(),u.value.copy(d.matrix)}function n(d,u){u.color.getRGB(d.fogColor.value,Oi(r)),u.isFog?(d.fogNear.value=u.near,d.fogFar.value=u.far):u.isFogExp2&&(d.fogDensity.value=u.density)}function i(d,u,h,m,f){let g=u;g.isMeshBasicMaterial?o(d,g):g.isMeshToonMaterial?(o(d,g),s(d,g)):g.isMeshStandardMaterial?(o(d,g),l(d,g)):g.isMeshDepthMaterial?o(d,g):g.isMeshDistanceMaterial?(o(d,g),c(d,g)):g.isSpriteMaterial?a(d,g):g.isShaderMaterial&&(g.uniformsNeedUpdate=!1)}function o(d,u){let h=d;h.opacity.value=u.opacity,u.color&&h.diffuse.value.copy(u.color),u.emissive&&h.emissive.value.copy(u.emissive).multiplyScalar(u.emissiveIntensity),u.map&&(h.map.value=u.map,t(u.map,h.mapTransform)),u.alphaMap&&(h.alphaMap.value=u.alphaMap,t(u.alphaMap,h.alphaMapTransform)),u.bumpMap&&(h.bumpMap.value=u.bumpMap,t(u.bumpMap,h.bumpMapTransform),h.bumpScale.value=u.bumpScale,u.side==="back"&&(h.bumpScale.value*=-1)),u.normalMap&&(h.normalMap.value=u.normalMap,t(u.normalMap,h.normalMapTransform),h.normalScale.value.copy(u.normalScale),u.side==="back"&&h.normalScale.value.negate()),u.displacementMap&&(h.displacementMap.value=u.displacementMap,t(u.displacementMap,h.displacementMapTransform),h.displacementScale.value=u.displacementScale,h.displacementBias.value=u.displacementBias),u.emissiveMap&&(h.emissiveMap.value=u.emissiveMap,t(u.emissiveMap,h.emissiveMapTransform)),u.specularMap&&(h.specularMap.value=u.specularMap,t(u.specularMap,h.specularMapTransform)),u.alphaTest>0&&(h.alphaTest.value=u.alphaTest);let m=e.get(u),f=m.envMap,g=m.envMapRotation;f&&(h.envMap.value=f,Sr.copy(g),Sr.x*=-1,Sr.y*=-1,Sr.z*=-1,f.isCubeTexture&&f.isRenderTargetTexture===!1&&(Sr.y*=-1,Sr.z*=-1),h.envMapRotation.value.setFromMatrix4(Pl.makeRotationFromEuler(Sr)),h.flipEnvMap.value=f.isCubeTexture&&f.isRenderTargetTexture===!1?-1:1,h.reflectivity.value=u.reflectivity,h.ior.value=u.ior,h.refractionRatio.value=u.refractionRatio),u.lightMap&&(h.lightMap.value=u.lightMap,h.lightMapIntensity.value=u.lightMapIntensity,t(u.lightMap,h.lightMapTransform)),u.aoMap&&(h.aoMap.value=u.aoMap,h.aoMapIntensity.value=u.aoMapIntensity,t(u.aoMap,h.aoMapTransform))}function a(d,u){let h=d;h.diffuse.value.copy(u.color),h.opacity.value=u.opacity,h.rotation.value=u.rotation,u.map&&(h.map.value=u.map,t(u.map,h.mapTransform)),u.alphaMap&&(h.alphaMap.value=u.alphaMap,t(u.alphaMap,h.alphaMapTransform)),u.alphaTest>0&&(h.alphaTest.value=u.alphaTest)}function s(d,u){u.gradientMap&&(d.gradientMap.value=u.gradientMap)}function l(d,u){let h=d;h.metalness.value=u.metalness,u.metalnessMap&&(h.metalnessMap.value=u.metalnessMap,t(u.metalnessMap,h.metalnessMapTransform)),h.roughness.value=u.roughness,u.roughnessMap&&(h.roughnessMap.value=u.roughnessMap,t(u.roughnessMap,h.roughnessMapTransform)),u.envMap&&(h.envMapIntensity.value=u.envMapIntensity)}function c(d,u){let h=d,m=e.get(u).light;h.referencePosition.value.setFromMatrixPosition(m.matrixWorld),h.nearDistance.value=m.shadow.camera.near,h.farDistance.value=m.shadow.camera.far}return{refreshFogUniforms:n,refreshMaterialUniforms:i}}var zn={r:0,b:0,g:0};function Go(r,e,t,n,i,o,a){let s=new Pe(0),l=o===!0?0:1,c=!1;function d(g){let v=g.isScene===!0?g.background:null;return v&&v.isTexture&&(v=(g.backgroundBlurriness>0?t:e).get(v)),v}function u(g){let v=!1,M=d(g);M===null?m(s,l):M&&M.isColor&&(m(M,1),v=!0),(r.autoClear||v)&&(n.buffers.depth.setTest(!0),n.buffers.depth.setMask(!0),n.buffers.color.setMask(!0),r.clear(r.autoClearColor,r.autoClearDepth,r.autoClearStencil))}function h(g,v){let M=d(v);M&&M.isTexture&&(c||(c=!0,console.warn("keel/lit background: texture backgrounds are not supported; use a colour.")))}function m(g,v){g.getRGB(zn,Oi(r)),n.buffers.color.setClear(zn.r,zn.g,zn.b,v,a)}function f(){}return{getClearColor:function(){return s},setClearColor:function(g,v=1){s.set(g),l=v,m(s,l)},getClearAlpha:function(){return l},setClearAlpha:function(g){l=g,m(s,l)},render:u,addToRenderList:h,dispose:f}}function Ho(r,e){let t=r.getParameter(r.MAX_VERTEX_ATTRIBS),n={},i=h(null),o=i,a=!1;function s(R,D,F,G,B){let Z=!1,re=u(G,F,D);o!==re&&(o=re,c(o.object)),Z=m(R,G,F,B),Z&&f(R,G,F,B),B!==null&&e.update(B,r.ELEMENT_ARRAY_BUFFER),(Z||a)&&(a=!1,A(R,D,F,G),B!==null&&r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,e.get(B).buffer))}function l(){return r.createVertexArray()}function c(R){return r.bindVertexArray(R)}function d(R){return r.deleteVertexArray(R)}function u(R,D,F){let G=F.wireframe===!0,B=n[R.id];B===void 0&&(B={},n[R.id]=B);let Z=B[D.id];Z===void 0&&(Z={},B[D.id]=Z);let re=Z[String(G)];return re===void 0&&(re=h(l()),Z[String(G)]=re),re}function h(R){let D=[],F=[],G=[];for(let B=0;B<t;B++)D[B]=0,F[B]=0,G[B]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:D,enabledAttributes:F,attributeDivisors:G,object:R,attributes:{},index:null}}function m(R,D,F,G){let B=o.attributes,Z=D.attributes,re=0,oe=F.getAttributes();for(let Y in oe)if(oe[Y].location>=0){let he=B[Y],me=Z[Y];if(me===void 0&&(Y==="instanceMatrix"&&R.instanceMatrix&&(me=R.instanceMatrix),Y==="instanceColor"&&R.instanceColor&&(me=R.instanceColor)),he===void 0||he.attribute!==me)return!0;re++}return o.attributesNum!==re||o.index!==G}function f(R,D,F,G){let B={},Z=D.attributes,re=0,oe=F.getAttributes();for(let Y in oe)if(oe[Y].location>=0){let he=Z[Y];he===void 0&&(Y==="instanceMatrix"&&R.instanceMatrix&&(he=R.instanceMatrix),Y==="instanceColor"&&R.instanceColor&&(he=R.instanceColor));let me={attribute:void 0};me.attribute=he,B[Y]=me,re++}o.attributes=B,o.attributesNum=re,o.index=G}function g(){let R=o.newAttributes;for(let D=0,F=R.length;D<F;D++)R[D]=0}function v(R){M(R,0)}function M(R,D){let F=o.newAttributes,G=o.enabledAttributes,B=o.attributeDivisors;F[R]=1,G[R]===0&&(r.enableVertexAttribArray(R),G[R]=1),B[R]!==D&&(r.vertexAttribDivisor(R,D),B[R]=D)}function T(){let R=o.newAttributes,D=o.enabledAttributes;for(let F=0,G=D.length;F<G;F++)D[F]!==R[F]&&(r.disableVertexAttribArray(F),D[F]=0)}function _(R,D,F,G,B,Z,re){re===!0?r.vertexAttribIPointer(R,D,F,B,Z):r.vertexAttribPointer(R,D,F,G,B,Z)}function A(R,D,F,G){g();let B=G.attributes,Z=F.getAttributes(),re=D.defaultAttributeValues;for(let oe in Z){let Y=Z[oe];if(Y.location>=0){let ae=B[oe];if(ae===void 0&&(oe==="instanceMatrix"&&R.instanceMatrix&&(ae=R.instanceMatrix),oe==="instanceColor"&&R.instanceColor&&(ae=R.instanceColor)),ae!==void 0){let he=ae.normalized,me=ae.itemSize,Ue=e.get(ae);if(Ue===void 0)continue;let Ge=Ue.buffer,ze=Ue.type,ot=Ue.bytesPerElement,je=ze===r.INT||ze===r.UNSIGNED_INT||ae.gpuType==="int";if(ae.isInstancedBufferAttribute){for(let Fe=0;Fe<Y.locationSize;Fe++)M(Y.location+Fe,ae.meshPerAttribute);R.isInstancedMesh!==!0&&G._maxInstanceCount===void 0&&(G._maxInstanceCount=ae.meshPerAttribute*ae.count)}else for(let Fe=0;Fe<Y.locationSize;Fe++)v(Y.location+Fe);r.bindBuffer(r.ARRAY_BUFFER,Ge);for(let Fe=0;Fe<Y.locationSize;Fe++)_(Y.location+Fe,me/Y.locationSize,ze,he,me*ot,me/Y.locationSize*Fe*ot,je)}else if(re!==void 0){let he=re[oe];if(he!==void 0)switch(he.length){case 2:r.vertexAttrib2fv(Y.location,he);break;case 3:r.vertexAttrib3fv(Y.location,he);break;case 4:r.vertexAttrib4fv(Y.location,he);break;default:r.vertexAttrib1fv(Y.location,he)}}}}T()}function U(){p();for(let R in n){let D=n[R];for(let F in D){let G=D[F];for(let B in G)d(G[B].object),delete G[B];delete D[F]}delete n[R]}}function w(R){if(n[R.id]===void 0)return;let D=n[R.id];for(let F in D){let G=D[F];for(let B in G)d(G[B].object),delete G[B];delete D[F]}delete n[R.id]}function E(R){for(let D in n){let F=n[D];if(F[R.id]===void 0)continue;let G=F[R.id];for(let B in G)d(G[B].object),delete G[B];delete F[R.id]}}function p(){y(),a=!0,o!==i&&(o=i,c(o.object))}function y(){i.geometry=null,i.program=null,i.wireframe=!1}return{setup:s,reset:p,resetDefaultState:y,dispose:U,releaseStatesOfGeometry:w,releaseStatesOfProgram:E,initAttributes:g,enableAttribute:v,disableUnusedAttributes:T}}function Wo(r,e,t){let n;function i(s){n=s}function o(s,l){r.drawArrays(n,s,l),t.update(l,n,1)}function a(s,l,c){c!==0&&(r.drawArraysInstanced(n,s,l,c),t.update(l,n,c))}return{setMode:i,render:o,renderInstances:a}}function Xo(r,e,t,n){let i;function o(){if(i!==void 0)return i;if(e.has("EXT_texture_filter_anisotropic")===!0){let E=e.get("EXT_texture_filter_anisotropic");i=r.getParameter(E.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else i=0;return i}function a(E){return!(E!=="rgba"&&n.convert(E)!==r.getParameter(r.IMPLEMENTATION_COLOR_READ_FORMAT))}function s(E){let p=E==="half"&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(E!=="u8"&&n.convert(E)!==r.getParameter(r.IMPLEMENTATION_COLOR_READ_TYPE)&&E!=="float"&&!p)}function l(E){if(E==="highp"){if(r.getShaderPrecisionFormat(r.VERTEX_SHADER,r.HIGH_FLOAT).precision>0&&r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.HIGH_FLOAT).precision>0)return"highp";E="mediump"}return E==="mediump"&&r.getShaderPrecisionFormat(r.VERTEX_SHADER,r.MEDIUM_FLOAT).precision>0&&r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let c=t.precision!==void 0?t.precision:"highp",d=l(c);d!==c&&(console.warn("keel/lit renderer:",c,"not supported, using",d,"instead."),c=d);let u=t.logarithmicDepthBuffer===!0,h=t.reversedDepthBuffer===!0&&e.has("EXT_clip_control"),m=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),f=r.getParameter(r.MAX_VERTEX_TEXTURE_IMAGE_UNITS),g=r.getParameter(r.MAX_TEXTURE_SIZE),v=r.getParameter(r.MAX_CUBE_MAP_TEXTURE_SIZE),M=r.getParameter(r.MAX_VERTEX_ATTRIBS),T=r.getParameter(r.MAX_VERTEX_UNIFORM_VECTORS),_=r.getParameter(r.MAX_VARYING_VECTORS),A=r.getParameter(r.MAX_FRAGMENT_UNIFORM_VECTORS),U=f>0,w=r.getParameter(r.MAX_SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:o,getMaxPrecision:l,textureFormatReadable:a,textureTypeReadable:s,precision:c,logarithmicDepthBuffer:u,reversedDepthBuffer:h,maxTextures:m,maxVertexTextures:f,maxTextureSize:g,maxCubemapSize:v,maxAttributes:M,maxVertexUniforms:T,maxVaryings:_,maxFragmentUniforms:A,vertexTextures:U,maxSamples:w}}function qo(r){let e=null,t=0,n=!1,i=!1,o=new wt,a=new rt,s={value:null,needsUpdate:!1},l={uniform:s,numPlanes:0,numIntersection:0,init(u,h){let m=u.length!==0||h||t!==0||n;return n=h,t=u.length,m},beginShadows(){i=!0,d(null)},endShadows(){i=!1},setGlobalState(u,h){e=d(u,h,0)},setState(u,h,m){let f=u.clippingPlanes,g=u.clipIntersection,v=u.clipShadows,M=r.get(u);if(!n||f===null||f.length===0||i&&!v)i?d(null):c();else{let T=i?0:t,_=T*4,A=M.clippingState||null;s.value=A,A=d(f,h,_,m);for(let U=0;U!==_;++U)A[U]=e[U];M.clippingState=A,l.numIntersection=g?l.numPlanes:0,l.numPlanes+=T}}};function c(){s.value!==e&&(s.value=e,s.needsUpdate=t>0),l.numPlanes=t,l.numIntersection=0}function d(u,h,m,f){let g=u!==null?u.length:0,v=null;if(g!==0){if(v=s.value,f!==!0||v===null){let M=m+g*4,T=h.matrixWorldInverse;a.getNormalMatrix(T),(v===null||v.length<M)&&(v=new Float32Array(M));for(let _=0,A=m;_!==g;++_,A+=4)o.copy(u[_]).applyMatrix4(T,a),o.normal.toArray(v,A),v[A+3]=o.constant}s.value=v,s.needsUpdate=!0}return l.numPlanes=g,l.numIntersection=0,v}return l}function Yo(r){function e(n){if(n&&n.isTexture){let i=n.mapping;if(i==="equirect-reflection"||i==="equirect-refraction")throw new Error("keel/lit: equirectangular environment maps are not supported")}return n}function t(){}return{get:e,dispose:t}}var Ul="\nvoid main() {\n gl_Position = vec4( position.xy, 0.0, 1.0 );\n}\n";function Il(r){return"\nuniform vec4 tile;\nuniform int samples;\n".concat(Fi(r.studio),"\n// PMREMGenerator's face convention: the inverse of cube_uv_reflection_fragment's getUV\nvec3 faceDirection( vec2 uv, float face ) {\n uv = 2.0 * uv - 1.0;\n if ( face == 0.0 ) return vec3( 1.0, uv.y, uv.x );\n if ( face == 1.0 ) return vec3( - uv.x, 1.0, - uv.y );\n if ( face == 2.0 ) return vec3( - uv.x, uv.y, 1.0 );\n if ( face == 3.0 ) return vec3( - 1.0, uv.y, - uv.x );\n if ( face == 4.0 ) return vec3( - uv.x, - 1.0, uv.y );\n return vec3( uv.x, uv.y, - 1.0 );\n}\nvec2 hammersley( uint i, uint n ) {\n uint b = i;\n b = ( b << 16u ) | ( b >> 16u );\n b = ( ( b & 0x55555555u ) << 1u ) | ( ( b & 0xAAAAAAAAu ) >> 1u );\n b = ( ( b & 0x33333333u ) << 2u ) | ( ( b & 0xCCCCCCCCu ) >> 2u );\n b = ( ( b & 0x0F0F0F0Fu ) << 4u ) | ( ( b & 0xF0F0F0F0u ) >> 4u );\n b = ( ( b & 0x00FF00FFu ) << 8u ) | ( ( b & 0xFF00FF00u ) >> 8u );\n return vec2( float( i ) / float( n ), float( b ) * 2.3283064365386963e-10 );\n}\nvoid main() {\n vec2 p = gl_FragCoord.xy - tile.xy;\n float faceSize = tile.z;\n vec2 cell = floor( p / faceSize );\n // (a face's interior is faceSize - 2 texels; its outer ring looks past the edge, so a bilinear read crosses it)\n vec2 uv = ( p - cell * faceSize - 1.0 ) / ( faceSize - 2.0 );\n vec3 N = normalize( faceDirection( uv, cell.x + 3.0 * cell.y ) );\n vec3 c;\n if ( tile.w <= 0.0 ) {\n c = studio( N );\n } else {\n vec3 up = abs( N.y ) < 0.999 ? vec3( 0.0, 1.0, 0.0 ) : vec3( 1.0, 0.0, 0.0 );\n vec3 T = normalize( cross( up, N ) ), B = cross( N, T );\n float a = tile.w * tile.w;\n vec3 acc = vec3( 0.0 );\n float w = 0.0;\n uint n = uint( samples );\n for ( uint i = 0u; i < n; i ++ ) {\n vec2 xi = hammersley( i, n );\n float phi = 6.2831853 * xi.x;\n float ct = sqrt( ( 1.0 - xi.y ) / ( 1.0 + ( a * a - 1.0 ) * xi.y ) );\n float st = sqrt( 1.0 - ct * ct );\n vec3 H = T * ( st * cos( phi ) ) + B * ( st * sin( phi ) ) + N * ct;\n vec3 L = 2.0 * dot( N, H ) * H - N;\n float NoL = dot( N, L );\n if ( NoL > 0.0 ) { acc += studio( L ) * NoL; w += NoL; }\n }\n c = acc / max( w, 1e-4 );\n }\n gl_FragColor = vec4( c, 1.0 );\n}\n")}function jo(r){let e=new WeakMap,t=null;function n(l){if(l&&l.isTexture){if(l.isEnvironment===!0)return i(l).target.texture;let c=l.mapping;if(c==="equirect-reflection"||c==="equirect-refraction"||(c==="cube-reflection"||c==="cube-refraction"))throw new Error("keel/lit: environment maps from a file are not supported: use an Environment")}return l}function i(l){let c=e.get(l);if(c===void 0){if(r===null)throw new Error("keel/lit: an Environment needs the renderer to prefilter it");let d=r.extensions.has("EXT_color_buffer_half_float")||r.extensions.has("EXT_color_buffer_float"),u=new Mr(l.width,l.height,{type:d?"half":"u8",mapping:"cube-uv-reflection",minFilter:"linear",magFilter:"linear",depthBuffer:!1,generateMipmaps:!1}),h=new yr({vertexShader:Ul,uniforms:{tile:{value:new Ze},samples:{value:0}},depthTest:!1,depthWrite:!1});c={target:u,material:h,version:-1},e.set(l,c),l.addEventListener("dispose",a)}return c.version!==l.version&&(o(r,l,c),c.version=l.version),c}function o(l,c,d){let{target:u,material:h}=d,m=Il(c);if(h.fragmentShader!==m&&(h.fragmentShader=m,h.needsUpdate=!0),t===null){let _=new qt(ai(2,2),h);_.frustumCulled=!1,t={mesh:_,camera:new xr}}t.mesh.material=h;let f=l.getRenderTarget(),g=l.getActiveCubeFace(),v=l.getActiveMipmapLevel(),M=Vi(c.size),T=h.uniforms.tile.value;for(let _ of M)u.viewport.set(_.x,_.y,3*_.size,2*_.size),u.scissor.set(_.x,_.y,3*_.size,2*_.size),u.scissorTest=!0,T.set(_.x,_.y,_.size,_.roughness),h.uniforms.samples.value=c.samples*M[0].size/_.size,l.setRenderTarget(u),l.render(t.mesh,t.camera);l.setRenderTarget(f,g,v)}function a(l){let c=l.target;c.removeEventListener("dispose",a);let d=e.get(c);d!==void 0&&(e.delete(c),d.target.dispose(),d.material.dispose())}function s(){e=new WeakMap,t!==null&&(t.mesh.geometry.dispose(),t=null)}return{get:n,dispose:s}}var Zo=new Set;function Dl(r){Zo.has(r)||(Zo.add(r),console.warn(r))}function Ko(r){let e={};function t(n){if(e[n]!==void 0)return e[n];let i;switch(n){case"WEBGL_depth_texture":i=r.getExtension("WEBGL_depth_texture")||r.getExtension("MOZ_WEBGL_depth_texture")||r.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":i=r.getExtension("EXT_texture_filter_anisotropic")||r.getExtension("MOZ_EXT_texture_filter_anisotropic")||r.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":i=r.getExtension("WEBGL_compressed_texture_s3tc")||r.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||r.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":i=r.getExtension("WEBGL_compressed_texture_pvrtc")||r.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:i=r.getExtension(n)}return e[n]=i,i}return{has:function(n){return t(n)!==null},init:function(){t("EXT_color_buffer_float"),t("WEBGL_clip_cull_distance"),t("OES_texture_float_linear"),t("EXT_color_buffer_half_float"),t("WEBGL_multisampled_render_to_texture"),t("WEBGL_render_shared_exponent")},get:function(n){let i=t(n);return i===null&&Dl("keel/lit renderer: "+n+" extension not supported."),i}}}function Fl(r){for(let e=r.length-1;e>=0;--e)if(r[e]>=65535)return!0;return!1}function Qo(r,e,t,n){let i={},o=new WeakMap;function a(u){let h=u.target;h.index!==null&&e.remove(h.index);for(let f in h.attributes)e.remove(h.attributes[f]);h.removeEventListener("dispose",a),delete i[h.id];let m=o.get(h);m&&(e.remove(m),o.delete(h)),n.releaseStatesOfGeometry(h),t.memory.geometries--}function s(u,h){return i[h.id]===!0||(h.addEventListener("dispose",a),i[h.id]=!0,t.memory.geometries++),h}function l(u){let h=u.attributes;for(let m in h)e.update(h[m],r.ARRAY_BUFFER)}function c(u){let h=[],m=u.index,f=u.attributes.position,g=0;if(m!==null){let T=m.array;g=m.version;for(let _=0,A=T.length;_<A;_+=3){let U=T[_+0],w=T[_+1],E=T[_+2];h.push(U,w,w,E,E,U)}}else if(f!==void 0){let T=f.array;g=f.version;for(let _=0,A=T.length/3-1;_<A;_+=3){let U=_+0,w=_+1,E=_+2;h.push(U,w,w,E,E,U)}}else return;let v=new de(Fl(h)?new Uint32Array(h):new Uint16Array(h),1);v.version=g;let M=o.get(u);M&&e.remove(M),o.set(u,v)}function d(u){let h=o.get(u);if(h){let m=u.index;m!==null&&h.version<m.version&&c(u)}else c(u);return o.get(u)}return{get:s,update:l,getWireframeAttribute:d}}function $o(r,e,t){let n;function i(d){n=d}let o,a;function s(d){o=d.type,a=d.bytesPerElement}function l(d,u){r.drawElements(n,u,o,d*a),t.update(u,n,1)}function c(d,u,h){h!==0&&(r.drawElementsInstanced(n,u,o,d*a,h),t.update(u,n,h))}return{setMode:i,setIndex:s,render:l,renderInstances:c}}function Jo(r){let e={geometries:0,textures:0},t={frame:0,calls:0,triangles:0,points:0,lines:0};function n(o,a,s){switch(t.calls++,a){case r.TRIANGLES:t.triangles+=s*(o/3);break;case r.LINES:t.lines+=s*(o/2);break;case r.LINE_STRIP:t.lines+=s*(o-1);break;case r.LINE_LOOP:t.lines+=s*o;break;case r.POINTS:t.points+=s*o;break;default:console.error("keel/lit Info: Unknown draw mode:",a);break}}function i(){t.calls=0,t.triangles=0,t.points=0,t.lines=0}return{memory:e,render:t,programs:null,autoReset:!0,reset:i,update:n}}function ea(r,e,t,n){let i=new WeakMap;function o(l){let c=n.render.frame,d=l.geometry,u=e.get(l,d);return i.get(u)!==c&&(e.update(u),i.set(u,c)),l.isInstancedMesh&&(l.hasEventListener("dispose",s)===!1&&l.addEventListener("dispose",s),i.get(l)!==c&&(t.update(l.instanceMatrix,r.ARRAY_BUFFER),l.instanceColor!==null&&t.update(l.instanceColor,r.ARRAY_BUFFER),i.set(l,c))),u}function a(){i=new WeakMap}function s(l){let c=l.target;c.removeEventListener("dispose",s),t.remove(c.instanceMatrix),c.instanceColor!==null&&t.remove(c.instanceColor)}return{update:o,dispose:a}}var Nl="\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\nvoid main() {\n\n #include <uv_vertex>\n #include <color_vertex>\n #include <morphinstance_vertex>\n #include <morphcolor_vertex>\n #include <batching_vertex>\n\n #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n\n #endif\n\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n\n #include <worldpos_vertex>\n #include <envmap_vertex>\n #include <fog_vertex>\n\n}\n",Vl="\nuniform vec3 diffuse;\nuniform float opacity;\n\n#ifndef FLAT_SHADED\n\n varying vec3 vNormal;\n\n#endif\n\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\nvoid main() {\n\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <clipping_planes_fragment>\n\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n #include <specularmap_fragment>\n\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\n // accumulation (baked indirect lighting only)\n #ifdef USE_LIGHTMAP\n\n vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n\n #else\n\n reflectedLight.indirectDiffuse += vec3( 1.0 );\n\n #endif\n\n // modulation\n #include <aomap_fragment>\n\n reflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\n vec3 outgoingLight = reflectedLight.indirectDiffuse;\n\n #include <envmap_fragment>\n\n #include <opaque_fragment>\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n #include <fog_fragment>\n #include <premultiplied_alpha_fragment>\n #include <dithering_fragment>\n\n}\n",Ol="\n#define STANDARD\n\nvarying vec3 vViewPosition;\n\n#ifdef USE_TRANSMISSION\n\n varying vec3 vWorldPosition;\n\n#endif\n\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\nvoid main() {\n\n #include <uv_vertex>\n #include <color_vertex>\n #include <morphinstance_vertex>\n #include <morphcolor_vertex>\n #include <batching_vertex>\n\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #include <normal_vertex>\n\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <displacementmap_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n\n vViewPosition = - mvPosition.xyz;\n\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n #include <fog_vertex>\n\n#ifdef USE_TRANSMISSION\n\n vWorldPosition = worldPosition.xyz;\n\n#endif\n}\n",kl="\n#define STANDARD\n\n#ifdef PHYSICAL\n #define IOR\n #define USE_SPECULAR\n#endif\n\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n\n#ifdef IOR\n uniform float ior;\n#endif\n\n#ifdef USE_SPECULAR\n uniform float specularIntensity;\n uniform vec3 specularColor;\n\n #ifdef USE_SPECULAR_COLORMAP\n uniform sampler2D specularColorMap;\n #endif\n\n #ifdef USE_SPECULAR_INTENSITYMAP\n uniform sampler2D specularIntensityMap;\n #endif\n#endif\n\n#ifdef USE_CLEARCOAT\n uniform float clearcoat;\n uniform float clearcoatRoughness;\n#endif\n\n#ifdef USE_DISPERSION\n uniform float dispersion;\n#endif\n\n#ifdef USE_IRIDESCENCE\n uniform float iridescence;\n uniform float iridescenceIOR;\n uniform float iridescenceThicknessMinimum;\n uniform float iridescenceThicknessMaximum;\n#endif\n\n#ifdef USE_SHEEN\n uniform vec3 sheenColor;\n uniform float sheenRoughness;\n\n #ifdef USE_SHEEN_COLORMAP\n uniform sampler2D sheenColorMap;\n #endif\n\n #ifdef USE_SHEEN_ROUGHNESSMAP\n uniform sampler2D sheenRoughnessMap;\n #endif\n#endif\n\n#ifdef USE_ANISOTROPY\n uniform vec2 anisotropyVector;\n\n #ifdef USE_ANISOTROPYMAP\n uniform sampler2D anisotropyMap;\n #endif\n#endif\n\nvarying vec3 vViewPosition;\n\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <iridescence_fragment>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_physical_pars_fragment>\n#include <transmission_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <iridescence_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\nvoid main() {\n\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <clipping_planes_fragment>\n\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n #include <roughnessmap_fragment>\n #include <metalnessmap_fragment>\n #include <normal_fragment_begin>\n #include <normal_fragment_maps>\n #include <clearcoat_normal_fragment_begin>\n #include <clearcoat_normal_fragment_maps>\n #include <emissivemap_fragment>\n\n // accumulation\n #include <lights_physical_fragment>\n #include <lights_fragment_begin>\n #include <lights_fragment_maps>\n #include <lights_fragment_end>\n\n // modulation\n #include <aomap_fragment>\n\n vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\n #include <transmission_fragment>\n\n vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\n #ifdef USE_SHEEN\n\n // Sheen energy compensation approximation calculation can be found at the end of\n // Estevez and Kulla, Production Friendly Microfacet Sheen BRDF (2017)\n float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\n outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;\n\n #endif\n\n #ifdef USE_CLEARCOAT\n\n float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\n vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\n outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\n #endif\n\n #include <opaque_fragment>\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n #include <fog_fragment>\n #include <premultiplied_alpha_fragment>\n #include <dithering_fragment>\n\n}\n",zl="\n#define TOON\n\nvarying vec3 vViewPosition;\n\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\nvoid main() {\n\n #include <uv_vertex>\n #include <color_vertex>\n #include <morphinstance_vertex>\n #include <morphcolor_vertex>\n #include <batching_vertex>\n\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n #include <normal_vertex>\n\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <displacementmap_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n\n vViewPosition = - mvPosition.xyz;\n\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n #include <fog_vertex>\n\n}\n",Bl="\n#define TOON\n\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\nvoid main() {\n\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <clipping_planes_fragment>\n\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <color_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n #include <normal_fragment_begin>\n #include <normal_fragment_maps>\n #include <emissivemap_fragment>\n\n // accumulation\n #include <lights_toon_fragment>\n #include <lights_fragment_begin>\n #include <lights_fragment_maps>\n #include <lights_fragment_end>\n\n // modulation\n #include <aomap_fragment>\n\n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\n #include <opaque_fragment>\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n #include <fog_fragment>\n #include <premultiplied_alpha_fragment>\n #include <dithering_fragment>\n\n}\n",Gl="\nuniform float rotation;\nuniform vec2 center;\n\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\nvoid main() {\n\n #include <uv_vertex>\n\n vec4 mvPosition = modelViewMatrix[ 3 ];\n\n vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\n #ifndef USE_SIZEATTENUATION\n\n bool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\n if ( isPerspective ) scale *= - mvPosition.z;\n\n #endif\n\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\n mvPosition.xy += rotatedPosition;\n\n gl_Position = projectionMatrix * mvPosition;\n\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n #include <fog_vertex>\n\n}\n",Hl="\nuniform vec3 diffuse;\nuniform float opacity;\n\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\nvoid main() {\n\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include <clipping_planes_fragment>\n\n vec3 outgoingLight = vec3( 0.0 );\n\n #include <logdepthbuf_fragment>\n #include <map_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n\n outgoingLight = diffuseColor.rgb;\n\n #include <opaque_fragment>\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n #include <fog_fragment>\n\n}\n",Wl="\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\n// This is used for computing an equivalent of gl_FragCoord.z that is as high precision as possible.\n// Some platforms compute gl_FragCoord at a lower precision which makes the manually computed value better for\n// depth-based postprocessing effects. Reproduced on iPad with A10 processor / iPadOS 13.3.1.\nvarying vec2 vHighPrecisionZW;\n\nvoid main() {\n\n #include <uv_vertex>\n\n #include <batching_vertex>\n #include <skinbase_vertex>\n\n #include <morphinstance_vertex>\n\n #ifdef USE_DISPLACEMENTMAP\n\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinnormal_vertex>\n\n #endif\n\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <displacementmap_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n #include <clipping_planes_vertex>\n\n vHighPrecisionZW = gl_Position.zw;\n\n}\n",Xl="\n#if DEPTH_PACKING == 3200\n\n uniform float opacity;\n\n#endif\n\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\nvarying vec2 vHighPrecisionZW;\n\nvoid main() {\n\n vec4 diffuseColor = vec4( 1.0 );\n #include <clipping_planes_fragment>\n\n #if DEPTH_PACKING == 3200\n\n diffuseColor.a = opacity;\n\n #endif\n\n #include <map_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n\n #include <logdepthbuf_fragment>\n\n // Higher precision equivalent of gl_FragCoord.z\n\n #ifdef USE_REVERSED_DEPTH_BUFFER\n\n float fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ];\n\n #else\n\n float fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5;\n\n #endif\n\n #if DEPTH_PACKING == 3200\n\n gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\n #elif DEPTH_PACKING == 3201\n\n gl_FragColor = packDepthToRGBA( fragCoordZ );\n\n #elif DEPTH_PACKING == 3202\n\n gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );\n\n #elif DEPTH_PACKING == 3203\n\n gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );\n\n #endif\n\n}\n",ql="\n#define DISTANCE\n\nvarying vec3 vWorldPosition;\n\n#include <common>\n#include <batching_pars_vertex>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\n\nvoid main() {\n\n #include <uv_vertex>\n\n #include <batching_vertex>\n #include <skinbase_vertex>\n\n #include <morphinstance_vertex>\n\n #ifdef USE_DISPLACEMENTMAP\n\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinnormal_vertex>\n\n #endif\n\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <displacementmap_vertex>\n #include <project_vertex>\n #include <worldpos_vertex>\n #include <clipping_planes_vertex>\n\n vWorldPosition = worldPosition.xyz;\n\n}\n",Yl="\n#define DISTANCE\n\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <clipping_planes_pars_fragment>\n\nvoid main () {\n\n vec4 diffuseColor = vec4( 1.0 );\n #include <clipping_planes_fragment>\n\n #include <map_fragment>\n #include <alphamap_fragment>\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n\n float dist = length( vWorldPosition - referencePosition );\n dist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n dist = saturate( dist ); // clamp to [ 0, 1 ]\n\n gl_FragColor = packDepthToRGBA( dist );\n\n}\n",jl="\n#include <common>\n#include <batching_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <shadowmap_pars_vertex>\n\nvoid main() {\n\n #include <batching_vertex>\n\n #include <beginnormal_vertex>\n #include <morphinstance_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n\n #include <begin_vertex>\n #include <morphtarget_vertex>\n #include <skinning_vertex>\n #include <project_vertex>\n #include <logdepthbuf_vertex>\n\n #include <worldpos_vertex>\n #include <shadowmap_vertex>\n #include <fog_vertex>\n\n}\n",Zl="\nuniform vec3 color;\nuniform float opacity;\n\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <logdepthbuf_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n\nvoid main() {\n\n #include <logdepthbuf_fragment>\n\n gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\n #include <tonemapping_fragment>\n #include <colorspace_fragment>\n #include <fog_fragment>\n\n}\n",{color:ki,vec3:Kl}=Io,zi=Object.freeze({flat:Object.freeze({uniforms:()=>jt([Ce.common,Ce.specularmap,Ce.envmap,Ce.aomap,Ce.lightmap,Ce.fog]),vertexShader:Nl,fragmentShader:Vl}),lit:Object.freeze({uniforms:()=>jt([Ce.common,Ce.envmap,Ce.aomap,Ce.lightmap,Ce.emissivemap,Ce.bumpmap,Ce.normalmap,Ce.displacementmap,Ce.roughnessmap,Ce.metalnessmap,Ce.fog,Ce.lights,{emissive:{value:ki(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Ol,fragmentShader:kl}),toon:Object.freeze({uniforms:()=>jt([Ce.common,Ce.aomap,Ce.lightmap,Ce.emissivemap,Ce.bumpmap,Ce.normalmap,Ce.displacementmap,Ce.gradientmap,Ce.fog,Ce.lights,{emissive:{value:ki(0)}}]),vertexShader:zl,fragmentShader:Bl}),billboard:Object.freeze({uniforms:()=>jt([Ce.sprite,Ce.fog]),vertexShader:Gl,fragmentShader:Hl}),depth:Object.freeze({uniforms:()=>jt([Ce.common,Ce.displacementmap]),vertexShader:Wl,fragmentShader:Xl}),distance:Object.freeze({uniforms:()=>jt([Ce.common,Ce.displacementmap,{referencePosition:{value:Kl(0,0,0)},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:ql,fragmentShader:Yl}),shadow:Object.freeze({uniforms:()=>jt([Ce.lights,Ce.fog,{color:{value:ki(0)},opacity:{value:1}}]),vertexShader:jl,fragmentShader:Zl})});var Bi=Object.freeze({alphahash_fragment:"\n#ifdef USE_ALPHAHASH\n\n if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;\n\n#endif\n",alphahash_pars_fragment:"\n#ifdef USE_ALPHAHASH\n\n /**\n * See: Wyman and McGuire, Hashed Alpha Testing (2017)\n */\n\n const float ALPHA_HASH_SCALE = 0.05; // Derived from trials only, and may be changed.\n\n float hash2D( vec2 value ) {\n\n return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );\n\n }\n\n float hash3D( vec3 value ) {\n\n return hash2D( vec2( hash2D( value.xy ), value.z ) );\n\n }\n\n float getAlphaHashThreshold( vec3 position ) {\n\n // Find the discretized derivatives of our coordinates\n float maxDeriv = max(\n length( dFdx( position.xyz ) ),\n length( dFdy( position.xyz ) )\n );\n float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );\n\n // Find two nearest log-discretized noise scales\n vec2 pixScales = vec2(\n exp2( floor( log2( pixScale ) ) ),\n exp2( ceil( log2( pixScale ) ) )\n );\n\n // Compute alpha thresholds at our two noise scales\n vec2 alpha = vec2(\n hash3D( floor( pixScales.x * position.xyz ) ),\n hash3D( floor( pixScales.y * position.xyz ) )\n );\n\n // Factor to interpolate lerp with\n float lerpFactor = fract( log2( pixScale ) );\n\n // Interpolate alpha threshold from noise at two scales\n float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;\n\n // Pass into CDF to compute uniformly distrib threshold\n float a = min( lerpFactor, 1.0 - lerpFactor );\n vec3 cases = vec3(\n x * x / ( 2.0 * a * ( 1.0 - a ) ),\n ( x - 0.5 * a ) / ( 1.0 - a ),\n 1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )\n );\n\n // Find our final, uniformly distributed alpha threshold (\u03B1\u03C4)\n float threshold = ( x < ( 1.0 - a ) )\n ? ( ( x < a ) ? cases.x : cases.y )\n : cases.z;\n\n // Avoids \u03B1\u03C4 == 0. Could also do \u03B1\u03C4 =1-\u03B1\u03C4\n return clamp( threshold , 1.0e-6, 1.0 );\n\n }\n\n#endif\n",alphamap_fragment:"\n#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;\n\n#endif\n",alphamap_pars_fragment:"\n#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n",alphatest_fragment:"\n#ifdef USE_ALPHATEST\n\n #ifdef ALPHA_TO_COVERAGE\n\n diffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );\n if ( diffuseColor.a == 0.0 ) discard;\n\n #else\n\n if ( diffuseColor.a < alphaTest ) discard;\n\n #endif\n\n#endif\n",alphatest_pars_fragment:"\n#ifdef USE_ALPHATEST\n uniform float alphaTest;\n#endif\n",aomap_fragment:"\n#ifdef USE_AOMAP\n\n // reads channel R, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n\n #if defined( USE_CLEARCOAT ) \n clearcoatSpecularIndirect *= ambientOcclusion;\n #endif\n\n #if defined( USE_SHEEN ) \n sheenSpecularIndirect *= ambientOcclusion;\n #endif\n\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n\n float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\n #endif\n\n#endif\n",aomap_pars_fragment:"\n#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif\n",batching_pars_vertex:"\n#ifdef USE_BATCHING\n #if ! defined( GL_ANGLE_multi_draw )\n #define gl_DrawID _gl_DrawID\n uniform int _gl_DrawID;\n #endif\n\n uniform highp sampler2D batchingTexture;\n uniform highp usampler2D batchingIdTexture;\n mat4 getBatchingMatrix( const in float i ) {\n\n int size = textureSize( batchingTexture, 0 ).x;\n int j = int( i ) * 4;\n int x = j % size;\n int y = j / size;\n vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\n vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\n vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\n vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\n return mat4( v1, v2, v3, v4 );\n\n }\n\n float getIndirectIndex( const in int i ) {\n\n int size = textureSize( batchingIdTexture, 0 ).x;\n int x = i % size;\n int y = i / size;\n return float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );\n\n }\n\n#endif\n\n#ifdef USE_BATCHING_COLOR\n\n uniform sampler2D batchingColorTexture;\n vec3 getBatchingColor( const in float i ) {\n\n int size = textureSize( batchingColorTexture, 0 ).x;\n int j = int( i );\n int x = j % size;\n int y = j / size;\n return texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;\n\n }\n\n#endif\n",batching_vertex:"\n#ifdef USE_BATCHING\n mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );\n#endif\n",begin_vertex:"\nvec3 transformed = vec3( position );\n\n#ifdef USE_ALPHAHASH\n\n vPosition = vec3( position );\n\n#endif\n",beginnormal_vertex:"\nvec3 objectNormal = vec3( normal );\n\n#ifdef USE_TANGENT\n\n vec3 objectTangent = vec3( tangent.xyz );\n\n#endif\n",bsdfs:"\n\nfloat G_BlinnPhong_Implicit( /* const in float dotNL, const in float dotNV */ ) {\n\n // geometry term is (n dot l)(n dot v) / 4(n dot l)(n dot v)\n return 0.25;\n\n}\n\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n\n}\n\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n\n vec3 halfDir = normalize( lightDir + viewDir );\n\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\n float D = D_BlinnPhong( shininess, dotNH );\n\n return F * ( G * D );\n\n} // validated\n\n",bumpmap_pars_fragment:"\n#ifdef USE_BUMPMAP\n\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n\n // Bump Mapping Unparametrized Surfaces on the GPU by Morten S. Mikkelsen\n // Mikkelsen, Bump Mapping Unparametrized Surfaces on the GPU (2010)\n\n // Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\n\n vec2 dHdxy_fwd() {\n\n vec2 dSTdx = dFdx( vBumpMapUv );\n vec2 dSTdy = dFdy( vBumpMapUv );\n\n float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;\n float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;\n float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;\n\n return vec2( dBx, dBy );\n\n }\n\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\n // normalize is done to ensure that the bump map looks the same regardless of the texture's scale\n vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );\n vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );\n vec3 vN = surf_norm; // normalized\n\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n\n float fDet = dot( vSigmaX, R1 ) * faceDirection;\n\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n\n }\n\n#endif\n",clearcoat_normal_fragment_begin:"\n#ifdef USE_CLEARCOAT\n\n vec3 clearcoatNormal = nonPerturbedNormal;\n\n#endif\n",clearcoat_normal_fragment_maps:"\n#ifdef USE_CLEARCOAT_NORMALMAP\n\n vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n clearcoatMapN.xy *= clearcoatNormalScale;\n\n clearcoatNormal = normalize( tbn2 * clearcoatMapN );\n\n#endif\n",clearcoat_pars_fragment:"\n\n#ifdef USE_CLEARCOATMAP\n\n uniform sampler2D clearcoatMap;\n\n#endif\n\n#ifdef USE_CLEARCOAT_NORMALMAP\n\n uniform sampler2D clearcoatNormalMap;\n uniform vec2 clearcoatNormalScale;\n\n#endif\n\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\n uniform sampler2D clearcoatRoughnessMap;\n\n#endif\n",clipping_planes_fragment:"\n#if NUM_CLIPPING_PLANES > 0\n\n vec4 plane;\n\n #ifdef ALPHA_TO_COVERAGE\n\n float distanceToPlane, distanceGradient;\n float clipOpacity = 1.0;\n\n #pragma unroll_loop_start\n for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\n plane = clippingPlanes[ i ];\n distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n distanceGradient = fwidth( distanceToPlane ) / 2.0;\n clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\n if ( clipOpacity == 0.0 ) discard;\n\n }\n #pragma unroll_loop_end\n\n #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\n float unionClipOpacity = 1.0;\n\n #pragma unroll_loop_start\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\n plane = clippingPlanes[ i ];\n distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n distanceGradient = fwidth( distanceToPlane ) / 2.0;\n unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\n }\n #pragma unroll_loop_end\n\n clipOpacity *= 1.0 - unionClipOpacity;\n\n #endif\n\n diffuseColor.a *= clipOpacity;\n\n if ( diffuseColor.a == 0.0 ) discard;\n\n #else\n\n #pragma unroll_loop_start\n for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\n plane = clippingPlanes[ i ];\n if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\n }\n #pragma unroll_loop_end\n\n #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\n bool clipped = true;\n\n #pragma unroll_loop_start\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\n plane = clippingPlanes[ i ];\n clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\n }\n #pragma unroll_loop_end\n\n if ( clipped ) discard;\n\n #endif\n\n #endif\n\n#endif\n",clipping_planes_pars_fragment:"\n#if NUM_CLIPPING_PLANES > 0\n\n varying vec3 vClipPosition;\n\n uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n\n#endif\n",clipping_planes_pars_vertex:"\n#if NUM_CLIPPING_PLANES > 0\n\n varying vec3 vClipPosition;\n\n#endif\n",clipping_planes_vertex:"\n#if NUM_CLIPPING_PLANES > 0\n\n vClipPosition = - mvPosition.xyz;\n\n#endif\n",color_fragment:"\n#if defined( USE_COLOR_ALPHA )\n\n diffuseColor *= vColor;\n\n#elif defined( USE_COLOR )\n\n diffuseColor.rgb *= vColor;\n\n#endif\n",color_pars_fragment:"\n#if defined( USE_COLOR_ALPHA )\n\n varying vec4 vColor;\n\n#elif defined( USE_COLOR )\n\n varying vec3 vColor;\n\n#endif\n",color_pars_vertex:"\n#if defined( USE_COLOR_ALPHA )\n\n varying vec4 vColor;\n\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\n varying vec3 vColor;\n\n#endif\n",color_vertex:"\n#if defined( USE_COLOR_ALPHA )\n\n vColor = vec4( 1.0 );\n\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\n vColor = vec3( 1.0 );\n\n#endif\n\n#ifdef USE_COLOR\n\n vColor *= color;\n\n#endif\n\n#ifdef USE_INSTANCING_COLOR\n\n vColor.xyz *= instanceColor.xyz;\n\n#endif\n\n#ifdef USE_BATCHING_COLOR\n\n vec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );\n\n vColor.xyz *= batchingColor.xyz;\n\n#endif\n",colorspace_fragment:"\ngl_FragColor = linearToOutputTexel( gl_FragColor );\n",common:"\n#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n\n#ifndef saturate\n// <tonemapping_pars_fragment> may have defined saturate() already\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\n\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\n\n// expects values in the range of [0,1]x[0,1], returns values in the [0,1] range.\n// do not collapse into a single function per: Rigg, improvements to the canonical one-liner GLSL rand for OpenGL ES 2.0\nhighp float rand( const in vec2 uv ) {\n\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\n return fract( sin( sn ) * c );\n\n}\n\n#ifdef HIGH_PRECISION\n float precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n float precisionSafeLength( vec3 v ) {\n float maxComponent = max3( abs( v ) );\n return length( v / maxComponent ) * maxComponent;\n }\n#endif\n\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\n\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n\n#ifdef USE_ALPHAHASH\n\n varying vec3 vPosition;\n\n#endif\n\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n}\n\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\n // dir can be either a direction vector or a normal vector\n // upper-left 3x3 of matrix is assumed to be orthogonal\n\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n\n}\n\nmat3 transposeMat3( const in mat3 m ) {\n\n mat3 tmp;\n\n tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\n return tmp;\n\n}\n\nbool isPerspectiveMatrix( mat4 m ) {\n\n return m[ 2 ][ 3 ] == - 1.0;\n\n}\n\nvec2 equirectUv( in vec3 dir ) {\n\n // dir is assumed to be unit length\n\n float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\n float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\n return vec2( u, v );\n\n}\n\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\n return RECIPROCAL_PI * diffuseColor;\n\n} // validated\n\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\n // Original approximation by Christophe Schlick '94\n // float fresnel = pow( 1.0 - dotVH, 5.0 );\n\n // Optimized variant (presented by Epic at SIGGRAPH '13)\n // Karis, Real Shading in Unreal Engine 4 (SIGGRAPH 2013 course notes)\n float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\n return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n\n} // validated\n\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\n // Original approximation by Christophe Schlick '94\n // float fresnel = pow( 1.0 - dotVH, 5.0 );\n\n // Optimized variant (presented by Epic at SIGGRAPH '13)\n // Karis, Real Shading in Unreal Engine 4 (SIGGRAPH 2013 course notes)\n float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\n return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n\n} // validated\n",cube_uv_reflection_fragment:"\n#ifdef ENVMAP_TYPE_CUBE_UV\n\n #define cubeUV_minMipLevel 4.0\n #define cubeUV_minTileSize 16.0\n\n // These shader functions convert between the UV coordinates of a single face of\n // a cubemap, the 0-5 integer index of a cube face, and the direction vector for\n // sampling a textureCube (not generally normalized ).\n\n float getFace( vec3 direction ) {\n\n vec3 absDirection = abs( direction );\n\n float face = - 1.0;\n\n if ( absDirection.x > absDirection.z ) {\n\n if ( absDirection.x > absDirection.y )\n\n face = direction.x > 0.0 ? 0.0 : 3.0;\n\n else\n\n face = direction.y > 0.0 ? 1.0 : 4.0;\n\n } else {\n\n if ( absDirection.z > absDirection.y )\n\n face = direction.z > 0.0 ? 2.0 : 5.0;\n\n else\n\n face = direction.y > 0.0 ? 1.0 : 4.0;\n\n }\n\n return face;\n\n }\n\n // RH coordinate system; PMREM face-indexing convention\n vec2 getUV( vec3 direction, float face ) {\n\n vec2 uv;\n\n if ( face == 0.0 ) {\n\n uv = vec2( direction.z, direction.y ) / abs( direction.x ); // pos x\n\n } else if ( face == 1.0 ) {\n\n uv = vec2( - direction.x, - direction.z ) / abs( direction.y ); // pos y\n\n } else if ( face == 2.0 ) {\n\n uv = vec2( - direction.x, direction.y ) / abs( direction.z ); // pos z\n\n } else if ( face == 3.0 ) {\n\n uv = vec2( - direction.z, direction.y ) / abs( direction.x ); // neg x\n\n } else if ( face == 4.0 ) {\n\n uv = vec2( - direction.x, direction.z ) / abs( direction.y ); // neg y\n\n } else {\n\n uv = vec2( direction.x, direction.y ) / abs( direction.z ); // neg z\n\n }\n\n return 0.5 * ( uv + 1.0 );\n\n }\n\n vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\n float face = getFace( direction );\n\n float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\n mipInt = max( mipInt, cubeUV_minMipLevel );\n\n float faceSize = exp2( mipInt );\n\n highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0; // #25071\n\n if ( face > 2.0 ) {\n\n uv.y += faceSize;\n\n face -= 3.0;\n\n }\n\n uv.x += face * faceSize;\n\n uv.x += filterInt * 3.0 * cubeUV_minTileSize;\n\n uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\n\n uv.x *= CUBEUV_TEXEL_WIDTH;\n uv.y *= CUBEUV_TEXEL_HEIGHT;\n\n #ifdef texture2DGradEXT\n\n return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb; // disable anisotropic filtering\n\n #else\n\n return texture2D( envMap, uv ).rgb;\n\n #endif\n\n }\n\n // These defines must match with PMREMGenerator\n\n #define cubeUV_r0 1.0\n #define cubeUV_m0 - 2.0\n #define cubeUV_r1 0.8\n #define cubeUV_m1 - 1.0\n #define cubeUV_r4 0.4\n #define cubeUV_m4 2.0\n #define cubeUV_r5 0.305\n #define cubeUV_m5 3.0\n #define cubeUV_r6 0.21\n #define cubeUV_m6 4.0\n\n float roughnessToMip( float roughness ) {\n\n float mip = 0.0;\n\n if ( roughness >= cubeUV_r1 ) {\n\n mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\n\n } else if ( roughness >= cubeUV_r4 ) {\n\n mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\n\n } else if ( roughness >= cubeUV_r5 ) {\n\n mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\n\n } else if ( roughness >= cubeUV_r6 ) {\n\n mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\n\n } else {\n\n mip = - 2.0 * log2( 1.16 * roughness ); // 1.16 = 1.79^0.25\n }\n\n return mip;\n\n }\n\n vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\n float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\n\n float mipF = fract( mip );\n\n float mipInt = floor( mip );\n\n vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\n if ( mipF == 0.0 ) {\n\n return vec4( color0, 1.0 );\n\n } else {\n\n vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\n return vec4( mix( color0, color1, mipF ), 1.0 );\n\n }\n\n }\n\n#endif\n",defaultnormal_vertex:"\n\nvec3 transformedNormal = objectNormal;\n#ifdef USE_TANGENT\n\n vec3 transformedTangent = objectTangent;\n\n#endif\n\n#ifdef USE_BATCHING\n\n // this is in lieu of a per-instance normal-matrix\n // shear transforms in the instance matrix are not supported\n\n mat3 bm = mat3( batchingMatrix );\n transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );\n transformedNormal = bm * transformedNormal;\n\n #ifdef USE_TANGENT\n\n transformedTangent = bm * transformedTangent;\n\n #endif\n\n#endif\n\n#ifdef USE_INSTANCING\n\n // this is in lieu of a per-instance normal-matrix\n // shear transforms in the instance matrix are not supported\n\n mat3 im = mat3( instanceMatrix );\n transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );\n transformedNormal = im * transformedNormal;\n\n #ifdef USE_TANGENT\n\n transformedTangent = im * transformedTangent;\n\n #endif\n\n#endif\n\ntransformedNormal = normalMatrix * transformedNormal;\n\n#ifdef FLIP_SIDED\n\n transformedNormal = - transformedNormal;\n\n#endif\n\n#ifdef USE_TANGENT\n\n transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;\n\n #ifdef FLIP_SIDED\n\n transformedTangent = - transformedTangent;\n\n #endif\n\n#endif\n",displacementmap_pars_vertex:"\n#ifdef USE_DISPLACEMENTMAP\n\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n\n#endif\n",displacementmap_vertex:"\n#ifdef USE_DISPLACEMENTMAP\n\n transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n\n#endif\n",dithering_fragment:"\n#ifdef DITHERING\n\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n\n#endif\n",dithering_pars_fragment:"\n#ifdef DITHERING\n\n // based on Shadertoy MslGR8\n vec3 dithering( vec3 color ) {\n //Calculate grid position\n float grid_position = rand( gl_FragCoord.xy );\n\n //Shift the individual colors differently, thus making it even harder to see the dithering pattern\n vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\n //modify shift according to grid position.\n dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\n //shift the color by dither_shift\n return color + dither_shift_RGB;\n }\n\n#endif\n",emissivemap_fragment:"\n#ifdef USE_EMISSIVEMAP\n\n vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\n #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n\n // use inline sRGB decode until browsers properly support SRGB8_ALPHA8 with video textures (#26516)\n\n emissiveColor = sRGBTransferEOTF( emissiveColor );\n\n #endif\n\n totalEmissiveRadiance *= emissiveColor.rgb;\n\n#endif\n",emissivemap_pars_fragment:"\n#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n",envmap_common_pars_fragment:"\n#ifdef USE_ENVMAP\n\n uniform float envMapIntensity;\n uniform float flipEnvMap;\n uniform mat3 envMapRotation;\n\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n \n#endif\n",envmap_fragment:"\n#ifdef USE_ENVMAP\n\n #ifdef ENV_WORLDPOS\n\n vec3 cameraToFrag;\n\n if ( isOrthographic ) {\n\n cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\n } else {\n\n cameraToFrag = normalize( vWorldPosition - cameraPosition );\n\n }\n\n // Transforming Normal Vectors with the Inverse Transformation\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\n #ifdef ENVMAP_MODE_REFLECTION\n\n vec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\n #else\n\n vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\n #endif\n\n #else\n\n vec3 reflectVec = vReflect;\n\n #endif\n\n #ifdef ENVMAP_TYPE_CUBE\n\n vec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\n #else\n\n vec4 envColor = vec4( 0.0 );\n\n #endif\n\n #ifdef ENVMAP_BLENDING_MULTIPLY\n\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\n #elif defined( ENVMAP_BLENDING_MIX )\n\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\n #elif defined( ENVMAP_BLENDING_ADD )\n\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n\n #endif\n\n#endif\n",envmap_pars_fragment:"\n#ifdef USE_ENVMAP\n\n uniform float reflectivity;\n\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\n #define ENV_WORLDPOS\n\n #endif\n\n #ifdef ENV_WORLDPOS\n\n varying vec3 vWorldPosition;\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n\n#endif\n",envmap_pars_vertex:"\n#ifdef USE_ENVMAP\n\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\n #define ENV_WORLDPOS\n\n #endif\n\n #ifdef ENV_WORLDPOS\n \n varying vec3 vWorldPosition;\n\n #else\n\n varying vec3 vReflect;\n uniform float refractionRatio;\n\n #endif\n\n#endif\n",envmap_physical_pars_fragment:"\n#ifdef USE_ENVMAP\n\n vec3 getIBLIrradiance( const in vec3 normal ) {\n\n #ifdef ENVMAP_TYPE_CUBE_UV\n\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\n vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );\n\n return PI * envMapColor.rgb * envMapIntensity;\n\n #else\n\n return vec3( 0.0 );\n\n #endif\n\n }\n\n vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\n #ifdef ENVMAP_TYPE_CUBE_UV\n\n vec3 reflectVec = reflect( - viewDir, normal );\n\n // Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.\n reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\n vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\n return envMapColor.rgb * envMapIntensity;\n\n #else\n\n return vec3( 0.0 );\n\n #endif\n\n }\n\n #ifdef USE_ANISOTROPY\n\n vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\n #ifdef ENVMAP_TYPE_CUBE_UV\n\n // Filament documentation, image-based lights: anisotropy\n vec3 bentNormal = cross( bitangent, viewDir );\n bentNormal = normalize( cross( bentNormal, bitangent ) );\n bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\n return getIBLRadiance( viewDir, bentNormal, roughness );\n\n #else\n\n return vec3( 0.0 );\n\n #endif\n\n }\n\n #endif\n\n#endif\n",envmap_vertex:"\n#ifdef USE_ENVMAP\n\n #ifdef ENV_WORLDPOS\n\n vWorldPosition = worldPosition.xyz;\n\n #else\n\n vec3 cameraToVertex;\n\n if ( isOrthographic ) {\n\n cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\n } else {\n\n cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\n }\n\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\n #ifdef ENVMAP_MODE_REFLECTION\n\n vReflect = reflect( cameraToVertex, worldNormal );\n\n #else\n\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\n #endif\n\n #endif\n\n#endif\n",fog_fragment:"\n#ifdef USE_FOG\n\n #ifdef FOG_EXP2\n\n float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\n #else\n\n float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\n #endif\n\n gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n\n#endif\n",fog_pars_fragment:"\n#ifdef USE_FOG\n\n uniform vec3 fogColor;\n varying float vFogDepth;\n\n #ifdef FOG_EXP2\n\n uniform float fogDensity;\n\n #else\n\n uniform float fogNear;\n uniform float fogFar;\n\n #endif\n\n#endif\n",fog_pars_vertex:"\n#ifdef USE_FOG\n\n varying float vFogDepth;\n\n#endif\n",fog_vertex:"\n#ifdef USE_FOG\n\n vFogDepth = - mvPosition.z;\n\n#endif\n",gradientmap_pars_fragment:"\n\n#ifdef USE_GRADIENTMAP\n\n uniform sampler2D gradientMap;\n\n#endif\n\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\n // dotNL will be from -1.0 to 1.0\n float dotNL = dot( normal, lightDirection );\n vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\n #ifdef USE_GRADIENTMAP\n\n return vec3( texture2D( gradientMap, coord ).r );\n\n #else\n\n vec2 fw = fwidth( coord ) * 0.5;\n return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n\n #endif\n\n}\n",iridescence_fragment:"\n\n#ifdef USE_IRIDESCENCE\n\n // XYZ to linear-sRGB color space\n const mat3 XYZ_TO_REC709 = mat3(\n 3.2404542, -0.9692660, 0.0556434,\n -1.5371385, 1.8760108, -0.2040259,\n -0.4985314, 0.0415560, 1.0572252\n );\n\n // Assume air interface for top\n // Note: We don't handle the case fresnel0 == 1\n vec3 Fresnel0ToIor( vec3 fresnel0 ) {\n\n vec3 sqrtF0 = sqrt( fresnel0 );\n return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );\n\n }\n\n // Conversion FO/IOR\n vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {\n\n return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );\n\n }\n\n // ior is a value between 1.0 and 3.0. 1.0 is air interface\n float IorToFresnel0( float transmittedIor, float incidentIor ) {\n\n return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));\n\n }\n\n // Fresnel equations for dielectric/dielectric interfaces.\n // Ref: Belcour and Barla, A Practical Extension to Microfacet Theory for the Modeling of Varying Iridescence (2017)\n // Evaluation XYZ sensitivity curves in Fourier space\n vec3 evalSensitivity( float OPD, vec3 shift ) {\n\n float phase = 2.0 * PI * OPD * 1.0e-9;\n vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );\n vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );\n vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );\n\n vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );\n xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );\n xyz /= 1.0685e-7;\n\n vec3 rgb = XYZ_TO_REC709 * xyz;\n return rgb;\n\n }\n\n vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {\n\n vec3 I;\n\n // Force iridescenceIOR -> outsideIOR when thinFilmThickness -> 0.0\n float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );\n // Evaluate the cosTheta on the base layer (Snell law)\n float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );\n\n // Handle TIR:\n float cosTheta2Sq = 1.0 - sinTheta2Sq;\n if ( cosTheta2Sq < 0.0 ) {\n\n return vec3( 1.0 );\n\n }\n\n float cosTheta2 = sqrt( cosTheta2Sq );\n\n // First interface\n float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );\n float R12 = F_Schlick( R0, 1.0, cosTheta1 );\n float T121 = 1.0 - R12;\n float phi12 = 0.0;\n if ( iridescenceIOR < outsideIOR ) phi12 = PI;\n float phi21 = PI - phi12;\n\n // Second interface\n vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); // guard against 1.0\n vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );\n vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );\n vec3 phi23 = vec3( 0.0 );\n if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;\n if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;\n if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;\n\n // Phase shift\n float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;\n vec3 phi = vec3( phi21 ) + phi23;\n\n // Compound terms\n vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );\n vec3 r123 = sqrt( R123 );\n vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );\n\n // Reflectance term for m = 0 (DC term amplitude)\n vec3 C0 = R12 + Rs;\n I = C0;\n\n // Reflectance term for m > 0 (pairs of diracs)\n vec3 Cm = Rs - T121;\n for ( int m = 1; m <= 2; ++ m ) {\n\n Cm *= r123;\n vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );\n I += Cm * Sm;\n\n }\n\n // Since out of gamut colors might be produced, negative color values are clamped to 0.\n return max( I, vec3( 0.0 ) );\n\n }\n\n#endif\n\n",iridescence_pars_fragment:"\n\n#ifdef USE_IRIDESCENCEMAP\n\n uniform sampler2D iridescenceMap;\n\n#endif\n\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\n uniform sampler2D iridescenceThicknessMap;\n\n#endif\n",lightmap_pars_fragment:"\n#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif\n",lights_fragment_begin:"\n/**\n * This is a template that can be used to light a material, it uses pluggable\n * RenderEquations (RE)for specific lighting scenarios.\n *\n * Instructions for use:\n * - Ensure that both RE_Direct, RE_IndirectDiffuse and RE_IndirectSpecular are defined\n * - Create a material parameter that is to be passed as the third parameter to your lighting functions.\n *\n * TODO:\n * - Add area light support.\n * - Add sphere light support.\n * - Add diffuse light probe (irradiance cubemap) support.\n */\n\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n\n#ifdef USE_CLEARCOAT\n\n geometryClearcoatNormal = clearcoatNormal;\n\n#endif\n\n#ifdef USE_IRIDESCENCE\n\n float dotNVi = saturate( dot( normal, geometryViewDir ) );\n\n if ( material.iridescenceThickness == 0.0 ) {\n\n material.iridescence = 0.0;\n\n } else {\n\n material.iridescence = saturate( material.iridescence );\n\n }\n\n if ( material.iridescence > 0.0 ) {\n\n material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\n // Iridescence F0 approximation\n material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\n }\n\n#endif\n\nIncidentLight directLight;\n\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\n PointLight pointLight;\n #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLightShadow;\n #endif\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\n pointLight = pointLights[ i ];\n\n getPointLightInfo( pointLight, geometryPosition, directLight );\n\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n #endif\n\n RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n }\n #pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\n SpotLight spotLight;\n vec4 spotColor;\n vec3 spotLightCoord;\n bool inSpotLightMap;\n\n #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLightShadow;\n #endif\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\n spotLight = spotLights[ i ];\n\n getSpotLightInfo( spotLight, geometryPosition, directLight );\n\n // spot lights are ordered [shadows with maps, shadows without maps, maps without shadows, none]\n #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n #else\n #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n #endif\n\n #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n #endif\n\n #undef SPOT_LIGHT_MAP_INDEX\n\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n #endif\n\n RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n }\n #pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\n directionalLight = directionalLights[ i ];\n\n getDirectionalLightInfo( directionalLight, directLight );\n\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n\n RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n }\n #pragma unroll_loop_end\n\n#endif\n\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\n RectAreaLight rectAreaLight;\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\n rectAreaLight = rectAreaLights[ i ];\n RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n }\n #pragma unroll_loop_end\n\n#endif\n\n#if defined( RE_IndirectDiffuse )\n\n vec3 iblIrradiance = vec3( 0.0 );\n\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\n #if defined( USE_LIGHT_PROBES )\n\n irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\n #endif\n\n #if ( NUM_HEMI_LIGHTS > 0 )\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\n }\n #pragma unroll_loop_end\n\n #endif\n\n#endif\n\n#if defined( RE_IndirectSpecular )\n\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n\n#endif\n",lights_fragment_end:"\n#if defined( RE_IndirectDiffuse )\n\n RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n#endif\n\n#if defined( RE_IndirectSpecular )\n\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\n#endif\n",lights_fragment_maps:"\n#if defined( RE_IndirectDiffuse )\n\n #ifdef USE_LIGHTMAP\n\n vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\n irradiance += lightMapIrradiance;\n\n #endif\n\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\n iblIrradiance += getIBLIrradiance( geometryNormal );\n\n #endif\n\n#endif\n\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\n #ifdef USE_ANISOTROPY\n\n radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\n #else\n\n radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\n #endif\n\n #ifdef USE_CLEARCOAT\n\n clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\n #endif\n\n#endif\n",lights_pars_begin:"\nuniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n\n#if defined( USE_LIGHT_PROBES )\n\n uniform vec3 lightProbe[ 9 ];\n\n#endif\n\n// get the irradiance (radiance convolved with cosine lobe) at the point 'normal' on the unit sphere\n// source: Ramamoorthi and Hanrahan, An Efficient Representation for Irradiance Environment Maps (2001)\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\n // normal is assumed to have unit length\n\n float x = normal.x, y = normal.y, z = normal.z;\n\n // band 0\n vec3 result = shCoefficients[ 0 ] * 0.886227;\n\n // band 1\n result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\n // band 2\n result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\n return result;\n\n}\n\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\n vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\n return irradiance;\n\n}\n\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\n vec3 irradiance = ambientLightColor;\n\n return irradiance;\n\n}\n\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\n // based upon Frostbite 3 Moving to Physically-based Rendering\n // page 32, equation 26: E[window1]\n // Lagarde and de Rousiers, Moving Frostbite to PBR (2014 course notes)\n float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\n if ( cutoffDistance > 0.0 ) {\n\n distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\n }\n\n return distanceFalloff;\n\n}\n\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\n return smoothstep( coneCosine, penumbraCosine, angleCosine );\n\n}\n\n#if NUM_DIR_LIGHTS > 0\n\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n };\n\n uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\n void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\n light.color = directionalLight.color;\n light.direction = directionalLight.direction;\n light.visible = true;\n\n }\n\n#endif\n\n\n#if NUM_POINT_LIGHTS > 0\n\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n };\n\n uniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\n // light is an out parameter as having it as a return value caused compiler errors on some devices\n void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\n vec3 lVector = pointLight.position - geometryPosition;\n\n light.direction = normalize( lVector );\n\n float lightDistance = length( lVector );\n\n light.color = pointLight.color;\n light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n light.visible = ( light.color != vec3( 0.0 ) );\n\n }\n\n#endif\n\n\n#if NUM_SPOT_LIGHTS > 0\n\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float coneCos;\n float penumbraCos;\n };\n\n uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\n // light is an out parameter as having it as a return value caused compiler errors on some devices\n void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\n vec3 lVector = spotLight.position - geometryPosition;\n\n light.direction = normalize( lVector );\n\n float angleCos = dot( light.direction, spotLight.direction );\n\n float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\n if ( spotAttenuation > 0.0 ) {\n\n float lightDistance = length( lVector );\n\n light.color = spotLight.color * spotAttenuation;\n light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n light.visible = ( light.color != vec3( 0.0 ) );\n\n } else {\n\n light.color = vec3( 0.0 );\n light.visible = false;\n\n }\n\n }\n\n#endif\n\n\n#if NUM_RECT_AREA_LIGHTS > 0\n\n struct RectAreaLight {\n vec3 color;\n vec3 position;\n vec3 halfWidth;\n vec3 halfHeight;\n };\n\n // Pre-computed values of LinearTransformedCosine approximation of BRDF\n // BRDF approximation Texture is 64x64\n uniform sampler2D ltc_1; // RGBA Float\n uniform sampler2D ltc_2; // RGBA Float\n\n uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n\n#endif\n\n\n#if NUM_HEMI_LIGHTS > 0\n\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n\n uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\n vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\n float dotNL = dot( normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\n vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\n return irradiance;\n\n }\n\n#endif\n",lights_physical_fragment:"\nPhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\n\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\n\nmaterial.roughness = max( roughnessFactor, 0.0525 );// 0.0525 corresponds to the base mip of a 256 cubemap.\nmaterial.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n\n#ifdef IOR\n\n material.ior = ior;\n\n #ifdef USE_SPECULAR\n\n float specularIntensityFactor = specularIntensity;\n vec3 specularColorFactor = specularColor;\n\n #ifdef USE_SPECULAR_COLORMAP\n\n specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\n #endif\n\n #ifdef USE_SPECULAR_INTENSITYMAP\n\n specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\n #endif\n\n material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\n #else\n\n float specularIntensityFactor = 1.0;\n vec3 specularColorFactor = vec3( 1.0 );\n material.specularF90 = 1.0;\n\n #endif\n\n material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n\n#else\n\n material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n material.specularF90 = 1.0;\n\n#endif\n\n#ifdef USE_CLEARCOAT\n\n material.clearcoat = clearcoat;\n material.clearcoatRoughness = clearcoatRoughness;\n material.clearcoatF0 = vec3( 0.04 );\n material.clearcoatF90 = 1.0;\n\n #ifdef USE_CLEARCOATMAP\n\n material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\n #endif\n\n #ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\n material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\n #endif\n\n material.clearcoat = saturate( material.clearcoat ); // Burley clearcoat model\n material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n material.clearcoatRoughness += geometryRoughness;\n material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n\n#endif\n\n#ifdef USE_DISPERSION\n\n material.dispersion = dispersion;\n\n#endif\n\n#ifdef USE_IRIDESCENCE\n\n material.iridescence = iridescence;\n material.iridescenceIOR = iridescenceIOR;\n\n #ifdef USE_IRIDESCENCEMAP\n\n material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\n #endif\n\n #ifdef USE_IRIDESCENCE_THICKNESSMAP\n\n material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\n #else\n\n material.iridescenceThickness = iridescenceThicknessMaximum;\n\n #endif\n\n#endif\n\n#ifdef USE_SHEEN\n\n material.sheenColor = sheenColor;\n\n #ifdef USE_SHEEN_COLORMAP\n\n material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\n #endif\n\n material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\n #ifdef USE_SHEEN_ROUGHNESSMAP\n\n material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\n #endif\n\n#endif\n\n#ifdef USE_ANISOTROPY\n\n #ifdef USE_ANISOTROPYMAP\n\n mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\n #else\n\n vec2 anisotropyV = anisotropyVector;\n\n #endif\n\n material.anisotropy = length( anisotropyV );\n\n if( material.anisotropy == 0.0 ) {\n anisotropyV = vec2( 1.0, 0.0 );\n } else {\n anisotropyV /= material.anisotropy;\n material.anisotropy = saturate( material.anisotropy );\n }\n\n // Roughness along the anisotropy bitangent is the material roughness, while the tangent roughness increases with anisotropy.\n material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\n material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n\n#endif\n",lights_physical_pars_fragment:'\n\nstruct PhysicalMaterial {\n\n vec3 diffuseColor;\n float roughness;\n vec3 specularColor;\n float specularF90;\n float dispersion;\n\n #ifdef USE_CLEARCOAT\n float clearcoat;\n float clearcoatRoughness;\n vec3 clearcoatF0;\n float clearcoatF90;\n #endif\n\n #ifdef USE_IRIDESCENCE\n float iridescence;\n float iridescenceIOR;\n float iridescenceThickness;\n vec3 iridescenceFresnel;\n vec3 iridescenceF0;\n #endif\n\n #ifdef USE_SHEEN\n vec3 sheenColor;\n float sheenRoughness;\n #endif\n\n #ifdef IOR\n float ior;\n #endif\n\n #ifdef USE_TRANSMISSION\n float transmission;\n float transmissionAlpha;\n float thickness;\n float attenuationDistance;\n vec3 attenuationColor;\n #endif\n\n #ifdef USE_ANISOTROPY\n float anisotropy;\n float alphaT;\n vec3 anisotropyT;\n vec3 anisotropyB;\n #endif\n\n};\n\n// temporary\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\n\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\n\n// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2\n// Lagarde and de Rousiers, Moving Frostbite to PBR (2014 course notes)\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\n float a2 = pow2( alpha );\n\n float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\n return 0.5 / max( gv + gl, EPSILON );\n\n}\n\n// Microfacet Models for Refraction through Rough Surfaces - equation (33)\n// Karis, Specular BRDF Reference (2013)\n// alpha is "roughness squared" in Disney\u2019s reparameterization\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\n float a2 = pow2( alpha );\n\n float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; // avoid alpha = 0 with dotNH = 1\n\n return RECIPROCAL_PI * a2 / pow2( denom );\n\n}\n\n// Filament documentation, anisotropic specular BRDF\n#ifdef USE_ANISOTROPY\n\n 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 ) {\n\n float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n float v = 0.5 / ( gv + gl );\n\n return saturate(v);\n\n }\n\n float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\n float a2 = alphaT * alphaB;\n highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n highp float v2 = dot( v, v );\n float w2 = a2 / v2;\n\n return RECIPROCAL_PI * a2 * pow2 ( w2 );\n\n }\n\n#endif\n\n#ifdef USE_CLEARCOAT\n\n // GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility\n vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\n vec3 f0 = material.clearcoatF0;\n float f90 = material.clearcoatF90;\n float roughness = material.clearcoatRoughness;\n\n float alpha = pow2( roughness ); // UE4\'s roughness\n\n vec3 halfDir = normalize( lightDir + viewDir );\n\n float dotNL = saturate( dot( normal, lightDir ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n\n vec3 F = F_Schlick( f0, f90, dotVH );\n\n float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\n float D = D_GGX( alpha, dotNH );\n\n return F * ( V * D );\n\n }\n\n#endif\n\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\n vec3 f0 = material.specularColor;\n float f90 = material.specularF90;\n float roughness = material.roughness;\n\n float alpha = pow2( roughness ); // UE4\'s roughness\n\n vec3 halfDir = normalize( lightDir + viewDir );\n\n float dotNL = saturate( dot( normal, lightDir ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n\n vec3 F = F_Schlick( f0, f90, dotVH );\n\n #ifdef USE_IRIDESCENCE\n\n F = mix( F, material.iridescenceFresnel, material.iridescence );\n\n #endif\n\n #ifdef USE_ANISOTROPY\n\n float dotTL = dot( material.anisotropyT, lightDir );\n float dotTV = dot( material.anisotropyT, viewDir );\n float dotTH = dot( material.anisotropyT, halfDir );\n float dotBL = dot( material.anisotropyB, lightDir );\n float dotBV = dot( material.anisotropyB, viewDir );\n float dotBH = dot( material.anisotropyB, halfDir );\n\n float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\n float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n\n #else\n\n float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\n float D = D_GGX( alpha, dotNH );\n\n #endif\n\n return F * ( V * D );\n\n}\n\n// Rect Area Light\n\n// Real-Time Polygonal-Light Shading with Linearly Transformed Cosines\n// by Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt\n// code: Heitz et al., LTC reference code\n\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\n const float LUT_SIZE = 64.0;\n const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n const float LUT_BIAS = 0.5 / LUT_SIZE;\n\n float dotNV = saturate( dot( N, V ) );\n\n // texture parameterized by sqrt( GGX alpha ) and sqrt( 1 - cos( theta ) )\n vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\n uv = uv * LUT_SCALE + LUT_BIAS;\n\n return uv;\n\n}\n\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\n // Real-Time Area Lighting: a Journey from Research to Production (p.102)\n // An approximation of the form factor of a horizon-clipped rectangle.\n\n float l = length( f );\n\n return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n\n}\n\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\n float x = dot( v1, v2 );\n\n float y = abs( x );\n\n // rational polynomial approximation to theta / sin( theta ) / 2PI\n float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n float b = 3.4175940 + ( 4.1616724 + y ) * y;\n float v = a / b;\n\n float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\n return cross( v1, v2 ) * theta_sintheta;\n\n}\n\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\n // bail if point is on back side of plane of light\n // assumes ccw winding order of light vertices\n vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n vec3 lightNormal = cross( v1, v2 );\n\n if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\n // construct orthonormal basis around N\n vec3 T1, T2;\n T1 = normalize( V - N * dot( V, N ) );\n T2 = - cross( N, T1 ); // negated from paper; possibly due to a different handedness of world coordinate system\n\n // compute transform\n mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\n // transform rect\n vec3 coords[ 4 ];\n coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\n // project rect onto sphere\n coords[ 0 ] = normalize( coords[ 0 ] );\n coords[ 1 ] = normalize( coords[ 1 ] );\n coords[ 2 ] = normalize( coords[ 2 ] );\n coords[ 3 ] = normalize( coords[ 3 ] );\n\n // calculate vector form factor\n vec3 vectorFormFactor = vec3( 0.0 );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\n // adjust for horizon clipping\n float result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\n/*\n // alternate method of adjusting for horizon clipping (see reference)\n // refactoring required\n float len = length( vectorFormFactor );\n float z = vectorFormFactor.z / len;\n\n const float LUT_SIZE = 64.0;\n const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n const float LUT_BIAS = 0.5 / LUT_SIZE;\n\n // tabulated horizon-clipped sphere, apparently...\n vec2 uv = vec2( z * 0.5 + 0.5, len );\n uv = uv * LUT_SCALE + LUT_BIAS;\n\n float scale = texture2D( ltc_2, uv ).w;\n\n float result = len * scale;\n*/\n\n return vec3( result );\n\n}\n\n// End Rect Area Light\n\n#if defined( USE_SHEEN )\n\n// Filament shaders, brdf.fs\nfloat D_Charlie( float roughness, float dotNH ) {\n\n float alpha = pow2( roughness );\n\n // Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF"\n float invAlpha = 1.0 / alpha;\n float cos2h = dotNH * dotNH;\n float sin2h = max( 1.0 - cos2h, 0.0078125 ); // 2^(-14/2), so sin2h^2 > 0 in fp16\n\n return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n\n}\n\n// Filament shaders, brdf.fs\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\n // Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"\n return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n\n}\n\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\n vec3 halfDir = normalize( lightDir + viewDir );\n\n float dotNL = saturate( dot( normal, lightDir ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n\n float D = D_Charlie( sheenRoughness, dotNH );\n float V = V_Neubelt( dotNV, dotNL );\n\n return sheenColor * ( D * V );\n\n}\n\n#endif\n\n// This is a curve-fit approximation to the "Charlie sheen" BRDF integrated over the hemisphere from\n// Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF". The analysis can be found\n// in the Sheen section of Estevez and Kulla, Production Friendly Microfacet Sheen BRDF (2017)\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\n float dotNV = saturate( dot( normal, viewDir ) );\n\n float r2 = roughness * roughness;\n\n float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n\n float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n\n float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n\n return saturate( DG * RECIPROCAL_PI );\n\n}\n\n// Analytical approximation of the DFG LUT, one half of the\n// split-sum approximation used in indirect specular lighting.\n// via \'environmentBRDF\' from "Physically Based Shading on Mobile"\n// Karis, Physically Based Shading on Mobile (2014)\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\n float dotNV = saturate( dot( normal, viewDir ) );\n\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\n vec4 r = roughness * c0 + c1;\n\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\n vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n\n return fab;\n\n}\n\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\n vec2 fab = DFGApprox( normal, viewDir, roughness );\n\n return specularColor * fab.x + specularF90 * fab.y;\n\n}\n\n// Fdez-Ag\xFCera\'s "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting"\n// Approximates multiscattering in order to preserve energy.\n// Fdez-Aguera, A Multiple-Scattering Microfacet Model for Real-Time Image-based Lighting (JCGT 2019)\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\n vec2 fab = DFGApprox( normal, viewDir, roughness );\n\n #ifdef USE_IRIDESCENCE\n\n vec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\n #else\n\n vec3 Fr = specularColor;\n\n #endif\n\n vec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\n float Ess = fab.x + fab.y;\n float Ems = 1.0 - Ess;\n\n vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; // 1/21\n vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\n singleScatter += FssEss;\n multiScatter += Fms * Ems;\n\n}\n\n#if NUM_RECT_AREA_LIGHTS > 0\n\n 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 ) {\n\n vec3 normal = geometryNormal;\n vec3 viewDir = geometryViewDir;\n vec3 position = geometryPosition;\n vec3 lightPos = rectAreaLight.position;\n vec3 halfWidth = rectAreaLight.halfWidth;\n vec3 halfHeight = rectAreaLight.halfHeight;\n vec3 lightColor = rectAreaLight.color;\n float roughness = material.roughness;\n\n vec3 rectCoords[ 4 ];\n rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; // counterclockwise; light shines in local neg z direction\n rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\n vec2 uv = LTC_Uv( normal, viewDir, roughness );\n\n vec4 t1 = texture2D( ltc_1, uv );\n vec4 t2 = texture2D( ltc_2, uv );\n\n mat3 mInv = mat3(\n vec3( t1.x, 0, t1.y ),\n vec3( 0, 1, 0 ),\n vec3( t1.z, 0, t1.w )\n );\n\n // LTC Fresnel Approximation by Stephen Hill\n // Hill and Heitz, LTC Fresnel approximation (SIGGRAPH 2016)\n vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\n reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\n reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\n }\n\n#endif\n\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\n float dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\n vec3 irradiance = dotNL * directLight.color;\n\n #ifdef USE_CLEARCOAT\n\n float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\n vec3 ccIrradiance = dotNLcc * directLight.color;\n\n clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\n #endif\n\n #ifdef USE_SHEEN\n\n sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n\n #endif\n\n reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );\n\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\n}\n\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\n #ifdef USE_CLEARCOAT\n\n clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\n #endif\n\n #ifdef USE_SHEEN\n\n sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\n #endif\n\n // Both indirect specular and indirect diffuse light accumulate here\n\n vec3 singleScattering = vec3( 0.0 );\n vec3 multiScattering = vec3( 0.0 );\n vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\n #ifdef USE_IRIDESCENCE\n\n computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\n\n #else\n\n computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\n #endif\n\n vec3 totalScattering = singleScattering + multiScattering;\n vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );\n\n reflectedLight.indirectSpecular += radiance * singleScattering;\n reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\n reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n\n}\n\n#define RE_Direct RE_Direct_Physical\n#define RE_Direct_RectArea RE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular RE_IndirectSpecular_Physical\n\n// ref: Lagarde and de Rousiers, Moving Frostbite to PBR (2014 course notes)\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\n return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n\n}\n',lights_toon_fragment:"\nToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\n",lights_toon_pars_fragment:"\nvarying vec3 vViewPosition;\n\nstruct ToonMaterial {\n\n vec3 diffuseColor;\n\n};\n\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\n vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\n}\n\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\n}\n\n#define RE_Direct RE_Direct_Toon\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon\n",logdepthbuf_fragment:"\n#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\n // Doing a strict comparison with == 1.0 can cause noise artifacts\n // on some platforms. See issue #17623.\n gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n\n#endif\n",logdepthbuf_pars_fragment:"\n#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\n uniform float logDepthBufFC;\n varying float vFragDepth;\n varying float vIsPerspective;\n\n#endif\n",logdepthbuf_pars_vertex:"\n#ifdef USE_LOGARITHMIC_DEPTH_BUFFER\n\n varying float vFragDepth;\n varying float vIsPerspective;\n\n#endif\n",logdepthbuf_vertex:"\n#ifdef USE_LOGARITHMIC_DEPTH_BUFFER\n\n vFragDepth = 1.0 + gl_Position.w;\n vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\n#endif\n",map_fragment:"\n#ifdef USE_MAP\n\n vec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\n #ifdef DECODE_VIDEO_TEXTURE\n\n // use inline sRGB decode until browsers properly support SRGB8_ALPHA8 with video textures (#26516)\n\n sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n\n #endif\n\n diffuseColor *= sampledDiffuseColor;\n\n#endif\n",map_pars_fragment:"\n#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif\n",metalnessmap_fragment:"\nfloat metalnessFactor = metalness;\n\n#ifdef USE_METALNESSMAP\n\n vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n\n // reads channel B, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n metalnessFactor *= texelMetalness.b;\n\n#endif\n",metalnessmap_pars_fragment:"\n#ifdef USE_METALNESSMAP\n\n uniform sampler2D metalnessMap;\n\n#endif\n",morphcolor_vertex:"\n#if defined( USE_MORPHCOLORS )\n\n // morphTargetBaseInfluence is set based on BufferGeometry.morphTargetsRelative value:\n // When morphTargetsRelative is false, this is set to 1 - sum(influences); this results in normal = sum((target - base) * influence)\n // When morphTargetsRelative is true, this is set to 1; as a result, all morph targets are simply added to the base after weighting\n vColor *= morphTargetBaseInfluence;\n\n for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\n #if defined( USE_COLOR_ALPHA )\n\n if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\n #elif defined( USE_COLOR )\n\n if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\n #endif\n\n }\n\n#endif\n",morphinstance_vertex:"\n#ifdef USE_INSTANCING_MORPH\n\n float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\n float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\n for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\n morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\n }\n#endif\n",morphnormal_vertex:"\n#ifdef USE_MORPHNORMALS\n\n // morphTargetBaseInfluence is set based on BufferGeometry.morphTargetsRelative value:\n // When morphTargetsRelative is false, this is set to 1 - sum(influences); this results in normal = sum((target - base) * influence)\n // When morphTargetsRelative is true, this is set to 1; as a result, all morph targets are simply added to the base after weighting\n objectNormal *= morphTargetBaseInfluence;\n\n for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\n if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\n }\n\n#endif\n",morphtarget_pars_vertex:"\n#ifdef USE_MORPHTARGETS\n\n #ifndef USE_INSTANCING_MORPH\n\n uniform float morphTargetBaseInfluence;\n uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\n #endif\n\n uniform sampler2DArray morphTargetsTexture;\n uniform ivec2 morphTargetsTextureSize;\n\n vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\n int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n int y = texelIndex / morphTargetsTextureSize.x;\n int x = texelIndex - y * morphTargetsTextureSize.x;\n\n ivec3 morphUV = ivec3( x, y, morphTargetIndex );\n return texelFetch( morphTargetsTexture, morphUV, 0 );\n\n }\n\n#endif\n",morphtarget_vertex:"\n#ifdef USE_MORPHTARGETS\n\n // morphTargetBaseInfluence is set based on BufferGeometry.morphTargetsRelative value:\n // When morphTargetsRelative is false, this is set to 1 - sum(influences); this results in position = sum((target - base) * influence)\n // When morphTargetsRelative is true, this is set to 1; as a result, all morph targets are simply added to the base after weighting\n transformed *= morphTargetBaseInfluence;\n\n for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\n if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\n }\n\n#endif\n",normal_fragment_begin:"\nfloat faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n\n#ifdef FLAT_SHADED\n\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n\n#else\n\n vec3 normal = normalize( vNormal );\n\n #ifdef DOUBLE_SIDED\n\n normal *= faceDirection;\n\n #endif\n\n#endif\n\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n\n #ifdef USE_TANGENT\n\n mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\n #else\n\n mat3 tbn = getTangentFrame( - vViewPosition, normal,\n #if defined( USE_NORMALMAP )\n vNormalMapUv\n #elif defined( USE_CLEARCOAT_NORMALMAP )\n vClearcoatNormalMapUv\n #else\n vUv\n #endif\n );\n\n #endif\n\n #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\n tbn[0] *= faceDirection;\n tbn[1] *= faceDirection;\n\n #endif\n\n#endif\n\n#ifdef USE_CLEARCOAT_NORMALMAP\n\n #ifdef USE_TANGENT\n\n mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\n #else\n\n mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n\n #endif\n\n #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\n tbn2[0] *= faceDirection;\n tbn2[1] *= faceDirection;\n\n #endif\n\n#endif\n\n// non perturbed normal for clearcoat among others\n\nvec3 nonPerturbedNormal = normal;\n\n",normal_fragment_maps:"\n\n#ifdef USE_NORMALMAP_OBJECTSPACE\n\n normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; // overrides both flatShading and attribute normals\n\n #ifdef FLIP_SIDED\n\n normal = - normal;\n\n #endif\n\n #ifdef DOUBLE_SIDED\n\n normal = normal * faceDirection;\n\n #endif\n\n normal = normalize( normalMatrix * normal );\n\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\n vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n mapN.xy *= normalScale;\n\n normal = normalize( tbn * mapN );\n\n#elif defined( USE_BUMPMAP )\n\n normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n\n#endif\n",normal_pars_fragment:"\n#ifndef FLAT_SHADED\n\n varying vec3 vNormal;\n\n #ifdef USE_TANGENT\n\n varying vec3 vTangent;\n varying vec3 vBitangent;\n\n #endif\n\n#endif\n",normal_pars_vertex:"\n#ifndef FLAT_SHADED\n\n varying vec3 vNormal;\n\n #ifdef USE_TANGENT\n\n varying vec3 vTangent;\n varying vec3 vBitangent;\n\n #endif\n\n#endif\n",normal_vertex:"\n#ifndef FLAT_SHADED // normal is computed with derivatives when FLAT_SHADED\n\n vNormal = normalize( transformedNormal );\n\n #ifdef USE_TANGENT\n\n vTangent = normalize( transformedTangent );\n vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\n #endif\n\n#endif\n",normalmap_pars_fragment:"\n#ifdef USE_NORMALMAP\n\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n\n#endif\n\n#ifdef USE_NORMALMAP_OBJECTSPACE\n\n uniform mat3 normalMatrix;\n\n#endif\n\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n\n // Normal Mapping Without Precomputed Tangents\n // Schuler, Followup: Normal Mapping Without Precomputed Tangents (2013)\n\n mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n\n vec3 q0 = dFdx( eye_pos.xyz );\n vec3 q1 = dFdy( eye_pos.xyz );\n vec2 st0 = dFdx( uv.st );\n vec2 st1 = dFdy( uv.st );\n\n vec3 N = surf_norm; // normalized\n\n vec3 q1perp = cross( q1, N );\n vec3 q0perp = cross( N, q0 );\n\n vec3 T = q1perp * st0.x + q0perp * st1.x;\n vec3 B = q1perp * st0.y + q0perp * st1.y;\n\n float det = max( dot( T, T ), dot( B, B ) );\n float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n\n return mat3( T * scale, B * scale, N );\n\n }\n\n#endif\n",opaque_fragment:"\n#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\n\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );\n",packing:"\nvec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\n\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n}\n\nconst float PackUpscale = 256. / 255.; // fraction -> 0..1 (including 1)\nconst float UnpackDownscale = 255. / 256.; // 0..1 -> fraction (excluding 1)\nconst float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\n\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\n\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\n\nvec4 packDepthToRGBA( const in float v ) {\n if( v <= 0.0 )\n return vec4( 0., 0., 0., 0. );\n if( v >= 1.0 )\n return vec4( 1., 1., 1., 1. );\n float vuf;\n float af = modf( v * PackFactors.a, vuf );\n float bf = modf( vuf * ShiftRight8, vuf );\n float gf = modf( vuf * ShiftRight8, vuf );\n return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\n\nvec3 packDepthToRGB( const in float v ) {\n if( v <= 0.0 )\n return vec3( 0., 0., 0. );\n if( v >= 1.0 )\n return vec3( 1., 1., 1. );\n float vuf;\n float bf = modf( v * PackFactors.b, vuf );\n float gf = modf( vuf * ShiftRight8, vuf );\n // the 0.9999 tweak is unimportant, very tiny empirical improvement\n // return vec3( vuf * Inv255, gf * PackUpscale, bf * 0.9999 );\n return vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\n\nvec2 packDepthToRG( const in float v ) {\n if( v <= 0.0 )\n return vec2( 0., 0. );\n if( v >= 1.0 )\n return vec2( 1., 1. );\n float vuf;\n float gf = modf( v * 256., vuf );\n return vec2( vuf * Inv255, gf );\n}\n\nfloat unpackRGBAToDepth( const in vec4 v ) {\n return dot( v, UnpackFactors4 );\n}\n\nfloat unpackRGBToDepth( const in vec3 v ) {\n return dot( v, UnpackFactors3 );\n}\n\nfloat unpackRGToDepth( const in vec2 v ) {\n return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\n\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\n\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\n\n// NOTE: viewZ, the z-coordinate in camera space, is negative for points in front of the camera\n\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n // -near maps to 0; -far maps to 1\n return ( viewZ + near ) / ( near - far );\n}\n\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n // maps orthographic depth in [ 0, 1 ] to viewZ\n return depth * ( near - far ) - near;\n}\n\n// NOTE: gonnavis, note on this workaround (2021)\n\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n // -near maps to 0; -far maps to 1\n return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\n\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n // maps perspective depth in [ 0, 1 ] to viewZ\n return ( near * far ) / ( ( far - near ) * depth - far );\n}\n",premultiplied_alpha_fragment:"\n#ifdef PREMULTIPLIED_ALPHA\n\n // Get normal blending with premultipled, use with CustomBlending, OneFactor, OneMinusSrcAlphaFactor, AddEquation.\n gl_FragColor.rgb *= gl_FragColor.a;\n\n#endif\n",project_vertex:"\nvec4 mvPosition = vec4( transformed, 1.0 );\n\n#ifdef USE_BATCHING\n\n mvPosition = batchingMatrix * mvPosition;\n\n#endif\n\n#ifdef USE_INSTANCING\n\n mvPosition = instanceMatrix * mvPosition;\n\n#endif\n\nmvPosition = modelViewMatrix * mvPosition;\n\ngl_Position = projectionMatrix * mvPosition;\n",roughnessmap_fragment:"\nfloat roughnessFactor = roughness;\n\n#ifdef USE_ROUGHNESSMAP\n\n vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n\n // reads channel G, compatible with a combined OcclusionRoughnessMetallic (RGB) texture\n roughnessFactor *= texelRoughness.g;\n\n#endif\n",roughnessmap_pars_fragment:"\n#ifdef USE_ROUGHNESSMAP\n\n uniform sampler2D roughnessMap;\n\n#endif\n",shadowmap_pars_fragment:"\n#if NUM_SPOT_LIGHT_COORDS > 0\n\n varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n\n#endif\n\n#if NUM_SPOT_LIGHT_MAPS > 0\n\n uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n\n#endif\n\n#ifdef USE_SHADOWMAP\n\n #if NUM_DIR_LIGHT_SHADOWS > 0\n\n uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\n struct DirectionalLightShadow {\n float shadowIntensity;\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n\n uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\n #endif\n\n #if NUM_SPOT_LIGHT_SHADOWS > 0\n\n uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\n struct SpotLightShadow {\n float shadowIntensity;\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n\n uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\n #endif\n\n #if NUM_POINT_LIGHT_SHADOWS > 0\n\n uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\n struct PointLightShadow {\n float shadowIntensity;\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n float shadowCameraNear;\n float shadowCameraFar;\n };\n\n uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\n #endif\n\n float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\n float depth = unpackRGBAToDepth( texture2D( depths, uv ) );\n\n #ifdef USE_REVERSED_DEPTH_BUFFER\n\n return step( depth, compare );\n\n #else\n\n return step( compare, depth );\n\n #endif\n\n }\n\n vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\n return unpackRGBATo2Half( texture2D( shadow, uv ) );\n\n }\n\n float VSMShadow( sampler2D shadow, vec2 uv, float compare ) {\n\n float occlusion = 1.0;\n\n vec2 distribution = texture2DDistribution( shadow, uv );\n\n #ifdef USE_REVERSED_DEPTH_BUFFER\n\n float hard_shadow = step( distribution.x, compare );\n\n #else\n\n float hard_shadow = step( compare, distribution.x );\n\n #endif\n\n if ( hard_shadow != 1.0 ) {\n\n float distance = compare - distribution.x;\n float variance = max( 0.00000, distribution.y * distribution.y );\n float softness_probability = variance / (variance + distance * distance ); // Chebeyshevs inequality\n softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); // 0.3 reduces light bleed\n occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\n }\n return occlusion;\n\n }\n\n float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\n float shadow = 1.0;\n\n shadowCoord.xyz /= shadowCoord.w;\n shadowCoord.z += shadowBias;\n\n bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n bool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\n if ( frustumTest ) {\n\n #if defined( SHADOWMAP_TYPE_PCF )\n\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n float dx2 = dx0 / 2.0;\n float dy2 = dy0 / 2.0;\n float dx3 = dx1 / 2.0;\n float dy3 = dy1 / 2.0;\n\n shadow = (\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 17.0 );\n\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx = texelSize.x;\n float dy = texelSize.y;\n\n vec2 uv = shadowCoord.xy;\n vec2 f = fract( uv * shadowMapSize + 0.5 );\n uv -= f * texelSize;\n\n shadow = (\n texture2DCompare( shadowMap, uv, shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n f.x ) +\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n f.x ) +\n mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n f.y ) +\n mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n f.y ) +\n mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n f.x ),\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n f.x ),\n f.y )\n ) * ( 1.0 / 9.0 );\n\n #elif defined( SHADOWMAP_TYPE_VSM )\n\n shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\n #else // no percentage-closer filtering:\n\n shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\n #endif\n\n }\n\n return mix( 1.0, shadow, shadowIntensity );\n\n }\n\n // cubeToUV() maps a 3D direction vector suitable for cube texture mapping to a 2D\n // vector suitable for 2D texture mapping. This code uses the following layout for the\n // 2D texture:\n //\n // xzXZ\n // y Y\n //\n // Y - Positive y direction\n // y - Negative y direction\n // X - Positive x direction\n // x - Negative x direction\n // Z - Positive z direction\n // z - Negative z direction\n //\n // Source and test bed:\n // tschw, gist da10c43c467ce8afd0c4\n\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n\n // Number of texels to avoid at the edge of each square\n\n vec3 absV = abs( v );\n\n // Intersect unit cube\n\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n\n // Apply scale to avoid seams\n\n // two texels less per square (one texel will do for NEAREST)\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\n // Unwrap\n\n // space: -1 ... 1 range for each square\n //\n // #X## dim := ( 4 , 2 )\n // # # center := ( 1 , 1 )\n\n vec2 planar = v.xy;\n\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n\n if ( absV.z >= almostOne ) {\n\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n\n } else if ( absV.x >= almostOne ) {\n\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n\n } else if ( absV.y >= almostOne ) {\n\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n\n }\n\n // Transform to UV space\n\n // scale := 0.5 / dim\n // translate := ( center + 0.5 ) / dim\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\n }\n\n float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\n float shadow = 1.0;\n\n // for point lights, the uniform @vShadowCoord is re-purposed to hold\n // the vector from the light to the world-space position of the fragment.\n vec3 lightToPosition = shadowCoord.xyz;\n \n float lightToPositionLength = length( lightToPosition );\n\n if ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {\n\n // dp = normalized distance from light to fragment position\n float dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); // need to clamp?\n dp += shadowBias;\n\n // bd3D = base direction 3D\n vec3 bd3D = normalize( lightToPosition );\n\n vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\n vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\n shadow = (\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n ) * ( 1.0 / 9.0 );\n\n #else // no percentage-closer filtering\n\n shadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\n #endif\n\n }\n\n return mix( 1.0, shadow, shadowIntensity );\n\n }\n\n#endif\n",shadowmap_pars_vertex:"\n\n#if NUM_SPOT_LIGHT_COORDS > 0\n\n uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n\n#endif\n\n#ifdef USE_SHADOWMAP\n\n #if NUM_DIR_LIGHT_SHADOWS > 0\n\n uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\n struct DirectionalLightShadow {\n float shadowIntensity;\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n\n uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\n #endif\n\n #if NUM_SPOT_LIGHT_SHADOWS > 0\n\n struct SpotLightShadow {\n float shadowIntensity;\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n\n uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\n #endif\n\n #if NUM_POINT_LIGHT_SHADOWS > 0\n\n uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\n struct PointLightShadow {\n float shadowIntensity;\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n float shadowCameraNear;\n float shadowCameraFar;\n };\n\n uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\n #endif\n\n /*\n #if NUM_RECT_AREA_LIGHTS > 0\n\n // TODO (abelnation): uniforms for area light shadows\n\n #endif\n */\n\n#endif\n",shadowmap_vertex:"\n\n#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\n // Offsetting the position used for querying occlusion along the world normal can be used to reduce shadow acne.\n vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n vec4 shadowWorldPosition;\n\n#endif\n\n#if defined( USE_SHADOWMAP )\n\n #if NUM_DIR_LIGHT_SHADOWS > 0\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\n shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\n }\n #pragma unroll_loop_end\n\n #endif\n\n #if NUM_POINT_LIGHT_SHADOWS > 0\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\n shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\n }\n #pragma unroll_loop_end\n\n #endif\n\n /*\n #if NUM_RECT_AREA_LIGHTS > 0\n\n // TODO (abelnation): update vAreaShadowCoord with area light info\n\n #endif\n */\n\n#endif\n\n// spot lights can be evaluated without active shadow mapping (when SpotLight.map is used)\n\n#if NUM_SPOT_LIGHT_COORDS > 0\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\n shadowWorldPosition = worldPosition;\n #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n #endif\n vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\n }\n #pragma unroll_loop_end\n\n#endif\n\n\n",shadowmask_pars_fragment:"\nfloat getShadowMask() {\n\n float shadow = 1.0;\n\n #ifdef USE_SHADOWMAP\n\n #if NUM_DIR_LIGHT_SHADOWS > 0\n\n DirectionalLightShadow directionalLight;\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\n directionalLight = directionalLightShadows[ i ];\n shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\n }\n #pragma unroll_loop_end\n\n #endif\n\n #if NUM_SPOT_LIGHT_SHADOWS > 0\n\n SpotLightShadow spotLight;\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\n spotLight = spotLightShadows[ i ];\n shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\n }\n #pragma unroll_loop_end\n\n #endif\n\n #if NUM_POINT_LIGHT_SHADOWS > 0\n\n PointLightShadow pointLight;\n\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\n pointLight = pointLightShadows[ i ];\n shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\n }\n #pragma unroll_loop_end\n\n #endif\n\n /*\n #if NUM_RECT_AREA_LIGHTS > 0\n\n // TODO (abelnation): update shadow for Area light\n\n #endif\n */\n\n #endif\n\n return shadow;\n\n}\n",skinbase_vertex:"\n#ifdef USE_SKINNING\n\n mat4 boneMatX = getBoneMatrix( skinIndex.x );\n mat4 boneMatY = getBoneMatrix( skinIndex.y );\n mat4 boneMatZ = getBoneMatrix( skinIndex.z );\n mat4 boneMatW = getBoneMatrix( skinIndex.w );\n\n#endif\n",skinning_pars_vertex:"\n#ifdef USE_SKINNING\n\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n\n uniform highp sampler2D boneTexture;\n\n mat4 getBoneMatrix( const in float i ) {\n\n int size = textureSize( boneTexture, 0 ).x;\n int j = int( i ) * 4;\n int x = j % size;\n int y = j / size;\n vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\n vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\n vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\n vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\n\n return mat4( v1, v2, v3, v4 );\n\n }\n\n#endif\n",skinning_vertex:"\n#ifdef USE_SKINNING\n\n vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\n vec4 skinned = vec4( 0.0 );\n skinned += boneMatX * skinVertex * skinWeight.x;\n skinned += boneMatY * skinVertex * skinWeight.y;\n skinned += boneMatZ * skinVertex * skinWeight.z;\n skinned += boneMatW * skinVertex * skinWeight.w;\n\n transformed = ( bindMatrixInverse * skinned ).xyz;\n\n#endif\n",skinnormal_vertex:"\n#ifdef USE_SKINNING\n\n mat4 skinMatrix = mat4( 0.0 );\n skinMatrix += skinWeight.x * boneMatX;\n skinMatrix += skinWeight.y * boneMatY;\n skinMatrix += skinWeight.z * boneMatZ;\n skinMatrix += skinWeight.w * boneMatW;\n skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\n objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\n #ifdef USE_TANGENT\n\n objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\n #endif\n\n#endif\n",specularmap_fragment:"\nfloat specularStrength;\n\n#ifdef USE_SPECULARMAP\n\n vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n specularStrength = texelSpecular.r;\n\n#else\n\n specularStrength = 1.0;\n\n#endif\n",specularmap_pars_fragment:"\n#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif\n",tonemapping_fragment:"\n#if defined( TONE_MAPPING )\n\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n\n#endif\n",transmission_fragment:"\n#ifdef USE_TRANSMISSION\n\n material.transmission = transmission;\n material.transmissionAlpha = 1.0;\n material.thickness = thickness;\n material.attenuationDistance = attenuationDistance;\n material.attenuationColor = attenuationColor;\n\n #ifdef USE_TRANSMISSIONMAP\n\n material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\n #endif\n\n #ifdef USE_THICKNESSMAP\n\n material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\n #endif\n\n vec3 pos = vWorldPosition;\n vec3 v = normalize( cameraPosition - pos );\n vec3 n = inverseTransformDirection( normal, viewMatrix );\n\n vec4 transmitted = getIBLVolumeRefraction(\n n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n material.attenuationColor, material.attenuationDistance );\n\n material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\n totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n\n#endif\n",transmission_pars_fragment:"\n#ifdef USE_TRANSMISSION\n\n // Transmission code is based on glTF-Sampler-Viewer\n // Khronos glTF Sample Viewer\n\n uniform float transmission;\n uniform float thickness;\n uniform float attenuationDistance;\n uniform vec3 attenuationColor;\n\n #ifdef USE_TRANSMISSIONMAP\n\n uniform sampler2D transmissionMap;\n\n #endif\n\n #ifdef USE_THICKNESSMAP\n\n uniform sampler2D thicknessMap;\n\n #endif\n\n uniform vec2 transmissionSamplerSize;\n uniform sampler2D transmissionSamplerMap;\n\n uniform mat4 modelMatrix;\n uniform mat4 projectionMatrix;\n\n varying vec3 vWorldPosition;\n\n // Mipped Bicubic Texture Filtering by N8\n // Shadertoy Dl2SDW\n\n float w0( float a ) {\n\n return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n\n }\n\n float w1( float a ) {\n\n return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n\n }\n\n float w2( float a ){\n\n return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n\n }\n\n float w3( float a ) {\n\n return ( 1.0 / 6.0 ) * ( a * a * a );\n\n }\n\n // g0 and g1 are the two amplitude functions\n float g0( float a ) {\n\n return w0( a ) + w1( a );\n\n }\n\n float g1( float a ) {\n\n return w2( a ) + w3( a );\n\n }\n\n // h0 and h1 are the two offset functions\n float h0( float a ) {\n\n return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n\n }\n\n float h1( float a ) {\n\n return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n\n }\n\n vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n\n uv = uv * texelSize.zw + 0.5;\n\n vec2 iuv = floor( uv );\n vec2 fuv = fract( uv );\n\n float g0x = g0( fuv.x );\n float g1x = g1( fuv.x );\n float h0x = h0( fuv.x );\n float h1x = h1( fuv.x );\n float h0y = h0( fuv.y );\n float h1y = h1( fuv.y );\n\n vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\n return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n\n }\n\n vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n\n vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n vec2 fLodSizeInv = 1.0 / fLodSize;\n vec2 cLodSizeInv = 1.0 / cLodSize;\n vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n return mix( fSample, cSample, fract( lod ) );\n\n }\n\n vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\n // Direction of refracted light.\n vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\n // Compute rotation-independent scaling of the model matrix.\n vec3 modelScale;\n modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\n // The thickness is specified in local space.\n return normalize( refractionVector ) * thickness * modelScale;\n\n }\n\n float applyIorToRoughness( const in float roughness, const in float ior ) {\n\n // Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and\n // an IOR of 1.5 results in the default amount of microfacet refraction.\n return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\n }\n\n vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\n float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n\n }\n\n vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\n if ( isinf( attenuationDistance ) ) {\n\n // Attenuation distance is +\u221E, i.e. the transmitted color is not attenuated at all.\n return vec3( 1.0 );\n\n } else {\n\n // Compute light attenuation using Beer's law.\n vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); // Beer's law\n return transmittance;\n\n }\n\n }\n\n vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\n const in vec3 attenuationColor, const in float attenuationDistance ) {\n\n vec4 transmittedLight;\n vec3 transmittance;\n\n #ifdef USE_DISPERSION\n\n float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\n vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\n\n for ( int i = 0; i < 3; i ++ ) {\n\n vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\n vec3 refractedRayExit = position + transmissionRay;\n\n // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.\n vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n vec2 refractionCoords = ndcPos.xy / ndcPos.w;\n refractionCoords += 1.0;\n refractionCoords /= 2.0;\n\n // Sample framebuffer to get pixel the refracted ray hits.\n vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\n transmittedLight[ i ] = transmissionSample[ i ];\n transmittedLight.a += transmissionSample.a;\n\n transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\n\n }\n\n transmittedLight.a /= 3.0;\n\n #else\n\n vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n vec3 refractedRayExit = position + transmissionRay;\n\n // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.\n vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n vec2 refractionCoords = ndcPos.xy / ndcPos.w;\n refractionCoords += 1.0;\n refractionCoords /= 2.0;\n\n // Sample framebuffer to get pixel the refracted ray hits.\n transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n\n #endif\n\n vec3 attenuatedColor = transmittance * transmittedLight.rgb;\n\n // Get the specular component.\n vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\n // As less light is transmitted, the opacity should be increased. This simple approximation does a decent job\n // of modulating a CSS background, and has no effect when the buffer is opaque, due to a solid object or clear color.\n float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n\n return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n\n }\n#endif\n",uv_pars_fragment:"\n#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\n varying vec2 vUv;\n\n#endif\n#ifdef USE_MAP\n\n varying vec2 vMapUv;\n\n#endif\n#ifdef USE_ALPHAMAP\n\n varying vec2 vAlphaMapUv;\n\n#endif\n#ifdef USE_LIGHTMAP\n\n varying vec2 vLightMapUv;\n\n#endif\n#ifdef USE_AOMAP\n\n varying vec2 vAoMapUv;\n\n#endif\n#ifdef USE_BUMPMAP\n\n varying vec2 vBumpMapUv;\n\n#endif\n#ifdef USE_NORMALMAP\n\n varying vec2 vNormalMapUv;\n\n#endif\n#ifdef USE_EMISSIVEMAP\n\n varying vec2 vEmissiveMapUv;\n\n#endif\n#ifdef USE_METALNESSMAP\n\n varying vec2 vMetalnessMapUv;\n\n#endif\n#ifdef USE_ROUGHNESSMAP\n\n varying vec2 vRoughnessMapUv;\n\n#endif\n#ifdef USE_ANISOTROPYMAP\n\n varying vec2 vAnisotropyMapUv;\n\n#endif\n#ifdef USE_CLEARCOATMAP\n\n varying vec2 vClearcoatMapUv;\n\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\n varying vec2 vClearcoatNormalMapUv;\n\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\n varying vec2 vClearcoatRoughnessMapUv;\n\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\n varying vec2 vIridescenceMapUv;\n\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\n varying vec2 vIridescenceThicknessMapUv;\n\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\n varying vec2 vSheenColorMapUv;\n\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\n varying vec2 vSheenRoughnessMapUv;\n\n#endif\n#ifdef USE_SPECULARMAP\n\n varying vec2 vSpecularMapUv;\n\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\n varying vec2 vSpecularColorMapUv;\n\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\n varying vec2 vSpecularIntensityMapUv;\n\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\n uniform mat3 transmissionMapTransform;\n varying vec2 vTransmissionMapUv;\n\n#endif\n#ifdef USE_THICKNESSMAP\n\n uniform mat3 thicknessMapTransform;\n varying vec2 vThicknessMapUv;\n\n#endif\n",uv_pars_vertex:"\n#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\n varying vec2 vUv;\n\n#endif\n#ifdef USE_MAP\n\n uniform mat3 mapTransform;\n varying vec2 vMapUv;\n\n#endif\n#ifdef USE_ALPHAMAP\n\n uniform mat3 alphaMapTransform;\n varying vec2 vAlphaMapUv;\n\n#endif\n#ifdef USE_LIGHTMAP\n\n uniform mat3 lightMapTransform;\n varying vec2 vLightMapUv;\n\n#endif\n#ifdef USE_AOMAP\n\n uniform mat3 aoMapTransform;\n varying vec2 vAoMapUv;\n\n#endif\n#ifdef USE_BUMPMAP\n\n uniform mat3 bumpMapTransform;\n varying vec2 vBumpMapUv;\n\n#endif\n#ifdef USE_NORMALMAP\n\n uniform mat3 normalMapTransform;\n varying vec2 vNormalMapUv;\n\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\n uniform mat3 displacementMapTransform;\n varying vec2 vDisplacementMapUv;\n\n#endif\n#ifdef USE_EMISSIVEMAP\n\n uniform mat3 emissiveMapTransform;\n varying vec2 vEmissiveMapUv;\n\n#endif\n#ifdef USE_METALNESSMAP\n\n uniform mat3 metalnessMapTransform;\n varying vec2 vMetalnessMapUv;\n\n#endif\n#ifdef USE_ROUGHNESSMAP\n\n uniform mat3 roughnessMapTransform;\n varying vec2 vRoughnessMapUv;\n\n#endif\n#ifdef USE_ANISOTROPYMAP\n\n uniform mat3 anisotropyMapTransform;\n varying vec2 vAnisotropyMapUv;\n\n#endif\n#ifdef USE_CLEARCOATMAP\n\n uniform mat3 clearcoatMapTransform;\n varying vec2 vClearcoatMapUv;\n\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\n uniform mat3 clearcoatNormalMapTransform;\n varying vec2 vClearcoatNormalMapUv;\n\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\n uniform mat3 clearcoatRoughnessMapTransform;\n varying vec2 vClearcoatRoughnessMapUv;\n\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\n uniform mat3 sheenColorMapTransform;\n varying vec2 vSheenColorMapUv;\n\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\n uniform mat3 sheenRoughnessMapTransform;\n varying vec2 vSheenRoughnessMapUv;\n\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\n uniform mat3 iridescenceMapTransform;\n varying vec2 vIridescenceMapUv;\n\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\n uniform mat3 iridescenceThicknessMapTransform;\n varying vec2 vIridescenceThicknessMapUv;\n\n#endif\n#ifdef USE_SPECULARMAP\n\n uniform mat3 specularMapTransform;\n varying vec2 vSpecularMapUv;\n\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\n uniform mat3 specularColorMapTransform;\n varying vec2 vSpecularColorMapUv;\n\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\n uniform mat3 specularIntensityMapTransform;\n varying vec2 vSpecularIntensityMapUv;\n\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\n uniform mat3 transmissionMapTransform;\n varying vec2 vTransmissionMapUv;\n\n#endif\n#ifdef USE_THICKNESSMAP\n\n uniform mat3 thicknessMapTransform;\n varying vec2 vThicknessMapUv;\n\n#endif\n",uv_vertex:"\n#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\n vUv = vec3( uv, 1 ).xy;\n\n#endif\n#ifdef USE_MAP\n\n vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_ALPHAMAP\n\n vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_LIGHTMAP\n\n vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_AOMAP\n\n vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_BUMPMAP\n\n vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_NORMALMAP\n\n vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\n vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_EMISSIVEMAP\n\n vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_METALNESSMAP\n\n vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_ROUGHNESSMAP\n\n vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_ANISOTROPYMAP\n\n vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_CLEARCOATMAP\n\n vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\n vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\n vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\n vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\n vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\n vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\n vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_SPECULARMAP\n\n vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\n vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\n vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\n vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n\n#endif\n#ifdef USE_THICKNESSMAP\n\n vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n\n#endif\n",worldpos_vertex:"\n#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n\n vec4 worldPosition = vec4( transformed, 1.0 );\n\n #ifdef USE_BATCHING\n\n worldPosition = batchingMatrix * worldPosition;\n\n #endif\n\n #ifdef USE_INSTANCING\n\n worldPosition = instanceMatrix * worldPosition;\n\n #endif\n\n worldPosition = modelMatrix * worldPosition;\n\n#endif\n"}),Gi=Object.freeze({tonemapping_pars_fragment:"\n#ifndef saturate\n// <common> may have defined saturate() already\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n\nuniform float toneMappingExposure;\n\n// exposure only\nvec3 LinearToneMapping( vec3 color ) {\n\n return saturate( toneMappingExposure * color );\n\n}\n\n// source: Reinhard et al., Photographic Tone Reproduction for Digital Images (UUCS-02-001, 2002)\nvec3 ReinhardToneMapping( vec3 color ) {\n\n color *= toneMappingExposure;\n return saturate( color / ( vec3( 1.0 ) + color ) );\n\n}\n\n// source: Hable, Filmic Tonemapping Operators (2010)\nvec3 CineonToneMapping( vec3 color ) {\n\n // filmic operator by Jim Hejl and Richard Burgess-Dawson\n color *= toneMappingExposure;\n color = max( vec3( 0.0 ), color - 0.004 );\n return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n\n}\n\n// source: Heitz et al., LTC reference code (ltc_blit.fs)\nvec3 RRTAndODTFit( vec3 v ) {\n\n vec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n return a / b;\n\n}\n\n// this implementation of ACES is modified to accommodate a brighter viewing environment.\n// the scale factor of 1/0.6 is subjective. see discussion in #19621.\n\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\n // sRGB => XYZ => D65_2_D60 => AP1 => RRT_SAT\n const mat3 ACESInputMat = mat3(\n vec3( 0.59719, 0.07600, 0.02840 ), // transposed from source\n vec3( 0.35458, 0.90834, 0.13383 ),\n vec3( 0.04823, 0.01566, 0.83777 )\n );\n\n // ODT_SAT => XYZ => D60_2_D65 => sRGB\n const mat3 ACESOutputMat = mat3(\n vec3( 1.60475, -0.10208, -0.00327 ), // transposed from source\n vec3( -0.53108, 1.10813, -0.07276 ),\n vec3( -0.07367, -0.00605, 1.07602 )\n );\n\n color *= toneMappingExposure / 0.6;\n\n color = ACESInputMat * color;\n\n // Apply RRT and ODT\n color = RRTAndODTFit( color );\n\n color = ACESOutputMat * color;\n\n // Clamp to [0, 1]\n return saturate( color );\n\n}\n\n// Matrices for rec 2020 <> rec 709 color space conversion\n// matrix provided in row-major order so it has been transposed\n// ITU-R Report BT.2407-2017\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n vec3( 1.6605, - 0.1246, - 0.0182 ),\n vec3( - 0.5876, 1.1329, - 0.1006 ),\n vec3( - 0.0728, - 0.0083, 1.1187 )\n);\n\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n vec3( 0.6274, 0.0691, 0.0164 ),\n vec3( 0.3293, 0.9195, 0.0880 ),\n vec3( 0.0433, 0.0113, 0.8956 )\n);\n\n// Wrensch, Minimal AgX Implementation (2023)\n// Mean error^2: 3.6705141e-06\nvec3 agxDefaultContrastApprox( vec3 x ) {\n\n vec3 x2 = x * x;\n vec3 x4 = x2 * x2;\n\n return + 15.5 * x4 * x2\n - 40.14 * x4 * x\n + 31.96 * x4\n - 6.868 * x2 * x\n + 0.4298 * x2\n + 0.1191 * x\n - 0.00232;\n\n}\n\n// AgX Tone Mapping implementation based on Filament, which in turn is based\n// on Blender's implementation using rec 2020 primaries\n// Filament pull request 7236\n// Inputs and outputs are encoded as Linear-sRGB.\n\nvec3 AgXToneMapping( vec3 color ) {\n\n // AgX constants\n const mat3 AgXInsetMatrix = mat3(\n vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n );\n\n // explicit AgXOutsetMatrix generated from Filaments AgXOutsetMatrixInv\n const mat3 AgXOutsetMatrix = mat3(\n vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n );\n\n // LOG2_MIN = -10.0\n // LOG2_MAX = +6.5\n // MIDDLE_GRAY = 0.18\n const float AgxMinEv = - 12.47393; // log2( pow( 2, LOG2_MIN ) * MIDDLE_GRAY )\n const float AgxMaxEv = 4.026069; // log2( pow( 2, LOG2_MAX ) * MIDDLE_GRAY )\n\n color *= toneMappingExposure;\n\n color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\n color = AgXInsetMatrix * color;\n\n // Log2 encoding\n color = max( color, 1e-10 ); // avoid 0 or negative numbers for log2\n color = log2( color );\n color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\n color = clamp( color, 0.0, 1.0 );\n\n // Apply sigmoid\n color = agxDefaultContrastApprox( color );\n\n // Apply AgX look\n // v = agxLook(v, look);\n\n color = AgXOutsetMatrix * color;\n\n // Linearize\n color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\n color = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\n // Gamut mapping. Simple clamp for now.\n color = clamp( color, 0.0, 1.0 );\n\n return color;\n\n}\n\n// model-viewer tone mapping examples\n\nvec3 NeutralToneMapping( vec3 color ) {\n\n const float StartCompression = 0.8 - 0.04;\n const float Desaturation = 0.15;\n\n color *= toneMappingExposure;\n\n float x = min( color.r, min( color.g, color.b ) );\n\n float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\n color -= offset;\n\n float peak = max( color.r, max( color.g, color.b ) );\n\n if ( peak < StartCompression ) return color;\n\n float d = 1. - StartCompression;\n\n float newPeak = 1. - d * d / ( peak + d - StartCompression );\n\n color *= newPeak / peak;\n\n float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\n return mix( color, vec3( newPeak ), g );\n\n}\n\nvec3 CustomToneMapping( vec3 color ) { return color; }\n",colorspace_pars_fragment:"\n\nvec4 LinearTransferOETF( in vec4 value ) {\n return value;\n}\n\nvec4 sRGBTransferEOTF( in vec4 value ) {\n 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 );\n}\n\nvec4 sRGBTransferOETF( in vec4 value ) {\n 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 );\n}\n\n"});var la=new dt,ta=new cn(1,1),ua=new dt,ca=new dt,da=new dt,ra=[],na=[],ia=new Float32Array(16),oa=new Float32Array(9),aa=new Float32Array(4);function Nr(r,e,t){let n=r[0];if(n<=0||n>0)return r;let i=e*t,o=ra[i];if(o===void 0&&(o=new Float32Array(i),ra[i]=o),e!==0){n.toArray(o,0);for(let a=1,s=0;a!==e;++a)s+=t,r[a].toArray(o,s)}return o}function at(r,e){if(r.length!==e.length)return!1;for(let t=0,n=r.length;t<n;t++)if(r[t]!==e[t])return!1;return!0}function st(r,e){for(let t=0,n=e.length;t<n;t++)r[t]=e[t]}function Bn(r,e){let t=na[e];t===void 0&&(t=new Int32Array(e),na[e]=t);for(let n=0;n!==e;++n)t[n]=r.allocateTextureUnit();return t}function Ql(r,e){let t=this.cache;t[0]!==e&&(r.uniform1f(this.addr,e),t[0]=e)}function $l(r,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(r.uniform2f(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(at(t,e))return;r.uniform2fv(this.addr,e),st(t,e)}}function Jl(r,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(r.uniform3f(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else if(e.r!==void 0)(t[0]!==e.r||t[1]!==e.g||t[2]!==e.b)&&(r.uniform3f(this.addr,e.r,e.g,e.b),t[0]=e.r,t[1]=e.g,t[2]=e.b);else{if(at(t,e))return;r.uniform3fv(this.addr,e),st(t,e)}}function eu(r,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(r.uniform4f(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(at(t,e))return;r.uniform4fv(this.addr,e),st(t,e)}}function tu(r,e){let t=this.cache,n=e.elements;if(n===void 0){if(at(t,e))return;r.uniformMatrix2fv(this.addr,!1,e),st(t,e)}else{if(at(t,n))return;aa.set(n),r.uniformMatrix2fv(this.addr,!1,aa),st(t,n)}}function ru(r,e){let t=this.cache,n=e.elements;if(n===void 0){if(at(t,e))return;r.uniformMatrix3fv(this.addr,!1,e),st(t,e)}else{if(at(t,n))return;oa.set(n),r.uniformMatrix3fv(this.addr,!1,oa),st(t,n)}}function nu(r,e){let t=this.cache,n=e.elements;if(n===void 0){if(at(t,e))return;r.uniformMatrix4fv(this.addr,!1,e),st(t,e)}else{if(at(t,n))return;ia.set(n),r.uniformMatrix4fv(this.addr,!1,ia),st(t,n)}}function iu(r,e){let t=this.cache;t[0]!==e&&(r.uniform1i(this.addr,e),t[0]=e)}function ou(r,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(r.uniform2i(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(at(t,e))return;r.uniform2iv(this.addr,e),st(t,e)}}function au(r,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(r.uniform3i(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else{if(at(t,e))return;r.uniform3iv(this.addr,e),st(t,e)}}function su(r,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(r.uniform4i(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(at(t,e))return;r.uniform4iv(this.addr,e),st(t,e)}}function lu(r,e){let t=this.cache;t[0]!==e&&(r.uniform1ui(this.addr,e),t[0]=e)}function uu(r,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y)&&(r.uniform2ui(this.addr,e.x,e.y),t[0]=e.x,t[1]=e.y);else{if(at(t,e))return;r.uniform2uiv(this.addr,e),st(t,e)}}function cu(r,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z)&&(r.uniform3ui(this.addr,e.x,e.y,e.z),t[0]=e.x,t[1]=e.y,t[2]=e.z);else{if(at(t,e))return;r.uniform3uiv(this.addr,e),st(t,e)}}function du(r,e){let t=this.cache;if(e.x!==void 0)(t[0]!==e.x||t[1]!==e.y||t[2]!==e.z||t[3]!==e.w)&&(r.uniform4ui(this.addr,e.x,e.y,e.z,e.w),t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=e.w);else{if(at(t,e))return;r.uniform4uiv(this.addr,e),st(t,e)}}function hu(r,e,t){let n=this.cache,i=t.allocateTextureUnit();n[0]!==i&&(r.uniform1i(this.addr,i),n[0]=i);let o;this.type===r.SAMPLER_2D_SHADOW?(ta.compareFunction="less-equal",o=ta):o=la,t.setTexture2D(e||o,i)}function mu(r,e,t){let n=this.cache,i=t.allocateTextureUnit();n[0]!==i&&(r.uniform1i(this.addr,i),n[0]=i),t.setTexture3D?.(e||ca,i)}function fu(r,e,t){let n=this.cache,i=t.allocateTextureUnit();n[0]!==i&&(r.uniform1i(this.addr,i),n[0]=i),t.setTextureCube?.(e||da,i)}function pu(r,e,t){let n=this.cache,i=t.allocateTextureUnit();n[0]!==i&&(r.uniform1i(this.addr,i),n[0]=i),t.setTexture2DArray?.(e||ua,i)}function gu(r){switch(r){case 5126:return Ql;case 35664:return $l;case 35665:return Jl;case 35666:return eu;case 35674:return tu;case 35675:return ru;case 35676:return nu;case 5124:case 35670:return iu;case 35667:case 35671:return ou;case 35668:case 35672:return au;case 35669:case 35673:return su;case 5125:return lu;case 36294:return uu;case 36295:return cu;case 36296:return du;case 35678:case 36198:case 36298:case 36306:case 35682:return hu;case 35679:case 36299:case 36307:return mu;case 35680:case 36300:case 36308:case 36293:return fu;case 36289:case 36303:case 36311:case 36292:return pu}}function bu(r,e){r.uniform1fv(this.addr,e)}function xu(r,e){let t=Nr(e,this.size,2);r.uniform2fv(this.addr,t)}function vu(r,e){let t=Nr(e,this.size,3);r.uniform3fv(this.addr,t)}function yu(r,e){let t=Nr(e,this.size,4);r.uniform4fv(this.addr,t)}function Mu(r,e){let t=Nr(e,this.size,4);r.uniformMatrix2fv(this.addr,!1,t)}function Su(r,e){let t=Nr(e,this.size,9);r.uniformMatrix3fv(this.addr,!1,t)}function _u(r,e){let t=Nr(e,this.size,16);r.uniformMatrix4fv(this.addr,!1,t)}function Tu(r,e){r.uniform1iv(this.addr,e)}function Au(r,e){r.uniform2iv(this.addr,e)}function Eu(r,e){r.uniform3iv(this.addr,e)}function wu(r,e){r.uniform4iv(this.addr,e)}function Cu(r,e){r.uniform1uiv(this.addr,e)}function Lu(r,e){r.uniform2uiv(this.addr,e)}function Ru(r,e){r.uniform3uiv(this.addr,e)}function Pu(r,e){r.uniform4uiv(this.addr,e)}function Uu(r,e,t){let n=this.cache,i=e.length,o=Bn(t,i);at(n,o)||(r.uniform1iv(this.addr,o),st(n,o));for(let a=0;a!==i;++a)t.setTexture2D(e[a]||la,o[a])}function Iu(r,e,t){let n=this.cache,i=e.length,o=Bn(t,i);at(n,o)||(r.uniform1iv(this.addr,o),st(n,o));for(let a=0;a!==i;++a)t.setTexture3D?.(e[a]||ca,o[a])}function Du(r,e,t){let n=this.cache,i=e.length,o=Bn(t,i);at(n,o)||(r.uniform1iv(this.addr,o),st(n,o));for(let a=0;a!==i;++a)t.setTextureCube?.(e[a]||da,o[a])}function Fu(r,e,t){let n=this.cache,i=e.length,o=Bn(t,i);at(n,o)||(r.uniform1iv(this.addr,o),st(n,o));for(let a=0;a!==i;++a)t.setTexture2DArray?.(e[a]||ua,o[a])}function Nu(r){switch(r){case 5126:return bu;case 35664:return xu;case 35665:return vu;case 35666:return yu;case 35674:return Mu;case 35675:return Su;case 35676:return _u;case 5124:case 35670:return Tu;case 35667:case 35671:return Au;case 35668:case 35672:return Eu;case 35669:case 35673:return wu;case 5125:return Cu;case 36294:return Lu;case 36295:return Ru;case 36296:return Pu;case 35678:case 36198:case 36298:case 36306:case 35682:return Uu;case 35679:case 36299:case 36307:return Iu;case 35680:case 36300:case 36308:case 36293:return Du;case 36289:case 36303:case 36311:case 36292:return Fu}}var Wi=class{id;addr;cache;type;setValue;constructor(e,t,n){this.id=e,this.addr=n,this.cache=[],this.type=t.type,this.setValue=gu(t.type)}},Xi=class{id;addr;cache;type;size;setValue;constructor(e,t,n){this.id=e,this.addr=n,this.cache=[],this.type=t.type,this.size=t.size,this.setValue=Nu(t.type)}},qi=class{id;seq;map;constructor(e){this.id=e,this.seq=[],this.map={}}setValue(e,t,n){let i=this.seq;for(let o=0,a=i.length;o!==a;++o){let s=i[o];s.setValue(e,t[s.id],n)}}},Hi=/(\w+)(\])?(\[|\.)?/g;function sa(r,e){r.seq.push(e),r.map[e.id]=e}function Vu(r,e,t){let n=r.name,i=n.length;for(Hi.lastIndex=0;;){let o=Hi.exec(n),a=Hi.lastIndex,s=o[1],l=o[2]==="]",c=o[3];if(l&&(s=s|0),c===void 0||c==="["&&a+2===i){sa(t,c===void 0?new Wi(s,r,e):new Xi(s,r,e));break}else{let u=t.map[s];u===void 0&&(u=new qi(s),sa(t,u)),t=u}}}function ha(r,e){let t={seq:[],map:{},setValue(i,o,a,s){let l=t.map[o];l!==void 0&&l.setValue(i,a,s)},setOptional(i,o,a){let s=o[a];s!==void 0&&t.setValue(i,a,s)}},n=r.getProgramParameter(e,r.ACTIVE_UNIFORMS);for(let i=0;i<n;++i){let o=r.getActiveUniform(e,i),a=r.getUniformLocation(e,o.name);Vu(o,a,t)}return t}function Yi(r,e,t,n){for(let i=0,o=e.length;i!==o;++i){let a=e[i],s=t[a.id];s.needsUpdate!==!1&&a.setValue(r,s.value,n)}}function ma(r,e){let t=[];for(let n=0,i=r.length;n!==i;++n){let o=r[n];o.id in e&&t.push(o)}return t}var Ou=37297,ku=0;function zu(r,e){let t=r.split("\n"),n=[],i=Math.max(e-6,0),o=Math.min(e+6,t.length);for(let a=i;a<o;a++){let s=a+1;n.push("".concat(s===e?">":" "," ").concat(s,": ").concat(t[a]))}return n.join("\n")}var fa=new rt;function Bu(r){Ne._getMatrix(fa,Ne.workingColorSpace,r);let e="mat3( ".concat(fa.elements.map(t=>t.toFixed(4))," )");switch(Ne.getTransfer(r)){case"linear":return[e,"LinearTransferOETF"];case"srgb":return[e,"sRGBTransferOETF"];default:return console.warn("keel/lit program: Unsupported color space: ",r),[e,"LinearTransferOETF"]}}function pa(r,e,t){let n=r.getShaderParameter(e,r.COMPILE_STATUS),o=(r.getShaderInfoLog(e)||"").trim();if(n&&o==="")return"";let a=/ERROR: 0:(\d+)/.exec(o);if(a){let s=parseInt(a[1]);return t.toUpperCase()+"\n\n"+o+"\n\n"+zu(r.getShaderSource(e)??"",s)}else return o}function Gu(r,e){let t=Bu(e);return["vec4 ".concat(r,"( vec4 value ) {")," return ".concat(t[1],"( vec4( value.rgb * ").concat(t[0],", value.a ) );"),"}"].join("\n")}function Hu(r,e){let t;switch(e){case"linear":t="Linear";break;case"reinhard":t="Reinhard";break;case"cineon":t="Cineon";break;case"aces-filmic":t="ACESFilmic";break;case"agx":t="AgX";break;case"neutral":t="Neutral";break;case"custom":t="Custom";break;default:console.warn("keel/lit program: Unsupported toneMapping:",e),t="Linear"}return"vec3 "+r+"( vec3 color ) { return "+t+"ToneMapping( color ); }"}var Gn=new L;function Wu(){Ne.getLuminanceCoefficients(Gn);let r=Gn.x.toFixed(4),e=Gn.y.toFixed(4),t=Gn.z.toFixed(4);return["float luminance( const in vec3 rgb ) {"," const vec3 weights = vec3( ".concat(r,", ").concat(e,", ").concat(t," );")," return dot( weights, rgb );","}"].join("\n")}function Xu(r){return[r.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":"",r.extensionMultiDraw?"#extension GL_ANGLE_multi_draw : require":""].filter(hn).join("\n")}function qu(r){let e=[];for(let t in r){let n=r[t];n!==!1&&e.push("#define "+t+" "+String(n))}return e.join("\n")}function Yu(r,e){let t={},n=r.getProgramParameter(e,r.ACTIVE_ATTRIBUTES);for(let i=0;i<n;i++){let o=r.getActiveAttrib(e,i),a=o.name,s=1;o.type===r.FLOAT_MAT2&&(s=2),o.type===r.FLOAT_MAT3&&(s=3),o.type===r.FLOAT_MAT4&&(s=4),t[a]={type:o.type,location:r.getAttribLocation(e,a),locationSize:s}}return t}function hn(r){return r!==""}function ga(r,e){let t=e.numSpotLightShadows+e.numSpotLightMaps-e.numSpotLightShadowsWithMaps;return r.replace(/NUM_DIR_LIGHTS/g,String(e.numDirLights)).replace(/NUM_SPOT_LIGHTS/g,String(e.numSpotLights)).replace(/NUM_SPOT_LIGHT_MAPS/g,String(e.numSpotLightMaps)).replace(/NUM_SPOT_LIGHT_COORDS/g,String(t)).replace(/NUM_RECT_AREA_LIGHTS/g,String(e.numRectAreaLights)).replace(/NUM_POINT_LIGHTS/g,String(e.numPointLights)).replace(/NUM_HEMI_LIGHTS/g,String(e.numHemiLights)).replace(/NUM_DIR_LIGHT_SHADOWS/g,String(e.numDirLightShadows)).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,String(e.numSpotLightShadowsWithMaps)).replace(/NUM_SPOT_LIGHT_SHADOWS/g,String(e.numSpotLightShadows)).replace(/NUM_POINT_LIGHT_SHADOWS/g,String(e.numPointLightShadows))}function ba(r,e){return r.replace(/NUM_CLIPPING_PLANES/g,String(e.numClippingPlanes)).replace(/UNION_CLIPPING_PLANES/g,String(e.numClippingPlanes-e.numClipIntersection))}var ju=/^[ \t]*#include +<([\w\d./]+)>/gm;function ji(r){return r.replace(ju,Ku)}var Zu=new Map;function Ku(r,e){let t=Bi[e];if(t===void 0){let n=Zu.get(e);if(n!==void 0)t=Bi[n],console.warn('keel/lit renderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',e,n);else throw new Error("Can not resolve #include <"+e+">")}return ji(t)}var Qu=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function xa(r){return r.replace(Qu,$u)}function $u(r,e,t,n){let i="";for(let o=parseInt(e);o<parseInt(t);o++)i+=n.replace(/\[\s*i\s*\]/g,"[ "+o+" ]").replace(/UNROLLED_LOOP_INDEX/g,String(o));return i}function va(r){let e="precision ".concat(r.precision," float;\n precision ").concat(r.precision," int;\n precision ").concat(r.precision," sampler2D;\n precision ").concat(r.precision," samplerCube;\n precision ").concat(r.precision," sampler3D;\n precision ").concat(r.precision," sampler2DArray;\n precision ").concat(r.precision," sampler2DShadow;\n precision ").concat(r.precision," samplerCubeShadow;\n precision ").concat(r.precision," sampler2DArrayShadow;\n precision ").concat(r.precision," isampler2D;\n precision ").concat(r.precision," isampler3D;\n precision ").concat(r.precision," isamplerCube;\n precision ").concat(r.precision," isampler2DArray;\n precision ").concat(r.precision," usampler2D;\n precision ").concat(r.precision," usampler3D;\n precision ").concat(r.precision," usamplerCube;\n precision ").concat(r.precision," usampler2DArray;\n ");return r.precision==="highp"?e+="\n#define HIGH_PRECISION":r.precision==="mediump"?e+="\n#define MEDIUM_PRECISION":r.precision==="lowp"&&(e+="\n#define LOW_PRECISION"),e}function Ju(r){let e="SHADOWMAP_TYPE_BASIC";return r.shadowMapType==="pcf"?e="SHADOWMAP_TYPE_PCF":r.shadowMapType==="pcf-soft"?e="SHADOWMAP_TYPE_PCF_SOFT":r.shadowMapType==="vsm"&&(e="SHADOWMAP_TYPE_VSM"),e}function ec(r){let e="ENVMAP_TYPE_CUBE";if(r.envMap)switch(r.envMapMode){case"cube-reflection":case"cube-refraction":e="ENVMAP_TYPE_CUBE";break;case"cube-uv-reflection":e="ENVMAP_TYPE_CUBE_UV";break}return e}function tc(r){let e="ENVMAP_MODE_REFLECTION";return r.envMap&&r.envMapMode==="cube-refraction"&&(e="ENVMAP_MODE_REFRACTION"),e}function rc(r){let e="ENVMAP_BLENDING_NONE";if(r.envMap)switch(r.combine){case"multiply":e="ENVMAP_BLENDING_MULTIPLY";break;case"mix":e="ENVMAP_BLENDING_MIX";break;case"add":e="ENVMAP_BLENDING_ADD";break}return e}function nc(r){let e=r.envMapCubeUVHeight;if(e===null)return null;let t=Math.log2(e)-2,n=1/e;return{texelWidth:1/(3*Math.max(Math.pow(2,t),112)),texelHeight:n,maxMip:t}}function ya(r,e,t){let n=r.createShader(e);return r.shaderSource(n,t),r.compileShader(n),n}function Ma(r,e,t,n){let i=r.getContext(),o=t.defines,a=t.vertexShader,s=t.fragmentShader,l=Ju(t),c=ec(t),d=tc(t),u=rc(t),h=nc(t),m=Xu(t),f=qu(o),g=i.createProgram(),v,M,T=t.glslVersion?"#version "+t.glslVersion+"\n":"";t.isRawShaderMaterial?(v=["#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,f].filter(hn).join("\n"),v.length>0&&(v+="\n"),M=["#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,f].filter(hn).join("\n"),M.length>0&&(M+="\n")):(v=[va(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,f,t.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",t.batching?"#define USE_BATCHING":"",t.batchingColor?"#define USE_BATCHING_COLOR":"",t.instancing?"#define USE_INSTANCING":"",t.instancingColor?"#define USE_INSTANCING_COLOR":"",t.instancingMorph?"#define USE_INSTANCING_MORPH":"",t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.map?"#define USE_MAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+d:"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",t.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",t.displacementMap?"#define USE_DISPLACEMENTMAP":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.anisotropy?"#define USE_ANISOTROPY":"",t.anisotropyMap?"#define USE_ANISOTROPYMAP":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",t.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",t.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaHash?"#define USE_ALPHAHASH":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",t.mapUv?"#define MAP_UV "+t.mapUv:"",t.alphaMapUv?"#define ALPHAMAP_UV "+t.alphaMapUv:"",t.lightMapUv?"#define LIGHTMAP_UV "+t.lightMapUv:"",t.aoMapUv?"#define AOMAP_UV "+t.aoMapUv:"",t.emissiveMapUv?"#define EMISSIVEMAP_UV "+t.emissiveMapUv:"",t.bumpMapUv?"#define BUMPMAP_UV "+t.bumpMapUv:"",t.normalMapUv?"#define NORMALMAP_UV "+t.normalMapUv:"",t.displacementMapUv?"#define DISPLACEMENTMAP_UV "+t.displacementMapUv:"",t.metalnessMapUv?"#define METALNESSMAP_UV "+t.metalnessMapUv:"",t.roughnessMapUv?"#define ROUGHNESSMAP_UV "+t.roughnessMapUv:"",t.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+t.anisotropyMapUv:"",t.clearcoatMapUv?"#define CLEARCOATMAP_UV "+t.clearcoatMapUv:"",t.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+t.clearcoatNormalMapUv:"",t.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+t.clearcoatRoughnessMapUv:"",t.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+t.iridescenceMapUv:"",t.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+t.iridescenceThicknessMapUv:"",t.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+t.sheenColorMapUv:"",t.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+t.sheenRoughnessMapUv:"",t.specularMapUv?"#define SPECULARMAP_UV "+t.specularMapUv:"",t.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+t.specularColorMapUv:"",t.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+t.specularIntensityMapUv:"",t.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+t.transmissionMapUv:"",t.thicknessMapUv?"#define THICKNESSMAP_UV "+t.thicknessMapUv:"",t.vertexTangents&&t.flatShading===!1?"#define USE_TANGENT":"",t.vertexColors?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUv1s?"#define USE_UV1":"",t.vertexUv2s?"#define USE_UV2":"",t.vertexUv3s?"#define USE_UV3":"",t.pointsUvs?"#define USE_POINTS_UV":"",t.flatShading?"#define FLAT_SHADED":"",t.skinning?"#define USE_SKINNING":"",t.morphTargets?"#define USE_MORPHTARGETS":"",t.morphNormals&&t.flatShading===!1?"#define USE_MORPHNORMALS":"",t.morphColors?"#define USE_MORPHCOLORS":"",t.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+t.morphTextureStride:"",t.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+t.morphTargetsCount:"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+l:"",t.sizeAttenuation?"#define USE_SIZEATTENUATION":"",t.numLightProbes>0?"#define USE_LIGHT_PROBES":"",t.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",t.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING"," attribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR"," attribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH"," uniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1"," attribute vec2 uv1;","#endif","#ifdef USE_UV2"," attribute vec2 uv2;","#endif","#ifdef USE_UV3"," attribute vec2 uv3;","#endif","#ifdef USE_TANGENT"," attribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )"," attribute vec4 color;","#elif defined( USE_COLOR )"," attribute vec3 color;","#endif","#ifdef USE_SKINNING"," attribute vec4 skinIndex;"," attribute vec4 skinWeight;","#endif","\n"].filter(hn).join("\n"),M=[va(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,f,t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",t.map?"#define USE_MAP":"",t.matcap?"#define USE_MATCAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+c:"",t.envMap?"#define "+d:"",t.envMap?"#define "+u:"",h?"#define CUBEUV_TEXEL_WIDTH "+h.texelWidth:"",h?"#define CUBEUV_TEXEL_HEIGHT "+h.texelHeight:"",h?"#define CUBEUV_MAX_MIP "+h.maxMip+".0":"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",t.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.anisotropy?"#define USE_ANISOTROPY":"",t.anisotropyMap?"#define USE_ANISOTROPYMAP":"",t.clearcoat?"#define USE_CLEARCOAT":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.dispersion?"#define USE_DISPERSION":"",t.iridescence?"#define USE_IRIDESCENCE":"",t.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",t.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",t.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaTest?"#define USE_ALPHATEST":"",t.alphaHash?"#define USE_ALPHAHASH":"",t.sheen?"#define USE_SHEEN":"",t.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.vertexTangents&&t.flatShading===!1?"#define USE_TANGENT":"",t.vertexColors||t.instancingColor||t.batchingColor?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUv1s?"#define USE_UV1":"",t.vertexUv2s?"#define USE_UV2":"",t.vertexUv3s?"#define USE_UV3":"",t.pointsUvs?"#define USE_POINTS_UV":"",t.gradientMap?"#define USE_GRADIENTMAP":"",t.flatShading?"#define FLAT_SHADED":"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+l:"",t.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",t.numLightProbes>0?"#define USE_LIGHT_PROBES":"",t.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",t.decodeVideoTextureEmissive?"#define DECODE_VIDEO_TEXTURE_EMISSIVE":"",t.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",t.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",t.toneMapping!=="none"?"#define TONE_MAPPING":"",t.toneMapping!=="none"?Gi.tonemapping_pars_fragment:"",t.toneMapping!=="none"?Hu("toneMapping",t.toneMapping):"",t.dithering?"#define DITHERING":"",t.opaque?"#define OPAQUE":"",Gi.colorspace_pars_fragment,Gu("linearToOutputTexel",t.outputColorSpace),Wu(),t.useDepthPacking?"#define DEPTH_PACKING "+t.depthPacking:"","\n"].filter(hn).join("\n")),a=ji(a),a=ga(a,t),a=ba(a,t),s=ji(s),s=ga(s,t),s=ba(s,t),a=xa(a),s=xa(s),t.isRawShaderMaterial!==!0&&(T="#version 300 es\n",v=[m,"#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+v,M=["#define varying in",t.glslVersion==="300 es"?"":"layout(location = 0) out highp vec4 pc_fragColor;",t.glslVersion==="300 es"?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join("\n")+"\n"+M);let _=T+v+a,A=T+M+s,U=ya(i,i.VERTEX_SHADER,_),w=ya(i,i.FRAGMENT_SHADER,A);i.attachShader(g,U),i.attachShader(g,w),t.index0AttributeName!==void 0?i.bindAttribLocation(g,0,t.index0AttributeName):t.morphTargets===!0&&i.bindAttribLocation(g,0,"position"),i.linkProgram(g);function E(F){if(r.debug.checkShaderErrors){let G=i.getProgramInfoLog(g)||"",B=i.getShaderInfoLog(U)||"",Z=i.getShaderInfoLog(w)||"",re=G.trim(),oe=B.trim(),Y=Z.trim(),ae=!0,he=!0;if(i.getProgramParameter(g,i.LINK_STATUS)===!1)if(ae=!1,typeof r.debug.onShaderError=="function")r.debug.onShaderError(i,g,U,w);else{let me=pa(i,U,"vertex"),Ue=pa(i,w,"fragment");console.error("keel/lit program: Shader Error "+i.getError()+" - VALIDATE_STATUS "+String(i.getProgramParameter(g,i.VALIDATE_STATUS))+"\n\nMaterial Name: "+F.name+"\nMaterial Type: "+F.type+"\n\nProgram Info Log: "+re+"\n"+me+"\n"+Ue)}else re!==""?console.warn("keel/lit program: Program Info Log:",re):(oe===""||Y==="")&&(he=!1);he&&(F.diagnostics={runnable:ae,programLog:re,vertexShader:{log:oe,prefix:v},fragmentShader:{log:Y,prefix:M}})}i.deleteShader(U),i.deleteShader(w),p=ha(i,g),y=Yu(i,g)}let p,y,R=t.rendererExtensionParallelShaderCompile===!1,D={getUniforms(){return p===void 0&&E(D),p},getAttributes(){return y===void 0&&E(D),y},isReady(){return R===!1&&(R=i.getProgramParameter(g,Ou)),R},destroy(){n.releaseStatesOfProgram(D),i.deleteProgram(g),D.program=void 0},type:t.shaderType,name:t.shaderName,id:ku++,cacheKey:e,usedTimes:1,program:g,vertexShader:U,fragmentShader:w};return D}var ic=0;function oc(r){return{id:ic++,code:r,usedTimes:0}}function Sa(){let r=new Map,e=new Map,t={shaderCache:r,materialCache:e,update(n){let i=n.vertexShader,o=n.fragmentShader,a=t._getShaderStage(i),s=t._getShaderStage(o),l=t._getShaderCacheForMaterial(n);return l.has(a)===!1&&(l.add(a),a.usedTimes++),l.has(s)===!1&&(l.add(s),s.usedTimes++),t},remove(n){let i=e.get(n);if(i!==void 0)for(let o of i)o.usedTimes--,o.usedTimes===0&&r.delete(o.code);return e.delete(n),t},getVertexShaderID(n){return t._getShaderStage(n.vertexShader).id},getFragmentShaderID(n){return t._getShaderStage(n.fragmentShader).id},dispose(){r.clear(),e.clear()},_getShaderCacheForMaterial(n){let i=e,o=i.get(n);return o===void 0&&(o=new Set,i.set(n,o)),o},_getShaderStage(n){let i=r,o=i.get(n);return o===void 0&&(o=oc(n),i.set(n,o)),o}};return t}var _a={DepthMaterial:"depth",DistanceMaterial:"distance",FlatMaterial:"flat",ToonMaterial:"toon",LitMaterial:"lit",BillboardMaterial:"billboard"},ac=Object.freeze({LitMaterial:"MeshStandardMaterial",ToonMaterial:"MeshToonMaterial",FlatMaterial:"MeshBasicMaterial",BillboardMaterial:"SpriteMaterial",CustomMaterial:"ShaderMaterial",DepthMaterial:"MeshDepthMaterial",DistanceMaterial:"MeshDistanceMaterial"}),sc={color:r=>new Pe(r),vec2:(r,e)=>new W(r,e),vec3:(r,e,t)=>new L(r,e,t),mat3:()=>new rt,mat4:()=>new Ve};function Ta(r,e,t,n,i,o,a){let s=new hr,l=Sa(),c=new Set,d=[],u=i.logarithmicDepthBuffer,h=i.vertexTextures,m=i.precision;function f(p){return c.add(p),p===0?"uv":"uv".concat(p)}function g(p,y,R,D,F){let G=D.fog,B=F.geometry,Z=p.isMeshStandardMaterial?D.environment:null,re=(p.isMeshStandardMaterial?t:e).get(p.envMap||Z),oe=re&&re.mapping==="cube-uv-reflection"?re.image.height:null,Y=_a[p.type];p.precision!==null&&(m=i.getMaxPrecision(p.precision),m!==p.precision&&console.warn("keel/lit programs.getParameters:",p.precision,"not supported, using",m,"instead."));let ae=B.morphAttributes.position||B.morphAttributes.normal||B.morphAttributes.color,he=ae!==void 0?ae.length:0,me=0;B.morphAttributes.position!==void 0&&(me=1),B.morphAttributes.normal!==void 0&&(me=2),B.morphAttributes.color!==void 0&&(me=3);let Ue,Ge,ze,ot;if(Y){let ke=zi[Y];Ue=ke.vertexShader,Ge=ke.fragmentShader}else{Ue=p.vertexShader,Ge=p.fragmentShader;let ke=p;l.update(ke),ze=l.getVertexShaderID(ke),ot=l.getFragmentShaderID(ke)}let je=r.getRenderTarget(),Fe=r.state.buffers.depth.getReversed(),Be=F.isInstancedMesh===!0,He=F.isBatchedMesh===!0,lt=!!p.map,Nt=!!p.matcap,J=!!re,Je=!!p.aoMap,H=!!p.lightMap,ee=!!p.bumpMap,k=!!p.normalMap,te=!!p.displacementMap,j=!!p.emissiveMap,ue=!!p.metalnessMap,ce=!!p.roughnessMap,Ae=p.anisotropy>0,_e=p.clearcoat>0,S=p.dispersion>0,b=p.iridescence>0,P=p.sheen>0,X=p.transmission>0,K=Ae&&!!p.anisotropyMap,N=_e&&!!p.clearcoatMap,Q=_e&&!!p.clearcoatNormalMap,pe=_e&&!!p.clearcoatRoughnessMap,be=b&&!!p.iridescenceMap,Oe=b&&!!p.iridescenceThicknessMap,ie=P&&!!p.sheenColorMap,Te=P&&!!p.sheenRoughnessMap,Ee=!!p.specularMap,q=!!p.specularColorMap,We=!!p.specularIntensityMap,et=X&&!!p.transmissionMap,ut=X&&!!p.thicknessMap,C=!!p.gradientMap,$=!!p.alphaMap,se=p.alphaTest>0,le=!!p.alphaHash,ye=!!p.extensions,ge="none";p.toneMapped&&(je===null||je.isXRRenderTarget===!0)&&(ge=r.toneMapping);let De={shaderID:Y,shaderType:ac[p.type]??p.type,shaderName:p.name,vertexShader:Ue,fragmentShader:Ge,defines:p.defines,customVertexShaderID:ze,customFragmentShaderID:ot,isRawShaderMaterial:p.isRawShaderMaterial===!0,glslVersion:p.glslVersion,precision:m,batching:He,batchingColor:He&&F._colorsTexture!==null,instancing:Be,instancingColor:Be&&F.instanceColor!==null,instancingMorph:Be&&F.morphTexture!==null,supportsVertexTextures:h,outputColorSpace:je===null?r.outputColorSpace:je.isXRRenderTarget===!0?je.texture.colorSpace:"linear",alphaToCoverage:!!p.alphaToCoverage,map:lt,matcap:Nt,envMap:J,envMapMode:J&&re.mapping,envMapCubeUVHeight:oe,aoMap:Je,lightMap:H,bumpMap:ee,normalMap:k,displacementMap:h&&te,emissiveMap:j,normalMapObjectSpace:k&&p.normalMapType==="object",normalMapTangentSpace:k&&p.normalMapType==="tangent",metalnessMap:ue,roughnessMap:ce,anisotropy:Ae,anisotropyMap:K,clearcoat:_e,clearcoatMap:N,clearcoatNormalMap:Q,clearcoatRoughnessMap:pe,dispersion:S,iridescence:b,iridescenceMap:be,iridescenceThicknessMap:Oe,sheen:P,sheenColorMap:ie,sheenRoughnessMap:Te,specularMap:Ee,specularColorMap:q,specularIntensityMap:We,transmission:X,transmissionMap:et,thicknessMap:ut,gradientMap:C,opaque:p.transparent===!1&&p.blending==="normal"&&p.alphaToCoverage===!1,alphaMap:$,alphaTest:se,alphaHash:le,combine:p.combine,mapUv:lt&&f(p.map.channel),aoMapUv:Je&&f(p.aoMap.channel),lightMapUv:H&&f(p.lightMap.channel),bumpMapUv:ee&&f(p.bumpMap.channel),normalMapUv:k&&f(p.normalMap.channel),displacementMapUv:te&&f(p.displacementMap.channel),emissiveMapUv:j&&f(p.emissiveMap.channel),metalnessMapUv:ue&&f(p.metalnessMap.channel),roughnessMapUv:ce&&f(p.roughnessMap.channel),anisotropyMapUv:K&&f(p.anisotropyMap.channel),clearcoatMapUv:N&&f(p.clearcoatMap.channel),clearcoatNormalMapUv:Q&&f(p.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:pe&&f(p.clearcoatRoughnessMap.channel),iridescenceMapUv:be&&f(p.iridescenceMap.channel),iridescenceThicknessMapUv:Oe&&f(p.iridescenceThicknessMap.channel),sheenColorMapUv:ie&&f(p.sheenColorMap.channel),sheenRoughnessMapUv:Te&&f(p.sheenRoughnessMap.channel),specularMapUv:Ee&&f(p.specularMap.channel),specularColorMapUv:q&&f(p.specularColorMap.channel),specularIntensityMapUv:We&&f(p.specularIntensityMap.channel),transmissionMapUv:et&&f(p.transmissionMap.channel),thicknessMapUv:ut&&f(p.thicknessMap.channel),alphaMapUv:$&&f(p.alphaMap.channel),vertexTangents:!!B.attributes.tangent&&(k||Ae),vertexColors:p.vertexColors,vertexAlphas:p.vertexColors===!0&&!!B.attributes.color&&B.attributes.color.itemSize===4,pointsUvs:F.isPoints===!0&&!!B.attributes.uv&&(lt||$),fog:!!G,useFog:p.fog===!0,fogExp2:!!G&&G.isFogExp2,flatShading:p.flatShading===!0&&p.wireframe===!1,sizeAttenuation:p.sizeAttenuation===!0,logarithmicDepthBuffer:u,reversedDepthBuffer:Fe,skinning:F.isSkinnedMesh===!0,morphTargets:B.morphAttributes.position!==void 0,morphNormals:B.morphAttributes.normal!==void 0,morphColors:B.morphAttributes.color!==void 0,morphTargetsCount:he,morphTextureStride:me,numDirLights:y.directional.length,numPointLights:y.point.length,numSpotLights:y.spot.length,numSpotLightMaps:y.spotLightMap.length,numRectAreaLights:y.rectArea.length,numHemiLights:y.hemi.length,numDirLightShadows:y.directionalShadowMap.length,numPointLightShadows:y.pointShadowMap.length,numSpotLightShadows:y.spotShadowMap.length,numSpotLightShadowsWithMaps:y.numSpotLightShadowsWithMaps,numLightProbes:y.numLightProbes,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,dithering:p.dithering,shadowMapEnabled:r.shadowMap.enabled&&R.length>0,shadowMapType:r.shadowMap.type,toneMapping:ge,decodeVideoTexture:lt&&p.map.isVideoTexture===!0&&Ne.getTransfer(p.map.colorSpace)==="srgb",decodeVideoTextureEmissive:j&&p.emissiveMap.isVideoTexture===!0&&Ne.getTransfer(p.emissiveMap.colorSpace)==="srgb",premultipliedAlpha:p.premultipliedAlpha,doubleSided:p.side==="both",flipSided:p.side==="back",useDepthPacking:p.depthPacking!==void 0&&dr.depthPacking[p.depthPacking]>=0,depthPacking:(p.depthPacking!==void 0?dr.depthPacking[p.depthPacking]:0)||0,index0AttributeName:p.index0AttributeName,extensionClipCullDistance:ye&&p.extensions.clipCullDistance===!0&&n.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(ye&&p.extensions.multiDraw===!0||He)&&n.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:n.has("KHR_parallel_shader_compile"),customProgramCacheKey:p.customProgramCacheKey(),vertexUv1s:!1,vertexUv2s:!1,vertexUv3s:!1};return De.vertexUv1s=c.has(1),De.vertexUv2s=c.has(2),De.vertexUv3s=c.has(3),c.clear(),De}function v(p){let y=[];if(p.shaderID?y.push(p.shaderID):(y.push(p.customVertexShaderID),y.push(p.customFragmentShaderID)),p.defines!==void 0)for(let R in p.defines)y.push(R),y.push(p.defines[R]);return p.isRawShaderMaterial===!1&&(M(y,p),T(y,p),y.push(ni[r.outputColorSpace])),y.push(p.customProgramCacheKey),y.join()}function M(p,y){p.push(y.precision),p.push(ni[y.outputColorSpace]),p.push(y.envMapMode?dr.mapping[y.envMapMode]:y.envMapMode),p.push(y.envMapCubeUVHeight),p.push(y.mapUv),p.push(y.alphaMapUv),p.push(y.lightMapUv),p.push(y.aoMapUv),p.push(y.bumpMapUv),p.push(y.normalMapUv),p.push(y.displacementMapUv),p.push(y.emissiveMapUv),p.push(y.metalnessMapUv),p.push(y.roughnessMapUv),p.push(y.anisotropyMapUv),p.push(y.clearcoatMapUv),p.push(y.clearcoatNormalMapUv),p.push(y.clearcoatRoughnessMapUv),p.push(y.iridescenceMapUv),p.push(y.iridescenceThicknessMapUv),p.push(y.sheenColorMapUv),p.push(y.sheenRoughnessMapUv),p.push(y.specularMapUv),p.push(y.specularColorMapUv),p.push(y.specularIntensityMapUv),p.push(y.transmissionMapUv),p.push(y.thicknessMapUv),p.push(y.combine===void 0?void 0:dr.combine[y.combine]),p.push(y.fogExp2),p.push(y.sizeAttenuation),p.push(y.morphTargetsCount),p.push(y.morphAttributeCount),p.push(y.numDirLights),p.push(y.numPointLights),p.push(y.numSpotLights),p.push(y.numSpotLightMaps),p.push(y.numHemiLights),p.push(y.numRectAreaLights),p.push(y.numDirLightShadows),p.push(y.numPointLightShadows),p.push(y.numSpotLightShadows),p.push(y.numSpotLightShadowsWithMaps),p.push(y.numLightProbes),p.push(dr.shadowMapType[y.shadowMapType]),p.push(dr.toneMapping[y.toneMapping]),p.push(y.numClippingPlanes),p.push(y.numClipIntersection),p.push(y.depthPacking)}function T(p,y){s.disableAll(),y.supportsVertexTextures&&s.enable(0),y.instancing&&s.enable(1),y.instancingColor&&s.enable(2),y.instancingMorph&&s.enable(3),y.matcap&&s.enable(4),y.envMap&&s.enable(5),y.normalMapObjectSpace&&s.enable(6),y.normalMapTangentSpace&&s.enable(7),y.clearcoat&&s.enable(8),y.iridescence&&s.enable(9),y.alphaTest&&s.enable(10),y.vertexColors&&s.enable(11),y.vertexAlphas&&s.enable(12),y.vertexUv1s&&s.enable(13),y.vertexUv2s&&s.enable(14),y.vertexUv3s&&s.enable(15),y.vertexTangents&&s.enable(16),y.anisotropy&&s.enable(17),y.alphaHash&&s.enable(18),y.batching&&s.enable(19),y.dispersion&&s.enable(20),y.batchingColor&&s.enable(21),y.gradientMap&&s.enable(22),p.push(s.mask),s.disableAll(),y.fog&&s.enable(0),y.useFog&&s.enable(1),y.flatShading&&s.enable(2),y.logarithmicDepthBuffer&&s.enable(3),y.reversedDepthBuffer&&s.enable(4),y.skinning&&s.enable(5),y.morphTargets&&s.enable(6),y.morphNormals&&s.enable(7),y.morphColors&&s.enable(8),y.premultipliedAlpha&&s.enable(9),y.shadowMapEnabled&&s.enable(10),y.doubleSided&&s.enable(11),y.flipSided&&s.enable(12),y.useDepthPacking&&s.enable(13),y.dithering&&s.enable(14),y.transmission&&s.enable(15),y.sheen&&s.enable(16),y.opaque&&s.enable(17),y.pointsUvs&&s.enable(18),y.decodeVideoTexture&&s.enable(19),y.decodeVideoTextureEmissive&&s.enable(20),y.alphaToCoverage&&s.enable(21),p.push(s.mask)}function _(p){let y=_a[p.type],R;if(y){let D=zi[y];R=Fo(D.uniforms(),sc)}else R=p.uniforms;return R}function A(p,y){let R;for(let D=0,F=d.length;D<F;D++){let G=d[D];if(G.cacheKey===y){R=G,++R.usedTimes;break}}return R===void 0&&(R=Ma(r,y,p,o),d.push(R)),R}function U(p){if(--p.usedTimes===0){let y=d.indexOf(p);d[y]=d[d.length-1],d.pop(),p.destroy()}}function w(p){l.remove(p)}function E(){l.dispose()}return{getParameters:g,getProgramCacheKey:v,getUniforms:_,acquireProgram:A,releaseProgram:U,releaseShaderCache:w,programs:d,dispose:E}}function Aa(){let r=new WeakMap;function e(a){return r.has(a)}function t(a){let s=r.get(a);return s===void 0&&(s={},r.set(a,s)),s}function n(a){r.delete(a)}function i(a,s,l){r.get(a)[s]=l}function o(){r=new WeakMap}return{has:e,get:t,remove:n,update:i,dispose:o}}function lc(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.material.id!==e.material.id?r.material.id-e.material.id:r.z!==e.z?r.z-e.z:r.id-e.id}function Ea(r,e){return r.groupOrder!==e.groupOrder?r.groupOrder-e.groupOrder:r.renderOrder!==e.renderOrder?r.renderOrder-e.renderOrder:r.z!==e.z?e.z-r.z:r.id-e.id}function wa(){let r=[],e=0,t=[],n=[],i=[];function o(){e=0,t.length=0,n.length=0,i.length=0}function a(u,h,m,f,g,v){let M=r[e];return M===void 0?(M={id:u.id,object:u,geometry:h,material:m,groupOrder:f,renderOrder:u.renderOrder,z:g,group:v},r[e]=M):(M.id=u.id,M.object=u,M.geometry=h,M.material=m,M.groupOrder=f,M.renderOrder=u.renderOrder,M.z=g,M.group=v),e++,M}function s(u,h,m,f,g,v){let M=a(u,h,m,f,g,v);m.transmission>0?n.push(M):m.transparent===!0?i.push(M):t.push(M)}function l(u,h,m,f,g,v){let M=a(u,h,m,f,g,v);m.transmission>0?n.unshift(M):m.transparent===!0?i.unshift(M):t.unshift(M)}function c(u,h){t.length>1&&t.sort(u||lc),n.length>1&&n.sort(h||Ea),i.length>1&&i.sort(h||Ea)}function d(){for(let u=e,h=r.length;u<h;u++){let m=r[u];if(m.id===null)break;m.id=null,m.object=null,m.geometry=null,m.material=null,m.group=null}}return{opaque:t,transmissive:n,transparent:i,init:o,push:s,unshift:l,finish:d,sort:c}}function Ca(){let r=new WeakMap;function e(n,i){let o=r.get(n),a;return o===void 0?(a=wa(),r.set(n,[a])):i>=o.length?(a=wa(),o.push(a)):a=o[i],a}function t(){r=new WeakMap}return{get:e,dispose:t}}function uc(){let r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t;return e.isDirectionalLight===!0?t={direction:new L,color:new Pe}:t={direction:new L,skyColor:new Pe,groundColor:new Pe},r[e.id]=t,t}}}function cc(){let r={};return{get:function(e){if(r[e.id]!==void 0)return r[e.id];let t={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new W};return r[e.id]=t,t}}}var dc=0;function hc(r,e){return(e.castShadow?2:0)-(r.castShadow?2:0)+(e.map?1:0)-(r.map?1:0)}function La(r){let e=uc(),t=cc(),n={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let s=0;s<9;s++)n.probe.push(new L);let i=new L;function o(s){let l=0,c=0,d=0;for(let E=0;E<9;E++)n.probe[E].set(0,0,0);let u=0,h=0,m=0,f=0,g=0,v=0,M=0,T=0,_=0,A=0,U=0;s.sort(hc);for(let E=0,p=s.length;E<p;E++){let y=s[E],R=y.color,D=y.intensity,F=y.shadow&&y.shadow.map?y.shadow.map.texture:null;if(y.isAmbientLight)l+=R.r*D,c+=R.g*D,d+=R.b*D;else if(y.isDirectionalLight){let G=e.get(y);if(G.color.copy(y.color).multiplyScalar(y.intensity),y.castShadow){let B=y.shadow,Z=t.get(y);Z.shadowIntensity=B.intensity,Z.shadowBias=B.bias,Z.shadowNormalBias=B.normalBias,Z.shadowRadius=B.radius,Z.shadowMapSize=B.mapSize,n.directionalShadow[u]=Z,n.directionalShadowMap[u]=F,n.directionalShadowMatrix[u]=y.shadow.matrix,v++}n.directional[u]=G,u++}else if(y.isHemisphereLight){let G=e.get(y);G.skyColor.copy(y.color).multiplyScalar(D),G.groundColor.copy(y.groundColor).multiplyScalar(D),n.hemi[g]=G,g++}}n.ambient[0]=l,n.ambient[1]=c,n.ambient[2]=d;let w=n.hash;(w.directionalLength!==u||w.pointLength!==h||w.spotLength!==m||w.rectAreaLength!==f||w.hemiLength!==g||w.numDirectionalShadows!==v||w.numPointShadows!==M||w.numSpotShadows!==T||w.numSpotMaps!==_||w.numLightProbes!==U)&&(n.directional.length=u,n.spot.length=m,n.rectArea.length=f,n.point.length=h,n.hemi.length=g,n.directionalShadow.length=v,n.directionalShadowMap.length=v,n.pointShadow.length=M,n.pointShadowMap.length=M,n.spotShadow.length=T,n.spotShadowMap.length=T,n.directionalShadowMatrix.length=v,n.pointShadowMatrix.length=M,n.spotLightMatrix.length=T+_-A,n.spotLightMap.length=_,n.numSpotLightShadowsWithMaps=A,n.numLightProbes=U,w.directionalLength=u,w.pointLength=h,w.spotLength=m,w.rectAreaLength=f,w.hemiLength=g,w.numDirectionalShadows=v,w.numPointShadows=M,w.numSpotShadows=T,w.numSpotMaps=_,w.numLightProbes=U,n.version=dc++)}function a(s,l){let c=0,d=0,u=l.matrixWorldInverse;for(let h=0,m=s.length;h<m;h++){let f=s[h];if(f.isDirectionalLight){let g=n.directional[c];g.direction.setFromMatrixPosition(f.matrixWorld),i.setFromMatrixPosition(f.target.matrixWorld),g.direction.sub(i),g.direction.transformDirection(u),c++}else if(f.isHemisphereLight){let g=n.hemi[d];g.direction.setFromMatrixPosition(f.matrixWorld),g.direction.transformDirection(u),d++}}}return{setup:o,setupView:a,state:n}}function Ra(r){let e=La(r),t=[],n=[];function i(d){c.camera=d,t.length=0,n.length=0}function o(d){t.push(d)}function a(d){n.push(d)}function s(){e.setup(t)}function l(d){e.setupView(t,d)}let c={lightsArray:t,shadowsArray:n,camera:null,lights:e,transmissionRenderTarget:{}};return{init:i,state:c,setupLights:s,setupLightsView:l,pushLight:o,pushShadow:a}}function Pa(r){let e=new WeakMap;function t(i,o=0){let a=e.get(i),s;return a===void 0?(s=Ra(r),e.set(i,[s])):o>=a.length?(s=Ra(r),a.push(s)):s=a[o],s}function n(){e=new WeakMap}return{get:t,dispose:n}}function Ua(r,e,t){let n=new Ht,i=new W,o=new W,a=new Ze,s=new ln({depthPacking:"rgba"}),l=new un,c={},d=t.maxTextureSize,u={front:"back",back:"front",both:"both"},h=new yr({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new W},radius:{value:4}}}),m=h.clone();m.defines.HORIZONTAL_PASS=1;let f=new Dt;f.setAttribute("position",new de(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));let g=new qt(f,h),v={enabled:!1,autoUpdate:!0,needsUpdate:!1,type:"pcf",render:T},M=v.type;function T(w,E,p){if(v.enabled===!1||v.autoUpdate===!1&&v.needsUpdate===!1||w.length===0)return;let y=r.getRenderTarget(),R=r.getActiveCubeFace(),D=r.getActiveMipmapLevel(),F=r.state;F.setBlending("none"),F.buffers.depth.getReversed()===!0?F.buffers.color.setClear(0,0,0,0):F.buffers.color.setClear(1,1,1,1),F.buffers.depth.setTest(!0),F.setScissorTest(!1);let G=M!=="vsm"&&v.type==="vsm",B=M==="vsm"&&v.type!=="vsm";for(let Z=0,re=w.length;Z<re;Z++){let oe=w[Z],Y=oe.shadow;if(Y===void 0){console.warn("keel/lit ShadowMap:",oe,"has no shadow.");continue}if(Y.autoUpdate===!1&&Y.needsUpdate===!1)continue;i.copy(Y.mapSize);let ae=Y.getFrameExtents();if(i.multiply(ae),o.copy(Y.mapSize),(i.x>d||i.y>d)&&(i.x>d&&(o.x=Math.floor(d/ae.x),i.x=o.x*ae.x,Y.mapSize.x=o.x),i.y>d&&(o.y=Math.floor(d/ae.y),i.y=o.y*ae.y,Y.mapSize.y=o.y)),Y.map===null||G===!0||B===!0){let me=v.type!=="vsm"?{minFilter:"nearest",magFilter:"nearest"}:{};Y.map!==null&&Y.map.dispose(),Y.map=new Mr(i.x,i.y,me),Y.map.texture.name=oe.name+".shadowMap",Y.camera.updateProjectionMatrix()}r.setRenderTarget(Y.map),r.clear();let he=Y.getViewportCount();for(let me=0;me<he;me++){let Ue=Y.getViewport(me);a.set(o.x*Ue.x,o.y*Ue.y,o.x*Ue.z,o.y*Ue.w),F.viewport(a),Y.updateMatrices(oe,me),n=Y.getFrustum(),A(E,p,Y.camera,oe,v.type)}Y.needsUpdate=!1}M=v.type,v.needsUpdate=!1,r.setRenderTarget(y,R,D)}function _(w,E,p,y){let R=null,D=p.isPointLight===!0?w.customDistanceMaterial:w.customDepthMaterial;if(D!==void 0)R=D;else if(R=p.isPointLight===!0?l:s,r.localClippingEnabled&&E.clipShadows===!0&&Array.isArray(E.clippingPlanes)&&E.clippingPlanes.length!==0||E.displacementMap&&E.displacementScale!==0||E.alphaMap&&E.alphaTest>0||E.map&&E.alphaTest>0||E.alphaToCoverage===!0){let G=R.uuid,B=E.uuid,Z=c[G];Z===void 0&&(Z={},c[G]=Z);let re=Z[B];re===void 0&&(re=R.clone(),Z[B]=re,E.addEventListener("dispose",U)),R=re}let F=R;if(F.visible=E.visible,F.wireframe=E.wireframe,y==="vsm"?F.side=E.shadowSide!==null?E.shadowSide:E.side:F.side=E.shadowSide!==null?E.shadowSide:u[E.side],F.alphaMap=E.alphaMap,F.alphaTest=E.alphaToCoverage===!0?.5:E.alphaTest,F.map=E.map,F.clipShadows=E.clipShadows,F.clippingPlanes=E.clippingPlanes,F.clipIntersection=E.clipIntersection,F.displacementMap=E.displacementMap,F.displacementScale=E.displacementScale,F.displacementBias=E.displacementBias,F.wireframeLinewidth=E.wireframeLinewidth,F.linewidth=E.linewidth,p.isPointLight===!0&&R.isMeshDistanceMaterial===!0){let G=r.properties.get(R);G.light=p}return R}function A(w,E,p,y,R){if(w.visible===!1)return;if(w.layers.test(E.layers)&&(w.isMesh||w.isLine||w.isPoints)&&(w.castShadow||w.receiveShadow&&R==="vsm")&&(!w.frustumCulled||n.intersectsObject(w))){w.modelViewMatrix.multiplyMatrices(p.matrixWorldInverse,w.matrixWorld);let G=e.update(w),B=w.material;if(Array.isArray(B)){let Z=G.groups;for(let re=0,oe=Z.length;re<oe;re++){let Y=Z[re],ae=B[Y.materialIndex];if(ae&&ae.visible){let he=_(w,ae,y,R);w.onBeforeShadow(r,w,E,p,G,he,Y),r.renderBufferDirect(p,null,G,he,w,Y),w.onAfterShadow(r,w,E,p,G,he,Y)}}}else if(B.visible){let Z=_(w,B,y,R);w.onBeforeShadow(r,w,E,p,G,Z,null),r.renderBufferDirect(p,null,G,Z,w,null),w.onAfterShadow(r,w,E,p,G,Z,null)}}let F=w.children;for(let G=0,B=F.length;G<B;G++)A(F[G],E,p,y,R)}function U(w){let E=w.target;E.removeEventListener("dispose",U);for(let p in c){let y=c[p],R=E.uuid;R in y&&(y[R].dispose(),delete y[R])}}return v}var mc={never:"always",less:"greater",equal:"not-equal","less-equal":"greater-equal",always:"never",greater:"less","not-equal":"equal","greater-equal":"less-equal"};function Ia(r,e){function t(){let C=!1,$=new Ze,se=null,le=new Ze(0,0,0,0);return{setMask:function(ye){se!==ye&&!C&&(r.colorMask(ye,ye,ye,ye),se=ye)},setLocked:function(ye){C=ye},setClear:function(ye,ge,De,ke,Et){Et===!0&&(ye*=ke,ge*=ke,De*=ke),$.set(ye,ge,De,ke),le.equals($)===!1&&(r.clearColor(ye,ge,De,ke),le.copy($))},reset:function(){C=!1,se=null,le.set(-1,0,0,0)}}}function n(){let C=!1,$=!1,se=null,le=null,ye=null;return{setReversed:function(ge){if($!==ge){let De=e.get("EXT_clip_control");ge?De.clipControlEXT(De.LOWER_LEFT_EXT,De.ZERO_TO_ONE_EXT):De.clipControlEXT(De.LOWER_LEFT_EXT,De.NEGATIVE_ONE_TO_ONE_EXT),$=ge;let ke=ye;ye=null,this.setClear(ke)}},getReversed:function(){return $},setTest:function(ge){ge?Fe(r.DEPTH_TEST):Be(r.DEPTH_TEST)},setMask:function(ge){se!==ge&&!C&&(r.depthMask(ge),se=ge)},setFunc:function(ge){if($&&(ge=mc[ge]),le!==ge){switch(ge){case"never":r.depthFunc(r.NEVER);break;case"always":r.depthFunc(r.ALWAYS);break;case"less":r.depthFunc(r.LESS);break;case"less-equal":r.depthFunc(r.LEQUAL);break;case"equal":r.depthFunc(r.EQUAL);break;case"greater-equal":r.depthFunc(r.GEQUAL);break;case"greater":r.depthFunc(r.GREATER);break;case"not-equal":r.depthFunc(r.NOTEQUAL);break;default:r.depthFunc(r.LEQUAL)}le=ge}},setLocked:function(ge){C=ge},setClear:function(ge){ye!==ge&&($&&(ge=1-ge),r.clearDepth(ge),ye=ge)},reset:function(){C=!1,se=null,le=null,ye=null,$=!1}}}function i(){let C=!1,$=null,se=null,le=null,ye=null,ge=null,De=null,ke=null,Et=null;return{setTest:function(Xe){C||(Xe?Fe(r.STENCIL_TEST):Be(r.STENCIL_TEST))},setMask:function(Xe){$!==Xe&&!C&&(r.stencilMask(Xe),$=Xe)},setFunc:function(Xe,Lt,zt){(se!==Xe||le!==Lt||ye!==zt)&&(r.stencilFunc(ti[Xe],Lt,zt),se=Xe,le=Lt,ye=zt)},setOp:function(Xe,Lt,zt){(ge!==Xe||De!==Lt||ke!==zt)&&(r.stencilOp(Gr[Xe],Gr[Lt],Gr[zt]),ge=Xe,De=Lt,ke=zt)},setLocked:function(Xe){C=Xe},setClear:function(Xe){Et!==Xe&&(r.clearStencil(Xe),Et=Xe)},reset:function(){C=!1,$=null,se=null,le=null,ye=null,ge=null,De=null,ke=null,Et=null}}}let o=t(),a=n(),s=i(),l=new WeakMap,c=new WeakMap,d={},u={},h=new WeakMap,m=[],f=null,g=!1,v=null,M=null,T=null,_=null,A=null,U=null,w=null,E=new Pe(0,0,0),p=0,y=!1,R=null,D=null,F=null,G=null,B=null,Z=r.getParameter(r.MAX_COMBINED_TEXTURE_IMAGE_UNITS),re=!1,oe=0,Y=r.getParameter(r.VERSION);Y.indexOf("WebGL")!==-1?(oe=parseFloat(/^WebGL (\d)/.exec(Y)[1]),re=oe>=1):Y.indexOf("OpenGL ES")!==-1&&(oe=parseFloat(/^OpenGL ES (\d)/.exec(Y)[1]),re=oe>=2);let ae=null,he={},me=r.getParameter(r.SCISSOR_BOX),Ue=r.getParameter(r.VIEWPORT),Ge=new Ze().fromArray(me),ze=new Ze().fromArray(Ue);function ot(C,$,se,le){let ye=new Uint8Array(4),ge=r.createTexture();r.bindTexture(C,ge),r.texParameteri(C,r.TEXTURE_MIN_FILTER,r.NEAREST),r.texParameteri(C,r.TEXTURE_MAG_FILTER,r.NEAREST);for(let De=0;De<se;De++)C===r.TEXTURE_3D||C===r.TEXTURE_2D_ARRAY?r.texImage3D($,0,r.RGBA,1,1,le,0,r.RGBA,r.UNSIGNED_BYTE,ye):r.texImage2D($+De,0,r.RGBA,1,1,0,r.RGBA,r.UNSIGNED_BYTE,ye);return ge}let je={};je[r.TEXTURE_2D]=ot(r.TEXTURE_2D,r.TEXTURE_2D,1),je[r.TEXTURE_CUBE_MAP]=ot(r.TEXTURE_CUBE_MAP,r.TEXTURE_CUBE_MAP_POSITIVE_X,6),je[r.TEXTURE_2D_ARRAY]=ot(r.TEXTURE_2D_ARRAY,r.TEXTURE_2D_ARRAY,1,1),je[r.TEXTURE_3D]=ot(r.TEXTURE_3D,r.TEXTURE_3D,1,1),o.setClear(0,0,0,1),a.setClear(1),s.setClear(0),Fe(r.DEPTH_TEST),a.setFunc("less-equal"),k(!1),te("back"),Fe(r.CULL_FACE),H("none");function Fe(C){d[C]!==!0&&(r.enable(C),d[C]=!0)}function Be(C){d[C]!==!1&&(r.disable(C),d[C]=!1)}function He(C,$){return u[C]!==$?(r.bindFramebuffer(C,$),u[C]=$,C===r.DRAW_FRAMEBUFFER&&(u[r.FRAMEBUFFER]=$),C===r.FRAMEBUFFER&&(u[r.DRAW_FRAMEBUFFER]=$),!0):!1}function lt(C,$){let se=m,le=!1;if(C){se=h.get($),se===void 0&&(se=[],h.set($,se));let ye=C.textures;if(se.length!==ye.length||se[0]!==r.COLOR_ATTACHMENT0){for(let ge=0,De=ye.length;ge<De;ge++)se[ge]=r.COLOR_ATTACHMENT0+ge;se.length=ye.length,le=!0}}else se[0]!==r.BACK&&(se[0]=r.BACK,le=!0);le&&r.drawBuffers(se)}function Nt(C){return f!==C?(r.useProgram(C),f=C,!0):!1}let J={add:r.FUNC_ADD,subtract:r.FUNC_SUBTRACT,"reverse-subtract":r.FUNC_REVERSE_SUBTRACT,min:r.MIN,max:r.MAX},Je={zero:r.ZERO,one:r.ONE,"src-color":r.SRC_COLOR,"src-alpha":r.SRC_ALPHA,"src-alpha-saturate":r.SRC_ALPHA_SATURATE,"dst-color":r.DST_COLOR,"dst-alpha":r.DST_ALPHA,"one-minus-src-color":r.ONE_MINUS_SRC_COLOR,"one-minus-src-alpha":r.ONE_MINUS_SRC_ALPHA,"one-minus-dst-color":r.ONE_MINUS_DST_COLOR,"one-minus-dst-alpha":r.ONE_MINUS_DST_ALPHA,"constant-color":r.CONSTANT_COLOR,"one-minus-constant-color":r.ONE_MINUS_CONSTANT_COLOR,"constant-alpha":r.CONSTANT_ALPHA,"one-minus-constant-alpha":r.ONE_MINUS_CONSTANT_ALPHA};function H(C,$,se,le,ye,ge,De,ke,Et,Xe){if(C==="none"){g===!0&&(Be(r.BLEND),g=!1);return}if(g===!1&&(Fe(r.BLEND),g=!0),C!=="custom"){if(C!==v||Xe!==y){if((M!=="add"||A!=="add")&&(r.blendEquation(r.FUNC_ADD),M="add",A="add"),Xe)switch(C){case"normal":r.blendFuncSeparate(r.ONE,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case"add":r.blendFunc(r.ONE,r.ONE);break;case"subtract":r.blendFuncSeparate(r.ZERO,r.ONE_MINUS_SRC_COLOR,r.ZERO,r.ONE);break;case"multiply":r.blendFuncSeparate(r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ZERO,r.ONE);break;default:console.error("keel/lit State: Invalid blending: ",C);break}else switch(C){case"normal":r.blendFuncSeparate(r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA);break;case"add":r.blendFuncSeparate(r.SRC_ALPHA,r.ONE,r.ONE,r.ONE);break;case"subtract":console.error("keel/lit State: subtract blending requires material.premultipliedAlpha = true");break;case"multiply":console.error("keel/lit State: multiply blending requires material.premultipliedAlpha = true");break;default:console.error("keel/lit State: Invalid blending: ",C);break}T=null,_=null,U=null,w=null,E.set(0,0,0),p=0,v=C,y=Xe}return}ye=ye||$,ge=ge||se,De=De||le,($!==M||ye!==A)&&(r.blendEquationSeparate(J[$],J[ye]),M=$,A=ye),(se!==T||le!==_||ge!==U||De!==w)&&(r.blendFuncSeparate(Je[se],Je[le],Je[ge],Je[De]),T=se,_=le,U=ge,w=De),(ke.equals(E)===!1||Et!==p)&&(r.blendColor(ke.r,ke.g,ke.b,Et),E.copy(ke),p=Et),v=C,y=!1}function ee(C,$){C.side==="both"?Be(r.CULL_FACE):Fe(r.CULL_FACE);let se=C.side==="back";$&&(se=!se),k(se),C.blending==="normal"&&C.transparent===!1?H("none"):H(C.blending,C.blendEquation,C.blendSrc,C.blendDst,C.blendEquationAlpha,C.blendSrcAlpha,C.blendDstAlpha,C.blendColor,C.blendAlpha,C.premultipliedAlpha),a.setFunc(C.depthFunc),a.setTest(C.depthTest),a.setMask(C.depthWrite),o.setMask(C.colorWrite);let le=C.stencilWrite;s.setTest(le),le&&(s.setMask(C.stencilWriteMask),s.setFunc(C.stencilFunc,C.stencilRef,C.stencilFuncMask),s.setOp(C.stencilFail,C.stencilZFail,C.stencilZPass)),ue(C.polygonOffset,C.polygonOffsetFactor,C.polygonOffsetUnits),C.alphaToCoverage===!0?Fe(r.SAMPLE_ALPHA_TO_COVERAGE):Be(r.SAMPLE_ALPHA_TO_COVERAGE)}function k(C){R!==C&&(C?r.frontFace(r.CW):r.frontFace(r.CCW),R=C)}function te(C){C!=="none"?(Fe(r.CULL_FACE),C!==D&&(C==="back"?r.cullFace(r.BACK):C==="front"?r.cullFace(r.FRONT):r.cullFace(r.FRONT_AND_BACK))):Be(r.CULL_FACE),D=C}function j(C){C!==F&&(re&&r.lineWidth(C),F=C)}function ue(C,$,se){C?(Fe(r.POLYGON_OFFSET_FILL),(G!==$||B!==se)&&(r.polygonOffset($,se),G=$,B=se)):Be(r.POLYGON_OFFSET_FILL)}function ce(C){C?Fe(r.SCISSOR_TEST):Be(r.SCISSOR_TEST)}function Ae(C){C===void 0&&(C=r.TEXTURE0+Z-1),ae!==C&&(r.activeTexture(C),ae=C)}function _e(C,$,se){se===void 0&&(ae===null?se=r.TEXTURE0+Z-1:se=ae);let le=he[se];le===void 0&&(le={type:void 0,texture:void 0},he[se]=le),(le.type!==C||le.texture!==$)&&(ae!==se&&(r.activeTexture(se),ae=se),r.bindTexture(C,$||je[C]),le.type=C,le.texture=$)}function S(){let C=he[ae];C!==void 0&&C.type!==void 0&&(r.bindTexture(C.type,null),C.type=void 0,C.texture=void 0)}let b=r;function P(...C){try{b.compressedTexImage2D(...C)}catch($){console.error("keel/lit State:",$)}}function X(...C){try{b.compressedTexImage3D(...C)}catch($){console.error("keel/lit State:",$)}}function K(...C){try{b.texSubImage2D(...C)}catch($){console.error("keel/lit State:",$)}}function N(...C){try{b.texSubImage3D(...C)}catch($){console.error("keel/lit State:",$)}}function Q(...C){try{b.compressedTexSubImage2D(...C)}catch($){console.error("keel/lit State:",$)}}function pe(...C){try{b.compressedTexSubImage3D(...C)}catch($){console.error("keel/lit State:",$)}}function be(...C){try{b.texStorage2D(...C)}catch($){console.error("keel/lit State:",$)}}function Oe(...C){try{b.texStorage3D(...C)}catch($){console.error("keel/lit State:",$)}}function ie(...C){try{b.texImage2D(...C)}catch($){console.error("keel/lit State:",$)}}function Te(...C){try{b.texImage3D(...C)}catch($){console.error("keel/lit State:",$)}}function Ee(C){Ge.equals(C)===!1&&(r.scissor(C.x,C.y,C.z,C.w),Ge.copy(C))}function q(C){ze.equals(C)===!1&&(r.viewport(C.x,C.y,C.z,C.w),ze.copy(C))}function We(C,$){let se=c.get($);se===void 0&&(se=new WeakMap,c.set($,se));let le=se.get(C);le===void 0&&(le=r.getUniformBlockIndex($,C.name),se.set(C,le))}function et(C,$){let le=c.get($).get(C);l.get($)!==le&&(r.uniformBlockBinding($,le,C.__bindingPointIndex),l.set($,le))}function ut(){r.disable(r.BLEND),r.disable(r.CULL_FACE),r.disable(r.DEPTH_TEST),r.disable(r.POLYGON_OFFSET_FILL),r.disable(r.SCISSOR_TEST),r.disable(r.STENCIL_TEST),r.disable(r.SAMPLE_ALPHA_TO_COVERAGE),r.blendEquation(r.FUNC_ADD),r.blendFunc(r.ONE,r.ZERO),r.blendFuncSeparate(r.ONE,r.ZERO,r.ONE,r.ZERO),r.blendColor(0,0,0,0),r.colorMask(!0,!0,!0,!0),r.clearColor(0,0,0,0),r.depthMask(!0),r.depthFunc(r.LESS),a.setReversed(!1),r.clearDepth(1),r.stencilMask(4294967295),r.stencilFunc(r.ALWAYS,0,4294967295),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),r.clearStencil(0),r.cullFace(r.BACK),r.frontFace(r.CCW),r.polygonOffset(0,0),r.activeTexture(r.TEXTURE0),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,null),r.bindFramebuffer(r.READ_FRAMEBUFFER,null),r.useProgram(null),r.lineWidth(1),r.scissor(0,0,r.canvas.width,r.canvas.height),r.viewport(0,0,r.canvas.width,r.canvas.height),d={},ae=null,he={},u={},h=new WeakMap,m=[],f=null,g=!1,v=null,M=null,T=null,_=null,A=null,U=null,w=null,E=new Pe(0,0,0),p=0,y=!1,R=null,D=null,F=null,G=null,B=null,Ge.set(0,0,r.canvas.width,r.canvas.height),ze.set(0,0,r.canvas.width,r.canvas.height),o.reset(),a.reset(),s.reset()}return{buffers:{color:o,depth:a,stencil:s},enable:Fe,disable:Be,bindFramebuffer:He,drawBuffers:lt,useProgram:Nt,setBlending:H,setMaterial:ee,setFlipSided:k,setCullFace:te,setLineWidth:j,setPolygonOffset:ue,setScissorTest:ce,activeTexture:Ae,bindTexture:_e,unbindTexture:S,compressedTexImage2D:P,compressedTexImage3D:X,texImage2D:ie,texImage3D:Te,updateUBOMapping:We,uniformBlockBinding:et,texStorage2D:be,texStorage3D:Oe,texSubImage2D:K,texSubImage3D:N,compressedTexSubImage2D:Q,compressedTexSubImage3D:pe,scissor:Ee,viewport:q,reset:ut}}function Da(r,e,t,n,i,o,a){let s=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):null,l=typeof navigator>"u"?!1:/OculusBrowser/g.test(navigator.userAgent),c=new W,d,u=new WeakMap,h=S=>n.get(S),m=S=>n.get(S),f=!1;try{f=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function g(S,b){return f?new OffscreenCanvas(S,b):document.createElement("canvas")}function v(S,b,P){let X=1,K=_e(S);if((K.width>P||K.height>P)&&(X=P/Math.max(K.width,K.height)),X<1)if(typeof HTMLImageElement<"u"&&S instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&S instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&S instanceof ImageBitmap||typeof VideoFrame<"u"&&S instanceof VideoFrame){let N=Math.floor(X*K.width),Q=Math.floor(X*K.height);d===void 0&&(d=g(N,Q));let pe=b?g(N,Q):d;return pe.width=N,pe.height=Q,pe.getContext("2d").drawImage(S,0,0,N,Q),console.warn("keel/lit: Texture has been resized from ("+K.width+"x"+K.height+") to ("+N+"x"+Q+")."),pe}else return"data"in S&&console.warn("keel/lit: Image in DataTexture is too big ("+K.width+"x"+K.height+")."),S;return S}function M(S){return S.generateMipmaps}function T(S){r.generateMipmap(S)}function _(S){return r.TEXTURE_2D}function A(S,b,P,X,K=!1){if(S!==null){let Q=r[S];if(Q!==void 0)return Q;console.warn("keel/lit: Attempt to use non-existing WebGL internal format '"+S+"'")}let N=b;if(b===r.RED&&(P===r.FLOAT&&(N=r.R32F),P===r.HALF_FLOAT&&(N=r.R16F),P===r.UNSIGNED_BYTE&&(N=r.R8)),b===r.RED_INTEGER&&(P===r.UNSIGNED_BYTE&&(N=r.R8UI),P===r.UNSIGNED_SHORT&&(N=r.R16UI),P===r.UNSIGNED_INT&&(N=r.R32UI),P===r.BYTE&&(N=r.R8I),P===r.SHORT&&(N=r.R16I),P===r.INT&&(N=r.R32I)),b===r.RG&&(P===r.FLOAT&&(N=r.RG32F),P===r.HALF_FLOAT&&(N=r.RG16F),P===r.UNSIGNED_BYTE&&(N=r.RG8)),b===r.RG_INTEGER&&(P===r.UNSIGNED_BYTE&&(N=r.RG8UI),P===r.UNSIGNED_SHORT&&(N=r.RG16UI),P===r.UNSIGNED_INT&&(N=r.RG32UI),P===r.BYTE&&(N=r.RG8I),P===r.SHORT&&(N=r.RG16I),P===r.INT&&(N=r.RG32I)),b===r.RGB_INTEGER&&(P===r.UNSIGNED_BYTE&&(N=r.RGB8UI),P===r.UNSIGNED_SHORT&&(N=r.RGB16UI),P===r.UNSIGNED_INT&&(N=r.RGB32UI),P===r.BYTE&&(N=r.RGB8I),P===r.SHORT&&(N=r.RGB16I),P===r.INT&&(N=r.RGB32I)),b===r.RGBA_INTEGER&&(P===r.UNSIGNED_BYTE&&(N=r.RGBA8UI),P===r.UNSIGNED_SHORT&&(N=r.RGBA16UI),P===r.UNSIGNED_INT&&(N=r.RGBA32UI),P===r.BYTE&&(N=r.RGBA8I),P===r.SHORT&&(N=r.RGBA16I),P===r.INT&&(N=r.RGBA32I)),b===r.RGB&&(P===r.UNSIGNED_INT_5_9_9_9_REV&&(N=r.RGB9_E5),P===r.UNSIGNED_INT_10F_11F_11F_REV&&(N=r.R11F_G11F_B10F)),b===r.RGBA){let Q=K?"linear":Ne.getTransfer(X);P===r.FLOAT&&(N=r.RGBA32F),P===r.HALF_FLOAT&&(N=r.RGBA16F),P===r.UNSIGNED_BYTE&&(N=Q==="srgb"?r.SRGB8_ALPHA8:r.RGBA8),P===r.UNSIGNED_SHORT_4_4_4_4&&(N=r.RGBA4),P===r.UNSIGNED_SHORT_5_5_5_1&&(N=r.RGB5_A1)}return(N===r.R16F||N===r.R32F||N===r.RG16F||N===r.RG32F||N===r.RGBA16F||N===r.RGBA32F)&&e.get("EXT_color_buffer_float"),N}function U(S,b){let P;return S?b===null||b==="uint"||b==="depth24-stencil8"?P=r.DEPTH24_STENCIL8:b==="float"?P=r.DEPTH32F_STENCIL8:b==="u16"&&(P=r.DEPTH24_STENCIL8,console.warn("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):b===null||b==="uint"||b==="depth24-stencil8"?P=r.DEPTH_COMPONENT24:b==="float"?P=r.DEPTH_COMPONENT32F:b==="u16"&&(P=r.DEPTH_COMPONENT16),P}function w(S,b){return M(S)===!0?Math.log2(Math.max(b.width,b.height))+1:S.mipmaps!==void 0&&S.mipmaps.length>0?S.mipmaps.length:1}function E(S){let b=S.target;b.removeEventListener("dispose",E),y(b)}function p(S){let b=S.target;b.removeEventListener("dispose",p),D(b)}function y(S){let b=h(S);if(b.__webglInit===void 0)return;let P=S.source,X=u.get(P);if(X){let K=X[b.__cacheKey];K.usedTimes--,K.usedTimes===0&&R(S),Object.keys(X).length===0&&u.delete(P)}n.remove(S)}function R(S){let b=h(S);r.deleteTexture(b.__webglTexture);let P=S.source,X=u.get(P);delete X[b.__cacheKey],a.memory.textures--}function D(S){let b=m(S);if(S.depthTexture&&(S.depthTexture.dispose(),n.remove(S.depthTexture)),Array.isArray(b.__webglFramebuffer))for(let X=0;X<b.__webglFramebuffer.length;X++)r.deleteFramebuffer(b.__webglFramebuffer[X]);else r.deleteFramebuffer(b.__webglFramebuffer);if(b.__webglDepthbuffer&&r.deleteRenderbuffer(b.__webglDepthbuffer),b.__webglMultisampledFramebuffer&&r.deleteFramebuffer(b.__webglMultisampledFramebuffer),b.__webglColorRenderbuffer)for(let X=0;X<b.__webglColorRenderbuffer.length;X++)b.__webglColorRenderbuffer[X]&&r.deleteRenderbuffer(b.__webglColorRenderbuffer[X]);b.__webglDepthRenderbuffer&&r.deleteRenderbuffer(b.__webglDepthRenderbuffer);let P=S.textures;for(let X=0,K=P.length;X<K;X++){let N=h(P[X]);N.__webglTexture&&(r.deleteTexture(N.__webglTexture),a.memory.textures--),n.remove(P[X])}n.remove(S)}let F=0;function G(){F=0}function B(){let S=F;return S>=i.maxTextures&&console.warn("keel/lit: Trying to use "+S+" texture units while this GPU supports only "+i.maxTextures),F+=1,S}function Z(S){let b=[];return b.push(S.wrapS),b.push(S.wrapT),b.push(S.wrapR||0),b.push(S.magFilter),b.push(S.minFilter),b.push(S.anisotropy),b.push(S.internalFormat),b.push(S.format),b.push(S.type),b.push(S.generateMipmaps),b.push(S.premultiplyAlpha),b.push(S.flipY),b.push(S.unpackAlignment),b.push(S.colorSpace),b.join()}function re(S,b){let P=h(S);if(S.isRenderTargetTexture===!1&&S.version>0&&P.__version!==S.version){let X=S.image;if(X===null)console.warn("keel/lit: Texture marked for update but no image data found.");else if(X.complete===!1)console.warn("keel/lit: Texture marked for update but image is incomplete");else{Be(P,S,b);return}}t.bindTexture(r.TEXTURE_2D,P.__webglTexture,r.TEXTURE0+b)}function oe(S,b,P,X){let K=h(b);if(b.version>0&&K.__version!==b.version)throw new Error("keel/lit: "+X+" textures are not supported");t.bindTexture(S,K.__webglTexture,r.TEXTURE0+P)}function Y(S,b){oe(r.TEXTURE_2D_ARRAY,S,b,"array")}function ae(S,b){oe(r.TEXTURE_3D,S,b,"3D")}function he(S,b){oe(r.TEXTURE_CUBE_MAP,S,b,"cube")}let me={repeat:r.REPEAT,clamp:r.CLAMP_TO_EDGE,mirror:r.MIRRORED_REPEAT},Ue={nearest:r.NEAREST,"nearest-mipmap-nearest":r.NEAREST_MIPMAP_NEAREST,"nearest-mipmap-linear":r.NEAREST_MIPMAP_LINEAR,linear:r.LINEAR,"linear-mipmap-nearest":r.LINEAR_MIPMAP_NEAREST,"linear-mipmap-linear":r.LINEAR_MIPMAP_LINEAR},Ge={never:r.NEVER,always:r.ALWAYS,less:r.LESS,"less-equal":r.LEQUAL,equal:r.EQUAL,"greater-equal":r.GEQUAL,greater:r.GREATER,"not-equal":r.NOTEQUAL};function ze(S,b){if(b.type==="float"&&e.has("OES_texture_float_linear")===!1&&(b.magFilter==="linear"||b.magFilter==="linear-mipmap-nearest"||b.magFilter==="nearest-mipmap-linear"||b.magFilter==="linear-mipmap-linear"||b.minFilter==="linear"||b.minFilter==="linear-mipmap-nearest"||b.minFilter==="nearest-mipmap-linear"||b.minFilter==="linear-mipmap-linear")&&console.warn("keel/lit: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),r.texParameteri(S,r.TEXTURE_WRAP_S,me[b.wrapS]),r.texParameteri(S,r.TEXTURE_WRAP_T,me[b.wrapT]),r.texParameteri(S,r.TEXTURE_MAG_FILTER,Ue[b.magFilter]),r.texParameteri(S,r.TEXTURE_MIN_FILTER,Ue[b.minFilter]),b.compareFunction&&(r.texParameteri(S,r.TEXTURE_COMPARE_MODE,r.COMPARE_REF_TO_TEXTURE),r.texParameteri(S,r.TEXTURE_COMPARE_FUNC,Ge[b.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){if(b.magFilter==="nearest"||b.minFilter!=="nearest-mipmap-linear"&&b.minFilter!=="linear-mipmap-linear"||b.type==="float"&&e.has("OES_texture_float_linear")===!1)return;if(b.anisotropy>1||h(b).__currentAnisotropy){let P=e.get("EXT_texture_filter_anisotropic");r.texParameterf(S,P.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(b.anisotropy,i.getMaxAnisotropy())),h(b).__currentAnisotropy=b.anisotropy}}}function ot(S,b){let P=!1;S.__webglInit===void 0&&(S.__webglInit=!0,b.addEventListener("dispose",E));let X=b.source,K=u.get(X);K===void 0&&(K={},u.set(X,K));let N=Z(b);if(N!==S.__cacheKey){K[N]===void 0&&(K[N]={texture:r.createTexture(),usedTimes:0},a.memory.textures++,P=!0),K[N].usedTimes++;let Q=K[S.__cacheKey];Q!==void 0&&(K[S.__cacheKey].usedTimes--,Q.usedTimes===0&&R(b)),S.__cacheKey=N,S.__webglTexture=K[N].texture}return P}function je(S,b,P){return Math.floor(Math.floor(S/P)/b)}function Fe(S,b,P,X){let N=S.updateRanges;if(N.length===0)t.texSubImage2D(r.TEXTURE_2D,0,0,0,b.width,b.height,P,X,b.data);else{N.sort((ie,Te)=>ie.start-Te.start);let Q=0;for(let ie=1;ie<N.length;ie++){let Te=N[Q],Ee=N[ie],q=Te.start+Te.count,We=je(Ee.start,b.width,4),et=je(Te.start,b.width,4);Ee.start<=q+1&&We===et&&je(Ee.start+Ee.count-1,b.width,4)===We?Te.count=Math.max(Te.count,Ee.start+Ee.count-Te.start):(++Q,N[Q]=Ee)}N.length=Q+1;let pe=r.getParameter(r.UNPACK_ROW_LENGTH),be=r.getParameter(r.UNPACK_SKIP_PIXELS),Oe=r.getParameter(r.UNPACK_SKIP_ROWS);r.pixelStorei(r.UNPACK_ROW_LENGTH,b.width);for(let ie=0,Te=N.length;ie<Te;ie++){let Ee=N[ie],q=Math.floor(Ee.start/4),We=Math.ceil(Ee.count/4),et=q%b.width,ut=Math.floor(q/b.width),C=We,$=1;r.pixelStorei(r.UNPACK_SKIP_PIXELS,et),r.pixelStorei(r.UNPACK_SKIP_ROWS,ut),t.texSubImage2D(r.TEXTURE_2D,0,et,ut,C,$,P,X,b.data)}S.clearUpdateRanges(),r.pixelStorei(r.UNPACK_ROW_LENGTH,pe),r.pixelStorei(r.UNPACK_SKIP_PIXELS,be),r.pixelStorei(r.UNPACK_SKIP_ROWS,Oe)}}function Be(S,b,P){let X=r.TEXTURE_2D,K=ot(S,b),N=b.source;t.bindTexture(X,S.__webglTexture,r.TEXTURE0+P);let Q=n.get(N);if(N.version!==Q.__version||K===!0){t.activeTexture(r.TEXTURE0+P);let pe=Ne.getPrimaries(Ne.workingColorSpace),be=b.colorSpace===""?null:Ne.getPrimaries(b.colorSpace),Oe=b.colorSpace===""||pe===be?r.NONE:r.BROWSER_DEFAULT_WEBGL;r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,b.flipY),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,b.premultiplyAlpha),r.pixelStorei(r.UNPACK_ALIGNMENT,b.unpackAlignment),r.pixelStorei(r.UNPACK_COLORSPACE_CONVERSION_WEBGL,Oe);let ie=v(b.image,!1,i.maxTextureSize);ie=Ae(b,ie);let Te=o.convert(b.format,b.colorSpace),Ee=o.convert(b.type),q=A(b.internalFormat,Te,Ee,b.colorSpace,!1);ze(X,b);let We,et=b.mipmaps,ut=!0,C=Q.__version===void 0||K===!0,$=N.dataReady,se=w(b,ie);if(b.isDepthTexture)q=U(b.format==="depth-stencil",b.type),C&&(ut?t.texStorage2D(r.TEXTURE_2D,1,q,ie.width,ie.height):t.texImage2D(r.TEXTURE_2D,0,q,ie.width,ie.height,0,Te,Ee,null));else if(b.isDataTexture)if(et.length>0){ut&&C&&t.texStorage2D(r.TEXTURE_2D,se,q,et[0].width,et[0].height);for(let le=0,ye=et.length;le<ye;le++)We=et[le],ut?$&&t.texSubImage2D(r.TEXTURE_2D,le,0,0,We.width,We.height,Te,Ee,We.data):t.texImage2D(r.TEXTURE_2D,le,q,We.width,We.height,0,Te,Ee,We.data);b.generateMipmaps=!1}else ut?(C&&t.texStorage2D(r.TEXTURE_2D,se,q,ie.width,ie.height),$&&Fe(b,ie,Te,Ee)):t.texImage2D(r.TEXTURE_2D,0,q,ie.width,ie.height,0,Te,Ee,ie.data);else if(et.length>0){if(ut&&C){let le=_e(et[0]);t.texStorage2D(r.TEXTURE_2D,se,q,le.width,le.height)}for(let le=0,ye=et.length;le<ye;le++)We=et[le],ut?$&&t.texSubImage2D(r.TEXTURE_2D,le,0,0,Te,Ee,We):t.texImage2D(r.TEXTURE_2D,le,q,Te,Ee,We);b.generateMipmaps=!1}else if(ut){if(C){let le=_e(ie);t.texStorage2D(r.TEXTURE_2D,se,q,le.width,le.height)}$&&t.texSubImage2D(r.TEXTURE_2D,0,0,0,Te,Ee,ie)}else t.texImage2D(r.TEXTURE_2D,0,q,Te,Ee,ie);M(b)&&T(X),Q.__version=N.version,b.onUpdate&&b.onUpdate(b)}S.__version=b.version}function He(S,b,P,X,K,N){let Q=o.convert(P.format,P.colorSpace),pe=o.convert(P.type),be=A(P.internalFormat,Q,pe,P.colorSpace),Oe=m(b),ie=h(P);if(ie.__renderTarget=b,!Oe.__hasExternalTextures){let Te=Math.max(1,b.width>>N),Ee=Math.max(1,b.height>>N);t.texImage2D(K,N,be,Te,Ee,0,Q,pe,null)}t.bindFramebuffer(r.FRAMEBUFFER,S),ce(b)?s.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,X,K,ie.__webglTexture,0,ue(b)):(K===r.TEXTURE_2D||K>=r.TEXTURE_CUBE_MAP_POSITIVE_X&&K<=r.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&r.framebufferTexture2D(r.FRAMEBUFFER,X,K,ie.__webglTexture,N),t.bindFramebuffer(r.FRAMEBUFFER,null)}function lt(S,b,P){if(r.bindRenderbuffer(r.RENDERBUFFER,S),b.depthBuffer){let X=b.depthTexture,K=X&&X.isDepthTexture?X.type:null,N=U(b.stencilBuffer,K),Q=b.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,pe=ue(b);ce(b)?s.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,pe,N,b.width,b.height):P?r.renderbufferStorageMultisample(r.RENDERBUFFER,pe,N,b.width,b.height):r.renderbufferStorage(r.RENDERBUFFER,N,b.width,b.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,Q,r.RENDERBUFFER,S)}else{let X=b.textures;for(let K=0;K<X.length;K++){let N=X[K],Q=o.convert(N.format,N.colorSpace),pe=o.convert(N.type),be=A(N.internalFormat,Q,pe,N.colorSpace),Oe=ue(b);P&&ce(b)===!1?r.renderbufferStorageMultisample(r.RENDERBUFFER,Oe,be,b.width,b.height):ce(b)?s.renderbufferStorageMultisampleEXT(r.RENDERBUFFER,Oe,be,b.width,b.height):r.renderbufferStorage(r.RENDERBUFFER,be,b.width,b.height)}}r.bindRenderbuffer(r.RENDERBUFFER,null)}function Nt(S,b){if(t.bindFramebuffer(r.FRAMEBUFFER,S),!(b.depthTexture&&b.depthTexture.isDepthTexture))throw new Error("keel/lit: renderTarget.depthTexture must be a DepthTexture");let P=b.depthTexture,X=h(P);X.__renderTarget=b;let K=P.image;(!X.__webglTexture||K.width!==b.width||K.height!==b.height)&&(K.width=b.width,K.height=b.height,P.needsUpdate=!0),re(P,0);let N=X.__webglTexture,Q=ue(b);if(P.format==="depth")ce(b)?s.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,N,0,Q):r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.TEXTURE_2D,N,0);else if(P.format==="depth-stencil")ce(b)?s.framebufferTexture2DMultisampleEXT(r.FRAMEBUFFER,r.DEPTH_STENCIL_ATTACHMENT,r.TEXTURE_2D,N,0,Q):r.framebufferTexture2D(r.FRAMEBUFFER,r.DEPTH_STENCIL_ATTACHMENT,r.TEXTURE_2D,N,0);else throw new Error("keel/lit: Unknown depthTexture format")}function J(S){let b=m(S);if(b.__boundDepthTexture!==S.depthTexture){let P=S.depthTexture;if(b.__depthDisposeCallback&&b.__depthDisposeCallback(),P){let X=()=>{delete b.__boundDepthTexture,delete b.__depthDisposeCallback,P.removeEventListener("dispose",X)};P.addEventListener("dispose",X),b.__depthDisposeCallback=X}b.__boundDepthTexture=P}if(S.depthTexture&&!b.__autoAllocateDepthBuffer){let P=S.texture.mipmaps;P&&P.length>0?Nt(b.__webglFramebuffer[0],S):Nt(b.__webglFramebuffer,S)}else{let P=S.texture.mipmaps;if(P&&P.length>0?t.bindFramebuffer(r.FRAMEBUFFER,b.__webglFramebuffer[0]):t.bindFramebuffer(r.FRAMEBUFFER,b.__webglFramebuffer),b.__webglDepthbuffer===void 0)b.__webglDepthbuffer=r.createRenderbuffer(),lt(b.__webglDepthbuffer,S,!1);else{let X=S.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,K=b.__webglDepthbuffer;r.bindRenderbuffer(r.RENDERBUFFER,K),r.framebufferRenderbuffer(r.FRAMEBUFFER,X,r.RENDERBUFFER,K)}}t.bindFramebuffer(r.FRAMEBUFFER,null)}function Je(S,b,P){let X=m(S);b!==void 0&&He(X.__webglFramebuffer,S,S.texture,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,0),P!==void 0&&J(S)}function H(S){let b=S.texture,P=m(S),X=h(b);S.addEventListener("dispose",p);let K=S.textures,N=K.length>1;if(N||(X.__webglTexture===void 0&&(X.__webglTexture=r.createTexture()),X.__version=b.version,a.memory.textures++),b.mipmaps&&b.mipmaps.length>0){let Q=[];P.__webglFramebuffer=Q;for(let pe=0;pe<b.mipmaps.length;pe++)Q[pe]=r.createFramebuffer()}else P.__webglFramebuffer=r.createFramebuffer();if(N)for(let Q=0,pe=K.length;Q<pe;Q++){let be=h(K[Q]);be.__webglTexture===void 0&&(be.__webglTexture=r.createTexture(),a.memory.textures++)}if(S.samples>0&&ce(S)===!1){let Q=r.createFramebuffer(),pe=[];P.__webglMultisampledFramebuffer=Q,P.__webglColorRenderbuffer=pe,t.bindFramebuffer(r.FRAMEBUFFER,Q);for(let be=0;be<K.length;be++){let Oe=K[be],ie=r.createRenderbuffer();pe[be]=ie,r.bindRenderbuffer(r.RENDERBUFFER,ie);let Te=o.convert(Oe.format,Oe.colorSpace),Ee=o.convert(Oe.type),q=A(Oe.internalFormat,Te,Ee,Oe.colorSpace,!1),We=ue(S);r.renderbufferStorageMultisample(r.RENDERBUFFER,We,q,S.width,S.height),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+be,r.RENDERBUFFER,ie)}if(r.bindRenderbuffer(r.RENDERBUFFER,null),S.depthBuffer){let be=r.createRenderbuffer();P.__webglDepthRenderbuffer=be,lt(be,S,!0)}t.bindFramebuffer(r.FRAMEBUFFER,null)}if(N){for(let Q=0,pe=K.length;Q<pe;Q++){let be=K[Q],Oe=h(be),ie=r.TEXTURE_2D;t.bindTexture(ie,Oe.__webglTexture),ze(ie,be),He(P.__webglFramebuffer,S,be,r.COLOR_ATTACHMENT0+Q,ie,0),M(be)&&T(ie)}t.unbindTexture()}else{let Q=r.TEXTURE_2D;if(t.bindTexture(Q,X.__webglTexture),ze(Q,b),b.mipmaps&&b.mipmaps.length>0)for(let pe=0;pe<b.mipmaps.length;pe++)He(P.__webglFramebuffer[pe],S,b,r.COLOR_ATTACHMENT0,Q,pe);else He(P.__webglFramebuffer,S,b,r.COLOR_ATTACHMENT0,Q,0);M(b)&&T(Q),t.unbindTexture()}S.depthBuffer&&J(S)}function ee(S){let b=S.textures;for(let P=0,X=b.length;P<X;P++){let K=b[P];if(M(K)){let N=_(S),Q=h(K).__webglTexture;t.bindTexture(N,Q),T(N),t.unbindTexture()}}}let k=[],te=[];function j(S){if(S.samples>0){if(ce(S)===!1){let b=S.textures,P=S.width,X=S.height,K=r.COLOR_BUFFER_BIT,N=S.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT,Q=m(S),pe=b.length>1,be=Q.__webglFramebuffer;if(pe)for(let ie=0;ie<b.length;ie++)t.bindFramebuffer(r.FRAMEBUFFER,Q.__webglMultisampledFramebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+ie,r.RENDERBUFFER,null),t.bindFramebuffer(r.FRAMEBUFFER,be),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0+ie,r.TEXTURE_2D,null,0);t.bindFramebuffer(r.READ_FRAMEBUFFER,Q.__webglMultisampledFramebuffer);let Oe=S.texture.mipmaps;Oe&&Oe.length>0?t.bindFramebuffer(r.DRAW_FRAMEBUFFER,Q.__webglFramebuffer[0]):t.bindFramebuffer(r.DRAW_FRAMEBUFFER,be);for(let ie=0;ie<b.length;ie++){if(S.resolveDepthBuffer&&(S.depthBuffer&&(K|=r.DEPTH_BUFFER_BIT),S.stencilBuffer&&S.resolveStencilBuffer&&(K|=r.STENCIL_BUFFER_BIT)),pe){r.framebufferRenderbuffer(r.READ_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.RENDERBUFFER,Q.__webglColorRenderbuffer[ie]);let Te=h(b[ie]).__webglTexture;r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,Te,0)}r.blitFramebuffer(0,0,P,X,0,0,P,X,K,r.NEAREST),l===!0&&(k.length=0,te.length=0,k.push(r.COLOR_ATTACHMENT0+ie),S.depthBuffer&&S.resolveDepthBuffer===!1&&(k.push(N),te.push(N),r.invalidateFramebuffer(r.DRAW_FRAMEBUFFER,te)),r.invalidateFramebuffer(r.READ_FRAMEBUFFER,k))}if(t.bindFramebuffer(r.READ_FRAMEBUFFER,null),t.bindFramebuffer(r.DRAW_FRAMEBUFFER,null),pe)for(let ie=0;ie<b.length;ie++){t.bindFramebuffer(r.FRAMEBUFFER,Q.__webglMultisampledFramebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+ie,r.RENDERBUFFER,Q.__webglColorRenderbuffer[ie]);let Te=h(b[ie]).__webglTexture;t.bindFramebuffer(r.FRAMEBUFFER,be),r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0+ie,r.TEXTURE_2D,Te,0)}t.bindFramebuffer(r.DRAW_FRAMEBUFFER,Q.__webglMultisampledFramebuffer)}else if(S.depthBuffer&&S.resolveDepthBuffer===!1&&l){let b=S.stencilBuffer?r.DEPTH_STENCIL_ATTACHMENT:r.DEPTH_ATTACHMENT;r.invalidateFramebuffer(r.DRAW_FRAMEBUFFER,[b])}}}function ue(S){return Math.min(i.maxSamples,S.samples)}function ce(S){let b=m(S);return S.samples>0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&b.__useRenderToTexture!==!1}function Ae(S,b){let P=S.colorSpace,X=S.format,K=S.type;return P!=="linear"&&P!==""&&(Ne.getTransfer(P)==="srgb"?(X!=="rgba"||K!=="u8")&&console.warn("keel/lit: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("keel/lit: Unsupported texture color space:",P)),b}function _e(S){return typeof HTMLImageElement<"u"&&S instanceof HTMLImageElement?(c.width=S.naturalWidth||S.width,c.height=S.naturalHeight||S.height):typeof VideoFrame<"u"&&S instanceof VideoFrame?(c.width=S.displayWidth,c.height=S.displayHeight):(c.width=S.width,c.height=S.height),c}return{allocateTextureUnit:B,resetTextureUnits:G,setTexture2D:re,setTexture2DArray:Y,setTexture3D:ae,setTextureCube:he,rebindTextures:Je,setupRenderTarget:H,updateRenderTargetMipmap:ee,updateMultisampleRenderTarget:j,setupDepthRenderbuffer:J,setupFrameBufferTexture:He,useMultisampledRTT:ce}}var fc=bt.u8,pc=bt.i8,gc=bt.i16,bc=bt.u16,xc=bt.int,vc=bt.uint,yc=bt.float,Mc=bt.half,Sc=bt.u4444,_c=bt.u5551,Tc=bt["depth24-stencil8"],Ac=bt.u5999,Ec=bt.u101111,wc=_t.alpha,Cc=_t.rgb,Lc=_t.rgba,Rc=_t.depth,Pc=_t["depth-stencil"],Uc=_t.red,Ic=_t["red-integer"],Dc=_t.rg,Fc=_t["rg-integer"],Nc=_t["rgba-integer"];function Fa(r,e){function t(n,i=""){let o=bt[n]??_t[n];if(o===fc)return r.UNSIGNED_BYTE;if(o===Sc)return r.UNSIGNED_SHORT_4_4_4_4;if(o===_c)return r.UNSIGNED_SHORT_5_5_5_1;if(o===Ac)return r.UNSIGNED_INT_5_9_9_9_REV;if(o===Ec)return r.UNSIGNED_INT_10F_11F_11F_REV;if(o===pc)return r.BYTE;if(o===gc)return r.SHORT;if(o===bc)return r.UNSIGNED_SHORT;if(o===xc)return r.INT;if(o===vc)return r.UNSIGNED_INT;if(o===yc)return r.FLOAT;if(o===Mc)return r.HALF_FLOAT;if(o===wc)return r.ALPHA;if(o===Cc)return r.RGB;if(o===Lc)return r.RGBA;if(o===Rc)return r.DEPTH_COMPONENT;if(o===Pc)return r.DEPTH_STENCIL;if(o===Uc)return r.RED;if(o===Ic)return r.RED_INTEGER;if(o===Dc)return r.RG;if(o===Fc)return r.RG_INTEGER;if(o===Nc)return r.RGBA_INTEGER;if(o===Tc)return r.UNSIGNED_INT_24_8;if(o!==void 0)return null;let a=r[n];return a!==void 0?a:null}return{convert:t}}function Vc(){let r=document.createElement("canvas");return r.style.display="block",r}var Oc=new Set(["rgba-integer","rg-integer","red-integer"]),kc=new Set(["u8","uint","u16","depth24-stencil8","u4444","u5551"]);function zc(r={}){let{canvas:e=Vc(),context:t=null,depth:n=!0,stencil:i=!1,alpha:o=!1,antialias:a=!1,premultipliedAlpha:s=!0,preserveDrawingBuffer:l=!1,powerPreference:c="default",failIfMajorPerformanceCaveat:d=!1,reversedDepthBuffer:u=!1}=r,h;t!==null?h=t.getContextAttributes().alpha:h=o;let m=new Uint32Array(4),f=new Int32Array(4),g=null,v=null,M=[],T=[],_=!1,A="srgb",U=0,w=0,E=null,p=-1,y=null,R=new Ze,D=new Ze,F=null,G=new Pe(0),B=0,Z=e.width,re=e.height,oe=1,Y=null,ae=null,he=new Ze(0,0,Z,re),me=new Ze(0,0,Z,re),Ue=!1,Ge=new Ht,ze=!1,ot=!1,je=new Ve,Fe=new L,Be=new Ze,He={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0},lt=!1;function Nt(){return E===null?oe:1}let J=t;function Je(x,I){return e.getContext(x,I)}try{let x={alpha:!0,depth:n,stencil:i,antialias:a,premultipliedAlpha:s,preserveDrawingBuffer:l,powerPreference:c,failIfMajorPerformanceCaveat:d};if("setAttribute"in e&&e.setAttribute("data-engine","keel/lit (three.js r180)"),e.addEventListener("webglcontextlost",et,!1),e.addEventListener("webglcontextrestored",ut,!1),e.addEventListener("webglcontextcreationerror",C,!1),J===null){let I="webgl2";if(J=Je(I,x),J===null)throw Je(I)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}}catch(x){throw console.error("keel/lit renderer: "+x.message),x}let H,ee,k,te,j,ue,ce,Ae,_e,S,b,P,X,K,N,Q,pe,be,Oe,ie,Te,Ee,q={};function We(){H=Ko(J),H.init(),Te=Fa(J,H),ee=Xo(J,H,r,Te),k=Ia(J,H),ee.reversedDepthBuffer&&u&&k.buffers.depth.setReversed(!0),te=Jo(J),j=Aa(),ue=Da(J,H,k,j,ee,Te,te),ce=Yo(q),Ae=jo(q),_e=zo(J),Ee=Ho(J,_e),S=Qo(J,_e,te,Ee),b=ea(J,S,_e,te),Q=qo(j),P=Ta(q,ce,Ae,H,ee,Ee,Q),X=Bo(q,j),K=Ca(),N=Pa(H),be=Go(q,ce,Ae,k,b,h,s),pe=Ua(q,b,ee),Oe=Wo(J,H,te),ie=$o(J,H,te),te.programs=P.programs,q.capabilities=ee,q.extensions=H,q.properties=j,q.renderLists=K,q.shadowMap=pe,q.state=k,q.info=te}Object.assign(q,{isLitRenderer:!0,isWebGLRenderer:!0,domElement:e,debug:{checkShaderErrors:!0,onShaderError:null},autoClear:!0,autoClearColor:!0,autoClearDepth:!0,autoClearStencil:!0,sortObjects:!0,clippingPlanes:[],localClippingEnabled:!1,toneMapping:"none",toneMappingExposure:1,transmissionResolutionScale:1}),Object.defineProperties(q,{coordinateSystem:{get:()=>"webgl",enumerable:!0},outputColorSpace:{enumerable:!0,get:()=>A,set:x=>{A=x;let I=J;I.drawingBufferColorSpace=Ne._getDrawingBufferColorSpace(x),I.unpackColorSpace=Ne._getUnpackColorSpace()}}}),We(),q.getContext=function(){return J},q.getContextAttributes=function(){return J.getContextAttributes()},q.forceContextLoss=function(){let x=H.get("WEBGL_lose_context");x&&x.loseContext()},q.forceContextRestore=function(){let x=H.get("WEBGL_lose_context");x&&x.restoreContext()},q.getPixelRatio=function(){return oe},q.setPixelRatio=function(x){x!==void 0&&(oe=x,this.setSize(Z,re,!1))},q.getSize=function(x){return x.set(Z,re)},q.setSize=function(x,I,O=!0){Z=x,re=I,e.width=Math.floor(x*oe),e.height=Math.floor(I*oe),O===!0&&(e.style.width=x+"px",e.style.height=I+"px"),this.setViewport(0,0,x,I)},q.getDrawingBufferSize=function(x){return x.set(Z*oe,re*oe).floor()},q.setDrawingBufferSize=function(x,I,O){Z=x,re=I,oe=O,e.width=Math.floor(x*O),e.height=Math.floor(I*O),this.setViewport(0,0,x,I)},q.getCurrentViewport=function(x){return x.copy(R)},q.getViewport=function(x){return x.copy(he)},q.setViewport=function(x,I,O,z){typeof x=="object"&&x.isVector4?he.set(x.x,x.y,x.z,x.w):he.set(x,I,O,z),k.viewport(R.copy(he).multiplyScalar(oe).round())},q.getScissor=function(x){return x.copy(me)},q.setScissor=function(x,I,O,z){typeof x=="object"&&x.isVector4?me.set(x.x,x.y,x.z,x.w):me.set(x,I,O,z),k.scissor(D.copy(me).multiplyScalar(oe).round())},q.getScissorTest=function(){return Ue},q.setScissorTest=function(x){k.setScissorTest(Ue=x)},q.setOpaqueSort=function(x){Y=x},q.setTransparentSort=function(x){ae=x},q.getClearColor=function(x){return x.copy(be.getClearColor())},q.setClearColor=function(...x){be.setClearColor(...x)},q.getClearAlpha=function(){return be.getClearAlpha()},q.setClearAlpha=function(...x){be.setClearAlpha(...x)},q.clear=function(x=!0,I=!0,O=!0){let z=0;if(x){let V=!1;if(E!==null){let xe=E.texture.format;V=Oc.has(xe)}if(V){let xe=E.texture.type,Me=kc.has(xe),we=be.getClearColor(),fe=be.getClearAlpha(),Re=we.r,Le=we.g,Se=we.b;Me?(m[0]=Re,m[1]=Le,m[2]=Se,m[3]=fe,J.clearBufferuiv(J.COLOR,0,m)):(f[0]=Re,f[1]=Le,f[2]=Se,f[3]=fe,J.clearBufferiv(J.COLOR,0,f))}else z|=J.COLOR_BUFFER_BIT}I&&(z|=J.DEPTH_BUFFER_BIT),O&&(z|=J.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),J.clear(z)},q.clearColor=function(){this.clear(!0,!1,!1)},q.clearDepth=function(){this.clear(!1,!0,!1)},q.clearStencil=function(){this.clear(!1,!1,!0)},q.dispose=function(){e.removeEventListener("webglcontextlost",et,!1),e.removeEventListener("webglcontextrestored",ut,!1),e.removeEventListener("webglcontextcreationerror",C,!1),be.dispose(),K.dispose(),N.dispose(),j.dispose(),ce.dispose(),Ae.dispose(),b.dispose(),Ee.dispose(),P.dispose(),ke.stop()};function et(x){x.preventDefault(),console.log("keel/lit renderer: Context Lost."),_=!0}function ut(){console.log("keel/lit renderer: Context Restored."),_=!1;let x=te.autoReset,I=pe.enabled,O=pe.autoUpdate,z=pe.needsUpdate,V=pe.type;We(),te.autoReset=x,pe.enabled=I,pe.autoUpdate=O,pe.needsUpdate=z,pe.type=V}function C(x){console.error("keel/lit renderer: A WebGL context could not be created. Reason: ",x.statusMessage)}function $(x){let I=x.target;I.removeEventListener("dispose",$),se(I)}function se(x){le(x),j.remove(x)}function le(x){let I=j.get(x).programs;I!==void 0&&(I.forEach(function(O){P.releaseProgram(O)}),x.isShaderMaterial&&P.releaseShaderCache(x))}q.renderBufferDirect=function(x,I,O,z,V,xe){I===null&&(I=He);let Me=V.isMesh&&V.matrixWorld.determinant()<0,we=Na(x,I,O,z,V);k.setMaterial(z,Me);let fe=O.index,Re=1;if(z.wireframe===!0){if(fe=S.getWireframeAttribute(O),fe===void 0)return;Re=2}let Le=O.drawRange,Se=O.attributes.position,qe=Le.start*Re,Bt=(Le.start+Le.count)*Re;xe!==null&&(qe=Math.max(qe,xe.start*Re),Bt=Math.min(Bt,(xe.start+xe.count)*Re)),fe!==null?(qe=Math.max(qe,0),Bt=Math.min(Bt,fe.count)):Se!=null&&(qe=Math.max(qe,0),Bt=Math.min(Bt,Se.count));let Zt=Bt-qe;if(Zt<0||Zt===1/0)return;Ee.setup(V,z,we,O,fe);let Vr,Vt=Oe;if(fe!==null&&(Vr=_e.get(fe),Vt=ie,Vt.setIndex(Vr)),V.isMesh?z.wireframe===!0?(k.setLineWidth(z.wireframeLinewidth*Nt()),Vt.setMode(J.LINES)):Vt.setMode(J.TRIANGLES):V.isSprite&&Vt.setMode(J.TRIANGLES),V.isInstancedMesh)Vt.renderInstances(qe,Zt,V.count);else if(O.isInstancedBufferGeometry){let Ie=O._maxInstanceCount!==void 0?O._maxInstanceCount:1/0,Hn=Math.min(O.instanceCount,Ie);Vt.renderInstances(qe,Zt,Hn)}else Vt.render(qe,Zt)};function ye(x,I,O){x.transparent===!0&&x.side==="both"&&x.forceSinglePass===!1?(x.side="back",x.needsUpdate=!0,mn(x,I,O),x.side="front",x.needsUpdate=!0,mn(x,I,O),x.side="both"):mn(x,I,O)}q.compile=function(x,I,O=null){O===null&&(O=x),v=N.get(O),v.init(I),T.push(v),O.traverseVisible(function(V){V.isLight&&V.layers.test(I.layers)&&(v.pushLight(V),V.castShadow&&v.pushShadow(V))}),x!==O&&x.traverseVisible(function(V){V.isLight&&V.layers.test(I.layers)&&(v.pushLight(V),V.castShadow&&v.pushShadow(V))}),v.setupLights();let z=new Set;return x.traverse(function(V){if(!(V.isMesh||V.isPoints||V.isLine||V.isSprite))return;let xe=V.material;if(xe)if(Array.isArray(xe))for(let Me=0;Me<xe.length;Me++){let we=xe[Me];ye(we,O,V),z.add(we)}else ye(xe,O,V),z.add(xe)}),v=T.pop(),z},q.compileAsync=function(x,I,O=null){let z=this.compile(x,I,O);return new Promise(V=>{function xe(){if(z.forEach(function(Me){j.get(Me).currentProgram.isReady()&&z.delete(Me)}),z.size===0){V(x);return}setTimeout(xe,10)}H.get("KHR_parallel_shader_compile")!==null?xe():setTimeout(xe,10)})};let ge=null;function De(x){ge&&ge(x)}let ke=ko();ke.setAnimationLoop(De),typeof self<"u"&&ke.setContext(self),q.setAnimationLoop=function(x){ge=x,x===null?ke.stop():ke.start()},q.render=function(x,I){if(I!==void 0&&I.isCamera!==!0){console.error("keel/lit renderer.render: camera is not a Camera.");return}if(_===!0)return;x.matrixWorldAutoUpdate===!0&&x.updateMatrixWorld(),I.parent===null&&I.matrixWorldAutoUpdate===!0&&I.updateMatrixWorld(),x.isScene===!0&&x.onBeforeRender(q,x,I,E),v=N.get(x,T.length),v.init(I),T.push(v),je.multiplyMatrices(I.projectionMatrix,I.matrixWorldInverse),Ge.setFromProjectionMatrix(je,"webgl",I.reversedDepth),ot=this.localClippingEnabled,ze=Q.init(this.clippingPlanes,ot),g=K.get(x,M.length),g.init(),M.push(g),Et(x,I,0,q.sortObjects),g.finish(),q.sortObjects===!0&&g.sort(Y,ae),lt=!0,lt&&be.addToRenderList(g,x),this.info.render.frame++,ze===!0&&Q.beginShadows();let O=v.state.shadowsArray;pe.render(O,x,I),ze===!0&&Q.endShadows(),this.info.autoReset===!0&&this.info.reset();let z=g.transmissive;v.setupLights(),z.length>0&&console.warn("keel/lit renderer: transmissive objects are not drawn by keel/lit."),lt&&be.render(x),Xe(g,x,I),E!==null&&w===0&&(ue.updateMultisampleRenderTarget(E),ue.updateRenderTargetMipmap(E)),x.isScene===!0&&x.onAfterRender(q,x,I),Ee.resetDefaultState(),p=-1,y=null,T.pop(),T.length>0?(v=T[T.length-1],ze===!0&&Q.setGlobalState(q.clippingPlanes,v.state.camera)):v=null,M.pop(),M.length>0?g=M[M.length-1]:g=null};function Et(x,I,O,z){if(x.visible===!1)return;if(x.layers.test(I.layers)){if(x.isGroup)O=x.renderOrder;else if(x.isLight)v.pushLight(x),x.castShadow&&v.pushShadow(x);else if(x.isSprite){if(!x.frustumCulled||Ge.intersectsSprite(x)){z&&Be.setFromMatrixPosition(x.matrixWorld).applyMatrix4(je);let Me=b.update(x),we=x.material;we.visible&&g.push(x,Me,we,O,Be.z,null)}}else if(x.isMesh&&(!x.frustumCulled||Ge.intersectsObject(x))){let Me=b.update(x),we=x.material;if(z&&(x.boundingSphere!==void 0?(x.boundingSphere===null&&x.computeBoundingSphere(),Be.copy(x.boundingSphere.center)):(Me.boundingSphere===null&&Me.computeBoundingSphere(),Be.copy(Me.boundingSphere.center)),Be.applyMatrix4(x.matrixWorld).applyMatrix4(je)),Array.isArray(we)){let fe=Me.groups;for(let Re=0,Le=fe.length;Re<Le;Re++){let Se=fe[Re],qe=we[Se.materialIndex];qe&&qe.visible&&g.push(x,Me,qe,O,Be.z,Se)}}else we.visible&&g.push(x,Me,we,O,Be.z,null)}}let xe=x.children;for(let Me=0,we=xe.length;Me<we;Me++)Et(xe[Me],I,O,z)}function Xe(x,I,O,z){let V=x.opaque,xe=x.transmissive,Me=x.transparent;v.setupLightsView(O),ze===!0&&Q.setGlobalState(q.clippingPlanes,O),z&&k.viewport(R.copy(z)),V.length>0&&Lt(V,I,O),xe.length>0&&Lt(xe,I,O),Me.length>0&&Lt(Me,I,O),k.buffers.depth.setTest(!0),k.buffers.depth.setMask(!0),k.buffers.color.setMask(!0),k.setPolygonOffset(!1)}function Lt(x,I,O){let z=I.isScene===!0?I.overrideMaterial:null;for(let V=0,xe=x.length;V<xe;V++){let Me=x[V],we=Me.object,fe=Me.geometry,Re=Me.group,Le=Me.material;Le.allowOverride===!0&&z!==null&&(Le=z),we.layers.test(O.layers)&&zt(we,I,O,fe,Le,Re)}}function zt(x,I,O,z,V,xe){x.onBeforeRender(q,I,O,z,V,xe),x.modelViewMatrix.multiplyMatrices(O.matrixWorldInverse,x.matrixWorld),x.normalMatrix.getNormalMatrix(x.modelViewMatrix),V.onBeforeRender(q,I,O,z,x,xe),V.transparent===!0&&V.side==="both"&&V.forceSinglePass===!1?(V.side="back",V.needsUpdate=!0,q.renderBufferDirect(O,I,z,V,x,xe),V.side="front",V.needsUpdate=!0,q.renderBufferDirect(O,I,z,V,x,xe),V.side="both"):q.renderBufferDirect(O,I,z,V,x,xe),x.onAfterRender(q,I,O,z,V,xe)}function mn(x,I,O){I.isScene!==!0&&(I=He);let z=j.get(x),V=v.state.lights,xe=v.state.shadowsArray,Me=V.state.version,we=P.getParameters(x,V.state,xe,I,O),fe=P.getProgramCacheKey(we),Re=z.programs;z.environment=x.isMeshStandardMaterial?I.environment:null,z.fog=I.fog,z.envMap=(x.isMeshStandardMaterial?Ae:ce).get(x.envMap||z.environment),z.envMapRotation=z.environment!==null&&x.envMap===null?I.environmentRotation:x.envMapRotation,Re===void 0&&(x.addEventListener("dispose",$),Re=new Map,z.programs=Re);let Le=Re.get(fe);if(Le!==void 0){if(z.currentProgram===Le&&z.lightsStateVersion===Me)return Ki(x,we),Le}else we.uniforms=P.getUniforms(x),x.onCompile(we,q),Le=P.acquireProgram(we,fe),Re.set(fe,Le),z.uniforms=we.uniforms;let Se=z.uniforms;return(!x.isShaderMaterial&&!x.isRawShaderMaterial||x.clipping===!0)&&(Se.clippingPlanes=Q.uniform),Ki(x,we),z.needsLights=Oa(x),z.lightsStateVersion=Me,z.needsLights&&(Se.ambientLightColor.value=V.state.ambient,Se.lightProbe.value=V.state.probe,Se.directionalLights.value=V.state.directional,Se.directionalLightShadows.value=V.state.directionalShadow,Se.spotLights.value=V.state.spot,Se.spotLightShadows.value=V.state.spotShadow,Se.rectAreaLights.value=V.state.rectArea,Se.ltc_1.value=V.state.rectAreaLTC1,Se.ltc_2.value=V.state.rectAreaLTC2,Se.pointLights.value=V.state.point,Se.pointLightShadows.value=V.state.pointShadow,Se.hemisphereLights.value=V.state.hemi,Se.directionalShadowMap.value=V.state.directionalShadowMap,Se.directionalShadowMatrix.value=V.state.directionalShadowMatrix,Se.spotShadowMap.value=V.state.spotShadowMap,Se.spotLightMatrix.value=V.state.spotLightMatrix,Se.spotLightMap.value=V.state.spotLightMap,Se.pointShadowMap.value=V.state.pointShadowMap,Se.pointShadowMatrix.value=V.state.pointShadowMatrix),z.currentProgram=Le,z.uniformsList=null,Le}function Zi(x){if(x.uniformsList===null){let I=x.currentProgram.getUniforms();x.uniformsList=ma(I.seq,x.uniforms)}return x.uniformsList}function Ki(x,I){let O=j.get(x);O.outputColorSpace=I.outputColorSpace,O.batching=I.batching,O.batchingColor=I.batchingColor,O.instancing=I.instancing,O.instancingColor=I.instancingColor,O.instancingMorph=I.instancingMorph,O.skinning=I.skinning,O.morphTargets=I.morphTargets,O.morphNormals=I.morphNormals,O.morphColors=I.morphColors,O.morphTargetsCount=I.morphTargetsCount,O.numClippingPlanes=I.numClippingPlanes,O.numIntersection=I.numClipIntersection,O.vertexAlphas=I.vertexAlphas,O.vertexTangents=I.vertexTangents,O.toneMapping=I.toneMapping}function Na(x,I,O,z,V){I.isScene!==!0&&(I=He),ue.resetTextureUnits();let xe=I.fog,Me=z.isMeshStandardMaterial?I.environment:null,we=E===null?q.outputColorSpace:E.isXRRenderTarget===!0?E.texture.colorSpace:"linear",fe=(z.isMeshStandardMaterial?Ae:ce).get(z.envMap||Me),Re=z.vertexColors===!0&&!!O.attributes.color&&O.attributes.color.itemSize===4,Le=!!O.attributes.tangent&&(!!z.normalMap||z.anisotropy>0),Se=!!O.morphAttributes.position,qe=!!O.morphAttributes.normal,Bt=!!O.morphAttributes.color,Zt="none";z.toneMapped&&(E===null||E.isXRRenderTarget===!0)&&(Zt=q.toneMapping);let Vr=O.morphAttributes.position||O.morphAttributes.normal||O.morphAttributes.color,Vt=Vr!==void 0?Vr.length:0,Ie=j.get(z),Hn=v.state.lights;if(ze===!0&&(ot===!0||x!==y)){let $i=x===y&&z.id===p;Q.setState(z,x,$i)}let tt=!1;z.version===Ie.__version?(Ie.needsLights&&Ie.lightsStateVersion!==Hn.state.version||Ie.outputColorSpace!==we||Ie.batching===!0||V.isInstancedMesh&&Ie.instancing===!1||!V.isInstancedMesh&&Ie.instancing===!0||Ie.skinning===!0||V.isInstancedMesh&&Ie.instancingColor===!0&&V.instanceColor===null||V.isInstancedMesh&&Ie.instancingColor===!1&&V.instanceColor!==null||V.isInstancedMesh&&Ie.instancingMorph===!0&&V.morphTexture===null||V.isInstancedMesh&&Ie.instancingMorph===!1&&V.morphTexture!==null||Ie.envMap!==fe||z.fog===!0&&Ie.fog!==xe||Ie.numClippingPlanes!==void 0&&(Ie.numClippingPlanes!==Q.numPlanes||Ie.numIntersection!==Q.numIntersection)||Ie.vertexAlphas!==Re||Ie.vertexTangents!==Le||Ie.morphTargets!==Se||Ie.morphNormals!==qe||Ie.morphColors!==Bt||Ie.toneMapping!==Zt||Ie.morphTargetsCount!==Vt)&&(tt=!0):(tt=!0,Ie.__version=z.version);let fn=Ie.currentProgram;tt===!0&&(fn=mn(z,I,V));let Qi=!1,Or=!1,Wn=!1,Rt=fn.getUniforms(),_r=Ie.uniforms;if(k.useProgram(fn.program)&&(Qi=!0,Or=!0,Wn=!0),z.id!==p&&(p=z.id,Or=!0),Qi||y!==x){k.buffers.depth.getReversed()&&x.reversedDepth!==!0&&(x._reversedDepth=!0,x.updateProjectionMatrix()),Rt.setValue(J,"projectionMatrix",x.projectionMatrix),Rt.setValue(J,"viewMatrix",x.matrixWorldInverse);let Ji=Rt.map.cameraPosition;Ji!==void 0&&Ji.setValue(J,Fe.setFromMatrixPosition(x.matrixWorld)),ee.logarithmicDepthBuffer&&Rt.setValue(J,"logDepthBufFC",2/(Math.log(x.far+1)/Math.LN2)),(z.isMeshPhongMaterial||z.isMeshToonMaterial||z.isMeshLambertMaterial||z.isMeshBasicMaterial||z.isMeshStandardMaterial||z.isShaderMaterial)&&Rt.setValue(J,"isOrthographic",x.isOrthographicCamera===!0),y!==x&&(y=x,Or=!0,Wn=!0)}return(Or||Ie.receiveShadow!==V.receiveShadow)&&(Ie.receiveShadow=V.receiveShadow,Rt.setValue(J,"receiveShadow",V.receiveShadow)),z.isMeshStandardMaterial&&z.envMap===null&&I.environment!==null&&(_r.envMapIntensity.value=I.environmentIntensity*z.envMapIntensity),Or&&(Rt.setValue(J,"toneMappingExposure",q.toneMappingExposure),Ie.needsLights&&Va(_r,Wn),xe&&z.fog===!0&&X.refreshFogUniforms(_r,xe),X.refreshMaterialUniforms(_r,z,oe,re,v.state.transmissionRenderTarget[x.id]),Yi(J,Zi(Ie),_r,ue)),z.isShaderMaterial&&z.uniformsNeedUpdate===!0&&(Yi(J,Zi(Ie),_r,ue),z.uniformsNeedUpdate=!1),z.isSpriteMaterial&&Rt.setValue(J,"center",V.center),Rt.setValue(J,"modelViewMatrix",V.modelViewMatrix),Rt.setValue(J,"normalMatrix",V.normalMatrix),Rt.setValue(J,"modelMatrix",V.matrixWorld),z.isShaderMaterial&&z.uniformsGroups.length>0&&console.warn("keel/lit renderer: CustomMaterial.uniformsGroups is not supported."),fn}function Va(x,I){x.ambientLightColor.needsUpdate=I,x.lightProbe.needsUpdate=I,x.directionalLights.needsUpdate=I,x.directionalLightShadows.needsUpdate=I,x.pointLights.needsUpdate=I,x.pointLightShadows.needsUpdate=I,x.spotLights.needsUpdate=I,x.spotLightShadows.needsUpdate=I,x.rectAreaLights.needsUpdate=I,x.hemisphereLights.needsUpdate=I}function Oa(x){return x.isMeshLambertMaterial||x.isMeshToonMaterial||x.isMeshPhongMaterial||x.isMeshStandardMaterial||x.isShadowMaterial||x.isShaderMaterial&&x.lights===!0}q.getActiveCubeFace=function(){return U},q.getActiveMipmapLevel=function(){return w},q.getRenderTarget=function(){return E};let ka=J.createFramebuffer();return q.setRenderTarget=function(x,I=0,O=0){E=x,U=I,w=O;let z=!0,V=null,xe=!1,Me=!1;if(x){let fe=x,Re=j.get(fe);if(Re.__useDefaultFramebuffer!==void 0)k.bindFramebuffer(J.FRAMEBUFFER,null),z=!1;else if(Re.__webglFramebuffer===void 0)ue.setupRenderTarget(fe);else if(Re.__hasExternalTextures)ue.rebindTextures(fe,j.get(fe.texture).__webglTexture,j.get(fe.depthTexture).__webglTexture);else if(fe.depthBuffer){let qe=fe.depthTexture;if(Re.__boundDepthTexture!==qe){if(qe!==null&&j.has(qe)&&(fe.width!==qe.image.width||fe.height!==qe.image.height))throw new Error("RenderTarget: Attached DepthTexture is initialized to the incorrect size.");ue.setupDepthRenderbuffer(fe)}}let Le=fe.texture;(Le.isData3DTexture||Le.isDataArrayTexture||Le.isCompressedArrayTexture)&&(Me=!0);let Se=j.get(fe).__webglFramebuffer;fe.isWebGLCubeRenderTarget?(Array.isArray(Se[I])?V=Se[I][O]:V=Se[I],xe=!0):fe.samples>0&&ue.useMultisampledRTT(fe)===!1?V=j.get(fe).__webglMultisampledFramebuffer:Array.isArray(Se)?V=Se[O]:V=Se,R.copy(fe.viewport),D.copy(fe.scissor),F=fe.scissorTest}else R.copy(he).multiplyScalar(oe).floor(),D.copy(me).multiplyScalar(oe).floor(),F=Ue;if(O!==0&&(V=ka),k.bindFramebuffer(J.FRAMEBUFFER,V)&&z&&k.drawBuffers(x,V),k.viewport(R),k.scissor(D),k.setScissorTest(F),xe){let fe=j.get(x.texture);J.framebufferTexture2D(J.FRAMEBUFFER,J.COLOR_ATTACHMENT0,J.TEXTURE_CUBE_MAP_POSITIVE_X+I,fe.__webglTexture,O)}else if(Me){let fe=I,Re=x;for(let Le=0;Le<Re.textures.length;Le++){let Se=j.get(Re.textures[Le]);J.framebufferTextureLayer(J.FRAMEBUFFER,J.COLOR_ATTACHMENT0+Le,Se.__webglTexture,O,fe)}}else if(x!==null&&O!==0){let fe=j.get(x.texture);J.framebufferTexture2D(J.FRAMEBUFFER,J.COLOR_ATTACHMENT0,J.TEXTURE_2D,fe.__webglTexture,O)}p=-1},q.readRenderTargetPixels=function(x,I,O,z,V,xe,Me,we=0){let fe=x;if(!(fe&&fe.isWebGLRenderTarget)){console.error("keel/lit renderer.readRenderTargetPixels: renderTarget is not a RenderTarget.");return}let Re=j.get(fe).__webglFramebuffer;if(fe.isWebGLCubeRenderTarget&&Me!==void 0&&(Re=Re[Me]),Re){k.bindFramebuffer(J.FRAMEBUFFER,Re);try{let Le=fe.textures[we],Se=Le.format,qe=Le.type;if(!ee.textureFormatReadable(Se)){console.error("keel/lit renderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}if(!ee.textureTypeReadable(qe)){console.error("keel/lit renderer.readRenderTargetPixels: renderTarget is not in u8 or implementation defined type.");return}I>=0&&I<=fe.width-z&&O>=0&&O<=fe.height-V&&(fe.textures.length>1&&J.readBuffer(J.COLOR_ATTACHMENT0+we),J.readPixels(I,O,z,V,Te.convert(Se),Te.convert(qe),xe))}finally{let Le=E!==null?j.get(E).__webglFramebuffer:null;k.bindFramebuffer(J.FRAMEBUFFER,Le)}}},q.copyFramebufferToTexture=function(x,I=null,O=0){let z=Math.pow(2,-O),V=Math.floor(x.image.width*z),xe=Math.floor(x.image.height*z),Me=I!==null?I.x:0,we=I!==null?I.y:0;ue.setTexture2D(x,0),J.copyTexSubImage2D(J.TEXTURE_2D,O,0,0,Me,we,V,xe),k.unbindTexture()},q.initRenderTarget=function(x){j.get(x).__webglFramebuffer===void 0&&ue.setupRenderTarget(x)},q.initTexture=function(x){x.isCubeTexture?ue.setTextureCube(x,0):x.isData3DTexture?ue.setTexture3D(x,0):x.isDataArrayTexture||x.isCompressedArrayTexture?ue.setTexture2DArray(x,0):ue.setTexture2D(x,0),k.unbindTexture()},q.resetState=function(){U=0,w=0,E=null,k.reset(),Ee.reset()},q}export{wi as AmbientLight,hi as ArcCurve,de as Attribute,ps as BLENDING,gs as BLEND_EQUATION,bs as BLEND_FACTOR,Ai as Billboard,on as BillboardMaterial,St as Box3,ni as COLOR_SPACE,vs as COMBINE,ti as COMPARE_FUNC,Cs as COORDINATE_SYSTEM,ws as CULL_FACE,br as Camera,Di as CanvasTexture,gi as CatmullRomCurve3,Pe as Color,Zr as CubicBezierCurve,di as CubicBezierCurve3,Qe as Curve,Yr as CurvePath,yr as CustomMaterial,xs as DEPTH_FUNC,Ms as DEPTH_PACKING,nn as DataTexture,ln as DepthMaterial,cn as DepthTexture,un as DistanceMaterial,ci as Earcut,fr as EllipseCurve,Tt as Emitter,Ni as Environment,vt as Euler,Ts as FILTER,rn as FlatMaterial,yi as Fog,Mi as FogExp2,Ht as Frustum,Dt as Geometry,xi as Group,Rr as InstanceAttribute,Ti as Instances,hr as Layers,vr as Light,In as LightShadow,mr as LineCurve,qr as LineCurve3,Pi as LitMaterial,Ss as MAPPING,ht as Material,rt as Matrix3,Ve as Matrix4,qt as Mesh,ys as NORMAL_MAP_TYPE,nt as Node,xr as OrthoCamera,_t as PIXEL_FORMAT,Qr as Path,Ei as PerspectiveCamera,wt as Plane,Kr as QuadraticBezierCurve,Xr as QuadraticBezierCurve3,Pt as Quaternion,dr as R180,ei as Ray,Mr as RenderTarget,As as SHADOW_MAP_TYPE,fs as SIDE,Gr as STENCIL_OP,Nn as STUDIO,pr as Shape,Ci as SkyLight,Yt as Source,Ot as Sphere,jr as SplineCurve,vi as Stage,Ri as SunLight,an as SunShadow,bt as TEXTURE_TYPE,Es as TONE_MAPPING,dt as Texture,Ui as ToonMaterial,ri as USAGE,W as Vector2,L as Vector3,Ze as Vector4,_s as WRAPPING,Ns as box,Ne as colorManagement,Vs as cone,zc as createLitRenderer,fo as cylinder,Bs as dodecahedron,xo as earcut,pl as earcutDeviation,xl as extrude,Ke as generated,ks as icosahedron,go as interpolations,Js as lathe,$t as linearToSrgb,os as mathUtils,zs as octahedron,ai as plane,po as polyhedron,Hs as ring,vl as shape,kt as shapeUtils,Os as sphere,Qt as srgbToLinear,Gs as tetrahedron,Ws as torus,$s as tube,Eo as worldUVGenerator};
|