1 line
22 KiB
JavaScript
1 line
22 KiB
JavaScript
!function(e){var t=window.webpackHotUpdate;window.webpackHotUpdate=function(e,r){!function(e,t){if(!_[e]||!b[e])return;for(var r in b[e]=!1,t)Object.prototype.hasOwnProperty.call(t,r)&&(p[r]=t[r]);0==--g&&0===m&&E()}(e,r),t&&t(e,r)};var r,n=!0,i="f56268094d3b9f806c19",o={},a=[],c=[];function u(e){var t=S[e];if(!t)return R;var n=function(n){return t.hot.active?(S[n]?-1===S[n].parents.indexOf(e)&&S[n].parents.push(e):(a=[e],r=n),-1===t.children.indexOf(n)&&t.children.push(n)):(console.warn("[HMR] unexpected require("+n+") from disposed module "+e),a=[]),R(n)},i=function(e){return{configurable:!0,enumerable:!0,get:function(){return R[e]},set:function(t){R[e]=t}}};for(var o in R)Object.prototype.hasOwnProperty.call(R,o)&&"e"!==o&&"t"!==o&&Object.defineProperty(n,o,i(o));return n.e=function(e){return"ready"===f&&d("prepare"),m++,R.e(e).then(t,(function(e){throw t(),e}));function t(){m--,"prepare"===f&&(w[e]||P(e),0===m&&0===g&&E())}},n.t=function(e,t){return 1&t&&(e=n(e)),R.t(e,-2&t)},n}function s(t){var n={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:r!==t,active:!0,accept:function(e,t){if(void 0===e)n._selfAccepted=!0;else if("function"==typeof e)n._selfAccepted=e;else if("object"==typeof e)for(var r=0;r<e.length;r++)n._acceptedDependencies[e[r]]=t||function(){};else n._acceptedDependencies[e]=t||function(){}},decline:function(e){if(void 0===e)n._selfDeclined=!0;else if("object"==typeof e)for(var t=0;t<e.length;t++)n._declinedDependencies[e[t]]=!0;else n._declinedDependencies[e]=!0},dispose:function(e){n._disposeHandlers.push(e)},addDisposeHandler:function(e){n._disposeHandlers.push(e)},removeDisposeHandler:function(e){var t=n._disposeHandlers.indexOf(e);t>=0&&n._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,f){case"idle":(p={})[t]=e[t],d("ready");break;case"ready":M(t);break;case"prepare":case"check":case"dispose":case"apply":(v=v||[]).push(t)}},check:O,apply:A,status:function(e){if(!e)return f;l.push(e)},addStatusHandler:function(e){l.push(e)},removeStatusHandler:function(e){var t=l.indexOf(e);t>=0&&l.splice(t,1)},data:o[t]};return r=void 0,n}var l=[],f="idle";function d(e){f=e;for(var t=0;t<l.length;t++)l[t].call(null,e)}var h,p,y,v,g=0,m=0,w={},b={},_={};function k(e){return+e+""===e?+e:e}function O(e){if("idle"!==f)throw new Error("check() is only allowed in idle status");return n=e,d("check"),(t=1e4,t=t||1e4,new Promise((function(e,r){if("undefined"==typeof XMLHttpRequest)return r(new Error("No browser support"));try{var n=new XMLHttpRequest,o=R.p+""+i+".hot-update.json";n.open("GET",o,!0),n.timeout=t,n.send(null)}catch(e){return r(e)}n.onreadystatechange=function(){if(4===n.readyState)if(0===n.status)r(new Error("Manifest request to "+o+" timed out."));else if(404===n.status)e();else if(200!==n.status&&304!==n.status)r(new Error("Manifest request to "+o+" failed."));else{try{var t=JSON.parse(n.responseText)}catch(e){return void r(e)}e(t)}}}))).then((function(e){if(!e)return d(x()?"ready":"idle"),null;b={},w={},_=e.c,y=e.h,d("prepare");var t=new Promise((function(e,t){h={resolve:e,reject:t}}));p={};return P(0),"prepare"===f&&0===m&&0===g&&E(),t}));var t}function P(e){_[e]?(b[e]=!0,g++,function(e){var t=document.createElement("script");t.charset="utf-8",t.src=R.p+""+e+"."+i+".hot-update.js",document.head.appendChild(t)}(e)):w[e]=!0}function E(){d("ready");var e=h;if(h=null,e)if(n)Promise.resolve().then((function(){return A(n)})).then((function(t){e.resolve(t)}),(function(t){e.reject(t)}));else{var t=[];for(var r in p)Object.prototype.hasOwnProperty.call(p,r)&&t.push(k(r));e.resolve(t)}}function A(t){if("ready"!==f)throw new Error("apply() is only allowed in ready status");return function t(n){var c,u,s,l,f;function h(e){for(var t=[e],r={},n=t.map((function(e){return{chain:[e],id:e}}));n.length>0;){var i=n.pop(),o=i.id,a=i.chain;if((l=S[o])&&(!l.hot._selfAccepted||l.hot._selfInvalidated)){if(l.hot._selfDeclined)return{type:"self-declined",chain:a,moduleId:o};if(l.hot._main)return{type:"unaccepted",chain:a,moduleId:o};for(var c=0;c<l.parents.length;c++){var u=l.parents[c],s=S[u];if(s){if(s.hot._declinedDependencies[o])return{type:"declined",chain:a.concat([u]),moduleId:o,parentId:u};-1===t.indexOf(u)&&(s.hot._acceptedDependencies[o]?(r[u]||(r[u]=[]),g(r[u],[o])):(delete r[u],t.push(u),n.push({chain:a.concat([u]),id:u})))}}}}return{type:"accepted",moduleId:e,outdatedModules:t,outdatedDependencies:r}}function g(e,t){for(var r=0;r<t.length;r++){var n=t[r];-1===e.indexOf(n)&&e.push(n)}}x();var m={},w=[],b={},O=function(){console.warn("[HMR] unexpected require("+E.moduleId+") to disposed module")};for(var P in p)if(Object.prototype.hasOwnProperty.call(p,P)){var E;f=k(P),E=p[P]?h(f):{type:"disposed",moduleId:P};var A=!1,M=!1,I=!1,D="";switch(E.chain&&(D="\nUpdate propagation: "+E.chain.join(" -> ")),E.type){case"self-declined":n.onDeclined&&n.onDeclined(E),n.ignoreDeclined||(A=new Error("Aborted because of self decline: "+E.moduleId+D));break;case"declined":n.onDeclined&&n.onDeclined(E),n.ignoreDeclined||(A=new Error("Aborted because of declined dependency: "+E.moduleId+" in "+E.parentId+D));break;case"unaccepted":n.onUnaccepted&&n.onUnaccepted(E),n.ignoreUnaccepted||(A=new Error("Aborted because "+f+" is not accepted"+D));break;case"accepted":n.onAccepted&&n.onAccepted(E),M=!0;break;case"disposed":n.onDisposed&&n.onDisposed(E),I=!0;break;default:throw new Error("Unexception type "+E.type)}if(A)return d("abort"),Promise.reject(A);if(M)for(f in b[f]=p[f],g(w,E.outdatedModules),E.outdatedDependencies)Object.prototype.hasOwnProperty.call(E.outdatedDependencies,f)&&(m[f]||(m[f]=[]),g(m[f],E.outdatedDependencies[f]));I&&(g(w,[E.moduleId]),b[f]=O)}var T,j=[];for(u=0;u<w.length;u++)f=w[u],S[f]&&S[f].hot._selfAccepted&&b[f]!==O&&!S[f].hot._selfInvalidated&&j.push({module:f,parents:S[f].parents.slice(),errorHandler:S[f].hot._selfAccepted});d("dispose"),Object.keys(_).forEach((function(e){!1===_[e]&&function(e){delete installedChunks[e]}(e)}));var C,F,L=w.slice();for(;L.length>0;)if(f=L.pop(),l=S[f]){var B={},H=l.hot._disposeHandlers;for(s=0;s<H.length;s++)(c=H[s])(B);for(o[f]=B,l.hot.active=!1,delete S[f],delete m[f],s=0;s<l.children.length;s++){var U=S[l.children[s]];U&&((T=U.parents.indexOf(f))>=0&&U.parents.splice(T,1))}}for(f in m)if(Object.prototype.hasOwnProperty.call(m,f)&&(l=S[f]))for(F=m[f],s=0;s<F.length;s++)C=F[s],(T=l.children.indexOf(C))>=0&&l.children.splice(T,1);d("apply"),void 0!==y&&(i=y,y=void 0);for(f in p=void 0,b)Object.prototype.hasOwnProperty.call(b,f)&&(e[f]=b[f]);var G=null;for(f in m)if(Object.prototype.hasOwnProperty.call(m,f)&&(l=S[f])){F=m[f];var N=[];for(u=0;u<F.length;u++)if(C=F[u],c=l.hot._acceptedDependencies[C]){if(-1!==N.indexOf(c))continue;N.push(c)}for(u=0;u<N.length;u++){c=N[u];try{c(F)}catch(e){n.onErrored&&n.onErrored({type:"accept-errored",moduleId:f,dependencyId:F[u],error:e}),n.ignoreErrored||G||(G=e)}}}for(u=0;u<j.length;u++){var V=j[u];f=V.module,a=V.parents,r=f;try{R(f)}catch(e){if("function"==typeof V.errorHandler)try{V.errorHandler(e)}catch(t){n.onErrored&&n.onErrored({type:"self-accept-error-handler-errored",moduleId:f,error:t,originalError:e}),n.ignoreErrored||G||(G=t),G||(G=e)}else n.onErrored&&n.onErrored({type:"self-accept-errored",moduleId:f,error:e}),n.ignoreErrored||G||(G=e)}}if(G)return d("fail"),Promise.reject(G);if(v)return t(n).then((function(e){return w.forEach((function(t){e.indexOf(t)<0&&e.push(t)})),e}));return d("idle"),new Promise((function(e){e(w)}))}(t=t||{})}function x(){if(v)return p||(p={}),v.forEach(M),v=void 0,!0}function M(t){Object.prototype.hasOwnProperty.call(p,t)||(p[t]=e[t])}var S={};function R(t){if(S[t])return S[t].exports;var r=S[t]={i:t,l:!1,exports:{},hot:s(t),parents:(c=a,a=[],c),children:[]};return e[t].call(r.exports,r,r.exports,u(t)),r.l=!0,r.exports}R.m=e,R.c=S,R.d=function(e,t,r){R.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},R.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},R.t=function(e,t){if(1&t&&(e=R(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(R.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)R.d(r,n,function(t){return e[t]}.bind(null,n));return r},R.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return R.d(t,"a",t),t},R.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},R.p="/",R.h=function(){return i},u(0)(R.s=0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";r.r(t);function n(e){return function(e){if(Array.isArray(e))return i(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return i(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return i(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function o(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function a(e,t,r){return t&&o(e.prototype,t),r&&o(e,r),e}function c(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&v(e,t)}function f(e){var t=y();return function(){var r,n=g(e);if(t){var i=g(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return d(this,r)}}function d(e,t){return!t||"object"!==u(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function h(e){var t="function"==typeof Map?new Map:void 0;return(h=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return p(e,arguments,g(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),v(n,e)})(e)}function p(e,t,r){return(p=y()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&v(i,r.prototype),i}).apply(null,arguments)}function y(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function v(e,t){return(v=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function g(e){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var m,w=function(e){l(r,e);var t=f(r);function r(e){var n;return s(this,r),(n=t.call(this,e)).name="ShaderCompilationError",n}return r}(h(Error)),b=function(e){l(r,e);var t=f(r);function r(e){var n;return s(this,r),(n=t.call(this,e)).name="ProgramLinkingError",n}return r}(h(Error)),_=function(e){l(r,e);var t=f(r);function r(e,n){var i;return s(this,r),(i=t.call(this,"Expected vector of at least size "+e+", but got one of size "+n+"!")).name="VectorSizeError",i}return r}(h(Error));!function(e){e[e.ERROR=0]="ERROR",e[e.QUIT=1]="QUIT",e[e.CONTINUE=2]="CONTINUE",e[e.WEBGL_ERROR=3]="WEBGL_ERROR"}(m||(m={}));var k=function e(t,r,n){if(s(this,e),c(this,"rep",void 0),"number"==typeof t){if("number"!=typeof r||"number"!=typeof n)throw new TypeError("Incorrect constructor call for Point3D");this.rep=new Float32Array(3),this.rep[0]=t,this.rep[1]=r,this.rep[2]=n}else this.rep=new Float32Array(t[2])},O=function(e){l(r,e);var t=f(r);function r(e,i){var o;if(s(this,r),"number"==typeof e)o=t.call(this,e,i,0);else{if(2!==e.length)throw new _(2,e.length);o=t.call(this,[].concat(n(e),[0]))}return d(o)}return a(r,[{key:"xOrd",value:function(){return this.rep[0]}},{key:"yOrd",value:function(){return this.rep[1]}},{key:"setX",value:function(e){this.rep[0]=e}},{key:"setY",value:function(e){this.rep[1]=e}},{key:"vec",value:function(){return new Float32Array(n(this.rep))}}],[{key:"Zeros",value:function(){return new r(0,0)}}]),r}(k),P=function(){function e(t,r,n,i){s(this,e),c(this,"rep",void 0),this.rep=new Float32Array([t,r,n,null!=i?i:1])}return a(e,[{key:"red",value:function(){return this.rep[0]}},{key:"green",value:function(){return this.rep[1]}},{key:"blue",value:function(){return this.rep[2]}},{key:"alpha",value:function(){return this.rep[3]}},{key:"setRed",value:function(e){this.rep[0]=e}},{key:"setGreen",value:function(e){this.rep[1]=e}},{key:"setBlue",value:function(e){this.rep[2]=e}},{key:"setAlpha",value:function(e){this.rep[3]=e}},{key:"vec",value:function(){return this.rep}}],[{key:"fromVec",value:function(t){if(4===t.length)return new e(t[0],t[1],t[2],t[3]);if(3===t.length)return new e(t[0],t[1],t[2]);throw new _("3 to 4",t.length)}}]),e}(),E=function(){function e(){s(this,e),c(this,"matrix",void 0);for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];if(16!==r[0].length)throw new _(16,r[0].length);r[0]instanceof Float32Array||(r[0]=new Float32Array(r[0])),this.matrix=r[0]}return a(e,[{key:"times",value:function(t){var r=new e(Array(16)),n=this.matrix,i=t.matrix,o=r.matrix;return o[0]=n[0]*i[0]+n[1]*i[4]+n[2]*i[8]+n[3]*i[12],o[1]=n[0]*i[1]+n[1]*i[5]+n[2]*i[9]+n[3]*i[13],o[2]=n[0]*i[2]+n[1]*i[6]+n[2]*i[10]+n[3]*i[14],o[3]=n[0]*i[3]+n[1]*i[7]+n[2]*i[11]+n[3]*i[15],o[4]=n[4]*i[0]+n[5]*i[4]+n[6]*i[8]+n[7]*i[12],o[5]=n[4]*i[1]+n[5]*i[5]+n[6]*i[9]+n[7]*i[13],o[6]=n[4]*i[2]+n[5]*i[6]+n[6]*i[10]+n[7]*i[14],o[7]=n[4]*i[3]+n[5]*i[7]+n[6]*i[11]+n[7]*i[15],o[8]=n[8]*i[0]+n[9]*i[4]+n[10]*i[8]+n[11]*i[12],o[9]=n[8]*i[1]+n[9]*i[5]+n[10]*i[9]+n[11]*i[13],o[10]=n[8]*i[2]+n[9]*i[6]+n[10]*i[10]+n[11]*i[14],o[11]=n[8]*i[3]+n[9]*i[7]+n[10]*i[11]+n[11]*i[15],o[12]=n[12]*i[0]+n[13]*i[4]+n[14]*i[8]+n[15]*i[12],o[13]=n[12]*i[1]+n[13]*i[5]+n[14]*i[9]+n[15]*i[13],o[14]=n[12]*i[2]+n[13]*i[6]+n[14]*i[10]+n[15]*i[14],o[15]=n[12]*i[3]+n[13]*i[7]+n[14]*i[11]+n[15]*i[15],r}},{key:"buffer",value:function(){return this.matrix.slice()}},{key:"set",value:function(e,t,r){this.matrix[4*e+t]=r}},{key:"setRel",value:function(e,t,r){this.matrix[4*e+t]+=r}}],[{key:"Identity",value:function(){return new e((t=4,r=Array(t*t).fill(0),new Float32Array(r.map((function(e,t){return t%5==0?1:0})))));var t,r}}]),e}(),A=function(){function e(){s(this,e),c(this,"trs",E.Identity());for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];r[0]&&(r[0]instanceof e?this.trs=new E(r[0].buffer()):this.trs=r[0].times(r[1]).times(r[2]).times(r[3]).times(r[4]))}return a(e,[{key:"toMatrix4",value:function(){return this.trs}},{key:"buffer",value:function(){return this.trs.buffer()}},{key:"translateBy",value:function(e,t,r){return this.trs=this.trs.times(new E([1,0,0,0,0,1,0,0,0,0,1,0,e,t,r,1])),this}},{key:"rotateBy",value:function(e,t,r){var n=Math.sin(e),i=Math.cos(e),o=Math.sin(t),a=Math.cos(t),c=Math.sin(r),u=Math.cos(r);return this.trs=this.trs.times(new E([1,0,0,0,0,i,n,0,0,-n,i,0,0,0,0,1])).times(new E([a,0,-o,0,0,1,0,0,o,0,a,0,0,0,0,1])).times(new E([u,c,0,0,-c,u,0,0,0,0,1,0,0,0,0,1])),this}},{key:"scaleBy",value:function(e,t,r){return this.trs=this.trs.times(new E([e,0,0,0,0,t,0,0,0,0,r,0,0,0,0,1])),this}}]),e}(),x=function(){function e(){s(this,e),c(this,"geometryRep",void 0),c(this,"color",void 0),c(this,"trsMatrix",void 0);for(var t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];if(r[0]instanceof Float32Array){var o,a;if(6!==r[0].length&&8!==r[0].length)throw new _("6 or 9",r[0].length);6===r[0].length?this.geometryRep=new Float32Array([].concat(n(r[0].slice(0,2)),[0],n(r[0].slice(2,4)),[0],n(r[0].slice(4,6)),[0])):this.geometryRep=r[0],this.trsMatrix=null!==(o=r[1])&&void 0!==o?o:new A,this.color=null!==(a=r[2])&&void 0!==a?a:new P(0,0,0,1)}else{var u,l;this.geometryRep=new Float32Array([].concat(n(r[0].vec()),n(r[1].vec()),n(r[2].vec()))),this.trsMatrix=null!==(u=r[3])&&void 0!==u?u:new A,this.color=null!==(l=r[4])&&void 0!==l?l:new P(0,0,0,1)}}return a(e,[{key:"colorVec",value:function(){return this.color.vec()}},{key:"setColor",value:function(e){this.color=e}},{key:"getColor",value:function(){return this.color}},{key:"getTrsMatrix",value:function(){return this.trsMatrix}},{key:"mapPointTo",value:function(e,t){e instanceof O?(this.geometryRep[t]=e.xOrd(),this.geometryRep[t+1]=e.yOrd()):(this.geometryRep[t]=e[0],this.geometryRep[t+1]=e[1])}},{key:"updatePoints",value:function(e,t,r){e&&this.mapPointTo(e,0),t&&this.mapPointTo(t,3),r&&this.mapPointTo(r,6)}},{key:"updatePointsFromVec",value:function(e){if(6!==e.length)throw new _(6,e.length);this.geometryRep=e}},{key:"pointBuffer",value:function(){return this.geometryRep}},{key:"translateBy",value:function(e,t,r){return this.trsMatrix.translateBy(e,t,r),this}},{key:"rotateBy",value:function(e,t,r){return this.trsMatrix.rotateBy(e,t,r),this}},{key:"scaleBy",value:function(e,t,r){return this.trsMatrix.scaleBy(e,t,r),this}}]),e}(),M=function(){function e(t,r){var n,i,o,a,u,l;s(this,e),c(this,"gl",void 0),c(this,"stage",void 0),c(this,"perspMat",void 0),c(this,"currentProgram",void 0),c(this,"positionAttributeLocation",0),c(this,"u_colorLoc",0),c(this,"u_trsMatrixLoc",0),c(this,"onShutdownCallback",(function(){})),this.gl=t,this.stage=r,this.currentProgram=this.createDefaultProgram(),this.perspMat=(n=90,i=this.stage.width/this.stage.height,o=1,a=2e3,u=Math.tan(.5*Math.PI-.5*n),new E([u/i,0,0,0,0,u,0,0,0,0,(o+a)*(l=1/(o-a)),-1,0,0,o*a*l*2,0])),this.setupGl()}return a(e,[{key:"setupGl",value:function(){this.gl.enable(this.gl.DEPTH_TEST),this.gl.enable(this.gl.CULL_FACE)}},{key:"onShutdown",value:function(e){this.onShutdownCallback=e}},{key:"shutdown",value:function(e){this.onShutdownCallback(e)}},{key:"createDefaultProgram",value:function(){var e=this.createProgram(this.createShaderFromString(this.gl.VERTEX_SHADER,"attribute vec4 a_position;\n\nuniform mat4 u_trsMatrix;\n\nvoid main() {\n gl_Position = u_trsMatrix * a_position;\n}"),this.createShaderFromString(this.gl.FRAGMENT_SHADER,"precision mediump float;\n\nuniform vec4 u_color;\n\nvoid main() {\n gl_FragColor = u_color;\n}"));return this.positionAttributeLocation=this.gl.getAttribLocation(e,"a_position"),this.u_colorLoc=this.gl.getUniformLocation(e,"u_color"),this.u_trsMatrixLoc=this.gl.getUniformLocation(e,"u_trsMatrix"),e}},{key:"createProgram",value:function(e,t){var r,n=this.gl.createProgram();if(this.gl.attachShader(n,e),this.gl.attachShader(n,t),this.gl.linkProgram(n),this.gl.getProgramParameter(n,this.gl.LINK_STATUS))return n;throw this.gl.deleteProgram(n),new b(null!==(r=this.gl.getProgramInfoLog(n))&&void 0!==r?r:"")}},{key:"createShaderFromString",value:function(e,t){var r=this.gl.createShader(e);if(this.gl.shaderSource(r,t),this.gl.compileShader(r),this.gl.getShaderParameter(r,this.gl.COMPILE_STATUS))return r;var n,i=null===(n=this.gl.getShaderInfoLog(r))||void 0===n?void 0:n.toString();throw this.gl.deleteShader(r),new w(null!=i?i:"")}},{key:"renderTriangle",value:function(e){this.gl.bufferData(this.gl.ARRAY_BUFFER,e.pointBuffer(),this.gl.STATIC_DRAW),this.gl.uniform4fv(this.u_colorLoc,e.colorVec()),this.gl.uniformMatrix4fv(this.u_trsMatrixLoc,!1,this.perspMat.times(e.getTrsMatrix().toMatrix4()).buffer()),this.gl.drawArrays(this.gl.TRIANGLES,0,3)}},{key:"initViewport",value:function(){this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT|this.gl.DEPTH_BUFFER_BIT)}},{key:"useDefaultProgram",value:function(){this.gl.useProgram(this.currentProgram);var e=this.gl.createBuffer();this.gl.bindBuffer(this.gl.ARRAY_BUFFER,e),this.gl.enableVertexAttribArray(this.positionAttributeLocation),this.gl.vertexAttribPointer(this.positionAttributeLocation,3,this.gl.FLOAT,!1,0,0)}},{key:"createRandomTriangle",value:function(){return new x(this.rand2DClipspacePoint(),this.rand2DClipspacePoint(),this.rand2DClipspacePoint(),this.randTrsMat(),this.randBasicColor())}},{key:"randTrsMat",value:function(){return(new A).translateBy(this.randClipspaceInt(),this.randClipspaceInt(),this.randClipspaceInt()).rotateBy(this.randAngle(),this.randAngle(),this.randAngle()).scaleBy(2*Math.random(),2*Math.random(),2*Math.random())}},{key:"rand2DClipspacePoint",value:function(){return new O(this.randClipspaceInt(),this.randClipspaceInt())}},{key:"randBasicColor",value:function(){return new P(Math.random(),Math.random(),Math.random())}},{key:"randAngle",value:function(){return 2*Math.random()*Math.PI}},{key:"randClipspaceInt",value:function(){return 2*Math.random()-1}},{key:"start",value:function(){this.initViewport(),this.useDefaultProgram();for(var e=0;e<200;e++){var t=this.createRandomTriangle();this.renderTriangle(t)}}}]),e}();function S(e,t){var r=document.createElement("div");r.id=e.id,r.innerText=t,e.replaceWith(r)}window.onload=function(){var e=function(e,t){var r=document.querySelector("#root"),n=document.createElement("canvas");return n.id="main-stage",n.width=e,n.height=t,r.appendChild(n),n}(640,480),t=e.getContext("webgl");if(t){var r=new M(t,e);r.onShutdown((function(t){return function(e,t){t===m.QUIT?S(e,"We're done here."):t===m.ERROR&&S(e,"Something unexpected happened and forced the program to shut down.")}(e,t)})),r.start()}else S(e,"Unable to initialize WebGL. Your browser or machine may not support it.")}}]); |