text: /**
   * @license glsl-canvas-js v0.2.2
   * (c) 2020 Luca Zampetti <lzampetti@gmail.com>
   * License: MIT
   */
  !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).glsl={})}(this,(function(t){"use strict";function e(t,e){for(var i=0;i<e.length;i++){var r=e[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function r(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var n="\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nattribute vec4 a_position;\nattribute vec4 a_normal;\nattribute vec2 a_texcoord;\nattribute vec4 a_color;\n\nvarying vec4 v_position;\nvarying vec4 v_normal;\nvarying vec2 v_texcoord;\nvarying vec4 v_color;\n",o="\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nvarying vec4 v_position;\nvarying vec4 v_normal;\nvarying vec2 v_texcoord;\nvarying vec4 v_color;\n",s="#version 300 es\n\nprecision mediump float;\n\nin vec4 a_position;\nin vec4 a_normal;\nin vec2 a_texcoord;\nin vec4 a_color;\n\nout vec4 v_position;\nout vec4 v_normal;\nout vec2 v_texcoord;\nout vec4 v_color;\n",a="#version 300 es\n\nprecision mediump float;\n\nin vec4 v_position;\nin vec4 v_normal;\nin vec2 v_texcoord;\nin vec4 v_color;\n\nout vec4 outColor;\n",u="\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_modelViewMatrix;\nuniform mat4 u_normalMatrix;\n\nuniform vec2 u_resolution;\nuniform float u_time;\n",h="\nvoid main() {\n\tv_position = a_position;\n\tv_normal = a_normal;\n\tv_texcoord = a_texcoord;\n\tv_color = a_color;\n\tgl_Position = a_position;\n}\n",f="\nvoid main(void) {\n\tv_position = u_projectionMatrix * u_modelViewMatrix * a_position;\n\tv_normal = u_normalMatrix * a_normal;\n\tv_texcoord = a_texcoord;\n\tv_color = a_color;\n\tgl_Position = v_position;\n}\n",c=n+u+f,l=s+u+f,m=o+u+"\nvoid main() {\n\tvec2 st = gl_FragCoord.xy / u_resolution.xy;\n\tst.x *= u_resolution.x / u_resolution.y;\n\tvec3 color = vec3(\n\t\tabs(cos(u_time * 0.1)) * st.y,\n\t\tabs(cos(u_time * 0.2)) * st.y,\n\t\tabs(sin(u_time)) * st.y\n\t);\n\tgl_FragColor = vec4(color, 1.0);\n}\n",d=a+u+"\nvoid main() {\n\tvec2 st = gl_FragCoord.xy / u_resolution.xy;\n\tst.x *= u_resolution.x / u_resolution.y;\n\tvec3 color = vec3(\n\t\tabs(cos(u_time * 0.1)) * st.y,\n\t\tabs(cos(u_time * 0.2)) * st.y,\n\t\tabs(sin(u_time)) * st.y\n\t);\n\toutColor = vec4(color, 1.0);\n}\n",v=o+u+"\nvoid main() {\n\tvec2 uv = v_texcoord;\n\tvec3 color = vec3(\n\t\tabs(cos(u_time * 0.1)) * uv.y,\n\t\tabs(cos(u_time * 0.2)) * uv.y,\n\t\tabs(sin(u_time)) * uv.y\n\t);\n\tfloat incidence = max(dot(v_normal.xyz, vec3(0.0, 1.0, 0.0)), 0.0);\n\tvec3 light = vec3(0.2) + (vec3(1.0) * incidence);\n\tgl_FragColor = vec4(v_color.rgb * color * light, 1.0);\n}\n",p=a+u+"\nvoid main() {\n\tvec2 uv = v_texcoord;\n\tvec3 color = vec3(\n\t\tabs(cos(u_time * 0.1)) * uv.y,\n\t\tabs(cos(u_time * 0.2)) * uv.y,\n\t\tabs(sin(u_time)) * uv.y\n\t);\n\tfloat incidence = max(dot(v_normal.xyz, vec3(0.0, 1.0, 0.0)), 0.0);\n\tvec3 light = vec3(0.2) + (vec3(1.0) * incidence);\n\toutColor = vec4(v_color.rgb * color * light, 1.0);\n}\n",g=n+u+h,x=s+u+h,_=o+u+"\nvoid main(){\n\tgl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}",y=a+u+"\nvoid main() {\n\toutColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n";var T=setTimeout;function E(t){return Boolean(t&&void 0!==t.length)}function M(){}function U(t){if(!(this instanceof U))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],R(t,this)}function b(t,e){for(;3===t._state;)t=t._value;0!==t._state?(t._handled=!0,U._immediateFn((function(){var i=1===t._state?e.onFulfilled:e.onRejected;if(null!==i){var r;try{r=i(t._value)}catch(t){return void w(e.promise,t)}A(e.promise,r)}else(1===t._state?A:w)(e.promise,t._value)}))):t._deferreds.push(e)}function A(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var i=e.then;if(e instanceof U)return t._state=3,t._value=e,void F(t);if("function"==typeof i)return void R((r=i,n=e,function(){r.apply(n,arguments)}),t)}t._state=1,t._value=e,F(t)}catch(e){w(t,e)}var r,n}function w(t,e){t._state=2,t._value=e,F(t)}function F(t){2===t._state&&0===t._deferreds.length&&U._immediateFn((function(){t._handled||U._unhandledRejectionFn(t._value)}));for(var e=0,i=t._deferreds.length;e<i;e++)b(t,t._deferreds[e]);t._deferreds=null}function L(t,e,i){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=i}function R(t,e){var i=!1;try{t((function(t){i||(i=!0,A(e,t))}),(function(t){i||(i=!0,w(e,t))}))}catch(t){if(i)return;i=!0,w(e,t)}}U.prototype.catch=function(t){return this.then(null,t)},U.prototype.then=function(t,e){var i=new this.constructor(M);return b(this,new L(t,e,i)),i},U.prototype.finally=function(t){var e=this.constructor;return this.then((function(i){return e.resolve(t()).then((function(){return i}))}),(function(i){return e.resolve(t()).then((function(){return e.reject(i)}))}))},U.all=function(t){return new U((function(e,i){if(!E(t))return i(new TypeError("Promise.all accepts an array"));var r=Array.prototype.slice.call(t);if(0===r.length)return e([]);var n=r.length;function o(t,s){try{if(s&&("object"==typeof s||"function"==typeof s)){var a=s.then;if("function"==typeof a)return void a.call(s,(function(e){o(t,e)}),i)}r[t]=s,0==--n&&e(r)}catch(t){i(t)}}for(var s=0;s<r.length;s++)o(s,r[s])}))},U.resolve=function(t){return t&&"object"==typeof t&&t.constructor===U?t:new U((function(e){e(t)}))},U.reject=function(t){return new U((function(e,i){i(t)}))},U.race=function(t){return new U((function(e,i){if(!E(t))return i(new TypeError("Promise.race accepts an array"));for(var r=0,n=t.length;r<n;r++)U.resolve(t[r]).then(e,i)}))},U._immediateFn="function"==typeof setImmediate&&function(t){setImmediate(t)}||function(t){T(t,0)},U._unhandledRejectionFn=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};var S,P=function(){function t(){}return t.fetch=function(t){return new Promise((function(e,i){var r=new XMLHttpRequest;r.onload=function(){e(r.response||r.responseText)},r.onerror=function(e){console.log("Common.error",e),i(new Error("Network request failed for url "+t))},r.ontimeout=function(e){i(new Error("Network request failed for url "+t))},r.onabort=function(){i(new Error("Aborted"))},r.open("GET",t,!0),r.send(null)}))},t}();!function(t){t[t.None=0]="None",t[t.Error=1]="Error",t[t.Warn=2]="Warn",t[t.Log=3]="Log"}(S||(S={}));var B,D,O,C=function(){function t(){}return t.log=function(){var e;t.enabled&&t.level>=S.Log&&(e=console).log.apply(e,arguments)},t.warn=function(){var e;t.enabled&&t.level>=S.Warn&&(e=console).warn.apply(e,arguments)},t.error=function(){var e;t.enabled&&t.level>=S.Error&&(e=console).error.apply(e,arguments)},t}();C.level=S.Warn,C.enabled=!0,(B=t.ContextVersion||(t.ContextVersion={})).WebGl="webgl",B.WebGl2="webgl2",function(t){t.LowP="lowp",t.MediumP="mediump",t.HighP="highp"}(D||(D={})),function(t){t.Flat="flat",t.Box="box",t.Sphere="sphere",t.Torus="torus",t.Mesh="mesh"}(O||(O={}));var I,G={webgl:{flat:{vertex:c,fragment:m},mesh:{vertex:c,fragment:v}},webgl2:{flat:{vertex:l,fragment:d},mesh:{vertex:l,fragment:p}}};(I=t.ContextError||(t.ContextError={}))[I.BrowserSupport=1]="BrowserSupport",I[I.Other=2]="Other";var V=function(){},W=function(){function e(){}return e.getContext_=function(t,e){for(var i=["webgl","experimental-webgl"],r=null,n=0;n<i.length;++n)try{r=t.getContext(i[n],e)}catch(t){if(r)break}return r},e.getContext2_=function(t,e){var i=null;try{i=t.getContext("webgl2",e)}catch(t){}return i},e.getFragmentVertex=function(t,i){var r;if(i){e.isWebGl2(t)&&(i=i.replace(/^\#version\s*300\s*es\s*\n/,""));null!==/(?:^\s*)((?:#if|#elif)(?:\s*)(defined\s*\(\s*VERTEX)(?:\s*\))|(?:#ifdef)(?:\s*VERTEX)(?:\s*))/gm.exec(i)&&(r=e.isWebGl2(t)?"#version 300 es\n#define VERTEX\n"+i:"#define VERTEX\n"+i)}return r},e.getIncludes=function(t){if(void 0===t)return Promise.resolve(t);for(var e,i=/#include\s*['|"](.*.glsl)['|"]/gm,r=[],n=0;null!==(e=i.exec(t));)r.push(Promise.resolve(t.slice(n,e.index))),n=e.index+e[0].length,r.push(P.fetch(e[1]));return r.push(Promise.resolve(t.slice(n))),Promise.all(r).then((function(t){return t.join("")}))},e.isWebGl=function(t){return t instanceof WebGLRenderingContext},e.isWebGl2=function(t){return window.WebGL2RenderingContext&&t instanceof WebGL2RenderingContext},e.inferVersion=function(e,i){var r=e||i;return r&&0===r.indexOf("#version 300 es")?t.ContextVersion.WebGl2:t.ContextVersion.WebGl},e.inferPrecision=function(t){var i=t.match(/precision\s+(.+)\s+float/);return i&&i.length>1&&(e.precision=i[1]),e.precision},e.versionDiffers=function(i,r,n){if(i){var o=this.isWebGl2(i)?t.ContextVersion.WebGl2:t.ContextVersion.WebGl;return e.inferVersion(r,n)!==o}return!1},e.getBufferVertex=function(t){return this.isWebGl2(t)?x:g},e.getVertex=function(t,e,i){if(void 0===i&&(i=O.Flat),t)return t;var r=this.inferVersion(t,e);return G[r][i===O.Flat?"flat":"mesh"].vertex},e.getFragment=function(t,e,i){if(void 0===i&&(i=O.Flat),e)return e;var r=this.inferVersion(t,e);return G[r][i===O.Flat?"flat":"mesh"].fragment},e.tryInferContext=function(i,r,n,o,s,a){function u(t,e){if("function"==typeof a)a(t);else{var i=n.parentNode;i&&(i.innerHTML='<div class="glsl-canvas--error">'+e+"</div>")}}if(void 0===s&&(s=[]),!WebGLRenderingContext)return u(t.ContextError.BrowserSupport,'This page requires a browser that supports WebGL.<br/>\n\t\t\t<a href="http://get.webgl.org">Click here to upgrade your browser.</a>'),null;var h=e.inferContext(i,r,n,o);if(h){this.isWebGl2(h)||-1!==s.indexOf("OES_standard_derivatives")||s.push("OES_standard_derivatives");var f=h.getSupportedExtensions();s.forEach((function(t){-1!==f.indexOf(t)?h.getExtension(t):C.warn("GlslCanvas "+t+" not supported")}))}else u(t.ContextError.Other,'It does not appear your computer can support WebGL.<br/>\n\t\t\t<a href="http://get.webgl.org/troubleshooting/">Click here for more information.</a>');return h},e.tryGetContext=function(i,r,n){function o(t,e){if("function"==typeof n)n(t);else{var r=i.parentNode;r&&(r.innerHTML='<div class="glsl-canvas--error">'+e+"</div>")}}if(!WebGLRenderingContext)return o(t.ContextError.BrowserSupport,'This page requires a browser that supports WebGL.<br/>\n\t\t\t<a href="http://get.webgl.org">Click here to upgrade your browser.</a>'),null;var s=e.getContext_(i,r);return s?s.getExtension("OES_standard_derivatives"):o(t.ContextError.Other,'It does not appear your computer can support WebGL.<br/>\n\t\t\t<a href="http://get.webgl.org/troubleshooting/">Click here for more information.</a>'),s},e.inferContext=function(e,i,r,n){return this.inferVersion(e,i)===t.ContextVersion.WebGl2?this.getContext2_(r,n):this.getContext_(r,n)},e.createShader=function(t,i,r,n){void 0===n&&(n=0);var o=t.createShader(r);if(i=i.replace(/precision\s+(.+)\s+float/,"precision "+e.precision+" float"),t.shaderSource(o,i),t.compileShader(o),!t.getShaderParameter(o,t.COMPILE_STATUS))throw e.lastError=t.getShaderInfoLog(o),C.error("*** Error compiling shader: "+e.lastError),t.deleteShader(o),{shader:o,source:i,type:r,error:e.lastError,offset:n};return o},e.createProgram=function(t,i,r,n){for(var o=t.createProgram(),s=0;s<i.length;++s)t.attachShader(o,i[s]);if(r&&n)for(var a=0;a<r.length;++a)t.bindAttribLocation(o,n?n[a]:a,r[a]);return t.linkProgram(o),t.validateProgram(o),t.getProgramParameter(o,t.LINK_STATUS)?(t.useProgram(o),o):(e.lastError=t.getProgramInfoLog(o),C.error("Error in program linking: "+e.lastError),t.deleteProgram(o),null)},e.createVertexBuffers=function(t,e){var i=new V,r=t.getAttribLocation(e,"a_texcoord");i.texcoord=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,i.texcoord),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(r),t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0);var n=t.getAttribLocation(e,"a_position");return i.position=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,i.position),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),i},e}();W.precision=D.MediumP,W.lastError="";var k,N=function(){},z=function(){function t(){this.values=new N}var e=t.prototype;return e.has=function(t){return this.values.hasOwnProperty(t)},e.set=function(t,e){this.values[t]=e},e.get=function(t){return this.values[t]},e.forEach=function(t){var e=0;for(var i in this.values)t(this.values[i],e,this.values),e++},e.reduce=function(t,e){var i=e,r=0;for(var n in this.values)i=t(i,this.values[n],r,this.values),r++;return i},t}(),X=function(){function t(t){t&&(Object.assign(this,t),this.positions&&(this.size=this.positions.length/3))}var e=t.prototype;return e.create=function(t,e){this.createData_(),this.createAttributes_(t,e)},e.createBufferData_=function(t,e,i){var r=t.createBuffer();return t.bindBuffer(e,r),t.bufferData(e,i,t.STATIC_DRAW),r},e.createAttribLocation_=function(t,e,i,r,n){var o=t.getAttribLocation(e,i);return t.enableVertexAttribArray(o),t.vertexAttribPointer(o,r,n,!1,0,0),o},e.createAttributes_=function(t,e){this.positions&&(this.positionBuffer=this.createBufferData_(t,t.ARRAY_BUFFER,new Float32Array(this.positions)),this.positionLocation=this.createAttribLocation_(t,e,"a_position",this.positions.length/this.size,t.FLOAT),t.bindAttribLocation(e,this.positionLocation,"a_position")),this.texcoords&&(this.texcoordBuffer=this.createBufferData_(t,t.ARRAY_BUFFER,new Float32Array(this.texcoords)),this.texcoordLocation=this.createAttribLocation_(t,e,"a_texcoord",this.texcoords.length/this.size,t.FLOAT),t.bindAttribLocation(e,this.texcoordLocation,"a_texcoord")),this.normals&&(this.normalBuffer=this.createBufferData_(t,t.ARRAY_BUFFER,new Float32Array(this.normals)),this.normalLocation=this.createAttribLocation_(t,e,"a_normal",this.normals.length/this.size,t.FLOAT),t.bindAttribLocation(e,this.normalLocation,"a_normal")),this.colors&&(this.colorBuffer=this.createBufferData_(t,t.ARRAY_BUFFER,new Float32Array(this.colors)),this.colorLocation=this.createAttribLocation_(t,e,"a_color",this.colors.length/this.size,t.FLOAT),t.bindAttribLocation(e,this.colorLocation,"a_color"))},e.attachAttributes_=function(t,e){var i;this.positions&&(i=t.getAttribLocation(e,"a_position"),t.enableVertexAttribArray(i),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.vertexAttribPointer(i,this.positions.length/this.size,t.FLOAT,!1,0,0)),this.texcoords&&(i=t.getAttribLocation(e,"a_texcoord"),t.enableVertexAttribArray(this.texcoordLocation),t.bindBuffer(t.ARRAY_BUFFER,this.texcoordBuffer),t.vertexAttribPointer(this.texcoordLocation,this.texcoords.length/this.size,t.FLOAT,!1,0,0)),this.normals&&(i=t.getAttribLocation(e,"a_normal"),t.enableVertexAttribArray(this.normalLocation),t.bindBuffer(t.ARRAY_BUFFER,this.normalBuffer),t.vertexAttribPointer(this.normalLocation,this.normals.length/this.size,t.FLOAT,!1,0,0)),this.colors&&(i=t.getAttribLocation(e,"a_color"),t.enableVertexAttribArray(this.colorLocation),t.bindBuffer(t.ARRAY_BUFFER,this.colorBuffer),t.vertexAttribPointer(this.colorLocation,this.colors.length/this.size,t.FLOAT,!1,0,0))},e.bindAttributes_=function(t,e){this.positions&&t.bindAttribLocation(e,this.positionLocation,"a_position"),this.texcoords&&t.bindAttribLocation(e,this.texcoordLocation,"a_texcoord"),this.normals&&t.bindAttribLocation(e,this.normalLocation,"a_normal"),this.colors&&t.bindAttribLocation(e,this.colorLocation,"a_color")},e.createData_=function(){this.positions=[],this.normals=[],this.texcoords=[],this.colors=[],this.size=0},t.fromIndices=function(t,e,i){var r=[];return t.forEach((function(t){r.push.apply(r,e.slice(t*i,t*i+i))})),r},t}(),H=function(t){function e(){return t.apply(this,arguments)||this}return i(e,t),e.prototype.createData_=function(){this.size=6,this.positions=[-1,-1,0,1,-1,0,1,1,0,-1,-1,0,1,1,0,-1,1,0],this.texcoords=[0,0,1,0,1,1,0,0,1,1,0,1],this.normals=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1],this.colors=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]},e}(X);(k=t.BufferFloatType||(t.BufferFloatType={}))[k.FLOAT=0]="FLOAT",k[k.HALF_FLOAT=1]="HALF_FLOAT";var j=function(){function e(t,e,i,r){var n=t.createFramebuffer(),o=this.getTexture(t,e,i,r);t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),this.texture=o,this.buffer=n,this.BW=e,this.BH=i,this.index=r}var i=e.prototype;return i.getFloatType=function(i){var r,n;if(e.floatType===t.BufferFloatType.FLOAT){var o=W.isWebGl2(i)?"EXT_color_buffer_float":"OES_texture_float";if(!(n=i.getExtension(o)))return e.floatType=t.BufferFloatType.HALF_FLOAT,this.getFloatType(i);r=i.FLOAT}else{var s=W.isWebGl2(i)?"EXT_color_buffer_half_float":"OES_texture_half_float";if(!(n=i.getExtension(s)))return e.floatType=t.BufferFloatType.FLOAT,this.getFloatType(i);r=n.HALF_FLOAT_OES}return r},i.getTexture=function(i,r,n,o){var s=this.getFloatType(i),a=i.createTexture();return i.activeTexture(i.TEXTURE0+o),i.bindTexture(i.TEXTURE_2D,a),i.texImage2D(i.TEXTURE_2D,0,W.isWebGl2(i)?i.RGBA16F:i.RGBA,r,n,0,i.RGBA,s,null),i.checkFramebufferStatus(i.FRAMEBUFFER)!==i.FRAMEBUFFER_COMPLETE?(e.floatType===t.BufferFloatType.FLOAT?e.floatType=t.BufferFloatType.HALF_FLOAT:e.floatType=t.BufferFloatType.FLOAT,this.getTexture(i,r,n,o)):a},i.resize=function(t,e,i){if(e!==this.BW||i!==this.BH){var r=this.buffer,n=this.texture,o=this.index;t.bindFramebuffer(t.FRAMEBUFFER,r);var s,a=t.checkFramebufferStatus(t.FRAMEBUFFER),u=Math.min(e,this.BW),h=Math.min(i,this.BH),f=this.getFloatType(t);a===t.FRAMEBUFFER_COMPLETE&&(s=new Float32Array(u*h*4),t.readPixels(0,0,u,h,t.RGBA,f,s)),t.bindFramebuffer(t.FRAMEBUFFER,null);var c=o+1,l=this.getTexture(t,e,i,c);f=this.getFloatType(t),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),s&&t.texSubImage2D(t.TEXTURE_2D,0,0,0,u,h,t.RGBA,f,s);var m=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,null),t.deleteTexture(n),t.activeTexture(t.TEXTURE0+o),t.bindTexture(t.TEXTURE_2D,l),this.index=o,this.texture=l,this.buffer=m,this.BW=e,this.BH=i}},e}();j.floatType=t.BufferFloatType.HALF_FLOAT;var Y=function(){function t(t,e,i,r){this.isValid=!1,this.index=t,this.key=e,this.vertexString=i,this.fragmentString=r,this.geometry=new H}var e=t.prototype;return e.create=function(t,e,i){var r=W.createShader(t,this.vertexString,t.VERTEX_SHADER),n=W.createShader(t,this.fragmentString,t.FRAGMENT_SHADER,1);n?this.isValid=!0:(n=W.createShader(t,W.isWebGl2(t)?y:_,t.FRAGMENT_SHADER),this.isValid=!1);var o=W.createProgram(t,[r,n]);if(!o)return this.isValid=!1,t.deleteShader(r),void t.deleteShader(n);this.geometry.create(t,o),t.deleteShader(r),t.deleteShader(n);var s=new j(t,e,i,this.index+0),a=new j(t,e,i,this.index+2);this.program=o,this.input=s,this.output=a},e.render=function(t,e,i){t.useProgram(this.program),t.bindFramebuffer(t.FRAMEBUFFER,this.output.buffer),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.output.texture,0),t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE&&(t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT)),t.viewport(0,0,e,i),t.drawArrays(t.TRIANGLES,0,this.geometry.size);var r=this.input;this.input=this.output,this.output=r},e.resize=function(t,e,i){t.useProgram(this.program),t.viewport(0,0,e,i),this.input.resize(t,e,i),this.output.resize(t,e,i)},e.destroy=function(t){t.deleteProgram(this.program),this.program=null,this.input=null,this.output=null},t}(),q=function(t){function r(){return t.apply(this,arguments)||this}var n,o,s;return i(r,t),r.getBuffers=function(t,e,i){var n=new r,o=0;if(e){W.isWebGl2(t)&&(e=e.replace(/^\#version\s*300\s*es\s*\n/,""));for(var s,a=/(?:^\s*)((?:#if|#elif)(?:\s*)(defined\s*\(\s*BUFFER_)(\d+)(?:\s*\))|(?:#ifdef)(?:\s*BUFFER_)(\d+)(?:\s*))/gm;null!==(s=a.exec(e));){var u=s[3]||s[4],h="u_buffer"+u,f=W.isWebGl2(t)?"#version 300 es\n#define BUFFER_"+u+"\n"+e:"#define BUFFER_"+u+"\n"+e,c=new Y(o,h,i,f);if(c.create(t,t.drawingBufferWidth,t.drawingBufferHeight),!c.program)throw"buffer error "+h;n.set(h,c),o+=4}}return n},n=r,(o=[{key:"count",get:function(){return 4*Object.keys(this.values).length}}])&&e(n.prototype,o),s&&e(n,s),r}(z),K=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.isVector2=!0,this.x=t,this.y=e}var e=t.prototype;return e.copy=function(t){return this.x=t.x,this.y=t.y,this},e.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.normalize=function(){return this.divideScalar(this.length()||1)},e.divideScalar=function(t){return this.multiplyScalar(1/t)},e.multiplyScalar=function(t){return this.x*=t,this.y*=t,this},e.subVectors=function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this},e.addVectors=function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this},t}(),J=function(){function t(t,e,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===i&&(i=0),this.isVector3=!0,this.x=t,this.y=e,this.z=i}var e=t.prototype;return e.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},e.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},e.normalize=function(){return this.divideScalar(this.length()||1)},e.divideScalar=function(t){return this.multiplyScalar(1/t)},e.multiplyScalar=function(t){return this.x*=t,this.y*=t,this.z*=t,this},e.subVectors=function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this},e.addVectors=function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this},e.crossVectors=function(t,e){var i=t.x,r=t.y,n=t.z,o=e.x,s=e.y,a=e.z;return this.x=r*a-n*s,this.y=n*o-i*a,this.z=i*s-r*o,this},t}(),Q=Math.PI/180,Z=function(t){function e(e,i,r){var n;return(n=t.call(this)||this).position=new J,n.value=new Float32Array([0,0,0]),n.mouse=null,n.dirty=!1,n.theta=(e||0)*Q,n.phi=(i||0)*Q,n.radius=r||6,n}i(e,t);var r=e.prototype;return r.down=function(t,e){this.mouse=new K(t,e)},r.move=function(t,e){var i=this.mouse;if(i&&(i.x!==t||i.y!==e)){var r=180*(t-i.x)*Q,n=180*(e-i.y)*Q;i.x=t,i.y=e,this.theta+=r,this.phi=Math.max(-60*Q,Math.min(60*Q,this.phi+n))}},r.up=function(){this.mouse=null},r.wheel=function(t){this.radius=Math.max(4,Math.min(10,this.radius+.02*t))},e.fromVector=function(t){var i=t.length();return new e(Math.acos(t.y/i),Math.atan(t.x/t.z),i)},e}(J),$="undefined"!=typeof Float32Array?Float32Array:Array;function tt(){var t=new $(16);return $!=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 et(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 it(t,e,i,r){var n,o,s,a,u,h,f,c,l,m,d,v,p,g,x,_,y,T,E,M,U,b,A,w,F=r[0],L=r[1],R=r[2],S=Math.hypot(F,L,R);return S<1e-6?null:(F*=S=1/S,L*=S,R*=S,n=Math.sin(i),s=1-(o=Math.cos(i)),a=e[0],u=e[1],h=e[2],f=e[3],c=e[4],l=e[5],m=e[6],d=e[7],v=e[8],p=e[9],g=e[10],x=e[11],_=F*F*s+o,y=L*F*s+R*n,T=R*F*s-L*n,E=F*L*s-R*n,M=L*L*s+o,U=R*L*s+F*n,b=F*R*s+L*n,A=L*R*s-F*n,w=R*R*s+o,t[0]=a*_+c*y+v*T,t[1]=u*_+l*y+p*T,t[2]=h*_+m*y+g*T,t[3]=f*_+d*y+x*T,t[4]=a*E+c*M+v*U,t[5]=u*E+l*M+p*U,t[6]=h*E+m*M+g*U,t[7]=f*E+d*M+x*U,t[8]=a*b+c*A+v*w,t[9]=u*b+l*A+p*w,t[10]=h*b+m*A+g*w,t[11]=f*b+d*A+x*w,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var rt,nt,ot=function(){function t(){this.delay=0,this.current=0,this.delta=0,this.paused=!1,this.start=this.previous=this.now()}var e=t.prototype;return e.now=function(){return performance.now()},e.play=function(){if(this.previous){var t=this.now();this.delay+=t-this.previous,this.previous=t}this.paused=!1},e.pause=function(){this.paused=!0},e.next=function(){var t=this.now();return this.delta=t-this.previous,this.current=t-this.start-this.delay,this.previous=t,this},t}(),st=function(t,e){this.event=t,this.callback=e},at=function(){function t(){this.listeners=new Set}var e=t.prototype;return e.logListeners=function(){this.listeners.forEach((function(t){return C.log(t)}))},e.subscribe=function(t){this.listeners.add(t)},e.unsubscribe=function(t){this.listeners.delete(t)},e.unsubscribeAll=function(){this.listeners.clear()},e.on=function(t,e){return this.listeners.add(new st(t,e)),this},e.off=function(t,e){var i=this;return e?this.listeners.delete(new st(t,e)):this.listeners.forEach((function(e){e.event===t&&i.listeners.delete(e)})),this},e.trigger=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),r=1;r<e;r++)i[r-1]=arguments[r];return this.listeners.forEach((function(e){e.event===t&&"function"==typeof e.callback&&e.callback.apply(e,i)})),this},t}(),ut=function(t){function e(){return t.apply(this,arguments)||this}return i(e,t),e.prototype.createData_=function(){this.size=36,this.positions=[-1,-1,1,1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,-1,1,-1],this.texcoords=[0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1],this.normals=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0];for(var t=[[1,1,1,1],[1,0,0,1],[0,1,0,1],[0,0,1,1],[1,1,0,1],[1,0,1,1]],e=[],i=0;i<t.length;++i){var r=t[i];e=e.concat(r,r,r,r,r,r)}this.colors=e},e}(X),ht=function(t){function e(){return t.apply(this,arguments)||this}return i(e,t),e.prototype.createData_=function(){var t,e,i=2*Math.PI,r=Math.PI,n=new J,o=new J,s=[],a=[],u=[],h=[],f=[],c=Math.min(0+r,Math.PI),l=0,m=[];for(e=0;e<=60;e++){var d=[],v=e/60,p=0;for(0==e?p=.5/80:60==e&&c==Math.PI&&(p=-.5/80),t=0;t<=80;t++){var g=t/80;n.x=-1.4*Math.cos(0+g*i)*Math.sin(0+v*r),n.y=1.4*Math.cos(0+v*r),n.z=1.4*Math.sin(0+g*i)*Math.sin(0+v*r),a.push(n.x,n.y,n.z),o.copy(n).normalize(),u.push(o.x,o.y,o.z);var x=g+p,_=1-v;h.push(x,_),f.push(1,1,1,1),d.push(l++)}m.push(d)}for(e=0;e<60;e++)for(t=0;t<80;t++){var y=m[e][t+1],T=m[e][t],E=m[e+1][t],M=m[e+1][t+1];0!==e&&s.push(y,T,M),(59!==e||c<Math.PI)&&s.push(T,E,M)}this.size=s.length,this.positions=X.fromIndices(s,a,3),this.texcoords=X.fromIndices(s,h,2),this.normals=X.fromIndices(s,u,3),this.colors=X.fromIndices(s,f,4)},e}(X),ft=function(t){function e(){return t.apply(this,arguments)||this}i(e,t);var r=e.prototype;return r.createData_=function(){for(var t=[],e=[],i=[],r=[],n=[],o=new J,s=new J,a=new J,u=new J,h=new J,f=new J,c=new J,l=0;l<=200;++l){var m=l/200*2*Math.PI*2;this.calculatePositionOnCurve(m,2,3,1,a),this.calculatePositionOnCurve(m+.01,2,3,1,u),f.subVectors(u,a),c.addVectors(u,a),h.crossVectors(f,c),c.crossVectors(h,f),h.normalize(),c.normalize();for(var d=0;d<=40;++d){var v=d/40*Math.PI*2,p=-.25*Math.cos(v),g=.25*Math.sin(v);o.x=a.x+(p*c.x+g*h.x),o.y=a.y+(p*c.y+g*h.y),o.z=a.z+(p*c.z+g*h.z),e.push(o.x,o.y,o.z),s.subVectors(o,a).normalize(),i.push(s.x,s.y,s.z),r.push(l/200*2*Math.round(3)),r.push(d/40),n.push(1,1,1,1)}}for(var x=1;x<=200;x++)for(var _=1;_<=40;_++){var y=41*(x-1)+(_-1),T=41*x+(_-1),E=41*x+_,M=41*(x-1)+_;t.push(y,T,M),t.push(T,E,M)}this.size=t.length,this.positions=X.fromIndices(t,e,3),this.texcoords=X.fromIndices(t,r,2),this.normals=X.fromIndices(t,i,3),this.colors=X.fromIndices(t,n,4)},r.calculatePositionOnCurve=function(t,e,i,r,n){var o=Math.cos(t),s=Math.sin(t),a=i/e*t,u=Math.cos(a);n.x=r*(2+u)*.5*o,n.y=r*(2+u)*s*.5,n.z=r*Math.sin(a)*.5},e}(X),ct=[[1,1,1],[1,0,0],[0,1,0],[0,0,1],[1,1,0],[0,1,1]],lt=0,mt=function(){function t(){}var e=t.prototype;return e.load=function(t){var e=this;return new Promise((function(i,r){P.fetch(t).then((function(t){var n=e.parse(t);if(n.positions.length){var o=new X(n);i(o)}else r("ObjLoader error: empty positions")}),(function(t){r(t)}))}))},e.parseIndices=function(t,e,i,r,n,o){for(var s=0;s<=t.length-3;){var a=void 0,u=void 0,h=void 0;0===s?(a=s,u=s+1,h=s+2):(a=s-1,u=s+1,h=s+2),s++;for(var f=[a,u,h],c=0;c<f.length;c++){var l=t[f[c]][e],m=void 0;l&&NaN!==l&&(m=r[l-1])&&(m=m.slice(0,i),n.push.apply(n,m))}}},e.parseFaces=function(t,e,i,r,n,o,s,a){var u=this,h=n.length;t.forEach((function(t){u.parseIndices(t,0,3,e,n,"positions"),u.parseIndices(t,2,3,i,o,"normals"),u.parseIndices(t,1,2,r,s,"texcoords")}));var f=n.length-h;f>0&&(new Array(f/3).fill(0).forEach((function(){var t=ct[lt%ct.length];a.push(t[0],t[1],t[2],1)})),lt++)},e.parse=function(t){var e=this,i=[],r=[],n=[],o=[];lt=0;var s=[],a=[],u=[],h=[];-1!==t.indexOf("\r\n")&&(t=t.replace(/\r\n/g,"\n")),(t=t.replace(/  /g," ")).split("\n").forEach((function(t,f){if(0===t.indexOf("v ")){h.length&&(e.parseFaces(h,s,a,u,i,r,n,o),h=[]);var c=t.replace("v","").trim().split(" ").map((function(t){return parseFloat(t)}));s.push(c)}else if(0===t.indexOf("vn ")){var l=t.replace("vn","").trim().split(" ").map((function(t){return parseFloat(t)})),m=new J(l[0],l[1],l[2]).normalize();a.push([m.x,m.y,m.z])}else if(0===t.indexOf("vt ")){var d=t.replace("vt","").trim().split(" ").map((function(t){return parseFloat(t)}));u.push(d)}else if(0===t.indexOf("f ")){var v=t.replace("f","").trim().split(" ").map((function(t){var e=t.split("/").map((function(t){return parseInt(t)}));return 2===e.length&&e.push(null),e}));h[h.length]=v}})),h.length&&this.parseFaces(h,s,a,u,i,r,n,o);for(var f={min:new J(Number.POSITIVE_INFINITY),max:new J(Number.NEGATIVE_INFINITY)},c=0;c<i.length;c+=3)f.min.x=Math.min(f.min.x,i[c]),f.min.y=Math.min(f.min.y,i[c+1]),f.min.z=Math.min(f.min.z,i[c+2]),f.max.x=Math.max(f.max.x,i[c]),f.max.y=Math.max(f.max.y,i[c+1]),f.max.z=Math.max(f.max.z,i[c+2]);for(var l=-(f.min.x+f.max.x)/2,m=-(f.min.y+f.max.y)/2,d=-(f.min.z+f.max.z)/2,v=0;v<i.length;v+=3)i[v]+=l,i[v+1]+=m,i[v+2]+=d;var p=i.reduce((function(t,e){return Math.max(t,e)}),0);return i.forEach((function(t,e){return i[e]=t/p*2})),r.length||(r=i.slice()),n.length||(n=this.unrapUvw(i)),{positions:i,normals:r,texcoords:n,colors:o}},e.unrapUvw=function(t){for(var e=[],i=0;i<t.length;i+=3){var r=new J(t[i],t[i+1],t[i+2]);r.normalize();var n=Math.asin(-r.y),o=Math.atan2(r.x,r.z),s=.5+n/Math.PI,a=.5+o/(2*Math.PI);e.push(s,a)}return e},t}(),dt=["jpg","jpeg","png"],vt=["ogv","webm","mp4"],pt=dt.concat(vt);function gt(t){return"data"in t&&"width"in t&&"height"in t}(rt=t.TextureSourceType||(t.TextureSourceType={}))[rt.Data=0]="Data",rt[rt.Element=1]="Element",rt[rt.Url=2]="Url",(nt=t.TextureFilteringType||(t.TextureFilteringType={})).MipMap="mipmap",nt.Linear="linear",nt.Nearest="nearest";var xt,_t,yt=function(e){function r(i,r,n,o,s){var a;return void 0===o&&(o={filtering:t.TextureFilteringType.Linear}),(a=e.call(this)||this).valid=!1,a.dirty=!1,a.animated=!1,a.powerOf2=!1,a.key=r,a.index=n,a.options=o,a.workpath=s,a.create(i),a}i(r,e),r.isPowerOf2=function(t){return 0==(t&t-1)},r.isSafari=function(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)},r.isTextureUrl=function(t){return t&&/\.(jpg|jpeg|png|ogv|webm|mp4)$/i.test(t.split("?")[0])},r.isTexture=function(t){return void 0!==r.getTextureOptions(t)},r.getMaxTextureSize=function(t){return t.getParameter(t.MAX_TEXTURE_SIZE)},r.getTextureOptions=function(t,e){if(void 0===e&&(e={}),"string"==typeof t&&""!==t){if(r.isTextureUrl(t))return e.url=t,-1!==t.indexOf("?")&&(e=t.split("?")[1].split("&").reduce((function(t,e){var i=e.split("="),r=decodeURIComponent(i[0]),n=decodeURIComponent(i[1]);switch(r){case"filtering":t[r]=n;break;case"repeat":case"UNPACK_FLIP_Y_WEBGL":t[r]=Boolean(n);break;case"UNPACK_PREMULTIPLY_ALPHA_WEBGL":case"TEXTURE_WRAP_S":case"TEXTURE_WRAP_T":t[r]=Number(n)}return t}),e)),e;document&&(t=document.querySelector(t))}return t instanceof HTMLCanvasElement||t instanceof HTMLImageElement||t instanceof HTMLVideoElement?(e.element=t,e):gt(t)?(e.data=t.data,e.width=t.width,e.height=t.height,e):null};var n=r.prototype;return n.create=function(t){this.texture=t.createTexture(),this.texture&&(this.valid=!0),this.setData(t,1,1,new Uint8Array([0,0,0,0]),this.options)},n.load=function(t,e){return void 0===e&&(e={}),this.options=e,"string"==typeof e.url?void 0===this.url||e.url!==this.url?this.setUrl(t,e.url,e):Promise.resolve(this):e.element?this.setElement(t,e.element,e):e.data&&e.width&&e.height?this.setData(t,e.width,e.height,e.data,e):Promise.reject(this)},n.setUrl=function(e,i,n){if(void 0===n&&(n={}),!this.valid)return Promise.reject(this);this.url=i,this.source=i,this.sourceType=t.TextureSourceType.Url,this.options=Object.assign(this.options,n);var o,s,a=String(-1===i.indexOf(":/")&&void 0!==this.workpath?this.workpath+"/"+i:i),u=i.split("?")[0].split(".").pop().toLowerCase();return-1!==vt.indexOf(u)?(C.log("GlslCanvas.setUrl video",a),(o=document.createElement("video")).setAttribute("preload","auto"),o.setAttribute("loop","true"),o.setAttribute("muted","true"),o.setAttribute("playsinline","true"),o.loop=!0,o.muted=!0,s=this.setElement(e,o,n),o.src=a,o.addEventListener("canplay",(function(){o.play()}))):(C.log("GlslCanvas.setUrl image",a),o=document.createElement("img"),s=this.setElement(e,o,n),r.isSafari()&&"data:"===i.slice(0,5)||(o.crossOrigin="anonymous"),o.src=a),s},n.setElement=function(e,i,r){var n=this;return void 0===r&&(r={}),r=this.options=Object.assign(this.options,r),new Promise((function(o,s){var a=i;if("string"==typeof i&&(i=document.querySelector(i)),i instanceof HTMLCanvasElement||i instanceof HTMLImageElement||i instanceof HTMLVideoElement)if(n.source=i,n.sourceType=t.TextureSourceType.Element,i instanceof HTMLVideoElement){var u=i;u.addEventListener("loadeddata",(function(t){n.update(e,r),n.setFiltering(e,r),o(n)})),u.addEventListener("error",(function(t){s(t)})),u.load()}else i instanceof HTMLImageElement?(i.addEventListener("load",(function(){n.update(e,r),n.setFiltering(e,r),o(n)})),i.addEventListener("error",(function(t){s(t)}))):(n.update(e,r),n.setFiltering(e,r),o(n));else{var h="the 'element' parameter (`element: "+JSON.stringify(a)+"`) must be a CSS selector string, or a <canvas>, <image> or <video> object";C.log("Texture '"+n.key+"': "+h,r),s(h)}}))},n.setData=function(e,i,r,n,o){return void 0===o&&(o={}),this.width=i,this.height=r,this.options=Object.assign(this.options,o),this.source=n,this.sourceType=t.TextureSourceType.Data,this.update(e,o),this.setFiltering(e,o),Promise.resolve(this)},n.update=function(e,i){if(this.valid){if(e.activeTexture(e.TEXTURE0+this.index),e.bindTexture(e.TEXTURE_2D,this.texture),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1===i.UNPACK_FLIP_Y_WEBGL?0:1),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,i.UNPACK_PREMULTIPLY_ALPHA_WEBGL||0),this.sourceType===t.TextureSourceType.Element)this.source instanceof HTMLImageElement&&this.source.naturalWidth&&this.source.naturalHeight?(this.width=this.source.naturalWidth,this.height=this.source.naturalHeight,e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.source)):this.source instanceof HTMLVideoElement&&this.source.videoWidth&&this.source.videoHeight?(this.width=this.source.videoWidth,this.height=this.source.videoHeight,e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.source)):this.source instanceof HTMLCanvasElement&&(this.width=this.source.width,this.height=this.source.height,e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.source));else if(this.sourceType===t.TextureSourceType.Data){var r=this.source;e.texImage2D(e.TEXTURE_2D,0,e.RGBA,this.width,this.height,0,e.RGBA,e.UNSIGNED_BYTE,r)}this.trigger("loaded",this)}},n.tryUpdate=function(t){var e=!1;return this.animated&&(e=!0,this.update(t,this.options)),e},n.destroy=function(t){this.valid&&(t.deleteTexture(this.texture),this.texture=null,delete this.source,this.source=null,this.valid=!1)},n.setFiltering=function(e,i){if(this.valid){var n=r.isPowerOf2(this.width)&&r.isPowerOf2(this.height),o=i.filtering||t.TextureFilteringType.MipMap,s=i.TEXTURE_WRAP_S||(i.repeat?e.REPEAT:e.CLAMP_TO_EDGE),a=i.TEXTURE_WRAP_T||(i.repeat?e.REPEAT:e.CLAMP_TO_EDGE);n||(o=o===t.TextureFilteringType.MipMap?t.TextureFilteringType.Linear:o,s=a=e.CLAMP_TO_EDGE,(i.repeat||i.TEXTURE_WRAP_S||i.TEXTURE_WRAP_T)&&C.warn("GlslCanvas: cannot repeat texture "+i.url+" cause is not power of 2.")),this.powerOf2=n,this.filtering=o,e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,a),this.filtering===t.TextureFilteringType.MipMap?(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.generateMipmap(e.TEXTURE_2D)):this.filtering===t.TextureFilteringType.Nearest?(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST)):this.filtering===t.TextureFilteringType.Linear&&(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR))}},r}(at),Tt=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).count=0,e.dirty=!1,e.animated=!1,e}i(e,t);var r=e.prototype;return r.clean=function(){for(var t in this.values)this.values[t].dirty=!1;this.dirty=!1},r.createOrUpdate=function(t,e,i,r,n,o){var s,a=this;void 0===r&&(r=0),void 0===n&&(n={});var u=yt.getTextureOptions(i,n);return(s=this.get(e))||(s=new yt(t,e,r+this.count,u,o),this.count++,this.set(e,s)),void 0!==u?s.load(t,u).then((function(e){if(e.source instanceof HTMLVideoElement){var i=e.source;i.addEventListener("play",(function(){e.animated=!0,a.animated=!0})),i.addEventListener("pause",(function(){e.animated=!1,a.animated=a.reduce((function(t,e){return t||e.animated}),!1)})),i.addEventListener("seeked",(function(){e.update(t,e.options),a.dirty=!0}))}return e})):Promise.resolve(s)},e}(z);(xt=t.UniformMethod||(t.UniformMethod={}))[xt.Unknown=0]="Unknown",xt.Uniform1i="uniform1i",xt.Uniform2i="uniform2i",xt.Uniform3i="uniform3i",xt.Uniform4i="uniform4i",xt.Uniform1f="uniform1f",xt.Uniform2f="uniform2f",xt.Uniform3f="uniform3f",xt.Uniform4f="uniform4f",xt.Uniform1iv="uniform1iv",xt.Uniform2iv="uniform2iv",xt.Uniform3iv="uniform3iv",xt.Uniform4iv="uniform4iv",xt.Uniform1fv="uniform1fv",xt.Uniform2fv="uniform2fv",xt.Uniform3fv="uniform3fv",xt.Uniform4fv="uniform4fv",xt.UniformMatrix2fv="uniformMatrix2fv",xt.UniformMatrix3fv="uniformMatrix3fv",xt.UniformMatrix4fv="uniformMatrix4fv",(_t=t.UniformType||(t.UniformType={}))[_t.Unknown=0]="Unknown",_t[_t.Float=1]="Float",_t[_t.Int=2]="Int",_t[_t.Bool=3]="Bool",_t[_t.Sampler2D=4]="Sampler2D",_t[_t.SamplerCube=5]="SamplerCube",_t[_t.Matrix2fv=6]="Matrix2fv",_t[_t.Matrix3fv=7]="Matrix3fv",_t[_t.Matrix4fv=8]="Matrix4fv";var Et=[t.UniformMethod.Uniform1i,t.UniformMethod.Uniform2i,t.UniformMethod.Uniform3i,t.UniformMethod.Uniform4i],Mt=[t.UniformMethod.Uniform1f,t.UniformMethod.Uniform2f,t.UniformMethod.Uniform3f,t.UniformMethod.Uniform4f],Ut=[t.UniformMethod.Uniform1iv,t.UniformMethod.Uniform2iv,t.UniformMethod.Uniform3iv,t.UniformMethod.Uniform4iv],bt=[t.UniformMethod.Uniform1fv,t.UniformMethod.Uniform2fv,t.UniformMethod.Uniform3fv,t.UniformMethod.Uniform4fv],At=function(e){var i=this;switch(this.dirty=!0,e&&Object.assign(this,e),this.method){case t.UniformMethod.UniformMatrix2fv:case t.UniformMethod.UniformMatrix3fv:case t.UniformMethod.UniformMatrix4fv:this.apply=function(t,e){if(i.dirty){t.useProgram(e);var r=t.getUniformLocation(e,i.key);t[i.method].apply(t,[r,!1].concat(i.values))}};break;default:this.apply=function(t,e){if(i.dirty){t.useProgram(e);var r=t.getUniformLocation(e,i.key);t[i.method].apply(t,[r].concat(i.values))}}}},wt=function(t){function e(e){return t.call(this,e)||this}return i(e,t),e}(At),Ft=function(e){function r(){var t;return(t=e.apply(this,arguments)||this).dirty=!1,t}i(r,e),r.isArrayOfInteger=function(t){return t.reduce((function(t,e){return t&&Number.isInteger(e)}),!0)},r.isArrayOfNumber=function(t){return t.reduce((function(t,e){return t&&"number"==typeof e}),!0)},r.isArrayOfBoolean=function(t){return t.reduce((function(t,e){return t&&"boolean"==typeof e}),!0)},r.isArrayOfTexture=function(t){return t.reduce((function(t,e){return t&&yt.isTexture(e)}),!0)},r.isArrayOfSampler2D=function(e){return e.reduce((function(e,i){return e&&i.type===t.UniformType.Sampler2D}),!0)},r.getType_=function(e){var i=t.UniformType.Unknown,n=1===e.length&&Array.isArray(e[0])?e[0]:e;return r.isArrayOfNumber(n)?i=t.UniformType.Float:r.isArrayOfBoolean(n)?i=t.UniformType.Bool:r.isArrayOfTexture(n)&&(i=t.UniformType.Sampler2D),i},r.getMethod_=function(e,i){var r=t.UniformMethod.Unknown,n=1===i.length&&Array.isArray(i[0]),o=(n?i[0]:i).length,s=o-1;switch(e){case t.UniformType.Float:r=n?s<bt.length?bt[s]:t.UniformMethod.Unknown:s<Mt.length?Mt[s]:t.UniformMethod.Uniform1fv;break;case t.UniformType.Int:case t.UniformType.Bool:r=n?s<Ut.length?Ut[s]:t.UniformMethod.Unknown:s<Et.length?Et[s]:t.UniformMethod.Uniform1iv;break;case t.UniformType.Sampler2D:r=n?t.UniformMethod.Uniform1iv:1===o?t.UniformMethod.Uniform1i:t.UniformMethod.Uniform1iv}return r},r.parseUniform=function(e,i,n){var o;void 0===n&&(n=null),n=n||r.getType_(i);var s=r.getMethod_(n,i);if(n!==t.UniformType.Unknown&&s!==t.UniformMethod.Unknown){if(n===t.UniformType.Sampler2D&&s===t.UniformMethod.Uniform1iv)return i[0].map((function(t,i){return new At({method:s,type:n,key:e+"["+i+"]",values:[t]})}));o=new At({method:s,type:n,key:e,values:i})}else C.error("Uniforms.parseUniform.Unknown",e,i);return o};var n=r.prototype;return n.create=function(t,e,i,r){var n=new At({method:t,type:e,key:i,values:r});return this.set(i,n),this.dirty=!0,n},n.createTexture=function(e,i){var r;return r=-1!==e.indexOf("]")?new wt({method:t.UniformMethod.Uniform1iv,type:t.UniformType.Sampler2D,key:e,values:[[i]]}):new wt({method:t.UniformMethod.Uniform1i,type:t.UniformType.Sampler2D,key:e,values:[i]}),this.set(e,r),this.dirty=!0,r},n.update=function(t,e,i,r){var n=this.get(i);n&&(n.method=t,n.type=e,n.values=r,n.dirty=!0,this.dirty=!0)},n.createOrUpdate=function(t,e,i,r){this.has(i)?this.update(t,e,i,r):this.create(t,e,i,r)},n.apply=function(t,e){for(var i in t.useProgram(e),this.values)this.values[i].apply(t,e)},n.clean=function(){for(var t in this.values)this.values[t].dirty=!1;this.dirty=!1},r.isDifferent=function(t,e){return t.length!==e.length||t.reduce((function(t,i,r){return t||i!==e[r]}),!1)},r}(z),Lt=function(e){function r(){var t;return(t=e.call(this)||this).uniforms=new Ft,t.buffers=new q,t.textures=new Tt,t.textureList=[],t.W=0,t.H=0,t.mouse=new K,t.radians=0,t.dirty=!0,t.animated=!1,t.camera=new Z,t.cache={},t.drawFunc_=t.drawArrays_,t}i(r,e);var n=r.prototype;return n.render=function(){var t=this.gl;if(t){var e=t.drawingBufferWidth,i=t.drawingBufferHeight;for(var r in this.update_(),t.viewport(0,0,e,i),this.buffers.values){var n=this.buffers.values[r];n.geometry.attachAttributes_(t,n.program),this.uniforms.apply(t,n.program),n.render(t,e,i)}this.geometry.attachAttributes_(t,this.program),this.uniforms.apply(t,this.program),this.drawFunc_(this.timer.delta),this.uniforms.clean(),this.textures.clean(),this.dirty=!1,this.trigger("render",this)}},n.drawArrays_=function(t){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,this.W,this.H),e.clearColor(0,0,0,1),e.clearDepth(1),e.enable(e.DEPTH_TEST),e.depthFunc(e.LEQUAL),e.enable(e.CULL_FACE),this.doubleSided&&this.mode!==O.Flat&&(e.cullFace(e.FRONT),e.drawArrays(e.TRIANGLES,0,this.geometry.size),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA)),e.cullFace(e.BACK),e.drawArrays(e.TRIANGLES,0,this.geometry.size)},n.create_=function(){this.createGeometry_(),this.createUniforms_()},n.createGeometry_=function(){this.parseGeometry_(),this.setMode(this.mode)},n.parseGeometry_=function(){var t=/^attribute\s+vec4\s+a_position\s*;\s*\/\/\s*([\w|\:\/\/|\.|\-|\_|\?|\&|\=]+)/gm.exec(this.vertexString);t&&t.length>1?this.mesh=t[1]:this.mesh=this.defaultMesh},n.createUniforms_=function(){var e=this.gl,i=this.fragmentString,r=e.drawingBufferWidth,n=e.drawingBufferHeight,o=this.timer=new ot,s=(i.match(/u_delta/g)||[]).length>1,a=(i.match(/u_time/g)||[]).length>1,u=(i.match(/u_date/g)||[]).length>1,h=(i.match(/u_mouse/g)||[]).length>1;if(this.animated=a||u||h,this.uniforms.create(t.UniformMethod.Uniform2f,t.UniformType.Float,"u_resolution",[r,n]),s&&this.uniforms.create(t.UniformMethod.Uniform1f,t.UniformType.Float,"u_delta",[o.delta/1e3]),a&&this.uniforms.create(t.UniformMethod.Uniform1f,t.UniformType.Float,"u_time",[o.current/1e3]),u){var f=new Date;this.uniforms.create(t.UniformMethod.Uniform4f,t.UniformType.Float,"u_date",[f.getFullYear(),f.getMonth(),f.getDate(),3600*f.getHours()+60*f.getMinutes()+f.getSeconds()+.001*f.getMilliseconds()])}h&&this.uniforms.create(t.UniformMethod.Uniform2f,t.UniformType.Float,"u_mouse",[0,0]),this.projectionMatrix=tt(),this.uniforms.create(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_projectionMatrix",this.projectionMatrix),this.modelViewMatrix=tt(),this.uniforms.create(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_modelViewMatrix",this.modelViewMatrix),this.normalMatrix=tt(),this.uniforms.create(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_normalMatrix",this.normalMatrix)},n.update_=function(){this.updateUniforms_()},n.updateUniforms_=function(){var e=this.gl,i=e.drawingBufferWidth,r=e.drawingBufferHeight;if(this.timer){var n=this.timer.next();if(this.uniforms.update(t.UniformMethod.Uniform2f,t.UniformType.Float,"u_resolution",[i,r]),this.uniforms.has("u_delta")&&this.uniforms.update(t.UniformMethod.Uniform1f,t.UniformType.Float,"u_delta",[n.delta/1e3]),this.uniforms.has("u_time")&&this.uniforms.update(t.UniformMethod.Uniform1f,t.UniformType.Float,"u_time",[n.current/1e3]),this.uniforms.has("u_date")){var o=new Date;this.uniforms.update(t.UniformMethod.Uniform4f,t.UniformType.Float,"u_date",[o.getFullYear(),o.getMonth(),o.getDate(),3600*o.getHours()+60*o.getMinutes()+o.getSeconds()+.001*o.getMilliseconds()])}if(this.uniforms.has("u_mouse")){var s=this.mouse;this.uniforms.update(t.UniformMethod.Uniform2f,t.UniformType.Float,"u_mouse",[s.x,s.y])}this.mode!==O.Flat&&(this.uniforms.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_projectionMatrix",this.updateProjectionMatrix_()),this.uniforms.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_modelViewMatrix",this.updateModelViewMatrix_(this.timer.delta)),this.uniforms.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_normalMatrix",this.updateNormalMatrix_(this.modelViewMatrix)))}},n.updateProjectionMatrix_=function(){var t=this.gl,e=45*Math.PI/180,i=t.drawingBufferWidth/t.drawingBufferHeight;return function(t,e,i,r,n){var o,s=1/Math.tan(e/2);t[0]=s/i,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s,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!=n&&n!==1/0?(o=1/(r-n),t[10]=(n+r)*o,t[14]=2*n*r*o):(t[10]=-1,t[14]=-2*r)}(this.projectionMatrix,e,i,.1,100),this.projectionMatrix},n.updateModelViewMatrix_=function(t){var e,i,r,n,o,s,a,u,h,f,c,l,m,d,v,p,g,x;return this.modelViewMatrix=et(this.modelViewMatrix),e=this.modelViewMatrix,i=this.modelViewMatrix,r=[0,0,-this.camera.radius],p=r[0],g=r[1],x=r[2],i===e?(e[12]=i[0]*p+i[4]*g+i[8]*x+i[12],e[13]=i[1]*p+i[5]*g+i[9]*x+i[13],e[14]=i[2]*p+i[6]*g+i[10]*x+i[14],e[15]=i[3]*p+i[7]*g+i[11]*x+i[15]):(n=i[0],o=i[1],s=i[2],a=i[3],u=i[4],h=i[5],f=i[6],c=i[7],l=i[8],m=i[9],d=i[10],v=i[11],e[0]=n,e[1]=o,e[2]=s,e[3]=a,e[4]=u,e[5]=h,e[6]=f,e[7]=c,e[8]=l,e[9]=m,e[10]=d,e[11]=v,e[12]=n*p+u*g+l*x+i[12],e[13]=o*p+h*g+m*x+i[13],e[14]=s*p+f*g+d*x+i[14],e[15]=a*p+c*g+v*x+i[15]),it(this.modelViewMatrix,this.modelViewMatrix,this.camera.theta+this.radians,[0,1,0]),it(this.modelViewMatrix,this.modelViewMatrix,this.camera.phi,[1,0,0]),this.camera.mouse||(this.camera.theta+=(0-this.camera.theta)/20,this.camera.phi+=(0-this.camera.phi)/20,this.radians+=5e-4*t),this.modelViewMatrix},n.updateNormalMatrix_=function(t){var e,i,r,n,o,s,a,u,h,f,c,l,m,d,v,p,g,x,_,y,T,E,M,U,b,A,w,F,L,R,S;return this.normalMatrix=et(this.normalMatrix),e=this.normalMatrix,r=(i=t)[0],n=i[1],o=i[2],s=i[3],a=i[4],u=i[5],h=i[6],f=i[7],c=i[8],l=i[9],m=i[10],d=i[11],v=i[12],p=i[13],g=i[14],x=i[15],(S=(_=r*u-n*a)*(R=m*x-d*g)-(y=r*h-o*a)*(L=l*x-d*p)+(T=r*f-s*a)*(F=l*g-m*p)+(E=n*h-o*u)*(w=c*x-d*v)-(M=n*f-s*u)*(A=c*g-m*v)+(U=o*f-s*h)*(b=c*p-l*v))&&(S=1/S,e[0]=(u*R-h*L+f*F)*S,e[1]=(o*L-n*R-s*F)*S,e[2]=(p*U-g*M+x*E)*S,e[3]=(m*M-l*U-d*E)*S,e[4]=(h*w-a*R-f*A)*S,e[5]=(r*R-o*w+s*A)*S,e[6]=(g*T-v*U-x*y)*S,e[7]=(c*U-m*T+d*y)*S,e[8]=(a*L-u*w+f*b)*S,e[9]=(n*w-r*L-s*b)*S,e[10]=(v*M-p*T+x*_)*S,e[11]=(l*T-c*M-d*_)*S,e[12]=(u*A-a*F-h*b)*S,e[13]=(r*F-n*A+o*b)*S,e[14]=(p*y-v*E-g*_)*S,e[15]=(c*E-l*y+m*_)*S),function(t,e){if(t===e){var i=e[1],r=e[2],n=e[3],o=e[6],s=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=i,t[6]=e[9],t[7]=e[13],t[8]=r,t[9]=o,t[11]=e[14],t[12]=n,t[13]=s,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]}(this.normalMatrix,this.normalMatrix),this.normalMatrix},n.setMode=function(e){var i,r=this;if(e===O.Mesh&&(i=this.cache[this.mesh]))return this.geometry=i,this.mode=O.Mesh,void(this.dirty=!0);switch(e){case O.Flat:i=new H,this.uniforms.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_projectionMatrix",tt()),this.uniforms.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_modelViewMatrix",tt()),this.uniforms.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_normalMatrix",tt());break;case O.Box:i=new ut;break;case O.Sphere:i=new ht;break;case O.Torus:i=new ft;break;case O.Mesh:i=new H,this.mesh?(new mt).load(this.getResource(this.mesh)).then((function(t){t.createAttributes_(r.gl,r.program);var e={};e[r.mesh]=t,r.cache=e,r.geometry=t,r.dirty=!0}),(function(t){C.warn("GlslCanvas",t),r.mode=O.Flat})):e=O.Flat}i.create(this.gl,this.program),this.geometry=i,this.mode=e,this.dirty=!0},n.setMesh=function(t){this.mesh=t},n.getResource=function(t){return String(-1===t.indexOf(":/")&&void 0!==this.workpath?this.workpath+"/"+t:t)},r}(at),Rt=function(e){function n(t,i){var o;return void 0===i&&(i={}),(o=e.call(this)||this).valid=!1,o.visible=!1,o.controls=!1,t?(o.options=i,o.canvas=t,o.width=0,o.height=0,o.rect=t.getBoundingClientRect(),o.devicePixelRatio=window.devicePixelRatio||1,o.mode=i.mode||O.Flat,o.mesh=i.mesh||void 0,o.doubleSided=i.doubleSided||!1,o.defaultMesh=o.mesh,o.workpath=i.workpath,t.style.backgroundColor=i.backgroundColor||"rgba(0,0,0,0)",o.getShaders_().then((function(t){o.load().then((function(t){o.program&&(o.addListeners_(),o.onLoop())}))}),(function(t){C.error("GlslCanvas.getShaders_.error",t)})),n.items.push(r(o)),o):r(o)}i(n,e);var o=n.prototype;return o.getShaders_=function(){var t=this;return new Promise((function(e,i){t.vertexString=t.options.vertexString||t.vertexString,t.fragmentString=t.options.fragmentString||t.fragmentString;var r=t.canvas,n={};r.hasAttribute("data-vertex-url")&&(n.vertex=r.getAttribute("data-vertex-url")),r.hasAttribute("data-fragment-url")&&(n.fragment=r.getAttribute("data-fragment-url")),r.hasAttribute("data-vertex")&&(t.vertexString=r.getAttribute("data-vertex")),r.hasAttribute("data-fragment")&&(t.fragmentString=r.getAttribute("data-fragment")),Object.keys(n).length?Promise.all(Object.keys(n).map((function(e,i){var r=n[e];return P.fetch(r).then((function(i){return"vertex"===e?t.vertexString=i:t.fragmentString=i}))}))).then((function(i){e([t.vertexString,t.fragmentString])})):e([t.vertexString,t.fragmentString])}))},o.addListeners_=function(){this.onScroll=this.onScroll.bind(this),this.onWheel=this.onWheel.bind(this),this.onClick=this.onClick.bind(this),this.onMove=this.onMove.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseOver=this.onMouseOver.bind(this),this.onMouseOut=this.onMouseOut.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onTouchMove=this.onTouchMove.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onLoop=this.onLoop.bind(this),window.addEventListener("scroll",this.onScroll),document.addEventListener("mousemove",this.onMouseMove,!1),document.addEventListener("touchmove",this.onTouchMove),this.addCanvasListeners_()},o.addCanvasListeners_=function(){this.controls=this.canvas.hasAttribute("controls"),this.canvas.addEventListener("wheel",this.onWheel),this.canvas.addEventListener("click",this.onClick),this.canvas.addEventListener("mousedown",this.onMouseDown),this.canvas.addEventListener("touchstart",this.onTouchStart),this.controls&&(this.canvas.addEventListener("mouseover",this.onMouseOver),this.canvas.addEventListener("mouseout",this.onMouseOut),this.canvas.hasAttribute("data-autoplay")||this.pause())},o.removeCanvasListeners_=function(){this.canvas.removeEventListener("wheel",this.onWheel),this.canvas.removeEventListener("click",this.onClick),this.canvas.removeEventListener("mousedown",this.onMouseDown),this.canvas.removeEventListener("mouseup",this.onMouseUp),this.canvas.removeEventListener("touchstart",this.onTouchStart),this.canvas.removeEventListener("touchend",this.onTouchEnd),this.controls&&(this.canvas.removeEventListener("mouseover",this.onMouseOver),this.canvas.removeEventListener("mouseout",this.onMouseOut))},o.removeListeners_=function(){window.cancelAnimationFrame(this.rafId),window.removeEventListener("scroll",this.onScroll),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("touchmove",this.onTouchMove),this.removeCanvasListeners_()},o.onScroll=function(t){this.rect=this.canvas.getBoundingClientRect()},o.onWheel=function(t){this.camera.wheel(t.deltaY),this.dirty=this.mode!==O.Flat,this.trigger("wheel",t)},o.onClick=function(t){this.controls&&this.toggle(),this.trigger("click",t)},o.onDown=function(t,e){this.mouse.x=t*this.devicePixelRatio,this.mouse.y=e*this.devicePixelRatio;var i=this.rect,r=Math.min(i.width,i.height);this.camera.down(t/r,e/r),this.trigger("down",this.mouse)},o.onMove=function(t,e){var i=this.rect,r=(t-i.left)*this.devicePixelRatio,n=(i.height-(e-i.top))*this.devicePixelRatio;if(r!==this.mouse.x||n!==this.mouse.y){this.mouse.x=r,this.mouse.y=n;var o=Math.min(i.width,i.height);this.camera.move(t/o,e/o),this.dirty=this.mode!==O.Flat&&null!==this.camera.mouse,this.trigger("move",this.mouse)}},o.onUp=function(t){this.camera.up(),this.controls&&this.pause(),this.trigger("out",t)},o.onMouseDown=function(t){this.onDown(t.clientX,t.clientY),document.addEventListener("mouseup",this.onMouseUp),document.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("touchmove",this.onTouchMove)},o.onMouseMove=function(t){this.onMove(t.clientX,t.clientY)},o.onMouseUp=function(t){this.onUp(t)},o.onMouseOver=function(t){this.play(),this.trigger("over",t)},o.onMouseOut=function(t){this.pause(),this.trigger("out",t)},o.onTouchStart=function(t){var e=[].slice.call(t.touches).reduce((function(t,e){return(t=t||new K).x+=e.clientX,t.y+=e.clientY,t}),null);e&&this.onDown(e.x/t.touches.length,e.y/t.touches.length),this.controls&&this.play(),this.trigger("over",t),document.addEventListener("touchend",this.onTouchEnd),document.removeEventListener("mousedown",this.onMouseDown),document.removeEventListener("mousemove",this.onMouseMove),this.controls&&(this.canvas.removeEventListener("mouseover",this.onMouseOver),this.canvas.removeEventListener("mouseout",this.onMouseOut))},o.onTouchMove=function(t){var e=[].slice.call(t.touches).reduce((function(t,e){return(t=t||new K).x+=e.clientX,t.y+=e.clientY,t}),null);e&&this.onMove(e.x/t.touches.length,e.y/t.touches.length)},o.onTouchEnd=function(t){this.onUp(t),document.removeEventListener("touchend",this.onTouchEnd)},o.onLoop=function(t){this.checkRender(),this.rafId=window.requestAnimationFrame(this.onLoop)},o.setUniform_=function(e,i,r,n){var o=this;void 0===r&&(r={}),void 0===n&&(n=null);var s=Ft.parseUniform(e,i,n);if(Array.isArray(s))Ft.isArrayOfSampler2D(s)?s.forEach((function(t){return o.loadTexture(t.key,t.values[0],r)})):s.forEach((function(t){return o.uniforms.set(t.key,t.values[0])}));else if(s)switch(s.type){case t.UniformType.Sampler2D:this.loadTexture(e,i[0],r);break;default:this.uniforms.set(e,s)}},o.isVisible_=function(){var t=this.rect;return t.top+t.height>0&&t.top<(window.innerHeight||document.documentElement.clientHeight)},o.isAnimated_=function(){return(this.animated||this.textures.animated||this.mode!==O.Flat)&&!this.timer.paused},o.isDirty_=function(){return this.dirty||this.uniforms.dirty||this.textures.dirty},o.sizeDidChanged_=function(){var t=this.gl,e=Math.ceil(this.canvas.clientWidth),i=Math.ceil(this.canvas.clientHeight);if(this.width!==e||this.height!==i){this.width=e,this.height=i;var r=Math.ceil(e*this.devicePixelRatio),n=Math.ceil(i*this.devicePixelRatio);for(var o in this.W=r,this.H=n,this.canvas.width=r,this.canvas.height=n,this.buffers.values){this.buffers.values[o].resize(t,r,n)}return this.rect=this.canvas.getBoundingClientRect(),this.trigger("resize"),!0}return!1},o.parseTextures_=function(t){for(var e,i=this,r=/uniform\s*sampler2D\s*([\w]*);(\s*\/\/\s*([\w|\:\/\/|\.|\-|\_|\?|\&|\=]*)|\s*)/gm;null!==(e=r.exec(t));){var n=e[1],o=e[3];yt.isTextureUrl(o)?this.textureList.push({key:n,url:o}):this.buffers.has(n)||this.textureList.push({key:n,url:null})}this.canvas.hasAttribute("data-textures")&&this.canvas.getAttribute("data-textures").split(",").forEach((function(t,e){var r="u_texture"+e;i.textureList.push({key:r,url:t})}));return this.textureList.length>0},o.load=function(t,e){var i=this,r=W.getFragmentVertex(this.gl,t||this.fragmentString);return Promise.all([W.getIncludes(t||this.fragmentString),W.getIncludes(r||e||this.vertexString)]).then((function(t){return i.fragmentString=t[0],i.vertexString=t[1],i.createContext_()}))},o.getContext_=function(){var t=this.vertexString,e=this.fragmentString;if(this.vertexString=W.getVertex(t,e,this.mode),this.fragmentString=W.getFragment(t,e,this.mode),W.versionDiffers(this.gl,t,e)&&(this.destroyContext_(),this.swapCanvas_(),this.uniforms=new Ft,this.buffers=new q,this.textures=new Tt,this.textureList=[]),!this.gl){var i=W.tryInferContext(t,e,this.canvas,this.options,this.options.extensions,this.options.onError);if(!i)return null;this.gl=i}return this.gl},o.createContext_=function(){var t,e,i=this.getContext_();if(!i)return!1;try{if(W.inferPrecision(this.fragmentString),t=W.createShader(i,this.vertexString,i.VERTEX_SHADER),e=W.createShader(i,this.fragmentString,i.FRAGMENT_SHADER))this.valid=!0;else{var r=W.getFragment(null,null,this.mode);e=W.createShader(i,r,i.FRAGMENT_SHADER),this.valid=!1}}catch(t){return this.trigger("error",t),!1}var n=W.createProgram(i,[t,e]);if(!n)return this.trigger("error",W.lastError),!1;if(i.deleteShader(t),i.deleteShader(e),this.program=n,this.valid){try{this.buffers=q.getBuffers(i,this.fragmentString,W.getBufferVertex(i))}catch(t){return this.valid=!1,this.trigger("error",t),!1}this.create_(),this.animated?this.canvas.classList.add("animated"):this.canvas.classList.remove("animated")}return this.trigger("load",this),this.valid},o.create_=function(){this.parseMode_(),this.parseMesh_(),e.prototype.create_.call(this),this.createBuffers_(),this.createTextures_()},o.parseMode_=function(){if(this.canvas.hasAttribute("data-mode")){var t=this.canvas.getAttribute("data-mode");-1!==["flat","box","sphere","torus","mesh"].indexOf(t)&&(this.mode=t)}},o.parseMesh_=function(){if(this.canvas.hasAttribute("data-mesh")){var t=this.canvas.getAttribute("data-mesh");-1!==t.indexOf(".obj")&&(this.mesh=this.defaultMesh=t)}},o.createBuffers_=function(){for(var e in this.buffers.values){var i=this.buffers.values[e];this.uniforms.create(t.UniformMethod.Uniform1i,t.UniformType.Sampler2D,i.key,[i.input.index])}},o.createTextures_=function(){var t=this;this.parseTextures_(this.fragmentString)&&(this.textureList.filter((function(t){return t.url})).forEach((function(e){t.setTexture(e.key,e.url,e.options)})),this.textureList=[])},o.update_=function(){e.prototype.update_.call(this),this.updateBuffers_(),this.updateTextures_()},o.updateBuffers_=function(){for(var e in this.buffers.values){var i=this.buffers.values[e];this.uniforms.update(t.UniformMethod.Uniform1i,t.UniformType.Sampler2D,i.key,[i.input.index])}},o.updateTextures_=function(){var e=this.gl;for(var i in this.textures.values){var r=this.textures.values[i];r.tryUpdate(e),this.uniforms.update(t.UniformMethod.Uniform1i,t.UniformType.Sampler2D,r.key,[r.index])}},o.destroyContext_=function(){var t=this.gl;for(var e in t.useProgram(null),this.program&&t.deleteProgram(this.program),this.buffers.values){this.buffers.values[e].destroy(t)}for(var i in this.textures.values){this.textures.values[i].destroy(t)}this.buffers=null,this.textures=null,this.uniforms=null,this.program=null,this.gl=null},o.swapCanvas_=function(){var t=this.canvas,e=t.cloneNode();t.parentNode.replaceChild(e,t),this.canvas=e,this.addCanvasListeners_()},o.destroy=function(){this.removeListeners_(),this.destroyContext_(),this.animated=!1,this.valid=!1;var t=n.items.indexOf(this);-1!==t&&n.items.splice(t,1)},o.loadTexture=function(e,i,r){var n=this;void 0===r&&(r={}),this.valid?this.textures.createOrUpdate(this.gl,e,i,this.buffers.count,r,this.options.workpath).then((function(i){var r=i.index;n.uniforms.createTexture(e,r).texture=i;var o=-1!==e.indexOf("[")?e.replace("[","Resolution["):e+"Resolution";return n.uniforms.create(t.UniformMethod.Uniform2f,t.UniformType.Float,o,[i.width,i.height]),i}),(function(t){var r=Array.isArray(t.path)?t.path.map((function(t){return t.error?t.error.message:""})).join(", "):t.message;C.error("GlslCanvas.loadTexture.error",e,i,r),n.trigger("textureError",{key:e,urlElementOrData:i,message:r})})):this.textureList.push({key:e,url:i,options:r})},o.setTexture=function(t,e,i){return void 0===i&&(i={}),this.setUniform_(t,[e],i)},o.setUniform=function(t){for(var e=arguments.length,i=new Array(e>1?e-1:0),r=1;r<e;r++)i[r-1]=arguments[r];return this.setUniform_(t,i)},o.setUniformOfInt=function(e,i){return this.setUniform_(e,i,null,t.UniformType.Int)},o.setUniforms=function(t){for(var e in t)this.setUniform(e,t[e])},o.pause=function(){this.valid&&(this.timer.pause(),this.canvas.classList.add("paused"),this.trigger("pause"))},o.play=function(){this.valid&&(this.timer.play(),this.canvas.classList.remove("paused"),this.trigger("play"))},o.toggle=function(){this.valid&&(this.timer.paused?this.play():this.pause())},o.checkRender=function(){this.isVisible_()&&(this.sizeDidChanged_()||this.isDirty_()||this.isAnimated_())?(this.render(),this.canvas.classList.add("playing")):this.canvas.classList.remove("playing")},n}(Lt);function St(t,e){return Rt.items.find((function(e){return e.canvas===t}))||new Rt(t,e)}function Pt(){return[].slice.call(document.getElementsByClassName("glsl-canvas")).filter((function(t){return t instanceof HTMLCanvasElement})).map((function(t){return St(t)}))}Rt.items=[],document&&document.addEventListener("DOMContentLoaded",(function(){Pt()})),t.BoxGeometry=ut,t.Buffer=j,t.Buffers=q,t.Canvas=Rt,t.CanvasTimer=ot,t.Common=P,t.Context=W,t.ContextVertexBuffers=V,t.DefaultWebGL2BufferFragment=y,t.DefaultWebGL2BufferVertex=x,t.DefaultWebGL2FlatFragment=d,t.DefaultWebGL2MeshFragment=p,t.DefaultWebGL2MeshVertex=l,t.DefaultWebGLBufferFragment=_,t.DefaultWebGLBufferVertex=g,t.DefaultWebGLFlatFragment=m,t.DefaultWebGLMeshFragment=v,t.DefaultWebGLMeshVertex=c,t.FlatGeometry=H,t.Geometry=X,t.IOBuffer=Y,t.IterableStringMap=z,t.Listener=st,t.Logger=C,t.METHODS_FLOAT=Mt,t.METHODS_FLOATV=bt,t.METHODS_INT=Et,t.METHODS_INTV=Ut,t.ObjLoader=mt,t.OrbitCamera=Z,t.Renderer=Lt,t.SphereGeometry=ht,t.Subscriber=at,t.Texture=yt,t.TextureExtensions=pt,t.TextureImageExtensions=dt,t.TextureVideoExtensions=vt,t.Textures=Tt,t.TorusGeometry=ft,t.Uniform=At,t.UniformTexture=wt,t.Uniforms=Ft,t.Vector2=K,t.Vector3=J,t.isTextureData=gt,t.loadAll=Pt,t.of=St,Object.defineProperty(t,"__esModule",{value:!0})}));
  //# sourceMappingURL=glsl-canvas.min.js.map