@woosh/meep-engine 2.46.22 → 2.46.24
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/build/meep.cjs +763 -0
- package/build/meep.min.js +1 -0
- package/build/meep.module.js +756 -1
- package/package.json +5 -3
- package/src/core/__module.js +1 -0
- package/src/engine/__module.js +2 -0
- package/src/engine/intelligence/__module.js +6 -0
- package/src/engine/intelligence/behavior/SelectorBehavior.js +4 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).MEEP={})}(this,(function(t){"use strict";function e(t,e){const i=t.length;if(i!==e.length)return!1;let n=0;for(;n<i;n++)if(t[n]!==e[n])return!1;return!0}function i(t){return t instanceof Int8Array||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array||t instanceof Float64Array}function n(t,e){if(!t)throw new Error(e||"AssertionError")}n.enum=function(t,e,i="value"){for(let i in e)if(e[i]===t)return;throw new Error(`${i}(=${t}) is not a valid enumerable value, valid values are: [${Object.values(e).join(", ")}]`)},n.notEqual=function(t,e,i){n(t!==e,i)},n.notOk=function(t,e){n(!t,e)},n.equal=function(t,e,i){n(t===e,i)},n.logicalyEqual=function(t,e,i){},n.ok=n,n.greaterThan=function(t,e,i){if(!(t>e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} > ${e}.`,new Error(n)}},n.greaterThanOrEqual=function(t,e,i){if(!(t>=e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} >= ${e}.`,new Error(n)}},n.lessThan=function(t,e,i){if(!(t<e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} < ${e}.`,new Error(n)}},n.lessThanOrEqual=function(t,e,i){if(!(t<=e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} <= ${e}.`,new Error(n)}},n.typeOf=function(t,e,i="value"){const n=typeof t;if(n!==e)throw new Error(`expected ${i} to be ${e}, instead was '${n}'(=${t})`)},n.arrayHas=function(t,e,i="Array does not contain the item"){},n.arrayHasNo=function(t,e,i="Array contains the item"){},n.arrayEqual=function(t,i,n="Arrays are not equal"){if(!e(t,i))throw new Error(n)},n.isInstanceOf=function(t,e,i="value",n=e.name){},n.isNumber=function(t,e="value"){const i=typeof t;if("number"!==i)throw new Error(`expected ${e} to be a number, instead was '${i}'(=${t})`)},n.isString=function(t,e="value"){const i=typeof t;if("string"!==i)throw new Error(`expected ${e} to be a string, instead was '${i}'(=${t})`)},n.isBoolean=function(t,e="value"){const i=typeof t;if("boolean"!==i)throw new Error(`expected ${e} to be a boolean, instead was '${i}'(=${t})`)},n.isFunction=function(t,e="value"){const i=typeof t;if("function"!==i)throw new Error(`expected ${e} to be a function, instead was '${i}'(=${t})`)},n.isInteger=function(t,e="value"){if(!Number.isInteger(t))throw new Error(`${e} must be an integer, instead was ${t}`)},n.isNonNegativeInteger=function(t,e="value"){if(t<0)throw new Error(`${e} must be >= 0, instead was ${t}`)},n.isArray=function(t,e="value"){if(!Array.isArray(t))throw new Error(`expected ${e} to be an array, instead was something else (typeof ='${typeof t}')`)},n.isArrayLike=function(t,e="value"){if(!Array.isArray(t)&&!i(t))throw new Error(`expected ${e} to be an array-like structure, instead was something else (typeof ='${typeof t}')`)},n.defined=function(t,e="value"){if(void 0===t)throw new Error(`${e} is undefined`)},n.isNull=function(t,e){if(null!==t)throw new Error(`${e} is NOT null`)},n.notNull=function(t,e="value"){if(null===t)throw new Error(`${e} is null`)},n.notNaN=function(t,e="value"){if(Number.isNaN(t))throw new Error(`${e} must be a valid number, instead was NaN`)},n.isFiniteNumber=function(t,e="value"){if(!Number.isFinite(t))throw new Error(`${e} must be a finite number, instead was ${t}`)};const s={RemoveAfterExecution:1};class r{constructor(t,e){this.handle=t,this.context=e,this.flags=0}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}}r.prototype.isSignalHandler=!0;const a=[];let o=0;class l{constructor(){this.handlers=[],this.flags=0}get dispatching(){return this.getFlag(2)}set dispatching(t){this.writeFlag(2,t)}get silent(){return this.getFlag(1)}set silent(t){this.writeFlag(1,t)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}contains(t){return-1!==h(this.handlers,t)}mute(){this.setFlag(1)}unmute(){this.clearFlag(1)}hasHandlers(){return this.handlers.length>0}addOne(t,e){const i=new r(t,e);i.setFlag(s.RemoveAfterExecution),this.handlers.push(i)}add(t,e){const i=new r(t,e);this.handlers.push(i)}remove(t,e){return void 0===e?function(t,e){const i=t.handlers;let n=h(i,e);return n>=0&&(i.splice(n,1),!0)}(this,t):function(t,e,i){const n=t.handlers;let s=c(n,e,i);return s>=0&&(n.splice(s,1),!0)}(this,t,e)}removeAll(){const t=this.handlers;t.splice(0,t.length)}dispatch(...t){0==(1&this.flags)&&(this.dispatching=!0,d(this.handlers,t),this.dispatching=!1)}send0(){if(0!=(1&this.flags))return;const t=this.handlers,e=t.length,i=o,n=i+e;let r,l;for(o=n,r=0;r<e;r++)a[i+r]=t[e-(r+1)];for(r=n-1;r>=i;r--){if(l=a[r],l.getFlag(s.RemoveAfterExecution)){const e=t.indexOf(l);t.splice(e,1)}const e=l.handle;try{e.call(l.context)}catch(t){}}o=i}send1(t){if(0!=(1&this.flags))return;const e=this.handlers,i=e.length,n=o,r=n+i;let l,h;for(o=r,l=0;l<i;l++)a[n+l]=e[i-(l+1)];for(l=r-1;l>=n;l--){if(h=a[l],h.getFlag(s.RemoveAfterExecution)){const t=e.indexOf(h);e.splice(t,1)}const i=h.handle;try{i.call(h.context,t)}catch(t){}}o=n}send2(t,e){if(0!=(1&this.flags))return;const i=this.handlers,n=i.length,r=o,l=r+n;let h,c;for(o=l,h=0;h<n;h++)a[r+h]=i[n-(h+1)];for(h=l-1;h>=r;h--){if(c=a[h],c.getFlag(s.RemoveAfterExecution)){const t=i.indexOf(c);i.splice(t,1)}const n=c.handle;try{n.call(c.context,t,e)}catch(t){}}o=r}send3(t,e,i){if(0!=(1&this.flags))return;const n=this.handlers,r=n.length,l=o,h=l+r;let c,u;for(o=h,c=0;c<r;c++)a[l+c]=n[r-(c+1)];for(c=h-1;c>=l;c--){if(u=a[c],u.getFlag(s.RemoveAfterExecution)){const t=n.indexOf(u);n.splice(t,1)}const r=u.handle;try{r.call(u.context,t,e,i)}catch(t){}}o=l}send4(t,e,i,n){if(0!=(1&this.flags))return;const r=this.handlers,l=r.length,h=o,c=h+l;let u,d;for(o=c,u=0;u<l;u++)a[h+u]=r[l-(u+1)];for(u=c-1;u>=h;u--){if(d=a[u],d.getFlag(s.RemoveAfterExecution)){const t=r.indexOf(d);r.splice(t,1)}const o=d.handle;try{o.call(d.context,t,e,i,n)}catch(t){}}o=h}send6(t,e,i,n,r,l){if(0!=(1&this.flags))return;const h=this.handlers,c=h.length,u=o,d=u+c;let p,f;for(o=d,p=0;p<c;p++)a[u+p]=h[c-(p+1)];for(p=d-1;p>=u;p--){if(f=a[p],f.getFlag(s.RemoveAfterExecution)){const t=h.indexOf(f);h.splice(t,1)}const o=f.handle;try{o.call(f.context,t,e,i,n,r,l)}catch(r){}}o=u}send8(t,e,i,n,r,l,h,c){if(0!=(1&this.flags))return;const u=this.handlers,d=u.length,p=o,f=p+d;let m,_;for(o=f,m=0;m<d;m++)a[p+m]=u[d-(m+1)];for(m=f-1;m>=p;m--){if(_=a[m],_.getFlag(s.RemoveAfterExecution)){const t=u.indexOf(_);u.splice(t,1)}const o=_.handle;try{o.call(_.context,t,e,i,n,r,l,h,c)}catch(r){}}o=p}isDispatching(){return this.dispatching}merge(t){const e=new l;function i(){e.dispatch(arguments)}return this.add(i),t.add(i),e}}function h(t,e,i){const n=t.length;for(let s=0;s<n;s++){const n=t[s];if(n.handle===e){if(void 0!==i&&i!==n.context)continue;return s}}return-1}function c(t,e,i){const n=t.length;for(let s=0;s<n;s++){const n=t[s];if(n.handle===e&&n.context===i)return s}return-1}function u(t,e,i){try{t.apply(e,i)}catch(t){}}function d(t,e){const i=t.length,n=o,r=n+i;let l,h;for(o=r,l=0;l<i;l++)a[n+l]=t[i-(l+1)];for(l=r-1;l>=n;l--){if(h=a[l],h.getFlag(s.RemoveAfterExecution)){const e=t.indexOf(h);t.splice(e,1)}u(h.handle,h.context,e)}o=n}function p(t,e,i){return(e-t)*i+t}function f(t){return t>0?1:t<0?-1:0}function m(t,e,i,n,s,r){return t*n+e*s+i*r}function _(t,e,i){return t*t+e*e+i*i}function g(t,e,i){return Math.hypot(t,e,i)}function y(t,e,i){return t<e?e:t>i?i:t}function v(t,e,i,n,s,r,a,o){const l=p(e,s,o),h=p(i,r,o),c=p(n,a,o);t.set(l,h,c)}function x(t){return t%1*1367130550^(0|t)}function w(t,e,i){return Math.abs(t-e)<=i}l.prototype.isSignal=!0;const b=1e-6;let S=class t{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i,this.onChanged=new l}readFromArray(t,e=0){this.set(t[e],t[e+1],t[e+2])}writeToArray(t,e=0){t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z}asArray(){const t=[];return this.writeToArray(t,0),t}set(t,e,i){const n=this.x,s=this.y,r=this.z;return t===n&&e===s&&i===r||(this.x=t,this.y=e,this.z=i,this.onChanged.hasHandlers()&&this.onChanged.send6(t,e,i,n,s,r)),this}setScalar(t){this.set(t,t,t)}setX(t){return this.set(t,this.y,this.z)}setY(t){return this.set(this.x,t,this.z)}setZ(t){return this.set(this.x,this.y,t)}setXY(t,e){return this.set(t,e,this.z)}setXZ(t,e){return this.set(t,this.y,e)}setYZ(t,e){return this.set(this.x,t,e)}addVectors(t,e){const i=t.x+e.x,n=t.y+e.y,s=t.z+e.z;this.set(i,n,s)}add(t){return this._add(t.x,t.y,t.z)}_add(t,e,i){return this.set(this.x+t,this.y+e,this.z+i)}subVectors(t,e){const i=t.x-e.x,n=t.y-e.y,s=t.z-e.z;this.set(i,n,s)}sub(t){return this._sub(t.x,t.y,t.z)}_sub(t,e,i){const n=this.x-t,s=this.y-e,r=this.z-i;return this.set(n,s,r)}_multiply(t,e,i){return this.set(this.x*t,this.y*e,this.z*i)}multiply(t){return this._multiply(t.x,t.y,t.z)}multiplyVectors(t,e){this.set(t.x*e.x,t.y*e.y,t.z*e.z)}subScalar(t){return this.set(this.x-t,this.y-t,this.z-t)}addScalar(t){return this.set(this.x+t,this.y+t,this.z+t)}clone(){return new t(this.x,this.y,this.z)}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t)}isZero(){return 0===this.x&&0===this.y&&0===this.z}cross(t){return this.crossVectors(this,t),this}crossVectors(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,a=e.y,o=e.z;this._crossVectors(i,n,s,r,a,o)}_crossVectors(t,e,i,n,s,r){const a=e*r-i*s,o=i*n-t*r,l=t*s-e*n;this.set(a,o,l)}abs(){return this.set(Math.abs(this.x),Math.abs(this.y),Math.abs(this.z))}dot(e){return t.dot(this,e)}length(){return g(this.x,this.y,this.z)}lengthSqr(){return _(this.x,this.y,this.z)}normalize(){const t=this.length();if(0===t)return;const e=1/t;this.multiplyScalar(e)}isNormalized(t=.01){const e=this.lengthSqr();return e+t>=1&&e-t<=1}copy(t){return this.set(t.x,t.y,t.z)}negate(){return this.set(-this.x,-this.y,-this.z)}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceSqrTo(t){return _(this.x-t.x,this.y-t.y,this.z-t.z)}_distanceSqrTo(t,e,i){return _(this.x-t,this.y-e,this.z-i)}distanceToSquared(t){return _(this.x-t.x,this.y-t.y,this.z-t.z)}angleTo(t){return function(t,e,i,n,s,r){const a=function(t,e,i,n,s,r){const a=m(t,e,i,n,s,r),o=g(t,e,i)*g(n,s,r);return 0===o?0:y(a/o,-1,1)}(t,e,i,n,s,r);return Math.acos(a)}(this.x,this.y,this.z,t.x,t.y,t.z)}applyQuaternion(t){const e=this.x,i=this.y,n=this.z,s=t.x,r=t.y,a=t.z,o=t.w;var l=o*e+r*n-a*i,h=o*i+a*e-s*n,c=o*n+s*i-r*e,u=-s*e-r*i-a*n;const d=l*o+u*-s+h*-a-c*-r,p=h*o+u*-r+c*-s-l*-a,f=c*o+u*-a+l*-r-h*-s;this.set(d,p,f)}sign(){return this.set(f(this.x),f(this.y),f(this.z))}lerp(t,e){const i=p(this.x,t.x,e),n=p(this.y,t.y,e),s=p(this.z,t.z,e);return this.set(i,n,s)}lerpVectors(t,e,i){!function(t,e,i,n){v(t,e.x,e.y,e.z,i.x,i.y,i.z,n)}(this,t,e,i)}slerpVectors(t,e,i){!function(t,e,i,n,s,r,a,o){const l=m(e,i,n,s,r,a);if(l>=1||l<=-1)return void v(t,e,i,n,s,r,a,o);const h=Math.acos(l),c=1/Math.sin(h),u=Math.sin((1-o)*h)*c,d=Math.sin(o*h)*c,p=e*u+s*d,f=i*u+r*d,_=n*u+a*d;t.set(p,f,_)}(this,t.x,t.y,t.z,e.x,e.y,e.z,i)}applyMatrix4_three(t){this.applyMatrix4(t.elements)}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=t[0]*e+t[4]*i+t[8]*n+t[12],r=t[1]*e+t[5]*i+t[9]*n+t[13],a=t[2]*e+t[6]*i+t[10]*n+t[14];this.set(s,r,a)}transformDirection_three(t){const e=this.x,i=this.y,n=this.z,s=t.elements,r=s[0]*e+s[4]*i+s[8]*n,a=s[1]*e+s[5]*i+s[9]*n,o=s[2]*e+s[6]*i+s[10]*n,l=1/g(r,a,o);this.set(r*l,a*l,o*l)}applyMatrix3_three(t){const e=this.x,i=this.y,n=this.z,s=t.elements,r=s[0]*e+s[3]*i+s[6]*n,a=s[1]*e+s[4]*i+s[7]*n,o=s[2]*e+s[5]*i+s[8]*n;return this.set(r,a,o)}threejs_setFromMatrixPosition(t){this.setFromMatrixPosition(t.elements)}setFromMatrixPosition(t){const e=t[12],i=t[13],n=t[14];this.set(e,i,n)}equals(t){return this._equals(t.x,t.y,t.z)}_equals(t,e,i){return this.x===t&&this.y===e&&this.z===i}roughlyEquals(t,e){return this._roughlyEquals(t.x,t.y,t.z,e)}_roughlyEquals(t,e,i,n=b){return w(this.x,t,n)&&w(this.y,e,n)&&w(this.z,i,n)}floor(){const t=0|this.x,e=0|this.y,i=0|this.z;this.set(t,e,i)}projectOntoVector3(t){const e=this.x,i=this.y,n=this.z,s=t.x,r=t.y,a=t.z,o=m(e,i,n,s,r,a)/(s*s+r*r+a*a),l=s*o,h=r*o,c=a*o;this.set(l,h,c)}static findOrthonormals(t,e,i){throw new Error("Not Implemented")}_projectVectors(t,e,i,n,s,r){const a=m(t,e,i,n,s,r)/(n*n+s*s+r*r),o=n*a,l=s*a,h=r*a;this.set(o,l,h)}setFromSphericalCoords(t,e,i){const n=Math.sin(e)*t,s=n*Math.sin(i),r=Math.cos(e)*t,a=n*Math.cos(i);this.set(s,r,a)}process(t){return t(this.x,this.y,this.z),this.onChanged.add(t),this}toJSON(){return{x:this.x,y:this.y,z:this.z}}fromJSON(t){"number"==typeof t?this.setScalar(t):this.copy(t)}toString(){return`[x:${this.x}, y:${this.y}, z:${this.z}]`}toBinaryBuffer(t){t.writeFloat64(this.x),t.writeFloat64(this.y),t.writeFloat64(this.z)}fromBinaryBuffer(t){const e=t.readFloat64(),i=t.readFloat64(),n=t.readFloat64();this.set(e,i,n)}toBinaryBufferFloat32(t){t.writeFloat32(this.x),t.writeFloat32(this.y),t.writeFloat32(this.z)}fromBinaryBufferFloat32(t){const e=t.readFloat32(),i=t.readFloat32(),n=t.readFloat32();this.set(e,i,n)}toBinaryBufferFloat32_EqualityEncoded(t){const e=this.x,i=this.y,n=this.z;let s=0;e===i&&(s|=1),i===n&&(s|=2),e===n&&(s|=4),t.writeUint8(s),7==(7&s)?t.writeFloat32(e):1===s?(t.writeFloat32(e),t.writeFloat32(n)):2===s||4===s?(t.writeFloat32(e),t.writeFloat32(i)):(t.writeFloat32(e),t.writeFloat32(i),t.writeFloat32(n))}fromBinaryBufferFloat32_EqualityEncoded(t){const e=t.readUint8();let i=0,n=0,s=0;7==(7&e)?(i=t.readFloat32(),n=i,s=i):1==(1&e)?(i=t.readFloat32(),n=i,s=t.readFloat32()):2==(2&e)?(i=t.readFloat32(),n=t.readFloat32(),s=n):4==(4&e)?(i=t.readFloat32(),n=t.readFloat32(),s=i):(i=t.readFloat32(),n=t.readFloat32(),s=t.readFloat32()),this.set(i,n,s)}hash(){let t=x(this.x);return t=(t<<5)-t+x(this.y),t=(t<<5)-t+x(this.z),t}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}set 0(t){this.x=t}set 1(t){this.y=t}set 2(t){this.z=t}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}static dot(e,i){return t._dot(e.x,e.y,e.z,i.x,i.y,i.z)}static distance(t,e){return g(t.x-e.x,t.y-e.y,t.z-e.z)}static fromArray(e,i=0){return new t(e[i],e[i+1],e[i+2])}static fromScalar(e){return new t(e,e,e)}};S.prototype.lengthSq=S.prototype.lengthSqr,S.prototype.isVector3=!0,S.zero=Object.freeze(new S(0,0,0)),S.one=Object.freeze(new S(1,1,1)),S.minus_one=Object.freeze(new S(-1,-1,-1)),S.up=Object.freeze(new S(0,1,0)),S.down=Object.freeze(new S(0,-1,0)),S.left=Object.freeze(new S(-1,0,0)),S.right=Object.freeze(new S(1,0,0)),S.forward=Object.freeze(new S(0,0,1)),S.back=Object.freeze(new S(0,0,-1)),S.typeName="Vector3",S._dot=m;const M="135",T=0,C=1,A=2,E=1,z=2,I=3,N=0,L=1,P=2,F=0,D=1,O=2,R=3,k=4,U=5,B=100,V=101,G=102,W=103,H=104,j=200,q=201,J=202,Y=203,X=204,Z=205,$=206,K=207,Q=208,tt=209,et=210,it=0,nt=1,st=2,rt=3,at=4,ot=5,lt=6,ht=7,ct=0,ut=1,dt=2,pt=0,ft=1,mt=2,_t=3,gt=4,yt=5,vt=301,xt=302,wt=303,bt=304,St=306,Mt=307,Tt=1e3,Ct=1001,At=1002,Et=1003,zt=1004,It=1005,Nt=1006,Lt=1007,Pt=1008,Ft=1009,Dt=1010,Ot=1011,Rt=1012,kt=1013,Ut=1014,Bt=1015,Vt=1016,Gt=1017,Wt=1018,Ht=1019,jt=1020,qt=1021,Jt=1022,Yt=1023,Xt=1024,Zt=1025,$t=Yt,Kt=1026,Qt=1027,te=1028,ee=1029,ie=1030,ne=1031,se=1032,re=1033,ae=33776,oe=33777,le=33778,he=33779,ce=35840,ue=35841,de=35842,pe=35843,fe=36196,me=37492,_e=37496,ge=37808,ye=37809,ve=37810,xe=37811,we=37812,be=37813,Se=37814,Me=37815,Te=37816,Ce=37817,Ae=37818,Ee=37819,ze=37820,Ie=37821,Ne=36492,Le=37840,Pe=37841,Fe=37842,De=37843,Oe=37844,Re=37845,ke=37846,Ue=37847,Be=37848,Ve=37849,Ge=37850,We=37851,He=37852,je=37853,qe=2300,Je=2301,Ye=2302,Xe=2400,Ze=2401,$e=2402,Ke=3e3,Qe=3001,ti=3007,ei=3002,ii=3004,ni=3005,si=3006,ri=3201,ai=0,oi=1,li=7680,hi=35044,ci=35048,ui="300 es";class di{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const i=this._listeners;void 0===i[t]&&(i[t]=[]),-1===i[t].indexOf(e)&&i[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const i=this._listeners;return void 0!==i[t]&&-1!==i[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const i=this._listeners[t];if(void 0!==i){const t=i.indexOf(e);-1!==t&&i.splice(t,1)}}dispatchEvent(t){if(void 0===this._listeners)return;const e=this._listeners[t.type];if(void 0!==e){t.target=this;const i=e.slice(0);for(let e=0,n=i.length;e<n;e++)i[e].call(this,t);t.target=null}}}const pi=[];for(let t=0;t<256;t++)pi[t]=(t<16?"0":"")+t.toString(16);const fi=Math.PI/180,mi=180/Math.PI;function _i(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,n=4294967295*Math.random()|0;return(pi[255&t]+pi[t>>8&255]+pi[t>>16&255]+pi[t>>24&255]+"-"+pi[255&e]+pi[e>>8&255]+"-"+pi[e>>16&15|64]+pi[e>>24&255]+"-"+pi[63&i|128]+pi[i>>8&255]+"-"+pi[i>>16&255]+pi[i>>24&255]+pi[255&n]+pi[n>>8&255]+pi[n>>16&255]+pi[n>>24&255]).toUpperCase()}function gi(t,e,i){return Math.max(e,Math.min(i,t))}function yi(t,e,i){return(1-i)*t+i*e}function vi(t){return 0==(t&t-1)&&0!==t}function xi(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}let wi,bi=class{constructor(t=0,e=0){this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t,e){return void 0!==e?this.addVectors(t,e):(this.x+=t.x,this.y+=t.y,this)}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t,e){return void 0!==e?this.subVectors(t,e):(this.x-=t.x,this.y-=t.y,this)}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,i=this.y,n=t.elements;return this.x=n[0]*e+n[3]*i+n[6],this.y=n[1]*e+n[4]*i+n[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e,i){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const i=Math.cos(e),n=Math.sin(e),s=this.x-t.x,r=this.y-t.y;return this.x=s*i-r*n+t.x,this.y=s*n+r*i+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}};bi.prototype.isVector2=!0;class Si{constructor(){this.elements=[1,0,0,0,1,0,0,0,1]}set(t,e,i,n,s,r,a,o,l){const h=this.elements;return h[0]=t,h[1]=n,h[2]=a,h[3]=e,h[4]=s,h[5]=o,h[6]=i,h[7]=r,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],this}extractBasis(t,e,i){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),i.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,n=e.elements,s=this.elements,r=i[0],a=i[3],o=i[6],l=i[1],h=i[4],c=i[7],u=i[2],d=i[5],p=i[8],f=n[0],m=n[3],_=n[6],g=n[1],y=n[4],v=n[7],x=n[2],w=n[5],b=n[8];return s[0]=r*f+a*g+o*x,s[3]=r*m+a*y+o*w,s[6]=r*_+a*v+o*b,s[1]=l*f+h*g+c*x,s[4]=l*m+h*y+c*w,s[7]=l*_+h*v+c*b,s[2]=u*f+d*g+p*x,s[5]=u*m+d*y+p*w,s[8]=u*_+d*v+p*b,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8];return e*r*h-e*a*l-i*s*h+i*a*o+n*s*l-n*r*o}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8],c=h*r-a*l,u=a*o-h*s,d=l*s-r*o,p=e*c+i*u+n*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const f=1/p;return t[0]=c*f,t[1]=(n*l-h*i)*f,t[2]=(a*i-n*r)*f,t[3]=u*f,t[4]=(h*e-n*o)*f,t[5]=(n*s-a*e)*f,t[6]=d*f,t[7]=(i*o-l*e)*f,t[8]=(r*e-i*s)*f,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,i,n,s,r,a){const o=Math.cos(s),l=Math.sin(s);return this.set(i*o,i*l,-i*(o*r+l*a)+r+t,-n*l,n*o,-n*(-l*r+o*a)+a+e,0,0,1),this}scale(t,e){const i=this.elements;return i[0]*=t,i[3]*=t,i[6]*=t,i[1]*=e,i[4]*=e,i[7]*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),n=this.elements,s=n[0],r=n[3],a=n[6],o=n[1],l=n[4],h=n[7];return n[0]=e*s+i*o,n[3]=e*r+i*l,n[6]=e*a+i*h,n[1]=-i*s+e*o,n[4]=-i*r+e*l,n[7]=-i*a+e*h,this}translate(t,e){const i=this.elements;return i[0]+=t*i[2],i[3]+=t*i[5],i[6]+=t*i[8],i[1]+=e*i[2],i[4]+=e*i[5],i[7]+=e*i[8],this}equals(t){const e=this.elements,i=t.elements;for(let t=0;t<9;t++)if(e[t]!==i[t])return!1;return!0}fromArray(t,e=0){for(let i=0;i<9;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}function Mi(t){if(0===t.length)return-Infinity;let e=t[0];for(let i=1,n=t.length;i<n;++i)t[i]>e&&(e=t[i]);return e}function Ti(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function Ci(t,e=0){let i=3735928559^e,n=1103547991^e;for(let e,s=0;s<t.length;s++)e=t.charCodeAt(s),i=Math.imul(i^e,2654435761),n=Math.imul(n^e,1597334677);return i=Math.imul(i^i>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),n=Math.imul(n^n>>>16,2246822507)^Math.imul(i^i>>>13,3266489909),4294967296*(2097151&n)+(i>>>0)}Si.prototype.isMatrix3=!0;class Ai{static getDataURL(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===wi&&(wi=Ti("canvas")),wi.width=t.width,wi.height=t.height;const i=wi.getContext("2d");t instanceof ImageData?i.putImageData(t,0,0):i.drawImage(t,0,0,t.width,t.height),e=wi}return e.width>2048||e.height>2048?e.toDataURL("image/jpeg",.6):e.toDataURL("image/png")}}let Ei=0;class zi extends di{constructor(t=zi.DEFAULT_IMAGE,e=zi.DEFAULT_MAPPING,i=Ct,n=Ct,s=Nt,r=Pt,a=Yt,o=Ft,l=1,h=Ke){super(),Object.defineProperty(this,"id",{value:Ei++}),this.uuid=_i(),this.name="",this.image=t,this.mipmaps=[],this.mapping=e,this.wrapS=i,this.wrapT=n,this.magFilter=s,this.minFilter=r,this.anisotropy=l,this.format=a,this.internalFormat=null,this.type=o,this.offset=new bi(0,0),this.repeat=new bi(1,1),this.center=new bi(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Si,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.encoding=h,this.userData={},this.version=0,this.onUpdate=null,this.isRenderTargetTexture=!1}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}clone(){return(new this.constructor).copy(this)}copy(t){return this.name=t.name,this.image=t.image,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.encoding=t.encoding,this.userData=JSON.parse(JSON.stringify(t.userData)),this}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.textures[this.uuid])return t.textures[this.uuid];const i={metadata:{version:4.5,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,mapping:this.mapping,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,type:this.type,encoding:this.encoding,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};if(void 0!==this.image){const n=this.image;if(void 0===n.uuid&&(n.uuid=_i()),!e&&void 0===t.images[n.uuid]){let e;if(Array.isArray(n)){e=[];for(let t=0,i=n.length;t<i;t++)n[t].isDataTexture?e.push(Ii(n[t].image)):e.push(Ii(n[t]))}else e=Ii(n);t.images[n.uuid]={uuid:n.uuid,url:e}}i.image=n.uuid}return"{}"!==JSON.stringify(this.userData)&&(i.userData=this.userData),e||(t.textures[this.uuid]=i),i}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(300!==this.mapping)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case Tt:t.x=t.x-Math.floor(t.x);break;case Ct:t.x=t.x<0?0:1;break;case At:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case Tt:t.y=t.y-Math.floor(t.y);break;case Ct:t.y=t.y<0?0:1;break;case At:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&this.version++}}function Ii(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?Ai.getDataURL(t):t.data?{data:Array.prototype.slice.call(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:{}}zi.DEFAULT_IMAGE=void 0,zi.DEFAULT_MAPPING=300,zi.prototype.isTexture=!0;let Ni=class{constructor(t=0,e=0,i=0,n=1){this.x=t,this.y=e,this.z=i,this.w=n}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,i,n){return this.x=t,this.y=e,this.z=i,this.w=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this}add(t,e){return void 0!==e?this.addVectors(t,e):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this)}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t,e){return void 0!==e?this.subVectors(t,e):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this)}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=t.elements;return this.x=r[0]*e+r[4]*i+r[8]*n+r[12]*s,this.y=r[1]*e+r[5]*i+r[9]*n+r[13]*s,this.z=r[2]*e+r[6]*i+r[10]*n+r[14]*s,this.w=r[3]*e+r[7]*i+r[11]*n+r[15]*s,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,i,n,s;const r=.01,a=.1,o=t.elements,l=o[0],h=o[4],c=o[8],u=o[1],d=o[5],p=o[9],f=o[2],m=o[6],_=o[10];if(Math.abs(h-u)<r&&Math.abs(c-f)<r&&Math.abs(p-m)<r){if(Math.abs(h+u)<a&&Math.abs(c+f)<a&&Math.abs(p+m)<a&&Math.abs(l+d+_-3)<a)return this.set(1,0,0,0),this;e=Math.PI;const t=(l+1)/2,o=(d+1)/2,g=(_+1)/2,y=(h+u)/4,v=(c+f)/4,x=(p+m)/4;return t>o&&t>g?t<r?(i=0,n=.707106781,s=.707106781):(i=Math.sqrt(t),n=y/i,s=v/i):o>g?o<r?(i=.707106781,n=0,s=.707106781):(n=Math.sqrt(o),i=y/n,s=x/n):g<r?(i=.707106781,n=.707106781,s=0):(s=Math.sqrt(g),i=v/s,n=x/s),this.set(i,n,s,e),this}let g=Math.sqrt((m-p)*(m-p)+(c-f)*(c-f)+(u-h)*(u-h));return Math.abs(g)<.001&&(g=1),this.x=(m-p)/g,this.y=(c-f)/g,this.z=(u-h)/g,this.w=Math.acos((l+d+_-1)/2),this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this.w=Math.min(this.w,t.w),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this.w=Math.max(this.w,t.w),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this.w=Math.max(t.w,Math.min(e.w,this.w)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this.w=Math.max(t,Math.min(e,this.w)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this.w=this.w<0?Math.ceil(this.w):Math.floor(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this.w=t.w+(e.w-t.w)*i,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t}fromBufferAttribute(t,e,i){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this.w=t.getW(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}};Ni.prototype.isVector4=!0;class Li extends di{constructor(t,e,i={}){super(),this.width=t,this.height=e,this.depth=1,this.scissor=new Ni(0,0,t,e),this.scissorTest=!1,this.viewport=new Ni(0,0,t,e),this.texture=new zi(void 0,i.mapping,i.wrapS,i.wrapT,i.magFilter,i.minFilter,i.format,i.type,i.anisotropy,i.encoding),this.texture.isRenderTargetTexture=!0,this.texture.image={width:t,height:e,depth:1},this.texture.generateMipmaps=void 0!==i.generateMipmaps&&i.generateMipmaps,this.texture.internalFormat=void 0!==i.internalFormat?i.internalFormat:null,this.texture.minFilter=void 0!==i.minFilter?i.minFilter:Nt,this.depthBuffer=void 0===i.depthBuffer||i.depthBuffer,this.stencilBuffer=void 0!==i.stencilBuffer&&i.stencilBuffer,this.depthTexture=void 0!==i.depthTexture?i.depthTexture:null}setTexture(t){t.image={width:this.width,height:this.height,depth:this.depth},this.texture=t}setSize(t,e,i=1){this.width===t&&this.height===e&&this.depth===i||(this.width=t,this.height=e,this.depth=i,this.texture.image.width=t,this.texture.image.height=e,this.texture.image.depth=i,this.dispose()),this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return(new this.constructor).copy(this)}copy(t){return this.width=t.width,this.height=t.height,this.depth=t.depth,this.viewport.copy(t.viewport),this.texture=t.texture.clone(),this.texture.image={...this.texture.image},this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.depthTexture=t.depthTexture,this}dispose(){this.dispatchEvent({type:"dispose"})}}Li.prototype.isWebGLRenderTarget=!0,class extends Li{constructor(t,e,i){super(t,e);const n=this.texture;this.texture=[];for(let t=0;t<i;t++)this.texture[t]=n.clone()}setSize(t,e,i=1){if(this.width!==t||this.height!==e||this.depth!==i){this.width=t,this.height=e,this.depth=i;for(let n=0,s=this.texture.length;n<s;n++)this.texture[n].image.width=t,this.texture[n].image.height=e,this.texture[n].image.depth=i;this.dispose()}return this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e),this}copy(t){this.dispose(),this.width=t.width,this.height=t.height,this.depth=t.depth,this.viewport.set(0,0,this.width,this.height),this.scissor.set(0,0,this.width,this.height),this.depthBuffer=t.depthBuffer,this.stencilBuffer=t.stencilBuffer,this.depthTexture=t.depthTexture,this.texture.length=0;for(let e=0,i=t.texture.length;e<i;e++)this.texture[e]=t.texture[e].clone();return this}}.prototype.isWebGLMultipleRenderTargets=!0;class Pi extends Li{constructor(t,e,i={}){super(t,e,i),this.samples=4,this.ignoreDepthForMultisampleCopy=void 0===i.ignoreDepth||i.ignoreDepth,this.useRenderToTexture=void 0!==i.useRenderToTexture&&i.useRenderToTexture,this.useRenderbuffer=!1===this.useRenderToTexture}copy(t){return super.copy.call(this,t),this.samples=t.samples,this.useRenderToTexture=t.useRenderToTexture,this.useRenderbuffer=t.useRenderbuffer,this}}Pi.prototype.isWebGLMultisampleRenderTarget=!0;let Fi=class{constructor(t=0,e=0,i=0,n=1){this._x=t,this._y=e,this._z=i,this._w=n}static slerp(t,e,i,n){return i.slerpQuaternions(t,e,n)}static slerpFlat(t,e,i,n,s,r,a){let o=i[n+0],l=i[n+1],h=i[n+2],c=i[n+3];const u=s[r+0],d=s[r+1],p=s[r+2],f=s[r+3];if(0===a)return t[e+0]=o,t[e+1]=l,t[e+2]=h,void(t[e+3]=c);if(1===a)return t[e+0]=u,t[e+1]=d,t[e+2]=p,void(t[e+3]=f);if(c!==f||o!==u||l!==d||h!==p){let t=1-a;const e=o*u+l*d+h*p+c*f,i=e>=0?1:-1,n=1-e*e;if(n>Number.EPSILON){const s=Math.sqrt(n),r=Math.atan2(s,e*i);t=Math.sin(t*r)/s,a=Math.sin(a*r)/s}const s=a*i;if(o=o*t+u*s,l=l*t+d*s,h=h*t+p*s,c=c*t+f*s,t===1-a){const t=1/Math.sqrt(o*o+l*l+h*h+c*c);o*=t,l*=t,h*=t,c*=t}}t[e]=o,t[e+1]=l,t[e+2]=h,t[e+3]=c}static multiplyQuaternionsFlat(t,e,i,n,s,r){const a=i[n],o=i[n+1],l=i[n+2],h=i[n+3],c=s[r],u=s[r+1],d=s[r+2],p=s[r+3];return t[e]=a*p+h*c+o*d-l*u,t[e+1]=o*p+h*u+l*c-a*d,t[e+2]=l*p+h*d+a*u-o*c,t[e+3]=h*p-a*c-o*u-l*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,i,n){return this._x=t,this._y=e,this._z=i,this._w=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e){if(!t||!t.isEuler)throw new Error("THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.");const i=t._x,n=t._y,s=t._z,r=t._order,a=Math.cos,o=Math.sin,l=a(i/2),h=a(n/2),c=a(s/2),u=o(i/2),d=o(n/2),p=o(s/2);switch(r){case"XYZ":this._x=u*h*c+l*d*p,this._y=l*d*c-u*h*p,this._z=l*h*p+u*d*c,this._w=l*h*c-u*d*p;break;case"YXZ":this._x=u*h*c+l*d*p,this._y=l*d*c-u*h*p,this._z=l*h*p-u*d*c,this._w=l*h*c+u*d*p;break;case"ZXY":this._x=u*h*c-l*d*p,this._y=l*d*c+u*h*p,this._z=l*h*p+u*d*c,this._w=l*h*c-u*d*p;break;case"ZYX":this._x=u*h*c-l*d*p,this._y=l*d*c+u*h*p,this._z=l*h*p-u*d*c,this._w=l*h*c+u*d*p;break;case"YZX":this._x=u*h*c+l*d*p,this._y=l*d*c+u*h*p,this._z=l*h*p-u*d*c,this._w=l*h*c-u*d*p;break;case"XZY":this._x=u*h*c-l*d*p,this._y=l*d*c-u*h*p,this._z=l*h*p+u*d*c,this._w=l*h*c+u*d*p}return!1!==e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const i=e/2,n=Math.sin(i);return this._x=t.x*n,this._y=t.y*n,this._z=t.z*n,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,i=e[0],n=e[4],s=e[8],r=e[1],a=e[5],o=e[9],l=e[2],h=e[6],c=e[10],u=i+a+c;if(u>0){const t=.5/Math.sqrt(u+1);this._w=.25/t,this._x=(h-o)*t,this._y=(s-l)*t,this._z=(r-n)*t}else if(i>a&&i>c){const t=2*Math.sqrt(1+i-a-c);this._w=(h-o)/t,this._x=.25*t,this._y=(n+r)/t,this._z=(s+l)/t}else if(a>c){const t=2*Math.sqrt(1+a-i-c);this._w=(s-l)/t,this._x=(n+r)/t,this._y=.25*t,this._z=(o+h)/t}else{const t=2*Math.sqrt(1+c-i-a);this._w=(r-n)/t,this._x=(s+l)/t,this._y=(o+h)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let i=t.dot(e)+1;return i<Number.EPSILON?(i=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=i):(this._x=0,this._y=-t.z,this._z=t.y,this._w=i)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=i),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(gi(this.dot(t),-1,1)))}rotateTowards(t,e){const i=this.angleTo(t);if(0===i)return this;const n=Math.min(1,e/i);return this.slerp(t,n),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t,e){return void 0!==e?this.multiplyQuaternions(t,e):this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const i=t._x,n=t._y,s=t._z,r=t._w,a=e._x,o=e._y,l=e._z,h=e._w;return this._x=i*h+r*a+n*l-s*o,this._y=n*h+r*o+s*a-i*l,this._z=s*h+r*l+i*o-n*a,this._w=r*h-i*a-n*o-s*l,this._onChangeCallback(),this}slerp(t,e){if(0===e)return this;if(1===e)return this.copy(t);const i=this._x,n=this._y,s=this._z,r=this._w;let a=r*t._w+i*t._x+n*t._y+s*t._z;if(a<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,a=-a):this.copy(t),a>=1)return this._w=r,this._x=i,this._y=n,this._z=s,this;const o=1-a*a;if(o<=Number.EPSILON){const t=1-e;return this._w=t*r+e*this._w,this._x=t*i+e*this._x,this._y=t*n+e*this._y,this._z=t*s+e*this._z,this.normalize(),this._onChangeCallback(),this}const l=Math.sqrt(o),h=Math.atan2(l,a),c=Math.sin((1-e)*h)/l,u=Math.sin(e*h)/l;return this._w=r*c+this._w*u,this._x=i*c+this._x*u,this._y=n*c+this._y*u,this._z=s*c+this._z*u,this._onChangeCallback(),this}slerpQuaternions(t,e,i){this.copy(t).slerp(e,i)}random(){const t=Math.random(),e=Math.sqrt(1-t),i=Math.sqrt(t),n=2*Math.PI*Math.random(),s=2*Math.PI*Math.random();return this.set(e*Math.cos(n),i*Math.sin(s),i*Math.cos(s),e*Math.sin(n))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}};Fi.prototype.isQuaternion=!0;class Di{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i}set(t,e,i){return void 0===i&&(i=this.z),this.x=t,this.y=e,this.z=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t,e){return void 0!==e?this.addVectors(t,e):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this)}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t,e){return void 0!==e?this.subVectors(t,e):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this)}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t,e){return void 0!==e?this.multiplyVectors(t,e):(this.x*=t.x,this.y*=t.y,this.z*=t.z,this)}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return!t||t.isEuler,this.applyQuaternion(Ri.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Ri.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[3]*i+s[6]*n,this.y=s[1]*e+s[4]*i+s[7]*n,this.z=s[2]*e+s[5]*i+s[8]*n,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,i=this.y,n=this.z,s=t.elements,r=1/(s[3]*e+s[7]*i+s[11]*n+s[15]);return this.x=(s[0]*e+s[4]*i+s[8]*n+s[12])*r,this.y=(s[1]*e+s[5]*i+s[9]*n+s[13])*r,this.z=(s[2]*e+s[6]*i+s[10]*n+s[14])*r,this}applyQuaternion(t){const e=this.x,i=this.y,n=this.z,s=t.x,r=t.y,a=t.z,o=t.w,l=o*e+r*n-a*i,h=o*i+a*e-s*n,c=o*n+s*i-r*e,u=-s*e-r*i-a*n;return this.x=l*o+u*-s+h*-a-c*-r,this.y=h*o+u*-r+c*-s-l*-a,this.z=c*o+u*-a+l*-r-h*-s,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,i=this.y,n=this.z,s=t.elements;return this.x=s[0]*e+s[4]*i+s[8]*n,this.y=s[1]*e+s[5]*i+s[9]*n,this.z=s[2]*e+s[6]*i+s[10]*n,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(t,Math.min(e,i)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,i){return this.x=t.x+(e.x-t.x)*i,this.y=t.y+(e.y-t.y)*i,this.z=t.z+(e.z-t.z)*i,this}cross(t,e){return void 0!==e?this.crossVectors(t,e):this.crossVectors(this,t)}crossVectors(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,a=e.y,o=e.z;return this.x=n*o-s*a,this.y=s*r-i*o,this.z=i*a-n*r,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const i=t.dot(this)/e;return this.copy(t).multiplyScalar(i)}projectOnPlane(t){return Oi.copy(this).projectOnVector(t),this.sub(Oi)}reflect(t){return this.sub(Oi.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const i=this.dot(t)/e;return Math.acos(gi(i,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y,n=this.z-t.z;return e*e+i*i+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,i){const n=Math.sin(e)*t;return this.x=n*Math.sin(i),this.y=Math.cos(e)*t,this.z=n*Math.cos(i),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,i){return this.x=t*Math.sin(e),this.y=i,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),i=this.setFromMatrixColumn(t,1).length(),n=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=i,this.z=n,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e,i){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=2*(Math.random()-.5),e=Math.random()*Math.PI*2,i=Math.sqrt(1-t**2);return this.x=i*Math.cos(e),this.y=i*Math.sin(e),this.z=t,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}Di.prototype.isVector3=!0;const Oi=new Di,Ri=new Fi;class ki{constructor(t=new Di(Infinity,Infinity,Infinity),e=new Di(-Infinity,-Infinity,-Infinity)){this.min=t,this.max=e}set(t,e){return this.min.copy(t),this.max.copy(e),this}setFromArray(t){let e=Infinity,i=Infinity,n=Infinity,s=-Infinity,r=-Infinity,a=-Infinity;for(let o=0,l=t.length;o<l;o+=3){const l=t[o],h=t[o+1],c=t[o+2];l<e&&(e=l),h<i&&(i=h),c<n&&(n=c),l>s&&(s=l),h>r&&(r=h),c>a&&(a=c)}return this.min.set(e,i,n),this.max.set(s,r,a),this}setFromBufferAttribute(t){let e=Infinity,i=Infinity,n=Infinity,s=-Infinity,r=-Infinity,a=-Infinity;for(let o=0,l=t.count;o<l;o++){const l=t.getX(o),h=t.getY(o),c=t.getZ(o);l<e&&(e=l),h<i&&(i=h),c<n&&(n=c),l>s&&(s=l),h>r&&(r=h),c>a&&(a=c)}return this.min.set(e,i,n),this.max.set(s,r,a),this}setFromPoints(t){this.makeEmpty();for(let e=0,i=t.length;e<i;e++)this.expandByPoint(t[e]);return this}setFromCenterAndSize(t,e){const i=Bi.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(i),this.max.copy(t).add(i),this}setFromObject(t){return this.makeEmpty(),this.expandByObject(t)}clone(){return(new this.constructor).copy(this)}copy(t){return this.min.copy(t.min),this.max.copy(t.max),this}makeEmpty(){return this.min.x=this.min.y=this.min.z=Infinity,this.max.x=this.max.y=this.max.z=-Infinity,this}isEmpty(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z}getCenter(t){return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}getSize(t){return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}expandByPoint(t){return this.min.min(t),this.max.max(t),this}expandByVector(t){return this.min.sub(t),this.max.add(t),this}expandByScalar(t){return this.min.addScalar(-t),this.max.addScalar(t),this}expandByObject(t){t.updateWorldMatrix(!1,!1);const e=t.geometry;void 0!==e&&(null===e.boundingBox&&e.computeBoundingBox(),Vi.copy(e.boundingBox),Vi.applyMatrix4(t.matrixWorld),this.union(Vi));const i=t.children;for(let t=0,e=i.length;t<e;t++)this.expandByObject(i[t]);return this}containsPoint(t){return!(t.x<this.min.x||t.x>this.max.x||t.y<this.min.y||t.y>this.max.y||t.z<this.min.z||t.z>this.max.z)}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return!(t.max.x<this.min.x||t.min.x>this.max.x||t.max.y<this.min.y||t.min.y>this.max.y||t.max.z<this.min.z||t.min.z>this.max.z)}intersectsSphere(t){return this.clampPoint(t.center,Bi),Bi.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,i;return t.normal.x>0?(e=t.normal.x*this.min.x,i=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,i=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,i+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,i+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,i+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,i+=t.normal.z*this.min.z),e<=-t.constant&&i>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(Yi),Xi.subVectors(this.max,Yi),Gi.subVectors(t.a,Yi),Wi.subVectors(t.b,Yi),Hi.subVectors(t.c,Yi),ji.subVectors(Wi,Gi),qi.subVectors(Hi,Wi),Ji.subVectors(Gi,Hi);let e=[0,-ji.z,ji.y,0,-qi.z,qi.y,0,-Ji.z,Ji.y,ji.z,0,-ji.x,qi.z,0,-qi.x,Ji.z,0,-Ji.x,-ji.y,ji.x,0,-qi.y,qi.x,0,-Ji.y,Ji.x,0];return!!Ki(e,Gi,Wi,Hi,Xi)&&(e=[1,0,0,0,1,0,0,0,1],!!Ki(e,Gi,Wi,Hi,Xi)&&(Zi.crossVectors(ji,qi),e=[Zi.x,Zi.y,Zi.z],Ki(e,Gi,Wi,Hi,Xi)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return Bi.copy(t).clamp(this.min,this.max).sub(t).length()}getBoundingSphere(t){return this.getCenter(t.center),t.radius=.5*this.getSize(Bi).length(),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()||(Ui[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Ui[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Ui[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Ui[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Ui[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Ui[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Ui[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Ui[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Ui)),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}ki.prototype.isBox3=!0;const Ui=[new Di,new Di,new Di,new Di,new Di,new Di,new Di,new Di],Bi=new Di,Vi=new ki,Gi=new Di,Wi=new Di,Hi=new Di,ji=new Di,qi=new Di,Ji=new Di,Yi=new Di,Xi=new Di,Zi=new Di,$i=new Di;function Ki(t,e,i,n,s){for(let r=0,a=t.length-3;r<=a;r+=3){$i.fromArray(t,r);const a=s.x*Math.abs($i.x)+s.y*Math.abs($i.y)+s.z*Math.abs($i.z),o=e.dot($i),l=i.dot($i),h=n.dot($i);if(Math.max(-Math.max(o,l,h),Math.min(o,l,h))>a)return!1}return!0}const Qi=new ki,tn=new Di,en=new Di,nn=new Di;class sn{constructor(t=new Di,e=-1){this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const i=this.center;void 0!==e?i.copy(e):Qi.setFromPoints(t).getCenter(i);let n=0;for(let e=0,s=t.length;e<s;e++)n=Math.max(n,i.distanceToSquared(t[e]));return this.radius=Math.sqrt(n),this}copy(t){return this.center.copy(t.center),this.radius=t.radius,this}isEmpty(){return this.radius<0}makeEmpty(){return this.center.set(0,0,0),this.radius=-1,this}containsPoint(t){return t.distanceToSquared(this.center)<=this.radius*this.radius}distanceToPoint(t){return t.distanceTo(this.center)-this.radius}intersectsSphere(t){const e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e}intersectsBox(t){return t.intersectsSphere(this)}intersectsPlane(t){return Math.abs(t.distanceToPoint(this.center))<=this.radius}clampPoint(t,e){const i=this.center.distanceToSquared(t);return e.copy(t),i>this.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){nn.subVectors(t,this.center);const e=nn.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),i=.5*(t-this.radius);this.center.add(nn.multiplyScalar(i/t)),this.radius+=i}return this}union(t){return en.subVectors(t.center,this.center).normalize().multiplyScalar(t.radius),this.expandByPoint(tn.copy(t.center).add(en)),this.expandByPoint(tn.copy(t.center).sub(en)),this}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const rn=new Di,an=new Di,on=new Di,ln=new Di,hn=new Di,cn=new Di,un=new Di;class dn{constructor(t=new Di,e=new Di(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.direction).multiplyScalar(t).add(this.origin)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,rn)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const i=e.dot(this.direction);return i<0?e.copy(this.origin):e.copy(this.direction).multiplyScalar(i).add(this.origin)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=rn.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(rn.copy(this.direction).multiplyScalar(e).add(this.origin),rn.distanceToSquared(t))}distanceSqToSegment(t,e,i,n){an.copy(t).add(e).multiplyScalar(.5),on.copy(e).sub(t).normalize(),ln.copy(this.origin).sub(an);const s=.5*t.distanceTo(e),r=-this.direction.dot(on),a=ln.dot(this.direction),o=-ln.dot(on),l=ln.lengthSq(),h=Math.abs(1-r*r);let c,u,d,p;if(h>0)if(c=r*o-a,u=r*a-o,p=s*h,c>=0)if(u>=-p)if(u<=p){const t=1/h;c*=t,u*=t,d=c*(c+r*u+2*a)+u*(r*c+u+2*o)+l}else u=s,c=Math.max(0,-(r*u+a)),d=-c*c+u*(u+2*o)+l;else u=-s,c=Math.max(0,-(r*u+a)),d=-c*c+u*(u+2*o)+l;else u<=-p?(c=Math.max(0,-(-r*s+a)),u=c>0?-s:Math.min(Math.max(-s,-o),s),d=-c*c+u*(u+2*o)+l):u<=p?(c=0,u=Math.min(Math.max(-s,-o),s),d=u*(u+2*o)+l):(c=Math.max(0,-(r*s+a)),u=c>0?s:Math.min(Math.max(-s,-o),s),d=-c*c+u*(u+2*o)+l);else u=r>0?-s:s,c=Math.max(0,-(r*u+a)),d=-c*c+u*(u+2*o)+l;return i&&i.copy(this.direction).multiplyScalar(c).add(this.origin),n&&n.copy(on).multiplyScalar(u).add(an),d}intersectSphere(t,e){rn.subVectors(t.center,this.origin);const i=rn.dot(this.direction),n=rn.dot(rn)-i*i,s=t.radius*t.radius;if(n>s)return null;const r=Math.sqrt(s-n),a=i-r,o=i+r;return a<0&&o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const i=-(this.origin.dot(t.normal)+t.constant)/e;return i>=0?i:null}intersectPlane(t,e){const i=this.distanceToPlane(t);return null===i?null:this.at(i,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return 0===e||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let i,n,s,r,a,o;const l=1/this.direction.x,h=1/this.direction.y,c=1/this.direction.z,u=this.origin;return l>=0?(i=(t.min.x-u.x)*l,n=(t.max.x-u.x)*l):(i=(t.max.x-u.x)*l,n=(t.min.x-u.x)*l),h>=0?(s=(t.min.y-u.y)*h,r=(t.max.y-u.y)*h):(s=(t.max.y-u.y)*h,r=(t.min.y-u.y)*h),i>r||s>n?null:((s>i||i!=i)&&(i=s),(r<n||n!=n)&&(n=r),c>=0?(a=(t.min.z-u.z)*c,o=(t.max.z-u.z)*c):(a=(t.max.z-u.z)*c,o=(t.min.z-u.z)*c),i>o||a>n?null:((a>i||i!=i)&&(i=a),(o<n||n!=n)&&(n=o),n<0?null:this.at(i>=0?i:n,e)))}intersectsBox(t){return null!==this.intersectBox(t,rn)}intersectTriangle(t,e,i,n,s){hn.subVectors(e,t),cn.subVectors(i,t),un.crossVectors(hn,cn);let r,a=this.direction.dot(un);if(a>0){if(n)return null;r=1}else{if(!(a<0))return null;r=-1,a=-a}ln.subVectors(this.origin,t);const o=r*this.direction.dot(cn.crossVectors(ln,cn));if(o<0)return null;const l=r*this.direction.dot(hn.cross(ln));if(l<0)return null;if(o+l>a)return null;const h=-r*ln.dot(un);return h<0?null:this.at(h/a,s)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class pn{constructor(){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]}set(t,e,i,n,s,r,a,o,l,h,c,u,d,p,f,m){const _=this.elements;return _[0]=t,_[4]=e,_[8]=i,_[12]=n,_[1]=s,_[5]=r,_[9]=a,_[13]=o,_[2]=l,_[6]=h,_[10]=c,_[14]=u,_[3]=d,_[7]=p,_[11]=f,_[15]=m,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new pn).fromArray(this.elements)}copy(t){const e=this.elements,i=t.elements;return e[0]=i[0],e[1]=i[1],e[2]=i[2],e[3]=i[3],e[4]=i[4],e[5]=i[5],e[6]=i[6],e[7]=i[7],e[8]=i[8],e[9]=i[9],e[10]=i[10],e[11]=i[11],e[12]=i[12],e[13]=i[13],e[14]=i[14],e[15]=i[15],this}copyPosition(t){const e=this.elements,i=t.elements;return e[12]=i[12],e[13]=i[13],e[14]=i[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,i){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this}makeBasis(t,e,i){return this.set(t.x,e.x,i.x,0,t.y,e.y,i.y,0,t.z,e.z,i.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,i=t.elements,n=1/fn.setFromMatrixColumn(t,0).length(),s=1/fn.setFromMatrixColumn(t,1).length(),r=1/fn.setFromMatrixColumn(t,2).length();return e[0]=i[0]*n,e[1]=i[1]*n,e[2]=i[2]*n,e[3]=0,e[4]=i[4]*s,e[5]=i[5]*s,e[6]=i[6]*s,e[7]=0,e[8]=i[8]*r,e[9]=i[9]*r,e[10]=i[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){!t||t.isEuler;const e=this.elements,i=t.x,n=t.y,s=t.z,r=Math.cos(i),a=Math.sin(i),o=Math.cos(n),l=Math.sin(n),h=Math.cos(s),c=Math.sin(s);if("XYZ"===t.order){const t=r*h,i=r*c,n=a*h,s=a*c;e[0]=o*h,e[4]=-o*c,e[8]=l,e[1]=i+n*l,e[5]=t-s*l,e[9]=-a*o,e[2]=s-t*l,e[6]=n+i*l,e[10]=r*o}else if("YXZ"===t.order){const t=o*h,i=o*c,n=l*h,s=l*c;e[0]=t+s*a,e[4]=n*a-i,e[8]=r*l,e[1]=r*c,e[5]=r*h,e[9]=-a,e[2]=i*a-n,e[6]=s+t*a,e[10]=r*o}else if("ZXY"===t.order){const t=o*h,i=o*c,n=l*h,s=l*c;e[0]=t-s*a,e[4]=-r*c,e[8]=n+i*a,e[1]=i+n*a,e[5]=r*h,e[9]=s-t*a,e[2]=-r*l,e[6]=a,e[10]=r*o}else if("ZYX"===t.order){const t=r*h,i=r*c,n=a*h,s=a*c;e[0]=o*h,e[4]=n*l-i,e[8]=t*l+s,e[1]=o*c,e[5]=s*l+t,e[9]=i*l-n,e[2]=-l,e[6]=a*o,e[10]=r*o}else if("YZX"===t.order){const t=r*o,i=r*l,n=a*o,s=a*l;e[0]=o*h,e[4]=s-t*c,e[8]=n*c+i,e[1]=c,e[5]=r*h,e[9]=-a*h,e[2]=-l*h,e[6]=i*c+n,e[10]=t-s*c}else if("XZY"===t.order){const t=r*o,i=r*l,n=a*o,s=a*l;e[0]=o*h,e[4]=-c,e[8]=l*h,e[1]=t*c+s,e[5]=r*h,e[9]=i*c-n,e[2]=n*c-i,e[6]=a*h,e[10]=s*c+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(_n,t,gn)}lookAt(t,e,i){const n=this.elements;return xn.subVectors(t,e),0===xn.lengthSq()&&(xn.z=1),xn.normalize(),yn.crossVectors(i,xn),0===yn.lengthSq()&&(1===Math.abs(i.z)?xn.x+=1e-4:xn.z+=1e-4,xn.normalize(),yn.crossVectors(i,xn)),yn.normalize(),vn.crossVectors(xn,yn),n[0]=yn.x,n[4]=vn.x,n[8]=xn.x,n[1]=yn.y,n[5]=vn.y,n[9]=xn.y,n[2]=yn.z,n[6]=vn.z,n[10]=xn.z,this}multiply(t,e){return void 0!==e?this.multiplyMatrices(t,e):this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const i=t.elements,n=e.elements,s=this.elements,r=i[0],a=i[4],o=i[8],l=i[12],h=i[1],c=i[5],u=i[9],d=i[13],p=i[2],f=i[6],m=i[10],_=i[14],g=i[3],y=i[7],v=i[11],x=i[15],w=n[0],b=n[4],S=n[8],M=n[12],T=n[1],C=n[5],A=n[9],E=n[13],z=n[2],I=n[6],N=n[10],L=n[14],P=n[3],F=n[7],D=n[11],O=n[15];return s[0]=r*w+a*T+o*z+l*P,s[4]=r*b+a*C+o*I+l*F,s[8]=r*S+a*A+o*N+l*D,s[12]=r*M+a*E+o*L+l*O,s[1]=h*w+c*T+u*z+d*P,s[5]=h*b+c*C+u*I+d*F,s[9]=h*S+c*A+u*N+d*D,s[13]=h*M+c*E+u*L+d*O,s[2]=p*w+f*T+m*z+_*P,s[6]=p*b+f*C+m*I+_*F,s[10]=p*S+f*A+m*N+_*D,s[14]=p*M+f*E+m*L+_*O,s[3]=g*w+y*T+v*z+x*P,s[7]=g*b+y*C+v*I+x*F,s[11]=g*S+y*A+v*N+x*D,s[15]=g*M+y*E+v*L+x*O,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],i=t[4],n=t[8],s=t[12],r=t[1],a=t[5],o=t[9],l=t[13],h=t[2],c=t[6],u=t[10],d=t[14];return t[3]*(+s*o*c-n*l*c-s*a*u+i*l*u+n*a*d-i*o*d)+t[7]*(+e*o*d-e*l*u+s*r*u-n*r*d+n*l*h-s*o*h)+t[11]*(+e*l*c-e*a*d-s*r*c+i*r*d+s*a*h-i*l*h)+t[15]*(-n*a*h-e*o*c+e*a*u+n*r*c-i*r*u+i*o*h)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,i){const n=this.elements;return t.isVector3?(n[12]=t.x,n[13]=t.y,n[14]=t.z):(n[12]=t,n[13]=e,n[14]=i),this}invert(){const t=this.elements,e=t[0],i=t[1],n=t[2],s=t[3],r=t[4],a=t[5],o=t[6],l=t[7],h=t[8],c=t[9],u=t[10],d=t[11],p=t[12],f=t[13],m=t[14],_=t[15],g=c*m*l-f*u*l+f*o*d-a*m*d-c*o*_+a*u*_,y=p*u*l-h*m*l-p*o*d+r*m*d+h*o*_-r*u*_,v=h*f*l-p*c*l+p*a*d-r*f*d-h*a*_+r*c*_,x=p*c*o-h*f*o-p*a*u+r*f*u+h*a*m-r*c*m,w=e*g+i*y+n*v+s*x;if(0===w)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const b=1/w;return t[0]=g*b,t[1]=(f*u*s-c*m*s-f*n*d+i*m*d+c*n*_-i*u*_)*b,t[2]=(a*m*s-f*o*s+f*n*l-i*m*l-a*n*_+i*o*_)*b,t[3]=(c*o*s-a*u*s-c*n*l+i*u*l+a*n*d-i*o*d)*b,t[4]=y*b,t[5]=(h*m*s-p*u*s+p*n*d-e*m*d-h*n*_+e*u*_)*b,t[6]=(p*o*s-r*m*s-p*n*l+e*m*l+r*n*_-e*o*_)*b,t[7]=(r*u*s-h*o*s+h*n*l-e*u*l-r*n*d+e*o*d)*b,t[8]=v*b,t[9]=(p*c*s-h*f*s-p*i*d+e*f*d+h*i*_-e*c*_)*b,t[10]=(r*f*s-p*a*s+p*i*l-e*f*l-r*i*_+e*a*_)*b,t[11]=(h*a*s-r*c*s-h*i*l+e*c*l+r*i*d-e*a*d)*b,t[12]=x*b,t[13]=(h*f*n-p*c*n+p*i*u-e*f*u-h*i*m+e*c*m)*b,t[14]=(p*a*n-r*f*n-p*i*o+e*f*o+r*i*m-e*a*m)*b,t[15]=(r*c*n-h*a*n+h*i*o-e*c*o-r*i*u+e*a*u)*b,this}scale(t){const e=this.elements,i=t.x,n=t.y,s=t.z;return e[0]*=i,e[4]*=n,e[8]*=s,e[1]*=i,e[5]*=n,e[9]*=s,e[2]*=i,e[6]*=n,e[10]*=s,e[3]*=i,e[7]*=n,e[11]*=s,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],i=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],n=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,i,n))}makeTranslation(t,e,i){return this.set(1,0,0,t,0,1,0,e,0,0,1,i,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),i=Math.sin(t);return this.set(1,0,0,0,0,e,-i,0,0,i,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,0,i,0,0,1,0,0,-i,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),i=Math.sin(t);return this.set(e,-i,0,0,i,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const i=Math.cos(e),n=Math.sin(e),s=1-i,r=t.x,a=t.y,o=t.z,l=s*r,h=s*a;return this.set(l*r+i,l*a-n*o,l*o+n*a,0,l*a+n*o,h*a+i,h*o-n*r,0,l*o-n*a,h*o+n*r,s*o*o+i,0,0,0,0,1),this}makeScale(t,e,i){return this.set(t,0,0,0,0,e,0,0,0,0,i,0,0,0,0,1),this}makeShear(t,e,i,n,s,r){return this.set(1,i,s,0,t,1,r,0,e,n,1,0,0,0,0,1),this}compose(t,e,i){const n=this.elements,s=e._x,r=e._y,a=e._z,o=e._w,l=s+s,h=r+r,c=a+a,u=s*l,d=s*h,p=s*c,f=r*h,m=r*c,_=a*c,g=o*l,y=o*h,v=o*c,x=i.x,w=i.y,b=i.z;return n[0]=(1-(f+_))*x,n[1]=(d+v)*x,n[2]=(p-y)*x,n[3]=0,n[4]=(d-v)*w,n[5]=(1-(u+_))*w,n[6]=(m+g)*w,n[7]=0,n[8]=(p+y)*b,n[9]=(m-g)*b,n[10]=(1-(u+f))*b,n[11]=0,n[12]=t.x,n[13]=t.y,n[14]=t.z,n[15]=1,this}decompose(t,e,i){const n=this.elements;let s=fn.set(n[0],n[1],n[2]).length();const r=fn.set(n[4],n[5],n[6]).length(),a=fn.set(n[8],n[9],n[10]).length();this.determinant()<0&&(s=-s),t.x=n[12],t.y=n[13],t.z=n[14],mn.copy(this);const o=1/s,l=1/r,h=1/a;return mn.elements[0]*=o,mn.elements[1]*=o,mn.elements[2]*=o,mn.elements[4]*=l,mn.elements[5]*=l,mn.elements[6]*=l,mn.elements[8]*=h,mn.elements[9]*=h,mn.elements[10]*=h,e.setFromRotationMatrix(mn),i.x=s,i.y=r,i.z=a,this}makePerspective(t,e,i,n,s,r){const a=this.elements,o=2*s/(e-t),l=2*s/(i-n),h=(e+t)/(e-t),c=(i+n)/(i-n),u=-(r+s)/(r-s),d=-2*r*s/(r-s);return a[0]=o,a[4]=0,a[8]=h,a[12]=0,a[1]=0,a[5]=l,a[9]=c,a[13]=0,a[2]=0,a[6]=0,a[10]=u,a[14]=d,a[3]=0,a[7]=0,a[11]=-1,a[15]=0,this}makeOrthographic(t,e,i,n,s,r){const a=this.elements,o=1/(e-t),l=1/(i-n),h=1/(r-s),c=(e+t)*o,u=(i+n)*l,d=(r+s)*h;return a[0]=2*o,a[4]=0,a[8]=0,a[12]=-c,a[1]=0,a[5]=2*l,a[9]=0,a[13]=-u,a[2]=0,a[6]=0,a[10]=-2*h,a[14]=-d,a[3]=0,a[7]=0,a[11]=0,a[15]=1,this}equals(t){const e=this.elements,i=t.elements;for(let t=0;t<16;t++)if(e[t]!==i[t])return!1;return!0}fromArray(t,e=0){for(let i=0;i<16;i++)this.elements[i]=t[i+e];return this}toArray(t=[],e=0){const i=this.elements;return t[e]=i[0],t[e+1]=i[1],t[e+2]=i[2],t[e+3]=i[3],t[e+4]=i[4],t[e+5]=i[5],t[e+6]=i[6],t[e+7]=i[7],t[e+8]=i[8],t[e+9]=i[9],t[e+10]=i[10],t[e+11]=i[11],t[e+12]=i[12],t[e+13]=i[13],t[e+14]=i[14],t[e+15]=i[15],t}}pn.prototype.isMatrix4=!0;const fn=new Di,mn=new pn,_n=new Di(0,0,0),gn=new Di(1,1,1),yn=new Di,vn=new Di,xn=new Di,wn=new pn,bn=new Fi;class Sn{constructor(t=0,e=0,i=0,n=Sn.DefaultOrder){this._x=t,this._y=e,this._z=i,this._order=n}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,i,n=this._order){return this._x=t,this._y=e,this._z=i,this._order=n,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,i=!0){const n=t.elements,s=n[0],r=n[4],a=n[8],o=n[1],l=n[5],h=n[9],c=n[2],u=n[6],d=n[10];switch(e){case"XYZ":this._y=Math.asin(gi(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-h,d),this._z=Math.atan2(-r,s)):(this._x=Math.atan2(u,l),this._z=0);break;case"YXZ":this._x=Math.asin(-gi(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,l)):(this._y=Math.atan2(-c,s),this._z=0);break;case"ZXY":this._x=Math.asin(gi(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(-c,d),this._z=Math.atan2(-r,l)):(this._y=0,this._z=Math.atan2(o,s));break;case"ZYX":this._y=Math.asin(-gi(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(u,d),this._z=Math.atan2(o,s)):(this._x=0,this._z=Math.atan2(-r,l));break;case"YZX":this._z=Math.asin(gi(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-c,s)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-gi(r,-1,1)),Math.abs(r)<.9999999?(this._x=Math.atan2(u,l),this._y=Math.atan2(a,s)):(this._x=Math.atan2(-h,d),this._y=0)}return this._order=e,!0===i&&this._onChangeCallback(),this}setFromQuaternion(t,e,i){return wn.makeRotationFromQuaternion(t),this.setFromRotationMatrix(wn,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return bn.setFromEuler(this),this.setFromQuaternion(bn,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}toVector3(t){return t?t.set(this._x,this._y,this._z):new Di(this._x,this._y,this._z)}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}}Sn.prototype.isEuler=!0,Sn.DefaultOrder="XYZ",Sn.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"];class Mn{constructor(){this.mask=1}set(t){this.mask=(1<<t|0)>>>0}enable(t){this.mask|=1<<t|0}enableAll(){this.mask=-1}toggle(t){this.mask^=1<<t|0}disable(t){this.mask&=~(1<<t|0)}disableAll(){this.mask=0}test(t){return 0!=(this.mask&t.mask)}isEnabled(t){return 0!=(this.mask&(1<<t|0))}}let Tn=0;const Cn=new Di,An=new Fi,En=new pn,zn=new Di,In=new Di,Nn=new Di,Ln=new Fi,Pn=new Di(1,0,0),Fn=new Di(0,1,0),Dn=new Di(0,0,1),On={type:"added"},Rn={type:"removed"};class kn extends di{constructor(){super(),Object.defineProperty(this,"id",{value:Tn++}),this.uuid=_i(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=kn.DefaultUp.clone();const t=new Di,e=new Sn,i=new Fi,n=new Di(1,1,1);e._onChange((function(){i.setFromEuler(e,!1)})),i._onChange((function(){e.setFromQuaternion(i,void 0,!1)})),Object.defineProperties(this,{position:{configurable:!0,enumerable:!0,value:t},rotation:{configurable:!0,enumerable:!0,value:e},quaternion:{configurable:!0,enumerable:!0,value:i},scale:{configurable:!0,enumerable:!0,value:n},modelViewMatrix:{value:new pn},normalMatrix:{value:new Si}}),this.matrix=new pn,this.matrixWorld=new pn,this.matrixAutoUpdate=kn.DefaultMatrixAutoUpdate,this.matrixWorldNeedsUpdate=!1,this.layers=new Mn,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.renderOrder=0,this.animations=[],this.userData={}}onBeforeRender(){}onAfterRender(){}applyMatrix4(t){this.matrixAutoUpdate&&this.updateMatrix(),this.matrix.premultiply(t),this.matrix.decompose(this.position,this.quaternion,this.scale)}applyQuaternion(t){return this.quaternion.premultiply(t),this}setRotationFromAxisAngle(t,e){this.quaternion.setFromAxisAngle(t,e)}setRotationFromEuler(t){this.quaternion.setFromEuler(t,!0)}setRotationFromMatrix(t){this.quaternion.setFromRotationMatrix(t)}setRotationFromQuaternion(t){this.quaternion.copy(t)}rotateOnAxis(t,e){return An.setFromAxisAngle(t,e),this.quaternion.multiply(An),this}rotateOnWorldAxis(t,e){return An.setFromAxisAngle(t,e),this.quaternion.premultiply(An),this}rotateX(t){return this.rotateOnAxis(Pn,t)}rotateY(t){return this.rotateOnAxis(Fn,t)}rotateZ(t){return this.rotateOnAxis(Dn,t)}translateOnAxis(t,e){return Cn.copy(t).applyQuaternion(this.quaternion),this.position.add(Cn.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Pn,t)}translateY(t){return this.translateOnAxis(Fn,t)}translateZ(t){return this.translateOnAxis(Dn,t)}localToWorld(t){return t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return t.applyMatrix4(En.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?zn.copy(t):zn.set(t,e,i);const n=this.parent;this.updateWorldMatrix(!0,!1),In.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?En.lookAt(In,zn,this.up):En.lookAt(zn,In,this.up),this.quaternion.setFromRotationMatrix(En),n&&(En.extractRotation(n.matrixWorld),An.setFromRotationMatrix(En),this.quaternion.premultiply(An.invert()))}add(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.add(arguments[t]);return this}return t===this||t&&t.isObject3D&&(null!==t.parent&&t.parent.remove(t),t.parent=this,this.children.push(t),t.dispatchEvent(On)),this}remove(t){if(arguments.length>1){for(let t=0;t<arguments.length;t++)this.remove(arguments[t]);return this}const e=this.children.indexOf(t);return-1!==e&&(t.parent=null,this.children.splice(e,1),t.dispatchEvent(Rn)),this}removeFromParent(){const t=this.parent;return null!==t&&t.remove(this),this}clear(){for(let t=0;t<this.children.length;t++){const e=this.children[t];e.parent=null,e.dispatchEvent(Rn)}return this.children.length=0,this}attach(t){return this.updateWorldMatrix(!0,!1),En.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),En.multiply(t.parent.matrixWorld)),t.applyMatrix4(En),this.add(t),t.updateWorldMatrix(!1,!0),this}getObjectById(t){return this.getObjectByProperty("id",t)}getObjectByName(t){return this.getObjectByProperty("name",t)}getObjectByProperty(t,e){if(this[t]===e)return this;for(let i=0,n=this.children.length;i<n;i++){const n=this.children[i].getObjectByProperty(t,e);if(void 0!==n)return n}}getWorldPosition(t){return this.updateWorldMatrix(!0,!1),t.setFromMatrixPosition(this.matrixWorld)}getWorldQuaternion(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(In,t,Nn),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(In,Ln,t),t}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(e[8],e[9],e[10]).normalize()}raycast(){}traverse(t){t(this);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].traverse(t)}traverseVisible(t){if(!1===this.visible)return;t(this);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].traverseVisible(t)}traverseAncestors(t){const e=this.parent;null!==e&&(t(e),e.traverseAncestors(t))}updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0}updateMatrixWorld(t){this.matrixAutoUpdate&&this.updateMatrix(),(this.matrixWorldNeedsUpdate||t)&&(null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),this.matrixWorldNeedsUpdate=!1,t=!0);const e=this.children;for(let i=0,n=e.length;i<n;i++)e[i].updateMatrixWorld(t)}updateWorldMatrix(t,e){const i=this.parent;if(!0===t&&null!==i&&i.updateWorldMatrix(!0,!1),this.matrixAutoUpdate&&this.updateMatrix(),null===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),!0===e){const t=this.children;for(let e=0,i=t.length;e<i;e++)t[e].updateWorldMatrix(!1,!0)}}toJSON(t){const e=void 0===t||"string"==typeof t,i={};e&&(t={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{}},i.metadata={version:4.5,type:"Object",generator:"Object3D.toJSON"});const n={};function s(e,i){return void 0===e[i.uuid]&&(e[i.uuid]=i.toJSON(t)),i.uuid}if(n.uuid=this.uuid,n.type=this.type,""!==this.name&&(n.name=this.name),!0===this.castShadow&&(n.castShadow=!0),!0===this.receiveShadow&&(n.receiveShadow=!0),!1===this.visible&&(n.visible=!1),!1===this.frustumCulled&&(n.frustumCulled=!1),0!==this.renderOrder&&(n.renderOrder=this.renderOrder),"{}"!==JSON.stringify(this.userData)&&(n.userData=this.userData),n.layers=this.layers.mask,n.matrix=this.matrix.toArray(),!1===this.matrixAutoUpdate&&(n.matrixAutoUpdate=!1),this.isInstancedMesh&&(n.type="InstancedMesh",n.count=this.count,n.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(n.instanceColor=this.instanceColor.toJSON())),this.isScene)this.background&&(this.background.isColor?n.background=this.background.toJSON():this.background.isTexture&&(n.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&(n.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){n.geometry=s(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const i=e.shapes;if(Array.isArray(i))for(let e=0,n=i.length;e<n;e++){const n=i[e];s(t.shapes,n)}else s(t.shapes,i)}}if(this.isSkinnedMesh&&(n.bindMode=this.bindMode,n.bindMatrix=this.bindMatrix.toArray(),void 0!==this.skeleton&&(s(t.skeletons,this.skeleton),n.skeleton=this.skeleton.uuid)),void 0!==this.material)if(Array.isArray(this.material)){const e=[];for(let i=0,n=this.material.length;i<n;i++)e.push(s(t.materials,this.material[i]));n.material=e}else n.material=s(t.materials,this.material);if(this.children.length>0){n.children=[];for(let e=0;e<this.children.length;e++)n.children.push(this.children[e].toJSON(t).object)}if(this.animations.length>0){n.animations=[];for(let e=0;e<this.animations.length;e++){const i=this.animations[e];n.animations.push(s(t.animations,i))}}if(e){const e=r(t.geometries),n=r(t.materials),s=r(t.textures),a=r(t.images),o=r(t.shapes),l=r(t.skeletons),h=r(t.animations);e.length>0&&(i.geometries=e),n.length>0&&(i.materials=n),s.length>0&&(i.textures=s),a.length>0&&(i.images=a),o.length>0&&(i.shapes=o),l.length>0&&(i.skeletons=l),h.length>0&&(i.animations=h)}return i.object=n,i;function r(t){const e=[];for(const i in t){const n=t[i];delete n.metadata,e.push(n)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let e=0;e<t.children.length;e++){const i=t.children[e];this.add(i.clone())}return this}}kn.DefaultUp=new Di(0,1,0),kn.DefaultMatrixAutoUpdate=!0,kn.prototype.isObject3D=!0;const Un=new Di,Bn=new Di,Vn=new Di,Gn=new Di,Wn=new Di,Hn=new Di,jn=new Di,qn=new Di,Jn=new Di,Yn=new Di;class Xn{constructor(t=new Di,e=new Di,i=new Di){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,n){n.subVectors(i,e),Un.subVectors(t,e),n.cross(Un);const s=n.lengthSq();return s>0?n.multiplyScalar(1/Math.sqrt(s)):n.set(0,0,0)}static getBarycoord(t,e,i,n,s){Un.subVectors(n,e),Bn.subVectors(i,e),Vn.subVectors(t,e);const r=Un.dot(Un),a=Un.dot(Bn),o=Un.dot(Vn),l=Bn.dot(Bn),h=Bn.dot(Vn),c=r*l-a*a;if(0===c)return s.set(-2,-1,-1);const u=1/c,d=(l*o-a*h)*u,p=(r*h-a*o)*u;return s.set(1-d-p,p,d)}static containsPoint(t,e,i,n){return this.getBarycoord(t,e,i,n,Gn),Gn.x>=0&&Gn.y>=0&&Gn.x+Gn.y<=1}static getUV(t,e,i,n,s,r,a,o){return this.getBarycoord(t,e,i,n,Gn),o.set(0,0),o.addScaledVector(s,Gn.x),o.addScaledVector(r,Gn.y),o.addScaledVector(a,Gn.z),o}static isFrontFacing(t,e,i,n){return Un.subVectors(i,e),Bn.subVectors(t,e),Un.cross(Bn).dot(n)<0}set(t,e,i){return this.a.copy(t),this.b.copy(e),this.c.copy(i),this}setFromPointsAndIndices(t,e,i,n){return this.a.copy(t[e]),this.b.copy(t[i]),this.c.copy(t[n]),this}setFromAttributeAndIndices(t,e,i,n){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,i),this.c.fromBufferAttribute(t,n),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return Un.subVectors(this.c,this.b),Bn.subVectors(this.a,this.b),.5*Un.cross(Bn).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return Xn.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return Xn.getBarycoord(t,this.a,this.b,this.c,e)}getUV(t,e,i,n,s){return Xn.getUV(t,this.a,this.b,this.c,e,i,n,s)}containsPoint(t){return Xn.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return Xn.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const i=this.a,n=this.b,s=this.c;let r,a;Wn.subVectors(n,i),Hn.subVectors(s,i),qn.subVectors(t,i);const o=Wn.dot(qn),l=Hn.dot(qn);if(o<=0&&l<=0)return e.copy(i);Jn.subVectors(t,n);const h=Wn.dot(Jn),c=Hn.dot(Jn);if(h>=0&&c<=h)return e.copy(n);const u=o*c-h*l;if(u<=0&&o>=0&&h<=0)return r=o/(o-h),e.copy(i).addScaledVector(Wn,r);Yn.subVectors(t,s);const d=Wn.dot(Yn),p=Hn.dot(Yn);if(p>=0&&d<=p)return e.copy(s);const f=d*l-o*p;if(f<=0&&l>=0&&p<=0)return a=l/(l-p),e.copy(i).addScaledVector(Hn,a);const m=h*p-d*c;if(m<=0&&c-h>=0&&d-p>=0)return jn.subVectors(s,n),a=(c-h)/(c-h+(d-p)),e.copy(n).addScaledVector(jn,a);const _=1/(m+f+u);return r=f*_,a=u*_,e.copy(i).addScaledVector(Wn,r).addScaledVector(Hn,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}let Zn=0;class $n extends di{constructor(){super(),Object.defineProperty(this,"id",{value:Zn++}),this.uuid=_i(),this.name="",this.type="Material",this.fog=!0,this.blending=D,this.side=N,this.vertexColors=!1,this.opacity=1,this.format=Yt,this.transparent=!1,this.blendSrc=X,this.blendDst=Z,this.blendEquation=B,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.depthFunc=rt,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=li,this.stencilZFail=li,this.stencilZPass=li,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.visible=!0,this.toneMapped=!0,this.userData={},this.version=0,this._alphaTest=0}get alphaTest(){return this._alphaTest}set alphaTest(t){this._alphaTest>0!=t>0&&this.version++,this._alphaTest=t}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const i=t[e];if(void 0===i)continue;if("shading"===e){this.flatShading=1===i;continue}const n=this[e];void 0!==n&&(n&&n.isColor?n.set(i):n&&n.isVector3&&i&&i.isVector3?n.copy(i):this[e]=i)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const i={metadata:{version:4.5,type:"Material",generator:"Material.toJSON"}};function n(t){const e=[];for(const i in t){const n=t[i];delete n.metadata,e.push(n)}return e}if(i.uuid=this.uuid,i.type=this.type,""!==this.name&&(i.name=this.name),this.color&&this.color.isColor&&(i.color=this.color.getHex()),void 0!==this.roughness&&(i.roughness=this.roughness),void 0!==this.metalness&&(i.metalness=this.metalness),void 0!==this.sheen&&(i.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(i.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(i.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(i.emissive=this.emissive.getHex()),this.emissiveIntensity&&1!==this.emissiveIntensity&&(i.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(i.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(i.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(i.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(i.shininess=this.shininess),void 0!==this.clearcoat&&(i.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(i.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(i.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(i.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(i.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,i.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.map&&this.map.isTexture&&(i.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(i.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(i.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(i.lightMap=this.lightMap.toJSON(t).uuid,i.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(i.aoMap=this.aoMap.toJSON(t).uuid,i.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(i.bumpMap=this.bumpMap.toJSON(t).uuid,i.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(i.normalMap=this.normalMap.toJSON(t).uuid,i.normalMapType=this.normalMapType,i.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(i.displacementMap=this.displacementMap.toJSON(t).uuid,i.displacementScale=this.displacementScale,i.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(i.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(i.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(i.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(i.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(i.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(i.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(i.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(i.combine=this.combine)),void 0!==this.envMapIntensity&&(i.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(i.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(i.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(i.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(i.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(i.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(i.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(i.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&(i.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(i.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(i.size=this.size),null!==this.shadowSide&&(i.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(i.sizeAttenuation=this.sizeAttenuation),this.blending!==D&&(i.blending=this.blending),this.side!==N&&(i.side=this.side),this.vertexColors&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),this.format!==Yt&&(i.format=this.format),!0===this.transparent&&(i.transparent=this.transparent),i.depthFunc=this.depthFunc,i.depthTest=this.depthTest,i.depthWrite=this.depthWrite,i.colorWrite=this.colorWrite,i.stencilWrite=this.stencilWrite,i.stencilWriteMask=this.stencilWriteMask,i.stencilFunc=this.stencilFunc,i.stencilRef=this.stencilRef,i.stencilFuncMask=this.stencilFuncMask,i.stencilFail=this.stencilFail,i.stencilZFail=this.stencilZFail,i.stencilZPass=this.stencilZPass,this.rotation&&0!==this.rotation&&(i.rotation=this.rotation),!0===this.polygonOffset&&(i.polygonOffset=!0),0!==this.polygonOffsetFactor&&(i.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(i.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth&&1!==this.linewidth&&(i.linewidth=this.linewidth),void 0!==this.dashSize&&(i.dashSize=this.dashSize),void 0!==this.gapSize&&(i.gapSize=this.gapSize),void 0!==this.scale&&(i.scale=this.scale),!0===this.dithering&&(i.dithering=!0),this.alphaTest>0&&(i.alphaTest=this.alphaTest),!0===this.alphaToCoverage&&(i.alphaToCoverage=this.alphaToCoverage),!0===this.premultipliedAlpha&&(i.premultipliedAlpha=this.premultipliedAlpha),!0===this.wireframe&&(i.wireframe=this.wireframe),this.wireframeLinewidth>1&&(i.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(i.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(i.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(i.flatShading=this.flatShading),!1===this.visible&&(i.visible=!1),!1===this.toneMapped&&(i.toneMapped=!1),"{}"!==JSON.stringify(this.userData)&&(i.userData=this.userData),e){const e=n(t.textures),s=n(t.images);e.length>0&&(i.textures=e),s.length>0&&(i.images=s)}return i}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.fog=t.fog,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.format=t.format,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let i=null;if(null!==e){const t=e.length;i=new Array(t);for(let n=0;n!==t;++n)i[n]=e[n].clone()}return this.clippingPlanes=i,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}}$n.prototype.isMaterial=!0;const Kn={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},Qn={h:0,s:0,l:0},ts={h:0,s:0,l:0};function es(t,e,i){return i<0&&(i+=1),i>1&&(i-=1),i<1/6?t+6*(e-t)*i:i<.5?e:i<2/3?t+6*(e-t)*(2/3-i):t}function is(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function ns(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let ss=class{constructor(t,e,i){return void 0===e&&void 0===i?this.set(t):this.setRGB(t,e,i)}set(t){return t&&t.isColor?this.copy(t):"number"==typeof t?this.setHex(t):"string"==typeof t&&this.setStyle(t),this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,this}setRGB(t,e,i){return this.r=t,this.g=e,this.b=i,this}setHSL(t,e,i){if(t=(t%1+1)%1,e=gi(e,0,1),i=gi(i,0,1),0===e)this.r=this.g=this.b=i;else{const n=i<=.5?i*(1+e):i+e-i*e,s=2*i-n;this.r=es(s,n,t+1/3),this.g=es(s,n,t),this.b=es(s,n,t-1/3)}return this}setStyle(t){let e;if(e=/^((?:rgb|hsl)a?)\(([^\)]*)\)/.exec(t)){let t;const i=e[1],n=e[2];switch(i){case"rgb":case"rgba":if(t=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))return this.r=Math.min(255,parseInt(t[1],10))/255,this.g=Math.min(255,parseInt(t[2],10))/255,this.b=Math.min(255,parseInt(t[3],10))/255,t[4],this;if(t=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n))return this.r=Math.min(100,parseInt(t[1],10))/100,this.g=Math.min(100,parseInt(t[2],10))/100,this.b=Math.min(100,parseInt(t[3],10))/100,t[4],this;break;case"hsl":case"hsla":if(t=/^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(n)){const e=parseFloat(t[1])/360,i=parseInt(t[2],10)/100,n=parseInt(t[3],10)/100;return t[4],this.setHSL(e,i,n)}}}else if(e=/^\#([A-Fa-f\d]+)$/.exec(t)){const t=e[1],i=t.length;if(3===i)return this.r=parseInt(t.charAt(0)+t.charAt(0),16)/255,this.g=parseInt(t.charAt(1)+t.charAt(1),16)/255,this.b=parseInt(t.charAt(2)+t.charAt(2),16)/255,this;if(6===i)return this.r=parseInt(t.charAt(0)+t.charAt(1),16)/255,this.g=parseInt(t.charAt(2)+t.charAt(3),16)/255,this.b=parseInt(t.charAt(4)+t.charAt(5),16)/255,this}return t&&t.length>0?this.setColorName(t):this}setColorName(t){const e=Kn[t.toLowerCase()];return void 0!==e&&this.setHex(e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copyGammaToLinear(t,e=2){return this.r=Math.pow(t.r,e),this.g=Math.pow(t.g,e),this.b=Math.pow(t.b,e),this}copyLinearToGamma(t,e=2){const i=e>0?1/e:1;return this.r=Math.pow(t.r,i),this.g=Math.pow(t.g,i),this.b=Math.pow(t.b,i),this}convertGammaToLinear(t){return this.copyGammaToLinear(this,t),this}convertLinearToGamma(t){return this.copyLinearToGamma(this,t),this}copySRGBToLinear(t){return this.r=is(t.r),this.g=is(t.g),this.b=is(t.b),this}copyLinearToSRGB(t){return this.r=ns(t.r),this.g=ns(t.g),this.b=ns(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(){return 255*this.r<<16^255*this.g<<8^255*this.b<<0}getHexString(){return("000000"+this.getHex().toString(16)).slice(-6)}getHSL(t){const e=this.r,i=this.g,n=this.b,s=Math.max(e,i,n),r=Math.min(e,i,n);let a,o;const l=(r+s)/2;if(r===s)a=0,o=0;else{const t=s-r;switch(o=l<=.5?t/(s+r):t/(2-s-r),s){case e:a=(i-n)/t+(i<n?6:0);break;case i:a=(n-e)/t+2;break;case n:a=(e-i)/t+4}a/=6}return t.h=a,t.s=o,t.l=l,t}getStyle(){return"rgb("+(255*this.r|0)+","+(255*this.g|0)+","+(255*this.b|0)+")"}offsetHSL(t,e,i){return this.getHSL(Qn),Qn.h+=t,Qn.s+=e,Qn.l+=i,this.setHSL(Qn.h,Qn.s,Qn.l),this}add(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this}addColors(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this}addScalar(t){return this.r+=t,this.g+=t,this.b+=t,this}sub(t){return this.r=Math.max(0,this.r-t.r),this.g=Math.max(0,this.g-t.g),this.b=Math.max(0,this.b-t.b),this}multiply(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this}multiplyScalar(t){return this.r*=t,this.g*=t,this.b*=t,this}lerp(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this}lerpColors(t,e,i){return this.r=t.r+(e.r-t.r)*i,this.g=t.g+(e.g-t.g)*i,this.b=t.b+(e.b-t.b)*i,this}lerpHSL(t,e){this.getHSL(Qn),t.getHSL(ts);const i=yi(Qn.h,ts.h,e),n=yi(Qn.s,ts.s,e),s=yi(Qn.l,ts.l,e);return this.setHSL(i,n,s),this}equals(t){return t.r===this.r&&t.g===this.g&&t.b===this.b}fromArray(t,e=0){return this.r=t[e],this.g=t[e+1],this.b=t[e+2],this}toArray(t=[],e=0){return t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t}fromBufferAttribute(t,e){return this.r=t.getX(e),this.g=t.getY(e),this.b=t.getZ(e),!0===t.normalized&&(this.r/=255,this.g/=255,this.b/=255),this}toJSON(){return this.getHex()}};ss.NAMES=Kn,ss.prototype.isColor=!0,ss.prototype.r=1,ss.prototype.g=1,ss.prototype.b=1;class rs extends $n{constructor(t){super(),this.type="MeshBasicMaterial",this.color=new ss(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=ct,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this}}rs.prototype.isMeshBasicMaterial=!0;const as=new Di,os=new bi;class ls{constructor(t,e,i){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=!0===i,this.usage=hi,this.updateRange={offset:0,count:-1},this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this}copyAt(t,e,i){t*=this.itemSize,i*=e.itemSize;for(let n=0,s=this.itemSize;n<s;n++)this.array[t+n]=e.array[i+n];return this}copyArray(t){return this.array.set(t),this}copyColorsArray(t){const e=this.array;let i=0;for(let n=0,s=t.length;n<s;n++){let s=t[n];void 0===s&&(s=new ss),e[i++]=s.r,e[i++]=s.g,e[i++]=s.b}return this}copyVector2sArray(t){const e=this.array;let i=0;for(let n=0,s=t.length;n<s;n++){let s=t[n];void 0===s&&(s=new bi),e[i++]=s.x,e[i++]=s.y}return this}copyVector3sArray(t){const e=this.array;let i=0;for(let n=0,s=t.length;n<s;n++){let s=t[n];void 0===s&&(s=new Di),e[i++]=s.x,e[i++]=s.y,e[i++]=s.z}return this}copyVector4sArray(t){const e=this.array;let i=0;for(let n=0,s=t.length;n<s;n++){let s=t[n];void 0===s&&(s=new Ni),e[i++]=s.x,e[i++]=s.y,e[i++]=s.z,e[i++]=s.w}return this}applyMatrix3(t){if(2===this.itemSize)for(let e=0,i=this.count;e<i;e++)os.fromBufferAttribute(this,e),os.applyMatrix3(t),this.setXY(e,os.x,os.y);else if(3===this.itemSize)for(let e=0,i=this.count;e<i;e++)as.fromBufferAttribute(this,e),as.applyMatrix3(t),this.setXYZ(e,as.x,as.y,as.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)as.x=this.getX(e),as.y=this.getY(e),as.z=this.getZ(e),as.applyMatrix4(t),this.setXYZ(e,as.x,as.y,as.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)as.x=this.getX(e),as.y=this.getY(e),as.z=this.getZ(e),as.applyNormalMatrix(t),this.setXYZ(e,as.x,as.y,as.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)as.x=this.getX(e),as.y=this.getY(e),as.z=this.getZ(e),as.transformDirection(t),this.setXYZ(e,as.x,as.y,as.z);return this}set(t,e=0){return this.array.set(t,e),this}getX(t){return this.array[t*this.itemSize]}setX(t,e){return this.array[t*this.itemSize]=e,this}getY(t){return this.array[t*this.itemSize+1]}setY(t,e){return this.array[t*this.itemSize+1]=e,this}getZ(t){return this.array[t*this.itemSize+2]}setZ(t,e){return this.array[t*this.itemSize+2]=e,this}getW(t){return this.array[t*this.itemSize+3]}setW(t,e){return this.array[t*this.itemSize+3]=e,this}setXY(t,e,i){return t*=this.itemSize,this.array[t+0]=e,this.array[t+1]=i,this}setXYZ(t,e,i,n){return t*=this.itemSize,this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t*=this.itemSize,this.array[t+0]=e,this.array[t+1]=i,this.array[t+2]=n,this.array[t+3]=s,this}onUpload(t){return this.onUploadCallback=t,this}clone(){return new this.constructor(this.array,this.itemSize).copy(this)}toJSON(){const t={itemSize:this.itemSize,type:this.array.constructor.name,array:Array.prototype.slice.call(this.array),normalized:this.normalized};return""!==this.name&&(t.name=this.name),this.usage!==hi&&(t.usage=this.usage),0===this.updateRange.offset&&-1===this.updateRange.count||(t.updateRange=this.updateRange),t}}ls.prototype.isBufferAttribute=!0;class hs extends ls{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class cs extends ls{constructor(t,e,i){super(new Uint32Array(t),e,i)}}(class extends ls{constructor(t,e,i){super(new Uint16Array(t),e,i)}}).prototype.isFloat16BufferAttribute=!0;class us extends ls{constructor(t,e,i){super(new Float32Array(t),e,i)}}let ds=0;const ps=new pn,fs=new kn,ms=new Di,_s=new ki,gs=new ki,ys=new Di;class vs extends di{constructor(){super(),Object.defineProperty(this,"id",{value:ds++}),this.uuid=_i(),this.name="",this.type="BufferGeometry",this.index=null,this.attributes={},this.morphAttributes={},this.morphTargetsRelative=!1,this.groups=[],this.boundingBox=null,this.boundingSphere=null,this.drawRange={start:0,count:Infinity},this.userData={}}getIndex(){return this.index}setIndex(t){return Array.isArray(t)?this.index=new(Mi(t)>65535?cs:hs)(t,1):this.index=t,this}getAttribute(t){return this.attributes[t]}setAttribute(t,e){return this.attributes[t]=e,this}deleteAttribute(t){return delete this.attributes[t],this}hasAttribute(t){return void 0!==this.attributes[t]}addGroup(t,e,i=0){this.groups.push({start:t,count:e,materialIndex:i})}clearGroups(){this.groups=[]}setDrawRange(t,e){this.drawRange.start=t,this.drawRange.count=e}applyMatrix4(t){const e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);const i=this.attributes.normal;if(void 0!==i){const e=(new Si).getNormalMatrix(t);i.applyNormalMatrix(e),i.needsUpdate=!0}const n=this.attributes.tangent;return void 0!==n&&(n.transformDirection(t),n.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this}applyQuaternion(t){return ps.makeRotationFromQuaternion(t),this.applyMatrix4(ps),this}rotateX(t){return ps.makeRotationX(t),this.applyMatrix4(ps),this}rotateY(t){return ps.makeRotationY(t),this.applyMatrix4(ps),this}rotateZ(t){return ps.makeRotationZ(t),this.applyMatrix4(ps),this}translate(t,e,i){return ps.makeTranslation(t,e,i),this.applyMatrix4(ps),this}scale(t,e,i){return ps.makeScale(t,e,i),this.applyMatrix4(ps),this}lookAt(t){return fs.lookAt(t),fs.updateMatrix(),this.applyMatrix4(fs.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(ms).negate(),this.translate(ms.x,ms.y,ms.z),this}setFromPoints(t){const e=[];for(let i=0,n=t.length;i<n;i++){const n=t[i];e.push(n.x,n.y,n.z||0)}return this.setAttribute("position",new us(e,3)),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new ki);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)this.boundingBox.set(new Di(-Infinity,-Infinity,-Infinity),new Di(Infinity,Infinity,Infinity));else{if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,i=e.length;t<i;t++){const i=e[t];_s.setFromBufferAttribute(i),this.morphTargetsRelative?(ys.addVectors(this.boundingBox.min,_s.min),this.boundingBox.expandByPoint(ys),ys.addVectors(this.boundingBox.max,_s.max),this.boundingBox.expandByPoint(ys)):(this.boundingBox.expandByPoint(_s.min),this.boundingBox.expandByPoint(_s.max))}}else this.boundingBox.makeEmpty();isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z)}}computeBoundingSphere(){null===this.boundingSphere&&(this.boundingSphere=new sn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)this.boundingSphere.set(new Di,Infinity);else if(t){const i=this.boundingSphere.center;if(_s.setFromBufferAttribute(t),e)for(let t=0,i=e.length;t<i;t++){const i=e[t];gs.setFromBufferAttribute(i),this.morphTargetsRelative?(ys.addVectors(_s.min,gs.min),_s.expandByPoint(ys),ys.addVectors(_s.max,gs.max),_s.expandByPoint(ys)):(_s.expandByPoint(gs.min),_s.expandByPoint(gs.max))}_s.getCenter(i);let n=0;for(let e=0,s=t.count;e<s;e++)ys.fromBufferAttribute(t,e),n=Math.max(n,i.distanceToSquared(ys));if(e)for(let s=0,r=e.length;s<r;s++){const r=e[s],a=this.morphTargetsRelative;for(let e=0,s=r.count;e<s;e++)ys.fromBufferAttribute(r,e),a&&(ms.fromBufferAttribute(t,e),ys.add(ms)),n=Math.max(n,i.distanceToSquared(ys))}this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)}}computeTangents(){const t=this.index,e=this.attributes;if(null===t||void 0===e.position||void 0===e.normal||void 0===e.uv)return;const i=t.array,n=e.position.array,s=e.normal.array,r=e.uv.array,a=n.length/3;void 0===e.tangent&&this.setAttribute("tangent",new ls(new Float32Array(4*a),4));const o=e.tangent.array,l=[],h=[];for(let t=0;t<a;t++)l[t]=new Di,h[t]=new Di;const c=new Di,u=new Di,d=new Di,p=new bi,f=new bi,m=new bi,_=new Di,g=new Di;function y(t,e,i){c.fromArray(n,3*t),u.fromArray(n,3*e),d.fromArray(n,3*i),p.fromArray(r,2*t),f.fromArray(r,2*e),m.fromArray(r,2*i),u.sub(c),d.sub(c),f.sub(p),m.sub(p);const s=1/(f.x*m.y-m.x*f.y);isFinite(s)&&(_.copy(u).multiplyScalar(m.y).addScaledVector(d,-f.y).multiplyScalar(s),g.copy(d).multiplyScalar(f.x).addScaledVector(u,-m.x).multiplyScalar(s),l[t].add(_),l[e].add(_),l[i].add(_),h[t].add(g),h[e].add(g),h[i].add(g))}let v=this.groups;0===v.length&&(v=[{start:0,count:i.length}]);for(let t=0,e=v.length;t<e;++t){const e=v[t],n=e.start;for(let t=n,s=n+e.count;t<s;t+=3)y(i[t+0],i[t+1],i[t+2])}const x=new Di,w=new Di,b=new Di,S=new Di;function M(t){b.fromArray(s,3*t),S.copy(b);const e=l[t];x.copy(e),x.sub(b.multiplyScalar(b.dot(e))).normalize(),w.crossVectors(S,e);const i=w.dot(h[t])<0?-1:1;o[4*t]=x.x,o[4*t+1]=x.y,o[4*t+2]=x.z,o[4*t+3]=i}for(let t=0,e=v.length;t<e;++t){const e=v[t],n=e.start;for(let t=n,s=n+e.count;t<s;t+=3)M(i[t+0]),M(i[t+1]),M(i[t+2])}}computeVertexNormals(){const t=this.index,e=this.getAttribute("position");if(void 0!==e){let i=this.getAttribute("normal");if(void 0===i)i=new ls(new Float32Array(3*e.count),3),this.setAttribute("normal",i);else for(let t=0,e=i.count;t<e;t++)i.setXYZ(t,0,0,0);const n=new Di,s=new Di,r=new Di,a=new Di,o=new Di,l=new Di,h=new Di,c=new Di;if(t)for(let u=0,d=t.count;u<d;u+=3){const d=t.getX(u+0),p=t.getX(u+1),f=t.getX(u+2);n.fromBufferAttribute(e,d),s.fromBufferAttribute(e,p),r.fromBufferAttribute(e,f),h.subVectors(r,s),c.subVectors(n,s),h.cross(c),a.fromBufferAttribute(i,d),o.fromBufferAttribute(i,p),l.fromBufferAttribute(i,f),a.add(h),o.add(h),l.add(h),i.setXYZ(d,a.x,a.y,a.z),i.setXYZ(p,o.x,o.y,o.z),i.setXYZ(f,l.x,l.y,l.z)}else for(let t=0,a=e.count;t<a;t+=3)n.fromBufferAttribute(e,t+0),s.fromBufferAttribute(e,t+1),r.fromBufferAttribute(e,t+2),h.subVectors(r,s),c.subVectors(n,s),h.cross(c),i.setXYZ(t+0,h.x,h.y,h.z),i.setXYZ(t+1,h.x,h.y,h.z),i.setXYZ(t+2,h.x,h.y,h.z);this.normalizeNormals(),i.needsUpdate=!0}}merge(t,e){if(!t||!t.isBufferGeometry)return;void 0===e&&(e=0);const i=this.attributes;for(const n in i){if(void 0===t.attributes[n])continue;const s=i[n].array,r=t.attributes[n],a=r.array,o=r.itemSize*e,l=Math.min(a.length,s.length-o);for(let t=0,e=o;t<l;t++,e++)s[e]=a[t]}return this}normalizeNormals(){const t=this.attributes.normal;for(let e=0,i=t.count;e<i;e++)ys.fromBufferAttribute(t,e),ys.normalize(),t.setXYZ(e,ys.x,ys.y,ys.z)}toNonIndexed(){function t(t,e){const i=t.array,n=t.itemSize,s=t.normalized,r=new i.constructor(e.length*n);let a=0,o=0;for(let s=0,l=e.length;s<l;s++){a=t.isInterleavedBufferAttribute?e[s]*t.data.stride+t.offset:e[s]*n;for(let t=0;t<n;t++)r[o++]=i[a++]}return new ls(r,n,s)}if(null===this.index)return this;const e=new vs,i=this.index.array,n=this.attributes;for(const s in n){const r=t(n[s],i);e.setAttribute(s,r)}const s=this.morphAttributes;for(const n in s){const r=[],a=s[n];for(let e=0,n=a.length;e<n;e++){const n=t(a[e],i);r.push(n)}e.morphAttributes[n]=r}e.morphTargetsRelative=this.morphTargetsRelative;const r=this.groups;for(let t=0,i=r.length;t<i;t++){const i=r[t];e.addGroup(i.start,i.count,i.materialIndex)}return e}toJSON(){const t={metadata:{version:4.5,type:"BufferGeometry",generator:"BufferGeometry.toJSON"}};if(t.uuid=this.uuid,t.type=this.type,""!==this.name&&(t.name=this.name),Object.keys(this.userData).length>0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const i in e)void 0!==e[i]&&(t[i]=e[i]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const i=this.attributes;for(const e in i){const n=i[e];t.data.attributes[e]=n.toJSON(t.data)}const n={};let s=!1;for(const e in this.morphAttributes){const i=this.morphAttributes[e],r=[];for(let e=0,n=i.length;e<n;e++){const n=i[e];r.push(n.toJSON(t.data))}r.length>0&&(n[e]=r,s=!0)}s&&(t.data.morphAttributes=n,t.data.morphTargetsRelative=this.morphTargetsRelative);const r=this.groups;r.length>0&&(t.data.groups=JSON.parse(JSON.stringify(r)));const a=this.boundingSphere;return null!==a&&(t.data.boundingSphere={center:a.center.toArray(),radius:a.radius}),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const i=t.index;null!==i&&this.setIndex(i.clone(e));const n=t.attributes;for(const t in n){const i=n[t];this.setAttribute(t,i.clone(e))}const s=t.morphAttributes;for(const t in s){const i=[],n=s[t];for(let t=0,s=n.length;t<s;t++)i.push(n[t].clone(e));this.morphAttributes[t]=i}this.morphTargetsRelative=t.morphTargetsRelative;const r=t.groups;for(let t=0,e=r.length;t<e;t++){const e=r[t];this.addGroup(e.start,e.count,e.materialIndex)}const a=t.boundingBox;null!==a&&(this.boundingBox=a.clone());const o=t.boundingSphere;return null!==o&&(this.boundingSphere=o.clone()),this.drawRange.start=t.drawRange.start,this.drawRange.count=t.drawRange.count,this.userData=t.userData,void 0!==t.parameters&&(this.parameters=Object.assign({},t.parameters)),this}dispose(){this.dispatchEvent({type:"dispose"})}}vs.prototype.isBufferGeometry=!0;const xs=new pn,ws=new dn,bs=new sn,Ss=new Di,Ms=new Di,Ts=new Di,Cs=new Di,As=new Di,Es=new Di,zs=new Di,Is=new Di,Ns=new Di,Ls=new bi,Ps=new bi,Fs=new bi,Ds=new Di,Os=new Di;class Rs extends kn{constructor(t=new vs,e=new rs){super(),this.type="Mesh",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t){return super.copy(t),void 0!==t.morphTargetInfluences&&(this.morphTargetInfluences=t.morphTargetInfluences.slice()),void 0!==t.morphTargetDictionary&&(this.morphTargetDictionary=Object.assign({},t.morphTargetDictionary)),this.material=t.material,this.geometry=t.geometry,this}updateMorphTargets(){const t=this.geometry;if(t.isBufferGeometry){const e=t.morphAttributes,i=Object.keys(e);if(i.length>0){const t=e[i[0]];if(void 0!==t){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,i=t.length;e<i;e++){const i=t[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[i]=e}}}}else{const e=t.morphTargets;void 0!==e&&e.length}}raycast(t,e){const i=this.geometry,n=this.material,s=this.matrixWorld;if(void 0===n)return;if(null===i.boundingSphere&&i.computeBoundingSphere(),bs.copy(i.boundingSphere),bs.applyMatrix4(s),!1===t.ray.intersectsSphere(bs))return;if(xs.copy(s).invert(),ws.copy(t.ray).applyMatrix4(xs),null!==i.boundingBox&&!1===ws.intersectsBox(i.boundingBox))return;let r;if(i.isBufferGeometry){const s=i.index,a=i.attributes.position,o=i.morphAttributes.position,l=i.morphTargetsRelative,h=i.attributes.uv,c=i.attributes.uv2,u=i.groups,d=i.drawRange;if(null!==s)if(Array.isArray(n))for(let i=0,p=u.length;i<p;i++){const p=u[i],f=n[p.materialIndex];for(let i=Math.max(p.start,d.start),n=Math.min(s.count,Math.min(p.start+p.count,d.start+d.count));i<n;i+=3){const n=s.getX(i),u=s.getX(i+1),d=s.getX(i+2);r=ks(this,f,t,ws,a,o,l,h,c,n,u,d),r&&(r.faceIndex=Math.floor(i/3),r.face.materialIndex=p.materialIndex,e.push(r))}}else for(let i=Math.max(0,d.start),u=Math.min(s.count,d.start+d.count);i<u;i+=3){const u=s.getX(i),d=s.getX(i+1),p=s.getX(i+2);r=ks(this,n,t,ws,a,o,l,h,c,u,d,p),r&&(r.faceIndex=Math.floor(i/3),e.push(r))}else if(void 0!==a)if(Array.isArray(n))for(let i=0,s=u.length;i<s;i++){const s=u[i],p=n[s.materialIndex];for(let i=Math.max(s.start,d.start),n=Math.min(a.count,Math.min(s.start+s.count,d.start+d.count));i<n;i+=3)r=ks(this,p,t,ws,a,o,l,h,c,i,i+1,i+2),r&&(r.faceIndex=Math.floor(i/3),r.face.materialIndex=s.materialIndex,e.push(r))}else for(let i=Math.max(0,d.start),s=Math.min(a.count,d.start+d.count);i<s;i+=3)r=ks(this,n,t,ws,a,o,l,h,c,i,i+1,i+2),r&&(r.faceIndex=Math.floor(i/3),e.push(r))}else i.isGeometry}}function ks(t,e,i,n,s,r,a,o,l,h,c,u){Ss.fromBufferAttribute(s,h),Ms.fromBufferAttribute(s,c),Ts.fromBufferAttribute(s,u);const d=t.morphTargetInfluences;if(r&&d){zs.set(0,0,0),Is.set(0,0,0),Ns.set(0,0,0);for(let t=0,e=r.length;t<e;t++){const e=d[t],i=r[t];0!==e&&(Cs.fromBufferAttribute(i,h),As.fromBufferAttribute(i,c),Es.fromBufferAttribute(i,u),a?(zs.addScaledVector(Cs,e),Is.addScaledVector(As,e),Ns.addScaledVector(Es,e)):(zs.addScaledVector(Cs.sub(Ss),e),Is.addScaledVector(As.sub(Ms),e),Ns.addScaledVector(Es.sub(Ts),e)))}Ss.add(zs),Ms.add(Is),Ts.add(Ns)}t.isSkinnedMesh&&(t.boneTransform(h,Ss),t.boneTransform(c,Ms),t.boneTransform(u,Ts));const p=function(t,e,i,n,s,r,a,o){let l;if(l=e.side===L?n.intersectTriangle(a,r,s,!0,o):n.intersectTriangle(s,r,a,e.side!==P,o),null===l)return null;Os.copy(o),Os.applyMatrix4(t.matrixWorld);const h=i.ray.origin.distanceTo(Os);return h<i.near||h>i.far?null:{distance:h,point:Os.clone(),object:t}}(t,e,i,n,Ss,Ms,Ts,Ds);if(p){o&&(Ls.fromBufferAttribute(o,h),Ps.fromBufferAttribute(o,c),Fs.fromBufferAttribute(o,u),p.uv=Xn.getUV(Ds,Ss,Ms,Ts,Ls,Ps,Fs,new bi)),l&&(Ls.fromBufferAttribute(l,h),Ps.fromBufferAttribute(l,c),Fs.fromBufferAttribute(l,u),p.uv2=Xn.getUV(Ds,Ss,Ms,Ts,Ls,Ps,Fs,new bi));const t={a:h,b:c,c:u,normal:new Di,materialIndex:0};Xn.getNormal(Ss,Ms,Ts,t.normal),p.face=t}return p}Rs.prototype.isMesh=!0;class Us extends vs{constructor(t=1,e=1,i=1,n=1,s=1,r=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:i,widthSegments:n,heightSegments:s,depthSegments:r};const a=this;n=Math.floor(n),s=Math.floor(s),r=Math.floor(r);const o=[],l=[],h=[],c=[];let u=0,d=0;function p(t,e,i,n,s,r,p,f,m,_,g){const y=r/m,v=p/_,x=r/2,w=p/2,b=f/2,S=m+1,M=_+1;let T=0,C=0;const A=new Di;for(let r=0;r<M;r++){const a=r*v-w;for(let o=0;o<S;o++){const u=o*y-x;A[t]=u*n,A[e]=a*s,A[i]=b,l.push(A.x,A.y,A.z),A[t]=0,A[e]=0,A[i]=f>0?1:-1,h.push(A.x,A.y,A.z),c.push(o/m),c.push(1-r/_),T+=1}}for(let t=0;t<_;t++)for(let e=0;e<m;e++){const i=u+e+S*t,n=u+e+S*(t+1),s=u+(e+1)+S*(t+1),r=u+(e+1)+S*t;o.push(i,n,r),o.push(n,s,r),C+=6}a.addGroup(d,C,g),d+=C,u+=T}p("z","y","x",-1,-1,i,e,t,r,s,0),p("z","y","x",1,-1,i,e,-t,r,s,1),p("x","z","y",1,1,t,i,e,n,r,2),p("x","z","y",1,-1,t,i,-e,n,r,3),p("x","y","z",1,-1,t,e,i,n,s,4),p("x","y","z",-1,-1,t,e,-i,n,s,5),this.setIndex(o),this.setAttribute("position",new us(l,3)),this.setAttribute("normal",new us(h,3)),this.setAttribute("uv",new us(c,2))}static fromJSON(t){return new Us(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function Bs(t){const e={};for(const i in t){e[i]={};for(const n in t[i]){const s=t[i][n];s&&(s.isColor||s.isMatrix3||s.isMatrix4||s.isVector2||s.isVector3||s.isVector4||s.isTexture||s.isQuaternion)?e[i][n]=s.clone():Array.isArray(s)?e[i][n]=s.slice():e[i][n]=s}}return e}function Vs(t){const e={};for(let i=0;i<t.length;i++){const n=Bs(t[i]);for(const t in n)e[t]=n[t]}return e}const Gs={clone:Bs,merge:Vs};class Ws extends $n{constructor(t){super(),this.type="ShaderMaterial",this.defines={},this.uniforms={},this.vertexShader="void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",this.fragmentShader="void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}",this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.clipping=!1,this.extensions={derivatives:!1,fragDepth:!1,drawBuffers:!1,shaderTextureLOD:!1},this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv2:[0,0]},this.index0AttributeName=void 0,this.uniformsNeedUpdate=!1,this.glslVersion=null,void 0!==t&&(t.attributes,this.setValues(t))}copy(t){return super.copy(t),this.fragmentShader=t.fragmentShader,this.vertexShader=t.vertexShader,this.uniforms=Bs(t.uniforms),this.defines=Object.assign({},t.defines),this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.lights=t.lights,this.clipping=t.clipping,this.extensions=Object.assign({},t.extensions),this.glslVersion=t.glslVersion,this}toJSON(t){const e=super.toJSON(t);e.glslVersion=this.glslVersion,e.uniforms={};for(const i in this.uniforms){const n=this.uniforms[i].value;n&&n.isTexture?e.uniforms[i]={type:"t",value:n.toJSON(t).uuid}:n&&n.isColor?e.uniforms[i]={type:"c",value:n.getHex()}:n&&n.isVector2?e.uniforms[i]={type:"v2",value:n.toArray()}:n&&n.isVector3?e.uniforms[i]={type:"v3",value:n.toArray()}:n&&n.isVector4?e.uniforms[i]={type:"v4",value:n.toArray()}:n&&n.isMatrix3?e.uniforms[i]={type:"m3",value:n.toArray()}:n&&n.isMatrix4?e.uniforms[i]={type:"m4",value:n.toArray()}:e.uniforms[i]={value:n}}Object.keys(this.defines).length>0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader;const i={};for(const t in this.extensions)!0===this.extensions[t]&&(i[t]=!0);return Object.keys(i).length>0&&(e.extensions=i),e}}Ws.prototype.isShaderMaterial=!0;let Hs=class extends kn{constructor(){super(),this.type="Camera",this.matrixWorldInverse=new pn,this.projectionMatrix=new pn,this.projectionMatrixInverse=new pn}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this}getWorldDirection(t){this.updateWorldMatrix(!0,!1);const e=this.matrixWorld.elements;return t.set(-e[8],-e[9],-e[10]).normalize()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return(new this.constructor).copy(this)}};Hs.prototype.isCamera=!0;class js extends Hs{constructor(t=50,e=1,i=.1,n=2e3){super(),this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=i,this.far=n,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=null===t.view?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=2*mi*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*fi*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*mi*Math.atan(Math.tan(.5*fi*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}setViewOffset(t,e,i,n,s,r){this.aspect=t/e,null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=i,this.view.offsetY=n,this.view.width=s,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*fi*this.fov)/this.zoom,i=2*e,n=this.aspect*i,s=-.5*n;const r=this.view;if(null!==this.view&&this.view.enabled){const t=r.fullWidth,a=r.fullHeight;s+=r.offsetX*n/t,e-=r.offsetY*i/a,n*=r.width/t,i*=r.height/a}const a=this.filmOffset;0!==a&&(s+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(s,s+n,e,e-i,t,this.far),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}js.prototype.isPerspectiveCamera=!0;const qs=90;class Js extends kn{constructor(t,e,i){if(super(),this.type="CubeCamera",!0!==i.isWebGLCubeRenderTarget)return;this.renderTarget=i;const n=new js(qs,1,t,e);n.layers=this.layers,n.up.set(0,-1,0),n.lookAt(new Di(1,0,0)),this.add(n);const s=new js(qs,1,t,e);s.layers=this.layers,s.up.set(0,-1,0),s.lookAt(new Di(-1,0,0)),this.add(s);const r=new js(qs,1,t,e);r.layers=this.layers,r.up.set(0,0,1),r.lookAt(new Di(0,1,0)),this.add(r);const a=new js(qs,1,t,e);a.layers=this.layers,a.up.set(0,0,-1),a.lookAt(new Di(0,-1,0)),this.add(a);const o=new js(qs,1,t,e);o.layers=this.layers,o.up.set(0,-1,0),o.lookAt(new Di(0,0,1)),this.add(o);const l=new js(qs,1,t,e);l.layers=this.layers,l.up.set(0,-1,0),l.lookAt(new Di(0,0,-1)),this.add(l)}update(t,e){null===this.parent&&this.updateMatrixWorld();const i=this.renderTarget,[n,s,r,a,o,l]=this.children,h=t.xr.enabled,c=t.getRenderTarget();t.xr.enabled=!1;const u=i.texture.generateMipmaps;i.texture.generateMipmaps=!1,t.setRenderTarget(i,0),t.render(e,n),t.setRenderTarget(i,1),t.render(e,s),t.setRenderTarget(i,2),t.render(e,r),t.setRenderTarget(i,3),t.render(e,a),t.setRenderTarget(i,4),t.render(e,o),i.texture.generateMipmaps=u,t.setRenderTarget(i,5),t.render(e,l),t.setRenderTarget(c),t.xr.enabled=h}}class Ys extends zi{constructor(t,e,i,n,s,r,a,o,l,h){super(t=void 0!==t?t:[],e=void 0!==e?e:vt,i,n,s,r,a,o,l,h),this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}Ys.prototype.isCubeTexture=!0;class Xs extends Li{constructor(t,e,i){Number.isInteger(e)&&(e=i),super(t,t,e),e=e||{},this.texture=new Ys(void 0,e.mapping,e.wrapS,e.wrapT,e.magFilter,e.minFilter,e.format,e.type,e.anisotropy,e.encoding),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=void 0!==e.generateMipmaps&&e.generateMipmaps,this.texture.minFilter=void 0!==e.minFilter?e.minFilter:Nt,this.texture._needsFlipEnvMap=!1}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.format=Yt,this.texture.encoding=e.encoding,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const i=new Us(5,5,5),n=new Ws({name:"CubemapFromEquirect",uniforms:Bs({tEquirect:{value:null}}),vertexShader:"\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include <begin_vertex>\n\t\t\t\t\t#include <project_vertex>\n\n\t\t\t\t}\n\t\t\t",fragmentShader:"\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include <common>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t",side:L,blending:F});n.uniforms.tEquirect.value=e;const s=new Rs(i,n),r=e.minFilter;return e.minFilter===Pt&&(e.minFilter=Nt),new Js(1,10,this).update(t,s),e.minFilter=r,s.geometry.dispose(),s.material.dispose(),this}clear(t,e,i,n){const s=t.getRenderTarget();for(let s=0;s<6;s++)t.setRenderTarget(this,s),t.clear(e,i,n);t.setRenderTarget(s)}}Xs.prototype.isWebGLCubeRenderTarget=!0;const Zs=new Di,$s=new Di,Ks=new Si;class Qs{constructor(t=new Di(1,0,0),e=0){this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,i,n){return this.normal.set(t,e,i),this.constant=n,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,i){const n=Zs.subVectors(i,e).cross($s.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(n,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(this.normal).multiplyScalar(-this.distanceToPoint(t)).add(t)}intersectLine(t,e){const i=t.delta(Zs),n=this.normal.dot(i);if(0===n)return 0===this.distanceToPoint(t.start)?e.copy(t.start):null;const s=-(t.start.dot(this.normal)+this.constant)/n;return s<0||s>1?null:e.copy(i).multiplyScalar(s).add(t.start)}intersectsLine(t){const e=this.distanceToPoint(t.start),i=this.distanceToPoint(t.end);return e<0&&i>0||i<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const i=e||Ks.getNormalMatrix(t),n=this.coplanarPoint(Zs).applyMatrix4(t),s=this.normal.applyMatrix3(i).normalize();return this.constant=-n.dot(s),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}Qs.prototype.isPlane=!0;const tr=new sn,er=new Di;class ir{constructor(t=new Qs,e=new Qs,i=new Qs,n=new Qs,s=new Qs,r=new Qs){this.planes=[t,e,i,n,s,r]}set(t,e,i,n,s,r){const a=this.planes;return a[0].copy(t),a[1].copy(e),a[2].copy(i),a[3].copy(n),a[4].copy(s),a[5].copy(r),this}copy(t){const e=this.planes;for(let i=0;i<6;i++)e[i].copy(t.planes[i]);return this}setFromProjectionMatrix(t){const e=this.planes,i=t.elements,n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],l=i[5],h=i[6],c=i[7],u=i[8],d=i[9],p=i[10],f=i[11],m=i[12],_=i[13],g=i[14],y=i[15];return e[0].setComponents(a-n,c-o,f-u,y-m).normalize(),e[1].setComponents(a+n,c+o,f+u,y+m).normalize(),e[2].setComponents(a+s,c+l,f+d,y+_).normalize(),e[3].setComponents(a-s,c-l,f-d,y-_).normalize(),e[4].setComponents(a-r,c-h,f-p,y-g).normalize(),e[5].setComponents(a+r,c+h,f+p,y+g).normalize(),this}intersectsObject(t){const e=t.geometry;return null===e.boundingSphere&&e.computeBoundingSphere(),tr.copy(e.boundingSphere).applyMatrix4(t.matrixWorld),this.intersectsSphere(tr)}intersectsSprite(t){return tr.center.set(0,0,0),tr.radius=.7071067811865476,tr.applyMatrix4(t.matrixWorld),this.intersectsSphere(tr)}intersectsSphere(t){const e=this.planes,i=t.center,n=-t.radius;for(let t=0;t<6;t++)if(e[t].distanceToPoint(i)<n)return!1;return!0}intersectsBox(t){const e=this.planes;for(let i=0;i<6;i++){const n=e[i];if(er.x=n.normal.x>0?t.max.x:t.min.x,er.y=n.normal.y>0?t.max.y:t.min.y,er.z=n.normal.z>0?t.max.z:t.min.z,n.distanceToPoint(er)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let i=0;i<6;i++)if(e[i].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}function nr(){let t=null,e=!1,i=null,n=null;function s(e,r){i(e,r),n=t.requestAnimationFrame(s)}return{start:function(){!0!==e&&null!==i&&(n=t.requestAnimationFrame(s),e=!0)},stop:function(){t.cancelAnimationFrame(n),e=!1},setAnimationLoop:function(t){i=t},setContext:function(e){t=e}}}function sr(t,e){const i=e.isWebGL2,n=new WeakMap;return{get:function(t){return t.isInterleavedBufferAttribute&&(t=t.data),n.get(t)},remove:function(e){e.isInterleavedBufferAttribute&&(e=e.data);const i=n.get(e);i&&(t.deleteBuffer(i.buffer),n.delete(e))},update:function(e,s){if(e.isGLBufferAttribute){const t=n.get(e);return void((!t||t.version<e.version)&&n.set(e,{buffer:e.buffer,type:e.type,bytesPerElement:e.elementSize,version:e.version}))}e.isInterleavedBufferAttribute&&(e=e.data);const r=n.get(e);void 0===r?n.set(e,function(e,n){const s=e.array,r=e.usage,a=t.createBuffer();t.bindBuffer(n,a),t.bufferData(n,s,r),e.onUploadCallback();let o=5126;return s instanceof Float32Array?o=5126:s instanceof Float64Array||(s instanceof Uint16Array?e.isFloat16BufferAttribute?i&&(o=5131):o=5123:s instanceof Int16Array?o=5122:s instanceof Uint32Array?o=5125:s instanceof Int32Array?o=5124:s instanceof Int8Array?o=5120:(s instanceof Uint8Array||s instanceof Uint8ClampedArray)&&(o=5121)),{buffer:a,type:o,bytesPerElement:s.BYTES_PER_ELEMENT,version:e.version}}(e,s)):r.version<e.version&&(function(e,n,s){const r=n.array,a=n.updateRange;t.bindBuffer(s,e),-1===a.count?t.bufferSubData(s,0,r):(i?t.bufferSubData(s,a.offset*r.BYTES_PER_ELEMENT,r,a.offset,a.count):t.bufferSubData(s,a.offset*r.BYTES_PER_ELEMENT,r.subarray(a.offset,a.offset+a.count)),a.count=-1)}(r.buffer,e,s),r.version=e.version)}}}class rr extends vs{constructor(t=1,e=1,i=1,n=1){super(),this.type="PlaneGeometry",this.parameters={width:t,height:e,widthSegments:i,heightSegments:n};const s=t/2,r=e/2,a=Math.floor(i),o=Math.floor(n),l=a+1,h=o+1,c=t/a,u=e/o,d=[],p=[],f=[],m=[];for(let t=0;t<h;t++){const e=t*u-r;for(let i=0;i<l;i++){const n=i*c-s;p.push(n,-e,0),f.push(0,0,1),m.push(i/a),m.push(1-t/o)}}for(let t=0;t<o;t++)for(let e=0;e<a;e++){const i=e+l*t,n=e+l*(t+1),s=e+1+l*(t+1),r=e+1+l*t;d.push(i,n,r),d.push(n,s,r)}this.setIndex(d),this.setAttribute("position",new us(p,3)),this.setAttribute("normal",new us(f,3)),this.setAttribute("uv",new us(m,2))}static fromJSON(t){return new rr(t.width,t.height,t.widthSegments,t.heightSegments)}}const ar={alphamap_fragment:"#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif",alphamap_pars_fragment:"#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",alphatest_fragment:"#ifdef USE_ALPHATEST\n\tif ( diffuseColor.a < alphaTest ) discard;\n#endif",alphatest_pars_fragment:"#ifdef USE_ALPHATEST\n\tuniform float alphaTest;\n#endif",aomap_fragment:"#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n\t#endif\n#endif",aomap_pars_fragment:"#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif",begin_vertex:"vec3 transformed = vec3( position );",beginnormal_vertex:"vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif",bsdfs:"vec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 f0, const in float f90, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, 1.0, dotVH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif",bumpmap_pars_fragment:"#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif",clipping_planes_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\n\t#endif\n#endif",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif",color_fragment:"#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#elif defined( USE_COLOR )\n\tdiffuseColor.rgb *= vColor;\n#endif",color_pars_fragment:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif",color_pars_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif",color_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif",common:"#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\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 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_maxMipLevel 8.0\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_maxTileSize 256.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\tfloat texelSize = 1.0 / ( 3.0 * cubeUV_maxTileSize );\n\t\tvec2 uv = getUV( direction, face ) * ( faceSize - 1.0 );\n\t\tvec2 f = fract( uv );\n\t\tuv += 0.5 - f;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tif ( mipInt < cubeUV_maxMipLevel ) {\n\t\t\tuv.y += 2.0 * cubeUV_maxTileSize;\n\t\t}\n\t\tuv.y += filterInt * 2.0 * cubeUV_minTileSize;\n\t\tuv.x += 3.0 * max( 0.0, cubeUV_maxTileSize - 2.0 * faceSize );\n\t\tuv *= texelSize;\n\t\tvec3 tl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x += texelSize;\n\t\tvec3 tr = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.y += texelSize;\n\t\tvec3 br = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tuv.x -= texelSize;\n\t\tvec3 bl = envMapTexelToLinear( texture2D( envMap, uv ) ).rgb;\n\t\tvec3 tm = mix( tl, tr, f.x );\n\t\tvec3 bm = mix( bl, br, f.x );\n\t\treturn mix( tm, bm, f.y );\n\t}\n\t#define r0 1.0\n\t#define v0 0.339\n\t#define m0 - 2.0\n\t#define r1 0.8\n\t#define v1 0.276\n\t#define m1 - 1.0\n\t#define r4 0.4\n\t#define v4 0.046\n\t#define m4 2.0\n\t#define r5 0.305\n\t#define v5 0.016\n\t#define m5 3.0\n\t#define r6 0.21\n\t#define v6 0.0038\n\t#define m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= r1 ) {\n\t\t\tmip = ( r0 - roughness ) * ( m1 - m0 ) / ( r0 - r1 ) + m0;\n\t\t} else if ( roughness >= r4 ) {\n\t\t\tmip = ( r1 - roughness ) * ( m4 - m1 ) / ( r1 - r4 ) + m1;\n\t\t} else if ( roughness >= r5 ) {\n\t\t\tmip = ( r4 - roughness ) * ( m5 - m4 ) / ( r4 - r5 ) + m4;\n\t\t} else if ( roughness >= r6 ) {\n\t\t\tmip = ( r5 - roughness ) * ( m6 - m5 ) / ( r5 - r6 ) + m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), m0, cubeUV_maxMipLevel );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif",defaultnormal_vertex:"vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif",encodings_fragment:"gl_FragColor = linearToOutputTexel( gl_FragColor );",encodings_pars_fragment:"\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn 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}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * value.a * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = clamp( floor( D ) / 255.0, 0.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}",envmap_fragment:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t\tenvColor = envMapTexelToLinear( envColor );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif",envmap_common_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif",envmap_physical_pars_fragment:"#if defined( USE_ENVMAP )\n\t#ifdef ENVMAP_MODE_REFRACTION\n\t\tuniform float refractionRatio;\n\t#endif\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#if defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec3 reflectVec;\n\t\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\t\treflectVec = reflect( - viewDir, normal );\n\t\t\t\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t\t#else\n\t\t\t\treflectVec = refract( - viewDir, normal, refractionRatio );\n\t\t\t#endif\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif",fog_vertex:"#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif",fog_fragment:"#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif",fog_pars_fragment:"#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif",gradientmap_pars_fragment:"#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn texture2D( gradientMap, coord ).rgb;\n\t#else\n\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t#endif\n}",lightmap_fragment:"#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel = texture2D( lightMap, vUv2 );\n\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tlightMapIrradiance *= PI;\n\t#endif\n\treflectedLight.indirectDiffuse += lightMapIrradiance;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif",lights_lambert_vertex:"vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointLightInfo( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotLightInfo( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalLightInfo( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry.normal );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif",lights_pars_begin:"uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\t#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\t\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\t\tif ( cutoffDistance > 0.0 ) {\n\t\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t\t}\n\t\treturn distanceFalloff;\n\t#else\n\t\tif ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\t\treturn pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t\t}\n\t\treturn 1.0;\n\t#endif\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif",lights_toon_fragment:"ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;",lights_toon_pars_fragment:"varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon\n#define Material_LightProbeLOD( material )\t(0)",lights_phong_fragment:"BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;",lights_phong_pars_fragment:"varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)",lights_physical_fragment:"PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\t#ifdef SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULARINTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vUv ).a;\n\t\t#endif\n\t\t#ifdef USE_SPECULARCOLORMAP\n\t\t\tspecularColorFactor *= specularColorMapTexelToLinear( texture2D( specularColorMap, vUv ) ).rgb;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( ior - 1.0 ) / ( ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEENCOLORMAP\n\t\tmaterial.sheenColor *= sheenColorMapTexelToLinear( texture2D( sheenColorMap, vUv ) ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\t#ifdef USE_SHEENROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vUv ).a;\n\t#endif\n#endif",lights_physical_pars_fragment:"struct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat roughness;\n\tvec3 specularColor;\n\tfloat specularF90;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n};\nvec3 clearcoatSpecular = vec3( 0.0 );\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\tvec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n\treturn fab;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\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\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\tvec3 FssEss = specularColor * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecular += ccIrradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.clearcoatNormal, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\treflectedLight.directSpecular += irradiance * BRDF_Sheen( directLight.direction, geometry.viewDir, geometry.normal, material.sheenColor, material.sheenRoughness );\n\t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularF90, material.roughness );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecular += clearcoatRadiance * EnvironmentBRDF( geometry.clearcoatNormal, geometry.viewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tcomputeMultiscattering( geometry.normal, geometry.viewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}",lights_fragment_begin:"\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef USE_CLEARCOAT\n\tgeometry.clearcoatNormal = clearcoatNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif",lights_fragment_maps:"#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometry.normal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getIBLRadiance( geometry.viewDir, geometry.normal, material.roughness );\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif",lights_fragment_end:"#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n#endif",logdepthbuf_fragment:"#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif",logdepthbuf_pars_fragment:"#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_pars_vertex:"#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif",map_fragment:"#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif",map_pars_fragment:"#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif",map_particle_fragment:"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif",map_particle_pars_fragment:"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tuniform mat3 uvTransform;\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",metalnessmap_fragment:"float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif",metalnessmap_pars_fragment:"#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\tif ( morphTargetInfluences[ i ] > 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1, 2 ) * morphTargetInfluences[ i ];\n\t\t}\n\t#else\n\t\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\t\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\t\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\t\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n\t#endif\n#endif",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t\tuniform sampler2DArray morphTargetsTexture;\n\t\tuniform vec2 morphTargetsTextureSize;\n\t\tvec3 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset, const in int stride ) {\n\t\t\tfloat texelIndex = float( vertexIndex * stride + offset );\n\t\t\tfloat y = floor( texelIndex / morphTargetsTextureSize.x );\n\t\t\tfloat x = texelIndex - y * morphTargetsTextureSize.x;\n\t\t\tvec3 morphUV = vec3( ( x + 0.5 ) / morphTargetsTextureSize.x, y / morphTargetsTextureSize.y, morphTargetIndex );\n\t\t\treturn texture( morphTargetsTexture, morphUV ).xyz;\n\t\t}\n\t#else\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\tuniform float morphTargetInfluences[ 8 ];\n\t\t#else\n\t\t\tuniform float morphTargetInfluences[ 4 ];\n\t\t#endif\n\t#endif\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\t#ifdef MORPHTARGETS_TEXTURE\n\t\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t\t#ifndef USE_MORPHNORMALS\n\t\t\t\tif ( morphTargetInfluences[ i ] > 0.0 ) transformed += getMorph( gl_VertexID, i, 0, 1 ) * morphTargetInfluences[ i ];\n\t\t\t#else\n\t\t\t\tif ( morphTargetInfluences[ i ] > 0.0 ) transformed += getMorph( gl_VertexID, i, 0, 2 ) * morphTargetInfluences[ i ];\n\t\t\t#endif\n\t\t}\n\t#else\n\t\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\t\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\t\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\t\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t\t#ifndef USE_MORPHNORMALS\n\t\t\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\t\t\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\t\t\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\t\t\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t\t#endif\n\t#endif\n#endif",normal_fragment_begin:"float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * faceDirection;\n\t\t\tbitangent = bitangent * faceDirection;\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;",normal_fragment_maps:"#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( - vViewPosition, normal, mapN, faceDirection );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif",normal_pars_fragment:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_pars_vertex:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_vertex:"#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif",normalmap_pars_fragment:"#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : faceDirection * inversesqrt( det );\n\t\treturn normalize( T * ( mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z );\n\t}\n#endif",clearcoat_normal_fragment_begin:"#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif",clearcoat_normal_fragment_maps:"#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN, faceDirection );\n\t#endif\n#endif",clearcoat_pars_fragment:"#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif",output_fragment:"#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= transmissionAlpha + 0.1;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );",packing:"vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}",premultiplied_alpha_fragment:"#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif",project_vertex:"vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;",dithering_fragment:"#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif",dithering_pars_fragment:"#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif",roughnessmap_fragment:"float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif",roughnessmap_pars_fragment:"#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif",shadowmap_pars_fragment:"#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif",shadowmap_pars_vertex:"#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif",shadowmap_vertex:"#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0\n\t\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\tvec4 shadowWorldPosition;\n\t#endif\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif",shadowmask_pars_fragment:"float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}",skinbase_vertex:"#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif",skinning_vertex:"#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif",skinnormal_vertex:"#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif",specularmap_fragment:"float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif",specularmap_pars_fragment:"#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif",tonemapping_fragment:"#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif",tonemapping_pars_fragment:"#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }",transmission_fragment:"#ifdef USE_TRANSMISSION\n\tfloat transmissionAlpha = 1.0;\n\tfloat transmissionFactor = transmission;\n\tfloat thicknessFactor = thickness;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\ttransmissionFactor *= texture2D( transmissionMap, vUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tthicknessFactor *= texture2D( thicknessMap, vUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmission = getIBLVolumeRefraction(\n\t\tn, v, roughnessFactor, material.diffuseColor, material.specularColor, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, ior, thicknessFactor,\n\t\tattenuationColor, attenuationDistance );\n\ttotalDiffuse = mix( totalDiffuse, transmission.rgb, transmissionFactor );\n\ttransmissionAlpha = mix( transmissionAlpha, transmission.a, transmissionFactor );\n#endif",transmission_pars_fragment:"#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tvec3 getVolumeTransmissionRay( vec3 n, vec3 v, float thickness, float ior, mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( float roughness, float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( vec2 fragCoord, float roughness, float ior ) {\n\t\tfloat framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\treturn texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n\t\t#else\n\t\t\treturn texture2D( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n\t\t#endif\n\t}\n\tvec3 applyVolumeAttenuation( vec3 radiance, float transmissionDistance, vec3 attenuationColor, float attenuationDistance ) {\n\t\tif ( attenuationDistance == 0.0 ) {\n\t\t\treturn radiance;\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance * radiance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( vec3 n, vec3 v, float roughness, vec3 diffuseColor, vec3 specularColor, float specularF90,\n\t\tvec3 position, mat4 modelMatrix, mat4 viewMatrix, mat4 projMatrix, float ior, float thickness,\n\t\tvec3 attenuationColor, float attenuationDistance ) {\n\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\trefractionCoords += 1.0;\n\t\trefractionCoords /= 2.0;\n\t\tvec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\tvec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );\n\t}\n#endif",uv_pars_fragment:"#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif",uv_pars_vertex:"#ifdef USE_UV\n\t#ifdef UVS_VERTEX_ONLY\n\t\tvec2 vUv;\n\t#else\n\t\tvarying vec2 vUv;\n\t#endif\n\tuniform mat3 uvTransform;\n#endif",uv_vertex:"#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif",uv2_pars_fragment:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif",uv2_pars_vertex:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n\tuniform mat3 uv2Transform;\n#endif",uv2_vertex:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif",worldpos_vertex:"#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION )\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif",background_vert:"varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}",background_frag:"uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}",cube_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}",cube_frag:"#include <envmap_common_pars_fragment>\nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include <envmap_fragment>\n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}",depth_vert:"#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}",depth_frag:"#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#endif\n}",distanceRGBA_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}",distanceRGBA_frag:"#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}",equirect_vert:"varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}",equirect_frag:"uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}",linedashed_vert:"uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}",linedashed_frag:"uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",meshbasic_vert:"#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinbase_vertex>\n\t\t#include <skinnormal_vertex>\n\t\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}",meshbasic_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_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 <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshlambert_vert:"#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshlambert_frag:"uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}",meshmatcap_frag:"#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshnormal_vert:"#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}",meshnormal_frag:"#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <normal_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshphong_frag:"#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshphysical_vert:"#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}",meshphysical_frag:"#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULARINTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n\t#ifdef USE_SPECULARCOLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEENCOLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEENROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\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 <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include <transmission_fragment>\n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;\n\t#endif\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <normal_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <normal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",meshtoon_frag:"#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <normal_pars_fragment>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}",points_vert:"uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}",points_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}",shadow_vert:"#include <common>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}",shadow_frag:"uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}",sprite_vert:"uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}",sprite_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <output_fragment>\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}"},or={common:{diffuse:{value:new ss(16777215)},opacity:{value:1},map:{value:null},uvTransform:{value:new Si},uv2Transform:{value:new Si},alphaMap:{value:null},alphaTest:{value:0}},specularmap:{specularMap:{value:null}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1}},emissivemap:{emissiveMap:{value:null}},bumpmap:{bumpMap:{value:null},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalScale:{value:new bi(1,1)}},displacementmap:{displacementMap:{value:null},displacementScale:{value:1},displacementBias:{value:0}},roughnessmap:{roughnessMap:{value:null}},metalnessmap:{metalnessMap:{value:null}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new ss(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotShadowMap:{value:[]},spotShadowMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new ss(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaTest:{value:0},uvTransform:{value:new Si}},sprite:{diffuse:{value:new ss(16777215)},opacity:{value:1},center:{value:new bi(.5,.5)},rotation:{value:0},map:{value:null},alphaMap:{value:null},alphaTest:{value:0},uvTransform:{value:new Si}}},lr={basic:{uniforms:Vs([or.common,or.specularmap,or.envmap,or.aomap,or.lightmap,or.fog]),vertexShader:ar.meshbasic_vert,fragmentShader:ar.meshbasic_frag},lambert:{uniforms:Vs([or.common,or.specularmap,or.envmap,or.aomap,or.lightmap,or.emissivemap,or.fog,or.lights,{emissive:{value:new ss(0)}}]),vertexShader:ar.meshlambert_vert,fragmentShader:ar.meshlambert_frag},phong:{uniforms:Vs([or.common,or.specularmap,or.envmap,or.aomap,or.lightmap,or.emissivemap,or.bumpmap,or.normalmap,or.displacementmap,or.fog,or.lights,{emissive:{value:new ss(0)},specular:{value:new ss(1118481)},shininess:{value:30}}]),vertexShader:ar.meshphong_vert,fragmentShader:ar.meshphong_frag},standard:{uniforms:Vs([or.common,or.envmap,or.aomap,or.lightmap,or.emissivemap,or.bumpmap,or.normalmap,or.displacementmap,or.roughnessmap,or.metalnessmap,or.fog,or.lights,{emissive:{value:new ss(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:ar.meshphysical_vert,fragmentShader:ar.meshphysical_frag},toon:{uniforms:Vs([or.common,or.aomap,or.lightmap,or.emissivemap,or.bumpmap,or.normalmap,or.displacementmap,or.gradientmap,or.fog,or.lights,{emissive:{value:new ss(0)}}]),vertexShader:ar.meshtoon_vert,fragmentShader:ar.meshtoon_frag},matcap:{uniforms:Vs([or.common,or.bumpmap,or.normalmap,or.displacementmap,or.fog,{matcap:{value:null}}]),vertexShader:ar.meshmatcap_vert,fragmentShader:ar.meshmatcap_frag},points:{uniforms:Vs([or.points,or.fog]),vertexShader:ar.points_vert,fragmentShader:ar.points_frag},dashed:{uniforms:Vs([or.common,or.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:ar.linedashed_vert,fragmentShader:ar.linedashed_frag},depth:{uniforms:Vs([or.common,or.displacementmap]),vertexShader:ar.depth_vert,fragmentShader:ar.depth_frag},normal:{uniforms:Vs([or.common,or.bumpmap,or.normalmap,or.displacementmap,{opacity:{value:1}}]),vertexShader:ar.meshnormal_vert,fragmentShader:ar.meshnormal_frag},sprite:{uniforms:Vs([or.sprite,or.fog]),vertexShader:ar.sprite_vert,fragmentShader:ar.sprite_frag},background:{uniforms:{uvTransform:{value:new Si},t2D:{value:null}},vertexShader:ar.background_vert,fragmentShader:ar.background_frag},cube:{uniforms:Vs([or.envmap,{opacity:{value:1}}]),vertexShader:ar.cube_vert,fragmentShader:ar.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:ar.equirect_vert,fragmentShader:ar.equirect_frag},distanceRGBA:{uniforms:Vs([or.common,or.displacementmap,{referencePosition:{value:new Di},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:ar.distanceRGBA_vert,fragmentShader:ar.distanceRGBA_frag},shadow:{uniforms:Vs([or.lights,or.fog,{color:{value:new ss(0)},opacity:{value:1}}]),vertexShader:ar.shadow_vert,fragmentShader:ar.shadow_frag}};function hr(t,e,i,n,s){const r=new ss(0);let a,o,l=0,h=null,c=0,u=null;function d(t,e){i.buffers.color.setClear(t.r,t.g,t.b,e,s)}return{getClearColor:function(){return r},setClearColor:function(t,e=1){r.set(t),l=e,d(r,l)},getClearAlpha:function(){return l},setClearAlpha:function(t){l=t,d(r,l)},render:function(i,s){let p=!1,f=!0===s.isScene?s.background:null;f&&f.isTexture&&(f=e.get(f));const m=t.xr,_=m.getSession&&m.getSession();_&&"additive"===_.environmentBlendMode&&(f=null),null===f?d(r,l):f&&f.isColor&&(d(f,1),p=!0),(t.autoClear||p)&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),f&&(f.isCubeTexture||f.mapping===St)?(void 0===o&&(o=new Rs(new Us(1,1,1),new Ws({name:"BackgroundCubeMaterial",uniforms:Bs(lr.cube.uniforms),vertexShader:lr.cube.vertexShader,fragmentShader:lr.cube.fragmentShader,side:L,depthTest:!1,depthWrite:!1,fog:!1})),o.geometry.deleteAttribute("normal"),o.geometry.deleteAttribute("uv"),o.onBeforeRender=function(t,e,i){this.matrixWorld.copyPosition(i.matrixWorld)},Object.defineProperty(o.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),n.update(o)),o.material.uniforms.envMap.value=f,o.material.uniforms.flipEnvMap.value=f.isCubeTexture&&!1===f.isRenderTargetTexture?-1:1,h===f&&c===f.version&&u===t.toneMapping||(o.material.needsUpdate=!0,h=f,c=f.version,u=t.toneMapping),i.unshift(o,o.geometry,o.material,0,0,null)):f&&f.isTexture&&(void 0===a&&(a=new Rs(new rr(2,2),new Ws({name:"BackgroundMaterial",uniforms:Bs(lr.background.uniforms),vertexShader:lr.background.vertexShader,fragmentShader:lr.background.fragmentShader,side:N,depthTest:!1,depthWrite:!1,fog:!1})),a.geometry.deleteAttribute("normal"),Object.defineProperty(a.material,"map",{get:function(){return this.uniforms.t2D.value}}),n.update(a)),a.material.uniforms.t2D.value=f,!0===f.matrixAutoUpdate&&f.updateMatrix(),a.material.uniforms.uvTransform.value.copy(f.matrix),h===f&&c===f.version&&u===t.toneMapping||(a.material.needsUpdate=!0,h=f,c=f.version,u=t.toneMapping),i.unshift(a,a.geometry,a.material,0,0,null))}}}function cr(t,e,i,n){const s=t.getParameter(34921),r=n.isWebGL2?null:e.get("OES_vertex_array_object"),a=n.isWebGL2||null!==r,o={},l=d(null);let h=l;function c(e){return n.isWebGL2?t.bindVertexArray(e):r.bindVertexArrayOES(e)}function u(e){return n.isWebGL2?t.deleteVertexArray(e):r.deleteVertexArrayOES(e)}function d(t){const e=[],i=[],n=[];for(let t=0;t<s;t++)e[t]=0,i[t]=0,n[t]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:e,enabledAttributes:i,attributeDivisors:n,object:t,attributes:{},index:null}}function p(){const t=h.newAttributes;for(let e=0,i=t.length;e<i;e++)t[e]=0}function f(t){m(t,0)}function m(i,s){const r=h.newAttributes,a=h.enabledAttributes,o=h.attributeDivisors;r[i]=1,0===a[i]&&(t.enableVertexAttribArray(i),a[i]=1),o[i]!==s&&((n.isWebGL2?t:e.get("ANGLE_instanced_arrays"))[n.isWebGL2?"vertexAttribDivisor":"vertexAttribDivisorANGLE"](i,s),o[i]=s)}function _(){const e=h.newAttributes,i=h.enabledAttributes;for(let n=0,s=i.length;n<s;n++)i[n]!==e[n]&&(t.disableVertexAttribArray(n),i[n]=0)}function g(e,i,s,r,a,o){!0!==n.isWebGL2||5124!==s&&5125!==s?t.vertexAttribPointer(e,i,s,r,a,o):t.vertexAttribIPointer(e,i,s,a,o)}function y(){v(),h!==l&&(h=l,c(h.object))}function v(){l.geometry=null,l.program=null,l.wireframe=!1}return{setup:function(s,l,u,y,v){let x=!1;if(a){const e=function(e,i,s){const a=!0===s.wireframe;let l=o[e.id];void 0===l&&(l={},o[e.id]=l);let h=l[i.id];void 0===h&&(h={},l[i.id]=h);let c=h[a];return void 0===c&&(c=d(n.isWebGL2?t.createVertexArray():r.createVertexArrayOES()),h[a]=c),c}(y,u,l);h!==e&&(h=e,c(h.object)),x=function(t,e){const i=h.attributes,n=t.attributes;let s=0;for(const t in n){const e=i[t],r=n[t];if(void 0===e)return!0;if(e.attribute!==r)return!0;if(e.data!==r.data)return!0;s++}return h.attributesNum!==s||h.index!==e}(y,v),x&&function(t,e){const i={},n=t.attributes;let s=0;for(const t in n){const e=n[t],r={};r.attribute=e,e.data&&(r.data=e.data),i[t]=r,s++}h.attributes=i,h.attributesNum=s,h.index=e}(y,v)}else{const t=!0===l.wireframe;h.geometry===y.id&&h.program===u.id&&h.wireframe===t||(h.geometry=y.id,h.program=u.id,h.wireframe=t,x=!0)}!0===s.isInstancedMesh&&(x=!0),null!==v&&i.update(v,34963),x&&(function(s,r,a,o){if(!1===n.isWebGL2&&(s.isInstancedMesh||o.isInstancedBufferGeometry)&&null===e.get("ANGLE_instanced_arrays"))return;p();const l=o.attributes,h=a.getAttributes(),c=r.defaultAttributeValues;for(const e in h){const n=h[e];if(n.location>=0){let r=l[e];if(void 0===r&&("instanceMatrix"===e&&s.instanceMatrix&&(r=s.instanceMatrix),"instanceColor"===e&&s.instanceColor&&(r=s.instanceColor)),void 0!==r){const e=r.normalized,a=r.itemSize,l=i.get(r);if(void 0===l)continue;const h=l.buffer,c=l.type,u=l.bytesPerElement;if(r.isInterleavedBufferAttribute){const i=r.data,l=i.stride,d=r.offset;if(i&&i.isInstancedInterleavedBuffer){for(let t=0;t<n.locationSize;t++)m(n.location+t,i.meshPerAttribute);!0!==s.isInstancedMesh&&void 0===o._maxInstanceCount&&(o._maxInstanceCount=i.meshPerAttribute*i.count)}else for(let t=0;t<n.locationSize;t++)f(n.location+t);t.bindBuffer(34962,h);for(let t=0;t<n.locationSize;t++)g(n.location+t,a/n.locationSize,c,e,l*u,(d+a/n.locationSize*t)*u)}else{if(r.isInstancedBufferAttribute){for(let t=0;t<n.locationSize;t++)m(n.location+t,r.meshPerAttribute);!0!==s.isInstancedMesh&&void 0===o._maxInstanceCount&&(o._maxInstanceCount=r.meshPerAttribute*r.count)}else for(let t=0;t<n.locationSize;t++)f(n.location+t);t.bindBuffer(34962,h);for(let t=0;t<n.locationSize;t++)g(n.location+t,a/n.locationSize,c,e,a*u,a/n.locationSize*t*u)}}else if(void 0!==c){const i=c[e];if(void 0!==i)switch(i.length){case 2:t.vertexAttrib2fv(n.location,i);break;case 3:t.vertexAttrib3fv(n.location,i);break;case 4:t.vertexAttrib4fv(n.location,i);break;default:t.vertexAttrib1fv(n.location,i)}}}}_()}(s,l,u,y),null!==v&&t.bindBuffer(34963,i.get(v).buffer))},reset:y,resetDefaultState:v,dispose:function(){y();for(const t in o){const e=o[t];for(const t in e){const i=e[t];for(const t in i)u(i[t].object),delete i[t];delete e[t]}delete o[t]}},releaseStatesOfGeometry:function(t){if(void 0===o[t.id])return;const e=o[t.id];for(const t in e){const i=e[t];for(const t in i)u(i[t].object),delete i[t];delete e[t]}delete o[t.id]},releaseStatesOfProgram:function(t){for(const e in o){const i=o[e];if(void 0===i[t.id])continue;const n=i[t.id];for(const t in n)u(n[t].object),delete n[t];delete i[t.id]}},initAttributes:p,enableAttribute:f,disableUnusedAttributes:_}}function ur(t,e,i,n){const s=n.isWebGL2;let r;this.setMode=function(t){r=t},this.render=function(e,n){t.drawArrays(r,e,n),i.update(n,r,1)},this.renderInstances=function(n,a,o){if(0===o)return;let l,h;if(s)l=t,h="drawArraysInstanced";else if(l=e.get("ANGLE_instanced_arrays"),h="drawArraysInstancedANGLE",null===l)return;l[h](r,n,a,o),i.update(a,r,o)}}function dr(t,e,i){let n;function s(e){if("highp"===e){if(t.getShaderPrecisionFormat(35633,36338).precision>0&&t.getShaderPrecisionFormat(35632,36338).precision>0)return"highp";e="mediump"}return"mediump"===e&&t.getShaderPrecisionFormat(35633,36337).precision>0&&t.getShaderPrecisionFormat(35632,36337).precision>0?"mediump":"lowp"}const r="undefined"!=typeof WebGL2RenderingContext&&t instanceof WebGL2RenderingContext||"undefined"!=typeof WebGL2ComputeRenderingContext&&t instanceof WebGL2ComputeRenderingContext;let a=void 0!==i.precision?i.precision:"highp";const o=s(a);o!==a&&(a=o);const l=r||e.has("WEBGL_draw_buffers"),h=!0===i.logarithmicDepthBuffer,c=t.getParameter(34930),u=t.getParameter(35660),d=t.getParameter(3379),p=t.getParameter(34076),f=t.getParameter(34921),m=t.getParameter(36347),_=t.getParameter(36348),g=t.getParameter(36349),y=u>0,v=r||e.has("OES_texture_float");return{isWebGL2:r,drawBuffers:l,getMaxAnisotropy:function(){if(void 0!==n)return n;if(!0===e.has("EXT_texture_filter_anisotropic")){const i=e.get("EXT_texture_filter_anisotropic");n=t.getParameter(i.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else n=0;return n},getMaxPrecision:s,precision:a,logarithmicDepthBuffer:h,maxTextures:c,maxVertexTextures:u,maxTextureSize:d,maxCubemapSize:p,maxAttributes:f,maxVertexUniforms:m,maxVaryings:_,maxFragmentUniforms:g,vertexTextures:y,floatFragmentTextures:v,floatVertexTextures:y&&v,maxSamples:r?t.getParameter(36183):0}}function pr(t){const e=this;let i=null,n=0,s=!1,r=!1;const a=new Qs,o=new Si,l={value:null,needsUpdate:!1};function h(){l.value!==i&&(l.value=i,l.needsUpdate=n>0),e.numPlanes=n,e.numIntersection=0}function c(t,i,n,s){const r=null!==t?t.length:0;let h=null;if(0!==r){if(h=l.value,!0!==s||null===h){const e=n+4*r,s=i.matrixWorldInverse;o.getNormalMatrix(s),(null===h||h.length<e)&&(h=new Float32Array(e));for(let e=0,i=n;e!==r;++e,i+=4)a.copy(t[e]).applyMatrix4(s,o),a.normal.toArray(h,i),h[i+3]=a.constant}l.value=h,l.needsUpdate=!0}return e.numPlanes=r,e.numIntersection=0,h}this.uniform=l,this.numPlanes=0,this.numIntersection=0,this.init=function(t,e,r){const a=0!==t.length||e||0!==n||s;return s=e,i=c(t,r,0),n=t.length,a},this.beginShadows=function(){r=!0,c(null)},this.endShadows=function(){r=!1,h()},this.setState=function(e,a,o){const u=e.clippingPlanes,d=e.clipIntersection,p=e.clipShadows,f=t.get(e);if(!s||null===u||0===u.length||r&&!p)r?c(null):h();else{const t=r?0:n,e=4*t;let s=f.clippingState||null;l.value=s,s=c(u,a,e,o);for(let t=0;t!==e;++t)s[t]=i[t];f.clippingState=s,this.numIntersection=d?this.numPlanes:0,this.numPlanes+=t}}}function fr(t){let e=new WeakMap;function i(t,e){return e===wt?t.mapping=vt:e===bt&&(t.mapping=xt),t}function n(t){const i=t.target;i.removeEventListener("dispose",n);const s=e.get(i);void 0!==s&&(e.delete(i),s.dispose())}return{get:function(s){if(s&&s.isTexture&&!1===s.isRenderTargetTexture){const r=s.mapping;if(r===wt||r===bt){if(e.has(s))return i(e.get(s).texture,s.mapping);{const r=s.image;if(r&&r.height>0){const a=t.getRenderTarget(),o=new Xs(r.height/2);return o.fromEquirectangularTexture(t,s),e.set(s,o),t.setRenderTarget(a),s.addEventListener("dispose",n),i(o.texture,s.mapping)}return null}}}return s},dispose:function(){e=new WeakMap}}}lr.physical={uniforms:Vs([lr.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatNormalScale:{value:new bi(1,1)},clearcoatNormalMap:{value:null},sheen:{value:0},sheenColor:{value:new ss(0)},sheenColorMap:{value:null},sheenRoughness:{value:0},sheenRoughnessMap:{value:null},transmission:{value:0},transmissionMap:{value:null},transmissionSamplerSize:{value:new bi},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},attenuationDistance:{value:0},attenuationColor:{value:new ss(0)},specularIntensity:{value:0},specularIntensityMap:{value:null},specularColor:{value:new ss(1,1,1)},specularColorMap:{value:null}}]),vertexShader:ar.meshphysical_vert,fragmentShader:ar.meshphysical_frag};class mr extends Hs{constructor(t=-1,e=1,i=1,n=-1,s=.1,r=2e3){super(),this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=i,this.bottom=n,this.near=s,this.far=r,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=null===t.view?null:Object.assign({},t.view),this}setViewOffset(t,e,i,n,s,r){null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=i,this.view.offsetY=n,this.view.width=s,this.view.height=r,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),i=(this.right+this.left)/2,n=(this.top+this.bottom)/2;let s=i-t,r=i+t,a=n+e,o=n-e;if(null!==this.view&&this.view.enabled){const t=(this.right-this.left)/this.view.fullWidth/this.zoom,e=(this.top-this.bottom)/this.view.fullHeight/this.zoom;s+=t*this.view.offsetX,r=s+t*this.view.width,a-=e*this.view.offsetY,o=a-e*this.view.height}this.projectionMatrix.makeOrthographic(s,r,a,o,this.near,this.far),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,null!==this.view&&(e.object.view=Object.assign({},this.view)),e}}mr.prototype.isOrthographicCamera=!0;class _r extends Ws{constructor(t){super(t),this.type="RawShaderMaterial"}}_r.prototype.isRawShaderMaterial=!0;const gr=4,yr=8,vr=Math.pow(2,yr),xr=[.125,.215,.35,.446,.526,.582],wr=yr-gr+1+xr.length,br={[Ke]:0,[Qe]:1,[ei]:2,[ii]:3,[ni]:4,[si]:5,[ti]:6},Sr=new mr,{_lodPlanes:Mr,_sizeLods:Tr,_sigmas:Cr}=Fr(),Ar=new ss;let Er=null;const zr=(1+Math.sqrt(5))/2,Ir=1/zr,Nr=[new Di(1,1,1),new Di(-1,1,1),new Di(1,1,-1),new Di(-1,1,-1),new Di(0,zr,Ir),new Di(0,zr,-Ir),new Di(Ir,0,zr),new Di(-Ir,0,zr),new Di(zr,Ir,0),new Di(-zr,Ir,0)];class Lr{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._blurMaterial=function(t){const e=new Float32Array(20),i=new Di(0,1,0);return new _r({name:"SphericalGaussianBlur",defines:{n:20},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:e},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:i},inputEncoding:{value:br[Ke]},outputEncoding:{value:br[Ke]}},vertexShader:"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t",fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform int samples;\n\t\t\tuniform float weights[ n ];\n\t\t\tuniform bool latitudinal;\n\t\t\tuniform float dTheta;\n\t\t\tuniform float mipInt;\n\t\t\tuniform vec3 poleAxis;\n\n\t\t\t\n\n\t\tuniform int inputEncoding;\n\t\tuniform int outputEncoding;\n\n\t\t#include <encodings_pars_fragment>\n\n\t\tvec4 inputTexelToLinear( vec4 value ) {\n\n\t\t\tif ( inputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( inputEncoding == 1 ) {\n\n\t\t\t\treturn sRGBToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 2 ) {\n\n\t\t\t\treturn RGBEToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 3 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 7.0 );\n\n\t\t\t} else if ( inputEncoding == 4 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 16.0 );\n\n\t\t\t} else if ( inputEncoding == 5 ) {\n\n\t\t\t\treturn RGBDToLinear( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn GammaToLinear( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 linearToOutputTexel( vec4 value ) {\n\n\t\t\tif ( outputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( outputEncoding == 1 ) {\n\n\t\t\t\treturn LinearTosRGB( value );\n\n\t\t\t} else if ( outputEncoding == 2 ) {\n\n\t\t\t\treturn LinearToRGBE( value );\n\n\t\t\t} else if ( outputEncoding == 3 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 7.0 );\n\n\t\t\t} else if ( outputEncoding == 4 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 16.0 );\n\n\t\t\t} else if ( outputEncoding == 5 ) {\n\n\t\t\t\treturn LinearToRGBD( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn LinearToGamma( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 envMapTexelToLinear( vec4 color ) {\n\n\t\t\treturn inputTexelToLinear( color );\n\n\t\t}\n\t\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include <cube_uv_reflection_fragment>\n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t",blending:F,depthTest:!1,depthWrite:!1})}(),this._equirectShader=null,this._cubemapShader=null,this._compileMaterial(this._blurMaterial)}fromScene(t,e=0,i=.1,n=100){Er=this._renderer.getRenderTarget();const s=this._allocateTargets();return this._sceneToCubeUV(t,i,n,s),e>0&&this._blur(s,0,0,e),this._applyPMREM(s),this._cleanup(s),s}fromEquirectangular(t){return this._fromTexture(t)}fromCubemap(t){return this._fromTexture(t)}compileCubemapShader(){null===this._cubemapShader&&(this._cubemapShader=kr(),this._compileMaterial(this._cubemapShader))}compileEquirectangularShader(){null===this._equirectShader&&(this._equirectShader=Rr(),this._compileMaterial(this._equirectShader))}dispose(){this._blurMaterial.dispose(),null!==this._cubemapShader&&this._cubemapShader.dispose(),null!==this._equirectShader&&this._equirectShader.dispose();for(let t=0;t<Mr.length;t++)Mr[t].dispose()}_cleanup(t){this._pingPongRenderTarget.dispose(),this._renderer.setRenderTarget(Er),t.scissorTest=!1,Or(t,0,0,t.width,t.height)}_fromTexture(t){Er=this._renderer.getRenderTarget();const e=this._allocateTargets(t);return this._textureToCubeUV(t,e),this._applyPMREM(e),this._cleanup(e),e}_allocateTargets(t){const e={magFilter:Et,minFilter:Et,generateMipmaps:!1,type:Ft,format:$t,encoding:Pr(t)?t.encoding:ei,depthBuffer:!1},i=Dr(e);return i.depthBuffer=!t,this._pingPongRenderTarget=Dr(e),i}_compileMaterial(t){const e=new Rs(Mr[0],t);this._renderer.compile(e,Sr)}_sceneToCubeUV(t,e,i,n){const s=new js(90,1,e,i),r=[1,-1,1,1,1,1],a=[1,1,1,-1,-1,-1],o=this._renderer,l=o.autoClear,h=o.outputEncoding,c=o.toneMapping;o.getClearColor(Ar),o.toneMapping=pt,o.outputEncoding=Ke,o.autoClear=!1;const u=new rs({name:"PMREM.Background",side:L,depthWrite:!1,depthTest:!1}),d=new Rs(new Us,u);let p=!1;const f=t.background;f?f.isColor&&(u.color.copy(f),t.background=null,p=!0):(u.color.copy(Ar),p=!0);for(let e=0;e<6;e++){const i=e%3;0==i?(s.up.set(0,r[e],0),s.lookAt(a[e],0,0)):1==i?(s.up.set(0,0,r[e]),s.lookAt(0,a[e],0)):(s.up.set(0,r[e],0),s.lookAt(0,0,a[e])),Or(n,i*vr,e>2?vr:0,vr,vr),o.setRenderTarget(n),p&&o.render(d,s),o.render(t,s)}d.geometry.dispose(),d.material.dispose(),o.toneMapping=c,o.outputEncoding=h,o.autoClear=l,t.background=f}_setEncoding(t,e){t.value=br[e.encoding]}_textureToCubeUV(t,e){const i=this._renderer,n=t.mapping===vt||t.mapping===xt;n?null==this._cubemapShader&&(this._cubemapShader=kr()):null==this._equirectShader&&(this._equirectShader=Rr());const s=n?this._cubemapShader:this._equirectShader,r=new Rs(Mr[0],s),a=s.uniforms;a.envMap.value=t,n||a.texelSize.value.set(1/t.image.width,1/t.image.height),this._setEncoding(a.inputEncoding,t),this._setEncoding(a.outputEncoding,e.texture),Or(e,0,0,3*vr,2*vr),i.setRenderTarget(e),i.render(r,Sr)}_applyPMREM(t){const e=this._renderer,i=e.autoClear;e.autoClear=!1;for(let e=1;e<wr;e++){const i=Math.sqrt(Cr[e]*Cr[e]-Cr[e-1]*Cr[e-1]),n=Nr[(e-1)%Nr.length];this._blur(t,e-1,e,i,n)}e.autoClear=i}_blur(t,e,i,n,s){const r=this._pingPongRenderTarget;this._halfBlur(t,r,e,i,n,"latitudinal",s),this._halfBlur(r,t,i,i,n,"longitudinal",s)}_halfBlur(t,e,i,n,s,r,a){const o=this._renderer,l=this._blurMaterial,h=new Rs(Mr[n],l),c=l.uniforms,u=Tr[i]-1,d=isFinite(s)?Math.PI/(2*u):2*Math.PI/39,p=s/d,f=isFinite(s)?1+Math.floor(3*p):20,m=[];let _=0;for(let t=0;t<20;++t){const e=t/p,i=Math.exp(-e*e/2);m.push(i),0==t?_+=i:t<f&&(_+=2*i)}for(let t=0;t<m.length;t++)m[t]=m[t]/_;c.envMap.value=t.texture,c.samples.value=f,c.weights.value=m,c.latitudinal.value="latitudinal"===r,a&&(c.poleAxis.value=a),c.dTheta.value=d,c.mipInt.value=yr-i,this._setEncoding(c.inputEncoding,t.texture),this._setEncoding(c.outputEncoding,t.texture);const g=Tr[n];Or(e,3*Math.max(0,vr-2*g),(0===n?0:2*vr)+2*g*(n>yr-gr?n-yr+gr:0),3*g,2*g),o.setRenderTarget(e),o.render(h,Sr)}}function Pr(t){return void 0!==t&&t.type===Ft&&(t.encoding===Ke||t.encoding===Qe||t.encoding===ti)}function Fr(){const t=[],e=[],i=[];let n=yr;for(let s=0;s<wr;s++){const r=Math.pow(2,n);e.push(r);let a=1/r;s>yr-gr?a=xr[s-yr+gr-1]:0==s&&(a=0),i.push(a);const o=1/(r-1),l=-o/2,h=1+o/2,c=[l,l,h,l,h,h,l,l,h,h,l,h],u=6,d=6,p=3,f=2,m=1,_=new Float32Array(p*d*u),g=new Float32Array(f*d*u),y=new Float32Array(m*d*u);for(let t=0;t<u;t++){const e=t%3*2/3-1,i=t>2?0:-1,n=[e,i,0,e+2/3,i,0,e+2/3,i+1,0,e,i,0,e+2/3,i+1,0,e,i+1,0];_.set(n,p*d*t),g.set(c,f*d*t);const s=[t,t,t,t,t,t];y.set(s,m*d*t)}const v=new vs;v.setAttribute("position",new ls(_,p)),v.setAttribute("uv",new ls(g,f)),v.setAttribute("faceIndex",new ls(y,m)),t.push(v),n>gr&&n--}return{_lodPlanes:t,_sizeLods:e,_sigmas:i}}function Dr(t){const e=new Li(3*vr,3*vr,t);return e.texture.mapping=St,e.texture.name="PMREM.cubeUv",e.scissorTest=!0,e}function Or(t,e,i,n,s){t.viewport.set(e,i,n,s),t.scissor.set(e,i,n,s)}function Rr(){const t=new bi(1,1);return new _r({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null},texelSize:{value:t},inputEncoding:{value:br[Ke]},outputEncoding:{value:br[Ke]}},vertexShader:"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t",fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform vec2 texelSize;\n\n\t\t\t\n\n\t\tuniform int inputEncoding;\n\t\tuniform int outputEncoding;\n\n\t\t#include <encodings_pars_fragment>\n\n\t\tvec4 inputTexelToLinear( vec4 value ) {\n\n\t\t\tif ( inputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( inputEncoding == 1 ) {\n\n\t\t\t\treturn sRGBToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 2 ) {\n\n\t\t\t\treturn RGBEToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 3 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 7.0 );\n\n\t\t\t} else if ( inputEncoding == 4 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 16.0 );\n\n\t\t\t} else if ( inputEncoding == 5 ) {\n\n\t\t\t\treturn RGBDToLinear( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn GammaToLinear( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 linearToOutputTexel( vec4 value ) {\n\n\t\t\tif ( outputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( outputEncoding == 1 ) {\n\n\t\t\t\treturn LinearTosRGB( value );\n\n\t\t\t} else if ( outputEncoding == 2 ) {\n\n\t\t\t\treturn LinearToRGBE( value );\n\n\t\t\t} else if ( outputEncoding == 3 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 7.0 );\n\n\t\t\t} else if ( outputEncoding == 4 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 16.0 );\n\n\t\t\t} else if ( outputEncoding == 5 ) {\n\n\t\t\t\treturn LinearToRGBD( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn LinearToGamma( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 envMapTexelToLinear( vec4 color ) {\n\n\t\t\treturn inputTexelToLinear( color );\n\n\t\t}\n\t\n\n\t\t\t#include <common>\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tvec2 f = fract( uv / texelSize - 0.5 );\n\t\t\t\tuv -= f * texelSize;\n\t\t\t\tvec3 tl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.x += texelSize.x;\n\t\t\t\tvec3 tr = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.y += texelSize.y;\n\t\t\t\tvec3 br = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\t\t\t\tuv.x -= texelSize.x;\n\t\t\t\tvec3 bl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;\n\n\t\t\t\tvec3 tm = mix( tl, tr, f.x );\n\t\t\t\tvec3 bm = mix( bl, br, f.x );\n\t\t\t\tgl_FragColor.rgb = mix( tm, bm, f.y );\n\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t",blending:F,depthTest:!1,depthWrite:!1})}function kr(){return new _r({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},inputEncoding:{value:br[Ke]},outputEncoding:{value:br[Ke]}},vertexShader:"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute vec3 position;\n\t\tattribute vec2 uv;\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t",fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\t\n\n\t\tuniform int inputEncoding;\n\t\tuniform int outputEncoding;\n\n\t\t#include <encodings_pars_fragment>\n\n\t\tvec4 inputTexelToLinear( vec4 value ) {\n\n\t\t\tif ( inputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( inputEncoding == 1 ) {\n\n\t\t\t\treturn sRGBToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 2 ) {\n\n\t\t\t\treturn RGBEToLinear( value );\n\n\t\t\t} else if ( inputEncoding == 3 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 7.0 );\n\n\t\t\t} else if ( inputEncoding == 4 ) {\n\n\t\t\t\treturn RGBMToLinear( value, 16.0 );\n\n\t\t\t} else if ( inputEncoding == 5 ) {\n\n\t\t\t\treturn RGBDToLinear( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn GammaToLinear( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 linearToOutputTexel( vec4 value ) {\n\n\t\t\tif ( outputEncoding == 0 ) {\n\n\t\t\t\treturn value;\n\n\t\t\t} else if ( outputEncoding == 1 ) {\n\n\t\t\t\treturn LinearTosRGB( value );\n\n\t\t\t} else if ( outputEncoding == 2 ) {\n\n\t\t\t\treturn LinearToRGBE( value );\n\n\t\t\t} else if ( outputEncoding == 3 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 7.0 );\n\n\t\t\t} else if ( outputEncoding == 4 ) {\n\n\t\t\t\treturn LinearToRGBM( value, 16.0 );\n\n\t\t\t} else if ( outputEncoding == 5 ) {\n\n\t\t\t\treturn LinearToRGBD( value, 256.0 );\n\n\t\t\t} else {\n\n\t\t\t\treturn LinearToGamma( value, 2.2 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tvec4 envMapTexelToLinear( vec4 color ) {\n\n\t\t\treturn inputTexelToLinear( color );\n\n\t\t}\n\t\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) ).rgb;\n\t\t\t\tgl_FragColor = linearToOutputTexel( gl_FragColor );\n\n\t\t\t}\n\t\t",blending:F,depthTest:!1,depthWrite:!1})}function Ur(t){let e=new WeakMap,i=null;function n(t){const i=t.target;i.removeEventListener("dispose",n);const s=e.get(i);void 0!==s&&(e.delete(i),s.dispose())}return{get:function(s){if(s&&s.isTexture&&!1===s.isRenderTargetTexture){const r=s.mapping,a=r===wt||r===bt,o=r===vt||r===xt;if(a||o){if(e.has(s))return e.get(s).texture;{const r=s.image;if(a&&r&&r.height>0||o&&r&&function(t){let e=0;for(let i=0;i<6;i++)void 0!==t[i]&&e++;return 6===e}(r)){const r=t.getRenderTarget();null===i&&(i=new Lr(t));const o=a?i.fromEquirectangular(s):i.fromCubemap(s);return e.set(s,o),t.setRenderTarget(r),s.addEventListener("dispose",n),o.texture}return null}}}return s},dispose:function(){e=new WeakMap,null!==i&&(i.dispose(),i=null)}}}function Br(t){const e={};function i(i){if(void 0!==e[i])return e[i];let n;switch(i){case"WEBGL_depth_texture":n=t.getExtension("WEBGL_depth_texture")||t.getExtension("MOZ_WEBGL_depth_texture")||t.getExtension("WEBKIT_WEBGL_depth_texture");break;case"EXT_texture_filter_anisotropic":n=t.getExtension("EXT_texture_filter_anisotropic")||t.getExtension("MOZ_EXT_texture_filter_anisotropic")||t.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":n=t.getExtension("WEBGL_compressed_texture_s3tc")||t.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":n=t.getExtension("WEBGL_compressed_texture_pvrtc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;default:n=t.getExtension(i)}return e[i]=n,n}return{has:function(t){return null!==i(t)},init:function(t){t.isWebGL2?i("EXT_color_buffer_float"):(i("WEBGL_depth_texture"),i("OES_texture_float"),i("OES_texture_half_float"),i("OES_texture_half_float_linear"),i("OES_standard_derivatives"),i("OES_element_index_uint"),i("OES_vertex_array_object"),i("ANGLE_instanced_arrays")),i("OES_texture_float_linear"),i("EXT_color_buffer_half_float"),i("WEBGL_multisampled_render_to_texture")},get:function(t){return i(t)}}}function Vr(t,e,i,n){const s={},r=new WeakMap;function a(t){const o=t.target;null!==o.index&&e.remove(o.index);for(const t in o.attributes)e.remove(o.attributes[t]);o.removeEventListener("dispose",a),delete s[o.id];const l=r.get(o);l&&(e.remove(l),r.delete(o)),n.releaseStatesOfGeometry(o),!0===o.isInstancedBufferGeometry&&delete o._maxInstanceCount,i.memory.geometries--}function o(t){const i=[],n=t.index,s=t.attributes.position;let a=0;if(null!==n){const t=n.array;a=n.version;for(let e=0,n=t.length;e<n;e+=3){const n=t[e+0],s=t[e+1],r=t[e+2];i.push(n,s,s,r,r,n)}}else{const t=s.array;a=s.version;for(let e=0,n=t.length/3-1;e<n;e+=3){const t=e+0,n=e+1,s=e+2;i.push(t,n,n,s,s,t)}}const o=new(Mi(i)>65535?cs:hs)(i,1);o.version=a;const l=r.get(t);l&&e.remove(l),r.set(t,o)}return{get:function(t,e){return!0===s[e.id]||(e.addEventListener("dispose",a),s[e.id]=!0,i.memory.geometries++),e},update:function(t){const i=t.attributes;for(const t in i)e.update(i[t],34962);const n=t.morphAttributes;for(const t in n){const i=n[t];for(let t=0,n=i.length;t<n;t++)e.update(i[t],34962)}},getWireframeAttribute:function(t){const e=r.get(t);if(e){const i=t.index;null!==i&&e.version<i.version&&o(t)}else o(t);return r.get(t)}}}function Gr(t,e,i,n){const s=n.isWebGL2;let r,a,o;this.setMode=function(t){r=t},this.setIndex=function(t){a=t.type,o=t.bytesPerElement},this.render=function(e,n){t.drawElements(r,n,a,e*o),i.update(n,r,1)},this.renderInstances=function(n,l,h){if(0===h)return;let c,u;if(s)c=t,u="drawElementsInstanced";else if(c=e.get("ANGLE_instanced_arrays"),u="drawElementsInstancedANGLE",null===c)return;c[u](r,l,a,n*o,h),i.update(l,r,h)}}function Wr(t){const e={frame:0,calls:0,triangles:0,points:0,lines:0};return{memory:{geometries:0,textures:0},render:e,programs:null,autoReset:!0,reset:function(){e.frame++,e.calls=0,e.triangles=0,e.points=0,e.lines=0},update:function(t,i,n){switch(e.calls++,i){case 4:e.triangles+=n*(t/3);break;case 1:e.lines+=n*(t/2);break;case 3:e.lines+=n*(t-1);break;case 2:e.lines+=n*t;break;case 0:e.points+=n*t}}}}class Hr extends zi{constructor(t=null,e=1,i=1,n=1){super(null),this.image={data:t,width:e,height:i,depth:n},this.magFilter=Et,this.minFilter=Et,this.wrapR=Ct,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.needsUpdate=!0}}function jr(t,e){return t[0]-e[0]}function qr(t,e){return Math.abs(e[1])-Math.abs(t[1])}function Jr(t,e){let i=1;const n=e.isInterleavedBufferAttribute?e.data.array:e.array;n instanceof Int8Array?i=127:n instanceof Int16Array?i=32767:n instanceof Int32Array&&(i=2147483647),t.divideScalar(i)}function Yr(t,e,i){const n={},s=new Float32Array(8),r=new WeakMap,a=new Di,o=[];for(let t=0;t<8;t++)o[t]=[t,0];return{update:function(l,h,c,u){const d=l.morphTargetInfluences;if(!0===e.isWebGL2){const n=h.morphAttributes.position.length;let s=r.get(h);if(void 0===s||s.count!==n){void 0!==s&&s.texture.dispose();const t=void 0!==h.morphAttributes.normal,i=h.morphAttributes.position,o=h.morphAttributes.normal||[],l=!0===t?2:1;let c=h.attributes.position.count*l,u=1;c>e.maxTextureSize&&(u=Math.ceil(c/e.maxTextureSize),c=e.maxTextureSize);const d=new Float32Array(c*u*4*n),p=new Hr(d,c,u,n);p.format=Yt,p.type=Bt;const f=4*l;for(let e=0;e<n;e++){const n=i[e],s=o[e],r=c*u*4*e;for(let e=0;e<n.count;e++){a.fromBufferAttribute(n,e),!0===n.normalized&&Jr(a,n);const i=e*f;d[r+i+0]=a.x,d[r+i+1]=a.y,d[r+i+2]=a.z,d[r+i+3]=0,!0===t&&(a.fromBufferAttribute(s,e),!0===s.normalized&&Jr(a,s),d[r+i+4]=a.x,d[r+i+5]=a.y,d[r+i+6]=a.z,d[r+i+7]=0)}}s={count:n,texture:p,size:new bi(c,u)},r.set(h,s)}let o=0;for(let t=0;t<d.length;t++)o+=d[t];const l=h.morphTargetsRelative?1:1-o;u.getUniforms().setValue(t,"morphTargetBaseInfluence",l),u.getUniforms().setValue(t,"morphTargetInfluences",d),u.getUniforms().setValue(t,"morphTargetsTexture",s.texture,i),u.getUniforms().setValue(t,"morphTargetsTextureSize",s.size)}else{const e=void 0===d?0:d.length;let i=n[h.id];if(void 0===i||i.length!==e){i=[];for(let t=0;t<e;t++)i[t]=[t,0];n[h.id]=i}for(let t=0;t<e;t++){const e=i[t];e[0]=t,e[1]=d[t]}i.sort(qr);for(let t=0;t<8;t++)t<e&&i[t][1]?(o[t][0]=i[t][0],o[t][1]=i[t][1]):(o[t][0]=Number.MAX_SAFE_INTEGER,o[t][1]=0);o.sort(jr);const r=h.morphAttributes.position,a=h.morphAttributes.normal;let l=0;for(let t=0;t<8;t++){const e=o[t],i=e[0],n=e[1];i!==Number.MAX_SAFE_INTEGER&&n?(r&&h.getAttribute("morphTarget"+t)!==r[i]&&h.setAttribute("morphTarget"+t,r[i]),a&&h.getAttribute("morphNormal"+t)!==a[i]&&h.setAttribute("morphNormal"+t,a[i]),s[t]=n,l+=n):(r&&!0===h.hasAttribute("morphTarget"+t)&&h.deleteAttribute("morphTarget"+t),a&&!0===h.hasAttribute("morphNormal"+t)&&h.deleteAttribute("morphNormal"+t),s[t]=0)}const c=h.morphTargetsRelative?1:1-l;u.getUniforms().setValue(t,"morphTargetBaseInfluence",c),u.getUniforms().setValue(t,"morphTargetInfluences",s)}}}}function Xr(t,e,i,n){let s=new WeakMap;function r(t){const e=t.target;e.removeEventListener("dispose",r),i.remove(e.instanceMatrix),null!==e.instanceColor&&i.remove(e.instanceColor)}return{update:function(t){const a=n.render.frame,o=t.geometry,l=e.get(t,o);return s.get(l)!==a&&(e.update(l),s.set(l,a)),t.isInstancedMesh&&(!1===t.hasEventListener("dispose",r)&&t.addEventListener("dispose",r),i.update(t.instanceMatrix,34962),null!==t.instanceColor&&i.update(t.instanceColor,34962)),l},dispose:function(){s=new WeakMap}}}Hr.prototype.isDataTexture2DArray=!0;class Zr extends zi{constructor(t=null,e=1,i=1,n=1){super(null),this.image={data:t,width:e,height:i,depth:n},this.magFilter=Et,this.minFilter=Et,this.wrapR=Ct,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.needsUpdate=!0}}Zr.prototype.isDataTexture3D=!0;const $r=new zi,Kr=new Hr,Qr=new Zr,ta=new Ys,ea=[],ia=[],na=new Float32Array(16),sa=new Float32Array(9),ra=new Float32Array(4);function aa(t,e,i){const n=t[0];if(n<=0||n>0)return t;const s=e*i;let r=ea[s];if(void 0===r&&(r=new Float32Array(s),ea[s]=r),0!==e){n.toArray(r,0);for(let n=1,s=0;n!==e;++n)s+=i,t[n].toArray(r,s)}return r}function oa(t,e){if(t.length!==e.length)return!1;for(let i=0,n=t.length;i<n;i++)if(t[i]!==e[i])return!1;return!0}function la(t,e){for(let i=0,n=e.length;i<n;i++)t[i]=e[i]}function ha(t,e){let i=ia[e];void 0===i&&(i=new Int32Array(e),ia[e]=i);for(let n=0;n!==e;++n)i[n]=t.allocateTextureUnit();return i}function ca(t,e){const i=this.cache;i[0]!==e&&(t.uniform1f(this.addr,e),i[0]=e)}function ua(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y||(t.uniform2f(this.addr,e.x,e.y),i[0]=e.x,i[1]=e.y);else{if(oa(i,e))return;t.uniform2fv(this.addr,e),la(i,e)}}function da(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z||(t.uniform3f(this.addr,e.x,e.y,e.z),i[0]=e.x,i[1]=e.y,i[2]=e.z);else if(void 0!==e.r)i[0]===e.r&&i[1]===e.g&&i[2]===e.b||(t.uniform3f(this.addr,e.r,e.g,e.b),i[0]=e.r,i[1]=e.g,i[2]=e.b);else{if(oa(i,e))return;t.uniform3fv(this.addr,e),la(i,e)}}function pa(t,e){const i=this.cache;if(void 0!==e.x)i[0]===e.x&&i[1]===e.y&&i[2]===e.z&&i[3]===e.w||(t.uniform4f(this.addr,e.x,e.y,e.z,e.w),i[0]=e.x,i[1]=e.y,i[2]=e.z,i[3]=e.w);else{if(oa(i,e))return;t.uniform4fv(this.addr,e),la(i,e)}}function fa(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(oa(i,e))return;t.uniformMatrix2fv(this.addr,!1,e),la(i,e)}else{if(oa(i,n))return;ra.set(n),t.uniformMatrix2fv(this.addr,!1,ra),la(i,n)}}function ma(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(oa(i,e))return;t.uniformMatrix3fv(this.addr,!1,e),la(i,e)}else{if(oa(i,n))return;sa.set(n),t.uniformMatrix3fv(this.addr,!1,sa),la(i,n)}}function _a(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(oa(i,e))return;t.uniformMatrix4fv(this.addr,!1,e),la(i,e)}else{if(oa(i,n))return;na.set(n),t.uniformMatrix4fv(this.addr,!1,na),la(i,n)}}function ga(t,e){const i=this.cache;i[0]!==e&&(t.uniform1i(this.addr,e),i[0]=e)}function ya(t,e){const i=this.cache;oa(i,e)||(t.uniform2iv(this.addr,e),la(i,e))}function va(t,e){const i=this.cache;oa(i,e)||(t.uniform3iv(this.addr,e),la(i,e))}function xa(t,e){const i=this.cache;oa(i,e)||(t.uniform4iv(this.addr,e),la(i,e))}function wa(t,e){const i=this.cache;i[0]!==e&&(t.uniform1ui(this.addr,e),i[0]=e)}function ba(t,e){const i=this.cache;oa(i,e)||(t.uniform2uiv(this.addr,e),la(i,e))}function Sa(t,e){const i=this.cache;oa(i,e)||(t.uniform3uiv(this.addr,e),la(i,e))}function Ma(t,e){const i=this.cache;oa(i,e)||(t.uniform4uiv(this.addr,e),la(i,e))}function Ta(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.safeSetTexture2D(e||$r,s)}function Ca(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTexture3D(e||Qr,s)}function Aa(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.safeSetTextureCube(e||ta,s)}function Ea(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTexture2DArray(e||Kr,s)}function za(t,e){t.uniform1fv(this.addr,e)}function Ia(t,e){const i=aa(e,this.size,2);t.uniform2fv(this.addr,i)}function Na(t,e){const i=aa(e,this.size,3);t.uniform3fv(this.addr,i)}function La(t,e){const i=aa(e,this.size,4);t.uniform4fv(this.addr,i)}function Pa(t,e){const i=aa(e,this.size,4);t.uniformMatrix2fv(this.addr,!1,i)}function Fa(t,e){const i=aa(e,this.size,9);t.uniformMatrix3fv(this.addr,!1,i)}function Da(t,e){const i=aa(e,this.size,16);t.uniformMatrix4fv(this.addr,!1,i)}function Oa(t,e){t.uniform1iv(this.addr,e)}function Ra(t,e){t.uniform2iv(this.addr,e)}function ka(t,e){t.uniform3iv(this.addr,e)}function Ua(t,e){t.uniform4iv(this.addr,e)}function Ba(t,e){t.uniform1uiv(this.addr,e)}function Va(t,e){t.uniform2uiv(this.addr,e)}function Ga(t,e){t.uniform3uiv(this.addr,e)}function Wa(t,e){t.uniform4uiv(this.addr,e)}function Ha(t,e,i){const n=e.length,s=ha(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.safeSetTexture2D(e[t]||$r,s[t])}function ja(t,e,i){const n=e.length,s=ha(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.setTexture3D(e[t]||Qr,s[t])}function qa(t,e,i){const n=e.length,s=ha(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.safeSetTextureCube(e[t]||ta,s[t])}function Ja(t,e,i){const n=e.length,s=ha(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.setTexture2DArray(e[t]||Kr,s[t])}function Ya(t,e,i){this.id=t,this.addr=i,this.cache=[],this.setValue=function(t){switch(t){case 5126:return ca;case 35664:return ua;case 35665:return da;case 35666:return pa;case 35674:return fa;case 35675:return ma;case 35676:return _a;case 5124:case 35670:return ga;case 35667:case 35671:return ya;case 35668:case 35672:return va;case 35669:case 35673:return xa;case 5125:return wa;case 36294:return ba;case 36295:return Sa;case 36296:return Ma;case 35678:case 36198:case 36298:case 36306:case 35682:return Ta;case 35679:case 36299:case 36307:return Ca;case 35680:case 36300:case 36308:case 36293:return Aa;case 36289:case 36303:case 36311:case 36292:return Ea}}(e.type)}function Xa(t,e,i){this.id=t,this.addr=i,this.cache=[],this.size=e.size,this.setValue=function(t){switch(t){case 5126:return za;case 35664:return Ia;case 35665:return Na;case 35666:return La;case 35674:return Pa;case 35675:return Fa;case 35676:return Da;case 5124:case 35670:return Oa;case 35667:case 35671:return Ra;case 35668:case 35672:return ka;case 35669:case 35673:return Ua;case 5125:return Ba;case 36294:return Va;case 36295:return Ga;case 36296:return Wa;case 35678:case 36198:case 36298:case 36306:case 35682:return Ha;case 35679:case 36299:case 36307:return ja;case 35680:case 36300:case 36308:case 36293:return qa;case 36289:case 36303:case 36311:case 36292:return Ja}}(e.type)}function Za(t){this.id=t,this.seq=[],this.map={}}Xa.prototype.updateCache=function(t){const e=this.cache;t instanceof Float32Array&&e.length!==t.length&&(this.cache=new Float32Array(t.length)),la(e,t)},Za.prototype.setValue=function(t,e,i){const n=this.seq;for(let s=0,r=n.length;s!==r;++s){const r=n[s];r.setValue(t,e[r.id],i)}};const $a=/(\w+)(\])?(\[|\.)?/g;function Ka(t,e){t.seq.push(e),t.map[e.id]=e}function Qa(t,e,i){const n=t.name,s=n.length;for($a.lastIndex=0;;){const r=$a.exec(n),a=$a.lastIndex;let o=r[1];const l="]"===r[2],h=r[3];if(l&&(o|=0),void 0===h||"["===h&&a+2===s){Ka(i,void 0===h?new Ya(o,t,e):new Xa(o,t,e));break}{let t=i.map[o];void 0===t&&(t=new Za(o),Ka(i,t)),i=t}}}function to(t,e){this.seq=[],this.map={};const i=t.getProgramParameter(e,35718);for(let n=0;n<i;++n){const i=t.getActiveUniform(e,n);Qa(i,t.getUniformLocation(e,i.name),this)}}function eo(t,e,i){const n=t.createShader(e);return t.shaderSource(n,i),t.compileShader(n),n}to.prototype.setValue=function(t,e,i,n){const s=this.map[e];void 0!==s&&s.setValue(t,i,n)},to.prototype.setOptional=function(t,e,i){const n=e[i];void 0!==n&&this.setValue(t,i,n)},to.upload=function(t,e,i,n){for(let s=0,r=e.length;s!==r;++s){const r=e[s],a=i[r.id];!1!==a.needsUpdate&&r.setValue(t,a.value,n)}},to.seqWithValue=function(t,e){const i=[];for(let n=0,s=t.length;n!==s;++n){const s=t[n];s.id in e&&i.push(s)}return i};let io=0;function no(t){switch(t){case Ke:return["Linear","( value )"];case Qe:return["sRGB","( value )"];case ei:return["RGBE","( value )"];case ii:return["RGBM","( value, 7.0 )"];case ni:return["RGBM","( value, 16.0 )"];case si:return["RGBD","( value, 256.0 )"];case ti:return["Gamma","( value, float( GAMMA_FACTOR ) )"];default:return["Linear","( value )"]}}function so(t,e,i){const n=t.getShaderParameter(e,35713),s=t.getShaderInfoLog(e).trim();return n&&""===s?"":i.toUpperCase()+"\n\n"+s+"\n\n"+function(t){const e=t.split("\n");for(let t=0;t<e.length;t++)e[t]=t+1+": "+e[t];return e.join("\n")}(t.getShaderSource(e))}function ro(t,e){const i=no(e);return"vec4 "+t+"( vec4 value ) { return "+i[0]+"ToLinear"+i[1]+"; }"}function ao(t,e){const i=no(e);return"vec4 "+t+"( vec4 value ) { return LinearTo"+i[0]+i[1]+"; }"}function oo(t,e){let i;switch(e){case ft:i="Linear";break;case mt:i="Reinhard";break;case _t:i="OptimizedCineon";break;case gt:i="ACESFilmic";break;case yt:i="Custom";break;default:i="Linear"}return"vec3 "+t+"( vec3 color ) { return "+i+"ToneMapping( color ); }"}function lo(t){return""!==t}function ho(t,e){return t.replace(/NUM_DIR_LIGHTS/g,e.numDirLights).replace(/NUM_SPOT_LIGHTS/g,e.numSpotLights).replace(/NUM_RECT_AREA_LIGHTS/g,e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,e.numPointLights).replace(/NUM_HEMI_LIGHTS/g,e.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS/g,e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,e.numPointLightShadows)}function co(t,e){return t.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const uo=/^[ \t]*#include +<([\w\d./]+)>/gm;function po(t){return t.replace(uo,fo)}function fo(t,e){const i=ar[e];if(void 0===i)throw new Error("Can not resolve #include <"+e+">");return po(i)}const mo=/#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g,_o=/#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 go(t){return t.replace(_o,vo).replace(mo,yo)}function yo(t,e,i,n){return vo(0,e,i,n)}function vo(t,e,i,n){let s="";for(let t=parseInt(e);t<parseInt(i);t++)s+=n.replace(/\[\s*i\s*\]/g,"[ "+t+" ]").replace(/UNROLLED_LOOP_INDEX/g,t);return s}function xo(t){let e="precision "+t.precision+" float;\nprecision "+t.precision+" int;";return"highp"===t.precision?e+="\n#define HIGH_PRECISION":"mediump"===t.precision?e+="\n#define MEDIUM_PRECISION":"lowp"===t.precision&&(e+="\n#define LOW_PRECISION"),e}function wo(t,e,i,n){const s=t.getContext(),r=i.defines;let a=i.vertexShader,o=i.fragmentShader;const l=function(t){let e="SHADOWMAP_TYPE_BASIC";return t.shadowMapType===E?e="SHADOWMAP_TYPE_PCF":t.shadowMapType===z?e="SHADOWMAP_TYPE_PCF_SOFT":t.shadowMapType===I&&(e="SHADOWMAP_TYPE_VSM"),e}(i),h=function(t){let e="ENVMAP_TYPE_CUBE";if(t.envMap)switch(t.envMapMode){case vt:case xt:e="ENVMAP_TYPE_CUBE";break;case St:case Mt:e="ENVMAP_TYPE_CUBE_UV"}return e}(i),c=function(t){let e="ENVMAP_MODE_REFLECTION";if(t.envMap)switch(t.envMapMode){case xt:case Mt:e="ENVMAP_MODE_REFRACTION"}return e}(i),u=function(t){let e="ENVMAP_BLENDING_NONE";if(t.envMap)switch(t.combine){case ct:e="ENVMAP_BLENDING_MULTIPLY";break;case ut:e="ENVMAP_BLENDING_MIX";break;case dt:e="ENVMAP_BLENDING_ADD"}return e}(i),d=t.gammaFactor>0?t.gammaFactor:1,p=i.isWebGL2?"":function(t){return[t.extensionDerivatives||t.envMapCubeUV||t.bumpMap||t.tangentSpaceNormalMap||t.clearcoatNormalMap||t.flatShading||"physical"===t.shaderID?"#extension GL_OES_standard_derivatives : enable":"",(t.extensionFragDepth||t.logarithmicDepthBuffer)&&t.rendererExtensionFragDepth?"#extension GL_EXT_frag_depth : enable":"",t.extensionDrawBuffers&&t.rendererExtensionDrawBuffers?"#extension GL_EXT_draw_buffers : require":"",(t.extensionShaderTextureLOD||t.envMap||t.transmission)&&t.rendererExtensionShaderTextureLod?"#extension GL_EXT_shader_texture_lod : enable":""].filter(lo).join("\n")}(i),f=function(t){const e=[];for(const i in t){const n=t[i];!1!==n&&e.push("#define "+i+" "+n)}return e.join("\n")}(r),m=s.createProgram();let _,g,y=i.glslVersion?"#version "+i.glslVersion+"\n":"";i.isRawShaderMaterial?(_=[f].filter(lo).join("\n"),_.length>0&&(_+="\n"),g=[p,f].filter(lo).join("\n"),g.length>0&&(g+="\n")):(_=[xo(i),"#define SHADER_NAME "+i.shaderName,f,i.instancing?"#define USE_INSTANCING":"",i.instancingColor?"#define USE_INSTANCING_COLOR":"",i.supportsVertexTextures?"#define VERTEX_TEXTURES":"","#define GAMMA_FACTOR "+d,"#define MAX_BONES "+i.maxBones,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+c:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMap&&i.objectSpaceNormalMap?"#define OBJECTSPACE_NORMALMAP":"",i.normalMap&&i.tangentSpaceNormalMap?"#define TANGENTSPACE_NORMALMAP":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.displacementMap&&i.supportsVertexTextures?"#define USE_DISPLACEMENTMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularIntensityMap?"#define USE_SPECULARINTENSITYMAP":"",i.specularColorMap?"#define USE_SPECULARCOLORMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.sheenColorMap?"#define USE_SHEENCOLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEENROUGHNESSMAP":"",i.vertexTangents?"#define USE_TANGENT":"",i.vertexColors?"#define USE_COLOR":"",i.vertexAlphas?"#define USE_COLOR_ALPHA":"",i.vertexUvs?"#define USE_UV":"",i.uvsVertexOnly?"#define UVS_VERTEX_ONLY":"",i.flatShading?"#define FLAT_SHADED":"",i.skinning?"#define USE_SKINNING":"",i.useVertexTexture?"#define BONE_TEXTURE":"",i.morphTargets?"#define USE_MORPHTARGETS":"",i.morphNormals&&!1===i.flatShading?"#define USE_MORPHNORMALS":"",i.morphTargets&&i.isWebGL2?"#define MORPHTARGETS_TEXTURE":"",i.morphTargets&&i.isWebGL2?"#define MORPHTARGETS_COUNT "+i.morphTargetsCount:"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.sizeAttenuation?"#define USE_SIZEATTENUATION":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&i.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING","\tattribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR","\tattribute vec3 instanceColor;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )","\tattribute vec4 color;","#elif defined( USE_COLOR )","\tattribute vec3 color;","#endif","#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )","\tattribute vec3 morphTarget0;","\tattribute vec3 morphTarget1;","\tattribute vec3 morphTarget2;","\tattribute vec3 morphTarget3;","\t#ifdef USE_MORPHNORMALS","\t\tattribute vec3 morphNormal0;","\t\tattribute vec3 morphNormal1;","\t\tattribute vec3 morphNormal2;","\t\tattribute vec3 morphNormal3;","\t#else","\t\tattribute vec3 morphTarget4;","\t\tattribute vec3 morphTarget5;","\t\tattribute vec3 morphTarget6;","\t\tattribute vec3 morphTarget7;","\t#endif","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(lo).join("\n"),g=[p,xo(i),"#define SHADER_NAME "+i.shaderName,f,"#define GAMMA_FACTOR "+d,i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp2?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.matcap?"#define USE_MATCAP":"",i.envMap?"#define USE_ENVMAP":"",i.envMap?"#define "+h:"",i.envMap?"#define "+c:"",i.envMap?"#define "+u:"",i.lightMap?"#define USE_LIGHTMAP":"",i.aoMap?"#define USE_AOMAP":"",i.emissiveMap?"#define USE_EMISSIVEMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.normalMap&&i.objectSpaceNormalMap?"#define OBJECTSPACE_NORMALMAP":"",i.normalMap&&i.tangentSpaceNormalMap?"#define TANGENTSPACE_NORMALMAP":"",i.clearcoat?"#define USE_CLEARCOAT":"",i.clearcoatMap?"#define USE_CLEARCOATMAP":"",i.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",i.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.specularIntensityMap?"#define USE_SPECULARINTENSITYMAP":"",i.specularColorMap?"#define USE_SPECULARCOLORMAP":"",i.roughnessMap?"#define USE_ROUGHNESSMAP":"",i.metalnessMap?"#define USE_METALNESSMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.alphaTest?"#define USE_ALPHATEST":"",i.sheen?"#define USE_SHEEN":"",i.sheenColorMap?"#define USE_SHEENCOLORMAP":"",i.sheenRoughnessMap?"#define USE_SHEENROUGHNESSMAP":"",i.transmission?"#define USE_TRANSMISSION":"",i.transmissionMap?"#define USE_TRANSMISSIONMAP":"",i.thicknessMap?"#define USE_THICKNESSMAP":"",i.vertexTangents?"#define USE_TANGENT":"",i.vertexColors||i.instancingColor?"#define USE_COLOR":"",i.vertexAlphas?"#define USE_COLOR_ALPHA":"",i.vertexUvs?"#define USE_UV":"",i.uvsVertexOnly?"#define UVS_VERTEX_ONLY":"",i.gradientMap?"#define USE_GRADIENTMAP":"",i.flatShading?"#define FLAT_SHADED":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+l:"",i.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",i.physicallyCorrectLights?"#define PHYSICALLY_CORRECT_LIGHTS":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",i.logarithmicDepthBuffer&&i.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"",(i.extensionShaderTextureLOD||i.envMap)&&i.rendererExtensionShaderTextureLod?"#define TEXTURE_LOD_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",i.toneMapping!==pt?"#define TONE_MAPPING":"",i.toneMapping!==pt?ar.tonemapping_pars_fragment:"",i.toneMapping!==pt?oo("toneMapping",i.toneMapping):"",i.dithering?"#define DITHERING":"",i.format===Jt?"#define OPAQUE":"",ar.encodings_pars_fragment,i.map?ro("mapTexelToLinear",i.mapEncoding):"",i.matcap?ro("matcapTexelToLinear",i.matcapEncoding):"",i.envMap?ro("envMapTexelToLinear",i.envMapEncoding):"",i.emissiveMap?ro("emissiveMapTexelToLinear",i.emissiveMapEncoding):"",i.specularColorMap?ro("specularColorMapTexelToLinear",i.specularColorMapEncoding):"",i.sheenColorMap?ro("sheenColorMapTexelToLinear",i.sheenColorMapEncoding):"",i.lightMap?ro("lightMapTexelToLinear",i.lightMapEncoding):"",ao("linearToOutputTexel",i.outputEncoding),i.depthPacking?"#define DEPTH_PACKING "+i.depthPacking:"","\n"].filter(lo).join("\n")),a=po(a),a=ho(a,i),a=co(a,i),o=po(o),o=ho(o,i),o=co(o,i),a=go(a),o=go(o),i.isWebGL2&&!0!==i.isRawShaderMaterial&&(y="#version 300 es\n",_=["precision mediump sampler2DArray;","#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+_,g=["#define varying in",i.glslVersion===ui?"":"out highp vec4 pc_fragColor;",i.glslVersion===ui?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join("\n")+"\n"+g);const v=y+g+o,x=eo(s,35633,y+_+a),w=eo(s,35632,v);if(s.attachShader(m,x),s.attachShader(m,w),void 0!==i.index0AttributeName?s.bindAttribLocation(m,0,i.index0AttributeName):!0===i.morphTargets&&s.bindAttribLocation(m,0,"position"),s.linkProgram(m),t.debug.checkShaderErrors){const t=s.getProgramInfoLog(m).trim(),e=s.getShaderInfoLog(x).trim(),i=s.getShaderInfoLog(w).trim();let n=!0,r=!0;!1===s.getProgramParameter(m,35714)?(n=!1,so(s,x,"vertex"),so(s,w,"fragment")):""!==t||""!==e&&""!==i||(r=!1),r&&(this.diagnostics={runnable:n,programLog:t,vertexShader:{log:e,prefix:_},fragmentShader:{log:i,prefix:g}})}let b,S;return s.deleteShader(x),s.deleteShader(w),this.getUniforms=function(){return void 0===b&&(b=new to(s,m)),b},this.getAttributes=function(){return void 0===S&&(S=function(t,e){const i={},n=t.getProgramParameter(e,35721);for(let s=0;s<n;s++){const n=t.getActiveAttrib(e,s),r=n.name;let a=1;35674===n.type&&(a=2),35675===n.type&&(a=3),35676===n.type&&(a=4),i[r]={type:n.type,location:t.getAttribLocation(e,r),locationSize:a}}return i}(s,m)),S},this.destroy=function(){n.releaseStatesOfProgram(this),s.deleteProgram(m),this.program=void 0},this.name=i.shaderName,this.id=io++,this.cacheKey=e,this.usedTimes=1,this.program=m,this.vertexShader=x,this.fragmentShader=w,this}function bo(t,e,i,n,s,r,a){const o=[],l=s.isWebGL2,h=s.logarithmicDepthBuffer,c=s.floatVertexTextures,u=s.maxVertexUniforms,d=s.vertexTextures;let p=s.precision;const f={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"},m=["precision","isWebGL2","supportsVertexTextures","outputEncoding","instancing","instancingColor","map","mapEncoding","matcap","matcapEncoding","envMap","envMapMode","envMapEncoding","envMapCubeUV","lightMap","lightMapEncoding","aoMap","emissiveMap","emissiveMapEncoding","bumpMap","normalMap","objectSpaceNormalMap","tangentSpaceNormalMap","clearcoat","clearcoatMap","clearcoatRoughnessMap","clearcoatNormalMap","displacementMap","specularMap",,"roughnessMap","metalnessMap","gradientMap","alphaMap","alphaTest","combine","vertexColors","vertexAlphas","vertexTangents","vertexUvs","uvsVertexOnly","fog","useFog","fogExp2","flatShading","sizeAttenuation","logarithmicDepthBuffer","skinning","maxBones","useVertexTexture","morphTargets","morphNormals","morphTargetsCount","premultipliedAlpha","numDirLights","numPointLights","numSpotLights","numHemiLights","numRectAreaLights","numDirLightShadows","numPointLightShadows","numSpotLightShadows","shadowMapEnabled","shadowMapType","toneMapping","physicallyCorrectLights","doubleSided","flipSided","numClippingPlanes","numClipIntersection","depthPacking","dithering","format","specularIntensityMap","specularColorMap","specularColorMapEncoding","transmission","transmissionMap","thicknessMap","sheen","sheenColorMap","sheenColorMapEncoding","sheenRoughnessMap"];function _(t){let e;return e=t&&t.isTexture?t.encoding:t&&t.isWebGLRenderTarget?t.texture.encoding:Ke,e}return{getParameters:function(r,o,m,g,y){const v=g.fog,x=r.isMeshStandardMaterial?g.environment:null,w=(r.isMeshStandardMaterial?i:e).get(r.envMap||x),b=f[r.type],S=y.isSkinnedMesh?function(t){const e=t.skeleton.bones;if(c)return 1024;{const t=u,i=Math.floor((t-20)/4),n=Math.min(i,e.length);return n<e.length?0:n}}(y):0;let M,T;if(null!==r.precision&&(p=s.getMaxPrecision(r.precision),r.precision),b){const t=lr[b];M=t.vertexShader,T=t.fragmentShader}else M=r.vertexShader,T=r.fragmentShader;const C=t.getRenderTarget(),A=r.alphaTest>0,E=r.clearcoat>0;return{isWebGL2:l,shaderID:b,shaderName:r.type,vertexShader:M,fragmentShader:T,defines:r.defines,isRawShaderMaterial:!0===r.isRawShaderMaterial,glslVersion:r.glslVersion,precision:p,instancing:!0===y.isInstancedMesh,instancingColor:!0===y.isInstancedMesh&&null!==y.instanceColor,supportsVertexTextures:d,outputEncoding:null!==C?_(C.texture):t.outputEncoding,map:!!r.map,mapEncoding:_(r.map),matcap:!!r.matcap,matcapEncoding:_(r.matcap),envMap:!!w,envMapMode:w&&w.mapping,envMapEncoding:_(w),envMapCubeUV:!!w&&(w.mapping===St||w.mapping===Mt),lightMap:!!r.lightMap,lightMapEncoding:_(r.lightMap),aoMap:!!r.aoMap,emissiveMap:!!r.emissiveMap,emissiveMapEncoding:_(r.emissiveMap),bumpMap:!!r.bumpMap,normalMap:!!r.normalMap,objectSpaceNormalMap:r.normalMapType===oi,tangentSpaceNormalMap:r.normalMapType===ai,clearcoat:E,clearcoatMap:E&&!!r.clearcoatMap,clearcoatRoughnessMap:E&&!!r.clearcoatRoughnessMap,clearcoatNormalMap:E&&!!r.clearcoatNormalMap,displacementMap:!!r.displacementMap,roughnessMap:!!r.roughnessMap,metalnessMap:!!r.metalnessMap,specularMap:!!r.specularMap,specularIntensityMap:!!r.specularIntensityMap,specularColorMap:!!r.specularColorMap,specularColorMapEncoding:_(r.specularColorMap),alphaMap:!!r.alphaMap,alphaTest:A,gradientMap:!!r.gradientMap,sheen:r.sheen>0,sheenColorMap:!!r.sheenColorMap,sheenColorMapEncoding:_(r.sheenColorMap),sheenRoughnessMap:!!r.sheenRoughnessMap,transmission:r.transmission>0,transmissionMap:!!r.transmissionMap,thicknessMap:!!r.thicknessMap,combine:r.combine,vertexTangents:!!r.normalMap&&!!y.geometry&&!!y.geometry.attributes.tangent,vertexColors:r.vertexColors,vertexAlphas:!0===r.vertexColors&&!!y.geometry&&!!y.geometry.attributes.color&&4===y.geometry.attributes.color.itemSize,vertexUvs:!!r.map||!!r.bumpMap||!!r.normalMap||!!r.specularMap||!!r.alphaMap||!!r.emissiveMap||!!r.roughnessMap||!!r.metalnessMap||!!r.clearcoatMap||!!r.clearcoatRoughnessMap||!!r.clearcoatNormalMap||!!r.displacementMap||!!r.transmissionMap||!!r.thicknessMap||!!r.specularIntensityMap||!!r.specularColorMap||!!r.sheenColorMap||r.sheenRoughnessMap,uvsVertexOnly:!(r.map||r.bumpMap||r.normalMap||r.specularMap||r.alphaMap||r.emissiveMap||r.roughnessMap||r.metalnessMap||r.clearcoatNormalMap||r.transmission>0||r.transmissionMap||r.thicknessMap||r.specularIntensityMap||r.specularColorMap||r.sheen>0||r.sheenColorMap||r.sheenRoughnessMap||!r.displacementMap),fog:!!v,useFog:r.fog,fogExp2:v&&v.isFogExp2,flatShading:!!r.flatShading,sizeAttenuation:r.sizeAttenuation,logarithmicDepthBuffer:h,skinning:!0===y.isSkinnedMesh&&S>0,maxBones:S,useVertexTexture:c,morphTargets:!!y.geometry&&!!y.geometry.morphAttributes.position,morphNormals:!!y.geometry&&!!y.geometry.morphAttributes.normal,morphTargetsCount:y.geometry&&y.geometry.morphAttributes.position?y.geometry.morphAttributes.position.length:0,numDirLights:o.directional.length,numPointLights:o.point.length,numSpotLights:o.spot.length,numRectAreaLights:o.rectArea.length,numHemiLights:o.hemi.length,numDirLightShadows:o.directionalShadowMap.length,numPointLightShadows:o.pointShadowMap.length,numSpotLightShadows:o.spotShadowMap.length,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,format:r.format,dithering:r.dithering,shadowMapEnabled:t.shadowMap.enabled&&m.length>0,shadowMapType:t.shadowMap.type,toneMapping:r.toneMapped?t.toneMapping:pt,physicallyCorrectLights:t.physicallyCorrectLights,premultipliedAlpha:r.premultipliedAlpha,doubleSided:r.side===P,flipSided:r.side===L,depthPacking:void 0!==r.depthPacking&&r.depthPacking,index0AttributeName:r.index0AttributeName,extensionDerivatives:r.extensions&&r.extensions.derivatives,extensionFragDepth:r.extensions&&r.extensions.fragDepth,extensionDrawBuffers:r.extensions&&r.extensions.drawBuffers,extensionShaderTextureLOD:r.extensions&&r.extensions.shaderTextureLOD,rendererExtensionFragDepth:l||n.has("EXT_frag_depth"),rendererExtensionDrawBuffers:l||n.has("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:l||n.has("EXT_shader_texture_lod"),customProgramCacheKey:r.customProgramCacheKey()}},getProgramCacheKey:function(e){const i=[];if(e.shaderID?i.push(e.shaderID):(i.push(Ci(e.fragmentShader)),i.push(Ci(e.vertexShader))),void 0!==e.defines)for(const t in e.defines)i.push(t),i.push(e.defines[t]);if(!1===e.isRawShaderMaterial){for(let t=0;t<m.length;t++)i.push(e[m[t]]);i.push(t.outputEncoding),i.push(t.gammaFactor)}return i.push(e.customProgramCacheKey),i.join()},getUniforms:function(t){const e=f[t.type];let i;if(e){const t=lr[e];i=Gs.clone(t.uniforms)}else i=t.uniforms;return i},acquireProgram:function(e,i){let n;for(let t=0,e=o.length;t<e;t++){const e=o[t];if(e.cacheKey===i){n=e,++n.usedTimes;break}}return void 0===n&&(n=new wo(t,i,e,r),o.push(n)),n},releaseProgram:function(t){if(0==--t.usedTimes){const e=o.indexOf(t);o[e]=o[o.length-1],o.pop(),t.destroy()}},programs:o}}function So(){let t=new WeakMap;return{get:function(e){let i=t.get(e);return void 0===i&&(i={},t.set(e,i)),i},remove:function(e){t.delete(e)},update:function(e,i,n){t.get(e)[i]=n},dispose:function(){t=new WeakMap}}}function Mo(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.program!==e.program?t.program.id-e.program.id:t.material.id!==e.material.id?t.material.id-e.material.id:t.z!==e.z?t.z-e.z:t.id-e.id}function To(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder:t.z!==e.z?e.z-t.z:t.id-e.id}function Co(t){const e=[];let i=0;const n=[],s=[],r=[],a={id:-1};function o(n,s,r,o,l,h){let c=e[i];const u=t.get(r);return void 0===c?(c={id:n.id,object:n,geometry:s,material:r,program:u.program||a,groupOrder:o,renderOrder:n.renderOrder,z:l,group:h},e[i]=c):(c.id=n.id,c.object=n,c.geometry=s,c.material=r,c.program=u.program||a,c.groupOrder=o,c.renderOrder=n.renderOrder,c.z=l,c.group=h),i++,c}return{opaque:n,transmissive:s,transparent:r,init:function(){i=0,n.length=0,s.length=0,r.length=0},push:function(t,e,i,a,l,h){const c=o(t,e,i,a,l,h);i.transmission>0?s.push(c):!0===i.transparent?r.push(c):n.push(c)},unshift:function(t,e,i,a,l,h){const c=o(t,e,i,a,l,h);i.transmission>0?s.unshift(c):!0===i.transparent?r.unshift(c):n.unshift(c)},finish:function(){for(let t=i,n=e.length;t<n;t++){const i=e[t];if(null===i.id)break;i.id=null,i.object=null,i.geometry=null,i.material=null,i.program=null,i.group=null}},sort:function(t,e){n.length>1&&n.sort(t||Mo),s.length>1&&s.sort(e||To),r.length>1&&r.sort(e||To)}}}function Ao(t){let e=new WeakMap;return{get:function(i,n){let s;return!1===e.has(i)?(s=new Co(t),e.set(i,[s])):n>=e.get(i).length?(s=new Co(t),e.get(i).push(s)):s=e.get(i)[n],s},dispose:function(){e=new WeakMap}}}function Eo(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":i={direction:new Di,color:new ss};break;case"SpotLight":i={position:new Di,direction:new Di,color:new ss,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":i={position:new Di,color:new ss,distance:0,decay:0};break;case"HemisphereLight":i={direction:new Di,skyColor:new ss,groundColor:new ss};break;case"RectAreaLight":i={color:new ss,position:new Di,halfWidth:new Di,halfHeight:new Di}}return t[e.id]=i,i}}}let zo=0;function Io(t,e){return(e.castShadow?1:0)-(t.castShadow?1:0)}function No(t,e){const i=new Eo,n=function(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let i;switch(e.type){case"DirectionalLight":case"SpotLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new bi};break;case"PointLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new bi,shadowCameraNear:1,shadowCameraFar:1e3}}return t[e.id]=i,i}}}(),s={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotShadow:[],spotShadowMap:[],spotShadowMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[]};for(let t=0;t<9;t++)s.probe.push(new Di);const r=new Di,a=new pn,o=new pn;return{setup:function(r,a){let o=0,l=0,h=0;for(let t=0;t<9;t++)s.probe[t].set(0,0,0);let c=0,u=0,d=0,p=0,f=0,m=0,_=0,g=0;r.sort(Io);const y=!0!==a?Math.PI:1;for(let t=0,e=r.length;t<e;t++){const e=r[t],a=e.color,v=e.intensity,x=e.distance,w=e.shadow&&e.shadow.map?e.shadow.map.texture:null;if(e.isAmbientLight)o+=a.r*v*y,l+=a.g*v*y,h+=a.b*v*y;else if(e.isLightProbe)for(let t=0;t<9;t++)s.probe[t].addScaledVector(e.sh.coefficients[t],v);else if(e.isDirectionalLight){const t=i.get(e);if(t.color.copy(e.color).multiplyScalar(e.intensity*y),e.castShadow){const t=e.shadow,i=n.get(e);i.shadowBias=t.bias,i.shadowNormalBias=t.normalBias,i.shadowRadius=t.radius,i.shadowMapSize=t.mapSize,s.directionalShadow[c]=i,s.directionalShadowMap[c]=w,s.directionalShadowMatrix[c]=e.shadow.matrix,m++}s.directional[c]=t,c++}else if(e.isSpotLight){const t=i.get(e);if(t.position.setFromMatrixPosition(e.matrixWorld),t.color.copy(a).multiplyScalar(v*y),t.distance=x,t.coneCos=Math.cos(e.angle),t.penumbraCos=Math.cos(e.angle*(1-e.penumbra)),t.decay=e.decay,e.castShadow){const t=e.shadow,i=n.get(e);i.shadowBias=t.bias,i.shadowNormalBias=t.normalBias,i.shadowRadius=t.radius,i.shadowMapSize=t.mapSize,s.spotShadow[d]=i,s.spotShadowMap[d]=w,s.spotShadowMatrix[d]=e.shadow.matrix,g++}s.spot[d]=t,d++}else if(e.isRectAreaLight){const t=i.get(e);t.color.copy(a).multiplyScalar(v),t.halfWidth.set(.5*e.width,0,0),t.halfHeight.set(0,.5*e.height,0),s.rectArea[p]=t,p++}else if(e.isPointLight){const t=i.get(e);if(t.color.copy(e.color).multiplyScalar(e.intensity*y),t.distance=e.distance,t.decay=e.decay,e.castShadow){const t=e.shadow,i=n.get(e);i.shadowBias=t.bias,i.shadowNormalBias=t.normalBias,i.shadowRadius=t.radius,i.shadowMapSize=t.mapSize,i.shadowCameraNear=t.camera.near,i.shadowCameraFar=t.camera.far,s.pointShadow[u]=i,s.pointShadowMap[u]=w,s.pointShadowMatrix[u]=e.shadow.matrix,_++}s.point[u]=t,u++}else if(e.isHemisphereLight){const t=i.get(e);t.skyColor.copy(e.color).multiplyScalar(v*y),t.groundColor.copy(e.groundColor).multiplyScalar(v*y),s.hemi[f]=t,f++}}p>0&&(e.isWebGL2||!0===t.has("OES_texture_float_linear")?(s.rectAreaLTC1=or.LTC_FLOAT_1,s.rectAreaLTC2=or.LTC_FLOAT_2):!0===t.has("OES_texture_half_float_linear")&&(s.rectAreaLTC1=or.LTC_HALF_1,s.rectAreaLTC2=or.LTC_HALF_2)),s.ambient[0]=o,s.ambient[1]=l,s.ambient[2]=h;const v=s.hash;v.directionalLength===c&&v.pointLength===u&&v.spotLength===d&&v.rectAreaLength===p&&v.hemiLength===f&&v.numDirectionalShadows===m&&v.numPointShadows===_&&v.numSpotShadows===g||(s.directional.length=c,s.spot.length=d,s.rectArea.length=p,s.point.length=u,s.hemi.length=f,s.directionalShadow.length=m,s.directionalShadowMap.length=m,s.pointShadow.length=_,s.pointShadowMap.length=_,s.spotShadow.length=g,s.spotShadowMap.length=g,s.directionalShadowMatrix.length=m,s.pointShadowMatrix.length=_,s.spotShadowMatrix.length=g,v.directionalLength=c,v.pointLength=u,v.spotLength=d,v.rectAreaLength=p,v.hemiLength=f,v.numDirectionalShadows=m,v.numPointShadows=_,v.numSpotShadows=g,s.version=zo++)},setupView:function(t,e){let i=0,n=0,l=0,h=0,c=0;const u=e.matrixWorldInverse;for(let e=0,d=t.length;e<d;e++){const d=t[e];if(d.isDirectionalLight){const t=s.directional[i];t.direction.setFromMatrixPosition(d.matrixWorld),r.setFromMatrixPosition(d.target.matrixWorld),t.direction.sub(r),t.direction.transformDirection(u),i++}else if(d.isSpotLight){const t=s.spot[l];t.position.setFromMatrixPosition(d.matrixWorld),t.position.applyMatrix4(u),t.direction.setFromMatrixPosition(d.matrixWorld),r.setFromMatrixPosition(d.target.matrixWorld),t.direction.sub(r),t.direction.transformDirection(u),l++}else if(d.isRectAreaLight){const t=s.rectArea[h];t.position.setFromMatrixPosition(d.matrixWorld),t.position.applyMatrix4(u),o.identity(),a.copy(d.matrixWorld),a.premultiply(u),o.extractRotation(a),t.halfWidth.set(.5*d.width,0,0),t.halfHeight.set(0,.5*d.height,0),t.halfWidth.applyMatrix4(o),t.halfHeight.applyMatrix4(o),h++}else if(d.isPointLight){const t=s.point[n];t.position.setFromMatrixPosition(d.matrixWorld),t.position.applyMatrix4(u),n++}else if(d.isHemisphereLight){const t=s.hemi[c];t.direction.setFromMatrixPosition(d.matrixWorld),t.direction.transformDirection(u),t.direction.normalize(),c++}}},state:s}}function Lo(t,e){const i=new No(t,e),n=[],s=[];return{init:function(){n.length=0,s.length=0},state:{lightsArray:n,shadowsArray:s,lights:i},setupLights:function(t){i.setup(n,t)},setupLightsView:function(t){i.setupView(n,t)},pushLight:function(t){n.push(t)},pushShadow:function(t){s.push(t)}}}function Po(t,e){let i=new WeakMap;return{get:function(n,s=0){let r;return!1===i.has(n)?(r=new Lo(t,e),i.set(n,[r])):s>=i.get(n).length?(r=new Lo(t,e),i.get(n).push(r)):r=i.get(n)[s],r},dispose:function(){i=new WeakMap}}}class Fo extends $n{constructor(t){super(),this.type="MeshDepthMaterial",this.depthPacking=3200,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.setValues(t)}copy(t){return super.copy(t),this.depthPacking=t.depthPacking,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this}}Fo.prototype.isMeshDepthMaterial=!0;class Do extends $n{constructor(t){super(),this.type="MeshDistanceMaterial",this.referencePosition=new Di,this.nearDistance=1,this.farDistance=1e3,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.fog=!1,this.setValues(t)}copy(t){return super.copy(t),this.referencePosition.copy(t.referencePosition),this.nearDistance=t.nearDistance,this.farDistance=t.farDistance,this.map=t.map,this.alphaMap=t.alphaMap,this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this}}Do.prototype.isMeshDistanceMaterial=!0;const Oo="void main() {\n\tgl_Position = vec4( position, 1.0 );\n}",Ro="uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";function ko(t,e,i){let n=new ir;const s=new bi,r=new bi,a=new Ni,o=new Fo({depthPacking:ri}),l=new Do,h={},c=i.maxTextureSize,u={0:L,1:N,2:P},d=new Ws({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new bi},radius:{value:4}},vertexShader:Oo,fragmentShader:Ro}),p=d.clone();p.defines.HORIZONTAL_PASS=1;const f=new vs;f.setAttribute("position",new ls(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const m=new Rs(f,d),_=this;function g(i,n){const s=e.update(m);d.defines.VSM_SAMPLES!==i.blurSamples&&(d.defines.VSM_SAMPLES=i.blurSamples,p.defines.VSM_SAMPLES=i.blurSamples,d.needsUpdate=!0,p.needsUpdate=!0),d.uniforms.shadow_pass.value=i.map.texture,d.uniforms.resolution.value=i.mapSize,d.uniforms.radius.value=i.radius,t.setRenderTarget(i.mapPass),t.clear(),t.renderBufferDirect(n,null,s,d,m,null),p.uniforms.shadow_pass.value=i.mapPass.texture,p.uniforms.resolution.value=i.mapSize,p.uniforms.radius.value=i.radius,t.setRenderTarget(i.map),t.clear(),t.renderBufferDirect(n,null,s,p,m,null)}function y(e,i,n,s,r,a,c){let d=null;const p=!0===s.isPointLight?e.customDistanceMaterial:e.customDepthMaterial;if(d=void 0!==p?p:!0===s.isPointLight?l:o,t.localClippingEnabled&&!0===n.clipShadows&&0!==n.clippingPlanes.length||n.displacementMap&&0!==n.displacementScale||n.alphaMap&&n.alphaTest>0){const t=d.uuid,e=n.uuid;let i=h[t];void 0===i&&(i={},h[t]=i);let s=i[e];void 0===s&&(s=d.clone(),i[e]=s),d=s}return d.visible=n.visible,d.wireframe=n.wireframe,d.side=c===I?null!==n.shadowSide?n.shadowSide:n.side:null!==n.shadowSide?n.shadowSide:u[n.side],d.alphaMap=n.alphaMap,d.alphaTest=n.alphaTest,d.clipShadows=n.clipShadows,d.clippingPlanes=n.clippingPlanes,d.clipIntersection=n.clipIntersection,d.displacementMap=n.displacementMap,d.displacementScale=n.displacementScale,d.displacementBias=n.displacementBias,d.wireframeLinewidth=n.wireframeLinewidth,d.linewidth=n.linewidth,!0===s.isPointLight&&!0===d.isMeshDistanceMaterial&&(d.referencePosition.setFromMatrixPosition(s.matrixWorld),d.nearDistance=r,d.farDistance=a),d}function v(i,s,r,a,o){if(!1===i.visible)return;if(i.layers.test(s.layers)&&(i.isMesh||i.isLine||i.isPoints)&&(i.castShadow||i.receiveShadow&&o===I)&&(!i.frustumCulled||n.intersectsObject(i))){i.modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,i.matrixWorld);const n=e.update(i),s=i.material;if(Array.isArray(s)){const e=n.groups;for(let l=0,h=e.length;l<h;l++){const h=e[l],c=s[h.materialIndex];if(c&&c.visible){const e=y(i,0,c,a,r.near,r.far,o);t.renderBufferDirect(r,null,n,e,i,h)}}}else if(s.visible){const e=y(i,0,s,a,r.near,r.far,o);t.renderBufferDirect(r,null,n,e,i,null)}}const l=i.children;for(let t=0,e=l.length;t<e;t++)v(l[t],s,r,a,o)}this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=E,this.render=function(e,i,o){if(!1===_.enabled)return;if(!1===_.autoUpdate&&!1===_.needsUpdate)return;if(0===e.length)return;const l=t.getRenderTarget(),h=t.getActiveCubeFace(),u=t.getActiveMipmapLevel(),d=t.state;d.setBlending(F),d.buffers.color.setClear(1,1,1,1),d.buffers.depth.setTest(!0),d.setScissorTest(!1);for(let l=0,h=e.length;l<h;l++){const h=e[l],u=h.shadow;if(void 0===u)continue;if(!1===u.autoUpdate&&!1===u.needsUpdate)continue;s.copy(u.mapSize);const p=u.getFrameExtents();if(s.multiply(p),r.copy(u.mapSize),(s.x>c||s.y>c)&&(s.x>c&&(r.x=Math.floor(c/p.x),s.x=r.x*p.x,u.mapSize.x=r.x),s.y>c&&(r.y=Math.floor(c/p.y),s.y=r.y*p.y,u.mapSize.y=r.y)),null===u.map&&!u.isPointLightShadow&&this.type===I){const t={minFilter:Nt,magFilter:Nt,format:Yt};u.map=new Li(s.x,s.y,t),u.map.texture.name=h.name+".shadowMap",u.mapPass=new Li(s.x,s.y,t),u.camera.updateProjectionMatrix()}if(null===u.map){const t={minFilter:Et,magFilter:Et,format:Yt};u.map=new Li(s.x,s.y,t),u.map.texture.name=h.name+".shadowMap",u.camera.updateProjectionMatrix()}t.setRenderTarget(u.map),t.clear();const f=u.getViewportCount();for(let t=0;t<f;t++){const e=u.getViewport(t);a.set(r.x*e.x,r.y*e.y,r.x*e.z,r.y*e.w),d.viewport(a),u.updateMatrices(h,t),n=u.getFrustum(),v(i,o,u.camera,h,this.type)}u.isPointLightShadow||this.type!==I||g(u,o),u.needsUpdate=!1}_.needsUpdate=!1,t.setRenderTarget(l,h,u)}}function Uo(t,e,i){const n=i.isWebGL2,s=new function(){let e=!1;const i=new Ni;let n=null;const s=new Ni(0,0,0,0);return{setMask:function(i){n===i||e||(t.colorMask(i,i,i,i),n=i)},setLocked:function(t){e=t},setClear:function(e,n,r,a,o){!0===o&&(e*=a,n*=a,r*=a),i.set(e,n,r,a),!1===s.equals(i)&&(t.clearColor(e,n,r,a),s.copy(i))},reset:function(){e=!1,n=null,s.set(-1,0,0,0)}}},r=new function(){let e=!1,i=null,n=null,s=null;return{setTest:function(t){t?gt(2929):yt(2929)},setMask:function(n){i===n||e||(t.depthMask(n),i=n)},setFunc:function(e){if(n!==e){if(e)switch(e){case it:t.depthFunc(512);break;case nt:t.depthFunc(519);break;case st:t.depthFunc(513);break;case rt:t.depthFunc(515);break;case at:t.depthFunc(514);break;case ot:t.depthFunc(518);break;case lt:t.depthFunc(516);break;case ht:t.depthFunc(517);break;default:t.depthFunc(515)}else t.depthFunc(515);n=e}},setLocked:function(t){e=t},setClear:function(e){s!==e&&(t.clearDepth(e),s=e)},reset:function(){e=!1,i=null,n=null,s=null}}},a=new function(){let e=!1,i=null,n=null,s=null,r=null,a=null,o=null,l=null,h=null;return{setTest:function(t){e||(t?gt(2960):yt(2960))},setMask:function(n){i===n||e||(t.stencilMask(n),i=n)},setFunc:function(e,i,a){n===e&&s===i&&r===a||(t.stencilFunc(e,i,a),n=e,s=i,r=a)},setOp:function(e,i,n){a===e&&o===i&&l===n||(t.stencilOp(e,i,n),a=e,o=i,l=n)},setLocked:function(t){e=t},setClear:function(e){h!==e&&(t.clearStencil(e),h=e)},reset:function(){e=!1,i=null,n=null,s=null,r=null,a=null,o=null,l=null,h=null}}};let o={},l={},h=null,c=!1,u=null,d=null,p=null,f=null,m=null,_=null,g=null,y=!1,v=null,x=null,w=null,b=null,S=null;const M=t.getParameter(35661);let E=!1,z=0;const I=t.getParameter(7938);-1!==I.indexOf("WebGL")?(z=parseFloat(/^WebGL (\d)/.exec(I)[1]),E=z>=1):-1!==I.indexOf("OpenGL ES")&&(z=parseFloat(/^OpenGL ES (\d)/.exec(I)[1]),E=z>=2);let N=null,ct={};const ut=t.getParameter(3088),dt=t.getParameter(2978),pt=(new Ni).fromArray(ut),ft=(new Ni).fromArray(dt);function mt(e,i,n){const s=new Uint8Array(4),r=t.createTexture();t.bindTexture(e,r),t.texParameteri(e,10241,9728),t.texParameteri(e,10240,9728);for(let e=0;e<n;e++)t.texImage2D(i+e,0,6408,1,1,0,6408,5121,s);return r}const _t={};function gt(e){!0!==o[e]&&(t.enable(e),o[e]=!0)}function yt(e){!1!==o[e]&&(t.disable(e),o[e]=!1)}_t[3553]=mt(3553,3553,1),_t[34067]=mt(34067,34069,6),s.setClear(0,0,0,1),r.setClear(1),a.setClear(0),gt(2929),r.setFunc(rt),bt(!1),St(C),gt(2884),wt(F);const vt={[B]:32774,[V]:32778,[G]:32779};if(n)vt[W]=32775,vt[H]=32776;else{const t=e.get("EXT_blend_minmax");null!==t&&(vt[W]=t.MIN_EXT,vt[H]=t.MAX_EXT)}const xt={[j]:0,[q]:1,[J]:768,[X]:770,[et]:776,[Q]:774,[$]:772,[Y]:769,[Z]:771,[tt]:775,[K]:773};function wt(e,i,n,s,r,a,o,l){if(e!==F){if(!1===c&&(gt(3042),c=!0),e===U)r=r||i,a=a||n,o=o||s,i===d&&r===m||(t.blendEquationSeparate(vt[i],vt[r]),d=i,m=r),n===p&&s===f&&a===_&&o===g||(t.blendFuncSeparate(xt[n],xt[s],xt[a],xt[o]),p=n,f=s,_=a,g=o),u=e,y=null;else if(e!==u||l!==y){if(d===B&&m===B||(t.blendEquation(32774),d=B,m=B),l)switch(e){case D:t.blendFuncSeparate(1,771,1,771);break;case O:t.blendFunc(1,1);break;case R:t.blendFuncSeparate(0,0,769,771);break;case k:t.blendFuncSeparate(0,768,0,770)}else switch(e){case D:t.blendFuncSeparate(770,771,1,771);break;case O:t.blendFunc(770,1);break;case R:t.blendFunc(0,769);break;case k:t.blendFunc(0,768)}p=null,f=null,_=null,g=null,u=e,y=l}}else!0===c&&(yt(3042),c=!1)}function bt(e){v!==e&&(e?t.frontFace(2304):t.frontFace(2305),v=e)}function St(e){e!==T?(gt(2884),e!==x&&(e===C?t.cullFace(1029):e===A?t.cullFace(1028):t.cullFace(1032))):yt(2884),x=e}function Mt(e,i,n){e?(gt(32823),b===i&&S===n||(t.polygonOffset(i,n),b=i,S=n)):yt(32823)}function Tt(e){void 0===e&&(e=33984+M-1),N!==e&&(t.activeTexture(e),N=e)}return{buffers:{color:s,depth:r,stencil:a},enable:gt,disable:yt,bindFramebuffer:function(e,i){return l[e]!==i&&(t.bindFramebuffer(e,i),l[e]=i,n&&(36009===e&&(l[36160]=i),36160===e&&(l[36009]=i)),!0)},useProgram:function(e){return h!==e&&(t.useProgram(e),h=e,!0)},setBlending:wt,setMaterial:function(t,e){t.side===P?yt(2884):gt(2884);let i=t.side===L;e&&(i=!i),bt(i),t.blending===D&&!1===t.transparent?wt(F):wt(t.blending,t.blendEquation,t.blendSrc,t.blendDst,t.blendEquationAlpha,t.blendSrcAlpha,t.blendDstAlpha,t.premultipliedAlpha),r.setFunc(t.depthFunc),r.setTest(t.depthTest),r.setMask(t.depthWrite),s.setMask(t.colorWrite);const n=t.stencilWrite;a.setTest(n),n&&(a.setMask(t.stencilWriteMask),a.setFunc(t.stencilFunc,t.stencilRef,t.stencilFuncMask),a.setOp(t.stencilFail,t.stencilZFail,t.stencilZPass)),Mt(t.polygonOffset,t.polygonOffsetFactor,t.polygonOffsetUnits),!0===t.alphaToCoverage?gt(32926):yt(32926)},setFlipSided:bt,setCullFace:St,setLineWidth:function(e){e!==w&&(E&&t.lineWidth(e),w=e)},setPolygonOffset:Mt,setScissorTest:function(t){t?gt(3089):yt(3089)},activeTexture:Tt,bindTexture:function(e,i){null===N&&Tt();let n=ct[N];void 0===n&&(n={type:void 0,texture:void 0},ct[N]=n),n.type===e&&n.texture===i||(t.bindTexture(e,i||_t[e]),n.type=e,n.texture=i)},unbindTexture:function(){const e=ct[N];void 0!==e&&void 0!==e.type&&(t.bindTexture(e.type,null),e.type=void 0,e.texture=void 0)},compressedTexImage2D:function(){try{t.compressedTexImage2D.apply(t,arguments)}catch(t){}},texImage2D:function(){try{t.texImage2D.apply(t,arguments)}catch(t){}},texImage3D:function(){try{t.texImage3D.apply(t,arguments)}catch(t){}},texStorage2D:function(){try{t.texStorage2D.apply(t,arguments)}catch(t){}},texSubImage2D:function(){try{t.texSubImage2D.apply(t,arguments)}catch(t){}},scissor:function(e){!1===pt.equals(e)&&(t.scissor(e.x,e.y,e.z,e.w),pt.copy(e))},viewport:function(e){!1===ft.equals(e)&&(t.viewport(e.x,e.y,e.z,e.w),ft.copy(e))},reset:function(){t.disable(3042),t.disable(2884),t.disable(2929),t.disable(32823),t.disable(3089),t.disable(2960),t.disable(32926),t.blendEquation(32774),t.blendFunc(1,0),t.blendFuncSeparate(1,0,1,0),t.colorMask(!0,!0,!0,!0),t.clearColor(0,0,0,0),t.depthMask(!0),t.depthFunc(513),t.clearDepth(1),t.stencilMask(4294967295),t.stencilFunc(519,0,4294967295),t.stencilOp(7680,7680,7680),t.clearStencil(0),t.cullFace(1029),t.frontFace(2305),t.polygonOffset(0,0),t.activeTexture(33984),t.bindFramebuffer(36160,null),!0===n&&(t.bindFramebuffer(36009,null),t.bindFramebuffer(36008,null)),t.useProgram(null),t.lineWidth(1),t.scissor(0,0,t.canvas.width,t.canvas.height),t.viewport(0,0,t.canvas.width,t.canvas.height),o={},N=null,ct={},l={},h=null,c=!1,u=null,d=null,p=null,f=null,m=null,_=null,g=null,y=!1,v=null,x=null,w=null,b=null,S=null,pt.set(0,0,t.canvas.width,t.canvas.height),ft.set(0,0,t.canvas.width,t.canvas.height),s.reset(),r.reset(),a.reset()}}}function Bo(t,e,i,n,s,r,a){const o=s.isWebGL2;s.maxTextures;const l=s.maxCubemapSize,h=s.maxTextureSize,c=s.maxSamples,u=e.has("WEBGL_multisampled_render_to_texture")?e.get("WEBGL_multisampled_render_to_texture"):void 0,d=new WeakMap;let p,f=!1;try{f="undefined"!=typeof OffscreenCanvas&&null!==new OffscreenCanvas(1,1).getContext("2d")}catch(t){}function m(t,e){return f?new OffscreenCanvas(t,e):Ti("canvas")}function _(t,e,i,n){let s=1;if((t.width>n||t.height>n)&&(s=n/Math.max(t.width,t.height)),s<1||!0===e){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const n=e?xi:Math.floor,r=n(s*t.width),a=n(s*t.height);void 0===p&&(p=m(r,a));const o=i?m(r,a):p;return o.width=r,o.height=a,o.getContext("2d").drawImage(t,0,0,r,a),o}return t}return t}function g(t){return vi(t.width)&&vi(t.height)}function y(t,e){return t.generateMipmaps&&e&&t.minFilter!==Et&&t.minFilter!==Nt}function v(e){t.generateMipmap(e)}function x(i,n,s){if(!1===o)return n;if(null!==i&&void 0!==t[i])return t[i];let r=n;return 6403===n&&(5126===s&&(r=33326),5131===s&&(r=33325),5121===s&&(r=33321)),6407===n&&(5126===s&&(r=34837),5131===s&&(r=34843),5121===s&&(r=32849)),6408===n&&(5126===s&&(r=34836),5131===s&&(r=34842),5121===s&&(r=32856)),33325!==r&&33326!==r&&34842!==r&&34836!==r||e.get("EXT_color_buffer_float"),r}function w(t){return t===Et||t===zt||t===It?9728:9729}function b(e){const i=e.target;i.removeEventListener("dispose",b),function(e){const i=n.get(e);void 0!==i.__webglInit&&(t.deleteTexture(i.__webglTexture),n.remove(e))}(i),i.isVideoTexture&&d.delete(i),a.memory.textures--}function S(e){const i=e.target;i.removeEventListener("dispose",S),function(e){const i=e.texture,s=n.get(e),r=n.get(i);if(e){if(void 0!==r.__webglTexture&&(t.deleteTexture(r.__webglTexture),a.memory.textures--),e.depthTexture&&e.depthTexture.dispose(),e.isWebGLCubeRenderTarget)for(let e=0;e<6;e++)t.deleteFramebuffer(s.__webglFramebuffer[e]),s.__webglDepthbuffer&&t.deleteRenderbuffer(s.__webglDepthbuffer[e]);else t.deleteFramebuffer(s.__webglFramebuffer),s.__webglDepthbuffer&&t.deleteRenderbuffer(s.__webglDepthbuffer),s.__webglMultisampledFramebuffer&&t.deleteFramebuffer(s.__webglMultisampledFramebuffer),s.__webglColorRenderbuffer&&t.deleteRenderbuffer(s.__webglColorRenderbuffer),s.__webglDepthRenderbuffer&&t.deleteRenderbuffer(s.__webglDepthRenderbuffer);if(e.isWebGLMultipleRenderTargets)for(let e=0,s=i.length;e<s;e++){const s=n.get(i[e]);s.__webglTexture&&(t.deleteTexture(s.__webglTexture),a.memory.textures--),n.remove(i[e])}n.remove(i),n.remove(e)}}(i)}let M=0;function T(t,e){const s=n.get(t);if(t.isVideoTexture&&function(t){const e=a.render.frame;d.get(t)!==e&&(d.set(t,e),t.update())}(t),t.version>0&&s.__version!==t.version){const i=t.image;if(void 0===i);else if(!1!==i.complete)return void N(s,t,e)}i.activeTexture(33984+e),i.bindTexture(3553,s.__webglTexture)}function C(e,s){const a=n.get(e);e.version>0&&a.__version!==e.version?function(e,n,s){if(6!==n.image.length)return;I(e,n),i.activeTexture(33984+s),i.bindTexture(34067,e.__webglTexture),t.pixelStorei(37440,n.flipY),t.pixelStorei(37441,n.premultiplyAlpha),t.pixelStorei(3317,n.unpackAlignment),t.pixelStorei(37443,0);const a=n&&(n.isCompressedTexture||n.image[0].isCompressedTexture),h=n.image[0]&&n.image[0].isDataTexture,c=[];for(let t=0;t<6;t++)c[t]=a||h?h?n.image[t].image:n.image[t]:_(n.image[t],!1,!0,l);const u=g(c[0])||o,d=r.convert(n.format),p=r.convert(n.type),f=x(n.internalFormat,d,p,n.encoding);let m;if(z(34067,n,u),a)for(let t=0;t<6;t++){m=c[t].mipmaps;for(let e=0;e<m.length;e++){const s=m[e];n.format!==Yt&&n.format!==Jt?null!==d&&i.compressedTexImage2D(34069+t,e,f,s.width,s.height,0,s.data):i.texImage2D(34069+t,e,f,s.width,s.height,0,d,p,s.data)}}else{m=n.mipmaps;for(let t=0;t<6;t++)if(h){i.texImage2D(34069+t,0,f,c[t].width,c[t].height,0,d,p,c[t].data);for(let e=0;e<m.length;e++){const n=m[e].image[t].image;i.texImage2D(34069+t,e+1,f,n.width,n.height,0,d,p,n.data)}}else{i.texImage2D(34069+t,0,f,d,p,c[t]);for(let e=0;e<m.length;e++){const n=m[e];i.texImage2D(34069+t,e+1,f,d,p,n.image[t])}}}y(n,u)&&v(34067),e.__version=n.version,n.onUpdate&&n.onUpdate(n)}(a,e,s):(i.activeTexture(33984+s),i.bindTexture(34067,a.__webglTexture))}const A={[Tt]:10497,[Ct]:33071,[At]:33648},E={[Et]:9728,[zt]:9984,[It]:9986,[Nt]:9729,[Lt]:9985,[Pt]:9987};function z(i,r,a){if(a?(t.texParameteri(i,10242,A[r.wrapS]),t.texParameteri(i,10243,A[r.wrapT]),32879!==i&&35866!==i||t.texParameteri(i,32882,A[r.wrapR]),t.texParameteri(i,10240,E[r.magFilter]),t.texParameteri(i,10241,E[r.minFilter])):(t.texParameteri(i,10242,33071),t.texParameteri(i,10243,33071),32879!==i&&35866!==i||t.texParameteri(i,32882,33071),r.wrapS!==Ct||r.wrapT,t.texParameteri(i,10240,w(r.magFilter)),t.texParameteri(i,10241,w(r.minFilter)),r.minFilter!==Et&&r.minFilter),!0===e.has("EXT_texture_filter_anisotropic")){const a=e.get("EXT_texture_filter_anisotropic");if(r.type===Bt&&!1===e.has("OES_texture_float_linear"))return;if(!1===o&&r.type===Vt&&!1===e.has("OES_texture_half_float_linear"))return;(r.anisotropy>1||n.get(r).__currentAnisotropy)&&(t.texParameterf(i,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(r.anisotropy,s.getMaxAnisotropy())),n.get(r).__currentAnisotropy=r.anisotropy)}}function I(e,i){void 0===e.__webglInit&&(e.__webglInit=!0,i.addEventListener("dispose",b),e.__webglTexture=t.createTexture(),a.memory.textures++)}function N(e,n,s){let a=3553;n.isDataTexture2DArray&&(a=35866),n.isDataTexture3D&&(a=32879),I(e,n),i.activeTexture(33984+s),i.bindTexture(a,e.__webglTexture),t.pixelStorei(37440,n.flipY),t.pixelStorei(37441,n.premultiplyAlpha),t.pixelStorei(3317,n.unpackAlignment),t.pixelStorei(37443,0);const l=function(t){return!o&&(t.wrapS!==Ct||t.wrapT!==Ct||t.minFilter!==Et&&t.minFilter!==Nt)}(n)&&!1===g(n.image),c=_(n.image,l,!1,h),u=g(c)||o,d=r.convert(n.format);let p,f=r.convert(n.type),m=x(n.internalFormat,d,f,n.encoding);z(a,n,u);const w=n.mipmaps;if(n.isDepthTexture)m=6402,o?m=n.type===Bt?36012:n.type===Ut?33190:n.type===jt?35056:33189:n.type,n.format===Kt&&6402===m&&n.type!==Rt&&n.type!==Ut&&(n.type=Rt,f=r.convert(n.type)),n.format===Qt&&6402===m&&(m=34041,n.type!==jt&&(n.type=jt,f=r.convert(n.type))),i.texImage2D(3553,0,m,c.width,c.height,0,d,f,null);else if(n.isDataTexture)if(w.length>0&&u){for(let t=0,e=w.length;t<e;t++)p=w[t],i.texImage2D(3553,t,m,p.width,p.height,0,d,f,p.data);n.generateMipmaps=!1}else i.texImage2D(3553,0,m,c.width,c.height,0,d,f,c.data);else if(n.isCompressedTexture)for(let t=0,e=w.length;t<e;t++)p=w[t],n.format!==Yt&&n.format!==Jt?null!==d&&i.compressedTexImage2D(3553,t,m,p.width,p.height,0,p.data):i.texImage2D(3553,t,m,p.width,p.height,0,d,f,p.data);else if(n.isDataTexture2DArray)i.texImage3D(35866,0,m,c.width,c.height,c.depth,0,d,f,c.data);else if(n.isDataTexture3D)i.texImage3D(32879,0,m,c.width,c.height,c.depth,0,d,f,c.data);else{const t=function(t,e,i){return!0===y(t,i)?Math.log2(Math.max(e.width,e.height))+1:t.mipmaps.length>0?t.mipmaps.length:1}(n,c,u),s=o&&!0!==n.isVideoTexture,r=void 0===e.__version;if(w.length>0&&u){s&&r&&i.texStorage2D(3553,t,m,w[0].width,w[0].height);for(let t=0,e=w.length;t<e;t++)p=w[t],s?i.texSubImage2D(3553,t,0,0,d,f,p):i.texImage2D(3553,t,m,d,f,p);n.generateMipmaps=!1}else s?(r&&i.texStorage2D(3553,t,m,c.width,c.height),i.texSubImage2D(3553,0,0,0,d,f,c)):i.texImage2D(3553,0,m,d,f,c)}y(n,u)&&v(a),e.__version=n.version,n.onUpdate&&n.onUpdate(n)}function L(e,s,a,o,l){const h=r.convert(a.format),c=r.convert(a.type),d=x(a.internalFormat,h,c,a.encoding);n.get(s).__hasExternalTextures||(32879===l||35866===l?i.texImage3D(l,0,d,s.width,s.height,s.depth,0,h,c,null):i.texImage2D(l,0,d,s.width,s.height,0,h,c,null)),i.bindFramebuffer(36160,e),s.useRenderToTexture?u.framebufferTexture2DMultisampleEXT(36160,o,l,n.get(a).__webglTexture,0,D(s)):t.framebufferTexture2D(36160,o,l,n.get(a).__webglTexture,0),i.bindFramebuffer(36160,null)}function P(e,i,n){if(t.bindRenderbuffer(36161,e),i.depthBuffer&&!i.stencilBuffer){let s=33189;if(n||i.useRenderToTexture){const e=i.depthTexture;e&&e.isDepthTexture&&(e.type===Bt?s=36012:e.type===Ut&&(s=33190));const n=D(i);i.useRenderToTexture?u.renderbufferStorageMultisampleEXT(36161,n,s,i.width,i.height):t.renderbufferStorageMultisample(36161,n,s,i.width,i.height)}else t.renderbufferStorage(36161,s,i.width,i.height);t.framebufferRenderbuffer(36160,36096,36161,e)}else if(i.depthBuffer&&i.stencilBuffer){const s=D(i);n&&i.useRenderbuffer?t.renderbufferStorageMultisample(36161,s,35056,i.width,i.height):i.useRenderToTexture?u.renderbufferStorageMultisampleEXT(36161,s,35056,i.width,i.height):t.renderbufferStorage(36161,34041,i.width,i.height),t.framebufferRenderbuffer(36160,33306,36161,e)}else{const e=!0===i.isWebGLMultipleRenderTargets?i.texture[0]:i.texture,s=r.convert(e.format),a=r.convert(e.type),o=x(e.internalFormat,s,a,e.encoding),l=D(i);n&&i.useRenderbuffer?t.renderbufferStorageMultisample(36161,l,o,i.width,i.height):i.useRenderToTexture?u.renderbufferStorageMultisampleEXT(36161,l,o,i.width,i.height):t.renderbufferStorage(36161,o,i.width,i.height)}t.bindRenderbuffer(36161,null)}function F(e){const s=n.get(e),r=!0===e.isWebGLCubeRenderTarget;if(e.depthTexture&&!s.__autoAllocateDepthBuffer){if(r)throw new Error("target.depthTexture not supported in Cube render targets");!function(e,s){if(s&&s.isWebGLCubeRenderTarget)throw new Error("Depth Texture with cube render targets is not supported");if(i.bindFramebuffer(36160,e),!s.depthTexture||!s.depthTexture.isDepthTexture)throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture");n.get(s.depthTexture).__webglTexture&&s.depthTexture.image.width===s.width&&s.depthTexture.image.height===s.height||(s.depthTexture.image.width=s.width,s.depthTexture.image.height=s.height,s.depthTexture.needsUpdate=!0),T(s.depthTexture,0);const r=n.get(s.depthTexture).__webglTexture,a=D(s);if(s.depthTexture.format===Kt)s.useRenderToTexture?u.framebufferTexture2DMultisampleEXT(36160,36096,3553,r,0,a):t.framebufferTexture2D(36160,36096,3553,r,0);else{if(s.depthTexture.format!==Qt)throw new Error("Unknown depthTexture format");s.useRenderToTexture?u.framebufferTexture2DMultisampleEXT(36160,33306,3553,r,0,a):t.framebufferTexture2D(36160,33306,3553,r,0)}}(s.__webglFramebuffer,e)}else if(r){s.__webglDepthbuffer=[];for(let n=0;n<6;n++)i.bindFramebuffer(36160,s.__webglFramebuffer[n]),s.__webglDepthbuffer[n]=t.createRenderbuffer(),P(s.__webglDepthbuffer[n],e,!1)}else i.bindFramebuffer(36160,s.__webglFramebuffer),s.__webglDepthbuffer=t.createRenderbuffer(),P(s.__webglDepthbuffer,e,!1);i.bindFramebuffer(36160,null)}function D(t){return o&&(t.useRenderbuffer||t.useRenderToTexture)?Math.min(c,t.samples):0}this.allocateTextureUnit=function(){const t=M;return M+=1,t},this.resetTextureUnits=function(){M=0},this.setTexture2D=T,this.setTexture2DArray=function(t,e){const s=n.get(t);t.version>0&&s.__version!==t.version?N(s,t,e):(i.activeTexture(33984+e),i.bindTexture(35866,s.__webglTexture))},this.setTexture3D=function(t,e){const s=n.get(t);t.version>0&&s.__version!==t.version?N(s,t,e):(i.activeTexture(33984+e),i.bindTexture(32879,s.__webglTexture))},this.setTextureCube=C,this.rebindTextures=function(t,e,i){const s=n.get(t);void 0!==e&&L(s.__webglFramebuffer,t,t.texture,36064,3553),void 0!==i&&F(t)},this.setupRenderTarget=function(e){const l=e.texture,h=n.get(e),c=n.get(l);e.addEventListener("dispose",S),!0!==e.isWebGLMultipleRenderTargets&&(void 0===c.__webglTexture&&(c.__webglTexture=t.createTexture()),c.__version=l.version,a.memory.textures++);const u=!0===e.isWebGLCubeRenderTarget,d=!0===e.isWebGLMultipleRenderTargets,p=l.isDataTexture3D||l.isDataTexture2DArray,f=g(e)||o;if(!o||l.format!==Jt||l.type!==Bt&&l.type!==Vt||(l.format=Yt),u){h.__webglFramebuffer=[];for(let e=0;e<6;e++)h.__webglFramebuffer[e]=t.createFramebuffer()}else if(h.__webglFramebuffer=t.createFramebuffer(),d){if(s.drawBuffers){const i=e.texture;for(let e=0,s=i.length;e<s;e++){const s=n.get(i[e]);void 0===s.__webglTexture&&(s.__webglTexture=t.createTexture(),a.memory.textures++)}}}else if(e.useRenderbuffer&&o){h.__webglMultisampledFramebuffer=t.createFramebuffer(),h.__webglColorRenderbuffer=t.createRenderbuffer(),t.bindRenderbuffer(36161,h.__webglColorRenderbuffer);const n=r.convert(l.format),s=r.convert(l.type),a=x(l.internalFormat,n,s,l.encoding),o=D(e);t.renderbufferStorageMultisample(36161,o,a,e.width,e.height),i.bindFramebuffer(36160,h.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(36160,36064,36161,h.__webglColorRenderbuffer),t.bindRenderbuffer(36161,null),e.depthBuffer&&(h.__webglDepthRenderbuffer=t.createRenderbuffer(),P(h.__webglDepthRenderbuffer,e,!0)),i.bindFramebuffer(36160,null)}if(u){i.bindTexture(34067,c.__webglTexture),z(34067,l,f);for(let t=0;t<6;t++)L(h.__webglFramebuffer[t],e,l,36064,34069+t);y(l,f)&&v(34067),i.unbindTexture()}else if(d){const t=e.texture;for(let s=0,r=t.length;s<r;s++){const r=t[s],a=n.get(r);i.bindTexture(3553,a.__webglTexture),z(3553,r,f),L(h.__webglFramebuffer,e,r,36064+s,3553),y(r,f)&&v(3553)}i.unbindTexture()}else{let t=3553;p&&o&&(t=l.isDataTexture3D?32879:35866),i.bindTexture(t,c.__webglTexture),z(t,l,f),L(h.__webglFramebuffer,e,l,36064,t),y(l,f)&&v(t),i.unbindTexture()}e.depthBuffer&&F(e)},this.updateRenderTargetMipmap=function(t){const e=g(t)||o,s=!0===t.isWebGLMultipleRenderTargets?t.texture:[t.texture];for(let r=0,a=s.length;r<a;r++){const a=s[r];if(y(a,e)){const e=t.isWebGLCubeRenderTarget?34067:3553,s=n.get(a).__webglTexture;i.bindTexture(e,s),v(e),i.unbindTexture()}}},this.updateMultisampleRenderTarget=function(e){if(e.useRenderbuffer&&o){const s=e.width,r=e.height;let a=16384;const o=[36064],l=e.stencilBuffer?33306:36096;e.depthBuffer&&o.push(l),e.ignoreDepthForMultisampleCopy||(e.depthBuffer&&(a|=256),e.stencilBuffer&&(a|=1024));const h=n.get(e);i.bindFramebuffer(36008,h.__webglMultisampledFramebuffer),i.bindFramebuffer(36009,h.__webglFramebuffer),e.ignoreDepthForMultisampleCopy&&(t.invalidateFramebuffer(36008,[l]),t.invalidateFramebuffer(36009,[l])),t.blitFramebuffer(0,0,s,r,0,0,s,r,a,9728),t.invalidateFramebuffer(36008,o),i.bindFramebuffer(36008,null),i.bindFramebuffer(36009,h.__webglMultisampledFramebuffer)}},this.setupDepthRenderbuffer=F,this.setupFrameBufferTexture=L,this.safeSetTexture2D=function(t,e){t&&t.isWebGLRenderTarget&&(t=t.texture),T(t,e)},this.safeSetTextureCube=function(t,e){t&&t.isWebGLCubeRenderTarget&&(t=t.texture),C(t,e)}}function Vo(t,e,i){const n=i.isWebGL2;return{convert:function(t){let i;if(t===Ft)return 5121;if(t===Gt)return 32819;if(t===Wt)return 32820;if(t===Ht)return 33635;if(t===Dt)return 5120;if(t===Ot)return 5122;if(t===Rt)return 5123;if(t===kt)return 5124;if(t===Ut)return 5125;if(t===Bt)return 5126;if(t===Vt)return n?5131:(i=e.get("OES_texture_half_float"),null!==i?i.HALF_FLOAT_OES:null);if(t===qt)return 6406;if(t===Jt)return 6407;if(t===Yt)return 6408;if(t===Xt)return 6409;if(t===Zt)return 6410;if(t===Kt)return 6402;if(t===Qt)return 34041;if(t===te)return 6403;if(t===ee)return 36244;if(t===ie)return 33319;if(t===ne)return 33320;if(t===se)return 36248;if(t===re)return 36249;if(t===ae||t===oe||t===le||t===he){if(i=e.get("WEBGL_compressed_texture_s3tc"),null===i)return null;if(t===ae)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(t===oe)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(t===le)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(t===he)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(t===ce||t===ue||t===de||t===pe){if(i=e.get("WEBGL_compressed_texture_pvrtc"),null===i)return null;if(t===ce)return i.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(t===ue)return i.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(t===de)return i.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(t===pe)return i.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(t===fe)return i=e.get("WEBGL_compressed_texture_etc1"),null!==i?i.COMPRESSED_RGB_ETC1_WEBGL:null;if((t===me||t===_e)&&(i=e.get("WEBGL_compressed_texture_etc"),null!==i)){if(t===me)return i.COMPRESSED_RGB8_ETC2;if(t===_e)return i.COMPRESSED_RGBA8_ETC2_EAC}return t===ge||t===ye||t===ve||t===xe||t===we||t===be||t===Se||t===Me||t===Te||t===Ce||t===Ae||t===Ee||t===ze||t===Ie||t===Le||t===Pe||t===Fe||t===De||t===Oe||t===Re||t===ke||t===Ue||t===Be||t===Ve||t===Ge||t===We||t===He||t===je?(i=e.get("WEBGL_compressed_texture_astc"),null!==i?t:null):t===Ne?(i=e.get("EXT_texture_compression_bptc"),null!==i?t:null):t===jt?n?34042:(i=e.get("WEBGL_depth_texture"),null!==i?i.UNSIGNED_INT_24_8_WEBGL:null):void 0}}}class Go extends js{constructor(t=[]){super(),this.cameras=t}}Go.prototype.isArrayCamera=!0;class Wo extends kn{constructor(){super(),this.type="Group"}}Wo.prototype.isGroup=!0;const Ho={type:"move"};class jo{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return null===this._hand&&(this._hand=new Wo,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return null===this._targetRay&&(this._targetRay=new Wo,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new Di,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new Di),this._targetRay}getGripSpace(){return null===this._grip&&(this._grip=new Wo,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new Di,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new Di),this._grip}dispatchEvent(t){return null!==this._targetRay&&this._targetRay.dispatchEvent(t),null!==this._grip&&this._grip.dispatchEvent(t),null!==this._hand&&this._hand.dispatchEvent(t),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),null!==this._targetRay&&(this._targetRay.visible=!1),null!==this._grip&&(this._grip.visible=!1),null!==this._hand&&(this._hand.visible=!1),this}update(t,e,i){let n=null,s=null,r=null;const a=this._targetRay,o=this._grip,l=this._hand;if(t&&"visible-blurred"!==e.session.visibilityState)if(null!==a&&(n=e.getPose(t.targetRaySpace,i),null!==n&&(a.matrix.fromArray(n.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),n.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(n.linearVelocity)):a.hasLinearVelocity=!1,n.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(n.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(Ho))),l&&t.hand){r=!0;for(const n of t.hand.values()){const t=e.getJointPose(n,i);if(void 0===l.joints[n.jointName]){const t=new Wo;t.matrixAutoUpdate=!1,t.visible=!1,l.joints[n.jointName]=t,l.add(t)}const s=l.joints[n.jointName];null!==t&&(s.matrix.fromArray(t.transform.matrix),s.matrix.decompose(s.position,s.rotation,s.scale),s.jointRadius=t.radius),s.visible=null!==t}const n=l.joints["index-finger-tip"],s=l.joints["thumb-tip"],a=n.position.distanceTo(s.position),o=.02,h=.005;l.inputState.pinching&&a>o+h?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&a<=o-h&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else null!==o&&t.gripSpace&&(s=e.getPose(t.gripSpace,i),null!==s&&(o.matrix.fromArray(s.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),s.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(s.linearVelocity)):o.hasLinearVelocity=!1,s.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(s.angularVelocity)):o.hasAngularVelocity=!1));return null!==a&&(a.visible=null!==n),null!==o&&(o.visible=null!==s),null!==l&&(l.visible=null!==r),this}}class qo extends zi{constructor(t,e,i,n,s,r,a,o,l,h){if((h=void 0!==h?h:Kt)!==Kt&&h!==Qt)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===i&&h===Kt&&(i=Rt),void 0===i&&h===Qt&&(i=jt),super(null,n,s,r,a,o,h,i,l),this.image={width:t,height:e},this.magFilter=void 0!==a?a:Et,this.minFilter=void 0!==o?o:Et,this.flipY=!1,this.generateMipmaps=!1}}qo.prototype.isDepthTexture=!0;class Jo extends di{constructor(t,e){super();const i=this;let n=null,s=1,r=null,a="local-floor";const o=t.extensions.has("WEBGL_multisampled_render_to_texture");let l=null,h=null,c=null,u=null,d=!1,p=null;const f=e.getContextAttributes();let m=null,_=null;const g=[],y=new Map,v=new js;v.layers.enable(1),v.viewport=new Ni;const x=new js;x.layers.enable(2),x.viewport=new Ni;const w=[v,x],b=new Go;b.layers.enable(1),b.layers.enable(2);let S=null,M=null;function T(t){const e=y.get(t.inputSource);e&&e.dispatchEvent({type:t.type,data:t.inputSource})}function C(){y.forEach((function(t,e){t.disconnect(e)})),y.clear(),S=null,M=null,t.setRenderTarget(m),u=null,c=null,h=null,n=null,_=null,L.stop(),i.isPresenting=!1,i.dispatchEvent({type:"sessionend"})}function A(t){const e=n.inputSources;for(let t=0;t<g.length;t++)y.set(e[t],g[t]);for(let e=0;e<t.removed.length;e++){const i=t.removed[e],n=y.get(i);n&&(n.dispatchEvent({type:"disconnected",data:i}),y.delete(i))}for(let e=0;e<t.added.length;e++){const i=t.added[e],n=y.get(i);n&&n.dispatchEvent({type:"connected",data:i})}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(t){let e=g[t];return void 0===e&&(e=new jo,g[t]=e),e.getTargetRaySpace()},this.getControllerGrip=function(t){let e=g[t];return void 0===e&&(e=new jo,g[t]=e),e.getGripSpace()},this.getHand=function(t){let e=g[t];return void 0===e&&(e=new jo,g[t]=e),e.getHandSpace()},this.setFramebufferScaleFactor=function(t){s=t,i.isPresenting},this.setReferenceSpaceType=function(t){a=t,i.isPresenting},this.getReferenceSpace=function(){return r},this.getBaseLayer=function(){return null!==c?c:u},this.getBinding=function(){return h},this.getFrame=function(){return p},this.getSession=function(){return n},this.setSession=async function(l){if(n=l,null!==n){if(m=t.getRenderTarget(),n.addEventListener("select",T),n.addEventListener("selectstart",T),n.addEventListener("selectend",T),n.addEventListener("squeeze",T),n.addEventListener("squeezestart",T),n.addEventListener("squeezeend",T),n.addEventListener("end",C),n.addEventListener("inputsourceschange",A),!0!==f.xrCompatible&&await e.makeXRCompatible(),void 0===n.renderState.layers||!1===t.capabilities.isWebGL2){const t={antialias:void 0!==n.renderState.layers||f.antialias,alpha:f.alpha,depth:f.depth,stencil:f.stencil,framebufferScaleFactor:s};u=new XRWebGLLayer(n,e,t),n.updateRenderState({baseLayer:u}),_=new Li(u.framebufferWidth,u.framebufferHeight)}else{d=f.antialias;let t=null,i=null,r=null;f.depth&&(r=f.stencil?35056:33189,t=f.stencil?Qt:Kt,i=f.stencil?jt:Rt);const a={colorFormat:f.alpha||d?32856:32849,depthFormat:r,scaleFactor:s};h=new XRWebGLBinding(n,e),c=h.createProjectionLayer(a),n.updateRenderState({layers:[c]}),_=d?new Pi(c.textureWidth,c.textureHeight,{format:Yt,type:Ft,depthTexture:new qo(c.textureWidth,c.textureHeight,i,void 0,void 0,void 0,void 0,void 0,void 0,t),stencilBuffer:f.stencil,ignoreDepth:c.ignoreDepthValues,useRenderToTexture:o}):new Li(c.textureWidth,c.textureHeight,{format:f.alpha?Yt:Jt,type:Ft,depthTexture:new qo(c.textureWidth,c.textureHeight,i,void 0,void 0,void 0,void 0,void 0,void 0,t),stencilBuffer:f.stencil,ignoreDepth:c.ignoreDepthValues})}this.setFoveation(0),r=await n.requestReferenceSpace(a),L.setContext(n),L.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}};const E=new Di,z=new Di;function I(t,e){null===e?t.matrixWorld.copy(t.matrix):t.matrixWorld.multiplyMatrices(e.matrixWorld,t.matrix),t.matrixWorldInverse.copy(t.matrixWorld).invert()}this.updateCamera=function(t){if(null===n)return;b.near=x.near=v.near=t.near,b.far=x.far=v.far=t.far,S===b.near&&M===b.far||(n.updateRenderState({depthNear:b.near,depthFar:b.far}),S=b.near,M=b.far);const e=t.parent,i=b.cameras;I(b,e);for(let t=0;t<i.length;t++)I(i[t],e);b.matrixWorld.decompose(b.position,b.quaternion,b.scale),t.position.copy(b.position),t.quaternion.copy(b.quaternion),t.scale.copy(b.scale),t.matrix.copy(b.matrix),t.matrixWorld.copy(b.matrixWorld);const s=t.children;for(let t=0,e=s.length;t<e;t++)s[t].updateMatrixWorld(!0);2===i.length?function(t,e,i){E.setFromMatrixPosition(e.matrixWorld),z.setFromMatrixPosition(i.matrixWorld);const n=E.distanceTo(z),s=e.projectionMatrix.elements,r=i.projectionMatrix.elements,a=s[14]/(s[10]-1),o=s[14]/(s[10]+1),l=(s[9]+1)/s[5],h=(s[9]-1)/s[5],c=(s[8]-1)/s[0],u=(r[8]+1)/r[0],d=a*c,p=a*u,f=n/(-c+u),m=f*-c;e.matrixWorld.decompose(t.position,t.quaternion,t.scale),t.translateX(m),t.translateZ(f),t.matrixWorld.compose(t.position,t.quaternion,t.scale),t.matrixWorldInverse.copy(t.matrixWorld).invert();const _=a+f,g=o+f,y=d-m,v=p+(n-m),x=l*o/g*_,w=h*o/g*_;t.projectionMatrix.makePerspective(y,v,x,w,_,g)}(b,v,x):b.projectionMatrix.copy(v.projectionMatrix)},this.getCamera=function(){return b},this.getFoveation=function(){return null!==c?c.fixedFoveation:null!==u?u.fixedFoveation:void 0},this.setFoveation=function(t){null!==c&&(c.fixedFoveation=t),null!==u&&void 0!==u.fixedFoveation&&(u.fixedFoveation=t)};let N=null;const L=new nr;L.setAnimationLoop((function(e,i){if(l=i.getViewerPose(r),p=i,null!==l){const e=l.views;null!==u&&(t.setRenderTargetFramebuffer(_,u.framebuffer),t.setRenderTarget(_));let i=!1;e.length!==b.cameras.length&&(b.cameras.length=0,i=!0);for(let n=0;n<e.length;n++){const s=e[n];let r=null;if(null!==u)r=u.getViewport(s);else{const e=h.getViewSubImage(c,s);r=e.viewport,0===n&&(t.setRenderTargetTextures(_,e.colorTexture,c.ignoreDepthValues?void 0:e.depthStencilTexture),t.setRenderTarget(_))}const a=w[n];a.matrix.fromArray(s.transform.matrix),a.projectionMatrix.fromArray(s.projectionMatrix),a.viewport.set(r.x,r.y,r.width,r.height),0===n&&b.matrix.copy(a.matrix),!0===i&&b.cameras.push(a)}}const s=n.inputSources;for(let t=0;t<g.length;t++){const e=g[t],n=s[t];e.update(n,i,r)}N&&N(e,i),p=null})),this.setAnimationLoop=function(t){N=t},this.dispose=function(){}}}function Yo(t){function e(e,i){e.opacity.value=i.opacity,i.color&&e.diffuse.value.copy(i.color),i.emissive&&e.emissive.value.copy(i.emissive).multiplyScalar(i.emissiveIntensity),i.map&&(e.map.value=i.map),i.alphaMap&&(e.alphaMap.value=i.alphaMap),i.specularMap&&(e.specularMap.value=i.specularMap),i.alphaTest>0&&(e.alphaTest.value=i.alphaTest);const n=t.get(i).envMap;let s,r;n&&(e.envMap.value=n,e.flipEnvMap.value=n.isCubeTexture&&!1===n.isRenderTargetTexture?-1:1,e.reflectivity.value=i.reflectivity,e.ior.value=i.ior,e.refractionRatio.value=i.refractionRatio),i.lightMap&&(e.lightMap.value=i.lightMap,e.lightMapIntensity.value=i.lightMapIntensity),i.aoMap&&(e.aoMap.value=i.aoMap,e.aoMapIntensity.value=i.aoMapIntensity),i.map?s=i.map:i.specularMap?s=i.specularMap:i.displacementMap?s=i.displacementMap:i.normalMap?s=i.normalMap:i.bumpMap?s=i.bumpMap:i.roughnessMap?s=i.roughnessMap:i.metalnessMap?s=i.metalnessMap:i.alphaMap?s=i.alphaMap:i.emissiveMap?s=i.emissiveMap:i.clearcoatMap?s=i.clearcoatMap:i.clearcoatNormalMap?s=i.clearcoatNormalMap:i.clearcoatRoughnessMap?s=i.clearcoatRoughnessMap:i.specularIntensityMap?s=i.specularIntensityMap:i.specularColorMap?s=i.specularColorMap:i.transmissionMap?s=i.transmissionMap:i.thicknessMap?s=i.thicknessMap:i.sheenColorMap?s=i.sheenColorMap:i.sheenRoughnessMap&&(s=i.sheenRoughnessMap),void 0!==s&&(s.isWebGLRenderTarget&&(s=s.texture),!0===s.matrixAutoUpdate&&s.updateMatrix(),e.uvTransform.value.copy(s.matrix)),i.aoMap?r=i.aoMap:i.lightMap&&(r=i.lightMap),void 0!==r&&(r.isWebGLRenderTarget&&(r=r.texture),!0===r.matrixAutoUpdate&&r.updateMatrix(),e.uv2Transform.value.copy(r.matrix))}function i(e,i){e.roughness.value=i.roughness,e.metalness.value=i.metalness,i.roughnessMap&&(e.roughnessMap.value=i.roughnessMap),i.metalnessMap&&(e.metalnessMap.value=i.metalnessMap),i.emissiveMap&&(e.emissiveMap.value=i.emissiveMap),i.bumpMap&&(e.bumpMap.value=i.bumpMap,e.bumpScale.value=i.bumpScale,i.side===L&&(e.bumpScale.value*=-1)),i.normalMap&&(e.normalMap.value=i.normalMap,e.normalScale.value.copy(i.normalScale),i.side===L&&e.normalScale.value.negate()),i.displacementMap&&(e.displacementMap.value=i.displacementMap,e.displacementScale.value=i.displacementScale,e.displacementBias.value=i.displacementBias),t.get(i).envMap&&(e.envMapIntensity.value=i.envMapIntensity)}return{refreshFogUniforms:function(t,e){t.fogColor.value.copy(e.color),e.isFog?(t.fogNear.value=e.near,t.fogFar.value=e.far):e.isFogExp2&&(t.fogDensity.value=e.density)},refreshMaterialUniforms:function(t,n,s,r,a){n.isMeshBasicMaterial?e(t,n):n.isMeshLambertMaterial?(e(t,n),function(t,e){e.emissiveMap&&(t.emissiveMap.value=e.emissiveMap)}(t,n)):n.isMeshToonMaterial?(e(t,n),function(t,e){e.gradientMap&&(t.gradientMap.value=e.gradientMap),e.emissiveMap&&(t.emissiveMap.value=e.emissiveMap),e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale,e.side===L&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===L&&t.normalScale.value.negate()),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}(t,n)):n.isMeshPhongMaterial?(e(t,n),function(t,e){t.specular.value.copy(e.specular),t.shininess.value=Math.max(e.shininess,1e-4),e.emissiveMap&&(t.emissiveMap.value=e.emissiveMap),e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale,e.side===L&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===L&&t.normalScale.value.negate()),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}(t,n)):n.isMeshStandardMaterial?(e(t,n),n.isMeshPhysicalMaterial?function(t,e,n){i(t,e),t.ior.value=e.ior,e.sheen>0&&(t.sheenColor.value.copy(e.sheenColor).multiplyScalar(e.sheen),t.sheenRoughness.value=e.sheenRoughness,e.sheenColorMap&&(t.sheenColorMap.value=e.sheenColorMap),e.sheenRoughnessMap&&(t.sheenRoughnessMap.value=e.sheenRoughnessMap)),e.clearcoat>0&&(t.clearcoat.value=e.clearcoat,t.clearcoatRoughness.value=e.clearcoatRoughness,e.clearcoatMap&&(t.clearcoatMap.value=e.clearcoatMap),e.clearcoatRoughnessMap&&(t.clearcoatRoughnessMap.value=e.clearcoatRoughnessMap),e.clearcoatNormalMap&&(t.clearcoatNormalScale.value.copy(e.clearcoatNormalScale),t.clearcoatNormalMap.value=e.clearcoatNormalMap,e.side===L&&t.clearcoatNormalScale.value.negate())),e.transmission>0&&(t.transmission.value=e.transmission,t.transmissionSamplerMap.value=n.texture,t.transmissionSamplerSize.value.set(n.width,n.height),e.transmissionMap&&(t.transmissionMap.value=e.transmissionMap),t.thickness.value=e.thickness,e.thicknessMap&&(t.thicknessMap.value=e.thicknessMap),t.attenuationDistance.value=e.attenuationDistance,t.attenuationColor.value.copy(e.attenuationColor)),t.specularIntensity.value=e.specularIntensity,t.specularColor.value.copy(e.specularColor),e.specularIntensityMap&&(t.specularIntensityMap.value=e.specularIntensityMap),e.specularColorMap&&(t.specularColorMap.value=e.specularColorMap)}(t,n,a):i(t,n)):n.isMeshMatcapMaterial?(e(t,n),function(t,e){e.matcap&&(t.matcap.value=e.matcap),e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale,e.side===L&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===L&&t.normalScale.value.negate()),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}(t,n)):n.isMeshDepthMaterial?(e(t,n),function(t,e){e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}(t,n)):n.isMeshDistanceMaterial?(e(t,n),function(t,e){e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias),t.referencePosition.value.copy(e.referencePosition),t.nearDistance.value=e.nearDistance,t.farDistance.value=e.farDistance}(t,n)):n.isMeshNormalMaterial?(e(t,n),function(t,e){e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale,e.side===L&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===L&&t.normalScale.value.negate()),e.displacementMap&&(t.displacementMap.value=e.displacementMap,t.displacementScale.value=e.displacementScale,t.displacementBias.value=e.displacementBias)}(t,n)):n.isLineBasicMaterial?(function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity}(t,n),n.isLineDashedMaterial&&function(t,e){t.dashSize.value=e.dashSize,t.totalSize.value=e.dashSize+e.gapSize,t.scale.value=e.scale}(t,n)):n.isPointsMaterial?function(t,e,i,n){let s;t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.size.value=e.size*i,t.scale.value=.5*n,e.map&&(t.map.value=e.map),e.alphaMap&&(t.alphaMap.value=e.alphaMap),e.alphaTest>0&&(t.alphaTest.value=e.alphaTest),e.map?s=e.map:e.alphaMap&&(s=e.alphaMap),void 0!==s&&(!0===s.matrixAutoUpdate&&s.updateMatrix(),t.uvTransform.value.copy(s.matrix))}(t,n,s,r):n.isSpriteMaterial?function(t,e){let i;t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.rotation.value=e.rotation,e.map&&(t.map.value=e.map),e.alphaMap&&(t.alphaMap.value=e.alphaMap),e.alphaTest>0&&(t.alphaTest.value=e.alphaTest),e.map?i=e.map:e.alphaMap&&(i=e.alphaMap),void 0!==i&&(!0===i.matrixAutoUpdate&&i.updateMatrix(),t.uvTransform.value.copy(i.matrix))}(t,n):n.isShadowMaterial?(t.color.value.copy(n.color),t.opacity.value=n.opacity):n.isShaderMaterial&&(n.uniformsNeedUpdate=!1)}}}function Xo(t={}){const e=void 0!==t.canvas?t.canvas:function(){const t=Ti("canvas");return t.style.display="block",t}(),i=void 0!==t.context?t.context:null,n=void 0!==t.alpha&&t.alpha,s=void 0===t.depth||t.depth,r=void 0===t.stencil||t.stencil,a=void 0!==t.antialias&&t.antialias,o=void 0===t.premultipliedAlpha||t.premultipliedAlpha,l=void 0!==t.preserveDrawingBuffer&&t.preserveDrawingBuffer,h=void 0!==t.powerPreference?t.powerPreference:"default",c=void 0!==t.failIfMajorPerformanceCaveat&&t.failIfMajorPerformanceCaveat;let u=null,d=null;const p=[],f=[];this.domElement=e,this.debug={checkShaderErrors:!0},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.gammaFactor=2,this.outputEncoding=Ke,this.physicallyCorrectLights=!1,this.toneMapping=pt,this.toneMappingExposure=1;const m=this;let _=!1,g=0,y=0,v=null,x=-1,w=null;const b=new Ni,S=new Ni;let T=null,C=e.width,A=e.height,E=1,z=null,I=null;const F=new Ni(0,0,C,A),D=new Ni(0,0,C,A);let O=!1;const R=[],k=new ir;let U=!1,B=!1,V=null;const G=new pn,W=new Di,H={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};function j(){return null===v?E:1}let q,J,Y,X,Z,$,K,Q,tt,et,it,nt,st,rt,at,ot,lt,ht,ct,ut,dt,ft,mt,_t=i;function gt(t,i){for(let n=0;n<t.length;n++){const s=t[n],r=e.getContext(s,i);if(null!==r)return r}return null}try{const t={alpha:n,depth:s,stencil:r,antialias:a,premultipliedAlpha:o,preserveDrawingBuffer:l,powerPreference:h,failIfMajorPerformanceCaveat:c};if("setAttribute"in e&&e.setAttribute("data-engine",`three.js r${M}`),e.addEventListener("webglcontextlost",xt,!1),e.addEventListener("webglcontextrestored",wt,!1),null===_t){const e=["webgl2","webgl","experimental-webgl"];if(!0===m.isWebGL1Renderer&&e.shift(),_t=gt(e,t),null===_t)throw gt(e)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}void 0===_t.getShaderPrecisionFormat&&(_t.getShaderPrecisionFormat=function(){return{rangeMin:1,rangeMax:1,precision:1}})}catch(t){throw t}function yt(){q=new Br(_t),J=new dr(_t,q,t),q.init(J),ft=new Vo(_t,q,J),Y=new Uo(_t,q,J),R[0]=1029,X=new Wr,Z=new So,$=new Bo(_t,q,Y,Z,J,ft,X),K=new fr(m),Q=new Ur(m),tt=new sr(_t,J),mt=new cr(_t,q,tt,J),et=new Vr(_t,tt,X,mt),it=new Xr(_t,et,tt,X),ct=new Yr(_t,J,$),ot=new pr(Z),nt=new bo(m,K,Q,q,J,mt,ot),st=new Yo(Z),rt=new Ao(Z),at=new Po(q,J),ht=new hr(m,K,Y,it,o),lt=new ko(m,it,J),ut=new ur(_t,q,X,J),dt=new Gr(_t,q,X,J),X.programs=nt.programs,m.capabilities=J,m.extensions=q,m.properties=Z,m.renderLists=rt,m.shadowMap=lt,m.state=Y,m.info=X}yt();const vt=new Jo(m,_t);function xt(t){t.preventDefault(),_=!0}function wt(){_=!1;const t=X.autoReset,e=lt.enabled,i=lt.autoUpdate,n=lt.needsUpdate,s=lt.type;yt(),X.autoReset=t,lt.enabled=e,lt.autoUpdate=i,lt.needsUpdate=n,lt.type=s}function bt(t){const e=t.target;e.removeEventListener("dispose",bt),function(t){(function(t){const e=Z.get(t).programs;void 0!==e&&e.forEach((function(t){nt.releaseProgram(t)}))})(t),Z.remove(t)}(e)}this.xr=vt,this.getContext=function(){return _t},this.getContextAttributes=function(){return _t.getContextAttributes()},this.forceContextLoss=function(){const t=q.get("WEBGL_lose_context");t&&t.loseContext()},this.forceContextRestore=function(){const t=q.get("WEBGL_lose_context");t&&t.restoreContext()},this.getPixelRatio=function(){return E},this.setPixelRatio=function(t){void 0!==t&&(E=t,this.setSize(C,A,!1))},this.getSize=function(t){return t.set(C,A)},this.setSize=function(t,i,n){vt.isPresenting||(C=t,A=i,e.width=Math.floor(t*E),e.height=Math.floor(i*E),!1!==n&&(e.style.width=t+"px",e.style.height=i+"px"),this.setViewport(0,0,t,i))},this.getDrawingBufferSize=function(t){return t.set(C*E,A*E).floor()},this.setDrawingBufferSize=function(t,i,n){C=t,A=i,E=n,e.width=Math.floor(t*n),e.height=Math.floor(i*n),this.setViewport(0,0,t,i)},this.getCurrentViewport=function(t){return t.copy(b)},this.getViewport=function(t){return t.copy(F)},this.setViewport=function(t,e,i,n){t.isVector4?F.set(t.x,t.y,t.z,t.w):F.set(t,e,i,n),Y.viewport(b.copy(F).multiplyScalar(E).floor())},this.getScissor=function(t){return t.copy(D)},this.setScissor=function(t,e,i,n){t.isVector4?D.set(t.x,t.y,t.z,t.w):D.set(t,e,i,n),Y.scissor(S.copy(D).multiplyScalar(E).floor())},this.getScissorTest=function(){return O},this.setScissorTest=function(t){Y.setScissorTest(O=t)},this.setOpaqueSort=function(t){z=t},this.setTransparentSort=function(t){I=t},this.getClearColor=function(t){return t.copy(ht.getClearColor())},this.setClearColor=function(){ht.setClearColor.apply(ht,arguments)},this.getClearAlpha=function(){return ht.getClearAlpha()},this.setClearAlpha=function(){ht.setClearAlpha.apply(ht,arguments)},this.clear=function(t,e,i){let n=0;(void 0===t||t)&&(n|=16384),(void 0===e||e)&&(n|=256),(void 0===i||i)&&(n|=1024),_t.clear(n)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){e.removeEventListener("webglcontextlost",xt,!1),e.removeEventListener("webglcontextrestored",wt,!1),rt.dispose(),at.dispose(),Z.dispose(),K.dispose(),Q.dispose(),it.dispose(),mt.dispose(),vt.dispose(),vt.removeEventListener("sessionstart",Mt),vt.removeEventListener("sessionend",Tt),V&&(V.dispose(),V=null),At.stop()},this.renderBufferDirect=function(t,e,i,n,s,r){null===e&&(e=H);const a=s.isMesh&&s.matrixWorld.determinant()<0,o=function(t,e,i,n,s){!0!==e.isScene&&(e=H),$.resetTextureUnits();const r=e.fog,a=n.isMeshStandardMaterial?e.environment:null,o=null===v?m.outputEncoding:v.texture.encoding,l=(n.isMeshStandardMaterial?Q:K).get(n.envMap||a),h=!0===n.vertexColors&&!!i.attributes.color&&4===i.attributes.color.itemSize,c=!!n.normalMap&&!!i.attributes.tangent,u=!!i.morphAttributes.position,p=!!i.morphAttributes.normal,f=i.morphAttributes.position?i.morphAttributes.position.length:0,_=Z.get(n),g=d.state.lights;if(!0===U&&(!0===B||t!==w)){const e=t===w&&n.id===x;ot.setState(n,t,e)}let y=!1;n.version===_.__version?_.needsLights&&_.lightsStateVersion!==g.state.version||_.outputEncoding!==o||s.isInstancedMesh&&!1===_.instancing?y=!0:s.isInstancedMesh||!0!==_.instancing?s.isSkinnedMesh&&!1===_.skinning?y=!0:s.isSkinnedMesh||!0!==_.skinning?_.envMap!==l||n.fog&&_.fog!==r?y=!0:void 0===_.numClippingPlanes||_.numClippingPlanes===ot.numPlanes&&_.numIntersection===ot.numIntersection?(_.vertexAlphas!==h||_.vertexTangents!==c||_.morphTargets!==u||_.morphNormals!==p||!0===J.isWebGL2&&_.morphTargetsCount!==f)&&(y=!0):y=!0:y=!0:y=!0:(y=!0,_.__version=n.version);let b=_.currentProgram;!0===y&&(b=Dt(n,e,s));let S=!1,M=!1,T=!1;const C=b.getUniforms(),z=_.uniforms;if(Y.useProgram(b.program)&&(S=!0,M=!0,T=!0),n.id!==x&&(x=n.id,M=!0),S||w!==t){if(C.setValue(_t,"projectionMatrix",t.projectionMatrix),J.logarithmicDepthBuffer&&C.setValue(_t,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),w!==t&&(w=t,M=!0,T=!0),n.isShaderMaterial||n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshStandardMaterial||n.envMap){const e=C.map.cameraPosition;void 0!==e&&e.setValue(_t,W.setFromMatrixPosition(t.matrixWorld))}(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial)&&C.setValue(_t,"isOrthographic",!0===t.isOrthographicCamera),(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial||n.isShadowMaterial||s.isSkinnedMesh)&&C.setValue(_t,"viewMatrix",t.matrixWorldInverse)}if(s.isSkinnedMesh){C.setOptional(_t,s,"bindMatrix"),C.setOptional(_t,s,"bindMatrixInverse");const t=s.skeleton;t&&(J.floatVertexTextures?(null===t.boneTexture&&t.computeBoneTexture(),C.setValue(_t,"boneTexture",t.boneTexture,$),C.setValue(_t,"boneTextureSize",t.boneTextureSize)):C.setOptional(_t,t,"boneMatrices"))}return!i||void 0===i.morphAttributes.position&&void 0===i.morphAttributes.normal||ct.update(s,i,n,b),(M||_.receiveShadow!==s.receiveShadow)&&(_.receiveShadow=s.receiveShadow,C.setValue(_t,"receiveShadow",s.receiveShadow)),M&&(C.setValue(_t,"toneMappingExposure",m.toneMappingExposure),_.needsLights&&function(t,e){t.ambientLightColor.needsUpdate=e,t.lightProbe.needsUpdate=e,t.directionalLights.needsUpdate=e,t.directionalLightShadows.needsUpdate=e,t.pointLights.needsUpdate=e,t.pointLightShadows.needsUpdate=e,t.spotLights.needsUpdate=e,t.spotLightShadows.needsUpdate=e,t.rectAreaLights.needsUpdate=e,t.hemisphereLights.needsUpdate=e}(z,T),r&&n.fog&&st.refreshFogUniforms(z,r),st.refreshMaterialUniforms(z,n,E,A,V),to.upload(_t,_.uniformsList,z,$)),n.isShaderMaterial&&!0===n.uniformsNeedUpdate&&(to.upload(_t,_.uniformsList,z,$),n.uniformsNeedUpdate=!1),n.isSpriteMaterial&&C.setValue(_t,"center",s.center),C.setValue(_t,"modelViewMatrix",s.modelViewMatrix),C.setValue(_t,"normalMatrix",s.normalMatrix),C.setValue(_t,"modelMatrix",s.matrixWorld),b}(t,e,i,n,s);Y.setMaterial(n,a);let l=i.index;const h=i.attributes.position;if(null===l){if(void 0===h||0===h.count)return}else if(0===l.count)return;let c,u=1;!0===n.wireframe&&(l=et.getWireframeAttribute(i),u=2),mt.setup(s,n,o,i,l);let p=ut;null!==l&&(c=tt.get(l),p=dt,p.setIndex(c));const f=null!==l?l.count:h.count,_=i.drawRange.start*u,g=i.drawRange.count*u,y=null!==r?r.start*u:0,b=null!==r?r.count*u:Infinity,S=Math.max(_,y),M=Math.min(f,_+g,y+b)-1,T=Math.max(0,M-S+1);if(0!==T){if(s.isMesh)!0===n.wireframe?(Y.setLineWidth(n.wireframeLinewidth*j()),p.setMode(1)):p.setMode(4);else if(s.isLine){let t=n.linewidth;void 0===t&&(t=1),Y.setLineWidth(t*j()),s.isLineSegments?p.setMode(1):s.isLineLoop?p.setMode(2):p.setMode(3)}else s.isPoints?p.setMode(0):s.isSprite&&p.setMode(4);if(s.isInstancedMesh)p.renderInstances(S,T,s.count);else if(i.isInstancedBufferGeometry){const t=Math.min(i.instanceCount,i._maxInstanceCount);p.renderInstances(S,T,t)}else p.render(S,T)}},this.compile=function(t,e){d=at.get(t),d.init(),f.push(d),t.traverseVisible((function(t){t.isLight&&t.layers.test(e.layers)&&(d.pushLight(t),t.castShadow&&d.pushShadow(t))})),d.setupLights(m.physicallyCorrectLights),t.traverse((function(e){const i=e.material;if(i)if(Array.isArray(i))for(let n=0;n<i.length;n++)Dt(i[n],t,e);else Dt(i,t,e)})),f.pop(),d=null};let St=null;function Mt(){At.stop()}function Tt(){At.start()}const At=new nr;function zt(t,e,i,n){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)i=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)d.pushLight(t),t.castShadow&&d.pushShadow(t);else if(t.isSprite){if(!t.frustumCulled||k.intersectsSprite(t)){n&&W.setFromMatrixPosition(t.matrixWorld).applyMatrix4(G);const e=it.update(t),s=t.material;s.visible&&u.push(t,e,s,i,W.z,null)}}else if((t.isMesh||t.isLine||t.isPoints)&&(t.isSkinnedMesh&&t.skeleton.frame!==X.render.frame&&(t.skeleton.update(),t.skeleton.frame=X.render.frame),!t.frustumCulled||k.intersectsObject(t))){n&&W.setFromMatrixPosition(t.matrixWorld).applyMatrix4(G);const e=it.update(t),s=t.material;if(Array.isArray(s)){const n=e.groups;for(let r=0,a=n.length;r<a;r++){const a=n[r],o=s[a.materialIndex];o&&o.visible&&u.push(t,e,o,i,W.z,a)}}else s.visible&&u.push(t,e,s,i,W.z,null)}const s=t.children;for(let t=0,r=s.length;t<r;t++)zt(s[t],e,i,n)}function It(t,e,i,n){const s=t.opaque,r=t.transmissive,o=t.transparent;d.setupLightsView(i),r.length>0&&function(t,e,i){if(null===V){const t=!0===a&&!0===J.isWebGL2;V=new(t?Pi:Li)(1024,1024,{generateMipmaps:!0,type:null!==ft.convert(Vt)?Vt:Ft,minFilter:Pt,magFilter:Et,wrapS:Ct,wrapT:Ct,useRenderToTexture:q.has("WEBGL_multisampled_render_to_texture")})}const n=m.getRenderTarget();m.setRenderTarget(V),m.clear();const s=m.toneMapping;m.toneMapping=pt,Nt(t,e,i),m.toneMapping=s,$.updateMultisampleRenderTarget(V),$.updateRenderTargetMipmap(V),m.setRenderTarget(n)}(s,e,i),n&&Y.viewport(b.copy(n)),s.length>0&&Nt(s,e,i),r.length>0&&Nt(r,e,i),o.length>0&&Nt(o,e,i)}function Nt(t,e,i){const n=!0===e.isScene?e.overrideMaterial:null;for(let s=0,r=t.length;s<r;s++){const r=t[s],a=r.object,o=r.geometry,l=null===n?r.material:n,h=r.group;a.layers.test(i.layers)&&Lt(a,e,i,o,l,h)}}function Lt(t,e,i,n,s,r){t.onBeforeRender(m,e,i,n,s,r),t.modelViewMatrix.multiplyMatrices(i.matrixWorldInverse,t.matrixWorld),t.normalMatrix.getNormalMatrix(t.modelViewMatrix),s.onBeforeRender(m,e,i,n,t,r),!0===s.transparent&&s.side===P?(s.side=L,s.needsUpdate=!0,m.renderBufferDirect(i,e,n,s,t,r),s.side=N,s.needsUpdate=!0,m.renderBufferDirect(i,e,n,s,t,r),s.side=P):m.renderBufferDirect(i,e,n,s,t,r),t.onAfterRender(m,e,i,n,s,r)}function Dt(t,e,i){!0!==e.isScene&&(e=H);const n=Z.get(t),s=d.state.lights,r=d.state.shadowsArray,a=s.state.version,o=nt.getParameters(t,s.state,r,e,i),l=nt.getProgramCacheKey(o);let h=n.programs;n.environment=t.isMeshStandardMaterial?e.environment:null,n.fog=e.fog,n.envMap=(t.isMeshStandardMaterial?Q:K).get(t.envMap||n.environment),void 0===h&&(t.addEventListener("dispose",bt),h=new Map,n.programs=h);let c=h.get(l);if(void 0!==c){if(n.currentProgram===c&&n.lightsStateVersion===a)return Ot(t,o),c}else o.uniforms=nt.getUniforms(t),t.onBuild(i,o,m),t.onBeforeCompile(o,m),c=nt.acquireProgram(o,l),h.set(l,c),n.uniforms=o.uniforms;const u=n.uniforms;(t.isShaderMaterial||t.isRawShaderMaterial)&&!0!==t.clipping||(u.clippingPlanes=ot.uniform),Ot(t,o),n.needsLights=function(t){return t.isMeshLambertMaterial||t.isMeshToonMaterial||t.isMeshPhongMaterial||t.isMeshStandardMaterial||t.isShadowMaterial||t.isShaderMaterial&&!0===t.lights}(t),n.lightsStateVersion=a,n.needsLights&&(u.ambientLightColor.value=s.state.ambient,u.lightProbe.value=s.state.probe,u.directionalLights.value=s.state.directional,u.directionalLightShadows.value=s.state.directionalShadow,u.spotLights.value=s.state.spot,u.spotLightShadows.value=s.state.spotShadow,u.rectAreaLights.value=s.state.rectArea,u.ltc_1.value=s.state.rectAreaLTC1,u.ltc_2.value=s.state.rectAreaLTC2,u.pointLights.value=s.state.point,u.pointLightShadows.value=s.state.pointShadow,u.hemisphereLights.value=s.state.hemi,u.directionalShadowMap.value=s.state.directionalShadowMap,u.directionalShadowMatrix.value=s.state.directionalShadowMatrix,u.spotShadowMap.value=s.state.spotShadowMap,u.spotShadowMatrix.value=s.state.spotShadowMatrix,u.pointShadowMap.value=s.state.pointShadowMap,u.pointShadowMatrix.value=s.state.pointShadowMatrix);const p=c.getUniforms(),f=to.seqWithValue(p.seq,u);return n.currentProgram=c,n.uniformsList=f,c}function Ot(t,e){const i=Z.get(t);i.outputEncoding=e.outputEncoding,i.instancing=e.instancing,i.skinning=e.skinning,i.morphTargets=e.morphTargets,i.morphNormals=e.morphNormals,i.morphTargetsCount=e.morphTargetsCount,i.numClippingPlanes=e.numClippingPlanes,i.numIntersection=e.numClipIntersection,i.vertexAlphas=e.vertexAlphas,i.vertexTangents=e.vertexTangents}At.setAnimationLoop((function(t){St&&St(t)})),"undefined"!=typeof window&&At.setContext(window),this.setAnimationLoop=function(t){St=t,vt.setAnimationLoop(t),null===t?At.stop():At.start()},vt.addEventListener("sessionstart",Mt),vt.addEventListener("sessionend",Tt),this.render=function(t,e){if(void 0!==e&&!0!==e.isCamera)return;if(!0===_)return;!0===t.autoUpdate&&t.updateMatrixWorld(),null===e.parent&&e.updateMatrixWorld(),!0===vt.enabled&&!0===vt.isPresenting&&(!0===vt.cameraAutoUpdate&&vt.updateCamera(e),e=vt.getCamera()),!0===t.isScene&&t.onBeforeRender(m,t,e,v),d=at.get(t,f.length),d.init(),f.push(d),G.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),k.setFromProjectionMatrix(G),B=this.localClippingEnabled,U=ot.init(this.clippingPlanes,B,e),u=rt.get(t,p.length),u.init(),p.push(u),zt(t,e,0,m.sortObjects),u.finish(),!0===m.sortObjects&&u.sort(z,I),!0===U&&ot.beginShadows();const i=d.state.shadowsArray;if(lt.render(i,t,e),!0===U&&ot.endShadows(),!0===this.info.autoReset&&this.info.reset(),ht.render(u,t),d.setupLights(m.physicallyCorrectLights),e.isArrayCamera){const i=e.cameras;for(let e=0,n=i.length;e<n;e++){const n=i[e];It(u,t,n,n.viewport)}}else It(u,t,e);null!==v&&($.updateMultisampleRenderTarget(v),$.updateRenderTargetMipmap(v)),!0===t.isScene&&t.onAfterRender(m,t,e),Y.buffers.depth.setTest(!0),Y.buffers.depth.setMask(!0),Y.buffers.color.setMask(!0),Y.setPolygonOffset(!1),mt.resetDefaultState(),x=-1,w=null,f.pop(),d=f.length>0?f[f.length-1]:null,p.pop(),u=p.length>0?p[p.length-1]:null},this.getActiveCubeFace=function(){return g},this.getActiveMipmapLevel=function(){return y},this.getRenderTarget=function(){return v},this.setRenderTargetTextures=function(t,e,i){Z.get(t.texture).__webglTexture=e,Z.get(t.depthTexture).__webglTexture=i;const n=Z.get(t);n.__hasExternalTextures=!0,n.__hasExternalTextures&&(n.__autoAllocateDepthBuffer=void 0===i,n.__autoAllocateDepthBuffer||t.useRenderToTexture&&(t.useRenderToTexture=!1,t.useRenderbuffer=!0))},this.setRenderTargetFramebuffer=function(t,e){const i=Z.get(t);i.__webglFramebuffer=e,i.__useDefaultFramebuffer=void 0===e},this.setRenderTarget=function(t,e=0,i=0){v=t,g=e,y=i;let n=!0;if(t){const e=Z.get(t);void 0!==e.__useDefaultFramebuffer?(Y.bindFramebuffer(36160,null),n=!1):void 0===e.__webglFramebuffer?$.setupRenderTarget(t):e.__hasExternalTextures&&$.rebindTextures(t,Z.get(t.texture).__webglTexture,Z.get(t.depthTexture).__webglTexture)}let s=null,r=!1,a=!1;if(t){const i=t.texture;(i.isDataTexture3D||i.isDataTexture2DArray)&&(a=!0);const n=Z.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(s=n[e],r=!0):s=t.useRenderbuffer?Z.get(t).__webglMultisampledFramebuffer:n,b.copy(t.viewport),S.copy(t.scissor),T=t.scissorTest}else b.copy(F).multiplyScalar(E).floor(),S.copy(D).multiplyScalar(E).floor(),T=O;if(Y.bindFramebuffer(36160,s)&&J.drawBuffers&&n){let e=!1;if(t)if(t.isWebGLMultipleRenderTargets){const i=t.texture;if(R.length!==i.length||36064!==R[0]){for(let t=0,e=i.length;t<e;t++)R[t]=36064+t;R.length=i.length,e=!0}}else 1===R.length&&36064===R[0]||(R[0]=36064,R.length=1,e=!0);else 1===R.length&&1029===R[0]||(R[0]=1029,R.length=1,e=!0);e&&(J.isWebGL2?_t.drawBuffers(R):q.get("WEBGL_draw_buffers").drawBuffersWEBGL(R))}if(Y.viewport(b),Y.scissor(S),Y.setScissorTest(T),r){const n=Z.get(t.texture);_t.framebufferTexture2D(36160,36064,34069+e,n.__webglTexture,i)}else if(a){const n=Z.get(t.texture),s=e||0;_t.framebufferTextureLayer(36160,36064,n.__webglTexture,i||0,s)}x=-1},this.readRenderTargetPixels=function(t,e,i,n,s,r,a){if(!t||!t.isWebGLRenderTarget)return;let o=Z.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(o=o[a]),o){Y.bindFramebuffer(36160,o);try{const a=t.texture,o=a.format,l=a.type;if(o!==Yt&&ft.convert(o)!==_t.getParameter(35739))return;const h=l===Vt&&(q.has("EXT_color_buffer_half_float")||J.isWebGL2&&q.has("EXT_color_buffer_float"));if(!(l===Ft||ft.convert(l)===_t.getParameter(35738)||l===Bt&&(J.isWebGL2||q.has("OES_texture_float")||q.has("WEBGL_color_buffer_float"))||h))return;36053===_t.checkFramebufferStatus(36160)&&e>=0&&e<=t.width-n&&i>=0&&i<=t.height-s&&_t.readPixels(e,i,n,s,ft.convert(o),ft.convert(l),r)}finally{const t=null!==v?Z.get(v).__webglFramebuffer:null;Y.bindFramebuffer(36160,t)}}},this.copyFramebufferToTexture=function(t,e,i=0){const n=Math.pow(2,-i),s=Math.floor(e.image.width*n),r=Math.floor(e.image.height*n);let a=ft.convert(e.format);J.isWebGL2&&(6407===a&&(a=32849),6408===a&&(a=32856)),$.setTexture2D(e,0),_t.copyTexImage2D(3553,i,a,t.x,t.y,s,r,0),Y.unbindTexture()},this.copyTextureToTexture=function(t,e,i,n=0){const s=e.image.width,r=e.image.height,a=ft.convert(i.format),o=ft.convert(i.type);$.setTexture2D(i,0),_t.pixelStorei(37440,i.flipY),_t.pixelStorei(37441,i.premultiplyAlpha),_t.pixelStorei(3317,i.unpackAlignment),e.isDataTexture?_t.texSubImage2D(3553,n,t.x,t.y,s,r,a,o,e.image.data):e.isCompressedTexture?_t.compressedTexSubImage2D(3553,n,t.x,t.y,e.mipmaps[0].width,e.mipmaps[0].height,a,e.mipmaps[0].data):_t.texSubImage2D(3553,n,t.x,t.y,a,o,e.image),0===n&&i.generateMipmaps&&_t.generateMipmap(3553),Y.unbindTexture()},this.copyTextureToTexture3D=function(t,e,i,n,s=0){if(m.isWebGL1Renderer)return;const r=t.max.x-t.min.x+1,a=t.max.y-t.min.y+1,o=t.max.z-t.min.z+1,l=ft.convert(n.format),h=ft.convert(n.type);let c;if(n.isDataTexture3D)$.setTexture3D(n,0),c=32879;else{if(!n.isDataTexture2DArray)return;$.setTexture2DArray(n,0),c=35866}_t.pixelStorei(37440,n.flipY),_t.pixelStorei(37441,n.premultiplyAlpha),_t.pixelStorei(3317,n.unpackAlignment);const u=_t.getParameter(3314),d=_t.getParameter(32878),p=_t.getParameter(3316),f=_t.getParameter(3315),_=_t.getParameter(32877),g=i.isCompressedTexture?i.mipmaps[0]:i.image;_t.pixelStorei(3314,g.width),_t.pixelStorei(32878,g.height),_t.pixelStorei(3316,t.min.x),_t.pixelStorei(3315,t.min.y),_t.pixelStorei(32877,t.min.z),i.isDataTexture||i.isDataTexture3D?_t.texSubImage3D(c,s,e.x,e.y,e.z,r,a,o,l,h,g.data):i.isCompressedTexture?_t.compressedTexSubImage3D(c,s,e.x,e.y,e.z,r,a,o,l,g.data):_t.texSubImage3D(c,s,e.x,e.y,e.z,r,a,o,l,h,g),_t.pixelStorei(3314,u),_t.pixelStorei(32878,d),_t.pixelStorei(3316,p),_t.pixelStorei(3315,f),_t.pixelStorei(32877,_),0===s&&n.generateMipmaps&&_t.generateMipmap(c),Y.unbindTexture()},this.initTexture=function(t){$.setTexture2D(t,0),Y.unbindTexture()},this.resetState=function(){g=0,y=0,v=null,Y.reset(),mt.reset()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}Xo.prototype.isWebGLRenderer=!0,class extends Xo{}.prototype.isWebGL1Renderer=!0;let Zo=class extends kn{constructor(){super(),this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.overrideMaterial=null,this.autoUpdate=!0,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),null!==t.background&&(this.background=t.background.clone()),null!==t.environment&&(this.environment=t.environment.clone()),null!==t.fog&&(this.fog=t.fog.clone()),null!==t.overrideMaterial&&(this.overrideMaterial=t.overrideMaterial.clone()),this.autoUpdate=t.autoUpdate,this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return null!==this.fog&&(e.object.fog=this.fog.toJSON()),e}};Zo.prototype.isScene=!0;class $o{constructor(t,e){this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=hi,this.updateRange={offset:0,count:-1},this.version=0,this.uuid=_i()}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}copy(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this}copyAt(t,e,i){t*=this.stride,i*=e.stride;for(let n=0,s=this.stride;n<s;n++)this.array[t+n]=e.array[i+n];return this}set(t,e=0){return this.array.set(t,e),this}clone(t){void 0===t.arrayBuffers&&(t.arrayBuffers={}),void 0===this.array.buffer._uuid&&(this.array.buffer._uuid=_i()),void 0===t.arrayBuffers[this.array.buffer._uuid]&&(t.arrayBuffers[this.array.buffer._uuid]=this.array.slice(0).buffer);const e=new this.array.constructor(t.arrayBuffers[this.array.buffer._uuid]),i=new this.constructor(e,this.stride);return i.setUsage(this.usage),i}onUpload(t){return this.onUploadCallback=t,this}toJSON(t){return void 0===t.arrayBuffers&&(t.arrayBuffers={}),void 0===this.array.buffer._uuid&&(this.array.buffer._uuid=_i()),void 0===t.arrayBuffers[this.array.buffer._uuid]&&(t.arrayBuffers[this.array.buffer._uuid]=Array.prototype.slice.call(new Uint32Array(this.array.buffer))),{uuid:this.uuid,buffer:this.array.buffer._uuid,type:this.array.constructor.name,stride:this.stride}}}$o.prototype.isInterleavedBuffer=!0;const Ko=new Di;class Qo{constructor(t,e,i,n=!1){this.name="",this.data=t,this.itemSize=e,this.offset=i,this.normalized=!0===n}get count(){return this.data.count}get array(){return this.data.array}set needsUpdate(t){this.data.needsUpdate=t}applyMatrix4(t){for(let e=0,i=this.data.count;e<i;e++)Ko.x=this.getX(e),Ko.y=this.getY(e),Ko.z=this.getZ(e),Ko.applyMatrix4(t),this.setXYZ(e,Ko.x,Ko.y,Ko.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)Ko.x=this.getX(e),Ko.y=this.getY(e),Ko.z=this.getZ(e),Ko.applyNormalMatrix(t),this.setXYZ(e,Ko.x,Ko.y,Ko.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)Ko.x=this.getX(e),Ko.y=this.getY(e),Ko.z=this.getZ(e),Ko.transformDirection(t),this.setXYZ(e,Ko.x,Ko.y,Ko.z);return this}setX(t,e){return this.data.array[t*this.data.stride+this.offset]=e,this}setY(t,e){return this.data.array[t*this.data.stride+this.offset+1]=e,this}setZ(t,e){return this.data.array[t*this.data.stride+this.offset+2]=e,this}setW(t,e){return this.data.array[t*this.data.stride+this.offset+3]=e,this}getX(t){return this.data.array[t*this.data.stride+this.offset]}getY(t){return this.data.array[t*this.data.stride+this.offset+1]}getZ(t){return this.data.array[t*this.data.stride+this.offset+2]}getW(t){return this.data.array[t*this.data.stride+this.offset+3]}setXY(t,e,i){return t=t*this.data.stride+this.offset,this.data.array[t+0]=e,this.data.array[t+1]=i,this}setXYZ(t,e,i,n){return t=t*this.data.stride+this.offset,this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this}setXYZW(t,e,i,n,s){return t=t*this.data.stride+this.offset,this.data.array[t+0]=e,this.data.array[t+1]=i,this.data.array[t+2]=n,this.data.array[t+3]=s,this}clone(t){if(void 0===t){const t=[];for(let e=0;e<this.count;e++){const i=e*this.data.stride+this.offset;for(let e=0;e<this.itemSize;e++)t.push(this.data.array[i+e])}return new ls(new this.array.constructor(t),this.itemSize,this.normalized)}return void 0===t.interleavedBuffers&&(t.interleavedBuffers={}),void 0===t.interleavedBuffers[this.data.uuid]&&(t.interleavedBuffers[this.data.uuid]=this.data.clone(t)),new Qo(t.interleavedBuffers[this.data.uuid],this.itemSize,this.offset,this.normalized)}toJSON(t){if(void 0===t){const t=[];for(let e=0;e<this.count;e++){const i=e*this.data.stride+this.offset;for(let e=0;e<this.itemSize;e++)t.push(this.data.array[i+e])}return{itemSize:this.itemSize,type:this.array.constructor.name,array:t,normalized:this.normalized}}return void 0===t.interleavedBuffers&&(t.interleavedBuffers={}),void 0===t.interleavedBuffers[this.data.uuid]&&(t.interleavedBuffers[this.data.uuid]=this.data.toJSON(t)),{isInterleavedBufferAttribute:!0,itemSize:this.itemSize,data:this.data.uuid,offset:this.offset,normalized:this.normalized}}}Qo.prototype.isInterleavedBufferAttribute=!0;class tl extends $n{constructor(t){super(),this.type="SpriteMaterial",this.color=new ss(16777215),this.map=null,this.alphaMap=null,this.rotation=0,this.sizeAttenuation=!0,this.transparent=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.rotation=t.rotation,this.sizeAttenuation=t.sizeAttenuation,this}}let el;tl.prototype.isSpriteMaterial=!0;const il=new Di,nl=new Di,sl=new Di,rl=new bi,al=new bi,ol=new pn,ll=new Di,hl=new Di,cl=new Di,ul=new bi,dl=new bi,pl=new bi;function fl(t,e,i,n,s,r){rl.subVectors(t,i).addScalar(.5).multiply(n),void 0!==s?(al.x=r*rl.x-s*rl.y,al.y=s*rl.x+r*rl.y):al.copy(rl),t.copy(e),t.x+=al.x,t.y+=al.y,t.applyMatrix4(ol)}(class extends kn{constructor(t){if(super(),this.type="Sprite",void 0===el){el=new vs;const t=new Float32Array([-.5,-.5,0,0,0,.5,-.5,0,1,0,.5,.5,0,1,1,-.5,.5,0,0,1]),e=new $o(t,5);el.setIndex([0,1,2,0,2,3]),el.setAttribute("position",new Qo(e,3,0,!1)),el.setAttribute("uv",new Qo(e,2,3,!1))}this.geometry=el,this.material=void 0!==t?t:new tl,this.center=new bi(.5,.5)}raycast(t,e){t.camera,nl.setFromMatrixScale(this.matrixWorld),ol.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),sl.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&!1===this.material.sizeAttenuation&&nl.multiplyScalar(-sl.z);const i=this.material.rotation;let n,s;0!==i&&(s=Math.cos(i),n=Math.sin(i));const r=this.center;fl(ll.set(-.5,-.5,0),sl,r,nl,n,s),fl(hl.set(.5,-.5,0),sl,r,nl,n,s),fl(cl.set(.5,.5,0),sl,r,nl,n,s),ul.set(0,0),dl.set(1,0),pl.set(1,1);let a=t.ray.intersectTriangle(ll,hl,cl,!1,il);if(null===a&&(fl(hl.set(-.5,.5,0),sl,r,nl,n,s),dl.set(0,1),a=t.ray.intersectTriangle(ll,cl,hl,!1,il),null===a))return;const o=t.ray.origin.distanceTo(il);o<t.near||o>t.far||e.push({distance:o,point:il.clone(),uv:Xn.getUV(il,ll,hl,cl,ul,dl,pl,new bi),face:null,object:this})}copy(t){return super.copy(t),void 0!==t.center&&this.center.copy(t.center),this.material=t.material,this}}).prototype.isSprite=!0;const ml=new Di,_l=new Ni,gl=new Ni,yl=new Di,vl=new pn;class xl extends Rs{constructor(t,e){super(t,e),this.type="SkinnedMesh",this.bindMode="attached",this.bindMatrix=new pn,this.bindMatrixInverse=new pn}copy(t){return super.copy(t),this.bindMode=t.bindMode,this.bindMatrix.copy(t.bindMatrix),this.bindMatrixInverse.copy(t.bindMatrixInverse),this.skeleton=t.skeleton,this}bind(t,e){this.skeleton=t,void 0===e&&(this.updateMatrixWorld(!0),this.skeleton.calculateInverses(),e=this.matrixWorld),this.bindMatrix.copy(e),this.bindMatrixInverse.copy(e).invert()}pose(){this.skeleton.pose()}normalizeSkinWeights(){const t=new Ni,e=this.geometry.attributes.skinWeight;for(let i=0,n=e.count;i<n;i++){t.x=e.getX(i),t.y=e.getY(i),t.z=e.getZ(i),t.w=e.getW(i);const n=1/t.manhattanLength();Infinity!==n?t.multiplyScalar(n):t.set(1,0,0,0),e.setXYZW(i,t.x,t.y,t.z,t.w)}}updateMatrixWorld(t){super.updateMatrixWorld(t),"attached"===this.bindMode?this.bindMatrixInverse.copy(this.matrixWorld).invert():"detached"===this.bindMode&&this.bindMatrixInverse.copy(this.bindMatrix).invert()}boneTransform(t,e){const i=this.skeleton,n=this.geometry;_l.fromBufferAttribute(n.attributes.skinIndex,t),gl.fromBufferAttribute(n.attributes.skinWeight,t),ml.copy(e).applyMatrix4(this.bindMatrix),e.set(0,0,0);for(let t=0;t<4;t++){const n=gl.getComponent(t);if(0!==n){const s=_l.getComponent(t);vl.multiplyMatrices(i.bones[s].matrixWorld,i.boneInverses[s]),e.addScaledVector(yl.copy(ml).applyMatrix4(vl),n)}}return e.applyMatrix4(this.bindMatrixInverse)}}xl.prototype.isSkinnedMesh=!0,class extends kn{constructor(){super(),this.type="Bone"}}.prototype.isBone=!0;class wl extends zi{constructor(t=null,e=1,i=1,n,s,r,a,o,l=Et,h=Et,c,u){super(null,r,a,o,l,h,n,s,c,u),this.image={data:t,width:e,height:i},this.magFilter=l,this.minFilter=h,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.needsUpdate=!0}}wl.prototype.isDataTexture=!0;class bl extends ls{constructor(t,e,i,n=1){"number"==typeof i&&(n=i,i=!1),super(t,e,i),this.meshPerAttribute=n}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}toJSON(){const t=super.toJSON();return t.meshPerAttribute=this.meshPerAttribute,t.isInstancedBufferAttribute=!0,t}}bl.prototype.isInstancedBufferAttribute=!0;const Sl=new pn,Ml=new pn,Tl=[],Cl=new Rs;(class extends Rs{constructor(t,e,i){super(t,e),this.instanceMatrix=new bl(new Float32Array(16*i),16),this.instanceColor=null,this.count=i,this.frustumCulled=!1}copy(t){return super.copy(t),this.instanceMatrix.copy(t.instanceMatrix),null!==t.instanceColor&&(this.instanceColor=t.instanceColor.clone()),this.count=t.count,this}getColorAt(t,e){e.fromArray(this.instanceColor.array,3*t)}getMatrixAt(t,e){e.fromArray(this.instanceMatrix.array,16*t)}raycast(t,e){const i=this.matrixWorld,n=this.count;if(Cl.geometry=this.geometry,Cl.material=this.material,void 0!==Cl.material)for(let s=0;s<n;s++){this.getMatrixAt(s,Sl),Ml.multiplyMatrices(i,Sl),Cl.matrixWorld=Ml,Cl.raycast(t,Tl);for(let t=0,i=Tl.length;t<i;t++){const i=Tl[t];i.instanceId=s,i.object=this,e.push(i)}Tl.length=0}}setColorAt(t,e){null===this.instanceColor&&(this.instanceColor=new bl(new Float32Array(3*this.instanceMatrix.count),3)),e.toArray(this.instanceColor.array,3*t)}setMatrixAt(t,e){e.toArray(this.instanceMatrix.array,16*t)}updateMorphTargets(){}dispose(){this.dispatchEvent({type:"dispose"})}}).prototype.isInstancedMesh=!0;class Al extends $n{constructor(t){super(),this.type="LineBasicMaterial",this.color=new ss(16777215),this.linewidth=1,this.linecap="round",this.linejoin="round",this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.linewidth=t.linewidth,this.linecap=t.linecap,this.linejoin=t.linejoin,this}}Al.prototype.isLineBasicMaterial=!0;const El=new Di,zl=new Di,Il=new pn,Nl=new dn,Ll=new sn;let Pl=class extends kn{constructor(t=new vs,e=new Al){super(),this.type="Line",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t){return super.copy(t),this.material=t.material,this.geometry=t.geometry,this}computeLineDistances(){const t=this.geometry;if(t.isBufferGeometry){if(null===t.index){const e=t.attributes.position,i=[0];for(let t=1,n=e.count;t<n;t++)El.fromBufferAttribute(e,t-1),zl.fromBufferAttribute(e,t),i[t]=i[t-1],i[t]+=El.distanceTo(zl);t.setAttribute("lineDistance",new us(i,1))}}else t.isGeometry;return this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Line.threshold,r=i.drawRange;if(null===i.boundingSphere&&i.computeBoundingSphere(),Ll.copy(i.boundingSphere),Ll.applyMatrix4(n),Ll.radius+=s,!1===t.ray.intersectsSphere(Ll))return;Il.copy(n).invert(),Nl.copy(t.ray).applyMatrix4(Il);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),o=a*a,l=new Di,h=new Di,c=new Di,u=new Di,d=this.isLineSegments?2:1;if(i.isBufferGeometry){const n=i.index,s=i.attributes.position;if(null!==n)for(let i=Math.max(0,r.start),a=Math.min(n.count,r.start+r.count)-1;i<a;i+=d){const r=n.getX(i),a=n.getX(i+1);if(l.fromBufferAttribute(s,r),h.fromBufferAttribute(s,a),Nl.distanceSqToSegment(l,h,u,c)>o)continue;u.applyMatrix4(this.matrixWorld);const d=t.ray.origin.distanceTo(u);d<t.near||d>t.far||e.push({distance:d,point:c.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this})}else for(let i=Math.max(0,r.start),n=Math.min(s.count,r.start+r.count)-1;i<n;i+=d){if(l.fromBufferAttribute(s,i),h.fromBufferAttribute(s,i+1),Nl.distanceSqToSegment(l,h,u,c)>o)continue;u.applyMatrix4(this.matrixWorld);const n=t.ray.origin.distanceTo(u);n<t.near||n>t.far||e.push({distance:n,point:c.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this})}}else i.isGeometry}updateMorphTargets(){const t=this.geometry;if(t.isBufferGeometry){const e=t.morphAttributes,i=Object.keys(e);if(i.length>0){const t=e[i[0]];if(void 0!==t){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,i=t.length;e<i;e++){const i=t[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[i]=e}}}}else{const e=t.morphTargets;void 0!==e&&e.length}}};Pl.prototype.isLine=!0;const Fl=new Di,Dl=new Di;class Ol extends Pl{constructor(t,e){super(t,e),this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(t.isBufferGeometry){if(null===t.index){const e=t.attributes.position,i=[];for(let t=0,n=e.count;t<n;t+=2)Fl.fromBufferAttribute(e,t),Dl.fromBufferAttribute(e,t+1),i[t]=0===t?0:i[t-1],i[t+1]=i[t]+Fl.distanceTo(Dl);t.setAttribute("lineDistance",new us(i,1))}}else t.isGeometry;return this}}Ol.prototype.isLineSegments=!0,class extends Pl{constructor(t,e){super(t,e),this.type="LineLoop"}}.prototype.isLineLoop=!0;class Rl extends $n{constructor(t){super(),this.type="PointsMaterial",this.color=new ss(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.alphaMap=t.alphaMap,this.size=t.size,this.sizeAttenuation=t.sizeAttenuation,this}}Rl.prototype.isPointsMaterial=!0;const kl=new pn,Ul=new dn,Bl=new sn,Vl=new Di;class Gl extends kn{constructor(t=new vs,e=new Rl){super(),this.type="Points",this.geometry=t,this.material=e,this.updateMorphTargets()}copy(t){return super.copy(t),this.material=t.material,this.geometry=t.geometry,this}raycast(t,e){const i=this.geometry,n=this.matrixWorld,s=t.params.Points.threshold,r=i.drawRange;if(null===i.boundingSphere&&i.computeBoundingSphere(),Bl.copy(i.boundingSphere),Bl.applyMatrix4(n),Bl.radius+=s,!1===t.ray.intersectsSphere(Bl))return;kl.copy(n).invert(),Ul.copy(t.ray).applyMatrix4(kl);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),o=a*a;if(i.isBufferGeometry){const s=i.index,a=i.attributes.position;if(null!==s)for(let i=Math.max(0,r.start),l=Math.min(s.count,r.start+r.count);i<l;i++){const r=s.getX(i);Vl.fromBufferAttribute(a,r),Wl(Vl,r,o,n,t,e,this)}else for(let i=Math.max(0,r.start),s=Math.min(a.count,r.start+r.count);i<s;i++)Vl.fromBufferAttribute(a,i),Wl(Vl,i,o,n,t,e,this)}}updateMorphTargets(){const t=this.geometry;if(t.isBufferGeometry){const e=t.morphAttributes,i=Object.keys(e);if(i.length>0){const t=e[i[0]];if(void 0!==t){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let e=0,i=t.length;e<i;e++){const i=t[e].name||String(e);this.morphTargetInfluences.push(0),this.morphTargetDictionary[i]=e}}}}else{const e=t.morphTargets;void 0!==e&&e.length}}}function Wl(t,e,i,n,s,r,a){const o=Ul.distanceSqToPoint(t);if(o<i){const i=new Di;Ul.closestPointToPoint(t,i),i.applyMatrix4(n);const l=s.ray.origin.distanceTo(i);if(l<s.near||l>s.far)return;r.push({distance:l,distanceToRay:Math.sqrt(o),point:i,index:e,face:null,object:a})}}Gl.prototype.isPoints=!0,class extends zi{constructor(t,e,i,n,s,r,a,o,l){super(t,e,i,n,s,r,a,o,l),this.format=void 0!==a?a:Jt,this.minFilter=void 0!==r?r:Nt,this.magFilter=void 0!==s?s:Nt,this.generateMipmaps=!1;const h=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){h.needsUpdate=!0,t.requestVideoFrameCallback(e)}))}clone(){return new this.constructor(this.image).copy(this)}update(){const t=this.image;0=="requestVideoFrameCallback"in t&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}.prototype.isVideoTexture=!0,class extends zi{constructor(t,e,i,n,s,r,a,o,l,h,c,u){super(null,r,a,o,l,h,n,s,c,u),this.image={width:e,height:i},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}}.prototype.isCompressedTexture=!0,class extends zi{constructor(t,e,i,n,s,r,a,o,l){super(t,e,i,n,s,r,a,o,l),this.needsUpdate=!0}}.prototype.isCanvasTexture=!0;class Hl{constructor(){this.type="Curve",this.arcLengthDivisions=200}getPoint(){return null}getPointAt(t,e){const i=this.getUtoTmapping(t);return this.getPoint(i,e)}getPoints(t=5){const e=[];for(let i=0;i<=t;i++)e.push(this.getPoint(i/t));return e}getSpacedPoints(t=5){const e=[];for(let i=0;i<=t;i++)e.push(this.getPointAt(i/t));return e}getLength(){const t=this.getLengths();return t[t.length-1]}getLengths(t=this.arcLengthDivisions){if(this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;const e=[];let i,n=this.getPoint(0),s=0;e.push(0);for(let r=1;r<=t;r++)i=this.getPoint(r/t),s+=i.distanceTo(n),e.push(s),n=i;return this.cacheArcLengths=e,e}updateArcLengths(){this.needsUpdate=!0,this.getLengths()}getUtoTmapping(t,e){const i=this.getLengths();let n=0;const s=i.length;let r;r=e||t*i[s-1];let a,o=0,l=s-1;for(;o<=l;)if(n=Math.floor(o+(l-o)/2),a=i[n]-r,a<0)o=n+1;else{if(!(a>0)){l=n;break}l=n-1}if(n=l,i[n]===r)return n/(s-1);const h=i[n];return(n+(r-h)/(i[n+1]-h))/(s-1)}getTangent(t,e){const i=1e-4;let n=t-i,s=t+i;n<0&&(n=0),s>1&&(s=1);const r=this.getPoint(n),a=this.getPoint(s),o=e||(r.isVector2?new bi:new Di);return o.copy(a).sub(r).normalize(),o}getTangentAt(t,e){const i=this.getUtoTmapping(t);return this.getTangent(i,e)}computeFrenetFrames(t,e){const i=new Di,n=[],s=[],r=[],a=new Di,o=new pn;for(let e=0;e<=t;e++){const i=e/t;n[e]=this.getTangentAt(i,new Di)}s[0]=new Di,r[0]=new Di;let l=Number.MAX_VALUE;const h=Math.abs(n[0].x),c=Math.abs(n[0].y),u=Math.abs(n[0].z);h<=l&&(l=h,i.set(1,0,0)),c<=l&&(l=c,i.set(0,1,0)),u<=l&&i.set(0,0,1),a.crossVectors(n[0],i).normalize(),s[0].crossVectors(n[0],a),r[0].crossVectors(n[0],s[0]);for(let e=1;e<=t;e++){if(s[e]=s[e-1].clone(),r[e]=r[e-1].clone(),a.crossVectors(n[e-1],n[e]),a.length()>Number.EPSILON){a.normalize();const t=Math.acos(gi(n[e-1].dot(n[e]),-1,1));s[e].applyMatrix4(o.makeRotationAxis(a,t))}r[e].crossVectors(n[e],s[e])}if(!0===e){let e=Math.acos(gi(s[0].dot(s[t]),-1,1));e/=t,n[0].dot(a.crossVectors(s[0],s[t]))>0&&(e=-e);for(let i=1;i<=t;i++)s[i].applyMatrix4(o.makeRotationAxis(n[i],e*i)),r[i].crossVectors(n[i],s[i])}return{tangents:n,normals:s,binormals:r}}clone(){return(new this.constructor).copy(this)}copy(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}toJSON(){const t={metadata:{version:4.5,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t}fromJSON(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}class jl extends Hl{constructor(t=0,e=0,i=1,n=1,s=0,r=2*Math.PI,a=!1,o=0){super(),this.type="EllipseCurve",this.aX=t,this.aY=e,this.xRadius=i,this.yRadius=n,this.aStartAngle=s,this.aEndAngle=r,this.aClockwise=a,this.aRotation=o}getPoint(t,e){const i=e||new bi,n=2*Math.PI;let s=this.aEndAngle-this.aStartAngle;const r=Math.abs(s)<Number.EPSILON;for(;s<0;)s+=n;for(;s>n;)s-=n;s<Number.EPSILON&&(s=r?0:n),!0!==this.aClockwise||r||(s===n?s=-n:s-=n);const a=this.aStartAngle+t*s;let o=this.aX+this.xRadius*Math.cos(a),l=this.aY+this.yRadius*Math.sin(a);if(0!==this.aRotation){const t=Math.cos(this.aRotation),e=Math.sin(this.aRotation),i=o-this.aX,n=l-this.aY;o=i*t-n*e+this.aX,l=i*e+n*t+this.aY}return i.set(o,l)}copy(t){return super.copy(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}toJSON(){const t=super.toJSON();return t.aX=this.aX,t.aY=this.aY,t.xRadius=this.xRadius,t.yRadius=this.yRadius,t.aStartAngle=this.aStartAngle,t.aEndAngle=this.aEndAngle,t.aClockwise=this.aClockwise,t.aRotation=this.aRotation,t}fromJSON(t){return super.fromJSON(t),this.aX=t.aX,this.aY=t.aY,this.xRadius=t.xRadius,this.yRadius=t.yRadius,this.aStartAngle=t.aStartAngle,this.aEndAngle=t.aEndAngle,this.aClockwise=t.aClockwise,this.aRotation=t.aRotation,this}}jl.prototype.isEllipseCurve=!0;class ql extends jl{constructor(t,e,i,n,s,r){super(t,e,i,i,n,s,r),this.type="ArcCurve"}}function Jl(){let t=0,e=0,i=0,n=0;function s(s,r,a,o){t=s,e=a,i=-3*s+3*r-2*a-o,n=2*s-2*r+a+o}return{initCatmullRom:function(t,e,i,n,r){s(e,i,r*(i-t),r*(n-e))},initNonuniformCatmullRom:function(t,e,i,n,r,a,o){let l=(e-t)/r-(i-t)/(r+a)+(i-e)/a,h=(i-e)/a-(n-e)/(a+o)+(n-i)/o;l*=a,h*=a,s(e,i,l,h)},calc:function(s){const r=s*s;return t+e*s+i*r+n*(r*s)}}}ql.prototype.isArcCurve=!0;const Yl=new Di,Xl=new Jl,Zl=new Jl,$l=new Jl;class Kl extends Hl{constructor(t=[],e=!1,i="centripetal",n=.5){super(),this.type="CatmullRomCurve3",this.points=t,this.closed=e,this.curveType=i,this.tension=n}getPoint(t,e=new Di){const i=e,n=this.points,s=n.length,r=(s-(this.closed?0:1))*t;let a,o,l=Math.floor(r),h=r-l;this.closed?l+=l>0?0:(Math.floor(Math.abs(l)/s)+1)*s:0===h&&l===s-1&&(l=s-2,h=1),this.closed||l>0?a=n[(l-1)%s]:(Yl.subVectors(n[0],n[1]).add(n[0]),a=Yl);const c=n[l%s],u=n[(l+1)%s];if(this.closed||l+2<s?o=n[(l+2)%s]:(Yl.subVectors(n[s-1],n[s-2]).add(n[s-1]),o=Yl),"centripetal"===this.curveType||"chordal"===this.curveType){const t="chordal"===this.curveType?.5:.25;let e=Math.pow(a.distanceToSquared(c),t),i=Math.pow(c.distanceToSquared(u),t),n=Math.pow(u.distanceToSquared(o),t);i<1e-4&&(i=1),e<1e-4&&(e=i),n<1e-4&&(n=i),Xl.initNonuniformCatmullRom(a.x,c.x,u.x,o.x,e,i,n),Zl.initNonuniformCatmullRom(a.y,c.y,u.y,o.y,e,i,n),$l.initNonuniformCatmullRom(a.z,c.z,u.z,o.z,e,i,n)}else"catmullrom"===this.curveType&&(Xl.initCatmullRom(a.x,c.x,u.x,o.x,this.tension),Zl.initCatmullRom(a.y,c.y,u.y,o.y,this.tension),$l.initCatmullRom(a.z,c.z,u.z,o.z,this.tension));return i.set(Xl.calc(h),Zl.calc(h),$l.calc(h)),i}copy(t){super.copy(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const i=t.points[e];this.points.push(i.clone())}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,i=this.points.length;e<i;e++){const i=this.points[e];t.points.push(i.toArray())}return t.closed=this.closed,t.curveType=this.curveType,t.tension=this.tension,t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const i=t.points[e];this.points.push((new Di).fromArray(i))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function Ql(t,e,i,n,s){const r=.5*(n-e),a=.5*(s-i),o=t*t;return(2*i-2*n+r+a)*(t*o)+(-3*i+3*n-2*r-a)*o+r*t+i}function th(t,e,i,n){return function(t,e){const i=1-t;return i*i*e}(t,e)+function(t,e){return 2*(1-t)*t*e}(t,i)+function(t,e){return t*t*e}(t,n)}function eh(t,e,i,n,s){return function(t,e){const i=1-t;return i*i*i*e}(t,e)+function(t,e){const i=1-t;return 3*i*i*t*e}(t,i)+function(t,e){return 3*(1-t)*t*t*e}(t,n)+function(t,e){return t*t*t*e}(t,s)}Kl.prototype.isCatmullRomCurve3=!0;class ih extends Hl{constructor(t=new bi,e=new bi,i=new bi,n=new bi){super(),this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=i,this.v3=n}getPoint(t,e=new bi){const i=e,n=this.v0,s=this.v1,r=this.v2,a=this.v3;return i.set(eh(t,n.x,s.x,r.x,a.x),eh(t,n.y,s.y,r.y,a.y)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}ih.prototype.isCubicBezierCurve=!0;class nh extends Hl{constructor(t=new Di,e=new Di,i=new Di,n=new Di){super(),this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=i,this.v3=n}getPoint(t,e=new Di){const i=e,n=this.v0,s=this.v1,r=this.v2,a=this.v3;return i.set(eh(t,n.x,s.x,r.x,a.x),eh(t,n.y,s.y,r.y,a.y),eh(t,n.z,s.z,r.z,a.z)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this.v3.copy(t.v3),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t.v3=this.v3.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this.v3.fromArray(t.v3),this}}nh.prototype.isCubicBezierCurve3=!0;class sh extends Hl{constructor(t=new bi,e=new bi){super(),this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new bi){const i=e;return 1===t?i.copy(this.v2):(i.copy(this.v2).sub(this.v1),i.multiplyScalar(t).add(this.v1)),i}getPointAt(t,e){return this.getPoint(t,e)}getTangent(t,e){const i=e||new bi;return i.copy(this.v2).sub(this.v1).normalize(),i}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}sh.prototype.isLineCurve=!0;class rh extends Hl{constructor(t=new bi,e=new bi,i=new bi){super(),this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new bi){const i=e,n=this.v0,s=this.v1,r=this.v2;return i.set(th(t,n.x,s.x,r.x),th(t,n.y,s.y,r.y)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}rh.prototype.isQuadraticBezierCurve=!0;class ah extends Hl{constructor(t=new Di,e=new Di,i=new Di){super(),this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new Di){const i=e,n=this.v0,s=this.v1,r=this.v2;return i.set(th(t,n.x,s.x,r.x),th(t,n.y,s.y,r.y),th(t,n.z,s.z,r.z)),i}copy(t){return super.copy(t),this.v0.copy(t.v0),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v0=this.v0.toArray(),t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v0.fromArray(t.v0),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}}ah.prototype.isQuadraticBezierCurve3=!0;class oh extends Hl{constructor(t=[]){super(),this.type="SplineCurve",this.points=t}getPoint(t,e=new bi){const i=e,n=this.points,s=(n.length-1)*t,r=Math.floor(s),a=s-r,o=n[0===r?r:r-1],l=n[r],h=n[r>n.length-2?n.length-1:r+1],c=n[r>n.length-3?n.length-1:r+2];return i.set(Ql(a,o.x,l.x,h.x,c.x),Ql(a,o.y,l.y,h.y,c.y)),i}copy(t){super.copy(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const i=t.points[e];this.points.push(i.clone())}return this}toJSON(){const t=super.toJSON();t.points=[];for(let e=0,i=this.points.length;e<i;e++){const i=this.points[e];t.points.push(i.toArray())}return t}fromJSON(t){super.fromJSON(t),this.points=[];for(let e=0,i=t.points.length;e<i;e++){const i=t.points[e];this.points.push((new bi).fromArray(i))}return this}}oh.prototype.isSplineCurve=!0;var lh=Object.freeze({__proto__:null,ArcCurve:ql,CatmullRomCurve3:Kl,CubicBezierCurve:ih,CubicBezierCurve3:nh,EllipseCurve:jl,LineCurve:sh,LineCurve3:class extends Hl{constructor(t=new Di,e=new Di){super(),this.type="LineCurve3",this.isLineCurve3=!0,this.v1=t,this.v2=e}getPoint(t,e=new Di){const i=e;return 1===t?i.copy(this.v2):(i.copy(this.v2).sub(this.v1),i.multiplyScalar(t).add(this.v1)),i}getPointAt(t,e){return this.getPoint(t,e)}copy(t){return super.copy(t),this.v1.copy(t.v1),this.v2.copy(t.v2),this}toJSON(){const t=super.toJSON();return t.v1=this.v1.toArray(),t.v2=this.v2.toArray(),t}fromJSON(t){return super.fromJSON(t),this.v1.fromArray(t.v1),this.v2.fromArray(t.v2),this}},QuadraticBezierCurve:rh,QuadraticBezierCurve3:ah,SplineCurve:oh});class hh extends Hl{constructor(){super(),this.type="CurvePath",this.curves=[],this.autoClose=!1}add(t){this.curves.push(t)}closePath(){const t=this.curves[0].getPoint(0),e=this.curves[this.curves.length-1].getPoint(1);t.equals(e)||this.curves.push(new sh(e,t))}getPoint(t,e){const i=t*this.getLength(),n=this.getCurveLengths();let s=0;for(;s<n.length;){if(n[s]>=i){const t=n[s]-i,r=this.curves[s],a=r.getLength(),o=0===a?0:1-t/a;return r.getPointAt(o,e)}s++}return null}getLength(){const t=this.getCurveLengths();return t[t.length-1]}updateArcLengths(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()}getCurveLengths(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;const t=[];let e=0;for(let i=0,n=this.curves.length;i<n;i++)e+=this.curves[i].getLength(),t.push(e);return this.cacheLengths=t,t}getSpacedPoints(t=40){const e=[];for(let i=0;i<=t;i++)e.push(this.getPoint(i/t));return this.autoClose&&e.push(e[0]),e}getPoints(t=12){const e=[];let i;for(let n=0,s=this.curves;n<s.length;n++){const r=s[n],a=r&&r.isEllipseCurve?2*t:r&&(r.isLineCurve||r.isLineCurve3)?1:r&&r.isSplineCurve?t*r.points.length:t,o=r.getPoints(a);for(let t=0;t<o.length;t++){const n=o[t];i&&i.equals(n)||(e.push(n),i=n)}}return this.autoClose&&e.length>1&&!e[e.length-1].equals(e[0])&&e.push(e[0]),e}copy(t){super.copy(t),this.curves=[];for(let e=0,i=t.curves.length;e<i;e++){const i=t.curves[e];this.curves.push(i.clone())}return this.autoClose=t.autoClose,this}toJSON(){const t=super.toJSON();t.autoClose=this.autoClose,t.curves=[];for(let e=0,i=this.curves.length;e<i;e++){const i=this.curves[e];t.curves.push(i.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.autoClose=t.autoClose,this.curves=[];for(let e=0,i=t.curves.length;e<i;e++){const i=t.curves[e];this.curves.push((new lh[i.type]).fromJSON(i))}return this}}class ch extends hh{constructor(t){super(),this.type="Path",this.currentPoint=new bi,t&&this.setFromPoints(t)}setFromPoints(t){this.moveTo(t[0].x,t[0].y);for(let e=1,i=t.length;e<i;e++)this.lineTo(t[e].x,t[e].y);return this}moveTo(t,e){return this.currentPoint.set(t,e),this}lineTo(t,e){const i=new sh(this.currentPoint.clone(),new bi(t,e));return this.curves.push(i),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,i,n){const s=new rh(this.currentPoint.clone(),new bi(t,e),new bi(i,n));return this.curves.push(s),this.currentPoint.set(i,n),this}bezierCurveTo(t,e,i,n,s,r){const a=new ih(this.currentPoint.clone(),new bi(t,e),new bi(i,n),new bi(s,r));return this.curves.push(a),this.currentPoint.set(s,r),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),i=new oh(e);return this.curves.push(i),this.currentPoint.copy(t[t.length-1]),this}arc(t,e,i,n,s,r){const a=this.currentPoint.x,o=this.currentPoint.y;return this.absarc(t+a,e+o,i,n,s,r),this}absarc(t,e,i,n,s,r){return this.absellipse(t,e,i,i,n,s,r),this}ellipse(t,e,i,n,s,r,a,o){const l=this.currentPoint.x,h=this.currentPoint.y;return this.absellipse(t+l,e+h,i,n,s,r,a,o),this}absellipse(t,e,i,n,s,r,a,o){const l=new jl(t,e,i,n,s,r,a,o);if(this.curves.length>0){const t=l.getPoint(0);t.equals(this.currentPoint)||this.lineTo(t.x,t.y)}this.curves.push(l);const h=l.getPoint(1);return this.currentPoint.copy(h),this}copy(t){return super.copy(t),this.currentPoint.copy(t.currentPoint),this}toJSON(){const t=super.toJSON();return t.currentPoint=this.currentPoint.toArray(),t}fromJSON(t){return super.fromJSON(t),this.currentPoint.fromArray(t.currentPoint),this}}class uh extends ch{constructor(t){super(t),this.uuid=_i(),this.type="Shape",this.holes=[]}getPointsHoles(t){const e=[];for(let i=0,n=this.holes.length;i<n;i++)e[i]=this.holes[i].getPoints(t);return e}extractPoints(t){return{shape:this.getPoints(t),holes:this.getPointsHoles(t)}}copy(t){super.copy(t),this.holes=[];for(let e=0,i=t.holes.length;e<i;e++){const i=t.holes[e];this.holes.push(i.clone())}return this}toJSON(){const t=super.toJSON();t.uuid=this.uuid,t.holes=[];for(let e=0,i=this.holes.length;e<i;e++){const i=this.holes[e];t.holes.push(i.toJSON())}return t}fromJSON(t){super.fromJSON(t),this.uuid=t.uuid,this.holes=[];for(let e=0,i=t.holes.length;e<i;e++){const i=t.holes[e];this.holes.push((new ch).fromJSON(i))}return this}}function dh(t,e,i,n,s){let r,a;if(s===function(t,e,i,n){let s=0;for(let r=e,a=i-n;r<i;r+=n)s+=(t[a]-t[r])*(t[r+1]+t[a+1]),a=r;return s}(t,e,i,n)>0)for(r=e;r<i;r+=n)a=Ph(r,t[r],t[r+1],a);else for(r=i-n;r>=e;r-=n)a=Ph(r,t[r],t[r+1],a);return a&&Ah(a,a.next)&&(Fh(a),a=a.next),a}function ph(t,e){if(!t)return t;e||(e=t);let i,n=t;do{if(i=!1,n.steiner||!Ah(n,n.next)&&0!==Ch(n.prev,n,n.next))n=n.next;else{if(Fh(n),n=e=n.prev,n===n.next)break;i=!0}}while(i||n!==e);return e}function fh(t,e,i,n,s,r,a){if(!t)return;!a&&r&&function(t,e,i,n){let s=t;do{null===s.z&&(s.z=bh(s.x,s.y,e,i,n)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next}while(s!==t);s.prevZ.nextZ=null,s.prevZ=null,function(t){let e,i,n,s,r,a,o,l,h=1;do{for(i=t,t=null,r=null,a=0;i;){for(a++,n=i,o=0,e=0;e<h&&(o++,n=n.nextZ,n);e++);for(l=h;o>0||l>0&&n;)0!==o&&(0===l||!n||i.z<=n.z)?(s=i,i=i.nextZ,o--):(s=n,n=n.nextZ,l--),r?r.nextZ=s:t=s,s.prevZ=r,r=s;i=n}r.nextZ=null,h*=2}while(a>1)}(s)}(t,n,s,r);let o,l,h=t;for(;t.prev!==t.next;)if(o=t.prev,l=t.next,r?_h(t,n,s,r):mh(t))e.push(o.i/i),e.push(t.i/i),e.push(l.i/i),Fh(t),t=l.next,h=l.next;else if((t=l)===h){a?1===a?fh(t=gh(ph(t),e,i),e,i,n,s,r,2):2===a&&yh(t,e,i,n,s,r):fh(ph(t),e,i,n,s,r,1);break}}function mh(t){const e=t.prev,i=t,n=t.next;if(Ch(e,i,n)>=0)return!1;let s=t.next.next;for(;s!==t.prev;){if(Mh(e.x,e.y,i.x,i.y,n.x,n.y,s.x,s.y)&&Ch(s.prev,s,s.next)>=0)return!1;s=s.next}return!0}function _h(t,e,i,n){const s=t.prev,r=t,a=t.next;if(Ch(s,r,a)>=0)return!1;const o=s.x<r.x?s.x<a.x?s.x:a.x:r.x<a.x?r.x:a.x,l=s.y<r.y?s.y<a.y?s.y:a.y:r.y<a.y?r.y:a.y,h=s.x>r.x?s.x>a.x?s.x:a.x:r.x>a.x?r.x:a.x,c=s.y>r.y?s.y>a.y?s.y:a.y:r.y>a.y?r.y:a.y,u=bh(o,l,e,i,n),d=bh(h,c,e,i,n);let p=t.prevZ,f=t.nextZ;for(;p&&p.z>=u&&f&&f.z<=d;){if(p!==t.prev&&p!==t.next&&Mh(s.x,s.y,r.x,r.y,a.x,a.y,p.x,p.y)&&Ch(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,f!==t.prev&&f!==t.next&&Mh(s.x,s.y,r.x,r.y,a.x,a.y,f.x,f.y)&&Ch(f.prev,f,f.next)>=0)return!1;f=f.nextZ}for(;p&&p.z>=u;){if(p!==t.prev&&p!==t.next&&Mh(s.x,s.y,r.x,r.y,a.x,a.y,p.x,p.y)&&Ch(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;f&&f.z<=d;){if(f!==t.prev&&f!==t.next&&Mh(s.x,s.y,r.x,r.y,a.x,a.y,f.x,f.y)&&Ch(f.prev,f,f.next)>=0)return!1;f=f.nextZ}return!0}function gh(t,e,i){let n=t;do{const s=n.prev,r=n.next.next;!Ah(s,r)&&Eh(s,n,n.next,r)&&Nh(s,r)&&Nh(r,s)&&(e.push(s.i/i),e.push(n.i/i),e.push(r.i/i),Fh(n),Fh(n.next),n=t=r),n=n.next}while(n!==t);return ph(n)}function yh(t,e,i,n,s,r){let a=t;do{let t=a.next.next;for(;t!==a.prev;){if(a.i!==t.i&&Th(a,t)){let o=Lh(a,t);return a=ph(a,a.next),o=ph(o,o.next),fh(a,e,i,n,s,r),void fh(o,e,i,n,s,r)}t=t.next}a=a.next}while(a!==t)}function vh(t,e){return t.x-e.x}function xh(t,e){if(e=function(t,e){let i=e;const n=t.x,s=t.y;let r,a=-Infinity;do{if(s<=i.y&&s>=i.next.y&&i.next.y!==i.y){const t=i.x+(s-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(t<=n&&t>a){if(a=t,t===n){if(s===i.y)return i;if(s===i.next.y)return i.next}r=i.x<i.next.x?i:i.next}}i=i.next}while(i!==e);if(!r)return null;if(n===a)return r;const o=r,l=r.x,h=r.y;let c,u=Infinity;i=r;do{n>=i.x&&i.x>=l&&n!==i.x&&Mh(s<h?n:a,s,l,h,s<h?a:n,s,i.x,i.y)&&(c=Math.abs(s-i.y)/(n-i.x),Nh(i,t)&&(c<u||c===u&&(i.x>r.x||i.x===r.x&&wh(r,i)))&&(r=i,u=c)),i=i.next}while(i!==o);return r}(t,e),e){const i=Lh(e,t);ph(e,e.next),ph(i,i.next)}}function wh(t,e){return Ch(t.prev,t,e.prev)<0&&Ch(e.next,t,t.next)<0}function bh(t,e,i,n,s){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)*s)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-n)*s)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function Sh(t){let e=t,i=t;do{(e.x<i.x||e.x===i.x&&e.y<i.y)&&(i=e),e=e.next}while(e!==t);return i}function Mh(t,e,i,n,s,r,a,o){return(s-a)*(e-o)-(t-a)*(r-o)>=0&&(t-a)*(n-o)-(i-a)*(e-o)>=0&&(i-a)*(r-o)-(s-a)*(n-o)>=0}function Th(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){let i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==e.i&&i.next.i!==e.i&&Eh(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}(t,e)&&(Nh(t,e)&&Nh(e,t)&&function(t,e){let i=t,n=!1;const s=(t.x+e.x)/2,r=(t.y+e.y)/2;do{i.y>r!=i.next.y>r&&i.next.y!==i.y&&s<(i.next.x-i.x)*(r-i.y)/(i.next.y-i.y)+i.x&&(n=!n),i=i.next}while(i!==t);return n}(t,e)&&(Ch(t.prev,t,e.prev)||Ch(t,e.prev,e))||Ah(t,e)&&Ch(t.prev,t,t.next)>0&&Ch(e.prev,e,e.next)>0)}function Ch(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function Ah(t,e){return t.x===e.x&&t.y===e.y}function Eh(t,e,i,n){const s=Ih(Ch(t,e,i)),r=Ih(Ch(t,e,n)),a=Ih(Ch(i,n,t)),o=Ih(Ch(i,n,e));return s!==r&&a!==o||!(0!==s||!zh(t,i,e))||!(0!==r||!zh(t,n,e))||!(0!==a||!zh(i,t,n))||!(0!==o||!zh(i,e,n))}function zh(t,e,i){return e.x<=Math.max(t.x,i.x)&&e.x>=Math.min(t.x,i.x)&&e.y<=Math.max(t.y,i.y)&&e.y>=Math.min(t.y,i.y)}function Ih(t){return t>0?1:t<0?-1:0}function Nh(t,e){return Ch(t.prev,t,t.next)<0?Ch(t,e,t.next)>=0&&Ch(t,t.prev,e)>=0:Ch(t,e,t.prev)<0||Ch(t,t.next,e)<0}function Lh(t,e){const i=new Dh(t.i,t.x,t.y),n=new Dh(e.i,e.x,e.y),s=t.next,r=e.prev;return t.next=e,e.prev=t,i.next=s,s.prev=i,n.next=i,i.prev=n,r.next=n,n.prev=r,n}function Ph(t,e,i,n){const s=new Dh(t,e,i);return n?(s.next=n.next,s.prev=n,n.next.prev=s,n.next=s):(s.prev=s,s.next=s),s}function Fh(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Dh(t,e,i){this.i=t,this.x=e,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}class Oh{static area(t){const e=t.length;let i=0;for(let n=e-1,s=0;s<e;n=s++)i+=t[n].x*t[s].y-t[s].x*t[n].y;return.5*i}static isClockWise(t){return Oh.area(t)<0}static triangulateShape(t,e){const i=[],n=[],s=[];Rh(t),kh(i,t);let r=t.length;e.forEach(Rh);for(let t=0;t<e.length;t++)n.push(r),r+=e[t].length,kh(i,e[t]);const a=function(t,e,i=2){const n=e&&e.length,s=n?e[0]*i:t.length;let r=dh(t,0,s,i,!0);const a=[];if(!r||r.next===r.prev)return a;let o,l,h,c,u,d,p;if(n&&(r=function(t,e,i,n){const s=[];let r,a,o,l,h;for(r=0,a=e.length;r<a;r++)o=e[r]*n,l=r<a-1?e[r+1]*n:t.length,h=dh(t,o,l,n,!1),h===h.next&&(h.steiner=!0),s.push(Sh(h));for(s.sort(vh),r=0;r<s.length;r++)xh(s[r],i),i=ph(i,i.next);return i}(t,e,r,i)),t.length>80*i){o=h=t[0],l=c=t[1];for(let e=i;e<s;e+=i)u=t[e],d=t[e+1],u<o&&(o=u),d<l&&(l=d),u>h&&(h=u),d>c&&(c=d);p=Math.max(h-o,c-l),p=0!==p?1/p:0}return fh(r,a,i,o,l,p),a}(i,n);for(let t=0;t<a.length;t+=3)s.push(a.slice(t,t+3));return s}}function Rh(t){const e=t.length;e>2&&t[e-1].equals(t[0])&&t.pop()}function kh(t,e){for(let i=0;i<e.length;i++)t.push(e[i].x),t.push(e[i].y)}class Uh extends vs{constructor(t=new uh([new bi(.5,.5),new bi(-.5,.5),new bi(-.5,-.5),new bi(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const i=this,n=[],s=[];for(let e=0,i=t.length;e<i;e++)r(t[e]);function r(t){const r=[],a=void 0!==e.curveSegments?e.curveSegments:12,o=void 0!==e.steps?e.steps:1;let l=void 0!==e.depth?e.depth:1,h=void 0===e.bevelEnabled||e.bevelEnabled,c=void 0!==e.bevelThickness?e.bevelThickness:.2,u=void 0!==e.bevelSize?e.bevelSize:c-.1,d=void 0!==e.bevelOffset?e.bevelOffset:0,p=void 0!==e.bevelSegments?e.bevelSegments:3;const f=e.extrudePath,m=void 0!==e.UVGenerator?e.UVGenerator:Bh;void 0!==e.amount&&(l=e.amount);let _,g,y,v,x,w=!1;f&&(_=f.getSpacedPoints(o),w=!0,h=!1,g=f.computeFrenetFrames(o,!1),y=new Di,v=new Di,x=new Di),h||(p=0,c=0,u=0,d=0);const b=t.extractPoints(a);let S=b.shape;const M=b.holes;if(!Oh.isClockWise(S)){S=S.reverse();for(let t=0,e=M.length;t<e;t++){const e=M[t];Oh.isClockWise(e)&&(M[t]=e.reverse())}}const T=Oh.triangulateShape(S,M),C=S;for(let t=0,e=M.length;t<e;t++){const e=M[t];S=S.concat(e)}function A(t,e,i){return e.clone().multiplyScalar(i).add(t)}const E=S.length,z=T.length;function I(t,e,i){let n,s,r;const a=t.x-e.x,o=t.y-e.y,l=i.x-t.x,h=i.y-t.y,c=a*a+o*o,u=a*h-o*l;if(Math.abs(u)>Number.EPSILON){const u=Math.sqrt(c),d=Math.sqrt(l*l+h*h),p=e.x-o/u,f=e.y+a/u,m=((i.x-h/d-p)*h-(i.y+l/d-f)*l)/(a*h-o*l);n=p+a*m-t.x,s=f+o*m-t.y;const _=n*n+s*s;if(_<=2)return new bi(n,s);r=Math.sqrt(_/2)}else{let t=!1;a>Number.EPSILON?l>Number.EPSILON&&(t=!0):a<-Number.EPSILON?l<-Number.EPSILON&&(t=!0):Math.sign(o)===Math.sign(h)&&(t=!0),t?(n=-o,s=a,r=Math.sqrt(c)):(n=a,s=o,r=Math.sqrt(c/2))}return new bi(n/r,s/r)}const N=[];for(let t=0,e=C.length,i=e-1,n=t+1;t<e;t++,i++,n++)i===e&&(i=0),n===e&&(n=0),N[t]=I(C[t],C[i],C[n]);const L=[];let P,F=N.concat();for(let t=0,e=M.length;t<e;t++){const e=M[t];P=[];for(let t=0,i=e.length,n=i-1,s=t+1;t<i;t++,n++,s++)n===i&&(n=0),s===i&&(s=0),P[t]=I(e[t],e[n],e[s]);L.push(P),F=F.concat(P)}for(let t=0;t<p;t++){const e=t/p,i=c*Math.cos(e*Math.PI/2),n=u*Math.sin(e*Math.PI/2)+d;for(let t=0,e=C.length;t<e;t++){const e=A(C[t],N[t],n);R(e.x,e.y,-i)}for(let t=0,e=M.length;t<e;t++){const e=M[t];P=L[t];for(let t=0,s=e.length;t<s;t++){const s=A(e[t],P[t],n);R(s.x,s.y,-i)}}}const D=u+d;for(let t=0;t<E;t++){const e=h?A(S[t],F[t],D):S[t];w?(v.copy(g.normals[0]).multiplyScalar(e.x),y.copy(g.binormals[0]).multiplyScalar(e.y),x.copy(_[0]).add(v).add(y),R(x.x,x.y,x.z)):R(e.x,e.y,0)}for(let t=1;t<=o;t++)for(let e=0;e<E;e++){const i=h?A(S[e],F[e],D):S[e];w?(v.copy(g.normals[t]).multiplyScalar(i.x),y.copy(g.binormals[t]).multiplyScalar(i.y),x.copy(_[t]).add(v).add(y),R(x.x,x.y,x.z)):R(i.x,i.y,l/o*t)}for(let t=p-1;t>=0;t--){const e=t/p,i=c*Math.cos(e*Math.PI/2),n=u*Math.sin(e*Math.PI/2)+d;for(let t=0,e=C.length;t<e;t++){const e=A(C[t],N[t],n);R(e.x,e.y,l+i)}for(let t=0,e=M.length;t<e;t++){const e=M[t];P=L[t];for(let t=0,s=e.length;t<s;t++){const s=A(e[t],P[t],n);w?R(s.x,s.y+_[o-1].y,_[o-1].x+i):R(s.x,s.y,l+i)}}}function O(t,e){let i=t.length;for(;--i>=0;){const n=i;let s=i-1;s<0&&(s=t.length-1);for(let t=0,i=o+2*p;t<i;t++){const i=E*t,r=E*(t+1);U(e+n+i,e+s+i,e+s+r,e+n+r)}}}function R(t,e,i){r.push(t),r.push(e),r.push(i)}function k(t,e,s){B(t),B(e),B(s);const r=n.length/3,a=m.generateTopUV(i,n,r-3,r-2,r-1);V(a[0]),V(a[1]),V(a[2])}function U(t,e,s,r){B(t),B(e),B(r),B(e),B(s),B(r);const a=n.length/3,o=m.generateSideWallUV(i,n,a-6,a-3,a-2,a-1);V(o[0]),V(o[1]),V(o[3]),V(o[1]),V(o[2]),V(o[3])}function B(t){n.push(r[3*t+0]),n.push(r[3*t+1]),n.push(r[3*t+2])}function V(t){s.push(t.x),s.push(t.y)}!function(){const t=n.length/3;if(h){let t=0,e=E*t;for(let t=0;t<z;t++){const i=T[t];k(i[2]+e,i[1]+e,i[0]+e)}t=o+2*p,e=E*t;for(let t=0;t<z;t++){const i=T[t];k(i[0]+e,i[1]+e,i[2]+e)}}else{for(let t=0;t<z;t++){const e=T[t];k(e[2],e[1],e[0])}for(let t=0;t<z;t++){const e=T[t];k(e[0]+E*o,e[1]+E*o,e[2]+E*o)}}i.addGroup(t,n.length/3-t,0)}(),function(){const t=n.length/3;let e=0;O(C,e),e+=C.length;for(let t=0,i=M.length;t<i;t++){const i=M[t];O(i,e),e+=i.length}i.addGroup(t,n.length/3-t,1)}()}this.setAttribute("position",new us(n,3)),this.setAttribute("uv",new us(s,2)),this.computeVertexNormals()}toJSON(){const t=super.toJSON();return function(t,e,i){if(i.shapes=[],Array.isArray(t))for(let e=0,n=t.length;e<n;e++){const n=t[e];i.shapes.push(n.uuid)}else i.shapes.push(t.uuid);return void 0!==e.extrudePath&&(i.options.extrudePath=e.extrudePath.toJSON()),i}(this.parameters.shapes,this.parameters.options,t)}static fromJSON(t,e){const i=[];for(let n=0,s=t.shapes.length;n<s;n++){const s=e[t.shapes[n]];i.push(s)}const n=t.options.extrudePath;return void 0!==n&&(t.options.extrudePath=(new lh[n.type]).fromJSON(n)),new Uh(i,t.options)}}const Bh={generateTopUV:function(t,e,i,n,s){const r=e[3*i],a=e[3*i+1],o=e[3*n],l=e[3*n+1],h=e[3*s],c=e[3*s+1];return[new bi(r,a),new bi(o,l),new bi(h,c)]},generateSideWallUV:function(t,e,i,n,s,r){const a=e[3*i],o=e[3*i+1],l=e[3*i+2],h=e[3*n],c=e[3*n+1],u=e[3*n+2],d=e[3*s],p=e[3*s+1],f=e[3*s+2],m=e[3*r],_=e[3*r+1],g=e[3*r+2];return Math.abs(o-c)<Math.abs(a-h)?[new bi(a,1-l),new bi(h,1-u),new bi(d,1-f),new bi(m,1-g)]:[new bi(o,1-l),new bi(c,1-u),new bi(p,1-f),new bi(_,1-g)]}};class Vh extends vs{constructor(t=new uh([new bi(0,.5),new bi(-.5,-.5),new bi(.5,-.5)]),e=12){super(),this.type="ShapeGeometry",this.parameters={shapes:t,curveSegments:e};const i=[],n=[],s=[],r=[];let a=0,o=0;if(!1===Array.isArray(t))l(t);else for(let e=0;e<t.length;e++)l(t[e]),this.addGroup(a,o,e),a+=o,o=0;function l(t){const a=n.length/3,l=t.extractPoints(e);let h=l.shape;const c=l.holes;!1===Oh.isClockWise(h)&&(h=h.reverse());for(let t=0,e=c.length;t<e;t++){const e=c[t];!0===Oh.isClockWise(e)&&(c[t]=e.reverse())}const u=Oh.triangulateShape(h,c);for(let t=0,e=c.length;t<e;t++){const e=c[t];h=h.concat(e)}for(let t=0,e=h.length;t<e;t++){const e=h[t];n.push(e.x,e.y,0),s.push(0,0,1),r.push(e.x,e.y)}for(let t=0,e=u.length;t<e;t++){const e=u[t],n=e[0]+a,s=e[1]+a,r=e[2]+a;i.push(n,s,r),o+=3}}this.setIndex(i),this.setAttribute("position",new us(n,3)),this.setAttribute("normal",new us(s,3)),this.setAttribute("uv",new us(r,2))}toJSON(){const t=super.toJSON();return function(t,e){if(e.shapes=[],Array.isArray(t))for(let i=0,n=t.length;i<n;i++){const n=t[i];e.shapes.push(n.uuid)}else e.shapes.push(t.uuid);return e}(this.parameters.shapes,t)}static fromJSON(t,e){const i=[];for(let n=0,s=t.shapes.length;n<s;n++){const s=e[t.shapes[n]];i.push(s)}return new Vh(i,t.curveSegments)}}(class extends $n{constructor(t){super(),this.type="ShadowMaterial",this.color=new ss(0),this.transparent=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this}}).prototype.isShadowMaterial=!0;class Gh extends $n{constructor(t){super(),this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new ss(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 ss(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ai,this.normalScale=new bi(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.defines={STANDARD:""},this.color.copy(t.color),this.roughness=t.roughness,this.metalness=t.metalness,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.roughnessMap=t.roughnessMap,this.metalnessMap=t.metalnessMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapIntensity=t.envMapIntensity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this}}Gh.prototype.isMeshStandardMaterial=!0,class extends Gh{constructor(t){super(),this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new bi(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return gi(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.sheenColor=new ss(0),this.sheenColorMap=null,this.sheenRoughness=1,this.sheenRoughnessMap=null,this.transmissionMap=null,this.thickness=0,this.thicknessMap=null,this.attenuationDistance=0,this.attenuationColor=new ss(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new ss(1,1,1),this.specularColorMap=null,this._sheen=0,this._clearcoat=0,this._transmission=0,this.setValues(t)}get sheen(){return this._sheen}set sheen(t){this._sheen>0!=t>0&&this.version++,this._sheen=t}get clearcoat(){return this._clearcoat}set clearcoat(t){this._clearcoat>0!=t>0&&this.version++,this._clearcoat=t}get transmission(){return this._transmission}set transmission(t){this._transmission>0!=t>0&&this.version++,this._transmission=t}copy(t){return super.copy(t),this.defines={STANDARD:"",PHYSICAL:""},this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.ior=t.ior,this.sheen=t.sheen,this.sheenColor.copy(t.sheenColor),this.sheenColorMap=t.sheenColorMap,this.sheenRoughness=t.sheenRoughness,this.sheenRoughnessMap=t.sheenRoughnessMap,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this.thickness=t.thickness,this.thicknessMap=t.thicknessMap,this.attenuationDistance=t.attenuationDistance,this.attenuationColor.copy(t.attenuationColor),this.specularIntensity=t.specularIntensity,this.specularIntensityMap=t.specularIntensityMap,this.specularColor.copy(t.specularColor),this.specularColorMap=t.specularColorMap,this}}.prototype.isMeshPhysicalMaterial=!0;class Wh extends $n{constructor(t){super(),this.type="MeshPhongMaterial",this.color=new ss(16777215),this.specular=new ss(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ss(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ai,this.normalScale=new bi(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=ct,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.flatShading=t.flatShading,this}}Wh.prototype.isMeshPhongMaterial=!0,class extends $n{constructor(t){super(),this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new ss(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ss(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ai,this.normalScale=new bi(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.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.gradientMap=t.gradientMap,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this}}.prototype.isMeshToonMaterial=!0;class Hh extends $n{constructor(t){super(),this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ai,this.normalScale=new bi(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.flatShading=t.flatShading,this}}Hh.prototype.isMeshNormalMaterial=!0,class extends $n{constructor(t){super(),this.type="MeshLambertMaterial",this.color=new ss(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new ss(0),this.emissiveIntensity=1,this.emissiveMap=null,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=ct,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this}}.prototype.isMeshLambertMaterial=!0,class extends $n{constructor(t){super(),this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new ss(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=ai,this.normalScale=new bi(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.flatShading=!1,this.setValues(t)}copy(t){return super.copy(t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.flatShading=t.flatShading,this}}.prototype.isMeshMatcapMaterial=!0,class extends Al{constructor(t){super(),this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}copy(t){return super.copy(t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this}}.prototype.isLineDashedMaterial=!0;const jh={arraySlice:function(t,e,i){return jh.isTypedArray(t)?new t.constructor(t.subarray(e,void 0!==i?i:t.length)):t.slice(e,i)},convertArray:function(t,e,i){return!t||!i&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)},isTypedArray:function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)},getKeyframeOrder:function(t){const e=t.length,i=new Array(e);for(let t=0;t!==e;++t)i[t]=t;return i.sort((function(e,i){return t[e]-t[i]})),i},sortedArray:function(t,e,i){const n=t.length,s=new t.constructor(n);for(let r=0,a=0;a!==n;++r){const n=i[r]*e;for(let i=0;i!==e;++i)s[a++]=t[n+i]}return s},flattenJSON:function(t,e,i,n){let s=1,r=t[0];for(;void 0!==r&&void 0===r[n];)r=t[s++];if(void 0===r)return;let a=r[n];if(void 0!==a)if(Array.isArray(a))do{a=r[n],void 0!==a&&(e.push(r.time),i.push.apply(i,a)),r=t[s++]}while(void 0!==r);else if(void 0!==a.toArray)do{a=r[n],void 0!==a&&(e.push(r.time),a.toArray(i,i.length)),r=t[s++]}while(void 0!==r);else do{a=r[n],void 0!==a&&(e.push(r.time),i.push(a)),r=t[s++]}while(void 0!==r)},subclip:function(t,e,i,n,s=30){const r=t.clone();r.name=e;const a=[];for(let t=0;t<r.tracks.length;++t){const e=r.tracks[t],o=e.getValueSize(),l=[],h=[];for(let t=0;t<e.times.length;++t){const r=e.times[t]*s;if(!(r<i||r>=n)){l.push(e.times[t]);for(let i=0;i<o;++i)h.push(e.values[t*o+i])}}0!==l.length&&(e.times=jh.convertArray(l,e.times.constructor),e.values=jh.convertArray(h,e.values.constructor),a.push(e))}r.tracks=a;let o=Infinity;for(let t=0;t<r.tracks.length;++t)o>r.tracks[t].times[0]&&(o=r.tracks[t].times[0]);for(let t=0;t<r.tracks.length;++t)r.tracks[t].shift(-1*o);return r.resetDuration(),r},makeClipAdditive:function(t,e=0,i=t,n=30){n<=0&&(n=30);const s=i.tracks.length,r=e/n;for(let e=0;e<s;++e){const n=i.tracks[e],s=n.ValueTypeName;if("bool"===s||"string"===s)continue;const a=t.tracks.find((function(t){return t.name===n.name&&t.ValueTypeName===s}));if(void 0===a)continue;let o=0;const l=n.getValueSize();n.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(o=l/3);let h=0;const c=a.getValueSize();a.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline&&(h=c/3);const u=n.times.length-1;let d;if(r<=n.times[0]){const t=o,e=l-o;d=jh.arraySlice(n.values,t,e)}else if(r>=n.times[u]){const t=u*l+o,e=t+l-o;d=jh.arraySlice(n.values,t,e)}else{const t=n.createInterpolant(),e=o,i=l-o;t.evaluate(r),d=jh.arraySlice(t.resultBuffer,e,i)}"quaternion"===s&&(new Fi).fromArray(d).normalize().conjugate().toArray(d);const p=a.times.length;for(let t=0;t<p;++t){const e=t*c+h;if("quaternion"===s)Fi.multiplyQuaternionsFlat(a.values,e,d,0,a.values,e);else{const t=c-2*h;for(let i=0;i<t;++i)a.values[e+i]-=d[i]}}}return t.blendMode=2501,t}};class qh{constructor(t,e,i,n){this.parameterPositions=t,this._cachedIndex=0,this.resultBuffer=void 0!==n?n:new e.constructor(i),this.sampleValues=e,this.valueSize=i,this.settings=null,this.DefaultSettings_={}}evaluate(t){const e=this.parameterPositions;let i=this._cachedIndex,n=e[i],s=e[i-1];t:{e:{let r;i:{n:if(!(t<n)){for(let r=i+2;;){if(void 0===n){if(t<s)break n;return i=e.length,this._cachedIndex=i,this.afterEnd_(i-1,t,s)}if(i===r)break;if(s=n,n=e[++i],t<n)break e}r=e.length;break i}if(t>=s)break t;{const a=e[1];t<a&&(i=2,s=a);for(let r=i-2;;){if(void 0===s)return this._cachedIndex=0,this.beforeStart_(0,t,n);if(i===r)break;if(n=s,s=e[--i-1],t>=s)break e}r=i,i=0}}for(;i<r;){const n=i+r>>>1;t<e[n]?r=n:i=n+1}if(n=e[i],s=e[i-1],void 0===s)return this._cachedIndex=0,this.beforeStart_(0,t,n);if(void 0===n)return i=e.length,this._cachedIndex=i,this.afterEnd_(i-1,s,t)}this._cachedIndex=i,this.intervalChanged_(i,s,n)}return this.interpolate_(i,s,t,n)}getSettings_(){return this.settings||this.DefaultSettings_}copySampleValue_(t){const e=this.resultBuffer,i=this.sampleValues,n=this.valueSize,s=t*n;for(let t=0;t!==n;++t)e[t]=i[s+t];return e}interpolate_(){throw new Error("call to abstract method")}intervalChanged_(){}}qh.prototype.beforeStart_=qh.prototype.copySampleValue_,qh.prototype.afterEnd_=qh.prototype.copySampleValue_;class Jh extends qh{constructor(t,e,i,n){super(t,e,i,n),this._weightPrev=-0,this._offsetPrev=-0,this._weightNext=-0,this._offsetNext=-0,this.DefaultSettings_={endingStart:Xe,endingEnd:Xe}}intervalChanged_(t,e,i){const n=this.parameterPositions;let s=t-2,r=t+1,a=n[s],o=n[r];if(void 0===a)switch(this.getSettings_().endingStart){case Ze:s=t,a=2*e-i;break;case $e:s=n.length-2,a=e+n[s]-n[s+1];break;default:s=t,a=i}if(void 0===o)switch(this.getSettings_().endingEnd){case Ze:r=t,o=2*i-e;break;case $e:r=1,o=i+n[1]-n[0];break;default:r=t-1,o=e}const l=.5*(i-e),h=this.valueSize;this._weightPrev=l/(e-a),this._weightNext=l/(o-i),this._offsetPrev=s*h,this._offsetNext=r*h}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=t*a,l=o-a,h=this._offsetPrev,c=this._offsetNext,u=this._weightPrev,d=this._weightNext,p=(i-e)/(n-e),f=p*p,m=f*p,_=-u*m+2*u*f-u*p,g=(1+u)*m+(-1.5-2*u)*f+(-.5+u)*p+1,y=(-1-d)*m+(1.5+d)*f+.5*p,v=d*m-d*f;for(let t=0;t!==a;++t)s[t]=_*r[h+t]+g*r[l+t]+y*r[o+t]+v*r[c+t];return s}}class Yh extends qh{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=t*a,l=o-a,h=(i-e)/(n-e),c=1-h;for(let t=0;t!==a;++t)s[t]=r[l+t]*c+r[o+t]*h;return s}}class Xh extends qh{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t){return this.copySampleValue_(t-1)}}class Zh{constructor(t,e,i,n){if(void 0===t)throw new Error("THREE.KeyframeTrack: track name is undefined");if(void 0===e||0===e.length)throw new Error("THREE.KeyframeTrack: no keyframes in track named "+t);this.name=t,this.times=jh.convertArray(e,this.TimeBufferType),this.values=jh.convertArray(i,this.ValueBufferType),this.setInterpolation(n||this.DefaultInterpolation)}static toJSON(t){const e=t.constructor;let i;if(e.toJSON!==this.toJSON)i=e.toJSON(t);else{i={name:t.name,times:jh.convertArray(t.times,Array),values:jh.convertArray(t.values,Array)};const e=t.getInterpolation();e!==t.DefaultInterpolation&&(i.interpolation=e)}return i.type=t.ValueTypeName,i}InterpolantFactoryMethodDiscrete(t){return new Xh(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodLinear(t){return new Yh(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodSmooth(t){return new Jh(this.times,this.values,this.getValueSize(),t)}setInterpolation(t){let e;switch(t){case qe:e=this.InterpolantFactoryMethodDiscrete;break;case Je:e=this.InterpolantFactoryMethodLinear;break;case Ye:e=this.InterpolantFactoryMethodSmooth}if(void 0===e){const e="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(void 0===this.createInterpolant){if(t===this.DefaultInterpolation)throw new Error(e);this.setInterpolation(this.DefaultInterpolation)}return this}return this.createInterpolant=e,this}getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return qe;case this.InterpolantFactoryMethodLinear:return Je;case this.InterpolantFactoryMethodSmooth:return Ye}}getValueSize(){return this.values.length/this.times.length}shift(t){if(0!==t){const e=this.times;for(let i=0,n=e.length;i!==n;++i)e[i]+=t}return this}scale(t){if(1!==t){const e=this.times;for(let i=0,n=e.length;i!==n;++i)e[i]*=t}return this}trim(t,e){const i=this.times,n=i.length;let s=0,r=n-1;for(;s!==n&&i[s]<t;)++s;for(;-1!==r&&i[r]>e;)--r;if(++r,0!==s||r!==n){s>=r&&(r=Math.max(r,1),s=r-1);const t=this.getValueSize();this.times=jh.arraySlice(i,s,r),this.values=jh.arraySlice(this.values,s*t,r*t)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!=0&&(t=!1);const i=this.times,n=this.values,s=i.length;0===s&&(t=!1);let r=null;for(let e=0;e!==s;e++){const n=i[e];if("number"==typeof n&&isNaN(n)){t=!1;break}if(null!==r&&r>n){t=!1;break}r=n}if(void 0!==n&&jh.isTypedArray(n))for(let e=0,i=n.length;e!==i;++e){const i=n[e];if(isNaN(i)){t=!1;break}}return t}optimize(){const t=jh.arraySlice(this.times),e=jh.arraySlice(this.values),i=this.getValueSize(),n=this.getInterpolation()===Ye,s=t.length-1;let r=1;for(let a=1;a<s;++a){let s=!1;const o=t[a];if(o!==t[a+1]&&(1!==a||o!==t[0]))if(n)s=!0;else{const t=a*i,n=t-i,r=t+i;for(let a=0;a!==i;++a){const i=e[t+a];if(i!==e[n+a]||i!==e[r+a]){s=!0;break}}}if(s){if(a!==r){t[r]=t[a];const n=a*i,s=r*i;for(let t=0;t!==i;++t)e[s+t]=e[n+t]}++r}}if(s>0){t[r]=t[s];for(let t=s*i,n=r*i,a=0;a!==i;++a)e[n+a]=e[t+a];++r}return r!==t.length?(this.times=jh.arraySlice(t,0,r),this.values=jh.arraySlice(e,0,r*i)):(this.times=t,this.values=e),this}clone(){const t=jh.arraySlice(this.times,0),e=jh.arraySlice(this.values,0),i=new(0,this.constructor)(this.name,t,e);return i.createInterpolant=this.createInterpolant,i}}Zh.prototype.TimeBufferType=Float32Array,Zh.prototype.ValueBufferType=Float32Array,Zh.prototype.DefaultInterpolation=Je;class $h extends Zh{}$h.prototype.ValueTypeName="bool",$h.prototype.ValueBufferType=Array,$h.prototype.DefaultInterpolation=qe,$h.prototype.InterpolantFactoryMethodLinear=void 0,$h.prototype.InterpolantFactoryMethodSmooth=void 0;class Kh extends Zh{}Kh.prototype.ValueTypeName="color";class Qh extends Zh{}Qh.prototype.ValueTypeName="number";class tc extends qh{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t,e,i,n){const s=this.resultBuffer,r=this.sampleValues,a=this.valueSize,o=(i-e)/(n-e);let l=t*a;for(let t=l+a;l!==t;l+=4)Fi.slerpFlat(s,0,r,l-a,r,l,o);return s}}class ec extends Zh{InterpolantFactoryMethodLinear(t){return new tc(this.times,this.values,this.getValueSize(),t)}}ec.prototype.ValueTypeName="quaternion",ec.prototype.DefaultInterpolation=Je,ec.prototype.InterpolantFactoryMethodSmooth=void 0;class ic extends Zh{}ic.prototype.ValueTypeName="string",ic.prototype.ValueBufferType=Array,ic.prototype.DefaultInterpolation=qe,ic.prototype.InterpolantFactoryMethodLinear=void 0,ic.prototype.InterpolantFactoryMethodSmooth=void 0;class nc extends Zh{}nc.prototype.ValueTypeName="vector";class sc{constructor(t,e=-1,i,n=2500){this.name=t,this.tracks=i,this.duration=e,this.blendMode=n,this.uuid=_i(),this.duration<0&&this.resetDuration()}static parse(t){const e=[],i=t.tracks,n=1/(t.fps||1);for(let t=0,s=i.length;t!==s;++t)e.push(rc(i[t]).scale(n));const s=new this(t.name,t.duration,e,t.blendMode);return s.uuid=t.uuid,s}static toJSON(t){const e=[],i=t.tracks,n={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode};for(let t=0,n=i.length;t!==n;++t)e.push(Zh.toJSON(i[t]));return n}static CreateFromMorphTargetSequence(t,e,i,n){const s=e.length,r=[];for(let t=0;t<s;t++){let a=[],o=[];a.push((t+s-1)%s,t,(t+1)%s),o.push(0,1,0);const l=jh.getKeyframeOrder(a);a=jh.sortedArray(a,1,l),o=jh.sortedArray(o,1,l),n||0!==a[0]||(a.push(s),o.push(o[0])),r.push(new Qh(".morphTargetInfluences["+e[t].name+"]",a,o).scale(1/i))}return new this(t,-1,r)}static findByName(t,e){let i=t;if(!Array.isArray(t)){const e=t;i=e.geometry&&e.geometry.animations||e.animations}for(let t=0;t<i.length;t++)if(i[t].name===e)return i[t];return null}static CreateClipsFromMorphTargetSequences(t,e,i){const n={},s=/^([\w-]*?)([\d]+)$/;for(let e=0,i=t.length;e<i;e++){const i=t[e],r=i.name.match(s);if(r&&r.length>1){const t=r[1];let e=n[t];e||(n[t]=e=[]),e.push(i)}}const r=[];for(const t in n)r.push(this.CreateFromMorphTargetSequence(t,n[t],e,i));return r}static parseAnimation(t,e){if(!t)return null;const i=function(t,e,i,n,s){if(0!==i.length){const r=[],a=[];jh.flattenJSON(i,r,a,n),0!==r.length&&s.push(new t(e,r,a))}},n=[],s=t.name||"default",r=t.fps||30,a=t.blendMode;let o=t.length||-1;const l=t.hierarchy||[];for(let t=0;t<l.length;t++){const s=l[t].keys;if(s&&0!==s.length)if(s[0].morphTargets){const t={};let e;for(e=0;e<s.length;e++)if(s[e].morphTargets)for(let i=0;i<s[e].morphTargets.length;i++)t[s[e].morphTargets[i]]=-1;for(const i in t){const t=[],r=[];for(let n=0;n!==s[e].morphTargets.length;++n){const n=s[e];t.push(n.time),r.push(n.morphTarget===i?1:0)}n.push(new Qh(".morphTargetInfluence["+i+"]",t,r))}o=t.length*(r||1)}else{const r=".bones["+e[t].name+"]";i(nc,r+".position",s,"pos",n),i(ec,r+".quaternion",s,"rot",n),i(nc,r+".scale",s,"scl",n)}}return 0===n.length?null:new this(s,o,n,a)}resetDuration(){let t=0;for(let e=0,i=this.tracks.length;e!==i;++e){const i=this.tracks[e];t=Math.max(t,i.times[i.times.length-1])}return this.duration=t,this}trim(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].trim(0,this.duration);return this}validate(){let t=!0;for(let e=0;e<this.tracks.length;e++)t=t&&this.tracks[e].validate();return t}optimize(){for(let t=0;t<this.tracks.length;t++)this.tracks[t].optimize();return this}clone(){const t=[];for(let e=0;e<this.tracks.length;e++)t.push(this.tracks[e].clone());return new this.constructor(this.name,this.duration,t,this.blendMode)}toJSON(){return this.constructor.toJSON(this)}}function rc(t){if(void 0===t.type)throw new Error("THREE.KeyframeTrack: track type undefined, can not parse");const e=function(t){switch(t.toLowerCase()){case"scalar":case"double":case"float":case"number":case"integer":return Qh;case"vector":case"vector2":case"vector3":case"vector4":return nc;case"color":return Kh;case"quaternion":return ec;case"bool":case"boolean":return $h;case"string":return ic}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+t)}(t.type);if(void 0===t.times){const e=[],i=[];jh.flattenJSON(t.keys,e,i,"value"),t.times=e,t.values=i}return void 0!==e.parse?e.parse(t):new e(t.name,t.times,t.values,t.interpolation)}const ac={enabled:!1,files:{},add:function(t,e){!1!==this.enabled&&(this.files[t]=e)},get:function(t){if(!1!==this.enabled)return this.files[t]},remove:function(t){delete this.files[t]},clear:function(){this.files={}}},oc=new class{constructor(t,e,i){const n=this;let s,r=!1,a=0,o=0;const l=[];this.onStart=void 0,this.onLoad=t,this.onProgress=e,this.onError=i,this.itemStart=function(t){o++,!1===r&&void 0!==n.onStart&&n.onStart(t,a,o),r=!0},this.itemEnd=function(t){a++,void 0!==n.onProgress&&n.onProgress(t,a,o),a===o&&(r=!1,void 0!==n.onLoad&&n.onLoad())},this.itemError=function(t){void 0!==n.onError&&n.onError(t)},this.resolveURL=function(t){return s?s(t):t},this.setURLModifier=function(t){return s=t,this},this.addHandler=function(t,e){return l.push(t,e),this},this.removeHandler=function(t){const e=l.indexOf(t);return-1!==e&&l.splice(e,2),this},this.getHandler=function(t){for(let e=0,i=l.length;e<i;e+=2){const i=l[e],n=l[e+1];if(i.global&&(i.lastIndex=0),i.test(t))return n}return null}}};class lc{constructor(t){this.manager=void 0!==t?t:oc,this.crossOrigin="anonymous",this.withCredentials=!1,this.path="",this.resourcePath="",this.requestHeader={}}load(){}loadAsync(t,e){const i=this;return new Promise((function(n,s){i.load(t,n,e,s)}))}parse(){}setCrossOrigin(t){return this.crossOrigin=t,this}setWithCredentials(t){return this.withCredentials=t,this}setPath(t){return this.path=t,this}setResourcePath(t){return this.resourcePath=t,this}setRequestHeader(t){return this.requestHeader=t,this}}const hc={};class cc extends lc{constructor(t){super(t)}load(t,e,i,n){void 0===t&&(t=""),void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const s=ac.get(t);if(void 0!==s)return this.manager.itemStart(t),setTimeout((()=>{e&&e(s),this.manager.itemEnd(t)}),0),s;if(void 0!==hc[t])return void hc[t].push({onLoad:e,onProgress:i,onError:n});hc[t]=[],hc[t].push({onLoad:e,onProgress:i,onError:n});const r=new Request(t,{headers:new Headers(this.requestHeader),credentials:this.withCredentials?"include":"same-origin"});fetch(r).then((e=>{if(200===e.status||0===e.status){e.status;const i=hc[t],n=e.body.getReader(),s=e.headers.get("Content-Length"),r=s?parseInt(s):0,a=0!==r;let o=0;return new ReadableStream({start(t){!function e(){n.read().then((({done:n,value:s})=>{if(n)t.close();else{o+=s.byteLength;const n=new ProgressEvent("progress",{lengthComputable:a,loaded:o,total:r});for(let t=0,e=i.length;t<e;t++){const e=i[t];e.onProgress&&e.onProgress(n)}t.enqueue(s),e()}}))}()}})}throw Error(`fetch for "${e.url}" responded with ${e.status}: ${e.statusText}`)})).then((t=>{const e=new Response(t);switch(this.responseType){case"arraybuffer":return e.arrayBuffer();case"blob":return e.blob();case"document":return e.text().then((t=>(new DOMParser).parseFromString(t,this.mimeType)));case"json":return e.json();default:return e.text()}})).then((e=>{ac.add(t,e);const i=hc[t];delete hc[t];for(let t=0,n=i.length;t<n;t++){const n=i[t];n.onLoad&&n.onLoad(e)}this.manager.itemEnd(t)})).catch((e=>{const i=hc[t];delete hc[t];for(let t=0,n=i.length;t<n;t++){const n=i[t];n.onError&&n.onError(e)}this.manager.itemError(t),this.manager.itemEnd(t)})),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}}class uc extends lc{constructor(t){super(t)}load(t,e,i,n){void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const s=this,r=ac.get(t);if(void 0!==r)return s.manager.itemStart(t),setTimeout((function(){e&&e(r),s.manager.itemEnd(t)}),0),r;const a=Ti("img");function o(){h(),ac.add(t,this),e&&e(this),s.manager.itemEnd(t)}function l(e){h(),n&&n(e),s.manager.itemError(t),s.manager.itemEnd(t)}function h(){a.removeEventListener("load",o,!1),a.removeEventListener("error",l,!1)}return a.addEventListener("load",o,!1),a.addEventListener("error",l,!1),"data:"!==t.substr(0,5)&&void 0!==this.crossOrigin&&(a.crossOrigin=this.crossOrigin),s.manager.itemStart(t),a.src=t,a}}class dc extends lc{constructor(t){super(t)}load(t,e,i,n){const s=new Ys,r=new uc(this.manager);r.setCrossOrigin(this.crossOrigin),r.setPath(this.path);let a=0;function o(i){r.load(t[i],(function(t){s.images[i]=t,a++,6===a&&(s.needsUpdate=!0,e&&e(s))}),void 0,n)}for(let e=0;e<t.length;++e)o(e);return s}}class pc extends lc{constructor(t){super(t)}load(t,e,i,n){const s=this,r=new wl,a=new cc(this.manager);return a.setResponseType("arraybuffer"),a.setRequestHeader(this.requestHeader),a.setPath(this.path),a.setWithCredentials(s.withCredentials),a.load(t,(function(t){const i=s.parse(t);i&&(void 0!==i.image?r.image=i.image:void 0!==i.data&&(r.image.width=i.width,r.image.height=i.height,r.image.data=i.data),r.wrapS=void 0!==i.wrapS?i.wrapS:Ct,r.wrapT=void 0!==i.wrapT?i.wrapT:Ct,r.magFilter=void 0!==i.magFilter?i.magFilter:Nt,r.minFilter=void 0!==i.minFilter?i.minFilter:Nt,r.anisotropy=void 0!==i.anisotropy?i.anisotropy:1,void 0!==i.encoding&&(r.encoding=i.encoding),void 0!==i.flipY&&(r.flipY=i.flipY),void 0!==i.format&&(r.format=i.format),void 0!==i.type&&(r.type=i.type),void 0!==i.mipmaps&&(r.mipmaps=i.mipmaps,r.minFilter=Pt),1===i.mipmapCount&&(r.minFilter=Nt),void 0!==i.generateMipmaps&&(r.generateMipmaps=i.generateMipmaps),r.needsUpdate=!0,e&&e(r,i))}),i,n),r}}class fc extends lc{constructor(t){super(t)}load(t,e,i,n){const s=new zi,r=new uc(this.manager);return r.setCrossOrigin(this.crossOrigin),r.setPath(this.path),r.load(t,(function(t){s.image=t,s.needsUpdate=!0,void 0!==e&&e(s)}),i,n),s}}let mc=class extends kn{constructor(t,e=1){super(),this.type="Light",this.color=new ss(t),this.intensity=e}dispose(){}copy(t){return super.copy(t),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,void 0!==this.groundColor&&(e.object.groundColor=this.groundColor.getHex()),void 0!==this.distance&&(e.object.distance=this.distance),void 0!==this.angle&&(e.object.angle=this.angle),void 0!==this.decay&&(e.object.decay=this.decay),void 0!==this.penumbra&&(e.object.penumbra=this.penumbra),void 0!==this.shadow&&(e.object.shadow=this.shadow.toJSON()),e}};mc.prototype.isLight=!0,class extends mc{constructor(t,e,i){super(t,i),this.type="HemisphereLight",this.position.copy(kn.DefaultUp),this.updateMatrix(),this.groundColor=new ss(e)}copy(t){return mc.prototype.copy.call(this,t),this.groundColor.copy(t.groundColor),this}}.prototype.isHemisphereLight=!0;const _c=new pn,gc=new Di,yc=new Di;class vc{constructor(t){this.camera=t,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new bi(512,512),this.map=null,this.mapPass=null,this.matrix=new pn,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new ir,this._frameExtents=new bi(1,1),this._viewportCount=1,this._viewports=[new Ni(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,i=this.matrix;gc.setFromMatrixPosition(t.matrixWorld),e.position.copy(gc),yc.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(yc),e.updateMatrixWorld(),_c.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(_c),i.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),i.multiply(e.projectionMatrix),i.multiply(e.matrixWorldInverse)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.bias=t.bias,this.radius=t.radius,this.mapSize.copy(t.mapSize),this}clone(){return(new this.constructor).copy(this)}toJSON(){const t={};return 0!==this.bias&&(t.bias=this.bias),0!==this.normalBias&&(t.normalBias=this.normalBias),1!==this.radius&&(t.radius=this.radius),512===this.mapSize.x&&512===this.mapSize.y||(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}class xc extends vc{constructor(){super(new js(50,1,.5,500)),this.focus=1}updateMatrices(t){const e=this.camera,i=2*mi*t.angle*this.focus,n=this.mapSize.width/this.mapSize.height,s=t.distance||e.far;i===e.fov&&n===e.aspect&&s===e.far||(e.fov=i,e.aspect=n,e.far=s,e.updateProjectionMatrix()),super.updateMatrices(t)}copy(t){return super.copy(t),this.focus=t.focus,this}}xc.prototype.isSpotLightShadow=!0;class wc extends mc{constructor(t,e,i=0,n=Math.PI/3,s=0,r=1){super(t,e),this.type="SpotLight",this.position.copy(kn.DefaultUp),this.updateMatrix(),this.target=new kn,this.distance=i,this.angle=n,this.penumbra=s,this.decay=r,this.shadow=new xc}get power(){return this.intensity*Math.PI}set power(t){this.intensity=t/Math.PI}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.distance=t.distance,this.angle=t.angle,this.penumbra=t.penumbra,this.decay=t.decay,this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}wc.prototype.isSpotLight=!0;const bc=new pn,Sc=new Di,Mc=new Di;class Tc extends vc{constructor(){super(new js(90,1,.5,500)),this._frameExtents=new bi(4,2),this._viewportCount=6,this._viewports=[new Ni(2,1,1,1),new Ni(0,1,1,1),new Ni(3,1,1,1),new Ni(1,1,1,1),new Ni(3,0,1,1),new Ni(1,0,1,1)],this._cubeDirections=[new Di(1,0,0),new Di(-1,0,0),new Di(0,0,1),new Di(0,0,-1),new Di(0,1,0),new Di(0,-1,0)],this._cubeUps=[new Di(0,1,0),new Di(0,1,0),new Di(0,1,0),new Di(0,1,0),new Di(0,0,1),new Di(0,0,-1)]}updateMatrices(t,e=0){const i=this.camera,n=this.matrix,s=t.distance||i.far;s!==i.far&&(i.far=s,i.updateProjectionMatrix()),Sc.setFromMatrixPosition(t.matrixWorld),i.position.copy(Sc),Mc.copy(i.position),Mc.add(this._cubeDirections[e]),i.up.copy(this._cubeUps[e]),i.lookAt(Mc),i.updateMatrixWorld(),n.makeTranslation(-Sc.x,-Sc.y,-Sc.z),bc.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),this._frustum.setFromProjectionMatrix(bc)}}Tc.prototype.isPointLightShadow=!0;let Cc,Ac=class extends mc{constructor(t,e,i=0,n=1){super(t,e),this.type="PointLight",this.distance=i,this.decay=n,this.shadow=new Tc}get power(){return 4*this.intensity*Math.PI}set power(t){this.intensity=t/(4*Math.PI)}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.distance=t.distance,this.decay=t.decay,this.shadow=t.shadow.clone(),this}};Ac.prototype.isPointLight=!0;class Ec extends vc{constructor(){super(new mr(-5,5,5,-5,.5,500))}}Ec.prototype.isDirectionalLightShadow=!0;class zc extends mc{constructor(t,e){super(t,e),this.type="DirectionalLight",this.position.copy(kn.DefaultUp),this.updateMatrix(),this.target=new kn,this.shadow=new Ec}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}zc.prototype.isDirectionalLight=!0;class Ic extends mc{constructor(t,e){super(t,e),this.type="AmbientLight"}}Ic.prototype.isAmbientLight=!0,class extends mc{constructor(t,e,i=10,n=10){super(t,e),this.type="RectAreaLight",this.width=i,this.height=n}get power(){return this.intensity*this.width*this.height*Math.PI}set power(t){this.intensity=t/(this.width*this.height*Math.PI)}copy(t){return super.copy(t),this.width=t.width,this.height=t.height,this}toJSON(t){const e=super.toJSON(t);return e.object.width=this.width,e.object.height=this.height,e}}.prototype.isRectAreaLight=!0;class Nc{constructor(){this.coefficients=[];for(let t=0;t<9;t++)this.coefficients.push(new Di)}set(t){for(let e=0;e<9;e++)this.coefficients[e].copy(t[e]);return this}zero(){for(let t=0;t<9;t++)this.coefficients[t].set(0,0,0);return this}getAt(t,e){const i=t.x,n=t.y,s=t.z,r=this.coefficients;return e.copy(r[0]).multiplyScalar(.282095),e.addScaledVector(r[1],.488603*n),e.addScaledVector(r[2],.488603*s),e.addScaledVector(r[3],.488603*i),e.addScaledVector(r[4],i*n*1.092548),e.addScaledVector(r[5],n*s*1.092548),e.addScaledVector(r[6],.315392*(3*s*s-1)),e.addScaledVector(r[7],i*s*1.092548),e.addScaledVector(r[8],.546274*(i*i-n*n)),e}getIrradianceAt(t,e){const i=t.x,n=t.y,s=t.z,r=this.coefficients;return e.copy(r[0]).multiplyScalar(.886227),e.addScaledVector(r[1],1.023328*n),e.addScaledVector(r[2],1.023328*s),e.addScaledVector(r[3],1.023328*i),e.addScaledVector(r[4],.858086*i*n),e.addScaledVector(r[5],.858086*n*s),e.addScaledVector(r[6],.743125*s*s-.247708),e.addScaledVector(r[7],.858086*i*s),e.addScaledVector(r[8],.429043*(i*i-n*n)),e}add(t){for(let e=0;e<9;e++)this.coefficients[e].add(t.coefficients[e]);return this}addScaledSH(t,e){for(let i=0;i<9;i++)this.coefficients[i].addScaledVector(t.coefficients[i],e);return this}scale(t){for(let e=0;e<9;e++)this.coefficients[e].multiplyScalar(t);return this}lerp(t,e){for(let i=0;i<9;i++)this.coefficients[i].lerp(t.coefficients[i],e);return this}equals(t){for(let e=0;e<9;e++)if(!this.coefficients[e].equals(t.coefficients[e]))return!1;return!0}copy(t){return this.set(t.coefficients)}clone(){return(new this.constructor).copy(this)}fromArray(t,e=0){const i=this.coefficients;for(let n=0;n<9;n++)i[n].fromArray(t,e+3*n);return this}toArray(t=[],e=0){const i=this.coefficients;for(let n=0;n<9;n++)i[n].toArray(t,e+3*n);return t}static getBasisAt(t,e){const i=t.x,n=t.y,s=t.z;e[0]=.282095,e[1]=.488603*n,e[2]=.488603*s,e[3]=.488603*i,e[4]=1.092548*i*n,e[5]=1.092548*n*s,e[6]=.315392*(3*s*s-1),e[7]=1.092548*i*s,e[8]=.546274*(i*i-n*n)}}Nc.prototype.isSphericalHarmonics3=!0;class Lc extends mc{constructor(t=new Nc,e=1){super(void 0,e),this.sh=t}copy(t){return super.copy(t),this.sh.copy(t.sh),this}fromJSON(t){return this.intensity=t.intensity,this.sh.fromArray(t.sh),this}toJSON(t){const e=super.toJSON(t);return e.object.sh=this.sh.toArray(),e}}Lc.prototype.isLightProbe=!0;class Pc{static decodeText(t){if("undefined"!=typeof TextDecoder)return(new TextDecoder).decode(t);let e="";for(let i=0,n=t.length;i<n;i++)e+=String.fromCharCode(t[i]);try{return decodeURIComponent(escape(e))}catch(t){return e}}static extractUrlBase(t){const e=t.lastIndexOf("/");return-1===e?"./":t.substr(0,e+1)}static resolveURL(t,e){return"string"!=typeof t||""===t?"":(/^https?:\/\//i.test(e)&&/^\//.test(t)&&(e=e.replace(/(^https?:\/\/[^\/]+).*/i,"$1")),/^(https?:)?\/\//i.test(t)||/^data:.*,.*$/i.test(t)||/^blob:.*$/i.test(t)?t:e+t)}}class Fc extends vs{constructor(){super(),this.type="InstancedBufferGeometry",this.instanceCount=Infinity}copy(t){return super.copy(t),this.instanceCount=t.instanceCount,this}clone(){return(new this.constructor).copy(this)}toJSON(){const t=super.toJSON(this);return t.instanceCount=this.instanceCount,t.isInstancedBufferGeometry=!0,t}}Fc.prototype.isInstancedBufferGeometry=!0,class extends lc{constructor(t){super(t),this.options={premultiplyAlpha:"none"}}setOptions(t){return this.options=t,this}load(t,e,i,n){void 0===t&&(t=""),void 0!==this.path&&(t=this.path+t),t=this.manager.resolveURL(t);const s=this,r=ac.get(t);if(void 0!==r)return s.manager.itemStart(t),setTimeout((function(){e&&e(r),s.manager.itemEnd(t)}),0),r;const a={};a.credentials="anonymous"===this.crossOrigin?"same-origin":"include",a.headers=this.requestHeader,fetch(t,a).then((function(t){return t.blob()})).then((function(t){return createImageBitmap(t,Object.assign(s.options,{colorSpaceConversion:"none"}))})).then((function(i){ac.add(t,i),e&&e(i),s.manager.itemEnd(t)})).catch((function(e){n&&n(e),s.manager.itemError(t),s.manager.itemEnd(t)})),s.manager.itemStart(t)}}.prototype.isImageBitmapLoader=!0;class Dc extends lc{constructor(t){super(t)}load(t,e,i,n){const s=this,r=new cc(this.manager);r.setResponseType("arraybuffer"),r.setPath(this.path),r.setRequestHeader(this.requestHeader),r.setWithCredentials(this.withCredentials),r.load(t,(function(i){try{const t=i.slice(0);(void 0===Cc&&(Cc=new(window.AudioContext||window.webkitAudioContext)),Cc).decodeAudioData(t,(function(t){e(t)}))}catch(e){n&&n(e),s.manager.itemError(t)}}),i,n)}}(class extends Lc{constructor(t,e,i=1){super(void 0,i);const n=(new ss).set(t),s=(new ss).set(e),r=new Di(n.r,n.g,n.b),a=new Di(s.r,s.g,s.b),o=Math.sqrt(Math.PI),l=o*Math.sqrt(.75);this.sh.coefficients[0].copy(r).add(a).multiplyScalar(o),this.sh.coefficients[1].copy(r).sub(a).multiplyScalar(l)}}).prototype.isHemisphereLightProbe=!0,class extends Lc{constructor(t,e=1){super(void 0,e);const i=(new ss).set(t);this.sh.coefficients[0].set(i.r,i.g,i.b).multiplyScalar(2*Math.sqrt(Math.PI))}}.prototype.isAmbientLightProbe=!0;class Oc{constructor(t,e,i){let n,s,r;switch(this.binding=t,this.valueSize=i,e){case"quaternion":n=this._slerp,s=this._slerpAdditive,r=this._setAdditiveIdentityQuaternion,this.buffer=new Float64Array(6*i),this._workIndex=5;break;case"string":case"bool":n=this._select,s=this._select,r=this._setAdditiveIdentityOther,this.buffer=new Array(5*i);break;default:n=this._lerp,s=this._lerpAdditive,r=this._setAdditiveIdentityNumeric,this.buffer=new Float64Array(5*i)}this._mixBufferRegion=n,this._mixBufferRegionAdditive=s,this._setIdentity=r,this._origIndex=3,this._addIndex=4,this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,this.useCount=0,this.referenceCount=0}accumulate(t,e){const i=this.buffer,n=this.valueSize,s=t*n+n;let r=this.cumulativeWeight;if(0===r){for(let t=0;t!==n;++t)i[s+t]=i[t];r=e}else{r+=e;const t=e/r;this._mixBufferRegion(i,s,0,t,n)}this.cumulativeWeight=r}accumulateAdditive(t){const e=this.buffer,i=this.valueSize,n=i*this._addIndex;0===this.cumulativeWeightAdditive&&this._setIdentity(),this._mixBufferRegionAdditive(e,n,0,t,i),this.cumulativeWeightAdditive+=t}apply(t){const e=this.valueSize,i=this.buffer,n=t*e+e,s=this.cumulativeWeight,r=this.cumulativeWeightAdditive,a=this.binding;if(this.cumulativeWeight=0,this.cumulativeWeightAdditive=0,s<1){const t=e*this._origIndex;this._mixBufferRegion(i,n,t,1-s,e)}r>0&&this._mixBufferRegionAdditive(i,n,this._addIndex*e,1,e);for(let t=e,s=e+e;t!==s;++t)if(i[t]!==i[t+e]){a.setValue(i,n);break}}saveOriginalState(){const t=this.binding,e=this.buffer,i=this.valueSize,n=i*this._origIndex;t.getValue(e,n);for(let t=i,s=n;t!==s;++t)e[t]=e[n+t%i];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0}restoreOriginalState(){const t=3*this.valueSize;this.binding.setValue(this.buffer,t)}_setAdditiveIdentityNumeric(){const t=this._addIndex*this.valueSize,e=t+this.valueSize;for(let i=t;i<e;i++)this.buffer[i]=0}_setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric(),this.buffer[this._addIndex*this.valueSize+3]=1}_setAdditiveIdentityOther(){const t=this._origIndex*this.valueSize,e=this._addIndex*this.valueSize;for(let i=0;i<this.valueSize;i++)this.buffer[e+i]=this.buffer[t+i]}_select(t,e,i,n,s){if(n>=.5)for(let n=0;n!==s;++n)t[e+n]=t[i+n]}_slerp(t,e,i,n){Fi.slerpFlat(t,e,t,e,t,i,n)}_slerpAdditive(t,e,i,n,s){const r=this._workIndex*s;Fi.multiplyQuaternionsFlat(t,r,t,e,t,i),Fi.slerpFlat(t,e,t,e,t,r,n)}_lerp(t,e,i,n,s){const r=1-n;for(let a=0;a!==s;++a){const s=e+a;t[s]=t[s]*r+t[i+a]*n}}_lerpAdditive(t,e,i,n,s){for(let r=0;r!==s;++r){const s=e+r;t[s]=t[s]+t[i+r]*n}}}const Rc="\\[\\]\\.:\\/",kc=new RegExp("["+Rc+"]","g"),Uc="[^"+Rc+"]",Bc="[^"+Rc.replace("\\.","")+"]",Vc=/((?:WC+[\/:])*)/.source.replace("WC",Uc),Gc=/(WCOD+)?/.source.replace("WCOD",Bc),Wc=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",Uc),Hc=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",Uc),jc=new RegExp("^"+Vc+Gc+Wc+Hc+"$"),qc=["material","materials","bones"];class Jc{constructor(t,e,i){this.path=e,this.parsedPath=i||Jc.parseTrackName(e),this.node=Jc.findNode(t,this.parsedPath.nodeName)||t,this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,i){return t&&t.isAnimationObjectGroup?new Jc.Composite(t,e,i):new Jc(t,e,i)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(kc,"")}static parseTrackName(t){const e=jc.exec(t);if(!e)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const i={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},n=i.nodeName&&i.nodeName.lastIndexOf(".");if(void 0!==n&&-1!==n){const t=i.nodeName.substring(n+1);-1!==qc.indexOf(t)&&(i.nodeName=i.nodeName.substring(0,n),i.objectName=t)}if(null===i.propertyName||0===i.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return i}static findNode(t,e){if(!e||""===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){const i=t.skeleton.getBoneByName(e);if(void 0!==i)return i}if(t.children){const i=function(t){for(let n=0;n<t.length;n++){const s=t[n];if(s.name===e||s.uuid===e)return s;const r=i(s.children);if(r)return r}return null},n=i(t.children);if(n)return n}return null}_getValue_unavailable(){}_setValue_unavailable(){}_getValue_direct(t,e){t[e]=this.targetObject[this.propertyName]}_getValue_array(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)t[e++]=i[n]}_getValue_arrayElement(t,e){t[e]=this.resolvedProperty[this.propertyIndex]}_getValue_toArray(t,e){this.resolvedProperty.toArray(t,e)}_setValue_direct(t,e){this.targetObject[this.propertyName]=t[e]}_setValue_direct_setNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.needsUpdate=!0}_setValue_direct_setMatrixWorldNeedsUpdate(t,e){this.targetObject[this.propertyName]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_array(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++]}_setValue_array_setNeedsUpdate(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++];this.targetObject.needsUpdate=!0}_setValue_array_setMatrixWorldNeedsUpdate(t,e){const i=this.resolvedProperty;for(let n=0,s=i.length;n!==s;++n)i[n]=t[e++];this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_arrayElement(t,e){this.resolvedProperty[this.propertyIndex]=t[e]}_setValue_arrayElement_setNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.needsUpdate=!0}_setValue_arrayElement_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty[this.propertyIndex]=t[e],this.targetObject.matrixWorldNeedsUpdate=!0}_setValue_fromArray(t,e){this.resolvedProperty.fromArray(t,e)}_setValue_fromArray_setNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.needsUpdate=!0}_setValue_fromArray_setMatrixWorldNeedsUpdate(t,e){this.resolvedProperty.fromArray(t,e),this.targetObject.matrixWorldNeedsUpdate=!0}_getValue_unbound(t,e){this.bind(),this.getValue(t,e)}_setValue_unbound(t,e){this.bind(),this.setValue(t,e)}bind(){let t=this.node;const e=this.parsedPath,i=e.objectName,n=e.propertyName;let s=e.propertyIndex;if(t||(t=Jc.findNode(this.rootNode,e.nodeName)||this.rootNode,this.node=t),this.getValue=this._getValue_unavailable,this.setValue=this._setValue_unavailable,!t)return;if(i){let n=e.objectIndex;switch(i){case"materials":if(!t.material)return;if(!t.material.materials)return;t=t.material.materials;break;case"bones":if(!t.skeleton)return;t=t.skeleton.bones;for(let e=0;e<t.length;e++)if(t[e].name===n){n=e;break}break;default:if(void 0===t[i])return;t=t[i]}if(void 0!==n){if(void 0===t[n])return;t=t[n]}}const r=t[n];if(void 0===r)return void e.nodeName;let a=this.Versioning.None;this.targetObject=t,void 0!==t.needsUpdate?a=this.Versioning.NeedsUpdate:void 0!==t.matrixWorldNeedsUpdate&&(a=this.Versioning.MatrixWorldNeedsUpdate);let o=this.BindingType.Direct;if(void 0!==s){if("morphTargetInfluences"===n){if(!t.geometry)return;if(!t.geometry.isBufferGeometry)return;if(!t.geometry.morphAttributes)return;void 0!==t.morphTargetDictionary[s]&&(s=t.morphTargetDictionary[s])}o=this.BindingType.ArrayElement,this.resolvedProperty=r,this.propertyIndex=s}else void 0!==r.fromArray&&void 0!==r.toArray?(o=this.BindingType.HasFromToArray,this.resolvedProperty=r):Array.isArray(r)?(o=this.BindingType.EntireArray,this.resolvedProperty=r):this.propertyName=n;this.getValue=this.GetterByBindingType[o],this.setValue=this.SetterByBindingTypeAndVersioning[o][a]}unbind(){this.node=null,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}}Jc.Composite=class{constructor(t,e,i){const n=i||Jc.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,n)}getValue(t,e){this.bind();const i=this._targetGroup.nCachedObjects_,n=this._bindings[i];void 0!==n&&n.getValue(t,e)}setValue(t,e){const i=this._bindings;for(let n=this._targetGroup.nCachedObjects_,s=i.length;n!==s;++n)i[n].setValue(t,e)}bind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,i=t.length;e!==i;++e)t[e].bind()}unbind(){const t=this._bindings;for(let e=this._targetGroup.nCachedObjects_,i=t.length;e!==i;++e)t[e].unbind()}},Jc.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},Jc.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},Jc.prototype.GetterByBindingType=[Jc.prototype._getValue_direct,Jc.prototype._getValue_array,Jc.prototype._getValue_arrayElement,Jc.prototype._getValue_toArray],Jc.prototype.SetterByBindingTypeAndVersioning=[[Jc.prototype._setValue_direct,Jc.prototype._setValue_direct_setNeedsUpdate,Jc.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[Jc.prototype._setValue_array,Jc.prototype._setValue_array_setNeedsUpdate,Jc.prototype._setValue_array_setMatrixWorldNeedsUpdate],[Jc.prototype._setValue_arrayElement,Jc.prototype._setValue_arrayElement_setNeedsUpdate,Jc.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[Jc.prototype._setValue_fromArray,Jc.prototype._setValue_fromArray_setNeedsUpdate,Jc.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class Yc{constructor(t,e,i=null,n=e.blendMode){this._mixer=t,this._clip=e,this._localRoot=i,this.blendMode=n;const s=e.tracks,r=s.length,a=new Array(r),o={endingStart:Xe,endingEnd:Xe};for(let t=0;t!==r;++t){const e=s[t].createInterpolant(null);a[t]=e,e.settings=o}this._interpolantSettings=o,this._interpolants=a,this._propertyBindings=new Array(r),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=2201,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=Infinity,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}play(){return this._mixer._activateAction(this),this}stop(){return this._mixer._deactivateAction(this),this.reset()}reset(){return this.paused=!1,this.enabled=!0,this.time=0,this._loopCount=-1,this._startTime=null,this.stopFading().stopWarping()}isRunning(){return this.enabled&&!this.paused&&0!==this.timeScale&&null===this._startTime&&this._mixer._isActiveAction(this)}isScheduled(){return this._mixer._isActiveAction(this)}startAt(t){return this._startTime=t,this}setLoop(t,e){return this.loop=t,this.repetitions=e,this}setEffectiveWeight(t){return this.weight=t,this._effectiveWeight=this.enabled?t:0,this.stopFading()}getEffectiveWeight(){return this._effectiveWeight}fadeIn(t){return this._scheduleFading(t,0,1)}fadeOut(t){return this._scheduleFading(t,1,0)}crossFadeFrom(t,e,i){if(t.fadeOut(e),this.fadeIn(e),i){const i=this._clip.duration,n=t._clip.duration,s=n/i,r=i/n;t.warp(1,s,e),this.warp(r,1,e)}return this}crossFadeTo(t,e,i){return t.crossFadeFrom(this,e,i)}stopFading(){const t=this._weightInterpolant;return null!==t&&(this._weightInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}setEffectiveTimeScale(t){return this.timeScale=t,this._effectiveTimeScale=this.paused?0:t,this.stopWarping()}getEffectiveTimeScale(){return this._effectiveTimeScale}setDuration(t){return this.timeScale=this._clip.duration/t,this.stopWarping()}syncWith(t){return this.time=t.time,this.timeScale=t.timeScale,this.stopWarping()}halt(t){return this.warp(this._effectiveTimeScale,0,t)}warp(t,e,i){const n=this._mixer,s=n.time,r=this.timeScale;let a=this._timeScaleInterpolant;null===a&&(a=n._lendControlInterpolant(),this._timeScaleInterpolant=a);const o=a.parameterPositions,l=a.sampleValues;return o[0]=s,o[1]=s+i,l[0]=t/r,l[1]=e/r,this}stopWarping(){const t=this._timeScaleInterpolant;return null!==t&&(this._timeScaleInterpolant=null,this._mixer._takeBackControlInterpolant(t)),this}getMixer(){return this._mixer}getClip(){return this._clip}getRoot(){return this._localRoot||this._mixer._root}_update(t,e,i,n){if(!this.enabled)return void this._updateWeight(t);const s=this._startTime;if(null!==s){const n=(t-s)*i;if(n<0||0===i)return;this._startTime=null,e=i*n}e*=this._updateTimeScale(t);const r=this._updateTime(e),a=this._updateWeight(t);if(a>0){const t=this._interpolants,e=this._propertyBindings;if(2501===this.blendMode)for(let i=0,n=t.length;i!==n;++i)t[i].evaluate(r),e[i].accumulateAdditive(a);else for(let i=0,s=t.length;i!==s;++i)t[i].evaluate(r),e[i].accumulate(n,a)}}_updateWeight(t){let e=0;if(this.enabled){e=this.weight;const i=this._weightInterpolant;if(null!==i){const n=i.evaluate(t)[0];e*=n,t>i.parameterPositions[1]&&(this.stopFading(),0===n&&(this.enabled=!1))}}return this._effectiveWeight=e,e}_updateTimeScale(t){let e=0;if(!this.paused){e=this.timeScale;const i=this._timeScaleInterpolant;null!==i&&(e*=i.evaluate(t)[0],t>i.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e))}return this._effectiveTimeScale=e,e}_updateTime(t){const e=this._clip.duration,i=this.loop;let n=this.time+t,s=this._loopCount;const r=2202===i;if(0===t)return-1===s?n:r&&1==(1&s)?e-n:n;if(2200===i){-1===s&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(n>=e)n=e;else{if(!(n<0)){this.time=n;break t}n=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(-1===s&&(t>=0?(s=0,this._setEndings(!0,0===this.repetitions,r)):this._setEndings(0===this.repetitions,!0,r)),n>=e||n<0){const i=Math.floor(n/e);n-=e*i,s+=Math.abs(i);const a=this.repetitions-s;if(a<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,n=t>0?e:0,this.time=n,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(1===a){const e=t<0;this._setEndings(e,!e,r)}else this._setEndings(!1,!1,r);this._loopCount=s,this.time=n,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:i})}}else this.time=n;if(r&&1==(1&s))return e-n}return n}_setEndings(t,e,i){const n=this._interpolantSettings;i?(n.endingStart=Ze,n.endingEnd=Ze):(n.endingStart=t?this.zeroSlopeAtStart?Ze:Xe:$e,n.endingEnd=e?this.zeroSlopeAtEnd?Ze:Xe:$e)}_scheduleFading(t,e,i){const n=this._mixer,s=n.time;let r=this._weightInterpolant;null===r&&(r=n._lendControlInterpolant(),this._weightInterpolant=r);const a=r.parameterPositions,o=r.sampleValues;return a[0]=s,o[0]=e,a[1]=s+t,o[1]=i,this}}(class extends di{constructor(t){super(),this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}_bindAction(t,e){const i=t._localRoot||this._root,n=t._clip.tracks,s=n.length,r=t._propertyBindings,a=t._interpolants,o=i.uuid,l=this._bindingsByRootAndName;let h=l[o];void 0===h&&(h={},l[o]=h);for(let t=0;t!==s;++t){const s=n[t],l=s.name;let c=h[l];if(void 0!==c)r[t]=c;else{if(c=r[t],void 0!==c){null===c._cacheIndex&&(++c.referenceCount,this._addInactiveBinding(c,o,l));continue}const n=e&&e._propertyBindings[t].binding.parsedPath;c=new Oc(Jc.create(i,l,n),s.ValueTypeName,s.getValueSize()),++c.referenceCount,this._addInactiveBinding(c,o,l),r[t]=c}a[t].resultBuffer=c.buffer}}_activateAction(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){const e=(t._localRoot||this._root).uuid,i=t._clip.uuid,n=this._actionsByClip[i];this._bindAction(t,n&&n.knownActions[0]),this._addInactiveAction(t,i,e)}const e=t._propertyBindings;for(let t=0,i=e.length;t!==i;++t){const i=e[t];0==i.useCount++&&(this._lendBinding(i),i.saveOriginalState())}this._lendAction(t)}}_deactivateAction(t){if(this._isActiveAction(t)){const e=t._propertyBindings;for(let t=0,i=e.length;t!==i;++t){const i=e[t];0==--i.useCount&&(i.restoreOriginalState(),this._takeBackBinding(i))}this._takeBackAction(t)}}_initMemoryManager(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;const t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}}_isActiveAction(t){const e=t._cacheIndex;return null!==e&&e<this._nActiveActions}_addInactiveAction(t,e,i){const n=this._actions,s=this._actionsByClip;let r=s[e];if(void 0===r)r={knownActions:[t],actionByRoot:{}},t._byClipCacheIndex=0,s[e]=r;else{const e=r.knownActions;t._byClipCacheIndex=e.length,e.push(t)}t._cacheIndex=n.length,n.push(t),r.actionByRoot[i]=t}_removeInactiveAction(t){const e=this._actions,i=e[e.length-1],n=t._cacheIndex;i._cacheIndex=n,e[n]=i,e.pop(),t._cacheIndex=null;const s=t._clip.uuid,r=this._actionsByClip,a=r[s],o=a.knownActions,l=o[o.length-1],h=t._byClipCacheIndex;l._byClipCacheIndex=h,o[h]=l,o.pop(),t._byClipCacheIndex=null,delete a.actionByRoot[(t._localRoot||this._root).uuid],0===o.length&&delete r[s],this._removeInactiveBindingsForAction(t)}_removeInactiveBindingsForAction(t){const e=t._propertyBindings;for(let t=0,i=e.length;t!==i;++t){const i=e[t];0==--i.referenceCount&&this._removeInactiveBinding(i)}}_lendAction(t){const e=this._actions,i=t._cacheIndex,n=this._nActiveActions++,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_takeBackAction(t){const e=this._actions,i=t._cacheIndex,n=--this._nActiveActions,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_addInactiveBinding(t,e,i){const n=this._bindingsByRootAndName,s=this._bindings;let r=n[e];void 0===r&&(r={},n[e]=r),r[i]=t,t._cacheIndex=s.length,s.push(t)}_removeInactiveBinding(t){const e=this._bindings,i=t.binding,n=i.rootNode.uuid,s=i.path,r=this._bindingsByRootAndName,a=r[n],o=e[e.length-1],l=t._cacheIndex;o._cacheIndex=l,e[l]=o,e.pop(),delete a[s],0===Object.keys(a).length&&delete r[n]}_lendBinding(t){const e=this._bindings,i=t._cacheIndex,n=this._nActiveBindings++,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_takeBackBinding(t){const e=this._bindings,i=t._cacheIndex,n=--this._nActiveBindings,s=e[n];t._cacheIndex=n,e[n]=t,s._cacheIndex=i,e[i]=s}_lendControlInterpolant(){const t=this._controlInterpolants,e=this._nActiveControlInterpolants++;let i=t[e];return void 0===i&&(i=new Yh(new Float32Array(2),new Float32Array(2),1,this._controlInterpolantsResultBuffer),i.__cacheIndex=e,t[e]=i),i}_takeBackControlInterpolant(t){const e=this._controlInterpolants,i=t.__cacheIndex,n=--this._nActiveControlInterpolants,s=e[n];t.__cacheIndex=n,e[n]=t,s.__cacheIndex=i,e[i]=s}clipAction(t,e,i){const n=e||this._root,s=n.uuid;let r="string"==typeof t?sc.findByName(n,t):t;const a=null!==r?r.uuid:t,o=this._actionsByClip[a];let l=null;if(void 0===i&&(i=null!==r?r.blendMode:2500),void 0!==o){const t=o.actionByRoot[s];if(void 0!==t&&t.blendMode===i)return t;l=o.knownActions[0],null===r&&(r=l._clip)}if(null===r)return null;const h=new Yc(this,r,e,i);return this._bindAction(h,l),this._addInactiveAction(h,a,s),h}existingAction(t,e){const i=e||this._root,n=i.uuid,s="string"==typeof t?sc.findByName(i,t):t,r=s?s.uuid:t,a=this._actionsByClip[r];return void 0!==a&&a.actionByRoot[n]||null}stopAllAction(){const t=this._actions;for(let e=this._nActiveActions-1;e>=0;--e)t[e].stop();return this}update(t){t*=this.timeScale;const e=this._actions,i=this._nActiveActions,n=this.time+=t,s=Math.sign(t),r=this._accuIndex^=1;for(let a=0;a!==i;++a)e[a]._update(n,t,s,r);const a=this._bindings,o=this._nActiveBindings;for(let t=0;t!==o;++t)a[t].apply(r);return this}setTime(t){this.time=0;for(let t=0;t<this._actions.length;t++)this._actions[t].time=0;return this.update(t)}getRoot(){return this._root}uncacheClip(t){const e=this._actions,i=t.uuid,n=this._actionsByClip,s=n[i];if(void 0!==s){const t=s.knownActions;for(let i=0,n=t.length;i!==n;++i){const n=t[i];this._deactivateAction(n);const s=n._cacheIndex,r=e[e.length-1];n._cacheIndex=null,n._byClipCacheIndex=null,r._cacheIndex=s,e[s]=r,e.pop(),this._removeInactiveBindingsForAction(n)}delete n[i]}}uncacheRoot(t){const e=t.uuid,i=this._actionsByClip;for(const t in i){const n=i[t].actionByRoot[e];void 0!==n&&(this._deactivateAction(n),this._removeInactiveAction(n))}const n=this._bindingsByRootAndName[e];if(void 0!==n)for(const t in n){const e=n[t];e.restoreOriginalState(),this._removeInactiveBinding(e)}}uncacheAction(t,e){const i=this.existingAction(t,e);null!==i&&(this._deactivateAction(i),this._removeInactiveAction(i))}}).prototype._controlInterpolantsResultBuffer=new Float32Array(1),class extends $o{constructor(t,e,i=1){super(t,e),this.meshPerAttribute=i}copy(t){return super.copy(t),this.meshPerAttribute=t.meshPerAttribute,this}clone(t){const e=super.clone(t);return e.meshPerAttribute=this.meshPerAttribute,e}toJSON(t){const e=super.toJSON(t);return e.isInstancedInterleavedBuffer=!0,e.meshPerAttribute=this.meshPerAttribute,e}}.prototype.isInstancedInterleavedBuffer=!0;class Xc{constructor(t,e,i=0,n=Infinity){this.ray=new dn(t,e),this.near=i,this.far=n,this.camera=null,this.layers=new Mn,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}}}set(t,e){this.ray.set(t,e)}setFromCamera(t,e){e&&e.isPerspectiveCamera?(this.ray.origin.setFromMatrixPosition(e.matrixWorld),this.ray.direction.set(t.x,t.y,.5).unproject(e).sub(this.ray.origin).normalize(),this.camera=e):e&&e.isOrthographicCamera&&(this.ray.origin.set(t.x,t.y,(e.near+e.far)/(e.near-e.far)).unproject(e),this.ray.direction.set(0,0,-1).transformDirection(e.matrixWorld),this.camera=e)}intersectObject(t,e=!0,i=[]){return $c(t,this,i,e),i.sort(Zc),i}intersectObjects(t,e=!0,i=[]){for(let n=0,s=t.length;n<s;n++)$c(t[n],this,i,e);return i.sort(Zc),i}}function Zc(t,e){return t.distance-e.distance}function $c(t,e,i,n){if(t.layers.test(e.layers)&&t.raycast(e,i),!0===n){const n=t.children;for(let t=0,s=n.length;t<s;t++)$c(n[t],e,i,!0)}}const Kc=new Di,Qc=new pn,tu=new pn;function eu(t){const e=[];t&&t.isBone&&e.push(t);for(let i=0;i<t.children.length;i++)e.push.apply(e,eu(t.children[i]));return e}const iu=new Float32Array(1),nu=new Int32Array(iu.buffer);class su{static toHalfFloat(t){t>65504&&(t=65504),iu[0]=t;const e=nu[0];let i=e>>16&32768,n=e>>12&2047;const s=e>>23&255;return s<103?i:s>142?(i|=31744,i|=(255==s?0:1)&&8388607&e,i):s<113?(n|=2048,i|=(n>>114-s)+(n>>113-s&1),i):(i|=s-112<<10|n>>1,i+=1&n,i)}}function ru(t,e){return t<e?t:e}Hl.create=function(t,e){return t.prototype=Object.create(Hl.prototype),t.prototype.constructor=t,t.prototype.getPoint=e,t},ch.prototype.fromPoints=function(t){return this.setFromPoints(t)},class extends Ol{constructor(t=10,e=10,i=4473924,n=8947848){i=new ss(i),n=new ss(n);const s=e/2,r=t/e,a=t/2,o=[],l=[];for(let t=0,h=0,c=-a;t<=e;t++,c+=r){o.push(-a,0,c,a,0,c),o.push(c,0,-a,c,0,a);const e=t===s?i:n;e.toArray(l,h),h+=3,e.toArray(l,h),h+=3,e.toArray(l,h),h+=3,e.toArray(l,h),h+=3}const h=new vs;h.setAttribute("position",new us(o,3)),h.setAttribute("color",new us(l,3)),super(h,new Al({vertexColors:!0,toneMapped:!1})),this.type="GridHelper"}}.prototype.setColors=function(){},class extends Ol{constructor(t){const e=eu(t),i=new vs,n=[],s=[],r=new ss(0,0,1),a=new ss(0,1,0);for(let t=0;t<e.length;t++){const i=e[t];i.parent&&i.parent.isBone&&(n.push(0,0,0),n.push(0,0,0),s.push(r.r,r.g,r.b),s.push(a.r,a.g,a.b))}i.setAttribute("position",new us(n,3)),i.setAttribute("color",new us(s,3)),super(i,new Al({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0})),this.type="SkeletonHelper",this.isSkeletonHelper=!0,this.root=t,this.bones=e,this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1}updateMatrixWorld(t){const e=this.bones,i=this.geometry,n=i.getAttribute("position");tu.copy(this.root.matrixWorld).invert();for(let t=0,i=0;t<e.length;t++){const s=e[t];s.parent&&s.parent.isBone&&(Qc.multiplyMatrices(tu,s.matrixWorld),Kc.setFromMatrixPosition(Qc),n.setXYZ(i,Kc.x,Kc.y,Kc.z),Qc.multiplyMatrices(tu,s.parent.matrixWorld),Kc.setFromMatrixPosition(Qc),n.setXYZ(i+1,Kc.x,Kc.y,Kc.z),i+=2)}i.getAttribute("position").needsUpdate=!0,super.updateMatrixWorld(t)}}.prototype.update=function(){},lc.prototype.extractUrlBase=function(t){return Pc.extractUrlBase(t)},lc.Handlers={add:function(){},get:function(){}},ki.prototype.center=function(t){return this.getCenter(t)},ki.prototype.empty=function(){return this.isEmpty()},ki.prototype.isIntersectionBox=function(t){return this.intersectsBox(t)},ki.prototype.isIntersectionSphere=function(t){return this.intersectsSphere(t)},ki.prototype.size=function(t){return this.getSize(t)},sn.prototype.empty=function(){return this.isEmpty()},ir.prototype.setFromMatrix=function(t){return this.setFromProjectionMatrix(t)},Si.prototype.flattenToArrayOffset=function(t,e){return this.toArray(t,e)},Si.prototype.multiplyVector3=function(t){return t.applyMatrix3(this)},Si.prototype.multiplyVector3Array=function(){},Si.prototype.applyToBufferAttribute=function(t){return t.applyMatrix3(this)},Si.prototype.applyToVector3Array=function(){},Si.prototype.getInverse=function(t){return this.copy(t).invert()},pn.prototype.extractPosition=function(t){return this.copyPosition(t)},pn.prototype.flattenToArrayOffset=function(t,e){return this.toArray(t,e)},pn.prototype.getPosition=function(){return(new Di).setFromMatrixColumn(this,3)},pn.prototype.setRotationFromQuaternion=function(t){return this.makeRotationFromQuaternion(t)},pn.prototype.multiplyToArray=function(){},pn.prototype.multiplyVector3=function(t){return t.applyMatrix4(this)},pn.prototype.multiplyVector4=function(t){return t.applyMatrix4(this)},pn.prototype.multiplyVector3Array=function(){},pn.prototype.rotateAxis=function(t){t.transformDirection(this)},pn.prototype.crossVector=function(t){return t.applyMatrix4(this)},pn.prototype.translate=function(){},pn.prototype.rotateX=function(){},pn.prototype.rotateY=function(){},pn.prototype.rotateZ=function(){},pn.prototype.rotateByAxis=function(){},pn.prototype.applyToBufferAttribute=function(t){return t.applyMatrix4(this)},pn.prototype.applyToVector3Array=function(){},pn.prototype.makeFrustum=function(t,e,i,n,s,r){return this.makePerspective(t,e,n,i,s,r)},pn.prototype.getInverse=function(t){return this.copy(t).invert()},Qs.prototype.isIntersectionLine=function(t){return this.intersectsLine(t)},Fi.prototype.multiplyVector3=function(t){return t.applyQuaternion(this)},Fi.prototype.inverse=function(){return this.invert()},dn.prototype.isIntersectionBox=function(t){return this.intersectsBox(t)},dn.prototype.isIntersectionPlane=function(t){return this.intersectsPlane(t)},dn.prototype.isIntersectionSphere=function(t){return this.intersectsSphere(t)},Xn.prototype.area=function(){return this.getArea()},Xn.prototype.barycoordFromPoint=function(t,e){return this.getBarycoord(t,e)},Xn.prototype.midpoint=function(t){return this.getMidpoint(t)},Xn.prototypenormal=function(t){return this.getNormal(t)},Xn.prototype.plane=function(t){return this.getPlane(t)},Xn.barycoordFromPoint=function(t,e,i,n,s){return Xn.getBarycoord(t,e,i,n,s)},Xn.normal=function(t,e,i,n){return Xn.getNormal(t,e,i,n)},uh.prototype.extractAllPoints=function(t){return this.extractPoints(t)},uh.prototype.extrude=function(t){return new Uh(this,t)},uh.prototype.makeGeometry=function(t){return new Vh(this,t)},bi.prototype.fromAttribute=function(t,e,i){return this.fromBufferAttribute(t,e,i)},bi.prototype.distanceToManhattan=function(t){return this.manhattanDistanceTo(t)},bi.prototype.lengthManhattan=function(){return this.manhattanLength()},Di.prototype.setEulerFromRotationMatrix=function(){},Di.prototype.setEulerFromQuaternion=function(){},Di.prototype.getPositionFromMatrix=function(t){return this.setFromMatrixPosition(t)},Di.prototype.getScaleFromMatrix=function(t){return this.setFromMatrixScale(t)},Di.prototype.getColumnFromMatrix=function(t,e){return this.setFromMatrixColumn(e,t)},Di.prototype.applyProjection=function(t){return this.applyMatrix4(t)},Di.prototype.fromAttribute=function(t,e,i){return this.fromBufferAttribute(t,e,i)},Di.prototype.distanceToManhattan=function(t){return this.manhattanDistanceTo(t)},Di.prototype.lengthManhattan=function(){return this.manhattanLength()},Ni.prototype.fromAttribute=function(t,e,i){return this.fromBufferAttribute(t,e,i)},Ni.prototype.lengthManhattan=function(){return this.manhattanLength()},kn.prototype.getChildByName=function(t){return this.getObjectByName(t)},kn.prototype.renderDepth=function(){},kn.prototype.translate=function(t,e){return this.translateOnAxis(e,t)},kn.prototype.getWorldRotation=function(){},kn.prototype.applyMatrix=function(t){return this.applyMatrix4(t)},Object.defineProperties(kn.prototype,{eulerOrder:{get:function(){return this.rotation.order},set:function(t){this.rotation.order=t}},useQuaternion:{get:function(){},set:function(){}}}),Rs.prototype.setDrawMode=function(){},Object.defineProperties(Rs.prototype,{drawMode:{get:function(){return 0},set:function(){}}}),xl.prototype.initBones=function(){},js.prototype.setLens=function(t,e){void 0!==e&&(this.filmGauge=e),this.setFocalLength(t)},Object.defineProperties(mc.prototype,{onlyShadow:{set:function(){}},shadowCameraFov:{set:function(t){this.shadow.camera.fov=t}},shadowCameraLeft:{set:function(t){this.shadow.camera.left=t}},shadowCameraRight:{set:function(t){this.shadow.camera.right=t}},shadowCameraTop:{set:function(t){this.shadow.camera.top=t}},shadowCameraBottom:{set:function(t){this.shadow.camera.bottom=t}},shadowCameraNear:{set:function(t){this.shadow.camera.near=t}},shadowCameraFar:{set:function(t){this.shadow.camera.far=t}},shadowCameraVisible:{set:function(){}},shadowBias:{set:function(t){this.shadow.bias=t}},shadowDarkness:{set:function(){}},shadowMapWidth:{set:function(t){this.shadow.mapSize.width=t}},shadowMapHeight:{set:function(t){this.shadow.mapSize.height=t}}}),Object.defineProperties(ls.prototype,{length:{get:function(){return this.array.length}},dynamic:{get:function(){return this.usage===ci},set:function(){this.setUsage(ci)}}}),ls.prototype.setDynamic=function(t){return this.setUsage(!0===t?ci:hi),this},ls.prototype.copyIndicesArray=function(){},ls.prototype.setArray=function(){},vs.prototype.addIndex=function(t){this.setIndex(t)},vs.prototype.addAttribute=function(t,e){return e&&e.isBufferAttribute||e&&e.isInterleavedBufferAttribute?"index"===t?(this.setIndex(e),this):this.setAttribute(t,e):this.setAttribute(t,new ls(arguments[1],arguments[2]))},vs.prototype.addDrawCall=function(t,e,i){this.addGroup(t,e)},vs.prototype.clearDrawCalls=function(){this.clearGroups()},vs.prototype.computeOffsets=function(){},vs.prototype.removeAttribute=function(t){return this.deleteAttribute(t)},vs.prototype.applyMatrix=function(t){return this.applyMatrix4(t)},Object.defineProperties(vs.prototype,{drawcalls:{get:function(){return this.groups}},offsets:{get:function(){return this.groups}}}),$o.prototype.setDynamic=function(t){return this.setUsage(!0===t?ci:hi),this},$o.prototype.setArray=function(){},Uh.prototype.getArrays=function(){},Uh.prototype.addShapeList=function(){},Uh.prototype.addShape=function(){},Zo.prototype.dispose=function(){},Object.defineProperties($n.prototype,{wrapAround:{get:function(){},set:function(){}},overdraw:{get:function(){},set:function(){}},wrapRGB:{get:function(){return new ss}},shading:{get:function(){},set:function(t){this.flatShading=1===t}},stencilMask:{get:function(){return this.stencilFuncMask},set:function(t){this.stencilFuncMask=t}},vertexTangents:{get:function(){},set:function(){}}}),Object.defineProperties(Ws.prototype,{derivatives:{get:function(){return this.extensions.derivatives},set:function(t){this.extensions.derivatives=t}}}),Xo.prototype.clearTarget=function(t,e,i,n){this.setRenderTarget(t),this.clear(e,i,n)},Xo.prototype.animate=function(t){this.setAnimationLoop(t)},Xo.prototype.getCurrentRenderTarget=function(){return this.getRenderTarget()},Xo.prototype.getMaxAnisotropy=function(){return this.capabilities.getMaxAnisotropy()},Xo.prototype.getPrecision=function(){return this.capabilities.precision},Xo.prototype.resetGLState=function(){return this.state.reset()},Xo.prototype.supportsFloatTextures=function(){return this.extensions.get("OES_texture_float")},Xo.prototype.supportsHalfFloatTextures=function(){return this.extensions.get("OES_texture_half_float")},Xo.prototype.supportsStandardDerivatives=function(){return this.extensions.get("OES_standard_derivatives")},Xo.prototype.supportsCompressedTextureS3TC=function(){return this.extensions.get("WEBGL_compressed_texture_s3tc")},Xo.prototype.supportsCompressedTexturePVRTC=function(){return this.extensions.get("WEBGL_compressed_texture_pvrtc")},Xo.prototype.supportsBlendMinMax=function(){return this.extensions.get("EXT_blend_minmax")},Xo.prototype.supportsVertexTextures=function(){return this.capabilities.vertexTextures},Xo.prototype.supportsInstancedArrays=function(){return this.extensions.get("ANGLE_instanced_arrays")},Xo.prototype.enableScissorTest=function(t){this.setScissorTest(t)},Xo.prototype.initMaterial=function(){},Xo.prototype.addPrePlugin=function(){},Xo.prototype.addPostPlugin=function(){},Xo.prototype.updateShadowMap=function(){},Xo.prototype.setFaceCulling=function(){},Xo.prototype.allocTextureUnit=function(){},Xo.prototype.setTexture=function(){},Xo.prototype.setTexture2D=function(){},Xo.prototype.setTextureCube=function(){},Xo.prototype.getActiveMipMapLevel=function(){return this.getActiveMipmapLevel()},Object.defineProperties(Xo.prototype,{shadowMapEnabled:{get:function(){return this.shadowMap.enabled},set:function(t){this.shadowMap.enabled=t}},shadowMapType:{get:function(){return this.shadowMap.type},set:function(t){this.shadowMap.type=t}},shadowMapCullFace:{get:function(){},set:function(){}},context:{get:function(){return this.getContext()}},vr:{get:function(){return this.xr}},gammaInput:{get:function(){return!1},set:function(){}},gammaOutput:{get:function(){return!1},set:function(t){this.outputEncoding=!0===t?Qe:Ke}},toneMappingWhitePoint:{get:function(){return 1},set:function(){}}}),Object.defineProperties(ko.prototype,{cullFace:{get:function(){},set:function(){}},renderReverseSided:{get:function(){},set:function(){}},renderSingleSided:{get:function(){},set:function(){}}}),Object.defineProperties(Li.prototype,{wrapS:{get:function(){return this.texture.wrapS},set:function(t){this.texture.wrapS=t}},wrapT:{get:function(){return this.texture.wrapT},set:function(t){this.texture.wrapT=t}},magFilter:{get:function(){return this.texture.magFilter},set:function(t){this.texture.magFilter=t}},minFilter:{get:function(){return this.texture.minFilter},set:function(t){this.texture.minFilter=t}},anisotropy:{get:function(){return this.texture.anisotropy},set:function(t){this.texture.anisotropy=t}},offset:{get:function(){return this.texture.offset},set:function(t){this.texture.offset=t}},repeat:{get:function(){return this.texture.repeat},set:function(t){this.texture.repeat=t}},format:{get:function(){return this.texture.format},set:function(t){this.texture.format=t}},type:{get:function(){return this.texture.type},set:function(t){this.texture.type=t}},generateMipmaps:{get:function(){return this.texture.generateMipmaps},set:function(t){this.texture.generateMipmaps=t}}}),class extends kn{constructor(t){super(),this.type="Audio",this.listener=t,this.context=t.context,this.gain=this.context.createGain(),this.gain.connect(t.getInput()),this.autoplay=!1,this.buffer=null,this.detune=0,this.loop=!1,this.loopStart=0,this.loopEnd=0,this.offset=0,this.duration=void 0,this.playbackRate=1,this.isPlaying=!1,this.hasPlaybackControl=!0,this.source=null,this.sourceType="empty",this._startedAt=0,this._progress=0,this._connected=!1,this.filters=[]}getOutput(){return this.gain}setNodeSource(t){return this.hasPlaybackControl=!1,this.sourceType="audioNode",this.source=t,this.connect(),this}setMediaElementSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaNode",this.source=this.context.createMediaElementSource(t),this.connect(),this}setMediaStreamSource(t){return this.hasPlaybackControl=!1,this.sourceType="mediaStreamNode",this.source=this.context.createMediaStreamSource(t),this.connect(),this}setBuffer(t){return this.buffer=t,this.sourceType="buffer",this.autoplay&&this.play(),this}play(t=0){if(!0===this.isPlaying)return;if(!1===this.hasPlaybackControl)return;this._startedAt=this.context.currentTime+t;const e=this.context.createBufferSource();return e.buffer=this.buffer,e.loop=this.loop,e.loopStart=this.loopStart,e.loopEnd=this.loopEnd,e.onended=this.onEnded.bind(this),e.start(this._startedAt,this._progress+this.offset,this.duration),this.isPlaying=!0,this.source=e,this.setDetune(this.detune),this.setPlaybackRate(this.playbackRate),this.connect()}pause(){if(!1!==this.hasPlaybackControl)return!0===this.isPlaying&&(this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate,!0===this.loop&&(this._progress=this._progress%(this.duration||this.buffer.duration)),this.source.stop(),this.source.onended=null,this.isPlaying=!1),this}stop(){if(!1!==this.hasPlaybackControl)return this._progress=0,this.source.stop(),this.source.onended=null,this.isPlaying=!1,this}connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(let t=1,e=this.filters.length;t<e;t++)this.filters[t-1].connect(this.filters[t]);this.filters[this.filters.length-1].connect(this.getOutput())}else this.source.connect(this.getOutput());return this._connected=!0,this}disconnect(){if(this.filters.length>0){this.source.disconnect(this.filters[0]);for(let t=1,e=this.filters.length;t<e;t++)this.filters[t-1].disconnect(this.filters[t]);this.filters[this.filters.length-1].disconnect(this.getOutput())}else this.source.disconnect(this.getOutput());return this._connected=!1,this}getFilters(){return this.filters}setFilters(t){return t||(t=[]),!0===this._connected?(this.disconnect(),this.filters=t.slice(),this.connect()):this.filters=t.slice(),this}setDetune(t){if(this.detune=t,void 0!==this.source.detune)return!0===this.isPlaying&&this.source.detune.setTargetAtTime(this.detune,this.context.currentTime,.01),this}getDetune(){return this.detune}getFilter(){return this.getFilters()[0]}setFilter(t){return this.setFilters(t?[t]:[])}setPlaybackRate(t){if(!1!==this.hasPlaybackControl)return this.playbackRate=t,!0===this.isPlaying&&this.source.playbackRate.setTargetAtTime(this.playbackRate,this.context.currentTime,.01),this}getPlaybackRate(){return this.playbackRate}onEnded(){this.isPlaying=!1}getLoop(){return!1!==this.hasPlaybackControl&&this.loop}setLoop(t){if(!1!==this.hasPlaybackControl)return this.loop=t,!0===this.isPlaying&&(this.source.loop=this.loop),this}setLoopStart(t){return this.loopStart=t,this}setLoopEnd(t){return this.loopEnd=t,this}getVolume(){return this.gain.gain.value}setVolume(t){return this.gain.gain.setTargetAtTime(t,this.context.currentTime,.01),this}}.prototype.load=function(t){const e=this;return(new Dc).load(t,(function(t){e.setBuffer(t)})),this},Js.prototype.updateCubeMap=function(t,e){return this.update(t,e)},Js.prototype.clear=function(t,e,i,n){return this.renderTarget.clear(t,e,i,n)},Ai.crossOrigin=void 0,Ai.loadTexture=function(t,e,i,n){const s=new fc;s.setCrossOrigin(this.crossOrigin);const r=s.load(t,i,void 0,n);return e&&(r.mapping=e),r},Ai.loadTextureCube=function(t,e,i,n){const s=new dc;s.setCrossOrigin(this.crossOrigin);const r=s.load(t,i,void 0,n);return e&&(r.mapping=e),r},Ai.loadCompressedTexture=function(){},Ai.loadCompressedTextureCube=function(){},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:M}})),"undefined"!=typeof window&&(window.__THREE__||(window.__THREE__=M));const au=new pn,ou=new S,lu=new S,hu=new S;class cu{constructor(t=0,e=0,i=0,n=1){this.x=t,this.y=e,this.z=i,this.w=n,this.onChanged=new l}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}get 3(){return this.w}set 0(t){this.x=t}set 1(t){this.y=t}set 2(t){this.z=t}set 3(t){this.w=t}_lookRotation(t,e,i,n,s,r){ou.set(t,e,i),ou.normalize(),hu._crossVectors(n,s,r,ou.x,ou.y,ou.z),0===hu.lengthSq()&&(1===Math.abs(r)?ou.x+=.001:ou.z+=.001,ou.normalize(),hu._crossVectors(n,s,r,ou.x,ou.y,ou.z)),hu.normalize(),lu.crossVectors(ou,hu);var a=hu.x,o=hu.y,l=hu.z,h=lu.x,c=lu.y,u=lu.z,d=ou.x,p=ou.y,f=ou.z;const m=a+c+f;let _,g,y,v;if(m>0){let t=Math.sqrt(m+1);v=.5*t,t=.5/t,_=(u-p)*t,g=(d-l)*t,y=(o-h)*t}else if(a>=c&&a>=f){var x=Math.sqrt(1+a-c-f),w=.5/x;_=.5*x,g=(o+h)*w,y=(l+d)*w,v=(u-p)*w}else if(c>f){var b=Math.sqrt(1+c-a-f),S=.5/b;_=(h+o)*S,g=.5*b,y=(p+u)*S,v=(d-l)*S}else{var M=Math.sqrt(1+f-a-c),T=.5/M;_=(d+l)*T,g=(p+u)*T,y=.5*M,v=(o-h)*T}this.set(_,g,y,v)}lookRotation(t,e=S.up){this._lookRotation(t.x,t.y,t.z,e.x,e.y,e.z)}__setThreeEuler(t){return this.__setRotationMatrix(au.elements),t.setFromRotationMatrix(au)}copyInverse(t){this.copy(t),this.invert()}invert(){const t=this.x,e=this.y,i=this.z,n=this.w,s=t*t+e*e+i*i+n*n;if(0===s)return void this.set(0,0,0,0);const r=1/s,a=-t*r,o=-e*r,l=-i*r,h=n*r;this.set(a,o,l,h)}angleTo(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=t.x,a=t.y,o=t.z,l=e*e+i*i+n*n+s*s;let h,c,u,d;if(0===l)h=0,c=0,u=0,d=0;else{const t=1/l;h=-e*t,c=-i*t,u=-n*t,d=s*t}const p=y(t.w*d-r*h-a*c-o*u,-1,1);return 2*Math.acos(p)}fromAxisAngle(t,e){this._fromAxisAngle(t.x,t.y,t.z,e)}_fromAxisAngle(t,e,i,n){const s=.5*n,r=Math.sin(s),a=t*r,o=e*r,l=i*r,h=Math.cos(s),c=1/Math.sqrt(a*a+o*o+l*l+h*h),u=a*c,d=o*c,p=l*c,f=h*c;this.set(u,d,p,f)}computeSwingAndTwist(t,e,i){const n=this.x,s=this.y,r=this.z,a=this.w,o=m(n,s,r,t.x,t.y,t.z),l=o/(t.x*t.x+t.y*t.y+t.z*t.z),h=t.x*l,c=t.y*l,u=t.z*l;o<0?i.set(-h,-c,-u,-a):i.set(h,c,u,a),i.normalize(),e._multiplyQuaternions(n,s,r,a,-i.x,-i.y,-i.z,i.w)}computeTwistAngle(t){const e=new cu,i=new cu;return this.computeSwingAndTwist(t,e,i),2*Math.acos(i.w)}toAxisAngle(t){const e=2*Math.acos(this.w),i=Math.sin(e/2);return i>b?t.set(this.x/i,this.y/i,this.z/i):t.set(1,0,0),e}normalize(){let t=this.length();if(t<b)this.set(0,0,0,1);else{const e=1/t;this.multiplyScalar(e)}}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t,this.w*t)}multiply(t){this.multiplyQuaternions(this,t)}multiplyQuaternions(t,e){const i=t.x,n=t.y,s=t.z,r=t.w,a=e.x,o=e.y,l=e.z,h=e.w;this._multiplyQuaternions(i,n,s,r,a,o,l,h)}_multiplyQuaternions(t,e,i,n,s,r,a,o){const l=t*o+n*s+e*a-i*r,h=e*o+n*r+i*s-t*a,c=i*o+n*a+t*r-e*s,u=n*o-t*s-e*r-i*a;return this.set(l,h,c,u)}length(){const t=this.x,e=this.y,i=this.z,n=this.w;return Math.sqrt(t*t+e*e+i*i+n*n)}rotateTowards(t,e){cu.rotateTowards(this,this,t,e)}alignToDirection(t,e=S.up,i=S.forward){const n=e.dot(t);Math.abs(n+1)<1e-6?this.set(i.x,i.y,i.z,Math.PI):Math.abs(n-1)<1e-6&&this.set(0,0,0,1);const s=Math.acos(n);uu.crossVectors(e,t),uu.normalize(),this.fromAxisAngle(uu,s)}lookAt(t,e){const i=new S;i.subVectors(e,t),i.normalize(),this.alignToDirection(i)}setRandom(t){this.set(t(),t(),t(),t()),this.normalize()}__setFromEuler(t,e,i,n="XYZ"){return"XYZ"===n?this.fromEulerAnglesXYZ(t,e,i):"YXZ"===n?this.fromEulerAnglesYXZ(t,e,i):"ZXY"===n?this.fromEulerAnglesZXY(t,e,i):"ZYX"===n?this.fromEulerAnglesZYX(t,e,i):"YZX"===n?this.fromEulerAnglesYZX(t,e,i):"XZY"===n&&this.fromEulerAnglesXZY(t,e,i),this}toEulerAnglesXYZ(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=s*s,a=e*e,o=i*i,l=n*n,h=2*(e*s-i*n),c=r-a-o+l,u=Math.atan2(h,c),d=2*(e*n+i*s),p=Math.asin(d),f=2*(n*s-e*i),m=r+a-o-l,_=Math.atan2(f,m);t.set(u,p,_)}toEulerAnglesYXZ(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=n*n,a=e*e,o=s*s,l=i*i,h=2*(e*n+s*i),c=o-a-l+r,u=-2*(i*n-s*e),d=2*(e*i+s*n),p=o-a+l-r,f=Math.atan2(d,p),m=Math.asin(u),_=Math.atan2(h,c);t.set(m,_,f)}toEulerAnglesZYX(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=e*e,a=i*i,o=n*n,l=s*s,h=2*(e*i+s*n),c=l+r-a-o,u=-2*(e*n-s*i),d=2*(i*n+s*e),p=l-r-a+o,f=Math.atan2(d,p),m=Math.asin(u),_=Math.atan2(h,c);t.set(f,m,_)}threeSetRotationMatrix(t){this.__setFromRotationMatrix(t.elements)}__setRotationMatrix(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=e+e,a=i+i,o=n+n,l=e*r,h=e*a,c=e*o,u=i*a,d=i*o,p=n*o,f=s*r,m=s*a,_=s*o;t[0]=1-(u+p),t[4]=h-_,t[8]=c+m,t[1]=h+_,t[5]=1-(l+p),t[9]=d-f,t[2]=c-m,t[6]=d+f,t[10]=1-(l+u),t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1}fromEulerAngles(t,e,i){return this.fromEulerAnglesXYZ(t,e,i)}fromEulerAnglesXYZ(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=Math.sin,o=Math.cos,l=a(n),h=a(s),c=a(r),u=o(n),d=o(s),p=o(r),f=l*d*p+u*h*c,m=u*h*p-l*d*c,_=u*d*c+l*h*p,g=u*d*p-l*h*c;this.set(f,m,_,g)}fromEulerAnglesYXZ(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=Math.sin,o=Math.cos,l=a(n),h=a(s),c=a(r),u=o(n),d=o(s),p=o(r),f=l*d*p+u*h*c,m=u*h*p-l*d*c,_=u*d*c-l*h*p,g=u*d*p+l*h*c;this.set(f,m,_,g)}fromEulerAnglesZXY(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=Math.sin,o=Math.cos,l=a(n),h=a(s),c=a(r),u=o(n),d=o(s),p=o(r),f=l*d*p-u*h*c,m=u*h*p+l*d*c,_=u*d*c+l*h*p,g=u*d*p-l*h*c;this.set(f,m,_,g)}fromEulerAnglesZYX(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=Math.sin,o=Math.cos,l=a(n),h=a(s),c=a(r),u=o(n),d=o(s),p=o(r),f=l*d*p-u*h*c,m=u*h*p+l*d*c,_=u*d*c-l*h*p,g=u*d*p+l*h*c;this.set(f,m,_,g)}fromEulerAnglesYZX(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=Math.sin,o=Math.cos,l=a(n),h=a(s),c=a(r),u=o(n),d=o(s),p=o(r),f=l*d*p+u*h*c,m=u*h*p+l*d*c,_=u*d*c-l*h*p,g=u*d*p-l*h*c;this.set(f,m,_,g)}fromEulerAnglesXZY(t,e,i){const n=.5*t,s=.5*e,r=.5*i,a=Math.sin,o=Math.cos,l=a(n),h=a(s),c=a(r),u=o(n),d=o(s),p=o(r),f=l*d*p-u*h*c,m=u*h*p-l*d*c,_=u*d*c+l*h*p,g=u*d*p+l*h*c;this.set(f,m,_,g)}fromNonUnitVectors(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,a=e.y,o=e.z,l=n*o-s*a,h=s*r-i*o,c=i*a-n*r,u=m(i,n,s,r,a,o),d=l*l+h*h+c*c,p=u+Math.sqrt(d+u*u),f=Math.sqrt(d+p*p),_=l/f,g=h/f,y=c/f,v=u/f;this.set(_,g,y,v)}fromUnitVectors2(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,a=e.y,o=e.z,l=m(i,n,s,r,a,o);if(-1===l)return du.crossVectors(S.left,t),du.lengthSqr()<1e-5&&du.crossVectors(S.up,t),du.normalize(),void this.set(du.x,du.y,du.z,0);const h=Math.sqrt(2+2*l),c=1/h,u=c*(n*o-s*a),d=c*(s*r-i*o),p=c*(i*a-n*r);this.set(u,d,p,.5*h)}fromUnitVectors(t,e){const i=t.dot(e);let n,s,r,a;if(i<-.9999999){const e=new S;e.crossVectors(S.left,t),e.lengthSqr()<1e-5&&e.crossVectors(S.up,t),e.normalize(),this.fromAxisAngle(e,Math.PI)}else i>.9999999?(n=0,s=0,r=0,a=1,this.set(n,s,r,a)):(n=t.y*e.z-t.z*e.y,s=t.z*e.x-t.x*e.z,r=t.x*e.y-t.y*e.x,a=1+i,this.set(n,s,r,a),this.normalize())}setFromRotationMatrix(t){const e=t.elements;this.__setFromRotationMatrix(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10])}__setFromRotationMatrix(t,e,i,n,s,r,a,o,l){const h=t+s+l;let c,u,d,p,f;return h>0?(f=Math.sqrt(h+1),p=.5*f,f=.5/f,c=(o-r)*f,u=(i-a)*f,d=(n-e)*f):t>s&&t>l?(f=Math.sqrt(1+t-s-l),c=.5*f,f=.5/f,p=(o-r)*f,u=(e+n)*f,d=(i+a)*f):s>l?(f=Math.sqrt(1+s-t-l),u=.5*f,f=.5/f,p=(i-a)*f,c=(e+n)*f,d=(r+o)*f):(f=Math.sqrt(1+l-t-s),d=.5*f,f=.5/f,p=(n-e)*f,c=(i+a)*f,u=(r+o)*f),this.set(c,u,d,p)}lerp(t,e){this.lerpQuaternions(this,t,e)}lerpQuaternions(t,e,i){const n=p(t.x,e.x,i),s=p(t.y,e.y,i),r=p(t.z,e.z,i),a=p(t.w,e.w,i);this.set(n,s,r,a)}slerp(t,e){const i=this.x,n=this.y,s=this.z,r=this.w;let a,o,l,h,c,u=t.x,d=t.y,p=t.z,f=t.w;o=i*u+n*d+s*p+r*f,o<0&&(o=-o,u=-u,d=-d,p=-p,f=-f),1-o>b?(a=Math.acos(o),l=Math.sin(a),h=Math.sin((1-e)*a)/l,c=Math.sin(e*a)/l):(h=1-e,c=e);const m=h*i+c*u,_=h*n+c*d,g=h*s+c*p,y=h*r+c*f;this.set(m,_,g,y)}quaternionsInterpolateRungeKutta4(t,e,i){throw new Error("Not Implemented")}process(t){t(this.x,this.y,this.z,this.w),this.onChanged.add(t)}copy(t){return this.set(t.x,t.y,t.z,t.w)}clone(){const t=new cu;return t.copy(this),t}set(t,e,i,n){const s=this.x,r=this.y,a=this.z,o=this.w;return s===t&&r===e&&a===i&&o===n||(this.x=t,this.y=e,this.z=i,this.w=n,this.onChanged.hasHandlers()&&this.onChanged.send8(t,e,i,n,s,r,a,o)),this}conjugate(){return this.set(-this.x,-this.y,-this.z,this.w)}toJSON(){return{x:this.x,y:this.y,z:this.z,w:this.w}}fromJSON(t){this.set(t.x,t.y,t.z,t.w)}toBinaryBuffer(t){t.writeFloat64(this.x),t.writeFloat64(this.y),t.writeFloat64(this.z),t.writeFloat64(this.w)}fromBinaryBuffer(t){const e=t.readFloat64(),i=t.readFloat64(),n=t.readFloat64(),s=t.readFloat64();this.set(e,i,n,s)}toBinaryBufferFloat32(t){t.writeFloat32(this.x),t.writeFloat32(this.y),t.writeFloat32(this.z),t.writeFloat32(this.w)}fromBinaryBufferFloat32(t){const e=t.readFloat32(),i=t.readFloat32(),n=t.readFloat32(),s=t.readFloat32();this.set(e,i,n,s)}decodeFromUint32(t){const e=3&t,i=((t>>2&1023)/511-1)*pu,n=((t>>12&1023)/511-1)*pu,s=((t>>22&1023)/511-1)*pu,r=1-i*i-n*n-s*s,a=Math.sqrt(r);0===e?this.set(a,i,n,s):1===e?this.set(i,a,n,s):2===e?this.set(i,n,a,s):this.set(i,n,s,a)}encodeToUint32(){const t=this.x,e=this.y,i=this.z,n=this.w,s=Math.abs(t),r=Math.abs(e),a=Math.abs(i),o=Math.abs(n);let l,h,c,u,d=0;d=r>s?r>a?r>o?1:3:a>o?2:3:s>a?s>o?0:3:a>o?2:3,0===d?(l=e,h=i,c=n,u=t):1===d?(l=t,h=i,c=n,u=e):2===d?(l=t,h=e,c=n,u=i):(l=t,h=e,c=i,u=n),u<0&&(l=-l,h=-h,c=-c);const p=1/(Math.sqrt(t*t+e*e+i*i+n*n)*pu);return 3&d|(1023&Math.round(511*(l*p+1)))<<2|(1023&Math.round(511*(h*p+1)))<<12|(1023&Math.round(511*(c*p+1)))<<22}readFromArray(t,e=0){this.set(t[e],t[e+1],t[e+2],t[e+3])}writeToArray(t,e=0){t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w}asArray(){return[this.x,this.y,this.z,this.w]}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w}hash(){return x(this.x)^x(this.y)>>2^x(this.z)>>1^x(this.w)<<2}roughlyEquals(t,e){return this._roughlyEquals(t.x,t.y,t.z,t.w,e)}_roughlyEquals(t,e,i,n,s=b){return w(this.x,t,s)&&w(this.y,e,s)&&w(this.z,i,s)&&w(this.w,n,s)}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}random(t=Math.random){const e=t(),i=Math.sqrt(1-e),n=Math.sqrt(e),s=2*Math.PI*t(),r=2*Math.PI*t();return this.set(i*Math.cos(s),n*Math.sin(r),n*Math.cos(r),i*Math.sin(s))}static random(t=Math.random){const e=new cu;return e.random(t),e}static fromEulerAngles(t,e,i){const n=new cu;return n.fromEulerAnglesXYZ(t,e,i),n}static rotateTowards(t,e,i,n){const s=e.angleTo(i);if(0===s)t.copy(i);else{const t=ru(1,n/s);e.slerp(i,t)}}}cu.identity=Object.freeze(new cu(0,0,0,1));const uu=new S,du=new S,pu=.70710678118,fu=Math.hypot;var mu,_u="undefined"!=typeof Float32Array?Float32Array:Array;function gu(){var t=new _u(16);return _u!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function yu(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function vu(t,e){var i=e[0],n=e[1],s=e[2],r=e[3],a=e[4],o=e[5],l=e[6],h=e[7],c=e[8],u=e[9],d=e[10],p=e[11],f=e[12],m=e[13],_=e[14],g=e[15],y=i*o-n*a,v=i*l-s*a,x=i*h-r*a,w=n*l-s*o,b=n*h-r*o,S=s*h-r*l,M=c*m-u*f,T=c*_-d*f,C=c*g-p*f,A=u*_-d*m,E=u*g-p*m,z=d*g-p*_,I=y*z-v*E+x*A+w*C-b*T+S*M;return I?(I=1/I,t[0]=(o*z-l*E+h*A)*I,t[1]=(s*E-n*z-r*A)*I,t[2]=(m*S-_*b+g*w)*I,t[3]=(d*b-u*S-p*w)*I,t[4]=(l*C-a*z-h*T)*I,t[5]=(i*z-s*C+r*T)*I,t[6]=(_*x-f*S-g*v)*I,t[7]=(c*S-d*x+p*v)*I,t[8]=(a*E-o*C+h*M)*I,t[9]=(n*C-i*E-r*M)*I,t[10]=(f*b-m*x+g*y)*I,t[11]=(u*x-c*b-p*y)*I,t[12]=(o*T-a*A-l*M)*I,t[13]=(i*A-n*T+s*M)*I,t[14]=(m*v-f*w-_*y)*I,t[15]=(c*w-u*v+d*y)*I,t):null}function xu(t,e,i){var n=e[0],s=e[1],r=e[2],a=e[3],o=e[4],l=e[5],h=e[6],c=e[7],u=e[8],d=e[9],p=e[10],f=e[11],m=e[12],_=e[13],g=e[14],y=e[15],v=i[0],x=i[1],w=i[2],b=i[3];return t[0]=v*n+x*o+w*u+b*m,t[1]=v*s+x*l+w*d+b*_,t[2]=v*r+x*h+w*p+b*g,t[3]=v*a+x*c+w*f+b*y,v=i[4],x=i[5],w=i[6],b=i[7],t[4]=v*n+x*o+w*u+b*m,t[5]=v*s+x*l+w*d+b*_,t[6]=v*r+x*h+w*p+b*g,t[7]=v*a+x*c+w*f+b*y,v=i[8],x=i[9],w=i[10],b=i[11],t[8]=v*n+x*o+w*u+b*m,t[9]=v*s+x*l+w*d+b*_,t[10]=v*r+x*h+w*p+b*g,t[11]=v*a+x*c+w*f+b*y,v=i[12],x=i[13],w=i[14],b=i[15],t[12]=v*n+x*o+w*u+b*m,t[13]=v*s+x*l+w*d+b*_,t[14]=v*r+x*h+w*p+b*g,t[15]=v*a+x*c+w*f+b*y,t}function wu(t,e,i,n){const s=i.x,r=i.y,a=i.z,o=i.w,l=s+s,h=r+r,c=a+a,u=s*l,d=s*h,p=s*c,f=r*h,m=r*c,_=a*c,g=o*l,y=o*h,v=o*c,x=n.x,w=n.y,b=n.z;t[0]=(1-(f+_))*x,t[1]=(d+v)*x,t[2]=(p-y)*x,t[3]=0,t[4]=(d-v)*w,t[5]=(1-(u+_))*w,t[6]=(m+g)*w,t[7]=0,t[8]=(p+y)*b,t[9]=(m-g)*b,t[10]=(1-(u+f))*b,t[11]=0,t[12]=e.x,t[13]=e.y,t[14]=e.z,t[15]=1}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),mu=new _u(3),_u!=Float32Array&&(mu[0]=0,mu[1]=0,mu[2]=0);let bu=null,Su=16;const Mu=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),Tu=new ArrayBuffer(64),Cu=new Float32Array(Tu,0,16);class Au{constructor(){this.position=new S(0,0,0),this.rotation=new cu(0,0,0,1),this.scale=new S(1,1,1),this.matrix=function(){Su>=16&&(bu=new ArrayBuffer(1024),Su=0);const t=new Float32Array(bu,64*Su,16);return t.set(Mu),Su++,t}(),this.flags=2,this.subscribeAllChanges(this.__handle_component_change,this)}subscribeAllChanges(t,e){this.position.onChanged.add(t,e),this.rotation.onChanged.add(t,e),this.scale.onChanged.add(t,e)}unsubscribeAllChanges(t,e){this.position.onChanged.remove(t,e),this.rotation.onChanged.remove(t,e),this.scale.onChanged.remove(t,e)}__handle_component_change(){this.getFlag(2)&&this.updateMatrix()}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}updateMatrix(){wu(this.matrix,this.position,this.rotation,this.scale)}lookAt(t){const e=this.position,i=t.x-e.x,n=t.y-e.y,s=t.z-e.z;0===i&&0===n&&0===s||this.rotation._lookRotation(i,n,s,S.up.x,S.up.y,S.up.z)}fromJSON(t){const e=t.position;void 0!==e?this.position.fromJSON(e):this.position.copy(S.zero);const i=t.rotation;void 0!==i?this.rotation.fromJSON(i):this.rotation.copy(cu.identity);const n=t.scale;void 0!==n?this.scale.fromJSON(n):this.scale.copy(S.one)}toJSON(){return{position:this.position.toJSON(),rotation:this.rotation.toJSON(),scale:this.scale.toJSON()}}copy(t){this.clearFlag(2),this.matrix.set(t.matrix),this.position.copy(t.position),this.rotation.copy(t.rotation),this.scale.copy(t.scale),this.flags=t.flags}clone(){const t=new Au;return t.copy(this),t}equals(t){return t.isTransform&&this.position.equals(t.position)&&this.rotation.equals(t.rotation)&&this.scale.equals(t.scale)}hash(){return this.position.hash()}static fromJSON(t){const e=new Au;return e.fromJSON(t),e}multiplyTransforms(t,e){xu(Cu,t.matrix,e.matrix),this.fromMatrix4(Cu)}fromThreeMatrix4(t){this.fromMatrix4(t.elements)}toThreeMatrix(t){this.toMatrix4(t.elements)}fromMatrix4(t){const e=this.getFlag(2);this.clearFlag(2),this.matrix.set(t),function(t,e,i,n){const s=t[0],r=t[1],a=t[2],o=fu(s,r,a),l=t[4],h=t[5],c=t[6],u=fu(l,h,c),d=t[8],p=t[9],f=t[10],m=fu(d,p,f),_=1/o,g=1/u,y=1/m,v=s*_,x=r*_,w=a*_,b=l*g,S=h*g,M=c*g,T=d*y,C=p*y,A=f*y;e.set(t[12],t[13],t[14]),n.set(o,u,m),i.__setFromRotationMatrix(v,b,T,x,S,C,w,M,A)}(t,this.position,this.rotation,this.scale),this.writeFlag(2,e)}toMatrix4(t){wu(t,this.position,this.rotation,this.scale)}makeIdentity(){this.position.copy(S.zero),this.rotation.copy(cu.identity),this.scale.copy(S.one)}}function Eu(t,e){return t<e?e:t}function zu(t,e,i){return t*(1-i)+e*i}Au.typeName="Transform",Au.prototype.isTransform=!0,Au.adjustRotation=function(t,e,i=Infinity){const n=new cu;n.lookRotation(e),t.rotateTowards(n,i)};const Iu={NoBlending:5,Normal:0,Add:1,Subtract:2,Multiply:3,MultiplyAdd:4},Nu={Uint8:"uint8",Uint16:"uint16",Uint32:"uint32",Uint64:"uint64",Int8:"int8",Int16:"int16",Int32:"int32",Int64:"int64",Float16:"float16",Float32:"float32",Float64:"float64"};function Lu(t){switch(Object.getPrototypeOf(t).constructor){case Uint8Array:case Uint8ClampedArray:return Nu.Uint8;case Uint16Array:return Nu.Uint16;case Uint32Array:return Nu.Uint32;case Int8Array:return Nu.Int8;case Int16Array:return Nu.Int16;case Int32Array:return Nu.Int32;case Float32Array:return Nu.Float32;case Float64Array:return Nu.Float64;default:throw new Error("unsupported constructor type")}}const Pu={[Nu.Uint8]:Uint8Array,[Nu.Uint16]:Uint16Array,[Nu.Uint32]:Uint32Array,[Nu.Int8]:Int8Array,[Nu.Int16]:Int16Array,[Nu.Int32]:Int32Array,[Nu.Float16]:Uint16Array,[Nu.Float32]:Float32Array,[Nu.Float64]:Float64Array},Fu=[],Du=[],Ou="undefined"!=typeof Uint8Array?Uint8Array:Array,Ru="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let t=0,e=Ru.length;t<e;++t)Fu[t]=Ru[t],Du[Ru.charCodeAt(t)]=t;function ku(t,e,i){const n=[];for(let r=e;r<i;r+=3){const e=(t[r]<<16&16711680)+(t[r+1]<<8&65280)+(255&t[r+2]);n.push(Fu[(s=e)>>18&63]+Fu[s>>12&63]+Fu[s>>6&63]+Fu[63&s])}var s;return n.join("")}Du["-".charCodeAt(0)]=62,Du["_".charCodeAt(0)]=63;class Uu{static encode(t){return function(t){let e;const i=t.length,n=i%3,s=[],r=16383,a=i-n;for(let e=0;e<a;e+=r){const i=ku(t,e,e+r>a?a:e+r);s.push(i)}return 1===n?(e=t[i-1],s.push(Fu[e>>2]+Fu[e<<4&63]+"==")):2===n&&(e=(t[i-2]<<8)+t[i-1],s.push(Fu[e>>10]+Fu[e>>4&63]+Fu[e<<2&63]+"=")),s.join("")}(new Uint8Array(t))}static decode(t){return function(t){var e,i,n=function(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var i=t.indexOf("=");return-1===i&&(i=e),[i,i===e?0:4-i%4]}(t),s=n[0],r=n[1],a=new Ou(function(t,e,i){return 3*(e+i)/4-i}(0,s,r)),o=0,l=r>0?s-4:s;for(i=0;i<l;i+=4)e=Du[t.charCodeAt(i)]<<18|Du[t.charCodeAt(i+1)]<<12|Du[t.charCodeAt(i+2)]<<6|Du[t.charCodeAt(i+3)],a[o++]=e>>16&255,a[o++]=e>>8&255,a[o++]=255&e;return 2===r&&(e=Du[t.charCodeAt(i)]<<2|Du[t.charCodeAt(i+1)]>>4,a[o++]=255&e),1===r&&(e=Du[t.charCodeAt(i)]<<10|Du[t.charCodeAt(i+1)]<<4|Du[t.charCodeAt(i+2)]>>2,a[o++]=e>>8&255,a[o++]=255&e),a}(t).buffer}}function Bu(t,i){const n=t.length;if(n!==i.length)return!1;if(n<128)return e(t,i);const s=t.byteLength;if(s!==i.byteLength)return!1;const r=t.constructor.BYTES_PER_ELEMENT;if(r!==i.constructor.BYTES_PER_ELEMENT)return!1;const a=t.buffer,o=i.buffer;if(a===o&&t.byteOffset===i.byteOffset)return!0;let l=t,h=i;return r<4&&s%4==0?(l=new Uint32Array(a,t.byteOffset,s/4),h=new Uint32Array(o,i.byteOffset,s/4)):r<2&&s%2==0&&(l=new Uint16Array(a,t.byteOffset,s/2),h=new Uint16Array(o,i.byteOffset,s/2)),e(l,h)}class Vu{constructor(t=[],e=1,i=0,n=0){if(!Number.isInteger(e)||e<0)throw new Error(`itemSize must be a non-negative integer, instead was ${e}`);if(!Number.isInteger(i)||e<0)throw new Error(`width must be a non-negative integer, instead was ${i}`);if(!Number.isInteger(n)||e<0)throw new Error(`height must be a non-negative integer, instead was ${n}`);if(void 0===t)throw new Error("data was undefined");this.width=i,this.height=n,this.itemSize=e,this.data=t,this.version=0,this.isSampler2D=!0}computeMax(t=0){const e=this.itemSize,i=this.data,n=i.length;if(0===n)return;let s=i[t],r=t;for(let a=t+e;a<n;a+=e){const t=i[a];s<t&&(s=t,r=a)}const a=this.width,o=r/this.itemSize|0;return{index:r,value:s,x:o%a,y:o/a|0}}computeMinIndices(t,e=0){const i=this.itemSize,n=this.data,s=n.length;if(0===s)return;let r=n[e],a=0;for(let o=e+i;o<s;o+=i){const e=n[o];r>e?(r=e,a=1,t[0]=o):e===r&&(t[a++]=o)}a<t.length&&t.splice(a,t.length-a)}computeMin(t=0){const e=this.itemSize,i=this.data,n=i.length;if(0===n)return;let s=i[t],r=t;for(let a=t+e;a<n;a+=e){const t=i[a];s>t&&(s=t,r=a)}const a=this.width,o=r/this.itemSize|0;return{index:r,value:s,x:o%a,y:o/a|0}}get(t,e,i){const n=[];return this.sampleBilinear(t,e,n,0),void 0!==i?(i.readFromArray(n,0),i):n[0]}sampleCatmullRomUV(t,e,i){const n=this.itemSize;for(let s=0;s<n;s++)i[s]=this.sampleChannelCatmullRomUV(t,e,s)}sampleChannelCatmullRomUV(t,e,i){const n=t*(this.width-1),s=e*(this.height-1);return this.sampleChannelCatmullRom(n,s,i)}sampleChannelCatmullRom(t,e,i){const n=Math.floor(t-.5)+.5,s=Math.floor(e-.5)+.5,r=t-n,a=e-s,o=r*(r*(1-.5*r)-.5),l=a*(a*(1-.5*a)-.5),h=r*(.5+r*(2-1.5*r)),c=a*(.5+a*(2-1.5*a)),u=r*r*(.5*r-.5),d=a*a*(.5*a-.5),p=1+r*r*(1.5*r-2.5)+h,f=1+a*a*(1.5*a-2.5)+c,m=n-1,_=s-1,g=n+2,y=s+2,v=n+h/p,x=s+c/f;let w=0;return w+=this.sampleChannelBilinear(m,_,i)*o*l,w+=this.sampleChannelBilinear(v,_,i)*p*l,w+=this.sampleChannelBilinear(g,_,i)*u*l,w+=this.sampleChannelBilinear(m,x,i)*o*f,w+=this.sampleChannelBilinear(v,x,i)*p*f,w+=this.sampleChannelBilinear(g,x,i)*u*f,w+=this.sampleChannelBilinear(m,y,i)*o*d,w+=this.sampleChannelBilinear(v,y,i)*p*d,w+=this.sampleChannelBilinear(g,y,i)*u*d,w}sampleBicubicUV(t,e,i){const n=this.itemSize;for(let s=0;s<n;s++)i[s]=this.sampleChannelBicubicUV(t,e,s)}sampleChannelBicubicUV(t,e,i){const n=t*(this.width-1),s=e*(this.height-1);return this.sampleChannelBicubic(n-.5,s-.5,i)}sampleChannelBicubic(t,e,i){const n=this.itemSize,s=this.width,r=this.height,a=this.data,o=s*n,l=s-1,h=r-1,c=y(t,0,l),u=y(e,0,h),d=0|c,p=0|u,f=c-d,m=u-p,_=Eu(0,d-1),g=Eu(0,p-1),v=ru(l,d+1),x=ru(h,p+1),w=ru(l,v+1),b=g*o+i,S=p*o+i,M=x*o+i,T=ru(h,x+1)*o+i,C=_*n,A=d*n,E=v*n,z=w*n,I=a[b+C],N=a[b+A],L=a[b+E],P=a[b+z],F=a[S+C],D=a[S+A],O=a[S+E],R=a[S+z],k=a[M+C],U=a[M+A],B=a[M+E],V=a[M+z],G=a[T+C],W=a[T+A],H=a[T+E],j=a[T+z],q=Gu(f,I,N,L,P),J=Gu(f,F,D,O,R),Y=Gu(f,k,U,B,V),X=Gu(f,G,W,H,j);return Gu(m,q,J,Y,X)}sampleBilinearUV(t,e,i,n=0){const s=this.itemSize;for(let r=0;r<s;r++)i[r+n]=this.sampleChannelBilinearUV(t,e,r)}sampleBilinear(t,e,i,n=0){const s=this.itemSize;for(let r=0;r<s;r++)i[r+n]=this.sampleChannelBilinear(t,e,r)}sampleChannelBilinearUV(t,e,i){const n=t*(this.width-1),s=e*(this.height-1);return this.sampleChannelBilinear(n,s,i)}sampleChannelBilinear(t,e,i){const n=this.itemSize,s=this.width,r=s*n,a=s-1,o=this.height-1,l=y(t,0,a),h=y(e,0,o),c=0|l,u=0|h,d=u*r,p=c*n+i,f=d+p;let m,_;m=l===c||c>=a?c:c+1,_=h===u||u>=o?u:u+1;const g=this.data,v=g[f];if(c===m&&u===_)return v;const x=l-c,w=h-u,b=m*n+i,S=_*r,M=S+p,T=S+b,C=g[d+b],A=g[M],E=g[T],z=zu(v,C,x),I=zu(A,E,x);return zu(z,I,w)}sampleNearestUV(t,e,i){const n=Math.round(t*(this.width-1)),s=Math.round(e*(this.height-1));this.read(ru(n,this.width-1),ru(s,this.height-1),i)}readChannel(t,e,i){const n=(e*this.width+t)*this.itemSize+i;return this.data[n]}read(t,e,i){const n=this.width,s=this.itemSize,r=(e*n+t)*s;for(let t=0;t<s;t++){const e=this.data[r+t];i[t]=e}}sample(t,e,i){const n=[];return this.sampleBilinear(t*(this.width-1),e*(this.height-1),n,0),i.readFromArray(n),n[0]}computeNeighbors(t,e){const i=this.width,n=this.height,s=t%i,r=t/i|0;s>0&&e.push(t-1),s<i-1&&e.push(t+1),r>0&&e.push(t-i),r<n-1&&e.push(t+i)}point2index(t,e){return t+e*this.width}index2point(t,e){const i=this.width,n=t%i,s=t/i|0;e.set(n,s)}makeArrayFiller(t,e){e=e||0;const i=this,n=[1/(t=t||255),1/t,1/t,1/t];let s;switch(i.itemSize){case 1:s=function(n,s,r,a){const o=(i.sampleChannelBilinear(r,a,0)+e)*t|0;s[n]=o,s[n+1]=o,s[n+2]=o,s[n+3]=255};break;case 2:s=function(s,r,a,o){i.sampleBilinear(a,o,n,0);const l=(n[0]+e)*t|0;r.fill(l,s,s+3),r[s+3]=(n[1]+e)*t|0};break;case 3:s=function(s,r,a,o){i.sampleBilinear(a,o,n,0),r[s]=(n[0]+e)*t|0,r[s+1]=(n[1]+e)*t|0,r[s+2]=(n[2]+e)*t|0,r[s+3]=255};break;case 4:s=function(s,r,a,o){i.sampleBilinear(a,o,n,0),r[s]=(n[0]+e)*t|0,r[s+1]=(n[1]+e)*t|0,r[s+2]=(n[2]+e)*t|0,r[s+3]=(n[3]+e)*t|0};break;default:throw new Error("unsupported item size")}return s}copyWithMargin(t,e,i,n,s,r,a,o,l,h,c){const u=this.itemSize,d=t.itemSize,p=Math.min(u,d),f=u*this.width,m=d*t.width,_=t.data,g=this.data;let y,v,x,w,b,S,M,T,C;for(C=i*m+e*u,v=Math.max(0,s-h),b=s;v<b;v++)for(S=v*f,y=Math.max(0,n-o),w=n;y<w;y++)for(T=S+y*u,x=0;x<p;x++)g[T+x]=_[C+x];for(M=i*m,v=Math.max(0,s-h),b=s;v<b;v++)for(S=v*f,y=0;y<r;y++)for(T=S+(y+n)*u,C=M+(y+e)*u,x=0;x<p;x++)g[T+x]=_[C+x];for(C=i*m+(e+r-1)*u,v=Math.max(0,s-h),b=s;v<b;v++)for(S=v*f,y=n+r,w=Math.min(this.width,y+l);y<w;y++)for(T=S+y*u,x=0;x<p;x++)g[T+x]=_[C+x];for(v=0;v<a;v++)for(S=(v+s)*f,M=(v+i)*m,C=M+e*u,y=Math.max(0,n-o),w=n;y<w;y++)for(T=S+y*u,x=0;x<p;x++)g[T+x]=_[C+x];for(this.copy(t,e,i,n,s,r,a),v=0;v<a;v++)for(S=(v+s)*f,M=(v+i)*m,C=M+(e+r-1)*u,y=n+r,w=Math.min(this.width,y+l);y<w;y++)for(T=S+y*u,x=0;x<p;x++)g[T+x]=_[C+x];for(C=(i+a-1)*m+e*u,v=s+r,b=Math.min(this.height,v+c);v<b;v++)for(S=v*f,y=Math.max(0,n-o),w=n;y<w;y++)for(T=S+y*u,x=0;x<p;x++)g[T+x]=_[C+x];for(M=(i+a-1)*m,v=s+r,b=Math.min(this.height,v+c);v<b;v++)for(S=v*f,y=0;y<r;y++)for(T=S+(y+n)*u,C=M+(y+e)*u,x=0;x<p;x++)g[T+x]=_[C+x];for(C=(i+a-1)*m+(e+r-1)*u,v=s+r,b=Math.min(this.height,v+c);v<b;v++)for(S=v*f,y=n+r,w=Math.min(this.width,y+l);y<w;y++)for(T=S+y*u,x=0;x<p;x++)g[T+x]=_[C+x];this.version++}copy(t,e,i,n,s,r,a){const o=Math.min(r,t.width-e,this.width-n),l=Math.min(a,t.height-i,this.height-s),h=this.itemSize,c=t.itemSize,u=Math.min(h,c),d=h*this.width,p=c*t.width,f=t.data,m=this.data;let _,g,y;for(g=0;g<l;g++){const t=(g+s)*d,r=(g+i)*p;for(_=0;_<o;_++){const i=t+(_+n)*h,s=r+(_+e)*c;for(y=0;y<u;y++)m[i+y]=f[s+y]}}this.version++}copy_sameItemSize(t,e,i,n,s,r,a){const o=this.itemSize;t.itemSize;const l=Math.min(r,t.width-e,this.width-n),h=Math.min(a,t.height-i,this.height-s),c=o*this.width,u=o*t.width,d=t.data,p=this.data,f=l*o;let m,_;for(m=0;m<h;m++){const t=(m+s)*c+n*o,r=(m+i)*u+e*o;for(_=0;_<f;_++)p[t+_]=d[r+_]}this.version++}paint(t,e,i,n,s,r,a,o=Iu.Normal){let l;if(o!==Iu.Normal)throw new Error(`Unsupported blendType(=${o})`);l=Wu;const h=Math.min(r,t.width-e,this.width-n),c=Math.min(a,t.height-i,this.height-s),u=Math.max(0,-n),d=[0,0,0,255],p=[0,0,0,255],f=[];let m,_;for(_=Math.max(0,-s);_<c;_++)for(m=u;m<h;m++){const e=Math.round(m+n),r=Math.round(_+s);this.read(e,r,d);const a=Math.round(m+i),o=Math.round(_+i);t.read(a,o,p),l(p,d,f),this.set(e,r,f)}}zeroFill(t,e,i,n){const s=y(t,0,this.width),r=y(e,0,this.height),a=y(t+i,0,this.width),o=y(e+n,0,this.height),l=this.data,h=this.itemSize,c=h*this.width,u=s*h,d=a*h;let p;for(p=r;p<o;p++){const t=p*c;l.fill(0,t+u,t+d)}this.version++}fill_channel(t,e){const i=this.itemSize,n=this.data,s=n.length;for(let r=t;r<s;r+=i)n[r]=e;this.version++}fill(t,e,i,n,s){const r=this.width,a=this.height,o=y(t,0,r),l=y(e,0,a),h=y(t+i,0,r),c=y(e+n,0,a),u=this.data,d=this.itemSize,p=d*r;let f,m,_;for(f=l;f<c;f++){const t=f*p;for(m=o;m<h;m++){const e=t+m*d;for(_=0;_<d;_++)u[e+_]=s[_]}}this.version++}writeChannel(t,e,i,n){const s=(e*this.width+t)*this.itemSize+i;this.data[s]=n,this.version++}set(t,e,i){const n=this.data,s=this.itemSize,r=s*this.width*e+t*s;for(let t=0;t<s;t++)n[r+t]=i[t];this.version++}traverseCircle(t,e,i,n){let s,r;const a=0|t,o=0|e,l=i*i,h=Math.ceil(i);for(r=-h;r<=h;r++){const t=r*r;for(s=-h;s<=h;s++)s*s+t<=l&&n(a+s,o+r,this)}}resize(t,e,i=!0){const n=this.width,s=this.height;if(n===t&&s===e)return;const r=this.itemSize,a=t*e*r,o=this.data,l=new(function(t){if(t instanceof Int8Array)return Int8Array;if(t instanceof Int16Array)return Int16Array;if(t instanceof Int32Array)return Int32Array;if(t instanceof Uint8Array)return Uint8Array;if(t instanceof Uint8ClampedArray)return Uint8ClampedArray;if(t instanceof Uint16Array)return Uint16Array;if(t instanceof Uint32Array)return Uint32Array;if(t instanceof Float32Array)return Float32Array;if(t instanceof Float64Array)return Float64Array;if(Array.isArray(t))return Array;throw new TypeError("Unsupported array type")}(o))(a);if(i)if(t===n)l.set(o.subarray(0,Math.min(o.length,a)));else{const i=ru(e,s),a=ru(t,n);for(let e=0;e<i;e++)for(let i=0;i<a;i++){const s=(e*t+i)*r,a=(e*n+i)*r;for(let t=0;t<r;t++)l[s+t]=o[a+t]}}this.width=t,this.height=e,this.data=l,this.version++}computeByteSize(){let t;return t=Array.isArray(this.data)?8*this.data.length:this.data.buffer.byteLength,t+280}toBinaryBuffer(t){const e=this.width,i=this.height,n=this.itemSize;if(t.writeUint16(e),t.writeUint16(i),t.writeUint8(n),!(this.data instanceof Uint8Array))throw new TypeError("Unsupported data type");{t.writeUint8(0);const s=e*i*n;t.writeBytes(this.data,0,s)}}fromBinaryBuffer(t){this.width=t.readUint16(),this.height=t.readUint16(),this.itemSize=t.readUint8();const e=t.readUint8();if(0!==e)throw new TypeError(`Unsupported data type (${e})`);{const e=this.height*this.width*this.itemSize;this.data=new Uint8Array(e),t.readBytes(this.data,0,e),this.version++}}traverseOrthogonalNeighbours(t,e,i,n){const s=this.width,r=this.height,a=this.point2index(t,e);let o=0;const l=this.data;t>0&&(o=a-1,i.call(n,t-1,e,l[o],o)),t<s-1&&(o=a+1,i.call(n,t+1,e,l[o],o)),e>0&&(o=a-s,i.call(n,t,e-1,l[o],o)),e<r-1&&(o=a+s,i.call(n,t,e+1,l[o],o))}equals(t){return this.width===t.width&&this.height===t.height&&this.itemSize===t.itemSize&&Bu(this.data,t.data)}hash(){let t=((65535&this.width)<<16|65535&this.height)^this.itemSize;const e=this.data.length,i=Math.max(1,Math.ceil(e/509));return t^=function(t,e,i,n){let s=i;for(let e=0;e<i;e+=n)s=31*s+t[e]|0;return s}(this.data,0,e,i),t}clone(){let t;return t=Array.isArray(this.data)?this.data.slice():new(0,this.data.constructor)(this.data),new Vu(t,this.itemSize,this.width,this.height)}toJSON(){const t=Uu.encode(this.data.buffer);return{height:this.height,width:this.width,itemSize:this.itemSize,type:Lu(this.data),data:t}}fromJSON({height:t,width:e,itemSize:i,type:n,data:s}){const r=function(t){const e=Pu[t];if(void 0===e)throw new Error(`Unsupported data type '${t}'`);return e}(n);if("string"==typeof s){const t=Uu.decode(s);this.data=new r(t)}else{if(!Array.isArray(s))throw new Error("Unsupported data format");this.data=new r(s)}this.height=t,this.width=e,this.itemSize=i}static uint8clamped(t,e,i){const n=new Uint8ClampedArray(e*i*t);return new Vu(n,t,e,i)}static uint8(t,e,i){const n=new Uint8Array(e*i*t);return new Vu(n,t,e,i)}static uint16(t,e,i){const n=new Uint16Array(e*i*t);return new Vu(n,t,e,i)}static uint32(t,e,i){const n=new Uint32Array(e*i*t);return new Vu(n,t,e,i)}static int8(t,e,i){const n=new Int8Array(e*i*t);return new Vu(n,t,e,i)}static int16(t,e,i){const n=new Int16Array(e*i*t);return new Vu(n,t,e,i)}static int32(t,e,i){const n=new Int32Array(e*i*t);return new Vu(n,t,e,i)}static float32(t,e,i){const n=new Float32Array(e*i*t);return new Vu(n,t,e,i)}static float64(t,e,i){const n=new Float64Array(e*i*t);return new Vu(n,t,e,i)}}function Gu(t,e,i,n,s){return.5*(n-e+(2*e-5*i+4*n-s+(3*(i-n)+s-e)*t)*t)*t+i}function Wu(t,e,i){const n=t[3]/255,s=e[3]/255;i[0]=t[0]*n+e[0]*(1-n),i[1]=t[1]*n+e[1]*(1-n),i[2]=t[2]*n+e[2]*(1-n),i[3]=255*(n+s*(1-n))}function Hu(t,e,i){const n=t[e];t[e]=t[i],t[i]=n}const ju=[];function qu(t,e,i,n,s,r=Hu,a=undefined){if(n>=s)return;let o,l,h=2;for(ju[0]=n,ju[1]=s;h>0;){h-=2;const n=ju[h+1],s=ju[h];o=s,l=n;const c=s+n>>1,u=e.call(i,t[c]);for(;o<=l;){for(;e.call(i,t[o])<u;)o++;for(;e.call(i,t[l])>u;)l--;o<=l&&(o!==l&&r.call(a,t,o,l),o++,l--)}s<l&&(ju[h++]=s,ju[h++]=l),o<n&&(ju[h++]=o,ju[h++]=n)}}function Ju(t,e=0,i=t.length){let n=0;const s=i-e;for(let e=0;e<i;e++)n+=t[e];return n/s}function Yu(t){let e=t;return e=50331903&(e|e<<16),e=50393103&(e|e<<8),e=51130563&(e|e<<4),e=153391689&(e|e<<2),e}function Xu(t,e,i){return Yu(t)|Yu(e)<<1|Yu(i)<<2}function Zu(t,e,i,n,s,r,a,o,l,h){return n+t*(t>0?o:s)+e*(e>0?l:r)+i*(i>0?h:a)}function $u(t,e,i,n,s,r,a){return m(n,s,r,t,e,i)+a}function Ku(t,e,i,n,s,r,a,o,l,h){let c,u,d,p,f,m,_=0;return t>0?(c=s,p=o):(c=o,p=s),e>0?(u=r,f=l):(u=l,f=r),i>0?(d=a,m=h):(d=h,m=a),$u(c,u,d,t,e,i,n)>=0?_+=1:_-=1,$u(p,f,m,t,e,i,n)>=0?_+=1:_-=1,_}function Qu(t,e,i,n,s,r,a,o){t[e]=i,t[e+1]=n,t[e+2]=s,t[e+3]=r,t[e+4]=n,t[e+5]=s,t[e+6]=i,t[e+7]=a,t[e+8]=s,t[e+9]=r,t[e+10]=a,t[e+11]=s,t[e+12]=i,t[e+13]=n,t[e+14]=o,t[e+15]=r,t[e+16]=n,t[e+17]=o,t[e+18]=i,t[e+19]=a,t[e+20]=o,t[e+21]=r,t[e+22]=a,t[e+23]=o}function td(t,e,i,n,s,r,a){let o=2,l=0;for(;l<24;l+=4){const h=Ku(a[l],a[l+1],a[l+2],a[l+3],t,e,i,n,s,r);if(h<0)return 0;0===h&&(o=1)}return o}function ed(t){return t>=0?t:-t}function id(t,e,i,n,s,r,a,o,l,h,c,u){const d=.5*(n-t),p=a-(t+d);if(p*h>=0&&ed(p)>d)return!1;const f=.5*(s-e),m=o-(e+f);if(m*c>=0&&ed(m)>f)return!1;const _=.5*(r-i),g=l-(i+_);if(g*u>=0&&ed(g)>_)return!1;const y=ed(c),v=ed(u),x=ed(h);return!(ed(c*g-u*m)>f*v+_*y||ed(u*p-h*g)>d*v+_*x||ed(h*m-c*p)>d*y+f*x)}function nd(t,e,i,n,s,r){const a=n-t,o=r-i;return 2*((s-e)*(a+o)+o*a)}function sd(t,e,i){t[0]=t[3]=i[12],t[1]=t[4]=i[13],t[2]=t[5]=i[14];for(let n=0;n<3;n++)for(let s=0;s<3;s++){const r=i[n+4*s],a=r*e[s],o=r*e[s+3];a<o?(t[n]+=a,t[n+3]+=o):(t[n]+=o,t[n+3]+=a)}}class rd{constructor(t=0,e=0,i=0,n=0,s=0,r=0){this.setBounds(t,e,i,n,s,r)}*[Symbol.iterator](){yield this.x0,yield this.y0,yield this.z0,yield this.x1,yield this.y1,yield this.z1}get 0(){return this.x0}get 1(){return this.y0}get 2(){return this.z0}get 3(){return this.x1}get 4(){return this.y1}get 5(){return this.z1}set 0(t){this.x0=t}set 1(t){this.y0=t}set 2(t){this.z0=t}set 3(t){this.x1=t}set 4(t){this.y1=t}set 5(t){this.z1=t}containsPoint(t,e,i){return t>=this.x0&&t<=this.x1&&e>=this.y0&&e<=this.y1&&i>=this.z0&&i<=this.z1}containsPointWithTolerance(t,e,i,n){return!(t+n<this.x0||t-n>this.x1||e+n<this.y0||e-n>this.y1||i+n<this.z0||i-n>this.z1)}computeMortonCode(){return Xu(this.x0+this.x1>>1,this.y0+this.y1>>1,this.z0+this.z1>>1)}computeSurfaceArea(){return nd(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1)}getSurfaceArea(){return this.computeSurfaceArea()}computeVolume(){return this.getExtentsX()*this.getExtentsY()*this.getExtentsZ()}copy(t){this.setBounds(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}setBounds(t,e,i,n,s,r){this.x0=t,this.y0=e,this.z0=i,this.x1=n,this.y1=s,this.z1=r}equals(t){return this._equals(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}_equals(t,e,i,n,s,r){return this.x0===t&&this.y0===e&&this.z0===i&&this.x1===n&&this.y1===s&&this.z1===r}setBoundsUnordered(t,e,i,n,s,r){let a,o,l,h,c,u;t<n?(a=t,h=n):(a=n,h=t),e<s?(o=e,c=s):(o=s,c=e),i<r?(l=i,u=r):(l=r,u=i),this.setBounds(a,o,l,h,c,u)}setNegativelyInfiniteBounds(){this.setBounds(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY)}setInfiniteBounds(){this.setBounds(Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY)}distanceToPoint2(t,e,i){return function(t,e,i,n,s,r,a,o,l){const h=e-o,c=o-s,u=i-l,d=l-r,p=Eu(t-a,a-n),f=Eu(h,c),m=Eu(u,d),_=p*p+f*f+m*m;return p<0&&f<0&&m<0?-_:_}(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t,e,i)}distanceToBox(t){return this._distanceToBox(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}_distanceToBox(t,e,i,n,s,r){const a=this.x0,o=this.y0,l=this.z0,h=a-n,c=t-this.x1,u=o-s,d=e-this.y1,p=l-r,f=i-this.z1,m=Math.max(h,c),_=Math.max(u,d),g=Math.max(p,f);let y=Math.sqrt(m*m+_*_+g*g);return m<0&&_<0&&g<0?-y:y}costForInclusion(t){return this._costForInclusion(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}_costForInclusion(t,e,i,n,s,r){let a=0,o=0,l=0;const h=this.x0,c=this.y0,u=this.z0,d=this.x1,p=this.y1,f=this.z1;h>t&&(a+=h-t),d<n&&(a+=n-d),c>e&&(o+=c-e),p<s&&(o+=s-p),u>i&&(l+=u-i),f<r&&(l+=r-f);const m=d-h,_=p-c,g=f-u;return a*(_+g)+o*(m+g)+l*(m+_)}_expandToFitPoint(t,e,i){let n=!1;return t<this.x0&&(this.x0=t,n=!0),e<this.y0&&(this.y0=e,n=!0),i<this.z0&&(this.z0=i,n=!0),t>this.x1&&(this.x1=t,n=!0),e>this.y1&&(this.y1=e,n=!0),i>this.z1&&(this.z1=i,n=!0),n}expandToFit(t){return this._expandToFit(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}_expandToFit(t,e,i,n,s,r){let a=!1;return t<this.x0&&(this.x0=t,a=!0),e<this.y0&&(this.y0=e,a=!0),i<this.z0&&(this.z0=i,a=!0),n>this.x1&&(this.x1=n,a=!0),s>this.y1&&(this.y1=s,a=!0),r>this.z1&&(this.z1=r,a=!0),a}_containsBox(t,e,i,n,s,r){return t>=this.x0&&e>=this.y0&&i>=this.z0&&n<=this.x1&&s<=this.y1&&r<=this.z1}containsBox(t){return this._containsBox(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}getExtentsX(){return this.x1-this.x0}getExtentsY(){return this.y1-this.y0}getExtentsZ(){return this.z1-this.z0}getHalfExtentsX(){return this.getExtentsX()/2}getHalfExtentsY(){return this.getExtentsY()/2}getHalfExtentsZ(){return this.getExtentsZ()/2}getExtents(t){const e=this.x1-this.x0,i=this.y1-this.y0,n=this.z1-this.z0;t.set(e,i,n)}getCenterX(){return.5*(this.x0+this.x1)}getCenterY(){return.5*(this.y0+this.y1)}getCenterZ(){return.5*(this.z0+this.z1)}getCenter(t){const e=this.getCenterX(),i=this.getCenterY(),n=this.getCenterZ();t.set(e,i,n)}intersectRay(t,e,i,n,s,r){return id(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t,e,i,n,s,r)}intersectSegment(t,e,i,n,s,r){return function(t,e,i,n,s,r,a,o,l,h,c,u){let d,p,f,m,_,g,y,v,x,w,b,S,M,T,C,A;return y=.5*(h-a),d=(n-t)/2,w=t+d,m=.5*(h+a)-w,M=ed(y),!(ed(m)>d+M||(v=.5*(c-o),p=(s-e)/2,b=e+p,_=.5*(c+o)-b,T=ed(v),ed(_)>p+T||(x=.5*(u-l),f=(r-i)/2,S=i+f,g=.5*(u+l)-S,C=ed(x),ed(g)>f+C||(A=v*g-x*_,ed(A)>p*C+f*T||(A=x*m-y*g,ed(A)>d*C+f*M||(A=y*_-v*m,ed(A)>d*T+p*M))))))}(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t,e,i,n,s,r)}threeContainsBox(t){const e=t.min,i=t.max;return this._containsBox(e.x,e.y,e.z,i.x,i.y,i.z)}traverseCorners(t,e){const i=this.x0,n=this.y0,s=this.z0,r=this.x1,a=this.y1,o=this.z1;t.call(e,i,n,s),t.call(e,i,n,o),t.call(e,i,a,s),t.call(e,i,a,o),t.call(e,r,n,s),t.call(e,r,n,o),t.call(e,r,a,s),t.call(e,r,a,o)}getCorners(t){Qu(t,0,this.x0,this.y0,this.z0,this.x1,this.y1,this.z1)}writeToArray(t,e=0){t[e]=this.x0,t[e+1]=this.y0,t[e+2]=this.z0,t[e+3]=this.x1,t[e+4]=this.y1,t[e+5]=this.z1}readFromArray(t,e=0){this.x0=t[e],this.y0=t[e+1],this.z0=t[e+2],this.x1=t[e+3],this.y1=t[e+4],this.z1=t[e+5]}computePlaneSide(t){const e=t.normal;return Ku(e.x,e.y,e.z,t.constant,this.x0,this.y0,this.z0,this.x1,this.y1,this.z1)}computeDistanceAbovePlane(t,e,i,n){return Zu(t,e,i,n,this.x0,this.y0,this.z0,this.x1,this.y1,this.z1)}_isBelowPlane(t,e,i,n){return this.computeDistanceAbovePlane(t,e,i,n)<0}isBelowPlane(t){const e=t.normal;return this._isBelowPlane(e.x,e.y,e.z,t.constant)}intersectSpace(t){let e=0;const i=t.length;for(;e<i;e++){const i=t[e];if(this.isBelowPlane(i))return!1}return!0}intersectFrustumDegree(t){const e=t.planes;let i=0,n=2;for(;i<6;i++){const t=e[i],s=this.computePlaneSide(t);if(s<0)return 0;0===s&&(n=1)}return n}intersectFrustumDegree_array(t){return td(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t)}intersectFrustum(t){const e=t.planes;for(let t=0;t<6;t++){const i=e[t];if(this.isBelowPlane(i))return!1}return!0}intersectFrustum_array(t){return function(t,e,i,n,s,r,a){for(let o=0;o<24;o+=4)if(Zu(a[o],a[o+1],a[o+2],a[o+3],t,e,i,n,s,r)<0)return!1;return!0}(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t)}applyMatrix4(t){const e=[],i=[];this.writeToArray(e,0),sd(i,e,t),this.readFromArray(i,0)}grow(t){this.x0-=t,this.y0-=t,this.z0-=t,this.x1+=t,this.y1+=t,this.z1+=t}clone(){const t=new rd;return t.copy(this),t}fromJSON({x0:t,y0:e,z0:i,x1:n,y1:s,z1:r}){this.setBounds(t,e,i,n,s,r)}}rd.prototype.isAABB3=!0;class ad extends rd{constructor(){super(),this.parentNode=null,this._mortonCode=void 0}validateAncestorChain(){const t=this.parentNode;return null===t||!!t.containsBox(this)&&(t.left===this||t.right===this)}computeDepth(){let t=0,e=this.parentNode;for(;null!==e;)e=e.parentNode,t++;return t}computeRoot(){let t=this;for(;null!==t.parentNode;)t=t.parentNode;return t}getMortonCode(){if(void 0===this._mortonCode){const t=Xu((this.x1+this.x0)/2,(this.y1+this.y0)/2,(this.z1+this.z0)/2);return this._mortonCode=t,t}return this._mortonCode}bubbleExpandToFit(t){let e=this;for(;e.expandToFit(t)&&(e=e.parentNode,null!==e););}remove(){this.disconnect()}disconnect(){const t=this.parentNode;if(null!==t){if(this===t.left)t.left=null,this.parentNode=null;else{if(this!==t.right)throw new Error("impostor child");t.right=null,this.parentNode=null}t.updateLeafNodeCount(),t.updateHeight()}}traverseSiblingsUp(){throw new Error("Not Implemented")}}function od(t){return t.isLeafNode}class ld extends ad{constructor(t,e,i,n,s,r,a){super(),this.object=t,this.parentNode=null,this.x0=e,this.y0=i,this.z0=n,this.x1=s,this.y1=r,this.z1=a}move(t,e,i){this.x0+=t,this.x1+=t,this.y0+=e,this.y1+=e,this.z0+=i,this.z1+=i,null!==this.parentNode&&this.parentNode.bubbleRefit()}resize(t,e,i,n,s,r){this.setBounds(t,e,i,n,s,r),this.bubbleRefit()}bubbleRefit(){null!==this.parentNode&&this.parentNode.bubbleRefit()}clone(){const t=new ld(this.object,this.x0,this.y0,this.z0,this.x1,this.y1,this.z1);return t.parentNode=this.parentNode,t}}ld.prototype.isLeafNode=!0,ld.prototype.height=0,ld.prototype.leafNodeCount=1;class hd{constructor(){}initialize(){}finalize(){}visitLeaf(t){}visitBinary(t){return!0}}const cd=[];let ud=0;function dd(t,e){let i;const n=ud;for(cd[ud++]=t;ud-- >n;)i=cd[ud],i.isBinaryNode?!1!==e.visitBinary(i)&&(null!==i.left&&(cd[ud++]=i.left),null!==i.right&&(cd[ud++]=i.right)):e.visitLeaf(i);ud=n}function pd(t,e,i,n){return e>=i&&n>=t}function fd(t,e,i,n,s,r){const a=n-t,o=r-i;return(s-e)*(a+o)+o*a}function md(t){return fd(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1)}function _d(t,e){return fd(ru(t.x0,e.x0),ru(t.y0,e.y0),ru(t.z0,e.z0),Eu(t.x1,e.x1),Eu(t.y1,e.y1),Eu(t.z1,e.z1))}let gd=0;const yd=[];class vd extends ad{constructor(){super(),this.parentNode=null,this.left=null,this.right=null,this.leafNodeCount=0,this.height=0}traversePreOrderUsingStack(t,e){let i=0;const n=gd;let s;for(yd[gd++]=this;gd-- >n;)i++,s=yd[gd],!1!==t.call(e,s)&&s.isBinaryNode&&(null!==s.right&&(yd[gd++]=s.right),null!==s.left&&(yd[gd++]=s.left));return gd=n,i}traverseLeavesPreOrderUsingStack(t,e){let i=0;const n=gd;let s;for(yd[gd++]=this;gd-- >n;)i++,s=yd[gd],s.isLeafNode?t.call(e,s):(null!==s.right&&(yd[gd++]=s.right),null!==s.left&&(yd[gd++]=s.left));return gd=n,i}isEmpty(){return null===this.left&&null===this.right}reset(){this.left=null,this.right=null,this.leafNodeCount=0,this.height=0,this.setNegativelyInfiniteBounds()}setChildren(t,e){this.left=t,this.right=e,t.parentNode=this,e.parentNode=this}setChildLeft(t){this.left=t,t.parentNode=this}setChildRight(t){this.right=t,t.parentNode=this}__insertion_findSiblingFor(t){let e=this,i=0,n=0;for(;!0===e.isBinaryNode;){const s=e.left,r=e.right,a=md(e),o=_d(e,t),l=o,h=o-a;if(null!==s){const e=_d(s,t);i=s.isLeafNode?e+h:e-md(s)+h}else i=Infinity;if(null!==r){const e=_d(r,t);n=r.isLeafNode?e+h:e-md(r)+h}else n=Infinity;if(l<i&&l<n)break;if(i<n&&null!==s)e=s;else{if(null===r)break;e=r}}return e}findParentFor(t){let e=this,i=0,n=0;for(;;){const s=e.left,r=e.right;if(null===s||null===r)return e;const a=s.isBinaryNode,o=r.isBinaryNode;if(i=s.costForInclusion(t),n=r.costForInclusion(t),i===n){if(s.isLeafNode)return s;if(r.isLeafNode)return r;i=s.leafNodeCount/md(s),n=r.leafNodeCount/md(r)}if(i===n&&(i=Math.random(),n=1-i),i<n){if(!a)return s;e=s}else{if(!o)return r;e=r}}}traverse(t){null!==this.left&&!1!==t(this.left)&&this.left.traverse(t),null!==this.right&&!1!==t(this.right)&&this.right.traverse(t)}traversePostOrder(t){this.left instanceof vd?this.left.traversePostOrder(t):this.left instanceof ld&&t(this.left),this.right instanceof vd?this.right.traversePostOrder(t):this.right instanceof ld&&t(this.right),t(this)}traversePreOrder(t){!1!==t(this)&&(this.left instanceof vd?this.left.traversePreOrder(t):this.left instanceof ld&&t(this.left),this.right instanceof vd?this.right.traversePreOrder(t):this.right instanceof ld&&t(this.right))}refitFor2(){const t=this.left,e=this.right;this.x0=ru(t.x0,e.x0),this.y0=ru(t.y0,e.y0),this.z0=ru(t.z0,e.z0),this.x1=Eu(t.x1,e.x1),this.y1=Eu(t.y1,e.y1),this.z1=Eu(t.z1,e.z1)}bubbleRefit(){let t=this;for(t.refit();;){const e=t.x0,i=t.y0,n=t.z0,s=t.x1,r=t.y1,a=t.z1;if(t=t.parentNode,null===t)return;let o=!1;if(e<t.x0&&(t.x0=e,o=!0),i<t.y0&&(t.y0=i,o=!0),n<t.z0&&(t.z0=n,o=!0),s>t.x1&&(t.x1=s,o=!0),r>t.y1&&(t.y1=r,o=!0),a>t.z1&&(t.z1=a,o=!0),!o)break}}refit(){null!==this.left&&null!==this.right?this.refitFor2():null!==this.left?this.copy(this.left):null!==this.right&&this.copy(this.right)}sumSurfaceArea(){let t=0;return this.traversePreOrderUsingStack((function(e){const i=e.computeSurfaceArea();t+=i})),t}countDescendants(){let t=0;return this.traversePreOrderUsingStack((function(e){t++})),t}computeSAH(){let t,e,i,n;const s=this.left;null===s?(i=0,t=0):(i=md(s),t=s.leafNodeCount);const r=this.right;null===r?(n=0,e=0):(n=md(r),e=r.leafNodeCount);return 1+1*(i*t/(a=md(this))+n*e/a);var a}updateHeight(){let t=this,e=0;for(;null!==t;){e=0;const i=t.right;null!==i&&(e=i.height);const n=this.left;null!==n&&(e=Eu(e,n.height)),t.height=e+1,t=t.parentNode}}updateLeafNodeCount(){let t=this;for(;null!==t;){let e=0;const i=t.right;null!==i&&(i.isLeafNode?e++:e+=i.leafNodeCount);const n=this.left;null!==n&&(n.isLeafNode?e++:e+=n.leafNodeCount),t.leafNodeCount=e,t=t.parentNode}}rotateLeft(){const t=this.right,e=this.left,i=t.left,n=t.right;this.left=t,this.right=n,null!==n&&(n.parentNode=this),t.left=e,null!==e&&(e.parentNode=t),t.right=i,t.updateLeafNodeCount(),t.updateHeight(),t.bubbleRefit()}rotateRight(){const t=this.right,e=this.left,i=e.left,n=e.right;null!==i&&(i.parentNode=this),e.right=t,null!==t&&(t.parentNode=e),e.left=n,e.updateLeafNodeCount(),e.updateHeight(),e.bubbleRefit()}insertManyBoxes2(t,e){let i,n;const s=new Array(e);for(i=0;i<e;i++)n=t(i),s[i]=n;qu(s,(t=>t.computeMortonCode()),null,0,Eu(0,e-1));let r=e;for(;r>2;){for(i=0;i<r-1;i+=2){const t=s[i],e=s[i+1];n=new vd,n.setChildren(t,e),n.updateHeight(),n.refitFor2(),s[i>>1]=n}const t=1&r;0!==t&&(s[i>>1]=s[i]),r=(r>>1)+t}for(i=0;i<r;i++)n=s[i],this.insertNode(n)}requestLeafIntersectionsAABB3(t,e,i,n,s,r,a){const o=gd;yd[gd++]=this;let l=0;for(;gd>o;){gd--;const o=yd[gd];if(h=e,c=i,u=n,d=s,p=r,f=a,m=o.x0,_=o.y0,g=o.z0,y=o.x1,v=o.y1,x=o.z1,pd(h,d,m,y)&&pd(c,p,_,v)&&pd(u,f,g,x))if(o.isLeafNode)t[l++]=o,l++;else{const t=o.left;null!==t&&(yd[gd++]=t);const e=o.right;null!==e&&(yd[gd++]=e)}}var h,c,u,d,p,f,m,_,g,y,v,x;return l}traverseSegmentLeafIntersections(t,e,i,n,s,r,a){this.traversePreOrder((function(o){return!(!o.intersectSegment(t,e,i,n,s,r)||o instanceof ld&&(a(o),1))}))}threeTraverseFrustumsIntersections(t,e){const i=t.length;return this.traversePreOrderUsingStack((function(n){let s=!1,r=0;for(;r<i;r++){const i=n.intersectFrustumDegree(t[r]);if(2===i)return n.isLeafNode?e(n,!0):n.traverseLeavesPreOrderUsingStack(xd,e),!1;1===i&&(s=!0)}return!!s&&(n.isLeafNode&&e(n,!1),!0)}))}threeTraverseFrustumsIntersections2(t,e){const i=t.length;function n(t){return!(t instanceof ld&&(e(t),1))}function s(t,e,i,n){return e===t&&(e=e.slice()),e.splice(n,1),e}function r(t,i,a){t.traversePreOrderUsingStack((function(t){let o=function(t,e,i){let n=e;for(let r=i-1;r>=0;r--){const i=e[r];let a=i;for(let r=i.length-1;r>=0;r--){const o=i[r],l=t.computePlaneSide(o);if(l<0)a=s(i,a);else if(l>0){n=s(e,n);break}}a!==i&&-1!==n.indexOf(i)&&(n===e&&(n=n.slice()),n[r]=a)}return n}(t,i,a);if(o!==i){let i=o.length;if(0!==i){let s=0;for(let t=0;t<i;t++)0===o[t].length&&s++;od(t)?e(t):s===i?function(t){t instanceof ld?e(t):t.traversePreOrderUsingStack(n)}(t):r(t,o,i)}}else{if(!od(t))return!0;e(t)}return!1}))}!function(e){let n=[];for(let e=0;e<i;e++){const i=t[e].planes;n.push(i)}r(e,n,i)}(this)}traverseRayLeafIntersections(t,e,i,n,s,r,a,o){this.traversePreOrderUsingStack((function(l){return!(!l.intersectRay(t,e,i,n,s,r)||od(l)&&(a.call(o,l),1))}))}computeBalanceFactor(){const t=new hd,e=[];return t.visitLeaf=t=>{const i=t.computeDepth();e.push(i)},dd(this,t),0===e.length?1:function(t){const e=Ju(t),i=t.length;let n=0;for(let s=0;s<i;s++){const i=t[s]-e;n+=i*i}const s=n/(i-1);return Math.sqrt(s)}(e)}insert(t,e,i,n,s,r,a){const o=new ld(a,t,e,i,n,s,r);return this.insertNode(o),o}insertNode(t){const e=this.__insertion_findSiblingFor(t);let i=e.parentNode;null===i?(i=e,null===e.left?e.setChildLeft(t):null===e.right?e.setChildRight(t):(i=new vd,i.setChildren(e.right,t),e.right=i,i.parentNode=e)):i.left===e&&null===i.right?i.setChildRight(t):i.right===e&&null===i.left?i.setChildLeft(t):i=function(t,e){const i=new vd,n=t.parentNode;if(t===n.left)n.left=i;else{if(t!==n.right)throw new Error("Not a child of specified parent node(impostor)");n.right=i}return i.setChildren(t,e),i.parentNode=n,i}(e,t);do{const t=i.left,e=i.right;i.height=1+Eu(null!==t?t.height:0,null!==e?e.height:0),i.refit(),i=i.parentNode}while(null!==i)}clone(t=!1){const e=new vd;return e.x0=this.x0,e.y0=this.y0,e.z0=this.z0,e.x1=this.x1,e.y1=this.y1,e.z1=this.z1,e.leafNodeCount=this.leafNodeCount,e.parentNode=this.parentNode,!0===t?(null!==this.left&&(e.left=this.left.clone(!0),e.left.parentNode=e),null!==this.right&&(e.right=this.right.clone(!0),e.right.parentNode=e)):(e.left=this.left,e.right=this.right),e.modifiers=this.modifiers,e}}function xd(t){this(t,!0)}vd.prototype.isBinaryNode=!0;class wd{constructor(t=0,e=0){this.x=t,this.y=e,this.onChanged=new l}readFromArray(t,e=0){this.set(t[e],t[e+1])}writeToArray(t,e=0){t[e]=this.x,t[e+1]=this.y}asArray(){const t=[];return this.writeToArray(t,0),t}set(t,e){const i=this.x,n=this.y;return i===t&&n===e||(this.x=t,this.y=e,this.onChanged.hasHandlers()&&this.onChanged.send4(t,e,i,n)),this}setSilent(t,e){this.x=t,this.y=e}setX(t){return this.set(t,this.y)}setY(t){return this.set(this.x,t)}_sub(t,e){return this.set(this.x-t,this.y-e)}sub(t){return this._sub(t.x,t.y)}subVectors(t,e){this.set(t.x-e.x,t.y-e.y)}floor(){return this.set(Math.floor(this.x),Math.floor(this.y))}ceil(){return this.set(Math.ceil(this.x),Math.ceil(this.y))}round(){const t=Math.round(this.x),e=Math.round(this.y);this.set(t,e)}abs(){return this.set(Math.abs(this.x),Math.abs(this.y))}_mod(t,e){return this.set(this.x%t,this.y%e)}mod(t){return this._mod(t.x,t.y)}divide(t){return this.set(this.x/t.x,this.y/t.y)}multiply(t){return this._multiply(t.x,t.y)}_multiply(t,e){return this.set(this.x*t,this.y*e)}max(t){const e=Eu(this.x,t.x),i=Eu(this.y,t.y);return this.set(e,i)}dot(t){return bd(this.x,this.y,t.x,t.y)}copy(t){return this.set(t.x,t.y)}clone(){return new wd(this.x,this.y)}negate(){return this.set(-this.x,-this.y)}_add(t,e){return this.set(this.x+t,this.y+e)}add(t){return this._add(t.x,t.y)}addScalar(t){return this._add(t,t)}setScalar(t){this.set(t,t)}divideScalar(t){this.multiplyScalar(1/t)}multiplyScalar(t){return this.set(this.x*t,this.y*t)}toJSON(){return{x:this.x,y:this.y}}fromJSON(t){if("number"==typeof t)this.set(t,t);else{const{x:e=0,y:i=0}=t;this.set(e,i)}}toBinaryBuffer(t){t.writeFloat64(this.x),t.writeFloat64(this.y)}fromBinaryBuffer(t){const e=t.readFloat64(),i=t.readFloat64();this.set(e,i)}toBinaryBufferFloat32(t){t.writeFloat32(this.x),t.writeFloat32(this.y)}fromBinaryBufferFloat32(t){const e=t.readFloat32(),i=t.readFloat32();this.set(e,i)}isZero(){return 0===this.x&&0===this.y}clamp(t,e,i,n){const s=y(this.x,t,i),r=y(this.y,e,n);return this.set(s,r)}clampLow(t,e){const i=Eu(this.x,t),n=Eu(this.y,e);return this.set(i,n)}clampHigh(t,e){const i=ru(this.x,t),n=ru(this.y,e);return this.set(i,n)}distanceSqrTo(t){return this._distanceSqrTo(t.x,t.y)}lerpVectors(t,e,i){!function(t,e,i,n){const s=p(e.x,i.x,n),r=p(e.y,i.y,n);t.set(s,r)}(this,t,e,i)}applyMatrix3(t){const e=this.x,i=this.y,n=t[0]*e+t[3]*i+t[6],s=t[1]*e+t[4]*i+t[7];this.set(n,s)}distanceTo(t){return this._distanceTo(t.x,t.y)}_distanceSqrTo(t,e){return Sd(this.x-t,this.y-e)}_distanceTo(t,e){return Math.sqrt(this._distanceSqrTo(t,e))}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}length(){return Md(this.x,this.y)}normalize(){const t=this.length();if(0===t)return;const e=1/t;this.multiplyScalar(e)}hashCode(){const t=1367130550*Math.sin(this.x);let e=(t<<5)-t+1367130550*Math.sin(this.y);return e|=0,e}rotate(t){const e=Math.sin(t),i=Math.cos(t),n=this.x*i-this.y*e,s=this.x*e-this.y*i;this.set(n,s)}process(t,e){return t.call(e,this.x,this.y),this.onChanged.add(t,e),this}toString(){return`Vector2{x:${this.x}, y:${this.y}}`}equals(t){return this.x===t.x&&this.y===t.y}get 0(){return this.x}get 1(){return this.y}set 0(t){this.x=t}set 1(t){this.y=t}*[Symbol.iterator](){yield this.x,yield this.y}}function bd(t,e,i,n){return t*i+e*n}function Sd(t,e){return t*t+e*e}function Md(t,e){return Math.sqrt(Sd(t,e))}function Td(t,e,i,n){return Md(i-t,n-e)}function Cd(...t){return function(t,e,i){const n=0+i;let s=i;for(let e=0;e<n;e++)s=(s<<5)-s+t[e],s|=0;return s}(t,0,t.length)}function Ad(t,e,i,n,s,r,a,o){return t*s+e*r+i*a+n*o}function Ed(t,e,i,n){return t*t+e*e+i*i+n*n}wd.up=Object.freeze(new wd(0,1)),wd.down=Object.freeze(new wd(0,-1)),wd.left=Object.freeze(new wd(-1,0)),wd.right=Object.freeze(new wd(1,0)),wd.zero=Object.freeze(new wd(0,0)),wd.one=Object.freeze(new wd(1,1)),wd.prototype.isVector2=!0,wd._distance=Td;class zd{constructor(t=0,e=0,i=0,n=0){this.x=t,this.y=e,this.z=i,this.w=n,this.onChanged=new l}get 0(){return this.x}get 1(){return this.y}get 2(){return this.z}get 3(){return this.w}readFromArray(t,e=0){this.set(t[e],t[e+1],t[e+2],t[e+3])}writeToArray(t,e=0){t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w}set(t,e,i,n){const s=this.x,r=this.y,a=this.z,o=this.w;return s===t&&r===e&&a===i&&o===n||(this.x=t,this.y=e,this.z=i,this.w=n,this.onChanged.hasHandlers()&&this.onChanged.dispatch(t,e,i,n,s,r,a,o)),this}multiplyVector3(t){const e=this.x*t.x,i=this.y*t.y,n=this.z*t.z;this.set(e,i,n,this.w)}multiplyScalar(t){return this.set(this.x*t,this.y*t,this.z*t,this.w*t)}_applyMatrix4(t,e,i,n,s,r,a,o,l,h,c,u,d,p,f,m){const _=this.x,g=this.y,y=this.z,v=this.w,x=t*_+s*g+l*y+d*v,w=e*_+r*g+h*y+p*v,b=i*_+a*g+c*y+f*v,S=n*_+o*g+u*y+m*v;return this.set(x,w,b,S)}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w}add3(t){return this.set(this.x+t.x,this.y+t.y,this.z+t.z,this.w)}threeApplyMatrix4(t){const e=t.elements;return this._applyMatrix4(e[0],e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8],e[9],e[10],e[11],e[12],e[13],e[14],e[15])}copy(t){return this.set(t.x,t.y,t.z,t.w)}clone(){const t=new zd;return t.copy(this),t}applyQuaternion(t){const e=this.x,i=this.y,n=this.z,s=this.w,r=t.x,a=t.y,o=t.z,l=t.w,h=l*e+a*n-o*i,c=l*i+o*e-r*n,u=l*n+r*i-a*e,d=-r*e-a*i-o*n,p=h*l+d*-r+c*-o-u*-a,f=c*l+d*-a+u*-r-h*-o,m=u*l+d*-o+h*-a-c*-r;this.set(p,f,m,s)}equals(t){return this.x===t.x&&this.y===t.y&&this.z===t.z&&this.w===t.w}hash(){return Cd(x(this.x),x(this.y),x(this.z),x(this.w))}lerpVectors(t,e,i){zd.lerp(t,e,i,this)}toArray(t){t[0]=this.x,t[1]=this.y,t[2]=this.z,t[3]=this.w}asArray(){const t=[];return this.toArray(t),t}setFromArray(t,e){this.set(t[e],t[e+1],t[e+2],t[e+3])}toJSON(){return{x:this.x,y:this.y,z:this.z,w:this.w}}fromJSON(t){this.copy(t)}toBinaryBuffer(t){t.writeFloat64(this.x),t.writeFloat64(this.y),t.writeFloat64(this.z),t.writeFloat64(this.w)}fromBinaryBuffer(t){const e=t.readFloat64(),i=t.readFloat64(),n=t.readFloat64(),s=t.readFloat64();this.set(e,i,n,s)}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}static lerp(t,e,i,n){const s=p(t.x,e.x,i),r=p(t.y,e.y,i),a=p(t.z,e.z,i),o=p(t.w,e.w,i);n.set(s,r,a,o)}}class Id extends Number{constructor(t=0){super(),this.x=t,this.onChanged=new l}valueOf(){return this.x}toString(){return String(this.x)}getValue(){return this.x}compareTo(t){return this.x-t.x}set(t){const e=this.x;return e!==t&&(this.x=t,this.onChanged.hasHandlers()&&this.onChanged.send2(t,e)),this}setSilent(t){this.x=t}isZero(){return 0===this.x}increment(){this._add(1)}decrement(){this._add(-1)}_add(t){return this.set(this.x+t)}add(t){return this._add(t.x)}_sub(t){return this._add(-t)}sub(t){return this._sub(t.x)}multiply(t){return this.set(this.x*t.x)}multiplyScalar(t){this.set(this.x*t)}clamp(t,e){return this.set(y(this.x,t,e))}copy(t){this.set(t.x)}clone(){return new Id(this.x)}equals(t){return this.x===t.x}hash(){return x(this.x)}process(t){t(this.x,this.x),this.onChanged.add(t)}toJSON(){return this.x}fromJSON(t){this.set(t)}readFromArray(t,e=0){this.set(t[e])}writeToArray(t,e=0){t[e]=this.x}asArray(){return[this.x]}toBinaryBuffer(t){t.writeFloat64(this.x)}fromBinaryBuffer(t){const e=t.readFloat64();this.set(e)}static compare(t,e){return t.x-e.x}get 0(){return this.x}set 0(t){this.x=t}*[Symbol.iterator](){yield this.x}}function Nd(t){if(null===t)return 0;if(void 0===t)return 1;const e=t.length;let i=0;for(let n=0;n<e;n++)i=31*i+t.charCodeAt(n)|0;return i}Id.prototype.isVector1=!0,Id.typeName="Vector1",Id.zero=Object.freeze(new Id(0)),Id.one=Object.freeze(new Id(1));class Ld extends String{constructor(t){super(),this.__value=t,this.onChanged=new l,this.isObservedString=!0}valueOf(){return this.__value}toString(){return this.__value}set(t){const e=this.__value;return e!==t&&(this.__value=t,this.onChanged.send2(t,e)),this}copy(t){this.set(t.getValue())}equals(t){return this.__value===t.__value}getValue(){return this.__value}process(t){t(this.getValue()),this.onChanged.add(t)}toJSON(){return this.__value}fromJSON(t){this.set(t)}toBinaryBuffer(t){t.writeUTF8String(this.__value)}fromBinaryBuffer(t){const e=t.readUTF8String();this.set(e)}hash(){return Nd(this.__value)}}function Pd(t,e){const i=e.width,n=e.height,s=t.width/i,r=t.height/n,a=Eu(1,Math.ceil(s)),o=Eu(1,Math.ceil(r)),l=a*o,h=t.itemSize,c=new Float32Array(h);let u,d,p,f,m;for(u=0;u<n;u++)for(d=0;d<i;d++){const n=d*s,_=u*r;for(m=0;m<h;m++)c[m]=0;for(p=0;p<o;p++)for(f=0;f<a;f++)for(m=0;m<h;m++)c[m]+=t.sampleChannelBilinear(n+f,_+p,m);for(m=0;m<h;m++){const t=c[m]/l;e.data[(u*i+d)*h+m]=t}}}function Fd(t,e){e.itemSize;const i=e.width,n=e.height,s=t.width,r=t.height;s===i&&r===n?e.data.set(t.data):s>i&&r>n?Number.isInteger(s/i)&&Number.isInteger(r/n)?function(t,e){const i=t.width,n=t.height,s=e.width,r=e.height,a=i/s,o=n/r,l=t.itemSize,h=new Array(l),c=1/(a*o),u=t.data,d=e.data;let p,f,m,_,g;for(g=0;g<r;g++){const t=g*o,e=g*s*l;for(_=0;_<s;_++){const n=e+_*l;for(p=0;p<l;p++)h[p]=0;const s=_*a;for(f=0;f<o;f++){const e=(t+f)*i+s;for(p=0;p<a;p++){const t=(e+p)*l;for(m=0;m<l;m++)h[m]+=u[m+t]}}for(p=0;p<l;p++)d[n+p]=h[p]*c}}}(t,e):Pd(t,e):s<i&&r<n?function(t,e){const i=e.itemSize,n=e.width,s=e.height,r=t.width,a=t.height,o=e.data;if(r===n&&a===s)return void o.set(t.data);const l=i*n,h=r/n,c=a/s;for(let e=0;e<s;e++){const s=e*c,r=e*l;for(let e=0;e<n;e++){const n=r+e*i;t.sampleBilinear(e*h,s,o,n)}}}(t,e):Pd(t,e)}function Dd(t){return t/255}function Od(t){return Math.round(255*t)}function Rd(t,e,i,n,s){let r,a,o;for(o=0;o<s;o++)r=e+o,a=n+o,i[a]=t[r]}const kd="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdj+P///38ACfsD/QVDRcoAAAAASUVORK5CYII=",Ud=[0,0,0,0];class Bd{constructor(t){this.borderWidth=new Id(.1),this.size=new wd(t.x,t.y),this.tileImage=new Ld(kd),this.sampler=Vu.uint8(4,t.x,t.y);const e=this.texture=new wl(this.sampler.data);e.wrapS=Ct,e.wrapT=Ct,e.magFilter=Et,e.minFilter=Et,e.anisotropy=0,e.flipY=!1,e.repeat.set(1,1),e.needsUpdate=!0,e.generateMipmaps=!1,this.stack=[],this.size.onChanged.add(((t,e)=>{this.sampler.resize(t,e),this.texture.dispose(),this.texture.image.data=this.sampler.data,this.texture.image.width=t,this.texture.image.height=e}))}get baseTileImage(){return 0===this.stack.length?this.tileImage.getValue():this.stack[0].tileImage}set baseTileImage(t){0===this.stack.length?this.tileImage.set(t):this.stack[0].tileImage=t}get canvas(){throw new Error("Deprecated, used .sampler instead")}push(){const t=this.sampler.clone(),e=new class{constructor(t,e,i){this.sampler=t,this.borderWidth=e,this.tileImage=i}}(t,this.borderWidth.getValue(),this.tileImage.getValue());this.stack.push(e),this.clear()}pop(){if(0===this.stack.length)return;const t=this.stack.pop(),e=t.sampler;this.size.set(e.width,e.height),this.sampler.copy(e,0,0,0,0,e.width,e.height),this.borderWidth.set(t.borderWidth),this.tileImage.set(t.tileImage),this.update()}clear(){const t=this.size;this.sampler.zeroFill(0,0,t.x,t.y),this.update()}update(){this.texture.needsUpdate=!0}readPoint(t,e,i){for(let n=0;n<4;n++){const s=this.sampler.readChannel(t,e,n);i[n]=Dd(s)}}paintPointAlphaBlend(t,e,i){const n=new zd;this.readPoint(t,e,n);const s=1-i.w;n.set(i.x*i.w+n.x*s,i.y*i.w+n.y*s,i.z*i.w+n.z*s,i.w+n.w*s),this.clearPoint(t,e),this.paintPoint(t,e,n)}clearPoint(t,e){this.sampler.set(t,e,Ud)}paintPoint(t,e,i){for(let n=0;n<4;n++)this.sampler.writeChannel(t,e,n,Od(i[n]));this.texture.needsUpdate=!0}writeData(t){const e=this.size;0!==e.x&&0!==e.y&&(i(this.sampler.data)?this.sampler.data.set(t):Rd(t,0,this.sampler.data,0,t.length),this.sampler.version++,this.texture.needsUpdate=!0)}paintImage(t,e,i,n,s){const r=function(t){const e=t.width,i=t.height,n=t.getContext("2d"),s=new Vu(null,4,e,i);return function(t,e){const i=t.width,n=t.height,s=e.getImageData(0,0,i,n).data;t.data=s}(s,n),s}(t);this.paintSampler(r,e,i,n,s)}paintSampler(t,e,i,n,s){const r=Vu.uint8(4,n,s);Fd(t,r),this.sampler.paint(r,0,0,e,i,n,s),this.texture.needsUpdate=!0}}const Vd=new Map;function Gd(t){const e=Vd.get(t);if(void 0!==e)return e;const i=(new fc).load(t);return i.wrapS=Tt,i.wrapT=Tt,i.repeat.set(1,1),Vd.set(t,i),i}class Wd{constructor(){this.__enabled=!1,this.materials=[],this.time=0,this.__speed0=new wd,this.__speed1=new wd,this.__speed2=new wd,this.variability=.37,this.setSpeed(.5,-.5)}set enabled(t){t!==this.__enabled&&(this.__enabled=t,this.materials.forEach(this.writeOneEnabled.bind(this)))}get enabled(){return this.__enabled}setSpeed(t,e){const i=this.variability;this.__speed0.set(t,e),this.__speed1.set(t*(1-i),e*(1+i)),this.__speed2.set(t*(1+i),e*(1-i))}writeOneCloudSpeed(t){const e=t.uniforms;e.v_CloudsSpeed_0.value.copy(this.__speed0),e.v_CloudsSpeed_1.value.copy(this.__speed1),e.v_CloudsSpeed_2.value.copy(this.__speed2)}writeOneEnabled(t){t.defines.SHADOWMAP_CLOUDS=this.__enabled,t.needsUpdate=!0}writeOneTime(t){t.uniforms.f_CloudsTime.value=this.time}writeAllTime(){const t=this.materials,e=t.length;for(let i=0;i<e;i++){const e=t[i];this.writeOneTime(e)}}update(t){this.time+=t,this.writeAllTime()}writeOneCloudTextures(t){const e=t.uniforms;e.t_Clouds_0.value=Gd("data/textures/noise/tile_256.png"),e.t_Clouds_1.value=Gd("data/textures/noise/tile_256.png"),e.t_Clouds_2.value=Gd("data/textures/noise/tile_256.png")}writeOneCloudUniforms(t){const e=t.uniforms;e.v_CloudsSize_0.value.set(161,161),e.v_CloudsSize_1.value.set(83,83),e.v_CloudsSize_2.value.set(23,23),e.f_CloudsAmount.value=.8,e.f_CloudsIntensity.value=.2,this.writeOneCloudSpeed(t)}removeMaterial(t){const e=this.materials.indexOf(t);return-1!==e&&(this.materials.splice(e,1),!0)}addMaterial(t){"object"==typeof t.defines&&t.defines.hasOwnProperty("SHADOWMAP_CLOUDS")&&(this.writeOneTime(t),this.writeOneEnabled(t),this.writeOneCloudTextures(t),this.writeOneCloudUniforms(t),this.materials.push(t))}}function Hd(t){this.onChanged=new l,this.__value=t}Hd.prototype.set=function(t){if(this.__value!==t){const e=this.__value;this.__value=t,this.onChanged.send2(t,e)}},Hd.prototype.setSilent=function(t){this.__value=t},Hd.prototype.get=function(){return this.__value},Hd.prototype.getValue=Hd.prototype.get,Hd.prototype.copy=function(t){this.set(t.__value)},Hd.prototype.equals=function(t){return"object"==typeof t&&this.__value===t.__value},Hd.prototype.clone=function(){return new Hd(this.__value)},Hd.prototype.process=function(t){return t(this.__value),this.onChanged.add(t),this},Hd.prototype.toString=function(){return JSON.stringify({value:this.__value})},Hd.prototype.toJSON=function(){return this.get()},Hd.prototype.fromJSON=function(t){this.set(t)};var jd=function(t,e){const i=new Rs(t,e);return(n=i).matrixAutoUpdate=!1,n.frustumCulled=!1,i;var n};class qd{visit(t,e){}}function Jd(){}function Yd(){return!0}function Xd(){return 0}function Zd(){return 1}function $d(t){return t}function Kd(t,e){return t===e}function Qd(t,e){return t-e}const tp=new Float32Array(6);class ep{constructor(){this.leafNodeCount=0,this.binaryNodeCount=0,this.boxCount=0,this.data=new Float32Array(16)}estimateByteSize(){return this.data.buffer.byteLength+248}initialize(t){const e=Math.log(t)/Math.log(2),i=Math.pow(2,Math.ceil(e))-1;this.leafNodeCount=t,this.binaryNodeCount=i,this.boxCount=this.leafNodeCount+this.binaryNodeCount;const n=6*this.boxCount;this.data.length<n?this.data=new Float32Array(n):this.data.fill(0)}unsortedBuiltIntermediate(){const t=this.data,e=this.binaryNodeCount,i=6*this.binaryNodeCount;let n,s,r,a,o,l,h=Math.floor(Math.log(e)/Math.log(2));for(r=Math.pow(2,h),s=6*(r-1),n=0;n<r;n++){const e=2*n,r=e+1,a=i+6*e,o=i+6*r;r<this.leafNodeCount?sp(t,s,a,o):e<this.leafNodeCount?Rd(c=t,a,c,s,6):np(s-6,s,t),s+=6}var c;for(h--;h>=0;h--)for(r=Math.pow(2,h),a=r-1,n=0;n<r;n++)o=1+(a<<1),l=o+1,sp(t,6*a,6*o,6*l),a++;Rd(t,0,tp,0,6),this.x0=tp[0],this.y0=tp[1],this.z0=tp[2],this.x1=tp[3],this.y1=tp[4],this.z1=tp[5]}writeLeaf(t,e,i,n,s,r,a){const o=6*this.binaryNodeCount+6*t;ip(this.data,o,e,i,n,s,r,a)}setLeafs(t){let e=6*this.binaryNodeCount;const i=this.data;let n=0;const s=this.leafNodeCount;for(;n<s;n++)t(n,e,i,ip),e+=6;this.unsortedBuiltIntermediate()}traversePreOrderStack(t,e){const i=ap;rp[ap++]=e;const n=6*this.binaryNodeCount,s=6*this.boxCount;for(;ap-- >i;){const e=rp[ap],i=6*e;if(t.visit(i,1)){const i=1+(e<<1),r=i+1,a=6*i,o=6*r;o<s&&(o<n?rp[ap++]=r:t.visit(o,0)),a<s&&(a<n?rp[ap++]=i:t.visit(a,0))}}ap=i}traversePreOrder(t,e,i){const n=t(6*e,i),s=6*this.binaryNodeCount,r=6*this.boxCount;if(!1!==n){const i=1+(e<<1),n=i+1,a=6*i,o=6*n;a<r&&(a<s?this.traversePreOrder(t,i,1):t(a,0)),o<r&&(o<s?this.traversePreOrder(t,n,1):t(o,0))}}traverseRayLeafIntersections(t,e,i,n,s,r,a,o){op.originX=t,op.originY=e,op.originZ=i,op.directionX=n,op.directionY=s,op.directionZ=r,op.root=this,op.callback=a,op.callbackThisArg=o,this.traversePreOrderStack(op,0)}}function ip(t,e,i,n,s,r,a,o){t[e]=i,t[e+1]=n,t[e+2]=s,t[e+3]=r,t[e+4]=a,t[e+5]=o}function np(t,e,i){Rd(i,t,tp,0,3),tp[3]=tp[0],tp[4]=tp[1],tp[5]=tp[2],Rd(tp,0,i,e,6)}function sp(t,e,i,n){!function(t,e,i,n,s){const r=t[e],a=t[e+1],o=t[e+2],l=t[e+3],h=t[e+4],c=t[e+5],u=t[i],d=t[i+1],p=t[i+2],f=t[i+3],m=t[i+4],_=t[i+5],g=ru(r,u),y=ru(a,d),v=ru(o,p),x=Eu(l,f),w=Eu(h,m),b=Eu(c,_);n[s]=g,n[s+1]=y,n[s+2]=v,n[s+3]=x,n[s+4]=w,n[s+5]=b}(t,i,n,t,e)}const rp=[];let ap=0;const op=new class extends qd{constructor(){super(),this.callback=Jd,this.callbackThisArg=null,this.originX=0,this.originY=0,this.originZ=0,this.directionX=0,this.directionY=0,this.directionZ=0,this.root=null}visit(t,e){const i=this.root,n=i.data,s=i.binaryNodeCount;if(!id(n[t],n[t+1],n[t+2],n[t+3],n[t+4],n[t+5],this.originX,this.originY,this.originZ,this.directionX,this.directionY,this.directionZ))return!1;if(0===e){const i=t/6-s;return this.callback.call(this.callbackThisArg,i,t,e),!1}return!0}};class lp{constructor(){this.normal=new S(0,1,0),this.position=new S(0,0,0),this.index=-1}applyMatrix4(t){const e=this.position,i=e.x,n=e.y,s=e.z,r=1/(t[3]*i+t[7]*n+t[11]*s+t[15]),a=(t[0]*i+t[4]*n+t[8]*s+t[12])*r,o=(t[1]*i+t[5]*n+t[9]*s+t[13])*r,l=(t[2]*i+t[6]*n+t[10]*s+t[14])*r;e.set(a,o,l);const h=this.normal,c=h.x,u=h.y,d=h.z,p=t[0]*c+t[4]*u+t[8]*d,f=t[1]*c+t[5]*u+t[9]*d,m=t[2]*c+t[6]*u+t[10]*d,_=1/g(p,f,m);h.set(p*_,f*_,m*_)}applyMatrix4_three(t){this.applyMatrix4(t.elements)}copy(t){this.position.copy(t.position),this.normal.copy(t.normal),this.index=t.index}clone(){const t=new lp;return t.copy(this),t}}function hp(t,e,i,n,s,r,a,o,l,h,c,u,d,p,f,_){const g=c-o,y=u-l,v=d-h,x=p-o,w=f-l,b=_-h,S=y*b-v*w,M=v*x-g*b,T=g*w-y*x;let C=m(s,r,a,S,M,T),A=1;if(0===C)return!1;C<0&&(A=-1,C=-C);const E=e-o,z=i-l,I=n-h,N=A*m(s,r,a,z*b-I*w,I*x-E*b,E*w-z*x);if(N<0)return!1;const L=A*m(s,r,a,y*I-v*z,v*E-g*I,g*z-y*E);if(L<0)return!1;if(N+L>C)return!1;const P=-A*m(E,z,I,S,M,T);if(P<0)return!1;const F=P/C;return t.normal.set(S,M,T),t.position.set(s*F+e,r*F+i,a*F+n),!0}const cp=new lp;function up(t,e,i){const n=e[0],s=e[1],r=e[2],a=e[3],o=e[4],l=e[5],h=i[3]*n+i[7]*s+i[11]*r+i[15];if(0===h)return!1;const c=1/h,u=(i[0]*n+i[4]*s+i[8]*r+i[12])*c,d=(i[1]*n+i[5]*s+i[9]*r+i[13])*c,p=(i[2]*n+i[6]*s+i[10]*r+i[14])*c,f=i[0]*a+i[4]*o+i[8]*l,m=i[1]*a+i[5]*o+i[9]*l,_=i[2]*a+i[6]*o+i[10]*l,g=Math.hypot(f,m,_);if(0===g)return!1;const y=1/g,v=f*y,x=m*y,w=_*y;return t[0]=u,t[1]=d,t[2]=p,t[3]=v,t[4]=x,t[5]=w,!0}function dp(t,e,i,n,s,r,a){t[0]=e,t[1]=i,t[2]=n,t[3]=s,t[4]=r,t[5]=a}const pp=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),fp=new Di,mp=new Di,_p=new Di,gp=new Di,yp=[],vp=[],xp=new S;function wp(t){return t.object}class bp{constructor(){this.geometry=null,this.bvh=null,this.position=null,this.scale=null,this.resolution=0,this.size=null,this.__bestDistance=0,this.__bestPosition=new S,this.__bestIndex=0,this.origin=new S,this.direction=new S,this.transform=new Float32Array(16),Rd(pp,0,this.transform,0,16),this.extractFaceIndexFromLeaf=wp}visitLeafIntersection(t){const e=this.geometry,i=e.getIndex().array,n=e.getAttribute("position").array,s=(0,this.extractFaceIndexFromLeaf)(t);if(function(t,e,i){const n=3*i,s=3*t[n],r=3*t[n+1],a=3*t[n+2];mp.set(e[s],e[s+1],e[s+2]),_p.set(e[r],e[r+1],e[r+2]),gp.set(e[a],e[a+1],e[a+2])}(i,n,s),function(t,e,i,n,s,r){const a=hp(cp,e.x,e.y,e.z,i.x,i.y,i.z,n.x,n.y,n.z,s.x,s.y,s.z,r.x,r.y,r.z);return t.copy(cp.position),a}(fp,this.origin,this.direction,mp,_p,gp)){const t=this.origin.distanceSqrTo(fp);t<this.__bestDistance&&(this.__bestDistance=t,this.__bestPosition.copy(fp),this.__bestIndex=s)}}raycast(t,e,i,n,s,r,a){vu(vp,this.transform),dp(yp,e,i,n,s,r,a),up(yp,yp,vp);const o=yp[0],l=yp[1],h=yp[2],c=yp[3],u=yp[4],d=yp[5];if(this.origin.set(o,l,h),this.direction.set(c,u,d),this.__bestDistance=Number.POSITIVE_INFINITY,this.bvh.traverseRayLeafIntersections(o,l,h,c,u,d,this.visitLeafIntersection,this),this.__bestDistance!==Number.POSITIVE_INFINITY){const e=this.geometry;return function(t,e,i){const n=3*i,s=3*t[n],r=3*t[n+1],a=3*t[n+2],o=e[s],l=e[s+1],h=e[s+2],c=e[r],u=e[r+1],d=e[r+2],p=o+c+e[a],f=l+u+e[a+1],m=h+d+e[a+2],_=1/g(p,f,m),y=p*_,v=f*_,x=m*_;xp.set(y,v,x)}(e.getIndex().array,e.getAttribute("normal").array,this.__bestIndex),t.position.copy(this.__bestPosition),t.normal.copy(xp),t.applyMatrix4(this.transform),!0}return!1}}class Sp extends Number{constructor(t){super(),this.__value=t,this.onChanged=new l}valueOf(){return this.getValue()}toString(){return this.getValue().toString()}set(t){const e=this.__value;return e!==t&&(this.__value=t,this.onChanged.send2(t,e)),this}setSilent(t){this.__value=t}isZero(){return 0===this.getValue()}subtract(t){this._add(-t.getValue())}_subtract(t){this.set(this.getValue()-t)}add(t){this._add(t.getValue())}_add(t){this.set(this.getValue()+t)}increment(){this.set(this.getValue()+1)}decrement(){this.set(this.getValue()-1)}getValue(){return this.__value}copy(t){this.set(t.__value)}equals(t){return this.__value===t.__value}hash(){return this.__value}toJSON(){return this.__value}fromJSON(t){this.set(t)}toBinaryBuffer(t){const e=this.__value;Infinity===e?t.writeInt32(2147483647):-Infinity===e?t.writeInt32(-2147483648):t.writeInt32(e)}fromBinaryBuffer(t){const e=t.readInt32();2147483647===e?this.set(Infinity):-2147483648===e?this.set(-Infinity):this.set(e)}}function Mp(t,e,i){const n=e-t;return 0===n?0:(i-t)/n}Sp.prototype.isObservedInteger=!0;class Tp{constructor(t=Number.NEGATIVE_INFINITY,e=Number.POSITIVE_INFINITY){this.min=t,this.max=e,this.onChanged=new l}set(t,e){const i=this.min,n=this.max;t===i&&e===n||(this.min=t,this.max=e,this.onChanged.hasHandlers()&&this.onChanged.send4(t,e,i,n))}copy(t){this.set(t.min,t.max)}multiplyScalar(t){const e=this.min*t,i=this.max*t;e>i?this.set(i,e):this.set(e,i)}normalizeValue(t){return Mp(this.min,this.max,t)}isZero(){return 0===this.min&&0===this.max}isExact(){return this.min===this.max}computeAverage(){return(this.min+this.max)/2}sampleRandom(t){return this.min+t()*(this.max-this.min)}fromJSON(t){this.set(t.min,t.max)}toJSON(){return{min:this.min,max:this.max}}toBinaryBuffer(t){t.writeFloat64(this.min),t.writeFloat64(this.max)}fromBinaryBuffer(t){this.min=t.readFloat64(),this.max=t.readFloat64()}equals(t){return this.min===t.min&&this.max===t.max}hash(){let t=x(this.min);return t=(t<<5)-t+x(this.max),t}get span(){return this.max-this.min}}Tp.prototype.isNumericInterval=!0,Tp.one_one=Object.freeze(new Tp(1,1)),Tp.zero_zero=Object.freeze(new Tp(0,0));class Cp{constructor(){this.gridPosition=new wd,this.scale=new wd(1,1),this.size=new wd,this.position=new wd,this.resolution=new Sp(1),this.material=null,this.mesh=jd(),this.mesh.name="TerrainTile",this.mesh.matrixWorldNeedsUpdate=!1,this.geometry=null,this.enableBVH=!0,this.boundingBox=new ld(this),this.bvh=null,this.isBuilt=!1,this.isBuildInProgress=!1,this.referenceCount=0,this.onBuilt=new l,this.onDestroyed=new l,this.stitching={top:!1,bottom:!1,left:!1,right:!1,topLeft:!1,topRight:!1,bottomLeft:!1,bottomRight:!1},this.__initial_height_range=new Tp(Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY),this.raycaster=new bp,this.raycaster.extractFaceIndexFromLeaf=$d}get transform(){return this.mesh.matrixWorld.elements}set transform(t){Rd(t,0,this.mesh.matrixWorld.elements,0,16),this.computeBoundingBox(),Rd(t,0,this.raycaster.transform,0,16)}raycast(t,e,i,n){const s=this.raycaster.raycast(Ap,t.x,t.y,t.z,e.x,e.y,e.z);return s?i(Ap.position,Ap.normal):n(),s}raycastFirstSync(t,e,i,n,s,r,a){return this.raycaster.raycast(t,e,i,n,s,r,a)}getVertexNormal(t,e){const i=this.geometry.attributes.normal.array,n=3*t;e.set(i[n],i[n+1],i[n+2])}setVertexNormal(t,e){const i=this.geometry.attributes.normal.array,n=3*t;i[n]=e.x,i[n+1]=e.y,i[n+2]=e.z}stitchNormals(t,e,i,n,s,r,a,o){const l=new S,h=new S,c=new S,u=new S,d=this;function p(t){return void 0!==t&&t.isBuilt}function f(t){t.geometry.attributes.normal.needsUpdate=!0}function m(t,e){if(p(t)&&p(e)){let i;const n=e.resolution.getValue(),s=t.resolution.getValue(),r=t.size.x*s*(t.size.y*s-1),a=e.size.x*n-1;if(t.stitching.bottom){for(i=1;i<a;i++)t.getVertexNormal(r+i,l),e.setVertexNormal(i,l);f(e),e.stitching.top=!0}else if(e.stitching.top){for(i=1;i<a;i++)e.getVertexNormal(i,l),t.setVertexNormal(r+i,l);f(t),t.stitching.bottom=!0}else{for(i=1;i<a;i++)e.getVertexNormal(i,l),t.getVertexNormal(r+i,h),l.add(h),l.normalize(),e.setVertexNormal(i,l),t.setVertexNormal(r+i,l);f(t),f(e),t.stitching.bottom=!0,e.stitching.top=!0}}}function _(t,e){if(p(t)&&p(e)){let i;const n=e.resolution.getValue(),s=t.resolution.getValue(),r=e.size.y*n-1,a=t.size.x*s-1,o=t.size.x*s,c=e.size.x*n;let u,d;if(t.stitching.right){for(i=0;i<r;i++)u=i*c,d=a+i*o,t.getVertexNormal(d,l),e.setVertexNormal(u,l);f(e),e.stitching.left=!0}else if(e.stitching.left){for(i=0;i<r;i++)u=i*c,d=a+i*o,e.getVertexNormal(u,l),t.setVertexNormal(d,l);f(t),t.stitching.right=!0}else{for(i=0;i<r;i++)u=i*c,d=a+i*o,e.getVertexNormal(u,l),t.getVertexNormal(d,h),l.add(h),l.normalize(),e.setVertexNormal(u,l),t.setVertexNormal(d,l);f(t),f(e),t.stitching.right=!0,e.stitching.left=!0}}}function g(t,e,i,n){if(p(t)&&p(e)&&p(i)&&p(n)){const s=t.size.x*t.resolution.getValue()*(t.size.y*t.resolution.getValue())-1,r=0,a=e.size.x*e.resolution.getValue()*(e.size.y*e.resolution.getValue()-1),o=i.size.x*i.resolution.getValue()-1;t.getVertexNormal(s,l),n.getVertexNormal(r,h),e.getVertexNormal(a,c),i.getVertexNormal(o,u),l.add(h),l.add(c),l.add(u),l.normalize(),t.setVertexNormal(s,l),n.setVertexNormal(r,l),e.setVertexNormal(a,l),i.setVertexNormal(o,l),f(t),f(e),f(i),f(n),t.stitching.bottomRight=!0,e.stitching.bottomLeft=!0,i.stitching.topRight=!0,n.stitching.topLeft=!0}}g(s,t,i,d),g(t,r,d,n),g(i,d,a,e),g(d,n,e,o),m(t,d),m(d,e),_(i,d),_(d,n)}computeBoundingBox(){let t;const e=this.geometry;if(null===e){const e=this.position,i=this.scale,n=this.size,s=this.__initial_height_range,r=new Di(e.x*i.x,s.min,e.y*i.y),a=new Di(r.x+n.x*i.x,s.max,r.z+n.y*i.y);t=new ki(r,a)}else{const i=this.bvh;if(null!==i){e.boundingBox=new ki(new Di(i.x0,i.y0,i.z0),new Di(i.x1,i.y1,i.z1));const t=i.x1-i.x0,n=i.y1-i.y0,s=i.z1-i.z0,r=Math.sqrt(t*t+n*n+s*s)/2,a=new Di(i.x0+t/2,i.y0+n/2,i.z0+s/2);e.boundingSphere=new sn(a,r)}t=e.boundingBox,null===t&&(e.computeBoundingBox(),t=e.boundingBox)}const i=t.min.x,n=t.min.y,s=t.min.z,r=t.max.x,a=t.max.y,o=t.max.z,l=new rd(i,n,s,r,a,o);l.applyMatrix4(this.transform),this.boundingBox.setBounds(l.x0,l.y0,l.z0,l.x1,l.y1,l.z1),this.boundingBox.bubbleRefit()}setInitialHeightBounds(t,e){this.__initial_height_range.set(t,e)}dispose(){null!==this.geometry&&(this.geometry.dispose(),this.geometry=null),this.isBuilt=!1}build(t){this.isBuilt=!0;const e=t.geometry,i=new vs;if(i.setIndex(new ls(e.indices,1)),i.setAttribute("position",new ls(e.vertices,3)),i.setAttribute("normal",new ls(e.normals,3)),i.setAttribute("uv",new ls(e.uvs,2)),this.geometry=i,this.enableBVH){const e=this.bvh=new ep;for(let i in t.bvh)t.bvh.hasOwnProperty(i)&&(e[i]=t.bvh[i])}const n=this.mesh;return n.geometry=i,n.receiveShadow=!0,n.castShadow=!0,this.computeBoundingBox(),this.raycaster.bvh=this.bvh,this.raycaster.geometry=i,this.raycaster.position=this.position,this.raycaster.scale=this.scale,this.raycaster.resolution=this.resolution.getValue(),this.raycaster.size=this.size,n}}const Ap=new lp;function Ep(t){return t<0?0:t>1?1:t}function zp(t){return parseInt(t,16)}const Ip=/rgb\(\s*([0-9]+),\s*([0-9]+),\s*([0-9]+)\s*\)/,Np=/rgba\(\s*([0-9]+),\s*([0-9]+),\s*([0-9]+),\s*([0-9]+(?:\.[0-9]*)?)\s*\)/,Lp=/hsv\(([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?)\)/;function Pp(t,e,i){let n=t;return n>e&&(n=e),n>i&&(n=i),n}function Fp(t){const e=Math.round(t).toString(16);return 1===e.length?"0"+e:e}function Dp(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}function Op(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}class Rp{constructor(t=0,e=0,i=0,n=1){this.r=t,this.g=e,this.b=i,this.a=n,this.onChanged=new l}get 0(){return this.r}set 0(t){this.r=t}get 1(){return this.g}set 1(t){this.g=t}get 2(){return this.b}set 2(t){this.b=t}get 3(){return this.a}set 3(t){this.a=t}setRGB(t,e,i){const n=this.r,s=this.g,r=this.b;this.r=t,this.g=e,this.b=i,this.onChanged.send6(t,e,i,n,s,r)}setHSL(t,e,i){let n=t%1;n<0&&(n+=Math.ceil(Math.abs(n)));const s=12*n%12,r=(8+12*n)%12,a=(4+12*n)%12,o=e*ru(i,1-i),l=i-o*Eu(-1,Pp(s-3,9-s,1)),h=i-o*Eu(-1,Pp(r-3,9-r,1)),c=i-o*Eu(-1,Pp(a-3,9-a,1));this.setRGB(l,h,c)}setHCL(t,e,i){let n=t%1;n<0&&(n+=Math.ceil(Math.abs(n)));const s=6*n,r=e*(1-Math.abs(s%2-1));let a,o,l;switch(Math.floor(s)){case 0:a=e,o=r,l=0;break;case 1:a=r,o=e,l=0;break;case 2:a=0,o=e,l=r;break;case 3:a=0,o=r,l=e;break;case 4:a=r,o=0,l=e;break;case 5:a=e,o=0,l=r}const h=i-(.3*a+.59*o+.11*l);this.setRGB(a+h,o+h,l+h)}setHSI(t,e,i){let n=t%1;n<0&&(n+=Math.ceil(Math.abs(n)));const s=6*n,r=1-Math.abs(s%2-1),a=3*i*e/(1+r),o=a*r;let l,h,c;switch(Math.floor(s)){case 0:l=a,h=o,c=0;break;case 1:l=o,h=a,c=0;break;case 2:l=0,h=a,c=o;break;case 3:l=0,h=o,c=a;break;case 4:l=o,h=0,c=a;break;case 5:l=a,h=0,c=o}const u=i*(1-e);this.setRGB(l+u,h+u,c+u)}setHSV(t,e,i){let n=t;n<0&&(n+=Math.ceil(Math.abs(n))),n%=1;const s=Ep(e),r=Ep(i);let a,o,l;const h=Math.floor(6*n),c=6*n-h,u=r*(1-s),d=r*(1-c*s),p=r*(1-(1-c)*s);switch(h%6){case 0:a=r,o=p,l=u;break;case 1:a=d,o=r,l=u;break;case 2:a=u,o=r,l=p;break;case 3:a=u,o=d,l=r;break;case 4:a=p,o=u,l=r;break;case 5:a=r,o=u,l=d}this.setRGB(a,o,l)}computeLuminance(){return.299*this.r+.587*this.g+.114*this.b}getHSV(){return function(t,e,i){t/=255,e/=255,i/=255;const n=Math.max(t,e,i),s=Math.min(t,e,i);var r,a,o=n,l=n-s;if(a=0===n?0:l/n,n===s)r=0;else{switch(n){case t:r=(e-i)/l+(e<i?6:0);break;case e:r=(i-t)/l+2;break;case i:r=(t-e)/l+4}r/=6}return{h:r,s:a,v:o}}(255*this.r,255*this.g,255*this.b)}toUint(){return function(t,e,i){const n=Od(t),s=Od(e);return 255&Od(i)|(255&s)<<8|(255&n)<<16}(this.r,this.g,this.b)}fromUint(t){const e=t>>16,i=t>>8&255,n=255&t;this.setRGB(e/255,i/255,n/255)}toHex(){return"#"+(t=Od(this.r),e=Od(this.g),i=Od(this.b),Fp(t)+Fp(e)+Fp(i));var t,e,i}toCssRGBAString(){return`rgba(${Od(this.r)},${Od(this.g)},${Od(this.b)},${this.a})`}equals(t){return this.r===t.r&&this.g===t.g&&this.b===t.b}copy(t){this.a=t.a,this.setRGB(t.r,t.g,t.b)}clone(){const t=new Rp;return t.copy(this),t}hash(){return Cd(x(this.r),x(this.g),x(this.b))}fromJSON({r:t,g:e,b:i}){this.setRGB(t,e,i)}toJSON(){return{r:this.r,g:this.g,b:this.b}}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b}writeToArray(t,e){t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b}toBinaryBuffer(t){t.writeFloat32(this.r),t.writeFloat32(this.g),t.writeFloat32(this.b)}fromBinaryBuffer(t){const e=t.readFloat32(),i=t.readFloat32(),n=t.readFloat32();this.setRGB(e,i,n)}parse(t){const e=function(t){const e=[],i=typeof t;let n,s,r,a=1;if("string"===i){const e=t.toLowerCase();let i;if(null!==(i=e.match(Ip)))n=parseInt(i[1]),s=parseInt(i[2]),r=parseInt(i[3]);else if(null!==(i=e.match(Np)))n=parseInt(i[1]),s=parseInt(i[2]),r=parseInt(i[3]),a=parseInt(i[4]);else if(null!==(i=e.match(Lp))){const t=function(t,e,i){let n=t%1;n<0&&(n=t+1);const s=Ep(e),r=Ep(i);let a,o,l,h,c,u,d,p;switch(h=Math.floor(6*t),c=6*n-h,u=r*(1-s),d=r*(1-c*s),p=r*(1-(1-c)*s),h%6){case 0:a=r,o=p,l=u;break;case 1:a=d,o=r,l=u;break;case 2:a=u,o=r,l=p;break;case 3:a=u,o=d,l=r;break;case 4:a=p,o=u,l=r;break;case 5:a=r,o=u,l=d}return{r:Od(a),g:Od(o),b:Od(l)}}(parseFloat(i[1]),parseFloat(i[2]),parseFloat(i[3]));n=t.r,s=t.g,r=t.b}else{if(!e.startsWith("#"))throw new Error(`Failed to decode color string '${t}' `);{const t={r:zp((o=e).slice(1,3)),g:zp(o.slice(3,5)),b:zp(o.slice(5))};n=t.r,s=t.g,r=t.b}}}else{if("number"!==i)throw new Error(`Failed to decode color '${t}'`);n=t>>16,s=t>>8&255,r=255&t}var o;return e[0]=n,e[1]=s,e[2]=r,e[3]=a,e}(t);"number"==typeof e[3]?this.a=e[3]:this.a=1,this.setRGB(e[0]/255,e[1]/255,e[2]/255)}lerpColors(t,e,i){this.r=p(t.r,e.r,i),this.g=p(t.g,e.g,i),this.b=p(t.b,e.b,i),this.a=p(t.a,e.a,i)}static fromRGB(t,e,i){return new Rp(t,e,i)}static fromHSV(t,e,i){const n=new Rp;return n.setHSV(t,e,i),n}static parse(t){const e=new Rp;return e.parse(t),e}static from_linear_to_sRGB(t,e){!function(t,e,i,n){t[0]=Dp(i[0]),t[1]=Dp(i[1]),t[2]=Dp(i[2])}(e,0,t)}static from_sRGB_to_linear(t,e){!function(t,e,i,n){t[0]=Op(i[0]),t[1]=Op(i[1]),t[2]=Op(i[2])}(e,0,t)}}function kp(){}function Up(t,e,i,n,s,r,a,o,l){const h=i-t,c=n-e,u=a-s,d=o-r,p=-u*c+h*d,f=(-c*(t-s)+h*(e-r))/p,m=(u*(e-r)-d*(t-s))/p;if(f>=0&&f<=1&&m>=0&&m<=1){const i=t+m*h,n=e+m*c;return l.set(i,n),!0}return!1}function Bp(t,e,i,n){return e>i&&n>t}Rp.red=Object.freeze(new Rp(1,0,0)),Rp.green=Object.freeze(new Rp(0,1,0)),Rp.blue=Object.freeze(new Rp(0,0,1)),Rp.yellow=Object.freeze(new Rp(1,1,0)),Rp.cyan=Object.freeze(new Rp(0,1,1)),Rp.magenta=Object.freeze(new Rp(1,0,1)),Rp.white=Object.freeze(new Rp(1,1,1)),Rp.black=Object.freeze(new Rp(0,0,0)),Rp.transparent=Object.freeze(new Rp(0,0,0,0)),kp.intersectionPoint=function(t,e,i,n,s){return Up(t.x,t.y,e.x,e.y,i.x,i.y,n.x,n.y,s)},kp.intersectionPointRaw=Up;class Vp{constructor(t=0,e=0,i=0,n=0){this.x0=t,this.y0=e,this.x1=i,this.y1=n}grow(t){this.set(this.x0-t,this.y0-t,this.x1+t,this.y1+t)}shrink(t){this.grow(-t)}applyMatrix3(t){const e=t[0],i=t[1],n=t[3],s=t[4],r=t[6],a=t[7],o=this.x0,l=this.y0,h=this.x1,c=this.y1,u=e*o+n*l+r,d=i*o+s*l+a,p=e*h+n*c+r,f=i*h+s*c+a;let m=ru(u,p),_=Eu(u,p),g=ru(d,f),y=Eu(d,f);this.set(m,g,_,y)}multiplyScalar(t){this.set(this.x0*t,this.y0*t,this.x1*t,this.y1*t)}computeOverlap(t,e){return function(t,e,i,n,s,r,a,o,l){const h=Eu(t,s),c=ru(i,a);if(h>=c)return!1;const u=Eu(e,r),d=ru(n,o);return!(u>=d||(l.set(h,u,c,d),0))}(this.x0,this.y0,this.x1,this.y1,t.x0,t.y0,t.x1,t.y1,e)}overlapExists(t){return Gp(this.x0,this.y0,this.x1,this.y1,t.x0,t.y0,t.x1,t.y1)}_expandToFit(t,e,i,n){this.x0=ru(this.x0,t),this.y0=ru(this.y0,e),this.x1=Eu(this.x1,i),this.y1=Eu(this.y1,n)}_expandToFitPoint(t,e){t<this.x0&&(this.x0=t),t>this.x1&&(this.x1=t),e<this.y0&&(this.y0=e),e>this.y1&&(this.y1=e)}midX(){return(this.x1+this.x0)/2}midY(){return(this.y1+this.y0)/2}lineIntersectionPoint(t,e,i){const n=this.x0,s=this.y0,r=this.x1,a=this.y1;return!!(kp.intersectionPointRaw(t.x,t.y,e.x,e.y,n,s,r,s,i)||kp.intersectionPointRaw(t.x,t.y,e.x,e.y,n,a,r,a,i)||kp.intersectionPointRaw(t.x,t.y,e.x,e.y,n,s,n,a,i)||kp.intersectionPointRaw(t.x,t.y,e.x,e.y,r,s,r,a,i))}computeNearestPointToPoint(t,e){let i,n;const s=this.x0,r=this.y0,a=this.x1,o=this.y1,l=t.x,h=t.y;i=y(l,s,a),n=y(h,r,o),e.set(i,n)}costForInclusion(t){return this._costForInclusion(t.x0,t.y0,t.x1,t.y1)}_costForInclusion(t,e,i,n){let s=0,r=0;const a=this.x0,o=this.y0,l=this.x1,h=this.y1;return a>t&&(s+=a-t),l<i&&(s+=i-l),o>e&&(r+=o-e),h<n&&(r+=n-h),s*(h-o)+r*(l-a)}computeArea(){const t=this.x0,e=this.y0;return(this.x1-t)*(this.y1-e)}computeSurfaceArea(){const t=this.x0,e=this.y0;return 2*(this.x1-t+(this.y1-e))}containsPoint(t,e){return t>=this.x0&&t<=this.x1&&e>=this.y0&&e<=this.y1}expandToFit(t){this._expandToFit(t.x0,t.y0,t.x1,t.y1)}getCenter(t){t.set((this.x0+this.x1)/2,(this.y0+this.y1)/2)}getWidth(){return this.x1-this.x0}getHeight(){return this.y1-this.y0}set(t,e,i,n){return this.x0=t,this.y0=e,this.x1=i,this.y1=n,this}setPosition(t,e){const i=this.getWidth(),n=this.getHeight();this.set(t,e,t+i,e+n)}move(t,e){this.set(this.x0+t,this.y0+e,this.x1+t,this.y1+e)}clone(){return new Vp(this.x0,this.y0,this.x1,this.y1)}copy(t){return this.set(t.x0,t.y0,t.x1,t.y1)}equals(t){return this.x0===t.x0&&this.y0===t.y0&&this.x1===t.x1&&this.y1===t.y1}clamp(t,e,i,n){this.x0=y(this.x0,t,i),this.y0=y(this.y0,e,n),this.x1=y(this.x1,t,i),this.y1=y(this.y1,e,n)}setBoundsUnordered(t,e,i,n){let s,r,a,o;t<i?(s=t,a=i):(s=i,a=t),e<n?(r=e,o=n):(r=n,o=e),this.set(s,r,a,o)}setNegativelyInfiniteBounds(){return this.set(Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY,Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY)}toString(){return`AABB2{x0:${this.x0}, y0:${this.y0}, x1:${this.x1}, y1:${this.y1}}`}toJSON(){return{x0:this.x0,y0:this.y0,x1:this.x1,y1:this.y1}}fromJSON(t){this.set(t.x0,t.y0,t.x1,t.y1)}}function Gp(t,e,i,n,s,r,a,o){return Bp(t,i,s,a)&&Bp(e,n,r,o)}Vp.computeLineBetweenTwoBoxes=function(t,e,i,n){const s=new wd(t.midX(),t.midY()),r=new wd(e.midX(),e.midY());return!!t.lineIntersectionPoint(s,r,i)&&!!e.lineIntersectionPoint(s,r,n)},Vp.zero=Object.freeze(new Vp(0,0,0,0)),Vp.unit=Object.freeze(new Vp(0,0,1,1));class Wp{constructor({material:t,buildWorker:e}){if(this.tiles=[],this.on={tileBuilt:new l,tileDestroyed:new l},this.tileSize=new wd(10,10),this.totalSize=new wd(1,1),void 0===t){const e=function(t){const e=(new fc).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wIZFDQQxd+nEAAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAH0lEQVQI12NkQAL///+Hs5kYcADSJRiRzWVkZKSFHQBYfwYMUOT4KAAAAABJRU5ErkJggg==");return e.magFilter=Et,void 0!==t&&(e.wrapS=Tt,e.wrapT=Tt,e.repeat.copy(t)),e}(this.totalSize.clone()._sub(1,1).multiplyScalar(.5));t=new Wh({map:e})}this.material=new Hd(t),this.resolution=new Sp(4),this.scale=new wd(1,1),this.buildWorker=e,this.bvh=new vd,this.heightRange=new Tp(0,0),this.debugTileMaterialRandom=!1,this.material.onChanged.add((()=>{this.traverse(this.assignTileMaterial,this)})),this.__transform=new Float32Array(16)}set transform(t){e(t,this.__transform)||(yu(this.__transform,t),this.traverse((e=>{e.transform=t})))}get transform(){return this.__transform}setHeightRange(t,e){this.heightRange.set(t,e);const i=this.tiles,n=i.length;for(let s=0;s<n;s++){const n=i[s];if(!n.isBuilt&&!n.isBuildInProgress){const i=n.boundingBox;i.resize(i.x0,t,i.z0,i.x1,e,i.z1)}}}initialize(){this.destroyTiles(),this.bvh.setNegativelyInfiniteBounds(),this.initializeTiles()}assignTileMaterial(t){let e=this.material.getValue();if(this.debugTileMaterialRandom){const t=new Rp;t.setHSV(Math.random(),.6*(0,Math.random)()+.4,1),e=new Wh({color:t.toUint()})}t.material=e,null!==t.mesh&&(t.mesh.material=e)}traverse(t,e){const i=this.tiles;let n,s=0;const r=i.length;for(;s<r;s++)n=i[s],t.call(e,n)}destroyTiles(){this.tiles.forEach(this.release,this),this.tiles.splice(0,this.tiles.length),this.bvh.right=null,this.bvh.left=null}rebuild(){this.destroyTiles(),this.initializeTiles()}rebuildTilesByUV(t,e,i,n){const s=t*this.totalSize.x,r=i*this.totalSize.x,a=e*this.totalSize.y,o=n*this.totalSize.y;this.getRawTilesOverlappingRectangle(s-1,a-1,r+1,o+1).forEach((t=>{t.isBuilt=!1}))}getRawTilesOverlappingRectangle(t,e,i,n){const s=[],r=this.tiles,a=r.length;for(let o=0;o<a;o++){const a=r[o],l=a.position.x,h=a.position.y;Gp(t,e,i,n,l,h,l+a.size.x,h+a.size.y)&&s.push(a)}return s}initializeTiles(){const t=this.totalSize.clone().divide(this.tileSize).ceil(),e=t.x*t.y,i=this.tiles,n=this;function s(t,e){return function(i){n.obtain(t,e).then(i)}}for(let e=0;e<t.y;e++){const n=e<t.y-1?this.tileSize.y:this.totalSize.y-this.tileSize.y*e;for(let r=0;r<t.x;r++){const a=r<t.x-1?this.tileSize.x:this.totalSize.x-this.tileSize.x*r,o=new Cp;i[e*t.x+r]=o,this.assignTileMaterial(o),o.gridPosition.set(r,e),o.size.set(a,n),o.position.set(this.tileSize.x*r,this.tileSize.y*e),o.scale.copy(this.scale),o.resolution.copy(this.resolution),o.setInitialHeightBounds(this.heightRange.min,this.heightRange.max),o.computeBoundingBox(),o.ensureBuilt=s(r,e)}}this.bvh.insertManyBoxes2((function(t){return i[t].boundingBox}),e)}computeTileIndex(t,e){return e*Math.ceil(this.totalSize.x/this.tileSize.x)+t}getRaw(t,e){if(t<0||t>=Math.ceil(this.totalSize.x/this.tileSize.x)||e<0)return;const i=this.computeTileIndex(t,e);return this.tiles[i]}getRawTileByPosition(t,e){const i=Math.floor(t/this.tileSize.x),n=Math.floor(e/this.tileSize.y);return this.getRaw(i,n)}getTileByWorldPosition2D(t,e){const i=function(t,e,i){var n=new _u(3);return n[0]=t,n[1]=0,n[2]=i,n}(t,0,e),n=gu();return vu(n,this.transform),function(t,e,i){var n=e[0],s=e[1],r=e[2],a=i[3]*n+i[7]*s+i[11]*r+i[15];a=a||1,t[0]=(i[0]*n+i[4]*s+i[8]*r+i[12])/a,t[1]=(i[1]*n+i[5]*s+i[9]*r+i[13])/a,t[2]=(i[2]*n+i[6]*s+i[10]*r+i[14])/a}(i,i,n),this.getRawTileByPosition(i.x,i.z)}obtainTileAtWorldPosition2D(t,e){const i=this.getTileByWorldPosition2D(t,e);return this.obtain(i.gridPosition.x,i.gridPosition.y)}processTile(t,e,i){const n=this.getRaw(t,e);n.isBuilt?i(n):n.onBuilt.addOne(i)}obtain(t,e){const i=this.getRaw(t,e);if(void 0===i)throw new Error(`No tile found at x=${t},y=${e}`);if(i.referenceCount++,i.isBuilt)return Promise.resolve(i);{const n=new Promise(((t,e)=>{i.onBuilt.addOne(t),i.onDestroyed.addOne(e)}));return i.isBuildInProgress||this.build(t,e,Jd,Jd),n}}release(t){t.referenceCount,t.referenceCount--,t.referenceCount<=0&&t.dispose(),t.onDestroyed.send1(t)}dispose(){const t=this.tiles,e=t.length;for(let i=0;i<e;i++)t[i].dispose()}stitchTile(t,e,i){const n=this.totalSize.clone();n.divide(this.tileSize),n.floor();const s=this;let r,a,o,l,h,c,u,d;e>0&&(r=s.getRaw(t,e-1),t>0&&(h=s.getRaw(t-1,e-1)),t<n.x-1&&(c=s.getRaw(t+1,e-1))),e<n.y-1&&(a=s.getRaw(t,e+1),t>0&&(u=s.getRaw(t-1,e+1)),t<n.x-1&&(d=s.getRaw(t+1,e+1))),t>0&&(o=s.getRaw(t-1,e)),t<n.x-1&&(l=s.getRaw(t+1,e)),i.stitchNormals(r,a,o,l,h,c,u,d)}raycastFirstSync(t,e,i,n,s,r,a){return Hp.collector=jp,Hp.setOrigin(e,i,n),Hp.setDirection(s,r,a),jp.initialize(),jp.setOrigin(e,i,n),jp.setDirection(s,r,a),dd(this.bvh,Hp),jp.closestDistance!==Number.POSITIVE_INFINITY&&(t.copy(jp.closest),!0)}raycastVerticalFirstSync(t,e,i){return this.raycastFirstSync(t,e,-1e4,i,0,1,0)}build(t,e,i,n){const s=this,r=this.computeTileIndex(t,e),a=this.tiles[r];a.isBuilt=!1,a.isBuildInProgress=!0;const o=a.resolution.getValue();this.buildWorker.buildTile(a.position.toJSON(),a.size.toJSON(),a.scale.toJSON(),s.totalSize.toJSON(),o).then((function(i){s.tiles[r]===a?a.isBuildInProgress?(a.build(i),s.stitchTile(t,e,a),a.boundingBox.parentNode.bubbleRefit(),a.isBuilt=!0,a.isBuildInProgress=!1,a.onBuilt.send1(a),s.on.tileBuilt.send1(a)):n("Build request has been cancelled"):n("Original tile was destroyed during build process")}),n)}}const Hp=new class extends hd{constructor(){super(),this.originX=0,this.originY=0,this.originZ=0,this.directionX=0,this.directionY=0,this.directionZ=0,this.collector=null}setOrigin(t,e,i){this.originX=t,this.originY=e,this.originZ=i}setDirection(t,e,i){this.directionX=t,this.directionY=e,this.directionZ=i}visitLeaf(t){t.intersectRay(this.originX,this.originY,this.originZ,this.directionX,this.directionY,this.directionZ)&&this.collector.visitLeaf(t)}visitBinary(t){const e=t.intersectRay(this.originX,this.originY,this.originZ,this.directionX,this.directionY,this.directionZ);return e&&this.collector.visitBinary(t),e}},jp=new class extends hd{constructor(){super(),this.closest=new lp,this.closestDistance=Number.POSITIVE_INFINITY,this.__tempContact=new lp,this.originX=0,this.originY=0,this.originZ=0,this.directionX=0,this.directionY=0,this.directionZ=0}setOrigin(t,e,i){this.originX=t,this.originY=e,this.originZ=i}setDirection(t,e,i){this.directionX=t,this.directionY=e,this.directionZ=i}initialize(){this.closestDistance=Number.POSITIVE_INFINITY}visitLeaf(t){const e=t.object;if(e.isBuilt&&e.raycastFirstSync(this.__tempContact,this.originX,this.originY,this.originZ,this.directionX,this.directionY,this.directionZ)){const t=this.__tempContact.position._distanceSqrTo(this.originX,this.originY,this.originZ);t<this.closestDistance&&(this.closestDistance=t,this.closest.copy(this.__tempContact))}}};function qp(){this.url="",this.offset=new wd(0,0),this.scale=new wd(1,1)}qp.prototype.copy=function(t){this.url=t.url,this.scale.copy(t.scale),this.offset.copy(t.offset)},qp.prototype.toJSON=function(){return{url:this.url,offset:this.offset.toJSON(),scale:this.scale.toJSON()}},qp.prototype.fromJSON=function(t){this.url=t.url,this.offset.fromJSON(t.offset),this.scale.fromJSON(t.scale)},qp.prototype.toBinaryBuffer=function(t){t.writeUTF8String(this.url),this.offset.toBinaryBuffer(t),this.scale.toBinaryBuffer(t)},qp.prototype.fromBinaryBuffer=function(t){this.url=t.readUTF8String(),this.offset.fromBinaryBuffer(t),this.scale.fromBinaryBuffer(t)};const Jp={ModelGLTF:"model/gltf",ModelGLTF_JSON:"model/gltf+json",ModelThreeJs:"three.js",ArrayBuffer:"arraybuffer",Texture:"texture",DeferredTexture:"texture-deferred",JSON:"json",Text:"text",Image:"image",ImageSvg:"image/svg",AnimationGraph:"x-meep/animation-graph",AttachmentSockets:"x-meep/attachment-sockets",JavaScript:"text/javascript",Sound:"audio",Font:"font/opentype"};function Yp(t,e){return t.equals(e)}function Xp(t){return t.hash()}class Zp{constructor(t,e){this.key=t,this.value=e}}class $p{constructor({keyHashFunction:t=Xp,keyEqualityFunction:e=Yp,capacity:i=16,loadFactor:n=.75}={}){this.keyHashFunction=t,this.keyEqualityFunction=e,this.records=[],this.size=0,this.__bucket_count=i,this.__load_factor=n}getCurrentLoad(){return this.size/this.__bucket_count}getOccupancy(){let t=0;const e=this.__bucket_count;for(let i=0;i<e;i++){const e=this.records[i];void 0!==e&&e.length>0&&t++}return t/this.__bucket_count}getCollisionCount(){let t=0;const e=this.__bucket_count;for(let i=0;i<e;i++){const e=this.records[i];if(void 0!==e){const i=e.length-1;i>0&&(t+=i)}}return t}setBucketCount(t){this.__bucket_count=t,this.size>0&&this.rebuild()}__compute_bucket_index(t){return((t>>>16^t)>>>0)%this.__bucket_count}set(t,e){const i=this.keyHashFunction(t),n=this.__compute_bucket_index(i),s=this.records;let r=s[n];if(void 0===r)r=[],s[n]=r;else{const i=r.length;for(let n=0;n<i;n++){const i=r[n],s=i.key;if(s===t||this.keyEqualityFunction(s,t))return void(i.value=e)}}r.push(new Zp(t,e));const a=this.size+1;this.size=a,a/this.__bucket_count>this.__load_factor&&this.setBucketCount(2*this.__bucket_count)}get(t){const e=this.keyHashFunction(t),i=this.__compute_bucket_index(e),n=this.records[i];if(void 0!==n){const e=n.length;for(let i=0;i<e;i++){const e=n[i],s=e.key;if(s===t||this.keyEqualityFunction(s,t))return e.value}}}getOrCompute(t,e,i){const n=this.get(t);if(void 0!==n)return n;const s=e.call(i,t);return this.set(t,s),s}getOrSet(t,e){const i=this.get(t);return void 0!==i?i:(this.set(t,e),e)}delete(t){const e=this.keyHashFunction(t),i=this.__compute_bucket_index(e),n=this.records[i];if(void 0===n)return!1;const s=n.length;for(let e=0;e<s;e++){const s=n[e].key;if(s===t||this.keyEqualityFunction(s,t))return n.length<=1?delete this.records[i]:n.splice(e,1),this.size--,!0}return!1}verifyHashes(t){let e,i;const n=this.records;for(e in n){if(!n.hasOwnProperty(e))continue;const s=n[e],r=s.length;for(i=0;i<r;i++){const n=s[i],r=this.keyHashFunction(n.key),a=this.__compute_bucket_index(r),o=parseInt(e);a!==o&&t(`Hash of key has changed. old=${o}, new=${a}`,n.key,n.value)}}}rebuild(){let t,e,i;const n=this.records;for(t in n){const s=parseInt(t);if(!n.hasOwnProperty(t))continue;const r=n[s];for(e=0,i=r.length;e<i;e++){const t=r[e],a=this.keyHashFunction(t.key),o=this.__compute_bucket_index(a);if(o!==s){r.splice(e,1),i--,e--,0===r.length&&delete n[s];const a=n[o];void 0===a?n[o]=[t]:a.push(t)}}}}forEach(t,e){let i,n,s;const r=this.records;for(i in r){if(!r.hasOwnProperty(i))continue;const a=r[i];for(n=0,s=a.length;n<s;n++){const i=a[n];t.call(e,i.value,i.key,this)}}}has(t){return void 0!==this.get(t)}clear(){this.records=[],this.size=0}*[Symbol.iterator](){let t,e,i;const n=this.records;for(t in n){if(!n.hasOwnProperty(t))continue;const s=n[t];for(e=0,i=s.length;e<i;e++){const t=s[e];yield[t.key,t.value]}}}values(){const t=this[Symbol.iterator]();return{next(){const e=t.next();return e.done?{done:!0,value:void 0}:{done:!1,value:e.value[0]}}}}keys(){const t=this[Symbol.iterator]();return{next(){const e=t.next();return e.done?{done:!0,value:void 0}:{done:!1,value:e.value[1]}}}}}class Kp{constructor(){this.key=null,this.value=null,this.next=null,this.previous=null}unlink(){const t=this.next,e=this.previous;null!==e&&(e.next=t),null!==t&&(t.previous=e)}}class Qp{constructor({maxWeight:t=Number.POSITIVE_INFINITY,keyWeigher:e=Xd,valueWeigher:i=Zd,keyHashFunction:n=Xd,keyEqualityFunction:s=Kd,capacity:r}={}){this.maxWeight=t,this.weight=0,this.keyWeigher=e,this.valueWeigher=i,this.__first=null,this.__last=null,this.data=new $p({keyHashFunction:n,keyEqualityFunction:s,capacity:r}),this.onEvicted=new l,this.onRemoved=new l,this.onSet=new l}__promote(t){t!==this.__first&&(t===this.__last&&(this.__last=t.previous),t.unlink(),t.previous=null,null!==this.__first?(t.next=this.__first,this.__first.previous=t):t.next=null,this.__first=t)}size(){return this.data.size}setMaxWeight(t){if("number"!=typeof t||t<0)throw new Error(`Weight must be a non-negative number, instead was '${t}'`);this.maxWeight=t,this.evictUntilWeight(this.maxWeight)}recomputeWeight(){let t=0;for(let[e,i]of this.data)t+=this.keyWeigher(e),t+=this.valueWeigher(i);this.weight=t}setValueWeigher(t){this.valueWeigher=t,this.recomputeWeight(),this.evictUntilWeight(this.maxWeight)}computeElementWeight(t,e){return this.keyWeigher(t)+this.valueWeigher(e)}findEvictionVictim(){return this.__last}evictOne(){const t=this.findEvictionVictim();return null!==t&&(this.remove(t.key),this.onEvicted.send2(t.key,t.value),!0)}evictUntilWeight(t){const e=Math.max(t,0);for(;this.weight>e;)this.evictOne()}put(t,e){let i=this.data.get(t);if(void 0===i){i=new Kp,i.key=t,i.value=e,i.next=this.__first,null!==this.__first&&(this.__first.previous=i),this.__first=i,null===this.__last&&(this.__last=i);const n=this.computeElementWeight(t,e),s=this.maxWeight-n;if(s<0)return;this.evictUntilWeight(s),this.data.set(t,i),this.weight+=n}else e===i.value||(this.weight-=this.valueWeigher(i.value),this.weight+=this.valueWeigher(e),i.value=e),this.__promote(i);this.onSet.send2(t,e)}get(t){const e=this.data.get(t);return void 0===e?null:(this.__promote(e),e.value)}contains(t){return this.data.has(t)}silentRemove(t){const e=this.data.get(t);return void 0!==e&&(this.__removeElement(e),!0)}__removeElement(t){const e=t.value;t===this.__first&&(this.__first=t.next),t===this.__last&&(this.__last=t.previous),t.unlink();const i=t.key,n=this.computeElementWeight(i,e);this.data.delete(i),this.weight-=n}remove(t){const e=this.data.get(t);return void 0!==e&&(this.__removeElement(e),this.onRemoved.send2(t,e.value),!0)}getOrCompute(t,e,i){const n=this.get(t);if(null!==n)return n;const s=e.call(i,t);return this.set(t,s),s}clear(){const t=Array.from(this.data.keys()),e=t.length;for(let i=0;i<e;i++){const e=t[i];this.remove(e)}}drop(){this.data.clear(),this.__first=null,this.__last=null,this.weight=0}}function tf(t){const e=t.length;let i=0;for(let n=0;n<e;n++){let e=t.charCodeAt(n);for(;e>255;)i++,e>>=8;i++}return i}function ef(t,e){if(t.width!==e.width||t.height!==e.height)throw new Error("Source and destination dimensions do not match");const i=t.itemSize,n=e.itemSize,s=t.width*t.height,r=e.data,a=t.data;let o,l;const h=function(t){switch(t){case Uint8Array:return 255;case Uint16Array:return 65535;case Uint32Array:return 4294967295;case Int8Array:return 127;case Int16Array:return 32767;case Int32Array:return 2147483647;case Float32Array:case Float64Array:default:return 1}}(r.constructor);if(i===n)r.set(a);else if(i>n)for(o=0;o<s;o++){const t=o*i,e=o*n;for(l=0;l<n;l++)r[e+l]=a[t+l]}else if(3===i&&4===n)for(o=0;o<s;o++){const t=3*o,e=4*o;r[e]=a[t],r[e+1]=a[t+1],r[e+2]=a[t+2],r[e+3]=h}else{if(2!==i||4!==n)throw new Error("Unsupported channel layout combination");for(o=0;o<s;o++){const t=2*o,e=4*o,i=a[t];r[e]=i,r[e+1]=i,r[e+2]=i,r[e+3]=a[t+1]}}e.version++}Qp.prototype.set=Qp.prototype.put;const nf=new Qp({maxWeight:304857600,keyHashFunction:Nd,keyWeigher:tf,valueWeigher:t=>t.computeByteSize()});class sf{constructor(){this.textureDiffuseURL="",this.diffuse=Vu.uint8(3,1,1),this.size=new wd(1,1),this.extra={},this.onChanged=new l}toJSON(){return{textureDiffuseURL:this.textureDiffuseURL,size:this.size.toJSON(),extra:this.extra}}fromJSON({textureDiffuseURL:t,size:e,extra:i={}}){this.textureDiffuseURL=t,this.size.fromJSON(e),this.extra=i}static from(t,e,i){const n=new sf;return n.textureDiffuseURL=t,n.size.set(e,i),n}static fromDescription(t){return sf.from(t.diffuse,t.size.x,t.size.y)}loadTextureData(t){const e=this.textureDiffuseURL,i=nf.get(e);return null!==i?(this.diffuse.resize(i.width,i.height,!1),this.diffuse.data.set(i.data),this.onChanged.send0(),Promise.resolve()):t.promise(e,Jp.Image).then((t=>{const i=void 0,n=i.itemSize,s=i.data;null!==this.diffuse&&this.diffuse.width===i.width&&this.diffuse.height===i.height||(this.diffuse=Vu.uint8(3,i.width,i.height)),ef(new Vu(s,n,i.width,i.height),this.diffuse),this.onChanged.send0();const r=Vu.uint8(3,i.width,i.height);r.data.set(this.diffuse.data),nf.put(e,r)}))}}function rf(t,e,i){const n=t.length;for(let s=0;s<n;s++)if(i(e,t[s]))return s;return-1}function af(t,e,i=Kd){const n=t.slice(),s=e.slice(),r=[];let a,o=n.length;for(a=0;a<o;a++){const t=n[a],e=rf(s,t,i);-1!==e&&(r.push(t),n.splice(a,1),s.splice(e,1),a--,o--)}return{uniqueA:n,uniqueB:s,common:r}}function of(t){this.on={added:new l,removed:new l},this.data=void 0!==t?t.slice():[],this.length=this.data.length}function lf(t){return this===t||this.equals(t)}function hf(t){return this===t}function cf(t,e){const i=e.length;i>=t.length?e.set(t,0):Rd(t,0,e,0,i)}of.prototype.get=function(t){return this.data[t]},of.prototype.set=function(t,e){const i=this.data[t];void 0!==i?this.on.removed.send2(i,t):t>=this.length&&(this.length=t+1,this.length),this.data[t]=e,this.on.added.send2(e,t)},of.prototype.add=function(t){this.data.push(t);const e=this.length;return this.length++,this.on.added.send2(t,e),this},of.prototype.addUnique=function(t){return!this.contains(t)&&(this.add(t),!0)},of.prototype.insert=function(t,e){return t>this.length&&(this.length=t+1),this.data.splice(t,0,e),this.length++,this.on.added.send2(e,t),this},of.prototype.crop=function(t,e){const i=this.data,n=i.splice(e,this.length-e),s=i.splice(0,t);this.length=e-t;const r=s.length,a=n.length,o=this.on.removed;if(o.hasHandlers()){let t;for(t=0;t<r;t++)o.send2(s[t],t);for(t=0;t<a;t++)o.send2(n[t],e+t)}return r+a},of.prototype.patch=function(t){const e=af(this.data,t,Yp),i=e.uniqueA,n=i.length;for(let t=0;t<n;t++){const e=i[t];this.removeOneOf(e)}const s=e.uniqueB;s.sort(((t,e)=>{const i=this.indexOf(t);return this.indexOf(e)-i}));const r=s.length;for(let t=0;t<r;t++){const e=s[t];let i=0;for(let t=this.indexOf(e)-1;t>=0;t--){const e=this.get(t),n=this.indexOf(e);if(-1!==n){i=n+1;break}}this.insert(i,e)}},of.prototype.addAll=function(t){const e=t.length,i=this.on.added;if(i.hasHandlers())for(let n=0;n<e;n++){const e=t[n];this.data.push(e),i.send2(e,this.length++)}else Array.prototype.push.apply(this.data,t),this.length+=e},of.prototype.addAllUnique=function(t){const e=this.data,i=t.filter((function(i,n){return-1===e.indexOf(i)&&-1===t.indexOf(i,n+1)}));this.addAll(i)},of.prototype.removeMany=function(t,e){const i=this.data.splice(t,e),n=i.length;if(this.length-=n,this.on.removed.hasHandlers())for(let e=0;e<n;e++){const n=i[e];this.on.removed.send2(n,t+e)}return i},of.prototype.remove=function(t){const e=this.data.splice(t,1);this.length--;const i=e[0];return this.on.removed.send2(i,t),i},of.prototype.removeAll=function(t){let e,i,n,s;i=t.length,s=this.length;let r=0;const a=this.data;t:for(e=0;e<i;e++){const i=t[e];for(n=s-1;n>=0;n--)if((o=a[n])===(l=i)||"function"==typeof o.equals&&o.equals(l)){this.remove(n),s--;continue t}r++}var o,l;return 0===r},of.prototype.removeOneOf=function(t){return"object"==typeof t&&"function"==typeof t.equals?this.removeOneIf(lf,t):this.removeOneIf(hf,t)},of.prototype.sort=function(){return Array.prototype.sort.apply(this.data,arguments),this},of.prototype.clone=function(){return new of(this.data)},of.prototype.some=function(t){const e=this.length,i=this.data;for(let n=0;n<e;n++)if(t(i[n]))return!0;return!1},of.prototype.removeIf=function(t){let e=this.length;const i=this.data;for(let n=0;n<e;n++)t(i[n])&&(this.remove(n),n--,e--)},of.prototype.removeOneIf=function(t,e){const i=this.length,n=this.data;for(let s=0;s<i;s++){const i=n[s];if(t.call(e,i))return this.remove(s),!0}return!1},of.prototype.forEach=function(t,e){const i=this.length,n=this.data;for(let s=0;s<i;s++)t.call(e,n[s],s)},of.prototype.reduce=function(t,e){let i=e;return this.forEach((function(e){i=t(i,e)})),i},of.prototype.filter=function(t){return this.data.filter(t)},of.prototype.find=function(t){const e=this.data;let i=0;const n=this.length;for(;i<n;i++){const n=e[i];if(t(n))return n}},of.prototype.findIndex=function(t){const e=this.data;let i=0;const n=this.length;for(;i<n;i++)if(t(e[i]))return i;return-1},of.prototype.visitFirstMatch=function(t,e){const i=this.data;let n=0;const s=this.length;for(;n<s;n++){const s=i[n];if(t(s))return void e(s,n)}},of.prototype.contains=function(t){return-1!==this.data.indexOf(t)},of.prototype.containsAny=function(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];if(this.contains(e))return!0}return!1},of.prototype.isEmpty=function(){return this.length<=0},of.prototype.indexOf=function(t){return this.data.indexOf(t)},of.prototype.map=function(t,e){const i=[],n=this.data,s=this.length;for(let r=0;r<s;r++){const s=n[r];void 0!==s&&(i[r]=t.call(e,s,r))}return i},of.prototype.resetViaCallback=function(t,e){const i=this.length;if(i>0){const n=this.on.removed,s=this.data;for(let r=i-1;r>=0;r--){const i=s[r];this.data.length=r,this.length=r,n.send2(i,r),t.call(e,i,r)}}},of.prototype.reset=function(){const t=this.length;if(t>0){const e=this.on.removed;if(e.hasHandlers()){const i=this.data;for(let n=t-1;n>=0;n--){const t=i[n];this.data.length=n,this.length=n,e.send2(t,n)}}else this.data=[],this.length=0}},of.prototype.deepCopy=function(t,e,i){const n=[],s=t.asArray(),r=s.length,a=this.data;let o=this.length;for(let t=0;t<o;t++){const r=a[t],o=rf(s,r,Yp);-1!==o?n[o]=r:"function"==typeof e&&e.call(i,r)}for(let t=0;t<r;t++)if(void 0===n[t]){const e=s[t];n[t]=e.clone()}this.reset(),this.addAll(n)},of.prototype.copy=function(t){this!==t&&(this.reset(),t.length>0&&(t instanceof of?this.addAll(t.data):this.addAll(t)))},of.prototype.asArray=function(){return this.data},of.prototype.toJSON=function(){return JSON.parse(JSON.stringify(this.data))},of.prototype.fromJSON=function(t,e){this.reset(),"function"==typeof e?this.addAll(t.map((function(t){const i=new e;return i.fromJSON(t),i}))):this.addAll(t)},of.prototype.toBinaryBuffer=function(t){const e=this.length;t.writeUint32(e);for(let i=0;i<e;i++)this.data[i].toBinaryBuffer(t)},of.prototype.fromBinaryBuffer=function(t,e){this.fromBinaryBufferViaFactory(t,(function(t){const i=new e;return i.fromBinaryBuffer(t),i}))},of.prototype.fromBinaryBufferViaFactory=function(t,e){this.reset(),this.addFromBinaryBufferViaFactory(t,e)},of.prototype.addFromBinaryBufferViaFactory=function(t,e){const i=t.readUint32();for(let n=0;n<i;n++){const i=e(t);this.add(i)}},of.prototype.addFromJSONViaFactory=function(t,e){const i=t.length;for(let n=0;n<i;n++){const i=e(t[n]);this.add(i)}},of.prototype.hash=function(){let t=0;const e=this.length;for(let i=0;i<e;i++)t=(t<<5)-t+this.data[i].hash(),t|=0;return t},of.prototype.last=function(){return this.data[this.length-1]},of.prototype.equals=function(t){const e=this.length;if(e!==t.length)return!1;let i;for(i=0;i<e;i++){const e=this.get(i),n=t.get(i);if(e!==n&&("object"!=typeof e||"object"!=typeof n||"function"!=typeof e.equals||!e.equals(n)))return!1}return!0},of.prototype.compare=function(t){const e=this.length,i=t.length;if(e!==i)return e-i;for(let i=0;i<e;i++){const e=this.get(i),n=t.get(i),s=e.compare(n);if(0!==s)return s}return 0};class uf{constructor(){this.uri="",this.size=new wd}static from(t,e){const i=new uf;return i.uri=t,i.size.copy(e),i}hash(){return Nd(this.uri)^this.size.hashCode()}equals(t){return this.uri===t.uri&&this.size.equals(t.size)}}const df=new Qp({maxWeight:104857600,keyEqualityFunction:Yp,keyHashFunction:Xp,valueWeigher:t=>t.computeByteSize()});class pf{constructor(){this.layers=new of,this.resolution=new wd(512,512),this.texture=new Hr(new Uint8Array(3),1,1,1),this.texture.format=Jt,this.texture.type=Ft,this.texture.wrapS=Tt,this.texture.wrapT=Tt,this.texture.anisotropy=8,this.texture.magFilter=Nt,this.texture.minFilter=1008,this.texture.generateMipmaps=!0,this.texture.encoding=Ke,this.texture.internalFormat="RGB8",this.scalesTexture=new wl(new Float32Array(64),32,1,ie,Bt),this.scalesTexture.wrapS=Ct,this.scalesTexture.wrapT=Ct,this.scalesTexture.minFilter=Nt,this.scalesTexture.magFilter=Et,this.scalesTexture.internalFormat="RG32F",this.scalesTexture.generateMipmaps=!1}toJSON(){return{resolution:this.resolution.toJSON(),layers:this.layers.toJSON()}}fromJSON({resolution:t=512,layers:e=[]}={}){this.resolution.fromJSON(t),this.layers.fromJSON(e,sf)}updateLayerScales(t,e){const i=this.layers,n=i.length,s=this.scalesTexture,r=s.image,a=2*n;r.data.length<a&&(s.dispose(),r.data=new Float32Array(a),r.height=1,r.width=n);const o=r.data;for(let s=0;s<n;s++){const n=i.get(s),r=2*s,a=t/n.size.x,l=e/n.size.y;o[r]=a,o[r+1]=l}s.needsUpdate=!0}loadTextureData(t){const e=this.layers.length,i=[];for(let n=0;n<e;n++){const e=this.layers.get(n).loadTextureData(t),s=n;e.then((()=>{this.writeLayerDataIntoTexture(s)}),(t=>{})),i.push(e)}return Promise.all(i)}writeAllLayersDataIntoTexture(){for(let t=0;t<this.layers.length;t++)this.writeLayerDataIntoTexture(t)}get(t){return this.layers.get(t)}findIndexByDescription(t){const e=this.layers,i=e.length;for(let n=0;n<i;n++){const i=e.get(n);if(i.size.equals(t.size)&&i.textureDiffuseURL===t.diffuse)return n}return-1}findIndexByDiffuseTextureURL(t){return this.layers.findIndex((e=>e.textureDiffuseURL===t))}count(){return this.layers.length}addLayer(t){const e=this.layers.length;return this.layers.add(t),e}removeLayer(t){return this.layers.removeOneOf(t)}__obtain_layer_data_at_resolution(t,e){const i=t.diffuse,n=e.x,s=e.y;if(i.width===n&&i.height===s)return t.diffuse;{const r=uf.from(t.textureDiffuseURL,e),a=df.get(r);if(null!==a)return a;const o=Vu.uint8(3,n,s);return Fd(i,o),df.put(r,o),o}}writeLayerDataIntoTexture(t){const e=this.get(t),i=this.texture.image.data,n=this.resolution,s=n.x*n.y*3;if(i.length<s*t)throw new Error("Texture data is too small, make sure you rebuild texture data before attempting to write");const r=s*t,a=this.__obtain_layer_data_at_resolution(e,n);i.set(a.data,r),this.texture.needsUpdate=!0}dispose(){this.texture.dispose(),this.scalesTexture.dispose()}clear(){this.layers.reset()}buildTexture(){const t=this.texture,e=t.image,i=this.resolution.x,n=this.resolution.y,s=this.layers.length;if(e.width===i&&e.height===n&&e.depth===s)return;t.dispose();const r=new Uint8Array(i*n*3*s);e.width===i&&e.height===n&&cf(e.data,r),e.data=r,e.width=i,e.height=n,e.depth=s,t.needsUpdate=!0}}const ff=["float rand(float v){"," return fract(sin(v) * 43758.5453);","}"].join("\n"),mf=["#ifdef SHADOWMAP_CLOUDS"," uniform float f_CloudsTime;"," uniform vec2 v_CloudsSpeed_0;"," uniform vec2 v_CloudsSpeed_1;"," uniform vec2 v_CloudsSpeed_2;"," uniform vec2 v_CloudsSize_0;"," uniform vec2 v_CloudsSize_1;"," uniform vec2 v_CloudsSize_2;"," varying vec2 v_Clouds_0_offset;"," varying vec2 v_Clouds_1_offset;"," varying vec2 v_Clouds_2_offset;","#endif"].join("\n"),_f=["#ifdef SHADOWMAP_CLOUDS"," vec2 cloudsUV = worldPosition.xz;"," v_Clouds_0_offset = (v_CloudsSpeed_0 * f_CloudsTime + cloudsUV) / v_CloudsSize_0;"," v_Clouds_1_offset = (v_CloudsSpeed_1 * f_CloudsTime + cloudsUV) / v_CloudsSize_1;"," v_Clouds_2_offset = (v_CloudsSpeed_2 * f_CloudsTime + cloudsUV) / v_CloudsSize_2;","#endif"].join("\n"),gf=["#ifdef SHADOWMAP_CLOUDS"," varying vec2 v_Clouds_0_offset;"," varying vec2 v_Clouds_1_offset;"," varying vec2 v_Clouds_2_offset;"," uniform sampler2D t_Clouds_0;"," uniform sampler2D t_Clouds_1;"," uniform sampler2D t_Clouds_2;"," uniform float f_CloudsAmount;"," uniform float f_CloudsIntensity;","#endif"].join("\n"),yf=["#ifdef SHADOWMAP_CLOUDS"," vec4 shadowmapCloudsColor = texture2D(t_Clouds_0, v_Clouds_0_offset) * texture2D(t_Clouds_1, v_Clouds_1_offset) * texture2D(t_Clouds_2, v_Clouds_2_offset);"," float shadowmapCloudsIntensity = min( max(shadowmapCloudsColor.r-(1.0-f_CloudsAmount),0.0)*(1.0/f_CloudsAmount), 0.05 ) * 20.0;"," reflectedLight.directDiffuse *= mix(1.0, 1.0-f_CloudsIntensity, shadowmapCloudsIntensity);","#endif"].join("\n"),vf=(["#ifdef USE_MAP"," vec4 texelColor = texture2D( map, vUv );"," texelColor = GammaToLinear( texelColor, float( GAMMA_FACTOR ) );"," \tdiffuseColor *= texelColor;","#endif"].join("\n"),{vertexShader:`\n #define PHYSICAL\n #define STANDARD\n \n uniform vec2 gridResolution;\n \n uniform vec4 uGridTransform;\n \n varying vec3 vViewPosition;\n varying vec2 vGridPosition;\n \n #ifndef FLAT_SHADED\n varying vec3 vNormal;\n #endif\n \n varying vec2 vUv;\n varying vec2 vUvGrid;\n uniform vec4 offsetRepeat;\n \n #include <common>\n #include <uv_pars_vertex>\n #include <uv2_pars_vertex>\n #include <color_pars_vertex>\n #include <fog_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 \n ${mf}\n \n void main() {\n \n vUv = uv;\n #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv;\n #endif\n \n vGridPosition = (position.xz - uGridTransform.zw) / uGridTransform.xy;\n vUvGrid = vGridPosition / gridResolution;\n \n #include <color_vertex>\n #include <beginnormal_vertex>\n #include <morphnormal_vertex>\n #include <skinbase_vertex>\n #include <skinnormal_vertex>\n #include <defaultnormal_vertex>\n \n #ifndef FLAT_SHADED // Normal computed with derivatives when FLAT_SHADED\n vNormal = normalize( transformedNormal );\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\t \n\t vViewPosition = - mvPosition.xyz;\n \n #if defined( SHADOWMAP_CLOUDS ) && !(defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ))\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #endif\n \n #include <worldpos_vertex>\n \n \n #include <shadowmap_vertex>\n #include <fog_vertex>\n \n ${_f}\n \n }\n `,fragmentShader:`\n #define PHYSICAL\n #define STANDARD\n \n #ifdef PHYSICAL\n //#define IOR\n //#define SPECULAR\n #endif\n \n #ifdef IOR\n uniform float ior;\n #endif\n precision highp sampler2DArray;\n \n uniform sampler2DArray splatWeightMap;\n uniform int splatLayerCount;\n \n uniform vec2 splatResolution;\n \n uniform sampler2D materialScalesMap;\n \n uniform sampler2DArray diffuseMaps;\n\n uniform sampler2D diffuseGridOverlaySprite;\n uniform sampler2D diffuseGridOverlayMap;\n \n uniform vec2 gridResolution;\n uniform float gridBorderWidth;\n uniform vec4 offsetRepeat;\n\n uniform vec3 diffuse;\n uniform vec3 emissive;\n uniform float opacity;\n \n varying vec3 vViewPosition;\n \n\n #include <common>\n #include <packing>\n #include <dithering_pars_fragment>\n #include <color_pars_fragment>\n \n varying vec2 vUv;\n varying vec2 vUvGrid;\n varying vec2 vGridPosition;\n \n #include <uv2_pars_fragment>\n #include <alphamap_pars_fragment>\n #include <alphatest_pars_fragment>\n #include <aomap_pars_fragment>\n #include <lightmap_pars_fragment>\n #include <emissivemap_pars_fragment>\n #include <bsdfs>\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 \n #ifndef FLAT_SHADED\n varying vec3 vNormal;\n \n #ifdef USE_TANGENT\n varying vec3 vTangent;\n varying vec3 vBitangent;\n #endif\n \n #endif\n \n #include <lights_physical_pars_fragment>\n #include <transmission_pars_fragment>\n #include <shadowmap_pars_fragment>\n #include <bumpmap_pars_fragment>\n #include <clearcoat_pars_fragment>\n #include <roughnessmap_pars_fragment>\n #include <metalnessmap_pars_fragment>\n #include <logdepthbuf_pars_fragment>\n #include <clipping_planes_pars_fragment>\n \n ${ff}\n \n vec4 blendSplatTextures(const in vec4 tex0, const in vec4 tex1, const in vec4 tex2, const in vec4 tex3, const in vec4 splat){\n \n float b0 = splat[0];\n \n float b1 = splat[1];\n \n float b2 = splat[2];\n \n float b3 = splat[3];\n \n return (tex0*b0 + tex1*b1 + tex2*b2 + tex3*b3) / (b0 + b1 + b2 + b3);\n }\n \n void randomBlend(in vec2 uv, inout vec3 v, float level){\n vec3 noise = vec3( rand(uv.x*12.9898 + uv.y*78.233), rand(uv.x*10.9898 + uv.y*73.233) , rand(uv.x*6.9898 + uv.y*71.233));\n v = v*(1.0 - level) + noise*level;\n }\n \n vec3 AdjustContrastCurve(vec3 color, float contrast) {\n float p = 1.0 / max(contrast, 0.0001);\n vec3 v = abs(color * 2.0 - 1.0);\n return pow(v, vec3(p)) * sign(color - 0.5) + 0.5;\n }\n \n vec3 AdjustSaturation(vec3 rgb, float adjustment){\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n vec3 intensity = vec3(dot(rgb, W));\n return mix(intensity, rgb, adjustment);\n }\n \n vec4 blendAlpha(in vec4 source, in vec4 target){\n return source*(1.0 - target.a) + vec4(target.rgb*target.a , target.a);\n }\n \n vec4 blendAdd(in vec4 source, in vec4 target){\n return source + target;\n } \n \n vec4 blendAddAlpha(in vec4 source, in vec4 target){\n \n vec4 a = blendAlpha(source, target);\n vec4 b = blendAdd(source, target);\n \n return mix(a, b, target.a);\n }\n \n vec3 rgb2hsv(vec3 c){\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n \n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n }\n \n vec3 hsv2rgb(vec3 c){\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n }\n \n const mat3 rgb2yiq = mat3(0.299, 0.587, 0.114, 0.595716, -0.274453, -0.321263, 0.211456, -0.522591, 0.311135);\n const mat3 yiq2rgb = mat3(1.0, 0.9563, 0.6210, 1.0, -0.2721, -0.6474, 1.0, -1.1070, 1.7046);\n\n vec3 brighten(const in vec3 color, in float factor){\n //vec3 yiq = rgb2yiq*color;\n \n //yiq.x *= factor;\n \n //return yiq2rgb * yiq;\n \n vec3 hsv = rgb2hsv(color);\n \n hsv.z *= factor;\n \n return hsv2rgb(hsv);\n }\n \n vec3 brighten2(const in vec3 color, in float factor, float p){\n vec3 yiq = rgb2yiq*color;\n \n yiq.x *= p;\n yiq.x = pow(yiq.x,factor);\n \n return yiq2rgb * yiq;\n }\n \n vec4 computeGridOverlayTexel(const in vec2 grid_uv, const in vec2 grid_resolution){\n vec2 grid_texel = vGridPosition + 0.5;\n \n vec2 uv = grid_texel / grid_resolution;\n \n vec4 tile_data = texture2D(diffuseGridOverlayMap, uv);\n \n if(tile_data.a == 0.0){\n return vec4(0.0);\n }\n \n vec2 tile_uv = mod(grid_texel , 1.0);\n \n vec4 tile_color = texture2D(diffuseGridOverlaySprite, tile_uv);\n \n if(tile_color.a <= 0.01){\n return vec4(0.0);\n }\n \n return tile_color * tile_data;\n }\n \n vec4 computeSplatMix(vec2 uv){\n \n float weightSum = 0.0;\n vec4 colorSum = vec4(0.0);\n \n for( int i = 0; i < splatLayerCount; i++){\n \n vec2 scale = texelFetch(materialScalesMap, ivec2(i, 0), 0 ).xy;\n \n vec2 layerUv = vUv * scale;\n \n vec4 diffuseData = texture(diffuseMaps, vec3(layerUv, i) );\n \n float weight = texture(splatWeightMap, vec3(uv, i)).x;\n \n weightSum += weight;\n colorSum += diffuseData*weight;\n }\n \n return colorSum / weightSum; \n }\n \n ${gf}\n \n out highp vec4 pc_fragColor;\n \n void main() { \n vec4 splatDiffuseColor = computeSplatMix(vUv);\n \n //decode the texture\n splatDiffuseColor = sRGBToLinear( splatDiffuseColor );\n \n //ensure it is fully opaque\n splatDiffuseColor.a = 1.0;\n \n #ifdef DIFFUSE_GRAIN\n randomBlend(vUv, splatDiffuseColor.rgb, 0.03);\n #endif\n \n vec4 gridOverlayColor = computeGridOverlayTexel(vUvGrid, gridResolution);\n \n #include <clipping_planes_fragment>\n \n vec4 diffuseColor = blendAlpha( splatDiffuseColor, gridOverlayColor );\n \n #ifdef USE_AOMAP\n \n vec4 aoShadowMapTexel = texture2D( aoMap, vUv2 );\n \n diffuseColor *= aoShadowMapTexel.r;\n \n #endif\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 \n // make surface completely diffuse\n float roughnessFactor = 1.0;\n float metalnessFactor = 0.0;\n \n #include <normal_fragment_begin>\n #include <emissivemap_fragment>\n \n vec3 rawDiffuseColor = diffuseColor.rgb;\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 ${yf}\n \n // modulation\n #include <aomap_fragment>\n \n \n vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n \n vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n \n pc_fragColor = vec4( outgoingLight, diffuseColor.a );\n \n #if defined( TONE_MAPPING )\n pc_fragColor.rgb = toneMapping( pc_fragColor.rgb );\n #endif\n \n //encode fragment\n pc_fragColor = linearToOutputTexel( pc_fragColor );\n #ifdef USE_FOG\n #ifdef FOG_EXP2\n float fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );\n #else\n float fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n #endif\n pc_fragColor.rgb = mix( pc_fragColor.rgb, fogColor, fogFactor );\n #endif\n \n #ifdef PREMULTIPLIED_ALPHA\n // Get get normal blending with premultipled, use with CustomBlending, OneFactor, OneMinusSrcAlphaFactor, AddEquation.\n pc_fragColor.rgb *= pc_fragColor.a;\n #endif\n \n #ifdef DITHERING\n pc_fragColor.rgb = dithering( pc_fragColor.rgb );\n #endif\n }\n `});function xf(){const t=Vu.uint8(4,1,1);for(let e=0;e<t.data.length;e++)t.data[e]=255;const e=function(t){const e=new wl;let i;if(e.format=Yt,4===t.itemSize)i=t.data;else{const e=Vu.uint8(4,t.width,t.height);ef(t,e),i=e.data}return e.type=Ft,e.flipY=!0,e.image={data:i,width:t.width,height:t.height},e.wrapS=Ct,e.wrapT=Ct,e.generateMipmaps=!1,e.repeat.set(1,1),e.needsUpdate=!0,e.anisotropy=4,e}(t);return e}function wf({gridResolution:t,splatMap:e,diffuseMaps:i,lightMap:n}){const s=Gs.merge([or.common,or.specularmap,or.envmap,or.aomap,or.lightmap,or.emissivemap,or.fog,or.lights,{splatWeightMap:{type:"t",value:null},splatLayerCount:{type:"f",value:4},splatResolution:{type:"v2",value:new bi(1,1)},gridResolution:{type:"v2",value:new bi(1,1)},uGridTransform:{type:"v4",value:new Ni},gridBorderWidth:{type:"f",value:.1},materialScalesMap:{type:"t",value:null},diffuseMaps:{type:"t",value:null},diffuseGridOverlayMap:{type:"t",value:null},diffuseGridOverlaySprite:{type:"t",value:xf()}},{emissive:{type:"c",value:new ss(0)},specular:{type:"c",value:new ss(16777215)},shininess:{type:"f",value:0},envMapIntensity:{value:1}},{f_CloudsTime:{type:"f",value:0},f_CloudsAmount:{type:"f",value:.9},f_CloudsIntensity:{type:"f",value:.3},v_CloudsSpeed_0:{type:"v2",value:new bi(.03,-.03)},v_CloudsSpeed_1:{type:"v2",value:new bi(.011,-.011)},v_CloudsSpeed_2:{type:"v2",value:new bi(.023,-.023)},v_CloudsSize_0:{type:"v2",value:new bi(40,40)},v_CloudsSize_1:{type:"v2",value:new bi(20,20)},v_CloudsSize_2:{type:"v2",value:new bi(10,10)},t_Clouds_0:{type:"t",value:null},t_Clouds_1:{type:"t",value:null},t_Clouds_2:{type:"t",value:null}}]);void 0!==t&&s.gridResolution.value.set(t.x,t.y);const r=new Ws({uniforms:s,vertexShader:vf.vertexShader,fragmentShader:vf.fragmentShader,side:N,blending:D,depthTest:!0,depthWrite:!0,transparent:!1,lights:!0,defines:{SHADOWMAP_CLOUDS:!1,DIFFUSE_GRAIN:!1},glslVersion:ui});return r.depthWrite=!0,r.transparent=!1,s.diffuse.value=new ss(16777215),void 0!==e&&(e.wrapS=e.wrapT=Ct,e.minFilter=Nt,e.magFilter=Nt,s.splatMap.value=e),void 0!==i&&(s.diffuseMaps.value=i),void 0!==n&&(r.aoMap=!0,s.aoMap.value=n,s.aoMapIntensity.value=.7),r.extensions.derivatives=!0,r.needsUpdate=!0,r.isSplatMaterial=!0,r}const bf={EndSuccess:0,EndFailure:1,Continue:2,Yield:3},Sf={INITIAL:0,READY:1,RUNNING:2,FAILED:3,SUCCEEDED:4,CANCELLED:5};class Mf{constructor({name:t,initializer:e=Jd,cycleFunction:i,computeProgress:n,dependencies:s=[],estimatedDuration:r=1}){this.dependencies=s,this.estimatedDuration=r,this.name=t,this.cycle=i,this.initialize=e,void 0!==n&&(this.computeProgress=n),this.on={started:new l,completed:new l,failed:new l},this.state=new Sp(Sf.INITIAL),this.__executedCpuTime=0,this.__executedCycleCount=0}computeProgress(){const t=this.__executedCycleCount;return 0===t?0:1-1/t}getExecutedCpuTime(){return this.__executedCpuTime}getEstimatedDuration(){return this.estimatedDuration}addDependency(t){if(t.isTaskGroup)this.addDependencies(t.children);else{if(!t.isTask)throw new Error("Expected a Task or a TaskGroup, got something else");-1===this.dependencies.indexOf(t)&&this.dependencies.push(t)}return this}addDependencies(t){if(!Array.isArray(t))throw new Error("argument 'tasks' is not an Array");t.forEach((t=>this.addDependency(t)))}toString(){return`Task{name:'${this.name}'}`}join(t,e){Mf.join(this,t,e)}executeSync(){this.initialize();let t=this.cycle();for(;t!==bf.EndSuccess&&t!==bf.EndFailure;t=this.cycle());return t===bf.EndSuccess?this.on.completed.dispatch():t===bf.EndFailure&&this.on.failed.dispatch(),t}promise(){return Mf.promise(this)}static promiseAll(t){const e=t.map(Mf.promise);return Promise.all(e)}static promise(t){return new Promise(((e,i)=>Mf.join(t,e,i)))}static join(t,e,i){const n=t.state.getValue();n===Sf.SUCCEEDED?e():n===Sf.FAILED?void 0!==i&&i():(t.on.completed.addOne(e),void 0!==i&&t.on.failed.addOne(i))}static joinAll(t,e,i){let n=t.length;if(0===n)return void e();let s=!1;function r(){n--,n<=0&&!s&&e()}function a(){s||(s=!0,i(arguments))}for(let e=0;e<t.length;e++)t[e].join(r,a)}}Mf.prototype.isTask=!0;class Tf{constructor(){this.size=new wd(512,512),this.depth=1;const t=this.size,e=t.x,i=t.y;this.weightTexture=new Hr(new Uint8Array(e*i),e,i,1),this.weightTexture.generateMipmaps=!1,this.weightTexture.format=te,this.weightTexture.type=Ft,this.weightTexture.magFilter=Nt,this.weightTexture.minFilter=Et,this.materialTexture=new wl(new Uint8Array(e*i*4),e,i)}toJSON(){const t=Uu.encode(this.weightData.buffer);return{size:this.size.toJSON(),depth:this.depth,data:t}}fromJSON({size:t={x:1,y:1},depth:e=0,data:i}={}){let n;if(this.resize(t.x,t.y,e),"string"==typeof i){const t=Uu.decode(i);n=new Uint8Array(t)}else{if(!Array.isArray(i))throw new Error("Unsupported data format");n=i}Rd(n,0,this.weightData,0,i.length),this.weightTexture.needsUpdate=!0}writeLayerFromSampler(t,e,i=0){const n=this.weightData,s=this.size.x,r=this.size.y,a=e*s*r,o=t.width,l=t.height-1,h=o-1;for(let e=0;e<r;e++){const o=e/r;for(let r=0;r<s;r++){const c=r/s,u=a+(e*s+r),d=t.sampleChannelBilinear(c*h,o*l,i);n[u]=d}}}readLayerToSampler(t,e,i=0){const n=this.weightData,s=this.size.x,r=this.size.y,a=e*s*r;for(let e=0;e<r;e++)for(let r=0;r<s;r++){const o=n[a+(e*s+r)];t.writeChannel(r,e,i,o)}}writeWeightData(t,e,i,n,s){const r=this.depth,a=n*s,o=this.size.x,l=this.size.y,h=o*l,c=Eu(0,ru(o-e,n)),u=Eu(0,ru(l-i,s)),d=this.weightData;for(let s=0;s<r;s++){const r=h*s,l=a*s;for(let s=0;s<u;s++){const a=(s+i)*o+r,h=s*n+l;for(let i=0;i<c;i++){const n=h+i;d[a+(i+e)]=t[n]}}}}readWeightData(t,e,i,n,s){const r=this.depth,a=this.size.x,o=this.size.y,l=a*o,h=n*s,c=Eu(0,ru(a-e,n)),u=Eu(0,ru(o-i,s)),d=this.weightData;for(let s=0;s<r;s++){const r=h*s,o=l*s;for(let s=0;s<u;s++){const l=s*n+r,h=(s+i)*a+o;for(let i=0;i<c;i++){const n=h+i+e;t[l+i]=d[n]}}}}sampleWeight(t,e,i){return this.getLayerWeightSampler(i).sampleChannelBilinearUV(t,e,0)}getLayerWeightSampler(t){const e=this.size.x,i=this.size.y,n=e*i,s=n*t,r=s+n;return new Vu(this.weightData.subarray(s,r),1,e,i)}get weightData(){return this.weightTexture.image.data}get materialData(){return this.materialTexture.image.data}get materialSampler(){return new Vu(this.materialData,4,this.size.x,this.size.y)}optimize(){return[]}computeWeightRankingMap(t){const e=this.size.x,i=this.size.y,n=this.depth,s=this.weightData,r=[],a=[];function o(t,e){const i=r[t];return r[e]-i}const l=e*i;return function(e,i,h){let c=0,u=0,d=c;const p=typeof i;return new Mf({name:"count (from 0 to "+("number"===p?i:"variable")+")",initializer(){c=0,"number"===p?u=i:"function"===p&&(u=i()),d=c},cycleFunction:function(){return d>=u?bf.EndSuccess:((e=>{for(let t=0;t<n;t++){const i=e+t*l;a[t]=t,r[t]=s[i]}a.sort(o);for(let i=0;i<n;i++){const n=a[i];t[e+n*l]=i}})(d),d++,bf.Continue)},computeProgress:function(){const t=u-c;return 0===t?0:(d-c)/t}})}(0,e*i)}dispose(){this.weightTexture.dispose(),this.materialTexture.dispose()}removeWeightLayer(t){if(t>=this.depth)return!1;this.depth--;const e=this.size.x*this.size.y,i=t*e,n=(t+1)*e,s=this.weightTexture;s.dispose();const r=s.image,a=r.data;a.copyWithin(i,n);const o=new Uint8Array(this.depth*e);return o.set(a.subarray(0,o.length)),r.data=o,r.depth=this.depth,s.needsUpdate=!0,!0}fillLayerWeights(t,e){const i=this.size.x*this.size.y,n=i*t,s=n+i,r=this.weightData;for(let t=n;t<s;t++)r[t]=e}addWeightLayer(){this.weightTexture.dispose();const t=this.size.x*this.size.y;this.depth++;const e=this.depth,i=new Uint8Array(t*e);i.set(this.weightData),this.weightTexture.image.data=i,this.weightTexture.image.depth=e,this.weightTexture.needsUpdate=!0}resize(t,e,i){const n=this.size.x,s=this.size.y,r=this.depth;this.depth=i,t===n&&e===s&&i===r||this.size.set(t,e);const a=this.weightTexture,o=a.image;if(o.width!==t||o.height!==e||o.depth!==i){a.dispose();const l=o.data,h=n*s,c=t*e;if(o.width=t,o.height=e,o.depth=i,o.data=new Uint8Array(c*i),n===t&&s===e)cf(l,o.data);else for(let a=0;a<ru(i,r);a++)Fd(new Vu(l.subarray(a*h,(a+1)*h),1,n,s),new Vu(o.data.subarray(a*c,(a+1)*c),1,t,e));a.needsUpdate=!0}}}class Cf{constructor(){this.offset_x=0,this.offset_y=0,this.scale_x=1,this.scale_y=1}}const Af=/[a-zA-Z0-9_\-]+\:\/\//,Ef="object"==typeof window,zf="object"==typeof process&&!Ef,If="function"==typeof importScripts;function Nf(t,e){try{return t.postMessage(e),!0}catch(t){return!1}}class Lf{constructor(t,e){this.url=t,this.methods=e,this.__pending={},this.__isRunning=!1,this.__worker=null,this.__id_counter=0,this.__handleMessageBound=this.__handleMessage.bind(this),this.__generateAPI(this,e)}$submitRequest(t,e){const i=this.__pending[t],n=e.length,s=new Array(n);for(let t=0;t<n;t++){const i=e[t];null!==(r=i)&&"object"==typeof r&&r.hasOwnProperty("toJSON")&&"function"===r.toJSON?s[t]=i.toJSON():s[t]=i}var r;const a=this.__id_counter++;return new Promise(((e,n)=>{const r={parameters:s,id:a,resolve:e,reject:n};if(i.push(r),this.isRunning()){const e={methodName:t,id:r.id,parameters:s};if(!Nf(this.__worker,e)){const t=i.indexOf(r);i.splice(t,1)}}}))}__makeMethod(t){this.__pending[t]=[];const e=this;this[t]=function(){return e.$submitRequest(t,arguments)}}__generateAPI(){for(let t in this.methods)this.methods.hasOwnProperty(t)&&this.__makeMethod(t)}__handleMessage(t){const e=this.__pending,i=t.data,n=i.id,s=i.methodName,r=e[s];if(void 0===r)throw new Error("Unexpected method '"+s+"'");{const t=r.length;for(let e=0;e<t;e++){const t=r[e];if(t.id===n)return r.splice(e,1),void(i.hasOwnProperty("error")?t.reject(i.error):t.resolve(i.result))}throw new Error(`Request ${n} not found in the request queue`)}}isRunning(){return this.__isRunning}stop(){this.__isRunning&&(this.__worker.terminate(),this.__isRunning=!1)}cancelRequest(t,e){const i=this.__pending[e];if(void 0===i)throw new Error(`No request queue for method name '${e}'`);const n=i.length;for(let e=0;e<n;e++)if(i[e].id===t){if(this.__isRunning)throw new Error("Ability to cancel pending requests while worker is running is not implemented yet");return i.splice(e,1),!0}}sendPendingRequests(){for(let t in this.__pending)if(this.__pending.hasOwnProperty(t)){const e=this.__pending[t],i=e.length;for(let n=0;n<i;n++){const i=e[n],s={methodName:t,id:i.id,parameters:i.parameters};Nf(this.__worker,s)}}}start(){this.__isRunning||(this.__worker=new Worker(this.url),this.__worker.onmessage=this.__handleMessageBound,this.__worker.onerror=t=>{},this.__isRunning=!0,this.sendPendingRequests())}}const Pf=function(t,e){this.text=t,this.indentation=e},Ff=function(){this.lines=[],this.indentation=0,this.indentSpaces=4};Ff.fromText=function(t){const e=new Ff,i=t.split("\n"),n=i.length;for(let t=0;t<n;t++)e.add(i[t]);return e},Ff.prototype.containsSubstring=function(t){const e=this.lines,i=e.length;for(let n=0;n<i;n++)if(-1!==e[n].text.indexOf(t))return!0;return!1},Ff.prototype.indent=function(){return this.indentation++,this},Ff.prototype.dedent=function(){return this.indentation--,this},Ff.prototype.add=function(t){const e=new Pf(t,this.indentation);return this.lines.push(e),this},Ff.prototype.addLines=function(t){const e=t.lines,i=e.length;for(let t=0;t<i;t++){const i=e[t],n=new Pf(i.text,i.indentation+this.indentation);this.lines.push(n)}},Ff.prototype.clear=function(){this.lines=[],this.indentation=0,this.indentSpaces=4},Ff.prototype.build=function(){const t=[];let e,i,n;const s=this.lines;for(e=0,n=s.length;e<n;e++){const n=s[e];let r="";for(i=0;i<n.indentation*this.indentSpaces;i++)r+=" ";t.push(r+n.text)}return t.join("\n")};const Df=/(function\s*)([a-zA-Z0-9_]+)?(\s*\([^\]]*\)\s*\{.*)/g,Of=function(){this.imports=[],this.methods={},this.functions=[],this.preable=new Ff};Of.prototype.addCode=function(t){this.preable.add(t)},Of.prototype.addMethod=function(t,e){this.methods[t]=e},Of.prototype.importFunction=function(t,e){this.functions.push({f:e,name:t})},Of.prototype.importScript=function(t){t=function(t){if(!function(t){return 0===t.search(Af)}(t)){let e;if(Ef)e=window;else if(If)e=self;else{if(!zf)throw new Error("Unknown environment");{let t=`${process.cwd()}/`.replace(/\\/g,"/");t=t.replace(/\/+/g,"/"),"/"!==t[0]&&(t=`/${t}`),e={location:{pathname:t,host:"",protocol:"file:"}}}}const i=e.location,n=i.pathname;let s;if(n.endsWith("/"))s=n.substring(0,n.length-1);else{const t=n.lastIndexOf("/");s=-1===t?"":n.substring(0,t)}t=i.protocol+"//"+i.host+s+"/"+t}return t}(t),this.imports.push(t)},Of.prototype.build=function(){const t=[];t.push("var globalScope = this;"),this.imports.forEach((function(e){t.push("globalScope.importScripts('"+e+"');")})),t.push(this.preable.build()),this.functions.forEach((function(e){const i=e.f.toString().replace(Df,`$1${e.name}$3`);t.push(i)})),t.push("var api = {};");for(let e in this.methods)if(this.methods.hasOwnProperty(e)){const i=this.methods[e],n=typeof i;let s;if("function"===n)s=i.toString();else{if("string"!==n)throw new Error(`Unsupported method type '${n}'`);s=i}t.push("api['"+e+"'] = "+s+";")}Array.prototype.push.apply(t,['function extractTransferables(obj, result) {\n if (typeof obj !== "object") {\n return; //not an object, skip\n } else if (obj instanceof ArrayBuffer) {\n result.push(obj);\n } else if (obj.buffer instanceof ArrayBuffer) {\n result.push(obj.buffer);\n } else if (obj instanceof ImageBitmap) {\n result.push(obj);\n } else {\n for (var i in obj) {\n if (obj.hasOwnProperty(i)) {\n extractTransferables(obj[i], result);\n }\n }\n }\n }',"globalScope.onmessage = function(event){"," var eventData = event.data;"," var requestId = eventData.id"," var methodName = eventData.methodName;"," var parameters = eventData.parameters;"," var method = api[methodName];"," function sendResult(result){"," var transferables = [];"," extractTransferables(result, transferables);"," globalScope.postMessage({methodName: methodName, id: requestId, result: result}, transferables);"," }"," function sendError(error){",' let stack = "";',' try{stack = error.stack.split("\\n")}catch(e){}'," globalScope.postMessage({methodName: methodName, id: requestId, error: {message: error.message, stack: stack }});"," }"," if(method === undefined){",' sendError(new Error("API named \'"+methodName+"\' was not found."));'," }else{"," try{"," method.apply(null,parameters).then(sendResult, sendError);"," }catch(e){"," sendError(e);"," }"," }","};"]);const e=function(t){const e="application/javascript";let i;if("object"==typeof window)if(void 0!==window.Blob)i=new Blob([t],{type:e});else{const e=window.BlobBuilder=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;void 0!==e&&(i=new e,i.append(t),i=i.getBlob())}return void 0!==i&&void 0!==URL.createObjectURL?URL.createObjectURL(i):`data:${e},${encodeURIComponent(t)}`}(t.join("\n"));return new Lf(e,this.methods)};class Rf extends Error{constructor(t){super(t)}}const kf=function(){return{uniforms:{normalMap:{type:"t",value:null},heightMap:{type:"t",value:null},world_size:{type:"v2",value:new bi(512,512)},rayLength:{type:"f",value:17}},defines:{NUM_SAMPLES:64,NUM_RINGS:7},vertexShader:["varying vec2 vUv;","void main() {","vUv = uv;","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["\n uniform sampler2D normalMap;\n uniform sampler2D heightMap;\n uniform float rayLength;\n uniform vec2 world_size;\n\n varying vec2 vUv;\n\n vec3 get(float x, float y){\n vec2 _uv = vUv.xy + vec2(x,y) / world_size;\n float h = texture2D(heightMap, _uv).x;\n return vec3( _uv.x * world_size.x, h, _uv.y * world_size.y );\n }\n \n float hash1( float n )\n {\n return fract( n*17.0*fract( n*0.3183099 ) );\n }\n \n float hash1( vec2 p )\n {\n p = 50.0*fract( p*0.3183099 );\n return fract( p.x*p.y*(p.x+p.y) );\n }\n \n // Non-sin based hash function, fast and has good randomness\n float hash12(vec2 p){\n vec3 p3 = fract(vec3(p.xyx) * .1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n }\n \n const float bias = 0.001;\n \n float pow2(float x){\n return x*x;\n }\n \n float getOcclusion(vec3 origin, vec3 normal, vec3 hit_position){\n vec3 viewDelta = hit_position - origin;\n \n float viewDistance = length( viewDelta );\n \n float vn = dot( normal, viewDelta );\n float a2 = (vn) / viewDistance - bias;\n float a1 = (1.0 + pow2( viewDistance ) );\n \n return max(0.0, a2) / a1;\n }\n \n const float PI2 = 6.28318530717958;\n const float kernelRadius = 100.0;\n \n const float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n const float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n \n float getAmbientOcclusion(vec3 world_position, vec3 world_normal){\n // jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/\n float angle = hash12( vUv ) * PI2;\n vec2 radius = vec2( rayLength * INV_NUM_SAMPLES );\n \n float occlusionSum = 0.0;\n float weightSum = 0.0;\n \n for( int i = 0; i < NUM_SAMPLES; i ++ ) {\n vec2 sampleUv = vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);\n \n angle += ANGLE_STEP;\n \n vec3 sample_pos = get(sampleUv.x, sampleUv.y);\n \n occlusionSum += getOcclusion(world_position, world_normal, sample_pos);\n weightSum += 1.0;\n }\n \n return occlusionSum/weightSum;\n }\n \n void main() {\n vec3 pos = get(0.0, 0.0);\n \n vec3 normal = texture2D( normalMap, vUv ).xzy;\n \n float occlusion = getAmbientOcclusion(pos, normal);\n \n float incident = 1.0 - occlusion;\n \n gl_FragColor = vec4(pow(incident,10.0), 0.0, 0.0, 1.0);\n }\n "].join("\n")}},Uf=new vs;Uf.setAttribute("position",new ls(new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),3)),Uf.setAttribute("uv",new ls(new Float32Array([0,0,2,0,0,2]),2));const Bf=" \n varying vec2 vUv;\n\n void main() {\n\n vUv = uv;\n \n gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );\n \n }";function Vf(t,e,i,n,s){void 0===s&&(s=new Uint8Array(e*i*4)),t.setSize(e,i);const r=new mr(-1,1,1,-1,0,1),a=new Zo;a.add(r);const o=new Ws(Object.assign({vertexShader:Bf},n));o.lights=!1,o.fog=!1,o.uniformsNeedUpdate=!0,o.needsUpdate=!0,o.side=P;const l=new Rs(Uf,o);a.add(l);const h=new Li(e,i,{generateMipmaps:!1,minFilter:Nt,stencilBuffer:!1,depthBuffer:!1}),c=t.getRenderTarget();t.setRenderTarget(h),t.render(a,r);const u=t.getContext();return u.readPixels(0,0,e,i,u.RGBA,u.UNSIGNED_BYTE,s),t.setRenderTarget(c),h.dispose(),o.dispose(),{array:s,graphics:t}}function Gf(t){switch(t){case 1:return te;case 2:return ie;case 3:return Jt;case 4:return Yt;default:throw new Error(`Unsupported channel count '${t}'`)}}function Wf(t,e){let i="";switch(t){case Nu.Uint8:i="8UI";break;case Nu.Uint16:i="16UI";break;case Nu.Uint32:i="32UI";break;case Nu.Int8:i="8I";break;case Nu.Int16:i="16I";break;case Nu.Int32:i="32I";break;case Nu.Float16:i="16F";break;case Nu.Float32:i="32F";break;case Nu.Float64:i="64F";break;default:throw new Error(`Unsupported data type '${t}'`)}let n="";switch(e){case 1:n="R";break;case 2:n="RG";break;case 3:n="RGB";break;case 4:n="RGBA";break;default:throw new Error(`Unsupported channel count '${e}'`)}return n+i}function Hf(t){const e=t.width,i=t.height,n=new wl(t.data,e,i);return n.wrapS=Ct,n.wrapT=Ct,n.generateMipmaps=!1,n.minFilter=Nt,n.magFilter=Et,n.flipY=!1,n.type=Bt,n.format=Gf(t.itemSize),n.internalFormat=Wf(Nu.Float32,t.itemSize),n.needsUpdate=!0,n}const jf=15,qf=`\n// bilateral filter, based on https://www.shadertoy.com/view/4dfGDH# and\n// http://people.csail.mit.edu/sparis/bf_course/course_notes.pdf\n// A bilateral filter is a non-linear, edge-preserving, and noise-reducing smoothing filter for images.\n// It replaces the intensity of each pixel with a weighted average of intensity values from nearby pixels.\n// This weight can be based on a Gaussian distribution. Crucially, the weights depend not only on\n// Euclidean distance of pixels, but also on the radiometric differences (e.g., range differences, such\n// as color intensity, depth distance, etc.). This preserves sharp edges.\n\nfloat normpdf3(in vec3 v, in float sigma) {\n return 0.39894 * exp(-0.5 * dot(v, v) / (sigma * sigma)) / sigma;\n}\n\n// filter size\n#define MSIZE ${jf}\nvarying vec2 vUv;\nuniform sampler2D source;\nuniform vec2 pixelOffset;\nuniform vec2 sigmas;\nuniform float bZnorm;\nuniform float kernel[MSIZE];\n\nvoid main(void) {\n\n // range sigma - controls blurriness based on a pixel distance\n float sigma = sigmas.x;\n \n // domain sigma - controls blurriness based on a pixel similarity (to preserve edges)\n float bSigma = sigmas.y;\n vec4 pixel = texture2D(source, vUv);\n vec4 accumulatedColor = vec4(0.0);\n float accumulatedFactor = 0.0;\n \n // read out the texels\n const int kSize = (MSIZE-1)/2;\n \n for (int i = -kSize; i <= kSize; ++i) {\n for (int j = -kSize; j <= kSize; ++j) {\n\n // sample the pixel with offset\n vec2 coord = vUv + vec2(float(i), float(j)) * pixelOffset;\n vec4 rgba = texture2D(source, coord);\n \n // bilateral factors\n float factor = kernel[kSize + j] * kernel[kSize + i];\n factor *= normpdf3(rgba.rgb - pixel.rgb, bSigma) * bZnorm;\n \n // accumulate\n accumulatedColor += factor * rgba;\n accumulatedFactor += factor;\n }\n }\n \n gl_FragColor = accumulatedColor / accumulatedFactor;\n}\n`;function Jf(t,e){return.39894*Math.exp(-.5*t*t/(e*e))/e}function Yf(t=10,e=.2){const i=1/Jf(0,e),n=new Float32Array(jf),s=Math.floor((jf-1)/2);for(let e=0;e<=s;e++){const i=Jf(e,t);n[s+e]=i,n[s-e]=i}return{uniforms:{source:{type:"t",value:null},pixelOffset:{type:"v2",value:new bi(1,1)},sigmas:{type:"v2",value:new bi(t,t)},bZnorm:{type:"f",value:i},kernel:{type:"f",value:n}},fragmentShader:qf}}const Xf=function(){return{uniforms:{heightMap:{type:"t",value:null},resolution:{type:"v2",value:new bi(512,512)}},vertexShader:["varying vec2 vUv;","void main() {","vUv = uv;","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform vec2 resolution;","uniform sampler2D heightMap;","#define sqrt2 1.41421356237;","varying vec2 vUv;","void main() {"," float uStep = 1.0/resolution.x;"," float vStep = 1.0/resolution.y;"," float top = texture2D( heightMap, vUv + vec2(0, -vStep)).x;"," float bottom = texture2D( heightMap, vUv + vec2(0, +vStep)).x;"," float left = texture2D( heightMap, vUv + vec2(-uStep, 0)).x;"," float right = texture2D( heightMap, vUv + vec2(+uStep, 0)).x;"," float dX = (right ) - ( left);"," float dY = ( bottom ) - ( top);"," float dZ = 2.0;"," vec3 n = normalize(vec3(dX, dY, dZ));"," gl_FragColor = vec4( n*0.5+0.5, 1.0 );","}"].join("\n")}};function Zf(t){return t/255-.5}function $f(){this.used=new Set}function Kf(t,e){if(1===t.itemSize){if(e.format!==te&&e.format!==Xt)throw new Error("itemSize is 1 and texture.format is not RedFormat")}else if(2===t.itemSize){if(e.format!==ie)throw new Error("itemSize is 2 and texture.format is not RGFormat")}else if(3===t.itemSize){if(e.format!==Jt)throw new Error("itemSize is 2 and texture.format is not RGBFormat")}else{if(4!==t.itemSize)throw new Error("Unsupported itemSize");if(e.format!==Yt)throw new Error("itemSize is 2 and texture.format is not RGBAFormat")}e.image.data!==t.data&&e.dispose(),e.image.data=t.data,e.image.width=t.width,e.image.height=t.height,e.needsUpdate=!0}$f.prototype.get=function(t){const e=document.createElement("canvas"),i=new Xo({alpha:!0,context:e.getContext("webgl2",{antialias:!0}),canvas:e});return this.used.add(i),i},$f.prototype.release=function(t){return!!this.used.has(t)&&(this.used.delete(t),t.forceContextLoss(),t.dispose(),t.domElement=null,!0)},$f.global=new $f;const Qf={BigEndian:!1,LittleEndian:!0};class tm{constructor(){this.endianness=Qf.BigEndian,this.position=0,this.length=0,this.capacity=0,this.data=new ArrayBuffer(0),this.dataView=new DataView(this.data),this.__data_uint8=new Uint8Array(0),this.__growFactor=1.1}get raw_bytes(){return this.__data_uint8}fromArrayBuffer(t){this.data=t,this.dataView=new DataView(t),this.__data_uint8=new Uint8Array(t),this.capacity=t.byteLength,this.length=this.capacity,this.position=0}trim(){return this.setCapacity(this.position),this}setCapacity(t){const e=this.__data_uint8,i=new Uint8Array(t),n=Math.min(i.length,e.length);i.set(e.subarray(0,n),0),this.data=i.buffer,this.__data_uint8=i,this.dataView=new DataView(this.data),this.capacity=t}ensureCapacity(t){if(this.capacity<t){const e=Math.ceil(Math.max(t,this.capacity*this.__growFactor,this.capacity+1024));this.setCapacity(e)}}readFloat32(){const t=this.dataView.getFloat32(this.position,this.endianness);return this.position+=4,t}readFloat64(){const t=this.dataView.getFloat64(this.position,this.endianness);return this.position+=8,t}readInt8(){const t=this.dataView.getInt8(this.position);return this.position+=1,t}readInt16(){const t=this.dataView.getInt16(this.position,this.endianness);return this.position+=2,t}readInt32(){const t=this.dataView.getInt32(this.position,this.endianness);return this.position+=4,t}readUint8(){const t=this.dataView.getUint8(this.position);return this.position+=1,t}readUint16(){const t=this.dataView.getUint16(this.position,this.endianness);return this.position+=2,t}readUint16LE(){const t=this.dataView.getUint16(this.position,Qf.LittleEndian);return this.position+=2,t}readUint16BE(){const t=this.dataView.getUint16(this.position,Qf.BigEndian);return this.position+=2,t}readUint24(){return this.endianness===Qf.BigEndian?this.readUint24BE():this.readUint24LE()}readUint24LE(){const t=this.dataView.getUint8(this.position),e=this.dataView.getUint8(this.position+1),i=this.dataView.getUint8(this.position+2);return this.position+=3,t|e<<8|i<<16}readUint24BE(){const t=this.dataView.getUint8(this.position),e=this.dataView.getUint8(this.position+1),i=this.dataView.getUint8(this.position+2);return this.position+=3,i|e<<8|t<<16}readUint32(){const t=this.dataView.getUint32(this.position,this.endianness);return this.position+=4,t}readUint32LE(){const t=this.dataView.getUint32(this.position,Qf.LittleEndian);return this.position+=4,t}readUint32BE(){const t=this.dataView.getUint32(this.position,Qf.BigEndian);return this.position+=4,t}readUint8Array(t,e,i){for(let n=0;n<i;n++)t[n+e]=this.readUint8()}readUint16Array(t,e,i){for(let n=0;n<i;n++)t[n+e]=this.readUint16()}readUint32Array(t,e,i){for(let n=0;n<i;n++)t[n+e]=this.readUint32()}readInt8Array(t,e,i){for(let n=0;n<i;n++)t[n+e]=this.readInt8()}readInt16Array(t,e,i){for(let n=0;n<i;n++)t[n+e]=this.readInt16()}readInt32Array(t,e,i){for(let n=0;n<i;n++)t[n+e]=this.readInt32()}readFloat32Array(t,e,i){for(let n=0;n<i;n++)t[n+e]=this.readFloat32()}readFloat64Array(t,e,i){for(let n=0;n<i;n++)t[n+e]=this.readFloat64()}writeFloat32Array(t,e,i){for(let n=0;n<i;n++)this.writeFloat32(t[n+e])}writeFloat32(t){const e=this.position+4;this.ensureCapacity(e),this.dataView.setFloat32(this.position,t,this.endianness),this.position=e}writeFloat64(t){const e=this.position+8;this.ensureCapacity(e),this.dataView.setFloat64(this.position,t,this.endianness),this.position=e}writeInt8(t){const e=this.position+1;this.ensureCapacity(e),this.dataView.setInt8(this.position,t),this.position=e}writeInt16(t){const e=this.position+2;this.ensureCapacity(e),this.dataView.setInt16(this.position,t,this.endianness),this.position=e}writeInt32(t){const e=this.position+4;this.ensureCapacity(e),this.dataView.setInt32(this.position,t,this.endianness),this.position=e}writeUint8(t){const e=this.position+1;this.ensureCapacity(e),this.dataView.setUint8(this.position,t),this.position=e}writeUint8Array(t,e,i){for(let n=0;n<i;n++)this.writeUint8(t[e+n])}writeUint16(t){const e=this.position+2;this.ensureCapacity(e),this.dataView.setUint16(this.position,t,this.endianness),this.position=e}writeUint16BE(t){const e=this.position+2;this.ensureCapacity(e),this.dataView.setUint16(this.position,t,Qf.BigEndian),this.position=e}writeUint16LE(t){const e=this.position+2;this.ensureCapacity(e),this.dataView.setUint16(this.position,t,Qf.LittleEndian),this.position=e}writeUint16Array(t,e,i){for(let n=0;n<i;n++)this.writeUint16(t[e+n])}writeUint24(t){this.endianness===Qf.BigEndian?this.writeUint24BE(t):this.writeUint24LE(t)}writeUint24BE(t){const e=this.position+3;this.ensureCapacity(e);const i=255&t,n=t>>8&255,s=t>>16&255;this.dataView.setUint8(this.position,s),this.dataView.setUint8(this.position+1,n),this.dataView.setUint8(this.position+2,i),this.position=e}writeUint24LE(t){const e=this.position+3;this.ensureCapacity(e);const i=255&t,n=t>>8&255,s=t>>16&255;this.dataView.setUint8(this.position,i),this.dataView.setUint8(this.position+1,n),this.dataView.setUint8(this.position+2,s),this.position=e}writeUintVar(t){let e=!0;for(;e||0!==t;){e=!1;let i=127&t;(t>>=7)>0&&(i|=128),this.writeUint8(i)}}readUintVar(){let t=!0,e=0,i=0;for(;t;){let n=this.readUint8();t=0!=(128&n),e|=(127&n)<<i,i+=7}return e}writeUint32(t){const e=this.position+4;this.ensureCapacity(e),this.dataView.setUint32(this.position,t,this.endianness),this.position=e}writeUint32BE(t){const e=this.position+4;this.ensureCapacity(e),this.dataView.setUint32(this.position,t,Qf.BigEndian),this.position=e}writeUint32LE(t){const e=this.position+4;this.ensureCapacity(e),this.dataView.setUint32(this.position,t,Qf.LittleEndian),this.position=e}writeUint32Array(t,e,i){for(let n=0;n<i;n++)this.writeUint32(t[e+n])}writeBytes(t,e,i){const n=e+i,s=this.position,r=s+i;if(this.ensureCapacity(r),0===e&&t.length===i)this.__data_uint8.set(t,s);else if("function"==typeof t.subarray)this.__data_uint8.set(t.subarray(e,n),s);else for(let n=0;n<i;n++)this.__data_uint8[s+n]=t[e+n];this.position=r}readBytes(t,e,i){const n=this.position,s=n+i,r=this.__data_uint8;i<128?Rd(r,n,t,e,i):t.set(r.subarray(n,s),e),this.position=s}writeUTF8String(t){if(null===t)return void this.writeUint32(4294967295);if(void 0===t)return void this.writeUint32(4294967294);let e=0;const i=t.length;if(i>=4294967294)throw new Error("String is too long");this.writeUint32(i);const n=this.position;let s=n,r=Math.max(32,i+(i>>1)+7);this.ensureCapacity(r+s);let a=this.__data_uint8;for(;e<i;){let o=t.charCodeAt(e++);if(o>=55296&&o<=56319){if(e<i){const i=t.charCodeAt(e);56320==(64512&i)&&(++e,o=((1023&o)<<10)+(1023&i)+65536)}if(o>=55296&&o<=56319)continue}if(s+4>this.capacity&&(r+=8,r*=1+e/i*2,r=r>>3<<3,this.ensureCapacity(r+n),a=this.__data_uint8),0!=(4294967168&o)){if(0==(4294965248&o))a[s++]=o>>6&31|192;else if(0==(4294901760&o))a[s++]=o>>12&15|224,a[s++]=o>>6&63|128;else{if(0!=(4292870144&o))continue;a[s++]=o>>18&7|240,a[s++]=o>>12&63|128,a[s++]=o>>6&63|128}a[s++]=63&o|128}else a[s++]=o}this.position=s}readUTF8String(){const t=this.readUint32();if(4294967295===t)return null;if(4294967294===t)return;const e=this.__data_uint8;let i="",n=this.position,s=0;for(;n<this.capacity&&s<t;){const t=e[n++];let r;if(0===t)break;0==(128&t)?r=t:192==(224&t)?r=(31&t)<<6|63&e[n++]:224==(240&t)?r=(31&t)<<12|(63&e[n++])<<6|63&e[n++]:240==(248&t)&&(r=(7&t)<<18|(63&e[n++])<<12|(63&e[n++])<<6|63&e[n++],r>65535&&(r-=65536,i+=String.fromCharCode(r>>>10&1023|55296),s++,r=56320|1023&r)),s++,i+=String.fromCharCode(r)}return this.position=n,i}writeASCIIString(t){const e=t.length,i=this.position,n=i+e;this.ensureCapacity(n);for(let n=0;n<e;n++){const e=t.charCodeAt(n);if(e>255)throw new Error(`Character ${String.fromCharCode(e)} can't be represented by a US-ASCII byte.`);this.__data_uint8[i+n]=e}this.position=n}readASCIICharacters(t,e=!1){let i="";for(let n=0;n<t;n++){const t=this.readUint8();if(e&&0===t)break;i+=String.fromCharCode(t)}return i}static fromArrayBuffer(t){const e=new tm;return e.fromArrayBuffer(t),e}static copyUTF8String(t,e){const i=t.readUTF8String();return e.writeUTF8String(i),i}static copyUintVar(t,e){const i=t.readUintVar();return e.writeUintVar(i),i}static copyUint8(t,e){const i=t.readUint8();return e.writeUint8(i),i}static copyUint16(t,e){const i=t.readUint16();return e.writeUint16(i),i}static copyUint32(t,e){const i=t.readUint32();return e.writeUint32(i),i}static copyFloat32(t,e){const i=t.readFloat32();return e.writeFloat32(i),i}static copyFloat64(t,e){const i=t.readFloat64();return e.writeFloat64(i),i}static copyBytes(t,e,i){const n=new Uint8Array(i);return t.readBytes(n,0,i),e.writeBytes(n,0,i),n}}const em={[Nu.Uint8]:0,[Nu.Uint16]:1,[Nu.Uint32]:2,[Nu.Int8]:3,[Nu.Int16]:4,[Nu.Int32]:5,[Nu.Float32]:6,[Nu.Float64]:7,[Nu.Float16]:8},im={[Nu.Uint8]:1,[Nu.Uint16]:2,[Nu.Uint32]:4,[Nu.Uint64]:8,[Nu.Int8]:1,[Nu.Int16]:2,[Nu.Int32]:4,[Nu.Int64]:8,[Nu.Float16]:2,[Nu.Float32]:4,[Nu.Float64]:8};let nm=0;class sm{constructor(){this.id=nm++,this.flags=0,this.gridScale=1,this.gridTransform=new Cf,this.gridTransformKind=1,this.resolution=4,this.size=new wd(0,0),this.preview=new qp,this.clouds=new Wd,this.clouds.enabled=!0,this.heightMapURL=null,this.heightRange=0,this.splat=new Tf,this.samplerHeight=Vu.float32(1,1,1),this.heightTexture=new wl(this.samplerHeight.data,this.samplerHeight.width,this.samplerHeight,te,Bt),this.heightTexture.wrapS=Ct,this.heightTexture.wrapT=Ct,this.heightTexture.generateMipmaps=!1,this.heightTexture.minFilter=Nt,this.heightTexture.magFilter=Et,this.heightTexture.flipY=!1,this.heightTexture.internalFormat="R32F",this.layers=new pf,this.material=new wf({}),this.frustumCulled=!0,this.__transform_matrix=gu(),this.overlay=new Bd(this.size),this.bvh=new vd,this.__buildWorker=function(){const t=new Of;return t.importScript("bundle-worker-terrain.js"),t.addCode("\n function useSampler(callback) {\n if (globalScope.samplerHeight !== undefined) {\n callback(globalScope.samplerHeight);\n } else {\n if (globalScope.useSampleCallbacks === undefined) {\n globalScope.useSampleCallbacks = [callback];\n } else {\n globalScope.useSampleCallbacks.push(callback);\n }\n }\n }\n "),t.addMethod("computeHeightRange",(function(){return new Promise((function(t,e){useSampler((function(e){const i=e.computeMin(),n=e.computeMax();t({min:i.value,max:n.value})}))}))})),t.addMethod("setHeightSampler",(function(t,e,i,n){return new Promise((function(s,r){globalScope.samplerHeight=new Lib.Sampler2D(t,e,i,n),void 0!==globalScope.useSampleCallbacks&&globalScope.useSampleCallbacks.forEach((function(t){t(globalScope.samplerHeight)})),s()}))})),t.addMethod("buildTile",(function(t,e,i,n,s){return new Promise((function(r,a){useSampler((function(o){try{const a=Lib.BufferedGeometryArraysBuilder.build(o,t,e,i,n,s);Lib.tensionOptimizeUV(a.vertices,a.uvs,a.indices,21);const l=Lib.BinaryBVHFromBufferGeometry.buildUnsorted(a.vertices,a.indices);r({geometry:a,bvh:l})}catch(t){a(t)}}))}))})),t.build()}(),this.__tiles=new Wp({material:this.material,buildWorker:this.__buildWorker}),this.__tiles.tileSize.set(rm,rm),this.__tiles.material.set(this.material),this.__assetManager=null,this.__legacyMaterialSpec=null,this.__legacyHeightSamplerURL=null,this.lightMapURL=null,this.__material_reference=null,this.initialize()}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}link(t){if(this.getFlag(2))return;this.startBuildService();const e=t.getMaterialManager().obtain(this.material);this.__material_reference=e;const i=e.getValue();this.clouds.addMaterial(i),this.__tiles.material.set(i),this.updateMaterial(),i.uniforms.diffuseMaps.value=this.layers.texture,this.setFlag(2)}unlink(){if(!this.getFlag(2))return;this.stopBuildService();const t=this.__material_reference.getValue();this.clouds.removeMaterial(t),this.__material_reference.release(),this.__tiles.dispose(),this.splat.dispose(),this.layers.dispose(),this.heightTexture.dispose(),this.clearFlag(2)}dispose(){if(this.getFlag(2))throw new Rf("component is linked, must be unlinked first")}initialize(){const t=this.overlay,e=this.material.uniforms;e.diffuseGridOverlayMap.value=t.texture,e.gridBorderWidth.value=t.borderWidth.getValue();const i=this.size;t.size.onChanged.add(((t,n)=>{e.gridResolution.value.set(i.x,i.y)})),t.borderWidth.onChanged.add((t=>{e.gridBorderWidth.value=t})),t.tileImage.onChanged.add(this.updateTileImage,this)}async updateTileImage(){const t=this.overlay.tileImage.getValue(),e=this.__assetManager;if(null===e)return;const i=await e.promise(t,Jp.Texture);if(t!==this.overlay.tileImage.getValue())return;const n=i.create();n.minFilter=Nt,n.magFilter=Nt,n.generateMipmaps=!1,this.material.uniforms.diffuseGridOverlaySprite.value=n}update(t){this.clouds.update(t)}sampleHeight(t,e,i,n,s){const r=new lp;this.raycastVerticalFirstSync(r,t,e)?i(r.position.y):n()}raycastFirstSync(t,e,i,n,s,r,a){return this.__tiles.raycastFirstSync(t,e,i,n,s,r,a)}raycast(t,e,i,n){throw new Error("Deprecated, use raycastFirstSync instead")}raycastVertical(t,e,i,n,s){throw new Error("Deprecated, use raycastVerticalFirstSync instead")}raycastVerticalFirstSync(t,e,i){return this.__tiles.raycastVerticalFirstSync(t,e,i)}projectPointsVertical(t,e,i){const n=this;let s=0;const r=t.length,a=[];function o(){++s>=r&&(function(t,e){const i=t.length-1,n=e.length;for(let s=0;s<n;s++){const n=e[s];let r=0,a=0;n>0&&(r+=t[n-1].y,a++),n<i&&(r+=t[n+1].y,a++),a>0&&(t[n].y=r/a)}}(t,a),e(t))}function l(e){const s=t[e];n.sampleHeight(s.x,s.z,(function(t){s.y=t,o()}),(function(){a.push(e),o()}),i)}if(0===r)e(t);else for(let t=0;t<r;t++)l(t)}mapGridPoints(t,e,i,n){const s=this,r=t.length;for(let i=0;i<r;i++){const n=t[i],r=e[i];s.mapPointGrid2World(n.x,n.y,r)}this.projectPointsVertical(e,i,n)}mapPointGrid2World(t,e,i){const n=this.gridTransform,s=t*n.scale_x+n.offset_x,r=e*n.scale_y+n.offset_y;i.set(s,i.y,r)}mapPointWorld2Grid(t,e){const i=this.gridTransform,n=(t.x-i.offset_x)/i.scale_x,s=(t.z-i.offset_y)/i.scale_y;e.set(n,s)}promiseAllTiles(){const t=this.__tiles,e=[];return t.traverse((function(i){const n=i.gridPosition.x,s=i.gridPosition.y,r=t.obtain(n,s);e.push(r)})),Promise.all(e)}updateMaterial(){let t=this.material;null!==this.__material_reference&&null!==this.__material_reference.getValue()&&(t=this.__material_reference.getValue());const e=t.uniforms;e.diffuseMaps.value=this.layers.texture,e.splatWeightMap.value=this.splat.weightTexture,e.splatLayerCount.value=this.layers.count(),e.materialScalesMap.value=this.layers.scalesTexture,e.splatResolution.value.set(this.splat.size.x,this.splat.size.y),e.gridResolution.value.set(this.size.x,this.size.y),e.uGridTransform.value.set(this.gridTransform.scale_x,this.gridTransform.scale_y,this.gridTransform.offset_x,this.gridTransform.offset_y),this.layers.updateLayerScales(this.size.x*this.gridScale,this.size.y*this.gridScale),t.uniformsNeedUpdate=!0}set transform(t){yu(this.__transform_matrix,t),this.__tiles.transform=t}get transform(){return this.__transform_matrix}addLayer(t){const e=this.layers,i=e.addLayer(t);return this.splat.addWeightLayer(),this.getFlag(1)&&(e.buildTexture(),t.loadTextureData(this.__assetManager).then((()=>{e.get(i)===t&&e.writeLayerDataIntoTexture(i)})),this.updateMaterial()),i}async updateHeights(){this.updateHeightTexture(),await this.updateWorkerHeights()}updateHeightTexture(){const t=this.samplerHeight,e=this.heightTexture,i=e.image;i.data!==t.data&&(e.dispose(),i.data=t.data),i.width=t.width,i.height=t.height,e.needsUpdate=!0}buildFromLegacy(t){const e=function(t,e,i){return new Promise((function(n,s){if(void 0===e){const t=new Vu(new Uint8Array(1),1,1,1);n(t)}else e.endsWith(".bin")?i.get(e,Jp.ArrayBuffer,(function(t){const e=t.create(),i=new tm;i.writeBytes(new Uint8Array(e),0,e.length),i.position=0;const s=function(t){const e=t.readUint32(),i=t.readUint32(),n=t.readUint8(),s=t.readUint8(),r=function(t,e,i){const n=t.endianness;t.endianness=Qf.LittleEndian;let s=null;switch(e){case Nu.Uint8:s=new Uint8Array(i),t.readUint8Array(s,0,i);break;case Nu.Uint16:s=new Uint16Array(i),t.readUint16Array(s,0,i);break;case Nu.Uint32:s=new Uint32Array(i),t.readUint32Array(s,0,i);break;case Nu.Int8:s=new Int8Array(i),t.readInt8Array(s,0,i);break;case Nu.Int16:s=new Int16Array(i),t.readInt16Array(s,0,i);break;case Nu.Int32:s=new Int32Array(i),t.readInt32Array(s,0,i);break;case Nu.Float32:s=new Float32Array(i),t.readFloat32Array(s,0,i);break;case Nu.Float64:s=new Float64Array(i),t.readFloat64Array(s,0,i);break;default:s=null}if(t.endianness=n,null===s)throw new TypeError(`Unsupported data type ${e}`);return s}(t,function(t){for(let e in em)if(em[e]===t)return e;throw new Error(`No type found with index ${t}`)}(s),e*i*n);return new Vu(r,n,e,i)}(i);n(s)}),s):i.get(e,Jp.Image,(function(e){const i=e.create(),s=i.width,r=i.height,a=function(t,e,i,n,s){n=n||1,s=s||0;const r=e*i,a=new Float32Array(r),o=n/765;for(let e=0;e<r;e++){const i=4*e,n=t[i],r=t[i+1],l=t[i+2];a[e]=(n+r+l)*o+s}return new Vu(a,1,e,i)}(i.data,s,r,t,-t/2);n(a)}),s)}))}(this.heightRange,this.__legacyHeightSamplerURL,t),i=this.__legacyMaterialSpec,n=function(t,e,i,n,s){const r=t.textures.diffuse;function a(t,n){const s=e.layers.get(n);return s.textureDiffuseURL=t,s.loadTextureData(i)}const o=r.length;for(let i=0;i<o;i++){const i=new sf,r=s*(n.x/n.y),a=s;i.size.set(r/t.repeat.x,a/t.repeat.y),i.diffuse=Vu.uint8(3,e.resolution.x,e.resolution.y),e.addLayer(i)}e.buildTexture();const l=[];for(let t=0;t<o;t++){const e=a(r[t],t);l.push(e)}return Promise.all(l).then((()=>{!function(){let t=0,i=0;for(let n=0;n<o;n++){const s=e.get(n);t=Eu(s.diffuse.width,t),i=Eu(s.diffuse.height,i)}e.resolution.set(t,i),e.buildTexture()}(),e.writeAllLayersDataIntoTexture()}))}(i,this.layers,t,this.size,this.gridScale),s=function(t,e,i){const n=t.textures.splat,s=n.length;function r(t,n){return i.promise(t,Jp.Image).then((t=>{const i=t.create(),s=Eu(i.width,4),r=Eu(i.height,4),a=new Vu(i.data,4,i.width,i.height);e.resize(s,r,4),e.writeLayerFromSampler(a,n,0)}))}const a=[];for(let t=0;t<s;t++){const e=r(n[t],t);a.push(e)}return Promise.all(a).then((()=>{const t=e.materialData,i=t.length;for(let e=0;e<i;e+=4)t[e]=0,t[e+1]=1,t[e+2]=2,t[e+3]=3;e.materialTexture.needsUpdate=!0,e.weightTexture.needsUpdate=!0}))}(i,this.splat,t);Promise.all([n,s]).then((()=>{this.updateMaterial()})),e.then((t=>{this.samplerHeight=t,this.updateHeightTexture(),this.updateWorkerHeights()}))}startBuildService(){this.__buildWorker.start(),this.updateWorkerHeights()}async updateWorkerHeights(){const t=this.samplerHeight,e=this.__buildWorker;return await e.setHeightSampler(t.data,t.itemSize,t.width,t.height),await e.computeHeightRange().then((({min:t,max:e})=>{this.__tiles.setHeightRange(t,e)}))}stopBuildService(){this.__buildWorker.stop()}buildGridTransform(){0===this.gridTransformKind?(this.gridTransform.scale_x=this.size.x/(this.size.x-1)*this.gridScale,this.gridTransform.scale_y=this.size.y/(this.size.y-1)*this.gridScale,this.gridTransform.offset_x=0,this.gridTransform.offset_y=0):1===this.gridTransformKind&&(this.gridTransform.scale_x=this.gridScale,this.gridTransform.scale_y=this.gridScale,this.gridTransform.offset_x=this.gridScale/2,this.gridTransform.offset_y=this.gridScale/2)}build(t){this.getFlag(1)||(this.__assetManager=t,this.buildGridTransform(),this.bvh.reset(),this.bvh.setNegativelyInfiniteBounds(),this.overlay.size.copy(this.size),this.__tiles.totalSize.copy(this.size),this.__tiles.scale.set(this.gridScale,this.gridScale),this.__tiles.resolution.set(this.resolution),null!==this.__legacyMaterialSpec?this.buildFromLegacy(t):(this.updateHeightTexture(),this.updateWorkerHeights(),this.layers.buildTexture(),this.layers.loadTextureData(t)),null!==this.lightMapURL&&(this.material.aoMap=!0,this.material.needsUpdate=!0,t.promise(this.lightMapURL,Jp.Texture).then((t=>{this.material.uniforms.aoMap.value=t.create(),this.material.uniforms.aoMapIntensity.value=.7}))),this.pMaterial=Promise.resolve(this.material),this.pTiles=Promise.resolve(this.__tiles),this.__tiles.initialize(),this.updateMaterial(),this.updateTileImage(),this.setFlag(1))}get tiles(){return this.__tiles}get aoMap(){const t=this.__material_reference;if(null===t)return null;const e=t.getValue();return null===e?null:e.uniforms.aoMap.value}buildLightMap(t=4){const e=this.size.x,i=this.size.y,n=y(e,16,2048),s=y(i,16,2048),r=new Uint8Array(n*s),a=new wl(r,n,s,te,Ft);return a.wrapT=Ct,a.wrapS=Ct,a.minFilter=Et,a.magFilter=Nt,a.flipY=!1,a.anisotropy=4,function({texture:t,heightSampler:e,resolution:i=new wd(t.image.width,t.image.height),rayLength:n=11,worldSize:s=i}){const r=$f.global.get(),a=function(t,e){const i=function(t,e){const i=e.width,n=e.height,s=Hf(e),r=new Xf;r.uniforms.heightMap.value=s,r.uniforms.resolution.value.set(i,n);const a=function(t){const e=t.length,i=Math.floor(e/4),n=new Float32Array(3*i);let s;for(let e=0;e<i;e++){const i=4*e,r=3*e;let a=Zf(t[i]),o=Zf(t[i+1]),l=Zf(t[i+2]);s=Math.sqrt(a*a+o*o+l*l),a/=s,o/=s,l/=s,n[r]=a,n[r+1]=o,n[r+2]=l}return n}(Vf(t,i,n,r).array);return new Vu(a,3,i,n)}(t,e);return Promise.resolve(i)}(r,e),o=function({renderer:t,pSamplerNormal:e,samplerHeight:i,resolution:n,wordSize:s=n,rayLength:r}){return new Promise((function(a,o){Promise.all([e]).then((function(e){const o=e[0],l=function(t,e,i,n,s=new bi(e.width,e.width),r=17){const a=n.x,o=n.y,l=Hf(i),h=Hf(e),c=new kf;c.uniforms.heightMap.value=h,c.uniforms.normalMap.value=l,c.uniforms.world_size.value.set(s.x,s.y),c.uniforms.rayLength.value=r;const u=Vf(t,a,o,c),d=new Yf(2);d.uniforms.source.value=function(t,e,i){const n=new wl;return n.format=Yt,n.type=Ft,n.flipY=!1,n.image={data:t,width:e,height:i},n.wrapS=Ct,n.wrapT=Ct,n.repeat.set(1,1),n.needsUpdate=!0,n.anisotropy=4,n}(u.array,a,o),d.uniforms.pixelOffset.value.set(1/a,1/o);const p=Vf(t,a,o,d),f=new Vu(new Uint8ClampedArray(a*o),1,a,o),m=a*o;for(let t=0;t<m;t++)f.data[t]=p.array[4*t];return f}(t,i,o,s,n,r);a(l)}),o)}))}({renderer:r,pSamplerNormal:a,samplerHeight:e,resolution:i,rayLength:n,worldSize:s}),l=o.then((e=>{Kf(e,t)}));return Promise.all([a,o]).finally((()=>{$f.global.release(r)})),l}({texture:a,heightSampler:this.samplerHeight,worldSize:new wd(e*this.gridScale,i*this.gridScale),resolution:new wd(e*t,i*t)}).then((()=>{const t=this.__material_reference;let e=this.material;return null!==t&&null!==t.getValue()&&(e=t.getValue()),e.aoMap=!0,e.needsUpdate=!0,e.uniforms.aoMap.value=a,e.uniforms.aoMapIntensity.value=.7,a}))}fromJSON({resolution:t=4,preview:e,size:i=1,scale:n=1,material:s,heights:r,layers:a,splat:o,overlayTileImage:l}={},h){this.clearFlag(1),void 0!==e&&this.preview.fromJSON(e),this.resolution=t,this.size.fromJSON(i),this.gridScale=n,this.materialDesc=s,void 0!==r?this.samplerHeight.fromJSON(r):(this.samplerHeight.data=new Float32Array(1),this.samplerHeight.width=1,this.samplerHeight.height=1,this.samplerHeight.itemSize=1,this.samplerHeight.version++),this.layers.fromJSON(a),this.splat.fromJSON(o),this.overlay.baseTileImage=void 0!==l?l:kd,this.build(h.assetManager)}toJSON(){return{size:this.size.toJSON(),scale:this.gridScale,resolution:this.resolution,material:this.materialDesc,preview:this.preview.toJSON(),heights:this.samplerHeight.toJSON(),layers:this.layers.toJSON(),splat:this.splat.toJSON(),overlayTileImage:this.overlay.baseTileImage}}}sm.typeName="Terrain";const rm=7;function am(t,e,i){let n=t;return n<e&&(n=e),n<i&&(n=i),n}function om(t,e,i,n,s,r,a,o,l,h,c,u,d){let p=0;return p+=m(t,e,i,s,r,a)>=n?1:-1,p+=m(t,e,i,o,l,h)>=n?1:-1,p+=m(t,e,i,c,u,d)>=n?1:-1,p}class lm extends qd{constructor(){super(),this.__geometry=null,this.__buffer_indices=null,this.__buffer_vertices=null,this.__buffer_vertex_stride=3,this.__buffer_position_offset=0,this.__root=null}setRoot(t){this.__root=t}setGeometry(t){this.geometry=t;const e=t.getIndex();this.__buffer_indices=e?e.array:null;const i=t.getAttribute("position");if(i.isInterleavedBufferAttribute){const t=i.data;this.__buffer_vertices=t.array,this.__buffer_vertex_stride=t.stride,this.__buffer_position_offset=i.offset}else this.__buffer_vertices=i.array,this.__buffer_vertex_stride=3,this.__buffer_position_offset=0}}class hm extends lm{constructor(){super(),this.planes=[],this.plane_count=0,this.__hit_count_in=0,this.__hit_count_out=0,this.__hit_count_intersect=0}reset(){this.__hit_count_in=0,this.__hit_count_intersect=0,this.__hit_count_out=0}getContainment(){return 0===this.__hit_count_out?this.__hit_count_intersect>0?0:1:this.__hit_count_intersect>0||this.__hit_count_in>0?0:-1}setPlanes(t){this.planes=t,this.plane_count=t.length}visit(t,e){const i=this.__root,n=i.data,s=i.binaryNodeCount,r=this.planes,a=this.plane_count;let o=!1;if(0===e){const e=3*(t/6-s),i=this.__buffer_indices,n=i[e],l=i[e+1],h=i[e+2],c=this.__buffer_vertices,u=this.__buffer_vertex_stride,d=this.__buffer_position_offset,p=n*u+d,f=l*u+d,m=h*u+d,_=c[p],g=c[p+1],y=c[p+2],v=c[f],x=c[f+1],w=c[f+2],b=c[m],S=c[m+1],M=c[m+2];for(let t=0;t<a;t++){const e=r[t],i=om(e.normal.x,e.normal.y,e.normal.z,e.constant,_,g,y,v,x,w,b,S,M);if(-3===i)return this.__hit_count_out++,!1;i<3&&(o=!0)}return o?this.__hit_count_intersect++:this.__hit_count_in++,!1}{const e=n[t],i=n[t+1],s=n[t+2],l=n[t+3],h=n[t+4],c=n[t+5];for(let t=0;t<a;t++){const n=r[t],a=Ku(n.normal.x,n.normal.y,n.normal.z,n.constant,e,i,s,l,h,c);if(-2===a)return this.__hit_count_out++,!1;0===a&&(o=!0)}return!!o||(this.__hit_count_in++,!1)}}}class cm extends lm{constructor(){super(),this.__nearest_distance=Number.POSITIVE_INFINITY,this.__nearest_hit=new lp,this.__temp_hit=new lp,this.__hit_found=!1,this.__ray_origin=new S,this.__ray_direction=new S}setRay(t,e,i,n,s,r){this.__ray_origin.set(t,e,i),this.__ray_direction.set(n,s,r)}reset(){this.__nearest_distance=Number.POSITIVE_INFINITY,this.__hit_found=!1}getNearestHit(){return this.__nearest_hit}isHitFound(){return this.__hit_found}visit(t,e){const i=this.__root,n=i.data,s=i.binaryNodeCount,r=this.__ray_origin,a=this.__ray_direction;if(0===e){const e=t/6-s,i=3*e,n=this.__buffer_indices;let o,l,h;null!==n?(o=n[i],l=n[i+1],h=n[i+2]):(o=i,l=i+1,h=i+2);const c=this.__buffer_vertices,u=this.__buffer_vertex_stride,d=this.__buffer_position_offset,p=o*u+d,f=l*u+d,m=h*u+d,_=c[p],g=c[p+1],y=c[p+2],v=c[f],x=c[f+1],w=c[f+2],b=c[m],S=c[m+1],M=c[m+2],T=this.__temp_hit;if(hp(T,r.x,r.y,r.z,a.x,a.y,a.z,_,g,y,v,x,w,b,S,M)){const t=T.position.distanceSqrTo(r);t<this.__nearest_distance&&(this.__nearest_hit.copy(T),this.__nearest_hit.index=e,this.__nearest_distance=t,this.__hit_found=!0)}return!1}return id(n[t],n[t+1],n[t+2],n[t+3],n[t+4],n[t+5],r.x,r.y,r.z,a.x,a.y,a.z)}}function um(t){if(!0!==t.isInterleavedBufferAttribute&&t.isBufferAttribute)return t;const e=t.data,i=e.array,n=e.stride,s=t.count,r=t.itemSize,a=s*r,o=t.offset,l=new i.constructor(a),h=new ls(l,r);h.normalized=t.normalized,h.name=t.name;let c=0,u=0;for(;c<s;c++)for(u=0;u<r;u++)l[c*r+u]=i[c*n+o+u];return h}class dm{constructor(t=104857600){this.cache=new Qp({maxWeight:t,keyHashFunction:t=>t.id,keyEqualityFunction:(t,e)=>t.id===e.id&&t.uuid===e.uuid,valueWeigher:t=>t.estimateByteSize()}),this.__visitor_clip=new hm,this.__visitor_raycast=new cm}set cache_size(t){this.cache.setMaxWeight(t)}get cache_size(){return this.cache.maxWeight}queryContainmentViaClippingPlanes(t,e){const i=this.__acquireBVH(t);return this.__visitor_clip.reset(),this.__visitor_clip.setGeometry(t),this.__visitor_clip.setPlanes(e),this.__visitor_clip.setRoot(i),i.traversePreOrderStack(this.__visitor_clip,0),this.__visitor_clip.getContainment()}queryRaycastNearest_array(t,e,i){return this.queryRaycastNearest_primitive(t,e,i[0],i[1],i[2],i[3],i[4],i[5])}queryRaycastNearest_primitive(t,e,i,n,s,r,a,o){let l;try{l=this.__acquireBVH(e)}catch(t){return!1}return this.__visitor_raycast.reset(),this.__visitor_raycast.setGeometry(e),this.__visitor_raycast.setRoot(l),this.__visitor_raycast.setRay(i,n,s,r,a,o),l.traversePreOrderStack(this.__visitor_raycast,0),!!this.__visitor_raycast.isHitFound()&&(t.copy(this.__visitor_raycast.getNearestHit()),!0)}queryRaycastNearest(t,e,i,n){return this.queryRaycastNearest_primitive(t,e,i.x,i.y,i.z,n.x,n.y,n.z)}__acquireBVH(t){const e=this.cache.get(t);if(null!==e)return e;const i=this.__buildBVH(t);return this.cache.put(t,i),i}__buildBVH(t){const e=t.getAttribute("position"),i=t.getIndex(),n=um(e).array;return null==i?function(t){const e=t.length/9,i=new ep;i.initialize(e);for(let n=0;n<e;n++){const e=3*n,s=3*e,r=3*(e+1),a=3*(e+2),o=t[s],l=t[s+1],h=t[s+2],c=t[r],u=t[r+1],d=t[r+2],p=t[a],f=t[a+1],m=t[a+2],_=Pp(o,c,p),g=Pp(l,u,f),y=Pp(h,d,m),v=am(o,c,p),x=am(l,u,f),w=am(h,d,m);i.writeLeaf(n,_,g,y,v,x,w)}return i.unsortedBuiltIntermediate(),i}(n):function(t,e){const i=e.length/3,n=new ep;n.initialize(i);for(let s=0;s<i;s++){const i=3*s,r=3*e[i],a=3*e[i+1],o=3*e[i+2],l=t[r],h=t[r+1],c=t[r+2],u=t[a],d=t[a+1],p=t[a+2],f=t[o],m=t[o+1],_=t[o+2],g=Pp(l,u,f),y=Pp(h,d,m),v=Pp(c,p,_),x=am(l,u,f),w=am(h,d,m),b=am(c,p,_);n.writeLeaf(s,g,y,v,x,w,b)}return n.unsortedBuiltIntermediate(),n}(n,um(i).array)}}dm.INSTANCE=new dm;const pm=new Float32Array(6),fm=new Float32Array(16),mm=new Float32Array(6);class _m{constructor(){this.geometry=null,this.material=null,this.depth_material=null,this.__bvh_leaf_id=-1,this.__bvh_tree=null,this.__bvh_aabb=new Float32Array(6),this.__entity=-1,this.__c_transform=null,this.mode=0,this.draw_method=0,this.flags=22}get __cached_object(){throw new Error("Deprecated")}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}hash(){return this.geometry.id^this.material.id^30&this.flags^this.draw_method<<16^this.mode<<12}equals(t){return this.geometry.id===t.geometry.id&&this.material.id===t.material.id&&this.draw_method===t.draw_method&&this.mode===t.mode&&(30&this.flags)==(30&t.flags)&&this.depth_material===t.depth_material}copy(t){this.geometry=t.geometry,this.material=t.material,this.depth_material=t.depth_material,this.draw_method=t.draw_method,this.mode=t.mode,this.flags=t.flags}clone(){const t=new _m;return t.copy(this),t}get entity(){return this.__entity}get transform(){return this.__c_transform.matrix}get bvh(){throw new Error("Deprecated, use #getBoundingBox method instead")}getBoundingBox(t){const e=this.__bvh_aabb;t.readFromArray(e)}from(t,e,i=0){this.geometry=t,this.material=e,this.mode=i,null===t.boundingBox&&t.computeBoundingBox()}static from(t,e,i){const n=new _m;return n.from(t,e,i),n}updateTransform(){this.update_bounds(),this.__bvh_tree.node_move_aabb(this.__bvh_leaf_id,this.__bvh_aabb)}update_bounds(){const t=this.geometry.boundingBox,e=t.min,i=e.x,n=e.y,s=e.z,r=t.max,a=r.x,o=r.y,l=r.z;pm[0]=i,pm[1]=n,pm[2]=s,pm[3]=a,pm[4]=o,pm[5]=l,sd(this.__bvh_aabb,pm,this.transform)}query_raycast_nearest(t,e,i){return vu(fm,i),!!up(mm,e,fm)&&!!dm.INSTANCE.queryRaycastNearest_array(t,this.geometry,mm)&&(t.applyMatrix4(i),!0)}}_m.typeName="ShadedGeometry",_m.serializable=!1;const gm=new rd;function ym(t,e){const i=e.entity.getComponent(_m);null!==i&&(i.getBoundingBox(gm),t.expandToFit(gm));const n=e.children,s=n.length;for(let e=0;e<s;e++)ym(t,n[e])}function vm(t,e){t.setNegativelyInfiniteBounds(),ym(t,e)}class xm{constructor(){this.__url=null,this.__node=null,this.__initial_bounds=new rd,this.flags=3}get url(){return this.__url}set url(t){t!==this.__url&&(this.__url=t)}getBoundingBox(t){return null!==this.__node&&(vm(t,this.__node),!0)}getUntransformedBoundingBox(t){t.copy(this.__initial_bounds)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}get castShadow(){return this.getFlag(1)}set castShadow(t){this.writeFlag(1,t)}get receiveShadow(){return this.getFlag(2)}set receiveShadow(t){this.writeFlag(2,t)}static fromURL(t){const e=new xm;return e.url=t,e.castShadow=!0,e.receiveShadow=!0,e}}function wm(t,e,i,n,s){let r=n,a=0;for(;a<s;a++){const n=t[e+a],s=i.indexOf(n);(-1===s||s>=r)&&(i[r]=n,r++)}return r-n}xm.typeName="SGMesh";class bm{constructor(){this.entityManager=null,this.state=new Hd(bm.State.INITIAL),this.dependencies=[],this.components_used=[]}get referenced_components(){const t=[];return wm(this.dependencies,0,t,t.length,this.dependencies.length),wm(this.components_used,0,t,t.length,this.components_used.length),t}startup(t,e,i){this.entityManager=t,e()}shutdown(t,e,i){e()}link(t,e){}unlink(t,e){}update(t){}}function Sm(t){return t.constructor.name}Object.defineProperties(bm.prototype,{componentClass:{configurable:!0,get:()=>null}}),bm.State={INITIAL:0,STARTING:1,RUNNING:2,STOPPING:3,STOPPED:4};class Mm extends Boolean{constructor(t){super(),this.__value=t,this.onChanged=new l}valueOf(){return this.__value}toString(){return this.__value.toString()}set(t){const e=this.__value;return e!==t&&(this.__value=t,this.onChanged.send2(t,e)),this}setTrue(){this.set(!0)}setFalse(){this.set(!1)}copy(t){this.set(t.getValue())}equals(t){return this.__value===t.__value}hashCode(){return this.__value?1:0}process(t){t(this.__value),this.onChanged.add(t)}getValue(){return this.__value}invert(){this.set(!this.__value)}toJSON(){return this.__value}fromJSON(t){this.set(t)}toBinaryBuffer(t){t.writeUint8(this.__value?1:0)}fromBinaryBuffer(t){const e=0!==t.readUint8();this.set(e)}}function Tm(t,e){this.__value=t,this.__validSet=e,this.onChanged=new l}Mm.FALSE=Object.freeze(new Mm(!1)),Mm.TRUE=Object.freeze(new Mm(!0)),Mm.prototype.isObservedBoolean=!0,Tm.prototype.getValidValueSet=function(){return this.__validSet},Tm.prototype.set=function(t){const e=this.__value;return e!==t&&(this.__value=t,this.onChanged.dispatch(t,e)),this},Tm.prototype.equals=function(t){return this.__value===t.__value},Tm.prototype.copy=function(t){this.set(t.getValue())},Tm.prototype.getValue=function(){return this.__value},Tm.prototype.invert=function(){this.set(!this.__value)},Tm.prototype.process=function(t){this.onChanged.add(t),t(this.__value,this.__value)},Tm.prototype.toJSON=function(){return this.__value},Tm.prototype.fromJSON=function(t){this.set(t)};const Cm=new pn;function Am(t,e,i=!0){i&&t.updateProjectionMatrix(),Cm.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),e.setFromProjectionMatrix(Cm)}const Em=new pn,zm=new S,Im=new S;function Nm(t,e){const i=zm,n=Im;i.copy(S.forward),n.copy(S.up),i.applyQuaternion(e),n.applyQuaternion(e),Em.lookAt(S.zero,i,n),t.setFromRotationMatrix(Em)}const Lm={Perspective:"perspective",Orthographic:"orthographic"};class Pm{constructor(){this.autoClip=!1,this.autoClipHysteresis=.33,this.object=null,this.fov=new Id(45),this.projectionType=new Tm(Lm.Perspective,Lm),this.active=new Mm(!1),this.__clip_far=100,this.__clip_near=.1}getReciprocalRotation(t,e){Nm(t,e)}get clip_far(){return this.__clip_far}set clip_far(t){this.__clip_far=t,null!==this.object&&(this.object.far=t)}get clip_near(){return this.__clip_near}set clip_near(t){this.__clip_near=t,null!==this.object&&(this.object.near=t)}updateMatrices(){const t=this.object;null!==t&&(t.updateProjectionMatrix(),t.updateMatrixWorld(!0),t.matrixWorldInverse.copy(t.matrixWorld),t.matrixWorldInverse.invert())}projectRay(t,e,i,n){Pm.projectRay(this.object,t,e,i,n)}copy(t){this.active.copy(t.active),this.projectionType.copy(t.projectionType),this.autoClip=t.autoClip}clone(){const t=new Pm;return t.copy(this),t}toJSON(){return{autoClip:this.autoClip,active:this.active.toJSON()}}fromJSON(t){this.autoClip=t.autoClip,"boolean"==typeof t.active?this.active.fromJSON(t.active):this.active.set(!1)}static projectRay(t,e,i,n,s){if(!t.isPerspectiveCamera&&!t.isOrthographicCamera)throw new Error("Unsupported camera type");var r,a,o,l;Dm.setFromMatrixPosition(t.matrixWorld.elements),Fm.set(e,i,.5),r=Fm,a=Fm,o=t.projectionMatrixInverse.elements,l=t.matrixWorld.elements,r.copy(a),r.applyMatrix4(o),r.applyMatrix4(l),Fm.sub(Dm),Fm.normalize(),n.copy(Dm),s.copy(Fm)}computeProjectionMatrix(t){const e=this.object;return null!==e&&(t.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),!0)}projectWorldPointOntoNearPlane(t,e,i,n){Am(this.object,Om);const s=Om.planes[0];Fm.set(t,e,i);const r=s.normal,a=-$u(t,e,i,r.x,r.y,r.z,s.constant);n.set(r.x*a+t,r.y*a+e,r.z*a+i)}}Pm.typeName="Camera",Pm.ProjectionType=Lm;const Fm=new S,Dm=new S,Om=new ir;function Rm(t,e,i){if("function"!=typeof e)throw new TypeError(`handler must be a function, instead was ${e}`);if("object"!=typeof t)throw new TypeError(`signal must be of an object, instead was ${t}`);if("function"!=typeof t.add)throw new TypeError(`signal.add must be a function, instead was ${t.add}`);this.signal=t,this.handler=e,this.context=i,this.linked=!1}function km(t,e,i){const n=t.object;if(null===n)return;const s=e/i;switch(t.projectionType.getValue()){case Pm.ProjectionType.Perspective:n.aspect=s;break;case Pm.ProjectionType.Orthographic:const t=n.right-n.left,e=n.bottom-n.top,i=s-t/e;if(i>0){const t=e*i;n.left-=t/2,n.right+=t/2}else if(i<0){const t=-e*i;n.top+=t/2,n.bottom-=t/2}}n.updateProjectionMatrix()}function Um(t){let e;switch(t.projectionType.getValue()){default:case Lm.Perspective:e=new js(t.fov.getValue(),1,1,50);break;case Lm.Orthographic:e=new mr(-10,10,20,-20,1,1)}return e.far=t.clip_far,e.near=t.clip_near,e}function Bm(t){t.updateMatrix();const e=t.children;for(let t=0,i=e.length;t<i;t++)Bm(e[t])}function Vm(t){Bm(t),t.updateMatrixWorld(!1)}function Gm(t){const e=t.object;null!==e&&(e.updateProjectionMatrix(),Vm(e))}function Wm(t,e,i){return e>=t&&t>=i||i>=t&&t>=e}function Hm(t){return t!==Number.NEGATIVE_INFINITY&&t!==Number.POSITIVE_INFINITY&&!Number.isNaN(t)}Rm.prototype.link=function(){this.linked||(this.linked=!0,this.signal.add(this.handler,this.context))},Rm.prototype.unlink=function(){this.linked&&(this.linked=!1,this.signal.remove(this.handler,this.context))};class jm{constructor(){this.camera=null,this.layers=null,this.hysteresis=.5,this.__frustum=new ir,this.near=0,this.far=0}__processLayer(t){t.state.visible&&t.computeNearFarClippingPlanes(this.__frustum,this.near,this.far,this.__updateClippingPlanes,this)}__updateClippingPlanes(t,e){t<this.near&&t!==Number.NEGATIVE_INFINITY&&(this.near=t),e>this.far&&e!==Number.POSITIVE_INFINITY&&(this.far=e)}compute(){const t=this.camera,e=this.hysteresis,i=t.near,n=t.far,s=e*Math.abs(n-i);Am(t,this.__frustum);const r=this.__frustum.planes[5],a=r.normal,o=t.position;r.constant=-m(o.x,o.y,o.z,a.x,a.y,a.z),this.far=Number.NEGATIVE_INFINITY,this.near=Number.POSITIVE_INFINITY,this.layers.traverse(this.__processLayer,this),this.near-=.001,this.far+=.001,(!Hm(this.near)||this.near<.5)&&(this.near=.5),(!Hm(this.far)||this.far<0)&&(this.far=100),Wm(this.near-i,0,s)&&(this.near=i),Wm(n-this.far,0,s)&&(this.far=n)}}const qm=new jm;class Jm extends bm{constructor(t,e){super(),this.scene=t,this.dependencies=[Pm,Au],this.entityManager=null,this.graphics=e,this.entityData=[];const i=this;this.__handleViewportResize=function(t,e){const n=i.entityManager;if(null===n)return;const s=n.dataset;null!==s&&s.traverseComponents(Pm,(function(i){km(i,t,e)}))},this.signalBindings=[]}link(t,e,i){null===t.object&&(t.object=Um(t));const n=this.graphics,s=n.viewport.size;function r(e,i,n){t.object.position.set(e,i,n),Gm(t)}function a(){const i=e.rotation;Nm(t.object.quaternion,i),t.object.rotation.setFromQuaternion(t.object.quaternion),Gm(t)}function o(){t.object=Um(t),km(t,s.x,s.y);const i=e.position;r(i.x,i.y,i.z),a(),l(t.active.getValue())}function l(e){e&&(n.camera=t.object)}km(t,s.x,s.y),this.scene.add(t.object);const h=e.position,c=e.rotation,u=[new Rm(h.onChanged,r),new Rm(c.onChanged,a),new Rm(t.projectionType.onChanged,o),new Rm(t.active.onChanged,l),new Rm(t.fov.onChanged,o)];u.forEach((t=>t.link())),this.entityData[i]=u,r(h.x,h.y,h.z),a(c.x,c.y,c.z,c.w),l(t.active.getValue())}unlink(t,e,i){const n=this.entityData;if(n.hasOwnProperty(i)){const t=n[i];void 0!==t&&t.forEach((t=>t.unlink())),delete n[i]}this.scene.remove(t.object)}startup(t,e,i){this.entityManager=t;const n=this.graphics;n.viewport.size.onChanged.add(this.__handleViewportResize);const s=new Rm(n.on.visibilityConstructionStarted,(function(){const e=t,i=n.layers,s=e.dataset;null!==s&&s.traverseComponents(Pm,(function(t){null!==t.object&&t.active.getValue()&&(void 0!==t.object.updateProjectionMatrix&&(t.object.updateProjectionMatrix(),t.object.updateMatrix(),t.object.updateMatrixWorld(!0)),!0===t.autoClip?function(t,e){const i=t.object,n=t.autoClipHysteresis;qm.hysteresis=n,qm.camera=i,qm.layers=e,qm.compute(),i.near===qm.near&&i.far===qm.far||(i.near=qm.near,i.far=qm.far,i.updateProjectionMatrix())}(t,i):(t.object.far=t.clip_far,t.object.near=t.clip_near))}))}));s.link(),this.signalBindings.push(s),e()}shutdown(t,e,i){this.graphics.viewport.size.onChanged.remove(this.__handleViewportResize),this.signalBindings.forEach((t=>t.unlink())),this.signalBindings.splice(0,this.signalBindings.length),e()}static traverseActiveCameras(t,e){t.traverseComponents(Pm,(function(t,i){t.active.getValue()&&e(t,i)}))}static getFirstActiveCamera(t){const e={entity:-1,component:void 0};return this.traverseActiveCameras(t,((t,i)=>{e.entity=i,e.component=t})),e}static getActiveFrustums(t,e){const i=[];null!==t&&t.traverseComponents(Pm,(function(t){if(t.active.getValue()){const e=t.object;if(null!==e){const t=new ir;Am(e,t),i.push(t)}}})),e(i)}}class Ym{constructor(){this.assetManager=null,this.engine=null}async link(t,e){this.assetManager=t,this.engine=e}async unlink(){}load(t,e,i,n){i("Not Implemented")}}const Xm={uniforms:{tDiffuse:{type:"t",value:null},opacity:{type:"f",value:1}},vertexShader:["varying vec2 vUv;","void main() {","vUv = uv;","gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );","}"].join("\n"),fragmentShader:["uniform float opacity;","uniform sampler2D tDiffuse;","varying vec2 vUv;","void main() {","vec4 texel = texture2D( tDiffuse, vUv );","gl_FragColor = opacity * texel;","}"].join("\n")};class Zm{constructor(t,e=0){this.factory=t,this.byteSize=e,this.dependencies=[],this.description=null}create(){return this.factory()}}Zm.prototype.byteSize=0;class $m extends Zm{constructor(t,e,i,n=4){super(),this.data=t,this.width=e,this.height=i,this.itemSize=n,this.byteSize=t.length}create(){return new Vu(this.data,this.itemSize,this.width,this.height)}}class Km{constructor(){this.kind="anonymous"}}const Qm=new Km;Km.default=Object.freeze(Qm);class t_ extends Ym{constructor({fetch_priority:t="auto"}={}){super(),this.__fetch_priority=t}load(t,e,i=console.error,n=Jd){const s=null!==this.assetManager?this.assetManager.crossOriginConfig:Km.default,r=new Headers,a=new Request(t,{credentials:"use-credentials"===s.kind?"include":"same-origin",headers:r});void 0!==a.priority&&(a.priority=this.__fetch_priority),fetch(a).then((function(t){if(200!==t.status&&0!==t.status)throw Error(`fetch for "${t.url}" responded with ${t.status}: ${t.statusText}`);if(t.status,"undefined"==typeof ReadableStream||void 0===t.body.getReader)return t;const e=t.body.getReader();t.headers.get("Content-Length");let i=0;const s=new ReadableStream({start(t){!function s(){e.read().then((({done:e,value:r})=>{e?t.close():(i+=r.byteLength,n(i,length),t.enqueue(r),s())}))}()}});return new Response(s)})).then((async function(t){const i=await t.arrayBuffer(),n=new Zm((function(){return i}),i.byteSize);e(n)})).catch(i)}}class e_{async decode(t){throw new Error("Unsupported Operation")}async test(t){return!0}}class i_ extends e_{constructor(...t){if(super(),this.children=t.slice(),this.children.length<1)throw new Error("At least one codec must be provided")}async test(t){const e=this.children,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(await i.test(t))return!0}return!1}async decode(t){const e=this.children,i=e.length,n=[];let s;for(let r=0;r<i;r++){const i=e[r];if(await i.test(t)){try{s=await i.decode(t)}catch(t){n.push({index:r,error:t});continue}return s}n.push({index:r,error:"Codec doesn't support this data"})}throw new Error(`All codecs failed, errors: ${n.map((t=>JSON.stringify(t))).join("\n")}`)}}class n_{constructor(t){this.worker=t,this.__request_count=0,this.__timeout=1e3,this.__decrement=this.decrement.bind(this),this.__terminate=this.terminate.bind(this),this.__pending_termination=-1}setTimeout(t){this.__timeout=t}terminate(){this.cancelScheduledTermination(),this.worker.stop()}cancelScheduledTermination(){this.__pending_termination>=0&&(clearInterval(this.__pending_termination),this.__pending_termination=-1)}scheduleTermination(t){this.cancelScheduledTermination(),this.__pending_termination=setTimeout(this.__terminate,t)}decrement(){this.__request_count--,this.__request_count<=0&&this.worker.isRunning()&&this.scheduleTermination(this.__timeout)}increment(){this.__request_count++,this.worker.isRunning()?this.__pending_termination>=0&&(clearInterval(this.__pending_termination),this.__pending_termination=-1):this.worker.start()}request(t,e){this.increment();const i=this.worker.$submitRequest(t,e);return i.finally(this.__decrement),i}}const s_=[137,80,78,71,13,10,26,10];class r_ extends e_{constructor(){super();const t=new Of;t.importScript("bundle-worker-image-decoder.js"),t.addMethod("decode",(function(t,e){return Lib.decode(t,e)})),this.worker=new n_(t.build()),this.worker.setTimeout(200)}async test(t){for(let e=0;e<s_.length;e++)if(t[e]!==s_[e])return!1;return!0}async decode(t){return await this.worker.request("decode",[t.buffer])}}class a_ extends e_{async decode(t){const e=new Image,i=URL.createObjectURL(new Blob([t]));e.src=i,await e.decode();const n=function(t){const e=t.width,i=t.height,n=document.createElement("canvas");n.width=e,n.height=i;const s=n.getContext("2d");return s.drawImage(t,0,0,e,i),s.getImageData(0,0,e,i).data}(e),s=e.width,r=e.height;return URL.revokeObjectURL(i),{data:n,width:s,height:r,itemSize:4,bitDepth:8}}}const o_="/";function l_(t){if("string"!=typeof t)throw new Error("path is not a string");const e=function(t){if("string"!=typeof t)throw new Error("path is not a string");const e=t.lastIndexOf(o_);return-1!==e?t.substring(e+1):t}(t),i=e.lastIndexOf(".");return-1!==i?e.substring(i+1):null}const h_="arraybuffer";class c_ extends Ym{constructor(){super(),this.decoder=new i_(new r_,new a_)}async link(t,e){void 0===t.getLoaderByType(h_)&&t.registerLoader(h_,new t_),super.link(t,e)}async __decode_via_worker(t){const e=(await this.assetManager.promise(t,h_)).create();return await this.decoder.decode(new Uint8Array(e))}async __standard(t){const e=await this.__decode_via_worker(t);let i;const n=e.bitDepth;switch(n){case 8:i=new Uint8Array(e.data);break;case 16:i=new Uint16Array(e.data);break;default:throw new Error(`Unsupported bit depth '${n}'. path='${t}'`)}return new $m(i,e.width,e.height,e.itemSize)}load(t,e,i,n){"dds"===l_(t)?this.assetManager.get(t,Jp.Texture,(t=>{const i=t.create(),n=function(t,e,i,n=!0){if(void 0===e||void 0===i){const n=t.image;null!=n?(void 0===e&&(e="number"==typeof n.width?n.width:512),void 0===i&&(i="number"==typeof n.height?n.height:512)):(void 0===e&&(e=512),void 0===i&&(i=512))}const s=$f.global.get({});s.getContext().getExtension("WEBGL_compressed_texture_s3tc");const r=Vf(s,e,i,{vertexShader:Xm.vertexShader,fragmentShader:Xm.fragmentShader,uniforms:{tDiffuse:{value:t,type:"t"},opacity:{value:1}}});return $f.global.release(s),n&&function(t,e,i,n=4){const s=e*n;let r,a,o,l=0;const h=i>>1;for(;l<h;l++){const e=(i-l-1)*s,n=l*s;for(let i=0;i<s;i++)a=n+i,o=e+i,r=t[a],t[a]=t[o],t[o]=r}}(r.array,e,i),new Vu(r.array,4,e,i)}(i);i.dispose();const s=new $m(n.data,n.width,n.height,n.itemSize);e(s)}),i,n):this.__standard(t).then(e,i)}}function u_(t,e){if(!t.isBuilt&&!t.isBuildInProgress){const i=t.gridPosition;e.build(i.x,i.y,Jd,Jd)}}class d_ extends bm{constructor(t,e){if(super(),void 0===t)throw new Error("No GraphicsEngine supplied");if(void 0===e)throw new Error("No AssetManager supplied");this.graphics=t,this.dependencies=[sm],this.assetManager=e,this.gridScaleX=1,this.gridScaleY=1,this.renderLayer=null,this.bvh=null,this.__time_delta=0}mapPointGrid2World(t,e,i){const n=t*this.gridScaleX,s=i.y,r=e*this.gridScaleY;i.set(n,s,r)}async startup(t,e,i){this.entityManager=t,this.renderLayer=this.graphics.layers.create("terrain-system"),this.renderLayer.extractRenderable=function(t){return t.mesh},this.bvh=this.renderLayer.bvh;const n=this.assetManager;n.hasLoaderForType("image")||await n.registerLoader("image",new c_),e()}shutdown(t,e,i){this.graphics.layers.remove(this.renderLayer),e()}link(t,e){t.getFlag(1)||t.build(this.assetManager);const i=t.size,n=t.gridScale,s=i.x,r=i.y;this.gridScaleX=s*n/(s-1),this.gridScaleY=r*n/(r-1),t.link(this.graphics);const a=t.__tiles.bvh;a.entity=e,this.renderLayer.bvh=a}unlink(t,e){this.renderLayer.bvh===t.__tiles.bvh&&(this.renderLayer.bvh=new vd),t.unlink()}update(t){const e=this.entityManager.dataset;this.__time_delta=t,null!==e&&e.traverseComponents(sm,this.__visitTerrainComponent,this)}__visitTerrainComponent(t,e){const i=this.entityManager.dataset,n=i.getComponent(e,Au);t.transform=void 0!==n?n.matrix:pp,t.update(this.__time_delta),t.frustumCulled&&d_.traverseVisibleTiles(i,t,u_)}static traverseVisibleTiles(t,e,i){const n=e.__tiles;void 0!==n&&Jm.getActiveFrustums(t,(function(t){n.bvh.threeTraverseFrustumsIntersections(t,(function(t){const e=t.object;i(e,n)}))}))}}class p_{constructor(){this.entity=-1}static from(t){const e=new p_;return e.entity=t,e}toJSON(){return{entity:this.entity}}fromJSON({entity:t}){this.entity=t}}p_.typeName="ParentEntity",p_.serializable=!1;const f_=new Uint8Array([0,1,28,2,29,14,24,3,30,22,20,15,25,17,4,8,31,27,13,23,21,19,16,7,26,12,18,6,11,5,10,9]);function m_(t){return f_[125613361*(t&-t)>>>27]}const __=.5;function g_(){this.__length=0,this.__capacity=64,this.__data_uint32=new Uint32Array(this.__capacity>>5),this.__shrinkFactor=__}g_.prototype.preventShrink=function(){this.__shrinkFactor=0},g_.prototype.setShrinkFactor=function(t){this.__shrinkFactor=t},g_.prototype.setCapacity=function(t){if(this.__length>t)throw new Error("Current length is greater than requested size");this.__resize(t)},g_.prototype.size=function(){return this.__length},g_.prototype.capacity=function(){return this.__capacity},g_.prototype.__resize=function(t){const e=Math.ceil(t/32),i=this.__data_uint32,n=new Uint32Array(e);i.length<e?n.set(i):n.set(i.subarray(0,e)),this.__data_uint32=n,this.__capacity=32*e},g_.prototype.__setLength=function(t){this.__length=t;const e=this.__capacity;if(t>e){const i=Math.ceil(am(t,e+128,1.3*e));this.__resize(i)}else t<e-128&&t<e*this.__shrinkFactor&&this.__resize(t)},g_.prototype.previousSetBit=function(t){const e=ru(t,this.__length-1);let i=e>>5,n=31&e;const s=this.__data_uint32;let r=s[i];for(;n>=0;n--)if(0!=(r&1<<n))return 32*i+n;for(i--;i>=0;i--)for(r=s[i],n=31;n>=0;n--)if(0!=(r&1<<n))return 32*i+n;return-1},g_.prototype.nextSetBit=function(t){const e=this.__length;if(t>=e)return-1;const i=this.__data_uint32;let n,s,r=t>>5,a=31&t;if(0!==a){const t=~((1<<a)-1),e=i[r]&t;if(0!==e)return a=m_(e),(r<<5)+a;r++}const o=e/32;for(;r<o;r++)if(n=i[r],0!==n)return a=m_(n),s=(r<<5)+a,s;return-1},g_.prototype.nextClearBit=function(t){let e,i=t>>5,n=31&t;const s=this.__length,r=s/32,a=this.__data_uint32;if(0!==n){e=a[i];const t=(e|(1<<n)-1)>>>0;if(4294967295!==t)return n=m_(~t),n+32*i;i++}for(;i<r;i++)if(e=a[i],4294967295!==e)return n=m_(~e),n+32*i;return s},g_.prototype.set=function(t,e){const i=t>>5,n=1<<(31&t);if(e){const e=t+1;e>this.__length&&this.__setLength(e),this.__data_uint32[i]|=n}else t<this.__length&&(this.__data_uint32[i]&=~n,t===this.__length-1&&this.__setLength(t))},g_.prototype.clear=function(t){this.set(t,!1)},g_.prototype.setRange=function(t,e){for(let i=t;i<=e;i++)this.set(i,!0)},g_.prototype.clearRange=function(t,e){for(let i=t;i<e;i++)this.set(i,!1)},g_.prototype.and=function(t){throw new Error("NIY")},g_.prototype.get=function(t){if(t>=this.__length)return!1;const e=t>>5,i=31&t;return 0!=(this.__data_uint32[e]&1<<i)},g_.prototype.getAndSet=function(t){const e=this.get(t);return e||this.set(t,!0),e},g_.prototype.getAndClear=function(t){const e=this.get(t);return e&&this.set(t,!1),e},g_.prototype.shift_right=function(t,e,i){for(let n=i;n>=e;n--){const e=this.get(n);this.set(n+t,e)}},g_.prototype.shift_left=function(t,e,i){for(let n=e;n<=i;n++){const e=this.get(n);this.set(n-t,e)}},g_.prototype.shift=function(t,e,i){t>0?this.shift_right(t,e,i):this.shift_right(-t,e,i)},g_.prototype.reset=function(){const t=this.__length;t<=0||(t<=32?this.__data_uint32[0]=0:this.__data_uint32.fill(0,0,Math.ceil(t/32)),this.__length=0)},g_.prototype.copy=function(t){const e=t.__length,i=e>>5,n=this.__length;n!==e&&(n<e?this.__resize(e):this.__data_uint32.fill(0,i),this.__length=e);for(let e=0;e<i;e++)this.__data_uint32[e]=t.__data_uint32[e];const s=i<<5,r=e-s;for(let e=0;e<r;e++){const i=s+e;this.set(i,t.get(i))}},g_.fixedSize=function(t){const e=new g_;return e.setCapacity(t),e.__shrinkFactor=0,e};class y_{constructor(t,e,i,n){const s=t.length;if(s<1)throw new Error(`Observer has to have at least 1 component types to watch, instead was given ${s}`);this.componentTypeCount=s,this.callbackComplete=e,this.callbackBroken=i,this.componentTypes=t,this.thisArg=n,this.componentMask=new g_,this.componentIndexMapping=[],this.dataset=null}build(t){let e;for(this.componentIndexMapping=[],this.componentMask.reset(),e=0;e<this.componentTypeCount;e++){const i=this.componentTypes[e],n=t.indexOf(i);if(-1===n)throw new Error(`Component type[${e}] was not found in the supplied map. Observer is not compatible.`);this.componentMask.set(n,!0),this.componentIndexMapping[n]=e}}connect(t){t.addObserver(this,!0)}disconnect(){this.dataset.removeObserver(this)}}const v_="entityRemoved",x_="componentAdded",w_={Initial:0,Starting:1,Running:2,Failed:3,Stopping:4,Stopped:5};function b_(){this.systems=[],this.systemObservers=[],this.on={systemStarted:new l,systemStopped:new l,systemAdded:new l,systemRemoved:new l,reset:new l},this.state=w_.Initial,this.dataset=null}function S_(t,e){try{t.update(e)}catch(t){}}function M_(t){return void 0!==t}function T_(t){return function(e){return e instanceof t}}function C_(t){return function(e){return typeof e===t}}b_.prototype.detachDataSet=function(){const t=this.dataset;null!==t&&(this.systemObservers.forEach((function(e){t.removeObserver(e,!0)})),this.dataset=null)},b_.prototype.getComponentTypeMap=function(){const t=[],e=this.systems,i=e.length;for(let n=0;n<i;n++){const i=e[n].referenced_components;wm(i,0,t,t.length,i.length)}return t},b_.prototype.attachDataSet=function(t){if(null!==this.dataset)throw new Error("Illegal status, another dataset is currently attached");const e=this.getComponentTypeMap();t.registerManyComponentTypes(e),this.dataset=t,this.systemObservers.forEach((function(e){t.addObserver(e,!0)}))},b_.prototype.createEntity=function(){return this.dataset.createEntity()},b_.prototype.createEntitySpecific=function(t){this.dataset.createEntitySpecific(t)},b_.prototype.removeComponentFromEntity=function(t,e){this.dataset.removeComponentFromEntityByIndex(t,e)},b_.prototype.getComponent=function(t,e){return this.dataset.getComponent(t,e)},b_.prototype.entityExists=function(t){return null!==this.dataset&&this.dataset.entityExists(t)},b_.prototype.getComponentAsync=function(t,e,i,n){const s=this,r=this.getComponent(t,e);null==r?this.addEntityEventListener(t,x_,(function r(a){a.klass===e&&(s.removeEntityEventListener(t,x_,r),i.call(n,a.instance))})):i.call(n,r)},b_.prototype.getComponents=function(t){return this.dataset.getAllComponents(t)},b_.prototype.getComponentByType=function(t,e){return this.dataset.getComponentByIndex(t,e)},b_.prototype.traverseEntities=function(t,e,i){null!==this.dataset&&this.dataset.traverseEntities(t,e,i)},b_.prototype.addEntityEventListener=function(t,e,i){this.dataset.addEntityEventListener(t,e,i)},b_.prototype.removeEntityEventListener=function(t,e,i){this.dataset.removeEntityEventListener(t,e,i)},b_.prototype.sendEvent=function(t,e,i){this.dataset.sendEvent(t,e,i)},b_.prototype.traverseComponents=function(t,e,i){null!==this.dataset&&this.dataset.traverseComponents(t,e,i)},b_.prototype.hasSystem=function(t){return null!==this.getSystem(t)},b_.prototype.getSystem=function(t){const e=this.systems,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i instanceof t)return i}return null},b_.prototype.getOwnerSystemByComponentClass=function(t){const e=this.getOwnerSystemIdByComponentClass(t);return this.systems[e]},b_.prototype.getOwnerSystemIdByComponentClass=function(t){const e=this.systems;let i=0;const n=e.length;for(;i<n;i++)if(e[i].componentClass===t)return i;return-1},b_.prototype.getComponentClassByName=function(t){const e=this.getComponentTypeMap();let i=0;const n=e.length;for(;i<n;i++){const n=e[i];if(n.typeName===t)return n}return null},b_.prototype.simulate=function(t){const e=this.systems;let i=0;const n=e.length;for(;i<n;i++)S_(e[i],t)},b_.prototype.addSystem=async function(t){const e=this.getSystem(Object.getPrototypeOf(t).constructor);if(null!==e){if(e===t)return;throw new Rf(`Another instance of system '${Sm(t)}' is already registered`)}try{!function(t){if(void 0===t)throw new Error("System is undefined");if(null===t)throw new Error("System is null");if(!(t instanceof bm))throw new TypeError('System does not inherit from "System" class');if("function"==typeof t.add)throw new Error("uses deprecated 'add' method, should use 'link' instead");if("function"==typeof t.remove)throw new Error("uses deprecated 'remove' method, should use 'unlink' instead");const e=t.dependencies,i=e.length;if(i<1)throw new Error("A system must declare at least one dependency");if(i>1)for(let t=0;t<i;t++){const n=e[t];for(let s=t+1;s<i;s++)if(n===e[s])throw new Error(`Detected duplicate dependency: ${n.constructor.typeName}`)}const n=i+1;if(t.link!==bm.prototype.link&&t.link.length!==n&&!0!==t.__validation_ignore_link_argument_count)throw new Error(`'link' method declares ${t.link.length} instead of expected ${n} based on it's ${i} dependencies`);if(t.unlink!==bm.prototype.unlink&&t.unlink.length!==n&&!0!==t.__validation_ignore_link_argument_count)throw new Error(`'unlink' method declares ${t.unlink.length} instead of expected ${n} based on it's ${i} dependencies`)}(t)}catch(t){}const i=t.state.getValue(),n=[bm.State.INITIAL,bm.State.STOPPED];if(-1===n.indexOf(i))throw new Rf(`System must be in one of these states: [${n.join(",")}], instead was ${i}`);const s=this.systems,r=s.length;s[r]=t;const a=new y_(t.dependencies,t.link,t.unlink,t);let o;this.systemObservers[r]=a,o=this.state===w_.Running?new Promise(((e,i)=>{t.startup(this,e,i)})):Promise.resolve(),null!==this.dataset&&(this.dataset.registerManyComponentTypes(t.referenced_components),this.dataset.addObserver(a)),this.on.systemAdded.send1(t),await o},b_.prototype.removeSystem=async function(t){const e=this.systems.indexOf(t);if(-1===e)return!1;const i=this.systemObservers[e];this.systemObservers.splice(e,1),this.systems.splice(e,1),null!==this.dataset&&this.dataset.removeObserver(i),await new Promise(((e,i)=>{this.stopSystem(t,e,(e=>{i(`system ${Sm(t)} shutdown failed: ${e}`)}))})),this.on.systemRemoved.send1(t)},b_.prototype.stopSystem=function(t,e,i){const n=this;try{t.state.set(bm.State.STOPPING)}catch(t){return void i(t)}try{t.shutdown(n,(function(){t.state.set(bm.State.STOPPED),n.on.systemStopped.send1(t),e(t)}),(function(t){i(t)}))}catch(t){i(t)}},b_.prototype.startSystem=function(t,e,i){if(t.state.getValue()===bm.State.RUNNING)return void e(t);const n=this;try{t.state.set(bm.State.STARTING)}catch(t){return void i(t)}function s(t){i(t)}try{t.startup(n,(function(){t.state.set(bm.State.RUNNING),n.on.systemStarted.dispatch(t),e(t)}),s)}catch(t){s(t)}},b_.prototype.startup=function(t,e){if(this.state===w_.Starting)throw new Rf("System is currently in starting state");if(this.state===w_.Running)return void t();this.state=w_.Starting;const i=this,n=this.systems;let s=0;const r=n.length;function a(){i.state=w_.Running;try{t()}catch(t){}}function o(){s++,s===r&&a()}let l=!0;function h(t,n){l&&(l=!1,i.state=w_.Failed,e(n))}0!==r?n.forEach((function(t){const e=o.bind(null,t),n=h.bind(null,t);i.startSystem(t,e,n)})):a()},b_.prototype.promiseSystem=function(t){const e=this;return new Promise((function(i,n){const s=e.getSystem(t);null!==s?i(s):e.on.systemAdded.add((function n(s){s instanceof t&&(e.on.systemAdded.remove(n),i(s))}))}))},b_.prototype.promiseSystemInState=function(t,e){const i=this;return new Promise((function(n,s){i.promiseSystem(t).then((function(t){!function i(){t.state.get()!==e?t.state.onChanged.addOne(i):n(t)}()}),s)}))},b_.prototype.shutdown=function(t,e){this.state=w_.Stopping,null!==this.dataset&&this.detachDataSet();const i=this,n=this.systems;let s=0;const r=n.length;function a(){i.state=w_.Stopped;try{t()}catch(t){}}function o(t){s++,t.state.set(bm.State.STOPPED),i.on.systemStopped.dispatch(t),s===r&&a()}let l=!0;function h(t){l&&(l=!1,i.state=w_.Failed,e())}0===r&&a(),n.forEach((function(t){t.state.set(bm.State.STOPPING);const e=o.bind(null,t),n=h.bind(null,t);try{t.shutdown(i,e,n)}catch(t){n(t)}}))},b_.prototype.reset=function(){this.dataset.clear(),this.on.reset.send0()};const A_={Built:1,RegisterComponents:2,WatchDestruction:4},E_=A_.RegisterComponents|A_.WatchDestruction;class z_{constructor(){this.entity=void 0,this.generation=-1,this.element=[],this.deferredListeners=[],this.dataset=null,this.flags=E_,this.properties={},this.on={built:new l}}__handleEntityDestroyed(){this.clearFlag(A_.Built)}setFlag(t){this.flags|=t}getFlag(t){return 0!=(this.flags&t)}clearFlag(t){this.flags&=~t}get isBuilt(){return this.getFlag(A_.Built)}removeAllComponents(){const t=this.element;for(let e=t.length-1;e>=0;e--){const i=t[e];this.removeComponent(Object.getPrototypeOf(i).constructor)}}add(t){if(void 0===t)throw new Error("Can not add "+t+" to EntityBuilder");return this.element.push(t),this.getFlag(A_.Built)&&this.dataset.addComponentToEntity(this.entity,t),this}hasComponent(t){return null!==this.getComponent(t)}getComponent(t){const e=this.element,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i instanceof t)return i}return null}getComponentSafe(t){const e=this.getComponent(t);if(null===e)throw new Error("Component of given class not found");return e}removeComponent(t){const e=this.element,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i instanceof t)return e.splice(n,1),this.getFlag(A_.Built)&&this.dataset.removeComponentFromEntity(this.entity,t),i}return null}sendEvent(t,e){this.getFlag(A_.Built)&&this.dataset.sendEvent(this.entity,t,e)}promiseEvent(t){return new Promise(((e,i)=>{const n=()=>{this.removeEventListener(t,n),this.removeEventListener(v_,i),e()};this.addEventListener(t,n),this.removeEventListener(v_,i)}))}addEventListener(t,e,i){return this.getFlag(A_.Built)?this.dataset.addEntityEventListener(this.entity,t,e,i):this.deferredListeners.push({name:t,listener:e,context:i}),this}removeEventListener(t,e,i){if(this.getFlag(A_.Built))this.dataset.removeEntityEventListener(this.entity,t,e,i);else{const n=this.deferredListeners;for(let s=0,r=n.length;s<r;s++){const a=n[s];a.name===t&&a.listener===e&&a.context===i&&(n.splice(s,1),s--,r--)}}return this}destroy(){if(this.getFlag(A_.Built)){const t=this.dataset,e=this.entity;return t.removeEntityEventListener(e,v_,this.__handleEntityDestroyed,this),t.removeEntity(e),this.entity=void 0,this.clearFlag(A_.Built),!0}return!1}build(t){if(this.getFlag(A_.Built)&&function(t,e,i){if(!i.entityExists(t))return!1;const n=e.length;for(let s=0;s<n;s++){const n=e[s];if(i.getComponent(t,n.constructor)!==n)return!1}return!0}(this.entity,this.element,t))return this.entity;const e=this.entity=t.createEntity();let i;this.dataset=t;const n=this.deferredListeners,s=n.length;for(i=0;i<s;i++){const s=n[i];t.addEntityEventListener(e,s.name,s.listener,s.context)}const r=this.element,a=r.length;if(this.getFlag(A_.RegisterComponents))for(i=0;i<a;i++){const e=r[i];t.registerComponentType(e.constructor)}for(i=0;i<a;i++){const n=r[i];t.addComponentToEntity(e,n)}return this.setFlag(A_.Built),this.getFlag(A_.WatchDestruction)&&t.addEntityEventListener(e,v_,this.__handleEntityDestroyed,this),this.on.built.send2(e,t),e}static readFromDataset(t,e){const i=new z_;return e.getAllComponents(t).filter(M_).forEach(i.add,i),i.setFlag(A_.Built),i.entity=t,i.dataset=e,i}}function I_(t,e){const i=t.indexOf(e);return-1!==i&&(t.splice(i,1),!0)}function N_(t){if(t>2**31-1)throw"number too large. number shouldn't be > 2**31-1";if(t<-1*2**31)throw"number too far negative, number shouldn't be < 2**31";for(var e=0,i=t,n="";e<32;e++,n+=String(i>>>31),i<<=1);return n.replace(/\B(?=(.{8})+(?!.))/g," ")}z_.prototype.isEntityBuilder=!0;class L_{constructor(){this.transform=new Au,this.parent=-1,this.flags=1}toString(){return JSON.stringify(this.toJSON())}toJSON(){return{transform:this.transform.toJSON(),parent:this.parent,flags:N_(this.flags)}}get immediate(){return this.getFlag(1)}set immediate(t){this.writeFlag(1,t)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}}L_.typeName="TransformAttachment";class P_{constructor(t=new z_){this.__parent=null,this.__entity=t,this.__children=[],this.__transform=new Au,this.on={built:new l,destroyed:new l},this.flags=1}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}traverse(t,e){t.call(e,this);const i=this.__children,n=i.length;for(let s=0;s<n;s++)i[s].traverse(t,e)}traverseChildren(t,e){this.__children.forEach(t,e)}get children(){return this.__children}__transform_sync_down(){const t=this.__transform;if(null===this.__parent){const e=this.__entity.getComponent(Au);null!==e&&e.copy(t)}else this.__safe_get_attachment().transform.copy(t)}static fromComponents(...t){const e=new P_;for(let i=0;i<t.length;i++){const n=t[i];e.entity.add(n)}return e}__safe_get_attachment(){const t=this.__entity;let e=t.getComponent(L_);return null===e&&(e=new L_,e.setFlag(1),t.add(e)),e}get transform(){return this.__transform}get parent(){return this.__parent}set parent(t){this.__parent=t;const e=this.__entity;if(!e.isBuilt)return;let i=e.removeComponent(p_),n=e.removeComponent(L_);if(null!==t){null===i&&(i=new p_);const s=t.entity;if(!s.isBuilt)throw new Error("Parent entity is not built");const r=s.entity;i.entity=r,e.add(i),null===n&&(n=this.__safe_get_attachment()),n.parent=r}}get entity(){return this.__entity}addChild(t){var e,i;return i=t,-1===(e=this.__children).indexOf(i)&&(e.push(i),!0)&&(null!==t.parent&&t.parent.removeChild(t),t.parent=this,this.__entity.isBuilt&&t.build(this.__entity.dataset),!0)}removeChild(t){return!!I_(this.__children,t)&&(t.parent=null,!0)}get isBuilt(){return this.__entity.isBuilt}attachListeners(){this.getFlag(2)||(this.__transform.position.onChanged.add(this.__transform_sync_down,this),this.__transform.scale.onChanged.add(this.__transform_sync_down,this),this.__transform.rotation.onChanged.add(this.__transform_sync_down,this),this.setFlag(2))}detachListeners(){this.__transform.position.onChanged.remove(this.__transform_sync_down,this),this.__transform.scale.onChanged.remove(this.__transform_sync_down,this),this.__transform.rotation.onChanged.remove(this.__transform_sync_down,this),this.clearFlag(2)}build(t){const e=this.__parent;if(null!==e){let t=this.__entity.getComponent(p_);null===t&&(t=new p_,this.__entity.add(t));const i=e.__entity;if(!i.isBuilt)throw new Error("Parent entity is not built");const n=i.entity;t.entity=n,this.__safe_get_attachment().parent=n}this.__transform_sync_down(),this.getFlag(1)&&this.attachListeners(),this.__entity.build(t);const i=this.__children,n=i.length;for(let e=0;e<n;e++)i[e].build(t);this.on.built.send0()}destroy(){if(!this.__entity.isBuilt)return;this.getFlag(2)&&this.detachListeners();const t=this.__children,e=t.length;for(let i=0;i<e;i++)t[i].destroy();this.__entity.destroy(),this.on.destroyed.send0()}}function F_(t){const e=new P_;!function(t,e){t.position.copy(e.position),t.scale.copy(e.scale),t.rotation.copy(e.quaternion),t.matrix.set(e.matrix.elements)}(e.transform,t);const i=e.entity,n=new Au;if(n.fromMatrix4(t.matrixWorld.elements),i.add(n),t.isMesh){t.isSkinnedMesh;const e=_m.from(t.geometry,t.material);i.add(e)}const s=t.children,r=s.length;for(let t=0;t<r;t++){const i=F_(s[t]);e.addChild(i)}return e}P_.prototype.isEntityNode=!0;class D_{constructor(){this.attachment=null,this.transform=null,this.entity=-1,this.parent_transform=null,this.ecd=null}toString(){return`UpdateContext{ attachment:${this.attachment}, entity:${this.entity} }`}update(){this.transform.multiplyTransforms(this.parent_transform,this.attachment.transform)}bind_parent(){const t=this.ecd.getComponent(this.attachment.parent,Au);return void 0!==t&&(this.parent_transform=t,!0)}link(){const t=this.parent_transform;t.position.onChanged.add(this.update,this),t.rotation.onChanged.add(this.update,this),t.scale.onChanged.add(this.update,this);const e=this.attachment.transform;e.position.onChanged.add(this.update,this),e.rotation.onChanged.add(this.update,this),e.scale.onChanged.add(this.update,this)}unlink(){const t=this.parent_transform;t.position.onChanged.remove(this.update,this),t.rotation.onChanged.remove(this.update,this),t.scale.onChanged.remove(this.update,this);const e=this.attachment.transform;e.position.onChanged.remove(this.update,this),e.rotation.onChanged.remove(this.update,this),e.scale.onChanged.remove(this.update,this)}}class O_ extends bm{constructor(){super(),this.dependencies=[L_,Au],this.__contexts=[],this.__queue=[],this.__queue_size=0,this.__queue_cursor=0}__finalize_link(t){t.link(),this.__contexts[t.entity]=t,0!=(1&t.attachment.flags)&&t.update()}__enqueue(t){this.__queue[this.__queue_size++]=t}__dequeue_entity(t){for(let e=0;e<this.__queue_size;e++)if(this.__queue[e].entity===t)return this.__queue.splice(e,1),this.__queue_size--,!0;return!1}link(t,e,i){const n=new D_;n.attachment=t,n.transform=e,n.entity=i;const s=this.entityManager.dataset;n.ecd=s,n.bind_parent()?this.__finalize_link(n):this.__enqueue(n)}unlink(t,e,i){const n=this.__contexts[i];void 0!==n?(delete this.__contexts[i],n.unlink()):this.__dequeue_entity(i)}update(t){const e=ru(this.__queue_size,32);for(let t=0;t<e;t++){const t=this.__queue_cursor%this.__queue_size,e=this.__queue[t];e.bind_parent()?(this.__finalize_link(e),this.__queue.splice(t,1),this.__queue_size--):this.__queue_cursor++}}}function R_(t,e,i,n,s,r){const a=t-n,o=e-s,l=i-r;return a*a+o*o+l*l}function k_(t,e){const i=t.material,n=e.material;return i===n?0:void 0===i?1:void 0===n?-1:i.id-n.id}class U_{constructor(){this.__object_count=0,this.__objects=[]}sort_by_material(){!function(t,e,i,n,s){if(0>=s)return;let r,a,o=2;for(ju[0]=0,ju[1]=s;o>0;){o-=2;const i=ju[o+1],n=ju[o];r=n,a=i;const s=t[n+i>>1];for(;r<=a;){for(;e.call(null,t[r],s)<0;)r++;for(;e.call(null,t[a],s)>0;)a--;if(r<=a){if(r!==a){const e=t[r];t[r]=t[a],t[a]=e}r++,a--}}n<a&&(ju[o++]=n,ju[o++]=a),r<i&&(ju[o++]=r,ju[o++]=i)}}(this.__objects,k_,0,0,this.__object_count-1)}score(t,e,i){return 0}intend_draw(t){return!0}add(t){throw new Error("Not Implemented")}build_start(t,e){}build_end(){}clear(){this.__object_count=0}*maintain(){}get objects(){return this.__objects}get object_count(){return this.__object_count}dispose(){}}U_.prototype.isShadedGeometryRenderAdapter=!0;class B_{constructor({read:t,write:e,name:i,uv_index:n=0}){this.name=i,this.read=t,this.write=e,this.uv_index=n}}const V_=new B_({name:"diffuse",uv_index:0,read:t=>t.map,write(t,e){t.map=e}}),G_=new B_({name:"alpha",uv_index:0,read:t=>t.alphaMap,write(t,e){t.alphaMap=e}}),W_=new B_({name:"displacement",uv_index:0,read:t=>t.displacementMap,write(t,e){t.displacementMap=e}}),H_={MeshDepthMaterial:[V_,W_,G_],MeshStandardMaterial:[V_,G_,new B_({name:"light",uv_index:1,read:t=>t.lightMap,write(t,e){t.lightMap=e}}),new B_({name:"ao",uv_index:1,read:t=>t.aoMap,write(t,e){t.aoMap=e}}),new B_({name:"emissive",uv_index:0,read:t=>t.emissiveMap,write(t,e){t.emissiveMap=e}}),new B_({name:"bump",uv_index:0,read:t=>t.bumpMap,write(t,e){t.bumpMap=e}}),new B_({name:"normal",uv_index:0,read:t=>t.normalMap,write(t,e){t.normalMap=e}}),W_,new B_({name:"roughness",uv_index:0,read:t=>t.roughnessMap,write(t,e){t.roughnessMap=e}}),new B_({name:"metalness",uv_index:0,read:t=>t.metalnessMap,write(t,e){t.metalnessMap=e}}),new B_({name:"environment",uv_index:0,read:t=>t.envMap,write(t,e){t.envMap=e}})]};function j_(t,i){return Array.isArray(t)||Array.isArray(i)?e(t,i):Bu(t,i)}const q_=new WeakMap;function J_(t,e){const i=q_.get(t);if(void 0!==i)return i;const n=t.width,s=t.height,r=Vu.uint8(4,n,s);return function(t,e,i){t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,i),t.drawBuffers([t.COLOR_ATTACHMENT0]);const n=e.width,s=e.height;if(4!==e.itemSize)throw new Error(`Expected sampler.itemSize to be 4, instead was '${e.itemSize}'`);const r=e.data;t.readPixels(0,0,n,s,t.RGBA,t.UNSIGNED_BYTE,r)}(e,r,t),q_.set(t,r),r}let Y_=null;function X_(t,e){let i;if(null===Y_||void 0===(i=Y_.deref())){i=document.createElement("canvas").getContext("webgl2"),i.activeTexture(i.TEXTURE0);const t=i.createTexture();i.bindTexture(i.TEXTURE_2D,t);const e=i.createFramebuffer();i.bindFramebuffer(i.FRAMEBUFFER,e),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,t,0),Y_=new WeakRef(i)}return i}function Z_(t,e){let i,n=e,s=0;const r=t.length;for(;s<r;)i=t[s],++s,i=3432918353*(65535&i)+((3432918353*(i>>>16)&65535)<<16),i=i<<15|i>>>17,i=461845907*(65535&i)+((461845907*(i>>>16)&65535)<<16),n^=i,n=n<<13|n>>>19,n=5*(65535&n)+((5*(n>>>16)&65535)<<16),n=27492+(65535&n)+((58964+(n>>>16)&65535)<<16);return n^=r,n^=n>>>16,n=2246822507*(65535&n)+((2246822507*(n>>>16)&65535)<<16),n^=n>>>13,n=3266489909*(65535&n)+((3266489909*(n>>>16)&65535)<<16),n^=n>>>16,n>>>0}function $_(t){const e=x(t.x);return(e<<5)-e+x(t.y)}const K_=new WeakMap;function Q_(t){if(null===t)return 0;if(void 0===t)return 0;const e=function(t){let e,i=0;null!==t.image&&void 0!==t.image&&(i=function(t){const e=K_.get(t);if(void 0!==e)return e;let i=0;t instanceof ImageBitmap?i=function(t){const e=ru(t.width,8),i=ru(t.height,8),n=function(t){return J_(t,X_(t.width,t.height))}(t),s=n.data,r=n.itemSize;let a=0;for(let t=0;t<i;t++){const i=t*n.width;for(let t=0;t<e;t++){const e=(t+i)*r;for(let t=0;t<r;t++)a=(a<<5)-a+s[e]}}return a}(t):t instanceof HTMLImageElement&&(i=Nd(t.src));let n=0,s=0;return"number"==typeof t.width&&(n=t.width),"number"==typeof t.height&&(s=t.height),i^=(65535&n)<<16|65535&s,K_.set(t,i),i}(t.image));const n=t.mipmaps;if(Array.isArray(n)){const t=n.length;for(e=0;e<t;e++){const t=n[e].data;if(!(t.length>1024)){i=(i<<5)-i+Z_(t,1337);break}}}return i}(t);return Cd(t.mapping,t.wrapS,t.wrapT,t.magFilter,t.minFilter,t.anisotropy,t.format,t.type,$_(t.offset),$_(t.repeat),$_(t.center),x(t.rotation),t.generateMipmaps?1:0,t.premultiplyAlpha?1:0,t.flipY?1:0,t.unpackAlignment,t.encoding,e)}function tg(t,e){return t===e||null!==t&&null!==e&&void 0!==t&&void 0!==e&&!!(t.mapping===e.mapping&&t.wrapS===e.wrapS&&t.wrapT===e.wrapT&&t.magFilter===e.magFilter&&t.minFilter===e.minFilter&&t.anisotropy===e.anisotropy&&t.format===e.format&&t.type===e.type&&t.offset.equals(e.offset)&&t.repeat.equals(e.repeat)&&t.center.equals(e.center)&&t.rotation===e.rotation&&t.generateMipmaps===e.generateMipmaps&&t.premultiplyAlpha===e.premultiplyAlpha&&t.flipY===e.flipY&&t.unpackAlignment===e.unpackAlignment&&t.encoding===e.encoding&&function(t,e){if(t===e)return!0;if(t instanceof Image&&e instanceof Image)return t.src===e.src;if("number"==typeof t.width&&t.width!==e.width||"number"==typeof t.height&&t.height!==e.height)return!1;if(t instanceof ImageBitmap&&e instanceof ImageBitmap)return function(t,e){if(t===e)return!0;if(t.width!==e.width||t.height!==e.height)return!1;const i=X_(t.width,t.height),n=J_(t,i),s=J_(e,i);return j_(n.data,s.data)}(t,e);if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++){const n=t[i],s=e[i];if(n.format!==s.format)return!1;if(!eg(n.mipmaps,s.mipmaps))return!1}}return!0}(t.image,e.image))&&!(t.isCompressedTexture&&e.isCompressedTexture&&!eg(t.mipmaps,e.mipmaps))}function eg(t,e){if(void 0===t)return void 0===e;if(void 0===e)return!1;const i=t.length;if(i!==e.length)return!1;for(let n=i-1;n>=0;n--)if(!ig(t[n],e[n]))return!1;return!0}function ig(t,e){if(t.width!==e.width)return!1;if(t.height!==e.width)return!1;const i=t.data,n=e.data;return i===n||j_(i,n)}function ng(t){return Xu(t.normal.x,t.normal.y,t.normal.z)^t.constant}function sg(t,e){const i=t.length;let n=i;for(let s=0;s<i;s++)n=(n<<5)-n+e(t[s]),n|=0;return n}function rg(t){return null==t?0:t.id}function ag(t){return t.getHex()}function og(t){let e=Cd(x(t.alphaTest),t.blendDst,null===t.blendDstAlpha?0:x(t.blendDstAlpha),t.blendEquation,null===t.blendEquationAlpha?0:x(t.blendEquationAlpha),t.blending,t.blendSrc,null===t.blendSrcAlpha?0:x(t.blendSrcAlpha),t.clipIntersection?0:1,null===t.clippingPlanes?0:sg(t.clippingPlanes,ng),t.clipShadows?0:1,t.colorWrite?0:1,t.depthFunc,t.depthTest?0:1,t.depthWrite?0:1,t.fog?0:1,x(t.opacity),t.polygonOffset?0:1,x(t.polygonOffsetFactor),x(t.polygonOffsetUnits),Nd(t.precision),t.premultipliedAlpha?0:1,t.dithering?0:1,t.flatShading?0:1,t.side,t.transparent?0:1,Nd(t.type),t.vertexColors?0:1,t.visible?0:1);return t.isMeshStandardMaterial?e=Cd(e,ag(t.color),x(t.roughness),x(t.metalness),rg(t.map),rg(t.lightMap),x(t.lightMapIntensity),rg(t.aoMap),x(t.aoMapIntensity),ag(t.emissive),x(t.emissiveIntensity),rg(t.emissiveMap),x(t.envMapIntensity),rg(t.bumpMap),rg(t.normalMap)):t.isShaderMaterial&&(e^=t.lights?0:1),e}function lg(t,e){return t.equals(e)}function hg(t,e){return t===e||null!==t&&null!==e&&void 0!==t&&void 0!==e&&t.id===e.id}function cg(t,e){if(t===e)return!0;if(t.type!==e.type)return!1;if(t.alphaTest!==e.alphaTest||t.blendDst!==e.blendDst||t.blendDstAlpha!==e.blendDstAlpha||t.blendEquation!==e.blendEquation||t.blendEquationAlpha!==e.blendEquationAlpha||t.blending!==e.blending||t.blendSrc!==e.blendSrc||t.blendSrcAlpha!==e.blendSrcAlpha||t.clipIntersection!==e.clipIntersection||!function(t,e,i){if(t===e)return!0;if(null===t||null===e||void 0===t||void 0===e)return!1;const n=t.length;if(n!==e.length)return!1;for(let s=0;s<n;s++)if(!i(t[s],e[s]))return!1;return!0}(t.clippingPlanes,e.clippingPlanes,lg)||t.clipShadows!==e.clipShadows||t.colorWrite!==e.colorWrite||t.depthFunc!==e.depthFunc||t.depthTest!==e.depthTest||t.depthWrite!==e.depthWrite||t.fog!==e.fog||t.lights!==e.lights||t.opacity!==e.opacity||t.polygonOffset!==e.polygonOffset||t.polygonOffsetFactor!==e.polygonOffsetFactor||t.polygonOffsetUnits!==e.polygonOffsetUnits||t.precision!==e.precision||t.premultipliedAlpha!==e.premultipliedAlpha||t.dithering!==e.dithering||t.flatShading!==e.flatShading||t.side!==e.side||t.transparent!==e.transparent||t.vertexColors!==e.vertexColors||t.visible!==e.visible)return!1;if(t.onBeforeCompile!==e.onBeforeCompile)return!1;if(t.isMeshStandardMaterial){if(!(t.color.equals(e.color)&&t.roughness===e.roughness&&t.metalness===e.metalness&&t.lightMapIntensity===e.lightMapIntensity&&t.aoMapIntensity===e.aoMapIntensity&&t.emissive.equals(e.emissive)&&t.emissiveIntensity===e.emissiveIntensity&&t.bumpScale===e.bumpScale&&t.normalMapType===e.normalMapType&&t.normalScale.equals(e.normalScale)&&t.displacementScale===e.displacementScale&&t.displacementBias===e.displacementBias&&t.envMapIntensity===e.envMapIntensity&&t.refractionRatio===e.refractionRatio&&t.wireframe===e.wireframe&&t.wireframeLinewidth===e.wireframeLinewidth&&t.morphTargets===e.morphTargets&&t.morphNormals===e.morphNormals&&hg(t.roughnessMap,e.roughnessMap)&&hg(t.metalnessMap,e.metalnessMap)&&hg(t.alphaMap,e.alphaMap)&&hg(t.envMap,e.envMap)&&hg(t.displacementMap,e.displacementMap)&&hg(t.normalMap,e.normalMap)&&hg(t.emissiveMap,e.emissiveMap)&&hg(t.bumpMap,e.bumpMap)&&hg(t.aoMap,e.aoMap)&&hg(t.map,e.map)&&hg(t.lightMap,e.lightMap)))return!1}else if(t.isMeshDepthMaterial){if(!hg(t.alphaMap,e.alphaMap)||t.depthPacking!==e.depthPacking||!hg(t.displacementMap,e.displacementMap)||t.displacementScale!==e.displacementScale||t.displacementBias!==e.displacementBias||!hg(t.map,e.map)||t.morphTargets!==e.morphTargets||t.wireframe!==e.wireframe||t.wireframeLinewidth!==e.wireframeLinewidth)return!1}else{if(!t.isMeshMatcapMaterial)return!1;if(!(t.color.equals(e.color)&&hg(t.matcap,e.matcap)&&hg(t.map,e.map)&&hg(t.bumpMap,e.bumpMap)&&hg(t.normalMap,e.normalMap)&&t.normalScale.equals(e.normalScale)&&hg(t.displacementMap,e.displacementMap)&&t.displacementScale===e.displacementScale&&t.displacementBias===e.displacementBias&&hg(t.alphaMap,e.alphaMap)&&t.morphTargets===e.morphTargets&&t.morphNormals===e.morphNormals&&t.flatShading===e.flatShading))return!1}return!0}class ug{constructor(){this.materialCache=new Qp({maxWeight:1e3,keyHashFunction:og,keyEqualityFunction:cg}),this.textureCache=new Qp({maxWeight:1e3,keyHashFunction:Q_,keyEqualityFunction:tg})}acquire(t){const e=this.materialCache.get(t);if(null!==e)return e;const i=this.textureCache,n=t.type,s=H_[n];if(void 0!==s){const e=s.length;for(let n=0;n<e;n++){const e=s[n],r=e.read(t);if(null==r)continue;const a=i.get(r);null!==a?e.write(t,a):i.put(r,r)}}return this.materialCache.put(t,t),t}}ug.Global=new ug;const dg=new WeakMap;let pg=0;function fg(t,e){let i=dg.get(t);void 0===i&&(i=new WeakMap,dg.set(t,i));let n=i.get(e);return void 0===n&&(n=new Function("previous, next",`return function f${pg++}(a,b,c,d){ previous(a,b,c,d); next(a,b,c,d); };`)(t,e),i.set(e,n)),n}const mg="\n #define USE_COLOR_ALPHA\n #define USE_INSTANCING_COLOR \n \n attribute mat4 instanceMatrix;\n attribute vec4 instanceColor;\n \n";function _g(t){const e=t.vertexShader,i=mg+e.replace("#include <begin_vertex>","\n vec3 transformed = ( instanceMatrix * vec4(position,1.0) ).xyz;\n ").replace("#include <beginnormal_vertex>","\n vec3 objectNormal = mat3( instanceMatrix ) * vec3( normal );\n #ifdef USE_TANGENT\n vec3 objectTangent = vec3( tangent.xyz );\n #endif\n ").replace("#include <color_vertex>","\n #if defined( USE_COLOR_ALPHA )\n vColor = instanceColor;\n #else\n vColor = instanceColor.xyz;\n #endif\n ");t.vertexShader=i,t.fragmentShader="\n #define USE_COLOR_ALPHA\n #define USE_INSTANCING_COLOR \n "+t.fragmentShader}class gg{constructor(){this.__threeGeometry=null,this.__threeInstanceGeometry=null,this.count=0,this.capacity=0,this.growFactor=1.2,this.growConstant=16,this.shrinkFactor=.5,this.shrinkConstant=64,this.__attributeTransform=null,this.__attributeTransformArray=null,this.__attributeColor=null,this.__attributeColorArray=null,this.__instanceUsage=ci,this.__material=null,this.indices=[],this.references=[],this.__draw_mode=0,this.mesh=jd(),this.use_color=!0}__build_mesh(){let t;switch(this.__draw_mode){case 0:t=new Rs(this.mesh.geometry,this.mesh.material);break;case 2:t=new Pl(this.mesh.geometry,this.mesh.material);break;case 3:t=new Ol(this.mesh.geometry,this.mesh.material);break;default:throw new Error(`Unsupported DrawMode '${this.__draw_mode}'`)}t.matrixAutoUpdate=!1,t.frustumCulled=!1,t.matrixWorldNeedsUpdate=!1,null!==this.mesh&&(t.castShadow=this.mesh.castShadow,t.receiveShadow=this.mesh.receiveShadow,t.customDepthMaterial=this.mesh.customDepthMaterial),this.mesh=t}set draw_mode(t){t!==this.__draw_mode&&(this.__draw_mode=t,this.__build_mesh())}set instance_usage(t){this.__instanceUsage!==t&&(this.__instanceUsage=t,null!==this.__attributeTransform&&this.__attributeTransform.setUsage(t),null!==this.__attributeColor&&this.__attributeColor.setUsage(t))}get instance_usage(){return this.__instanceUsage}dispose(){null!==this.__threeGeometry&&this.__threeGeometry.dispose()}setGeometry(t){if(!0!==t.isBufferGeometry)throw new Error("Expected THREE.BufferedGeometry, got something else instead.");this.__threeInstanceGeometry=t,this.build()}setMaterial(t){const e=t.clone();if(e.isShaderMaterial)for(const i in e.uniforms)e.uniforms[i]=t.uniforms[i];e.onBeforeCompile=fg(t.onBeforeCompile,_g);const i=new Fo({depthPacking:ri});0!==e.alphaTest&&(i.alphaTest=e.alphaTest,i.map=e.map),i.onBeforeCompile=_g;const n=ug.Global.acquire(e);this.__material=n,this.mesh.material=n,this.mesh.customDepthMaterial=ug.Global.acquire(i)}setCapacity(t){this.capacity!==t&&(this.capacity=t,this.build())}ensureCapacity(t){const e=this.capacity;if(e<t){const i=am(t,e*this.growFactor,e+this.growConstant),n=Math.ceil(i);this.setCapacity(n)}else ru(e*this.shrinkFactor,e-this.shrinkConstant)>t&&this.setCapacity(t)}setTransformAt(t,e){this.__attributeTransformArray.set(e,16*t)}setColorAt(t,e){this.__attributeColorArray.set(e,4*t)}setColorByComponentAt(t,e,i,n,s){const r=this.__attributeColorArray,a=4*t;r[a]=e,r[a+1]=i,r[a+2]=n,r[a+3]=s}requestAttributeUpdate(){this.__attributeTransform.needsUpdate=!0,null!==this.__attributeColor&&(this.__attributeColor.needsUpdate=!0)}swap(t,e){throw new Error("Not Implemented Yet")}setCount(t){this.ensureCapacity(t),this.count=t,this.__threeGeometry.instanceCount=t}getCount(){return this.count}add(t){const e=this.count;return this.setCount(e+1),this.indices[t]=e,this.references[e]=t,e}traverseReferences(t,e){const i=this.indices,n=i.length;for(let s=0;s<n;s++){const n=i[s];void 0!==n&&t.call(e,n,s)}}remove(t){const e=this.indices[t];if(void 0===e)throw new Error(`Reference '${t}' was not found`);delete this.indices[t];const i=this.count-1,n=this.references;if(e===i)delete n[e];else{const t=this.__attributeTransform;t.array.copyWithin(16*e,16*i,16*i+16),t.needsUpdate=!0;const s=this.__attributeColor;null!==s&&(s.array.copyWithin(4*e,4*i,4*i+4),s.needsUpdate=!0);const r=n[i];if(void 0===r)throw new Error("Moved reference was not found");delete n[i],n[e]=r,this.indices[r]=e}this.setCount(this.count-1)}build(){null!==this.__threeGeometry&&this.__threeGeometry.dispose(),this.__threeGeometry=new Fc;const t=this.__threeInstanceGeometry,e=this.__threeGeometry;e.instanceCount=this.count,e.dynamic=!0,e.index=t.index;for(let i in t.attributes)t.attributes.hasOwnProperty(i)&&(e.attributes[i]=t.attributes[i]);const i=new Float32Array(16*this.capacity);if(null!==this.__attributeTransform){const t=this.__attributeTransform.array;cf(t,i),i.length>t.length&&i.fill(0,t.length)}if(this.__attributeTransformArray=i,this.__attributeTransform=new bl(i,16),this.__attributeTransform.setUsage(this.__instanceUsage),e.setAttribute("instanceMatrix",this.__attributeTransform),this.use_color){const t=new Uint8Array(4*this.capacity);if(null!==this.__attributeColor){const e=this.__attributeColor.array;cf(e,t),t.length>e.length&&t.fill(255,e.length)}this.__attributeColorArray=t,this.__attributeColor=new bl(t,4),this.__attributeColor.normalized=!0,this.__attributeColor.setUsage(this.__instanceUsage),e.setAttribute("instanceColor",this.__attributeColor)}else this.__attributeColorArray=null,this.__attributeColor=null;this.mesh.geometry=e}static from(t,e){const i=new gg;return i.setGeometry(t),i.setMaterial(e),i}}class yg extends U_{constructor(){super(),this.__instanced_meshes=new $p({keyHashFunction:t=>t.geometry.id^t.material.id^t.mode,keyEqualityFunction:(t,e)=>t.material.id===e.material.id&&t.geometry.id===e.geometry.id&&t.mode===e.mode&&(6&t.flags)==(6&e.flags)}),this.__active_meshes=new Set}score(t,e,i){return i>16?1:i<4?-1:0}__get_instanced_mesh(t){let e=this.__instanced_meshes.get(t);return void 0!==e||(e=new gg,e.instance_usage=35040,e.shrinkFactor=0,e.draw_mode=t.mode,e.setMaterial(t.material),e.setGeometry(t.geometry),e.mesh.castShadow=t.getFlag(2),e.mesh.receiveShadow=t.getFlag(4),this.__instanced_meshes.set(t,e)),e}add(t){const e=this.__get_instanced_mesh(t),i=e.count,n=i+1;n>e.capacity&&e.ensureCapacity(n),e.setTransformAt(i,t.transform),e.count=n,this.__active_meshes.add(e)}build_start(t,e){this.clear()}build_end(){const t=this.__objects;for(const e of this.__active_meshes)e.setCount(e.getCount()),e.requestAttributeUpdate(),t[this.__object_count++]=e.mesh}clear(){super.clear();const t=this.__active_meshes;for(const e of t)e.setCount(0);t.clear()}dispose(){this.clear(),this.__instanced_meshes.forEach(((t,e)=>{t.dispose()})),this.__instanced_meshes.clear()}}class vg{constructor(){this.__object_cache=new WeakMap}get(t){const e=this.__object_cache.get(t);if(void 0!==e)return e;const i=function(t){let e;const i=t.mode,n=t.material,s=t.geometry;if(0===i)e=new Rs(s,n);else if(2===i)e=new Pl(s,n);else if(3===i)e=new Ol(s,n);else{if(4!==i)throw new Error(`Unsupported draw mode '${i}'`);e=new Gl(s,n)}return e.matrixAutoUpdate=!1,e.frustumCulled=!1,e.matrixWorldNeedsUpdate=!1,e.castShadow=t.getFlag(2),e.receiveShadow=t.getFlag(4),null!==t.depth_material&&(e.customDepthMaterial=t.depth_material),e}(t);return this.__object_cache.set(t,i),i}}vg.INSTANCE=new vg;class xg extends U_{constructor(){super(),this.__cache=vg.INSTANCE}build_start(t,e){this.clear()}add(t){const e=this.__cache.get(t),i=t.transform,n=e.matrixWorld.elements;for(let t=0;t<16;t++)n[t]=i[t];this.__objects[this.__object_count++]=e}}const wg=4294967295,bg=10;class Sg{constructor(){this.__data_buffer=new ArrayBuffer(5120),this.__data_float32=new Float32Array(this.__data_buffer),this.__data_uint32=new Uint32Array(this.__data_buffer),this.__capacity=128,this.__size=0,this.__free=[],this.__free_pointer=0,this.__root=wg}get root(){return this.__root}get node_capacity(){return this.__capacity}__grow_capacity(){const t=Math.ceil(Eu(1.2*this.__capacity,this.__capacity+64));this.__set_capacity(t)}__set_capacity(t){const e=this.__data_uint32,i=new ArrayBuffer(t*bg*4);this.__data_buffer=i,this.__data_float32=new Float32Array(i),this.__data_uint32=new Uint32Array(i),cf(e,this.__data_uint32),this.__capacity=t}trim(){this.__capacity>this.__size&&this.__set_capacity(this.__size)}allocate_node(){let t;const e=this.__free_pointer;if(e>0){const i=e-1;t=this.__free[i],this.__free_pointer=i}else t=this.__size,t>=this.__capacity&&this.__grow_capacity(),this.__size++;const i=bg*t,n=this.__data_float32;n[i]=Number.POSITIVE_INFINITY,n[i+1]=Number.POSITIVE_INFINITY,n[i+2]=Number.POSITIVE_INFINITY,n[i+3]=Number.NEGATIVE_INFINITY,n[i+4]=Number.NEGATIVE_INFINITY,n[i+5]=Number.NEGATIVE_INFINITY;const s=this.__data_uint32;return s[i+6]=wg,s[i+7]=wg,s[i+8]=wg,s[i+9]=0,t}release_node(t){this.__free[this.__free_pointer++]=t}node_is_leaf(t){return this.__data_uint32[bg*t+7]===wg}node_get_user_data(t){return this.__data_uint32[bg*t+8]}node_set_user_data(t,e){this.__data_uint32[bg*t+8]=e}node_get_child1(t){return this.__data_uint32[bg*t+7]}node_set_child1(t,e){this.__data_uint32[bg*t+7]=e}node_get_child2(t){return this.__data_uint32[bg*t+8]}node_set_child2(t,e){this.__data_uint32[bg*t+8]=e}node_get_parent(t){return this.__data_uint32[bg*t+6]}node_set_parent(t,e){this.__data_uint32[bg*t+6]=e}node_get_height(t){return this.__data_uint32[bg*t+9]}node_set_height(t,e){this.__data_uint32[bg*t+9]=e}node_get_aabb(t,e){const i=bg*t,n=this.__data_float32;e[0]=n[i],e[1]=n[i+1],e[2]=n[i+2],e[3]=n[i+3],e[4]=n[i+4],e[5]=n[i+5]}node_set_aabb(t,e){const i=bg*t,n=this.__data_float32;n[i]=e[0],n[i+1]=e[1],n[i+2]=e[2],n[i+3]=e[3],n[i+4]=e[4],n[i+5]=e[5]}node_move_aabb(t,e){this.node_set_aabb(t,e);const i=this.__data_uint32[bg*t+6];i!==wg&&this.bubble_up_refit(i)}node_set_aabb_primitive(t,e,i,n,s,r,a){const o=bg*t,l=this.__data_float32;l[o]=e,l[o+1]=i,l[o+2]=n,l[o+3]=s,l[o+4]=r,l[o+5]=a}node_get_surface_area(t){const e=bg*t,i=this.__data_float32;return nd(i[e],i[e+1],i[e+2],i[e+3],i[e+4],i[e+5])}node_get_combined_surface_area(t,e){const i=bg*t,n=bg*e,s=this.__data_float32;return nd(ru(s[i],s[n]),ru(s[i+1],s[n+1]),ru(s[i+2],s[n+2]),Eu(s[i+3],s[n+3]),Eu(s[i+4],s[n+4]),Eu(s[i+5],s[n+5]))}node_set_combined_aabb(t,e,i){const n=bg*e,s=bg*i,r=this.__data_float32,a=ru(r[n],r[s]),o=ru(r[n+1],r[s+1]),l=ru(r[n+2],r[s+2]),h=Eu(r[n+3],r[s+3]),c=Eu(r[n+4],r[s+4]),u=Eu(r[n+5],r[s+5]),d=t*bg;r[d]=a,r[d+1]=o,r[d+2]=l,r[d+3]=h,r[d+4]=c,r[d+5]=u}insert_leaf(t){let e=this.__data_uint32;if(this.__root===wg)return this.__root=t,void(e[t*bg+6]=wg);let i=this.__root;for(;!1===this.node_is_leaf(i);){const n=e[i*bg+7],s=e[i*bg+8],r=this.node_get_surface_area(i),a=this.node_get_combined_surface_area(i,t),o=2*a,l=2*(a-r);let h,c;if(this.node_is_leaf(n))h=this.node_get_combined_surface_area(t,n)+l;else{const e=this.node_get_surface_area(n);h=this.node_get_combined_surface_area(t,n)-e+l}if(this.node_is_leaf(s))c=this.node_get_combined_surface_area(t,s)+l;else{const e=this.node_get_surface_area(s);c=this.node_get_combined_surface_area(t,s)-e+l}if(o<h&&o<c)break;i=h<c?n:s}const n=i,s=e[n*bg+6],r=this.allocate_node();e=this.__data_uint32,e[r*bg+6]=s,this.node_set_combined_aabb(r,t,n),e[r*bg+9]=e[n*bg+9]+1,s!==wg?e[s*bg+7]===n?e[s*bg+7]=r:e[s*bg+8]=r:this.__root=r,e[r*bg+7]=n,e[r*bg+8]=t,e[n*bg+6]=r,e[t*bg+6]=r,this.bubble_up_update(r)}bubble_up_refit(t){let e=t;const i=this.__data_uint32;do{e=this.balance(e);const t=e*bg,n=i[t+7],s=i[t+8];this.node_set_combined_aabb(e,n,s),e=i[t+6]}while(e!==wg)}bubble_up_update(t){let e=t;const i=this.__data_uint32;for(;e!==wg;){e=this.balance(e);const t=e*bg,n=i[t+7],s=i[t+8];i[t+9]=1+Eu(i[n*bg+9],i[s*bg+9]),this.node_set_combined_aabb(e,n,s),e=i[t+6]}}remove_leaf(t){if(t===this.__root)return void(this.__root=wg);const e=this.__data_uint32,i=e[t*bg+6],n=e[i*bg+6];let s;const r=e[i*bg+7];s=r===t?e[i*bg+8]:r,n!==wg?(e[n*bg+7]===i?e[n*bg+7]=s:e[n*bg+8]=s,e[s*bg+6]=n,this.release_node(i),this.bubble_up_update(n)):(this.__root=s,e[s*bg+6]=wg,this.release_node(i))}balance(t){const e=this.__data_uint32;if(this.node_is_leaf(t)||e[t*bg+9]<2)return t;const i=e[t*bg+7],n=e[t*bg+8],s=e[n*bg+9]-e[i*bg+9];if(s>1){const s=e[n*bg+7],r=e[n*bg+8];e[n*bg+7]=t;const a=e[t*bg+6];return e[n*bg+6]=a,e[t*bg+6]=n,a!==wg?e[a*bg+7]===t?e[a*bg+7]=n:e[a*bg+8]=n:this.__root=n,e[s*bg+9]>e[r*bg+9]?(e[n*bg+8]=s,e[t*bg+8]=r,e[r*bg+6]=t,this.node_set_combined_aabb(t,i,r),this.node_set_combined_aabb(n,t,s),e[t*bg+9]=1+Eu(e[i*bg+9],e[r*bg+9]),e[n*bg+9]=1+Eu(e[t*bg+9],e[s*bg+9])):(e[n*bg+8]=r,e[t*bg+8]=s,e[s*bg+6]=t,this.node_set_combined_aabb(t,i,s),this.node_set_combined_aabb(n,t,r),e[t*bg+9]=1+Eu(e[i*bg+9],e[s*bg+9]),e[n*bg+9]=1+Eu(e[t*bg+9],e[r*bg+9])),n}if(s<-1){const s=e[i*bg+7],r=e[i*bg+8];e[i*bg+7]=t;const a=e[t*bg+6];return e[i*bg+6]=a,e[t*bg+6]=i,a!==wg?e[a*bg+7]===t?e[a*bg+7]=i:e[a*bg+8]=i:this.__root=i,e[s*bg+9]>e[r*bg+9]?(e[i*bg+8]=s,e[t*bg+7]=r,e[r*bg+6]=t,this.node_set_combined_aabb(t,n,r),this.node_set_combined_aabb(i,t,s),e[t*bg+9]=1+Eu(e[n*bg+9],e[r*bg+9]),e[i*bg+9]=1+Eu(e[t*bg+9],e[s*bg+9])):(e[i*bg+8]=r,e[t*bg+7]=s,e[s*bg+6]=t,this.node_set_combined_aabb(t,n,s),this.node_set_combined_aabb(i,t,r),e[t*bg+9]=1+Eu(e[n*bg+9],e[s*bg+9]),e[i*bg+9]=1+Eu(e[t*bg+9],e[r*bg+9])),i}return t}release_all(){this.__root=wg,this.__size=0,this.__free_pointer=0}traverse(t,e){let i=0;const n=[],s=this.__root;s!==wg&&(n[i++]=s);const r=this.__data_uint32;for(;i>0;){i--;const s=n[i];t.call(e,s,this);const a=s*bg,o=r[a+7],l=r[a+8];o!==wg&&(n[i++]=l,n[i++]=o)}}collect_nodes_all(t,e){let i=e;return this.traverse((e=>{t[i++]=e})),i-e}__move_node_links(t,e){const i=this.__data_uint32,n=t*bg,s=i[n+7],r=i[n+8];s!==wg&&(i[s*bg+6]=e,i[r*bg+6]=e);const a=i[n+6];a!==wg&&(i[a*bg+7]===t?i[a*bg+7]=e:i[a*bg+8]=e)}swap_nodes(t,e){const i=this.__data_uint32,n=t*bg,s=e*bg;return i[n+6]!==e&&i[s+6]!==t&&(this.__move_node_links(t,e),this.__move_node_links(e,t),Rd(i,n,this.__free,this.__free_pointer,bg),Rd(i,s,i,n,bg),Rd(this.__free,this.__free_pointer,i,s,bg),this.__root===t?this.__root=e:this.__root===e&&(this.__root=t),!0)}}function Mg(t,e){return td(t[0],t[1],t[2],t[3],t[4],t[5],e)}const Tg=[];function Cg(t,e,i,n){if(n===wg)return 0;let s=0;Tg[s++]=n;let r=e;for(;s>0;){s--;const e=Tg[s];if(i.node_is_leaf(e))t[r++]=i.node_get_user_data(e);else{const t=i.node_get_child1(e),n=i.node_get_child2(e);Tg[s++]=t,Tg[s++]=n}}return r-e}const Ag=[],Eg=[];function zg(t,e,i,n){const s=i.root;if(s===wg)return 0;let r=1;Ag[0]=s;let a=e;for(;r>0;){r--;const e=Ag[r];i.node_get_aabb(e,Eg);const s=Mg(Eg,n);if(0!==s)if(i.node_is_leaf(e))t[a++]=i.node_get_user_data(e);else if(2===s)a+=Cg(t,a,i,e);else{const t=i.node_get_child1(e),n=i.node_get_child2(e);Ag[r++]=t,Ag[r++]=n}}return a-e}const Ig=[];class Ng{constructor(){this.adapters=[new xg,new yg]}*maintain(){const t=this.adapters;for(let e=0;e<t.length;e++){const i=t[e];void 0!==i&&(yield*i.maintain())}}setAdapter(t,e){const i=this.adapters[t];void 0!==i&&i.dispose(),this.adapters[t]=e}removeAdapter(t){const e=this.adapters[t];return void 0!==e&&(delete this.adapters[t],e.dispose(),!0)}collect(t,e,i,n,s,r){const a=this.adapters,o=a.length;let l=0,h=0;for(;l<o;l++)a[l].build_start(i,n);const c=zg(Ig,0,s,n.frustum),u=r.computeComponentTypeIndex(_m);for(l=0;l<c;l++){const t=Ig[l],e=r.getComponentByIndex(t,u);0!=(16&e.flags)&&e.material.visible&&a[e.draw_method].add(e)}let d=0;for(l=0;l<o;l++){const i=a[l];i.build_end();const n=i.object_count;for(h=0;h<n;h++){const n=i.objects[h];t[e+d]=n,d++}}return d}dispose(){for(const t of this.adapters)void 0!==t&&t.dispose()}}const Lg=[];let Pg=0;function Fg(t,e,i,n){const s=Pg,r=i.root;if(r===wg)return 0;Lg[Pg++]=r;let a=e;for(;Pg>s;){Pg--;const e=Lg[Pg];if(n.evaluate(e,i))if(i.node_is_leaf(e))t[a++]=e;else{const t=i.node_get_child1(e),n=i.node_get_child2(e);Lg[Pg++]=n,Lg[Pg++]=t}}return Pg=s,a-e}class Dg{evaluate(t,e){throw new Error("Not Implemented")}}const Og=[];class Rg extends Dg{constructor(){super(),this.ray=[]}static from(t){const e=new Rg;return e.ray=t,e}evaluate(t,e){return e.node_get_aabb(t,Og),function(t,e){return id(t[0],t[1],t[2],t[3],t[4],t[5],e[0],e[1],e[2],e[3],e[4],e[5])}(Og,this.ray)}}class kg{constructor(){this.__system=null,this.__entity_iterator=null}step(){const t=this.__system;if(null===t)return!1;const e=t.entityManager.dataset;if(null===e)return!1;if(!e.isComponentTypeRegistered(_m))return!1;null===this.__entity_iterator&&(this.__entity_iterator=e.createEntityIterator());const i=this.__entity_iterator.next();if(i.done)return this.__entity_iterator=e.createEntityIterator(),!1;const n=i.value;if(!e.entityExists(n))return this.__entity_iterator=null,!1;const s=e.getComponent(n,_m);if(void 0===s)return!1;if(s.getFlag(8))return!1;const r=t.getGeometryUsageCounters().get(s.geometry.id),a=t.__view_contexts.values().next().value;if(void 0===a)return!1;const o=a.adapters,l=o.length;let h=Number.NEGATIVE_INFINITY,c=-1;for(let t=0;t<l;t++){const e=o[t].score(s.geometry,s.material,r);e>h&&(h=e,c=t)}return-1!==c&&s.draw_method!==c&&!!o[c].intend_draw(s)&&(s.draw_method=c,!0)}}const Ug=new lp,Bg=new Float32Array(6);function Vg(t,e){for(let i in t)if(t[i]===e)return i}const Gg={New:"new",Initializing:"initializing",Initialized:"initialized",Finalizing:"finalizing",Finalized:"finalized",Starting:"starting",Running:"running",Stopping:"stopping",Stopped:"stopped"};class Wg{constructor(){this.id="",this.__state=new Tm(Gg.New,Gg)}getState(){return this.__state}initialize(){const t=this.__state.getValue();if(t!==Gg.New&&t!==Gg.Finalized)throw new Rf(`Expected New or Finalized state, instead got ${Vg(Gg,t)}`);this.__state.set(Gg.Initialized)}finalize(){const t=this.__state;if(t.getValue()===Gg.Running&&this.shutdown(),t.getValue()!==Gg.Stopped&&t.getValue()!==Gg.Initialized)throw new Rf(`Expected Initialized or Stopped state, instead got ${Vg(Gg,t.getValue())}`);t.set(Gg.Finalized)}startup(){const t=this.__state.getValue();if(t!==Gg.Initialized&&t!==Gg.Stopped)throw new Rf(`Expected Initial state, instead got ${Vg(Gg,t)}`);this.__state.set(Gg.Running)}shutdown(){this.__state.set(Gg.Stopped)}}class Hg extends Wg{constructor(){super(),this.__dependencies=[],this.engine=null}attach(){this.id="",this.engine=null}get dependencies(){return this.__dependencies}initialize(t){this.engine=t,super.initialize()}finalize(){super.finalize()}async startup(){return super.startup(),Promise.resolve()}async shutdown(){return super.shutdown(),Promise.resolve()}}const jg={defines:{NUM_SAMPLES:7,NUM_RINGS:4,NORMAL_TEXTURE:0,DIFFUSE_TEXTURE:0,DEPTH_PACKING:1,PERSPECTIVE_CAMERA:1},uniforms:{tDepth:{value:null},tNormal:{value:null},size:{value:new bi(512,512)},cameraNear:{value:1},cameraFar:{value:100},cameraProjectionMatrix:{value:new pn},cameraInverseProjectionMatrix:{value:new pn},intensity:{value:.1},bias:{value:.5},minResolution:{value:0},kernelRadius:{value:100},randomSeed:{value:0}},vertexShader:"\n\n\t\tvarying vec2 vUv;\n\n\t\tvoid main() {\n\t\t\tvUv = uv;\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\t\t}",fragmentShader:"\n\n\t\t#include <common>\n\n\t\tvarying vec2 vUv;\n\n\t\tuniform sampler2D tDepth;\n\n\t\t#if NORMAL_TEXTURE == 1\n\t\tuniform sampler2D tNormal;\n\t\t#endif\n\n\t\tuniform float cameraNear;\n\t\tuniform float cameraFar;\n\t\tuniform mat4 cameraProjectionMatrix;\n\t\tuniform mat4 cameraInverseProjectionMatrix;\n\n\t\tuniform float intensity;\n\t\tuniform float bias;\n\t\tuniform float kernelRadius;\n\t\tuniform float minResolution;\n\t\tuniform vec2 size;\n\t\tuniform float randomSeed;\n\n\t\t// RGBA depth\n\n\t\t#include <packing>\n\t\t\n\t\tout float out_occlusion;\n\n\t\tfloat getDepth( const in vec2 screenPosition ) {\n\t\t\t#if DEPTH_PACKING == 1\n\t\t\treturn unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );\n\t\t\t#else\n\t\t\treturn texture2D( tDepth, screenPosition ).x;\n\t\t\t#endif\n\t\t}\n\n\t\tfloat getViewZ( const in float depth ) {\n\t\t\t#if PERSPECTIVE_CAMERA == 1\n\t\t\treturn perspectiveDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#else\n\t\t\treturn orthographicDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#endif\n\t\t}\n\n\t\tvec3 getViewPosition( const in vec2 screenPosition, const in float depth, const in float viewZ ) {\n\t\t\tfloat clipW = cameraProjectionMatrix[2][3] * viewZ + cameraProjectionMatrix[3][3];\n\t\t\tvec4 clipPosition = vec4( ( vec3( screenPosition, depth ) - 0.5 ) * 2.0, 1.0 );\n\t\t\tclipPosition *= clipW; // unprojection.\n\n\t\t\treturn ( cameraInverseProjectionMatrix * clipPosition ).xyz;\n\t\t}\n\n\t\tvec3 getViewNormal( const in vec3 viewPosition, const in vec2 screenPosition ) {\n\t\t\t#if NORMAL_TEXTURE == 1\n\t\t\treturn unpackRGBToNormal( texture2D( tNormal, screenPosition ).xyz );\n\t\t\t#else\n\t\t\treturn normalize( cross( dFdx( viewPosition ), dFdy( viewPosition ) ) );\n\t\t\t#endif\n\t\t}\n\t\t\n\t\t// Non-sin based hash function, fast and has good randomness\n float hash12(vec2 p){\n vec3 p3 = fract(vec3(p.xyx) * .1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n }\n \n\t\tfloat minResolutionMultipliedByCameraFar;\n\n\t\tfloat getOcclusion( const in vec3 centerViewPosition, const in vec3 centerViewNormal, const in vec3 sampleViewPosition ) {\n\t\t\tvec3 viewDelta = sampleViewPosition - centerViewPosition;\n\t\t\t\n\t\t\tfloat viewDistance = length( viewDelta );\n\t\t\t\n float vn = dot( centerViewNormal, viewDelta );\n float a2 = (vn - minResolutionMultipliedByCameraFar) / viewDistance - bias;\n float a1 = (1.0 + pow2( viewDistance ) );\n \n\t\t\treturn max(0.0, a2) / a1;\n\t\t}\n\n\t\t// moving costly divides into consts\n\t\tconst float ANGLE_STEP = PI2 * float( NUM_RINGS ) / float( NUM_SAMPLES );\n\t\tconst float INV_NUM_SAMPLES = 1.0 / float( NUM_SAMPLES );\n\n\t\tfloat getAmbientOcclusion( const in vec3 centerViewPosition ) {\n\t\t\t// precompute some variables require in getOcclusion.\n\t\t\tminResolutionMultipliedByCameraFar = minResolution * cameraFar;\n\t\t\tvec3 centerViewNormal = getViewNormal( centerViewPosition, vUv );\n\n\t\t\t// jsfiddle that shows sample pattern: https://jsfiddle.net/a16ff1p7/\n\t\t\tfloat angle = hash12( vUv + randomSeed ) * PI2;\n\t\t\tvec2 radius = vec2( kernelRadius * INV_NUM_SAMPLES ) / size;\n\n\t\t\tfloat occlusionSum = 0.0;\n\t\t\tfloat weightSum = 0.0;\n\n\t\t\tfor( int i = 0; i < NUM_SAMPLES; i ++ ) {\n\t\t\t\tvec2 sampleUv = vUv + vec2( cos( angle ), sin( angle ) ) * radius * float(i+1);\n\t\t\t\t\n\t\t\t\tangle += ANGLE_STEP;\n\n\t\t\t\tfloat sampleDepth = getDepth( sampleUv );\n\t\t\t\t\n\t\t\t\tif( sampleDepth >= ( 1.0 - EPSILON ) ) {\n\t\t\t\t // skip, too far\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tfloat sampleViewZ = getViewZ( sampleDepth );\n\t\t\t\t\n\t\t\t\tvec3 sampleViewPosition = getViewPosition( sampleUv, sampleDepth, sampleViewZ );\n\t\t\t\t\n\t\t\t\tocclusionSum += getOcclusion( centerViewPosition, centerViewNormal, sampleViewPosition );\n\t\t\t\t\n\t\t\t\tweightSum += 1.0;\n\t\t\t}\n\n\t\t\tif( weightSum == 0.0 ) discard;\n\n\t\t\treturn occlusionSum * ( intensity / weightSum );\n\t\t}\n\n\t\tvoid main() {\n\t\t\tfloat centerDepth = getDepth( vUv );\n\t\t\tif( centerDepth >= ( 1.0 - EPSILON ) ) {\n\t\t\t\tdiscard;\n\t\t\t}\n\n\t\t\tfloat centerViewZ = getViewZ( centerDepth );\n\t\t\tvec3 viewPosition = getViewPosition( vUv, centerDepth, centerViewZ );\n\n\t\t\tfloat ambientOcclusion = getAmbientOcclusion( viewPosition );\n\t\t\t\n\t\t\tfloat invOcclusion = 1.0 - ambientOcclusion;\n\t\t\t\n\t\t\tout_occlusion = invOcclusion;\n\t\t}"},qg=function(t=["r","g","b","a"]){return`\n uniform sampler2D tTexture;\n varying vec2 vUv;\n \n void main(){\n vec4 texel = texture2D( tTexture, vUv );\n gl_FragColor = ${function(t,e){const i=[],n=e.length;for(let t=0;t<n;t++){const n=e[t];if("string"==typeof n)i[t]=`texel.${n}`;else{if("number"!=typeof n)throw new Error(`Unsupported swizzle token '${n}'`);i[t]=Number(n).toFixed(4)}}const s=i.join(", "),r=[void 0,"float","vec2","vec3","vec4"][e.length];if(void 0===r)throw new Error(`No constructor for input length ${e.length}`);return`${r}(${s})`}(0,t)};\n }\n `};function Jg(t,e){if(e===Iu.MultiplyAdd)t.blending=U,t.blendEquation=B,t.blendSrc=q,t.blendDst=Z;else{const i=function(t){let e;if(t===Iu.NoBlending)e=F;else if(t===Iu.Normal)e=D;else if(t===Iu.Add)e=O;else if(t===Iu.Subtract)e=R;else{if(t!==Iu.Multiply)throw new TypeError(`Unsupported blending type ${t}`);e=k}return e}(e);t.blending=i}}class Yg{constructor({renderTarget:t,blending:e,renderTargetScale:i=1}){this.name="",this.__blending=e,this.renderTarget=t,this.renderTargetScale=i,this.object=new Rs(Uf,this.buildMaterial()),this.stage=0,this.size=new wd,this.__enabled=!0,this.__order=0,this.on={preRender:new l}}get blending(){return this.__blending}set blending(t){t!==this.__blending&&(this.__blending=t,Jg(this.object.material,t))}set order(t){this.__order=t,this.object.renderOrder=t}get order(){return this.__order}set enabled(t){!this.__enabled&&t?this.enable():this.__enabled&&!t&&this.disable()}get enabled(){return this.__enabled}enable(){this.__enabled||(this.__enabled=!0,this.object.visible=!0)}disable(){this.__enabled&&(this.__enabled=!1,this.object.visible=!1)}setSize(t,e){this.size.set(t,e),this.updateRenderTargetSize()}updateRenderTargetSize(){if(null!==this.renderTarget){const t=this.renderTargetScale,e=this.size,i=e.x*t,n=e.y*t;this.renderTarget.setSize(i,n)}}setRenderTargetScale(t){this.renderTargetScale=t,this.updateRenderTargetSize()}setCustomMaterial(t){Jg(t,this.blending),this.object.material=t}buildMaterial(){const t={tTexture:{type:"t",value:this.renderTarget.texture}};let e;const i=this.renderTarget.texture.format;if(i===te)e=["r","r","r",1];else{if(i!==Yt)throw new Error("Unsupported format");e=["r","g","b","a"]}const n=new Ws({uniforms:t,vertexShader:"\n varying vec2 vUv;\n \n void main() {\n \n vUv = uv;\n gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );\n \n }\n ",fragmentShader:qg(e),lights:!1,fog:!1,depthTest:!1,depthWrite:!1,transparent:!0,vertexColors:!1});return Jg(n,this.blending),n}}const Xg={defines:{KERNEL_RADIUS:4,DEPTH_PACKING:1,PERSPECTIVE_CAMERA:1},uniforms:{tDiffuse:{value:null},size:{value:new bi(512,512)},sampleUvOffsets:{value:[new bi(0,0)]},sampleWeights:{value:[1]},tDepth:{value:null},cameraNear:{value:10},cameraFar:{value:1e3},depthCutoff:{value:10}},vertexShader:"\n\n\t\t#include <common>\n\n\t\tuniform vec2 size;\n\n\t\tvarying vec2 vUv;\n\t\tvarying vec2 vInvSize;\n\n\t\tvoid main() {\n\t\t\tvUv = uv;\n\t\t\tvInvSize = 1.0 / size;\n\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\t\t}",fragmentShader:"\n\n\t\t#include <common>\n\t\t#include <packing>\n\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform sampler2D tDepth;\n\n\t\tuniform float cameraNear;\n\t\tuniform float cameraFar;\n\t\tuniform float depthCutoff;\n\n\t\tuniform vec2 sampleUvOffsets[ KERNEL_RADIUS + 1 ];\n\t\tuniform float sampleWeights[ KERNEL_RADIUS + 1 ];\n\n\t\tvarying vec2 vUv;\n\t\tvarying vec2 vInvSize;\n\n\t\tfloat getDepth( const in vec2 screenPosition ) {\n\t\t\t#if DEPTH_PACKING == 1\n\t\t\treturn unpackRGBAToDepth( texture2D( tDepth, screenPosition ) );\n\t\t\t#else\n\t\t\treturn texture2D( tDepth, screenPosition ).x;\n\t\t\t#endif\n\t\t}\n\n\t\tfloat getViewZ( const in float depth ) {\n\t\t\t#if PERSPECTIVE_CAMERA == 1\n\t\t\treturn perspectiveDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#else\n\t\t\treturn orthographicDepthToViewZ( depth, cameraNear, cameraFar );\n\t\t\t#endif\n\t\t}\n\n\t\tvoid main() {\n\t\t\tfloat depth = getDepth( vUv );\n\t\t\tif( depth >= ( 1.0 - EPSILON ) ) {\n\t\t\t\tdiscard;\n\t\t\t}\n\n\t\t\tfloat centerViewZ = -getViewZ( depth );\n\t\t\tbool rBreak = false, lBreak = false;\n\n\t\t\tfloat weightSum = sampleWeights[0];\n\t\t\tvec4 diffuseSum = texture2D( tDiffuse, vUv ) * weightSum;\n\n\t\t\tfor( int i = 1; i <= KERNEL_RADIUS; i ++ ) {\n\n\t\t\t\tfloat sampleWeight = sampleWeights[i];\n\t\t\t\tvec2 sampleUvOffset = sampleUvOffsets[i] * vInvSize;\n\n\t\t\t\tvec2 sampleUv = vUv + sampleUvOffset;\n\t\t\t\tfloat viewZ = -getViewZ( getDepth( sampleUv ) );\n\n\t\t\t\tif( abs( viewZ - centerViewZ ) > depthCutoff ) rBreak = true;\n\n\t\t\t\tif( ! rBreak ) {\n\t\t\t\t\tdiffuseSum += texture2D( tDiffuse, sampleUv ) * sampleWeight;\n\t\t\t\t\tweightSum += sampleWeight;\n\t\t\t\t}\n\n\t\t\t\tsampleUv = vUv - sampleUvOffset;\n\t\t\t\tviewZ = -getViewZ( getDepth( sampleUv ) );\n\n\t\t\t\tif( abs( viewZ - centerViewZ ) > depthCutoff ) lBreak = true;\n\n\t\t\t\tif( ! lBreak ) {\n\t\t\t\t\tdiffuseSum += texture2D( tDiffuse, sampleUv ) * sampleWeight;\n\t\t\t\t\tweightSum += sampleWeight;\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tgl_FragColor = diffuseSum / weightSum;\n\t\t}"},Zg={createSampleWeights:function(t,e){const i=[];for(let n=0;n<=t;n++)i.push($g(n,e));return i},createSampleOffsets:function(t,e){const i=[];for(let n=0;n<=t;n++)i.push(e.clone().multiplyScalar(n));return i},configure:function(t,e,i,n){t.defines.KERNEL_RADIUS=e,t.uniforms.sampleUvOffsets.value=Zg.createSampleOffsets(e,n),t.uniforms.sampleWeights.value=Zg.createSampleWeights(e,i),t.needsUpdate=!0}};function $g(t,e){return Math.exp(-t*t/(e*e*2))/(Math.sqrt(2*Math.PI)*e)}const Kg=new Rs(Uf,null);Kg.frustumCulled=!1,Kg.matrixAutoUpdate=!1,Kg.matrixWorldNeedsUpdate=!1;const Qg=new mr(-1,1,1,-1,0,1),ty=new Zo;function ey(t,e){Kg.material=e,t.render(ty,Qg),Kg.material=null}ty.autoUpdate=!1,ty.matrixAutoUpdate=!1,ty.matrixWorldNeedsUpdate=!1,ty.add(Kg);const iy=new ss;class ny{constructor({format:t=Yt,radius:e=8,clear_color:i=0,clear_alpha:n=1}){this.__rt_input=null,this.__rt_output=null,this.__intermediate=new Pi({format:t}),this.__material_blur_x=new Ws({uniforms:Gs.clone(Xg.uniforms),defines:Object.assign({},Xg.defines),vertexShader:Xg.vertexShader,fragmentShader:Xg.fragmentShader,blending:F}),this.__material_blur_y=new Ws({uniforms:Gs.clone(Xg.uniforms),defines:Object.assign({},Xg.defines),vertexShader:Xg.vertexShader,fragmentShader:Xg.fragmentShader,blending:F}),this.__depth_cutoff=.01,this.__blur_radius=e,this.__blur_std_dev=4,this.__clear_color=new ss(i),this.__clear_alpha=n}configureMaterials(){const t=this.__material_blur_x,e=this.__material_blur_y;t.defines.DEPTH_PACKING=e.defines.DEPTH_PACKING=0,t.defines.PERSPECTIVE_CAMERA=e.defines.PERSPECTIVE_CAMERA=1,t.blending=e.blending=F,Zg.configure(t,this.__blur_radius,this.__blur_std_dev,new bi(1,0)),Zg.configure(e,this.__blur_radius,this.__blur_std_dev,new bi(0,1)),this.__material_blur_y.uniforms.tDiffuse.value=this.__intermediate.texture}setRenderCamera(t){const e=this.__material_blur_x,i=this.__material_blur_y;!0===t.isPerspectiveCamera&&1!==e.defines.PERSPECTIVE_CAMERA?(e.defines.PERSPECTIVE_CAMERA=1,i.defines.PERSPECTIVE_CAMERA=1,e.needsUpdate=!0,i.needsUpdate=!0):!0!==t.isPerspectiveCamera&&0!==e.defines.PERSPECTIVE_CAMERA&&(e.defines.PERSPECTIVE_CAMERA=0,i.defines.PERSPECTIVE_CAMERA=0,e.needsUpdate=!0,i.needsUpdate=!0);const n=this.__depth_cutoff*(t.far-t.near);e.uniforms.depthCutoff.value=n,i.uniforms.depthCutoff.value=n,e.uniforms.cameraNear.value=i.uniforms.cameraNear.value=t.near,e.uniforms.cameraFar.value=i.uniforms.cameraFar.value=t.far}execute(t){this.__intermediate.width===this.__rt_output.width&&this.__intermediate.height===this.__rt_output.height||this.__intermediate.setSize(this.__rt_output.width,this.__rt_output.height);const e=this.__material_blur_x,i=this.__material_blur_y;e.uniforms.size.value.set(this.__rt_output.width,this.__rt_output.height),i.uniforms.size.value.set(this.__rt_output.width,this.__rt_output.height);const n=t.getRenderTarget(),s=iy;t.getClearColor(s);const r=t.getClearAlpha(),a=t.autoClear;t.autoClear=!1,t.setClearColor(this.__clear_color),t.setRenderTarget(this.__intermediate),t.clearColor(),ey(t,e),t.setRenderTarget(this.__rt_output),t.clearColor(),ey(t,i),t.setRenderTarget(n),t.setClearColor(s,r),t.autoClear=a}setDepthBuffer(t){const e=this.__material_blur_x,i=this.__material_blur_y;e.uniforms.tDepth.value=i.uniforms.tDepth.value=t}setInput(t){this.__rt_input=t,this.__material_blur_x.uniforms.tDiffuse.value=t.texture}setOutput(t){this.__rt_output=t}dispose(){this.__intermediate.dispose()}}const sy="color-and-depth",ry="normal";function ay(t){return t.children instanceof Array}class oy{constructor(t,e){this.quietTime=t,this.workTime=e,this.queueUnresolved=[],this.queueReady=[],this.on={task_started:new l,task_completed:new l,completed:new l},this.policy=ly.ROUND_ROBIN}runGroup(t){const e=t.state.getValue();if(e!==Sf.INITIAL)throw new Rf(`Expected task state INITIAL, instead got ${Vg(Sf,e)}`);const i=this,n=t.children,s=n.length;let r=s,a=!1;function o(){a||(a=!0,t.state.set(Sf.SUCCEEDED),t.on.completed.send0(),i.prod())}function l(){r--,r<=0&&o()}function h(e){!function(e){a||(a=!0,t.state.set(Sf.FAILED),t.on.failed.send1(e),i.prod())}(e)}if(s>0){t.state.set(Sf.RUNNING);let e=0;for(;e<s;e++){const t=n[e];t.on.completed.add(l),t.on.failed.add(h),ay(t)?this.runGroup(t):this.run(t)}}else o()}removeGroup(t){const e=t.children,i=e.length;for(let t=0;t<i;t++){const i=e[t];ay(i)?this.removeGroup(i):this.removeTask(i)}}removeTask(t){const e=this.queueReady.indexOf(t);if(-1!==e)return this.queueReady.splice(e,1),!0;const i=this.queueUnresolved.indexOf(t);return-1!==i&&(this.queueUnresolved.splice(i,1),!0)}run(t){this.queueUnresolved.push(t),this.prod()}runMany(t){Array.prototype.push.apply(this.queueUnresolved,t),this.prod()}startTask(t){const e=performance.now();try{t.initialize(t,this)}catch(e){return t.state.set(Sf.FAILED),t.on.failed.dispatch(e),!1}finally{const i=performance.now()-e;t.__executedCpuTime+=i}return t.state.set(Sf.RUNNING),t.on.started.send1(this),this.queueReady.push(t),this.on.task_started.send1(t),!0}resolveTasks(){const t=this.queueUnresolved;let e=0,i=t.length;for(;e<i;e++){const n=t[e];switch(uy(n)){case cy.READY:t.splice(e,1),n.state.set(Sf.READY),this.startTask(n),e=0,i=t.length;break;case cy.FAILED:t.splice(e,1),i--,e--}}}contains(t){return-1!==this.queueUnresolved.indexOf(t)||-1!==this.queueReady.indexOf(t)}prod(){const t=this;let e=0;this.resolveTasks();const i=this.queueReady;let n,s;function r(){n=i.length}switch(this.policy){case oy.POLICY.ROUND_ROBIN:s=function(){return i[e++%n]};break;case oy.POLICY.SEQUENTIAL:default:s=function(){return i[0]}}function a(e){const n=i.indexOf(e);-1!==n&&i.splice(n,1),e.state.set(Sf.SUCCEEDED),e.on.completed.send1(t),t.resolveTasks(),r(),t.on.task_completed.send1(e)}function o(e,n){const s=i.indexOf(e);-1!==s&&i.splice(s,1),e.state.set(Sf.FAILED),e.on.failed.dispatch(n),t.resolveTasks(),r(),t.on.task_completed.send1(e)}r(),!this.busy&&n>0&&(this.busy=!0,function e(){let i=t.workTime,l=0;for(;n>0;){const t=s();if(void 0===t)break;try{l=hy(t,i,a,o)}catch(e){o(t,e)}if(i-=Math.max(l,1),i<=0)break}r(),n>0?setTimeout(e,t.quietTime):(t.busy=!1,t.on.completed.send0())}())}join(t){0===this.queueReady.length&&0===this.queueUnresolved.length?t():this.on.completed.addOne(t)}}const ly={ROUND_ROBIN:0,SEQUENTIAL:1,TIME_SLICE:2};function hy(t,e,i,n){let s=0;const r=t.cycle,a=performance.now(),o=a+e;let l,h=a+1e-6;for(;h<o;)if(s++,l=r(),h=performance.now(),l!==bf.Continue){if(l===bf.Yield)break;if(l===bf.EndSuccess)break;if(l===bf.EndFailure)break;throw new Error(`Task '${t.name}' produced unknown signal: `+l)}const c=h-a;return t.__executedCpuTime+=c,t.__executedCycleCount+=s,l===bf.EndSuccess?i(t):l===bf.EndFailure&&n(t,"Task signalled failure"),c}oy.POLICY=ly;const cy={READY:0,FAILED:1,UNRESOLVED:2};function uy(t){const e=t.dependencies;let i=0;const n=e.length;for(;i<n;i++)switch(e[i].state.getValue()){case Sf.INITIAL:case Sf.RUNNING:case Sf.READY:return cy.UNRESOLVED;case Sf.SUCCEEDED:break;default:case Sf.FAILED:return cy.FAILED}return cy.READY}const dy=function(t,e,i){this.__value=void 0!==t?t:0,this.__limitUpper=void 0!==e?e:0,this.__limitLower=void 0!==i?i:0,this.onChanged=new l,this.onOverflow=new l,this.onFilled=new l,this.on={changed:this.onChanged,overflow:this.onOverflow}};dy.prototype.setUpperLimit=function(t){const e=this.__limitUpper;t!==e&&(this.__limitUpper=t,this.onChanged.send4(this.__value,this.__limitUpper,this.__value,e))},dy.prototype.getUpperLimit=function(){return this.__limitUpper},dy.prototype.getLowerLimit=function(){return this.__limitLower},dy.prototype.setLowerLimit=function(t){t!==this.__limitLower&&(this.__limitLower=t,this.onChanged.dispatch())},dy.prototype.setValue=function(t){const e=this.__value;if(e===t)return;const i=t-this.__limitUpper;this.__value=t,this.onChanged.send4(this.__value,this.__limitUpper,e,this.__limitUpper),i>0&&this.onOverflow.send1(i),i>=0&&this.onFilled.send0()},dy.prototype.getValue=function(){return this.__value},dy.prototype.getFraction=function(){return Mp(this.__limitLower,this.__limitUpper,this.__value)},dy.prototype.setValueToLimit=function(){this.setValue(this.__limitUpper)},dy.prototype.isValueAtLimit=function(){return this.__value===this.__limitUpper},dy.prototype.addValue=function(t){this.setValue(this.__value+t)},dy.prototype.copy=function(t){return this.setUpperLimit(t.getUpperLimit()),this.setValue(t.getValue()),this},dy.prototype.equals=function(t){return this.__value===t.__value&&this.__limitLower===t.__limitLower&&this.__limitUpper===t.__limitUpper},dy.prototype.hash=function(){const t=x(this.__value),e=(t<<5)-t+x(this.__limitLower);return(e<<5)-e+x(this.__limitUpper)},dy.prototype.toJSON=function(){return{value:this.__value,limit:this.__limitUpper}},dy.prototype.fromJSON=function(t){this.setUpperLimit(t.limit),this.setValue(t.value)},dy.prototype.toBinaryBuffer=function(t){t.writeFloat64(this.__value),t.writeFloat64(this.__limitUpper)},dy.prototype.fromBinaryBuffer=function(t){const e=t.readFloat64(),i=t.readFloat64();this.setUpperLimit(i),this.setValue(e)};class py{constructor(t=new Map){this.on={set:new l,deleted:new l},this.data=t}get(t){return this.data.get(t)}set(t,e){return this.data.set(t,e),this.on.set.send2(t,e),this}delete(t){const e=this.data.delete(t);return e&&this.on.deleted.send1(t),e}forEach(t,e){this.data.forEach(t,e)}get size(){return this.data.size}}class fy{constructor({keyHashFunction:t=Xp,keyEqualityFunction:e=Yp,capacity:i}={}){this.__map=new $p({keyHashFunction:t,keyEqualityFunction:e,capacity:i})}get size(){return this.__map.size}add(t){return this.__map.set(t,t),this}clear(){this.__map.clear()}delete(t){return this.__map.delete(t)}has(t){return this.__map.has(t)}*[Symbol.iterator](){for(const t of this.__map.keys())yield t}keys(){return this.__map.keys()}values(){return this.__map.keys()}entries(){throw new Error("Not implemented")}get(t){return this.__map.get(t)}forEach(t,e){for(const i of this.values())t.call(e,i,i,this)}ensure(t){const e=this.get(t);return void 0!==e?e:(this.add(t),t)}}class my{constructor(t,e){this.path=t,this.type=e}equals(t){return this.path===t.path&&this.type===t.type}hash(){return Cd(Nd(this.path),Nd(this.type))}toString(){return`{ type: '${this.type}', path: '${this.path}' }`}}function _y(t){let e=t-1;return e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e}class gy{constructor(t=16){const e=_y(Eu(16,t));this.__data=new Array(e),this.__head=0,this.__tail=0,this.__status=1}resetStatus(t){const e=this.__head,i=this.__tail;this.__status=e===i?t?0:1:2}__circularBiggerPos(t){const e=t+1;return e>=this.__data.length?0:e}__circularSmallerPos(t){const e=t-1;return e<0?this.__data.length-1:e}__checkAndExpand(){if(0!==this.__status)return;const t=this.__data.length;if(Number.MAX_SAFE_INTEGER===t)throw new Error("Maximum array size exceeded");let e=2*t;e<0&&(e=Number.MAX_SAFE_INTEGER);const i=new Array(e),n=this.__head;Rd(this.__data,n,i,0,t-n),Rd(this.__data,0,i,t-n,n),this.__head=0,this.__tail=t,this.__status=2,this.__data=i}isEmpty(){return 0===this.size()}clear(){if(1!==this.__status){let t=this.__head;const e=this.__tail;do{this.__data[t]=void 0,t=this.__circularBiggerPos(t)}while(t!==e);this.__status=1}this.__head=0,this.__tail=0}size(){const t=this.__data;if(0===this.__status)return t.length;const e=this.__head,i=this.__tail;return e<=i?i-e:i+t.length-e}__removeInternal(t,e){let i=t;if(e){const t=this.__head;for(;i!==t;){const t=this.__circularSmallerPos(i);this.__data[i]=this.__data[t],i=t}this.__head=this.__circularBiggerPos(t)}else{const t=this.__tail;for(;i!==t;){const t=this.__circularBiggerPos(i);this.__data[i]=this.__data[t],i=t}this.__tail=this.__circularSmallerPos(t)}this.__data[i]=void 0,this.resetStatus(!1)}remove(t){const e=this.__index_of(t);return-1!==e&&(this.__removeInternal(e,!0),!0)}__index_of(t){const e=this.size(),i=this.__data,n=i.length;for(let s=0;s<e;s++)if(i[(this.__head+s)%n]===t)return s;return-1}has(t){return-1!==this.__index_of(t)}addFirst(t){this.__checkAndExpand(),this.__head=this.__circularSmallerPos(this.__head),this.__data[this.__head]=t,this.resetStatus(!0)}removeFirst(){const t=this.__data[this.__head];return this.__data[this.__head]=void 0,this.__head=this.__circularBiggerPos(this.__head),this.resetStatus(!1),t}getFirst(){return this.__data[this.__head]}addLast(t){this.__checkAndExpand(),this.__data[this.__tail]=t,this.__tail=this.__circularBiggerPos(this.__tail),this.resetStatus(!0)}removeLast(){const t=this.__circularSmallerPos(this.__tail),e=this.__data[t];return this.__data[t]=void 0,this.__tail=t,this.resetStatus(!1),e}getLast(){const t=this.__circularSmallerPos(this.__tail);return this.__data[t]}}gy.prototype.peek=gy.prototype.getFirst,gy.prototype.push=gy.prototype.addFirst,gy.prototype.pop=gy.prototype.removeFirst,gy.prototype.add=gy.prototype.addLast;class yy{constructor(t,e,i){this.successCallback=t,this.failureCallback=e,this.pogressCallback=i,this.priority=0,this.flags=0}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}}class vy{constructor(t){this.scoreFunction=t,this.data=[],this.length=0}bubbleUp(t){const e=this.data;let i,n=t,s=e[n],r=this.scoreFunction(s);for(;n>0;){i=n-1>>1;const t=e[i];if(!(r<this.scoreFunction(t)))break;e[i]=s,e[n]=t,n=i}}bubbleDown(t){const e=this.data,i=this.length;let n=t,s=n;for(;;){const t=1+(n<<1);if(t>=i)break;const r=t+1;let a=e[s];const o=this.scoreFunction(a),l=e[t],h=this.scoreFunction(l);if(r>=i){if(h>=o)break;s=t,a=l}else{const i=e[r],n=this.scoreFunction(i);if(h<=n){if(h>=o)break;s=t,a=l}else{if(n>=o)break;s=r,a=i}}e[s]=e[n],e[n]=a,n=s}}pop(){this.length--;const t=this.length,e=this.data.pop();if(0===t)return e;{const t=this.data[0];return this.data[0]=e,this.bubbleDown(0),t}}peek(){return this.data[0]}delete(t){const e=this.data.indexOf(t);return-1!==e&&(this.deleteByIndex(e),!0)}deleteByIndex(t){this.data.splice(t,1),this.length--}clear(){this.data=[],this.length=0}contains(t){return-1!==this.data.indexOf(t)}isEmpty(){return 0===this.length}size(){return this.length}updateElementScore(t){const e=this.data.indexOf(t);return-1!==e&&(this.bubbleDown(e),!0)}push(t){this.data.push(t);const e=this.length;this.length=e+1,this.bubbleUp(e)}}class xy{constructor(t){this.description=t,this.requests=[],this.progress=new dy(0,0),this.state=0}get priority(){let t=0;const e=this.requests,i=e.length;i>0&&(t=e[0].priority);for(let n=1;n<i;n++){const i=e[n];i.priority>t&&(t=i)}return t}}function wy(t){return-t.priority}class by{constructor(t){this.assets=new $p({capacity:1024}),this.request_map=new py(new $p),this.__pending_asset_wait_queue=new vy(wy),this.__pending_asset_active_load_set=new Set,this.load_concurrency=Infinity,this.loaders={},this.transformers={},this.aliases=new Map,this.rootPath="",this.__engine=t,this.crossOriginConfig=new Km,this.failures=new fy,this.__response_queue=new gy,this.__response_processor=new Mf({name:"Asset Manager Response processor",cycleFunction:()=>{if(this.__response_queue.isEmpty())return bf.Yield;const t=this.__response_queue.removeFirst();return this.__process_response(t),bf.Continue}}),this.__is_running=!1}startup(){this.__is_running||(this.__engine.executor.run(this.__response_processor),this.__is_running=!0)}async shutdown(t=!1){this.__is_running&&(t||await Promise.allSettled([Mf.promise(this.__response_processor)]),this.__engine.executor.removeTask(this.__response_processor),this.__is_running=!1)}remove(t,e){const i=new my(t,e);return this.assets.delete(i)}clear(){this.assets.clear()}dumpLoadedAssetList(){return JSON.stringify(function(t){const e={[Jp.DeferredTexture]:3,[Jp.Texture]:3,[Jp.ImageSvg]:3,[Jp.Image]:3,[Jp.JSON]:1,[Jp.ArrayBuffer]:1,[Jp.ModelThreeJs]:2,[Jp.ModelGLTF_JSON]:2,[Jp.ModelGLTF]:2},i=[];return t.assets.forEach((function(t,n){const s=n.type,r=function(t){const i=e[t];return void 0===i?3:i}(s),a=n.path;i.push({uri:a,type:s,level:r})})),i}(this),3,3)}promise(t,e,{skip_queue:i=!1}={}){return new Promise(((i,n)=>{this.get(t,e,i,n)}))}get(t,e,i,n=console.error,s=Jd,r=!1){if("string"!=typeof t)throw new Error("Path must be string. Path = "+JSON.stringify(t));if("string"!=typeof e)throw new TypeError(`type must be a string, instead was '${typeof e}'`);const a=new my(t,e),o=this.assets.get(a);if(void 0!==o)i(o);else{const t=new yy(i,n,s);t.writeFlag(1,r),this.submitRequest(a,t)}}insert(t,e,i){const n=new my(t,e);this.assets.get(n),this.assets.set(n,i)}__process_response(t){try{t.request.successCallback(t.asset)}catch(t){}}__schedule_response(t,e){this.__response_queue.add(new class{constructor(t,e){this.asset=t,this.request=e}}(t,e))}__schedule_load(t){this.__pending_asset_active_load_set.size<this.load_concurrency?this.__dispatch_pending_asset(t):this.__pending_asset_wait_queue.push(t)}__force_load(t){this.__pending_asset_active_load_set.has(t)||(this.__pending_asset_wait_queue.delete(t),this.__dispatch_pending_asset(t))}__handle_asset_resolved(t){const e=this.__pending_asset_active_load_set;this.request_map.delete(t.description),e.delete(t);const i=this.__pending_asset_wait_queue;for(;!i.isEmpty()&&e.size<this.load_concurrency;){const t=i.pop();this.__dispatch_pending_asset(t)}}__dispatch_pending_asset(t){const e=t.requests,i=t.description,n=i.type,s=i.path,r=this.loaders[n];if(void 0===r){for(let t=0;t<e.length;t++){const i=e[t];"function"==typeof i.failureCallback&&i.failureCallback(`no loader exists for asset type '${n}', valid types are: ${Object.keys(this.loaders).join(", ")}`)}return void this.__handle_asset_resolved(t)}this.__pending_asset_active_load_set.add(t);const a=this.assets,o=this.failures,l=async s=>{if(3===t.state)return;t.state,t.state=3;let r=s;const o=this.transformers[n];if(void 0!==o){const t=o.length;for(let e=0;e<t;e++){const t=o[e],n=await t.transform(r,i);"object"!=typeof n||(r=n)}}r.description=i,a.set(i,r),this.__handle_asset_resolved(t);for(let t=0;t<e.length;t++){const i=e[t];this.__schedule_response(r,i)}},h=n=>{if(4!==t.state){t.state,t.state=4;for(let t=0;t<e.length;t++){const i=e[t];try{i.failureCallback(n)}catch(t){}}this.__handle_asset_resolved(t),o.add(i)}};function c(i,n){e.forEach((function(t){if("function"==typeof t.pogressCallback)try{t.pogressCallback(i,n)}catch(t){}})),t.progress.setValue(i),t.progress.setUpperLimit(n)}try{const t=this.rootPath+s;"function"==typeof r?r(t,l,h,c):r.load(t,l,h,c)}catch(t){h(t)}}submitRequest(t,e){const i=this.request_map;let n=!1,s=i.get(t);void 0===s&&(s=new xy(t),i.set(t,s),n=!0),s.requests.push(e),n?this.__schedule_load(s):this.__pending_asset_wait_queue.updateElementScore(s),e.getFlag(1)&&this.__force_load(s)}hasLoaderForType(t){return void 0!==this.getLoaderByType(t)}getLoaderByType(t){return this.loaders[t]}__getLoadedAssetDescriptorsByType(t){return Array.from(this.assets.keys()).filter((e=>e.type===t))}registerTransformer(t,e){let i=this.transformers[t];void 0===i&&(i=[],this.transformers[t]=i),i.push(e),this.__getLoadedAssetDescriptorsByType(t).length}unregisterTransformer(t,e){const i=this.transformers[t];return void 0!==i&&!!function(t,e,i,n){for(let e=0;e<i;e++)if(t[e]===n)return t.splice(e,1),!0;return!1}(i,0,i.length,e)&&(this.__getLoadedAssetDescriptorsByType(t).length,!0)}async registerLoader(t,e){const i=this.getLoaderByType(t);if(void 0!==i){if(i===e)return i;if(Object.getPrototypeOf(i)===Object.getPrototypeOf(e))return i;throw new Error(`Loader for type '${t}' is already registered`)}return"function"==typeof e||await e.link(this,this.__engine),this.loaders[t]=e,e}async unregisterLoader(t){const e=this.getLoaderByType(t);void 0!==e&&(delete this.loaders[t],await e.unlink())}tryGet(t,e){const i=new my(t,e),n=this.assets.get(i);return void 0!==n?n:null}isFailed(t,e){const i=new my(t,e);return this.failures.has(i)}promiseByAlias(t){const e=this.aliases.get(t);return void 0===e?new Promise.reject(`Alias '${t}' not found`):this.promise(e.path,e.path)}resolveAlias(t){return this.aliases.get(t)}assignAlias(t,e,i){const n=new my(e,i);this.aliases.set(t,n)}}by.prototype.isAssetManager=!0;const Sy={backspace:8,tab:9,enter:13,shift:16,ctrl:17,alt:18,pause_break:19,caps_lock:20,escape:27,space:32,page_up:33,page_down:34,end:35,home:36,left_arrow:37,up_arrow:38,right_arrow:39,down_arrow:40,insert:45,delete:46,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57,a:65,b:66,c:67,d:68,e:69,f:70,g:71,h:72,i:73,j:74,k:75,l:76,m:77,n:78,o:79,p:80,q:81,r:82,s:83,t:84,u:85,v:86,w:87,x:88,y:89,z:90,"left_window key":91,"right_window key":92,select_key:93,numpad_0:96,numpad_1:97,numpad_2:98,numpad_3:99,numpad_4:100,numpad_5:101,numpad_6:102,numpad_7:103,numpad_8:104,numpad_9:105,multiply:106,add:107,subtract:109,decimal_point:110,divide:111,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,num_lock:144,scroll_lock:145,semi_colon:186,equal_sign:187,comma:188,dash:189,period:190,forward_slash:191,grave_accent:192,open_bracket:219,backslash:220,close_bracket:221,single_quote:222,back_quote:223},My=function(t,e){const i=[],n={};function s(t){let e;return"number"==typeof t?(void 0===i[t]&&(i[t]={}),e=i[t]):(void 0===n[t]&&(n[t]={}),e=n[t]),e}this.mapKey=function(t,e){const i=s(t);e.on&&(i.on=e.on),e.off&&(i.off=e.off)},this.mapKeyBoolean=function(t,e,i){const n=s(Sy[t]);return n.on=function(){e[i]=!0},n.off=function(){e[i]=!1},this},e.addEventListener("keydown",(function(t){const e=t.keyCode,n=i[e];n&&n.on&&n.on(t)})),e.addEventListener("keyup",(function(t){const e=t.keyCode,n=i[e];n&&n.off&&n.off(t)})),t.addEventListener("mousedown",(function(t){const e=n.mouse1;e&&e.on(t)})),t.addEventListener("mouseup",(function(t){const e=n.mouse1;e&&e.off(t)}))};class Ty{constructor(){this.layerTargets=[],this.camera=new mr(-1,1,1,-1,0,1),this.scene=new Zo,this.size=new wd(0,0),this.__pixelRatio=1}remove(t){const e=this.layerTargets.indexOf(t);return-1!==e&&(this.layerTargets.splice(e,1),t.renderTarget.dispose(),!0)}createLayer(t,e=Iu.Normal){let i;if(t instanceof Li||t instanceof Pi)i=t;else{const e={minFilter:Nt,magFilter:Nt,format:Yt,depthBuffer:!1,stencilBuffer:!1,generateMipmaps:!1};for(let i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);i=new Pi(1,1,e)}const n=new Yg({renderTarget:i,blending:e});return this.addLayer(n),n}addLayer(t){return!this.layerTargets.includes(t)&&(t.setSize(this.size.x,this.size.y),this.layerTargets.push(t),!0)}hasActiveLayers(){const t=this.layerTargets,e=t.length;for(let i=0;i<e;i++)if(t[i].enabled)return!0;return!1}__prepare_scene_for_stage(t){const e=this.layerTargets,i=e.length,n=this.scene;let s=0;for(let r=0;r<i;r++){const i=e[r];i.stage===t&&(n.children[s++]=i.object,i.on.preRender.send0())}n.children.length=s}composite(t,e){if(!this.hasActiveLayers())return;this.__prepare_scene_for_stage(e);const i=this.camera,n=this.scene;t.autoClear=!1,t.render(n,i)}setPixelRatio(t){this.__pixelRatio!==t&&(this.__pixelRatio=t,this.__updateResolution())}getPixelRatio(){return this.__pixelRatio}__updateResolution(){const t=this.size.x,e=this.size.y*this.__pixelRatio,i=t*this.__pixelRatio,n=this.layerTargets;for(let t=0;t<n.length;t++)n[t].setSize(i,e)}setSize(t,e){this.size.set(t,e),this.__updateResolution(t,e)}}const Cy=new Float32Array(9);class Ay{constructor(){this.el=null,this.bindings=[],this.flags=4;const t=this.position=new wd(0,0),e=this.rotation=new Id(0),i=this.scale=new wd(1,1),n=this.size=new wd(0,0);this.transformOrigin=new wd(.5,.5),this.on={linked:new l,unlinked:new l},this.children=[],this.parent=null,t.onChanged.add(this.__updateTransform,this),i.onChanged.add(this.__updateTransform,this),e.onChanged.add(this.__updateTransform,this),n.onChanged.add(this.__setDimensions,this),this.transformOrigin.onChanged.add(this.__setTransformOrigin,this)}get isLinked(){return this.getFlag(1)}get isDestroyed(){return this.getFlag(2)}set visible(t){t!==this.getFlag(4)&&(this.writeFlag(4,t),function(t,e){const i=t.style;e?i.removeProperty("display"):i.display="none"}(this.el,t))}get visible(){return this.getFlag(4)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}__setTransformOrigin(t,e){this.el.style.transformOrigin=`${100*t}% ${100*e}%`}__setDimensions(t,e){const i=this.el.style;i.width=t+"px",i.height=e+"px"}__updateTransform(){!function(t,e,i,n){const s=Cy;!function(t,e,i,n,s,r,a,o){const l=-o,h=Math.sin(l),c=Math.cos(l);t[0]=n*c,t[1]=n*h,t[2]=-n*(0*c+0*h)+0+e,t[3]=-s*h,t[4]=s*c,t[5]=-s*(0*-h+0*c)+0+i,t[6]=0,t[7]=0,t[8]=1}(s,e.x,e.y,i.x,i.y,0,0,n);const r="matrix("+s[0]+","+s[3]+","+s[1]+","+s[4]+","+s[2]+","+s[5]+")";t.style.transform=r}(this.el,this.position,this.scale,this.rotation.getValue())}link(){if(this.isLinked)return;this.setFlag(1);const t=this.bindings,e=t.length;let i;for(i=0;i<e;i++)t[i].link();const n=this.children,s=n.length;for(i=0;i<s;i++)n[i].link();this.on.linked.send0()}unlink(){if(!this.isLinked)return;this.clearFlag(1);const t=this.bindings,e=t.length;let i;for(i=0;i<e;i++)t[i].unlink();const n=this.children,s=n.length;for(i=0;i<s;i++)n[i].unlink();this.on.unlinked.send0()}addChildren(t){for(let e=0;e<t.length;e++)this.addChild(t[e])}addChild(t){return t.parent=this,this.isLinked&&!t.isLinked&&t.link(),this.children.push(t),this.el.appendChild(t.el),this}computePlacement(t,e,i,n,s,r){const a=new wd(e,i);a.multiply(this.size),a.add(this.position),a._sub(t.x*n,t.y*s),r.copy(a)}addChildAt(t,e,i,n,s){this.computePlacement(t.size,e,i,n,s,t.position),this.addChild(t),this.resizeToFitChildren()}removeChild(t){const e=this.children.indexOf(t);-1!==e&&(this.children.splice(e,1),this.el.removeChild(t.el),t.unlink(),t.parent=null)}hasChild(t){return-1!==this.children.indexOf(t)}removeAllChildren(){const t=this.children,e=t.length;for(let i=0;i<e;i++){const e=t.pop();this.el.removeChild(e.el),e.unlink(),e.parent=null}}expandToFit(t,e,i){const n=this.position.x+e,s=this.position.y+i;t._expandToFit(n,s,n+this.size.x,s+this.size.y);const r=this.children;let a=0;const o=r.length;for(;a<o;a++)r[a].expandToFit(t,n,s)}computeBoundingBox(t){return void 0===t&&(t=new Vp).setNegativelyInfiniteBounds(),this.expandToFit(t,0,0),t}resizeToFitChildren(){const t=new Vp(0,0,this.size.x,this.size.y),e=this.children;let i=0;const n=e.length;for(;i<n;i++)e[i].expandToFit(t,0,0);this.size.set(t.x1,t.y1)}positionLocalToGlobal(t,e){e.copy(t);let i=this;for(;null!==i;)e.add(i.position),i=i.parent;return e}positionGlobalToLocal(t,e){e.copy(t);let i=this;for(;null!==i;)e.sub(i.position),i=i.parent;return e}computeGlobalScale(t){let e=this,i=1,n=1;for(;null!==e;)i*=e.scale.x,n*=e.scale.y,e=e.parent;t.set(i,n)}destroy(){const t=this.children,e=t.length;for(let i=0;i<e;i++)t[i].destroy();this.setFlag(2)}bindSignal(t,e,i){const n=new Rm(t,e,i);return this.bindings.push(n),this.isLinked&&n.link(),this}unbindSignal(t,e,i){const n=this.bindings,s=n.length;for(let r=0;r<s;r++){const s=n[r];if(s.signal===t&&s.handler===e&&(void 0===i||s.context===i))return n.splice(r,1),s.unlink(),!0}return!1}addClass(t){this.el.classList.add(t)}addClasses(t){const e=this.el.classList,i=t.length;for(let n=0;n<i;n++){const i=t[n];e.add(i)}}removeClass(t){this.el.classList.remove(t)}removeClassesByPattern(t){const e=this.el.classList,i=[],n=e.length;for(let s=0;s<n;s++){const n=e[s];-1!==n.search(t)&&i.push(n)}const s=i.length;for(let t=0;t<s;t++){const n=i[t];e.remove(n)}return i}setClass(t,e){return this.el.classList.toggle(t,e),this}css(t){for(let e in t)t.hasOwnProperty(e)&&(this.el.style[e]=t[e])}attr(t){for(let e in t)t.hasOwnProperty(e)&&this.el.setAttribute(e,t[e])}followSize({size:t,padding:e=wd.zero}){const i=()=>{this.size.set(t.x-2*e.x,t.y-2*e.y)};this.on.linked.add((()=>{i(),t.onChanged.add(i)})),this.on.unlinked.add((()=>{t.onChanged.remove(i)})),i()}}Ay.prototype.isView=!0;class Ey extends Ay{constructor({classList:t=[],el:e,tag:i="div",tagNamespace:n,css:s,attr:r}={}){super(),this.el=void 0!==e?e:void 0!==n?document.createElementNS(n,i):document.createElement(i),this.addClasses(t),void 0!==s&&this.css(s),void 0!==r&&this.attr(r)}static group(t,e={}){const i=new Ey(e);return t.forEach(i.addChild,i),i}static create(){return new Ey}}const zy={Opaque:1,Transparent:2};function Iy(t,e){const i=t.length-e;i>0&&t.splice(e,i)}class Ny{constructor(t){this.__elements=[],this.__elements_cursor=0,this.__swap_elements=[],this.__swap_elements_count=0,this.__compare=t,this.version=0,this.size=0,this.onUpdateFinished=new l,this.onAdded=new l,this.onRemoved=new l,this.state=0}get elements(){return this.__elements}forEach(t,e){const i=this.size,n=this.__elements;for(let s=0;s<i;s++){const i=n[s];t.call(e,i)}}sort(t,e){throw new Error("Deprecated, the set is always sorted")}contains(t){return-1!==this.__indexOf(t)}__indexOf(t){const e=this.__indexExpected(t);return this.__elements[e]===t?e:-1}__indexExpected(t){return function(t,e,i,n=0,s=t.length-1){let r=n,a=s;for(;r<=a;){const n=r+a>>1,s=i(e,t[n]);if(s<0)a=n-1;else{if(!(s>0))return n;r=n+1}}return r}(this.__elements,t,this.__compare,0,this.size-1)}forceRemove(t){if(1===this.state)throw new Rf("Cannot remove during build");const e=this.__indexOf(t);return-1!==e&&(this.__elements.splice(e,1),this.size--,this.version++,!0)}clear(){0!==this.size&&(this.size=0,this.state=0,this.version++)}includeAll(){throw new Error("deprecated #includeAll")}initializeUpdate(){const t=this.__elements;this.__elements=this.__swap_elements,this.__swap_elements=t;const e=this.size;this.size=this.__swap_elements_count,this.__swap_elements_count=e,this.__elements_cursor=0,this.state=1,this.version++}finalizeUpdate(){this.size=this.__elements_cursor,Iy(this.__elements,this.size),this.__elements.sort(this.__compare);let t=0,e=0;for(;t<this.size&&e<this.__swap_elements_count;){const i=this.__elements[t],n=this.__swap_elements[e],s=this.__compare(i,n);0===s?(t++,e++):s<0?(t++,this.onAdded.send1(i)):(e++,this.onRemoved.send1(n))}for(;t<this.size;t++)this.onAdded.send1(this.__elements[t]);for(;e<this.__swap_elements_count;e++)this.onRemoved.send1(this.__swap_elements[e]);this.state=2,this.onUpdateFinished.send0()}push(t){this.__elements[this.__elements_cursor++]=t}pushOther(t){const e=t.__elements,i=t.size;for(let t=0;t<i;t++){const i=e[t];this.push(i)}}}function Ly(t,e){for(let i=0;i<6;i++){const n=t[i],s=4*i,r=n.normal;e[s]=r.x,e[s+1]=r.y,e[s+2]=r.z,e[s+3]=n.constant}}function Py(t,e,i,n,s,r,a,o,l,h,c,u){const d=r-i,p=a-n,f=o-s,_=m(d,p,f,l,h,c);if(0===_)return!1;const g=-(m(l,h,c,i,n,s)+u)/_;return!(g<0||g>1||(t[e]=d*g+i,t[e+1]=p*g+n,t[e+2]=f*g+s,0))}Ny.prototype.isIncrementalDeltaSet=!0;const Fy=[];Fy[0]=19,Fy[1]=41,Fy[2]=70,Fy[3]=140,Fy[4]=784,Fy[5]=2336,Fy[6]=1600,Fy[7]=3200;const Dy=[];function Oy(t,e,i,n,s,r,a,o,l,h,c,u,d,p){const f=o*d-l*u,_=l*c-a*d,g=a*u-o*c,y=u*s-d*n,v=d*i-c*s,x=c*n-u*i,w=n*l-s*o,b=s*a-i*l,S=i*o-n*a,M=m(i,n,s,f,_,g);if(0===M)return!1;const T=1/M,C=-r,A=(f*C-y*h-w*p)*T,E=(_*C-v*h-b*p)*T,z=(g*C-x*h-S*p)*T;return t[e]=A,t[e+1]=E,t[e+2]=z,!0}function Ry(t,e,i,n,s,r){for(let a=0;a<r;a++){if(0==(n&1<<a))continue;const r=4*a;if($u(t,e,i,s[r],s[r+1],s[r+2],s[r+3])<-b)return!1}return!0}Dy[0]=1,Dy[1]=2,Dy[2]=19,Dy[3]=11,Dy[4]=4,Dy[5]=13,Dy[6]=22,Dy[7]=31,Dy[8]=37,Dy[9]=38,Dy[10]=55,Dy[11]=47;const ky=new ArrayBuffer(236),Uy=new Float32Array(ky,0,24),By=new Float32Array(ky,96,24),Vy=new Uint32Array(ky,192,8),Gy=new Float32Array(ky,224,3),Wy=[];class Hy{constructor(){this.visible=!0}copy(t){this.visible=t.visible}clone(){const t=new Hy;return t.copy(this),t}}function jy(t,e){return t.id-e.id}const qy=[];let Jy=0;function Yy(t,e,i){let n,s=0;const r=Jy;for(qy[Jy++]=i;Jy-- >r;)n=qy[Jy],n.isBinaryNode?(null!==n.right&&(qy[Jy++]=n.right),null!==n.left&&(qy[Jy++]=n.left)):(t[e+s]=n.object,s++);return Jy=r,s}const Xy=[],Zy=[];class $y{constructor(){this.bvh=new vd,this.bvh.setNegativelyInfiniteBounds(),this.state=new Hy,this.name=null,this.managed=!1,this.extractRenderable=$d,this.visibleSet=new Ny(jy),this.renderPass=zy.Opaque}get visible(){return this.state.visible}set visible(t){this.state.visible=t}computeNearFarClippingPlanes(t,e,i,n,s){const r=this.bvh;Ky.setFrustum(t),Ky.near=e,Ky.far=i,r.isEmpty()||dd(r,Ky),n.call(s,Ky.near,Ky.far)}buildVisibleSet(t,e,i){const n=i.frustum,s=this.extractRenderable;if("function"!=typeof s)return 0;const r=function(t,e,i,n){let s,r=0,a=1;for(Xy[0]=i;a>0;){a--,s=Xy[a];const e=td(s.x0,s.y0,s.z0,s.x1,s.y1,s.z1,n);if(2===e)r+=Yy(t,r,s);else if(1===e)if(!0===s.isBinaryNode){const t=s.right;null!==t&&(Xy[a++]=t);const e=s.left;null!==e&&(Xy[a++]=e)}else t[r]=s.object,r++}return r-0}(Zy,0,this.bvh,n);let a=0,o=0;for(;o<r;o++){const i=s(Zy[o]);i&&(t[a+e]=i,a++)}return a}}const Ky=new class extends hd{constructor(){super(),this.frustum=null,this.__planes=[],this.__planeCount=0,this.__nearPlaneNormal=null,this.__nearPlaneConstant=0,this.__planes_f32=new Float32Array(24),this.near=0,this.far=0}setFrustum(t){this.frustum=t;const e=t.planes;this.__planes[0]=e[0],this.__planes[1]=e[1],this.__planes[2]=e[2],this.__planes[3]=e[3],this.__planes[4]=e[5];const i=e[5];this.__nearPlaneNormal=i.normal,this.__nearPlaneConstant=i.constant,this.__planeCount=5,Ly(e,this.__planes_f32)}__process_point(t,e,i){const n=this.__distanceToNearPlane(t,e,i);n<this.near&&(this.near=n),n>this.far&&(this.far=n)}__distanceToNearPlane(t,e,i){const n=this.__nearPlaneNormal;return $u(t,e,i,n.x,n.y,n.z,this.__nearPlaneConstant)}__traverseBox_Detailed(t,e){this.__traverseBoxNearCorner(t),function(t,e,i,n,s,r,a,o,l,h,c){const u=function(t,e,i,n,s,r,a,o,l,h,c){Qu(Uy,0,i,n,s,r,a,o),function(t,e,i,n,s,r,a){t[0]=1,t[1]=0,t[2]=0,t[3]=-e,t[4]=-1,t[5]=0,t[6]=0,t[7]=s,t[8]=0,t[9]=1,t[10]=0,t[11]=-i,t[12]=0,t[13]=-1,t[14]=0,t[15]=r,t[16]=0,t[17]=0,t[18]=1,t[19]=-n,t[20]=0,t[21]=0,t[22]=-1,t[23]=a}(By,i,n,s,r,a,o);let u=0,d=0,p=0;for(let e=0;e<8;e++){const i=3*e,n=Uy[i],s=Uy[i+1],r=Uy[i+2];d=0;for(let t=0;t<4;t++){const i=1<<t;if(0==(l&i))continue;const a=4*t;$u(n,s,r,h[a],h[a+1],h[a+2],h[a+3])<0&&(0===d&&(u|=Fy[e]),d|=i)}Vy[e]=d,0===d&&(t[p++]=n,t[p++]=s,t[p++]=r)}for(let e=0;e<12;e++){if(0==(u&1<<e))continue;const i=Dy[e],n=7&i,s=i>>3&7;if(0!=(Vy[n]&Vy[s]))continue;const r=3*n,a=3*s,o=Uy[r],d=Uy[r+1],f=Uy[r+2],m=Uy[a],_=Uy[a+1],g=Uy[a+2];for(let e=0;e<c;e++){const i=1<<e;if(0==(l&i))continue;const n=4*e,s=h[n],r=h[n+1],a=h[n+2],u=h[n+3];Py(Gy,0,o,d,f,m,_,g,s,r,a,u)&&Ry(Gy[0],Gy[1],Gy[2],l^i,h,c)&&(t[p++]=Gy[0],t[p++]=Gy[1],t[p++]=Gy[2])}}for(let e=0;e<6;e++){const c=4*e,u=By[c],d=By[c+1],f=By[c+2],m=By[c+3];for(let e=0;e<4;e++){if(0==(l&1<<e))continue;const c=4*e,_=(e+2)%4*4;if(Oy(Gy,0,u,d,f,m,h[c],h[c+1],h[c+2],h[c+3],h[_],h[_+1],h[_+2],h[_+3])){const e=Gy[0],l=Gy[1],h=Gy[2];!(e+b<i||e-b>r||l+b<n||l-b>a||h+b<s||h-b>o)&&(t[p++]=e,t[p++]=l,t[p++]=h)}}}return(p-0)/3}(Wy,0,t,e,i,n,s,r,a,o,l);for(let t=0;t<u;t++){const e=3*t,i=Wy[e],n=Wy[e+1],s=Wy[e+2];h.call(c,i,n,s)}}(t.x0,t.y0,t.z0,t.x1,t.y1,t.z1,e,this.__planes_f32,this.__planeCount,this.__process_point,this)}__traverseBoxNearCorner(t){const e=this.__nearPlaneNormal,i=e.x,n=e.y,s=e.z,r=t.x0,a=t.y0,o=t.z0,l=t.x1,h=t.y1,c=t.z1;let u,d,p;u=i>0?r:l,d=n>0?a:h,p=s>0?o:c,this.__process_point(u,d,p)}__traverseBoxNearAndFarCorners(t){const e=this.__nearPlaneNormal,i=e.x,n=e.y,s=e.z,r=t.x0,a=t.y0,o=t.z0,l=t.x1,h=t.y1,c=t.z1;let u,d,p,f,m,_;i>0?(u=r,f=l):(u=l,f=r),n>0?(d=a,m=h):(d=h,m=a),s>0?(p=o,_=c):(p=c,_=o),this.__process_point(u,d,p),this.__process_point(f,m,_)}visitLeaf(t){let e=0;const i=this.__planeCount,n=this.__planes;for(let s=0;s<i;s++){const i=n[s],r=t.computePlaneSide(i);if(r<0)return!1;0===r&&(e|=1<<s)}0!==e?this.__traverseBox_Detailed(t,e):this.__traverseBoxNearAndFarCorners(t)}visitBinary(t){const e=t.x0,i=t.y0,n=t.z0,s=t.x1,r=t.y1,a=t.z1,o=this.__nearPlaneNormal;let l,h,c,u,d,p;o.x>0?(l=e,u=s):(l=s,u=e),o.y>0?(h=i,d=r):(h=r,d=i),o.z>0?(c=n,p=a):(c=a,p=n);const f=this.__distanceToNearPlane(u,d,p);if(f<0)return!1;const m=this.__distanceToNearPlane(l,h,c);if(!(m<this.near||f>this.far))return!1;const _=this.__planes;let g=!1;for(let e=0;e<4;e++){const i=_[e],n=t.computePlaneSide(i);if(n<0)return!1;0===n&&(g=!0)}return!!g||(m<this.near&&(this.near=m),f>this.far&&(this.far=f),!1)}};class Qy{constructor(){this.data=[],this.on={removed:new l,added:new l}}asArray(){return this.data.slice()}isEmpty(){return this.data.length<=0}remove(t){const e=this.data.indexOf(t);return-1!==e&&(this.data.splice(e,1),this.on.removed.send1(t),!0)}push(t){this.data.push(t),this.on.added.send1(t)}pop(){if(this.isEmpty())return;const t=this.data.pop();return this.on.removed.send1(t),t}peek(){return this.data[this.data.length-1]}clear(){if(this.on.removed.hasHandlers())for(;!this.isEmpty();)this.pop();else this.data.splice(0,this.data.length)}}class tv{constructor(){this.layers=new Map}write(t){for(const[e,i]of this.layers)t.getLayerByName(e).state.copy(i)}read(t){this.layers.clear();const e=t.layers,i=e.length;for(let t=0;t<i;t++){const i=e.get(t),n=i.state.clone();this.layers.set(i.name,n)}}}class ev{constructor(){this.__stateStack=new Qy,this.layers=new of}getLayerCount(){return this.layers.length}getLayerByIndex(t){const e=this.layers.get(t);if(void 0===e)throw new Error(`Layer with index ${t} not found`);return e}hideAll(){const t=this.layers,e=t.length;for(let i=0;i<e;i++)t.get(i).state.visible=!1}pushState(){const t=new tv;return t.read(this),this.__stateStack.push(t),t}popState(){this.__stateStack.isEmpty()||this.__stateStack.pop().write(this)}create(t){const e=new $y;return e.name=t,this.add(e),e}add(t){const e=t.name;if(void 0!==this.getLayerByName(e))throw new Error(`RenderLayer named '${e}' already exists`);this.layers.add(t)}remove(t){return this.layers.removeOneOf(t)}getLayerByName(t){return this.layers.find((function(e){return e.name===t}))}traverse(t,e){this.layers.forEach(t,e)}map(t){return this.layers.map(t)}}const iv=[];function nv(){this.buffers=[],this.needsRebuild=!1,this.orderedBuffers=[],this.pixelRatio=1}nv.prototype.initialize=function(t){for(const e of this.buffers){if(e.initialize(t),"object"!=typeof e.renderTarget)throw new Error(`renderTarget was expected to be of type 'object', instead was '${typeof e.renderTarget}'`);if(!0!==e.renderTarget.isWebGLRenderTarget)throw new Error(`renderTarget.isWebGLRenderTarget must be true, instead was '${e.renderTarget.isWebGLRenderTarget}'`)}},nv.prototype.build=function(){this.orderedBuffers=this.computeRenderOrder(),this.needsRebuild=!1},nv.prototype.computeRenderOrder=function(){const t=this.buffers.slice(),e={},i=[];function n(t){const i=t.dependencies;for(let t=0;t<i.length;t++){const n=i[t];if(void 0===e[n])return!1}return!0}let s=t.length;for(;s>0;){const r=s;for(let r=0;r<s;r++){const a=t[r];n(a)&&(i.push(a),t.splice(r,1),e[a.id]=a,r--,s--)}if(r===s)throw new Error(`dependencies could not be satisfied for ${s} buffers`)}return i},nv.prototype.getById=function(t){return this.buffers.find((function(e){return e.id===t}))},nv.prototype.add=function(t){if(void 0!==this.getById(t.id))throw new Error(`Failed to add buffer. Another buffer with id='${t.id}' already exists`);this.buffers.push(t),this.needsRebuild=!0},nv.prototype.update=function(){this.needsRebuild&&this.build()},nv.prototype.__populate_dependencies=function(t,e){const i=e.dependencies,n=i.length;for(let e=0;e<n;e++){const n=i[e],s=this.getById(n);t[e]=s}},nv.prototype.render=function(t,e,i){this.update();const n=this.orderedBuffers,s=n.length;for(let r=0;r<s;r++){const s=n[r];s.referenceCount>0&&(this.__populate_dependencies(iv,s),s.render(t,e,i,iv))}},nv.prototype.setPixelRatio=function(t){this.pixelRatio=t},nv.prototype.setSize=function(t,e){const i=this.buffers,n=i.length,s=this.pixelRatio;for(let r=0;r<n;r++)i[r].setSize(t*s,e*s)};class sv{constructor(t){this.id=t,this.renderTarget=null,this.referenceCount=0,this.dependencies=[],this.size=new wd(0,0)}getRenderTarget(){return this.renderTarget}initialize(t){}finalize(t){}render(t,e,i,n){const s=t.getRenderTarget();t.setRenderTarget(this.renderTarget),t.clear(),t.render(i,e),t.setRenderTarget(s)}setSize(t,e){const i=this.size;t===i.x&&e===i.y||(this.renderTarget.setSize(t,e),i.set(t,e))}}class rv extends sv{initialize(t){if(e=t.getContext(),!(void 0!==WebGL2RenderingContext&&e instanceof WebGL2RenderingContext||t.extensions.get("WEBGL_depth_texture")))throw new Error("renderer does not support required 'WEBGL_depth_texture' extension");var e;const i=new bi;t.getSize(i);const n=new Pi(i.x,i.y,{ignoreDepth:!1});n.texture.format=Jt,n.texture.minFilter=Et,n.texture.magFilter=Et,n.texture.generateMipmaps=!1,n.texture.encoding=Qe,n.stencilBuffer=!1,n.depthBuffer=!0,n.depthTexture=new qo,n.depthTexture.format=Kt,n.depthTexture.type=Bt,n.depthTexture.generateMipmaps=!1,n.depthTexture.internalFormat="DEPTH_COMPONENT32F",this.renderTarget=n}}const av={tTexture:{type:"t",value:null}},ov=new Ws({uniforms:av,vertexShader:"\n varying vec2 vUv;\n \n void main() {\n \n vUv = uv;\n gl_Position = vec4( (uv - 0.5)*2.0, 0.0, 1.0 );\n \n }\n ",fragmentShader:qg(),blending:D,lights:!1,fog:!1,depthTest:!1,depthWrite:!1,transparent:!0,vertexColors:!1});class lv{constructor(){}record(t,e){}}class hv extends lv{record(t,e){}}hv.INSTANCE=new hv;const cv=new class extends lv{constructor(){super(),this.target=hv.INSTANCE}setTarget(t){this.target=t}record(t,e){this.target.record(t,e)}},uv=[];class dv{constructor(){this.__object_map=new WeakMap}__get_object_twin(t){const e=this.__object_map.get(t);if(void 0!==e)return e;let i;const n=t.geometry;return i=t.isSkinnedMesh?new xl(n,null):new Rs(n,null),i.matrixAutoUpdate=!1,i.matrixWorldNeedsUpdate=!1,i.frustumCulled=!1,this.__object_map.set(t,i),i}build_scene({scene:t,input:e,input_size:i,input_filter:n=Yd,object_filter:s,material_extractor:r,material_extractor_context:a}){const o=t.children;o.length=0;let l=0,h=0,c=0;for(;c<i;c++){const t=e[c];n(t)&&(uv[l++]=t)}for(;l>0;){const e=uv[--l];if(s(e)&&e.isMesh){const i=e.geometry;if(null!==i){const n=this.__get_object_twin(e),s=r.call(a,e);n.geometry=i,n.material=s,e.isSkinnedMesh&&(n.bindMatrix.copy(e.bindMatrix),n.bindMatrixInverse.copy(e.bindMatrixInverse),n.skeleton=e.skeleton),n.matrix.copy(e.matrix),n.matrixWorld.copy(e.matrixWorld),n.normalMatrix.copy(e.normalMatrix),o[h++]=n,n.parent=t}}const i=e.children,n=i.length;for(c=0;c<n;c++){const t=i[c];uv[l++]=t}}o.length=h}}dv.INSTANCE=new dv;class pv extends sv{constructor(t){super(t),this.dependencies.push(sy)}initialize(t){super.initialize(t),t.extensions.get("EXT_color_buffer_float");const e=new bi;t.getSize(e);const i=new Pi(e.x,e.y,{minFilter:Et,magFilter:Et,format:Yt,type:Vt,depthBuffer:!0,stencilBuffer:!1,generateMipmaps:!1});i.texture.internalFormat="RGBA16F",this.renderTarget=i,this.__material_static=new Hh({depthWrite:!0}),this.__material_skinned=new Hh({depthWrite:!0}),this.__material_static.side=P,this.__material_skinned.side=P;const n=new Zo;this.__scene=n,n.autoUpdate=!1,n.matrixAutoUpdate=!1,n.matrixWorldNeedsUpdate=!1}__bindMaterial(t){let e;if(void 0!==t.customNormalMaterial)e=t.customNormalMaterial;else{const i=t.material;e=t.isSkinnedMesh?this.__material_skinned:this.__material_static,void 0!==i&&(i.alphaTest>0?e.map=i.map:e.map=null,e.normalMap=i.normalMap)}return e}render(t,e,i,n){this.__renderer=t;const s=t.getRenderTarget();t.setRenderTarget(this.renderTarget),t.clear(!0,!0,!1),dv.INSTANCE.build_scene({scene:this.__scene,input:i.children,input_size:i.children.length,object_filter:t=>t.visible,material_extractor:this.__bindMaterial,material_extractor_context:this}),t.render(this.__scene,e),t.setRenderTarget(s)}}class fv{constructor(){this.__onReleased=new l,this.__value=null,this.__is_bound=!1}get onReleased(){return this.__onReleased}bind(t){if(t!==this.__value){if(this.__is_bound)throw new Error("Reference is already bound, must release before binding to a new value");this.__value=t,this.__is_bound=!0}}getValue(){return this.__value}release(){if(!this.__is_bound)return;const t=this.__value;this.__value=null,this.__is_bound=!1,this.__onReleased.send2(this,t)}}fv.NULL=Object.freeze(new fv);class mv{constructor(t){this.__source=null,this.__material=t,this.__ref_count=0,this.onLastReleased=new l}getSource(){return this.__source}setSource(t){this.__source=t}getMaterial(){return this.__material}__release_reference(){this.__ref_count--,0===this.__ref_count&&this.onLastReleased.send1(this)}getRef(){const t=new fv;return t.bind(this.__material),t.onReleased.add(this.__release_reference,this),this.__ref_count++,t}}class _v{constructor(){this.__library=new $p({keyHashFunction:og,keyEqualityFunction:cg,capacity:1024}),this.__cache=new Qp({keyHashFunction:og,keyEqualityFunction:cg,maxWeight:100}),this.__reverse_library=new $p({keyHashFunction:og,keyEqualityFunction:cg,capacity:1024}),this.__cache.onEvicted.add(this.__dispose_material,this),this.__transform_chain=[]}__dispose_material(t,e){e.getMaterial().dispose()}__handle_last_reference_removed(t){const e=t.getMaterial(),i=t.getSource();this.__library.delete(i),this.__reverse_library.delete(e),this.__cache.put(i,t)}addCompileStep(t){this.__transform_chain.push(t)}removeCompileStep(t){const e=this.__transform_chain.indexOf(t);return-1!==e&&(this.__transform_chain.splice(e,1),!0)}__compile(t){let e=t;const i=this.__transform_chain,n=i.length;for(let t=0;t<n;t++)e=i[t].transform(e);return e}obtain(t){let e=this.__reverse_library.get(t);if(void 0!==e)return e.getRef();if(e=this.__library.get(t),void 0===e){if(e=this.__cache.get(t),null!==e)this.__cache.remove(t);else{const i=this.__compile(t);e=new mv(i),e.setSource(t)}e.onLastReleased.addOne(this.__handle_last_reference_removed,this),this.__library.set(t,e),this.__reverse_library.set(e.getMaterial(),e)}return e.getRef()}}const gv=new Ws({uniforms:{shadow_pass:{value:null},resolution:{value:new bi},radius:{value:4},samples:{value:8}},defines:{VSM_SAMPLES:8},vertexShader:"\nvoid main() {\n\tgl_Position = vec4( position, 1.0 );\n}\n",fragmentShader:"\nuniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\t// This seems totally useless but it's a crazy work around for a Adreno compiler bug\n\t// float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}\n"}),yv=gv.clone();yv.defines.HORIZONTAL_PASS=1;const vv=new ss;class xv{constructor(){this.__renderer=null,this.onBeforeRender=new l}update(t,e,i,n){const s=e.camera;this.__renderer=t,this.__ensure_map(e,t);const r=t.getRenderTarget(),a=t.getActiveCubeFace(),o=t.getActiveMipmapLevel(),l=t.getScissorTest();t.getClearColor(vv);const h=t.getClearAlpha(),c=t.autoClearColor,u=t.autoClearDepth,d=t.autoClearStencil,p=t.sortObjects,f=e.map;t.setRenderTarget(f),t.setClearColor(16777215,1),t.setScissorTest(!1),t.autoClearColor=!1,t.autoClearDepth=!1,t.autoClearStencil=!1,t.sortObjects=!1,t.clear(!0,!0,!1),e.updateMatrices(n,0),this.onBeforeRender.send3(t,s,i),f.width<=0||f.height<=0||(t.render(i,s),t.shadowMap.type===I&&this.__do_vsm_pass(e)),t.setRenderTarget(r,a,o),t.setScissorTest(l),t.setClearColor(vv,h),t.autoClearColor=c,t.autoClearDepth=u,t.autoClearStencil=d,t.sortObjects=p,t.info.render.frame++}__do_vsm_pass(t){const e=this.__renderer;gv.defines.VSM_SAMPLES!==t.blurSamples&&(gv.defines.VSM_SAMPLES=t.blurSamples,yv.defines.VSM_SAMPLES=t.blurSamples,gv.needsUpdate=!0,yv.needsUpdate=!0);const i=gv.uniforms;i.shadow_pass.value=t.map.texture,i.resolution.value=t.mapSize,i.radius.value=t.radius,i.samples.value=t.blurSamples,e.setRenderTarget(t.mapPass),e.clear(),ey(e,gv);const n=yv.uniforms;n.shadow_pass.value=t.mapPass.texture,n.resolution.value=t.mapSize,n.radius.value=t.radius,n.samples.value=t.blurSamples,e.setRenderTarget(t.map),e.clear(),ey(e,yv)}__ensure_map(t,e){const i=t.mapSize;if(null===t.map){const n={format:Yt,scissorTest:!1,stencilBuffer:!1};t.isPointLightShadow||e.shadowMap.type!==I?(n.minFilter=Et,n.magFilter=Et):(n.minFilter=Nt,n.magFilter=Nt,t.mapPass=new Li(i.x,i.y,Object.assign({depthBuffer:!1},n))),t.map=new Li(i.x,i.y,n),t.map.texture.name=".shadowMap",t.camera.updateProjectionMatrix()}}}const wv=new ir,bv=new Float32Array(16);class Sv{constructor(){this.name="",this.__camera=null,this.frustum=new Float32Array(24),this.projection_matrix=new Float32Array(16),this.bounding_box=new rd,this.visible_objects=new Ny(jy),this.flags=7,this.on={preVisibilityBuild:new l,postVisibilityBuild:new l,preRender:new l},this.projection_modifiers=[]}addProjectionModifier(t){this.projection_modifiers.push(t)}removeProjectionModifier(t){return I_(this.projection_modifiers,t)}set_from_camera(t){this.__camera=t,Am(t,wv,!1),Ly(wv.planes,this.frustum),Rd(t.projectionMatrix.elements,0,this.projection_matrix,0,16);let e=this.projection_matrix,i=bv;for(let t=0;t<this.projection_modifiers.length;t++){const n=this.projection_modifiers[t];n.transform.call(n.context,e,i);const s=e;e=i,i=s}e!==this.projection_matrix&&Rd(e,0,this.projection_matrix,0,16),Rd(this.projection_matrix,0,this.__camera.projectionMatrix.elements,0,16)}get camera(){return this.__camera}build_visibility(t,e){this.on.preVisibilityBuild.send0(),this.visible_objects.initializeUpdate(),e.output=this.visible_objects,e.view=this,e.build(t),this.visible_objects.finalizeUpdate(),this.on.postVisibilityBuild.send0()}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}}const Mv=[];class Tv{constructor(){this.__view=null,this.__activeLayer=null,this.__output=null}get filters(){throw new Error("Method is deprecated")}set filters(t){throw new Error("Method is deprecated")}addFilter(t){throw new Error("Method is deprecated")}removeFilter(t){throw new Error("Method is deprecated")}set view(t){this.__view=t}__processLayer(t){if(!t.state.visible)return;if(this.__activeLayer=t,t.managed)return void this.__output.pushOther(t.visibleSet);const e=t.buildVisibleSet(Mv,0,this.__view);for(let t=0;t<e;t++){const e=Mv[t];this.__output.push(e),this.__activeLayer.visibleSet.push(e)}}set output(t){this.__output=t}build(t){t.traverse(this.__processLayer,this)}}class Cv{constructor(){this.__data=new of,this.__visibility_computer=new Tv,this.on={preViewBuild:new l,postViewBuild:new l}}get elements(){return this.__data}create(){const t=new Sv;return this.__data.add(t),t}add(t){return!this.__data.contains(t)&&(this.__data.add(t),!0)}remove(t){return this.__data.removeOneOf(t)}build_visibility(t){t.traverse((t=>{t.managed||t.visibleSet.initializeUpdate()}));const e=this.__data,i=e.length;for(let n=0;n<i;n++){const i=e.get(n);i.getFlag(1)?(this.on.preViewBuild.send1(i),i.build_visibility(t,this.__visibility_computer),this.on.postViewBuild.send1(i)):i.visible_objects.clear()}t.traverse((t=>{t.managed||t.visibleSet.finalizeUpdate()}))}}var Av=function(t){return URL.createObjectURL(new Blob([t],{type:"text/javascript"}))};try{URL.revokeObjectURL(Av(""))}catch(t){Av=function(t){return"data:application/javascript;charset=UTF-8,"+encodeURI(t)}}var Ev=Uint8Array,zv=Uint16Array,Iv=Uint32Array,Nv=new Ev([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Lv=new Ev([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Pv=new Ev([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Fv=function(t,e){for(var i=new zv(31),n=0;n<31;++n)i[n]=e+=1<<t[n-1];var s=new Iv(i[30]);for(n=1;n<30;++n)for(var r=i[n];r<i[n+1];++r)s[r]=r-i[n]<<5|n;return[i,s]},Dv=Fv(Nv,2),Ov=Dv[0],Rv=Dv[1];Ov[28]=258,Rv[258]=28;for(var kv=Fv(Lv,0)[0],Uv=new zv(32768),Bv=0;Bv<32768;++Bv){var Vv=(43690&Bv)>>>1|(21845&Bv)<<1;Vv=(61680&(Vv=(52428&Vv)>>>2|(13107&Vv)<<2))>>>4|(3855&Vv)<<4,Uv[Bv]=((65280&Vv)>>>8|(255&Vv)<<8)>>>1}var Gv=function(t,e,i){for(var n=t.length,s=0,r=new zv(e);s<n;++s)++r[t[s]-1];var a,o=new zv(e);for(s=0;s<e;++s)o[s]=o[s-1]+r[s-1]<<1;if(i){a=new zv(1<<e);var l=15-e;for(s=0;s<n;++s)if(t[s])for(var h=s<<4|t[s],c=e-t[s],u=o[t[s]-1]++<<c,d=u|(1<<c)-1;u<=d;++u)a[Uv[u]>>>l]=h}else for(a=new zv(n),s=0;s<n;++s)t[s]&&(a[s]=Uv[o[t[s]-1]++]>>>15-t[s]);return a},Wv=new Ev(288);for(Bv=0;Bv<144;++Bv)Wv[Bv]=8;for(Bv=144;Bv<256;++Bv)Wv[Bv]=9;for(Bv=256;Bv<280;++Bv)Wv[Bv]=7;for(Bv=280;Bv<288;++Bv)Wv[Bv]=8;var Hv=new Ev(32);for(Bv=0;Bv<32;++Bv)Hv[Bv]=5;var jv=Gv(Wv,9,1),qv=Gv(Hv,5,1),Jv=function(t){for(var e=t[0],i=1;i<t.length;++i)t[i]>e&&(e=t[i]);return e},Yv=function(t,e,i){var n=e/8|0;return(t[n]|t[n+1]<<8)>>(7&e)&i},Xv=function(t,e){var i=e/8|0;return(t[i]|t[i+1]<<8|t[i+2]<<16)>>(7&e)},Zv=function(t){return(t/8|0)+(7&t&&1)},$v=function(t,e,i){var n=t.length;if(!n||i&&!i.l&&n<5)return e||new Ev(0);var s=!e||i,r=!i||i.i;i||(i={}),e||(e=new Ev(3*n));var a=function(t){var i=e.length;if(t>i){var n=new Ev(Math.max(2*i,t));n.set(e),e=n}},o=i.f||0,l=i.p||0,h=i.b||0,c=i.l,u=i.d,d=i.m,p=i.n,f=8*n;do{if(!c){i.f=o=Yv(t,l,1);var m=Yv(t,l+1,3);if(l+=3,!m){var _=t[(A=Zv(l)+4)-4]|t[A-3]<<8,g=A+_;if(g>n){if(r)throw"unexpected EOF";break}s&&a(h+_),e.set(t.subarray(A,g),h),i.b=h+=_,i.p=l=8*g;continue}if(1==m)c=jv,u=qv,d=9,p=5;else{if(2!=m)throw"invalid block type";var y=Yv(t,l,31)+257,v=Yv(t,l+10,15)+4,x=y+Yv(t,l+5,31)+1;l+=14;for(var w=new Ev(x),b=new Ev(19),S=0;S<v;++S)b[Pv[S]]=Yv(t,l+3*S,7);l+=3*v;var M=Jv(b),T=(1<<M)-1,C=Gv(b,M,1);for(S=0;S<x;){var A,E=C[Yv(t,l,T)];if(l+=15&E,(A=E>>>4)<16)w[S++]=A;else{var z=0,I=0;for(16==A?(I=3+Yv(t,l,3),l+=2,z=w[S-1]):17==A?(I=3+Yv(t,l,7),l+=3):18==A&&(I=11+Yv(t,l,127),l+=7);I--;)w[S++]=z}}var N=w.subarray(0,y),L=w.subarray(y);d=Jv(N),p=Jv(L),c=Gv(N,d,1),u=Gv(L,p,1)}if(l>f){if(r)throw"unexpected EOF";break}}s&&a(h+131072);for(var P=(1<<d)-1,F=(1<<p)-1,D=l;;D=l){var O=(z=c[Xv(t,l)&P])>>>4;if((l+=15&z)>f){if(r)throw"unexpected EOF";break}if(!z)throw"invalid length/literal";if(O<256)e[h++]=O;else{if(256==O){D=l,c=null;break}var R=O-254;if(O>264){var k=Nv[S=O-257];R=Yv(t,l,(1<<k)-1)+Ov[S],l+=k}var U=u[Xv(t,l)&F],B=U>>>4;if(!U)throw"invalid distance";if(l+=15&U,L=kv[B],B>3&&(k=Lv[B],L+=Xv(t,l)&(1<<k)-1,l+=k),l>f){if(r)throw"unexpected EOF";break}s&&a(h+131072);for(var V=h+R;h<V;h+=4)e[h]=e[h-L],e[h+1]=e[h+1-L],e[h+2]=e[h+2-L],e[h+3]=e[h+3-L];h=V}}i.l=c,i.p=D,i.b=h,c&&(o=1,i.m=d,i.d=u,i.n=p)}while(!o);return h==e.length?e:function(t,e,i){(null==e||e<0)&&(e=0),(null==i||i>t.length)&&(i=t.length);var n=new(t instanceof zv?zv:t instanceof Iv?Iv:Ev)(i-e);return n.set(t.subarray(e,i)),n}(e,0,h)},Kv=new Ev(0),Qv=function(t){if(8!=(15&t[0])||t[0]>>>4>7||(t[0]<<8|t[1])%31)throw"invalid zlib data";if(32&t[1])throw"invalid zlib data: preset dictionaries not supported"};function tx(t,e){return $v((Qv(t),t.subarray(2,-4)),e)}var ex="undefined"!=typeof TextDecoder&&new TextDecoder;try{ex.decode(Kv,{stream:!0})}catch(t){}class ix extends pc{constructor(t){super(t),this.type=Vt}parse(t){const e=65536,i=14,n=65537,s=1<<i,r=s-1,a=32768,o=65535,l=59,h=63,c=2+h-l,u=8,d=4,p=4,f=2,m=1,_=0,g=1,y=0,v=2,x=Math.pow(2.7182818,2.2);var w=new DataView(new ArrayBuffer(8));function b(t){if(0===t)return[t,0];w.setFloat64(0,t);var e=w.getUint32(0)>>>20&2047;0===e&&(w.setFloat64(0,t*Math.pow(2,64)),e=(w.getUint32(0)>>>20&2047)-64);var i=e-1022,n=function(t,e){for(var i=Math.min(3,Math.ceil(Math.abs(e)/1023)),n=t,s=0;s<i;s++)n*=Math.pow(2,Math.floor((e+s)/i));return n}(t,-i);return[n,i]}const S={l:0,c:0,lc:0};function M(t,e,i,n,s){for(;i<t;)e=e<<8|K(n,s),i+=8;i-=t,S.l=e>>i&(1<<t)-1,S.c=e,S.lc=i}const T=new Array(59);function C(t){return 63&t}function A(t){return t>>6}const E={c:0,lc:0};function z(t,e,i,n){t=t<<8|K(i,n),e+=8,E.c=t,E.lc=e}const I={c:0,lc:0};function N(t,e,i,n,s,r,a,o,l,h){if(t==e){n<8&&(z(i,n,s,a),i=E.c,n=E.lc);var c=i>>(n-=8);if(c=new Uint8Array([c])[0],l.value+c>h)return!1;for(var u=o[l.value-1];c-- >0;)o[l.value++]=u}else{if(!(l.value<h))return!1;o[l.value++]=t}I.c=i,I.lc=n}function L(t){return 65535&t}function P(t){var e=L(t);return e>32767?e-65536:e}const F={a:0,b:0};function D(t,e){var i=P(t),n=P(e),s=i+(1&n)+(n>>1),r=s,a=s-n;F.a=r,F.b=a}function O(t,e){var i=L(t),n=L(e),s=i-(n>>1)&o,r=n+s-a&o;F.a=r,F.b=s}function R(t,e,i,n,s,r,a){for(var o,l=a<16384,h=i>s?s:i,c=1;c<=h;)c<<=1;for(o=c>>=1,c>>=1;c>=1;){for(var u,d,p,f,m=0,_=m+r*(s-o),g=r*c,y=r*o,v=n*c,x=n*o;m<=_;m+=y){for(var w=m,b=m+n*(i-o);w<=b;w+=x){var S=w+v,M=(T=w+g)+v;l?(D(t[w+e],t[T+e]),u=F.a,p=F.b,D(t[S+e],t[M+e]),d=F.a,f=F.b,D(u,d),t[w+e]=F.a,t[S+e]=F.b,D(p,f),t[T+e]=F.a,t[M+e]=F.b):(O(t[w+e],t[T+e]),u=F.a,p=F.b,O(t[S+e],t[M+e]),d=F.a,f=F.b,O(u,d),t[w+e]=F.a,t[S+e]=F.b,O(p,f),t[T+e]=F.a,t[M+e]=F.b)}if(i&c){var T=w+g;l?D(t[w+e],t[T+e]):O(t[w+e],t[T+e]),u=F.a,t[T+e]=F.b,t[w+e]=u}}if(s&c)for(w=m,b=m+n*(i-o);w<=b;w+=x)S=w+v,l?D(t[w+e],t[S+e]):O(t[w+e],t[S+e]),u=F.a,t[S+e]=F.b,t[w+e]=u;o=c,c>>=1}return m}function k(t,e,a,o,u,d){var p=a.value,f=$(e,a),m=$(e,a);a.value+=4;var _=$(e,a);if(a.value+=4,f<0||f>=n||m<0||m>=n)throw"Something wrong with HUF_ENCSIZE";var g=new Array(n),y=new Array(s);if(function(t){for(var e=0;e<s;e++)t[e]={},t[e].len=0,t[e].lit=0,t[e].p=null}(y),function(t,e,i,s,r,a,o){for(var u=i,d=0,p=0;r<=a;r++){if(u.value-i.value>s)return!1;M(6,d,p,t,u);var f=S.l;if(d=S.c,p=S.lc,o[r]=f,f==h){if(u.value-i.value>s)throw"Something wrong with hufUnpackEncTable";M(8,d,p,t,u);var m=S.l+c;if(d=S.c,p=S.lc,r+m>a+1)throw"Something wrong with hufUnpackEncTable";for(;m--;)o[r++]=0;r--}else if(f>=l){if(r+(m=f-l+2)>a+1)throw"Something wrong with hufUnpackEncTable";for(;m--;)o[r++]=0;r--}}!function(t){for(var e=0;e<=58;++e)T[e]=0;for(e=0;e<n;++e)T[t[e]]+=1;var i=0;for(e=58;e>0;--e){var s=i+T[e]>>1;T[e]=i,i=s}for(e=0;e<n;++e){var r=t[e];r>0&&(t[e]=r|T[r]++<<6)}}(o)}(t,0,a,o-(a.value-p),f,m,g),_>8*(o-(a.value-p)))throw"Something wrong with hufUncompress";!function(t,e,n,s){for(;e<=n;e++){var r=A(t[e]),a=C(t[e]);if(r>>a)throw"Invalid table entry";if(a>i){if((c=s[r>>a-i]).len)throw"Invalid table entry";if(c.lit++,c.p){var o=c.p;c.p=new Array(c.lit);for(var l=0;l<c.lit-1;++l)c.p[l]=o[l]}else c.p=new Array(1);c.p[c.lit-1]=e}else if(a){var h=0;for(l=1<<i-a;l>0;l--){var c;if((c=s[(r<<i-a)+h]).len||c.p)throw"Invalid table entry";c.len=a,c.lit=e,h++}}}}(g,f,m,y),function(t,e,n,s,a,o,l,h,c,u){for(var d=0,p=0,f=h,m=Math.trunc(a.value+(o+7)/8);a.value<m;)for(z(d,p,n,a),d=E.c,p=E.lc;p>=i;)if((v=e[d>>p-i&r]).len)p-=v.len,N(v.lit,l,d,p,n,0,a,c,u,f),d=I.c,p=I.lc;else{if(!v.p)throw"hufDecode issues";var _;for(_=0;_<v.lit;_++){for(var g=C(t[v.p[_]]);p<g&&a.value<m;)z(d,p,n,a),d=E.c,p=E.lc;if(p>=g&&A(t[v.p[_]])==(d>>p-g&(1<<g)-1)){p-=g,N(v.p[_],l,d,p,n,0,a,c,u,f),d=I.c,p=I.lc;break}}if(_==v.lit)throw"hufDecode issues"}var y=8-o&7;for(d>>=y,p-=y;p>0;){var v;if(!(v=e[d<<i-p&r]).len)throw"hufDecode issues";p-=v.len,N(v.lit,l,d,p,n,0,a,c,u,f),d=I.c,p=I.lc}}(g,y,t,0,a,_,m,d,u,{value:0})}function U(t){for(var e=1;e<t.length;e++){var i=t[e-1]+t[e]-128;t[e]=i}}function B(t,e){for(var i=0,n=Math.floor((t.length+1)/2),s=0,r=t.length-1;!(s>r||(e[s++]=t[i++],s>r));)e[s++]=t[n++]}function V(t){for(var e=t.byteLength,i=new Array,n=0,s=new DataView(t);e>0;){var r=s.getInt8(n++);if(r<0){e-=1+(o=-r);for(var a=0;a<o;a++)i.push(s.getUint8(n++))}else{var o=r;e-=2;var l=s.getUint8(n++);for(a=0;a<o+1;a++)i.push(l)}}return i}function G(t,e,i){for(var n,s=1;s<64;)65280==(n=e[t.value])?s=64:n>>8==255?s+=255&n:(i[s]=n,s++),t.value++}function W(t){const e=.5*Math.cos(.7853975),i=.5*Math.cos(3.14159/16),n=.5*Math.cos(3.14159/8),s=.5*Math.cos(3*3.14159/16),r=.5*Math.cos(.981746875),a=.5*Math.cos(3*3.14159/8),o=.5*Math.cos(1.374445625);for(var l=new Array(4),h=new Array(4),c=new Array(4),u=new Array(4),d=0;d<8;++d){var p=8*d;l[0]=n*t[p+2],l[1]=a*t[p+2],l[2]=n*t[p+6],l[3]=a*t[p+6],h[0]=i*t[p+1]+s*t[p+3]+r*t[p+5]+o*t[p+7],h[1]=s*t[p+1]-o*t[p+3]-i*t[p+5]-r*t[p+7],h[2]=r*t[p+1]-i*t[p+3]+o*t[p+5]+s*t[p+7],h[3]=o*t[p+1]-r*t[p+3]+s*t[p+5]-i*t[p+7],c[0]=e*(t[p+0]+t[p+4]),c[3]=e*(t[p+0]-t[p+4]),c[1]=l[0]+l[3],c[2]=l[1]-l[2],u[0]=c[0]+c[1],u[1]=c[3]+c[2],u[2]=c[3]-c[2],u[3]=c[0]-c[1],t[p+0]=u[0]+h[0],t[p+1]=u[1]+h[1],t[p+2]=u[2]+h[2],t[p+3]=u[3]+h[3],t[p+4]=u[3]-h[3],t[p+5]=u[2]-h[2],t[p+6]=u[1]-h[1],t[p+7]=u[0]-h[0]}for(var f=0;f<8;++f)l[0]=n*t[16+f],l[1]=a*t[16+f],l[2]=n*t[48+f],l[3]=a*t[48+f],h[0]=i*t[8+f]+s*t[24+f]+r*t[40+f]+o*t[56+f],h[1]=s*t[8+f]-o*t[24+f]-i*t[40+f]-r*t[56+f],h[2]=r*t[8+f]-i*t[24+f]+o*t[40+f]+s*t[56+f],h[3]=o*t[8+f]-r*t[24+f]+s*t[40+f]-i*t[56+f],c[0]=e*(t[f]+t[32+f]),c[3]=e*(t[f]-t[32+f]),c[1]=l[0]+l[3],c[2]=l[1]-l[2],u[0]=c[0]+c[1],u[1]=c[3]+c[2],u[2]=c[3]-c[2],u[3]=c[0]-c[1],t[0+f]=u[0]+h[0],t[8+f]=u[1]+h[1],t[16+f]=u[2]+h[2],t[24+f]=u[3]+h[3],t[32+f]=u[3]-h[3],t[40+f]=u[2]-h[2],t[48+f]=u[1]-h[1],t[56+f]=u[0]-h[0]}function H(t){for(var e=0;e<64;++e){var i=t[0][e],n=t[1][e],s=t[2][e];t[0][e]=i+1.5747*s,t[1][e]=i-.1873*n-.4682*s,t[2][e]=i+1.8556*n}}function j(t,e,i){for(var n=0;n<64;++n)e[i+n]=su.toHalfFloat((s=t[n])<=1?Math.sign(s)*Math.pow(Math.abs(s),2.2):Math.sign(s)*Math.pow(x,Math.abs(s)-1));var s}function q(t){var e=tx(t.array.slice(t.offset.value,t.offset.value+t.size)),i=new Uint8Array(e.length);return U(e),B(e,i),new DataView(i.buffer)}function J(t){var e=t.viewer,i={value:t.offset.value},n=new Uint8Array(t.width*t.lines*(ot.channels.length*t.type*f)),s={version:tt(e,i),unknownUncompressedSize:tt(e,i),unknownCompressedSize:tt(e,i),acCompressedSize:tt(e,i),dcCompressedSize:tt(e,i),rleCompressedSize:tt(e,i),rleUncompressedSize:tt(e,i),rleRawSize:tt(e,i),totalAcUncompressedCount:tt(e,i),totalDcUncompressedCount:tt(e,i),acCompression:tt(e,i)};if(s.version<2)throw"EXRLoader.parse: "+ot.compression+" version "+s.version+" is unsupported";for(var r=new Array,a=nt(e,i)-f;a>0;){var o=Y(e.buffer,i),l=Q(e,i),h=l>>2&3,c=new Int8Array([(l>>4)-1])[0],u=Q(e,i);r.push({name:o,index:c,type:u,compression:h}),a-=o.length+3}for(var d=ot.channels,p=new Array(t.channels),m=0;m<t.channels;++m){var x=p[m]={},w=d[m];x.name=w.name,x.compression=y,x.decoded=!1,x.type=w.pixelType,x.pLinear=w.pLinear,x.width=t.width,x.height=t.lines}for(var b={idx:new Array(3)},S=0;S<t.channels;++S)for(x=p[S],m=0;m<r.length;++m){var M=r[m];x.name==M.name&&(x.compression=M.compression,M.index>=0&&(b.idx[M.index]=S),x.offset=S)}if(s.acCompressedSize>0)switch(s.acCompression){case _:var T=new Uint16Array(s.totalAcUncompressedCount);k(t.array,e,i,s.acCompressedSize,T,s.totalAcUncompressedCount);break;case g:var C=tx(t.array.slice(i.value,i.value+s.totalAcUncompressedCount));T=new Uint16Array(C.buffer),i.value+=s.totalAcUncompressedCount}if(s.dcCompressedSize>0){var A={array:t.array,offset:i,size:s.dcCompressedSize},E=new Uint16Array(q(A).buffer);i.value+=s.dcCompressedSize}if(s.rleRawSize>0){var z=V((C=tx(t.array.slice(i.value,i.value+s.rleCompressedSize))).buffer);i.value+=s.rleCompressedSize}var I=0,N=new Array(p.length);for(m=0;m<N.length;++m)N[m]=new Array;for(var L=0;L<t.lines;++L)for(var P=0;P<p.length;++P)N[P].push(I),I+=p[P].width*t.type*f;for(function(t,e,i,n,s,r){var a,o,l=new DataView(r.buffer),h=i[t.idx[0]].width,c=i[t.idx[0]].height,u=Math.floor(h/8),d=Math.ceil(h/8),p=Math.ceil(c/8),m=h-8*(d-1),_=c-8*(p-1),g={value:0},y=new Array(3),v=new Array(3),x=new Array(3),w=new Array(3),b=new Array(3);for(let i=0;i<3;++i)b[i]=e[t.idx[i]],y[i]=i<1?0:y[i-1]+d*p,v[i]=new Float32Array(64),x[i]=new Uint16Array(64),w[i]=new Uint16Array(64*d);for(let e=0;e<p;++e){var S=8;e==p-1&&(S=_);var M=8;for(let t=0;t<d;++t){t==d-1&&(M=m);for(let t=0;t<3;++t)x[t].fill(0),x[t][0]=s[y[t]++],G(g,n,x[t]),a=x[t],(o=v[t])[0]=it(a[0]),o[1]=it(a[1]),o[2]=it(a[5]),o[3]=it(a[6]),o[4]=it(a[14]),o[5]=it(a[15]),o[6]=it(a[27]),o[7]=it(a[28]),o[8]=it(a[2]),o[9]=it(a[4]),o[10]=it(a[7]),o[11]=it(a[13]),o[12]=it(a[16]),o[13]=it(a[26]),o[14]=it(a[29]),o[15]=it(a[42]),o[16]=it(a[3]),o[17]=it(a[8]),o[18]=it(a[12]),o[19]=it(a[17]),o[20]=it(a[25]),o[21]=it(a[30]),o[22]=it(a[41]),o[23]=it(a[43]),o[24]=it(a[9]),o[25]=it(a[11]),o[26]=it(a[18]),o[27]=it(a[24]),o[28]=it(a[31]),o[29]=it(a[40]),o[30]=it(a[44]),o[31]=it(a[53]),o[32]=it(a[10]),o[33]=it(a[19]),o[34]=it(a[23]),o[35]=it(a[32]),o[36]=it(a[39]),o[37]=it(a[45]),o[38]=it(a[52]),o[39]=it(a[54]),o[40]=it(a[20]),o[41]=it(a[22]),o[42]=it(a[33]),o[43]=it(a[38]),o[44]=it(a[46]),o[45]=it(a[51]),o[46]=it(a[55]),o[47]=it(a[60]),o[48]=it(a[21]),o[49]=it(a[34]),o[50]=it(a[37]),o[51]=it(a[47]),o[52]=it(a[50]),o[53]=it(a[56]),o[54]=it(a[59]),o[55]=it(a[61]),o[56]=it(a[35]),o[57]=it(a[36]),o[58]=it(a[48]),o[59]=it(a[49]),o[60]=it(a[57]),o[61]=it(a[58]),o[62]=it(a[62]),o[63]=it(a[63]),W(v[t]);H(v);for(let e=0;e<3;++e)j(v[e],w[e],64*t)}let r=0;for(let n=0;n<3;++n){const s=i[t.idx[n]].type;for(let t=8*e;t<8*e+S;++t){r=b[n][t];for(let e=0;e<u;++e){const i=64*e+8*(7&t);l.setUint16(r+0*f*s,w[n][i+0],!0),l.setUint16(r+1*f*s,w[n][i+1],!0),l.setUint16(r+2*f*s,w[n][i+2],!0),l.setUint16(r+3*f*s,w[n][i+3],!0),l.setUint16(r+4*f*s,w[n][i+4],!0),l.setUint16(r+5*f*s,w[n][i+5],!0),l.setUint16(r+6*f*s,w[n][i+6],!0),l.setUint16(r+7*f*s,w[n][i+7],!0),r+=8*f*s}}if(u!=d)for(let t=8*e;t<8*e+S;++t){const e=b[n][t]+8*u*f*s,i=64*u+8*(7&t);for(let t=0;t<M;++t)l.setUint16(e+t*f*s,w[n][i+t],!0)}}}for(var T=new Uint16Array(h),C=(l=new DataView(r.buffer),0);C<3;++C){i[t.idx[C]].decoded=!0;var A=i[t.idx[C]].type;if(2==i[C].type)for(var E=0;E<c;++E){const t=b[C][E];for(var z=0;z<h;++z)T[z]=l.getUint16(t+z*f*A,!0);for(z=0;z<h;++z)l.setFloat32(t+z*f*A,it(T[z]),!0)}}}(b,N,p,T,E,n),m=0;m<p.length;++m)if(!(x=p[m]).decoded){if(x.compression!==v)throw"EXRLoader.parse: unsupported channel compression";var F=0,D=0;for(L=0;L<t.lines;++L){for(var O=N[m][F],R=0;R<x.width;++R){for(var U=0;U<f*x.type;++U)n[O++]=z[D+U*x.width*x.height];D++}F++}}return new DataView(n.buffer)}function Y(t,e){for(var i=new Uint8Array(t),n=0;0!=i[e.value+n];)n+=1;var s=(new TextDecoder).decode(i.slice(e.value,e.value+n));return e.value=e.value+n+1,s}function X(t,e){var i=t.getUint32(0,!0);return e.value=e.value+u,i}function Z(t,e){var i=t.getInt32(e.value,!0);return e.value=e.value+p,i}function $(t,e){var i=t.getUint32(e.value,!0);return e.value=e.value+p,i}function K(t,e){var i=t[e.value];return e.value=e.value+m,i}function Q(t,e){var i=t.getUint8(e.value);return e.value=e.value+m,i}function tt(t,e){var i=Number(t.getBigInt64(e.value,!0));return e.value+=u,i}function et(t,e){var i=t.getFloat32(e.value,!0);return e.value+=d,i}function it(t){var e=(31744&t)>>10,i=1023&t;return(t>>15?-1:1)*(e?31===e?i?NaN:Infinity:Math.pow(2,e-15)*(1+i/1024):i/1024*6103515625e-14)}function nt(t,e){var i=t.getUint16(e.value,!0);return e.value+=f,i}function st(t,e,i,n,s){return"string"===n||"stringvector"===n||"iccProfile"===n?function(t,e,i){var n=(new TextDecoder).decode(new Uint8Array(t).slice(e.value,e.value+i));return e.value=e.value+i,n}(e,i,s):"chlist"===n?function(t,e,i,n){for(var s=i.value,r=[];i.value<s+n-1;){var a=Y(e,i),o=Z(t,i),l=Q(t,i);i.value+=3;var h=Z(t,i),c=Z(t,i);r.push({name:a,pixelType:o,pLinear:l,xSampling:h,ySampling:c})}return i.value+=1,r}(t,e,i,s):"chromaticities"===n?function(t,e){return{redX:et(t,e),redY:et(t,e),greenX:et(t,e),greenY:et(t,e),blueX:et(t,e),blueY:et(t,e),whiteX:et(t,e),whiteY:et(t,e)}}(t,i):"compression"===n?function(t,e){return["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"][Q(t,e)]}(t,i):"box2i"===n?function(t,e){return{xMin:$(t,e),yMin:$(t,e),xMax:$(t,e),yMax:$(t,e)}}(t,i):"lineOrder"===n?function(t,e){return["INCREASING_Y"][Q(t,e)]}(t,i):"float"===n?et(t,i):"v2f"===n?function(t,e){return[et(t,e),et(t,e)]}(t,i):"v3f"===n?function(t,e){return[et(t,e),et(t,e),et(t,e)]}(t,i):"int"===n?Z(t,i):"rational"===n?function(t,e){return[Z(t,e),$(t,e)]}(t,i):"timecode"===n?function(t,e){return[$(t,e),$(t,e)]}(t,i):"preview"===n?(i.value+=s,"skipped"):void(i.value+=s)}var rt=new DataView(t),at=new Uint8Array(t),ot={};rt.getUint32(0,!0),rt.getUint8(4,!0),rt.getUint8(5,!0);for(var lt={value:8},ht=!0;ht;){var ct=Y(t,lt);if(0==ct)ht=!1;else{var ut=st(rt,t,lt,Y(t,lt),$(rt,lt));void 0===ut||(ot[ct]=ut)}}var dt,pt,ft,mt,_t=ot.dataWindow.yMax+1;switch(ot.compression){case"NO_COMPRESSION":pt=1,dt=function(t){return new DataView(t.array.buffer,t.offset.value,t.size)};break;case"RLE_COMPRESSION":pt=1,dt=function(t){var e=t.viewer.buffer.slice(t.offset.value,t.offset.value+t.size),i=new Uint8Array(V(e)),n=new Uint8Array(i.length);return U(i),B(i,n),new DataView(n.buffer)};break;case"ZIPS_COMPRESSION":pt=1,dt=q;break;case"ZIP_COMPRESSION":pt=16,dt=q;break;case"PIZ_COMPRESSION":pt=32,dt=function(t){for(var i=t.viewer,n={value:t.offset.value},s=t.width*pt*(ot.channels.length*t.type),r=new Uint16Array(s),a=new Uint8Array(8192),o=0,l=new Array(t.channels),h=0;h<t.channels;h++)l[h]={},l[h].start=o,l[h].end=l[h].start,l[h].nx=t.width,l[h].ny=t.lines,l[h].size=t.type,o+=l[h].nx*l[h].ny*l[h].size;var c=nt(i,n),u=nt(i,n);if(u>=8192)throw"Something is wrong with PIZ_COMPRESSION BITMAP_SIZE";if(c<=u)for(h=0;h<u-c+1;h++)a[h+c]=Q(i,n);var d=new Uint16Array(e),p=function(t,i){for(var n=0,s=0;s<e;++s)(0==s||t[s>>3]&1<<(7&s))&&(i[n++]=s);for(var r=n-1;n<e;)i[n++]=0;return r}(a,d),m=$(i,n);for(k(t.array,i,n,m,r,o),h=0;h<t.channels;++h)for(var _=l[h],g=0;g<l[h].size;++g)R(r,_.start+g,_.nx,_.size,_.ny,_.nx*_.size,p);!function(t,e,i){for(var n=0;n<i;++n)e[n]=t[e[n]]}(d,r,o);for(var y=0,v=new Uint8Array(r.buffer.byteLength),x=0;x<t.lines;x++)for(var w=0;w<t.channels;w++){var b=(_=l[w]).nx*_.size,S=new Uint8Array(r.buffer,_.end*f,b*f);v.set(S,y),y+=b*f,_.end+=b}return new DataView(v.buffer)};break;case"PXR24_COMPRESSION":pt=16,dt=function(t){var e=tx(t.array.slice(t.offset.value,t.offset.value+t.size));const i=t.lines*t.channels*t.width,n=1==t.type?new Uint16Array(i):new Uint32Array(i);let s=0,r=0;const a=new Array(4);for(let i=0;i<t.lines;i++)for(let i=0;i<t.channels;i++){let i=0;switch(t.type){case 1:a[0]=s,a[1]=a[0]+t.width,s=a[1]+t.width;for(let s=0;s<t.width;++s)i+=e[a[0]++]<<8|e[a[1]++],n[r]=i,r++;break;case 2:a[0]=s,a[1]=a[0]+t.width,a[2]=a[1]+t.width,s=a[2]+t.width;for(let s=0;s<t.width;++s)i+=e[a[0]++]<<24|e[a[1]++]<<16|e[a[2]++]<<8,n[r]=i,r++}}return new DataView(n.buffer)};break;case"DWAA_COMPRESSION":pt=32,dt=J;break;case"DWAB_COMPRESSION":pt=256,dt=J;break;default:throw"EXRLoader.parse: "+ot.compression+" is unsupported"}var gt=ot.channels[0].pixelType;if(1===gt)switch(this.type){case Ft:case Bt:mt=function(t,e){return it(nt(t,e))},ft=f;break;case Vt:mt=nt,ft=f}else{if(2!==gt)throw"EXRLoader.parse: unsupported pixelType "+gt+" for "+ot.compression+".";switch(this.type){case Ft:case Bt:mt=et,ft=d;break;case Vt:mt=function(t,e){return su.toHalfFloat(et(t,e))},ft=d}}for(var yt=_t/pt,vt=0;vt<yt;vt++)X(rt,lt);var xt=ot.dataWindow.xMax-ot.dataWindow.xMin+1,wt=ot.dataWindow.yMax-ot.dataWindow.yMin+1,bt=xt*wt*4;switch(this.type){case Ft:case Bt:var St=new Float32Array(bt);ot.channels.length<4&&St.fill(1,0,bt);break;case Vt:St=new Uint16Array(bt),ot.channels.length<4&&St.fill(15360,0,bt)}for(var Mt,Tt,Ct={R:0,G:1,B:2,A:3},At={size:0,width:xt,lines:pt,offset:lt,array:at,viewer:rt,type:gt,channels:ot.channels.length},Et={value:0},zt=0;zt<wt/pt;zt++){Mt=$(rt,lt),bt=$(rt,lt),At.lines=Mt+pt>wt?wt-Mt:pt,At.offset=lt,At.size=bt,Tt=dt(At),lt.value+=bt;for(var It=0;It<pt;It++){var Nt=It+zt*pt;if(Nt>=wt)break;for(var Lt=0;Lt<ot.channels.length;Lt++)for(var Pt=Ct[ot.channels[Lt].name],Dt=0;Dt<xt;Dt++){var Ot=It*(ot.channels.length*xt)+Lt*xt+Dt;Et.value=Ot*ft;var Rt=mt(Tt,Et);St[4*xt*(wt-1-Nt)+4*Dt+Pt]=Rt}}}if(this.type===Ft){let t,e;const i=St.length,n=new Uint8Array(i);for(let i=0;i<wt;++i)for(let s=0;s<xt;++s){e=i*xt*4+4*s;const r=St[e],a=St[e+1],o=St[e+2];if(t=r>a?r:a,t=o>t?o:t,t<1e-32)n[e]=n[e+1]=n[e+2]=n[e+3]=0;else{const i=b(t);t=256*i[0]/t,n[e]=r*t,n[e+1]=a*t,n[e+2]=o*t,n[e+3]=i[1]+128}}St=n}const kt=this.type===Ft?$t:Yt;return{header:ot,width:xt,height:wt,data:St,format:kt,type:this.type}}setDataType(t){return this.type=t,this}load(t,e,i,n){return super.load(t,(function(t,i){switch(t.type){case Ft:t.encoding=ei,t.minFilter=Et,t.magFilter=Et,t.generateMipmaps=!1,t.flipY=!1;break;case Bt:case Vt:t.encoding=Ke,t.minFilter=Nt,t.magFilter=Nt,t.generateMipmaps=!1,t.flipY=!1}e&&e(t,i)}),i,n)}}class nx extends pc{constructor(t){super(t),this.type=Vt}parse(t){const e=function(t,e,i){e=e||1024;let n=t.pos,s=-1,r=0,a="",o=String.fromCharCode.apply(null,new Uint16Array(t.subarray(n,n+128)));for(;0>(s=o.indexOf("\n"))&&r<e&&n<t.byteLength;)a+=o,r+=o.length,n+=128,o+=String.fromCharCode.apply(null,new Uint16Array(t.subarray(n,n+128)));return-1<s&&(!1!==i&&(t.pos+=r+s+1),a+o.slice(0,s))},i=function(t,e,i,n){const s=t[e+3],r=Math.pow(2,s-128)/255;i[n+0]=t[e+0]*r,i[n+1]=t[e+1]*r,i[n+2]=t[e+2]*r},n=function(t,e,i,n){const s=t[e+3],r=Math.pow(2,s-128)/255;i[n+0]=su.toHalfFloat(Math.min(t[e+0]*r,65504)),i[n+1]=su.toHalfFloat(Math.min(t[e+1]*r,65504)),i[n+2]=su.toHalfFloat(Math.min(t[e+2]*r,65504))},s=new Uint8Array(t);s.pos=0;const r=function(t){const i=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,n=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,s=/^\s*FORMAT=(\S+)\s*$/,r=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,a={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let o,l;if(t.pos>=t.byteLength||!(o=e(t)))return-1;if(!(l=o.match(/^#\?(\S+)/)))return-1;for(a.valid|=1,a.programtype=l[1],a.string+=o+"\n";o=e(t),!1!==o;)if(a.string+=o+"\n","#"!==o.charAt(0)){if((l=o.match(i))&&(a.gamma=parseFloat(l[1],10)),(l=o.match(n))&&(a.exposure=parseFloat(l[1],10)),(l=o.match(s))&&(a.valid|=2,a.format=l[1]),(l=o.match(r))&&(a.valid|=4,a.height=parseInt(l[1],10),a.width=parseInt(l[2],10)),2&a.valid&&4&a.valid)break}else a.comments+=o+"\n";return 2&a.valid&&4&a.valid?a:-1}(s);if(-1!==r){const t=r.width,e=r.height,a=function(t,e,i){const n=e;if(n<8||n>32767||2!==t[0]||2!==t[1]||128&t[2])return new Uint8Array(t);if(n!==(t[2]<<8|t[3]))return-1;const s=new Uint8Array(4*e*i);if(!s.length)return-1;let r=0,a=0;const o=4*n,l=new Uint8Array(4),h=new Uint8Array(o);let c=i;for(;c>0&&a<t.byteLength;){if(a+4>t.byteLength)return-1;if(l[0]=t[a++],l[1]=t[a++],l[2]=t[a++],l[3]=t[a++],2!=l[0]||2!=l[1]||(l[2]<<8|l[3])!=n)return-1;let e,i=0;for(;i<o&&a<t.byteLength;){e=t[a++];const n=e>128;if(n&&(e-=128),0===e||i+e>o)return-1;if(n){const n=t[a++];for(let t=0;t<e;t++)h[i++]=n}else h.set(t.subarray(a,a+e),i),i+=e,a+=e}const u=n;for(let t=0;t<u;t++){let e=0;s[r]=h[t+e],e+=n,s[r+1]=h[t+e],e+=n,s[r+2]=h[t+e],e+=n,s[r+3]=h[t+e],r+=4}c--}return s}(s.subarray(s.pos),t,e);if(-1!==a){let s,o,l,h;switch(this.type){case Ft:s=a,o=$t,l=Ft;break;case Bt:h=a.length/4;const t=new Float32Array(3*h);for(let e=0;e<h;e++)i(a,4*e,t,3*e);s=t,o=Jt,l=Bt;break;case Vt:h=a.length/4;const e=new Uint16Array(3*h);for(let t=0;t<h;t++)n(a,4*t,e,3*t);s=e,o=Jt,l=Vt}return{width:t,height:e,data:s,header:r.string,gamma:r.gamma,exposure:r.exposure,format:o,type:l}}}return null}setDataType(t){return this.type=t,this}load(t,e,i,n){return super.load(t,(function(t,i){switch(t.type){case Ft:t.encoding=ei,t.minFilter=Et,t.magFilter=Et,t.generateMipmaps=!1,t.flipY=!0;break;case Bt:case Vt:t.encoding=Ke,t.minFilter=Nt,t.magFilter=Nt,t.generateMipmaps=!1,t.flipY=!0}e&&e(t,i)}),i,n)}}class sx extends lc{constructor(t){super(t),this.hdrLoader=new nx,this.type=Vt}load(t,e,i,n){Array.isArray(t)||(this.setDataType(t),t=e,e=i,i=n,n=arguments[4]);const s=new Ys;switch(s.type=this.type,s.type){case Ft:s.encoding=ei,s.format=Yt,s.minFilter=Et,s.magFilter=Et,s.generateMipmaps=!1;break;case Bt:case Vt:s.encoding=Ke,s.format=Jt,s.minFilter=Nt,s.magFilter=Nt,s.generateMipmaps=!1}const r=this;let a=0;function o(e,i,n,o){new cc(r.manager).setPath(r.path).setResponseType("arraybuffer").setWithCredentials(r.withCredentials).load(t[e],(function(t){a++;const n=r.hdrLoader.parse(t);if(n){if(void 0!==n.data){const t=new wl(n.data,n.width,n.height);t.type=s.type,t.encoding=s.encoding,t.format=s.format,t.minFilter=s.minFilter,t.magFilter=s.magFilter,t.generateMipmaps=s.generateMipmaps,s.images[e]=t}6===a&&(s.needsUpdate=!0,i&&i(s))}}),n,o)}for(let s=0;s<t.length;s++)o(s,e,i,n);return s}setDataType(t){return this.type=t,this.hdrLoader.setDataType(t),this}}const rx=Math.PI/180;function ax(t,e){const i=this;this.entityManager=e,this.__material_manager=new _v,this.on={preRender:new l,postRender:new l,preOpaquePass:new l,postOpaquePass:new l,preComposite:new l,postComposite:new l,buffersRendered:new l,visibilityConstructionStarted:new l,visibilityConstructionEnded:new l},this.pixelRatio=new Id(1),this.layers=new ev,this.bvh=new vd,this.bvh.setNegativelyInfiniteBounds();const n=new Zo;n.autoUpdate=!1,n.matrixAutoUpdate=!1,this.scene=n,this.visibleGroup=new Wo,this.visibleGroup.matrixAutoUpdate=!1,this.scene.add(this.visibleGroup),this.camera=t,this.renderer=null,this.layerComposer=new Ty,this.initGUI=function(t){void 0!==this.effects&&this.effects.initializeGUI(t)},Object.defineProperties(this,{info:{get:function(){return i.renderer.info}}}),this.viewport=new Ey,this.viewport.size.onChanged.add(this.updateSize,this),this.pixelRatio.onChanged.add(this.updateSize,this),this.frameBuffers=new nv,this.shadowmap_renderer=new xv,this.views=new Cv,this.main_view=this.views.create(),this.main_view.name="Main Camera",this.needDraw=!0,this.autoDraw=!0,this.frameIndex=0}function ox(t){if(t.isMesh||t.isPoints){const e=t.material;if(!1===e.depthWrite&&!1===e.depthTest)return zy.Transparent}return zy.Opaque}function lx(){let t=window.AudioContext||window.webkitAudioContext||null;if(!t)throw new Error("AudioContext not supported!");const e=this.context=new t({latencyHint:"interactive"});e.suspend();const i=e.createGain(),n=e.createDynamicsCompressor();this.destination=i,i.connect(n),n.connect(e.destination),Object.defineProperties(this,{volume:{get:function(){return i.gain.value},set:function(t){i.gain.setValueAtTime(t,e.currentTime,0)}}})}ax.prototype.getMaterialManager=function(){return this.__material_manager},ax.prototype.getRenderer=function(){return this.renderer},ax.prototype.loadEnvironmentMap=async function(t){const{filtered:e}=await async function({path:t,renderer:e,original:i=!1,filtered:n=!0}){let s,r,a;if(Array.isArray(t))a="hdr"===l_(t[0])?await function(t){const e=new sx;return new Promise(((i,n)=>{e.load(t,(t=>{i(t)}),Jd,n)}))}(t):await function(t){const e=new dc;return new Promise(((i,n)=>{e.load(t,(t=>{t.magFilter=Nt,t.encoding=Qe,i(t)}),Jd,n)}))}(t),s="c";else{if("string"!=typeof t)throw new Error(`Unsupported parameter format: '${t}'`);{const e=l_(t).toLowerCase();if("exr"===e)a=await function(t){return new Promise(((e,i)=>{(new ix).setDataType(Ft).load(t,(t=>{e(t)}),Jd,i)}))}(t);else{if("jpg"!==e)throw new Error(`Unsupported cube map texture extension '${e}'`);a=await function(t){return new Promise(((e,i)=>{(new fc).load(t,(t=>{t.encoding=Qe,e(t)}),Jd,i)}))}(t)}s="e"}}const o={};if(n){if(void 0===e)throw new Error("renderer argument not supplied, expected a WebGLRenderer");const t=new Lr(e);if("c"===s)r=t.fromCubemap(a);else{if("e"!==s)throw new Error(`Unsupported cubemap type '${s}'`);r=t.fromEquirectangular(a)}t.dispose(),o.filtered=r.texture}return i?o.original=a:a.dispose(),o}({path:t,renderer:this.renderer,original:!1,filtered:!0});return this.scene.environment=e,e},ax.prototype.updateSize=function(){const t=this.viewport.size,e=this.renderer,i=this.pixelRatio.getValue(),n=Eu(0,t.x*i),s=Eu(0,t.y*i);e.setSize(n,s);const r=window.devicePixelRatio;e.setPixelRatio(r),e.domElement.style.width=t.x+"px",e.domElement.style.height=t.y+"px",this.frameBuffers.setPixelRatio(r),this.layerComposer.setPixelRatio(r),this.layerComposer.setSize(n,s),this.frameBuffers.setSize(n,s)},ax.prototype.getResolution=function(t){const e=this.computeTotalPixelRatio();t.set(this.viewport.size.x*e,this.viewport.size.y*e)},ax.prototype.computeTotalPixelRatio=function(){return this.pixelRatio.getValue()*window.devicePixelRatio},ax.prototype.initializeFrameBuffers=function(){const t=new rv(sy);t.referenceCount+=1,this.frameBuffers.add(t);const e=new pv(ry);this.frameBuffers.add(e),this.frameBuffers.initialize(this.renderer)},ax.prototype.getDepthTexture=function(){return this.frameBuffers.getById(sy).renderTarget.depthTexture},ax.prototype.start=function(){const t=document.createElement("canvas"),e=t.getContext("webgl2",{antialias:!1}),i={antialias:!0,logarithmicDepthBuffer:!1,canvas:t,context:e},n=this.renderer=new Xo(i),s=this.getGPUName();cv.record("gpu-type",{category:"system",label:s}),n.domElement.addEventListener("webglcontextrestored",(function(t){}),!1),n.domElement.addEventListener("webglcontextlost",(function(t){t.preventDefault()}),!1);const r=this.domElement=n.domElement,a=r.style;r.classList.add("graphics-engine-render-canvas"),a.userSelect=a.webkitUserSelect=a.mozUserSelect="none",a.touchAction="none",function(t){t.autoClear=!1,t.setClearColor(12303359,0),t.outputEncoding=Ke,t.toneMapping=pt,t.toneMappingExposure=1,t.state.setFlipSided(!1),t.shadowMap.enabled=!0,t.shadowMap.type=I,t.sortObjects=!0,t.info.autoReset=!1,ENV_PRODUCTION?t.debug.checkShaderErrors=!1:t.debug.checkShaderErrors=!0}(n),this.enableExtensions(),this.initializeFrameBuffers();const o=this.viewport,l=o.size;n.setSize(l.x,l.y),this.frameBuffers.setSize(l.x,l.y),o.el=n.domElement},ax.prototype.getGPUName=function(){const t=this.renderer.getContext(),e=t.getExtension("WEBGL_debug_renderer_info");return null===e?"Unknown":t.getParameter(e.UNMASKED_RENDERER_WEBGL)},ax.prototype.stop=function(){const t=this.renderer;void 0!==t&&(t.forceContextLoss(),t.context=null,t.domElement=null,this.renderer=null)},ax.prototype.enableExtensions=function(){const t=this.renderer.getContext();t.getExtension("OES_standard_derivatives"),t.getExtension("WEBGL_depth_texture"),t.getExtension("WEBGL_compressed_texture_s3tc")},ax.prototype.viewportProjectionRay=function(t,e,i,n){Pm.projectRay(this.camera,t,e,i,n)},ax.prototype.intersectObjectUnderViewportPoint=function(){const t=new Di,e=new Xc,i=new Di;return function(n,s,r,a){return this.viewportProjectionRay(n,s,i,t),e.set(i,t),e.intersectObject(r,a)}}(),ax.prototype.normalizeViewportPoint=function(t,e){const i=this.viewport.size,n=t.x,s=t.y;e.x=n/i.x*2-1,e.y=-s/i.y*2+1},ax.prototype.viewportWorldSize=function(t,e,i){const n=this.viewport.size,s=t.fov*rx,r=t.position.z,a=Math.abs(r)+e,o=Math.tan(.5*s)*a*2,l=o*(n.x/n.y);return i.x=l,i.y=o,i},ax.prototype.constructVisibleScene=function(t,e,i){this.on.visibilityConstructionStarted.send3(t,e,i),this.main_view.set_from_camera(e),this.views.build_visibility(this.layers),this.on.visibilityConstructionEnded.send3(t,e,i)},ax.prototype.clearVisibleGroup=function(){this.visibleGroup.children.length=0},ax.prototype.prepareRenderPass=function(t){this.clearVisibleGroup();const e=this.visibleGroup;let i=0;const n=this.main_view.visible_objects,s=n.size,r=n.elements;for(let n=0;n<s;n++){const s=r[n];ox(s)===t&&(s.parent=e,e.children[i++]=s)}e.length=i},ax.prototype.renderOpaque=function(){this.on.preOpaquePass.send0(),this.prepareRenderPass(zy.Opaque);const t=this.renderer,e=this.frameBuffers;e.render(t,this.camera,this.scene),function(t,e){av.tTexture.value=t,ey(e,ov)}(e.getById(sy).renderTarget.texture,t),this.on.postOpaquePass.send0()},ax.prototype.renderTransparent=function(){const t=this.scene,e=t.background;t.background=null,this.prepareRenderPass(zy.Transparent),this.renderer.render(t,this.camera),t.background=e},ax.prototype.render=function(){this.needDraw&&!this.autoDraw&&(this.needDraw=!1),this.frameIndex++;const t=this.renderer;t.info.reset(),t.autoClear=!1,t.clearAlpha=0;const e=this.scene,i=this.camera;e.children.indexOf(i)<0&&e.add(i),this.constructVisibleScene(t,i,e),this.on.preRender.send3(t,i,e),this.main_view.on.preRender.send1(this.main_view),this.renderOpaque(),this.layerComposer.composite(t,1),this.on.buffersRendered.send3(t,i,e),this.renderTransparent(),this.layerComposer.composite(t,0),this.on.postRender.send3(t,i,e)},lx.prototype.getCurrentTime=function(){return this.context.currentTime},lx.prototype.resumeContext=function(){return this.context.resume()},lx.prototype.start=function(){return new Promise(((t,e)=>{this.resumeContext(),t()}))};const hx="mousedown",cx="mouseup",ux="mousemove",dx="mouseenter",px="mouseleave",fx="wheel",mx="touchstart",_x="touchend",gx="touchmove";function yx(t){return t.preventDefault(),t.stopPropagation(),!1}function vx(t,e){const i=t.length;for(let n=0;n<i;n++)e(t.item(n),n)}function xx(t,e){const i=t.length;let n=0,s=0;if(i>0){for(let e=0;e<i;e++){const i=t.item(e);null!==i&&(n+=i.clientX,s+=i.clientY)}n/=i,s/=i}e.set(n,s)}function wx(t){this.isRunning=!1,this.__target=null,this.domElement=t;const e=this.position=new wd;this.eventHandlerMouseMove=t=>{t.preventDefault(),this.__target=t.target,this.readPointerPositionFromEvent(e,t),this.on.move.send3(e,t,new wd(t.movementX,t.movementY))},this.eventHandlerMouseUp=t=>{this.readPointerPositionFromEvent(e,t),this.on.up.send2(e,t)},this.eventHandlerMouseDown=t=>{this.readPointerPositionFromEvent(e,t),this.on.down.send2(e,t)};const i=new l,n=new l,s=new l;i.add(((t,e,i)=>{this.on.down.send3(t,e,i)})),n.add(((t,e,i)=>{this.on.up.send3(t,e,i)})),s.add(((t,e,i)=>{this.on.move.send3(t,e,i)}));const r=new wd;this.eventHandlerTouchStart=function(t){xx(t.touches,e),i.send2(e,t),r.copy(e)},this.eventHandlerTouchEnd=function(t){xx(t.touches,e),n.send2(e,t)},this.eventHandlerTouchMove=function(t){t.preventDefault(),xx(t.touches,e);const i=new wd;i.subVectors(e,r),s.send3(e,t,i),r.copy(e)};const a=new l;this.eventHandlerGlobalTouchEnd=t=>{xx(t.touches,e),a.send2(e,t)},this.eventHandlerGlobalMouseUp=t=>{this.readPointerPositionFromEvent(e,t),a.send2(e,t)},this.eventHandlerWheel=t=>{t.preventDefault();const i=f(t.deltaX),n=f(t.deltaY),s=f(t.deltaZ),r=new S(i,n,s);this.readPointerPositionFromEvent(e,t),this.on.wheel.send3(r,e,t)},this.on={down:new l,up:new l,move:new l,tap:new l,drag:new l,dragStart:new l,dragEnd:new l,wheel:new l,pinch:new l,pinchStart:new l,pinchEnd:new l},function(t,e,i,n,s){const r=new wd;function a(e,n){t.remove(a),i.remove(o),s.send2(e,n)}function o(e,s){r.distanceTo(e)>n&&(i.remove(o),t.remove(a))}e.add((function(e){t.addOne(a),i.add(o),r.copy(e)}))}(this.on.up,this.on.down,this.on.move,10,this.on.tap),function(t,e,i,n,s,r){const a=new wd;function o(e){t.remove(o),i.remove(h)}function l(e){t.remove(l),i.remove(u),s.send1(e)}function h(e,s){i.remove(h),i.add(u),t.remove(o),t.add(l),c.copy(a),n.send2(a,s),u(e,s)}const c=new wd;function u(t,e){r.send4(t,a,c,e),c.copy(t)}e.add((function(e){a.copy(e),t.add(o),i.add(h)}))}(a,this.on.down,this.on.move,this.on.dragStart,this.on.dragEnd,this.on.drag),function({touchStart:t,touchEnd:e,touchMove:i,pinch:n,pinchStart:s,pinchEnd:r,device:a}){const o=new wd,l=new wd,h=new wd,c=new wd;let u=!1,d=0;function p(t,e){xx(t,o);const i=t.length;e.set(0,0);for(let n=0;n<i;n++){const i=t.item(n);a.readPointerPositionFromEvent(l,i),l.sub(o),l.abs(),e.add(l)}return e.multiplyScalar(1/i)}function f(t,e){p(e.touches,c),n.send2(c,h)}e.add((function(t,e){vx(e.changedTouches,(function(t){d--,d<2&&u&&(u=!1,i.remove(f),r.send0())}))})),t.add((function(t,e){vx(e.changedTouches,(function(t){!function(t,e){d++,d>1&&!u&&function(t){u=!0,p(t.touches,h),i.add(f),s.send1(h)}(e)}(0,e)}))}))}({touchStart:i,touchEnd:n,touchMove:s,pinch:this.on.pinch,pinchStart:this.on.pinchStart,pinchEnd:this.on.pinchEnd})}wx.prototype.getTargetElement=function(){return this.__target},wx.prototype.setTargetElement=function(t){if(this.__target===t)return;let e=this.isRunning;e&&this.stop(),this.__target=t,e&&this.start()},wx.prototype.readPointerPositionFromEvent=function(t,e){!function(t,e,i=e.target){let n=e.clientX,s=e.clientY;if("function"==typeof i.getBoundingClientRect){const t=i.getBoundingClientRect();s-=t.top,n-=t.left}t.set(n,s)}(t,e,this.domElement)},wx.prototype.start=function(){if(this.isRunning)return;this.isRunning=!0;const t=this.domElement;t.addEventListener(ux,this.eventHandlerMouseMove),t.addEventListener(cx,this.eventHandlerMouseUp),t.addEventListener(hx,this.eventHandlerMouseDown),t.addEventListener(mx,this.eventHandlerTouchStart),t.addEventListener(_x,this.eventHandlerTouchEnd),t.addEventListener(gx,this.eventHandlerTouchMove),window.addEventListener(cx,this.eventHandlerGlobalMouseUp),window.addEventListener(_x,this.eventHandlerGlobalTouchEnd),t.addEventListener(fx,this.eventHandlerWheel,{passive:!1}),t.addEventListener("contextmenu",yx)},wx.prototype.stop=function(){if(!this.isRunning)return;this.isRunning=!1;const t=this.domElement;t.removeEventListener(ux,this.eventHandlerMouseMove),t.removeEventListener(cx,this.eventHandlerMouseUp),t.removeEventListener(hx,this.eventHandlerMouseDown),t.removeEventListener(mx,this.eventHandlerTouchStart),t.removeEventListener(_x,this.eventHandlerTouchEnd),t.removeEventListener(gx,this.eventHandlerTouchMove),window.removeEventListener(cx,this.eventHandlerGlobalMouseUp),window.removeEventListener(_x,this.eventHandlerGlobalTouchEnd),t.removeEventListener(fx,this.eventHandlerWheel),t.removeEventListener("contextmenu",yx)};const bx="keyup",Sx="keydown";class Mx{down=new l;up=new l;is_down=!1}function Tx(t,e){return null!=e&&"object"==typeof e&&t instanceof e}class Cx{constructor(t){var e;Tx(e=t,HTMLInputElement)||Tx(e,HTMLSelectElement)||Tx(e,HTMLTextAreaElement)||Tx(e,HTMLAnchorElement)||Tx(e,HTMLButtonElement)||Tx(e,HTMLAreaElement)||t.getAttribute("tabindex"),this.domElement=t,this.on={down:new l,up:new l};const i=this.keys={},n=[];for(let t in Sy)n[Sy[t]]=t,i[t]=new Mx;this.__handlerKeyDown=t=>{this.on.down.send1(t);const e=t.keyCode,s=n[e];if(void 0!==s){const e=i[s];e.is_down=!0,e.down.send1(t)}},this.__handlerKeyUp=t=>{this.on.up.send1(t);const e=t.keyCode,s=n[e];if(void 0!==s){const e=i[s];e.is_down=!1,e.up.send1(t)}}}start(){this.domElement.addEventListener(Sx,this.__handlerKeyDown),this.domElement.addEventListener(bx,this.__handlerKeyUp)}stop(){this.domElement.removeEventListener(Sx,this.__handlerKeyDown),this.domElement.removeEventListener(bx,this.__handlerKeyUp)}}const Ax={CRITICAL:0,HIGH:1,NORMAL:2,OPTIONAL:3};class Ex{constructor(){this.uri=null,this.type=null,this.level=Ax.OPTIONAL,this.priotity=0}fromJSON({uri:t,type:e,level:i=Ax.OPTIONAL,priority:n=0}){this.uri=t,this.type=e,this.level=i,this.priotity=n}static fromJSON(t){const e=new Ex;return e.fromJSON(t),e}}const zx=function(){this.totalAssetCount=0;const t=this.assets=[];for(let e in Ax)Ax.hasOwnProperty(e)&&(t[Ax[e]]=[]);this.on={added:new l,progress:new l,levelFinished:new l,error:new l,loadStart:new l,completed:new l}};function Ix(t,e,i,n){const s=e*i;for(let e=n.nextSetBit(0);-1!==e;e=n.nextSetBit(e+1))if(!t.get(e+s))return!1;return!0}function Nx(t,e,i,n,s){for(let r=e.nextSetBit(0);-1!==r;r=e.nextSetBit(r+1)){const e=n[r][t];s[i[r]]=e}}zx.prototype.add=function(t,e,i,n){void 0===i&&(i=Ax.OPTIONAL);const s=this.assets,r=Ex.fromJSON({uri:t,type:e,priority:n});return s.hasOwnProperty(i)||(i=Ax.OPTIONAL),s[i].push(r),this.totalAssetCount++,this.on.added.dispatch(r,i),this},zx.prototype.addAll=function(t){const e=this;t.forEach((function(t){e.add(t.uri,t.type,t.level)}))},zx.prototype.load=function(t){const e=this.on,i=this.assets,n=i.map((function(t,e){return{level:e,count:t.length}}));e.loadStart.dispatch(n);const s=this.totalAssetCount;let r=0;const a=[];for(let t in i)i.hasOwnProperty(t)&&a.push(t);let o=0;return function n(){if(o<a.length){const a=o;o++,e.levelFinished.addOne(n),function(n){const a=i[n],o=a.length;if(0===o)return void e.levelFinished.dispatch(n);let l=0;function h(t){l++,r++,e.progress.dispatch({level:{id:n,value:l,max:o},global:{value:r,max:s}}),l>=o&&e.levelFinished.dispatch(n)}function c(t){e.error.dispatch(t)}a.sort(((t,e)=>e.priotity-t.priority)),a.forEach((function(e){t.get(e.uri,e.type,h,c)}))}(a)}else e.completed.dispatch()}(),this};const Lx=[],Px=[];class Fx{constructor(){this.entityOccupancy=new g_,this.componentOccupancy=new g_,this.componentTypeMap=[],this.__type_to_index_map=new Map,this.componentTypeCount=0,this.components=[],this.entityCount=0,this.generation=0,this.onEntityCreated=new l,this.onEntityRemoved=new l,this.__entityEventListeners=[],this.__entityAnyEventListeners=[],this.observers=[]}promiseComponent(t,e){const i=this;return new Promise((function(n,s){const r=i.getComponent(t,e);void 0===r?(i.addEntityEventListener(t,x_,(function t(s,r){if(s.klass===e){const e=s.instance;i.removeEntityEventListener(r,x_,t),n(e)}})),i.addEntityEventListener(t,v_,(function(){s(`Entity ${t} has been removed`)}))):n(r)}))}addObserver(t,e){if(t.dataset===this)return!1;let i;t.dataset=this,t.build(this.componentTypeMap);const n=t.componentMask;for(i=n.nextSetBit(0);-1!==i;i=n.nextSetBit(i+1))this.observers[i].push(t);if(!0===e){const e=this.componentTypeCount,s=this.componentOccupancy,r=this.entityOccupancy,a=this.components,o=t.componentIndexMapping,l=[];for(i=r.nextSetBit(0);-1!==i;i=r.nextSetBit(i+1))Ix(s,i,e,n)&&(Nx(i,n,o,a,l),l[t.componentTypeCount]=i,t.callbackComplete.apply(t.thisArg,l))}return!0}removeObserver(t,e){let i,n=!1;const s=t.componentMask;for(i=s.nextSetBit(0);-1!==i;i=s.nextSetBit(i+1)){const e=this.observers[i],s=e.indexOf(t);-1!==s&&(n=!0,e.splice(s,1))}if(n&&!0===e){const e=this.componentTypeCount,n=this.componentOccupancy,r=this.entityOccupancy,a=this.components,o=t.componentIndexMapping,l=[];for(i=r.nextSetBit(0);-1!==i;i=r.nextSetBit(i+1))Ix(n,i,e,s)&&(Nx(i,s,o,a,l),l[t.componentTypeCount]=i,t.callbackBroken.apply(t.thisArg,l))}return t.dataset=null,n}getEntityCount(){return this.entityCount}getComponentTypeCount(){return this.componentTypeCount}getComponents(t,e){const i=e.length,n=new Array(i),s=this.componentTypeCount,r=s*t,a=r+s;for(let i=this.componentOccupancy.nextSetBit(r);i<a&&-1!==i;i=this.componentOccupancy.nextSetBit(i+1)){const r=i%s,a=this.componentTypeMap[r],o=e.indexOf(a);-1!==o&&(n[o]=this.components[r][t])}return n}getAllComponents(t){const e=[],i=this.componentTypeCount,n=i*t,s=n+i;for(let r=this.componentOccupancy.nextSetBit(n);r<s&&-1!==r;r=this.componentOccupancy.nextSetBit(r+1)){const n=r%i;e[n]=this.components[n][t]}return e}setComponentTypeMap(t){const e=t.length,i=af(t,this.componentTypeMap),n=i.uniqueA,s=i.uniqueB,r=i.common,a=this;!function(){const t=[];for(let e=0;e<s.length;e++){const i=s[e];a.traverseComponents(i,(function(){return t.push(i),!1}))}if(t.length>0){const e=t.map((t=>t.typeName)).join(", ");throw new Error(`Component types can not be unmapped due to presence of live components: ${e}`)}}();const o=function(){const e=[];let i,n;for(i=0,n=r.length;i<n;i++){const n=r[i],s=a.componentTypeMap.indexOf(n),o=t.indexOf(n);e[s]=o}return e}();!function(t){const i=new g_;let n;const s=a.componentTypeCount;for(n=a.componentOccupancy.nextSetBit(0);-1!==n;n=a.componentOccupancy.nextSetBit(n+1)){const r=t[n%s];if(void 0!==r){const t=Math.floor(n/s);i.set(t*e+r,!0)}}a.componentOccupancy=i}(o),function(e){let i,s;const r=[];for(i=0,s=n.length;i<s;i++){const e=n[i];r[t.indexOf(e)]=[]}for(i=0,s=e.length;i<s;i++){const t=e[i];void 0!==t&&(r[t]=a.components[i])}a.components=r}(o),function(e){let i,s;const r=[];for(i=0,s=n.length;i<s;i++){const e=n[i];r[t.indexOf(e)]=[]}for(i=0,s=e.length;i<s;i++){const n=e[i];if(void 0===n)continue;const s=a.observers[i];s.forEach((function(e){e.build(t)})),r[n]=s}a.observers=r}(o),this.componentTypeMap=t,this.__type_to_index_map.clear();for(let i=0;i<e;i++)this.__type_to_index_map.set(t[i],i);this.componentTypeCount=e}areComponentTypesRegistered(t){for(let e=0;e<t.length;e++){const i=t[e];if(!this.isComponentTypeRegistered(i))return!1}return!0}isComponentTypeRegistered(t){return-1!==this.getComponentTypeMap().indexOf(t)}getComponentTypeMap(){return this.componentTypeMap}registerManyComponentTypes(t){const e=af(t,this.componentTypeMap);if(0===e.uniqueA.length)return!1;const i=this.componentTypeMap.concat(e.uniqueA);return this.setComponentTypeMap(i),!0}registerComponentType(t){if(this.isComponentTypeRegistered(t))return!1;const e=this.componentTypeMap.concat([t]);return this.setComponentTypeMap(e),!0}unregisterComponentType(t){if(this.isComponentTypeRegistered(t))return!1;const e=this.componentTypeMap.slice(),i=e.indexOf(t);return e.splice(i,1),this.setComponentTypeMap(e),!0}createEntity(){const t=this.entityOccupancy.nextClearBit(0);return this.entityOccupancy.set(t,!0),this.entityCount++,this.onEntityCreated.send1(t),this.generation++,t}createEntitySpecific(t){if(this.entityExists(t))throw new Error(`EntityId ${t} is already in use`);this.entityOccupancy.set(t,!0),this.entityCount++,this.onEntityCreated.send1(t),this.generation++}entityExists(t){return this.entityOccupancy.get(t)}componentIndexExists(t){return t>=0&&t<this.componentTypeCount}removeEntity(t){if(!this.entityExists(t))return;const e=this.componentOccupancy,i=this.componentTypeCount,n=t*i,s=n+i;for(let r=e.nextSetBit(n);r<s&&-1!==r;r=e.nextSetBit(r+1)){const e=r%i;this.removeComponentFromEntityByIndex_Unchecked(t,e,r)}this.sendEvent(t,v_,t),delete this.__entityEventListeners[t],delete this.__entityAnyEventListeners[t],this.entityOccupancy.set(t,!1),this.entityCount--,this.onEntityRemoved.send1(t)}removeEntities(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.removeEntity(e)}}removeComponentFromEntity(t,e){const i=this.componentTypeMap.indexOf(e);if(-1===i)throw new Error("Component class not found in this dataset");this.removeComponentFromEntityByIndex(t,i)}removeComponentFromEntityByIndex(t,e){const i=t*this.componentTypeCount+e;this.componentOccupancy.get(i)&&this.removeComponentFromEntityByIndex_Unchecked(t,e,i)}removeComponentFromEntityByIndex_Unchecked(t,e,i){this.processObservers_ComponentRemoved(t,e);const n=this.components[e][t];delete this.components[e][t],this.componentOccupancy.clear(i);const s=this.componentTypeMap[e];this.sendEvent(t,"componentRemoved",{klass:s,instance:n})}computeComponentTypeIndex(t){const e=this.__type_to_index_map.get(t);return void 0===e?-1:e}computeComponentCount(t){let e=0;return this.traverseComponents(t,(function(){e++})),e}getAnyComponent(t){let e=-1,i=null;return this.traverseComponents(t,((t,n)=>(e=n,i=t,!1))),{entity:e,component:i}}addComponentToEntity(t,e){const i=e.constructor,n=this.__type_to_index_map.get(i);if("number"!=typeof n)throw new Error(`Component class not found in this dataset for componentInstance ${s=e,"object"==typeof s?s.constructor.toString():s}`);var s;this.addComponentToEntityByIndex(t,n,e)}addComponentToEntityByIndex(t,e,i){const n=t*this.componentTypeCount+e;this.componentOccupancy.set(n,!0),this.components[e][t]=i,this.processObservers_ComponentAdded(t,e);const s=this.componentTypeMap[e];this.sendEvent(t,x_,{klass:s,instance:i})}getComponentByIndex(t,e){return this.components[e][t]}hasComponent(t,e){return void 0!==this.getComponent(t,e)}getComponent(t,e){const i=this.computeComponentTypeIndex(e);if(-1!==i)return this.getComponentByIndex(t,i)}getComponentSafe(t,e){const i=this.getComponent(t,e);if(void 0===i)throw new Error("Component not found");return i}traverseEntities(t,e,i){let n,s;const r=Lx,a=t.length;for(s=0;s<a;s++){const e=t[s],i=this.computeComponentTypeIndex(e);if(-1===i)return;r[s]=i}const o=Px;Iy(Px,a+1);const l=this.entityOccupancy,h=this.componentTypeCount,c=this.componentOccupancy,u=this.components;t:for(n=l.nextSetBit(0);-1!==n;n=l.nextSetBit(n+1)){const t=n*h;for(s=0;s<a;s++){const e=r[s];if(!c.get(t+e))continue t;o[s]=u[e][n]}if(o[a]=n,!1===e.apply(i,o))return}}traverseEntitiesExact(t,e,i){let n,s;const r=[],a=t.length;for(s=0;s<a;s++){const e=t[s],i=this.computeComponentTypeIndex(e);r[s]=i}const o=[];t:for(n=this.entityOccupancy.nextSetBit(0);-1!==n;n=this.entityOccupancy.nextSetBit(n+1)){const t=n*this.componentTypeCount,l=t+this.componentTypeCount;let h=0;for(s=this.componentOccupancy.nextSetBit(t);s<l&&-1!==s;s=this.componentOccupancy.nextSetBit(s+1)){const e=s-t,i=r.indexOf(e);if(-1===i)continue t;h++,o[i]=this.components[e][n]}if(h===a&&(o[a]=n,!1===e.apply(i,o)))return}}*createEntityIterator(){const t=this.entityOccupancy;for(let e=t.nextSetBit(0);-1!==e;e=t.nextSetBit(e+1))yield e}traverseComponents(t,e,i){const n=this.computeComponentTypeIndex(t);-1!==n&&this.traverseComponentsByIndex(n,e,i)}traverseComponentsByIndex(t,e,i){ENV_PRODUCTION,this.__traverseComponentsByIndex_via_property(t,e,i)}__traverseComponentsByIndex_via_bitset(t,e,i){const n=this.components[t],s=this.componentTypeCount,r=this.entityOccupancy,a=this.componentOccupancy;for(let o=r.nextSetBit(0);-1!==o;o=r.nextSetBit(o+1)){const r=o*s+t;if(a.get(r)){const t=n[o];if(!1===e.call(i,t,o))break}}}__traverseComponentsByIndex_via_property(t,e,i){const n=this.components[t];for(const t in n){const s=Number.parseInt(t),r=n[s];if(void 0!==r&&!1===e.call(i,r,s))break}}processObservers_ComponentAdded(t,e){const i=this.observers[e],n=i.length;if(0===n)return;let s=0;const r=[];for(;s<n;s++){const e=i[s];Ix(this.componentOccupancy,t,this.componentTypeCount,e.componentMask)&&(Nx(t,e.componentMask,e.componentIndexMapping,this.components,r),r[e.componentTypeCount]=t,e.callbackComplete.apply(e.thisArg,r))}}processObservers_ComponentRemoved(t,e){const i=this.observers[e],n=i.length;let s;const r=[];for(s=0;s<n;s++){const e=i[s];Ix(this.componentOccupancy,t,this.componentTypeCount,e.componentMask)&&(Nx(t,e.componentMask,e.componentIndexMapping,this.components,r),r[e.componentTypeCount]=t,e.callbackBroken.apply(e.thisArg,r))}}addEntityAnyEventListener(t,e,i){if(!this.entityExists(t))throw new Error(`Entity '${t}' does not exist`);const n=this.__entityAnyEventListeners;let s=n[t];void 0===s&&(s=[],n[t]=s);const a=new r(e,i);s.push(a)}removeAnyEventListener(t,e,i){let n,s=this.__entityAnyEventListeners[t];return void 0!==s&&(n=void 0===i?h(s,e):c(s,e,i),!(n<0||(s.splice(n,1),0)))}addEntityEventListener(t,e,i,n){if(!this.entityExists(t))throw new Error(`Entity '${t}' does not exist`);const s=this.__entityEventListeners;let a=s[t];void 0===a&&(a={},s[t]=a);let o=a[e];void 0===o&&(o=[],a[e]=o);const l=new r(i,n);o.push(l)}removeEntityEventListener(t,e,i,n){const s=this.__entityEventListeners[t];if(void 0===s)return!1;const r=s[e];if(void 0===r)return!1;let a;return a=void 0===n?h(r,i):c(r,i,n),!(a<0||(r.splice(a,1),0))}sendEvent(t,e,i){!function(t,e,i,n){const s=t[e];void 0!==s&&function(t,e,i,n){const s=t[i];if(void 0===s)return;const r=s.length;if(0===r)return;const a=Ox;let o;for(Ox+=r,o=0;o<r;o++){const t=s[o];Dx[o+a]=t}for(let t=0;t<r;t++){const i=Dx[t+a];i.handle.call(i.context,n,e)}Ox=a}(s,e,i,n)}(this.__entityEventListeners,t,e,i);const n=this.__entityAnyEventListeners[t];void 0!==n&&function(t,e,i,n){const s=t.length;if(0===s)return;const r=Ox;let a;for(Ox+=s,a=0;a<s;a++){const e=t[a];Dx[a+r]=e}for(let t=0;t<s;t++){const s=Dx[t+r];s.handle.call(s.context,i,n,e)}Ox=r}(n,t,e,i)}entityHasComponents(t){const e=this.getAllComponents(t),i=e.length;for(let t=0;t<i;t++)if(void 0!==e[t])return!0;return!1}clear(){const t=this.entityOccupancy;for(let e=t.nextSetBit(0);-1!==e;e=t.nextSetBit(e+1))this.removeEntity(e)}dropData(){for(let t=0;t<this.componentTypeCount;t++)this.components[t]=[];this.componentOccupancy.reset(),this.entityOccupancy.reset(),this.entityCount=0,this.__entityEventListeners=[]}getComponentClassByName(t){let e=0;for(;e<this.componentTypeCount;e++){const i=this.componentTypeMap[e];if(i.typeName===t)return i}return null}maskedCopy(t,e){let i;const n=e.length,s=[],r=[];for(i=0;i<n;i++){const n=e[i],a=t.computeComponentTypeIndex(n);if(-1===a)continue;const o=this.computeComponentTypeIndex(n);if(-1===o)throw new Error("This dataset does not have component class registered");s.push(a),r.push(o)}const a=s.length,o=t.entityOccupancy,l=t.componentOccupancy,h=t.componentTypeCount;let c;for(c=o.nextSetBit(0);-1!==c;c=o.nextSetBit(c+1))for(this.createEntitySpecific(c),i=0;i<a;i++){const e=s[i];if(l.get(h*c+e)){const n=r[i],s=t.getComponentByIndex(c,e);this.addComponentToEntityByIndex(c,n,s)}}}traverseEntitiesCompactedFiltered(t,e){const i=t.length,n=new Array(i);let s,r;for(s=0;s<i;s++){const e=t[s],i=this.computeComponentTypeIndex(e);n[s]=i}n.sort();const a=this.entityOccupancy,o=this.componentOccupancy,l=this.componentTypeCount,h=[];let c;for(s=a.nextSetBit(0);-1!==s;s=a.nextSetBit(s+1)){const t=s*l;for(c=0,r=0;r<i;r++){const e=n[r];if(o.get(t+e)){const t=this.components[e][s];h[c]=t,c++}}e(s,h,c)}}isEmpty(){return 0===this.entityCount}traverseEntityIndices(t){let e;const i=this.entityOccupancy;for(e=i.nextSetBit(0);-1!==e;e=i.nextSetBit(e+1))t(e)}}Fx.prototype.isEntityComponentDataset=!0;const Dx=[];let Ox=0;class Rx{constructor(t){this.name=t,this.dataset=new Fx,this.active=new Mm(!1),this.destroyed=!1,this.speedModifiers=new of}handlePreActivation(){}handlePostActivation(){}handlePreDeactivation(){}handlePostDeactivation(){}setup(t,e,i,n){return function(t,e){let i=!1,n=!1,s=null;return t.then((function(){i=!0}),(function(t){n=!0,s=t})),new Mf({name:e,cycleFunction:function(){if(i)return bf.EndSuccess;if(n)throw s;return bf.Yield},computeProgress:function(){return i?1:0}})}(new Promise((function(t,e){i(),t()})),`${name} scene setup`)}teardown(t,e,i){}clear(){this.dataset.clear()}}class kx{constructor(t,e){this.currentScene=null,this.scenes=new of,this.entityManager=t,this.clock=e,this.stack=[]}create(t){const e=new Rx(t);return this.add(e),e}add(t){if(this.exists(t.name))throw new Error(`Scene named '${t.name}' already exists`);this.scenes.add(t)}indexByName(t){const e=this.scenes.length;for(let i=0;i<e;i++)if(this.scenes.get(i).name===t)return i;return-1}getByName(t){return this.scenes.find((function(e){return e.name===t}))}remove(t){const e=this.indexByName(t);if(-1===e)return!1;const i=this.scenes.get(e);return this.currentScene===i&&(this.deactivateCurrentScene(),this.currentScene=null),this.scenes.remove(e),!0}clear(){return null!==this.currentScene&&(this.currentScene.active.set(!1),this.entityManager.detachDataSet(),this.currentScene=null),this}exists(t){return this.scenes.some((function(e){return e.name===t}))}deactivateScene(t){if(t.active.getValue()){try{t.handlePreDeactivation()}catch(t){}t.active.set(!1),this.entityManager.dataset===t.dataset&&this.entityManager.detachDataSet(),t.speedModifiers.forEach((t=>this.clock.speed.removeModifier(t))),t.speedModifiers.on.added.remove(this.__handleSpeedModifierAdded,this),t.speedModifiers.on.removed.remove(this.__handleSpeedModifierRemoved,this);try{t.handlePostDeactivation()}catch(t){}}}activateScene(t){try{t.handlePreActivation()}catch(t){}this.entityManager.attachDataSet(t.dataset),t.active.set(!0),t.speedModifiers.forEach((t=>this.clock.speed.addModifier(t))),t.speedModifiers.on.added.add(this.__handleSpeedModifierAdded,this),t.speedModifiers.on.removed.add(this.__handleSpeedModifierRemoved,this);try{t.handlePostActivation()}catch(t){}this.currentScene=t}deactivateCurrentScene(){const t=this.currentScene;null!==t&&this.deactivateScene(t)}__handleSpeedModifierAdded(t){this.clock.speed.addModifier(t)}__handleSpeedModifierRemoved(t){this.clock.speed.removeModifier(t)}set(t){const e=this.getByName(t);if(void 0===e)throw new Error(`Scene named '${t}' doesn't exist, valid options are: [${this.scenes.map((t=>t.name)).join(", ")}]`);if(this.currentScene===e)return;const i=this.entityManager;e.dataset.registerManyComponentTypes(i.getComponentTypeMap()),this.deactivateCurrentScene(),this.activateScene(e)}stackPush(t){this.stack.push(this.currentScene.name),this.set(t)}stackPop(){const t=this.stack.pop();return this.set(t),t}stackDrop(){this.stack.splice(0,this.stack.length)}update(t){}}class Ux{constructor(){this.flags=0}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}toJSON(){return{flags:this.flags}}fromJSON({flags:t=0}){this.flags=t}}const Bx=new Ux;Bx.setFlag(1),Ux.Transient=Object.freeze(Bx),Ux.typeName="SerializationMetadata";const Vx={Initial:0,Running:1,Succeeded:2,Failed:3,Suspended:4,Invalid:5};class Gx{constructor(){this.context=null}tick(t){throw new Error("Abstract method, needs to be overridden")}initialize(t){this.context=t}finalize(){}}Gx.prototype.isBehavior=!0;class Wx extends Gx{constructor(){super(),this.__source=null}getSource(){return this.__source}setSource(t){this.__source=t}initialize(t){super.initialize(t),this.__source.initialize(t)}finalize(){super.finalize(),this.__source.finalize()}}class Hx extends Wx{constructor(t,e=Infinity){super(),this.__limit=e,this.__iterator=0,this.setSource(t)}setCount(t){this.__limit=t}getCount(){return this.__limit}static from(t,e=Infinity){return new Hx(t,e)}tick(t){const e=this.__source.tick(t);return e!==Vx.Succeeded&&e!==Vx.Failed?e:(this.__iterator++,this.__iterator>=this.__limit?Vx.Succeeded:(this.__source.initialize(this.context),Vx.Running))}}Hx.typeName="RepeatBehavior";class jx extends Gx{constructor(t,e){super(),this.__action=t,this.__context=e}tick(t){try{return this.__action.call(this.__context,t),Vx.Succeeded}catch(t){return Vx.Failed}}}class qx extends Gx{constructor(){super(),this.__children=[]}addChild(t){this.__children.push(t)}getChildren(){return this.__children}removeChild(t){const e=this.__children.indexOf(t);return-1!==e&&(this.__children.splice(e,1),!0)}clearChildren(){this.__children=[]}}qx.prototype.isCompositeBehavior=!0;class Jx extends qx{constructor(){super(),this.__currentBehaviourIndex=-1,this.__currentBehaviourState=Vx.Initial,this.__currentBehaviour=void 0}initialize(t){super.initialize(t),this.__currentBehaviourIndex=0,this.__currentBehaviour=this.__children[0],this.__currentBehaviour.initialize(t),this.__currentBehaviourState=Vx.Running}tick(t){const e=this.__currentBehaviour,i=e.tick(t);return this.__currentBehaviourState=i,i!==Vx.Succeeded?i:(e.finalize(),this.__currentBehaviourState=Vx.Initial,this.__currentBehaviourIndex++,this.__currentBehaviourIndex<this.__children.length?(this.__currentBehaviour=this.__children[this.__currentBehaviourIndex],this.__currentBehaviour.initialize(this.context),this.__currentBehaviourState=Vx.Running,Vx.Running):Vx.Succeeded)}finalize(){const t=this.__children.length;this.__currentBehaviourIndex!==t&&void 0!==this.__currentBehaviour&&this.__currentBehaviourState!==Vx.Initial&&this.__currentBehaviour.finalize(),this.__currentBehaviour=void 0,this.__currentBehaviourIndex=t}static from(t){const e=new Jx;return t.forEach((t=>e.addChild(t))),e}}Jx.prototype.isSequenceBehavior=!0,Jx.typeName="SequenceBehavior";class Yx{constructor(){this.clock=0,this.flags=0,this.__behavior=null}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}get behavior(){return this.__behavior}set behavior(t){this.__behavior=t}get list(){return null!==this.__behavior?[this.__behavior]:[]}set list(t){t.length>1?this.__behavior=Jx.from(t):1===t.length?this.__behavior=t[0]:this.__behavior=null}static looping_function(t,e){return Yx.fromOne(Hx.from(new jx(t,e)))}static fromOne(t){const e=new Yx;return e.__behavior=t,e}}Yx.serializable=!0,Yx.typeName="BehaviorComponent";class Xx extends Gx{constructor(t){super(),this.animation=t}tick(t){return this.animation.advance(t),this.animation.position>=this.animation.track.timeEnd&&!this.animation.loop?Vx.Succeeded:Vx.Running}initialize(){this.animation.setPosition(this.animation.track.timeStart)}}function Zx(t,e){const i=typeof t;if(i!==typeof e)return!1;if("object"===i){for(let i in t)if(!Zx(t[i],e[i]))return!1;for(let i in e)if(!Zx(t[i],e[i]))return!1;return!0}return t===e}class $x{constructor(t){this.view=null,this.klass=null,this.parameters={},this.anchor=new wd(0,0),this.group=null,this.flags=1,this.visible=new Mm(!0),void 0!==t&&(this.view=t,this["@serialization_transient"]=!0)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}equals(t){return!(this.flags!==t.flags||this.klass!==t.klass||!this.getFlag(1)&&this.view!==t.view||!this.anchor.equals(t.anchor)||this.group!==t.group||!this.visible.equals(t.visible)||!Zx(this.parameters,t.parameters))}hash(){return Cd(this.flags,Nd(this.klass),this.anchor.hashCode(),Nd(this.group),this.visible.hashCode())}static fromView(t){const e=new $x;return e.clearFlag(1),e.view=t,e}static fromJSON(t){const e=new $x;return e.fromJSON(t),e}fromJSON({klass:t,parameters:e={},anchor:i=wd.zero,group:n=null,visible:s=!0}){if(null!==n&&"string"!=typeof n)throw new Error(`Expected group to be null or string, instead was '${typeof n}'`);this.klass=t,this.parameters=e,this.anchor.fromJSON(i),this.group=n,this.visible.set(s)}toJSON(){return{klass:this.klass,parameters:this.parameters,anchor:this.anchor.toJSON(),group:this.group,visible:this.visible.toJSON()}}}$x.typeName="GUIElement",$x.serializable=!0;class Kx{constructor({position:t,offset:e}={}){this.position=new wd,this.offset=new wd,this.anchor=new wd(0,0),this.resolveGuiCollisions=!1,this.screenEdgeWidth=10,this.stickToScreenEdge=!1,this.enabled=new Mm(!0),void 0!==t&&this.position.copy(t),void 0!==e&&this.offset.copy(e)}equals(t){return this.position.equals(t.position)&&this.offset.equals(t.offset)&&this.anchor.equals(t.anchor)&&this.resolveGuiCollisions===t.resolveGuiCollisions&&this.screenEdgeWidth===t.screenEdgeWidth&&this.stickToScreenEdge===t.stickToScreenEdge&&this.enabled.equals(t.enabled)}hash(){return Cd(this.position.hashCode(),this.offset.hashCode(),this.anchor.hashCode(),this.resolveGuiCollisions?1:0,x(this.screenEdgeWidth),this.stickToScreenEdge?1:0,this.enabled.hashCode())}fromJSON({position:t=wd.zero,offset:e=wd.zero,anchor:i=wd.zero,screenEdgeWidth:n=0,stickToScreenEdge:s=!1,enabled:r=!0}){this.position.fromJSON(t),this.offset.fromJSON(e),this.anchor.fromJSON(i),this.screenEdgeWidth=n,this.stickToScreenEdge=s,this.enabled.fromJSON(r)}toJSON(){return{position:this.position.toJSON(),offset:this.offset.toJSON(),anchor:this.anchor.toJSON(),screenEdgeWidth:this.screenEdgeWidth,stickToScreenEdge:this.stickToScreenEdge,enabled:this.enabled.toJSON()}}static fromJSON(t){const e=new Kx;return e.fromJSON(t),e}}Kx.typeName="ViewportPosition",Kx.serializable=!0;const Qx=function(t,e){let i;return i="string"==typeof t?void 0===e?document.createElement(t):document.createElementNS(e,t):"object"==typeof t?t:document.createElement("div"),this.el=i,this};function tw(t){let e;return e=t instanceof Qx?t.el:t,e}function ew(t,e){return new Qx(t,e)}function iw(t){const e=t%1;if(0!==e&&Math.abs(t)<100){const e=function(t){if(t%1==0)return 0;const e=t.toString(),i=e.indexOf(".");if(-1===i)return 0;let n=e.length-1;for(;n>i&&"0"===e.charAt(n);n--);return n-i}(t.toFixed(2)),i=Math.min(e,2);return t.toFixed(i)}return function(t,e){return void 0===e&&(e=","),t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,e)}(t-e,",")}Qx.prototype.createChild=function(t){const e=new Qx(t);return this.append(e),e},Qx.prototype.append=function(t){const e=tw(t);return this.el.appendChild(e),this},Qx.prototype.remove=function(t){const e=tw(t);return this.el.removeChild(e),this},Qx.prototype.text=function(t){return this.el.innerText=t,this},Qx.prototype.select=function(t){const e=this.el.querySelector(t);return null===e?null:ew(e)},Qx.prototype.addClass=function(t){return this.el.classList.add(t),this},Qx.prototype.removeClass=function(t){return this.el.classList.remove(t),this},Qx.prototype.setClass=function(t,e){return this.el.classList.toggle(t,e),this},Qx.prototype.css=function(t){for(let e in t)t.hasOwnProperty(e)&&(this.el.style[e]=t[e]);return this},Qx.prototype.attr=function(t){const e=this.el;for(let i in t)t.hasOwnProperty(i)&&e.setAttribute(i,t[i]);return this},Qx.prototype.clone=function(){return new Qx(this.el.cloneNode(!0))},Qx.prototype.clear=function(){const t=this.el;for(;t.children.length>0;)t.removeChild(t.children[0]);return this},Qx.prototype.on=function(t,e){return this.el.addEventListener(t,e),this},Qx.prototype.off=function(t,e){return this.el.removeEventListener(t,e),this};const nw=function(t,e,i){this.x=void 0!==t?t:0,this.a=void 0!==e?e:0,this.b=void 0!==i?i:1,this.onChanged=new l};nw.prototype.copy=function(t){return this.set(t.x,t.a,t.b)},nw.prototype.set=function(t,e,i){return this.x=t,this.a=e,this.b=i,this.onChanged.dispatch(t,e,i),this},nw.prototype.addMultiplier=function(t){return this.b+=t,this.onChanged.dispatch(this.x,this.a,this.b),this},nw.prototype.subMultiplier=function(t){return this.addMultiplier(-t)},nw.prototype.addConstant=function(t){return this.a+=t,this.onChanged.dispatch(this.x,this.a,this.b),this},nw.prototype.subConstant=function(t){return this.addConstant(-t)},nw.prototype.getValue=function(){return this.x*this.b+this.a},nw.prototype.equals=function(t){return this.x===t.x&&this.a===t.a&&this.b===t.b},nw.prototype.toJSON=function(){return{x:this.x,a:this.a,b:this.b}},nw.prototype.fromJSON=function(t){this.set(t.x,t.a,t.b)};class sw{constructor(t=1,e=0){this.a=t,this.b=e,this.source=0,this.transient=!1}copy(t){this.a=t.a,this.b=t.b,this.source=t.source,this.transient=t.transient}clone(){const t=new sw;return t.copy(this),t}add(t){this.a+=t.a-1,this.b+=t.b}equals(t){return this.a===t.a&&this.b===t.b&&this.source===t.source&&this.transient===t.transient}hash(){return x(this.a)^x(this.b)^this.source^(this.transient?0:1)}toString(){return`LinearModifier{ a:${this.a}, b:${this.b} }`}toJSON(){return{a:this.a,b:this.b,source:this.source,transient:this.transient}}fromJSON({a:t=1,b:e=0,source:i=0,transient:n=!1}){this.a=t,this.b=e,this.source=i,this.transient=n}}sw.CONSTANT_ONE=Object.freeze(new sw(0,1)),sw.CONSTANT_ZERO=Object.freeze(new sw(0,0));class rw extends Number{constructor(t){super(),this.id=0,this.base=new Id(t),this.__modifiers=new of,this.value=new Id(t),this.base.onChanged.add(this.updateValue,this),this.postprocess=rw.Process.NONE}get onModifierAdded(){return this.__modifiers.on.added}get onModifierRemoved(){return this.__modifiers.on.removed}resetModifiers(){this.__modifiers.reset()}valueOf(){return this.getValue()}toString(){return String(this.getValue())}getValue(){return this.value.x}updateValue(){const t=this.base.x,e=this.__modifiers,i=rw.applyModifiers(t,e),n=this.postprocess(i);this.value.set(n)}getBaseValue(){return this.base.getValue()}setBaseValue(t){this.base.set(t)}getModifiers(){return this.__modifiers.data}addModifier(t){this.__modifiers.add(t),this.updateValue()}removeModifier(t){const e=this.__modifiers.removeOneOf(t);return this.updateValue(),e}equals(t){return w(this.getValue(),t.getValue(),b)}copy(t){this.base.copy(t.base),this.__modifiers.copy(t.__modifiers)}copyBase(t){this.base.copy(t.base)}setBaseFromParametricFunction(t,e){const i=t(e);this.base.set(i)}addNonTransientModifiersFromStat(t){const e=t.__modifiers.data,i=e.length;for(let t=0;t<i;t++){const i=e[t];if(i.transient)continue;const n=i.clone();this.addModifier(n)}}toJSON(){return{base:this.base.toJSON(),modifiers:this.__modifiers.toJSON()}}fromJSON(t){this.base.fromJSON(t.base),this.__modifiers.fromJSON(t.modifiers,sw)}get onChanged(){return this.value.onChanged}static applyModifiers(t,e){let i,n=1,s=0;const r=e.length,a=e.data;for(i=0;i<r;i++){const t=a[i];n+=t.a-1,s+=t.b}return t*n+s}}function aw(t,e){let i=!1;function n(){i=!1,t.call(e)}return function(){i||(i=!0,requestAnimationFrame(n))}}function ow(t){return"number"==typeof t?iw(t):t}function lw(t){return iw(t)}function hw(t){return ow(t[0])+" / "+ow(t[1])}function cw(t){return t.getValue()}function uw(t){return mw.find((function(e){return e.matcher(t)}))}function dw(t){return t}function pw(t,e,i){this.matcher=t,this.extractor=e,this.formatter=i}function fw(t,e,i){return new pw(t,e,i)}rw.Process={ROUND_DOWN:function(t){return 0|t},NONE:function(t){return t},clampMin:function(t){return function(e){return Eu(t,e)}},chain:function(...t){const e=t.length;return function(i){let n=i;for(let i=0;i<e;i++)n=(0,t[i])(n);return n}}},rw.prototype.isStat=!0;const mw=[fw(T_(Mm),cw,ow),fw(T_(Hd),cw,ow),fw(T_(Ld),cw,ow),fw(T_(nw),cw,lw),fw(T_(dy),(function(t){return[t.getValue(),t.getUpperLimit()]}),hw),fw(T_(rw),cw,lw),fw(T_(Id),cw,lw),fw(T_(Sp),cw,lw),fw((_w=i,gw=Array.isArray,function(t){return _w(t)||gw(t)}),(function(t){return t.map((function(t){return(0,uw(t).extractor)(t)}))}),hw),fw(C_("number"),dw,lw),fw(C_("string"),dw,dw),fw(C_("boolean"),dw,dw),fw(C_("function"),(function(t){return t()}),ow),fw(C_("undefined"),dw,dw)];var _w,gw;class yw extends Ay{constructor(t,{classList:e=[],transform:i=dw,format:n=Jd,tag:s="div",size:r,css:a}={}){super(),this.model=t;const o=uw(t),l=o.extractor,h=n!==Jd?n:o.formatter;this.__extractor=l,this.__formatter=h,this.__transform=i,this.el=document.createElement(s),this.el.classList.add("label");for(const t of e)this.el.classList.add(t);if(this.size.onChanged.add(this.updateSize,this),"object"==typeof this.model&&void 0!==this.model.onChanged){const t=aw(this.updateTransform,this);this.bindSignal(this.model.onChanged,t)}void 0!==a&&this.css(a),void 0!==r&&this.size.fromJSON(r)}updateSize(t,e){this.el.style.lineHeight=e+"px"}updateText(t){this.el.textContent=t}updateTransform(){const t=this.model,e=this.__extractor(t),i=this.__transform(e),n=this.__formatter(i);this.updateText(n)}link(){super.link(),this.updateTransform()}}class vw{constructor(t,e){this.key=t,this.value=e}equals(t){return this.key===t.key&&this.value===t.value}}function xw(t,e){const i=t.length;if(i!==e.length)return!1;let n=0;for(;n<i;n++){const i=t[n],s=e[n];if(i!==s){if(void 0===i)return!1;if(null===i)return!1;if("function"!=typeof i.equals)return!1;if(!i.equals(s))return!1}}return!0}function ww(t){return Cd(Nd(t.key),Nd(t.value))}class bw{constructor(){this.attributes=[],this.style=[],this.tag=""}toJSON(){const t={},e=this.attributes.length;for(let i=0;i<e;i++){const e=this.attributes[i];t[e.key]=e.value}const i={},n=this.style.length;for(let t=0;t<n;t++){const e=this.style[t];i[e.key]=e.value}return{attributes:t,styles:i}}initializeFromElement(t){this.tag=t.tagName.toLowerCase();const e=t.classList.length;for(let i=0;i<e;i++)t.classList[i];let i=0;const n=t.style,s=n.length;for(let t=0;t<s;t++){const e=n.item(t),i=new vw(e,n.getPropertyValue(e));this.style[t]=i}this.style.splice(i,this.style.length-i);const r=t.getAttributeNames(),a=r.length;for(i=0;i<a;i++){const e=r[i],n=t.getAttribute(e),s=new vw(e,n);this.attributes[i]=s}this.attributes.splice(i,this.attributes.length-i),this.updateHash()}updateHash(){const t=sg(this.style,ww),e=sg(this.attributes,ww),i=Nd(this.tag);this.__hash=Cd(t,e,i)}hash(){return this.__hash}equals(t){return this.tag===t.tag&&xw(this.style,t.style)&&xw(this.attributes,t.attributes)}reset(){const t=this.attributes;t.splice(0,t.length);const e=this.style;e.splice(0,e.length)}static fromElement(t){const e=new bw;return e.initializeFromElement(t),e}createElement(){const t=document.createElement(this.tag),e=this.style,i=e.length,n=t.style;for(let t=0;t<i;t++){const i=e[t];n.setProperty(i.key,i.value)}const s=this.attributes,r=s.length;for(let e=0;e<r;e++){const i=s[e];t.setAttribute(i.key,i.value)}return t}}function Sw(t,e,i){this.creator=t,this.destroyer=e,this.resetter=i,this.pool=[],this.maxSize=256}Sw.prototype.create=function(){if(this.pool.length>0){const t=this.pool.pop();return this.resetter(t),t}return this.creator()},Sw.prototype.release=function(t){return this.pool.length>=this.maxSize?(this.destroyer!==Jd&&this.destroyer(t),!1):(this.pool.push(t),!0)};const Mw=new Sw((()=>new bw),Jd,(t=>{t.reset()})),Tw=new class{constructor({capacity:t=100,perKeyCapacity:e=10}={}){this.data=new $p,this.__first=null,this.__last=null,this.capacity=t,this.perKeyCapacity=e,this.size=0}get(t){const e=this.data.get(t);if(void 0===e)return;let i;return e.length>1?i=e.pop():(i=e[0],this.data.delete(t)),i.unlink(),this.size--,i.value}__removeElement(t){t===this.__first&&(this.__first=t.next),t===this.__last&&(this.__last=t.previous),t.unlink();const e=t.key,i=this.data.get(e);if(1===i.length)this.data.delete(e);else{const e=i.indexOf(t);i.splice(e,1)}this.size--}add(t,e){let i=this.data.get(t);if(void 0===i)i=[],this.data.set(t,i);else if(i.length>=this.perKeyCapacity)return!1;this.size>=this.capacity&&this.__removeElement(this.__first);const n=new Kp;return n.value=e,n.key=t,n.previous=this.__last,null!==this.__last&&(this.__last.next=n),this.__last=n,null===this.__first&&(this.__first=n),i.push(n),this.size++,!0}}({capacity:500,perKeyCapacity:100});class Cw extends Ay{constructor(t,{classList:e=[],attributes:i={}}={}){let n;super(),null==t?n="":"string"==typeof t?n=t:"object"==typeof t&&"function"==typeof t.getValue&&(n=t.getValue(),void 0!==t.onChanged&&this.bindSignal(t.onChanged,this.__setSource,this));const s=Mw.create();s.tag="img",s.attributes=[new vw("src",n),new vw("class",e.join(" "))];for(const t in i){const e=String(i[t]),n=new vw(t,e);s.attributes.push(n)}s.updateHash(),this.el=function(t){let e=Tw.get(t);return void 0===e&&(e=t.createElement()),e}(s),Mw.release(s);const r=e.length;for(let t=0;t<r;t++){const i=e[t];this.addClass(i)}this.size.onChanged.add(this.__setSize,this)}destroy(){super.destroy();const t=Mw.create();t.initializeFromElement(this.el),Tw.add(t,this.el)||Mw.release(t)}__setSize(t,e){this.el.setAttribute("width",t),this.el.setAttribute("height",e)}__setSource(t){this.el.setAttribute("src",t)}}class Aw extends Ay{constructor({action:t,name:e,icon:i,classList:n=[],css:s}){if(super(),"function"!=typeof t)throw new Error("Action must be a function");const r=ew();this.el=r.el;const a=ew();a.addClass("foreground");const o=ew();if(o.addClass("background"),r.append(a),r.append(o),r.addClass("ui-button-view"),void 0!==s&&this.css(s),this.addClasses(n),this.el.addEventListener("click",(e=>{if(this.__enabled){const i=t(e);i instanceof Promise&&(this.enabled=!1,i.finally((()=>{this.enabled=!0})))}})),void 0!==e){const t=new yw(e);this.addChild(t),this.size.onChanged.add((function(e,i){t.size.set(e,i)}))}if(null!=i){const t=new Cw(i);this.addChild(t)}this.__enabled=!0}set enabled(t){this.__enabled!==t&&(this.__enabled=t,this.setClass("enabled",t),this.setClass("disabled",!t))}get enabled(){return this.__enabled}}class Ew extends Ay{constructor(t,e){super();const i=ew("div").addClass("ui-confirmation-dialog-view");this.el=i.el;const n=new Ey({classList:["content-container"]});n.addChild(t),this.addChild(n);const s=new Ey({classList:["button-area"]}),r=e.length;for(let t=0;t<r;t++){const i=e[t],n="button-"+i.name.replace(" ","-"),r=i.displayName,a=new Aw({name:r,action:function(t){t.stopPropagation(),i.callback(t)},classList:[n,"ui-confirmation-dialog-button","ui-button-rectangular"]}),o=i.enabled;if(void 0!==o){const t=()=>a.enabled=o.getValue();a.on.linked.add(t),a.bindSignal(o.onChanged,t)}a.size.set(115,36),s.addChild(a)}this.addChild(s)}}class zw{constructor({el:t,dragStart:e=Jd,drag:i=Jd,dragEnd:n=Jd,stopPropagation:s=!0}){this.pointerLocal=new wx(t);const r=this.pointerGlobal=new wx(window),a=new wd,o=new wd;s&&this.pointerLocal.on.down.add(((t,e)=>{e.stopPropagation()})),this.pointerLocal.on.dragStart.add((t=>{a.copy(t),o.copy(t),r.start(),e(t),r.on.up.add((function t(e){r.on.up.remove(t),r.stop(),n(e,a)}))})),this.pointerGlobal.on.move.add(((t,e,n)=>{i(t,a,n)}))}getPointer(){return this.pointerLocal}start(){this.pointerLocal.start()}stop(){this.pointerLocal.stop(),this.pointerGlobal.stop()}}class Iw extends Ay{constructor(t,e){super(t,e);const i=ew("div").addClass("ui-element-window");this.el=i.el,t.addClass("content"),this.addChild(t);const n=e.closeAction;!1!==e.closeable&&"function"==typeof n&&function(t,e){const i=document.createElement("div");i.classList.add("button-close"),t.el.appendChild(i);const n=document.createElement("div");n.classList.add("icon"),i.appendChild(n),i.addEventListener("click",e)}(this,n),this.title=new Hd(e.title);const s=new yw(this.title,{classList:["title"]});this.addChild(s),e.draggable&&function(t,e){let i=null;new zw({el:e,drag(e,n){const s=e.clone().sub(n);t.position.copy(i.clone().add(s))},dragStart(){i=t.position.clone()}}).start()}(this,s.el),e.resizable&&function(t){const e=new wx(window),i=new wx(t.el);i.start();let n=null;e.on.move.add((function(e){const i=e.clone().sub(n);t.size.add(i)})),e.on.up.add((function(){e.stop()})),i.on.down.add((function(i){const s=t.size.clone().sub(i.clone().sub(t.position));s.x<10&&s.x>0&&s.y<10&&s.y>0&&(n=i.clone(),e.start())}))}(this),this.content=t}}const Nw=function(t){return t},Lw=function(t){return t*t},Pw=function(t){return-t*(t-2)};function Fw(t){this.properties=t,this.propertyCount=t.length,this.keyValues=[],this.keyTimes=[],this.timeStart=Number.POSITIVE_INFINITY,this.timeEnd=Number.NEGATIVE_INFINITY,this.transitionKeys=[],this.transitionFunctions=[]}function Dw(t,e,i){this.track=t,this.position=t.timeStart,this.updateCallback=e,this.updateTraget=i,this.__lastKeyIndex=0,this.__lastTransitionIndex=0,this.__nextKeyIndex=0,this.__nextKeyTime=0,this.__loop=!1,this.__valueBuffer=new Float64Array(t.propertyCount),this.on={ended:new l},this.setPosition(0)}Fw.prototype.optimize=function(){const t=this.keyValues.length,e=this.keyTimes.length,i=new ArrayBuffer(4*e+8*t),n=new Float32Array(i,0,e),s=new Float64Array(i,4*e,t);s.set(this.keyValues,0),this.keyValues=s,n.set(this.keyTimes,0),this.keyTimes=n},Fw.prototype.addKey=function(t,e){if(e.length!==this.propertyCount)throw new Error("Number of supplied values("+e.length+") does not match number of track properties("+this.propertyCount+")");if(0===this.keyTimes.length)this.timeStart=t;else{if(t<this.timeEnd)throw new Error("Attempted to insert key in the past. Keys must be sequential");if(t===this.timeEnd)throw new Error("Attempted to insert key at the same time as already existing key")}this.timeEnd=t,Array.prototype.push.apply(this.keyValues,e),this.keyTimes.push(t)},Fw.prototype.addTransition=function(t,e){this.transitionKeys.push(t),this.transitionFunctions.push(e)},Fw.prototype.keyLowerBoundIndexAt=function(t){const e=this.keyTimes,i=e.length;for(let n=0,s=i;n<s;n++)if(e[n]>t)return n-1;return i-1},Fw.prototype.transitionIndexAt=function(t){const e=this.transitionKeys,i=e.length,n=this.keyTimes;for(let s=0,r=i;s<r;s++){const i=e[s];if(!(n[i+1]<t))return n[i]<=t?s:-1}return-1},Fw.prototype.readKeyValues=function(t,e){const i=this.propertyCount,n=i*t,s=this.keyValues;for(let t=0;t<i;t++)e[t]=s[t+n]},Dw.prototype.promiseEnded=function(){return this.position>=this.track.timeEnd?Promise.resolve():new Promise(((t,e)=>{this.on.ended.add(t)}))},Dw.prototype.setLoop=function(t){this.__loop=t},Dw.prototype.reset=function(){this.setPosition(this.track.timeStart)},Dw.prototype.setPosition=function(t){this.position=t;const e=this.track,i=e.transitionIndexAt(t);this.__lastTransitionIndex=i,this.__lastKeyIndex=-1!==i?e.transitionKeys[i]:e.keyLowerBoundIndexAt(t);const n=e.keyTimes.length;this.__nextKeyIndex=n>1?ru(this.__lastKeyIndex+1,n-1):this.__lastKeyIndex,this.__nextKeyTime=e.keyTimes[this.__nextKeyIndex]},Dw.prototype.advanceKey=function(){const t=this.track,e=t.keyTimes.length;if(this.__lastKeyIndex===e-1){if(!this.__loop)return this.__lastTransitionIndex=-1,this.on.ended.dispatch(),!1;this.__lastKeyIndex=-1}this.__lastKeyIndex=this.__lastKeyIndex+1,this.__nextKeyTime=t.keyTimes[Math.min(this.__lastKeyIndex+1,e-1)];const i=t.transitionKeys,n=i.length;for(let t=this.__lastTransitionIndex+1;t<n;t++){const e=i[t];if(e===this.__lastKeyIndex){this.__lastTransitionIndex=t;break}if(e>this.__lastKeyIndex){this.__lastTransitionIndex=-1;break}}return!0},Dw.prototype.advance=function(t){let e=this.position+t;t<0?this.setPosition(e):e>this.__nextKeyTime?(e>=this.track.timeEnd&&(this.__loop?e%=this.track.timeEnd:this.on.ended.dispatch()),this.setPosition(e)):this.position=e,this.update()},Dw.prototype.update=function(){this.readCurrentValues(this.__valueBuffer),this.updateCallback.apply(this.updateTraget,this.__valueBuffer)},Dw.prototype.readCurrentValues=function(t){const e=this.track,i=this.__lastKeyIndex;if(-1!==this.__lastTransitionIndex){const n=this.__nextKeyTime,s=e.keyTimes[i],r=n-s,a=(this.position-s)/r,o=(0,e.transitionFunctions[this.__lastTransitionIndex])(a),l=e.propertyCount,h=e.keyValues,c=i*l,u=c+l;for(let e=0;e<l;e++){const i=h[e+c],n=o*(h[e+u]-i)+i;t[e]=n}}else e.readKeyValues(i,t)};var Ow=function(t){return document.createElementNS("http://www.w3.org/2000/svg",t)};class Rw extends Ay{constructor(){super();const t=Ow("svg"),e=Ow("defs"),i=Ow("linearGradient");i.setAttribute("id","gradient"),e.appendChild(i);const n=Ow("stop"),s=Ow("stop");n.setAttribute("offset","50%"),s.setAttribute("offset","100%"),n.classList.add("color-stop-0"),s.classList.add("color-stop-1"),i.appendChild(n),i.appendChild(s),t.appendChild(e),t.classList.add("compass"),t.setAttribute("width",28),t.setAttribute("height",24);const r=Ow("polygon");r.setAttribute("points","28,12 0,24 0,0"),r.classList.add("compass-triangle"),t.appendChild(r);const a=12*Math.SQRT2;t.style.transformOrigin=`${a}px 12px`,t.style.top="-12px",t.style.left=`-${a}px`,this.el=t}rotateFromDirectionVector(t,e){const i=Math.atan2(e,t);this.rotation.set(i)}}function kw(t,e){const i=e.length;for(let e=0;e<i;e++)t[e].set(0,0);let n=0;for(let s=0;s<i-1;s++){const r=e[s],a=r.x1,o=r.y1;for(let l=s+1;l<i;l++){const i=e[l],h=a-i.x0;if(h<0)continue;const c=i.x1-r.x0;if(c<0)continue;const u=o-i.y0;if(u<0)continue;const d=i.y1-r.y0;if(d<0)continue;let p=h<c?-h:c,f=u<d?-u:d;Math.abs(p)<Math.abs(f)?f=0:p=0;const m=new wd(p,f),_=m.multiplyScalar(.5),g=t[s],y=t[l];!0===r.locked&&!0===i.locked||(!0===r.locked?y.sub(m):!0===i.locked?g.add(m):(g.add(_),y.sub(_)),n++)}}for(let n=0;n<i;n++){const i=e[n],s=t[n],r=s.x,a=s.y;i.move(r,a)}return n}class Uw extends Ay{constructor(t,e){super(),this.model=t,this.el=document.createElement("div"),this.addClass("tooltip-view");const i=new Ey({classList:["contents"]});this.addChild(i),i.addChild(e),this.contentView=i;const n=new Rw;this.addChild(n),this.compass=n}layout(t){const e=function(t){const e=t.getBoundingClientRect();let i=e.left,n=e.top,s=e.right,r=e.bottom;return Number.isNaN(s)&&(s=i),Number.isNaN(r)&&(r=n),new Vp(i,n,s,r)}(this.contentView.el);e.grow(16);const i=function(t){const e=t.position,i=e.x,n=e.y,s=t.size;let r=i,a=n;return s.x>0&&(r+=s.x),s.y>0&&(a+=s.y),new Vp(i,n,r,a)}(this.model.target),n=function(t,e,i){const n=t.clone(),s=e.clone(),r=(i.getHeight()+n.getHeight())/2,a=(i.getWidth()+n.getWidth())/2;n.set(a,r,a+n.getWidth(),r+n.getHeight()),new wd(s.midX(),s.midY()),s.locked=!0;const o=function(t,e,i){const n=[wd.up,wd.right,wd.down,wd.left],s=new wd(e.midX(),e.midY()),r=e.getHeight(),a=e.getWidth(),o=Math.sqrt(r*r+a*a),l=t.getWidth(),h=t.getHeight(),c=l/2,u=h/2,d=new wd,p=n.map((function(t){const i=t.clone()._multiply(1,-1),n=i.clone();n.multiplyScalar(o+1),n.add(s),e.lineIntersectionPoint(s,n,d);const r=new wd(c,u);return r.multiply(i),r._sub(c,u),r.add(d),r})),f=p.map((function(t){const n=new Vp,s=t.x,r=s+l,a=t.y,o=a+h;r<=e.x0?n.set(i.x0,i.y0,e.x0,i.y1):s>=e.x1?n.set(e.x1,i.y0,i.x1,i.y1):o<=e.y0?n.set(i.x0,i.y0,i.x1,e.y0):a>=e.y1&&n.set(i.x0,e.y1,i.x1,i.y1);let c=0;const u=n.getWidth();return n.getHeight()-h<0&&c--,u-l<0&&c--,c}));let m=0,_=f[0];for(let t=1;t<f.length;t++){const e=f[t];e>_+b&&(_=e,m=t)}return p[m]}(n,s,i);n.set(o.x,o.y,o.x+n.getWidth(),o.y+n.getHeight());for(let t=0;t<5;t++)!function(t,e,i,n){const s=.1*(e-t.midX()),r=.1*(i-t.midY());t.move(s,r)}(n,o.x+n.getWidth()/2,o.y+n.getHeight()/2),function(t,e){const i=[],n=t.length;for(let t=0;t<n;t++)i.push(new wd(0,0));let s=-1;for(;e>0&&0!==s;)e--,s=kw(i,t)}([n,s],10),function(t,e){for(let i=0,n=e.length;i<n;i++){const n=e[i];if(!0===n.locked)continue;let s=0,r=0;const a=n.x0,o=n.x1,l=n.y0,h=n.y1,c=t.x0,u=t.x1,d=t.y0,p=t.y1;a<c?s=c-a:o>u&&(s=u-o),l<d?r=d-l:h>p&&(r=p-h),n.move(s,r)}}(i,[n]);return t.copy(n),t}(e,i,t);n.shrink(16);const s=this.compass;!function(){const t=new wd(i.midX(),i.midY()),e=new wd;n.computeNearestPointToPoint(t,e),s.rotateFromDirectionVector(t.x-e.x,t.y-e.y),s.position.copy(e)._add(-n.x0,-n.y0)}(),this.position.set(n.x0,n.y0)}}class Bw{constructor(t,e,i,n,s){this.value=t,this.start=e,this.end=i,this.name=n,this.type=s}equals(t){return this.value===t.value&&this.start===t.start&&this.end===t.end&&this.name===t.name&&this.type===t.type}hash(){return 0}}const Vw={Text:0,Reference:1,StyleStart:2,StyleEnd:3,ReferenceValue:4};function Gw(t,e,i){this.position=t,this.message=e,this.input=i}function Ww(t,e,i){let n=e;const s=t.charAt(e);if("["!==s)throw new Gw(e,`expected style start: '[', got '${s}' instead`,t);n++;const r=t.charAt(n);let a;if("$"===r)a=Vw.StyleStart,n++;else if("/"===r){n++;const e=t.charAt(n);if(n++,"$"!==e)throw new Gw(n,`expected style end sequence '[/$', instead got '[/${e}'`,t);a=Vw.StyleEnd}const o=n;for(;n<i;){if("]"===t.charAt(n)){const i=t.substring(o,n);return n++,new Bw(i,e,n,"style",a)}n++}throw new Gw(e,"input underflow, missing terminal of style sequence ']'",t)}const Hw={String:"string",Number:"number",Boolean:"boolean",Array:"array",Any:"any"},jw={LiteralString:"literal-string",LiteralNumber:"literal-number",LiteralBoolean:"literal-boolean",Identifier:"identifier",Reference:"reference"};function qw(t,e,i){let n=e,s=0;t:for(;n<i;){const i=t.charAt(n);let r;switch(i){case"0":r=0;break;case"1":r=1;break;case"2":r=2;break;case"3":r=3;break;case"4":r=4;break;case"5":r=5;break;case"6":r=6;break;case"7":r=7;break;case"8":r=8;break;case"9":r=9;break;default:if(n===e)throw new Gw(n,`Expected a digit [0,1,2,3,4,5,6,7,8,9] but got '${i}' instead`,t);break t}n++,s=10*s+r}return new Bw(s,e,n,null,Hw.Number)}function Jw(t,e,i){let n,s=e;for(;s<i&&(n=t.charAt(s)," "===n||"\n"===n||"\t"===n);)s++;return s}function Yw(t,e,i){const n=t.charAt(e);switch(n){case"t":case"f":return function(t,e,i){const n=t.charAt(e);let s,r=e;if("t"===n&&i-e>=4){if("rue"!==t.substring(e+1,e+4))throw new Gw(e,`expected 'true', instead got '${t.substring(e,e+4)}'`,t);s=!0,r=e+4}else{if(!("f"===n&&i-e>=5))throw new Gw(e,`expected 't' or 'f', instead got '${n}'`,t);if("alse"!==t.substring(e+1,e+5))throw new Gw(e,`expected 'false', instead got '${t.substring(e,e+5)}'`,t);s=!1,r=e+5}return new Bw(s,e,r,jw.LiteralBoolean,Hw.Boolean)}(t,e,i);case'"':case"'":return function(t,e,i){let n=e;const s=function(t,e){const i=t.charAt(e);if('"'!==i&&"'"!==i)throw new Gw(e,'Expected ", found '+i+" instead",t);return i}(t,n);let r;n++;let a="";const o=i-1;for(;n<o;n++)if(r=t.charAt(n),"\\"===r)switch(n++,r=t.charAt(n),r){case"n":a+="\n";break;case"t":a+="\t";break;case"r":a+="\r";break;case"b":a+="\b";break;case"f":a+="\f";break;case"v":a+="\v";break;case"0":a+="\0";break;default:a+=r}else{if(r===s)break;a+=r}if(r=t.charAt(n),r!==s)throw new Gw(e,"Expected string terminator : "+s+", but found '"+r+"' instead",t);return n++,new Bw(a,e,n,jw.LiteralString,Hw.String)}(t,e,i);case"-":case"+":case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":return function(t,e,i){let n=e;const s=function(t){let e=1;const s=t.charAt(n);if("-"===s)e=-1;else{if("+"!==s)return 1;e=1}return n=Jw(t,n+1,i),e}(t);let r;if("0"!==t.charAt(n)||"x"!==t.charAt(n+1)&&"x"!==t.charAt(n+1)){const e=qw(t,n,i);if(n=e.end,r=e.value,n<i&&"."===t.charAt(n)){n++;const e=qw(t,n,i),s=e.end-e.start;r+=e.value/Math.pow(10,s),n=e.end}}else{const e=function(t,e,i){const n=t.charAt(e),s=t.charAt(e+1);if("0"!==n||"x"!==s&&"X"!==s)throw new Gw(e,"Expected hex prefix 0x",t);let r=e+2,a=0;t:for(;r<i;){const i=t.charAt(r);let n;switch(i){case"0":n=0;break;case"1":n=1;break;case"2":n=2;break;case"3":n=3;break;case"4":n=4;break;case"5":n=5;break;case"6":n=6;break;case"7":n=7;break;case"8":n=8;break;case"9":n=9;break;case"a":case"A":n=10;break;case"b":case"B":n=11;break;case"c":case"C":n=12;break;case"d":case"D":n=13;break;case"e":case"E":n=14;break;case"f":case"F":n=15;break;default:if(r===e)throw new Gw(r,`Expected a digit [0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F] but got '${i}' instead`,t);break t}r++,a=16*a+n}return new Bw(a,e,r,null,Hw.Number)}(t,n,i);n=e.end,r=e.value}return r*=s,new Bw(r,e,n,jw.LiteralNumber,Hw.Number)}(t,e,i);case"[":return function(t,e,i){let n=e;const s=t.charAt(n);if("["!==s)throw new Gw(e,`expected array start: '[', got '${s}' instead`,t);n++;const r=[];for(;n<i;){n=Jw(t,n,i);const e=Yw(t,n,i);if(n=e.end,r.push(e),n=Jw(t,n,i),!(n<i))throw new Gw(n,"Unterminated array literal",t);{const e=t.charAt(n);if(","!==e){if("]"===e){n++;break}throw new Gw(n,`Unexpected input '${e}', expected either separator ',' or end of sequence ']'`,t)}n++}}return new Bw(r,e,n,"array",Hw.Array)}(t,e,i);default:throw new Gw(e,"Expected literal start, but found '"+n+"'",t)}}function Xw(t,e,i){let n,s,r;for(s=e;;){if(s>=i)throw new Gw(s,"Input underflow while reading reference key",t);if(n=t.charAt(s),s++,"="===n){r=t.substring(e,s-1).trim();break}}const a=s;if(s>=i)throw new Gw(s,`Input underflow while reading reference value, value so far='${t.substring(a,i)}'`,t);const o=Yw(t,s,i);s=o.end;const l=new vw(r,o.value);return new Bw(l,e,s,"reference-value",Vw.ReferenceValue)}class Zw{constructor(t,e){this.type=t,this.values=e}}function $w(t,e,i){let n,s=e;const r=t.charAt(e);if("["!==r)throw new Gw(e,`expected reference start: '[', got '${r}' instead`,t);s++;const a=s;let o;for(;;){if(s>=i)throw new Gw(e,"input underflow, expected reference separator ':' is missing",t);if(":"===t.charAt(s)){o=t.substring(a,s),s++;break}s++}s=Jw(t,s,i),n=t.charAt(s);let l={};if("]"!==n){for(;;){s=Jw(t,s,i);const e=Xw(t,s,i);s=e.end,s=Jw(t,s,i);const r=e.value;if(l[r.key]=r.value,n=t.charAt(s),","!==n)break;s++}s=Jw(t,s,i),n=t.charAt(s)}if("]"===n){s++;const t=new Zw(o,l);return new Bw(t,e,s,"reference",Vw.Reference)}throw new Gw(s,"input underflow, expected reference end ']' is missing",t)}function Kw(t,e,i){let n=e;for(;n<i&&"["!==t.charAt(n);)n++;const s=t.substring(e,n);return new Bw(s,e,n,"text",Vw.Text)}function Qw(t){let e=0,i=t.length;const n=[];for(;e<i;){let s;if("["===t.charAt(e)){const n=t.charAt(e+1);s="$"===n||"/"===n?Ww(t,e,i):$w(t,e,i)}else s=Kw(t,e,i);if(void 0===s)break;n.push(s),e=s.end}return n}class tb{constructor(){this.__cache=new Qp({maxWeight:1048576,keyWeigher:tf,valueWeigher:t=>256*t.length,keyHashFunction:Nd,keyEqualityFunction:Kd})}resetCache(){this.__cache.clear()}parse(t){const e=this.__cache.get(t);if(null!==e)return e;const i=Qw(t);return this.__cache.put(t,i),i}}class eb{constructor(){this.enableTooltips=!0}}class ib{constructor(){this.database=null,this.localization=null,this.tooltips=null,this.__recursionCount=0,this.__recursionReferencePath=[],this.__contextStack=[],this.__tooltipsEnabled=!0,this.__reference_compilers_visual=new Map,this.__reference_compilers_text=new Map,this.__parser=new tb}addReferenceCompilerVisual(t,e){return!this.__reference_compilers_visual.has(t)&&(this.__reference_compilers_visual.set(t,e),!0)}removeReferenceCompilerVisual(t){return!!this.__reference_compilers_visual.has(t)&&(this.__reference_compilers_visual.delete(t),!0)}addReferenceCompilerText(t,e){return!this.__reference_compilers_text.has(t)&&(this.__reference_compilers_text.set(t,e),!0)}removeReferenceCompilerText(t){return!!this.__reference_compilers_text.has(t)&&(this.__reference_compilers_text.delete(t),!0)}getTooltipsEnabled(){return this.__tooltipsEnabled}setTooltipsEnabled(t){this.__tooltipsEnabled=t}initialize(t,e){this.database=t,this.localization=e}startup(){const t=this;return new Promise((function(e,i){if(null===t.database)throw new Error("Database not set; probably not initialized");t.database.promise().then(e,i)}))}getReferenceDepth(t){let e=0;const i=this.__recursionReferencePath,n=i.length;for(let s=0;s<n;s++)i[s].type===t&&e++;return e}compileTokensToText(t){const e=this.database,i=this.localization,n=this.tooltips,s=this;return t.map((t=>{let r;const a=t.type;if(a===Vw.Reference)r=function(t){const r=t.value,a=r.type.toLocaleLowerCase(),o=s.__reference_compilers_text.get(a);if(void 0===o)return;let l;s.__recursionReferencePath.push(r);try{l=o.compile(r.values,e,i,s,n)}catch(t){l="ERROR"}return s.__recursionReferencePath.pop(),l}(t);else if(a===Vw.Text)r=t.value;else if(a===Vw.StyleStart);else if(a!==Vw.StyleEnd)throw new TypeError(`Unsupported token type '${a}'`);return r})).filter((t=>void 0!==t)).join("")}compileTokensToVisual(t,e=new Ey({tag:"span"})){const i=this.database,n=this.localization,s=this.tooltips,r=this;function a(t,e){const i=t.value,n=new yw(i,{tag:"span"});e.push(n)}function o(t,e){const a=t.value,o=a.type.toLocaleLowerCase(),l=r.__reference_compilers_visual.get(o);if(void 0===l)return;let h;r.__recursionReferencePath.push(a);try{h=l.compile(a.values,i,n,r,s)}catch(t){h=new yw("ERROR")}r.__recursionReferencePath.pop(),h.addClass("reference-type-"+o),e.push(h)}const l=[];let h=e;function c(){const t=new Ey({tag:"span"});return l.forEach((e=>t.addClass(e))),t}function u(t){l.push(t);const i=c();e.addChild(i),h=i}function d(t){const i=l.indexOf(t);if(-1!==i)if(l.splice(i,1),0===l.length)h=e;else{const t=c();e.addChild(t),h=t}}const p=t.length;for(let e=0;e<p;e++){let i=t[e];const n=[],s=i.type;if(s===Vw.Reference)o(i,n);else if(s===Vw.Text)a(i,n);else if(s===Vw.StyleStart)u(i.value);else{if(s!==Vw.StyleEnd)throw new TypeError(`Unsupported token type '${s}'`);d(i.value)}const r=n.length;for(let t=0;t<r;t++){const e=n[t];h.addChild(e)}}return e}pushState(){const t=new eb;t.enableTooltips=this.__tooltipsEnabled,this.__contextStack.push(t)}popState(){const t=this.__contextStack.pop();this.__tooltipsEnabled=t.enableTooltips}compileAsText(t){if(this.__recursionCount>=50)return"";this.__recursionCount++,this.pushState();try{const e=this.__parser.parse(t);return this.compileTokensToText(e)}finally{this.popState(),this.__recursionCount--}}compile(t,e){if(this.__recursionCount>=50)return new Ey;this.__recursionCount++,this.pushState();try{const i=this.__parser.parse(t);return this.compileTokensToVisual(i,e)}finally{this.popState(),this.__recursionCount--}}compile_localized(t,e,i){const n=this.localization.getString(t,i);return this.compile(n,e)}}class nb{constructor(){this.gml=null,this.contextView=new Ey,this.contextView.addClass("ui-tooltip-manager-context"),this.pointer=null;const t=this;this.updateTask=new Mf({name:"Update Tooltip Cursor",cycleFunction:function(){const e=t.pointer.position;return t.update(e.x,e.y),bf.Yield}}),this.executor=new oy(500,1e-5),this.tips=new of}getGML(){return this.gml}initialize(t,e){this.gml=t,this.pointer=e,this.signalBindings=[]}startup(){const t=this;return new Promise((function(e,i){if(null===t.database)throw new Error("Database not set; probably not initialized");if(null===t.contextView)throw new Error("ContextView not set; probably not initialized");t.signalBindings.forEach((t=>t.link())),t.executor.run(t.updateTask),t.gml.startup().then(e,i)}))}shutdown(){const t=this;return new Promise((function(e,i){t.signalBindings.forEach((t=>t.unlink())),t.executor.removeTask(t.updateTask),e()}))}update(){}buildTipView(t){const e=this.getGML();e.pushState(),e.setTooltipsEnabled(!1);const i=t.factory.call(t.factoryContext);let n;if(e.popState(),"object"==typeof i)n=i;else{const t=i.toString();n=this.gml.compile(t)}const s=new Uw(t,n);t.view=s;const r=aw((()=>{this.positionTip(s)}));return s.bindSignal(t.target.position.onChanged,r),s.bindSignal(t.target.size.onChanged,r),s}add(t){const e=this.contextView,i=this.buildTipView(t);i.css({opacity:0}),requestAnimationFrame((()=>{this.positionTip(i),i.css({opacity:1})})),e.addChild(i),this.tips.add(t)}contains(t){return this.tips.contains(t)}remove(t){this.tips.removeOneOf(t)&&(this.contextView.removeChild(t.view),t.view=null)}positionTip(t){if(null===t)return;const e=this.contextView,i=new Vp(0,0,e.size.x,e.size.y);t.layout(i)}}function sb(t=0,e=0,i=0,n=0){this.position=new wd(t,e),this.size=new wd(i,n)}sb.prototype.set=function(t,e,i,n){this.size.set(i,n),this.position.set(t,e)},sb.prototype.clone=function(){return new sb(this.position.x,this.position.y,this.size.x,this.size.y)},sb.prototype.copy=function(t){this.position.copy(t.position),this.size.copy(t.size)},sb.prototype._intersects=function(t,e,i,n){const s=this.position,r=this.size,a=s.x,o=s.y;return pd(t,i,a,r.x+a)&&pd(e,n,o,o+r.y)},sb.prototype.intersects=function(t){const e=t.position.x,i=t.position.y,n=t.size.y+i,s=t.size.x+e;return this._intersects(e,i,s,n)},sb.prototype._overlaps=function(t,e,i,n){const s=this.position,r=this.size,a=s.x,o=s.y;return Bp(t,i,a,r.x+a)&&Bp(e,n,o,o+r.y)},sb.prototype.overlaps=function(t){const e=t.position.x,i=t.position.y,n=t.size.y+i,s=t.size.x+e;return this._overlaps(e,i,s,n)},sb.prototype._resizeToFit=function(t,e,i,n){const s=this.size,r=this.position.x,a=this.position.y;let o=s.y+a,l=s.x+r;Number.isNaN(l)&&(l=-Infinity),Number.isNaN(o)&&(o=-Infinity);const h=ru(t,r),c=ru(e,a),u=Eu(i,l),d=Eu(n,o);this.position.set(h,c),s.set(u-h,d-c)},sb.prototype.resizeToFit=function(t){const e=t.position.x,i=t.position.y,n=t.size.y+i,s=t.size.x+e;return this._resizeToFit(e,i,s,n)},sb.prototype._contains=function(t,e,i,n){const s=this.size,r=this.position.x,a=this.position.y,o=s.y+a,l=s.x+r;return t>=r&&i<=l&&e>=a&&n<=o},sb.prototype.contains=function(t){const e=t.position.x,i=t.position.y,n=t.size.y+i,s=t.size.x+e;return this._contains(e,i,s,n)},sb.prototype.computeCenter=function(t){const e=this.position,i=this.size,n=e.x+i.x/2,s=e.y+i.y/2;t.set(n,s)},sb.prototype.computeArea=function(){return this.size.x*this.size.y},sb.prototype.toArray=function(t,e=0){t[e]=this.position.x,t[e+1]=this.position.y,t[e+2]=this.size.x,t[e+3]=this.size.y},sb.prototype.toJSON=function(){return{position:this.position.toJSON(),size:this.size.toJSON()}},sb.prototype.fromJSON=function(t){this.position.fromJSON(t.position),this.size.fromJSON(t.size)};class rb{constructor(t,e,i,n=[]){this.target=t,this.factory=e,this.factoryContext=i,this.obstracles=n,this.view=null}}function ab(t,e,i){const n=t.getBoundingClientRect();if(n.left<i.x0&&(i.x0=n.left),n.right>i.x1&&(i.x1=n.right),n.top<i.y0&&(i.y0=n.top),n.bottom>i.y1&&(i.y1=n.bottom),e>0){const n=t.children;for(let t=0,s=n.length;t<s;t++)ab(n[t],e-1,i)}}const ob=new Vp;class lb{constructor({depth:t=0}={}){this.dimensions=new sb,this.__depth=t,this.element=null,this.running=!1,this.__dom_resize_observer=new ResizeObserver(this.__dom_resize_observer_callback.bind(this))}__dom_resize_observer_callback(t,e){const i=t[0].contentRect;ob.setNegativelyInfiniteBounds(),ab(this.element,this.__depth,ob);const n=this.dimensions;n.position.set(ob.x0,ob.y0),n.size.set(i.width,i.height)}synchronize(){ob.setNegativelyInfiniteBounds(),ab(this.element,this.__depth,ob);const t=this.dimensions;t.position.set(ob.x0,ob.y0),t.size.set(ob.getWidth(),ob.getHeight())}start(){this.running||(this.running=!0,this.synchronize(),null!==this.element&&this.__dom_resize_observer.observe(this.element))}attach(t){this.element=t,this.running&&this.__dom_resize_observer.unobserve(this.element)}stop(){this.running&&(this.running=!1,null!==this.element&&this.__dom_resize_observer.unobserve(this.element))}watchView(t){this.attach(t.el),t.on.linked.add(this.start,this),t.on.unlinked.add(this.stop,this)}unwatchView(t){t.on.linked.remove(this.start,this),t.on.unlinked.remove(this.stop,this)}}class hb{constructor(t,e,i){this.view=t,this.factory=e;const n=new sb;this.tipTargetRectangle=n,this.tip=new rb(n,e,i),this.on={entered:new l,exited:new l};const s=this.isEntered=new Mm(!1),r=new lb;this.sizeObserver=r,this.bindings=[new Rm(t.position.onChanged,this.__copyDimensions,this),new Rm(t.size.onChanged,this.__copyDimensions,this),new Rm(r.dimensions.position.onChanged,this.__copyDimensionsFromBoundingRect,this),new Rm(r.dimensions.size.onChanged,this.__copyDimensionsFromBoundingRect,this)],this.handleMouseEnter=()=>{s.set(!0),this.on.entered.send0(),r.attach(t.el),r.start()},this.handleMouseLeave=()=>{s.set(!1),r.stop(),this.on.exited.send0()}}__copyDimensionsFromBoundingRect(){const t=this.sizeObserver.dimensions;this.tipTargetRectangle.copy(t)}__copyDimensions(){const t=this.view,e=t.position,i=t.scale,n=t.size,s=this.tipTargetRectangle;s.position.set(e.x,e.y),s.size.set(n.x*i.x,n.y*i.y)}__handleViewLinked(){const t=this.view.el;t.style.pointerEvents="auto",t.addEventListener(dx,this.handleMouseEnter),t.addEventListener(px,this.handleMouseLeave);const e=this.bindings,i=e.length;for(let t=0;t<i;t++)e[t].link();this.__copyDimensions()}__handleViewUnlinked(){const t=this.view.el;t.removeEventListener(dx,this.handleMouseEnter),t.removeEventListener(px,this.handleMouseLeave);const e=this.bindings,i=e.length;for(let t=0;t<i;t++)e[t].unlink();this.isEntered.getValue()&&this.handleMouseLeave()}link(){const t=this.view;t.isLinked&&this.__handleViewLinked(),t.on.linked.add(this.__handleViewLinked,this),t.on.unlinked.add(this.__handleViewUnlinked,this)}unlink(){const t=this.view;t.isLinked&&this.__handleViewUnlinked(),t.on.linked.remove(this.__handleViewLinked,this),t.on.unlinked.remove(this.__handleViewUnlinked,this)}}class cb{constructor(t){this.tipManager=t,this.live=new WeakMap,this.__showDelay=128,this.__showDelayTimeout=-1}getTipManager(){return this.tipManager}show(t){const e=t.tip;this.tipManager.add(e)}hide(t){const e=t.tip;this.tipManager.remove(e)}updatePositions(){const t=this.tipManager;t.tips.forEach((e=>{t.positionTip(e.view)}))}updateTip(t){const e=this.live.get(t);if(void 0===e)return!1;e.isEntered.getValue()&&(this.hide(e),this.show(e))}manage(t,e,i){t.on.linked.add((()=>{this.add(t,e,i)})),t.on.unlinked.add((()=>{this.remove(t)}))}requestShow(t){this.cancelShowRequest(),this.__showDelayTimeout=setTimeout((()=>{this.show(t)}),this.__showDelay)}cancelShowRequest(){-1!==this.__showDelayTimeout&&(clearTimeout(this.__showDelayTimeout),this.__showDelayTimeout=-1)}initializeHide(t){this.cancelShowRequest(),this.hide(t)}add(t,e,i){const n=new hb(t,e,i);this.live.set(t,n),n.on.entered.add((()=>{this.requestShow(n)})),n.on.exited.add((()=>{this.initializeHide(n)})),n.link()}remove(t){const e=this.live.get(t);void 0!==e&&(this.hide(e),this.live.delete(t),e.unlink())}}function ub(){return("undefined"==typeof performance?Date:performance).now()/1e3}function db(t){const e=ub(),i=(e-t.__lastMeasurement)*t.speed;t.__lastMeasurement=e,t.elapsedTime+=i}class pb{constructor(){this.__lastMeasurement=0,this.elapsedTime=0,this.timeAtDelta=0,this.__isRunning=!1,this.speed=new rw(1),this.speed.postprocess=rw.Process.clampMin(0)}set multiplier(t){this.speed.base.set(t)}get multiplier(){return this.speed.base.getValue()}start(){this.__lastMeasurement=ub(),this.timeAtDelta=this.updateElapsedTime(),this.__isRunning=!0}stop(){this.__isRunning=!1}pause(){this.__isRunning=!1,db(this)}getDelta(){const t=this.updateElapsedTime(),e=t-this.timeAtDelta;return this.timeAtDelta=t,e}updateElapsedTime(){return this.__isRunning&&db(this),this.elapsedTime}getElapsedTime(){return this.elapsedTime}reset(){this.elapsedTime=0,this.timeAtDelta=0}}class fb{constructor(){this.clock=new pb,this.clock.pause(),this.isRunning=!1,this.callbacks=[]}subscribe(t,e){const i=new r(t,e);this.callbacks.push(i)}unsubscribe(t,e){const i=this.callbacks,n=i.length;for(let s=0;s<n;s++){const n=i[s];if(n.handle===t){if(void 0===e)return void i.splice(s,1);if(e===n.context)return void i.splice(s,1)}}}start({maxTimeout:t=100}={}){const e=this;let i=null,n=null;function s(){cancelAnimationFrame(n),a()}function r(){clearTimeout(i),setTimeout(a,0)}function a(){n=requestAnimationFrame(r),function(){if(e.isRunning){const t=e.clock.getDelta(),i=e.callbacks;for(let e=0;e<i.length;e++){const n=i[e];try{n.handle.call(n.context,t)}catch(t){}}}}(),i=setTimeout(s,t)}this.isRunning=!0,e.clock.getDelta(),e.clock.start(),requestAnimationFrame(r)}pause(){this.isRunning=!1}resume(){this.isRunning=!0}}class mb{constructor(t){this.description=t,this.__state=-1,this.__eventHandlersStateEntry=[],this.__eventHandlersStateExit=[]}addEventHandlerStateEntry(t,e,i){const n=this.__eventHandlersStateEntry[t],s=new r(e,i);void 0===n?this.__eventHandlersStateEntry[t]=[s]:n.push(s)}removeEventHandlerStateEntry(t,e,i){const n=this.__eventHandlersStateEntry[t];if(void 0!==n){const t=h(n,e,i);if(-1!==t)return n.splice(t,1),!0}return!1}addEventHandlerStateExit(t,e,i){const n=this.__eventHandlersStateExit[t],s=new r(e,i);void 0===n?this.__eventHandlersStateExit[t]=[s]:n.push(s)}removeEventHandlerStateExit(t,e,i){const n=this.__eventHandlersStateExit[t];if(void 0!==n){const t=h(n,e,i);if(-1!==t)return n.splice(t,1),!0}return!1}setState(t){const e=this.__state,i=this.__eventHandlersStateExit[e];void 0!==i&&d(i,[e,t]),this.__state=t;const n=this.__eventHandlersStateEntry[t];void 0!==n&&d(n,[t,e])}getState(){return this.__state}navigateTo(t){const e=this.getState();if(e===t)return;const i=this.description.findPath(e,t);if(null===i)throw new Error(`No path exists from current state '${e}' to target state '${t}'`);const n=i.length;for(let t=1;t<n;t++){const e=i[t];this.setState(e)}}advance(t,e=Jd){const i=this.description,n=i.__actions[this.__state];let s;if(void 0===n){const t=i.getOutgoingStates(this.__state);if(1!==t.length)return!1;s=t[0]}else s=n(t);return e(s,t),this.setState(s),!0}}const _b=new class{constructor(){this.__states=new g_,this.__edges=[],this.__actions=[]}traverseStates(t,e){const i=this.__states;for(let n=i.nextSetBit(0);-1!==n;n=i.nextSetBit(n+1))t.call(e,n)}stateExists(t){return this.__states.get(t)}edgeExists(t,e){const i=this.__edges[t];return void 0!==i&&-1!==i.indexOf(e)}createState(t=this.__states.nextClearBit(0)){return this.__states.set(t,!0),t}createEdge(t,e){const i=this.__edges,n=i[t];void 0===n?i[t]=[e]:n.push(e)}setAction(t,e){this.__actions[t]=e}getOutgoingStates(t){const e=this.__edges[t];return void 0===e?[]:e}getIncomingStates(t){const e=[];for(let i in this.__edges){const n=parseInt(i);-1!==this.__edges[n].indexOf(t)&&e.push(n)}return e}findPath(t,e){const i=new Set;i.add(t);const n=new Set,s=new Map;function r(){const t=[];let i=e;do{t.unshift(i),i=s.get(i)}while(void 0!==i);return t}const a=this;function o(t){const e=a.getOutgoingStates(t),r=e.length;for(let a=0;a<r;a++){const r=e[a];n.has(r)||i.has(r)||(i.add(r),s.set(r,t))}}for(;i.size>0;){const t=i.values().next().value;if(t===e)return r();i.delete(t),n.add(t),o(t)}return null}};_b.createState(0),_b.createState(1),_b.createState(2),_b.createState(3),_b.createEdge(0,1),_b.createEdge(1,2),_b.createEdge(2,1),_b.createEdge(1,3),_b.setAction(0,(()=>1)),_b.setAction(1,(t=>t)),_b.setAction(2,(()=>1));class gb{constructor({priority:t=0}={}){this.sm=new mb(_b),this.sm.setState(0),this.priority=t}makeReady(){const t=this.sm.getState();if(1!==t){if(0!==t&&2!==t)throw new Rf(`expected Initial(=0) or Active(=2) state, got ${t}`);this.sm.advance()}}makeActive(){const t=this.sm.getState();2!==t&&(1!==t&&this.makeReady(),this.sm.advance(2))}makeDestroyed(){const t=this.sm.getState();3!==t&&(1!==t&&this.makeReady(),this.sm.advance(3))}}const yb={Normal:"normal",Pointer:"pointer",Attack:"attack",Move:"move"};class vb{constructor(){this.elements=[],this.__active=null,this.observers=new Map,this.on={added:new l,lastRemoved:new l,firstAdded:new l}}hasActive(){return null!==this.__active}update(){if(!this.hasActive()&&this.elements.length>0){const t=this.elements[0];this.activate(t)}}activate(t){this.__active=t,t.makeActive()}add(t){t.sm.addEventHandlerStateEntry(3,(()=>{this.remove(t),this.update()})),this.elements.push(t),this.elements.sort(((t,e)=>e.priority-t.priority)),this.hasActive()&&this.__active!==this.elements[0]&&(this.__active.makeReady(),this.__active=null),this.update(),this.on.added.send1(t),1===this.elements.length&&this.on.firstAdded.send0()}remove(t){const e=this.elements.indexOf(t);return-1!==e&&(t===this.__active&&(this.__active=null),this.elements.splice(e,1),this.update(),0===this.elements.length&&this.on.lastRemoved.send0(),!0)}}class xb{constructor({title:t="",description:e="",image:i="",classList:n=[]}){this.title=t,this.description=e,this.image=new Hd(i),this.classList=n}}function wb(){this.elements=new of,this.maxLength=1e3}xb.prototype.isNotification=!0,wb.prototype.add=function(t){const e=new xb(t);return this.addNotification(e),e},wb.prototype.addNotification=function(t){const e=this.elements.length,i=this.maxLength-1;e>i&&this.elements.crop(e-i,e),this.elements.add(t)};class bb{constructor({log:t,initializer:e,updateFunction:i=Jd}){this.needsUpdate=i!==Jd,this.__update_function=i,this.log=t,this.initializer=e,this.timeScale=1}update(t){const e=this.timeScale*t;this.__update_function(e)}initialize(){this.initializer(this.log)}}class Sb{constructor(){this.channels=new Map,this.displays=new of,this.defaultArea=void 0,this.ecd=null}createChannel(t){if(this.channels.has(t))throw new Error(`channel '${t}' already exists`);this.channels.set(t,new wb),void 0===this.defaultArea&&(this.defaultArea=t)}getChannel(t){return this.channels.get(t)}getDisplays(t){const e=this.getChannel(t);return this.displays.filter((t=>t.log===e))}addDisplay(t,e,i){const n=this.channels.get(t);if(void 0===n)throw new Error(`channel '${t}' doesn't exist`);const s=new bb({log:n,initializer:e,updateFunction:i});this.displays.add(s),s.initialize()}addEmitterDisplay(t,e,i=null){const n=new Map,s=this,r=`managed-notification-channel-${t}`;function a(t){for(const[e,i]of n)if(i.entity===t){n.delete(e);break}}this.addDisplay(t,(function(t){e.objectEmitter.objectFinalizer=function(t){const e=n.get(t);void 0!==e&&(e.removeEventListener(v_,a),e.destroy(),n.delete(t))},t.elements.on.added.add((function(t){e.spawn(t)})),e.on.spanwed.add((function(t){t.addClass(r);const e=new z_;e.add(Ux.Transient);const o=s.ecd;if(null!==o){const s=$x.fromView(t);s.group=i,e.addEventListener(v_,a),e.add(s).build(o),n.set(t,e)}}))}),(function(t){e.tick(t)}))}addNotification(t,e=this.defaultArea){const i=this.channels.get(e);if(void 0===i)throw new Error(`Area '${e}' doesn't exist`);i.addNotification(t)}tick(t){const e=this.displays,i=e.length;for(let n=0;n<i;n++){const i=e.get(n);i.needsUpdate&&i.update(t)}}}class Mb{constructor(t){this.object=t,this.playback=null}}class Tb{constructor(){this.animation=null,this.animationUpdater=null,this.objectFactory=null,this.objectInitializer=Jd,this.objectFinalizer=Jd,this.elements=[],this.rushThreshold=Number.POSITIVE_INFINITY,this.spawnDelay=0,this.__spawnTimeBudget=0,this.__spawnBuffer=[],this.on={spanwed:new l,removed:new l},this.liveCount=0}setAnimation(t,e){this.animation=t,this.animationUpdater=e}setInitializer(t){this.objectInitializer=t}setFinalizer(t){this.objectFinalizer=t}spawn(t){this.liveCount++,this.__spawnTimeBudget<this.spawnDelay?this.__spawnBuffer.push(t):(this.spawnImmediate(t),this.__spawnTimeBudget=0)}spawnImmediate(t){const e=this.objectFactory(t),i=new Dw(this.animation,this.animationUpdater,e);i.reset(),i.update(),this.objectInitializer(e);const n=this;i.on.ended.add((function(){n.remove(e)}));const s=new Mb(e);return s.playback=i,this.elements.push(s),this.on.spanwed.dispatch(e),s}trySpawnDeferred(){const t=this.__spawnBuffer;let e=t.length;if(0===e)return;const i=this.__spawnTimeBudget;let n=0;const s=ru(Math.floor(i/this.spawnDelay),e),r=t.splice(0,s);for(n=0;n<s;n++){const t=r[n];this.spawnImmediate(t).playback.advance((s-(n+1))*this.spawnDelay)}this.__spawnTimeBudget%=this.spawnDelay}remove(t){const e=this.elements;for(let i=0,n=e.length;i<n;i++)if(e[i].object===t)return e.splice(i,1),this.liveCount--,this.objectFinalizer(t),this.on.removed.send1(t),!0;return!1}tick(t){const e=this.elements,i=e.length;for(let n=i-1;n>=0;n--){const s=e[n].playback,r=Eu(1,(i-n)/this.rushThreshold)*t;s.advance(r)}this.__spawnTimeBudget+=t,this.trySpawnDeferred()}}class Cb{constructor(){this.source=new wd,this.objectEmitter=new Tb,this.objectEmitter.objectInitializer=function(t){t.visible=!0};const t=this;this.objectEmitter.objectFactory=function(e){const i=t.viewFactory(e);return i.position.copy(t.source),i},this.viewFactory=null,this.timeScale=1,this.on=this.objectEmitter.on}setAnimation(t,e){this.objectEmitter.setAnimation(t,e)}setRushThreshold(t){this.objectEmitter.rushThreshold=t}setSpawnDelay(t){this.objectEmitter.spawnDelay=t}tick(t){const e=t*this.timeScale;this.objectEmitter.tick(e)}spawn(t){return this.objectEmitter.spawn(t)}remove(t){return this.objectEmitter.remove(t)}}class Ab extends Ay{constructor(t){super(),this.model=t;const e=ew("div").addClass("ui-notification-view");this.el=e.el,this.addClasses(t.classList),this.vImage=new Cw(t.image,{classList:["image"]}),this.addChild(this.vImage),this.dTitle=e.createChild("div").addClass("title"),this.dDescription=e.createChild("div").addClass("description"),this.bindSignal(t.image.onChanged,this.updateImage,this)}link(){super.link();const t=this.model;this.dTitle.text(t.title),this.dDescription.text(t.description),this.updateImage()}updateImage(){const t=this.model.image.getValue();this.vImage.visible=void 0!==t&&""!==t}}const Eb="primary",zb="secondary",Ib="toast";class Nb{constructor(){this.scene=null,this.modals=new vb,this.notifications=new Sb,this.clockModifierZero=new sw(0,0)}initialize(t){var e;this.scene=t,(e=this.notifications).createChannel(Eb),e.createChannel(zb),e.createChannel(Ib),e.addEmitterDisplay(Eb,function(){const t=new Cb;t.setRushThreshold(1),t.setSpawnDelay(2);const e=new Fw(["alpha","scale"]);return e.addKey(0,[0,1.3]),e.addKey(.6,[1,1]),e.addKey(2.9,[1,1]),e.addKey(3.4,[0,1]),e.addTransition(0,Lw),e.addTransition(2,Pw),t.setAnimation(e,(function(t,e){this.el.style.opacity=t,this.scale.set(e,e)})),t.viewFactory=function(t){return new Ab(t)},t}()),e.addEmitterDisplay(zb,function(){const t=new Cb;t.setRushThreshold(1),t.setSpawnDelay(.7);const e=new Fw(["alpha","position.y","scale"]);return e.addKey(0,[.2,0,1.1]),e.addKey(.17,[1,0,1]),e.addKey(3.2,[1,-60,1]),e.addKey(3.7,[0,-70,1]),e.addTransition(0,Lw),e.addTransition(1,Nw),e.addTransition(2,Pw),t.setAnimation(e,(function(t,e,i){const n=this;n.el.style.opacity=t,n.position.setY(e),n.scale.set(i,i)})),t.viewFactory=function(t){return new Ab(t)},t}()),e.addEmitterDisplay(Ib,function(){const t=new Cb;t.setRushThreshold(5),t.setSpawnDelay(.1);const e=new Fw(["alpha","position.x"]);return e.addKey(0,[.2,100]),e.addKey(.17,[1,0]),e.addKey(7.5,[1,0]),e.addKey(8,[0,0]),e.addTransition(0,Lw),e.addTransition(1,Nw),e.addTransition(2,Pw),t.setAnimation(e,(function(t,e){this.el.style.opacity=t,this.position.setX(e)})),t.viewFactory=function(t){return new Ab(t)},t}(),"managed-toast-notifications"),this.notifications.ecd=t.dataset}tick(t){this.notifications.tick(t)}stopTime(){this.scene.speedModifiers.add(this.clockModifierZero)}resumeTime(){this.scene.speedModifiers.removeOneOf(this.clockModifierZero)}startup(){this.modals.on.firstAdded.add(this.stopTime,this),this.modals.on.lastRemoved.add(this.resumeTime,this)}shutdown(){this.modals.on.firstAdded.remove(this.stopTime,this),this.modals.on.lastRemoved.remove(this.resumeTime,this)}}function Lb(){this.windows=new of,this.captureInputs=new Mm(!1),this.entityManager=null,this.engine=null,this.sceneContexts=new WeakMap,this.tooltips=new nb,this.viewTooltips=new cb(this.tooltips),this.ticker=new fb,this.ticker.subscribe((t=>{let e=null;try{e=this.getActiveSceneContext()}catch(t){}null!==e&&e.tick(t)})),this.view=new Ey({classList:["gui-engine-root"],css:{position:"absolute",left:"0",top:"0"}}),this.gml=new ib,this.cursor=new Ld(yb.Normal),this.localization=null}function Pb(t){const e=new Ay;return e.el=document.createElement("div"),e.el.classList.add("text"),e.el.innerText=t,e.size.set(300,100),e}function Fb(t,e){this.view=t,this.name=e}Lb.prototype.openWindow=function({closeable:t,content:e,title:i,wrapper:n}){const s=new z_,r=new Iw(e,{closeAction:function(){s.destroy()},title:i,closeable:t});let a;s.add(new Kx),void 0!==n?(a=n,n.addChild(r)):a=r;const o=$x.fromView(a);s.add(o).add(Ux.Transient);const l=this.entityManager.dataset;return function(t,e){const i=new Fw(["alpha","scale"]);i.addKey(0,[0,.95]),i.addKey(.2,[1,1]),i.addTransition(0,Nw);const n=new Dw(i,(function(t,e){this.el.style.opacity=t,this.scale.set(e,e)}),t);n.update(),function(t,e){const i=new z_,n=Yx.fromOne(new Xx(t));n.clock=1,i.add(n),i.add(Ux.Transient),t.update(),i.build(e),t.on.ended.add((function(){i.destroy()}))}(n,e)}(r,l),s.build(l),s},Lb.prototype.createModal=function({content:t,title:e,priority:i=0}){const n=this.entityManager,s=this;let r=null,a=null;const o=new gb({priority:i});return o.sm.addEventHandlerStateEntry(2,(function(){a=function(){const t=new Ay;t.el=document.createElement("div"),t.el.classList.add("ui-modal-overlay"),t.el.addEventListener("click",(function(t){t.stopPropagation(),o.makeDestroyed()}));const e=new z_;return e.add(Ux.Transient),e.add($x.fromView(t)),e}(),a.build(n.dataset);const i=t,l=new Ey({classList:["ui-modal-window-container"]});r=s.openWindow({title:e,content:i,closeable:!1,wrapper:l}),r.getComponent($x).anchor.set(.5,.5),r.removeComponent(Kx)})),o.sm.addEventHandlerStateExit(2,(function(){r.destroy(),a.destroy()})),this.getActiveSceneContext().modals.add(o),o},Lb.prototype.createModalConfirmation=function({title:t,content:e,confirmationEnabled:i}){const n=this;let s=null;return new Promise((function(r,a){let o=!1;function l(){s.makeDestroyed()}const h=new Ew(e,[{name:"yes",displayName:n.localization.getString("system_confirmation_confirm"),callback:function(){o=!0,l(),r()},enabled:i},{name:"no",displayName:n.localization.getString("system_confirmation_cancel"),callback:function(){o=!0,l(),a()}}]);s=n.createModal({content:h,title:t}),s.sm.addEventHandlerStateEntry(3,(function(){o||a()}))}))},Lb.prototype.confirmTextDialog=function({text:t,title:e}){const i=Pb(t);return this.createModalConfirmation({title:e,content:i})},Lb.prototype.createTextAlert=function({text:t,title:e}){const i=Pb(t);return this.createAlert({content:i,title:e})},Lb.prototype.createAlert=function({content:t,title:e,marks:i=[],priority:n=0,lifecycleHook:s=Jd}){let r=null;const a=this.localization,o=new Ew(t,[{name:"ok",displayName:a.getString("system_confirmation_continue"),callback:function(){r.makeDestroyed()}}]);if(i.length>0){const t=new Ey({classList:["marks"]});i.forEach(t.addChild,t),o.addChild(t)}r=this.createModal({content:o,title:e,priority:n});const l=new Promise((function(t,e){r.sm.addEventHandlerStateEntry(3,t)}));return s(r),l},Lb.prototype.obtainSceneContext=function(t){let e=this.sceneContexts.get(t);return void 0===e&&(e=new Nb,e.initialize(t),e.startup(),this.sceneContexts.set(t,e)),e},Lb.prototype.getActiveSceneContext=function(){const t=this.engine;if(null===t)throw new Error("Engine is not set");const e=t.sceneManager.currentScene;return null===e?null:this.obtainSceneContext(e)},Lb.prototype.__update_localization=function(){this.view.removeClassesByPattern(/locale-/),this.view.addClass(`locale-${this.localization.locale.getValue()}`)},Lb.prototype.startup=function(t){this.engine=t,this.entityManager=t.entityManager;const e=this,i=t.localization;return this.gml.initialize(t.staticKnowledge,i),this.tooltips.initialize(this.gml,t.devices.pointer),this.gml.tooltips=this.viewTooltips,this.view.addChild(this.tooltips.contextView),t.gameView.addChild(this.view),t.gameView.size.process((function(t,i){e.view.size.set(t,i),e.tooltips.contextView.size.set(t,i)})),this.ticker.start(),this.localization=i,this.cursor.process((function(e,i){function n(t){return`cursor-${t}`}const s=t.graphics.domElement.classList;"string"==typeof i&&s.remove(n(i)),"string"==typeof e&&s.add(n(e))})),this.localization.locale.onChanged.add(this.__update_localization,this),this.__update_localization(),Promise.all([this.tooltips.startup()])},Lb.prototype.shutdown=function(){this.windows.reset(),this.entityManager=null;const t=this.tooltips.shutdown();return this.localization.locale.onChanged.remove(this.__update_localization,this),Promise.all([t])};class Db extends Ay{constructor(){super();const t=ew("div").css({position:"absolute",left:0,top:0,pointerEvents:"none"}).el;t.setAttribute("tabindex",0),this.el=t,this.addClass("view-stack"),this.__stack=[],this.__activeFrame=null,this.bindSignal(this.size.onChanged,this.updateActiveFrameSize.bind(this))}updateActiveFrameSize(){const t=this.__activeFrame;null!==t&&t.view.size.copy(this.size)}link(){super.link(),this.updateActiveFrameSize()}setActiveFrame(t){const e=this.__stack;if(t>=e.length)throw new Error("Index is too high, stack overflow");if(null!==this.__activeFrame&&this.removeChild(this.__activeFrame.view),t>=0){const i=e[t];this.__activeFrame=i;const n=i.view;this.addChild(n),n.size.copy(this.size),n.position.set(0,0)}else this.__activeFrame=null}push(t,e=""){const i=this.__stack,n=new Fb(t,e);i.push(n);const s=i.length-1;this.setActiveFrame(s)}unwind(t){const e=this.__stack,i=e.length,n=e.splice(t,i-t);return this.setActiveFrame(t-1),n}pop(){return this.unwind(this.__stack.length-1)[0]}}function Ob(t,e="Unnamed"){this.name=e,this.children=t,this.on={started:new l,completed:new l,failed:new l},this.state=new Sp(Sf.INITIAL)}function Rb(t){if(t.isTask){const e=t.state.getValue();if(e===Sf.INITIAL||e===Sf.READY)return 0}return t.computeProgress()}Ob.prototype.getExecutedCpuTime=function(){let t=0;const e=this.children,i=e.length;for(let n=0;n<i;n++)t+=e[n].getExecutedCpuTime();return t},Ob.prototype.addChild=function(t){return-1===this.children.indexOf(t)&&(this.children.push(t),!0)},Ob.prototype.addChildren=function(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.addChild(e)}},Ob.prototype.isTaskGroup=!0,Ob.prototype.addDependency=function(t){if(t.isTaskGroup)this.addDependencies(t.children);else{const e=this.children,i=e.length;for(let n=0;n<i;n++)e[n].addDependency(t)}},Ob.prototype.addDependencies=function(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.addDependency(e)}},Ob.prototype.getEstimatedDuration=function(){let t=0;const e=this.children,i=e.length;for(let n=0;n<i;n++){const i=e[n].getEstimatedDuration();isNaN(i)||i<0||(t+=i)}return t},Ob.prototype.getVerboseStatusMessage=function(){const t=new Ff;return function e(i){if(i.isTaskGroup){t.add(`group ['${i.name}']`),t.indent();for(let t=0;t<i.children.length;t++)e(i.children[t]);t.dedent()}else t.add(`task ['${i.name}'] ${Vg(Sf,i.state.getValue())}`)}(this),t.build()},Ob.prototype.computeProgress=function(){const t=this.children,e=t.length;let i=0,n=0;for(let s=0;s<e;s++){const e=t[s],r=e.getEstimatedDuration();isNaN(r)||(i+=Rb(e)*r,n+=r)}return 0===n?0:i/n},Ob.prototype.join=function(t,e){Mf.join(this,t,e)},Ob.prototype.promise=function(){return Mf.promise(this)};class kb{constructor(){this.table=null,this.id=null,this.source=null}static from(t,e,i){const n=new kb;return n.id=t,n.source=e,n.table=i,n}}const Ub={Initial:0,Loading:1,Loaded:2,Failed:3};class Bb{constructor(){this.__state=new Tm(Ub.Initial,Ub),this.__specs=[]}reset(){this.__state.set(Ub.Initial);const t=this.__specs,e=t.length;for(let i=0;i<e;i++)t[i].table.reset()}add(t,e,i){const n=this.__state.getValue();if(n!==Ub.Initial)throw new Rf(`Adding new tables is only allowed in Initial state, current state is ${Vg(Ub,n)}`);const s=this.getDescriptorById(t);if(void 0!==s){if(s.id===t&&s.source===e&&Object.getPrototypeOf(s.table)===Object.getPrototypeOf(i))return;throw new Error(`Table '${t}' already exists`)}const r=kb.from(t,e,i);this.__specs.push(r),this[t]=i}getDescriptorById(t){const e=this.__specs,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.id===t)return i}}getTable(t){const e=this.getDescriptorById(t);if(void 0!==e)return e.table}promise(){const t=this.__state;return new Promise((function(e,i){t.process((function(t){return t===Ub.Loaded?e():t===Ub.Failed?i("Failed to load Static Knowledge"):void 0}))}))}validate(t){const e=new Ob(this.__specs.map((t=>t.table.validate(this,console.error))),"Database Validation"),i=Mf.promise(e);return t.runGroup(e),i}async __link_table(t,e,i){const n=t.table;await n.link(this,e,i)}link(t,e){const i=this.__specs.map((i=>{this.__link_table(i,t,e).catch((t=>{i.table}))}));return Promise.all([i])}async __load_table(t,e,i){const n=t.source,s=t.table;if(!0!==s.isStaticKnowledgeDataTable)throw new Error("Illegal argument, table.isStaticKnowledgeDataTable !== true");const r=(await e.promise(n,Jp.JSON)).create();return await s.load(r,i),s}async __hot_load(t,e,i){await this.__load_table(t,e,i),await this.__link_table(t,e,i)}load(t,e){if(this.__state.getValue()!==Ub.Initial)throw new Error("Illegal state");this.__state.set(Ub.Loading);const i=this,n=[],s=this.__specs.length;for(let i=0;i<s;i++){const s=this.__specs[i],r=this.__load_table(s,t,e);n.push(r)}return Promise.all(n).then((()=>{let i=this.link(t,e);return ENV_PRODUCTION||(i=i.then((()=>this.validate(e)))),i})).then((function(){i.__state.set(Ub.Loaded)}),(function(t){i.__state.set(Ub.Failed)}))}}Bb.prototype.isStaticKnowledgeDatabase=!0;const Vb=new Uint32Array(65536),Gb=(t,e)=>{if(t.length<e.length){const i=e;e=t,t=i}return 0===e.length?t.length:t.length<=32?((t,e)=>{const i=t.length,n=e.length,s=1<<i-1;let r=-1,a=0,o=i,l=i;for(;l--;)Vb[t.charCodeAt(l)]|=1<<l;for(l=0;l<n;l++){let t=Vb[e.charCodeAt(l)];const i=t|a;t|=(t&r)+r^r,a|=~(t|r),r&=t,a&s&&o++,r&s&&o--,a=a<<1|1,r=r<<1|~(i|a),a&=i}for(l=i;l--;)Vb[t.charCodeAt(l)]=0;return o})(t,e):((t,e)=>{const i=e.length,n=t.length,s=[],r=[],a=Math.ceil(i/32),o=Math.ceil(n/32);for(let t=0;t<a;t++)r[t]=-1,s[t]=0;let l=0;for(;l<o-1;l++){let a=0,o=-1;const h=32*l,c=Math.min(32,n)+h;for(let e=h;e<c;e++)Vb[t.charCodeAt(e)]|=1<<e;for(let t=0;t<i;t++){const i=Vb[e.charCodeAt(t)],n=r[t/32|0]>>>t&1,l=s[t/32|0]>>>t&1,h=i|a,c=((i|l)&o)+o^o|i|l;let u=a|~(c|o),d=o&c;u>>>31^n&&(r[t/32|0]^=1<<t),d>>>31^l&&(s[t/32|0]^=1<<t),u=u<<1|n,d=d<<1|l,o=d|~(h|u),a=u&h}for(let e=h;e<c;e++)Vb[t.charCodeAt(e)]=0}let h=0,c=-1;const u=32*l,d=Math.min(32,n-u)+u;for(let e=u;e<d;e++)Vb[t.charCodeAt(e)]|=1<<e;let p=n;for(let t=0;t<i;t++){const i=Vb[e.charCodeAt(t)],a=r[t/32|0]>>>t&1,o=s[t/32|0]>>>t&1,l=i|h,u=((i|o)&c)+c^c|i|o;let d=h|~(u|c),f=c&u;p+=d>>>n-1&1,p-=f>>>n-1&1,d>>>31^a&&(r[t/32|0]^=1<<t),f>>>31^o&&(s[t/32|0]^=1<<t),d=d<<1|a,f=f<<1|o,c=f|~(l|d),h=d&l}for(let e=u;e<d;e++)Vb[t.charCodeAt(e)]=0;return p})(t,e)},Wb=/\$\{([a-zA-Z0-9_]+)\}/gi;class Hb{reading_speed=10;fallback_languages=[];locale="";fromJSON({reading_speed:t=10,fallback_languages:e=[]}){this.reading_speed=t,this.fallback_languages=e}static fromJSON(t){const e=new Hb;return e.fromJSON(t),e}}const jb=Object.freeze({}),qb=Object.freeze(new Hb);class Jb{constructor(){this.assetManager=null,this.json={},this.language_metadata=qb,this.locale=new Ld(""),this.debug=!0,this.__failure_cache=new Qp({maxWeight:1024,keyHashFunction:t=>sg(t,Nd)})}get reading_speed(){return this.language_metadata.reading_speed}estimateReadingTime(t){return t.length/this.reading_speed}setAssetManager(t){this.assetManager=t}validate(t){let e=!0;for(let i in this.json){const n=this.json[i],s=n.replace(Wb,(function(t,e){return"0"}));try{Qw(s)}catch(s){e=!1,t(i,s,n)}}return e}loadLocale(t,e="data/database/text"){const i=this.assetManager;if(null===i)throw new Error("AssetManager is not set");let n=e.trim();for(;n.endsWith("/")||n.endsWith("\\");)n.slice(0,n.length-1);const s=i.promise(`${n}/${t}.json`,"json").then((e=>{const i=e.create();this.json=i,this.locale.set(t)}),(t=>{this.json={}})),r=i.promise(`${n}/languages.json`,"json").then((e=>{const i=e.create();this.language_metadata=Hb.fromJSON(i[t])}),(t=>{this.language_metadata=qb}));return Promise.all([s,r])}formatIntegerByThousands(t){return new Intl.NumberFormat(this.locale.getValue(),{useGrouping:!0}).format(t)}__debugMissingKey(t,e){const i=this.locale.getValue(),n=JSON.stringify(e);this.__failure_cache.getOrCompute([i,t,n],(()=>{const e=Object.keys(this.json).map((function(e){return{key:e,distance:Gb(e,t)}}));e.sort((function(t,e){return t.distance-e.distance}));const i=e.slice(0,3).map((t=>t.key));return`No localization value for id='${t}', seed=${n}, approximate matches: ${i.join(", ")}`}))}getString(t,e=jb){const i=this.json[t];return void 0===i?(this.debug&&this.__debugMissingKey(t,e),`@${t}`):function(t,e){return t.replace(Wb,(function(t,i){return e[i]}))}(i,e)}hasString(t){return void 0!==this.json[t]}}class Yb{constructor(){this.__elements=new Map;const t=this;this.proxy=new Proxy({},{get(e,i,n){const s=t.__elements.get(i);if(void 0===s)throw new Error(`Module '${i}' not found in the registry`);return s}})}traverse(t){this.__elements.forEach(((e,i)=>t(i,e)))}get(t){return this.__elements.get(t)}has(t){return this.__elements.has(t)}add(t,e){return this.has(t)?(this.get(t),!1):(this.__elements.set(t,e),!0)}initialize(){}}class Xb{constructor(t,e){this.first=t,this.second=e,this.direction=3}contains(t){return this.first===t||this.second===t}validateTransition(t,e){const i=this.first,n=this.second;return i===t&&n===e&&this.traversableForward()||n===t&&i===e&&this.traversableBackward()}other(t){return t===this.first?this.second:this.first}traversableForward(){return 0!=(1&this.direction)}traversableBackward(){return 0!=(2&this.direction)}angle(){const t=this.second.clone().sub(this.first);return Math.atan2(t.y,t.x)}get nodes(){return[this.first,this.second]}get length(){return this.first.distanceTo(this.second)}}Xb.prototype.isEdge=!0;class Zb{constructor(){this.__nodes=[],this.__nodes_set=new Set,this.__edges=[],this.onChange=new l}get nodes(){return this.__nodes}get edges(){return this.__edges}copy(t){this.clear(),this.__nodes=t.__nodes.slice(),this.__edges=t.__edges.slice(),this.__nodes_set=new Set(this.__nodes)}findPath(t,e){const i=new Set;i.add(t);const n=new Set,s=new Map;function r(){const t=[];let i=e;do{t.unshift(i),i=s.get(i)}while(void 0!==i);return t}const a=this;function o(t){a.traverseSuccessors(t,(function(e,r){n.has(e)||i.has(e)||(i.add(e),s.set(e,t))}))}for(;i.size>0;){const t=i.values().next().value;if(t===e)return r();i.delete(t),n.add(t),o(t)}return null}isEdgeBetween(t,e){return!(!this.containsNode(t)||!this.containsNode(e))&&null!==this.findConnectingEdge(t,e)}edgeExists(t,e){return!(!this.containsNode(t)||!this.containsNode(e))&&this.traversePredecessors(t,(function(t){if(t===e)return!1}))}traverseNodes(t,e){const i=this.__nodes,n=i.length;for(let s=0;s<n;s++){const n=i[s];if(!1===t.call(e,n))return}}traverseSuccessors(t,e){const i=this.__edges;let n=0;const s=i.length;for(;n<s;n++){const s=i[n],r=s.first,a=s.second;if(r===t&&s.traversableForward()){if(!1===e(a,s))return}else if(a===t&&s.traversableBackward()&&!1===e(r,s))return}}traverseEdges(t){const e=this.__edges;let i=0;const n=e.length;for(;i<n;i++)if(!1===t(e[i]))return}traversePredecessors(t,e){const i=this.__edges;let n=0;const s=i.length;for(;n<s;n++){const s=i[n],r=s.first,a=s.second;if(a===t&&s.traversableForward()){if(!1===e(r,s))return!0}else if(r===t&&s.traversableBackward()&&!1===e(a,s))return!0}return!1}traverseAttachedEdges(t,e){const i=this.__edges;let n=0;const s=i.length;for(;n<s;n++){const s=i[n],r=s.first,a=s.second;if(r===t){if(!1===e(a,s))return}else if(a===t&&!1===e(r,s))return}}findTraversableEdge(t,e){const i=this.__edges,n=i.length;for(let s=0;s<n;s++){const n=i[s];if(n.first===t&&n.second===e&&2!==n.direction||n.second===t&&n.first===e&&1!==n.direction)return n}return null}findConnectingEdge(t,e){const i=this.__edges,n=i.length;for(let s=0;s<n;s++){const n=i[s];if(n.contains(t)&&n.contains(e))return n}return null}findTraversableEdges(t,e,i){const n=this.__edges;for(let s=0;s<n.length;s++){const r=n[s];if(r.validateTransition(t,e)&&!1===i(r))return}}getAttachedEdges(t){let e=0;const i=[],n=this.__edges,s=n.length;for(;e<s;e++){const s=n[e];s.contains(t)&&i.push(s)}return i}getNeighbours(t){const e=[],i=this.edges,n=i.length;for(let s=0;s<n;s++){const n=i[s],r=n.first,a=n.second;r!==t||1!==n.direction&&3!==n.direction?a!==t||2!==n.direction&&3!==n.direction||-1===e.indexOf(r)&&e.push(r):-1===e.indexOf(a)&&e.push(a)}return e}containsNode(t){return this.__nodes_set.has(t)}length(){const t=this.__edges;let e=0;for(let i=0;i<t.length;i++)e+=t[i].length;return e}addNode(t){this.__nodes_set.add(t),this.__nodes.push(t)}removeNode(t){if(!this.containsNode(t))return!1;const e=this.__nodes.indexOf(t);if(-1===e)return!1;{const i=this.getAttachedEdges(t),n=i.length;for(let t=0;t<n;t++){const e=i[t];this.removeEdge(e)}return this.__nodes.splice(e,1),this.__nodes_set.delete(t),!0}}hasNode(t){return this.containsNode(t)}addEdge(t){this.__edges.push(t),this.onChange.send1(t)}createEdge(t,e,i=3){const n=new Xb(t,e);return n.direction=i,this.addEdge(n),n}removeEdge(t){const e=this.__edges,i=e.indexOf(t);return i>=0&&(e.splice(i,1),this.onChange.send1(t),!0)}clear(){this.__edges=[],this.__nodes=[],this.__nodes_set.clear(),this.onChange.send0()}clone(){const t=new Zb;return t.copy(this),t}}class $b{constructor(){this.upgraders=new Map,this.serializers=new Map}registerAdapters(t){t.forEach((t=>{this.registerAdapter(t)}))}registerAdapter(t,e){if(void 0===e){const i=t.getClass();if("string"!=typeof i.typeName)throw new Error("className not specified, could not infer class name from the class itself");e=i.typeName}return!this.serializers.has(e)&&(this.serializers.set(e,t),!0)}removeAdapter(t){const e=this.serializers.get(t);return void 0!==e&&this.serializers.delete(t),e}getAdapter(t){return this.serializers.get(t)}registerUpgrader(t,e){if(e.getStartVersion()===e.getTargetVersion())throw new Error(`Upgrader for '${t}' start(=${e.getStartVersion()}) and target(=${e.getTargetVersion()}) versions are the same, must be different`);e.getStartVersion(),e.getTargetVersion();let i=this.upgraders.get(t);return void 0===i&&(i=new Zb,this.upgraders.set(t,i)),!i.hasNode(e)&&(i.addNode(e),i.traverseNodes((t=>{t!==e&&(t.getStartVersion()===e.getTargetVersion()?i.createEdge(t,e):t.getTargetVersion()===e.getStartVersion()&&i.createEdge(e,t))})),!0)}getUpgradersChain(t,e,i){if(e===i)return[];const n=this.upgraders.get(t);if(void 0===n)throw new Error(`No upgraders available for class '${t}', upgrade is required from from version ${e} to ${i}`);const s=[],r=[];n.traverseNodes((t=>{t.getStartVersion()===e&&s.push(t),t.getTargetVersion()===i&&r.push(t)}));let a=null,o=Number.POSITIVE_INFINITY;for(let t=0,e=s.length;t<e;t++){const e=s[t];for(let t=0,i=r.length;t<i;t++){const i=r[t],s=n.findPath(e,i);if(null!==s){const t=s.length;o>t&&(a=s,o=t)}}}return a}}$b.prototype.isBinarySerializationRegistry=!0;const Kb=[Gg.Finalizing,Gg.Initializing,Gg.Starting,Gg.Stopping];function Qb(t,e){const i=t.getState().getValue();return i===Gg.Initialized||i===Gg.Stopped?Promise.resolve():i===Gg.New||i===Gg.Finalized?(t.initialize(e),Promise.resolve()):i===Gg.Running?t.shutdown():Promise.reject(`Unsupported initial state '${i}'`)}class tS{constructor(t,e){this.__klass=e,this.__instance=t,this.__references=new of,this.dependency_references=new of,this.on={lastReleased:new l},this.__transition=Promise.resolve()}synchronize(){return this.__transition}transition(t,e){if(Kb.includes(t))return Promise.reject(`Requested state '${t}' is transient. Only steady states are allowed`);const i=this.__instance,n=this.__transition.then((()=>new Promise(((n,s)=>i.getState().getValue()===t?n():t===Gg.Initialized?Qb(i,e).then(n,s):t===Gg.Running?function(t,e){const i=t.getState().getValue();return i===Gg.Running?Promise.resolve():i===Gg.Initialized||i===Gg.Stopped?t.startup():i===Gg.New||i===Gg.Finalized?Qb(t,e).then((()=>t.startup())):Promise.reject(`Unsupported initial state '${i}'`)}(i,e).then(n,s):t===Gg.Finalized?function(t,e){const i=t.getState().getValue();return i===Gg.New||i===Gg.Finalized?Promise.resolve():i===Gg.Running?Qb(t,e).then((()=>t.finalize())):i===Gg.Stopped||i===Gg.Initialized?(t.finalize(),Promise.resolve()):Promise.reject(`Unsupported initial state '${i}'`)}(i,e).then(n,s):void s(`Unsupported target state '${t}'`)))));return this.__transition=n,n}async dispose(){const t=this.__instance,e=t.getState();e.getValue()===Gg.Running&&await t.shutdown(),e.getValue()!==Gg.Stopped&&e.getValue()!==Gg.Initialized||await t.finalize(),this.dependency_references.forEach((t=>t.release()))}__handle_reference_released(t){this.__references.removeOneOf(t)&&this.__references.isEmpty()&&this.on.lastReleased.send2(this,t)}getKlass(){return this.__klass}getReference(){const t=new fv;return t.onReleased.add(this.__handle_reference_released,this),t.bind(this.__instance),this.__references.add(t),t}get referenceCount(){return this.__references.length}get instance(){return this.__instance}}class eS extends Wg{constructor(){super(),this.__plugins=new Map,this.engine=null,this.__version=0}__getActivePluginInstances(){const t=[];for(const[e,i]of this.__plugins)i.referenceCount<=0||t.push(i.instance);return t}__getActivePluginContexts(){const t=[];for(const[e,i]of this.__plugins)i.referenceCount<=0||t.push(i);return t}async __transition_plugin_to_state(t,e){const i=t.instance;if(e===Gg.Initialized||e===Gg.Running){const t=i.dependencies;for(let i=0;i<t.length;i++){const n=t[i],s=this.__plugins.get(n),r=s.instance.getState().getValue();r!==Gg.Running&&(e===Gg.Running||r!==Gg.Initialized)&&await s.transition(e,this.engine)}}await t.transition(e,this.engine)}async __transition_active_plugins_to(t){let e;do{e=this.__version;const i=this.__getActivePluginContexts(),n=i.length,s=[];for(let e=0;e<n;e++){const n=i[e],r=this.__transition_plugin_to_state(n,t);s.push(r)}await Promise.all(s)}while(e!==this.__version)}__handle_last_plugin_reference_release(t){this.__version++;const e=t.getKlass();this.__plugins.delete(e)&&t.dispose()}initialize(t){this.engine=t,super.initialize();const e=this.__getActivePluginInstances(),i=e.length;for(let n=0;n<i;n++)e[n].initialize(t)}finalize(){super.finalize();const t=this.__getActivePluginInstances(),e=t.length;for(let i=0;i<e;i++)t[i].finalize()}async startup(){return super.startup(),this.__transition_active_plugins_to(Gg.Running)}async shutdown(){return super.shutdown(),this.__transition_active_plugins_to(Gg.Finalized)}async acquire(t){if(!function(t,e){let i=t;for(;void 0!==i;){if(i===e||i instanceof e)return!0;i=i.prototype}return!1}(t,Hg))throw new Error("PluginClass is not a subclass of EnginePlugin");let e,i=this.__plugins.get(t);if(void 0===i){this.__version++;const n=new t;i=new tS(n,t),i.on.lastReleased.add(this.__handle_last_plugin_reference_release,this),this.__plugins.set(t,i),e=i.getReference();const s=await this.acquireMany(n.dependencies);i.dependency_references.addAll(s);const r=this.getState().getValue(),a=this.engine;await i.transition(r,a)}else e=i.getReference(),await i.synchronize();return e}async acquireMany(t){const e=t.map(this.acquire,this);return await Promise.all(e)}getPlugin(t){const e=this.__getActivePluginInstances(),i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.constructor===t)return i}}getById(t){const e=this.__getActivePluginInstances(),i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.id===t)return i}}}class iS{constructor(t){this.id=t,this.parent=null}computePath(){const t=[];let e=this;for(;null!==e;)t.unshift(e.id),e=e.parent;return t}}class nS extends iS{constructor(t,e,i=Jd,n={transient:!1}){super(t);const s=this;this.read=e,this.write=function(t){const e=i(t);return void 0!==e&&"function"==typeof e.then?e.then((()=>s.on.written.dispatch(t)),(e=>s.on.writeFailed.dispatch(t,e))):s.on.written.dispatch(t),e},this.settings=n,this.isTransient=!0===n.transient,this.on={written:new l,writeFailed:new l,settingsUpdated:new l}}setSetting(t,e){this.settings[t]=e,this.on.settingsUpdated.send2(t,e)}toJSON(){let t=this.read();switch(typeof t){case"number":case"boolean":case"string":return t;default:return null}}fromJSON(t){this.write(t)}}class sS extends iS{constructor(t){super(t),this.children=[]}resolve(t){let e=this;for(let i=0;i<t.length;i++){const n=t[i],s=e;if(e=s.children.find((t=>t.id===n)),void 0===e)throw new Error(`Failed to resolve path at '${n}'[${i}], in path: [${t.join(", ")}], available options:[${s.children.map((t=>t.id)).join(", ")}]`)}return e}addChild(t){return void 0===this.getChildById(t.id)&&(this.children.push(t),t.parent=this,!0)}getChildById(t){return this.children.find((e=>e.id===t))}add(t,e,i,n){let s=new nS(t,e,i,n);return this.addChild(s),this}addGroup(t){let e=new sS(t);return this.addChild(e),e}toJSON(){const t={};return this.children.forEach((e=>{e.isTransient||(t[e.id]=e.toJSON())})),t}fromJSON(t){this.children.forEach((e=>{t.hasOwnProperty(e.id)&&e.fromJSON(t[e.id])}))}traverseOptions(t,e){this.children.forEach((function(i){!function(t){return"function"==typeof t.read}(i)?i.traverseOptions(t,e):t.call(e,i)}))}attachToStorage(t,e){const n=this,s=t;function r(){const t=function(t){let e="";try{!function(t,e){function n(t,i){e('"'+t+'":'),s(i)}function s(t){const r=typeof t;switch(r){case"object":null===t?e("null"):t instanceof Array||i(t)?function(t){e("[");const i=t.length;if(i>0){s(t[0]);for(let n=1;n<i;n++)e(","),s(t[n])}e("]")}(t):function(t){e("{");let i=0;for(let s in t)i++>0&&e(","),n(s,t[s]);e("}")}(t);break;case"number":case"boolean":case"string":e(JSON.stringify(t));break;case"undefined":s("null");break;default:throw new Error("Can not process object of type "+r)}}s(t)}(t,(function(t){e+=t}))}catch(t){throw t}return e}(n.toJSON());e.store(s,t,Jd,console.error,Jd)}new Promise((function(t,i){e.load(s,t,i)})).then((t=>{try{n.fromJSON(JSON.parse(t))}catch(t){}})).catch(console.error).finally((()=>{n.traverseOptions((t=>t.on.written.add(r)))}))}}sS.prototype.isOptionGroup=!0;class rS{record(t){throw new Error("Not implemented")}getLastRecord(){throw new Error("Not implemented")}computeStats(t){throw new Error("Not implemented")}clear(){throw new Error("Not implemented")}}class aS{constructor(t){this.size=t,this.head=0,this.tail=0,this.count=0,this.data=new Array(t)}resize(t){const e=new Array(t);this.data=e,this.size=t,this.count=ru(t,this.count),this.clear()}getHead(){return this.data[this.head-1]}getFromHead(t){let e=this.head-(t+1);for(;e<0;)e+=this.size;return this.data[e]}clear(){this.head=0,this.tail=0,this.count=0}push(t){const e=this.head;this.data[e]=t;const i=this.size,n=(e+1)%i;this.head=n,this.count===i?this.tail=(this.tail+1)%i:this.count++}shift(){if(0===this.count)return;const t=this.data[this.tail];return this.count--,this.tail=(this.tail+1)%this.size,t}removeElementByIndex(t){if(t>=this.count)return;const e=this.size,i=this.tail,n=this.count;for(let s=t;s<n;s++){const t=i+s,n=t%e,r=(t+1)%e;this.data[n]=this.data[r]}this.head--,this.count--}removeIf(t,e){const i=this.count,n=this.size,s=this.tail,r=this.data;for(let a=0;a<i;a++){const i=(s+a)%n,o=r[i];if(t.call(e,o))return this.removeElementByIndex(i),o}}forEach(t,e){const i=this.count,n=this.size,s=this.tail,r=this.data;for(let a=0;a<i;a++){const i=r[(s+a)%n];t.call(e,i)}}contains(t){return-1!==this.data.indexOf(t)}}class oS extends rS{constructor(t=100){super(),this.__data=new aS(t)}resize(t){this.__data.resize(t)}getLastRecord(){return this.__data.getHead()}record(t){this.__data.push(t)}computeStats(t){const e=this.__data,i=e.data,n=e.count;return 0===n?(t.mean=0,t.meadian=0,t.min=0,t.max=0,!1):(t.mean=Ju(i,0,n),t.meadian=function(t,e,i){const n=t.slice();return n.sort(Qd),n[0+(i-0)/2|0]}(i,0,n),t.max=function(t,e=0,i=t.length){let n=Number.NEGATIVE_INFINITY;for(let s=e;s<i;s++){const e=t[s];e>n&&(n=e)}return n}(i,0,n),t.min=function(t,e=0,i=t.length){let n=Number.POSITIVE_INFINITY;for(let s=e;s<i;s++){const e=t[s];e<n&&(n=e)}return n}(i,0,n),!0)}clear(){this.__data.clear()}}class lS{constructor(){this.data=new Map}clear(){this.data.forEach(((t,e)=>{t.clear()}))}list(){return Array.from(this.data.keys())}create({name:t,buffer_size:e=1e3}){const i=new oS(e);return this.add(t,i),i}add(t,e){this.data.set(t,e)}get(t){return this.data.get(t)}}class hS{constructor(t=15,e,i){this.__timeout=t,this.__handle=-1,this.__method=()=>{e.call(i)}}start(){-1!==this.__handle&&this.stop(),this.__handle=setInterval(this.__method,1e3*this.__timeout)}stop(){-1!==this.__handle&&(clearInterval(this.__handle),this.__handle=-1)}}class cS{constructor(){this.mean=0,this.meadian=0,this.max=0,this.min=0}}const uS=new class{constructor(){this.backends=[]}addBackend(t){return!this.backends.includes(t)&&(this.backends.push(t),!0)}removeBackend(t){const e=this.backends.indexOf(t);return-1!==e&&(this.backends.splice(e,1),!0)}log(t,e){const i=this.backends,n=i.length;for(let s=0;s<n;s++){const n=i[s];t>n.getLevel()||n.log(t,e)}}info(t){this.log(3,t)}warn(t){this.log(2,t)}error(t){this.log(1,t)}};function dS(){this.graphics_control_viewport_size=new Mm(!0),this.simulation_speed=new Id(1),this.input_mouse_sensitivity=new Id(5)}const pS="frame_delay",fS="render_time",mS="simulation_time";class _S{constructor(t,{entityManager:e}={}){this.platform=t,this.staticKnowledge=new Bb,this.plugins=new eS,this.performance=new lS,this.executor=new oy(1,10),this.__using_external_entity_manager=void 0!==e,this.__using_external_entity_manager?this.entityManager=e:this.entityManager=new b_,this.ticker=new fb,this.__performacne_monitor=new hS(15,(()=>{const t=this.performance,e=new cS,i=t.get(fS);i.computeStats(e);const n=(1e3*e.mean).toFixed(2),s=t.get(mS);s.computeStats(e);const r=(1e3*e.mean).toFixed(2),a=t.get(pS);a.computeStats(e);const o=(1/e.mean).toFixed(2);return i.clear(),s.clear(),a.clear(),`FPS: ${o}, RENDER: ${n}ms, SIMULATION: ${r}ms`})),this.__using_external_entity_manager||this.ticker.subscribe((t=>{const e=performance.now();this.entityManager.simulate(t);const i=(performance.now()-e)/1e3;this.performance.get(mS).record(i)})),this.initialize()}initialize(){this.performance.create({name:fS}),this.performance.create({name:mS}),this.performance.create({name:pS}),this.options=new sS("options"),this.classRegistry=new Yb,this.binarySerializationRegistry=new $b,this.settings=new dS,this.services={},this.storage=this.platform.getStorage(),this.assetManager=new by(this),this.localization=new Jb,this.localization.setAssetManager(this.assetManager);const t=window.innerWidth/3,e=window.innerHeight/3;this.camera=new js(45,t/e,1,50);const i=this.graphics=new ax(this.camera,this.entityManager);try{i.start()}catch(t){uS.info("Failed to start GraphicEngine: ",t)}this.inputEngine=new My(i.domElement,window);const n=new lx;n.volume=1,this.sound=n,this.gui=new Lb,this.sceneManager=new kx(this.entityManager,this.ticker.clock),this.initializeViews(),this.devices={pointer:new wx(this.viewStack.el),keyboard:new Cx(this.viewStack.el)},this.devices.pointer.start(),this.devices.keyboard.start(),this.initializeSettings(),uS.info("engine initialized"),this.renderingEnabled=!0,this.plugins.initialize(this)}get grid(){throw new Error("Deprecated, use systems/components to achieve the same functionality as before")}initializeViews(){const t=this.graphics.viewport,e=new Ey;e.addClass("game-view"),e.css({left:0,top:0,position:"absolute",pointerEvents:"none"}),t.css({pointerEvents:"auto"}),this.gameView=e,e.addChild(t),this.viewStack=new Db,this.viewStack.push(e,"game-view"),t.bindSignal(e.size.onChanged,t.size.set.bind(t.size)),e.on.linked.add((function(){t.size.copy(e.size)}))}initializeSettings(){uS.info("Initializing engine settings...");const t=this;function e(){let e=t.viewStack.el.parentElement;for(;null!==e&&void 0===e.innerWidth;)e=e.parentElement;null==e&&(e=window),t.viewStack.size.set(e.innerWidth,e.innerHeight)}this.settings.graphics_control_viewport_size.process((function(t){t?(e(),window.addEventListener("resize",e,!1)):window.removeEventListener("resize",e)})),uS.info("Engine settings initilized.")}benchmark(){let t=0;const e=Date.now();let i;for(;this.entityManager.simulate(1e-10),i=Date.now(),!(i-e>2e3);)t++;return t/((i-e)/1e3)}loadAssetList(t){const e=new zx,i=this.assetManager;return i.get(t,"json",(function(t){e.addAll(t.create()),e.load(i)})),e}render(){const t=this.graphics;if(t.autoDraw&&(t.needDraw=!0),t&&this.renderingEnabled&&t.needDraw){const e=this.performance,i=performance.now();t.render();const n=(performance.now()-i)/1e3;e.get(fS).record(n)}}start(){const t=this;this.assetManager.startup(),this.__performacne_monitor.start();const e=this.performance;return Promise.all([this.sound.start().then((function(){return new Promise((function(e,i){t.entityManager.startup(e,i)}))})),this.staticKnowledge.load(this.assetManager,this.executor),this.gui.startup(this),this.plugins.startup()]).then((function(){let i=performance.now();requestAnimationFrame((function n(){const s=performance.now();requestAnimationFrame(n),t.render();const r=(s-i)/1e3;i=s,e.get(pS).record(r)})),t.ticker.start({maxTimeout:200}),t.options.attachToStorage("lazykitty.komrade.options",t.storage),uS.info("engine started")}),(function(t){uS.error(`Engine Failed to start: ${t}`)}))}async stop(){this.__performacne_monitor.stop(),this.ticker.pause(),this.__using_external_entity_manager||await new Promise(((t,e)=>this.entityManager.shutdown(t,e))),await this.plugins.shutdown(),await this.gui.shutdown(),await this.assetManager.shutdown()}exit(){window.close()}requestExit(){return this.gui.confirmTextDialog({title:this.localization.getString("system_confirm_exit_to_system.title"),text:this.localization.getString("system_confirm_exit_to_system.text")}).then((()=>{this.exit()}))}}_S.prototype.isEngine=!0;const gS=2*Math.PI;function yS(t){let e=t%gS;return e=(e+gS)%gS,e>Math.PI&&(e-=gS),e}function vS(t,e){return Math.atan2(t,e)}function xS(t,e,i){return t[e+4*i]}const wS=Math.PI,bS=new pn,SS=[],MS=new S;function TS(t,e,i,n){const s=yS(i.pitch),r=yS(i.yaw),a=yS(i.roll),o=(a>=Math.PI/2-1e-4||a<=-(Math.PI/2-1e-4)?-1:1)*(s>Math.PI||s<0?-1:1)*t;n.yaw=r+o,n.pitch=s-e}const CS=Math.PI/360;class AS{constructor(t){this.target=new S,this.pitch=0,this.yaw=0,this.roll=0,this.distance=0,this.distanceMin=1,this.distanceMax=200,void 0!==t&&this.fromJSON(t)}setFromEyeAndTarget(t,e,i=S.up){bS.lookAt(e,t,i),function(t,e,i,n,s){{t[0]=vS(xS(e,1,0),xS(e,0,0));const i=Md(xS(e,2,2),xS(e,2,1));t[0]<0?(t[0]>0?t[0]-=wS:t[0]+=wS,t[1]=vS(-xS(e,2,0),-i)):t[1]=vS(-xS(e,2,0),i);const n=function(t){return Math.sin(t)}(t[0]),s=function(t){return Math.cos(t)}(t[0]);t[2]=vS(n*xS(e,0,2)-s*xS(e,1,2),s*xS(e,1,1)-n*xS(e,0,1))}}(SS,bS.elements),this.pitch=SS[2],this.yaw=SS[1],this.roll=SS[0],this.distance=t.distanceTo(e),this.target.copy(e)}equals(t){return this.target.equals(t.target)&&this.pitch===t.pitch&&this.yaw===t.yaw&&this.roll===t.roll&&this.distance===t.distance&&this.distanceMin===t.distanceMin&&this.distanceMax===t.distanceMax}copy(t){this.target.copy(t.target),this.pitch=t.pitch,this.yaw=t.yaw,this.roll=t.roll,this.distance=t.distance,this.distanceMax=t.distanceMax,this.distanceMin=t.distanceMin}clone(){const t=new AS;return t.copy(this),t}lerp(t,e,i){this.target.lerpVectors(t.target,e.target,i),this.pitch=p(t.pitch,e.pitch,i),this.yaw=p(t.yaw,e.yaw,i),this.roll=p(t.roll,e.roll,i),this.distance=p(t.distance,e.distance,i),this.distanceMin=p(t.distanceMin,e.distanceMin,i),this.distanceMax=p(t.distanceMax,e.distanceMax,i)}toJSON(){return{target:this.target.toJSON(),pitch:this.pitch,yaw:this.yaw,roll:this.roll,distance:this.distance,distanceMin:this.distanceMin,distanceMax:this.distanceMax}}fromJSON({distance:t=0,distanceMin:e=0,distanceMax:i=0,pitch:n=0,yaw:s=0,roll:r=0,target:a=S.zero}){this.distance=t,this.distanceMin=e,this.distanceMax=i,this.pitch=n,this.roll=r,this.yaw=s,this.target.fromJSON(a)}static fromJSON(t){const e=new AS;return e.fromJSON(t),e}}AS.typeName="TopDownCameraController",AS.pan=function(t,e,i,n,s,r,a=S.one){const o=n*Math.tan(s*CS)*2/i.clientHeight;!function(t,e,i,n){const s=e.matrix.elements;MS.set(s[0],s[1],s[2]),MS.multiplyScalar(-t),i._sub(MS.x*n.x,MS.y*n.y,MS.z*n.z)}(t.x*o,e,r,a),function(t,e,i,n){const s=e.matrix.elements;MS.set(s[4],s[5],s[6]),MS.multiplyScalar(t),i._sub(MS.x*n.x,MS.y*n.y,MS.z*n.z)}(t.y*o,e,r,a)},AS.rotate=TS;const ES={DIRECTION:0,SPOT:1,POINT:2,AMBIENT:3};class zS{constructor(){this.type=new Tm(ES.DIRECTION,ES),this.color=new Rp(1,1,1),this.intensity=new Id(1),this.angle=new Id(Math.PI/4),this.penumbra=new Id(.4),this.distance=new Id(1),this.castShadow=new Mm(!1),this.__threeObject=null,this.__fp_light=null}static fromJSON(t){const e=new zS;return e.fromJSON(t),e}fromJSON(t){void 0!==t.type&&this.type.fromJSON(t.type),void 0!==t.color?"string"==typeof t.color?this.color.parse(t.color):this.color.fromUint(t.color):this.color.setRGB(1,1,1),void 0!==t.intensity?this.intensity.fromJSON(t.intensity):this.intensity.set(1),void 0!==t.castShadow?this.castShadow.fromJSON(t.castShadow):this.castShadow.set(!1);const e=this.type.getValue();e===ES.SPOT&&(void 0!==t.angle&&this.angle.fromJSON(t.angle),void 0!==t.penumbra&&this.penumbra.fromJSON(t.penumbra)),e!==ES.SPOT&&e!==ES.POINT||(void 0!==t.distance?this.distance.fromJSON(t.distance):this.distance.set(1)),this.__threeObject=null}toJSON(){const t={type:this.type.toJSON(),color:this.color.toUint(),intensity:this.intensity.toJSON(),castShadow:this.castShadow.toJSON()},e=this.type.getValue();return e===ES.SPOT&&(t.angle=this.angle.toJSON(),t.penumbra=this.penumbra.toJSON()),e!==ES.SPOT&&e!==ES.POINT||(t.distance=this.distance.toJSON()),t}}zS.typeName="Light",zS.Type=ES;class IS{constructor(t){this.level=new Id(0),void 0!==t&&this.fromJSON(t),this.color=new Rp(0,.3,.5),this.shoreDepthTransition=new Tp(.7,2),this.shoreColor=new Rp(.584,.792,.85),this.waveSpeed=new Id(1.8),this.waveAmplitude=new Id(.3),this.waveFrequency=new Id(1),this.scattering=new Id(1.2),this.__shader=null,this.__threeObject=null,this.color.onChanged.add(this.writeShaderUniforms,this),this.shoreDepthTransition.onChanged.add(this.writeShaderUniforms,this),this.shoreColor.onChanged.add(this.writeShaderUniforms,this),this.waveSpeed.onChanged.add(this.writeShaderUniforms,this),this.waveAmplitude.onChanged.add(this.writeShaderUniforms,this),this.waveFrequency.onChanged.add(this.writeShaderUniforms,this),this.scattering.onChanged.add(this.writeShaderUniforms,this)}updateShaderForTerrain(t,e){const i=this.__shader;if(null===i)return;const n=t.size.x*t.gridScale,s=t.size.y*t.gridScale,r=new wl(t.samplerHeight.data,t.samplerHeight.width,t.samplerHeight.height,te,Bt);r.wrapS=Ct,r.wrapT=Ct,r.generateMipmaps=!1,r.minFilter=Nt,r.magFilter=Nt,r.flipY=!1,r.internalFormat="R32F",i.uniforms.tHeightTexture.value=r,i.uniforms.vHeightUv.value.set(-.25,-.25,e/n,e/s),i.uniforms.vHeightTextureResolution.value.set(t.samplerHeight.width,t.samplerHeight.height)}writeShaderUniforms(){const t=this.__shader;if(null===t)return;const e=t.uniforms;e.waterColor.value.setRGB(this.color.r,this.color.g,this.color.b),e.shoreColor.value.setRGB(this.shoreColor.r,this.shoreColor.g,this.shoreColor.b),e.fWaveSpeed.value=this.waveSpeed.getValue(),e.fWaveAmplitude.value=this.waveAmplitude.getValue(),e.fWaveFrequency.value=this.waveFrequency.getValue(),e.fScattering.value=this.scattering.getValue(),e.vShoreDepthTransition.value.set(this.shoreDepthTransition.min,this.shoreDepthTransition.max)}fromJSON(t){"number"==typeof t.level&&this.level.fromJSON(t.level),"object"==typeof t.color&&this.color.fromJSON(t.color)}toJSON(){return{level:this.level.toJSON(),color:this.color.toJSON()}}}IS.typeName="Water";class NS{constructor(){}getStorage(){throw new Error("Not implemented")}getAchievementGateway(){throw new Error("Not implemented")}pickDefaultLocale(t){throw new Error("Not implemented")}startup(){return Promise.resolve()}shutdown(){return Promise.resolve()}}class LS{constructor(){}storeBinary(t,e,i,n,s){this.store(t,e,i,n,s)}loadBinary(t,e,i,n){this.load(t,e,i,n)}promiseLoadBinary(t,e=Jd){return new Promise(((i,n)=>{this.loadBinary(t,i,n,e)}))}promiseStoreBinary(t,e,i=Jd){return new Promise(((n,s)=>{this.storeBinary(t,e,n,s,i)}))}store(t,e,i,n,s){throw new Error("Not Implemented")}load(t,e,i,n){throw new Error("Not Implemented")}list(t,e){throw new Error("Not Implemented")}promiseList(){return new Promise(((t,e)=>this.list(t,e)))}remove(t,e,i){throw new Error("Not implemented")}promiseRemove(t){return new Promise(((e,i)=>this.remove(t,e,i)))}contains(t,e,i){this.list((function(i){e(-1!==i.indexOf(t))}),i)}promiseContains(t){return new Promise(((e,i)=>this.contains(t,e,i)))}}const PS="readwrite",FS="main";class DS extends LS{constructor(t){super(),this.db=new Promise((function(e,i){const n=indexedDB.open(t,1);n.addEventListener("success",(function(t){e(n.result)})),n.addEventListener("error",i),n.addEventListener("upgradeneeded",(t=>{t.target.result.createObjectStore(FS)}),!0)}))}remove(t,e,i){const n=this.db.then((n=>{const s=n.transaction(FS,PS).objectStore(FS).delete(t);"function"==typeof e&&s.addEventListener("success",(t=>{e(t.target.result)})),"function"==typeof i&&s.addEventListener("error",(t=>{i(t)}))}));"function"==typeof i&&n.catch(i)}load(t,e,i,n){this.db.then((n=>{const s=n.transaction(FS,"readonly").objectStore(FS).get(t);s.addEventListener("success",(t=>{e(t.target.result)})),s.addEventListener("error",(t=>{i(t)}))})).catch(i)}store(t,e,i,n,s){const r=this.db.then((s=>{const r=s.transaction(FS,PS).objectStore(FS).put(e,t);"function"==typeof i&&r.addEventListener("success",(t=>{i(t.target.result)})),"function"==typeof n&&r.addEventListener("error",(t=>{n(t)}))}));"function"==typeof n&&r.catch(n)}list(t,e){this.db.then((i=>{const n=i.transaction(FS,IDBTransaction.READ_ONLY).objectStore(FS).getAllKeys();n.addEventListener("success",(e=>{t(e.target.result)})),n.addEventListener("error",(t=>{e(t)}))})).catch(e)}}class OS{constructor(){}getUnlocked(){throw new Error("Not implemented")}unlock(t){throw new Error("Not implemented")}}class RS extends OS{constructor(t,e="achievements"){super(),this.storage=t,this.key=e,this.last=Promise.resolve()}getUnlocked(){return new Promise(((t,e)=>{this.storage.load(this.key,(e=>{t(void 0===e?[]:e)}),e,Jd)}))}unlock(t){const e=this.storage,i=this.last.finally((()=>new Promise(((i,n)=>{e.load(this.key,(s=>{let r;if(void 0!==s){if(s.includes(t))return void i();r=s.slice()}else r=[];r.push(t),e.store(this.key,r,i,n,Jd)}),n,Jd)}))));return this.last=i,i}}function kS(){const t={};if(void 0===window)return t;const e=window.location.hash,i=/([a-zA-Z0-9\-\_]+)\=([a-zA-Z0-9\-\_]+)/g;let n;for(;null!==(n=i.exec(e));){const e=n[1],i=n[2];t[e]=i}return t}class US extends NS{constructor({storageKey:t="@woosh/meep/app"}={}){super(),this.storage=new DS(t,this.services),this.storage.compressionEnabled=!1,this.achievements=new RS(this.storage)}getStorage(){return this.storage}getAchievementGateway(){return this.achievements}pickDefaultLocale(t){const e=kS();let i;return i=void 0!==e.lang?e.lang:function(){const e=window.navigator.languages;function i(t){const i=e.length,n=e.indexOf(t);if(-1!==n)return 1.1*(i-n);{const n=t.split("-")[0];for(let t=0;t<i;t++){const s=e[t].split("-")[0];if(n.toLowerCase()===s.toLowerCase())return 1*(i-t)}}return 0}const n=function(t,e){let i,n;const s=t.length;if(0!==s){i=t[0],n=e(i);for(let r=1;r<s;r++){const s=t[r],a=e(s);a>n&&(n=a,i=s)}return i}}(t.map((t=>({key:t,score:i(t)}))),(t=>t.score));return 0===n.score?"en-gb":n.key}(),i}}class BS{constructor(t){this.values=[],void 0!==t&&this.add(t)}get count(){return this.values.length}get(t){return this.values[t]}set name(t){this.clear(),this.add(t)}get name(){return this.getFirst()}clear(){this.values.splice(0,this.values.length)}add(t){return!this.contains(t)&&(this.values.push(t),!0)}addAll(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.add(e)}}getFirst(){return this.values[0]}contains(t){return-1!==this.values.indexOf(t)}containsAll(t){const e=t.length,i=this.values,n=i.length;let s=0,r=0;t:for(;s<e;s++){const e=t[s];for(r=0;r<n;r++)if(i[r]===e)continue t;return!1}return!0}containsOneOf(t){const e=this.values,i=t,n=e.length,s=i.length;for(let t=0;t<n;t++){const n=e[t];for(let t=0;t<s;t++)if(n===i[t])return!0}return!1}getValues(){return this.values}traverse(t,e){this.values.forEach(t,e)}hash(){let t=0;const e=this.values,i=e.length;for(let n=0;n<i;n++)t=(t<<5)-t+Nd(e[n]),t|=0;return t}equals(t){const e=this.values,i=t.values,n=e.length;if(n!==i.length)return!1;for(let t=0;t<n;t++)if(e[t]!==i[t])return!1;return!0}toJSON(){return this.values}fromJSON(t){"string"==typeof t?(this.clear(),this.add(t)):Array.isArray(t)&&(this.values=t)}static find(t,e){const i=[];return e.traverseComponents(BS,((e,n)=>{e.containsAll(t)&&i.push(n)})),i}static fromOne(t){const e=new BS;return e.add(t),e}static fromJSON(t){const e=new BS;return e.fromJSON(t),e}}BS.typeName="Tag";class VS{constructor({path:t,listener:e,exclusive:i=!1}){this.path=t,this.listener=e,this.exclusive=i}}class GS{constructor(t=[]){this.mapping=new of;const e=t.map((t=>new VS(t)));this.mapping.addAll(e),this.on={unlinked:new l}}static from(t){const e=new GS,i=t.length;for(let n=0;n<i;n++){const i=t[n],s=new VS(i);e.mapping.add(s)}return e}}GS.typeName="InputController",GS.serializable=!1;const WS=new S;class HS extends bm{constructor(){super(),this.enabled=new Hd(!0),this.dependencies=[AS]}__visit_camera_entity(t,e){const i=this.entityManager.dataset.getComponent(e,Au);void 0!==i&&function(t,e){const i=e.rotation,n=y(t.distance,t.distanceMin,t.distanceMax),s=t.target,r=t.yaw,a=t.pitch,o=t.roll;i.__setFromEuler(a,r,o,"ZYX"),WS.copy(S.forward),WS.applyQuaternion(i),WS.multiplyScalar(-n),WS.add(s),e.position.copy(WS)}(t,i)}update(t){const e=this.entityManager.dataset;this.enabled.get()&&null!==e&&e.traverseComponents(AS,this.__visit_camera_entity,this)}}const jS=function(){const t=[new Di(-1,-1,0),new Di(-1,-1,0),new Di(-1,1,0),new Di(-1,1,0),new Di(1,-1,0),new Di(1,-1,0),new Di(1,1,0),new Di(1,1,0)];return function(e,i,n,s){t[0].set(-1,-1,e),t[1].set(-1,-1,i),t[2].set(-1,1,e),t[3].set(-1,1,i),t[4].set(1,-1,e),t[5].set(1,-1,i),t[6].set(1,1,e),t[7].set(1,1,i);let r=Number.POSITIVE_INFINITY,a=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY;for(let e=0;e<8;e++){const i=t[e];i.unproject(n),i.x<r&&(r=i.x),i.x>l&&(l=i.x),i.y<a&&(a=i.y),i.y>h&&(h=i.y),i.z<o&&(o=i.z),i.z>c&&(c=i.z)}s(r,a,o,l,h,c)}}(),qS=function(){const t=[new Di(-1,-1,0),new Di(-1,-1,0),new Di(-1,1,0),new Di(-1,1,0),new Di(1,-1,0),new Di(1,-1,0),new Di(1,1,0),new Di(1,1,0)];return function(e,i,n,s,r){t[0].set(-1,-1,e),t[1].set(-1,-1,i),t[2].set(-1,1,e),t[3].set(-1,1,i),t[4].set(1,-1,e),t[5].set(1,-1,i),t[6].set(1,1,e),t[7].set(1,1,i);let a=Number.POSITIVE_INFINITY,o=Number.POSITIVE_INFINITY,l=Number.POSITIVE_INFINITY,h=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY,u=Number.NEGATIVE_INFINITY;for(let e=0;e<8;e++){const i=t[e];i.unproject(n),i.applyMatrix4(s),i.x<a&&(a=i.x),i.x>h&&(h=i.x),i.y<o&&(o=i.y),i.y>c&&(c=i.y),i.z<l&&(l=i.z),i.z>u&&(u=i.z)}r.setBounds(a,o,l,h,c,u)}}();var JS={project:qS,unproject:function(t,e,i,n,s,r,a,o){const l=[new Di(t,e,i),new Di(t,e,r),new Di(t,s,i),new Di(t,s,r),new Di(n,e,i),new Di(n,e,r),new Di(n,s,i),new Di(n,s,r)];let h=Number.POSITIVE_INFINITY,c=Number.POSITIVE_INFINITY,u=Number.POSITIVE_INFINITY,d=Number.NEGATIVE_INFINITY,p=Number.NEGATIVE_INFINITY,f=Number.NEGATIVE_INFINITY;l.forEach((function(t){t.project(a),t.x<h&&(h=t.x),t.x>d&&(d=t.x),t.y<c&&(c=t.y),t.y>p&&(p=t.y),t.z<u&&(u=t.z),t.z>f&&(f=t.z)})),o(h,c,u,d,p,f)},projectInWorldSpace:jS};class YS{constructor(t){this.light=t,this.address=0,this.bvh_leaf_main=new ld(this,0,0,0,0,0,0)}compare(t){return this.light.compare(t.light)}update(){const t=this.bvh_leaf_main;this.light.getAABB(t),null!==t.parentNode&&t.parentNode.bubbleRefit()}link(){this.update(),this.light.onDimensionChanged(this.update,this)}unlink(){this.light.offDimensionChanged(this.update,this),this.bvh_leaf_main.disconnect()}}const XS=new ArrayBuffer(84),ZS=new Uint8Array(XS,0,43);ZS[21]=0,ZS[37]=1,ZS[25]=2,ZS[41]=3,ZS[22]=4,ZS[38]=5,ZS[26]=6,ZS[42]=7;const $S=new Uint8Array(XS,43,41);function KS(t,e,i,n,s,r){let a=0,o=0,l=0;for(;a<6;a++){const s=4*a,h=r[s]*t+r[s+1]*e+r[s+2]*i+r[s+3];if(h<0){if(!(h>=-n))return!1;o++,l|=1<<a}}return o<2||function(t,e,i,n,s,r,a){const o=t*t;if(3===s){const t=3*ZS[r];if(R_(a[t],a[t+1],a[t+2],e,i,n)>o)return!1}else if(2===s){const t=$S[r],s=3*(7&t),l=3*(t>>3&7),h=function(t,e,i,n,s,r,a,o,l){const h=n-t,c=s-e,u=r-i,d=Ep((h*(a-t)+c*(o-e)+u*(l-i))/(h*h+c*c+u*u));return R_(a,o,l,h*d+t,c*d+e,u*d+i)}(a[s],a[s+1],a[s+2],a[l],a[l+1],a[l+2],e,i,n);if(h>o)return!1}return!0}(n,t,e,i,o,l,s)}$S[5]=8,$S[6]=44,$S[9]=26,$S[10]=62,$S[20]=32,$S[24]=50,$S[36]=41,$S[40]=59,$S[17]=16,$S[18]=52,$S[33]=25,$S[34]=61;const QS=new S,tM=new S;function eM(t,e,i,n,s,r,a,o,l,h,c,u){QS._crossVectors(t,e,i,o,l,h),tM._crossVectors(QS.x,QS.y,QS.z,o,l,h);const d=u*Math.cos(c),p=u*Math.sin(c);QS.set(s+d*o+p*tM.x,r+d*l+p*tM.y,a+d*h+p*tM.z);let f=0;return Ad(QS.x,QS.y,QS.z,1,t,e,i,n)>=0?f+=1:f-=1,Ad(s,r,a,1,t,e,i,n)>=0?f+=1:f-=1,f}function iM(t,e,i){for(let e=0;e<6;e++){const n=4*e;if(eM(i[n],i[n+1],i[n+2],i[n+3],t.position.x,t.position.y,t.position.z,t.direction.x,t.direction.y,t.direction.z,t.angle.getValue(),t.distance.getValue())<0)return!1}return!0}const nM=[];let sM=0;function rM(t,e,i,n,s){let r=0,a=0;const o=sM;nM[sM]=i,sM++;t:for(;sM-- >o;){const i=nM[sM];if(!0===i.isBinaryNode){for(a=0;a<6;a++){const t=4*a;if(Zu(n[t],n[t+1],n[t+2],n[t+3],i.x0,i.y0,i.z0,i.x1,i.y1,i.z1)<0)continue t}null!==i.right&&(nM[sM]=i.right,sM++),null!==i.left&&(nM[sM]=i.left,sM++)}else{const a=i.object,o=a.light;if(o.isPointLight){const t=o.position;if(!KS(t.x,t.y,t.z,o.radius.getValue(),s,n))continue}else if(o.isSpotLight&&!iM(o,0,n))continue;t[e+r]=a,r++}}return sM=o,r}function aM(t,e,i,n,s){const r=i.normal,a=n.normal,o=s.normal;return Oy(t,e,r.x,r.y,r.z,i.constant,a.x,a.y,a.z,n.constant,o.x,o.y,o.z,s.constant)}function oM(t,e,i,n){const s=t[e],r=t[e+1],a=t[e+2],o=t[e+3],l=-t[e+4],h=-t[e+5],c=-t[e+6],u=-t[e+7];i[n]=s,i[n+1]=r,i[n+2]=a,i[n+3]=o,i[n+4]=l,i[n+5]=h,i[n+6]=c,i[n+7]=u}rM.iteration_count=0,rM.rejection_count=0,rM.rejection_sphere_count=0,rM.plane_tests=0,rM.plane_tests_early_exits=0,rM.checks_sphere=0,rM.checks_sphere_plane=0,rM.checks_sphere_frustum_corner=0,rM.checks_sphere_frustum_edge=0;const lM=new Qs,hM=new Di,cM=new Di,uM=new Di;function dM(t,e,i){const n=3*i,s=e[n],r=e[n+1],a=e[n+2];t.set(s,r,a)}function pM(t,e,i,n,s,r){dM(hM,t,e),dM(cM,t,i),dM(uM,t,n),lM.setFromCoplanarPoints(hM,cM,uM),s[r]=lM.normal.x,s[r+1]=lM.normal.y,s[r+2]=lM.normal.z,s[r+3]=lM.constant}const fM={Uint:0,Int:1,Float:2};function mM(t,e){if(t===fM.Uint){if(e<=8)return Nu.Uint8;if(e<=16)return Nu.Uint16;if(e<=32)return Nu.Uint32}else if(t===fM.Int){if(e<=8)return Nu.Int8;if(e<=16)return Nu.Int16;if(e<=32)return Nu.Int32}else if(t===fM.Float){if(e<=32)return Nu.Float32;if(e<=64)return Nu.Float64}throw new Error(`Unsupported numeric type(=${t}) and precision(=${e}) combination`)}function _M(t){switch(t){case Nu.Uint8:return Ft;case Nu.Uint16:return Rt;case Nu.Uint32:return Ut;case Nu.Int8:return Dt;case Nu.Int16:return Ot;case Nu.Int32:return kt;case Nu.Float16:return Vt;case Nu.Float32:case Nu.Float64:return Bt;default:throw new Error(`Unsupported data type '${t}'`)}}class gM{constructor(){this.__channel_count=1,this.size=1,this.__precision=8,this.__type=fM.Uint,this.__texture=new wl(new Uint8Array(0),0,0),this.__texture.image.width=0,this.__texture.image.height=0,this.__texture.type=Ft,this.__texture.format=te,this.__texture.magFilter=Et,this.__texture.minFilter=Et,this.__texture.wrapS=Ct,this.__texture.wrapT=Ct,this.__texture.generateMipmaps=!1,this.needsRebuild=!1,this.__height=0,this.__data_type=Nu.Uint8}get concrete_type(){return this.__data_type}set channel_count(t){this.__channel_count!==t&&(this.__channel_count=t,this.needsRebuild=!0)}get channel_count(){return this.__channel_count}update(){this.needsRebuild&&this.build()}set type(t){this.__type=t,this.__update_data_type()}get type(){return this.__type}get precision(){return this.__precision}set precision(t){this.__precision=t,this.__update_data_type()}dispose(){this.__texture.dispose()}__update_data_type(){const t=mM(this.__type,this.__precision);t!==this.__data_type&&(this.__data_type=t,this.needsRebuild=!0)}build(t=!0){const e=this.__texture,i=e.image.data,n=i.length,s=128*this.__height*this.__channel_count,r=new(0,Pu[this.__data_type])(s);e.format=function(t,e){if(t===fM.Uint||t===fM.Int)return function(t){switch(t){case 1:return ee;case 2:return ne;case 3:return se;case 4:return re;default:throw new Error(`Unsupported channel count '${t}'`)}}(e);if(t===fM.Float)return Gf(e);throw new Error(`Unsupported numeric type '${t}'`)}(this.__type,this.__channel_count),e.type=_M(this.__data_type),e.internalFormat=Wf(this.__data_type,this.channel_count),t&&(n<s?r.set(i):r.set(i.slice(0,s))),e.dispose(),e.image.height=this.__height,e.image.width=128,e.image.data=r,e.needsUpdate=!0,this.needsRebuild=!1}getTexture(){return this.__texture}resize(t){this.size=t;const e=Eu(Math.ceil(t/128),1),i=this.__texture.image.height;return i<e?(this.__height=Math.ceil(1.05*e),this.needsRebuild=!0,!0):.5*i>e&&(this.__height=e,this.needsRebuild=!0,!0)}getTextureByteSize(){const t=im[this.__data_type],e=this.__texture.image;return t*e.width*e.height*this.__channel_count}}const yM=24,vM=28;function xM(t,e,i,n){const s=t.getFloat32(i),r=t.getFloat32(i+4),a=t.getFloat32(i+8),o=t.getFloat32(i+12),l=t.getFloat32(i+16),h=t.getFloat32(i+20),c=t.getFloat32(n),u=t.getFloat32(n+4),d=t.getFloat32(n+8),p=t.getFloat32(n+12),f=t.getFloat32(n+16),m=t.getFloat32(n+20),_=ru(s,c),g=ru(r,u),y=ru(a,d),v=Eu(o,p),x=Eu(l,f),w=Eu(h,m);t.setFloat32(e,_),t.setFloat32(e+4,g),t.setFloat32(e+8,y),t.setFloat32(e+12,v),t.setFloat32(e+16,x),t.setFloat32(e+20,w)}function wM(t,e,i){const n=t.getFloat32(i),s=t.getFloat32(i+4),r=t.getFloat32(i+8);t.setFloat32(e,n),t.setFloat32(e+4,s),t.setFloat32(e+8,r),t.setFloat32(e+12,n),t.setFloat32(e+16,s),t.setFloat32(e+20,r)}function bM(t,e,i){const n=t.getFloat32(e),s=t.getFloat32(e+4),r=t.getFloat32(e+8);return Xu((n+t.getFloat32(e+12))/2,(s+t.getFloat32(e+16))/2,(r+t.getFloat32(e+20))/2)}const SM=[],MM=[],TM=[],CM=[];class AM{constructor(){this.__data_buffer=new ArrayBuffer(320),this.__data_uint8=new Uint8Array(this.__data_buffer),this.__data_view=new DataView(this.__data_buffer),this.__node_count_binary=0,this.__node_count_leaf=0}getTotalBoxCount(){return this.__node_count_binary+this.__node_count_leaf}getBinaryNodeCount(){return this.__node_count_binary}getLeafNodeCount(){return this.__node_count_leaf}getLeafBlockAddress(){return this.__node_count_binary*yM}getDataView(){return this.__data_view}initialize_structure(){const t=this.__node_count_binary*yM+this.__node_count_leaf*vM;this.__data_buffer.byteLength<t&&(this.__data_buffer=new ArrayBuffer(t),this.__data_uint8=new Uint8Array(this.__data_buffer),this.__data_view=new DataView(this.__data_buffer))}setLeafCount(t){this.__node_count_leaf=t;const e=_y(t);this.__node_count_binary=t<=1?e:e-1}setLeafData(t,e,i,n,s,r,a,o){const l=t*vM+this.__node_count_binary*yM,h=this.__data_view;h.setFloat32(l,i),h.setFloat32(l+4,n),h.setFloat32(l+8,s),h.setFloat32(l+12,r),h.setFloat32(l+16,a),h.setFloat32(l+20,o),h.setUint32(l+24,e)}readBounds(t,e,i){const n=this.__data_view;for(let s=0;s<6;s++)e[i+s]=n.getFloat32(t+4*s)}readLeafPayload(t){const e=this.getLeafBlockAddress()+t*vM+24;return this.__data_view.getUint32(e)}compute_total_surface_area(){let t=0;const e=new Float32Array(6);for(let i=0;i<this.getTotalBoxCount();i++){let n;n=i<this.__node_count_binary?i*yM:(i-this.__node_count_binary)*vM+this.getLeafBlockAddress(),this.readBounds(n,e,0),t+=fd(e[0],e[1],e[2],e[3],e[4],e[5])}return t}__compute_bounds_area_of_3_boxes(t,e,i){return this.readBounds(t,SM,0),this.readBounds(e,MM,0),this.readBounds(i,TM,0),fd(Pp(SM[0],MM[0],TM[0]),Pp(SM[1],MM[1],TM[1]),Pp(SM[2],MM[2],TM[2]),am(SM[3],MM[3],TM[3]),am(SM[4],MM[4],TM[4]),am(SM[5],MM[5],TM[5]))}__fitness_function_should_swap_leaves_sah(t,e){const i=Eu(t-1,0),n=ru(t+1,this.__node_count_leaf-1),s=this.getLeafBlockAddress(),r=t*vM+s,a=i*vM+s,o=n*vM+s,l=Eu(e-1,0),h=ru(e+1,this.__node_count_leaf-1),c=e*vM+s,u=l*vM+s,d=h*vM+s;return this.__compute_bounds_area_of_3_boxes(a,r,o)+this.__compute_bounds_area_of_3_boxes(u,c,d)-(this.__compute_bounds_area_of_3_boxes(a,c,o)+this.__compute_bounds_area_of_3_boxes(u,r,d))}sort_bubble_sah(){const t=this.__node_count_leaf;for(let e=0;e<t;e++)for(let i=e+1;i<t;i++)this.__fitness_function_should_swap_leaves_sah(e,i)>0&&this.__swap_leaves(e,i)}sort_morton(t){const e=this.__node_count_binary*yM;if(this.__node_count_leaf<2)return;let i,n,s=2;CM[0]=0,CM[1]=this.__node_count_leaf-1;const r=this.__data_view;for(;s>0;){s-=2;const t=CM[s+1],a=CM[s];i=a,n=t;const o=bM(r,(a+t>>1)*vM+e);for(;i<=n;){for(;bM(r,i*vM+e)<o;)i++;for(;bM(r,n*vM+e)>o;)n--;i<=n&&(i!==n&&this.__swap_leaves(i,n),i++,n--)}a<n&&(CM[s++]=a,CM[s++]=n),i<t&&(CM[s++]=i,CM[s++]=t)}}__swap_leaves(t,e){const i=this.getLeafBlockAddress();!function(t,e,i,n,s){let r,a,o;for(o=0;o<s;o++){r=e+o,a=n+o;const s=i[a];i[a]=t[r],t[r]=s}}(this.__data_uint8,t*vM+i,this.__data_uint8,e*vM+i,vM)}build(){const t=this.__node_count_binary,e=t*yM;let i,n,s,r,a=Math.floor(Math.log(t)/Math.log(2));s=Math.pow(2,a),n=(s-1)*yM;const o=this.__node_count_leaf;for(i=0;i<s;i++){const t=2*i,s=t+1,r=e+t*vM,a=e+s*vM;s<o?xM(this.__data_view,n,r,a):t<o?Rd(l=this.__data_uint8,r,l,n,24):wM(this.__data_view,n,n-yM),n+=yM}var l;for(a--;a>=0;a--)for(s=Math.pow(2,a),r=s-1,i=0;i<s;i++){const t=1+(r<<1),e=r*yM,i=t*yM,n=(t+1)*yM;xM(this.__data_view,e,i,n),r++}}}class EM extends Vp{constructor(t,e,i,n){super(t,e,i,n),this.data=null,this.parentNode=null}disconnect(){const t=this.parentNode;if(null===t)return;const e=t.data,i=e.indexOf(this);e.splice(i,1);let n=t;for(;null!==n;)n.treeDataCount--,n=n.parentNode;this.parentNode.balanceBubbleUp(),this.parentNode=null}resize(t,e,i,n){this.x0=t,this.y0=e,this.x1=i,this.y1=n;const s=this.parentNode;if(null===s)return;let r=s;(this.x0<r.x0||this.x1>=r.x1||this.y0<r.y0||this.y1>=r.y1)&&(this.disconnect(),r.insertDatum(this))}move(t,e){const i=this.x0+t,n=this.y0+e,s=this.x1+t,r=this.y1+e;this.resize(i,n,s,r)}}EM.prototype.isQuadTreeDatum=!0;class zM extends Vp{constructor(t=0,e=0,i=0,n=0){super(t,e,i,n),this.topLeft=null,this.topRight=null,this.bottomLeft=null,this.bottomRight=null,this.parentNode=null,this.treeDataCount=0,this.data=[]}balance(){const t=this.data.length,e=this.isSplit();return t>16&&!e?(this.split(),1):this.treeDataCount<8&&e?(this.merge(),2):0}balanceBubbleUp(){if(2===this.balance()){let t=this.parentNode;for(;null!==t&&2===t.balance();)t=t.parentNode}}resize(t,e,i,n){this.x0===t&&this.y0===e&&this.x1===i&&this.y1===n||(this.isSplit()&&this.merge(),this.x0=t,this.y0=e,this.x1=i,this.y1=n,this.balance())}add(t,e,i,n,s){const r=new EM(e,i,n,s);return r.data=t,this.insertDatum(r),r}insertDatum(t){const e=this.x0,i=this.y0,n=this.x1,s=this.y1;if(t.x0<e||t.x1>n||t.y0<i||t.y1>s)null===this.parentNode?(this.resize(ru(e,t.x0),ru(i,t.y0),Eu(n,t.x1),Eu(s,t.y1)),this.addDatum(t)):this.parentNode.insertDatum(t);else{if(!this.isSplit()){if(!(this.treeDataCount>=16))return void this.addDatum(t);this.split()}const r=(e+n)/2,a=(i+s)/2;t.y1<a?t.x1<r?this.topLeft.insertDatum(t):t.x0>=r?this.topRight.insertDatum(t):this.addDatum(t):t.y0>=a?t.x1<r?this.bottomLeft.insertDatum(t):t.x0>=r?this.bottomRight.insertDatum(t):this.addDatum(t):this.addDatum(t)}}addDatum(t){this.treeDataCount++,this.data.push(t),t.parentNode=this;let e=this.parentNode;for(;null!==e;)e.treeDataCount++,e=e.parentNode}isSplit(){return null!==this.topLeft}split(){const t=this.x0,e=this.y0,i=this.x1,n=this.y1,s=(t+i)/2,r=(e+n)/2;this.topLeft=new zM(t,e,s,r),this.topLeft.parentNode=this,this.topRight=new zM(s,e,i,r),this.topRight.parentNode=this,this.bottomLeft=new zM(t,r,s,n),this.bottomLeft.parentNode=this,this.bottomRight=new zM(s,r,i,n),this.bottomRight.parentNode=this,this.pushDataDown(),this.topLeft.balance(),this.topRight.balance(),this.bottomLeft.balance(),this.bottomRight.balance()}pullDataUp(){this.topLeft.traversePreOrder(this.absorbDataFrom,this),this.topRight.traversePreOrder(this.absorbDataFrom,this),this.bottomLeft.traversePreOrder(this.absorbDataFrom,this),this.bottomRight.traversePreOrder(this.absorbDataFrom,this)}absorbDataFrom(t){const e=this.data,i=t.data,n=i.length;for(let t=0;t<n;t++){const n=i[t];n.parentNode=this,e.push(n)}t.treeDataCount=0,t.data=[]}pushDataDown(){const t=this.data;let e=t.length,i=0;const n=this.x0,s=this.y0,r=.5*(n+this.x1),a=.5*(s+this.y1);for(;i<e;i++){const n=t[i];let s;if(n.y1<a)if(n.x1<r)s=this.topLeft;else{if(!(n.x0>=r))continue;s=this.topRight}else{if(!(n.y0>=a))continue;if(n.x1<r)s=this.bottomLeft;else{if(!(n.x0>=r))continue;s=this.bottomRight}}s.data.push(n),s.treeDataCount++,t.splice(i,1),n.parentNode=s,i--,e--}}merge(){this.pullDataUp(),this.topLeft=null,this.topRight=null,this.bottomLeft=null,this.bottomRight=null}clear(){this.data=[],this.treeDataCount=0,this.topLeft=null,this.topRight=null,this.bottomLeft=null,this.bottomRight=null}getRawData(t){this.traverseData((e=>{const i=e.data;t.push(i)}))}traverseData(t,e){this.traversePreOrder((i=>{const n=i.data,s=n.length;for(let i=0;i<s;i++){const s=n[i];t.call(e,s)}}))}traversePreOrder(t,e){!1!==t.call(e,this)&&this.isSplit()&&(this.topLeft.traversePreOrder(t,e),this.topRight.traversePreOrder(t,e),this.bottomLeft.traversePreOrder(t,e),this.bottomRight.traversePreOrder(t,e))}traversePointIntersections(t,e,i,n){const s=this.data,r=s.length;for(let a=0;a<r;a++){const r=s[a];if(r.x0<=t&&r.x1>=t&&r.y0<=e&&r.y1>=e&&!1===i.call(n,r,t,e))return}if(this.isSplit()){const s=(this.x0+this.x1)/2,r=(this.y0+this.y1)/2;s>=t&&(r>=e&&this.topLeft.traversePointIntersections(t,e,i,n),r<=e&&this.bottomLeft.traversePointIntersections(t,e,i,n)),s<=t&&(r>=e&&this.topRight.traversePointIntersections(t,e,i,n),r<=e&&this.bottomRight.traversePointIntersections(t,e,i,n))}}requestDatumIntersectionsPoint(t,e,i){let n=0;return this.traversePointIntersections(e,i,(e=>{t[n++]=e})),n}requestDatumIntersectionsRectangle(t,e,i,n,s){let r=0;return this.traverseRectangleIntersections(e,i,n,s,(e=>{t[r++]=e})),r}traverseRectangleIntersections(t,e,i,n,s,r){const a=this.data,o=a.length;for(let l=0;l<o;l++){const o=a[l];if(o.x0<i&&o.x1>t&&o.y0<n&&o.y1>e&&!1===s.call(r,o,t,e,i,n))return}if(this.isSplit()){const a=(this.x0+this.x1)/2,o=(this.y0+this.y1)/2;a>=t&&(o>=e&&this.topLeft.traverseRectangleIntersections(t,e,i,n,s,r),o<=n&&this.bottomLeft.traverseRectangleIntersections(t,e,i,n,s,r)),a<=i&&(o>=e&&this.topRight.traverseRectangleIntersections(t,e,i,n,s,r),o<=n&&this.bottomRight.traverseRectangleIntersections(t,e,i,n,s,r))}}}function IM(t){const e=[];let i;function n(t){if(i===t)return;const n=t.x0,s=t.y0,r=t.x1,a=t.y1,o=i.x0,l=i.y0,h=i.x1,c=i.y1;if(n>=o&&r<=h&&s>=l&&a<=c)e.push(t);else if(o>=n&&h<=r&&l>=s&&c<=a)return e.push(i),!1}t.traversePreOrder((function(t){const e=t.data,s=e.length;for(let r=0;r<s;r++)i=e[r],t.traverseRectangleIntersections(i.x0,i.y0,i.x1,i.y1,n)}));for(let t=0;t<e.length;t++)e[t].disconnect()}function NM(t,e,i,n){return(t-i)*e+(e-n)*i}function LM(t,e,i,n){let s=null,r=Number.POSITIVE_INFINITY;return i.traversePreOrder((i=>{if(i.getWidth()<t)return!1;if(i.getHeight()<e)return!1;const a=i.data,o=a.length;for(let i=0;i<o;i++){const o=a[i],l=o.getWidth();if(l<t)continue;const h=o.getHeight();if(h<e)continue;const c=n(l,h,t,e);c<r&&(r=c,s=o)}return!0})),s}function PM(t,e){const i=t.getWidth(),n=t.getHeight(),s=LM(i,n,e,NM);if(null===s)return!1;s.disconnect();const r=s.y0,a=s.x0;if(t.set(a,r,a+i,r+n),function(t,e){const i=[],n=[];let s,r;for(e.traverseRectangleIntersections(t.x0,t.y0,t.x1,t.y1,(function(e){n.push(e);const s=Eu(t.x0,e.x0),r=ru(t.x1,e.x1),a=Eu(t.y0,e.y0),o=ru(t.y1,e.y1);s>e.x0&&i.push(new EM(e.x0,e.y0,s,e.y1)),r<e.x1&&i.push(new EM(r,e.y0,e.x1,e.y1)),a>e.y0&&i.push(new EM(e.x0,e.y0,e.x1,a)),o<e.y1&&i.push(new EM(e.x0,o,e.x1,e.y1))})),s=0,r=n.length;s<r;s++)n[s].disconnect();for(function(t){let e,i,n=t.length;t:for(e=0;e<n;e++){const s=t[e],r=s.x0,a=s.y0,o=s.x1,l=s.y1;for(i=e+1;i<n;i++){const s=t[i],h=s.x0,c=s.y0,u=s.x1,d=s.y1;if(r>=h&&o<=u&&a>=c&&l<=d){t.splice(e,1),e--,n--;continue t}h>=r&&u<=o&&c>=a&&d<=l&&(t.splice(i,1),i--,n--)}}}(i),s=0,r=i.length;s<r;s++){const t=i[s];e.insertDatum(t)}}(t,e),t.y1!==s.y1){const i=new EM(s.x0,t.y1,s.x1,s.y1);e.insertDatum(i)}if(t.x1!==s.x1){const i=new EM(t.x1,s.y0,s.x1,s.y1);e.insertDatum(i)}return!0}class FM{constructor(t,e){this.size=new wd(t,e),this.free=new zM(0,0,t,e),this.free.add(null,0,0,t,e),this.boxes=[]}remove(t){const e=this.boxes.indexOf(t);return-1!==e&&(this.boxes.splice(e,1),this.free.insertDatum(new EM(t.x0,t.y0,t.x1,t.y1)),!0)}removeMany(t){let e=0;const i=t.length;for(let n=0;n<i;n++){const i=t[n];this.remove(i)||e++}return e}add(t){const e=PM(t,this.free);return e&&(this.boxes.push(t),IM(this.free)),e}canAdd(t,e){return null!==LM(t,e,this.free,NM)}addMany(t){const e=t.length,i=[],n=new vy((function(e){const i=t[e];return-Math.min(i.getWidth(),i.getHeight())}));for(let t=0;t<e;t++)n.push(t);for(let s=0;s<e;s++){const e=n.pop(),s=t[e];if(!PM(s,this.free))return this.removeMany(i),!1;this.boxes.push(s),i.push(s)}return IM(this.free),!0}repack(){const t=this.boxes;return this.clear(),this.addMany(t)}clear(){this.free.clear(),this.free.insertDatum(new EM(0,0,this.size.x,this.size.y)),this.boxes=[]}resize(t,e){const i=this.size.x,n=this.size.y;this.size.set(t,e),i>t||n>e?this.repack():(t>i&&this.free.insertDatum(new EM(i,0,t,e)),e>n&&this.free.insertDatum(new EM(0,n,t,e)))}validate(){const t=this.boxes,e=t.length;let i,n;for(i=0;i<e;i++){const s=t[i];for(n=i+1;n<e;n++){const e=t[n];if(s.computeOverlap(e,new Vp))return!1}}return!0}}function DM(){this.bitSet=new g_}DM.prototype.get=function(){const t=this.bitSet.nextClearBit(0);return this.bitSet.set(t,!0),t},DM.prototype.getSpecific=function(t){return!this.isUsed(t)&&(this.bitSet.set(t,!0),!0)},DM.prototype.isUsed=function(t){return this.bitSet.get(t)},DM.prototype.traverseUsed=function(t){const e=this.bitSet;for(let i=e.nextSetBit(0);-1!==i;i=e.nextSetBit(i+1))t(i)},DM.prototype.release=function(t){this.bitSet.clear(t)},DM.prototype.reset=function(){this.bitSet.reset()};class OM{constructor(){this.position=new wd(0,0),this.size=new wd(0,0),this.padding=4,this.id=-1,this.sampler=null,this.uv=new sb(0,0,0,0),this.packing=new Vp,this.flags=0,this.last_painted_version=-1}updateUV(t,e){const i=this.position,n=this.size,s=this.uv,r=i.x,a=i.y,o=n.x,l=n.y;s.set(r/t,a/e,o/t,l/e)}updatePositionFromPacking(t,e){const i=this,n=this.packing,s=n.x0+i.padding,r=n.y0+i.padding;i.position.set(s,r),this.updateUV(t,e)}setFlag(t){this.flags|=t}clearFlag(t){this.flags&=~t}writeFlag(t,e){e?this.setFlag(t):this.clearFlag(t)}getFlag(t){return(this.flags&t)===t}}OM.prototype.isAtlasPatch=!0;class RM{add(t,e){throw new Error("Not Implemented")}remove(t){throw new Error("Not Implemented")}get sampler(){throw new Error("Not Implemented")}update(){throw new Error("Not Implemented")}}function kM(t){return t.clone()}class UM extends RM{constructor(t=16,e=Nu.Uint8,i=4){super(),this.idPool=new DM,this.patches=[],this.size=new wd(t,t);const n=Pu[e];this.__sampler=new Vu(new n(t*t*i),i,t,t),this.packer=new FM(t,t),this.on={painted:new l},this.__needsUpdate=!1}get sampler(){return this.__sampler}getPatch(t){const e=this.patches,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.sampler===t)return i}}needsUpdate(){return this.__needsUpdate}contains(t){return this.patches.includes(t)}erase(){const t=this.patches,e=t.length;for(let i=0;i<e;i++)t[i].clearFlag(2);this.__sampler.data.fill(0),this.__needsUpdate=!0}resize(t,e){const i=this.patches,n=i.length;for(let s=0;s<n;s++){const n=i[s];if(n.getFlag(1)){const i=n.packing.x1,s=n.packing.y1;if(i>t||s>e)return!1}}for(let s=0;s<n;s++){const n=i[s];n.getFlag(1)&&n.updateUV(t,e)}return this.size.set(t,e),this.packer.resize(t,e),this.__sampler.resize(t,e),!0}paintPatch(t){const e=this.__sampler,i=t.sampler,n=t.position,s=t.size;e.copy_sameItemSize(i,0,0,n.x,n.y,s.x,s.y),t.setFlag(2),t.last_painted_version=i.version}erasePatch(t){const e=t.packing,i=e.x0,n=e.y0,s=e.x1,r=e.y1;this.eraseArea(i,n,s,r),t.clearFlag(2)}eraseArea(t,e,i,n){this.__sampler.zeroFill(t,e,i-t,n-e)}add(t,e=4){const i=new OM;i.id=this.idPool.get(),i.sampler=t,i.size.set(t.width,t.height),i.padding=e;const n=2*e;return i.packing.set(0,0,t.width+n,t.height+n),this.patches.push(i),this.__needsUpdate=!0,i}can_pack(t,e){return this.packer.canAdd(t,e)}remove(t){const e=this.patches.indexOf(t);return-1!==e&&(this.patches.splice(e,1),this.idPool.release(t.id),t.getFlag(2)&&this.erasePatch(t),t.getFlag(1)&&this.packer.remove(t.packing),!0)}repack(){const t=this.patches,e=t.length;for(let i=0;i<e;i++){const e=t[i];e.getFlag(1)&&(e.clearFlag(1),this.packer.remove(e.packing))}return this.pack(),this.__needsUpdate=!0,!0}pack(){const t=this.patches,e=t.length;let i,n;const s=[];for(i=0;i<e;i++){const e=t[i];e.getFlag(1)||s.push(e.packing)}if(s.length<=0)return!0;if(this.packer.addMany(s));else{const t=new FM(this.size.x,this.size.y),e=this.packer.boxes.map(kM);if(Array.prototype.push.apply(s,this.packer.boxes),!t.addMany(s)){for(i=0,n=e.length;i<n;i++){const t=e[i];this.packer.boxes[i].copy(t)}return!1}for(i=0,n=e.length;i<n;i++){const t=this.packer.boxes[i],n=e[i];if(t.equals(n));else{const e=this.patches.find((e=>e.packing===t));this.eraseArea(n.x0,n.y0,n.x1,n.y1),e.clearFlag(2)}}this.packer=t}for(i=0;i<e;i++){const e=t[i];e.setFlag(1),e.updatePositionFromPacking(this.size.x,this.size.y)}return!0}paint(){const t=this.patches,e=t.length;let i=0;for(let n=0;n<e;n++){const e=t[n];e.getFlag(2)&&e.last_painted_version===e.sampler.version||(this.paintPatch(e),i++)}i>0&&this.on.painted.send0()}update(){if(!this.__needsUpdate)return;const t=Eu(0,Math.log2(_y(this.size.x))),e=Eu(0,Math.log2(_y(this.size.y)));let i=t,n=e;for(;!this.pack();)for(;;){if(i<n?i++:n++,i>14||n>14)throw new Error(`Packing failed, could not pack ${this.patches.length} into ${Math.pow(2,14)} resolution texture. Initial powers: ${t}, ${e}`);const s=Math.pow(2,i),r=Math.pow(2,n);if(this.resize(s,r))break}this.paint(),this.__needsUpdate=!1}reset(){this.__sampler.data.fill(0),this.patches=[],this.packer.clear(),this.idPool.reset()}}class BM{constructor(){this.patch=null,this.last_use_time=0}}class VM extends RM{constructor({atlas:t}){super(),this.__cached_patches=[],this.__atals=t}__find_eviction_target(){let t=Infinity,e=-1;const i=this.__cached_patches,n=i.length;for(let s=0;s<n;s++){const n=i[s].last_use_time;n<t&&(e=s,t=n)}return e}__find_replacement_target(t,e){let i=Infinity,n=Infinity,s=-1;const r=this.__cached_patches,a=r.length;for(let o=0;o<a;o++){const a=r[o],l=a.patch.packing,h=l.x1-l.x0,c=l.y1-l.y0;if(h<t||c<e)continue;const u=h*c;if(u>i)continue;const d=a.last_use_time;d>=n||(i=u,n=d,s=o)}return s}__evict(t){const e=this.__cached_patches,i=e[t];e.splice(t,1),this.__atals.remove(i.patch)}__evict_all(){for(let t=this.__cached_patches.length-1;t>0;t--)this.__evict(t)}__evict_for(t,e){if(this.__cached_patches.length<=0)return!1;const i=this.__find_replacement_target(t,e);if(-1!==i)return this.__evict(i),!0;for(;!this.__atals.can_pack(t,e);){const t=this.__find_eviction_target();if(-1===t)return!1;this.__evict(t)}return!0}update(){try{this.__atals.update()}catch(t){if(!(this.__cached_patches.length>0))throw t;this.__evict_all(),this.__atals.update()}}get atlas(){return this.__atals}get sampler(){return this.__atals.sampler}reset(){this.__cached_patches.splice(0,this.__cached_patches.length),this.__atals.reset()}__find_cache_record_index(t){const e=this.__cached_patches,i=e.length;for(let n=0;n<i;n++)if(e[n].patch.sampler===t)return n;return-1}add(t,e=4){const i=this.__find_cache_record_index(t),n=this.__cached_patches;if(-1!==i){const t=n[i];return n.splice(i,1),t.patch}const s=t.width+2*e,r=t.height+2*e;return n.length>0&&!this.__atals.can_pack(s,r)&&this.__evict_for(s,r),this.__atals.add(t,e)}remove(t){if(!this.__atals.contains(t))return!1;const e=new BM;return e.last_use_time=performance.now(),e.patch=t,this.__cached_patches.push(e),!0}}let GM=0;class WM{constructor(){this.id=GM++}toString(){return`Light#${this.id}`}onDimensionChanged(t,e){throw new Error("Not Implemented")}offDimensionChanged(t,e){throw new Error("Not Implemented")}getCenter(t){throw new Error("Not Implemented")}getAABB(t){throw new Error("Not Implemented")}toArray(t,e){throw new Error("Not Implemented")}compare(t){return this.id-t.id}}WM.prototype.type="Abstract";const HM=[],jM=new Float32Array(6);class qM extends WM{constructor(){super(),this.transform=new Float32Array(16),this.transform_inverse=new Float32Array(16),this.uv=new Float32Array(4),this.texture_diffuse=null,this.draw_priority=0,this.__signal_transfom_changed=new l}setTransform(t){yu(this.transform,t),vu(this.transform_inverse,this.transform),this.__signal_transfom_changed.send0()}handleUvPositionChange(t,e){this.uv[0]=t,this.uv[1]=e}handleUvSizeChange(t,e){this.uv[2]=t,this.uv[3]=e}compare(t){if(t.isDecal){const e=this.draw_priority-t.draw_priority;if(0!==e)return e}return super.compare(t)}onDimensionChanged(t,e){this.__signal_transfom_changed.add(t,e)}offDimensionChanged(t,e){this.__signal_transfom_changed.remove(t,e)}getCenter(t){t[0]=this.transform[12],t[1]=this.transform[13],t[2]=this.transform[14]}getAABB(t){Qu(HM,0,-.5,-.5,-.5,.5,.5,.5),function(t,e,i){const n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],l=i[5],h=i[6],c=i[7],u=i[8],d=i[9],p=i[10],f=i[11],m=i[12],_=i[13],g=i[14],y=i[15];let v=Number.POSITIVE_INFINITY,x=Number.POSITIVE_INFINITY,w=Number.POSITIVE_INFINITY,b=Number.NEGATIVE_INFINITY,S=Number.NEGATIVE_INFINITY,M=Number.NEGATIVE_INFINITY;for(let t=0;t<24;t+=3){const i=e[t],T=e[t+1],C=e[t+2],A=1/(a*i+c*T+f*C+y),E=(n*i+o*T+u*C+m)*A,z=(s*i+l*T+d*C+_)*A,I=(r*i+h*T+p*C+g)*A;v>E&&(v=E),b<E&&(b=E),x>z&&(x=z),S<z&&(S=z),w>I&&(w=I),M<I&&(M=I)}t[0]=v,t[1]=x,t[2]=w,t[3]=b,t[4]=S,t[5]=M}(jM,HM,this.transform),t.readFromArray(jM,0)}toArray(t,e){return Rd(this.transform_inverse,0,t,e,16),Rd(this.uv,0,t,e+16,4),t[e+20]=this.draw_priority,t[e+21]=this.id,24}}qM.prototype.isDecal=!0,qM.prototype.ENCODED_SLOT_COUNT=24;class JM extends RM{constructor(t){super(),this.__atlas=t,this.__patches=new Map,this.__ref_counts=new Map}update(){this.__atlas.update()}__handle_ref_release(t,e){const i=this.__ref_counts,n=i.get(e);i.set(e,n-1),1===n&&(this.__atlas.remove(e),i.delete(e),this.__patches.delete(e.sampler))}acquire(t){let e=this.__patches.get(t);const i=this.__ref_counts,n=this.__atlas;void 0===e?(e=n.add(t),i.set(e,1),this.__patches.set(t,e)):i.set(e,i.get(e)+1);const s=new fv;return s.bind(e),s.onReleased.add(this.__handle_ref_release,this),s}}function YM(t,e){return t.id-e.id}function XM(t,e,i,n){const s=3*e;i[n]=t[s],i[n+1]=t[s+1],i[n+2]=t[s+2]}function ZM(t,e,i,n,s,r,a){XM(a,e*i+n*s+r,t,0);const o=r+1;XM(a,e*i+n*s+o,t,12);const l=n+1;XM(a,e*i+l*s+r,t,6),XM(a,e*i+l*s+o,t,18);const h=e+1;XM(a,h*i+n*s+r,t,3),XM(a,h*i+n*s+o,t,15),XM(a,h*i+l*s+r,t,9),XM(a,h*i+l*s+o,t,21)}const $M=[];function KM(t,e,i){const n=t.getFloat32(e),s=t.getFloat32(e+4),r=t.getFloat32(e+8),a=t.getFloat32(e+12),o=t.getFloat32(e+16),l=t.getFloat32(e+20);for(let t=0;t<24;t+=4)if(Zu(i[t],i[t+1],i[t+2],i[t+3],n,s,r,a,o,l)<=0)return!1;return!0}const QM=1024,tT=new ArrayBuffer(192+4*QM),eT=new Float32Array(tT,0,24),iT=new Float32Array(tT,96,24),nT=new Uint32Array(tT,192,QM),sT=[];function rT(t,e,i,n,s,r){const a=function(t,e,i,n,s,r){let a=1,o=0;const l=i.getBinaryNodeCount();if(l<=0)return 0;$M[0]=0;const h=l+i.getLeafNodeCount(),c=i.getDataView();for(;a-- >0;){const e=$M[a];if(e<l){if(!KM(c,e*yM,s))continue;const t=1+(e<<1),i=t+1;i<h?($M[a++]=i,$M[a++]=t):t<h&&($M[a++]=t)}else{const i=(e-l)*vM+l*yM,a=c.getUint32(i+24),h=3&a,u=4294967288&a;if(0===h){if(!KS(n[u],n[u+1],n[u+2],n[u+3],r,s))continue}else{if(3!==h)throw new Error(`Unsupported light type ${h}`);if(!KM(c,i,s))continue}t[0+o]=a,o++}}return o}(sT,0,e,r,iT,eT);if(s[t+1]=a,0===a)return 0;const o=function(t,e){let i=e;for(let n=0;n<e;n++)i=31*i+t[n];return i>>>0}(sT,a)&QM-1,l=nT[o];if(4294967295!==l){const e=function(t,e,i,n){for(let s=0;s<e;s++){const e=i[n+s];if(2*t[s]!==e)return!1}return!0}(sT,a,n,l);if(e)return s[t]=l,0}else nT[o]=i;s[t]=i;for(let t=0;t<a;t++){const e=sT[t];n[i+t]=e}return a}function aT(t,e){const i=function(t){if(!0===t.isPointLight)return 0;if(!0===t.isDecal)return 3;throw new Error("Unsupported light type")}(e);return i|t<<2}function oT(t,e){const i=t.elements,n=t.size;e.setLeafCount(n),e.initialize_structure();for(let t=0;t<n;t++){const n=i[t],s=n.bvh_leaf_main,r=aT(n.address,n.light);e.setLeafData(t,r,s.x0,s.y0,s.z0,s.x1,s.y1,s.z1)}e.build()}class lT{constructor(){this.__light_data_bvh=new vd,this.__light_data_map=new Map,this.__tiles_resolution=new S(32,16,8),this.__cluster_texture_precision=8,this.__cluster_texture_needs_rebuild=!1,this.__cluster_texture=new Zr(new Uint16Array(4),1,1,1),this.__cluster_texture.flipY=!1,this.__cluster_texture.generateMipmaps=!1,this.__cluster_texture.magFilter=Et,this.__cluster_texture.minFilter=Et,this.__cluster_texture.type=Rt,this.__cluster_texture.format=re,this.__cluster_texture.internalFormat="RGBA16UI",this.__lookup_data=new gM,this.__lookup_data.type=fM.Uint,this.__lookup_data.channel_count=1,this.__lookup_data.precision=8,this.__lookup_data.resize(1),this.__light_data=new gM,this.__light_data.type=fM.Float,this.__light_data.precision=32,this.__light_data.channel_count=4,this.__light_data.resize(8),this.__decal_atlas_texture=new wl(new Uint8Array(4),1,1,Yt),this.__decal_atlas_texture.type=Ft,this.__decal_atlas_texture.flipY=!1,this.__decal_atlas_texture.wrapS=Ct,this.__decal_atlas_texture.wrapT=Ct,this.__decal_atlas_texture.minFilter=1008,this.__decal_atlas_texture.magFilter=Nt,this.__decal_atlas_texture.generateMipmaps=!0,this.__decal_atlas_texture.anisotropy=8,this.__decal_atlas=new VM({atlas:new UM(512)}),this.__decal_patch_references=new JM(this.__decal_atlas),this.__decal_references=new Map,this.__visible_lights=new Ny(YM),this.__visible_decals=new Ny(YM),this.__sorted_visible_lights=[],this.__visible_bvh_lights=new AM,this.__visible_bvh_decals=new AM,this.__view_frustum=new ir,this.__view_frustum_points=new Float32Array(24),this.__projection_matrix=new Float32Array(16),this.__cluster_planes=new Float32Array(1),this.__cluster_frustum_points=new Float32Array(1),this.setTileMapResolution(32,16,16),this.__visible_lights.onAdded.add(this.__handle_visible_light_added,this),this.__visible_lights.onRemoved.add(this.__handle_visible_light_removed,this),this.__visible_decals.onAdded.add(this.__handle_visible_decal_added,this),this.__visible_decals.onRemoved.add(this.__handle_visible_decal_removed,this),this.__light_data_needs_update=!0,this.__visible_bvh_needs_update=!0,window.light_manager=this}set decal_filtering_enabled(t){const e=this.__decal_atlas_texture;e.generateMipmaps!==t&&(e.generateMipmaps=t)}get decal_filtering_enabled(){return this.__decal_atlas_texture.generateMipmaps}__update_decal_atlas_texture(){const t=this.__decal_atlas.sampler;t.version!==this.__decal_atlas_texture.version&&(Kf(t,this.__decal_atlas_texture),this.__decal_atlas_texture.version=t.version)}__set_cluster_addressable_bit_range(t){const e=Math.ceil(t);return this.__cluster_texture_precision=e,_M(mM(fM.Uint,e))!==this.__cluster_texture.type&&(this.__cluster_texture_needs_rebuild=!0,!0)}__update_cluster_texture(){this.__cluster_texture_needs_rebuild&&this.__build_cluster_texture()}__build_cluster_texture(){const t=mM(fM.Uint,this.__cluster_texture_precision),e=_M(t),i=this.__cluster_texture;i.dispose();const n=i.image,s=this.__tiles_resolution;n.width=s.x,n.height=s.y,n.depth=s.z,i.type=e,i.internalFormat=Wf(t,4);const r=Pu[t];n.data=new r(s.x*s.y*s.z*4),i.needsUpdate=!0,this.__cluster_texture_needs_rebuild=!1}__ensure_lookup_size(t){return this.__lookup_data.resize(t)}getTextureLookup(){return this.__lookup_data.getTexture()}getTextureData(){return this.__light_data.getTexture()}getTextureClusters(){return this.__cluster_texture}getTextureDecalAtlas(){return this.__decal_atlas_texture}getResolution(){return this.__tiles_resolution}__handle_light_dimensions_change(){this.__visible_bvh_needs_update=!0,this.__light_data_needs_update=!0}__handle_visible_decal_added(t){this.__light_data_needs_update=!0;const e=t.light;e.onDimensionChanged(this.__handle_light_dimensions_change,this);const i=this.__decal_patch_references.acquire(e.texture_diffuse),n=i.getValue().uv;n.position.onChanged.add(e.handleUvPositionChange,e),n.size.onChanged.add(e.handleUvSizeChange,e),e.uv[0]=n.position.x,e.uv[1]=n.position.y,e.uv[2]=n.size.x,e.uv[3]=n.size.y,this.__decal_references.set(e,i)}__handle_visible_decal_removed(t){this.__light_data_needs_update=!0;const e=t.light;e.offDimensionChanged(this.__handle_light_dimensions_change,this);const i=this.__decal_references.get(e);if(void 0===i)return;const n=i.getValue().uv;n.position.onChanged.remove(e.handleUvPositionChange,e),n.size.onChanged.remove(e.handleUvSizeChange,e),i.release(),this.__decal_references.delete(e)}__handle_visible_light_added(t){this.__light_data_needs_update=!0,t.light.onDimensionChanged(this.__handle_light_dimensions_change,this)}__handle_visible_light_removed(t){this.__light_data_needs_update=!0,t.light.offDimensionChanged(this.__handle_light_dimensions_change,this)}__sort_visible_light_score(t){const e=eT;return t.light.getCenter(e),function(t,e,i,n){const s=n[0]*t+n[4]*e+n[8]*i+n[12],r=n[1]*t+n[5]*e+n[9]*i+n[13],a=n[2]*t+n[6]*e+n[10]*i+n[14],o=511.5/(n[3]*t+n[7]*e+n[11]*i+n[15]),l=r*o,h=a*o,c=y(s*o+511.5,0,1023),u=y(l+511.5,0,1023),d=y(h+511.5,0,1023);return Xu(Math.round(c),Math.round(u),Math.round(d))}(e[0],e[1],e[2],this.__projection_matrix)}__assess_sorting_score(t,e){let i=0;const n=[],s=[];for(let u=0;u<e;u++){const d=t[u],p=this.__sort_visible_light_score(d);d.light.getCenter(n);for(let d=u+1;d<e;d++){const e=t[d],u=this.__sort_visible_light_score(e);e.light.getCenter(s),i+=Math.abs(p-u)/(r=n[0],a=n[1],o=n[2],l=s[0],h=s[1],c=s[2],Math.sqrt(R_(r,a,o,l,h,c)))}}var r,a,o,l,h,c;return i/(e*(e-1)*.5)}__sort_visible_light(){const t=this.__sorted_visible_lights,e=this.__visible_lights,i=e.size,n=this.__visible_decals,s=n.size,r=i+s;r>i&&t.splice(i,r-i),Rd(e.elements,0,t,0,i),Rd(n.elements,0,t,i,s),qu(t,this.__sort_visible_light_score,this,0,r-1)}__update_visible_bvh(){this.__visible_bvh_needs_update=!1,oT(this.__visible_lights,this.__visible_bvh_lights),oT(this.__visible_decals,this.__visible_bvh_decals)}__build_view_frustum(t){Am(t,this.__view_frustum,!1),Hu(this.__view_frustum.planes,4,5),this.__build_view_frustum_points()}__build_visible_light_list(){const t=this.__visible_lights;t.initializeUpdate();const e=this.__visible_decals;e.initializeUpdate();const i=[];Ly(this.__view_frustum.planes,iT);const n=rM(i,0,this.__light_data_bvh,iT,this.__view_frustum_points);for(let s=0;s<n;s++){const n=i[s];n.light instanceof qM?e.push(n):t.push(n)}t.finalizeUpdate(),e.finalizeUpdate()}__write_light_data_texture(){const t=this.__sorted_visible_lights,e=t.length;let i=0;for(let n=0;n<e;n++)i+=t[n].light.ENCODED_SLOT_COUNT;const n=i,s=this.__light_data;s.resize(Math.ceil(i/4)),s.update(),this.__lookup_data.precision=Math.max(0,Math.ceil(Math.log2(s.size)))+2;const r=s.getTexture(),a=r.image.data;i=0;for(let n=0;n<e;n++){const e=t[n],s=e.light;e.address=i>>2,i+=s.toArray(a,i),0!=(3&i)&&(i=1+(i>>2)<<2)}if(i!==n)throw new Error(`Expected light data size is ${n}, actual written data is size is ${i}`);r.needsUpdate=!0,this.__visible_bvh_needs_update=!0}__assign_lights_to_clusters(){const t=this.__tiles_resolution,e=t.z,i=t.y,n=t.x,s=n+1,r=i+1,a=s*r,o=this.__cluster_planes,l=this.__visible_bvh_lights,h=this.__visible_bvh_decals,c=4*s,u=c+4*r,d=this.__light_data.getTexture().image.data,p=n*i,f=this.__cluster_texture,m=f.image.data,_=this.__lookup_data;_.update();const g=_.getTexture(),y=g.image.data,v=this.__cluster_frustum_points;let x,w,b,S=0;for(nT.fill(4294967295),b=0;b<e;b++){const t=b*p;for(oM(o,u+4*b,iT,16),w=0;w<i;w++)for(oM(o,c+4*w,iT,8),x=0;x<n;x++){oM(o,0+4*x,iT,0),ZM(eT,b,a,w,s,x,v);const e=4*(t+w*n+x);S+=rT(e,l,S,y,m,d),S+=rT(e+2,h,S,y,m,d)}}f.needsUpdate=!0,g.needsUpdate=!0;const M=this.__lookup_data.size,T=this.__ensure_lookup_size(S),C=this.__set_cluster_addressable_bit_range(Math.max(0,Math.log2(S)));(T&&M<S||C)&&(this.__update_cluster_texture(),this.__assign_lights_to_clusters())}__build_cluster_frustum_planes(){const t=this.__tiles_resolution,e=t.z,i=t.y,n=t.x;!function(t,e,i,n,s){let r,a=0;const o=i+1,l=n+1,h=s+1,c=o*l,u=s*c;for(r=0;r<o;r++)pM(e,r,n*o+r,u+r,t,a),a+=4;for(r=0;r<l;r++)pM(e,r*o,u+r*o,r*o+i,t,a),a+=4;for(r=0;r<h;r++)pM(e,r*c,r*c+i,r*c+n*o,t,a),a+=4}(this.__cluster_planes,this.__cluster_frustum_points,n,i,e)}__build_view_frustum_points(){const t=this.__view_frustum;!function(t,e){const i=e[0],n=e[2],s=e[4];aM(t,0,i,n,s);const r=e[5];aM(t,3,i,n,r);const a=e[3];aM(t,6,i,a,s),aM(t,9,i,a,r);const o=e[1];aM(t,12,o,n,s),aM(t,15,o,n,r),aM(t,18,o,a,s),aM(t,21,o,a,r)}(this.__view_frustum_points,t.planes)}__build_cluster_frustum_points(){const t=this.__tiles_resolution,e=t.z,i=t.y,n=t.x;!function(t,e,i,n,s){const r=t[0],a=t[1],o=t[2],l=t[3],h=t[4],c=t[5],u=t[6],d=t[7],p=t[8],f=t[9],m=t[10],_=t[11],g=t[12],y=t[13],v=t[14],x=t[15],w=t[16],b=t[17],S=t[18],M=t[19],T=t[20],C=t[21],A=t[22],E=t[23],z=e+1,I=i+1,N=n+1,L=z*I;for(let t=0;t<N;t++){const N=t/n,P=1-N,F=t*L;for(let t=0;t<I;t++){const n=t/i,I=1-n,L=F+t*z;for(let t=0;t<z;t++){const i=t/e,z=1-i,F=z*I*P,D=z*I*N,O=z*n*P,R=z*n*N,k=i*I*P,U=i*I*N,B=i*n*P,V=i*n*N,G=r*F+l*D+u*O+f*R+g*k+x*U+S*B+C*V,W=a*F+h*D+d*O+m*R+y*k+w*U+M*B+A*V,H=o*F+c*D+p*O+_*R+v*k+b*U+T*B+E*V,j=3*(L+t);s[j]=G,s[j+1]=W,s[j+2]=H}}}}(this.__view_frustum_points,n,i,e,this.__cluster_frustum_points)}buildTiles(t){t.matrixWorldInverse.copy(t.matrixWorld),t.matrixWorldInverse.invert(),xu(this.__projection_matrix,t.projectionMatrix.elements,t.matrixWorldInverse.elements),this.__build_view_frustum(t),this.__build_visible_light_list(),this.__decal_atlas.update(),this.__update_decal_atlas_texture(),this.__light_data_needs_update&&(this.__sort_visible_light(),this.__write_light_data_texture(),this.__light_data_needs_update=!1),this.__visible_bvh_needs_update&&this.__update_visible_bvh(),this.__build_cluster_frustum_points(),this.__build_cluster_frustum_planes(),this.__assign_lights_to_clusters()}dispose(){this.__cluster_texture.dispose(),this.__light_data.dispose(),this.__lookup_data.dispose(),this.__decal_atlas_texture.dispose()}setTileMapResolution(t,e,i){const n=this.__tiles_resolution;if(t===n.x&&e===n.y&&i===n.z)return;n.set(t,e,i),this.__cluster_texture_needs_rebuild=!0,this.__update_cluster_texture();const s=4*(t+1+(e+1)+(i+1)),r=(t+1)*(e+1)*(i+1)*3,a=new ArrayBuffer(4*(s+r));this.__cluster_planes=new Float32Array(a,0,s),this.__cluster_frustum_points=new Float32Array(a,4*s,r)}addLight(t){const e=new YS(t);e.link(),this.__light_data_bvh.insertNode(e.bvh_leaf_main),this.__light_data_map.set(t,e)}removeLight(t){const e=this.__light_data_map.get(t);return void 0!==e&&(e.unlink(),this.__light_data_map.delete(t),!0)}}class hT{transform(t){throw new Error("Not implemented")}}function cT(t,e,i){const n=t.indexOf(e);if(-1===n)return t;const s=n+e.length;return t.slice(0,s)+i+t.slice(s)}function uT(t,e,i,n){const s=t.indexOf(e);if(-1!==s){const i=s+e.length;return t.slice(0,i)+n+t.slice(i)}const r=t.indexOf(i);return-1===r?t:t.slice(0,r)+n+t.slice(r+i.length)}const dT="\n#ifndef FP_SHADER_CHUNK_ACCUMULATION\n #define FP_SHADER_CHUNK_ACCUMULATION\n \n // read light data\n for(uint i=0u; i < fp_cluster_metadata.y; i++){\n uint lookup_index = fp_cluster_metadata.x + i;\n\n uint light_descriptor = texelFetch(fp_t_light_lookup, address_to_data_texture_coordinates(lookup_index), 0 ).r;\n\n uint type = (light_descriptor) & 0x3u;\n uint light_address = light_descriptor >> 2;\n \n\n if(type == 0u){\n // point light\n \n vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);\n vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);\n \n vec3 light_position = light_data_0.xyz;\n float light_radius = light_data_0.w;\n \n vec3 light_color = light_data_1.xyz;\n float light_intensity = light_data_1.w;\n \n PointLight pointlight;\n \n pointlight.position = light_position;\n pointlight.distance = light_radius;\n pointlight.color = light_color*light_intensity;\n pointlight.decay = 1.0;\n \n fp_getPointDirectLightIrradiance( pointlight, directLight, vViewPosition );\n RE_Direct( directLight, geometry, material, reflectedLight );\n \n }\n }\n#endif\n",pT="\n#ifndef FP_SHADER_CHUNK_DECODE_PARS\n #define FP_SHADER_CHUNK_DECODE_PARS\n\n // don't rely on three.js light number define to ensure that point light calculations are available\n #if NUM_POINT_LIGHTS < 1\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n };\n #endif\n \n // directLight is an out parameter as having it as a return value caused compiler errors on some devices\n void fp_getPointDirectLightIrradiance( const in PointLight pointLight, out IncidentLight directLight, vec3 viewPosition ) {\n \n // TODO consider moving light position transformation to view-space over to CPU\n vec3 lVector = (viewMatrix*vec4(pointLight.position,1.0)).xyz + viewPosition;\n \n directLight.direction = normalize( lVector );\n \n float lightDistance = length( lVector );\n \n directLight.color = pointLight.color;\n directLight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n directLight.visible = ( directLight.color != vec3( 0.0 ) );\n }\n \n float convert_depth_to_linear(in float d){\n float d_n = 2.0*d - 1.0;\n \n float f = fp_f_camera_far;\n float n = fp_f_camera_near;\n \n float fn = f*n;\n \n float z_diff = f - n;\n \n float denominator = (f + n - d_n * z_diff );\n \n float z_view = (2.0*fn) / denominator;\n \n return (z_view - n) / z_diff;\n }\n \n ivec2 address_to_data_texture_coordinates(uint address){\n // Lookup texture has 128 width\n uint lookup_index_x = address % 128u;\n uint lookup_index_y = address >> 7;\n \n return ivec2(int(lookup_index_x),int(lookup_index_y));\n }\n#endif\n",fT="//@injection_point FORWARD_PLUS:accumulation",mT="\n #ifndef FP_SHADER_CHUNK_PREAMBLE\n #define FP_SHADER_CHUNK_PREAMBLE\n \n precision mediump usampler3D;\n precision mediump usampler2D;\n \n uniform usampler3D fp_t_light_tiles;\n \n uniform usampler2D fp_t_light_lookup;\n uniform sampler2D fp_t_light_data;\n uniform sampler2D fp_t_decal_atlas;\n uniform vec2 fp_t_decal_atlas_resolution; \n \n uniform vec3 fp_v3_light_cluster_resolution;\n \n uniform float fp_f_camera_near;\n uniform float fp_f_camera_far;\n \n #define gl_FragDepthEXT gl_FragDepth\n #define texture2D texture\n #define textureCube texture\n #define texture2DProj textureProj\n #define texture2DLodEXT textureLod\n #define texture2DProjLodEXT textureProjLod\n #define textureCubeLodEXT textureLod\n #define texture2DGradEXT textureGrad\n #define texture2DProjGradEXT textureProjGrad\n #define textureCubeGradEXT textureGrad\n \n uniform vec2 fp_resolution; \n \n #endif\n",_T="\n#ifndef FP_SHADER_CHUNK_LOAD_METADATA\n #define FP_SHADER_CHUNK_LOAD_METADATA\n\n ivec3 v3_cluster_resolution = textureSize(fp_t_light_tiles, 0);\n ivec3 v3_cluster_position = ivec3( clip_v.x * float(v3_cluster_resolution.x), clip_v.y*float(v3_cluster_resolution.y), (clip_v.z)*float(v3_cluster_resolution.z) );\n\n uvec4 fp_cluster_metadata = texelFetch( fp_t_light_tiles, v3_cluster_position, 0 ).rgba;\n \n#endif\n",gT=`\n vec3 clip_v = vec3( vec2(gl_FragCoord.x, gl_FragCoord.y) / fp_resolution, convert_depth_to_linear(gl_FragCoord.z));\n clip_v.x = 1.0 - clip_v.x;\n ${_T}\n `,yT=`\n ${mT}\n `,vT=`\n vec3 fp_normalized_screen_position = ((gl_Position.xyz / gl_Position.w)+vec3(1.0))*0.5; \n vec3 clip_v = vec3( vec2(fp_normalized_screen_position.x, fp_normalized_screen_position.y), convert_depth_to_linear(fp_normalized_screen_position.z));\n ${_T}\n `,xT="@forward-plus-material-transformer";class wT extends hT{constructor({light_manager:t,resolution:e}){super(),this.__light_manager=t,this.__resolution=e;const i=this.__common_uniforms={fp_t_light_tiles:{type:"t",value:t.getTextureClusters()},fp_t_light_lookup:{type:"t",value:t.getTextureLookup()},fp_t_light_data:{type:"t",value:t.getTextureData()},fp_t_decal_atlas:{type:"t",value:t.getTextureDecalAtlas()},fp_t_decal_atlas_resolution:{type:"t",value:new bi(1,1)},fp_f_camera_near:{type:"f",value:0},fp_f_camera_far:{type:"f",value:0},fp_resolution:{type:"v2",value:e}};this.__on_before_compile=t=>{Object.assign(t.uniforms,i),t.glslVersion=ui,!0===t.defines.LIGHTING_VERTEX_ONLY?t.vertexShader=function(t){let e=mT+t;return e=cT(e,"void main() {",vT),e=cT(e,"#include <lights_pars_begin>",pT),e=uT(e,"#include <lights_fragment_end>",fT,dT),e}(t.vertexShader):(t.vertexShader=cT("\n #define attribute in\n #define varying out\n #define texture2D texture\n \n varying vec3 v_world_position;\n "+t.vertexShader,"#include <worldpos_vertex>","\n #if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n // worldPosition comes from 'worldpos_vertex' shader chunk\n v_world_position = worldPosition.xyz;\n #else\n v_world_position = ( modelMatrix * vec4( transformed, 1.0 )).xyz;\n #endif\n "),t.fragmentShader=function(t){let e=yT;return-1===t.indexOf("v_world_position")&&(e+="\n varying vec3 v_world_position;\n "),-1===t.indexOf("#define gl_FragColor")&&-1===t.indexOf("pc_fragColor")&&(e+="\n out highp vec4 pc_fragColor;\n #define gl_FragColor pc_fragColor\n "),e+=t,e=cT(e,"void main() {",gT),e=cT(e,"#include <lights_pars_begin>",pT),e=function(t,e,i){const n=t.indexOf("#include <lights_fragment_begin>");if(-1===n)return t;const s=n;return t.slice(0,s)+"\n#ifndef FP_SHADER_CHUNK_APPLY_DECALS\n #define FP_SHADER_CHUNK_APPLY_DECALS\n \n // process decals\n for(uint i=0u; i < fp_cluster_metadata.w; i++){\n uint lookup_index = fp_cluster_metadata.z + i;\n\n uint light_descriptor = texelFetch(fp_t_light_lookup, address_to_data_texture_coordinates(lookup_index), 0 ).r;\n\n uint type = (light_descriptor) & 0x3u;\n uint light_address = light_descriptor >> 2;\n \n // decal\n vec4 light_data_0 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address), 0);\n vec4 light_data_1 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+1u), 0);\n vec4 light_data_2 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+2u), 0);\n vec4 light_data_3 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+3u), 0);\n \n mat4 decal_transform_matrix = mat4(\n light_data_0,\n light_data_1,\n light_data_2,\n light_data_3\n );\n \n vec4 local_position = decal_transform_matrix*vec4(v_world_position, 1.0);\n \n if(max3(abs(local_position.xyz)) < 0.5){\n \n // we're inside decal volume\n vec4 light_data_4 = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+4u), 0);\n \n // compute normal of the decal, we get this by extracting rotation matrix and transforming (0,1,0) vector using that \n vec3 decal_normal = normalize(vec3(\n decal_transform_matrix[0][2], decal_transform_matrix[1][2], decal_transform_matrix[2][2]\n )); \n \n // Get geometry normal in world-space\n vec3 g_normal = normalize( ( transpose(viewMatrix) * vec4( normal, 0.0 ) ).xyz );\n \n float decal_surface_dot = dot(decal_normal, g_normal);\n \n // we fade out decals when the projection angle to the surface gets too steep\n // 0.7 is cos(45deg) and 0.5 is cos(60deg), dot returns cos of angle between two normals\n float decal_surface_angle_fade = smoothstep(-0.5,-0.7,decal_surface_dot);\n \n if(decal_surface_angle_fade <= 0.0){\n continue;\n }\n \n vec2 decal_local_uv = (local_position.xy + 0.5);\n vec2 decal_uv = decal_local_uv*light_data_4.zw + light_data_4.xy;\n \n vec4 decal_color = texture2D(fp_t_decal_atlas,decal_uv, -0.2);\n \n // compute decal alpha\n float decal_alpha = decal_color.a * decal_surface_angle_fade;\n \n if(decal_alpha < 0.003){\n continue;\n }\n \n material.diffuseColor = material.diffuseColor*(1.0-decal_alpha) + decal_color.xyz*decal_alpha;\n } \n \n }\n \n#endif\n"+t.slice(s)}(e),e=uT(e,"#include <lights_fragment_begin>",fT,dT),e}(t.fragmentShader))}}updateCamera(t){const e=this.__common_uniforms;e.fp_f_camera_far.value=t.camera.far,e.fp_f_camera_near.value=t.camera.near,e.fp_t_decal_atlas_resolution.value.set(e.fp_t_decal_atlas.value.image.width,e.fp_t_decal_atlas.value.image.height)}transform(t){if(t.hasOwnProperty(xT)){if(t[xT]!==this)throw new Error("The material is already transformed, but is associated with a different transformer instance");return t}let e=t;return function(t){return t.isMeshStandardMaterial||t.isShaderMaterial&&t.lights}(t)&&(e=t.clone(),t.isShaderMaterial&&(e.uniforms=Object.assign({},t.uniforms),e.defines=Object.assign({},t.defines)),e.onBeforeCompile=fg(t.onBeforeCompile,this.__on_before_compile),e[xT]=this),e}}class bT extends Hg{constructor(){super();const t=new lT;t.setTileMapResolution(16,8,8),this.__light_manager=t,this.__resolution=new bi,this.__material_transformer=new wT({light_manager:this.__light_manager,resolution:this.__resolution})}setClusterResolution(t,e,i){this.__light_manager.setTileMapResolution(t,e,i)}__prepare_for_render(t){this.__material_transformer.updateCamera(t),this.__light_manager.buildTiles(t.camera)}updateResolution(){this.engine.graphics.getResolution(this.__resolution)}async startup(){const t=this.engine.graphics;t.getMaterialManager().addCompileStep(this.__material_transformer),t.viewport.size.onChanged.add(this.updateResolution,this),t.pixelRatio.onChanged.add(this.updateResolution,this),t.main_view.on.preRender.add(this.__prepare_for_render,this),this.updateResolution(),await super.startup()}async shutdown(){const t=this.engine.graphics;t.getMaterialManager().removeCompileStep(this.__material_transformer),t.viewport.size.onChanged.remove(this.updateResolution,this),t.pixelRatio.onChanged.remove(this.updateResolution,this),t.on.preRender.remove(this.__prepare_for_render,this),this.__light_manager.dispose(),await super.shutdown()}getLightManager(){return this.__light_manager}}function ST(t,e){let i=t.get(e);return void 0===i&&(i=[],t.set(e,i)),i}class MT{constructor(){this.__used=new Map,this.__available=new Map,this.__scene=null}__getUsed(t){return ST(this.__used,t)}__getAvailable(t){return ST(this.__available,t)}__create(t){const e=function(t){switch(t){case ES.POINT:return new Ac(0,0,0,1);case ES.AMBIENT:return new Ic(0,0);case ES.DIRECTION:return new zc(0,0);case ES.SPOT:return new wc(0,0,0,0,0,1);default:throw new Error("Unknown light type: "+t)}}(t);return null!==this.__scene&&this.__scene.add(e),e}attach(t){this.__scene!==t&&(null!==this.__scene&&this.detach(),this.__scene=t,this.__traverseAllLight(t.add,t))}detach(){const t=this.__scene;null!==t&&(this.__traverseAllLight(t.remove,t),this.__scene=null)}__traverseAllLight(t,e){for(const[i,n]of this.__used)n.forEach(t,e);for(const[i,n]of this.__available)n.forEach(t,e)}obtain(t){const e=this.__getAvailable(t);let i;return i=e.length<=0?this.__create(t):e.pop(),this.__getUsed(t).push(i),i}release(t){const e=function(t){if(t.isPointLight)return ES.POINT;if(t.isSpotLight)return ES.SPOT;if(t.isDirectionalLight)return ES.DIRECTION;if(t.isAmbientLight)return ES.AMBIENT;throw new Error("Unsupported light type")}(t),i=this.__getUsed(e),n=i.indexOf(t);return-1!==n&&(function(t){t.intensity=0,void 0!==t.castShadow&&(t.castShadow=!1)}(t),i.splice(n,1),this.__getAvailable(e).push(t),!0)}countTotalByType(t){const e=this.__getAvailable(t),i=this.__getUsed(t);return e.length+i.length}reserve(t,e){let i=this.countTotalByType(t);for(;i<e;i++){const e=this.__create(t);this.__getAvailable(t).push(e)}}}class TT{constructor(){this.__graphics=null,this.__maps=new of}set graphics(t){this.__graphics=t}add(t){return!this.__maps.contains(t)&&(this.__maps.add(t),t.views.forEach(this.__graphics.views.add,this.__graphics.views),!0)}remove(t){const e=this.__maps.removeOneOf(t);return e&&t.views.forEach(this.__graphics.views.remove,this.__graphics.views),e}}class CT extends bm{constructor(t){super(),this.__ContextClass=t,this.__context_pool=new Sw((()=>new t),(t=>{}),(t=>{})),this.__live_contexts=[],this.__validation_ignore_link_argument_count=!0}__getEntityContext(t){return this.__live_contexts[t]}link(){const t=arguments.length-1,e=arguments[t],i=this.__context_pool.create();i.system=this,i.entity=e;for(let e=0;e<t;e++)i.components[e]=arguments[e];i.link(),this.__live_contexts[e]=i}unlink(){const t=arguments[arguments.length-1],e=this.__live_contexts[t];void 0!==e&&(delete this.__live_contexts[t],e.unlink(),this.__context_pool.release(e))}}class AT{constructor(){this.entity=-1,this.system=null,this.components=[],this.__is_linked=!1}getDataset(){return this.system.entityManager.dataset}link(){this.__is_linked||(this.__is_linked=!0)}unlink(){this.__is_linked&&(this.__is_linked=!1)}}class ET{constructor(){this.__c_transform=null,this.__c_light=null}set component_transform(t){this.__c_transform=t}set component_light(t){this.__c_light=t}applySettings(t){}link(t){this.__c_transform.position.onChanged.add(this.__apply_position,this),this.__c_transform.rotation.onChanged.add(this.__apply_rotation,this);const e=this.__c_light;e.intensity.onChanged.add(this.__apply_intensity,this),e.color.onChanged.add(this.__apply_color,this),e.distance.onChanged.add(this.__apply_distance,this),e.angle.onChanged.add(this.__apply_angle,this),e.penumbra.onChanged.add(this.__apply_penumbra,this),e.castShadow.onChanged.add(this.__apply_castShadow,this);const i=e.type.getValue();i===ES.POINT?this.__apply_distance():i===ES.SPOT&&(this.__apply_angle(),this.__apply_penumbra()),this.__apply_intensity(),this.__apply_color(),this.__apply_castShadow(),this.__apply_position(),this.__apply_rotation(),this.applySettings(t.system.settings)}unlink(t){this.__c_transform.position.onChanged.remove(this.__apply_position,this),this.__c_transform.rotation.onChanged.remove(this.__apply_rotation,this),this.__c_light.intensity.onChanged.remove(this.__apply_intensity,this),this.__c_light.color.onChanged.remove(this.__apply_color,this),this.__c_light.distance.onChanged.remove(this.__apply_distance,this),this.__c_light.angle.onChanged.remove(this.__apply_angle,this),this.__c_light.penumbra.onChanged.remove(this.__apply_penumbra,this),this.__c_light.castShadow.onChanged.remove(this.__apply_castShadow,this)}__apply_position(){}__apply_rotation(){}__apply_intensity(){}__apply_color(){}__apply_distance(){}__apply_angle(){}__apply_penumbra(){}__apply_castShadow(){}}class zT extends WM{constructor(){super(),this.position=new S,this.radius=new Id(1),this.color=new Rp(1,1,1),this.intensity=new Id(1)}getCenter(t){this.position.writeToArray(t,0)}getAABB(t){const e=this.radius.getValue(),i=this.position,n=i.x,s=i.y,r=i.z;t.setBounds(n-e,s-e,r-e,n+e,s+e,r+e)}onDimensionChanged(t,e){this.position.onChanged.add(t,e),this.radius.onChanged.add(t,e)}offDimensionChanged(t,e){this.position.onChanged.remove(t,e),this.radius.onChanged.remove(t,e)}toArray(t,e){const i=this.position;t[e]=i.x,t[e+1]=i.y,t[e+2]=i.z,t[e+3]=this.radius.getValue();const n=this.color;return t[e+4]=n.r,t[e+5]=n.g,t[e+6]=n.b,t[e+7]=this.intensity.getValue(),8}}zT.prototype.isPointLight=!0,zT.prototype.ENCODED_SLOT_COUNT=8;class IT extends ET{constructor(){super(),this.__light=null}getPlugin(t){return t.system.__plugin.getValue()}link(t){const e=this.getPlugin(t).getLightManager(),i=new zT,n=this.__c_light;i.intensity=n.intensity,i.color=n.color,i.radius=n.distance,i.position=this.__c_transform.position,n.__fp_light=i,e.addLight(i),this.__light=i}unlink(t){this.getPlugin(t).getLightManager().removeLight(this.__light)}}function NT(t,e){const i=t.__threeObject;if(e.__setThreeEuler(i.rotation),void 0!==i.target){const t=i.target.position;t.set(0,0,1).applyQuaternion(e),t.set(i.position.x+t.x,i.position.y+t.y,i.position.z+t.z),i.target.updateMatrixWorld(!0)}Vm(t.__threeObject)}class LT{constructor(){this.views=[]}}const PT=new Zo;PT.autoUpdate=!1,PT.matrixAutoUpdate=!1,PT.matrixWorldNeedsUpdate=!1;const FT=new Fo({depthPacking:ri,side:P});function DT(t){let e;const i=t.customDepthMaterial;return e=void 0!==i?i:FT,e}function OT(t){if(!1===t.castShadow)return!1;if(!1===t.visible)return!1;if(t.isMesh){const e=t.customDepthMaterial?t.customDepthMaterial:t.material;if(e&&!1===e.visible)return!1}return!0}class RT extends ET{constructor(){super(),this.__system=null,this.__shadow_map=null,this.__object_map=new WeakMap}link(t){this.__system=t.system;const e=this.__system.__three_light_cache;(function(t,e){null===t.__threeObject&&(t.__threeObject=function(t,e){const i=t.intensity.getValue(),n=t.color.toUint(),s=t.type.getValue(),r=e.obtain(s);switch(s){case ES.DIRECTION:break;case ES.SPOT:r.angle=t.angle.getValue(),r.penumbra=t.penumbra.getValue(),r.distance=t.distance.getValue();break;case ES.POINT:case ES.AMBIENT:break;default:throw new Error("Unknown light type: "+t.type)}return r.color.setHex(n),r.intensity=i,r.castShadow=t.castShadow.getValue(),r}(t,e))})(this.__c_light,e),super.link(t)}unlink(t){this.__system.__three_light_cache.release(this.__three_getLight()),this.__c_light.__threeObject=null,this.__shadowmap_unlink(),super.unlink(t)}__three_getLight(){return this.__c_light.__threeObject}__apply_intensity(){this.__three_getLight().intensity=this.__c_light.intensity.getValue()}__apply_color(){const t=this.__c_light.color;this.__three_getLight().color.setRGB(t.r,t.g,t.b)}__apply_distance(t){this.__three_getLight().distance=this.__c_light.distance.getValue()}__apply_angle(){this.__three_getLight().angle=this.__c_light.angle.getValue()}__apply_penumbra(){this.__three_getLight().penumbra=this.__c_light.penumbra.getValue()}__shadowmap_link(){this.__shadow_map=new LT;const t=new Sv;t.name="Shadow Map",this.__shadow_map.views.push(t),this.__system.__shadows.add(this.__shadow_map),t.on.preVisibilityBuild.add(this.__shadowmap_prepare_view,this),t.on.postVisibilityBuild.add(this.__shadowmap_render,this)}__shadowmap_unlink(){null!==this.__shadow_map&&(this.__system.__shadows.remove(this.__shadow_map),this.__shadow_map=null)}__shadowmap_prepare_view(){const t=this.__shadow_map.views[0],e=this.__three_getLight().shadow.camera;e.updateMatrix(),e.updateMatrixWorld(),t.set_from_camera(e)}__shadowmap_render(){const t=this.__shadow_map.views[0];t.on.preRender.send1(t);const e=this.__system.__graphics,i=this.__three_getLight(),n=i.shadow,s=t.visible_objects,r=s.size;dv.INSTANCE.build_scene({scene:PT,input:s.elements,input_size:r,material_extractor:DT,object_filter:OT}),e.shadowmap_renderer.update(e.renderer,n,PT,i)}__apply_castShadow(){const t=this.__c_light.castShadow.getValue();this.__three_getLight().castShadow=t,t&&null===this.__shadow_map?this.__shadowmap_link():t||null===this.__shadow_map||this.__shadowmap_unlink()}__apply_position(){const t=this.__c_transform,e=t.position,i=this.__three_getLight();i.position.set(e.x,e.y,e.z);const n=this.__c_light,s=n.type.getValue();s===ES.SPOT||s===ES.DIRECTION?NT(n,t.rotation):Vm(i)}__apply_rotation(){NT(this.__c_light,this.__c_transform.rotation)}applySettings(t){const e=this.__three_getLight().shadow;if(void 0!==e){e.autoUpdate=!1,e.camera.matrixAutoUpdate=!1;const i=parseInt(t.shadowResolution);e.radius=1,e.blurSamples=8,e.mapSize.width===i&&e.mapSize.height===i||(e.mapSize.width=e.mapSize.height=i,null!==e.map&&(e.map.dispose(),e.map=null))}}}class kT extends AT{constructor(){super(),this.__binding=null}getLight(){return this.components[0]}getTransform(){return this.components[1]}__rebuild(){this.__binding.unlink(this),this.__build(),this.__binding.link(this)}__build(){this.getLight().type.getValue()===ES.POINT&&this.system.__use_forward_plus?this.__binding=new IT:this.__binding=new RT,this.__binding.component_light=this.getLight(),this.__binding.component_transform=this.getTransform()}applySettings(){this.__binding.applySettings(this.system.settings)}link(){this.__build(),this.__binding.link(this),this.getLight().type.onChanged.add(this.__rebuild,this)}unlink(){this.getLight().type.onChanged.remove(this.__rebuild,this),this.__binding.unlink(this)}}class UT extends CT{constructor(t,e={}){super(kT);const i=t.graphics;this.dependencies=[zS,Au],this.engine=t,this.scene=i.scene,this.settings=e,this.__graphics=i,this.__camera_object=null,this.bindings=[],this.__shadows=new TT,this.__shadows.graphics=i,this.__use_forward_plus=!0,this.__plugin=null,this.__three_light_cache=new MT,this.__three_light_cache.attach(this.scene),void 0!==e.preAllocateLightsDirection&&this.__three_light_cache.reserve(ES.DIRECTION,e.preAllocateLightsDirection),void 0!==e.preAllocateLightsSpot&&this.__three_light_cache.reserve(ES.SPOT,e.preAllocateLightsSpot),void 0!==e.preAllocateLightsPoint&&this.__three_light_cache.reserve(ES.POINT,e.preAllocateLightsPoint),void 0!==e.preAllocateLightsAmbient&&this.__three_light_cache.reserve(ES.POINT,e.preAllocateLightsAmbient)}get componentClass(){return zS}setConfiguration(t,e){this.settings[t]=e;const i=this.entityManager;if(null===i)return;const n=i.dataset;null!==n&&n.traverseComponents(zS,this.applySettingsOne,this)}applySettingsOne(t,e){this.__getEntityContext(e).applySettings()}async startup(t,e,i){this.__use_forward_plus&&(this.__plugin=await this.engine.plugins.acquire(bT)),this.__graphics.on.visibilityConstructionEnded.add(this.__updateShadowCameraForActiveCamera,this),super.startup(t,e,i)}shutdown(t,e,i){null!==this.__plugin&&(this.__plugin.release(),this.__plugin=null),this.__graphics.on.visibilityConstructionEnded.remove(this.__updateShadowCameraForActiveCamera,this),super.shutdown(t,e,i)}__updateShadowCameraForActiveCamera(){const t=this.entityManager.dataset;null!==t&&t.traverseComponents(Pm,this.__updateShadowCameraForCamera,this)}__visit_entity_to_update_shadow(t,e){const i=t.__threeObject;null!==i&&t.type.getValue()!==ES.AMBIENT&&(t.castShadow.getValue()?(i.castShadow=!0,function(t,e,i){const n=i.layers,s=e.shadow;if(void 0===s)return;const r=s.camera;JS.project(-1,1,t,r.matrixWorldInverse,VT),function(t,e,i,n,s,r,a,o){const l=r-i,h=a-n,c=t.x,u=t.y,d=l/c,p=h/u,f=i-i%d-d/2,m=n-n%p-p/2,_=f+l*((c+1)/c),g=m+h*((u+1)/u);e.left=f,e.right=_,e.bottom=m,e.top=g}(s.mapSize,r,VT.x0,VT.y0,VT.z0,VT.x1,VT.y1,VT.z1),BT.hysteresis=.33,BT.camera=r,BT.layers=n,BT.compute(),r.near=BT.near,r.far=BT.far,r.updateProjectionMatrix(),s.bias=-1e-4}(this.__camera_object,i,this.__graphics)):i.castShadow=!1)}__updateShadowCameraForCamera(t,e){const i=this.entityManager.dataset;return!t.active.getValue()||(this.__camera_object=t.object,null===this.__camera_object||i.traverseComponents(zS,this.__visit_entity_to_update_shadow,this),!1)}}const BT=new jm,VT=new rd;function GT(t,e){return"function"==typeof t.hasOwnProperty?t.hasOwnProperty(e):void 0!==t[e]}function WT(t){const e=Object.keys(t),i=e.length;return i>10&&(e.splice(0,10),e.push(`[... ${i-10} more options]`)),e}function HT(t,e,i){return function(t,e,i){let n=t;e.length>0&&""===e[0]&&e.shift();const s=e.length;for(let t=0;t<s;t++){const r=e[t];if(!GT(n,r)){if("function"!=typeof i){const i=WT(n);throw new Error(`failed to resolve path [${e.join(",")}] at part ${t} [${r}]. Existing keys: ${i.join(", ")}`)}i(n,r,t,s)}n=n[r]}return n}(t,e.split("/"),i)}function jT(t,e,i){function n(t){const e=this;this.signal=t,this.running=!1,this.deferred=[];const i=this.bindings=[];this.handler=function(){const t=i.length;for(let e=0;e<t;e++){const t=i[e];if(t.listener.apply(void 0,arguments),t.exclusive)break}e.__processDeferred()}}return n.prototype.__processDeferred=function(){const t=this.deferred,e=t.length;for(let i=0;i<e;i++){const e=t[i];this.registerBinding(e)}this.deferred=[]},n.prototype.registerBinding=function(t){this.bindings.push(t),this.bindings.sort(((t,e)=>t.exclusive&&!e.exclusive?-1:!t.exclusive&&e.exclusive?1:e.priotity-t.priority))},n.prototype.start=function(){this.signal.add(this.handler)},n.prototype.stop=function(){this.signal.remove(this.handler)},n.prototype.add=function(t){this.signal.isDispatching()?this.deferred.push(t):this.registerBinding(t)},n.prototype.remove=function(t){const e=this.bindings.indexOf(t);if(-1!==e)this.bindings.splice(e,1);else{const e=this.deferred.indexOf(t);this.deferred.splice(e,1)}},function(t,e,s){if(t.hasOwnProperty(e))return t[e];{let s=function(){const t=new n(i);return t.start(),t}();return t[e]=s,s}}(t,e)}function qT(t,e,i){t.forEach((function(t){const n=t.path,s=HT(e,n);jT(i,n,s).add(t)}))}function JT(t,e,i){t.forEach((function(t){const n=t.path,s=HT(e,n);jT(i,n,s).remove(t)}))}class YT extends bm{constructor(t){super(),this.enabled=new Hd(!0),this.dependencies=[GS],this.devices=t;const e=this;this.enabled.onChanged.add((function(t){const i=e.entityManager.dataset;null!==i&&(t?i.traverseComponents(GS,(function(t){qT(t.mapping,e.devices,e.proxies)})):i.traverseComponents(GS,(function(t){JT(t.mapping,e.devices,e.proxies)})))}))}startup(t,e,i){this.entityManager=t,this.proxies={},e()}link(t,e){qT(t.mapping,this.devices,this.proxies)}unlink(t,e){JT(t.mapping,this.devices,this.proxies),t.on.unlinked.send1(e)}}class XT extends bm{constructor(t){super(),this.dependencies=[IS],this.graphicsEngine=t,this.renderLayer=null,this.bvh=null,this.cleaup=[],this.updateQueue=[],this.__time_delta=0}shutdown(t,e,i){try{this.graphicsEngine.size.onChanged.remove(this.setViewportSize),this.graphicsEngine.layers.remove(this.renderLayer),e()}catch(t){i(t)}}startup(t,e,i){this.entityManager=t;const n=this.graphicsEngine;this.renderLayer=n.layers.create(XT.RENDER_LAYER_NAME);const s=n.viewport.size;this.renderLayer.extractRenderable=function(t){return t.__threeObject},this.renderLayer.renderPass=zy.Transparent,this.renderLayer.computeNearFarClippingPlanes=function(t,e=0){const i=[],n=[[],[],[],[]],s={near:0,far:0};let r;function a(t){for(let e=0;e<4;e++){const a=n[e],o=a[0],l=a[1];if(!aM(i,0,o,l,t))continue;const h=r.normal,c=$u(i[0],i[1],i[2],h.x,h.y,h.z,r.constant);c>0&&c<s.near&&(s.near=c),c>s.far&&(s.far=c)}}return function(i,o,l,h,c){const u=i.planes;r=u[5],n[0][0]=u[0],n[0][1]=u[2],n[1][0]=u[0],n[1][1]=u[3],n[2][0]=u[1],n[2][1]=u[2],n[3][0]=u[1],n[3][1]=u[3],s.near=o,s.far=l,t(a),s.near<=s.far&&h.call(c,s.near-e,s.far+e)}}((function(e){t.dataset.traverseComponents(IS,(function(t,i){const n=new Qs(new Di(0,1,0),t.level.getValue());e(n)}))})),this.bvh=this.renderLayer.bvh;const r=this;n.on.preRender.add((function(t,e,i){const a=r.entityManager.dataset;if(null===a)return;const o=n.computeTotalPixelRatio();a.traverseComponents(IS,(function(t,i){const n=t.__shader;n.uniforms.fCameraNear.value=e.near,n.uniforms.fCameraFar.value=e.far,n.uniforms.vScreenResolution.value.set(s.x*o,s.y*o)}))})),e()}link(t,e){const i=this.graphicsEngine.frameBuffers.getById(sy);let n,s;if(null===t.__shader?(n=function(){const t={time:{type:"f",value:0},fCameraNear:{type:"f",value:0},fCameraFar:{type:"f",value:0},vHeightUv:{type:"v4",value:new Ni},tHeightTexture:{type:"t",value:null},vHeightTextureResolution:{type:"v2",value:new bi},tDepthTexture:{type:"t",value:null},vScreenResolution:{type:"v2",value:new bi},waterColor:{type:"c",value:new ss},shoreColor:{type:"c",value:new ss(9816793)},fWaveSpeed:{type:"f",value:1.8},fScattering:{type:"f",value:1.2},fWaveAmplitude:{type:"f",value:.3},fWaveFrequency:{type:"f",value:3},vShoreDepthTransition:{type:"v2",value:new bi(.7,2)}};return new Ws({vertexShader:"\n\nvarying vec2 vUv; \nvarying float level;\n\nvarying vec3 vWorldPosition;\n\nvoid main(){\n\n vUv = uv;\n \n vWorldPosition = (modelMatrix * vec4(position, 1.0)).xyz;\n \n level = vWorldPosition.y;\n \n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",fragmentShader:"\nuniform vec3 waterColor;\nuniform vec3 shoreColor;\n\nuniform float fScattering;\n\nuniform sampler2D tHeightTexture;\nuniform sampler2D tDepthTexture;\n\nuniform vec2 vHeightTextureResolution;\n\nuniform vec2 vScreenResolution;\n\nuniform float fCameraNear;\nuniform float fCameraFar;\n\nuniform vec4 vHeightUv;\n\nuniform float time;\n\nuniform float fWaveAmplitude;\nuniform float fWaveSpeed;\nuniform float fWaveFrequency;\n\nuniform vec2 vShoreDepthTransition;\n\nvarying vec2 vUv;\nvarying float level;\nvarying vec3 vWorldPosition;\n\nfloat depthToLinear( float z, float cameraNear, float cameraFar ) {\n float z_n = 2.0 * z - 1.0;\n \n float z_e = 2.0 * cameraNear * cameraFar / (cameraFar + cameraNear - z_n * (cameraFar - cameraNear));\n\n return z_e;\n}\n\t \nvec4 sampleTextureGaussian( sampler2D tex,vec2 uv, vec2 texelSize){\n float r = 1.0;\n \n float dx0 = - texelSize.x * r;\n float dy0 = - texelSize.y * r;\n float dx1 = + texelSize.x * r;\n float dy1 = + texelSize.y * r;\n \n return (\n texture2D(tex, uv + vec2( dx0, dy0 ) ) +\n texture2D(tex, uv + vec2( 0.0, dy0 ) ) +\n texture2D(tex, uv + vec2( dx1, dy0 ) ) +\n texture2D(tex, uv + vec2( dx0, 0.0 ) ) +\n texture2D(tex, uv) +\n texture2D(tex, uv + vec2( dx1, 0.0 ) ) +\n texture2D(tex, uv + vec2( dx0, dy1 ) ) +\n texture2D(tex, uv + vec2( 0.0, dy1 ) ) +\n texture2D(tex, uv + vec2( dx1, dy1 ) )\n ) * ( 1.0 / 9.0 );\n}\n\nvec4 blur9(sampler2D image, vec2 uv, vec2 texelSize, vec2 direction) {\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.3846153846) * direction;\n vec2 off2 = vec2(3.2307692308) * direction;\n color += texture2D(image, uv) * 0.2270270270;\n color += texture2D(image, uv + (off1 * texelSize )) * 0.3162162162;\n color += texture2D(image, uv - (off1 * texelSize )) * 0.3162162162;\n color += texture2D(image, uv + (off2 * texelSize )) * 0.0702702703;\n color += texture2D(image, uv - (off2 * texelSize )) * 0.0702702703;\n return color;\n}\n\nvec4 blur13(sampler2D image, vec2 uv, vec2 texelSize, vec2 direction) {\n vec4 color = vec4(0.0);\n vec2 off1 = vec2(1.411764705882353) * direction;\n vec2 off2 = vec2(3.2941176470588234) * direction;\n vec2 off3 = vec2(5.176470588235294) * direction;\n color += texture2D(image, uv) * 0.1964825501511404;\n color += texture2D(image, uv + (off1 * texelSize)) * 0.2969069646728344;\n color += texture2D(image, uv - (off1 * texelSize)) * 0.2969069646728344;\n color += texture2D(image, uv + (off2 * texelSize)) * 0.09447039785044732;\n color += texture2D(image, uv - (off2 * texelSize)) * 0.09447039785044732;\n color += texture2D(image, uv + (off3 * texelSize)) * 0.010381362401148057;\n color += texture2D(image, uv - (off3 * texelSize)) * 0.010381362401148057;\n return color;\n} \n\nvoid main(){\n\n //compute view depth\n float screenEnvDepth = texture2D(tDepthTexture, gl_FragCoord.xy / vScreenResolution ).x;\n \n float screenEnvDepthLinear = depthToLinear(screenEnvDepth, fCameraNear, fCameraFar);\n \n float objectDepth = gl_FragCoord.z;\n \n float objectDepthLinear = depthToLinear(objectDepth, fCameraNear, fCameraFar);\n\n float viewDepth = screenEnvDepthLinear - objectDepthLinear;\n \n if(viewDepth < 0.0){\n discard;\n }\n \n //sample water depth relative to the sky\n vec2 depthUV = (vUv + vHeightUv.xy) * vHeightUv.zw;\n \n float height = blur13( tHeightTexture, depthUV, 1.0 / vHeightTextureResolution, vec2(1.0) ).r;\n \n float depth = level - height;\n \n float geoHash = (vWorldPosition.x+ vWorldPosition.z)*fWaveFrequency;\n \n float waveHeightModifier = sin(geoHash + time*fWaveSpeed) / 3.14159265359;\n \n float waveHeight = depth + fWaveAmplitude * waveHeightModifier;\n \n float deepColorFactor = smoothstep(vShoreDepthTransition.x, vShoreDepthTransition.y, waveHeight);\n \n vec4 color = mix(\n vec4(shoreColor, 0.8), \n vec4(waterColor, 1.0), \n deepColorFactor\n );\n \n //this simulates scattering under water\n float scatteringFactor = 1.0 - exp( - viewDepth * fScattering );\n \n float fogAmount = scatteringFactor;\n\n gl_FragColor = color;\n \n gl_FragColor.a *= fogAmount;\n}\n",uniforms:t,blending:D,lights:!1,fog:!1,depthTest:!1,depthWrite:!1,transparent:!0,vertexColors:!1})}(),n.uniforms.tDepthTexture.value=i.renderTarget.depthTexture,t.__shader=n,t.writeShaderUniforms()):n=t.__shader,n.side=L,null===t.__threeObject){const e=new rr(800,800,1,1);s=jd(e,n),t.__threeObject=s}else s=t.__threeObject;s.rotation.x=.5*Math.PI,s.position.x=200,s.position.z=200,s.position.y=t.level.getValue(),Vm(s);const r=new ld(t,-200,t.level.getValue(),-200,600,t.level.getValue(),600);function a(t,e){s.position.y=t,Vm(s),r.move(0,0,t-e)}t.bvh=r,t.level.onChanged.add(a),this.bvh.insertNode(r),this.cleaup[e]=function(){t.level.onChanged.remove(a)},this.updateQueue.push(t)}unlink(t,e){t.bvh.disconnect(),(0,this.cleaup[e])(),delete this.cleaup[e];const i=this.updateQueue.indexOf(t);-1!==i&&this.updateQueue.splice(i,1)}processUpdateQueue(){const t=this.updateQueue;let e=t.length;if(0===e)return;const i=this.entityManager.dataset;if(null===i)return;const n=i.getAnyComponent(sm).component;if(null!==n)for(let i=0;i<e;i++)t[i].updateShaderForTerrain(n,800),t.splice(i,1),i--,e--}__visit_component(t,e){const i=t.__shader;void 0!==i&&(i.uniforms.time.value+=this.__time_delta)}update(t){this.__time_delta=t;const e=this.entityManager.dataset;null!==e&&(this.processUpdateQueue(),e.traverseComponents(IS,this.__visit_component,this))}}function ZT(t){this.scripts=t instanceof Array?t:"function"==typeof t?[t]:[]}XT.RENDER_LAYER_NAME="water-system",ZT.typeName="Script",ZT.serializable=!1;const $T=new S;class KT{constructor(t,e){const i=t.component,n=new wd(0,0),s={panUp:!1,panDown:!1,panLeft:!1,panRight:!1},r=new GS;function a(i,n,s){i.forEach((i=>{r.mapping.add({path:"keyboard/keys/"+i+"/down",listener:()=>{n[s]=!0,e.sendEvent(t.entity,"user-input")}}),r.mapping.add({path:"keyboard/keys/"+i+"/up",listener:()=>n[s]=!1})}))}a(["down_arrow","s"],s,"panDown"),a(["up_arrow","w"],s,"panUp"),a(["left_arrow","a"],s,"panLeft"),a(["right_arrow","d"],s,"panRight"),r.on.unlinked.add((function(){s.panDown=!1,s.panUp=!1,s.panLeft=!1,s.panRight=!1}));const o=new ZT((function(r){if(n.set(0,0),s.panDown&&(n.y+=1),s.panUp&&(n.y-=1),s.panLeft&&(n.x-=1),s.panRight&&(n.x+=1),n.isZero())return;let a=n.clone().multiplyScalar(10*r);const o=e.getComponent(t.entity,Au);$T.set(-a.x,0,-a.y),$T.applyQuaternion(o.rotation),i.target.add($T)})),l=new z_;this.builder=l.add(r).add(Ux.Transient).add(BS.fromJSON(["Keyboard Camera Controller"])).add(o)}build(t){return this.builder.build(t)}}class QT{constructor(){this.systems=[],this.plugins=[],this.knowledge=[],this.loaders=new Map}hasLoader(t){return this.loaders.has(t)}addLoader(t,e){return!this.loaders.has(t)&&(this.loaders.set(t,e),!0)}removeLoader(t){const e=this.loaders.get(t);return void 0!==e&&this.loaders.delete(t),e}addPlugin(t){return this.plugins.push(t),!0}addSystem(t){return this.systems.push(t),!0}addManySystems(...t){t.forEach((t=>this.addSystem(t)))}addDataTable(t){return this.knowledge.push(t),!0}async apply(t){const e=[];this.loaders.forEach(((i,n)=>{e.push(t.assetManager.registerLoader(n,i))})),await Promise.all(e);const i=this.knowledge.length;for(let e=0;e<i;e++){const i=this.knowledge[e];t.staticKnowledge.add(i.id,i.source,i.table)}const n=t.plugins,s=this.plugins,r=s.length;for(let t=0;t<r;t++){const e=s[t];await n.acquire(e)}const a=t.entityManager,o=this.systems.length;for(let e=0;e<o;e++){const i=this.systems[e];t.entityManager.hasSystem(i.constructor)||await a.addSystem(i)}}}class tC extends Ym{load(t,e,i,n){!function(t,e,i){const n=new XMLHttpRequest;n.open("GET",t,!0),n.onreadystatechange=function(){n.readyState===XMLHttpRequest.DONE&&(200===n.status?e&&e(n.response):i&&i(n))},n.send()}(t,(function(t){let n;try{n=JSON.parse(t)}catch(t){return void i(t)}e({create:function(){return n}})}),i)}}class eC{constructor(){this.level=3}getLevel(){return this.level}setLevel(t){this.level=t}log(t,e){throw new Error("Abstract class, method needs to be implemented in the subclass")}}let iC;class nC extends eC{log(t,e){switch(t){case 1:case 0:case 2:return}}static get INSTANCE(){return void 0===iC&&(iC=new nC),iC}}function sC(){this.prevPosition={x:0,y:0,z:0},this.nodes={listener:null}}sC.typeName="SoundListener",sC.prototype.toJSON=function(){return{}},sC.prototype.fromJSON=function(t){},sC.prototype.toBinaryBuffer=function(t){},sC.prototype.fromBinaryBuffer=function(t){};let rC=null;function aC(){if(null!==rC)return rC;let t,e=navigator.userAgent,i=e.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(i[1]))return t=/\brv[ :]+(\d+)/g.exec(e)||[],{name:"IE",version:t[1]||""};if("Chrome"===i[1]&&(t=e.match(/\bOPR|Edge\/(\d+)/),null!=t))return{name:"Opera",version:t[1]};i=i[2]?[i[1],i[2]]:[navigator.appName,navigator.appVersion,"-?"],null!=(t=e.match(/version\/(\d+)/i))&&i.splice(1,1,t[1]);const n={name:i[0],version:i[1]};return rC=n,n}const oC=new S,lC=new S;class hC{constructor(){this.listener=null,this.transform=null,this.audioContext=null}link(){this.transform.position.onChanged.add(this.updatePosition,this),this.transform.rotation.onChanged.add(this.updateRotation,this),this.updatePosition(),this.updateRotation()}unlink(){this.transform.position.onChanged.remove(this.updatePosition,this),this.transform.rotation.onChanged.remove(this.updateRotation,this)}updateRotation(){const t=this.transform.rotation;oC.copy(S.forward),oC.applyQuaternion(t),lC.copy(S.up),lC.applyQuaternion(t);const e=this.audioContext.listener;pC(e,oC,lC)}updatePosition(){const t=this.audioContext.listener;dC(t,this.transform.position)}}class cC extends bm{constructor(t){super(),this.dependencies=[sC,Au],this.webAudioContext=t,this.data=[]}link(t,e,i){const n=new hC;n.transform=e,n.listener=t,n.audioContext=this.webAudioContext,n.link(),this.data[i]=n}unlink(t,e,i){const n=this.data[i];void 0!==n&&(delete this.data[i],n.unlink())}}function uC(t,e){let i,n,s;i=Number.isFinite(e.x)?e.x:0,n=Number.isFinite(e.y)?e.y:0,s=Number.isFinite(e.z)?e.z:0,t.setPosition(i,n,s)}let dC=function(t,e){};if(void 0!==navigator){const t=aC();"Chrome"===t.name?dC=t.version>=64?function(t,e){Number.isFinite(e.x)&&t.positionX.setValueAtTime(e.x,0),Number.isFinite(e.y)&&t.positionY.setValueAtTime(e.y,0),Number.isFinite(e.z)&&t.positionZ.setValueAtTime(e.z,0)}:uC:"Firefox"===t.name&&(dC=uC)}let pC=Jd;if(void 0!==navigator){const t=aC();"Chrome"===t.name?pC=function(t,e,i){t.forwardX.value=e.x,t.forwardY.value=e.y,t.forwardZ.value=e.z,t.upX.value=i.x,t.upY.value=i.y,t.upZ.value=i.z}:"Firefox"===t.name&&(pC=function(t,e,i){t.setOrientation(e.x,e.y,e.z,i.x,i.y,i.z)})}var fC=function(){var t=0,e=document.createElement("div");function i(t){return e.appendChild(t.dom),t}function n(i){for(var n=0;n<e.children.length;n++)e.children[n].style.display=n===i?"block":"none";t=i}e.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",e.addEventListener("click",(function(i){i.preventDefault(),n(++t%e.children.length)}),!1);var s=(performance||Date).now(),r=s,a=0,o=i(new fC.Panel("FPS","#0ff","#002")),l=i(new fC.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var h=i(new fC.Panel("MB","#f08","#201"));return n(0),{REVISION:16,dom:e,addPanel:i,showPanel:n,begin:function(){s=(performance||Date).now()},end:function(){a++;var t=(performance||Date).now();if(l.update(t-s,200),t>=r+1e3&&(o.update(1e3*a/(t-r),100),r=t,a=0,h)){var e=performance.memory;h.update(e.usedJSHeapSize/1048576,e.jsHeapSizeLimit/1048576)}return t},update:function(){s=this.end()},domElement:e,setMode:n}};fC.Panel=function(t,e,i){var n=Infinity,s=0,r=Math.round,a=r(window.devicePixelRatio||1),o=80*a,l=48*a,h=3*a,c=2*a,u=3*a,d=15*a,p=74*a,f=30*a,m=document.createElement("canvas");m.width=o,m.height=l,m.style.cssText="width:80px;height:48px";var _=m.getContext("2d");return _.font="bold "+9*a+"px Helvetica,Arial,sans-serif",_.textBaseline="top",_.fillStyle=i,_.fillRect(0,0,o,l),_.fillStyle=e,_.fillText(t,h,c),_.fillRect(u,d,p,f),_.fillStyle=i,_.globalAlpha=.9,_.fillRect(u,d,p,f),{dom:m,update:function(l,g){n=Math.min(n,l),s=Math.max(s,l),_.fillStyle=i,_.globalAlpha=1,_.fillRect(0,0,o,d),_.fillStyle=e,_.fillText(r(l)+" "+t+" ("+r(n)+"-"+r(s)+")",h,c),_.drawImage(m,u+a,d,p-a,f,u,d,p-a,f),_.fillRect(u+p-a,d,a,f),_.fillStyle=i,_.globalAlpha=.9,_.fillRect(u+p-a,d,a,r((1-l/g)*f))}}};class mC{constructor(){this.engine=new _S(new US),window.engine=this.engine,uS.addBackend(nC.INSTANCE),this.p=null}static addFpsCounter(t){const e=new fC;t.graphics.on.postRender.add(e.update,e);const i=new Ey({el:e.domElement});t.viewStack.addChild(i)}initialize({configuration:t=Jd,enable_localization:e=!1}={}){if(null!==this.p)return this.p;const i=this.engine,n=new Promise((async function(n,s){const r=new QT;if(t(r,i),r.hasLoader("json")||r.addLoader("json",new tC),await r.apply(i),await i.start(),e)try{await function(t){const e=kS();let i;return i=void 0!==e.lang?e.lang:"en-gb",t.localization.loadLocale(i)}(i)}catch(t){}i.sceneManager.create("test"),i.sceneManager.set("test"),document.body.appendChild(i.viewStack.el),i.viewStack.link(),document.body.style.margin="0",document.body.style.overflow="hidden",window.addEventListener(hx,(function t(){window.removeEventListener(hx,t),i.sound.resumeContext()})),n(i)}));return this.p=n,n}static buildCamera({engine:t,ecd:e=t.entityManager.dataset,target:i=new S,distance:n=10,pitch:s=1.4,yaw:r=0,autoClip:a=!1,distanceMin:o=0,distanceMax:l=1e3,fieldOfView:h=45}){const c=t.entityManager;null===c.getSystem(HS)&&c.addSystem(new HS),null===c.getSystem(Jm)&&c.addSystem(new Jm(t.graphics.scene,t.graphics)),null===c.getSystem(cC)&&c.addSystem(new cC(t.sound.context)),e.isComponentTypeRegistered(BS)||e.registerComponentType(BS);const u=new Au,d=new AS;d.pitch=s,d.yaw=r,d.distance=n,d.distanceMin=o,d.distanceMax=l,d.target.copy(i);const p=new Pm;p.active.set(!0),p.autoClip=a,p.clip_far=l,p.fov.set(h);const f=new z_;return f.add(u).add(d).add(p).add(new sC).add(BS.fromJSON(["Camera"])).build(e),f}static async buildBasics({engine:t,focus:e=new S(10,0,10),heightMap:i,heightRange:n,pitch:s=.7,yaw:r=-1.2,distance:a=10,terrainSize:o=new wd(10,10),terrainResolution:l=10,enableWater:h=!0,enableTerrain:c=!0,enableLights:u=!0,cameraFieldOfView:d,cameraFarDistance:p,cameraController:f=!0,cameraAutoClip:m=!1,shadowmapResolution:_,showFps:g=!0}){g&&mC.addFpsCounter(t),u&&await mC.buildLights({engine:t,shadowmapResolution:_});const y=mC.buildCamera({engine:t,target:e,pitch:s,yaw:r,distance:a,fieldOfView:d,distanceMax:p,autoClip:m}).entity;if(c&&await mC.buildTerrain({engine:t,heightMap:i,heightRange:n,resolution:l,size:o,enableWater:h}),f){mC.buildOrbitalCameraController({engine:t,cameraEntity:y});const e=t.entityManager.dataset;new KT({component:e.getComponent(y,AS),entity:y},e).build(e)}}static async buildLights({engine:t,ecd:e=t.entityManager.dataset,shadowmapResolution:i=1024}){const n=t.entityManager;n.hasSystem(UT)||await n.addSystem(new UT(t,{shadowResolution:i})),e.isComponentTypeRegistered(BS)||e.registerComponentType(BS);const s=new zS;s.type.set(zS.Type.DIRECTION),s.color.setRGB(1,1,1),s.intensity.set(.8),s.castShadow.set(!0);const r=new Au;r.position.set(30,70,30),r.rotation.set(-.18780341950959473,.8049745556929917,-.4533975611897181,-.3334313787830773),(new z_).add(s).add(r).add(BS.fromJSON(["Light","Key"])).build(e);const a=new zS;a.type.set(zS.Type.AMBIENT),a.color.setRGB(1,1,1),a.intensity.set(.1),(new z_).add(a).add(new Au).add(BS.fromJSON(["Light","Ambient"])).build(e)}static async buildOrbitalCameraController({cameraEntity:t,engine:e,ecd:i=e.entityManager.dataset,sensitivity:n=.01}){void 0===t&&(t=i.getAnyComponent(Pm).entity);const s=e.entityManager;null===s.getSystem(YT)&&await s.addSystem(new YT(e.devices)),i.isComponentTypeRegistered(Ux)||i.registerComponentType(Ux);const r=e.graphics.domElement;r.addEventListener("contextmenu",(t=>{t.preventDefault()}));const a=function({camera_entity:t,ecd:e,dom_element:i,sensitivity:n=.01}){function s(){return e.getComponent(t,AS)}const r=new GS([{path:"pointer/on/tap",listener(t,e){}},{path:"pointer/on/down",listener(t,e){}},{path:"pointer/on/drag",listener:function(r,a,o,l){const h=o.clone().sub(r),c=function(t){const e=[];for(let i=0;i<32;i++){const n=t>>i;e[i]=0!=(1&n)}return e}(l.buttons);c[0]?function(n){const r=n.clone(),a=s(),o=e.getComponent(t,Pm);AS.pan(r,o.object,i,a.distance,o.object.fov,a.target)}(h):function(t){const e=s();TS(t.x*n,t.y*n,e,e)}(h),l.preventDefault()}},{path:"pointer/on/wheel",listener(t,e){!function(t){const e=s(),i=e.distance+t;e.distance=y(i,e.distanceMin,e.distanceMax)}(t.y)}}]),a=new z_;return a.add(r),a}({camera_entity:t,ecd:i,dom_element:r,sensitivity:n});return a.add(BS.fromJSON(["CameraController"])),a.add(Ux.Transient),a.build(i),a}static async buildTerrain({engine:t,size:e=new wd(10,10),diffuse0:i="data/textures/utility/checkers_dark_grey_256x256.png",heightMap:n="data/textures/utility/white_pixel.png",heightRange:s=0,resolution:r=10,waterLevel:a=0,enableWater:o=!0}){const l=t.entityManager;null===l.getSystem(d_)&&await l.addSystem(new d_(t.graphics,t.assetManager));const h=new sm;h.size.copy(e),h.resolution=r,h.gridScale=2,h.layers.addLayer(sf.from(i,5,5)),h.splat.resize(1,1,1),h.splat.fillLayerWeights(0,255),h.heightMapURL=n,h.build(t.assetManager);const c=new z_;if(c.add(new Au),c.add(h),o){null===l.getSystem(XT)&&l.addSystem(new XT(t.graphics));const e=new IS;e.level.set(a),c.add(e)}return c.build(t.entityManager.dataset),h}}let _C=null;mC.getSingleton=function(){return null===_C&&(_C=new mC),_C};class gC extends qx{constructor(){super(),this.__currentBehaviour=null,this.__currentBehaviourIndex=-1}static from(t){const e=new gC;return t.forEach(e.addChild,e),e}tick(t){if(this.__children.length<1)return Vx.Failed;for(;;){const e=this.__currentBehaviour.tick(t);if(e!==Vx.Failed)return e;this.__currentBehaviour.finalize();const i=this.__children;if(this.__currentBehaviourIndex++,this.__currentBehaviourIndex>=i.length)return this.__currentBehaviour=null,Vx.Failed;this.__currentBehaviour=i[this.__currentBehaviourIndex],this.__currentBehaviour.initialize(this.context)}}finalize(){null!==this.__currentBehaviour&&(this.__currentBehaviour.finalize(),this.__currentBehaviour=null)}initialize(t){super.initialize(t);const e=this.__children;e.length>0?(this.__currentBehaviourIndex=0,this.__currentBehaviour=e[0],this.__currentBehaviour.initialize()):(this.__currentBehaviourIndex=-1,this.__currentBehaviour=null)}}const yC={RequireOne:0,RequireAll:1};class vC extends qx{constructor(t,e){super(),this.successPolicy=t,this.failurePolicy=e,this.activeSet=new g_,this.successCount=0,this.failureCount=0}getSuccessPolicy(){return this.successPolicy}setSuccessPolicy(t){this.successPolicy=t}getFailurePolicy(){return this.failurePolicy}setFailurePolicy(t){this.failurePolicy=t}tick(t){const e=this.activeSet,i=this.__children,n=i.length;let s;for(s=0;s<n;s++){if(!e.get(s))continue;const n=i[s],r=n.tick(t);if(r===Vx.Succeeded){if(e.set(s,!1),this.successCount++,n.finalize(),this.successPolicy===yC.RequireOne)return this.__finalizeActiveChildren(),Vx.Succeeded}else if(r===Vx.Failed){if(e.set(s,!1),this.failureCount++,n.finalize(),this.failurePolicy===yC.RequireOne)return this.__finalizeActiveChildren(),Vx.Failed;if(this.successPolicy===yC.RequireAll)return this.__finalizeActiveChildren(),Vx.Failed}}return this.successCount===n&&this.successPolicy===yC.RequireAll?Vx.Succeeded:this.failureCount===n&&this.failurePolicy===yC.RequireAll||this.failureCount+this.successCount===n?Vx.Failed:Vx.Running}initialize(t){this.successCount=0,this.failureCount=0;const e=this.__children,i=e.length;for(let n=0;n<i;n++)e[n].initialize(t),this.activeSet.set(n,!0);super.initialize(t)}__finalizeActiveChildren(){const t=this.__children,e=this.activeSet;for(let i=e.nextSetBit(0);-1!==i;i=e.nextSetBit(i+1))t[i].finalize()}finalize(){this.__finalizeActiveChildren()}static from(t,e=yC.RequireAll,i=yC.RequireOne){const n=new vC(e,i);return t.forEach((t=>n.addChild(t))),n}}vC.prototype.isParallelBehavior=!0,vC.typeName="ParallelBehavior";class xC{constructor(t){this.referenceCount=0,this.type=t,this.value=function(t){let e;switch(t){case Hw.Number:e=new Id(0);break;case Hw.Boolean:e=new Mm(!1);break;case Hw.String:e=new Ld("");break;default:throw new TypeError(`Unsupported data type '${t}'`)}return e}(t)}}class wC{contains(t,e){throw new Error("Not implemented")}getKeys(){throw new Error("Not implemented")}acquire(t,e,i){throw new Error("Not implemented")}release(t){throw new Error("Not implemented")}acquireBoolean(t,e=!1){return this.acquire(t,Hw.Boolean,e)}acquireNumber(t,e=0){return this.acquire(t,Hw.Number,e)}incrementNumber(t,e=1){this.acquireNumber(t)._add(e),this.release(t)}acquireString(t,e=""){return this.acquire(t,Hw.String,e)}}class bC extends wC{constructor(){super(),this.on={added:new l},this.data={},this.proxy=new Proxy(this,{get(t,e,i){if(t.contains(e,Hw.Any))return t.acquire(e,Hw.Any).getValue()},set(t,e,i,n){const s=function(t){switch(typeof t){case"number":return Hw.Number;case"string":return Hw.String;case"boolean":return Hw.Boolean;default:if(Array.isArray(t))return Hw.Array;throw new Error(`Unsupported value type for value '${t}'`)}}(i);return t.acquire(e,s,i).set(i),!0},ownKeys:t=>t.getKeys()})}getKeys(){return Reflect.ownKeys(this.data)}getValueProxy(){return this.proxy}contains(t,e){const i=this.data[t];return void 0!==i&&(e===Hw.Any||i.type===e)}traverse(t,e){for(let i in this.data){if(!this.data.hasOwnProperty(i))continue;const n=this.data[i];t.call(e,i,n.value,n.type)}}traverseWithPattern(t,e){this.traverse((function(i,n,s){t.test(i)&&e(i,n,s)}))}acquire(t,e,i){let n;if(this.data.hasOwnProperty(t)){if(n=this.data[t],e!==Hw.Any&&n.type!==e)throw new TypeError(`Value '${t}' exists, but is type(='${n.type}'), expected type '${e}'`)}else{n=new xC(e);const s=n.value;void 0!==i&&s.set(i),this.data[t]=n,this.on.added.send4(t,s.getValue(),e,this)}return n.referenceCount++,n.value}release(t){this.data[t].referenceCount--}reset(){this.data={}}copy(t){this.reset(),t.traverse(((t,e,i)=>{this.acquire(t,i,e.getValue())}))}clone(){const t=new bC;return t.copy(this),t}toJSON(){const t={};return this.traverse(((e,i,n)=>{t[e]=i.toJSON()})),t}fromJSON(t){this.reset();for(let e in t){const i=t[e],n=typeof i;"number"===n?this.acquireNumber(e,i).set(i):"boolean"===n?this.acquireBoolean(e,i).set(i):"string"===n&&this.acquireString(e,i).set(i)}}}bC.typeName="Blackboard",t.AmbientOcclusionPostProcessEffect=class extends Hg{constructor(){super(),this.id="ambient-occlusion-post-process";const t=Object.assign({},jg.defines);this.__material=new Ws({defines:t,fragmentShader:jg.fragmentShader,vertexShader:jg.vertexShader,uniforms:Gs.clone(jg.uniforms),glslVersion:ui,depthWrite:!1,depthTest:!1});const e=this.__material.uniforms;e.bias.value=.5,e.intensity.value=2,e.kernelRadius.value=30,e.minResolution.value=0,this.__material.blending=F,this.__material.extensions.derivatives=!0,t.DEPTH_PACKING=0,t.NORMAL_TEXTURE=0,t.PERSPECTIVE_CAMERA=1,t.NUM_SAMPLES=13,t.NUM_RINGS=5,this.__use_normals=!1,this.__resolution_scale=.5,this.__composit_layer=null,this.__render_camera=null,this.__render_target=new Pi(1,1,{minFilter:Nt,magFilter:Nt,format:te,type:Ft,internalFormat:"R8",depthBuffer:!1,stencilBuffer:!1,generateMipmaps:!1}),this.__used_buffers=[],this.__blur=new ny({format:te,clear_color:16777215})}set intensity(t){this.__material.uniforms.intensity.value=t}get intensity(){return this.__material.uniforms.intensity.value}__setCamera(t){this.__render_camera=t;const e=this.__material,i=e.defines;!0===t.isPerspectiveCamera&&1!==i.PERSPECTIVE_CAMERA?(i.PERSPECTIVE_CAMERA=1,e.needsUpdate=!0):!0!==t.isPerspectiveCamera&&0!==i.PERSPECTIVE_CAMERA&&(i.PERSPECTIVE_CAMERA=0,e.needsUpdate=!0),this.__blur.setRenderCamera(t)}initialize(t){this.__blur.configureMaterials(),super.initialize(t)}finalize(){super.finalize()}__prepare_uniforms(){const t=this.__material,e=t.uniforms,i=this.__render_camera;e.size.value.set(this.__render_target.width,this.__render_target.height);const n=i.near,s=i.far;e.cameraNear.value=n,e.cameraFar.value=s,e.cameraInverseProjectionMatrix.value.copy(i.projectionMatrixInverse),e.cameraProjectionMatrix.value.copy(i.projectionMatrix),t.uniformsNeedUpdate=!0}__prepare_draw(){const t=this.engine.graphics.camera;this.__setCamera(t),this.__prepare_uniforms()}__render(){const t=this.engine.graphics.renderer;this.__prepare_draw();const e=t.getRenderTarget();t.setRenderTarget(this.__render_target),t.clearColor(),ey(t,this.__material),t.setRenderTarget(e),this.__blur.execute(t)}setNormalBufferUsage(t){if(t===this.__use_normals)return;this.__use_normals=t;const e=this.__material,i=e.uniforms,n=e.defines,s=this.engine.graphics.frameBuffers.getById(ry);t?(i.tNormal.value=s.getRenderTarget().texture,this.__add_used_frame_buffer(s),n.NORMAL_TEXTURE=1):(i.tNormal.value=null,this.__remove_used_frame_buffer(s),n.NORMAL_TEXTURE=0),e.needsUpdate=!0}__add_used_frame_buffer(t){this.__used_buffers.includes(t)||(t.referenceCount++,this.__used_buffers.push(t))}__remove_used_frame_buffer(t){const e=this.__used_buffers.indexOf(t);-1!==e&&(t.referenceCount--,this.__used_buffers.splice(e,1))}__update_render_target_size(){const t=this.engine.graphics.viewport.size,e=Math.ceil(t.x*this.__resolution_scale),i=Math.ceil(t.y*this.__resolution_scale);this.__render_target.setSize(e,i)}async startup(){const t=this.engine.graphics;this.__composit_layer=t.layerComposer.createLayer({format:te,type:Ft,internalFormat:"R8"},Iu.Multiply),this.__composit_layer.name="Ambient Occlusion",this.__composit_layer.stage=1;const e=this.__material.uniforms,i=t.frameBuffers.getById(sy).getRenderTarget().depthTexture;return e.tDepth.value=i,this.__use_normals&&(this.__use_normals=!1,this.setNormalBufferUsage(!0)),this.__composit_layer.on.preRender.add(this.__render,this),t.viewport.size.onChanged.add(this.__update_render_target_size,this),this.__update_render_target_size(),this.__blur.setDepthBuffer(i),this.__blur.setInput(this.__render_target),this.__blur.setOutput(this.__composit_layer.renderTarget),super.startup()}async shutdown(){const t=this.engine.graphics;return t.layerComposer.remove(this.__composit_layer),this.__composit_layer.on.preRender.remove(this.__render,this),t.viewport.size.onChanged.add(this.__update_render_target_size,this),this.__blur.dispose(),this.__render_target.dispose(),super.shutdown()}},t.Behavior=Gx,t.BehaviorStatus=Vx,t.Blackboard=bC,t.Cache=Qp,t.EngineConfiguration=QT,t.EngineHarness=mC,t.EntityBuilderFlags=A_,t.ForwardPlusRenderingPlugin=bT,t.HashMap=$p,t.Light=zS,t.ParallelBehavior=vC,t.ParallelBehaviorPolicy=yC,t.SGMesh=xm,t.SGMeshSystem=class extends bm{constructor(t){super(),this.__engine=t,this.__assetManager=t.assetManager,this.dependencies=[xm,Au],this.__wait_queue=[],this.__wait_queue_process_index=0,this.__asset_object_cache=new Map}async startup(t,e,i){t.hasSystem(O_)||await t.addSystem(new O_),super.startup(t,e,i)}async process(t,e,i){const n=this.__assetManager,s=this.entityManager.dataset,r=function(t){const e=t.lastIndexOf(".");if(-1===e)return null;switch(t.substring(e+1)){case"json":return"three.js";case"glb":return"model/gltf";case"gltf":return"model/gltf+json";default:return null}}(e.url);let a,o;try{a=await n.promise(e.url,r)}catch(e){return void s.sendEvent(t,"@ecd-component-SGMesh/asset-failed")}if(!s.entityExists(t))return;if(s.getComponent(t,xm)!==e)return;void 0!==a.boundingBox&&(e.__initial_bounds.copy(a.boundingBox),a.has_root_transform&&e.__initial_bounds.applyMatrix4(a.root_transform.matrix));const l=this.__asset_object_cache.get(a);void 0!==l?o=l:(o=a.create(),this.__asset_object_cache.set(a,o));let h=F_(o);if(a.has_root_transform){const t=new P_;t.entity.add(new Au),h.transform.copy(a.root_transform),t.addChild(h),h=t}function c(){h.transform.copy(i)}h.entity.add(p_.from(t)),e.__node=h,c(),h.build(s),i.position.onChanged.add(c),i.rotation.onChanged.add(c),i.scale.onChanged.add(c),h.on.destroyed.addOne((()=>{i.position.onChanged.remove(c),i.rotation.onChanged.remove(c),i.scale.onChanged.remove(c)})),h.traverse((t=>{const i=t.entity.getComponent(_m);null!==i&&(i.writeFlag(2,e.castShadow),i.writeFlag(4,e.receiveShadow))})),s.sendEvent(t,"@ecd-component-SGMesh/asset-attached")}link(t,e,i){const n=e.position;t.__initial_bounds.setBounds(n.x,n.y,n.z,n.x,n.y,n.z),null!==t.url?this.process(i,t,e):this.__wait_queue.push(i)}unlink(t,e,i){null!==t.__node&&(t.__node.destroy(),t.__node=null);const n=this.__wait_queue.indexOf(i);-1!==n&&this.__wait_queue.splice(n,1)}update(t){const e=this.entityManager.dataset;if(null===e)return;const i=this.__wait_queue;let n=i.length;if(n>0){const t=performance.now();let s=this.__wait_queue_process_index;const r=s+ru(n,128);for(;s<r;){const r=s%n;s++;const a=i[r],o=e.getComponent(a,xm);if(null===o.url)continue;i.splice(r,1);const l=e.getComponent(a,Au);if(this.process(a,o,l),performance.now()-t>40)break}this.__wait_queue_process_index=s}}},t.SelectorBehavior=gC,t.SequenceBehavior=Jx,t.ShadedGeometry=_m,t.ShadedGeometrySystem=class extends bm{constructor(t){super(),this.dependencies=[_m,Au],this.__engine=t,this.__render_layer=null,this.__view_contexts=new Map,this.__adapter_suppliers=new Map,this.__geometry_usage_counters=new Map,this.__bvh_binary=new Sg;const e=new kg;this.__optimization_task=new Mf({name:"ShadedGeometry Draw Method optimizer",initializer:()=>{e.__system=this},cycleFunction:()=>e.step()?bf.Continue:bf.Yield}),this.__maintenance_task=function(t,e,i=bf.Continue){return new Mf({name:t,cycleFunction:()=>e.next().done?bf.EndSuccess:i})}("Maintenance",function*(t){for(;;){const e=t.__view_contexts;for(const[t,i]of e)void 0!==i&&(yield*i.maintain());yield}}(this),bf.Yield)}get bvh(){return this.__bvh_binary}getGeometryUsageCounters(){return this.__geometry_usage_counters}register_render_adapter(t,e){this.__adapter_suppliers.has(t)&&this.unregister_render_adapter(t),this.__adapter_suppliers.set(t,e),this.__view_contexts.forEach(((i,n)=>{i.setAdapter(t,e())}))}unregister_render_adapter(t){return void 0!==this.__adapter_suppliers.get(t)&&(this.__adapter_suppliers.delete(t),this.__view_contexts.forEach(((e,i)=>{e.removeAdapter(t)})),!0)}__handle_view_added(t){const e=new Ng;this.__adapter_suppliers.forEach(((t,i)=>{e.setAdapter(i,t())})),this.__view_contexts.set(t,e)}__handle_view_removed(t){const e=this.__view_contexts.get(t);this.__view_contexts.delete(t),e.dispose()}async startup(t,e,i){this.entityManager=t;const n=this.__engine,s=n.graphics,r=s.views.elements;r.forEach(this.__handle_view_added,this),r.on.added.add(this.__handle_view_added,this),r.on.removed.add(this.__handle_view_removed,this),this.__render_layer=s.layers.create("shaded-geometry"),this.__render_layer.buildVisibleSet=(e,i,n)=>{const r=this.__view_contexts.get(n),a=t.dataset;return null===a?0:r.collect(e,i,s.renderer,n,this.__bvh_binary,a)},this.__optimization_task.state.set(Sf.INITIAL),n.executor.run(this.__optimization_task),this.__maintenance_task.state.set(Sf.INITIAL),n.executor.run(this.__maintenance_task),e()}async shutdown(t,e,i){const n=this.__engine,s=n.graphics.views.elements;n.executor.removeTask(this.__optimization_task),n.executor.removeTask(this.__maintenance_task),s.forEach(this.__handle_view_removed,this),s.on.added.remove(this.__handle_view_added,this),s.on.removed.remove(this.__handle_view_removed,this),e()}link(t,e,i){t.__c_transform=e,t.update_bounds(),e.position.onChanged.add(t.updateTransform,t),e.rotation.onChanged.add(t.updateTransform,t),e.scale.onChanged.add(t.updateTransform,t),t.__entity=i;const n=this.__bvh_binary,s=n.allocate_node();n.node_set_aabb(s,t.__bvh_aabb),n.node_set_user_data(s,i),n.insert_leaf(s),t.__bvh_tree=n,t.__bvh_leaf_id=s;const r=t.geometry.id,a=this.__geometry_usage_counters.get(r),o=void 0!==a?a+1:1;this.__geometry_usage_counters.set(r,o)}unlink(t,e,i){e.position.onChanged.remove(t.updateTransform,t),e.rotation.onChanged.remove(t.updateTransform,t),e.scale.onChanged.remove(t.updateTransform,t);const n=t.__bvh_leaf_id;this.__bvh_binary.remove_leaf(n),this.__bvh_binary.release_node(n),t.__bvh_leaf_id=-1,t.__bvh_tree=null;const s=t.geometry.id,r=this.__geometry_usage_counters.get(s);1===r?(this.__geometry_usage_counters.delete(s),t.geometry.dispose()):this.__geometry_usage_counters.set(s,r-1)}queryOverlapFrustum(t,e,i){return zg(t,e,this.__bvh_binary,i)}raycast(t,e,i,n,s,r,a=Yd,o){const l=[],h=[],c=Fg(h,0,this.__bvh_binary,Rg.from([t,e,i,n,s,r])),u=this.entityManager.dataset;if(null===u)return l;const d=u.computeComponentTypeIndex(_m);for(let p=0;p<c;p++){const c=h[p],f=this.__bvh_binary.node_get_user_data(c),m=u.getComponentByIndex(f,d);if(!a.call(o,f,m))continue;const _=m.transform;dp(Bg,t,e,i,n,s,r),m.query_raycast_nearest(Ug,Bg,_)&&l.push({entity:f,mesh:m,contact:Ug.clone()})}return l}raycastNearest(t,e,i,n,s,r,a,o=Yd,l){let h=Infinity,c=!1,u=null;const d=[],p=Fg(d,0,this.__bvh_binary,Rg.from([e,i,n,s,r,a])),f=this.entityManager.dataset;if(null===f)return;const m=f.computeComponentTypeIndex(_m);for(let _=0;_<p;_++){const p=d[_],g=this.__bvh_binary.node_get_user_data(p),y=f.getComponentByIndex(g,m);if(!o.call(l,g,y))continue;const v=y.transform;if(dp(Bg,e,i,n,s,r,a),!y.query_raycast_nearest(Ug,Bg,v))continue;c=!0;const x=Ug.position,w=R_(x.x,x.y,x.z,e,i,n);w<h&&(t.copy(Ug),u=y,h=w)}return c?{entity:u.__entity,mesh:u}:void 0}},t.Signal=l,t.SignalBinding=Rm,t.Transform=Au,t.dispatchViaProxy=d,t.findSignalHandlerIndexByHandle=h,t.findSignalHandlerIndexByHandleAndContext=c,t.quat3_createFromAxisAngle=function(t,e,i){const n=.5*e,s=Math.sin(n);i.set(t.x*s,t.y*s,t.z*s,Math.cos(n))},t.quat_array_from_look=function(t,e,i,n,s,r,a){ou.set(e,i,n),ou.normalize(),hu._crossVectors(s,r,a,ou.x,ou.y,ou.z),hu.normalize(),lu.crossVectors(ou,hu);var o=hu.x,l=hu.y,h=hu.z,c=lu.x,u=lu.y,d=lu.z,p=ou.x,f=ou.y,m=ou.z;const _=o+u+m;let g,y,v,x;if(_>0){let t=Math.sqrt(_+1);x=.5*t,t=.5/t,g=(d-f)*t,y=(p-h)*t,v=(l-c)*t}else if(o>=u&&o>=m){var w=Math.sqrt(1+o-u-m),b=.5/w;g=.5*w,y=(l+c)*b,v=(h+p)*b,x=(d-f)*b}else if(u>m){var S=Math.sqrt(1+u-o-m),M=.5/S;g=(c+l)*M,y=.5*S,v=(f+d)*M,x=(p-h)*M}else{var T=Math.sqrt(1+m-o-u),C=.5/T;g=(p+h)*C,y=(f+d)*C,v=.5*T,x=(l-c)*C}t[0]=g,t[1]=y,t[2]=v,t[3]=x},t.v2_angleBetween=function(t,e,i,n){const s=y(bd(t,e,i,n)/(Md(t,e)*Md(i,n)),-1,1);return Math.acos(s)},t.v2_bearing_angle_towards=function(t,e,i,n){let s=Math.atan2(i-t,e-n);return s<0&&(s+=6.283185307179586),s},t.v2_distance=Td,t.v2_dot=bd,t.v2_length_sqr=Sd,t.v2_magnitude=Md,t.v4_applyMatrix4=function(t,e,i){const n=i[0],s=i[1],r=i[2],a=i[3],o=i[4],l=i[5],h=i[6],c=i[7],u=i[8],d=i[9],p=i[10],f=i[11],m=i[12],_=i[13],g=i[14],y=i[15],v=e[0],x=e[1],w=e[2],b=e[3],S=n*v+o*x+u*w+m*b,M=s*v+l*x+d*w+_*b,T=r*v+h*x+p*w+g*b,C=a*v+c*x+f*w+y*b;t[0]=S,t[1]=M,t[2]=T,t[3]=C},t.v4_distance_sqr=function(t,e,i,n,s,r,a,o){return Ed(t-s,e-r,i-a,n-o)},t.v4_dot=Ad,t.v4_length_sqr=Ed}));
|