1 line
36 KiB
JavaScript
1 line
36 KiB
JavaScript
!function(e){var t=window.webpackHotUpdate;window.webpackHotUpdate=function(e,n){!function(e,t){if(!_[e]||!w[e])return;for(var n in w[e]=!1,t)Object.prototype.hasOwnProperty.call(t,n)&&(d[n]=t[n]);0==--g&&0===m&&S()}(e,n),t&&t(e,n)};var n,r=!0,o="96d6984be2e376a14bf8",i={},a=[],u=[];function c(e){var t=j[e];if(!t)return B;var r=function(r){return t.hot.active?(j[r]?-1===j[r].parents.indexOf(e)&&j[r].parents.push(e):(a=[e],n=r),-1===t.children.indexOf(r)&&t.children.push(r)):(console.warn("[HMR] unexpected require("+r+") from disposed module "+e),a=[]),B(r)},o=function(e){return{configurable:!0,enumerable:!0,get:function(){return B[e]},set:function(t){B[e]=t}}};for(var i in B)Object.prototype.hasOwnProperty.call(B,i)&&"e"!==i&&"t"!==i&&Object.defineProperty(r,i,o(i));return r.e=function(e){return"ready"===f&&h("prepare"),m++,B.e(e).then(t,(function(e){throw t(),e}));function t(){m--,"prepare"===f&&(b[e]||E(e),0===m&&0===g&&S())}},r.t=function(e,t){return 1&t&&(e=r(e)),B.t(e,-2&t)},r}function l(t){var r={_acceptedDependencies:{},_declinedDependencies:{},_selfAccepted:!1,_selfDeclined:!1,_selfInvalidated:!1,_disposeHandlers:[],_main:n!==t,active:!0,accept:function(e,t){if(void 0===e)r._selfAccepted=!0;else if("function"==typeof e)r._selfAccepted=e;else if("object"==typeof e)for(var n=0;n<e.length;n++)r._acceptedDependencies[e[n]]=t||function(){};else r._acceptedDependencies[e]=t||function(){}},decline:function(e){if(void 0===e)r._selfDeclined=!0;else if("object"==typeof e)for(var t=0;t<e.length;t++)r._declinedDependencies[e[t]]=!0;else r._declinedDependencies[e]=!0},dispose:function(e){r._disposeHandlers.push(e)},addDisposeHandler:function(e){r._disposeHandlers.push(e)},removeDisposeHandler:function(e){var t=r._disposeHandlers.indexOf(e);t>=0&&r._disposeHandlers.splice(t,1)},invalidate:function(){switch(this._selfInvalidated=!0,f){case"idle":(d={})[t]=e[t],h("ready");break;case"ready":A(t);break;case"prepare":case"check":case"dispose":case"apply":(v=v||[]).push(t)}},check:k,apply:P,status:function(e){if(!e)return f;s.push(e)},addStatusHandler:function(e){s.push(e)},removeStatusHandler:function(e){var t=s.indexOf(e);t>=0&&s.splice(t,1)},data:i[t]};return n=void 0,r}var s=[],f="idle";function h(e){f=e;for(var t=0;t<s.length;t++)s[t].call(null,e)}var p,d,y,v,g=0,m=0,b={},w={},_={};function O(e){return+e+""===e?+e:e}function k(e){if("idle"!==f)throw new Error("check() is only allowed in idle status");return r=e,h("check"),(t=1e4,t=t||1e4,new Promise((function(e,n){if("undefined"==typeof XMLHttpRequest)return n(new Error("No browser support"));try{var r=new XMLHttpRequest,i=B.p+""+o+".hot-update.json";r.open("GET",i,!0),r.timeout=t,r.send(null)}catch(e){return n(e)}r.onreadystatechange=function(){if(4===r.readyState)if(0===r.status)n(new Error("Manifest request to "+i+" timed out."));else if(404===r.status)e();else if(200!==r.status&&304!==r.status)n(new Error("Manifest request to "+i+" failed."));else{try{var t=JSON.parse(r.responseText)}catch(e){return void n(e)}e(t)}}}))).then((function(e){if(!e)return h(x()?"ready":"idle"),null;w={},b={},_=e.c,y=e.h,h("prepare");var t=new Promise((function(e,t){p={resolve:e,reject:t}}));d={};return E(0),"prepare"===f&&0===m&&0===g&&S(),t}));var t}function E(e){_[e]?(w[e]=!0,g++,function(e){var t=document.createElement("script");t.charset="utf-8",t.src=B.p+""+e+"."+o+".hot-update.js",document.head.appendChild(t)}(e)):b[e]=!0}function S(){h("ready");var e=p;if(p=null,e)if(r)Promise.resolve().then((function(){return P(r)})).then((function(t){e.resolve(t)}),(function(t){e.reject(t)}));else{var t=[];for(var n in d)Object.prototype.hasOwnProperty.call(d,n)&&t.push(O(n));e.resolve(t)}}function P(t){if("ready"!==f)throw new Error("apply() is only allowed in ready status");return function t(r){var u,c,l,s,f;function p(e){for(var t=[e],n={},r=t.map((function(e){return{chain:[e],id:e}}));r.length>0;){var o=r.pop(),i=o.id,a=o.chain;if((s=j[i])&&(!s.hot._selfAccepted||s.hot._selfInvalidated)){if(s.hot._selfDeclined)return{type:"self-declined",chain:a,moduleId:i};if(s.hot._main)return{type:"unaccepted",chain:a,moduleId:i};for(var u=0;u<s.parents.length;u++){var c=s.parents[u],l=j[c];if(l){if(l.hot._declinedDependencies[i])return{type:"declined",chain:a.concat([c]),moduleId:i,parentId:c};-1===t.indexOf(c)&&(l.hot._acceptedDependencies[i]?(n[c]||(n[c]=[]),g(n[c],[i])):(delete n[c],t.push(c),r.push({chain:a.concat([c]),id:c})))}}}}return{type:"accepted",moduleId:e,outdatedModules:t,outdatedDependencies:n}}function g(e,t){for(var n=0;n<t.length;n++){var r=t[n];-1===e.indexOf(r)&&e.push(r)}}x();var m={},b=[],w={},k=function(){console.warn("[HMR] unexpected require("+S.moduleId+") to disposed module")};for(var E in d)if(Object.prototype.hasOwnProperty.call(d,E)){var S;f=O(E),S=d[E]?p(f):{type:"disposed",moduleId:E};var P=!1,A=!1,R=!1,T="";switch(S.chain&&(T="\nUpdate propagation: "+S.chain.join(" -> ")),S.type){case"self-declined":r.onDeclined&&r.onDeclined(S),r.ignoreDeclined||(P=new Error("Aborted because of self decline: "+S.moduleId+T));break;case"declined":r.onDeclined&&r.onDeclined(S),r.ignoreDeclined||(P=new Error("Aborted because of declined dependency: "+S.moduleId+" in "+S.parentId+T));break;case"unaccepted":r.onUnaccepted&&r.onUnaccepted(S),r.ignoreUnaccepted||(P=new Error("Aborted because "+f+" is not accepted"+T));break;case"accepted":r.onAccepted&&r.onAccepted(S),A=!0;break;case"disposed":r.onDisposed&&r.onDisposed(S),R=!0;break;default:throw new Error("Unexception type "+S.type)}if(P)return h("abort"),Promise.reject(P);if(A)for(f in w[f]=d[f],g(b,S.outdatedModules),S.outdatedDependencies)Object.prototype.hasOwnProperty.call(S.outdatedDependencies,f)&&(m[f]||(m[f]=[]),g(m[f],S.outdatedDependencies[f]));R&&(g(b,[S.moduleId]),w[f]=k)}var D,M=[];for(c=0;c<b.length;c++)f=b[c],j[f]&&j[f].hot._selfAccepted&&w[f]!==k&&!j[f].hot._selfInvalidated&&M.push({module:f,parents:j[f].parents.slice(),errorHandler:j[f].hot._selfAccepted});h("dispose"),Object.keys(_).forEach((function(e){!1===_[e]&&function(e){delete installedChunks[e]}(e)}));var I,C,F=b.slice();for(;F.length>0;)if(f=F.pop(),s=j[f]){var U={},L=s.hot._disposeHandlers;for(l=0;l<L.length;l++)(u=L[l])(U);for(i[f]=U,s.hot.active=!1,delete j[f],delete m[f],l=0;l<s.children.length;l++){var H=j[s.children[l]];H&&((D=H.parents.indexOf(f))>=0&&H.parents.splice(D,1))}}for(f in m)if(Object.prototype.hasOwnProperty.call(m,f)&&(s=j[f]))for(C=m[f],l=0;l<C.length;l++)I=C[l],(D=s.children.indexOf(I))>=0&&s.children.splice(D,1);h("apply"),void 0!==y&&(o=y,y=void 0);for(f in d=void 0,w)Object.prototype.hasOwnProperty.call(w,f)&&(e[f]=w[f]);var z=null;for(f in m)if(Object.prototype.hasOwnProperty.call(m,f)&&(s=j[f])){C=m[f];var G=[];for(c=0;c<C.length;c++)if(I=C[c],u=s.hot._acceptedDependencies[I]){if(-1!==G.indexOf(u))continue;G.push(u)}for(c=0;c<G.length;c++){u=G[c];try{u(C)}catch(e){r.onErrored&&r.onErrored({type:"accept-errored",moduleId:f,dependencyId:C[c],error:e}),r.ignoreErrored||z||(z=e)}}}for(c=0;c<M.length;c++){var N=M[c];f=N.module,a=N.parents,n=f;try{B(f)}catch(e){if("function"==typeof N.errorHandler)try{N.errorHandler(e)}catch(t){r.onErrored&&r.onErrored({type:"self-accept-error-handler-errored",moduleId:f,error:t,originalError:e}),r.ignoreErrored||z||(z=t),z||(z=e)}else r.onErrored&&r.onErrored({type:"self-accept-errored",moduleId:f,error:e}),r.ignoreErrored||z||(z=e)}}if(z)return h("fail"),Promise.reject(z);if(v)return t(r).then((function(e){return b.forEach((function(t){e.indexOf(t)<0&&e.push(t)})),e}));return h("idle"),new Promise((function(e){e(b)}))}(t=t||{})}function x(){if(v)return d||(d={}),v.forEach(A),v=void 0,!0}function A(t){Object.prototype.hasOwnProperty.call(d,t)||(d[t]=e[t])}var j={};function B(t){if(j[t])return j[t].exports;var n=j[t]={i:t,l:!1,exports:{},hot:l(t),parents:(u=a,a=[],u),children:[]};return e[t].call(n.exports,n,n.exports,c(t)),n.l=!0,n.exports}B.m=e,B.c=j,B.d=function(e,t,n){B.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},B.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},B.t=function(e,t){if(1&t&&(e=B(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(B.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)B.d(n,r,function(t){return e[t]}.bind(null,r));return n},B.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return B.d(t,"a",t),t},B.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},B.p="/",B.h=function(){return o},c(0)(B.s=0)}([function(e,t,n){e.exports=n(1)},function(e,t,n){"use strict";n.r(t);var r=function e(t,n,r){var o,i,a;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),a=void 0,(i="rep")in(o=this)?Object.defineProperty(o,i,{value:a,enumerable:!0,configurable:!0,writable:!0}):o[i]=a,"number"==typeof t){if("number"!=typeof n||"number"!=typeof r)throw new TypeError("Incorrect constructor call for PointVec");this.rep=new Float32Array(3),this.rep[0]=t,this.rep[1]=n,this.rep[2]=r}else this.rep=new Float32Array(t[2])};function o(e){return(o="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 i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t){return(a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e){var t=function(){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}}();return function(){var n,r=s(e);if(t){var o=s(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return c(this,n)}}function c(e,t){return!t||"object"!==o(t)&&"function"!=typeof t?l(e):t}function l(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var h=function(e){!function(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&&a(e,t)}(c,e);var t,n,r,o=u(c);function c(e,t,n){var r;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,c),f(l(r=o.call(this,e,t,n)),"len",void 0),f(l(r),"lengthCacheDirty",!0),r.len=0,r}return t=c,r=[{key:"Zeros",value:function(){return new c(0,0,0)}}],(n=[{key:"x",value:function(){return this.rep[0]}},{key:"y",value:function(){return this.rep[1]}},{key:"z",value:function(){return this.rep[2]}},{key:"setX",value:function(e){this.rep[0]=e,this.lengthCacheDirty=!1}},{key:"setY",value:function(e){this.rep[1]=e,this.lengthCacheDirty=!1}},{key:"setZ",value:function(e){this.rep[2]=e,this.lengthCacheDirty=!1}},{key:"set",value:function(e){this.setX(e.x()),this.setY(e.y()),this.setZ(e.z())}},{key:"vec",value:function(){return this.rep.slice()}},{key:"cross",value:function(e){return new c(this.y()*e.z()-this.z()*e.y(),this.z()*e.x()-this.x()*e.z(),this.x()*e.y()-this.y()*e.x())}},{key:"dot",value:function(e){return this.x()*e.x()+this.y()*e.y()+this.z()*e.z()}},{key:"minus",value:function(e){return new c(this.x()-e.x(),this.y()-e.y(),this.z()-e.z())}},{key:"plus",value:function(e){return new c(this.x()+e.x(),this.y()+e.y(),this.z()+e.z())}},{key:"normalised",value:function(){var e=this.length();return e>1e-5?this.scaled(1/e):c.Zeros()}},{key:"scaled",value:function(e){return new c(this.x()*e,this.y()*e,this.z()*e)}},{key:"length",value:function(){return this.lengthCacheDirty&&(this.len=Math.sqrt(this.dot(this)),this.lengthCacheDirty=!1),this.len}}])&&i(t.prototype,n),r&&i(t,r),c}(r);function p(e){return(p="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 d(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function y(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function v(e,t){return(v=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function g(e){var t=function(){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}}();return function(){var n,r=b(e);if(t){var o=b(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return m(this,n)}}function m(e,t){return!t||"object"!==p(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 b(e){return(b=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var w=function(e){!function(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)}(i,e);var t,n,r,o=g(i);function i(){var e;d(this,i),e=o.call(this);for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return n[0]&&(n[0]instanceof i?e.matrix=n[0].buffer():e.matrix=n[0].times(n[1]).times(n[2]).times(n[3]).times(n[4])),e}return t=i,(n=[{key:"position",value:function(){return new h(this.buffer(12,15))}},{key:"setPosition",value:function(e,t,n){e instanceof h?this.setSlice([e.x(),e.y(),e.z()],12):this.setSlice([e,null!=t?t:0,null!=n?n:0],12)}},{key:"translateBy",value:function(e,t,n){return this.matrix=this.times(new V([1,0,0,0,0,1,0,0,0,0,1,0,e,t,n,1])).buffer(),this}},{key:"rotateBy",value:function(e,t,n){var r=Math.sin(e),o=Math.cos(e),i=Math.sin(t),a=Math.cos(t),u=Math.sin(n),c=Math.cos(n);return this.matrix=this.times(new V([1,0,0,0,0,o,r,0,0,-r,o,0,0,0,0,1])).times(new V([a,0,-i,0,0,1,0,0,i,0,a,0,0,0,0,1])).times(new V([c,u,0,0,-u,c,0,0,0,0,1,0,0,0,0,1])).buffer(),this}},{key:"scaleBy",value:function(e,t,n){return void 0!==t&&void 0!==n||(t=e,n=e),this.matrix=this.times(new V([e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1])).buffer(),this}}])&&y(t.prototype,n),r&&y(t,r),i}(V);function _(e){return(_="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 O(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function k(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&&j(e,t)}function E(e){var t=A();return function(){var n,r=B(e);if(t){var o=B(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return S(this,n)}}function S(e,t){return!t||"object"!==_(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 P(e){var t="function"==typeof Map?new Map:void 0;return(P=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;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,r)}function r(){return x(e,arguments,B(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),j(r,e)})(e)}function x(e,t,n){return(x=A()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&j(o,n.prototype),o}).apply(null,arguments)}function A(){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 j(e,t){return(j=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function B(e){return(B=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var R=function(e){k(n,e);var t=E(n);function n(e){var r;return O(this,n),(r=t.call(this,e)).name="ShaderCompilationError",r}return n}(P(Error)),T=function(e){k(n,e);var t=E(n);function n(e){var r;return O(this,n),(r=t.call(this,e)).name="ProgramLinkingError",r}return n}(P(Error)),D=function(e){k(n,e);var t=E(n);function n(e,r){var o;return O(this,n),(o=t.call(this,"Expected vector of at least size "+e+", but got one of size "+r+"!")).name="VectorSizeError",o}return n}(P(Error));function M(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function I(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function C(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var F=function(){function e(){var t,n,r,o;M(this,e),C(this,"rep",void 0),this.rep=new Float32Array([null!==(t=arguments.length<=0?void 0:arguments[0])&&void 0!==t?t:.5,null!==(n=arguments.length<=1?void 0:arguments[1])&&void 0!==n?n:.5,null!==(r=arguments.length<=2?void 0:arguments[2])&&void 0!==r?r:.5,null!==(o=arguments.length<=3?void 0:arguments[3])&&void 0!==o?o:1])}var t,n,r;return t=e,r=[{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 D("3 to 4",t.length)}}],(n=[{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}}])&&I(t.prototype,n),r&&I(t,r),e}();function U(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function L(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var H=function(){function e(t,n){var r;if(function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),L(this,"geometry",void 0),L(this,"trsMatrix",void 0),t.elementBuffer)r=new Uint16Array(t.elementBuffer);else{if(t.pointBuffer.length%3!=0)throw new D("Multiple of 3 (no vertexOrder supplied)",t.pointBuffer.length);r=new Uint16Array(Array(t.pointBuffer.length/3).keys())}this.geometry={pointBuffer:t.pointBuffer,normalBuffer:t.normalBuffer,elementBuffer:r},this.trsMatrix=null!=n?n:new w}var t,n,r;return t=e,(n=[{key:"getTrsMatrix",value:function(){return this.trsMatrix}},{key:"pointBuffer",value:function(){return this.geometry.pointBuffer}},{key:"normalBuffer",value:function(){return this.geometry.normalBuffer}},{key:"elementBuffer",value:function(){return this.geometry.elementBuffer}},{key:"position",value:function(){return this.trsMatrix.position()}},{key:"translateBy",value:function(e,t,n){return this.trsMatrix.translateBy(e,t,n),this}},{key:"rotateBy",value:function(e,t,n){return this.trsMatrix.rotateBy(e,t,n),this}},{key:"scaleBy",value:function(e,t,n){return t&&n?this.trsMatrix.scaleBy(e,t,n):this.trsMatrix.scaleBy(e),this}}])&&U(t.prototype,n),r&&U(t,r),e}();function z(e){var t=Array(e*e).fill(0);return new Float32Array(t.map((function(e,t){return t%5==0?1:0})))}function G(e,t,n){return t.minus(e).cross(n.minus(e))}function N(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function q(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function W(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var V=function(){function e(){N(this,e),W(this,"matrix",void 0);for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];if(n[0]){if(16!==n[0].length)throw new D(16,n[0].length);n[0]instanceof Float32Array||(n[0]=new Float32Array(n[0])),this.matrix=n[0]}else this.matrix=z(4)}var t,n,r;return t=e,r=[{key:"Perspective",value:function(t,n,r,o){var i=Math.tan(Math.PI/2-t/2),a=1/(r-o);return new e(new Float32Array([i/n,0,0,0,0,i,0,0,0,0,(r+o)*a,-1,0,0,r*o*a*2,0]))}},{key:"Identity",value:function(){return new e(z(4))}}],(n=[{key:"times",value:function(t){var n=new e(Array(16)),r=this.matrix,o=t.matrix,i=n.matrix;return i[0]=r[0]*o[0]+r[1]*o[4]+r[2]*o[8]+r[3]*o[12],i[1]=r[0]*o[1]+r[1]*o[5]+r[2]*o[9]+r[3]*o[13],i[2]=r[0]*o[2]+r[1]*o[6]+r[2]*o[10]+r[3]*o[14],i[3]=r[0]*o[3]+r[1]*o[7]+r[2]*o[11]+r[3]*o[15],i[4]=r[4]*o[0]+r[5]*o[4]+r[6]*o[8]+r[7]*o[12],i[5]=r[4]*o[1]+r[5]*o[5]+r[6]*o[9]+r[7]*o[13],i[6]=r[4]*o[2]+r[5]*o[6]+r[6]*o[10]+r[7]*o[14],i[7]=r[4]*o[3]+r[5]*o[7]+r[6]*o[11]+r[7]*o[15],i[8]=r[8]*o[0]+r[9]*o[4]+r[10]*o[8]+r[11]*o[12],i[9]=r[8]*o[1]+r[9]*o[5]+r[10]*o[9]+r[11]*o[13],i[10]=r[8]*o[2]+r[9]*o[6]+r[10]*o[10]+r[11]*o[14],i[11]=r[8]*o[3]+r[9]*o[7]+r[10]*o[11]+r[11]*o[15],i[12]=r[12]*o[0]+r[13]*o[4]+r[14]*o[8]+r[15]*o[12],i[13]=r[12]*o[1]+r[13]*o[5]+r[14]*o[9]+r[15]*o[13],i[14]=r[12]*o[2]+r[13]*o[6]+r[14]*o[10]+r[15]*o[14],i[15]=r[12]*o[3]+r[13]*o[7]+r[14]*o[11]+r[15]*o[15],n}},{key:"buffer",value:function(e,t){return this.matrix.slice(e,t)}},{key:"set",value:function(e,t,n){this.matrix[4*e+t]=n}},{key:"setSlice",value:function(e,t){this.matrix.set(e,t)}},{key:"setRel",value:function(e,t,n){this.matrix[4*e+t]+=n}},{key:"inverse",value:function(){var t=this.matrix,n=t[0],r=t[1],o=t[2],i=t[3],a=t[4],u=t[5],c=t[6],l=t[7],s=t[8],f=t[9],h=t[10],p=t[11],d=t[12],y=t[13],v=t[14],g=t[15],m=h*g,b=v*p,w=c*g,_=v*l,O=c*p,k=h*l,E=o*g,S=v*i,P=o*p,x=h*i,A=o*l,j=c*i,B=s*y,R=d*f,T=a*y,D=d*u,M=a*f,I=s*u,C=n*y,F=d*r,U=n*f,L=s*r,H=n*u,z=a*r,G=m*u+_*f+O*y-(b*u+w*f+k*y),N=b*r+E*f+x*y-(m*r+S*f+P*y),q=w*r+S*u+A*y-(_*r+E*u+j*y),W=k*r+P*u+j*f-(O*r+x*u+A*f),V=1/(n*G+a*N+s*q+d*W);return new e([V*G,V*N,V*q,V*W,V*(b*a+w*s+k*d-(m*a+_*s+O*d)),V*(m*n+S*s+P*d-(b*n+E*s+x*d)),V*(_*n+E*a+j*d-(w*n+S*a+A*d)),V*(O*n+x*a+A*s-(k*n+P*a+j*s)),V*(B*l+D*p+M*g-(R*l+T*p+I*g)),V*(R*i+C*p+L*g-(B*i+F*p+U*g)),V*(T*i+F*l+H*g-(D*i+C*l+z*g)),V*(I*i+U*l+z*p-(M*i+L*l+H*p)),V*(T*h+I*v+R*c-(M*v+B*c+D*h)),V*(U*v+B*o+F*h-(C*h+L*v+R*o)),V*(C*c+z*v+D*o-(H*v+T*o+F*c)),V*(H*h+M*o+L*c-(U*c+z*h+I*o))])}}])&&q(t.prototype,n),r&&q(t,r),e}();function Y(e){return(Y="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 X(e){return function(e){if(Array.isArray(e))return Z(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 Z(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Z(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 Z(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function Q(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function $(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function J(e,t){return(J=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function K(e){var t=function(){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}}();return function(){var n,r=ne(e);if(t){var o=ne(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return ee(this,n)}}function ee(e,t){return!t||"object"!==Y(t)&&"function"!=typeof t?te(e):t}function te(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function ne(e){return(ne=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function re(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var oe=function(e){!function(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&&J(e,t)}(i,e);var t,n,r,o=K(i);function i(){var e,t,n,r,a;(Q(this,i),"number"!=typeof(arguments.length<=0?void 0:arguments[0]))?(re(te(e=o.call(this,arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1])),"color",void 0),re(te(e),"height",void 0),re(te(e),"basePoints",void 0),t=arguments.length<=2?void 0:arguments[2]):(re(te(e=o.call(this,i.generateGeometry(arguments.length<=0?void 0:arguments[0],arguments.length<=1?void 0:arguments[1]),arguments.length<=2?void 0:arguments[2])),"color",void 0),re(te(e),"height",void 0),re(te(e),"basePoints",void 0),e.height=null!==(n=arguments.length<=0?void 0:arguments[0])&&void 0!==n?n:i.DEFAULT_HEIGHT,e.basePoints=null!==(r=arguments.length<=1?void 0:arguments[1])&&void 0!==r?r:i.DEFAULT_BASE_POINTS,t=null!==(a=arguments.length<=4?void 0:arguments[4])&&void 0!==a?a:new F);return t.hasOwnProperty("length")?e.color=F.fromVec(t):e.color=t,ee(e)}return t=i,r=[{key:"generateGeometry",value:function(e,t){t=Math.abs(Math.ceil(t));for(var n=2*Math.PI/t,r=[0,0,0,0,0,e,0,1,0],o=[],i=[],a=1;a<t;a++)r.push(Math.sin(n*a),Math.cos(n*a),0),i.push(0,2+a,1+a),o.push(0,0,-1,0,0,-1,0,0,-1),i.push(1,1+a,2+a),o.push.apply(o,X(G(new h(r.slice(1,3)),new h(r.slice(1+a,4+a)),new h(r.slice(2+a,5+a))).vec()));return i.push(0,2,1+t),i.push(1,1+t,2),{pointBuffer:new Float32Array(r),normalBuffer:new Float32Array(o),elementBuffer:new Uint16Array(i)}}}],(n=[{key:"update",value:function(e){var t=e/1e3;this.rotateBy(0,.05*t,0)}},{key:"setHeight",value:function(e){var t;this.changeHeight(e-(null!==(t=this.height)&&void 0!==t?t:0))}},{key:"changeHeight",value:function(e){var t,n;this.height=null!==(t=this.height)&&void 0!==t?t:i.DEFAULT_HEIGHT+e,this.geometry=i.generateGeometry(this.height,null!==(n=this.basePoints)&&void 0!==n?n:i.DEFAULT_BASE_POINTS)}},{key:"setBasePoints",value:function(e){var t;this.height=e,this.geometry=i.generateGeometry(this.height,null!==(t=this.basePoints)&&void 0!==t?t:i.DEFAULT_BASE_POINTS)}},{key:"setColor",value:function(e){this.color=e}},{key:"getColor",value:function(){return this.color}}])&&$(t.prototype,n),r&&$(t,r),i}(H);re(oe,"DEFAULT_BASE_POINTS",10),re(oe,"DEFAULT_HEIGHT",1);var ie=oe;function ae(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ue(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function ce(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var le,se=function(){function e(){ae(this,e),ce(this,"trs",void 0),this.trs=new w,void 0!==(arguments.length<=0?void 0:arguments[0])&&((arguments.length<=0?void 0:arguments[0])instanceof h?(this.trs.setPosition(arguments.length<=0?void 0:arguments[0]),this.lookAt(arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2])):(this.rotateBy(arguments.length<=1?void 0:arguments[1],arguments.length<=2?void 0:arguments[2],arguments.length<=3?void 0:arguments[3]),this.translateBy(0,0,arguments.length<=0?void 0:arguments[0])))}var t,n,r;return t=e,(n=[{key:"translateBy",value:function(e,t,n){return this.trs.translateBy(e,t,n),this}},{key:"rotateBy",value:function(e,t,n){return this.trs.rotateBy(e,t,n),this}},{key:"scaleBy",value:function(e,t,n){return this.trs.scaleBy(e,t,n),this}},{key:"getTrsMatrix",value:function(){return this.trs}},{key:"position",value:function(){return this.trs.position()}},{key:"lookAt",value:function(e,t){var n=this.position(),r=n.minus(e).normalised(),o=t.cross(r).normalised(),i=r.cross(o).normalised();this.trs.setSlice([o.x(),o.y(),o.z(),0,i.x(),i.y(),i.z(),0,r.x(),r.y(),r.z(),0,n.x(),n.y(),n.z(),0],0)}},{key:"viewMat",value:function(){return this.trs.inverse()}}])&&ue(t.prototype,n),r&&ue(t,r),e}();function fe(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return he(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return he(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,u=!1;return{s:function(){n=e[Symbol.iterator]()},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw i}}}}function he(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function pe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function de(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}!function(e){e[e.ERROR=0]="ERROR",e[e.QUIT=1]="QUIT",e[e.CONTINUE=2]="CONTINUE",e[e.WEBGL_ERROR=3]="WEBGL_ERROR"}(le||(le={}));var ye=function(){function e(t,n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),de(this,"gl",void 0),de(this,"stage",void 0),de(this,"normalBuffer",void 0),de(this,"pointBuffer",void 0),de(this,"elementBuffer",void 0),de(this,"currentProgram",void 0),de(this,"a_position",0),de(this,"a_normal",0),de(this,"u_colorLoc",0),de(this,"u_trsMatrixLoc",0),de(this,"objects",[]),de(this,"camera",new se),de(this,"running",!0),de(this,"onShutdownCallback",(function(){})),this.gl=t,this.stage=n,this.currentProgram=this.createDefaultProgram(),this.setupGl()}var t,n,r;return t=e,(n=[{key:"setupGl",value:function(){this.gl.enable(this.gl.DEPTH_TEST),this.gl.enable(this.gl.CULL_FACE),this.gl.frontFace(this.gl.CW)}},{key:"onShutdown",value:function(e){this.onShutdownCallback=e}},{key:"shutdown",value:function(e){this.running=!1,this.onShutdownCallback(e)}},{key:"createDefaultProgram",value:function(){var e=this.createProgram(this.createShaderFromString(this.gl.VERTEX_SHADER,"attribute vec4 a_position;\nattribute vec4 a_normal;\nuniform mat4 u_trsMatrix;\n\nvarying vec3 v_light;\nvarying float v_depth;\nvarying vec3 v_normal;\n\nvoid main() {\n v_light = vec3(0.0, 0.0, 1.0);\n v_normal = (u_trsMatrix * a_normal).xyz;\n vec4 pos = u_trsMatrix * a_position;\n v_depth = pos.z;\n gl_Position = pos;\n}"),this.createShaderFromString(this.gl.FRAGMENT_SHADER,"precision mediump float;\n\nuniform vec4 u_color;\nvarying float v_depth;\nvarying vec3 v_light;\nvarying vec3 v_normal;\n\nvoid main() {\n vec3 normal = normalize(v_normal);\n float light = dot(normal, v_light);\n gl_FragColor = u_color;\n gl_FragColor.rgb *= light;\n}"));return this.a_position=this.gl.getAttribLocation(e,"a_position"),this.a_normal=this.gl.getAttribLocation(e,"a_normal"),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 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;var r=this.gl.getProgramInfoLog(n);throw this.gl.deleteProgram(n),new T(null!=r?r:"")}},{key:"createShaderFromString",value:function(e,t){var n=this.gl.createShader(e);if(this.gl.shaderSource(n,t),this.gl.compileShader(n),this.gl.getShaderParameter(n,this.gl.COMPILE_STATUS))return n;var r,o=null===(r=this.gl.getShaderInfoLog(n))||void 0===r?void 0:r.toString();throw this.gl.deleteShader(n),new R(null!=o?o:"")}},{key:"renderObject",value:function(e){this.gl.enableVertexAttribArray(this.a_position),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.pointBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,e.pointBuffer(),this.gl.STATIC_DRAW),this.gl.vertexAttribPointer(this.a_position,3,this.gl.FLOAT,!1,0,0),this.gl.enableVertexAttribArray(this.a_normal),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.normalBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,e.normalBuffer(),this.gl.STATIC_DRAW),this.gl.vertexAttribPointer(this.a_normal,3,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.elementBuffer),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,e.elementBuffer(),this.gl.STATIC_DRAW),this.gl.uniform4fv(this.u_colorLoc,e.getColor().vec()),this.gl.uniformMatrix4fv(this.u_trsMatrixLoc,!1,this.useCamera(e.getTrsMatrix()).buffer()),this.gl.drawElements(this.gl.TRIANGLES,e.elementBuffer().length,this.gl.UNSIGNED_SHORT,0)}},{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),this.pointBuffer=this.gl.createBuffer(),this.elementBuffer=this.gl.createBuffer(),this.normalBuffer=this.gl.createBuffer()}},{key:"useCamera",value:function(e){return V.Perspective(90,this.stage.clientWidth/this.stage.clientHeight,1,2e3).times(this.camera.viewMat()).times(e)}},{key:"mainLoop",value:function(e){var t,n=fe(this.objects);try{for(n.s();!(t=n.n()).done;)t.value.update(e)}catch(e){n.e(e)}finally{n.f()}var r,o=fe(this.objects);try{for(o.s();!(r=o.n()).done;){var i=r.value;this.renderObject(i)}}catch(e){o.e(e)}finally{o.f()}}},{key:"frame",value:function(e){var t=this,n=Date.now(),r=n-e;this.mainLoop(r),this.running&&window.requestAnimationFrame((function(){return t.frame(n)}))}},{key:"setupScene",value:function(){var e=new ie(4,100);e.setColor(new F(1,0,0)),e.scaleBy(.2),e.rotateBy(-Math.PI/2,0,.5),this.objects.push(e),console.log(this.camera.getTrsMatrix()),this.camera.translateBy(10,0,10),this.camera.lookAt(e.position(),new h(0,1,0)),console.log(this.camera.getTrsMatrix()),console.log(this.useCamera(e.getTrsMatrix()))}},{key:"run",value:function(){var e=this;this.initViewport(),this.useDefaultProgram(),this.setupScene(),window.requestAnimationFrame((function(){return e.frame(Date.now())}))}}])&&pe(t.prototype,n),r&&pe(t,r),e}();function ve(e,t){var n=document.createElement("div");n.id=e.id,n.innerText=t,e.replaceWith(n)}window.onload=function(){var e=function(e,t){var n=document.querySelector("#root"),r=document.createElement("canvas");return r.id="main-stage",r.width=e,r.height=t,n.appendChild(r),r}(1024,720),t=e.getContext("webgl");if(t){var n=new ye(t,e);n.onShutdown((function(t){return function(e,t){t===le.QUIT?ve(e,"We're done here."):t===le.ERROR&&ve(e,"Something unexpected happened and forced the program to shut down.")}(e,t)})),n.run()}else ve(e,"Unable to initialize WebGL. Your browser or machine may not support it.")}}]); |