/** * @license glsl-canvas-js v0.2.6 * (c) 2021 Luca Zampetti * License: MIT */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).glsl={})}(this,(function(t){"use strict";function e(t,e){for(var r=0;r=P.Log&&(e=console).log.apply(e,arguments)},t.warn=function(){var e;t.enabled&&t.level>=P.Warn&&(e=console).warn.apply(e,arguments)},t.error=function(){var e;t.enabled&&t.level>=P.Error&&(e=console).error.apply(e,arguments)},t}();I.level=P.Warn,I.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"}(C||(C={}));var G,k={webgl:{flat:{vertex:l,fragment:m},mesh:{vertex:l,fragment:p}},webgl2:{flat:{vertex:d,fragment:v},mesh:{vertex:d,fragment:g}}};(G=t.ContextError||(t.ContextError={}))[G.BrowserSupport=1]="BrowserSupport",G[G.Other=2]="Other";var W=function(){},N=function(){function e(){}return e.getContext_=function(t,e){for(var r=["webgl","experimental-webgl"],i=null,n=0;n1&&(e.precision=r[1]),e.precision},e.versionDiffers=function(r,i,n){if(r){var o=this.isWebGl2(r)?t.ContextVersion.WebGl2:t.ContextVersion.WebGl;return e.inferVersion(i,n)!==o}return!1},e.getBufferVertex=function(t){return this.isWebGl2(t)?y:_},e.getVertex=function(t,e,r){if(void 0===r&&(r=C.Flat),t)return t;var i=this.inferVersion(t,e);return k[i][r===C.Flat?"flat":"mesh"].vertex},e.getFragment=function(t,e,r){if(void 0===r&&(r=C.Flat),e)return e;var i=this.inferVersion(t,e);return k[i][r===C.Flat?"flat":"mesh"].fragment},e.tryInferContext=function(r,i,n,o,s,a){function u(t,e){if("function"==typeof a)a(t);else{var r=n.parentNode;r&&(r.innerHTML='
'+e+"
")}}if(void 0===s&&(s=[]),!WebGLRenderingContext)return u(t.ContextError.BrowserSupport,'This page requires a browser that supports WebGL.
\n\t\t\tClick here to upgrade your browser.'),null;var h=e.inferContext(r,i,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):I.warn("GlslCanvas "+t+" not supported")}))}else u(t.ContextError.Other,'It does not appear your computer can support WebGL.
\n\t\t\tClick here for more information.');return h},e.tryGetContext=function(r,i,n){function o(t,e){if("function"==typeof n)n(t);else{var i=r.parentNode;i&&(i.innerHTML='
'+e+"
")}}if(!WebGLRenderingContext)return o(t.ContextError.BrowserSupport,'This page requires a browser that supports WebGL.
\n\t\t\tClick here to upgrade your browser.'),null;var s=e.getContext_(r,i);return s?s.getExtension("OES_standard_derivatives"):o(t.ContextError.Other,'It does not appear your computer can support WebGL.
\n\t\t\tClick here for more information.'),s},e.inferContext=function(e,r,i,n){return this.inferVersion(e,r)===t.ContextVersion.WebGl2?this.getContext2_(i,n):this.getContext_(i,n)},e.createShader=function(t,r,i,n){void 0===n&&(n=0);var o=t.createShader(i);if(r=r.replace(/precision\s+(.+)\s+float/,"precision "+e.precision+" float"),t.shaderSource(o,r),t.compileShader(o),!t.getShaderParameter(o,t.COMPILE_STATUS))throw e.lastError=t.getShaderInfoLog(o),I.error("*** Error compiling shader: "+e.lastError),t.deleteShader(o),{shader:o,source:r,type:i,error:e.lastError,offset:n};return o},e.createProgram=function(t,r,i,n){for(var o=t.createProgram(),s=0;s1?e-1:0),i=1;i0&&(new Array(f/3).fill(0).forEach((function(){var t=lt[dt%lt.length];a.push(t[0],t[1],t[2],1)})),dt++)},e.parse=function(t){var e=this,r=[],i=[],n=[],o=[];dt=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,r,i,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)})),d=new J(l[0],l[1],l[2]).normalize();a.push([d.x,d.y,d.z])}else if(0===t.indexOf("vt ")){var m=t.replace("vt","").trim().split(" ").map((function(t){return parseFloat(t)}));u.push(m)}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,r,i,n,o);for(var f={min:new J(Number.POSITIVE_INFINITY),max:new J(Number.NEGATIVE_INFINITY)},c=0;c, or