@woosh/meep-engine 2.85.17 → 2.85.19
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/bundle-worker-image-decoder.js +1 -0
- package/build/bundle-worker-terrain.js +1 -0
- package/build/meep.cjs +116722 -0
- package/build/meep.min.js +1 -0
- package/build/meep.module.js +116685 -0
- package/package.json +1 -1
- package/src/generation/theme/ThemeEngine.d.ts +10 -0
- package/src/generation/theme/ThemeEngine.d.ts.map +1 -1
- package/src/generation/theme/ThemeEngine.js +94 -62
|
@@ -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}class n{appendDescriptionOf(t){throw new Error("Not Implemented")}appendList(t,e,i,n){throw new Error("Not Implemented")}appendText(t){throw new Error("Not Implemented")}appendValue(t){throw new Error("Not Implemented")}appendValueList(t,e,i,n){throw new Error("Not Implemented")}}class s{describeTo(t){throw new Error("Not Implemented")}}class r extends s{value;constructor(t){super(),this.value=t}describeTo(t){t.appendValue(this.value)}}class a{#t;constructor(t){this.#t=t}*[Symbol.iterator](){for(const t of this.#t)yield new r(t)}}class o extends n{appendDescriptionOf(t){return t.describeTo(this),this}#e(t){this.appendText('"'),this.appendText(t),this.appendText('"')}appendValue(t){return null==t?this.appendText("null"):void 0===t?this.appendText("undefined"):"string"==typeof t?this.#e(t):"number"==typeof t?this.appendText(function(t){return String(t)}(t)):Array.isArray(t)?this.appendValueList("[",", ","]",t):(this.appendText("<"),this.appendText(function(t){try{return String(t)}catch(t){return"VALUE@0"}}(t)),this.appendText(">")),this}appendValueList(t,e,i,n){return this.appendList(t,e,i,new a(n)),this}appendList(t,e,i,n){let s=!1;this.appendText(t);const r=n[Symbol.iterator]();for(let t=r.next();!0!==t.done;t=r.next())s&&this.appendText(e),this.appendDescriptionOf(t.value),s=!0;return this.appendText(i),this}}class l extends o{value="";appendText(t){return this.value+=t,this}}function h(t,e){if(!t)throw new Error(e||"AssertionError")}function c(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}h.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(", ")}]`)},h.notEqual=function(t,e,i){h(t!==e,i)},h.notOk=function(t,e){h(!t,e)},h.equal=function(t,e,i){if(t!==e)throw new Error(void 0!==i?i:`${t} !== ${e}`)},h.logicalyEqual=function(t,e,i){},h.ok=h,h.greaterThan=function(t,e,i){if(!(t>e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} > ${e}.`,new Error(n)}},h.greaterThanOrEqual=function(t,e,i){if(!(t>=e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} >= ${e}.`,new Error(n)}},h.lessThan=function(t,e,i){if(!(t<e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} < ${e}.`,new Error(n)}},h.lessThanOrEqual=function(t,e,i){if(!(t<=e)){let n="";throw void 0!==i&&(n+=i+". "),n+=`Expected ${t} <= ${e}.`,new Error(n)}},h.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})`)},h.arrayHas=function(t,e,i="Array does not contain the item"){},h.arrayHasNo=function(t,e,i="Array contains the item"){},h.arrayEqual=function(t,i,n="Arrays are not equal"){if(!e(t,i))throw new Error(n)},h.isInstanceOf=function(t,e,i="value",n=e.name){},h.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})`)},h.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})`)},h.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})`)},h.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})`)},h.isInteger=function(t,e="value"){if(!Number.isInteger(t))throw new Error(`${e} must be an integer, instead was ${t}`)},h.isNonNegativeInteger=function(t,e="value"){if(t<0)throw new Error(`${e} must be >= 0, instead was ${t}`)},h.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}')`)},h.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}')`)},h.defined=function(t,e="value"){if(void 0===t)throw new Error(`${e} is undefined`)},h.isNull=function(t,e){if(null!==t)throw new Error(`${e} is NOT null`)},h.notNull=function(t,e="value"){if(null===t)throw new Error(`${e} is null`)},h.notNaN=function(t,e="value"){if(Number.isNaN(t))throw new Error(`${e} must be a valid number, instead was NaN`)},h.isFiniteNumber=function(t,e="value"){if(!Number.isFinite(t))throw new Error(`${e} must be a finite number, instead was ${t}`)},h.that=function(t,e,i){if(i.matches(t))return;const n=new l;throw n.appendText(`Expected ${e} to be `),i.describeTo(n),n.appendText(" instead "),i.describeMismatch(t,n),new Error(n.value)};const u=Math.hypot,d=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);let p=null,f=16;class m{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}}m.prototype.isSignalHandler=!0;const _=[];let g=0;class y{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!==v(this.handlers,t)}mute(){this.setFlag(1)}unmute(){this.clearFlag(1)}hasHandlers(){return this.handlers.length>0}addOne(t,e){const i=new m(t,e);i.setFlag(1),this.handlers.push(i)}add(t,e){const i=new m(t,e);this.handlers.push(i)}remove(t,e){return void 0===e?function(t,e){const i=t.handlers;let n=v(i,e);return n>=0&&(i.splice(n,1),!0)}(this,t):function(t,e,i){const n=t.handlers;let s=x(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.setFlag(2),b(this.handlers,t),this.clearFlag(2))}send0(){if(0!=(1&this.flags))return;const t=this.handlers,e=t.length,i=g,n=i+e;let s,r;for(g=n,s=0;s<e;s++)_[i+s]=t[e-(s+1)];for(s=n-1;s>=i;s--){if(r=_[s],r.getFlag(1)){const e=t.indexOf(r);t.splice(e,1)}const e=r.handle;try{e.call(r.context)}catch(t){}}g=i}send1(t){if(0!=(1&this.flags))return;const e=this.handlers,i=e.length,n=g,s=n+i;let r,a;for(g=s,r=0;r<i;r++)_[n+r]=e[i-(r+1)];for(r=s-1;r>=n;r--){if(a=_[r],a.getFlag(1)){const t=e.indexOf(a);e.splice(t,1)}const i=a.handle;try{i.call(a.context,t)}catch(t){}}g=n}send2(t,e){if(0!=(1&this.flags))return;const i=this.handlers,n=i.length,s=g,r=s+n;let a,o;for(g=r,a=0;a<n;a++)_[s+a]=i[n-(a+1)];for(a=r-1;a>=s;a--){if(o=_[a],o.getFlag(1)){const t=i.indexOf(o);i.splice(t,1)}const n=o.handle;try{n.call(o.context,t,e)}catch(t){}}g=s}send3(t,e,i){if(0!=(1&this.flags))return;const n=this.handlers,s=n.length,r=g,a=r+s;let o,l;for(g=a,o=0;o<s;o++)_[r+o]=n[s-(o+1)];for(o=a-1;o>=r;o--){if(l=_[o],l.getFlag(1)){const t=n.indexOf(l);n.splice(t,1)}const s=l.handle;try{s.call(l.context,t,e,i)}catch(t){}}g=r}send4(t,e,i,n){if(0!=(1&this.flags))return;const s=this.handlers,r=s.length,a=g,o=a+r;let l,h;for(g=o,l=0;l<r;l++)_[a+l]=s[r-(l+1)];for(l=o-1;l>=a;l--){if(h=_[l],h.getFlag(1)){const t=s.indexOf(h);s.splice(t,1)}const r=h.handle;try{r.call(h.context,t,e,i,n)}catch(t){}}g=a}send6(t,e,i,n,s,r){if(0!=(1&this.flags))return;const a=this.handlers,o=a.length,l=g,h=l+o;let c,u;for(g=h,c=0;c<o;c++)_[l+c]=a[o-(c+1)];for(c=h-1;c>=l;c--){if(u=_[c],u.getFlag(1)){const t=a.indexOf(u);a.splice(t,1)}const o=u.handle;try{o.call(u.context,t,e,i,n,s,r)}catch(s){}}g=l}send8(t,e,i,n,s,r,a,o){if(0!=(1&this.flags))return;const l=this.handlers,h=l.length,c=g,u=c+h;let d,p;for(g=u,d=0;d<h;d++)_[c+d]=l[h-(d+1)];for(d=u-1;d>=c;d--){if(p=_[d],p.getFlag(1)){const t=l.indexOf(p);l.splice(t,1)}const h=p.handle;try{h.call(p.context,t,e,i,n,s,r,a,o)}catch(s){}}g=c}isDispatching(){return this.getFlag(2)}merge(t){const e=new y;function i(){e.dispatch(arguments)}return this.add(i),t.add(i),e}}function v(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 x(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 w(t,e,i){try{t.apply(e,i)}catch(t){}}function b(t,e){const i=t.length,n=g,s=n+i;let r,a;for(g=s,r=0;r<i;r++)_[n+r]=t[i-(r+1)];for(r=s-1;r>=n;r--){if(a=_[r],a.getFlag(1)){const e=t.indexOf(a);t.splice(e,1)}w(a.handle,a.context,e)}g=n}function S(t,e,i){return t<e?e:t>i?i:t}y.prototype.isSignal=!0;const M=1e-6;function T(t,e,i){return Math.abs(t-e)<=i}function A(t,e,i){return(e-t)*i+t}function C(t,e){return t<e?t:e}function E(t){const e=0|t;return 1367130550*(t-e)^e}const z=Math.SQRT1_2/511;function L(t,e,i,n,s,r){return t*n+e*s+i*r}function I(t){return t>0?1:t<0?-1:0}function N(t,e,i){return Math.hypot(t,e,i)}function P(t,e,i){return t*t+e*e+i*i}function D(t,e,i,n,s,r,a,o){const l=A(e,s,o),h=A(i,r,o),c=A(n,a,o);t.set(l,h,c)}let O=class t{constructor(t=0,e=0,i=0){this.x=t,this.y=e,this.z=i,this.onChanged=new y}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 N(this.x,this.y,this.z)}lengthSqr(){return P(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 P(this.x-t.x,this.y-t.y,this.z-t.z)}_distanceSqrTo(t,e,i){return P(this.x-t,this.y-e,this.z-i)}distanceToSquared(t){return P(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=L(t,e,i,n,s,r),o=N(t,e,i)*N(n,s,r);return 0===o?0:S(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(I(this.x),I(this.y),I(this.z))}lerp(t,e){const i=A(this.x,t.x,e),n=A(this.y,t.y,e),s=A(this.z,t.z,e);return this.set(i,n,s)}lerpVectors(t,e,i){D(this,t.x,t.y,t.z,e.x,e.y,e.z,i)}slerpVectors(t,e,i){!function(t,e,i,n,s,r,a,o){const l=L(e,i,n,s,r,a);if(l>=1||l<=-1)return void D(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,m=n*u+a*d;t.set(p,f,m)}(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=1/(t[3]*e+t[7]*i+t[11]*n+t[15]),r=(t[0]*e+t[4]*i+t[8]*n+t[12])*s,a=(t[1]*e+t[5]*i+t[9]*n+t[13])*s,o=(t[2]*e+t[6]*i+t[10]*n+t[14])*s;this.set(r,a,o)}applyDirectionMatrix4(t){const e=this.x,i=this.y,n=this.z,s=t[0]*e+t[4]*i+t[8]*n,r=t[1]*e+t[5]*i+t[9]*n,a=t[2]*e+t[6]*i+t[10]*n,o=1/N(s,r,a);this.set(s*o,r*o,a*o)}transformDirection_three(t){const e=t.elements;this.applyDirectionMatrix4(e)}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=M){return T(this.x,t,n)&&T(this.y,e,n)&&T(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=L(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=L(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`Vector3{ 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){throw new Error("deprecated, use v3_binary_equality_encode")}fromBinaryBufferFloat32_EqualityEncoded(t){throw new Error("deprecated, use v3_binary_equality_decode")}hash(){return E(this.x)^E(this.y)<<1^E(this.z)<<2}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(t,e){return L(t.x,t.y,t.z,e.x,e.y,e.z)}static distance(t,e){return N(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)}};O.prototype.lengthSq=O.prototype.lengthSqr,O.prototype.fromArray=O.prototype.readFromArray,O.prototype.toArray=O.prototype.writeToArray,O.prototype.isVector3=!0,O.zero=Object.freeze(new O(0,0,0)),O.one=Object.freeze(new O(1,1,1)),O.minus_one=Object.freeze(new O(-1,-1,-1)),O.up=Object.freeze(new O(0,1,0)),O.down=Object.freeze(new O(0,-1,0)),O.left=Object.freeze(new O(-1,0,0)),O.right=Object.freeze(new O(1,0,0)),O.forward=Object.freeze(new O(0,0,1)),O.back=Object.freeze(new O(0,0,-1)),O.typeName="Vector3",O._dot=L;const F=new O,R=new O,k=new O;let B=class t{constructor(t=0,e=0,i=0,n=1){this.x=t,this.y=e,this.z=i,this.w=n,this.onChanged=new y}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){F.set(t,e,i),F.normalize(),k._crossVectors(n,s,r,F.x,F.y,F.z),0===k.lengthSq()&&(1===Math.abs(r)?F.x+=.001:F.z+=.001,F.normalize(),k._crossVectors(n,s,r,F.x,F.y,F.z)),k.normalize(),R.crossVectors(F,k);const a=k.x,o=k.y,l=k.z,h=R.x,c=R.y,u=R.z,d=F.x,p=F.y,f=F.z,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){const t=Math.sqrt(1+a-c-f),e=.5/t;_=.5*t,g=(o+h)*e,y=(l+d)*e,v=(u-p)*e}else if(c>f){const t=Math.sqrt(1+c-a-f),e=.5/t;_=(h+o)*e,g=.5*t,y=(p+u)*e,v=(d-l)*e}else{const t=Math.sqrt(1+f-a-c),e=.5/t;_=(d+l)*e,g=(p+u)*e,y=.5*t,v=(o-h)*e}this.set(_,g,y,v)}lookRotation(t,e=O.up){this._lookRotation(t.x,t.y,t.z,e.x,e.y,e.z)}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=S(e*t.x+i*t.y+n*t.z+s*t.w,-1,1),a=Math.abs(r);return 2*Math.acos(a)}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=L(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(e){const i=new t,n=new t;return this.computeSwingAndTwist(e,i,n),2*Math.acos(n.w)}toAxisAngle(t){const e=2*Math.acos(this.w),i=Math.sin(.5*e);return Math.abs(i)>M?t.set(this.x/i,this.y/i,this.z/i):t.set(1,0,0),e}normalize(){let t=this.length();if(t<M)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(e,i){t.rotateTowards(this,this,e,i)}alignToDirection(t,e=O.up,i=O.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);U.crossVectors(e,t),U.normalize(),this.fromAxisAngle(U,s)}lookAt(t,e){const i=new O;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,_)}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=L(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),m=l/f,_=h/f,g=c/f,y=u/f;this.set(m,_,g,y)}fromUnitVectors2(t,e){const i=t.x,n=t.y,s=t.z,r=e.x,a=e.y,o=e.z,l=L(i,n,s,r,a,o);if(-1===l)return V.crossVectors(O.left,t),V.lengthSqr()<1e-5&&V.crossVectors(O.up,t),V.normalize(),void this.set(V.x,V.y,V.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 O;e.crossVectors(O.left,t),e.lengthSqr()<1e-5&&e.crossVectors(O.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=A(t.x,e.x,i),s=A(t.y,e.y,i),r=A(t.z,e.z,i),a=A(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>M?(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 e=new t;return e.copy(this),e}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){!function(t,e,i){const n=3&i,s=i>>12&1023,r=i>>22&1023,a=(i>>2&1023)*z-Math.SQRT1_2,o=s*z-Math.SQRT1_2,l=r*z-Math.SQRT1_2,h=1-a*a-o*o-l*l,c=Math.sqrt(h);let u,d,p,f;0===n?(u=c,d=a,p=o,f=l):1===n?(u=a,d=c,p=o,f=l):2===n?(u=a,d=o,p=c,f=l):(u=a,d=o,p=l,f=c),t[0]=u,t[1]=d,t[2]=p,t[3]=f}(this,0,t)}encodeToUint32(){return function(t,e,i,n){const s=Math.abs(t),r=Math.abs(e),a=Math.abs(i),o=Math.abs(n);let l,h,c,u,d;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=511/(Math.hypot(l,h,c,u)*Math.SQRT1_2);return 3&d|(1023&Math.round(l*p+511))<<2|(1023&Math.round(h*p+511))<<12|(1023&Math.round(c*p+511))<<22}(this.x,this.y,this.z,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}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 E(this.x)^E(this.y)>>2^E(this.z)>>1^E(this.w)<<2}roughlyEquals(t,e){return this._roughlyEquals(t.x,t.y,t.z,t.w,e)}_roughlyEquals(t,e,i,n,s=M){return T(this.x,t,s)&&T(this.y,e,s)&&T(this.z,i,s)&&T(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))}toString(){return`{ x: ${this.x}, y: ${this.y}, z: ${this.z}, w: ${this.w} }`}static random(e=Math.random){const i=new t;return i.random(e),i}static fromEulerAngles(e,i,n){const s=new t;return s.fromEulerAnglesXYZ(e,i,n),s}static rotateTowards(t,e,i,n){const s=e.angleTo(i);if(0===s)t.copy(i);else{const t=C(1,n/s);e.slerp(i,t)}}};B.prototype.fromArray=B.prototype.readFromArray,B.prototype.toArray=B.prototype.writeToArray,B.identity=Object.freeze(new B(0,0,0,1));const U=new O,V=new O,W=new Float32Array(16);class G{position=new O(0,0,0);rotation=new B(0,0,0,1);scale=new O(1,1,1);matrix=function(){f>=16&&(p=new ArrayBuffer(1024),f=0);const t=new Float32Array(p,64*f,16);return t.set(d),f++,t}();flags=2;constructor(){this.subscribe(this.#i,this)}get forward(){const t=O.forward.clone();return t.applyDirectionMatrix4(this.matrix),t}subscribe(t,e){this.position.onChanged.add(t,e),this.rotation.onChanged.add(t,e),this.scale.onChanged.add(t,e)}unsubscribe(t,e){this.position.onChanged.remove(t,e),this.rotation.onChanged.remove(t,e),this.scale.onChanged.remove(t,e)}#i(){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(){c(this.matrix,this.position,this.rotation,this.scale)}lookAt(t,e=O.up){const i=this.position,n=t.x-i.x,s=t.y-i.y,r=t.z-i.z;0===n&&0===s&&0===r||this.rotation._lookRotation(n,s,r,e.x,e.y,e.z)}fromJSON(t){const e=t.position;void 0!==e?this.position.fromJSON(e):this.position.copy(O.zero);const i=t.rotation;void 0!==i?this.rotation.fromJSON(i):this.rotation.copy(B.identity);const n=t.scale;void 0!==n?this.scale.fromJSON(n):this.scale.copy(O.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 G;return t.copy(this),t}equals(t){return 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 G;return e.fromJSON(t),e}multiplyTransforms(t,e){!function(t,e,i){const 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];let v=i[0],x=i[1],w=i[2],b=i[3];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}(W,t.matrix,e.matrix),this.fromMatrix4(W)}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=u(s,r,a),l=t[4],h=t[5],c=t[6],d=u(l,h,c),p=t[8],f=t[9],m=t[10],_=u(p,f,m),g=0!==o?1/o:1e7,y=0!==d?1/d:1e7,v=0!==_?1/_:1e7,x=s*g,w=r*g,b=a*g,S=l*y,M=h*y,T=c*y,A=p*v,C=f*v,E=m*v;e.set(t[12],t[13],t[14]),n.set(o,d,_),i.__setFromRotationMatrix(x,S,A,w,M,C,b,T,E)}(t,this.position,this.rotation,this.scale),this.writeFlag(2,e)}toMatrix4(t){c(t,this.position,this.rotation,this.scale)}makeIdentity(){this.fromMatrix4(d)}toString(){return`{ position: ${this.position}, rotation: ${this.rotation}, scale: ${this.scale} }`}}G.typeName="Transform",G.prototype.isTransform=!0,G.adjustRotation=function(t,e,i=Infinity){const n=new B;n.lookRotation(e),t.rotateTowards(n,i)};var H,j="undefined"!=typeof Float32Array?Float32Array:Array;function q(){var t=new j(16);return j!=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 J(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 Y(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,A=c*g-p*f,C=u*_-d*m,E=u*g-p*m,z=d*g-p*_,L=y*z-v*E+x*C+w*A-b*T+S*M;return L?(L=1/L,t[0]=(o*z-l*E+h*C)*L,t[1]=(s*E-n*z-r*C)*L,t[2]=(m*S-_*b+g*w)*L,t[3]=(d*b-u*S-p*w)*L,t[4]=(l*A-a*z-h*T)*L,t[5]=(i*z-s*A+r*T)*L,t[6]=(_*x-f*S-g*v)*L,t[7]=(c*S-d*x+p*v)*L,t[8]=(a*E-o*A+h*M)*L,t[9]=(n*A-i*E-r*M)*L,t[10]=(f*b-m*x+g*y)*L,t[11]=(u*x-c*b-p*y)*L,t[12]=(o*T-a*C-l*M)*L,t[13]=(i*C-n*T+s*M)*L,t[14]=(m*v-f*w-_*y)*L,t[15]=(c*w-u*v+d*y)*L,t):null}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),H=new j(3),j!=Float32Array&&(H[0]=0,H[1]=0,H[2]=0);const X="136",$=0,Z=1,K=2,Q=1,tt=2,et=3,it=0,nt=1,st=2,rt=0,at=1,ot=2,lt=3,ht=4,ct=5,ut=100,dt=101,pt=102,ft=103,mt=104,_t=200,gt=201,yt=202,vt=203,xt=204,wt=205,bt=206,St=207,Mt=208,Tt=209,At=210,Ct=0,Et=1,zt=2,Lt=3,It=4,Nt=5,Pt=6,Dt=7,Ot=0,Ft=1,Rt=2,kt=0,Bt=1,Ut=2,Vt=3,Wt=4,Gt=5,Ht=301,jt=302,qt=303,Jt=304,Yt=306,Xt=307,$t=1e3,Zt=1001,Kt=1002,Qt=1003,te=1004,ee=1005,ie=1006,ne=1007,se=1008,re=1009,ae=1010,oe=1011,le=1012,he=1013,ce=1014,ue=1015,de=1016,pe=1017,fe=1018,me=1019,_e=1020,ge=1021,ye=1022,ve=1023,xe=1024,we=1025,be=1026,Se=1027,Me=1028,Te=1029,Ae=1030,Ce=1031,Ee=1032,ze=1033,Le=33776,Ie=33777,Ne=33778,Pe=33779,De=35840,Oe=35841,Fe=35842,Re=35843,ke=36196,Be=37492,Ue=37496,Ve=37808,We=37809,Ge=37810,He=37811,je=37812,qe=37813,Je=37814,Ye=37815,Xe=37816,$e=37817,Ze=37818,Ke=37819,Qe=37820,ti=37821,ei=36492,ii=37840,ni=37841,si=37842,ri=37843,ai=37844,oi=37845,li=37846,hi=37847,ci=37848,ui=37849,di=37850,pi=37851,fi=37852,mi=37853,_i=2300,gi=2301,yi=2302,vi=2400,xi=2401,wi=2402,bi=3e3,Si=3001,Mi=3201,Ti=0,Ai=1,Ci=7680,Ei=35044,zi=35048,Li="300 es";class Ii{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 Ni=[];for(let t=0;t<256;t++)Ni[t]=(t<16?"0":"")+t.toString(16);const Pi=Math.PI/180,Di=180/Math.PI;function Oi(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,i=4294967295*Math.random()|0,n=4294967295*Math.random()|0;return(Ni[255&t]+Ni[t>>8&255]+Ni[t>>16&255]+Ni[t>>24&255]+"-"+Ni[255&e]+Ni[e>>8&255]+"-"+Ni[e>>16&15|64]+Ni[e>>24&255]+"-"+Ni[63&i|128]+Ni[i>>8&255]+"-"+Ni[i>>16&255]+Ni[i>>24&255]+Ni[255&n]+Ni[n>>8&255]+Ni[n>>16&255]+Ni[n>>24&255]).toUpperCase()}function Fi(t,e,i){return Math.max(e,Math.min(i,t))}function Ri(t,e,i){return(1-i)*t+i*e}function ki(t){return 0==(t&t-1)&&0!==t}function Bi(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}let Ui,Vi=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}};Vi.prototype.isVector2=!0;class Wi{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 Gi(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 Hi(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}Wi.prototype.isMatrix3=!0;class ji{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===Ui&&(Ui=Hi("canvas")),Ui.width=t.width,Ui.height=t.height;const i=Ui.getContext("2d");t instanceof ImageData?i.putImageData(t,0,0):i.drawImage(t,0,0,t.width,t.height),e=Ui}return e.width>2048||e.height>2048?e.toDataURL("image/jpeg",.6):e.toDataURL("image/png")}}let qi=0;class Ji extends Ii{constructor(t=Ji.DEFAULT_IMAGE,e=Ji.DEFAULT_MAPPING,i=Zt,n=Zt,s=ie,r=se,a=ve,o=re,l=1,h=bi){super(),Object.defineProperty(this,"id",{value:qi++}),this.uuid=Oi(),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 Vi(0,0),this.repeat=new Vi(1,1),this.center=new Vi(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new Wi,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=Oi()),!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(Yi(n[t].image)):e.push(Yi(n[t]))}else e=Yi(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 $t:t.x=t.x-Math.floor(t.x);break;case Zt:t.x=t.x<0?0:1;break;case Kt: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 $t:t.y=t.y-Math.floor(t.y);break;case Zt:t.y=t.y<0?0:1;break;case Kt: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 Yi(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap?ji.getDataURL(t):t.data?{data:Array.prototype.slice.call(t.data),width:t.width,height:t.height,type:t.data.constructor.name}:{}}Ji.DEFAULT_IMAGE=void 0,Ji.DEFAULT_MAPPING=300,Ji.prototype.isTexture=!0;let Xi=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}};Xi.prototype.isVector4=!0;class $i extends Ii{constructor(t,e,i={}){super(),this.width=t,this.height=e,this.depth=1,this.scissor=new Xi(0,0,t,e),this.scissorTest=!1,this.viewport=new Xi(0,0,t,e),this.texture=new Ji(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:ie,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"})}}$i.prototype.isWebGLRenderTarget=!0,class extends $i{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 Zi extends $i{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}}Zi.prototype.isWebGLMultisampleRenderTarget=!0;class Ki{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(Fi(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(){}}Ki.prototype.isQuaternion=!0;class Qi{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(en.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(en.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 tn.copy(this).projectOnVector(t),this.sub(tn)}reflect(t){return this.sub(tn.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(Fi(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}}Qi.prototype.isVector3=!0;const tn=new Qi,en=new Ki;class nn{constructor(t=new Qi(Infinity,Infinity,Infinity),e=new Qi(-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=rn.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(),an.copy(e.boundingBox),an.applyMatrix4(t.matrixWorld),this.union(an));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,rn),rn.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(pn),fn.subVectors(this.max,pn),on.subVectors(t.a,pn),ln.subVectors(t.b,pn),hn.subVectors(t.c,pn),cn.subVectors(ln,on),un.subVectors(hn,ln),dn.subVectors(on,hn);let e=[0,-cn.z,cn.y,0,-un.z,un.y,0,-dn.z,dn.y,cn.z,0,-cn.x,un.z,0,-un.x,dn.z,0,-dn.x,-cn.y,cn.x,0,-un.y,un.x,0,-dn.y,dn.x,0];return!!gn(e,on,ln,hn,fn)&&(e=[1,0,0,0,1,0,0,0,1],!!gn(e,on,ln,hn,fn)&&(mn.crossVectors(cn,un),e=[mn.x,mn.y,mn.z],gn(e,on,ln,hn,fn)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return rn.copy(t).clamp(this.min,this.max).sub(t).length()}getBoundingSphere(t){return this.getCenter(t.center),t.radius=.5*this.getSize(rn).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()||(sn[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),sn[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),sn[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),sn[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),sn[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),sn[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),sn[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),sn[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(sn)),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)}}nn.prototype.isBox3=!0;const sn=[new Qi,new Qi,new Qi,new Qi,new Qi,new Qi,new Qi,new Qi],rn=new Qi,an=new nn,on=new Qi,ln=new Qi,hn=new Qi,cn=new Qi,un=new Qi,dn=new Qi,pn=new Qi,fn=new Qi,mn=new Qi,_n=new Qi;function gn(t,e,i,n,s){for(let r=0,a=t.length-3;r<=a;r+=3){_n.fromArray(t,r);const a=s.x*Math.abs(_n.x)+s.y*Math.abs(_n.y)+s.z*Math.abs(_n.z),o=e.dot(_n),l=i.dot(_n),h=n.dot(_n);if(Math.max(-Math.max(o,l,h),Math.min(o,l,h))>a)return!1}return!0}const yn=new nn,vn=new Qi,xn=new Qi,wn=new Qi;class bn{constructor(t=new Qi,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):yn.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){wn.subVectors(t,this.center);const e=wn.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),i=.5*(t-this.radius);this.center.add(wn.multiplyScalar(i/t)),this.radius+=i}return this}union(t){return!0===this.center.equals(t.center)?xn.set(0,0,1).multiplyScalar(t.radius):xn.subVectors(t.center,this.center).normalize().multiplyScalar(t.radius),this.expandByPoint(vn.copy(t.center).add(xn)),this.expandByPoint(vn.copy(t.center).sub(xn)),this}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}}const Sn=new Qi,Mn=new Qi,Tn=new Qi,An=new Qi,Cn=new Qi,En=new Qi,zn=new Qi;class Ln{constructor(t=new Qi,e=new Qi(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,Sn)),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=Sn.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(Sn.copy(this.direction).multiplyScalar(e).add(this.origin),Sn.distanceToSquared(t))}distanceSqToSegment(t,e,i,n){Mn.copy(t).add(e).multiplyScalar(.5),Tn.copy(e).sub(t).normalize(),An.copy(this.origin).sub(Mn);const s=.5*t.distanceTo(e),r=-this.direction.dot(Tn),a=An.dot(this.direction),o=-An.dot(Tn),l=An.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(Tn).multiplyScalar(u).add(Mn),d}intersectSphere(t,e){Sn.subVectors(t.center,this.origin);const i=Sn.dot(this.direction),n=Sn.dot(Sn)-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,Sn)}intersectTriangle(t,e,i,n,s){Cn.subVectors(e,t),En.subVectors(i,t),zn.crossVectors(Cn,En);let r,a=this.direction.dot(zn);if(a>0){if(n)return null;r=1}else{if(!(a<0))return null;r=-1,a=-a}An.subVectors(this.origin,t);const o=r*this.direction.dot(En.crossVectors(An,En));if(o<0)return null;const l=r*this.direction.dot(Cn.cross(An));if(l<0)return null;if(o+l>a)return null;const h=-r*An.dot(zn);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 In{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 In).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/Nn.setFromMatrixColumn(t,0).length(),s=1/Nn.setFromMatrixColumn(t,1).length(),r=1/Nn.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(Dn,t,On)}lookAt(t,e,i){const n=this.elements;return kn.subVectors(t,e),0===kn.lengthSq()&&(kn.z=1),kn.normalize(),Fn.crossVectors(i,kn),0===Fn.lengthSq()&&(1===Math.abs(i.z)?kn.x+=1e-4:kn.z+=1e-4,kn.normalize(),Fn.crossVectors(i,kn)),Fn.normalize(),Rn.crossVectors(kn,Fn),n[0]=Fn.x,n[4]=Rn.x,n[8]=kn.x,n[1]=Fn.y,n[5]=Rn.y,n[9]=kn.y,n[2]=Fn.z,n[6]=Rn.z,n[10]=kn.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],A=n[5],C=n[9],E=n[13],z=n[2],L=n[6],I=n[10],N=n[14],P=n[3],D=n[7],O=n[11],F=n[15];return s[0]=r*w+a*T+o*z+l*P,s[4]=r*b+a*A+o*L+l*D,s[8]=r*S+a*C+o*I+l*O,s[12]=r*M+a*E+o*N+l*F,s[1]=h*w+c*T+u*z+d*P,s[5]=h*b+c*A+u*L+d*D,s[9]=h*S+c*C+u*I+d*O,s[13]=h*M+c*E+u*N+d*F,s[2]=p*w+f*T+m*z+_*P,s[6]=p*b+f*A+m*L+_*D,s[10]=p*S+f*C+m*I+_*O,s[14]=p*M+f*E+m*N+_*F,s[3]=g*w+y*T+v*z+x*P,s[7]=g*b+y*A+v*L+x*D,s[11]=g*S+y*C+v*I+x*O,s[15]=g*M+y*E+v*N+x*F,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=Nn.set(n[0],n[1],n[2]).length();const r=Nn.set(n[4],n[5],n[6]).length(),a=Nn.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],Pn.copy(this);const o=1/s,l=1/r,h=1/a;return Pn.elements[0]*=o,Pn.elements[1]*=o,Pn.elements[2]*=o,Pn.elements[4]*=l,Pn.elements[5]*=l,Pn.elements[6]*=l,Pn.elements[8]*=h,Pn.elements[9]*=h,Pn.elements[10]*=h,e.setFromRotationMatrix(Pn),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}}In.prototype.isMatrix4=!0;const Nn=new Qi,Pn=new In,Dn=new Qi(0,0,0),On=new Qi(1,1,1),Fn=new Qi,Rn=new Qi,kn=new Qi,Bn=new In,Un=new Ki;class Vn{constructor(t=0,e=0,i=0,n=Vn.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(Fi(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(-Fi(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(Fi(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(-Fi(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(Fi(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(-Fi(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 Bn.makeRotationFromQuaternion(t),this.setFromRotationMatrix(Bn,e,i)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Un.setFromEuler(this),this.setFromQuaternion(Un,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 Qi(this._x,this._y,this._z)}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}}Vn.prototype.isEuler=!0,Vn.DefaultOrder="XYZ",Vn.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"];class Wn{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 Gn=0;const Hn=new Qi,jn=new Ki,qn=new In,Jn=new Qi,Yn=new Qi,Xn=new Qi,$n=new Ki,Zn=new Qi(1,0,0),Kn=new Qi(0,1,0),Qn=new Qi(0,0,1),ts={type:"added"},es={type:"removed"};class is extends Ii{constructor(){super(),Object.defineProperty(this,"id",{value:Gn++}),this.uuid=Oi(),this.name="",this.type="Object3D",this.parent=null,this.children=[],this.up=is.DefaultUp.clone();const t=new Qi,e=new Vn,i=new Ki,n=new Qi(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 In},normalMatrix:{value:new Wi}}),this.matrix=new In,this.matrixWorld=new In,this.matrixAutoUpdate=is.DefaultMatrixAutoUpdate,this.matrixWorldNeedsUpdate=!1,this.layers=new Wn,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 jn.setFromAxisAngle(t,e),this.quaternion.multiply(jn),this}rotateOnWorldAxis(t,e){return jn.setFromAxisAngle(t,e),this.quaternion.premultiply(jn),this}rotateX(t){return this.rotateOnAxis(Zn,t)}rotateY(t){return this.rotateOnAxis(Kn,t)}rotateZ(t){return this.rotateOnAxis(Qn,t)}translateOnAxis(t,e){return Hn.copy(t).applyQuaternion(this.quaternion),this.position.add(Hn.multiplyScalar(e)),this}translateX(t){return this.translateOnAxis(Zn,t)}translateY(t){return this.translateOnAxis(Kn,t)}translateZ(t){return this.translateOnAxis(Qn,t)}localToWorld(t){return t.applyMatrix4(this.matrixWorld)}worldToLocal(t){return t.applyMatrix4(qn.copy(this.matrixWorld).invert())}lookAt(t,e,i){t.isVector3?Jn.copy(t):Jn.set(t,e,i);const n=this.parent;this.updateWorldMatrix(!0,!1),Yn.setFromMatrixPosition(this.matrixWorld),this.isCamera||this.isLight?qn.lookAt(Yn,Jn,this.up):qn.lookAt(Jn,Yn,this.up),this.quaternion.setFromRotationMatrix(qn),n&&(qn.extractRotation(n.matrixWorld),jn.setFromRotationMatrix(qn),this.quaternion.premultiply(jn.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(ts)),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(es)),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(es)}return this.children.length=0,this}attach(t){return this.updateWorldMatrix(!0,!1),qn.copy(this.matrixWorld).invert(),null!==t.parent&&(t.parent.updateWorldMatrix(!0,!1),qn.multiply(t.parent.matrixWorld)),t.applyMatrix4(qn),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(Yn,t,Xn),t}getWorldScale(t){return this.updateWorldMatrix(!0,!1),this.matrixWorld.decompose(Yn,$n,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}}is.DefaultUp=new Qi(0,1,0),is.DefaultMatrixAutoUpdate=!0,is.prototype.isObject3D=!0;const ns=new Qi,ss=new Qi,rs=new Qi,as=new Qi,os=new Qi,ls=new Qi,hs=new Qi,cs=new Qi,us=new Qi,ds=new Qi;class ps{constructor(t=new Qi,e=new Qi,i=new Qi){this.a=t,this.b=e,this.c=i}static getNormal(t,e,i,n){n.subVectors(i,e),ns.subVectors(t,e),n.cross(ns);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){ns.subVectors(n,e),ss.subVectors(i,e),rs.subVectors(t,e);const r=ns.dot(ns),a=ns.dot(ss),o=ns.dot(rs),l=ss.dot(ss),h=ss.dot(rs),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,as),as.x>=0&&as.y>=0&&as.x+as.y<=1}static getUV(t,e,i,n,s,r,a,o){return this.getBarycoord(t,e,i,n,as),o.set(0,0),o.addScaledVector(s,as.x),o.addScaledVector(r,as.y),o.addScaledVector(a,as.z),o}static isFrontFacing(t,e,i,n){return ns.subVectors(i,e),ss.subVectors(t,e),ns.cross(ss).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 ns.subVectors(this.c,this.b),ss.subVectors(this.a,this.b),.5*ns.cross(ss).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return ps.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return ps.getBarycoord(t,this.a,this.b,this.c,e)}getUV(t,e,i,n,s){return ps.getUV(t,this.a,this.b,this.c,e,i,n,s)}containsPoint(t){return ps.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return ps.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;os.subVectors(n,i),ls.subVectors(s,i),cs.subVectors(t,i);const o=os.dot(cs),l=ls.dot(cs);if(o<=0&&l<=0)return e.copy(i);us.subVectors(t,n);const h=os.dot(us),c=ls.dot(us);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(os,r);ds.subVectors(t,s);const d=os.dot(ds),p=ls.dot(ds);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(ls,a);const m=h*p-d*c;if(m<=0&&c-h>=0&&d-p>=0)return hs.subVectors(s,n),a=(c-h)/(c-h+(d-p)),e.copy(n).addScaledVector(hs,a);const _=1/(m+f+u);return r=f*_,a=u*_,e.copy(i).addScaledVector(os,r).addScaledVector(ls,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}let fs=0;class ms extends Ii{constructor(){super(),Object.defineProperty(this,"id",{value:fs++}),this.uuid=Oi(),this.name="",this.type="Material",this.fog=!0,this.blending=at,this.side=it,this.vertexColors=!1,this.opacity=1,this.format=ve,this.transparent=!1,this.blendSrc=xt,this.blendDst=wt,this.blendEquation=ut,this.blendSrcAlpha=null,this.blendDstAlpha=null,this.blendEquationAlpha=null,this.depthFunc=Lt,this.depthTest=!0,this.depthWrite=!0,this.stencilWriteMask=255,this.stencilFunc=519,this.stencilRef=0,this.stencilFuncMask=255,this.stencilFail=Ci,this.stencilZFail=Ci,this.stencilZPass=Ci,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!==at&&(i.blending=this.blending),this.side!==it&&(i.side=this.side),this.vertexColors&&(i.vertexColors=!0),this.opacity<1&&(i.opacity=this.opacity),this.format!==ve&&(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++}}ms.prototype.isMaterial=!0;const _s={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},gs={h:0,s:0,l:0},ys={h:0,s:0,l:0};function vs(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 xs(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function ws(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let bs=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=Fi(e,0,1),i=Fi(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=vs(s,n,t+1/3),this.g=vs(s,n,t),this.b=vs(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=_s[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}copySRGBToLinear(t){return this.r=xs(t.r),this.g=xs(t.g),this.b=xs(t.b),this}copyLinearToSRGB(t){return this.r=ws(t.r),this.g=ws(t.g),this.b=ws(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(gs),gs.h+=t,gs.s+=e,gs.l+=i,this.setHSL(gs.h,gs.s,gs.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(gs),t.getHSL(ys);const i=Ri(gs.h,ys.h,e),n=Ri(gs.s,ys.s,e),s=Ri(gs.l,ys.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()}};bs.NAMES=_s,bs.prototype.isColor=!0,bs.prototype.r=1,bs.prototype.g=1,bs.prototype.b=1;class Ss extends ms{constructor(t){super(),this.type="MeshBasicMaterial",this.color=new bs(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=Ot,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}}Ss.prototype.isMeshBasicMaterial=!0;const Ms=new Qi,Ts=new Vi;class As{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=Ei,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 bs),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 Vi),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 Qi),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 Xi),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++)Ts.fromBufferAttribute(this,e),Ts.applyMatrix3(t),this.setXY(e,Ts.x,Ts.y);else if(3===this.itemSize)for(let e=0,i=this.count;e<i;e++)Ms.fromBufferAttribute(this,e),Ms.applyMatrix3(t),this.setXYZ(e,Ms.x,Ms.y,Ms.z);return this}applyMatrix4(t){for(let e=0,i=this.count;e<i;e++)Ms.x=this.getX(e),Ms.y=this.getY(e),Ms.z=this.getZ(e),Ms.applyMatrix4(t),this.setXYZ(e,Ms.x,Ms.y,Ms.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)Ms.x=this.getX(e),Ms.y=this.getY(e),Ms.z=this.getZ(e),Ms.applyNormalMatrix(t),this.setXYZ(e,Ms.x,Ms.y,Ms.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)Ms.x=this.getX(e),Ms.y=this.getY(e),Ms.z=this.getZ(e),Ms.transformDirection(t),this.setXYZ(e,Ms.x,Ms.y,Ms.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!==Ei&&(t.usage=this.usage),0===this.updateRange.offset&&-1===this.updateRange.count||(t.updateRange=this.updateRange),t}}As.prototype.isBufferAttribute=!0;class Cs extends As{constructor(t,e,i){super(new Uint16Array(t),e,i)}}class Es extends As{constructor(t,e,i){super(new Uint32Array(t),e,i)}}(class extends As{constructor(t,e,i){super(new Uint16Array(t),e,i)}}).prototype.isFloat16BufferAttribute=!0;class zs extends As{constructor(t,e,i){super(new Float32Array(t),e,i)}}let Ls=0;const Is=new In,Ns=new is,Ps=new Qi,Ds=new nn,Os=new nn,Fs=new Qi;class Rs extends Ii{constructor(){super(),Object.defineProperty(this,"id",{value:Ls++}),this.uuid=Oi(),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(Gi(t)>65535?Es:Cs)(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 Wi).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 Is.makeRotationFromQuaternion(t),this.applyMatrix4(Is),this}rotateX(t){return Is.makeRotationX(t),this.applyMatrix4(Is),this}rotateY(t){return Is.makeRotationY(t),this.applyMatrix4(Is),this}rotateZ(t){return Is.makeRotationZ(t),this.applyMatrix4(Is),this}translate(t,e,i){return Is.makeTranslation(t,e,i),this.applyMatrix4(Is),this}scale(t,e,i){return Is.makeScale(t,e,i),this.applyMatrix4(Is),this}lookAt(t){return Ns.lookAt(t),Ns.updateMatrix(),this.applyMatrix4(Ns.matrix),this}center(){return this.computeBoundingBox(),this.boundingBox.getCenter(Ps).negate(),this.translate(Ps.x,Ps.y,Ps.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 zs(e,3)),this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new nn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)this.boundingBox.set(new Qi(-Infinity,-Infinity,-Infinity),new Qi(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];Ds.setFromBufferAttribute(i),this.morphTargetsRelative?(Fs.addVectors(this.boundingBox.min,Ds.min),this.boundingBox.expandByPoint(Fs),Fs.addVectors(this.boundingBox.max,Ds.max),this.boundingBox.expandByPoint(Fs)):(this.boundingBox.expandByPoint(Ds.min),this.boundingBox.expandByPoint(Ds.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 bn);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)this.boundingSphere.set(new Qi,Infinity);else if(t){const i=this.boundingSphere.center;if(Ds.setFromBufferAttribute(t),e)for(let t=0,i=e.length;t<i;t++){const i=e[t];Os.setFromBufferAttribute(i),this.morphTargetsRelative?(Fs.addVectors(Ds.min,Os.min),Ds.expandByPoint(Fs),Fs.addVectors(Ds.max,Os.max),Ds.expandByPoint(Fs)):(Ds.expandByPoint(Os.min),Ds.expandByPoint(Os.max))}Ds.getCenter(i);let n=0;for(let e=0,s=t.count;e<s;e++)Fs.fromBufferAttribute(t,e),n=Math.max(n,i.distanceToSquared(Fs));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++)Fs.fromBufferAttribute(r,e),a&&(Ps.fromBufferAttribute(t,e),Fs.add(Ps)),n=Math.max(n,i.distanceToSquared(Fs))}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 As(new Float32Array(4*a),4));const o=e.tangent.array,l=[],h=[];for(let t=0;t<a;t++)l[t]=new Qi,h[t]=new Qi;const c=new Qi,u=new Qi,d=new Qi,p=new Vi,f=new Vi,m=new Vi,_=new Qi,g=new Qi;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 Qi,w=new Qi,b=new Qi,S=new Qi;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 As(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 Qi,s=new Qi,r=new Qi,a=new Qi,o=new Qi,l=new Qi,h=new Qi,c=new Qi;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++)Fs.fromBufferAttribute(t,e),Fs.normalize(),t.setXYZ(e,Fs.x,Fs.y,Fs.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 As(r,n,s)}if(null===this.index)return this;const e=new Rs,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"})}}Rs.prototype.isBufferGeometry=!0;const ks=new In,Bs=new Ln,Us=new bn,Vs=new Qi,Ws=new Qi,Gs=new Qi,Hs=new Qi,js=new Qi,qs=new Qi,Js=new Qi,Ys=new Qi,Xs=new Qi,$s=new Vi,Zs=new Vi,Ks=new Vi,Qs=new Qi,tr=new Qi;class er extends is{constructor(t=new Rs,e=new Ss){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(),Us.copy(i.boundingSphere),Us.applyMatrix4(s),!1===t.ray.intersectsSphere(Us))return;if(ks.copy(s).invert(),Bs.copy(t.ray).applyMatrix4(ks),null!==i.boundingBox&&!1===Bs.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=ir(this,f,t,Bs,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=ir(this,n,t,Bs,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=ir(this,p,t,Bs,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=ir(this,n,t,Bs,a,o,l,h,c,i,i+1,i+2),r&&(r.faceIndex=Math.floor(i/3),e.push(r))}else i.isGeometry}}function ir(t,e,i,n,s,r,a,o,l,h,c,u){Vs.fromBufferAttribute(s,h),Ws.fromBufferAttribute(s,c),Gs.fromBufferAttribute(s,u);const d=t.morphTargetInfluences;if(r&&d){Js.set(0,0,0),Ys.set(0,0,0),Xs.set(0,0,0);for(let t=0,e=r.length;t<e;t++){const e=d[t],i=r[t];0!==e&&(Hs.fromBufferAttribute(i,h),js.fromBufferAttribute(i,c),qs.fromBufferAttribute(i,u),a?(Js.addScaledVector(Hs,e),Ys.addScaledVector(js,e),Xs.addScaledVector(qs,e)):(Js.addScaledVector(Hs.sub(Vs),e),Ys.addScaledVector(js.sub(Ws),e),Xs.addScaledVector(qs.sub(Gs),e)))}Vs.add(Js),Ws.add(Ys),Gs.add(Xs)}t.isSkinnedMesh&&(t.boneTransform(h,Vs),t.boneTransform(c,Ws),t.boneTransform(u,Gs));const p=function(t,e,i,n,s,r,a,o){let l;if(l=e.side===nt?n.intersectTriangle(a,r,s,!0,o):n.intersectTriangle(s,r,a,e.side!==st,o),null===l)return null;tr.copy(o),tr.applyMatrix4(t.matrixWorld);const h=i.ray.origin.distanceTo(tr);return h<i.near||h>i.far?null:{distance:h,point:tr.clone(),object:t}}(t,e,i,n,Vs,Ws,Gs,Qs);if(p){o&&($s.fromBufferAttribute(o,h),Zs.fromBufferAttribute(o,c),Ks.fromBufferAttribute(o,u),p.uv=ps.getUV(Qs,Vs,Ws,Gs,$s,Zs,Ks,new Vi)),l&&($s.fromBufferAttribute(l,h),Zs.fromBufferAttribute(l,c),Ks.fromBufferAttribute(l,u),p.uv2=ps.getUV(Qs,Vs,Ws,Gs,$s,Zs,Ks,new Vi));const t={a:h,b:c,c:u,normal:new Qi,materialIndex:0};ps.getNormal(Vs,Ws,Gs,t.normal),p.face=t}return p}er.prototype.isMesh=!0;class nr extends Rs{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,A=0;const C=new Qi;for(let r=0;r<M;r++){const a=r*v-w;for(let o=0;o<S;o++){const u=o*y-x;C[t]=u*n,C[e]=a*s,C[i]=b,l.push(C.x,C.y,C.z),C[t]=0,C[e]=0,C[i]=f>0?1:-1,h.push(C.x,C.y,C.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),A+=6}a.addGroup(d,A,g),d+=A,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 zs(l,3)),this.setAttribute("normal",new zs(h,3)),this.setAttribute("uv",new zs(c,2))}static fromJSON(t){return new nr(t.width,t.height,t.depth,t.widthSegments,t.heightSegments,t.depthSegments)}}function sr(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 rr(t){const e={};for(let i=0;i<t.length;i++){const n=sr(t[i]);for(const t in n)e[t]=n[t]}return e}const ar={clone:sr,merge:rr};class or extends ms{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=sr(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}}or.prototype.isShaderMaterial=!0;let lr=class extends is{constructor(){super(),this.type="Camera",this.matrixWorldInverse=new In,this.projectionMatrix=new In,this.projectionMatrixInverse=new In}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)}};lr.prototype.isCamera=!0;class hr extends lr{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*Di*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*Pi*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*Di*Math.atan(Math.tan(.5*Pi*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*Pi*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}}hr.prototype.isPerspectiveCamera=!0;const cr=90;class ur extends is{constructor(t,e,i){if(super(),this.type="CubeCamera",!0!==i.isWebGLCubeRenderTarget)return;this.renderTarget=i;const n=new hr(cr,1,t,e);n.layers=this.layers,n.up.set(0,-1,0),n.lookAt(new Qi(1,0,0)),this.add(n);const s=new hr(cr,1,t,e);s.layers=this.layers,s.up.set(0,-1,0),s.lookAt(new Qi(-1,0,0)),this.add(s);const r=new hr(cr,1,t,e);r.layers=this.layers,r.up.set(0,0,1),r.lookAt(new Qi(0,1,0)),this.add(r);const a=new hr(cr,1,t,e);a.layers=this.layers,a.up.set(0,0,-1),a.lookAt(new Qi(0,-1,0)),this.add(a);const o=new hr(cr,1,t,e);o.layers=this.layers,o.up.set(0,-1,0),o.lookAt(new Qi(0,0,1)),this.add(o);const l=new hr(cr,1,t,e);l.layers=this.layers,l.up.set(0,-1,0),l.lookAt(new Qi(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 dr extends Ji{constructor(t,e,i,n,s,r,a,o,l,h){super(t=void 0!==t?t:[],e=void 0!==e?e:Ht,i,n,s,r,a,o,l,h),this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}dr.prototype.isCubeTexture=!0;class pr extends $i{constructor(t,e,i){Number.isInteger(e)&&(e=i),super(t,t,e),e=e||{},this.texture=new dr(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:ie,this.texture._needsFlipEnvMap=!1}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.format=ve,this.texture.encoding=e.encoding,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const i=new nr(5,5,5),n=new or({name:"CubemapFromEquirect",uniforms:sr({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:nt,blending:rt});n.uniforms.tEquirect.value=e;const s=new er(i,n),r=e.minFilter;return e.minFilter===se&&(e.minFilter=ie),new ur(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)}}pr.prototype.isWebGLCubeRenderTarget=!0;const fr=new Qi,mr=new Qi,_r=new Wi;class gr{constructor(t=new Qi(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=fr.subVectors(i,e).cross(mr.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(fr),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||_r.getNormalMatrix(t),n=this.coplanarPoint(fr).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)}}gr.prototype.isPlane=!0;const yr=new bn,vr=new Qi;class xr{constructor(t=new gr,e=new gr,i=new gr,n=new gr,s=new gr,r=new gr){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(),yr.copy(e.boundingSphere).applyMatrix4(t.matrixWorld),this.intersectsSphere(yr)}intersectsSprite(t){return yr.center.set(0,0,0),yr.radius=.7071067811865476,yr.applyMatrix4(t.matrixWorld),this.intersectsSphere(yr)}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(vr.x=n.normal.x>0?t.max.x:t.min.x,vr.y=n.normal.y>0?t.max.y:t.min.y,vr.z=n.normal.z>0?t.max.z:t.min.z,n.distanceToPoint(vr)<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 wr(){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 br(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 Sr extends Rs{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 zs(p,3)),this.setAttribute("normal",new zs(f,3)),this.setAttribute("uv",new zs(m,2))}static fromJSON(t){return new Sr(t.width,t.height,t.widthSegments,t.heightSegments)}}const Mr={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 ) + 0.5;\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\treturn texture2D( envMap, uv ).rgb;\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:"vec4 LinearToLinear( in vec4 value ) {\n\treturn value;\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}",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 vec3( texture2D( gradientMap, coord ).r );\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 );\nvec3 sheenSpecular = vec3( 0.0 );\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n\tfloat b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n\tfloat DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n\treturn saturate( DG * RECIPROCAL_PI );\n}\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\tsheenSpecular += 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\t#ifdef USE_SHEEN\n\t\tsheenSpecular += irradiance * material.sheenColor * IBLSheenBRDF( geometry.normal, geometry.viewDir, material.sheenRoughness );\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_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;\n\t#endif\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}"},Tr={common:{diffuse:{value:new bs(16777215)},opacity:{value:1},map:{value:null},uvTransform:{value:new Wi},uv2Transform:{value:new Wi},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 Vi(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 bs(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 bs(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaTest:{value:0},uvTransform:{value:new Wi}},sprite:{diffuse:{value:new bs(16777215)},opacity:{value:1},center:{value:new Vi(.5,.5)},rotation:{value:0},map:{value:null},alphaMap:{value:null},alphaTest:{value:0},uvTransform:{value:new Wi}}},Ar={basic:{uniforms:rr([Tr.common,Tr.specularmap,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.fog]),vertexShader:Mr.meshbasic_vert,fragmentShader:Mr.meshbasic_frag},lambert:{uniforms:rr([Tr.common,Tr.specularmap,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.fog,Tr.lights,{emissive:{value:new bs(0)}}]),vertexShader:Mr.meshlambert_vert,fragmentShader:Mr.meshlambert_frag},phong:{uniforms:rr([Tr.common,Tr.specularmap,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.fog,Tr.lights,{emissive:{value:new bs(0)},specular:{value:new bs(1118481)},shininess:{value:30}}]),vertexShader:Mr.meshphong_vert,fragmentShader:Mr.meshphong_frag},standard:{uniforms:rr([Tr.common,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.roughnessmap,Tr.metalnessmap,Tr.fog,Tr.lights,{emissive:{value:new bs(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Mr.meshphysical_vert,fragmentShader:Mr.meshphysical_frag},toon:{uniforms:rr([Tr.common,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.gradientmap,Tr.fog,Tr.lights,{emissive:{value:new bs(0)}}]),vertexShader:Mr.meshtoon_vert,fragmentShader:Mr.meshtoon_frag},matcap:{uniforms:rr([Tr.common,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,Tr.fog,{matcap:{value:null}}]),vertexShader:Mr.meshmatcap_vert,fragmentShader:Mr.meshmatcap_frag},points:{uniforms:rr([Tr.points,Tr.fog]),vertexShader:Mr.points_vert,fragmentShader:Mr.points_frag},dashed:{uniforms:rr([Tr.common,Tr.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Mr.linedashed_vert,fragmentShader:Mr.linedashed_frag},depth:{uniforms:rr([Tr.common,Tr.displacementmap]),vertexShader:Mr.depth_vert,fragmentShader:Mr.depth_frag},normal:{uniforms:rr([Tr.common,Tr.bumpmap,Tr.normalmap,Tr.displacementmap,{opacity:{value:1}}]),vertexShader:Mr.meshnormal_vert,fragmentShader:Mr.meshnormal_frag},sprite:{uniforms:rr([Tr.sprite,Tr.fog]),vertexShader:Mr.sprite_vert,fragmentShader:Mr.sprite_frag},background:{uniforms:{uvTransform:{value:new Wi},t2D:{value:null}},vertexShader:Mr.background_vert,fragmentShader:Mr.background_frag},cube:{uniforms:rr([Tr.envmap,{opacity:{value:1}}]),vertexShader:Mr.cube_vert,fragmentShader:Mr.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Mr.equirect_vert,fragmentShader:Mr.equirect_frag},distanceRGBA:{uniforms:rr([Tr.common,Tr.displacementmap,{referencePosition:{value:new Qi},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Mr.distanceRGBA_vert,fragmentShader:Mr.distanceRGBA_frag},shadow:{uniforms:rr([Tr.lights,Tr.fog,{color:{value:new bs(0)},opacity:{value:1}}]),vertexShader:Mr.shadow_vert,fragmentShader:Mr.shadow_frag}};function Cr(t,e,i,n,s){const r=new bs(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===Yt)?(void 0===o&&(o=new er(new nr(1,1,1),new or({name:"BackgroundCubeMaterial",uniforms:sr(Ar.cube.uniforms),vertexShader:Ar.cube.vertexShader,fragmentShader:Ar.cube.fragmentShader,side:nt,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 er(new Sr(2,2),new or({name:"BackgroundMaterial",uniforms:sr(Ar.background.uniforms),vertexShader:Ar.background.vertexShader,fragmentShader:Ar.background.fragmentShader,side:it,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 Er(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 zr(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 Lr(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 Ir(t){const e=this;let i=null,n=0,s=!1,r=!1;const a=new gr,o=new Wi,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 Nr(t){let e=new WeakMap;function i(t,e){return e===qt?t.mapping=Ht:e===Jt&&(t.mapping=jt),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===qt||r===Jt){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 pr(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}}}Ar.physical={uniforms:rr([Ar.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatNormalScale:{value:new Vi(1,1)},clearcoatNormalMap:{value:null},sheen:{value:0},sheenColor:{value:new bs(0)},sheenColorMap:{value:null},sheenRoughness:{value:0},sheenRoughnessMap:{value:null},transmission:{value:0},transmissionMap:{value:null},transmissionSamplerSize:{value:new Vi},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},attenuationDistance:{value:0},attenuationColor:{value:new bs(0)},specularIntensity:{value:0},specularIntensityMap:{value:null},specularColor:{value:new bs(1,1,1)},specularColorMap:{value:null}}]),vertexShader:Mr.meshphysical_vert,fragmentShader:Mr.meshphysical_frag};class Pr extends lr{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}}Pr.prototype.isOrthographicCamera=!0;class Dr extends or{constructor(t){super(t),this.type="RawShaderMaterial"}}Dr.prototype.isRawShaderMaterial=!0;const Or=Math.pow(2,8),Fr=[.125,.215,.35,.446,.526,.582],Rr=5+Fr.length,kr={[bi]:0,[Si]:1},Br=new Pr,{_lodPlanes:Ur,_sizeLods:Vr,_sigmas:Wr}=Xr(),Gr=new bs;let Hr=null;const jr=(1+Math.sqrt(5))/2,qr=1/jr,Jr=[new Qi(1,1,1),new Qi(-1,1,1),new Qi(1,1,-1),new Qi(-1,1,-1),new Qi(0,jr,qr),new Qi(0,jr,-qr),new Qi(qr,0,jr),new Qi(-qr,0,jr),new Qi(jr,qr,0),new Qi(-jr,qr,0)];class Yr{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._blurMaterial=function(t){const e=new Float32Array(20),i=new Qi(0,1,0);return new Dr({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}},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\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 {\n\n\t\t\t\treturn sRGBToLinear( value );\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}\n\t\t",blending:rt,depthTest:!1,depthWrite:!1})}(),this._equirectShader=null,this._cubemapShader=null,this._compileMaterial(this._blurMaterial)}fromScene(t,e=0,i=.1,n=100){Hr=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=Qr(),this._compileMaterial(this._cubemapShader))}compileEquirectangularShader(){null===this._equirectShader&&(this._equirectShader=Kr(),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<Ur.length;t++)Ur[t].dispose()}_cleanup(t){this._pingPongRenderTarget.dispose(),this._renderer.setRenderTarget(Hr),t.scissorTest=!1,Zr(t,0,0,t.width,t.height)}_fromTexture(t){Hr=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:ie,minFilter:ie,generateMipmaps:!1,type:de,format:ve,encoding:bi,depthBuffer:!1},i=$r(e);return i.depthBuffer=!t,this._pingPongRenderTarget=$r(e),i}_compileMaterial(t){const e=new er(Ur[0],t);this._renderer.compile(e,Br)}_sceneToCubeUV(t,e,i,n){const s=new hr(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.toneMapping;o.getClearColor(Gr),o.toneMapping=kt,o.autoClear=!1;const c=new Ss({name:"PMREM.Background",side:nt,depthWrite:!1,depthTest:!1}),u=new er(new nr,c);let d=!1;const p=t.background;p?p.isColor&&(c.color.copy(p),t.background=null,d=!0):(c.color.copy(Gr),d=!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])),Zr(n,i*Or,e>2?Or:0,Or,Or),o.setRenderTarget(n),d&&o.render(u,s),o.render(t,s)}u.geometry.dispose(),u.material.dispose(),o.toneMapping=h,o.autoClear=l,t.background=p}_setEncoding(t,e){!0===this._renderer.capabilities.isWebGL2&&e.format===ve&&e.type===re&&e.encoding===Si?t.value=kr[bi]:t.value=kr[e.encoding]}_textureToCubeUV(t,e){const i=this._renderer,n=t.mapping===Ht||t.mapping===jt;n?null==this._cubemapShader&&(this._cubemapShader=Qr()):null==this._equirectShader&&(this._equirectShader=Kr());const s=n?this._cubemapShader:this._equirectShader,r=new er(Ur[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),Zr(e,0,0,3*Or,2*Or),i.setRenderTarget(e),i.render(r,Br)}_applyPMREM(t){const e=this._renderer,i=e.autoClear;e.autoClear=!1;for(let e=1;e<Rr;e++){const i=Math.sqrt(Wr[e]*Wr[e]-Wr[e-1]*Wr[e-1]),n=Jr[(e-1)%Jr.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 er(Ur[n],l),c=l.uniforms,u=Vr[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=8-i;const g=Vr[n];Zr(e,3*Math.max(0,Or-2*g),(0===n?0:2*Or)+2*g*(n>4?n-8+4:0),3*g,2*g),o.setRenderTarget(e),o.render(h,Br)}}function Xr(){const t=[],e=[],i=[];let n=8;for(let s=0;s<Rr;s++){const r=Math.pow(2,n);e.push(r);let a=1/r;s>4?a=Fr[s-8+4-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 Rs;v.setAttribute("position",new As(_,p)),v.setAttribute("uv",new As(g,f)),v.setAttribute("faceIndex",new As(y,m)),t.push(v),n>4&&n--}return{_lodPlanes:t,_sizeLods:e,_sigmas:i}}function $r(t){const e=new $i(3*Or,3*Or,t);return e.texture.mapping=Yt,e.texture.name="PMREM.cubeUv",e.scissorTest=!0,e}function Zr(t,e,i,n,s){t.viewport.set(e,i,n,s),t.scissor.set(e,i,n,s)}function Kr(){const t=new Vi(1,1);return new Dr({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null},texelSize:{value:t},inputEncoding:{value:kr[bi]}},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\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 {\n\n\t\t\t\treturn sRGBToLinear( value );\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}\n\t\t",blending:rt,depthTest:!1,depthWrite:!1})}function Qr(){return new Dr({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},inputEncoding:{value:kr[bi]}},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\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 {\n\n\t\t\t\treturn sRGBToLinear( value );\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 = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) );\n\n\t\t\t}\n\t\t",blending:rt,depthTest:!1,depthWrite:!1})}function ta(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===qt||r===Jt,o=r===Ht||r===jt;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 Yr(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 ea(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 ia(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(Gi(i)>65535?Es:Cs)(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 na(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 sa(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 ra extends Ji{constructor(t=null,e=1,i=1,n=1){super(null),this.image={data:t,width:e,height:i,depth:n},this.magFilter=Qt,this.minFilter=Qt,this.wrapR=Zt,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}function aa(t,e){return t[0]-e[0]}function oa(t,e){return Math.abs(e[1])-Math.abs(t[1])}function la(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 ha(t,e,i){const n={},s=new Float32Array(8),r=new WeakMap,a=new Qi,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 ra(d,c,u,n);p.format=ve,p.type=ue,p.needsUpdate=!0;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&&la(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&&la(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 Vi(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(oa);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(aa);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 ca(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}}}ra.prototype.isDataTexture2DArray=!0;class ua extends Ji{constructor(t=null,e=1,i=1,n=1){super(null),this.image={data:t,width:e,height:i,depth:n},this.magFilter=Qt,this.minFilter=Qt,this.wrapR=Zt,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}ua.prototype.isDataTexture3D=!0;const da=new Ji,pa=new ra,fa=new ua,ma=new dr,_a=[],ga=[],ya=new Float32Array(16),va=new Float32Array(9),xa=new Float32Array(4);function wa(t,e,i){const n=t[0];if(n<=0||n>0)return t;const s=e*i;let r=_a[s];if(void 0===r&&(r=new Float32Array(s),_a[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 ba(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 Sa(t,e){for(let i=0,n=e.length;i<n;i++)t[i]=e[i]}function Ma(t,e){let i=ga[e];void 0===i&&(i=new Int32Array(e),ga[e]=i);for(let n=0;n!==e;++n)i[n]=t.allocateTextureUnit();return i}function Ta(t,e){const i=this.cache;i[0]!==e&&(t.uniform1f(this.addr,e),i[0]=e)}function Aa(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(ba(i,e))return;t.uniform2fv(this.addr,e),Sa(i,e)}}function Ca(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(ba(i,e))return;t.uniform3fv(this.addr,e),Sa(i,e)}}function Ea(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(ba(i,e))return;t.uniform4fv(this.addr,e),Sa(i,e)}}function za(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(ba(i,e))return;t.uniformMatrix2fv(this.addr,!1,e),Sa(i,e)}else{if(ba(i,n))return;xa.set(n),t.uniformMatrix2fv(this.addr,!1,xa),Sa(i,n)}}function La(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(ba(i,e))return;t.uniformMatrix3fv(this.addr,!1,e),Sa(i,e)}else{if(ba(i,n))return;va.set(n),t.uniformMatrix3fv(this.addr,!1,va),Sa(i,n)}}function Ia(t,e){const i=this.cache,n=e.elements;if(void 0===n){if(ba(i,e))return;t.uniformMatrix4fv(this.addr,!1,e),Sa(i,e)}else{if(ba(i,n))return;ya.set(n),t.uniformMatrix4fv(this.addr,!1,ya),Sa(i,n)}}function Na(t,e){const i=this.cache;i[0]!==e&&(t.uniform1i(this.addr,e),i[0]=e)}function Pa(t,e){const i=this.cache;ba(i,e)||(t.uniform2iv(this.addr,e),Sa(i,e))}function Da(t,e){const i=this.cache;ba(i,e)||(t.uniform3iv(this.addr,e),Sa(i,e))}function Oa(t,e){const i=this.cache;ba(i,e)||(t.uniform4iv(this.addr,e),Sa(i,e))}function Fa(t,e){const i=this.cache;i[0]!==e&&(t.uniform1ui(this.addr,e),i[0]=e)}function Ra(t,e){const i=this.cache;ba(i,e)||(t.uniform2uiv(this.addr,e),Sa(i,e))}function ka(t,e){const i=this.cache;ba(i,e)||(t.uniform3uiv(this.addr,e),Sa(i,e))}function Ba(t,e){const i=this.cache;ba(i,e)||(t.uniform4uiv(this.addr,e),Sa(i,e))}function Ua(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.safeSetTexture2D(e||da,s)}function Va(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTexture3D(e||fa,s)}function Wa(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.safeSetTextureCube(e||ma,s)}function Ga(t,e,i){const n=this.cache,s=i.allocateTextureUnit();n[0]!==s&&(t.uniform1i(this.addr,s),n[0]=s),i.setTexture2DArray(e||pa,s)}function Ha(t,e){t.uniform1fv(this.addr,e)}function ja(t,e){const i=wa(e,this.size,2);t.uniform2fv(this.addr,i)}function qa(t,e){const i=wa(e,this.size,3);t.uniform3fv(this.addr,i)}function Ja(t,e){const i=wa(e,this.size,4);t.uniform4fv(this.addr,i)}function Ya(t,e){const i=wa(e,this.size,4);t.uniformMatrix2fv(this.addr,!1,i)}function Xa(t,e){const i=wa(e,this.size,9);t.uniformMatrix3fv(this.addr,!1,i)}function $a(t,e){const i=wa(e,this.size,16);t.uniformMatrix4fv(this.addr,!1,i)}function Za(t,e){t.uniform1iv(this.addr,e)}function Ka(t,e){t.uniform2iv(this.addr,e)}function Qa(t,e){t.uniform3iv(this.addr,e)}function to(t,e){t.uniform4iv(this.addr,e)}function eo(t,e){t.uniform1uiv(this.addr,e)}function io(t,e){t.uniform2uiv(this.addr,e)}function no(t,e){t.uniform3uiv(this.addr,e)}function so(t,e){t.uniform4uiv(this.addr,e)}function ro(t,e,i){const n=e.length,s=Ma(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.safeSetTexture2D(e[t]||da,s[t])}function ao(t,e,i){const n=e.length,s=Ma(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.setTexture3D(e[t]||fa,s[t])}function oo(t,e,i){const n=e.length,s=Ma(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.safeSetTextureCube(e[t]||ma,s[t])}function lo(t,e,i){const n=e.length,s=Ma(i,n);t.uniform1iv(this.addr,s);for(let t=0;t!==n;++t)i.setTexture2DArray(e[t]||pa,s[t])}function ho(t,e,i){this.id=t,this.addr=i,this.cache=[],this.setValue=function(t){switch(t){case 5126:return Ta;case 35664:return Aa;case 35665:return Ca;case 35666:return Ea;case 35674:return za;case 35675:return La;case 35676:return Ia;case 5124:case 35670:return Na;case 35667:case 35671:return Pa;case 35668:case 35672:return Da;case 35669:case 35673:return Oa;case 5125:return Fa;case 36294:return Ra;case 36295:return ka;case 36296:return Ba;case 35678:case 36198:case 36298:case 36306:case 35682:return Ua;case 35679:case 36299:case 36307:return Va;case 35680:case 36300:case 36308:case 36293:return Wa;case 36289:case 36303:case 36311:case 36292:return Ga}}(e.type)}function co(t,e,i){this.id=t,this.addr=i,this.cache=[],this.size=e.size,this.setValue=function(t){switch(t){case 5126:return Ha;case 35664:return ja;case 35665:return qa;case 35666:return Ja;case 35674:return Ya;case 35675:return Xa;case 35676:return $a;case 5124:case 35670:return Za;case 35667:case 35671:return Ka;case 35668:case 35672:return Qa;case 35669:case 35673:return to;case 5125:return eo;case 36294:return io;case 36295:return no;case 36296:return so;case 35678:case 36198:case 36298:case 36306:case 35682:return ro;case 35679:case 36299:case 36307:return ao;case 35680:case 36300:case 36308:case 36293:return oo;case 36289:case 36303:case 36311:case 36292:return lo}}(e.type)}function uo(t){this.id=t,this.seq=[],this.map={}}co.prototype.updateCache=function(t){const e=this.cache;t instanceof Float32Array&&e.length!==t.length&&(this.cache=new Float32Array(t.length)),Sa(e,t)},uo.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 po=/(\w+)(\])?(\[|\.)?/g;function fo(t,e){t.seq.push(e),t.map[e.id]=e}function mo(t,e,i){const n=t.name,s=n.length;for(po.lastIndex=0;;){const r=po.exec(n),a=po.lastIndex;let o=r[1];const l="]"===r[2],h=r[3];if(l&&(o|=0),void 0===h||"["===h&&a+2===s){fo(i,void 0===h?new ho(o,t,e):new co(o,t,e));break}{let t=i.map[o];void 0===t&&(t=new uo(o),fo(i,t)),i=t}}}function _o(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);mo(i,t.getUniformLocation(e,i.name),this)}}function go(t,e,i){const n=t.createShader(e);return t.shaderSource(n,i),t.compileShader(n),n}_o.prototype.setValue=function(t,e,i,n){const s=this.map[e];void 0!==s&&s.setValue(t,i,n)},_o.prototype.setOptional=function(t,e,i){const n=e[i];void 0!==n&&this.setValue(t,i,n)},_o.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)}},_o.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 yo=0;function vo(t){switch(t){case bi:return["Linear","( value )"];case Si:return["sRGB","( value )"];default:return["Linear","( value )"]}}function xo(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 wo(t,e){const i=vo(e);return"vec4 "+t+"( vec4 value ) { return "+i[0]+"ToLinear"+i[1]+"; }"}function bo(t,e){const i=vo(e);return"vec4 "+t+"( vec4 value ) { return LinearTo"+i[0]+i[1]+"; }"}function So(t,e){let i;switch(e){case Bt:i="Linear";break;case Ut:i="Reinhard";break;case Vt:i="OptimizedCineon";break;case Wt:i="ACESFilmic";break;case Gt:i="Custom";break;default:i="Linear"}return"vec3 "+t+"( vec3 color ) { return "+i+"ToneMapping( color ); }"}function Mo(t){return""!==t}function To(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 Ao(t,e){return t.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const Co=/^[ \t]*#include +<([\w\d./]+)>/gm;function Eo(t){return t.replace(Co,zo)}function zo(t,e){const i=Mr[e];if(void 0===i)throw new Error("Can not resolve #include <"+e+">");return Eo(i)}const Lo=/#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g,Io=/#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 No(t){return t.replace(Io,Do).replace(Lo,Po)}function Po(t,e,i,n){return Do(0,e,i,n)}function Do(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 Oo(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 Fo(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===Q?e="SHADOWMAP_TYPE_PCF":t.shadowMapType===tt?e="SHADOWMAP_TYPE_PCF_SOFT":t.shadowMapType===et&&(e="SHADOWMAP_TYPE_VSM"),e}(i),h=function(t){let e="ENVMAP_TYPE_CUBE";if(t.envMap)switch(t.envMapMode){case Ht:case jt:e="ENVMAP_TYPE_CUBE";break;case Yt:case Xt:e="ENVMAP_TYPE_CUBE_UV"}return e}(i),c=function(t){let e="ENVMAP_MODE_REFLECTION";if(t.envMap)switch(t.envMapMode){case jt:case Xt:e="ENVMAP_MODE_REFRACTION"}return e}(i),u=function(t){let e="ENVMAP_BLENDING_NONE";if(t.envMap)switch(t.combine){case Ot:e="ENVMAP_BLENDING_MULTIPLY";break;case Ft:e="ENVMAP_BLENDING_MIX";break;case Rt:e="ENVMAP_BLENDING_ADD"}return e}(i),d=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(Mo).join("\n")}(i),p=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),f=s.createProgram();let m,_,g=i.glslVersion?"#version "+i.glslVersion+"\n":"";i.isRawShaderMaterial?(m=[p].filter(Mo).join("\n"),m.length>0&&(m+="\n"),_=[d,p].filter(Mo).join("\n"),_.length>0&&(_+="\n")):(m=[Oo(i),"#define SHADER_NAME "+i.shaderName,p,i.instancing?"#define USE_INSTANCING":"",i.instancingColor?"#define USE_INSTANCING_COLOR":"",i.supportsVertexTextures?"#define VERTEX_TEXTURES":"","#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(Mo).join("\n"),_=[d,Oo(i),"#define SHADER_NAME "+i.shaderName,p,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!==kt?"#define TONE_MAPPING":"",i.toneMapping!==kt?Mr.tonemapping_pars_fragment:"",i.toneMapping!==kt?So("toneMapping",i.toneMapping):"",i.dithering?"#define DITHERING":"",i.format===ye?"#define OPAQUE":"",Mr.encodings_pars_fragment,i.map?wo("mapTexelToLinear",i.mapEncoding):"",i.matcap?wo("matcapTexelToLinear",i.matcapEncoding):"",i.envMap?wo("envMapTexelToLinear",i.envMapEncoding):"",i.emissiveMap?wo("emissiveMapTexelToLinear",i.emissiveMapEncoding):"",i.specularColorMap?wo("specularColorMapTexelToLinear",i.specularColorMapEncoding):"",i.sheenColorMap?wo("sheenColorMapTexelToLinear",i.sheenColorMapEncoding):"",i.lightMap?wo("lightMapTexelToLinear",i.lightMapEncoding):"",bo("linearToOutputTexel",i.outputEncoding),i.depthPacking?"#define DEPTH_PACKING "+i.depthPacking:"","\n"].filter(Mo).join("\n")),a=Eo(a),a=To(a,i),a=Ao(a,i),o=Eo(o),o=To(o,i),o=Ao(o,i),a=No(a),o=No(o),i.isWebGL2&&!0!==i.isRawShaderMaterial&&(g="#version 300 es\n",m=["precision mediump sampler2DArray;","#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+m,_=["#define varying in",i.glslVersion===Li?"":"layout(location = 0) out highp vec4 pc_fragColor;",i.glslVersion===Li?"":"#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"+_);const y=g+_+o,v=go(s,35633,g+m+a),x=go(s,35632,y);if(s.attachShader(f,v),s.attachShader(f,x),void 0!==i.index0AttributeName?s.bindAttribLocation(f,0,i.index0AttributeName):!0===i.morphTargets&&s.bindAttribLocation(f,0,"position"),s.linkProgram(f),t.debug.checkShaderErrors){const t=s.getProgramInfoLog(f).trim(),e=s.getShaderInfoLog(v).trim(),i=s.getShaderInfoLog(x).trim();let n=!0,r=!0;!1===s.getProgramParameter(f,35714)?(n=!1,xo(s,v,"vertex"),xo(s,x,"fragment")):""!==t||""!==e&&""!==i||(r=!1),r&&(this.diagnostics={runnable:n,programLog:t,vertexShader:{log:e,prefix:m},fragmentShader:{log:i,prefix:_}})}let w,b;return s.deleteShader(v),s.deleteShader(x),this.getUniforms=function(){return void 0===w&&(w=new _o(s,f)),w},this.getAttributes=function(){return void 0===b&&(b=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,f)),b},this.destroy=function(){n.releaseStatesOfProgram(this),s.deleteProgram(f),this.program=void 0},this.name=i.shaderName,this.id=yo++,this.cacheKey=e,this.usedTimes=1,this.program=f,this.vertexShader=v,this.fragmentShader=x,this}let Ro=0;class ko{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(t){const e=t.vertexShader,i=t.fragmentShader,n=this._getShaderStage(e),s=this._getShaderStage(i),r=this._getShaderCacheForMaterial(t);return!1===r.has(n)&&(r.add(n),n.usedTimes++),!1===r.has(s)&&(r.add(s),s.usedTimes++),this}remove(t){const e=this.materialCache.get(t);for(const t of e)t.usedTimes--,0===t.usedTimes&&this.shaderCache.delete(t);return this.materialCache.delete(t),this}getVertexShaderID(t){return this._getShaderStage(t.vertexShader).id}getFragmentShaderID(t){return this._getShaderStage(t.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(t){const e=this.materialCache;return!1===e.has(t)&&e.set(t,new Set),e.get(t)}_getShaderStage(t){const e=this.shaderCache;if(!1===e.has(t)){const i=new Bo;e.set(t,i)}return e.get(t)}}class Bo{constructor(){this.id=Ro++,this.usedTimes=0}}function Uo(t,e,i,n,s,r,a){const o=new Wn,l=new ko,h=[],c=s.isWebGL2,u=s.logarithmicDepthBuffer,d=s.floatVertexTextures,p=s.maxVertexUniforms,f=s.vertexTextures;let m=s.precision;const _={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function g(t){let e;return e=t&&t.isTexture?t.encoding:t&&t.isWebGLRenderTarget?t.texture.encoding:bi,c&&t&&t.isTexture&&t.format===ve&&t.type===re&&t.encoding===Si&&(e=bi),e}return{getParameters:function(r,o,h,y,v){const x=y.fog,w=r.isMeshStandardMaterial?y.environment:null,b=(r.isMeshStandardMaterial?i:e).get(r.envMap||w),S=_[r.type],M=v.isSkinnedMesh?function(t){const e=t.skeleton.bones;if(d)return 1024;{const t=p,i=Math.floor((t-20)/4),n=Math.min(i,e.length);return n<e.length?0:n}}(v):0;let T,A,C,E;if(null!==r.precision&&(m=s.getMaxPrecision(r.precision),r.precision),S){const t=Ar[S];T=t.vertexShader,A=t.fragmentShader}else T=r.vertexShader,A=r.fragmentShader,l.update(r),C=l.getVertexShaderID(r),E=l.getFragmentShaderID(r);const z=t.getRenderTarget(),L=r.alphaTest>0,I=r.clearcoat>0;return{isWebGL2:c,shaderID:S,shaderName:r.type,vertexShader:T,fragmentShader:A,defines:r.defines,customVertexShaderID:C,customFragmentShaderID:E,isRawShaderMaterial:!0===r.isRawShaderMaterial,glslVersion:r.glslVersion,precision:m,instancing:!0===v.isInstancedMesh,instancingColor:!0===v.isInstancedMesh&&null!==v.instanceColor,supportsVertexTextures:f,outputEncoding:null!==z?g(z.texture):t.outputEncoding,map:!!r.map,mapEncoding:g(r.map),matcap:!!r.matcap,matcapEncoding:g(r.matcap),envMap:!!b,envMapMode:b&&b.mapping,envMapEncoding:g(b),envMapCubeUV:!!b&&(b.mapping===Yt||b.mapping===Xt),lightMap:!!r.lightMap,lightMapEncoding:g(r.lightMap),aoMap:!!r.aoMap,emissiveMap:!!r.emissiveMap,emissiveMapEncoding:g(r.emissiveMap),bumpMap:!!r.bumpMap,normalMap:!!r.normalMap,objectSpaceNormalMap:r.normalMapType===Ai,tangentSpaceNormalMap:r.normalMapType===Ti,clearcoat:I,clearcoatMap:I&&!!r.clearcoatMap,clearcoatRoughnessMap:I&&!!r.clearcoatRoughnessMap,clearcoatNormalMap:I&&!!r.clearcoatNormalMap,displacementMap:!!r.displacementMap,roughnessMap:!!r.roughnessMap,metalnessMap:!!r.metalnessMap,specularMap:!!r.specularMap,specularIntensityMap:!!r.specularIntensityMap,specularColorMap:!!r.specularColorMap,specularColorMapEncoding:g(r.specularColorMap),alphaMap:!!r.alphaMap,alphaTest:L,gradientMap:!!r.gradientMap,sheen:r.sheen>0,sheenColorMap:!!r.sheenColorMap,sheenColorMapEncoding:g(r.sheenColorMap),sheenRoughnessMap:!!r.sheenRoughnessMap,transmission:r.transmission>0,transmissionMap:!!r.transmissionMap,thicknessMap:!!r.thicknessMap,combine:r.combine,vertexTangents:!!r.normalMap&&!!v.geometry&&!!v.geometry.attributes.tangent,vertexColors:r.vertexColors,vertexAlphas:!0===r.vertexColors&&!!v.geometry&&!!v.geometry.attributes.color&&4===v.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:!!x,useFog:r.fog,fogExp2:x&&x.isFogExp2,flatShading:!!r.flatShading,sizeAttenuation:r.sizeAttenuation,logarithmicDepthBuffer:u,skinning:!0===v.isSkinnedMesh&&M>0,maxBones:M,useVertexTexture:d,morphTargets:!!v.geometry&&!!v.geometry.morphAttributes.position,morphNormals:!!v.geometry&&!!v.geometry.morphAttributes.normal,morphTargetsCount:v.geometry&&v.geometry.morphAttributes.position?v.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&&h.length>0,shadowMapType:t.shadowMap.type,toneMapping:r.toneMapped?t.toneMapping:kt,physicallyCorrectLights:t.physicallyCorrectLights,premultipliedAlpha:r.premultipliedAlpha,doubleSided:r.side===st,flipSided:r.side===nt,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:c||n.has("EXT_frag_depth"),rendererExtensionDrawBuffers:c||n.has("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:c||n.has("EXT_shader_texture_lod"),customProgramCacheKey:r.customProgramCacheKey()}},getProgramCacheKey:function(e){const i=[];if(e.shaderID?i.push(e.shaderID):(i.push(e.customVertexShaderID),i.push(e.customFragmentShaderID)),void 0!==e.defines)for(const t in e.defines)i.push(t),i.push(e.defines[t]);return!1===e.isRawShaderMaterial&&(function(t,e){t.push(e.precision),t.push(e.outputEncoding),t.push(e.mapEncoding),t.push(e.matcapEncoding),t.push(e.envMapMode),t.push(e.envMapEncoding),t.push(e.lightMapEncoding),t.push(e.emissiveMapEncoding),t.push(e.combine),t.push(e.vertexUvs),t.push(e.fogExp2),t.push(e.sizeAttenuation),t.push(e.maxBones),t.push(e.morphTargetsCount),t.push(e.numDirLights),t.push(e.numPointLights),t.push(e.numSpotLights),t.push(e.numHemiLights),t.push(e.numRectAreaLights),t.push(e.numDirLightShadows),t.push(e.numPointLightShadows),t.push(e.numSpotLightShadows),t.push(e.shadowMapType),t.push(e.toneMapping),t.push(e.numClippingPlanes),t.push(e.numClipIntersection),t.push(e.format),t.push(e.specularColorMapEncoding),t.push(e.sheenColorMapEncoding)}(i,e),function(t,e){o.disableAll(),e.isWebGL2&&o.enable(0),e.supportsVertexTextures&&o.enable(1),e.instancing&&o.enable(2),e.instancingColor&&o.enable(3),e.map&&o.enable(4),e.matcap&&o.enable(5),e.envMap&&o.enable(6),e.envMapCubeUV&&o.enable(7),e.lightMap&&o.enable(8),e.aoMap&&o.enable(9),e.emissiveMap&&o.enable(10),e.bumpMap&&o.enable(11),e.normalMap&&o.enable(12),e.objectSpaceNormalMap&&o.enable(13),e.tangentSpaceNormalMap&&o.enable(14),e.clearcoat&&o.enable(15),e.clearcoatMap&&o.enable(16),e.clearcoatRoughnessMap&&o.enable(17),e.clearcoatNormalMap&&o.enable(18),e.displacementMap&&o.enable(19),e.specularMap&&o.enable(20),e.roughnessMap&&o.enable(21),e.metalnessMap&&o.enable(22),e.gradientMap&&o.enable(23),e.alphaMap&&o.enable(24),e.alphaTest&&o.enable(25),e.vertexColors&&o.enable(26),e.vertexAlphas&&o.enable(27),e.vertexUvs&&o.enable(28),e.vertexTangents&&o.enable(29),e.uvsVertexOnly&&o.enable(30),e.fog&&o.enable(31),t.push(o.mask),o.disableAll(),e.useFog&&o.enable(0),e.flatShading&&o.enable(1),e.logarithmicDepthBuffer&&o.enable(2),e.skinning&&o.enable(3),e.useVertexTexture&&o.enable(4),e.morphTargets&&o.enable(5),e.morphNormals&&o.enable(6),e.premultipliedAlpha&&o.enable(7),e.shadowMapEnabled&&o.enable(8),e.physicallyCorrectLights&&o.enable(9),e.doubleSided&&o.enable(10),e.flipSided&&o.enable(11),e.depthPacking&&o.enable(12),e.dithering&&o.enable(13),e.specularIntensityMap&&o.enable(14),e.specularColorMap&&o.enable(15),e.transmission&&o.enable(16),e.transmissionMap&&o.enable(17),e.thicknessMap&&o.enable(18),e.sheen&&o.enable(19),e.sheenColorMap&&o.enable(20),e.sheenRoughnessMap&&o.enable(21),t.push(o.mask)}(i,e),i.push(t.outputEncoding)),i.push(e.customProgramCacheKey),i.join()},getUniforms:function(t){const e=_[t.type];let i;if(e){const t=Ar[e];i=ar.clone(t.uniforms)}else i=t.uniforms;return i},acquireProgram:function(e,i){let n;for(let t=0,e=h.length;t<e;t++){const e=h[t];if(e.cacheKey===i){n=e,++n.usedTimes;break}}return void 0===n&&(n=new Fo(t,i,e,r),h.push(n)),n},releaseProgram:function(t){if(0==--t.usedTimes){const e=h.indexOf(t);h[e]=h[h.length-1],h.pop(),t.destroy()}},releaseShaderCache:function(t){l.remove(t)},programs:h,dispose:function(){l.dispose()}}}function Vo(){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 Wo(t,e){return t.groupOrder!==e.groupOrder?t.groupOrder-e.groupOrder:t.renderOrder!==e.renderOrder?t.renderOrder-e.renderOrder: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 Go(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 Ho(){const t=[];let e=0;const i=[],n=[],s=[];function r(i,n,s,r,a,o){let l=t[e];return void 0===l?(l={id:i.id,object:i,geometry:n,material:s,groupOrder:r,renderOrder:i.renderOrder,z:a,group:o},t[e]=l):(l.id=i.id,l.object=i,l.geometry=n,l.material=s,l.groupOrder=r,l.renderOrder=i.renderOrder,l.z=a,l.group=o),e++,l}return{opaque:i,transmissive:n,transparent:s,init:function(){e=0,i.length=0,n.length=0,s.length=0},push:function(t,e,a,o,l,h){const c=r(t,e,a,o,l,h);a.transmission>0?n.push(c):!0===a.transparent?s.push(c):i.push(c)},unshift:function(t,e,a,o,l,h){const c=r(t,e,a,o,l,h);a.transmission>0?n.unshift(c):!0===a.transparent?s.unshift(c):i.unshift(c)},finish:function(){for(let i=e,n=t.length;i<n;i++){const e=t[i];if(null===e.id)break;e.id=null,e.object=null,e.geometry=null,e.material=null,e.group=null}},sort:function(t,e){i.length>1&&i.sort(t||Wo),n.length>1&&n.sort(e||Go),s.length>1&&s.sort(e||Go)}}}function jo(){let t=new WeakMap;return{get:function(e,i){let n;return!1===t.has(e)?(n=new Ho,t.set(e,[n])):i>=t.get(e).length?(n=new Ho,t.get(e).push(n)):n=t.get(e)[i],n},dispose:function(){t=new WeakMap}}}function qo(){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 Qi,color:new bs};break;case"SpotLight":i={position:new Qi,direction:new Qi,color:new bs,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":i={position:new Qi,color:new bs,distance:0,decay:0};break;case"HemisphereLight":i={direction:new Qi,skyColor:new bs,groundColor:new bs};break;case"RectAreaLight":i={color:new bs,position:new Qi,halfWidth:new Qi,halfHeight:new Qi}}return t[e.id]=i,i}}}let Jo=0;function Yo(t,e){return(e.castShadow?1:0)-(t.castShadow?1:0)}function Xo(t,e){const i=new qo,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 Vi};break;case"PointLight":i={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Vi,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 Qi);const r=new Qi,a=new In,o=new In;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(Yo);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=Tr.LTC_FLOAT_1,s.rectAreaLTC2=Tr.LTC_FLOAT_2):!0===t.has("OES_texture_half_float_linear")&&(s.rectAreaLTC1=Tr.LTC_HALF_1,s.rectAreaLTC2=Tr.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=Jo++)},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 $o(t,e){const i=new Xo(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 Zo(t,e){let i=new WeakMap;return{get:function(n,s=0){let r;return!1===i.has(n)?(r=new $o(t,e),i.set(n,[r])):s>=i.get(n).length?(r=new $o(t,e),i.get(n).push(r)):r=i.get(n)[s],r},dispose:function(){i=new WeakMap}}}class Ko extends ms{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}}Ko.prototype.isMeshDepthMaterial=!0;class Qo extends ms{constructor(t){super(),this.type="MeshDistanceMaterial",this.referencePosition=new Qi,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}}Qo.prototype.isMeshDistanceMaterial=!0;const tl="void main() {\n\tgl_Position = vec4( position, 1.0 );\n}",el="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 il(t,e,i){let n=new xr;const s=new Vi,r=new Vi,a=new Xi,o=new Ko({depthPacking:Mi}),l=new Qo,h={},c=i.maxTextureSize,u={0:nt,1:it,2:st},d=new or({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new Vi},radius:{value:4}},vertexShader:tl,fragmentShader:el}),p=d.clone();p.defines.HORIZONTAL_PASS=1;const f=new Rs;f.setAttribute("position",new As(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const m=new er(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===et?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===et)&&(!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=Q,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(rt),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===et){const t={minFilter:ie,magFilter:ie,format:ve};u.map=new $i(s.x,s.y,t),u.map.texture.name=h.name+".shadowMap",u.mapPass=new $i(s.x,s.y,t),u.camera.updateProjectionMatrix()}if(null===u.map){const t={minFilter:Qt,magFilter:Qt,format:ve};u.map=new $i(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!==et||g(u,o),u.needsUpdate=!1}_.needsUpdate=!1,t.setRenderTarget(l,h,u)}}function nl(t,e,i){const n=i.isWebGL2,s=new function(){let e=!1;const i=new Xi;let n=null;const s=new Xi(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?F(2929):R(2929)},setMask:function(n){i===n||e||(t.depthMask(n),i=n)},setFunc:function(e){if(n!==e){if(e)switch(e){case Ct:t.depthFunc(512);break;case Et:t.depthFunc(519);break;case zt:t.depthFunc(513);break;case Lt:t.depthFunc(515);break;case It:t.depthFunc(514);break;case Nt:t.depthFunc(518);break;case Pt:t.depthFunc(516);break;case Dt: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?F(2960):R(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 T=!1,A=0;const C=t.getParameter(7938);-1!==C.indexOf("WebGL")?(A=parseFloat(/^WebGL (\d)/.exec(C)[1]),T=A>=1):-1!==C.indexOf("OpenGL ES")&&(A=parseFloat(/^OpenGL ES (\d)/.exec(C)[1]),T=A>=2);let E=null,z={};const L=t.getParameter(3088),I=t.getParameter(2978),N=(new Xi).fromArray(L),P=(new Xi).fromArray(I);function D(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 O={};function F(e){!0!==o[e]&&(t.enable(e),o[e]=!0)}function R(e){!1!==o[e]&&(t.disable(e),o[e]=!1)}O[3553]=D(3553,3553,1),O[34067]=D(34067,34069,6),s.setClear(0,0,0,1),r.setClear(1),a.setClear(0),F(2929),r.setFunc(Lt),V(!1),W(Z),F(2884),U(rt);const k={[ut]:32774,[dt]:32778,[pt]:32779};if(n)k[ft]=32775,k[mt]=32776;else{const t=e.get("EXT_blend_minmax");null!==t&&(k[ft]=t.MIN_EXT,k[mt]=t.MAX_EXT)}const B={[_t]:0,[gt]:1,[yt]:768,[xt]:770,[At]:776,[Mt]:774,[bt]:772,[vt]:769,[wt]:771,[Tt]:775,[St]:773};function U(e,i,n,s,r,a,o,l){if(e!==rt){if(!1===c&&(F(3042),c=!0),e===ct)r=r||i,a=a||n,o=o||s,i===d&&r===m||(t.blendEquationSeparate(k[i],k[r]),d=i,m=r),n===p&&s===f&&a===_&&o===g||(t.blendFuncSeparate(B[n],B[s],B[a],B[o]),p=n,f=s,_=a,g=o),u=e,y=null;else if(e!==u||l!==y){if(d===ut&&m===ut||(t.blendEquation(32774),d=ut,m=ut),l)switch(e){case at:t.blendFuncSeparate(1,771,1,771);break;case ot:t.blendFunc(1,1);break;case lt:t.blendFuncSeparate(0,0,769,771);break;case ht:t.blendFuncSeparate(0,768,0,770)}else switch(e){case at:t.blendFuncSeparate(770,771,1,771);break;case ot:t.blendFunc(770,1);break;case lt:t.blendFunc(0,769);break;case ht:t.blendFunc(0,768)}p=null,f=null,_=null,g=null,u=e,y=l}}else!0===c&&(R(3042),c=!1)}function V(e){v!==e&&(e?t.frontFace(2304):t.frontFace(2305),v=e)}function W(e){e!==$?(F(2884),e!==x&&(e===Z?t.cullFace(1029):e===K?t.cullFace(1028):t.cullFace(1032))):R(2884),x=e}function G(e,i,n){e?(F(32823),b===i&&S===n||(t.polygonOffset(i,n),b=i,S=n)):R(32823)}function H(e){void 0===e&&(e=33984+M-1),E!==e&&(t.activeTexture(e),E=e)}return{buffers:{color:s,depth:r,stencil:a},enable:F,disable:R,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:U,setMaterial:function(t,e){t.side===st?R(2884):F(2884);let i=t.side===nt;e&&(i=!i),V(i),t.blending===at&&!1===t.transparent?U(rt):U(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)),G(t.polygonOffset,t.polygonOffsetFactor,t.polygonOffsetUnits),!0===t.alphaToCoverage?F(32926):R(32926)},setFlipSided:V,setCullFace:W,setLineWidth:function(e){e!==w&&(T&&t.lineWidth(e),w=e)},setPolygonOffset:G,setScissorTest:function(t){t?F(3089):R(3089)},activeTexture:H,bindTexture:function(e,i){null===E&&H();let n=z[E];void 0===n&&(n={type:void 0,texture:void 0},z[E]=n),n.type===e&&n.texture===i||(t.bindTexture(e,i||O[e]),n.type=e,n.texture=i)},unbindTexture:function(){const e=z[E];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){}},texStorage3D:function(){try{t.texStorage3D.apply(t,arguments)}catch(t){}},texSubImage2D:function(){try{t.texSubImage2D.apply(t,arguments)}catch(t){}},texSubImage3D:function(){try{t.texSubImage3D.apply(t,arguments)}catch(t){}},compressedTexSubImage2D:function(){try{t.compressedTexSubImage2D.apply(t,arguments)}catch(t){}},scissor:function(e){!1===N.equals(e)&&(t.scissor(e.x,e.y,e.z,e.w),N.copy(e))},viewport:function(e){!1===P.equals(e)&&(t.viewport(e.x,e.y,e.z,e.w),P.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={},E=null,z={},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,N.set(0,0,t.canvas.width,t.canvas.height),P.set(0,0,t.canvas.width,t.canvas.height),s.reset(),r.reset(),a.reset()}}}function sl(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):Hi("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?Bi: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 ki(t.width)&&ki(t.height)}function y(t,e){return t.generateMipmaps&&e&&t.minFilter!==Qt&&t.minFilter!==ie}function v(e){t.generateMipmap(e)}function x(i,n,s,r){if(!1===o)return n;if(null!==i&&void 0!==t[i])return t[i];let a=n;return 6403===n&&(5126===s&&(a=33326),5131===s&&(a=33325),5121===s&&(a=33321)),6407===n&&(5126===s&&(a=34837),5131===s&&(a=34843),5121===s&&(a=32849)),6408===n&&(5126===s&&(a=34836),5131===s&&(a=34842),5121===s&&(a=r===Si?35907:32856)),33325!==a&&33326!==a&&34842!==a&&34836!==a||e.get("EXT_color_buffer_float"),a}function w(t,e,i){return!0===y(t,i)||t.isFramebufferTexture&&t.minFilter!==Qt&&t.minFilter!==ie?Math.log2(Math.max(e.width,e.height))+1:void 0!==t.mipmaps&&t.mipmaps.length>0?t.mipmaps.length:t.isCompressedTexture&&Array.isArray(t.image)?e.mipmaps.length:1}function b(t){return t===Qt||t===te||t===ee?9728:9729}function S(e){const i=e.target;i.removeEventListener("dispose",S),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 M(e){const i=e.target;i.removeEventListener("dispose",M),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 T=0;function A(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=c[0],d=g(u)||o,p=r.convert(n.format),f=r.convert(n.type),m=x(n.internalFormat,p,f,n.encoding),b=o&&!0!==n.isVideoTexture,S=void 0===e.__version;let M,T=w(n,u,d);if(L(34067,n,d),a){b&&S&&i.texStorage2D(34067,T,m,u.width,u.height);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!==ve&&n.format!==ye?null!==p&&(b?i.compressedTexSubImage2D(34069+t,e,0,0,s.width,s.height,p,s.data):i.compressedTexImage2D(34069+t,e,m,s.width,s.height,0,s.data)):b?i.texSubImage2D(34069+t,e,0,0,s.width,s.height,p,f,s.data):i.texImage2D(34069+t,e,m,s.width,s.height,0,p,f,s.data)}}}else{M=n.mipmaps,b&&S&&(M.length>0&&T++,i.texStorage2D(34067,T,m,c[0].width,c[0].height));for(let t=0;t<6;t++)if(h){b?i.texSubImage2D(34069+t,0,0,0,c[t].width,c[t].height,p,f,c[t].data):i.texImage2D(34069+t,0,m,c[t].width,c[t].height,0,p,f,c[t].data);for(let e=0;e<M.length;e++){const n=M[e].image[t].image;b?i.texSubImage2D(34069+t,e+1,0,0,n.width,n.height,p,f,n.data):i.texImage2D(34069+t,e+1,m,n.width,n.height,0,p,f,n.data)}}else{b?i.texSubImage2D(34069+t,0,0,0,p,f,c[t]):i.texImage2D(34069+t,0,m,p,f,c[t]);for(let e=0;e<M.length;e++){const n=M[e];b?i.texSubImage2D(34069+t,e+1,0,0,p,f,n.image[t]):i.texImage2D(34069+t,e+1,m,p,f,n.image[t])}}}y(n,d)&&v(34067),e.__version=n.version,n.onUpdate&&n.onUpdate(n)}(a,e,s):(i.activeTexture(33984+s),i.bindTexture(34067,a.__webglTexture))}const E={[$t]:10497,[Zt]:33071,[Kt]:33648},z={[Qt]:9728,[te]:9984,[ee]:9986,[ie]:9729,[ne]:9985,[se]:9987};function L(i,r,a){if(a?(t.texParameteri(i,10242,E[r.wrapS]),t.texParameteri(i,10243,E[r.wrapT]),32879!==i&&35866!==i||t.texParameteri(i,32882,E[r.wrapR]),t.texParameteri(i,10240,z[r.magFilter]),t.texParameteri(i,10241,z[r.minFilter])):(t.texParameteri(i,10242,33071),t.texParameteri(i,10243,33071),32879!==i&&35866!==i||t.texParameteri(i,32882,33071),r.wrapS!==Zt||r.wrapT,t.texParameteri(i,10240,b(r.magFilter)),t.texParameteri(i,10241,b(r.minFilter)),r.minFilter!==Qt&&r.minFilter),!0===e.has("EXT_texture_filter_anisotropic")){const a=e.get("EXT_texture_filter_anisotropic");if(r.type===ue&&!1===e.has("OES_texture_float_linear"))return;if(!1===o&&r.type===de&&!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",S),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!==Zt||t.wrapT!==Zt||t.minFilter!==Qt&&t.minFilter!==ie)}(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);L(a,n,u);const b=n.mipmaps,S=o&&!0!==n.isVideoTexture,M=void 0===e.__version,T=w(n,c,u);if(n.isDepthTexture)m=6402,o?m=n.type===ue?36012:n.type===ce?33190:n.type===_e?35056:33189:n.type,n.format===be&&6402===m&&n.type!==le&&n.type!==ce&&(n.type=le,f=r.convert(n.type)),n.format===Se&&6402===m&&(m=34041,n.type!==_e&&(n.type=_e,f=r.convert(n.type))),S&&M?i.texStorage2D(3553,1,m,c.width,c.height):i.texImage2D(3553,0,m,c.width,c.height,0,d,f,null);else if(n.isDataTexture)if(b.length>0&&u){S&&M&&i.texStorage2D(3553,T,m,b[0].width,b[0].height);for(let t=0,e=b.length;t<e;t++)p=b[t],S?i.texSubImage2D(3553,0,0,0,p.width,p.height,d,f,p.data):i.texImage2D(3553,t,m,p.width,p.height,0,d,f,p.data);n.generateMipmaps=!1}else S?(M&&i.texStorage2D(3553,T,m,c.width,c.height),i.texSubImage2D(3553,0,0,0,c.width,c.height,d,f,c.data)):i.texImage2D(3553,0,m,c.width,c.height,0,d,f,c.data);else if(n.isCompressedTexture){S&&M&&i.texStorage2D(3553,T,m,b[0].width,b[0].height);for(let t=0,e=b.length;t<e;t++)p=b[t],n.format!==ve&&n.format!==ye?null!==d&&(S?i.compressedTexSubImage2D(3553,t,0,0,p.width,p.height,d,p.data):i.compressedTexImage2D(3553,t,m,p.width,p.height,0,p.data)):S?i.texSubImage2D(3553,t,0,0,p.width,p.height,d,f,p.data):i.texImage2D(3553,t,m,p.width,p.height,0,d,f,p.data)}else if(n.isDataTexture2DArray)S?(M&&i.texStorage3D(35866,T,m,c.width,c.height,c.depth),i.texSubImage3D(35866,0,0,0,0,c.width,c.height,c.depth,d,f,c.data)):i.texImage3D(35866,0,m,c.width,c.height,c.depth,0,d,f,c.data);else if(n.isDataTexture3D)S?(M&&i.texStorage3D(32879,T,m,c.width,c.height,c.depth),i.texSubImage3D(32879,0,0,0,0,c.width,c.height,c.depth,d,f,c.data)):i.texImage3D(32879,0,m,c.width,c.height,c.depth,0,d,f,c.data);else if(n.isFramebufferTexture)S&&M?i.texStorage2D(3553,T,m,c.width,c.height):i.texImage2D(3553,0,m,c.width,c.height,0,d,f,null);else if(b.length>0&&u){S&&M&&i.texStorage2D(3553,T,m,b[0].width,b[0].height);for(let t=0,e=b.length;t<e;t++)p=b[t],S?i.texSubImage2D(3553,t,0,0,d,f,p):i.texImage2D(3553,t,m,d,f,p);n.generateMipmaps=!1}else S?(M&&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 P(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,F(s)):t.framebufferTexture2D(36160,o,l,n.get(a).__webglTexture,0),i.bindFramebuffer(36160,null)}function D(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===ue?s=36012:e.type===ce&&(s=33190));const n=F(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=F(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=F(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 O(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),A(s.depthTexture,0);const r=n.get(s.depthTexture).__webglTexture,a=F(s);if(s.depthTexture.format===be)s.useRenderToTexture?u.framebufferTexture2DMultisampleEXT(36160,36096,3553,r,0,a):t.framebufferTexture2D(36160,36096,3553,r,0);else{if(s.depthTexture.format!==Se)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(),D(s.__webglDepthbuffer[n],e,!1)}else i.bindFramebuffer(36160,s.__webglFramebuffer),s.__webglDepthbuffer=t.createRenderbuffer(),D(s.__webglDepthbuffer,e,!1);i.bindFramebuffer(36160,null)}function F(t){return o&&(t.useRenderbuffer||t.useRenderToTexture)?Math.min(c,t.samples):0}this.allocateTextureUnit=function(){const t=T;return T+=1,t},this.resetTextureUnits=function(){T=0},this.setTexture2D=A,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&&P(s.__webglFramebuffer,t,t.texture,36064,3553),void 0!==i&&O(t)},this.setupRenderTarget=function(e){const l=e.texture,h=n.get(e),c=n.get(l);e.addEventListener("dispose",M),!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!==ye||l.type!==ue&&l.type!==de||(l.format=ve),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=F(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(),D(h.__webglDepthRenderbuffer,e,!0)),i.bindFramebuffer(36160,null)}if(u){i.bindTexture(34067,c.__webglTexture),L(34067,l,f);for(let t=0;t<6;t++)P(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),L(3553,r,f),P(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),L(t,l,f),P(h.__webglFramebuffer,e,l,36064,t),y(l,f)&&v(t),i.unbindTexture()}e.depthBuffer&&O(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=O,this.setupFrameBufferTexture=P,this.safeSetTexture2D=function(t,e){t&&t.isWebGLRenderTarget&&(t=t.texture),A(t,e)},this.safeSetTextureCube=function(t,e){t&&t.isWebGLCubeRenderTarget&&(t=t.texture),C(t,e)}}function rl(t,e,i){const n=i.isWebGL2;return{convert:function(t){let i;if(t===re)return 5121;if(t===pe)return 32819;if(t===fe)return 32820;if(t===me)return 33635;if(t===ae)return 5120;if(t===oe)return 5122;if(t===le)return 5123;if(t===he)return 5124;if(t===ce)return 5125;if(t===ue)return 5126;if(t===de)return n?5131:(i=e.get("OES_texture_half_float"),null!==i?i.HALF_FLOAT_OES:null);if(t===ge)return 6406;if(t===ye)return 6407;if(t===ve)return 6408;if(t===xe)return 6409;if(t===we)return 6410;if(t===be)return 6402;if(t===Se)return 34041;if(t===Me)return 6403;if(t===Te)return 36244;if(t===Ae)return 33319;if(t===Ce)return 33320;if(t===Ee)return 36248;if(t===ze)return 36249;if(t===Le||t===Ie||t===Ne||t===Pe){if(i=e.get("WEBGL_compressed_texture_s3tc"),null===i)return null;if(t===Le)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(t===Ie)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(t===Ne)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(t===Pe)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(t===De||t===Oe||t===Fe||t===Re){if(i=e.get("WEBGL_compressed_texture_pvrtc"),null===i)return null;if(t===De)return i.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(t===Oe)return i.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(t===Fe)return i.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(t===Re)return i.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(t===ke)return i=e.get("WEBGL_compressed_texture_etc1"),null!==i?i.COMPRESSED_RGB_ETC1_WEBGL:null;if((t===Be||t===Ue)&&(i=e.get("WEBGL_compressed_texture_etc"),null!==i)){if(t===Be)return i.COMPRESSED_RGB8_ETC2;if(t===Ue)return i.COMPRESSED_RGBA8_ETC2_EAC}return t===Ve||t===We||t===Ge||t===He||t===je||t===qe||t===Je||t===Ye||t===Xe||t===$e||t===Ze||t===Ke||t===Qe||t===ti||t===ii||t===ni||t===si||t===ri||t===ai||t===oi||t===li||t===hi||t===ci||t===ui||t===di||t===pi||t===fi||t===mi?(i=e.get("WEBGL_compressed_texture_astc"),null!==i?t:null):t===ei?(i=e.get("EXT_texture_compression_bptc"),null!==i?t:null):t===_e?n?34042:(i=e.get("WEBGL_depth_texture"),null!==i?i.UNSIGNED_INT_24_8_WEBGL:null):void 0}}}class al extends hr{constructor(t=[]){super(),this.cameras=t}}al.prototype.isArrayCamera=!0;class ol extends is{constructor(){super(),this.type="Group"}}ol.prototype.isGroup=!0;const ll={type:"move"};class hl{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return null===this._hand&&(this._hand=new ol,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 ol,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new Qi,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new Qi),this._targetRay}getGripSpace(){return null===this._grip&&(this._grip=new ol,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new Qi,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new Qi),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(ll))),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 ol;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 cl extends Ji{constructor(t,e,i,n,s,r,a,o,l,h){if((h=void 0!==h?h:be)!==be&&h!==Se)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===i&&h===be&&(i=le),void 0===i&&h===Se&&(i=_e),super(null,n,s,r,a,o,h,i,l),this.image={width:t,height:e},this.magFilter=void 0!==a?a:Qt,this.minFilter=void 0!==o?o:Qt,this.flipY=!1,this.generateMipmaps=!1}}cl.prototype.isDepthTexture=!0;class ul extends Ii{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 hr;v.layers.enable(1),v.viewport=new Xi;const x=new hr;x.layers.enable(2),x.viewport=new Xi;const w=[v,x],b=new al;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 A(){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,N.stop(),i.isPresenting=!1,i.dispatchEvent({type:"sessionend"})}function C(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 hl,g[t]=e),e.getTargetRaySpace()},this.getControllerGrip=function(t){let e=g[t];return void 0===e&&(e=new hl,g[t]=e),e.getGripSpace()},this.getHand=function(t){let e=g[t];return void 0===e&&(e=new hl,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",A),n.addEventListener("inputsourceschange",C),!0!==f.xrCompatible&&await e.makeXRCompatible(),void 0===n.renderState.layers||!1===t.capabilities.isWebGL2){const i={antialias:void 0!==n.renderState.layers||f.antialias,alpha:f.alpha,depth:f.depth,stencil:f.stencil,framebufferScaleFactor:s};u=new XRWebGLLayer(n,e,i),n.updateRenderState({baseLayer:u}),_=new $i(u.framebufferWidth,u.framebufferHeight,{format:ve,type:re,encoding:t.outputEncoding})}else{d=f.antialias;let i=null,r=null,a=null;f.depth&&(a=f.stencil?35056:33190,i=f.stencil?Se:be,r=f.stencil?_e:le);const l={colorFormat:f.alpha||d?32856:32849,depthFormat:a,scaleFactor:s};h=new XRWebGLBinding(n,e),c=h.createProjectionLayer(l),n.updateRenderState({layers:[c]}),_=d?new Zi(c.textureWidth,c.textureHeight,{format:ve,type:re,depthTexture:new cl(c.textureWidth,c.textureHeight,r,void 0,void 0,void 0,void 0,void 0,void 0,i),stencilBuffer:f.stencil,ignoreDepth:c.ignoreDepthValues,useRenderToTexture:o,encoding:t.outputEncoding}):new $i(c.textureWidth,c.textureHeight,{format:f.alpha?ve:ye,type:re,depthTexture:new cl(c.textureWidth,c.textureHeight,r,void 0,void 0,void 0,void 0,void 0,void 0,i),stencilBuffer:f.stencil,ignoreDepth:c.ignoreDepthValues,encoding:t.outputEncoding})}this.setFoveation(1),r=await n.requestReferenceSpace(a),N.setContext(n),N.start(),i.isPresenting=!0,i.dispatchEvent({type:"sessionstart"})}};const E=new Qi,z=new Qi;function L(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;L(b,e);for(let t=0;t<i.length;t++)L(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 I=null;const N=new wr;N.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)}I&&I(e,i),p=null})),this.setAnimationLoop=function(t){I=t},this.dispose=function(){}}}function dl(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===nt&&(e.bumpScale.value*=-1)),i.normalMap&&(e.normalMap.value=i.normalMap,e.normalScale.value.copy(i.normalScale),i.side===nt&&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===nt&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===nt&&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===nt&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===nt&&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===nt&&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===nt&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===nt&&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===nt&&(t.bumpScale.value*=-1)),e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale),e.side===nt&&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 pl(t={}){const e=void 0!==t.canvas?t.canvas:function(){const t=Hi("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.outputEncoding=bi,this.physicallyCorrectLights=!1,this.toneMapping=kt,this.toneMappingExposure=1;const m=this;let _=!1,g=0,y=0,v=null,x=-1,w=null;const b=new Xi,S=new Xi;let M=null,T=e.width,A=e.height,C=1,E=null,z=null;const L=new Xi(0,0,T,A),I=new Xi(0,0,T,A);let N=!1;const P=[],D=new xr;let O=!1,F=!1,R=null;const k=new In,B=new Qi,U={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};function V(){return null===v?C:1}let W,G,H,j,q,J,Y,$,Z,K,Q,tt,et,rt,at,ot,lt,ht,ct,ut,dt,pt,ft,mt=i;function _t(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${X}`),e.addEventListener("webglcontextlost",vt,!1),e.addEventListener("webglcontextrestored",xt,!1),null===mt){const e=["webgl2","webgl","experimental-webgl"];if(!0===m.isWebGL1Renderer&&e.shift(),mt=_t(e,t),null===mt)throw _t(e)?new Error("Error creating WebGL context with your selected attributes."):new Error("Error creating WebGL context.")}void 0===mt.getShaderPrecisionFormat&&(mt.getShaderPrecisionFormat=function(){return{rangeMin:1,rangeMax:1,precision:1}})}catch(t){throw t}function gt(){W=new ea(mt),G=new Lr(mt,W,t),W.init(G),pt=new rl(mt,W,G),H=new nl(mt,W,G),P[0]=1029,j=new sa,q=new Vo,J=new sl(mt,W,H,q,G,pt,j),Y=new Nr(m),$=new ta(m),Z=new br(mt,G),ft=new Er(mt,W,Z,G),K=new ia(mt,Z,j,ft),Q=new ca(mt,K,Z,j),ct=new ha(mt,G,J),ot=new Ir(q),tt=new Uo(m,Y,$,W,G,ft,ot),et=new dl(q),rt=new jo,at=new Zo(W,G),ht=new Cr(m,Y,H,Q,o),lt=new il(m,Q,G),ut=new zr(mt,W,j,G),dt=new na(mt,W,j,G),j.programs=tt.programs,m.capabilities=G,m.extensions=W,m.properties=q,m.renderLists=rt,m.shadowMap=lt,m.state=H,m.info=j}gt();const yt=new ul(m,mt);function vt(t){t.preventDefault(),_=!0}function xt(){_=!1;const t=j.autoReset,e=lt.enabled,i=lt.autoUpdate,n=lt.needsUpdate,s=lt.type;gt(),j.autoReset=t,lt.enabled=e,lt.autoUpdate=i,lt.needsUpdate=n,lt.type=s}function wt(t){const e=t.target;e.removeEventListener("dispose",wt),function(t){(function(t){const e=q.get(t).programs;void 0!==e&&(e.forEach((function(t){tt.releaseProgram(t)})),t.isShaderMaterial&&tt.releaseShaderCache(t))})(t),q.remove(t)}(e)}this.xr=yt,this.getContext=function(){return mt},this.getContextAttributes=function(){return mt.getContextAttributes()},this.forceContextLoss=function(){const t=W.get("WEBGL_lose_context");t&&t.loseContext()},this.forceContextRestore=function(){const t=W.get("WEBGL_lose_context");t&&t.restoreContext()},this.getPixelRatio=function(){return C},this.setPixelRatio=function(t){void 0!==t&&(C=t,this.setSize(T,A,!1))},this.getSize=function(t){return t.set(T,A)},this.setSize=function(t,i,n){yt.isPresenting||(T=t,A=i,e.width=Math.floor(t*C),e.height=Math.floor(i*C),!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(T*C,A*C).floor()},this.setDrawingBufferSize=function(t,i,n){T=t,A=i,C=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(L)},this.setViewport=function(t,e,i,n){t.isVector4?L.set(t.x,t.y,t.z,t.w):L.set(t,e,i,n),H.viewport(b.copy(L).multiplyScalar(C).floor())},this.getScissor=function(t){return t.copy(I)},this.setScissor=function(t,e,i,n){t.isVector4?I.set(t.x,t.y,t.z,t.w):I.set(t,e,i,n),H.scissor(S.copy(I).multiplyScalar(C).floor())},this.getScissorTest=function(){return N},this.setScissorTest=function(t){H.setScissorTest(N=t)},this.setOpaqueSort=function(t){E=t},this.setTransparentSort=function(t){z=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),mt.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",vt,!1),e.removeEventListener("webglcontextrestored",xt,!1),rt.dispose(),at.dispose(),q.dispose(),Y.dispose(),$.dispose(),Q.dispose(),ft.dispose(),tt.dispose(),yt.dispose(),yt.removeEventListener("sessionstart",St),yt.removeEventListener("sessionend",Mt),R&&(R.dispose(),R=null),Tt.stop()},this.renderBufferDirect=function(t,e,i,n,s,r){null===e&&(e=U);const a=s.isMesh&&s.matrixWorld.determinant()<0,o=function(t,e,i,n,s){!0!==e.isScene&&(e=U),J.resetTextureUnits();const r=e.fog,a=n.isMeshStandardMaterial?e.environment:null,o=null===v?m.outputEncoding:v.texture.encoding,l=(n.isMeshStandardMaterial?$:Y).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,_=n.toneMapped?m.toneMapping:kt,g=q.get(n),y=d.state.lights;if(!0===O&&(!0===F||t!==w)){const e=t===w&&n.id===x;ot.setState(n,t,e)}let b=!1;n.version===g.__version?g.needsLights&&g.lightsStateVersion!==y.state.version||g.outputEncoding!==o||s.isInstancedMesh&&!1===g.instancing?b=!0:s.isInstancedMesh||!0!==g.instancing?s.isSkinnedMesh&&!1===g.skinning?b=!0:s.isSkinnedMesh||!0!==g.skinning?g.envMap!==l||n.fog&&g.fog!==r?b=!0:void 0===g.numClippingPlanes||g.numClippingPlanes===ot.numPlanes&&g.numIntersection===ot.numIntersection?(g.vertexAlphas!==h||g.vertexTangents!==c||g.morphTargets!==u||g.morphNormals!==p||g.toneMapping!==_||!0===G.isWebGL2&&g.morphTargetsCount!==f)&&(b=!0):b=!0:b=!0:b=!0:(b=!0,g.__version=n.version);let S=g.currentProgram;!0===b&&(S=Lt(n,e,s));let M=!1,T=!1,E=!1;const z=S.getUniforms(),L=g.uniforms;if(H.useProgram(S.program)&&(M=!0,T=!0,E=!0),n.id!==x&&(x=n.id,T=!0),M||w!==t){if(z.setValue(mt,"projectionMatrix",t.projectionMatrix),G.logarithmicDepthBuffer&&z.setValue(mt,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),w!==t&&(w=t,T=!0,E=!0),n.isShaderMaterial||n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshStandardMaterial||n.envMap){const e=z.map.cameraPosition;void 0!==e&&e.setValue(mt,B.setFromMatrixPosition(t.matrixWorld))}(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial)&&z.setValue(mt,"isOrthographic",!0===t.isOrthographicCamera),(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial||n.isShadowMaterial||s.isSkinnedMesh)&&z.setValue(mt,"viewMatrix",t.matrixWorldInverse)}if(s.isSkinnedMesh){z.setOptional(mt,s,"bindMatrix"),z.setOptional(mt,s,"bindMatrixInverse");const t=s.skeleton;t&&(G.floatVertexTextures?(null===t.boneTexture&&t.computeBoneTexture(),z.setValue(mt,"boneTexture",t.boneTexture,J),z.setValue(mt,"boneTextureSize",t.boneTextureSize)):z.setOptional(mt,t,"boneMatrices"))}return!i||void 0===i.morphAttributes.position&&void 0===i.morphAttributes.normal||ct.update(s,i,n,S),(T||g.receiveShadow!==s.receiveShadow)&&(g.receiveShadow=s.receiveShadow,z.setValue(mt,"receiveShadow",s.receiveShadow)),T&&(z.setValue(mt,"toneMappingExposure",m.toneMappingExposure),g.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}(L,E),r&&n.fog&&et.refreshFogUniforms(L,r),et.refreshMaterialUniforms(L,n,C,A,R),_o.upload(mt,g.uniformsList,L,J)),n.isShaderMaterial&&!0===n.uniformsNeedUpdate&&(_o.upload(mt,g.uniformsList,L,J),n.uniformsNeedUpdate=!1),n.isSpriteMaterial&&z.setValue(mt,"center",s.center),z.setValue(mt,"modelViewMatrix",s.modelViewMatrix),z.setValue(mt,"normalMatrix",s.normalMatrix),z.setValue(mt,"modelMatrix",s.matrixWorld),S}(t,e,i,n,s);H.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=K.getWireframeAttribute(i),u=2),ft.setup(s,n,o,i,l);let p=ut;null!==l&&(c=Z.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?(H.setLineWidth(n.wireframeLinewidth*V()),p.setMode(1)):p.setMode(4);else if(s.isLine){let t=n.linewidth;void 0===t&&(t=1),H.setLineWidth(t*V()),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++)Lt(i[n],t,e);else Lt(i,t,e)})),f.pop(),d=null};let bt=null;function St(){Tt.stop()}function Mt(){Tt.start()}const Tt=new wr;function At(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||D.intersectsSprite(t)){n&&B.setFromMatrixPosition(t.matrixWorld).applyMatrix4(k);const e=Q.update(t),s=t.material;s.visible&&u.push(t,e,s,i,B.z,null)}}else if((t.isMesh||t.isLine||t.isPoints)&&(t.isSkinnedMesh&&t.skeleton.frame!==j.render.frame&&(t.skeleton.update(),t.skeleton.frame=j.render.frame),!t.frustumCulled||D.intersectsObject(t))){n&&B.setFromMatrixPosition(t.matrixWorld).applyMatrix4(k);const e=Q.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,B.z,a)}}else s.visible&&u.push(t,e,s,i,B.z,null)}const s=t.children;for(let t=0,r=s.length;t<r;t++)At(s[t],e,i,n)}function Ct(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===R){const t=!0===a&&!0===G.isWebGL2;R=new(t?Zi:$i)(1024,1024,{generateMipmaps:!0,type:null!==pt.convert(de)?de:re,minFilter:se,magFilter:Qt,wrapS:Zt,wrapT:Zt,useRenderToTexture:W.has("WEBGL_multisampled_render_to_texture")})}const n=m.getRenderTarget();m.setRenderTarget(R),m.clear();const s=m.toneMapping;m.toneMapping=kt,Et(t,e,i),m.toneMapping=s,J.updateMultisampleRenderTarget(R),J.updateRenderTargetMipmap(R),m.setRenderTarget(n)}(s,e,i),n&&H.viewport(b.copy(n)),s.length>0&&Et(s,e,i),r.length>0&&Et(r,e,i),o.length>0&&Et(o,e,i)}function Et(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)&&zt(a,e,i,o,l,h)}}function zt(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===st?(s.side=nt,s.needsUpdate=!0,m.renderBufferDirect(i,e,n,s,t,r),s.side=it,s.needsUpdate=!0,m.renderBufferDirect(i,e,n,s,t,r),s.side=st):m.renderBufferDirect(i,e,n,s,t,r),t.onAfterRender(m,e,i,n,s,r)}function Lt(t,e,i){!0!==e.isScene&&(e=U);const n=q.get(t),s=d.state.lights,r=d.state.shadowsArray,a=s.state.version,o=tt.getParameters(t,s.state,r,e,i),l=tt.getProgramCacheKey(o);let h=n.programs;n.environment=t.isMeshStandardMaterial?e.environment:null,n.fog=e.fog,n.envMap=(t.isMeshStandardMaterial?$:Y).get(t.envMap||n.environment),void 0===h&&(t.addEventListener("dispose",wt),h=new Map,n.programs=h);let c=h.get(l);if(void 0!==c){if(n.currentProgram===c&&n.lightsStateVersion===a)return It(t,o),c}else o.uniforms=tt.getUniforms(t),t.onBuild(i,o,m),t.onBeforeCompile(o,m),c=tt.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),It(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=_o.seqWithValue(p.seq,u);return n.currentProgram=c,n.uniformsList=f,c}function It(t,e){const i=q.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,i.toneMapping=e.toneMapping}Tt.setAnimationLoop((function(t){bt&&bt(t)})),"undefined"!=typeof window&&Tt.setContext(window),this.setAnimationLoop=function(t){bt=t,yt.setAnimationLoop(t),null===t?Tt.stop():Tt.start()},yt.addEventListener("sessionstart",St),yt.addEventListener("sessionend",Mt),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===yt.enabled&&!0===yt.isPresenting&&(!0===yt.cameraAutoUpdate&&yt.updateCamera(e),e=yt.getCamera()),!0===t.isScene&&t.onBeforeRender(m,t,e,v),d=at.get(t,f.length),d.init(),f.push(d),k.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),D.setFromProjectionMatrix(k),F=this.localClippingEnabled,O=ot.init(this.clippingPlanes,F,e),u=rt.get(t,p.length),u.init(),p.push(u),At(t,e,0,m.sortObjects),u.finish(),!0===m.sortObjects&&u.sort(E,z),!0===O&&ot.beginShadows();const i=d.state.shadowsArray;if(lt.render(i,t,e),!0===O&&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];Ct(u,t,n,n.viewport)}}else Ct(u,t,e);null!==v&&(J.updateMultisampleRenderTarget(v),J.updateRenderTargetMipmap(v)),!0===t.isScene&&t.onAfterRender(m,t,e),H.buffers.depth.setTest(!0),H.buffers.depth.setMask(!0),H.buffers.color.setMask(!0),H.setPolygonOffset(!1),ft.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){q.get(t.texture).__webglTexture=e,q.get(t.depthTexture).__webglTexture=i;const n=q.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=q.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=q.get(t);void 0!==e.__useDefaultFramebuffer?(H.bindFramebuffer(36160,null),n=!1):void 0===e.__webglFramebuffer?J.setupRenderTarget(t):e.__hasExternalTextures&&J.rebindTextures(t,q.get(t.texture).__webglTexture,q.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=q.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(s=n[e],r=!0):s=t.useRenderbuffer?q.get(t).__webglMultisampledFramebuffer:n,b.copy(t.viewport),S.copy(t.scissor),M=t.scissorTest}else b.copy(L).multiplyScalar(C).floor(),S.copy(I).multiplyScalar(C).floor(),M=N;if(H.bindFramebuffer(36160,s)&&G.drawBuffers&&n){let e=!1;if(t)if(t.isWebGLMultipleRenderTargets){const i=t.texture;if(P.length!==i.length||36064!==P[0]){for(let t=0,e=i.length;t<e;t++)P[t]=36064+t;P.length=i.length,e=!0}}else 1===P.length&&36064===P[0]||(P[0]=36064,P.length=1,e=!0);else 1===P.length&&1029===P[0]||(P[0]=1029,P.length=1,e=!0);e&&(G.isWebGL2?mt.drawBuffers(P):W.get("WEBGL_draw_buffers").drawBuffersWEBGL(P))}if(H.viewport(b),H.scissor(S),H.setScissorTest(M),r){const n=q.get(t.texture);mt.framebufferTexture2D(36160,36064,34069+e,n.__webglTexture,i)}else if(a){const n=q.get(t.texture),s=e||0;mt.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=q.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(o=o[a]),o){H.bindFramebuffer(36160,o);try{const a=t.texture,o=a.format,l=a.type;if(o!==ve&&pt.convert(o)!==mt.getParameter(35739))return;const h=l===de&&(W.has("EXT_color_buffer_half_float")||G.isWebGL2&&W.has("EXT_color_buffer_float"));if(!(l===re||pt.convert(l)===mt.getParameter(35738)||l===ue&&(G.isWebGL2||W.has("OES_texture_float")||W.has("WEBGL_color_buffer_float"))||h))return;36053===mt.checkFramebufferStatus(36160)&&e>=0&&e<=t.width-n&&i>=0&&i<=t.height-s&&mt.readPixels(e,i,n,s,pt.convert(o),pt.convert(l),r)}finally{const t=null!==v?q.get(v).__webglFramebuffer:null;H.bindFramebuffer(36160,t)}}},this.copyFramebufferToTexture=function(t,e,i=0){if(!0!==e.isFramebufferTexture)return;const n=Math.pow(2,-i),s=Math.floor(e.image.width*n),r=Math.floor(e.image.height*n);J.setTexture2D(e,0),mt.copyTexSubImage2D(3553,i,0,0,t.x,t.y,s,r),H.unbindTexture()},this.copyTextureToTexture=function(t,e,i,n=0){const s=e.image.width,r=e.image.height,a=pt.convert(i.format),o=pt.convert(i.type);J.setTexture2D(i,0),mt.pixelStorei(37440,i.flipY),mt.pixelStorei(37441,i.premultiplyAlpha),mt.pixelStorei(3317,i.unpackAlignment),e.isDataTexture?mt.texSubImage2D(3553,n,t.x,t.y,s,r,a,o,e.image.data):e.isCompressedTexture?mt.compressedTexSubImage2D(3553,n,t.x,t.y,e.mipmaps[0].width,e.mipmaps[0].height,a,e.mipmaps[0].data):mt.texSubImage2D(3553,n,t.x,t.y,a,o,e.image),0===n&&i.generateMipmaps&&mt.generateMipmap(3553),H.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=pt.convert(n.format),h=pt.convert(n.type);let c;if(n.isDataTexture3D)J.setTexture3D(n,0),c=32879;else{if(!n.isDataTexture2DArray)return;J.setTexture2DArray(n,0),c=35866}mt.pixelStorei(37440,n.flipY),mt.pixelStorei(37441,n.premultiplyAlpha),mt.pixelStorei(3317,n.unpackAlignment);const u=mt.getParameter(3314),d=mt.getParameter(32878),p=mt.getParameter(3316),f=mt.getParameter(3315),_=mt.getParameter(32877),g=i.isCompressedTexture?i.mipmaps[0]:i.image;mt.pixelStorei(3314,g.width),mt.pixelStorei(32878,g.height),mt.pixelStorei(3316,t.min.x),mt.pixelStorei(3315,t.min.y),mt.pixelStorei(32877,t.min.z),i.isDataTexture||i.isDataTexture3D?mt.texSubImage3D(c,s,e.x,e.y,e.z,r,a,o,l,h,g.data):i.isCompressedTexture?mt.compressedTexSubImage3D(c,s,e.x,e.y,e.z,r,a,o,l,g.data):mt.texSubImage3D(c,s,e.x,e.y,e.z,r,a,o,l,h,g),mt.pixelStorei(3314,u),mt.pixelStorei(32878,d),mt.pixelStorei(3316,p),mt.pixelStorei(3315,f),mt.pixelStorei(32877,_),0===s&&n.generateMipmaps&&mt.generateMipmap(c),H.unbindTexture()},this.initTexture=function(t){J.setTexture2D(t,0),H.unbindTexture()},this.resetState=function(){g=0,y=0,v=null,H.reset(),ft.reset()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}pl.prototype.isWebGLRenderer=!0,class extends pl{}.prototype.isWebGL1Renderer=!0;let fl=class extends is{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}};fl.prototype.isScene=!0;class ml{constructor(t,e){this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=Ei,this.updateRange={offset:0,count:-1},this.version=0,this.uuid=Oi()}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=Oi()),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=Oi()),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}}}ml.prototype.isInterleavedBuffer=!0;const _l=new Qi;class gl{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++)_l.x=this.getX(e),_l.y=this.getY(e),_l.z=this.getZ(e),_l.applyMatrix4(t),this.setXYZ(e,_l.x,_l.y,_l.z);return this}applyNormalMatrix(t){for(let e=0,i=this.count;e<i;e++)_l.x=this.getX(e),_l.y=this.getY(e),_l.z=this.getZ(e),_l.applyNormalMatrix(t),this.setXYZ(e,_l.x,_l.y,_l.z);return this}transformDirection(t){for(let e=0,i=this.count;e<i;e++)_l.x=this.getX(e),_l.y=this.getY(e),_l.z=this.getZ(e),_l.transformDirection(t),this.setXYZ(e,_l.x,_l.y,_l.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 As(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 gl(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}}}gl.prototype.isInterleavedBufferAttribute=!0;class yl extends ms{constructor(t){super(),this.type="SpriteMaterial",this.color=new bs(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 vl;yl.prototype.isSpriteMaterial=!0;const xl=new Qi,wl=new Qi,bl=new Qi,Sl=new Vi,Ml=new Vi,Tl=new In,Al=new Qi,Cl=new Qi,El=new Qi,zl=new Vi,Ll=new Vi,Il=new Vi;function Nl(t,e,i,n,s,r){Sl.subVectors(t,i).addScalar(.5).multiply(n),void 0!==s?(Ml.x=r*Sl.x-s*Sl.y,Ml.y=s*Sl.x+r*Sl.y):Ml.copy(Sl),t.copy(e),t.x+=Ml.x,t.y+=Ml.y,t.applyMatrix4(Tl)}(class extends is{constructor(t){if(super(),this.type="Sprite",void 0===vl){vl=new Rs;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 ml(t,5);vl.setIndex([0,1,2,0,2,3]),vl.setAttribute("position",new gl(e,3,0,!1)),vl.setAttribute("uv",new gl(e,2,3,!1))}this.geometry=vl,this.material=void 0!==t?t:new yl,this.center=new Vi(.5,.5)}raycast(t,e){t.camera,wl.setFromMatrixScale(this.matrixWorld),Tl.copy(t.camera.matrixWorld),this.modelViewMatrix.multiplyMatrices(t.camera.matrixWorldInverse,this.matrixWorld),bl.setFromMatrixPosition(this.modelViewMatrix),t.camera.isPerspectiveCamera&&!1===this.material.sizeAttenuation&&wl.multiplyScalar(-bl.z);const i=this.material.rotation;let n,s;0!==i&&(s=Math.cos(i),n=Math.sin(i));const r=this.center;Nl(Al.set(-.5,-.5,0),bl,r,wl,n,s),Nl(Cl.set(.5,-.5,0),bl,r,wl,n,s),Nl(El.set(.5,.5,0),bl,r,wl,n,s),zl.set(0,0),Ll.set(1,0),Il.set(1,1);let a=t.ray.intersectTriangle(Al,Cl,El,!1,xl);if(null===a&&(Nl(Cl.set(-.5,.5,0),bl,r,wl,n,s),Ll.set(0,1),a=t.ray.intersectTriangle(Al,El,Cl,!1,xl),null===a))return;const o=t.ray.origin.distanceTo(xl);o<t.near||o>t.far||e.push({distance:o,point:xl.clone(),uv:ps.getUV(xl,Al,Cl,El,zl,Ll,Il,new Vi),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 Pl=new Qi,Dl=new Xi,Ol=new Xi,Fl=new Qi,Rl=new In;class kl extends er{constructor(t,e){super(t,e),this.type="SkinnedMesh",this.bindMode="attached",this.bindMatrix=new In,this.bindMatrixInverse=new In}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 Xi,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;Dl.fromBufferAttribute(n.attributes.skinIndex,t),Ol.fromBufferAttribute(n.attributes.skinWeight,t),Pl.copy(e).applyMatrix4(this.bindMatrix),e.set(0,0,0);for(let t=0;t<4;t++){const n=Ol.getComponent(t);if(0!==n){const s=Dl.getComponent(t);Rl.multiplyMatrices(i.bones[s].matrixWorld,i.boneInverses[s]),e.addScaledVector(Fl.copy(Pl).applyMatrix4(Rl),n)}}return e.applyMatrix4(this.bindMatrixInverse)}}kl.prototype.isSkinnedMesh=!0,class extends is{constructor(){super(),this.type="Bone"}}.prototype.isBone=!0;class Bl extends Ji{constructor(t=null,e=1,i=1,n,s,r,a,o,l=Qt,h=Qt,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}}Bl.prototype.isDataTexture=!0;class Ul extends As{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}}Ul.prototype.isInstancedBufferAttribute=!0;const Vl=new In,Wl=new In,Gl=[],Hl=new er;(class extends er{constructor(t,e,i){super(t,e),this.instanceMatrix=new Ul(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(Hl.geometry=this.geometry,Hl.material=this.material,void 0!==Hl.material)for(let s=0;s<n;s++){this.getMatrixAt(s,Vl),Wl.multiplyMatrices(i,Vl),Hl.matrixWorld=Wl,Hl.raycast(t,Gl);for(let t=0,i=Gl.length;t<i;t++){const i=Gl[t];i.instanceId=s,i.object=this,e.push(i)}Gl.length=0}}setColorAt(t,e){null===this.instanceColor&&(this.instanceColor=new Ul(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 jl extends ms{constructor(t){super(),this.type="LineBasicMaterial",this.color=new bs(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}}jl.prototype.isLineBasicMaterial=!0;const ql=new Qi,Jl=new Qi,Yl=new In,Xl=new Ln,$l=new bn;let Zl=class extends is{constructor(t=new Rs,e=new jl){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++)ql.fromBufferAttribute(e,t-1),Jl.fromBufferAttribute(e,t),i[t]=i[t-1],i[t]+=ql.distanceTo(Jl);t.setAttribute("lineDistance",new zs(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(),$l.copy(i.boundingSphere),$l.applyMatrix4(n),$l.radius+=s,!1===t.ray.intersectsSphere($l))return;Yl.copy(n).invert(),Xl.copy(t.ray).applyMatrix4(Yl);const a=s/((this.scale.x+this.scale.y+this.scale.z)/3),o=a*a,l=new Qi,h=new Qi,c=new Qi,u=new Qi,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),Xl.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),Xl.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}}};Zl.prototype.isLine=!0;const Kl=new Qi,Ql=new Qi;class th extends Zl{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)Kl.fromBufferAttribute(e,t),Ql.fromBufferAttribute(e,t+1),i[t]=0===t?0:i[t-1],i[t+1]=i[t]+Kl.distanceTo(Ql);t.setAttribute("lineDistance",new zs(i,1))}}else t.isGeometry;return this}}th.prototype.isLineSegments=!0,class extends Zl{constructor(t,e){super(t,e),this.type="LineLoop"}}.prototype.isLineLoop=!0;class eh extends ms{constructor(t){super(),this.type="PointsMaterial",this.color=new bs(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}}eh.prototype.isPointsMaterial=!0;const ih=new In,nh=new Ln,sh=new bn,rh=new Qi;class ah extends is{constructor(t=new Rs,e=new eh){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(),sh.copy(i.boundingSphere),sh.applyMatrix4(n),sh.radius+=s,!1===t.ray.intersectsSphere(sh))return;ih.copy(n).invert(),nh.copy(t.ray).applyMatrix4(ih);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);rh.fromBufferAttribute(a,r),oh(rh,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++)rh.fromBufferAttribute(a,i),oh(rh,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 oh(t,e,i,n,s,r,a){const o=nh.distanceSqToPoint(t);if(o<i){const i=new Qi;nh.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})}}ah.prototype.isPoints=!0,class extends Ji{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:ye,this.minFilter=void 0!==r?r:ie,this.magFilter=void 0!==s?s:ie,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 Ji{constructor(t,e,i){super({width:t,height:e}),this.format=i,this.magFilter=Qt,this.minFilter=Qt,this.generateMipmaps=!1,this.needsUpdate=!0}}.prototype.isFramebufferTexture=!0,class extends Ji{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 Ji{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 lh{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 Vi:new Qi);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 Qi,n=[],s=[],r=[],a=new Qi,o=new In;for(let e=0;e<=t;e++){const i=e/t;n[e]=this.getTangentAt(i,new Qi)}s[0]=new Qi,r[0]=new Qi;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(Fi(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(Fi(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 hh extends lh{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 Vi,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}}hh.prototype.isEllipseCurve=!0;class ch extends hh{constructor(t,e,i,n,s,r){super(t,e,i,i,n,s,r),this.type="ArcCurve"}}function uh(){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)}}}ch.prototype.isArcCurve=!0;const dh=new Qi,ph=new uh,fh=new uh,mh=new uh;class _h extends lh{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 Qi){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]:(dh.subVectors(n[0],n[1]).add(n[0]),a=dh);const c=n[l%s],u=n[(l+1)%s];if(this.closed||l+2<s?o=n[(l+2)%s]:(dh.subVectors(n[s-1],n[s-2]).add(n[s-1]),o=dh),"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),ph.initNonuniformCatmullRom(a.x,c.x,u.x,o.x,e,i,n),fh.initNonuniformCatmullRom(a.y,c.y,u.y,o.y,e,i,n),mh.initNonuniformCatmullRom(a.z,c.z,u.z,o.z,e,i,n)}else"catmullrom"===this.curveType&&(ph.initCatmullRom(a.x,c.x,u.x,o.x,this.tension),fh.initCatmullRom(a.y,c.y,u.y,o.y,this.tension),mh.initCatmullRom(a.z,c.z,u.z,o.z,this.tension));return i.set(ph.calc(h),fh.calc(h),mh.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 Qi).fromArray(i))}return this.closed=t.closed,this.curveType=t.curveType,this.tension=t.tension,this}}function gh(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 yh(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 vh(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)}_h.prototype.isCatmullRomCurve3=!0;class xh extends lh{constructor(t=new Vi,e=new Vi,i=new Vi,n=new Vi){super(),this.type="CubicBezierCurve",this.v0=t,this.v1=e,this.v2=i,this.v3=n}getPoint(t,e=new Vi){const i=e,n=this.v0,s=this.v1,r=this.v2,a=this.v3;return i.set(vh(t,n.x,s.x,r.x,a.x),vh(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}}xh.prototype.isCubicBezierCurve=!0;class wh extends lh{constructor(t=new Qi,e=new Qi,i=new Qi,n=new Qi){super(),this.type="CubicBezierCurve3",this.v0=t,this.v1=e,this.v2=i,this.v3=n}getPoint(t,e=new Qi){const i=e,n=this.v0,s=this.v1,r=this.v2,a=this.v3;return i.set(vh(t,n.x,s.x,r.x,a.x),vh(t,n.y,s.y,r.y,a.y),vh(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}}wh.prototype.isCubicBezierCurve3=!0;class bh extends lh{constructor(t=new Vi,e=new Vi){super(),this.type="LineCurve",this.v1=t,this.v2=e}getPoint(t,e=new Vi){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 Vi;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}}bh.prototype.isLineCurve=!0;class Sh extends lh{constructor(t=new Vi,e=new Vi,i=new Vi){super(),this.type="QuadraticBezierCurve",this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new Vi){const i=e,n=this.v0,s=this.v1,r=this.v2;return i.set(yh(t,n.x,s.x,r.x),yh(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}}Sh.prototype.isQuadraticBezierCurve=!0;class Mh extends lh{constructor(t=new Qi,e=new Qi,i=new Qi){super(),this.type="QuadraticBezierCurve3",this.v0=t,this.v1=e,this.v2=i}getPoint(t,e=new Qi){const i=e,n=this.v0,s=this.v1,r=this.v2;return i.set(yh(t,n.x,s.x,r.x),yh(t,n.y,s.y,r.y),yh(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}}Mh.prototype.isQuadraticBezierCurve3=!0;class Th extends lh{constructor(t=[]){super(),this.type="SplineCurve",this.points=t}getPoint(t,e=new Vi){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(gh(a,o.x,l.x,h.x,c.x),gh(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 Vi).fromArray(i))}return this}}Th.prototype.isSplineCurve=!0;var Ah=Object.freeze({__proto__:null,ArcCurve:ch,CatmullRomCurve3:_h,CubicBezierCurve:xh,CubicBezierCurve3:wh,EllipseCurve:hh,LineCurve:bh,LineCurve3:class extends lh{constructor(t=new Qi,e=new Qi){super(),this.type="LineCurve3",this.isLineCurve3=!0,this.v1=t,this.v2=e}getPoint(t,e=new Qi){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:Sh,QuadraticBezierCurve3:Mh,SplineCurve:Th});class Ch extends lh{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 bh(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 Ah[i.type]).fromJSON(i))}return this}}class Eh extends Ch{constructor(t){super(),this.type="Path",this.currentPoint=new Vi,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 bh(this.currentPoint.clone(),new Vi(t,e));return this.curves.push(i),this.currentPoint.set(t,e),this}quadraticCurveTo(t,e,i,n){const s=new Sh(this.currentPoint.clone(),new Vi(t,e),new Vi(i,n));return this.curves.push(s),this.currentPoint.set(i,n),this}bezierCurveTo(t,e,i,n,s,r){const a=new xh(this.currentPoint.clone(),new Vi(t,e),new Vi(i,n),new Vi(s,r));return this.curves.push(a),this.currentPoint.set(s,r),this}splineThru(t){const e=[this.currentPoint.clone()].concat(t),i=new Th(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 hh(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 zh extends Eh{constructor(t){super(t),this.uuid=Oi(),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 Eh).fromJSON(i))}return this}}function Lh(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=Zh(r,t[r],t[r+1],a);else for(r=i-n;r>=e;r-=n)a=Zh(r,t[r],t[r+1],a);return a&&jh(a,a.next)&&(Kh(a),a=a.next),a}function Ih(t,e){if(!t)return t;e||(e=t);let i,n=t;do{if(i=!1,n.steiner||!jh(n,n.next)&&0!==Hh(n.prev,n,n.next))n=n.next;else{if(Kh(n),n=e=n.prev,n===n.next)break;i=!0}}while(i||n!==e);return e}function Nh(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=Uh(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?Dh(t,n,s,r):Ph(t))e.push(o.i/i),e.push(t.i/i),e.push(l.i/i),Kh(t),t=l.next,h=l.next;else if((t=l)===h){a?1===a?Nh(t=Oh(Ih(t),e,i),e,i,n,s,r,2):2===a&&Fh(t,e,i,n,s,r):Nh(Ih(t),e,i,n,s,r,1);break}}function Ph(t){const e=t.prev,i=t,n=t.next;if(Hh(e,i,n)>=0)return!1;let s=t.next.next;for(;s!==t.prev;){if(Wh(e.x,e.y,i.x,i.y,n.x,n.y,s.x,s.y)&&Hh(s.prev,s,s.next)>=0)return!1;s=s.next}return!0}function Dh(t,e,i,n){const s=t.prev,r=t,a=t.next;if(Hh(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=Uh(o,l,e,i,n),d=Uh(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&&Wh(s.x,s.y,r.x,r.y,a.x,a.y,p.x,p.y)&&Hh(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,f!==t.prev&&f!==t.next&&Wh(s.x,s.y,r.x,r.y,a.x,a.y,f.x,f.y)&&Hh(f.prev,f,f.next)>=0)return!1;f=f.nextZ}for(;p&&p.z>=u;){if(p!==t.prev&&p!==t.next&&Wh(s.x,s.y,r.x,r.y,a.x,a.y,p.x,p.y)&&Hh(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;f&&f.z<=d;){if(f!==t.prev&&f!==t.next&&Wh(s.x,s.y,r.x,r.y,a.x,a.y,f.x,f.y)&&Hh(f.prev,f,f.next)>=0)return!1;f=f.nextZ}return!0}function Oh(t,e,i){let n=t;do{const s=n.prev,r=n.next.next;!jh(s,r)&&qh(s,n,n.next,r)&&Xh(s,r)&&Xh(r,s)&&(e.push(s.i/i),e.push(n.i/i),e.push(r.i/i),Kh(n),Kh(n.next),n=t=r),n=n.next}while(n!==t);return Ih(n)}function Fh(t,e,i,n,s,r){let a=t;do{let t=a.next.next;for(;t!==a.prev;){if(a.i!==t.i&&Gh(a,t)){let o=$h(a,t);return a=Ih(a,a.next),o=Ih(o,o.next),Nh(a,e,i,n,s,r),void Nh(o,e,i,n,s,r)}t=t.next}a=a.next}while(a!==t)}function Rh(t,e){return t.x-e.x}function kh(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&&Wh(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),Xh(i,t)&&(c<u||c===u&&(i.x>r.x||i.x===r.x&&Bh(r,i)))&&(r=i,u=c)),i=i.next}while(i!==o);return r}(t,e),e){const i=$h(e,t);Ih(e,e.next),Ih(i,i.next)}}function Bh(t,e){return Hh(t.prev,t,e.prev)<0&&Hh(e.next,t,t.next)<0}function Uh(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 Vh(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 Wh(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 Gh(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&&qh(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}(t,e)&&(Xh(t,e)&&Xh(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)&&(Hh(t.prev,t,e.prev)||Hh(t,e.prev,e))||jh(t,e)&&Hh(t.prev,t,t.next)>0&&Hh(e.prev,e,e.next)>0)}function Hh(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function jh(t,e){return t.x===e.x&&t.y===e.y}function qh(t,e,i,n){const s=Yh(Hh(t,e,i)),r=Yh(Hh(t,e,n)),a=Yh(Hh(i,n,t)),o=Yh(Hh(i,n,e));return s!==r&&a!==o||!(0!==s||!Jh(t,i,e))||!(0!==r||!Jh(t,n,e))||!(0!==a||!Jh(i,t,n))||!(0!==o||!Jh(i,e,n))}function Jh(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 Yh(t){return t>0?1:t<0?-1:0}function Xh(t,e){return Hh(t.prev,t,t.next)<0?Hh(t,e,t.next)>=0&&Hh(t,t.prev,e)>=0:Hh(t,e,t.prev)<0||Hh(t,t.next,e)<0}function $h(t,e){const i=new Qh(t.i,t.x,t.y),n=new Qh(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 Zh(t,e,i,n){const s=new Qh(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 Kh(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 Qh(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 tc{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 tc.area(t)<0}static triangulateShape(t,e){const i=[],n=[],s=[];ec(t),ic(i,t);let r=t.length;e.forEach(ec);for(let t=0;t<e.length;t++)n.push(r),r+=e[t].length,ic(i,e[t]);const a=function(t,e,i=2){const n=e&&e.length,s=n?e[0]*i:t.length;let r=Lh(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=Lh(t,o,l,n,!1),h===h.next&&(h.steiner=!0),s.push(Vh(h));for(s.sort(Rh),r=0;r<s.length;r++)kh(s[r],i),i=Ih(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 Nh(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 ec(t){const e=t.length;e>2&&t[e-1].equals(t[0])&&t.pop()}function ic(t,e){for(let i=0;i<e.length;i++)t.push(e[i].x),t.push(e[i].y)}class nc extends Rs{constructor(t=new zh([new Vi(.5,.5),new Vi(-.5,.5),new Vi(-.5,-.5),new Vi(.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:sc;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 Qi,v=new Qi,x=new Qi),h||(p=0,c=0,u=0,d=0);const b=t.extractPoints(a);let S=b.shape;const M=b.holes;if(!tc.isClockWise(S)){S=S.reverse();for(let t=0,e=M.length;t<e;t++){const e=M[t];tc.isClockWise(e)&&(M[t]=e.reverse())}}const T=tc.triangulateShape(S,M),A=S;for(let t=0,e=M.length;t<e;t++){const e=M[t];S=S.concat(e)}function C(t,e,i){return e.clone().multiplyScalar(i).add(t)}const E=S.length,z=T.length;function L(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 Vi(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 Vi(n/r,s/r)}const I=[];for(let t=0,e=A.length,i=e-1,n=t+1;t<e;t++,i++,n++)i===e&&(i=0),n===e&&(n=0),I[t]=L(A[t],A[i],A[n]);const N=[];let P,D=I.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]=L(e[t],e[n],e[s]);N.push(P),D=D.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=A.length;t<e;t++){const e=C(A[t],I[t],n);R(e.x,e.y,-i)}for(let t=0,e=M.length;t<e;t++){const e=M[t];P=N[t];for(let t=0,s=e.length;t<s;t++){const s=C(e[t],P[t],n);R(s.x,s.y,-i)}}}const O=u+d;for(let t=0;t<E;t++){const e=h?C(S[t],D[t],O):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?C(S[e],D[e],O):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=A.length;t<e;t++){const e=C(A[t],I[t],n);R(e.x,e.y,l+i)}for(let t=0,e=M.length;t<e;t++){const e=M[t];P=N[t];for(let t=0,s=e.length;t<s;t++){const s=C(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 F(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);B(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){U(t),U(e),U(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 B(t,e,s,r){U(t),U(e),U(r),U(e),U(s),U(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 U(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;F(A,e),e+=A.length;for(let t=0,i=M.length;t<i;t++){const i=M[t];F(i,e),e+=i.length}i.addGroup(t,n.length/3-t,1)}()}this.setAttribute("position",new zs(n,3)),this.setAttribute("uv",new zs(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 Ah[n.type]).fromJSON(n)),new nc(i,t.options)}}const sc={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 Vi(r,a),new Vi(o,l),new Vi(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 Vi(a,1-l),new Vi(h,1-u),new Vi(d,1-f),new Vi(m,1-g)]:[new Vi(o,1-l),new Vi(c,1-u),new Vi(p,1-f),new Vi(_,1-g)]}};class rc extends Rs{constructor(t=new zh([new Vi(0,.5),new Vi(-.5,-.5),new Vi(.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===tc.isClockWise(h)&&(h=h.reverse());for(let t=0,e=c.length;t<e;t++){const e=c[t];!0===tc.isClockWise(e)&&(c[t]=e.reverse())}const u=tc.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 zs(n,3)),this.setAttribute("normal",new zs(s,3)),this.setAttribute("uv",new zs(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 rc(i,t.curveSegments)}}(class extends ms{constructor(t){super(),this.type="ShadowMaterial",this.color=new bs(0),this.transparent=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this}}).prototype.isShadowMaterial=!0;class ac extends ms{constructor(t){super(),this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new bs(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 bs(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ti,this.normalScale=new Vi(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}}ac.prototype.isMeshStandardMaterial=!0,class extends ac{constructor(t){super(),this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new Vi(1,1),this.clearcoatNormalMap=null,this.ior=1.5,Object.defineProperty(this,"reflectivity",{get:function(){return Fi(2.5*(this.ior-1)/(this.ior+1),0,1)},set:function(t){this.ior=(1+.4*t)/(1-.4*t)}}),this.sheenColor=new bs(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 bs(1,1,1),this.specularIntensity=1,this.specularIntensityMap=null,this.specularColor=new bs(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 oc extends ms{constructor(t){super(),this.type="MeshPhongMaterial",this.color=new bs(16777215),this.specular=new bs(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new bs(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ti,this.normalScale=new Vi(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=Ot,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}}oc.prototype.isMeshPhongMaterial=!0,class extends ms{constructor(t){super(),this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new bs(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new bs(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ti,this.normalScale=new Vi(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 lc extends ms{constructor(t){super(),this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ti,this.normalScale=new Vi(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}}lc.prototype.isMeshNormalMaterial=!0,class extends ms{constructor(t){super(),this.type="MeshLambertMaterial",this.color=new bs(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new bs(0),this.emissiveIntensity=1,this.emissiveMap=null,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=Ot,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 ms{constructor(t){super(),this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new bs(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=Ti,this.normalScale=new Vi(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 jl{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 hc={arraySlice:function(t,e,i){return hc.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=hc.convertArray(l,e.times.constructor),e.values=hc.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=hc.arraySlice(n.values,t,e)}else if(r>=n.times[u]){const t=u*l+o,e=t+l-o;d=hc.arraySlice(n.values,t,e)}else{const t=n.createInterpolant(),e=o,i=l-o;t.evaluate(r),d=hc.arraySlice(t.resultBuffer,e,i)}"quaternion"===s&&(new Ki).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)Ki.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 cc{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_(){}}cc.prototype.beforeStart_=cc.prototype.copySampleValue_,cc.prototype.afterEnd_=cc.prototype.copySampleValue_;class uc extends cc{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:vi,endingEnd:vi}}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 xi:s=t,a=2*e-i;break;case wi: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 xi:r=t,o=2*i-e;break;case wi: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 dc extends cc{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 pc extends cc{constructor(t,e,i,n){super(t,e,i,n)}interpolate_(t){return this.copySampleValue_(t-1)}}class fc{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=hc.convertArray(e,this.TimeBufferType),this.values=hc.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:hc.convertArray(t.times,Array),values:hc.convertArray(t.values,Array)};const e=t.getInterpolation();e!==t.DefaultInterpolation&&(i.interpolation=e)}return i.type=t.ValueTypeName,i}InterpolantFactoryMethodDiscrete(t){return new pc(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodLinear(t){return new dc(this.times,this.values,this.getValueSize(),t)}InterpolantFactoryMethodSmooth(t){return new uc(this.times,this.values,this.getValueSize(),t)}setInterpolation(t){let e;switch(t){case _i:e=this.InterpolantFactoryMethodDiscrete;break;case gi:e=this.InterpolantFactoryMethodLinear;break;case yi: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 _i;case this.InterpolantFactoryMethodLinear:return gi;case this.InterpolantFactoryMethodSmooth:return yi}}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=hc.arraySlice(i,s,r),this.values=hc.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&&hc.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=hc.arraySlice(this.times),e=hc.arraySlice(this.values),i=this.getValueSize(),n=this.getInterpolation()===yi,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=hc.arraySlice(t,0,r),this.values=hc.arraySlice(e,0,r*i)):(this.times=t,this.values=e),this}clone(){const t=hc.arraySlice(this.times,0),e=hc.arraySlice(this.values,0),i=new(0,this.constructor)(this.name,t,e);return i.createInterpolant=this.createInterpolant,i}}fc.prototype.TimeBufferType=Float32Array,fc.prototype.ValueBufferType=Float32Array,fc.prototype.DefaultInterpolation=gi;class mc extends fc{}mc.prototype.ValueTypeName="bool",mc.prototype.ValueBufferType=Array,mc.prototype.DefaultInterpolation=_i,mc.prototype.InterpolantFactoryMethodLinear=void 0,mc.prototype.InterpolantFactoryMethodSmooth=void 0;class _c extends fc{}_c.prototype.ValueTypeName="color";class gc extends fc{}gc.prototype.ValueTypeName="number";class yc extends cc{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)Ki.slerpFlat(s,0,r,l-a,r,l,o);return s}}class vc extends fc{InterpolantFactoryMethodLinear(t){return new yc(this.times,this.values,this.getValueSize(),t)}}vc.prototype.ValueTypeName="quaternion",vc.prototype.DefaultInterpolation=gi,vc.prototype.InterpolantFactoryMethodSmooth=void 0;class xc extends fc{}xc.prototype.ValueTypeName="string",xc.prototype.ValueBufferType=Array,xc.prototype.DefaultInterpolation=_i,xc.prototype.InterpolantFactoryMethodLinear=void 0,xc.prototype.InterpolantFactoryMethodSmooth=void 0;class wc extends fc{}wc.prototype.ValueTypeName="vector";class bc{constructor(t,e=-1,i,n=2500){this.name=t,this.tracks=i,this.duration=e,this.blendMode=n,this.uuid=Oi(),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(Sc(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(fc.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=hc.getKeyframeOrder(a);a=hc.sortedArray(a,1,l),o=hc.sortedArray(o,1,l),n||0!==a[0]||(a.push(s),o.push(o[0])),r.push(new gc(".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=[];hc.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 gc(".morphTargetInfluence["+i+"]",t,r))}o=t.length*(r||1)}else{const r=".bones["+e[t].name+"]";i(wc,r+".position",s,"pos",n),i(vc,r+".quaternion",s,"rot",n),i(wc,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 Sc(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 gc;case"vector":case"vector2":case"vector3":case"vector4":return wc;case"color":return _c;case"quaternion":return vc;case"bool":case"boolean":return mc;case"string":return xc}throw new Error("THREE.KeyframeTrack: Unsupported typeName: "+t)}(t.type);if(void 0===t.times){const e=[],i=[];hc.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 Mc={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={}}},Tc=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 Ac{constructor(t){this.manager=void 0!==t?t:Tc,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 Cc={};class Ec extends Ac{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=Mc.get(t);if(void 0!==s)return this.manager.itemStart(t),setTimeout((()=>{e&&e(s),this.manager.itemEnd(t)}),0),s;if(void 0!==Cc[t])return void Cc[t].push({onLoad:e,onProgress:i,onError:n});Cc[t]=[],Cc[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){if(e.status,"undefined"==typeof ReadableStream||void 0===e.body.getReader)return e;const i=Cc[t],n=e.body.getReader(),s=e.headers.get("Content-Length"),r=s?parseInt(s):0,a=0!==r;let o=0;const l=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()}}))}()}});return new Response(l)}throw Error(`fetch for "${e.url}" responded with ${e.status}: ${e.statusText}`)})).then((t=>{switch(this.responseType){case"arraybuffer":return t.arrayBuffer();case"blob":return t.blob();case"document":return t.text().then((t=>(new DOMParser).parseFromString(t,this.mimeType)));case"json":return t.json();default:return t.text()}})).then((e=>{Mc.add(t,e);const i=Cc[t];delete Cc[t];for(let t=0,n=i.length;t<n;t++){const n=i[t];n.onLoad&&n.onLoad(e)}})).catch((e=>{const i=Cc[t];if(void 0===i)throw this.manager.itemError(t),e;delete Cc[t];for(let t=0,n=i.length;t<n;t++){const n=i[t];n.onError&&n.onError(e)}this.manager.itemError(t)})).finally((()=>{this.manager.itemEnd(t)})),this.manager.itemStart(t)}setResponseType(t){return this.responseType=t,this}setMimeType(t){return this.mimeType=t,this}}class zc extends Ac{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=Mc.get(t);if(void 0!==r)return s.manager.itemStart(t),setTimeout((function(){e&&e(r),s.manager.itemEnd(t)}),0),r;const a=Hi("img");function o(){h(),Mc.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 Lc extends Ac{constructor(t){super(t)}load(t,e,i,n){const s=new dr,r=new zc(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 Ic extends Ac{constructor(t){super(t)}load(t,e,i,n){const s=new Ji,r=new zc(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 Nc=class extends is{constructor(t,e=1){super(),this.type="Light",this.color=new bs(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}};Nc.prototype.isLight=!0,class extends Nc{constructor(t,e,i){super(t,i),this.type="HemisphereLight",this.position.copy(is.DefaultUp),this.updateMatrix(),this.groundColor=new bs(e)}copy(t){return Nc.prototype.copy.call(this,t),this.groundColor.copy(t.groundColor),this}}.prototype.isHemisphereLight=!0;const Pc=new In,Dc=new Qi,Oc=new Qi;class Fc{constructor(t){this.camera=t,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new Vi(512,512),this.map=null,this.mapPass=null,this.matrix=new In,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new xr,this._frameExtents=new Vi(1,1),this._viewportCount=1,this._viewports=[new Xi(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,i=this.matrix;Dc.setFromMatrixPosition(t.matrixWorld),e.position.copy(Dc),Oc.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(Oc),e.updateMatrixWorld(),Pc.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Pc),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 Rc extends Fc{constructor(){super(new hr(50,1,.5,500)),this.focus=1}updateMatrices(t){const e=this.camera,i=2*Di*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}}Rc.prototype.isSpotLightShadow=!0;class kc extends Nc{constructor(t,e,i=0,n=Math.PI/3,s=0,r=1){super(t,e),this.type="SpotLight",this.position.copy(is.DefaultUp),this.updateMatrix(),this.target=new is,this.distance=i,this.angle=n,this.penumbra=s,this.decay=r,this.shadow=new Rc}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}}kc.prototype.isSpotLight=!0;const Bc=new In,Uc=new Qi,Vc=new Qi;class Wc extends Fc{constructor(){super(new hr(90,1,.5,500)),this._frameExtents=new Vi(4,2),this._viewportCount=6,this._viewports=[new Xi(2,1,1,1),new Xi(0,1,1,1),new Xi(3,1,1,1),new Xi(1,1,1,1),new Xi(3,0,1,1),new Xi(1,0,1,1)],this._cubeDirections=[new Qi(1,0,0),new Qi(-1,0,0),new Qi(0,0,1),new Qi(0,0,-1),new Qi(0,1,0),new Qi(0,-1,0)],this._cubeUps=[new Qi(0,1,0),new Qi(0,1,0),new Qi(0,1,0),new Qi(0,1,0),new Qi(0,0,1),new Qi(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()),Uc.setFromMatrixPosition(t.matrixWorld),i.position.copy(Uc),Vc.copy(i.position),Vc.add(this._cubeDirections[e]),i.up.copy(this._cubeUps[e]),i.lookAt(Vc),i.updateMatrixWorld(),n.makeTranslation(-Uc.x,-Uc.y,-Uc.z),Bc.multiplyMatrices(i.projectionMatrix,i.matrixWorldInverse),this._frustum.setFromProjectionMatrix(Bc)}}Wc.prototype.isPointLightShadow=!0;let Gc,Hc=class extends Nc{constructor(t,e,i=0,n=1){super(t,e),this.type="PointLight",this.distance=i,this.decay=n,this.shadow=new Wc}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}};Hc.prototype.isPointLight=!0;class jc extends Fc{constructor(){super(new Pr(-5,5,5,-5,.5,500))}}jc.prototype.isDirectionalLightShadow=!0;class qc extends Nc{constructor(t,e){super(t,e),this.type="DirectionalLight",this.position.copy(is.DefaultUp),this.updateMatrix(),this.target=new is,this.shadow=new jc}dispose(){this.shadow.dispose()}copy(t){return super.copy(t),this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}qc.prototype.isDirectionalLight=!0;class Jc extends Nc{constructor(t,e){super(t,e),this.type="AmbientLight"}}Jc.prototype.isAmbientLight=!0,class extends Nc{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 Yc{constructor(){this.coefficients=[];for(let t=0;t<9;t++)this.coefficients.push(new Qi)}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)}}Yc.prototype.isSphericalHarmonics3=!0;class Xc extends Nc{constructor(t=new Yc,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}}Xc.prototype.isLightProbe=!0;class $c{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 Zc extends Rs{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}}Zc.prototype.isInstancedBufferGeometry=!0,class extends Ac{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=Mc.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){Mc.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 Kc extends Ac{constructor(t){super(t)}load(t,e,i,n){const s=this,r=new Ec(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===Gc&&(Gc=new(window.AudioContext||window.webkitAudioContext)),Gc).decodeAudioData(t,(function(t){e(t)}))}catch(e){n&&n(e),s.manager.itemError(t)}}),i,n)}}(class extends Xc{constructor(t,e,i=1){super(void 0,i);const n=(new bs).set(t),s=(new bs).set(e),r=new Qi(n.r,n.g,n.b),a=new Qi(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 Xc{constructor(t,e=1){super(void 0,e);const i=(new bs).set(t);this.sh.coefficients[0].set(i.r,i.g,i.b).multiplyScalar(2*Math.sqrt(Math.PI))}}.prototype.isAmbientLightProbe=!0;class Qc{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){Ki.slerpFlat(t,e,t,e,t,i,n)}_slerpAdditive(t,e,i,n,s){const r=this._workIndex*s;Ki.multiplyQuaternionsFlat(t,r,t,e,t,i),Ki.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 tu="\\[\\]\\.:\\/",eu=new RegExp("["+tu+"]","g"),iu="[^"+tu+"]",nu="[^"+tu.replace("\\.","")+"]",su=/((?:WC+[\/:])*)/.source.replace("WC",iu),ru=/(WCOD+)?/.source.replace("WCOD",nu),au=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",iu),ou=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",iu),lu=new RegExp("^"+su+ru+au+ou+"$"),hu=["material","materials","bones"];class cu{constructor(t,e,i){this.path=e,this.parsedPath=i||cu.parseTrackName(e),this.node=cu.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 cu.Composite(t,e,i):new cu(t,e,i)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(eu,"")}static parseTrackName(t){const e=lu.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!==hu.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=cu.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}}cu.Composite=class{constructor(t,e,i){const n=i||cu.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()}},cu.prototype.BindingType={Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},cu.prototype.Versioning={None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},cu.prototype.GetterByBindingType=[cu.prototype._getValue_direct,cu.prototype._getValue_array,cu.prototype._getValue_arrayElement,cu.prototype._getValue_toArray],cu.prototype.SetterByBindingTypeAndVersioning=[[cu.prototype._setValue_direct,cu.prototype._setValue_direct_setNeedsUpdate,cu.prototype._setValue_direct_setMatrixWorldNeedsUpdate],[cu.prototype._setValue_array,cu.prototype._setValue_array_setNeedsUpdate,cu.prototype._setValue_array_setMatrixWorldNeedsUpdate],[cu.prototype._setValue_arrayElement,cu.prototype._setValue_arrayElement_setNeedsUpdate,cu.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate],[cu.prototype._setValue_fromArray,cu.prototype._setValue_fromArray_setNeedsUpdate,cu.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate]];class uu{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:vi,endingEnd:vi};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=xi,n.endingEnd=xi):(n.endingStart=t?this.zeroSlopeAtStart?xi:vi:wi,n.endingEnd=e?this.zeroSlopeAtEnd?xi:vi:wi)}_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 Ii{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 Qc(cu.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 dc(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?bc.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 uu(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?bc.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 ml{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 du{constructor(t,e,i=0,n=Infinity){this.ray=new Ln(t,e),this.near=i,this.far=n,this.camera=null,this.layers=new Wn,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 fu(t,this,i,e),i.sort(pu),i}intersectObjects(t,e=!0,i=[]){for(let n=0,s=t.length;n<s;n++)fu(t[n],this,i,e);return i.sort(pu),i}}function pu(t,e){return t.distance-e.distance}function fu(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++)fu(n[t],e,i,!0)}}const mu=new Qi,_u=new In,gu=new In;function yu(t){const e=[];t&&t.isBone&&e.push(t);for(let i=0;i<t.children.length;i++)e.push.apply(e,yu(t.children[i]));return e}const vu=new Float32Array(1);function xu(t,e,i,n,s,r,a,o){t[e+0]=i,t[e+1]=n,t[e+2]=s,t[e+3]=r,t[e+4]=a,t[e+5]=o}new Int32Array(vu.buffer),lh.create=function(t,e){return t.prototype=Object.create(lh.prototype),t.prototype.constructor=t,t.prototype.getPoint=e,t},Eh.prototype.fromPoints=function(t){return this.setFromPoints(t)},class extends th{constructor(t=10,e=10,i=4473924,n=8947848){i=new bs(i),n=new bs(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 Rs;h.setAttribute("position",new zs(o,3)),h.setAttribute("color",new zs(l,3)),super(h,new jl({vertexColors:!0,toneMapped:!1})),this.type="GridHelper"}}.prototype.setColors=function(){},class extends th{constructor(t){const e=yu(t),i=new Rs,n=[],s=[],r=new bs(0,0,1),a=new bs(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 zs(n,3)),i.setAttribute("color",new zs(s,3)),super(i,new jl({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");gu.copy(this.root.matrixWorld).invert();for(let t=0,i=0;t<e.length;t++){const s=e[t];s.parent&&s.parent.isBone&&(_u.multiplyMatrices(gu,s.matrixWorld),mu.setFromMatrixPosition(_u),n.setXYZ(i,mu.x,mu.y,mu.z),_u.multiplyMatrices(gu,s.parent.matrixWorld),mu.setFromMatrixPosition(_u),n.setXYZ(i+1,mu.x,mu.y,mu.z),i+=2)}i.getAttribute("position").needsUpdate=!0,super.updateMatrixWorld(t)}}.prototype.update=function(){},Ac.prototype.extractUrlBase=function(t){return $c.extractUrlBase(t)},Ac.Handlers={add:function(){},get:function(){}},nn.prototype.center=function(t){return this.getCenter(t)},nn.prototype.empty=function(){return this.isEmpty()},nn.prototype.isIntersectionBox=function(t){return this.intersectsBox(t)},nn.prototype.isIntersectionSphere=function(t){return this.intersectsSphere(t)},nn.prototype.size=function(t){return this.getSize(t)},bn.prototype.empty=function(){return this.isEmpty()},xr.prototype.setFromMatrix=function(t){return this.setFromProjectionMatrix(t)},Wi.prototype.flattenToArrayOffset=function(t,e){return this.toArray(t,e)},Wi.prototype.multiplyVector3=function(t){return t.applyMatrix3(this)},Wi.prototype.multiplyVector3Array=function(){},Wi.prototype.applyToBufferAttribute=function(t){return t.applyMatrix3(this)},Wi.prototype.applyToVector3Array=function(){},Wi.prototype.getInverse=function(t){return this.copy(t).invert()},In.prototype.extractPosition=function(t){return this.copyPosition(t)},In.prototype.flattenToArrayOffset=function(t,e){return this.toArray(t,e)},In.prototype.getPosition=function(){return(new Qi).setFromMatrixColumn(this,3)},In.prototype.setRotationFromQuaternion=function(t){return this.makeRotationFromQuaternion(t)},In.prototype.multiplyToArray=function(){},In.prototype.multiplyVector3=function(t){return t.applyMatrix4(this)},In.prototype.multiplyVector4=function(t){return t.applyMatrix4(this)},In.prototype.multiplyVector3Array=function(){},In.prototype.rotateAxis=function(t){t.transformDirection(this)},In.prototype.crossVector=function(t){return t.applyMatrix4(this)},In.prototype.translate=function(){},In.prototype.rotateX=function(){},In.prototype.rotateY=function(){},In.prototype.rotateZ=function(){},In.prototype.rotateByAxis=function(){},In.prototype.applyToBufferAttribute=function(t){return t.applyMatrix4(this)},In.prototype.applyToVector3Array=function(){},In.prototype.makeFrustum=function(t,e,i,n,s,r){return this.makePerspective(t,e,n,i,s,r)},In.prototype.getInverse=function(t){return this.copy(t).invert()},gr.prototype.isIntersectionLine=function(t){return this.intersectsLine(t)},Ki.prototype.multiplyVector3=function(t){return t.applyQuaternion(this)},Ki.prototype.inverse=function(){return this.invert()},Ln.prototype.isIntersectionBox=function(t){return this.intersectsBox(t)},Ln.prototype.isIntersectionPlane=function(t){return this.intersectsPlane(t)},Ln.prototype.isIntersectionSphere=function(t){return this.intersectsSphere(t)},ps.prototype.area=function(){return this.getArea()},ps.prototype.barycoordFromPoint=function(t,e){return this.getBarycoord(t,e)},ps.prototype.midpoint=function(t){return this.getMidpoint(t)},ps.prototypenormal=function(t){return this.getNormal(t)},ps.prototype.plane=function(t){return this.getPlane(t)},ps.barycoordFromPoint=function(t,e,i,n,s){return ps.getBarycoord(t,e,i,n,s)},ps.normal=function(t,e,i,n){return ps.getNormal(t,e,i,n)},zh.prototype.extractAllPoints=function(t){return this.extractPoints(t)},zh.prototype.extrude=function(t){return new nc(this,t)},zh.prototype.makeGeometry=function(t){return new rc(this,t)},Vi.prototype.fromAttribute=function(t,e,i){return this.fromBufferAttribute(t,e,i)},Vi.prototype.distanceToManhattan=function(t){return this.manhattanDistanceTo(t)},Vi.prototype.lengthManhattan=function(){return this.manhattanLength()},Qi.prototype.setEulerFromRotationMatrix=function(){},Qi.prototype.setEulerFromQuaternion=function(){},Qi.prototype.getPositionFromMatrix=function(t){return this.setFromMatrixPosition(t)},Qi.prototype.getScaleFromMatrix=function(t){return this.setFromMatrixScale(t)},Qi.prototype.getColumnFromMatrix=function(t,e){return this.setFromMatrixColumn(e,t)},Qi.prototype.applyProjection=function(t){return this.applyMatrix4(t)},Qi.prototype.fromAttribute=function(t,e,i){return this.fromBufferAttribute(t,e,i)},Qi.prototype.distanceToManhattan=function(t){return this.manhattanDistanceTo(t)},Qi.prototype.lengthManhattan=function(){return this.manhattanLength()},Xi.prototype.fromAttribute=function(t,e,i){return this.fromBufferAttribute(t,e,i)},Xi.prototype.lengthManhattan=function(){return this.manhattanLength()},is.prototype.getChildByName=function(t){return this.getObjectByName(t)},is.prototype.renderDepth=function(){},is.prototype.translate=function(t,e){return this.translateOnAxis(e,t)},is.prototype.getWorldRotation=function(){},is.prototype.applyMatrix=function(t){return this.applyMatrix4(t)},Object.defineProperties(is.prototype,{eulerOrder:{get:function(){return this.rotation.order},set:function(t){this.rotation.order=t}},useQuaternion:{get:function(){},set:function(){}}}),er.prototype.setDrawMode=function(){},Object.defineProperties(er.prototype,{drawMode:{get:function(){return 0},set:function(){}}}),kl.prototype.initBones=function(){},hr.prototype.setLens=function(t,e){void 0!==e&&(this.filmGauge=e),this.setFocalLength(t)},Object.defineProperties(Nc.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(As.prototype,{length:{get:function(){return this.array.length}},dynamic:{get:function(){return this.usage===zi},set:function(){this.setUsage(zi)}}}),As.prototype.setDynamic=function(t){return this.setUsage(!0===t?zi:Ei),this},As.prototype.copyIndicesArray=function(){},As.prototype.setArray=function(){},Rs.prototype.addIndex=function(t){this.setIndex(t)},Rs.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 As(arguments[1],arguments[2]))},Rs.prototype.addDrawCall=function(t,e,i){this.addGroup(t,e)},Rs.prototype.clearDrawCalls=function(){this.clearGroups()},Rs.prototype.computeOffsets=function(){},Rs.prototype.removeAttribute=function(t){return this.deleteAttribute(t)},Rs.prototype.applyMatrix=function(t){return this.applyMatrix4(t)},Object.defineProperties(Rs.prototype,{drawcalls:{get:function(){return this.groups}},offsets:{get:function(){return this.groups}}}),ml.prototype.setDynamic=function(t){return this.setUsage(!0===t?zi:Ei),this},ml.prototype.setArray=function(){},nc.prototype.getArrays=function(){},nc.prototype.addShapeList=function(){},nc.prototype.addShape=function(){},fl.prototype.dispose=function(){},Object.defineProperties(ms.prototype,{wrapAround:{get:function(){},set:function(){}},overdraw:{get:function(){},set:function(){}},wrapRGB:{get:function(){return new bs}},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(or.prototype,{derivatives:{get:function(){return this.extensions.derivatives},set:function(t){this.extensions.derivatives=t}}}),pl.prototype.clearTarget=function(t,e,i,n){this.setRenderTarget(t),this.clear(e,i,n)},pl.prototype.animate=function(t){this.setAnimationLoop(t)},pl.prototype.getCurrentRenderTarget=function(){return this.getRenderTarget()},pl.prototype.getMaxAnisotropy=function(){return this.capabilities.getMaxAnisotropy()},pl.prototype.getPrecision=function(){return this.capabilities.precision},pl.prototype.resetGLState=function(){return this.state.reset()},pl.prototype.supportsFloatTextures=function(){return this.extensions.get("OES_texture_float")},pl.prototype.supportsHalfFloatTextures=function(){return this.extensions.get("OES_texture_half_float")},pl.prototype.supportsStandardDerivatives=function(){return this.extensions.get("OES_standard_derivatives")},pl.prototype.supportsCompressedTextureS3TC=function(){return this.extensions.get("WEBGL_compressed_texture_s3tc")},pl.prototype.supportsCompressedTexturePVRTC=function(){return this.extensions.get("WEBGL_compressed_texture_pvrtc")},pl.prototype.supportsBlendMinMax=function(){return this.extensions.get("EXT_blend_minmax")},pl.prototype.supportsVertexTextures=function(){return this.capabilities.vertexTextures},pl.prototype.supportsInstancedArrays=function(){return this.extensions.get("ANGLE_instanced_arrays")},pl.prototype.enableScissorTest=function(t){this.setScissorTest(t)},pl.prototype.initMaterial=function(){},pl.prototype.addPrePlugin=function(){},pl.prototype.addPostPlugin=function(){},pl.prototype.updateShadowMap=function(){},pl.prototype.setFaceCulling=function(){},pl.prototype.allocTextureUnit=function(){},pl.prototype.setTexture=function(){},pl.prototype.setTexture2D=function(){},pl.prototype.setTextureCube=function(){},pl.prototype.getActiveMipMapLevel=function(){return this.getActiveMipmapLevel()},Object.defineProperties(pl.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?Si:bi}},toneMappingWhitePoint:{get:function(){return 1},set:function(){}},gammaFactor:{get:function(){return 2},set:function(){}}}),Object.defineProperties(il.prototype,{cullFace:{get:function(){},set:function(){}},renderReverseSided:{get:function(){},set:function(){}},renderSingleSided:{get:function(){},set:function(){}}}),Object.defineProperties($i.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 is{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 Kc).load(t,(function(t){e.setBuffer(t)})),this},ur.prototype.updateCubeMap=function(t,e){return this.update(t,e)},ur.prototype.clear=function(t,e,i,n){return this.renderTarget.clear(t,e,i,n)},ji.crossOrigin=void 0,ji.loadTexture=function(t,e,i,n){const s=new Ic;s.setCrossOrigin(this.crossOrigin);const r=s.load(t,i,void 0,n);return e&&(r.mapping=e),r},ji.loadTextureCube=function(t,e,i,n){const s=new Lc;s.setCrossOrigin(this.crossOrigin);const r=s.load(t,i,void 0,n);return e&&(r.mapping=e),r},ji.loadCompressedTexture=function(){},ji.loadCompressedTextureCube=function(){},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:X}})),"undefined"!=typeof window&&(window.__THREE__||(window.__THREE__=X));class wu{#n=null;#s=-1;bounds=new Float32Array(6);get is_linked(){return-1!==this.#s}link(t,e){this.#n=t;const i=t.allocate_node();this.#s=i,t.node_set_aabb(i,this.bounds),t.node_set_user_data(i,e),t.insert_leaf(i)}unlink(){const t=this.#s;this.#n.remove_leaf(t),this.#n.release_node(t),this.#s=-1,this.#n=null}write_bounds(){null!==this.#n&&this.#n.node_move_aabb(this.#s,this.bounds)}resize(t,e,i,n,s,r){xu(this.bounds,0,t,e,i,n,s,r),this.write_bounds()}}class bu extends Error{constructor(t){super(t)}}class Su{normal=new O(0,1,0);position=new O(0,0,0);index=-1;get 0(){return this.position.x}get 1(){return this.position.y}get 2(){return this.position.z}get 3(){return this.normal.x}get 4(){return this.normal.y}get 5(){return this.normal.z}applyMatrix4(t){this.position.applyMatrix4(t),this.normal.applyDirectionMatrix4(t)}applyMatrix4_three(t){this.applyMatrix4(t.elements)}fromArray(t,e=0){this.position.readFromArray(t,e),this.normal.readFromArray(t,e+3)}toArray(t,e=0){this.position.writeToArray(t,e),this.normal.writeToArray(t,e+3)}equals(t){return this.index===t.index&&this.position.equals(t.position)&&this.normal.equals(t.normal)}copy(t){this.position.copy(t.position),this.normal.copy(t.normal),this.index=t.index}clone(){const t=new Su;return t.copy(this),t}}function Mu(t,e){return t<e?e:t}class Tu{constructor(t=0,e=0){this.x=t,this.y=e,this.onChanged=new y}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=Mu(this.x,t.x),i=Mu(this.y,t.y);return this.set(e,i)}dot(t){return Au(this.x,this.y,t.x,t.y)}copy(t){return this.set(t.x,t.y)}clone(){return new Tu(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=S(this.x,t,i),r=S(this.y,e,n);return this.set(s,r)}clampLow(t,e){const i=Mu(this.x,t),n=Mu(this.y,e);return this.set(i,n)}clampHigh(t,e){const i=C(this.x,t),n=C(this.y,e);return this.set(i,n)}distanceSqrTo(t){return this._distanceSqrTo(t.x,t.y)}lerpVectors(t,e,i){const n=A(t.x,e.x,i),s=A(t.y,e.y,i);this.set(n,s)}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 Cu(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 Eu(this.x,this.y)}normalize(){const t=this.length();if(0===t)return;const e=1/t;this.multiplyScalar(e)}hash(){const t=E(this.x);return(t<<5)-t+E(this.y)}rotate(t){const e=Math.sin(t),i=Math.cos(t),n=this.x,s=this.y,r=n*i-s*e,a=n*e+s*i;this.set(r,a)}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}roughlyEquals(t,e){return this._roughlyEquals(t.x,t.y,e)}_roughlyEquals(t,e,i=M){return T(this.x,t,i)&&T(this.y,e,i)}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 Au(t,e,i,n){return t*i+e*n}function Cu(t,e){return t*t+e*e}function Eu(t,e){return Math.sqrt(Cu(t,e))}function zu(t,e,i,n){return Eu(i-t,n-e)}Tu.up=Object.freeze(new Tu(0,1)),Tu.down=Object.freeze(new Tu(0,-1)),Tu.left=Object.freeze(new Tu(-1,0)),Tu.right=Object.freeze(new Tu(1,0)),Tu.zero=Object.freeze(new Tu(0,0)),Tu.one=Object.freeze(new Tu(1,1)),Tu.prototype.isVector2=!0,Tu._distance=zu;const Lu="texture",Iu="json",Nu="image",Pu=["float rand(float v){"," return fract(sin(v) * 43758.5453);","}"].join("\n"),Du=["#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"),Ou=["#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"),Fu=["#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"),Ru=["#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");["#ifdef USE_MAP"," vec4 texelColor = texture2D( map, vUv );"," texelColor = GammaToLinear( texelColor, float( GAMMA_FACTOR ) );"," \tdiffuseColor *= texelColor;","#endif"].join("\n");const ku={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 ${Du}\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 ${Ou}\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 ${Pu}\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 ${Fu}\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 ${Ru}\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 Bu({gridResolution:t,splatMap:e,diffuseMaps:i,lightMap:n}){const s=ar.merge([Tr.common,Tr.specularmap,Tr.envmap,Tr.aomap,Tr.lightmap,Tr.emissivemap,Tr.fog,Tr.lights,{splatWeightMap:{type:"t",value:null},splatLayerCount:{type:"f",value:4},splatResolution:{type:"v2",value:new Vi(1,1)},gridResolution:{type:"v2",value:new Vi(1,1)},uGridTransform:{type:"v4",value:new Xi},gridBorderWidth:{type:"f",value:.1},materialScalesMap:{type:"t",value:null},diffuseMaps:{type:"t",value:null},diffuseGridOverlayMap:{type:"t",value:null},diffuseGridOverlaySprite:{type:"t",value:function(t,e){const i=new Bl(new Uint8Array([255,255,255,255]),1,1);return i.generateMipmaps=!1,i.needsUpdate=!0,i.type=re,i}()}},{emissive:{type:"c",value:new bs(0)},specular:{type:"c",value:new bs(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 Vi(.03,-.03)},v_CloudsSpeed_1:{type:"v2",value:new Vi(.011,-.011)},v_CloudsSpeed_2:{type:"v2",value:new Vi(.023,-.023)},v_CloudsSize_0:{type:"v2",value:new Vi(40,40)},v_CloudsSize_1:{type:"v2",value:new Vi(20,20)},v_CloudsSize_2:{type:"v2",value:new Vi(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 or({uniforms:s,vertexShader:ku.vertexShader,fragmentShader:ku.fragmentShader,side:it,blending:at,depthTest:!0,depthWrite:!0,transparent:!1,lights:!0,defines:{SHADOWMAP_CLOUDS:!1,DIFFUSE_GRAIN:!1},glslVersion:Li});return r.depthWrite=!0,r.transparent=!1,s.diffuse.value=new bs(16777215),void 0!==e&&(e.wrapS=e.wrapT=Zt,e.minFilter=ie,e.magFilter=ie,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 Uu=[],Vu=[],Wu="undefined"!=typeof Uint8Array?Uint8Array:Array,Gu="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let t=0,e=64;t<e;++t)Uu[t]=Gu[t],Vu[Gu.charCodeAt(t)]=t;function Hu(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(Uu[(s=e)>>18&63]+Uu[s>>12&63]+Uu[s>>6&63]+Uu[63&s])}var s;return n.join("")}Vu["-".charCodeAt(0)]=62,Vu["_".charCodeAt(0)]=63;class ju{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=Hu(t,e,e+r>a?a:e+r);s.push(i)}return 1===n?(e=t[i-1],s.push(Uu[e>>2]+Uu[e<<4&63]+"==")):2===n&&(e=(t[i-2]<<8)+t[i-1],s.push(Uu[e>>10]+Uu[e>>4&63]+Uu[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 Wu(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=Vu[t.charCodeAt(i)]<<18|Vu[t.charCodeAt(i+1)]<<12|Vu[t.charCodeAt(i+2)]<<6|Vu[t.charCodeAt(i+3)],a[o++]=e>>16&255,a[o++]=e>>8&255,a[o++]=255&e;return 2===r&&(e=Vu[t.charCodeAt(i)]<<2|Vu[t.charCodeAt(i+1)]>>4,a[o++]=255&e),1===r&&(e=Vu[t.charCodeAt(i)]<<10|Vu[t.charCodeAt(i+1)]<<4|Vu[t.charCodeAt(i+2)]>>2,a[o++]=e>>8&255,a[o++]=255&e),a}(t).buffer}}const qu={Uint8:"uint8",Uint16:"uint16",Uint32:"uint32",Uint64:"uint64",Int8:"int8",Int16:"int16",Int32:"int32",Int64:"int64",Float16:"float16",Float32:"float32",Float64:"float64"},Ju={[qu.Uint8]:Uint8Array,[qu.Uint16]:Uint16Array,[qu.Uint32]:Uint32Array,[qu.Int8]:Int8Array,[qu.Int16]:Int16Array,[qu.Int32]:Int32Array,[qu.Float16]:Uint16Array,[qu.Float32]:Float32Array,[qu.Float64]:Float64Array};function Yu(t,i){if(t===i)return!0;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;if(r!==i.constructor)return!1;const a=t.buffer,o=i.buffer;if(a===o&&t.byteOffset===i.byteOffset)return!0;let l=t,h=i;const c=r.BYTES_PER_ELEMENT;return c<4&&s%4==0?(l=new Uint32Array(a,t.byteOffset,s/4),h=new Uint32Array(o,i.byteOffset,s/4)):c<2&&s%2==0&&(l=new Uint16Array(a,t.byteOffset,s/2),h=new Uint16Array(o,i.byteOffset,s/2)),e(l,h)}function Xu(t){switch(Object.getPrototypeOf(t).constructor){case Uint8Array:case Uint8ClampedArray:return qu.Uint8;case Uint16Array:return qu.Uint16;case Uint32Array:return qu.Uint32;case Int8Array:return qu.Int8;case Int16Array:return qu.Int16;case Int32Array:return qu.Int32;case Float32Array:return qu.Float32;case Float64Array:return qu.Float64;default:throw new Error("unsupported constructor type")}}const $u=A;function Zu(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 Ku(t,e,i,n){let s=i;for(let r=e;r<i;r+=n)s=(s<<5)-s+(t[r]>>>0);return s>>>0}class Qu{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)||i<0)throw new Error(`width must be a non-negative integer, instead was ${i}`);if(!Number.isInteger(n)||i<0)throw new Error(`height must be a non-negative integer, instead was ${n}`);if(void 0===t)throw new Error("data was undefined");if(t.length<i*n*e)throw new Error(`Buffer underflow, data.length(=${t.length}) is too small. Expected at least ${i*n*e}`);this.width=i,this.height=n,this.itemSize=e,this.data=t,this.version=0}get(t,e,i){throw new Error("Deprecated method, use sampleBilinear instead")}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-.5,s=e*this.height-.5;return this.sampleChannelCatmullRom(n,s,i)}sampleChannelCatmullRom(t,e,i){const n=Math.floor(t),s=Math.floor(e),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,s=e*this.height;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=S(t,0,l),u=S(e,0,h),d=0|c,p=0|u,f=c-d,m=u-p,_=Mu(0,d-1),g=Mu(0,p-1),y=C(l,d+1),v=C(h,p+1),x=C(l,y+1),w=g*o+i,b=p*o+i,M=v*o+i,T=C(h,v+1)*o+i,A=_*n,E=d*n,z=y*n,L=x*n,I=a[w+A],N=a[w+E],P=a[w+z],D=a[w+L],O=a[b+A],F=a[b+E],R=a[b+z],k=a[b+L],B=a[M+A],U=a[M+E],V=a[M+z],W=a[M+L],G=a[T+A],H=a[T+E],j=a[T+z],q=a[T+L],J=Zu(f,I,N,P,D),Y=Zu(f,O,F,R,k),X=Zu(f,B,U,V,W),$=Zu(f,G,H,j,q);return Zu(m,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-.5,s=e*this.height-.5;return this.sampleChannelBilinear(n,s,i)}sampleChannelBilinear(t,e,i){const n=this.itemSize,s=this.width,r=s*n,a=this.height-1,o=S(t,0,s-1),l=S(e,0,a),h=0|o,c=0|l,u=c*r,d=h*n+i,p=u+d;let f,m;f=o===h?h:h+1,m=l===c?c:c+1;const _=this.data,g=_[p];if(h===f&&c===m)return g;const y=o-h,v=l-c,x=f*n+i,w=m*r,b=w+d,M=w+x,T=_[u+x],A=_[b],C=_[M],E=$u(g,T,y),z=$u(A,C,y);return $u(E,z,v)}sampleNearestUV(t,e,i){const n=this.width,s=this.height,r=Math.round(t*n-.5),a=Math.round(e*s-.5);this.read(S(r,0,n-1),S(a,0,s-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]}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)}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++}zeroFill(t,e,i,n){const s=S(t,0,this.width),r=S(e,0,this.height),a=S(t+i,0,this.width),o=S(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++}channelFill(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=S(t,0,r),l=S(e,0,a),h=S(t+i,0,r),c=S(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=C(e,s),a=C(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}equals(t){return this.width===t.width&&this.height===t.height&&this.itemSize===t.itemSize&&Yu(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^=Ku(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 Qu(t,this.itemSize,this.width,this.height)}toJSON(){const t=ju.encode(this.data.buffer);return{height:this.height,width:this.width,itemSize:this.itemSize,type:Xu(this.data),data:t}}fromJSON({height:t,width:e,itemSize:i,type:n,data:s}){const r=function(t){const e=Ju[t];if(void 0===e)throw new Error(`Unsupported data type '${t}'`);return e}(n);if("string"==typeof s){const t=ju.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 Qu(n,t,e,i)}static uint8(t,e,i){const n=new Uint8Array(e*i*t);return new Qu(n,t,e,i)}static uint16(t,e,i){const n=new Uint16Array(e*i*t);return new Qu(n,t,e,i)}static uint32(t,e,i){const n=new Uint32Array(e*i*t);return new Qu(n,t,e,i)}static int8(t,e,i){const n=new Int8Array(e*i*t);return new Qu(n,t,e,i)}static int16(t,e,i){const n=new Int16Array(e*i*t);return new Qu(n,t,e,i)}static int32(t,e,i){const n=new Int32Array(e*i*t);return new Qu(n,t,e,i)}static float32(t,e,i){const n=new Float32Array(e*i*t);return new Qu(n,t,e,i)}static float64(t,e,i){const n=new Float64Array(e*i*t);return new Qu(n,t,e,i)}}Qu.prototype.isSampler2D=!0,Qu.typeName="Sampler2D";const td="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAA1JREFUGFdj+P///38ACfsD/QVDRcoAAAAASUVORK5CYII=";function ed(t){return Math.round(255*t)}function id(t){return t/255}function nd(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]}class sd extends Number{constructor(t=0){super(),this.x=t,this.onChanged=new y}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(S(this.x,t,e))}copy(t){this.set(t.x)}clone(){return new sd(this.x)}equals(t){return this.x===t.x}hash(){return E(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 rd(...t){return Ku(t,0,t.length,1)}function ad(t,e,i,n){return t*t+e*e+i*i+n*n}sd.prototype.isVector1=!0,sd.typeName="Vector1",sd.zero=Object.freeze(new sd(0)),sd.one=Object.freeze(new sd(1));class od{constructor(t=0,e=0,i=0,n=0){this.x=t,this.y=e,this.z=i,this.w=n,this.onChanged=new y}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 od;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 rd(E(this.x),E(this.y),E(this.z),E(this.w))}lerpVectors(t,e,i){od.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=A(t.x,e.x,i),r=A(t.y,e.y,i),a=A(t.z,e.z,i),o=A(t.w,e.w,i);n.set(s,r,a,o)}}function ld(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}class hd extends String{constructor(t=""){super(),this.__value=t,this.onChanged=new y}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 ld(this.__value)}}function cd(t,e){const i=e.width,n=e.height,s=t.width/i,r=t.height/n,a=Mu(1,Math.ceil(s)),o=Mu(1,Math.ceil(r)),l=1/(a*o),h=t.itemSize,c=new Float32Array(h);let u,d,p,f,m;for(u=0;u<n;u++){const n=u*r;for(d=0;d<i;d++){const r=d*s,_=(u*i+d)*h;for(p=0;p<o;p++)for(f=0;f<a;f++)for(m=0;m<h;m++)c[m]+=t.sampleChannelBilinear(r+f,n+p,m);for(m=0;m<h;m++)e.data[_+m]=c[m]*l,c[m]=0}}}function ud(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 Float64Array(l),c=1/(a*o),u=t.data,d=e.data;for(let t=0;t<r;t++){const e=t*o,n=t*s*l;for(let t=0;t<s;t++){const s=n+t*l,r=t*a;for(let t=0;t<o;t++){let n=((e+t)*i+r)*l;for(let t=a;t>0;t--){for(let t=0;t<l;t++)h[t]+=u[t+n];n+=l}}for(let t=0;t<l;t++)d[s+t]=h[t]*c,h[t]=0}}}(t,e):cd(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):cd(t,e)}hd.prototype.isObservedString=!0;function dd(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))}let pd=class{constructor(t,e,i){this.sampler=t,this.borderWidth=e,this.tileImage=i}};const fd=[0,0,0,0];class md{constructor(t){this.borderWidth=new sd(.1),this.size=new Tu(t.x,t.y),this.tileImage=new hd(td),this.sampler=Qu.uint8(4,t.x,t.y);const e=this.texture=new Bl(this.sampler.data);e.wrapS=Zt,e.wrapT=Zt,e.magFilter=Qt,e.minFilter=Qt,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 pd(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]=id(s)}}paintPointAlphaBlend(t,e,i){const n=new od;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,fd)}paintPoint(t,e,i){for(let n=0;n<4;n++)this.sampler.writeChannel(t,e,n,ed(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):nd(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 Qu(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=Qu.uint8(4,n,s);ud(t,r),function(t,e,i,n,s,r,a,o,l=0){let h;if(0!==l)throw new Error(`Unsupported blendType(=${l})`);h=dd;const c=Math.min(a,e.width-i,t.width-s),u=Math.min(o,e.height-n,t.height-r),d=Math.max(0,-s),p=[0,0,0,255],f=[0,0,0,255],m=[];let _,g;for(g=Math.max(0,-r);g<u;g++)for(_=d;_<c;_++){const i=Math.round(_+s),a=Math.round(g+r);t.read(i,a,p);const o=Math.round(_+n),l=Math.round(g+n);e.read(o,l,f),h(f,p,m),t.set(i,a,m)}}(this,r,0,0,e,i,n,s),this.texture.needsUpdate=!0}}const _d=new Map;function gd(t){const e=_d.get(t);if(void 0!==e)return e;const i=(new Ic).load(t);return i.wrapS=$t,i.wrapT=$t,i.repeat.set(1,1),_d.set(t,i),i}class yd{__enabled=!1;materials=[];time=0;__speed0=new Tu;__speed1=new Tu;__speed2=new Tu;variability=.37;constructor(){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))}}class vd{url="";offset=new Tu(0,0);scale=new Tu(1,1);copy(t){this.url=t.url,this.scale.copy(t.scale),this.offset.copy(t.offset)}toJSON(){return{url:this.url,offset:this.offset.toJSON(),scale:this.scale.toJSON()}}fromJSON(t){this.url=t.url,this.offset.fromJSON(t.offset),this.scale.fromJSON(t.scale)}toBinaryBuffer(t){t.writeUTF8String(this.url),this.offset.toBinaryBuffer(t),this.scale.toBinaryBuffer(t)}fromBinaryBuffer(t){this.url=t.readUTF8String(),this.offset.fromBinaryBuffer(t),this.scale.fromBinaryBuffer(t)}}function xd(t,e){const i=e.length;i>=t.length?e.set(t,0):nd(t,0,e,0,i)}function wd(t,e,i,n,s,r){const a=n-t,o=r-i;return 2*((s-e)*(a+o)+o*a)}const bd=4294967295,Sd=10,Md=Math.floor(107374182.375);class Td{__data_buffer=new ArrayBuffer(5120);__data_float32=new Float32Array(this.__data_buffer);__data_uint32=new Uint32Array(this.__data_buffer);__capacity=128;__size=0;__free=[];__free_pointer=0;__root=bd;get root(){return this.__root}get node_capacity(){return this.__capacity}set node_capacity(t){if(this.__size>t)throw new Error(`Can't shrink capacity to ${t}, because it's below occupancy(${this.__size}).`);this.__set_capacity(t)}__grow_capacity(){if(this.__capacity>=Md)throw new Error("Can not grow capacity, already at maximum platform limit");let t=Math.ceil(Mu(1.2*this.__capacity,this.__capacity+64));t>Md&&(t=Md),this.__set_capacity(t)}__set_capacity(t){if(this.__capacity===t)return;const e=this.__data_uint32,i=new ArrayBuffer(t*Sd*4);this.__data_buffer=i,this.__data_float32=new Float32Array(i),this.__data_uint32=new Uint32Array(i),xd(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=Sd*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]=bd,s[i+7]=bd,s[i+8]=bd,s[i+9]=0,t}release_node(t){this.__free[this.__free_pointer++]=t}node_is_leaf(t){return this.__data_uint32[Sd*t+7]===bd}node_get_user_data(t){return this.__data_uint32[Sd*t+8]}node_set_user_data(t,e){this.__data_uint32[Sd*t+8]=e}node_get_child1(t){return this.__data_uint32[Sd*t+7]}node_set_child1(t,e){this.__data_uint32[Sd*t+7]=e}node_get_child2(t){return this.__data_uint32[Sd*t+8]}node_set_child2(t,e){this.__data_uint32[Sd*t+8]=e}node_get_parent(t){return this.__data_uint32[Sd*t+6]}node_set_parent(t,e){this.__data_uint32[Sd*t+6]=e}node_get_height(t){return this.__data_uint32[Sd*t+9]}node_set_height(t,e){this.__data_uint32[Sd*t+9]=e}node_get_aabb(t,e){const i=Sd*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=Sd*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[Sd*t+6];i!==bd&&this.bubble_up_refit(i)}node_set_aabb_primitive(t,e,i,n,s,r,a){const o=Sd*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=Sd*t,i=this.__data_float32;return wd(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=Sd*t,n=Sd*e,s=this.__data_float32;return wd(C(s[i],s[n]),C(s[i+1],s[n+1]),C(s[i+2],s[n+2]),Mu(s[i+3],s[n+3]),Mu(s[i+4],s[n+4]),Mu(s[i+5],s[n+5]))}node_set_combined_aabb(t,e,i){const n=Sd*e,s=Sd*i,r=this.__data_float32,a=C(r[n],r[s]),o=C(r[n+1],r[s+1]),l=C(r[n+2],r[s+2]),h=Mu(r[n+3],r[s+3]),c=Mu(r[n+4],r[s+4]),u=Mu(r[n+5],r[s+5]),d=t*Sd;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===bd)return this.__root=t,void(e[t*Sd+6]=bd);let i=this.__root;for(;!1===this.node_is_leaf(i);){const n=e[i*Sd+7],s=e[i*Sd+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*Sd+6],r=this.allocate_node();e=this.__data_uint32,e[r*Sd+6]=s,this.node_set_combined_aabb(r,t,n),e[r*Sd+9]=e[n*Sd+9]+1,s!==bd?e[s*Sd+7]===n?e[s*Sd+7]=r:e[s*Sd+8]=r:this.__root=r,e[r*Sd+7]=n,e[r*Sd+8]=t,e[n*Sd+6]=r,e[t*Sd+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*Sd,n=i[t+7],s=i[t+8];this.node_set_combined_aabb(e,n,s),e=i[t+6]}while(e!==bd)}bubble_up_update(t){let e=t;const i=this.__data_uint32;for(;e!==bd;){e=this.balance(e);const t=e*Sd,n=i[t+7],s=i[t+8];i[t+9]=1+Mu(i[n*Sd+9],i[s*Sd+9]),this.node_set_combined_aabb(e,n,s),e=i[t+6]}}remove_leaf(t){if(t===this.__root)return void(this.__root=bd);const e=this.__data_uint32,i=e[t*Sd+6],n=e[i*Sd+6];let s;const r=e[i*Sd+7];s=r===t?e[i*Sd+8]:r,n!==bd?(e[n*Sd+7]===i?e[n*Sd+7]=s:e[n*Sd+8]=s,e[s*Sd+6]=n,this.release_node(i),this.bubble_up_update(n)):(this.__root=s,e[s*Sd+6]=bd,this.release_node(i))}balance(t){const e=this.__data_uint32;if(this.node_is_leaf(t)||e[t*Sd+9]<2)return t;const i=e[t*Sd+7],n=e[t*Sd+8],s=e[n*Sd+9]-e[i*Sd+9];if(s>1){const s=e[n*Sd+7],r=e[n*Sd+8];e[n*Sd+7]=t;const a=e[t*Sd+6];return e[n*Sd+6]=a,e[t*Sd+6]=n,a!==bd?e[a*Sd+7]===t?e[a*Sd+7]=n:e[a*Sd+8]=n:this.__root=n,e[s*Sd+9]>e[r*Sd+9]?(e[n*Sd+8]=s,e[t*Sd+8]=r,e[r*Sd+6]=t,this.node_set_combined_aabb(t,i,r),this.node_set_combined_aabb(n,t,s),e[t*Sd+9]=1+Mu(e[i*Sd+9],e[r*Sd+9]),e[n*Sd+9]=1+Mu(e[t*Sd+9],e[s*Sd+9])):(e[n*Sd+8]=r,e[t*Sd+8]=s,e[s*Sd+6]=t,this.node_set_combined_aabb(t,i,s),this.node_set_combined_aabb(n,t,r),e[t*Sd+9]=1+Mu(e[i*Sd+9],e[s*Sd+9]),e[n*Sd+9]=1+Mu(e[t*Sd+9],e[r*Sd+9])),n}if(s<-1){const s=e[i*Sd+7],r=e[i*Sd+8];e[i*Sd+7]=t;const a=e[t*Sd+6];return e[i*Sd+6]=a,e[t*Sd+6]=i,a!==bd?e[a*Sd+7]===t?e[a*Sd+7]=i:e[a*Sd+8]=i:this.__root=i,e[s*Sd+9]>e[r*Sd+9]?(e[i*Sd+8]=s,e[t*Sd+7]=r,e[r*Sd+6]=t,this.node_set_combined_aabb(t,n,r),this.node_set_combined_aabb(i,t,s),e[t*Sd+9]=1+Mu(e[n*Sd+9],e[r*Sd+9]),e[i*Sd+9]=1+Mu(e[t*Sd+9],e[s*Sd+9])):(e[i*Sd+8]=r,e[t*Sd+7]=s,e[s*Sd+6]=t,this.node_set_combined_aabb(t,n,s),this.node_set_combined_aabb(i,t,r),e[t*Sd+9]=1+Mu(e[n*Sd+9],e[s*Sd+9]),e[i*Sd+9]=1+Mu(e[t*Sd+9],e[r*Sd+9])),i}return t}release_all(){this.__root=bd,this.__size=0,this.__free_pointer=0}traverse(t,e){let i=0;const n=[],s=this.__root;s!==bd&&(n[i++]=s);const r=this.__data_uint32;for(;i>0;){i--;const s=n[i];t.call(e,s,this);const a=s*Sd,o=r[a+7],l=r[a+8];o!==bd&&(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*Sd,s=i[n+7],r=i[n+8];s!==bd&&(i[s*Sd+6]=e,i[r*Sd+6]=e);const a=i[n+6];a!==bd&&(i[a*Sd+7]===t?i[a*Sd+7]=e:i[a*Sd+8]=e)}swap_nodes(t,e){const i=this.__data_uint32,n=t*Sd,s=e*Sd;return i[n+6]!==e&&i[s+6]!==t&&(this.__move_node_links(t,e),this.__move_node_links(e,t),nd(i,n,this.__free,this.__free_pointer,Sd),nd(i,s,i,n,Sd),nd(this.__free,this.__free_pointer,i,s,Sd),this.__root===t?this.__root=e:this.__root===e&&(this.__root=t),!0)}}const Ad=new Uint32Array(781250);Ad.pointer=0;const Cd=Math.abs;function Ed(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&&Cd(p)>d)return!1;const f=.5*(s-e),m=o-(e+f);if(m*c>=0&&Cd(m)>f)return!1;const _=.5*(r-i),g=l-(i+_);if(g*u>=0&&Cd(g)>_)return!1;const y=Cd(c),v=Cd(u);if(Cd(c*g-u*m)>f*v+_*y)return!1;const x=Cd(h);return!(Cd(u*p-h*g)>d*v+_*x)&&Cd(h*m-c*p)<=d*y+f*x}const zd=Ad;function Ld(t){return t<0?0:t>1?1:t}function Id(t){return parseInt(t,16)}const Nd=/rgb\(\s*([0-9]+),\s*([0-9]+),\s*([0-9]+)\s*\)/,Pd=/rgba\(\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?)\s*\)/,Dd=/hsv\(([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?),\s*([0-9]+(?:\.[0-9]*)?)\)/;function Od(t,e,i){let n=t;return n>e&&(n=e),n>i&&(n=i),n}function Fd(t){const e=Math.round(t).toString(16);return 1===e.length?"0"+e:e}function Rd(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}function kd(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}class Bd{constructor(t=0,e=0,i=0,n=1){this.r=t,this.g=e,this.b=i,this.a=n,this.onChanged=new y}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){this.set(t,e,i,this.a)}setA(t){this.set(this.r,this.g,this.b,t)}set(t,e,i,n){const s=this.r,r=this.g,a=this.b,o=this.a;this.r=t,this.g=e,this.b=i,this.a=n,this.onChanged.send8(t,e,i,n,s,r,a,o)}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*C(i,1-i),l=i-o*Mu(-1,Od(s-3,9-s,1)),h=i-o*Mu(-1,Od(r-3,9-r,1)),c=i-o*Mu(-1,Od(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=Ld(e),r=Ld(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){const n=id(t),s=id(e),r=id(i),a=Math.max(n,s,r),o=Math.min(n,s,r);let l,h,c=a;const u=a-o;if(h=0===a?0:u/a,a===o)l=0;else{switch(a){case n:l=(s-r)/u+(s<r?6:0);break;case s:l=(r-n)/u+2;break;case r:l=(n-s)/u+4}l/=6}return{h:l,s:h,v:c}}(255*this.r,255*this.g,255*this.b)}toUint(){return function(t,e,i){const n=ed(t),s=ed(e);return 255&ed(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=ed(this.r),e=ed(this.g),i=ed(this.b),Fd(t)+Fd(e)+Fd(i));var t,e,i}toCssRGBAString(){return`rgba(${ed(this.r)},${ed(this.g)},${ed(this.b)},${this.a})`}equals(t){return this.r===t.r&&this.g===t.g&&this.b===t.b&&this.a===t.a}copy(t){this.a=t.a,this.setRGB(t.r,t.g,t.b)}clone(){const t=new Bd;return t.copy(this),t}hash(){return this.toUint()}fromJSON({r:t,g:e,b:i,a:n=1}){this.setRGB(t,e,i),this.a=n}toJSON(){return{r:this.r,g:this.g,b:this.b,a:this.a}}*[Symbol.iterator](){yield this.r,yield this.g,yield this.b,yield this.a}writeToArray(t,e){t[e]=this.r,t[e+1]=this.g,t[e+2]=this.b,t[e+3]=this.a}toBinaryBuffer(t){t.writeFloat32(this.r),t.writeFloat32(this.g),t.writeFloat32(this.b),t.writeFloat32(this.a)}fromBinaryBuffer(t){const e=t.readFloat32(),i=t.readFloat32(),n=t.readFloat32(),s=t.readFloat32();this.setRGB(e,i,n),this.a=s}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(Nd)))n=parseInt(i[1]),s=parseInt(i[2]),r=parseInt(i[3]);else if(null!==(i=e.match(Pd)))n=parseFloat(i[1]),s=parseFloat(i[2]),r=parseFloat(i[3]),a=parseFloat(i[4]);else if(null!==(i=e.match(Dd))){const t=function(t,e,i){let n=t;n<0&&(n+=Math.ceil(Math.abs(n))),n%=1;const s=Ld(e),r=Ld(i);let a,o,l,h,c,u,d,p;switch(h=Math.floor(6*n),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:ed(a),g:ed(o),b:ed(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=function(t){const e={r:Id(t.slice(1,3)),g:Id(t.slice(3,5)),b:Id(t.slice(5,7))};return t.length>7?e.a=Id(t.slice(7,9)):e.a=1,e}(e);n=t.r,s=t.g,r=t.b,a=t.a}}}else{if("number"!==i)throw new Error(`Failed to decode color '${t}'`);n=t>>16,s=t>>8&255,r=255&t}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=A(t.r,e.r,i),this.g=A(t.g,e.g,i),this.b=A(t.b,e.b,i),this.a=A(t.a,e.a,i)}static fromRGB(t,e,i){return new Bd(t,e,i)}static fromHSV(t,e,i){const n=new Bd;return n.setHSV(t,e,i),n}static parse(t){const e=new Bd;return e.parse(t),e}static from_linear_to_sRGB(t,e){!function(t,e,i,n){t[0]=Rd(i[0]),t[1]=Rd(i[1]),t[2]=Rd(i[2])}(e,0,t)}static from_sRGB_to_linear(t,e){!function(t,e,i,n){t[0]=kd(i[0]),t[1]=kd(i[1]),t[2]=kd(i[2])}(e,0,t)}}function Ud(){}function Vd(t,e,i,n){return e>i&&n>t}function Wd(t,e,i,n,s,r,a,o){return Vd(t,i,s,a)&&Vd(e,n,r,o)}function Gd(t,e,i){const n=e-t;return 0===n?0:(i-t)/n}Bd.red=Object.freeze(new Bd(1,0,0)),Bd.green=Object.freeze(new Bd(0,1,0)),Bd.blue=Object.freeze(new Bd(0,0,1)),Bd.yellow=Object.freeze(new Bd(1,1,0)),Bd.cyan=Object.freeze(new Bd(0,1,1)),Bd.magenta=Object.freeze(new Bd(1,0,1)),Bd.white=Object.freeze(new Bd(1,1,1)),Bd.black=Object.freeze(new Bd(0,0,0)),Bd.transparent=Object.freeze(new Bd(0,0,0,0));class Hd{constructor(t=Number.NEGATIVE_INFINITY,e=Number.POSITIVE_INFINITY){this.min=t,this.max=e,this.onChanged=new y}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 Gd(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=E(this.min);return t=(t<<5)-t+E(this.max),t}get span(){return this.max-this.min}}Hd.prototype.isNumericInterval=!0,Hd.one_one=Object.freeze(new Hd(1,1)),Hd.zero_zero=Object.freeze(new Hd(0,0));class jd extends Number{onChanged=new y;constructor(t=0){super(),this.__value=t}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 qd(t){this.onChanged=new y,this.__value=t}jd.prototype.isObservedInteger=!0,qd.prototype.set=function(t){if(this.__value!==t){const e=this.__value;this.__value=t,this.onChanged.send2(t,e)}},qd.prototype.setSilent=function(t){this.__value=t},qd.prototype.get=function(){return this.__value},qd.prototype.getValue=qd.prototype.get,qd.prototype.copy=function(t){this.set(t.__value)},qd.prototype.equals=function(t){return"object"==typeof t&&this.__value===t.__value},qd.prototype.clone=function(){return new qd(this.__value)},qd.prototype.process=function(t){return t(this.__value),this.onChanged.add(t),this},qd.prototype.toString=function(){return JSON.stringify({value:this.__value})},qd.prototype.toJSON=function(){return this.get()},qd.prototype.fromJSON=function(t){this.set(t)};function Jd(t){let e=t-1;return e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e}function Yd(t,e,i,n,s,r){t[e+0]=C(i[n+0],s[r+0]),t[e+1]=C(i[n+1],s[r+1]),t[e+2]=C(i[n+2],s[r+2]),t[e+3]=Mu(i[n+3],s[r+3]),t[e+4]=Mu(i[n+4],s[r+4]),t[e+5]=Mu(i[n+5],s[r+5])}function Xd(t,e,i,n,s,r){const a=n-t,o=r-i;return(s-e)*(a+o)+o*a}function $d(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 Zd(t,e,i){return $d(t)|$d(e)<<1|$d(i)<<2}function Kd(t,e,i){let n=t;return n<e&&(n=e),n<i&&(n=i),n}function Qd(t,e,i){const n=t[i],s=t[i+1],r=t[i+2];xu(t,e,n,s,r,n,s,r)}function tp(t,e,i){const n=t[e],s=t[e+1],r=t[e+2];return function(t,e,i,n){const s=n[0],r=n[1],a=n[2],o=1023*(t-s)/(n[3]-s),l=1023*(e-r)/(n[4]-r),h=1023*(i-a)/(n[5]-a);return Zd(Math.round(o),Math.round(l),Math.round(h))}(.5*(n+t[e+3]),.5*(s+t[e+4]),.5*(r+t[e+5]),i)}const ep=Ad;class ip{__data_buffer;__data_float32;__data_uint32;__node_count_binary=0;__node_count_leaf=0;constructor(){this.data=new ArrayBuffer(320)}estimateByteSize(){return this.data.byteLength+248}getTotalBoxCount(){return this.__node_count_binary+this.__node_count_leaf}get binary_node_count(){return this.__node_count_binary}get leaf_node_count(){return this.__node_count_leaf}getLeafBlockAddress(){return 6*this.__node_count_binary}get float32(){return this.__data_float32}get uint32(){return this.__data_uint32}set data(t){this.__data_buffer=t,this.__data_float32=new Float32Array(this.__data_buffer),this.__data_uint32=new Uint32Array(this.__data_buffer)}get data(){return this.__data_buffer}getNodeAddress(t){const e=this.__node_count_binary,i=t-e;return i<0?6*t:6*e+7*i}initialize_structure(){const t=4*(6*this.__node_count_binary+7*this.__node_count_leaf);this.__data_buffer.byteLength<t&&(this.data=new ArrayBuffer(t))}setLeafCount(t){this.__node_count_leaf=t;const e=Jd(t);this.__node_count_binary=t<=1?e:e-1}setLeafData(t,e,i,n,s,r,a,o){const l=7*t+6*this.__node_count_binary;xu(this.__data_float32,l,i,n,s,r,a,o),this.__data_uint32[l+6]=e}readBounds(t,e,i){nd(this.__data_float32,t,e,i,6)}readLeafPayload(t){const e=this.getLeafBlockAddress()+7*t+6;return this.__data_uint32[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?6*i:7*(i-this.__node_count_binary)+this.getLeafBlockAddress(),this.readBounds(n,e,0),t+=Xd(e[0],e[1],e[2],e[3],e[4],e[5])}return t}__compute_bounds_area_of_3_boxes(t,e,i){const n=this.__data_float32;return Xd(Od(n[t+0],n[e+0],n[i+0]),Od(n[t+1],n[e+1],n[i+1]),Od(n[t+2],n[e+2],n[i+2]),Kd(n[t+3],n[e+3],n[i+3]),Kd(n[t+4],n[e+4],n[i+4]),Kd(n[t+5],n[e+5],n[i+5]))}__fitness_function_should_swap_leaves_sah(t,e){const i=Mu(t-1,0),n=C(t+1,this.__node_count_leaf-1),s=this.getLeafBlockAddress(),r=7*t+s,a=7*i+s,o=7*n+s,l=7*e+s,h=7*Mu(e-1,0)+s,c=7*C(e+1,this.__node_count_leaf-1)+s;return this.__compute_bounds_area_of_3_boxes(a,r,o)+this.__compute_bounds_area_of_3_boxes(h,l,c)-(this.__compute_bounds_area_of_3_boxes(a,l,o)+this.__compute_bounds_area_of_3_boxes(h,r,c))}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=6*this.__node_count_binary;if(this.__node_count_leaf<2)return;let i,n,s=2;ep[0]=0,ep[1]=this.__node_count_leaf-1;const r=this.__data_float32;for(;s>0;){s-=2;const a=ep[s+1],o=ep[s];i=o,n=a;const l=tp(r,7*(o+a>>1)+e,t);for(;i<=n;){for(;tp(r,7*i+e,t)<l;)i++;for(;tp(r,7*n+e,t)>l;)n--;i<=n&&(i!==n&&this.__swap_leaves(i,n),i++,n--)}o<n&&(ep[s++]=o,ep[s++]=n),i<a&&(ep[s++]=i,ep[s++]=a)}}__swap_leaves(t,e){const i=this.getLeafBlockAddress(),n=7*t+i,s=7*e+i;!function(t,e,i,n,s){let r,a,o;for(o=0;o<7;o++){r=e+o,a=n+o;const s=i[a];i[a]=t[r],t[r]=s}}(this.__data_float32,n,this.__data_float32,s)}build(){const t=this.__node_count_binary,e=6*t;let i,n,s,r,a=Math.floor(Math.log(t)/Math.log(2));s=Math.pow(2,a),n=6*(s-1);const o=this.__node_count_leaf,l=this.__data_float32;for(i=0;i<s;i++){const t=2*i,s=t+1,r=e+7*t;s<o?Yd(l,n,l,r,l,e+7*s):t<o?nd(l,r,l,n,6):Qd(this.__data_float32,n,n-6),n+=6}for(a--;a>=0;a--)for(s=Math.pow(2,a),r=s-1,i=0;i<s;i++){const t=1+(r<<1);Yd(l,6*r,l,6*t,l,6*(t+1)),r++}}}function np(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 sp(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 rp(t,e,i,n,s,r,a,o,l,h){let c,u,d,p,f,m;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);const _=-n;return L(p,f,m,t,e,i)<_?-2:L(t,e,i,c,u,d)>=_?2:0}function ap(t,e,i,n,s,r,a,o,l){const h=4*l;for(let l=0;l<h;l+=4){const h=o+l;if(sp(a[h],a[h+1],a[h+2],a[h+3],t,e,i,n,s,r)<0)return!1}return!0}function op(t,e,i,n,s,r,a){let o=2;for(let l=0;l<24;l+=4){const h=rp(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 lp(t){return t>=0?t:-t}function hp(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 cp{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 function(t,e,i,n){return e>=t[0]&&e<=t[3]&&i>=t[1]&&i<=t[4]&&n>=t[2]&&n<=t[5]}(this,t,e,i)}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 Zd(this.x0+this.x1>>1,this.y0+this.y1>>1,this.z0+this.z1>>1)}computeSurfaceArea(){return wd(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)}_translate(t,e,i){this.setBounds(this.x0+t,this.y0+e,this.z0+i,this.x1+t,this.y1+e,this.z1+i)}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;let p=Mu(t-a,a-n),f=Mu(h,c),m=Mu(u,d);return p>0||f>0||m>0?(p=Mu(p,0),f=Mu(f,0),m=Mu(m,0),p*p+f*f+m*m):-(p*p+f*f+m*m)}(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){return function(t,e,i,n,s,r,a,o,l,h,c,u){const d=a-n,p=t-h,f=o-s,m=e-c,_=l-r,g=i-u,y=Math.max(d,p),v=Math.max(f,m),x=Math.max(_,g);let w=Math.sqrt(y*y+v*v+x*x);return y<0&&v<0&&x<0?-w:w}(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t,e,i,n,s,r)}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 Ed(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,A,C;return y=.5*(h-a),d=(n-t)/2,w=t+d,m=.5*(h+a)-w,M=lp(y),!(lp(m)>d+M||(v=.5*(c-o),p=(s-e)/2,b=e+p,_=.5*(c+o)-b,T=lp(v),lp(_)>p+T||(x=.5*(u-l),f=(r-i)/2,S=i+f,g=.5*(u+l)-S,A=lp(x),lp(g)>f+A||(C=v*g-x*_,lp(C)>p*A+f*T||(C=x*m-y*g,lp(C)>d*A+f*M||(C=y*_-v*m,lp(C)>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){np(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){const i=t[e],n=t[e+1],s=t[e+2],r=t[e+3],a=t[e+4],o=t[e+5];this.setBounds(i,n,s,r,a,o)}computePlaneSide(t){const e=t.normal;return rp(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 sp(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 op(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 ap(this.x0,this.y0,this.z0,this.x1,this.y1,this.z1,t,0,6)}applyMatrix4(t){const e=[],i=[];this.writeToArray(e,0),hp(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 cp;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)}}function up(t,e,i,n,s){const r=i[n+0],a=i[n+1],o=i[n+2],l=i[n+3],h=i[n+4],c=i[n+5],u=s[3]*r+s[7]*a+s[11]*o+s[15];if(0===u)return!1;const d=1/u,p=(s[0]*r+s[4]*a+s[8]*o+s[12])*d,f=(s[1]*r+s[5]*a+s[9]*o+s[13])*d,m=(s[2]*r+s[6]*a+s[10]*o+s[14])*d,_=s[0]*l+s[4]*h+s[8]*c,g=s[1]*l+s[5]*h+s[9]*c,y=s[2]*l+s[6]*h+s[10]*c,v=Math.hypot(_,g,y);if(0===v)return!1;const x=1/v,w=_*x,b=g*x,S=y*x;return t[e+0]=p,t[e+1]=f,t[e+2]=m,t[e+3]=w,t[e+4]=b,t[e+5]=S,!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}function pp(t,e,i,n,s,r,a,o){return Ed(t[e],t[e+1],t[e+2],t[e+3],t[e+4],t[e+5],i,n,s,r,a,o)}cp.prototype.isAABB3=!0;const fp=Ad;function mp(t,e,i,n,s,r,a,o,l,h,c,u,d,p,f,m){const _=c-o,g=u-l,y=d-h,v=p-o,x=f-l,w=m-h,b=g*w-y*x,S=y*v-_*w,M=_*x-g*v;let T=L(s,r,a,b,S,M),A=1;if(0===T)return!1;T<0&&(A=-1,T=-T);const C=e-o,E=i-l,z=n-h,I=A*L(s,r,a,E*w-z*x,z*v-C*w,C*x-E*v);if(I<0)return!1;const N=A*L(s,r,a,g*z-y*E,y*C-_*z,_*E-g*C);if(N<0)return!1;if(I+N>T)return!1;const P=-A*L(C,E,z,b,S,M);if(P<0)return!1;const D=P/T;return t.normal.set(b,S,M),t.position.set(s*D+e,r*D+i,a*D+n),!0}const _p=[],gp=new Su;function yp(t,e,i,n,s,r,a,o,l,h,c,u){let d=!1;const p=function(t,e,i,n,s,r,a,o,l){let h=0;const c=i.binary_node_count;if(c<=0)return 0;const u=fp.pointer++;fp[u]=0;const d=c+i.leaf_node_count,p=i.float32,f=i.uint32;do{fp.pointer--;const e=fp[fp.pointer],u=i.getNodeAddress(e);if(pp(p,u,n,s,r,a,o,l))if(e<c){const t=1+(e<<1),i=t+1;i<d?(fp[fp.pointer++]=i,fp[fp.pointer++]=t):t<d&&(fp[fp.pointer++]=t)}else t[0+h]=f[u+6],h++}while(fp.pointer>u);return h}(_p,0,e,a,o,l,h,c,u);let f,m,_,g=Infinity;for(let e=0;e<p;e++){const p=3*_p[e];void 0!==r?(f=r[p],m=r[p+1],_=r[p+2]):(f=p,m=p+1,_=p+2);const y=f*s+n,v=m*s+n,x=_*s+n,w=i[y],b=i[y+1],S=i[y+2],M=i[v],T=i[v+1],A=i[v+2],C=i[x],E=i[x+1],z=i[x+2];if(!mp(gp,a,o,l,h,c,u,w,b,S,M,T,A,C,E,z))continue;d=!0;const L=gp.position._distanceSqrTo(a,o,l);L<g&&(g=L,t.copy(gp))}return d}var vp=function(t,e){const i=new er(t,e);return(n=i).matrixAutoUpdate=!1,n.frustumCulled=!1,i;var n};const xp=new Rs,wp=new Ss,bp=[],Sp=[];class Mp{gridPosition=new Tu;scale=new Tu(1,1);size=new Tu;position=new Tu;resolution=new jd(1);material=null;mesh=vp(xp,wp);geometry=null;enableBVH=!0;external_bvh=new wu;bvh=null;isBuilt=!1;isBuildInProgress=!1;referenceCount=0;onBuilt=new y;onDestroyed=new y;stitching={top:!1,bottom:!1,left:!1,right:!1,topLeft:!1,topRight:!1,bottomLeft:!1,bottomRight:!1};__initial_height_range=new Hd(Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY);constructor(){this.mesh.name="TerrainTile",this.mesh.matrixWorldNeedsUpdate=!1}get transform(){return this.mesh.matrixWorld.elements}set transform(t){nd(t,0,this.mesh.matrixWorld.elements,0,16),this.computeBoundingBox()}raycastFirstSync(t,e,i,n,s,r,a){const o=this.transform;Y(Sp,o),dp(bp,e,i,n,s,r,a),up(bp,0,bp,0,Sp);const l=bp[0],h=bp[1],c=bp[2],u=bp[3],d=bp[4],p=bp[5],f=this.geometry,m=f.getIndex().array,_=f.getAttribute("position").array;let g=yp(t,this.bvh,_,0,3,m,l,h,c,u,d,p);return g&&(t.applyMatrix4(o),t.normal.normalize()),g}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 O,h=new O,c=new O,u=new O,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 Qi(e.x*i.x,s.min,e.y*i.y),a=new Qi(r.x+n.x*i.x,s.max,r.z+n.y*i.y);t=new nn(r,a)}else{const i=this.bvh;if(null!==i){const t=i.float32,n=t[0],s=t[1],r=t[2],a=t[3],o=t[4],l=t[5];e.boundingBox=new nn(new Qi(n,s,r),new Qi(a,o,l));const h=a-n,c=o-s,u=l-r,d=Math.sqrt(h*h+c*c+u*u)/2,p=new Qi(n+h/2,s+c/2,r+u/2);e.boundingSphere=new bn(p,d)}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 cp(i,n,s,r,a,o);l.applyMatrix4(this.transform),this.external_bvh.resize(l.x0,l.y0,l.z0,l.x1,l.y1,l.z1)}setInitialHeightBounds(t,e){this.__initial_height_range.set(t,e)}dispose(){this.isBuilt&&(null!==this.geometry&&(this.geometry.dispose(),this.geometry=null),this.isBuilt=!1,this.onDestroyed.send1(this))}build(t){this.isBuilt=!0;const e=t.geometry,i=new Rs;if(i.setIndex(new As(e.indices,1)),i.setAttribute("position",new As(e.vertices,3)),i.setAttribute("normal",new As(e.normals,3)),i.setAttribute("uv",new As(e.uvs,2)),this.geometry=i,this.enableBVH){const e=this.bvh=new ip,i=t.bvh;e.setLeafCount(i.leaf_count),e.data=i.data}const n=this.mesh;return n.geometry=i,n.receiveShadow=!0,n.castShadow=!0,this.computeBoundingBox(),n}}const Tp=[],Ap=new Su;class Cp{tiles=[];on={tileBuilt:new y,tileDestroyed:new y};tileSize=new Tu(10,10);totalSize=new Tu(1,1);resolution=new jd(4);scale=new Tu(1,1);__transform=new Float32Array(16);bvh=new Td;heightRange=new Hd(0,0);debugTileMaterialRandom=!1;constructor({material:t,buildWorker:e}){if(void 0===t){const e=function(t){const e=(new Ic).load("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wIZFDQQxd+nEAAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAH0lEQVQI12NkQAL///+Hs5kYcADSJRiRzWVkZKSFHQBYfwYMUOT4KAAAAABJRU5ErkJggg==");return e.magFilter=Qt,void 0!==t&&(e.wrapS=$t,e.wrapT=$t,e.repeat.copy(t)),e}(this.totalSize.clone()._sub(1,1).multiplyScalar(.5));t=new oc({map:e})}this.material=new qd(t),this.buildWorker=e,this.material.onChanged.add((()=>{this.traverse(this.assignTileMaterial,this)}))}set transform(t){e(t,this.__transform)||(J(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.external_bvh;i.bounds[1]=t,i.bounds[4]=e,i.write_bounds()}}}initialize(){this.destroyTiles(),this.initializeTiles()}assignTileMaterial(t){let e=this.material.getValue();if(this.debugTileMaterialRandom){const t=new Bd;t.setHSV(Math.random(),.6*(0,Math.random)()+.4,1),e=new oc({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(){const t=this.tiles,e=t.length;for(let i=0;i<e;i++){const e=t[i];e.external_bvh.unlink(),e.dispose()}t.splice(0,e),this.bvh.release_all()}rebuild(){this.destroyTiles(),this.initializeTiles()}rebuildTilesByUV(t,e,i,n){const s=this.totalSize,r=t*s.x,a=i*s.x,o=e*s.y,l=n*s.y,h=this.getRawTilesOverlappingRectangle(r-1,o-1,a+1,l+1),c=h.length;for(let t=0;t<c;t++)h[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;Wd(t,e,i,n,l,h,l+a.size.x,h+a.size.y)&&s.push(a)}return s}initializeTiles(){const t=this.totalSize,e=t.clone(),i=this.tileSize;e.divide(i),e.ceil();const n=this.tiles,s=this;function r(t,e){return function(i){s.obtain(t,e).then(i)}}for(let s=0;s<e.y;s++){const a=s<e.y-1?i.y:t.y-i.y*s;for(let o=0;o<e.x;o++){const l=o<e.x-1?i.x:t.x-i.x*o,h=new Mp,c=s*e.x+o;n[c]=h,this.assignTileMaterial(h),h.gridPosition.set(o,s),h.size.set(l,a),h.position.set(i.x*o,i.y*s),h.scale.copy(this.scale),h.resolution.copy(this.resolution),h.setInitialHeightBounds(this.heightRange.min,this.heightRange.max),h.computeBoundingBox(),h.ensureBuilt=r(o,s),h.external_bvh.link(this.bvh,c)}}}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 j(3);return n[0]=t,n[1]=0,n[2]=i,n}(t,0,e),n=q();return Y(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[0],i[1])}obtainTileAtWorldPosition2D(t,e){const i=this.getTileByWorldPosition2D(t,e);return this.obtain(i.gridPosition.x,i.gridPosition.y)}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,Ud,Ud),n}}release(t){t.referenceCount,t.referenceCount--,t.referenceCount<=0&&t.dispose()}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){const o=function(t,e,i,n,s,r,a,o,l,h){if(e===bd)return 0;const c=zd.pointer++;zd[c]=e;let u=0;const d=t.__data_float32,p=t.__data_uint32;do{zd.pointer--;const t=zd[zd.pointer],e=t*Sd;if(!Ed(d[e],d[e+1],d[e+2],d[e+3],d[e+4],d[e+5],s,r,a,o,l,h))continue;const n=p[e+7];n!==bd?(zd[zd.pointer++]=n,zd[zd.pointer++]=p[e+8]):i[u++]=t}while(zd.pointer>c);return u-0}(this.bvh,this.bvh.root,Tp,0,e,i,n,s,r,a);let l=Number.POSITIVE_INFINITY,h=!1;for(let c=0;c<o;c++){const o=Tp[c],u=this.bvh.node_get_user_data(o),d=this.tiles[u];if(!d.isBuilt)continue;if(!d.raycastFirstSync(Ap,e,i,n,s,r,a))continue;h=!0;const p=Ap.position._distanceSqrTo(e,i,n);p<l&&(l=p,t.copy(Ap))}return h}raycastVerticalFirstSync(t,e,i){return this.raycastFirstSync(t,e,-1e4,i,0,1,0)}build(t,e,i,n){const s=this.computeTileIndex(t,e),r=this.tiles[s];r.isBuilt=!1,r.isBuildInProgress=!0;const a=r.resolution.getValue();this.buildWorker.buildTile(r.position.toJSON(),r.size.toJSON(),r.scale.toJSON(),this.totalSize.toJSON(),a).then((i=>{this.tiles[s]===r?r.isBuildInProgress?(r.build(i),this.stitchTile(t,e,r),r.external_bvh.write_bounds(),r.isBuilt=!0,r.isBuildInProgress=!1,r.onBuilt.send1(r),this.on.tileBuilt.send1(r)):n("Build request has been cancelled"):n("Original tile was destroyed during build process")}),n)}}const Ep=function(){return{uniforms:{normalMap:{type:"t",value:null},heightMap:{type:"t",value:null},world_size:{type:"v2",value:new Vi(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")}},zp=new Rs;zp.setAttribute("position",new As(new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),3)),zp.setAttribute("uv",new As(new Float32Array([0,0,2,0,0,2]),2));const Lp=" \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 Ip(t,e,i,n,s){void 0===s&&(s=new Uint8Array(e*i*4)),t.setSize(e,i);const r=new Pr(-1,1,1,-1,0,1),a=new fl;a.add(r);const o=new or(Object.assign({vertexShader:Lp},n));o.lights=!1,o.fog=!1,o.uniformsNeedUpdate=!0,o.needsUpdate=!0,o.side=st;const l=new er(zp,o);a.add(l);const h=new $i(e,i,{generateMipmaps:!1,minFilter:ie,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 Np(t){switch(t){case 1:return Me;case 2:return Ae;case 3:return ye;case 4:return ve;default:throw new Error(`Unsupported channel count '${t}'`)}}function Pp(t,e){let i="";switch(t){case qu.Uint8:i="8UI";break;case qu.Uint16:i="16UI";break;case qu.Uint32:i="32UI";break;case qu.Int8:i="8I";break;case qu.Int16:i="16I";break;case qu.Int32:i="32I";break;case qu.Float16:i="16F";break;case qu.Float32:i="32F";break;case qu.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 Dp(t){const e=t.width,i=t.height,n=new Bl(t.data,e,i);return n.wrapS=Zt,n.wrapT=Zt,n.generateMipmaps=!1,n.minFilter=ie,n.magFilter=Qt,n.flipY=!1,n.type=ue,n.format=Np(t.itemSize),n.internalFormat=Pp(qu.Float32,t.itemSize),n.needsUpdate=!0,n}const Op=15,Fp=`\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 ${Op}\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 Rp(t,e){return.39894*Math.exp(-.5*t*t/(e*e))/e}function kp(t=10,e=.2){const i=1/Rp(0,e),n=new Float32Array(Op),s=Math.floor((Op-1)/2);for(let e=0;e<=s;e++){const i=Rp(e,t);n[s+e]=i,n[s-e]=i}return{uniforms:{source:{type:"t",value:null},pixelOffset:{type:"v2",value:new Vi(1,1)},sigmas:{type:"v2",value:new Vi(t,t)},bZnorm:{type:"f",value:i},kernel:{type:"f",value:n}},fragmentShader:Fp}}const Bp=function(){return{uniforms:{heightMap:{type:"t",value:null},resolution:{type:"v2",value:new Vi(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 Up(t){return t/255-.5}class Vp{used=new Set;get(t){const e=document.createElement("canvas"),i=new pl({alpha:!0,context:e.getContext("webgl2",{antialias:!0}),canvas:e});return this.used.add(i),i}release(t){return!!this.used.has(t)&&(this.used.delete(t),t.forceContextLoss(),t.dispose(),t.domElement=null,!0)}static global=new Vp}function Wp(t,e){if(1===t.itemSize){if(e.format!==Me&&e.format!==xe)throw new Error("itemSize is 1 and texture.format is not RedFormat")}else if(2===t.itemSize){if(e.format!==Ae)throw new Error("itemSize is 2 and texture.format is not RGFormat")}else if(3===t.itemSize){if(e.format!==ye)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!==ve)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}function Gp(t,e){return t.equals(e)}function Hp(t){return t.hash()}function jp(t,e,i){const n=t[e];t[e]=t[i],t[i]=n}function qp(t,e){return(t<<2)+t+1&e}class Jp{constructor(t,e,i){this.key=t,this.value=e,this.hash=i}}const Yp=4294967295;function Xp(t,e,i,n){return t.hash===e&&(t.key===i||n(t.key,i))}const $p=new Uint32Array(0);class Zp{#r=$p;#a=new Array(0);#o=0;#l=0;#h=0;#c=0;#u=0;#d=0;#p=0;#f=0;#m=.75;#_=0;constructor({keyHashFunction:t=Hp,keyEqualityFunction:e=Gp,capacity:i=16,loadFactor:n=.75}={}){this.keyHashFunction=t,this.keyEqualityFunction=e,this.#m=n,this.#g(Jd(i))}get size(){return this.#h}getCurrentLoad(){return this.#h/this.#c}#g(t){if(t<this.#h)throw new Error(`count must be at least equal to must of records in the map (=${this.#h}), instead was ${t}`);this.#p=function(t){let e=0;return 0==(65535&t)&&(t>>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&(t>>=1,e+=1),0===t&&(e+=1),e}(t),this.#d=this.#p+1,this.#c=2**this.#d,this.#f=this.#c-1,this.#u=2**this.#p;const e=function(t){if(t<=256)return Uint8Array;if(t<=65536)return Uint16Array;if(t<=4294967295)return Uint32Array;throw new Error(`Unsupported size ${t}`)}(this.#u+2);this.#r=new e(this.#c);const i=new Array(this.#u),n=this.#a;this.#a=i,nd(n,0,i,0,C(n.length,this.#u)),this.#h>0&&this.rebuild()}#y(t){return(t>>>16^t)>>>0&this.#f}#v(t){const e=this.keyHashFunction(t);return e===Yp?0:e}#x(t,e,i){const n=this.#o;if(this.#o++,void 0!==this.#a[n]){const s=this.#a[n];s.hash=i,s.key=t,s.value=e}else this.#a[n]=new Jp(t,e,i);return n}#w(t){t.key=null,t.value=null,t.hash=Yp}#b(){this.#o===this.#u&&(this.#h===this.#u?this.#S():this.rebuild())}set(t,e){this.#b();const i=this.#v(t);let n=this.#y(i),s=-1;for(;;){const r=this.#r[n];if(r>1){const n=this.#a[r-2];if(Xp(n,i,t,this.keyEqualityFunction))return void(n.value=e)}else{if(0===r){-1!==s&&(n=s);const r=this.#x(t,e,i);this.#r[n]=r+2;break}-1===s&&(s=n)}n=qp(n,this.#f)}const r=this.#h+1;this.#h=r,r/this.#c>this.#m&&this.#S()}get(t){const e=this.#v(t);let i=this.#y(e);for(;;){const n=this.#r[i];if(n>1){const i=this.#a[n-2];if(Xp(i,e,t,this.keyEqualityFunction))return i.value}else if(0===n)return;i=qp(i,this.#f)}}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)}#M(t){if(this.#l===t){let e=t+1,i=this.#o;const n=this.#a;for(;e<i&&n[e].hash===Yp;)e++;this.#l=e}}delete(t){const e=this.#v(t);let i=this.#y(e);const n=this.#r,s=this.#a;for(;;){const r=n[i];if(r>1){const a=r-2,o=s[a];if(Xp(o,e,t,this.keyEqualityFunction))return this.#w(o),n[i]=1,this.#h--,this.#M(a),!0}else if(0===r)return!1;i=qp(i,this.#f)}}verifyHashes(t,e){let i=!0;const n=this.#c;for(let s=0;s<n;s++){const n=this.#r[s];if(n<=1)continue;const r=this.#a[n-2],a=this.#v(r.key);r.hash!==a&&(t.call(e,`Hash stored on the entry(=${r.hash}) is different from the computed key hash(=${a}).`,r.key,r.value),i=!1)}return i}#S(){this.#g(2*this.#u)}rebuild(){const t=this.#o,e=this.#a,i=this.#r;i.fill(0);let n=0;for(let s=this.#l;s<t;s++){const t=e[s].hash;if(t===Yp)continue;const r=n;n++,r!==s&&jp(e,r,s);let a=this.#y(t);for(;;){if(0===i[a]){i[a]=r+2;break}a=qp(a,this.#f)}}this.#l=0,this.#o=this.#h,this.#_++}#T(){let t=0;for(let e=this.#l;e<this.#o;e++)this.#a[e].hash!==Yp&&t++;return t}forEach(t,e){const i=this.#c,n=this.#a,s=this.#r;this.#_;for(let r=0;r<i;r++){const i=s[r];if(i<=1)continue;const a=n[i-2];t.call(e,a.value,a.key,this)}}has(t){return void 0!==this.get(t)}clear(){const t=this.#r,e=this.#c;for(let i=0;i<e;i++){const e=t[i];if(0!==e){if(1!==e){const t=e-2;this.#w(this.#a[t])}t[i]=0}}this.#h=0,this.#l=0,this.#o=0}*[Symbol.iterator](){const t=this.#c,e=this.#r,i=this.#a;this.#_;for(let n=0;n<t;n++){const t=e[n];if(t<=1)continue;const s=i[t-2];yield[s.key,s.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[1]}}}}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[0]}}}}}function Kp(){return 1}function Qp(){return 0}function tf(t,e){return t===e}class ef{constructor(){this.key=null,this.value=null,this.weight=0,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 nf{constructor({maxWeight:t=Number.POSITIVE_INFINITY,keyWeigher:e=Qp,valueWeigher:i=Kp,keyHashFunction:n=Qp,keyEqualityFunction:s=tf,capacity:r}={}){this.maxWeight=t,this.weight=0,this.keyWeigher=e,this.valueWeigher=i,this.__first=null,this.__last=null,this.data=new Zp({keyHashFunction:n,keyEqualityFunction:s,capacity:r}),this.onEvicted=new y,this.onRemoved=new y,this.onSet=new y}__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){const n=this.computeElementWeight(e,i.value);i.weight=n,t+=n}this.weight=t}updateElementWeight(t){const e=this.data.get(t);if(void 0===e)return!1;const i=e.weight,n=this.computeElementWeight(t,e.value);if(n===i)return!0;e.weight=n;const s=n-i;return this.weight+=s,this.weight>this.maxWeight&&n<=this.maxWeight&&this.evictUntilWeight(this.maxWeight),!0}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 ef,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);i.weight=n;const 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)}contains(t){return this.data.has(t)}get(t){const e=this.data.get(t);return void 0===e?null:(this.__promote(e),e.value)}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}__removeElement(t){t.value,t===this.__first&&(this.__first=t.next),t===this.__last&&(this.__last=t.previous),t.unlink();const e=t.key;this.data.delete(e),this.weight-=t.weight}remove(t){const e=this.data.get(t);return void 0!==e&&(this.__removeElement(e),this.onRemoved.send2(t,e.value),!0)}silentRemove(t){const e=this.data.get(t);return void 0!==e&&(this.__removeElement(e),!0)}clear(){const t=[];!function(t,e){for(let i=e.next();!i.done;i=e.next())t.push(i.value)}(t,this.data.keys());const 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}validate(t,e){return this.data.verifyHashes(((i,n,s)=>{t.call(e,i,n,s.value)}))}}function sf(t,e){return t===e||"object"==typeof t&&"function"==typeof t.equals&&t.equals(e)}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=tf){const n=t.slice(),s=e.slice(),r=[];let a=n.length;for(let t=0;t<a;t++){const e=n[t],o=rf(s,e,i);-1!==o&&(r.push(e),n.splice(t,1),s.splice(o,1),t--,a--)}return{uniqueA:n,uniqueB:s,common:r}}nf.prototype.set=nf.prototype.put,nf.prototype.delete=nf.prototype.remove,nf.prototype.has=nf.prototype.contains;class of{on={added:new y,removed:new y};constructor(t){this.data=void 0!==t?t.slice():[],this.length=this.data.length}get(t){return this.data[t]}set(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)}add(t){this.data.push(t);const e=this.length;return this.length=e+1,this.on.added.send2(t,e),this}addUnique(t){return!this.contains(t)&&(this.add(t),!0)}insert(t,e){return t>this.length&&(this.length=t),this.data.splice(t,0,e),this.length++,this.on.added.send2(e,t),this}crop(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}patch(t){const e=af(this.data,t,sf),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(((e,i)=>{const n=t.indexOf(e);return t.indexOf(i)-n}));const r=s.length;for(let e=0;e<r;e++){const i=s[e];let n=0;for(let e=t.indexOf(i)-1;e>=0;e--){const i=t[e],s=this.indexOf(i);if(-1!==s){n=s+1;break}}this.insert(n,i)}}addAll(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}addAllUnique(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)}removeMany(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}remove(t){const e=this.data.splice(t,1);this.length--;const i=e[0];return this.on.removed.send2(i,t),i}removeAll(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(sf(a[n],i)){this.remove(n),s--;continue t}r++}return 0===r}removeOneOf(t){return"object"==typeof t&&"function"==typeof t.equals?this.removeOneIf(lf,t):this.removeOneIf(hf,t)}sort(){return Array.prototype.sort.apply(this.data,arguments),this}clone(){return new of(this.data)}some(t){const e=this.length,i=this.data;for(let n=0;n<e;n++)if(t(i[n]))return!0;return!1}removeIf(t,e){let i=this.length;const n=this.data;for(let s=0;s<i;s++){const r=n[s];t.call(e,r)&&(this.remove(s),s--,i--)}}removeOneIf(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}forEach(t,e){const i=this.length,n=this.data;for(let s=0;s<i;s++)t.call(e,n[s],s)}reduce(t,e){let i=e;return this.forEach((function(e){i=t(i,e)})),i}filter(t){return this.data.filter(t)}find(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}}findIndex(t){const e=this.data;let i=0;const n=this.length;for(;i<n;i++)if(t(e[i]))return i;return-1}visitFirstMatch(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)}}contains(t){return-1!==this.data.indexOf(t)}containsAny(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];if(this.contains(e))return!0}return!1}isEmpty(){return this.length<=0}indexOf(t){return this.data.indexOf(t)}map(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}resetViaCallback(t,e){const i=this.length,n=this.on.removed,s=this.data;for(let r=i-1;r>=0;r--){const i=s[r];s.length=r,this.length=r,n.send2(i,r),t.call(e,i,r)}}reset(){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}}deepCopy(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,Gp);-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)}copy(t){this!==t&&(this.reset(),t.length>0&&(t instanceof of?this.addAll(t.data):this.addAll(t)))}asArray(){return this.data}toJSON(){return JSON.parse(JSON.stringify(this.data))}fromJSON(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)}toBinaryBuffer(t){const e=this.length;t.writeUint32(e);for(let i=0;i<e;i++){const e=this.data[i];if("function"!=typeof e.toBinaryBuffer)throw new Error("item.toBinaryBuffer is not a function");e.toBinaryBuffer(t)}}fromBinaryBuffer(t,e){this.fromBinaryBufferViaFactory(t,(function(t){const i=new e;if("function"!=typeof i.fromBinaryBuffer)throw new Error("item.fromBinaryBuffer is not a function");return i.fromBinaryBuffer(t),i}))}fromBinaryBufferViaFactory(t,e){this.reset(),this.addFromBinaryBufferViaFactory(t,e)}addFromBinaryBufferViaFactory(t,e){const i=t.readUint32();for(let n=0;n<i;n++){const i=e(t);this.add(i)}}addFromJSONViaFactory(t,e){const i=t.length;for(let n=0;n<i;n++){const i=e(t[n]);this.add(i)}}hash(){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}first(){return this.get(0)}last(){return this.get(this.length-1)}equals(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}compare(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}}function lf(t){return this===t||this.equals(t)}function hf(t){return this===t}function cf(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}const uf=new nf({maxWeight:304857600,keyHashFunction:ld,keyWeigher:cf,valueWeigher:t=>t.computeByteSize()});class df{textureDiffuseURL="";diffuse=Qu.uint8(3,1,1);size=new Tu(1,1);extra={};onChanged=new y;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 df;return n.textureDiffuseURL=t,n.size.set(e,i),n}static fromDescription(t){return df.from(t.diffuse,t.size.x,t.size.y)}loadTextureData(t){const e=this.textureDiffuseURL,i=uf.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,Nu).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=Qu.uint8(3,i.width,i.height)),function(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=0,l=0;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){const t=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);for(o=0;o<s;o++){const e=3*o,i=4*o;r[i]=a[e],r[i+1]=a[e+1],r[i+2]=a[e+2],r[i+3]=t}}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++}(new Qu(s,n,i.width,i.height),this.diffuse),this.onChanged.send0();const r=Qu.uint8(3,i.width,i.height);r.data.set(this.diffuse.data),uf.put(e,r)}))}}df.prototype.isTerrainLayer=!0;class pf{uri="";size=new Tu;static from(t,e){const i=new pf;return i.uri=t,i.size.copy(e),i}hash(){return ld(this.uri)^this.size.hash()}equals(t){return this.uri===t.uri&&this.size.equals(t.size)}}const ff=new nf({maxWeight:104857600,keyEqualityFunction:Gp,keyHashFunction:Hp,valueWeigher:t=>t.computeByteSize()});class mf{constructor(){this.layers=new of,this.resolution=new Tu(512,512),this.texture=new ra(new Uint8Array(3),1,1,1),this.texture.format=ye,this.texture.type=re,this.texture.wrapS=$t,this.texture.wrapT=$t,this.texture.anisotropy=8,this.texture.magFilter=ie,this.texture.minFilter=1008,this.texture.generateMipmaps=!0,this.texture.encoding=bi,this.texture.internalFormat="RGB8",this.scalesTexture=new Bl(new Float32Array(64),32,1,Ae,ue),this.scalesTexture.wrapS=Zt,this.scalesTexture.wrapT=Zt,this.scalesTexture.minFilter=ie,this.scalesTexture.magFilter=Qt,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,df)}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=pf.from(t.textureDiffuseURL,e),a=ff.get(r);if(null!==a)return a;const o=Qu.uint8(3,n,s);return ud(i,o),ff.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&&xd(e.data,r),e.data=r,e.width=i,e.height=n,e.depth=s,t.needsUpdate=!0}}const _f=/[a-zA-Z0-9_\-]+\:\/\//,gf="object"==typeof window,yf="object"==typeof process&&!gf,vf="function"==typeof importScripts;class xf{constructor(t,e){this.text=t,this.indentation=e}}class wf{lines=[];indentation=0;indentSpaces=4;get count(){return this.lines.length}containsSubstring(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}indent(){return this.indentation++,this}dedent(){return this.indentation--,this}add(t){const e=new xf(t,this.indentation);return this.lines.push(e),this}addLines(t){const e=t.lines,i=e.length;for(let t=0;t<i;t++){const i=e[t],n=new xf(i.text,i.indentation+this.indentation);this.lines.push(n)}}clear(){this.lines=[],this.indentation=0}build(){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")}static fromText(t){const e=new wf,i=t.split("\n"),n=i.length;for(let t=0;t<n;t++)e.add(i[t]);return e}}function bf(t,e){try{return t.postMessage(e),!0}catch(t){return!1}}class Sf{__pending={};__isRunning=!1;__worker=null;__id_counter=0;constructor(t,e){this.url=t,this.methods=e,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(!bf(this.__worker,e)){const t=i.indexOf(r);i.splice(t,1)}}}))}__makeMethod(t){if(this.__pending.hasOwnProperty(t))throw new Error(`Method '${t}' already defined`);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};bf(this.__worker,s)}}}start(){this.__isRunning||(this.__worker=new Worker(this.url),this.__worker.onmessage=this.__handleMessage,this.__worker.onerror=t=>{},this.__isRunning=!0,this.sendPendingRequests())}}const Mf=/(function\s*)([a-zA-Z0-9_]+)?(\s*\([^\]]*\)\s*\{.*)/g;class Tf{imports=[];methods={};functions=[];preamble=new wf;addCode(t){this.preamble.add(t)}addMethod(t,e){this.methods[t]=e}importFunction(t,e){this.functions.push({f:e,name:t})}importScript(t){t=function(t){if(!function(t){return 0===t.search(_f)}(t)){let e;if(gf)e=window;else if(vf)e=self;else{if(!yf)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)}build(){const t=[];t.push("var globalScope = this;"),this.imports.forEach((function(e){t.push("globalScope.importScripts('"+e+"');")})),t.push(this.preamble.build()),this.functions.forEach((function(e){const i=e.f.toString().replace(Mf,`$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 Sf(e,this.methods)}}class Af{constructor(){this.offset_x=0,this.offset_y=0,this.scale_x=1,this.scale_y=1}}function Cf(t,e){return-1===t.indexOf(e)&&(t.push(e),!0)}const Ef={INITIAL:0,READY:1,RUNNING:2,FAILED:3,SUCCEEDED:4,CANCELLED:5};let zf=0;class Lf{id=zf++;on={started:new y,completed:new y,failed:new y};state=new jd(Ef.INITIAL);__executedCpuTime=0;__executedCycleCount=0;constructor({name:t="Unnamed",initializer:e=Ud,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)}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");Cf(this.dependencies,t)}return this}addDependencies(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.addDependency(e)}}toString(){return`Task{name:'${this.name}'}`}join(t,e){Lf.join(this,t,e)}executeSync(){this.initialize(),this.on.started.send0();let t=this.cycle();for(;0!==t&&1!==t;t=this.cycle());return 0===t?this.on.completed.send0():1===t&&this.on.failed.send0(),t}promise(){return Lf.promise(this)}static promiseAll(t){const e=t.map(Lf.promise);return Promise.all(e)}static promise(t){return new Promise(((e,i)=>Lf.join(t,e,i)))}static join(t,e,i){const n=t.state.getValue();n===Ef.SUCCEEDED?e():n===Ef.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)}}Lf.prototype.isTask=!0;class If{constructor(){this.size=new Tu(1,1),this.depth=1;const t=this.size,e=t.x,i=t.y;this.weightTexture=new ra(new Uint8Array(e*i),e,i,1),this.weightTexture.generateMipmaps=!1,this.weightTexture.format=Me,this.weightTexture.type=re,this.weightTexture.magFilter=ie,this.weightTexture.minFilter=Qt,this.materialTexture=new Bl(new Uint8Array(e*i*4),e,i)}toJSON(){const t=ju.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=ju.decode(i);n=new Uint8Array(t)}else{if(!Array.isArray(i))throw new Error("Unsupported data format");n=i}nd(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=Mu(0,C(o-e,n)),u=Mu(0,C(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=Mu(0,C(a-e,n)),u=Mu(0,C(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 Qu(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 Qu(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 Lf({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?0:((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++,2)},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,n=!0){const s=this.size.x,r=this.size.y,a=this.depth;this.depth=i,t===s&&e===r&&i===a||this.size.set(t,e);const o=this.weightTexture,l=o.image;if(l.width!==t||l.height!==e||l.depth!==i){o.dispose();const h=l.data,c=s*r,u=t*e;if(l.width=t,l.height=e,l.depth=i,l.data=new Uint8Array(u*i),n)if(s===t&&r===e)xd(h,l.data);else for(let n=0;n<C(i,a);n++)ud(new Qu(h.subarray(n*c,(n+1)*c),1,s,r),new Qu(l.data.subarray(n*u,(n+1)*u),1,t,e));o.needsUpdate=!0}}}let Nf=0;class Pf{id=Nf++;flags=0;gridScale=1;gridTransform=new Af;gridTransformKind=1;resolution=4;size=new Tu(0,0);preview=new vd;splat=new If;layers=new mf;__buildWorker=function(){const t=new Tf;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=Lib.sampler2d_channel_compute_min(e),n=Lib.sampler2d_channel_compute_max(e);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.build_bvh(a.vertices,a.indices);r({geometry:a,bvh:{leaf_count:l.leaf_node_count,data:l.data}})}catch(t){a(t)}}))}))})),t.build()}();bvh=new wu;constructor(){this.clouds=new yd,this.clouds.enabled=!0,this.heightRange=0,this.samplerHeight=Qu.float32(1,1,1),this.heightTexture=new Bl(this.samplerHeight.data,this.samplerHeight.width,this.samplerHeight,Me,ue),this.heightTexture.wrapS=Zt,this.heightTexture.wrapT=Zt,this.heightTexture.generateMipmaps=!1,this.heightTexture.minFilter=ie,this.heightTexture.magFilter=Qt,this.heightTexture.flipY=!1,this.heightTexture.internalFormat="R32F",this.material=new Bu({}),this.frustumCulled=!0,this.__transform_matrix=q(),this.overlay=new md(this.size),this.__tiles=new Cp({material:this.material,buildWorker:this.__buildWorker}),this.__tiles.tileSize.set(Df,Df),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.bvh.unlink(),this.clearFlag(2)}dispose(){if(this.getFlag(2))throw new bu("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,Lu);if(t!==this.overlay.tileImage.getValue())return;const n=i.create();n.minFilter=ie,n.magFilter=ie,n.generateMipmaps=!1,this.material.uniforms.diffuseGridOverlaySprite.value=n}update(t){this.clouds.update(t)}sampleHeight(t,e,i,n,s){const r=new Su;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){J(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){throw new Error("Deprecated, no longer supported")}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)}buildNonVisual(){this.buildGridTransform(),this.bvh.resize(0,0,0,0,0,0),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),this.updateHeightTexture(),this.updateWorkerHeights()}build(t){this.getFlag(1)||(this.__assetManager=t,this.buildNonVisual(),this.layers.buildTexture(),this.layers.loadTextureData(t),null!==this.lightMapURL&&(this.material.aoMap=!0,this.material.needsUpdate=!0,t.promise(this.lightMapURL,Lu).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=S(e,16,2048),s=S(i,16,2048),r=new Uint8Array(n*s),a=new Bl(r,n,s,Me,re);return a.wrapT=Zt,a.wrapS=Zt,a.minFilter=Qt,a.magFilter=ie,a.flipY=!1,a.anisotropy=4,function({texture:t,heightSampler:e,resolution:i=new Tu(t.image.width,t.image.height),rayLength:n=11,worldSize:s=i}){const r=Vp.global.get(),a=function(t,e){const i=function(t,e){const i=e.width,n=e.height,s=Dp(e),r=new Bp;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=Up(t[i]),o=Up(t[i+1]),l=Up(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}(Ip(t,i,n,r).array);return new Qu(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 Vi(e.width,e.width),r=17){const a=n.x,o=n.y,l=Dp(i),h=Dp(e),c=new Ep;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=Ip(t,a,o,c),d=new kp(2);d.uniforms.source.value=function(t,e,i){const n=new Bl;return n.format=ve,n.type=re,n.flipY=!1,n.image={data:t,width:e,height:i},n.wrapS=Zt,n.wrapT=Zt,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=Ip(t,a,o,d),f=new Qu(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=>{Wp(e,t)}));return Promise.all([a,o]).finally((()=>{Vp.global.release(r)})),l}({texture:a,heightSampler:this.samplerHeight,worldSize:new Tu(e*this.gridScale,i*this.gridScale),resolution:new Tu(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:td,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}}}Pf.typeName="Terrain";const Df=7;function Of(t,e){const i=t.length;for(let n=0;n<i;n++){const i=t[n],s=4*n,r=i.normal;e[s]=r.x,e[s+1]=r.y,e[s+2]=r.z,e[s+3]=i.constant}}function Ff(t,e,i,n,s,r){const a=3*n,o=3*s,l=3*r,h=i[a],c=i[a+1],u=i[a+2],d=i[o],p=i[o+1],f=i[o+2],m=i[l],_=i[l+1],g=i[l+2],y=Od(h,d,m),v=Od(c,p,_),x=Od(u,f,g),w=Kd(h,d,m),b=Kd(c,p,_),S=Kd(u,f,g);t.setLeafData(e,e,y,v,x,w,b,S)}function Rf(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 As(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}function kf(t,e,i,n,s){return ap(t[e+0],t[e+1],t[e+2],t[e+3],t[e+4],t[e+5],i,n,s)}const Bf=Ad;function Uf(t,e,i,n,s,r,a,o,l,h,c,u,d){let p=0;return p+=L(t,e,i,s,r,a)>=n?1:-1,p+=L(t,e,i,o,l,h)>=n?1:-1,p+=L(t,e,i,c,u,d)>=n?1:-1,p}function Vf(t,e,i,n,s,r,a,o,l,h,c,u){for(let d=0;d<i;d++){const i=e+4*d;if(-3===Uf(t[i],t[i+1],t[i+2],t[i+3],n,s,r,a,o,l,h,c,u))return!1}return!0}const Wf=[],Gf=[];class Hf{constructor(t=104857600){this.cache=new nf({maxWeight:t,keyHashFunction:t=>t.id,keyEqualityFunction:(t,e)=>t.id===e.id&&t.uuid===e.uuid,valueWeigher:t=>t.estimateByteSize()})}set cache_size(t){this.cache.setMaxWeight(t)}get cache_size(){return this.cache.maxWeight}queryContainmentViaClippingPlanes(t,e){const i=this.__acquireBVH(t);Of(e,Gf);const n=t.getIndex()?.array,s=t.getAttribute("position");let r,a=3,o=0;return s.isInterleavedBufferAttribute?(r=s.data.array,a=s.data.stride,o=s.offset):(r=s.array,a=3,o=0),function(t,e,i,n,s,r,a,o){const l=function(t,e,i,n,s,r){let a=0;const o=i.binary_node_count;if(o<=0)return 0;const l=Bf.pointer++;Bf[l]=0;const h=o+i.leaf_node_count,c=i.float32,u=i.uint32;do{Bf.pointer--;const e=Bf[Bf.pointer],s=i.getNodeAddress(e);if(kf(c,s,n,0,r))if(e<o){const t=1+(e<<1),i=t+1;i<h?(Bf[Bf.pointer++]=i,Bf[Bf.pointer++]=t):t<h&&(Bf[Bf.pointer++]=t)}else t[0+a]=u[s+6],a++}while(Bf.pointer>l);return a}(Wf,0,t,r,0,o);let h,c,u;for(let t=0;t<l;t++){const a=3*Wf[t];void 0!==s?(h=s[a],c=s[a+1],u=s[a+2]):(h=a,c=a+1,u=a+2);const l=h*n+i,d=c*n+i,p=u*n+i;if(Vf(r,0,o,e[l],e[l+1],e[l+2],e[d],e[d+1],e[d+2],e[p],e[p+1],e[p+2]))return!0}return!1}(i,r,o,a,n,Gf,0,e.length)}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}const h=e.getIndex()?.array,c=e.getAttribute("position");let u,d=3,p=0;return c.isInterleavedBufferAttribute?(u=c.data.array,d=c.data.stride,p=c.offset):(u=c.array,d=3,p=0),yp(t,l,u,p,d,h,i,n,s,r,a,o)}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=Rf(e).array,s=new ip;return null==i?function(t,e){const i=indices.length/3;t.setLeafCount(i),t.initialize_structure();for(let n=0;n<i;n++){const i=3*n;Ff(t,n,e,i,i+1,i+2)}t.build()}(s,n):function(t,e,i){const n=i.length/3;t.setLeafCount(n),t.initialize_structure();for(let s=0;s<n;s++){const n=3*s;Ff(t,s,e,i[n],i[n+1],i[n+2])}t.build()}(s,n,Rf(i).array),s}}Hf.INSTANCE=new Hf;const jf=new Float32Array(6),qf=new Float32Array(16),Jf=new Float32Array(6);class Yf{constructor(){this.geometry=null,this.material=null,this.depth_material=null,this.__bvh_leaf=new wu,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 Yf;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_leaf.bounds;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 Yf;return n.from(t,e,i),n}updateTransform(){this.update_bounds(),this.__bvh_leaf.write_bounds()}update_bounds(){!function(t,e){const i=e.boundingBox;!function(t,e,i){e.x,e.y,e.z,i.x,i.y,i.z,t[0]=e.x,t[1]=e.y,t[2]=e.z,t[3]=i.x,t[4]=i.y,t[5]=i.z}(t,i.min,i.max)}(jf,this.geometry),hp(this.__bvh_leaf.bounds,jf,this.transform)}query_raycast_nearest(t,e,i){return Y(qf,i),!!up(Jf,0,e,0,qf)&&!!Hf.INSTANCE.queryRaycastNearest_array(t,this.geometry,Jf)&&(t.applyMatrix4(i),!0)}}Yf.typeName="ShadedGeometry",Yf.serializable=!1;const Xf=new cp;function $f(t,e){const i=e.entity.getComponent(Yf);null!==i&&(i.getBoundingBox(Xf),t.expandToFit(Xf));const n=e.children,s=n.length;for(let e=0;e<s;e++)$f(t,n[e])}function Zf(t,e){t.setNegativelyInfiniteBounds(),$f(t,e)}class Kf{#A=null;flags=3;__url=null;__node=null;__initial_bounds=new cp;get node(){return this.__node}equals(t){return null!=t&&this.__url===t.__url&&this.flags===t.flags&&this.materialOverride===t.materialOverride}hash(){return ld(this.__url)}copy(t){this.__url=t.__url,this.__node=null,this.__initial_bounds.copy(t.__initial_bounds),this.#A=t.#A}clone(){const t=new Kf;return t.copy(this),t}set materialOverride(t){if(t!==this.#A){if(null===t)throw new Error("Once material override is set it can not be cleared, create a new SGMesh instance if you would like to clear override");this.#A=t,this.applyMaterialOverride()}}get materialOverride(){return this.#A}applyMaterialOverride(){null!==this.__node&&this.__node.traverse((t=>{const e=t.entity.getComponent(Yf);null!==e&&(e.material=this.#A)}))}get url(){return this.__url}set url(t){t!==this.__url&&(this.__url=t)}getBoundingBox(t){return null!==this.__node&&(Zf(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 Kf;return e.url=t,e.castShadow=!0,e.receiveShadow=!0,e}}function Qf(t,e){return op(t[0],t[1],t[2],t[3],t[4],t[5],e)}Kf.typeName="SGMesh";const tm=Ad;function em(t,e,i,n){if(n===bd)return 0;const s=tm.pointer++;tm[s]=n;let r=e;for(;tm.pointer>s;){tm.pointer--;const e=tm[tm.pointer];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);tm[tm.pointer++]=t,tm[tm.pointer++]=n}}return r-e}const im=Ad,nm=new Float32Array(6);function sm(t,e,i,n){const s=i.root;if(s===bd)return 0;const r=im.pointer++;im[r]=s;let a=e;for(;im.pointer>r;){im.pointer--;const e=im[im.pointer];i.node_get_aabb(e,nm);const s=Qf(nm,n);if(0!==s)if(i.node_is_leaf(e))t[a++]=i.node_get_user_data(e);else if(2===s)a+=em(t,a,i,e);else{const t=i.node_get_child1(e),n=i.node_get_child2(e);im[im.pointer++]=t,im[im.pointer++]=n}}return a-e}const rm={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 am{constructor(t,e=0){this.factory=t,this.byteSize=e,this.dependencies=[],this.description=null}equals(t){return this===t||this.description===t.description||this.description.equals(t.description)}hash(){return this.description.hash()}create(){return this.factory()}}am.prototype.byteSize=0;class om{constructor(){this.kind="anonymous"}}const lm=new om;om.default=Object.freeze(lm);class hm{assetManager=null;context=null;async link(t,e){this.assetManager=t,this.context=e}async unlink(){}load(t,e,i,n,s){n("Not Implemented")}}class cm extends hm{constructor({fetch_priority:t="auto"}={}){super(),this.__fetch_priority=t}load(t,e,i,n=console.error,s=Ud){const r=null!==this.assetManager?this.assetManager.crossOriginConfig:om.default,a=new Headers,o=new Request(e,{credentials:"use-credentials"===r.kind?"include":"same-origin",headers:a});void 0!==o.priority&&(o.priority=this.__fetch_priority),fetch(o).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(),i=t.headers.get("Content-Length"),n=i?parseInt(i):0;let r=0;const a=new ReadableStream({type:"bytes",start(t){!function i(){e.read().then((({done:e,value:a})=>{e?t.close():(r+=a.byteLength,s(r,n),t.enqueue(a),i())}))}()}});return new Response(a)})).then((async function(t){const e=await t.arrayBuffer(),n=new am((function(){return e}),e.byteSize);i(n)})).catch(n)}}class um{async decode(t){throw new Error("Unsupported Operation")}async test(t){return!0}}class dm extends um{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 pm extends um{async decode(t){const e=new Image,i=new Blob([t]),n=URL.createObjectURL(i);e.src=n,await e.decode();const s=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),r=e.width,a=e.height;return URL.revokeObjectURL(n),{data:s,width:r,height:a,itemSize:4,bitDepth:8}}}class fm{__request_count=0;__timeout=1e3;__pending_termination=-1;constructor(t){this.worker=t}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 mm=[137,80,78,71,13,10,26,10];class _m extends um{constructor(){super();const t=new Tf;t.importScript("bundle-worker-image-decoder.js"),t.addMethod("decode",(function(t,e){return Lib.decode(t,e)})),this.worker=new fm(t.build()),this.worker.setTimeout(1200)}async test(t){for(let e=0;e<mm.length;e++)if(t[e]!==mm[e])return!1;return!0}decode(t){return this.worker.request("decode",[t.buffer])}}class gm extends am{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 Qu(this.data,this.itemSize,this.width,this.height)}}const ym="arraybuffer";class vm extends hm{constructor(){super(),this.decoder=new dm(new _m,new pm)}async link(t,e){void 0===t.getLoaderByType(ym)&&await t.registerLoader(ym,new cm),await super.link(t,e)}async __decode_via_worker(t,e){const i=(await this.assetManager.promise(t,ym,{scope:e})).create();return await this.decoder.decode(new Uint8Array(i))}async __standard(t,e){const i=await this.__decode_via_worker(t,e);let n;const s=i.bitDepth;switch(s){case 8:n=new Uint8Array(i.data);break;case 16:n=new Uint16Array(i.data);break;default:throw new Error(`Unsupported bit depth '${s}'. path='${t}'`)}return new gm(n,i.width,i.height,i.itemSize)}load(t,e,i,n,s){"dds"===function(t){const e=typeof t;if("string"!==e)throw new Error(`path must be a string, instead was '${e}'`);const i=function(t){if("string"!=typeof t)throw new Error("path is not a string");const e=t.lastIndexOf("/");return-1!==e?t.substring(e+1):t}(t),n=i.lastIndexOf(".");return-1!==n?i.substring(n+1):null}(e)?this.assetManager.get({path:e,scope:t,type:Lu,callback:t=>{const e=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=Vp.global.get({});s.getContext().getExtension("WEBGL_compressed_texture_s3tc");const r=Ip(s,e,i,{vertexShader:rm.vertexShader,fragmentShader:rm.fragmentShader,uniforms:{tDiffuse:{value:t,type:"t"},opacity:{value:1}}});return Vp.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 Qu(r.array,4,e,i)}(e);e.dispose();const s=new gm(n.data,n.width,n.height,n.itemSize);i(s)},failure:n,progress:s}):this.__standard(e,t).then(i,n)}}class xm{#C=!1;get linked(){return this.#C}constructor(t,e,i){if("function"!=typeof e)throw new TypeError(`handler must be a function, instead was '${typeof e}'`);if("object"!=typeof t)throw new TypeError(`signal must be of an object, instead was '${typeof t}'`);if("function"!=typeof t.add)throw new TypeError(`signal.add must be a function, instead was '${typeof t.add}'`);this.signal=t,this.handler=e,this.context=i}link(){this.#C||(this.#C=!0,this.signal.add(this.handler,this.context))}unlink(){this.#C&&(this.#C=!1,this.signal.remove(this.handler,this.context))}}class wm{access=3;resource=null;static from(t,e=3){const i=new wm;return i.access=e,i.resource=t,i}}function bm(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}wm.prototype.isResourceAccessSpecification=!0;class Sm{entityManager=null;state=new qd(Mm.INITIAL);dependencies=[];components_used=[];get referenced_components(){const t=[];bm(this.dependencies,0,t,t.length,this.dependencies.length);const e=this.components_used,i=e.length;for(let n=0;n<i;n++)Cf(t,e[n].resource);return t}getAccessForComponent(t){let e=0;const i=this.components_used,n=i.length;for(let s=0;s<n;s++){const n=i[s];if(n.resource===t){e|=n.access;break}}const s=this.dependencies,r=s.length;for(let i=0;i<r;i++)if(s[i]===t){e|=1;break}return e}startup(t,e,i){this.entityManager=t,e()}shutdown(t,e,i){e()}link(t,e){}unlink(t,e){}}Sm.prototype.fixedUpdate=Ud,Sm.prototype.update=Ud,Object.defineProperties(Sm.prototype,{componentClass:{configurable:!0,get:()=>null}});const Mm={INITIAL:0,STARTING:1,RUNNING:2,STOPPING:3,STOPPED:4};function Tm(t){return t.constructor.name}Sm.State=Mm;const Am={Perspective:"perspective",Orthographic:"orthographic"};function Cm(t){let e;switch(t.projectionType.getValue()){default:case Am.Perspective:e=new hr(t.fov.getValue(),1,1,50);break;case Am.Orthographic:e=new Pr(-10,10,20,-20,1,1)}return e.far=t.clip_far,e.near=t.clip_near,e}class Em extends Boolean{constructor(t){super(),this.__value=t,this.onChanged=new y}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 zm(t,e){this.__value=t,this.__validSet=e,this.onChanged=new y}Em.FALSE=Object.freeze(new Em(!1)),Em.TRUE=Object.freeze(new Em(!0)),Em.prototype.isObservedBoolean=!0,zm.prototype.getValidValueSet=function(){return this.__validSet},zm.prototype.set=function(t){const e=this.__value;return e!==t&&(this.__value=t,this.onChanged.dispatch(t,e)),this},zm.prototype.equals=function(t){return this.__value===t.__value},zm.prototype.copy=function(t){this.set(t.getValue())},zm.prototype.getValue=function(){return this.__value},zm.prototype.invert=function(){this.set(!this.__value)},zm.prototype.process=function(t){this.onChanged.add(t),t(this.__value,this.__value)},zm.prototype.toJSON=function(){return this.__value},zm.prototype.fromJSON=function(t){this.set(t)};const Lm=new In;function Im(t,e,i=!0){i&&t.updateProjectionMatrix(),Lm.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),e.setFromProjectionMatrix(Lm)}const Nm=new In,Pm=new O,Dm=new O;function Om(t,e){const i=Pm,n=Dm;i.copy(O.forward),n.copy(O.up),i.applyQuaternion(e),n.applyQuaternion(e),Nm.lookAt(O.zero,i,n),t.setFromRotationMatrix(Nm)}class Fm{constructor(){this.autoClip=!1,this.autoClipHysteresis=.33,this.object=null,this.fov=new sd(45),this.projectionType=new zm(Am.Perspective,Am),this.active=new Em(!0),this.__clip_far=100,this.__clip_near=.1}getReciprocalRotation(t,e){Om(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){Fm.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 Fm;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;km.setFromMatrixPosition(t.matrixWorld.elements),Rm.set(e,i,.5),r=Rm,a=Rm,o=t.projectionMatrixInverse.elements,l=t.matrixWorld.elements,r.copy(a),r.applyMatrix4(o),r.applyMatrix4(l),Rm.sub(km),Rm.normalize(),n.copy(km),s.copy(Rm)}computeProjectionMatrix(t){const e=this.object;return null!==e&&(t.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),!0)}rayPlaneIntersection(t,e,i,n,s,r,a,o){Im(this.object,Bm);const l=Bm.planes[o];!function(t,e,i,n,s,r,a,o,l,h,c){const u=L(s,r,a,o,l,h),d=L(o,l,h,e,i,n)+c;if(0!==u){const o=-d/u;return!(o<0||(t.set(s*o+e,r*o+i,a*o+n),0))}0===d&&t.set(e,i,n)}(t,e,i,n,s,r,a,l.normal.x,l.normal.y,l.normal.z,l.constant)}projectWorldPointOntoNearPlane(t,e,i,n){Im(this.object,Bm);const s=Bm.planes[0];Rm.set(t,e,i);const r=s.normal,a=function(t,e,i,n,s,r,a){return L(n,s,r,t,e,i)+a}(t,e,i,r.x,r.y,r.z,s.constant),o=-a;n.set(r.x*o+t,r.y*o+e,r.z*o+i)}}Fm.typeName="Camera",Fm.ProjectionType=Am;const Rm=new O,km=new O,Bm=new xr;function Um(t,e,i){const n=t.object;if(null===n)return;const s=e/i;switch(t.projectionType.getValue()){case Fm.ProjectionType.Perspective:n.aspect=s;break;case Fm.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 Vm(t){t.updateMatrix();const e=t.children;for(let t=0,i=e.length;t<i;t++)Vm(e[t])}function Wm(t){Vm(t),t.updateMatrixWorld(!1)}function Gm(t){const e=t.object;null!==e&&(e.updateProjectionMatrix(),Wm(e))}class Hm extends Sm{constructor(t){super(),this.scene=t.scene,this.dependencies=[Fm,G],this.components_used=[wm.from(Fm,2)],this.entityManager=null,this.graphics=t,this.entityData=[];const e=this;this.__handleViewportResize=function(t,i){const n=e.entityManager;if(null===n)return;const s=n.dataset;null!==s&&s.traverseComponents(Fm,(function(e){Um(e,t,i)}))},this.signalBindings=[]}link(t,e,i){null===t.object&&(t.object=Cm(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;Om(t.object.quaternion,i),t.object.rotation.setFromQuaternion(t.object.quaternion),Gm(t)}function o(){t.object=Cm(t),Um(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)}Um(t,s.x,s.y),this.scene.add(t.object);const h=e.position,c=e.rotation,u=[new xm(h.onChanged,r),new xm(c.onChanged,a),new xm(t.projectionType.onChanged,o),new xm(t.active.onChanged,l),new xm(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 xm(n.on.visibilityConstructionStarted,(function(){const e=t;n.layers;const i=e.dataset;null!==i&&i.traverseComponents(Fm,(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){t.object.far=t.clip_far,t.object.near=t.clip_near}(t):(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(Fm,(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(Fm,(function(t){if(t.active.getValue()){const e=t.object;if(null!==e){const t=new xr;Im(e,t),i.push(t)}}})),e(i)}}function jm(t,e){if(!t.isBuilt&&!t.isBuildInProgress){const i=t.gridPosition;e.build(i.x,i.y,Ud,Ud)}}class qm extends Sm{dependencies=[Pf];gridScaleX=1;gridScaleY=1;__time_delta=0;renderLayer=null;bvh=new Td;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.assetManager=e}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.buildVisibleSet=(t,e,i)=>{const n=this.entityManager;if(null===n)return 0;const s=n.dataset;if(null===s)return 0;const r=[];let a=0;return s.traverseComponents(Pf,((n,s)=>{const o=n.tiles,l=sm(r,0,o.bvh,i.frustum);for(let i=0;i<l;i++){const n=r[i],s=o.tiles[n];s.isBuilt&&(t[e+a]=s.mesh,a++)}})),a};const n=this.assetManager;n.hasLoaderForType("image")||await n.registerLoader("image",new vm),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),t.bvh.link(this.bvh,e)}unlink(t,e){t.unlink()}update(t){const e=this.entityManager.dataset;this.__time_delta=t,null!==e&&e.traverseComponents(Pf,this.__visitTerrainComponent,this)}__visitTerrainComponent(t,e){const i=this.entityManager.dataset,n=i.getComponent(e,G);t.transform=void 0!==n?n.matrix:d,t.update(this.__time_delta),t.frustumCulled&&qm.traverseVisibleTiles(i,t,jm)}static traverseVisibleTiles(t,e,i){const n=e.__tiles,s=[],r=new Set,a=new Float32Array(24);void 0!==n&&Hm.getActiveFrustums(t,(function(t){let e=0;for(let i=0;i<t.length;i++)Of(t[i].planes,a),e+=sm(s,0,n.bvh,a);for(let t=0;t<e;t++){const e=s[t];if(!r.has(e)){const t=n.tiles[e];i(t,n)}r.add(e)}}))}}const Jm=new nf({maxWeight:134217728,keyEqualityFunction:Gp,keyHashFunction:Hp,keyWeigher:t=>t.byteSize+64,valueWeigher:t=>1});function Ym(t,e,i=0,n=t.length){const s=i+n;for(let n=i;n<s;n++)if(t[n]===e)return t.splice(n,1),!0;return!1}function Xm(t){return void 0!==t}const $m=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 Zm(t){return $m[125613361*(t&-t)>>>27]}function Km(){this.__length=0,this.__capacity=64,this.__data_uint32=new Uint32Array(this.__capacity>>5),this.__shrinkFactor=.5}Km.prototype.preventShrink=function(){this.__shrinkFactor=0},Km.prototype.setShrinkFactor=function(t){this.__shrinkFactor=t},Km.prototype.setCapacity=function(t){if(this.__length>t)throw new Error("Current length is greater than requested size");this.__resize(t)},Km.prototype.size=function(){return this.__length},Km.prototype.capacity=function(){return this.__capacity},Km.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},Km.prototype.__updateLength=function(){const t=this.previousSetBit(this.__length)+1;t<this.__length&&this.__setLength(t)},Km.prototype.__setLength=function(t){this.__length=t;const e=this.__capacity;if(t>e){const i=Math.ceil(Kd(t,e+128,1.3*e));this.__resize(i)}else t<e-128&&t<e*this.__shrinkFactor&&this.__resize(t)},Km.prototype.previousSetBit=function(t){const e=C(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},Km.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=Zm(e),(r<<5)+a;r++}const o=e/32;for(;r<o;r++)if(n=i[r],0!==n)return a=Zm(n),s=(r<<5)+a,s;return-1},Km.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=Zm(~t),n+32*i;i++}for(;i<r;i++)if(e=a[i],4294967295!==e)return n=Zm(~e),n+32*i;return s},Km.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,this.__updateLength())},Km.prototype.clear=function(t){this.set(t,!1)},Km.prototype.setRange=function(t,e){for(let i=t;i<=e;i++)this.set(i,!0)},Km.prototype.clearRange=function(t,e){for(let i=t;i<e;i++)this.set(i,!1)},Km.prototype.and=function(t){throw new Error("NIY")},Km.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)},Km.prototype.getAndSet=function(t){const e=this.get(t);return e||this.set(t,!0),e},Km.prototype.getAndClear=function(t){const e=this.get(t);return e&&this.set(t,!1),e},Km.prototype.shift_right=function(t,e,i){for(let n=i;n>=e;n--){const e=this.get(n);this.set(n+t,e)}},Km.prototype.shift_left=function(t,e,i){for(let n=e;n<=i;n++){const e=this.get(n);this.set(n-t,e)}},Km.prototype.shift=function(t,e,i){t>0?this.shift_right(t,e,i):this.shift_right(-t,e,i)},Km.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)},Km.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))}},Km.fixedSize=function(t){const e=new Km;return e.setCapacity(t),e.__shrinkFactor=0,e};class Qm{componentMask=new Km;componentIndexMapping=[];dataset=null;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}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)}}class t_{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)}isDirectedTowards(t){return this.first===t&&2===this.direction||this.second===t&&1===this.direction}isDirectedAwayFrom(t){return this.first===t&&1===this.direction||this.second===t&&2===this.direction}get nodes(){return[this.first,this.second]}}t_.prototype.isEdge=!0;class e_{node=null;__edges=[];__neighbors=new Map;get neighbours(){return Array.from(this.__neighbors.keys())}getEdgeCount(){return this.__edges.length}getEdges(){return this.__edges}get inNodes(){return this.inEdges.map((t=>t.other(this.node)))}get outNodes(){return this.outEdges.map((t=>t.other(this.node)))}get outEdges(){const t=[];return this.getOutgoingEdges(t),t}get inEdges(){const t=[];return this.getIncomingEdges(t),t}getIncomingEdges(t){const e=this.__edges,i=e.length;let n=0;for(let s=0;s<i;s++){const i=e[s];i.isDirectedTowards(this.node)&&(t.push(i),n++)}return n}getOutgoingEdges(t){const e=this.__edges,i=e.length;let n=0;for(let s=0;s<i;s++){const i=e[s];i.isDirectedAwayFrom(this.node)&&(t.push(i),n++)}return n}getIncomingEdgeCount(){let t=0;const e=this.__edges,i=e.length,n=this.node;for(let s=0;s<i;s++){const i=e[s];(i.first===n&&1===i.direction||i.second===n&&2===i.direction)&&t++}return t}edgeWithNodeExists(t){return this.__neighbors.has(t)}traverseEdges(t,e){let i=0;const n=this.__edges,s=n.length;for(;i<s;i++){const s=n[i];t.call(e,s)}return i}getAnyEdgeWith(t){if(!this.edgeWithNodeExists(t))return;const e=this.__edges,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.contains(t))return i}}getAnyDirectionEdgeTo(t){const e=this.__edges,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.second===t&&1===i.direction||i.first===t&&2===i.direction)return i}}addEdge(t){if(this.__edges.includes(t))return!1;const e=t.other(this.node);this.__edges.push(t);let i=this.__neighbors.get(e);return void 0===i&&(i=0),this.__neighbors.set(e,i+1),!0}removeEdge(t){const e=this.__edges,i=e.indexOf(t);if(-1===i)return!1;e.splice(i,1);const n=t.other(this.node),s=this.__neighbors.get(n);return s<=1?this.__neighbors.delete(n):this.__neighbors.set(n,s-1),!0}}function i_(t,e){const i=[];let n=t;do{i.unshift(n.node),n=e.get(n)}while(void 0!==n);return i}class n_{__nodes=new Map;__edges=new Set;on={nodeAdded:new y,nodeRemoved:new y,edgeAdded:new y,edgeRemoved:new y};hasNode(t){return this.__nodes.has(t)}addNode(t){if(this.hasNode(t))return!1;const e=new e_;return e.node=t,this.__nodes.set(t,e),this.on.nodeAdded.send2(t,this),!0}removeNode(t){const e=this.__nodes.get(t);return void 0!==e&&(e.traverseEdges(this.removeEdge,this),this.__nodes.delete(t),this.on.nodeRemoved.send2(t,this),!0)}traverseNodes(t,e){for(const[i,n]of this.__nodes)t.call(e,i)}get nodeCount(){return this.__nodes.size}getNodeCount(){return this.__nodes.size}findNode(t,e){const i=this.__nodes;for(const[n,s]of i)if(t.call(e,n))return n}getNodeContainer(t){return this.__nodes.get(t)}getNodeDegree(t){const e=this.__nodes.get(t);return void 0===e?0:e.getEdgeCount()}get nodes(){return Array.from(this.getNodes())}getNodes(){return this.__nodes.keys()}getEdges(){return this.__edges}createEdge(t,e,i=3){const n=new t_(t,e);return n.direction=i,this.addEdge(n),n}addEdge(t){if(this.hasEdge(t))return!1;const e=this.__nodes.get(t.first),i=this.__nodes.get(t.second);if(void 0===e)throw new Error(`First node(=${t.first}) of the edge is not part of the graph`);if(void 0===i)throw new Error(`Second node(=${t.second}) of the edge is not part of the graph`);return e.addEdge(t),i.addEdge(t),this.__edges.add(t),this.on.edgeAdded.send2(t,this),!0}removeEdge(t){if(!this.hasEdge(t))return!1;const e=this.__nodes.get(t.first),i=this.__nodes.get(t.second);if(void 0===e||void 0===i)throw new Error("One or both nodes of the edge are not present on the graph. This is a critical error");return e.removeEdge(t),i.removeEdge(t),this.__edges.delete(t),this.on.edgeRemoved.send2(t,this),!0}hasEdge(t){return this.__edges.has(t)}traverseEdges(t,e){for(const i of this.__edges)t.call(e,i)}get edgeCount(){return this.__edges.size}edgeExistsBetween(t,e){const i=this.__nodes.get(t);return void 0!==i&&i.edgeWithNodeExists(e)}getAnyEdgeBetween(t,e){const i=this.__nodes.get(t);if(void 0!==i&&this.hasNode(e))return i.getAnyEdgeWith(e)}getAnyDirectedEdge(t,e){const i=this.__nodes.get(t);if(void 0!==i)return i.getAnyDirectionEdgeTo(e)}getAttachedEdges(t,e){const i=this.__nodes.get(e);if(void 0===i)return 0;const n=i.getEdges(),s=n.length;for(let e=0;e<s;e++)t[e]=n[e];return s}getNeighbours(t){const e=this.__nodes.get(t);return void 0===e?[]:e.neighbours}nodeHasEdges(t){const e=this.__nodes.get(t);return void 0!==e&&e.getEdgeCount()>0}findPath(t,e){const i=this.__nodes.get(t),n=this.__nodes.get(e),s=new Set;s.add(i);const r=new Set,a=new Map;for(;s.size>0;){const t=s.values().next().value;if(t===n)return i_(n,a);s.delete(t),r.add(t);const e=t.getEdges(),i=t.node,o=e.length;for(let n=0;n<o;n++){const o=e[n],l=o.first,h=o.second;let c=null;if(l!==i||1!==o.direction&&3!==o.direction){if(h!==i||2!==o.direction&&3!==o.direction)continue;c=l}else c=h;const u=this.__nodes.get(c);r.has(u)||s.has(u)||(s.add(u),a.set(u,t))}}return null}clear(){this.__nodes.clear(),this.__edges.clear()}copy(t){this.clear(),t.traverseNodes(this.addNode,this),t.traverseEdges(this.addEdge,this)}clone(){const t=new n_;return t.copy(this),t}}const s_="entityRemoved",r_="componentAdded";class a_{systems=[];systemsExecutionOrder=[];systemObservers=[];on={systemStarted:new y,systemStopped:new y,systemAdded:new y,systemRemoved:new y};state=0;systemAccumulatedFixedStepTime=new Map;fixedUpdateStepSize=.015;dataset=null;__execution_order_needs_update=!0;updateExecutionOrder(){const t=this.systemsExecutionOrder;t.splice(0,t.length);const e=this.systems,i=e.length;let n=0;for(let s=0;s<i;s++){const i=e[s];i.update===Ud&&i.fixedUpdate===Ud||(t[n++]=i)}const s=function(t,e){const i=new n_;for(let n=0;n<t;n++){const t=e[n],s=t.referenced_components,r=s.length;for(let t=0;t<r;t++){const e=s[t];i.addNode(e)}for(let e=0;e<r;e++){const n=s[e];if(0!=(6&t.getAccessForComponent(n)))for(let a=0;a<r;a++){if(e===a)continue;const r=s[a];0!=(1&t.getAccessForComponent(r))&&void 0===i.getAnyDirectedEdge(n,r)&&i.createEdge(n,r,1)}}}return i}(n,t);function r(t){let e=0;const i=t.referenced_components,n=i.length;for(let r=0;r<n;r++){const n=i[r];e+=1e-4;const a=s.getNodeContainer(n).getIncomingEdgeCount(),o=t.getAccessForComponent(n);e+=0!=(4&o)?4*a:0!=(2&o)?2*a:a}return e}const a=new Map;for(let e=0;e<n;e++){const i=t[e];a.set(i,r(i))}t.sort(((t,e)=>a.get(e)-a.get(t))),this.__execution_order_needs_update=!1}detachDataSet(){const t=this.dataset;null!==t&&(this.systemObservers.forEach((function(e){t.removeObserver(e,!0)})),this.dataset=null)}getComponentTypeMap(){const t=[],e=this.systems,i=e.length;for(let n=0;n<i;n++){const i=e[n].referenced_components;bm(i,0,t,t.length,i.length)}return t}attachDataSet(t){if(null!==this.dataset){if(this.dataset===t)return;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)}))}hasSystem(t){return null!==this.getSystem(t)}getSystem(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}getComponentClassByName(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}simulate(t){this.__execution_order_needs_update&&this.updateExecutionOrder();const e=this.systems,i=e.length,n=this.fixedUpdateStepSize,s=this.systemAccumulatedFixedStepTime;for(let r=0;r<i;r++){const i=e[r];if(i.fixedUpdate!==Ud){let e=s.get(i)+t;for(;e>=n;){try{i.fixedUpdate(n)}catch(t){}e-=n}s.set(i,e)}if(i.update!==Ud)try{i.update(t)}catch(t){}}}addSystem(t){const e=this.getSystem(Object.getPrototypeOf(t).constructor);if(null!==e){if(e===t)return Promise.resolve();throw new bu(`Another instance of system '${Tm(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 Sm))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.components_used,i=e.length;for(let t=0;t<i;t++){const i=e[t];if(null==i||!0!==i.isResourceAccessSpecification)throw new Error(`Invalid access specification[${t}], expected an instance of ResourceAccessSpecification, but got something else`);if(null===i.resource)throw new Error(`No component specified for element [${t}]`);if(0===i.access)throw new Error("No access modifiers specified, must have at least one (such as Read, Write, Create)");for(let n=0;n<t-1;n++)if(e[n].resource===i.resource)throw new Error(`Duplicate specification of component [${n}] and [${t}]`)}const n=t.dependencies,s=n.length;if(s<1)throw new Error("A system must declare at least one dependency");if(s>1)for(let t=0;t<s;t++){const e=n[t];for(let i=t+1;i<s;i++)if(e===n[i])throw new Error(`Detected duplicate dependency: ${e.constructor.typeName}`)}const r=s+1;if(t.link!==Sm.prototype.link&&t.link.length!==r&&!0!==t.__validation_ignore_link_argument_count)throw new Error(`'link' method declares ${t.link.length} instead of expected ${r} based on it's ${s} dependencies`);if(t.unlink!==Sm.prototype.unlink&&t.unlink.length!==r&&!0!==t.__validation_ignore_link_argument_count)throw new Error(`'unlink' method declares ${t.unlink.length} instead of expected ${r} based on it's ${s} dependencies`)}(t)}catch(t){}const i=t.state.getValue(),n=[Mm.INITIAL,Mm.STOPPED];if(-1===n.indexOf(i))throw new bu(`System must be in one of these states: [${n.join(",")}], instead was ${i}`);const s=this.systems,r=s.length;s[r]=t,this.__execution_order_needs_update=!0;const a=new Qm(t.dependencies,t.link,t.unlink,t);let o;if(this.systemObservers[r]=a,o=2===this.state?new Promise(((e,i)=>{this.startSystem(t,e,i)})):Promise.resolve(),null===t.entityManager)t.entityManager=this;else if(t.entityManager!==this)throw new Error("System is bound to another EntityManager");return null!==this.dataset&&(this.dataset.registerManyComponentTypes(t.referenced_components),this.dataset.addObserver(a)),this.systemAccumulatedFixedStepTime.set(t,0),this.on.systemAdded.send1(t),o}async removeSystem(t){const e=this.systems.indexOf(t);if(-1===e)return!1;const i=this.systemObservers[e];return this.systemObservers.splice(e,1),this.systems.splice(e,1),this.__execution_order_needs_update=!0,null!==this.dataset&&this.dataset.removeObserver(i),await new Promise(((e,i)=>{this.stopSystem(t,e,(e=>{i(`system ${Tm(t)} shutdown failed: ${e}`)}))})),this.systemAccumulatedFixedStepTime.delete(t),this.on.systemRemoved.send1(t),!0}stopSystem(t,e,i){const n=this;try{t.state.set(Mm.STOPPING)}catch(t){return void i(t)}try{t.shutdown(n,(function(){t.state.set(Mm.STOPPED),n.on.systemStopped.send1(t),e(t)}),(function(t){i(t)}))}catch(t){i(t)}}startSystem(t,e,i){if(t.state.getValue()===Mm.RUNNING)return void e(t);const n=this;try{t.state.set(Mm.STARTING)}catch(t){return void i(t)}function s(t){i(t)}try{t.startup(n,(function(){t.state.set(Mm.RUNNING),n.on.systemStarted.dispatch(t),e(t)}),s)}catch(t){s(t)}}startup(t,e){if(1===this.state)throw new bu("System is currently in starting state");if(2===this.state)return void t();this.state=1;const i=this,n=this.systems;let s=0;const r=n.length;function a(){i.state=2;try{t()}catch(t){}}function o(){s++,s===r&&a()}let l=!0;function h(t,n){l&&(l=!1,i.state=3,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()}promiseSystem(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))}))}))}promiseSystemInState(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)}))}shutdown(t,e){this.state=4,null!==this.dataset&&this.detachDataSet();const i=this,n=this.systems;let s=0;const r=n.length;function a(){i.state=5;try{t()}catch(t){}}function o(t){s++,t.state.set(Mm.STOPPED),i.on.systemStopped.send1(t),s===r&&a()}let l=!0;function h(t){l&&(l=!1,i.state=3,e())}0===r&&a(),n.forEach((function(t){t.state.set(Mm.STOPPING);const e=o.bind(null,t),n=h.bind(null,t);try{t.shutdown(i,e,n)}catch(t){n(t)}}))}}class o_{id=-1;generation=-1;components=[];#E=[];dataset=null;flags=6;properties={};on={built:new y};#z(){this.clearFlag(1)}setFlag(t){this.flags|=t}getFlag(t){return 0!=(this.flags&t)}clearFlag(t){this.flags&=~t}get isBuilt(){return this.getFlag(1)}removeAllComponents(){const t=this.components;for(let e=t.length-1;e>=0;e--){const i=t[e];this.removeComponent(Object.getPrototypeOf(i).constructor)}}get count(){return this.components.length}add(t){if(null==t)throw new Error(`Can not add ${t} to Entity`);return this.components.push(t),this.getFlag(1)&&this.dataset.addComponentToEntity(this.id,t),this}hasComponent(t){return null!==this.getComponent(t)}getComponent(t){const e=this.components,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.components,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(1)&&this.dataset.removeComponentFromEntity(this.id,t),i}return null}sendEvent(t,e){this.getFlag(1)&&this.dataset.sendEvent(this.id,t,e)}promiseEvent(t){return new Promise(((e,i)=>{const n=()=>{this.removeEventListener(t,n),this.removeEventListener(s_,i),e()};this.addEventListener(t,n),this.removeEventListener(s_,i)}))}addEventListener(t,e,i){return this.getFlag(1)?this.dataset.addEntityEventListener(this.id,t,e,i):this.#E.push({name:t,listener:e,context:i}),this}removeEventListener(t,e,i){if(this.getFlag(1))this.dataset.removeEntityEventListener(this.id,t,e,i);else{const n=this.#E;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(1)){const t=this.dataset,e=this.id;return t.removeEntityEventListener(e,s_,this.#z,this),t.removeEntity(e),this.id=-1,this.generation=-1,this.clearFlag(1),!0}return!1}build(t){if(this.getFlag(1)&&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.id,this.components,t))return this.id;const e=this.id=t.createEntity();let i;this.generation=t.getEntityGeneration(e),this.dataset=t;const n=this.#E,s=n.length;for(i=0;i<s;i++){const s=n[i];t.addEntityEventListener(e,s.name,s.listener,s.context)}this.#E.splice(0,s);const r=this.components,a=r.length;if(this.getFlag(2))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(1),this.getFlag(4)&&t.addEntityEventListener(e,s_,this.#z,this),this.on.built.send2(e,t),e}static readFromDataset(t,e){const i=new o_;return e.getAllComponents(t).filter(Xm).forEach(i.add,i),i.setFlag(1),i.id=t,i.dataset=e,i.generation=e.getEntityGeneration(t),i}}o_.prototype.isEntity=!0;class l_{transform=new G;parent=-1;flags=1;toString(){return JSON.stringify(this.toJSON())}toJSON(){return{transform:this.transform.toJSON(),parent:this.parent,flags:this.flags}}fromJSON({transform:t,parent:e=-1,flags:i=1}){this.transform.fromJSON(t),this.parent=e,this.flags=i}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 h_{constructor(){this.entity=-1}static from(t){const e=new h_;return e.entity=t,e}toJSON(){return{entity:this.entity}}fromJSON({entity:t}){this.entity=t}}h_.typeName="ParentEntity",h_.serializable=!1;class c_{__parent=null;__children=[];__transform=new G;on={built:new y,destroyed:new y};flags=1;constructor(t=new o_){this.__entity=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}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(G);null!==e&&e.copy(t)}else this.__safe_get_attachment().transform.copy(t)}static fromComponents(...t){const e=new c_;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(h_),n=e.removeComponent(l_);if(null!==t){null===i&&(i=new h_);const s=t.entity;if(!s.isBuilt)throw new Error("Parent entity is not built");const r=s.id;i.entity=r,e.add(i),null===n&&(n=this.__safe_get_attachment()),n.parent=r}}get entity(){return this.__entity}addChild(t){return!!Cf(this.__children,t)&&(null!==t.parent&&t.parent.removeChild(t),t.parent=this,this.__entity.isBuilt&&t.build(this.__entity.dataset),!0)}removeChild(t){return!!Ym(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(h_);null===t&&(t=new h_,this.__entity.add(t));const i=e.__entity;if(!i.isBuilt)throw new Error("Parent entity is not built");const n=i.id;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()}}c_.prototype.isEntityNode=!0;class u_{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,G);return void 0!==t&&(this.parent_transform=t,!0)}link(){this.parent_transform.subscribe(this.update,this),this.attachment.transform.subscribe(this.update,this)}unlink(){this.parent_transform.unsubscribe(this.update,this),this.attachment.transform.unsubscribe(this.update,this)}}class d_ extends Sm{__contexts=[];__queue=[];__queue_size=0;__queue_cursor=0;constructor(){super(),this.dependencies=[l_,G],this.components_used=[wm.from(l_,1),wm.from(G,3)]}__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 u_;n.attachment=t,n.transform=e,n.entity=i,n.ecd=this.entityManager.dataset,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=C(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++}}}class p_ extends hd{constructor(t=""){super(t)}getLocalizationKey(){return`component.name.${this.getValue()}`}getLocalizedValue(t){return t.getString(this.getLocalizationKey())}clone(){const t=new p_;return t.copy(this),t}}function f_(t){const e=new c_;!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 G;if(n.fromMatrix4(t.matrixWorld.elements),i.add(n),i.add(new p_(t.name)),t.isMesh){t.isSkinnedMesh;const e=Yf.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_.typeName="Name";const m_=Ad;function __(t,e,i,n,s){if(n===bd)return 0;const r=m_.pointer++;m_[r]=n;let a=e;for(;m_.pointer>r;){m_.pointer--;const e=m_[m_.pointer];if(s.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);m_[m_.pointer++]=n,m_[m_.pointer++]=t}}return a-e}class g_{evaluate(t,e){throw new Error("Not Implemented")}}const y_=[];class v_ extends g_{ray=[];static from(t){const e=new v_;return e.ray=t,e}evaluate(t,e){return e.node_get_aabb(t,y_),function(t,e){return Ed(t[0],t[1],t[2],t[3],t[4],t[5],e[0],e[1],e[2],e[3],e[4],e[5])}(y_,this.ray)}}function x_(){return!0}function w_(t,e,i,n,s,r){const a=t-n,o=e-s,l=i-r;return a*a+o*o+l*l}class b_ extends n{appendText(t){return this}appendList(t,e,i,n){return this}appendValueList(t,e,i,n){return this}appendValue(t){return this}appendDescriptionOf(t){return this}}b_.INSTANCE=new b_,class extends s{matches(t,e=b_.INSTANCE){throw new Error("Not Implemented")}describeMismatch(t,e){throw new Error("Not Implemented")}}.prototype.isMatcher=!0;class S_{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(Yf))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,Yf);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 M_=[];function T_(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 A_{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(M_[0]=0,M_[1]=s;o>0;){o-=2;const i=M_[o+1],n=M_[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&&(M_[o++]=n,M_[o++]=a),r<i&&(M_[o++]=r,M_[o++]=i)}}(this.__objects,T_,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(){}}A_.prototype.isShadedGeometryRenderAdapter=!0;class C_{object=null;key=null}class E_{constructor(){this.__object_cache=new WeakMap}get(t){const e=this.__object_cache.get(t);if(void 0!==e){const i=e.object;if(e.key.equals(t))return i}const i=t.clone(),n=function(t){let e;const i=t.mode,n=t.material,s=t.geometry;if(0===i)e=new er(s,n);else if(2===i)e=new Zl(s,n);else if(3===i)e=new th(s,n);else{if(4!==i)throw new Error(`Unsupported draw mode '${i}'`);e=new ah(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}(i),s=new C_;return s.key=i,s.object=n,this.__object_cache.set(t,s),n}}E_.INSTANCE=new E_;class z_ extends A_{constructor(){super(),this.__cache=E_.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}}class L_{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 I_=new L_({name:"diffuse",uv_index:0,read:t=>t.map,write(t,e){t.map=e}}),N_=new L_({name:"alpha",uv_index:0,read:t=>t.alphaMap,write(t,e){t.alphaMap=e}}),P_=new L_({name:"displacement",uv_index:0,read:t=>t.displacementMap,write(t,e){t.displacementMap=e}}),D_={MeshDepthMaterial:[I_,P_,N_],MeshStandardMaterial:[I_,N_,new L_({name:"light",uv_index:1,read:t=>t.lightMap,write(t,e){t.lightMap=e}}),new L_({name:"ao",uv_index:1,read:t=>t.aoMap,write(t,e){t.aoMap=e}}),new L_({name:"emissive",uv_index:0,read:t=>t.emissiveMap,write(t,e){t.emissiveMap=e}}),new L_({name:"bump",uv_index:0,read:t=>t.bumpMap,write(t,e){t.bumpMap=e}}),new L_({name:"normal",uv_index:0,read:t=>t.normalMap,write(t,e){t.normalMap=e}}),P_,new L_({name:"roughness",uv_index:0,read:t=>t.roughnessMap,write(t,e){t.roughnessMap=e}}),new L_({name:"metalness",uv_index:0,read:t=>t.metalnessMap,write(t,e){t.metalnessMap=e}}),new L_({name:"environment",uv_index:0,read:t=>t.envMap,write(t,e){t.envMap=e}})]};function O_(t,i){return Array.isArray(t)||Array.isArray(i)?e(t,i):Yu(t,i)}const F_=new WeakMap;function R_(t,e){const i=F_.get(t);if(void 0!==i)return i;const n=t.width,s=t.height,r=Qu.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),F_.set(t,r),r}let k_=null;function B_(t,e){let i;if(null===k_||void 0===(i=k_.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),k_=new WeakRef(i)}return i}function U_(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 V_(t){const e=E(t.x);return(e<<5)-e+E(t.y)}const W_=new WeakMap;function G_(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=W_.get(t);if(void 0!==e)return e;let i=0;t instanceof ImageBitmap?i=function(t){const e=C(t.width,8),i=C(t.height,8),n=function(t){return R_(t,B_(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=ld(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,W_.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+U_(t,1337);break}}}return i}(t);return rd(t.mapping,t.wrapS,t.wrapT,t.magFilter,t.minFilter,t.anisotropy,t.format,t.type,V_(t.offset),V_(t.repeat),V_(t.center),E(t.rotation),t.generateMipmaps?1:0,t.premultiplyAlpha?1:0,t.flipY?1:0,t.unpackAlignment,t.encoding,e)}function H_(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=B_(t.width,t.height),n=R_(t,i),s=R_(e,i);return O_(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(!j_(n.mipmaps,s.mipmaps))return!1}}return!0}(t.image,e.image))&&!(t.isCompressedTexture&&e.isCompressedTexture&&!j_(t.mipmaps,e.mipmaps))}function j_(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(!q_(t[n],e[n]))return!1;return!0}function q_(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||O_(i,n)}function J_(t){return Zd(t.normal.x,t.normal.y,t.normal.z)^t.constant}function Y_(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 X_(t){return null==t?0:t.id}function $_(t){return t.getHex()}function Z_(t){let e=rd(E(t.alphaTest),t.blendDst,null===t.blendDstAlpha?0:E(t.blendDstAlpha),t.blendEquation,null===t.blendEquationAlpha?0:E(t.blendEquationAlpha),t.blending,t.blendSrc,null===t.blendSrcAlpha?0:E(t.blendSrcAlpha),t.clipIntersection?0:1,null===t.clippingPlanes?0:Y_(t.clippingPlanes,J_),t.clipShadows?0:1,t.colorWrite?0:1,t.depthFunc,t.depthTest?0:1,t.depthWrite?0:1,t.fog?0:1,E(t.opacity),t.polygonOffset?0:1,E(t.polygonOffsetFactor),E(t.polygonOffsetUnits),ld(t.precision),t.premultipliedAlpha?0:1,t.dithering?0:1,t.flatShading?0:1,t.side,t.transparent?0:1,ld(t.type),t.vertexColors?0:1,t.visible?0:1);return t.isMeshStandardMaterial?e=rd(e,$_(t.color),E(t.roughness),E(t.metalness),X_(t.map),X_(t.lightMap),E(t.lightMapIntensity),X_(t.aoMap),E(t.aoMapIntensity),$_(t.emissive),E(t.emissiveIntensity),X_(t.emissiveMap),E(t.envMapIntensity),X_(t.bumpMap),X_(t.normalMap)):t.isShaderMaterial&&(e^=t.lights?0:1),e}function K_(t,e){return t.equals(e)}function Q_(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}function tg(t,e){return t===e||null!==t&&null!==e&&void 0!==t&&void 0!==e&&t.id===e.id}function eg(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||!Q_(t.clippingPlanes,e.clippingPlanes,K_)||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&&tg(t.roughnessMap,e.roughnessMap)&&tg(t.metalnessMap,e.metalnessMap)&&tg(t.alphaMap,e.alphaMap)&&tg(t.envMap,e.envMap)&&tg(t.displacementMap,e.displacementMap)&&tg(t.normalMap,e.normalMap)&&tg(t.emissiveMap,e.emissiveMap)&&tg(t.bumpMap,e.bumpMap)&&tg(t.aoMap,e.aoMap)&&tg(t.map,e.map)&&tg(t.lightMap,e.lightMap)))return!1}else if(t.isMeshDepthMaterial){if(!tg(t.alphaMap,e.alphaMap)||t.depthPacking!==e.depthPacking||!tg(t.displacementMap,e.displacementMap)||t.displacementScale!==e.displacementScale||t.displacementBias!==e.displacementBias||!tg(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)&&tg(t.matcap,e.matcap)&&tg(t.map,e.map)&&tg(t.bumpMap,e.bumpMap)&&tg(t.normalMap,e.normalMap)&&t.normalScale.equals(e.normalScale)&&tg(t.displacementMap,e.displacementMap)&&t.displacementScale===e.displacementScale&&t.displacementBias===e.displacementBias&&tg(t.alphaMap,e.alphaMap)&&t.morphTargets===e.morphTargets&&t.morphNormals===e.morphNormals&&t.flatShading===e.flatShading))return!1}return!0}class ig{constructor(){this.materialCache=new nf({maxWeight:1e3,keyHashFunction:Z_,keyEqualityFunction:eg}),this.textureCache=new nf({maxWeight:1e3,keyHashFunction:G_,keyEqualityFunction:H_})}acquire(t){const e=this.materialCache.get(t);if(null!==e)return e;const i=this.textureCache,n=t.type,s=D_[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}validate(t,e){const i=this.materialCache.validate(((i,n,s)=>{t.call(e,`Material error: ${i}. Material ${n}`)})),n=this.textureCache.validate(((i,n,s)=>{t.call(e,`Texture error: ${i}. Texture ${n}`)}));return i&&n}}ig.Global=new ig;const ng=new WeakMap;let sg=0;function rg(t,e){let i=ng.get(t);void 0===i&&(i=new WeakMap,ng.set(t,i));let n=i.get(e);return void 0===n&&(n=new Function("previous, next",`return function f${sg++}(a,b,c,d){ previous(a,b,c,d); next(a,b,c,d); };`)(t,e),i.set(e,n)),n}function ag(t){const e="\n #define USE_COLOR_ALPHA\n #define USE_INSTANCING_COLOR \n \n attribute mat4 instanceMatrix;\n attribute vec4 instanceColor;\n \n"+t.vertexShader.replace("#include <begin_vertex>","\n vec3 transformed = ( instanceMatrix * vec4(position,1.0) ).xyz;\n ").replace("#include <beginnormal_vertex>","\n vec3 objectNormal = vec3( normal );\n {\n // this is in lieu of a per-instance normal-matrix\n // shear transforms in the instance matrix are not supported\n\n mat3 m = mat3( instanceMatrix );\n \n objectNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n objectNormal = m * objectNormal;\n \n }\n \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=e,t.fragmentShader="\n #define USE_COLOR_ALPHA\n #define USE_INSTANCING_COLOR \n "+t.fragmentShader}const og=new nf({maxWeight:1024,keyHashFunction:Z_});class lg{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=zi,this.__material=null,this.indices=[],this.references=[],this.__draw_mode=0,this.mesh=vp(),this.use_color=!0}__build_mesh(){let t;switch(this.__draw_mode){case 0:t=new er(this.mesh.geometry,this.mesh.material);break;case 2:t=new Zl(this.mesh.geometry,this.mesh.material);break;case 3:t=new th(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()}#L(t){const e=t.clone();if(e.isShaderMaterial)for(const i in e.uniforms)e.uniforms[i]=t.uniforms[i];e.onBeforeCompile=rg(t.onBeforeCompile,ag);const i=new Ko({depthPacking:Mi});return 0!==e.alphaTest&&(i.alphaTest=e.alphaTest,i.map=e.map),i.onBeforeCompile=ag,{color:ig.Global.acquire(e),depth:ig.Global.acquire(i)}}setMaterial(t){const e=og.getOrCompute(t,this.#L,this);this.__material=e.color,this.mesh.material=e.color,this.mesh.customDepthMaterial=e.depth}setCapacity(t){this.capacity!==t&&(this.capacity=t,this.build())}ensureCapacity(t){const e=this.capacity;if(e<t){const i=Kd(t,e*this.growFactor,e+this.growConstant),n=Math.ceil(i);this.setCapacity(n)}else C(e*this.shrinkFactor,e-this.shrinkConstant)>t&&this.setCapacity(t)}setTransformAt(t,e){nd(e,0,this.__attributeTransformArray,16*t,16)}setColorAt(t,e){nd(e,0,this.__attributeColorArray,4*t,4)}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 Zc;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;xd(t,i),i.length>t.length&&i.fill(0,t.length)}if(this.__attributeTransformArray=i,this.__attributeTransform=new Ul(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;xd(e,t),t.length>e.length&&t.fill(255,e.length)}this.__attributeColorArray=t,this.__attributeColor=new Ul(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 lg;return i.setGeometry(t),i.setMaterial(e),i}}class hg{geometry=-1;material=-1;mode=0;flags=0;hash(){return this.geometry^this.material}equals(t){return this.geometry===t.geometry&&this.material===t.material&&this.mode===t.mode&&this.flags===t.flags}copy(t){this.geometry=t.geometry,this.material=t.material,this.mode=t.mode,this.flags=t.flags}clone(){const t=new hg;return t.copy(this),t}fromSG(t){this.geometry=t.geometry.id,this.material=t.material.id,this.mode=t.mode,this.flags=t.flags}}const cg=new hg;class ug extends A_{__instanced_meshes=new Zp;__active_meshes=new Set;score(t,e,i){return i>16?1:i<4?-1:0}__get_instanced_mesh(t){cg.fromSG(t),cg.flags&=6;let e=this.__instanced_meshes.get(cg);return void 0!==e||(e=new lg,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(cg.clone(),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()}}const dg=[];class pg{constructor(){this.adapters=[new z_,new ug]}*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=sm(dg,0,s,n.frustum),u=r.computeComponentTypeIndex(Yf);for(l=0;l<c;l++){const t=dg[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 fg=new Su,mg=new Float32Array(6);function _g(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 yg{id="";__state=new zm(gg.New,gg);getState(){return this.__state}initialize(){const t=this.__state.getValue();if(t!==gg.New&&t!==gg.Finalized)throw new bu(`Expected New or Finalized state, instead got ${_g(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 bu(`Expected Initialized or Stopped state, instead got ${_g(gg,t.getValue())}`);t.set(gg.Finalized)}startup(){const t=this.__state.getValue();if(t!==gg.Initialized&&t!==gg.Stopped)throw new bu(`Expected Initial state, instead got ${_g(gg,t)}`);this.__state.set(gg.Running)}shutdown(){this.__state.set(gg.Stopped)}}class vg extends yg{__dependencies=[];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 xg={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 Vi(512,512)},cameraNear:{value:1},cameraFar:{value:100},cameraProjectionMatrix:{value:new In},cameraInverseProjectionMatrix:{value:new In},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}"},wg=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 bg(t,e){if(4===e)t.blending=ct,t.blendEquation=ut,t.blendSrc=gt,t.blendDst=wt;else{const i=function(t){let e;if(5===t)e=rt;else if(0===t)e=at;else if(1===t)e=ot;else if(2===t)e=lt;else{if(3!==t)throw new TypeError(`Unsupported blending type ${t}`);e=ht}return e}(e);t.blending=i}}class Sg{constructor({renderTarget:t,blending:e,renderTargetScale:i=1}){this.name="",this.__blending=e,this.renderTarget=t,this.renderTargetScale=i,this.object=new er(zp,this.buildMaterial()),this.stage=0,this.size=new Tu,this.__enabled=!0,this.__order=0,this.on={preRender:new y}}get blending(){return this.__blending}set blending(t){t!==this.__blending&&(this.__blending=t,bg(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){bg(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===Me)e=["r","r","r",1];else{if(i!==ve)throw new Error("Unsupported format");e=["r","g","b","a"]}const n=new or({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:wg(e),lights:!1,fog:!1,depthTest:!1,depthWrite:!1,transparent:!0,vertexColors:!1});return bg(n,this.blending),n}}const Mg={defines:{KERNEL_RADIUS:4,DEPTH_PACKING:1,PERSPECTIVE_CAMERA:1},uniforms:{tDiffuse:{value:null},size:{value:new Vi(512,512)},sampleUvOffsets:{value:[new Vi(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}"},Tg={createSampleWeights:function(t,e){const i=[];for(let n=0;n<=t;n++)i.push(Ag(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=Tg.createSampleOffsets(e,n),t.uniforms.sampleWeights.value=Tg.createSampleWeights(e,i),t.needsUpdate=!0}};function Ag(t,e){return Math.exp(-t*t/(e*e*2))/(Math.sqrt(2*Math.PI)*e)}const Cg=new er(zp,null);Cg.frustumCulled=!1,Cg.matrixAutoUpdate=!1,Cg.matrixWorldNeedsUpdate=!1;const Eg=new Pr(-1,1,1,-1,0,1),zg=new fl;function Lg(t,e){Cg.material=e,t.render(zg,Eg),Cg.material=null}zg.autoUpdate=!1,zg.matrixAutoUpdate=!1,zg.matrixWorldNeedsUpdate=!1,zg.add(Cg);const Ig=new bs;class Ng{constructor({format:t=ve,radius:e=8,clear_color:i=0,clear_alpha:n=1}){this.__rt_input=null,this.__rt_output=null,this.__intermediate=new Zi({format:t}),this.__material_blur_x=new or({uniforms:ar.clone(Mg.uniforms),defines:Object.assign({},Mg.defines),vertexShader:Mg.vertexShader,fragmentShader:Mg.fragmentShader,blending:rt}),this.__material_blur_y=new or({uniforms:ar.clone(Mg.uniforms),defines:Object.assign({},Mg.defines),vertexShader:Mg.vertexShader,fragmentShader:Mg.fragmentShader,blending:rt}),this.__depth_cutoff=.01,this.__blur_radius=e,this.__blur_std_dev=4,this.__clear_color=new bs(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=rt,Tg.configure(t,this.__blur_radius,this.__blur_std_dev,new Vi(1,0)),Tg.configure(e,this.__blur_radius,this.__blur_std_dev,new Vi(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=Ig;t.getClearColor(s);const r=t.getClearAlpha(),a=t.autoClear;t.autoClear=!1,t.setClearColor(this.__clear_color),t.setRenderTarget(this.__intermediate),t.clearColor(),Lg(t,e),t.setRenderTarget(this.__rt_output),t.clearColor(),Lg(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 Pg="color-and-depth",Dg="normal";var Og=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 Og.Panel("FPS","#0ff","#002")),l=i(new Og.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var h=i(new Og.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}};Og.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))}}};const Fg=new Float32Array(2);function Rg(t,e,i,n,s,r,a,o,l){const h=function(t,e,i,n,s,r,a,o,l,h){const c=s-i,u=r-n,d=l-a,p=h-o,f=n-o,m=i-a,_=1/(-d*u+c*p),g=(-u*m+c*f)*_,y=(d*f-p*m)*_;if(g>=0&&g<=1&&y>=0&&y<=1){const e=i+y*c,s=n+y*u;return t[0]=e,t[1]=s,!0}return!1}(Fg,0,t,e,i,n,s,r,a,o);return h&&l.readFromArray(Fg),h}class kg{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=C(u,p),_=Mu(u,p),g=C(d,f),y=Mu(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=Mu(t,s),c=C(i,a);if(h>=c)return!1;const u=Mu(e,r),d=C(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 Wd(this.x0,this.y0,this.x1,this.y1,t.x0,t.y0,t.x1,t.y1)}_expandToFit(t,e,i,n){this.x0=C(this.x0,t),this.y0=C(this.y0,e),this.x1=Mu(this.x1,i),this.y1=Mu(this.y1,n)}_expandToFitPoint(t,e){this._expandToFit(t,e,t,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!!(Rg(t.x,t.y,e.x,e.y,n,s,r,s,i)||Rg(t.x,t.y,e.x,e.y,n,a,r,a,i)||Rg(t.x,t.y,e.x,e.y,n,s,n,a,i)||Rg(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=S(l,s,a),n=S(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 kg(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=S(this.x0,t,i),this.y0=S(this.y0,e,n),this.x1=S(this.x1,t,i),this.y1=S(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)}}kg.computeLineBetweenTwoBoxes=function(t,e,i,n){const s=new Tu(t.midX(),t.midY()),r=new Tu(e.midX(),e.midY());return!!t.lineIntersectionPoint(s,r,i)&&!!e.lineIntersectionPoint(s,r,n)},kg.zero=Object.freeze(new kg(0,0,0,0)),kg.unit=Object.freeze(new kg(0,0,1,1));class Bg{bindings=[];flags=4;position=new Tu(0,0);rotation=new sd(0);scale=new Tu(1,1);size=new Tu(0,0);transformOrigin=new Tu(.5,.5);on={linked:new y,unlinked:new y};children=[];parent=null;#I=new Float32Array(9);#N=new Float32Array(9);constructor(){this.el=null,this.position.onChanged.add(this.__updateTransform,this),this.scale.onChanged.add(this.__updateTransform,this),this.rotation.onChanged.add(this.__updateTransform,this),this.size.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(){const t=this.position,e=this.scale,i=this.rotation.getValue();!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}(this.#N,t.x,t.y,e.x,e.y,0,0,i),this.#P()}#P(){const t=this.#N,e=this.#I;for(let i=0;i<9;i++)if(!T(t[i],e[i],1.192092896e-7))return this.#D(),!0;return!1}#D(){!function(t,e){const i="matrix("+t[0]+","+t[3]+","+t[1]+","+t[4]+","+t[2]+","+t[5]+")";e.style.transform=i}(this.#N,this.el),this.#I.set(this.#N)}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 Tu(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,i=e.indexOf(t);return-1!==i&&(e.splice(i,1),this.el.removeChild(t.el),t.unlink(),t.parent=null,!0)}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 kg).setNegativelyInfiniteBounds(),this.expandToFit(t,0,0),t}resizeToFitChildren(){const t=new kg(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 xm(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=Tu.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()}}Bg.prototype.isView=!0;class Ug extends Bg{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 Ug(e);return t.forEach(i.addChild,i),i}static create(){return new Ug}}class Vg extends hm{load(t,e,i,n,s){!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()}(e,(function(t){let e;try{e=JSON.parse(t)}catch(t){return void n(t)}i({create:function(){return e}})}),n)}}class Wg{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 Gg=new Wg;Gg.setFlag(1),Wg.Transient=Object.freeze(Gg),Wg.typeName="SerializationMetadata";class Hg{values=[];get count(){return this.values.length}get(t){return this.values[t]}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+ld(e[n]),t|=0;return t}equals(t){return e(this.values,t.values)}toJSON(){return this.values}fromJSON(t){if(this.clear(),"string"==typeof t)this.add(t);else{const e=t.length;for(let i=0;i<e;i++)this.add(t[i])}}static find(t,e){const i=[];return e.traverseComponents(Hg,((e,n)=>{e.containsAll(t)&&i.push(n)})),i}static fromOne(t){const e=new Hg;return e.add(t),e}static fromJSON(t){const e=new Hg;return e.fromJSON(t),e}}Hg.typeName="Tag";const jg=new Uint32Array(65536),qg=(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--;)jg[t.charCodeAt(l)]|=1<<l;for(l=0;l<n;l++){let t=jg[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--;)jg[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++)jg[t.charCodeAt(e)]|=1<<e;for(let t=0;t<i;t++){const i=jg[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++)jg[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++)jg[t.charCodeAt(e)]|=1<<e;let p=n;for(let t=0;t<i;t++){const i=jg[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++)jg[t.charCodeAt(e)]=0;return p})(t,e)};class Jg{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 Yg={Text:0,Reference:1,StyleStart:2,StyleEnd:3,ReferenceValue:4};function Xg(t,e,i){this.position=t,this.message=e,this.input=i}function $g(t,e,i){let n=e;const s=t.charAt(e);if("["!==s)throw new Xg(e,`expected style start: '[', got '${s}' instead`,t);n++;const r=t.charAt(n);let a;if("$"===r)a=Yg.StyleStart,n++;else if("/"===r){n++;const e=t.charAt(n);if(n++,"$"!==e)throw new Xg(n,`expected style end sequence '[/$', instead got '[/${e}'`,t);a=Yg.StyleEnd}const o=n;for(;n<i;){if("]"===t.charAt(n)){const i=t.substring(o,n);return n++,new Jg(i,e,n,"style",a)}n++}throw new Xg(e,"input underflow, missing terminal of style sequence ']'",t)}class Zg{constructor(t,e){this.key=t,this.value=e}equals(t){return this.key===t.key&&this.value===t.value}}function Kg(t,e,i){let n,s=e;for(;s<i&&(n=t.charAt(s)," "===n||"\n"===n||"\t"===n);)s++;return s}const Qg={String:"string",Number:"number",Boolean:"boolean",Array:"array",Any:"any"},ty={LiteralString:"literal-string",LiteralNumber:"literal-number",LiteralBoolean:"literal-boolean",Identifier:"identifier",Reference:"reference"};function ey(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 Xg(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 Jg(s,e,n,null,Qg.Number)}function iy(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 Xg(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 Xg(e,`expected 't' or 'f', instead got '${n}'`,t);if("alse"!==t.substring(e+1,e+5))throw new Xg(e,`expected 'false', instead got '${t.substring(e,e+5)}'`,t);s=!1,r=e+5}return new Jg(s,e,r,ty.LiteralBoolean,Qg.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 Xg(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 Xg(e,"Expected string terminator : "+s+", but found '"+r+"' instead",t);return n++,new Jg(a,e,n,ty.LiteralString,Qg.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=Kg(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=ey(t,n,i);if(n=e.end,r=e.value,n<i&&"."===t.charAt(n)){n++;const e=ey(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 Xg(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 Xg(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 Jg(a,e,r,null,Qg.Number)}(t,n,i);n=e.end,r=e.value}return r*=s,new Jg(r,e,n,ty.LiteralNumber,Qg.Number)}(t,e,i);case"[":return function(t,e,i){let n=e;const s=t.charAt(n);if("["!==s)throw new Xg(e,`expected array start: '[', got '${s}' instead`,t);n++;const r=[];for(;n<i;){n=Kg(t,n,i);const e=iy(t,n,i);if(n=e.end,r.push(e),n=Kg(t,n,i),!(n<i))throw new Xg(n,"Unterminated array literal",t);{const e=t.charAt(n);if(","!==e){if("]"===e){n++;break}throw new Xg(n,`Unexpected input '${e}', expected either separator ',' or end of sequence ']'`,t)}n++}}return new Jg(r,e,n,"array",Qg.Array)}(t,e,i);default:throw new Xg(e,"Expected literal start, but found '"+n+"'",t)}}function ny(t,e,i){let n,s,r;for(s=e;;){if(s>=i)throw new Xg(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 Xg(s,`Input underflow while reading reference value, value so far='${t.substring(a,i)}'`,t);const o=iy(t,s,i);s=o.end;const l=new Zg(r,o.value);return new Jg(l,e,s,"reference-value",Yg.ReferenceValue)}class sy{constructor(t,e){this.type=t,this.values=e}}function ry(t,e,i){let n,s=e;const r=t.charAt(e);if("["!==r)throw new Xg(e,`expected reference start: '[', got '${r}' instead`,t);s++;const a=s;let o;for(;;){if(s>=i)throw new Xg(e,"input underflow, expected reference separator ':' is missing",t);if(":"===t.charAt(s)){o=t.substring(a,s),s++;break}s++}s=Kg(t,s,i),n=t.charAt(s);let l={};if("]"!==n){for(;;){s=Kg(t,s,i);const e=ny(t,s,i);s=e.end,s=Kg(t,s,i);const r=e.value;if(l[r.key]=r.value,n=t.charAt(s),","!==n)break;s++}s=Kg(t,s,i),n=t.charAt(s)}if("]"===n){s++;const t=new sy(o,l);return new Jg(t,e,s,"reference",Yg.Reference)}throw new Xg(s,"input underflow, expected reference end ']' is missing",t)}function ay(t,e,i){let n=e;for(;n<i&&"["!==t.charAt(n);)n++;const s=t.substring(e,n);return new Jg(s,e,n,"text",Yg.Text)}function oy(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?$g(t,e,i):ry(t,e,i)}else s=ay(t,e,i);if(void 0===s)break;n.push(s),e=s.end}return n}const ly=/\$\{([a-zA-Z0-9_]+)\}/gi;class hy{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 hy;return e.fromJSON(t),e}}const cy=Object.freeze({}),uy=Object.freeze(new hy);class dy{constructor(){this.assetManager=null,this.json={},this.language_metadata=uy,this.locale=new hd(""),this.debug=!0,this.__failure_cache=new nf({maxWeight:1024,keyHashFunction:t=>Y_(t,ld)})}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(ly,(function(t,e){return"0"}));try{oy(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=hy.fromJSON(i[t])}),(t=>{this.language_metadata=uy}));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:qg(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=cy){const i=this.json[t];return void 0===i?(this.debug&&this.__debugMissingKey(t,e),`@${t}`):function(t,e){return t.replace(ly,(function(t,i){return e[i]}))}(i,e)}hasString(t){return void 0!==this.json[t]}}class py{#O=new Map;#F=new Map;constructor(){this.proxy=new Proxy(this,{get(t,e,i){const n=t.get(e);if(void 0===n)throw new Error(`Module '${e}' not found in the registry`);return n}})}traverse(t){this.#O.forEach(((e,i)=>t(i,e)))}get(t){return this.#O.get(t)}has(t){return this.#O.has(t)}add(t,e){if(this.has(t))return this.get(t),!1;this.#O.set(t,e);let i=this.#F.get(e);return void 0===i&&(i=[],this.#F.set(e,i)),i.push(t),!0}findNamesByModule(t){const e=this.#F.get(t);if(void 0===e)throw new Error("Module not found");return e}initialize(){}}function fy(t){return t.children instanceof Array}class my{#R=0;#k=-1;constructor(t=1,e=15){this.quietTime=t,this.workTime=e,this.queueUnresolved=[],this.queueReady=[],this.on={task_started:new y,task_completed:new y,completed:new y},this.busy=!1,this.policy=_y.ROUND_ROBIN}runGroup(t){const e=t.state.getValue();if(e!==Ef.INITIAL)throw new bu(`Expected task state INITIAL, instead got ${_g(Ef,e)}`);const i=this,n=t.children,s=n.length;let r=s,a=!1;function o(){a||(a=!0,t.state.set(Ef.SUCCEEDED),t.on.completed.send0(),i.prod())}function l(){r--,r<=0&&o()}function h(e){!function(e){a||(a=!0,t.state.set(Ef.FAILED),t.on.failed.send1(e),i.prod())}(e)}if(s>0){t.state.set(Ef.RUNNING);let e=0;for(;e<s;e++){const t=n[e];t.on.completed.add(l),t.on.failed.add(h),fy(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];fy(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(Ef.FAILED),t.on.failed.dispatch(e),!1}finally{const i=performance.now()-e;t.__executedCpuTime+=i}return t.state.set(Ef.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(yy(n)){case gy.READY:t.splice(e,1),n.state.set(Ef.READY),this.startTask(n),e=0,i=t.length;break;case gy.FAILED:t.splice(e,1),i--,e--}}}contains(t){return-1!==this.queueUnresolved.indexOf(t)||-1!==this.queueReady.indexOf(t)}#B(){const t=this.queueReady;switch(this.policy){case my.POLICY.ROUND_ROBIN:return t[this.#R%t.length];default:case my.POLICY.SEQUENTIAL:return t[0]}}#U(t){const e=this.queueReady,i=e.indexOf(t);-1!==i&&e.splice(i,1),t.state.set(Ef.SUCCEEDED),t.on.completed.send1(this),this.resolveTasks(),this.on.task_completed.send1(t)}#V(t,e){const i=this.queueReady,n=i.indexOf(t);-1!==n&&i.splice(n,1),t.state.set(Ef.FAILED),t.on.failed.send1(e),this.resolveTasks(),this.on.task_completed.send1(t)}#W(t,e){let i=0;const n=t.cycle,s=performance.now(),r=s+e;let a,o=s+1e-6;for(;o<r;)if(i++,a=n(),o=performance.now(),2!==a){if(3===a)break;if(0===a)break;if(1===a)break;throw new Error(`Task '${t.name}' produced unknown signal: `+a)}const l=o-s;return t.__executedCpuTime+=l,t.__executedCycleCount+=i,0===a?this.#U(t):1===a&&this.#V(t,"Task signalled failure"),l}#G=this.#H.bind(this);#H(){let t=this.workTime,e=0;const i=this.queueReady;for(;i.length>0;){const i=this.#B();if(void 0===i)break;try{e=this.#W(i,t)}catch(t){this.#V(i,t)}if(this.#R++,t-=Math.max(e,1),t<=0)break}0===this.queueReady.length?(this.busy=!1,this.on.completed.send0()):this.#k=setTimeout(this.#G,this.quietTime)}prod(){this.resolveTasks(),!this.busy&&this.queueReady.length>0&&(this.busy=!0,this.#H())}join(t){0===this.queueReady.length&&0===this.queueUnresolved.length?t():this.on.completed.addOne(t)}}const _y={ROUND_ROBIN:0,SEQUENTIAL:1,TIME_SLICE:2};my.POLICY=_y;const gy={READY:0,FAILED:1,UNRESOLVED:2};function yy(t){const e=t.dependencies;let i=0;const n=e.length;for(;i<n;i++)switch(e[i].state.getValue()){case Ef.INITIAL:case Ef.RUNNING:case Ef.READY:return gy.UNRESOLVED;case Ef.SUCCEEDED:break;default:return gy.FAILED}return gy.READY}const vy=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 xy(t){let e;return e=t instanceof vy?t.el:t,e}function wy(t,e){return new vy(t,e)}function by(t,e){this.view=t,this.name=e}vy.prototype.createChild=function(t){const e=new vy(t);return this.append(e),e},vy.prototype.append=function(t){const e=xy(t);return this.el.appendChild(e),this},vy.prototype.remove=function(t){const e=xy(t);return this.el.removeChild(e),this},vy.prototype.text=function(t){return this.el.innerText=t,this},vy.prototype.select=function(t){const e=this.el.querySelector(t);return null===e?null:wy(e)},vy.prototype.addClass=function(t){return this.el.classList.add(t),this},vy.prototype.removeClass=function(t){return this.el.classList.remove(t),this},vy.prototype.setClass=function(t,e){return this.el.classList.toggle(t,e),this},vy.prototype.css=function(t){for(let e in t)t.hasOwnProperty(e)&&(this.el.style[e]=t[e]);return this},vy.prototype.attr=function(t){const e=this.el;for(let i in t)t.hasOwnProperty(i)&&e.setAttribute(i,t[i]);return this},vy.prototype.clone=function(){return new vy(this.el.cloneNode(!0))},vy.prototype.clear=function(){const t=this.el;for(;t.children.length>0;)t.removeChild(t.children[0]);return this},vy.prototype.on=function(t,e){return this.el.addEventListener(t,e),this},vy.prototype.off=function(t,e){return this.el.removeEventListener(t,e),this};class Sy extends Bg{constructor(){super();const t=wy("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 by(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]}}class My{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 Ty{constructor(t=new Map){this.on={set:new y,deleted:new y},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 Ay{constructor(t=16){const e=Jd(Mu(1,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;nd(this.__data,n,i,0,t-n),nd(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]}}Ay.prototype.peek=Ay.prototype.getFirst,Ay.prototype.push=Ay.prototype.addFirst,Ay.prototype.pop=Ay.prototype.removeFirst,Ay.prototype.add=Ay.prototype.addLast;class Cy{constructor({keyHashFunction:t=Hp,keyEqualityFunction:e=Gp,capacity:i}={}){this.__map=new Zp({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 Ey{constructor(t,e){this.path=t,this.type=e}equals(t){return this.path===t.path&&this.type===t.type}hash(){return rd(ld(this.path),ld(this.type))}toString(){return`{ type: '${this.type}', path: '${this.path}' }`}}Ey.prototype.isAssetDescription=!0;class zy{constructor(t,e,i){this.successCallback=t,this.failureCallback=e,this.pogressCallback=i,this.priority=1,this.scope=null,this.flags=0}get scoped_priority(){const t=this.priority,e=this.scope;return null===e?t:t*e.final_priority}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}}let Ly=0;class Iy{id=Ly++;priority=1;sources=[];get final_priority(){const t=this.sources,e=t.length;if(0===e)return this.priority;let i=t[0].final_priority;for(let n=0;n<e;n++){const e=t[n].final_priority;e>i&&(i=e)}return this.priority*i}static from(t){const e=new Iy;return e.sources=t,e}toString(){const t=this.sources.length>0?`[ ${this.sources.join(", ")} ]`:"none";return`Scope{ id:${this.id}, sources:${t} }`}}Iy.GLOBAL=Object.freeze(new Iy);const Ny=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 y,this.onOverflow=new y,this.onFilled=new y,this.on={changed:this.onChanged,overflow:this.onOverflow}};Ny.prototype.setUpperLimit=function(t){const e=this.__limitUpper;t!==e&&(this.__limitUpper=t,this.onChanged.send4(this.__value,this.__limitUpper,this.__value,e))},Ny.prototype.getUpperLimit=function(){return this.__limitUpper},Ny.prototype.getLowerLimit=function(){return this.__limitLower},Ny.prototype.setLowerLimit=function(t){t!==this.__limitLower&&(this.__limitLower=t,this.onChanged.dispatch())},Ny.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()},Ny.prototype.getValue=function(){return this.__value},Ny.prototype.getFraction=function(){return Gd(this.__limitLower,this.__limitUpper,this.__value)},Ny.prototype.setValueToLimit=function(){this.setValue(this.__limitUpper)},Ny.prototype.isValueAtLimit=function(){return this.__value===this.__limitUpper},Ny.prototype.addValue=function(t){this.setValue(this.__value+t)},Ny.prototype.copy=function(t){return this.setUpperLimit(t.getUpperLimit()),this.setValue(t.getValue()),this},Ny.prototype.equals=function(t){return this.__value===t.__value&&this.__limitLower===t.__limitLower&&this.__limitUpper===t.__limitUpper},Ny.prototype.hash=function(){const t=E(this.__value),e=(t<<5)-t+E(this.__limitLower);return(e<<5)-e+E(this.__limitUpper)},Ny.prototype.toJSON=function(){return{value:this.__value,limit:this.__limitUpper}},Ny.prototype.fromJSON=function(t){this.setUpperLimit(t.limit),this.setValue(t.value)},Ny.prototype.toBinaryBuffer=function(t){t.writeFloat64(this.__value),t.writeFloat64(this.__limitUpper)},Ny.prototype.fromBinaryBuffer=function(t){const e=t.readFloat64(),i=t.readFloat64();this.setUpperLimit(i),this.setValue(e)};class Py{constructor(t){this.description=t,this.requests=[],this.progress=new Ny(0,0),this.state=0}get priority(){const t=this.requests,e=t.length;if(0===e)return 0;let i=t[0].priority;for(let n=1;n<e;n++){const e=t[n];e.scoped_priority>i&&(i=e)}return i}}let Dy=class{constructor(t,e){this.asset=t,this.request=e}};function Oy(t){return-t.priority}class Fy{assets=new Zp({capacity:1024});request_map=new Ty(new Zp);#j=new My(Oy);#q=new Set;load_concurrency=Infinity;#J={};#Y={};#X=new Map;rootPath="";crossOriginConfig=new om;#$=new Cy;#Z=new Ay;#K=new Lf({name:"Asset Manager Response processor",cycleFunction:()=>{if(this.#Z.isEmpty())return 3;const t=this.#Z.removeFirst();return this.#Q(t),2}});#tt=!1;#et=null;#it=null;constructor({context:t,executor:e=new my}={}){this.#et=t,this.#it=e}startup(){this.#tt||(this.#it.run(this.#K),this.#tt=!0)}async shutdown(t=!1){this.#tt&&(t||await Promise.allSettled([Lf.promise(this.#K)]),this.#it.removeTask(this.#K),this.#tt=!1)}remove(t,e){const i=new Ey(t,e);return this.assets.delete(i)}clear(){this.assets.clear()}dumpLoadedAssetList(){return JSON.stringify(function(t){const e={"texture-deferred":3,[Lu]:3,"image/svg":3,[Nu]:3,[Iu]:1,arraybuffer:1,"three.js":2,"model/gltf+json":2,"model/gltf":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,{scope:i,skip_queue:n=!1}={}){return new Promise(((n,s)=>{this.get({path:t,type:e,callback:n,failure:s,scope:i})}))}get({path:t,type:e,callback:i,failure:n=console.error,progress:s=Ud,skip_queue:r=!1,scope:a=null}){if("string"!=typeof t)throw new TypeError(`Path must be string. instead was '${typeof t}'`);if("string"!=typeof e)throw new TypeError(`type must be a string, instead was '${typeof e}'`);const o=new Ey(t,e),l=this.assets.get(o);if(void 0!==l)i(l);else{const t=new zy(i,n,s);t.scope=a,t.writeFlag(1,r),this.submitRequest(o,t)}}insert(t,e,i){const n=new Ey(t,e);this.assets.get(n),this.assets.set(n,i)}#Q(t){try{t.request.successCallback(t.asset)}catch(t){}}#nt(t,e){this.#Z.add(new Dy(t,e))}#st(t){this.#q.size<this.load_concurrency?this.#rt(t):this.#j.push(t)}#at(t){this.#q.has(t)||(this.#j.delete(t),this.#rt(t))}#ot(t){const e=this.#q;this.request_map.delete(t.description),e.delete(t);const i=this.#j;for(;!i.isEmpty()&&e.size<this.load_concurrency;){const t=i.pop();this.#rt(t)}}#rt(t){const e=t.requests,i=t.description,n=i.type,s=i.path,r=this.#J[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.#J).join(", ")}`)}return void this.#ot(t)}this.#q.add(t);const a=this.assets,o=this.#$,l=async s=>{if(3===t.state)return;t.state,t.state=3;let r=s;const o=this.#Y[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.#ot(t);for(let t=0;t<e.length;t++){const i=e[t];this.#nt(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.#ot(t),o.add(i)}},c=[];for(let t=0;t<e.length;t++){const i=e[t].scope;null!==i&&Cf(c,i)}let u;u=c.length>0?Iy.from(c):Iy.GLOBAL;const d=this.rootPath+s;try{r.load(u,d,l,h,(function(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)}))}catch(t){h(t)}}submitRequest(t,e){const i=this.request_map;let n=!1,s=i.get(t);void 0===s&&(s=new Py(t),i.set(t,s),n=!0),s.requests.push(e),n?this.#st(s):this.#j.updateElementScore(s),e.getFlag(1)&&this.#at(s)}hasLoaderForType(t){return void 0!==this.getLoaderByType(t)}getLoaderByType(t){return this.#J[t]}#lt(t){return Array.from(this.assets.keys()).filter((e=>e.type===t))}registerTransformer(t,e){let i=this.#Y[t];void 0===i&&(i=[],this.#Y[t]=i),i.push(e),this.#lt(t).length}unregisterTransformer(t,e){const i=this.#Y[t];return void 0!==i&&!!Ym(i,e)&&(this.#lt(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`)}let n=e;return"function"==typeof n?(n=new hm,n.load=e):await n.link(this,this.#et),this.#J[t]=n,n}async unregisterLoader(t){const e=this.getLoaderByType(t);void 0!==e&&(delete this.#J[t],await e.unlink())}tryGet(t,e){const i=new Ey(t,e),n=this.assets.get(i);return void 0!==n?n:null}isFailed(t,e){const i=new Ey(t,e);return this.#$.has(i)}promiseByAlias(t){const e=this.#X.get(t);return void 0===e?new Promise.reject(`Alias '${t}' not found`):this.promise(e.path,e.path)}resolveAlias(t){return this.#X.get(t)}assignAlias(t,e,i){const n=new Ey(e,i);this.#X.set(t,n)}}Fy.prototype.isAssetManager=!0;const Ry={CRITICAL:0,HIGH:1,NORMAL:2,OPTIONAL:3};class ky{constructor(){this.uri=null,this.type=null,this.level=Ry.OPTIONAL,this.priotity=0}fromJSON({uri:t,type:e,level:i=Ry.OPTIONAL,priority:n=0}){this.uri=t,this.type=e,this.level=i,this.priotity=n}static fromJSON(t){const e=new ky;return e.fromJSON(t),e}}const By=function(){this.totalAssetCount=0;const t=this.assets=[];for(let e in Ry)Ry.hasOwnProperty(e)&&(t[Ry[e]]=[]);this.on={added:new y,progress:new y,levelFinished:new y,error:new y,loadStart:new y,completed:new y}};By.prototype.add=function(t,e,i,n){void 0===i&&(i=Ry.OPTIONAL);const s=this.assets,r=ky.fromJSON({uri:t,type:e,priority:n});return s.hasOwnProperty(i)||(i=Ry.OPTIONAL),s[i].push(r),this.totalAssetCount++,this.on.added.send2(r,i),this},By.prototype.addAll=function(t){const e=this;t.forEach((function(t){e.add(t.uri,t.type,t.level)}))},By.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.send1(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({path:e.uri,type:e.type,callback:h,failure:c})}))}(a)}else e.completed.send0()}(),this};class Uy{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 Vy{constructor(t){this.size=t,this.head=0,this.tail=0,this.count=0,this.data=new Array(t)}resize(t){if(t===this.size)return;const e=new Array(t);this.data=e,this.size=t,this.count=C(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)}}function Wy(t,e){return t-e}class Gy extends Uy{constructor(t=100){super(),this.__data=new Vy(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.median=0,t.min=0,t.max=0,!1):(t.mean=function(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}(i,0,n),t.median=function(t,e,i){const n=t.slice();return n.sort(Wy),n[0+(i-0>>1)]}(i,0,n-1),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 Hy{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 Gy(e);return this.add(t,i),i}add(t,e){this.data.set(t,e)}get(t){return this.data.get(t)}}class jy{mean=0;median=0;max=0;min=0;toString(){return`{min:${this.min}, max:${this.max}, mean:${this.mean}, median:${this.median}`}}class qy{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 Jy{upgraders=new Map;serializers=new Map;registerAdapters(t){t.forEach((t=>{this.registerAdapter(t)}))}registerAdapter(t,e){let i=e;if(void 0===i){const e=t.getClass();if("string"!=typeof e.typeName)throw new Error("className not specified, could not infer class name from the class itself");i=e.typeName}return!this.serializers.has(i)&&(this.serializers.set(i,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 n_,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}}Jy.prototype.isBinarySerializationRegistry=!0;class Yy{constructor(){}record(t,e){}}class Xy extends Yy{record(t,e){}}Xy.INSTANCE=new Xy;const $y=new class extends Yy{constructor(){super(),this.target=Xy.INSTANCE}setTarget(t){this.target=t}record(t,e){this.target.record(t,e)}};class Zy{constructor(){this.layerTargets=[],this.camera=new Pr(-1,1,1,-1,0,1),this.scene=new fl,this.size=new Tu(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=0){let i;if(t instanceof $i||t instanceof Zi)i=t;else{const e={minFilter:ie,magFilter:ie,format:ve,depthBuffer:!1,stencilBuffer:!1,generateMipmaps:!1};for(let i in t)t.hasOwnProperty(i)&&(e[i]=t[i]);i=new Zi(1,1,e)}const n=new Sg({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)}}class Ky{#ht=new y;#ct=null;#ut=!1;get bound(){return this.#ut}get onReleased(){return this.#ht}bind(t){if(t!==this.#ct){if(this.#ut)throw new Error("Reference is already bound, must release before binding to a new value");this.#ct=t,this.#ut=!0}}getValue(){return this.#ct}release(){if(!this.#ut)return;const t=this.#ct;this.#ct=null,this.#ut=!1,this.#ht.send2(this,t)}}Ky.NULL=Object.freeze(new Ky);class Qy{constructor(t){this.__source=null,this.__material=t,this.__ref_count=0,this.onLastReleased=new y}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 Ky;return t.bind(this.__material),t.onReleased.add(this.__release_reference,this),this.__ref_count++,t}}class tv{constructor(){this.__library=new Zp({keyHashFunction:Z_,keyEqualityFunction:eg,capacity:1024}),this.__cache=new nf({keyHashFunction:Z_,keyEqualityFunction:eg,maxWeight:100}),this.__reverse_library=new Zp({keyHashFunction:Z_,keyEqualityFunction:eg,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 Qy(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()}}class ev{renderTarget=null;referenceCount=0;dependencies=[];size=new Tu(0,0);constructor(t){this.id=t}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 iv extends ev{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 Vi;t.getSize(i);const n=new Zi(i.x,i.y,{ignoreDepth:!1});n.texture.format=ye,n.texture.minFilter=Qt,n.texture.magFilter=Qt,n.texture.generateMipmaps=!1,n.texture.encoding=Si,n.stencilBuffer=!1,n.depthBuffer=!0,n.depthTexture=new cl,n.depthTexture.format=be,n.depthTexture.type=ue,n.depthTexture.generateMipmaps=!1,n.depthTexture.internalFormat="DEPTH_COMPONENT32F",this.renderTarget=n}}const nv=[];class sv{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 kl(n,null):new er(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=x_,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)&&(nv[l++]=t)}for(;l>0;){const e=nv[--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];nv[l++]=t}}o.length=h}}sv.INSTANCE=new sv;class rv extends ev{constructor(t){super(t),this.dependencies.push(Pg)}initialize(t){super.initialize(t),t.extensions.get("EXT_color_buffer_float");const e=new Vi;t.getSize(e);const i=new Zi(e.x,e.y,{minFilter:Qt,magFilter:Qt,format:ve,type:de,depthBuffer:!0,stencilBuffer:!1,generateMipmaps:!1});i.texture.internalFormat="RGBA16F",this.renderTarget=i,this.__material_static=new lc({depthWrite:!0}),this.__material_skinned=new lc({depthWrite:!0}),this.__material_static.side=st,this.__material_skinned.side=st;const n=new fl;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),sv.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)}}const av=[];function ov(){this.buffers=[],this.needsRebuild=!1,this.orderedBuffers=[],this.pixelRatio=1}function lv(t){return t}function hv(t,e){return t.id-e.id}function cv(t,e){const i=t.length-e;i>0&&t.splice(e,i)}ov.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}'`)}},ov.prototype.build=function(){this.orderedBuffers=this.computeRenderOrder(),this.needsRebuild=!1},ov.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},ov.prototype.getById=function(t){return this.buffers.find((function(e){return e.id===t}))},ov.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},ov.prototype.update=function(){this.needsRebuild&&this.build()},ov.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}},ov.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(av,s),s.render(t,e,i,av))}},ov.prototype.setPixelRatio=function(t){this.pixelRatio=t},ov.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 uv{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 y,this.onAdded=new y,this.onRemoved=new y,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 bu("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(){const t=this.__elements_cursor,e=this.__swap_elements_count;this.size=t;const i=this.__elements,n=this.__swap_elements,s=this.__compare,r=this.onAdded,a=this.onRemoved;cv(i,t),i.sort(s);let o=0,l=0;for(;o<t&&l<e;){const t=i[o],e=n[l],h=s(t,e);0===h?(o++,l++):h<0?(o++,r.send1(t)):(l++,a.send1(e))}for(;o<t;o++)r.send1(i[o]);for(;l<e;l++)a.send1(n[l]);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)}}}uv.prototype.isIncrementalDeltaSet=!0;class dv{constructor(){this.visible=!0}copy(t){this.visible=t.visible}clone(){const t=new dv;return t.copy(this),t}}class pv{state=new dv;name=null;managed=!1;extractRenderable=lv;visibleSet=new uv(hv);get visible(){return this.state.visible}set visible(t){this.state.visible=t}computeNearFarClippingPlanes(t,e,i,n,s){throw new Error("deprecated")}buildVisibleSet(t,e,i){throw new Error("deprecated")}}class fv{data=[];on={removed:new y,added:new y};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 mv{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 _v{constructor(){this.__stateStack=new fv,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 mv;return t.read(this),this.__stateStack.push(t),t}popState(){this.__stateStack.isEmpty()||this.__stateStack.pop().write(this)}create(t){const e=new pv;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 gv={tTexture:{type:"t",value:null}},yv=new or({uniforms:gv,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:wg(),blending:at,lights:!1,fog:!1,depthTest:!1,depthWrite:!1,transparent:!0,vertexColors:!1}),vv=new xr,xv=new Float32Array(16);class wv{constructor(){this.name="",this.__camera=null,this.frustum=new Float32Array(24),this.projection_matrix=new Float32Array(16),this.bounding_box=new cp,this.visible_objects=new uv(hv),this.flags=7,this.on={preVisibilityBuild:new y,postVisibilityBuild:new y,preRender:new y},this.projection_modifiers=[]}addProjectionModifier(t){this.projection_modifiers.push(t)}removeProjectionModifier(t){return Ym(this.projection_modifiers,t)}set_from_camera(t){this.__camera=t,Im(t,vv,!1),Of(vv.planes,this.frustum),nd(t.projectionMatrix.elements,0,this.projection_matrix,0,16);let e=this.projection_matrix,i=xv;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&&nd(e,0,this.projection_matrix,0,16),nd(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 bv=[];class Sv{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(bv,0,this.__view);for(let t=0;t<e;t++){const e=bv[t];this.__output.push(e),this.__activeLayer.visibleSet.push(e)}}set output(t){this.__output=t}build(t){t.traverse(this.__processLayer,this)}}class Mv{constructor(){this.__data=new of,this.__visibility_computer=new Sv,this.on={preViewBuild:new y,postViewBuild:new y}}get elements(){return this.__data}create(){const t=new wv;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()}))}}const Tv=new or({uniforms:{shadow_pass:{value:null},resolution:{value:new Vi},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"}),Av=Tv.clone();Av.defines.HORIZONTAL_PASS=1;const Cv=new bs;class Ev{constructor(){this.__renderer=null,this.onBeforeRender=new y}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(Cv);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===et&&this.__do_vsm_pass(e)),t.setRenderTarget(r,a,o),t.setScissorTest(l),t.setClearColor(Cv,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;Tv.defines.VSM_SAMPLES!==t.blurSamples&&(Tv.defines.VSM_SAMPLES=t.blurSamples,Av.defines.VSM_SAMPLES=t.blurSamples,Tv.needsUpdate=!0,Av.needsUpdate=!0);const i=Tv.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(),Lg(e,Tv);const n=Av.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(),Lg(e,Av)}__ensure_map(t,e){const i=t.mapSize;if(null===t.map){const n={format:ve,scissorTest:!1,stencilBuffer:!1};t.isPointLightShadow||e.shadowMap.type!==et?(n.minFilter=Qt,n.magFilter=Qt):(n.minFilter=ie,n.magFilter=ie,t.mapPass=new $i(i.x,i.y,Object.assign({depthBuffer:!1},n))),t.map=new $i(i.x,i.y,n),t.map.texture.name=".shadowMap",t.camera.updateProjectionMatrix()}}}class zv{#dt=!1;constructor({camera:t,debug:e=!1}){this.#dt=e;const i=this;this.__material_manager=new tv,this.on={preRender:new y,postRender:new y,preOpaquePass:new y,postOpaquePass:new y,preComposite:new y,postComposite:new y,buffersRendered:new y,visibilityConstructionStarted:new y,visibilityConstructionEnded:new y},this.pixelRatio=new sd(1),this.layers=new _v;const n=new fl;n.autoUpdate=!1,n.matrixAutoUpdate=!1,this.scene=n,this.visibleGroup=new ol,this.visibleGroup.matrixAutoUpdate=!1,this.scene.add(this.visibleGroup),this.camera=t,this.renderer=null,this.layerComposer=new Zy,Object.defineProperties(this,{info:{get:function(){return i.renderer.info}}}),this.viewport=new Ug,this.viewport.size.onChanged.add(this.updateSize,this),this.pixelRatio.onChanged.add(this.updateSize,this),this.frameBuffers=new ov,this.shadowmap_renderer=new Ev,this.views=new Mv,this.main_view=this.views.create(),this.main_view.name="Main Camera",this.needDraw=!0,this.autoDraw=!0,this.frameIndex=0,this.intersectObjectUnderViewportPoint=function(){const t=new Qi,e=new du,i=new Qi;return function(n,s,r,a){return this.viewportProjectionRay(n,s,i,t),e.set(i,t),e.intersectObject(r,a)}}()}getMaterialManager(){return this.__material_manager}getRenderer(){return this.renderer}updateSize(){const t=this.viewport.size,e=this.renderer,i=this.pixelRatio.getValue(),n=Mu(0,t.x*i),s=Mu(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)}getResolution(t){const e=this.computeTotalPixelRatio();t.set(this.viewport.size.x*e,this.viewport.size.y*e)}computeTotalPixelRatio(){return this.pixelRatio.getValue()*window.devicePixelRatio}initializeFrameBuffers(){const t=new iv(Pg);t.referenceCount+=1,this.frameBuffers.add(t);const e=new rv(Dg);this.frameBuffers.add(e),this.frameBuffers.initialize(this.renderer)}start(){const t=document.createElement("canvas"),e=t.getContext("webgl2",{antialias:!1}),i={antialias:!0,logarithmicDepthBuffer:!1,canvas:t,context:e,powerPreference:"high-performance"},n=this.renderer=new pl(i),s=this.getGPUName();$y.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=bi,t.toneMapping=kt,t.toneMappingExposure=1,t.state.setFlipSided(!1),t.shadowMap.enabled=!0,t.shadowMap.type=et,t.sortObjects=!0,t.info.autoReset=!1}(n),n.debug.checkShaderErrors=this.#dt,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}getGPUName(){const t=this.renderer.getContext(),e=t.getExtension("WEBGL_debug_renderer_info");return null===e?"Unknown":t.getParameter(e.UNMASKED_RENDERER_WEBGL)}stop(){const t=this.renderer;void 0!==t&&(t.forceContextLoss(),t.context=null,t.domElement=null,this.renderer=null)}enableExtensions(){const t=this.renderer.getContext();t.getExtension("OES_standard_derivatives"),t.getExtension("WEBGL_depth_texture"),t.getExtension("WEBGL_compressed_texture_s3tc")}viewportProjectionRay(t,e,i,n){Fm.projectRay(this.camera,t,e,i,n)}normalizeViewportPoint(t,e){const i=this.viewport.size,n=t.x+.5,s=t.y+.5;e.x=n/i.x*2-1,e.y=-s/i.y*2+1}constructVisibleScene(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)}clearVisibleGroup(){this.visibleGroup.children.length=0}prepareRenderPass(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];Lv(s)===t&&(s.parent=e,e.children[i++]=s)}e.length=i}renderOpaque(){this.on.preOpaquePass.send0(),this.prepareRenderPass(1);const t=this.renderer,e=this.frameBuffers;e.render(t,this.camera,this.scene);const i=e.getById(Pg);if(void 0===i)throw new Error("No color-depth frame buffer");!function(t,e){gv.tTexture.value=t,Lg(e,yv)}(i.renderTarget.texture,t),this.on.postOpaquePass.send0()}renderTransparent(){const t=this.scene,e=t.background;t.background=null,this.prepareRenderPass(2),this.renderer.render(t,this.camera),t.background=e}render(){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)}}function Lv(t){if(t.isMesh||t.isPoints){const e=t.material;if(!1===e.depthWrite&&!1===e.depthTest)return 2}return 1}const Iv={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},Nv="keyup",Pv="keydown";class Dv{down=new y;up=new y;is_down=!1}function Ov(t,e){return null!=e&&"object"==typeof e&&t instanceof e}const Fv=[];class Rv{on={down:new y,up:new y};keys={};constructor(t){var e;Ov(e=t,HTMLInputElement)||Ov(e,HTMLSelectElement)||Ov(e,HTMLTextAreaElement)||Ov(e,HTMLAnchorElement)||Ov(e,HTMLButtonElement)||Ov(e,HTMLAreaElement)||t.getAttribute("tabindex"),this.domElement=t;for(let t in Iv)Fv[Iv[t]]=t,this.keys[t]=new Dv}#pt=t=>{this.on.down.send1(t);const e=t.keyCode,i=Fv[e];if(void 0!==i){const e=this.keys[i];e.is_down=!0,e.down.send1(t)}};#ft=t=>{this.on.up.send1(t);const e=t.keyCode,i=Fv[e];if(void 0!==i){const e=this.keys[i];e.is_down=!1,e.up.send1(t)}};start(){this.domElement.addEventListener(Pv,this.#pt),this.domElement.addEventListener(Nv,this.#ft)}stop(){this.domElement.removeEventListener(Pv,this.#pt),this.domElement.removeEventListener(Nv,this.#ft)}}const kv="mousedown",Bv="mouseup",Uv="mousemove",Vv="mouseenter",Wv="mouseleave",Gv="wheel",Hv="touchstart",jv="touchend",qv="touchmove";function Jv(t){return t.preventDefault(),t.stopPropagation(),!1}function Yv(t,e){const i=t.length;for(let n=0;n<i;n++)e(t.item(n),n)}function Xv(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)}class $v{position=new Tu;#mt=new Tu;#_t=new y;#gt=new y;#yt=new y;#vt=new y;on={down:new y,up:new y,move:new y,tap:new y,drag:new y,dragStart:new y,dragEnd:new y,wheel:new y,pinch:new y,pinchStart:new y,pinchEnd:new y};#xt=null;isRunning=!1;buttons=new Array(32);get mouseButtonLeft(){return this.buttons[0]}get mouseButtonRight(){return this.buttons[2]}get mouseButtonMiddle(){return this.buttons[1]}constructor(t){for(let t=0;t<this.buttons.length;t++)this.buttons[t]=new Dv;this.domElement=t,this.#gt.add(((t,e,i)=>{this.on.down.send3(t,e,i)})),this.#yt.add(((t,e,i)=>{this.on.up.send3(t,e,i)})),this.#vt.add(((t,e,i)=>{this.on.move.send3(t,e,i)})),function(t,e,i,n,s){const r=new Tu;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 Tu;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 Tu;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)}))}(this.#_t,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 Tu,l=new Tu,h=new Tu,c=new Tu;let u=!1,d=0;function p(t,e){Xv(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){Yv(e.changedTouches,(function(t){d--,d<2&&u&&(u=!1,i.remove(f),r.send0())}))})),t.add((function(t,e){Yv(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:this.#gt,touchEnd:this.#yt,touchMove:this.#vt,pinch:this.on.pinch,pinchStart:this.on.pinchStart,pinchEnd:this.on.pinchEnd,device:this})}#wt=t=>{this.readPointerPositionFromEvent(this.position,t),this.on.down.send2(this.position,t);const e=t.button,i=this.buttons[e];void 0!==i&&(i.is_down=!0,i.down.send0())};#bt=t=>{Xv(t.touches,this.position),this.#_t.send2(this.position,t)};#St=t=>{this.readPointerPositionFromEvent(this.position,t),this.on.up.send2(this.position,t)};#Mt=t=>{this.readPointerPositionFromEvent(this.position,t),this.#_t.send2(this.position,t);const e=t.button,i=this.buttons[e];void 0!==i&&(i.is_down=!1,i.up.send0())};#Tt=t=>{Xv(t.touches,this.position),this.#yt.send2(this.position,t)};#At=t=>{t.preventDefault(),Xv(t.touches,position);const e=new Tu;e.subVectors(this.position,this.#mt),this.#vt.send3(this.position,t,e),this.#mt.copy(this.position)};#Ct=t=>{t.preventDefault();const e=I(t.deltaX),i=I(t.deltaY),n=I(t.deltaZ),s=new O(e,i,n);this.readPointerPositionFromEvent(this.position,t),this.on.wheel.send3(s,this.position,t)};#Et=t=>{Xv(t.touches,this.position),this.#gt.send2(this.position,t),this.#mt.copy(this.position)};#zt=t=>{t.preventDefault(),this.#xt=t.target,this.readPointerPositionFromEvent(this.position,t),this.on.move.send3(this.position,t,new Tu(t.movementX,t.movementY))};getTargetElement(){return this.#xt}setTargetElement(t){if(this.#xt===t)return;let e=this.isRunning;e&&this.stop(),this.#xt=t,e&&this.start()}readPointerPositionFromEvent(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)}start(){if(this.isRunning)return;this.isRunning=!0;const t=this.domElement;t.addEventListener(Uv,this.#zt),t.addEventListener(Bv,this.#St),t.addEventListener(kv,this.#wt),t.addEventListener(Hv,this.#Et),t.addEventListener(jv,this.#Tt),t.addEventListener(qv,this.#At),window.addEventListener(Bv,this.#Mt),window.addEventListener(jv,this.#bt),t.addEventListener(Gv,this.#Ct,{passive:!1}),t.addEventListener("contextmenu",Jv)}stop(){if(!this.isRunning)return;this.isRunning=!1;const t=this.domElement;t.removeEventListener(Uv,this.#zt),t.removeEventListener(Bv,this.#St),t.removeEventListener(kv,this.#wt),t.removeEventListener(Hv,this.#Et),t.removeEventListener(jv,this.#Tt),t.removeEventListener(qv,this.#At),window.removeEventListener(Bv,this.#Mt),window.removeEventListener(jv,this.#bt),t.removeEventListener(Gv,this.#Ct),t.removeEventListener("contextmenu",Jv)}}function Zv(t,e="Unnamed"){this.name=e,this.children=t,this.on={started:new y,completed:new y,failed:new y},this.state=new jd(Ef.INITIAL)}function Kv(t){if(t.isTask){const e=t.state.getValue();if(e===Ef.INITIAL||e===Ef.READY)return 0}return t.computeProgress()}Zv.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},Zv.prototype.addChild=function(t){return-1===this.children.indexOf(t)&&(this.children.push(t),!0)},Zv.prototype.addChildren=function(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.addChild(e)}},Zv.prototype.isTaskGroup=!0,Zv.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)}},Zv.prototype.addDependencies=function(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.addDependency(e)}},Zv.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},Zv.prototype.getVerboseStatusMessage=function(){const t=new wf;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}'] ${_g(Ef,i.state.getValue())}`)}(this),t.build()},Zv.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+=Kv(e)*r,n+=r)}return 0===n?0:i/n},Zv.prototype.join=function(t,e){Lf.join(this,t,e)},Zv.prototype.promise=function(){return Lf.promise(this)};class Qv{constructor(){this.table=null,this.id=null,this.source=null}static from(t,e,i){const n=new Qv;return n.id=t,n.source=e,n.table=i,n}}const tx={Initial:0,Loading:1,Loaded:2,Failed:3};class ex{__state=new zm(tx.Initial,tx);__specs=[];#Lt=!1;set validation_enabled(t){this.#Lt=t}reset(){this.__state.set(tx.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!==tx.Initial)throw new bu(`Adding new tables is only allowed in Initial state, current state is ${_g(tx,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=Qv.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===tx.Loaded?e():t===tx.Failed?i("Failed to load Static Knowledge"):void 0}))}))}validate(t){const e=new Zv(this.__specs.map((t=>t.table.validate(this,console.error))),"Database Validation"),i=Lf.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,Iu)).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()!==tx.Initial)throw new Error("Illegal state");this.__state.set(tx.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 this.#Lt&&(i=i.then((()=>this.validate(e)))),i})).then((function(){i.__state.set(tx.Loaded)}),(function(t){i.__state.set(tx.Failed)}))}}ex.prototype.isStaticKnowledgeDatabase=!0;const ix=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)}};class nx{parent=null;constructor(t){this.id=t}computePath(){const t=[];let e=this;for(;null!==e;)t.unshift(e.id),e=e.parent;return t}}class sx extends nx{on={written:new y,writeFailed:new y,settingsUpdated:new y};constructor(t,e,i=Ud,n={transient:!1}){super(t);const s=this;this.read=e,this.write=function(t){let e,n=!1;try{e=i(t)}catch(e){n=!0,s.on.writeFailed.send2(t,e)}return n||(void 0!==e&&"function"==typeof e.then?e.then((()=>s.on.written.send1(t)),(e=>s.on.writeFailed.send2(t,e))):s.on.written.send1(t)),e},this.settings=n,this.isTransient=!0===n.transient}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 rx extends nx{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 sx(t,e,i,n);return this.addChild(s),this}addGroup(t){let e=new rx(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,Ud,console.error,Ud)}return new Promise((function(t,i){e.load(s,t,i)})).then((t=>{void 0!==t&&"string"==typeof t&&n.fromJSON(JSON.parse(t))})).finally((()=>{n.traverseOptions((t=>t.on.written.add(r)))}))}}rx.prototype.isOptionGroup=!0;const ax=[gg.Finalizing,gg.Initializing,gg.Starting,gg.Stopping];function ox(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 lx{constructor(t,e){this.__klass=e,this.__instance=t,this.__references=new of,this.dependency_references=new of,this.on={lastReleased:new y},this.__transition=Promise.resolve()}synchronize(){return this.__transition}transition(t,e){if(ax.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?ox(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?ox(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?ox(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 Ky;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 hx extends yg{__plugins=new Map;engine=null;__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,vg))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 lx(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}}}function cx(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 ux(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}}const dx=[],px=[];class fx{entityOccupancy=new Km;entityGeneration=new Uint32Array(0);componentOccupancy=new Km;componentTypeMap=[];__type_to_index_map=new Map;componentTypeCount=0;components=[];entityCount=0;generation=0;onEntityCreated=new y;onEntityRemoved=new y;__entityEventListeners=[];__entityAnyEventListeners=[];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,r_,(function t(s,r){if(s.klass===e){const e=s.instance;i.removeEntityEventListener(r,r_,t),n(e)}})),i.addEntityEventListener(t,s_,(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))cx(s,i,e,n)&&(ux(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))cx(n,i,e,s)&&(ux(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 Km;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}enlargeGenerationTable(t){const e=this.entityGeneration.length,i=Kd(t,Math.ceil(1.2*e),e+16),n=new Uint32Array(i);n.set(this.entityGeneration),this.entityGeneration=n}getEntityGeneration(t){return this.entityGeneration[t]}createEntityUnsafe(t){this.entityOccupancy.set(t,!0),this.entityGeneration.length<=t&&this.enlargeGenerationTable(t+1);const e=this.generation;this.generation=e+1,this.entityGeneration[t]=e,this.entityCount++,this.onEntityCreated.send1(t)}createEntity(){const t=this.entityOccupancy.nextClearBit(0);return this.createEntityUnsafe(t),t}createEntitySpecific(t){if(this.entityExists(t))throw new Error(`EntityId ${t} is already in use`);this.createEntityUnsafe(t)}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,s_,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,r_,{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}getComponentAsync(t,e,i,n){const s=this.getComponent(t,e),r=s=>{s.klass===e&&(this.removeEntityEventListener(t,r_,r),i.call(n,s.instance))};void 0===s?this.addEntityEventListener(t,r_,r):i.call(n,s)}traverseEntities(t,e,i){let n,s;const r=dx,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;cv(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){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];cx(this.componentOccupancy,t,this.componentTypeCount,e.componentMask)&&(ux(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];cx(this.componentOccupancy,t,this.componentTypeCount,e.componentMask)&&(ux(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 r=new m(e,i);s.push(r)}removeAnyEventListener(t,e,i){let n,s=this.__entityAnyEventListeners[t];return void 0!==s&&(n=void 0===i?v(s,e):x(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 r=s[t];void 0===r&&(r={},s[t]=r);let a=r[e];void 0===a&&(a=[],r[e]=a);const o=new m(i,n);a.push(o)}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?v(r,i):x(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=_x;let o;for(_x+=r,o=0;o<r;o++){const t=s[o];mx[o+a]=t}for(let t=0;t<r;t++){const i=mx[t+a];i.handle.call(i.context,n,e)}_x=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=_x;let a;for(_x+=s,a=0;a<s;a++){const e=t[a];mx[a+r]=e}for(let t=0;t<s;t++){const s=mx[t+r];s.handle.call(s.context,i,n,e)}_x=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 mx=[];let _x=0;class gx{constructor(t="Unnamed"){this.name=t,this.dataset=new fx,this.active=new Em(!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 Lf({name:e,cycleFunction:function(){if(i)return 0;if(n)throw s;return 3},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 yx{#It=null;get current_scene(){return this.#It}#Nt=null;get entity_manager(){return this.#Nt}constructor(t,e){this.scenes=new of,this.#Nt=t,this.clock=e,this.stack=[]}create(t){const e=new gx(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.#It===i&&(this.deactivateCurrentScene(),this.#It=null),this.scenes.remove(e),!0}clear(){return null!==this.#It&&(this.#It.active.set(!1),this.#Nt.detachDataSet(),this.#It=null),this}exists(t){return void 0!==this.getByName(t)}deactivateScene(t){if(t.active.getValue()){try{t.handlePreDeactivation()}catch(t){}t.active.set(!1),this.#Nt.dataset===t.dataset&&this.#Nt.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.#Nt.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.#It=t}deactivateCurrentScene(){const t=this.#It;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.#It===e)return;const i=this.#Nt;e.dataset.registerManyComponentTypes(i.getComponentTypeMap()),this.deactivateCurrentScene(),this.activateScene(e)}stackPush(t){this.stack.push(this.#It.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 vx{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 vx;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 E(this.a)^E(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}}vx.CONSTANT_ONE=Object.freeze(new vx(0,1)),vx.CONSTANT_ZERO=Object.freeze(new vx(0,0));class xx extends Number{constructor(t){super(),this.id=0,this.base=new sd(t),this.__modifiers=new of,this.value=new sd(t),this.base.onChanged.add(this.updateValue,this),this.postprocess=xx.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=xx.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()}hasModifier(t){return this.__modifiers.contains(t)}removeModifier(t){const e=this.__modifiers.removeOneOf(t);return this.updateValue(),e}equals(t){return T(this.getValue(),t.getValue(),M)}copy(t){this.base.copy(t.base),this.__modifiers.copy(t.__modifiers),this.updateValue()}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,vx),this.updateValue()}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}}xx.Process={ROUND_DOWN:function(t){return 0|t},NONE:function(t){return t},clampMin:function(t){return function(e){return Mu(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}}},xx.prototype.isStat=!0;const wx="undefined"==typeof performance?Date:performance;function bx(){return.001*wx.now()}function Sx(t){const e=bx(),i=(e-t.__lastMeasurement)*t.speed;t.__lastMeasurement=e,t.elapsedTime+=i}class Mx{__lastMeasurement=0;elapsedTime=0;timeAtDelta=0;__isRunning=!1;speed=new xx(1);constructor(){this.speed.postprocess=xx.Process.clampMin(0)}set multiplier(t){this.speed.base.set(t)}get multiplier(){return this.speed.base.getValue()}start(){this.__lastMeasurement=bx(),this.timeAtDelta=this.updateElapsedTime(),this.__isRunning=!0}stop(){this.__isRunning=!1}pause(){this.__isRunning=!1,Sx(this)}getDelta(){const t=this.updateElapsedTime(),e=t-this.timeAtDelta;return this.timeAtDelta=t,e}updateElapsedTime(){return this.__isRunning&&Sx(this),this.elapsedTime}getElapsedTime(){return this.elapsedTime}reset(){this.elapsedTime=0,this.timeAtDelta=0}}class Tx{clock=new Mx;#Pt=!1;onTick=new y;get callbacks(){throw new Error("deprecated, use onTick signal instead")}constructor(){this.clock.pause()}subscribe(t,e){this.onTick.add(t,e)}unsubscribe(t,e){this.onTick.remove(t,e)}start({maxTimeout:t=100}={}){let e=null,i=null;this.#Pt=!0;const n=()=>{if(!this.#Pt)return;const t=this.clock.getDelta();this.onTick.send1(t)};function s(){cancelAnimationFrame(i),a()}function r(){clearTimeout(e),setTimeout(a,0)}function a(){i=requestAnimationFrame(r),n(),e=setTimeout(s,t)}this.clock.getDelta(),this.clock.start(),requestAnimationFrame(r)}pause(){this.#Pt=!1}resume(){this.#Pt=!0}}class Ax{constructor(){let t=window.AudioContext||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)}}})}getCurrentTime(){return this.context.currentTime}resumeContext(){return this.context.resume()}start(){return new Promise(((t,e)=>{this.resumeContext(),t()}))}}class Cx{__state=-1;__eventHandlersStateEntry=[];__eventHandlersStateExit=[];constructor(t){this.description=t}addEventHandlerStateEntry(t,e,i){const n=this.__eventHandlersStateEntry[t],s=new m(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=v(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 m(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=v(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&&b(i,[e,t]),this.__state=t;const n=this.__eventHandlersStateEntry[t];void 0!==n&&b(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=Ud){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 Ex=new class{constructor(){this.__states=new Km,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}};Ex.createState(0),Ex.createState(1),Ex.createState(2),Ex.createState(3),Ex.createEdge(0,1),Ex.createEdge(1,2),Ex.createEdge(2,1),Ex.createEdge(1,3),Ex.setAction(0,(()=>1)),Ex.setAction(1,(t=>t)),Ex.setAction(2,(()=>1));class zx{constructor({priority:t=0}={}){this.sm=new Cx(Ex),this.sm.setState(0),this.priority=t}makeReady(){const t=this.sm.getState();if(1!==t){if(0!==t&&2!==t)throw new bu(`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 Lx=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 y};function Ix(t){const e=t%1;return e*Math.pow(10,2)>0&&Math.abs(t)<100?function(t,e){let i=t.length;for(;"0"===t.substring(i-1,i);)i-=1;return t.substring(0,i)}(t.toFixed(2)):function(t,e=","){return t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,e)}(t-e,",")}function Nx(t){return function(e){return e instanceof t}}function Px(t){return function(e){return typeof e===t}}function Dx(t,e){let i=!1;function n(){i=!1,t.call(e)}return function(){i||(i=!0,requestAnimationFrame(n))}}function Ox(t){return"number"==typeof t?Ix(t):t}function Fx(t){return Ix(t)}function Rx(t){return Ox(t[0])+" / "+Ox(t[1])}function kx(t){return t.getValue()}function Bx(t){return Gx.find((function(e){return e.matcher(t)}))}function Ux(t){return t}function Vx(t,e,i){this.matcher=t,this.extractor=e,this.formatter=i}function Wx(t,e,i){return new Vx(t,e,i)}Lx.prototype.copy=function(t){return this.set(t.x,t.a,t.b)},Lx.prototype.set=function(t,e,i){return this.x=t,this.a=e,this.b=i,this.onChanged.dispatch(t,e,i),this},Lx.prototype.addMultiplier=function(t){return this.b+=t,this.onChanged.dispatch(this.x,this.a,this.b),this},Lx.prototype.subMultiplier=function(t){return this.addMultiplier(-t)},Lx.prototype.addConstant=function(t){return this.a+=t,this.onChanged.dispatch(this.x,this.a,this.b),this},Lx.prototype.subConstant=function(t){return this.addConstant(-t)},Lx.prototype.getValue=function(){return this.x*this.b+this.a},Lx.prototype.equals=function(t){return this.x===t.x&&this.a===t.a&&this.b===t.b},Lx.prototype.toJSON=function(){return{x:this.x,a:this.a,b:this.b}},Lx.prototype.fromJSON=function(t){this.set(t.x,t.a,t.b)};const Gx=[Wx(Nx(Em),kx,Ox),Wx(Nx(qd),kx,Ox),Wx(Nx(hd),kx,Ox),Wx(Nx(Lx),kx,Fx),Wx(Nx(Ny),(function(t){return[t.getValue(),t.getUpperLimit()]}),Rx),Wx(Nx(xx),kx,Fx),Wx(Nx(sd),kx,Fx),Wx(Nx(jd),kx,Fx),Wx((Hx=i,jx=Array.isArray,function(t){return Hx(t)||jx(t)}),(function(t){return t.map((function(t){return(0,Bx(t).extractor)(t)}))}),Rx),Wx(Px("number"),Ux,Fx),Wx(Px("string"),Ux,Ux),Wx(Px("boolean"),Ux,Ux),Wx(Px("function"),(function(t){return t()}),Ox),Wx(Px("undefined"),Ux,Ux)];var Hx,jx;class qx extends Bg{constructor(t,{classList:e=[],transform:i=Ux,format:n=Ud,tag:s="div",size:r,css:a}={}){super(),this.model=t;const o=Bx(t),l=o.extractor,h=n!==Ud?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=Dx(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()}}function Jx(t,e,i){this.creator=t,this.destroyer=e,this.resetter=i,this.pool=[],this.maxSize=256}function Yx(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 Xx(t){return rd(ld(t.key),ld(t.value))}function $x(t,e){const i=t.key,n=e.key;if(i===n)return 0;const s=typeof i,r=typeof n,a=s.localeCompare(r);return 0!==a?a:"string"!==s?0:i.localeCompare(n)}Jx.prototype.create=function(){if(this.pool.length>0){const t=this.pool.pop();return this.resetter(t),t}return this.creator()},Jx.prototype.release=function(t){return this.pool.length>=this.maxSize?(this.destroyer!==Ud&&this.destroyer(t),!1):(this.pool.push(t),!0)};class Zx{constructor(){this.attributes=[],this.style=[],this.tag="",this.__hash=-1}setAttribute(t,e){const i=this.#Dt(t);if(void 0!==i){if(i.value===e)return;i.value=e}else this.attributes.push(new Zg(t,e));this.update()}getAttribute(t){const e=this.#Dt(t);return void 0===e?null:e.value}#Dt(t){const e=this.attributes,i=e.length;for(let n=0;n<i;n++){const i=e[n];if(i.key===t)return i}}#Ot(){this.attributes.sort($x),this.style.sort($x)}update(){this.#Ot(),this.#Ft()}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 Zg(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 Zg(e,n);this.attributes[i]=s}this.attributes.splice(i,this.attributes.length-i),this.update()}#Ft(){const t=Y_(this.style,Xx),e=Y_(this.attributes,Xx),i=ld(this.tag);this.__hash=rd(t,e,i)}hash(){return this.__hash}equals(t){return this.tag===t.tag&&Yx(this.style,t.style)&&Yx(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 Zx;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}}const Kx=new Jx((()=>new Zx),Ud,(t=>{t.reset()})),Qx=new class{onRemoved=new y;constructor({capacity:t=100,perKeyCapacity:e=10}={}){this.data=new Zp,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),n=i.indexOf(t);i.splice(n,1),0===i.length&&this.data.delete(e),this.size--,this.onRemoved.send2(e,t.value)}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 ef;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 tw extends Bg{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=Kx.create();s.tag="img",s.attributes=[new Zg("src",n),new Zg("class",e.join(" "))];for(const t in i){const e=String(i[t]),n=new Zg(t,e);s.attributes.push(n)}s.update(),this.el=function(t){let e=Qx.get(t);return void 0===e&&(e=t.createElement()),e}(s),Kx.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=Kx.create();t.initializeFromElement(this.el),Qx.add(t,this.el)||Kx.release(t)}__setSize(t,e){this.el.setAttribute("width",t),this.el.setAttribute("height",e)}__setSource(t){this.el.setAttribute("src",t)}}class ew extends Bg{constructor({tag:t="div",action:e,name:i,icon:n,classList:s=[],css:r}){if(super(),"function"!=typeof e)throw new Error("Action must be a function");const a=wy(t);this.el=a.el;const o=wy();o.addClass("foreground");const l=wy();if(l.addClass("background"),a.append(o),a.append(l),a.addClass("ui-button-view"),void 0!==r&&this.css(r),this.addClasses(s),this.el.addEventListener("click",(t=>{if(this.__enabled){const i=e(t);i instanceof Promise&&(this.enabled=!1,i.finally((()=>{this.enabled=!0})))}})),void 0!==i){const t=new qx(i);this.addChild(t),this.size.onChanged.add((function(e,i){t.size.set(e,i)}))}if(null!=n){const t=new tw(n);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 iw extends Bg{constructor(t,e){super();const i=wy("div").addClass("ui-confirmation-dialog-view");this.el=i.el;const n=new Ug({classList:["content-container"]});n.addChild(t),this.addChild(n);const s=new Ug({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 ew({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 nw{constructor({el:t,dragStart:e=Ud,drag:i=Ud,dragEnd:n=Ud,stopPropagation:s=!0}){this.pointerLocal=new $v(t);const r=this.pointerGlobal=new $v(window),a=new Tu,o=new Tu;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 sw extends Bg{constructor(t,e){super(t,e);const i=wy("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 qd(e.title);const s=new qx(this.title,{classList:["title"]});this.addChild(s),e.draggable&&function(t,e){let i=null;new nw({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 $v(window),i=new $v(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}}function rw(t,e,i,n){return e>=i&&n>=t}class aw{constructor(t=0,e=0,i=0,n=0){this.position=new Tu(t,e),this.size=new Tu(i,n)}set(t,e,i,n){this.size.set(i,n),this.position.set(t,e)}clone(){return new aw(this.position.x,this.position.y,this.size.x,this.size.y)}copy(t){this.position.copy(t.position),this.size.copy(t.size)}_intersects(t,e,i,n){const s=this.position,r=this.size,a=s.x,o=s.y;return rw(t,i,a,r.x+a)&&rw(e,n,o,o+r.y)}intersects(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)}_overlaps(t,e,i,n){const s=this.position,r=this.size,a=s.x,o=s.y;return Vd(t,i,a,r.x+a)&&Vd(e,n,o,o+r.y)}overlaps(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)}_resizeToFit(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=C(t,r),c=C(e,a),u=Mu(i,l),d=Mu(n,o);this.position.set(h,c),s.set(u-h,d-c)}resizeToFit(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)}_contains(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}contains(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)}computeCenter(t){const e=this.position,i=this.size,n=e.x+i.x/2,s=e.y+i.y/2;t.set(n,s)}computeArea(){return this.size.x*this.size.y}toArray(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}toJSON(){return{position:this.position.toJSON(),size:this.size.toJSON()}}fromJSON(t){this.position.fromJSON(t.position),this.size.fromJSON(t.size)}}aw.prototype.isRectangle=!0;class ow{constructor(t,e,i,n=[]){this.target=t,this.factory=e,this.factoryContext=i,this.obstracles=n,this.view=null}}function lw(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++)lw(n[t],e-1,i)}}const hw=new kg;class cw{constructor({depth:t=0}={}){this.dimensions=new aw,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;hw.setNegativelyInfiniteBounds(),lw(this.element,this.__depth,hw);const n=this.dimensions;n.position.set(hw.x0,hw.y0),n.size.set(i.width,i.height)}synchronize(){hw.setNegativelyInfiniteBounds(),lw(this.element,this.__depth,hw);const t=this.dimensions;t.position.set(hw.x0,hw.y0),t.size.set(hw.getWidth(),hw.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 uw{constructor(t,e,i){this.view=t,this.factory=e;const n=new aw;this.tipTargetRectangle=n,this.tip=new ow(n,e,i),this.on={entered:new y,exited:new y};const s=this.isEntered=new Em(!1),r=new cw;this.sizeObserver=r,this.bindings=[new xm(t.position.onChanged,this.__copyDimensions,this),new xm(t.size.onChanged,this.__copyDimensions,this),new xm(r.dimensions.position.onChanged,this.__copyDimensionsFromBoundingRect,this),new xm(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(Vv,this.handleMouseEnter),t.addEventListener(Wv,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(Vv,this.handleMouseEnter),t.removeEventListener(Wv,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 dw{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 uw(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())}}class pw{#Rt=new nf({maxWeight:1048576,keyWeigher:cf,valueWeigher:t=>256*t.length,keyHashFunction:ld,keyEqualityFunction:tf});parse(t){const e=this.#Rt.get(t);if(null!==e)return e;const i=oy(t);return this.#Rt.put(t,i),i}}class fw{constructor(){this.enableTooltips=!0}}class mw{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 pw}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===Yg.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===Yg.Text)r=t.value;else if(a===Yg.StyleStart);else if(a!==Yg.StyleEnd)throw new TypeError(`Unsupported token type '${a}'`);return r})).filter((t=>void 0!==t)).join("")}compileTokensToVisual(t,e=new Ug({tag:"span"})){const i=this.database,n=this.localization,s=this.tooltips,r=this;function a(t,e){const i=t.value,n=new qx(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 qx("ERROR")}r.__recursionReferencePath.pop(),h.addClass("reference-type-"+o),e.push(h)}const l=[];let h=e;function c(){const t=new Ug({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===Yg.Reference)o(i,n);else if(s===Yg.Text)a(i,n);else if(s===Yg.StyleStart)u(i.value);else{if(s!==Yg.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 fw;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 Ug;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)}}var _w=function(t){return document.createElementNS("http://www.w3.org/2000/svg",t)};class gw extends Bg{constructor(){super();const t=_w("svg"),e=_w("defs"),i=_w("linearGradient");i.setAttribute("id","gradient"),e.appendChild(i);const n=_w("stop"),s=_w("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=_w("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 yw(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 Tu(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 vw extends Bg{constructor(t,e){super(),this.model=t,this.el=document.createElement("div"),this.addClass("tooltip-view");const i=new Ug({classList:["contents"]});this.addChild(i),i.addChild(e),this.contentView=i;const n=new gw;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 kg(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 kg(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 Tu(s.midX(),s.midY()),s.locked=!0;const o=function(t,e,i){const n=[Tu.up,Tu.right,Tu.down,Tu.left],s=new Tu(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 Tu,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 Tu(c,u);return r.multiply(i),r._sub(c,u),r.add(d),r})),f=p.map((function(t){const n=new kg,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>_+M&&(_=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 Tu(0,0));let s=-1;for(;e>0&&0!==s;)e--,s=yw(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 Tu(i.midX(),i.midY()),e=new Tu;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 xw{constructor(){this.gml=null,this.contextView=new Ug,this.contextView.addClass("ui-tooltip-manager-context"),this.pointer=null;const t=this;this.updateTask=new Lf({name:"Update Tooltip Cursor",cycleFunction:function(){const e=t.pointer.position;return t.update(e.x,e.y),3}}),this.executor=new my(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 vw(t,n);t.view=s;const r=Dx((()=>{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 kg(0,0,e.size.x,e.size.y);t.layout(i)}}function ww(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 bw(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 y},this.setPosition(0)}ww.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},ww.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)},ww.prototype.addTransition=function(t,e){this.transitionKeys.push(t),this.transitionFunctions.push(e)},ww.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},ww.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},ww.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]},bw.prototype.promiseEnded=function(){return this.position>=this.track.timeEnd?Promise.resolve():new Promise(((t,e)=>{this.on.ended.add(t)}))},bw.prototype.setLoop=function(t){this.__loop=t},bw.prototype.reset=function(){this.setPosition(this.track.timeStart)},bw.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?C(this.__lastKeyIndex+1,n-1):this.__lastKeyIndex,this.__nextKeyTime=e.keyTimes[this.__nextKeyIndex]},bw.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},bw.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()},bw.prototype.update=function(){this.readCurrentValues(this.__valueBuffer),this.updateCallback.apply(this.updateTraget,this.__valueBuffer)},bw.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)};const Sw={Initial:0,Running:1,Succeeded:2,Failed:3,Suspended:4,Invalid:5};class Mw{context=null;onInitialized=new y;onFinalized=new y;tick(t){throw new Error("Abstract method, needs to be overridden")}initialize(t){this.context=t,this.onInitialized.send2(this,t)}finalize(){this.onFinalized.send1(this)}}Mw.prototype.isBehavior=!0,Mw.typeName="Behavior";class Tw extends Mw{constructor(){super(),this.__source=null}getSource(){return this.__source}setSource(t){this.__source=t}initialize(t){this.__source.initialize(t),super.initialize(t)}finalize(){this.__source.finalize(),super.finalize()}}Tw.prototype.isDecoratorBehavior=!0;class Aw extends Tw{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 Aw(t,e)}initialize(t){this.__iterator=0,super.initialize(t)}tick(t){const e=this.__source,i=e.tick(t);return i!==Sw.Succeeded&&i!==Sw.Failed?i:(this.__iterator++,this.__iterator>=this.limit?Sw.Succeeded:(e.initialize(this.context),Sw.Running))}}Aw.typeName="RepeatBehavior";class Cw extends Mw{constructor(t,e){super(),this.__action=t,this.__context=void 0===e?this:e}tick(t){try{return this.__action.call(this.__context,t,this.context),Sw.Succeeded}catch(t){return Sw.Failed}}}class Ew extends Mw{constructor(){super(),this.__children=[]}addChild(t){this.__children.push(t)}addChildren(t){const e=t.length;for(let i=0;i<e;i++){const e=t[i];this.addChild(e)}}getChildren(){return this.__children}removeChild(t){const e=this.__children.indexOf(t);return-1!==e&&(this.__children.splice(e,1),!0)}clearChildren(){this.__children=[]}}Ew.prototype.isCompositeBehavior=!0;class zw extends Ew{constructor(){super(),this.__currentBehaviourIndex=-1,this.__currentBehaviourState=Sw.Initial,this.__currentBehaviour=void 0}initialize(t){this.__currentBehaviourIndex=0,this.__currentBehaviour=this.__children[0],this.__currentBehaviour.initialize(t),this.__currentBehaviourState=Sw.Running,super.initialize(t)}tick(t){const e=this.__currentBehaviour,i=e.tick(t);return this.__currentBehaviourState=i,i!==Sw.Succeeded?i:(e.finalize(),this.__currentBehaviourState=Sw.Initial,this.__currentBehaviourIndex++,this.__currentBehaviourIndex<this.__children.length?(this.__currentBehaviour=this.__children[this.__currentBehaviourIndex],this.__currentBehaviour.initialize(this.context),this.__currentBehaviourState=Sw.Running,Sw.Running):Sw.Succeeded)}finalize(){const t=this.__children.length;this.__currentBehaviourIndex!==t&&void 0!==this.__currentBehaviour&&this.__currentBehaviourState!==Sw.Initial&&this.__currentBehaviour.finalize(),this.__currentBehaviour=void 0,this.__currentBehaviourIndex=t,super.finalize()}static from(t){const e=new zw;return e.addChildren(t),e}}zw.prototype.isSequenceBehavior=!0,zw.typeName="SequenceBehavior";class Lw{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=zw.from(t):1===t.length?this.__behavior=t[0]:this.__behavior=null}static looping_function(t,e){return Lw.fromOne(Aw.from(new Cw(t,e)))}static fromOne(t){const e=new Lw;return e.__behavior=t,e}}Lw.serializable=!0,Lw.typeName="BehaviorComponent";class Iw extends Mw{constructor(t){super(),this.animation=t}tick(t){return this.animation.advance(t),this.animation.position>=this.animation.track.timeEnd&&!this.animation.loop?Sw.Succeeded:Sw.Running}initialize(){this.animation.setPosition(this.animation.track.timeStart)}}const Nw=function(t){return t},Pw=function(t){return t*t},Dw=function(t){return-t*(t-2)};function Ow(t,i){const n=typeof t;if(n!==typeof i)return!1;if("object"===n){if(Array.isArray(t))return!!Array.isArray(i)&&Q_(t,i,Ow);const n=Object.keys(t);if(!e(n,Object.keys(i)))return!1;const s=n.length;for(let e=0;e<s;e++){const s=n[e];if(!Ow(t[s],i[s]))return!1}return!0}return t===i}class Fw{view=null;klass=null;parameters={};anchor=new Tu(0,0);group=null;flags=1;visible=new Em(!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)||!Ow(this.parameters,t.parameters))}hash(){return rd(this.flags,ld(this.klass),this.anchor.hash(),ld(this.group),this.visible.hashCode())}static fromView(t){const e=new Fw;return e.clearFlag(1),e.view=t,e}static fromJSON(t){const e=new Fw;return e.fromJSON(t),e}fromJSON({klass:t,parameters:e={},anchor:i=Tu.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()}}}Fw.typeName="GUIElement",Fw.serializable=!0;class Rw{constructor(t){this.position=new Tu,this.offset=new Tu,this.anchor=new Tu(0,0),this.resolveGuiCollisions=!1,this.screenEdgeWidth=10,this.stickToScreenEdge=!1,this.enabled=new Em(!0),void 0!==t&&this.fromJSON(t)}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 rd(this.position.hash(),this.offset.hash(),this.anchor.hash(),this.resolveGuiCollisions?1:0,E(this.screenEdgeWidth),this.stickToScreenEdge?1:0,this.enabled.hashCode())}fromJSON({position:t=Tu.zero,offset:e=Tu.zero,anchor:i=Tu.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 Rw;return e.fromJSON(t),e}}Rw.typeName="ViewportPosition",Rw.serializable=!0;class kw{constructor(){this.elements=[],this.__active=null,this.observers=new Map,this.on={added:new y,lastRemoved:new y,firstAdded:new y}}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 Bw{constructor({title:t="",description:e="",image:i="",classList:n=[]}){this.title=t,this.description=e,this.image=new qd(i),this.classList=n}}function Uw(){this.elements=new of,this.maxLength=1e3}Bw.prototype.isNotification=!0,Uw.prototype.add=function(t){const e=new Bw(t);return this.addNotification(e),e},Uw.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 Vw{constructor({log:t,initializer:e,updateFunction:i=Ud}){this.needsUpdate=i!==Ud,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 Ww{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 Uw),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 Vw({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.id===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(s_,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 o_;e.add(Wg.Transient);const o=s.ecd;if(null!==o){const s=Fw.fromView(t);s.group=i,e.addEventListener(s_,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 Gw{constructor(t){this.object=t,this.playback=null}}class Hw{constructor(){this.animation=null,this.animationUpdater=null,this.objectFactory=null,this.objectInitializer=Ud,this.objectFinalizer=Ud,this.elements=[],this.rushThreshold=Number.POSITIVE_INFINITY,this.spawnDelay=0,this.__spawnTimeBudget=0,this.__spawnBuffer=[],this.on={spanwed:new y,removed:new y},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 bw(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 Gw(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=C(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=Mu(1,(i-n)/this.rushThreshold)*t;s.advance(r)}this.__spawnTimeBudget+=t,this.trySpawnDeferred()}}class jw{constructor(){this.source=new Tu,this.objectEmitter=new Hw,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 qw extends Bg{constructor(t){super(),this.model=t;const e=wy("div").addClass("ui-notification-view");this.el=e.el,this.addClasses(t.classList),this.vImage=new tw(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 Jw="primary",Yw="secondary",Xw="toast";class $w{constructor(){this.scene=null,this.modals=new kw,this.notifications=new Ww,this.clockModifierZero=new vx(0,0)}initialize(t){var e;this.scene=t,(e=this.notifications).createChannel(Jw),e.createChannel(Yw),e.createChannel(Xw),e.addEmitterDisplay(Jw,function(){const t=new jw;t.setRushThreshold(1),t.setSpawnDelay(2);const e=new ww(["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,Pw),e.addTransition(2,Dw),t.setAnimation(e,(function(t,e){this.el.style.opacity=t,this.scale.set(e,e)})),t.viewFactory=function(t){return new qw(t)},t}()),e.addEmitterDisplay(Yw,function(){const t=new jw;t.setRushThreshold(1),t.setSpawnDelay(.7);const e=new ww(["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,Pw),e.addTransition(1,Nw),e.addTransition(2,Dw),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 qw(t)},t}()),e.addEmitterDisplay(Xw,function(){const t=new jw;t.setRushThreshold(5),t.setSpawnDelay(.1);const e=new ww(["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,Pw),e.addTransition(1,Nw),e.addTransition(2,Dw),t.setAnimation(e,(function(t,e){this.el.style.opacity=t,this.position.setX(e)})),t.viewFactory=function(t){return new qw(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)}}class Zw{windows=new of;entityManager=null;engine=null;sceneContexts=new WeakMap;tooltips=new xw;viewTooltips=new dw(this.tooltips);ticker=new Tx;view=new Ug({classList:["gui-engine-root"],css:{position:"absolute",left:"0",top:"0"}});gml=new mw;cursor=new hd("normal");localization=null;constructor(){this.ticker.subscribe((t=>{let e=null;try{e=this.getActiveSceneContext()}catch(t){}null!==e&&e.tick(t)}))}openWindow({closeable:t,content:e,title:i,wrapper:n}){const s=new o_,r=new sw(e,{closeAction:function(){s.destroy()},title:i,closeable:t});let a;s.add(new Rw),void 0!==n?(a=n,n.addChild(r)):a=r;const o=Fw.fromView(a);s.add(o).add(Wg.Transient);const l=this.entityManager.dataset;return function(t,e){const i=new ww(["alpha","scale"]);i.addKey(0,[0,.95]),i.addKey(.2,[1,1]),i.addTransition(0,Nw);const n=new bw(i,(function(t,e){this.el.style.opacity=t,this.scale.set(e,e)}),t);n.update(),function(t,e){const i=new o_,n=Lw.fromOne(new Iw(t));n.clock=1,i.add(n),i.add(Wg.Transient),t.update(),i.build(e),t.on.ended.add((function(){i.destroy()}))}(n,e)}(r,l),s.build(l),s}createModal({content:t,title:e,priority:i=0}){const n=this.entityManager,s=this;let r=null,a=null;const o=new zx({priority:i});return o.sm.addEventHandlerStateEntry(2,(function(){a=function(){const t=new Bg;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 o_;return e.add(Wg.Transient),e.add(Fw.fromView(t)),e}(),a.build(n.dataset);const i=t,l=new Ug({classList:["ui-modal-window-container"]});r=s.openWindow({title:e,content:i,closeable:!1,wrapper:l}),r.getComponent(Fw).anchor.set(.5,.5),r.removeComponent(Rw)})),o.sm.addEventHandlerStateExit(2,(function(){r.destroy(),a.destroy()})),this.getActiveSceneContext().modals.add(o),o}createModalConfirmation({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 iw(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()}))}))}confirmTextDialog({text:t,title:e}){const i=Kw(t);return this.createModalConfirmation({title:e,content:i})}createTextAlert({text:t,title:e}){const i=Kw(t);return this.createAlert({content:i,title:e})}createAlert({content:t,title:e,marks:i=[],priority:n=0,lifecycleHook:s=Ud}){let r=null;const a=this.localization,o=new iw(t,[{name:"ok",displayName:a.getString("system_confirmation_continue"),callback:function(){r.makeDestroyed()}}]);if(i.length>0){const t=new Ug({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}obtainSceneContext(t){let e=this.sceneContexts.get(t);return void 0===e&&(e=new $w,e.initialize(t),e.startup(),this.sceneContexts.set(t,e)),e}getActiveSceneContext(){const t=this.engine;if(null===t)throw new Error("Engine is not set");const e=t.sceneManager.current_scene;return null===e?null:this.obtainSceneContext(e)}__update_localization(){this.view.removeClassesByPattern(/locale-/),this.view.addClass(`locale-${this.localization.locale.getValue()}`)}startup(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()])}shutdown(){this.windows.reset(),this.entityManager=null;const t=this.tooltips.shutdown();return this.localization.locale.onChanged.remove(this.__update_localization,this),Promise.all([t])}}function Kw(t){const e=new Bg;return e.el=document.createElement("div"),e.el.classList.add("text"),e.el.innerText=t,e.size.set(300,100),e}function Qw(){this.graphics_control_viewport_size=new Em(!0),this.simulation_speed=new sd(1),this.input_mouse_sensitivity=new sd(5)}const tb="frame_delay",eb="render_time",ib="simulation_time";class nb{#kt=0;viewStack=new Sy;constructor(t,{entityManager:e,enableGraphics:i=!0,enableAudio:n=!0,debug:s=!0}={}){this.platform=t,this.staticKnowledge=new ex,this.staticKnowledge.validation_enabled=s,this.plugins=new hx,this.performance=new Hy,this.executor=new my(1,10),this.__using_external_entity_manager=void 0!==e,this.__using_external_entity_manager?this.entityManager=e:this.entityManager=new a_,this.ticker=new Tx,this.assetManager=new Fy({context:this,executor:this.executor}),this.__performacne_monitor=new qy(15,(()=>{const t=this.performance,e=new jy,i=t.get(eb);i.computeStats(e);const n=(1e3*e.mean).toFixed(2),s=t.get(ib);s.computeStats(e);const r=(1e3*e.mean).toFixed(2),a=t.get(tb);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.onTick.add((t=>{const e=performance.now();this.entityManager.simulate(t);const i=(performance.now()-e)/1e3;this.performance.get(ib).record(i)})),this.performance.create({name:eb}),this.performance.create({name:ib}),this.performance.create({name:tb}),this.options=new rx("options"),this.moduleRegistry=new py,this.binarySerializationRegistry=new Jy,this.settings=new Qw,this.services={},this.storage=this.platform.getStorage(),this.localization=new dy,this.localization.setAssetManager(this.assetManager);const r=window.innerWidth/3,a=window.innerHeight/3;if(this.camera=new hr(45,r/a,1,50),!1!==i){const t=new zv({camera:this.camera,debug:s});this.graphics=t;try{t.start()}catch(t){ix.error(`Failed to start GraphicEngine: ${t}`)}}else ix.info("enableGraphics option is not set, no graphics engine will be created");if(!1!==n){const t=new Ax;t.volume=1,this.sound=t}else ix.info("enableAudio option is not set, no audio engine will be created");this.gui=new Zw,this.sceneManager=new yx(this.entityManager,this.ticker.clock),this.initializeViews(),this.devices={pointer:new $v(this.viewStack.el),keyboard:new Rv(this.viewStack.el)},this.devices.pointer.start(),this.devices.keyboard.start(),this.initializeSettings(),ix.info("engine initialized"),this.renderingEnabled=!0,this.plugins.initialize(this)}get inputEngine(){throw new Error("Deprecated, use .devices instead")}get grid(){throw new Error("Deprecated, use systems/components to achieve the same functionality as before")}initializeViews(){const t=new Ug;if(t.addClass("game-view"),t.css({left:0,top:0,position:"absolute",pointerEvents:"none"}),this.gameView=t,this.viewStack.push(t,"game-view"),void 0!==this.graphics){const e=this.graphics.viewport;e.css({pointerEvents:"auto"}),t.addChild(e),e.bindSignal(t.size.onChanged,e.size.set.bind(e.size)),t.on.linked.add((function(){e.size.copy(t.size)}))}}initializeSettings(){ix.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)})),ix.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 By,i=this.assetManager;return i.get({path:t,type:"json",callback: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(eb).record(n)}}start(){return this.assetManager.startup(),this.__performacne_monitor.start(),Promise.all([this.sound.start().then((()=>new Promise(((t,e)=>{this.entityManager.startup(t,e)})))),this.staticKnowledge.load(this.assetManager,this.executor),this.gui.startup(this),this.plugins.startup()]).then((async()=>{this.#kt=performance.now(),requestAnimationFrame(this.#Bt),this.ticker.start({maxTimeout:200}),await this.options.attachToStorage("lazykitty.komrade.options",this.storage),ix.info("engine started")}),(function(t){ix.error(`Engine Failed to start: ${t}`)}))}#Bt=()=>{const t=this.#kt,e=performance.now();requestAnimationFrame(this.#Bt),this.render();const i=(e-t)/1e3;this.#kt=e,this.performance.get(tb).record(i)};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()}))}}nb.prototype.isEngine=!0;class sb{systems=[];plugins=[];knowledge=[];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)}}}const rb=2*Math.PI;function ab(t){let e=t%rb;return e=(e+rb)%rb,e>Math.PI&&(e-=rb),e}function ob(t,e){return Math.atan2(t,e)}function lb(t,e,i){return t[e+4*i]}const hb=Math.PI,cb=new In,ub=[],db=new O;function pb(t,e,i,n){const s=ab(i.pitch),r=ab(i.yaw),a=ab(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 fb=Math.PI/360;class mb{constructor(t){this.target=new O,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=O.up){cb.lookAt(e,t,i),function(t,e,i,n,s){{t[0]=ob(lb(e,1,0),lb(e,0,0));const i=Eu(lb(e,2,2),lb(e,2,1));t[0]<0?(t[0]>0?t[0]-=hb:t[0]+=hb,t[1]=ob(-lb(e,2,0),-i)):t[1]=ob(-lb(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]=ob(n*lb(e,0,2)-s*lb(e,1,2),s*lb(e,1,1)-n*lb(e,0,1))}}(ub,cb.elements),this.pitch=ub[2],this.yaw=ub[1],this.roll=ub[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 mb;return t.copy(this),t}lerp(t,e,i){this.target.lerpVectors(t.target,e.target,i),this.pitch=A(t.pitch,e.pitch,i),this.yaw=A(t.yaw,e.yaw,i),this.roll=A(t.roll,e.roll,i),this.distance=A(t.distance,e.distance,i),this.distanceMin=A(t.distanceMin,e.distanceMin,i),this.distanceMax=A(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=O.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 mb;return e.fromJSON(t),e}}mb.typeName="TopDownCameraController",mb.pan=function(t,e,i,n,s,r,a=O.one){const o=n*Math.tan(s*fb)*2/i.clientHeight;!function(t,e,i,n){const s=e.matrix.elements;db.set(s[0],s[1],s[2]),db.multiplyScalar(-t),i._sub(db.x*n.x,db.y*n.y,db.z*n.z)}(t.x*o,e,r,a),function(t,e,i,n){const s=e.matrix.elements;db.set(s[4],s[5],s[6]),db.multiplyScalar(t),i._sub(db.x*n.x,db.y*n.y,db.z*n.z)}(t.y*o,e,r,a)},mb.rotate=pb;class _b{constructor({path:t,listener:e,exclusive:i=!1}){this.path=t,this.listener=e,this.exclusive=i}}class gb{constructor(t=[]){this.mapping=new of;const e=t.map((t=>new _b(t)));this.mapping.addAll(e),this.on={unlinked:new y}}static from(t){const e=new gb,i=t.length;for(let n=0;n<i;n++){const i=t[n],s=new _b(i);e.mapping.add(s)}return e}}gb.typeName="InputController",gb.serializable=!1;const yb=new O;class vb extends Sm{constructor(){super(),this.enabled=new qd(!0),this.dependencies=[mb],this.components_used=[wm.from(G,2)]}__visit_camera_entity(t,e){const i=this.entityManager.dataset.getComponent(e,G);void 0!==i&&function(t,e){const i=e.rotation,n=S(t.distance,t.distanceMin,t.distanceMax),s=t.target,r=t.yaw,a=t.pitch,o=t.roll;i.__setFromEuler(a,r,o,"ZYX"),yb.copy(O.forward),yb.applyQuaternion(i),yb.multiplyScalar(-n),yb.add(s),e.position.copy(yb)}(t,i)}update(t){const e=this.entityManager.dataset;this.enabled.get()&&null!==e&&e.traverseComponents(mb,this.__visit_camera_entity,this)}}const xb={DIRECTION:0,SPOT:1,POINT:2,AMBIENT:3};class wb{constructor(){this.type=new zm(xb.DIRECTION,xb),this.color=new Bd(1,1,1),this.intensity=new sd(1),this.angle=new sd(Math.PI/4),this.penumbra=new sd(.4),this.distance=new sd(1),this.castShadow=new Em(!1),this.__threeObject=null,this.__fp_light=null}static fromJSON(t){const e=new wb;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===xb.SPOT&&(void 0!==t.angle&&this.angle.fromJSON(t.angle),void 0!==t.penumbra&&this.penumbra.fromJSON(t.penumbra)),e!==xb.SPOT&&e!==xb.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===xb.SPOT&&(t.angle=this.angle.toJSON(),t.penumbra=this.penumbra.toJSON()),e!==xb.SPOT&&e!==xb.POINT||(t.distance=this.distance.toJSON()),t}}wb.typeName="Light",wb.Type=xb;class bb extends Sm{constructor(t){super(),this.__ContextClass=t,this.__context_pool=new Jx((()=>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))}}function Sb(t,e){if(0===t){if(e<=8)return qu.Uint8;if(e<=16)return qu.Uint16;if(e<=32)return qu.Uint32}else if(1===t){if(e<=8)return qu.Int8;if(e<=16)return qu.Int16;if(e<=32)return qu.Int32}else if(2===t){if(e<=32)return qu.Float32;if(e<=64)return qu.Float64}throw new Error(`Unsupported numeric type(=${t}) and precision(=${e}) combination`)}function Mb(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 Tb(t,e,i,n,s,r,a){Mb(a,e*i+n*s+r,t,0);const o=r+1;Mb(a,e*i+n*s+o,t,12);const l=n+1;Mb(a,e*i+l*s+r,t,6),Mb(a,e*i+l*s+o,t,18);const h=e+1;Mb(a,h*i+n*s+r,t,3),Mb(a,h*i+n*s+o,t,15),Mb(a,h*i+l*s+r,t,9),Mb(a,h*i+l*s+o,t,21)}class Ab{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")}}class Cb{constructor(){this.patch=null,this.last_use_time=0}}class Eb extends Ab{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}__find_cache_record_index_by_patch(t){const e=this.__cached_patches,i=e.length;for(let n=0;n<i;n++)if(e[n].patch===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;if(-1!==this.__find_cache_record_index_by_patch(t))return!1;const e=new Cb;return e.last_use_time=performance.now(),e.patch=t,this.__cached_patches.push(e),!0}}class zb extends Ab{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 Ky;return s.bind(e),s.onReleased.add(this.__handle_ref_release,this),s}}class Lb extends kg{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)}}Lb.prototype.isQuadTreeDatum=!0;class Ib extends kg{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 Lb(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(C(e,t.x0),C(i,t.y0),Mu(n,t.x1),Mu(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=.5*(t+i),r=.5*(e+n);this.topLeft=new Ib(t,e,s,r),this.topLeft.parentNode=this,this.topRight=new Ib(s,e,i,r),this.topRight.parentNode=this,this.bottomLeft=new Ib(t,r,s,n),this.bottomLeft.parentNode=this,this.bottomRight=new Ib(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 Nb(t,e,i,n){return(t-i)*e+(e-n)*i}function Pb(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 Db(t,e){const i=t.getWidth(),n=t.getHeight(),s=Pb(i,n,e,Nb);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=Mu(t.x0,e.x0),r=C(t.x1,e.x1),a=Mu(t.y0,e.y0),o=C(t.y1,e.y1);s>e.x0&&i.push(new Lb(e.x0,e.y0,s,e.y1)),r<e.x1&&i.push(new Lb(r,e.y0,e.x1,e.y1)),a>e.y0&&i.push(new Lb(e.x0,e.y0,e.x1,a)),o<e.y1&&i.push(new Lb(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 Lb(s.x0,t.y1,s.x1,s.y1);e.insertDatum(i)}if(t.x1!==s.x1){const i=new Lb(t.x1,s.y0,s.x1,s.y1);e.insertDatum(i)}return!0}function Ob(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()}class Fb{constructor(t,e){this.size=new Tu(t,e),this.free=new Ib(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 Lb(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=Db(t,this.free);return e&&(this.boxes.push(t),Ob(this.free)),e}canAdd(t,e){return null!==Pb(t,e,this.free,Nb)}addMany(t){const e=t.length,i=[],n=new My((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(!Db(s,this.free))return this.removeMany(i),!1;this.boxes.push(s),i.push(s)}return Ob(this.free),!0}repack(){const t=this.boxes;return this.clear(),this.addMany(t)}clear(){this.free.clear(),this.free.insertDatum(new Lb(0,0,this.size.x,this.size.y)),this.boxes=[]}resize(t,e){const i=this.size.x,n=this.size.y;return this.size.set(t,e),i>t||n>e?this.repack():(t>i&&this.free.insertDatum(new Lb(i,0,t,e)),e>n&&this.free.insertDatum(new Lb(0,n,t,e)),!0)}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 kg))return!1}}return!0}}class Rb{#Ut=new Km;peek(){return this.#Ut.nextClearBit(0)}get(){const t=this.peek();return this.#Ut.set(t,!0),t}getSpecific(t){return!this.isUsed(t)&&(this.#Ut.set(t,!0),!0)}isUsed(t){return this.#Ut.get(t)}traverseUsed(t){const e=this.#Ut;for(let i=e.nextSetBit(0);-1!==i;i=e.nextSetBit(i+1))t(i)}release(t){this.#Ut.clear(t)}reset(){this.#Ut.reset()}}function kb(t){return t.clone()}class Bb{constructor(){this.position=new Tu(0,0),this.size=new Tu(0,0),this.padding=4,this.id=-1,this.sampler=null,this.uv=new aw(0,0,0,0),this.packing=new kg,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}}Bb.prototype.isAtlasPatch=!0;class Ub extends Ab{constructor(t=16,e=qu.Uint8,i=4){super(),this.idPool=new Rb,this.patches=[],this.size=new Tu(t,t);const n=Ju[e];this.__sampler=new Qu(new n(t*t*i),i,t,t),this.packer=new Fb(t,t),this.on={painted:new y,removed:new y},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;!function(t,e,i,n,s,r,a,o){const l=t.itemSize;e.itemSize;const h=Math.min(a,e.width-0,t.width-s),c=Math.min(o,e.height-0,t.height-r),u=l*t.width,d=l*e.width,p=e.data,f=t.data,m=h*l;let _,g;for(_=0;_<c;_++){const t=(_+r)*u+s*l,e=(_+0)*d+0*l;for(g=0;g<m;g++)f[t+g]=p[e+g]}t.version++}(e,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 Bb;i.id=this.idPool.get(),i.sampler=t,i.size.set(t.width,t.height),i.padding=e,i.setFlag(4);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),t.clearFlag(7),this.on.removed.send2(t,t.sampler),!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 Fb(this.size.x,this.size.y),e=this.packer.boxes.map(kb);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=Mu(0,Math.log2(Jd(this.size.x))),e=Mu(0,Math.log2(Jd(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()}}function Vb(t){switch(t){case qu.Uint8:return re;case qu.Uint16:return le;case qu.Uint32:return ce;case qu.Int8:return ae;case qu.Int16:return oe;case qu.Int32:return he;case qu.Float16:return de;case qu.Float32:case qu.Float64:return ue;default:throw new Error(`Unsupported data type '${t}'`)}}const Wb={[qu.Uint8]:1,[qu.Uint16]:2,[qu.Uint32]:4,[qu.Uint64]:8,[qu.Int8]:1,[qu.Int16]:2,[qu.Int32]:4,[qu.Int64]:8,[qu.Float16]:2,[qu.Float32]:4,[qu.Float64]:8};class Gb{constructor(){this.__channel_count=1,this.size=1,this.__precision=8,this.__type=0,this.__texture=new Bl(new Uint8Array(0),0,0),this.__texture.image.width=0,this.__texture.image.height=0,this.__texture.type=re,this.__texture.format=Me,this.__texture.magFilter=Qt,this.__texture.minFilter=Qt,this.__texture.wrapS=Zt,this.__texture.wrapT=Zt,this.__texture.generateMipmaps=!1,this.needsRebuild=!1,this.__height=0,this.__data_type=qu.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=Sb(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,Ju[this.__data_type])(s);e.format=function(t,e){if(0===t||1===t)return function(t){switch(t){case 1:return Te;case 2:return Ce;case 3:return Ee;case 4:return ze;default:throw new Error(`Unsupported channel count '${t}'`)}}(e);if(2===t)return Np(e);throw new Error(`Unsupported numeric type '${t}'`)}(this.__type,this.__channel_count),e.type=Vb(this.__data_type),e.internalFormat=Pp(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=Mu(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=Wb[this.__data_type],e=this.__texture.image;return t*e.width*e.height*this.__channel_count}}const Hb=new ArrayBuffer(84),jb=new Uint8Array(Hb,0,43);jb[21]=0,jb[37]=1,jb[25]=2,jb[41]=3,jb[22]=4,jb[38]=5,jb[26]=6,jb[42]=7;const qb=new Uint8Array(Hb,43,41);function Jb(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*jb[r];if(w_(a[t],a[t+1],a[t+2],e,i,n)>o)return!1}else if(2===s){const t=qb[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=Ld((h*(a-t)+c*(o-e)+u*(l-i))/(h*h+c*c+u*u));return w_(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)}qb[5]=8,qb[6]=44,qb[9]=26,qb[10]=62,qb[20]=32,qb[24]=50,qb[36]=41,qb[40]=59,qb[17]=16,qb[18]=52,qb[33]=25,qb[34]=61;const Yb=Ad;function Xb(t,e,i){const n=t[e],s=t[e+1],r=t[e+2],a=t[e+3],o=t[e+4],l=t[e+5];for(let t=0;t<24;t+=4)if(sp(i[t],i[t+1],i[t+2],i[t+3],n,s,r,a,o,l)<=0)return!1;return!0}const $b=new ArrayBuffer(4288),Zb=new Float32Array($b,0,24),Kb=new Float32Array($b,96,24),Qb=new Uint32Array($b,192,1024),tS=[];function eS(t,e,i,n,s,r){const a=function(t,e,i,n,s,r){let a=0;const o=i.binary_node_count;if(o<=0)return 0;const l=Yb.pointer++;Yb[l]=0;const h=o+i.leaf_node_count,c=i.float32,u=i.uint32;do{Yb.pointer--;const e=Yb[Yb.pointer];if(e<o){if(!Xb(c,6*e,s))continue;const t=1+(e<<1),i=t+1;i<h?(Yb[Yb.pointer++]=i,Yb[Yb.pointer++]=t):t<h&&(Yb[Yb.pointer++]=t)}else{const i=7*(e-o)+6*o,l=u[i+6],h=3&l,d=4294967288&l;if(0===h){if(!Jb(n[d],n[d+1],n[d+2],n[d+3],r,s))continue}else{if(3!==h)throw new Error(`Unsupported light type ${h}`);if(!Xb(c,i,s))continue}t[0+a]=l,a++}}while(Yb.pointer>l);return a}(tS,0,e,r,Kb,Zb);if(s[t+1]=a,0===a)return 0;const o=1023&function(t,e){let i=e;for(let n=0;n<e;n++)i=31*i+t[n];return i>>>0}(tS,a),l=Qb[o];if(4294967295!==l){if(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}(tS,a,n,l))return s[t]=l,0}else Qb[o]=i;s[t]=i;for(let t=0;t<a;t++){const e=tS[t];n[i+t]=e}return a}const iS=new gr,nS=new Qi,sS=new Qi,rS=new Qi;function aS(t,e,i){const n=3*i,s=e[n],r=e[n+1],a=e[n+2];t.set(s,r,a)}function oS(t,e,i,n,s,r){aS(nS,t,e),aS(sS,t,i),aS(rS,t,n),iS.setFromCoplanarPoints(nS,sS,rS),s[r]=iS.normal.x,s[r+1]=iS.normal.y,s[r+2]=iS.normal.z,s[r+3]=iS.constant}function lS(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}function hS(t,e,i,n,s){const r=i.normal,a=n.normal,o=s.normal;return function(t,e,i,n,s,r,a,o,l,h,c,u,d,p){const f=o*d-l*u,m=l*c-a*d,_=a*u-o*c,g=u*s-d*n,y=d*i-c*s,v=c*n-u*i,x=n*l-s*o,w=s*a-i*l,b=i*o-n*a,S=L(i,n,s,f,m,_);if(0===S)return!1;const M=1/S,T=-r,A=(f*T-g*h-x*p)*M,C=(m*T-y*h-w*p)*M,E=(_*T-v*h-b*p)*M;return t[e]=A,t[e+1]=C,t[e+2]=E,!0}(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)}class cS{constructor(t){this.light=t,this.address=0,this.bvh_leaf=new wu}compare(t){return this.light.compare(t.light)}update(){const t=this.bvh_leaf;this.light.getAABB(t.bounds),t.write_bounds()}link(t){this.bvh_leaf.link(t,this.light.id),this.update(),this.light.onDimensionChanged(this.update,this)}unlink(){this.light.offDimensionChanged(this.update,this),this.bvh_leaf.unlink()}}let uS=0;class dS{constructor(){this.id=uS++}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}}dS.prototype.type="Abstract";const pS=[];class fS extends dS{constructor(){super(),this.transform=new Float32Array(16),this.transform_inverse=new Float32Array(16),this.uv=new Float32Array(4),this.color=new Float32Array(4),this.color.fill(1),this.texture_diffuse=null,this.draw_priority=0,this.__signal_transfom_changed=new y}setTransform(t){J(this.transform,t),Y(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){np(pS,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],A=e[t+2],C=1/(a*i+c*T+f*A+y),E=(n*i+o*T+u*A+m)*C,z=(s*i+l*T+d*A+_)*C,L=(r*i+h*T+p*A+g)*C;v>E&&(v=E),b<E&&(b=E),x>z&&(x=z),S<z&&(S=z),w>L&&(w=L),M<L&&(M=L)}t[0]=v,t[1]=x,t[2]=w,t[3]=b,t[4]=S,t[5]=M}(t,pS,this.transform)}toArray(t,e){return nd(this.transform_inverse,0,t,e,16),nd(this.uv,0,t,e+16,4),nd(this.color,0,t,e+20,4),24}}function mS(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 _S(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.bounds,r=mS(n.address,n.light);e.setLeafData(t,r,s[0],s[1],s[2],s[3],s[4],s[5])}e.build()}function gS(t,e){return e.light.id-t.light.id}fS.prototype.isDecal=!0,fS.prototype.ENCODED_SLOT_COUNT=24;class yS{#Vt=new Td;#Wt=new Map;constructor(){this.__tiles_resolution=new O(32,16,8),this.__cluster_texture_precision=8,this.__cluster_texture_needs_rebuild=!1,this.__cluster_texture=new ua(new Uint16Array(4),1,1,1),this.__cluster_texture.flipY=!1,this.__cluster_texture.generateMipmaps=!1,this.__cluster_texture.magFilter=Qt,this.__cluster_texture.minFilter=Qt,this.__cluster_texture.type=le,this.__cluster_texture.format=ze,this.__cluster_texture.internalFormat="RGBA16UI",this.__lookup_data=new Gb,this.__lookup_data.type=0,this.__lookup_data.channel_count=1,this.__lookup_data.precision=8,this.__lookup_data.resize(1),this.__light_data=new Gb,this.__light_data.type=2,this.__light_data.precision=32,this.__light_data.channel_count=4,this.__light_data.resize(8),this.__decal_atlas_texture=new Bl(new Uint8Array(4),1,1,ve),this.__decal_atlas_texture.type=re,this.__decal_atlas_texture.flipY=!1,this.__decal_atlas_texture.wrapS=Zt,this.__decal_atlas_texture.wrapT=Zt,this.__decal_atlas_texture.minFilter=1008,this.__decal_atlas_texture.magFilter=ie,this.__decal_atlas_texture.generateMipmaps=!0,this.__decal_atlas_texture.anisotropy=8,this.__decal_atlas=new Eb({atlas:new Ub(512)}),this.__decal_patch_references=new zb(this.__decal_atlas),this.__decal_references=new Map,this.__visible_lights=new uv(gS),this.__visible_decals=new uv(gS),this.__sorted_visible_lights=[],this.__visible_bvh_lights=new ip,this.__visible_bvh_decals=new ip,this.__view_frustum=new xr,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}requestDataUpdate(){this.__light_data_needs_update=!0}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&&(Wp(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,Vb(Sb(0,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=Sb(0,this.__cluster_texture_precision),e=Vb(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=Pp(t,4);const r=Ju[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=Zb;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=S(s*o+511.5,0,1023),u=S(l+511.5,0,1023),d=S(h+511.5,0,1023);return Zd(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(w_(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),nd(e.elements,0,t,0,i),nd(n.elements,0,t,i,s),function(t,e,i,n,s,r=jp,a){if(n>=s)return;let o,l,h=2;for(M_[0]=n,M_[1]=s;h>0;){h-=2;const n=M_[h+1],s=M_[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&&(M_[h++]=s,M_[h++]=l),o<n&&(M_[h++]=o,M_[h++]=n)}}(t,this.__sort_visible_light_score,this,0,r-1)}__update_visible_bvh(){this.__visible_bvh_needs_update=!1,_S(this.__visible_lights,this.__visible_bvh_lights),_S(this.__visible_decals,this.__visible_bvh_decals)}__build_view_frustum(t){Im(t,this.__view_frustum,!1),jp(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=[];Of(this.__view_frustum.planes,Kb);const n=sm(i,0,this.#Vt,Kb);for(let s=0;s<n;s++){const n=i[s],r=this.#Wt.get(n),a=r.light;if(!0===a.isDecal)e.push(r);else if(!0===a.isPointLight){const e=a.position;if(!Jb(e.x,e.y,e.z,a.radius.getValue(),this.__view_frustum_points,Kb))continue;t.push(r)}}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(Qb.fill(4294967295),b=0;b<e;b++){const t=b*p;for(lS(o,u+4*b,Kb,16),w=0;w<i;w++)for(lS(o,c+4*w,Kb,8),x=0;x<n;x++){lS(o,0+4*x,Kb,0),Tb(Zb,b,a,w,s,x,v);const e=4*(t+w*n+x);S+=eS(e,l,S,y,m,d),S+=eS(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),A=this.__set_cluster_addressable_bit_range(Math.max(0,Math.log2(S)));(T&&M<S||A)&&(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++)oS(e,r,n*o+r,u+r,t,a),a+=4;for(r=0;r<l;r++)oS(e,r*o,u+r*o,r*o+i,t,a),a+=4;for(r=0;r<h;r++)oS(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];hS(t,0,i,n,s);const r=e[5];hS(t,3,i,n,r);const a=e[3];hS(t,6,i,a,s),hS(t,9,i,a,r);const o=e[1];hS(t,12,o,n,s),hS(t,15,o,n,r),hS(t,18,o,a,s),hS(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],A=t[21],C=t[22],E=t[23],z=e+1,L=i+1,I=n+1,N=z*L;for(let t=0;t<I;t++){const I=t/n,P=1-I,D=t*N;for(let t=0;t<L;t++){const n=t/i,L=1-n,N=D+t*z;for(let t=0;t<z;t++){const i=t/e,z=1-i,D=z*L*P,O=z*L*I,F=z*n*P,R=z*n*I,k=i*L*P,B=i*L*I,U=i*n*P,V=i*n*I,W=r*D+l*O+u*F+f*R+g*k+x*B+S*U+A*V,G=a*D+h*O+d*F+m*R+y*k+w*B+M*U+C*V,H=o*D+c*O+p*F+_*R+v*k+b*B+T*U+E*V,j=3*(N+t);s[j]=W,s[j+1]=G,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(),function(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];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}(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)}hasLight(t){return this.#Wt.has(t.id)}addLight(t){const e=new cS(t);e.link(this.#Vt),this.#Wt.set(t.id,e)}removeLight(t){const e=t.id,i=this.#Wt.get(e);return void 0!==i&&(i.unlink(),this.#Wt.delete(e),!0)}}class vS{transform(t){throw new Error("Not implemented")}}function xS(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 wS(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 bS="\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",SS="\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",MS="//@injection_point FORWARD_PLUS:accumulation",TS="\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",AS="\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",CS=`\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 ${AS}\n `,ES=`\n ${TS}\n `,zS=`\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 ${AS}\n `,LS="@forward-plus-material-transformer";class IS extends vS{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 Vi(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=Li,!0===t.defines.LIGHTING_VERTEX_ONLY?t.vertexShader=function(t){let e=TS+t;return e=xS(e,"void main() {",zS),e=xS(e,"#include <lights_pars_begin>",SS),e=wS(e,"#include <lights_fragment_end>",MS,bS),e}(t.vertexShader):(t.vertexShader=xS("\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=ES;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=xS(e,"void main() {",CS),e=xS(e,"#include <lights_pars_begin>",SS),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 vec4 decal_color_tint = texelFetch(fp_t_light_data, address_to_data_texture_coordinates(light_address+5u), 0);\n \n decal_color*= decal_color_tint;\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=wS(e,"#include <lights_fragment_begin>",MS,bS),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(LS)){if(t[LS]!==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=rg(t.onBeforeCompile,this.__on_before_compile),e[LS]=this),e}}class NS extends vg{constructor(){super();const t=new yS;t.setTileMapResolution(16,8,8),this.__light_manager=t,this.__resolution=new Vi,this.__material_transformer=new IS({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}}const PS=[new Qi(-1,-1,0),new Qi(-1,-1,0),new Qi(-1,1,0),new Qi(-1,1,0),new Qi(1,-1,0),new Qi(1,-1,0),new Qi(1,1,0),new Qi(1,1,0)];class DS{entity=-1;system=null;components=[];__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 OS{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===xb.POINT?this.__apply_distance():i===xb.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 FS extends dS{constructor(){super(),this.position=new O,this.radius=new sd(1),this.color=new Bd(1,1,1),this.intensity=new sd(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[0]=n-e,t[1]=s-e,t[2]=r-e,t[3]=n+e,t[4]=s+e,t[5]=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}}FS.prototype.isPointLight=!0,FS.prototype.ENCODED_SLOT_COUNT=8;class RS extends OS{constructor(){super(),this.__light=null}getPlugin(t){return t.system.__plugin.getValue()}link(t){const e=this.getPlugin(t).getLightManager(),i=new FS,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 kS(t,e){const i=t.__threeObject;if(e.toEulerAnglesXYZ(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)}Wm(t.__threeObject)}class BS{constructor(){this.views=[]}}const US=new fl;US.autoUpdate=!1,US.matrixAutoUpdate=!1,US.matrixWorldNeedsUpdate=!1;const VS=new Ko({depthPacking:Mi,side:st});function WS(t){let e;const i=t.customDepthMaterial;return e=void 0!==i?i:VS,e}function GS(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 HS extends OS{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 xb.DIRECTION:break;case xb.SPOT:r.angle=t.angle.getValue(),r.penumbra=t.penumbra.getValue(),r.distance=t.distance.getValue();break;case xb.POINT:case xb.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 BS;const t=new wv;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;sv.INSTANCE.build_scene({scene:US,input:s.elements,input_size:r,material_extractor:WS,object_filter:GS}),e.shadowmap_renderer.update(e.renderer,n,US,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===xb.SPOT||s===xb.DIRECTION?kS(n,t.rotation):Wm(i)}__apply_rotation(){kS(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 jS extends DS{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()===xb.POINT&&this.system.__use_forward_plus?this.__binding=new RS:this.__binding=new HS,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 qS{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}}function JS(t,e){let i=t.get(e);return void 0===i&&(i=[],t.set(e,i)),i}class YS{constructor(){this.__used=new Map,this.__available=new Map,this.__scene=null}__getUsed(t){return JS(this.__used,t)}__getAvailable(t){return JS(this.__available,t)}__create(t){const e=function(t){switch(t){case xb.POINT:return new Hc(0,0,0,1);case xb.AMBIENT:return new Jc(0,0);case xb.DIRECTION:return new qc(0,0);case xb.SPOT:return new kc(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 xb.POINT;if(t.isSpotLight)return xb.SPOT;if(t.isDirectionalLight)return xb.DIRECTION;if(t.isAmbientLight)return xb.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 XS extends bb{constructor(t,e={}){super(jS);const i=t.graphics;this.dependencies=[wb,G],this.components_used=[wm.from(wb,2)],this.engine=t,this.scene=i.scene,this.settings=e,this.__graphics=i,this.__camera_object=null,this.bindings=[],this.__shadows=new qS,this.__shadows.graphics=i,this.__use_forward_plus=!0,this.__plugin=null,this.__three_light_cache=new YS,this.__three_light_cache.attach(this.scene),void 0!==e.preAllocateLightsDirection&&this.__three_light_cache.reserve(xb.DIRECTION,e.preAllocateLightsDirection),void 0!==e.preAllocateLightsSpot&&this.__three_light_cache.reserve(xb.SPOT,e.preAllocateLightsSpot),void 0!==e.preAllocateLightsPoint&&this.__three_light_cache.reserve(xb.POINT,e.preAllocateLightsPoint),void 0!==e.preAllocateLightsAmbient&&this.__three_light_cache.reserve(xb.POINT,e.preAllocateLightsAmbient)}get componentClass(){return wb}setConfiguration(t,e){this.settings[t]=e;const i=this.entityManager;if(null===i)return;const n=i.dataset;null!==n&&n.traverseComponents(wb,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(NS)),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(Fm,this.__updateShadowCameraForCamera,this)}__visit_entity_to_update_shadow(t,e){const i=t.__threeObject;null!==i&&t.type.getValue()!==xb.AMBIENT&&(t.castShadow.getValue()?(i.castShadow=!0,function(t,e,i){const n=e.shadow;if(void 0===n)return;const s=n.camera;(function(t,e,i,n,s){PS[0].set(-1,-1,t),PS[1].set(-1,-1,e),PS[2].set(-1,1,t),PS[3].set(-1,1,e),PS[4].set(1,-1,t),PS[5].set(1,-1,e),PS[6].set(1,1,t),PS[7].set(1,1,e);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 t=0;t<8;t++){const e=PS[t];e.unproject(i),e.applyMatrix4(n),e.x<r&&(r=e.x),e.x>l&&(l=e.x),e.y<a&&(a=e.y),e.y>h&&(h=e.y),e.z<o&&(o=e.z),e.z>c&&(c=e.z)}s.setBounds(r,a,o,l,h,c)})(-1,1,t,s.matrixWorldInverse,$S),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}(n.mapSize,s,$S.x0,$S.y0,$S.z0,$S.x1,$S.y1,$S.z1),s.near=.1,s.far=100,s.updateProjectionMatrix(),n.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(wb,this.__visit_entity_to_update_shadow,this),!1)}}const $S=new cp;class ZS{level=new sd(0);color=new Bd(0,.3,.5);shoreDepthTransition=new Hd(.7,2);shoreColor=new Bd(.584,.792,.85);waveSpeed=new sd(1.8);waveAmplitude=new sd(.3);waveFrequency=new sd(1);scattering=new sd(1.2);bvh=new wu;constructor(t){void 0!==t&&this.fromJSON(t),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)}updateTransform(){const t=this.__threeObject;null!==t&&(t.rotation.x=.5*Math.PI,t.position.x=200,t.position.z=200,t.position.y=this.level.getValue(),Wm(t)),this.updateBounds()}updateBounds(){const t=this.level.getValue();this.bvh.resize(-200,t,-200,600,t,600)}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 Bl(t.samplerHeight.data,t.samplerHeight.width,t.samplerHeight.height,Me,ue);r.wrapS=Zt,r.wrapT=Zt,r.generateMipmaps=!1,r.minFilter=ie,r.magFilter=ie,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()}}}ZS.typeName="Water";class KS extends Sm{dependencies=[ZS];bvh=new Td;cleaup=[];updateQueue=[];__time_delta=0;constructor(t){super(),this.graphicsEngine=t,this.renderLayer=null}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(KS.RENDER_LAYER_NAME);const s=n.viewport.size;this.renderLayer.buildVisibleSet=function(t,e,i,n){const s=[];return function(n,r,a){if(null===t)return 0;const o=t.dataset;if(null===o)return 0;const l=sm(s,0,e,a.frustum);let h=0;for(let t=0;t<l;t++)h+=i.call(void 0,n,r+h,s[t],o);return h}}(this.entityManager,this.bvh,((t,e,i,n)=>{const s=n.getComponent(i,ZS).__threeObject;return null===s?0:(t[e]=s,1)}));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(ZS,(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(Pg);let n;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 Xi},tHeightTexture:{type:"t",value:null},vHeightTextureResolution:{type:"v2",value:new Vi},tDepthTexture:{type:"t",value:null},vScreenResolution:{type:"v2",value:new Vi},waterColor:{type:"c",value:new bs},shoreColor:{type:"c",value:new bs(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 Vi(.7,2)}};return new or({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:at,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=nt,null===t.__threeObject){const e=new Sr(800,800,1,1),i=vp(e,n);t.__threeObject=i}t.updateTransform(),t.level.onChanged.add(t.updateTransform,t),t.bvh.link(this.bvh,e),this.cleaup[e]=function(){t.level.onChanged.remove(t.updateTransform,t)},this.updateQueue.push(t)}unlink(t,e){t.bvh.unlink(),(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=function(t,e=Ud){const i=t.getAnyComponent(Pf),n=i.component;return e(n,i.entity),n}(i);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(ZS,this.__visit_component,this))}}function QS(t){this.scripts=t instanceof Array?t:"function"==typeof t?[t]:[]}KS.RENDER_LAYER_NAME="water-system",QS.typeName="Script",QS.serializable=!1;const tM=new O;class eM{constructor(t,e){const i=t.component,n=new Tu(0,0),s={panUp:!1,panDown:!1,panLeft:!1,panRight:!1},r=new gb;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 QS((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,G);tM.set(-a.x,0,-a.y),tM.applyQuaternion(o.rotation),i.target.add(tM)})),l=new o_;this.builder=l.add(r).add(Wg.Transient).add(Hg.fromJSON(["Keyboard Camera Controller"])).add(o)}build(t){return this.builder.build(t)}}function iM(t,e){return"function"==typeof t.hasOwnProperty?t.hasOwnProperty(e):void 0!==t[e]}function nM(t){const e=Object.keys(t),i=e.length;return i>10&&(e.splice(0,10),e.push(`[... ${i-10} more options]`)),e}function sM(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(!iM(n,r)){if("function"!=typeof i){const i=nM(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 rM(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 aM(t,e,i){t.forEach((function(t){const n=t.path,s=sM(e,n);rM(i,n,s).add(t)}))}function oM(t,e,i){t.forEach((function(t){const n=t.path,s=sM(e,n);rM(i,n,s).remove(t)}))}class lM extends Sm{constructor(t){super(),this.enabled=new qd(!0),this.dependencies=[gb],this.devices=t;const e=this;this.enabled.onChanged.add((function(t){const i=e.entityManager.dataset;null!==i&&(t?i.traverseComponents(gb,(function(t){aM(t.mapping,e.devices,e.proxies)})):i.traverseComponents(gb,(function(t){oM(t.mapping,e.devices,e.proxies)})))}))}startup(t,e,i){this.entityManager=t,this.proxies={},e()}link(t,e){aM(t.mapping,this.devices,this.proxies)}unlink(t,e){oM(t.mapping,this.devices,this.proxies),t.on.unlinked.send1(e)}}class hM{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 cM;class uM extends hM{log(t,e){switch(t){case 1:case 0:case 2:return}}static get INSTANCE(){return void 0===cM&&(cM=new uM),cM}}function dM(){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 pM{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 fM{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=Ud){return new Promise(((i,n)=>{this.loadBinary(t,i,n,e)}))}promiseStoreBinary(t,e,i=Ud){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 mM="readwrite",_M="main";class gM extends fM{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(_M)}),!0)}))}remove(t,e,i){const n=this.db.then((n=>{const s=n.transaction(_M,mM).objectStore(_M).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(_M,"readonly").objectStore(_M).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(_M,mM).objectStore(_M).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(_M,IDBTransaction.READ_ONLY).objectStore(_M).getAllKeys();n.addEventListener("success",(e=>{t(e.target.result)})),n.addEventListener("error",(t=>{e(t)}))})).catch(e)}}class yM{constructor(){}getUnlocked(){throw new Error("Not implemented")}unlock(t){throw new Error("Not implemented")}}class vM extends yM{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,Ud)}))}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,Ud)}),n,Ud)}))));return this.last=i,i}}class xM extends pM{constructor({storageKey:t="@woosh/meep/app"}={}){super(),this.storage=new gM(t,this.services),this.storage.compressionEnabled=!1,this.achievements=new vM(this.storage)}getStorage(){return this.storage}getAchievementGateway(){return this.achievements}pickDefaultLocale(t){const e=dM();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}}function wM(){this.prevPosition={x:0,y:0,z:0},this.nodes={listener:null}}wM.typeName="SoundListener",wM.prototype.toJSON=function(){return{}},wM.prototype.fromJSON=function(t){},wM.prototype.toBinaryBuffer=function(t){},wM.prototype.fromBinaryBuffer=function(t){};let bM=null;function SM(){if(null!==bM)return bM;const t=globalThis.navigator;if(void 0===t)throw new Error("Not a browser, globalThis.navigator is undefined");let e,i=t.userAgent,n=i.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];if(/trident/i.test(n[1]))return e=/\brv[ :]+(\d+)/g.exec(i)||[],{name:"IE",version:e[1]||""};if("Chrome"===n[1]&&(e=i.match(/\bOPR|Edge\/(\d+)/),null!=e))return{name:"Opera",version:e[1]};n=n[2]?[n[1],n[2]]:[t.appName,t.appVersion,"-?"],null!=(e=i.match(/version\/(\d+)/i))&&n.splice(1,1,e[1]);const s={name:n[0],version:n[1]};return bM=s,s}const MM=new O,TM=new O;class AM{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;MM.copy(O.forward),MM.applyQuaternion(t),TM.copy(O.up),TM.applyQuaternion(t);const e=this.audioContext.listener;LM(e,MM,TM)}updatePosition(){const t=this.audioContext.listener;zM(t,this.transform.position)}}class CM extends Sm{constructor(t){super(),this.dependencies=[wM,G],this.components_used=[wm.from(wM,3)],this.webAudioContext=t,this.data=[]}link(t,e,i){const n=new AM;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 EM(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 zM=function(t,e){};if(void 0!==globalThis.navigator){const t=SM();"Chrome"===t.name?zM=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)}:EM:"Firefox"===t.name&&(zM=EM)}let LM=Ud;if(void 0!==globalThis.navigator){const t=SM();"Chrome"===t.name?LM=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&&(LM=function(t,e,i){t.setOrientation(e.x,e.y,e.z,i.x,i.y,i.z)})}class IM{constructor(){this.engine=new nb(new xM),window.engine=this.engine,ix.addBackend(uM.INSTANCE),this.p=null}static addFpsCounter(t){const e=new Og;t.graphics.on.postRender.add(e.update,e);const i=new Ug({el:e.domElement});t.viewStack.addChild(i)}initialize({configuration:t=Ud,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 sb;if(t(r,i),r.hasLoader("json")||r.addLoader("json",new Vg),await r.apply(i),await i.start(),e)try{await function(t){const e=dM();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(kv,(function t(){window.removeEventListener(kv,t),i.sound.resumeContext()})),n(i)}));return this.p=n,n}static buildCamera({engine:t,ecd:e=t.entityManager.dataset,target:i=new O,distance:n=10,pitch:s=1.4,yaw:r=0,autoClip:a=!1,distanceMin:o=.01,distanceMax:l=1e3,fieldOfView:h=45}){const c=t.entityManager;null===c.getSystem(vb)&&c.addSystem(new vb),null===c.getSystem(Hm)&&c.addSystem(new Hm(t.graphics)),null===c.getSystem(CM)&&c.addSystem(new CM(t.sound.context)),e.isComponentTypeRegistered(Hg)||e.registerComponentType(Hg);const u=new G,d=new mb;d.pitch=s,d.yaw=r,d.distance=n,d.distanceMin=o,d.distanceMax=l,d.target.copy(i);const p=new Fm;p.active.set(!0),p.autoClip=a,p.clip_far=l,p.fov.set(h);const f=new o_;return f.add(u).add(d).add(p).add(new wM).add(Hg.fromJSON(["Camera"])).build(e),f}static async buildBasics({engine:t,focus:e=new O(10,0,10),heightMap:i,heightRange:n,pitch:s=.7,yaw:r=-1.2,distance:a=10,terrainSize:o=new Tu(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&&IM.addFpsCounter(t),u&&await IM.buildLights({engine:t,shadowmapResolution:_});const y=IM.buildCamera({engine:t,target:e,pitch:s,yaw:r,distance:a,fieldOfView:d,distanceMax:p,autoClip:m}).id;if(c&&await IM.buildTerrain({engine:t,heightMap:i,heightRange:n,resolution:l,size:o,enableWater:h}),f){IM.buildOrbitalCameraController({engine:t,cameraEntity:y});const e=t.entityManager.dataset;new eM({component:e.getComponent(y,mb),entity:y},e).build(e)}}static async buildLights({engine:t,ecd:e=t.entityManager.dataset,shadowmapResolution:i=1024,castShadow:n=!0}){const s=t.entityManager;s.hasSystem(XS)||await s.addSystem(new XS(t,{shadowResolution:i})),e.isComponentTypeRegistered(Hg)||e.registerComponentType(Hg);const r=new wb;r.type.set(wb.Type.DIRECTION),r.color.setRGB(1,1,1),r.intensity.set(.8),r.castShadow.set(n);const a=new G;a.position.set(30,70,30),a.rotation.set(-.18780341950959473,.8049745556929917,-.4533975611897181,-.3334313787830773),(new o_).add(r).add(a).add(Hg.fromJSON(["Light","Key"])).build(e);const o=new wb;o.type.set(wb.Type.AMBIENT),o.color.setRGB(1,1,1),o.intensity.set(.1),(new o_).add(o).add(new G).add(Hg.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(Fm).entity);const s=e.entityManager;null===s.getSystem(lM)&&await s.addSystem(new lM(e.devices)),i.isComponentTypeRegistered(Wg)||i.registerComponentType(Wg);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,mb)}const r=new gb([{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);!function(t){const e=[];for(let i=0;i<32;i++){const n=t>>i;e[i]=0!=(1&n)}return e}(l.buttons)[0]?function(t){const e=s();pb(t.x*n,t.y*n,e,e)}(h):function(n){const r=n.clone(),a=s(),o=e.getComponent(t,Fm);mb.pan(r,o.object,i,a.distance,o.object.fov,a.target)}(h),l.preventDefault()}},{path:"pointer/on/wheel",listener(t,e){!function(t){const e=s(),i=e.distance+t;e.distance=S(i,e.distanceMin,e.distanceMax)}(t.y)}}]),a=new o_;return a.add(r),a}({camera_entity:t,ecd:i,dom_element:r,sensitivity:n});return a.add(Hg.fromJSON(["CameraController"])),a.add(Wg.Transient),a.build(i),a}static async buildTerrain({engine:t,size:e=new Tu(10,10),diffuse0:i="data/textures/utility/checkers_dark_grey_256x256.png",heightRange:n=0,resolution:s=10,waterLevel:r=0,enableWater:a=!0}){const o=t.entityManager;null===o.getSystem(qm)&&await o.addSystem(new qm(t.graphics,t.assetManager));const l=new Pf;l.size.copy(e),l.resolution=s,l.gridScale=2,l.layers.addLayer(df.from(i,5,5)),l.splat.resize(1,1,1),l.splat.fillLayerWeights(0,255),l.build(t.assetManager);const h=new o_;if(h.add(new G),h.add(l),a){null===o.getSystem(KS)&&o.addSystem(new KS(t.graphics));const e=new ZS;e.level.set(r),h.add(e)}return h.build(t.entityManager.dataset),l}}let NM=null;IM.getSingleton=function(){return null===NM&&(NM=new IM),NM};class PM extends Ew{constructor(){super(),this.__currentBehaviour=null,this.__currentBehaviourIndex=-1}static from(t){const e=new PM;return t.forEach(e.addChild,e),e}tick(t){if(this.__children.length<1)return Sw.Failed;for(;;){const e=this.__currentBehaviour.tick(t);if(e!==Sw.Failed)return e;this.__currentBehaviour.finalize();const i=this.__children;if(this.__currentBehaviourIndex++,this.__currentBehaviourIndex>=i.length)return this.__currentBehaviour=null,Sw.Failed;this.__currentBehaviour=i[this.__currentBehaviourIndex],this.__currentBehaviour.initialize(this.context)}}finalize(){null!==this.__currentBehaviour&&(this.__currentBehaviour.finalize(),this.__currentBehaviour=null),super.finalize()}initialize(t){const e=this.__children;e.length>0?(this.__currentBehaviourIndex=0,this.__currentBehaviour=e[0],this.__currentBehaviour.initialize(t)):(this.__currentBehaviourIndex=-1,this.__currentBehaviour=null),super.initialize(t)}}const DM={RequireOne:0,RequireAll:1};class OM extends Ew{constructor(t,e){super(),this.successPolicy=t,this.failurePolicy=e,this.activeSet=new Km,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===Sw.Succeeded){if(e.set(s,!1),this.successCount++,n.finalize(),this.successPolicy===DM.RequireOne)return this.__finalizeActiveChildren(),Sw.Succeeded}else if(r===Sw.Failed){if(e.set(s,!1),this.failureCount++,n.finalize(),this.failurePolicy===DM.RequireOne)return this.__finalizeActiveChildren(),Sw.Failed;if(this.successPolicy===DM.RequireAll)return this.__finalizeActiveChildren(),Sw.Failed}}return this.successCount===n&&this.successPolicy===DM.RequireAll?Sw.Succeeded:this.failureCount===n&&this.failurePolicy===DM.RequireAll||this.failureCount+this.successCount===n?Sw.Failed:Sw.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(),super.finalize()}static from(t,e=DM.RequireAll,i=DM.RequireOne){const n=new OM(e,i);return n.addChildren(t),n}}OM.prototype.isParallelBehavior=!0,OM.typeName="ParallelBehavior";class FM{constructor(t){this.referenceCount=0,this.type=t,this.value=function(t){let e;switch(t){case Qg.Number:e=new sd(0);break;case Qg.Boolean:e=new Em(!1);break;case Qg.String:e=new hd("");break;default:throw new TypeError(`Unsupported data type '${t}'`)}return e}(t)}}class RM{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,Qg.Boolean,e)}acquireNumber(t,e=0){return this.acquire(t,Qg.Number,e)}incrementNumber(t,e=1){this.acquireNumber(t)._add(e),this.release(t)}acquireString(t,e=""){return this.acquire(t,Qg.String,e)}}class kM extends RM{constructor(){super(),this.on={added:new y},this.data={},this.proxy=new Proxy(this,{get(t,e,i){if(t.contains(e,Qg.Any))return t.acquire(e,Qg.Any).getValue()},set(t,e,i,n){const s=function(t){switch(typeof t){case"number":return Qg.Number;case"string":return Qg.String;case"boolean":return Qg.Boolean;default:if(Array.isArray(t))return Qg.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===Qg.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!==Qg.Any&&n.type!==e)throw new TypeError(`Value '${t}' exists, but is type(='${n.type}'), expected type '${e}'`)}else{n=new FM(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){const e=this.data;t.traverse(((t,i,n)=>{const s=e[t],r=i.getValue();void 0===s?this.acquire(t,n,r):s.type!==n?(delete e[t],this.acquire(t,n,r)):s.value.set(r)}));const i=[];for(const n in e){const s=e[n];t.contains(n,s.type)||i.push(n)}for(let t=0;t<i.length;t++){const n=i[t];delete e[n]}}clone(){const t=new kM;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)}}static fromJSON(t){const e=new kM;return e.fromJSON(t),e}}function BM(t){return t-1>>1}kM.typeName="Blackboard";const UM=new Uint32Array(4);function VM(t,e,i){const n=e%i,s=e/i|0;t.set(n,s)}function WM(t,e,i,n){const s=e%i,r=e/i|0;let a=0;return r>0&&(t[a]=e-i,a++),s>0&&(t[a]=e-1,a++),s<i-1&&(t[a]=e+1,a++),r<n-1&&(t[a]=e+i,a++),a}function GM(t,e,i,n){let s=new Tu(-1,-1),r=new Tu,a=1,o=1,l=0,h=0;const c=[];let u=t,d=u,p=e[u];for(;-1!==u;){VM(r,u,i),l=r.x-s.x,h=r.y-s.y,0!==l&&(l/=Math.abs(l)),0!==h&&(h/=Math.abs(h)),(a!==l||o!==h)&&(a=l,o=h,c.push(d)),d=u;const t=s;s=r,r=t;const f=WM(UM,u,i,n);u=-1;for(let t=0;t<f;t++){const n=UM[t],c=e[n];c<p?(u=n,p=c):c===p&&(VM(r,n,i),l=r.x-s.x,h=r.y-s.y,l===a&&h===o&&(u=n,p=c))}}return c[c.length-1]!==d&&c.push(d),c.reverse(),c}function HM(t,e,i){const n=e%i-t%i,s=(e/i|0)-(t/i|0);return n*n+s*s}const jM=new class{constructor(t=64){this.__data_buffer=new ArrayBuffer(8*t),this.__data_uint32=new Uint32Array(this.__data_buffer),this.__data_float32=new Float32Array(this.__data_buffer),this.__capacity=t,this.__size=0}__capacity_grow(){const t=this.__capacity,e=Math.ceil(Mu(1.2*t,t+16)),i=new ArrayBuffer(8*e),n=new Uint32Array(i);n.set(this.__data_uint32),this.__data_buffer=i,this.__data_uint32=n,this.__data_float32=new Float32Array(i),this.__capacity=e}compare(t,e){const i=this.__data_float32,n=e<<1;return i[t<<1]<i[n]}swap(t,e){const i=t<<1,n=e<<1,s=this.__data_uint32,r=s[i];s[i]=s[n],s[n]=r;const a=i+1,o=n+1,l=s[a];s[a]=s[o],s[o]=l}heap_down(t){let e=t;const i=this.__size;for(;;){const t=1+(e<<1),n=t+1;let s=e;if(t<i&&this.compare(t,s)&&(s=t),n<i&&this.compare(n,s)&&(s=n),s===e)break;this.swap(e,s),e=s}}heap_up(t){let e=t;for(;e>0;){const t=e-1>>1;if(this.compare(t,e))break;this.swap(t,e),e=t}}get size(){return this.__size}get capacity(){return this.__capacity}get top_id(){return this.__data_uint32[1]}is_empty(){return 0===this.__size}peek_min(){return this.top_id}pop_min(){const t=this.top_id;return this.__size--,this.__size>0&&(this.swap(0,this.__size),this.heap_down(0)),t}find_index_by_id(t){const e=this.__size<<1,i=this.__data_uint32;for(let n=1;n<e;n+=2)if(i[n]===t)return n>>>1;return-1}contains(t){return-1!==this.find_index_by_id(t)}clear(){this.__size=0}remove(t){const e=this.find_index_by_id(t);return-1!==e&&(this.__remove_by_index(e),!0)}__remove_by_index(t){let e=t;for(;e>0;){const t=BM(e);this.swap(t,e),e=t}this.pop_min()}update_score(t,e){const i=this.find_index_by_id(t);if(-1===i)throw new Error("Not found");this.__update_score_by_index(i,e)}__update_score_by_index(t,e){const i=this.__data_float32,n=t<<1,s=i[n];e<s?(i[n]=e,this.heap_up(t)):e>s&&(i[n]=e,this.heap_down(t))}get_score(t){const e=this.find_index_by_id(t);if(-1===e)return Number.NaN;const i=e<<1;return this.__data_float32[i]}insert_or_update(t,e){const i=this.find_index_by_id(t);-1===i?this.insert(t,e):this.__update_score_by_index(i,e)}insert(t,e){const i=this.__size;i>=this.__capacity&&this.__capacity_grow();const n=i,s=n<<1;this.__data_float32[s]=e,this.__data_uint32[s+1]=t,this.__size=i+1,this.heap_up(n)}},qM=new Km;qM.preventShrink(),t.AmbientOcclusionPostProcessEffect=class extends vg{constructor(){super(),this.id="ambient-occlusion-post-process";const t=Object.assign({},xg.defines);this.__material=new or({defines:t,fragmentShader:xg.fragmentShader,vertexShader:xg.vertexShader,uniforms:ar.clone(xg.uniforms),glslVersion:Li,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=rt,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 Zi(1,1,{minFilter:ie,magFilter:ie,format:Me,type:re,internalFormat:"R8",depthBuffer:!1,stencilBuffer:!1,generateMipmaps:!1}),this.__used_buffers=[],this.__blur=new Ng({format:Me,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(),Lg(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(Dg);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:Me,type:re,internalFormat:"R8"},3),this.__composit_layer.name="Ambient Occlusion",this.__composit_layer.stage=1;const e=this.__material.uniforms,i=t.frameBuffers.getById(Pg).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=Mw,t.BehaviorStatus=Sw,t.Blackboard=kM,t.Cache=nf,t.EngineConfiguration=sb,t.EngineHarness=IM,t.ForwardPlusRenderingPlugin=NS,t.HashMap=Zp,t.Light=wb,t.ParallelBehavior=OM,t.ParallelBehaviorPolicy=DM,t.SGMesh=Kf,t.SGMeshSystem=class extends Sm{constructor(t){super(),this.__engine=t,this.__assetManager=t.assetManager,this.dependencies=[Kf,G],this.components_used=[wm.from(Kf,3),wm.from(G,1),wm.from(Yf,4),wm.from(l_,4)],this.__wait_queue=[],this.__wait_queue_process_index=0}async startup(t,e,i){t.hasSystem(d_)||await t.addSystem(new d_),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,Kf)!==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=Jm.get(a);null!==l?o=l:(o=a.create(),Jm.set(a,o));let h=f_(o);if(a.has_root_transform){const t=new c_;t.entity.add(new G),h.transform.copy(a.root_transform),t.addChild(h),h=t}function c(){h.transform.copy(i)}h.entity.add(h_.from(t)),e.__node=h,c(),h.build(s),i.subscribe(c),h.on.destroyed.addOne((()=>{i.unsubscribe(c)}));const u=e.materialOverride;h.traverse((t=>{const i=t.entity.getComponent(Yf);null!==i&&(i.writeFlag(2,e.castShadow),i.writeFlag(4,e.receiveShadow),null!==u&&(i.material=u))})),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+C(n,128);for(;s<r;){const r=s%n;s++;const a=i[r],o=e.getComponent(a,Kf);if(null===o.url)continue;i.splice(r,1);const l=e.getComponent(a,G);if(this.process(a,o,l),performance.now()-t>40)break}this.__wait_queue_process_index=s}}},t.SelectorBehavior=PM,t.SequenceBehavior=zw,t.ShadedGeometry=Yf,t.ShadedGeometrySystem=class extends Sm{constructor(t){super(),this.dependencies=[Yf,G],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 Td;const e=new S_;this.__optimization_task=new Lf({name:"ShadedGeometry Draw Method optimizer",initializer:()=>{e.__system=this},cycleFunction:()=>e.step()?2:3}),this.__maintenance_task=function(t,e,i=2){return new Lf({name:t,cycleFunction:()=>e.next().done?0:i})}("Maintenance",function*(t){for(;;){const e=t.__view_contexts;for(const[t,i]of e)void 0!==i&&(yield*i.maintain());yield}}(this),3)}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 pg;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(Ef.INITIAL),n.executor.run(this.__optimization_task),this.__maintenance_task.state.set(Ef.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.subscribe(t.updateTransform,t),t.__entity=i,t.__bvh_leaf.link(this.__bvh_binary,i);const n=t.geometry.id,s=this.__geometry_usage_counters.get(n),r=void 0!==s?s+1:1;this.__geometry_usage_counters.set(n,r)}unlink(t,e,i){e.unsubscribe(t.updateTransform,t),t.__bvh_leaf.unlink();const n=t.geometry.id,s=this.__geometry_usage_counters.get(n);1===s?(this.__geometry_usage_counters.delete(n),t.geometry.dispose()):this.__geometry_usage_counters.set(n,s-1)}queryOverlapFrustum(t,e,i){return sm(t,e,this.__bvh_binary,i)}raycast(t,e,i,n,s,r,a=x_,o){const l=[],h=[],c=this.__bvh_binary,u=__(h,0,c,c.root,v_.from([t,e,i,n,s,r])),d=this.entityManager.dataset;if(null===d)return l;const p=d.computeComponentTypeIndex(Yf);for(let f=0;f<u;f++){const u=h[f],m=c.node_get_user_data(u),_=d.getComponentByIndex(m,p);if(!a.call(o,m,_))continue;const g=_.transform;dp(mg,t,e,i,n,s,r),_.query_raycast_nearest(fg,mg,g)&&l.push({entity:m,mesh:_,contact:fg.clone()})}return l}raycastNearest(t,e,i,n,s,r,a,o=x_,l){let h=Infinity,c=!1,u=null;const d=[],p=this.__bvh_binary,f=__(d,0,p,p.root,v_.from([e,i,n,s,r,a])),m=this.entityManager.dataset;if(null===m)return;const _=m.computeComponentTypeIndex(Yf);for(let g=0;g<f;g++){const f=d[g],y=p.node_get_user_data(f),v=m.getComponentByIndex(y,_);if(!o.call(l,y,v))continue;const x=v.transform;if(dp(mg,e,i,n,s,r,a),!v.query_raycast_nearest(fg,mg,x))continue;c=!0;const w=fg.position,b=w_(w.x,w.y,w.z,e,i,n);b<h&&(t.copy(fg),u=v,h=b)}return c?{entity:u.__entity,mesh:u}:void 0}},t.Signal=y,t.SignalBinding=xm,t.Transform=G,t.dispatchViaProxy=b,t.findSignalHandlerIndexByHandle=v,t.findSignalHandlerIndexByHandleAndContext=x,t.find_path_on_grid_astar=function(t,e,i,n,s,r,a){jM.clear(),qM.reset();const o=[];for(o[n]=0,jM.insert(n,HM(n,s,e));!jM.is_empty();){const n=jM.pop_min();if(n===s)return GM(n,o,e,i);qM.set(n,!0);const l=WM(UM,n,e,i);for(let i=0;i<l;++i){const l=UM[i];if(qM.get(l))continue;const h=t[l];if(h===a){qM.set(l,!0);continue}const c=h*r+1,u=o[n]+c,d=jM.find_index_by_id(l),p=-1===d;if(p||u<o[l]){o[l]=u;const t=u+HM(l,s,e);p?jM.insert(l,t):jM.__update_score_by_index(d,t)}}}return[]},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.v2_angleBetween=function(t,e,i,n){const s=S(Au(t,e,i,n)/(Eu(t,e)*Eu(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=zu,t.v2_dot=Au,t.v2_length_sqr=Cu,t.v2_magnitude=Eu,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,A=a*v+c*x+f*w+y*b;t[0]=S,t[1]=M,t[2]=T,t[3]=A},t.v4_distance_sqr=function(t,e,i,n,s,r,a,o){return ad(t-s,e-r,i-a,n-o)},t.v4_dot=function(t,e,i,n,s,r,a,o){return t*s+e*r+i*a+n*o},t.v4_length_sqr=ad}));
|