text: !function(t){var e={};function r(n){if(e[n])return e[n].exports;var i=e[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)r.d(n,i,function(e){return t[e]}.bind(null,i));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=100)}([function(t,e,r){"use strict";r.d(e,"a",(function(){return u})),r.d(e,"b",(function(){return c}));var n=r(13),i=r(1),s=r(2),o=r(4);const a=Array;class u extends a{get x(){return this[0]}set x(t){this[0]=t}get y(){return this[1]}set y(t){this[1]=t}get magnitude(){return Math.hypot(...this)}get magnitudeSqr(){return this[0]*this[0]+this[1]*this[1]}get normalized(){const t=this.magnitude;return 0==t?c.zero():this.clone().div(c(t,t))}get negative(){return this.clone().negate()}get inversed(){return this.clone().inverse()}get isZero(){return 0===this.x&&0===this.y}constructor(t,e){super(t,e)}static zero(){return new u(0,0)}static one(){return new u(1,1)}static up(){return new u(0,1)}static down(){return new u(0,-1)}static left(){return new u(-1,0)}static right(){return new u(1,0)}static distance(t,e){return Math.sqrt((t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y))}static distanceSquared(t,e){return(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y)}static math(t){return(...e)=>c(t(...e.map(t=>t.x)),t(...e.map(t=>t.y)))}asMut(){return this}plus(t){return c.plus(this,this,t)}minus(t){return c.minus(this,this,t)}mul(t){return c.mul(this,this,t)}div(t){return c.div(this,this,t)}dot(t){return this[0]*t[0]+this[1]*t[1]}normalize(){return c.normalize(this,this)}inverse(){return this[0]=1/this[0],this[1]=1/this[1],this}negate(){return this[0]=-this[0],this[1]=-this[1],this}oneMinus(){return this[0]=1-this[0],this[1]=1-this[1],this}equals(t){return void 0!==t&&(t[0]===this[0]&&t[1]===this[1])}clone(t=c.zero()){return t.set(this)}set(t){return this[0]=t[0]||0,this[1]=t[1]||0,this}fill(t){return this[0]=this[1]=t,this}toVec3(t=0){return Object(i.b)(this[0],this[1],t)}__to(t){switch(t){case n.a:return Object(n.b)(this[0],this[1],0,0);case i.a:return Object(i.b)(this[0],this[1],0)}return this.clone()}}function c(t,e=t){return new u(t,e)}c.from=t=>{const[e=0,r=0]=t;return c(e,r)},c.floor=t=>c(Math.floor(t.x),Math.floor(t.y)),c.zero=u.zero,c.one=u.one,c.left=u.left,c.right=u.right,c.down=u.down,c.up=u.up,c.math=u.math,c.plus=Object(s.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]+r,t[1]=e[1]+r):(t[0]=e[0]+r[0],t[1]=e[1]+(r[1]||0)),t),2,c.zero),c.minus=Object(s.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]-r,t[1]=e[1]-r):(t[0]=e[0]-r[0],t[1]=e[1]-(r[1]||0)),t),2,c.zero),c.mul=Object(s.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]*r,t[1]=e[1]*r):(t[0]=e[0]*r[0],t[1]=e[1]*r[1]),t),2,c.zero),c.div=Object(s.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]/r,t[1]=e[1]/r):(t[0]=e[0]/r[0],t[1]=e[1]/r[1]),t),2,c.zero),c.exp=Object(s.b)((t,e)=>("number"==typeof e?(t[0]=Math.exp(e),t[1]=Math.exp(e)):(t[0]=Math.exp(e[0]),t[1]=Math.exp(e[1])),t),1,c.zero),c.inverse=Object(s.b)((t,e)=>(t[0]=1/e[0],t[1]=1/e[1],t),1,c.zero),c.dot=(t,e)=>t[0]*e[0]+t[1]*e[1],c.cross=(t,e)=>t[0]*e[1]-t[1]*e[0],c.normalize=Object(s.b)(o.d.normalize,1,c.zero),c.perpendicular=Object(s.b)((t,e)=>(t[0]=-e[1],t[1]=e[0],t),1,c.zero),c.set=Object(s.b)((t,e)=>(t[0]=e[0],t[1]=e[1],t),1,c.zero),c.fill=Object(s.b)((t,e)=>(t[0]=t[1]=e,t),1,c.zero)},function(t,e,r){"use strict";r.d(e,"a",(function(){return u})),r.d(e,"b",(function(){return c}));var n=r(13),i=r(0),s=r(2),o=r(4);const a=Array;class u extends a{get x(){return this[0]}set x(t){this[0]=t}get y(){return this[1]}set y(t){this[1]=t}get z(){return this[2]}set z(t){this[2]=t}get magnitude(){return Math.hypot(...this)}get normalized(){const t=this.magnitude;return 0==t?c.zero():this.clone().div(c(t,t,t))}get negative(){return this.clone().negate()}get inversed(){return this.clone().inverse()}constructor(t,e,r){super(t,e,r)}static zero(){return new u(0,0,0)}static one(){return new u(1,1,1)}asMut(){return this}plus(t){return c.plus(this,this,t)}minus(t){return c.minus(this,this,t)}mul(t){return c.mul(this,this,t)}div(t){return c.div(this,this,t)}dot(t){return this[0]*t[0]+this[1]*t[1]+this[2]*t[2]}normalize(){return c.normalize(this,this)}inverse(){return this[0]=1/this[0],this[1]=1/this[1],this[2]=1/this[2],this}negate(){return this[0]=-this[0],this[1]=-this[1],this[2]=-this[2],this}cross(t){return c(this.y*t.z-this.z*t.y,this.z*t.x-this.x*t.z,this.x*t.y-this.y*t.x)}set(t){return this[0]=t[0]||0,this[1]=t[1]||0,this[2]=t[2]||0,this}fill(t){return this[0]=this[1]=this[2]=t,this}clone(t=c.zero()){return t.set(this)}setX(t){return this[0]=t,this}setY(t){return this[1]=t,this}setZ(t){return this[2]=t,this}toVec2(){return Object(i.b)(this[0],this[1])}equals(t){return void 0!==t&&(t[0]===this[0]&&t[1]===this[1]&&t[2]===this[2])}static math(t){return(...e)=>c(t(...e.map(t=>t.x)),t(...e.map(t=>t.y)),t(...e.map(t=>t.z)))}static mathNonAlloc(t,e,...r){return e[0]=t(...r.map(t=>t[0])),e[1]=t(...r.map(t=>t[1])),e[2]=t(...r.map(t=>t[2])),e}__to(t){switch(t){case n.a:return Object(n.b)(this[0],this[1],this[2],0);case i.a:return Object(i.b)(this[0],this[1])}return this.clone()}}function c(t,e=t,r=t){return new u(t,e,r)}c.from=t=>{const[e=0,r=0,n=0]=t;return c(e,r,n)},c.zero=u.zero,c.one=u.one,c.math=u.math,c.normalize=Object(s.b)(o.e.normalize,1,c.zero),c.inverse=Object(s.b)(o.e.inverse,1,c.zero),c.negate=Object(s.b)(o.e.negate,1,c.zero),c.plus=Object(s.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]+r,t[1]=e[1]+r,t[2]=e[2]+r):(t[0]=e[0]+r[0],t[1]=e[1]+(r[1]||0),t[2]=e[2]+(r[2]||0)),t),2,c.zero),c.minus=Object(s.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]-r,t[1]=e[1]-r,t[2]=e[2]-r):(t[0]=e[0]-r[0],t[1]=e[1]-(r[1]||0),t[2]=e[2]-(r[2]||0)),t),2,c.zero),c.mul=Object(s.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r):(t[0]=e[0]*r[0],t[1]=e[1]*(void 0===r[1]?1:r[1]),t[2]=e[2]*(void 0===r[2]?1:r[2])),t),2,c.zero),c.div=Object(s.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]/r,t[1]=e[1]/r,t[2]=e[2]/r):(t[0]=e[0]/r[0],t[1]=e[1]/(void 0===r[1]?1:r[1]),t[2]=e[2]/(void 0===r[2]?1:r[2])),t),2,c.zero),c.set=Object(s.b)((t,e)=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t),1,c.zero),c.fill=Object(s.b)((t,e)=>(t[0]=t[1]=t[2]=e,t),1,c.zero)},function(t,e,r){"use strict";function n(t,e,r){return(...n)=>{if(n.length<=e){const e=r();return t(e,...n)}{let[e,...i]=n;return void 0===e&&(e=r()),t(e,...i)}}}r.d(e,"b",(function(){return n})),r.d(e,"a",(function(){return i}));Math.log(.01);const i={lerp:(t,e,r)=>(e-t)*r+t,linstep:(t,e,r)=>i.clamp((r-t)/(e-t),0,1),smoothStep(t,e,r){const n=i.linstep(t,e,r);return n*n*(3-2*n)},clamp:(t,e,r)=>Math.min(Math.max(t,e),r),mapClamped(t,e,r,n,s){const o=this.linstep(t,e,s);return i.lerp(r,n,o)},damp:function(t,e,r,n,s=.01,o=-Math.log(s)){const a=o/r,u=Math.exp(-n*a);return i.lerp(t,e,1-u)}}},function(t,e,r){"use strict";r.d(e,"c",(function(){return i})),r.d(e,"e",(function(){return a})),r.d(e,"d",(function(){return u})),r.d(e,"b",(function(){return c})),r.d(e,"a",(function(){return h}));var n=r(36);class i{constructor(){this.gl=null,this.width=0,this.height=0,this.assets=null,this.renderer=null}}let s,o=new class extends n.a{drawLine(t,e,r){}};const a=t=>s=t,u=()=>s,c=()=>{var t;return null===(t=u())||void 0===t?void 0:t.gl},h=t=>(t&&(o=t),o)},function(t,e,r){"use strict";r.d(e,"a",(function(){return n})),r.d(e,"b",(function(){return i})),r.d(e,"c",(function(){return a})),r.d(e,"d",(function(){return u})),r.d(e,"e",(function(){return s})),r.d(e,"f",(function(){return o}));var n={};r.r(n),r.d(n,"EPSILON",(function(){return c})),r.d(n,"ARRAY_TYPE",(function(){return h})),r.d(n,"RANDOM",(function(){return l})),r.d(n,"setMatrixArrayType",(function(){return d})),r.d(n,"toRadian",(function(){return b})),r.d(n,"equals",(function(){return m}));var i={};r.r(i),r.d(i,"create",(function(){return p})),r.d(i,"clone",(function(){return v})),r.d(i,"copy",(function(){return g})),r.d(i,"fromValues",(function(){return y})),r.d(i,"set",(function(){return x})),r.d(i,"identity",(function(){return M})),r.d(i,"transpose",(function(){return w})),r.d(i,"invert",(function(){return R})),r.d(i,"adjoint",(function(){return _})),r.d(i,"determinant",(function(){return O})),r.d(i,"multiply",(function(){return T})),r.d(i,"translate",(function(){return A})),r.d(i,"scale",(function(){return E})),r.d(i,"rotate",(function(){return S})),r.d(i,"rotateX",(function(){return j})),r.d(i,"rotateY",(function(){return P})),r.d(i,"rotateZ",(function(){return z})),r.d(i,"fromTranslation",(function(){return F})),r.d(i,"fromScaling",(function(){return C})),r.d(i,"fromRotation",(function(){return L})),r.d(i,"fromXRotation",(function(){return B})),r.d(i,"fromYRotation",(function(){return D})),r.d(i,"fromZRotation",(function(){return I})),r.d(i,"fromRotationTranslation",(function(){return U})),r.d(i,"fromQuat2",(function(){return N})),r.d(i,"getTranslation",(function(){return G})),r.d(i,"getScaling",(function(){return k})),r.d(i,"getRotation",(function(){return V})),r.d(i,"fromRotationTranslationScale",(function(){return W})),r.d(i,"fromRotationTranslationScaleOrigin",(function(){return q})),r.d(i,"fromQuat",(function(){return H})),r.d(i,"frustum",(function(){return K})),r.d(i,"perspective",(function(){return Y})),r.d(i,"perspectiveFromFieldOfView",(function(){return X})),r.d(i,"ortho",(function(){return Z})),r.d(i,"lookAt",(function(){return Q})),r.d(i,"targetTo",(function(){return $})),r.d(i,"str",(function(){return J})),r.d(i,"frob",(function(){return tt})),r.d(i,"add",(function(){return et})),r.d(i,"subtract",(function(){return rt})),r.d(i,"multiplyScalar",(function(){return nt})),r.d(i,"multiplyScalarAndAdd",(function(){return it})),r.d(i,"exactEquals",(function(){return st})),r.d(i,"equals",(function(){return ot})),r.d(i,"mul",(function(){return at})),r.d(i,"sub",(function(){return ut}));var s={};r.r(s),r.d(s,"create",(function(){return ct})),r.d(s,"clone",(function(){return ht})),r.d(s,"length",(function(){return lt})),r.d(s,"fromValues",(function(){return dt})),r.d(s,"copy",(function(){return ft})),r.d(s,"set",(function(){return bt})),r.d(s,"add",(function(){return mt})),r.d(s,"subtract",(function(){return pt})),r.d(s,"multiply",(function(){return vt})),r.d(s,"divide",(function(){return gt})),r.d(s,"ceil",(function(){return yt})),r.d(s,"floor",(function(){return xt})),r.d(s,"min",(function(){return Mt})),r.d(s,"max",(function(){return wt})),r.d(s,"round",(function(){return Rt})),r.d(s,"scale",(function(){return _t})),r.d(s,"scaleAndAdd",(function(){return Ot})),r.d(s,"distance",(function(){return Tt})),r.d(s,"squaredDistance",(function(){return At})),r.d(s,"squaredLength",(function(){return Et})),r.d(s,"negate",(function(){return St})),r.d(s,"inverse",(function(){return jt})),r.d(s,"normalize",(function(){return Pt})),r.d(s,"dot",(function(){return zt})),r.d(s,"cross",(function(){return Ft})),r.d(s,"lerp",(function(){return Ct})),r.d(s,"hermite",(function(){return Lt})),r.d(s,"bezier",(function(){return Bt})),r.d(s,"random",(function(){return Dt})),r.d(s,"transformMat4",(function(){return It})),r.d(s,"transformMat3",(function(){return Ut})),r.d(s,"transformQuat",(function(){return Nt})),r.d(s,"rotateX",(function(){return Gt})),r.d(s,"rotateY",(function(){return kt})),r.d(s,"rotateZ",(function(){return Vt})),r.d(s,"angle",(function(){return Wt})),r.d(s,"zero",(function(){return qt})),r.d(s,"str",(function(){return Ht})),r.d(s,"exactEquals",(function(){return Kt})),r.d(s,"equals",(function(){return Yt})),r.d(s,"sub",(function(){return Zt})),r.d(s,"mul",(function(){return Qt})),r.d(s,"div",(function(){return $t})),r.d(s,"dist",(function(){return Jt})),r.d(s,"sqrDist",(function(){return te})),r.d(s,"len",(function(){return ee})),r.d(s,"sqrLen",(function(){return re})),r.d(s,"forEach",(function(){return ne}));var o={};r.r(o),r.d(o,"create",(function(){return ie})),r.d(o,"clone",(function(){return se})),r.d(o,"fromValues",(function(){return oe})),r.d(o,"copy",(function(){return ae})),r.d(o,"set",(function(){return ue})),r.d(o,"add",(function(){return ce})),r.d(o,"subtract",(function(){return he})),r.d(o,"multiply",(function(){return le})),r.d(o,"divide",(function(){return de})),r.d(o,"ceil",(function(){return fe})),r.d(o,"floor",(function(){return be})),r.d(o,"min",(function(){return me})),r.d(o,"max",(function(){return pe})),r.d(o,"round",(function(){return ve})),r.d(o,"scale",(function(){return ge})),r.d(o,"scaleAndAdd",(function(){return ye})),r.d(o,"distance",(function(){return xe})),r.d(o,"squaredDistance",(function(){return Me})),r.d(o,"length",(function(){return we})),r.d(o,"squaredLength",(function(){return Re})),r.d(o,"negate",(function(){return _e})),r.d(o,"inverse",(function(){return Oe})),r.d(o,"normalize",(function(){return Te})),r.d(o,"dot",(function(){return Ae})),r.d(o,"cross",(function(){return Ee})),r.d(o,"lerp",(function(){return Se})),r.d(o,"random",(function(){return je})),r.d(o,"transformMat4",(function(){return Pe})),r.d(o,"transformQuat",(function(){return ze})),r.d(o,"zero",(function(){return Fe})),r.d(o,"str",(function(){return Ce})),r.d(o,"exactEquals",(function(){return Le})),r.d(o,"equals",(function(){return Be})),r.d(o,"sub",(function(){return De})),r.d(o,"mul",(function(){return Ie})),r.d(o,"div",(function(){return Ue})),r.d(o,"dist",(function(){return Ne})),r.d(o,"sqrDist",(function(){return Ge})),r.d(o,"len",(function(){return ke})),r.d(o,"sqrLen",(function(){return Ve})),r.d(o,"forEach",(function(){return We}));var a={};r.r(a),r.d(a,"create",(function(){return qe})),r.d(a,"identity",(function(){return He})),r.d(a,"setAxisAngle",(function(){return Ke})),r.d(a,"getAxisAngle",(function(){return Ye})),r.d(a,"getAngle",(function(){return Xe})),r.d(a,"multiply",(function(){return Ze})),r.d(a,"rotateX",(function(){return Qe})),r.d(a,"rotateY",(function(){return $e})),r.d(a,"rotateZ",(function(){return Je})),r.d(a,"calculateW",(function(){return tr})),r.d(a,"exp",(function(){return er})),r.d(a,"ln",(function(){return rr})),r.d(a,"pow",(function(){return nr})),r.d(a,"slerp",(function(){return ir})),r.d(a,"random",(function(){return sr})),r.d(a,"invert",(function(){return or})),r.d(a,"conjugate",(function(){return ar})),r.d(a,"fromMat3",(function(){return ur})),r.d(a,"fromEuler",(function(){return cr})),r.d(a,"str",(function(){return hr})),r.d(a,"clone",(function(){return gr})),r.d(a,"fromValues",(function(){return yr})),r.d(a,"copy",(function(){return xr})),r.d(a,"set",(function(){return Mr})),r.d(a,"add",(function(){return wr})),r.d(a,"mul",(function(){return Rr})),r.d(a,"scale",(function(){return _r})),r.d(a,"dot",(function(){return Or})),r.d(a,"lerp",(function(){return Tr})),r.d(a,"length",(function(){return Ar})),r.d(a,"len",(function(){return Er})),r.d(a,"squaredLength",(function(){return Sr})),r.d(a,"sqrLen",(function(){return jr})),r.d(a,"normalize",(function(){return Pr})),r.d(a,"exactEquals",(function(){return zr})),r.d(a,"equals",(function(){return Fr})),r.d(a,"rotationTo",(function(){return Cr})),r.d(a,"sqlerp",(function(){return Lr})),r.d(a,"setAxes",(function(){return Br}));var u={};r.r(u),r.d(u,"create",(function(){return Dr})),r.d(u,"clone",(function(){return Ir})),r.d(u,"fromValues",(function(){return Ur})),r.d(u,"copy",(function(){return Nr})),r.d(u,"set",(function(){return Gr})),r.d(u,"add",(function(){return kr})),r.d(u,"subtract",(function(){return Vr})),r.d(u,"multiply",(function(){return Wr})),r.d(u,"divide",(function(){return qr})),r.d(u,"ceil",(function(){return Hr})),r.d(u,"floor",(function(){return Kr})),r.d(u,"min",(function(){return Yr})),r.d(u,"max",(function(){return Xr})),r.d(u,"round",(function(){return Zr})),r.d(u,"scale",(function(){return Qr})),r.d(u,"scaleAndAdd",(function(){return $r})),r.d(u,"distance",(function(){return Jr})),r.d(u,"squaredDistance",(function(){return tn})),r.d(u,"length",(function(){return en})),r.d(u,"squaredLength",(function(){return rn})),r.d(u,"negate",(function(){return nn})),r.d(u,"inverse",(function(){return sn})),r.d(u,"normalize",(function(){return on})),r.d(u,"dot",(function(){return an})),r.d(u,"cross",(function(){return un})),r.d(u,"lerp",(function(){return cn})),r.d(u,"random",(function(){return hn})),r.d(u,"transformMat2",(function(){return ln})),r.d(u,"transformMat2d",(function(){return dn})),r.d(u,"transformMat3",(function(){return fn})),r.d(u,"transformMat4",(function(){return bn})),r.d(u,"rotate",(function(){return mn})),r.d(u,"angle",(function(){return pn})),r.d(u,"zero",(function(){return vn})),r.d(u,"str",(function(){return gn})),r.d(u,"exactEquals",(function(){return yn})),r.d(u,"equals",(function(){return xn})),r.d(u,"len",(function(){return Mn})),r.d(u,"sub",(function(){return wn})),r.d(u,"mul",(function(){return Rn})),r.d(u,"div",(function(){return _n})),r.d(u,"dist",(function(){return On})),r.d(u,"sqrDist",(function(){return Tn})),r.d(u,"sqrLen",(function(){return An})),r.d(u,"forEach",(function(){return En}));var c=1e-6,h="undefined"!=typeof Float32Array?Float32Array:Array,l=Math.random;function d(t){h=t}var f=Math.PI/180;function b(t){return t*f}function m(t,e){return Math.abs(t-e)<=c*Math.max(1,Math.abs(t),Math.abs(e))}function p(){var t=new h(16);return h!=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 v(t){var e=new h(16);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function g(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,r,n,i,s,o,a,u,c,l,d,f,b,m,p){var v=new h(16);return v[0]=t,v[1]=e,v[2]=r,v[3]=n,v[4]=i,v[5]=s,v[6]=o,v[7]=a,v[8]=u,v[9]=c,v[10]=l,v[11]=d,v[12]=f,v[13]=b,v[14]=m,v[15]=p,v}function x(t,e,r,n,i,s,o,a,u,c,h,l,d,f,b,m,p){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t[4]=s,t[5]=o,t[6]=a,t[7]=u,t[8]=c,t[9]=h,t[10]=l,t[11]=d,t[12]=f,t[13]=b,t[14]=m,t[15]=p,t}function M(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function w(t,e){if(t===e){var r=e[1],n=e[2],i=e[3],s=e[6],o=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=n,t[9]=s,t[11]=e[14],t[12]=i,t[13]=o,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15];return t}function R(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],u=e[6],c=e[7],h=e[8],l=e[9],d=e[10],f=e[11],b=e[12],m=e[13],p=e[14],v=e[15],g=r*a-n*o,y=r*u-i*o,x=r*c-s*o,M=n*u-i*a,w=n*c-s*a,R=i*c-s*u,_=h*m-l*b,O=h*p-d*b,T=h*v-f*b,A=l*p-d*m,E=l*v-f*m,S=d*v-f*p,j=g*S-y*E+x*A+M*T-w*O+R*_;return j?(j=1/j,t[0]=(a*S-u*E+c*A)*j,t[1]=(i*E-n*S-s*A)*j,t[2]=(m*R-p*w+v*M)*j,t[3]=(d*w-l*R-f*M)*j,t[4]=(u*T-o*S-c*O)*j,t[5]=(r*S-i*T+s*O)*j,t[6]=(p*x-b*R-v*y)*j,t[7]=(h*R-d*x+f*y)*j,t[8]=(o*E-a*T+c*_)*j,t[9]=(n*T-r*E-s*_)*j,t[10]=(b*w-m*x+v*g)*j,t[11]=(l*x-h*w-f*g)*j,t[12]=(a*O-o*A-u*_)*j,t[13]=(r*A-n*O+i*_)*j,t[14]=(m*y-b*M-p*g)*j,t[15]=(h*M-l*y+d*g)*j,t):null}function _(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],u=e[6],c=e[7],h=e[8],l=e[9],d=e[10],f=e[11],b=e[12],m=e[13],p=e[14],v=e[15];return t[0]=a*(d*v-f*p)-l*(u*v-c*p)+m*(u*f-c*d),t[1]=-(n*(d*v-f*p)-l*(i*v-s*p)+m*(i*f-s*d)),t[2]=n*(u*v-c*p)-a*(i*v-s*p)+m*(i*c-s*u),t[3]=-(n*(u*f-c*d)-a*(i*f-s*d)+l*(i*c-s*u)),t[4]=-(o*(d*v-f*p)-h*(u*v-c*p)+b*(u*f-c*d)),t[5]=r*(d*v-f*p)-h*(i*v-s*p)+b*(i*f-s*d),t[6]=-(r*(u*v-c*p)-o*(i*v-s*p)+b*(i*c-s*u)),t[7]=r*(u*f-c*d)-o*(i*f-s*d)+h*(i*c-s*u),t[8]=o*(l*v-f*m)-h*(a*v-c*m)+b*(a*f-c*l),t[9]=-(r*(l*v-f*m)-h*(n*v-s*m)+b*(n*f-s*l)),t[10]=r*(a*v-c*m)-o*(n*v-s*m)+b*(n*c-s*a),t[11]=-(r*(a*f-c*l)-o*(n*f-s*l)+h*(n*c-s*a)),t[12]=-(o*(l*p-d*m)-h*(a*p-u*m)+b*(a*d-u*l)),t[13]=r*(l*p-d*m)-h*(n*p-i*m)+b*(n*d-i*l),t[14]=-(r*(a*p-u*m)-o*(n*p-i*m)+b*(n*u-i*a)),t[15]=r*(a*d-u*l)-o*(n*d-i*l)+h*(n*u-i*a),t}function O(t){var e=t[0],r=t[1],n=t[2],i=t[3],s=t[4],o=t[5],a=t[6],u=t[7],c=t[8],h=t[9],l=t[10],d=t[11],f=t[12],b=t[13],m=t[14],p=t[15];return(e*o-r*s)*(l*p-d*m)-(e*a-n*s)*(h*p-d*b)+(e*u-i*s)*(h*m-l*b)+(r*a-n*o)*(c*p-d*f)-(r*u-i*o)*(c*m-l*f)+(n*u-i*a)*(c*b-h*f)}function T(t,e,r){var n=e[0],i=e[1],s=e[2],o=e[3],a=e[4],u=e[5],c=e[6],h=e[7],l=e[8],d=e[9],f=e[10],b=e[11],m=e[12],p=e[13],v=e[14],g=e[15],y=r[0],x=r[1],M=r[2],w=r[3];return t[0]=y*n+x*a+M*l+w*m,t[1]=y*i+x*u+M*d+w*p,t[2]=y*s+x*c+M*f+w*v,t[3]=y*o+x*h+M*b+w*g,y=r[4],x=r[5],M=r[6],w=r[7],t[4]=y*n+x*a+M*l+w*m,t[5]=y*i+x*u+M*d+w*p,t[6]=y*s+x*c+M*f+w*v,t[7]=y*o+x*h+M*b+w*g,y=r[8],x=r[9],M=r[10],w=r[11],t[8]=y*n+x*a+M*l+w*m,t[9]=y*i+x*u+M*d+w*p,t[10]=y*s+x*c+M*f+w*v,t[11]=y*o+x*h+M*b+w*g,y=r[12],x=r[13],M=r[14],w=r[15],t[12]=y*n+x*a+M*l+w*m,t[13]=y*i+x*u+M*d+w*p,t[14]=y*s+x*c+M*f+w*v,t[15]=y*o+x*h+M*b+w*g,t}function A(t,e,r){var n,i,s,o,a,u,c,h,l,d,f,b,m=r[0],p=r[1],v=r[2];return e===t?(t[12]=e[0]*m+e[4]*p+e[8]*v+e[12],t[13]=e[1]*m+e[5]*p+e[9]*v+e[13],t[14]=e[2]*m+e[6]*p+e[10]*v+e[14],t[15]=e[3]*m+e[7]*p+e[11]*v+e[15]):(n=e[0],i=e[1],s=e[2],o=e[3],a=e[4],u=e[5],c=e[6],h=e[7],l=e[8],d=e[9],f=e[10],b=e[11],t[0]=n,t[1]=i,t[2]=s,t[3]=o,t[4]=a,t[5]=u,t[6]=c,t[7]=h,t[8]=l,t[9]=d,t[10]=f,t[11]=b,t[12]=n*m+a*p+l*v+e[12],t[13]=i*m+u*p+d*v+e[13],t[14]=s*m+c*p+f*v+e[14],t[15]=o*m+h*p+b*v+e[15]),t}function E(t,e,r){var n=r[0],i=r[1],s=r[2];return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t[3]=e[3]*n,t[4]=e[4]*i,t[5]=e[5]*i,t[6]=e[6]*i,t[7]=e[7]*i,t[8]=e[8]*s,t[9]=e[9]*s,t[10]=e[10]*s,t[11]=e[11]*s,t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}function S(t,e,r,n){var i,s,o,a,u,h,l,d,f,b,m,p,v,g,y,x,M,w,R,_,O,T,A,E,S=n[0],j=n[1],P=n[2],z=Math.hypot(S,j,P);return z<c?null:(S*=z=1/z,j*=z,P*=z,i=Math.sin(r),o=1-(s=Math.cos(r)),a=e[0],u=e[1],h=e[2],l=e[3],d=e[4],f=e[5],b=e[6],m=e[7],p=e[8],v=e[9],g=e[10],y=e[11],x=S*S*o+s,M=j*S*o+P*i,w=P*S*o-j*i,R=S*j*o-P*i,_=j*j*o+s,O=P*j*o+S*i,T=S*P*o+j*i,A=j*P*o-S*i,E=P*P*o+s,t[0]=a*x+d*M+p*w,t[1]=u*x+f*M+v*w,t[2]=h*x+b*M+g*w,t[3]=l*x+m*M+y*w,t[4]=a*R+d*_+p*O,t[5]=u*R+f*_+v*O,t[6]=h*R+b*_+g*O,t[7]=l*R+m*_+y*O,t[8]=a*T+d*A+p*E,t[9]=u*T+f*A+v*E,t[10]=h*T+b*A+g*E,t[11]=l*T+m*A+y*E,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}function j(t,e,r){var n=Math.sin(r),i=Math.cos(r),s=e[4],o=e[5],a=e[6],u=e[7],c=e[8],h=e[9],l=e[10],d=e[11];return e!==t&&(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[4]=s*i+c*n,t[5]=o*i+h*n,t[6]=a*i+l*n,t[7]=u*i+d*n,t[8]=c*i-s*n,t[9]=h*i-o*n,t[10]=l*i-a*n,t[11]=d*i-u*n,t}function P(t,e,r){var n=Math.sin(r),i=Math.cos(r),s=e[0],o=e[1],a=e[2],u=e[3],c=e[8],h=e[9],l=e[10],d=e[11];return e!==t&&(t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t[0]=s*i-c*n,t[1]=o*i-h*n,t[2]=a*i-l*n,t[3]=u*i-d*n,t[8]=s*n+c*i,t[9]=o*n+h*i,t[10]=a*n+l*i,t[11]=u*n+d*i,t}function z(t,e,r){var n=Math.sin(r),i=Math.cos(r),s=e[0],o=e[1],a=e[2],u=e[3],c=e[4],h=e[5],l=e[6],d=e[7];return e!==t&&(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[0]=s*i+c*n,t[1]=o*i+h*n,t[2]=a*i+l*n,t[3]=u*i+d*n,t[4]=c*i-s*n,t[5]=h*i-o*n,t[6]=l*i-a*n,t[7]=d*i-u*n,t}function F(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}function C(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function L(t,e,r){var n,i,s,o=r[0],a=r[1],u=r[2],h=Math.hypot(o,a,u);return h<c?null:(o*=h=1/h,a*=h,u*=h,n=Math.sin(e),s=1-(i=Math.cos(e)),t[0]=o*o*s+i,t[1]=a*o*s+u*n,t[2]=u*o*s-a*n,t[3]=0,t[4]=o*a*s-u*n,t[5]=a*a*s+i,t[6]=u*a*s+o*n,t[7]=0,t[8]=o*u*s+a*n,t[9]=a*u*s-o*n,t[10]=u*u*s+i,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t)}function B(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=n,t[6]=r,t[7]=0,t[8]=0,t[9]=-r,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function D(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=0,t[2]=-r,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=r,t[9]=0,t[10]=n,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function I(t,e){var r=Math.sin(e),n=Math.cos(e);return t[0]=n,t[1]=r,t[2]=0,t[3]=0,t[4]=-r,t[5]=n,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function U(t,e,r){var n=e[0],i=e[1],s=e[2],o=e[3],a=n+n,u=i+i,c=s+s,h=n*a,l=n*u,d=n*c,f=i*u,b=i*c,m=s*c,p=o*a,v=o*u,g=o*c;return t[0]=1-(f+m),t[1]=l+g,t[2]=d-v,t[3]=0,t[4]=l-g,t[5]=1-(h+m),t[6]=b+p,t[7]=0,t[8]=d+v,t[9]=b-p,t[10]=1-(h+f),t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function N(t,e){var r=new h(3),n=-e[0],i=-e[1],s=-e[2],o=e[3],a=e[4],u=e[5],c=e[6],l=e[7],d=n*n+i*i+s*s+o*o;return d>0?(r[0]=2*(a*o+l*n+u*s-c*i)/d,r[1]=2*(u*o+l*i+c*n-a*s)/d,r[2]=2*(c*o+l*s+a*i-u*n)/d):(r[0]=2*(a*o+l*n+u*s-c*i),r[1]=2*(u*o+l*i+c*n-a*s),r[2]=2*(c*o+l*s+a*i-u*n)),U(t,e,r),t}function G(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}function k(t,e){var r=e[0],n=e[1],i=e[2],s=e[4],o=e[5],a=e[6],u=e[8],c=e[9],h=e[10];return t[0]=Math.hypot(r,n,i),t[1]=Math.hypot(s,o,a),t[2]=Math.hypot(u,c,h),t}function V(t,e){var r=new h(3);k(r,e);var n=1/r[0],i=1/r[1],s=1/r[2],o=e[0]*n,a=e[1]*i,u=e[2]*s,c=e[4]*n,l=e[5]*i,d=e[6]*s,f=e[8]*n,b=e[9]*i,m=e[10]*s,p=o+l+m,v=0;return p>0?(v=2*Math.sqrt(p+1),t[3]=.25*v,t[0]=(d-b)/v,t[1]=(f-u)/v,t[2]=(a-c)/v):o>l&&o>m?(v=2*Math.sqrt(1+o-l-m),t[3]=(d-b)/v,t[0]=.25*v,t[1]=(a+c)/v,t[2]=(f+u)/v):l>m?(v=2*Math.sqrt(1+l-o-m),t[3]=(f-u)/v,t[0]=(a+c)/v,t[1]=.25*v,t[2]=(d+b)/v):(v=2*Math.sqrt(1+m-o-l),t[3]=(a-c)/v,t[0]=(f+u)/v,t[1]=(d+b)/v,t[2]=.25*v),t}function W(t,e,r,n){var i=e[0],s=e[1],o=e[2],a=e[3],u=i+i,c=s+s,h=o+o,l=i*u,d=i*c,f=i*h,b=s*c,m=s*h,p=o*h,v=a*u,g=a*c,y=a*h,x=n[0],M=n[1],w=n[2];return t[0]=(1-(b+p))*x,t[1]=(d+y)*x,t[2]=(f-g)*x,t[3]=0,t[4]=(d-y)*M,t[5]=(1-(l+p))*M,t[6]=(m+v)*M,t[7]=0,t[8]=(f+g)*w,t[9]=(m-v)*w,t[10]=(1-(l+b))*w,t[11]=0,t[12]=r[0],t[13]=r[1],t[14]=r[2],t[15]=1,t}function q(t,e,r,n,i){var s=e[0],o=e[1],a=e[2],u=e[3],c=s+s,h=o+o,l=a+a,d=s*c,f=s*h,b=s*l,m=o*h,p=o*l,v=a*l,g=u*c,y=u*h,x=u*l,M=n[0],w=n[1],R=n[2],_=i[0],O=i[1],T=i[2],A=(1-(m+v))*M,E=(f+x)*M,S=(b-y)*M,j=(f-x)*w,P=(1-(d+v))*w,z=(p+g)*w,F=(b+y)*R,C=(p-g)*R,L=(1-(d+m))*R;return t[0]=A,t[1]=E,t[2]=S,t[3]=0,t[4]=j,t[5]=P,t[6]=z,t[7]=0,t[8]=F,t[9]=C,t[10]=L,t[11]=0,t[12]=r[0]+_-(A*_+j*O+F*T),t[13]=r[1]+O-(E*_+P*O+C*T),t[14]=r[2]+T-(S*_+z*O+L*T),t[15]=1,t}function H(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,u=i+i,c=r*o,h=n*o,l=n*a,d=i*o,f=i*a,b=i*u,m=s*o,p=s*a,v=s*u;return t[0]=1-l-b,t[1]=h+v,t[2]=d-p,t[3]=0,t[4]=h-v,t[5]=1-c-b,t[6]=f+m,t[7]=0,t[8]=d+p,t[9]=f-m,t[10]=1-c-l,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function K(t,e,r,n,i,s,o){var a=1/(r-e),u=1/(i-n),c=1/(s-o);return t[0]=2*s*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2*s*u,t[6]=0,t[7]=0,t[8]=(r+e)*a,t[9]=(i+n)*u,t[10]=(o+s)*c,t[11]=-1,t[12]=0,t[13]=0,t[14]=o*s*2*c,t[15]=0,t}function Y(t,e,r,n,i){var s,o=1/Math.tan(e/2);return t[0]=o/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=o,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,null!=i&&i!==1/0?(s=1/(n-i),t[10]=(i+n)*s,t[14]=2*i*n*s):(t[10]=-1,t[14]=-2*n),t}function X(t,e,r,n){var i=Math.tan(e.upDegrees*Math.PI/180),s=Math.tan(e.downDegrees*Math.PI/180),o=Math.tan(e.leftDegrees*Math.PI/180),a=Math.tan(e.rightDegrees*Math.PI/180),u=2/(o+a),c=2/(i+s);return t[0]=u,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=c,t[6]=0,t[7]=0,t[8]=-(o-a)*u*.5,t[9]=(i-s)*c*.5,t[10]=n/(r-n),t[11]=-1,t[12]=0,t[13]=0,t[14]=n*r/(r-n),t[15]=0,t}function Z(t,e,r,n,i,s,o){var a=1/(e-r),u=1/(n-i),c=1/(s-o);return t[0]=-2*a,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=-2*u,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=2*c,t[11]=0,t[12]=(e+r)*a,t[13]=(i+n)*u,t[14]=(o+s)*c,t[15]=1,t}function Q(t,e,r,n){var i,s,o,a,u,h,l,d,f,b,m=e[0],p=e[1],v=e[2],g=n[0],y=n[1],x=n[2],w=r[0],R=r[1],_=r[2];return Math.abs(m-w)<c&&Math.abs(p-R)<c&&Math.abs(v-_)<c?M(t):(l=m-w,d=p-R,f=v-_,i=y*(f*=b=1/Math.hypot(l,d,f))-x*(d*=b),s=x*(l*=b)-g*f,o=g*d-y*l,(b=Math.hypot(i,s,o))?(i*=b=1/b,s*=b,o*=b):(i=0,s=0,o=0),a=d*o-f*s,u=f*i-l*o,h=l*s-d*i,(b=Math.hypot(a,u,h))?(a*=b=1/b,u*=b,h*=b):(a=0,u=0,h=0),t[0]=i,t[1]=a,t[2]=l,t[3]=0,t[4]=s,t[5]=u,t[6]=d,t[7]=0,t[8]=o,t[9]=h,t[10]=f,t[11]=0,t[12]=-(i*m+s*p+o*v),t[13]=-(a*m+u*p+h*v),t[14]=-(l*m+d*p+f*v),t[15]=1,t)}function $(t,e,r,n){var i=e[0],s=e[1],o=e[2],a=n[0],u=n[1],c=n[2],h=i-r[0],l=s-r[1],d=o-r[2],f=h*h+l*l+d*d;f>0&&(h*=f=1/Math.sqrt(f),l*=f,d*=f);var b=u*d-c*l,m=c*h-a*d,p=a*l-u*h;return(f=b*b+m*m+p*p)>0&&(b*=f=1/Math.sqrt(f),m*=f,p*=f),t[0]=b,t[1]=m,t[2]=p,t[3]=0,t[4]=l*p-d*m,t[5]=d*b-h*p,t[6]=h*m-l*b,t[7]=0,t[8]=h,t[9]=l,t[10]=d,t[11]=0,t[12]=i,t[13]=s,t[14]=o,t[15]=1,t}function J(t){return"mat4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+", "+t[4]+", "+t[5]+", "+t[6]+", "+t[7]+", "+t[8]+", "+t[9]+", "+t[10]+", "+t[11]+", "+t[12]+", "+t[13]+", "+t[14]+", "+t[15]+")"}function tt(t){return Math.hypot(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15])}function et(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t[4]=e[4]+r[4],t[5]=e[5]+r[5],t[6]=e[6]+r[6],t[7]=e[7]+r[7],t[8]=e[8]+r[8],t[9]=e[9]+r[9],t[10]=e[10]+r[10],t[11]=e[11]+r[11],t[12]=e[12]+r[12],t[13]=e[13]+r[13],t[14]=e[14]+r[14],t[15]=e[15]+r[15],t}function rt(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t[4]=e[4]-r[4],t[5]=e[5]-r[5],t[6]=e[6]-r[6],t[7]=e[7]-r[7],t[8]=e[8]-r[8],t[9]=e[9]-r[9],t[10]=e[10]-r[10],t[11]=e[11]-r[11],t[12]=e[12]-r[12],t[13]=e[13]-r[13],t[14]=e[14]-r[14],t[15]=e[15]-r[15],t}function nt(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t[4]=e[4]*r,t[5]=e[5]*r,t[6]=e[6]*r,t[7]=e[7]*r,t[8]=e[8]*r,t[9]=e[9]*r,t[10]=e[10]*r,t[11]=e[11]*r,t[12]=e[12]*r,t[13]=e[13]*r,t[14]=e[14]*r,t[15]=e[15]*r,t}function it(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t[4]=e[4]+r[4]*n,t[5]=e[5]+r[5]*n,t[6]=e[6]+r[6]*n,t[7]=e[7]+r[7]*n,t[8]=e[8]+r[8]*n,t[9]=e[9]+r[9]*n,t[10]=e[10]+r[10]*n,t[11]=e[11]+r[11]*n,t[12]=e[12]+r[12]*n,t[13]=e[13]+r[13]*n,t[14]=e[14]+r[14]*n,t[15]=e[15]+r[15]*n,t}function st(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]}function ot(t,e){var r=t[0],n=t[1],i=t[2],s=t[3],o=t[4],a=t[5],u=t[6],h=t[7],l=t[8],d=t[9],f=t[10],b=t[11],m=t[12],p=t[13],v=t[14],g=t[15],y=e[0],x=e[1],M=e[2],w=e[3],R=e[4],_=e[5],O=e[6],T=e[7],A=e[8],E=e[9],S=e[10],j=e[11],P=e[12],z=e[13],F=e[14],C=e[15];return Math.abs(r-y)<=c*Math.max(1,Math.abs(r),Math.abs(y))&&Math.abs(n-x)<=c*Math.max(1,Math.abs(n),Math.abs(x))&&Math.abs(i-M)<=c*Math.max(1,Math.abs(i),Math.abs(M))&&Math.abs(s-w)<=c*Math.max(1,Math.abs(s),Math.abs(w))&&Math.abs(o-R)<=c*Math.max(1,Math.abs(o),Math.abs(R))&&Math.abs(a-_)<=c*Math.max(1,Math.abs(a),Math.abs(_))&&Math.abs(u-O)<=c*Math.max(1,Math.abs(u),Math.abs(O))&&Math.abs(h-T)<=c*Math.max(1,Math.abs(h),Math.abs(T))&&Math.abs(l-A)<=c*Math.max(1,Math.abs(l),Math.abs(A))&&Math.abs(d-E)<=c*Math.max(1,Math.abs(d),Math.abs(E))&&Math.abs(f-S)<=c*Math.max(1,Math.abs(f),Math.abs(S))&&Math.abs(b-j)<=c*Math.max(1,Math.abs(b),Math.abs(j))&&Math.abs(m-P)<=c*Math.max(1,Math.abs(m),Math.abs(P))&&Math.abs(p-z)<=c*Math.max(1,Math.abs(p),Math.abs(z))&&Math.abs(v-F)<=c*Math.max(1,Math.abs(v),Math.abs(F))&&Math.abs(g-C)<=c*Math.max(1,Math.abs(g),Math.abs(C))}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var at=T,ut=rt;function ct(){var t=new h(3);return h!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function ht(t){var e=new h(3);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function lt(t){var e=t[0],r=t[1],n=t[2];return Math.hypot(e,r,n)}function dt(t,e,r){var n=new h(3);return n[0]=t,n[1]=e,n[2]=r,n}function ft(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function bt(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function mt(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function pt(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function vt(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function gt(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t}function yt(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t}function xt(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t}function Mt(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t}function wt(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t}function Rt(t,e){return t[0]=Math.round(e[0]),t[1]=Math.round(e[1]),t[2]=Math.round(e[2]),t}function _t(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function Ot(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t}function Tt(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return Math.hypot(r,n,i)}function At(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2];return r*r+n*n+i*i}function Et(t){var e=t[0],r=t[1],n=t[2];return e*e+r*r+n*n}function St(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t}function jt(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t}function Pt(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t}function zt(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Ft(t,e,r){var n=e[0],i=e[1],s=e[2],o=r[0],a=r[1],u=r[2];return t[0]=i*u-s*a,t[1]=s*o-n*u,t[2]=n*a-i*o,t}function Ct(t,e,r,n){var i=e[0],s=e[1],o=e[2];return t[0]=i+n*(r[0]-i),t[1]=s+n*(r[1]-s),t[2]=o+n*(r[2]-o),t}function Lt(t,e,r,n,i,s){var o=s*s,a=o*(2*s-3)+1,u=o*(s-2)+s,c=o*(s-1),h=o*(3-2*s);return t[0]=e[0]*a+r[0]*u+n[0]*c+i[0]*h,t[1]=e[1]*a+r[1]*u+n[1]*c+i[1]*h,t[2]=e[2]*a+r[2]*u+n[2]*c+i[2]*h,t}function Bt(t,e,r,n,i,s){var o=1-s,a=o*o,u=s*s,c=a*o,h=3*s*a,l=3*u*o,d=u*s;return t[0]=e[0]*c+r[0]*h+n[0]*l+i[0]*d,t[1]=e[1]*c+r[1]*h+n[1]*l+i[1]*d,t[2]=e[2]*c+r[2]*h+n[2]*l+i[2]*d,t}function Dt(t,e){e=e||1;var r=2*l()*Math.PI,n=2*l()-1,i=Math.sqrt(1-n*n)*e;return t[0]=Math.cos(r)*i,t[1]=Math.sin(r)*i,t[2]=n*e,t}function It(t,e,r){var n=e[0],i=e[1],s=e[2],o=r[3]*n+r[7]*i+r[11]*s+r[15];return o=o||1,t[0]=(r[0]*n+r[4]*i+r[8]*s+r[12])/o,t[1]=(r[1]*n+r[5]*i+r[9]*s+r[13])/o,t[2]=(r[2]*n+r[6]*i+r[10]*s+r[14])/o,t}function Ut(t,e,r){var n=e[0],i=e[1],s=e[2];return t[0]=n*r[0]+i*r[3]+s*r[6],t[1]=n*r[1]+i*r[4]+s*r[7],t[2]=n*r[2]+i*r[5]+s*r[8],t}function Nt(t,e,r){var n=r[0],i=r[1],s=r[2],o=r[3],a=e[0],u=e[1],c=e[2],h=i*c-s*u,l=s*a-n*c,d=n*u-i*a,f=i*d-s*l,b=s*h-n*d,m=n*l-i*h,p=2*o;return h*=p,l*=p,d*=p,f*=2,b*=2,m*=2,t[0]=a+h+f,t[1]=u+l+b,t[2]=c+d+m,t}function Gt(t,e,r,n){var i=[],s=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],s[0]=i[0],s[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),s[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),t[0]=s[0]+r[0],t[1]=s[1]+r[1],t[2]=s[2]+r[2],t}function kt(t,e,r,n){var i=[],s=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],s[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),s[1]=i[1],s[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),t[0]=s[0]+r[0],t[1]=s[1]+r[1],t[2]=s[2]+r[2],t}function Vt(t,e,r,n){var i=[],s=[];return i[0]=e[0]-r[0],i[1]=e[1]-r[1],i[2]=e[2]-r[2],s[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),s[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),s[2]=i[2],t[0]=s[0]+r[0],t[1]=s[1]+r[1],t[2]=s[2]+r[2],t}function Wt(t,e){var r=t[0],n=t[1],i=t[2],s=e[0],o=e[1],a=e[2],u=Math.sqrt(r*r+n*n+i*i)*Math.sqrt(s*s+o*o+a*a),c=u&&zt(t,e)/u;return Math.acos(Math.min(Math.max(c,-1),1))}function qt(t){return t[0]=0,t[1]=0,t[2]=0,t}function Ht(t){return"vec3("+t[0]+", "+t[1]+", "+t[2]+")"}function Kt(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]}function Yt(t,e){var r=t[0],n=t[1],i=t[2],s=e[0],o=e[1],a=e[2];return Math.abs(r-s)<=c*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(n-o)<=c*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=c*Math.max(1,Math.abs(i),Math.abs(a))}var Xt,Zt=pt,Qt=vt,$t=gt,Jt=Tt,te=At,ee=lt,re=Et,ne=(Xt=ct(),function(t,e,r,n,i,s){var o,a;for(e||(e=3),r||(r=0),a=n?Math.min(n*e+r,t.length):t.length,o=r;o<a;o+=e)Xt[0]=t[o],Xt[1]=t[o+1],Xt[2]=t[o+2],i(Xt,Xt,s),t[o]=Xt[0],t[o+1]=Xt[1],t[o+2]=Xt[2];return t});function ie(){var t=new h(4);return h!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t}function se(t){var e=new h(4);return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function oe(t,e,r,n){var i=new h(4);return i[0]=t,i[1]=e,i[2]=r,i[3]=n,i}function ae(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function ue(t,e,r,n,i){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t}function ce(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t[3]=e[3]+r[3],t}function he(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t[3]=e[3]-r[3],t}function le(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t[3]=e[3]*r[3],t}function de(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t[2]=e[2]/r[2],t[3]=e[3]/r[3],t}function fe(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t[2]=Math.ceil(e[2]),t[3]=Math.ceil(e[3]),t}function be(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t[2]=Math.floor(e[2]),t[3]=Math.floor(e[3]),t}function me(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t[2]=Math.min(e[2],r[2]),t[3]=Math.min(e[3],r[3]),t}function pe(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t[2]=Math.max(e[2],r[2]),t[3]=Math.max(e[3],r[3]),t}function ve(t,e){return t[0]=Math.round(e[0]),t[1]=Math.round(e[1]),t[2]=Math.round(e[2]),t[3]=Math.round(e[3]),t}function ge(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r,t}function ye(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t[2]=e[2]+r[2]*n,t[3]=e[3]+r[3]*n,t}function xe(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],s=e[3]-t[3];return Math.hypot(r,n,i,s)}function Me(t,e){var r=e[0]-t[0],n=e[1]-t[1],i=e[2]-t[2],s=e[3]-t[3];return r*r+n*n+i*i+s*s}function we(t){var e=t[0],r=t[1],n=t[2],i=t[3];return Math.hypot(e,r,n,i)}function Re(t){var e=t[0],r=t[1],n=t[2],i=t[3];return e*e+r*r+n*n+i*i}function _e(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=-e[3],t}function Oe(t,e){return t[0]=1/e[0],t[1]=1/e[1],t[2]=1/e[2],t[3]=1/e[3],t}function Te(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r*r+n*n+i*i+s*s;return o>0&&(o=1/Math.sqrt(o)),t[0]=r*o,t[1]=n*o,t[2]=i*o,t[3]=s*o,t}function Ae(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}function Ee(t,e,r,n){var i=r[0]*n[1]-r[1]*n[0],s=r[0]*n[2]-r[2]*n[0],o=r[0]*n[3]-r[3]*n[0],a=r[1]*n[2]-r[2]*n[1],u=r[1]*n[3]-r[3]*n[1],c=r[2]*n[3]-r[3]*n[2],h=e[0],l=e[1],d=e[2],f=e[3];return t[0]=l*c-d*u+f*a,t[1]=-h*c+d*o-f*s,t[2]=h*u-l*o+f*i,t[3]=-h*a+l*s-d*i,t}function Se(t,e,r,n){var i=e[0],s=e[1],o=e[2],a=e[3];return t[0]=i+n*(r[0]-i),t[1]=s+n*(r[1]-s),t[2]=o+n*(r[2]-o),t[3]=a+n*(r[3]-a),t}function je(t,e){var r,n,i,s,o,a;e=e||1;do{o=(r=2*l()-1)*r+(n=2*l()-1)*n}while(o>=1);do{a=(i=2*l()-1)*i+(s=2*l()-1)*s}while(a>=1);var u=Math.sqrt((1-o)/a);return t[0]=e*r,t[1]=e*n,t[2]=e*i*u,t[3]=e*s*u,t}function Pe(t,e,r){var n=e[0],i=e[1],s=e[2],o=e[3];return t[0]=r[0]*n+r[4]*i+r[8]*s+r[12]*o,t[1]=r[1]*n+r[5]*i+r[9]*s+r[13]*o,t[2]=r[2]*n+r[6]*i+r[10]*s+r[14]*o,t[3]=r[3]*n+r[7]*i+r[11]*s+r[15]*o,t}function ze(t,e,r){var n=e[0],i=e[1],s=e[2],o=r[0],a=r[1],u=r[2],c=r[3],h=c*n+a*s-u*i,l=c*i+u*n-o*s,d=c*s+o*i-a*n,f=-o*n-a*i-u*s;return t[0]=h*c+f*-o+l*-u-d*-a,t[1]=l*c+f*-a+d*-o-h*-u,t[2]=d*c+f*-u+h*-a-l*-o,t[3]=e[3],t}function Fe(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=0,t}function Ce(t){return"vec4("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"}function Le(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]}function Be(t,e){var r=t[0],n=t[1],i=t[2],s=t[3],o=e[0],a=e[1],u=e[2],h=e[3];return Math.abs(r-o)<=c*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(n-a)<=c*Math.max(1,Math.abs(n),Math.abs(a))&&Math.abs(i-u)<=c*Math.max(1,Math.abs(i),Math.abs(u))&&Math.abs(s-h)<=c*Math.max(1,Math.abs(s),Math.abs(h))}var De=he,Ie=le,Ue=de,Ne=xe,Ge=Me,ke=we,Ve=Re,We=function(){var t=ie();return function(e,r,n,i,s,o){var a,u;for(r||(r=4),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,a=n;a<u;a+=r)t[0]=e[a],t[1]=e[a+1],t[2]=e[a+2],t[3]=e[a+3],s(t,t,o),e[a]=t[0],e[a+1]=t[1],e[a+2]=t[2],e[a+3]=t[3];return e}}();function qe(){var t=new h(4);return h!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function He(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function Ke(t,e,r){r*=.5;var n=Math.sin(r);return t[0]=n*e[0],t[1]=n*e[1],t[2]=n*e[2],t[3]=Math.cos(r),t}function Ye(t,e){var r=2*Math.acos(e[3]),n=Math.sin(r/2);return n>c?(t[0]=e[0]/n,t[1]=e[1]/n,t[2]=e[2]/n):(t[0]=1,t[1]=0,t[2]=0),r}function Xe(t,e){var r=Or(t,e);return Math.acos(2*r*r-1)}function Ze(t,e,r){var n=e[0],i=e[1],s=e[2],o=e[3],a=r[0],u=r[1],c=r[2],h=r[3];return t[0]=n*h+o*a+i*c-s*u,t[1]=i*h+o*u+s*a-n*c,t[2]=s*h+o*c+n*u-i*a,t[3]=o*h-n*a-i*u-s*c,t}function Qe(t,e,r){r*=.5;var n=e[0],i=e[1],s=e[2],o=e[3],a=Math.sin(r),u=Math.cos(r);return t[0]=n*u+o*a,t[1]=i*u+s*a,t[2]=s*u-i*a,t[3]=o*u-n*a,t}function $e(t,e,r){r*=.5;var n=e[0],i=e[1],s=e[2],o=e[3],a=Math.sin(r),u=Math.cos(r);return t[0]=n*u-s*a,t[1]=i*u+o*a,t[2]=s*u+n*a,t[3]=o*u-i*a,t}function Je(t,e,r){r*=.5;var n=e[0],i=e[1],s=e[2],o=e[3],a=Math.sin(r),u=Math.cos(r);return t[0]=n*u+i*a,t[1]=i*u-n*a,t[2]=s*u+o*a,t[3]=o*u-s*a,t}function tr(t,e){var r=e[0],n=e[1],i=e[2];return t[0]=r,t[1]=n,t[2]=i,t[3]=Math.sqrt(Math.abs(1-r*r-n*n-i*i)),t}function er(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=Math.sqrt(r*r+n*n+i*i),a=Math.exp(s),u=o>0?a*Math.sin(o)/o:0;return t[0]=r*u,t[1]=n*u,t[2]=i*u,t[3]=a*Math.cos(o),t}function rr(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=Math.sqrt(r*r+n*n+i*i),a=o>0?Math.atan2(o,s)/o:0;return t[0]=r*a,t[1]=n*a,t[2]=i*a,t[3]=.5*Math.log(r*r+n*n+i*i+s*s),t}function nr(t,e,r){return rr(t,e),_r(t,t,r),er(t,t),t}function ir(t,e,r,n){var i,s,o,a,u,h=e[0],l=e[1],d=e[2],f=e[3],b=r[0],m=r[1],p=r[2],v=r[3];return(s=h*b+l*m+d*p+f*v)<0&&(s=-s,b=-b,m=-m,p=-p,v=-v),1-s>c?(i=Math.acos(s),o=Math.sin(i),a=Math.sin((1-n)*i)/o,u=Math.sin(n*i)/o):(a=1-n,u=n),t[0]=a*h+u*b,t[1]=a*l+u*m,t[2]=a*d+u*p,t[3]=a*f+u*v,t}function sr(t){var e=l(),r=l(),n=l(),i=Math.sqrt(1-e),s=Math.sqrt(e);return t[0]=i*Math.sin(2*Math.PI*r),t[1]=i*Math.cos(2*Math.PI*r),t[2]=s*Math.sin(2*Math.PI*n),t[3]=s*Math.cos(2*Math.PI*n),t}function or(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r*r+n*n+i*i+s*s,a=o?1/o:0;return t[0]=-r*a,t[1]=-n*a,t[2]=-i*a,t[3]=s*a,t}function ar(t,e){return t[0]=-e[0],t[1]=-e[1],t[2]=-e[2],t[3]=e[3],t}function ur(t,e){var r,n=e[0]+e[4]+e[8];if(n>0)r=Math.sqrt(n+1),t[3]=.5*r,r=.5/r,t[0]=(e[5]-e[7])*r,t[1]=(e[6]-e[2])*r,t[2]=(e[1]-e[3])*r;else{var i=0;e[4]>e[0]&&(i=1),e[8]>e[3*i+i]&&(i=2);var s=(i+1)%3,o=(i+2)%3;r=Math.sqrt(e[3*i+i]-e[3*s+s]-e[3*o+o]+1),t[i]=.5*r,r=.5/r,t[3]=(e[3*s+o]-e[3*o+s])*r,t[s]=(e[3*s+i]+e[3*i+s])*r,t[o]=(e[3*o+i]+e[3*i+o])*r}return t}function cr(t,e,r,n){var i=.5*Math.PI/180;e*=i,r*=i,n*=i;var s=Math.sin(e),o=Math.cos(e),a=Math.sin(r),u=Math.cos(r),c=Math.sin(n),h=Math.cos(n);return t[0]=s*u*h-o*a*c,t[1]=o*a*h+s*u*c,t[2]=o*u*c-s*a*h,t[3]=o*u*h+s*a*c,t}function hr(t){return"quat("+t[0]+", "+t[1]+", "+t[2]+", "+t[3]+")"}var lr,dr,fr,br,mr,pr,vr,gr=se,yr=oe,xr=ae,Mr=ue,wr=ce,Rr=Ze,_r=ge,Or=Ae,Tr=Se,Ar=we,Er=Ar,Sr=Re,jr=Sr,Pr=Te,zr=Le,Fr=Be,Cr=(lr=ct(),dr=dt(1,0,0),fr=dt(0,1,0),function(t,e,r){var n=zt(e,r);return n<-.999999?(Ft(lr,dr,e),ee(lr)<1e-6&&Ft(lr,fr,e),Pt(lr,lr),Ke(t,lr,Math.PI),t):n>.999999?(t[0]=0,t[1]=0,t[2]=0,t[3]=1,t):(Ft(lr,e,r),t[0]=lr[0],t[1]=lr[1],t[2]=lr[2],t[3]=1+n,Pr(t,t))}),Lr=(br=qe(),mr=qe(),function(t,e,r,n,i,s){return ir(br,e,i,s),ir(mr,r,n,s),ir(t,br,mr,2*s*(1-s)),t}),Br=(pr=new h(9),h!=Float32Array&&(pr[1]=0,pr[2]=0,pr[3]=0,pr[5]=0,pr[6]=0,pr[7]=0),pr[0]=1,pr[4]=1,pr[8]=1,vr=pr,function(t,e,r,n){return vr[0]=r[0],vr[3]=r[1],vr[6]=r[2],vr[1]=n[0],vr[4]=n[1],vr[7]=n[2],vr[2]=-e[0],vr[5]=-e[1],vr[8]=-e[2],Pr(t,ur(t,vr))});function Dr(){var t=new h(2);return h!=Float32Array&&(t[0]=0,t[1]=0),t}function Ir(t){var e=new h(2);return e[0]=t[0],e[1]=t[1],e}function Ur(t,e){var r=new h(2);return r[0]=t,r[1]=e,r}function Nr(t,e){return t[0]=e[0],t[1]=e[1],t}function Gr(t,e,r){return t[0]=e,t[1]=r,t}function kr(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t}function Vr(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t}function Wr(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t}function qr(t,e,r){return t[0]=e[0]/r[0],t[1]=e[1]/r[1],t}function Hr(t,e){return t[0]=Math.ceil(e[0]),t[1]=Math.ceil(e[1]),t}function Kr(t,e){return t[0]=Math.floor(e[0]),t[1]=Math.floor(e[1]),t}function Yr(t,e,r){return t[0]=Math.min(e[0],r[0]),t[1]=Math.min(e[1],r[1]),t}function Xr(t,e,r){return t[0]=Math.max(e[0],r[0]),t[1]=Math.max(e[1],r[1]),t}function Zr(t,e){return t[0]=Math.round(e[0]),t[1]=Math.round(e[1]),t}function Qr(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t}function $r(t,e,r,n){return t[0]=e[0]+r[0]*n,t[1]=e[1]+r[1]*n,t}function Jr(t,e){var r=e[0]-t[0],n=e[1]-t[1];return Math.hypot(r,n)}function tn(t,e){var r=e[0]-t[0],n=e[1]-t[1];return r*r+n*n}function en(t){var e=t[0],r=t[1];return Math.hypot(e,r)}function rn(t){var e=t[0],r=t[1];return e*e+r*r}function nn(t,e){return t[0]=-e[0],t[1]=-e[1],t}function sn(t,e){return t[0]=1/e[0],t[1]=1/e[1],t}function on(t,e){var r=e[0],n=e[1],i=r*r+n*n;return i>0&&(i=1/Math.sqrt(i)),t[0]=e[0]*i,t[1]=e[1]*i,t}function an(t,e){return t[0]*e[0]+t[1]*e[1]}function un(t,e,r){var n=e[0]*r[1]-e[1]*r[0];return t[0]=t[1]=0,t[2]=n,t}function cn(t,e,r,n){var i=e[0],s=e[1];return t[0]=i+n*(r[0]-i),t[1]=s+n*(r[1]-s),t}function hn(t,e){e=e||1;var r=2*l()*Math.PI;return t[0]=Math.cos(r)*e,t[1]=Math.sin(r)*e,t}function ln(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[2]*i,t[1]=r[1]*n+r[3]*i,t}function dn(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[2]*i+r[4],t[1]=r[1]*n+r[3]*i+r[5],t}function fn(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[3]*i+r[6],t[1]=r[1]*n+r[4]*i+r[7],t}function bn(t,e,r){var n=e[0],i=e[1];return t[0]=r[0]*n+r[4]*i+r[12],t[1]=r[1]*n+r[5]*i+r[13],t}function mn(t,e,r,n){var i=e[0]-r[0],s=e[1]-r[1],o=Math.sin(n),a=Math.cos(n);return t[0]=i*a-s*o+r[0],t[1]=i*o+s*a+r[1],t}function pn(t,e){var r=t[0],n=t[1],i=e[0],s=e[1],o=Math.sqrt(r*r+n*n)*Math.sqrt(i*i+s*s),a=o&&(r*i+n*s)/o;return Math.acos(Math.min(Math.max(a,-1),1))}function vn(t){return t[0]=0,t[1]=0,t}function gn(t){return"vec2("+t[0]+", "+t[1]+")"}function yn(t,e){return t[0]===e[0]&&t[1]===e[1]}function xn(t,e){var r=t[0],n=t[1],i=e[0],s=e[1];return Math.abs(r-i)<=c*Math.max(1,Math.abs(r),Math.abs(i))&&Math.abs(n-s)<=c*Math.max(1,Math.abs(n),Math.abs(s))}var Mn=en,wn=Vr,Rn=Wr,_n=qr,On=Jr,Tn=tn,An=rn,En=function(){var t=Dr();return function(e,r,n,i,s,o){var a,u;for(r||(r=2),n||(n=0),u=i?Math.min(i*r+n,e.length):e.length,a=n;a<u;a+=r)t[0]=e[a],t[1]=e[a+1],s(t,t,o),e[a]=t[0],e[a+1]=t[1];return e}}()},function(t,e,r){"use strict";r.r(e),r.d(e,"Vector2",(function(){return i.h})),r.d(e,"vec2",(function(){return i.y})),r.d(e,"Vector3",(function(){return i.i})),r.d(e,"vec3",(function(){return i.z})),r.d(e,"Vector4",(function(){return i.j})),r.d(e,"vec4",(function(){return i.A})),r.d(e,"Color",(function(){return i.a})),r.d(e,"rgba",(function(){return i.x})),r.d(e,"rgb",(function(){return i.w})),r.d(e,"hsl",(function(){return i.p})),r.d(e,"plus",(function(){return i.t})),r.d(e,"minus",(function(){return i.r})),r.d(e,"mul",(function(){return i.s})),r.d(e,"div",(function(){return i.n})),r.d(e,"dot",(function(){return i.o})),r.d(e,"cross",(function(){return i.l})),r.d(e,"distance",(function(){return i.m})),r.d(e,"boxRaycast",(function(){return i.k})),r.d(e,"Deg2Rad",(function(){return i.b})),r.d(e,"Rad2Deg",(function(){return i.f})),r.d(e,"Matrix4x4",(function(){return i.d})),r.d(e,"mat4",(function(){return i.q})),r.d(e,"Quaternion",(function(){return i.e})),r.d(e,"quat",(function(){return i.u})),r.d(e,"ray",(function(){return i.v})),r.d(e,"Rect",(function(){return i.g})),r.d(e,"MathUtils",(function(){return i.c})),r.d(e,"Material",(function(){return s.u})),r.d(e,"shaderProp",(function(){return s.K})),r.d(e,"MaterialFromShader",(function(){return s.v})),r.d(e,"SimpleTexturedMaterial",(function(){return s.B})),r.d(e,"materialDefine",(function(){return s.J})),r.d(e,"DefaultVertexData",(function(){return s.h})),r.d(e,"DefaultVertexStructInfo",(function(){return s.i})),r.d(e,"VertexStruct",(function(){return s.G})),r.d(e,"Mesh",(function(){return s.w})),r.d(e,"MeshLegacy",(function(){return s.x})),r.d(e,"ZograRenderer",(function(){return s.I})),r.d(e,"DepthTest",(function(){return s.k})),r.d(e,"Blending",(function(){return s.c})),r.d(e,"Culling",(function(){return s.e})),r.d(e,"DefaultShaderAttributeNames",(function(){return s.g})),r.d(e,"Shader",(function(){return s.A})),r.d(e,"FilterMode",(function(){return s.n})),r.d(e,"WrapMode",(function(){return s.H})),r.d(e,"Texture",(function(){return s.C})),r.d(e,"TextureResizing",(function(){return s.F})),r.d(e,"Texture2D",(function(){return s.D})),r.d(e,"DepthTexture",(function(){return s.l})),r.d(e,"RenderTexture",(function(){return s.z})),r.d(e,"Asset",(function(){return s.a})),r.d(e,"GPUAsset",(function(){return s.q})),r.d(e,"LazyInitAsset",(function(){return s.r})),r.d(e,"AssetManager",(function(){return s.b})),r.d(e,"Lines",(function(){return s.t})),r.d(e,"LineBuilder",(function(){return s.s})),r.d(e,"EventEmitter",(function(){return s.m})),r.d(e,"BufferStructureInfo",(function(){return s.d})),r.d(e,"GLArrayBuffer",(function(){return s.p})),r.d(e,"RenderBuffer",(function(){return s.y})),r.d(e,"DepthBuffer",(function(){return s.j})),r.d(e,"FrameBuffer",(function(){return s.o})),r.d(e,"DebugProvider",(function(){return s.f})),r.d(e,"TextureFormat",(function(){return s.E})),r.d(e,"AssetsPack",(function(){return o.b})),r.d(e,"AssetsImporter",(function(){return o.a})),r.d(e,"TextureImporter",(function(){return a.a})),r.d(e,"MeshBuilder",(function(){return u.a})),r.d(e,"MeshBuilderLegacy",(function(){return u.b})),r.d(e,"Utils",(function(){return n})),r.d(e,"GLContext",(function(){return h.c})),r.d(e,"GlobalContext",(function(){return h.d}));var n={};r.r(n),r.d(n,"ImageSizing",(function(){return c.a})),r.d(n,"imageResize",(function(){return c.b}));var i=r(55),s=r(63),o=r(51),a=r(73),u=r(24),c=r(41),h=r(3)},function(t,e,r){"use strict";r.d(e,"j",(function(){return u})),r.d(e,"h",(function(){return c})),r.d(e,"i",(function(){return h})),r.d(e,"f",(function(){return l})),r.d(e,"g",(function(){return d})),r.d(e,"d",(function(){return f})),r.d(e,"e",(function(){return b})),r.d(e,"c",(function(){return m})),r.d(e,"a",(function(){return p})),r.d(e,"b",(function(){return v}));var n=r(1),i=r(13),s=r(0),o=r(9);function a(t,e){let r=Math.max(t.length||0,e.length||0);switch(r){case 2:return"number"==typeof t?s.b.fill(t):s.b.set(t);case 3:return"number"==typeof t?s.b.fill(t):n.b.set(t);case 4:return"number"==typeof t?s.b.fill(t):i.b.set(t);case 16:return"number"==typeof t?s.b.fill(t):o.b.set(t)}return console.warn(`Unsupported vector length '${r}'`),new Array}function u(t,e,r){if("number"==typeof t&&"number"==typeof e)return t+e;let o=r||a(t,e);switch(o.length){case 2:return s.b.plus(o,o,e);case 3:return n.b.plus(o,o,e);case 4:return i.b.plus(o,o,e)}return console.warn(`Unsupported vector length '${o.length}'`),i.b.plus(o,o,e)}function c(t,e,r){if("number"==typeof t&&"number"==typeof e)return t+e;let o=r||a(t,e);switch(o.length){case 2:return s.b.minus(o,o,e);case 3:return n.b.minus(o,o,e);case 4:return i.b.minus(o,o,e)}return console.warn(`Unsupported vector length '${o.length}'`),i.b.minus(o,o,e)}function h(t,e,r){if("number"==typeof t&&"number"==typeof e)return t+e;let o=r||a(t,e);switch(o.length){case 2:return s.b.mul(o,o,e);case 3:return n.b.mul(o,o,e);case 4:return i.b.mul(o,o,e)}return console.warn(`Unsupported vector length '${o.length}'`),i.b.mul(o,o,e)}function l(t,e,r){if("number"==typeof t&&"number"==typeof e)return t+e;let o=r||a(t,e);switch(o.length){case 2:return s.b.div(o,o,e);case 3:return n.b.div(o,o,e);case 4:return i.b.div(o,o,e)}return console.warn(`Unsupported vector length '${o.length}'`),i.b.div(o,o,e)}function d(t,e){switch(t.length){case 2:return t[0]*e[0]+t[1]*e[1];case 3:return t[0]*e[0]+t[1]*e[1]+t[2]*e[2];case 4:return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3]}}function f(t,e,r=n.b.zero()){return r[0]=t[1]*e[2]-t[2]*e[1],r[1]=t[2]*e[0]-t[0]*e[2],r[2]=t[0]*e[1]-t[1]*e[0],r}function b(t,e){return Math.hypot(e[0]-t[0]||0,e[1]-t[1]||0,e[2]-t[2]||0,e[3]-t[3]||0)}function m(t,e,r){if(0==(r=r.normalized).x&&0==r.y)return[!1,0,s.b.zero()];let n=s.b.zero(),i=s.b.zero();if(0==r.x)return n.y=(t.yMin-e.y)/r.y,i.y=(t.yMax-e.y)/r.y,n.x=i.x=Number.NEGATIVE_INFINITY,t.xMin<=e.x&&e.x<=t.xMax?n.y<i.y?[!0,n.y,Object(s.b)(0,-1)]:[!0,i.y,Object(s.b)(0,1)]:[!1,0,s.b.zero()];if(0==r.y)return n.x=(t.xMin-e.x)/r.x,i.x=(t.xMax-e.x)/r.x,n.y=i.y=Number.NEGATIVE_INFINITY,t.yMin<=e.y&&e.y<=t.yMax?n.x<i.x?[!0,n.x,Object(s.b)(-1,0)]:[!0,i.x,Object(s.b)(1,0)]:[!1,0,s.b.zero()];n=c(t.min,e).div(r),i=c(t.max,e).div(r);var o=n.x,a=i.x,u=Object(s.b)(-1,0),h=n.y,l=i.y,d=Object(s.b)(0,-1);return n.x>i.x&&(o=i.x,a=n.x,u=Object(s.b)(1,0)),n.y>i.y&&(h=i.y,l=n.y,d=Object(s.b)(0,1)),h>a||o>l?[!1,0,s.b.zero()]:o>h?[!0,o,u]:[!0,h,d]}Number.prototype.__to=function(t){switch(t){case i.a:return Object(i.b)(this.valueOf(),this.valueOf(),this.valueOf(),this.valueOf());case n.a:return Object(n.b)(this.valueOf(),this.valueOf(),this.valueOf());case s.a:return Object(s.b)(this.valueOf(),this.valueOf())}return this.valueOf()};const p=Math.PI/180,v=180/Math.PI},function(t,e,r){"use strict";r.d(e,"d",(function(){return n})),r.d(e,"a",(function(){return i})),r.d(e,"b",(function(){return s})),r.d(e,"c",(function(){return d})),r.d(e,"e",(function(){return f}));var n,i,s,o=r(10),a=r(3),u=r(18),c=r(15),h=r(23),l=r(16);!function(t){t[t.Disable=-1]="Disable",t[t.Always=WebGL2RenderingContext.ALWAYS]="Always",t[t.Never=WebGL2RenderingContext.NEVER]="Never",t[t.Less=WebGL2RenderingContext.LESS]="Less",t[t.Equal=WebGL2RenderingContext.EQUAL]="Equal",t[t.LEqual=WebGL2RenderingContext.LEQUAL]="LEqual",t[t.Greater=WebGL2RenderingContext.GREATER]="Greater",t[t.NotEqual=WebGL2RenderingContext.NOTEQUAL]="NotEqual",t[t.GEqual=WebGL2RenderingContext.GEQUAL]="GEqual"}(n||(n={})),function(t){t[t.Disable=-1]="Disable",t[t.Zero=WebGL2RenderingContext.ZERO]="Zero",t[t.One=WebGL2RenderingContext.ONE]="One",t[t.SrcColor=WebGL2RenderingContext.SRC_COLOR]="SrcColor",t[t.OneMinusSrcColor=WebGL2RenderingContext.ONE_MINUS_SRC_COLOR]="OneMinusSrcColor",t[t.DstColor=WebGL2RenderingContext.DST_COLOR]="DstColor",t[t.OneMinusDstColor=WebGL2RenderingContext.ONE_MINUS_DST_COLOR]="OneMinusDstColor",t[t.SrcAlpha=WebGL2RenderingContext.SRC_ALPHA]="SrcAlpha",t[t.OneMinusSrcAlpha=WebGL2RenderingContext.ONE_MINUS_SRC_ALPHA]="OneMinusSrcAlpha",t[t.DstAlpha=WebGL2RenderingContext.DST_ALPHA]="DstAlpha",t[t.OneMinusDstAlpha=WebGL2RenderingContext.ONE_MINUS_DST_ALPHA]="OneMinusDstAlpha"}(i||(i={})),function(t){t[t.Disable=-1]="Disable",t[t.Back=WebGL2RenderingContext.BACK]="Back",t[t.Front=WebGL2RenderingContext.FRONT]="Front",t[t.Both=WebGL2RenderingContext.FRONT_AND_BACK]="Both"}(s||(s={}));const d={vert:"aPos",color:"aColor",uv:"aUV",uv2:"aUV2",normal:"aNormal"};class f extends c.a{constructor(t,e,r={},n=Object(a.b)()){super(r.name),this.attributes={},this.initialized=!1,this.gl=null,this.program=null,this.vertexShader=null,this.fragmentShader=null,this.pipelineStates={},this.builtinUniformLocations=null,this._compiled=!1,r.name||(this.name="Shader_"+this.assetID),this.vertexShaderSource=t,this.fragmentShaderSouce=e,this.options=r,this.gl=n,this.vertexStruct=h.a.from(this.options.vertexStructure||l.a),this.attributeNames=Object.assign(Object.assign({},d),r.attributes),this.setPipelineStateInternal(this.options),this.tryInit()}get compiled(){return this._compiled}uniformLocation(t){return this.tryInit(!0),this.gl.getUniformLocation(this.program,t)}use(){this.tryInit(!0),this.gl.useProgram(this.program)}setupBuiltinUniform(t){this.tryInit(!0);const e=this.gl;this.builtinUniformLocations.matM&&e.uniformMatrix4fv(this.builtinUniformLocations.matM,!1,t.matM.asMut()),this.builtinUniformLocations.matVP&&e.uniformMatrix4fv(this.builtinUniformLocations.matVP,!1,t.matVP.asMut()),this.builtinUniformLocations.matMVP&&e.uniformMatrix4fv(this.builtinUniformLocations.matMVP,!1,t.matMVP.asMut()),this.builtinUniformLocations.matM_IT&&e.uniformMatrix4fv(this.builtinUniformLocations.matM_IT,!1,t.matM_IT.asMut()),this.builtinUniformLocations.matMV_IT&&e.uniformMatrix4fv(this.builtinUniformLocations.matMV_IT,!1,t.matMV_IT.asMut())}setPipelineStateInternal(t){let e=!1,r=[i.One,i.Zero],o=[i.One,i.OneMinusSrcAlpha];"number"==typeof t.blend&&t.blend!==i.Disable?(e=!0,r=[t.blend,t.blend],o=[t.blend,t.blend]):t.blend instanceof Array&&(e=!0,r=t.blend),t.blendRGB&&(e=!1!==t.blend&&t.blend!==i.Disable,r=t.blendRGB),t.blendAlpha&&(e=!1!==t.blend&&t.blend!==i.Disable,o=t.blendAlpha),this.pipelineStates={depth:t.depth||n.Less,blend:e,blendRGB:r,blendAlpha:o,zWrite:!1!==t.zWrite,cull:t.cull||s.Back}}_internal(){return this.tryInit(!0),{options:this.options}}tryInit(t=!1){if(this.initialized)return!0;const e=this.gl||Object(a.b)();if(!e)return!!t&&Object(o.c)("Failed to init shader without a global GL context");this.gl=e,this.program=Object(o.d)(e.createProgram(),"Failed to create shader program"),this.vertexShader=Object(o.d)(e.createShader(e.VERTEX_SHADER),"Failed to create vertex shader"),this.fragmentShader=Object(o.d)(e.createShader(e.FRAGMENT_SHADER),"Failed to create fragment shader"),this.compile(),e.useProgram(this.program);const r=Object.assign(Object.assign({},d),this.options.attributes);this.attributes={};for(const t in r)this.attributes[t]=e.getAttribLocation(this.program,r[t]);return this.builtinUniformLocations=Object(o.b)(e,this.program,u.a),this.initialized=!0,!0}compile(){if(this.gl.shaderSource(this.vertexShader,this.vertexShaderSource),this.gl.compileShader(this.vertexShader),!this.gl.getShaderParameter(this.vertexShader,this.gl.COMPILE_STATUS))throw new Error("Failed to compile vertex shader:\r\n"+this.gl.getShaderInfoLog(this.vertexShader));if(this.gl.shaderSource(this.fragmentShader,this.fragmentShaderSouce),this.gl.compileShader(this.fragmentShader),!this.gl.getShaderParameter(this.fragmentShader,this.gl.COMPILE_STATUS))throw new Error("Failed to compile fragment shader:\r\n"+this.gl.getShaderInfoLog(this.fragmentShader));this.gl.attachShader(this.program,this.vertexShader),this.gl.attachShader(this.program,this.fragmentShader);for(const t of this.vertexStruct.elements)this.attributeNames[t.key]&&this.gl.bindAttribLocation(this.program,t.location,this.attributeNames[t.key]);if(this.gl.linkProgram(this.program),!this.gl.getProgramParameter(this.program,this.gl.LINK_STATUS))throw new Error("Failed to link shader program:\r\n"+this.gl.getProgramInfoLog(this.program))}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return l})),r.d(e,"e",(function(){return f})),r.d(e,"b",(function(){return b})),r.d(e,"c",(function(){return m})),r.d(e,"d",(function(){return p}));var n,i=r(7),s=r(11),o=(r(42),r(3)),a=r(12),u=r(15),c=r(18),h=function(t,e,r,n){var i,s=arguments.length,o=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(o=(s<3?i(o):s>3?i(e,r,o):i(e,r))||o);return s>3&&o&&Object.defineProperty(e,r,o),o};!function(t){t[t.Field=0]="Field",t[t.Dynamic=1]="Dynamic"}(n||(n={}));class l extends u.a{constructor(t,e=Object(o.b)()){super(),this.properties={},this.textureCount=0,this.boundTextures=[],this.initialized=!1,this.name="Material_"+this.assetID,this.gl=e,this._shader=t,this.pipelineStateOverride=Object.assign({},t.pipelineStates)}get shader(){return this._shader}upload(t){this.tryInit(!0),this.setupPipelineStateOverride();for(const t in this.properties){const e=this.properties[t],r=e.key?this[e.key]:e.value;void 0!==r&&this.uploadUniform(e,r)}}setProp(t,e,r){this.tryInit(!0);const n=this.getOrCreatePropInfo(t,e);e===n.type?n.key?this[n.key]=r:n.value=r:console.warn("Uniform type missmatch")}unbindRenderTextures(){this.tryInit(!0);this.gl;for(let t=0;t<this.boundTextures.length;t++){const e=this.boundTextures[t];e instanceof a.c&&e.unbind(t)}this.boundTextures.length=0}tryInit(t=!1){if(this.initialized)return!0;const e=this.gl||Object(o.b)();if(!e){if(t)throw new Error("Failed to intialize material without global GL context");return!1}this.gl=e;for(const t in this){const e=(r=this,n=t,Reflect.getMetadata(d,r,n));if(!e)continue;this.getOrCreatePropInfo(e.name,e.type).key=t}var r,n;return this.initialized=!0,!0}setUniformDirectly(t,e,r){if(void 0===r)throw new Error("");this.tryInit(!0);const n=this.getOrCreatePropInfo(t,e);n.location&&this.uploadUniform(n,r)}getOrCreatePropInfo(t,e){let r=this.properties[t];return r||(r="tex2d"===e?{type:e,value:void 0,uploaed:void 0,location:this.shader.uniformLocation(t)}:"tex2d[]"===e?{type:e,value:void 0,uploaded:void 0,location:this.shader.uniformLocation(t),buffer:new Array}:e.endsWith("[]")?{type:e,value:void 0,uploaded:void 0,location:this.shader.uniformLocation(t),buffer:new Float32Array}:{type:e,value:void 0,uploaded:void 0,location:this.shader.uniformLocation(t)},this.properties[t]=r,r)}setPipelineStateOverride(t){let e=!1,r=[i.a.One,i.a.Zero],n=[i.a.One,i.a.OneMinusSrcAlpha];"number"==typeof t.blend&&t.blend!==i.a.Disable?(e=!0,r=[t.blend,t.blend],n=[t.blend,t.blend]):t.blend instanceof Array&&(e=!0,r=t.blend),t.blendRGB&&(e=!1!==t.blend&&t.blend!==i.a.Disable,r=t.blendRGB),t.blendAlpha&&(e=!1!==t.blend&&t.blend!==i.a.Disable,n=t.blendAlpha),this.pipelineStateOverride={depth:t.depth||i.d.Less,blend:e,blendRGB:r,blendAlpha:n,zWrite:!1!==t.zWrite,cull:t.cull||i.b.Back}}setupPipelineStateOverride(){const t=this.gl;if(this.pipelineStateOverride.depth===i.d.Disable?t.disable(t.DEPTH_TEST):(t.enable(t.DEPTH_TEST),t.depthMask(this.pipelineStateOverride.zWrite),t.depthFunc(this.pipelineStateOverride.depth)),this.pipelineStateOverride.blend){const[e,r]=this.pipelineStateOverride.blendRGB,[n,i]=this.pipelineStateOverride.blendAlpha;t.enable(t.BLEND),t.blendFuncSeparate(e,r,n,i)}else t.disable(t.BLEND);this.pipelineStateOverride.cull===i.b.Disable?t.disable(t.CULL_FACE):(t.enable(t.CULL_FACE),t.cullFace(this.pipelineStateOverride.cull),t.frontFace(t.CCW))}uploadUniform(t,e){var r;const n=this.gl,i=Object(o.d)();if(!t.location)return!1;if(null===t.uploaded&&null===e&&"tex2d"!==t.type)return!1;let s=e;switch(t.type){case"int":n.uniform1i(t.location,e);break;case"float":n.uniform1f(t.location,e);break;case"vec2":n.uniform2fv(t.location,e);break;case"vec3":n.uniform3fv(t.location,e);break;case"vec4":case"color":n.uniform4fv(t.location,e);break;case"mat4":n.uniformMatrix4fv(t.location,!1,e);break;case"int[]":e.length&&n.uniform1iv(t.location,e);break;case"float[]":e.length&&n.uniform1fv(t.location,e);break;case"vec2[]":{const r=this.setVectorUniformBuffer(t,2,e);r&&n.uniform2fv(t.location,t.buffer,0,r);break}case"vec3[]":{const r=this.setVectorUniformBuffer(t,3,e);r&&n.uniform3fv(t.location,t.buffer,0,r);break}case"color[]":case"vec4[]":{const r=this.setVectorUniformBuffer(t,4,e);r&&n.uniform4fv(t.location,t.buffer,0,r);break}case"mat4[]":{const r=this.setVectorUniformBuffer(t,16,e);r&&n.uniform4fv(t.location,t.buffer,0,r);break}case"tex2d":{const r=t;e=e||i.renderer.assets.textures.default;let o=this.bindNextTexture(e);r.uploaded!==o&&(n.uniform1i(r.location,o),r.uploaded=o),s=o;break}case"tex2d[]":{const o=t,a=e;let u=!1;const c=o.uploaded||[];for(let t=0;t<a.length;t++){const e=a[t]||i.renderer.assets.textures.default;let n=this.bindNextTexture(e);(null===(r=o.uploaded)||void 0===r?void 0:r[t])!==n&&(u=!0),c[t]=n}u&&(n.uniform1iv(o.location,c,0,a.length),o.uploaded=c),s=c}}t.uploaded=s}bindNextTexture(t){return t.bind(this.boundTextures.length),this.boundTextures.push(t)-1}setVectorUniformBuffer(t,e,r){t.buffer.length<e*r.length&&(t.buffer=new Float32Array(e*r.length));for(let n=0;n<r.length;n++)t.buffer.set(r[n],n*e);return e*r.length}}const d=Symbol("shaderProp");function f(t,e){return Reflect.metadata(d,{name:t,type:e})}function b(t){return class extends l{constructor(e=Object(o.b)()){super(t,e)}}}function m(t){class e extends(b(t)){constructor(){super(...arguments),this.texture=null,this.color=new s.a(1,1,1,1)}}return h([f(c.a.mainTex,"tex2d")],e.prototype,"texture",void 0),h([f(c.a.color,"color")],e.prototype,"color",void 0),e}function p(t){return class extends t{constructor(...t){super(...t)}}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return l})),r.d(e,"b",(function(){return d}));var n=r(4),i=r(22),s=r(1),o=r(13),a=r(0),u=r(2);const c=Array,h=o.b.zero();class l extends c{constructor(t=0,e=0,r=0,n=0,i=0,s=0,o=0,a=0,u=0,c=0,h=0,l=0,d=0,f=0,b=0,m=0){super(t,e,r,n,i,s,o,a,u,c,h,l,d,f,b,m)}static create(){return new l}asMut(){return this}set(t){return n.b.set(this,...t)}fill(t){return d.fill(this,t)}clone(t=d.create()){return t.set(this)}equals(t){return d.equal(this,t)}}function d(t=0,e=0,r=0,n=0,i=0,s=0,o=0,a=0,u=0,c=0,h=0,d=0,f=0,b=0,m=0,p=0){return new l(t,e,r,n,i,s,o,a,u,c,h,d,f,b,m,p)}d.create=l.create,d.identity=Object(u.b)(n.b.identity,0,d.create),d.rts=Object(u.b)(n.b.fromRotationTranslationScale,3,d.create),d.translate=Object(u.b)(n.b.translate,2,l.create),d.invert=Object(u.b)(n.b.invert,1,l.create),d.getTranslation=Object(u.b)(n.b.getTranslation,1,s.b.zero),d.getRotation=Object(u.b)(n.b.getRotation,1,i.b.create),d.getScaling=Object(u.b)(n.b.getScaling,1,s.b.zero),d.mulVec4=Object(u.b)((t,e,r)=>n.f.transformMat4(t,r,e),2,o.b.zero),d.perspective=Object(u.b)(n.b.perspective,4,l.create),d.transpose=Object(u.b)(n.b.transpose,1,l.create),d.rotate=Object(u.b)((t,e,r,i)=>n.b.rotate(t,e,i,r),3,l.create),d.scale=Object(u.b)(n.b.scale,2,l.create),d.fromTranslation=Object(u.b)(n.b.fromTranslation,1,l.create),d.fromRotation=Object(u.b)(n.b.fromRotation,1,l.create),d.fromScaling=Object(u.b)(n.b.fromScaling,1,l.create),d.mul=Object(u.b)(n.b.mul,2,l.create),d.add=Object(u.b)(n.b.add,2,d.create),d.sub=Object(u.b)(n.b.sub,2,d.create),d.plus=d.add,d.minus=d.sub,d.mulVector=Object(u.b)((t,e,r)=>(h[0]=r[0],h[1]=r[1],h[2]=r[2],h[3]=0,n.f.transformMat4(h,h,e),t[0]=h[0],t[1]=h[1],t[2]=h[2],t),2,s.b.zero),d.mulPoint=Object(u.b)((t,e,r)=>(h[0]=r[0],h[1]=r[1],h[2]=r[2],h[3]=1,n.f.transformMat4(h,h,e),t[0]=h[0],t[1]=h[1],t[2]=h[2],t),2,s.b.zero),d.mulPoint2=Object(u.b)((t,e,r)=>(h[0]=r[0],h[1]=r[1],h[2]=0,h[3]=1,n.f.transformMat4(h,h,e),t[0]=h[0],t[1]=h[1],t),2,a.b.zero),d.mulVector2=Object(u.b)((t,e,r)=>(h[0]=r[0],h[1]=r[1],h[2]=0,h[3]=0,n.f.transformMat4(h,h,e),t[0]=h[0],t[1]=h[1],t),2,a.b.zero),d.ortho=function(...t){if(4===t.length)return function(t,e,r,i){const s=d.create();return n.b.ortho(s,-e*t,e*t,-t,t,r,i),s}(...t);const e=d.create();return n.b.ortho(e,...t),e},d.equal=(t,e)=>void 0!==t&&void 0!==e&&((t instanceof Array||t instanceof Float32Array)&&(e instanceof Array||e instanceof Float32Array)&&n.b.exactEquals(t,e)),d.set=Object(u.b)(n.b.set,1,d.create),d.fill=Object(u.b)((t,e)=>(t[0]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=e,t),1,d.create)},function(t,e,r){"use strict";r.d(e,"d",(function(){return n})),r.d(e,"c",(function(){return i})),r.d(e,"b",(function(){return s})),r.d(e,"a",(function(){return o}));r(42);function n(t,e){if(null===t)throw new Error(e);return t}function i(t){throw new Error(t)}function s(t,e,r){const n={};for(const i in r)n[i]=t.getUniformLocation(e,r[i]);return n}function o(t,e){const r=new Array(e);for(let n=0;n<e;n++)r[n]="function"==typeof t?t(n):t;return r}},function(t,e,r){"use strict";r.d(e,"a",(function(){return i})),r.d(e,"d",(function(){return s})),r.d(e,"c",(function(){return o})),r.d(e,"b",(function(){return a}));var n=r(13);class i extends n.a{get r(){return this[0]}set r(t){this[0]=t}get g(){return this[1]}set g(t){this[1]=t}get b(){return this[2]}set b(t){this[2]=t}get a(){return this[3]}set a(t){this[3]=t}constructor(t,e,r,n=1){super(t,e,r,n)}static get white(){return new i(1,1,1)}static get transparent(){return new i(1,1,1,0)}static get black(){return new i(0,0,0)}static get red(){return new i(1,0,0)}static get green(){return new i(0,1,0)}static get blue(){return new i(0,0,1)}static get cyan(){return new i(0,1,1)}static get yellow(){return new i(1,1,0)}static get magenta(){return new i(1,0,1)}static get gray(){return new i(.5,.5,.5)}transparent(){return new i(this.r,this.g,this.b,0)}setHSL(t,e,r){t=t<0?t+360:t;const n=(1-Math.abs(2*r-1))*e;if(isNaN(t))return this.r=this.g=this.b=0,this;t/=60;const i=n*(1-Math.abs(t%2-1));let s=[0,0,0];0<=t&&t<=1?s=[n,i,0]:t<=2?s=[i,n,0]:t<=3?s=[0,n,i]:t<=4?s=[0,i,n]:t<=5?s=[i,0,n]:t<=6&&(s=[n,0,i]);let o=r-n/2;return this.r=s[0]+o,this.g=s[1]+o,this.b=s[2]+o,this}get hue(){const t=this.r,e=this.g,r=this.b,n=Math.max(t,e,r),i=Math.min(t,e,r);let s=0;return n===i?s=0:n===t?s=60*(0+(e-r)/(n-i)):n===e?s=60*(2+(r-t)/(n-i)):n===r&&(s=60*(4+(t-e)/(n-i))),s<0?s+360:s}get saturation(){const t=Math.max(this.r,this.g,this.b),e=Math.min(this.r,this.g,this.b);return 0===t||1==e?0:(t-e)/(1-Math.abs(t+e-1))}get lightness(){return(Math.max(this.r,this.g,this.b)+Math.min(this.r,this.g,this.b))/2}toHSL(){return[this.hue,this.saturation,this.lightness]}static fromHSL(t,e,r,n=1){return new i(0,0,0,n).setHSL(t,e,r)}static fromString(t,e){t=t.replace(new RegExp(/\s/g),"");var r=new RegExp("#[0-9a-fA-F]{6}");if(r.test(t)){var n=(t=t.replace("#","")).charAt(0)+t.charAt(1),s=t.charAt(2)+t.charAt(3),o=t.charAt(4)+t.charAt(5),a=parseInt(n,16),u=parseInt(s,16),c=parseInt(o,16);return new i(a/255,u/255,c/255,e||1)}if((r=new RegExp("rgb\\(([0-9]+(\\.[0-9]+){0,1}),([0-9]+(\\.[0-9]+){0,1}),([0-9]+(\\.[0-9]+){0,1})\\)")).test(t)){var h=t.replace("rgb(","").replace(")","").split(",");a=parseInt(h[0]),u=parseInt(h[1]),c=parseInt(h[2]);return new i(a/255,u/255,c/255,(l=e||1)/255)}if((r=new RegExp("rgba\\(([0-9]+(\\.[0-9]+){0,1}),([0-9]+(\\.[0-9]+){0,1}),([0-9]+(\\.[0-9]+){0,1}),([0-9]+(\\.[0-9]+){0,1})\\)")).test(t)){h=t.replace("rgba(","").replace(")","").split(","),a=parseInt(h[0]),u=parseInt(h[1]),c=parseInt(h[2]);var l=e||parseFloat(h[3]);return new i(a/255,u/255,c/255,l)}throw new Error(`Invalid color string '${t}'`)}}const s=(t,e,r,n=1)=>new i(t,e,r,n),o=(t,e,r)=>new i(t,e,r,1),a=i.fromHSL},function(t,e,r){"use strict";r.d(e,"b",(function(){return n})),r.d(e,"g",(function(){return i})),r.d(e,"d",(function(){return b})),r.d(e,"f",(function(){return s})),r.d(e,"e",(function(){return p})),r.d(e,"a",(function(){return v})),r.d(e,"c",(function(){return g}));var n,i,s,o=r(3),a=r(14),u=r(10),c=r(15),h=r(18),l=r(0),d=r(41),f=r(17);!function(t){t[t.Linear=WebGL2RenderingContext.LINEAR]="Linear",t[t.Nearest=WebGL2RenderingContext.NEAREST]="Nearest"}(n||(n={})),function(t){t[t.Repeat=WebGL2RenderingContext.REPEAT]="Repeat",t[t.Clamp=WebGL2RenderingContext.CLAMP_TO_EDGE]="Clamp",t[t.Mirror=WebGL2RenderingContext.MIRRORED_REPEAT]="Mirror"}(i||(i={}));class b extends c.a{}!function(t){t[t.Discard=0]="Discard",t[t.Stretch=1]="Stretch",t[t.Cover=2]="Cover",t[t.Contain=3]="Contain",t[t.KeepLower=4]="KeepLower",t[t.KeepHigher=5]="KeepHigher",t[t.Center=6]="Center"}(s||(s={}));class m extends c.a{constructor(t,e,r=a.a.RGBA,s=n.Linear,u=Object(o.d)()){super(),this.autoMipmap=!0,this.wrapMode=i.Repeat,this._glTex=null,this.initialized=!1,this.created=!1,this.name="Texture_"+this.assetID,this.ctx=u,this.format=r,this.width=t,this.height=e,this.filterMode=s,this.tryInit(!1)}get size(){return Object(l.b)(this.width,this.height)}glTex(){return this.create(),this._glTex}bind(t){this.create();const e=this.ctx.gl;e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,this._glTex)}unbind(t){this.create();const e=this.ctx.gl;e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_2D,null)}destroy(){if(!this.initialized||this.destroyed)return;this.ctx.gl.deleteTexture(this._glTex),super.destroy()}resize(t,e,r=s.Discard){this.tryInit(!0);const n=this.ctx.gl;let i=m.wrapGlTex(this._glTex,this.width,this.height,this.format,this.filterMode,this.ctx),o=new g(t,e,!1,this.format,this.filterMode,this.ctx);o.wrapMode=this.wrapMode,o.autoMipmap=this.autoMipmap,o.create(),o.updateParameters();const a=this.size;switch(this.width=t,this.height=e,r){case s.Discard:break;default:const[t,e]=Object(d.b)(a,o.size,r);this.ctx.renderer.blit(i,o,this.ctx.assets.materials.blitCopy,t,e)}return this.autoMipmap&&o.generateMipmap(),this._glTex=o._glTex,n.deleteTexture(i._glTex),this}generateMipmap(){this.create();const t=this.ctx.gl;t.bindTexture(t.TEXTURE_2D,this._glTex),t.generateMipmap(t.TEXTURE_2D)}updateParameters(){this.create();const t=this.ctx.gl;t.bindTexture(t.TEXTURE_2D,this._glTex),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,this.filterMode),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,this.filterMode),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,this.wrapMode),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,this.wrapMode)}create(){if(this.created)return;this.tryInit(!0);const t=this.ctx.gl;t.bindTexture(t.TEXTURE_2D,this._glTex);const[e,r,n]=Object(a.b)(t,this.format);t.texImage2D(t.TEXTURE_2D,0,e,this.width,this.height,0,r,n,null),this.created=!0,this.updateParameters(),t.bindTexture(t.TEXTURE_2D,null)}setData(t){this.create();const e=this.ctx.gl;e.bindTexture(e.TEXTURE_2D,this._glTex),function(t,e,r,n,i,s,o,c,l){var d,f;const b=t.gl,m=(t.renderer,null!==(d=b.createTexture())&&void 0!==d?d:Object(u.c)("Failed to create texture.")),[p,v,g]=Object(a.b)(b,s);b.bindTexture(b.TEXTURE_2D,m),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MIN_FILTER,b.NEAREST),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_MAG_FILTER,b.NEAREST),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_S,c),b.texParameteri(b.TEXTURE_2D,b.TEXTURE_WRAP_T,c),void 0!==r.width&&void 0!==r.height?(r=r,b.texImage2D(b.TEXTURE_2D,l,p,v,g,r)):(r=r,b.texImage2D(b.TEXTURE_2D,l,p,n,i,0,v,g,r));const y=null!==(f=b.createFramebuffer())&&void 0!==f?f:Object(u.c)("Failed to create frame buffer");b.bindFramebuffer(b.FRAMEBUFFER,y),b.framebufferTexture2D(b.FRAMEBUFFER,b.COLOR_ATTACHMENT0,b.TEXTURE_2D,e,0),b.viewport(0,0,n,i),b.drawBuffers([b.COLOR_ATTACHMENT0]),b.disable(b.CULL_FACE);const x=t.assets.shaders.FlipTexture;x.use(),b.activeTexture(b.TEXTURE0),b.bindTexture(b.TEXTURE_2D,m),b.uniform1i(x.uniformLocation(h.a.mainTex),0);const M=t.assets.meshes.screenQuad;M.bind(),b.drawElements(b.TRIANGLE_STRIP,M.indices.length,b.UNSIGNED_INT,0),b.activeTexture(b.TEXTURE0),b.bindTexture(b.TEXTURE_2D,null),b.deleteFramebuffer(y),b.bindFramebuffer(b.FRAMEBUFFER,null),b.deleteTexture(m)}(this.ctx,this._glTex,t,this.width,this.height,this.format,this.filterMode,this.wrapMode,0)}tryInit(t=!1){var e;if(this.initialized)return!0;const r=this.ctx||Object(o.d)();if(!r){if(t)throw new Error("Failed to initialize texture without a global GL context");return!1}const n=r.gl;return this._glTex=null!==(e=n.createTexture())&&void 0!==e?e:Object(u.c)("Failed to create texture."),this.initialized=!0,!0}static wrapGlTex(t,e,r,i=a.a.RGBA,s=n.Linear,u=Object(o.d)()){var c=new m(e,r,i,s,u);return c._glTex=t,c.initialized=!0,c.created=!0,c}}class p extends m{constructor(t=0,e=0,r=a.a.RGBA,i=n.Linear,s=Object(o.d)()){super(t,e,r,i,s)}setData(t){void 0!==t.width&&void 0!==t.height&&(t=t,this.width=t.width,this.height=t.height),super.setData(t)}clone(){this.created||this.create();let t=new g(this.width,this.height,!1,this.format,this.filterMode,this.ctx);this.ctx.renderer.blit(this,t);let e=new p(this.width,this.height,this.format,this.filterMode,this.ctx);return e._glTex=t.glTex(),e.initialized=!0,e.created=!0,e}}class v extends m{constructor(t,e,r=Object(o.d)()){super(t,e,a.a.DEPTH_COMPONENT,n.Nearest,r)}bindFramebuffer(){this.create();const t=this.ctx.gl;t.framebufferTexture2D(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.TEXTURE_2D,this._glTex,0)}}class g extends m{constructor(t,e,r=!1,i=a.a.RGBA,s=n.Linear,u=Object(o.d)()){super(t,e,i,s,u),this.depthTexture=null,r&&(this.depthTexture=new v(t,e,u))}setData(t){super.setData(t)}destroy(){var t;this.initialized&&!this.destroyed&&(null===(t=this.depthTexture)||void 0===t||t.destroy(),super.destroy())}bindFramebuffer(t){this.create();const e=this.ctx.gl;e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.TEXTURE_2D,this._glTex,0)}createFramebuffer(){this.create();const t=new f.a(this.width,this.height);return t.addColorAttachment(this,0),t}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return u})),r.d(e,"b",(function(){return c}));var n=r(1),i=r(0),s=r(4),o=r(2);const a=Array;class u extends a{get x(){return this[0]}set x(t){this[0]=t}get y(){return this[1]}set y(t){this[1]=t}get z(){return this[2]}set z(t){this[2]=t}get w(){return this[3]}set w(t){this[3]=t}get magnitude(){return Math.hypot(...this)}get normalized(){const t=this.magnitude;return 0==t?c.zero():this.clone().div(c(t,t,t,t))}get negative(){return this.clone().negate()}get inversed(){return this.clone().inverse()}constructor(t,e,r=0,n=0){super(t,e,r||0,n||0)}static zero(){return new u(0,0,0,0)}static one(){return new u(1,1,1,1)}asMut(){return this}plus(t){return c.plus(this,this,t)}minus(t){return c.minus(this,this,t)}mul(t){return c.mul(this,this,t)}div(t){return c.div(this,this,t)}dot(t){return this[0]*t[0]+this[1]*t[1]+this[2]*t[2]+this[3]*t[3]}normalize(){return c.normalize(this,this)}inverse(){return this[0]=1/this[0],this[1]=1/this[1],this[2]=1/this[2],this[3]=1/this[3],this}negate(){return this[0]=-this[0],this[1]=-this[1],this[2]=-this[2],this[3]=-this[3],this}clone(t=c.zero()){return t.set(this)}equals(t){return void 0!==t&&(t[0]===this[0]&&t[1]===this[1]&&t[2]===this[2]&&t[3]===this[3])}set(t){return this[0]=t[0]||0,this[1]=t[1]||0,this[2]=t[2]||0,this[3]=t[3]||0,this}fill(t){return this[0]=this[1]=this[2]=this[3]=t,this}static math(t){return(...e)=>c(t(...e.map(t=>t.x)),t(...e.map(t=>t.y)),t(...e.map(t=>t.z)),t(...e.map(t=>t.w)))}static mathNonAlloc(t){return(e,...r)=>(e[0]=t(...r.map(t=>t[0])),e[1]=t(...r.map(t=>t[1])),e[2]=t(...r.map(t=>t[2])),e[3]=t(...r.map(t=>t[3])),e)}__to(t){switch(t){case u:return this.clone();case n.a:return Object(n.b)(this[0],this[1],this[2]);case i.a:return Object(i.b)(this[0],this[1])}return this.clone()}}function c(t,e=t,r=t,n=t){return new u(t,e,r,n)}c.from=t=>{const[e=0,r=0,n=0,i=0]=t;return c(e,r,n,i)},c.floor=t=>c(Math.floor(t.x),Math.floor(t.y),Math.floor(t.z),Math.floor(t.w)),c.zero=u.zero,c.one=u.one,c.math=u.math,c.mathNonAlloc=u.mathNonAlloc,c.normalize=Object(o.b)(s.f.normalize,1,c.zero),c.plus=Object(o.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]+r,t[1]=e[1]+r,t[2]=e[2]+r,t[3]=e[3]+r):(t[0]=e[0]+r[0],t[1]=e[1]+(r[1]||0),t[2]=e[2]+(r[2]||0),t[3]=e[3]+(r[3]||0)),t),2,c.zero),c.minus=Object(o.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]-r,t[1]=e[1]-r,t[2]=e[2]-r,t[3]=e[3]-r):(t[0]=e[0]-r[0],t[1]=e[1]-(r[1]||0),t[2]=e[2]-(r[2]||0),t[3]=e[3]-(r[3]||0)),t),2,c.zero),c.mul=Object(o.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t[3]=e[3]*r):(t[0]=e[0]*r[0],t[1]=e[1]*(void 0===r[1]?1:r[1]),t[2]=e[2]*(void 0===r[2]?1:r[2]),t[3]=e[3]*(void 0===r[3]?1:r[3])),t),2,c.zero),c.div=Object(o.b)((t,e,r)=>("number"==typeof r?(t[0]=e[0]/r,t[1]=e[1]/r,t[2]=e[2]/r,t[3]=e[3]/r):(t[0]=e[0]/r[0],t[1]=e[1]/(void 0===r[1]?1:r[1]),t[2]=e[2]/(void 0===r[2]?1:r[2]),t[3]=e[3]/(void 0===r[3]?1:r[3])),t),2,c.zero),c.set=Object(o.b)((t,e)=>(t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t),1,c.zero),c.fill=Object(o.b)((t,e)=>(t[0]=t[1]=t[2]=t[3]=e,t),1,c.zero)},function(t,e,r){"use strict";var n;function i(t,e){return{[n.RGB]:[t.RGB,t.RGB,t.UNSIGNED_BYTE],[n.RGBA]:[t.RGBA,t.RGBA,t.UNSIGNED_BYTE],[n.LUMINANCE_ALPHA]:[t.LUMINANCE_ALPHA,t.LUMINANCE_ALPHA,t.UNSIGNED_BYTE],[n.LUMINANCE]:[t.LUMINANCE,t.LUMINANCE,t.UNSIGNED_BYTE],[n.ALPHA]:[t.ALPHA,t.ALPHA,t.UNSIGNED_BYTE],[n.R8]:[t.R8,t.RED,t.UNSIGNED_BYTE],[n.R16F]:[t.R16F,t.RED,t.HALF_FLOAT],[n.R32F]:[t.R32F,t.RED,t.FLOAT],[n.R8UI]:[t.R8UI,t.RED_INTEGER,t.UNSIGNED_BYTE],[n.RG8]:[t.RG8,t.RG,t.UNSIGNED_BYTE],[n.RG16F]:[t.RG16F,t.RG,t.HALF_FLOAT],[n.RG32F]:[t.RG32F,t.RG,t.FLOAT],[n.RG8UI]:[t.RG8UI,t.RG_INTEGER,t.UNSIGNED_BYTE],[n.RGB8]:[t.RGB8,t.RGB,t.UNSIGNED_BYTE],[n.SRGB8]:[t.SRGB8,t.RGB,t.UNSIGNED_BYTE],[n.RGB565]:[t.RGB565,t.RGB,t.UNSIGNED_BYTE],[n.R11F_G11F_B10F]:[t.R11F_G11F_B10F,t.RGB,t.UNSIGNED_INT_10F_11F_11F_REV],[n.RGB9_E5]:[t.RGB9_E5,t.RGB,t.HALF_FLOAT],[n.RGB16F]:[t.RGB16F,t.RGB,t.HALF_FLOAT],[n.RGB32F]:[t.RGB32F,t.RGB,t.FLOAT],[n.RGB8UI]:[t.RGB8UI,t.RGB_INTEGER,t.UNSIGNED_BYTE],[n.RGBA8]:[t.RGBA8,t.RGBA,t.UNSIGNED_BYTE],[n.SRGB8_ALPHA8]:[t.SRGB8_ALPHA8,t.RGBA,t.UNSIGNED_BYTE],[n.RGB5_A1]:[t.RGB5_A1,t.RGBA,t.UNSIGNED_BYTE],[n.RGB10_A2]:[t.RGB10_A2,t.RGBA,t.UNSIGNED_INT_2_10_10_10_REV],[n.RGBA4]:[t.RGBA4,t.RGBA,t.UNSIGNED_BYTE],[n.RGBA16F]:[t.RGBA16F,t.RGBA,t.HALF_FLOAT],[n.RGBA32F]:[t.RGBA32F,t.RGBA,t.FLOAT],[n.RGBA8UI]:[t.RGBA8UI,t.RGBA_INTEGER,t.UNSIGNED_BYTE],[n.DEPTH_COMPONENT]:[t.DEPTH_COMPONENT,t.DEPTH_COMPONENT,t.UNSIGNED_INT],[n.DEPTH_STENCIL]:[t.DEPTH_STENCIL,t.DEPTH_COMPONENT,t.UNSIGNED_INT]}[e]}r.d(e,"a",(function(){return n})),r.d(e,"b",(function(){return i})),function(t){t[t.RGB=WebGL2RenderingContext.RGB]="RGB",t[t.RGBA=WebGL2RenderingContext.RGBA]="RGBA",t[t.LUMINANCE_ALPHA=WebGL2RenderingContext.LUMINANCE_ALPHA]="LUMINANCE_ALPHA",t[t.LUMINANCE=WebGL2RenderingContext.LUMINANCE]="LUMINANCE",t[t.ALPHA=WebGL2RenderingContext.ALPHA]="ALPHA",t[t.R8=WebGL2RenderingContext.R8]="R8",t[t.R16F=WebGL2RenderingContext.R16F]="R16F",t[t.R32F=WebGL2RenderingContext.R32F]="R32F",t[t.R8UI=WebGL2RenderingContext.R8UI]="R8UI",t[t.RG8=WebGL2RenderingContext.RG8]="RG8",t[t.RG16F=WebGL2RenderingContext.RG16F]="RG16F",t[t.RG32F=WebGL2RenderingContext.RG32F]="RG32F",t[t.RG8UI=WebGL2RenderingContext.RG8UI]="RG8UI",t[t.RGB8=WebGL2RenderingContext.RGB8]="RGB8",t[t.SRGB8=WebGL2RenderingContext.SRGB8]="SRGB8",t[t.RGB565=WebGL2RenderingContext.RGB565]="RGB565",t[t.R11F_G11F_B10F=WebGL2RenderingContext.R11F_G11F_B10F]="R11F_G11F_B10F",t[t.RGB9_E5=WebGL2RenderingContext.RGB9_E5]="RGB9_E5",t[t.RGB16F=WebGL2RenderingContext.RGB16F]="RGB16F",t[t.RGB32F=WebGL2RenderingContext.RGB32F]="RGB32F",t[t.RGB8UI=WebGL2RenderingContext.RGB8UI]="RGB8UI",t[t.RGBA8=WebGL2RenderingContext.RGBA8]="RGBA8",t[t.SRGB8_ALPHA8=WebGL2RenderingContext.SRGB8_ALPHA8]="SRGB8_ALPHA8",t[t.RGB5_A1=WebGL2RenderingContext.RGB5_A1]="RGB5_A1",t[t.RGB10_A2=WebGL2RenderingContext.RGB10_A2]="RGB10_A2",t[t.RGBA4=WebGL2RenderingContext.RGBA4]="RGBA4",t[t.RGBA16F=WebGL2RenderingContext.RGBA16F]="RGBA16F",t[t.RGBA32F=WebGL2RenderingContext.RGBA32F]="RGBA32F",t[t.RGBA8UI=WebGL2RenderingContext.RGBA8UI]="RGBA8UI",t[t.DEPTH_COMPONENT=WebGL2RenderingContext.DEPTH_COMPONENT]="DEPTH_COMPONENT",t[t.DEPTH_STENCIL=WebGL2RenderingContext.DEPTH_STENCIL]="DEPTH_STENCIL"}(n||(n={}))},function(t,e,r){"use strict";r.d(e,"a",(function(){return s})),r.d(e,"c",(function(){return o})),r.d(e,"d",(function(){return a})),r.d(e,"b",(function(){return u}));var n=r(28),i=r(3);class s{constructor(t){this.destroyed=!1,this.assetID=u.newAssetID(this),this.name=t||"Asset_"+this.assetID}destroy(){this.destroyed=!0,u.destroy(this.assetID)}}class o extends s{constructor(t=Object(i.d)(),e){super(e),this.initialized=!1,this.ctx=t}tryInit(t=!1){if(this.initialized)return!0;this.ctx||(this.ctx=Object(i.d)());const e=this.ctx&&this.init();if(!e&&t)throw new Error(`Failed to init GPU Asset '${this.name}' without global gl context.`);return this.initialized=e,e}}class a extends s{constructor(t=Object(i.d)()){super(),this.initialzed=!1,this.ctx=t}tryInit(t=!1){if(this.initialzed)return!0;const e=this.ctx||Object(i.d)();if(!e){if(t)throw new Error("Failed to initialize GPU resource withou a global GL context.");return!1}if(this.ctx=e,this.init())return this.initialzed=!0,!0;if(t)throw new Error("Failed to initialize required GPU resource.");return!1}}const u=new class{constructor(){this.assetsMap=new Map,this.id=1,this.eventEmitter=new n.a}newAssetID(t){const e=++this.id;return this.assetsMap.set(e,t),t.assetID=e}find(t){if("number"==typeof t)return this.assetsMap.get(t);if("string"==typeof t)for(const e of this.assetsMap.values())if(e.name===t)return e}destroy(t){this.assetsMap.get(t)&&this.assetsMap.delete(t)}findAssetsOfType(t){return Array.from(this.assetsMap.values()).filter(e=>e instanceof t)}on(t,e){return this.eventEmitter.on(t,e)}off(t,e){return this.eventEmitter.off(t,e)}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return l})),r.d(e,"b",(function(){return d})),r.d(e,"e",(function(){return f})),r.d(e,"c",(function(){return b})),r.d(e,"d",(function(){return m}));var n=r(1),i=r(0),s=r(11),o=r(3),a=r(10),u=r(6),c=r(15),h=r(23);const l={vert:"vec3",color:"vec4",normal:"vec3",uv:"vec2",uv2:"vec2"},d=h.a.from(l);function f(t){return t}class b extends c.a{constructor(...t){super("Mesh"),this.ctx=null,this.initialized=!1,this.vertexArray=null,this.elementBuffer=null,this.dirty=!0,this.indices=new Uint32Array,0===t.length?(this.ctx=Object(o.d)(),this.vertices=new h.b(l,0,this.ctx)):1===t.length?t[0]instanceof o.c?(this.ctx=t[0],this.vertices=new h.b(l,0,this.ctx)):(this.ctx=Object(o.d)(),this.vertices=new h.b(t[0],0,this.ctx)):(this.ctx=t[1]||Object(o.d)(),this.vertices=new h.b(t[0],0,this.ctx)),this.tryInit(!1)}get verts(){return this.getVertexDataArray("vert",n.b.zero)}set verts(t){this.setVertexDataArray("vert",t)}get uvs(){return this.getVertexDataArray("uv",i.b.zero)}set uvs(t){this.setVertexDataArray("uv",t)}get colors(){return this.getVertexDataArray("color",()=>s.a.black)}set colors(t){this.setVertexDataArray("color",t)}get normals(){return this.getVertexDataArray("uv2",n.b.zero)}set normals(t){this.setVertexDataArray("normal",t)}get uv2(){return this.getVertexDataArray("uv2",i.b.zero)}set uv2(t){this.setVertexDataArray("uv2",t)}get triangles(){return Array.from(this.indices)}set triangles(t){t.length>this.indices.length&&(this.indices=new Uint32Array(t.length)),this.indices.set(t)}getVertexDataArray(t,e){return this.vertices.map(r=>e().set(r[t]))}setVertexDataArray(t,e){this.vertices;e.length>=this.vertices.length&&this.vertices.resize(e.length),e.forEach((e,r)=>this.vertices[r][t].set(e))}resize(t,e,r=!1){this.vertices.resize(t,r);let n=this.indices;this.indices=new Uint32Array(e),r&&(e<n.length&&(n=new Uint32Array(n.buffer,0,e)),this.indices.set(n,0)),this.dirty=!0}update(t=!1){this.dirty=!0,this.vertices.markDirty(),t&&this.upload()}upload(){if(this.tryInit(!0),!this.dirty)return!1;const t=this.ctx.gl;return this.vertices.upload(),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.elementBuffer),t.bufferData(t.ELEMENT_ARRAY_BUFFER,this.indices,t.STATIC_DRAW),this.dirty=!1,!0}bind(){this.upload();const t=this.ctx.gl;return t.bindVertexArray(this.vertexArray),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.elementBuffer),this.indices.length}unbind(){this.tryInit(!0);const t=this.ctx.gl;t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null),t.bindVertexArray(null)}calculateNormals(t=0){if(this.triangles.length%3!=0)throw new Error("Invalid triangles.");for(let t=0;t<this.triangles.length;t+=3){const e=this.vertices[this.triangles[t+0]].vert,r=this.vertices[this.triangles[t+1]].vert,i=this.vertices[this.triangles[t+2]].vert,s=Object(u.h)(r,e),o=Object(u.h)(i,e),a=Object(u.d)(s,o).normalize();n.b.plus(this.vertices[this.triangles[t+0]].normal,this.vertices[this.triangles[t+0]].normal,a),n.b.plus(this.vertices[this.triangles[t+1]].normal,this.vertices[this.triangles[t+1]].normal,a),n.b.plus(this.vertices[this.triangles[t+2]].normal,this.vertices[this.triangles[t+2]].normal,a)}for(let t=0;t<this.vertices.length;t++)n.b.normalize(this.vertices[t].normal,this.vertices[t].normal)}tryInit(t=!1){var e,r;if(this.initialized)return!0;if(this.ctx=this.ctx||Object(o.d)(),!this.ctx){if(t)throw new Error("Failed to init mesh without global GL context");return!1}const n=this.ctx.gl;return this.elementBuffer=null!==(e=n.createBuffer())&&void 0!==e?e:Object(a.c)("Failed to create element buffer object."),this.vertexArray=null!==(r=n.createVertexArray())&&void 0!==r?r:Object(a.c)("Failed to create vertex array object."),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,this.elementBuffer),n.bindVertexArray(this.vertexArray),this.vertices.bindVertexArray(),n.bindVertexArray(null),this.initialized=!0,!0}}class m extends c.a{constructor(t=Object(o.b)()){super(),this._verts=[],this._triangles=[],this._uvs=[],this._uv2=[],this._colors=[],this._normals=[],this.dirty=!0,this.uploaded=!1,this.vertices=new Float32Array(0),this.indices=new Uint32Array(0),this.VAO=null,this.VBO=null,this.EBO=null,this.initialized=!1,this.name="Mesh_"+this.assetID,this.vertexStruct=d,this.gl=t,this.tryInit(!1)}get verts(){return this._verts}set verts(t){this._verts=t,this.dirty=!0}get triangles(){return this._triangles}set triangles(t){this._triangles=t,this.dirty=!0}get uvs(){return this._uvs}set uvs(t){this._uvs=t,this.dirty=!0}get uv2(){return this._uv2}set uv2(t){this._uv2=t,this.dirty=!0}get colors(){return this._colors}set colors(t){this._colors=t,this.dirty=!0}get normals(){return this._normals}set normals(t){this._normals=t,this.dirty=!0}clear(){this.verts=[],this.uvs=[],this.triangles=[],this.colors=[],this.normals=[]}calculateNormals(t=0){if(this.triangles.length%3!=0)throw new Error("Invalid triangles.");this.normals=Object(a.a)(()=>Object(n.b)(0,0,0),this.verts.length);for(let t=0;t<this.triangles.length;t+=3){const e=this.verts[this.triangles[t]],r=this.verts[this.triangles[t+1]],n=this.verts[this.triangles[t+2]],i=Object(u.h)(r,e),s=Object(u.h)(n,e),o=Object(u.d)(i,s).normalize();this.normals[this.triangles[t+0]].plus(o),this.normals[this.triangles[t+1]].plus(o),this.normals[this.triangles[t+2]].plus(o)}for(let t=0;t<this.normals.length;t++)this.normals[t]=this.normals[t].normalize()}update(){if(this.dirty){if(this.triangles.length%3!=0)throw new Error("Invalid triangles.");if(this.colors.length!==this.verts.length&&(this.colors=[...this.colors,...Object(a.a)(s.a.white,this.verts.length-this.colors.length)]),this.uvs.length!==this.verts.length&&(this.uvs=[...this.uvs,...Object(a.a)(Object(i.b)(0,0),this.verts.length-this.uvs.length)]),this.uv2.length!==this.verts.length&&(this.uv2=[...this.uv2,...Object(a.a)(Object(i.b)(0,0),this.verts.length-this.uv2.length)]),this.normals.length!==this.verts.length&&(this.normals=[...this.normals,...Object(a.a)(Object(n.b)(0,0,0),this.verts.length-this.normals.length)]),this.vertices=new Float32Array(this.verts.flatMap((t,e)=>[...t,...this.colors[e],...this.normals[e],...this.uvs[e],...this.uv2[e]])),this.vertices.length!=14*this.verts.length)throw new Error("Buffer with invalid length.");this.indices=new Uint32Array(this.triangles.flat()),this.dirty=!1,this.uploaded=!1}}setup(){this.update(),this.tryInit(!0);const t=this.gl;return this.uploaded||(t.bindBuffer(t.ARRAY_BUFFER,this.VBO),t.bufferData(t.ARRAY_BUFFER,this.vertices,t.STATIC_DRAW),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.EBO),t.bufferData(t.ELEMENT_ARRAY_BUFFER,this.indices,t.STATIC_DRAW),this.uploaded=!0),[this.VBO,this.EBO]}bind(t){this.setup();const e=this.gl;e.bindVertexArray(this.VAO),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.EBO)}unbind(){const t=this.gl;t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,null),t.bindVertexArray(null)}destroy(){this.initialized&&(this.destroyed||(this.gl.deleteBuffer(this.VBO),this.gl.deleteBuffer(this.EBO),super.destroy()))}tryInit(t=!1){var e,r;if(this.initialized)return!0;const n=this.gl||Object(o.b)();if(!n){if(t)throw new Error("Failed to init mesh without global GL context");return!1}return this.gl=n,this.VBO=null!==(e=n.createBuffer())&&void 0!==e?e:Object(a.c)("Failed to create vertex buffer."),this.EBO=null!==(r=n.createBuffer())&&void 0!==r?r:Object(a.c)("Failed to create element buffer."),this.initVAO(),this.initialized=!0,!0}initVAO(){var t;const e=this.gl;this.VAO=null!==(t=e.createVertexArray())&&void 0!==t?t:Object(a.c)("Failed to create vertex array object."),e.bindVertexArray(this.VAO),e.bindBuffer(e.ARRAY_BUFFER,this.VBO);for(const t of this.vertexStruct.elements)e.enableVertexAttribArray(t.location),e.vertexAttribPointer(t.location,t.length,e.FLOAT,!1,this.vertexStruct.byteSize,t.byteOffset);e.bindVertexArray(null),e.bindBuffer(e.ARRAY_BUFFER,null)}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return a}));var n=r(3),i=r(10),s=r(0),o=r(15);WebGL2RenderingContext.BACK;class a extends o.c{constructor(t=0,e=0,r=Object(n.d)()){super(r),this.frameBuffer=null,this._colorAttachments=[],this._depthAttachment=null,this.activeBuffers=[],this.dirty=!0,this.size=Object(s.b)(Math.floor(t),Math.floor(e)),this.tryInit(!1)}get width(){return this.size.x}get height(){return this.size.y}get colorAttachments(){return this._colorAttachments}get depthAttachment(){return this._depthAttachment}glFBO(){return this.tryInit(!0),this.frameBuffer}addColorAttachment(t,e=this._colorAttachments.length){t.width===this.size.x&&t.height===this.size.y||console.warn(`Color attachment size [${t.width}, ${t.height}] missmatch with framebuffer.`),this._colorAttachments[e]=t,this.dirty=!0}setDepthAttachment(t){t.width===this.size.x&&t.height===this.size.y||console.warn(`Depth attachment size [${t.width}, ${t.height}] missmatch with framebuffer.`),this._depthAttachment=t,this.dirty=!0}reset(t=this.width,e=this.height){this.size.x=t,this.size.y=e,this._colorAttachments=[],this._depthAttachment=null,this.dirty=!0}init(){var t;const e=this.ctx.gl;return this.frameBuffer=null!==(t=e.createFramebuffer())&&void 0!==t?t:Object(i.c)("Failed to create frame buffer object"),!0}bind(){this.tryInit(!0);const t=this.ctx.gl;this.activeBuffers=[],t.bindFramebuffer(t.FRAMEBUFFER,this.frameBuffer);for(let e=0;e<this._colorAttachments.length;e++)this._colorAttachments[e]?(this._colorAttachments[e].bindFramebuffer(e),this.activeBuffers.push(t.COLOR_ATTACHMENT0+e)):t.framebufferRenderbuffer(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0+e,t.RENDERBUFFER,null);this._depthAttachment?(this._depthAttachment.bindFramebuffer(),this.activeBuffers.push(t.DEPTH_ATTACHMENT)):t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,null),t.viewport(0,0,this.width,this.height),t.drawBuffers(this.activeBuffers)}destroy(){super.destroy();this.ctx.gl.deleteFramebuffer(this.frameBuffer)}}a.CanvasBuffer=Object.freeze(new class{get name(){return""}get assetID(){return-1}get width(){return Object(n.d)().width}get height(){return Object(n.d)().height}get size(){return Object(n.d)().renderer.canvasSize}bind(){const t=Object(n.d)().gl;t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,this.width,this.height)}destroy(){}})},function(t,e,r){"use strict";r.d(e,"a",(function(){return s})),r.d(e,"b",(function(){return o}));var n=r(7),i=r(20);const s={matM:"uTransformM",matM_IT:"uTransformM_IT",matMInv:"uTransformMInv",matVP:"uTransformVP",matMVP:"uTransformMVP",matMV_IT:"uTransformMV_IT",flipUV:"uFlipUV",mainTex:"uMainTex",color:"uColor"};function o(t){return{DefaultShader:new n.e(i.BuiltinShaderSources.defaultVert,i.BuiltinShaderSources.defaultFrag,{name:"DefaultShader"},t),BlitCopy:new n.e(i.BuiltinShaderSources.defaultVert,i.BuiltinShaderSources.blitCopy,{name:"BlitCopy",depth:n.d.Always,blend:n.a.Disable,zWrite:!1},t),FlipTexture:new n.e(i.BuiltinShaderSources.flipVert,i.BuiltinShaderSources.blitCopy,{},t),ColoredLine:new n.e(i.BuiltinShaderSources.colorVert,i.BuiltinShaderSources.colorFrag,{blend:[n.a.SrcAlpha,n.a.OneMinusSrcAlpha],depth:n.d.Disable,zWrite:!1},t),ErrorShader:new n.e(i.BuiltinShaderSources.defaultVert,i.BuiltinShaderSources.texFrag,{name:"Error"},t)}}},function(t,e,r){"use strict";var n=Object.defineProperty;n(e,"__esModule",{value:!0}),((t,e)=>{for(var r in e)n(t,r,{get:e[r],enumerable:!0})})(e,{ShaderSource:()=>o});var i="#version 300 es\r\nprecision mediump float;\r\n\r\nin vec3 aPos;\r\nin vec4 aColor;\r\nin vec2 aUV;\r\nin vec3 aNormal;\r\n\r\nuniform mat4 uTransformM;\r\nuniform mat4 uTransformVP;\r\nuniform mat4 uTransformMVP;\r\nuniform mat4 uTransformM_IT;\r\n\r\nout vec4 vColor;\r\nout vec4 vPos;\r\nout vec2 vUV;\r\nout vec3 vNormal;\r\nout vec3 vWorldPos;\r\n\r\nvoid main()\r\n{\r\n    gl_Position = uTransformMVP * vec4(aPos, 1);\r\n    vPos = gl_Position;\r\n    vColor = aColor;\r\n    vUV = aUV;\r\n    vNormal = (uTransformM_IT *  vec4(aNormal, 0)).xyz;\r\n    vWorldPos = (uTransformM * vec4(aPos, 1)).xyz;\r\n    \r\n}",s="#version 300 es\r\nprecision mediump float;\r\n\r\nin vec4 vColor;\r\nin vec4 vPos;\r\nin vec2 vUV;\r\n\r\nuniform sampler2D uMainTex;\r\nuniform vec4 uColor;\r\n\r\nout vec4 fragColor;\r\n\r\nvoid main()\r\n{\r\n    vec4 color = texture(uMainTex, vUV.xy).rgba;\r\n    // color = color * vec3(uColor);\r\n    fragColor = color.rgba * vColor.rgba * uColor.rgba;\r\n    // fragColor = vec4(vUV.xy, 0, 1);\r\n}",o={default2D:[i,s],particle2D:["#version 300 es\r\nprecision mediump float;\r\n\r\nin vec3 aPos;\r\nin vec4 aColor;\r\nin vec2 aUV;\r\nin vec3 aNormal;\r\n\r\nin vec3 particlePos;\r\nin vec3 particleRotation;\r\nin float particleSize;\r\n\r\nuniform mat4 uTransformM;\r\nuniform mat4 uTransformVP;\r\nuniform mat4 uTransformMVP;\r\nuniform mat4 uTransformM_IT;\r\n\r\nout vec4 vColor;\r\nout vec4 vPos;\r\nout vec2 vUV;\r\nout vec3 vNormal;\r\nout vec3 vWorldPos;\r\n\r\n#define PI (3.14159265358979323846264338327950288419716939937510)\r\n\r\nvec4 from_euler(float x, float y, float z)\r\n{\r\n    float halfToRad = PI / 360.0;\r\n    x *= halfToRad;\r\n    z *= halfToRad;\r\n    y *= halfToRad;\r\n\r\n    float sx = sin(x);\r\n    float cx = cos(x);\r\n    float sy = sin(y);\r\n    float cy = cos(y);\r\n    float sz = sin(z);\r\n    float cz = cos(z);\r\n\r\n    vec4 q;\r\n    q[0] = sx * cy * cz - cx * sy * sz;\r\n    q[1] = cx * sy * cz + sx * cy * sz;\r\n    q[2] = cx * cy * sz - sx * sy * cz;\r\n    q[3] = cx * cy * cz + sx * sy * sz;\r\n    return q;\r\n}\r\n\r\nmat4 from_rts(vec4 q, vec3 v, vec3 s)\r\n{\r\n    mat4 m;\r\n    float x = q[0];\r\n    float y = q[1];\r\n    float z = q[2];\r\n    float w = q[3];\r\n    float x2 = x + x;\r\n    float y2 = y + y;\r\n    float z2 = z + z;\r\n\r\n    float xx = x * x2;\r\n    float xy = x * y2;\r\n    float xz = x * z2;\r\n    float yy = y * y2;\r\n    float yz = y * z2;\r\n    float zz = z * z2;\r\n    float wx = w * x2;\r\n    float wy = w * y2;\r\n    float wz = w * z2;\r\n    float sx = s[0];\r\n    float sy = s[1];\r\n    float sz = s[2];\r\n\r\n    m[0][0] = (1.0 - (yy + zz)) * sx;\r\n    m[0][1] = (xy + wz) * sx;\r\n    m[0][2] = (xz - wy) * sx;\r\n    m[0][3] = 0.0;\r\n    m[1][0] = (xy - wz) * sy;\r\n    m[1][1] = (1.0 - (xx + zz)) * sy;\r\n    m[1][2] = (yz + wx) * sy;\r\n    m[1][3] = 0.0;\r\n    m[2][0] = (xz + wy) * sz;\r\n    m[2][1] = (yz - wx) * sz;\r\n    m[2][2] = (1.0 - (xx + yy)) * sz;\r\n    m[2][3] = 0.0;\r\n    m[3][0] = v[0];\r\n    m[3][1] = v[1];\r\n    m[3][2] = v[2];\r\n    m[3][3] = 1.0;\r\n\r\n    return m;\r\n}\r\n\r\nvoid main()\r\n{\r\n    vec4 rotation = from_euler(particleRotation.x, particleRotation.y, particleRotation.z);\r\n    mat4 rts = from_rts(rotation, particlePos, vec3(particleSize));\r\n    mat4 mvp = uTransformMVP * rts;\r\n    gl_Position = mvp * vec4(aPos, 1);\r\n    vPos = gl_Position;\r\n    vColor = aColor;\r\n    vUV = aUV;\r\n    vNormal = (uTransformM_IT *  vec4(aNormal, 0)).xyz;\r\n    vWorldPos = (uTransformM * vec4(aPos, 1)).xyz;\r\n    \r\n}",s],shadow2D:["#version 300 es\r\nprecision mediump float;\r\n\r\nin vec3 aPos;\r\nin vec4 aColor;\r\nin vec2 aUV;\r\nin vec3 aNormal;\r\nin vec2 aP0;\r\nin vec2 aP1;\r\n\r\nuniform mat4 uTransformM;\r\nuniform mat4 uTransformVP;\r\nuniform mat4 uTransformMVP;\r\nuniform mat4 uTransformM_IT;\r\n\r\nout vec4 vColor;\r\nout vec4 vPos;\r\nout vec2 vUV;\r\nout vec3 vNormal;\r\nout vec3 vP;\r\nout vec2 vP0;\r\nout vec2 vP1;\r\n\r\nvoid main()\r\n{\r\n    gl_Position = uTransformMVP * vec4(aPos, 1);\r\n    vPos = gl_Position;\r\n    vColor = aColor;\r\n    vUV = aUV;\r\n    vNormal = (uTransformM_IT *  vec4(aNormal, 0)).xyz;\r\n    vP = aPos;\r\n    vP0 = aP0;\r\n    vP1 = aP1;\r\n    \r\n}","#version 300 es\r\nprecision mediump float;\r\n\r\nin vec4 vPos;\r\nin vec2 vP0;\r\nin vec2 vP1;\r\nin vec3 vP;\r\n\r\nuniform vec2 uLightPos;\r\nuniform float uVolumnSize;\r\nuniform float uLightRange;\r\n\r\nout float fragColor;\r\n\r\n#define PI (3.14)\r\n\r\n// See: https://www.geogebra.org/geometry/ysvegxsz\r\n\r\nbool circleTangent(vec2 p, vec2 center, float radius, out vec2 p1, out vec2 p2)\r\n{\r\n    float r2 = radius * radius;\r\n    float d2 = (p.x - center.x) * (p.x - center.x) + (p.y - center.y) * (p.y - center.y);\r\n    if (d2 < r2)\r\n        return false;\r\n\r\n    vec2 p0 = p - center;\r\n    p1 = vec2(r2 / d2) * p0 + vec2(radius / d2 * sqrt(d2 - r2)) * vec2(-p0.y, p0.x);\r\n    p2 = vec2(r2 / d2) * p0 - vec2(radius / d2 * sqrt(d2 - r2)) * vec2(-p0.y, p0.x);\r\n    p1 += center;\r\n    p2 += center;\r\n    return true;\r\n}\r\n\r\nfloat cross2(vec2 u, vec2 v)\r\n{\r\n\treturn cross(vec3(u, 0.0), vec3(v, 0.0)).z;\r\n}\r\nfloat saturate(float x)\r\n{\r\n    return clamp(x, 0.0, 1.0);\r\n    // return min(max(x, 0.0), 1.0);\r\n    if (x <= 0.0)\r\n        return 0.0;\r\n    else if (x >= 1.0)\r\n        return 1.0;\r\n    return x;\r\n}\r\n// Fix undefined result when x > 1\r\nfloat fixacos(float x) {\r\n    if (x >= 1.0)\r\n        return 0.0;\r\n    return acos(x);\r\n}\r\n\r\nvoid main()\r\n{\r\n    vec2 p = vP.xy;\r\n    vec2 p1, p2;\r\n    // p1 = uLightPos.xy;\r\n    // p2 = uLightPos.xy;\r\n    circleTangent(p, vec2(0), uVolumnSize, p1, p2);\r\n    vec2 right = normalize(p1 - p);\r\n    vec2 left = normalize(p2 - p);\r\n    vec2 u = normalize(vP1 - p);\r\n    vec2 v = normalize(vP0 - p);\r\n    if(cross2(v, u) < 0.0)\r\n    {\r\n        vec2 t = v;\r\n        v = u;\r\n        u = t;\r\n    }\r\n    \r\n\tfloat leftLeak = saturate(sign(cross2(u, left))) * fixacos(dot(u, left));\r\n\tfloat rightLeak = saturate(sign(cross2(right, v))) * fixacos(dot(right, v));\r\n    float total = acos(dot(right, left));\r\n\r\n\r\n    fragColor = 1.0 - (leftLeak + rightLeak) / total;\r\n}"],light2D:["// #version 300 es\r\nprecision mediump float;\r\n\r\nattribute vec3 aPos;\r\nattribute vec4 aColor;\r\nattribute vec2 aUV;\r\nattribute vec3 aNormal;\r\n\r\nuniform mat4 uTransformM;\r\nuniform mat4 uTransformVP;\r\nuniform mat4 uTransformMVP;\r\nuniform mat4 uTransformM_IT;\r\n\r\nvarying vec4 vColor;\r\nvarying vec4 vPos;\r\nvarying vec2 vUV;\r\nvarying vec3 vNormal;\r\nvarying vec3 vWorldPos;\r\n\r\nvoid main()\r\n{\r\n    gl_Position = uTransformMVP * vec4(aPos, 1);\r\n    vPos = gl_Position;\r\n    vColor = aColor;\r\n    vUV = aUV;\r\n    vNormal = (uTransformM_IT *  vec4(aNormal, 0)).xyz;\r\n    vWorldPos = (uTransformM * vec4(aPos, 1)).xyz;\r\n    \r\n}","// #version 300 es\r\nprecision mediump float;\r\n\r\n#define MAX_LIGHT 4\r\n\r\nvarying vec2 vUV;\r\n\r\nuniform vec4 uLightPosList[MAX_LIGHT];\r\nuniform vec4 uLightColorList[MAX_LIGHT];\r\nuniform vec4 uLightParamsList[MAX_LIGHT]; // (volumn, range, attenuation, intensity)\r\nuniform sampler2D uShadowMapList[MAX_LIGHT];\r\nuniform int uLightCount;\r\nuniform vec4 uCameraParams; // (pos.x, pos.y, viewWidth, viewHgith)\r\nuniform vec4 uAmbientLightColor;\r\n\r\n// out vec4 fragColor;\r\n\r\nfloat lightAttenuation(float r, float attenuation)\r\n{\r\n    if(attenuation <= -1.0)\r\n        return 0.0;\r\n    else if (attenuation <= 0.0)\r\n    {\r\n        float t = 1.0 / (attenuation + 1.0) - 1.0;\r\n        return exp(-r * t) - exp(-t) * r;\r\n    }\r\n    else if (attenuation < 1.0)\r\n    {\r\n        float t = 1.0 / (1.0 - attenuation) - 1.0;\r\n        r = 1.0 - r;\r\n        return 1.0 - (exp(-r * t) - exp(-t) * r);\r\n    }\r\n    else {\r\n        return r >= 1.0 ? 0.0 : 1.0;\r\n    }\r\n}\r\n\r\nvoid main()\r\n{\r\n    vec2 worldPos = (vUV - vec2(0.5)) * uCameraParams.zw + uCameraParams.xy;\r\n    for (int i = 0; i < MAX_LIGHT; i++)\r\n    {\r\n        float r = distance(uLightPosList[i].xy, worldPos);\r\n        r -= uLightParamsList[i].x;\r\n        r = r / (uLightParamsList[i].y -  uLightParamsList[i].x);\r\n        float light = lightAttenuation(clamp(r, 0.0, 1.0), uLightParamsList[i].z);\r\n        light *= uLightParamsList[i].w;\r\n        float shadow = texture2D(uShadowMapList[i], vUV.xy).r;\r\n        light *= 1.0 - shadow;\r\n        \r\n        gl_FragColor += vec4(light) * uLightColorList[i].rgba;\r\n    }\r\n    gl_FragColor += uAmbientLightColor;\r\n    \r\n}"],light2DSimple:["#version 300 es\r\nprecision mediump float;\r\n\r\nin vec3 aPos;\r\nin vec2 aUV;\r\nin vec4 aLightColor;\r\nin vec4 aLightParams; // (volumn, range, attenuation, intensity)\r\nin vec3 aLightPos;\r\n\r\nuniform mat4 uTransformMVP;\r\n\r\nout vec4 vLightColor;\r\nout vec4 vLightParams; \r\nout vec3 vLightPos;\r\nout vec4 vPos;\r\nout vec2 vUV;\r\n\r\nvoid main()\r\n{\r\n    gl_Position = uTransformMVP * vec4(aPos.xy * vec2(aLightParams.y) + aLightPos.xy, 0, 1);\r\n    vPos = gl_Position;\r\n    vUV = aUV;\r\n    vLightParams = aLightParams;\r\n    vLightColor = aLightColor;\r\n    vLightPos = aLightPos;\r\n}","#version 300 es\r\nprecision mediump float;\r\n\r\nin vec4 vLightColor;\r\nin vec4 vLightParams; // (volumn, range, attenuation, intensity)\r\nin vec4 vPos;\r\nin vec2 vUV;\r\n\r\nout vec4 fragColor;\r\n\r\nfloat lightAttenuation(float r, float range, float volumn, float attenuation)\r\n{\r\n    r -= volumn;\r\n    r /= range - volumn;\r\n    if(attenuation <= -1.0)\r\n        return 0.0;\r\n    else if (attenuation <= 0.0)\r\n    {\r\n        float t = 1.0 / (attenuation + 1.0) - 1.0;\r\n        return exp(-r * t) - exp(-t) * r;\r\n    }\r\n    else if (attenuation < 1.0)\r\n    {\r\n        float t = 1.0 / (1.0 - attenuation) - 1.0;\r\n        r = 1.0 - r;\r\n        return 1.0 - (exp(-r * t) - exp(-t) * r);\r\n    }\r\n    else {\r\n        return r >= 1.0 ? 0.0 : 1.0;\r\n    }\r\n}\r\n\r\nvoid main()\r\n{\r\n    float r = length(vUV * vec2(2) - vec2(1)) * vLightParams.y;\r\n    float attenuation = lightAttenuation(r, vLightParams.y, vLightParams.x, vLightParams.z);\r\n    attenuation = max(attenuation, 0.0);\r\n    attenuation *= vLightParams.w;\r\n    vec3 color = vLightColor.rgb * vec3(attenuation);\r\n\r\n    fragColor = vec4(color, 1);\r\n    // fragColor = vec4(1);\r\n}"],boxBlur:[i,"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec4 vColor;\r\nin vec4 vPos;\r\nin vec2 vUV;\r\n\r\nuniform sampler2D uMainTex;\r\nuniform vec4 uTexSize; // (w, h, 1/w, 1/h)\r\nuniform float uSampleOffset;\r\n\r\nout vec4 fragColor;\r\n\r\nvoid main()\r\n{\r\n    vec2 delta = vec2(-uSampleOffset, uSampleOffset);\r\n    vec4 color = \r\n      texture(uMainTex, clamp(vUV.xy + uTexSize.zw * delta.xx, vec2(0), vec2(1)))\r\n    + texture(uMainTex, clamp(vUV.xy + uTexSize.zw * delta.yx, vec2(0), vec2(1)))\r\n    + texture(uMainTex, clamp(vUV.xy + uTexSize.zw * delta.yy, vec2(0), vec2(1)))\r\n    + texture(uMainTex, clamp(vUV.xy + uTexSize.zw * delta.xy, vec2(0), vec2(1)));\r\n\r\n    color /= vec4(4.0);\r\n\r\n    fragColor = color.rgba;\r\n}"],bloomFilter:[i,"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec2 vUV;\r\nuniform sampler2D uMainTex;\r\nuniform float uThreshold;\r\nuniform float uSoftThreshold;\r\n\r\nout vec4 fragColor;\r\n\r\n// Ref: https://catlikecoding.com/unity/tutorials/advanced-rendering/bloom/\r\nvoid main()\r\n{\r\n    vec3 color =  texture(uMainTex, vUV).rgb;\r\n    float brightness = max(color.r, max(color.g, color.b));\r\n    float knee = uThreshold * uSoftThreshold;\r\n    float soft = brightness - uThreshold + knee;\r\n    soft = clamp(soft, 0.0, 2.0 * knee);\r\n    soft = soft * soft / (4.0 * knee + 0.00001);\r\n\r\n    float contribution = max(soft, brightness - uThreshold);\r\n\tcontribution /= max(brightness, 0.00001);\r\n\r\n    color = contribution * color;\r\n\r\n\r\n\r\n    fragColor = vec4(color.rgb, 1.0);\r\n}"],bloomCompose:[i,"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec2 vUV;\r\n\r\nuniform sampler2D uMainTex;\r\nuniform float uIntensity;\r\n\r\nout vec4 fragColor;\r\n\r\nvoid main()\r\n{\r\n    fragColor = vec4(texture(uMainTex, vUV).rgb * vec3(uIntensity), 1.0);\r\n}"],blitCopy:[i,"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec2 vUV;\r\nuniform sampler2D uMainTex;\r\n\r\nout vec4 fragColor;\r\n\r\nvoid main()\r\n{\r\n    fragColor = texture(uMainTex, vUV).rgba;\r\n}"]}},function(t,e,r){"use strict";var n=Object.defineProperty;n(e,"__esModule",{value:!0}),((t,e)=>{for(var r in e)n(t,r,{get:e[r],enumerable:!0})})(e,{BuiltinShaderSources:()=>i});var i={defaultVert:"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec3 aPos;\r\nin vec4 aColor;\r\nin vec2 aUV;\r\nin vec3 aNormal;\r\n\r\nuniform mat4 uTransformM;\r\nuniform mat4 uTransformVP;\r\nuniform mat4 uTransformMVP;\r\n\r\nout vec4 vColor;\r\nout vec4 vPos;\r\nout vec2 vUV;\r\nout vec3 vNormal;\r\n\r\nvoid main()\r\n{\r\n    gl_Position = uTransformMVP * vec4(aPos, 1);\r\n    vColor = aColor;\r\n    vUV = aUV;\r\n    vNormal = aNormal;\r\n}",defaultFrag:"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec4 vColor;\r\nin vec4 vPos;\r\nin vec2 vUV;\r\n\r\nuniform sampler2D uMainTex;\r\nuniform vec4 uColor;\r\n\r\nout vec4 fragColor;\r\n\r\nvoid main()\r\n{\r\n    vec4 color = texture(uMainTex, vUV.xy).rgba;\r\n    color = color * vColor * uColor;\r\n    fragColor = color;\r\n}",blitCopy:"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec4 vColor;\r\nin vec4 vPos;\r\nin vec2 vUV;\r\nin vec3 vNormal;\r\n\r\nuniform sampler2D uMainTex;\r\n\r\nout vec4 fragColor;\r\n\r\nvoid main()\r\n{\r\n    fragColor = texture(uMainTex, vUV).rgba;\r\n}",colorFrag:"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec4 vColor;\r\nin vec4 vPos;\r\n\r\nout vec4 fragColor;\r\n\r\nvoid main()\r\n{\r\n    fragColor = vColor;\r\n}",colorVert:"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec3 aPos;\r\nin vec4 aColor;\r\n\r\nuniform mat4 uTransformM;\r\nuniform mat4 uTransformVP;\r\nuniform mat4 uTransformMVP;\r\n\r\nout vec4 vColor;\r\nout vec4 vPos;\r\n\r\nvoid main()\r\n{\r\n    gl_Position = uTransformMVP * vec4(aPos, 1);\r\n    vColor = aColor;\r\n}",flipVert:"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec3 aPos;\r\nin vec2 aUV;\r\n\r\nout vec2 vUV;\r\n\r\nvoid main()\r\n{\r\n    gl_Position = vec4(aPos, 1);\r\n    vUV = vec2(aUV.x, vec2(1) - aUV.y);\r\n}",texFrag:"#version 300 es\r\nprecision mediump float;\r\n\r\nin vec4 vPos;\r\nin vec2 vUV;\r\n\r\nuniform sampler2D uMainTex;\r\n\r\nout vec4 fragColor;\r\n\r\nvoid main()\r\n{\r\n    fragColor = texture(uMainTex, vUV).rgba;\r\n}"}},function(t,e,r){"use strict";r.d(e,"a",(function(){return s}));var n=r(6),i=r(0);class s{constructor(t,e){this.min=t,this.max=Object(n.j)(t,e)}get xMin(){return this.min.x}get yMin(){return this.min.y}get xMax(){return this.max.x}get yMax(){return this.max.y}get size(){return Object(n.h)(this.max,this.min)}get center(){return Object(n.j)(this.min,this.max).mul(Object(i.b)(.5))}shrink(t){let e=Object(n.j)(this.min,Object(i.b)(t)),r=Object(n.h)(this.max,Object(i.b)(t));return e.x>r.x&&(e.x=r.x=(e.x+r.x)/2),e.y>r.y&&(e.y=r.y=(e.y+r.y)/2),new s(e,r.minus(e))}expand(t){return new s(Object(n.h)(this.min,Object(i.b)(t)),Object(n.j)(this.size,Object(i.b)(2*t)))}static box01(){return new s(i.b.zero(),i.b.one())}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return u})),r.d(e,"b",(function(){return c}));var n=r(4),i=r(1),s=r(6),o=r(2);const a=Array;class u extends a{static create(){return new u(0,0,0,0)}asMut(){return this}equals(t){return!!(t&&t instanceof Array)&&n.c.exactEquals(this,t)}clone(t=u.create()){return t.set(this)}set(t){return this[0]=t[0]||0,this[1]=t[1]||0,this[2]=t[2]||0,this[3]=t[3]||0,this}fill(t){return this[0]=t,this[1]=t,this[2]=t,this[3]=t,this}}function c(t=0,e=t,r=t,n=t){return new u(t,e,r,n)}c.create=()=>c(0),c.identity=Object(o.b)(n.c.identity,0,c.create),c.axisAngle=Object(o.b)((t,e,r)=>n.c.setAxisAngle(t,e,r),2,c.create),c.mul=Object(o.b)(n.c.mul,2,c.create),c.invert=Object(o.b)(n.c.invert,1,c.create),c.normalize=Object(o.b)(n.c.normalize,1,c.create),c.euler=Object(o.b)((t,e)=>(t[0]=Math.atan2(2*(e[3]*e[0]+e[1]*e[2]),1-2*(e[0]**2+e[1]**2))*s.b,t[1]=Math.asin(2*(e[3]*e[1]-e[2]*e[0]))*s.b,t[2]=Math.atan2(2*(e[3]*e[2]+e[0]*e[1]),1-2*(e[1],e[2]**2))*s.b,t),1,i.b.zero),c.fromEuler=Object(o.b)((t,e)=>n.c.fromEuler(t,e[0],e[1],e[2]),1,c.create),c.rotate=Object(o.b)((t,e,r)=>n.e.transformQuat(t,r,e),2,i.b.zero),c.equals=(t,e)=>n.c.exactEquals(t,e)},function(t,e,r){"use strict";r.d(e,"a",(function(){return s})),r.d(e,"b",(function(){return o}));var n=r(10),i=r(3);const s={from(t){const e={float:1,vec2:2,vec3:3,vec4:4,mat4:16},r={elements:[],byteSize:0,totalSize:0};let n=0;for(const i in t){const s={key:i,type:t[i],location:n,length:e[t[i]]};s.byteLength=4*s.length,s.offset=r.totalSize,s.byteOffset=r.byteSize,r.totalSize+=s.length,r.byteSize+=s.byteLength,r.elements.push(s),n+="mat4"===t[i]?4:1}return r}};class o extends Array{constructor(t,e,r=Object(i.d)()){super(e),this.static=!0,this.Data=null,this.dirty=!1,this.initialized=!1,this.glBuf=null,this.swapBuffer=null,this.structure=s.from(t),this.ctx=r,this.buffer=null,this.resize(e),this.tryInit(!1)}get byteLength(){return this.length*this.structure.byteSize}resize(t,e=!0){const r=this.buffer;this.buffer=new Float32Array(this.structure.totalSize*t),e&&r&&(r.length>this.buffer.length?this.buffer.set(new Float32Array(r.buffer,0,this.buffer.length)):this.buffer.set(r,0)),this.length=t;for(let t=0;t<this.length;t++){const e={};for(const r of this.structure.elements){const n=t*this.structure.byteSize+r.byteOffset;switch(r.type){case"float":e[r.key]=new Float32Array(this.buffer.buffer,n,1);break;case"vec2":e[r.key]=new Float32Array(this.buffer.buffer,n,2);break;case"vec3":e[r.key]=new Float32Array(this.buffer.buffer,n,3);break;case"vec4":e[r.key]=new Float32Array(this.buffer.buffer,n,4);break;case"mat4":e[r.key]=new Float32Array(this.buffer.buffer,n,16)}}this[t]=e}this.dirty=!0}swapVertices(t,e){this.swapBuffer||(this.swapBuffer=new Float32Array(this.structure.totalSize));const r=t*this.structure.byteSize,n=e*this.structure.byteSize;let i=this.swapBuffer,s=new Float32Array(this.buffer.buffer,r,this.structure.totalSize);i.set(s);const o=new Float32Array(this.buffer.buffer,n,this.structure.totalSize);this.buffer.set(o,t*this.structure.totalSize),this.buffer.set(i,e*this.structure.totalSize)}markDirty(){this.dirty=!0}upload(t=!1){if(this.tryInit(!0),!this.dirty&&!t&&this.static)return!1;const e=this.ctx.gl;return e.bindBuffer(e.ARRAY_BUFFER,this.glBuf),e.bufferData(e.ARRAY_BUFFER,this.buffer,this.static?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.dirty=!1,!0}bind(){this.tryInit(!0);const t=this.ctx.gl;this.upload(),t.bindBuffer(t.ARRAY_BUFFER,this.glBuf)}bindVertexArray(t=!1,e){this.tryInit(!0);const r=this.ctx.gl;this.upload(),r.bindBuffer(r.ARRAY_BUFFER,this.glBuf);for(const n of this.structure.elements){const i=e?e[n.key]||-1:n.location;i<0||("mat4"===n.type?(r.enableVertexAttribArray(i+0),r.enableVertexAttribArray(i+1),r.enableVertexAttribArray(i+2),r.enableVertexAttribArray(i+3),r.vertexAttribPointer(i+0,4,r.FLOAT,!1,this.structure.byteSize,n.byteOffset+0),r.vertexAttribPointer(i+1,4,r.FLOAT,!1,this.structure.byteSize,n.byteOffset+1),r.vertexAttribPointer(i+2,4,r.FLOAT,!1,this.structure.byteSize,n.byteOffset+2),r.vertexAttribPointer(i+3,4,r.FLOAT,!1,this.structure.byteSize,n.byteOffset+3),t&&(r.vertexAttribDivisor(i+0,1),r.vertexAttribDivisor(i+1,1),r.vertexAttribDivisor(i+2,1),r.vertexAttribDivisor(i+3,1))):(r.enableVertexAttribArray(i),r.vertexAttribPointer(i,n.length,r.FLOAT,!1,this.structure.byteSize,n.byteOffset),t&&r.vertexAttribDivisor(i,1)))}}unbindVertexArray(t=!1,e){this.tryInit(!0);const r=this.ctx.gl;for(const n of this.structure.elements){const i=e?e[n.key]||-1:n.location;i<0||("mat4"===n.type?(r.disableVertexAttribArray(i+0),r.disableVertexAttribArray(i+1),r.disableVertexAttribArray(i+2),r.disableVertexAttribArray(i+3),t&&(r.vertexAttribDivisor(i+0,0),r.vertexAttribDivisor(i+1,0),r.vertexAttribDivisor(i+2,0),r.vertexAttribDivisor(i+3,0))):(r.disableVertexAttribArray(i),t&&r.vertexAttribDivisor(i,0)))}}unbind(){this.tryInit(!0);const t=this.ctx.gl;t.bindBuffer(t.ARRAY_BUFFER,null),t.bindVertexArray(null)}tryInit(t=!1){var e;if(this.initialized)return!0;const r=this.ctx||Object(i.d)();if(!r){if(t)throw new Error("Failed to init render buffer without a global GL context.");return!1}this.ctx=r;const s=r.gl;return this.glBuf=null!==(e=s.createBuffer())&&void 0!==e?e:Object(n.c)("Failed to create render buffer"),s.bindBuffer(s.ARRAY_BUFFER,this.glBuf),s.bufferData(s.ARRAY_BUFFER,this.byteLength,this.static?s.STATIC_DRAW:s.DYNAMIC_DRAW),s.bindBuffer(s.ARRAY_BUFFER,null),this.initialized=!0,!0}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return c})),r.d(e,"b",(function(){return h}));var n=r(0),i=r(1),s=r(11),o=r(6),a=r(3),u=r(16);class c{constructor(t=16,e=3*t,r=u.a,n=Object(a.d)()){this.verticesCount=0,this.indicesCount=0,this.mesh=new u.c(r,n),this.mesh.resize(t,e)}addPolygon(...t){if(t.length<=0)return;this.verticesCount+t.length>this.mesh.vertices.length&&this.mesh.resize(2*this.mesh.vertices.length,2*this.mesh.indices.length,!0);const e=this.verticesCount;for(const r in t[0])for(let n=0;n<t.length;n++)this.mesh.vertices[e+n][r].set(t[n][r]);for(let r=0;r<t.length-2;r++)this.mesh.indices[this.indicesCount+3*r+0]=e+0,this.mesh.indices[this.indicesCount+3*r+1]=e+r+1,this.mesh.indices[this.indicesCount+3*r+2]=e+r+2;this.verticesCount+=t.length,this.indicesCount+=3*(t.length-2)}toMesh(){return this.mesh.indices.length!=this.indicesCount?this.mesh.resize(this.verticesCount,this.indicesCount,!0):this.mesh.vertices.length!=this.verticesCount&&this.mesh.vertices.resize(this.verticesCount,!0),this.mesh}static quad(t=n.b.zero(),e=n.b.one(),r=Object(a.d)()){const i=n.b.mul(e,.5),s=new u.c(r);return s.resize(4,6),s.vertices[0].vert.set([t.x-i.x,t.y-i.y,0]),s.vertices[1].vert.set([t.x+i.x,t.y-i.y,0]),s.vertices[2].vert.set([t.x+i.x,t.y+i.y,0]),s.vertices[3].vert.set([t.x-i.x,t.y+i.y,0]),s.vertices[0].uv.set([0,0]),s.vertices[1].uv.set([1,0]),s.vertices[2].uv.set([1,1]),s.vertices[3].uv.set([0,1]),s.vertices[0].normal.set([0,0,1]),s.vertices[1].normal.set([0,0,1]),s.vertices[2].normal.set([0,0,1]),s.vertices[3].normal.set([0,0,1]),s.vertices[0].color.fill(1),s.vertices[1].color.fill(1),s.vertices[2].color.fill(1),s.vertices[3].color.fill(1),s.indices.set([0,1,2,0,2,3]),s}static ndcQuad(t=Object(a.d)()){return this.quad(n.b.zero(),Object(n.b)(2,2),t)}static ndcTriangle(t=Object(a.d)()){const e=new u.c(t);return e.resize(3,3),e.vertices[0].vert.set([-1,-1,0]),e.vertices[1].vert.set([3,-1,0]),e.vertices[2].vert.set([-1,3,0]),e.vertices[0].uv.set([0,0]),e.vertices[1].uv.set([2,0]),e.vertices[2].uv.set([0,2]),e.vertices[0].normal.set([0,0,1]),e.vertices[1].normal.set([0,0,1]),e.vertices[2].normal.set([0,0,1]),e.vertices[0].color.fill(1),e.vertices[1].color.fill(1),e.vertices[2].color.fill(1),e.indices.set([0,1,2]),e.name="mesh_ndc_triangle",e}static cube(t=i.b.zero(),e=i.b.one(),r){const s=[Object(i.b)(-.5,-.5,-.5).mul(e).plus(t),Object(i.b)(.5,-.5,-.5).mul(e).plus(t),Object(i.b)(.5,.5,-.5).mul(e).plus(t),Object(i.b)(-.5,.5,-.5).mul(e).plus(t),Object(i.b)(-.5,-.5,.5).mul(e).plus(t),Object(i.b)(.5,-.5,.5).mul(e).plus(t),Object(i.b)(.5,.5,.5).mul(e).plus(t),Object(i.b)(-.5,.5,.5).mul(e).plus(t)],o=[Object(n.b)(0,0),Object(n.b)(1,0),Object(n.b)(1,1),Object(n.b)(0,1)],a=new c(24,36,u.a,r);a.addPolygon({vert:s[1],uv:o[0],normal:Object(i.b)(0,0,-1)},{vert:s[0],uv:o[1],normal:Object(i.b)(0,0,-1)},{vert:s[3],uv:o[2],normal:Object(i.b)(0,0,-1)},{vert:s[2],uv:o[3],normal:Object(i.b)(0,0,-1)}),a.addPolygon({vert:s[5],uv:o[0],normal:Object(i.b)(1,0,0)},{vert:s[1],uv:o[1],normal:Object(i.b)(1,0,0)},{vert:s[2],uv:o[2],normal:Object(i.b)(1,0,0)},{vert:s[6],uv:o[3],normal:Object(i.b)(1,0,0)}),a.addPolygon({vert:s[4],uv:o[0],normal:Object(i.b)(0,0,1)},{vert:s[5],uv:o[1],normal:Object(i.b)(0,0,1)},{vert:s[6],uv:o[2],normal:Object(i.b)(0,0,1)},{vert:s[7],uv:o[3],normal:Object(i.b)(0,0,1)}),a.addPolygon({vert:s[0],uv:o[0],normal:Object(i.b)(-1,0,0)},{vert:s[4],uv:o[1],normal:Object(i.b)(-1,0,0)},{vert:s[7],uv:o[2],normal:Object(i.b)(-1,0,0)},{vert:s[3],uv:o[3],normal:Object(i.b)(-1,0,0)}),a.addPolygon({vert:s[7],uv:o[0],normal:Object(i.b)(0,1,0)},{vert:s[6],uv:o[1],normal:Object(i.b)(0,1,0)},{vert:s[2],uv:o[2],normal:Object(i.b)(0,1,0)},{vert:s[3],uv:o[3],normal:Object(i.b)(0,1,0)}),a.addPolygon({vert:s[0],uv:o[0],normal:Object(i.b)(0,-1,0)},{vert:s[1],uv:o[1],normal:Object(i.b)(0,-1,0)},{vert:s[5],uv:o[2],normal:Object(i.b)(0,-1,0)},{vert:s[4],uv:o[3],normal:Object(i.b)(0,-1,0)});const h=a.toMesh();return h.vertices.forEach(t=>t.color.fill(1)),h.name="mesh_cube",h}}class h{constructor(t=0,e=Object(a.d)()){this.verts=[],this.triangles=[],this.uvs=[],this.colors=[],this.ctx=e}addPolygon(t,e){const r=this.verts.length;for(let r=0;r<t.length;r++)this.verts.push(t[r]),this.uvs.push(e[r]),this.colors.push(s.a.white);for(let e=2;e<t.length;e++)this.triangles.push(r+0,r+e-1,r+e)}addSubMesh(t,e,r=[s.a.white],i=[Object(n.b)(0,0)]){const o=this.verts.length;if(e.length%3!=0)throw new Error("Invalid number of triangles.");for(let e=0;e<t.length;e++)this.verts.push(t[e]),this.uvs.push(e>=i.length?i[i.length-1]:i[e]),this.colors.push(e>=r.length?r[r.length-1]:r[e]);for(let t=0;t<e.length;t++)this.triangles.push(o+e[t])}toMesh(){const t=new u.c(this.ctx);return t.verts=this.verts,t.triangles=this.triangles,t.colors=this.colors,t.uvs=this.uvs,t.calculateNormals(),t}static quad(t=n.b.zero(),e=n.b.one()){const r=Object(o.i)(e,Object(n.b)(.5)),s=new u.c;return s.verts=[Object(i.b)(t.x-r.x,t.y-r.y,0),Object(i.b)(t.x+r.x,t.y-r.y,0),Object(i.b)(t.x+r.x,t.y+r.y,0),Object(i.b)(t.x-r.x,t.y+r.y,0)],s.triangles=[0,1,3,1,2,3],s.uvs=[Object(n.b)(0,0),Object(n.b)(1,0),Object(n.b)(1,1),Object(n.b)(0,1)],s.normals=[Object(i.b)(0,0,1),Object(i.b)(0,0,1),Object(i.b)(0,0,1),Object(i.b)(0,0,1)],s.name="mesh_quad",s}static ndcQuad(){return this.quad(n.b.zero(),Object(n.b)(2,2))}static ndcTriangle(){const t=new u.c;return t.verts=[Object(i.b)(-1,-1,0),Object(i.b)(3,-1,0),Object(i.b)(-1,3,0)],t.triangles=[0,1,2],t.uvs=[Object(n.b)(0,0),Object(n.b)(2,0),Object(n.b)(0,2)],t.normals=[Object(i.b)(0,0,1),Object(i.b)(0,0,1),Object(i.b)(0,0,1)],t.name="mesh_ndc_triangle",t}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return o})),r.d(e,"b",(function(){return a}));var n=r(47),i=r(15),s=r(28);class o extends n.a{constructor(){super(...arguments),this.assetID=i.b.newAssetID(this),this.name="Entity_"+this.assetID,this.eventEmitter=new s.a,this._destroyed=!1,this._collider=null}get collider(){return this._collider}set collider(t){this.scene&&t&&t.__bind(this,this.scene),this._collider&&this._collider!==t&&this._collider.__unbind(),this._collider=t}get destroyed(){return this._destroyed}on(t,e){return this.eventEmitter.on(t,e)}off(t,e){this.eventEmitter.off(t,e)}destroy(){this._destroyed=!0,this.scene?this.scene.remove(this):i.b.destroy(this.assetID)}start(t){}update(t){}exit(t){}__updateRecursive(t){this.update(t),this.eventEmitter.emit("update",this,t);for(const e of this.children)e.__updateRecursive(t)}__addToScene(t){var e;super.__addToScene(t),null===(e=this._collider)||void 0===e||e.__bind(this,t)}__removeFromScene(t){var e;super.__removeFromScene(t),null===(e=this._collider)||void 0===e||e.__unbindPhysics()}__start(t){this.start(t),this.eventEmitter.with().emit("start",this,t)}__exit(t){this.exit(t),this.eventEmitter.with().emit("exit",this,t),this._destroyed&&i.b.destroy(this.assetID)}}class a{constructor(){this.entityMap=new Map,this._entities=[]}get entities(){return this._entities}add(t){this.entityMap.set(t.assetID,t),this._entities=Array.from(this.entityMap.values())}removeRecursive(t){this.entityMap.delete(t.assetID);for(const e of t.children)this.removeRecursive(e)}remove(t){this.removeRecursive(t),t.parent&&t.parent.children.delete(t),this._entities=Array.from(this.entityMap.values())}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return n}));class n{setup(t,e){}cleanup(t,e){}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return s}));var n=r(3),i=r(25);class s extends i.a{constructor(t=Object(n.d)()){super(),this.meshes=[],this.materials=[],this.materials=[t.assets.materials.default]}on(t,e){this.eventEmitter.with().on(t,e)}off(t,e){this.eventEmitter.with().off(t,e)}render(t,e){this.eventEmitter.with().emit("render",this,t,e);for(let e=0;e<this.meshes.length;e++)t.renderer.drawMesh(this.meshes[e],this.localToWorldMatrix,this.materials[e])}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return n}));class n{constructor(){this.listeners=new Map}on(t,e){var r;this.listeners.has(t)||this.listeners.set(t,[]),null===(r=this.listeners.get(t))||void 0===r||r.push(e)}off(t,e){var r,n;this.listeners.has(t)&&this.listeners.set(t,null!==(n=null===(r=this.listeners.get(t))||void 0===r?void 0:r.filter(t=>t!==e))&&void 0!==n?n:[])}emit(t,...e){var r;null===(r=this.listeners.get(t))||void 0===r||r.forEach(t=>t(...e))}with(){return this}}},function(t,e,r){"use strict";r.d(e,"b",(function(){return n})),r.d(e,"a",(function(){return o}));var n,i=r(27),s=r(9);!function(t){t[t.NearToFar=0]="NearToFar",t[t.FarToNear=1]="FarToNear"}(n||(n={}));const o={create:(t,e,r)=>({camera:t,scene:e,cameraOutput:r,visibleObjects:e.getEntitiesOfType(i.a),getVisibleObjects(t=n.NearToFar,e){const r=this.camera.worldToLocalMatrix;let i=this.visibleObjects;e&&(i=i.filter(e));let o=i.map(t=>({pos:s.b.mulPoint(r,t.position),obj:t}));return o=t===n.NearToFar?o.sort((t,e)=>e.pos.z-t.pos.z):o.sort((t,e)=>t.pos.z-e.pos.z),o.map(t=>t.obj)}})}},function(t,e,r){"use strict";r.d(e,"a",(function(){return u}));var n=r(0),i=r(44),s=r(40),o=r(35),a=r(32);class u extends o.a{constructor(){super(...arguments),this._tilemap=null}get tilemap(){return this._tilemap}__bind(t,e){super.__bind(t,e),t instanceof i.b&&(this._tilemap=t)}checkCollision(t,e){return t instanceof s.a?Object(a.a)(this,t,e):(console.warn("Unimplemented collision check"),null)}checkContact(t){return t instanceof s.a?Object(a.b)(this,t):(console.warn("Unimplemented contact check"),!1)}getPolygons(t,e){if(!this.tilemap)return null;const r=n.b.zero(),i=[];for(let n=t.y;n<e.y+this.tilemap.chunkSize;n+=this.tilemap.chunkSize)for(let s=t.x;s<e.x+this.tilemap.chunkSize;s+=this.tilemap.chunkSize){r.x=s,r.y=n;const t=this.tilemap.getChunkAt(r);i.push(...t.getPolygons())}return i}}},function(t,e,r){"use strict";r.d(e,"b",(function(){return n})),r.d(e,"a",(function(){return h})),r.d(e,"c",(function(){return l}));var n,i=r(0),s=r(3),o=r(6);class a{constructor(t){this.currentIdx=0,this.buffers=[t(),t()]}get current(){return this.buffers[this.currentIdx%2]}set current(t){this.buffers[this.currentIdx%2]=t}get back(){return this.buffers[(this.currentIdx+1)%2]}set back(t){this.buffers[(this.currentIdx+1)%2]=t}update(){this.currentIdx++}}!function(t){t[t.Pressed=1]="Pressed",t[t.Released=0]="Released"}(n||(n={}));const u={getBoundingClientRect:()=>({x:0,y:0,left:0,top:0,right:document.documentElement.clientWidth||window.innerWidth,bottom:document.documentElement.clientHeight||window.innerHeight,width:document.documentElement.clientWidth||window.innerWidth,height:document.documentElement.clientHeight||window.innerHeight})};class c{constructor(){this.keyStates=new Map,this.keyStatesThisFrame=new Map,this.mousePos=i.b.zero(),this.mouseDelta=i.b.zero(),this.wheelDelta=0}}class h{constructor(t={}){var e,r,h;this.preventBrowserShortcut=!0,this.bound=null,this.states=new a(()=>new c),this.renderer=null,this.eventTarget=t.target||window,this.pointerLockElement=null!==(e=t.pointerLockElement)&&void 0!==e?e:document.body,this.renderer=t.renderer||Object(s.d)().renderer,t.bound?this.bound=t.bound:(null===(r=t.target)||void 0===r?void 0:r.getBoundingClientRect)?this.bound=t.target:this.bound=null===(h=this.renderer)||void 0===h?void 0:h.canvas,this.eventTarget.addEventListener("keydown",t=>{this.states.back.keyStates.set(t.keyCode,n.Pressed),this.states.current.keyStates.get(t.keyCode)!==n.Pressed&&this.states.back.keyStatesThisFrame.set(t.keyCode,n.Pressed),this.preventBrowserShortcut&&t.ctrlKey&&(t.keyCode==l.S||t.keyCode==l.W)&&(t.preventDefault(),t.stopPropagation())}),this.eventTarget.addEventListener("keyup",t=>{this.states.back.keyStates.set(t.keyCode,n.Released),this.states.back.keyStatesThisFrame.set(t.keyCode,n.Released)}),this.eventTarget.addEventListener("mousedown",t=>{var e;const r=null===(e=this.bound)||void 0===e?void 0:e.getBoundingClientRect();if(r){const e=Object(i.b)(r.left,null==r?void 0:r.top),n=Object(o.h)(Object(i.b)(t.clientX,t.clientY),e);if(n.x<0||n.y<0||n.x>r.width||n.y>r.height)return}this.states.back.keyStates.set(l.Mouse0+t.button,n.Pressed),this.states.current.keyStates.get(l.Mouse0+t.button)!==n.Pressed&&this.states.back.keyStatesThisFrame.set(l.Mouse0+t.button,n.Pressed)}),this.eventTarget.addEventListener("mouseup",t=>{var e;const r=null===(e=this.bound)||void 0===e?void 0:e.getBoundingClientRect();if(r){const e=Object(i.b)(r.left,null==r?void 0:r.top),n=Object(o.h)(Object(i.b)(t.clientX,t.clientY),e);if(n.x<0||n.y<0||n.x>r.width||n.y>r.height)return}this.states.back.keyStates.set(l.Mouse0+t.button,n.Released),this.states.back.keyStatesThisFrame.set(l.Mouse0+t.button,n.Released)}),this.eventTarget.addEventListener("mousemove",t=>{var e;this.renderer||(this.renderer=Object(s.d)().renderer);const r=(this.bound||(null===(e=this.renderer)||void 0===e?void 0:e.canvas)||u).getBoundingClientRect(),n=Object(o.h)(Object(i.b)(t.clientX,t.clientY),Object(i.b)(r.left,r.top));this.renderer&&n.mul(this.renderer.canvasSize).div(Object(i.b)(r.width,r.height)),this.states.back.mouseDelta.plus(Object(i.b)(t.movementX,t.movementY)),this.states.back.mousePos=n}),this.eventTarget.addEventListener("wheel",t=>{this.states.back.wheelDelta=t.deltaY});for(const t in l)isNaN(t)&&l.hasOwnProperty(t)&&this.states.back.keyStates.set(l[t],n.Released);window.addEventListener("beforeunload",t=>{!this.preventBrowserShortcut||this.states.back.keyStates.get(l.W)!==n.Pressed&&this.states.back.keyStates.get(l.Control)!==n.Pressed||(t.preventDefault(),t.returnValue="Really want to quit?")})}get pointerPosition(){return this.states.current.mousePos}get pointerDelta(){return this.states.current.mouseDelta}get wheelDelta(){return this.states.current.wheelDelta}getKey(t){return this.states.current.keyStates.get(t)===n.Pressed}getKeyDown(t){return this.states.current.keyStatesThisFrame.get(t)===n.Pressed}getKeyUp(t){return this.states.current.keyStatesThisFrame.get(t)===n.Released}update(){this.states.update(),this.states.back.keyStatesThisFrame.clear(),this.states.back.mouseDelta=i.b.zero(),this.states.back.wheelDelta=0;for(const[t,e]of this.states.current.keyStates)this.states.back.keyStates.set(t,e);this.states.back.mousePos=this.states.current.mousePos}lockPointer(){this.pointerLockElement.requestPointerLock()}releasePointer(){document.exitPointerLock()}}var l;!function(t){t[t.BackSpace=8]="BackSpace",t[t.Tab=9]="Tab",t[t.Clear=12]="Clear",t[t.Enter=13]="Enter",t[t.Shift=16]="Shift",t[t.Control=17]="Control",t[t.Alt=18]="Alt",t[t.Pause=19]="Pause",t[t.CapsLock=20]="CapsLock",t[t.Escape=27]="Escape",t[t.Space=32]="Space",t[t.Prior=33]="Prior",t[t.Next=34]="Next",t[t.End=35]="End",t[t.Home=36]="Home",t[t.Left=37]="Left",t[t.Up=38]="Up",t[t.Right=39]="Right",t[t.Down=40]="Down",t[t.Select=41]="Select",t[t.Print=42]="Print",t[t.Execute=43]="Execute",t[t.Insert=45]="Insert",t[t.Delete=46]="Delete",t[t.Help=47]="Help",t[t.Num0=48]="Num0",t[t.Num1=49]="Num1",t[t.Num2=50]="Num2",t[t.Num3=51]="Num3",t[t.Num4=52]="Num4",t[t.Num5=53]="Num5",t[t.Num6=54]="Num6",t[t.Num7=55]="Num7",t[t.Num8=56]="Num8",t[t.Num9=57]="Num9",t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.J=74]="J",t[t.K=75]="K",t[t.L=76]="L",t[t.M=77]="M",t[t.N=78]="N",t[t.O=79]="O",t[t.P=80]="P",t[t.Q=81]="Q",t[t.R=82]="R",t[t.S=83]="S",t[t.T=84]="T",t[t.U=85]="U",t[t.V=86]="V",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.Z=90]="Z",t[t.KP0=96]="KP0",t[t.KP1=97]="KP1",t[t.KP2=98]="KP2",t[t.KP3=99]="KP3",t[t.KP4=100]="KP4",t[t.KP5=101]="KP5",t[t.KP6=102]="KP6",t[t.KP7=103]="KP7",t[t.KP8=104]="KP8",t[t.KP9=105]="KP9",t[t.KPMultiply=106]="KPMultiply",t[t.KPAdd=107]="KPAdd",t[t.KPSeparator=108]="KPSeparator",t[t.KPSubtract=109]="KPSubtract",t[t.KPDecimal=110]="KPDecimal",t[t.KPDivide=111]="KPDivide",t[t.F1=112]="F1",t[t.F2=113]="F2",t[t.F3=114]="F3",t[t.F4=115]="F4",t[t.F5=116]="F5",t[t.F6=117]="F6",t[t.F7=118]="F7",t[t.F8=119]="F8",t[t.F9=120]="F9",t[t.F10=121]="F10",t[t.F11=122]="F11",t[t.F12=123]="F12",t[t.F13=124]="F13",t[t.F14=125]="F14",t[t.F15=126]="F15",t[t.F16=127]="F16",t[t.F17=128]="F17",t[t.F18=129]="F18",t[t.F19=130]="F19",t[t.F20=131]="F20",t[t.F21=132]="F21",t[t.F22=133]="F22",t[t.F23=134]="F23",t[t.F24=135]="F24",t[t.NumLock=136]="NumLock",t[t.ScrollLock=137]="ScrollLock",t[t.Mouse0=256]="Mouse0",t[t.Mouse1=257]="Mouse1",t[t.Mouse2=258]="Mouse2",t[t.Mouse3=259]="Mouse3",t[t.Mouse4=260]="Mouse4",t[t.Mouse5=261]="Mouse5",t[t.Mouse6=262]="Mouse6"}(l||(l={}))},function(t,e,r){"use strict";r.d(e,"b",(function(){return a})),r.d(e,"a",(function(){return u}));var n=r(0),i=r(6),s=r(21),o=r(3);function a(t,e){var r;if(!t.entity||!e.entity)return!1;const i=e.entity.position.toVec2().plus(e.offset),s=n.b.math(Math.floor)(i).plus(.5),o=n.b.math(Math.ceil)(n.b.mul(e.size,.5));for(var a=-o.y;a<=o.y;a++)for(var u=-o.x;u<=o.x;u++){const o=Object(n.b)(u,a).plus(s),c=null===(r=t.tilemap)||void 0===r?void 0:r.getTile(o);if((null==c?void 0:c.collide)&&Math.abs(i.x-o.x)<=e.size.x/2+.5&&Math.abs(i.y-o.y)<=e.size.y/2+.5)return!0}return!1}function u(t,e,r){if(!e.entity||!t.tilemap)return null;const a=Object(i.f)(e.size,2),u=e.entity.position.toVec2().plus(e.offset),c=Object(i.h)(u,r),h=n.b.math(Math.ceil)(a),l=n.b.math(Math.floor)(c),d=r.magnitude;let f=!1,b=n.b.zero(),m=Number.MAX_VALUE;for(var p=-h.y;p<=h.y;p++)for(var v=-h.x;v<=h.x;v++){const t=new s.a(Object(n.b)(v,p).plus(l),Object(i.j)(e.size,1));Object(o.a)().drawRect(t);const[a,u,h]=Object(i.c)(t,c,r);a&&u>0&&u<=d&&Object(i.g)(h,r)<0&&u<m&&(f=!0,b=h)}if(f){const n=r.normalized.mul(m).plus(c);return{self:t,other:e,point:n,seperation:Object(i.h)(n,u)}}return null}},function(t,e,r){"use strict";r.d(e,"d",(function(){return n})),r.d(e,"c",(function(){return p})),r.d(e,"a",(function(){return v})),r.d(e,"b",(function(){return M}));var n,i=r(16),s=r(11),o=r(0),a=r(12),u=r(14),c=r(9),h=r(8),l=r(7),d=r(19),f=r(25),b=r(30),m=function(t,e,r,n){var i,s=arguments.length,o=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(o=(s<3?i(o):s>3?i(e,r,o):i(e,r))||o);return s>3&&o&&Object.defineProperty(e,r,o),o};!function(t){t.Soft="soft",t.Hard="hard"}(n||(n={}));const p=Object(i.e)(Object.assign(Object.assign({},i.a),{p0:"vec2",p1:"vec2"}));class v extends f.a{constructor(t=!1){super(),this.shadowType=!1,this.volumnRadius=1,this.lightRange=10,this.lightColor=s.a.white,this.intensity=1,this.attenuation=0,this.shadowMesh=null,this.shadowMat=new M,this.__tempVectors=Array.from(new Array(32)).map(()=>o.b.zero()),this.shadowType=t,t===n.Soft&&(this.shadowMesh=new i.c(p)),this.shadowMesh&&this.shadowMesh.resize(5e3,9e3)}getShadowMap(t,e){return this.shadowMesh||(this.shadowMesh=new i.c(p)),this.shadowMesh.vertices.length<=0&&this.shadowMesh.resize(50,90),this.shadowMap||(this.shadowMap=new a.c(t.renderer.canvasSize.x,t.renderer.canvasSize.y,!1,u.a.R8,a.b.Linear)),this.shadowMap.size.equals(e.cameraOutput.size)||this.shadowMap.resize(e.cameraOutput.width,e.cameraOutput.height,a.f.Discard),this.updateShadowMesh(t,e),t.renderer.setFramebuffer(this.shadowMap),t.renderer.clear(s.a.black),this.shadowMat.lightPos.set(this.position),this.shadowMat.lightRange=this.lightRange,this.shadowMat.volumnSize=this.volumnRadius,t.renderer.drawMesh(this.shadowMesh,this.localToWorldMatrix,this.shadowMat),this.shadowMap}updateShadowMesh(t,e){this.shadowMesh.indices.fill(0);const r=[Object(o.b)(-this.lightRange).plus(this.position.toVec2()),Object(o.b)(this.lightRange).plus(this.position.toVec2())],n=c.b.identity();let i=0,s=0;for(const t of e.scene.physics.__getColliders())if(t instanceof b.a){const e=t.getPolygons(...r);if(!e)continue;n.set(t.tilemap.localToWorldMatrix),c.b.mul(n,n,this.worldToLocalMatrix);for(const t of e)for(let e=0;e<t.points.length;e++){const[r,o]=this.appendLineShadow(t.points[e],t.points[(e+1)%t.points.length],n,i,s);i+=r,s+=o}}this.shadowMesh.update()}appendLineShadow(t,e,r,n,i){let s=0;(this.shadowMesh.vertices.length<=n+5||this.shadowMesh.indices.length<=i+9)&&this.shadowMesh.resize(2*this.shadowMesh.vertices.length,2*this.shadowMesh.indices.length,!0);const a=this.volumnRadius*this.volumnRadius,u=this.lightRange*this.lightRange,h=c.b.mulPoint2(this.__tempVectors[s++],r,t),l=c.b.mulPoint2(this.__tempVectors[s++],r,e);o.b.set(this.shadowMesh.vertices[n+0].vert,h),o.b.set(this.shadowMesh.vertices[n+1].vert,l);const d=o.b.minus(this.__tempVectors[s++],l,h).normalize();let f=x(h,this.volumnRadius,[this.__tempVectors[s++],this.__tempVectors[s++]]),b=x(l,this.volumnRadius,[this.__tempVectors[s++],this.__tempVectors[s++]]);f=[f[1],f[0]];const m=this.shadowMesh.vertices[n+4].vert,p=this.shadowMesh.vertices[n+2].vert,v=[o.b.minus(this.__tempVectors[s++],h,f[0]).normalize(),o.b.minus(this.__tempVectors[s++],h,f[1]).normalize()],g=[o.b.minus(this.__tempVectors[s++],l,b[0]).normalize(),o.b.minus(this.__tempVectors[s++],l,b[1]).normalize()];let y=0;o.b.cross(d,v[0])<=0?(y|=1,m.set(g[1].mul(Math.sqrt(u-a)).plus(b[1]))):m.set(v[0].mul(Math.sqrt(u-a)).plus(f[0])),o.b.cross(d,g[0])<=0?(y|=2,p.set(v[1].mul(Math.sqrt(u-a)).plus(f[1]))):p.set(g[0].mul(Math.sqrt(u-a)).plus(b[0]));const M=o.b.plus(this.__tempVectors[s++],m,p).mul(.5);o.b.mul(this.shadowMesh.vertices[n+3].vert,M,u/M.magnitudeSqr);switch(o.b.set(this.shadowMesh.vertices[n+0].p0,h),o.b.set(this.shadowMesh.vertices[n+0].p1,l),o.b.set(this.shadowMesh.vertices[n+1].p0,h),o.b.set(this.shadowMesh.vertices[n+1].p1,l),o.b.set(this.shadowMesh.vertices[n+2].p0,h),o.b.set(this.shadowMesh.vertices[n+2].p1,l),o.b.set(this.shadowMesh.vertices[n+3].p0,h),o.b.set(this.shadowMesh.vertices[n+3].p1,l),o.b.set(this.shadowMesh.vertices[n+4].p0,h),o.b.set(this.shadowMesh.vertices[n+4].p1,l),y){case 0:this.shadowMesh.indices.set([n+0,n+3,n+4,n+0,n+1,n+3,n+1,n+2,n+3],i);break;case 1:this.shadowMesh.indices.set([n+1,n+2,n+3,n+1,n+3,n+4,n+1,n+1,n+1],i);break;case 2:this.shadowMesh.indices.set([n+0,n+2,n+3,n+0,n+3,n+4,n+1,n+1,n+1],i);break;case 3:this.shadowMesh.indices.set([n+1,n+3,n+4,n+1,n+0,n+3,n+0,n+2,n+3],i)}return[5,9]}appendVerts(){}destroy(){var t,e;this.destroyed||(super.destroy(),null===(t=this.shadowMesh)||void 0===t||t.destroy(),null===(e=this.shadowMap)||void 0===e||e.destroy())}}const g=o.b.zero(),y=o.b.zero();function x(t,e,r=[o.b.zero(),o.b.zero()]){const n=e*e,i=t.magnitudeSqr,s=g;return s.x=-t.y,s.y=t.x,s.mul(e/i*Math.sqrt(i-n)),o.b.mul(y,t,n/i),r[0].set(y).plus(s),r[1].set(y).minus(s),r}class M extends(Object(h.b)(new l.e(...d.ShaderSource.shadow2D,{vertexStructure:p,attributes:{p0:"aP0",p1:"aP1"},cull:l.b.Back,blend:[l.a.One,l.a.One]}))){constructor(){super(...arguments),this.lightPos=o.b.zero(),this.volumnSize=1,this.lightRange=10}}m([Object(h.e)("uLightPos","vec2")],M.prototype,"lightPos",void 0),m([Object(h.e)("uVolumnSize","float")],M.prototype,"volumnSize",void 0),m([Object(h.e)("uLightRange","float")],M.prototype,"lightRange",void 0)},function(t,e,r){"use strict";r.d(e,"b",(function(){return n})),r.d(e,"a",(function(){return b}));var n,i=r(12),s=r(3),o=r(0),a=r(25),u=r(9),c=r(6),h=r(11),l=r(1),d=r(56),f=r(13);!function(t){t[t.Perspective=0]="Perspective",t[t.Orthographic=1]="Orthographic"}(n||(n={}));class b extends a.a{constructor(t=Object(s.d)()){super(),this.output=null,this.FOV=30,this.near=.3,this.far=1e3,this.viewHeight=1,this.projection=n.Perspective,this.clearColor=h.a.black,this.clearDepth=!0,this.postprocess=[],this.ctx=t}get pixelSize(){return this.output instanceof i.c?Object(o.b)(this.output.width,this.output.height):Object(o.b)(this.ctx.width,this.ctx.height)}get aspectRatio(){return this.pixelSize.x/this.pixelSize.y}get viewProjectionMatrix(){const t=this.worldToLocalMatrix,e=this.projectionMatrix;return u.b.mul(e,t)}get projectionMatrix(){return this.projection===n.Perspective?u.b.perspective(this.FOV*c.a,this.aspectRatio,this.near,this.far):u.b.ortho(this.viewHeight,this.aspectRatio,this.near,this.far)}on(t,e){this.eventEmitter.with().on(t,e)}off(t,e){this.eventEmitter.with().on(t,e)}__preRender(t){this.eventEmitter.with().emit("prerender",this,t)}__postRender(t){this.eventEmitter.with().emit("postrender",this,t)}screenToRay(t){const e=this.screenToWorld(t);return Object(d.a)(this.position.clone(),Object(c.h)(Object(l.b)(e.x,e.y,e.z),this.position))}screenToWorld(t){const e=this.projection==n.Perspective?this.near:1,r=this.screenToViewport(t).mul(Object(o.b)(2,-2)).minus(Object(o.b)(1,-1)),i=Object(c.i)(Object(f.b)(r.x,r.y,-1,1),e),s=u.b.invert(this.viewProjectionMatrix),a=u.b.mulVec4(s,i);return Object(l.b)(a[0],a[1],a[2])}screenToViewport(t){return null===this.output?Object(c.f)(t,Object(o.b)(this.ctx.width,this.ctx.height)):this.output instanceof i.c?Object(c.f)(t,Object(o.b)(this.output.width,this.output.height)):o.b.zero()}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return s}));var n=r(28),i=r(46);class s extends i.a{constructor(){super(...arguments),this.rigidbody=null,this.enabled=!0,this.__eventEmitter=new n.a,this.__colliderIdx=-1}on(t,e){this.__eventEmitter.on(t,e)}off(t,e){this.__eventEmitter.on(t,e)}checkCollision(t,e){return null}checkContact(t){return!1}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return u}));var n=r(11),i=r(6),s=r(21),o=r(0),a=r(1);class u{drawRay(t,e,r=1,s=n.a.red){this.drawLine(t,Object(i.i)(e,r).plus(t),s)}drawRect(...t){let e,r,i;t[0]instanceof s.a?(e=t[0].min,r=t[0].max,i=t[1]||n.a.red):(e=t[0],r=t[1],i=t[2]||n.a.red),this.drawLine(Object(o.b)(e.x,e.y).toVec3(),Object(o.b)(r.x,e.y).toVec3(),i),this.drawLine(Object(o.b)(r.x,e.y).toVec3(),Object(o.b)(r.x,r.y).toVec3(),i),this.drawLine(Object(o.b)(r.x,r.y).toVec3(),Object(o.b)(e.x,r.y).toVec3(),i),this.drawLine(Object(o.b)(e.x,r.y).toVec3(),Object(o.b)(e.x,e.y).toVec3(),i)}drawLines(t,e=n.a.red){for(let r=0;r<t.length;r++)this.drawLine(t[r],t[(r+1)%t.length],e)}drawCircle(t,e,r=n.a.red){for(let n=0;n<24;n++){const i=Object(a.b)(Math.cos(2*n*Math.PI/24),Math.sin(2*n*Math.PI/24),0),s=Object(a.b)(Math.cos((n+1)%24*2*Math.PI/24),Math.sin((n+1)%24*2*Math.PI/24),0);this.drawLine(i.mul(e).plus(t),s.mul(e).plus(t),r)}}}},function(t,e,r){"use strict";r.r(e),r.d(e,"Vector2",(function(){return n.Vector2})),r.d(e,"vec2",(function(){return n.vec2})),r.d(e,"Vector3",(function(){return n.Vector3})),r.d(e,"vec3",(function(){return n.vec3})),r.d(e,"Vector4",(function(){return n.Vector4})),r.d(e,"vec4",(function(){return n.vec4})),r.d(e,"Color",(function(){return n.Color})),r.d(e,"rgba",(function(){return n.rgba})),r.d(e,"rgb",(function(){return n.rgb})),r.d(e,"hsl",(function(){return n.hsl})),r.d(e,"plus",(function(){return n.plus})),r.d(e,"minus",(function(){return n.minus})),r.d(e,"mul",(function(){return n.mul})),r.d(e,"div",(function(){return n.div})),r.d(e,"dot",(function(){return n.dot})),r.d(e,"cross",(function(){return n.cross})),r.d(e,"distance",(function(){return n.distance})),r.d(e,"boxRaycast",(function(){return n.boxRaycast})),r.d(e,"Deg2Rad",(function(){return n.Deg2Rad})),r.d(e,"Rad2Deg",(function(){return n.Rad2Deg})),r.d(e,"Matrix4x4",(function(){return n.Matrix4x4})),r.d(e,"mat4",(function(){return n.mat4})),r.d(e,"Quaternion",(function(){return n.Quaternion})),r.d(e,"quat",(function(){return n.quat})),r.d(e,"ray",(function(){return n.ray})),r.d(e,"Rect",(function(){return n.Rect})),r.d(e,"MathUtils",(function(){return n.MathUtils})),r.d(e,"Material",(function(){return n.Material})),r.d(e,"shaderProp",(function(){return n.shaderProp})),r.d(e,"MaterialFromShader",(function(){return n.MaterialFromShader})),r.d(e,"SimpleTexturedMaterial",(function(){return n.SimpleTexturedMaterial})),r.d(e,"materialDefine",(function(){return n.materialDefine})),r.d(e,"DefaultVertexData",(function(){return n.DefaultVertexData})),r.d(e,"DefaultVertexStructInfo",(function(){return n.DefaultVertexStructInfo})),r.d(e,"VertexStruct",(function(){return n.VertexStruct})),r.d(e,"Mesh",(function(){return n.Mesh})),r.d(e,"MeshLegacy",(function(){return n.MeshLegacy})),r.d(e,"ZograRenderer",(function(){return n.ZograRenderer})),r.d(e,"DepthTest",(function(){return n.DepthTest})),r.d(e,"Blending",(function(){return n.Blending})),r.d(e,"Culling",(function(){return n.Culling})),r.d(e,"DefaultShaderAttributeNames",(function(){return n.DefaultShaderAttributeNames})),r.d(e,"Shader",(function(){return n.Shader})),r.d(e,"FilterMode",(function(){return n.FilterMode})),r.d(e,"WrapMode",(function(){return n.WrapMode})),r.d(e,"Texture",(function(){return n.Texture})),r.d(e,"TextureResizing",(function(){return n.TextureResizing})),r.d(e,"Texture2D",(function(){return n.Texture2D})),r.d(e,"DepthTexture",(function(){return n.DepthTexture})),r.d(e,"RenderTexture",(function(){return n.RenderTexture})),r.d(e,"Asset",(function(){return n.Asset})),r.d(e,"GPUAsset",(function(){return n.GPUAsset})),r.d(e,"LazyInitAsset",(function(){return n.LazyInitAsset})),r.d(e,"AssetManager",(function(){return n.AssetManager})),r.d(e,"Lines",(function(){return n.Lines})),r.d(e,"LineBuilder",(function(){return n.LineBuilder})),r.d(e,"EventEmitter",(function(){return n.EventEmitter})),r.d(e,"BufferStructureInfo",(function(){return n.BufferStructureInfo})),r.d(e,"GLArrayBuffer",(function(){return n.GLArrayBuffer})),r.d(e,"RenderBuffer",(function(){return n.RenderBuffer})),r.d(e,"DepthBuffer",(function(){return n.DepthBuffer})),r.d(e,"FrameBuffer",(function(){return n.FrameBuffer})),r.d(e,"DebugProvider",(function(){return n.DebugProvider})),r.d(e,"TextureFormat",(function(){return n.TextureFormat})),r.d(e,"AssetsPack",(function(){return n.AssetsPack})),r.d(e,"AssetsImporter",(function(){return n.AssetsImporter})),r.d(e,"TextureImporter",(function(){return n.TextureImporter})),r.d(e,"MeshBuilder",(function(){return n.MeshBuilder})),r.d(e,"MeshBuilderLegacy",(function(){return n.MeshBuilderLegacy})),r.d(e,"Utils",(function(){return n.Utils})),r.d(e,"GLContext",(function(){return n.GLContext})),r.d(e,"GlobalContext",(function(){return n.GlobalContext})),r.d(e,"Projection",(function(){return i.m})),r.d(e,"Camera",(function(){return i.c})),r.d(e,"RenderObject",(function(){return i.n})),r.d(e,"LightType",(function(){return i.j})),r.d(e,"Light",(function(){return i.i})),r.d(e,"Entity",(function(){return i.d})),r.d(e,"EntityManager",(function(){return i.e})),r.d(e,"Scene",(function(){return i.o})),r.d(e,"Transform",(function(){return i.q})),r.d(e,"ZograEngine",(function(){return i.r})),r.d(e,"KeyState",(function(){return i.g})),r.d(e,"InputManager",(function(){return i.f})),r.d(e,"Keys",(function(){return i.h})),r.d(e,"Timeline",(function(){return i.p})),r.d(e,"AnimationPlayback",(function(){return i.a})),r.d(e,"Animator",(function(){return i.b})),r.d(e,"ParticleMaterial",(function(){return i.k})),r.d(e,"ParticleSystem",(function(){return i.l})),r.d(e,"PreviewRenderer",(function(){return s.g})),r.d(e,"RenderOrder",(function(){return s.j})),r.d(e,"RenderData",(function(){return s.i})),r.d(e,"RenderContext",(function(){return s.h})),r.d(e,"Default2DRenderPipeline",(function(){return s.d})),r.d(e,"PostProcess",(function(){return s.e})),r.d(e,"PostprocessPass",(function(){return s.f})),r.d(e,"Bloom",(function(){return s.a})),r.d(e,"BlurMethod",(function(){return s.c})),r.d(e,"Blur",(function(){return s.b})),r.d(e,"RenderPass",(function(){return s.k})),r.d(e,"BoxCollider",(function(){return o.a})),r.d(e,"Collider2D",(function(){return a.a})),r.d(e,"Physics2D",(function(){return u.a})),r.d(e,"Rigidbody2D",(function(){return h})),r.d(e,"TilemapCollider",(function(){return l.a})),r.d(e,"Sprite",(function(){return d.a})),r.d(e,"SpriteObject",(function(){return f.a})),r.d(e,"Tilemap",(function(){return b.b})),r.d(e,"Chunk",(function(){return b.a})),r.d(e,"Default2DMaterial",(function(){return m.a})),r.d(e,"LineRenderer",(function(){return p.a})),r.d(e,"ShadowType",(function(){return v.d})),r.d(e,"Shadow2DVertStruct",(function(){return v.c})),r.d(e,"Light2D",(function(){return v.a})),r.d(e,"Shadow2DMaterial",(function(){return v.b})),r.d(e,"BuiltinShaders",(function(){return g}));var n=r(5),i=r(59),s=r(60),o=r(40),a=r(35),u=r(72),c=r(0);class h{constructor(t){this.mass=1,this._velocity=c.b.zero(),this._acceleration=c.b.zero(),this._motion=c.b.zero(),this.collider=t}get velocity(){return this._velocity}set velocity(t){this._velocity.set(t)}get acceleration(){return this._acceleration}addForce(t){this._acceleration.x+=t.x/this.mass,this._acceleration.y+=t.y/this.mass}addAcceleration(t){this._acceleration.plus(t)}setAcceleration(t){this._acceleration.set(t)}setForce(t){this._acceleration.x=t.x/this.mass,this._acceleration.y=t.y/this.mass}clearForce(){this._acceleration.x=0,this._acceleration.y=0}}var l=r(30),d=r(66),f=r(77),b=r(44),m=r(39),p=r(75),v=r(33);const g=r(19).ShaderSource},function(t,e,r){"use strict";r.d(e,"a",(function(){return s})),r.d(e,"b",(function(){return o}));var n=r(12),i=r(26);class s{constructor(){this.__intialized=!1}create(t){}}class o extends i.a{constructor(t,e){super(),this.format=e,this.buffers=[new n.c(t.screen.width,t.screen.height,!1,this.format,n.b.Nearest).createFramebuffer(),new n.c(t.screen.width,t.screen.height,!1,this.format,n.b.Nearest).createFramebuffer()]}render(t,e){if(!e.cameraOutput.size.equals(this.buffers[0].size)){const t=this.buffers[0].colorAttachments[0].resize(e.cameraOutput.width,e.cameraOutput.height,n.f.Discard),r=this.buffers[1].colorAttachments[0].resize(e.cameraOutput.width,e.cameraOutput.height,n.f.Discard);this.buffers[0].reset(e.cameraOutput.width,e.cameraOutput.height),this.buffers[1].reset(e.cameraOutput.width,e.cameraOutput.height),this.buffers[0].addColorAttachment(t,0),this.buffers[1].addColorAttachment(r,0)}const r=e.camera;let[i,s]=this.buffers;const o=e.cameraOutput.colorAttachments[0];t.renderer.blitCopy(o,i.colorAttachments[0]);for(const e of r.postprocess)e.__intialized||(e.create(t),e.__intialized=!0),e.render(t,i.colorAttachments[0],s),[i,s]=[s,i];e.postprocessOutput=i.colorAttachments[0]}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return u}));var n=r(8),i=r(7),s=r(11),o=r(19),a=function(t,e,r,n){var i,s=arguments.length,o=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(o=(s<3?i(o):s>3?i(e,r,o):i(e,r))||o);return s>3&&o&&Object.defineProperty(e,r,o),o};class u extends(Object(n.b)(new i.e(...o.ShaderSource.default2D,{cull:i.b.Disable,depth:i.d.Disable,zWrite:!1,blend:[i.a.SrcAlpha,i.a.OneMinusSrcAlpha]}))){constructor(){super(...arguments),this.texture=null,this.color=s.a.white}}a([Object(n.e)("uMainTex","tex2d")],u.prototype,"texture",void 0),a([Object(n.e)("uColor","color")],u.prototype,"color",void 0)},function(t,e,r){"use strict";r.d(e,"a",(function(){return a}));var n=r(0),i=r(35);var s=r(32),o=r(30);class a extends i.a{constructor(){super(...arguments),this.offset=n.b.zero(),this.size=n.b.one()}checkCollision(t,e){return t instanceof o.a?Object(s.a)(t,this,e.negative):(console.warn("Unimplemented collision check"),null)}checkContact(t){return t instanceof o.a?Object(s.b)(t,this):t instanceof a?function(t,e){if(!t.entity||!e.entity)return!1;const r=t.entity.position.toVec2().plus(t.offset),i=e.entity.position.toVec2().plus(e.offset),s=n.b.math(Math.abs)(n.b.minus(i,r));return s.x<=(t.size.x+e.size.x)/2&&s.y<=(t.size.y+e.size.y)/2}(this,t):(console.warn("Unimplemented collision check"),!1)}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return n})),r.d(e,"b",(function(){return o}));var n,i=r(21),s=r(0);function o(t,e,r){let o=new i.a(s.b.zero(),t),a=new i.a(s.b.zero(),e);if(r===n.Contain){if(t.x/t.y>e.x/e.y){const r=e.y-t.y*(e.x/t.x);a.min.y+=r/2,a.max.y-=r/2}else{const r=e.x-t.x*(e.y/t.y);a.min.x+=r/2,a.max.x-=r/2}}else if(r===n.Cover){if(t.x/t.y>e.x/e.y){const r=t.x-e.x*(t.y/e.y);o.min.x+=r/2,o.max.x-=r/2}else{const r=t.y-e.y*(t.x/e.x);o.min.y+=r/2,o.max.y-=r/2}}else{if(t.x<e.x)switch(r){case n.Center:const r=e.x-t.x;a.min.x+=r/2,a.max.x-=r/2;break;case n.KeepHigher:a.min.x=e.x-t.x;break;case n.KeepLower:a.max.x=t.x}else if(t.x>e.x)switch(r){case n.Center:const r=t.x-e.x;o.min.x+=r/2,o.max.x-=r/2;break;case n.KeepHigher:o.min.x=t.x-e.x;break;case n.KeepLower:o.max.x=e.x}if(t.y<e.y)switch(r){case n.Center:const r=e.y-t.y;a.min.y+=r/2,a.max.y-=r/2;break;case n.KeepHigher:a.min.y=e.y-t.y;break;case n.KeepLower:a.max.y=t.y}else if(t.y>e.y)switch(r){case n.Center:const r=t.y-e.y;o.min.y+=r/2,o.max.y-=r/2;break;case n.KeepHigher:o.min.y=t.y-e.y;break;case n.KeepLower:o.max.y=e.y}}return[o,a]}!function(t){t[t.Stretch=1]="Stretch",t[t.Cover=2]="Cover",t[t.Contain=3]="Contain",t[t.KeepLower=4]="KeepLower",t[t.KeepHigher=5]="KeepHigher",t[t.Center=6]="Center"}(n||(n={}))},function(t,e,r){(function(t,e){
  /*! *****************************************************************************
  Copyright (C) Microsoft. All rights reserved.
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  this file except in compliance with the License. You may obtain a copy of the
  License at http://www.apache.org/licenses/LICENSE-2.0
  
  THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  MERCHANTABLITY OR NON-INFRINGEMENT.
  
  See the Apache Version 2.0 License for specific language governing permissions
  and limitations under the License.
  ***************************************************************************** */
  var r;!function(r){!function(n){var i="object"==typeof e?e:"object"==typeof self?self:"object"==typeof this?this:Function("return this;")(),s=o(r);function o(t,e){return function(r,n){"function"!=typeof t[r]&&Object.defineProperty(t,r,{configurable:!0,writable:!0,value:n}),e&&e(r,n)}}void 0===i.Reflect?i.Reflect=r:s=o(i.Reflect,s),function(e){var r=Object.prototype.hasOwnProperty,n="function"==typeof Symbol,i=n&&void 0!==Symbol.toPrimitive?Symbol.toPrimitive:"@@toPrimitive",s=n&&void 0!==Symbol.iterator?Symbol.iterator:"@@iterator",o="function"==typeof Object.create,a={__proto__:[]}instanceof Array,u=!o&&!a,c={create:o?function(){return F(Object.create(null))}:a?function(){return F({__proto__:null})}:function(){return F({})},has:u?function(t,e){return r.call(t,e)}:function(t,e){return e in t},get:u?function(t,e){return r.call(t,e)?t[e]:void 0}:function(t,e){return t[e]}},h=Object.getPrototypeOf(Function),l="object"==typeof t&&t.env&&"true"===t.env.REFLECT_METADATA_USE_MAP_POLYFILL,d=l||"function"!=typeof Map||"function"!=typeof Map.prototype.entries?function(){var t={},e=[],r=function(){function t(t,e,r){this._index=0,this._keys=t,this._values=e,this._selector=r}return t.prototype["@@iterator"]=function(){return this},t.prototype[s]=function(){return this},t.prototype.next=function(){var t=this._index;if(t>=0&&t<this._keys.length){var r=this._selector(this._keys[t],this._values[t]);return t+1>=this._keys.length?(this._index=-1,this._keys=e,this._values=e):this._index++,{value:r,done:!1}}return{value:void 0,done:!0}},t.prototype.throw=function(t){throw this._index>=0&&(this._index=-1,this._keys=e,this._values=e),t},t.prototype.return=function(t){return this._index>=0&&(this._index=-1,this._keys=e,this._values=e),{value:t,done:!0}},t}();return function(){function e(){this._keys=[],this._values=[],this._cacheKey=t,this._cacheIndex=-2}return Object.defineProperty(e.prototype,"size",{get:function(){return this._keys.length},enumerable:!0,configurable:!0}),e.prototype.has=function(t){return this._find(t,!1)>=0},e.prototype.get=function(t){var e=this._find(t,!1);return e>=0?this._values[e]:void 0},e.prototype.set=function(t,e){var r=this._find(t,!0);return this._values[r]=e,this},e.prototype.delete=function(e){var r=this._find(e,!1);if(r>=0){for(var n=this._keys.length,i=r+1;i<n;i++)this._keys[i-1]=this._keys[i],this._values[i-1]=this._values[i];return this._keys.length--,this._values.length--,e===this._cacheKey&&(this._cacheKey=t,this._cacheIndex=-2),!0}return!1},e.prototype.clear=function(){this._keys.length=0,this._values.length=0,this._cacheKey=t,this._cacheIndex=-2},e.prototype.keys=function(){return new r(this._keys,this._values,n)},e.prototype.values=function(){return new r(this._keys,this._values,i)},e.prototype.entries=function(){return new r(this._keys,this._values,o)},e.prototype["@@iterator"]=function(){return this.entries()},e.prototype[s]=function(){return this.entries()},e.prototype._find=function(t,e){return this._cacheKey!==t&&(this._cacheIndex=this._keys.indexOf(this._cacheKey=t)),this._cacheIndex<0&&e&&(this._cacheIndex=this._keys.length,this._keys.push(t),this._values.push(void 0)),this._cacheIndex},e}();function n(t,e){return t}function i(t,e){return e}function o(t,e){return[t,e]}}():Map,f=l||"function"!=typeof Set||"function"!=typeof Set.prototype.entries?function(){function t(){this._map=new d}return Object.defineProperty(t.prototype,"size",{get:function(){return this._map.size},enumerable:!0,configurable:!0}),t.prototype.has=function(t){return this._map.has(t)},t.prototype.add=function(t){return this._map.set(t,t),this},t.prototype.delete=function(t){return this._map.delete(t)},t.prototype.clear=function(){this._map.clear()},t.prototype.keys=function(){return this._map.keys()},t.prototype.values=function(){return this._map.values()},t.prototype.entries=function(){return this._map.entries()},t.prototype["@@iterator"]=function(){return this.keys()},t.prototype[s]=function(){return this.keys()},t}():Set,b=new(l||"function"!=typeof WeakMap?function(){var t=c.create(),e=n();return function(){function t(){this._key=n()}return t.prototype.has=function(t){var e=i(t,!1);return void 0!==e&&c.has(e,this._key)},t.prototype.get=function(t){var e=i(t,!1);return void 0!==e?c.get(e,this._key):void 0},t.prototype.set=function(t,e){return i(t,!0)[this._key]=e,this},t.prototype.delete=function(t){var e=i(t,!1);return void 0!==e&&delete e[this._key]},t.prototype.clear=function(){this._key=n()},t}();function n(){var e;do{e="@@WeakMap@@"+o()}while(c.has(t,e));return t[e]=!0,e}function i(t,n){if(!r.call(t,e)){if(!n)return;Object.defineProperty(t,e,{value:c.create()})}return t[e]}function s(t,e){for(var r=0;r<e;++r)t[r]=255*Math.random()|0;return t}function o(){var t,e=(t=16,"function"==typeof Uint8Array?"undefined"!=typeof crypto?crypto.getRandomValues(new Uint8Array(t)):"undefined"!=typeof msCrypto?msCrypto.getRandomValues(new Uint8Array(t)):s(new Uint8Array(t),t):s(new Array(t),t));e[6]=79&e[6]|64,e[8]=191&e[8]|128;for(var r="",n=0;n<16;++n){var i=e[n];4!==n&&6!==n&&8!==n||(r+="-"),i<16&&(r+="0"),r+=i.toString(16).toLowerCase()}return r}}():WeakMap);function m(t,e,r){var n=b.get(t);if(M(n)){if(!r)return;n=new d,b.set(t,n)}var i=n.get(e);if(M(i)){if(!r)return;i=new d,n.set(e,i)}return i}function p(t,e,r){var n=m(e,r,!1);return!M(n)&&!!n.has(t)}function v(t,e,r){var n=m(e,r,!1);if(!M(n))return n.get(t)}function g(t,e,r,n){m(r,n,!0).set(t,e)}function y(t,e){var r=[],n=m(t,e,!1);if(M(n))return r;for(var i=function(t){var e=S(t,s);if(!A(e))throw new TypeError;var r=e.call(t);if(!R(r))throw new TypeError;return r}(n.keys()),o=0;;){var a=j(i);if(!a)return r.length=o,r;var u=a.value;try{r[o]=u}catch(t){try{P(i)}finally{throw t}}o++}}function x(t){if(null===t)return 1;switch(typeof t){case"undefined":return 0;case"boolean":return 2;case"string":return 3;case"symbol":return 4;case"number":return 5;case"object":return null===t?1:6;default:return 6}}function M(t){return void 0===t}function w(t){return null===t}function R(t){return"object"==typeof t?null!==t:"function"==typeof t}function _(t,e){switch(x(t)){case 0:case 1:case 2:case 3:case 4:case 5:return t}var r=3===e?"string":5===e?"number":"default",n=S(t,i);if(void 0!==n){var s=n.call(t,r);if(R(s))throw new TypeError;return s}return function(t,e){if("string"===e){var r=t.toString;if(A(r))if(!R(i=r.call(t)))return i;if(A(n=t.valueOf))if(!R(i=n.call(t)))return i}else{var n;if(A(n=t.valueOf))if(!R(i=n.call(t)))return i;var i,s=t.toString;if(A(s))if(!R(i=s.call(t)))return i}throw new TypeError}(t,"default"===r?"number":r)}function O(t){var e=_(t,3);return"symbol"==typeof e?e:function(t){return""+t}(e)}function T(t){return Array.isArray?Array.isArray(t):t instanceof Object?t instanceof Array:"[object Array]"===Object.prototype.toString.call(t)}function A(t){return"function"==typeof t}function E(t){return"function"==typeof t}function S(t,e){var r=t[e];if(null!=r){if(!A(r))throw new TypeError;return r}}function j(t){var e=t.next();return!e.done&&e}function P(t){var e=t.return;e&&e.call(t)}function z(t){var e=Object.getPrototypeOf(t);if("function"!=typeof t||t===h)return e;if(e!==h)return e;var r=t.prototype,n=r&&Object.getPrototypeOf(r);if(null==n||n===Object.prototype)return e;var i=n.constructor;return"function"!=typeof i||i===t?e:i}function F(t){return t.__=void 0,delete t.__,t}e("decorate",(function(t,e,r,n){if(M(r)){if(!T(t))throw new TypeError;if(!E(e))throw new TypeError;return function(t,e){for(var r=t.length-1;r>=0;--r){var n=(0,t[r])(e);if(!M(n)&&!w(n)){if(!E(n))throw new TypeError;e=n}}return e}(t,e)}if(!T(t))throw new TypeError;if(!R(e))throw new TypeError;if(!R(n)&&!M(n)&&!w(n))throw new TypeError;return w(n)&&(n=void 0),function(t,e,r,n){for(var i=t.length-1;i>=0;--i){var s=(0,t[i])(e,r,n);if(!M(s)&&!w(s)){if(!R(s))throw new TypeError;n=s}}return n}(t,e,r=O(r),n)})),e("metadata",(function(t,e){return function(r,n){if(!R(r))throw new TypeError;if(!M(n)&&!function(t){switch(x(t)){case 3:case 4:return!0;default:return!1}}(n))throw new TypeError;g(t,e,r,n)}})),e("defineMetadata",(function(t,e,r,n){if(!R(r))throw new TypeError;return M(n)||(n=O(n)),g(t,e,r,n)})),e("hasMetadata",(function(t,e,r){if(!R(e))throw new TypeError;return M(r)||(r=O(r)),function t(e,r,n){if(p(e,r,n))return!0;var i=z(r);return!w(i)&&t(e,i,n)}(t,e,r)})),e("hasOwnMetadata",(function(t,e,r){if(!R(e))throw new TypeError;return M(r)||(r=O(r)),p(t,e,r)})),e("getMetadata",(function(t,e,r){if(!R(e))throw new TypeError;return M(r)||(r=O(r)),function t(e,r,n){if(p(e,r,n))return v(e,r,n);var i=z(r);return w(i)?void 0:t(e,i,n)}(t,e,r)})),e("getOwnMetadata",(function(t,e,r){if(!R(e))throw new TypeError;return M(r)||(r=O(r)),v(t,e,r)})),e("getMetadataKeys",(function(t,e){if(!R(t))throw new TypeError;return M(e)||(e=O(e)),function t(e,r){var n=y(e,r),i=z(e);if(null===i)return n;var s=t(i,r);if(s.length<=0)return n;if(n.length<=0)return s;for(var o=new f,a=[],u=0,c=n;u<c.length;u++){var h=c[u];o.has(h)||(o.add(h),a.push(h))}for(var l=0,d=s;l<d.length;l++){h=d[l];o.has(h)||(o.add(h),a.push(h))}return a}(t,e)})),e("getOwnMetadataKeys",(function(t,e){if(!R(t))throw new TypeError;return M(e)||(e=O(e)),y(t,e)})),e("deleteMetadata",(function(t,e,r){if(!R(e))throw new TypeError;M(r)||(r=O(r));var n=m(e,r,!1);if(M(n))return!1;if(!n.delete(t))return!1;if(n.size>0)return!0;var i=b.get(e);return i.delete(r),i.size>0||b.delete(e),!0}))}(s)}()}(r||(r={}))}).call(this,r(70),r(71))},function(t,e,r){"use strict";r.d(e,"a",(function(){return v})),r.d(e,"b",(function(){return g}));var n=r(16),i=r(7),s=r(8),o=r(11),a=r(24),u=r(0),c=r(23),h=r(1),l=r(2),d=r(19),f=r(27),b=function(t,e,r,n){var i,s=arguments.length,o=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(o=(s<3?i(o):s>3?i(e,r,o):i(e,r))||o);return s>3&&o&&Object.defineProperty(e,r,o),o};const m=Object(n.e)({vert:"vec3",color:"vec4",normal:"vec3",uv:"vec2",uv2:"vec2",pos:"vec3",rotation:"vec3",size:"float"}),p=Object.assign(Object.assign({},i.c),{pos:"particlePos",rotation:"particleRotation",size:"particleSize"});class v extends(Object(s.b)(new i.e(...d.ShaderSource.particle2D,{vertexStructure:m,attributes:p}))){constructor(){super(...arguments),this.color=o.a.white,this.texture=null}}b([Object(s.e)("uColor","color")],v.prototype,"color",void 0),b([Object(s.e)("uMainTex","tex2d")],v.prototype,"texture",void 0);class g extends f.a{constructor(){super(),this.mesh=a.a.quad(),this.material=new v,this.duration=1,this.lifetime=1,this.spawnRate=30,this.startSize=[.2,.4],this.startColor={r:1,g:1,b:1,a:1},this.startRotation={x:0,y:0,z:0},this.startSpeed=[5,10],this.startAcceleration={x:0,y:-20,z:0},this.emitter=g.boxEmitter(u.b.one()),this.lifeSize=null,this.lifeColor={r:null,g:null,b:null,a:null},this.lifeRotation={x:null,y:null,z:null},this.lifeSpeed=null,this.lifeAcceleration={x:null,y:null,z:null},this.particlesBuffer=new c.b({pos:"vec3",color:"vec4",rotation:"vec3",size:"float",velocity:"vec4",lifetime:"vec2",acceleration:"vec3"},0),this.particleCount=0,this.spawnedTime=0,this.state="stopped",this.particlesBuffer.static=!1}get maxCount(){return this.particlesBuffer.length}set maxCount(t){this.particlesBuffer.resize(t)}play(){this.state="pending"}update(t){switch(this.state){case"stopped":break;case"pending":this.state="running",this.spawnedTime=t.time;case"running":const e=1/this.getScalarValue(this.spawnRate);for(;this.spawnedTime+e<=t.time;)this.spawnedTime+=e,this.emitOne(this.position)}this.updateParticles(t)}render(t,e){t.renderer.drawMeshInstance(this.mesh,this.particlesBuffer,this.material,this.particleCount)}emit(t,e=this.position){for(let r=0;r<t;r++)this.emitOne(e)}updateParticles(t){for(let e=0;e<this.particleCount;e++){const r=this.particlesBuffer[e],n=r.lifetime[0]/r.lifetime[1];if(n>=1){e<this.particleCount-1&&(this.particlesBuffer.swapVertices(e,this.particleCount-1),e--),this.particleCount--;continue}r.lifetime[0]+=t.deltaTime,this.lifeColor&&("function"==typeof this.lifeColor?r.color.set(this.lifeColor(n,this)):(r.color[0]=this.updateScalarValue(this.lifeColor.r,n,r.color[0]),r.color[1]=this.updateScalarValue(this.lifeColor.g,n,r.color[1]),r.color[2]=this.updateScalarValue(this.lifeColor.b,n,r.color[2]),r.color[3]=this.updateScalarValue(this.lifeColor.a,n,r.color[3]))),this.lifeSize&&("function"==typeof this.lifeSize?r.size[0]=this.lifeSize(n):r.size[0]=this.updateScalarValue(this.lifeSize,n,r.size[0])),this.lifeAcceleration&&("function"==typeof this.lifeAcceleration?r.acceleration.set(this.lifeAcceleration(n,this)):(r.acceleration[0]=this.updateScalarValue(this.lifeAcceleration.x,n,r.acceleration[0]),r.acceleration[1]=this.updateScalarValue(this.lifeAcceleration.y,n,r.acceleration[1]),r.acceleration[2]=this.updateScalarValue(this.lifeAcceleration.z,n,r.acceleration[2])));let i=r.velocity[0],s=r.velocity[1],o=r.velocity[2];i*=r.velocity[3],s*=r.velocity[3],o*=r.velocity[3],i+=r.acceleration[0]*t.deltaTime,s+=r.acceleration[1]*t.deltaTime,o+=r.acceleration[2]*t.deltaTime,r.velocity[3]=Math.sqrt(i*i+s*s+o*o),r.velocity[0]=i/r.velocity[3],r.velocity[1]=s/r.velocity[3],r.velocity[2]=o/r.velocity[3],this.lifeSpeed&&("function"==typeof this.lifeSpeed?r.velocity[3]=this.lifeSpeed(n):r.velocity[3]=this.updateScalarValue(this.lifeSpeed,n,r.velocity[3])),r.pos[0]+=r.velocity[0]*r.velocity[3]*t.deltaTime,r.pos[1]+=r.velocity[1]*r.velocity[3]*t.deltaTime,r.pos[2]+=r.velocity[2]*r.velocity[3]*t.deltaTime,this.lifeRotation&&("function"==typeof this.lifeRotation?r.rotation.set(this.lifeRotation(n,this)):(r.rotation[0]=this.updateScalarValue(this.lifeRotation.x,n,r.rotation[0]),r.rotation[1]=this.updateScalarValue(this.lifeRotation.y,n,r.rotation[1]),r.rotation[2]=this.updateScalarValue(this.lifeRotation.z,n,r.rotation[2])))}}updateParticleProperty(t,e,r){}emitOne(t){if(this.particleCount>=this.maxCount)return;let e=this.particlesBuffer[this.particleCount++],r=h.b.zero(),n=h.b.zero();this.emitter(this,t,r,n);const i=this.getScalarValue(this.lifetime);let s=this.getScalarValue(this.startSpeed);if(e.velocity.set(r),s<0&&h.b.negate(e.velocity,r),e.velocity[3]=Math.abs(s),e.pos.set(n),e.size[0]=this.getScalarValue(this.startSize),e.lifetime[0]=0,e.lifetime[1]=i,"function"==typeof this.startColor){let t=this.startColor(0,this);e.color.set(t)}else e.color[0]=this.getScalarValue(this.startColor.r),e.color[1]=this.getScalarValue(this.startColor.g),e.color[2]=this.getScalarValue(this.startColor.b),e.color[3]=this.getScalarValue(this.startColor.a);"function"==typeof this.startRotation?e.rotation.set(this.startRotation(0,this)):(e.rotation[0]=this.getScalarValue(this.startRotation.x),e.rotation[1]=this.getScalarValue(this.startRotation.y),e.rotation[2]=this.getScalarValue(this.startRotation.z)),"function"==typeof this.startAcceleration?e.acceleration.set(this.startAcceleration(0,this)):(e.acceleration[0]=this.getScalarValue(this.startAcceleration.x),e.acceleration[1]=this.getScalarValue(this.startAcceleration.y),e.acceleration[2]=this.getScalarValue(this.startAcceleration.z))}getScalarValue(t){return"number"==typeof t?t:"function"==typeof t?t(this):t instanceof Array?l.a.lerp(...t,Math.random()):(console.warn("Unknown property generator: ",t),0)}updateScalarValue(t,e,r){return null===t?r:"number"==typeof t?t:"function"==typeof t?t(e):t instanceof Array?l.a.lerp(...t,e):(console.log("Unknown property modifier:",t),r)}static boxEmitter(t){return(e,r,n,i)=>{i[0]=(Math.random()-.5)*t.x,i[1]=(Math.random()-.5)*t.y,i[2]=0,i.plus(r),h.b.minus(n,i,r).normalize()}}static circleEmitter(t){return(e,r,n,i)=>{const s=Math.sqrt(Math.random())*t,o=Math.random()*Math.PI*2;i.x=Math.cos(o)*s,i.y=Math.sin(o)*s,i.z=0,i.plus(r),h.b.minus(n,i,r).normalize()}}}g.VertexStructure=m,g.AttributeNames=p},function(t,e,r){"use strict";r.d(e,"b",(function(){return l})),r.d(e,"a",(function(){return d}));var n=r(0),i=r(6),s=r(24),o=r(1),a=r(27),u=r(49),c=r(21);class h{constructor(t=0){this.bound=new c.a(n.b.zero(),n.b.zero()),this.points=new Array}append(t){this.points.push(t),this.bound.min.x=Math.min(t.x,this.bound.min.x),this.bound.min.y=Math.min(t.y,this.bound.min.y),this.bound.max.x=Math.max(t.x,this.bound.max.x),this.bound.max.y=Math.max(t.y,this.bound.max.y)}}class l extends a.a{constructor(...t){super(),this.chunks=new Map,this.materials[0]=u.a.tilemapDefault,0===t.length?(this.chunkSize=16,this.ChunkType=d):1===t.length?"number"==typeof t[0]?(this.chunkSize=t[0],this.ChunkType=d):(this.chunkSize=16,this.ChunkType=t[0]):[this.chunkSize,this.ChunkType]=t}render(t,e){this.eventEmitter.with().emit("render",this,t,e);let r=Object(n.b)(e.camera.viewHeight*e.camera.aspectRatio,e.camera.viewHeight),[s]=this.chunkPos(Object(i.h)(e.camera.position.toVec2(),r)),[o]=this.chunkPos(Object(i.j)(e.camera.position.toVec2(),r));for(let e=s.y;e<=o.y;e++)for(let r=s.x;r<=o.x;r++){const i=this.getOrCreateChunk(Object(n.b)(r,e));t.renderer.drawMesh(i.mesh,this.localToWorldMatrix,this.materials[0])}}getTile(t){let[e,r]=this.chunkPos(n.b.math(Math.floor)(t));return this.getOrCreateChunk(e).getTile(r)}setTile(t,e){let[r,i]=this.chunkPos(n.b.math(Math.floor)(t));return this.getOrCreateChunk(r).setTile(i,e)}getChunkAt(t){let[e,r]=this.chunkPos(n.b.math(Math.floor)(t));return this.getOrCreateChunk(e)}visibleChunkRange(t){let e=Object(n.b)(t.viewHeight*t.aspectRatio,t.viewHeight),[r]=this.chunkPos(Object(i.h)(t.position.toVec2(),e)),[s]=this.chunkPos(Object(i.j)(t.position.toVec2(),e));return[r,Object(i.j)(s,1)]}getOrCreateChunk(t){const e=this.calcChunkID(t);let r=this.chunks.get(e);return r||(r=new this.ChunkType(t.mul(this.chunkSize),this.chunkSize),this.chunks.set(e,r),r)}getChunk(t){const e=this.calcChunkID(t);return this.chunks.get(e)}calcChunkID(t){let e=t.x,r=t.y;-0==t.x&&(e=0),-0==t.y&&(r=0);const n=r>=0?0:1;return(e>=0?0:1)<<31|Math.abs(Math.floor(e))<<16|n<<15|Math.abs(Math.floor(r))}destroy(){if(!this.destroyed){super.destroy();for(const t of this.chunks.values())t.destroy();this.chunks.clear()}}chunkPos(t){let e=n.b.math(Math.floor)(t);return[n.b.math(Math.floor)(Object(i.f)(e,this.chunkSize)),n.b.math(f)(e,Object(n.b)(this.chunkSize))]}}class d{constructor(t,e){this.polygons=[],this.dirty=!1,this.chunkSize=e,this.basePos=t,this.tiles=new Array(e*e),this.mesh=function(t,e){const r=new s.a(e*e*4,e*e*6),i=[{vert:Object(o.b)(0),uv:Object(n.b)(0,0)},{vert:Object(o.b)(0),uv:Object(n.b)(1,0)},{vert:Object(o.b)(0),uv:Object(n.b)(1,1)},{vert:Object(o.b)(0),uv:Object(n.b)(0,1)}];for(let n=0;n<e;n++)for(let s=0;s<e;s++)i[0].vert.set([s+t.x,n+t.y,0]),i[1].vert.set([s+1+t.x,n+t.y,0]),i[2].vert.set([s+1+t.x,n+1+t.y,0]),i[3].vert.set([s+t.x,n+1+t.y,0]),r.addPolygon(...i);return r.toMesh()}(t,e)}getTile(t){const e=t.y*this.chunkSize+t.x;return this.tiles[e]}setTile(t,e){var r;let n=t.y*this.chunkSize+t.x;(null===(r=this.tiles[n])||void 0===r?void 0:r.collide)!==(null==e?void 0:e.collide)&&(this.dirty=!0),this.tiles[n]=e,n*=4,(null==e?void 0:e.sprite)&&(this.mesh.vertices[n+0].uv.set([e.sprite.uvRect.xMin,e.sprite.uvRect.yMin]),this.mesh.vertices[n+1].uv.set([e.sprite.uvRect.xMax,e.sprite.uvRect.yMin]),this.mesh.vertices[n+2].uv.set([e.sprite.uvRect.xMax,e.sprite.uvRect.yMax]),this.mesh.vertices[n+3].uv.set([e.sprite.uvRect.xMin,e.sprite.uvRect.yMax]),this.mesh.vertices[n+0].color.set(e.sprite.color),this.mesh.vertices[n+1].color.set(e.sprite.color),this.mesh.vertices[n+2].color.set(e.sprite.color),this.mesh.vertices[n+3].color.set(e.sprite.color),this.mesh.update())}destroy(){this.mesh.destroy()}getPolygons(){return this.dirty&&(this.polygons=Array.from(this.enumPolygons())),this.dirty=!1,this.polygons}*enumPolygons(){const t=(t,e)=>0<=t&&t<this.chunkSize&&0<=e&&e<this.chunkSize,e=new Array((this.chunkSize+1)*(this.chunkSize+1)*(this.chunkSize+1)*(this.chunkSize+1)),r=(e,r)=>t(e,r)?this.tiles[r*this.chunkSize+e]:null,i=(t,e)=>{var n,i,s,o,a;return(null===(n=r(t,e))||void 0===n?void 0:n.collide)?(null===(i=r(t-1,e))||void 0===i?void 0:i.collide)?(null===(s=r(t+1,e))||void 0===s?void 0:s.collide)?(null===(o=r(t,e-1))||void 0===o?void 0:o.collide)?(null===(a=r(t,e+1))||void 0===a?void 0:a.collide)?0:l:d:c:u:0},s=(t,e)=>e*this.chunkSize+t,o=(t,e)=>s(t.x,t.y)*(this.chunkSize+1)*(this.chunkSize+1)+s(e.x,e.y),a=(t,i,s)=>{var a,h,f,b,m,p,v,g,y,x,M,w;const R=[t,i];let _=t.clone();for(;;){let t=R[R.length-1];if(e[o(_,t)]){R.length-=1,R[0].equals(R[R.length-1])&&(R.length-=1);break}switch(e[o(_,t)]=!0,_.set(t),s){case l:if(null===(a=r(t.x,t.y))||void 0===a?void 0:a.collide)R.push(Object(n.b)(t.x+1,t.y)),s=c;else if(null===(h=r(t.x-1,t.y))||void 0===h?void 0:h.collide)t.y+=1;else{if(!(null===(f=r(t.x-1,t.y-1))||void 0===f?void 0:f.collide))throw new Error("Invalid tilemap");R.push(Object(n.b)(t.x-1,t.y)),s=u}break;case u:if(null===(b=r(t.x-1,t.y))||void 0===b?void 0:b.collide)R.push(Object(n.b)(t.x,t.y+1)),s=l;else if(null===(m=r(t.x-1,t.y-1))||void 0===m?void 0:m.collide)t.x-=1;else{if(!(null===(p=r(t.x,t.y-1))||void 0===p?void 0:p.collide))throw new Error("Invalid tilemap");R.push(Object(n.b)(t.x,t.y-1)),s=d}break;case d:if(null===(v=r(t.x-1,t.y-1))||void 0===v?void 0:v.collide)R.push(Object(n.b)(t.x-1,t.y)),s=u;else if(null===(g=r(t.x,t.y-1))||void 0===g?void 0:g.collide)t.y-=1;else{if(!(null===(y=r(t.x,t.y))||void 0===y?void 0:y.collide))throw new Error("Invalid tilemap");R.push(Object(n.b)(t.x+1,t.y)),s=c}break;case c:if(null===(x=r(t.x,t.y-1))||void 0===x?void 0:x.collide)R.push(Object(n.b)(t.x,t.y-1)),s=d;else if(null===(M=r(t.x,t.y))||void 0===M?void 0:M.collide)t.x+=1;else{if(!(null===(w=r(t.x-1,t.y))||void 0===w?void 0:w.collide))throw new Error("Invalid tilemap");R.push(Object(n.b)(t.x,t.y+1)),s=l}}}return R},u=1,c=2,l=3,d=4;for(let t=0;t<this.chunkSize;t++)for(let r=0;r<this.chunkSize;r++){const s=i(r,t);if(!s)continue;let f,b,m;switch(s){case u:f=Object(n.b)(r,t+1),b=Object(n.b)(r,t),m=d;break;case d:f=Object(n.b)(r,t),b=Object(n.b)(r+1,t),m=c;break;case c:f=Object(n.b)(r+1,t),b=Object(n.b)(r+1,t+1),m=l;break;case l:f=Object(n.b)(r+1,t+1),b=Object(n.b)(r,t+1),m=d}if(!e[o(f,b)]){const t=a(f,b,m),e=new h(t.length);for(const r of t)e.append(r.plus(this.basePos));yield e}}}}function f(t,e){return t>=0?t%e:(e+t%e)%e}},function(t,e,r){"use strict";r.d(e,"a",(function(){return u}));var n=r(36),i=r(50),s=r(17),o=r(11),a=r(9);class u extends n.a{constructor(){super(...arguments),this.lines=new i.b}drawLine(t,e,r=o.a.white){const n=this.lines.verts,i=this.lines.lines,s=this.lines.colors,a=n.length;n.push(t,e),s.push(r,r),i.push(a,a+1),this.lines.verts=n,this.lines.colors=s,this.lines.lines=i}render(t,e){t.renderer.setFramebuffer(s.a.CanvasBuffer),t.renderer.drawLines(this.lines,a.b.identity(),t.renderer.assets.materials.ColoredLine),this.lines.clear()}}},function(t,e,r){"use strict";r.d(e,"b",(function(){return n})),r.d(e,"a",(function(){return i}));class n{__addCollider(){}__removeCollider(){}__getColliders(){return[]}update(){}}class i{constructor(){this._physicsSystem=null,this._entity=null}get physics(){return this._physicsSystem}get entity(){return this._entity}__bind(t,e){if(this.entity&&this.entity!==t)throw new Error("Collider should only be bound to single entity.");this._entity=t,this._physicsSystem=e.physics,this._physicsSystem.__addCollider(this)}__unbind(){this._entity=null,this.__unbindPhysics()}__unbindPhysics(){var t;null===(t=this._physicsSystem)||void 0===t||t.__removeCollider(this),this._physicsSystem=null}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return o}));var n=r(9),i=r(1),s=r(22);class o{constructor(){this._parent=null,this.children=new Set,this._localPosition=i.b.zero(),this._localRotation=s.b.identity(),this._localScaling=i.b.one(),this._rotation=s.b.identity(),this._inv_rotation=s.b.identity(),this._localToWorld=n.b.identity(),this._worldToLocal=n.b.identity(),this._scene=null}get localPosition(){return this._localPosition}get localRotation(){return this._localRotation}get localScaling(){return this._localScaling}set localPosition(t){this._localPosition.set(t),this.updateTransformRecursive()}set localRotation(t){this._localRotation.set(t),this.updateTransformRecursive()}set localScaling(t){this._localScaling.set(t),this.updateTransformRecursive()}get scene(){return this._scene}get position(){return this._parent?n.b.mulPoint(this._parent.localToWorldMatrix,this.localPosition):this.localPosition}set position(t){this._parent?n.b.mulPoint(this._localPosition,this._parent.worldToLocalMatrix,t):this.localPosition.set(t),this.updateTransformRecursive()}get rotation(){return this._rotation}set rotation(t){this._parent?(s.b.mul(this._localRotation,this._parent._inv_rotation,t),s.b.normalize(this._localRotation,this._localRotation)):s.b.normalize(this._localRotation,t),this.updateTransformRecursive()}get localToWorldMatrix(){return this._localToWorld}get worldToLocalMatrix(){return this._worldToLocal}get parent(){return this._parent}set parent(t){this._parent=t,t&&t.children.add(this),this.updateTransformRecursive()}translate(t){this._parent?this.localPosition.plus(n.b.mulVector(this._parent.worldToLocalMatrix,t)):this.localPosition.plus(t),this.updateTransformRecursive()}__addToScene(t){this._scene=t}__removeFromScene(t){this._scene=null}updateTransformRecursive(){this._rotation.set(this._localRotation),n.b.rts(this._localToWorld,this._localRotation,this._localPosition,this._localScaling),this._parent&&(n.b.mul(this._localToWorld,this._parent._localToWorld,this._localToWorld),s.b.mul(this._rotation,this._parent._rotation,this._rotation)),n.b.invert(this._worldToLocal,this._localToWorld),s.b.invert(this._inv_rotation,this._rotation);for(const t of this.children)t.updateTransformRecursive()}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return o}));var n=r(25),i=r(28),s=r(15);class o extends n.b{constructor(t){super(),this.engine=void 0,this.eventEmitter=new i.a,this.addsNextFrame=new Map,this.removesNextFrame=new Set,this.assetID=s.b.newAssetID(this),this.name="Scene_"+this.assetID,this.physics=new t}add(t,e=null){if(t.destroyed)console.error("Attempt to add destroyed entity");else{this.addsNextFrame.set(t,e);for(const e of t.children)this.add(e,t)}}remove(t){this.removesNextFrame.add(t)}rootEntities(){return this._entities.filter(t=>null===t.parent)}getEntities(){return this._entities}getEntitiesOfType(t){return this.entities.filter(e=>e instanceof t)}withPhysics(t){return this.physics=t,this}on(t,e){this.eventEmitter.on(t,e)}off(t,e){this.eventEmitter.off(t,e)}clearAll(){var t,e;const r=null!==(e=null===(t=this.engine)||void 0===t?void 0:t.time)&&void 0!==e?e:{time:0,deltaTime:0};for(const t of this._entities)t.destroy();this.addsNextFrame.clear(),this.removesNextFrame.clear(),this.removePendingEntites(r),this._entities=[],this.entityMap.clear()}destroy(){this.clearAll()}__update(t){var e;this.addPendingEntities(t),this.removePendingEntites(t);const r=this.rootEntities();for(const e of r)e.__updateRecursive(t);null===(e=this.physics)||void 0===e||e.update(t)}addPendingEntities(t){const e=this.addsNextFrame;this.addsNextFrame=new Map;for(const[t,r]of e){super.add(t),t.__addToScene(this);t.constructor;r&&(t.parent=r),this.eventEmitter.emit("entity-add",t,r||null)}for(const[r,n]of e)r.__start(t)}removePendingEntites(t){const e=this.removesNextFrame;this.removesNextFrame=new Set;for(const t of e)super.remove(t),t.__removeFromScene(this),this.eventEmitter.emit("entity-remove",t,t.parent);for(const r of e)r.__exit(t)}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return s}));var n=r(39),i=r(43);const s={spriteDefault:new n.a,tilemapDefault:new n.a,particleDefault:new i.a}},function(t,e,r){"use strict";r.d(e,"b",(function(){return a})),r.d(e,"a",(function(){return u}));var n=r(11),i=r(3),s=r(10),o=r(15);class a extends o.a{constructor(t=Object(i.b)()){var e,r;super(),this._verts=[],this._colors=[],this._lines=[],this.dirty=!0,this.vertices=new Float32Array(0),this.indices=new Uint32Array(0),this.name="Lines_"+this.assetID,this.gl=t,this.VBO=null!==(e=t.createBuffer())&&void 0!==e?e:Object(s.c)("Failed to create vertex buffer."),this.EBO=null!==(r=t.createBuffer())&&void 0!==r?r:Object(s.c)("Failed to create element buffer.")}get verts(){return this._verts}set verts(t){this._verts=t,this.dirty=!0}get colors(){return this._colors}set colors(t){this._colors=t,this.dirty=!0}get lines(){return this._lines}set lines(t){this._lines=t,this.dirty=!0}clear(){this.verts=[],this.colors=[],this.lines=[]}update(){if(this.dirty){const t=this.gl;if(this.lines.length%2!=0)throw new Error("Invalid lines.");if(this.colors.length!==this.verts.length&&(this.colors=[...this.colors,...Object(s.a)(n.a.white,this.verts.length-this.colors.length)]),this.vertices=new Float32Array(this.verts.flatMap((t,e)=>[...t,...this.colors[e]])),this.vertices.length!=7*this.verts.length)throw new Error("Buffer with invalid length.");this.indices=new Uint32Array(this.lines.flat()),t.bindBuffer(t.ARRAY_BUFFER,this.VBO),t.bufferData(t.ARRAY_BUFFER,this.vertices,t.DYNAMIC_DRAW),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.EBO),t.bufferData(t.ELEMENT_ARRAY_BUFFER,this.indices,t.DYNAMIC_DRAW),this.dirty=!1}}bind(t){const e=this.gl;this.update();const r=t.attributes;e.bindBuffer(e.ARRAY_BUFFER,this.VBO),r.vert>=0&&(e.vertexAttribPointer(r.vert,3,e.FLOAT,!1,28,0),e.enableVertexAttribArray(r.vert)),r.color>=0&&(e.vertexAttribPointer(r.color,4,e.FLOAT,!1,28,12),e.enableVertexAttribArray(r.color)),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.EBO)}destroy(){this.destroyed||(this.gl.deleteBuffer(this.VBO),this.gl.deleteBuffer(this.EBO),super.destroy())}}class u{constructor(t=0,e=Object(i.b)()){this.verts=[],this.colors=[],this.lines=[],this.gl=e}addLine(t,e=n.a.white){const r=this.verts.length,[i,s]=t;this.verts.push(i,s),this.colors.push(e,e),this.lines.push(r,r+1)}toLines(){const t=new a(this.gl);return t.verts=this.verts,t.colors=this.colors,t.lines=this.lines,t.update(),t}}},function(t,e,r){"use strict";r.d(e,"b",(function(){return i})),r.d(e,"a",(function(){return s}));var n=r(3);class i{constructor(){this.mainAsset=null,this.assets=new Map}add(t,e){e.name=t,this.assets.set(t,e)}setMain(t){this.mainAsset=t}get(t){for(const[e,r]of this.assets)if(r instanceof t)return r;return null}getAll(t){return Array.from(this.assets.values()).filter(e=>e instanceof t)}}class s{constructor(t){this.importers=t}async url(t,e=Object(n.d)()){const r=await fetch(t).then(t=>t.arrayBuffer());return await this.buffer(r,e)}async blob(t,e=Object(n.d)()){const r=await t.arrayBuffer();return await this.buffer(r,e)}async buffer(t,e=Object(n.d)()){const r={};for(const n in this.importers)r[n]=r=>this.importers[n].import(t,r,e);return r}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return M}));var n=r(10),i=r(3),s=r(11),o=r(9),a=r(17),u=r(12),c=r(0),h=r(8),l=function(t,e,r,n){var i,s=arguments.length,o=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(o=(s<3?i(o):s>3?i(e,r,o):i(e,r))||o);return s>3&&o&&Object.defineProperty(e,r,o),o};var d=r(18),f=r(20),b=r(14);var m=r(1),p=r(24);class v{constructor(t){const e=t.gl;this.gl=e,t.assets=this,this.BuiltinUniforms=d.a,this.shaderSources=f.BuiltinShaderSources,this.shaders=Object(d.b)(e),this.meshes=function(t){return{quad:p.a.quad(c.b.zero(),c.b.one(),t),screenQuad:p.a.ndcQuad(t),cube:p.a.cube(m.b.zero(),m.b.one(),t)}}(t),this.textures=function(t){var e;const r=document.createElement("canvas");r.width=r.height=64;const i=null!==(e=r.getContext("2d"))&&void 0!==e?e:Object(n.c)("Failed to create default texture.");i.fillStyle="black",i.fillRect(0,0,64,64),i.fillStyle="cyan",i.fillRect(0,0,32,32),i.fillRect(32,32,32,32);const s=new u.e(64,64,b.a.RGBA,u.b.Linear,t);s.setData(r),s.name="Texture-Error",i.fillStyle="blue",i.fillRect(0,0,64,64);const o=new u.e(64,64,b.a.RGBA,u.b.Linear,t);o.setData(r),o.name="Default-Normal",i.fillStyle="white",i.fillRect(0,0,64,64);const a=new u.e(64,64,b.a.RGBA,u.b.Linear,t);return a.setData(r),a.name="Default-White",{default:a,defaultNormal:o,error:s}}(t),this.types=function(t,e,r){let n=class extends(Object(h.b)(r.DefaultShader)){constructor(){super(...arguments),this.color=s.a.white,this.mainTexture=e.default}};l([Object(h.e)("uColor","color")],n.prototype,"color",void 0),l([Object(h.e)("uMainTex","tex2d")],n.prototype,"mainTexture",void 0),n=l([h.d],n);let i=class extends(Object(h.b)(r.BlitCopy)){constructor(){super(...arguments),this.source=null,this.flip=Object(c.b)(0,0)}};l([Object(h.e)("uMainTex","tex2d")],i.prototype,"source",void 0),l([Object(h.e)("uFlip","vec2")],i.prototype,"flip",void 0),i=l([h.d],i);let o=class extends(Object(h.b)(r.DefaultShader)){constructor(){super(...arguments),this.color=s.a.white,this.mainTexture=e.default,this.normalTexture=e.defaultNormal,this.emission=s.a.black,this.specular=s.a.white,this.metiallic=.023,this.smoothness=.5,this.fresnel=5}};return l([Object(h.e)("uColor","color")],o.prototype,"color",void 0),l([Object(h.e)("uMainTex","tex2d")],o.prototype,"mainTexture",void 0),l([Object(h.e)("uNormalTex","tex2d")],o.prototype,"normalTexture",void 0),l([Object(h.e)("uEmission","color")],o.prototype,"emission",void 0),l([Object(h.e)("uSpecular","color")],o.prototype,"specular",void 0),l([Object(h.e)("uMetallic","float")],o.prototype,"metiallic",void 0),l([Object(h.e)("uSmoothness","float")],o.prototype,"smoothness",void 0),l([Object(h.e)("uFresnel","float")],o.prototype,"fresnel",void 0),o=l([h.d],o),{DefaultMaterial:n,BlitCopy:i,DefaultLit:o}}(0,this.textures,this.shaders),this.materials=function(t,e,r,n){const i=new h.a(r.ErrorShader,t);return i.setProp("uMainTex","tex2d",n.error),{error:i,default:new e.DefaultMaterial(t),blitCopy:new e.BlitCopy(t),ColoredLine:new h.a(r.ColoredLine,t)}}(e,this.types,this.shaders,this.textures)}}var g=r(21),y=r(6);class x{constructor(t){this.pool=[],this.allocator=t}get(...t){return this.pool.length<=0?this.allocator(...t):this.pool.pop()}release(t){this.pool.push(t)}}class M{constructor(t,e,r){this.viewProjectionMatrix=o.b.identity(),this.viewMatrix=o.b.identity(),this.projectionMatrix=o.b.identity(),this.target=a.a.CanvasBuffer,this.shader=null,this.globalUniforms=new Map,this.globalTextures=new Map,this.framebufferPool=new x((t,e)=>new a.a(t,e)),this.blitFramebuffer=[new a.a,new a.a],this.canvas=t,this.width=void 0===e?t.width:e,this.height=void 0===r?t.height:r,this.canvas.width=this.width,this.canvas.height=this.height,this.scissor=new g.a(c.b.zero(),Object(c.b)(this.width,this.height)),this.gl=Object(n.d)(this.canvas.getContext("webgl2"),"WebGL2 is not support on current device."),this.gl.getExtension("EXT_color_buffer_float"),this.gl.getExtension("EXT_color_buffer_half_float"),this.ctx=new i.c,Object.assign(this.ctx,{gl:this.gl,width:this.width,height:this.height,assets:{},renderer:this}),this.assets=new v(this.ctx),this.ctx.assets=this.assets,Object(i.d)()||this.use(),this.helperAssets={clipBlitMesh:p.a.ndcQuad(),blitMesh:p.a.ndcTriangle()}}use(){Object(i.e)(this.ctx)}setSize(t,e){t=Math.floor(t),e=Math.floor(e),this.canvas.width=t,this.canvas.height=e,this.width=t,this.height=e,this.ctx.width=t,this.ctx.height=e}get canvasSize(){return Object(c.b)(this.width,this.height)}setViewProjection(t,e){o.b.mul(this.viewProjectionMatrix,e,t)}setFramebuffer(t,e){let r;if(t===a.a.CanvasBuffer)r=a.a.CanvasBuffer;else if(t instanceof a.a)r=t;else if(t instanceof Array){let n=0,i=0;t.length>0?(n=t[0].width,i=t[0].height):e&&(n=e.width,i=e.height);const s=this.getTempFramebuffer(n,i);for(let e=0;e<t.length;e++)s.addColorAttachment(t[e],e);e&&s.setDepthAttachment(e),r=s}else{const n=t,i=this.getTempFramebuffer(n.width,n.height);i.addColorAttachment(n,0),e&&i.setDepthAttachment(e),r=i}r!==this.target&&(this.detachCurrentFramebuffer(),this.target=r),this.scissor.min.set([0,0]),this.scissor.max.set(this.target.size),this.target.bind()}detachCurrentFramebuffer(){this.target.__isTemp&&this.framebufferPool.release(this.target)}getTempFramebuffer(t,e){const r=this.framebufferPool.get(t,e);return r.__isTemp=!0,r.reset(t,e),r}blitCopy(t,e){const r=this.gl,[n,i]=this.blitFramebuffer;n.reset(t.width,t.height),n.addColorAttachment(t),n.bind(),i.reset(t.width,t.height),r.bindFramebuffer(r.READ_FRAMEBUFFER,n.glFBO()),t instanceof u.c?r.framebufferTexture2D(r.READ_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.RENDERBUFFER,t.glTex(),0):r.framebufferRenderbuffer(r.READ_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.RENDERBUFFER,t.glBuf()),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,i.glFBO()),e instanceof u.c?r.framebufferTexture2D(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,e.glTex(),0):r.framebufferRenderbuffer(r.DRAW_FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,e.glBuf()),r.blitFramebuffer(0,0,t.width,t.height,0,0,e.width,e.height,r.COLOR_BUFFER_BIT,r.NEAREST),r.bindFramebuffer(r.READ_FRAMEBUFFER,null),r.bindFramebuffer(r.DRAW_FRAMEBUFFER,null)}clear(t=s.a.black,e=!0){this.gl.clearColor(t.r,t.g,t.b,t.a),this.gl.clear(this.gl.COLOR_BUFFER_BIT|(e?this.gl.DEPTH_BUFFER_BIT:0))}blit(t,e,r=this.assets.materials.blitCopy,n,i){const s=this.target;this.setFramebuffer(e),e=this.target;const u=this.viewProjectionMatrix;let h=this.helperAssets.blitMesh,l=e===a.a.CanvasBuffer?new g.a(c.b.zero(),this.canvasSize):new g.a(c.b.zero(),e.size.clone());if(t&&(n||i)&&(l=i||l,n)){h=this.helperAssets.clipBlitMesh;let e=Object(y.f)(n.min,t.size),r=Object(y.f)(n.max,t.size);h.uvs=[Object(c.b)(e.x,e.y),Object(c.b)(r.x,e.y),Object(c.b)(r.x,r.y),Object(c.b)(e.x,r.y)],h.update()}this.target=e,this.scissor=l,this.viewProjectionMatrix=o.b.identity(),t&&r.setProp(d.a.mainTex,"tex2d",t),this.drawMesh(h,o.b.identity(),r),this.setFramebuffer(s),this.viewProjectionMatrix=u}useShader(t){this.gl;this.shader=t,t.use()}setupTransforms(t,e){this.gl;const r=o.b.mul(this.viewProjectionMatrix,e),n=o.b.create();o.b.invert(n,e)?o.b.transpose(n,n):n.fill(0);const i=o.b.mul(this.viewMatrix,e);o.b.invert(i,i)?o.b.transpose(i,i):i.fill(0),t.setupBuiltinUniform({matM:e,matVP:this.viewProjectionMatrix,matMVP:r,matM_IT:n,matMV_IT:i})}setupGlobalUniforms(t){for(const e of this.globalUniforms.values())t.setUniformDirectly(e.name,e.type,e.value)}drawMeshInstance(t,e,r,n){r||(r=this.assets.materials.error);const i=this.gl,s={assets:this.assets,gl:i,nextTextureUnit:0,size:Object(c.b)(this.width,this.height)};this.target.bind(),this.setupScissor(),this.useShader(r.shader),r.upload(s),this.setupTransforms(r.shader,o.b.identity());const a=t.bind();e.bindVertexArray(!0,r.shader.attributes),i.drawElementsInstanced(i.TRIANGLES,a,i.UNSIGNED_INT,0,n),e.unbindVertexArray(!0,r.shader.attributes),t.unbind(),r.unbindRenderTextures()}drawMeshProceduralInstance(t,e,r){e||(e=this.assets.materials.error);const n=this.gl,i={assets:this.assets,gl:n,nextTextureUnit:0,size:Object(c.b)(this.width,this.height)};this.target.bind(),this.setupScissor(),this.useShader(e.shader),e.upload(i),this.setupTransforms(e.shader,o.b.identity());const s=t.bind();n.drawElementsInstanced(n.TRIANGLES,s,n.UNSIGNED_INT,0,r),e.unbindRenderTextures()}drawMesh(t,e,r){r||(r=this.assets.materials.error);const n=this.gl,i={assets:this.assets,gl:n,nextTextureUnit:0,size:Object(c.b)(this.width,this.height)};this.target.bind(),this.setupScissor(),this.useShader(r.shader),r.upload(i),this.setupTransforms(r.shader,e),this.setupGlobalUniforms(r);let s=t.bind();n.drawElements(n.TRIANGLES,s,n.UNSIGNED_INT,0),t.unbind(),r.unbindRenderTextures()}drawLines(t,e,r){const n=this.gl,i={assets:this.assets,gl:n,nextTextureUnit:0,size:Object(c.b)(this.width,this.height)};this.target.bind(),this.setupScissor(),this.useShader(r.shader),r.upload(i),this.setupTransforms(r.shader,e),t.bind(r.shader),n.drawElements(n.LINES,t.lines.length,n.UNSIGNED_INT,0)}setGlobalUniform(t,e,r){this.globalUniforms.set(t,{name:t,type:e,value:r})}unsetGlobalUniform(t){this.globalUniforms.delete(t)}setupScissor(){this.gl.viewport(this.scissor.xMin,this.scissor.yMin,this.scissor.size.x,this.scissor.size.y)}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return f}));var n=r(14),i=r(12),s=r(9),o=r(57),a=r(29),u=r(11),c=r(17),h=r(50),l=r(1),d=r(45);class f{constructor(t){this.msaa=4,this.materialReplaceMap=new Map,this.debugLayer=new d.a,this.cameraOutputFBOs=new Map,this.cameraOutputTextures=new Map,this.renderer=t;const e=Object(u.d)(1,1,1,.1),r=new h.a(0,t.gl);for(let t=-10;t<=10;t+=1)r.addLine([Object(l.b)(t,0,-10),Object(l.b)(t,0,10)],e),r.addLine([Object(l.b)(-10,0,t),Object(l.b)(10,0,t)],e);this.grid=r.toLines()}render(t,e,r){for(let n=0;n<r.length;n++){const i=a.a.create(r[n],e,this.getFramebuffer(t,r[n]));this.renderCamera(t,i)}}setupLight(t,e){t.renderer.setGlobalUniform("uLightDir","vec3",Object(l.b)(-1,1,0).normalize()),t.renderer.setGlobalUniform("uAmbientSky","color",Object(u.c)(.2,.2,.2)),t.renderer.setGlobalUniform("uLightPos","vec3",e.camera.position.clone()),t.renderer.setGlobalUniform("uLightColor","color",Object(u.c)(.8,.8,.8))}renderCamera(t,e){const r=e.camera;r.__preRender(t),t.renderer.setFramebuffer(e.cameraOutput),t.renderer.clear(r.clearColor,r.clearDepth),t.renderer.setViewProjection(r.worldToLocalMatrix,r.projectionMatrix),t.renderer.setGlobalUniform("uCameraPos","vec3",r.position.clone()),this.setupLight(t,e);const n=e.getVisibleObjects(a.b.NearToFar);for(const r of n)r.render(t,e);this.renderGrid(t,e),this.finalBlit(t,e),r.__postRender(t)}finalBlit(t,e){var r,s,o,a;const u=e.camera;let h=this.cameraOutputTextures.get(u);h||(h=new i.c(null!==(s=null===(r=e.camera.output)||void 0===r?void 0:r.width)&&void 0!==s?s:t.renderer.canvasSize.x,null!==(a=null===(o=e.camera.output)||void 0===o?void 0:o.height)&&void 0!==a?a:t.renderer.canvasSize.y,!1,n.a.RGBA,i.b.Linear),this.cameraOutputTextures.set(u,h)),t.renderer.blitCopy(e.cameraOutput.colorAttachments[0],h),t.renderer.blit(h,c.a.CanvasBuffer)}renderGrid(t,e){this.renderer.drawLines(this.grid,s.b.identity(),this.renderer.assets.materials.ColoredLine)}drawWithMaterial(t,e,r){this.materialReplaceMap.has(r.constructor)?this.renderer.drawMesh(t,e,this.materialReplaceMap.get(r.constructor)):this.renderer.drawMesh(t,e,r)}replaceMaterial(t,e){this.materialReplaceMap.set(t,e)}getFramebuffer(t,e){let r=this.cameraOutputFBOs.get(e);if(!r){r=new c.a(t.renderer.canvas.width,t.renderer.canvas.height);const i=new o.b(r.width,r.height,n.a.RGBA8,this.msaa);r.addColorAttachment(i),this.cameraOutputFBOs.set(e,r)}return r}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return m}));var n=r(8),i=r(7),s=r(13),o=r(12),a=r(3),u=r(11),c=r(0),h=r(6),l=r(14),d=r(19),f=function(t,e,r,n){var i,s=arguments.length,o=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(o=(s<3?i(o):s>3?i(e,r,o):i(e,r))||o);return s>3&&o&&Object.defineProperty(e,r,o),o};class b extends(Object(n.b)(new i.e(...d.ShaderSource.boxBlur))){constructor(){super(...arguments),this.texture=null,this.textureSize=s.b.one(),this.sampleOffset=1}}f([Object(n.e)("uMainTex","tex2d")],b.prototype,"texture",void 0),f([Object(n.e)("uTexSize","vec4")],b.prototype,"textureSize",void 0),f([Object(n.e)("uSampleOffset","float")],b.prototype,"sampleOffset",void 0);class m{constructor(){this.steps=[],this.downsampleMaterial=new b,this.upsampleMaterial=new b}init(t){this.steps[0]||(this.steps[0]=new o.c(t.width,t.height,!1,t.format,t.filterMode),this.steps[0].wrapMode=o.g.Clamp,this.steps[0].updateParameters()),this.steps[0].width===t.width&&this.steps[0].height===t.height||this.steps[0].resize(t.width,t.height,o.f.Discard)}blur(t,e=4,r=this.steps[0],n=Object(a.d)()){return r==this.steps[0]&&(this.steps[0]||(this.steps[0]=new o.c(t.width,t.height,!1,t.format,t.filterMode)),this.init(t),r=this.steps[0]),n.renderer.setFramebuffer(r),n.renderer.clear(u.a.black),this.downSample(n.renderer,t,e),this.upSample(n.renderer,e,r)}downSample(t,e,r){for(let n=1;n<=r;n++){const r=c.b.floor(Object(h.f)(e.size,Object(c.b)(2)));this.steps[n]||(this.steps[n]=new o.c(r.x,r.y,!1,l.a.RGBA,o.b.Linear),this.steps[n].wrapMode=o.g.Clamp,this.steps[n].updateParameters());const i=this.steps[n];i.width===r.x&&i.height===r.y||i.resize(r.x,r.y,o.f.Discard),this.downsampleMaterial.texture=e,this.downsampleMaterial.textureSize=Object(s.b)(e.width,e.height,1/e.width,1/e.height),this.downsampleMaterial.sampleOffset=1,t.blit(e,i,this.downsampleMaterial),e=i}}upSample(t,e,r=this.steps[0]){let n=this.steps[e];for(let i=e-1;i>=0;i--){const e=Object(h.i)(n.size,Object(c.b)(2));this.steps[i]||(this.steps[i]=new o.c(e.x,e.y,!1,l.a.RGBA,o.b.Linear),this.steps[i].wrapMode=o.g.Clamp,this.steps[i].updateParameters());const a=0===i?r:this.steps[i];this.upsampleMaterial.texture=n,this.upsampleMaterial.textureSize=Object(s.b)(n.width,n.height,1/n.width,1/n.height),this.upsampleMaterial.sampleOffset=.5,t.blit(n,a,this.upsampleMaterial),n=a}return n}}},function(t,e,r){"use strict";var n=r(4),i=r(0);r.d(e,"h",(function(){return i.a})),r.d(e,"y",(function(){return i.b}));var s=r(1);r.d(e,"i",(function(){return s.a})),r.d(e,"z",(function(){return s.b}));var o=r(13);r.d(e,"j",(function(){return o.a})),r.d(e,"A",(function(){return o.b}));var a=r(11);r.d(e,"a",(function(){return a.a})),r.d(e,"p",(function(){return a.b})),r.d(e,"w",(function(){return a.c})),r.d(e,"x",(function(){return a.d}));var u=r(6);r.d(e,"b",(function(){return u.a})),r.d(e,"f",(function(){return u.b})),r.d(e,"k",(function(){return u.c})),r.d(e,"l",(function(){return u.d})),r.d(e,"m",(function(){return u.e})),r.d(e,"n",(function(){return u.f})),r.d(e,"o",(function(){return u.g})),r.d(e,"r",(function(){return u.h})),r.d(e,"s",(function(){return u.i})),r.d(e,"t",(function(){return u.j}));var c=r(9);r.d(e,"d",(function(){return c.a})),r.d(e,"q",(function(){return c.b}));var h=r(22);r.d(e,"e",(function(){return h.a})),r.d(e,"u",(function(){return h.b}));var l=r(56);r.d(e,"v",(function(){return l.a}));var d=r(21);r.d(e,"g",(function(){return d.a}));var f=r(2);r.d(e,"c",(function(){return f.a})),n.a.setMatrixArrayType(Array)},function(t,e,r){"use strict";function n(t,e){return{origin:t,direction:e.normalized}}r.d(e,"a",(function(){return n}))},function(t,e,r){"use strict";r.d(e,"b",(function(){return u})),r.d(e,"a",(function(){return c}));var n=r(0),i=r(10),s=r(15),o=r(3),a=r(14);class u extends s.c{constructor(t,e,r=a.a.RGBA8,i=0,s=Object(o.d)()){super(s),this.multiSampling=0,this.format=a.a.RGBA8,this._glBuf=null,this.size=Object(n.b)(t,e),this.format=r,this.multiSampling=i,this.tryInit(!1)}get width(){return this.size.x}get height(){return this.size.y}glBuf(){return this.tryInit(!0),this._glBuf}resize(t,e){if(this.size.x=t,this.size.y=e,!this.initialized)return this;const r=this.ctx.gl;return r.bindRenderbuffer(r.RENDERBUFFER,this._glBuf),r.renderbufferStorageMultisample(r.RENDERBUFFER,this.multiSampling,this.format,this.size.x,this.size.y),r.bindRenderbuffer(r.RENDERBUFFER,null),this}updateParams(){this.tryInit(!0);const t=this.ctx.gl;t.bindRenderbuffer(t.RENDERBUFFER,this._glBuf),t.renderbufferStorageMultisample(t.RENDERBUFFER,this.multiSampling,this.format,this.size.x,this.size.y)}init(){var t;const e=this.ctx.gl;return this._glBuf=null!==(t=e.createRenderbuffer())&&void 0!==t?t:Object(i.c)("Failed to create render buffer."),e.bindRenderbuffer(e.RENDERBUFFER,this._glBuf),e.renderbufferStorageMultisample(e.RENDERBUFFER,this.multiSampling,this.format,this.size.x,this.size.y),e.bindRenderbuffer(e.RENDERBUFFER,null),!0}bindFramebuffer(t){this.tryInit(!0);const e=this.ctx.gl;e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.RENDERBUFFER,this._glBuf)}destroy(){super.destroy();this.ctx.gl.deleteRenderbuffer(this._glBuf)}}class c extends s.c{constructor(t,e,r=0,i=Object(o.d)()){super(i),this.multiSampling=0,this.format=a.a.RGBA8,this.glBuf=null,this.size=Object(n.b)(t,e),this.format=a.a.DEPTH_COMPONENT,this.multiSampling=r,this.tryInit(!1)}get width(){return this.size.x}set width(t){this.size.x=t}get height(){return this.size.y}set height(t){this.size.y=t}updateParams(){this.tryInit(!0);const t=this.ctx.gl;t.bindRenderbuffer(t.RENDERBUFFER,this.glBuf),t.renderbufferStorageMultisample(t.RENDERBUFFER,this.multiSampling,this.format,this.size.x,this.size.y)}init(){var t;const e=this.ctx.gl;return this.glBuf=null!==(t=e.createRenderbuffer())&&void 0!==t?t:Object(i.c)("Failed to create render buffer."),e.bindRenderbuffer(e.RENDERBUFFER,this.glBuf),e.renderbufferStorageMultisample(e.RENDERBUFFER,this.multiSampling,this.format,this.size.x,this.size.y),e.bindRenderbuffer(e.RENDERBUFFER,null),!0}bindFramebuffer(){this.tryInit(!0);const t=this.ctx.gl;t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,this.glBuf)}destroy(){super.destroy();this.ctx.gl.deleteRenderbuffer(this.glBuf)}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return n}));const n={create:t=>({renderer:t,screen:{width:t.canvas.width,height:t.canvas.height}})}},function(t,e,r){"use strict";r.d(e,"m",(function(){return i.b})),r.d(e,"c",(function(){return i.a})),r.d(e,"n",(function(){return s.a})),r.d(e,"j",(function(){return n})),r.d(e,"i",(function(){return u})),r.d(e,"d",(function(){return o.a})),r.d(e,"e",(function(){return o.b})),r.d(e,"o",(function(){return c.a})),r.d(e,"q",(function(){return h.a})),r.d(e,"r",(function(){return l.a})),r.d(e,"g",(function(){return d.b})),r.d(e,"f",(function(){return d.a})),r.d(e,"h",(function(){return d.c})),r.d(e,"p",(function(){return f.c})),r.d(e,"a",(function(){return f.a})),r.d(e,"b",(function(){return f.b})),r.d(e,"k",(function(){return b.a})),r.d(e,"l",(function(){return b.b}));var n,i=r(34),s=r(27),o=r(25),a=r(11);!function(t){t[t.Directional=0]="Directional",t[t.Point=1]="Point"}(n||(n={}));class u extends o.a{constructor(t=n.Directional){super(),this.intensity=1,this.color=a.a.white,this.type=t}}var c=r(48),h=r(47),l=r(62),d=r(31),f=r(76),b=r(43)},function(t,e,r){"use strict";r.d(e,"g",(function(){return n.a})),r.d(e,"j",(function(){return i.b})),r.d(e,"i",(function(){return i.a})),r.d(e,"h",(function(){return s.a})),r.d(e,"d",(function(){return o.a})),r.d(e,"e",(function(){return a.d})),r.d(e,"f",(function(){return a.e})),r.d(e,"a",(function(){return a.a})),r.d(e,"c",(function(){return a.c})),r.d(e,"b",(function(){return a.b})),r.d(e,"k",(function(){return u}));var n=r(53),i=r(29),s=r(58),o=r(64),a=r(61);class u{setup(t,e){}cleanup(t,e){}}},function(t,e,r){"use strict";r.d(e,"d",(function(){return i.a})),r.d(e,"e",(function(){return i.b})),r.d(e,"a",(function(){return s.a})),r.d(e,"c",(function(){return n})),r.d(e,"b",(function(){return a}));var n,i=r(38),s=r(74),o=r(54);!function(t){t[t.Downsample=0]="Downsample",t[t.Gussian=1]="Gussian"}(n||(n={}));class a extends i.a{constructor(t=n.Downsample){super(),this.radius=64,this.blurRenderer=new o.a,this.method=t}render(t,e,r){this.radius>0?this.blurRenderer.blur(e,Math.log2(this.radius),r):t.renderer.blit(e,r)}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return h}));var n=r(48),i=r(53),s=r(58),o=r(34),a=r(52),u=r(28),c=r(46);class h{constructor(t,e=i.a){this.fixedDeltaTime=!1,this._time={deltaTime:0,time:0},this.renderer=new a.a(t,t.width,t.height),this.renderPipeline=new e(this.renderer),this._scene=new n.a(c.b),this.eventEmitter=new u.a}get time(){return this._time}get scene(){return this._scene}set scene(t){const e=this._scene;this._scene=t,t.engine=this,this.eventEmitter.emit("scene-change",t,e)}renderScene(){const t=this.scene.getEntitiesOfType(o.a);this.renderPipeline.render(s.a.create(this.renderer),this.scene,t)}start(){let t=0,e=0,r=0;const n=i=>{if(0===t)return e=t=i,void requestAnimationFrame(n);this.fixedDeltaTime?r+=16:r=i;const s=(r-t)/1e3;t=r;const a={time:(r-e)/1e3,deltaTime:s};this._time=a,this.eventEmitter.emit("update",a),this.scene.__update(a),this.eventEmitter.emit("render",this.scene.getEntitiesOfType(o.a)),this.renderScene(),requestAnimationFrame(n)};requestAnimationFrame(n)}on(t,e){this.eventEmitter.on(t,e)}off(t,e){this.eventEmitter.off(t,e)}}},function(t,e,r){"use strict";var n=r(8);r.d(e,"u",(function(){return n.a})),r.d(e,"v",(function(){return n.b})),r.d(e,"B",(function(){return n.c})),r.d(e,"J",(function(){return n.d})),r.d(e,"K",(function(){return n.e}));var i=r(16);r.d(e,"h",(function(){return i.a})),r.d(e,"i",(function(){return i.b})),r.d(e,"w",(function(){return i.c})),r.d(e,"x",(function(){return i.d})),r.d(e,"G",(function(){return i.e}));var s=r(52);r.d(e,"I",(function(){return s.a}));var o=r(7);r.d(e,"c",(function(){return o.a})),r.d(e,"e",(function(){return o.b})),r.d(e,"g",(function(){return o.c})),r.d(e,"k",(function(){return o.d})),r.d(e,"A",(function(){return o.e}));var a=r(12);r.d(e,"l",(function(){return a.a})),r.d(e,"n",(function(){return a.b})),r.d(e,"z",(function(){return a.c})),r.d(e,"C",(function(){return a.d})),r.d(e,"D",(function(){return a.e})),r.d(e,"F",(function(){return a.f})),r.d(e,"H",(function(){return a.g}));var u=r(15);r.d(e,"a",(function(){return u.a})),r.d(e,"b",(function(){return u.b})),r.d(e,"q",(function(){return u.c})),r.d(e,"r",(function(){return u.d}));var c=r(50);r.d(e,"s",(function(){return c.a})),r.d(e,"t",(function(){return c.b}));var h=r(28);r.d(e,"m",(function(){return h.a}));var l=r(23);r.d(e,"d",(function(){return l.a})),r.d(e,"p",(function(){return l.b}));var d=r(57);r.d(e,"j",(function(){return d.a})),r.d(e,"y",(function(){return d.b}));var f=r(17);r.d(e,"o",(function(){return f.a}));var b=r(36);r.d(e,"f",(function(){return b.a}));var m=r(14);r.d(e,"E",(function(){return m.a}))},function(t,e,r){"use strict";r.d(e,"a",(function(){return z}));var n=r(14),i=r(57),s=r(0),o=r(29),a=r(11),u=r(17),c=r(45),h=r(3),l=r(23),d=r(12),f=r(24),b=r(13),m=r(1),p=r(8),v=r(7),g=r(16),y=r(33),x=r(19),M=r(26),w=function(t,e,r,n){var i,s=arguments.length,o=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(o=(s<3?i(o):s>3?i(e,r,o):i(e,r))||o);return s>3&&o&&Object.defineProperty(e,r,o),o};class R extends M.a{constructor(t,e){super(),this.light2DShadowMaterial=new _,this.lightComposeMaterial=new O,this.lightInstancingMaterial=new A,this.lightInstancingBuffer=new l.b(T,64),this.settings=e,this.lightmap=new d.c(t.screen.width,t.screen.height,!1,n.a.RGBA16F,d.b.Linear),this.simpleLightMesh=f.a.quad(s.b.zero(),Object(s.b)(2)),this.lightInstancingBuffer.static=!1}render(t,e){e.cameraOutput.size.equals(this.lightmap.size)||this.lightmap.resize(e.cameraOutput.width,e.cameraOutput.height,d.f.Discard);const r=e.scene.getEntitiesOfType(y.a),n=r.filter(t=>t.shadowType===y.d.Hard||t.shadowType===y.d.Soft),i=r.filter(t=>!1===t.shadowType);t.renderer.setFramebuffer(this.lightmap),t.renderer.clear(a.a.black),this.drawShadowLights(t,e,n),this.drawSimpleLights(t,e,i),t.renderer.blit(this.lightmap,e.cameraOutput,this.lightComposeMaterial)}drawSimpleLights(t,e,r){r.length>this.lightInstancingBuffer.length&&this.lightInstancingBuffer.resize(2*this.lightInstancingBuffer.length);for(let t=0;t<r.length;t++)b.b.set(this.lightInstancingBuffer[t].lightColor,r[t].lightColor),m.b.set(this.lightInstancingBuffer[t].lightPos,r[t].position),this.lightInstancingBuffer[t].lightParams[0]=r[t].volumnRadius,this.lightInstancingBuffer[t].lightParams[1]=r[t].lightRange,this.lightInstancingBuffer[t].lightParams[2]=r[t].attenuation,this.lightInstancingBuffer[t].lightParams[3]=r[t].intensity;t.renderer.drawMeshInstance(this.simpleLightMesh,this.lightInstancingBuffer,this.lightInstancingMaterial,r.length)}drawShadowLights(t,e,r){for(let t=0;t<this.light2DShadowMaterial.lightParamsList.length;t++)this.light2DShadowMaterial.lightParamsList[t].fill(0);for(let n=0;n<r.length;n++){const i=r[n];this.light2DShadowMaterial.lightPosList[n]=this.light2DShadowMaterial.lightPosList[n]||b.b.zero(),b.b.set(this.light2DShadowMaterial.lightPosList[n],i.position),this.light2DShadowMaterial.lightPosList[n].w=1,this.light2DShadowMaterial.lightParamsList[n]=this.light2DShadowMaterial.lightParamsList[n]||b.b.zero(),this.light2DShadowMaterial.lightParamsList[n].x=i.volumnRadius,this.light2DShadowMaterial.lightParamsList[n].y=i.lightRange,this.light2DShadowMaterial.lightParamsList[n].z=i.attenuation,this.light2DShadowMaterial.lightParamsList[n].w=i.intensity,this.light2DShadowMaterial.lightColorList[n]=this.light2DShadowMaterial.lightColorList[n]||a.a.white,this.light2DShadowMaterial.lightColorList[n].set(i.lightColor),this.light2DShadowMaterial.shadowMapList[n]=i.getShadowMap(t,e)}this.light2DShadowMaterial.lightCount=r.length,this.light2DShadowMaterial.cameraParams.x=e.camera.position.x,this.light2DShadowMaterial.cameraParams.y=e.camera.position.y,this.light2DShadowMaterial.cameraParams.z=2*e.camera.viewHeight*e.camera.aspectRatio,this.light2DShadowMaterial.cameraParams.w=2*e.camera.viewHeight,b.b.mul(this.light2DShadowMaterial.ambientLightColor,this.settings.ambientLightColor,this.settings.ambientIntensity),t.renderer.blit(null,this.lightmap,this.light2DShadowMaterial)}}class _ extends(Object(p.b)(new v.e(...x.ShaderSource.light2D,{blend:[v.a.One,v.a.Zero],depth:v.d.Disable,zWrite:!1}))){constructor(){super(...arguments),this.lightPosList=[],this.lightColorList=[],this.lightParamsList=[],this.shadowMapList=[],this.lightCount=0,this.cameraParams=b.b.zero(),this.ambientLightColor=a.a.white}}w([Object(p.e)("uLightPosList","vec4[]")],_.prototype,"lightPosList",void 0),w([Object(p.e)("uLightColorList","color[]")],_.prototype,"lightColorList",void 0),w([Object(p.e)("uLightParamsList","vec4[]")],_.prototype,"lightParamsList",void 0),w([Object(p.e)("uShadowMapList","tex2d[]")],_.prototype,"shadowMapList",void 0),w([Object(p.e)("uLightCount","int")],_.prototype,"lightCount",void 0),w([Object(p.e)("uCameraParams","vec4")],_.prototype,"cameraParams",void 0),w([Object(p.e)("uAmbientLightColor","color")],_.prototype,"ambientLightColor",void 0);class O extends(Object(p.b)(new v.e(...x.ShaderSource.blitCopy,{blend:[v.a.DstColor,v.a.Zero],depth:v.d.Disable,zWrite:!1}))){}const T=Object(g.e)({lightPos:"vec3",lightParams:"vec4",lightColor:"vec4"});class A extends(Object(p.b)(new v.e(...x.ShaderSource.light2DSimple,{vertexStructure:Object.assign(Object.assign({},g.a),T),attributes:{lightPos:"aLightPos",lightColor:"aLightColor",lightParams:"aLightParams"},blend:[v.a.One,v.a.One]}))){}class E extends M.a{constructor(t,e){super(),this.renderOrder=t,this.filter=e}render(t,e){e.camera;t.renderer.setFramebuffer(e.cameraOutput);const r=e.getVisibleObjects(this.renderOrder,this.filter);for(const n of r)n.render(t,e)}}var S=r(38);class j extends M.a{constructor(t,e){super(),this.tempRT=new d.c(t.screen.width,t.screen.height,!1,e)}render(t,e){var r,n;e.cameraOutput.size.equals(this.tempRT.size)||this.tempRT.resize(e.cameraOutput.width,e.cameraOutput.height);const s=e.camera;if(e.postprocessOutput)t.renderer.blit(e.postprocessOutput,null!==(r=s.output)&&void 0!==r?r:u.a.CanvasBuffer);else{if(e.cameraOutput===u.a.CanvasBuffer)return;e.cameraOutput instanceof u.a&&(e.cameraOutput.colorAttachments[0]instanceof i.b?s.output instanceof d.c?t.renderer.blitCopy(e.cameraOutput.colorAttachments[0],s.output):(t.renderer.blitCopy(e.cameraOutput.colorAttachments[0],this.tempRT),t.renderer.blit(this.tempRT,u.a.CanvasBuffer)):e.cameraOutput.colorAttachments[0]instanceof d.c&&t.renderer.blit(e.cameraOutput.colorAttachments[0],null!==(n=s.output)&&void 0!==n?n:u.a.CanvasBuffer))}}}class P extends M.a{render(t,e){const r=e.camera;t.renderer.setFramebuffer(e.cameraOutput),t.renderer.clear(r.clearColor,r.clearDepth)}}class z{constructor(){this.msaa=4,this.renderFormat=n.a.RGBA8,this.debuglayer=new c.a,this.ambientLightColor=new a.a(1,1,1,1),this.ambientIntensity=1,this.perCameraResources=new Map,Object(h.a)(this.debuglayer)}render(t,e,r){for(const n of r){const r=this.getCameraResources(t,n),i=o.a.create(n,e,r.outputFBO);this.renderCamera(t,i)}}replaceMaterial(t,e){throw new Error("Method not implemented.")}renderCamera(t,e){const r=e.camera;r.__preRender(t),t.renderer.setViewProjection(r.worldToLocalMatrix,r.projectionMatrix);const n=this.getCameraResources(t,r);for(const r of n.renderPass)r.setup(t,e),r.render(t,e);for(const r of n.renderPass)r.cleanup(t,e);this.debuglayer.render(t,e),r.__postRender(t)}getCameraResources(t,e){let r=this.perCameraResources.get(e);if(!r){const n=new u.a(t.renderer.canvas.width,t.renderer.canvas.height),s=new i.b(n.width,n.height,this.renderFormat,this.msaa);n.addColorAttachment(s),r={outputFBO:n,outputBuffer:s,renderPass:this.createRenderPass(t,e)},this.perCameraResources.set(e,r)}const n=null===e.output?Object(s.b)(t.screen.width,t.screen.height):e.output.size;if(!n.equals(r.outputFBO.size)){console.log("resize",r.outputFBO.size,n);const t=r.outputFBO.colorAttachments[0].resize(n.x,n.y);r.outputFBO.reset(n.x,n.y),r.outputFBO.addColorAttachment(t,0)}return r}createRenderPass(t,e){return[new P,new E(o.b.FarToNear),new R(t,this),new S.b(t,this.renderFormat),new j(t,this.renderFormat)]}}},,function(t,e,r){"use strict";r.d(e,"a",(function(){return o}));var n=r(11),i=r(21),s=r(6);class o{constructor(t,e,r){this.color=n.a.white,this.texture=t,this.uvRect=new i.a(Object(s.f)(r,e),Object(s.f)(1,e))}}},,,,function(t,e){var r,n,i=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function a(t){if(r===setTimeout)return setTimeout(t,0);if((r===s||!r)&&setTimeout)return r=setTimeout,setTimeout(t,0);try{return r(t,0)}catch(e){try{return r.call(null,t,0)}catch(e){return r.call(this,t,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:s}catch(t){r=s}try{n="function"==typeof clearTimeout?clearTimeout:o}catch(t){n=o}}();var u,c=[],h=!1,l=-1;function d(){h&&u&&(h=!1,u.length?c=u.concat(c):l=-1,c.length&&f())}function f(){if(!h){var t=a(d);h=!0;for(var e=c.length;e;){for(u=c,c=[];++l<e;)u&&u[l].run();l=-1,e=c.length}u=null,h=!1,function(t){if(n===clearTimeout)return clearTimeout(t);if((n===o||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(t);try{n(t)}catch(e){try{return n.call(null,t)}catch(e){return n.call(this,t)}}}(t)}}function b(t,e){this.fun=t,this.array=e}function m(){}i.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];c.push(new b(t,e)),1!==c.length||h||a(f)},b.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=m,i.addListener=m,i.once=m,i.off=m,i.removeListener=m,i.removeAllListeners=m,i.emit=m,i.prependListener=m,i.prependOnceListener=m,i.listeners=function(t){return[]},i.binding=function(t){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(t){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";r.d(e,"a",(function(){return s}));var n=r(0),i=r(6);class s{constructor(){this.gravity=n.b.zero(),this.colliderList=[]}__addCollider(t){(t=t).__colliderIdx=this.colliderList.push(t)-1}__removeCollider(t){const e=t;if(e.__colliderIdx>=0){if(this.colliderList.length>1){const t=this.colliderList[this.colliderList.length-1];t.__colliderIdx=e.__colliderIdx,this.colliderList[e.__colliderIdx]=t}this.colliderList.length--}}__getColliders(){return this.colliderList}update(t){var e,r,s,o,a;this.updateMotion(t);for(let t=0;t<this.colliderList.length;t++){const u=this.colliderList[t];for(let c=t+1;c<this.colliderList.length;c++){if(t===c)continue;const h=this.colliderList[c];if(!u.checkContact(h))continue;if(u.__eventEmitter.emit("onContact",h),h.__eventEmitter.emit("onContact",u),!u.rigidbody&&!h.rigidbody)continue;const[l,d]=h.rigidbody?[u,h]:[h,u],f=Object(i.h)(null!==(r=null===(e=d.rigidbody)||void 0===e?void 0:e._motion)&&void 0!==r?r:n.b.zero(),null!==(o=null===(s=l.rigidbody)||void 0===s?void 0:s._motion)&&void 0!==o?o:n.b.zero()),b=l.checkCollision(d,f);if(b){if(l.rigidbody&&d.rigidbody){console.warn("Collision between two rigidbody is not implement");continue}null===(a=d.entity)||void 0===a||a.translate(b.seperation.toVec3()),l.__eventEmitter.emit("onCollide",b),b.self=d,b.other=l,d.__eventEmitter.emit("onCollide",b)}}}}updateMotion(t){var e;const r=this.gravity,n=0!==r.x&&0!==r.y;for(let s=0;s<this.colliderList.length;s++){const o=this.colliderList[s].rigidbody;if(!o)continue;n&&o.addAcceleration(r),o._velocity.x+=o._acceleration.x*t.deltaTime,o._velocity.y+=o._acceleration.y*t.deltaTime;const a=Object(i.i)(o._velocity,t.deltaTime);null===(e=o.collider.entity)||void 0===e||e.translate(a.toVec3()),o._motion=a}}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return a}));var n=r(12),i=r(3),s=r(14);const o={tex2d:{import:(t,e,r=Object(i.d)())=>new Promise((i,o)=>{const a=new Blob([t]),u=new Image;u.src=URL.createObjectURL(a);const c=()=>{const t={width:u.width,height:u.height,filterMode:n.b.Linear,format:s.a.RGBA,mipmap:!0,wrapMpde:n.g.Repeat},o=Object.assign(Object.assign({},t),e),a=new n.e(o.width,o.height,o.format,o.filterMode,r);a.autoMipmap=o.mipmap,a.wrapMode=o.wrapMpde,a.updateParameters(),a.setData(u),i(a)};u.complete?c():u.onload=c})}},a=new(r(51).a)(o)},function(t,e,r){"use strict";r.d(e,"a",(function(){return f}));var n=r(8),i=r(7),s=r(12),o=r(14),a=r(19),u=r(54),c=r(38),h=function(t,e,r,n){var i,s=arguments.length,o=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(o=(s<3?i(o):s>3?i(e,r,o):i(e,r))||o);return s>3&&o&&Object.defineProperty(e,r,o),o};class l extends(Object(n.b)(new i.e(...a.ShaderSource.bloomFilter,{depth:i.d.Disable,zWrite:!1}))){constructor(){super(...arguments),this.texture=null,this.threshold=1,this.softThreshold=.5}}h([Object(n.e)("uMainTex","tex2d")],l.prototype,"texture",void 0),h([Object(n.e)("uThreshold","float")],l.prototype,"threshold",void 0),h([Object(n.e)("uSoftThreshold","float")],l.prototype,"softThreshold",void 0);class d extends(Object(n.b)(new i.e(...a.ShaderSource.bloomCompose,{blendRGB:[i.a.One,i.a.One],blendAlpha:[i.a.Zero,i.a.One],depth:i.d.Disable,zWrite:!1}))){constructor(){super(...arguments),this.intensity=1}}h([Object(n.e)("uIntensity","float")],d.prototype,"intensity",void 0);class f extends c.a{constructor(){super(...arguments),this.intensity=1,this.blurSteps=4,this.threshold=1,this.softThreshold=.25,this.materialFilter=new l,this.materialCompose=new d,this.blurRenderer=new u.a,this.filterOutput=null}create(t){this.filterOutput=new s.c(t.renderer.canvasSize.x,t.renderer.canvasSize.y,!1,o.a.RGBA16F),this.blurRenderer.upsampleMaterial.setPipelineStateOverride({blend:[i.a.One,i.a.One]})}render(t,e,r){e.size.equals(this.filterOutput.size)||this.filterOutput.resize(e.width,e.height,s.f.Discard),t.renderer.blit(e,this.filterOutput,this.materialFilter);const n=this.blurRenderer.blur(this.filterOutput,this.blurSteps);this.materialCompose.intensity=this.intensity,t.renderer.blit(e,r),t.renderer.blit(n,r,this.materialCompose)}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return u}));var n=r(16),i=r(9),s=r(0),o=r(6),a=r(27);class u extends a.a{constructor(){super(...arguments),this.mesh=new n.c,this.dirty=!1,this.points=[]}updateMesh(){this.dirty=!0}render(t,e){this.rebuildMesh(),t.renderer.drawMesh(this.mesh,i.b.identity(),this.materials[0])}rebuildMesh(){if(!this.dirty)return;const t=this.points.length-1;t<1&&this.mesh.resize(this.mesh.vertices.length,0),this.mesh.resize(4*t,6*t,!1);const e=s.b.zero(),r=s.b.zero(),n=s.b.zero(),i=s.b.zero(),o=s.b.zero(),a=s.b.zero();for(let t=0;t<this.points.length-1;t++){const u=this.points[t],h=this.points[t+1];if(s.b.minus(e,h.position,u.position),e.normalize(),e.isZero)continue;s.b.perpendicular(r,e),t>0?c([n,i],this.points[t-1],this.points[t],this.points[t+1]):(n.set(r).mul(u.width/2).plus(u.position),i.set(r).mul(-u.width/2).plus(u.position)),t<this.points.length-2?c([o,a],this.points[t],this.points[t+1],this.points[t+2]):(o.set(r).mul(h.width/2).plus(h.position),a.set(r).mul(-h.width/2).plus(h.position));const l=4*t;this.mesh.vertices[l+0].vert.set(n),this.mesh.vertices[l+1].vert.set(i),this.mesh.vertices[l+2].vert.set(o),this.mesh.vertices[l+3].vert.set(a),this.mesh.vertices[l+0].color.set(u.color),this.mesh.vertices[l+1].color.set(u.color),this.mesh.vertices[l+2].color.set(h.color),this.mesh.vertices[l+3].color.set(h.color),this.mesh.vertices[l+0].uv.set([0,1]),this.mesh.vertices[l+1].uv.set([0,0]),this.mesh.vertices[l+2].uv.set([1,1]),this.mesh.vertices[l+3].uv.set([1,0]);const d=6*t;this.mesh.indices[d+0]=l+0,this.mesh.indices[d+1]=l+1,this.mesh.indices[d+2]=l+3,this.mesh.indices[d+3]=l+0,this.mesh.indices[d+4]=l+3,this.mesh.indices[d+5]=l+2}this.dirty=!1}destroy(){this.destroyed||(super.destroy(),this.mesh.destroy())}}function c(t,e,r,n){const[i,a]=t;s.b.minus(i,e.position,r.position).normalize(),s.b.minus(a,n.position,r.position).normalize();const u=Object(o.j)(i,a).div(2);let c=0;s.b.dot(u,u)<=1e-7||i.isZero?(s.b.perpendicular(u,a),c=1):a.isZero?(s.b.perpendicular(u,i),c=-1):(u.normalize(),c=Math.sign(s.b.cross(a,i))*Math.sqrt((1-Object(o.g)(i,a))/2));const h=r.width/2/c,l=i.set(u).mul(h).plus(r.position),d=a.set(u).mul(-h).plus(r.position);return(isNaN(l.x)||isNaN(l.y)||isNaN(d.x)||isNaN(d.y))&&console.log(l,d),[l,d]}},function(t,e,r){"use strict";r.d(e,"c",(function(){return i})),r.d(e,"a",(function(){return s})),r.d(e,"b",(function(){return a}));var n=r(2);function i(t){const e=Object.keys(t.frames).map(t=>({key:t,time:parseFloat(t)})).sort((t,e)=>t.time-e.time),r={loop:t.loop||!1,duration:t.duration,frames:[],updater:t.updater};for(const n of e)r.frames.push({time:n.time,values:t.frames[n.key]});return r}class s{constructor(t,e,r){this.frameTime=0,this.time=0,this.timeScale=1,this.target=void 0,this.updater=void 0,this.state="stopped",this.currentFrame={},this.frameTime=0,this.timeline=t,this.loop=t.loop,this.duration=t.duration,this.target=e,this.updater=r,!this.updater&&e&&t.updater&&(this.updater=r=>{t.updater(r.frame,e)})}get playing(){return"playing"===this.state||"pending"===this.state}get finished(){return"stopped"===this.state}play(t=0){return new Promise((e,r)=>{this.resolver=e,this.rejector=r,this.frameTime=t,this.frameTime=t,this.state="pending",this.timeline&&this.timeline.frames.length>0&&Object.assign(this.currentFrame,this.timeline.frames[0].values)})}stop(){this.state="stopped"}update(t){switch(this.state){case"stopped":return;case"pending":this.state="playing",this.checkEnd(),this.updateAnimation(t);break;case"playing":this.time+=t*this.timeScale,this.checkEnd(),this.updateAnimation(t)}}reject(){var t;null===(t=this.rejector)||void 0===t||t.call(this)}updateAnimation(t){this.updater&&(this.loop?this.frameTime=this.time%this.timeline.duration:this.frameTime=this.time,this.updateFrame(),this.updater({deltaTime:t,frame:this.currentFrame,animator:this,target:this.target,time:this.time,frameTime:this.frameTime,progress:this.frameTime/this.duration}))}updateFrame(){if(this.timeline&&this.timeline.frames.length>0){for(let t=0;t<this.timeline.frames.length;t++)if(this.timeline.frames[t].time>=this.frameTime)return 0===t||this.timeline.frames[t].time===this.frameTime?Object.assign(this.currentFrame,this.timeline.frames[t].values):this.interpolate(this.currentFrame,this.timeline.frames[t-1],this.timeline.frames[t]),this.currentFrame;this.loop?this.interpolate(this.currentFrame,this.timeline.frames[this.timeline.frames.length-1],this.timeline.frames[0]):Object.assign(this.currentFrame,this.timeline.frames[this.timeline.frames.length-1].values)}}interpolate(t,e,r){let i=(this.frameTime-e.time)/(r.time-e.time);r.time<e.time&&(i=(this.frameTime-e.time)/(this.timeline.duration+r.time-e.time));for(const s in e.values)t[s]=e.values[s],"number"==typeof e.values[s]&&"number"==typeof r.values[s]&&(t[s]=n.a.lerp(e.values[s],r.values[s],i));return t}checkEnd(){var t;this.time>=this.duration&&(this.time=this.duration,this.state="stopped",null===(t=this.resolver)||void 0===t||t.call(this,this))}}class o{constructor(t,e){this.currentTime=0,this.state="stopped",this.totalTime=t,this.updater=e}get finished(){return"stopped"===this.state}play(){return new Promise((t,e)=>{this.rejector=e,this.resolver=t,"stopped"===this.state&&(this.state="pending")})}stop(){this.resolver=void 0,this.state="stopped"}update(t){var e;switch(this.state){case"stopped":return;case"pending":this.state="playing";case"playing":this.currentTime+=t,this.checkEnd(),null===(e=this.updater)||void 0===e||e.call(this,this.currentTime/this.totalTime,t)}}reject(){var t;null===(t=this.rejector)||void 0===t||t.call(this)}checkEnd(){var t;this.currentTime>=this.totalTime&&(this.currentTime=this.totalTime,this.state="stopped",null===(t=this.resolver)||void 0===t||t.call(this))}}class a{constructor(t){this.tracks=[],this.defaultTarget=t}playOn(t,e,r=this.defaultTarget,n=e.duration,i){const o=new s(e,r,i);o.duration=n;const a=o.play();return this.tracks[t]&&this.tracks[t].reject(),this.tracks[t]=o,a}play(t,e=this.defaultTarget,r=t.duration,n){return this.playOn(this.tracks.length,t,e,r,n)}playProceduralOn(t,e,r,n=0){const i=new o(e,r);i.currentTime=n;const s=i.play();return this.tracks[t]&&this.tracks[t].reject(),this.tracks[t]=i,s}playProcedural(t,e,r=0){return this.playProceduralOn(this.tracks.length,t,e)}wait(t,e){const r=new o(t),n=r.play();this.tracks.push(r),n.then(e)}update(t){for(let e=0;e<this.tracks.length;e++){const r=this.tracks[e];r&&(r.update(t),r.finished&&(this.tracks[e]=void 0))}}clear(){for(const t of this.tracks)null==t||t.reject();this.tracks.length=0}}},function(t,e,r){"use strict";r.d(e,"a",(function(){return h}));var n=r(0),i=r(24),s=r(11),o=r(13),a=r(27),u=r(49);const c=[Object(n.b)(-.5,-.5),Object(n.b)(.5,-.5),Object(n.b)(.5,.5),Object(n.b)(-.5,.5)];class h extends a.a{constructor(){super(),this.mesh=i.a.quad(),this.material=u.a.spriteDefault,this._sprite=null,this._size=n.b.one(),this._color=s.a.white,this.meshes[0]=this.mesh,this.materials[0]=this.material}get size(){return this._size}set size(t){this._size.set(t),n.b.mul(this.mesh.vertices[0].vert,c[0],this._size),n.b.mul(this.mesh.vertices[1].vert,c[1],this._size),n.b.mul(this.mesh.vertices[2].vert,c[2],this._size),n.b.mul(this.mesh.vertices[3].vert,c[3],this._size),this.mesh.update()}get color(){return this._color}set color(t){this._color.set(t),this.sprite?(o.b.mul(this.mesh.vertices[0].color,this.sprite.color,t),o.b.mul(this.mesh.vertices[1].color,this.sprite.color,t),o.b.mul(this.mesh.vertices[2].color,this.sprite.color,t),o.b.mul(this.mesh.vertices[3].color,this.sprite.color,t)):(o.b.set(this.mesh.vertices[0].color,t),o.b.set(this.mesh.vertices[1].color,t),o.b.set(this.mesh.vertices[2].color,t),o.b.set(this.mesh.vertices[3].color,t)),this.mesh.update()}get sprite(){return this._sprite}set sprite(t){this._sprite=t,t?(this.mesh.vertices[0].uv.set([t.uvRect.xMin,t.uvRect.yMin]),this.mesh.vertices[1].uv.set([t.uvRect.xMax,t.uvRect.yMin]),this.mesh.vertices[2].uv.set([t.uvRect.xMax,t.uvRect.yMax]),this.mesh.vertices[3].uv.set([t.uvRect.xMin,t.uvRect.yMax]),this.mesh.vertices[0].color.set(t.color),this.mesh.vertices[1].color.set(t.color),this.mesh.vertices[2].color.set(t.color),this.mesh.vertices[3].color.set(t.color),this.mesh.update()):this.material.texture=null}render(t,e){var r;this.material.setProp("uMainTex","tex2d",(null===(r=this.sprite)||void 0===r?void 0:r.texture)||null),t.renderer.drawMesh(this.mesh,this.localToWorldMatrix,this.material)}destroy(){this.destroyed||(super.destroy(),this.mesh.destroy())}}},,,,,,,,,,,,function(t,e){t.exports="#version 300 es\r\nprecision mediump float;\r\n\r\nin vec4 vColor;\r\nin vec2 vUV;\r\n\r\nuniform sampler2D uMainTex;\r\n\r\nout vec4 fragColor;\r\n\r\nvoid main()\r\n{\r\n    float r = length(vUV.xy * vec2(2) - vec2(1));\r\n    float c = smoothstep(1.0, 0.5, r);\r\n    fragColor = vec4(c) * vColor;\r\n}"},,,,,,,,,,,function(t,e,r){"use strict";r.r(e);var n=r(8),i=r(7),s=r(37),o=r(43),a=r(62),u=r(64),c=r(11),h=r(14),l=r(31),d=r(34),f=r(1),b=r(2),m=r(74),p=r(89),v=r.n(p);class g extends(Object(n.b)(new i.e(s.BuiltinShaders.particle2D[0],v.a,{vertexStructure:o.b.VertexStructure,attributes:o.b.AttributeNames,blend:[i.a.SrcAlpha,i.a.OneMinusSrcAlpha],depth:i.d.Disable}))){}const y=document.querySelector("#canvas"),x=new a.a(y,u.a);x.fixedDeltaTime=!0,x.renderPipeline.ambientLightColor=c.a.white,x.renderPipeline.renderFormat=h.a.RGBA16F;const M=new l.a({});x.start();const w=x.scene;window.scene=w;const R=new d.a;R.position=Object(f.b)(0,0,20),R.projection=d.b.Orthographic,R.viewHeight=10,w.add(R),window.camera=R;const _=new o.b;_.material=new g,_.maxCount=512,_.duration=5,_.spawnRate=0,_.startSpeed=[3,16],_.startRotation={x:0,y:0,z:()=>360*Math.random()},_.startColor=()=>c.a.fromHSL(360*Math.random(),.8,.7).mul(b.a.lerp(.2,2,Math.random())),_.material.pipelineStateOverride.blendRGB=[i.a.SrcAlpha,i.a.OneMinusSrcAlpha],_.material.pipelineStateOverride.depth=i.d.Disable,w.add(_),_.play(),window.particleSystem=_;const O=new m.a;R.postprocess.push(O),x.on("update",()=>{if(M.update(),M.getKeyDown(l.c.Mouse0)){const t=R.screenToWorld(M.pointerPosition);t.z=0,_.emit(100,t)}})}]);