├── .gitignore ├── .npmignore ├── .prettierrc ├── LICENSE ├── README.md ├── docs ├── assets │ ├── index.a6925462.js │ └── vendor.3b317da4.js └── index.html ├── example ├── index.html ├── main.ts ├── texture.ts └── types.d.ts ├── lib ├── index.d.ts ├── index.d.ts.map ├── index.es.js └── index.umd.js ├── media └── screenshot.webp ├── package-lock.json ├── package.json ├── src └── index.ts ├── tsconfig.json ├── vite.example-config.js └── vite.lib-config.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | ./docs 2 | ./example 3 | ./media 4 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "tabWidth": 2, 4 | "useTabs": false 5 | } 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rounded box 2 | 3 | Generates a rounded box mesh centered on the origin with configurable dimensions, corner and edge radius, and resolution. 4 | 5 |

6 | 7 |

8 | 9 | [Live Demo](https://wwwtyro.github.io/rounded-box) 10 | 11 | ## Installation 12 | 13 | ```sh 14 | npm i rounded-box 15 | ``` 16 | 17 | ## Example 18 | 19 | ``` 20 | import { generateRoundedBox } from "rounded-box"; 21 | 22 | const box = generateRoundedBox({ width: 1, height: 1.25, depth: 1.5 }); 23 | ``` 24 | 25 | ## API 26 | 27 | ```ts 28 | const box = generateRoundedBox(options?: Options) 29 | ``` 30 | 31 | ### Parameters 32 | 33 | > options 34 | 35 | | Option | Type | Default | Description | 36 | | ---------- | ------ | ------- | ----------------------------------------------------------------------------------------- | 37 | | width | number | 1 | The size of the box along the x-axis. | 38 | | height | number | 1 | The size of the box along the y-axis. | 39 | | depth | number | 1 | The size of the box along the z-axis. | 40 | | radius | number | 0.125 | The radius of the rounded box corners and edges. | 41 | | resolution | number | 5 | The number of segments along the rounded regions of the mesh used to approximate a curve. | 42 | 43 | ### Returns 44 | 45 | > box 46 | 47 | | Name | Type | Description | 48 | | --------- | ---------- | -------------------------------------------------------------------------------- | 49 | | positions | number[][] | The position of each vertex in the format [[x0, y0, z0], [x1, y1, z1], ...] | 50 | | normals | number[][] | The normal vector of each vertex in the format [[x0, y0, z0], [x1, y1, z1], ...] | 51 | | cells | number[][] | The indicies of the mesh in the format [[i0, j0, k0], [i1, j1, k1], ...] | 52 | 53 | ## Running the example 54 | 55 | ```sh 56 | git clone https://github.com/wwwtyro/rounded-box.git 57 | cd rounded-box 58 | npm i 59 | npm run dev 60 | ``` 61 | 62 | Open a browser to localhost:3000/example/ 63 | -------------------------------------------------------------------------------- /docs/assets/index.a6925462.js: -------------------------------------------------------------------------------- 1 | var t=Object.defineProperty,e=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,r=(e,o,n)=>o in e?t(e,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[o]=n,i=(t,i)=>{for(var s in i||(i={}))o.call(i,s)&&r(t,s,i[s]);if(e)for(var s of e(i))n.call(i,s)&&r(t,s,i[s]);return t},s=("undefined"!=typeof require&&require,(t,e,o)=>(r(t,"symbol"!=typeof e?e+"":e,o),o));import{f as l,m as a,l as c,a as p,c as h,s as u,b as m,d,e as f,n as g,g as v,h as x,R as y,t as b,i as w,j as N,p as j}from"./vendor.3b317da4.js";!function(){const t=document.createElement("link").relList;if(!(t&&t.supports&&t.supports("modulepreload"))){for(const t of document.querySelectorAll('link[rel="modulepreload"]'))e(t);new MutationObserver((t=>{for(const o of t)if("childList"===o.type)for(const t of o.addedNodes)"LINK"===t.tagName&&"modulepreload"===t.rel&&e(t)})).observe(document,{childList:!0,subtree:!0})}function e(t){if(t.ep)return;t.ep=!0;const e=function(t){const e={};return t.integrity&&(e.integrity=t.integrity),t.referrerpolicy&&(e.referrerPolicy=t.referrerpolicy),"use-credentials"===t.crossorigin?e.credentials="include":"anonymous"===t.crossorigin?e.credentials="omit":e.credentials="same-origin",e}(t);fetch(t.href,e)}}();const P=[{start:l(.5,-.5,.5),right:l(0,0,-1),up:l(0,1,0)},{start:l(-.5,-.5,-.5),right:l(0,0,1),up:l(0,1,0)},{start:l(-.5,.5,.5),right:l(1,0,0),up:l(0,0,-1)},{start:l(-.5,-.5,-.5),right:l(1,0,0),up:l(0,0,1)},{start:l(-.5,-.5,.5),right:l(1,0,0),up:l(0,1,0)},{start:l(.5,-.5,-.5),right:l(-1,0,0),up:l(0,1,0)}];function z(t,e,o,n,r,i,s){const l=[];for(let a=0;a[t[0],t[1],t[2]])),normals:v.map((t=>[t[0],t[1],t[2]])),cells:g}}({width:1,height:1.25,depth:1.5}),_=A.buffer(S.positions),B=A.buffer(S.normals),K=A.elements(S.cells);!function t(){const e=j(N(),Math.PI/3,C.width/C.height,.1,100),o={x:0,y:0,width:C.width,height:C.height};A.clear({color:[1,1,1,1],depth:1}),E({positions:_,normals:B,cells:K,count:S.positions.length,model:I.rotation,view:F,projection:e,viewport:o}),requestAnimationFrame(t)}(); 2 | -------------------------------------------------------------------------------- /docs/assets/vendor.3b317da4.js: -------------------------------------------------------------------------------- 1 | "undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function e(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})})),t}var t={exports:{}},n=t.exports=function(){var e=function(e){return e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Float32Array||e instanceof Float64Array||e instanceof Uint8ClampedArray},t=function(e,t){for(var n=Object.keys(t),r=0;r=0&&(0|e)===e||a("invalid parameter type, ("+e+")"+o(t)+". must be a nonnegative integer")}function h(e,t,n){t.indexOf(e)<0&&a("invalid value"+o(n)+". must be one of: "+t)}var d=["gl","canvas","container","attributes","pixelRatio","extensions","optionalExtensions","profile","onDone"];function m(e){Object.keys(e).forEach((function(e){d.indexOf(e)<0&&a('invalid regl constructor argument "'+e+'". must be one of '+d)}))}function p(e,t){for(e+="";e.length0&&t.push(new g("unknown",0,e))}})),t}function A(e,t){t.forEach((function(t){var n=e[t.file];if(n){var r=n.index[t.line];if(r)return r.errors.push(t),void(n.hasErrors=!0)}e.unknown.hasErrors=!0,e.unknown.lines[0].errors.push(t)}))}function E(e,t,r,a,o){if(!e.getShaderParameter(t,e.COMPILE_STATUS)){var u=e.getShaderInfoLog(t),s=a===e.FRAGMENT_SHADER?"fragment":"vertex";j(r,"string",s+" shader source must be a string",o);var f=w(r,o),c=M(u);A(f,c),Object.keys(f).forEach((function(e){var t=f[e];if(t.hasErrors){var r=[""],a=[""];i("file number "+e+": "+t.name+"\n","color:red;text-decoration:underline;font-weight:bold"),t.lines.forEach((function(e){if(e.errors.length>0){i(p(e.number,4)+"| ","background-color:yellow; font-weight:bold"),i(e.line+n,"color:red; background-color:yellow; font-weight:bold");var t=0;e.errors.forEach((function(r){var a=r.message,o=/^\s*'(.*)'\s*:\s*(.*)$/.exec(a);if(o){var u=o[1];switch(a=o[2],u){case"assign":u="="}t=Math.max(e.line.indexOf(u,t),0)}else t=0;i(p("| ",6)),i(p("^^^",t+3)+n,"font-weight:bold"),i(p("| ",6)),i(a+n,"font-weight:bold")})),i(p("| ",6)+n)}else i(p(e.number,4)+"| "),i(e.line+n,"color:red")})),"undefined"==typeof document||window.chrome?console.log(r.join("")):(a[0]=r.join("%c"),console.log.apply(console,a))}function i(e,t){r.push(e),a.push(t||"")}})),i.raise("Error compiling "+s+" shader, "+f[0].name)}}function _(e,t,r,a,o){if(!e.getProgramParameter(t,e.LINK_STATUS)){var u=e.getProgramInfoLog(t),s=w(r,o),f='Error linking program with vertex shader, "'+w(a,o)[0].name+'", and fragment shader "'+s[0].name+'"';"undefined"!=typeof document?console.log("%c"+f+n+"%c"+u,"color:red;text-decoration:underline;font-weight:bold","color:red"):console.log(f+n+u),i.raise(f)}}function S(e){e._commandRef=y()}function T(e,t,n,r){function a(e){return e?r.id(e):0}function i(e,t){Object.keys(t).forEach((function(t){e[r.id(t)]=!0}))}S(e),e._fragId=a(e.static.frag),e._vertId=a(e.static.vert);var o=e._uniformSet={};i(o,t.static),i(o,t.dynamic);var u=e._attributeSet={};i(u,n.static),i(u,n.dynamic),e._hasCount="count"in e.static||"count"in e.dynamic||"elements"in e.static||"elements"in e.dynamic}function O(e,t){var n=x();a(e+" in command "+(t||y())+("unknown"===n?"":" called from "+n))}function k(e,t,n){e||O(t,n||y())}function D(e,t,n,r){e in t||O("unknown parameter ("+e+")"+o(n)+". possible values: "+Object.keys(t).join(),r||y())}function j(e,t,n,r){f(e,t)||O("invalid parameter type"+o(n)+". expected "+t+", got "+typeof e,r||y())}function C(e){e()}function P(e,t,n){e.texture?h(e.texture._texture.internalformat,t,"unsupported texture format for attachment"):h(e.renderbuffer._renderbuffer.format,n,"unsupported renderbuffer format for attachment")}var I=33071,R=9728,F=9984,z=9985,L=9986,B=9987,V=5121,q=5122,N=5123,Y=5124,U=5125,X=5126,W=32819,H=32820,G=33635,Q=34042,K=36193,$={};function Z(e,t){return e===H||e===W||e===G?2:e===Q?4:$[e]*t}function J(e){return!(e&e-1||!e)}function ee(e,t,n){var r,a=t.width,o=t.height,u=t.channels;i(a>0&&a<=n.maxTextureSize&&o>0&&o<=n.maxTextureSize,"invalid texture shape"),e.wrapS===I&&e.wrapT===I||i(J(a)&&J(o),"incompatible wrap mode for texture, both width and height must be power of 2"),1===t.mipmask?1!==a&&1!==o&&i(e.minFilter!==F&&e.minFilter!==L&&e.minFilter!==z&&e.minFilter!==B,"min filter requires mipmap"):(i(J(a)&&J(o),"texture must be a square power of 2 to support mipmapping"),i(t.mipmask===(a<<1)-1,"missing or incomplete mipmap data")),t.type===X&&(n.extensions.indexOf("oes_texture_float_linear")<0&&i(e.minFilter===R&&e.magFilter===R,"filter not supported, must enable oes_texture_float_linear"),i(!e.genMipmaps,"mipmap generation not supported with float textures"));var s=t.images;for(r=0;r<16;++r)if(s[r]){var f=a>>r,c=o>>r;i(t.mipmask&1<0&&a<=r.maxTextureSize&&o>0&&o<=r.maxTextureSize,"invalid texture shape"),i(a===o,"cube map must be square"),i(t.wrapS===I&&t.wrapT===I,"wrap mode not supported by cube map");for(var s=0;s>l,m=o>>l;i(f.mipmask&1<1&&t===n&&('"'===t||"'"===t))return['"'+se(e.substr(1,e.length-2))+'"'];var r=/\[(false|true|null|\d+|'[^']*'|"[^"]*")\]/.exec(e);if(r)return fe(e.substr(0,r.index)).concat(fe(r[1])).concat(fe(e.substr(r.index+r[0].length)));var a=e.split(".");if(1===a.length)return['"'+se(e)+'"'];for(var i=[],o=0;o0,"invalid pixel ratio"))):ne.raise("invalid arguments to regl"),t&&("canvas"===t.nodeName.toLowerCase()?r=t:n=t),!a){if(!r){ne("undefined"!=typeof document,"must manually specify webgl context outside of DOM environments");var d=ge(n||document.body,l,f);if(!d)return null;r=d.canvas,h=d.onDestroy}void 0===o.premultipliedAlpha&&(o.premultipliedAlpha=!0),a=ye(r,o)}return a?{gl:a,canvas:r,container:n,extensions:u,optionalExtensions:s,pixelRatio:f,profile:c,onDone:l,onDestroy:h}:(h(),l("webgl not supported, try upgrading your browser or graphics drivers http://get.webgl.org"),null)}function _e(e,t){var n={};function r(t){ne.type(t,"string","extension name must be string");var r,a=t.toLowerCase();try{r=n[a]=e.getExtension(a)}catch(i){}return!!r}for(var a=0;a65535)<<4,t|=n=((e>>>=t)>255)<<3,t|=n=((e>>>=n)>15)<<2,(t|=n=((e>>>=n)>3)<<1)|(e>>>=n)>>1}function Fe(){var e=Se(8,(function(){return[]}));function t(t){var n=Ie(t),r=e[Re(n)>>2];return r.length>0?r.pop():new ArrayBuffer(n)}function n(t){e[Re(t.byteLength)>>2].push(t)}function r(e,n){var r=null;switch(e){case Te:r=new Int8Array(t(n),0,n);break;case Oe:r=new Uint8Array(t(n),0,n);break;case ke:r=new Int16Array(t(2*n),0,n);break;case De:r=new Uint16Array(t(2*n),0,n);break;case je:r=new Int32Array(t(4*n),0,n);break;case Ce:r=new Uint32Array(t(4*n),0,n);break;case Pe:r=new Float32Array(t(4*n),0,n);break;default:return null}return r.length!==n?r.subarray(0,n):r}function a(e){n(e.buffer)}return{alloc:t,free:n,allocType:r,freeType:a}}var ze=Fe();ze.zero=Fe();var Le=3408,Be=3410,Ve=3411,qe=3412,Ne=3413,Ye=3414,Ue=3415,Xe=33901,We=33902,He=3379,Ge=3386,Qe=34921,Ke=36347,$e=36348,Ze=35661,Je=35660,et=34930,tt=36349,nt=34076,rt=34024,at=7936,it=7937,ot=7938,ut=35724,st=34047,ft=36063,ct=34852,lt=3553,ht=34067,dt=34069,mt=33984,pt=6408,vt=5126,bt=5121,gt=36160,yt=36053,xt=36064,wt=16384,Mt=function(e,t){var n=1;t.ext_texture_filter_anisotropic&&(n=e.getParameter(st));var r=1,a=1;t.webgl_draw_buffers&&(r=e.getParameter(ct),a=e.getParameter(ft));var i=!!t.oes_texture_float;if(i){var o=e.createTexture();e.bindTexture(lt,o),e.texImage2D(lt,0,pt,1,1,0,pt,vt,null);var u=e.createFramebuffer();if(e.bindFramebuffer(gt,u),e.framebufferTexture2D(gt,xt,lt,o,0),e.bindTexture(lt,null),e.checkFramebufferStatus(gt)!==yt)i=!1;else{e.viewport(0,0,1,1),e.clearColor(1,0,0,1),e.clear(wt);var s=ze.allocType(vt,4);e.readPixels(0,0,1,1,pt,vt,s),e.getError()?i=!1:(e.deleteFramebuffer(u),e.deleteTexture(o),i=1===s[0]),ze.freeType(s)}}var f=!0;if("undefined"==typeof navigator||!(/MSIE/.test(navigator.userAgent)||/Trident\//.test(navigator.appVersion)||/Edge/.test(navigator.userAgent))){var c=e.createTexture(),l=ze.allocType(bt,36);e.activeTexture(mt),e.bindTexture(ht,c),e.texImage2D(dt,0,pt,3,3,0,pt,bt,l),ze.freeType(l),e.bindTexture(ht,null),e.deleteTexture(c),f=!e.getError()}return{colorBits:[e.getParameter(Be),e.getParameter(Ve),e.getParameter(qe),e.getParameter(Ne)],depthBits:e.getParameter(Ye),stencilBits:e.getParameter(Ue),subpixelBits:e.getParameter(Le),extensions:Object.keys(t).filter((function(e){return!!t[e]})),maxAnisotropic:n,maxDrawbuffers:r,maxColorAttachments:a,pointSizeDims:e.getParameter(Xe),lineWidthDims:e.getParameter(We),maxViewportDims:e.getParameter(Ge),maxCombinedTextureUnits:e.getParameter(Ze),maxCubeMapSize:e.getParameter(nt),maxRenderbufferSize:e.getParameter(rt),maxTextureUnits:e.getParameter(et),maxTextureSize:e.getParameter(He),maxAttributes:e.getParameter(Qe),maxVertexUniforms:e.getParameter(Ke),maxVertexTextureUnits:e.getParameter(Je),maxVaryingVectors:e.getParameter($e),maxFragmentUniforms:e.getParameter(tt),glsl:e.getParameter(ut),renderer:e.getParameter(it),vendor:e.getParameter(at),version:e.getParameter(ot),readFloat:i,npotTextureCube:f}};function At(t){return!!t&&"object"==typeof t&&Array.isArray(t.shape)&&Array.isArray(t.stride)&&"number"==typeof t.offset&&t.shape.length===t.stride.length&&(Array.isArray(t.data)||e(t.data))}var Et=function(e){return Object.keys(e).map((function(t){return e[t]}))},_t={shape:jt,flatten:Dt};function St(e,t,n){for(var r=0;r0)if(Array.isArray(n[0])){u=Ft(n);for(var f=1,c=1;c0)if("number"==typeof t[0]){var i=ze.allocType(c.dtype,t.length);Yt(i,t),m(i,a),ze.freeType(i)}else if(Array.isArray(t[0])||e(t[0])){r=Ft(t);var o=Rt(t,r,c.dtype);m(o,a),ze.freeType(o)}else ne.raise("invalid buffer data")}else if(At(t)){r=t.shape;var u=t.stride,s=0,f=0,h=0,d=0;1===r.length?(s=r[0],f=1,h=u[0],d=0):2===r.length?(s=r[0],f=r[1],h=u[0],d=u[1]):ne.raise("invalid shape");var p=Array.isArray(t.data)?c.dtype:Nt(t.data),v=ze.allocType(p,s*f);Ut(v,t.data,s,f,h,d,t.offset),m(v,a),ze.freeType(v)}else ne.raise("invalid data for buffer subdata");return l}return o[c.id]=c,s||l(a),l._reglType="buffer",l._buffer=c,l.subdata=p,r.profile&&(l.stats=c.stats),l.destroy=function(){d(c)},l}function p(){Et(o).forEach((function(e){e.buffer=t.createBuffer(),t.bindBuffer(e.type,e.buffer),t.bufferData(e.type,e.persistentData||e.byteLength,e.usage)}))}return r.profile&&(n.getTotalBufferSize=function(){var e=0;return Object.keys(o).forEach((function(t){e+=o[t].stats.size})),e}),{create:m,createStream:f,destroyStream:c,clear:function(){Et(o).forEach(d),s.forEach(d)},getBuffer:function(e){return e&&e._buffer instanceof u?e._buffer:null},restore:p,_initBuffer:h}}qt[5120]=1,qt[5122]=2,qt[5124]=4,qt[5121]=1,qt[5123]=2,qt[5125]=4,qt[5126]=4;var Wt={points:0,point:0,lines:1,line:1,triangles:4,triangle:4,"line loop":2,"line strip":3,"triangle strip":5,"triangle fan":6},Ht=0,Gt=1,Qt=4,Kt=5120,$t=5121,Zt=5122,Jt=5123,en=5124,tn=5125,nn=34963,rn=35040,an=35044;function on(t,n,r,a){var i={},o=0,u={uint8:$t,uint16:Jt};function s(e){this.id=o++,i[this.id]=this,this.buffer=e,this.primType=Qt,this.vertCount=0,this.type=0}n.oes_element_index_uint&&(u.uint32=tn),s.prototype.bind=function(){this.buffer.bind()};var f=[];function c(e){var t=f.pop();return t||(t=new s(r.create(null,nn,!0,!1)._buffer)),h(t,e,rn,-1,-1,0,0),t}function l(e){f.push(e)}function h(a,i,o,u,s,f,c){var l;if(a.buffer.bind(),i){var h=c;c||e(i)&&(!At(i)||e(i.data))||(h=n.oes_element_index_uint?tn:Jt),r._initBuffer(a.buffer,i,o,h,3)}else t.bufferData(nn,f,o),a.buffer.dtype=l||$t,a.buffer.usage=o,a.buffer.dimension=3,a.buffer.byteLength=f;if(l=c,!c){switch(a.buffer.dtype){case $t:case Kt:l=$t;break;case Jt:case Zt:l=Jt;break;case tn:case en:l=tn;break;default:ne.raise("unsupported type for element array")}a.buffer.dtype=l}a.type=l,ne(l!==tn||!!n.oes_element_index_uint,"32 bit element buffers not supported, enable oes_element_index_uint first");var d=s;d<0&&(d=a.buffer.byteLength,l===Jt?d>>=1:l===tn&&(d>>=2)),a.vertCount=d;var m=u;if(u<0){m=Qt;var p=a.buffer.dimension;1===p&&(m=Ht),2===p&&(m=Gt),3===p&&(m=Qt)}a.primType=m}function d(e){a.elementsCount--,ne(null!==e.buffer,"must not double destroy elements"),delete i[e.id],e.buffer.destroy(),e.buffer=null}function m(t,n){var i=r.create(null,nn,!0),o=new s(i._buffer);function f(t){if(t)if("number"==typeof t)i(t),o.primType=Qt,o.vertCount=0|t,o.type=$t;else{var n=null,r=an,a=-1,s=-1,c=0,l=0;Array.isArray(t)||e(t)||At(t)?n=t:(ne.type(t,"object","invalid arguments for elements"),"data"in t&&(n=t.data,ne(Array.isArray(n)||e(n)||At(n),"invalid data for element buffer")),"usage"in t&&(ne.parameter(t.usage,It,"invalid element buffer usage"),r=It[t.usage]),"primitive"in t&&(ne.parameter(t.primitive,Wt,"invalid element buffer primitive"),a=Wt[t.primitive]),"count"in t&&(ne("number"==typeof t.count&&t.count>=0,"invalid vertex count for elements"),s=0|t.count),"type"in t&&(ne.parameter(t.type,u,"invalid buffer type"),l=u[t.type]),"length"in t?c=0|t.length:(c=s,l===Jt||l===Zt?c*=2:l!==tn&&l!==en||(c*=4))),h(o,n,r,a,s,c,l)}else i(),o.primType=Qt,o.vertCount=0,o.type=$t;return f}return a.elementsCount++,f(t),f._reglType="elements",f._elements=o,f.subdata=function(e,t){return i.subdata(e,t),f},f.destroy=function(){d(o)},f}return{create:m,createStream:c,destroyStream:l,getElements:function(e){return"function"==typeof e&&e._elements instanceof s?e._elements:null},clear:function(){Et(i).forEach(d)}}}var un=new Float32Array(1),sn=new Uint32Array(un.buffer),fn=5123;function cn(e){for(var t=ze.allocType(fn,e.length),n=0;n>>31<<15,i=(r<<1>>>24)-127,o=r>>13&1023;if(i<-24)t[n]=a;else if(i<-14){var u=-14-i;t[n]=a+(o+1024>>u)}else t[n]=i>15?a+31744:a+(i+15<<10)+o}return t}function ln(t){return Array.isArray(t)||e(t)}var hn=function(e){return!(e&e-1||!e)},dn=34467,mn=3553,pn=34067,vn=34069,bn=6408,gn=6406,yn=6407,xn=6409,wn=6410,Mn=32854,An=32855,En=36194,_n=32819,Sn=32820,Tn=33635,On=34042,kn=6402,Dn=34041,jn=35904,Cn=35906,Pn=36193,In=33776,Rn=33777,Fn=33778,zn=33779,Ln=35986,Bn=35987,Vn=34798,qn=35840,Nn=35841,Yn=35842,Un=35843,Xn=36196,Wn=5121,Hn=5123,Gn=5125,Qn=5126,Kn=10242,$n=10243,Zn=10497,Jn=33071,er=33648,tr=10240,nr=10241,rr=9728,ar=9729,ir=9984,or=9985,ur=9986,sr=9987,fr=33170,cr=4352,lr=4353,hr=4354,dr=34046,mr=3317,pr=37440,vr=37441,br=37443,gr=37444,yr=33984,xr=[ir,ur,or,sr],wr=[0,xn,wn,yn,bn],Mr={};function Ar(e){return"[object "+e+"]"}Mr[xn]=Mr[gn]=Mr[kn]=1,Mr[Dn]=Mr[wn]=2,Mr[yn]=Mr[jn]=3,Mr[bn]=Mr[Cn]=4;var Er=Ar("HTMLCanvasElement"),_r=Ar("OffscreenCanvas"),Sr=Ar("CanvasRenderingContext2D"),Tr=Ar("ImageBitmap"),Or=Ar("HTMLImageElement"),kr=Ar("HTMLVideoElement"),Dr=Object.keys(Ct).concat([Er,_r,Sr,Tr,Or,kr]),jr=[];jr[Wn]=1,jr[Qn]=4,jr[Pn]=2,jr[Hn]=2,jr[Gn]=4;var Cr=[];function Pr(e){return Array.isArray(e)&&(0===e.length||"number"==typeof e[0])}function Ir(e){return!!Array.isArray(e)&&!(0===e.length||!ln(e[0]))}function Rr(e){return Object.prototype.toString.call(e)}function Fr(e){return Rr(e)===Er}function zr(e){return Rr(e)===_r}function Lr(e){return Rr(e)===Sr}function Br(e){return Rr(e)===Tr}function Vr(e){return Rr(e)===Or}function qr(e){return Rr(e)===kr}function Nr(e){if(!e)return!1;var t=Rr(e);return Dr.indexOf(t)>=0||Pr(e)||Ir(e)||At(e)}function Yr(e){return 0|Ct[Object.prototype.toString.call(e)]}function Ur(e,t){var n=t.length;switch(e.type){case Wn:case Hn:case Gn:case Qn:var r=ze.allocType(e.type,n);r.set(t),e.data=r;break;case Pn:e.data=cn(t);break;default:ne.raise("unsupported texture type, must specify a typed array")}}function Xr(e,t){return ze.allocType(e.type===Pn?Qn:e.type,t)}function Wr(e,t){e.type===Pn?(e.data=cn(t),ze.freeType(t)):e.data=t}function Hr(e,t,n,r,a,i){for(var o=e.width,u=e.height,s=e.channels,f=Xr(e,o*u*s),c=0,l=0;l=1;)u+=o*s*s,s/=2;return u}return o*n*r}function Qr(n,r,a,i,o,u,s){var f={"don't care":cr,"dont care":cr,nice:hr,fast:lr},c={repeat:Zn,clamp:Jn,mirror:er},l={nearest:rr,linear:ar},h=t({mipmap:sr,"nearest mipmap nearest":ir,"linear mipmap nearest":or,"nearest mipmap linear":ur,"linear mipmap linear":sr},l),d={none:0,browser:gr},m={uint8:Wn,rgba4:_n,rgb565:Tn,"rgb5 a1":Sn},p={alpha:gn,luminance:xn,"luminance alpha":wn,rgb:yn,rgba:bn,rgba4:Mn,"rgb5 a1":An,rgb565:En},v={};r.ext_srgb&&(p.srgb=jn,p.srgba=Cn),r.oes_texture_float&&(m.float32=m.float=Qn),r.oes_texture_half_float&&(m.float16=m["half float"]=Pn),r.webgl_depth_texture&&(t(p,{depth:kn,"depth stencil":Dn}),t(m,{uint16:Hn,uint32:Gn,"depth stencil":On})),r.webgl_compressed_texture_s3tc&&t(v,{"rgb s3tc dxt1":In,"rgba s3tc dxt1":Rn,"rgba s3tc dxt3":Fn,"rgba s3tc dxt5":zn}),r.webgl_compressed_texture_atc&&t(v,{"rgb atc":Ln,"rgba atc explicit alpha":Bn,"rgba atc interpolated alpha":Vn}),r.webgl_compressed_texture_pvrtc&&t(v,{"rgb pvrtc 4bppv1":qn,"rgb pvrtc 2bppv1":Nn,"rgba pvrtc 4bppv1":Yn,"rgba pvrtc 2bppv1":Un}),r.webgl_compressed_texture_etc1&&(v["rgb etc1"]=Xn);var b=Array.prototype.slice.call(n.getParameter(dn));Object.keys(v).forEach((function(e){var t=v[e];b.indexOf(t)>=0&&(p[e]=t)}));var g=Object.keys(p);a.textureFormats=g;var y=[];Object.keys(p).forEach((function(e){var t=p[e];y[t]=e}));var x=[];Object.keys(m).forEach((function(e){var t=m[e];x[t]=e}));var w=[];Object.keys(l).forEach((function(e){var t=l[e];w[t]=e}));var M=[];Object.keys(h).forEach((function(e){var t=h[e];M[t]=e}));var A=[];Object.keys(c).forEach((function(e){var t=c[e];A[t]=e}));var E=g.reduce((function(e,t){var n=p[t];return n===xn||n===gn||n===xn||n===wn||n===kn||n===Dn||r.ext_srgb&&(n===jn||n===Cn)?e[n]=n:n===An||t.indexOf("rgba")>=0?e[n]=bn:e[n]=yn,e}),{});function _(){this.internalformat=bn,this.format=bn,this.type=Wn,this.compressed=!1,this.premultiplyAlpha=!1,this.flipY=!1,this.unpackAlignment=1,this.colorSpace=gr,this.width=0,this.height=0,this.channels=0}function S(e,t){e.internalformat=t.internalformat,e.format=t.format,e.type=t.type,e.compressed=t.compressed,e.premultiplyAlpha=t.premultiplyAlpha,e.flipY=t.flipY,e.unpackAlignment=t.unpackAlignment,e.colorSpace=t.colorSpace,e.width=t.width,e.height=t.height,e.channels=t.channels}function T(e,t){if("object"==typeof t&&t){if("premultiplyAlpha"in t&&(ne.type(t.premultiplyAlpha,"boolean","invalid premultiplyAlpha"),e.premultiplyAlpha=t.premultiplyAlpha),"flipY"in t&&(ne.type(t.flipY,"boolean","invalid texture flip"),e.flipY=t.flipY),"alignment"in t&&(ne.oneOf(t.alignment,[1,2,4,8],"invalid texture unpack alignment"),e.unpackAlignment=t.alignment),"colorSpace"in t&&(ne.parameter(t.colorSpace,d,"invalid colorSpace"),e.colorSpace=d[t.colorSpace]),"type"in t){var n=t.type;ne(r.oes_texture_float||!("float"===n||"float32"===n),"you must enable the OES_texture_float extension in order to use floating point textures."),ne(r.oes_texture_half_float||!("half float"===n||"float16"===n),"you must enable the OES_texture_half_float extension in order to use 16-bit floating point textures."),ne(r.webgl_depth_texture||!("uint16"===n||"uint32"===n||"depth stencil"===n),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),ne.parameter(n,m,"invalid texture type"),e.type=m[n]}var i=e.width,o=e.height,u=e.channels,s=!1;"shape"in t?(ne(Array.isArray(t.shape)&&t.shape.length>=2,"shape must be an array"),i=t.shape[0],o=t.shape[1],3===t.shape.length&&(u=t.shape[2],ne(u>0&&u<=4,"invalid number of channels"),s=!0),ne(i>=0&&i<=a.maxTextureSize,"invalid width"),ne(o>=0&&o<=a.maxTextureSize,"invalid height")):("radius"in t&&(i=o=t.radius,ne(i>=0&&i<=a.maxTextureSize,"invalid radius")),"width"in t&&(i=t.width,ne(i>=0&&i<=a.maxTextureSize,"invalid width")),"height"in t&&(o=t.height,ne(o>=0&&o<=a.maxTextureSize,"invalid height")),"channels"in t&&(u=t.channels,ne(u>0&&u<=4,"invalid number of channels"),s=!0)),e.width=0|i,e.height=0|o,e.channels=0|u;var f=!1;if("format"in t){var c=t.format;ne(r.webgl_depth_texture||!("depth"===c||"depth stencil"===c),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),ne.parameter(c,p,"invalid texture format");var l=e.internalformat=p[c];e.format=E[l],c in m&&("type"in t||(e.type=m[c])),c in v&&(e.compressed=!0),f=!0}!s&&f?e.channels=Mr[e.format]:s&&!f?e.channels!==wr[e.format]&&(e.format=e.internalformat=wr[e.channels]):f&&s&&ne(e.channels===Mr[e.format],"number of channels inconsistent with specified format")}}function O(e){n.pixelStorei(pr,e.flipY),n.pixelStorei(vr,e.premultiplyAlpha),n.pixelStorei(br,e.colorSpace),n.pixelStorei(mr,e.unpackAlignment)}function k(){_.call(this),this.xOffset=0,this.yOffset=0,this.data=null,this.needsFree=!1,this.element=null,this.needsCopy=!1}function D(t,n){var r=null;if(Nr(n)?r=n:n&&(ne.type(n,"object","invalid pixel data type"),T(t,n),"x"in n&&(t.xOffset=0|n.x),"y"in n&&(t.yOffset=0|n.y),Nr(n.data)&&(r=n.data)),ne(!t.compressed||r instanceof Uint8Array,"compressed texture data must be stored in a uint8array"),n.copy){ne(!r,"can not specify copy and data field for the same texture");var i=o.viewportWidth,u=o.viewportHeight;t.width=t.width||i-t.xOffset,t.height=t.height||u-t.yOffset,t.needsCopy=!0,ne(t.xOffset>=0&&t.xOffset=0&&t.yOffset0&&t.width<=i&&t.height>0&&t.height<=u,"copy texture read out of bounds")}else if(r){if(e(r))t.channels=t.channels||4,t.data=r,"type"in n||t.type!==Wn||(t.type=Yr(r));else if(Pr(r))t.channels=t.channels||4,Ur(t,r),t.alignment=1,t.needsFree=!0;else if(At(r)){var s=r.data;Array.isArray(s)||t.type!==Wn||(t.type=Yr(s));var f,c,l,h,d,m,p=r.shape,v=r.stride;3===p.length?(l=p[2],m=v[2]):(ne(2===p.length,"invalid ndarray pixel data, must be 2 or 3D"),l=1,m=1),f=p[0],c=p[1],h=v[0],d=v[1],t.alignment=1,t.width=f,t.height=c,t.channels=l,t.format=t.internalformat=wr[l],t.needsFree=!0,Hr(t,s,h,d,m,r.offset)}else if(Fr(r)||zr(r)||Lr(r))Fr(r)||zr(r)?t.element=r:t.element=r.canvas,t.width=t.element.width,t.height=t.element.height,t.channels=4;else if(Br(r))t.element=r,t.width=r.width,t.height=r.height,t.channels=4;else if(Vr(r))t.element=r,t.width=r.naturalWidth,t.height=r.naturalHeight,t.channels=4;else if(qr(r))t.element=r,t.width=r.videoWidth,t.height=r.videoHeight,t.channels=4;else if(Ir(r)){var b=t.width||r[0].length,g=t.height||r.length,y=t.channels;y=ln(r[0][0])?y||r[0][0].length:y||1;for(var x=_t.shape(r),w=1,M=0;M=0,"oes_texture_float extension not enabled"):t.type===Pn&&ne(a.extensions.indexOf("oes_texture_half_float")>=0,"oes_texture_half_float extension not enabled")}function j(e,t,r){var a=e.element,o=e.data,u=e.internalformat,s=e.format,f=e.type,c=e.width,l=e.height;O(e),a?n.texImage2D(t,r,s,s,f,a):e.compressed?n.compressedTexImage2D(t,r,u,c,l,0,o):e.needsCopy?(i(),n.copyTexImage2D(t,r,s,e.xOffset,e.yOffset,c,l,0)):n.texImage2D(t,r,s,c,l,0,s,f,o||null)}function C(e,t,r,a,o){var u=e.element,s=e.data,f=e.internalformat,c=e.format,l=e.type,h=e.width,d=e.height;O(e),u?n.texSubImage2D(t,o,r,a,c,l,u):e.compressed?n.compressedTexSubImage2D(t,o,r,a,f,h,d,s):e.needsCopy?(i(),n.copyTexSubImage2D(t,o,r,a,e.xOffset,e.yOffset,h,d)):n.texSubImage2D(t,o,r,a,h,d,c,l,s)}var P=[];function I(){return P.pop()||new k}function R(e){e.needsFree&&ze.freeType(e.data),k.call(e),P.push(e)}function F(){_.call(this),this.genMipmaps=!1,this.mipmapHint=cr,this.mipmask=0,this.images=Array(16)}function z(e,t,n){var r=e.images[0]=I();e.mipmask=1,r.width=e.width=t,r.height=e.height=n,r.channels=e.channels=4}function L(e,t){var n=null;if(Nr(t))S(n=e.images[0]=I(),e),D(n,t),e.mipmask=1;else if(T(e,t),Array.isArray(t.mipmap))for(var r=t.mipmap,a=0;a>=a,n.height>>=a,D(n,r[a]),e.mipmask|=1<=0&&!("faces"in t)&&(e.genMipmaps=!0)}if("mag"in t){var r=t.mag;ne.parameter(r,l),e.magFilter=l[r]}var i=e.wrapS,o=e.wrapT;if("wrap"in t){var u=t.wrap;"string"==typeof u?(ne.parameter(u,c),i=o=c[u]):Array.isArray(u)&&(ne.parameter(u[0],c),ne.parameter(u[1],c),i=c[u[0]],o=c[u[1]])}else{if("wrapS"in t){var s=t.wrapS;ne.parameter(s,c),i=c[s]}if("wrapT"in t){var d=t.wrapT;ne.parameter(d,c),o=c[d]}}if(e.wrapS=i,e.wrapT=o,"anisotropic"in t){var m=t.anisotropic;ne("number"==typeof m&&m>=1&&m<=a.maxAnisotropic,"aniso samples must be between 1 and "),e.anisotropic=t.anisotropic}if("mipmap"in t){var p=!1;switch(typeof t.mipmap){case"string":ne.parameter(t.mipmap,f,"invalid mipmap hint"),e.mipmapHint=f[t.mipmap],e.genMipmaps=!0,p=!0;break;case"boolean":p=e.genMipmaps=t.mipmap;break;case"object":ne(Array.isArray(t.mipmap),"invalid mipmap type"),e.genMipmaps=!1,p=!0;break;default:ne.raise("invalid mipmap type")}p&&!("min"in t)&&(e.minFilter=ir)}}function X(e,t){n.texParameteri(t,nr,e.minFilter),n.texParameteri(t,tr,e.magFilter),n.texParameteri(t,Kn,e.wrapS),n.texParameteri(t,$n,e.wrapT),r.ext_texture_filter_anisotropic&&n.texParameteri(t,dr,e.anisotropic),e.genMipmaps&&(n.hint(fr,e.mipmapHint),n.generateMipmap(t))}var W=0,H={},G=a.maxTextureUnits,Q=Array(G).map((function(){return null}));function K(e){_.call(this),this.mipmask=0,this.internalformat=bn,this.id=W++,this.refCount=1,this.target=e,this.texture=n.createTexture(),this.unit=-1,this.bindCount=0,this.texInfo=new Y,s.profile&&(this.stats={size:0})}function $(e){n.activeTexture(yr),n.bindTexture(e.target,e.texture)}function Z(){var e=Q[0];e?n.bindTexture(e.target,e.texture):n.bindTexture(mn,null)}function J(e){var t=e.texture;ne(t,"must not double destroy texture");var r=e.unit,a=e.target;r>=0&&(n.activeTexture(yr+r),n.bindTexture(a,null),Q[r]=null),n.deleteTexture(t),e.texture=null,e.params=null,e.pixels=null,e.refCount=0,delete H[e.id],u.textureCount--}function ee(e,t){var r=new K(mn);function i(e,t){var n=r.texInfo;Y.call(n);var o=q();return"number"==typeof e?z(o,0|e,"number"==typeof t?0|t:0|e):e?(ne.type(e,"object","invalid arguments to regl.texture"),U(n,e),L(o,e)):z(o,1,1),n.genMipmaps&&(o.mipmask=(o.width<<1)-1),r.mipmask=o.mipmask,S(r,o),ne.texture2D(n,o,a),r.internalformat=o.internalformat,i.width=o.width,i.height=o.height,$(r),B(o,mn),X(n,mn),Z(),N(o),s.profile&&(r.stats.size=Gr(r.internalformat,r.type,o.width,o.height,n.genMipmaps,!1)),i.format=y[r.internalformat],i.type=x[r.type],i.mag=w[n.magFilter],i.min=M[n.minFilter],i.wrapS=A[n.wrapS],i.wrapT=A[n.wrapT],i}function o(e,t,n,a){ne(!!e,"must specify image data");var o=0|t,u=0|n,s=0|a,f=I();return S(f,r),f.width=0,f.height=0,D(f,e),f.width=f.width||(r.width>>s)-o,f.height=f.height||(r.height>>s)-u,ne(r.type===f.type&&r.format===f.format&&r.internalformat===f.internalformat,"incompatible format for texture.subimage"),ne(o>=0&&u>=0&&o+f.width<=r.width&&u+f.height<=r.height,"texture.subimage write out of bounds"),ne(r.mipmask&1<>u;++u){var f=a>>u,c=o>>u;if(!f||!c)break;n.texImage2D(mn,u,r.format,f,c,0,r.format,r.type,null)}return Z(),s.profile&&(r.stats.size=Gr(r.internalformat,r.type,a,o,!1,!1)),i}return H[r.id]=r,u.textureCount++,i(e,t),i.subimage=o,i.resize=f,i._reglType="texture2d",i._texture=r,s.profile&&(i.stats=r.stats),i.destroy=function(){r.decRef()},i}function te(e,t,r,i,o,f){var c=new K(pn);H[c.id]=c,u.cubeCount++;var l=new Array(6);function h(e,t,n,r,i,o){var u,f=c.texInfo;for(Y.call(f),u=0;u<6;++u)l[u]=q();if("number"!=typeof e&&e)if("object"==typeof e)if(t)L(l[0],e),L(l[1],t),L(l[2],n),L(l[3],r),L(l[4],i),L(l[5],o);else if(U(f,e),T(c,e),"faces"in e){var d=e.faces;for(ne(Array.isArray(d)&&6===d.length,"cube faces must be a length 6 array"),u=0;u<6;++u)ne("object"==typeof d[u]&&!!d[u],"invalid input for cube map face"),S(l[u],c),L(l[u],d[u])}else for(u=0;u<6;++u)L(l[u],e);else ne.raise("invalid arguments to cube map");else{var m=0|e||1;for(u=0;u<6;++u)z(l[u],m,m)}for(S(c,l[0]),ne.optional((function(){a.npotTextureCube||ne(hn(c.width)&&hn(c.height),"your browser does not support non power or two texture dimensions")})),f.genMipmaps?c.mipmask=(l[0].width<<1)-1:c.mipmask=l[0].mipmask,ne.textureCube(c,f,l,a),c.internalformat=l[0].internalformat,h.width=l[0].width,h.height=l[0].height,$(c),u=0;u<6;++u)B(l[u],vn+u);for(X(f,pn),Z(),s.profile&&(c.stats.size=Gr(c.internalformat,c.type,h.width,h.height,f.genMipmaps,!0)),h.format=y[c.internalformat],h.type=x[c.type],h.mag=w[f.magFilter],h.min=M[f.minFilter],h.wrapS=A[f.wrapS],h.wrapT=A[f.wrapT],u=0;u<6;++u)N(l[u]);return h}function d(e,t,n,r,a){ne(!!t,"must specify image data"),ne("number"==typeof e&&e===(0|e)&&e>=0&&e<6,"invalid face");var i=0|n,o=0|r,u=0|a,s=I();return S(s,c),s.width=0,s.height=0,D(s,t),s.width=s.width||(c.width>>u)-i,s.height=s.height||(c.height>>u)-o,ne(c.type===s.type&&c.format===s.format&&c.internalformat===s.internalformat,"incompatible format for texture.subimage"),ne(i>=0&&o>=0&&i+s.width<=c.width&&o+s.height<=c.height,"texture.subimage write out of bounds"),ne(c.mipmask&1<>a;++a)n.texImage2D(vn+r,a,c.format,t>>a,t>>a,0,c.format,c.type,null);return Z(),s.profile&&(c.stats.size=Gr(c.internalformat,c.type,h.width,h.height,!1,!0)),h}}return h(e,t,r,i,o,f),h.subimage=d,h.resize=m,h._reglType="textureCube",h._texture=c,s.profile&&(h.stats=c.stats),h.destroy=function(){c.decRef()},h}function re(){for(var e=0;e>t,e.height>>t,0,e.internalformat,e.type,null);else for(var r=0;r<6;++r)n.texImage2D(vn+r,t,e.internalformat,e.width>>t,e.height>>t,0,e.internalformat,e.type,null);X(e.texInfo,e.target)}))}function ie(){for(var e=0;e0)continue;a.unit=-1}Q[r]=e,t=r;break}t>=G&&ne.raise("insufficient number of texture units"),s.profile&&u.maxTextureUnits=2,"invalid renderbuffer shape"),u=0|d[0],s=0|d[1]}else"radius"in h&&(u=s=0|h.radius),"width"in h&&(u=0|h.width),"height"in h&&(s=0|h.height);"format"in h&&(ne.parameter(h.format,i,"invalid renderbuffer format"),f=i[h.format])}else"number"==typeof t?(u=0|t,s="number"==typeof r?0|r:u):t?ne.raise("invalid arguments to renderbuffer constructor"):u=s=1;if(ne(u>0&&s>0&&u<=n.maxRenderbufferSize&&s<=n.maxRenderbufferSize,"invalid renderbuffer size"),u!==c.width||s!==c.height||f!==c.format)return l.width=c.width=u,l.height=c.height=s,c.format=f,e.bindRenderbuffer(Kr,c.renderbuffer),e.renderbufferStorage(Kr,f,u,s),ne(0===e.getError(),"invalid render buffer format"),a.profile&&(c.stats.size=sa(c.format,c.width,c.height)),l.format=o[c.format],l}function h(t,r){var i=0|t,o=0|r||i;return i===c.width&&o===c.height||(ne(i>0&&o>0&&i<=n.maxRenderbufferSize&&o<=n.maxRenderbufferSize,"invalid renderbuffer size"),l.width=c.width=i,l.height=c.height=o,e.bindRenderbuffer(Kr,c.renderbuffer),e.renderbufferStorage(Kr,c.format,i,o),ne(0===e.getError(),"invalid render buffer format"),a.profile&&(c.stats.size=sa(c.format,c.width,c.height))),l}return s[c.id]=c,r.renderbufferCount++,l(t,u),l.resize=h,l._reglType="renderbuffer",l._renderbuffer=c,a.profile&&(l.stats=c.stats),l.destroy=function(){c.decRef()},l}function h(){Et(s).forEach((function(t){t.renderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(Kr,t.renderbuffer),e.renderbufferStorage(Kr,t.format,t.width,t.height)})),e.bindRenderbuffer(Kr,null)}return f.prototype.decRef=function(){--this.refCount<=0&&c(this)},a.profile&&(r.getTotalRenderbufferSize=function(){var e=0;return Object.keys(s).forEach((function(t){e+=s[t].stats.size})),e}),{create:l,clear:function(){Et(s).forEach(c)},restore:h}},ca=36160,la=36161,ha=3553,da=34069,ma=36064,pa=36096,va=36128,ba=33306,ga=36053,ya=36054,xa=36055,wa=36057,Ma=36061,Aa=36193,Ea=5121,_a=5126,Sa=6407,Ta=6408,Oa=6402,ka=[Sa,Ta],Da=[];Da[Ta]=4,Da[Sa]=3;var ja=[];ja[Ea]=1,ja[_a]=4,ja[Aa]=2;var Ca=33189,Pa=36168,Ia=34041,Ra=[32854,32855,36194,35907,34842,34843,34836],Fa={};function za(e,n,r,a,i,o){var u={cur:null,next:null,dirty:!1,setFBO:null},s=["rgba"],f=["rgba4","rgb565","rgb5 a1"];n.ext_srgb&&f.push("srgba"),n.ext_color_buffer_half_float&&f.push("rgba16f","rgb16f"),n.webgl_color_buffer_float&&f.push("rgba32f");var c=["uint8"];function l(e,t,n){this.target=e,this.texture=t,this.renderbuffer=n;var r=0,a=0;t?(r=t.width,a=t.height):n&&(r=n.width,a=n.height),this.width=r,this.height=a}function h(e){e&&(e.texture&&e.texture._texture.decRef(),e.renderbuffer&&e.renderbuffer._renderbuffer.decRef())}function d(e,t,n){if(e)if(e.texture){var r=e.texture._texture,a=Math.max(1,r.width),i=Math.max(1,r.height);ne(a===t&&i===n,"inconsistent width/height for supplied texture"),r.refCount+=1}else{var o=e.renderbuffer._renderbuffer;ne(o.width===t&&o.height===n,"inconsistent width/height for renderbuffer"),o.refCount+=1}}function m(t,n){n&&(n.texture?e.framebufferTexture2D(ca,t,n.target,n.texture._texture.texture,0):e.framebufferRenderbuffer(ca,t,la,n.renderbuffer._renderbuffer.renderbuffer))}function p(e){var t=ha,n=null,r=null,a=e;"object"==typeof e&&(a=e.data,"target"in e&&(t=0|e.target)),ne.type(a,"function","invalid attachment data");var i=a._reglType;return"texture2d"===i?(n=a,ne(t===ha)):"textureCube"===i?(n=a,ne(t>=da&&t=2,"invalid shape for framebuffer"),o=j[0],h=j[1]}else"radius"in D&&(o=h=D.radius),"width"in D&&(o=D.width),"height"in D&&(h=D.height);("color"in D||"colors"in D)&&(y=D.color||D.colors,Array.isArray(y)&&ne(1===y.length||n.webgl_draw_buffers,"multiple render targets not supported")),y||("colorCount"in D&&(_=0|D.colorCount,ne(_>0,"invalid color buffer count")),"colorTexture"in D&&(x=!!D.colorTexture,w="rgba4"),"colorType"in D&&(A=D.colorType,x?(ne(n.oes_texture_float||!("float"===A||"float32"===A),"you must enable OES_texture_float in order to use floating point framebuffer objects"),ne(n.oes_texture_half_float||!("half float"===A||"float16"===A),"you must enable OES_texture_half_float in order to use 16-bit floating point framebuffer objects")):"half float"===A||"float16"===A?(ne(n.ext_color_buffer_half_float,"you must enable EXT_color_buffer_half_float to use 16-bit render buffers"),w="rgba16f"):"float"!==A&&"float32"!==A||(ne(n.webgl_color_buffer_float,"you must enable WEBGL_color_buffer_float in order to use 32-bit floating point renderbuffers"),w="rgba32f"),ne.oneOf(A,c,"invalid color type")),"colorFormat"in D&&(w=D.colorFormat,s.indexOf(w)>=0?x=!0:f.indexOf(w)>=0?x=!1:ne.optional((function(){x?ne.oneOf(D.colorFormat,s,"invalid color format for texture"):ne.oneOf(D.colorFormat,f,"invalid color format for renderbuffer")})))),("depthTexture"in D||"depthStencilTexture"in D)&&(k=!(!D.depthTexture&&!D.depthStencilTexture),ne(!k||n.webgl_depth_texture,"webgl_depth_texture extension not supported")),"depth"in D&&("boolean"==typeof D.depth?m=D.depth:(S=D.depth,g=!1)),"stencil"in D&&("boolean"==typeof D.stencil?g=D.stencil:(T=D.stencil,m=!1)),"depthStencil"in D&&("boolean"==typeof D.depthStencil?m=g=D.depthStencil:(O=D.depthStencil,m=!1,g=!1))}else o=h=1;var C=null,P=null,I=null,R=null;if(Array.isArray(y))C=y.map(p);else if(y)C=[p(y)];else for(C=new Array(_),a=0;a<_;++a)C[a]=v(o,h,x,w,A);ne(n.webgl_draw_buffers||C.length<=1,"you must enable the WEBGL_draw_buffers extension in order to use multiple color buffers."),ne(C.length<=r.maxColorAttachments,"too many color attachments, not supported"),o=o||C[0].width,h=h||C[0].height,S?P=p(S):m&&!g&&(P=v(o,h,k,"depth","uint32")),T?I=p(T):g&&!m&&(I=v(o,h,!1,"stencil","uint8")),O?R=p(O):!S&&!T&&g&&m&&(R=v(o,h,k,"depth stencil","depth stencil")),ne(!!S+!!T+!!O<=1,"invalid framebuffer configuration, can specify exactly one depth/stencil attachment");var F=null;for(a=0;a=0||C[a].renderbuffer&&Ra.indexOf(C[a].renderbuffer._renderbuffer.format)>=0,"framebuffer color attachment "+a+" is invalid"),C[a]&&C[a].texture){var z=Da[C[a].texture._texture.format]*ja[C[a].texture._texture.type];null===F?F=z:ne(F===z,"all color attachments much have the same number of bits per pixel.")}return d(P,o,h),ne(!P||P.texture&&P.texture._texture.format===Oa||P.renderbuffer&&P.renderbuffer._renderbuffer.format===Ca,"invalid depth attachment for framebuffer object"),d(I,o,h),ne(!I||I.renderbuffer&&I.renderbuffer._renderbuffer.format===Pa,"invalid stencil attachment for framebuffer object"),d(R,o,h),ne(!R||R.texture&&R.texture._texture.format===Ia||R.renderbuffer&&R.renderbuffer._renderbuffer.format===Ia,"invalid depth-stencil attachment for framebuffer object"),M(i),i.width=o,i.height=h,i.colorAttachments=C,i.depthAttachment=P,i.stencilAttachment=I,i.depthStencilAttachment=R,l.color=C.map(b),l.depth=b(P),l.stencil=b(I),l.depthStencil=b(R),l.width=i.width,l.height=i.height,E(i),l}function h(e,t){ne(u.next!==i,"can not resize a framebuffer which is currently in use");var n=Math.max(0|e,1),r=Math.max(0|t||n,1);if(n===i.width&&r===i.height)return l;for(var a=i.colorAttachments,o=0;o=2,"invalid shape for framebuffer"),ne(g[0]===g[1],"cube framebuffer must be square"),h=g[0]}else"radius"in b&&(h=0|b.radius),"width"in b?(h=0|b.width,"height"in b&&ne(b.height===h,"must be square")):"height"in b&&(h=0|b.height);("color"in b||"colors"in b)&&(d=b.color||b.colors,Array.isArray(d)&&ne(1===d.length||n.webgl_draw_buffers,"multiple render targets not supported")),d||("colorCount"in b&&(v=0|b.colorCount,ne(v>0,"invalid color buffer count")),"colorType"in b&&(ne.oneOf(b.colorType,c,"invalid color type"),p=b.colorType),"colorFormat"in b&&(m=b.colorFormat,ne.oneOf(b.colorFormat,s,"invalid color format for texture"))),"depth"in b&&(l.depth=b.depth),"stencil"in b&&(l.stencil=b.stencil),"depthStencil"in b&&(l.depthStencil=b.depthStencil)}else h=1;if(d)if(Array.isArray(d))for(f=[],r=0;r0&&(l.depth=i[0].depth,l.stencil=i[0].stencil,l.depthStencil=i[0].depthStencil),i[r]?i[r](l):i[r]=_(l)}return t(o,{width:h,height:h,color:f})}function f(e){var t,n=0|e;if(ne(n>0&&n<=r.maxCubeMapSize,"invalid radius for cube fbo"),n===o.width)return o;var a=o.color;for(t=0;t{for(var e=Object.keys(t),n=0;n=0,'invalid option for vao: "'+e[n]+'" valid options are '+qa)})),ne(Array.isArray(a),"attributes must be an array")}ne(a.length0,"must specify at least one attribute");var c={},l=r.attributes;l.length=a.length;for(var h=0;h=v.byteLength?d.subdata(v):(d.destroy(),r.buffers[h]=null)),r.buffers[h]||(d=r.buffers[h]=i.create(m,Ba,!1,!0)),p.buffer=i.getBuffer(d),p.size=0|p.buffer.dimension,p.normalized=!1,p.type=p.buffer.dtype,p.offset=0,p.stride=0,p.divisor=0,p.state=1,c[h]=1):i.getBuffer(m)?(p.buffer=i.getBuffer(m),p.size=0|p.buffer.dimension,p.normalized=!1,p.type=p.buffer.dtype,p.offset=0,p.stride=0,p.divisor=0,p.state=1):i.getBuffer(m.buffer)?(p.buffer=i.getBuffer(m.buffer),p.size=0|(+m.size||p.buffer.dimension),p.normalized=!!m.normalized||!1,"type"in m?(ne.parameter(m.type,Pt,"invalid buffer type"),p.type=Pt[m.type]):p.type=p.buffer.dtype,p.offset=0|(m.offset||0),p.stride=0|(m.stride||0),p.divisor=0|(m.divisor||0),p.state=1,ne(p.size>=1&&p.size<=4,"size must be between 1 and 4"),ne(p.offset>=0,"invalid offset"),ne(p.stride>=0&&p.stride<=255,"stride must be between 0 and 255"),ne(p.divisor>=0,"divisor must be positive"),ne(!p.divisor||!!n.angle_instanced_arrays,"ANGLE_instanced_arrays must be enabled to use divisor")):"x"in m?(ne(h>0,"first attribute must not be a constant"),p.x=+m.x||0,p.y=+m.y||0,p.z=+m.z||0,p.w=+m.w||0,p.state=2):ne(!1,"invalid attribute spec for location "+h)}for(var b=0;b1)for(var b=0;b1&&(y=y.replace("[0]","")),s(v,new u(y,n.id(y),e.getUniformLocation(d,y),c))}var x=e.getProgramParameter(d,Ha);a.profile&&(t.stats.attributesCount=x);var w=t.attributes;for(o=0;oe&&(e=t.stats.uniformsCount)})),e},r.getMaxAttributesCount=function(){var e=0;return l.forEach((function(t){t.stats.attributesCount>e&&(e=t.stats.attributesCount)})),e}),{clear:function(){var t=e.deleteShader.bind(e);Et(i).forEach(t),i={},Et(o).forEach(t),o={},l.forEach((function(t){e.deleteProgram(t.program)})),l.length=0,c={},r.shaderCount=0},program:function(n,a,u,s){ne.command(n>=0,"missing vertex shader",u),ne.command(a>=0,"missing fragment shader",u);var f=c[a];f||(f=c[a]={});var h=f[n];if(h&&(h.refCount++,!s))return h;var p=new d(a,n);return r.shaderCount++,m(p,u,s),h||(f[n]=p),l.push(p),t(p,{destroy:function(){if(p.refCount--,p.refCount<=0){e.deleteProgram(p.program);var t=l.indexOf(p);l.splice(t,1),r.shaderCount--}f[p.vertId].refCount<=0&&(e.deleteShader(o[p.vertId]),delete o[p.vertId],delete c[p.fragId][p.vertId]),Object.keys(c[p.fragId]).length||(e.deleteShader(i[p.fragId]),delete i[p.fragId],delete c[p.fragId])}})},restore:p,shader:f,frag:-1,vert:-1}}var Qa=6408,Ka=5121,$a=3333,Za=5126;function Ja(t,n,r,a,i,o,u){function s(s){var f;null===n.next?(ne(i.preserveDrawingBuffer,'you must create a webgl context with "preserveDrawingBuffer":true in order to read pixels from the drawing buffer'),f=Ka):(ne(null!==n.next.colorAttachments[0].texture,"You cannot read from a renderbuffer"),f=n.next.colorAttachments[0].texture._texture.type,ne.optional((function(){o.oes_texture_float?(ne(f===Ka||f===Za,"Reading from a framebuffer is only allowed for the types 'uint8' and 'float'"),f===Za&&ne(u.readFloat,"Reading 'float' values is not permitted in your browser. For a fallback, please see: https://www.npmjs.com/package/glsl-read-float")):ne(f===Ka,"Reading from a framebuffer is only allowed for the type 'uint8'")})));var c=0,l=0,h=a.framebufferWidth,d=a.framebufferHeight,m=null;e(s)?m=s:s&&(ne.type(s,"object","invalid arguments to regl.read()"),c=0|s.x,l=0|s.y,ne(c>=0&&c=0&&l0&&h+c<=a.framebufferWidth,"invalid width for read pixels"),ne(d>0&&d+l<=a.framebufferHeight,"invalid height for read pixels"),r();var p=h*d*4;return m||(f===Ka?m=new Uint8Array(p):f===Za&&(m=m||new Float32Array(p))),ne.isTypedArray(m,"data buffer for regl.read() must be a typedarray"),ne(m.byteLength>=p,"data buffer for regl.read() too small"),t.pixelStorei($a,4),t.readPixels(c,l,h,d,Qa,f,m),m}function f(e){var t;return n.setFBO({framebuffer:e.framebuffer},(function(){t=s(e)})),t}function c(e){return e&&"framebuffer"in e?f(e):s(e)}return c}function ei(e){return Array.prototype.slice.call(e)}function ti(e){return ei(e).join("")}function ni(){var e=0,n=[],r=[];function a(t){for(var a=0;a0&&(n.push(t,"="),n.push.apply(n,ei(arguments)),n.push(";")),t}return t(r,{def:i,toString:function(){return ti([a.length>0?"var "+a.join(",")+";":"",ti(n)])}})}function o(){var e=i(),n=i(),r=e.toString,a=n.toString;function o(t,r){n(t,r,"=",e.def(t,r),";")}return t((function(){e.apply(e,ei(arguments))}),{def:e.def,entry:e,exit:n,save:o,set:function(t,n,r){o(t,n),e(t,n,"=",r,";")},toString:function(){return r()+a()}})}function u(){var e=ti(arguments),n=o(),r=o(),a=n.toString,i=r.toString;return t(n,{then:function(){return n.apply(n,ei(arguments)),this},else:function(){return r.apply(r,ei(arguments)),this},toString:function(){var t=i();return t&&(t="else{"+t+"}"),ti(["if(",e,"){",a(),"}",t])}})}var s=i(),f={};function c(e,n){var r=[];function a(){var e="a"+r.length;return r.push(e),e}n=n||0;for(var i=0;i":516,notequal:517,"!=":517,"!==":517,gequal:518,">=":518,always:519},nu={0:0,zero:0,keep:7680,replace:7681,increment:7682,decrement:7683,"increment wrap":34055,"decrement wrap":34056,invert:5386},ru={frag:35632,vert:35633},au={cw:qo,ccw:No};function iu(t){return Array.isArray(t)||e(t)||At(t)}function ou(e){return e.sort((function(e,t){return e===Vi?-1:t===Vi?1:e=1,r>=2,t)}if(n===li){var a=e.data;return new uu(a.thisDep,a.contextDep,a.propDep,t)}if(n===hi)return new uu(!1,!1,!1,t);if(n===di){for(var i=!1,o=!1,u=!1,s=0;s=1&&(o=!0),c>=2&&(u=!0)}else f.type===li&&(i=i||f.data.thisDep,o=o||f.data.contextDep,u=u||f.data.propDep)}return new uu(i,o,u,t)}return new uu(n===ci,n===fi,n===si,t)}var lu=new uu(!1,!1,!1,(function(){}));function hu(e,n,r,a,i,o,u,s,f,c,l,h,d,m,p){var v=c.Record,b={add:32774,subtract:32778,"reverse subtract":32779};r.ext_blend_minmax&&(b.min=Yo,b.max=Uo);var g=r.angle_instanced_arrays,y=r.webgl_draw_buffers,x=r.oes_vertex_array_object,w={dirty:!0,profile:p.profile},M={},A=[],E={},_={};function S(e){return e.replace(".","_")}function T(e,t,n){var r=S(e);A.push(e),M[r]=w[r]=!!n,E[r]=t}function O(e,t,n){var r=S(e);A.push(e),Array.isArray(n)?(w[r]=n.slice(),M[r]=n.slice()):w[r]=M[r]=n,_[r]=t}T(mi,mo),T(pi,ho),O(vi,"blendColor",[0,0,0,0]),O(bi,"blendEquationSeparate",[Qo,Qo]),O(gi,"blendFuncSeparate",[Go,Ho,Go,Ho]),T(yi,vo,!0),O(xi,"depthFunc",Ko),O(wi,"depthRange",[0,1]),O(Mi,"depthMask",!0),O(Ai,Ai,[!0,!0,!0,!0]),T(Ei,lo),O(_i,"cullFace",Vo),O(Si,Si,No),O(Ti,Ti,1),T(Oi,go),O(ki,"polygonOffset",[0,0]),T(Di,yo),T(ji,xo),O(Ci,"sampleCoverage",[1,!1]),T(Pi,po),O(Ii,"stencilMask",-1),O(Ri,"stencilFunc",[Xo,0,-1]),O(Fi,"stencilOpSeparate",[Bo,Wo,Wo,Wo]),O(zi,"stencilOpSeparate",[Vo,Wo,Wo,Wo]),T(Li,bo),O(Bi,"scissor",[0,0,e.drawingBufferWidth,e.drawingBufferHeight]),O(Vi,Vi,[0,0,e.drawingBufferWidth,e.drawingBufferHeight]);var k={gl:e,context:d,strings:n,next:M,current:w,draw:h,elements:o,buffer:i,shader:l,attributes:c.state,vao:c,uniforms:f,framebuffer:s,extensions:r,timer:m,isBufferArgs:iu},D={primTypes:Wt,compareFuncs:tu,blendFuncs:Jo,blendEquations:b,stencilOps:nu,glTypes:Pt,orientationType:au};ne.optional((function(){k.isArrayLike=ln})),y&&(D.backBuffer=[Vo],D.drawBuffer=Se(a.maxDrawbuffers,(function(e){return 0===e?[0]:Se(e,(function(e){return Zo+e}))})));var j=0;function C(){var e=ni(),t=e.link,r=e.global;e.id=j++,e.batchId="0";var a=t(k),i=e.shared={props:"a0"};Object.keys(k).forEach((function(e){i[e]=r.def(a,".",e)})),ne.optional((function(){e.CHECK=t(ne),e.commandStr=ne.guessCommand(),e.command=t(e.commandStr),e.assert=function(e,n,r){e("if(!(",n,"))",this.CHECK,".commandRaise(",t(r),",",this.command,");")},D.invalidBlendCombinations=eu}));var o=e.next={},u=e.current={};Object.keys(_).forEach((function(e){Array.isArray(w[e])&&(o[e]=r.def(i.next,".",e),u[e]=r.def(i.current,".",e))}));var s=e.constants={};Object.keys(D).forEach((function(e){s[e]=r.def(JSON.stringify(D[e]))})),e.invoke=function(n,r){switch(r.type){case ui:var a=["this",i.context,i.props,e.batchId];return n.def(t(r.data),".call(",a.slice(0,Math.max(r.data.length+1,4)),")");case si:return n.def(i.props,r.data);case fi:return n.def(i.context,r.data);case ci:return n.def("this",r.data);case li:return r.data.append(e,n),r.data.ref;case hi:return r.data.toString();case di:return r.data.map((function(t){return e.invoke(n,t)}))}},e.attribCache={};var f={};return e.scopeAttrib=function(e){var r=n.id(e);if(r in f)return f[r];var a=c.scope[r];return a||(a=c.scope[r]=new v),f[r]=t(a)},e}function P(e){var t,n=e.static,r=e.dynamic;if(qi in n){var a=!!n[qi];(t=fu((function(e,t){return a}))).enable=a}else if(qi in r){var i=r[qi];t=cu(i,(function(e,t){return e.invoke(t,i)}))}return t}function I(e,t){var n=e.static,r=e.dynamic;if(Ni in n){var a=n[Ni];return a?(a=s.getFramebuffer(a),ne.command(a,"invalid framebuffer object"),fu((function(e,t){var n=e.link(a),r=e.shared;t.set(r.framebuffer,".next",n);var i=r.context;return t.set(i,"."+Ji,n+".width"),t.set(i,"."+eo,n+".height"),n}))):fu((function(e,t){var n=e.shared;t.set(n.framebuffer,".next","null");var r=n.context;return t.set(r,"."+Ji,r+"."+ao),t.set(r,"."+eo,r+"."+io),"null"}))}if(Ni in r){var i=r[Ni];return cu(i,(function(e,t){var n=e.invoke(t,i),r=e.shared,a=r.framebuffer,o=t.def(a,".getFramebuffer(",n,")");ne.optional((function(){e.assert(t,"!"+n+"||"+o,"invalid framebuffer object")})),t.set(a,".next",o);var u=r.context;return t.set(u,"."+Ji,o+"?"+o+".width:"+u+"."+ao),t.set(u,"."+eo,o+"?"+o+".height:"+u+"."+io),o}))}return null}function R(e,t,n){var r=e.static,a=e.dynamic;function i(e){if(e in r){var i=r[e];ne.commandType(i,"object","invalid "+e,n.commandStr);var o,u,s=!0,f=0|i.x,c=0|i.y;return"width"in i?(o=0|i.width,ne.command(o>=0,"invalid "+e,n.commandStr)):s=!1,"height"in i?(u=0|i.height,ne.command(u>=0,"invalid "+e,n.commandStr)):s=!1,new uu(!s&&t&&t.thisDep,!s&&t&&t.contextDep,!s&&t&&t.propDep,(function(e,t){var n=e.shared.context,r=o;"width"in i||(r=t.def(n,".",Ji,"-",f));var a=u;return"height"in i||(a=t.def(n,".",eo,"-",c)),[f,c,r,a]}))}if(e in a){var l=a[e],h=cu(l,(function(t,n){var r=t.invoke(n,l);ne.optional((function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)}));var a=t.shared.context,i=n.def(r,".x|0"),o=n.def(r,".y|0"),u=n.def('"width" in ',r,"?",r,".width|0:","(",a,".",Ji,"-",i,")"),s=n.def('"height" in ',r,"?",r,".height|0:","(",a,".",eo,"-",o,")");return ne.optional((function(){t.assert(n,u+">=0&&"+s+">=0","invalid "+e)})),[i,o,u,s]}));return t&&(h.thisDep=h.thisDep||t.thisDep,h.contextDep=h.contextDep||t.contextDep,h.propDep=h.propDep||t.propDep),h}return t?new uu(t.thisDep,t.contextDep,t.propDep,(function(e,t){var n=e.shared.context;return[0,0,t.def(n,".",Ji),t.def(n,".",eo)]})):null}var o=i(Vi);if(o){var u=o;o=new uu(o.thisDep,o.contextDep,o.propDep,(function(e,t){var n=u.append(e,t),r=e.shared.context;return t.set(r,"."+to,n[2]),t.set(r,"."+no,n[3]),n}))}return{viewport:o,scissor_box:i(Bi)}}function F(e,t){var n=e.static;if("string"==typeof n[Ui]&&"string"==typeof n[Yi]){if(Object.keys(t.dynamic).length>0)return null;var r=t.static,a=Object.keys(r);if(a.length>0&&"number"==typeof r[a[0]]){for(var i=[],o=0;o=0,"invalid "+e,t.commandStr),fu((function(e,t){return o&&(e.OFFSET=u),u}))}if(e in r){var c=r[e];return cu(c,(function(t,n){var r=t.invoke(n,c);return o&&(t.OFFSET=r,ne.optional((function(){t.assert(n,r+">=0","invalid "+e)}))),r}))}if(o){if(f)return fu((function(e,t){return e.OFFSET=0,0}));if(i)return new uu(s.thisDep,s.contextDep,s.propDep,(function(e,t){return t.def(e.shared.vao+".currentVAO?"+e.shared.vao+".currentVAO.offset:0")}))}else if(i)return new uu(s.thisDep,s.contextDep,s.propDep,(function(e,t){return t.def(e.shared.vao+".currentVAO?"+e.shared.vao+".currentVAO.instances:-1")}));return null}var p=m(Gi,!0);function v(){if(Hi in n){var e=0|n[Hi];return a.count=e,ne.command("number"==typeof e&&e>=0,"invalid vertex count",t.commandStr),fu((function(){return e}))}if(Hi in r){var o=r[Hi];return cu(o,(function(e,t){var n=e.invoke(t,o);return ne.optional((function(){e.assert(t,"typeof "+n+'==="number"&&'+n+">=0&&"+n+"===("+n+"|0)","invalid vertex count")})),n}))}if(f){if(su(h)){if(h)return p?new uu(p.thisDep,p.contextDep,p.propDep,(function(e,t){var n=t.def(e.ELEMENTS,".vertCount-",e.OFFSET);return ne.optional((function(){e.assert(t,n+">=0","invalid vertex offset/element buffer too small")})),n})):fu((function(e,t){return t.def(e.ELEMENTS,".vertCount")}));var u=fu((function(){return-1}));return ne.optional((function(){u.MISSING=!0})),u}var c=new uu(h.thisDep||p.thisDep,h.contextDep||p.contextDep,h.propDep||p.propDep,(function(e,t){var n=e.ELEMENTS;return e.OFFSET?t.def(n,"?",n,".vertCount-",e.OFFSET,":-1"):t.def(n,"?",n,".vertCount:-1")}));return ne.optional((function(){c.DYNAMIC=!0})),c}return i?new uu(s.thisDep,s.contextDep,s.propDep,(function(e,t){return t.def(e.shared.vao,".currentVAO?",e.shared.vao,".currentVAO.count:-1")})):null}var b=d(),g=v(),y=m(Qi,!1);return{elements:h,primitive:b,count:g,instances:y,offset:p,vao:s,vaoActive:i,elementsActive:f,static:a}}function B(e,t){var n=e.static,r=e.dynamic,i={};return A.forEach((function(e){var o=S(e);function u(t,a){if(e in n){var u=t(n[e]);i[o]=fu((function(){return u}))}else if(e in r){var s=r[e];i[o]=cu(s,(function(e,t){return a(e,t,e.invoke(t,s))}))}}switch(e){case Ei:case pi:case mi:case Pi:case yi:case Li:case Oi:case Di:case ji:case Mi:return u((function(n){return ne.commandType(n,"boolean",e,t.commandStr),n}),(function(t,n,r){return ne.optional((function(){t.assert(n,"typeof "+r+'==="boolean"',"invalid flag "+e,t.commandStr)})),r}));case xi:return u((function(n){return ne.commandParameter(n,tu,"invalid "+e,t.commandStr),tu[n]}),(function(t,n,r){var a=t.constants.compareFuncs;return ne.optional((function(){t.assert(n,r+" in "+a,"invalid "+e+", must be one of "+Object.keys(tu))})),n.def(a,"[",r,"]")}));case wi:return u((function(e){return ne.command(ln(e)&&2===e.length&&"number"==typeof e[0]&&"number"==typeof e[1]&&e[0]<=e[1],"depth range is 2d array",t.commandStr),e}),(function(e,t,n){return ne.optional((function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===2&&typeof "+n+'[0]==="number"&&typeof '+n+'[1]==="number"&&'+n+"[0]<="+n+"[1]","depth range must be a 2d array")})),[t.def("+",n,"[0]"),t.def("+",n,"[1]")]}));case gi:return u((function(e){ne.commandType(e,"object","blend.func",t.commandStr);var n="srcRGB"in e?e.srcRGB:e.src,r="srcAlpha"in e?e.srcAlpha:e.src,a="dstRGB"in e?e.dstRGB:e.dst,i="dstAlpha"in e?e.dstAlpha:e.dst;return ne.commandParameter(n,Jo,o+".srcRGB",t.commandStr),ne.commandParameter(r,Jo,o+".srcAlpha",t.commandStr),ne.commandParameter(a,Jo,o+".dstRGB",t.commandStr),ne.commandParameter(i,Jo,o+".dstAlpha",t.commandStr),ne.command(-1===eu.indexOf(n+", "+a),"unallowed blending combination (srcRGB, dstRGB) = ("+n+", "+a+")",t.commandStr),[Jo[n],Jo[a],Jo[r],Jo[i]]}),(function(t,n,r){var a=t.constants.blendFuncs;function i(i,o){var u=n.def('"',i,o,'" in ',r,"?",r,".",i,o,":",r,".",i);return ne.optional((function(){t.assert(n,u+" in "+a,"invalid "+e+"."+i+o+", must be one of "+Object.keys(Jo))})),u}ne.optional((function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid blend func, must be an object")}));var o=i("src","RGB"),u=i("dst","RGB");ne.optional((function(){var e=t.constants.invalidBlendCombinations;t.assert(n,e+".indexOf("+o+'+", "+'+u+") === -1 ","unallowed blending combination for (srcRGB, dstRGB)")}));var s=n.def(a,"[",o,"]"),f=n.def(a,"[",i("src","Alpha"),"]");return[s,n.def(a,"[",u,"]"),f,n.def(a,"[",i("dst","Alpha"),"]")]}));case bi:return u((function(n){return"string"==typeof n?(ne.commandParameter(n,b,"invalid "+e,t.commandStr),[b[n],b[n]]):"object"==typeof n?(ne.commandParameter(n.rgb,b,e+".rgb",t.commandStr),ne.commandParameter(n.alpha,b,e+".alpha",t.commandStr),[b[n.rgb],b[n.alpha]]):void ne.commandRaise("invalid blend.equation",t.commandStr)}),(function(t,n,r){var a=t.constants.blendEquations,i=n.def(),o=n.def(),u=t.cond("typeof ",r,'==="string"');return ne.optional((function(){function n(e,n,r){t.assert(e,r+" in "+a,"invalid "+n+", must be one of "+Object.keys(b))}n(u.then,e,r),t.assert(u.else,r+"&&typeof "+r+'==="object"',"invalid "+e),n(u.else,e+".rgb",r+".rgb"),n(u.else,e+".alpha",r+".alpha")})),u.then(i,"=",o,"=",a,"[",r,"];"),u.else(i,"=",a,"[",r,".rgb];",o,"=",a,"[",r,".alpha];"),n(u),[i,o]}));case vi:return u((function(e){return ne.command(ln(e)&&4===e.length,"blend.color must be a 4d array",t.commandStr),Se(4,(function(t){return+e[t]}))}),(function(e,t,n){return ne.optional((function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===4","blend.color must be a 4d array")})),Se(4,(function(e){return t.def("+",n,"[",e,"]")}))}));case Ii:return u((function(e){return ne.commandType(e,"number",o,t.commandStr),0|e}),(function(e,t,n){return ne.optional((function(){e.assert(t,"typeof "+n+'==="number"',"invalid stencil.mask")})),t.def(n,"|0")}));case Ri:return u((function(n){ne.commandType(n,"object",o,t.commandStr);var r=n.cmp||"keep",a=n.ref||0,i="mask"in n?n.mask:-1;return ne.commandParameter(r,tu,e+".cmp",t.commandStr),ne.commandType(a,"number",e+".ref",t.commandStr),ne.commandType(i,"number",e+".mask",t.commandStr),[tu[r],a,i]}),(function(e,t,n){var r=e.constants.compareFuncs;return ne.optional((function(){function a(){e.assert(t,Array.prototype.join.call(arguments,""),"invalid stencil.func")}a(n+"&&typeof ",n,'==="object"'),a('!("cmp" in ',n,")||(",n,".cmp in ",r,")")})),[t.def('"cmp" in ',n,"?",r,"[",n,".cmp]",":",Wo),t.def(n,".ref|0"),t.def('"mask" in ',n,"?",n,".mask|0:-1")]}));case Fi:case zi:return u((function(n){ne.commandType(n,"object",o,t.commandStr);var r=n.fail||"keep",a=n.zfail||"keep",i=n.zpass||"keep";return ne.commandParameter(r,nu,e+".fail",t.commandStr),ne.commandParameter(a,nu,e+".zfail",t.commandStr),ne.commandParameter(i,nu,e+".zpass",t.commandStr),[e===zi?Vo:Bo,nu[r],nu[a],nu[i]]}),(function(t,n,r){var a=t.constants.stencilOps;function i(i){return ne.optional((function(){t.assert(n,'!("'+i+'" in '+r+")||("+r+"."+i+" in "+a+")","invalid "+e+"."+i+", must be one of "+Object.keys(nu))})),n.def('"',i,'" in ',r,"?",a,"[",r,".",i,"]:",Wo)}return ne.optional((function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)})),[e===zi?Vo:Bo,i("fail"),i("zfail"),i("zpass")]}));case ki:return u((function(e){ne.commandType(e,"object",o,t.commandStr);var n=0|e.factor,r=0|e.units;return ne.commandType(n,"number",o+".factor",t.commandStr),ne.commandType(r,"number",o+".units",t.commandStr),[n,r]}),(function(t,n,r){return ne.optional((function(){t.assert(n,r+"&&typeof "+r+'==="object"',"invalid "+e)})),[n.def(r,".factor|0"),n.def(r,".units|0")]}));case _i:return u((function(e){var n=0;return"front"===e?n=Bo:"back"===e&&(n=Vo),ne.command(!!n,o,t.commandStr),n}),(function(e,t,n){return ne.optional((function(){e.assert(t,n+'==="front"||'+n+'==="back"',"invalid cull.face")})),t.def(n,'==="front"?',Bo,":",Vo)}));case Ti:return u((function(e){return ne.command("number"==typeof e&&e>=a.lineWidthDims[0]&&e<=a.lineWidthDims[1],"invalid line width, must be a positive number between "+a.lineWidthDims[0]+" and "+a.lineWidthDims[1],t.commandStr),e}),(function(e,t,n){return ne.optional((function(){e.assert(t,"typeof "+n+'==="number"&&'+n+">="+a.lineWidthDims[0]+"&&"+n+"<="+a.lineWidthDims[1],"invalid line width")})),n}));case Si:return u((function(e){return ne.commandParameter(e,au,o,t.commandStr),au[e]}),(function(e,t,n){return ne.optional((function(){e.assert(t,n+'==="cw"||'+n+'==="ccw"',"invalid frontFace, must be one of cw,ccw")})),t.def(n+'==="cw"?'+qo+":"+No)}));case Ai:return u((function(e){return ne.command(ln(e)&&4===e.length,"color.mask must be length 4 array",t.commandStr),e.map((function(e){return!!e}))}),(function(e,t,n){return ne.optional((function(){e.assert(t,e.shared.isArrayLike+"("+n+")&&"+n+".length===4","invalid color.mask")})),Se(4,(function(e){return"!!"+n+"["+e+"]"}))}));case Ci:return u((function(e){ne.command("object"==typeof e&&e,o,t.commandStr);var n="value"in e?e.value:1,r=!!e.invert;return ne.command("number"==typeof n&&n>=0&&n<=1,"sample.coverage.value must be a number between 0 and 1",t.commandStr),[n,r]}),(function(e,t,n){return ne.optional((function(){e.assert(t,n+"&&typeof "+n+'==="object"',"invalid sample.coverage")})),[t.def('"value" in ',n,"?+",n,".value:1"),t.def("!!",n,".invert")]}))}})),i}function V(e,t){var n=e.static,r=e.dynamic,a={};return Object.keys(n).forEach((function(e){var r,i=n[e];if("number"==typeof i||"boolean"==typeof i)r=fu((function(){return i}));else if("function"==typeof i){var o=i._reglType;"texture2d"===o||"textureCube"===o?r=fu((function(e){return e.link(i)})):"framebuffer"===o||"framebufferCube"===o?(ne.command(i.color.length>0,'missing color attachment for framebuffer sent to uniform "'+e+'"',t.commandStr),r=fu((function(e){return e.link(i.color[0])}))):ne.commandRaise('invalid data for uniform "'+e+'"',t.commandStr)}else ln(i)?r=fu((function(t){return t.global.def("[",Se(i.length,(function(n){return ne.command("number"==typeof i[n]||"boolean"==typeof i[n],"invalid uniform "+e,t.commandStr),i[n]})),"]")})):ne.commandRaise('invalid or missing data for uniform "'+e+'"',t.commandStr);r.value=i,a[e]=r})),Object.keys(r).forEach((function(e){var t=r[e];a[e]=cu(t,(function(e,n){return e.invoke(n,t)}))})),a}function q(e,t){var r=e.static,a=e.dynamic,o={};return Object.keys(r).forEach((function(e){var a=r[e],u=n.id(e),s=new v;if(iu(a))s.state=ii,s.buffer=i.getBuffer(i.create(a,uo,!1,!0)),s.type=0;else{var f=i.getBuffer(a);if(f)s.state=ii,s.buffer=f,s.type=0;else if(ne.command("object"==typeof a&&a,"invalid data for attribute "+e,t.commandStr),"constant"in a){var c=a.constant;s.buffer="null",s.state=oi,"number"==typeof c?s.x=c:(ne.command(ln(c)&&c.length>0&&c.length<=4,"invalid constant for attribute "+e,t.commandStr),ri.forEach((function(e,t){t=0,'invalid offset for attribute "'+e+'"',t.commandStr);var h=0|a.stride;ne.command(h>=0&&h<256,'invalid stride for attribute "'+e+'", must be integer betweeen [0, 255]',t.commandStr);var d=0|a.size;ne.command(!("size"in a)||d>0&&d<=4,'invalid size for attribute "'+e+'", must be 1,2,3,4',t.commandStr);var m=!!a.normalized,p=0;"type"in a&&(ne.commandParameter(a.type,Pt,"invalid type for attribute "+e,t.commandStr),p=Pt[a.type]);var b=0|a.divisor;ne.optional((function(){"divisor"in a&&(ne.command(0===b||g,'cannot specify divisor for attribute "'+e+'", instancing not supported',t.commandStr),ne.command(b>=0,'invalid divisor for attribute "'+e+'"',t.commandStr));var n=t.commandStr,r=["buffer","offset","divisor","normalized","type","size","stride"];Object.keys(a).forEach((function(t){ne.command(r.indexOf(t)>=0,'unknown parameter "'+t+'" for attribute pointer "'+e+'" (valid parameters are '+r+")",n)}))})),s.buffer=f,s.state=ii,s.size=d,s.normalized=m,s.type=p||f.dtype,s.offset=l,s.stride=h,s.divisor=b}}o[e]=fu((function(e,t){var n=e.attribCache;if(u in n)return n[u];var r={isStream:!1};return Object.keys(s).forEach((function(e){r[e]=s[e]})),s.buffer&&(r.buffer=e.link(s.buffer),r.type=r.type||r.buffer+".dtype"),n[u]=r,r}))})),Object.keys(a).forEach((function(e){var t=a[e];function n(n,r){var a=n.invoke(r,t),i=n.shared,o=n.constants,u=i.isBufferArgs,s=i.buffer;ne.optional((function(){n.assert(r,a+"&&(typeof "+a+'==="object"||typeof '+a+'==="function")&&('+u+"("+a+")||"+s+".getBuffer("+a+")||"+s+".getBuffer("+a+".buffer)||"+u+"("+a+'.buffer)||("constant" in '+a+"&&(typeof "+a+'.constant==="number"||'+i.isArrayLike+"("+a+".constant))))",'invalid dynamic attribute "'+e+'"')}));var f={isStream:r.def(!1)},c=new v;c.state=ii,Object.keys(c).forEach((function(e){f[e]=r.def(""+c[e])}));var l=f.buffer,h=f.type;function d(e){r(f[e],"=",a,".",e,"|0;")}return r("if(",u,"(",a,")){",f.isStream,"=true;",l,"=",s,".createStream(",uo,",",a,");",h,"=",l,".dtype;","}else{",l,"=",s,".getBuffer(",a,");","if(",l,"){",h,"=",l,".dtype;",'}else if("constant" in ',a,"){",f.state,"=",oi,";","if(typeof "+a+'.constant === "number"){',f[ri[0]],"=",a,".constant;",ri.slice(1).map((function(e){return f[e]})).join("="),"=0;","}else{",ri.map((function(e,t){return f[e]+"="+a+".constant.length>"+t+"?"+a+".constant["+t+"]:0;"})).join(""),"}}else{","if(",u,"(",a,".buffer)){",l,"=",s,".createStream(",uo,",",a,".buffer);","}else{",l,"=",s,".getBuffer(",a,".buffer);","}",h,'="type" in ',a,"?",o.glTypes,"[",a,".type]:",l,".dtype;",f.normalized,"=!!",a,".normalized;"),d("size"),d("offset"),d("stride"),d("divisor"),r("}}"),r.exit("if(",f.isStream,"){",s,".destroyStream(",l,");","}"),f}o[e]=cu(t,n)})),o}function N(e){var t=e.static,n=e.dynamic,r={};return Object.keys(t).forEach((function(e){var n=t[e];r[e]=fu((function(e,t){return"number"==typeof n||"boolean"==typeof n?""+n:e.link(n)}))})),Object.keys(n).forEach((function(e){var t=n[e];r[e]=cu(t,(function(e,n){return e.invoke(n,t)}))})),r}function Y(e,t,n,a,i){var o=e.static,u=e.dynamic;ne.optional((function(){var e=[Ni,Yi,Ui,Xi,Wi,Gi,Hi,Qi,qi,Ki].concat(A);function t(t){Object.keys(t).forEach((function(t){ne.command(e.indexOf(t)>=0,'unknown parameter "'+t+'"',i.commandStr)}))}t(o),t(u)}));var s=F(e,t),f=I(e),l=R(e,f,i),h=L(e,i),d=B(e,i),m=z(e,i,s);function p(e){var t=l[e];t&&(d[e]=t)}p(Vi),p(S(Bi));var v=Object.keys(d).length>0,b={framebuffer:f,draw:h,shader:m,state:d,dirty:v,scopeVAO:null,drawVAO:null,useVAO:!1,attributes:{}};if(b.profile=P(e),b.uniforms=V(n,i),b.drawVAO=b.scopeVAO=h.vao,!b.drawVAO&&m.program&&!s&&r.angle_instanced_arrays&&h.static.elements){var g=!0,y=m.program.attributes.map((function(e){var n=t.static[e];return g=g&&!!n,n}));if(g&&y.length>0){var x=c.getVAO(c.createVAO({attributes:y,elements:h.static.elements}));b.drawVAO=new uu(null,null,null,(function(e,t){return e.link(x)})),b.useVAO=!0}}return s?b.useVAO=!0:b.attributes=q(t,i),b.context=N(a),b}function U(e,t,n){var r=e.shared.context,a=e.scope();Object.keys(n).forEach((function(i){t.save(r,"."+i);var o=n[i].append(e,t);Array.isArray(o)?a(r,".",i,"=[",o.join(),"];"):a(r,".",i,"=",o,";")})),t(a)}function X(e,t,n,r){var a,i=e.shared,o=i.gl,u=i.framebuffer;y&&(a=t.def(i.extensions,".webgl_draw_buffers"));var s,f=e.constants,c=f.drawBuffer,l=f.backBuffer;s=n?n.append(e,t):t.def(u,".next"),r||t("if(",s,"!==",u,".cur){"),t("if(",s,"){",o,".bindFramebuffer(",$o,",",s,".framebuffer);"),y&&t(a,".drawBuffersWEBGL(",c,"[",s,".colorAttachments.length]);"),t("}else{",o,".bindFramebuffer(",$o,",null);"),y&&t(a,".drawBuffersWEBGL(",l,");"),t("}",u,".cur=",s,";"),r||t("}")}function W(e,t,n){var r=e.shared,a=r.gl,i=e.current,o=e.next,u=r.current,s=r.next,f=e.cond(u,".dirty");A.forEach((function(t){var r,c,l=S(t);if(!(l in n.state))if(l in o){r=o[l],c=i[l];var h=Se(w[l].length,(function(e){return f.def(r,"[",e,"]")}));f(e.cond(h.map((function(e,t){return e+"!=="+c+"["+t+"]"})).join("||")).then(a,".",_[l],"(",h,");",h.map((function(e,t){return c+"["+t+"]="+e})).join(";"),";"))}else{r=f.def(s,".",l);var d=e.cond(r,"!==",u,".",l);f(d),l in E?d(e.cond(r).then(a,".enable(",E[l],");").else(a,".disable(",E[l],");"),u,".",l,"=",r,";"):d(a,".",_[l],"(",r,");",u,".",l,"=",r,";")}})),0===Object.keys(n.state).length&&f(u,".dirty=false;"),t(f)}function H(e,t,n,r){var a=e.shared,i=e.current,o=a.current,u=a.gl;ou(Object.keys(n)).forEach((function(a){var s=n[a];if(!r||r(s)){var f=s.append(e,t);if(E[a]){var c=E[a];su(s)?t(u,f?".enable(":".disable(",c,");"):t(e.cond(f).then(u,".enable(",c,");").else(u,".disable(",c,");")),t(o,".",a,"=",f,";")}else if(ln(f)){var l=i[a];t(u,".",_[a],"(",f,");",f.map((function(e,t){return l+"["+t+"]="+e})).join(";"),";")}else t(u,".",_[a],"(",f,");",o,".",a,"=",f,";")}}))}function G(e,t){g&&(e.instancing=t.def(e.shared.extensions,".angle_instanced_arrays"))}function Q(e,t,n,r,a){var i,o,u,s=e.shared,f=e.stats,c=s.current,l=s.timer,h=n.profile;function d(){return"undefined"==typeof performance?"Date.now()":"performance.now()"}function p(e){e(i=t.def(),"=",d(),";"),"string"==typeof a?e(f,".count+=",a,";"):e(f,".count++;"),m&&(r?e(o=t.def(),"=",l,".getNumPendingQueries();"):e(l,".beginQuery(",f,");"))}function v(e){e(f,".cpuTime+=",d(),"-",i,";"),m&&(r?e(l,".pushScopeStats(",o,",",l,".getNumPendingQueries(),",f,");"):e(l,".endQuery();"))}function b(e){var n=t.def(c,".profile");t(c,".profile=",e,";"),t.exit(c,".profile=",n,";")}if(h){if(su(h))return void(h.enable?(p(t),v(t.exit),b("true")):b("false"));b(u=h.append(e,t))}else u=t.def(c,".profile");var g=e.block();p(g),t("if(",u,"){",g,"}");var y=e.block();v(y),t.exit("if(",u,"){",y,"}")}function K(e,t,n,r,a){var i=e.shared;function o(e){switch(e){case Mo:case So:case Do:return 2;case Ao:case To:case jo:return 3;case Eo:case Oo:case Co:return 4;default:return 1}}function u(n,r,a){var o=i.gl,u=t.def(n,".location"),s=t.def(i.attributes,"[",u,"]"),f=a.state,c=a.buffer,l=[a.x,a.y,a.z,a.w],h=["buffer","normalized","offset","stride"];function d(){t("if(!",s,".buffer){",o,".enableVertexAttribArray(",u,");}");var n,i=a.type;if(n=a.size?t.def(a.size,"||",r):r,t("if(",s,".type!==",i,"||",s,".size!==",n,"||",h.map((function(e){return s+"."+e+"!=="+a[e]})).join("||"),"){",o,".bindBuffer(",uo,",",c,".buffer);",o,".vertexAttribPointer(",[u,n,i,a.normalized,a.stride,a.offset],");",s,".type=",i,";",s,".size=",n,";",h.map((function(e){return s+"."+e+"="+a[e]+";"})).join(""),"}"),g){var f=a.divisor;t("if(",s,".divisor!==",f,"){",e.instancing,".vertexAttribDivisorANGLE(",[u,f],");",s,".divisor=",f,";}")}}function m(){t("if(",s,".buffer){",o,".disableVertexAttribArray(",u,");",s,".buffer=null;","}if(",ri.map((function(e,t){return s+"."+e+"!=="+l[t]})).join("||"),"){",o,".vertexAttrib4f(",u,",",l,");",ri.map((function(e,t){return s+"."+e+"="+l[t]+";"})).join(""),"}")}f===ii?d():f===oi?m():(t("if(",f,"===",ii,"){"),d(),t("}else{"),m(),t("}"))}r.forEach((function(r){var i,s=r.name,f=n.attributes[s];if(f){if(!a(f))return;i=f.append(e,t)}else{if(!a(lu))return;var c=e.scopeAttrib(s);ne.optional((function(){e.assert(t,c+".state","missing attribute "+s)})),i={},Object.keys(new v).forEach((function(e){i[e]=t.def(c,".",e)}))}u(e.link(r),o(r.info.type),i)}))}function $(e,t,r,a,i,o){for(var u,s=e.shared,f=s.gl,c={},l=0;l1){if(!v)continue;var b=d.replace("[0]","");if(c[b])continue;c[b]=1}var g,y=e.link(h)+".location";if(v){if(!i(v))continue;if(su(v)){var x=v.value;if(ne.command(null!=x,'missing uniform "'+d+'"',e.commandStr),m===Fo||m===zo){ne.command("function"==typeof x&&(m===Fo&&("texture2d"===x._reglType||"framebuffer"===x._reglType)||m===zo&&("textureCube"===x._reglType||"framebufferCube"===x._reglType)),"invalid texture for uniform "+d,e.commandStr);var w=e.link(x._texture||x.color[0]._texture);t(f,".uniform1i(",y,",",w+".bind());"),t.exit(w,".unbind();")}else if(m===Po||m===Io||m===Ro){ne.optional((function(){ne.command(ln(x),"invalid matrix for uniform "+d,e.commandStr),ne.command(m===Po&&4===x.length||m===Io&&9===x.length||m===Ro&&16===x.length,"invalid length for matrix uniform "+d,e.commandStr)}));var M=e.global.def("new Float32Array(["+Array.prototype.slice.call(x)+"])"),A=2;m===Io?A=3:m===Ro&&(A=4),t(f,".uniformMatrix",A,"fv(",y,",false,",M,");")}else{switch(m){case wo:1===p?ne.commandType(x,"number","uniform "+d,e.commandStr):ne.command(ln(x)&&x.length===p,"uniform "+d,e.commandStr),u="1f";break;case Mo:ne.command(ln(x)&&x.length&&x.length%2==0&&x.length<=2*p,"uniform "+d,e.commandStr),u="2f";break;case Ao:ne.command(ln(x)&&x.length&&x.length%3==0&&x.length<=3*p,"uniform "+d,e.commandStr),u="3f";break;case Eo:ne.command(ln(x)&&x.length&&x.length%4==0&&x.length<=4*p,"uniform "+d,e.commandStr),u="4f";break;case ko:1===p?ne.commandType(x,"boolean","uniform "+d,e.commandStr):ne.command(ln(x)&&x.length===p,"uniform "+d,e.commandStr),u="1i";break;case _o:1===p?ne.commandType(x,"number","uniform "+d,e.commandStr):ne.command(ln(x)&&x.length===p,"uniform "+d,e.commandStr),u="1i";break;case Do:case So:ne.command(ln(x)&&x.length&&x.length%2==0&&x.length<=2*p,"uniform "+d,e.commandStr),u="2i";break;case jo:case To:ne.command(ln(x)&&x.length&&x.length%3==0&&x.length<=3*p,"uniform "+d,e.commandStr),u="3i";break;case Co:case Oo:ne.command(ln(x)&&x.length&&x.length%4==0&&x.length<=4*p,"uniform "+d,e.commandStr),u="4i"}p>1?(u+="v",x=e.global.def("["+Array.prototype.slice.call(x)+"]")):x=ln(x)?Array.prototype.slice.call(x):x,t(f,".uniform",u,"(",y,",",x,");")}continue}g=v.append(e,t)}else{if(!i(lu))continue;g=t.def(s.uniforms,"[",n.id(d),"]")}m===Fo?(ne(!Array.isArray(g),"must specify a scalar prop for textures"),t("if(",g,"&&",g,'._reglType==="framebuffer"){',g,"=",g,".color[0];","}")):m===zo&&(ne(!Array.isArray(g),"must specify a scalar prop for cube maps"),t("if(",g,"&&",g,'._reglType==="framebufferCube"){',g,"=",g,".color[0];","}")),ne.optional((function(){function n(n,r){e.assert(t,n,'bad data or missing for uniform "'+d+'". '+r)}function r(e,t){1===t&&ne(!Array.isArray(g),"must not specify an array type for uniform"),n("Array.isArray("+g+") && typeof "+g+'[0]===" '+e+'" || typeof '+g+'==="'+e+'"',"invalid type, expected "+e)}function a(t,r,a){Array.isArray(g)?ne(g.length&&g.length%t==0&&g.length<=t*a,"must have length of "+(1===a?"":"n * ")+t):n(s.isArrayLike+"("+g+")&&"+g+".length && "+g+".length % "+t+" === 0 && "+g+".length<="+t*a,"invalid vector, should have length of "+(1===a?"":"n * ")+t,e.commandStr)}function i(t){ne(!Array.isArray(g),"must not specify a value type"),n("typeof "+g+'==="function"&&'+g+'._reglType==="texture'+(t===fo?"2d":"Cube")+'"',"invalid texture type",e.commandStr)}switch(m){case _o:r("number",p);break;case So:a(2,"number",p);break;case To:a(3,"number",p);break;case Oo:a(4,"number",p);break;case wo:r("number",p);break;case Mo:a(2,"number",p);break;case Ao:a(3,"number",p);break;case Eo:a(4,"number",p);break;case ko:r("boolean",p);break;case Do:a(2,"boolean",p);break;case jo:a(3,"boolean",p);break;case Co:a(4,"boolean",p);break;case Po:a(4,"number",p);break;case Io:a(9,"number",p);break;case Ro:a(16,"number",p);break;case Fo:i(fo);break;case zo:i(co)}}));var E=1;switch(m){case Fo:case zo:var _=t.def(g,"._texture");t(f,".uniform1i(",y,",",_,".bind());"),t.exit(_,".unbind();");continue;case _o:case ko:u="1i";break;case So:case Do:u="2i",E=2;break;case To:case jo:u="3i",E=3;break;case Oo:case Co:u="4i",E=4;break;case wo:u="1f";break;case Mo:u="2f",E=2;break;case Ao:u="3f",E=3;break;case Eo:u="4f",E=4;break;case Po:u="Matrix2fv";break;case Io:u="Matrix3fv";break;case Ro:u="Matrix4fv"}if(-1===u.indexOf("Matrix")&&p>1&&(u+="v",E=1),"M"===u.charAt(0)){t(f,".uniform",u,"(",y,",");var S=Math.pow(m-Po+2,2),T=e.global.def("new Float32Array(",S,")");Array.isArray(g)?t("false,(",Se(S,(function(e){return T+"["+e+"]="+g[e]})),",",T,")"):t("false,(Array.isArray(",g,")||",g," instanceof Float32Array)?",g,":(",Se(S,(function(e){return T+"["+e+"]="+g+"["+e+"]"})),",",T,")"),t(");")}else if(E>1){for(var O=[],k=[],D=0;D=0","missing vertex count")}))):(a=s.def(o,".",Hi),ne.optional((function(){e.assert(s,a+">=0","missing vertex count")}))),a}var c=s();function l(a){var i=u[a];return i?i.contextDep&&r.contextDynamic||i.propDep?i.append(e,n):i.append(e,t):t.def(o,".",a)}var h,d,m=l(Wi),p=l(Gi),v=f();if("number"==typeof v){if(0===v)return}else n("if(",v,"){"),n.exit("}");g&&(h=l(Qi),d=e.instancing);var b=c+".type",y=u.elements&&su(u.elements)&&!u.vaoActive;function w(){function e(){n(d,".drawElementsInstancedANGLE(",[m,v,b,p+"<<(("+b+"-"+ai+")>>1)",h],");")}function t(){n(d,".drawArraysInstancedANGLE(",[m,p,v,h],");")}c&&"null"!==c?y?e():(n("if(",c,"){"),e(),n("}else{"),t(),n("}")):t()}function M(){function e(){n(i+".drawElements("+[m,v,b,p+"<<(("+b+"-"+ai+")>>1)"]+");")}function t(){n(i+".drawArrays("+[m,p,v]+");")}c&&"null"!==c?y?e():(n("if(",c,"){"),e(),n("}else{"),t(),n("}")):t()}g&&("number"!=typeof h||h>=0)?"string"==typeof h?(n("if(",h,">0){"),w(),n("}else if(",h,"<0){"),M(),n("}")):w():M()}function J(e,t,n,r,a){var i=C(),o=i.proc("body",a);return ne.optional((function(){i.commandStr=t.commandStr,i.command=i.link(t.commandStr)})),g&&(i.instancing=o.def(i.shared.extensions,".angle_instanced_arrays")),e(i,o,n,r),i.compile().body}function ee(e,t,n,r){G(e,t),n.useVAO?n.drawVAO?t(e.shared.vao,".setVAO(",n.drawVAO.append(e,t),");"):t(e.shared.vao,".setVAO(",e.shared.vao,".targetVAO);"):(t(e.shared.vao,".setVAO(null);"),K(e,t,n,r.attributes,(function(){return!0}))),$(e,t,n,r.uniforms,(function(){return!0}),!1),Z(e,t,t,n)}function te(e,t){var n=e.proc("draw",1);G(e,n),U(e,n,t.context),X(e,n,t.framebuffer),W(e,n,t),H(e,n,t.state),Q(e,n,t,!1,!0);var r=t.shader.progVar.append(e,n);if(n(e.shared.gl,".useProgram(",r,".program);"),t.shader.program)ee(e,n,t,t.shader.program);else{n(e.shared.vao,".setVAO(null);");var a=e.global.def("{}"),i=n.def(r,".id"),o=n.def(a,"[",i,"]");n(e.cond(o).then(o,".call(this,a0);").else(o,"=",a,"[",i,"]=",e.link((function(n){return J(ee,e,t,n,1)})),"(",r,");",o,".call(this,a0);"))}Object.keys(t.state).length>0&&n(e.shared.current,".dirty=true;"),e.shared.vao&&n(e.shared.vao,".setVAO(null);")}function re(e,t,n,r){function a(){return!0}e.batchId="a1",G(e,t),K(e,t,n,r.attributes,a),$(e,t,n,r.uniforms,a,!1),Z(e,t,t,n)}function ae(e,t,n,r){G(e,t);var a=n.contextDep,i=t.def(),o="a0",u="a1",s=t.def();e.shared.props=s,e.batchId=i;var f=e.scope(),c=e.scope();function l(e){return e.contextDep&&a||e.propDep}function h(e){return!l(e)}if(t(f.entry,"for(",i,"=0;",i,"<",u,";++",i,"){",s,"=",o,"[",i,"];",c,"}",f.exit),n.needsContext&&U(e,c,n.context),n.needsFramebuffer&&X(e,c,n.framebuffer),H(e,c,n.state,l),n.profile&&l(n.profile)&&Q(e,c,n,!1,!0),r)n.useVAO?n.drawVAO?l(n.drawVAO)?c(e.shared.vao,".setVAO(",n.drawVAO.append(e,c),");"):f(e.shared.vao,".setVAO(",n.drawVAO.append(e,f),");"):f(e.shared.vao,".setVAO(",e.shared.vao,".targetVAO);"):(f(e.shared.vao,".setVAO(null);"),K(e,f,n,r.attributes,h),K(e,c,n,r.attributes,l)),$(e,f,n,r.uniforms,h,!1),$(e,c,n,r.uniforms,l,!0),Z(e,f,c,n);else{var d=e.global.def("{}"),m=n.shader.progVar.append(e,c),p=c.def(m,".id"),v=c.def(d,"[",p,"]");c(e.shared.gl,".useProgram(",m,".program);","if(!",v,"){",v,"=",d,"[",p,"]=",e.link((function(t){return J(re,e,n,t,2)})),"(",m,");}",v,".call(this,a0[",i,"],",i,");")}}function ie(e,t){var n=e.proc("batch",2);e.batchId="0",G(e,n);var r=!1,a=!0;Object.keys(t.context).forEach((function(e){r=r||t.context[e].propDep})),r||(U(e,n,t.context),a=!1);var i=t.framebuffer,o=!1;function u(e){return e.contextDep&&r||e.propDep}i?(i.propDep?r=o=!0:i.contextDep&&r&&(o=!0),o||X(e,n,i)):X(e,n,null),t.state.viewport&&t.state.viewport.propDep&&(r=!0),W(e,n,t),H(e,n,t.state,(function(e){return!u(e)})),t.profile&&u(t.profile)||Q(e,n,t,!1,"a1"),t.contextDep=r,t.needsContext=a,t.needsFramebuffer=o;var s=t.shader.progVar;if(s.contextDep&&r||s.propDep)ae(e,n,t,null);else{var f=s.append(e,n);if(n(e.shared.gl,".useProgram(",f,".program);"),t.shader.program)ae(e,n,t,t.shader.program);else{n(e.shared.vao,".setVAO(null);");var c=e.global.def("{}"),l=n.def(f,".id"),h=n.def(c,"[",l,"]");n(e.cond(h).then(h,".call(this,a0,a1);").else(h,"=",c,"[",l,"]=",e.link((function(n){return J(ae,e,t,n,2)})),"(",f,");",h,".call(this,a0,a1);"))}}Object.keys(t.state).length>0&&n(e.shared.current,".dirty=true;"),e.shared.vao&&n(e.shared.vao,".setVAO(null);")}function oe(e,t){var r=e.proc("scope",3);e.batchId="a2";var a=e.shared,i=a.current;function o(n){var i=t.shader[n];i&&r.set(a.shader,"."+n,i.append(e,r))}U(e,r,t.context),t.framebuffer&&t.framebuffer.append(e,r),ou(Object.keys(t.state)).forEach((function(n){var i=t.state[n].append(e,r);ln(i)?i.forEach((function(t,a){r.set(e.next[n],"["+a+"]",t)})):r.set(a.next,"."+n,i)})),Q(e,r,t,!0,!0),[Xi,Gi,Hi,Qi,Wi].forEach((function(n){var i=t.draw[n];i&&r.set(a.draw,"."+n,""+i.append(e,r))})),Object.keys(t.uniforms).forEach((function(i){var o=t.uniforms[i].append(e,r);Array.isArray(o)&&(o="["+o.join()+"]"),r.set(a.uniforms,"["+n.id(i)+"]",o)})),Object.keys(t.attributes).forEach((function(n){var a=t.attributes[n].append(e,r),i=e.scopeAttrib(n);Object.keys(new v).forEach((function(e){r.set(i,"."+e,a[e])}))})),t.scopeVAO&&r.set(a.vao,".targetVAO",t.scopeVAO.append(e,r)),o(Yi),o(Ui),Object.keys(t.state).length>0&&(r(i,".dirty=true;"),r.exit(i,".dirty=true;")),r("a1(",e.shared.context,",a0,",e.batchId,");")}function ue(e){if("object"==typeof e&&!ln(e)){for(var t=Object.keys(e),n=0;n=0;--e){var t=D[e];t&&t(m,null,0)}r.flush(),c&&c.update()}function F(){!I&&D.length>0&&(I=pe.next(R))}function z(){I&&(pe.cancel(R),I=null)}function L(e){e.preventDefault(),i=!0,z(),j.forEach((function(e){e()}))}function B(e){r.getError(),i=!1,o.restore(),M.restore(),g.restore(),A.restore(),E.restore(),_.restore(),x.restore(),c&&c.restore(),S.procs.refresh(),F(),C.forEach((function(e){e()}))}function V(){D.length=0,z(),k&&(k.removeEventListener(Mu,L),k.removeEventListener(Au,B)),M.clear(),_.clear(),E.clear(),x.clear(),A.clear(),y.clear(),g.clear(),c&&c.clear(),P.forEach((function(e){e()}))}function q(e){function n(e){var n=t({},e);function r(e){if(e in n){var t=n[e];delete n[e],Object.keys(t).forEach((function(r){n[e+"."+r]=t[r]}))}}return delete n.uniforms,delete n.attributes,delete n.context,delete n.vao,"stencil"in n&&n.stencil.op&&(n.stencil.opBack=n.stencil.opFront=n.stencil.op,delete n.stencil.op),r("blend"),r("depth"),r("cull"),r("stencil"),r("polygonOffset"),r("scissor"),r("sample"),"vao"in e&&(n.vao=e.vao),n}function r(e,t){var n={},r={};return Object.keys(e).forEach((function(a){var i=e[a];if(me.isDynamic(i))r[a]=me.unbox(i,a);else{if(t&&Array.isArray(i))for(var o=0;o0)return h.call(this,p(0|e),0|e)}else{if(!Array.isArray(e))return l.call(this,e);if(e.length)return h.call(this,e,e.length)}}return t(v,{stats:f,destroy:function(){c.destroy()}})}k&&(k.addEventListener(Mu,L,!1),k.addEventListener(Au,B,!1));var N=_.setFBO=q({framebuffer:me.define.call(null,Eu,"framebuffer")});function Y(e,t){var n=0;S.procs.poll();var a=t.color;a&&(r.clearColor(+a[0]||0,+a[1]||0,+a[2]||0,+a[3]||0),n|=gu),"depth"in t&&(r.clearDepth(+t.depth),n|=yu),"stencil"in t&&(r.clearStencil(0|t.stencil),n|=xu),ne(!!n,"called regl.clear with no buffer specified"),r.clear(n)}function U(e){if(ne("object"==typeof e&&e,"regl.clear() takes an object as input"),"framebuffer"in e)if(e.framebuffer&&"framebufferCube"===e.framebuffer_reglType)for(var n=0;n<6;++n)N(t({framebuffer:e.framebuffer.faces[n]},e),Y);else N(e,Y);else Y(null,e)}function X(e){function t(){var t=Tu(D,e);function n(){var e=Tu(D,n);D[e]=D[D.length-1],D.length-=1,D.length<=0&&z()}ne(t>=0,"cannot cancel a frame twice"),D[t]=n}return ne.type(e,"function","regl.frame() callback must be a function"),D.push(e),F(),{cancel:t}}function W(){var e=O.viewport,t=O.scissor_box;e[0]=e[1]=t[0]=t[1]=0,m.viewportWidth=m.framebufferWidth=m.drawingBufferWidth=e[2]=t[2]=r.drawingBufferWidth,m.viewportHeight=m.framebufferHeight=m.drawingBufferHeight=e[3]=t[3]=r.drawingBufferHeight}function H(){m.tick+=1,m.time=Q(),W(),S.procs.poll()}function G(){A.refresh(),W(),S.procs.refresh(),c&&c.update()}function Q(){return(ve()-l)/1e3}function K(e,t){var n;switch(ne.type(t,"function","listener callback must be a function"),e){case"frame":return X(t);case"lost":n=j;break;case"restore":n=C;break;case"destroy":n=P;break;default:ne.raise("invalid event, must be one of frame,lost,restore,destroy")}return n.push(t),{cancel:function(){for(var e=0;e=0},read:T,destroy:V,_gl:r,_refresh:G,poll:function(){H(),c&&c.update()},now:Q,stats:s});return n.onDone(null,$),$}return Ou}(),r="undefined"!=typeof Float32Array?Float32Array:Array;function a(){var e=new r(16);return r!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e}function i(e,t,n,r,a){var i,o=1/Math.tan(t/2);return e[0]=o/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,null!=a&&a!==1/0?(i=1/(r-a),e[10]=(a+r)*i,e[14]=2*a*r*i):(e[10]=-1,e[14]=-2*r),e}function o(e,t,n,r){var a,i,o,u,s,f,c,l,h,d,m=t[0],p=t[1],v=t[2],b=r[0],g=r[1],y=r[2],x=n[0],w=n[1],M=n[2];return Math.abs(m-x)<1e-6&&Math.abs(p-w)<1e-6&&Math.abs(v-M)<1e-6?function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(e):(c=m-x,l=p-w,h=v-M,a=g*(h*=d=1/Math.hypot(c,l,h))-y*(l*=d),i=y*(c*=d)-b*h,o=b*l-g*c,(d=Math.hypot(a,i,o))?(a*=d=1/d,i*=d,o*=d):(a=0,i=0,o=0),u=l*o-h*i,s=h*a-c*o,f=c*i-l*a,(d=Math.hypot(u,s,f))?(u*=d=1/d,s*=d,f*=d):(u=0,s=0,f=0),e[0]=a,e[1]=u,e[2]=c,e[3]=0,e[4]=i,e[5]=s,e[6]=l,e[7]=0,e[8]=o,e[9]=f,e[10]=h,e[11]=0,e[12]=-(a*m+i*p+o*v),e[13]=-(u*m+s*p+f*v),e[14]=-(c*m+l*p+h*v),e[15]=1,e)}function u(){var e=new r(3);return r!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function s(e){var t=new r(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function f(e){var t=e[0],n=e[1],r=e[2];return Math.hypot(t,n,r)}function c(e,t,n){var a=new r(3);return a[0]=e,a[1]=t,a[2]=n,a}function l(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e}function h(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e}function d(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e[2]=t[2]*n[2],e}function m(e,t,n){return e[0]=Math.min(t[0],n[0]),e[1]=Math.min(t[1],n[1]),e[2]=Math.min(t[2],n[2]),e}function p(e,t,n){return e[0]=Math.max(t[0],n[0]),e[1]=Math.max(t[1],n[1]),e[2]=Math.max(t[2],n[2]),e}function v(e,t,n,r){return e[0]=t[0]+n[0]*r,e[1]=t[1]+n[1]*r,e[2]=t[2]+n[2]*r,e}function b(e,t){var n=t[0],r=t[1],a=t[2],i=n*n+r*r+a*a;return i>0&&(i=1/Math.sqrt(i)),e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e}function g(e,t){var n=e[0],r=e[1],a=e[2],i=t[0],o=t[1],u=t[2];return Math.abs(n-i)<=1e-6*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(a-u)<=1e-6*Math.max(1,Math.abs(a),Math.abs(u))}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)}),u();!function(){var e=["bubbles","cancelable","view","detail","screenX","screenY","clientX","clientY","ctrlKey","altKey","shiftKey","metaKey","button","relatedTarget","pageX","pageY"],t=[!1,!1,null,null,0,0,0,0,!1,!1,!1,!1,0,null,0,0];function n(n,r){r=r||Object.create(null);var a=document.createEvent("Event");a.initEvent(n,r.bubbles||!1,r.cancelable||!1);for(var i,o=2;o=Math.abs(r["client"+i]-this.firstXY[i])}return this.firstXY=null,t}},findTouch:function(e,t){for(var n,r=0,a=e.length;r=t.length){var n=[];F.forEach((function(e,r){if(1!==r&&!this.findTouch(t,r-2)){var a=e.out;n.push(a)}}),this),n.forEach(this.cancelOut,this)}},touchstart:function(e){this.vacuumTouches(e),this.setPrimaryTouch(e.changedTouches[0]),this.dedupSynthMouse(e),this.scrolling||(this.clickCount++,this.processTouches(e,this.overDown))},overDown:function(e){F.set(e.pointerId,{target:e.target,out:e,outTarget:e.target}),f.enterOver(e),f.down(e)},touchmove:function(e){this.scrolling||(this.shouldScroll(e)?(this.scrolling=!0,this.touchcancel(e)):(e.preventDefault(),this.processTouches(e,this.moveOverOut)))},moveOverOut:function(e){var t=e,n=F.get(t.pointerId);if(n){var r=n.out,a=n.outTarget;f.move(t),r&&a!==t.target&&(r.relatedTarget=t.target,t.relatedTarget=a,r.target=a,t.target?(f.leaveOut(r),f.enterOver(t)):(t.target=a,t.relatedTarget=null,this.cancelOut(t))),n.out=t,n.outTarget=t.target}},touchend:function(e){this.dedupSynthMouse(e),this.processTouches(e,this.upOut)},upOut:function(e){this.scrolling||(f.up(e),f.leaveOut(e)),this.cleanUpPointer(e)},touchcancel:function(e){this.processTouches(e,this.cancelOut)},cancelOut:function(e){f.cancel(e),f.leaveOut(e),this.cleanUpPointer(e)},cleanUpPointer:function(e){F.delete(e.pointerId),this.removePrimaryPointer(e)},dedupSynthMouse:function(e){var t=C.lastTouches,n=e.changedTouches[0];if(this.isPrimaryTouch(n)){var r={x:n.clientX,y:n.clientY};t.push(r);var a=function(e,t){var n=e.indexOf(t);n>-1&&e.splice(n,1)}.bind(null,t,r);setTimeout(a,z)}}};j=new g(V.elementAdded,V.elementRemoved,V.elementChanged,V);var q,N,Y,U=f.pointermap,X=window.MSPointerEvent&&"number"==typeof window.MSPointerEvent.MSPOINTER_TYPE_MOUSE,W={events:["MSPointerDown","MSPointerMove","MSPointerUp","MSPointerOut","MSPointerOver","MSPointerCancel","MSGotPointerCapture","MSLostPointerCapture"],register:function(e){f.listen(e,this.events)},unregister:function(e){f.unlisten(e,this.events)},POINTER_TYPES:["","unavailable","touch","pen","mouse"],prepareEvent:function(e){var t=e;return X&&((t=f.cloneEvent(e)).pointerType=this.POINTER_TYPES[e.pointerType]),t},cleanup:function(e){U.delete(e)},MSPointerDown:function(e){U.set(e.pointerId,e);var t=this.prepareEvent(e);f.down(t)},MSPointerMove:function(e){var t=this.prepareEvent(e);f.move(t)},MSPointerUp:function(e){var t=this.prepareEvent(e);f.up(t),this.cleanup(e.pointerId)},MSPointerOut:function(e){var t=this.prepareEvent(e);f.leaveOut(t)},MSPointerOver:function(e){var t=this.prepareEvent(e);f.enterOver(t)},MSPointerCancel:function(e){var t=this.prepareEvent(e);f.cancel(t),this.cleanup(e.pointerId)},MSLostPointerCapture:function(e){var t=f.makeEvent("lostpointercapture",e);f.dispatchEvent(t)},MSGotPointerCapture:function(e){var t=f.makeEvent("gotpointercapture",e);f.dispatchEvent(t)}};function H(){if(!window.PointerEvent){if(window.PointerEvent=n,window.navigator.msPointerEnabled){var e=window.navigator.msMaxTouchPoints;Object.defineProperty(window.navigator,"maxTouchPoints",{value:e,enumerable:!0}),f.registerSource("ms",W)}else Object.defineProperty(window.navigator,"maxTouchPoints",{value:0,enumerable:!0}),f.registerSource("mouse",C),void 0!==window.ontouchstart&&f.registerSource("touch",V);f.register(document)}}function G(e){if(!f.pointermap.has(e)){var t=new Error("InvalidPointerId");throw t.name="InvalidPointerId",t}}function Q(e){for(var t=e.parentNode;t&&t!==e.ownerDocument;)t=t.parentNode;if(!t){var n=new Error("InvalidStateError");throw n.name="InvalidStateError",n}}function K(e){return 0!==f.pointermap.get(e).buttons}function $(){window.Element&&!Element.prototype.setPointerCapture&&Object.defineProperties(Element.prototype,{setPointerCapture:{value:q},releasePointerCapture:{value:N},hasPointerCapture:{value:Y}})}window.navigator.msPointerEnabled?(q=function(e){G(e),Q(this),K(e)&&(f.setCapture(e,this,!0),this.msSetPointerCapture(e))},N=function(e){G(e),f.releaseCapture(e,!0),this.msReleasePointerCapture(e)}):(q=function(e){G(e),Q(this),K(e)&&f.setCapture(e,this)},N=function(e){G(e),f.releaseCapture(e)}),Y=function(e){return!!f.captureInfo[e]},S(),H(),$()}();var y=1e-6,x="undefined"!=typeof Float32Array?Float32Array:Array,w=Math.random;var M=Math.PI/180;var A=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",EPSILON:y,get ARRAY_TYPE(){return x},RANDOM:w,setMatrixArrayType:function(e){x=e},toRadian:function(e){return e*M},equals:function(e,t){return Math.abs(e-t)<=y*Math.max(1,Math.abs(e),Math.abs(t))}});function E(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=n[0],s=n[1],f=n[2],c=n[3];return e[0]=r*u+i*s,e[1]=a*u+o*s,e[2]=r*f+i*c,e[3]=a*f+o*c,e}function _(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e}var S=E,T=_,O=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",create:function(){var e=new x(4);return x!=Float32Array&&(e[1]=0,e[2]=0),e[0]=1,e[3]=1,e},clone:function(e){var t=new x(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},copy:function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},identity:function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e},fromValues:function(e,t,n,r){var a=new x(4);return a[0]=e,a[1]=t,a[2]=n,a[3]=r,a},set:function(e,t,n,r,a){return e[0]=t,e[1]=n,e[2]=r,e[3]=a,e},transpose:function(e,t){if(e===t){var n=t[1];e[1]=t[2],e[2]=n}else e[0]=t[0],e[1]=t[2],e[2]=t[1],e[3]=t[3];return e},invert:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=n*i-a*r;return o?(o=1/o,e[0]=i*o,e[1]=-r*o,e[2]=-a*o,e[3]=n*o,e):null},adjoint:function(e,t){var n=t[0];return e[0]=t[3],e[1]=-t[1],e[2]=-t[2],e[3]=n,e},determinant:function(e){return e[0]*e[3]-e[2]*e[1]},multiply:E,rotate:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=Math.sin(n),s=Math.cos(n);return e[0]=r*s+i*u,e[1]=a*s+o*u,e[2]=r*-u+i*s,e[3]=a*-u+o*s,e},scale:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=n[0],s=n[1];return e[0]=r*u,e[1]=a*u,e[2]=i*s,e[3]=o*s,e},fromRotation:function(e,t){var n=Math.sin(t),r=Math.cos(t);return e[0]=r,e[1]=n,e[2]=-n,e[3]=r,e},fromScaling:function(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=t[1],e},str:function(e){return"mat2("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},frob:function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2))},LDU:function(e,t,n,r){return e[2]=r[2]/r[0],n[0]=r[0],n[1]=r[1],n[3]=r[3]-e[2]*n[1],[e,t,n]},add:function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e},subtract:_,exactEquals:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]},equals:function(e,t){var n=e[0],r=e[1],a=e[2],i=e[3],o=t[0],u=t[1],s=t[2],f=t[3];return Math.abs(n-o)<=y*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(r-u)<=y*Math.max(1,Math.abs(r),Math.abs(u))&&Math.abs(a-s)<=y*Math.max(1,Math.abs(a),Math.abs(s))&&Math.abs(i-f)<=y*Math.max(1,Math.abs(i),Math.abs(f))},multiplyScalar:function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e},multiplyScalarAndAdd:function(e,t,n,r){return e[0]=t[0]+n[0]*r,e[1]=t[1]+n[1]*r,e[2]=t[2]+n[2]*r,e[3]=t[3]+n[3]*r,e},mul:S,sub:T});function k(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=t[4],s=t[5],f=n[0],c=n[1],l=n[2],h=n[3],d=n[4],m=n[5];return e[0]=r*f+i*c,e[1]=a*f+o*c,e[2]=r*l+i*h,e[3]=a*l+o*h,e[4]=r*d+i*m+u,e[5]=a*d+o*m+s,e}function D(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e[4]=t[4]-n[4],e[5]=t[5]-n[5],e}var j=k,C=D,P=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",create:function(){var e=new x(6);return x!=Float32Array&&(e[1]=0,e[2]=0,e[4]=0,e[5]=0),e[0]=1,e[3]=1,e},clone:function(e){var t=new x(6);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t},copy:function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e},identity:function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e[4]=0,e[5]=0,e},fromValues:function(e,t,n,r,a,i){var o=new x(6);return o[0]=e,o[1]=t,o[2]=n,o[3]=r,o[4]=a,o[5]=i,o},set:function(e,t,n,r,a,i,o){return e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=o,e},invert:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=t[4],u=t[5],s=n*i-r*a;return s?(s=1/s,e[0]=i*s,e[1]=-r*s,e[2]=-a*s,e[3]=n*s,e[4]=(a*u-i*o)*s,e[5]=(r*o-n*u)*s,e):null},determinant:function(e){return e[0]*e[3]-e[1]*e[2]},multiply:k,rotate:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=t[4],s=t[5],f=Math.sin(n),c=Math.cos(n);return e[0]=r*c+i*f,e[1]=a*c+o*f,e[2]=r*-f+i*c,e[3]=a*-f+o*c,e[4]=u,e[5]=s,e},scale:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=t[4],s=t[5],f=n[0],c=n[1];return e[0]=r*f,e[1]=a*f,e[2]=i*c,e[3]=o*c,e[4]=u,e[5]=s,e},translate:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=t[4],s=t[5],f=n[0],c=n[1];return e[0]=r,e[1]=a,e[2]=i,e[3]=o,e[4]=r*f+i*c+u,e[5]=a*f+o*c+s,e},fromRotation:function(e,t){var n=Math.sin(t),r=Math.cos(t);return e[0]=r,e[1]=n,e[2]=-n,e[3]=r,e[4]=0,e[5]=0,e},fromScaling:function(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=t[1],e[4]=0,e[5]=0,e},fromTranslation:function(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e[4]=t[0],e[5]=t[1],e},str:function(e){return"mat2d("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+")"},frob:function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2)+Math.pow(e[4],2)+Math.pow(e[5],2)+1)},add:function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e[4]=t[4]+n[4],e[5]=t[5]+n[5],e},subtract:D,multiplyScalar:function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*n,e[5]=t[5]*n,e},multiplyScalarAndAdd:function(e,t,n,r){return e[0]=t[0]+n[0]*r,e[1]=t[1]+n[1]*r,e[2]=t[2]+n[2]*r,e[3]=t[3]+n[3]*r,e[4]=t[4]+n[4]*r,e[5]=t[5]+n[5]*r,e},exactEquals:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]},equals:function(e,t){var n=e[0],r=e[1],a=e[2],i=e[3],o=e[4],u=e[5],s=t[0],f=t[1],c=t[2],l=t[3],h=t[4],d=t[5];return Math.abs(n-s)<=y*Math.max(1,Math.abs(n),Math.abs(s))&&Math.abs(r-f)<=y*Math.max(1,Math.abs(r),Math.abs(f))&&Math.abs(a-c)<=y*Math.max(1,Math.abs(a),Math.abs(c))&&Math.abs(i-l)<=y*Math.max(1,Math.abs(i),Math.abs(l))&&Math.abs(o-h)<=y*Math.max(1,Math.abs(o),Math.abs(h))&&Math.abs(u-d)<=y*Math.max(1,Math.abs(u),Math.abs(d))},mul:j,sub:C});function I(){var e=new x(9);return x!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[5]=0,e[6]=0,e[7]=0),e[0]=1,e[4]=1,e[8]=1,e}function R(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=t[4],s=t[5],f=t[6],c=t[7],l=t[8],h=n[0],d=n[1],m=n[2],p=n[3],v=n[4],b=n[5],g=n[6],y=n[7],x=n[8];return e[0]=h*r+d*o+m*f,e[1]=h*a+d*u+m*c,e[2]=h*i+d*s+m*l,e[3]=p*r+v*o+b*f,e[4]=p*a+v*u+b*c,e[5]=p*i+v*s+b*l,e[6]=g*r+y*o+x*f,e[7]=g*a+y*u+x*c,e[8]=g*i+y*s+x*l,e}function F(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e[4]=t[4]-n[4],e[5]=t[5]-n[5],e[6]=t[6]-n[6],e[7]=t[7]-n[7],e[8]=t[8]-n[8],e}var z=R,L=F,B=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",create:I,fromMat4:function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e},clone:function(e){var t=new x(9);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t},copy:function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e},fromValues:function(e,t,n,r,a,i,o,u,s){var f=new x(9);return f[0]=e,f[1]=t,f[2]=n,f[3]=r,f[4]=a,f[5]=i,f[6]=o,f[7]=u,f[8]=s,f},set:function(e,t,n,r,a,i,o,u,s,f){return e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=o,e[6]=u,e[7]=s,e[8]=f,e},identity:function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},transpose:function(e,t){if(e===t){var n=t[1],r=t[2],a=t[5];e[1]=t[3],e[2]=t[6],e[3]=n,e[5]=t[7],e[6]=r,e[7]=a}else e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8];return e},invert:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=t[4],u=t[5],s=t[6],f=t[7],c=t[8],l=c*o-u*f,h=-c*i+u*s,d=f*i-o*s,m=n*l+r*h+a*d;return m?(m=1/m,e[0]=l*m,e[1]=(-c*r+a*f)*m,e[2]=(u*r-a*o)*m,e[3]=h*m,e[4]=(c*n-a*s)*m,e[5]=(-u*n+a*i)*m,e[6]=d*m,e[7]=(-f*n+r*s)*m,e[8]=(o*n-r*i)*m,e):null},adjoint:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=t[4],u=t[5],s=t[6],f=t[7],c=t[8];return e[0]=o*c-u*f,e[1]=a*f-r*c,e[2]=r*u-a*o,e[3]=u*s-i*c,e[4]=n*c-a*s,e[5]=a*i-n*u,e[6]=i*f-o*s,e[7]=r*s-n*f,e[8]=n*o-r*i,e},determinant:function(e){var t=e[0],n=e[1],r=e[2],a=e[3],i=e[4],o=e[5],u=e[6],s=e[7],f=e[8];return t*(f*i-o*s)+n*(-f*a+o*u)+r*(s*a-i*u)},multiply:R,translate:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=t[4],s=t[5],f=t[6],c=t[7],l=t[8],h=n[0],d=n[1];return e[0]=r,e[1]=a,e[2]=i,e[3]=o,e[4]=u,e[5]=s,e[6]=h*r+d*o+f,e[7]=h*a+d*u+c,e[8]=h*i+d*s+l,e},rotate:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=t[4],s=t[5],f=t[6],c=t[7],l=t[8],h=Math.sin(n),d=Math.cos(n);return e[0]=d*r+h*o,e[1]=d*a+h*u,e[2]=d*i+h*s,e[3]=d*o-h*r,e[4]=d*u-h*a,e[5]=d*s-h*i,e[6]=f,e[7]=c,e[8]=l,e},scale:function(e,t,n){var r=n[0],a=n[1];return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=a*t[3],e[4]=a*t[4],e[5]=a*t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e},fromTranslation:function(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=t[0],e[7]=t[1],e[8]=1,e},fromRotation:function(e,t){var n=Math.sin(t),r=Math.cos(t);return e[0]=r,e[1]=n,e[2]=0,e[3]=-n,e[4]=r,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},fromScaling:function(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=t[1],e[5]=0,e[6]=0,e[7]=0,e[8]=1,e},fromMat2d:function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=0,e[3]=t[2],e[4]=t[3],e[5]=0,e[6]=t[4],e[7]=t[5],e[8]=1,e},fromQuat:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=n+n,u=r+r,s=a+a,f=n*o,c=r*o,l=r*u,h=a*o,d=a*u,m=a*s,p=i*o,v=i*u,b=i*s;return e[0]=1-l-m,e[3]=c-b,e[6]=h+v,e[1]=c+b,e[4]=1-f-m,e[7]=d-p,e[2]=h-v,e[5]=d+p,e[8]=1-f-l,e},normalFromMat4:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=t[4],u=t[5],s=t[6],f=t[7],c=t[8],l=t[9],h=t[10],d=t[11],m=t[12],p=t[13],v=t[14],b=t[15],g=n*u-r*o,y=n*s-a*o,x=n*f-i*o,w=r*s-a*u,M=r*f-i*u,A=a*f-i*s,E=c*p-l*m,_=c*v-h*m,S=c*b-d*m,T=l*v-h*p,O=l*b-d*p,k=h*b-d*v,D=g*k-y*O+x*T+w*S-M*_+A*E;return D?(D=1/D,e[0]=(u*k-s*O+f*T)*D,e[1]=(s*S-o*k-f*_)*D,e[2]=(o*O-u*S+f*E)*D,e[3]=(a*O-r*k-i*T)*D,e[4]=(n*k-a*S+i*_)*D,e[5]=(r*S-n*O-i*E)*D,e[6]=(p*A-v*M+b*w)*D,e[7]=(v*x-m*A-b*y)*D,e[8]=(m*M-p*x+b*g)*D,e):null},projection:function(e,t,n){return e[0]=2/t,e[1]=0,e[2]=0,e[3]=0,e[4]=-2/n,e[5]=0,e[6]=-1,e[7]=1,e[8]=1,e},str:function(e){return"mat3("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+")"},frob:function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2)+Math.pow(e[4],2)+Math.pow(e[5],2)+Math.pow(e[6],2)+Math.pow(e[7],2)+Math.pow(e[8],2))},add:function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e[4]=t[4]+n[4],e[5]=t[5]+n[5],e[6]=t[6]+n[6],e[7]=t[7]+n[7],e[8]=t[8]+n[8],e},subtract:F,multiplyScalar:function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*n,e[5]=t[5]*n,e[6]=t[6]*n,e[7]=t[7]*n,e[8]=t[8]*n,e},multiplyScalarAndAdd:function(e,t,n,r){return e[0]=t[0]+n[0]*r,e[1]=t[1]+n[1]*r,e[2]=t[2]+n[2]*r,e[3]=t[3]+n[3]*r,e[4]=t[4]+n[4]*r,e[5]=t[5]+n[5]*r,e[6]=t[6]+n[6]*r,e[7]=t[7]+n[7]*r,e[8]=t[8]+n[8]*r,e},exactEquals:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]},equals:function(e,t){var n=e[0],r=e[1],a=e[2],i=e[3],o=e[4],u=e[5],s=e[6],f=e[7],c=e[8],l=t[0],h=t[1],d=t[2],m=t[3],p=t[4],v=t[5],b=t[6],g=t[7],x=t[8];return Math.abs(n-l)<=y*Math.max(1,Math.abs(n),Math.abs(l))&&Math.abs(r-h)<=y*Math.max(1,Math.abs(r),Math.abs(h))&&Math.abs(a-d)<=y*Math.max(1,Math.abs(a),Math.abs(d))&&Math.abs(i-m)<=y*Math.max(1,Math.abs(i),Math.abs(m))&&Math.abs(o-p)<=y*Math.max(1,Math.abs(o),Math.abs(p))&&Math.abs(u-v)<=y*Math.max(1,Math.abs(u),Math.abs(v))&&Math.abs(s-b)<=y*Math.max(1,Math.abs(s),Math.abs(b))&&Math.abs(f-g)<=y*Math.max(1,Math.abs(f),Math.abs(g))&&Math.abs(c-x)<=y*Math.max(1,Math.abs(c),Math.abs(x))},mul:z,sub:L});function V(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function q(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=t[4],s=t[5],f=t[6],c=t[7],l=t[8],h=t[9],d=t[10],m=t[11],p=t[12],v=t[13],b=t[14],g=t[15],y=n[0],x=n[1],w=n[2],M=n[3];return e[0]=y*r+x*u+w*l+M*p,e[1]=y*a+x*s+w*h+M*v,e[2]=y*i+x*f+w*d+M*b,e[3]=y*o+x*c+w*m+M*g,y=n[4],x=n[5],w=n[6],M=n[7],e[4]=y*r+x*u+w*l+M*p,e[5]=y*a+x*s+w*h+M*v,e[6]=y*i+x*f+w*d+M*b,e[7]=y*o+x*c+w*m+M*g,y=n[8],x=n[9],w=n[10],M=n[11],e[8]=y*r+x*u+w*l+M*p,e[9]=y*a+x*s+w*h+M*v,e[10]=y*i+x*f+w*d+M*b,e[11]=y*o+x*c+w*m+M*g,y=n[12],x=n[13],w=n[14],M=n[15],e[12]=y*r+x*u+w*l+M*p,e[13]=y*a+x*s+w*h+M*v,e[14]=y*i+x*f+w*d+M*b,e[15]=y*o+x*c+w*m+M*g,e}function N(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=r+r,s=a+a,f=i+i,c=r*u,l=r*s,h=r*f,d=a*s,m=a*f,p=i*f,v=o*u,b=o*s,g=o*f;return e[0]=1-(d+p),e[1]=l+g,e[2]=h-b,e[3]=0,e[4]=l-g,e[5]=1-(c+p),e[6]=m+v,e[7]=0,e[8]=h+b,e[9]=m-v,e[10]=1-(c+d),e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function Y(e,t){return e[0]=t[12],e[1]=t[13],e[2]=t[14],e}function U(e,t){var n=t[0]+t[5]+t[10],r=0;return n>0?(r=2*Math.sqrt(n+1),e[3]=.25*r,e[0]=(t[6]-t[9])/r,e[1]=(t[8]-t[2])/r,e[2]=(t[1]-t[4])/r):t[0]>t[5]&&t[0]>t[10]?(r=2*Math.sqrt(1+t[0]-t[5]-t[10]),e[3]=(t[6]-t[9])/r,e[0]=.25*r,e[1]=(t[1]+t[4])/r,e[2]=(t[8]+t[2])/r):t[5]>t[10]?(r=2*Math.sqrt(1+t[5]-t[0]-t[10]),e[3]=(t[8]-t[2])/r,e[0]=(t[1]+t[4])/r,e[1]=.25*r,e[2]=(t[6]+t[9])/r):(r=2*Math.sqrt(1+t[10]-t[0]-t[5]),e[3]=(t[1]-t[4])/r,e[0]=(t[8]+t[2])/r,e[1]=(t[6]+t[9])/r,e[2]=.25*r),e}function X(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e[4]=t[4]-n[4],e[5]=t[5]-n[5],e[6]=t[6]-n[6],e[7]=t[7]-n[7],e[8]=t[8]-n[8],e[9]=t[9]-n[9],e[10]=t[10]-n[10],e[11]=t[11]-n[11],e[12]=t[12]-n[12],e[13]=t[13]-n[13],e[14]=t[14]-n[14],e[15]=t[15]-n[15],e}var W=q,H=X,G=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",create:function(){var e=new x(16);return x!=Float32Array&&(e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0),e[0]=1,e[5]=1,e[10]=1,e[15]=1,e},clone:function(e){var t=new x(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},copy:function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},fromValues:function(e,t,n,r,a,i,o,u,s,f,c,l,h,d,m,p){var v=new x(16);return v[0]=e,v[1]=t,v[2]=n,v[3]=r,v[4]=a,v[5]=i,v[6]=o,v[7]=u,v[8]=s,v[9]=f,v[10]=c,v[11]=l,v[12]=h,v[13]=d,v[14]=m,v[15]=p,v},set:function(e,t,n,r,a,i,o,u,s,f,c,l,h,d,m,p,v){return e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=o,e[6]=u,e[7]=s,e[8]=f,e[9]=c,e[10]=l,e[11]=h,e[12]=d,e[13]=m,e[14]=p,e[15]=v,e},identity:V,transpose:function(e,t){if(e===t){var n=t[1],r=t[2],a=t[3],i=t[6],o=t[7],u=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=r,e[9]=i,e[11]=t[14],e[12]=a,e[13]=o,e[14]=u}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e},invert:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=t[4],u=t[5],s=t[6],f=t[7],c=t[8],l=t[9],h=t[10],d=t[11],m=t[12],p=t[13],v=t[14],b=t[15],g=n*u-r*o,y=n*s-a*o,x=n*f-i*o,w=r*s-a*u,M=r*f-i*u,A=a*f-i*s,E=c*p-l*m,_=c*v-h*m,S=c*b-d*m,T=l*v-h*p,O=l*b-d*p,k=h*b-d*v,D=g*k-y*O+x*T+w*S-M*_+A*E;return D?(D=1/D,e[0]=(u*k-s*O+f*T)*D,e[1]=(a*O-r*k-i*T)*D,e[2]=(p*A-v*M+b*w)*D,e[3]=(h*M-l*A-d*w)*D,e[4]=(s*S-o*k-f*_)*D,e[5]=(n*k-a*S+i*_)*D,e[6]=(v*x-m*A-b*y)*D,e[7]=(c*A-h*x+d*y)*D,e[8]=(o*O-u*S+f*E)*D,e[9]=(r*S-n*O-i*E)*D,e[10]=(m*M-p*x+b*g)*D,e[11]=(l*x-c*M-d*g)*D,e[12]=(u*_-o*T-s*E)*D,e[13]=(n*T-r*_+a*E)*D,e[14]=(p*y-m*w-v*g)*D,e[15]=(c*w-l*y+h*g)*D,e):null},adjoint:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=t[4],u=t[5],s=t[6],f=t[7],c=t[8],l=t[9],h=t[10],d=t[11],m=t[12],p=t[13],v=t[14],b=t[15];return e[0]=u*(h*b-d*v)-l*(s*b-f*v)+p*(s*d-f*h),e[1]=-(r*(h*b-d*v)-l*(a*b-i*v)+p*(a*d-i*h)),e[2]=r*(s*b-f*v)-u*(a*b-i*v)+p*(a*f-i*s),e[3]=-(r*(s*d-f*h)-u*(a*d-i*h)+l*(a*f-i*s)),e[4]=-(o*(h*b-d*v)-c*(s*b-f*v)+m*(s*d-f*h)),e[5]=n*(h*b-d*v)-c*(a*b-i*v)+m*(a*d-i*h),e[6]=-(n*(s*b-f*v)-o*(a*b-i*v)+m*(a*f-i*s)),e[7]=n*(s*d-f*h)-o*(a*d-i*h)+c*(a*f-i*s),e[8]=o*(l*b-d*p)-c*(u*b-f*p)+m*(u*d-f*l),e[9]=-(n*(l*b-d*p)-c*(r*b-i*p)+m*(r*d-i*l)),e[10]=n*(u*b-f*p)-o*(r*b-i*p)+m*(r*f-i*u),e[11]=-(n*(u*d-f*l)-o*(r*d-i*l)+c*(r*f-i*u)),e[12]=-(o*(l*v-h*p)-c*(u*v-s*p)+m*(u*h-s*l)),e[13]=n*(l*v-h*p)-c*(r*v-a*p)+m*(r*h-a*l),e[14]=-(n*(u*v-s*p)-o*(r*v-a*p)+m*(r*s-a*u)),e[15]=n*(u*h-s*l)-o*(r*h-a*l)+c*(r*s-a*u),e},determinant:function(e){var t=e[0],n=e[1],r=e[2],a=e[3],i=e[4],o=e[5],u=e[6],s=e[7],f=e[8],c=e[9],l=e[10],h=e[11],d=e[12],m=e[13],p=e[14],v=e[15];return(t*o-n*i)*(l*v-h*p)-(t*u-r*i)*(c*v-h*m)+(t*s-a*i)*(c*p-l*m)+(n*u-r*o)*(f*v-h*d)-(n*s-a*o)*(f*p-l*d)+(r*s-a*u)*(f*m-c*d)},multiply:q,translate:function(e,t,n){var r=n[0],a=n[1],i=n[2],o=void 0,u=void 0,s=void 0,f=void 0,c=void 0,l=void 0,h=void 0,d=void 0,m=void 0,p=void 0,v=void 0,b=void 0;return t===e?(e[12]=t[0]*r+t[4]*a+t[8]*i+t[12],e[13]=t[1]*r+t[5]*a+t[9]*i+t[13],e[14]=t[2]*r+t[6]*a+t[10]*i+t[14],e[15]=t[3]*r+t[7]*a+t[11]*i+t[15]):(o=t[0],u=t[1],s=t[2],f=t[3],c=t[4],l=t[5],h=t[6],d=t[7],m=t[8],p=t[9],v=t[10],b=t[11],e[0]=o,e[1]=u,e[2]=s,e[3]=f,e[4]=c,e[5]=l,e[6]=h,e[7]=d,e[8]=m,e[9]=p,e[10]=v,e[11]=b,e[12]=o*r+c*a+m*i+t[12],e[13]=u*r+l*a+p*i+t[13],e[14]=s*r+h*a+v*i+t[14],e[15]=f*r+d*a+b*i+t[15]),e},scale:function(e,t,n){var r=n[0],a=n[1],i=n[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*a,e[5]=t[5]*a,e[6]=t[6]*a,e[7]=t[7]*a,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},rotate:function(e,t,n,r){var a,i,o,u,s,f,c,l,h,d,m,p,v,b,g,x,w,M,A,E,_,S,T,O,k=r[0],D=r[1],j=r[2],C=Math.sqrt(k*k+D*D+j*j);return C0?(n[0]=2*(u*o+c*r+s*i-f*a)/l,n[1]=2*(s*o+c*a+f*r-u*i)/l,n[2]=2*(f*o+c*i+u*a-s*r)/l):(n[0]=2*(u*o+c*r+s*i-f*a),n[1]=2*(s*o+c*a+f*r-u*i),n[2]=2*(f*o+c*i+u*a-s*r)),N(e,t,n),e},getTranslation:Y,getScaling:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[4],o=t[5],u=t[6],s=t[8],f=t[9],c=t[10];return e[0]=Math.sqrt(n*n+r*r+a*a),e[1]=Math.sqrt(i*i+o*o+u*u),e[2]=Math.sqrt(s*s+f*f+c*c),e},getRotation:U,fromRotationTranslationScale:function(e,t,n,r){var a=t[0],i=t[1],o=t[2],u=t[3],s=a+a,f=i+i,c=o+o,l=a*s,h=a*f,d=a*c,m=i*f,p=i*c,v=o*c,b=u*s,g=u*f,y=u*c,x=r[0],w=r[1],M=r[2];return e[0]=(1-(m+v))*x,e[1]=(h+y)*x,e[2]=(d-g)*x,e[3]=0,e[4]=(h-y)*w,e[5]=(1-(l+v))*w,e[6]=(p+b)*w,e[7]=0,e[8]=(d+g)*M,e[9]=(p-b)*M,e[10]=(1-(l+m))*M,e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e},fromRotationTranslationScaleOrigin:function(e,t,n,r,a){var i=t[0],o=t[1],u=t[2],s=t[3],f=i+i,c=o+o,l=u+u,h=i*f,d=i*c,m=i*l,p=o*c,v=o*l,b=u*l,g=s*f,y=s*c,x=s*l,w=r[0],M=r[1],A=r[2],E=a[0],_=a[1],S=a[2],T=(1-(p+b))*w,O=(d+x)*w,k=(m-y)*w,D=(d-x)*M,j=(1-(h+b))*M,C=(v+g)*M,P=(m+y)*A,I=(v-g)*A,R=(1-(h+p))*A;return e[0]=T,e[1]=O,e[2]=k,e[3]=0,e[4]=D,e[5]=j,e[6]=C,e[7]=0,e[8]=P,e[9]=I,e[10]=R,e[11]=0,e[12]=n[0]+E-(T*E+D*_+P*S),e[13]=n[1]+_-(O*E+j*_+I*S),e[14]=n[2]+S-(k*E+C*_+R*S),e[15]=1,e},fromQuat:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=n+n,u=r+r,s=a+a,f=n*o,c=r*o,l=r*u,h=a*o,d=a*u,m=a*s,p=i*o,v=i*u,b=i*s;return e[0]=1-l-m,e[1]=c+b,e[2]=h-v,e[3]=0,e[4]=c-b,e[5]=1-f-m,e[6]=d+p,e[7]=0,e[8]=h+v,e[9]=d-p,e[10]=1-f-l,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},frustum:function(e,t,n,r,a,i,o){var u=1/(n-t),s=1/(a-r),f=1/(i-o);return e[0]=2*i*u,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=2*i*s,e[6]=0,e[7]=0,e[8]=(n+t)*u,e[9]=(a+r)*s,e[10]=(o+i)*f,e[11]=-1,e[12]=0,e[13]=0,e[14]=o*i*2*f,e[15]=0,e},perspective:function(e,t,n,r,a){var i=1/Math.tan(t/2),o=void 0;return e[0]=i/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,null!=a&&a!==1/0?(o=1/(r-a),e[10]=(a+r)*o,e[14]=2*a*r*o):(e[10]=-1,e[14]=-2*r),e},perspectiveFromFieldOfView:function(e,t,n,r){var a=Math.tan(t.upDegrees*Math.PI/180),i=Math.tan(t.downDegrees*Math.PI/180),o=Math.tan(t.leftDegrees*Math.PI/180),u=Math.tan(t.rightDegrees*Math.PI/180),s=2/(o+u),f=2/(a+i);return e[0]=s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=f,e[6]=0,e[7]=0,e[8]=-(o-u)*s*.5,e[9]=(a-i)*f*.5,e[10]=r/(n-r),e[11]=-1,e[12]=0,e[13]=0,e[14]=r*n/(n-r),e[15]=0,e},ortho:function(e,t,n,r,a,i,o){var u=1/(t-n),s=1/(r-a),f=1/(i-o);return e[0]=-2*u,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*s,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*f,e[11]=0,e[12]=(t+n)*u,e[13]=(a+r)*s,e[14]=(o+i)*f,e[15]=1,e},lookAt:function(e,t,n,r){var a=void 0,i=void 0,o=void 0,u=void 0,s=void 0,f=void 0,c=void 0,l=void 0,h=void 0,d=void 0,m=t[0],p=t[1],v=t[2],b=r[0],g=r[1],x=r[2],w=n[0],M=n[1],A=n[2];return Math.abs(m-w)0&&(c*=d=1/Math.sqrt(d),l*=d,h*=d);var m=s*h-f*l,p=f*c-u*h,v=u*l-s*c;return(d=m*m+p*p+v*v)>0&&(m*=d=1/Math.sqrt(d),p*=d,v*=d),e[0]=m,e[1]=p,e[2]=v,e[3]=0,e[4]=l*v-h*p,e[5]=h*m-c*v,e[6]=c*p-l*m,e[7]=0,e[8]=c,e[9]=l,e[10]=h,e[11]=0,e[12]=a,e[13]=i,e[14]=o,e[15]=1,e},str:function(e){return"mat4("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+", "+e[8]+", "+e[9]+", "+e[10]+", "+e[11]+", "+e[12]+", "+e[13]+", "+e[14]+", "+e[15]+")"},frob:function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2)+Math.pow(e[4],2)+Math.pow(e[5],2)+Math.pow(e[6],2)+Math.pow(e[7],2)+Math.pow(e[8],2)+Math.pow(e[9],2)+Math.pow(e[10],2)+Math.pow(e[11],2)+Math.pow(e[12],2)+Math.pow(e[13],2)+Math.pow(e[14],2)+Math.pow(e[15],2))},add:function(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e[4]=t[4]+n[4],e[5]=t[5]+n[5],e[6]=t[6]+n[6],e[7]=t[7]+n[7],e[8]=t[8]+n[8],e[9]=t[9]+n[9],e[10]=t[10]+n[10],e[11]=t[11]+n[11],e[12]=t[12]+n[12],e[13]=t[13]+n[13],e[14]=t[14]+n[14],e[15]=t[15]+n[15],e},subtract:X,multiplyScalar:function(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*n,e[5]=t[5]*n,e[6]=t[6]*n,e[7]=t[7]*n,e[8]=t[8]*n,e[9]=t[9]*n,e[10]=t[10]*n,e[11]=t[11]*n,e[12]=t[12]*n,e[13]=t[13]*n,e[14]=t[14]*n,e[15]=t[15]*n,e},multiplyScalarAndAdd:function(e,t,n,r){return e[0]=t[0]+n[0]*r,e[1]=t[1]+n[1]*r,e[2]=t[2]+n[2]*r,e[3]=t[3]+n[3]*r,e[4]=t[4]+n[4]*r,e[5]=t[5]+n[5]*r,e[6]=t[6]+n[6]*r,e[7]=t[7]+n[7]*r,e[8]=t[8]+n[8]*r,e[9]=t[9]+n[9]*r,e[10]=t[10]+n[10]*r,e[11]=t[11]+n[11]*r,e[12]=t[12]+n[12]*r,e[13]=t[13]+n[13]*r,e[14]=t[14]+n[14]*r,e[15]=t[15]+n[15]*r,e},exactEquals:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]&&e[8]===t[8]&&e[9]===t[9]&&e[10]===t[10]&&e[11]===t[11]&&e[12]===t[12]&&e[13]===t[13]&&e[14]===t[14]&&e[15]===t[15]},equals:function(e,t){var n=e[0],r=e[1],a=e[2],i=e[3],o=e[4],u=e[5],s=e[6],f=e[7],c=e[8],l=e[9],h=e[10],d=e[11],m=e[12],p=e[13],v=e[14],b=e[15],g=t[0],x=t[1],w=t[2],M=t[3],A=t[4],E=t[5],_=t[6],S=t[7],T=t[8],O=t[9],k=t[10],D=t[11],j=t[12],C=t[13],P=t[14],I=t[15];return Math.abs(n-g)<=y*Math.max(1,Math.abs(n),Math.abs(g))&&Math.abs(r-x)<=y*Math.max(1,Math.abs(r),Math.abs(x))&&Math.abs(a-w)<=y*Math.max(1,Math.abs(a),Math.abs(w))&&Math.abs(i-M)<=y*Math.max(1,Math.abs(i),Math.abs(M))&&Math.abs(o-A)<=y*Math.max(1,Math.abs(o),Math.abs(A))&&Math.abs(u-E)<=y*Math.max(1,Math.abs(u),Math.abs(E))&&Math.abs(s-_)<=y*Math.max(1,Math.abs(s),Math.abs(_))&&Math.abs(f-S)<=y*Math.max(1,Math.abs(f),Math.abs(S))&&Math.abs(c-T)<=y*Math.max(1,Math.abs(c),Math.abs(T))&&Math.abs(l-O)<=y*Math.max(1,Math.abs(l),Math.abs(O))&&Math.abs(h-k)<=y*Math.max(1,Math.abs(h),Math.abs(k))&&Math.abs(d-D)<=y*Math.max(1,Math.abs(d),Math.abs(D))&&Math.abs(m-j)<=y*Math.max(1,Math.abs(m),Math.abs(j))&&Math.abs(p-C)<=y*Math.max(1,Math.abs(p),Math.abs(C))&&Math.abs(v-P)<=y*Math.max(1,Math.abs(v),Math.abs(P))&&Math.abs(b-I)<=y*Math.max(1,Math.abs(b),Math.abs(I))},mul:W,sub:H});function Q(){var e=new x(3);return x!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function K(e){var t=e[0],n=e[1],r=e[2];return Math.sqrt(t*t+n*n+r*r)}function $(e,t,n){var r=new x(3);return r[0]=e,r[1]=t,r[2]=n,r}function Z(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e}function J(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e[2]=t[2]*n[2],e}function ee(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e[2]=t[2]/n[2],e}function te(e,t){var n=t[0]-e[0],r=t[1]-e[1],a=t[2]-e[2];return Math.sqrt(n*n+r*r+a*a)}function ne(e,t){var n=t[0]-e[0],r=t[1]-e[1],a=t[2]-e[2];return n*n+r*r+a*a}function re(e){var t=e[0],n=e[1],r=e[2];return t*t+n*n+r*r}function ae(e,t){var n=t[0],r=t[1],a=t[2],i=n*n+r*r+a*a;return i>0&&(i=1/Math.sqrt(i),e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i),e}function ie(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function oe(e,t,n){var r=t[0],a=t[1],i=t[2],o=n[0],u=n[1],s=n[2];return e[0]=a*s-i*u,e[1]=i*o-r*s,e[2]=r*u-a*o,e}var ue=Z,se=J,fe=ee,ce=te,le=ne,he=K,de=re,me=function(){var e=Q();return function(t,n,r,a,i,o){var u=void 0,s=void 0;for(n||(n=3),r||(r=0),s=a?Math.min(a*n+r,t.length):t.length,u=r;u1?0:a<-1?Math.PI:Math.acos(a)},str:function(e){return"vec3("+e[0]+", "+e[1]+", "+e[2]+")"},exactEquals:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]},equals:function(e,t){var n=e[0],r=e[1],a=e[2],i=t[0],o=t[1],u=t[2];return Math.abs(n-i)<=y*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=y*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(a-u)<=y*Math.max(1,Math.abs(a),Math.abs(u))},sub:ue,mul:se,div:fe,dist:ce,sqrDist:le,len:he,sqrLen:de,forEach:me});function ve(){var e=new x(4);return x!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function be(e){var t=new x(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t}function ge(e,t,n,r){var a=new x(4);return a[0]=e,a[1]=t,a[2]=n,a[3]=r,a}function ye(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}function xe(e,t,n,r,a){return e[0]=t,e[1]=n,e[2]=r,e[3]=a,e}function we(e,t,n){return e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2],e[3]=t[3]+n[3],e}function Me(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e[2]=t[2]-n[2],e[3]=t[3]-n[3],e}function Ae(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e[2]=t[2]*n[2],e[3]=t[3]*n[3],e}function Ee(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e[2]=t[2]/n[2],e[3]=t[3]/n[3],e}function _e(e,t,n){return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e}function Se(e,t){var n=t[0]-e[0],r=t[1]-e[1],a=t[2]-e[2],i=t[3]-e[3];return Math.sqrt(n*n+r*r+a*a+i*i)}function Te(e,t){var n=t[0]-e[0],r=t[1]-e[1],a=t[2]-e[2],i=t[3]-e[3];return n*n+r*r+a*a+i*i}function Oe(e){var t=e[0],n=e[1],r=e[2],a=e[3];return Math.sqrt(t*t+n*n+r*r+a*a)}function ke(e){var t=e[0],n=e[1],r=e[2],a=e[3];return t*t+n*n+r*r+a*a}function De(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=n*n+r*r+a*a+i*i;return o>0&&(o=1/Math.sqrt(o),e[0]=n*o,e[1]=r*o,e[2]=a*o,e[3]=i*o),e}function je(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]}function Ce(e,t,n,r){var a=t[0],i=t[1],o=t[2],u=t[3];return e[0]=a+r*(n[0]-a),e[1]=i+r*(n[1]-i),e[2]=o+r*(n[2]-o),e[3]=u+r*(n[3]-u),e}function Pe(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]}function Ie(e,t){var n=e[0],r=e[1],a=e[2],i=e[3],o=t[0],u=t[1],s=t[2],f=t[3];return Math.abs(n-o)<=y*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(r-u)<=y*Math.max(1,Math.abs(r),Math.abs(u))&&Math.abs(a-s)<=y*Math.max(1,Math.abs(a),Math.abs(s))&&Math.abs(i-f)<=y*Math.max(1,Math.abs(i),Math.abs(f))}var Re=Me,Fe=Ae,ze=Ee,Le=Se,Be=Te,Ve=Oe,qe=ke,Ne=function(){var e=ve();return function(t,n,r,a,i,o){var u=void 0,s=void 0;for(n||(n=4),r||(r=0),s=a?Math.min(a*n+r,t.length):t.length,u=r;u=1);do{u=(a=2*w()-1)*a+(i=2*w()-1)*i}while(u>=1);var s=Math.sqrt((1-o)/u);return e[0]=t*n,e[1]=t*r,e[2]=t*a*s,e[3]=t*i*s,e},transformMat4:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3];return e[0]=n[0]*r+n[4]*a+n[8]*i+n[12]*o,e[1]=n[1]*r+n[5]*a+n[9]*i+n[13]*o,e[2]=n[2]*r+n[6]*a+n[10]*i+n[14]*o,e[3]=n[3]*r+n[7]*a+n[11]*i+n[15]*o,e},transformQuat:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=n[0],u=n[1],s=n[2],f=n[3],c=f*r+u*i-s*a,l=f*a+s*r-o*i,h=f*i+o*a-u*r,d=-o*r-u*a-s*i;return e[0]=c*f+d*-o+l*-s-h*-u,e[1]=l*f+d*-u+h*-o-c*-s,e[2]=h*f+d*-s+c*-u-l*-o,e[3]=t[3],e},str:function(e){return"vec4("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},exactEquals:Pe,equals:Ie,sub:Re,mul:Fe,div:ze,dist:Le,sqrDist:Be,len:Ve,sqrLen:qe,forEach:Ne});function Ue(){var e=new x(4);return x!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}function Xe(e,t,n){n*=.5;var r=Math.sin(n);return e[0]=r*t[0],e[1]=r*t[1],e[2]=r*t[2],e[3]=Math.cos(n),e}function We(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=n[0],s=n[1],f=n[2],c=n[3];return e[0]=r*c+o*u+a*f-i*s,e[1]=a*c+o*s+i*u-r*f,e[2]=i*c+o*f+r*s-a*u,e[3]=o*c-r*u-a*s-i*f,e}function He(e,t,n){n*=.5;var r=t[0],a=t[1],i=t[2],o=t[3],u=Math.sin(n),s=Math.cos(n);return e[0]=r*s+o*u,e[1]=a*s+i*u,e[2]=i*s-a*u,e[3]=o*s-r*u,e}function Ge(e,t,n){n*=.5;var r=t[0],a=t[1],i=t[2],o=t[3],u=Math.sin(n),s=Math.cos(n);return e[0]=r*s-i*u,e[1]=a*s+o*u,e[2]=i*s+r*u,e[3]=o*s-a*u,e}function Qe(e,t,n){n*=.5;var r=t[0],a=t[1],i=t[2],o=t[3],u=Math.sin(n),s=Math.cos(n);return e[0]=r*s+a*u,e[1]=a*s-r*u,e[2]=i*s+o*u,e[3]=o*s-i*u,e}function Ke(e,t,n,r){var a=t[0],i=t[1],o=t[2],u=t[3],s=n[0],f=n[1],c=n[2],l=n[3],h=void 0,d=void 0,m=void 0,p=void 0,v=void 0;return(d=a*s+i*f+o*c+u*l)<0&&(d=-d,s=-s,f=-f,c=-c,l=-l),1-d>y?(h=Math.acos(d),m=Math.sin(h),p=Math.sin((1-r)*h)/m,v=Math.sin(r*h)/m):(p=1-r,v=r),e[0]=p*a+v*s,e[1]=p*i+v*f,e[2]=p*o+v*c,e[3]=p*u+v*l,e}function $e(e,t){var n=t[0]+t[4]+t[8],r=void 0;if(n>0)r=Math.sqrt(n+1),e[3]=.5*r,r=.5/r,e[0]=(t[5]-t[7])*r,e[1]=(t[6]-t[2])*r,e[2]=(t[1]-t[3])*r;else{var a=0;t[4]>t[0]&&(a=1),t[8]>t[3*a+a]&&(a=2);var i=(a+1)%3,o=(a+2)%3;r=Math.sqrt(t[3*a+a]-t[3*i+i]-t[3*o+o]+1),e[a]=.5*r,r=.5/r,e[3]=(t[3*i+o]-t[3*o+i])*r,e[i]=(t[3*i+a]+t[3*a+i])*r,e[o]=(t[3*o+a]+t[3*a+o])*r}return e}var Ze,Je,et,tt,nt,rt,at=be,it=ge,ot=ye,ut=xe,st=we,ft=We,ct=_e,lt=je,ht=Ce,dt=Oe,mt=dt,pt=ke,vt=pt,bt=De,gt=Pe,yt=Ie,xt=(Ze=Q(),Je=$(1,0,0),et=$(0,1,0),function(e,t,n){var r=ie(t,n);return r<-.999999?(oe(Ze,Je,t),he(Ze)<1e-6&&oe(Ze,et,t),ae(Ze,Ze),Xe(e,Ze,Math.PI),e):r>.999999?(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e):(oe(Ze,t,n),e[0]=Ze[0],e[1]=Ze[1],e[2]=Ze[2],e[3]=1+r,bt(e,e))}),wt=(tt=Ue(),nt=Ue(),function(e,t,n,r,a,i){return Ke(tt,t,a,i),Ke(nt,n,r,i),Ke(e,tt,nt,2*i*(1-i)),e}),Mt=(rt=I(),function(e,t,n,r){return rt[0]=n[0],rt[3]=n[1],rt[6]=n[2],rt[1]=r[0],rt[4]=r[1],rt[7]=r[2],rt[2]=-t[0],rt[5]=-t[1],rt[8]=-t[2],bt(e,$e(e,rt))}),At=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",create:Ue,identity:function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},setAxisAngle:Xe,getAxisAngle:function(e,t){var n=2*Math.acos(t[3]),r=Math.sin(n/2);return r>y?(e[0]=t[0]/r,e[1]=t[1]/r,e[2]=t[2]/r):(e[0]=1,e[1]=0,e[2]=0),n},multiply:We,rotateX:He,rotateY:Ge,rotateZ:Qe,calculateW:function(e,t){var n=t[0],r=t[1],a=t[2];return e[0]=n,e[1]=r,e[2]=a,e[3]=Math.sqrt(Math.abs(1-n*n-r*r-a*a)),e},slerp:Ke,random:function(e){var t=w(),n=w(),r=w(),a=Math.sqrt(1-t),i=Math.sqrt(t);return e[0]=a*Math.sin(2*Math.PI*n),e[1]=a*Math.cos(2*Math.PI*n),e[2]=i*Math.sin(2*Math.PI*r),e[3]=i*Math.cos(2*Math.PI*r),e},invert:function(e,t){var n=t[0],r=t[1],a=t[2],i=t[3],o=n*n+r*r+a*a+i*i,u=o?1/o:0;return e[0]=-n*u,e[1]=-r*u,e[2]=-a*u,e[3]=i*u,e},conjugate:function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e},fromMat3:$e,fromEuler:function(e,t,n,r){var a=.5*Math.PI/180;t*=a,n*=a,r*=a;var i=Math.sin(t),o=Math.cos(t),u=Math.sin(n),s=Math.cos(n),f=Math.sin(r),c=Math.cos(r);return e[0]=i*s*c-o*u*f,e[1]=o*u*c+i*s*f,e[2]=o*s*f-i*u*c,e[3]=o*s*c+i*u*f,e},str:function(e){return"quat("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+")"},clone:at,fromValues:it,copy:ot,set:ut,add:st,mul:ft,scale:ct,dot:lt,lerp:ht,length:dt,len:mt,squaredLength:pt,sqrLen:vt,normalize:bt,exactEquals:gt,equals:yt,rotationTo:xt,sqlerp:wt,setAxes:Mt});function Et(e,t,n){var r=.5*n[0],a=.5*n[1],i=.5*n[2],o=t[0],u=t[1],s=t[2],f=t[3];return e[0]=o,e[1]=u,e[2]=s,e[3]=f,e[4]=r*f+a*s-i*u,e[5]=a*f+i*o-r*s,e[6]=i*f+r*u-a*o,e[7]=-r*o-a*u-i*s,e}function _t(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e}var St=ot;var Tt=ot;function Ot(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=n[4],s=n[5],f=n[6],c=n[7],l=t[4],h=t[5],d=t[6],m=t[7],p=n[0],v=n[1],b=n[2],g=n[3];return e[0]=r*g+o*p+a*b-i*v,e[1]=a*g+o*v+i*p-r*b,e[2]=i*g+o*b+r*v-a*p,e[3]=o*g-r*p-a*v-i*b,e[4]=r*c+o*u+a*f-i*s+l*g+m*p+h*b-d*v,e[5]=a*c+o*s+i*u-r*f+h*g+m*v+d*p-l*b,e[6]=i*c+o*f+r*s-a*u+d*g+m*b+l*v-h*p,e[7]=o*c-r*u-a*s-i*f+m*g-l*p-h*v-d*b,e}var kt=Ot;var Dt=lt;var jt=dt,Ct=jt,Pt=pt,It=Pt;var Rt=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",create:function(){var e=new x(8);return x!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[4]=0,e[5]=0,e[6]=0,e[7]=0),e[3]=1,e},clone:function(e){var t=new x(8);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t},fromValues:function(e,t,n,r,a,i,o,u){var s=new x(8);return s[0]=e,s[1]=t,s[2]=n,s[3]=r,s[4]=a,s[5]=i,s[6]=o,s[7]=u,s},fromRotationTranslationValues:function(e,t,n,r,a,i,o){var u=new x(8);u[0]=e,u[1]=t,u[2]=n,u[3]=r;var s=.5*a,f=.5*i,c=.5*o;return u[4]=s*r+f*n-c*t,u[5]=f*r+c*e-s*n,u[6]=c*r+s*t-f*e,u[7]=-s*e-f*t-c*n,u},fromRotationTranslation:Et,fromTranslation:function(e,t){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e[4]=.5*t[0],e[5]=.5*t[1],e[6]=.5*t[2],e[7]=0,e},fromRotation:function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=0,e[5]=0,e[6]=0,e[7]=0,e},fromMat4:function(e,t){var n=Ue();U(n,t);var r=new x(3);return Y(r,t),Et(e,n,r),e},copy:_t,identity:function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e[4]=0,e[5]=0,e[6]=0,e[7]=0,e},set:function(e,t,n,r,a,i,o,u,s){return e[0]=t,e[1]=n,e[2]=r,e[3]=a,e[4]=i,e[5]=o,e[6]=u,e[7]=s,e},getReal:St,getDual:function(e,t){return e[0]=t[4],e[1]=t[5],e[2]=t[6],e[3]=t[7],e},setReal:Tt,setDual:function(e,t){return e[4]=t[0],e[5]=t[1],e[6]=t[2],e[7]=t[3],e},getTranslation:function(e,t){var n=t[4],r=t[5],a=t[6],i=t[7],o=-t[0],u=-t[1],s=-t[2],f=t[3];return e[0]=2*(n*f+i*o+r*s-a*u),e[1]=2*(r*f+i*u+a*o-n*s),e[2]=2*(a*f+i*s+n*u-r*o),e},translate:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=.5*n[0],s=.5*n[1],f=.5*n[2],c=t[4],l=t[5],h=t[6],d=t[7];return e[0]=r,e[1]=a,e[2]=i,e[3]=o,e[4]=o*u+a*f-i*s+c,e[5]=o*s+i*u-r*f+l,e[6]=o*f+r*s-a*u+h,e[7]=-r*u-a*s-i*f+d,e},rotateX:function(e,t,n){var r=-t[0],a=-t[1],i=-t[2],o=t[3],u=t[4],s=t[5],f=t[6],c=t[7],l=u*o+c*r+s*i-f*a,h=s*o+c*a+f*r-u*i,d=f*o+c*i+u*a-s*r,m=c*o-u*r-s*a-f*i;return He(e,t,n),r=e[0],a=e[1],i=e[2],o=e[3],e[4]=l*o+m*r+h*i-d*a,e[5]=h*o+m*a+d*r-l*i,e[6]=d*o+m*i+l*a-h*r,e[7]=m*o-l*r-h*a-d*i,e},rotateY:function(e,t,n){var r=-t[0],a=-t[1],i=-t[2],o=t[3],u=t[4],s=t[5],f=t[6],c=t[7],l=u*o+c*r+s*i-f*a,h=s*o+c*a+f*r-u*i,d=f*o+c*i+u*a-s*r,m=c*o-u*r-s*a-f*i;return Ge(e,t,n),r=e[0],a=e[1],i=e[2],o=e[3],e[4]=l*o+m*r+h*i-d*a,e[5]=h*o+m*a+d*r-l*i,e[6]=d*o+m*i+l*a-h*r,e[7]=m*o-l*r-h*a-d*i,e},rotateZ:function(e,t,n){var r=-t[0],a=-t[1],i=-t[2],o=t[3],u=t[4],s=t[5],f=t[6],c=t[7],l=u*o+c*r+s*i-f*a,h=s*o+c*a+f*r-u*i,d=f*o+c*i+u*a-s*r,m=c*o-u*r-s*a-f*i;return Qe(e,t,n),r=e[0],a=e[1],i=e[2],o=e[3],e[4]=l*o+m*r+h*i-d*a,e[5]=h*o+m*a+d*r-l*i,e[6]=d*o+m*i+l*a-h*r,e[7]=m*o-l*r-h*a-d*i,e},rotateByQuatAppend:function(e,t,n){var r=n[0],a=n[1],i=n[2],o=n[3],u=t[0],s=t[1],f=t[2],c=t[3];return e[0]=u*o+c*r+s*i-f*a,e[1]=s*o+c*a+f*r-u*i,e[2]=f*o+c*i+u*a-s*r,e[3]=c*o-u*r-s*a-f*i,u=t[4],s=t[5],f=t[6],c=t[7],e[4]=u*o+c*r+s*i-f*a,e[5]=s*o+c*a+f*r-u*i,e[6]=f*o+c*i+u*a-s*r,e[7]=c*o-u*r-s*a-f*i,e},rotateByQuatPrepend:function(e,t,n){var r=t[0],a=t[1],i=t[2],o=t[3],u=n[0],s=n[1],f=n[2],c=n[3];return e[0]=r*c+o*u+a*f-i*s,e[1]=a*c+o*s+i*u-r*f,e[2]=i*c+o*f+r*s-a*u,e[3]=o*c-r*u-a*s-i*f,u=n[4],s=n[5],f=n[6],c=n[7],e[4]=r*c+o*u+a*f-i*s,e[5]=a*c+o*s+i*u-r*f,e[6]=i*c+o*f+r*s-a*u,e[7]=o*c-r*u-a*s-i*f,e},rotateAroundAxis:function(e,t,n,r){if(Math.abs(r)0){n=Math.sqrt(n);var r=t[0]/n,a=t[1]/n,i=t[2]/n,o=t[3]/n,u=t[4],s=t[5],f=t[6],c=t[7],l=r*u+a*s+i*f+o*c;e[0]=r,e[1]=a,e[2]=i,e[3]=o,e[4]=(u-r*l)/n,e[5]=(s-a*l)/n,e[6]=(f-i*l)/n,e[7]=(c-o*l)/n}return e},str:function(e){return"quat2("+e[0]+", "+e[1]+", "+e[2]+", "+e[3]+", "+e[4]+", "+e[5]+", "+e[6]+", "+e[7]+")"},exactEquals:function(e,t){return e[0]===t[0]&&e[1]===t[1]&&e[2]===t[2]&&e[3]===t[3]&&e[4]===t[4]&&e[5]===t[5]&&e[6]===t[6]&&e[7]===t[7]},equals:function(e,t){var n=e[0],r=e[1],a=e[2],i=e[3],o=e[4],u=e[5],s=e[6],f=e[7],c=t[0],l=t[1],h=t[2],d=t[3],m=t[4],p=t[5],v=t[6],b=t[7];return Math.abs(n-c)<=y*Math.max(1,Math.abs(n),Math.abs(c))&&Math.abs(r-l)<=y*Math.max(1,Math.abs(r),Math.abs(l))&&Math.abs(a-h)<=y*Math.max(1,Math.abs(a),Math.abs(h))&&Math.abs(i-d)<=y*Math.max(1,Math.abs(i),Math.abs(d))&&Math.abs(o-m)<=y*Math.max(1,Math.abs(o),Math.abs(m))&&Math.abs(u-p)<=y*Math.max(1,Math.abs(u),Math.abs(p))&&Math.abs(s-v)<=y*Math.max(1,Math.abs(s),Math.abs(v))&&Math.abs(f-b)<=y*Math.max(1,Math.abs(f),Math.abs(b))}});function Ft(){var e=new x(2);return x!=Float32Array&&(e[0]=0,e[1]=0),e}function zt(e,t,n){return e[0]=t[0]-n[0],e[1]=t[1]-n[1],e}function Lt(e,t,n){return e[0]=t[0]*n[0],e[1]=t[1]*n[1],e}function Bt(e,t,n){return e[0]=t[0]/n[0],e[1]=t[1]/n[1],e}function Vt(e,t){var n=t[0]-e[0],r=t[1]-e[1];return Math.sqrt(n*n+r*r)}function qt(e,t){var n=t[0]-e[0],r=t[1]-e[1];return n*n+r*r}function Nt(e){var t=e[0],n=e[1];return Math.sqrt(t*t+n*n)}function Yt(e){var t=e[0],n=e[1];return t*t+n*n}var Ut,Xt,Wt=Nt,Ht=zt,Gt=Lt,Qt=Bt,Kt=Vt,$t=qt,Zt=Yt,Jt=function(){var e=Ft();return function(t,n,r,a,i,o){var u=void 0,s=void 0;for(n||(n=2),r||(r=0),s=a?Math.min(a*n+r,t.length):t.length,u=r;u0&&(a=1/Math.sqrt(a),e[0]=t[0]*a,e[1]=t[1]*a),e},dot:function(e,t){return e[0]*t[0]+e[1]*t[1]},cross:function(e,t,n){var r=t[0]*n[1]-t[1]*n[0];return e[0]=e[1]=0,e[2]=r,e},lerp:function(e,t,n,r){var a=t[0],i=t[1];return e[0]=a+r*(n[0]-a),e[1]=i+r*(n[1]-i),e},random:function(e,t){t=t||1;var n=2*w()*Math.PI;return e[0]=Math.cos(n)*t,e[1]=Math.sin(n)*t,e},transformMat2:function(e,t,n){var r=t[0],a=t[1];return e[0]=n[0]*r+n[2]*a,e[1]=n[1]*r+n[3]*a,e},transformMat2d:function(e,t,n){var r=t[0],a=t[1];return e[0]=n[0]*r+n[2]*a+n[4],e[1]=n[1]*r+n[3]*a+n[5],e},transformMat3:function(e,t,n){var r=t[0],a=t[1];return e[0]=n[0]*r+n[3]*a+n[6],e[1]=n[1]*r+n[4]*a+n[7],e},transformMat4:function(e,t,n){var r=t[0],a=t[1];return e[0]=n[0]*r+n[4]*a+n[12],e[1]=n[1]*r+n[5]*a+n[13],e},rotate:function(e,t,n,r){var a=t[0]-n[0],i=t[1]-n[1],o=Math.sin(r),u=Math.cos(r);return e[0]=a*u-i*o+n[0],e[1]=a*o+i*u+n[1],e},angle:function(e,t){var n=e[0],r=e[1],a=t[0],i=t[1],o=n*n+r*r;o>0&&(o=1/Math.sqrt(o));var u=a*a+i*i;u>0&&(u=1/Math.sqrt(u));var s=(n*a+r*i)*o*u;return s>1?0:s<-1?Math.PI:Math.acos(s)},str:function(e){return"vec2("+e[0]+", "+e[1]+")"},exactEquals:function(e,t){return e[0]===t[0]&&e[1]===t[1]},equals:function(e,t){var n=e[0],r=e[1],a=t[0],i=t[1];return Math.abs(n-a)<=y*Math.max(1,Math.abs(n),Math.abs(a))&&Math.abs(r-i)<=y*Math.max(1,Math.abs(r),Math.abs(i))},len:Wt,sub:Ht,mul:Gt,div:Qt,dist:Kt,sqrDist:$t,sqrLen:Zt,forEach:Jt}),tn=e(Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",glMatrix:A,mat2:O,mat2d:P,mat3:B,mat4:G,quat:At,quat2:Rt,vec2:en,vec3:pe,vec4:Ye})),nn={exports:{}};Ut=nn,Xt=function(){function e(t,r,a,i){"object"==typeof r&&(a=r.depth,i=r.prototype,r=r.circular);var o=[],u=[],s="undefined"!=typeof Buffer;return void 0===r&&(r=!0),void 0===a&&(a=1/0),function t(a,f){if(null===a)return null;if(0==f)return a;var c,l;if("object"!=typeof a)return a;if(e.__isArray(a))c=[];else if(e.__isRegExp(a))c=new RegExp(a.source,n(a)),a.lastIndex&&(c.lastIndex=a.lastIndex);else if(e.__isDate(a))c=new Date(a.getTime());else{if(s&&Buffer.isBuffer(a))return c=Buffer.allocUnsafe?Buffer.allocUnsafe(a.length):new Buffer(a.length),a.copy(c),c;void 0===i?(l=Object.getPrototypeOf(a),c=Object.create(l)):(c=Object.create(i),l=i)}if(r){var h=o.indexOf(a);if(-1!=h)return u[h];o.push(a),u.push(c)}for(var d in a){var m;l&&(m=Object.getOwnPropertyDescriptor(l,d)),m&&null==m.set||(c[d]=t(a[d],f-1))}return c}(t,a)}function t(e){return Object.prototype.toString.call(e)}function n(e){var t="";return e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),t}return e.clonePrototype=function(e){if(null===e)return null;var t=function(){};return t.prototype=e,new t},e.__objToStr=t,e.__isDate=function(e){return"object"==typeof e&&"[object Date]"===t(e)},e.__isArray=function(e){return"object"==typeof e&&"[object Array]"===t(e)},e.__isRegExp=function(e){return"object"==typeof e&&"[object RegExp]"===t(e)},e.__getRegExpFlags=n,e}(),Ut.exports&&(Ut.exports=Xt);var rn=nn.exports;const an=tn.mat4,on=function(e,t){return e=e||{},Object.keys(t).forEach((function(n){void 0===e[n]&&(e[n]=rn(t[n]))})),e};var un=function(e,t={}){const n=(t=on(t,{speed:.005,onRotate:function(){},drag:0,invert:!1,hideCursor:!1})).invert?-1:1,r=an.create();let a=!1,i=e.style.cursor;const o={x:0,y:0,dx:0,dy:0,down:!1};function u(e,n){const a=an.create();an.rotateY(a,a,e*t.speed),an.rotateX(a,a,n*t.speed),an.multiply(r,a,r),t.onRotate()}function s(n){o.x=n.clientX,o.y=n.clientY,o.dx=0,o.dy=0,o.down=!0,e.setPointerCapture(n.pointerId),t.hideCursor&&(i=e.style.cursor,e.style.cursor="none"),n.preventDefault()}function f(){o.down=!1,e.style.cursor=i}function c(e){o.down&&(o.dx=n*(e.clientX-o.x),o.dy=n*(e.clientY-o.y),o.x=e.clientX,o.y=e.clientY,u(o.dx,o.dy))}function l(t){e.releasePointerCapture(t.pointerId)}return function e(){a||(requestAnimationFrame(e),o.down&&(o.dx=0,o.dy=0),Math.abs(o.dx*t.speed)<1e-4&&Math.abs(o.dy*t.speed)<1e-4&&(o.dx=0,o.dy=0),0===o.dx&&0===o.dy||(o.dx-=o.dx*t.drag,o.dy-=o.dy*t.drag,u(o.dx,o.dy)))}(),e.addEventListener("pointerdown",s),e.addEventListener("pointerup",f),e.addEventListener("pointermove",c),e.addEventListener("pointercancel",l),{spin:function(e,t){o.dx=e,o.dy=t},rotation:r,dispose:function(){e.removeEventListener("pointerdown",s),e.removeEventListener("pointerup",f),e.removeEventListener("pointermove",c),e.removeEventListener("pointercancel",l),a=!0}}};export{n as R,d as a,h as b,u as c,l as d,m as e,c as f,g,s as h,o as i,a as j,f as l,p as m,b as n,i as p,v as s,un as t}; 2 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Rounded Box Demo 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Rounded Box Demo 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /example/main.ts: -------------------------------------------------------------------------------- 1 | import REGL from "regl"; 2 | import { mat4 } from "gl-matrix"; 3 | import Trackball from "trackball-controller"; 4 | import { generateRoundedBox } from "../src/index"; 5 | 6 | import { textureData } from "./texture"; 7 | 8 | const regl = REGL(); 9 | const canvas = document.getElementsByTagName("canvas")[0]; 10 | canvas.style.touchAction = "none"; 11 | 12 | const texture = regl.texture({ 13 | data: textureData, 14 | width: 512, 15 | height: 512, 16 | format: "alpha", 17 | wrap: "repeat", 18 | min: "linear mipmap linear", 19 | mag: "linear", 20 | }); 21 | 22 | const render = regl({ 23 | vert: ` 24 | precision mediump float; 25 | attribute vec3 position, normal; 26 | uniform mat4 model, view, projection; 27 | varying vec3 vNormal, voNormal, vPos; 28 | void main() { 29 | gl_Position = projection * view * model * vec4(position, 1); 30 | vNormal = (model * vec4(normal, 1)).xyz; 31 | voNormal = normal; 32 | vPos = position.xyz; 33 | }`, 34 | frag: ` 35 | precision mediump float; 36 | uniform sampler2D texture; 37 | varying vec3 vNormal, voNormal, vPos; 38 | void main() { 39 | vec3 onormal = normalize(voNormal); 40 | vec3 blend = abs(onormal); 41 | blend /= blend.x + blend.y + blend.z; 42 | vec3 texel = vPos; 43 | float tex = 0.0; 44 | tex += blend.x * texture2D(texture, texel.yz).a; 45 | tex += blend.y * texture2D(texture, texel.xz).a; 46 | tex += blend.z * texture2D(texture, texel.xy).a; 47 | vec3 lightDir = normalize(vec3(1,0,2)); 48 | float intensity = 0.5 + 0.5 * clamp(dot(normalize(vNormal), lightDir), 0.0, 1.0); 49 | vec3 color = intensity * mix(vec3(0.5,0.0,0), vec3(1,0.5,0.5), tex) + vec3(pow(intensity, 257.0)); 50 | gl_FragColor = vec4(color,1); 51 | }`, 52 | attributes: { 53 | position: regl.prop("positions"), 54 | normal: regl.prop("normals"), 55 | }, 56 | uniforms: { 57 | texture, 58 | model: regl.prop("model"), 59 | view: regl.prop("view"), 60 | projection: regl.prop("projection"), 61 | }, 62 | cull: { 63 | enable: true, 64 | face: "back", 65 | }, 66 | elements: regl.prop("cells"), 67 | viewport: regl.prop("viewport"), 68 | }); 69 | 70 | const trackball = new Trackball(canvas, { drag: 0.01 }); 71 | trackball.spin(20, 3); 72 | 73 | const view = mat4.lookAt(mat4.create(), [0, 0, 3], [0, 0, 0], [0, 1, 0]); 74 | 75 | const box = generateRoundedBox({ width: 1, height: 1.25, depth: 1.5 }); 76 | const positions = regl.buffer(box.positions); 77 | const normals = regl.buffer(box.normals); 78 | const cells = regl.elements(box.cells); 79 | 80 | function loop() { 81 | const projection = mat4.perspective(mat4.create(), Math.PI / 3, canvas.width / canvas.height, 0.1, 100); 82 | const viewport = { x: 0, y: 0, width: canvas.width, height: canvas.height }; 83 | regl.clear({ 84 | color: [1, 1, 1, 1], 85 | depth: 1, 86 | }); 87 | render({ 88 | positions, 89 | normals, 90 | cells, 91 | count: box.positions.length, 92 | model: trackball.rotation, 93 | view, 94 | projection, 95 | viewport, 96 | }); 97 | requestAnimationFrame(loop); 98 | } 99 | 100 | loop(); 101 | -------------------------------------------------------------------------------- /example/texture.ts: -------------------------------------------------------------------------------- 1 | const size = 512; 2 | const count = 255; 3 | 4 | export const textureData = new Uint8Array(size * size); 5 | textureData.fill(255); 6 | 7 | const walkers: { color: number; x: number; y: number }[] = []; 8 | 9 | for (let i = 0; i < count; i++) { 10 | walkers.push({ 11 | color: 255 - i, 12 | x: Math.floor(Math.random() * size), 13 | y: Math.floor(Math.random() * size), 14 | }); 15 | } 16 | 17 | for (let step = 0; step < 20000; step++) { 18 | for (const walker of walkers) { 19 | if (Math.random() < 0.5) { 20 | walker.x += Math.random() < 0.5 ? 1 : -1; 21 | walker.x = ((walker.x % size) + size) % size; 22 | } else { 23 | walker.y += Math.random() < 0.5 ? 1 : -1; 24 | walker.y = ((walker.y % size) + size) % size; 25 | } 26 | textureData[walker.y * size + walker.x] = walker.color; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /example/types.d.ts: -------------------------------------------------------------------------------- 1 | declare module "trackball-controller"; 2 | -------------------------------------------------------------------------------- /lib/index.d.ts: -------------------------------------------------------------------------------- 1 | interface Options { 2 | width?: number; 3 | height?: number; 4 | depth?: number; 5 | radius?: number; 6 | resolution?: number; 7 | } 8 | export declare function generateRoundedBox(options?: Options): { 9 | positions: number[][]; 10 | normals: number[][]; 11 | cells: number[][]; 12 | }; 13 | export {}; 14 | //# sourceMappingURL=index.d.ts.map -------------------------------------------------------------------------------- /lib/index.d.ts.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiFA,UAAU,OAAO;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAUD,wBAAgB,kBAAkB,CAAC,OAAO,GAAE,OAAY;;;;EAkDvD"} -------------------------------------------------------------------------------- /lib/index.es.js: -------------------------------------------------------------------------------- 1 | var t=Object.defineProperty,r=Object.getOwnPropertySymbols,n=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable,o=(r,n,i)=>n in r?t(r,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[n]=i,e=(t,e)=>{for(var s in e||(e={}))n.call(e,s)&&o(t,s,e[s]);if(r)for(var s of r(e))i.call(e,s)&&o(t,s,e[s]);return t},s=("undefined"!=typeof require&&require,(t,r,n)=>(o(t,"symbol"!=typeof r?r+"":r,n),n)),h="undefined"!=typeof Float32Array?Float32Array:Array;function a(){var t=new h(3);return h!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function u(t){var r=new h(3);return r[0]=t[0],r[1]=t[1],r[2]=t[2],r}function p(t){var r=t[0],n=t[1],i=t[2];return Math.hypot(r,n,i)}function l(t,r,n){var i=new h(3);return i[0]=t,i[1]=r,i[2]=n,i}function c(t,r,n){return t[0]=r[0]-n[0],t[1]=r[1]-n[1],t[2]=r[2]-n[2],t}function f(t,r,n){return t[0]=r[0]*n[0],t[1]=r[1]*n[1],t[2]=r[2]*n[2],t}function g(t,r,n){return t[0]=Math.max(r[0],n[0]),t[1]=Math.max(r[1],n[1]),t[2]=Math.max(r[2],n[2]),t}function d(t,r,n,i){return t[0]=r[0]+n[0]*i,t[1]=r[1]+n[1]*i,t[2]=r[2]+n[2]*i,t}Math.hypot||(Math.hypot=function(){for(var t=0,r=arguments.length;r--;)t+=arguments[r]*arguments[r];return Math.sqrt(t)}),a();const M=[{start:l(.5,-.5,.5),right:l(0,0,-1),up:l(0,1,0)},{start:l(-.5,-.5,-.5),right:l(0,0,1),up:l(0,1,0)},{start:l(-.5,.5,.5),right:l(1,0,0),up:l(0,0,-1)},{start:l(-.5,-.5,-.5),right:l(1,0,0),up:l(0,0,1)},{start:l(-.5,-.5,.5),right:l(1,0,0),up:l(0,1,0)},{start:l(.5,-.5,-.5),right:l(-1,0,0),up:l(0,1,0)}];function b(t,r,n,i,o,e,s){const h=[];for(let u=0;u0&&(e=1/Math.sqrt(e)),t[0]=r[0]*e,t[1]=r[1]*e,t[2]=r[2]*e,t}(a(),c(a(),t,u));return{normal:p,position:d(a(),u,p,n)}}class v{constructor(){s(this,"positions",[]),s(this,"cells",[])}populateCell(t){0===this.cells.length&&this.cells.push([]),3===this.cells[this.cells.length-1].length&&this.cells.push([]),this.cells[this.cells.length-1].push(t)}index(t){for(const p of t){let t=!1;for(let u=0;u[t[0],t[1],t[2]])),normals:w.map((t=>[t[0],t[1],t[2]])),cells:x}}export{x as generateRoundedBox}; 2 | -------------------------------------------------------------------------------- /lib/index.umd.js: -------------------------------------------------------------------------------- 1 | var __defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(t,r,e)=>r in t?__defProp(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,__spreadValues=(t,r)=>{for(var e in r||(r={}))__hasOwnProp.call(r,e)&&__defNormalProp(t,e,r[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(r))__propIsEnum.call(r,e)&&__defNormalProp(t,e,r[e]);return t},__require="undefined"!=typeof require?require:t=>{throw new Error('Dynamic require of "'+t+'" is not supported')},__publicField=(t,r,e)=>(__defNormalProp(t,"symbol"!=typeof r?r+"":r,e),e);!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((t="undefined"!=typeof globalThis?globalThis:t||self)["rounded-box"]={})}(this,(function(t){"use strict";var r=1e-6,e="undefined"!=typeof Float32Array?Float32Array:Array;function o(){var t=new e(3);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function n(t){var r=new e(3);return r[0]=t[0],r[1]=t[1],r[2]=t[2],r}function i(t){var r=t[0],e=t[1],o=t[2];return Math.hypot(r,e,o)}function s(t,r,o){var n=new e(3);return n[0]=t,n[1]=r,n[2]=o,n}function a(t,r,e){return t[0]=r[0]-e[0],t[1]=r[1]-e[1],t[2]=r[2]-e[2],t}function h(t,r,e){return t[0]=r[0]*e[0],t[1]=r[1]*e[1],t[2]=r[2]*e[2],t}function p(t,r,e){return t[0]=Math.max(r[0],e[0]),t[1]=Math.max(r[1],e[1]),t[2]=Math.max(r[2],e[2]),t}function u(t,r,e,o){return t[0]=r[0]+e[0]*o,t[1]=r[1]+e[1]*o,t[2]=r[2]+e[2]*o,t}Math.hypot||(Math.hypot=function(){for(var t=0,r=arguments.length;r--;)t+=arguments[r]*arguments[r];return Math.sqrt(t)}),o();const l=[{start:s(.5,-.5,.5),right:s(0,0,-1),up:s(0,1,0)},{start:s(-.5,-.5,-.5),right:s(0,0,1),up:s(0,1,0)},{start:s(-.5,.5,.5),right:s(1,0,0),up:s(0,0,-1)},{start:s(-.5,-.5,-.5),right:s(1,0,0),up:s(0,0,1)},{start:s(-.5,-.5,.5),right:s(1,0,0),up:s(0,1,0)},{start:s(.5,-.5,-.5),right:s(-1,0,0),up:s(0,1,0)}];function c(t,r,e,n,i,s,a){const h=[];for(let p=0;p0&&(i=1/Math.sqrt(i)),t[0]=r[0]*i,t[1]=r[1]*i,t[2]=r[2]*i,t}(o(),a(o(),t,d));return{normal:_,position:u(o(),d,_,e)}}class d{constructor(){__publicField(this,"positions",[]),__publicField(this,"cells",[])}populateCell(t){0===this.cells.length&&this.cells.push([]),3===this.cells[this.cells.length-1].length&&this.cells.push([]),this.cells[this.cells.length-1].push(t)}index(t){for(const l of t){let t=!1;for(let n=0;n[t[0],t[1],t[2]])),normals:x.map((t=>[t[0],t[1],t[2]])),cells:M}},Object.defineProperty(t,"__esModule",{value:!0}),t[Symbol.toStringTag]="Module"})); 2 | -------------------------------------------------------------------------------- /media/screenshot.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wwwtyro/rounded-box/7959d6382b2ff7aab6f9fc0115eb74cdf1852e69/media/screenshot.webp -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rounded-box", 3 | "version": "0.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "clone": { 8 | "version": "1.0.4", 9 | "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", 10 | "integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=" 11 | }, 12 | "colorette": { 13 | "version": "1.4.0", 14 | "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.4.0.tgz", 15 | "integrity": "sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==", 16 | "dev": true 17 | }, 18 | "defaults": { 19 | "version": "1.0.3", 20 | "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz", 21 | "integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=", 22 | "requires": { 23 | "clone": "^1.0.2" 24 | } 25 | }, 26 | "esbuild": { 27 | "version": "0.12.28", 28 | "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.12.28.tgz", 29 | "integrity": "sha512-pZ0FrWZXlvQOATlp14lRSk1N9GkeJ3vLIwOcUoo3ICQn9WNR4rWoNi81pbn6sC1iYUy7QPqNzI3+AEzokwyVcA==", 30 | "dev": true 31 | }, 32 | "fsevents": { 33 | "version": "2.3.2", 34 | "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", 35 | "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", 36 | "dev": true, 37 | "optional": true 38 | }, 39 | "function-bind": { 40 | "version": "1.1.1", 41 | "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", 42 | "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", 43 | "dev": true 44 | }, 45 | "gl-matrix": { 46 | "version": "3.3.0", 47 | "resolved": "https://registry.npmjs.org/gl-matrix/-/gl-matrix-3.3.0.tgz", 48 | "integrity": "sha512-COb7LDz+SXaHtl/h4LeaFcNdJdAQSDeVqjiIihSXNrkWObZLhDI4hIkZC11Aeqp7bcE72clzB0BnDXr2SmslRA==" 49 | }, 50 | "has": { 51 | "version": "1.0.3", 52 | "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", 53 | "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", 54 | "dev": true, 55 | "requires": { 56 | "function-bind": "^1.1.1" 57 | } 58 | }, 59 | "is-core-module": { 60 | "version": "2.6.0", 61 | "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.6.0.tgz", 62 | "integrity": "sha512-wShG8vs60jKfPWpF2KZRaAtvt3a20OAn7+IJ6hLPECpSABLcKtFKTTI4ZtH5QcBruBHlq+WsdHWyz0BCZW7svQ==", 63 | "dev": true, 64 | "requires": { 65 | "has": "^1.0.3" 66 | } 67 | }, 68 | "nanoid": { 69 | "version": "3.1.25", 70 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.25.tgz", 71 | "integrity": "sha512-rdwtIXaXCLFAQbnfqDRnI6jaRHp9fTcYBjtFKE8eezcZ7LuLjhUaQGNeMXf1HmRoCH32CLz6XwX0TtxEOS/A3Q==", 72 | "dev": true 73 | }, 74 | "path-parse": { 75 | "version": "1.0.7", 76 | "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", 77 | "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", 78 | "dev": true 79 | }, 80 | "pepjs": { 81 | "version": "0.4.3", 82 | "resolved": "https://registry.npmjs.org/pepjs/-/pepjs-0.4.3.tgz", 83 | "integrity": "sha1-FggOlwqud5kTdWwtrviOqnSG30E=" 84 | }, 85 | "postcss": { 86 | "version": "8.3.6", 87 | "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.3.6.tgz", 88 | "integrity": "sha512-wG1cc/JhRgdqB6WHEuyLTedf3KIRuD0hG6ldkFEZNCjRxiC+3i6kkWUUbiJQayP28iwG35cEmAbe98585BYV0A==", 89 | "dev": true, 90 | "requires": { 91 | "colorette": "^1.2.2", 92 | "nanoid": "^3.1.23", 93 | "source-map-js": "^0.6.2" 94 | } 95 | }, 96 | "regl": { 97 | "version": "2.1.0", 98 | "resolved": "https://registry.npmjs.org/regl/-/regl-2.1.0.tgz", 99 | "integrity": "sha512-oWUce/aVoEvW5l2V0LK7O5KJMzUSKeiOwFuJehzpSFd43dO5spP9r+sSUfhKtsky4u6MCqWJaRL+abzExynfTg==" 100 | }, 101 | "resolve": { 102 | "version": "1.20.0", 103 | "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.20.0.tgz", 104 | "integrity": "sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==", 105 | "dev": true, 106 | "requires": { 107 | "is-core-module": "^2.2.0", 108 | "path-parse": "^1.0.6" 109 | } 110 | }, 111 | "rollup": { 112 | "version": "2.56.3", 113 | "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.56.3.tgz", 114 | "integrity": "sha512-Au92NuznFklgQCUcV96iXlxUbHuB1vQMaH76DHl5M11TotjOHwqk9CwcrT78+Tnv4FN9uTBxq6p4EJoYkpyekg==", 115 | "dev": true, 116 | "requires": { 117 | "fsevents": "~2.3.2" 118 | } 119 | }, 120 | "source-map-js": { 121 | "version": "0.6.2", 122 | "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-0.6.2.tgz", 123 | "integrity": "sha512-/3GptzWzu0+0MBQFrDKzw/DvvMTUORvgY6k6jd/VS6iCR4RDTKWH6v6WPwQoUO8667uQEf9Oe38DxAYWY5F/Ug==", 124 | "dev": true 125 | }, 126 | "trackball-controller": { 127 | "version": "2.0.0", 128 | "resolved": "https://registry.npmjs.org/trackball-controller/-/trackball-controller-2.0.0.tgz", 129 | "integrity": "sha512-GNm5CZNKbXlWo1twjDbta3+T8+DthM5wLruMg7ZXk0nYBTgSQzYHh7ih2SmfDk1lvk6k+qQ0pfbyLCMn/n/uwg==", 130 | "requires": { 131 | "defaults": "^1.0.3", 132 | "gl-matrix": "^2.7.1", 133 | "pepjs": "^0.4.3" 134 | }, 135 | "dependencies": { 136 | "gl-matrix": { 137 | "version": "2.8.1", 138 | "resolved": "https://registry.npmjs.org/gl-matrix/-/gl-matrix-2.8.1.tgz", 139 | "integrity": "sha512-0YCjVpE3pS5XWlN3J4X7AiAx65+nqAI54LndtVFnQZB6G/FVLkZH8y8V6R3cIoOQR4pUdfwQGd1iwyoXHJ4Qfw==" 140 | } 141 | } 142 | }, 143 | "typescript": { 144 | "version": "4.4.3", 145 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.3.tgz", 146 | "integrity": "sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA==", 147 | "dev": true 148 | }, 149 | "vite": { 150 | "version": "2.5.10", 151 | "resolved": "https://registry.npmjs.org/vite/-/vite-2.5.10.tgz", 152 | "integrity": "sha512-0ObiHTi5AHyXdJcvZ67HMsDgVpjT5RehvVKv6+Q0jFZ7zDI28PF5zK9mYz2avxdA+4iJMdwCz6wnGNnn4WX5Gg==", 153 | "dev": true, 154 | "requires": { 155 | "esbuild": "^0.12.17", 156 | "fsevents": "~2.3.2", 157 | "postcss": "^8.3.6", 158 | "resolve": "^1.20.0", 159 | "rollup": "^2.38.5" 160 | } 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rounded-box", 3 | "version": "1.0.4", 4 | "description": "Generates a rounded box mesh centered on the origin with configurable dimensions, corner and edge radius, and resolution.", 5 | "keywords": [ 6 | "3D", 7 | "rounded box", 8 | "rounded cube", 9 | "box", 10 | "cube", 11 | "mesh", 12 | "geometry", 13 | "procedural", 14 | "webgl" 15 | ], 16 | "author": { 17 | "name": "Rye Terrell", 18 | "email": "ryeterrell@ryeterrell.net", 19 | "url": "https://wwwtyro.net" 20 | }, 21 | "homepage": "https://github.com/wwwtyro/rounded-box", 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/wwwtyro/rounded-box.git" 25 | }, 26 | "license": "Unlicense", 27 | "files": [ 28 | "lib" 29 | ], 30 | "main": "./lib/index.umd.js", 31 | "module": "./lib/index.es.js", 32 | "types": "./lib/index", 33 | "scripts": { 34 | "dev": "vite --config vite.example-config.js --host 0.0.0.0", 35 | "build-lib": "tsc && vite --config vite.lib-config.js build", 36 | "build-example": "tsc && vite --config vite.example-config.js build", 37 | "clean": "rm -rf lib docs", 38 | "build": "npm run clean && npm run build-lib && npm run build-example" 39 | }, 40 | "exports": { 41 | ".": { 42 | "import": "./lib/index.es.js", 43 | "require": "./lib/index.umd.js" 44 | } 45 | }, 46 | "devDependencies": { 47 | "typescript": "^4.3.2", 48 | "regl": "^2.1.0", 49 | "vite": "^2.5.4", 50 | "trackball-controller": "^2.0.0" 51 | }, 52 | "dependencies": { 53 | "gl-matrix": "^3.3.0" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { vec3 } from "gl-matrix"; 2 | 3 | const faces = [ 4 | { start: vec3.fromValues(+0.5, -0.5, +0.5), right: vec3.fromValues(0, 0, -1), up: vec3.fromValues(0, +1, 0) }, // Positive X 5 | { start: vec3.fromValues(-0.5, -0.5, -0.5), right: vec3.fromValues(0, 0, +1), up: vec3.fromValues(0, +1, 0) }, // Negative X 6 | { start: vec3.fromValues(-0.5, +0.5, +0.5), right: vec3.fromValues(+1, 0, 0), up: vec3.fromValues(0, 0, -1) }, // Positive Y 7 | { start: vec3.fromValues(-0.5, -0.5, -0.5), right: vec3.fromValues(+1, 0, 0), up: vec3.fromValues(0, 0, +1) }, // Negative Y 8 | { start: vec3.fromValues(-0.5, -0.5, +0.5), right: vec3.fromValues(+1, 0, 0), up: vec3.fromValues(0, +1, 0) }, // Positive Z 9 | { start: vec3.fromValues(+0.5, -0.5, -0.5), right: vec3.fromValues(-1, 0, 0), up: vec3.fromValues(0, +1, 0) }, // Negative Z 10 | ]; 11 | 12 | function grid( 13 | start: vec3, 14 | right: vec3, 15 | up: vec3, 16 | width: number, 17 | height: number, 18 | widthSteps: number, 19 | heightSteps: number 20 | ) { 21 | const positions: vec3[] = []; 22 | for (let x = 0; x < widthSteps; x++) { 23 | for (let y = 0; y < heightSteps; y++) { 24 | const pa = vec3.scaleAndAdd(vec3.create(), start, right, (width * x) / widthSteps); 25 | vec3.scaleAndAdd(pa, pa, up, (height * y) / heightSteps); 26 | const pb = vec3.scaleAndAdd(vec3.create(), pa, right, width / widthSteps); 27 | const pc = vec3.scaleAndAdd(vec3.create(), pb, up, height / heightSteps); 28 | const pd = vec3.scaleAndAdd(vec3.create(), pa, up, height / heightSteps); 29 | positions.push(pa, pb, pc, pa, pc, pd); 30 | } 31 | } 32 | return positions; 33 | } 34 | 35 | function roundedBoxPoint(point: vec3, size: vec3, radius: number) { 36 | const boundMax = vec3.multiply(vec3.create(), size, vec3.fromValues(0.5, 0.5, 0.5)); 37 | vec3.subtract(boundMax, boundMax, [radius, radius, radius]); 38 | const boundMin = vec3.multiply(vec3.create(), size, vec3.fromValues(-0.5, -0.5, -0.5)); 39 | vec3.add(boundMin, boundMin, [radius, radius, radius]); 40 | const clamped = vec3.max(vec3.create(), boundMin, point); 41 | vec3.min(clamped, boundMax, clamped); 42 | const normal = vec3.normalize(vec3.create(), vec3.subtract(vec3.create(), point, clamped)); 43 | const position = vec3.scaleAndAdd(vec3.create(), clamped, normal, radius); 44 | return { 45 | normal, 46 | position, 47 | }; 48 | } 49 | 50 | class Indexer { 51 | public positions: vec3[] = []; 52 | public cells: number[][] = []; 53 | 54 | populateCell(index: number) { 55 | if (this.cells.length === 0) { 56 | this.cells.push([]); 57 | } 58 | if (this.cells[this.cells.length - 1].length === 3) { 59 | this.cells.push([]); 60 | } 61 | this.cells[this.cells.length - 1].push(index); 62 | } 63 | 64 | index(points: vec3[]) { 65 | for (const point of points) { 66 | let populated = false; 67 | for (let i = 0; i < this.positions.length; i++) { 68 | if (vec3.equals(this.positions[i], point)) { 69 | this.populateCell(i); 70 | populated = true; 71 | break; 72 | } 73 | } 74 | if (!populated) { 75 | this.positions.push(vec3.clone(point)); 76 | this.populateCell(this.positions.length - 1); 77 | } 78 | } 79 | } 80 | } 81 | 82 | interface Options { 83 | width?: number; 84 | height?: number; 85 | depth?: number; 86 | radius?: number; 87 | resolution?: number; 88 | } 89 | 90 | const DEFAULTS = { 91 | width: 1, 92 | height: 1, 93 | depth: 1, 94 | radius: 0.125, 95 | resolution: 5, 96 | }; 97 | 98 | export function generateRoundedBox(options: Options = {}) { 99 | const { width, height, depth, radius, resolution } = { ...DEFAULTS, ...options }; 100 | const size = vec3.fromValues(width, height, depth); 101 | vec3.max(size, size, [2 * radius, 2 * radius, 2 * radius]); 102 | 103 | const indexer = new Indexer(); 104 | for (const face of faces) { 105 | const width = vec3.length(vec3.multiply(vec3.create(), face.right, size)); 106 | const height = vec3.length(vec3.multiply(vec3.create(), face.up, size)); 107 | const s0 = vec3.multiply(vec3.create(), face.start, size); 108 | const s1 = vec3.scaleAndAdd(vec3.create(), s0, face.right, radius); 109 | const s2 = vec3.scaleAndAdd(vec3.create(), s0, face.right, width - radius); 110 | const s3 = vec3.scaleAndAdd(vec3.create(), s0, face.up, radius); 111 | const s4 = vec3.scaleAndAdd(vec3.create(), s3, face.right, radius); 112 | const s5 = vec3.scaleAndAdd(vec3.create(), s3, face.right, width - radius); 113 | const s6 = vec3.scaleAndAdd(vec3.create(), s0, face.up, height - radius); 114 | const s7 = vec3.scaleAndAdd(vec3.create(), s6, face.right, radius); 115 | const s8 = vec3.scaleAndAdd(vec3.create(), s6, face.right, width - radius); 116 | // Each corner grid. 117 | indexer.index(grid(s0, face.right, face.up, radius, radius, resolution, resolution)); 118 | indexer.index(grid(s2, face.right, face.up, radius, radius, resolution, resolution)); 119 | indexer.index(grid(s6, face.right, face.up, radius, radius, resolution, resolution)); 120 | indexer.index(grid(s8, face.right, face.up, radius, radius, resolution, resolution)); 121 | // Left and right side. 122 | indexer.index(grid(s3, face.right, face.up, radius, height - 2 * radius, resolution, 1)); 123 | indexer.index(grid(s5, face.right, face.up, radius, height - 2 * radius, resolution, 1)); 124 | // Top and bottom. 125 | indexer.index(grid(s1, face.right, face.up, width - 2 * radius, radius, 1, resolution)); 126 | indexer.index(grid(s7, face.right, face.up, width - 2 * radius, radius, 1, resolution)); 127 | // Middle face. 128 | indexer.index(grid(s4, face.right, face.up, width - 2 * radius, height - 2 * radius, 1, 1)); 129 | } 130 | 131 | const { positions, cells } = indexer; 132 | 133 | const normals: vec3[] = []; 134 | 135 | for (const position of positions) { 136 | const rounded = roundedBoxPoint(position, size, radius); 137 | position[0] = rounded.position[0]; 138 | position[1] = rounded.position[1]; 139 | position[2] = rounded.position[2]; 140 | normals.push(rounded.normal); 141 | } 142 | 143 | return { 144 | positions: positions.map((p) => [p[0], p[1], p[2]]), 145 | normals: normals.map((n) => [n[0], n[1], n[2]]), 146 | cells, 147 | }; 148 | } 149 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "module": "ESNext", 6 | "lib": ["ESNext", "DOM"], 7 | "moduleResolution": "Node", 8 | "strict": true, 9 | "sourceMap": true, 10 | "resolveJsonModule": true, 11 | "esModuleInterop": true, 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true, 14 | "noImplicitReturns": true, 15 | "emitDeclarationOnly": true, 16 | "declaration": true, 17 | "declarationDir": "./lib", 18 | "declarationMap": true 19 | }, 20 | "include": ["./src"] 21 | } 22 | -------------------------------------------------------------------------------- /vite.example-config.js: -------------------------------------------------------------------------------- 1 | // vite.config.js 2 | const path = require("path"); 3 | const { defineConfig } = require("vite"); 4 | 5 | module.exports = defineConfig({ 6 | root: "./example", 7 | base: "./", 8 | build: { 9 | outDir: "../docs", 10 | emptyOutDir: true, 11 | }, 12 | rollupOptions: { 13 | input: { 14 | main: path.resolve(__dirname, "example/index.html"), 15 | }, 16 | }, 17 | }); 18 | -------------------------------------------------------------------------------- /vite.lib-config.js: -------------------------------------------------------------------------------- 1 | // vite.config.js 2 | const path = require("path"); 3 | const { defineConfig } = require("vite"); 4 | 5 | module.exports = defineConfig({ 6 | build: { 7 | outDir: "lib", 8 | lib: { 9 | name: "rounded-box", 10 | entry: path.resolve(__dirname, "src/index.ts"), 11 | fileName: (format) => `index.${format}.js`, 12 | }, 13 | }, 14 | }); 15 | --------------------------------------------------------------------------------