/*! For license information please see pacioli-0.6.0.bundle.js.LICENSE.txt */ var Pacioli;(()=>{var __webpack_modules__={84(t,e,n){const i=n(96).J,r=Math.PI/180,s={archimedean:g,rectangular:function(t){var e=4*t[0]/t[1],n=0,i=0;return function(t){var r=t<0?-1:1;switch(Math.sqrt(1+4*r*t)-r&3){case 0:n+=e;break;case 1:i+=4;break;case 2:n-=e;break;default:i-=4}return[n,i]}}},a=2048;function o(t){return t.text}function l(){return"serif"}function c(){return"normal"}function u(t){return Math.sqrt(t.value)}function h(){return 1}function d(t,e,n,i){if(!e.sprite){var s=t.context,o=t.ratio;s.clearRect(0,0,2048/o,a/o);var l=0,c=0,u=0,h=n.length;for(--i;++i>5<<5,x=~~Math.max(Math.abs(m+g),Math.abs(m-g))}else _=_+31>>5<<5;if(x>u&&(u=x),l+_>=2048&&(l=0,c+=u,u=0),c+x>=a)break;s.translate((l+(_>>1))/o,(c+(x>>1))/o),e.rotate&&s.rotate(e.rotate*r),s.fillText(e.text,h,0),e.padding&&(s.lineWidth=2*e.padding,s.strokeText(e.text,h,0)),s.restore(),e.width=_,e.height=x,e.xoff=l,e.yoff=c,e.x1=_>>1,e.y1=x>>1,e.x0=-e.x1,e.y0=-e.y1,e.hasText=!0,l+=_}for(var _=s.getImageData(0,0,2048/o,a/o).data,x=[];--i>=0;)if((e=n[i]).hasText){for(var y=e.width,b=y>>5,w=e.y1-e.y0,M=0;M>5),C=_[2048*(c+T)+(l+M)<<2]?1<<31-M%32:0;x[A]|=C,S|=C}S?E=T:(e.y0++,w--,T--,c++)}e.y1=e.y0+E,e.sprite=x.slice(0,(e.y1-e.y0)*b)}}}function p(t,e,n){n>>=5;for(var i,r=t.sprite,s=t.width>>5,a=t.x-(s<<4),o=127&a,l=32-o,c=t.y1-t.y0,u=(t.y+t.y0)*n+(a>>5),h=0;h>>o:0))&e[u+d])return!0;u+=n}return!1}function f(t,e){var n=t[0],i=t[1];e.x+e.x0i.x&&(i.x=e.x+e.x1),e.y+e.y1>i.y&&(i.y=e.y+e.y1)}function m(t,e){return t.x+t.x1>e[0].x&&t.x+t.x0e[0].y&&t.y+t.y030*(~~(6*A())-3),R={},P=v;function N(e,n,i){t[0],t[1];for(var r,s,a,o=n.x,l=n.y,c=Math.sqrt(t[0]*t[0]+t[1]*t[1]),u=w(t),h=A()<.5?1:-1,d=-h;(r=u(d+=h))&&(s=~~r[0],a=~~r[1],!(Math.min(Math.abs(s),Math.abs(a))>=c));)if(n.x=o+s,n.y=l+a,!(n.x+n.x0<0||n.y+n.y0<0||n.x+n.x1>t[0]||n.y+n.y1>t[1])&&(!i||m(n,i))&&!p(n,e,t[0])){for(var f,g=n.sprite,v=n.width>>5,_=t[0]>>5,x=n.x-(v<<4),y=127&x,b=32-y,M=n.y1-n.y0,S=(n.y+n.y0)*_+(x>>5),E=0;E>>y:0);S+=_}return!0}return!1}return R.canvas=function(t){return arguments.length?(P=_(t),R):P},R.start=function(){var i=function(t){const e=t.getContext("2d",{willReadFrequently:!0});t.width=t.height=1;const n=Math.sqrt(e.getImageData(0,0,1,1).data.length>>2);return t.width=2048/n,t.height=a/n,e.fillStyle=e.strokeStyle="red",{context:e,ratio:n}}(P()),s=function(t){for(var e=[],n=-1;++n>5)*t[1]),o=null,l=M.length,c=-1,u=[],h=M.map(function(t,i){return t.text=e.call(this,t,i),t.font=n.call(this,t,i),t.style=x.call(this,t,i),t.weight=y.call(this,t,i),t.rotate=C.call(this,t,i),t.size=~~r.call(this,t,i),t.padding=b.call(this,t,i),t}).sort(function(t,e){return e.size-t.size});return T&&clearInterval(T),T=setInterval(p,0),p(),R;function p(){for(var e=Date.now();Date.now()-e>1,n.y=t[1]*(A()+.5)>>1,d(i,n,h,c),n.hasText&&N(s,n,o)&&(u.push(n),E.call("word",R,n),o?f(o,n):o=[{x:n.x+n.x0,y:n.y+n.y0},{x:n.x+n.x1,y:n.y+n.y1}],n.x-=t[0]>>1,n.y-=t[1]>>1)}c>=l&&(R.stop(),E.call("end",R,u,o))}},R.stop=function(){T&&(clearInterval(T),T=null);for(const t of M)delete t.sprite;return R},R.timeInterval=function(t){return arguments.length?(S=null==t?1/0:t,R):S},R.words=function(t){return arguments.length?(M=t,R):M},R.size=function(e){return arguments.length?(t=[+e[0],+e[1]],R):t},R.font=function(t){return arguments.length?(n=_(t),R):n},R.fontStyle=function(t){return arguments.length?(x=_(t),R):x},R.fontWeight=function(t){return arguments.length?(y=_(t),R):y},R.rotate=function(t){return arguments.length?(C=_(t),R):C},R.text=function(t){return arguments.length?(e=_(t),R):e},R.spiral=function(t){return arguments.length?(w=s[t]||t,R):w},R.fontSize=function(t){return arguments.length?(r=_(t),R):r},R.padding=function(t){return arguments.length?(b=_(t),R):b},R.random=function(t){return arguments.length?(A=t,R):A},R.on=function(){var t=E.on.apply(E,arguments);return t===E?R:t},R}},96(t,e,n){"use strict";n.d(e,{J:()=>l});var i={value:function(){}};function r(){for(var t,e=0,n=arguments.length,i={};e=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!i.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),l=-1,c=s.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++l0)for(var n,i,r=new Array(n),s=0;s3;r-=4)t(),t(),t(),t();for(;r>0;)t(),r--;if(new Date-n>e)break}for(r=i;r>3;r-=4)t(),t(),t(),t();for(;r>0;)t(),r--;return 1e3*(3*i-1)/(new Date-n)},numeric._myIndexOf=function(t){var e,n=this.length;for(e=0;enumeric.largeArray)return n.push("...Large Array..."),!0;for(c=!1,n.push("["),r=0;r0&&(n.push(","),c&&n.push("\n ")),c=t(i[r]);return n.push("]"),!0}for(r in n.push("{"),c=!1,i)i.hasOwnProperty(r)&&(c&&n.push(",\n"),c=!0,n.push(r),n.push(": \n"),t(i[r]));return n.push("}"),!0}(t),n.join("")},numeric.parseDate=function(t){return function t(e){if("string"==typeof e)return Date.parse(e.replace(/-/g,"/"));if(!(e instanceof Array))throw new Error("parseDate: parameter must be arrays of strings");var n,i=[];for(n=0;n0){for(r[l]=[],e=0;e>>8^r[255&(s^t[i])];return-1^s}var n,i,r,s,a,o,l,c,u,h,d=t[0].length,p=t[0][0].length,f=[137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,p>>24&255,p>>16&255,p>>8&255,255&p,d>>24&255,d>>16&255,d>>8&255,255&d,8,2,0,0,0,-1,-2,-3,-4,-5,-6,-7,-8,73,68,65,84,8,29];for(h=e(f,12,29),f[29]=h>>24&255,f[30]=h>>16&255,f[31]=h>>8&255,f[32]=255&h,n=1,i=0,l=0;l>8&255,f.push(a),f.push(o),f.push(255&~a),f.push(255&~o),0===l&&f.push(0),c=0;c255?255:a<0?0:Math.round(a)))%65521))%65521,f.push(a);f.push(0)}return u=(i<<16)+n,f.push(u>>24&255),f.push(u>>16&255),f.push(u>>8&255),f.push(255&u),s=f.length-41,f[33]=s>>24&255,f[34]=s>>16&255,f[35]=s>>8&255,f[36]=255&s,h=e(f,37),f.push(h>>24&255),f.push(h>>16&255),f.push(h>>8&255),f.push(255&h),f.push(0),f.push(0),f.push(0),f.push(0),f.push(73),f.push(69),f.push(78),f.push(68),f.push(174),f.push(66),f.push(96),f.push(130),"data:image/png;base64,"+function(t){var e,n,i,r,s,a,o,l=t.length,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",u="";for(e=0;e>4),a=((15&i)<<2)+((r=t[e+2])>>6),o=63&r,e+1>=l?a=o=64:e+2>=l&&(o=64),u+=c.charAt(n>>2)+c.charAt(s)+c.charAt(a)+c.charAt(o);return u}(f)},numeric._dim=function(t){for(var e=[];"object"==typeof t;)e.push(t.length),t=t[0];return e},numeric.dim=function(t){var e;return"object"==typeof t?"object"==typeof(e=t[0])?"object"==typeof e[0]?numeric._dim(t):[t.length,e.length]:[t.length]:[]},numeric.mapreduce=function(t,e){return Function("x","accum","_s","_k",'if(typeof accum === "undefined") accum = '+e+';\nif(typeof x === "number") { var xi = x; '+t+'; return accum; }\nif(typeof _s === "undefined") _s = numeric.dim(x);\nif(typeof _k === "undefined") _k = 0;\nvar _n = _s[_k];\nvar i,xi;\nif(_k < _s.length-1) {\n for(i=_n-1;i>=0;i--) {\n accum = arguments.callee(x[i],accum,_s,_k+1);\n } return accum;\n}\nfor(i=_n-1;i>=1;i-=2) { \n xi = x[i];\n '+t+";\n xi = x[i-1];\n "+t+";\n}\nif(i === 0) {\n xi = x[i];\n "+t+"\n}\nreturn accum;")},numeric.mapreduce2=function(t,e){return Function("x","var n = x.length;\nvar i,xi;\n"+e+";\nfor(i=n-1;i!==-1;--i) { \n xi = x[i];\n "+t+";\n}\nreturn accum;")},numeric.same=function t(e,n){var i,r;if(!(e instanceof Array&&n instanceof Array))return!1;if((r=e.length)!==n.length)return!1;for(i=0;i=0;i-=2)s[i+1]=e,s[i]=e;return-1===i&&(s[0]=e),s}for(i=r-1;i>=0;i--)s[i]=numeric.rep(t,e,n+1);return s},numeric.dotMMsmall=function(t,e){var n,i,r,s,a,o,l,c,u,h,d;for(s=t.length,a=e.length,o=e[0].length,l=Array(s),n=s-1;n>=0;n--){for(c=Array(o),u=t[n],r=o-1;r>=0;r--){for(h=u[a-1]*e[a-1][r],i=a-2;i>=1;i-=2)d=i-1,h+=u[i]*e[i][r]+u[d]*e[d][r];0===i&&(h+=u[0]*e[0][r]),c[r]=h}l[n]=c}return l},numeric._getCol=function(t,e,n){var i;for(i=t.length-1;i>0;--i)n[i]=t[i][e],n[--i]=t[i][e];0===i&&(n[0]=t[0][e])},numeric.dotMMbig=function(t,e){var n,i,r,s=numeric._getCol,a=e.length,o=Array(a),l=t.length,c=e[0].length,u=new Array(l),h=numeric.dotVV;for(--a,i=--l;-1!==i;--i)u[i]=Array(c);for(i=--c;-1!==i;--i)for(s(e,i,o),r=l;-1!==r;--r)n=t[r],u[r][i]=h(n,o);return u},numeric.dotMV=function(t,e){var n,i=t.length,r=(e.length,Array(i)),s=numeric.dotVV;for(n=i-1;n>=0;n--)r[n]=s(t[n],e);return r},numeric.dotVM=function(t,e){var n,i,r,s,a,o,l;for(r=t.length,s=e[0].length,a=Array(s),i=s-1;i>=0;i--){for(o=t[r-1]*e[r-1][i],n=r-2;n>=1;n-=2)l=n-1,o+=t[n]*e[n][i]+t[l]*e[l][i];0===n&&(o+=t[0]*e[0][i]),a[i]=o}return a},numeric.dotVV=function(t,e){var n,i,r=t.length,s=t[r-1]*e[r-1];for(n=r-2;n>=1;n-=2)i=n-1,s+=t[n]*e[n]+t[i]*e[i];return 0===n&&(s+=t[0]*e[0]),s},numeric.dot=function(t,e){var n=numeric.dim;switch(1e3*n(t).length+n(e).length){case 2002:return e.length<10?numeric.dotMMsmall(t,e):numeric.dotMMbig(t,e);case 2001:return numeric.dotMV(t,e);case 1002:return numeric.dotVM(t,e);case 1001:return numeric.dotVV(t,e);case 1e3:return numeric.mulVS(t,e);case 1:return numeric.mulSV(t,e);case 0:return t*e;default:throw new Error("numeric.dot only works on vectors and matrices")}},numeric.diag=function(t){var e,n,i,r,s=t.length,a=Array(s);for(e=s-1;e>=0;e--){for(r=Array(s),n=e+2,i=s-1;i>=n;i-=2)r[i]=0,r[i-1]=0;for(i>e&&(r[i]=0),r[e]=t[e],i=e-1;i>=1;i-=2)r[i]=0,r[i-1]=0;0===i&&(r[0]=0),a[e]=r}return a},numeric.getDiag=function(t){var e,n=Math.min(t.length,t[0].length),i=Array(n);for(e=n-1;e>=1;--e)i[e]=t[e][e],i[--e]=t[e][e];return 0===e&&(i[0]=t[0][0]),i},numeric.identity=function(t){return numeric.diag(numeric.rep([t],1))},numeric.pointwise=function(t,e,n){void 0===n&&(n="");var i,r,s=[],a=/\[i\]$/,o="",l=!1;for(i=0;i=0;i--) ret[i] = arguments.callee("+t.join(",")+",_s,_k+1);\n return ret;\n}\n"+n+"\nfor(i=_n-1;i!==-1;--i) {\n "+e+"\n}\nreturn ret;",Function.apply(null,s)},numeric.pointwise2=function(t,e,n){void 0===n&&(n="");var i,r,s=[],a=/\[i\]$/,o="",l=!1;for(i=0;i=0;a--)t("object"==typeof e?e[a]:e,"object"==typeof n?n[a]:n,i,r+1,s);else s(e,n)},numeric._biforeach2=function t(e,n,i,r,s){if(r===i.length-1)return s(e,n);var a,o=i[r],l=Array(o);for(a=o-1;a>=0;--a)l[a]=t("object"==typeof e?e[a]:e,"object"==typeof n?n[a]:n,i,r+1,s);return l},numeric._foreach=function t(e,n,i,r){var s;if(i!==n.length-1)for(s=n[i]-1;s>=0;s--)t(e[s],n,i+1,r);else r(e)},numeric._foreach2=function t(e,n,i,r){if(i===n.length-1)return r(e);var s,a=n[i],o=Array(a);for(s=a-1;s>=0;s--)o[s]=t(e[s],n,i+1,r);return o},numeric.ops2={add:"+",sub:"-",mul:"*",div:"/",mod:"%",and:"&&",or:"||",eq:"===",neq:"!==",lt:"<",gt:">",leq:"<=",geq:">=",band:"&",bor:"|",bxor:"^",lshift:"<<",rshift:">>",rrshift:">>>"},numeric.opseq={addeq:"+=",subeq:"-=",muleq:"*=",diveq:"/=",modeq:"%=",lshifteq:"<<=",rshifteq:">>=",rrshifteq:">>>=",bandeq:"&=",boreq:"|=",bxoreq:"^="},numeric.mathfuns=["abs","acos","asin","atan","ceil","cos","exp","floor","log","round","sin","sqrt","tan","isNaN","isFinite"],numeric.mathfuns2=["atan2","pow","max","min"],numeric.ops1={neg:"-",not:"!",bnot:"~",clone:""},numeric.mapreducers={any:["if(xi) return true;","var accum = false;"],all:["if(!xi) return false;","var accum = true;"],sum:["accum += xi;","var accum = 0;"],prod:["accum *= xi;","var accum = 1;"],norm2Squared:["accum += xi*xi;","var accum = 0;"],norminf:["accum = max(accum,abs(xi));","var accum = 0, max = Math.max, abs = Math.abs;"],norm1:["accum += abs(xi)","var accum = 0, abs = Math.abs;"],sup:["accum = max(accum,xi);","var accum = -Infinity, max = Math.max;"],inf:["accum = min(accum,xi);","var accum = Infinity, min = Math.min;"]},function(){var t,e;for(t=0;tm&&(f=s,m=o);for(n=d[f],d[f]=d[a],d[a]=n,r=p[f],p[f]=p[a],p[a]=r,t=n[a],o=a;o!==h;++o)n[o]/=t;for(o=h-1;-1!==o;--o)r[o]/=t;for(s=u-1;-1!==s;--s)if(s!==a){for(e=d[s],i=p[s],t=e[a],o=a+1;o!==h;++o)e[o]-=n[o]*t;for(o=h-1;o>0;--o)i[o]-=r[o]*t,i[--o]-=r[o]*t;0===o&&(i[0]-=r[0]*t)}}return p},numeric.det=function(t){var e=numeric.dim(t);if(2!==e.length||e[0]!==e[1])throw new Error("numeric: det() only works on square matrices");var n,i,r,s,a,o,l,c,u=e[0],h=1,d=numeric.clone(t);for(i=0;iMath.abs(d[r][i])&&(r=n);for(r!==i&&(l=d[r],d[r]=d[i],d[i]=l,h*=-1),s=d[i],n=i+1;n=1;e-=2){for(r=t[e],i=t[e-1],n=o-1;n>=1;--n)(s=l[n])[e]=r[n],s[e-1]=i[n],(s=l[--n])[e]=r[n],s[e-1]=i[n];0===n&&((s=l[0])[e]=r[0],s[e-1]=i[0])}if(0===e){for(i=t[0],n=o-1;n>=1;--n)l[n][0]=i[n],l[--n][0]=i[n];0===n&&(l[0][0]=i[0])}return l},numeric.negtranspose=function(t){var e,n,i,r,s,a=t.length,o=t[0].length,l=Array(o);for(n=0;n=1;e-=2){for(r=t[e],i=t[e-1],n=o-1;n>=1;--n)(s=l[n])[e]=-r[n],s[e-1]=-i[n],(s=l[--n])[e]=-r[n],s[e-1]=-i[n];0===n&&((s=l[0])[e]=-r[0],s[e-1]=-i[0])}if(0===e){for(i=t[0],n=o-1;n>=1;--n)l[n][0]=-i[n],l[--n][0]=-i[n];0===n&&(l[0][0]=-i[0])}return l},numeric._random=function t(e,n){var i,r,s=e[n],a=Array(s);if(n===e.length-1){for(r=Math.random,i=s-1;i>=1;i-=2)a[i]=r(),a[i-1]=r();return 0===i&&(a[0]=r()),a}for(i=s-1;i>=0;i--)a[i]=t(e,n+1);return a},numeric.random=function(t){return numeric._random(t,0)},numeric.norm2=function(t){return Math.sqrt(numeric.norm2Squared(t))},numeric.linspace=function(t,e,n){if(void 0===n&&(n=Math.max(Math.round(e-t)+1,1)),n<2)return 1===n?[t]:[];var i,r=Array(n);for(i=--n;i>=0;i--)r[i]=(i*e+(n-i)*t)/n;return r},numeric.getBlock=function(t,e,n){var i=numeric.dim(t);return function t(r,s){var a,o=e[s],l=n[s]-o,c=Array(l);if(s===i.length-1){for(a=l;a>=0;a--)c[a]=r[a+o];return c}for(a=l;a>=0;a--)c[a]=t(r[a+o],s+1);return c}(t,0)},numeric.setBlock=function(t,e,n,i){var r=numeric.dim(t);return function t(i,s,a){var o,l=e[a],c=n[a]-l;if(a===r.length-1)for(o=c;o>=0;o--)i[o+l]=s[o];for(o=c;o>=0;o--)t(i[o+l],s[o],a+1)}(t,i,0),t},numeric.getRange=function(t,e,n){var i,r,s,a,o=e.length,l=n.length,c=Array(o);for(i=o-1;-1!==i;--i)for(c[i]=Array(l),s=c[i],a=t[e[i]],r=l-1;-1!==r;--r)s[r]=a[n[r]];return c},numeric.blockMatrix=function(t){var e=numeric.dim(t);if(e.length<4)return numeric.blockMatrix([t]);var n,i,r,s,a,o=e[0],l=e[1];for(n=0,i=0,r=0;r=0;s--){for(r=Array(c),o=t[s],a=c-1;a>=3;--a)r[a]=o*e[a],r[--a]=o*e[a],r[--a]=o*e[a],r[--a]=o*e[a];for(;a>=0;)r[a]=o*e[a],--a;u[s]=r}return u},numeric.T=function(t,e){this.x=t,this.y=e},numeric.t=function(t,e){return new numeric.T(t,e)},numeric.Tbinop=function(t,e,n,i,r){var s;if(numeric.indexOf,"string"!=typeof r)for(s in r="",numeric)numeric.hasOwnProperty(s)&&(t.indexOf(s)>=0||e.indexOf(s)>=0||n.indexOf(s)>=0||i.indexOf(s)>=0)&&s.length>1&&(r+="var "+s+" = numeric."+s+";\n");return Function(["y"],"var x = this;\nif(!(y instanceof numeric.T)) { y = new numeric.T(y); }\n"+r+"\nif(x.y) { if(y.y) { return new numeric.T("+i+");\n }\n return new numeric.T("+n+");\n}\nif(y.y) {\n return new numeric.T("+e+");\n}\nreturn new numeric.T("+t+");\n")},numeric.T.prototype.add=numeric.Tbinop("add(x.x,y.x)","add(x.x,y.x),y.y","add(x.x,y.x),x.y","add(x.x,y.x),add(x.y,y.y)"),numeric.T.prototype.sub=numeric.Tbinop("sub(x.x,y.x)","sub(x.x,y.x),neg(y.y)","sub(x.x,y.x),x.y","sub(x.x,y.x),sub(x.y,y.y)"),numeric.T.prototype.mul=numeric.Tbinop("mul(x.x,y.x)","mul(x.x,y.x),mul(x.x,y.y)","mul(x.x,y.x),mul(x.y,y.x)","sub(mul(x.x,y.x),mul(x.y,y.y)),add(mul(x.x,y.y),mul(x.y,y.x))"),numeric.T.prototype.reciprocal=function(){var t=numeric.mul,e=numeric.div;if(this.y){var n=numeric.add(t(this.x,this.x),t(this.y,this.y));return new numeric.T(e(this.x,n),e(numeric.neg(this.y),n))}return new T(e(1,this.x))},numeric.T.prototype.div=function(t){if(t instanceof numeric.T||(t=new numeric.T(t)),t.y)return this.mul(t.reciprocal());var e=numeric.div;return this.y?new numeric.T(e(this.x,t.x),e(this.y,t.x)):new numeric.T(e(this.x,t.x))},numeric.T.prototype.dot=numeric.Tbinop("dot(x.x,y.x)","dot(x.x,y.x),dot(x.x,y.y)","dot(x.x,y.x),dot(x.y,y.x)","sub(dot(x.x,y.x),dot(x.y,y.y)),add(dot(x.x,y.y),dot(x.y,y.x))"),numeric.T.prototype.transpose=function(){var t=numeric.transpose,e=this.x,n=this.y;return n?new numeric.T(t(e),t(n)):new numeric.T(t(e))},numeric.T.prototype.transjugate=function(){var t=numeric.transpose,e=this.x,n=this.y;return n?new numeric.T(t(e),numeric.negtranspose(n)):new numeric.T(t(e))},numeric.Tunop=function(t,e,n){return"string"!=typeof n&&(n=""),Function("var x = this;\n"+n+"\nif(x.y) { "+e+";\n}\n"+t+";\n")},numeric.T.prototype.exp=numeric.Tunop("return new numeric.T(ex)","return new numeric.T(mul(cos(x.y),ex),mul(sin(x.y),ex))","var ex = numeric.exp(x.x), cos = numeric.cos, sin = numeric.sin, mul = numeric.mul;"),numeric.T.prototype.conj=numeric.Tunop("return new numeric.T(x.x);","return new numeric.T(x.x,numeric.neg(x.y));"),numeric.T.prototype.neg=numeric.Tunop("return new numeric.T(neg(x.x));","return new numeric.T(neg(x.x),neg(x.y));","var neg = numeric.neg;"),numeric.T.prototype.sin=numeric.Tunop("return new numeric.T(numeric.sin(x.x))","return x.exp().sub(x.neg().exp()).div(new numeric.T(0,2));"),numeric.T.prototype.cos=numeric.Tunop("return new numeric.T(numeric.cos(x.x))","return x.exp().add(x.neg().exp()).div(2);"),numeric.T.prototype.abs=numeric.Tunop("return new numeric.T(numeric.abs(x.x));","return new numeric.T(numeric.sqrt(numeric.add(mul(x.x,x.x),mul(x.y,x.y))));","var mul = numeric.mul;"),numeric.T.prototype.log=numeric.Tunop("return new numeric.T(numeric.log(x.x));","var theta = new numeric.T(numeric.atan2(x.y,x.x)), r = x.abs();\nreturn new numeric.T(numeric.log(r.x),theta.x);"),numeric.T.prototype.norm2=numeric.Tunop("return numeric.norm2(x.x);","var f = numeric.norm2Squared;\nreturn Math.sqrt(f(x.x)+f(x.y));"),numeric.T.prototype.inv=function(){var t=this;if(void 0===t.y)return new numeric.T(numeric.inv(t.x));var e,n,i,r,s,a,o,l,c,u,h,d,p,f,m,g,v,_,x=t.x.length,y=numeric.identity(x),b=numeric.rep([x,x],0),w=numeric.clone(t.x),M=numeric.clone(t.y);for(c=0;cd&&(h=u,d=p);for(h!==c&&(_=w[c],w[c]=w[h],w[h]=_,_=M[c],M[c]=M[h],M[h]=_,_=y[c],y[c]=y[h],y[h]=_,_=b[c],b[c]=b[h],b[h]=_),e=w[c],n=M[c],s=y[c],a=b[c],f=e[c],m=n[c],u=c+1;u0;c--)for(s=y[c],a=b[c],u=c-1;u>=0;u--)for(o=y[u],l=b[u],f=w[u][c],m=M[u][c],h=x-1;h>=0;h--)g=s[h],v=a[h],o[h]-=f*g-m*v,l[h]-=f*v+m*g;return new numeric.T(y,b)},numeric.T.prototype.get=function(t){var e,n=this.x,i=this.y,r=0,s=t.length;if(i){for(;r=0?1:-1)*numeric.norm2(t);e[0]+=n;var i=numeric.norm2(e);if(0===i)throw new Error("eig: internal error");return numeric.div(e,i)},numeric.toUpperHessenberg=function(t){var e=numeric.dim(t);if(2!==e.length||e[0]!==e[1])throw new Error("numeric: toUpperHessenberg() only works on square matrices");var n,i,r,s,a,o,l,c,u,h,d=e[0],p=numeric.clone(t),f=numeric.identity(d);for(i=0;i0){for(a=numeric.house(s),o=numeric.getBlock(p,[i+1,i],[d-1,d-1]),l=numeric.tensor(a,numeric.dot(a,o)),n=i+1;n=4*l?(E=.5*(c+Math.sqrt(c*c-4*l)),T=.5*(c-Math.sqrt(c*c-4*l)),u=numeric.add(numeric.sub(numeric.dot(u,u),numeric.mul(u,E+T)),numeric.diag(numeric.rep([3],E*T)))):u=numeric.add(numeric.sub(numeric.dot(u,u),numeric.mul(u,c)),numeric.diag(numeric.rep([3],l))),n=[u[0][0],u[1][0],u[2][0]],i=numeric.house(n),p=[t[0],t[1],t[2]],f=numeric.tensor(i,numeric.dot(i,p)),g=0;g<3;g++)for(d=t[g],m=f[g],_=0;_=0?((g=(a-(d=u<0?-.5*(u-T(h)):-.5*(u+T(h))))*(a-d)+o*o)>(v=l*l+(c-d)*(c-d))?(f=(a-d)/(g=T(g)),m=o/g):(f=l/(v=T(v)),m=(c-d)/v),r=new y([[m,-f],[f,m]]),S.setRows(n,s,r.dot(S.getRows(n,s)))):(d=-.5*u,p=.5*T(-h),(g=(a-d)*(a-d)+o*o)>(v=l*l+(c-d)*(c-d))?(f=(a-d)/(g=T(g+p*p)),m=o/g,d=0,p/=g):(f=l/(v=T(v+p*p)),m=(c-d)/v,d=p/v,p=0),r=new y([[m,-f],[f,m]],[[d,p],[p,-d]]),S.setRows(n,s,r.dot(S.getRows(n,s))))}var A=S.dot(t).dot(S.transjugate()),C=(b=t.length,numeric.T.identity(b));for(s=0;s0)for(i=s-1;i>=0;i--){var R=A.get([i,i]),P=A.get([s,s]);numeric.neq(R.x,P.x)||numeric.neq(R.y,P.y)?(d=A.getRow(i).getBlock([i],[s-1]),p=C.getRow(s).getBlock([i],[s-1]),C.set([s,i],A.get([i,s]).neg().sub(d.dot(p)).div(R.sub(P)))):C.setRow(s,C.getRow(i))}for(s=0;s=s.length;)s[s.length]=0;0!==e[i]&&s[i]++}var a=s.length,o=Array(a+1);for(o[0]=0,n=0;n=l){if(r[u]=p[c],0===c)return;++u,o=h[--c],l=d[c]}else 0===i[a=s[n[o]]]?(i[a]=1,h[c]=o,p[++c]=a,o=e[a],d[c]=l=e[a+1]):++o},numeric.ccsLPSolve=function(t,e,n,i,r,s,a){var o,l,c,u,h,d,p,f,m,g=t[0],v=t[1],_=t[2],x=(g.length,e[0]),y=e[1],b=e[2];for(l=x[r],c=x[r+1],i.length=0,o=l;os&&(a=r,s=o);for(b(_[n])=c){if(r[h]=s[f[u]],0===u)return;++h,l=d[--u],c=p[u]}else 0===i[o=n[l]]?(i[o]=1,d[u]=l,f[++u]=o,l=e[o=s[o]],p[u]=c=e[o+1]):++l}},numeric.ccsLPSolve0=function(t,e,n,i,r,s,a,o){var l,c,u,h,d,p,f,m,g,v=t[0],_=t[1],x=t[2],y=(v.length,e[0]),b=e[1],w=e[2];for(c=y[r],u=y[r+1],i.length=0,l=c;ls&&(a=r,s=o);for(b(_[w[n]])n[i]&&(n[i]=e.length),e)e.hasOwnProperty(r)&&t(e[r],n,i+1);return n},numeric.sclone=function t(e,n,i){void 0===n&&(n=0),void 0===i&&(i=numeric.sdim(e).length);var r,s=Array(e.length);if(n===i-1){for(r in e)e.hasOwnProperty(r)&&(s[r]=e[r]);return s}for(r in e)e.hasOwnProperty(r)&&(s[r]=t(e[r],n+1,i));return s},numeric.sdiag=function(t){var e,n,i=t.length,r=Array(i);for(e=i-1;e>=1;e-=2)n=e-1,r[e]=[],r[e][e]=t[e],r[n]=[],r[n][n]=t[n];return 0===e&&(r[0]=[],r[0][0]=t[e]),r},numeric.sidentity=function(t){return numeric.sdiag(numeric.rep([t],1))},numeric.stranspose=function(t){var e,n,i,r=[];for(e in t.length,t)if(t.hasOwnProperty(e))for(n in i=t[e])i.hasOwnProperty(n)&&("object"!=typeof r[n]&&(r[n]=[]),r[n][e]=i[n]);return r},numeric.sLUP=function(t,e){throw new Error("The function numeric.sLUP had a bug in it and has been removed. Please use the new numeric.ccsLUP function instead.")},numeric.sdotMM=function(t,e){var n,i,r,s,a,o,l,c=t.length,u=(e.length,numeric.stranspose(e)),h=u.length,d=Array(c);for(r=c-1;r>=0;r--){for(l=[],n=t[r],a=h-1;a>=0;a--){for(s in o=0,i=u[a],n)n.hasOwnProperty(s)&&s in i&&(o+=n[s]*i[s]);o&&(l[a]=o)}d[r]=l}return d},numeric.sdotMV=function(t,e){var n,i,r,s,a=t.length,o=Array(a);for(i=a-1;i>=0;i--){for(r in s=0,n=t[i])n.hasOwnProperty(r)&&e[r]&&(s+=n[r]*e[r]);s&&(o[i]=s)}return o},numeric.sdotVM=function(t,e){var n,i,r,s,a=[];for(n in t)if(t.hasOwnProperty(n))for(i in r=e[n],s=t[n],r)r.hasOwnProperty(i)&&(a[i]||(a[i]=0),a[i]+=s*r[i]);return a},numeric.sdotVV=function(t,e){var n,i=0;for(n in t)t[n]&&e[n]&&(i+=t[n]*e[n]);return i},numeric.sdot=function(t,e){var n=numeric.sdim(t).length,i=numeric.sdim(e).length;switch(1e3*n+i){case 0:return t*e;case 1001:return numeric.sdotVV(t,e);case 2001:return numeric.sdotMV(t,e);case 1002:return numeric.sdotVM(t,e);case 2002:return numeric.sdotMM(t,e);default:throw new Error("numeric.sdot not implemented for tensors of order "+n+" and "+i)}},numeric.sscatter=function(t){var e,n,i,r,s=t[0].length,a=t.length,o=[];for(n=s-1;n>=0;--n)if(t[a-1][n]){for(r=o,i=0;i=0;--s)n[s]=[];for(s=r;s>=0;--s)n[s].push(i[s]);n[r+1].push(a)}}else t(a,n,i);return i.length>r&&i.pop(),n},numeric.cLU=function(t){var e,n,i,r,s,a,o=t[0],l=t[1],c=t[2],u=o.length,h=0;for(e=0;eh&&(h=o[e]);h++;var d,p=Array(h),f=Array(h),m=numeric.rep([h],1/0),g=numeric.rep([h],-1/0);for(i=0;ig[e]&&(g[e]=n);for(e=0;eg[e+1]&&(g[e+1]=g[e]);for(e=h-1;e>=1;e--)m[e]=0;n--){for(;h[i]>n;)a[n]-=d[i]*a[h[i]],i--;a[n]/=d[i],i--}return a},numeric.cgrid=function(t,e){"number"==typeof t&&(t=[t,t]);var n,i,r,s=numeric.rep(t,-1);for("function"!=typeof e&&(e="L"===e?function(e,n){return e>=t[0]/2||nr&&(r=s[i]);for(r++,n=numeric.rep([r],0),i=0;i1;)r[i=a((e+n)/2)]<=t?e=i:n=i;return this._at(t,e)}s=t.length;var o,l=Array(s);for(o=s-1;-1!==o;--o)l[o]=this.at(t[o]);return l},numeric.Spline.prototype.diff=function(){var t,e,n,i=this.x,r=this.yl,s=this.yr,a=this.kl,o=this.kr,l=r.length,c=a,u=o,h=Array(l),d=Array(l),p=numeric.add,f=numeric.mul,m=numeric.div,g=numeric.sub;for(t=l-1;-1!==t;--t)e=i[t+1]-i[t],n=g(s[t+1],r[t]),h[t]=m(p(f(n,6),f(a[t],-4*e),f(o[t+1],-2*e)),e*e),d[t+1]=m(p(f(n,-6),f(a[t],2*e),f(o[t+1],4*e)),e*e);return new numeric.Spline(i,c,u,h,d)},numeric.Spline.prototype.roots=function(){function t(t){return t*t}var e=[],n=this.x,i=this.yl,r=this.yr,s=this.kl,a=this.kr;"number"==typeof i[0]&&(i=[i],r=[r],s=[s],a=[a]);var o,l,c,u,h,d,p,f,m,g,v,_,x,y,b,w,M,S,E,T,A,C,R,P=i.length,N=n.length-1,L=(e=Array(P),Math.sqrt);for(o=0;o!==P;++o){for(u=i[o],h=r[o],d=s[o],p=a[o],f=[],l=0;l!==N;l++){for(l>0&&h[l]*u[l]<0&&f.push(n[l]),w=n[l+1]-n[l],n[l],v=u[l],_=h[l+1],m=d[l]/w,x=(g=p[l+1]/w)+3*v+2*m-3*_,y=3*(g+m+2*(v-_)),(b=t(m-g+3*(v-_))+12*g*v)<=0?M=(S=x/y)>n[l]&&Sn[l]&&Sn[l]&&E0)A=C,S=E;else{for(var U=0;!((R=(S*C-E*A)/(S-E))<=A||R>=C);)if((T=this._at(R,l))*E>0)C=R,E=T,-1===U&&(S*=.5),U=-1;else{if(!(T*S>0))break;A=R,S=T,1===U&&(E*=.5),U=1}f.push(R),A=M[c+1],S=this._at(A,l)}else f.push(A),A=C,S=E;0===E&&f.push(C)}e[o]=f}return"number"==typeof this.yl[0]?e[0]:e},numeric.spline=function(t,e,n,i){var r,s=t.length,a=[],o=[],l=[],c=numeric.sub,u=numeric.mul,h=numeric.add;for(r=s-2;r>=0;r--)o[r]=t[r+1]-t[r],l[r]=c(e[r+1],e[r]);"string"!=typeof n&&"string"!=typeof i||(n=i="periodic");var d=[[],[],[]];switch(typeof n){case"undefined":a[0]=u(3/(o[0]*o[0]),l[0]),d[0].push(0,0),d[1].push(0,1),d[2].push(2/o[0],1/o[0]);break;case"string":a[0]=h(u(3/(o[s-2]*o[s-2]),l[s-2]),u(3/(o[0]*o[0]),l[0])),d[0].push(0,0,0),d[1].push(s-2,0,1),d[2].push(1/o[s-2],2/o[s-2]+2/o[0],1/o[0]);break;default:a[0]=n,d[0].push(0),d[1].push(0),d[2].push(1)}for(r=1;r20)throw new Error("Numerical gradient fails");if(f[r]=e[r]+x,s=t(f),f[r]=e[r]-x,a=t(f),f[r]=e[r],isNaN(s)||isNaN(a))x/=16;else{if(m[r]=(s-a)/(2*x),o=e[r]-x,l=e[r],c=e[r]+x,u=(s-i)/x,h=(i-a)/x,d=p(g(m[r]),g(i),g(s),g(a),g(o),g(l),g(c),1e-8),!(v(p(g(u-m[r]),g(h-m[r]),g(u-h))/d,x/d)>.001))break;x/=16}}return m},numeric.uncmin=function(t,e,n,i,r,s,a){var o=numeric.gradient;void 0===a&&(a={}),void 0===n&&(n=1e-8),void 0===i&&(i=function(e){return o(t,e)}),void 0===r&&(r=1e3);var l,c,u=(e=numeric.clone(e)).length,h=t(e);if(isNaN(h))throw new Error("uncmin: f(x0) is a NaN!");var d=Math.max,p=numeric.norm2;n=d(n,numeric.epsilon);var f,m,g,v,_,x,y,b,w,M,S=a.Hinv||numeric.identity(u),E=numeric.dot,T=(numeric.inv,numeric.sub),A=numeric.add,C=numeric.tensor,R=numeric.div,P=numeric.mul,N=numeric.all,L=numeric.isFinite,U=numeric.neg,D=0,I="";for(m=i(e);D=.1*w*c||isNaN(l));)w*=.5,++D;if(w*M1;)o[i=r(.5*(e+n))]<=t?e=i:n=i;return this._at(t,e)},numeric.dopri=function(t,e,n,i,r,s,a){void 0===r&&(r=1e-6),void 0===s&&(s=1e3);var o,l,c,u,h,d,p,f,m,g,v,_,x,y=[t],b=[n],w=[i(t,n)],M=[],S=[3/40,9/40],E=[44/45,-56/15,32/9],T=[19372/6561,-25360/2187,64448/6561,-212/729],A=[9017/3168,-355/33,46732/5247,49/176,-5103/18656],C=[35/384,0,500/1113,125/192,-2187/6784,11/84],R=[.10013431883002395,0,.3918321794184259,-.02982460176594817,.05893268337240795,-.04497888809104361,5618549.5/235043384],P=[.2,.3,.8,8/9,1,1],N=[-71/57600,0,71/16695,-71/1920,17253/339200,-22/525,1/40],L=0,U=(e-t)/10,D=0,I=numeric.add,O=numeric.mul,k=(Math.max,Math.min),F=Math.abs,B=numeric.norminf,z=Math.pow,V=numeric.any,H=numeric.lt,G=numeric.and,W=(numeric.sub,new numeric.Dopri(y,b,w,M,-1,""));for("function"==typeof a&&(v=a(t,n));te&&(U=e-t),o=i(t+P[0]*U,I(n,O(.2*U,w[L]))),l=i(t+P[1]*U,I(I(n,O(S[0]*U,w[L])),O(S[1]*U,o))),c=i(t+P[2]*U,I(I(I(n,O(E[0]*U,w[L])),O(E[1]*U,o)),O(E[2]*U,l))),u=i(t+P[3]*U,I(I(I(I(n,O(T[0]*U,w[L])),O(T[1]*U,o)),O(T[2]*U,l)),O(T[3]*U,c))),h=i(t+P[4]*U,I(I(I(I(I(n,O(A[0]*U,w[L])),O(A[1]*U,o)),O(A[2]*U,l)),O(A[3]*U,c)),O(A[4]*U,u))),d=i(t+U,m=I(I(I(I(I(n,O(w[L],U*C[0])),O(l,U*C[2])),O(c,U*C[3])),O(u,U*C[4])),O(h,U*C[5]))),(g="number"==typeof(p=I(I(I(I(I(O(w[L],U*N[0]),O(l,U*N[2])),O(c,U*N[3])),O(u,U*N[4])),O(h,U*N[5])),O(d,U*N[6])))?F(p):B(p))>r){if(t+(U=.2*U*z(r/g,.25))===t){W.msg="Step size became too small";break}}else{if(M[L]=I(I(I(I(I(I(n,O(w[L],U*R[0])),O(l,U*R[2])),O(c,U*R[3])),O(u,U*R[4])),O(h,U*R[5])),O(d,U*R[6])),y[++L]=t+U,b[L]=m,w[L]=d,"function"==typeof a){var j,X,$=t,q=t+.5*U;if(_=a(q,M[L-1]),V(x=G(H(v,0),H(0,_)))||($=q,v=_,_=a(q=t+U,m),x=G(H(v,0),H(0,_))),V(x)){for(var Y,Z,K=0,J=1,Q=1;;){if("number"==typeof v)X=(Q*_*$-J*v*q)/(Q*_-J*v);else for(X=q,f=v.length-1;-1!==f;--f)v[f]<0&&_[f]>0&&(X=k(X,(Q*_[f]*$-J*v[f]*q)/(Q*_[f]-J*v[f])));if(X<=$||X>=q)break;Z=a(X,j=W._at(X,L-1)),V(Y=G(H(v,0),H(0,Z)))?(q=X,_=Z,x=Y,Q=1,-1===K?J*=.5:J=1,K=-1):($=X,v=Z,J=1,1===K?Q*=.5:Q=1,K=1)}return m=W._at(.5*(t+X),L-1),W.f[L]=i(X,j),W.x[L]=X,W.y[L]=j,W.ymid[L-1]=m,W.events=x,W.iterations=D,W}}t+=U,n=m,v=_,U=k(.8*U*z(r/g,.25),4*U)}return W.iterations=D,W},numeric.LU=function(t,e){e=e||!1;var n,i,r,s,a,o,l,c,u,h=Math.abs,d=t.length,p=d-1,f=new Array(d);for(e||(t=numeric.clone(t)),r=0;r=0;--n){for(s=o[n],i=n+1;iI)&&(y=I),u=g(t,d(y,A)),l=f(D,C),L=v-1;-1!==L;--L)l[L][L]+=1;U=R(l,m(u,y),!0);var O=m(P,f(e,U)),k=1;for(L=_-1;-1!==L;--L)O[L]<0&&(k=S(k,-.999*O[L]));if(o=p(s,d(U,k)),!E(T(P=p(n,f(e,o)),0)))return{solution:s,message:"",iterations:c};if(s=o,y=0);if(x)return{solution:o,message:"Unbounded",iterations:c}}return{solution:s,message:"maximum iteration count exceeded",iterations:c}},numeric._solveLP=function(t,e,n,i,r){var s=t.length,a=n.length,o=(numeric.sum,numeric.log,numeric.mul,numeric.sub),l=numeric.dot,c=(numeric.div,numeric.add,numeric.rep([s],0).concat([1])),u=numeric.rep([a,1],-1),h=numeric.blockMatrix([[e,u]]),d=n,p=numeric.rep([s],0).concat(Math.max(0,numeric.sup(numeric.neg(n)))+1),f=numeric.__solveLP(c,h,d,i,r,p,!1),m=numeric.clone(f.solution);if(m.length=s,numeric.inf(o(n,l(e,m)))<0)return{solution:NaN,message:"Infeasible",iterations:f.iterations};var g=numeric.__solveLP(t,e,n,i,r-f.iterations,m,!0);return g.iterations+=f.iterations,g},numeric.solveLP=function(t,e,n,i,r,s,a){if(void 0===a&&(a=1e3),void 0===s&&(s=numeric.epsilon),void 0===i)return numeric._solveLP(t,e,n,s,a);var o,l=i.length,c=i[0].length,u=e.length,h=numeric.echelonize(i),d=numeric.rep([c],0),p=h.P,f=[];for(o=p.length-1;-1!==o;--o)d[p[o]]=1;for(o=c-1;-1!==o;--o)0===d[o]&&f.push(o);var m=numeric.getRange,g=numeric.linspace(0,l-1),v=numeric.linspace(0,u-1),_=m(i,g,f),x=m(e,v,p),y=m(e,v,f),b=numeric.dot,w=numeric.sub,M=b(x,h.I),S=w(y,b(M,_)),E=w(n,b(M,r)),T=Array(p.length),A=Array(f.length);for(o=p.length-1;-1!==o;--o)T[o]=t[p[o]];for(o=f.length-1;-1!==o;--o)A[o]=t[f[o]];var C=w(A,b(T,b(h.I,_))),R=numeric._solveLP(C,S,E,s,a),P=R.solution;if(P!=P)return R;var N=b(h.I,w(r,b(_,P))),L=Array(t.length);for(o=p.length-1;-1!==o;--o)L[p[o]]=N[o];for(o=f.length-1;-1!==o;--o)L[f[o]]=P[o];return{solution:L,message:R.message,iterations:R.iterations}},numeric.MPStoLP=function(t){t instanceof String&&t.split("\n");var e,n,i,r,s=0,a=["Initial state","NAME","ROWS","COLUMNS","RHS","BOUNDS","ENDATA"],o=t.length,l=0,c={},u=[],h=0,d={},p=0,f=[],m=[],g=[];function v(n){throw new Error("MPStoLP: "+n+"\nLine "+e+": "+t[e]+"\nCurrent state: "+a[s]+"\n")}for(e=0;e=s;)t/=2,e/=2,i>>>=1;return(t+i)/e},i},a=e.pow(n,6),r=e.pow(2,r),s=2*r,c(e.random(),t)}([],numeric.seedrandom,256,0,52),function(t){function e(t){if("object"!=typeof t)return t;var n,i=[],r=t.length;for(n=0;nu)f[_]=N;else if(f[_]=-Math.abs(N),N>0){for(v=1;v<=i;v+=1)a[v][g]=-a[v][g];o[g]=-o[g]}}for(g=1;g<=d;g+=1)f[E+h[g]]=0;for(A=0,P=0,g=1;g<=c;g+=1)f[E+g]=1;g-=1){for(N=f[g],x=(_=S+g*(g+3)/2)-g,v=g+1;v<=d;v+=1)N-=f[_]*f[M+v],_+=v;if(N/=f[x],f[M+g]=N,h[g]u)f[E+A]=N;else if(f[E+A]=-Math.abs(N),N>0){for(v=1;v<=i;v+=1)a[v][A]=-a[v][A];o[A]=-o[A]}return 700}for(h[d+=1]=A,_=S+(d-1)*d/2+1,g=1;g<=d-1;g+=1)f[_]=f[g],_+=1;if(d===i)f[_]=f[i];else{for(g=i;g>=d+1&&0!==f[g]&&(D=Math.max(Math.abs(f[g-1]),Math.abs(f[g])),I=Math.min(Math.abs(f[g-1]),Math.abs(f[g])),P=f[g-1]>=0?Math.abs(D*Math.sqrt(1+I*I/(D*D))):-Math.abs(D*Math.sqrt(1+I*I/(D*D))),D=f[g-1]/P,I=f[g]/P,1!==D);g-=1)if(0===D)for(f[g-1]=I*P,v=1;v<=i;v+=1)P=t[v][g-1],t[v][g-1]=t[v][g],t[v][g]=P;else for(f[g-1]=P,O=I/(1+D),v=1;v<=i;v+=1)P=D*t[v][g-1]+I*t[v][g],t[v][g]=O*(t[v][g-1]+P)-t[v][g],t[v][g-1]=P;f[_]=f[d]}return 0}function j(){if(0===f[x=(_=S+b*(b+1)/2+1)+b])return 798;if(D=Math.max(Math.abs(f[x-1]),Math.abs(f[x])),I=Math.min(Math.abs(f[x-1]),Math.abs(f[x])),P=f[x-1]>=0?Math.abs(D*Math.sqrt(1+I*I/(D*D))):-Math.abs(D*Math.sqrt(1+I*I/(D*D))),D=f[x-1]/P,I=f[x]/P,1===D)return 798;if(0===D){for(g=b+1;g<=d;g+=1)P=f[x-1],f[x-1]=f[x],f[x]=P,x+=g;for(g=1;g<=i;g+=1)P=t[g][b],t[g][b]=t[g][b+1],t[g][b+1]=P}else{for(O=I/(1+D),g=b+1;g<=d;g+=1)P=D*f[x-1]+I*f[x],f[x]=O*(f[x-1]+P)-f[x],f[x-1]=P,x+=g;for(g=1;g<=i;g+=1)P=D*t[g][b]+I*t[g][b+1],t[g][b+1]=O*(t[g][b]+P)-t[g][b+1],t[g][b]=P}return 0}function X(){for(x=_-b,g=1;g<=b;g+=1)f[x]=f[_],_+=1,x+=1;return f[T+b]=f[T+b+1],h[b]=h[b+1],(b+=1)(e=Math.abs(e))?t*Math.sqrt(1+e*e/t/t):0==e?t:e*Math.sqrt(1+t*t/e/e)}var g=0,v=0,_=0,x=0,y=0,b=0,w=0;for(s=0;s=0&&(v=-v),_=g*v-w,c[s][s]=g-v,a=l;a=0&&(v=-v),_=g*v-w,c[s][s+1]=g-v,a=l;ax&&(x=y)}for(s=h-1;-1!=s;s+=-1){if(0!=v){for(_=v*c[s][s+1],a=l;a=49)throw"Error: no convergence.";for(x=p[l],v=m(g=(((y=p[o-1])-b)*(y+b)+((v=d[o-1])-(_=d[o]))*(v+_))/(2*_*y),1),g=g<0?((x-b)*(x+b)+_*(y/(g-v)-_))/x:((x-b)*(x+b)+_*(y/(g+v)-_))/x,r=1,w=1,s=l+1;s=0;a--)if(p[a]{var e=t&&t.__esModule?()=>t.default:()=>t;return __webpack_require__.d(e,{a:e}),e},__webpack_require__.d=(t,e)=>{for(var n in e)__webpack_require__.o(e,n)&&!__webpack_require__.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},__webpack_require__.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),__webpack_require__.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),__webpack_require__.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var __webpack_exports__={};(()=>{"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{$base_array_array_get:()=>Mi,$base_array_array_put:()=>Si,$base_array_array_size:()=>Ei,$base_array_make_array:()=>wi,$base_base__empty_ref:()=>re,$base_base__new_ref:()=>ie,$base_base__ref_get:()=>ae,$base_base__ref_set:()=>se,$base_base_apply:()=>ee,$base_base_equal:()=>ve,$base_base_error:()=>le,$base_base_from_just:()=>pe,$base_base_identity:()=>ne,$base_base_is_nothing:()=>de,$base_base_just:()=>oe,$base_base_not:()=>fe,$base_base_not_equal:()=>ge,$base_base_nothing:()=>he,$base_base_try_catch:()=>ue,$base_base_tuple:()=>te,$base_io_print:()=>_e,$base_list_append:()=>jn,$base_list_cons:()=>ei,$base_list_contains:()=>ni,$base_list_empty_list:()=>ii,$base_list_fold_list:()=>Qn,$base_list_head:()=>Jn,$base_list_list_size:()=>Kn,$base_list_loop_list:()=>Zn,$base_list_map_list:()=>Gn,$base_list_mapnz:()=>Vn,$base_list_naturals:()=>Yn,$base_list_nth:()=>qn,$base_list_reverse:()=>Xn,$base_list_sort_list:()=>ti,$base_list_tail:()=>$n,$base_list_zip:()=>Hn,$base_map_empty_map:()=>Ti,$base_map_keys:()=>Ri,$base_map_lookup:()=>Ai,$base_map_store:()=>Ci,$base_matrix_abs:()=>xn,$base_matrix_abs_min:()=>nn,$base_matrix_bottom:()=>ke,$base_matrix_cbrt:()=>Pn,$base_matrix_ceiling:()=>gn,$base_matrix_cholesky_decomposition:()=>Fn,$base_matrix_column:()=>Te,$base_matrix_column_domain:()=>Ae,$base_matrix_column_unit:()=>Ce,$base_matrix_cos:()=>cn,$base_matrix_dim_div:()=>Ge,$base_matrix_dim_inv:()=>He,$base_matrix_div:()=>sn,$base_matrix_divide:()=>Xe,$base_matrix_eigenvalue_decomposition:()=>Un,$base_matrix_eigenvalue_list:()=>Dn,$base_matrix_exp:()=>Mn,$base_matrix_expt:()=>bn,$base_matrix_floor:()=>mn,$base_matrix_gcd:()=>$e,$base_matrix_get:()=>Pe,$base_matrix_get_num:()=>Re,$base_matrix_greater:()=>An,$base_matrix_greater_eq:()=>Cn,$base_matrix_index_less:()=>Ee,$base_matrix_is_zero:()=>xe,$base_matrix_left_identity:()=>Fe,$base_matrix_less:()=>En,$base_matrix_less_eq:()=>Tn,$base_matrix_ln:()=>Sn,$base_matrix_log:()=>wn,$base_matrix_magnitude:()=>be,$base_matrix_make_matrix:()=>Ne,$base_matrix_max:()=>an,$base_matrix_mexpt:()=>yn,$base_matrix_min:()=>on,$base_matrix_minus:()=>Ye,$base_matrix_mmult:()=>We,$base_matrix_mod:()=>en,$base_matrix_multiply:()=>je,$base_matrix_negative:()=>Ze,$base_matrix_negative_support:()=>Ie,$base_matrix_plu_decomposition:()=>Ln,$base_matrix_positive_support:()=>De,$base_matrix_qr_decomposition:()=>Nn,$base_matrix_random:()=>Bn,$base_matrix_ranking:()=>zn,$base_matrix_reciprocal:()=>ze,$base_matrix_rem:()=>rn,$base_matrix_right_identity:()=>Be,$base_matrix_round:()=>_n,$base_matrix_row:()=>we,$base_matrix_row_domain:()=>Se,$base_matrix_row_unit:()=>Me,$base_matrix_rscale:()=>Je,$base_matrix_scalar_unit:()=>ye,$base_matrix_scale:()=>Ke,$base_matrix_scale_down:()=>Qe,$base_matrix_signum:()=>Le,$base_matrix_sin:()=>ln,$base_matrix_singular_value_list:()=>kn,$base_matrix_solve:()=>In,$base_matrix_sqrt:()=>Rn,$base_matrix_sum:()=>qe,$base_matrix_support:()=>Ue,$base_matrix_tan:()=>un,$base_matrix_top:()=>Oe,$base_matrix_total:()=>tn,$base_matrix_transpose:()=>Ve,$base_matrix_truncate:()=>vn,$base_string_char_at:()=>gi,$base_string_compare_string:()=>pi,$base_string_concatenate:()=>fi,$base_string_format:()=>ri,$base_string_pad:()=>_i,$base_string_parse_num:()=>yi,$base_string_split_string:()=>mi,$base_string_string_length:()=>vi,$base_string_trim:()=>xi,$base_string_unit2string:()=>hi,$base_system__acos:()=>dn,$base_system__add_mut:()=>Wn,$base_system__asin:()=>hn,$base_system__atan:()=>pn,$base_system__atan2:()=>fn,$base_system__nr_decimals:()=>oi,$base_system__num2string:()=>di,$base_system__precision:()=>ci,$base_system__set_nr_decimals:()=>li,$base_system__set_precision:()=>ui,$base_system__skip:()=>me,$base_system__system_time:()=>bi,BarChart:()=>Zx,DOM:()=>ht,DOMTable:()=>pt,DimNum:()=>b,FunctionType:()=>bf,GenericType:()=>rt,Histogram:()=>fy,IndexSet:()=>$,IndexType:()=>K,LineChart:()=>Qx,Matrix:()=>$i,MatrixType:()=>J,ONE:()=>Jt,PacioliBarChartComponent:()=>ob,PacioliContext:()=>Z,PacioliControlsComponent:()=>Yy,PacioliCoordinates:()=>V,PacioliHistogramComponent:()=>cb,PacioliHistogramOptionsComponent:()=>db,PacioliInputsComponent:()=>Ky,PacioliLineChartComponent:()=>sb,PacioliList:()=>lt,PacioliMatrixComponent:()=>Cb,PacioliPieChartComponent:()=>fb,PacioliScatterPlotComponent:()=>gb,PacioliSceneComponent:()=>$y,PacioliString:()=>nt,PacioliTableComponent:()=>Sb,PacioliTuple:()=>ot,PacioliValueComponent:()=>yb,PacioliWordCloudComponent:()=>_b,PieChart:()=>ay,SIBaseType:()=>st,ScatterPlot:()=>cy,Shape:()=>G,Space:()=>of,VectorBaseType:()=>at,WordCloud:()=>Ty,compute_$base_system__runtime_environment:()=>Qt,conversionFactor:()=>tr,convertUnit:()=>Qi,createCoordinates:()=>Tt,createMatrixType:()=>Zi,fetchIndex:()=>Dt,fetchValue:()=>Ut,findNonZero:()=>Fi,fun:()=>Ji,initialNumbers:()=>Pt,internUnit:()=>bt,list:()=>hr,lookupItem:()=>Ot,makeIndexSet:()=>Et,matchTypes:()=>df,matrixShapeFromType:()=>gt,num:()=>ar,oneNumbers:()=>Ct,oneNumbersFromShape:()=>Rt,parseDimNum:()=>lr,parseUnit:()=>or,si:()=>U,storePacioliValue:()=>Bt,string:()=>Nt,subs:()=>yf,tuple:()=>cr,typeFromVarName:()=>sr,unit:()=>er,unitFromVarName:()=>rr,unitType:()=>nr,unitVectorType:()=>ir,value:()=>Ki});var t=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,e=Math.ceil,n=Math.floor,i="[BigNumber Error] ",r=i+"Number primitive has more than 15 significant digits: ",s=1e14,a=14,o=9007199254740991,l=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],c=1e7,u=1e9;function h(t){var e=0|t;return t>0||t===e?e:e-1}function d(t){for(var e,n,i=1,r=t.length,s=t[0]+"";ic^n?1:-1;for(o=(l=r.length)<(c=s.length)?l:c,a=0;as[a]^n?1:-1;return l==c?0:l>c^n?1:-1}function f(t,e,r,s){if(tr||t!==n(t))throw Error(i+(s||"Argument")+("number"==typeof t?tr?" out of range: ":" not an integer: ":" not a primitive number: ")+String(t))}function m(t){var e=t.c.length-1;return h(t.e/a)==e&&t.c[e]%2!=0}function g(t,e){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(e<0?"e":"e+")+e}function v(t,e,n){var i,r;if(e<0){for(r=n+".";++e;r+=n);t=r+t}else if(++e>(i=t.length)){for(r=n,e-=i;--e;r+=n);t+=r}else eL?g.c=g.e=null:e.e=10;h/=10,u++);return void(u>L?g.c=g.e=null:(g.e=u,g.c=[e]))}m=String(e)}else{if(!t.test(m=String(e)))return w(g,m,d);g.s=45==m.charCodeAt(0)?(m=m.slice(1),-1):1}(u=m.indexOf("."))>-1&&(m=m.replace(".","")),(h=m.search(/e/i))>0?(u<0&&(u=h),u+=+m.slice(h+1),m=m.substring(0,h)):u<0&&(u=m.length)}else{if(f(i,2,k.length,"Base"),10==i&&F)return G(g=new B(e),A+g.e+1,C);if(m=String(e),d="number"==typeof e){if(0*e!=0)return w(g,m,d,i);if(g.s=1/e<0?(m=m.slice(1),-1):1,B.DEBUG&&m.replace(/^0\.0*|\./,"").length>15)throw Error(r+e)}else g.s=45===m.charCodeAt(0)?(m=m.slice(1),-1):1;for(s=k.slice(0,i),u=h=0,p=m.length;hu){u=p;continue}}else if(!c&&(m==m.toUpperCase()&&(m=m.toLowerCase())||m==m.toLowerCase()&&(m=m.toUpperCase()))){c=!0,h=-1,u=0;continue}return w(g,String(e),d,i)}d=!1,(u=(m=b(m,i,10,g.s)).indexOf("."))>-1?m=m.replace(".",""):u=m.length}for(h=0;48===m.charCodeAt(h);h++);for(p=m.length;48===m.charCodeAt(--p););if(m=m.slice(h,++p)){if(p-=h,d&&B.DEBUG&&p>15&&(e>o||e!==n(e)))throw Error(r+g.s*e);if((u=u-h-1)>L)g.c=g.e=null;else if(u=P)?g(l,a):v(l,a,"0");else if(s=(t=G(new B(t),e,n)).e,o=(l=d(t.c)).length,1==i||2==i&&(e<=s||s<=R)){for(;oa),l=v(l,s,"0"),s+1>o){if(--e>0)for(l+=".";e--;l+="0");}else if((e+=s-o)>0)for(s+1==o&&(l+=".");e--;l+="0");return t.s<0&&r?"-"+l:l}function V(t,e){for(var n,i,r=1,s=new B(t[0]);r=10;r/=10,i++);return(n=i+n*a-1)>L?t.c=t.e=null:n=10;d/=10,c++);if((u=i-c)<0)u+=a,h=i,p=g[f=0],m=n(p/v[c-h-1]%10);else if((f=e((u+1)/a))>=g.length){if(!o)break t;for(;g.length<=f;g.push(0));p=m=0,c=1,h=(u%=a)-a+1}else{for(p=d=g[f],c=1;d>=10;d/=10,c++);m=(h=(u%=a)-a+c)<0?0:n(p/v[c-h-1]%10)}if(o=o||i<0||null!=g[f+1]||(h<0?p:p%v[c-h-1]),o=r<4?(m||o)&&(0==r||r==(t.s<0?3:2)):m>5||5==m&&(4==r||o||6==r&&(u>0?h>0?p/v[c-h]:0:g[f-1])%10&1||r==(t.s<0?8:7)),i<1||!g[0])return g.length=0,o?(i-=t.e+1,g[0]=v[(a-i%a)%a],t.e=-i||0):g[0]=t.e=0,t;if(0==u?(g.length=f,d=1,f--):(g.length=f+1,d=v[a-u],g[f]=h>0?n(p/v[c-h]%v[h])*d:0),o)for(;;){if(0==f){for(u=1,h=g[0];h>=10;h/=10,u++);for(h=g[0]+=d,d=1;h>=10;h/=10,d++);u!=d&&(t.e++,g[0]==s&&(g[0]=1));break}if(g[f]+=d,g[f]!=s)break;g[f--]=0,d=1}for(u=g.length;0===g[--u];g.pop());}t.e>L?t.c=t.e=null:t.e=P?g(e,n):v(e,n,"0"),t.s<0?"-"+e:e)}return B.clone=_,B.ROUND_UP=0,B.ROUND_DOWN=1,B.ROUND_CEIL=2,B.ROUND_FLOOR=3,B.ROUND_HALF_UP=4,B.ROUND_HALF_DOWN=5,B.ROUND_HALF_EVEN=6,B.ROUND_HALF_CEIL=7,B.ROUND_HALF_FLOOR=8,B.EUCLID=9,B.config=B.set=function(t){var e,n;if(null!=t){if("object"!=typeof t)throw Error(i+"Object expected: "+t);if(t.hasOwnProperty(e="DECIMAL_PLACES")&&(f(n=t[e],0,u,e),A=n),t.hasOwnProperty(e="ROUNDING_MODE")&&(f(n=t[e],0,8,e),C=n),t.hasOwnProperty(e="EXPONENTIAL_AT")&&((n=t[e])&&n.pop?(f(n[0],-u,0,e),f(n[1],0,u,e),R=n[0],P=n[1]):(f(n,-u,u,e),R=-(P=n<0?-n:n))),t.hasOwnProperty(e="RANGE"))if((n=t[e])&&n.pop)f(n[0],-u,-1,e),f(n[1],1,u,e),N=n[0],L=n[1];else{if(f(n,-u,u,e),!n)throw Error(i+e+" cannot be zero: "+n);N=-(L=n<0?-n:n)}if(t.hasOwnProperty(e="CRYPTO")){if((n=t[e])!==!!n)throw Error(i+e+" not true or false: "+n);if(n){if(!(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes)))throw U=!n,Error(i+"crypto unavailable");U=n}else U=n}if(t.hasOwnProperty(e="MODULO_MODE")&&(f(n=t[e],0,9,e),D=n),t.hasOwnProperty(e="POW_PRECISION")&&(f(n=t[e],0,u,e),I=n),t.hasOwnProperty(e="FORMAT")){if("object"!=typeof(n=t[e]))throw Error(i+e+" not an object: "+n);O=n}if(t.hasOwnProperty(e="ALPHABET")){if("string"!=typeof(n=t[e])||/^.?$|[+\-.\s]|(.).*\1/.test(n))throw Error(i+e+" invalid: "+n);F="0123456789"==n.slice(0,10),k=n}}return{DECIMAL_PLACES:A,ROUNDING_MODE:C,EXPONENTIAL_AT:[R,P],RANGE:[N,L],CRYPTO:U,MODULO_MODE:D,POW_PRECISION:I,FORMAT:O,ALPHABET:k}},B.isBigNumber=function(t){if(!t||!0!==t._isBigNumber)return!1;if(!B.DEBUG)return!0;var e,r,o=t.c,l=t.e,c=t.s;t:if("[object Array]"=={}.toString.call(o)){if((1===c||-1===c)&&l>=-u&&l<=u&&l===n(l)){if(0===o[0]){if(0===l&&1===o.length)return!0;break t}if((e=(l+1)%a)<1&&(e+=a),String(o[0]).length==e){for(e=0;e=s||r!==n(r))break t;if(0!==r)return!0}}}else if(null===o&&null===l&&(null===c||1===c||-1===c))return!0;throw Error(i+"Invalid BigNumber: "+t)},B.maximum=B.max=function(){return V(arguments,-1)},B.minimum=B.min=function(){return V(arguments,1)},B.random=(M=9007199254740992,S=Math.random()*M&2097151?function(){return n(Math.random()*M)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(t){var r,s,o,c,h,d=0,p=[],m=new B(T);if(null==t?t=A:f(t,0,u),c=e(t/a),U)if(crypto.getRandomValues){for(r=crypto.getRandomValues(new Uint32Array(c*=2));d>>11))>=9e15?(s=crypto.getRandomValues(new Uint32Array(2)),r[d]=s[0],r[d+1]=s[1]):(p.push(h%1e14),d+=2);d=c/2}else{if(!crypto.randomBytes)throw U=!1,Error(i+"crypto unavailable");for(r=crypto.randomBytes(c*=7);d=9e15?crypto.randomBytes(7).copy(r,d):(p.push(h%1e14),d+=7);d=c/7}if(!U)for(;d=10;h/=10,d++);dn-1&&(null==a[r+1]&&(a[r+1]=0),a[r+1]+=a[r]/n|0,a[r]%=n)}return a.reverse()}return function(n,i,r,s,a){var o,l,c,u,h,p,f,m,g=n.indexOf("."),_=A,x=C;for(g>=0&&(u=I,I=0,n=n.replace(".",""),p=(m=new B(i)).pow(n.length-g),I=u,m.c=e(v(d(p.c),p.e,"0"),10,r,t),m.e=m.c.length),c=u=(f=e(n,i,r,a?(o=k,t):(o=t,k))).length;0==f[--u];f.pop());if(!f[0])return o.charAt(0);if(g<0?--c:(p.c=f,p.e=c,p.s=s,f=(p=y(p,m,_,x,r)).c,h=p.r,c=p.e),g=f[l=c+_+1],u=r/2,h=h||l<0||null!=f[l+1],h=x<4?(null!=g||h)&&(0==x||x==(p.s<0?3:2)):g>u||g==u&&(4==x||h||6==x&&1&f[l-1]||x==(p.s<0?8:7)),l<1||!f[0])n=h?v(o.charAt(1),-_,o.charAt(0)):o.charAt(0);else{if(f.length=l,h)for(--r;++f[--l]>r;)f[l]=0,l||(++c,f=[1].concat(f));for(u=f.length;!f[--u];);for(g=0,n="";g<=u;n+=o.charAt(f[g++]));n=v(n,c,o.charAt(0))}return n}}(),y=function(){function t(t,e,n){var i,r,s,a,o=0,l=t.length,u=e%c,h=e/c|0;for(t=t.slice();l--;)o=((r=u*(s=t[l]%c)+(i=h*s+(a=t[l]/c|0)*u)%c*c+o)/n|0)+(i/c|0)+h*a,t[l]=r%n;return o&&(t=[o].concat(t)),t}function e(t,e,n,i){var r,s;if(n!=i)s=n>i?1:-1;else for(r=s=0;re[r]?1:-1;break}return s}function i(t,e,n,i){for(var r=0;n--;)t[n]-=r,r=t[n]1;t.splice(0,1));}return function(r,o,l,c,u){var d,p,f,m,g,v,_,x,y,b,w,M,S,E,T,A,C,R=r.s==o.s?1:-1,P=r.c,N=o.c;if(!(P&&P[0]&&N&&N[0]))return new B(r.s&&o.s&&(P?!N||P[0]!=N[0]:N)?P&&0==P[0]||!N?0*R:R/0:NaN);for(y=(x=new B(R)).c=[],R=l+(p=r.e-o.e)+1,u||(u=s,p=h(r.e/a)-h(o.e/a),R=R/a|0),f=0;N[f]==(P[f]||0);f++);if(N[f]>(P[f]||0)&&p--,R<0)y.push(1),m=!0;else{for(E=P.length,A=N.length,f=0,R+=2,(g=n(u/(N[0]+1)))>1&&(N=t(N,g,u),P=t(P,g,u),A=N.length,E=P.length),S=A,w=(b=P.slice(0,A)).length;w=u/2&&T++;do{if(g=0,(d=e(N,b,A,w))<0){if(M=b[0],A!=w&&(M=M*u+(b[1]||0)),(g=n(M/T))>1)for(g>=u&&(g=u-1),_=(v=t(N,g,u)).length,w=b.length;1==e(v,b,_,w);)g--,i(v,A<_?C:N,_,u),_=v.length,d=1;else 0==g&&(d=g=1),_=(v=N.slice()).length;if(_=10;R/=10,f++);G(x,l+(x.e=f+p*a-1)+1,c,m)}else x.e=p,x.r=+m;return x}}(),w=function(){var t=/^(-?)0([xbo])(?=\w[\w.]*$)/i,e=/^([^.]+)\.$/,n=/^\.([^.]+)$/,r=/^-?(Infinity|NaN)$/,s=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(a,o,l,c){var u,h=l?o:o.replace(s,"");if(r.test(h))a.s=isNaN(h)?null:h<0?-1:1;else{if(!l&&(h=h.replace(t,function(t,e,n){return u="x"==(n=n.toLowerCase())?16:"b"==n?2:8,c&&c!=u?t:e}),c&&(u=c,h=h.replace(e,"$1").replace(n,"0.$1")),o!=h))return new B(h,u);if(B.DEBUG)throw Error(i+"Not a"+(c?" base "+c:"")+" number: "+o);a.s=null}a.c=a.e=null}}(),E.absoluteValue=E.abs=function(){var t=new B(this);return t.s<0&&(t.s=1),t},E.comparedTo=function(t,e){return p(this,new B(t,e))},E.decimalPlaces=E.dp=function(t,e){var n,i,r,s=this;if(null!=t)return f(t,0,u),null==e?e=C:f(e,0,8),G(new B(s),t+s.e+1,e);if(!(n=s.c))return null;if(i=((r=n.length-1)-h(this.e/a))*a,r=n[r])for(;r%10==0;r/=10,i--);return i<0&&(i=0),i},E.dividedBy=E.div=function(t,e){return y(this,new B(t,e),A,C)},E.dividedToIntegerBy=E.idiv=function(t,e){return y(this,new B(t,e),0,1)},E.exponentiatedBy=E.pow=function(t,r){var s,o,l,c,u,h,d,p,f=this;if((t=new B(t)).c&&!t.isInteger())throw Error(i+"Exponent not an integer: "+W(t));if(null!=r&&(r=new B(r)),u=t.e>14,!f.c||!f.c[0]||1==f.c[0]&&!f.e&&1==f.c.length||!t.c||!t.c[0])return p=new B(Math.pow(+W(f),u?t.s*(2-m(t)):+W(t))),r?p.mod(r):p;if(h=t.s<0,r){if(r.c?!r.c[0]:!r.s)return new B(NaN);(o=!h&&f.isInteger()&&r.isInteger())&&(f=f.mod(r))}else{if(t.e>9&&(f.e>0||f.e<-1||(0==f.e?f.c[0]>1||u&&f.c[1]>=24e7:f.c[0]<8e13||u&&f.c[0]<=9999975e7)))return c=f.s<0&&m(t)?-0:0,f.e>-1&&(c=1/c),new B(h?1/c:c);I&&(c=e(I/a+2))}for(u?(s=new B(.5),h&&(t.s=1),d=m(t)):d=(l=Math.abs(+W(t)))%2,p=new B(T);;){if(d){if(!(p=p.times(f)).c)break;c?p.c.length>c&&(p.c.length=c):o&&(p=p.mod(r))}if(l){if(0===(l=n(l/2)))break;d=l%2}else if(G(t=t.times(s),t.e+1,1),t.e>14)d=m(t);else{if(0===(l=+W(t)))break;d=l%2}f=f.times(f),c?f.c&&f.c.length>c&&(f.c.length=c):o&&(f=f.mod(r))}return o?p:(h&&(p=T.div(p)),r?p.mod(r):c?G(p,I,C,void 0):p)},E.integerValue=function(t){var e=new B(this);return null==t?t=C:f(t,0,8),G(e,e.e+1,t)},E.isEqualTo=E.eq=function(t,e){return 0===p(this,new B(t,e))},E.isFinite=function(){return!!this.c},E.isGreaterThan=E.gt=function(t,e){return p(this,new B(t,e))>0},E.isGreaterThanOrEqualTo=E.gte=function(t,e){return 1===(e=p(this,new B(t,e)))||0===e},E.isInteger=function(){return!!this.c&&h(this.e/a)>this.c.length-2},E.isLessThan=E.lt=function(t,e){return p(this,new B(t,e))<0},E.isLessThanOrEqualTo=E.lte=function(t,e){return-1===(e=p(this,new B(t,e)))||0===e},E.isNaN=function(){return!this.s},E.isNegative=function(){return this.s<0},E.isPositive=function(){return this.s>0},E.isZero=function(){return!!this.c&&0==this.c[0]},E.minus=function(t,e){var n,i,r,o,l=this,c=l.s;if(e=(t=new B(t,e)).s,!c||!e)return new B(NaN);if(c!=e)return t.s=-e,l.plus(t);var u=l.e/a,d=t.e/a,p=l.c,f=t.c;if(!u||!d){if(!p||!f)return p?(t.s=-e,t):new B(f?l:NaN);if(!p[0]||!f[0])return f[0]?(t.s=-e,t):new B(p[0]?l:3==C?-0:0)}if(u=h(u),d=h(d),p=p.slice(),c=u-d){for((o=c<0)?(c=-c,r=p):(d=u,r=f),r.reverse(),e=c;e--;r.push(0));r.reverse()}else for(i=(o=(c=p.length)<(e=f.length))?c:e,c=e=0;e0)for(;e--;p[n++]=0);for(e=s-1;i>c;){if(p[--i]=0;){for(n=0,g=M[r]%y,v=M[r]/y|0,o=r+(l=d);o>r;)n=((p=g*(p=w[--l]%y)+(u=v*p+(f=w[l]/y|0)*g)%y*y+_[o]+n)/x|0)+(u/y|0)+v*f,_[o--]=p%x;_[o]=n}return n?++i:_.splice(0,1),H(t,_,i)},E.negated=function(){var t=new B(this);return t.s=-t.s||null,t},E.plus=function(t,e){var n,i=this,r=i.s;if(e=(t=new B(t,e)).s,!r||!e)return new B(NaN);if(r!=e)return t.s=-e,i.minus(t);var o=i.e/a,l=t.e/a,c=i.c,u=t.c;if(!o||!l){if(!c||!u)return new B(r/0);if(!c[0]||!u[0])return u[0]?t:new B(c[0]?i:0*r)}if(o=h(o),l=h(l),c=c.slice(),r=o-l){for(r>0?(l=o,n=u):(r=-r,n=c),n.reverse();r--;n.push(0));n.reverse()}for((r=c.length)-(e=u.length)<0&&(n=u,u=c,c=n,e=r),r=0;e;)r=(c[--e]=c[e]+u[e]+r)/s|0,c[e]=s===c[e]?0:c[e]%s;return r&&(c=[r].concat(c),++l),H(t,c,l)},E.precision=E.sd=function(t,e){var n,i,r,s=this;if(null!=t&&t!==!!t)return f(t,1,u),null==e?e=C:f(e,0,8),G(new B(s),t,e);if(!(n=s.c))return null;if(i=(r=n.length-1)*a+1,r=n[r]){for(;r%10==0;r/=10,i--);for(r=n[0];r>=10;r/=10,i++);}return t&&s.e+1>i&&(i=s.e+1),i},E.shiftedBy=function(t){return f(t,-o,o),this.times("1e"+t)},E.squareRoot=E.sqrt=function(){var t,e,n,i,r,s=this,a=s.c,o=s.s,l=s.e,c=A+4,u=new B("0.5");if(1!==o||!a||!a[0])return new B(!o||o<0&&(!a||a[0])?NaN:a?s:1/0);if(0==(o=Math.sqrt(+W(s)))||o==1/0?(((e=d(a)).length+l)%2==0&&(e+="0"),o=Math.sqrt(+e),l=h((l+1)/2)-(l<0||l%2),n=new B(e=o==1/0?"5e"+l:(e=o.toExponential()).slice(0,e.indexOf("e")+1)+l)):n=new B(o+""),n.c[0])for((o=(l=n.e)+c)<3&&(o=0);;)if(r=n,n=u.times(r.plus(y(s,r,c,1))),d(r.c).slice(0,o)===(e=d(n.c)).slice(0,o)){if(n.e0&&m>0){for(a=m%l||l,h=f.substr(0,a);a0&&(h+=u+f.slice(a)),p&&(h="-"+h)}r=d?h+(n.decimalSeparator||"")+((c=+n.fractionGroupSize)?d.replace(new RegExp("\\d{"+c+"}\\B","g"),"$&"+(n.fractionGroupSeparator||"")):d):h}return(n.prefix||"")+r+(n.suffix||"")},E.toFraction=function(t){var e,n,r,s,o,c,u,h,p,f,m,g,v=this,_=v.c;if(null!=t&&(!(u=new B(t)).isInteger()&&(u.c||1!==u.s)||u.lt(T)))throw Error(i+"Argument "+(u.isInteger()?"out of range: ":"not an integer: ")+W(u));if(!_)return new B(v);for(e=new B(T),p=n=new B(T),r=h=new B(T),g=d(_),o=e.e=g.length-v.e-1,e.c[0]=l[(c=o%a)<0?a+c:c],t=!t||u.comparedTo(e)>0?o>0?e:p:u,c=L,L=1/0,u=new B(g),h.c[0]=0;f=y(u,e,0,1),1!=(s=n.plus(f.times(r))).comparedTo(t);)n=r,r=s,p=h.plus(f.times(s=p)),h=s,e=u.minus(f.times(s=e)),u=s;return s=y(t.minus(n),r,0,1),h=h.plus(s.times(p)),n=n.plus(s.times(r)),h.s=p.s=v.s,m=y(p,r,o*=2,C).minus(v).abs().comparedTo(y(h,n,o,C).minus(v).abs())<1?[p,r]:[h,n],L=c,m},E.toNumber=function(){return+W(this)},E.toPrecision=function(t,e){return null!=t&&f(t,1,u),z(this,t,e,2)},E.toString=function(t){var e,n=this,i=n.s,r=n.e;return null===r?i?(e="Infinity",i<0&&(e="-"+e)):e="NaN":(null==t?e=r<=R||r>=P?g(d(n.c),r):v(d(n.c),r,"0"):10===t&&F?e=v(d((n=G(new B(n),A+r+1,C)).c),n.e,"0"):(f(t,2,k.length,"Base"),e=b(v(d(n.c),r,"0"),10,t,i,!0)),i<0&&n.c[0]&&(e="-"+e)),e},E.valueOf=E.toJSON=function(){return W(this)},E._isBigNumber=!0,E[Symbol.toStringTag]="BigNumber",E[Symbol.for("nodejs.util.inspect.custom")]=E.valueOf,null!=x&&B.set(x),B}(),x=class t{constructor(t,e){this.base=t,this.power=e}static fromBase(e){return new t(e,1)}withPower(e){return new t(this.base,e)}getName(){return this.base.name}toText(){return this.base.toText()+(1===this.power?"":"^"+this.power)}},y=class t{static{this.ONE=new t(new Map)}static one(){return t.ONE}static fromTerm(e){return new t(new Map([[e.getName(),e]]))}static fromBase(e){return t.fromTerm(x.fromBase(e))}constructor(t){this.termMap=new Map;for(let e of t.values())0!==e.power&&this.termMap.set(e.getName(),e)}power(t){return this.termMap.get(t.name)?.power||0}terms(){return Array.from(this.termMap.values())}bases(){return Array.from(this.termMap.values()).map(t=>t.base)}equals(t){for(let e of this.termMap.values())if(e.power!==t.power(e.base))return!1;for(let e of t.termMap.values())if(e.power!==this.power(e.base))return!1;return!0}mult(e){var n=new Map;for(let t of this.termMap.values())n.set(t.getName(),t);for(let t of e.termMap.values())n.set(t.getName(),t.withPower(t.power+this.power(t.base)));return new t(n)}expt(e){var n=new Map;for(let t of this.termMap.values())n.set(t.getName(),t.withPower(t.power*e));return new t(n)}reciprocal(){return this.expt(-1)}div(t){return this.mult(t.reciprocal())}isDimensionless(){return 0===this.termMap.size}toText(){let t="",e="";for(let n of this.termMap.values())n.power>0&&(t+=e+n.toText(),e="*");e="/";for(let n of this.termMap.values())n.power<0&&(t+=e+n.withPower(-n.power).toText());return t}map(e){var n=new t(new Map);for(let t of this.termMap.values()){var i=e(t.base);n=n.mult(i.expt(t.power))}return n}fold(t,e,n){let i=Array.from(this.termMap.values());if(0===i.length){if(void 0===n)throw Error("Folding an empty unit but no default value is provided");return n}return i.map(e=>t(e.base,e.power)).reduce(e)}},b=class t{constructor(t,e){this.magnitude=t,this.unit=e}static{this.ONE=new t(new _(1),new y(new Map))}static dimless(e){return new t(e,P.ONE)}static fromUnit(e){return new t(new _(1),e)}static fromNumber(e,n=P.ONE){return new t(new _(e),n)}static fromString(e,n=P.ONE){return new t(new _(e),n)}withUnit(e){return new t(this.magnitude,e)}withMagnitude(e){return new t(e,this.unit)}equals(t){return 0===this.magnitude.comparedTo(t.magnitude)&&this.unit.equals(t.unit)}sum(e){if(!this.unit.equals(e.unit))throw new Error("Cannot sum "+this.toText()+" and "+e.toText()+" because the units differ");return new t(this.magnitude.plus(e.magnitude),this.unit)}scale(e){return new t(this.magnitude.multipliedBy(e),this.unit)}mult(e){return new t(this.magnitude.multipliedBy(e.magnitude),this.unit.mult(e.unit))}expt(e){return new t(this.magnitude.exponentiatedBy(e),this.unit.expt(e))}reciprocal(){return this.expt(-1)}div(t){return this.mult(t.reciprocal())}round(){return new t(this.magnitude.integerValue(_.ROUND_HALF_CEIL),this.unit)}isDimensionless(){return this.unit.isDimensionless()}print(){let t=this.magnitude.toFixed(),e=this.unit.fold((t,e)=>1===e?t.name:`${t.name}^${e}`,(t,e)=>t+"*"+e,"");return 0===e.length?t:"1"===t?e:t+"*"+e}toText(){let t=this.magnitude.toString(),e=this.unit.toText();return 0===e.length?t:t+("/"===e[0]?"":"*")+e}toFixed(t){let e=this.unit.toText();return 0===e.length?this.magnitude.toFixed(t):this.magnitude.toFixed(t)+("/"===e[0]?"":" ")+e}toLocale(t,e){let n=1.1.toLocaleString(e)[1],i=this.unit.toText();return this.magnitude.toFixed(t).replace(".",n)+(""===i?"":" "+i)}toPrecision(t){let e=this.unit.toText();return 0===e.length?this.magnitude.toPrecision(t):this.magnitude.toPrecision(t)+("/"===e[0]?"":"*")+this.unit.toText()}};function w(t,e){let n=e.map(t=>({tag:t.tag,regex:new RegExp("\\s*"+t.regex+"\\s*","y")})).concat({tag:"eof",regex:/$/}),i=[],r=0,s=M(t,n,0);for(;void 0!==s&&"eof"!==s.tag;)i.push(s),r=s.position,s=M(t,n,s.position);if(void 0===s)throw new Error("Unknown token at "+r);return i}function M(t,e,n){for(let i=0;i0&&("times"===s[0].tag||"div"===s[0].tag);)switch(s[0].tag){case"times":{let t=A(s.slice(1),e,n);r=r.mult(t.num),s=t.rest;break}case"div":{let t=A(s.slice(1),e,n);r=r.div(t.num),s=t.rest;break}}return{num:r,rest:s}}function A(t,e,n){if(0===w.length)throw new Error("Expected unit term");let i,r,s=t[0];switch(s.tag){case"left":{let a=T(t.slice(1),e,n);if(0===a.rest.length)throw new Error("missing closing parenthesis opening at "+s.position);if("right"!==a.rest[0].tag)throw new Error("Missing closing parenthesis opening at "+s.position);i=a.num,r=a.rest.slice(1);break}case"scaled":i=b.fromUnit(n(s.data[1],s.data[2])),r=t.slice(1);break;case"identifier":e(s.data[1]),i=b.fromUnit(e(s.data[1])),r=t.slice(1);break;case"integer":case"decimal":i=b.dimless(new _(s.data[1])),r=t.slice(1)}if(void 0===i||void 0===r)throw new Error("Expected unit term but got "+s.tag);if(r.length>0&&"power"===r[0].tag){if("integer"!==r[1].tag)throw new Error("expected integer power");i=i.expt(parseInt(r[1].data[1])),r=r.slice(2)}return{num:i,rest:r}}var C=class t{constructor(t,e,n){this.power=t,this.name=e,this.symbol=n}equals(t){return this.power===t.power}static{this.empty=new t(0,"","")}isEmpty(){return 0===this.power}},R=class t{constructor(t,e,n){this.prefix=t,this.base=e,this.symbol=n,this.name=this.prefix.isEmpty()?e:this.prefix.name+":"+e}static from(e,n){return new t(C.empty,e,n)}withPrefix(e){return new t(e,this.base,this.symbol)}isPrimitive(){return this.prefix.isEmpty()}toText(){return this.prefix.symbol+this.symbol}},P=class extends y{static{this.ONE=new y(new Map)}},N=class t{constructor(t,e,n){this.prefixes=new Map,this.bases=new Map,this.equations=new Map,this.unitCache=new Map;for(let e of t)this.prefixes.set(e.name,e);for(let t of e.values())this.bases.set(t.name,t);for(let[t,e]of n)this.equations.set(t,e)}static empty(){return new t([C.empty],[],[])}static fromDef(e){return t.empty().loadDef(e)}loadDef(t){for(let e of t.prefixes)this.prefixes.set(e.name,new C(e.power,e.name,e.symbol));for(let e of t.bases)this.addSIBase(R.from(e.name,e.symbol));for(let e of t.equations){let t=this.parseSIUnit(e.rhs),n=new b(new _(e.rhs.factor||1),t);this.equations.set(e.lhs,n)}return this}parseSIUnit(t){return function(t,e){if(!t.powers)throw new Error("expected powers in unit json "+t);return t.powers.map(n=>{if(!n.base)throw new Error("expected base in the powers of unit json "+t);if(!n.base.name)throw new Error("expected name in the base of the powers of unit json "+t);let i=e(n.base.prefix||"",n.base.name);if(!i)throw new Error("Cannot create unit from json. Base callback returned invalid base for "+n.base.name);return i.expt(n.power||1)}).reduce((t,e)=>t.mult(e),y.ONE)}(t,(t,e)=>{if(this.prefixes.get(t))return this.getScaledUnit(t,e);throw new Error("Cannot create unit from json. Invalid prefix: "+t)})}addBase(t,e,n){this.addSIBase(R.from(t,e),n)}addSIBase(t,e){this.bases.set(t.name,t),void 0!==e&&this.equations.set(t.name,e)}getBases(){return Array.from(this.bases.values())}getPrefixes(){return Array.from(this.prefixes.values())}getPrefix(t){let e=this.prefixes.get(t);if(!e)throw new Error("Prefix "+t+" unknown");return e}getScaledUnit(t,e){let n=this.lookupScaledUnit(t,e);if(void 0===n)throw new Error(`Base '${e}' unknown (prefix override = ${t})`);return n}lookupScaledUnit(t,e){let n=e.split(":"),i=2===n.length?n[1]:e,r=t.length>0?t+":"+i:i;return this.unitCache.get(r)||this.getUnitFromBase(t,i,r)}getUnit(t){let e=this.lookupUnit(t);if(void 0===e)throw new Error("Base '"+t+"' unknown");return e}lookupUnit(t){let e=this.unitCache.get(t);if(e)return e;{let e=t.split(":");return 2===e.length?this.getUnitFromBase(e[0],e[1],t):this.getUnitFromBase("",t,t)}}getUnitFromBase(t,e,n){let i=this.prefixes.get(t),r=this.bases.get(e);if(!r)return;if(!i)throw new Error("Prefix '"+t+"' unknown in unit "+n);let s=y.fromBase(r.withPrefix(i));return this.unitCache.set(n,s),s}flatten(t){let e=b.ONE;for(let n of t.termMap.values()){let t=n.base.prefix.power*n.power,i=new _(1).shiftedBy(t),r=this.equations.get(n.base.base);if(r)e=e.mult(this.flattenDimNum(r.expt(n.power))).scale(i);else{let t=y.fromBase(n.base.withPrefix(C.empty)).expt(n.power);e=e.mult(new b(i,t))}}return e}flattenDimNum(t){let e=this.flatten(t.unit);return new b(t.magnitude.multipliedBy(e.magnitude),e.unit)}convertDimNum(t,e){return new b(t.magnitude.multipliedBy(this.conversionFactor(t.unit,e)),e)}conversionFactor(t,e){var n=this.flatten(t.div(e));if(n.isDimensionless())return n.magnitude;throw new Error("cannot convert unit "+t.toText()+" to unit "+e.toText())}conversionFactorMaybe(t,e){var n=this.flatten(t.div(e));if(n.isDimensionless())return n.magnitude}genDef(){return{prefixes:Array.from(this.prefixes.values()).map(t=>({name:t.name,power:t.power,symbol:t.symbol})),bases:Array.from(this.bases.values()).map(t=>({name:t.name,symbol:t.symbol})),equations:Array.from(this.equations.entries()).map(([t,e])=>({lhs:t,rhs:{factor:e.magnitude,powers:Array.from(e.unit.termMap.values()).map(t=>({base:{name:t.base.base,prefix:t.base.prefix.name},power:t.power}))}}))}}toText(){return"Prefixes:\n"+Array.from(this.prefixes.values()).filter(t=>0!==t.power).map(t=>" "+t.name+" ("+t.symbol+") = 10^"+t.power).join("\n")+"\nBases:\n"+Array.from(this.bases.values()).map(t=>" "+t.name+" ("+t.symbol+")").join("\n")+"\nEquations:\n"+Array.from(this.equations.entries()).map(([t,e])=>" "+t+" = "+e.toText()).join("\n")}parseDimNum(t){return E(t,this.getUnit.bind(this),this.getScaledUnit.bind(this))}},L={prefixes:[{name:"yocto",power:-24,symbol:"y"},{name:"zepto",power:-21,symbol:"z"},{name:"atto",power:-18,symbol:"a"},{name:"femto",power:-15,symbol:"f"},{name:"pico",power:-12,symbol:"p"},{name:"nano",power:-9,symbol:"n"},{name:"micro",power:-6,symbol:"µ"},{name:"milli",power:-3,symbol:"m"},{name:"centi",power:-2,symbol:"c"},{name:"deci",power:-1,symbol:"d"},{name:"kilo",power:3,symbol:"k"},{name:"mega",power:6,symbol:"M"},{name:"giga",power:9,symbol:"G"},{name:"tera",power:12,symbol:"T"},{name:"peta",power:15,symbol:"P"},{name:"exa",power:18,symbol:"E"},{name:"zetta",power:21,symbol:"Z"},{name:"yotta",power:24,symbol:"Y"}],bases:[{name:"gram",symbol:"g"},{name:"ampere",symbol:"A"},{name:"kelvin",symbol:"K"},{name:"mole",symbol:"mol"},{name:"candela",symbol:"cd"},{name:"second",symbol:"s"},{name:"metre",symbol:"m"}],equations:[]},U=N.fromDef(L),D=__webpack_require__(505),I=__webpack_require__.n(D);function O(t){const e=t.nrRows,n=t.nrColumns,i=function(t){var i;const r=Array.from({length:e});for(let s=0;st[0]>e[0]?1:t[0]e[1]?1:t[1]t.name).join(" % ")}kronecker(t){return new z([...this.indexSets,...t.indexSets])}slice(t,e){return new z(this.indexSets.slice(t,e))}order(){return this.indexSets.length}}class V{static fromIndex(t,e){const n=[];let i=e;for(let e=t.length-1;0<=e;e--){const r=t[e].items.length;n[e]=t[e].items[i%r],i=Math.floor(i/r)}return new V(n,t)}constructor(t,e){this.names=t,this.indexSets=e,this.kind="coordinates"}position(){let t=0;for(let e=0;e{if(t.position===n){const i=t.vector,r=e[n];return i.get(t.vector.indexSet.position(r))}return P.ONE};let i=P.ONE;for(let e=0;en(t,e)));return i}join(t){return new V([...this.names,...t.names],[...this.indexSets,...t.indexSets])}slice(t,e){return new V(this.names.slice(t,e),this.indexSets.slice(t,e))}}class H extends y{}H.ONE=new y(new Map);class G{static scalar(t){return new G(t,z.empty(),H.ONE,z.empty(),H.ONE)}constructor(t,e,n,i,r){this.multiplier=t,this.rowDimension=e,this.rowUnit=n,this.columnDimension=i,this.columnUnit=r,this.kind="matrixshape"}toText(){let t="("+this.multiplier.toText()+"|";return t+=this.rowDimension.toText()+"|",t+=this.rowUnit.toText()+"|",t+=this.columnDimension.toText()+"|",t+=this.columnUnit.toText()+"|",t+=")",t}rowOrder(){return this.rowDimension.order()}columnOrder(){return this.columnDimension.order()}equals(t){return this.multiplier.equals(t.multiplier)&&this.rowDimension.equals(t.rowDimension)&&this.columnDimension.equals(t.columnDimension)&&this.rowUnit.equals(t.rowUnit)&&this.columnUnit.equals(t.columnUnit)}isScalar(){return 0===this.rowDimension.order()&&0===this.columnDimension.order()}mult(t){return t.isScalar()?this.scale(t):this.isScalar()?t.scale(this):new G(this.multiplier.mult(t.multiplier),this.rowDimension,this.rowUnit.mult(t.rowUnit),this.columnDimension,this.columnUnit.mult(t.columnUnit))}dot(t){if(!this.columnDimension.equals(t.rowDimension)&&this.columnUnit.equals(t.rowUnit))throw new Error("Shape "+this.toText()+" is not compatible for dot product with shape "+t.toText());return new G(this.multiplier.mult(t.multiplier),this.rowDimension,this.rowUnit,t.columnDimension,t.columnUnit)}scale(t){return new G(this.multiplier.mult(t.multiplier),this.rowDimension,this.rowUnit,this.columnDimension,this.columnUnit)}transpose(){return new G(this.multiplier,this.columnDimension,this.columnUnit.reciprocal(),this.rowDimension,this.rowUnit.reciprocal())}reciprocal(){return new G(this.multiplier.reciprocal(),this.rowDimension,this.rowUnit.reciprocal(),this.columnDimension,this.columnUnit.reciprocal())}kron(t){const e=this.rowOrder(),n=this.columnOrder();return new G(this.multiplier.mult(t.multiplier),this.rowDimension.kronecker(t.rowDimension),this.rowUnit.mult(t.rowUnit.map(t=>y.fromBase(t.shift(e)))),this.columnDimension.kronecker(t.columnDimension),this.columnUnit.mult(t.columnUnit.map(t=>y.fromBase(t.shift(n)))))}dimensionless(){return new G(P.ONE,this.rowDimension,H.ONE,this.columnDimension,H.ONE)}nrRows(){let t=1;for(let e=0;et.names.join(",")+` (${t.unit.toText()})`)}columnNames(){return this.columnIndices().map(t=>t.names.join(",")+` (${t.unit.toText()})`)}rowHeaders(){return this.rowDimension.indexSets.map(function(t){return t.name})}rowHeader(){return this.rowHeaders().reduce(function(t,e){return t+"%"+e},"")}columnHeaders(){return this.columnDimension.indexSets.map(function(t){return t.name})}columnHeader(){return this.columnHeaders().reduce(function(t,e){return t+"%"+e},"")}findRowUnit(t){return this.rowCoordinates(t).findIndividualUnit(this.rowUnit)}findColumnUnit(t){return this.columnCoordinates(t).findIndividualUnit(this.columnUnit)}unitAt(t,e){return this.multiplier.mult(this.findRowUnit(t)).div(this.findColumnUnit(e))}reorder(t,e){const n=this.rowOrder(),i=this.columnOrder();if(t===n&&e===i)return this;if(t+e!==n+i)throw new Error(`Cannot reorder matrix from (${n.toString()},${i.toString()}) to (${t.toString()},${e.toString()}). The total order must be equal.`);const r=this.rowDimension.kronecker(this.columnDimension),s=r.slice(0,t),a=r.slice(t),o=this.rowUnit.mult(this.columnUnit.reciprocal().map(t=>y.fromBase(t.shift(n)))),l=o.map(e=>e.position>=t?H.ONE:y.fromBase(e)),c=o.map(e=>e.positiony.fromBase(e.shift(-t))).reciprocal();return new G(this.multiplier,s,l,a,c)}}class W{constructor(t,e){this.type=t,this.value=e,this.kind="maybe"}}class j{constructor(t){this.value=t,this.kind="maybe"}}const X={kind:"void"};class ${static fromItems(t,e,n){const i=new Map;for(const[t,e]of n.entries())i.set(e,t);return new $(t,e,n,i)}constructor(t,e,n,i){this.id=t,this.name=e,this.items=n,this.index=i}size(){return this.items.length}position(t){const e=this.index.get(t);if(void 0===e)throw new Error("Element "+t+" not found when looking for position in index set "+this.name);return e}}class q{constructor(t,e,n){this.name=t,this.indexSet=e,this.elements=n}static fromMap(t,e,n){var i;const r=[];for(const t of e.items)r.push(null!==(i=n.get(t))&&void 0!==i?i:P.ONE);return new q(t,e,r)}toText(){return this.name}get(t){return this.elements[t]}}const Y={prefixes:[{name:"yocto",power:-24,symbol:"y"},{name:"zepto",power:-21,symbol:"z"},{name:"atto",power:-18,symbol:"a"},{name:"femto",power:-15,symbol:"f"},{name:"pico",power:-12,symbol:"p"},{name:"nano",power:-9,symbol:"n"},{name:"micro",power:-6,symbol:"µ"},{name:"milli",power:-3,symbol:"m"},{name:"centi",power:-2,symbol:"c"},{name:"deci",power:-1,symbol:"d"},{name:"kilo",power:3,symbol:"k"},{name:"mega",power:6,symbol:"M"},{name:"giga",power:9,symbol:"G"},{name:"tera",power:12,symbol:"T"},{name:"peta",power:15,symbol:"P"},{name:"exa",power:18,symbol:"E"},{name:"zetta",power:21,symbol:"Z"},{name:"yotta",power:24,symbol:"Y"}],bases:[],equations:[]};class Z{static si(){return new Z(N.fromDef(L),new Map,new Map)}static empty(){return new Z(N.fromDef(Y),new Map,new Map)}static fromUOMContext(t){return new Z(t,new Map,new Map)}constructor(t,e=new Map,n=new Map){this.unitContext=t,this.unitVectors=e,this.indexSets=n}addBase(t,e,n){this.unitContext.addBase(t,e,n)}getUnit(t,e){return this.unitContext.getScaledUnit(t,e)}lookupUnit(t,e){return this.unitContext.lookupScaledUnit(t,e)}addIndexSet(t){return this.indexSets.set(t.id,t),this}findIndexSet(t){return this.indexSets.get(t)}getIndexSets(){return[...this.indexSets.values()]}addUnitVectorFromJSON(t,e,n){const i=this.findIndexSet(e);if(i){const e=new Map;for(const t of n)e.set(t.name,this.unitContext.parseSIUnit(t.unit));const r=q.fromMap(t,i,e);return this.addUnitVector(r),r}throw new Error("Index set "+e+" unknown when creating unit vector "+t)}addUnitVector(t){return this.unitVectors.set(t.name,t),this}findUnitVector(t){return this.unitVectors.get(t)}}class K{constructor(t){this.sets=t,this.kind="index"}}class J{constructor(t,e,n,i,r){this.multiplier=t,this.rowIndex=e,this.rowUnit=n,this.columnIndex=i,this.columnUnit=r,this.kind="matrix"}}const Q={kind:"boole",value:!0},tt={kind:"boole",value:!1};class et{constructor(t,e,n){this.fun=t,this.type=e,this.context=n,this.kind="function"}apply(t){const e=t.map(t=>vt(t)),n=t.map(t=>_t(t)),i=this.type.from.items.length;if(t.length===i){const t=this.type.apply(e);return mt(this.fun(...n),t,this.context)}throw new Error(`Number of arguments do not match. Expected ${i.toString()}, but got ${t.length.toString()}`)}call(...t){return this.apply(t)}}class nt{constructor(t){this.value=t,this.kind="string"}}class it{constructor(t,e,n){this.vector=t,this.position=e,this.baseName=n,this.name=n+":"+e.toString()}getName(){return this.name}toText(){return this.name}get(t){return this.vector.get(t)}shift(t){return new it(this.vector,this.position+t,this.baseName)}}class rt{constructor(t,e){this.name=t,this.items=e,this.kind="generic"}}class st{constructor(t,e){if(this.prefix=t,this.base=e,this.kind="sibasetype",this.isVar=!1,"string"!=typeof t)throw new Error("prefix error");if(e.includes(":"))throw new Error(`Double colon: prefix=${t} name=${e}`);this.name=0===t.length?e:t+":"+e}toText(){return""===this.prefix?this.name:this.prefix+":"+this.name}}class at{constructor(t,e){this.name=t,this.position=e,this.kind="vectorbasetype",this.isVar=!1}toText(){return this.name+"$"+this.position.toString()}shift(t){return new at(this.name,this.position+t)}}class ot extends Array{constructor(...t){super(),this.kind="tuple",this.push(...t)}}class lt extends Array{constructor(t,...e){super(),this.type=t,this.kind="list",this.push(...e)}}class ct extends Array{constructor(){super(...arguments),this.kind="array"}}class ut{constructor(t,e,n,i,r={}){this.indexHeaders=t,this.index=e,this.header=n,this.values=i,this.options=r}total(){return function(t){let e;for(const n of t){const t=n;if(void 0===e)e=t;else{if(!e.unit.equals(t.unit))return;e=e.sum(t)}}return e}(this.values.map(t=>t.num))}static fromVector(t,e,n={}){return function(t,e,n={}){const i=[...t.rowIndexSets().map(t=>t.name),...t.columnIndexSets().map(t=>t.name)],r=[],s=[],a=t.shape,o=a.nrRows(),l=a.nrColumns();if(0===o||0===l)throw new Error("No rows and columns?");{const e=O(t.numbers);for(let t=0;t{const e={decimals:t.decimals,unit:t.unit,raw:t.raw,exponential:t.exponential,showTotal:t.showTotal,total:t.total};return"matrix"===t.value.kind?ut.fromVector(t.value,t.header,e):ut.fromList(t.value,t.header,e)});return new Li(n,e).dom()}class ft{constructor(t,e,n,i){this.srcType=t,this.dstType=e,this.rawMap=n,this.context=i,this.kind="map"}dom(){return function(t,e,n,i){const r=t.rawMap.keyMap,s=t.rawMap.valueMap,a=document.createElement("ul");for(const t of r.keys()){const o=r.get(t),l=s.get(t);if(void 0!==o&&void 0!==l){const t=document.createElement("li");t.appendChild(ht(mt(o,e,i))),t.appendChild(document.createTextNode("→")),t.appendChild(ht(mt(l,n,i))),a.appendChild(t)}}return a}(this,this.srcType,this.dstType,this.context)}}function mt(t,e,n){switch(e.kind){case"generic":switch(e.name){case"Tuple":{const i=t,r=new ot;for(const[t,s]of i.entries())r.push(mt(s,e.items[t],n));return r}case"Boole":if("boolean"==typeof t)return t?Q:tt;throw new Error(`Expected a boolean instead of ${typeof t} when boxing raw boolean value`);case"String":if("string"==typeof t)return new nt(t);throw new Error(`Expected a string instead of ${typeof t} when boxing raw string value`);case"Void":return X;case"Maybe":{const i=t.value;return new W(e,void 0===i?void 0:mt(i,e.items[0],n))}case"List":if(Array.isArray(t)){const i=t,r=new lt(e);for(const t of i)r.push(mt(t,e.items[0],n));return r}throw new Error(`Expected an array object instead of ${typeof t} when boxing raw list value`);case"Array":if(Array.isArray(t)){const i=t,r=new ct;for(const t of i)r.push(mt(t,e.items[0],n));return r}throw new Error(`Expected an array object instead of ${typeof t} when boxing raw array value`);case"Map":return new ft(e.items[0],e.items[1],t,n);default:throw new Error(`Unxpected type '${e.name}' for value ${Wi(t)} `)}case"function":if("function"==typeof t)return new et(t,e,n);throw new Error(`Expected a function instead of ${typeof t} when boxing raw function value`);case"matrix":return new $i(gt(e,n),t);case"typevar":throw new Error(`Unxpected typevar '${e.kind}' for type ${typeof t} with value ${e.name} `);case"index":{const i=t,r=xt(e,n);return V.fromIndex(r.indexSets,i.position)}}}function gt(t,e){const n=xt(t.rowIndex,e),i=xt(t.columnIndex,e);return new G(bt(t.multiplier,e),n,wt(n,t.rowUnit,e),i,wt(i,t.columnUnit,e))}function vt(t){switch(t.kind){case"matrix":return new J(function(t){return t.map(t=>y.fromBase(new st(t.prefix.name,t.base)))}(t.shape.multiplier),yt(t.shape.rowDimension),Mt(t.shape.rowUnit),yt(t.shape.columnDimension),Mt(t.shape.columnUnit));case"list":case"function":return t.type;case"tuple":return new rt("Tuple",t.map(t=>vt(t)));case"string":return new rt("String",[]);case"boole":return new rt("Boole",[]);default:throw new Error(`Unexpected value kind ${t.kind}`)}}function _t(t){switch(t.kind){case"matrix":return t.numbers;case"tuple":return Hi(t.map(t=>_t(t)));case"list":return Vi(t.map(t=>_t(t)));case"string":case"boole":return t.value;case"function":return t.fun;case"maybe":return void 0===t.value?Bi:new j(_t(t.value));default:throw new Error(`unexpected value kind ${t.kind}`)}}function xt(t,e){if("index"===t.kind)return new z(t.sets.map(t=>Dt(t,e)));throw new Error("index kind "+t.kind+" unexpected")}function yt(t){return new K(t.indexSets.map(t=>t.id))}function bt(t,e){return t.map(t=>{if(t.isVar)throw new Error("cannot have variable");return It(t.prefix,t.base,e)})}function wt(t,e,n){const i=e.map(e=>{if(e.isVar)throw new Error("cannot intern a unit containing a unit variable");{const i=function(t,e,n=St){const i=n.findUnitVector(t);if(void 0===i){const i=zt(t)().units,r=new Map;for(const[t,e]of Object.entries(i))r.set(t,bt(e,n));const s=q.fromMap(t,e,r);return n.addUnitVector(s),s}return i}(e.name,t.indexSets[e.position],n);return y.fromBase(new it(i,e.position,e.name))}});return i}function Mt(t){return t.map(t=>y.fromBase(new at(t.baseName,t.position)))}const St=Z.empty();function Et(t,e,n){return $.fromItems(t,e,n)}function Tt(t,e=St){const n=[],i=[];for(const[r,s]of t.entries())n[r]=s[0],i[r]=Dt(s[1],e);const r=new V(n,i);return{kind:"coordinates",position:r.position(),size:r.size(),coords:r}}function At(t,e){return zi([],t,e,"DOK")}function Ct(t,e){const n=zi([],t,e,"DOK");for(let i=0;iMath.abs(e)?(n=e/t,n=Math.abs(t)*Math.sqrt(1+n*n)):0!==e?(n=t/e,n=Math.abs(e)*Math.sqrt(1+n*n)):n=0,n}function Ht(t,e){const n=[];for(var i=0;iArray.from(t))}globalThis.Pacioli={};class jt{constructor(t){if(0===t.length)throw new Error("Matrix cannot have empty rows.");var e=Wt(t);if(this.m=e.length,this.n=e[0].length,this.m= n)");var n=Math.min(this.m,this.n);this.s=Gt(Math.min(this.m+1,this.n)),this.U=Ht(this.m,n),this.V=Ht(this.n,this.n);for(var i=function(t){for(var e=[];t-- >0;)e.push(0);return e}(this.n),r=function(t){for(var e=[];t-- >0;)e.push(0);return e}(this.m),s=Math.min(this.m-1,this.n),a=Math.max(0,Math.min(this.n-2,this.m)),o=0;o=0;o--)if(0!==this.s[o]){for(c=o+1;c=0;o--){if(function(t,e){return t&&e}(o0;){o=0;var m=0;for(o=h-2;o>=-1&&-1!==o;o--)if(Math.abs(i[o])<=f+p*(Math.abs(this.s[o])+Math.abs(this.s[o+1]))){i[o]=0;break}if(o===h-2)m=4;else{var g=0;for(g=h-1;g>=o&&g!==o;g--)if(u=(g!==h?Math.abs(i[g]):0)+(g!==o+1?Math.abs(i[g-1]):0),Math.abs(this.s[g])<=f+p*u){this.s[g]=0;break}g===o?m=3:g===h-1?m=1:(m=2,o=g)}switch(o++,m){case 1:var v=i[h-2];for(i[h-2]=0,c=h-2;c>=o;c--){u=Vt(this.s[c],v);var _=this.s[c]/u,x=v/u;for(this.s[c]=u,c!==o&&(v=-x*i[c-1],i[c-1]=_*i[c-1]),l=0;l=this.s[o+1]);){if(u=this.s[o],this.s[o]=this.s[o+1],this.s[o+1]=u,oe&&n++;return n}}class Xt{constructor(t){if(this.n=t.length,0===t.length)throw new Error("Matrix cannot have empty rows.");this.L=Ht(this.n,this.n),this.isspd=t[0].length===this.n;for(var e=0;e0),this.L[e][e]=Math.sqrt(Math.max(i,0)),r=e+1;r=0;i--)for(r=0;rArray.from(t)),this.Rdiag=[];for(var e=0;e=n?this.QR[e][n]:0;return t}getR(){const t=Ht(this.n,this.n);for(var e=0;e=0;e--){for(var n=0;nArray.from(t)),this.piv=[];for(var e=0;e0;)e.push(0);return e}(this.m),r=0;rMath.abs(i[l])&&(l=e);if(l!==r){for(var c=0;cn?this.LU[e][n]:e===n?1:0;return t}getU(){for(var t=Ht(this.n,this.n),e=0;e0;e--){for(var n=0,i=0,r=0;r0&&(a=-a),this.e[e]=n*a,i-=s*a,this.d[e-1]=s-a,t=0;tr)do{var a=this.d[r],o=Vt(v=(this.d[r+1]-a)/(2*this.e[r]),1);v<0&&(o=-o),this.d[r]=this.e[r]/(v+o),this.d[r+1]=this.e[r]*(v+o);var l=this.d[r+1],c=a-this.d[r];for(t=r+2;t=r;t--){d=h,h=u,m=f,a=u*this.e[t],c=u*v,o=Vt(v,this.e[t]),this.e[t+1]=f*o,f=this.e[t]/o,v=(u=v/o)*this.d[t]-f*a,this.d[t+1]=c+f*(u*a+f*this.d[t]);for(var g=0;gi*n);this.d[r]=this.d[r]+e,this.e[r]=0}for(t=0;t=e;i--)this.ort[i]=this.H[i][e-1]/n,r+=this.ort[i]*this.ort[i];var s=Math.sqrt(r);this.ort[e]>0&&(s=-s),r-=this.ort[e]*s,this.ort[e]=this.ort[e]-s;for(var a=e;a=e;i--)o+=this.ort[i]*this.H[i][a];for(o/=r,i=e;i<=t;i++)this.H[i][a]-=o*this.ort[i]}for(i=0;i<=t;i++){for(o=0,a=t;a>=e;a--)o+=this.ort[a]*this.H[i][a];for(o/=r,a=e;a<=t;a++)this.H[i][a]-=o*this.ort[a]}this.ort[e]=n*this.ort[e],this.H[e][e-1]=n*s}}for(i=0;i=1;e--)if(0!==this.H[e][e-1]){for(i=e+1;i<=t;i++)this.ort[i]=this.H[i][e-1];for(a=e;a<=t;a++){for(s=0,i=e;i<=t;i++)s+=this.ort[i]*this.V[i][a];for(s=s/this.ort[e]/this.H[e][e-1],i=e;i<=t;i++)this.V[i][a]+=s*this.ort[i]}}}cdiv(t,e,n,i){var r,s;Math.abs(n)>Math.abs(i)?(s=n+(r=i/n)*i,this.cdivr=(t+r*e)/s,this.cdivi=(e-r*t)/s):(s=i+(r=n/i)*n,this.cdivr=(r*t+e)/s,this.cdivi=(r*e-t)/s)}hqr2(){for(var t,e,n,i,r=this.n,s=r-1,a=r-1,o=Math.pow(2,-52),l=0,c=0,u=0,h=0,d=0,p=0,f=0,m=0;ma)&&(this.d[m]=this.H[m][m],this.e[m]=0);for(var g=Math.max(m-1,0);g=0;){for(var _=s;_>0&&(0===(d=Math.abs(this.H[_-1][_-1])+Math.abs(this.H[_][_]))&&(d=f),!(Math.abs(this.H[_][_-1])=0){for(p=c>=0?c+p:c-p,this.d[s-1]=n+p,this.d[s]=this.d[s-1],0!==p&&(this.d[s]=n-e/p),this.e[s-1]=0,this.e[s]=0,c=(n=this.H[s][s-1])/(d=Math.abs(n)+Math.abs(p)),u=p/d,c/=h=Math.sqrt(c*c+u*u),u/=h,g=s-1;g0){for(d=Math.sqrt(d),i=_&&(c=((h=n-(p=this.H[x][x]))*(d=i-p)-e)/this.H[x+1][x]+this.H[x][x+1],u=this.H[x+1][x+1]-p-h-d,h=this.H[x+2][x+1],c/=d=Math.abs(c)+Math.abs(u)+Math.abs(h),u/=d,h/=d,x!==_)&&!(Math.abs(this.H[x][x-1])*(Math.abs(u)+Math.abs(h))x+2&&(this.H[m][m-3]=0);for(var y=x;y<=s-1;y++){var b=y!==s-1;if(y!==x){if(c=this.H[y][y-1],u=this.H[y+1][y-1],h=b?this.H[y+2][y-1]:0,0===(n=Math.abs(c)+Math.abs(u)+Math.abs(h)))continue;c/=n,u/=n,h/=n}if(d=Math.sqrt(c*c+u*u+h*h),c<0&&(d=-d),0!==d){for(y!==x?this.H[y][y-1]=-d*n:_!==x&&(this.H[y][y-1]=-this.H[y][y-1]),n=(c+=d)/d,i=u/d,p=h/d,u/=c,h/=c,g=y;g=0;s--)if(c=this.d[s],0===(u=this.e[s]))for(_=s,this.H[s][s]=1,m=s-1;m>=0;m--){for(e=this.H[m][m]-c,h=0,g=_;g<=s;g++)h+=this.H[m][g]*this.H[g][s];if(this.e[m]<0)p=e,d=h;else if(_=m,0===this.e[m]?this.H[m][s]=0!==e?-h/e:-h/(o*f):(n=this.H[m][m+1],i=this.H[m+1][m],t=(n*d-p*h)/(u=(this.d[m]-c)*(this.d[m]-c)+this.e[m]*this.e[m]),this.H[m][s]=t,Math.abs(n)>Math.abs(p)?this.H[m+1][s]=(-h-e*t)/n:this.H[m+1][s]=(-d-i*t)/p),o*(t=Math.abs(this.H[m][s]))*t>1)for(g=m;g<=s;g++)this.H[g][s]=this.H[g][s]/t}else if(u<0)for(_=s-1,Math.abs(this.H[s][s-1])>Math.abs(this.H[s-1][s])?(this.H[s-1][s-1]=u/this.H[s][s-1],this.H[s-1][s]=-(this.H[s][s]-c)/this.H[s][s-1]):(this.cdiv(0,-this.H[s-1][s],this.H[s-1][s-1]-c,u),this.H[s-1][s-1]=this.cdivr,this.H[s-1][s]=this.cdivi),this.H[s][s-1]=0,this.H[s][s]=1,m=s-2;m>=0;m--){var w=0,M=0,S=0,E=0;for(w=0,M=0,g=_;g<=s;g++)w+=this.H[m][g]*this.H[g][s-1],M+=this.H[m][g]*this.H[g][s];if(e=this.H[m][m]-c,this.e[m]<0)p=e,h=w,d=M;else if(_=m,0===this.e[m]?(this.cdiv(-w,-M,e,u),this.H[m][s-1]=this.cdivr,this.H[m][s]=this.cdivi):(n=this.H[m][m+1],i=this.H[m+1][m],function(t,e){return t&&e}(0===(S=(this.d[m]-c)*(this.d[m]-c)+this.e[m]*this.e[m]-u*u),0==(E=2*(this.d[m]-c)*u))&&(S=o*f*(Math.abs(e)+Math.abs(u)+Math.abs(n)+Math.abs(i)+Math.abs(p))),this.cdiv(n*h-p*w+u*M,n*d-p*M-u*w,S,E),this.H[m][s-1]=this.cdivr,this.H[m][s]=this.cdivi,Math.abs(n)>Math.abs(p)+Math.abs(u)?(this.H[m+1][s-1]=(-w-e*this.H[m][s-1]+u*this.H[m][s])/n,this.H[m+1][s]=(-M-e*this.H[m][s]-u*this.H[m][s-1])/n):(this.cdiv(-h-i*this.H[m][s-1],-d-i*this.H[m][s],p,u),this.H[m+1][s-1]=this.cdivr,this.H[m+1][s]=this.cdivi)),o*(t=Math.max(Math.abs(this.H[m][s-1]),Math.abs(this.H[m][s])))*t>1)for(g=m;g<=s;g++)this.H[g][s-1]=this.H[g][s-1]/t,this.H[g][s]=this.H[g][s]/t}for(m=0;ma))for(g=m;g=0;g--)for(m=0;m<=a;m++){for(p=0,y=0;y<=Math.min(g,a);y++)p+=this.V[m][y]*this.H[y][g];this.V[m][g]=p}}}getV(){return this.V}getRealEigenvalues(){return this.d}getImagEigenvalues(){return this.e}getD(){for(var t=Ht(this.n,this.n),e=0;e0?t[e][e+1]=this.e[e]:this.e[e]<0&&(t[e][e-1]=this.e[e])}return t}}class Zt extends Error{constructor(t){super(t),this.name="PacioliError"}}const Kt=!1,Jt=P.ONE,Qt=(Math.pow(10,24),Math.pow(10,21),Math.pow(10,18),Math.pow(10,15),Math.pow(10,12),Math.pow(10,9),Math.pow(10,6),Math.pow(10,3),Math.pow(10,2),Math.pow(10,1),Math.pow(10,-1),Math.pow(10,-2),Math.pow(10,-3),Math.pow(10,-6),Math.pow(10,-9),Math.pow(10,-12),Math.pow(10,-15),Math.pow(10,-18),Math.pow(10,-21),Math.pow(10,-24),function(){return"javascript"}),te=function(...t){return Hi(t)},ee=function(t,e){return t.apply(t,e)};function ne(t){return t}function ie(t){return Gi([t])}function re(){return Gi(Array.from({length:1}))}function se(t,e){return t[0]=e,t}function ae(t){return t[0]}function oe(t){return new j(t)}function le(t){throw new Zt(t)}const ce=!1;function ue(t,e){if(ce)return t();try{return t()}catch(t){return e(t instanceof Error?t.message:String(t))}}function he(){return Bi}function de(t){return void 0===t.value}function pe(t){if(void 0===t.value)throw new Error("Cannot get empty Maybe value");return t.value}function fe(t){return!t}function me(){return X}function ge(t,e){return!ve(t,e)}function ve(t,e){if(t===e)return!0;if("string"==typeof t||"string"==typeof e)return t===e;if("boolean"==typeof t||"boolean"==typeof e)return t===e;if("function"==typeof t||"function"==typeof e)return t===e;if("coordinates"===t.kind&&"coordinates"===e.kind)return t.position===e.position;if("maybe"===t.kind&&"maybe"===e.kind)return void 0===t.value&&void 0===e.value||void 0!==t.value&&void 0!==e.value&&ve(t.value,e.value);if("matrix"===t.kind&&"matrix"===e.kind)return!Fi(t,e,function(t,e){return t!==e},!1);if(Array.isArray(t)&&Array.isArray(e)){const n=t.length;if(e.length!==n)return!1;for(let i=0;ir[t][2]&&(r[t]=[e,i,a])}}for(let t=0;tr[t][2]&&(t=e);at){const n=t;t=e,e=n}if(0===t)return e;if(0===e)return t;for(;;){if(0===(t%=e))return e;if(0===(e%=t))return t}})}function qe(t,e){return Kt&&"CCS"===t.storage?zi(I().ccsadd(F(t),F(e)),t.nrRows,e.nrColumns,"CCS"):ki(t,e,function(t,e){return t+e})}function Ye(t,e){return Kt&&"CCS"===t.storage?zi(I().ccssub(F(t),F(e)),t.nrRows,e.nrColumns,"CCS"):ki(t,e,function(t,e){return t-e})}function Ze(t){return Oi(t,function(t){return-t})}function Ke(t,e){const n=Ii(t,0,0);return Oi(e,function(t){return n*t})}function Je(t,e){const n=Ii(e,0,0);return Oi(t,function(t){return n*t})}function Qe(t,e){return Ke(ze(e),t)}function tn(t){const e=k(t)[2];let n=0;for(const t of e)n+=t;const i=At(1,1);return Di(i,0,0,n),i}function en(t,e){return ki(t,e,function(t,e){if(0===e)return t;{const n=t%e;return n<0?n+Math.abs(e):n}})}function nn(t,e){return ki(t,e,function(t,e){return 0===e?t:t-e*Math.round(t/e)})}function rn(t,e){return ki(t,e,function(t,e){return 0===e?t:t%e})}function sn(t,e){return ki(t,e,function(t,e){return 0===e?0:Math.trunc(t/e)})}function an(t,e){return zi(I().max(O(t),O(e)),t.nrRows,t.nrColumns,"full")}function on(t,e){return zi(I().min(O(t),O(e)),t.nrRows,t.nrColumns,"full")}function ln(t){return zi(I().sin(O(t)),t.nrRows,t.nrColumns,"full")}function cn(t){return zi(I().cos(O(t)),t.nrRows,t.nrColumns,"full")}function un(t){return zi(I().tan(O(t)),t.nrRows,t.nrColumns,"full")}function hn(t){return zi(I().asin(O(t)),t.nrRows,t.nrColumns,"full")}function dn(t){return zi(I().acos(O(t)),t.nrRows,t.nrColumns,"full")}function pn(t){return zi(I().atan(O(t)),t.nrRows,t.nrColumns,"full")}function fn(t,e){return zi(I().atan2(O(t),O(e)),t.nrRows,t.nrColumns,"full")}function mn(t){return Oi(t,function(t){return Math.floor(t)})}function gn(t){return Oi(t,function(t){return Math.ceil(t)})}function vn(t){return Oi(t,function(t){return Math.trunc(t)})}function _n(t){return Oi(t,function(t){return Math.round(t)})}function xn(t){return Oi(t,function(t){return Math.abs(t)})}function yn(t,e){const n=Ii(e,0,0);if(0===n)return Fe(t);if(1===n)return t;if(n<0)return yn(zi(I().inv(O(t)),t.nrColumns,t.nrRows,"full"),Ze(e));{let e=t;for(let i=1;i=e},!0)}function Tn(t,e){return!Fi(t,e,function(t,e){return t>e},!1)}function An(t,e){return!Fi(t,e,function(t,e){return t<=e},!0)}function Cn(t,e){return!Fi(t,e,function(t,e){return tr&&(s=qe(s,Ke(o,We(a,Ve(i)))))}const a=We(s,e);if(a.nrColumns!==e.nrColumns)throw new Error("Incorrect matrix shape issue in solve");if(a.nrRows!==t.nrColumns)throw new Error("Incorrect matrix shape issue in solve");return a}const On=!0;function kn(t){const e=t.nrRowse[2]?1:t[2]ve(t,e))}function ii(){return Vi([])}function ri(t,...e){if("string"!=typeof t)throw new Error(`Illegal format string. The first argument to format must be a string. Found: \n\n${Wi(t)}`);const n=t;let i="",r=0;const s=n.length;let a=0;for(;a0){let t;try{t=""===s[1]?null:Number.parseInt(s[1])}catch(e){t=null}const n=e[r++];if("object"!=typeof n||"matrix"!==n.kind)throw new Error("Expected matrix for %d format argument");const o=Ii(n,0,0).toFixed(0);i+=null===t?o:o.padStart(t," "),a+=s[0].length}else{const s=/^%([0-9]*)([.]?)([0-9]*)f/.exec(n.slice(a));if(null!==s&&s[0].length>0){let t,n;try{t=""===s[3]?si:Number.parseInt(s[3])}catch(e){t=si}try{n=""===s[1]?null:Number.parseInt(s[1])}catch(t){n=null}const o=e[r++];if("object"!=typeof o||"matrix"!==o.kind)throw new Error("Expected matrix for %d format argument");if(1===o.nrRows&&1===o.nrColumns){const e=Ii(o,0,0).toFixed(t);i+=null===n?e:e.padStart(n," ")}else i+=ji(o);a+=s[0].length}else i+=t,a++}}}}else i+=t,a++}return i}let si=2,ai=14;function oi(){return Pt(1,1,[[0,0,si]])}function li(t){return si=Ii(t,0,0),X}function ci(){return Pt(1,1,[[0,0,ai]])}function ui(t){return ai=Ii(t,0,0),X}function hi(t){const e=t.shape;if(void 0===e)throw new Error("shape undefined in unit2string");const n=e.rowOrder(),i=e.columnOrder();if(0===n&&0===i)return e.unitAt(0,0).toText();throw new Zt("unit2string is only implemented for scalars, not for vectors and matrices")}function di(t,e,n){const i=n.shape;if(void 0===i)throw new Error("shape undefined");return new $i(i,t).toDecimal(Ii(e,0,0))}function pi(t,e){return Pt(1,1,[[0,0,t.localeCompare(e)]])}function fi(t,e){return t+e}function mi(t,e){return Vi(t.split(e))}function gi(t,e){const n=t.length;if(0===n)throw new Error("char_at called on empty string");const i=Ii(e,0,0)%n;return t.charAt(i<0?i+n:i)}function vi(t){return Pt(1,1,[[0,0,t.length]])}function _i(t,e,n,i){return t+e.padStart(Math.max(0,Ii(n,0,0)-t.length),i)}function xi(t){return t.trim()}function yi(t){return Pt(1,1,[[0,0,Number(t)]])}function bi(){return Pt(1,1,[[0,0,Date.now()]])}function wi(t){return function(t){return t.kind="array",t}(Array.from({length:Ii(t,0,0)}))}function Mi(t,e){return t[Ii(e,0,0)]}function Si(t,e,n){return t[Ii(e,0,0)]=n,X}function Ei(t){return Pt(1,1,[[0,0,t.length]])}function Ti(){return new Xi}function Ai(t,e){return e.lookup(t)}function Ci(t,e,n){return n.store(t,e)}function Ri(t){return t.keys()}function Pi(t,e){return t.magnitude.isZero()&&void 0!==e.zeroString?e.zeroString:e.exponential?e.omitDecimals?t.magnitude.toExponential():t.magnitude.toExponential(e.nrDecimals):e.omitDecimals?t.magnitude.toFixed():t.magnitude.toFixed(e.nrDecimals)}const Ni={decimals:si,raw:!1,exponential:!1,nozerorows:!1,totals:!1,ascii:!1,clipboard:!1};class Li{constructor(t,e={}){this.columns=t,this.options=e}isSingleScalar(){return 1===this.columns.length&&0===this.columns[0].indexHeaders.length}singuleScalar(){return this.columns[0].values[0].num}stringifiedSinguleScalar(){var t,e,n,i;return null!==(e=null===(t=this.options)||void 0===t?void 0:t.raw)&&void 0!==e&&e?this.singuleScalar().toFixed():this.singuleScalar().toFixed(null!==(i=null===(n=this.options)||void 0===n?void 0:n.decimals)&&void 0!==i?i:si)}indexHeaders(){return 0===this.columns.length?[]:this.columns[0].indexHeaders}valueHeaders(){return this.columns.map(t=>t.header)}cellOptions(t){var e,n;return{zeroString:this.options.zero,omitDecimals:!0===t.options.raw||!0===this.options.raw||Ni.raw,nrDecimals:null!==(n=null!==(e=t.options.decimals)&&void 0!==e?e:this.options.decimals)&&void 0!==n?n:Ni.decimals,exponential:!0===t.options.exponential||!0===this.options.exponential||Ni.exponential}}rows(){if(0===this.columns.length)return[];const t=this.columns[0].index,e=[];for(const[n,i]of t.entries()){const t={index:i,values:this.columns.map(t=>{let e=t.values[n].num;const i=t.options.unit;return void 0!==i&&(e=St.unitContext.convertDimNum(e,i)),{num:e,magnitude:Pi(e,this.cellOptions(t)),unit:e.unit.toText()}})};e.push(t)}return e}totals(){return this.columns.map(t=>{if(!0!==this.options.totals&&!0!==t.options.showTotal)return;const e=t.total();return void 0!==e?{num:e,magnitude:Pi(e,this.cellOptions(t)),unit:e.unit.toText()}:void 0})}dom(){if(!0===this.options.ascii){const t=document.createElement("pre");return t.innerText=this.ascii(),t}if(!0===this.options.clipboard){const t=document.createElement("pre");return t.innerText=this.clipboardText(),t}return function(t){if(t.isSingleScalar()){const e=document.createElement("span");return e.textContent=t.stringifiedSinguleScalar(),e}const e=document.createElement("table");e.part="table";const n=document.createElement("thead"),i=document.createElement("tbody");e.appendChild(n),e.appendChild(i);const r=document.createElement("tr");r.part="header row";for(const e of t.indexHeaders()){const t=document.createElement("th");t.className="key",t.part="header key",t.innerHTML=e,r.appendChild(t)}for(const e of t.valueHeaders()){const t=document.createElement("th");t.innerHTML=e,t.className="value",t.part="header value",t.colSpan=2,r.appendChild(t)}n.appendChild(r);for(const e of t.rows()){const t=document.createElement("tr");t.part="body row";for(const n of e.index){const e=document.createElement("td");e.className="key",e.part="body key",e.innerHTML=n,t.appendChild(e)}for(const n of e.values){const e=document.createElement("td"),i=document.createElement("td");e.className="value",e.part="body value",e.innerHTML=n.magnitude,i.className="unit",i.part="body unit",i.innerHTML=n.unit,t.appendChild(e),t.appendChild(i)}i.appendChild(t)}const s=t.indexHeaders().length;if(t.totals().some(t=>void 0!==t)&&s>0){const e=document.createElement("tr");e.part="total row";const n=document.createElement("td");n.className="total key",n.part="total title",n.innerHTML="Total",e.appendChild(n);for(let t=1;te(t))],t.nrRows,t.nrColumns,"COO")}function ki(t,e,n){let i=0,r=0;const s=k(t),a=k(e),o=s[0],l=s[1],c=s[2],u=a[0],h=a[1],d=a[2],p=o.length,f=u.length,m=[],g=[],v=[],_=function(t,e,i,r){const s=n(i,r);"number"==typeof s&&0!==s&&(m.push(t),g.push(e),v.push(s))};for(;ie?(_(e,s,0,d[r]),r++):ts?(_(e,s,0,d[r]),r++):(_(t,s,c[i],d[r]),i++,r++)}for(;ie){if(n(0,p[s]))return!0;s++}else if(ta){if(n(0,p[s]))return!0;s++}else{if(n(u[r],p[s]))return!0;r++,s++}g++}for(;rji(t)).join(", ")}]`;case"tuple":return`(${t.map(t=>ji(t)).join(", ")})`;case"array":return`{${t.map(t=>ji(t)).join(", ")}}`;case"ref":return`<${t.map(t=>ji(t)).join(", ")}>`;case"coordinates":return`${t.size.toString()}@${t.position.toString()}`;case"map":{const e=[];for(const n of t.keyMap.keys()){const i=t.keyMap.get(n),r=t.valueMap.get(n);void 0!==i&&void 0!==r&&e.push(`${ji(i)}->${ji(r)}`)}return`<${e.join(", ")}>`}case"void":return"Void";case"maybe":return void 0===t.value?"Nothing":`just<${ji(t.value)}>`}}class Xi{constructor(){this.kind="map",this.valueMap=new Map,this.keyMap=new Map}store(t,e){const n=ji(t);return this.valueMap.set(n,e),this.keyMap.set(n,t),X}lookup(t){const e=ji(t);return this.keyMap.has(e)?new j(this.valueMap.get(e)):new j}keys(){const t=[];for(const e of this.keyMap.values())t.push(e);return Vi(t)}}class $i{constructor(t,e){this.shape=t,this.numbers=e,this.kind="matrix"}filter(t){return new $i(this.shape,function(t,e){const n=t.nrRows,i=t.nrColumns,r=k(t),s=r[0],a=r[1],o=r[2],l=[],c=[],u=[];for(const[t,r]of s.entries()){const s={kind:"coordinates",position:r,size:n},h={kind:"coordinates",position:a[t],size:i};e(o[t],s,h)&&(l.push(r),c.push(a[t]),u.push(o[t]))}return zi([l,c,u],n,i,"COO")}(this.numbers,t))}getDimNum(t,e){return b.fromNumber(this.getNum(t,e),this.getUnit(t,e))}getNum(t,e){return Ii(this.numbers,t,e)}getUnit(t,e){return this.shape.unitAt(t,e)}convertUnit(t,e){const n=G.scalar(t);return new $i(this.shape.dimensionless().scale(n),function(t,e,n,i){const r=t.nrRows,s=t.nrColumns,a=k(t),o=a[0],l=a[1],c=a[2],u=[];for(const[t,r]of o.entries()){const s=i.conversionFactor(e.unitAt(r,l[t]),n);u.push(c[t]*s.toNumber())}return zi([o,l,u],r,s,"COO")}(this.numbers,this.shape,t,e))}rowIndexSets(){return this.shape.rowDimension.indexSets}columnIndexSets(){return this.shape.columnDimension.indexSets}keyValueList(t=!1){return function(t,e=!1){const n=[];if(e){const e=O(t.numbers);for(let i=0;iIt("",t,e),(t,n)=>It(t,n,e)).unit}function lr(t,e=St){return E(t,t=>It("",t,e),(t,n)=>It(t,n,e))}function cr(t){return new ot(...t)}let ur=0;function hr(t){if(0===t.length)throw new Error("Cannot make empty list (yet)");const e=t.map(function(t){return t});return 0===e.length?new lt(new rt("List",[sr(`_xyzzy${(ur++).toString()}_`)])):new lt(new rt("List",[vt(t[0])]),...e)}const dr="181",pr=0,fr=1,mr=2,gr=100,vr=101,_r=102,xr=200,yr=201,br=202,wr=203,Mr=204,Sr=205,Er=206,Tr=207,Ar=208,Cr=209,Rr=210,Pr=211,Nr=212,Lr=213,Ur=214,Dr=0,Ir=1,Or=2,kr=3,Fr=4,Br=5,zr=6,Vr=7,Hr=301,Gr=302,Wr=306,jr=1e3,Xr=1001,$r=1002,qr=1003,Yr=1004,Zr=1005,Kr=1006,Jr=1007,Qr=1008,ts=1009,es=1012,ns=1013,is=1014,rs=1015,ss=1016,as=1017,os=1018,ls=1020,cs=1023,us=1026,hs=1027,ds=1029,ps=1030,fs=1031,ms=1033,gs=33776,vs=33777,_s=33778,xs=33779,ys=35840,bs=35841,ws=35842,Ms=35843,Ss=36196,Es=37492,Ts=37496,As=37808,Cs=37809,Rs=37810,Ps=37811,Ns=37812,Ls=37813,Us=37814,Ds=37815,Is=37816,Os=37817,ks=37818,Fs=37819,Bs=37820,zs=37821,Vs=36492,Hs=36494,Gs=36495,Ws=36283,js=36284,Xs=36285,$s=36286,qs=2300,Ys=2301,Zs=2302,Ks="",Js="srgb",Qs="srgb-linear",ta="linear",ea="srgb",na=7680,ia=512,ra=513,sa=514,aa=515,oa=516,la=517,ca=518,ua=519,ha="300 es",da=2e3,pa=2001;function fa(t){for(let e=t.length-1;e>=0;--e)if(t[e]>=65535)return!0;return!1}function ma(t){return document.createElementNS("http://www.w3.org/1999/xhtml",t)}function ga(){const t=ma("canvas");return t.style.display="block",t}Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array;const va={};function _a(...t){const e="THREE."+t.shift();console.log(e,...t)}function xa(...t){const e="THREE."+t.shift();console.warn(e,...t)}function ya(...t){const e="THREE."+t.shift();console.error(e,...t)}function ba(...t){const e=t.join(" ");e in va||(va[e]=!0,xa(...t))}class wa{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const n=this._listeners;void 0===n[t]&&(n[t]=[]),-1===n[t].indexOf(e)&&n[t].push(e)}hasEventListener(t,e){const n=this._listeners;return void 0!==n&&void 0!==n[t]&&-1!==n[t].indexOf(e)}removeEventListener(t,e){const n=this._listeners;if(void 0===n)return;const i=n[t];if(void 0!==i){const t=i.indexOf(e);-1!==t&&i.splice(t,1)}}dispatchEvent(t){const e=this._listeners;if(void 0===e)return;const n=e[t.type];if(void 0!==n){t.target=this;const e=n.slice(0);for(let n=0,i=e.length;n>8&255]+Ma[t>>16&255]+Ma[t>>24&255]+"-"+Ma[255&e]+Ma[e>>8&255]+"-"+Ma[e>>16&15|64]+Ma[e>>24&255]+"-"+Ma[63&n|128]+Ma[n>>8&255]+"-"+Ma[n>>16&255]+Ma[n>>24&255]+Ma[255&i]+Ma[i>>8&255]+Ma[i>>16&255]+Ma[i>>24&255]).toLowerCase()}function Aa(t,e,n){return Math.max(e,Math.min(n,t))}function Ca(t,e,n){return(1-n)*t+n*e}function Ra(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function Pa(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const Na=Sa;class La{constructor(t=0,e=0){La.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Aa(this.x,t.x,e.x),this.y=Aa(this.y,t.y,e.y),this}clampScalar(t,e){return this.x=Aa(this.x,t,e),this.y=Aa(this.y,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Aa(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(Aa(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const n=Math.cos(e),i=Math.sin(e),r=this.x-t.x,s=this.y-t.y;return this.x=r*n-s*i+t.x,this.y=r*i+s*n+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Ua{constructor(t=0,e=0,n=0,i=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=n,this._w=i}static slerpFlat(t,e,n,i,r,s,a){let o=n[i+0],l=n[i+1],c=n[i+2],u=n[i+3],h=r[s+0],d=r[s+1],p=r[s+2],f=r[s+3];if(a<=0)return t[e+0]=o,t[e+1]=l,t[e+2]=c,void(t[e+3]=u);if(a>=1)return t[e+0]=h,t[e+1]=d,t[e+2]=p,void(t[e+3]=f);if(u!==f||o!==h||l!==d||c!==p){let t=o*h+l*d+c*p+u*f;t<0&&(h=-h,d=-d,p=-p,f=-f,t=-t);let e=1-a;if(t<.9995){const n=Math.acos(t),i=Math.sin(n);e=Math.sin(e*n)/i,o=o*e+h*(a=Math.sin(a*n)/i),l=l*e+d*a,c=c*e+p*a,u=u*e+f*a}else{o=o*e+h*a,l=l*e+d*a,c=c*e+p*a,u=u*e+f*a;const t=1/Math.sqrt(o*o+l*l+c*c+u*u);o*=t,l*=t,c*=t,u*=t}}t[e]=o,t[e+1]=l,t[e+2]=c,t[e+3]=u}static multiplyQuaternionsFlat(t,e,n,i,r,s){const a=n[i],o=n[i+1],l=n[i+2],c=n[i+3],u=r[s],h=r[s+1],d=r[s+2],p=r[s+3];return t[e]=a*p+c*u+o*d-l*h,t[e+1]=o*p+c*h+l*u-a*d,t[e+2]=l*p+c*d+a*h-o*u,t[e+3]=c*p-a*u-o*h-l*d,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,n,i){return this._x=t,this._y=e,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e=!0){const n=t._x,i=t._y,r=t._z,s=t._order,a=Math.cos,o=Math.sin,l=a(n/2),c=a(i/2),u=a(r/2),h=o(n/2),d=o(i/2),p=o(r/2);switch(s){case"XYZ":this._x=h*c*u+l*d*p,this._y=l*d*u-h*c*p,this._z=l*c*p+h*d*u,this._w=l*c*u-h*d*p;break;case"YXZ":this._x=h*c*u+l*d*p,this._y=l*d*u-h*c*p,this._z=l*c*p-h*d*u,this._w=l*c*u+h*d*p;break;case"ZXY":this._x=h*c*u-l*d*p,this._y=l*d*u+h*c*p,this._z=l*c*p+h*d*u,this._w=l*c*u-h*d*p;break;case"ZYX":this._x=h*c*u-l*d*p,this._y=l*d*u+h*c*p,this._z=l*c*p-h*d*u,this._w=l*c*u+h*d*p;break;case"YZX":this._x=h*c*u+l*d*p,this._y=l*d*u+h*c*p,this._z=l*c*p-h*d*u,this._w=l*c*u-h*d*p;break;case"XZY":this._x=h*c*u-l*d*p,this._y=l*d*u-h*c*p,this._z=l*c*p+h*d*u,this._w=l*c*u+h*d*p;break;default:xa("Quaternion: .setFromEuler() encountered an unknown order: "+s)}return!0===e&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const n=e/2,i=Math.sin(n);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,n=e[0],i=e[4],r=e[8],s=e[1],a=e[5],o=e[9],l=e[2],c=e[6],u=e[10],h=n+a+u;if(h>0){const t=.5/Math.sqrt(h+1);this._w=.25/t,this._x=(c-o)*t,this._y=(r-l)*t,this._z=(s-i)*t}else if(n>a&&n>u){const t=2*Math.sqrt(1+n-a-u);this._w=(c-o)/t,this._x=.25*t,this._y=(i+s)/t,this._z=(r+l)/t}else if(a>u){const t=2*Math.sqrt(1+a-n-u);this._w=(r-l)/t,this._x=(i+s)/t,this._y=.25*t,this._z=(o+c)/t}else{const t=2*Math.sqrt(1+u-n-a);this._w=(s-i)/t,this._x=(r+l)/t,this._y=(o+c)/t,this._z=.25*t}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let n=t.dot(e)+1;return n<1e-8?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(Aa(this.dot(t),-1,1)))}rotateTowards(t,e){const n=this.angleTo(t);if(0===n)return this;const i=Math.min(1,e/n);return this.slerp(t,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const n=t._x,i=t._y,r=t._z,s=t._w,a=e._x,o=e._y,l=e._z,c=e._w;return this._x=n*c+s*a+i*l-r*o,this._y=i*c+s*o+r*a-n*l,this._z=r*c+s*l+n*o-i*a,this._w=s*c-n*a-i*o-r*l,this._onChangeCallback(),this}slerp(t,e){if(e<=0)return this;if(e>=1)return this.copy(t);let n=t._x,i=t._y,r=t._z,s=t._w,a=this.dot(t);a<0&&(n=-n,i=-i,r=-r,s=-s,a=-a);let o=1-e;if(a<.9995){const t=Math.acos(a),l=Math.sin(t);o=Math.sin(o*t)/l,e=Math.sin(e*t)/l,this._x=this._x*o+n*e,this._y=this._y*o+i*e,this._z=this._z*o+r*e,this._w=this._w*o+s*e,this._onChangeCallback()}else this._x=this._x*o+n*e,this._y=this._y*o+i*e,this._z=this._z*o+r*e,this._w=this._w*o+s*e,this.normalize();return this}slerpQuaternions(t,e,n){return this.copy(t).slerp(e,n)}random(){const t=2*Math.PI*Math.random(),e=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),r=Math.sqrt(n);return this.set(i*Math.sin(t),i*Math.cos(t),r*Math.sin(e),r*Math.cos(e))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class Da{constructor(t=0,e=0,n=0){Da.prototype.isVector3=!0,this.x=t,this.y=e,this.z=n}set(t,e,n){return void 0===n&&(n=this.z),this.x=t,this.y=e,this.z=n,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(Oa.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(Oa.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*i,this.y=r[1]*e+r[4]*n+r[7]*i,this.z=r[2]*e+r[5]*n+r[8]*i,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,r=t.elements,s=1/(r[3]*e+r[7]*n+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*n+r[8]*i+r[12])*s,this.y=(r[1]*e+r[5]*n+r[9]*i+r[13])*s,this.z=(r[2]*e+r[6]*n+r[10]*i+r[14])*s,this}applyQuaternion(t){const e=this.x,n=this.y,i=this.z,r=t.x,s=t.y,a=t.z,o=t.w,l=2*(s*i-a*n),c=2*(a*e-r*i),u=2*(r*n-s*e);return this.x=e+o*l+s*u-a*c,this.y=n+o*c+a*l-r*u,this.z=i+o*u+r*c-s*l,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i,this.y=r[1]*e+r[5]*n+r[9]*i,this.z=r[2]*e+r[6]*n+r[10]*i,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Aa(this.x,t.x,e.x),this.y=Aa(this.y,t.y,e.y),this.z=Aa(this.z,t.z,e.z),this}clampScalar(t,e){return this.x=Aa(this.x,t,e),this.y=Aa(this.y,t,e),this.z=Aa(this.z,t,e),this}clampLength(t,e){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Aa(n,t,e))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const n=t.x,i=t.y,r=t.z,s=e.x,a=e.y,o=e.z;return this.x=i*o-r*a,this.y=r*s-n*o,this.z=n*a-i*s,this}projectOnVector(t){const e=t.lengthSq();if(0===e)return this.set(0,0,0);const n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)}projectOnPlane(t){return Ia.copy(this).projectOnVector(t),this.sub(Ia)}reflect(t){return this.sub(Ia.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;const n=this.dot(t)/e;return Math.acos(Aa(n,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,n){const i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=i,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,4*e)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,3*e)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=Math.random()*Math.PI*2,e=2*Math.random()-1,n=Math.sqrt(1-e*e);return this.x=n*Math.cos(t),this.y=e,this.z=n*Math.sin(t),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Ia=new Da,Oa=new Ua;class ka{constructor(t,e,n,i,r,s,a,o,l){ka.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],void 0!==t&&this.set(t,e,n,i,r,s,a,o,l)}set(t,e,n,i,r,s,a,o,l){const c=this.elements;return c[0]=t,c[1]=i,c[2]=a,c[3]=e,c[4]=r,c[5]=o,c[6]=n,c[7]=s,c[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}extractBasis(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(t){const e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,r=this.elements,s=n[0],a=n[3],o=n[6],l=n[1],c=n[4],u=n[7],h=n[2],d=n[5],p=n[8],f=i[0],m=i[3],g=i[6],v=i[1],_=i[4],x=i[7],y=i[2],b=i[5],w=i[8];return r[0]=s*f+a*v+o*y,r[3]=s*m+a*_+o*b,r[6]=s*g+a*x+o*w,r[1]=l*f+c*v+u*y,r[4]=l*m+c*_+u*b,r[7]=l*g+c*x+u*w,r[2]=h*f+d*v+p*y,r[5]=h*m+d*_+p*b,r[8]=h*g+d*x+p*w,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],l=t[7],c=t[8];return e*s*c-e*a*l-n*r*c+n*a*o+i*r*l-i*s*o}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],l=t[7],c=t[8],u=c*s-a*l,h=a*o-c*r,d=l*r-s*o,p=e*u+n*h+i*d;if(0===p)return this.set(0,0,0,0,0,0,0,0,0);const f=1/p;return t[0]=u*f,t[1]=(i*l-c*n)*f,t[2]=(a*n-i*s)*f,t[3]=h*f,t[4]=(c*e-i*o)*f,t[5]=(i*r-a*e)*f,t[6]=d*f,t[7]=(n*o-l*e)*f,t[8]=(s*e-n*r)*f,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}getNormalMatrix(t){return this.setFromMatrix4(t).invert().transpose()}transposeIntoArray(t){const e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this}setUvTransform(t,e,n,i,r,s,a){const o=Math.cos(r),l=Math.sin(r);return this.set(n*o,n*l,-n*(o*s+l*a)+s+t,-i*l,i*o,-i*(-l*s+o*a)+a+e,0,0,1),this}scale(t,e){return this.premultiply(Fa.makeScale(t,e)),this}rotate(t){return this.premultiply(Fa.makeRotation(-t)),this}translate(t,e){return this.premultiply(Fa.makeTranslation(t,e)),this}makeTranslation(t,e){return t.isVector2?this.set(1,0,t.x,0,1,t.y,0,0,1):this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}equals(t){const e=this.elements,n=t.elements;for(let t=0;t<9;t++)if(e[t]!==n[t])return!1;return!0}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}clone(){return(new this.constructor).fromArray(this.elements)}}const Fa=new ka,Ba=(new ka).set(.4123908,.3575843,.1804808,.212639,.7151687,.0721923,.0193308,.1191948,.9505322),za=(new ka).set(3.2409699,-1.5373832,-.4986108,-.9692436,1.8759675,.0415551,.0556301,-.203977,1.0569715);function Va(){const t={enabled:!0,workingColorSpace:Qs,spaces:{},convert:function(t,e,n){return!1!==this.enabled&&e!==n&&e&&n?(this.spaces[e].transfer===ea&&(t.r=Ga(t.r),t.g=Ga(t.g),t.b=Ga(t.b)),this.spaces[e].primaries!==this.spaces[n].primaries&&(t.applyMatrix3(this.spaces[e].toXYZ),t.applyMatrix3(this.spaces[n].fromXYZ)),this.spaces[n].transfer===ea&&(t.r=Wa(t.r),t.g=Wa(t.g),t.b=Wa(t.b)),t):t},workingToColorSpace:function(t,e){return this.convert(t,this.workingColorSpace,e)},colorSpaceToWorking:function(t,e){return this.convert(t,e,this.workingColorSpace)},getPrimaries:function(t){return this.spaces[t].primaries},getTransfer:function(t){return t===Ks?ta:this.spaces[t].transfer},getToneMappingMode:function(t){return this.spaces[t].outputColorSpaceConfig.toneMappingMode||"standard"},getLuminanceCoefficients:function(t,e=this.workingColorSpace){return t.fromArray(this.spaces[e].luminanceCoefficients)},define:function(t){Object.assign(this.spaces,t)},_getMatrix:function(t,e,n){return t.copy(this.spaces[e].toXYZ).multiply(this.spaces[n].fromXYZ)},_getDrawingBufferColorSpace:function(t){return this.spaces[t].outputColorSpaceConfig.drawingBufferColorSpace},_getUnpackColorSpace:function(t=this.workingColorSpace){return this.spaces[t].workingColorSpaceConfig.unpackColorSpace},fromWorkingColorSpace:function(e,n){return ba("ColorManagement: .fromWorkingColorSpace() has been renamed to .workingToColorSpace()."),t.workingToColorSpace(e,n)},toWorkingColorSpace:function(e,n){return ba("ColorManagement: .toWorkingColorSpace() has been renamed to .colorSpaceToWorking()."),t.colorSpaceToWorking(e,n)}},e=[.64,.33,.3,.6,.15,.06],n=[.2126,.7152,.0722],i=[.3127,.329];return t.define({[Qs]:{primaries:e,whitePoint:i,transfer:ta,toXYZ:Ba,fromXYZ:za,luminanceCoefficients:n,workingColorSpaceConfig:{unpackColorSpace:Js},outputColorSpaceConfig:{drawingBufferColorSpace:Js}},[Js]:{primaries:e,whitePoint:i,transfer:ea,toXYZ:Ba,fromXYZ:za,luminanceCoefficients:n,outputColorSpaceConfig:{drawingBufferColorSpace:Js}}}),t}const Ha=Va();function Ga(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function Wa(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}let ja;class Xa{static getDataURL(t,e="image/png"){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;let n;if(t instanceof HTMLCanvasElement)n=t;else{void 0===ja&&(ja=ma("canvas")),ja.width=t.width,ja.height=t.height;const e=ja.getContext("2d");t instanceof ImageData?e.putImageData(t,0,0):e.drawImage(t,0,0,t.width,t.height),n=ja}return n.toDataURL(e)}static sRGBToLinear(t){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){const e=ma("canvas");e.width=t.width,e.height=t.height;const n=e.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const i=n.getImageData(0,0,t.width,t.height),r=i.data;for(let t=0;t1),this.pmremVersion=0}get width(){return this.source.getSize(Ka).x}get height(){return this.source.getSize(Ka).y}get depth(){return this.source.getSize(Ka).z}get image(){return this.source.data}set image(t=null){this.source.data=t}updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}clone(){return(new this.constructor).copy(this)}copy(t){return this.name=t.name,this.source=t.source,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.channel=t.channel,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.colorSpace=t.colorSpace,this.renderTarget=t.renderTarget,this.isRenderTargetTexture=t.isRenderTargetTexture,this.isArrayTexture=t.isArrayTexture,this.userData=JSON.parse(JSON.stringify(t.userData)),this.needsUpdate=!0,this}setValues(t){for(const e in t){const n=t[e];if(void 0===n){xa(`Texture.setValues(): parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&n&&i.isVector2&&n.isVector2||i&&n&&i.isVector3&&n.isVector3||i&&n&&i.isMatrix3&&n.isMatrix3?i.copy(n):this[e]=n:xa(`Texture.setValues(): property '${e}' does not exist.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.textures[this.uuid])return t.textures[this.uuid];const n={metadata:{version:4.7,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,image:this.source.toJSON(t).uuid,mapping:this.mapping,channel:this.channel,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,internalFormat:this.internalFormat,type:this.type,colorSpace:this.colorSpace,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,generateMipmaps:this.generateMipmaps,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};return Object.keys(this.userData).length>0&&(n.userData=this.userData),e||(t.textures[this.uuid]=n),n}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(t){if(300!==this.mapping)return t;if(t.applyMatrix3(this.matrix),t.x<0||t.x>1)switch(this.wrapS){case jr:t.x=t.x-Math.floor(t.x);break;case Xr:t.x=t.x<0?0:1;break;case $r:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case jr:t.y=t.y-Math.floor(t.y);break;case Xr:t.y=t.y<0?0:1;break;case $r:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}set needsUpdate(t){!0===t&&(this.version++,this.source.needsUpdate=!0)}set needsPMREMUpdate(t){!0===t&&this.pmremVersion++}}Ja.DEFAULT_IMAGE=null,Ja.DEFAULT_MAPPING=300,Ja.DEFAULT_ANISOTROPY=1;class Qa{constructor(t=0,e=0,n=0,i=1){Qa.prototype.isVector4=!0,this.x=t,this.y=e,this.z=n,this.w=i}get width(){return this.z}set width(t){this.z=t}get height(){return this.w}set height(t){this.w=t}set(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.w=i,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this.w=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setW(t){return this.w=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this.w*=t.w,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this}applyMatrix4(t){const e=this.x,n=this.y,i=this.z,r=this.w,s=t.elements;return this.x=s[0]*e+s[4]*n+s[8]*i+s[12]*r,this.y=s[1]*e+s[5]*n+s[9]*i+s[13]*r,this.z=s[2]*e+s[6]*n+s[10]*i+s[14]*r,this.w=s[3]*e+s[7]*n+s[11]*i+s[15]*r,this}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this.w/=t.w,this}divideScalar(t){return this.multiplyScalar(1/t)}setAxisAngleFromQuaternion(t){this.w=2*Math.acos(t.w);const e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this}setAxisAngleFromRotationMatrix(t){let e,n,i,r;const s=.01,a=.1,o=t.elements,l=o[0],c=o[4],u=o[8],h=o[1],d=o[5],p=o[9],f=o[2],m=o[6],g=o[10];if(Math.abs(c-h)o&&t>v?tv?o1);this.dispose()}this.viewport.set(0,0,t,e),this.scissor.set(0,0,t,e)}clone(){return(new this.constructor).copy(this)}copy(t){this.width=t.width,this.height=t.height,this.depth=t.depth,this.scissor.copy(t.scissor),this.scissorTest=t.scissorTest,this.viewport.copy(t.viewport),this.textures.length=0;for(let e=0,n=t.textures.length;e=this.min.x&&t.x<=this.max.x&&t.y>=this.min.y&&t.y<=this.max.y&&t.z>=this.min.z&&t.z<=this.max.z}containsBox(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z}getParameter(t,e){return e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(t){return t.max.x>=this.min.x&&t.min.x<=this.max.x&&t.max.y>=this.min.y&&t.min.y<=this.max.y&&t.max.z>=this.min.z&&t.min.z<=this.max.z}intersectsSphere(t){return this.clampPoint(t.center,ao),ao.distanceToSquared(t.center)<=t.radius*t.radius}intersectsPlane(t){let e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}intersectsTriangle(t){if(this.isEmpty())return!1;this.getCenter(mo),go.subVectors(this.max,mo),lo.subVectors(t.a,mo),co.subVectors(t.b,mo),uo.subVectors(t.c,mo),ho.subVectors(co,lo),po.subVectors(uo,co),fo.subVectors(lo,uo);let e=[0,-ho.z,ho.y,0,-po.z,po.y,0,-fo.z,fo.y,ho.z,0,-ho.x,po.z,0,-po.x,fo.z,0,-fo.x,-ho.y,ho.x,0,-po.y,po.x,0,-fo.y,fo.x,0];return!!xo(e,lo,co,uo,go)&&(e=[1,0,0,0,1,0,0,0,1],!!xo(e,lo,co,uo,go)&&(vo.crossVectors(ho,po),e=[vo.x,vo.y,vo.z],xo(e,lo,co,uo,go)))}clampPoint(t,e){return e.copy(t).clamp(this.min,this.max)}distanceToPoint(t){return this.clampPoint(t,ao).distanceTo(t)}getBoundingSphere(t){return this.isEmpty()?t.makeEmpty():(this.getCenter(t.center),t.radius=.5*this.getSize(ao).length()),t}intersect(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}union(t){return this.min.min(t.min),this.max.max(t.max),this}applyMatrix4(t){return this.isEmpty()||(so[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),so[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),so[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),so[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),so[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),so[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),so[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),so[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(so)),this}translate(t){return this.min.add(t),this.max.add(t),this}equals(t){return t.min.equals(this.min)&&t.max.equals(this.max)}toJSON(){return{min:this.min.toArray(),max:this.max.toArray()}}fromJSON(t){return this.min.fromArray(t.min),this.max.fromArray(t.max),this}}const so=[new Da,new Da,new Da,new Da,new Da,new Da,new Da,new Da],ao=new Da,oo=new ro,lo=new Da,co=new Da,uo=new Da,ho=new Da,po=new Da,fo=new Da,mo=new Da,go=new Da,vo=new Da,_o=new Da;function xo(t,e,n,i,r){for(let s=0,a=t.length-3;s<=a;s+=3){_o.fromArray(t,s);const a=r.x*Math.abs(_o.x)+r.y*Math.abs(_o.y)+r.z*Math.abs(_o.z),o=e.dot(_o),l=n.dot(_o),c=i.dot(_o);if(Math.max(-Math.max(o,l,c),Math.min(o,l,c))>a)return!1}return!0}const yo=new ro,bo=new Da,wo=new Da;class Mo{constructor(t=new Da,e=-1){this.isSphere=!0,this.center=t,this.radius=e}set(t,e){return this.center.copy(t),this.radius=e,this}setFromPoints(t,e){const n=this.center;void 0!==e?n.copy(e):yo.setFromPoints(t).getCenter(n);let i=0;for(let e=0,r=t.length;ethis.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e}getBoundingBox(t){return this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)}applyMatrix4(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this}translate(t){return this.center.add(t),this}expandByPoint(t){if(this.isEmpty())return this.center.copy(t),this.radius=0,this;bo.subVectors(t,this.center);const e=bo.lengthSq();if(e>this.radius*this.radius){const t=Math.sqrt(e),n=.5*(t-this.radius);this.center.addScaledVector(bo,n/t),this.radius+=n}return this}union(t){return t.isEmpty()?this:this.isEmpty()?(this.copy(t),this):(!0===this.center.equals(t.center)?this.radius=Math.max(this.radius,t.radius):(wo.subVectors(t.center,this.center).setLength(t.radius),this.expandByPoint(bo.copy(t.center).add(wo)),this.expandByPoint(bo.copy(t.center).sub(wo))),this)}equals(t){return t.center.equals(this.center)&&t.radius===this.radius}clone(){return(new this.constructor).copy(this)}toJSON(){return{radius:this.radius,center:this.center.toArray()}}fromJSON(t){return this.radius=t.radius,this.center.fromArray(t.center),this}}const So=new Da,Eo=new Da,To=new Da,Ao=new Da,Co=new Da,Ro=new Da,Po=new Da;class No{constructor(t=new Da,e=new Da(0,0,-1)){this.origin=t,this.direction=e}set(t,e){return this.origin.copy(t),this.direction.copy(e),this}copy(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}at(t,e){return e.copy(this.origin).addScaledVector(this.direction,t)}lookAt(t){return this.direction.copy(t).sub(this.origin).normalize(),this}recast(t){return this.origin.copy(this.at(t,So)),this}closestPointToPoint(t,e){e.subVectors(t,this.origin);const n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.origin).addScaledVector(this.direction,n)}distanceToPoint(t){return Math.sqrt(this.distanceSqToPoint(t))}distanceSqToPoint(t){const e=So.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(So.copy(this.origin).addScaledVector(this.direction,e),So.distanceToSquared(t))}distanceSqToSegment(t,e,n,i){Eo.copy(t).add(e).multiplyScalar(.5),To.copy(e).sub(t).normalize(),Ao.copy(this.origin).sub(Eo);const r=.5*t.distanceTo(e),s=-this.direction.dot(To),a=Ao.dot(this.direction),o=-Ao.dot(To),l=Ao.lengthSq(),c=Math.abs(1-s*s);let u,h,d,p;if(c>0)if(u=s*o-a,h=s*a-o,p=r*c,u>=0)if(h>=-p)if(h<=p){const t=1/c;u*=t,h*=t,d=u*(u+s*h+2*a)+h*(s*u+h+2*o)+l}else h=r,u=Math.max(0,-(s*h+a)),d=-u*u+h*(h+2*o)+l;else h=-r,u=Math.max(0,-(s*h+a)),d=-u*u+h*(h+2*o)+l;else h<=-p?(u=Math.max(0,-(-s*r+a)),h=u>0?-r:Math.min(Math.max(-r,-o),r),d=-u*u+h*(h+2*o)+l):h<=p?(u=0,h=Math.min(Math.max(-r,-o),r),d=h*(h+2*o)+l):(u=Math.max(0,-(s*r+a)),h=u>0?r:Math.min(Math.max(-r,-o),r),d=-u*u+h*(h+2*o)+l);else h=s>0?-r:r,u=Math.max(0,-(s*h+a)),d=-u*u+h*(h+2*o)+l;return n&&n.copy(this.origin).addScaledVector(this.direction,u),i&&i.copy(Eo).addScaledVector(To,h),d}intersectSphere(t,e){So.subVectors(t.center,this.origin);const n=So.dot(this.direction),i=So.dot(So)-n*n,r=t.radius*t.radius;if(i>r)return null;const s=Math.sqrt(r-i),a=n-s,o=n+s;return o<0?null:a<0?this.at(o,e):this.at(a,e)}intersectsSphere(t){return!(t.radius<0)&&this.distanceSqToPoint(t.center)<=t.radius*t.radius}distanceToPlane(t){const e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;const n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null}intersectPlane(t,e){const n=this.distanceToPlane(t);return null===n?null:this.at(n,e)}intersectsPlane(t){const e=t.distanceToPoint(this.origin);return 0===e||t.normal.dot(this.direction)*e<0}intersectBox(t,e){let n,i,r,s,a,o;const l=1/this.direction.x,c=1/this.direction.y,u=1/this.direction.z,h=this.origin;return l>=0?(n=(t.min.x-h.x)*l,i=(t.max.x-h.x)*l):(n=(t.max.x-h.x)*l,i=(t.min.x-h.x)*l),c>=0?(r=(t.min.y-h.y)*c,s=(t.max.y-h.y)*c):(r=(t.max.y-h.y)*c,s=(t.min.y-h.y)*c),n>s||r>i?null:((r>n||isNaN(n))&&(n=r),(s=0?(a=(t.min.z-h.z)*u,o=(t.max.z-h.z)*u):(a=(t.max.z-h.z)*u,o=(t.min.z-h.z)*u),n>o||a>i?null:((a>n||n!=n)&&(n=a),(o=0?n:i,e)))}intersectsBox(t){return null!==this.intersectBox(t,So)}intersectTriangle(t,e,n,i,r){Co.subVectors(e,t),Ro.subVectors(n,t),Po.crossVectors(Co,Ro);let s,a=this.direction.dot(Po);if(a>0){if(i)return null;s=1}else{if(!(a<0))return null;s=-1,a=-a}Ao.subVectors(this.origin,t);const o=s*this.direction.dot(Ro.crossVectors(Ao,Ro));if(o<0)return null;const l=s*this.direction.dot(Co.cross(Ao));if(l<0)return null;if(o+l>a)return null;const c=-s*Ao.dot(Po);return c<0?null:this.at(c/a,r)}applyMatrix4(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}equals(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}clone(){return(new this.constructor).copy(this)}}class Lo{constructor(t,e,n,i,r,s,a,o,l,c,u,h,d,p,f,m){Lo.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],void 0!==t&&this.set(t,e,n,i,r,s,a,o,l,c,u,h,d,p,f,m)}set(t,e,n,i,r,s,a,o,l,c,u,h,d,p,f,m){const g=this.elements;return g[0]=t,g[4]=e,g[8]=n,g[12]=i,g[1]=r,g[5]=s,g[9]=a,g[13]=o,g[2]=l,g[6]=c,g[10]=u,g[14]=h,g[3]=d,g[7]=p,g[11]=f,g[15]=m,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return(new Lo).fromArray(this.elements)}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this}copyPosition(t){const e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}setFromMatrix3(t){const e=t.elements;return this.set(e[0],e[3],e[6],0,e[1],e[4],e[7],0,e[2],e[5],e[8],0,0,0,0,1),this}extractBasis(t,e,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}extractRotation(t){const e=this.elements,n=t.elements,i=1/Uo.setFromMatrixColumn(t,0).length(),r=1/Uo.setFromMatrixColumn(t,1).length(),s=1/Uo.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*r,e[5]=n[5]*r,e[6]=n[6]*r,e[7]=0,e[8]=n[8]*s,e[9]=n[9]*s,e[10]=n[10]*s,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromEuler(t){const e=this.elements,n=t.x,i=t.y,r=t.z,s=Math.cos(n),a=Math.sin(n),o=Math.cos(i),l=Math.sin(i),c=Math.cos(r),u=Math.sin(r);if("XYZ"===t.order){const t=s*c,n=s*u,i=a*c,r=a*u;e[0]=o*c,e[4]=-o*u,e[8]=l,e[1]=n+i*l,e[5]=t-r*l,e[9]=-a*o,e[2]=r-t*l,e[6]=i+n*l,e[10]=s*o}else if("YXZ"===t.order){const t=o*c,n=o*u,i=l*c,r=l*u;e[0]=t+r*a,e[4]=i*a-n,e[8]=s*l,e[1]=s*u,e[5]=s*c,e[9]=-a,e[2]=n*a-i,e[6]=r+t*a,e[10]=s*o}else if("ZXY"===t.order){const t=o*c,n=o*u,i=l*c,r=l*u;e[0]=t-r*a,e[4]=-s*u,e[8]=i+n*a,e[1]=n+i*a,e[5]=s*c,e[9]=r-t*a,e[2]=-s*l,e[6]=a,e[10]=s*o}else if("ZYX"===t.order){const t=s*c,n=s*u,i=a*c,r=a*u;e[0]=o*c,e[4]=i*l-n,e[8]=t*l+r,e[1]=o*u,e[5]=r*l+t,e[9]=n*l-i,e[2]=-l,e[6]=a*o,e[10]=s*o}else if("YZX"===t.order){const t=s*o,n=s*l,i=a*o,r=a*l;e[0]=o*c,e[4]=r-t*u,e[8]=i*u+n,e[1]=u,e[5]=s*c,e[9]=-a*c,e[2]=-l*c,e[6]=n*u+i,e[10]=t-r*u}else if("XZY"===t.order){const t=s*o,n=s*l,i=a*o,r=a*l;e[0]=o*c,e[4]=-u,e[8]=l*c,e[1]=t*u+r,e[5]=s*c,e[9]=n*u-i,e[2]=i*u-n,e[6]=a*c,e[10]=r*u+t}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}makeRotationFromQuaternion(t){return this.compose(Io,t,Oo)}lookAt(t,e,n){const i=this.elements;return Bo.subVectors(t,e),0===Bo.lengthSq()&&(Bo.z=1),Bo.normalize(),ko.crossVectors(n,Bo),0===ko.lengthSq()&&(1===Math.abs(n.z)?Bo.x+=1e-4:Bo.z+=1e-4,Bo.normalize(),ko.crossVectors(n,Bo)),ko.normalize(),Fo.crossVectors(Bo,ko),i[0]=ko.x,i[4]=Fo.x,i[8]=Bo.x,i[1]=ko.y,i[5]=Fo.y,i[9]=Bo.y,i[2]=ko.z,i[6]=Fo.z,i[10]=Bo.z,this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,r=this.elements,s=n[0],a=n[4],o=n[8],l=n[12],c=n[1],u=n[5],h=n[9],d=n[13],p=n[2],f=n[6],m=n[10],g=n[14],v=n[3],_=n[7],x=n[11],y=n[15],b=i[0],w=i[4],M=i[8],S=i[12],E=i[1],T=i[5],A=i[9],C=i[13],R=i[2],P=i[6],N=i[10],L=i[14],U=i[3],D=i[7],I=i[11],O=i[15];return r[0]=s*b+a*E+o*R+l*U,r[4]=s*w+a*T+o*P+l*D,r[8]=s*M+a*A+o*N+l*I,r[12]=s*S+a*C+o*L+l*O,r[1]=c*b+u*E+h*R+d*U,r[5]=c*w+u*T+h*P+d*D,r[9]=c*M+u*A+h*N+d*I,r[13]=c*S+u*C+h*L+d*O,r[2]=p*b+f*E+m*R+g*U,r[6]=p*w+f*T+m*P+g*D,r[10]=p*M+f*A+m*N+g*I,r[14]=p*S+f*C+m*L+g*O,r[3]=v*b+_*E+x*R+y*U,r[7]=v*w+_*T+x*P+y*D,r[11]=v*M+_*A+x*N+y*I,r[15]=v*S+_*C+x*L+y*O,this}multiplyScalar(t){const e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}determinant(){const t=this.elements,e=t[0],n=t[4],i=t[8],r=t[12],s=t[1],a=t[5],o=t[9],l=t[13],c=t[2],u=t[6],h=t[10],d=t[14];return t[3]*(+r*o*u-i*l*u-r*a*h+n*l*h+i*a*d-n*o*d)+t[7]*(+e*o*d-e*l*h+r*s*h-i*s*d+i*l*c-r*o*c)+t[11]*(+e*l*u-e*a*d-r*s*u+n*s*d+r*a*c-n*l*c)+t[15]*(-i*a*c-e*o*u+e*a*h+i*s*u-n*s*h+n*o*c)}transpose(){const t=this.elements;let e;return e=t[1],t[1]=t[4],t[4]=e,e=t[2],t[2]=t[8],t[8]=e,e=t[6],t[6]=t[9],t[9]=e,e=t[3],t[3]=t[12],t[12]=e,e=t[7],t[7]=t[13],t[13]=e,e=t[11],t[11]=t[14],t[14]=e,this}setPosition(t,e,n){const i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=n),this}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],s=t[4],a=t[5],o=t[6],l=t[7],c=t[8],u=t[9],h=t[10],d=t[11],p=t[12],f=t[13],m=t[14],g=t[15],v=u*m*l-f*h*l+f*o*d-a*m*d-u*o*g+a*h*g,_=p*h*l-c*m*l-p*o*d+s*m*d+c*o*g-s*h*g,x=c*f*l-p*u*l+p*a*d-s*f*d-c*a*g+s*u*g,y=p*u*o-c*f*o-p*a*h+s*f*h+c*a*m-s*u*m,b=e*v+n*_+i*x+r*y;if(0===b)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const w=1/b;return t[0]=v*w,t[1]=(f*h*r-u*m*r-f*i*d+n*m*d+u*i*g-n*h*g)*w,t[2]=(a*m*r-f*o*r+f*i*l-n*m*l-a*i*g+n*o*g)*w,t[3]=(u*o*r-a*h*r-u*i*l+n*h*l+a*i*d-n*o*d)*w,t[4]=_*w,t[5]=(c*m*r-p*h*r+p*i*d-e*m*d-c*i*g+e*h*g)*w,t[6]=(p*o*r-s*m*r-p*i*l+e*m*l+s*i*g-e*o*g)*w,t[7]=(s*h*r-c*o*r+c*i*l-e*h*l-s*i*d+e*o*d)*w,t[8]=x*w,t[9]=(p*u*r-c*f*r-p*n*d+e*f*d+c*n*g-e*u*g)*w,t[10]=(s*f*r-p*a*r+p*n*l-e*f*l-s*n*g+e*a*g)*w,t[11]=(c*a*r-s*u*r-c*n*l+e*u*l+s*n*d-e*a*d)*w,t[12]=y*w,t[13]=(c*f*i-p*u*i+p*n*h-e*f*h-c*n*m+e*u*m)*w,t[14]=(p*a*i-s*f*i-p*n*o+e*f*o+s*n*m-e*a*m)*w,t[15]=(s*u*i-c*a*i+c*n*o-e*u*o-s*n*h+e*a*h)*w,this}scale(t){const e=this.elements,n=t.x,i=t.y,r=t.z;return e[0]*=n,e[4]*=i,e[8]*=r,e[1]*=n,e[5]*=i,e[9]*=r,e[2]*=n,e[6]*=i,e[10]*=r,e[3]*=n,e[7]*=i,e[11]*=r,this}getMaxScaleOnAxis(){const t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,i))}makeTranslation(t,e,n){return t.isVector3?this.set(1,0,0,t.x,0,1,0,t.y,0,0,1,t.z,0,0,0,1):this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}makeRotationX(t){const e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}makeRotationY(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}makeRotationZ(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(t,e){const n=Math.cos(e),i=Math.sin(e),r=1-n,s=t.x,a=t.y,o=t.z,l=r*s,c=r*a;return this.set(l*s+n,l*a-i*o,l*o+i*a,0,l*a+i*o,c*a+n,c*o-i*s,0,l*o-i*a,c*o+i*s,r*o*o+n,0,0,0,0,1),this}makeScale(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}makeShear(t,e,n,i,r,s){return this.set(1,n,r,0,t,1,s,0,e,i,1,0,0,0,0,1),this}compose(t,e,n){const i=this.elements,r=e._x,s=e._y,a=e._z,o=e._w,l=r+r,c=s+s,u=a+a,h=r*l,d=r*c,p=r*u,f=s*c,m=s*u,g=a*u,v=o*l,_=o*c,x=o*u,y=n.x,b=n.y,w=n.z;return i[0]=(1-(f+g))*y,i[1]=(d+x)*y,i[2]=(p-_)*y,i[3]=0,i[4]=(d-x)*b,i[5]=(1-(h+g))*b,i[6]=(m+v)*b,i[7]=0,i[8]=(p+_)*w,i[9]=(m-v)*w,i[10]=(1-(h+f))*w,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}decompose(t,e,n){const i=this.elements;let r=Uo.set(i[0],i[1],i[2]).length();const s=Uo.set(i[4],i[5],i[6]).length(),a=Uo.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),t.x=i[12],t.y=i[13],t.z=i[14],Do.copy(this);const o=1/r,l=1/s,c=1/a;return Do.elements[0]*=o,Do.elements[1]*=o,Do.elements[2]*=o,Do.elements[4]*=l,Do.elements[5]*=l,Do.elements[6]*=l,Do.elements[8]*=c,Do.elements[9]*=c,Do.elements[10]*=c,e.setFromRotationMatrix(Do),n.x=r,n.y=s,n.z=a,this}makePerspective(t,e,n,i,r,s,a=2e3,o=!1){const l=this.elements,c=2*r/(e-t),u=2*r/(n-i),h=(e+t)/(e-t),d=(n+i)/(n-i);let p,f;if(o)p=r/(s-r),f=s*r/(s-r);else if(a===da)p=-(s+r)/(s-r),f=-2*s*r/(s-r);else{if(a!==pa)throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+a);p=-s/(s-r),f=-s*r/(s-r)}return l[0]=c,l[4]=0,l[8]=h,l[12]=0,l[1]=0,l[5]=u,l[9]=d,l[13]=0,l[2]=0,l[6]=0,l[10]=p,l[14]=f,l[3]=0,l[7]=0,l[11]=-1,l[15]=0,this}makeOrthographic(t,e,n,i,r,s,a=2e3,o=!1){const l=this.elements,c=2/(e-t),u=2/(n-i),h=-(e+t)/(e-t),d=-(n+i)/(n-i);let p,f;if(o)p=1/(s-r),f=s/(s-r);else if(a===da)p=-2/(s-r),f=-(s+r)/(s-r);else{if(a!==pa)throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+a);p=-1/(s-r),f=-r/(s-r)}return l[0]=c,l[4]=0,l[8]=0,l[12]=h,l[1]=0,l[5]=u,l[9]=0,l[13]=d,l[2]=0,l[6]=0,l[10]=p,l[14]=f,l[3]=0,l[7]=0,l[11]=0,l[15]=1,this}equals(t){const e=this.elements,n=t.elements;for(let t=0;t<16;t++)if(e[t]!==n[t])return!1;return!0}fromArray(t,e=0){for(let n=0;n<16;n++)this.elements[n]=t[n+e];return this}toArray(t=[],e=0){const n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}}const Uo=new Da,Do=new Lo,Io=new Da(0,0,0),Oo=new Da(1,1,1),ko=new Da,Fo=new Da,Bo=new Da,zo=new Lo,Vo=new Ua;class Ho{constructor(t=0,e=0,n=0,i=Ho.DEFAULT_ORDER){this.isEuler=!0,this._x=t,this._y=e,this._z=n,this._order=i}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get order(){return this._order}set order(t){this._order=t,this._onChangeCallback()}set(t,e,n,i=this._order){return this._x=t,this._y=e,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this}setFromRotationMatrix(t,e=this._order,n=!0){const i=t.elements,r=i[0],s=i[4],a=i[8],o=i[1],l=i[5],c=i[9],u=i[2],h=i[6],d=i[10];switch(e){case"XYZ":this._y=Math.asin(Aa(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(-c,d),this._z=Math.atan2(-s,r)):(this._x=Math.atan2(h,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Aa(c,-1,1)),Math.abs(c)<.9999999?(this._y=Math.atan2(a,d),this._z=Math.atan2(o,l)):(this._y=Math.atan2(-u,r),this._z=0);break;case"ZXY":this._x=Math.asin(Aa(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(-u,d),this._z=Math.atan2(-s,l)):(this._y=0,this._z=Math.atan2(o,r));break;case"ZYX":this._y=Math.asin(-Aa(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(h,d),this._z=Math.atan2(o,r)):(this._x=0,this._z=Math.atan2(-s,l));break;case"YZX":this._z=Math.asin(Aa(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-c,l),this._y=Math.atan2(-u,r)):(this._x=0,this._y=Math.atan2(a,d));break;case"XZY":this._z=Math.asin(-Aa(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(h,l),this._y=Math.atan2(a,r)):(this._x=Math.atan2(-c,d),this._y=0);break;default:xa("Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!0===n&&this._onChangeCallback(),this}setFromQuaternion(t,e,n){return zo.makeRotationFromQuaternion(t),this.setFromRotationMatrix(zo,e,n)}setFromVector3(t,e=this._order){return this.set(t.x,t.y,t.z,e)}reorder(t){return Vo.setFromEuler(this),this.setFromQuaternion(Vo,t)}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order}fromArray(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Ho.DEFAULT_ORDER="XYZ";class Go{constructor(){this.mask=1}set(t){this.mask=1<>>0}enable(t){this.mask|=1<1){for(let t=0;t1){for(let t=0;t0&&(i.userData=this.userData),i.layers=this.layers.mask,i.matrix=this.matrix.toArray(),i.up=this.up.toArray(),!1===this.matrixAutoUpdate&&(i.matrixAutoUpdate=!1),this.isInstancedMesh&&(i.type="InstancedMesh",i.count=this.count,i.instanceMatrix=this.instanceMatrix.toJSON(),null!==this.instanceColor&&(i.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(i.type="BatchedMesh",i.perObjectFrustumCulled=this.perObjectFrustumCulled,i.sortObjects=this.sortObjects,i.drawRanges=this._drawRanges,i.reservedRanges=this._reservedRanges,i.geometryInfo=this._geometryInfo.map(t=>({...t,boundingBox:t.boundingBox?t.boundingBox.toJSON():void 0,boundingSphere:t.boundingSphere?t.boundingSphere.toJSON():void 0})),i.instanceInfo=this._instanceInfo.map(t=>({...t})),i.availableInstanceIds=this._availableInstanceIds.slice(),i.availableGeometryIds=this._availableGeometryIds.slice(),i.nextIndexStart=this._nextIndexStart,i.nextVertexStart=this._nextVertexStart,i.geometryCount=this._geometryCount,i.maxInstanceCount=this._maxInstanceCount,i.maxVertexCount=this._maxVertexCount,i.maxIndexCount=this._maxIndexCount,i.geometryInitialized=this._geometryInitialized,i.matricesTexture=this._matricesTexture.toJSON(t),i.indirectTexture=this._indirectTexture.toJSON(t),null!==this._colorsTexture&&(i.colorsTexture=this._colorsTexture.toJSON(t)),null!==this.boundingSphere&&(i.boundingSphere=this.boundingSphere.toJSON()),null!==this.boundingBox&&(i.boundingBox=this.boundingBox.toJSON())),this.isScene)this.background&&(this.background.isColor?i.background=this.background.toJSON():this.background.isTexture&&(i.background=this.background.toJSON(t).uuid)),this.environment&&this.environment.isTexture&&!0!==this.environment.isRenderTargetTexture&&(i.environment=this.environment.toJSON(t).uuid);else if(this.isMesh||this.isLine||this.isPoints){i.geometry=r(t.geometries,this.geometry);const e=this.geometry.parameters;if(void 0!==e&&void 0!==e.shapes){const n=e.shapes;if(Array.isArray(n))for(let e=0,i=n.length;e0){i.children=[];for(let e=0;e0){i.animations=[];for(let e=0;e0&&(n.geometries=e),i.length>0&&(n.materials=i),r.length>0&&(n.textures=r),a.length>0&&(n.images=a),o.length>0&&(n.shapes=o),l.length>0&&(n.skeletons=l),c.length>0&&(n.animations=c),u.length>0&&(n.nodes=u)}return n.object=i,n;function s(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}}clone(t){return(new this.constructor).copy(this,t)}copy(t,e=!0){if(this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldAutoUpdate=t.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.animations=t.animations.slice(),this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(let e=0;e0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)}static getBarycoord(t,e,n,i,r){al.subVectors(i,e),ol.subVectors(n,e),ll.subVectors(t,e);const s=al.dot(al),a=al.dot(ol),o=al.dot(ll),l=ol.dot(ol),c=ol.dot(ll),u=s*l-a*a;if(0===u)return r.set(0,0,0),null;const h=1/u,d=(l*o-a*c)*h,p=(s*c-a*o)*h;return r.set(1-d-p,p,d)}static containsPoint(t,e,n,i){return null!==this.getBarycoord(t,e,n,i,cl)&&cl.x>=0&&cl.y>=0&&cl.x+cl.y<=1}static getInterpolation(t,e,n,i,r,s,a,o){return null===this.getBarycoord(t,e,n,i,cl)?(o.x=0,o.y=0,"z"in o&&(o.z=0),"w"in o&&(o.w=0),null):(o.setScalar(0),o.addScaledVector(r,cl.x),o.addScaledVector(s,cl.y),o.addScaledVector(a,cl.z),o)}static getInterpolatedAttribute(t,e,n,i,r,s){return gl.setScalar(0),vl.setScalar(0),_l.setScalar(0),gl.fromBufferAttribute(t,e),vl.fromBufferAttribute(t,n),_l.fromBufferAttribute(t,i),s.setScalar(0),s.addScaledVector(gl,r.x),s.addScaledVector(vl,r.y),s.addScaledVector(_l,r.z),s}static isFrontFacing(t,e,n,i){return al.subVectors(n,e),ol.subVectors(t,e),al.cross(ol).dot(i)<0}set(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this}setFromPointsAndIndices(t,e,n,i){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[i]),this}setFromAttributeAndIndices(t,e,n,i){return this.a.fromBufferAttribute(t,e),this.b.fromBufferAttribute(t,n),this.c.fromBufferAttribute(t,i),this}clone(){return(new this.constructor).copy(this)}copy(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this}getArea(){return al.subVectors(this.c,this.b),ol.subVectors(this.a,this.b),.5*al.cross(ol).length()}getMidpoint(t){return t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(t){return xl.getNormal(this.a,this.b,this.c,t)}getPlane(t){return t.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(t,e){return xl.getBarycoord(t,this.a,this.b,this.c,e)}getInterpolation(t,e,n,i,r){return xl.getInterpolation(t,this.a,this.b,this.c,e,n,i,r)}containsPoint(t){return xl.containsPoint(t,this.a,this.b,this.c)}isFrontFacing(t){return xl.isFrontFacing(this.a,this.b,this.c,t)}intersectsBox(t){return t.intersectsTriangle(this)}closestPointToPoint(t,e){const n=this.a,i=this.b,r=this.c;let s,a;ul.subVectors(i,n),hl.subVectors(r,n),pl.subVectors(t,n);const o=ul.dot(pl),l=hl.dot(pl);if(o<=0&&l<=0)return e.copy(n);fl.subVectors(t,i);const c=ul.dot(fl),u=hl.dot(fl);if(c>=0&&u<=c)return e.copy(i);const h=o*u-c*l;if(h<=0&&o>=0&&c<=0)return s=o/(o-c),e.copy(n).addScaledVector(ul,s);ml.subVectors(t,r);const d=ul.dot(ml),p=hl.dot(ml);if(p>=0&&d<=p)return e.copy(r);const f=d*l-o*p;if(f<=0&&l>=0&&p<=0)return a=l/(l-p),e.copy(n).addScaledVector(hl,a);const m=c*p-d*u;if(m<=0&&u-c>=0&&d-p>=0)return dl.subVectors(r,i),a=(u-c)/(u-c+(d-p)),e.copy(i).addScaledVector(dl,a);const g=1/(m+f+h);return s=f*g,a=h*g,e.copy(n).addScaledVector(ul,s).addScaledVector(hl,a)}equals(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}}const yl={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},bl={h:0,s:0,l:0},wl={h:0,s:0,l:0};function Ml(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+6*(e-t)*(2/3-n):t}class Sl{constructor(t,e,n){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(t,e,n)}set(t,e,n){if(void 0===e&&void 0===n){const e=t;e&&e.isColor?this.copy(e):"number"==typeof e?this.setHex(e):"string"==typeof e&&this.setStyle(e)}else this.setRGB(t,e,n);return this}setScalar(t){return this.r=t,this.g=t,this.b=t,this}setHex(t,e=Js){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,Ha.colorSpaceToWorking(this,e),this}setRGB(t,e,n,i=Ha.workingColorSpace){return this.r=t,this.g=e,this.b=n,Ha.colorSpaceToWorking(this,i),this}setHSL(t,e,n,i=Ha.workingColorSpace){if(t=(t%(r=1)+r)%r,e=Aa(e,0,1),n=Aa(n,0,1),0===e)this.r=this.g=this.b=n;else{const i=n<=.5?n*(1+e):n+e-n*e,r=2*n-i;this.r=Ml(r,i,t+1/3),this.g=Ml(r,i,t),this.b=Ml(r,i,t-1/3)}var r;return Ha.colorSpaceToWorking(this,i),this}setStyle(t,e=Js){function n(e){void 0!==e&&parseFloat(e)<1&&xa("Color: Alpha component of "+t+" will be ignored.")}let i;if(i=/^(\w+)\(([^\)]*)\)/.exec(t)){let r;const s=i[1],a=i[2];switch(s){case"rgb":case"rgba":if(r=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(r[4]),this.setRGB(Math.min(255,parseInt(r[1],10))/255,Math.min(255,parseInt(r[2],10))/255,Math.min(255,parseInt(r[3],10))/255,e);if(r=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(r[4]),this.setRGB(Math.min(100,parseInt(r[1],10))/100,Math.min(100,parseInt(r[2],10))/100,Math.min(100,parseInt(r[3],10))/100,e);break;case"hsl":case"hsla":if(r=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(a))return n(r[4]),this.setHSL(parseFloat(r[1])/360,parseFloat(r[2])/100,parseFloat(r[3])/100,e);break;default:xa("Color: Unknown color model "+t)}}else if(i=/^\#([A-Fa-f\d]+)$/.exec(t)){const n=i[1],r=n.length;if(3===r)return this.setRGB(parseInt(n.charAt(0),16)/15,parseInt(n.charAt(1),16)/15,parseInt(n.charAt(2),16)/15,e);if(6===r)return this.setHex(parseInt(n,16),e);xa("Color: Invalid hex color "+t)}else if(t&&t.length>0)return this.setColorName(t,e);return this}setColorName(t,e=Js){const n=yl[t.toLowerCase()];return void 0!==n?this.setHex(n,e):xa("Color: Unknown color "+t),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(t){return this.r=t.r,this.g=t.g,this.b=t.b,this}copySRGBToLinear(t){return this.r=Ga(t.r),this.g=Ga(t.g),this.b=Ga(t.b),this}copyLinearToSRGB(t){return this.r=Wa(t.r),this.g=Wa(t.g),this.b=Wa(t.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(t=Js){return Ha.workingToColorSpace(El.copy(this),t),65536*Math.round(Aa(255*El.r,0,255))+256*Math.round(Aa(255*El.g,0,255))+Math.round(Aa(255*El.b,0,255))}getHexString(t=Js){return("000000"+this.getHex(t).toString(16)).slice(-6)}getHSL(t,e=Ha.workingColorSpace){Ha.workingToColorSpace(El.copy(this),e);const n=El.r,i=El.g,r=El.b,s=Math.max(n,i,r),a=Math.min(n,i,r);let o,l;const c=(a+s)/2;if(a===s)o=0,l=0;else{const t=s-a;switch(l=c<=.5?t/(s+a):t/(2-s-a),s){case n:o=(i-r)/t+(i0!=t>0&&this.version++,this._alphaTest=t}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(t){if(void 0!==t)for(const e in t){const n=t[e];if(void 0===n){xa(`Material: parameter '${e}' has value of undefined.`);continue}const i=this[e];void 0!==i?i&&i.isColor?i.set(n):i&&i.isVector3&&n&&n.isVector3?i.copy(n):this[e]=n:xa(`Material: '${e}' is not a property of THREE.${this.type}.`)}}toJSON(t){const e=void 0===t||"string"==typeof t;e&&(t={textures:{},images:{}});const n={metadata:{version:4.7,type:"Material",generator:"Material.toJSON"}};function i(t){const e=[];for(const n in t){const i=t[n];delete i.metadata,e.push(i)}return e}if(n.uuid=this.uuid,n.type=this.type,""!==this.name&&(n.name=this.name),this.color&&this.color.isColor&&(n.color=this.color.getHex()),void 0!==this.roughness&&(n.roughness=this.roughness),void 0!==this.metalness&&(n.metalness=this.metalness),void 0!==this.sheen&&(n.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(n.sheenColor=this.sheenColor.getHex()),void 0!==this.sheenRoughness&&(n.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(n.emissive=this.emissive.getHex()),void 0!==this.emissiveIntensity&&1!==this.emissiveIntensity&&(n.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(n.specular=this.specular.getHex()),void 0!==this.specularIntensity&&(n.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(n.specularColor=this.specularColor.getHex()),void 0!==this.shininess&&(n.shininess=this.shininess),void 0!==this.clearcoat&&(n.clearcoat=this.clearcoat),void 0!==this.clearcoatRoughness&&(n.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(n.clearcoatMap=this.clearcoatMap.toJSON(t).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(n.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(t).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(n.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(t).uuid,n.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.sheenColorMap&&this.sheenColorMap.isTexture&&(n.sheenColorMap=this.sheenColorMap.toJSON(t).uuid),this.sheenRoughnessMap&&this.sheenRoughnessMap.isTexture&&(n.sheenRoughnessMap=this.sheenRoughnessMap.toJSON(t).uuid),void 0!==this.dispersion&&(n.dispersion=this.dispersion),void 0!==this.iridescence&&(n.iridescence=this.iridescence),void 0!==this.iridescenceIOR&&(n.iridescenceIOR=this.iridescenceIOR),void 0!==this.iridescenceThicknessRange&&(n.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(n.iridescenceMap=this.iridescenceMap.toJSON(t).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(n.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(t).uuid),void 0!==this.anisotropy&&(n.anisotropy=this.anisotropy),void 0!==this.anisotropyRotation&&(n.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(n.anisotropyMap=this.anisotropyMap.toJSON(t).uuid),this.map&&this.map.isTexture&&(n.map=this.map.toJSON(t).uuid),this.matcap&&this.matcap.isTexture&&(n.matcap=this.matcap.toJSON(t).uuid),this.alphaMap&&this.alphaMap.isTexture&&(n.alphaMap=this.alphaMap.toJSON(t).uuid),this.lightMap&&this.lightMap.isTexture&&(n.lightMap=this.lightMap.toJSON(t).uuid,n.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(n.aoMap=this.aoMap.toJSON(t).uuid,n.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(n.bumpMap=this.bumpMap.toJSON(t).uuid,n.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(n.normalMap=this.normalMap.toJSON(t).uuid,n.normalMapType=this.normalMapType,n.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(n.displacementMap=this.displacementMap.toJSON(t).uuid,n.displacementScale=this.displacementScale,n.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(n.roughnessMap=this.roughnessMap.toJSON(t).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(n.metalnessMap=this.metalnessMap.toJSON(t).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(n.emissiveMap=this.emissiveMap.toJSON(t).uuid),this.specularMap&&this.specularMap.isTexture&&(n.specularMap=this.specularMap.toJSON(t).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(n.specularIntensityMap=this.specularIntensityMap.toJSON(t).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(n.specularColorMap=this.specularColorMap.toJSON(t).uuid),this.envMap&&this.envMap.isTexture&&(n.envMap=this.envMap.toJSON(t).uuid,void 0!==this.combine&&(n.combine=this.combine)),void 0!==this.envMapRotation&&(n.envMapRotation=this.envMapRotation.toArray()),void 0!==this.envMapIntensity&&(n.envMapIntensity=this.envMapIntensity),void 0!==this.reflectivity&&(n.reflectivity=this.reflectivity),void 0!==this.refractionRatio&&(n.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(n.gradientMap=this.gradientMap.toJSON(t).uuid),void 0!==this.transmission&&(n.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(n.transmissionMap=this.transmissionMap.toJSON(t).uuid),void 0!==this.thickness&&(n.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(n.thicknessMap=this.thicknessMap.toJSON(t).uuid),void 0!==this.attenuationDistance&&this.attenuationDistance!==1/0&&(n.attenuationDistance=this.attenuationDistance),void 0!==this.attenuationColor&&(n.attenuationColor=this.attenuationColor.getHex()),void 0!==this.size&&(n.size=this.size),null!==this.shadowSide&&(n.shadowSide=this.shadowSide),void 0!==this.sizeAttenuation&&(n.sizeAttenuation=this.sizeAttenuation),1!==this.blending&&(n.blending=this.blending),0!==this.side&&(n.side=this.side),!0===this.vertexColors&&(n.vertexColors=!0),this.opacity<1&&(n.opacity=this.opacity),!0===this.transparent&&(n.transparent=!0),204!==this.blendSrc&&(n.blendSrc=this.blendSrc),205!==this.blendDst&&(n.blendDst=this.blendDst),this.blendEquation!==gr&&(n.blendEquation=this.blendEquation),null!==this.blendSrcAlpha&&(n.blendSrcAlpha=this.blendSrcAlpha),null!==this.blendDstAlpha&&(n.blendDstAlpha=this.blendDstAlpha),null!==this.blendEquationAlpha&&(n.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(n.blendColor=this.blendColor.getHex()),0!==this.blendAlpha&&(n.blendAlpha=this.blendAlpha),3!==this.depthFunc&&(n.depthFunc=this.depthFunc),!1===this.depthTest&&(n.depthTest=this.depthTest),!1===this.depthWrite&&(n.depthWrite=this.depthWrite),!1===this.colorWrite&&(n.colorWrite=this.colorWrite),255!==this.stencilWriteMask&&(n.stencilWriteMask=this.stencilWriteMask),519!==this.stencilFunc&&(n.stencilFunc=this.stencilFunc),0!==this.stencilRef&&(n.stencilRef=this.stencilRef),255!==this.stencilFuncMask&&(n.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==na&&(n.stencilFail=this.stencilFail),this.stencilZFail!==na&&(n.stencilZFail=this.stencilZFail),this.stencilZPass!==na&&(n.stencilZPass=this.stencilZPass),!0===this.stencilWrite&&(n.stencilWrite=this.stencilWrite),void 0!==this.rotation&&0!==this.rotation&&(n.rotation=this.rotation),!0===this.polygonOffset&&(n.polygonOffset=!0),0!==this.polygonOffsetFactor&&(n.polygonOffsetFactor=this.polygonOffsetFactor),0!==this.polygonOffsetUnits&&(n.polygonOffsetUnits=this.polygonOffsetUnits),void 0!==this.linewidth&&1!==this.linewidth&&(n.linewidth=this.linewidth),void 0!==this.dashSize&&(n.dashSize=this.dashSize),void 0!==this.gapSize&&(n.gapSize=this.gapSize),void 0!==this.scale&&(n.scale=this.scale),!0===this.dithering&&(n.dithering=!0),this.alphaTest>0&&(n.alphaTest=this.alphaTest),!0===this.alphaHash&&(n.alphaHash=!0),!0===this.alphaToCoverage&&(n.alphaToCoverage=!0),!0===this.premultipliedAlpha&&(n.premultipliedAlpha=!0),!0===this.forceSinglePass&&(n.forceSinglePass=!0),!0===this.wireframe&&(n.wireframe=!0),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(n.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(n.wireframeLinejoin=this.wireframeLinejoin),!0===this.flatShading&&(n.flatShading=!0),!1===this.visible&&(n.visible=!1),!1===this.toneMapped&&(n.toneMapped=!1),!1===this.fog&&(n.fog=!1),Object.keys(this.userData).length>0&&(n.userData=this.userData),e){const e=i(t.textures),r=i(t.images);e.length>0&&(n.textures=e),r.length>0&&(n.images=r)}return n}clone(){return(new this.constructor).copy(this)}copy(t){this.name=t.name,this.blending=t.blending,this.side=t.side,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.blendColor.copy(t.blendColor),this.blendAlpha=t.blendAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;const e=t.clippingPlanes;let n=null;if(null!==e){const t=e.length;n=new Array(t);for(let i=0;i!==t;++i)n[i]=e[i].clone()}return this.clippingPlanes=n,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.alphaHash=t.alphaHash,this.alphaToCoverage=t.alphaToCoverage,this.premultipliedAlpha=t.premultipliedAlpha,this.forceSinglePass=t.forceSinglePass,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(t){!0===t&&this.version++}}class Cl extends Al{constructor(t){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Sl(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.envMapRotation=new Ho,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapRotation.copy(t.envMapRotation),this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.fog=t.fog,this}}const Rl=new Da,Pl=new La;let Nl=0;class Ll{constructor(t,e,n=!1){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,Object.defineProperty(this,"id",{value:Nl++}),this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=n,this.usage=35044,this.updateRanges=[],this.gpuType=rs,this.version=0}onUploadCallback(){}set needsUpdate(t){!0===t&&this.version++}setUsage(t){return this.usage=t,this}addUpdateRange(t,e){this.updateRanges.push({start:t,count:e})}clearUpdateRanges(){this.updateRanges.length=0}copy(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this.gpuType=t.gpuType,this}copyAt(t,e,n){t*=this.itemSize,n*=e.itemSize;for(let i=0,r=this.itemSize;ie.count&&xa("BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry."),e.needsUpdate=!0}return this}computeBoundingBox(){null===this.boundingBox&&(this.boundingBox=new ro);const t=this.attributes.position,e=this.morphAttributes.position;if(t&&t.isGLBufferAttribute)return ya("BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.",this),void this.boundingBox.set(new Da(-1/0,-1/0,-1/0),new Da(1/0,1/0,1/0));if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(let t=0,n=e.length;t0&&(t.userData=this.userData),void 0!==this.parameters){const e=this.parameters;for(const n in e)void 0!==e[n]&&(t[n]=e[n]);return t}t.data={attributes:{}};const e=this.index;null!==e&&(t.data.index={type:e.array.constructor.name,array:Array.prototype.slice.call(e.array)});const n=this.attributes;for(const e in n){const i=n[e];t.data.attributes[e]=i.toJSON(t.data)}const i={};let r=!1;for(const e in this.morphAttributes){const n=this.morphAttributes[e],s=[];for(let e=0,i=n.length;e0&&(i[e]=s,r=!0)}r&&(t.data.morphAttributes=i,t.data.morphTargetsRelative=this.morphTargetsRelative);const s=this.groups;s.length>0&&(t.data.groups=JSON.parse(JSON.stringify(s)));const a=this.boundingSphere;return null!==a&&(t.data.boundingSphere=a.toJSON()),t}clone(){return(new this.constructor).copy(this)}copy(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const e={};this.name=t.name;const n=t.index;null!==n&&this.setIndex(n.clone());const i=t.attributes;for(const t in i){const n=i[t];this.setAttribute(t,n.clone(e))}const r=t.morphAttributes;for(const t in r){const n=[],i=r[t];for(let t=0,r=i.length;t0){const n=t[e[0]];if(void 0!==n){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=n.length;t(t.far-t.near)**2)return}Wl.copy(r).invert(),jl.copy(t.ray).applyMatrix4(Wl),null!==n.boundingBox&&!1===jl.intersectsBox(n.boundingBox)||this._computeIntersections(t,e,jl)}}_computeIntersections(t,e,n){let i;const r=this.geometry,s=this.material,a=r.index,o=r.attributes.position,l=r.attributes.uv,c=r.attributes.uv1,u=r.attributes.normal,h=r.groups,d=r.drawRange;if(null!==a)if(Array.isArray(s))for(let r=0,o=h.length;rn.far?null:{distance:c,point:tc.clone(),object:t}}(t,e,n,i,ql,Yl,Zl,Ql);if(u){const t=new Da;xl.getBarycoord(Ql,ql,Yl,Zl,t),r&&(u.uv=xl.getInterpolatedAttribute(r,o,l,c,t,new La)),s&&(u.uv1=xl.getInterpolatedAttribute(s,o,l,c,t,new La)),a&&(u.normal=xl.getInterpolatedAttribute(a,o,l,c,t,new Da),u.normal.dot(i.direction)>0&&u.normal.multiplyScalar(-1));const e={a:o,b:l,c,normal:new Da,materialIndex:0};xl.getNormal(ql,Yl,Zl,e.normal),u.face=e,u.barycoord=t}return u}class ic extends Gl{constructor(t=1,e=1,n=1,i=1,r=1,s=1){super(),this.type="BoxGeometry",this.parameters={width:t,height:e,depth:n,widthSegments:i,heightSegments:r,depthSegments:s};const a=this;i=Math.floor(i),r=Math.floor(r),s=Math.floor(s);const o=[],l=[],c=[],u=[];let h=0,d=0;function p(t,e,n,i,r,s,p,f,m,g,v){const _=s/m,x=p/g,y=s/2,b=p/2,w=f/2,M=m+1,S=g+1;let E=0,T=0;const A=new Da;for(let s=0;s0?1:-1,c.push(A.x,A.y,A.z),u.push(o/m),u.push(1-s/g),E+=1}}for(let t=0;t0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader,e.lights=this.lights,e.clipping=this.clipping;const n={};for(const t in this.extensions)!0===this.extensions[t]&&(n[t]=!0);return Object.keys(n).length>0&&(e.extensions=n),e}}class cc extends sl{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Lo,this.projectionMatrix=new Lo,this.projectionMatrixInverse=new Lo,this.coordinateSystem=da,this._reversedDepth=!1}get reversedDepth(){return this._reversedDepth}copy(t,e){return super.copy(t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this.coordinateSystem=t.coordinateSystem,this}getWorldDirection(t){return super.getWorldDirection(t).negate()}updateMatrixWorld(t){super.updateMatrixWorld(t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return(new this.constructor).copy(this)}}const uc=new Da,hc=new La,dc=new La;class pc extends cc{constructor(t=50,e=1,n=.1,i=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=t,this.zoom=1,this.near=n,this.far=i,this.focus=10,this.aspect=e,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=null===t.view?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this}setFocalLength(t){const e=.5*this.getFilmHeight()/t;this.fov=2*Ea*Math.atan(e),this.updateProjectionMatrix()}getFocalLength(){const t=Math.tan(.5*Sa*this.fov);return.5*this.getFilmHeight()/t}getEffectiveFOV(){return 2*Ea*Math.atan(Math.tan(.5*Sa*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}getViewBounds(t,e,n){uc.set(-1,-1,.5).applyMatrix4(this.projectionMatrixInverse),e.set(uc.x,uc.y).multiplyScalar(-t/uc.z),uc.set(1,1,.5).applyMatrix4(this.projectionMatrixInverse),n.set(uc.x,uc.y).multiplyScalar(-t/uc.z)}getViewSize(t,e){return this.getViewBounds(t,hc,dc),e.subVectors(dc,hc)}setViewOffset(t,e,n,i,r,s){this.aspect=t/e,null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=i,this.view.width=r,this.view.height=s,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=this.near;let e=t*Math.tan(.5*Sa*this.fov)/this.zoom,n=2*e,i=this.aspect*n,r=-.5*i;const s=this.view;if(null!==this.view&&this.view.enabled){const t=s.fullWidth,a=s.fullHeight;r+=s.offsetX*i/t,e-=s.offsetY*n/a,i*=s.width/t,n*=s.height/a}const a=this.filmOffset;0!==a&&(r+=t*a/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-n,t,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}}const fc=-90;class mc extends sl{constructor(t,e,n){super(),this.type="CubeCamera",this.renderTarget=n,this.coordinateSystem=null,this.activeMipmapLevel=0;const i=new pc(fc,1,t,e);i.layers=this.layers,this.add(i);const r=new pc(fc,1,t,e);r.layers=this.layers,this.add(r);const s=new pc(fc,1,t,e);s.layers=this.layers,this.add(s);const a=new pc(fc,1,t,e);a.layers=this.layers,this.add(a);const o=new pc(fc,1,t,e);o.layers=this.layers,this.add(o);const l=new pc(fc,1,t,e);l.layers=this.layers,this.add(l)}updateCoordinateSystem(){const t=this.coordinateSystem,e=this.children.concat(),[n,i,r,s,a,o]=e;for(const t of e)this.remove(t);if(t===da)n.up.set(0,1,0),n.lookAt(1,0,0),i.up.set(0,1,0),i.lookAt(-1,0,0),r.up.set(0,0,-1),r.lookAt(0,1,0),s.up.set(0,0,1),s.lookAt(0,-1,0),a.up.set(0,1,0),a.lookAt(0,0,1),o.up.set(0,1,0),o.lookAt(0,0,-1);else{if(t!==pa)throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+t);n.up.set(0,-1,0),n.lookAt(-1,0,0),i.up.set(0,-1,0),i.lookAt(1,0,0),r.up.set(0,0,1),r.lookAt(0,1,0),s.up.set(0,0,-1),s.lookAt(0,-1,0),a.up.set(0,-1,0),a.lookAt(0,0,1),o.up.set(0,-1,0),o.lookAt(0,0,-1)}for(const t of e)this.add(t),t.updateMatrixWorld()}update(t,e){null===this.parent&&this.updateMatrixWorld();const{renderTarget:n,activeMipmapLevel:i}=this;this.coordinateSystem!==t.coordinateSystem&&(this.coordinateSystem=t.coordinateSystem,this.updateCoordinateSystem());const[r,s,a,o,l,c]=this.children,u=t.getRenderTarget(),h=t.getActiveCubeFace(),d=t.getActiveMipmapLevel(),p=t.xr.enabled;t.xr.enabled=!1;const f=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,t.setRenderTarget(n,0,i),t.render(e,r),t.setRenderTarget(n,1,i),t.render(e,s),t.setRenderTarget(n,2,i),t.render(e,a),t.setRenderTarget(n,3,i),t.render(e,o),t.setRenderTarget(n,4,i),t.render(e,l),n.texture.generateMipmaps=f,t.setRenderTarget(n,5,i),t.render(e,c),t.setRenderTarget(u,h,d),t.xr.enabled=p,n.texture.needsPMREMUpdate=!0}}class gc extends Ja{constructor(t=[],e=301,n,i,r,s,a,o,l,c){super(t,e,n,i,r,s,a,o,l,c),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(t){this.image=t}}class vc extends eo{constructor(t=1,e={}){super(t,t,e),this.isWebGLCubeRenderTarget=!0;const n={width:t,height:t,depth:1},i=[n,n,n,n,n,n];this.texture=new gc(i),this._setTextureOptions(e),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(t,e){this.texture.type=e.type,this.texture.colorSpace=e.colorSpace,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;const n={tEquirect:{value:null}},i="\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include \n\t\t\t\t\t#include \n\n\t\t\t\t}\n\t\t\t",r="\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include \n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t",s=new ic(5,5,5),a=new lc({name:"CubemapFromEquirect",uniforms:rc(n),vertexShader:i,fragmentShader:r,side:1,blending:0});a.uniforms.tEquirect.value=e;const o=new ec(s,a),l=e.minFilter;return e.minFilter===Qr&&(e.minFilter=Kr),new mc(1,10,this).update(t,o),e.minFilter=l,o.geometry.dispose(),o.material.dispose(),this}clear(t,e=!0,n=!0,i=!0){const r=t.getRenderTarget();for(let r=0;r<6;r++)t.setRenderTarget(this,r),t.clear(e,n,i);t.setRenderTarget(r)}}class _c extends sl{constructor(){super(),this.isGroup=!0,this.type="Group"}}const xc={type:"move"};class yc{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return null===this._hand&&(this._hand=new _c,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return null===this._targetRay&&(this._targetRay=new _c,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new Da,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new Da),this._targetRay}getGripSpace(){return null===this._grip&&(this._grip=new _c,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new Da,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new Da),this._grip}dispatchEvent(t){return null!==this._targetRay&&this._targetRay.dispatchEvent(t),null!==this._grip&&this._grip.dispatchEvent(t),null!==this._hand&&this._hand.dispatchEvent(t),this}connect(t){if(t&&t.hand){const e=this._hand;if(e)for(const n of t.hand.values())this._getHandJoint(e,n)}return this.dispatchEvent({type:"connected",data:t}),this}disconnect(t){return this.dispatchEvent({type:"disconnected",data:t}),null!==this._targetRay&&(this._targetRay.visible=!1),null!==this._grip&&(this._grip.visible=!1),null!==this._hand&&(this._hand.visible=!1),this}update(t,e,n){let i=null,r=null,s=null;const a=this._targetRay,o=this._grip,l=this._hand;if(t&&"visible-blurred"!==e.session.visibilityState){if(l&&t.hand){s=!0;for(const i of t.hand.values()){const t=e.getJointPose(i,n),r=this._getHandJoint(l,i);null!==t&&(r.matrix.fromArray(t.transform.matrix),r.matrix.decompose(r.position,r.rotation,r.scale),r.matrixWorldNeedsUpdate=!0,r.jointRadius=t.radius),r.visible=null!==t}const i=l.joints["index-finger-tip"],r=l.joints["thumb-tip"],a=i.position.distanceTo(r.position),o=.02,c=.005;l.inputState.pinching&&a>o+c?(l.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!l.inputState.pinching&&a<=o-c&&(l.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}else null!==o&&t.gripSpace&&(r=e.getPose(t.gripSpace,n),null!==r&&(o.matrix.fromArray(r.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale),o.matrixWorldNeedsUpdate=!0,r.linearVelocity?(o.hasLinearVelocity=!0,o.linearVelocity.copy(r.linearVelocity)):o.hasLinearVelocity=!1,r.angularVelocity?(o.hasAngularVelocity=!0,o.angularVelocity.copy(r.angularVelocity)):o.hasAngularVelocity=!1));null!==a&&(i=e.getPose(t.targetRaySpace,n),null===i&&null!==r&&(i=r),null!==i&&(a.matrix.fromArray(i.transform.matrix),a.matrix.decompose(a.position,a.rotation,a.scale),a.matrixWorldNeedsUpdate=!0,i.linearVelocity?(a.hasLinearVelocity=!0,a.linearVelocity.copy(i.linearVelocity)):a.hasLinearVelocity=!1,i.angularVelocity?(a.hasAngularVelocity=!0,a.angularVelocity.copy(i.angularVelocity)):a.hasAngularVelocity=!1,this.dispatchEvent(xc)))}return null!==a&&(a.visible=null!==i),null!==o&&(o.visible=null!==r),null!==l&&(l.visible=null!==s),this}_getHandJoint(t,e){if(void 0===t.joints[e.jointName]){const n=new _c;n.matrixAutoUpdate=!1,n.visible=!1,t.joints[e.jointName]=n,t.add(n)}return t.joints[e.jointName]}}class bc extends sl{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.backgroundRotation=new Ho,this.environmentIntensity=1,this.environmentRotation=new Ho,this.overrideMaterial=null,"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(t,e){return super.copy(t,e),null!==t.background&&(this.background=t.background.clone()),null!==t.environment&&(this.environment=t.environment.clone()),null!==t.fog&&(this.fog=t.fog.clone()),this.backgroundBlurriness=t.backgroundBlurriness,this.backgroundIntensity=t.backgroundIntensity,this.backgroundRotation.copy(t.backgroundRotation),this.environmentIntensity=t.environmentIntensity,this.environmentRotation.copy(t.environmentRotation),null!==t.overrideMaterial&&(this.overrideMaterial=t.overrideMaterial.clone()),this.matrixAutoUpdate=t.matrixAutoUpdate,this}toJSON(t){const e=super.toJSON(t);return null!==this.fog&&(e.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(e.object.backgroundBlurriness=this.backgroundBlurriness),1!==this.backgroundIntensity&&(e.object.backgroundIntensity=this.backgroundIntensity),e.object.backgroundRotation=this.backgroundRotation.toArray(),1!==this.environmentIntensity&&(e.object.environmentIntensity=this.environmentIntensity),e.object.environmentRotation=this.environmentRotation.toArray(),e}}class wc extends Ja{constructor(t=null,e=1,n=1,i,r,s,a,o,l=1003,c=1003,u,h){super(null,s,a,o,l,c,i,r,u,h),this.isDataTexture=!0,this.image={data:t,width:e,height:n},this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}const Mc=new Da,Sc=new Da,Ec=new ka;class Tc{constructor(t=new Da(1,0,0),e=0){this.isPlane=!0,this.normal=t,this.constant=e}set(t,e){return this.normal.copy(t),this.constant=e,this}setComponents(t,e,n,i){return this.normal.set(t,e,n),this.constant=i,this}setFromNormalAndCoplanarPoint(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this}setFromCoplanarPoints(t,e,n){const i=Mc.subVectors(n,e).cross(Sc.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(i,t),this}copy(t){return this.normal.copy(t.normal),this.constant=t.constant,this}normalize(){const t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(t){return this.normal.dot(t)+this.constant}distanceToSphere(t){return this.distanceToPoint(t.center)-t.radius}projectPoint(t,e){return e.copy(t).addScaledVector(this.normal,-this.distanceToPoint(t))}intersectLine(t,e){const n=t.delta(Mc),i=this.normal.dot(n);if(0===i)return 0===this.distanceToPoint(t.start)?e.copy(t.start):null;const r=-(t.start.dot(this.normal)+this.constant)/i;return r<0||r>1?null:e.copy(t.start).addScaledVector(n,r)}intersectsLine(t){const e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0}intersectsBox(t){return t.intersectsPlane(this)}intersectsSphere(t){return t.intersectsPlane(this)}coplanarPoint(t){return t.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(t,e){const n=e||Ec.getNormalMatrix(t),i=this.coplanarPoint(Mc).applyMatrix4(t),r=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(r),this}translate(t){return this.constant-=t.dot(this.normal),this}equals(t){return t.normal.equals(this.normal)&&t.constant===this.constant}clone(){return(new this.constructor).copy(this)}}const Ac=new Mo,Cc=new La(.5,.5),Rc=new Da;class Pc{constructor(t=new Tc,e=new Tc,n=new Tc,i=new Tc,r=new Tc,s=new Tc){this.planes=[t,e,n,i,r,s]}set(t,e,n,i,r,s){const a=this.planes;return a[0].copy(t),a[1].copy(e),a[2].copy(n),a[3].copy(i),a[4].copy(r),a[5].copy(s),this}copy(t){const e=this.planes;for(let n=0;n<6;n++)e[n].copy(t.planes[n]);return this}setFromProjectionMatrix(t,e=2e3,n=!1){const i=this.planes,r=t.elements,s=r[0],a=r[1],o=r[2],l=r[3],c=r[4],u=r[5],h=r[6],d=r[7],p=r[8],f=r[9],m=r[10],g=r[11],v=r[12],_=r[13],x=r[14],y=r[15];if(i[0].setComponents(l-s,d-c,g-p,y-v).normalize(),i[1].setComponents(l+s,d+c,g+p,y+v).normalize(),i[2].setComponents(l+a,d+u,g+f,y+_).normalize(),i[3].setComponents(l-a,d-u,g-f,y-_).normalize(),n)i[4].setComponents(o,h,m,x).normalize(),i[5].setComponents(l-o,d-h,g-m,y-x).normalize();else if(i[4].setComponents(l-o,d-h,g-m,y-x).normalize(),e===da)i[5].setComponents(l+o,d+h,g+m,y+x).normalize();else{if(e!==pa)throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+e);i[5].setComponents(o,h,m,x).normalize()}return this}intersectsObject(t){if(void 0!==t.boundingSphere)null===t.boundingSphere&&t.computeBoundingSphere(),Ac.copy(t.boundingSphere).applyMatrix4(t.matrixWorld);else{const e=t.geometry;null===e.boundingSphere&&e.computeBoundingSphere(),Ac.copy(e.boundingSphere).applyMatrix4(t.matrixWorld)}return this.intersectsSphere(Ac)}intersectsSprite(t){Ac.center.set(0,0,0);const e=Cc.distanceTo(t.center);return Ac.radius=.7071067811865476+e,Ac.applyMatrix4(t.matrixWorld),this.intersectsSphere(Ac)}intersectsSphere(t){const e=this.planes,n=t.center,i=-t.radius;for(let t=0;t<6;t++)if(e[t].distanceToPoint(n)0?t.max.x:t.min.x,Rc.y=i.normal.y>0?t.max.y:t.min.y,Rc.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(Rc)<0)return!1}return!0}containsPoint(t){const e=this.planes;for(let n=0;n<6;n++)if(e[n].distanceToPoint(t)<0)return!1;return!0}clone(){return(new this.constructor).copy(this)}}class Nc extends Al{constructor(t){super(),this.isLineBasicMaterial=!0,this.type="LineBasicMaterial",this.color=new Sl(16777215),this.map=null,this.linewidth=1,this.linecap="round",this.linejoin="round",this.fog=!0,this.setValues(t)}copy(t){return super.copy(t),this.color.copy(t.color),this.map=t.map,this.linewidth=t.linewidth,this.linecap=t.linecap,this.linejoin=t.linejoin,this.fog=t.fog,this}}const Lc=new Da,Uc=new Da,Dc=new Lo,Ic=new No,Oc=new Mo,kc=new Da,Fc=new Da;class Bc extends sl{constructor(t=new Gl,e=new Nc){super(),this.isLine=!0,this.type="Line",this.geometry=t,this.material=e,this.morphTargetDictionary=void 0,this.morphTargetInfluences=void 0,this.updateMorphTargets()}copy(t,e){return super.copy(t,e),this.material=Array.isArray(t.material)?t.material.slice():t.material,this.geometry=t.geometry,this}computeLineDistances(){const t=this.geometry;if(null===t.index){const e=t.attributes.position,n=[0];for(let t=1,i=e.count;t0){const n=t[e[0]];if(void 0!==n){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let t=0,e=n.length;ti)return;kc.applyMatrix4(t.matrixWorld);const l=e.ray.origin.distanceTo(kc);return le.far?void 0:{distance:l,point:Fc.clone().applyMatrix4(t.matrixWorld),index:a,face:null,faceIndex:null,barycoord:null,object:t}}const Vc=new Da,Hc=new Da;class Gc extends Bc{constructor(t,e){super(t,e),this.isLineSegments=!0,this.type="LineSegments"}computeLineDistances(){const t=this.geometry;if(null===t.index){const e=t.attributes.position,n=[];for(let t=0,i=e.count;t0||0!==i)&&(c.push(s,a,l),_+=3),(e>0||i!==r-1)&&(c.push(a,o,l),_+=3)}l.addGroup(g,_,0),g+=_}(),!1===s&&(t>0&&v(!0),e>0&&v(!1)),this.setIndex(c),this.setAttribute("position",new Il(u,3)),this.setAttribute("normal",new Il(h,3)),this.setAttribute("uv",new Il(d,2))}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}static fromJSON(t){return new $c(t.radiusTop,t.radiusBottom,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}class qc extends $c{constructor(t=1,e=1,n=32,i=1,r=!1,s=0,a=2*Math.PI){super(0,t,e,n,i,r,s,a),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:n,heightSegments:i,openEnded:r,thetaStart:s,thetaLength:a}}static fromJSON(t){return new qc(t.radius,t.height,t.radialSegments,t.heightSegments,t.openEnded,t.thetaStart,t.thetaLength)}}const Yc=new Da,Zc=new Da,Kc=new Da,Jc=new xl;class Qc extends Gl{constructor(t=null,e=1){if(super(),this.type="EdgesGeometry",this.parameters={geometry:t,thresholdAngle:e},null!==t){const n=4,i=Math.pow(10,n),r=Math.cos(Sa*e),s=t.getIndex(),a=t.getAttribute("position"),o=s?s.count:a.count,l=[0,0,0],c=["a","b","c"],u=new Array(3),h={},d=[];for(let t=0;t=r)){const a=e[1];t=r)break e}s=n,n=0;break n}break t}for(;n>>1;te;)--s;if(++s,0!==r||s!==i){r>=s&&(s=Math.max(s,1),r=s-1);const t=this.getValueSize();this.times=n.slice(r,s),this.values=this.values.slice(r*t,s*t)}return this}validate(){let t=!0;const e=this.getValueSize();e-Math.floor(e)!==0&&(ya("KeyframeTrack: Invalid value size in track.",this),t=!1);const n=this.times,i=this.values,r=n.length;0===r&&(ya("KeyframeTrack: Track is empty.",this),t=!1);let s=null;for(let e=0;e!==r;e++){const i=n[e];if("number"==typeof i&&isNaN(i)){ya("KeyframeTrack: Time is not a valid number.",this,e,i),t=!1;break}if(null!==s&&s>i){ya("KeyframeTrack: Out of order keys.",this,e,i,s),t=!1;break}s=i}if(void 0!==i&&function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}(i))for(let e=0,n=i.length;e!==n;++e){const n=i[e];if(isNaN(n)){ya("KeyframeTrack: Value is not a valid number.",this,e,n),t=!1;break}}return t}optimize(){const t=this.times.slice(),e=this.values.slice(),n=this.getValueSize(),i=this.getInterpolation()===Zs,r=t.length-1;let s=1;for(let a=1;a0){t[s]=t[r];for(let t=r*n,i=s*n,a=0;a!==n;++a)e[i+a]=e[t+a];++s}return s!==t.length?(this.times=t.slice(0,s),this.values=e.slice(0,s*n)):(this.times=t,this.values=e),this}clone(){const t=this.times.slice(),e=this.values.slice(),n=new(0,this.constructor)(this.name,t,e);return n.createInterpolant=this.createInterpolant,n}}hu.prototype.ValueTypeName="",hu.prototype.TimeBufferType=Float32Array,hu.prototype.ValueBufferType=Float32Array,hu.prototype.DefaultInterpolation=Ys;class du extends hu{constructor(t,e,n){super(t,e,n)}}du.prototype.ValueTypeName="bool",du.prototype.ValueBufferType=Array,du.prototype.DefaultInterpolation=qs,du.prototype.InterpolantFactoryMethodLinear=void 0,du.prototype.InterpolantFactoryMethodSmooth=void 0;(class extends hu{constructor(t,e,n,i){super(t,e,n,i)}}).prototype.ValueTypeName="color";(class extends hu{constructor(t,e,n,i){super(t,e,n,i)}}).prototype.ValueTypeName="number";class pu extends ou{constructor(t,e,n,i){super(t,e,n,i)}interpolate_(t,e,n,i){const r=this.resultBuffer,s=this.sampleValues,a=this.valueSize,o=(n-e)/(i-e);let l=t*a;for(let t=l+a;l!==t;l+=4)Ua.slerpFlat(r,0,s,l-a,s,l,o);return r}}class fu extends hu{constructor(t,e,n,i){super(t,e,n,i)}InterpolantFactoryMethodLinear(t){return new pu(this.times,this.values,this.getValueSize(),t)}}fu.prototype.ValueTypeName="quaternion",fu.prototype.InterpolantFactoryMethodSmooth=void 0;class mu extends hu{constructor(t,e,n){super(t,e,n)}}mu.prototype.ValueTypeName="string",mu.prototype.ValueBufferType=Array,mu.prototype.DefaultInterpolation=qs,mu.prototype.InterpolantFactoryMethodLinear=void 0,mu.prototype.InterpolantFactoryMethodSmooth=void 0;(class extends hu{constructor(t,e,n,i){super(t,e,n,i)}}).prototype.ValueTypeName="vector";Error,new WeakMap;class gu extends sl{constructor(t,e=1){super(),this.isLight=!0,this.type="Light",this.color=new Sl(t),this.intensity=e}dispose(){}copy(t,e){return super.copy(t,e),this.color.copy(t.color),this.intensity=t.intensity,this}toJSON(t){const e=super.toJSON(t);return e.object.color=this.color.getHex(),e.object.intensity=this.intensity,void 0!==this.groundColor&&(e.object.groundColor=this.groundColor.getHex()),void 0!==this.distance&&(e.object.distance=this.distance),void 0!==this.angle&&(e.object.angle=this.angle),void 0!==this.decay&&(e.object.decay=this.decay),void 0!==this.penumbra&&(e.object.penumbra=this.penumbra),void 0!==this.shadow&&(e.object.shadow=this.shadow.toJSON()),void 0!==this.target&&(e.object.target=this.target.uuid),e}}const vu=new Lo,_u=new Da,xu=new Da;class yu{constructor(t){this.camera=t,this.intensity=1,this.bias=0,this.normalBias=0,this.radius=1,this.blurSamples=8,this.mapSize=new La(512,512),this.mapType=ts,this.map=null,this.mapPass=null,this.matrix=new Lo,this.autoUpdate=!0,this.needsUpdate=!1,this._frustum=new Pc,this._frameExtents=new La(1,1),this._viewportCount=1,this._viewports=[new Qa(0,0,1,1)]}getViewportCount(){return this._viewportCount}getFrustum(){return this._frustum}updateMatrices(t){const e=this.camera,n=this.matrix;_u.setFromMatrixPosition(t.matrixWorld),e.position.copy(_u),xu.setFromMatrixPosition(t.target.matrixWorld),e.lookAt(xu),e.updateMatrixWorld(),vu.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),this._frustum.setFromProjectionMatrix(vu,e.coordinateSystem,e.reversedDepth),e.reversedDepth?n.set(.5,0,0,.5,0,.5,0,.5,0,0,1,0,0,0,0,1):n.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),n.multiply(vu)}getViewport(t){return this._viewports[t]}getFrameExtents(){return this._frameExtents}dispose(){this.map&&this.map.dispose(),this.mapPass&&this.mapPass.dispose()}copy(t){return this.camera=t.camera.clone(),this.intensity=t.intensity,this.bias=t.bias,this.radius=t.radius,this.autoUpdate=t.autoUpdate,this.needsUpdate=t.needsUpdate,this.normalBias=t.normalBias,this.blurSamples=t.blurSamples,this.mapSize.copy(t.mapSize),this}clone(){return(new this.constructor).copy(this)}toJSON(){const t={};return 1!==this.intensity&&(t.intensity=this.intensity),0!==this.bias&&(t.bias=this.bias),0!==this.normalBias&&(t.normalBias=this.normalBias),1!==this.radius&&(t.radius=this.radius),512===this.mapSize.x&&512===this.mapSize.y||(t.mapSize=this.mapSize.toArray()),t.camera=this.camera.toJSON(!1).object,delete t.camera.matrix,t}}class bu extends yu{constructor(){super(new pc(50,1,.5,500)),this.isSpotLightShadow=!0,this.focus=1,this.aspect=1}updateMatrices(t){const e=this.camera,n=2*Ea*t.angle*this.focus,i=this.mapSize.width/this.mapSize.height*this.aspect,r=t.distance||e.far;n===e.fov&&i===e.aspect&&r===e.far||(e.fov=n,e.aspect=i,e.far=r,e.updateProjectionMatrix()),super.updateMatrices(t)}copy(t){return super.copy(t),this.focus=t.focus,this}}class wu extends gu{constructor(t,e,n=0,i=Math.PI/3,r=0,s=2){super(t,e),this.isSpotLight=!0,this.type="SpotLight",this.position.copy(sl.DEFAULT_UP),this.updateMatrix(),this.target=new sl,this.distance=n,this.angle=i,this.penumbra=r,this.decay=s,this.map=null,this.shadow=new bu}get power(){return this.intensity*Math.PI}set power(t){this.intensity=t/Math.PI}dispose(){this.shadow.dispose()}copy(t,e){return super.copy(t,e),this.distance=t.distance,this.angle=t.angle,this.penumbra=t.penumbra,this.decay=t.decay,this.target=t.target.clone(),this.shadow=t.shadow.clone(),this}}class Mu extends cc{constructor(t=-1,e=1,n=1,i=-1,r=.1,s=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=t,this.right=e,this.top=n,this.bottom=i,this.near=r,this.far=s,this.updateProjectionMatrix()}copy(t,e){return super.copy(t,e),this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom,this.near=t.near,this.far=t.far,this.zoom=t.zoom,this.view=null===t.view?null:Object.assign({},t.view),this}setViewOffset(t,e,n,i,r,s){null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=i,this.view.width=r,this.view.height=s,this.updateProjectionMatrix()}clearViewOffset(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const t=(this.right-this.left)/(2*this.zoom),e=(this.top-this.bottom)/(2*this.zoom),n=(this.right+this.left)/2,i=(this.top+this.bottom)/2;let r=n-t,s=n+t,a=i+e,o=i-e;if(null!==this.view&&this.view.enabled){const t=(this.right-this.left)/this.view.fullWidth/this.zoom,e=(this.top-this.bottom)/this.view.fullHeight/this.zoom;r+=t*this.view.offsetX,s=r+t*this.view.width,a-=e*this.view.offsetY,o=a-e*this.view.height}this.projectionMatrix.makeOrthographic(r,s,a,o,this.near,this.far,this.coordinateSystem,this.reversedDepth),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(t){const e=super.toJSON(t);return e.object.zoom=this.zoom,e.object.left=this.left,e.object.right=this.right,e.object.top=this.top,e.object.bottom=this.bottom,e.object.near=this.near,e.object.far=this.far,null!==this.view&&(e.object.view=Object.assign({},this.view)),e}}class Su extends gu{constructor(t,e){super(t,e),this.isAmbientLight=!0,this.type="AmbientLight"}}new WeakMap;class Eu extends pc{constructor(t=[]){super(),this.isArrayCamera=!0,this.isMultiViewCamera=!1,this.cameras=t}}const Tu="\\[\\]\\.:\\/",Au=new RegExp("["+Tu+"]","g"),Cu="[^"+Tu+"]",Ru="[^"+Tu.replace("\\.","")+"]",Pu=new RegExp("^"+/((?:WC+[\/:])*)/.source.replace("WC",Cu)+/(WCOD+)?/.source.replace("WCOD",Ru)+/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",Cu)+/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",Cu)+"$"),Nu=["material","materials","bones","map"];class Lu{constructor(t,e,n){this.path=e,this.parsedPath=n||Lu.parseTrackName(e),this.node=Lu.findNode(t,this.parsedPath.nodeName),this.rootNode=t,this.getValue=this._getValue_unbound,this.setValue=this._setValue_unbound}static create(t,e,n){return t&&t.isAnimationObjectGroup?new Lu.Composite(t,e,n):new Lu(t,e,n)}static sanitizeNodeName(t){return t.replace(/\s/g,"_").replace(Au,"")}static parseTrackName(t){const e=Pu.exec(t);if(null===e)throw new Error("PropertyBinding: Cannot parse trackName: "+t);const n={nodeName:e[2],objectName:e[3],objectIndex:e[4],propertyName:e[5],propertyIndex:e[6]},i=n.nodeName&&n.nodeName.lastIndexOf(".");if(void 0!==i&&-1!==i){const t=n.nodeName.substring(i+1);-1!==Nu.indexOf(t)&&(n.nodeName=n.nodeName.substring(0,i),n.objectName=t)}if(null===n.propertyName||0===n.propertyName.length)throw new Error("PropertyBinding: can not parse propertyName from trackName: "+t);return n}static findNode(t,e){if(void 0===e||""===e||"."===e||-1===e||e===t.name||e===t.uuid)return t;if(t.skeleton){const n=t.skeleton.getBoneByName(e);if(void 0!==n)return n}if(t.children){const n=function(t){for(let i=0;i.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{Iu.set(t.z,0,-t.x).normalize();const e=Math.acos(t.y);this.quaternion.setFromAxisAngle(Iu,e)}}setLength(t,e=.2*t,n=.2*e){this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(n,e,n),this.cone.position.y=t,this.cone.updateMatrix()}setColor(t){this.line.material.color.set(t),this.cone.material.color.set(t)}copy(t){return super.copy(t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this}dispose(){this.line.geometry.dispose(),this.line.material.dispose(),this.cone.geometry.dispose(),this.cone.material.dispose()}}class Bu extends Gc{constructor(t=1){const e=[0,0,0,t,0,0,0,0,0,0,t,0,0,0,0,0,0,t],n=new Gl;n.setAttribute("position",new Il(e,3)),n.setAttribute("color",new Il([1,0,0,1,.6,0,0,1,0,.6,1,0,0,0,1,0,.6,1],3)),super(n,new Nc({vertexColors:!0,toneMapped:!1})),this.type="AxesHelper"}setColors(t,e,n){const i=new Sl,r=this.geometry.attributes.color.array;return i.set(t),i.toArray(r,0),i.toArray(r,3),i.set(e),i.toArray(r,6),i.toArray(r,9),i.set(n),i.toArray(r,12),i.toArray(r,15),this.geometry.attributes.color.needsUpdate=!0,this}dispose(){this.geometry.dispose(),this.material.dispose()}}class zu extends wa{constructor(t,e=null){super(),this.object=t,this.domElement=e,this.enabled=!0,this.state=-1,this.keys={},this.mouseButtons={LEFT:null,MIDDLE:null,RIGHT:null},this.touches={ONE:null,TWO:null}}connect(t){void 0!==t?(null!==this.domElement&&this.disconnect(),this.domElement=t):xa("Controls: connect() now requires an element.")}disconnect(){}dispose(){}update(){}}function Vu(t,e,n,i){const r=function(t){switch(t){case ts:case 1010:return{byteLength:1,components:1};case es:case 1011:case ss:return{byteLength:2,components:1};case as:case os:return{byteLength:2,components:4};case is:case ns:case rs:return{byteLength:4,components:1};case 35902:case 35899:return{byteLength:4,components:3}}throw new Error(`Unknown texture type ${t}.`)}(i);switch(n){case 1021:return t*e;case 1028:case ds:return t*e/r.components*r.byteLength;case ps:case fs:return t*e*2/r.components*r.byteLength;case 1022:return t*e*3/r.components*r.byteLength;case cs:case ms:return t*e*4/r.components*r.byteLength;case gs:case vs:return Math.floor((t+3)/4)*Math.floor((e+3)/4)*8;case _s:case xs:return Math.floor((t+3)/4)*Math.floor((e+3)/4)*16;case bs:case Ms:return Math.max(t,16)*Math.max(e,8)/4;case ys:case ws:return Math.max(t,8)*Math.max(e,8)/2;case Ss:case Es:return Math.floor((t+3)/4)*Math.floor((e+3)/4)*8;case Ts:case As:return Math.floor((t+3)/4)*Math.floor((e+3)/4)*16;case Cs:return Math.floor((t+4)/5)*Math.floor((e+3)/4)*16;case Rs:return Math.floor((t+4)/5)*Math.floor((e+4)/5)*16;case Ps:return Math.floor((t+5)/6)*Math.floor((e+4)/5)*16;case Ns:return Math.floor((t+5)/6)*Math.floor((e+5)/6)*16;case Ls:return Math.floor((t+7)/8)*Math.floor((e+4)/5)*16;case Us:return Math.floor((t+7)/8)*Math.floor((e+5)/6)*16;case Ds:return Math.floor((t+7)/8)*Math.floor((e+7)/8)*16;case Is:return Math.floor((t+9)/10)*Math.floor((e+4)/5)*16;case Os:return Math.floor((t+9)/10)*Math.floor((e+5)/6)*16;case ks:return Math.floor((t+9)/10)*Math.floor((e+7)/8)*16;case Fs:return Math.floor((t+9)/10)*Math.floor((e+9)/10)*16;case Bs:return Math.floor((t+11)/12)*Math.floor((e+9)/10)*16;case zs:return Math.floor((t+11)/12)*Math.floor((e+11)/12)*16;case Vs:case Hs:case Gs:return Math.ceil(t/4)*Math.ceil(e/4)*16;case Ws:case js:return Math.ceil(t/4)*Math.ceil(e/4)*8;case Xs:case $s:return Math.ceil(t/4)*Math.ceil(e/4)*16}throw new Error(`Unable to determine texture byte length for ${n} format.`)}function Hu(){let t=null,e=!1,n=null,i=null;function r(e,s){n(e,s),i=t.requestAnimationFrame(r)}return{start:function(){!0!==e&&null!==n&&(i=t.requestAnimationFrame(r),e=!0)},stop:function(){t.cancelAnimationFrame(i),e=!1},setAnimationLoop:function(t){n=t},setContext:function(e){t=e}}}function Gu(t){const e=new WeakMap;return{get:function(t){return t.isInterleavedBufferAttribute&&(t=t.data),e.get(t)},remove:function(n){n.isInterleavedBufferAttribute&&(n=n.data);const i=e.get(n);i&&(t.deleteBuffer(i.buffer),e.delete(n))},update:function(n,i){if(n.isInterleavedBufferAttribute&&(n=n.data),n.isGLBufferAttribute){const t=e.get(n);return void((!t||t.versiont.start-e.start);let e=0;for(let t=1;t 0\n\tvec4 plane;\n\t#ifdef ALPHA_TO_COVERAGE\n\t\tfloat distanceToPlane, distanceGradient;\n\t\tfloat clipOpacity = 1.0;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\tclipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\tif ( clipOpacity == 0.0 ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tfloat unionClipOpacity = 1.0;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\n\t\t\t\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\n\t\t\t\tunionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tclipOpacity *= 1.0 - unionClipOpacity;\n\t\t#endif\n\t\tdiffuseColor.a *= clipOpacity;\n\t\tif ( diffuseColor.a == 0.0 ) discard;\n\t#else\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\t\tbool clipped = true;\n\t\t\t#pragma unroll_loop_start\n\t\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\t\tplane = clippingPlanes[ i ];\n\t\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t\t}\n\t\t\t#pragma unroll_loop_end\n\t\t\tif ( clipped ) discard;\n\t\t#endif\n\t#endif\n#endif",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif",color_fragment:"#if defined( USE_COLOR_ALPHA )\n\tdiffuseColor *= vColor;\n#elif defined( USE_COLOR )\n\tdiffuseColor.rgb *= vColor;\n#endif",color_pars_fragment:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR )\n\tvarying vec3 vColor;\n#endif",color_pars_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvarying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvarying vec3 vColor;\n#endif",color_vertex:"#if defined( USE_COLOR_ALPHA )\n\tvColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\n\tvColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n\tvColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n\tvColor.xyz *= instanceColor.xyz;\n#endif\n#ifdef USE_BATCHING_COLOR\n\tvec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );\n\tvColor.xyz *= batchingColor.xyz;\n#endif",common:"#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n\tvarying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n\treturn m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\treturn vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n\t#define cubeUV_minMipLevel 4.0\n\t#define cubeUV_minTileSize 16.0\n\tfloat getFace( vec3 direction ) {\n\t\tvec3 absDirection = abs( direction );\n\t\tfloat face = - 1.0;\n\t\tif ( absDirection.x > absDirection.z ) {\n\t\t\tif ( absDirection.x > absDirection.y )\n\t\t\t\tface = direction.x > 0.0 ? 0.0 : 3.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t} else {\n\t\t\tif ( absDirection.z > absDirection.y )\n\t\t\t\tface = direction.z > 0.0 ? 2.0 : 5.0;\n\t\t\telse\n\t\t\t\tface = direction.y > 0.0 ? 1.0 : 4.0;\n\t\t}\n\t\treturn face;\n\t}\n\tvec2 getUV( vec3 direction, float face ) {\n\t\tvec2 uv;\n\t\tif ( face == 0.0 ) {\n\t\t\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 1.0 ) {\n\t\t\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n\t\t} else if ( face == 2.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\n\t\t} else if ( face == 3.0 ) {\n\t\t\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\n\t\t} else if ( face == 4.0 ) {\n\t\t\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\n\t\t} else {\n\t\t\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\n\t\t}\n\t\treturn 0.5 * ( uv + 1.0 );\n\t}\n\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n\t\tfloat face = getFace( direction );\n\t\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n\t\tmipInt = max( mipInt, cubeUV_minMipLevel );\n\t\tfloat faceSize = exp2( mipInt );\n\t\thighp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;\n\t\tif ( face > 2.0 ) {\n\t\t\tuv.y += faceSize;\n\t\t\tface -= 3.0;\n\t\t}\n\t\tuv.x += face * faceSize;\n\t\tuv.x += filterInt * 3.0 * cubeUV_minTileSize;\n\t\tuv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\n\t\tuv.x *= CUBEUV_TEXEL_WIDTH;\n\t\tuv.y *= CUBEUV_TEXEL_HEIGHT;\n\t\t#ifdef texture2DGradEXT\n\t\t\treturn texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;\n\t\t#else\n\t\t\treturn texture2D( envMap, uv ).rgb;\n\t\t#endif\n\t}\n\t#define cubeUV_r0 1.0\n\t#define cubeUV_m0 - 2.0\n\t#define cubeUV_r1 0.8\n\t#define cubeUV_m1 - 1.0\n\t#define cubeUV_r4 0.4\n\t#define cubeUV_m4 2.0\n\t#define cubeUV_r5 0.305\n\t#define cubeUV_m5 3.0\n\t#define cubeUV_r6 0.21\n\t#define cubeUV_m6 4.0\n\tfloat roughnessToMip( float roughness ) {\n\t\tfloat mip = 0.0;\n\t\tif ( roughness >= cubeUV_r1 ) {\n\t\t\tmip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\n\t\t} else if ( roughness >= cubeUV_r4 ) {\n\t\t\tmip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\n\t\t} else if ( roughness >= cubeUV_r5 ) {\n\t\t\tmip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\n\t\t} else if ( roughness >= cubeUV_r6 ) {\n\t\t\tmip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\n\t\t} else {\n\t\t\tmip = - 2.0 * log2( 1.16 * roughness );\t\t}\n\t\treturn mip;\n\t}\n\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n\t\tfloat mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\n\t\tfloat mipF = fract( mip );\n\t\tfloat mipInt = floor( mip );\n\t\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n\t\tif ( mipF == 0.0 ) {\n\t\t\treturn vec4( color0, 1.0 );\n\t\t} else {\n\t\t\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n\t\t\treturn vec4( mix( color0, color1, mipF ), 1.0 );\n\t\t}\n\t}\n#endif",defaultnormal_vertex:"vec3 transformedNormal = objectNormal;\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = objectTangent;\n#endif\n#ifdef USE_BATCHING\n\tmat3 bm = mat3( batchingMatrix );\n\ttransformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );\n\ttransformedNormal = bm * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = bm * transformedTangent;\n\t#endif\n#endif\n#ifdef USE_INSTANCING\n\tmat3 im = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );\n\ttransformedNormal = im * transformedNormal;\n\t#ifdef USE_TANGENT\n\t\ttransformedTangent = im * transformedTangent;\n\t#endif\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\ttransformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n\t\temissiveColor = sRGBTransferEOTF( emissiveColor );\n\t#endif\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif",colorspace_fragment:"gl_FragColor = linearToOutputTexel( gl_FragColor );",colorspace_pars_fragment:"vec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferEOTF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}",envmap_fragment:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif",envmap_common_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform mat3 envMapRotation;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n#endif",envmap_pars_fragment:"#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif",envmap_pars_vertex:"#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif",envmap_physical_pars_fragment:"#ifdef USE_ENVMAP\n\tvec3 getIBLIrradiance( const in vec3 normal ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );\n\t\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\tvec3 reflectVec = reflect( - viewDir, normal );\n\t\t\treflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );\n\t\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\n\t\t\treturn envMapColor.rgb * envMapIntensity;\n\t\t#else\n\t\t\treturn vec3( 0.0 );\n\t\t#endif\n\t}\n\t#ifdef USE_ANISOTROPY\n\t\tvec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n\t\t\t#ifdef ENVMAP_TYPE_CUBE_UV\n\t\t\t\tvec3 bentNormal = cross( bitangent, viewDir );\n\t\t\t\tbentNormal = normalize( cross( bentNormal, bitangent ) );\n\t\t\t\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n\t\t\t\treturn getIBLRadiance( viewDir, bentNormal, roughness );\n\t\t\t#else\n\t\t\t\treturn vec3( 0.0 );\n\t\t\t#endif\n\t\t}\n\t#endif\n#endif",envmap_vertex:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif",fog_vertex:"#ifdef USE_FOG\n\tvFogDepth = - mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\n\tvarying float vFogDepth;\n#endif",fog_fragment:"#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif",fog_pars_fragment:"#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float vFogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif",gradientmap_pars_fragment:"#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn vec3( texture2D( gradientMap, coord ).r );\n\t#else\n\t\tvec2 fw = fwidth( coord ) * 0.5;\n\t\treturn mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n\t#endif\n}",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif",lights_lambert_fragment:"LambertMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularStrength = specularStrength;",lights_lambert_pars_fragment:"varying vec3 vViewPosition;\nstruct LambertMaterial {\n\tvec3 diffuseColor;\n\tfloat specularStrength;\n};\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Lambert\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Lambert",lights_pars_begin:"uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n\tuniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\treturn irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif ( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n\t\tlight.color = directionalLight.color;\n\t\tlight.direction = directionalLight.direction;\n\t\tlight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = pointLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tlight.color = pointLight.color;\n\t\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n\t\tvec3 lVector = spotLight.position - geometryPosition;\n\t\tlight.direction = normalize( lVector );\n\t\tfloat angleCos = dot( light.direction, spotLight.direction );\n\t\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\tif ( spotAttenuation > 0.0 ) {\n\t\t\tfloat lightDistance = length( lVector );\n\t\t\tlight.color = spotLight.color * spotAttenuation;\n\t\t\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tlight.visible = ( light.color != vec3( 0.0 ) );\n\t\t} else {\n\t\t\tlight.color = vec3( 0.0 );\n\t\t\tlight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n\t\tfloat dotNL = dot( normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\treturn irradiance;\n\t}\n#endif",lights_toon_fragment:"ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;",lights_toon_pars_fragment:"varying vec3 vViewPosition;\nstruct ToonMaterial {\n\tvec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon",lights_phong_fragment:"BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;",lights_phong_pars_fragment:"varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n\tvec3 diffuseColor;\n\tvec3 specularColor;\n\tfloat specularShininess;\n\tfloat specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong",lights_physical_fragment:"PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n\tmaterial.ior = ior;\n\t#ifdef USE_SPECULAR\n\t\tfloat specularIntensityFactor = specularIntensity;\n\t\tvec3 specularColorFactor = specularColor;\n\t\t#ifdef USE_SPECULAR_COLORMAP\n\t\t\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n\t\t#endif\n\t\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\t\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n\t\t#endif\n\t\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n\t#else\n\t\tfloat specularIntensityFactor = 1.0;\n\t\tvec3 specularColorFactor = vec3( 1.0 );\n\t\tmaterial.specularF90 = 1.0;\n\t#endif\n\tmaterial.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n\tmaterial.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\tmaterial.clearcoatF0 = vec3( 0.04 );\n\tmaterial.clearcoatF90 = 1.0;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_DISPERSION\n\tmaterial.dispersion = dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tmaterial.iridescence = iridescence;\n\tmaterial.iridescenceIOR = iridescenceIOR;\n\t#ifdef USE_IRIDESCENCEMAP\n\t\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n\t#endif\n\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\t\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n\t#else\n\t\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\n\t#endif\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheenColor;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n\t#endif\n\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\t#ifdef USE_ANISOTROPYMAP\n\t\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n\t\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n\t\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n\t#else\n\t\tvec2 anisotropyV = anisotropyVector;\n\t#endif\n\tmaterial.anisotropy = length( anisotropyV );\n\tif( material.anisotropy == 0.0 ) {\n\t\tanisotropyV = vec2( 1.0, 0.0 );\n\t} else {\n\t\tanisotropyV /= material.anisotropy;\n\t\tmaterial.anisotropy = saturate( material.anisotropy );\n\t}\n\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\n\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\n#endif",lights_physical_pars_fragment:"uniform sampler2D dfgLUT;\nstruct PhysicalMaterial {\n\tvec3 diffuseColor;\n\tfloat roughness;\n\tvec3 specularColor;\n\tfloat specularF90;\n\tfloat dispersion;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat clearcoat;\n\t\tfloat clearcoatRoughness;\n\t\tvec3 clearcoatF0;\n\t\tfloat clearcoatF90;\n\t#endif\n\t#ifdef USE_IRIDESCENCE\n\t\tfloat iridescence;\n\t\tfloat iridescenceIOR;\n\t\tfloat iridescenceThickness;\n\t\tvec3 iridescenceFresnel;\n\t\tvec3 iridescenceF0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tvec3 sheenColor;\n\t\tfloat sheenRoughness;\n\t#endif\n\t#ifdef IOR\n\t\tfloat ior;\n\t#endif\n\t#ifdef USE_TRANSMISSION\n\t\tfloat transmission;\n\t\tfloat transmissionAlpha;\n\t\tfloat thickness;\n\t\tfloat attenuationDistance;\n\t\tvec3 attenuationColor;\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat anisotropy;\n\t\tfloat alphaT;\n\t\tvec3 anisotropyT;\n\t\tvec3 anisotropyB;\n\t#endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n\tfloat V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n\t\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n\t\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n\t\tfloat v = 0.5 / ( gv + gl );\n\t\treturn saturate(v);\n\t}\n\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n\t\tfloat a2 = alphaT * alphaB;\n\t\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n\t\thighp float v2 = dot( v, v );\n\t\tfloat w2 = a2 / v2;\n\t\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\n\t}\n#endif\n#ifdef USE_CLEARCOAT\n\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n\t\tvec3 f0 = material.clearcoatF0;\n\t\tfloat f90 = material.clearcoatF90;\n\t\tfloat roughness = material.clearcoatRoughness;\n\t\tfloat alpha = pow2( roughness );\n\t\tvec3 halfDir = normalize( lightDir + viewDir );\n\t\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\t\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\t\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\t\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\t\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t\treturn F * ( V * D );\n\t}\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 f0 = material.specularColor;\n\tfloat f90 = material.specularF90;\n\tfloat roughness = material.roughness;\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\n\tvec3 F = F_Schlick( f0, f90, dotVH );\n\t#ifdef USE_IRIDESCENCE\n\t\tF = mix( F, material.iridescenceFresnel, material.iridescence );\n\t#endif\n\t#ifdef USE_ANISOTROPY\n\t\tfloat dotTL = dot( material.anisotropyT, lightDir );\n\t\tfloat dotTV = dot( material.anisotropyT, viewDir );\n\t\tfloat dotTH = dot( material.anisotropyT, halfDir );\n\t\tfloat dotBL = dot( material.anisotropyB, lightDir );\n\t\tfloat dotBV = dot( material.anisotropyB, viewDir );\n\t\tfloat dotBH = dot( material.anisotropyB, halfDir );\n\t\tfloat V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n\t\tfloat D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n\t#else\n\t\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\t\tfloat D = D_GGX( alpha, dotNH );\n\t#endif\n\treturn F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transpose( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n\tfloat alpha = pow2( roughness );\n\tfloat invAlpha = 1.0 / alpha;\n\tfloat cos2h = dotNH * dotNH;\n\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\n\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n\tvec3 halfDir = normalize( lightDir + viewDir );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat D = D_Charlie( sheenRoughness, dotNH );\n\tfloat V = V_Neubelt( dotNV, dotNL );\n\treturn sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat r2 = roughness * roughness;\n\tfloat a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n\tfloat b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n\tfloat DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n\treturn saturate( DG * RECIPROCAL_PI );\n}\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 uv = vec2( roughness, dotNV );\n\treturn texture2D( dfgLUT, uv ).rg;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\treturn specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n\tvec2 fab = DFGApprox( normal, viewDir, roughness );\n\t#ifdef USE_IRIDESCENCE\n\t\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n\t#else\n\t\tvec3 Fr = specularColor;\n\t#endif\n\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n\tfloat Ess = fab.x + fab.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nvec3 BRDF_GGX_Multiscatter( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n\tvec3 singleScatter = BRDF_GGX( lightDir, viewDir, normal, material );\n\tfloat dotNL = saturate( dot( normal, lightDir ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 dfgV = DFGApprox( vec3(0.0, 0.0, 1.0), vec3(sqrt(1.0 - dotNV * dotNV), 0.0, dotNV), material.roughness );\n\tvec2 dfgL = DFGApprox( vec3(0.0, 0.0, 1.0), vec3(sqrt(1.0 - dotNL * dotNL), 0.0, dotNL), material.roughness );\n\tvec3 FssEss_V = material.specularColor * dfgV.x + material.specularF90 * dfgV.y;\n\tvec3 FssEss_L = material.specularColor * dfgL.x + material.specularF90 * dfgL.y;\n\tfloat Ess_V = dfgV.x + dfgV.y;\n\tfloat Ess_L = dfgL.x + dfgL.y;\n\tfloat Ems_V = 1.0 - Ess_V;\n\tfloat Ems_L = 1.0 - Ess_L;\n\tvec3 Favg = material.specularColor + ( 1.0 - material.specularColor ) * 0.047619;\n\tvec3 Fms = FssEss_V * FssEss_L * Favg / ( 1.0 - Ems_V * Ems_L * Favg * Favg + EPSILON );\n\tfloat compensationFactor = Ems_V * Ems_L;\n\tvec3 multiScatter = Fms * compensationFactor;\n\treturn singleScatter + multiScatter;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometryNormal;\n\t\tvec3 viewDir = geometryViewDir;\n\t\tvec3 position = geometryPosition;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.roughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = dotNLcc * directLight.color;\n\t\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n\t#endif\n\treflectedLight.directSpecular += irradiance * BRDF_GGX_Multiscatter( directLight.direction, geometryViewDir, geometryNormal, material );\n\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n\t#endif\n\t#ifdef USE_SHEEN\n\t\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n\t#endif\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\t#ifdef USE_IRIDESCENCE\n\t\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\n\t#else\n\t\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n\t#endif\n\tvec3 totalScattering = singleScattering + multiScattering;\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );\n\treflectedLight.indirectSpecular += radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}",lights_fragment_begin:"\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n\tgeometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\n\tif ( material.iridescenceThickness == 0.0 ) {\n\t\tmaterial.iridescence = 0.0;\n\t} else {\n\t\tmaterial.iridescence = saturate( material.iridescence );\n\t}\n\tif ( material.iridescence > 0.0 ) {\n\t\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n\t\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n\t}\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointLightInfo( pointLight, geometryPosition, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\tvec4 spotColor;\n\tvec3 spotLightCoord;\n\tbool inSpotLightMap;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\n\t\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n\t\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n\t\t#else\n\t\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n\t\t#endif\n\t\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n\t\t\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n\t\t\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n\t\t\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n\t\t\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n\t\t#endif\n\t\t#undef SPOT_LIGHT_MAP_INDEX\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalLightInfo( directionalLight, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\t#if defined( USE_LIGHT_PROBES )\n\t\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n\t#endif\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif",lights_fragment_maps:"#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getIBLIrradiance( geometryNormal );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\t#ifdef USE_ANISOTROPY\n\t\tradiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n\t#else\n\t\tradiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n\t#endif\n#endif",lights_fragment_end:"#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif",logdepthbuf_fragment:"#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\tgl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif",logdepthbuf_pars_fragment:"#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_pars_vertex:"#ifdef USE_LOGARITHMIC_DEPTH_BUFFER\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif",logdepthbuf_vertex:"#ifdef USE_LOGARITHMIC_DEPTH_BUFFER\n\tvFragDepth = 1.0 + gl_Position.w;\n\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n#endif",map_fragment:"#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif",map_pars_fragment:"#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif",map_particle_fragment:"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t#if defined( USE_POINTS_UV )\n\t\tvec2 uv = vUv;\n\t#else\n\t\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tdiffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif",map_particle_pars_fragment:"#if defined( USE_POINTS_UV )\n\tvarying vec2 vUv;\n#else\n\t#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\t\tuniform mat3 uvTransform;\n\t#endif\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif",metalnessmap_fragment:"float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif",metalnessmap_pars_fragment:"#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif",morphinstance_vertex:"#ifdef USE_INSTANCING_MORPH\n\tfloat morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\n\t}\n#endif",morphcolor_vertex:"#if defined( USE_MORPHCOLORS )\n\tvColor *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\t#if defined( USE_COLOR_ALPHA )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n\t\t#elif defined( USE_COLOR )\n\t\t\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n\t\t#endif\n\t}\n#endif",morphnormal_vertex:"#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",morphtarget_pars_vertex:"#ifdef USE_MORPHTARGETS\n\t#ifndef USE_INSTANCING_MORPH\n\t\tuniform float morphTargetBaseInfluence;\n\t\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n\t#endif\n\tuniform sampler2DArray morphTargetsTexture;\n\tuniform ivec2 morphTargetsTextureSize;\n\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n\t\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n\t\tint y = texelIndex / morphTargetsTextureSize.x;\n\t\tint x = texelIndex - y * morphTargetsTextureSize.x;\n\t\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\n\t\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\n\t}\n#endif",morphtarget_vertex:"#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n\t\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n\t}\n#endif",normal_fragment_begin:"float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n\tvec3 fdx = dFdx( vViewPosition );\n\tvec3 fdy = dFdy( vViewPosition );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal *= faceDirection;\n\t#endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn = getTangentFrame( - vViewPosition, normal,\n\t\t#if defined( USE_NORMALMAP )\n\t\t\tvNormalMapUv\n\t\t#elif defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tvClearcoatNormalMapUv\n\t\t#else\n\t\t\tvUv\n\t\t#endif\n\t\t);\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn[0] *= faceDirection;\n\t\ttbn[1] *= faceDirection;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\t#ifdef USE_TANGENT\n\t\tmat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n\t#else\n\t\tmat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n\t#endif\n\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n\t\ttbn2[0] *= faceDirection;\n\t\ttbn2[1] *= faceDirection;\n\t#endif\n#endif\nvec3 nonPerturbedNormal = normal;",normal_fragment_maps:"#ifdef USE_NORMALMAP_OBJECTSPACE\n\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * faceDirection;\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\tnormal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif",normal_pars_fragment:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_pars_vertex:"#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif",normal_vertex:"#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif",normalmap_pars_fragment:"#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef USE_NORMALMAP_OBJECTSPACE\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n\tmat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n\t\tvec3 q0 = dFdx( eye_pos.xyz );\n\t\tvec3 q1 = dFdy( eye_pos.xyz );\n\t\tvec2 st0 = dFdx( uv.st );\n\t\tvec2 st1 = dFdy( uv.st );\n\t\tvec3 N = surf_norm;\n\t\tvec3 q1perp = cross( q1, N );\n\t\tvec3 q0perp = cross( N, q0 );\n\t\tvec3 T = q1perp * st0.x + q0perp * st1.x;\n\t\tvec3 B = q1perp * st0.y + q0perp * st1.y;\n\t\tfloat det = max( dot( T, T ), dot( B, B ) );\n\t\tfloat scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n\t\treturn mat3( T * scale, B * scale, N );\n\t}\n#endif",clearcoat_normal_fragment_begin:"#ifdef USE_CLEARCOAT\n\tvec3 clearcoatNormal = nonPerturbedNormal;\n#endif",clearcoat_normal_fragment_maps:"#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\tclearcoatNormal = normalize( tbn2 * clearcoatMapN );\n#endif",clearcoat_pars_fragment:"#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif",iridescence_pars_fragment:"#ifdef USE_IRIDESCENCEMAP\n\tuniform sampler2D iridescenceMap;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform sampler2D iridescenceThicknessMap;\n#endif",opaque_fragment:"#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );",packing:"vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\nconst float Inv255 = 1. / 255.;\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\nvec4 packDepthToRGBA( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec4( 0., 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec4( 1., 1., 1., 1. );\n\tfloat vuf;\n\tfloat af = modf( v * PackFactors.a, vuf );\n\tfloat bf = modf( vuf * ShiftRight8, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\n}\nvec3 packDepthToRGB( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec3( 0., 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec3( 1., 1., 1. );\n\tfloat vuf;\n\tfloat bf = modf( v * PackFactors.b, vuf );\n\tfloat gf = modf( vuf * ShiftRight8, vuf );\n\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\n}\nvec2 packDepthToRG( const in float v ) {\n\tif( v <= 0.0 )\n\t\treturn vec2( 0., 0. );\n\tif( v >= 1.0 )\n\t\treturn vec2( 1., 1. );\n\tfloat vuf;\n\tfloat gf = modf( v * 256., vuf );\n\treturn vec2( vuf * Inv255, gf );\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors4 );\n}\nfloat unpackRGBToDepth( const in vec3 v ) {\n\treturn dot( v, UnpackFactors3 );\n}\nfloat unpackRGToDepth( const in vec2 v ) {\n\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\n}\nvec4 pack2HalfToRGBA( const in vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( const in vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn depth * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * depth - far );\n}",premultiplied_alpha_fragment:"#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif",project_vertex:"vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_BATCHING\n\tmvPosition = batchingMatrix * mvPosition;\n#endif\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;",dithering_fragment:"#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif",dithering_pars_fragment:"#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif",roughnessmap_fragment:"float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n\troughnessFactor *= texelRoughness.g;\n#endif",roughnessmap_pars_fragment:"#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif",shadowmap_pars_fragment:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\tfloat depth = unpackRGBAToDepth( texture2D( depths, uv ) );\n\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\treturn step( depth, compare );\n\t\t#else\n\t\t\treturn step( compare, depth );\n\t\t#endif\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow( sampler2D shadow, vec2 uv, float compare ) {\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\t\tfloat hard_shadow = step( distribution.x, compare );\n\t\t#else\n\t\t\tfloat hard_shadow = step( compare, distribution.x );\n\t\t#endif\n\t\tif ( hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n\t\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tfloat shadow = 1.0;\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\t\n\t\tfloat lightToPositionLength = length( lightToPosition );\n\t\tif ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {\n\t\t\tfloat dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\t\tdp += shadowBias;\n\t\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\t\tshadow = (\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t\t) * ( 1.0 / 9.0 );\n\t\t\t#else\n\t\t\t\tshadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t\t#endif\n\t\t}\n\t\treturn mix( 1.0, shadow, shadowIntensity );\n\t}\n#endif",shadowmap_pars_vertex:"#if NUM_SPOT_LIGHT_COORDS > 0\n\tuniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowIntensity;\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowNormalBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif",shadowmap_vertex:"#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\tvec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\t\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n\t\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n\t\tshadowWorldPosition = worldPosition;\n\t\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\t\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n\t\t#endif\n\t\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n\t}\n\t#pragma unroll_loop_end\n#endif",shadowmask_pars_fragment:"float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}",skinbase_vertex:"#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif",skinning_pars_vertex:"#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\tuniform highp sampler2D boneTexture;\n\tmat4 getBoneMatrix( const in float i ) {\n\t\tint size = textureSize( boneTexture, 0 ).x;\n\t\tint j = int( i ) * 4;\n\t\tint x = j % size;\n\t\tint y = j / size;\n\t\tvec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\n\t\tvec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\n\t\tvec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\n\t\tvec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\n\t\treturn mat4( v1, v2, v3, v4 );\n\t}\n#endif",skinning_vertex:"#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif",skinnormal_vertex:"#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif",specularmap_fragment:"float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif",specularmap_pars_fragment:"#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif",tonemapping_fragment:"#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif",tonemapping_pars_fragment:"#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 CineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n\treturn a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tconst mat3 ACESInputMat = mat3(\n\t\tvec3( 0.59719, 0.07600, 0.02840 ),\t\tvec3( 0.35458, 0.90834, 0.13383 ),\n\t\tvec3( 0.04823, 0.01566, 0.83777 )\n\t);\n\tconst mat3 ACESOutputMat = mat3(\n\t\tvec3( 1.60475, -0.10208, -0.00327 ),\t\tvec3( -0.53108, 1.10813, -0.07276 ),\n\t\tvec3( -0.07367, -0.00605, 1.07602 )\n\t);\n\tcolor *= toneMappingExposure / 0.6;\n\tcolor = ACESInputMat * color;\n\tcolor = RRTAndODTFit( color );\n\tcolor = ACESOutputMat * color;\n\treturn saturate( color );\n}\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.6605, - 0.1246, - 0.0182 ),\n\tvec3( - 0.5876, 1.1329, - 0.1006 ),\n\tvec3( - 0.0728, - 0.0083, 1.1187 )\n);\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\n\tvec3( 0.6274, 0.0691, 0.0164 ),\n\tvec3( 0.3293, 0.9195, 0.0880 ),\n\tvec3( 0.0433, 0.0113, 0.8956 )\n);\nvec3 agxDefaultContrastApprox( vec3 x ) {\n\tvec3 x2 = x * x;\n\tvec3 x4 = x2 * x2;\n\treturn + 15.5 * x4 * x2\n\t\t- 40.14 * x4 * x\n\t\t+ 31.96 * x4\n\t\t- 6.868 * x2 * x\n\t\t+ 0.4298 * x2\n\t\t+ 0.1191 * x\n\t\t- 0.00232;\n}\nvec3 AgXToneMapping( vec3 color ) {\n\tconst mat3 AgXInsetMatrix = mat3(\n\t\tvec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\n\t\tvec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\n\t\tvec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\n\t);\n\tconst mat3 AgXOutsetMatrix = mat3(\n\t\tvec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\n\t\tvec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\n\t\tvec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\n\t);\n\tconst float AgxMinEv = - 12.47393;\tconst float AgxMaxEv = 4.026069;\n\tcolor *= toneMappingExposure;\n\tcolor = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\n\tcolor = AgXInsetMatrix * color;\n\tcolor = max( color, 1e-10 );\tcolor = log2( color );\n\tcolor = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\n\tcolor = clamp( color, 0.0, 1.0 );\n\tcolor = agxDefaultContrastApprox( color );\n\tcolor = AgXOutsetMatrix * color;\n\tcolor = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\n\tcolor = LINEAR_REC2020_TO_LINEAR_SRGB * color;\n\tcolor = clamp( color, 0.0, 1.0 );\n\treturn color;\n}\nvec3 NeutralToneMapping( vec3 color ) {\n\tconst float StartCompression = 0.8 - 0.04;\n\tconst float Desaturation = 0.15;\n\tcolor *= toneMappingExposure;\n\tfloat x = min( color.r, min( color.g, color.b ) );\n\tfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\n\tcolor -= offset;\n\tfloat peak = max( color.r, max( color.g, color.b ) );\n\tif ( peak < StartCompression ) return color;\n\tfloat d = 1. - StartCompression;\n\tfloat newPeak = 1. - d * d / ( peak + d - StartCompression );\n\tcolor *= newPeak / peak;\n\tfloat g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\n\treturn mix( color, vec3( newPeak ), g );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }",transmission_fragment:"#ifdef USE_TRANSMISSION\n\tmaterial.transmission = transmission;\n\tmaterial.transmissionAlpha = 1.0;\n\tmaterial.thickness = thickness;\n\tmaterial.attenuationDistance = attenuationDistance;\n\tmaterial.attenuationColor = attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n\t#endif\n\tvec3 pos = vWorldPosition;\n\tvec3 v = normalize( cameraPosition - pos );\n\tvec3 n = inverseTransformDirection( normal, viewMatrix );\n\tvec4 transmitted = getIBLVolumeRefraction(\n\t\tn, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n\t\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\n\t\tmaterial.attenuationColor, material.attenuationDistance );\n\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif",transmission_pars_fragment:"#ifdef USE_TRANSMISSION\n\tuniform float transmission;\n\tuniform float thickness;\n\tuniform float attenuationDistance;\n\tuniform vec3 attenuationColor;\n\t#ifdef USE_TRANSMISSIONMAP\n\t\tuniform sampler2D transmissionMap;\n\t#endif\n\t#ifdef USE_THICKNESSMAP\n\t\tuniform sampler2D thicknessMap;\n\t#endif\n\tuniform vec2 transmissionSamplerSize;\n\tuniform sampler2D transmissionSamplerMap;\n\tuniform mat4 modelMatrix;\n\tuniform mat4 projectionMatrix;\n\tvarying vec3 vWorldPosition;\n\tfloat w0( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n\t}\n\tfloat w1( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n\t}\n\tfloat w2( float a ){\n\t\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n\t}\n\tfloat w3( float a ) {\n\t\treturn ( 1.0 / 6.0 ) * ( a * a * a );\n\t}\n\tfloat g0( float a ) {\n\t\treturn w0( a ) + w1( a );\n\t}\n\tfloat g1( float a ) {\n\t\treturn w2( a ) + w3( a );\n\t}\n\tfloat h0( float a ) {\n\t\treturn - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n\t}\n\tfloat h1( float a ) {\n\t\treturn 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n\t}\n\tvec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n\t\tuv = uv * texelSize.zw + 0.5;\n\t\tvec2 iuv = floor( uv );\n\t\tvec2 fuv = fract( uv );\n\t\tfloat g0x = g0( fuv.x );\n\t\tfloat g1x = g1( fuv.x );\n\t\tfloat h0x = h0( fuv.x );\n\t\tfloat h1x = h1( fuv.x );\n\t\tfloat h0y = h0( fuv.y );\n\t\tfloat h1y = h1( fuv.y );\n\t\tvec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\tvec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n\t\treturn g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n\t\t\tg1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n\t}\n\tvec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n\t\tvec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n\t\tvec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n\t\tvec2 fLodSizeInv = 1.0 / fLodSize;\n\t\tvec2 cLodSizeInv = 1.0 / cLodSize;\n\t\tvec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n\t\tvec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n\t\treturn mix( fSample, cSample, fract( lod ) );\n\t}\n\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n\t\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n\t\tvec3 modelScale;\n\t\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n\t\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n\t\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n\t\treturn normalize( refractionVector ) * thickness * modelScale;\n\t}\n\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\n\t\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n\t}\n\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n\t\tfloat lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n\t\treturn textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n\t}\n\tvec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tif ( isinf( attenuationDistance ) ) {\n\t\t\treturn vec3( 1.0 );\n\t\t} else {\n\t\t\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n\t\t\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\t\t\treturn transmittance;\n\t\t}\n\t}\n\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n\t\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n\t\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\n\t\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\n\t\tvec4 transmittedLight;\n\t\tvec3 transmittance;\n\t\t#ifdef USE_DISPERSION\n\t\t\tfloat halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\n\t\t\tvec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\n\t\t\tfor ( int i = 0; i < 3; i ++ ) {\n\t\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\n\t\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\t\trefractionCoords += 1.0;\n\t\t\t\trefractionCoords /= 2.0;\n\t\t\t\tvec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\n\t\t\t\ttransmittedLight[ i ] = transmissionSample[ i ];\n\t\t\t\ttransmittedLight.a += transmissionSample.a;\n\t\t\t\ttransmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\n\t\t\t}\n\t\t\ttransmittedLight.a /= 3.0;\n\t\t#else\n\t\t\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n\t\t\tvec3 refractedRayExit = position + transmissionRay;\n\t\t\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n\t\t\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\n\t\t\trefractionCoords += 1.0;\n\t\t\trefractionCoords /= 2.0;\n\t\t\ttransmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n\t\t\ttransmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n\t\t#endif\n\t\tvec3 attenuatedColor = transmittance * transmittedLight.rgb;\n\t\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n\t\tfloat transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n\t\treturn vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n\t}\n#endif",uv_pars_fragment:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_pars_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvarying vec2 vUv;\n#endif\n#ifdef USE_MAP\n\tuniform mat3 mapTransform;\n\tvarying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform mat3 alphaMapTransform;\n\tvarying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n\tuniform mat3 lightMapTransform;\n\tvarying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n\tuniform mat3 aoMapTransform;\n\tvarying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n\tuniform mat3 bumpMapTransform;\n\tvarying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n\tuniform mat3 normalMapTransform;\n\tvarying vec2 vNormalMapUv;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tuniform mat3 displacementMapTransform;\n\tvarying vec2 vDisplacementMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tuniform mat3 emissiveMapTransform;\n\tvarying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n\tuniform mat3 metalnessMapTransform;\n\tvarying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tuniform mat3 roughnessMapTransform;\n\tvarying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tuniform mat3 anisotropyMapTransform;\n\tvarying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tuniform mat3 clearcoatMapTransform;\n\tvarying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform mat3 clearcoatNormalMapTransform;\n\tvarying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform mat3 clearcoatRoughnessMapTransform;\n\tvarying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tuniform mat3 sheenColorMapTransform;\n\tvarying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tuniform mat3 sheenRoughnessMapTransform;\n\tvarying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tuniform mat3 iridescenceMapTransform;\n\tvarying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tuniform mat3 iridescenceThicknessMapTransform;\n\tvarying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n\tuniform mat3 specularMapTransform;\n\tvarying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tuniform mat3 specularColorMapTransform;\n\tvarying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tuniform mat3 specularIntensityMapTransform;\n\tvarying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tuniform mat3 transmissionMapTransform;\n\tvarying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n\tuniform mat3 thicknessMapTransform;\n\tvarying vec2 vThicknessMapUv;\n#endif",uv_vertex:"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n\tvUv = vec3( uv, 1 ).xy;\n#endif\n#ifdef USE_MAP\n\tvMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ALPHAMAP\n\tvAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_LIGHTMAP\n\tvLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_AOMAP\n\tvAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_BUMPMAP\n\tvBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_NORMALMAP\n\tvNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n\tvDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_EMISSIVEMAP\n\tvEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_METALNESSMAP\n\tvMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ROUGHNESSMAP\n\tvRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ANISOTROPYMAP\n\tvAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOATMAP\n\tvClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tvClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tvClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n\tvIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n\tvIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n\tvSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n\tvSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULARMAP\n\tvSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n\tvSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n\tvSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n\tvTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_THICKNESSMAP\n\tvThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n#endif",worldpos_vertex:"#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_BATCHING\n\t\tworldPosition = batchingMatrix * worldPosition;\n\t#endif\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif",background_vert:"varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}",background_frag:"uniform sampler2D t2D;\nuniform float backgroundIntensity;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\ttexColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include \n\t#include \n}",backgroundCube_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n\tgl_Position.z = gl_Position.w;\n}",backgroundCube_frag:"#ifdef ENVMAP_TYPE_CUBE\n\tuniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n\tuniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nuniform mat3 backgroundRotation;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );\n\t#else\n\t\tvec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t#endif\n\ttexColor.rgb *= backgroundIntensity;\n\tgl_FragColor = texColor;\n\t#include \n\t#include \n}",cube_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n\tgl_Position.z = gl_Position.w;\n}",cube_frag:"uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n\tgl_FragColor = texColor;\n\tgl_FragColor.a *= opacity;\n\t#include \n\t#include \n}",depth_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvHighPrecisionZW = gl_Position.zw;\n}",depth_frag:"#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include \n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_REVERSED_DEPTH_BUFFER\n\t\tfloat fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ];\n\t#else\n\t\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5;\n\t#endif\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#elif DEPTH_PACKING == 3202\n\t\tgl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );\n\t#elif DEPTH_PACKING == 3203\n\t\tgl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );\n\t#endif\n}",distanceRGBA_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvWorldPosition = worldPosition.xyz;\n}",distanceRGBA_frag:"#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main () {\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}",equirect_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n}",equirect_frag:"uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV = equirectUv( direction );\n\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\t#include \n\t#include \n}",linedashed_vert:"uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",linedashed_frag:"uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshbasic_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n\t\t#include \n\t\t#include \n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshbasic_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n\t\treflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include \n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshlambert_vert:"#define LAMBERT\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n\t#include \n}",meshlambert_frag:"#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n}",meshmatcap_frag:"#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t#else\n\t\tvec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshnormal_vert:"#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}",meshnormal_frag:"#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n\tvarying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\tgl_FragColor = vec4( packNormalToRGB( normal ), diffuseColor.a );\n\t#ifdef OPAQUE\n\t\tgl_FragColor.a = 1.0;\n\t#endif\n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n\t#include \n}",meshphong_frag:"#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshphysical_vert:"#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n\tvarying vec3 vWorldPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n#ifdef USE_TRANSMISSION\n\tvWorldPosition = worldPosition.xyz;\n#endif\n}",meshphysical_frag:"#define STANDARD\n#ifdef PHYSICAL\n\t#define IOR\n\t#define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n\tuniform float ior;\n#endif\n#ifdef USE_SPECULAR\n\tuniform float specularIntensity;\n\tuniform vec3 specularColor;\n\t#ifdef USE_SPECULAR_COLORMAP\n\t\tuniform sampler2D specularColorMap;\n\t#endif\n\t#ifdef USE_SPECULAR_INTENSITYMAP\n\t\tuniform sampler2D specularIntensityMap;\n\t#endif\n#endif\n#ifdef USE_CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_DISPERSION\n\tuniform float dispersion;\n#endif\n#ifdef USE_IRIDESCENCE\n\tuniform float iridescence;\n\tuniform float iridescenceIOR;\n\tuniform float iridescenceThicknessMinimum;\n\tuniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheenColor;\n\tuniform float sheenRoughness;\n\t#ifdef USE_SHEEN_COLORMAP\n\t\tuniform sampler2D sheenColorMap;\n\t#endif\n\t#ifdef USE_SHEEN_ROUGHNESSMAP\n\t\tuniform sampler2D sheenRoughnessMap;\n\t#endif\n#endif\n#ifdef USE_ANISOTROPY\n\tuniform vec2 anisotropyVector;\n\t#ifdef USE_ANISOTROPYMAP\n\t\tuniform sampler2D anisotropyMap;\n\t#endif\n#endif\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n\tvec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n\t#include \n\tvec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n\t#ifdef USE_SHEEN\n\t\tfloat sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n\t\toutgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;\n\t#endif\n\t#ifdef USE_CLEARCOAT\n\t\tfloat dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n\t\tvec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n\t\toutgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n}",meshtoon_frag:"#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",points_vert:"uniform float size;\nuniform float scale;\n#include \n#include \n#include \n#include \n#include \n#include \n#ifdef USE_POINTS_UV\n\tvarying vec2 vUv;\n\tuniform mat3 uvTransform;\n#endif\nvoid main() {\n\t#ifdef USE_POINTS_UV\n\t\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n}",points_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",shadow_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",shadow_frag:"uniform vec3 color;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include \n\t#include \n\t#include \n}",sprite_vert:"uniform float rotation;\nuniform vec2 center;\n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec4 mvPosition = modelViewMatrix[ 3 ];\n\tvec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include \n\t#include \n\t#include \n}",sprite_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\t#include \n\t#include \n\t#include \n\t#include \n}"},ju={common:{diffuse:{value:new Sl(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new ka},alphaMap:{value:null},alphaMapTransform:{value:new ka},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new ka}},envmap:{envMap:{value:null},envMapRotation:{value:new ka},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new ka}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new ka}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new ka},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new ka},normalScale:{value:new La(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new ka},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new ka}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new ka}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new ka}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Sl(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new Sl(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new ka},alphaTest:{value:0},uvTransform:{value:new ka}},sprite:{diffuse:{value:new Sl(16777215)},opacity:{value:1},center:{value:new La(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new ka},alphaMap:{value:null},alphaMapTransform:{value:new ka},alphaTest:{value:0}}},Xu={basic:{uniforms:sc([ju.common,ju.specularmap,ju.envmap,ju.aomap,ju.lightmap,ju.fog]),vertexShader:Wu.meshbasic_vert,fragmentShader:Wu.meshbasic_frag},lambert:{uniforms:sc([ju.common,ju.specularmap,ju.envmap,ju.aomap,ju.lightmap,ju.emissivemap,ju.bumpmap,ju.normalmap,ju.displacementmap,ju.fog,ju.lights,{emissive:{value:new Sl(0)}}]),vertexShader:Wu.meshlambert_vert,fragmentShader:Wu.meshlambert_frag},phong:{uniforms:sc([ju.common,ju.specularmap,ju.envmap,ju.aomap,ju.lightmap,ju.emissivemap,ju.bumpmap,ju.normalmap,ju.displacementmap,ju.fog,ju.lights,{emissive:{value:new Sl(0)},specular:{value:new Sl(1118481)},shininess:{value:30}}]),vertexShader:Wu.meshphong_vert,fragmentShader:Wu.meshphong_frag},standard:{uniforms:sc([ju.common,ju.envmap,ju.aomap,ju.lightmap,ju.emissivemap,ju.bumpmap,ju.normalmap,ju.displacementmap,ju.roughnessmap,ju.metalnessmap,ju.fog,ju.lights,{emissive:{value:new Sl(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Wu.meshphysical_vert,fragmentShader:Wu.meshphysical_frag},toon:{uniforms:sc([ju.common,ju.aomap,ju.lightmap,ju.emissivemap,ju.bumpmap,ju.normalmap,ju.displacementmap,ju.gradientmap,ju.fog,ju.lights,{emissive:{value:new Sl(0)}}]),vertexShader:Wu.meshtoon_vert,fragmentShader:Wu.meshtoon_frag},matcap:{uniforms:sc([ju.common,ju.bumpmap,ju.normalmap,ju.displacementmap,ju.fog,{matcap:{value:null}}]),vertexShader:Wu.meshmatcap_vert,fragmentShader:Wu.meshmatcap_frag},points:{uniforms:sc([ju.points,ju.fog]),vertexShader:Wu.points_vert,fragmentShader:Wu.points_frag},dashed:{uniforms:sc([ju.common,ju.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Wu.linedashed_vert,fragmentShader:Wu.linedashed_frag},depth:{uniforms:sc([ju.common,ju.displacementmap]),vertexShader:Wu.depth_vert,fragmentShader:Wu.depth_frag},normal:{uniforms:sc([ju.common,ju.bumpmap,ju.normalmap,ju.displacementmap,{opacity:{value:1}}]),vertexShader:Wu.meshnormal_vert,fragmentShader:Wu.meshnormal_frag},sprite:{uniforms:sc([ju.sprite,ju.fog]),vertexShader:Wu.sprite_vert,fragmentShader:Wu.sprite_frag},background:{uniforms:{uvTransform:{value:new ka},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Wu.background_vert,fragmentShader:Wu.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new ka}},vertexShader:Wu.backgroundCube_vert,fragmentShader:Wu.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Wu.cube_vert,fragmentShader:Wu.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Wu.equirect_vert,fragmentShader:Wu.equirect_frag},distanceRGBA:{uniforms:sc([ju.common,ju.displacementmap,{referencePosition:{value:new Da},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Wu.distanceRGBA_vert,fragmentShader:Wu.distanceRGBA_frag},shadow:{uniforms:sc([ju.lights,ju.fog,{color:{value:new Sl(0)},opacity:{value:1}}]),vertexShader:Wu.shadow_vert,fragmentShader:Wu.shadow_frag}};Xu.physical={uniforms:sc([Xu.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new ka},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new ka},clearcoatNormalScale:{value:new La(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new ka},dispersion:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new ka},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new ka},sheen:{value:0},sheenColor:{value:new Sl(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new ka},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new ka},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new ka},transmissionSamplerSize:{value:new La},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new ka},attenuationDistance:{value:0},attenuationColor:{value:new Sl(0)},specularColor:{value:new Sl(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new ka},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new ka},anisotropyVector:{value:new La},anisotropyMap:{value:null},anisotropyMapTransform:{value:new ka}}]),vertexShader:Wu.meshphysical_vert,fragmentShader:Wu.meshphysical_frag};const $u={r:0,b:0,g:0},qu=new Ho,Yu=new Lo;function Zu(t,e,n,i,r,s,a){const o=new Sl(0);let l,c,u=!0===s?0:1,h=null,d=0,p=null;function f(t){let i=!0===t.isScene?t.background:null;return i&&i.isTexture&&(i=(t.backgroundBlurriness>0?n:e).get(i)),i}function m(e,n){e.getRGB($u,ac(t)),i.buffers.color.setClear($u.r,$u.g,$u.b,n,a)}return{getClearColor:function(){return o},setClearColor:function(t,e=1){o.set(t),u=e,m(o,u)},getClearAlpha:function(){return u},setClearAlpha:function(t){u=t,m(o,u)},render:function(e){let n=!1;const r=f(e);null===r?m(o,u):r&&r.isColor&&(m(r,1),n=!0);const s=t.xr.getEnvironmentBlendMode();"additive"===s?i.buffers.color.setClear(0,0,0,1,a):"alpha-blend"===s&&i.buffers.color.setClear(0,0,0,0,a),(t.autoClear||n)&&(i.buffers.depth.setTest(!0),i.buffers.depth.setMask(!0),i.buffers.color.setMask(!0),t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil))},addToRenderList:function(e,n){const i=f(n);i&&(i.isCubeTexture||i.mapping===Wr)?(void 0===c&&(c=new ec(new ic(1,1,1),new lc({name:"BackgroundCubeMaterial",uniforms:rc(Xu.backgroundCube.uniforms),vertexShader:Xu.backgroundCube.vertexShader,fragmentShader:Xu.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),c.geometry.deleteAttribute("normal"),c.geometry.deleteAttribute("uv"),c.onBeforeRender=function(t,e,n){this.matrixWorld.copyPosition(n.matrixWorld)},Object.defineProperty(c.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),r.update(c)),qu.copy(n.backgroundRotation),qu.x*=-1,qu.y*=-1,qu.z*=-1,i.isCubeTexture&&!1===i.isRenderTargetTexture&&(qu.y*=-1,qu.z*=-1),c.material.uniforms.envMap.value=i,c.material.uniforms.flipEnvMap.value=i.isCubeTexture&&!1===i.isRenderTargetTexture?-1:1,c.material.uniforms.backgroundBlurriness.value=n.backgroundBlurriness,c.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,c.material.uniforms.backgroundRotation.value.setFromMatrix4(Yu.makeRotationFromEuler(qu)),c.material.toneMapped=Ha.getTransfer(i.colorSpace)!==ea,h===i&&d===i.version&&p===t.toneMapping||(c.material.needsUpdate=!0,h=i,d=i.version,p=t.toneMapping),c.layers.enableAll(),e.unshift(c,c.geometry,c.material,0,0,null)):i&&i.isTexture&&(void 0===l&&(l=new ec(new tu(2,2),new lc({name:"BackgroundMaterial",uniforms:rc(Xu.background.uniforms),vertexShader:Xu.background.vertexShader,fragmentShader:Xu.background.fragmentShader,side:0,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute("normal"),Object.defineProperty(l.material,"map",{get:function(){return this.uniforms.t2D.value}}),r.update(l)),l.material.uniforms.t2D.value=i,l.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,l.material.toneMapped=Ha.getTransfer(i.colorSpace)!==ea,!0===i.matrixAutoUpdate&&i.updateMatrix(),l.material.uniforms.uvTransform.value.copy(i.matrix),h===i&&d===i.version&&p===t.toneMapping||(l.material.needsUpdate=!0,h=i,d=i.version,p=t.toneMapping),l.layers.enableAll(),e.unshift(l,l.geometry,l.material,0,0,null))},dispose:function(){void 0!==c&&(c.geometry.dispose(),c.material.dispose(),c=void 0),void 0!==l&&(l.geometry.dispose(),l.material.dispose(),l=void 0)}}}function Ku(t,e){const n=t.getParameter(t.MAX_VERTEX_ATTRIBS),i={},r=c(null);let s=r,a=!1;function o(e){return t.bindVertexArray(e)}function l(e){return t.deleteVertexArray(e)}function c(t){const e=[],i=[],r=[];for(let t=0;t=0){const n=r[e];let i=a[e];if(void 0===i&&("instanceMatrix"===e&&t.instanceMatrix&&(i=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(i=t.instanceColor)),void 0===n)return!0;if(n.attribute!==i)return!0;if(i&&n.data!==i.data)return!0;o++}return s.attributesNum!==o||s.index!==i}(n,m,l,g),v&&function(t,e,n,i){const r={},a=e.attributes;let o=0;const l=n.getAttributes();for(const e in l)if(l[e].location>=0){let n=a[e];void 0===n&&("instanceMatrix"===e&&t.instanceMatrix&&(n=t.instanceMatrix),"instanceColor"===e&&t.instanceColor&&(n=t.instanceColor));const i={};i.attribute=n,n&&n.data&&(i.data=n.data),r[e]=i,o++}s.attributes=r,s.attributesNum=o,s.index=i}(n,m,l,g),null!==g&&e.update(g,t.ELEMENT_ARRAY_BUFFER),(v||a)&&(a=!1,function(n,i,r,s){u();const a=s.attributes,o=r.getAttributes(),l=i.defaultAttributeValues;for(const i in o){const r=o[i];if(r.location>=0){let o=a[i];if(void 0===o&&("instanceMatrix"===i&&n.instanceMatrix&&(o=n.instanceMatrix),"instanceColor"===i&&n.instanceColor&&(o=n.instanceColor)),void 0!==o){const i=o.normalized,a=o.itemSize,l=e.get(o);if(void 0===l)continue;const c=l.buffer,u=l.type,p=l.bytesPerElement,m=u===t.INT||u===t.UNSIGNED_INT||o.gpuType===ns;if(o.isInterleavedBufferAttribute){const e=o.data,l=e.stride,g=o.offset;if(e.isInstancedInterleavedBuffer){for(let t=0;t0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.HIGH_FLOAT).precision>0)return"highp";e="mediump"}return"mediump"===e&&t.getShaderPrecisionFormat(t.VERTEX_SHADER,t.MEDIUM_FLOAT).precision>0&&t.getShaderPrecisionFormat(t.FRAGMENT_SHADER,t.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}let a=void 0!==n.precision?n.precision:"highp";const o=s(a);o!==a&&(xa("WebGLRenderer:",a,"not supported, using",o,"instead."),a=o);const l=!0===n.logarithmicDepthBuffer,c=!0===n.reversedDepthBuffer&&e.has("EXT_clip_control"),u=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),h=t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS);return{isWebGL2:!0,getMaxAnisotropy:function(){if(void 0!==r)return r;if(!0===e.has("EXT_texture_filter_anisotropic")){const n=e.get("EXT_texture_filter_anisotropic");r=t.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else r=0;return r},getMaxPrecision:s,textureFormatReadable:function(e){return e===cs||i.convert(e)===t.getParameter(t.IMPLEMENTATION_COLOR_READ_FORMAT)},textureTypeReadable:function(n){const r=n===ss&&(e.has("EXT_color_buffer_half_float")||e.has("EXT_color_buffer_float"));return!(n!==ts&&i.convert(n)!==t.getParameter(t.IMPLEMENTATION_COLOR_READ_TYPE)&&n!==rs&&!r)},precision:a,logarithmicDepthBuffer:l,reversedDepthBuffer:c,maxTextures:u,maxVertexTextures:h,maxTextureSize:t.getParameter(t.MAX_TEXTURE_SIZE),maxCubemapSize:t.getParameter(t.MAX_CUBE_MAP_TEXTURE_SIZE),maxAttributes:t.getParameter(t.MAX_VERTEX_ATTRIBS),maxVertexUniforms:t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS),maxVaryings:t.getParameter(t.MAX_VARYING_VECTORS),maxFragmentUniforms:t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS),vertexTextures:h>0,maxSamples:t.getParameter(t.MAX_SAMPLES)}}function th(t){const e=this;let n=null,i=0,r=!1,s=!1;const a=new Tc,o=new ka,l={value:null,needsUpdate:!1};function c(t,n,i,r){const s=null!==t?t.length:0;let c=null;if(0!==s){if(c=l.value,!0!==r||null===c){const e=i+4*s,r=n.matrixWorldInverse;o.getNormalMatrix(r),(null===c||c.length0),e.numPlanes=i,e.numIntersection=0);else{const t=s?0:i,e=4*t;let r=f.clippingState||null;l.value=r,r=c(h,o,e,u);for(let t=0;t!==e;++t)r[t]=n[t];f.clippingState=r,this.numIntersection=d?this.numPlanes:0,this.numPlanes+=t}}}function eh(t){let e=new WeakMap;function n(t,e){return 303===e?t.mapping=Hr:304===e&&(t.mapping=Gr),t}function i(t){const n=t.target;n.removeEventListener("dispose",i);const r=e.get(n);void 0!==r&&(e.delete(n),r.dispose())}return{get:function(r){if(r&&r.isTexture){const s=r.mapping;if(303===s||304===s){if(e.has(r))return n(e.get(r).texture,r.mapping);{const s=r.image;if(s&&s.height>0){const a=new vc(s.height);return a.fromEquirectangularTexture(t,r),e.set(r,a),r.addEventListener("dispose",i),n(a.texture,r.mapping)}return null}}}return r},dispose:function(){e=new WeakMap}}}const nh=[.125,.215,.35,.446,.526,.582],ih=new Mu,rh=new Sl;let sh=null,ah=0,oh=0,lh=!1;const ch=new Da;class uh{constructor(t){this._renderer=t,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._sizeLods=[],this._sigmas=[],this._lodMeshes=[],this._backgroundBox=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null}fromScene(t,e=0,n=.1,i=100,r={}){const{size:s=256,position:a=ch}=r;sh=this._renderer.getRenderTarget(),ah=this._renderer.getActiveCubeFace(),oh=this._renderer.getActiveMipmapLevel(),lh=this._renderer.xr.enabled,this._renderer.xr.enabled=!1,this._setSize(s);const o=this._allocateTargets();return o.depthBuffer=!0,this._sceneToCubeUV(t,n,i,o,a),e>0&&this._blur(o,0,0,e),this._applyPMREM(o),this._cleanup(o),o}fromEquirectangular(t,e=null){return this._fromTexture(t,e)}fromCubemap(t,e=null){return this._fromTexture(t,e)}compileCubemapShader(){null===this._cubemapMaterial&&(this._cubemapMaterial=fh(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){null===this._equirectMaterial&&(this._equirectMaterial=ph(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),null!==this._cubemapMaterial&&this._cubemapMaterial.dispose(),null!==this._equirectMaterial&&this._equirectMaterial.dispose(),null!==this._backgroundBox&&(this._backgroundBox.geometry.dispose(),this._backgroundBox.material.dispose())}_setSize(t){this._lodMax=Math.floor(Math.log2(t)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){null!==this._blurMaterial&&this._blurMaterial.dispose(),null!==this._ggxMaterial&&this._ggxMaterial.dispose(),null!==this._pingPongRenderTarget&&this._pingPongRenderTarget.dispose();for(let t=0;tt-4?o=nh[a-t+4-1]:0===a&&(o=0),n.push(o);const l=1/(s-2),c=-l,u=1+l,h=[c,c,u,c,u,u,c,c,u,u,c,u],d=6,p=6,f=3,m=2,g=1,v=new Float32Array(f*p*d),_=new Float32Array(m*p*d),x=new Float32Array(g*p*d);for(let t=0;t2?0:-1,i=[e,n,0,e+2/3,n,0,e+2/3,n+1,0,e,n,0,e+2/3,n+1,0,e,n+1,0];v.set(i,f*p*t),_.set(h,m*p*t);const r=[t,t,t,t,t,t];x.set(r,g*p*t)}const y=new Gl;y.setAttribute("position",new Ll(v,f)),y.setAttribute("uv",new Ll(_,m)),y.setAttribute("faceIndex",new Ll(x,g)),i.push(new ec(y,null)),r>4&&r--}return{lodMeshes:i,sizeLods:e,sigmas:n}}(i)),this._blurMaterial=function(t,e,n){const i=new Float32Array(20),r=new Da(0,1,0);return new lc({name:"SphericalGaussianBlur",defines:{n:20,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/n,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:i},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:r}},vertexShader:"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t",fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform int samples;\n\t\t\tuniform float weights[ n ];\n\t\t\tuniform bool latitudinal;\n\t\t\tuniform float dTheta;\n\t\t\tuniform float mipInt;\n\t\t\tuniform vec3 poleAxis;\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include \n\n\t\t\tvec3 getSample( float theta, vec3 axis ) {\n\n\t\t\t\tfloat cosTheta = cos( theta );\n\t\t\t\t// Rodrigues' axis-angle rotation\n\t\t\t\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t\t\t\t+ cross( axis, vOutputDirection ) * sin( theta )\n\t\t\t\t\t+ axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );\n\n\t\t\t\treturn bilinearCubeUV( envMap, sampleDirection, mipInt );\n\n\t\t\t}\n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );\n\n\t\t\t\tif ( all( equal( axis, vec3( 0.0 ) ) ) ) {\n\n\t\t\t\t\taxis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );\n\n\t\t\t\t}\n\n\t\t\t\taxis = normalize( axis );\n\n\t\t\t\tgl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n\t\t\t\tgl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );\n\n\t\t\t\tfor ( int i = 1; i < n; i++ ) {\n\n\t\t\t\t\tif ( i >= samples ) {\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t}\n\n\t\t\t\t\tfloat theta = dTheta * float( i );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );\n\t\t\t\t\tgl_FragColor.rgb += weights[ i ] * getSample( theta, axis );\n\n\t\t\t\t}\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}(i,t,e),this._ggxMaterial=function(t,e,n){return new lc({name:"PMREMGGXConvolution",defines:{GGX_SAMPLES:256,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/n,CUBEUV_MAX_MIP:`${t}.0`},uniforms:{envMap:{value:null},roughness:{value:0},mipInt:{value:0}},vertexShader:"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t",fragmentShader:'\n\n\t\t\tprecision highp float;\n\t\t\tprecision highp int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\t\t\tuniform float roughness;\n\t\t\tuniform float mipInt;\n\n\t\t\t#define ENVMAP_TYPE_CUBE_UV\n\t\t\t#include \n\n\t\t\t#define PI 3.14159265359\n\n\t\t\t// Van der Corput radical inverse\n\t\t\tfloat radicalInverse_VdC(uint bits) {\n\t\t\t\tbits = (bits << 16u) | (bits >> 16u);\n\t\t\t\tbits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);\n\t\t\t\tbits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);\n\t\t\t\tbits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);\n\t\t\t\tbits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);\n\t\t\t\treturn float(bits) * 2.3283064365386963e-10; // / 0x100000000\n\t\t\t}\n\n\t\t\t// Hammersley sequence\n\t\t\tvec2 hammersley(uint i, uint N) {\n\t\t\t\treturn vec2(float(i) / float(N), radicalInverse_VdC(i));\n\t\t\t}\n\n\t\t\t// GGX VNDF importance sampling (Eric Heitz 2018)\n\t\t\t// "Sampling the GGX Distribution of Visible Normals"\n\t\t\t// https://jcgt.org/published/0007/04/01/\n\t\t\tvec3 importanceSampleGGX_VNDF(vec2 Xi, vec3 V, float roughness) {\n\t\t\t\tfloat alpha = roughness * roughness;\n\n\t\t\t\t// Section 3.2: Transform view direction to hemisphere configuration\n\t\t\t\tvec3 Vh = normalize(vec3(alpha * V.x, alpha * V.y, V.z));\n\n\t\t\t\t// Section 4.1: Orthonormal basis\n\t\t\t\tfloat lensq = Vh.x * Vh.x + Vh.y * Vh.y;\n\t\t\t\tvec3 T1 = lensq > 0.0 ? vec3(-Vh.y, Vh.x, 0.0) / sqrt(lensq) : vec3(1.0, 0.0, 0.0);\n\t\t\t\tvec3 T2 = cross(Vh, T1);\n\n\t\t\t\t// Section 4.2: Parameterization of projected area\n\t\t\t\tfloat r = sqrt(Xi.x);\n\t\t\t\tfloat phi = 2.0 * PI * Xi.y;\n\t\t\t\tfloat t1 = r * cos(phi);\n\t\t\t\tfloat t2 = r * sin(phi);\n\t\t\t\tfloat s = 0.5 * (1.0 + Vh.z);\n\t\t\t\tt2 = (1.0 - s) * sqrt(1.0 - t1 * t1) + s * t2;\n\n\t\t\t\t// Section 4.3: Reprojection onto hemisphere\n\t\t\t\tvec3 Nh = t1 * T1 + t2 * T2 + sqrt(max(0.0, 1.0 - t1 * t1 - t2 * t2)) * Vh;\n\n\t\t\t\t// Section 3.4: Transform back to ellipsoid configuration\n\t\t\t\treturn normalize(vec3(alpha * Nh.x, alpha * Nh.y, max(0.0, Nh.z)));\n\t\t\t}\n\n\t\t\tvoid main() {\n\t\t\t\tvec3 N = normalize(vOutputDirection);\n\t\t\t\tvec3 V = N; // Assume view direction equals normal for pre-filtering\n\n\t\t\t\tvec3 prefilteredColor = vec3(0.0);\n\t\t\t\tfloat totalWeight = 0.0;\n\n\t\t\t\t// For very low roughness, just sample the environment directly\n\t\t\t\tif (roughness < 0.001) {\n\t\t\t\t\tgl_FragColor = vec4(bilinearCubeUV(envMap, N, mipInt), 1.0);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Tangent space basis for VNDF sampling\n\t\t\t\tvec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\n\t\t\t\tvec3 tangent = normalize(cross(up, N));\n\t\t\t\tvec3 bitangent = cross(N, tangent);\n\n\t\t\t\tfor(uint i = 0u; i < uint(GGX_SAMPLES); i++) {\n\t\t\t\t\tvec2 Xi = hammersley(i, uint(GGX_SAMPLES));\n\n\t\t\t\t\t// For PMREM, V = N, so in tangent space V is always (0, 0, 1)\n\t\t\t\t\tvec3 H_tangent = importanceSampleGGX_VNDF(Xi, vec3(0.0, 0.0, 1.0), roughness);\n\n\t\t\t\t\t// Transform H back to world space\n\t\t\t\t\tvec3 H = normalize(tangent * H_tangent.x + bitangent * H_tangent.y + N * H_tangent.z);\n\t\t\t\t\tvec3 L = normalize(2.0 * dot(V, H) * H - V);\n\n\t\t\t\t\tfloat NdotL = max(dot(N, L), 0.0);\n\n\t\t\t\t\tif(NdotL > 0.0) {\n\t\t\t\t\t\t// Sample environment at fixed mip level\n\t\t\t\t\t\t// VNDF importance sampling handles the distribution filtering\n\t\t\t\t\t\tvec3 sampleColor = bilinearCubeUV(envMap, L, mipInt);\n\n\t\t\t\t\t\t// Weight by NdotL for the split-sum approximation\n\t\t\t\t\t\t// VNDF PDF naturally accounts for the visible microfacet distribution\n\t\t\t\t\t\tprefilteredColor += sampleColor * NdotL;\n\t\t\t\t\t\ttotalWeight += NdotL;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (totalWeight > 0.0) {\n\t\t\t\t\tprefilteredColor = prefilteredColor / totalWeight;\n\t\t\t\t}\n\n\t\t\t\tgl_FragColor = vec4(prefilteredColor, 1.0);\n\t\t\t}\n\t\t',blending:0,depthTest:!1,depthWrite:!1})}(i,t,e)}return i}_compileMaterial(t){const e=new ec(new Gl,t);this._renderer.compile(e,ih)}_sceneToCubeUV(t,e,n,i,r){const s=new pc(90,1,e,n),a=[1,-1,1,1,1,1],o=[1,1,1,-1,-1,-1],l=this._renderer,c=l.autoClear,u=l.toneMapping;l.getClearColor(rh),l.toneMapping=0,l.autoClear=!1,l.state.buffers.depth.getReversed()&&(l.setRenderTarget(i),l.clearDepth(),l.setRenderTarget(null)),null===this._backgroundBox&&(this._backgroundBox=new ec(new ic,new Cl({name:"PMREM.Background",side:1,depthWrite:!1,depthTest:!1})));const h=this._backgroundBox,d=h.material;let p=!1;const f=t.background;f?f.isColor&&(d.color.copy(f),t.background=null,p=!0):(d.color.copy(rh),p=!0);for(let e=0;e<6;e++){const n=e%3;0===n?(s.up.set(0,a[e],0),s.position.set(r.x,r.y,r.z),s.lookAt(r.x+o[e],r.y,r.z)):1===n?(s.up.set(0,0,a[e]),s.position.set(r.x,r.y,r.z),s.lookAt(r.x,r.y+o[e],r.z)):(s.up.set(0,a[e],0),s.position.set(r.x,r.y,r.z),s.lookAt(r.x,r.y,r.z+o[e]));const c=this._cubeSize;dh(i,n*c,e>2?c:0,c,c),l.setRenderTarget(i),p&&l.render(h,s),l.render(t,s)}l.toneMapping=u,l.autoClear=c,t.background=f}_textureToCubeUV(t,e){const n=this._renderer,i=t.mapping===Hr||t.mapping===Gr;i?(null===this._cubemapMaterial&&(this._cubemapMaterial=fh()),this._cubemapMaterial.uniforms.flipEnvMap.value=!1===t.isRenderTargetTexture?-1:1):null===this._equirectMaterial&&(this._equirectMaterial=ph());const r=i?this._cubemapMaterial:this._equirectMaterial,s=this._lodMeshes[0];s.material=r,r.uniforms.envMap.value=t;const a=this._cubeSize;dh(e,0,0,3*a,2*a),n.setRenderTarget(e),n.render(s,ih)}_applyPMREM(t){const e=this._renderer,n=e.autoClear;e.autoClear=!1;const i=this._lodMeshes.length;for(let e=1;eh-4?n-h+4:0),f=4*(this._cubeSize-d);o.envMap.value=t.texture,o.roughness.value=u,o.mipInt.value=h-e,dh(r,p,f,3*d,2*d),i.setRenderTarget(r),i.render(a,ih),o.envMap.value=r.texture,o.roughness.value=0,o.mipInt.value=h-n,dh(t,p,f,3*d,2*d),i.setRenderTarget(t),i.render(a,ih)}_blur(t,e,n,i,r){const s=this._pingPongRenderTarget;this._halfBlur(t,s,e,n,i,"latitudinal",r),this._halfBlur(s,t,n,n,i,"longitudinal",r)}_halfBlur(t,e,n,i,r,s,a){const o=this._renderer,l=this._blurMaterial;"latitudinal"!==s&&"longitudinal"!==s&&ya("blur direction must be either latitudinal or longitudinal!");const c=this._lodMeshes[i];c.material=l;const u=l.uniforms,h=this._sizeLods[n]-1,d=isFinite(r)?Math.PI/(2*h):2*Math.PI/39,p=r/d,f=isFinite(r)?1+Math.floor(3*p):20;f>20&&xa(`sigmaRadians, ${r}, is too large and will clip, as it requested ${f} samples when the maximum is set to 20`);const m=[];let g=0;for(let t=0;t<20;++t){const e=t/p,n=Math.exp(-e*e/2);m.push(n),0===t?g+=n:tv-4?i-v+4:0),4*(this._cubeSize-_),3*_,2*_),o.setRenderTarget(e),o.render(c,ih)}}function hh(t,e,n){const i=new eo(t,e,n);return i.texture.mapping=Wr,i.texture.name="PMREM.cubeUv",i.scissorTest=!0,i}function dh(t,e,n,i,r){t.viewport.set(e,n,i,r),t.scissor.set(e,n,i,r)}function ph(){return new lc({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t",fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform sampler2D envMap;\n\n\t\t\t#include \n\n\t\t\tvoid main() {\n\n\t\t\t\tvec3 outputDirection = normalize( vOutputDirection );\n\t\t\t\tvec2 uv = equirectUv( outputDirection );\n\n\t\t\t\tgl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 );\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}function fh(){return new lc({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:"\n\n\t\tprecision mediump float;\n\t\tprecision mediump int;\n\n\t\tattribute float faceIndex;\n\n\t\tvarying vec3 vOutputDirection;\n\n\t\t// RH coordinate system; PMREM face-indexing convention\n\t\tvec3 getDirection( vec2 uv, float face ) {\n\n\t\t\tuv = 2.0 * uv - 1.0;\n\n\t\t\tvec3 direction = vec3( uv, 1.0 );\n\n\t\t\tif ( face == 0.0 ) {\n\n\t\t\t\tdirection = direction.zyx; // ( 1, v, u ) pos x\n\n\t\t\t} else if ( face == 1.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xz *= -1.0; // ( -u, 1, -v ) pos y\n\n\t\t\t} else if ( face == 2.0 ) {\n\n\t\t\t\tdirection.x *= -1.0; // ( -u, v, 1 ) pos z\n\n\t\t\t} else if ( face == 3.0 ) {\n\n\t\t\t\tdirection = direction.zyx;\n\t\t\t\tdirection.xz *= -1.0; // ( -1, v, -u ) neg x\n\n\t\t\t} else if ( face == 4.0 ) {\n\n\t\t\t\tdirection = direction.xzy;\n\t\t\t\tdirection.xy *= -1.0; // ( -u, -1, v ) neg y\n\n\t\t\t} else if ( face == 5.0 ) {\n\n\t\t\t\tdirection.z *= -1.0; // ( u, v, -1 ) neg z\n\n\t\t\t}\n\n\t\t\treturn direction;\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvOutputDirection = getDirection( uv, faceIndex );\n\t\t\tgl_Position = vec4( position, 1.0 );\n\n\t\t}\n\t",fragmentShader:"\n\n\t\t\tprecision mediump float;\n\t\t\tprecision mediump int;\n\n\t\t\tuniform float flipEnvMap;\n\n\t\t\tvarying vec3 vOutputDirection;\n\n\t\t\tuniform samplerCube envMap;\n\n\t\t\tvoid main() {\n\n\t\t\t\tgl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) );\n\n\t\t\t}\n\t\t",blending:0,depthTest:!1,depthWrite:!1})}function mh(t){let e=new WeakMap,n=null;function i(t){const n=t.target;n.removeEventListener("dispose",i);const r=e.get(n);void 0!==r&&(e.delete(n),r.dispose())}return{get:function(r){if(r&&r.isTexture){const s=r.mapping,a=303===s||304===s,o=s===Hr||s===Gr;if(a||o){let s=e.get(r);const l=void 0!==s?s.texture.pmremVersion:0;if(r.isRenderTargetTexture&&r.pmremVersion!==l)return null===n&&(n=new uh(t)),s=a?n.fromEquirectangular(r,s):n.fromCubemap(r,s),s.texture.pmremVersion=r.pmremVersion,e.set(r,s),s.texture;if(void 0!==s)return s.texture;{const l=r.image;return a&&l&&l.height>0||o&&l&&function(t){let e=0;for(let n=0;n<6;n++)void 0!==t[n]&&e++;return 6===e}(l)?(null===n&&(n=new uh(t)),s=a?n.fromEquirectangular(r):n.fromCubemap(r),s.texture.pmremVersion=r.pmremVersion,e.set(r,s),r.addEventListener("dispose",i),s.texture):null}}}return r},dispose:function(){e=new WeakMap,null!==n&&(n.dispose(),n=null)}}}function gh(t){const e={};function n(n){if(void 0!==e[n])return e[n];const i=t.getExtension(n);return e[n]=i,i}return{has:function(t){return null!==n(t)},init:function(){n("EXT_color_buffer_float"),n("WEBGL_clip_cull_distance"),n("OES_texture_float_linear"),n("EXT_color_buffer_half_float"),n("WEBGL_multisampled_render_to_texture"),n("WEBGL_render_shared_exponent")},get:function(t){const e=n(t);return null===e&&ba("WebGLRenderer: "+t+" extension not supported."),e}}}function vh(t,e,n,i){const r={},s=new WeakMap;function a(t){const o=t.target;null!==o.index&&e.remove(o.index);for(const t in o.attributes)e.remove(o.attributes[t]);o.removeEventListener("dispose",a),delete r[o.id];const l=s.get(o);l&&(e.remove(l),s.delete(o)),i.releaseStatesOfGeometry(o),!0===o.isInstancedBufferGeometry&&delete o._maxInstanceCount,n.memory.geometries--}function o(t){const n=[],i=t.index,r=t.attributes.position;let a=0;if(null!==i){const t=i.array;a=i.version;for(let e=0,i=t.length;ee.maxTextureSize&&(y=Math.ceil(x/e.maxTextureSize),x=e.maxTextureSize);const b=new Float32Array(x*y*4*u),w=new no(b,x,y,u);w.type=rs,w.needsUpdate=!0;const M=4*_;for(let E=0;E0)return t;const r=e*n;let s=Ah[r];if(void 0===s&&(s=new Float32Array(r),Ah[r]=s),0!==e){i.toArray(s,0);for(let i=1,r=0;i!==e;++i)r+=n,t[i].toArray(s,r)}return s}function Uh(t,e){if(t.length!==e.length)return!1;for(let n=0,i=t.length;n":" "} ${r}: ${n[t]}`)}return i.join("\n")}(t.getShaderSource(e),i)}return r}function Nd(t,e){const n=function(t){Ha._getMatrix(Rd,Ha.workingColorSpace,t);const e=`mat3( ${Rd.elements.map(t=>t.toFixed(4))} )`;switch(Ha.getTransfer(t)){case ta:return[e,"LinearTransferOETF"];case ea:return[e,"sRGBTransferOETF"];default:return xa("WebGLProgram: Unsupported color space: ",t),[e,"LinearTransferOETF"]}}(e);return[`vec4 ${t}( vec4 value ) {`,`\treturn ${n[1]}( vec4( value.rgb * ${n[0]}, value.a ) );`,"}"].join("\n")}function Ld(t,e){let n;switch(e){case 1:n="Linear";break;case 2:n="Reinhard";break;case 3:n="Cineon";break;case 4:n="ACESFilmic";break;case 6:n="AgX";break;case 7:n="Neutral";break;case 5:n="Custom";break;default:xa("WebGLProgram: Unsupported toneMapping:",e),n="Linear"}return"vec3 "+t+"( vec3 color ) { return "+n+"ToneMapping( color ); }"}const Ud=new Da;function Dd(t){return""!==t}function Id(t,e){const n=e.numSpotLightShadows+e.numSpotLightMaps-e.numSpotLightShadowsWithMaps;return t.replace(/NUM_DIR_LIGHTS/g,e.numDirLights).replace(/NUM_SPOT_LIGHTS/g,e.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,e.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,n).replace(/NUM_RECT_AREA_LIGHTS/g,e.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,e.numPointLights).replace(/NUM_HEMI_LIGHTS/g,e.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,e.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,e.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,e.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,e.numPointLightShadows)}function Od(t,e){return t.replace(/NUM_CLIPPING_PLANES/g,e.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,e.numClippingPlanes-e.numClipIntersection)}const kd=/^[ \t]*#include +<([\w\d./]+)>/gm;function Fd(t){return t.replace(kd,zd)}const Bd=new Map;function zd(t,e){let n=Wu[e];if(void 0===n){const t=Bd.get(e);if(void 0===t)throw new Error("Can not resolve #include <"+e+">");n=Wu[t],xa('WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',e,t)}return Fd(n)}const Vd=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Hd(t){return t.replace(Vd,Gd)}function Gd(t,e,n,i){let r="";for(let t=parseInt(e);t0&&(g+="\n"),v=["#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,f].filter(Dd).join("\n"),v.length>0&&(v+="\n")):(g=[Wd(n),"#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,f,n.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",n.batching?"#define USE_BATCHING":"",n.batchingColor?"#define USE_BATCHING_COLOR":"",n.instancing?"#define USE_INSTANCING":"",n.instancingColor?"#define USE_INSTANCING_COLOR":"",n.instancingMorph?"#define USE_INSTANCING_MORPH":"",n.useFog&&n.fog?"#define USE_FOG":"",n.useFog&&n.fogExp2?"#define FOG_EXP2":"",n.map?"#define USE_MAP":"",n.envMap?"#define USE_ENVMAP":"",n.envMap?"#define "+u:"",n.lightMap?"#define USE_LIGHTMAP":"",n.aoMap?"#define USE_AOMAP":"",n.bumpMap?"#define USE_BUMPMAP":"",n.normalMap?"#define USE_NORMALMAP":"",n.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",n.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",n.displacementMap?"#define USE_DISPLACEMENTMAP":"",n.emissiveMap?"#define USE_EMISSIVEMAP":"",n.anisotropy?"#define USE_ANISOTROPY":"",n.anisotropyMap?"#define USE_ANISOTROPYMAP":"",n.clearcoatMap?"#define USE_CLEARCOATMAP":"",n.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",n.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",n.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",n.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",n.specularMap?"#define USE_SPECULARMAP":"",n.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",n.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",n.roughnessMap?"#define USE_ROUGHNESSMAP":"",n.metalnessMap?"#define USE_METALNESSMAP":"",n.alphaMap?"#define USE_ALPHAMAP":"",n.alphaHash?"#define USE_ALPHAHASH":"",n.transmission?"#define USE_TRANSMISSION":"",n.transmissionMap?"#define USE_TRANSMISSIONMAP":"",n.thicknessMap?"#define USE_THICKNESSMAP":"",n.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",n.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",n.mapUv?"#define MAP_UV "+n.mapUv:"",n.alphaMapUv?"#define ALPHAMAP_UV "+n.alphaMapUv:"",n.lightMapUv?"#define LIGHTMAP_UV "+n.lightMapUv:"",n.aoMapUv?"#define AOMAP_UV "+n.aoMapUv:"",n.emissiveMapUv?"#define EMISSIVEMAP_UV "+n.emissiveMapUv:"",n.bumpMapUv?"#define BUMPMAP_UV "+n.bumpMapUv:"",n.normalMapUv?"#define NORMALMAP_UV "+n.normalMapUv:"",n.displacementMapUv?"#define DISPLACEMENTMAP_UV "+n.displacementMapUv:"",n.metalnessMapUv?"#define METALNESSMAP_UV "+n.metalnessMapUv:"",n.roughnessMapUv?"#define ROUGHNESSMAP_UV "+n.roughnessMapUv:"",n.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+n.anisotropyMapUv:"",n.clearcoatMapUv?"#define CLEARCOATMAP_UV "+n.clearcoatMapUv:"",n.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+n.clearcoatNormalMapUv:"",n.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+n.clearcoatRoughnessMapUv:"",n.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+n.iridescenceMapUv:"",n.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+n.iridescenceThicknessMapUv:"",n.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+n.sheenColorMapUv:"",n.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+n.sheenRoughnessMapUv:"",n.specularMapUv?"#define SPECULARMAP_UV "+n.specularMapUv:"",n.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+n.specularColorMapUv:"",n.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+n.specularIntensityMapUv:"",n.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+n.transmissionMapUv:"",n.thicknessMapUv?"#define THICKNESSMAP_UV "+n.thicknessMapUv:"",n.vertexTangents&&!1===n.flatShading?"#define USE_TANGENT":"",n.vertexColors?"#define USE_COLOR":"",n.vertexAlphas?"#define USE_COLOR_ALPHA":"",n.vertexUv1s?"#define USE_UV1":"",n.vertexUv2s?"#define USE_UV2":"",n.vertexUv3s?"#define USE_UV3":"",n.pointsUvs?"#define USE_POINTS_UV":"",n.flatShading?"#define FLAT_SHADED":"",n.skinning?"#define USE_SKINNING":"",n.morphTargets?"#define USE_MORPHTARGETS":"",n.morphNormals&&!1===n.flatShading?"#define USE_MORPHNORMALS":"",n.morphColors?"#define USE_MORPHCOLORS":"",n.morphTargetsCount>0?"#define MORPHTARGETS_TEXTURE_STRIDE "+n.morphTextureStride:"",n.morphTargetsCount>0?"#define MORPHTARGETS_COUNT "+n.morphTargetsCount:"",n.doubleSided?"#define DOUBLE_SIDED":"",n.flipSided?"#define FLIP_SIDED":"",n.shadowMapEnabled?"#define USE_SHADOWMAP":"",n.shadowMapEnabled?"#define "+l:"",n.sizeAttenuation?"#define USE_SIZEATTENUATION":"",n.numLightProbes>0?"#define USE_LIGHT_PROBES":"",n.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",n.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING","\tattribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR","\tattribute vec3 instanceColor;","#endif","#ifdef USE_INSTANCING_MORPH","\tuniform sampler2D morphTexture;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1","\tattribute vec2 uv1;","#endif","#ifdef USE_UV2","\tattribute vec2 uv2;","#endif","#ifdef USE_UV3","\tattribute vec2 uv3;","#endif","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )","\tattribute vec4 color;","#elif defined( USE_COLOR )","\tattribute vec3 color;","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter(Dd).join("\n"),v=[Wd(n),"#define SHADER_TYPE "+n.shaderType,"#define SHADER_NAME "+n.shaderName,f,n.useFog&&n.fog?"#define USE_FOG":"",n.useFog&&n.fogExp2?"#define FOG_EXP2":"",n.alphaToCoverage?"#define ALPHA_TO_COVERAGE":"",n.map?"#define USE_MAP":"",n.matcap?"#define USE_MATCAP":"",n.envMap?"#define USE_ENVMAP":"",n.envMap?"#define "+c:"",n.envMap?"#define "+u:"",n.envMap?"#define "+h:"",d?"#define CUBEUV_TEXEL_WIDTH "+d.texelWidth:"",d?"#define CUBEUV_TEXEL_HEIGHT "+d.texelHeight:"",d?"#define CUBEUV_MAX_MIP "+d.maxMip+".0":"",n.lightMap?"#define USE_LIGHTMAP":"",n.aoMap?"#define USE_AOMAP":"",n.bumpMap?"#define USE_BUMPMAP":"",n.normalMap?"#define USE_NORMALMAP":"",n.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",n.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",n.emissiveMap?"#define USE_EMISSIVEMAP":"",n.anisotropy?"#define USE_ANISOTROPY":"",n.anisotropyMap?"#define USE_ANISOTROPYMAP":"",n.clearcoat?"#define USE_CLEARCOAT":"",n.clearcoatMap?"#define USE_CLEARCOATMAP":"",n.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",n.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",n.dispersion?"#define USE_DISPERSION":"",n.iridescence?"#define USE_IRIDESCENCE":"",n.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",n.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",n.specularMap?"#define USE_SPECULARMAP":"",n.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",n.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",n.roughnessMap?"#define USE_ROUGHNESSMAP":"",n.metalnessMap?"#define USE_METALNESSMAP":"",n.alphaMap?"#define USE_ALPHAMAP":"",n.alphaTest?"#define USE_ALPHATEST":"",n.alphaHash?"#define USE_ALPHAHASH":"",n.sheen?"#define USE_SHEEN":"",n.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",n.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",n.transmission?"#define USE_TRANSMISSION":"",n.transmissionMap?"#define USE_TRANSMISSIONMAP":"",n.thicknessMap?"#define USE_THICKNESSMAP":"",n.vertexTangents&&!1===n.flatShading?"#define USE_TANGENT":"",n.vertexColors||n.instancingColor||n.batchingColor?"#define USE_COLOR":"",n.vertexAlphas?"#define USE_COLOR_ALPHA":"",n.vertexUv1s?"#define USE_UV1":"",n.vertexUv2s?"#define USE_UV2":"",n.vertexUv3s?"#define USE_UV3":"",n.pointsUvs?"#define USE_POINTS_UV":"",n.gradientMap?"#define USE_GRADIENTMAP":"",n.flatShading?"#define FLAT_SHADED":"",n.doubleSided?"#define DOUBLE_SIDED":"",n.flipSided?"#define FLIP_SIDED":"",n.shadowMapEnabled?"#define USE_SHADOWMAP":"",n.shadowMapEnabled?"#define "+l:"",n.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",n.numLightProbes>0?"#define USE_LIGHT_PROBES":"",n.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",n.decodeVideoTextureEmissive?"#define DECODE_VIDEO_TEXTURE_EMISSIVE":"",n.logarithmicDepthBuffer?"#define USE_LOGARITHMIC_DEPTH_BUFFER":"",n.reversedDepthBuffer?"#define USE_REVERSED_DEPTH_BUFFER":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",0!==n.toneMapping?"#define TONE_MAPPING":"",0!==n.toneMapping?Wu.tonemapping_pars_fragment:"",0!==n.toneMapping?Ld("toneMapping",n.toneMapping):"",n.dithering?"#define DITHERING":"",n.opaque?"#define OPAQUE":"",Wu.colorspace_pars_fragment,Nd("linearToOutputTexel",n.outputColorSpace),(Ha.getLuminanceCoefficients(Ud),["float luminance( const in vec3 rgb ) {",`\tconst vec3 weights = vec3( ${Ud.x.toFixed(4)}, ${Ud.y.toFixed(4)}, ${Ud.z.toFixed(4)} );`,"\treturn dot( weights, rgb );","}"].join("\n")),n.useDepthPacking?"#define DEPTH_PACKING "+n.depthPacking:"","\n"].filter(Dd).join("\n")),a=Fd(a),a=Id(a,n),a=Od(a,n),o=Fd(o),o=Id(o,n),o=Od(o,n),a=Hd(a),o=Hd(o),!0!==n.isRawShaderMaterial&&(_="#version 300 es\n",g=[p,"#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+g,v=["#define varying in",n.glslVersion===ha?"":"layout(location = 0) out highp vec4 pc_fragColor;",n.glslVersion===ha?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join("\n")+"\n"+v);const x=_+g+a,y=_+v+o,b=Ad(r,r.VERTEX_SHADER,x),w=Ad(r,r.FRAGMENT_SHADER,y);function M(e){if(t.debug.checkShaderErrors){const n=r.getProgramInfoLog(m)||"",i=r.getShaderInfoLog(b)||"",s=r.getShaderInfoLog(w)||"",a=n.trim(),o=i.trim(),l=s.trim();let c=!0,u=!0;if(!1===r.getProgramParameter(m,r.LINK_STATUS))if(c=!1,"function"==typeof t.debug.onShaderError)t.debug.onShaderError(r,m,b,w);else{const t=Pd(r,b,"vertex"),n=Pd(r,w,"fragment");ya("THREE.WebGLProgram: Shader Error "+r.getError()+" - VALIDATE_STATUS "+r.getProgramParameter(m,r.VALIDATE_STATUS)+"\n\nMaterial Name: "+e.name+"\nMaterial Type: "+e.type+"\n\nProgram Info Log: "+a+"\n"+t+"\n"+n)}else""!==a?xa("WebGLProgram: Program Info Log:",a):""!==o&&""!==l||(u=!1);u&&(e.diagnostics={runnable:c,programLog:a,vertexShader:{log:o,prefix:g},fragmentShader:{log:l,prefix:v}})}r.deleteShader(b),r.deleteShader(w),S=new Td(r,m),E=function(t,e){const n={},i=t.getProgramParameter(e,t.ACTIVE_ATTRIBUTES);for(let r=0;r0,$=s.clearcoat>0,q=s.dispersion>0,Y=s.iridescence>0,Z=s.sheen>0,K=s.transmission>0,J=X&&!!s.anisotropyMap,Q=$&&!!s.clearcoatMap,tt=$&&!!s.clearcoatNormalMap,et=$&&!!s.clearcoatRoughnessMap,nt=Y&&!!s.iridescenceMap,it=Y&&!!s.iridescenceThicknessMap,rt=Z&&!!s.sheenColorMap,st=Z&&!!s.sheenRoughnessMap,at=!!s.specularMap,ot=!!s.specularColorMap,lt=!!s.specularIntensityMap,ct=K&&!!s.transmissionMap,ut=K&&!!s.thicknessMap,ht=!!s.gradientMap,dt=!!s.alphaMap,pt=s.alphaTest>0,ft=!!s.alphaHash,mt=!!s.extensions;let gt=0;s.toneMapped&&(null!==N&&!0!==N.isXRRenderTarget||(gt=t.toneMapping));const vt={shaderID:M,shaderType:s.type,shaderName:s.name,vertexShader:T,fragmentShader:A,defines:s.defines,customVertexShaderID:C,customFragmentShaderID:R,isRawShaderMaterial:!0===s.isRawShaderMaterial,glslVersion:s.glslVersion,precision:p,batching:D,batchingColor:D&&null!==v._colorsTexture,instancing:U,instancingColor:U&&null!==v.instanceColor,instancingMorph:U&&null!==v.morphTexture,supportsVertexTextures:d,outputColorSpace:null===N?t.outputColorSpace:!0===N.isXRRenderTarget?N.texture.colorSpace:Qs,alphaToCoverage:!!s.alphaToCoverage,map:I,matcap:O,envMap:k,envMapMode:k&&b.mapping,envMapCubeUVHeight:w,aoMap:F,lightMap:B,bumpMap:z,normalMap:V,displacementMap:d&&H,emissiveMap:G,normalMapObjectSpace:V&&1===s.normalMapType,normalMapTangentSpace:V&&0===s.normalMapType,metalnessMap:W,roughnessMap:j,anisotropy:X,anisotropyMap:J,clearcoat:$,clearcoatMap:Q,clearcoatNormalMap:tt,clearcoatRoughnessMap:et,dispersion:q,iridescence:Y,iridescenceMap:nt,iridescenceThicknessMap:it,sheen:Z,sheenColorMap:rt,sheenRoughnessMap:st,specularMap:at,specularColorMap:ot,specularIntensityMap:lt,transmission:K,transmissionMap:ct,thicknessMap:ut,gradientMap:ht,opaque:!1===s.transparent&&1===s.blending&&!1===s.alphaToCoverage,alphaMap:dt,alphaTest:pt,alphaHash:ft,combine:s.combine,mapUv:I&&m(s.map.channel),aoMapUv:F&&m(s.aoMap.channel),lightMapUv:B&&m(s.lightMap.channel),bumpMapUv:z&&m(s.bumpMap.channel),normalMapUv:V&&m(s.normalMap.channel),displacementMapUv:H&&m(s.displacementMap.channel),emissiveMapUv:G&&m(s.emissiveMap.channel),metalnessMapUv:W&&m(s.metalnessMap.channel),roughnessMapUv:j&&m(s.roughnessMap.channel),anisotropyMapUv:J&&m(s.anisotropyMap.channel),clearcoatMapUv:Q&&m(s.clearcoatMap.channel),clearcoatNormalMapUv:tt&&m(s.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:et&&m(s.clearcoatRoughnessMap.channel),iridescenceMapUv:nt&&m(s.iridescenceMap.channel),iridescenceThicknessMapUv:it&&m(s.iridescenceThicknessMap.channel),sheenColorMapUv:rt&&m(s.sheenColorMap.channel),sheenRoughnessMapUv:st&&m(s.sheenRoughnessMap.channel),specularMapUv:at&&m(s.specularMap.channel),specularColorMapUv:ot&&m(s.specularColorMap.channel),specularIntensityMapUv:lt&&m(s.specularIntensityMap.channel),transmissionMapUv:ct&&m(s.transmissionMap.channel),thicknessMapUv:ut&&m(s.thicknessMap.channel),alphaMapUv:dt&&m(s.alphaMap.channel),vertexTangents:!!x.attributes.tangent&&(V||X),vertexColors:s.vertexColors,vertexAlphas:!0===s.vertexColors&&!!x.attributes.color&&4===x.attributes.color.itemSize,pointsUvs:!0===v.isPoints&&!!x.attributes.uv&&(I||dt),fog:!!_,useFog:!0===s.fog,fogExp2:!!_&&_.isFogExp2,flatShading:!0===s.flatShading&&!1===s.wireframe,sizeAttenuation:!0===s.sizeAttenuation,logarithmicDepthBuffer:h,reversedDepthBuffer:L,skinning:!0===v.isSkinnedMesh,morphTargets:void 0!==x.morphAttributes.position,morphNormals:void 0!==x.morphAttributes.normal,morphColors:void 0!==x.morphAttributes.color,morphTargetsCount:E,morphTextureStride:P,numDirLights:o.directional.length,numPointLights:o.point.length,numSpotLights:o.spot.length,numSpotLightMaps:o.spotLightMap.length,numRectAreaLights:o.rectArea.length,numHemiLights:o.hemi.length,numDirLightShadows:o.directionalShadowMap.length,numPointLightShadows:o.pointShadowMap.length,numSpotLightShadows:o.spotShadowMap.length,numSpotLightShadowsWithMaps:o.numSpotLightShadowsWithMaps,numLightProbes:o.numLightProbes,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,dithering:s.dithering,shadowMapEnabled:t.shadowMap.enabled&&u.length>0,shadowMapType:t.shadowMap.type,toneMapping:gt,decodeVideoTexture:I&&!0===s.map.isVideoTexture&&Ha.getTransfer(s.map.colorSpace)===ea,decodeVideoTextureEmissive:G&&!0===s.emissiveMap.isVideoTexture&&Ha.getTransfer(s.emissiveMap.colorSpace)===ea,premultipliedAlpha:s.premultipliedAlpha,doubleSided:2===s.side,flipSided:1===s.side,useDepthPacking:s.depthPacking>=0,depthPacking:s.depthPacking||0,index0AttributeName:s.index0AttributeName,extensionClipCullDistance:mt&&!0===s.extensions.clipCullDistance&&i.has("WEBGL_clip_cull_distance"),extensionMultiDraw:(mt&&!0===s.extensions.multiDraw||D)&&i.has("WEBGL_multi_draw"),rendererExtensionParallelShaderCompile:i.has("KHR_parallel_shader_compile"),customProgramCacheKey:s.customProgramCacheKey()};return vt.vertexUv1s=c.has(1),vt.vertexUv2s=c.has(2),vt.vertexUv3s=c.has(3),c.clear(),vt},getProgramCacheKey:function(e){const n=[];if(e.shaderID?n.push(e.shaderID):(n.push(e.customVertexShaderID),n.push(e.customFragmentShaderID)),void 0!==e.defines)for(const t in e.defines)n.push(t),n.push(e.defines[t]);return!1===e.isRawShaderMaterial&&(function(t,e){t.push(e.precision),t.push(e.outputColorSpace),t.push(e.envMapMode),t.push(e.envMapCubeUVHeight),t.push(e.mapUv),t.push(e.alphaMapUv),t.push(e.lightMapUv),t.push(e.aoMapUv),t.push(e.bumpMapUv),t.push(e.normalMapUv),t.push(e.displacementMapUv),t.push(e.emissiveMapUv),t.push(e.metalnessMapUv),t.push(e.roughnessMapUv),t.push(e.anisotropyMapUv),t.push(e.clearcoatMapUv),t.push(e.clearcoatNormalMapUv),t.push(e.clearcoatRoughnessMapUv),t.push(e.iridescenceMapUv),t.push(e.iridescenceThicknessMapUv),t.push(e.sheenColorMapUv),t.push(e.sheenRoughnessMapUv),t.push(e.specularMapUv),t.push(e.specularColorMapUv),t.push(e.specularIntensityMapUv),t.push(e.transmissionMapUv),t.push(e.thicknessMapUv),t.push(e.combine),t.push(e.fogExp2),t.push(e.sizeAttenuation),t.push(e.morphTargetsCount),t.push(e.morphAttributeCount),t.push(e.numDirLights),t.push(e.numPointLights),t.push(e.numSpotLights),t.push(e.numSpotLightMaps),t.push(e.numHemiLights),t.push(e.numRectAreaLights),t.push(e.numDirLightShadows),t.push(e.numPointLightShadows),t.push(e.numSpotLightShadows),t.push(e.numSpotLightShadowsWithMaps),t.push(e.numLightProbes),t.push(e.shadowMapType),t.push(e.toneMapping),t.push(e.numClippingPlanes),t.push(e.numClipIntersection),t.push(e.depthPacking)}(n,e),function(t,e){o.disableAll(),e.supportsVertexTextures&&o.enable(0),e.instancing&&o.enable(1),e.instancingColor&&o.enable(2),e.instancingMorph&&o.enable(3),e.matcap&&o.enable(4),e.envMap&&o.enable(5),e.normalMapObjectSpace&&o.enable(6),e.normalMapTangentSpace&&o.enable(7),e.clearcoat&&o.enable(8),e.iridescence&&o.enable(9),e.alphaTest&&o.enable(10),e.vertexColors&&o.enable(11),e.vertexAlphas&&o.enable(12),e.vertexUv1s&&o.enable(13),e.vertexUv2s&&o.enable(14),e.vertexUv3s&&o.enable(15),e.vertexTangents&&o.enable(16),e.anisotropy&&o.enable(17),e.alphaHash&&o.enable(18),e.batching&&o.enable(19),e.dispersion&&o.enable(20),e.batchingColor&&o.enable(21),e.gradientMap&&o.enable(22),t.push(o.mask),o.disableAll(),e.fog&&o.enable(0),e.useFog&&o.enable(1),e.flatShading&&o.enable(2),e.logarithmicDepthBuffer&&o.enable(3),e.reversedDepthBuffer&&o.enable(4),e.skinning&&o.enable(5),e.morphTargets&&o.enable(6),e.morphNormals&&o.enable(7),e.morphColors&&o.enable(8),e.premultipliedAlpha&&o.enable(9),e.shadowMapEnabled&&o.enable(10),e.doubleSided&&o.enable(11),e.flipSided&&o.enable(12),e.useDepthPacking&&o.enable(13),e.dithering&&o.enable(14),e.transmission&&o.enable(15),e.sheen&&o.enable(16),e.opaque&&o.enable(17),e.pointsUvs&&o.enable(18),e.decodeVideoTexture&&o.enable(19),e.decodeVideoTextureEmissive&&o.enable(20),e.alphaToCoverage&&o.enable(21),t.push(o.mask)}(n,e),n.push(t.outputColorSpace)),n.push(e.customProgramCacheKey),n.join()},getUniforms:function(t){const e=f[t.type];let n;if(e){const t=Xu[e];n=oc.clone(t.uniforms)}else n=t.uniforms;return n},acquireProgram:function(e,n){let i;for(let t=0,e=u.length;t0?i.push(u):!0===a.transparent?r.push(u):n.push(u)},unshift:function(t,e,a,o,l,c){const u=s(t,e,a,o,l,c);a.transmission>0?i.unshift(u):!0===a.transparent?r.unshift(u):n.unshift(u)},finish:function(){for(let n=e,i=t.length;n1&&n.sort(t||Kd),i.length>1&&i.sort(e||Jd),r.length>1&&r.sort(e||Jd)}}}function tp(){let t=new WeakMap;return{get:function(e,n){const i=t.get(e);let r;return void 0===i?(r=new Qd,t.set(e,[r])):n>=i.length?(r=new Qd,i.push(r)):r=i[n],r},dispose:function(){t=new WeakMap}}}function ep(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let n;switch(e.type){case"DirectionalLight":n={direction:new Da,color:new Sl};break;case"SpotLight":n={position:new Da,direction:new Da,color:new Sl,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":n={position:new Da,color:new Sl,distance:0,decay:0};break;case"HemisphereLight":n={direction:new Da,skyColor:new Sl,groundColor:new Sl};break;case"RectAreaLight":n={color:new Sl,position:new Da,halfWidth:new Da,halfHeight:new Da}}return t[e.id]=n,n}}}let np=0;function ip(t,e){return(e.castShadow?2:0)-(t.castShadow?2:0)+(e.map?1:0)-(t.map?1:0)}function rp(t){const e=new ep,n=function(){const t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];let n;switch(e.type){case"DirectionalLight":case"SpotLight":n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new La};break;case"PointLight":n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new La,shadowCameraNear:1,shadowCameraFar:1e3}}return t[e.id]=n,n}}}(),i={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let t=0;t<9;t++)i.probe.push(new Da);const r=new Da,s=new Lo,a=new Lo;return{setup:function(r){let s=0,a=0,o=0;for(let t=0;t<9;t++)i.probe[t].set(0,0,0);let l=0,c=0,u=0,h=0,d=0,p=0,f=0,m=0,g=0,v=0,_=0;r.sort(ip);for(let t=0,x=r.length;t0&&(!0===t.has("OES_texture_float_linear")?(i.rectAreaLTC1=ju.LTC_FLOAT_1,i.rectAreaLTC2=ju.LTC_FLOAT_2):(i.rectAreaLTC1=ju.LTC_HALF_1,i.rectAreaLTC2=ju.LTC_HALF_2)),i.ambient[0]=s,i.ambient[1]=a,i.ambient[2]=o;const x=i.hash;x.directionalLength===l&&x.pointLength===c&&x.spotLength===u&&x.rectAreaLength===h&&x.hemiLength===d&&x.numDirectionalShadows===p&&x.numPointShadows===f&&x.numSpotShadows===m&&x.numSpotMaps===g&&x.numLightProbes===_||(i.directional.length=l,i.spot.length=u,i.rectArea.length=h,i.point.length=c,i.hemi.length=d,i.directionalShadow.length=p,i.directionalShadowMap.length=p,i.pointShadow.length=f,i.pointShadowMap.length=f,i.spotShadow.length=m,i.spotShadowMap.length=m,i.directionalShadowMatrix.length=p,i.pointShadowMatrix.length=f,i.spotLightMatrix.length=m+g-v,i.spotLightMap.length=g,i.numSpotLightShadowsWithMaps=v,i.numLightProbes=_,x.directionalLength=l,x.pointLength=c,x.spotLength=u,x.rectAreaLength=h,x.hemiLength=d,x.numDirectionalShadows=p,x.numPointShadows=f,x.numSpotShadows=m,x.numSpotMaps=g,x.numLightProbes=_,i.version=np++)},setupView:function(t,e){let n=0,o=0,l=0,c=0,u=0;const h=e.matrixWorldInverse;for(let e=0,d=t.length;e=r.length?(s=new sp(t),r.push(s)):s=r[i],s},dispose:function(){e=new WeakMap}}}function op(t,e,n){let i=new Pc;const r=new La,s=new La,a=new Qa,o=new ru({depthPacking:3201}),l=new su,c={},u=n.maxTextureSize,h={[pr]:1,[fr]:0,[mr]:2},d=new lc({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new La},radius:{value:4}},vertexShader:"void main() {\n\tgl_Position = vec4( position, 1.0 );\n}",fragmentShader:"uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include \nvoid main() {\n\tconst float samples = float( VSM_SAMPLES );\n\tfloat mean = 0.0;\n\tfloat squared_mean = 0.0;\n\tfloat uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n\tfloat uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n\tfor ( float i = 0.0; i < samples; i ++ ) {\n\t\tfloat uvOffset = uvStart + i * uvStride;\n\t\t#ifdef HORIZONTAL_PASS\n\t\t\tvec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n\t\t\tmean += distribution.x;\n\t\t\tsquared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n\t\t#else\n\t\t\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n\t\t\tmean += depth;\n\t\t\tsquared_mean += depth * depth;\n\t\t#endif\n\t}\n\tmean = mean / samples;\n\tsquared_mean = squared_mean / samples;\n\tfloat std_dev = sqrt( squared_mean - mean * mean );\n\tgl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}"}),p=d.clone();p.defines.HORIZONTAL_PASS=1;const f=new Gl;f.setAttribute("position",new Ll(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const m=new ec(f,d),g=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let v=this.type;function _(n,i){const s=e.update(m);d.defines.VSM_SAMPLES!==n.blurSamples&&(d.defines.VSM_SAMPLES=n.blurSamples,p.defines.VSM_SAMPLES=n.blurSamples,d.needsUpdate=!0,p.needsUpdate=!0),null===n.mapPass&&(n.mapPass=new eo(r.x,r.y)),d.uniforms.shadow_pass.value=n.map.texture,d.uniforms.resolution.value=n.mapSize,d.uniforms.radius.value=n.radius,t.setRenderTarget(n.mapPass),t.clear(),t.renderBufferDirect(i,null,s,d,m,null),p.uniforms.shadow_pass.value=n.mapPass.texture,p.uniforms.resolution.value=n.mapSize,p.uniforms.radius.value=n.radius,t.setRenderTarget(n.map),t.clear(),t.renderBufferDirect(i,null,s,p,m,null)}function x(e,n,i,r){let s=null;const a=!0===i.isPointLight?e.customDistanceMaterial:e.customDepthMaterial;if(void 0!==a)s=a;else if(s=!0===i.isPointLight?l:o,t.localClippingEnabled&&!0===n.clipShadows&&Array.isArray(n.clippingPlanes)&&0!==n.clippingPlanes.length||n.displacementMap&&0!==n.displacementScale||n.alphaMap&&n.alphaTest>0||n.map&&n.alphaTest>0||!0===n.alphaToCoverage){const t=s.uuid,e=n.uuid;let i=c[t];void 0===i&&(i={},c[t]=i);let r=i[e];void 0===r&&(r=s.clone(),i[e]=r,n.addEventListener("dispose",b)),s=r}return s.visible=n.visible,s.wireframe=n.wireframe,s.side=3===r?null!==n.shadowSide?n.shadowSide:n.side:null!==n.shadowSide?n.shadowSide:h[n.side],s.alphaMap=n.alphaMap,s.alphaTest=!0===n.alphaToCoverage?.5:n.alphaTest,s.map=n.map,s.clipShadows=n.clipShadows,s.clippingPlanes=n.clippingPlanes,s.clipIntersection=n.clipIntersection,s.displacementMap=n.displacementMap,s.displacementScale=n.displacementScale,s.displacementBias=n.displacementBias,s.wireframeLinewidth=n.wireframeLinewidth,s.linewidth=n.linewidth,!0===i.isPointLight&&!0===s.isMeshDistanceMaterial&&(t.properties.get(s).light=i),s}function y(n,r,s,a,o){if(!1===n.visible)return;if(n.layers.test(r.layers)&&(n.isMesh||n.isLine||n.isPoints)&&(n.castShadow||n.receiveShadow&&3===o)&&(!n.frustumCulled||i.intersectsObject(n))){n.modelViewMatrix.multiplyMatrices(s.matrixWorldInverse,n.matrixWorld);const i=e.update(n),l=n.material;if(Array.isArray(l)){const e=i.groups;for(let c=0,u=e.length;cu||r.y>u)&&(r.x>u&&(s.x=Math.floor(u/m.x),r.x=s.x*m.x,h.mapSize.x=s.x),r.y>u&&(s.y=Math.floor(u/m.y),r.y=s.y*m.y,h.mapSize.y=s.y)),null===h.map||!0===p||!0===f){const t=3!==this.type?{minFilter:qr,magFilter:qr}:{};null!==h.map&&h.map.dispose(),h.map=new eo(r.x,r.y,t),h.map.texture.name=c.name+".shadowMap",h.camera.updateProjectionMatrix()}t.setRenderTarget(h.map),t.clear();const g=h.getViewportCount();for(let t=0;t=1):-1!==N.indexOf("OpenGL ES")&&(P=parseFloat(/^OpenGL ES (\d)/.exec(N)[1]),R=P>=2);let L=null,U={};const D=t.getParameter(t.SCISSOR_BOX),I=t.getParameter(t.VIEWPORT),O=(new Qa).fromArray(D),k=(new Qa).fromArray(I);function F(e,n,i,r){const s=new Uint8Array(4),a=t.createTexture();t.bindTexture(e,a),t.texParameteri(e,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(e,t.TEXTURE_MAG_FILTER,t.NEAREST);for(let a=0;an||r.height>n)&&(i=n/Math.max(r.width,r.height)),i<1){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap||"undefined"!=typeof VideoFrame&&t instanceof VideoFrame){const n=Math.floor(i*r.width),s=Math.floor(i*r.height);void 0===h&&(h=f(n,s));const a=e?f(n,s):h;return a.width=n,a.height=s,a.getContext("2d").drawImage(t,0,0,n,s),xa("WebGLRenderer: Texture has been resized from ("+r.width+"x"+r.height+") to ("+n+"x"+s+")."),a}return"data"in t&&xa("WebGLRenderer: Image in DataTexture is too big ("+r.width+"x"+r.height+")."),t}return t}function g(t){return t.generateMipmaps}function v(e){t.generateMipmap(e)}function _(e){return e.isWebGLCubeRenderTarget?t.TEXTURE_CUBE_MAP:e.isWebGL3DRenderTarget?t.TEXTURE_3D:e.isWebGLArrayRenderTarget||e.isCompressedArrayTexture?t.TEXTURE_2D_ARRAY:t.TEXTURE_2D}function x(n,i,r,s,a=!1){if(null!==n){if(void 0!==t[n])return t[n];xa("WebGLRenderer: Attempt to use non-existing WebGL internal format '"+n+"'")}let o=i;if(i===t.RED&&(r===t.FLOAT&&(o=t.R32F),r===t.HALF_FLOAT&&(o=t.R16F),r===t.UNSIGNED_BYTE&&(o=t.R8)),i===t.RED_INTEGER&&(r===t.UNSIGNED_BYTE&&(o=t.R8UI),r===t.UNSIGNED_SHORT&&(o=t.R16UI),r===t.UNSIGNED_INT&&(o=t.R32UI),r===t.BYTE&&(o=t.R8I),r===t.SHORT&&(o=t.R16I),r===t.INT&&(o=t.R32I)),i===t.RG&&(r===t.FLOAT&&(o=t.RG32F),r===t.HALF_FLOAT&&(o=t.RG16F),r===t.UNSIGNED_BYTE&&(o=t.RG8)),i===t.RG_INTEGER&&(r===t.UNSIGNED_BYTE&&(o=t.RG8UI),r===t.UNSIGNED_SHORT&&(o=t.RG16UI),r===t.UNSIGNED_INT&&(o=t.RG32UI),r===t.BYTE&&(o=t.RG8I),r===t.SHORT&&(o=t.RG16I),r===t.INT&&(o=t.RG32I)),i===t.RGB_INTEGER&&(r===t.UNSIGNED_BYTE&&(o=t.RGB8UI),r===t.UNSIGNED_SHORT&&(o=t.RGB16UI),r===t.UNSIGNED_INT&&(o=t.RGB32UI),r===t.BYTE&&(o=t.RGB8I),r===t.SHORT&&(o=t.RGB16I),r===t.INT&&(o=t.RGB32I)),i===t.RGBA_INTEGER&&(r===t.UNSIGNED_BYTE&&(o=t.RGBA8UI),r===t.UNSIGNED_SHORT&&(o=t.RGBA16UI),r===t.UNSIGNED_INT&&(o=t.RGBA32UI),r===t.BYTE&&(o=t.RGBA8I),r===t.SHORT&&(o=t.RGBA16I),r===t.INT&&(o=t.RGBA32I)),i===t.RGB&&(r===t.UNSIGNED_INT_5_9_9_9_REV&&(o=t.RGB9_E5),r===t.UNSIGNED_INT_10F_11F_11F_REV&&(o=t.R11F_G11F_B10F)),i===t.RGBA){const e=a?ta:Ha.getTransfer(s);r===t.FLOAT&&(o=t.RGBA32F),r===t.HALF_FLOAT&&(o=t.RGBA16F),r===t.UNSIGNED_BYTE&&(o=e===ea?t.SRGB8_ALPHA8:t.RGBA8),r===t.UNSIGNED_SHORT_4_4_4_4&&(o=t.RGBA4),r===t.UNSIGNED_SHORT_5_5_5_1&&(o=t.RGB5_A1)}return o!==t.R16F&&o!==t.R32F&&o!==t.RG16F&&o!==t.RG32F&&o!==t.RGBA16F&&o!==t.RGBA32F||e.get("EXT_color_buffer_float"),o}function y(e,n){let i;return e?null===n||n===is||n===ls?i=t.DEPTH24_STENCIL8:n===rs?i=t.DEPTH32F_STENCIL8:n===es&&(i=t.DEPTH24_STENCIL8,xa("DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.")):null===n||n===is||n===ls?i=t.DEPTH_COMPONENT24:n===rs?i=t.DEPTH_COMPONENT32F:n===es&&(i=t.DEPTH_COMPONENT16),i}function b(t,e){return!0===g(t)||t.isFramebufferTexture&&t.minFilter!==qr&&t.minFilter!==Kr?Math.log2(Math.max(e.width,e.height))+1:void 0!==t.mipmaps&&t.mipmaps.length>0?t.mipmaps.length:t.isCompressedTexture&&Array.isArray(t.image)?e.mipmaps.length:1}function w(t){const e=t.target;e.removeEventListener("dispose",w),function(t){const e=i.get(t);if(void 0===e.__webglInit)return;const n=t.source,r=d.get(n);if(r){const i=r[e.__cacheKey];i.usedTimes--,0===i.usedTimes&&S(t),0===Object.keys(r).length&&d.delete(n)}i.remove(t)}(e),e.isVideoTexture&&u.delete(e)}function M(e){const n=e.target;n.removeEventListener("dispose",M),function(e){const n=i.get(e);if(e.depthTexture&&(e.depthTexture.dispose(),i.remove(e.depthTexture)),e.isWebGLCubeRenderTarget)for(let e=0;e<6;e++){if(Array.isArray(n.__webglFramebuffer[e]))for(let i=0;i0&&s.__version!==e.version){const t=e.image;if(null===t)xa("WebGLRenderer: Texture marked for update but no image data found.");else{if(!1!==t.complete)return void U(s,e,r);xa("WebGLRenderer: Texture marked for update but image is incomplete")}}else e.isExternalTexture&&(s.__webglTexture=e.sourceTexture?e.sourceTexture:null);n.bindTexture(t.TEXTURE_2D,s.__webglTexture,t.TEXTURE0+r)}const A={[jr]:t.REPEAT,[Xr]:t.CLAMP_TO_EDGE,[$r]:t.MIRRORED_REPEAT},C={[qr]:t.NEAREST,[Yr]:t.NEAREST_MIPMAP_NEAREST,[Zr]:t.NEAREST_MIPMAP_LINEAR,[Kr]:t.LINEAR,[Jr]:t.LINEAR_MIPMAP_NEAREST,[Qr]:t.LINEAR_MIPMAP_LINEAR},R={[ia]:t.NEVER,[ua]:t.ALWAYS,[ra]:t.LESS,[aa]:t.LEQUAL,[sa]:t.EQUAL,[ca]:t.GEQUAL,[oa]:t.GREATER,[la]:t.NOTEQUAL};function P(n,s){if(s.type!==rs||!1!==e.has("OES_texture_float_linear")||s.magFilter!==Kr&&s.magFilter!==Jr&&s.magFilter!==Zr&&s.magFilter!==Qr&&s.minFilter!==Kr&&s.minFilter!==Jr&&s.minFilter!==Zr&&s.minFilter!==Qr||xa("WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device."),t.texParameteri(n,t.TEXTURE_WRAP_S,A[s.wrapS]),t.texParameteri(n,t.TEXTURE_WRAP_T,A[s.wrapT]),n!==t.TEXTURE_3D&&n!==t.TEXTURE_2D_ARRAY||t.texParameteri(n,t.TEXTURE_WRAP_R,A[s.wrapR]),t.texParameteri(n,t.TEXTURE_MAG_FILTER,C[s.magFilter]),t.texParameteri(n,t.TEXTURE_MIN_FILTER,C[s.minFilter]),s.compareFunction&&(t.texParameteri(n,t.TEXTURE_COMPARE_MODE,t.COMPARE_REF_TO_TEXTURE),t.texParameteri(n,t.TEXTURE_COMPARE_FUNC,R[s.compareFunction])),!0===e.has("EXT_texture_filter_anisotropic")){if(s.magFilter===qr)return;if(s.minFilter!==Zr&&s.minFilter!==Qr)return;if(s.type===rs&&!1===e.has("OES_texture_float_linear"))return;if(s.anisotropy>1||i.get(s).__currentAnisotropy){const a=e.get("EXT_texture_filter_anisotropic");t.texParameterf(n,a.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(s.anisotropy,r.getMaxAnisotropy())),i.get(s).__currentAnisotropy=s.anisotropy}}}function N(e,n){let i=!1;void 0===e.__webglInit&&(e.__webglInit=!0,n.addEventListener("dispose",w));const r=n.source;let s=d.get(r);void 0===s&&(s={},d.set(r,s));const o=function(t){const e=[];return e.push(t.wrapS),e.push(t.wrapT),e.push(t.wrapR||0),e.push(t.magFilter),e.push(t.minFilter),e.push(t.anisotropy),e.push(t.internalFormat),e.push(t.format),e.push(t.type),e.push(t.generateMipmaps),e.push(t.premultiplyAlpha),e.push(t.flipY),e.push(t.unpackAlignment),e.push(t.colorSpace),e.join()}(n);if(o!==e.__cacheKey){void 0===s[o]&&(s[o]={texture:t.createTexture(),usedTimes:0},a.memory.textures++,i=!0),s[o].usedTimes++;const r=s[e.__cacheKey];void 0!==r&&(s[e.__cacheKey].usedTimes--,0===r.usedTimes&&S(n)),e.__cacheKey=o,e.__webglTexture=s[o].texture}return i}function L(t,e,n){return Math.floor(Math.floor(t/n)/e)}function U(e,a,o){let l=t.TEXTURE_2D;(a.isDataArrayTexture||a.isCompressedArrayTexture)&&(l=t.TEXTURE_2D_ARRAY),a.isData3DTexture&&(l=t.TEXTURE_3D);const c=N(e,a),u=a.source;n.bindTexture(l,e.__webglTexture,t.TEXTURE0+o);const h=i.get(u);if(u.version!==h.__version||!0===c){n.activeTexture(t.TEXTURE0+o);const e=Ha.getPrimaries(Ha.workingColorSpace),i=a.colorSpace===Ks?null:Ha.getPrimaries(a.colorSpace),d=a.colorSpace===Ks||e===i?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,a.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,a.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,d);let p=m(a.image,!1,r.maxTextureSize);p=H(a,p);const f=s.convert(a.format,a.colorSpace),_=s.convert(a.type);let w,M=x(a.internalFormat,f,_,a.colorSpace,a.isVideoTexture);P(l,a);const S=a.mipmaps,E=!0!==a.isVideoTexture,T=void 0===h.__version||!0===c,A=u.dataReady,C=b(a,p);if(a.isDepthTexture)M=y(a.format===hs,a.type),T&&(E?n.texStorage2D(t.TEXTURE_2D,1,M,p.width,p.height):n.texImage2D(t.TEXTURE_2D,0,M,p.width,p.height,0,f,_,null));else if(a.isDataTexture)if(S.length>0){E&&T&&n.texStorage2D(t.TEXTURE_2D,C,M,S[0].width,S[0].height);for(let e=0,i=S.length;et.start-e.start);let o=0;for(let t=1;t0){const i=Vu(w.width,w.height,a.format,a.type);for(const r of a.layerUpdates){const s=w.data.subarray(r*i/w.data.BYTES_PER_ELEMENT,(r+1)*i/w.data.BYTES_PER_ELEMENT);n.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,r,w.width,w.height,1,f,s)}a.clearLayerUpdates()}else n.compressedTexSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,w.width,w.height,p.depth,f,w.data)}else n.compressedTexImage3D(t.TEXTURE_2D_ARRAY,e,M,w.width,w.height,p.depth,0,w.data,0,0);else xa("WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()");else E?A&&n.texSubImage3D(t.TEXTURE_2D_ARRAY,e,0,0,0,w.width,w.height,p.depth,f,_,w.data):n.texImage3D(t.TEXTURE_2D_ARRAY,e,M,w.width,w.height,p.depth,0,f,_,w.data)}else{E&&T&&n.texStorage2D(t.TEXTURE_2D,C,M,S[0].width,S[0].height);for(let e=0,i=S.length;e0){const e=Vu(p.width,p.height,a.format,a.type);for(const i of a.layerUpdates){const r=p.data.subarray(i*e/p.data.BYTES_PER_ELEMENT,(i+1)*e/p.data.BYTES_PER_ELEMENT);n.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,i,p.width,p.height,1,f,_,r)}a.clearLayerUpdates()}else n.texSubImage3D(t.TEXTURE_2D_ARRAY,0,0,0,0,p.width,p.height,p.depth,f,_,p.data)}else n.texImage3D(t.TEXTURE_2D_ARRAY,0,M,p.width,p.height,p.depth,0,f,_,p.data);else if(a.isData3DTexture)E?(T&&n.texStorage3D(t.TEXTURE_3D,C,M,p.width,p.height,p.depth),A&&n.texSubImage3D(t.TEXTURE_3D,0,0,0,0,p.width,p.height,p.depth,f,_,p.data)):n.texImage3D(t.TEXTURE_3D,0,M,p.width,p.height,p.depth,0,f,_,p.data);else if(a.isFramebufferTexture){if(T)if(E)n.texStorage2D(t.TEXTURE_2D,C,M,p.width,p.height);else{let e=p.width,i=p.height;for(let r=0;r>=1,i>>=1}}else if(S.length>0){if(E&&T){const e=G(S[0]);n.texStorage2D(t.TEXTURE_2D,C,M,e.width,e.height)}for(let e=0,i=S.length;e>u),i=Math.max(1,r.height>>u);c===t.TEXTURE_3D||c===t.TEXTURE_2D_ARRAY?n.texImage3D(c,u,p,e,i,r.depth,0,h,d,null):n.texImage2D(c,u,p,e,i,0,h,d,null)}n.bindFramebuffer(t.FRAMEBUFFER,e),V(r)?o.framebufferTexture2DMultisampleEXT(t.FRAMEBUFFER,l,c,m.__webglTexture,0,z(r)):(c===t.TEXTURE_2D||c>=t.TEXTURE_CUBE_MAP_POSITIVE_X&&c<=t.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&t.framebufferTexture2D(t.FRAMEBUFFER,l,c,m.__webglTexture,u),n.bindFramebuffer(t.FRAMEBUFFER,null)}function I(e,n,i){if(t.bindRenderbuffer(t.RENDERBUFFER,e),n.depthBuffer){const r=n.depthTexture,s=r&&r.isDepthTexture?r.type:null,a=y(n.stencilBuffer,s),l=n.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,c=z(n);V(n)?o.renderbufferStorageMultisampleEXT(t.RENDERBUFFER,c,a,n.width,n.height):i?t.renderbufferStorageMultisample(t.RENDERBUFFER,c,a,n.width,n.height):t.renderbufferStorage(t.RENDERBUFFER,a,n.width,n.height),t.framebufferRenderbuffer(t.FRAMEBUFFER,l,t.RENDERBUFFER,e)}else{const e=n.textures;for(let r=0;r{delete r.__boundDepthTexture,delete r.__depthDisposeCallback,t.removeEventListener("dispose",e)};t.addEventListener("dispose",e),r.__depthDisposeCallback=e}r.__boundDepthTexture=t}if(e.depthTexture&&!r.__autoAllocateDepthBuffer){if(s)throw new Error("target.depthTexture not supported in Cube render targets");const t=e.texture.mipmaps;t&&t.length>0?O(r.__webglFramebuffer[0],e):O(r.__webglFramebuffer,e)}else if(s){r.__webglDepthbuffer=[];for(let i=0;i<6;i++)if(n.bindFramebuffer(t.FRAMEBUFFER,r.__webglFramebuffer[i]),void 0===r.__webglDepthbuffer[i])r.__webglDepthbuffer[i]=t.createRenderbuffer(),I(r.__webglDepthbuffer[i],e,!1);else{const n=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,s=r.__webglDepthbuffer[i];t.bindRenderbuffer(t.RENDERBUFFER,s),t.framebufferRenderbuffer(t.FRAMEBUFFER,n,t.RENDERBUFFER,s)}}else{const i=e.texture.mipmaps;if(i&&i.length>0?n.bindFramebuffer(t.FRAMEBUFFER,r.__webglFramebuffer[0]):n.bindFramebuffer(t.FRAMEBUFFER,r.__webglFramebuffer),void 0===r.__webglDepthbuffer)r.__webglDepthbuffer=t.createRenderbuffer(),I(r.__webglDepthbuffer,e,!1);else{const n=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,i=r.__webglDepthbuffer;t.bindRenderbuffer(t.RENDERBUFFER,i),t.framebufferRenderbuffer(t.FRAMEBUFFER,n,t.RENDERBUFFER,i)}}n.bindFramebuffer(t.FRAMEBUFFER,null)}const F=[],B=[];function z(t){return Math.min(r.maxSamples,t.samples)}function V(t){const n=i.get(t);return t.samples>0&&!0===e.has("WEBGL_multisampled_render_to_texture")&&!1!==n.__useRenderToTexture}function H(t,e){const n=t.colorSpace,i=t.format,r=t.type;return!0===t.isCompressedTexture||!0===t.isVideoTexture||n!==Qs&&n!==Ks&&(Ha.getTransfer(n)===ea?i===cs&&r===ts||xa("WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):ya("WebGLTextures: Unsupported texture color space:",n)),e}function G(t){return"undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement?(c.width=t.naturalWidth||t.width,c.height=t.naturalHeight||t.height):"undefined"!=typeof VideoFrame&&t instanceof VideoFrame?(c.width=t.displayWidth,c.height=t.displayHeight):(c.width=t.width,c.height=t.height),c}this.allocateTextureUnit=function(){const t=E;return t>=r.maxTextures&&xa("WebGLTextures: Trying to use "+t+" texture units while this GPU supports only "+r.maxTextures),E+=1,t},this.resetTextureUnits=function(){E=0},this.setTexture2D=T,this.setTexture2DArray=function(e,r){const s=i.get(e);!1===e.isRenderTargetTexture&&e.version>0&&s.__version!==e.version?U(s,e,r):(e.isExternalTexture&&(s.__webglTexture=e.sourceTexture?e.sourceTexture:null),n.bindTexture(t.TEXTURE_2D_ARRAY,s.__webglTexture,t.TEXTURE0+r))},this.setTexture3D=function(e,r){const s=i.get(e);!1===e.isRenderTargetTexture&&e.version>0&&s.__version!==e.version?U(s,e,r):n.bindTexture(t.TEXTURE_3D,s.__webglTexture,t.TEXTURE0+r)},this.setTextureCube=function(e,a){const o=i.get(e);e.version>0&&o.__version!==e.version?function(e,a,o){if(6!==a.image.length)return;const l=N(e,a),c=a.source;n.bindTexture(t.TEXTURE_CUBE_MAP,e.__webglTexture,t.TEXTURE0+o);const u=i.get(c);if(c.version!==u.__version||!0===l){n.activeTexture(t.TEXTURE0+o);const e=Ha.getPrimaries(Ha.workingColorSpace),i=a.colorSpace===Ks?null:Ha.getPrimaries(a.colorSpace),h=a.colorSpace===Ks||e===i?t.NONE:t.BROWSER_DEFAULT_WEBGL;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,a.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,a.unpackAlignment),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,h);const d=a.isCompressedTexture||a.image[0].isCompressedTexture,p=a.image[0]&&a.image[0].isDataTexture,f=[];for(let t=0;t<6;t++)f[t]=d||p?p?a.image[t].image:a.image[t]:m(a.image[t],!0,r.maxCubemapSize),f[t]=H(a,f[t]);const _=f[0],y=s.convert(a.format,a.colorSpace),w=s.convert(a.type),M=x(a.internalFormat,y,w,a.colorSpace),S=!0!==a.isVideoTexture,E=void 0===u.__version||!0===l,T=c.dataReady;let A,C=b(a,_);if(P(t.TEXTURE_CUBE_MAP,a),d){S&&E&&n.texStorage2D(t.TEXTURE_CUBE_MAP,C,M,_.width,_.height);for(let e=0;e<6;e++){A=f[e].mipmaps;for(let i=0;i0&&C++;const e=G(f[0]);n.texStorage2D(t.TEXTURE_CUBE_MAP,C,M,e.width,e.height)}for(let e=0;e<6;e++)if(p){S?T&&n.texSubImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,0,0,f[e].width,f[e].height,y,w,f[e].data):n.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+e,0,M,f[e].width,f[e].height,0,y,w,f[e].data);for(let i=0;i1;if(h||(void 0===l.__webglTexture&&(l.__webglTexture=t.createTexture()),l.__version=r.version,a.memory.textures++),u){o.__webglFramebuffer=[];for(let e=0;e<6;e++)if(r.mipmaps&&r.mipmaps.length>0){o.__webglFramebuffer[e]=[];for(let n=0;n0){o.__webglFramebuffer=[];for(let e=0;e0&&!1===V(e)){o.__webglMultisampledFramebuffer=t.createFramebuffer(),o.__webglColorRenderbuffer=[],n.bindFramebuffer(t.FRAMEBUFFER,o.__webglMultisampledFramebuffer);for(let n=0;n0)for(let i=0;i0)for(let n=0;n0)if(!1===V(e)){const r=e.textures,s=e.width,a=e.height;let o=t.COLOR_BUFFER_BIT;const c=e.stencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT,u=i.get(e),h=r.length>1;if(h)for(let e=0;e0?n.bindFramebuffer(t.DRAW_FRAMEBUFFER,u.__webglFramebuffer[0]):n.bindFramebuffer(t.DRAW_FRAMEBUFFER,u.__webglFramebuffer);for(let n=0;n= 1.0 ) {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;\n\n\t} else {\n\n\t\tgl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;\n\n\t}\n\n}",uniforms:{depthColor:{value:this.texture},depthWidth:{value:e.z},depthHeight:{value:e.w}}});this.mesh=new ec(new tu(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}}class pp extends wa{constructor(t,e){super();const n=this;let i=null,r=1,s=null,a="local-floor",o=1,l=null,c=null,u=null,h=null,d=null,p=null;const f="undefined"!=typeof XRWebGLBinding,m=new dp,g={},v=e.getContextAttributes();let _=null,x=null;const y=[],b=[],w=new La;let M=null;const S=new pc;S.viewport=new Qa;const E=new pc;E.viewport=new Qa;const T=[S,E],A=new Eu;let C=null,R=null;function P(t){const e=b.indexOf(t.inputSource);if(-1===e)return;const n=y[e];void 0!==n&&(n.update(t.inputSource,t.frame,l||s),n.dispatchEvent({type:t.type,data:t.inputSource}))}function N(){i.removeEventListener("select",P),i.removeEventListener("selectstart",P),i.removeEventListener("selectend",P),i.removeEventListener("squeeze",P),i.removeEventListener("squeezestart",P),i.removeEventListener("squeezeend",P),i.removeEventListener("end",N),i.removeEventListener("inputsourceschange",L);for(let t=0;t=0&&(b[i]=null,y[i].disconnect(n))}for(let e=0;e=b.length){b.push(n),i=t;break}if(null===b[t]){b[t]=n,i=t;break}}if(-1===i)break}const r=y[i];r&&r.connect(n)}}this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(t){let e=y[t];return void 0===e&&(e=new yc,y[t]=e),e.getTargetRaySpace()},this.getControllerGrip=function(t){let e=y[t];return void 0===e&&(e=new yc,y[t]=e),e.getGripSpace()},this.getHand=function(t){let e=y[t];return void 0===e&&(e=new yc,y[t]=e),e.getHandSpace()},this.setFramebufferScaleFactor=function(t){r=t,!0===n.isPresenting&&xa("WebXRManager: Cannot change framebuffer scale while presenting.")},this.setReferenceSpaceType=function(t){a=t,!0===n.isPresenting&&xa("WebXRManager: Cannot change reference space type while presenting.")},this.getReferenceSpace=function(){return l||s},this.setReferenceSpace=function(t){l=t},this.getBaseLayer=function(){return null!==h?h:d},this.getBinding=function(){return null===u&&f&&(u=new XRWebGLBinding(i,e)),u},this.getFrame=function(){return p},this.getSession=function(){return i},this.setSession=async function(c){if(i=c,null!==i){if(_=t.getRenderTarget(),i.addEventListener("select",P),i.addEventListener("selectstart",P),i.addEventListener("selectend",P),i.addEventListener("squeeze",P),i.addEventListener("squeezestart",P),i.addEventListener("squeezeend",P),i.addEventListener("end",N),i.addEventListener("inputsourceschange",L),!0!==v.xrCompatible&&await e.makeXRCompatible(),M=t.getPixelRatio(),t.getSize(w),f&&"createProjectionLayer"in XRWebGLBinding.prototype){let n=null,s=null,a=null;v.depth&&(a=v.stencil?e.DEPTH24_STENCIL8:e.DEPTH_COMPONENT24,n=v.stencil?hs:us,s=v.stencil?ls:is);const o={colorFormat:e.RGBA8,depthFormat:a,scaleFactor:r};u=this.getBinding(),h=u.createProjectionLayer(o),i.updateRenderState({layers:[h]}),t.setPixelRatio(1),t.setSize(h.textureWidth,h.textureHeight,!1),x=new eo(h.textureWidth,h.textureHeight,{format:cs,type:ts,depthTexture:new jc(h.textureWidth,h.textureHeight,s,void 0,void 0,void 0,void 0,void 0,void 0,n),stencilBuffer:v.stencil,colorSpace:t.outputColorSpace,samples:v.antialias?4:0,resolveDepthBuffer:!1===h.ignoreDepthValues,resolveStencilBuffer:!1===h.ignoreDepthValues})}else{const n={antialias:v.antialias,alpha:!0,depth:v.depth,stencil:v.stencil,framebufferScaleFactor:r};d=new XRWebGLLayer(i,e,n),i.updateRenderState({baseLayer:d}),t.setPixelRatio(1),t.setSize(d.framebufferWidth,d.framebufferHeight,!1),x=new eo(d.framebufferWidth,d.framebufferHeight,{format:cs,type:ts,colorSpace:t.outputColorSpace,stencilBuffer:v.stencil,resolveDepthBuffer:!1===d.ignoreDepthValues,resolveStencilBuffer:!1===d.ignoreDepthValues})}x.isXRRenderTarget=!0,this.setFoveation(o),l=null,s=await i.requestReferenceSpace(a),k.setContext(i),k.start(),n.isPresenting=!0,n.dispatchEvent({type:"sessionstart"})}},this.getEnvironmentBlendMode=function(){if(null!==i)return i.environmentBlendMode},this.getDepthTexture=function(){return m.getDepthTexture()};const U=new Da,D=new Da;function I(t,e){null===e?t.matrixWorld.copy(t.matrix):t.matrixWorld.multiplyMatrices(e.matrixWorld,t.matrix),t.matrixWorldInverse.copy(t.matrixWorld).invert()}this.updateCamera=function(t){if(null===i)return;let e=t.near,n=t.far;null!==m.texture&&(m.depthNear>0&&(e=m.depthNear),m.depthFar>0&&(n=m.depthFar)),A.near=E.near=S.near=e,A.far=E.far=S.far=n,C===A.near&&R===A.far||(i.updateRenderState({depthNear:A.near,depthFar:A.far}),C=A.near,R=A.far),A.layers.mask=6|t.layers.mask,S.layers.mask=3&A.layers.mask,E.layers.mask=5&A.layers.mask;const r=t.parent,s=A.cameras;I(A,r);for(let t=0;t0&&(t.alphaTest.value=i.alphaTest);const r=e.get(i),s=r.envMap,a=r.envMapRotation;s&&(t.envMap.value=s,fp.copy(a),fp.x*=-1,fp.y*=-1,fp.z*=-1,s.isCubeTexture&&!1===s.isRenderTargetTexture&&(fp.y*=-1,fp.z*=-1),t.envMapRotation.value.setFromMatrix4(mp.makeRotationFromEuler(fp)),t.flipEnvMap.value=s.isCubeTexture&&!1===s.isRenderTargetTexture?-1:1,t.reflectivity.value=i.reflectivity,t.ior.value=i.ior,t.refractionRatio.value=i.refractionRatio),i.lightMap&&(t.lightMap.value=i.lightMap,t.lightMapIntensity.value=i.lightMapIntensity,n(i.lightMap,t.lightMapTransform)),i.aoMap&&(t.aoMap.value=i.aoMap,t.aoMapIntensity.value=i.aoMapIntensity,n(i.aoMap,t.aoMapTransform))}return{refreshFogUniforms:function(e,n){n.color.getRGB(e.fogColor.value,ac(t)),n.isFog?(e.fogNear.value=n.near,e.fogFar.value=n.far):n.isFogExp2&&(e.fogDensity.value=n.density)},refreshMaterialUniforms:function(t,r,s,a,o){r.isMeshBasicMaterial||r.isMeshLambertMaterial?i(t,r):r.isMeshToonMaterial?(i(t,r),function(t,e){e.gradientMap&&(t.gradientMap.value=e.gradientMap)}(t,r)):r.isMeshPhongMaterial?(i(t,r),function(t,e){t.specular.value.copy(e.specular),t.shininess.value=Math.max(e.shininess,1e-4)}(t,r)):r.isMeshStandardMaterial?(i(t,r),function(t,e){t.metalness.value=e.metalness,e.metalnessMap&&(t.metalnessMap.value=e.metalnessMap,n(e.metalnessMap,t.metalnessMapTransform)),t.roughness.value=e.roughness,e.roughnessMap&&(t.roughnessMap.value=e.roughnessMap,n(e.roughnessMap,t.roughnessMapTransform)),e.envMap&&(t.envMapIntensity.value=e.envMapIntensity)}(t,r),r.isMeshPhysicalMaterial&&function(t,e,i){t.ior.value=e.ior,e.sheen>0&&(t.sheenColor.value.copy(e.sheenColor).multiplyScalar(e.sheen),t.sheenRoughness.value=e.sheenRoughness,e.sheenColorMap&&(t.sheenColorMap.value=e.sheenColorMap,n(e.sheenColorMap,t.sheenColorMapTransform)),e.sheenRoughnessMap&&(t.sheenRoughnessMap.value=e.sheenRoughnessMap,n(e.sheenRoughnessMap,t.sheenRoughnessMapTransform))),e.clearcoat>0&&(t.clearcoat.value=e.clearcoat,t.clearcoatRoughness.value=e.clearcoatRoughness,e.clearcoatMap&&(t.clearcoatMap.value=e.clearcoatMap,n(e.clearcoatMap,t.clearcoatMapTransform)),e.clearcoatRoughnessMap&&(t.clearcoatRoughnessMap.value=e.clearcoatRoughnessMap,n(e.clearcoatRoughnessMap,t.clearcoatRoughnessMapTransform)),e.clearcoatNormalMap&&(t.clearcoatNormalMap.value=e.clearcoatNormalMap,n(e.clearcoatNormalMap,t.clearcoatNormalMapTransform),t.clearcoatNormalScale.value.copy(e.clearcoatNormalScale),1===e.side&&t.clearcoatNormalScale.value.negate())),e.dispersion>0&&(t.dispersion.value=e.dispersion),e.iridescence>0&&(t.iridescence.value=e.iridescence,t.iridescenceIOR.value=e.iridescenceIOR,t.iridescenceThicknessMinimum.value=e.iridescenceThicknessRange[0],t.iridescenceThicknessMaximum.value=e.iridescenceThicknessRange[1],e.iridescenceMap&&(t.iridescenceMap.value=e.iridescenceMap,n(e.iridescenceMap,t.iridescenceMapTransform)),e.iridescenceThicknessMap&&(t.iridescenceThicknessMap.value=e.iridescenceThicknessMap,n(e.iridescenceThicknessMap,t.iridescenceThicknessMapTransform))),e.transmission>0&&(t.transmission.value=e.transmission,t.transmissionSamplerMap.value=i.texture,t.transmissionSamplerSize.value.set(i.width,i.height),e.transmissionMap&&(t.transmissionMap.value=e.transmissionMap,n(e.transmissionMap,t.transmissionMapTransform)),t.thickness.value=e.thickness,e.thicknessMap&&(t.thicknessMap.value=e.thicknessMap,n(e.thicknessMap,t.thicknessMapTransform)),t.attenuationDistance.value=e.attenuationDistance,t.attenuationColor.value.copy(e.attenuationColor)),e.anisotropy>0&&(t.anisotropyVector.value.set(e.anisotropy*Math.cos(e.anisotropyRotation),e.anisotropy*Math.sin(e.anisotropyRotation)),e.anisotropyMap&&(t.anisotropyMap.value=e.anisotropyMap,n(e.anisotropyMap,t.anisotropyMapTransform))),t.specularIntensity.value=e.specularIntensity,t.specularColor.value.copy(e.specularColor),e.specularColorMap&&(t.specularColorMap.value=e.specularColorMap,n(e.specularColorMap,t.specularColorMapTransform)),e.specularIntensityMap&&(t.specularIntensityMap.value=e.specularIntensityMap,n(e.specularIntensityMap,t.specularIntensityMapTransform))}(t,r,o)):r.isMeshMatcapMaterial?(i(t,r),function(t,e){e.matcap&&(t.matcap.value=e.matcap)}(t,r)):r.isMeshDepthMaterial?i(t,r):r.isMeshDistanceMaterial?(i(t,r),function(t,n){const i=e.get(n).light;t.referencePosition.value.setFromMatrixPosition(i.matrixWorld),t.nearDistance.value=i.shadow.camera.near,t.farDistance.value=i.shadow.camera.far}(t,r)):r.isMeshNormalMaterial?i(t,r):r.isLineBasicMaterial?(function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,e.map&&(t.map.value=e.map,n(e.map,t.mapTransform))}(t,r),r.isLineDashedMaterial&&function(t,e){t.dashSize.value=e.dashSize,t.totalSize.value=e.dashSize+e.gapSize,t.scale.value=e.scale}(t,r)):r.isPointsMaterial?function(t,e,i,r){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.size.value=e.size*i,t.scale.value=.5*r,e.map&&(t.map.value=e.map,n(e.map,t.uvTransform)),e.alphaMap&&(t.alphaMap.value=e.alphaMap,n(e.alphaMap,t.alphaMapTransform)),e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,r,s,a):r.isSpriteMaterial?function(t,e){t.diffuse.value.copy(e.color),t.opacity.value=e.opacity,t.rotation.value=e.rotation,e.map&&(t.map.value=e.map,n(e.map,t.mapTransform)),e.alphaMap&&(t.alphaMap.value=e.alphaMap,n(e.alphaMap,t.alphaMapTransform)),e.alphaTest>0&&(t.alphaTest.value=e.alphaTest)}(t,r):r.isShadowMaterial?(t.color.value.copy(r.color),t.opacity.value=r.opacity):r.isShaderMaterial&&(r.uniformsNeedUpdate=!1)}}}function vp(t,e,n,i){let r={},s={},a=[];const o=t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS);function l(t,e,n,i){const r=t.value,s=e+"_"+n;if(void 0===i[s])return i[s]="number"==typeof r||"boolean"==typeof r?r:r.clone(),!0;{const t=i[s];if("number"==typeof r||"boolean"==typeof r){if(t!==r)return i[s]=r,!0}else if(!1===t.equals(r))return t.copy(r),!0}return!1}function c(t){const e={boundary:0,storage:0};return"number"==typeof t||"boolean"==typeof t?(e.boundary=4,e.storage=4):t.isVector2?(e.boundary=8,e.storage=8):t.isVector3||t.isColor?(e.boundary=16,e.storage=12):t.isVector4?(e.boundary=16,e.storage=16):t.isMatrix3?(e.boundary=48,e.storage=48):t.isMatrix4?(e.boundary=64,e.storage=64):t.isTexture?xa("WebGLRenderer: Texture samplers can not be part of an uniforms group."):xa("WebGLRenderer: Unsupported uniform value type.",t),e}function u(e){const n=e.target;n.removeEventListener("dispose",u);const i=a.indexOf(n.__bindingPointIndex);a.splice(i,1),t.deleteBuffer(r[n.id]),delete r[n.id],delete s[n.id]}return{bind:function(t,e){const n=e.program;i.uniformBlockBinding(t,n)},update:function(n,h){let d=r[n.id];void 0===d&&(function(t){const e=t.uniforms;let n=0;for(let t=0,i=e.length;t0&&(n+=16-i),t.__size=n,t.__cache={}}(n),d=function(e){const n=function(){for(let t=0;t0),h=!!n.morphAttributes.position,d=!!n.morphAttributes.normal,p=!!n.morphAttributes.color;let f=0;i.toneMapped&&(null!==E&&!0!==E.isXRRenderTarget||(f=b.toneMapping));const m=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,g=void 0!==m?m.length:0,v=tt.get(i),x=_.state.lights;if(!0===H&&(!0===G||t!==A)){const e=t===A&&i.id===T;ht.setState(i,t,e)}let y=!1;i.version===v.__version?v.needsLights&&v.lightsStateVersion!==x.state.version||v.outputColorSpace!==o||r.isBatchedMesh&&!1===v.batching?y=!0:r.isBatchedMesh||!0!==v.batching?r.isBatchedMesh&&!0===v.batchingColor&&null===r.colorTexture||r.isBatchedMesh&&!1===v.batchingColor&&null!==r.colorTexture||r.isInstancedMesh&&!1===v.instancing?y=!0:r.isInstancedMesh||!0!==v.instancing?r.isSkinnedMesh&&!1===v.skinning?y=!0:r.isSkinnedMesh||!0!==v.skinning?r.isInstancedMesh&&!0===v.instancingColor&&null===r.instanceColor||r.isInstancedMesh&&!1===v.instancingColor&&null!==r.instanceColor||r.isInstancedMesh&&!0===v.instancingMorph&&null===r.morphTexture||r.isInstancedMesh&&!1===v.instancingMorph&&null!==r.morphTexture||v.envMap!==l||!0===i.fog&&v.fog!==s?y=!0:void 0===v.numClippingPlanes||v.numClippingPlanes===ht.numPlanes&&v.numIntersection===ht.numIntersection?(v.vertexAlphas!==c||v.vertexTangents!==u||v.morphTargets!==h||v.morphNormals!==d||v.morphColors!==p||v.toneMapping!==f||v.morphTargetsCount!==g)&&(y=!0):y=!0:y=!0:y=!0:y=!0:(y=!0,v.__version=i.version);let w=v.currentProgram;!0===y&&(w=Ft(i,e,r));let M=!1,S=!1,C=!1;const R=w.getUniforms(),P=v.uniforms;if(J.useProgram(w.program)&&(M=!0,S=!0,C=!0),i.id!==T&&(T=i.id,S=!0),M||A!==t){J.buffers.depth.getReversed()&&!0!==t.reversedDepth&&(t._reversedDepth=!0,t.updateProjectionMatrix()),R.setValue(yt,"projectionMatrix",t.projectionMatrix),R.setValue(yt,"viewMatrix",t.matrixWorldInverse);const e=R.map.cameraPosition;void 0!==e&&e.setValue(yt,j.setFromMatrixPosition(t.matrixWorld)),K.logarithmicDepthBuffer&&R.setValue(yt,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),(i.isMeshPhongMaterial||i.isMeshToonMaterial||i.isMeshLambertMaterial||i.isMeshBasicMaterial||i.isMeshStandardMaterial||i.isShaderMaterial)&&R.setValue(yt,"isOrthographic",!0===t.isOrthographicCamera),A!==t&&(A=t,S=!0,C=!0)}if(r.isSkinnedMesh){R.setOptional(yt,r,"bindMatrix"),R.setOptional(yt,r,"bindMatrixInverse");const t=r.skeleton;t&&(null===t.boneTexture&&t.computeBoneTexture(),R.setValue(yt,"boneTexture",t.boneTexture,et))}r.isBatchedMesh&&(R.setOptional(yt,r,"batchingTexture"),R.setValue(yt,"batchingTexture",r._matricesTexture,et),R.setOptional(yt,r,"batchingIdTexture"),R.setValue(yt,"batchingIdTexture",r._indirectTexture,et),R.setOptional(yt,r,"batchingColorTexture"),null!==r._colorsTexture&&R.setValue(yt,"batchingColorTexture",r._colorsTexture,et));const N=n.morphAttributes;if(void 0===N.position&&void 0===N.normal&&void 0===N.color||ft.update(r,n,w),(S||v.receiveShadow!==r.receiveShadow)&&(v.receiveShadow=r.receiveShadow,R.setValue(yt,"receiveShadow",r.receiveShadow)),i.isMeshGouraudMaterial&&null!==i.envMap&&(P.envMap.value=l,P.flipEnvMap.value=l.isCubeTexture&&!1===l.isRenderTargetTexture?-1:1),i.isMeshStandardMaterial&&null===i.envMap&&null!==e.environment&&(P.envMapIntensity.value=e.environmentIntensity),void 0!==P.dfgLUT&&(P.dfgLUT.value=(null===xp&&(xp=new wc(_p,32,32,ps,ss),xp.minFilter=Kr,xp.magFilter=Kr,xp.wrapS=Xr,xp.wrapT=Xr,xp.generateMipmaps=!1,xp.needsUpdate=!0),xp)),S&&(R.setValue(yt,"toneMappingExposure",b.toneMappingExposure),v.needsLights&&function(t,e){t.ambientLightColor.needsUpdate=e,t.lightProbe.needsUpdate=e,t.directionalLights.needsUpdate=e,t.directionalLightShadows.needsUpdate=e,t.pointLights.needsUpdate=e,t.pointLightShadows.needsUpdate=e,t.spotLights.needsUpdate=e,t.spotLightShadows.needsUpdate=e,t.rectAreaLights.needsUpdate=e,t.hemisphereLights.needsUpdate=e}(P,C),s&&!0===i.fog&<.refreshFogUniforms(P,s),lt.refreshMaterialUniforms(P,i,I,D,_.state.transmissionRenderTarget[t.id]),Td.upload(yt,Bt(v),P,et)),i.isShaderMaterial&&!0===i.uniformsNeedUpdate&&(Td.upload(yt,Bt(v),P,et),i.uniformsNeedUpdate=!1),i.isSpriteMaterial&&R.setValue(yt,"center",r.center),R.setValue(yt,"modelViewMatrix",r.modelViewMatrix),R.setValue(yt,"normalMatrix",r.normalMatrix),R.setValue(yt,"modelMatrix",r.matrixWorld),i.isShaderMaterial||i.isRawShaderMaterial){const t=i.uniformsGroups;for(let e=0,n=t.length;e{function n(){i.forEach(function(t){tt.get(t).currentProgram.isReady()&&i.delete(t)}),0!==i.size?setTimeout(n,10):e(t)}null!==Z.get("KHR_parallel_shader_compile")?n():setTimeout(n,10)})};let Rt=null;function Pt(){Lt.stop()}function Nt(){Lt.start()}const Lt=new Hu;function Ut(t,e,n,i){if(!1===t.visible)return;if(t.layers.test(e.layers))if(t.isGroup)n=t.renderOrder;else if(t.isLOD)!0===t.autoUpdate&&t.update(e);else if(t.isLight)_.pushLight(t),t.castShadow&&_.pushShadow(t);else if(t.isSprite){if(!t.frustumCulled||V.intersectsSprite(t)){i&&X.setFromMatrixPosition(t.matrixWorld).applyMatrix4(W);const e=at.update(t),r=t.material;r.visible&&v.push(t,e,r,n,X.z,null)}}else if((t.isMesh||t.isLine||t.isPoints)&&(!t.frustumCulled||V.intersectsObject(t))){const e=at.update(t),r=t.material;if(i&&(void 0!==t.boundingSphere?(null===t.boundingSphere&&t.computeBoundingSphere(),X.copy(t.boundingSphere.center)):(null===e.boundingSphere&&e.computeBoundingSphere(),X.copy(e.boundingSphere.center)),X.applyMatrix4(t.matrixWorld).applyMatrix4(W)),Array.isArray(r)){const i=e.groups;for(let s=0,a=i.length;s0&&Ot(r,e,n),s.length>0&&Ot(s,e,n),a.length>0&&Ot(a,e,n),J.buffers.depth.setTest(!0),J.buffers.depth.setMask(!0),J.buffers.color.setMask(!0),J.setPolygonOffset(!1)}function It(t,e,n,i){if(null!==(!0===n.isScene?n.overrideMaterial:null))return;void 0===_.state.transmissionRenderTarget[i.id]&&(_.state.transmissionRenderTarget[i.id]=new eo(1,1,{generateMipmaps:!0,type:Z.has("EXT_color_buffer_half_float")||Z.has("EXT_color_buffer_float")?ss:ts,minFilter:Qr,samples:4,stencilBuffer:r,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Ha.workingColorSpace}));const s=_.state.transmissionRenderTarget[i.id],a=i.viewport||C;s.setSize(a.z*b.transmissionResolutionScale,a.w*b.transmissionResolutionScale);const o=b.getRenderTarget(),l=b.getActiveCubeFace(),c=b.getActiveMipmapLevel();b.setRenderTarget(s),b.getClearColor(N),L=b.getClearAlpha(),L<1&&b.setClearColor(16777215,.5),b.clear(),q&&pt.render(n);const u=b.toneMapping;b.toneMapping=0;const h=i.viewport;if(void 0!==i.viewport&&(i.viewport=void 0),_.setupLightsView(i),!0===H&&ht.setGlobalState(b.clippingPlanes,i),Ot(t,n,i),et.updateMultisampleRenderTarget(s),et.updateRenderTargetMipmap(s),!1===Z.has("WEBGL_multisampled_render_to_texture")){let t=!1;for(let r=0,s=e.length;r0)for(let e=0,s=n.length;e0&&It(i,r,t,e),q&&pt.render(t),Dt(v,t,e);null!==E&&0===S&&(et.updateMultisampleRenderTarget(E),et.updateRenderTargetMipmap(E)),!0===t.isScene&&t.onAfterRender(b,t,e),_t.resetDefaultState(),T=-1,A=null,y.pop(),y.length>0?(_=y[y.length-1],!0===H&&ht.setGlobalState(b.clippingPlanes,_.state.camera)):_=null,x.pop(),v=x.length>0?x[x.length-1]:null},this.getActiveCubeFace=function(){return M},this.getActiveMipmapLevel=function(){return S},this.getRenderTarget=function(){return E},this.setRenderTargetTextures=function(t,e,n){const i=tt.get(t);i.__autoAllocateDepthBuffer=!1===t.resolveDepthBuffer,!1===i.__autoAllocateDepthBuffer&&(i.__useRenderToTexture=!1),tt.get(t.texture).__webglTexture=e,tt.get(t.depthTexture).__webglTexture=i.__autoAllocateDepthBuffer?void 0:n,i.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(t,e){const n=tt.get(t);n.__webglFramebuffer=e,n.__useDefaultFramebuffer=void 0===e};const Vt=yt.createFramebuffer();this.setRenderTarget=function(t,e=0,n=0){E=t,M=e,S=n;let i=!0,r=null,s=!1,a=!1;if(t){const o=tt.get(t);if(void 0!==o.__useDefaultFramebuffer)J.bindFramebuffer(yt.FRAMEBUFFER,null),i=!1;else if(void 0===o.__webglFramebuffer)et.setupRenderTarget(t);else if(o.__hasExternalTextures)et.rebindTextures(t,tt.get(t.texture).__webglTexture,tt.get(t.depthTexture).__webglTexture);else if(t.depthBuffer){const e=t.depthTexture;if(o.__boundDepthTexture!==e){if(null!==e&&tt.has(e)&&(t.width!==e.image.width||t.height!==e.image.height))throw new Error("WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.");et.setupDepthRenderbuffer(t)}}const l=t.texture;(l.isData3DTexture||l.isDataArrayTexture||l.isCompressedArrayTexture)&&(a=!0);const c=tt.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(r=Array.isArray(c[e])?c[e][n]:c[e],s=!0):r=t.samples>0&&!1===et.useMultisampledRTT(t)?tt.get(t).__webglMultisampledFramebuffer:Array.isArray(c)?c[n]:c,C.copy(t.viewport),R.copy(t.scissor),P=t.scissorTest}else C.copy(F).multiplyScalar(I).floor(),R.copy(B).multiplyScalar(I).floor(),P=z;if(0!==n&&(r=Vt),J.bindFramebuffer(yt.FRAMEBUFFER,r)&&i&&J.drawBuffers(t,r),J.viewport(C),J.scissor(R),J.setScissorTest(P),s){const i=tt.get(t.texture);yt.framebufferTexture2D(yt.FRAMEBUFFER,yt.COLOR_ATTACHMENT0,yt.TEXTURE_CUBE_MAP_POSITIVE_X+e,i.__webglTexture,n)}else if(a){const i=e;for(let e=0;e=0&&e<=t.width-i&&n>=0&&n<=t.height-r&&(t.textures.length>1&&yt.readBuffer(yt.COLOR_ATTACHMENT0+o),yt.readPixels(e,n,i,r,vt.convert(l),vt.convert(c),s))}finally{const t=null!==E?tt.get(E).__webglFramebuffer:null;J.bindFramebuffer(yt.FRAMEBUFFER,t)}}},this.readRenderTargetPixelsAsync=async function(t,e,n,i,r,s,a,o=0){if(!t||!t.isWebGLRenderTarget)throw new Error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");let l=tt.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==a&&(l=l[a]),l){if(e>=0&&e<=t.width-i&&n>=0&&n<=t.height-r){J.bindFramebuffer(yt.FRAMEBUFFER,l);const a=t.textures[o],c=a.format,u=a.type;if(!K.textureFormatReadable(c))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.");if(!K.textureTypeReadable(u))throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.");const h=yt.createBuffer();yt.bindBuffer(yt.PIXEL_PACK_BUFFER,h),yt.bufferData(yt.PIXEL_PACK_BUFFER,s.byteLength,yt.STREAM_READ),t.textures.length>1&&yt.readBuffer(yt.COLOR_ATTACHMENT0+o),yt.readPixels(e,n,i,r,vt.convert(c),vt.convert(u),0);const d=null!==E?tt.get(E).__webglFramebuffer:null;J.bindFramebuffer(yt.FRAMEBUFFER,d);const p=yt.fenceSync(yt.SYNC_GPU_COMMANDS_COMPLETE,0);return yt.flush(),await function(t,e){return new Promise(function(n,i){setTimeout(function r(){switch(t.clientWaitSync(e,t.SYNC_FLUSH_COMMANDS_BIT,0)){case t.WAIT_FAILED:i();break;case t.TIMEOUT_EXPIRED:setTimeout(r,4);break;default:n()}},4)})}(yt,p),yt.bindBuffer(yt.PIXEL_PACK_BUFFER,h),yt.getBufferSubData(yt.PIXEL_PACK_BUFFER,0,s),yt.deleteBuffer(h),yt.deleteSync(p),s}throw new Error("THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.")}},this.copyFramebufferToTexture=function(t,e=null,n=0){const i=Math.pow(2,-n),r=Math.floor(t.image.width*i),s=Math.floor(t.image.height*i),a=null!==e?e.x:0,o=null!==e?e.y:0;et.setTexture2D(t,0),yt.copyTexSubImage2D(yt.TEXTURE_2D,n,0,0,a,o,r,s),J.unbindTexture()};const Ht=yt.createFramebuffer(),Gt=yt.createFramebuffer();this.copyTextureToTexture=function(t,e,n=null,i=null,r=0,s=null){let a,o,l,c,u,h,d,p,f;null===s&&(0!==r?(ba("WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels."),s=r,r=0):s=0);const m=t.isCompressedTexture?t.mipmaps[s]:t.image;if(null!==n)a=n.max.x-n.min.x,o=n.max.y-n.min.y,l=n.isBox3?n.max.z-n.min.z:1,c=n.min.x,u=n.min.y,h=n.isBox3?n.min.z:0;else{const e=Math.pow(2,-r);a=Math.floor(m.width*e),o=Math.floor(m.height*e),l=t.isDataArrayTexture?m.depth:t.isData3DTexture?Math.floor(m.depth*e):1,c=0,u=0,h=0}null!==i?(d=i.x,p=i.y,f=i.z):(d=0,p=0,f=0);const g=vt.convert(e.format),v=vt.convert(e.type);let _;e.isData3DTexture?(et.setTexture3D(e,0),_=yt.TEXTURE_3D):e.isDataArrayTexture||e.isCompressedArrayTexture?(et.setTexture2DArray(e,0),_=yt.TEXTURE_2D_ARRAY):(et.setTexture2D(e,0),_=yt.TEXTURE_2D),yt.pixelStorei(yt.UNPACK_FLIP_Y_WEBGL,e.flipY),yt.pixelStorei(yt.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultiplyAlpha),yt.pixelStorei(yt.UNPACK_ALIGNMENT,e.unpackAlignment);const x=yt.getParameter(yt.UNPACK_ROW_LENGTH),y=yt.getParameter(yt.UNPACK_IMAGE_HEIGHT),b=yt.getParameter(yt.UNPACK_SKIP_PIXELS),w=yt.getParameter(yt.UNPACK_SKIP_ROWS),M=yt.getParameter(yt.UNPACK_SKIP_IMAGES);yt.pixelStorei(yt.UNPACK_ROW_LENGTH,m.width),yt.pixelStorei(yt.UNPACK_IMAGE_HEIGHT,m.height),yt.pixelStorei(yt.UNPACK_SKIP_PIXELS,c),yt.pixelStorei(yt.UNPACK_SKIP_ROWS,u),yt.pixelStorei(yt.UNPACK_SKIP_IMAGES,h);const S=t.isDataArrayTexture||t.isData3DTexture,E=e.isDataArrayTexture||e.isData3DTexture;if(t.isDepthTexture){const n=tt.get(t),i=tt.get(e),m=tt.get(n.__renderTarget),g=tt.get(i.__renderTarget);J.bindFramebuffer(yt.READ_FRAMEBUFFER,m.__webglFramebuffer),J.bindFramebuffer(yt.DRAW_FRAMEBUFFER,g.__webglFramebuffer);for(let n=0;nMath.PI&&(n-=Cp),i<-Math.PI?i+=Cp:i>Math.PI&&(i-=Cp),this._spherical.theta=n<=i?Math.max(n,Math.min(i,this._spherical.theta)):this._spherical.theta>(n+i)/2?Math.max(n,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),!0===this.enableDamping?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let r=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const t=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),r=t!=this._spherical.radius}if(Ap.setFromSpherical(this._spherical),Ap.applyQuaternion(this._quatInverse),e.copy(this.target).add(Ap),this.object.lookAt(this.target),!0===this.enableDamping?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let t=null;if(this.object.isPerspectiveCamera){const e=Ap.length();t=this._clampDistance(e*this._scale);const n=e-t;this.object.position.addScaledVector(this._dollyDirection,n),this.object.updateMatrixWorld(),r=!!n}else if(this.object.isOrthographicCamera){const e=new Da(this._mouse.x,this._mouse.y,0);e.unproject(this.object);const n=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),r=n!==this.object.zoom;const i=new Da(this._mouse.x,this._mouse.y,0);i.unproject(this.object),this.object.position.sub(i).add(e),this.object.updateMatrixWorld(),t=Ap.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;null!==t&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(t).add(this.object.position):(Sp.origin.copy(this.object.position),Sp.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(Sp.direction))Pp||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Pp||this._lastTargetPosition.distanceToSquared(this.target)>Pp)&&(this.dispatchEvent(bp),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0)}_getAutoRotationAngle(t){return null!==t?Cp/60*this.autoRotateSpeed*t:Cp/60/60*this.autoRotateSpeed}_getZoomScale(t){const e=Math.abs(.01*t);return Math.pow(.95,this.zoomSpeed*e)}_rotateLeft(t){this._sphericalDelta.theta-=t}_rotateUp(t){this._sphericalDelta.phi-=t}_panLeft(t,e){Ap.setFromMatrixColumn(e,0),Ap.multiplyScalar(-t),this._panOffset.add(Ap)}_panUp(t,e){!0===this.screenSpacePanning?Ap.setFromMatrixColumn(e,1):(Ap.setFromMatrixColumn(e,0),Ap.crossVectors(this.object.up,Ap)),Ap.multiplyScalar(t),this._panOffset.add(Ap)}_pan(t,e){const n=this.domElement;if(this.object.isPerspectiveCamera){const i=this.object.position;Ap.copy(i).sub(this.target);let r=Ap.length();r*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*t*r/n.clientHeight,this.object.matrix),this._panUp(2*e*r/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(t*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(e*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(t){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=t:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(t,e){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),i=t-n.left,r=e-n.top,s=n.width,a=n.height;this._mouse.x=i/s*2-1,this._mouse.y=-r/a*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(t){return Math.max(this.minDistance,Math.min(this.maxDistance,t))}_handleMouseDownRotate(t){this._rotateStart.set(t.clientX,t.clientY)}_handleMouseDownDolly(t){this._updateZoomParameters(t.clientX,t.clientX),this._dollyStart.set(t.clientX,t.clientY)}_handleMouseDownPan(t){this._panStart.set(t.clientX,t.clientY)}_handleMouseMoveRotate(t){this._rotateEnd.set(t.clientX,t.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(Cp*this._rotateDelta.x/e.clientHeight),this._rotateUp(Cp*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(t){this._dollyEnd.set(t.clientX,t.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(t){this._panEnd.set(t.clientX,t.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(t){this._updateZoomParameters(t.clientX,t.clientY),t.deltaY<0?this._dollyIn(this._getZoomScale(t.deltaY)):t.deltaY>0&&this._dollyOut(this._getZoomScale(t.deltaY)),this.update()}_handleKeyDown(t){let e=!1;switch(t.code){case this.keys.UP:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(Cp*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),e=!0;break;case this.keys.BOTTOM:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateUp(-Cp*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),e=!0;break;case this.keys.LEFT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(Cp*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),e=!0;break;case this.keys.RIGHT:t.ctrlKey||t.metaKey||t.shiftKey?this.enableRotate&&this._rotateLeft(-Cp*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),e=!0}e&&(t.preventDefault(),this.update())}_handleTouchStartRotate(t){if(1===this._pointers.length)this._rotateStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._rotateStart.set(n,i)}}_handleTouchStartPan(t){if(1===this._pointers.length)this._panStart.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._panStart.set(n,i)}}_handleTouchStartDolly(t){const e=this._getSecondPointerPosition(t),n=t.pageX-e.x,i=t.pageY-e.y,r=Math.sqrt(n*n+i*i);this._dollyStart.set(0,r)}_handleTouchStartDollyPan(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enablePan&&this._handleTouchStartPan(t)}_handleTouchStartDollyRotate(t){this.enableZoom&&this._handleTouchStartDolly(t),this.enableRotate&&this._handleTouchStartRotate(t)}_handleTouchMoveRotate(t){if(1==this._pointers.length)this._rotateEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._rotateEnd.set(n,i)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const e=this.domElement;this._rotateLeft(Cp*this._rotateDelta.x/e.clientHeight),this._rotateUp(Cp*this._rotateDelta.y/e.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(t){if(1===this._pointers.length)this._panEnd.set(t.pageX,t.pageY);else{const e=this._getSecondPointerPosition(t),n=.5*(t.pageX+e.x),i=.5*(t.pageY+e.y);this._panEnd.set(n,i)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(t){const e=this._getSecondPointerPosition(t),n=t.pageX-e.x,i=t.pageY-e.y,r=Math.sqrt(n*n+i*i);this._dollyEnd.set(0,r),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const s=.5*(t.pageX+e.x),a=.5*(t.pageY+e.y);this._updateZoomParameters(s,a)}_handleTouchMoveDollyPan(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enablePan&&this._handleTouchMovePan(t)}_handleTouchMoveDollyRotate(t){this.enableZoom&&this._handleTouchMoveDolly(t),this.enableRotate&&this._handleTouchMoveRotate(t)}_addPointer(t){this._pointers.push(t.pointerId)}_removePointer(t){delete this._pointerPositions[t.pointerId];for(let e=0;eXp(t,e))),new Bc(n,i)}(e,n))}function Jp(t){t.geometry.dispose()}function Qp(t,e,n){t.add(function(t,e){const[n,i,r,s,a]=t,o=""===a.value?"blue":a.value,l=Xp(n,e),[c,u]=ef(i,e),h=new Fu(c,l,u,o);return""!==r.value&&(h.name=r.value),h}(e,n)),""===function(t){const[e,n,i,r,s]=t;return i.value}(e)&&""===function(t){const[e,n,i,r,s]=t;return r.value}(e)||t.add(function(t,e){const[n,i,r,s,a]=t,o=$p(s.value,.7,e),l=Xp(n,e).add(Xp(i,e));return o.position.set(l.x,l.y+.5*e.labelScale,l.z),""!==r.value&&(o.name=r.value+"_label"),o}(e,n))}function tf(t,e,n){const[i,r,s,a,o]=e;if(""!==s.value){const e=t.getObjectByName(s.value);if(e){const[t,s]=ef(r,n),a=""===o.value?"blue":o.value,l=Xp(i,n);e.position.set(l.x,l.y,l.z),e.setDirection(t),e.setLength(s),e.setColor(a)}const l=t.getObjectByName(s.value+"_label");if(l){const t=Xp(i,n).add(Xp(r,n));l.position.set(t.x,t.y+.5*n.labelScale,t.z),function(t,e){const n=t.material.map;if(null===n)console.log("no texture");else{const t=n.source.data;let i=t.getContext("2d");if(null===i)console.log("no context");else{const r=1.1*Math.ceil(i.measureText(e).width),s=t.height;if(r>t.width){const e=i.font;t.width=r;const n=t.getContext("2d");null===n?console.log("no context"):(n.textAlign="center",n.font=e,n.textBaseline="middle",i=n)}else i.clearRect(0,0,t.width,t.height);i.fillText(e,r/2,s/2),n.needsUpdate=!0}}}(l,a.value)}}}function ef(t,e){const n=Xp(t,e),i=Math.hypot(n.x,n.y,n.z);return n.normalize(),[n,i]}function nf(t,e,n){const[i,r,s,a]=e,o=Xp(i,n),l=Xp(r,n),c=new wu(new Sl(s.value),Ii(a.numbers,0,0));c.position.set(o.x,o.y,o.z),c.target.position.set(l.x,l.y,l.z),t.add(c),t.add(c.target)}function rf(t,e,n){const[i,r,s,a,o]=e,l=Ii(o.numbers,0,0),c=$p(i.value,l,{fontFamily:""===a.value?n.fontFamily:a.value,fontSize:n.fontSize*l,labelColor:""===s.value?n.labelColor:s.value,labelScale:n.labelScale});Wp(c,r,n),t.add(c)}new Da,new Da,new ka;class sf{constructor(t){this.options=t,this.axisLabels=[],this.labelsVisible=!0,this.renderer=function(t,e){const n=new yp({antialias:!0,preserveDrawingBuffer:!0});return n.setSize(t,e),n}(t.width,t.height),this.root=this.renderer.domElement,this.scene=new bc,this.scene.background=new Sl(t.background),this.camera=function(t){switch(t.orthographic?"orthographic":"perspective"){case"perspective":return new pc(50,t.width/t.height,t.cameraNear*t.scale,t.cameraFar*t.scale);case"orthographic":{const e=.05;return new Mu(e*-t.width/2,e*t.width/2,e*t.height/2,e*-t.height/2,t.cameraNear*t.scale,t.cameraFar*t.scale)}default:throw new Error("Camera kind $kind unknown")}}(t),this.scene.add(this.camera),this.controls=function(t,e){const n=new Np(t,e);return n.maxPolarAngle=Math.PI/1,n}(this.camera,this.root),this.controls.addEventListener("change",this.onChangeOrbit.bind(this)),this.body=new sl,this.scene.add(this.body),this.camera.position.set(t.cameraX*t.scale,t.cameraY*t.scale,t.cameraZ*t.scale),this.camera.lookAt(this.body.position),this.updateLabelOrientations(),this.controls.update()}getRoot(){return this.root}loadScene(t){var e,n;const[i,r,s,a,o,l,c]=t;for(const t of s)qp(this.body,t,this.options);for(const t of r)Qp(this.body,t,this.options);for(const t of a)Kp(this.body,t,this.options);for(const t of o)nf(this.body,t,this.options);for(const t of c)rf(this.body,t,this.options);this.updateLabelOrientations(),this.setAmbientLight(null!==(e=this.options.ambientColor)&&void 0!==e?e:l[0].value,null!==(n=this.options.ambientIntensity)&&void 0!==n?n:Ii(l[1].numbers,0,0))}updateScene(t){const[,e,n]=t;for(const t of e)tf(this.body,t,this.options);for(const t of n)Yp(this.body,t,this.options)}render(){this.renderer.render(this.scene,this.camera),this.controls.autoRotate&&this.controls.update(),this.updateLabelOrientations()}clear(){for(;this.body.children.length>0;){const t=this.body.children[0];switch(t.type){case"Mesh":Zp(t);break;case"Line":Jp(t)}this.body.remove(t)}}dispose(){var t,e,n;this.clear(),this.renderer.dispose(),this.controls.dispose(),null===(t=this.axis)||void 0===t||t.dispose(),null===(e=this.grid)||void 0===e||e.dispose(),null===(n=this.ambientLight)||void 0===n||n.dispose()}resize(t,e){this.renderer.setSize(t,e)}hasLabels(){return this.labelsVisible}showLabels(){this.hasLabels()||(this.labelsVisible=!0,this.updateLabelOrientations())}hideLabels(){this.hasLabels()&&(this.labelsVisible=!1,this.updateLabelOrientations())}hasGrid(){return void 0!==this.grid}showGrid(){void 0===this.grid&&(this.grid=function(t,e,n){const i=new Sl(n);return new Du(t,e,i,i)}(this.options.gridSize*this.options.scale,this.options.gridDivisions,this.options.gridColor),this.scene.add(this.grid))}hideGrid(){this.grid&&(this.scene.remove(this.grid),this.grid.dispose(),this.grid=void 0)}hasAxis(){return void 0!==this.axis}showAxis(){void 0===this.axis&&(this.axis=function(t,e,n,i){const r=new Bu(t);return r.setColors(new Sl(e),new Sl(n),new Sl(i)),r}(this.options.axisSize*this.options.scale,this.options.axisColorsX,this.options.axisColorsY,this.options.axisColorsZ),this.scene.add(this.axis)),this.options.hideLabels||this.showAxisLabels()}hideAxis(){this.hideAxisLabels(),this.axis&&(this.scene.remove(this.axis),this.axis.dispose(),this.axis=void 0)}hasAxisLabels(){return this.axisLabels.length>0}showAxisLabels(){if(0===this.axisLabels.length){this.axisLabels=function(t,e,n){const i=[],r=n.unitX.toText(),s=n.unitY.toText(),a=n.unitZ.toText(),o=1.05*t,l=$p(`x[${r}]`,.5,n),c=$p(`y[${s}]`,.5,n),u=$p(`z[${a}]`,.5,n);return l.position.set(o,0,0),u.position.set(0,o,0),c.position.set(0,0,o),i.push(l,c,u),i}(this.options.axisSize*this.options.scale,0,this.options);for(const t of this.axisLabels)this.scene.add(t);this.updateLabelOrientations()}}hideAxisLabels(){for(const t of this.axisLabels)this.scene.remove(t);this.axisLabels=[]}updateLabelOrientations(){for(const t of this.body.children)"Mesh"===t.type&&"PlaneGeometry"===t.geometry.type&&(t.rotation.x=this.camera.rotation.x,t.rotation.y=this.camera.rotation.y,t.rotation.z=this.camera.rotation.z,t.visible=this.hasLabels());for(const t of this.axisLabels)"Mesh"===t.type&&"PlaneGeometry"===t.geometry.type&&(t.rotation.x=this.camera.rotation.x,t.rotation.y=this.camera.rotation.y,t.rotation.z=this.camera.rotation.z,t.visible=this.hasLabels())}startAutoRotation(t){this.controls.autoRotateSpeed=60/(null!=t?t:this.options.secondsPerRotation),this.controls.autoRotate=!0}stopAutoRotation(){this.controls.autoRotate=!1}isAutoRotating(){return this.controls.autoRotate}autoRotateSpeed(){return this.controls.autoRotate?60/this.controls.autoRotateSpeed:0}setAmbientLight(t,e){void 0===this.ambientLight&&(this.ambientLight=new Su,this.scene.add(this.ambientLight)),this.ambientLight.color=new Sl(t),this.ambientLight.intensity=e}onChangeOrbit(){this.updateLabelOrientations(),requestAnimationFrame(()=>{this.renderer.render(this.scene,this.camera)})}addPath(t,e){Kp(this.body,t,e)}addMesh(t,e){qp(this.body,t,e)}}const af={orthographic:!1,axis:!1,axisSize:10,axisColorsX:"#eeaaaa",axisColorsY:"#aaeeaa",axisColorsZ:"#aaaaee",width:800,height:450,unitX:P.ONE,unitY:P.ONE,unitZ:P.ONE,verbose:!1,fps:60,background:"#eeeeee",grid:!1,gridSize:20,gridDivisions:20,gridColor:"#dddddd",cameraNear:.1,cameraFar:2e3,cameraX:20,cameraY:10,cameraZ:20,hideLabels:!1,labelColor:"#0A0A0A",labelScale:1,fontFamily:"sans-serif",fontSize:100,autoRotation:!1,secondsPerRotation:30,scale:1};class of{constructor(t,e){this.parent=t,this.TIME_UNIT=er("second"),this.animating=!1,this.frameCounter=0,this.options=Object.assign(Object.assign({},af),e),this.environment=new sf(this.options),this.parent.appendChild(this.environment.getRoot()),this.options.grid&&this.showGrid(),this.options.axis&&this.showAxis(),this.options.autoRotation&&this.startAutoRotation(this.options.secondsPerRotation)}getDescription(){return this.initialScene?this.initialScene[0].value:void 0}isAnimation(){return void 0!==this.callback||void 0!==this.statefulCallback}frameNr(){return this.frameCounter}isRunning(){return this.animating}runningTime(){return this.frameCounter/this.options.fps}clear(){this.environment.clear()}dispose(){this.environment.dispose()}loadAnimation(t){const[e,n]=t;this.callback=e,this.statefulCallback=void 0,this.initialState=void 0,this.loadScene(n)}loadStatefulAnimation(t){const[e,n,i]=t;this.statefulCallback=n,this.initialState=e,this.callback=void 0,this.loadScene(i)}loadScene(t){this.initialScene=t,this.clear(),this.environment.loadScene(t),this.resetAnimation()}setRunning(t){if(this.animating&&!t&&this.pauseAnimation(),!this.animating&&t){if(void 0===this.animationScene)throw new Error("No scene elements to update");if(!this.isAnimation())throw new Error("No callback available in UpdateSpace");this.startAnimation(),this.draw()}}resize(t,e){this.environment.resize(t,e),this.draw()}hasLabels(){return this.environment.hasLabels()}showLabels(){this.environment.showLabels(),this.draw()}hideLabels(){this.environment.hideLabels(),this.draw()}hasGrid(){return this.environment.hasGrid()}showGrid(){this.environment.showGrid(),this.draw()}hideGrid(){this.environment.hideGrid(),this.draw()}hasAxis(){return this.environment.hasAxis()}showAxis(){this.environment.showAxis(),this.draw()}hideAxis(){this.environment.hideAxis(),this.draw()}hasAxisLabels(){return this.environment.hasAxisLabels()}showAxisLabels(){this.environment.showAxisLabels(),this.draw()}hideAxisLabels(){this.environment.hideAxisLabels(),this.draw()}startAutoRotation(t){this.environment.startAutoRotation(t),this.draw()}stopAutoRotation(){this.environment.stopAutoRotation()}autoRotateSpeed(){return this.environment.autoRotateSpeed()}setAmbientLight(t,e){this.environment.setAmbientLight(t,e)}updateScene(){if(void 0===this.animationScene)throw new Error("No scene elements to update");if(!this.callback&&!this.statefulCallback)throw new Error("No callback available in UpdateSpace");if(this.statefulCallback&&!this.initialState)throw new Error("No initial value available in UpdateSpace");this.moveSceneForward(),this.draw()}draw(){void 0===this.animationRequest&&(this.animationRequest=requestAnimationFrame(this.render.bind(this)))}startAnimation(){this.animating=!0}resetAnimation(){this.animationScene=this.initialScene,this.animationState=this.initialState,this.frameCounter=0}pauseAnimation(){void 0===this.animationRequest||this.environment.isAutoRotating()||(globalThis.cancelAnimationFrame(this.animationRequest),this.animationRequest=void 0),this.animating=!1}render(){this.animationRequest=void 0,this.animating&&this.isAnimation()&&this.moveSceneForward(),this.environment.render(),(this.animating||this.environment.isAutoRotating())&&this.draw()}moveSceneForward(){var t;if(this.frameCounter++,!this.animationScene)throw new Error("no animation scene for animation");if(this.callback)this.animationScene=this.callback.call(ar(this.runningTime(),this.TIME_UNIT),this.animationScene);else{if(!this.statefulCallback)throw new Error("no callback to recalculate scene for animation");{const e=null!==(t=this.animationState)&&void 0!==t?t:this.initialState;if(!e)throw new Error("no state to recalculate scene for animation");{const[t,n]=this.statefulCallback.call(ar(this.runningTime(),this.TIME_UNIT),e,this.animationScene);this.animationState=t,this.animationScene=n}}}this.environment.updateScene(this.animationScene)}addPath(t,e){let n={unitX:this.options.unitX,unitY:this.options.unitX,unitZ:this.options.unitX,scale:1};e&&(n=Object.assign(Object.assign({},n),e)),this.environment.addPath(t,n)}addMesh(t,e){let n={unitX:this.options.unitX,unitY:this.options.unitX,unitZ:this.options.unitX,scale:1};e&&(n=Object.assign(Object.assign({},n),e)),this.environment.addMesh(t,n)}}class lf{constructor(t,e){this.lhs=t,this.rhs=e,this.kind="typeeq"}}class cf{constructor(t,e){this.lhs=t,this.rhs=e,this.kind="uniteq"}}class uf{constructor(t,e){this.lhs=t,this.rhs=e,this.kind="vectoreq"}}class hf{constructor(t,e){this.lhs=t,this.rhs=e,this.kind="indexeq"}}function df(t,e){return function(t){let e=new pf;for(const n of t)switch(n.kind){case"typeeq":{const t=yf(n.lhs,e);"typevar"===t.kind&&(e=pf.fromType(t,yf(n.rhs,e)).compose(e));break}case"indexeq":{const t=_f(n.lhs,e.indexMap);"indexvar"===t.kind&&(e=pf.fromIndex(t,_f(n.rhs,e.indexMap)).compose(e));break}case"uniteq":{const t=new pf;t.unitMap=mf(xf(n.lhs,e.unitMap),xf(n.rhs,e.unitMap)),e=t.compose(e);break}case"vectoreq":{const t=new pf;t.vectorMap=mf(xf(n.lhs,e.vectorMap),xf(n.rhs,e.vectorMap)),e=t.compose(e);break}}return e}(vf(t,e))}class pf{constructor(t=new Map,e=new Map,n=new Map,i=new Map){this.typeMap=t,this.indexMap=e,this.unitMap=n,this.vectorMap=i}static fromType(t,e){const n=new pf;return n.typeMap.set(t.name,e),n}static fromIndex(t,e){const n=new pf;return n.indexMap.set(t.name,e),n}compose(t){const e=ff(this.unitMap,t.unitMap,xf),n=ff(this.vectorMap,t.vectorMap,xf),i=ff(this.indexMap,t.indexMap,_f),r=ff(this.typeMap,t.typeMap,(t,r)=>yf(t,new pf(r,i,e,n)));return new pf(r,i,e,n)}}function ff(t,e,n){const i=new Map;for(const[e,n]of t.entries())i.set(e,n);for(const[r,s]of e.entries())i.set(r,n(s,t));return i}function mf(t,e){return t.equals(e)?new Map:gf(t.div(e))}function gf(t){const e=new Map,n=[],i=[];for(const e of t.bases())e.isVar?n.push(e):i.push(e);if(0===n.length){if(i.length>0)throw new Zt("Contradiction while matching units. Expected equal units, but after simplifying the following remains: 1 = "+t.toText());return e}const r=n[0],s=t.power(r);if(1===n.length){let n=y.ONE;for(const e of i){const i=t.power(e);if(i%s!==0)throw new Error("unit error in unit "+t.toText());n=n.mult(y.fromBase(e).expt(-i/s))}return e.set(r.name,n),e}let a=r;for(const e of n)Math.abs(t.power(e))0)&&n.push(new uf(t.rowUnit,e.rowUnit)),("indexvar"===t.columnIndex.kind||t.columnIndex.sets.length>0)&&n.push(new uf(t.columnUnit,e.columnUnit)),n}if("generic"===t.kind&&"generic"===e.kind){if(t.name!==e.name)throw new Error(`Mixup of types ${t.name} and ${e.name}`);let n=[];for(let i=0;it.isVar&&e.get(t.name)||y.fromBase(t))}function yf(t,e){switch(t.kind){case"typevar":return e.typeMap.get(t.name)||t;case"matrix":return new J(xf(t.multiplier,e.unitMap),_f(t.rowIndex,e.indexMap),xf(t.rowUnit,e.vectorMap),_f(t.columnIndex,e.indexMap),xf(t.columnUnit,e.vectorMap));case"generic":return new rt(t.name,t.items.map(t=>yf(t,e)));case"function":return new bf(yf(t.from,e),yf(t.to,e));case"index":return t}}class bf{constructor(t,e){this.from=t,this.to=e,this.kind="function"}apply(t){return yf(this.to,df(this.from,new rt("Tuple",t)))}}var wf=Array.prototype,Mf=wf.slice;function Sf(t,e){return null==t||null==e?NaN:te?1:t>=e?0:NaN}function Ef(t,e){return null==t||null==e?NaN:et?1:e>=t?0:NaN}function Tf(t){let e,n,i;function r(t,i,r=0,s=t.length){if(r>>1;n(t[e],i)<0?r=e+1:s=e}while(rSf(t(e),n),i=(e,n)=>t(e)-n):(e=t===Sf||t===Ef?t:Af,n=t,i=t),{left:r,center:function(t,e,n=0,s=t.length){const a=r(t,e,n,s-1);return a>n&&i(t[a-1],e)>-i(t[a],e)?a-1:a},right:function(t,i,r=0,s=t.length){if(r>>1;n(t[e],i)<=0?r=e+1:s=e}while(rt}function Lf(t,e){let n,i;if(void 0===e)for(const e of t)null!=e&&(void 0===n?e>=e&&(n=i=e):(n>e&&(n=e),i=s&&(n=i=s):(n>s&&(n=s),i=Df?10:s>=If?5:s>=Of?2:1;let o,l,c;return r<0?(c=Math.pow(10,-r)/a,o=Math.round(t*c),l=Math.round(e*c),o/ce&&--l,c=-c):(c=Math.pow(10,r)*a,o=Math.round(t/c),l=Math.round(e/c),o*ce&&--l),l0))return[];if((t=+t)===(e=+e))return[t];const i=e=r))return[];const o=s-r+1,l=new Array(o);if(i)if(a<0)for(let t=0;t=n&&++e;return e}(t))/Math.LN2)+1)}function Vf(){var t=Uf,e=Lf,n=zf;function i(i){Array.isArray(i)||(i=Array.from(i));var r,s,a,o=i.length,l=new Array(o);for(r=0;r0?(t=Math.floor(t/r)*r,e=Math.ceil(e/r)*r):r<0&&(t=Math.ceil(t*r)/r,e=Math.floor(e*r)/r),i=r}}(u,h,n)),(d=Ff(u,h,n))[0]<=u&&(a=Bf(u,h,n)),d[d.length-1]>=h)if(t>=h&&e===Lf){const t=Bf(u,h,n);isFinite(t)&&(t>0?h=(Math.floor(h/t)+1)*t:t<0&&(h=(Math.ceil(h*-t)+1)/-t))}else d.pop()}for(var p=d.length,f=0,m=p;d[f]<=u;)++f;for(;d[m-1]>h;)--m;(f||m0?d[r-1]:u,g.x1=r0)for(r=0;r=e)&&(n=e);else{let i=-1;for(let r of t)null!=(r=e(r,++i,t))&&(n=r)&&(n=r)}return n}function Gf(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n>e||void 0===n&&e>=e)&&(n=e);else{let i=-1;for(let r of t)null!=(r=e(r,++i,t))&&(n>r||void 0===n&&r>=r)&&(n=r)}return n}function Wf(t,e){return(null==t||!(t>=t))-(null==e||!(e>=e))||(te?1:0)}function jf(t,e,n=0,i=1/0,r){if(e=Math.floor(e),n=Math.floor(Math.max(0,n)),i=Math.floor(Math.min(t.length-1,i)),!(n<=e&&e<=i))return t;for(r=void 0===r?Wf:function(t=Sf){if(t===Sf)return Wf;if("function"!=typeof t)throw new TypeError("compare is not a function");return(e,n)=>{const i=t(e,n);return i||0===i?i:(0===t(n,n))-(0===t(e,e))}}(r);i>n;){if(i-n>600){const s=i-n+1,a=e-n+1,o=Math.log(s),l=.5*Math.exp(2*o/3),c=.5*Math.sqrt(o*l*(s-l)/s)*(a-s/2<0?-1:1);jf(t,e,Math.max(n,Math.floor(e-a*l/s+c)),Math.min(i,Math.floor(e+(s-a)*l/s+c)),r)}const s=t[e];let a=n,o=i;for(Xf(t,n,e),r(t[i],s)>0&&Xf(t,n,i);a0;)--o}0===r(t[n],s)?Xf(t,n,o):(++o,Xf(t,o,i)),o<=e&&(n=o+1),e<=o&&(i=o-1)}return t}function Xf(t,e,n){const i=t[e];t[e]=t[n],t[n]=i}function $f(t,e,n){if(t=Float64Array.from(function*(t,e){if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(yield e);else{let n=-1;for(let i of t)null!=(i=e(i,++n,t))&&(i=+i)>=i&&(yield i)}}(t,n)),(i=t.length)&&!isNaN(e=+e)){if(e<=0||i<2)return Gf(t);if(e>=1)return Hf(t);var i,r=(i-1)*e,s=Math.floor(r),a=Hf(jf(t,s).subarray(0,s+1));return a+(Gf(t.subarray(s+1))-a)*(r-s)}}function qf(t){return t}var Yf=1e-6;function Zf(t){return"translate("+t+",0)"}function Kf(t){return"translate(0,"+t+")"}function Jf(t){return e=>+t(e)}function Qf(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function tm(){return!this.__axis}function em(t,e){var n=[],i=null,r=null,s=6,a=6,o=3,l="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,c=1===t||4===t?-1:1,u=4===t||2===t?"x":"y",h=1===t||3===t?Zf:Kf;function d(d){var p=null==i?e.ticks?e.ticks.apply(e,n):e.domain():i,f=null==r?e.tickFormat?e.tickFormat.apply(e,n):qf:r,m=Math.max(s,0)+o,g=e.range(),v=+g[0]+l,_=+g[g.length-1]+l,x=(e.bandwidth?Qf:Jf)(e.copy(),l),y=d.selection?d.selection():d,b=y.selectAll(".domain").data([null]),w=y.selectAll(".tick").data(p,e).order(),M=w.exit(),S=w.enter().append("g").attr("class","tick"),E=w.select("line"),T=w.select("text");b=b.merge(b.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),w=w.merge(S),E=E.merge(S.append("line").attr("stroke","currentColor").attr(u+"2",c*s)),T=T.merge(S.append("text").attr("fill","currentColor").attr(u,c*m).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),d!==y&&(b=b.transition(d),w=w.transition(d),E=E.transition(d),T=T.transition(d),M=M.transition(d).attr("opacity",Yf).attr("transform",function(t){return isFinite(t=x(t))?h(t+l):this.getAttribute("transform")}),S.attr("opacity",Yf).attr("transform",function(t){var e=this.parentNode.__axis;return h((e&&isFinite(e=e(t))?e:x(t))+l)})),M.remove(),b.attr("d",4===t||2===t?a?"M"+c*a+","+v+"H"+l+"V"+_+"H"+c*a:"M"+l+","+v+"V"+_:a?"M"+v+","+c*a+"V"+l+"H"+_+"V"+c*a:"M"+v+","+l+"H"+_),w.attr("opacity",1).attr("transform",function(t){return h(x(t)+l)}),E.attr(u+"2",c*s),T.attr(u,c*m).text(f),y.filter(tm).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),y.each(function(){this.__axis=x})}return d.scale=function(t){return arguments.length?(e=t,d):e},d.ticks=function(){return n=Array.from(arguments),d},d.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),d):n.slice()},d.tickValues=function(t){return arguments.length?(i=null==t?null:Array.from(t),d):i&&i.slice()},d.tickFormat=function(t){return arguments.length?(r=t,d):r},d.tickSize=function(t){return arguments.length?(s=a=+t,d):s},d.tickSizeInner=function(t){return arguments.length?(s=+t,d):s},d.tickSizeOuter=function(t){return arguments.length?(a=+t,d):a},d.tickPadding=function(t){return arguments.length?(o=+t,d):o},d.offset=function(t){return arguments.length?(l=+t,d):l},d}function nm(t){return em(3,t)}function im(t){return em(4,t)}function rm(){}function sm(t){return null==t?rm:function(){return this.querySelector(t)}}function am(){return[]}function om(t){return null==t?am:function(){return this.querySelectorAll(t)}}function lm(t){return function(){return this.matches(t)}}function cm(t){return function(e){return e.matches(t)}}var um=Array.prototype.find;function hm(){return this.firstElementChild}var dm=Array.prototype.filter;function pm(){return Array.from(this.children)}function fm(t){return new Array(t.length)}function mm(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function gm(t,e,n,i,r,s){for(var a,o=0,l=e.length,c=s.length;oe?1:t>=e?0:NaN}mm.prototype={constructor:mm,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}};var bm="http://www.w3.org/1999/xhtml";const wm={svg:"http://www.w3.org/2000/svg",xhtml:bm,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Mm(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),wm.hasOwnProperty(e)?{space:wm[e],local:t}:t}function Sm(t){return function(){this.removeAttribute(t)}}function Em(t){return function(){this.removeAttributeNS(t.space,t.local)}}function Tm(t,e){return function(){this.setAttribute(t,e)}}function Am(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function Cm(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function Rm(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function Pm(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function Nm(t){return function(){this.style.removeProperty(t)}}function Lm(t,e,n){return function(){this.style.setProperty(t,e,n)}}function Um(t,e,n){return function(){var i=e.apply(this,arguments);null==i?this.style.removeProperty(t):this.style.setProperty(t,i,n)}}function Dm(t,e){return t.style.getPropertyValue(e)||Pm(t).getComputedStyle(t,null).getPropertyValue(e)}function Im(t){return function(){delete this[t]}}function Om(t,e){return function(){this[t]=e}}function km(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function Fm(t){return t.trim().split(/^|\s+/)}function Bm(t){return t.classList||new zm(t)}function zm(t){this._node=t,this._names=Fm(t.getAttribute("class")||"")}function Vm(t,e){for(var n=Bm(t),i=-1,r=e.length;++i=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var dg=[null];function pg(t,e){this._groups=t,this._parents=e}function fg(){return new pg([[document.documentElement]],dg)}pg.prototype=fg.prototype={constructor:pg,select:function(t){"function"!=typeof t&&(t=sm(t));for(var e=this._groups,n=e.length,i=new Array(n),r=0;r=b&&(b=y+1);!(x=v[b])&&++b=0;)(i=r[s])&&(a&&4^i.compareDocumentPosition(a)&&a.parentNode.insertBefore(i,a),a=i);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=ym);for(var n=this._groups,i=n.length,r=new Array(i),s=0;s1?this.each((null==e?Nm:"function"==typeof e?Um:Lm)(t,e,null==n?"":n)):Dm(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?Im:"function"==typeof e?km:Om)(t,e)):this.node()[t]},classed:function(t,e){var n=Fm(t+"");if(arguments.length<2){for(var i=Bm(this.node()),r=-1,s=n.length;++r=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}})}(t+""),a=s.length;if(!(arguments.length<2)){for(o=e?lg:og,i=0;i{}};function vg(){for(var t,e=0,n=arguments.length,i={};e=0&&(e=t.slice(n+1),t=t.slice(0,n)),t&&!i.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:e}})),a=-1,o=s.length;if(!(arguments.length<2)){if(null!=e&&"function"!=typeof e)throw new Error("invalid callback: "+e);for(;++a0)for(var n,i,r=new Array(n),s=0;s=0&&e._call.call(void 0,t),e=e._next;--Sg}()}finally{Sg=0,function(){for(var t,e,n=wg,i=1/0;n;)n._call?(i>n._time&&(i=n._time),t=n,n=n._next):(e=n._next,n._next=null,n=t?t._next=e:wg=e);Mg=t,Fg(i)}(),Cg=0}}function kg(){var t=Pg.now(),e=t-Ag;e>1e3&&(Rg-=e,Ag=t)}function Fg(t){Sg||(Eg&&(Eg=clearTimeout(Eg)),t-Cg>24?(t<1/0&&(Eg=setTimeout(Og,t-Pg.now()-Rg)),Tg&&(Tg=clearInterval(Tg))):(Tg||(Ag=Pg.now(),Tg=setInterval(kg,1e3)),Sg=1,Ng(Og)))}function Bg(t,e,n){var i=new Dg;return e=null==e?0:+e,i.restart(n=>{i.stop(),t(n+e)},e,n),i}Dg.prototype=Ig.prototype={constructor:Dg,restart:function(t,e,n){if("function"!=typeof t)throw new TypeError("callback is not a function");n=(null==n?Lg():+n)+(null==e?0:+e),this._next||Mg===this||(Mg?Mg._next=this:wg=this,Mg=this),this._call=t,this._time=n,Fg()},stop:function(){this._call&&(this._call=null,this._time=1/0,Fg())}};var zg=bg("start","end","cancel","interrupt"),Vg=[];function Hg(t,e,n,i,r,s){var a=t.__transition;if(a){if(n in a)return}else t.__transition={};!function(t,e,n){var i,r=t.__transition;function s(l){var c,u,h,d;if(1!==n.state)return o();for(c in r)if((d=r[c]).name===n.name){if(3===d.state)return Bg(s);4===d.state?(d.state=6,d.timer.stop(),d.on.call("interrupt",t,t.__data__,d.index,d.group),delete r[c]):+c0)throw new Error("too late; already scheduled");return n}function Wg(t,e){var n=jg(t,e);if(n.state>3)throw new Error("too late; already running");return n}function jg(t,e){var n=t.__transition;if(!n||!(n=n[e]))throw new Error("transition not found");return n}function Xg(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}var $g,qg=180/Math.PI,Yg={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function Zg(t,e,n,i,r,s){var a,o,l;return(a=Math.sqrt(t*t+e*e))&&(t/=a,e/=a),(l=t*n+e*i)&&(n-=t*l,i-=e*l),(o=Math.sqrt(n*n+i*i))&&(n/=o,i/=o,l/=o),t*i180?e+=360:e-t>180&&(t+=360),s.push({i:n.push(r(n)+"rotate(",null,i)-2,x:Xg(t,e)})):e&&n.push(r(n)+"rotate("+e+i)}(s.rotate,a.rotate,o,l),function(t,e,n,s){t!==e?s.push({i:n.push(r(n)+"skewX(",null,i)-2,x:Xg(t,e)}):e&&n.push(r(n)+"skewX("+e+i)}(s.skewX,a.skewX,o,l),function(t,e,n,i,s,a){if(t!==n||e!==i){var o=s.push(r(s)+"scale(",null,",",null,")");a.push({i:o-4,x:Xg(t,n)},{i:o-2,x:Xg(e,i)})}else 1===n&&1===i||s.push(r(s)+"scale("+n+","+i+")")}(s.scaleX,s.scaleY,a.scaleX,a.scaleY,o,l),s=a=null,function(t){for(var e,n=-1,i=l.length;++n>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?Mv(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?Mv(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=dv.exec(t))?new Ev(e[1],e[2],e[3],1):(e=pv.exec(t))?new Ev(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=fv.exec(t))?Mv(e[1],e[2],e[3],e[4]):(e=mv.exec(t))?Mv(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=gv.exec(t))?Nv(e[1],e[2]/100,e[3]/100,1):(e=vv.exec(t))?Nv(e[1],e[2]/100,e[3]/100,e[4]):_v.hasOwnProperty(t)?wv(_v[t]):"transparent"===t?new Ev(NaN,NaN,NaN,0):null}function wv(t){return new Ev(t>>16&255,t>>8&255,255&t,1)}function Mv(t,e,n,i){return i<=0&&(t=e=n=NaN),new Ev(t,e,n,i)}function Sv(t,e,n,i){return 1===arguments.length?((r=t)instanceof sv||(r=bv(r)),r?new Ev((r=r.rgb()).r,r.g,r.b,r.opacity):new Ev):new Ev(t,e,n,null==i?1:i);var r}function Ev(t,e,n,i){this.r=+t,this.g=+e,this.b=+n,this.opacity=+i}function Tv(){return`#${Pv(this.r)}${Pv(this.g)}${Pv(this.b)}`}function Av(){const t=Cv(this.opacity);return`${1===t?"rgb(":"rgba("}${Rv(this.r)}, ${Rv(this.g)}, ${Rv(this.b)}${1===t?")":`, ${t})`}`}function Cv(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function Rv(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function Pv(t){return((t=Rv(t))<16?"0":"")+t.toString(16)}function Nv(t,e,n,i){return i<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Uv(t,e,n,i)}function Lv(t){if(t instanceof Uv)return new Uv(t.h,t.s,t.l,t.opacity);if(t instanceof sv||(t=bv(t)),!t)return new Uv;if(t instanceof Uv)return t;var e=(t=t.rgb()).r/255,n=t.g/255,i=t.b/255,r=Math.min(e,n,i),s=Math.max(e,n,i),a=NaN,o=s-r,l=(s+r)/2;return o?(a=e===s?(n-i)/o+6*(n0&&l<1?0:a,new Uv(a,o,l,t.opacity)}function Uv(t,e,n,i){this.h=+t,this.s=+e,this.l=+n,this.opacity=+i}function Dv(t){return(t=(t||0)%360)<0?t+360:t}function Iv(t){return Math.max(0,Math.min(1,t||0))}function Ov(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}function kv(t,e,n,i,r){var s=t*t,a=s*t;return((1-3*t+3*s-a)*e+(4-6*s+3*a)*n+(1+3*t+3*s-3*a)*i+a*r)/6}iv(sv,bv,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:xv,formatHex:xv,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Lv(this).formatHsl()},formatRgb:yv,toString:yv}),iv(Ev,Sv,rv(sv,{brighter(t){return t=null==t?ov:Math.pow(ov,t),new Ev(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?av:Math.pow(av,t),new Ev(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new Ev(Rv(this.r),Rv(this.g),Rv(this.b),Cv(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Tv,formatHex:Tv,formatHex8:function(){return`#${Pv(this.r)}${Pv(this.g)}${Pv(this.b)}${Pv(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Av,toString:Av})),iv(Uv,function(t,e,n,i){return 1===arguments.length?Lv(t):new Uv(t,e,n,null==i?1:i)},rv(sv,{brighter(t){return t=null==t?ov:Math.pow(ov,t),new Uv(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?av:Math.pow(av,t),new Uv(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,i=n+(n<.5?n:1-n)*e,r=2*n-i;return new Ev(Ov(t>=240?t-240:t+120,r,i),Ov(t,r,i),Ov(t<120?t+240:t-120,r,i),this.opacity)},clamp(){return new Uv(Dv(this.h),Iv(this.s),Iv(this.l),Cv(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Cv(this.opacity);return`${1===t?"hsl(":"hsla("}${Dv(this.h)}, ${100*Iv(this.s)}%, ${100*Iv(this.l)}%${1===t?")":`, ${t})`}`}}));const Fv=t=>()=>t;function Bv(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):Fv(isNaN(t)?e:t)}const zv=function t(e){var n=function(t){return 1===(t=+t)?Bv:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(i){return Math.pow(t+i*e,n)}}(e,n,t):Fv(isNaN(e)?n:e)}}(e);function i(t,e){var i=n((t=Sv(t)).r,(e=Sv(e)).r),r=n(t.g,e.g),s=n(t.b,e.b),a=Bv(t.opacity,e.opacity);return function(e){return t.r=i(e),t.g=r(e),t.b=s(e),t.opacity=a(e),t+""}}return i.gamma=t,i}(1);function Vv(t){return function(e){var n,i,r=e.length,s=new Array(r),a=new Array(r),o=new Array(r);for(n=0;n=1?(n=1,e-1):Math.floor(n*e),r=t[i],s=t[i+1],a=i>0?t[i-1]:2*r-s,o=is&&(r=e.slice(s,r),o[a]?o[a]+=r:o[++a]=r),(n=n[0])===(i=i[0])?o[a]?o[a]+=i:o[++a]=i:(o[++a]=null,l.push({i:a,x:Xg(n,i)})),s=Gv.lastIndex;return s=0&&(t=t.slice(0,e)),!t||"start"===t})}(e)?Gg:Wg;return function(){var a=s(this,t),o=a.on;o!==i&&(r=(i=o).copy()).on(e,n),a.on=r}}(n,t,e))},attr:function(t,e){var n=Mm(t),i="transform"===n?Qg:jv;return this.attrTween(t,"function"==typeof e?(n.local?Kv:Zv)(n,i,nv(this,"attr."+t,e)):null==e?(n.local?$v:Xv)(n):(n.local?Yv:qv)(n,i,e))},attrTween:function(t,e){var n="attr."+t;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(null==e)return this.tween(n,null);if("function"!=typeof e)throw new Error;var i=Mm(t);return this.tween(n,(i.local?Jv:Qv)(i,e))},style:function(t,e,n){var i="transform"==(t+="")?Jg:jv;return null==e?this.styleTween(t,function(t,e){var n,i,r;return function(){var s=Dm(this,t),a=(this.style.removeProperty(t),Dm(this,t));return s===a?null:s===n&&a===i?r:r=e(n=s,i=a)}}(t,i)).on("end.style."+t,s_(t)):"function"==typeof e?this.styleTween(t,function(t,e,n){var i,r,s;return function(){var a=Dm(this,t),o=n(this),l=o+"";return null==o&&(this.style.removeProperty(t),l=o=Dm(this,t)),a===l?null:a===i&&l===r?s:(r=l,s=e(i=a,o))}}(t,i,nv(this,"style."+t,e))).each(function(t,e){var n,i,r,s,a="style."+e,o="end."+a;return function(){var l=Wg(this,t),c=l.on,u=null==l.value[a]?s||(s=s_(e)):void 0;c===n&&r===u||(i=(n=c).copy()).on(o,r=u),l.on=i}}(this._id,t)):this.styleTween(t,function(t,e,n){var i,r,s=n+"";return function(){var a=Dm(this,t);return a===s?null:a===i?r:r=e(i=a,n)}}(t,i,e),n).on("end.style."+t,null)},styleTween:function(t,e,n){var i="style."+(t+="");if(arguments.length<2)return(i=this.tween(i))&&i._value;if(null==e)return this.tween(i,null);if("function"!=typeof e)throw new Error;return this.tween(i,function(t,e,n){var i,r;function s(){var s=e.apply(this,arguments);return s!==r&&(i=(r=s)&&function(t,e,n){return function(i){this.style.setProperty(t,e.call(this,i),n)}}(t,s,n)),i}return s._value=e,s}(t,e,null==n?"":n))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var e=t(this);this.textContent=null==e?"":e}}(nv(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var e="text";if(arguments.length<1)return(e=this.tween(e))&&e._value;if(null==t)return this.tween(e,null);if("function"!=typeof t)throw new Error;return this.tween(e,function(t){var e,n;function i(){var i=t.apply(this,arguments);return i!==n&&(e=(n=i)&&function(t){return function(e){this.textContent=t.call(this,e)}}(i)),e}return i._value=t,i}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var e=this.parentNode;for(var n in this.__transition)if(+n!==t)return;e&&e.removeChild(this)}}(this._id))},tween:function(t,e){var n=this._id;if(t+="",arguments.length<2){for(var i,r=jg(this.node(),n).tween,s=0,a=r.length;s2&&n.state<5,n.state=6,n.timer.stop(),n.on.call(i?"interrupt":"cancel",t,t.__data__,n.index,n.group),delete s[r]):a=!1;a&&delete t.__transition}}(this,t)})},mg.prototype.transition=function(t){var e,n;t instanceof o_?(e=t._id,t=t._name):(e=l_(),(n=u_).time=Lg(),t=null==t?null:t+"");for(var i=this._groups,r=i.length,s=0;s=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function k_(t){if(!(e=O_.exec(t)))throw new Error("invalid format: "+t);var e;return new F_({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function F_(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function B_(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,i=t.slice(0,n);return[i.length>1?i[0]+i.slice(2):i,+t.slice(n+1)]}function z_(t){return(t=B_(Math.abs(t)))?t[1]:NaN}function V_(t,e){var n=B_(t,e);if(!n)return t+"";var i=n[0],r=n[1];return r<0?"0."+new Array(-r).join("0")+i:i.length>r+1?i.slice(0,r+1)+"."+i.slice(r+1):i+new Array(r-i.length+2).join("0")}k_.prototype=F_.prototype,F_.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};const H_={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>V_(100*t,e),r:V_,s:function(t,e){var n=B_(t,e);if(!n)return t+"";var i=n[0],r=n[1],s=r-(I_=3*Math.max(-8,Math.min(8,Math.floor(r/3))))+1,a=i.length;return s===a?i:s>a?i+new Array(s-a+1).join("0"):s>0?i.slice(0,s)+"."+i.slice(s):"0."+new Array(1-s).join("0")+B_(t,Math.max(0,e+s-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function G_(t){return t}var W_,j_,X_,$_=Array.prototype.map,q_=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Y_(){var t=function(){var t,e,n,i,r,s,a=P_,o=P_,l=A_,c=N_;function u(){var t,e,n,l=Math.min(a.length,o.length);return c!==N_&&(t=a[0],e=a[l-1],t>e&&(n=t,t=e,e=n),c=function(n){return Math.max(t,Math.min(e,n))}),i=l>2?D_:U_,r=s=null,h}function h(e){return null==e||isNaN(e=+e)?n:(r||(r=i(a.map(t),o,l)))(t(c(e)))}return h.invert=function(n){return c(e((s||(s=i(o,a.map(t),Xg)))(n)))},h.domain=function(t){return arguments.length?(a=Array.from(t,R_),u()):a.slice()},h.range=function(t){return arguments.length?(o=Array.from(t),u()):o.slice()},h.rangeRound=function(t){return o=Array.from(t),l=C_,u()},h.clamp=function(t){return arguments.length?(c=!!t||N_,u()):c!==N_},h.interpolate=function(t){return arguments.length?(l=t,u()):l},h.unknown=function(t){return arguments.length?(n=t,h):n},function(n,i){return t=n,e=i,u()}}()(N_,N_);return t.copy=function(){return e=t,Y_().domain(e.domain()).range(e.range()).interpolate(e.interpolate()).clamp(e.clamp()).unknown(e.unknown());var e},g_.apply(t,arguments),function(t){var e=t.domain;return t.ticks=function(t){var n=e();return Ff(n[0],n[n.length-1],null==t?10:t)},t.tickFormat=function(t,n){var i=e();return function(t,e,n,i){var r,s=function(t,e,n){n=+n;const i=(e=+e)<(t=+t),r=i?Bf(e,t,n):Bf(t,e,n);return(i?-1:1)*(r<0?1/-r:r)}(t,e,n);switch((i=k_(null==i?",f":i)).type){case"s":var a=Math.max(Math.abs(t),Math.abs(e));return null!=i.precision||isNaN(r=function(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(z_(e)/3)))-z_(Math.abs(t)))}(s,a))||(i.precision=r),X_(i,a);case"":case"e":case"g":case"p":case"r":null!=i.precision||isNaN(r=function(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,z_(e)-z_(t))+1}(s,Math.max(Math.abs(t),Math.abs(e))))||(i.precision=r-("e"===i.type));break;case"f":case"%":null!=i.precision||isNaN(r=function(t){return Math.max(0,-z_(Math.abs(t)))}(s))||(i.precision=r-2*("%"===i.type))}return j_(i)}(i[0],i[i.length-1],null==t?10:t,n)},t.nice=function(n){null==n&&(n=10);var i,r,s=e(),a=0,o=s.length-1,l=s[a],c=s[o],u=10;for(c0;){if((r=Bf(l,c,n))===i)return s[a]=l,s[o]=c,e(s);if(r>0)l=Math.floor(l/r)*r,c=Math.ceil(c/r)*r;else{if(!(r<0))break;l=Math.ceil(l*r)/r,c=Math.floor(c*r)/r}i=r}return t},t}(t)}W_=function(t){var e,n,i=void 0===t.grouping||void 0===t.thousands?G_:(e=$_.call(t.grouping,Number),n=t.thousands+"",function(t,i){for(var r=t.length,s=[],a=0,o=e[0],l=0;r>0&&o>0&&(l+o+1>i&&(o=Math.max(1,i-l)),s.push(t.substring(r-=o,r+o)),!((l+=o+1)>i));)o=e[a=(a+1)%e.length];return s.reverse().join(n)}),r=void 0===t.currency?"":t.currency[0]+"",s=void 0===t.currency?"":t.currency[1]+"",a=void 0===t.decimal?".":t.decimal+"",o=void 0===t.numerals?G_:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}($_.call(t.numerals,String)),l=void 0===t.percent?"%":t.percent+"",c=void 0===t.minus?"−":t.minus+"",u=void 0===t.nan?"NaN":t.nan+"";function h(t){var e=(t=k_(t)).fill,n=t.align,h=t.sign,d=t.symbol,p=t.zero,f=t.width,m=t.comma,g=t.precision,v=t.trim,_=t.type;"n"===_?(m=!0,_="g"):H_[_]||(void 0===g&&(g=12),v=!0,_="g"),(p||"0"===e&&"="===n)&&(p=!0,e="0",n="=");var x="$"===d?r:"#"===d&&/[boxX]/.test(_)?"0"+_.toLowerCase():"",y="$"===d?s:/[%p]/.test(_)?l:"",b=H_[_],w=/[defgprs%]/.test(_);function M(t){var r,s,l,d=x,M=y;if("c"===_)M=b(t)+M,t="";else{var S=(t=+t)<0||1/t<0;if(t=isNaN(t)?u:b(Math.abs(t),g),v&&(t=function(t){t:for(var e,n=t.length,i=1,r=-1;i0&&(r=0)}return r>0?t.slice(0,r)+t.slice(e+1):t}(t)),S&&0===+t&&"+"!==h&&(S=!1),d=(S?"("===h?h:c:"-"===h||"("===h?"":h)+d,M=("s"===_?q_[8+I_/3]:"")+M+(S&&"("===h?")":""),w)for(r=-1,s=t.length;++r(l=t.charCodeAt(r))||l>57){M=(46===l?a+t.slice(r+1):t.slice(r))+M,t=t.slice(0,r);break}}m&&!p&&(t=i(t,1/0));var E=d.length+t.length+M.length,T=E>1)+d+t+M+T.slice(E);break;default:t=T+d+t+M}return o(t)}return g=void 0===g?6:/[gprs]/.test(_)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),M.toString=function(){return t+""},M}return{format:h,formatPrefix:function(t,e){var n=h(((t=k_(t)).type="f",t)),i=3*Math.max(-8,Math.min(8,Math.floor(z_(e)/3))),r=Math.pow(10,-i),s=q_[8+i/3];return function(t){return n(r*t)+s}}}}({thousands:",",grouping:[3],currency:["$",""]}),j_=W_.format,X_=W_.formatPrefix;const Z_=function(t){for(var e=new Array(8),n=0;n<8;)e[n]="#"+t.slice(6*n,6*++n);return e}("7fc97fbeaed4fdc086ffff99386cb0f0027fbf5b17666666");function K_(t){return"string"==typeof t?new pg([[document.querySelector(t)]],[document.documentElement]):new pg([[t]],dg)}function J_(t){return function(){return t}}const Q_=Math.abs,tx=Math.atan2,ex=Math.cos,nx=Math.max,ix=Math.min,rx=Math.sin,sx=Math.sqrt,ax=1e-12,ox=Math.PI,lx=ox/2,cx=2*ox;function ux(t){return t>=1?lx:t<=-1?-lx:Math.asin(t)}const hx=Math.PI,dx=2*hx,px=1e-6,fx=dx-px;function mx(t){this._+=t[0];for(let e=1,n=t.length;e=0))throw new Error(`invalid digits: ${t}`);if(e>15)return mx;const n=10**e;return function(t){this._+=t[0];for(let e=1,i=t.length;epx)if(Math.abs(u*o-l*c)>px&&r){let d=n-s,p=i-a,f=o*o+l*l,m=d*d+p*p,g=Math.sqrt(f),v=Math.sqrt(h),_=r*Math.tan((hx-Math.acos((f+h-m)/(2*g*v)))/2),x=_/v,y=_/g;Math.abs(x-1)>px&&this._append`L${t+x*c},${e+x*u}`,this._append`A${r},${r},0,0,${+(u*d>c*p)},${this._x1=t+y*o},${this._y1=e+y*l}`}else this._append`L${this._x1=t},${this._y1=e}`}arc(t,e,n,i,r,s){if(t=+t,e=+e,s=!!s,(n=+n)<0)throw new Error(`negative radius: ${n}`);let a=n*Math.cos(i),o=n*Math.sin(i),l=t+a,c=e+o,u=1^s,h=s?i-r:r-i;null===this._x1?this._append`M${l},${c}`:(Math.abs(this._x1-l)>px||Math.abs(this._y1-c)>px)&&this._append`L${l},${c}`,n&&(h<0&&(h=h%dx+dx),h>fx?this._append`A${n},${n},0,1,${u},${t-a},${e-o}A${n},${n},0,1,${u},${this._x1=l},${this._y1=c}`:h>px&&this._append`A${n},${n},0,${+(h>=hx)},${u},${this._x1=t+n*Math.cos(r)},${this._y1=e+n*Math.sin(r)}`)}rect(t,e,n,i){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${n=+n}v${+i}h${-n}Z`}toString(){return this._}}function vx(t){let e=3;return t.digits=function(n){if(!arguments.length)return e;if(null==n)e=null;else{const t=Math.floor(n);if(!(t>=0))throw new RangeError(`invalid digits: ${n}`);e=t}return t},()=>new gx(e)}function _x(t){return t.innerRadius}function xx(t){return t.outerRadius}function yx(t){return t.startAngle}function bx(t){return t.endAngle}function wx(t){return t&&t.padAngle}function Mx(t,e,n,i,r,s,a){var o=t-n,l=e-i,c=(a?s:-s)/sx(o*o+l*l),u=c*l,h=-c*o,d=t+u,p=e+h,f=n+u,m=i+h,g=(d+f)/2,v=(p+m)/2,_=f-d,x=m-p,y=_*_+x*x,b=r-s,w=d*m-f*p,M=(x<0?-1:1)*sx(nx(0,b*b*y-w*w)),S=(w*x-_*M)/y,E=(-w*_-x*M)/y,T=(w*x+_*M)/y,A=(-w*_+x*M)/y,C=S-g,R=E-v,P=T-g,N=A-v;return C*C+R*R>P*P+N*N&&(S=T,E=A),{cx:S,cy:E,x01:-u,y01:-h,x11:S*(r/b-1),y11:E*(r/b-1)}}function Sx(){var t=_x,e=xx,n=J_(0),i=null,r=yx,s=bx,a=wx,o=null,l=vx(c);function c(){var c,u,h,d=+t.apply(this,arguments),p=+e.apply(this,arguments),f=r.apply(this,arguments)-lx,m=s.apply(this,arguments)-lx,g=Q_(m-f),v=m>f;if(o||(o=c=l()),pax)if(g>cx-ax)o.moveTo(p*ex(f),p*rx(f)),o.arc(0,0,p,f,m,!v),d>ax&&(o.moveTo(d*ex(m),d*rx(m)),o.arc(0,0,d,m,f,v));else{var _,x,y=f,b=m,w=f,M=m,S=g,E=g,T=a.apply(this,arguments)/2,A=T>ax&&(i?+i.apply(this,arguments):sx(d*d+p*p)),C=ix(Q_(p-d)/2,+n.apply(this,arguments)),R=C,P=C;if(A>ax){var N=ux(A/d*rx(T)),L=ux(A/p*rx(T));(S-=2*N)>ax?(w+=N*=v?1:-1,M-=N):(S=0,w=M=(f+m)/2),(E-=2*L)>ax?(y+=L*=v?1:-1,b-=L):(E=0,y=b=(f+m)/2)}var U=p*ex(y),D=p*rx(y),I=d*ex(M),O=d*rx(M);if(C>ax){var k,F=p*ex(b),B=p*rx(b),z=d*ex(w),V=d*rx(w);if(g1?0:h<-1?ox:Math.acos(h))/2),$=sx(k[0]*k[0]+k[1]*k[1]);R=ix(C,(d-$)/(X-1)),P=ix(C,(p-$)/(X+1))}else R=P=0}E>ax?P>ax?(_=Mx(z,V,U,D,p,P,v),x=Mx(F,B,I,O,p,P,v),o.moveTo(_.cx+_.x01,_.cy+_.y01),Pax&&S>ax?R>ax?(_=Mx(I,O,F,B,d,-R,v),x=Mx(U,D,z,V,d,-R,v),o.lineTo(_.cx+_.x01,_.cy+_.y01),Rt?1:e>=t?0:NaN}function Lx(t){return t}function Ux(t,e,n){t._context.bezierCurveTo(t._x1+t._k*(t._x2-t._x0),t._y1+t._k*(t._y2-t._y0),t._x2+t._k*(t._x1-e),t._y2+t._k*(t._y1-n),t._x2,t._y2)}function Dx(t,e){this._context=t,this._k=(1-e)/6}Array.prototype.slice,Tx.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e)}}},Dx.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:Ux(this,this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2,this._x1=t,this._y1=e;break;case 2:this._point=3;default:Ux(this,t,e)}this._x0=this._x1,this._x1=this._x2,this._x2=t,this._y0=this._y1,this._y1=this._y2,this._y2=e}};const Ix=function t(e){function n(t){return new Dx(t,e)}return n.tension=function(e){return t(+e)},n}(0);function Ox(t,e,n){this.k=t,this.x=e,this.y=n}Ox.prototype={constructor:Ox,scale:function(t){return 1===t?this:new Ox(this.k*t,this.x,this.y)},translate:function(t,e){return 0===t&0===e?this:new Ox(this.k,this.x+this.k*t,this.y+this.k*e)},apply:function(t){return[t[0]*this.k+this.x,t[1]*this.k+this.y]},applyX:function(t){return t*this.k+this.x},applyY:function(t){return t*this.k+this.y},invert:function(t){return[(t[0]-this.x)/this.k,(t[1]-this.y)/this.k]},invertX:function(t){return(t-this.x)/this.k},invertY:function(t){return(t-this.y)/this.k},rescaleX:function(t){return t.copy().domain(t.range().map(this.invertX,this).map(t.invert,t))},rescaleY:function(t){return t.copy().domain(t.range().map(this.invertY,this).map(t.invert,t))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}},new Ox(1,0,0),Ox.prototype;const kx={left:0,top:0,right:0,bottom:0};function Fx(t){try{if(void 0===t)return kx;const e=t.split(" ").map(Number),n=e.length;return 0===n?kx:{left:e[0%n],top:e[1%n],right:e[2%n],bottom:e[3%n]}}catch(t){return kx}}function Bx(t,e){var n,i,r,s,a,o,l,c;return{left:(null!==(n=null==t?void 0:t.left)&&void 0!==n?n:0)+(null!==(i=null==e?void 0:e.left)&&void 0!==i?i:0),top:(null!==(r=null==t?void 0:t.top)&&void 0!==r?r:0)+(null!==(s=null==e?void 0:e.top)&&void 0!==s?s:0),right:(null!==(a=null==t?void 0:t.right)&&void 0!==a?a:0)+(null!==(o=null==e?void 0:e.right)&&void 0!==o?o:0),bottom:(null!==(l=null==t?void 0:t.bottom)&&void 0!==l?l:0)+(null!==(c=null==e?void 0:e.bottom)&&void 0!==c?c:0)}}class zx{constructor(t){this.className=t,this.id=t.split(" ").filter(t=>""!==t).join(".")}findDiv(){const t=K_("div."+this.id);return t.size()>0?t:K_("body").append("div").style("position","absolute").style("background","white").style("border","solid 1pt darkgrey").style("border-radius","4pt").style("padding","4pt").style("display","none").attr("class",this.className)}show(t,e,n){const i=this.findDiv();i.html(t),i.style("left",e.toString()+"px"),i.style("top",n.toString()+"px"),i.style("display",null)}hide(){K_("div."+this.id).style("display","none")}}function Vx(t,e,n){t.append("text").attr("x",n.width/2).attr("y",n.height/2).style("text-anchor","middle").text(e)}function Hx(t,e,n){const i=null!=n?n:e.caption;void 0!==i&&t.append("text").attr("x",e.width/2).attr("y",16).style("text-anchor","middle").text(i)}function Gx(t,e,n,i){const r=n?e=>e.convertUnit(n,t.unitContext):t=>t,s=i?e=>e.convertUnit(i,t.unitContext):t=>t;switch(e.kind){case"tuple":{if(2!==e.length)throw a=`When the data is a tuple it must be a pair. Got a tuple of length ${e.length.toString()}.`,new Zt(`Unexpected data for linear chart. ${a}\n\nValid chart data for a linear chart is \n - a list of (number, number) pairs\n - a pair of number lists\n - a pair of number vectors\n - a vector\n - a list of numbers`);const t=e[0],n=e[1];if("matrix"===t.kind&&"matrix"===n.kind)return function(t,e){const n=Math.min(t.shape.nrRows(),e.shape.nrRows());if(0===n)return null;{const i=[];let r=t.getNum(0,0),s=t.getNum(0,0),a=e.getNum(0,0),o=e.getNum(0,0);for(let l=0;lr(t)),n.map(t=>s(t)))}throw new Error(`exptected a tuple of vectors or a tuple of number lists, but got a (${t.kind}, ${n.kind}) tuple`)}case"list":{if(0===e.length)return null;const t=e[0];if("matrix"===t.kind)return function(t,e=!0){const n=[];let i,r;for(const[s,a]of t.entries()){const t=a.getNum(0,0);(e||0!==t)&&(n.push({x:s,y:t}),(void 0===r||rs(t)));if("tuple"===t.kind){const t=e;return jx(t.map(t=>t[0]),t.map(t=>t[1]))}throw new Error("exptected a list of numbers but got a list of "+t.kind)}case"matrix":return function(t,e=!0){const n=[];let i,r;const s=t.numbers,a=t.shape;for(let t=0;te.convertUnit(i,t.unitContext):t=>t;switch(e.kind){case"list":return function(t,e,n){const i=[];let r,s;if(0===t.length)return null;const a=t[0];if("matrix"===a.kind){for(const[a,o]of t.entries()){const t=Ii(n(o).numbers,0,0);(e||0!==t)&&(i.push({value:t,label:a.toString()}),(void 0===s||s{var e;return null!==(e=p(t.label))&&void 0!==e?e:0}).attr("width",p.bandwidth()).attr("y",t=>Math.min(f(0),f(t.value))).attr("height",t=>Math.abs(f(0)-f(t.value))).on("click",(t,n)=>{if(r){y.hide();const t=new CustomEvent("onclick",{detail:{number:b.fromNumber(n.value,e.unit),label:n.label,options:i}});setTimeout(()=>{r(t)},0)}}).on("mouseover",(t,n)=>{if(s){const r=new CustomEvent("tooltip",{detail:{number:b.fromNumber(n.value,e.unit),label:n.label,options:i}});y.show(s(r),t.pageX+i.tooltipOffset.dx,t.pageY+i.tooltipOffset.dy)}}).on("mouseout",()=>{y.hide()});const w=void 0===i.ylabel?"":`${i.ylabel} `,M=`[${e.unit.toText()}]`;x.append("text").attr("x",-16).attr("y",-16).style("text-anchor","start").text(w+M)}(t,n,e,this.options,this.clickHandler,this.tooltipText)}Hx(i,this.options)}}const Kx={left:64,top:32,right:16,bottom:40},Jx={width:640,height:360,decimals:2,xlabel:"x",ylabel:"y",rotate:!1,smooth:!1,zeros:!0,convert:!0,tooltipOffset:{dx:16,dy:-64}};class Qx{constructor(t,e,n){this.data=t,this.context=e,this.clickHandler=ty,this.tooltipText=ey,this.options=Object.assign(Object.assign({},Jx),n)}draw(t){const e=void 0!==this.options.unit&&""!==this.options.unit?or(this.options.unit):void 0,n=void 0!==this.options.xunit&&""!==this.options.xunit?or(this.options.xunit):void 0,i=void 0!==this.options.yunit&&""!==this.options.yunit?or(this.options.yunit):void 0,r=Gx(this.context,this.data,n||e,i||e);for(;t.firstChild;)t.firstChild.remove();const s=Bx(Kx,Fx(this.options.margin)),a=this.options.width-s.left-s.right,o=this.options.height-s.top-s.bottom,l=K_(t).append("svg").attr("width",a+s.left+s.right).attr("height",o+s.top+s.bottom).attr("class","pacioli chart line-chart");null===r?Vx(l,"No data",this.options):function(t,e,n,i,r,s,a){var o,l;const c=null!==(o=r.ylower)&&void 0!==o?o:e.yLower,u=null!==(l=r.yupper)&&void 0!==l?l:e.yUpper,h=Y_([e.xLower,e.xUpper],[0,n]),d=Y_([c,u],[i,0]),p=nm(h).tickSize(-i),f=t.append("g").attr("class","x axis").attr("transform",`translate(0,${i.toString()})`);f.append("g").call(p),!0===r.rotate?f.selectAll("text").style("text-anchor","end").attr("transform","rotate(-45)"):f.selectAll("text").attr("transform","translate(0, 5)"),f.append("text").attr("x",n).attr("y",24).attr("dy","0.71em").style("text-anchor","end").text(`${r.xlabel} [${e.xUnit.toText()}] (n=${e.values.length.toString()})`);const m=im(d).ticks(r.yticks),g=t.append("g").attr("class","y axis").attr("transform","translate(0,0)");g.append("g").call(m),g.append("text").attr("x",-16).attr("y",-16).style("text-anchor","begin").text(t=>r.ylabel+" ["+e.yUnit.toText()+"]");const v=r.norm;if(void 0!==v){const n=Px().x(([t,e])=>h(t)||0).y(function(t){return d(v)});t.append("path").attr("d",n(e.values.map((t,e)=>[e,t.y]))).attr("class","").attr("stroke","green")}const _=Px().x(([t,e])=>h(t)).y(([t,e])=>d(e));!0===r.smooth&&_.curve(Ix),t.append("path").attr("d",_(e.values.map(t=>[t.x,t.y]))).attr("class","data");const x=t.append("circle").attr("r",3).style("display","none").style("fill","grey"),y=new zx("pacioli tooltip line-chart"),w=e.xUpper-e.xLower,M=0===w?0:n/w;t.selectAll(".hitbox").data(e.values).enter().append("rect").attr("x",t=>(t.x-0)*M).attr("y",0).attr("width",M-1).attr("height",i).style("fill","none").style("pointer-events","all").on("click",(t,n)=>{if(s){y.hide(),x.style("display","none");const t=new CustomEvent("onclick",{detail:{number:b.fromNumber(n.y,e.yUnit),label:b.fromNumber(n.x,e.xUnit),options:r}});setTimeout(()=>{s(t)},0)}}).on("mouseover",(t,n)=>{a&&(y.show(a(new CustomEvent("tooltip",{detail:{number:b.fromNumber(n.y,e.yUnit),label:b.fromNumber(n.x,e.xUnit),options:r}})),t.pageX+r.tooltipOffset.dx,t.pageY+r.tooltipOffset.dy),x.attr("cx",(n.x-0)*M),x.attr("cy",d(n.y)),x.style("display",null))}).on("mouseout",()=>{y.hide(),x.style("display","none")})}(l.append("g").attr("width",a).attr("height",o).attr("transform",`translate(${s.left.toString()},${s.top.toString()})`),r,a,o,this.options,this.clickHandler,this.tooltipText),Hx(l,this.options)}}function ty(t){const{label:e,number:n,options:i}=t.detail;alert(`${i.xlabel} = ${e.toText()}\n${i.ylabel} = ${n.toText()}`)}function ey(t){const{label:e,number:n,options:i}=t.detail;return`${i.xlabel} = ${e.toFixed(i.decimals)}
${i.ylabel} = ${n.toFixed(i.decimals)}`}const ny={left:8,top:8,right:8,bottom:8},iy={width:640,height:360,radius:128,label:"",labelOffset:.5,decimals:2,zeros:!1,convert:!0,tooltipOffset:{dx:16,dy:-64}};function ry(t){const{number:e,label:n,options:i,fraction:r}=t.detail,s=e.toFixed(i.decimals),a=(100*r).toFixed(0),o=void 0===i.label||""===i.label?"Value":`${i.label}: value`;alert(`${o} for ${n} is ${s} (${a}%)`)}function sy(t){const{number:e,label:n,options:i,fraction:r}=t.detail;return`${n}: ${e.toFixed(i.decimals)} (${(100*r).toFixed(0)}%)`}class ay{constructor(t,e,n){this.data=t,this.context=e,this.clickHandler=ry,this.tooltipText=sy,this.options=Object.assign(Object.assign({},iy),n)}draw(t){const e=void 0!==this.options.unit&&""!==this.options.unit?or(this.options.unit):void 0,n=Wx(this.context,this.data,this.options.zeros,e);for(;t.firstChild;)t.firstChild.remove();const i=Bx(ny,Fx(this.options.margin)),r=this.options.width-i.left-i.right,s=this.options.height-i.top-i.bottom,a=K_(t).append("svg").attr("class","pacioli chart pie-chart").attr("width",this.options.width).attr("height",this.options.height);null===n?Vx(a,"No data",this.options):function(t,e,n,i,r,s,a){t.attr("transform",`translate(${(n/2).toString()},${(i/2).toString()})`);const o=Math.min(n,i)/4,l=1.4*o,c=e.entries.reduce((t,e)=>t+e.value,0),u=t.append("g"),h=b_().domain(e.entries.map(t=>t.label)).range(Z_),d=function(){var t=Lx,e=Nx,n=null,i=J_(0),r=J_(cx),s=J_(0);function a(a){var o,l,c,u,h,d=(a=Ex(a)).length,p=0,f=new Array(d),m=new Array(d),g=+i.apply(this,arguments),v=Math.min(cx,Math.max(-cx,r.apply(this,arguments)-g)),_=Math.min(Math.abs(v)/d,s.apply(this,arguments)),x=_*(v<0?-1:1);for(o=0;o0&&(p+=h);for(null!=e?f.sort(function(t,n){return e(m[t],m[n])}):null!=n&&f.sort(function(t,e){return n(a[t],a[e])}),o=0,c=p?(v-d*x)/p:0;o0?h*c:0)+x,m[l]={data:a[l],index:o,value:h,startAngle:g,endAngle:u,padAngle:_};return m}return a.value=function(e){return arguments.length?(t="function"==typeof e?e:J_(+e),a):t},a.sortValues=function(t){return arguments.length?(e=t,n=null,a):e},a.sort=function(t){return arguments.length?(n=t,e=null,a):n},a.startAngle=function(t){return arguments.length?(i="function"==typeof t?t:J_(+t),a):i},a.endAngle=function(t){return arguments.length?(r="function"==typeof t?t:J_(+t),a):r},a.padAngle=function(t){return arguments.length?(s="function"==typeof t?t:J_(+t),a):s},a}().sort(null).value(t=>t.value)(e.entries.map(t=>({name:t.label,value:t.value}))),p=Sx().innerRadius(0).outerRadius(o),f=Sx().innerRadius(l).outerRadius(l),m=new zx("pacioli tooltip pie-chart");u.selectAll(null).data(d).enter().append("path").attr("class","slice").attr("fill",t=>h(t.data.name)).attr("d",p).on("click",(t,n)=>{if(s){const t=n.data;m.hide(),setTimeout(()=>{const n=new CustomEvent("onclick",{detail:{number:b.fromNumber(t.value,e.unit),label:t.name,fraction:t.value/c,options:r}});s(n)},0)}}).on("mouseover",(t,n)=>{if(a){const i=new CustomEvent("tooltip",{detail:{number:b.fromNumber(n.data.value,e.unit),label:n.data.name,fraction:n.data.value/c,options:r}});m.show(a(i),t.pageX+r.tooltipOffset.dx,t.pageY+r.tooltipOffset.dy)}}).on("mouseout",()=>{m.hide()}),u.selectAll("text").data(d).enter().append("text").style("text-anchor","middle").style("alignment-baseline","middle").attr("transform",t=>`translate(${f.centroid(t).toString()})`).append("tspan").attr("y","-0.6em").attr("x",0).text(t=>t.data.name)}(a.append("g").attr("transform",`translate(${i.left.toString()},${i.top.toString()})`),n,r,s,this.options,this.clickHandler,this.tooltipText),Hx(a,this.options)}}const oy={left:48,top:32,right:24,bottom:48},ly={width:640,height:360,xlabel:"x",ylabel:"y",radius:5,trendline:!1,decimals:2,convert:!0,tooltipOffset:{dx:16,dy:-64}};class cy{constructor(t,e,n){this.data=t,this.context=e,this.clickHandler=hy,this.tooltipText=uy,this.options=Object.assign(Object.assign({},ly),n)}draw(t){const e=Gx(this.context,this.data,this.options.convert&&void 0!==this.options.xunit?or(this.options.xunit):void 0,this.options.convert&&void 0!==this.options.yunit?or(this.options.yunit):void 0),n=Bx(oy,Fx(this.options.margin)),i=this.options.width-n.left-n.right,r=this.options.height-n.top-n.bottom;for(;t.firstChild;)t.firstChild.remove();const s=K_(t).append("svg").attr("width",i+n.left+n.right).attr("height",r+n.top+n.bottom).attr("class","pacioli chart scatter-plot");null===e?Vx(s,"No data",this.options):function(t,e,n,i,r,s,a){var o,l,c,u;const h=e.xUnit,d=e.yUnit,p=e.values,f=null!==(o=r.xlower)&&void 0!==o?o:e.xLower,m=null!==(l=r.xupper)&&void 0!==l?l:e.xUpper,g=null!==(c=r.ylower)&&void 0!==c?c:e.yLower,v=null!==(u=r.yupper)&&void 0!==u?u:e.yUpper,_=Y_().domain([f,m]).range([0,n]),x=Y_().domain([g,v]).range([i,0]),y=nm(_).ticks(r.xticks),w=im(x).ticks(r.yticks),M=t.append("g").attr("transform",`translate(0,${i.toString()})`).attr("class","x axis");M.append("g").call(y);const S=r.xlabel;M.append("text").attr("x",n).attr("y",32).style("text-anchor","end").text(`${S} [${h.toText()}] (n=${p.length.toString()})`);const E=r.ylabel,T=t.append("g").attr("class","y axis");T.append("g").call(w),T.append("text").attr("x",-16).attr("y",-16).text(E+" ["+d.toText()+"]");const A=new zx("pacioli tooltip scatter-plot");if(t.selectAll(null).data(p).enter().append("circle").attr("class","dot").attr("r",r.radius).attr("cx",function(t){return _(t.x)}).attr("cy",function(t){return x(t.y)}).on("click",(t,e)=>{A.hide(),s&&setTimeout(()=>{const t=new CustomEvent("onclick",{detail:{x:b.fromNumber(e.x,h),y:b.fromNumber(e.y,d),options:r,element:e.coordinates}});s(t)},0)}).on("mouseover",(t,e)=>{a&&A.show(a(new CustomEvent("tooltip",{detail:{x:b.fromNumber(e.x,h),y:b.fromNumber(e.y,d),options:r,element:e.coordinates}})),t.pageX+r.tooltipOffset.dx,t.pageY+r.tooltipOffset.dy)}).on("mouseout",()=>{A.hide()}),r.trendline&&p.length>0){const e=[],n=[];let i=p[0].x,r=p[0].y;for(const t of p){const s=t.x,a=t.y;e.push(s),n.push(a),i`:""}${i.xlabel} = ${s}\n
\n ${i.ylabel} = ${a}`}function hy(t){const{x:e,y:n,options:i,element:r}=t.detail,s=e.toText(),a=n.toText(),o=r?`${r.names.join(",")}\n`:"";alert(`${o}${i.xlabel} = ${s}\n${i.ylabel} = ${a}`)}const dy={left:48,top:32,right:16,bottom:64},py={width:640,height:360,ylabel:"Frequency",zeros:!1,convert:!0,decimals:2,gap:1,heuristic:"d3",tooltipOffset:{dx:16,dy:-64}};class fy{constructor(t,e,n){this.data=t,this.context=e,this.clickHandler=my,this.tooltipText=gy,this.options=Object.assign(Object.assign({},py),n)}draw(t){const e=void 0!==this.options.unit&&""!==this.options.unit?or(this.options.unit):void 0,n=Wx(this.context,this.data,this.options.zeros,e),i=Bx(dy,Fx(this.options.margin)),r=this.options.width-i.left-i.right,s=this.options.height-i.top-i.bottom;for(;t.firstChild;)t.firstChild.remove();const a=K_(t).append("svg").attr("width",r+i.left+i.right).attr("height",s+i.top+i.bottom).attr("class","pacioli chart histogram");if(null===n)Vx(a,"No data",this.options);else{const t=a.append("g").attr("transform",`translate(${i.left.toString()},${i.top.toString()})`),e="number"==typeof this.options.lower,o="number"==typeof this.options.upper,l="number"==typeof this.options.bins,c=e?this.options.lower:Math.floor(n.min),u=o?this.options.upper:Math.floor(n.max)+1,h=l?this.options.bins:function(t,e,n,i){const r=t.map(t=>t.value);switch(i){case"d3":return Vf().domain([e,n])(r).length;case"sturges":return vy(r);case"freedman-diaconis":return _y(r,e,n);case"seaborn":return Math.max(vy(r),_y(r,e,n));default:throw new Error(`bin size heuristic '${i}' unknown. Expected one of 'd3', 'sturges', 'freedman-diaconis', or 'seaborn'`)}}(n.entries,c,u,this.options.heuristic);if(h<=0)throw new Error(`number of bins ${h.toString()} must be a positive number`);if(u(e+1)*m+r),v=Vf().domain([r,s]).thresholds(g)(i.entries.map(t=>t.value)),_=Y_().domain([r,s]).range([0,e]),x=Hf(v,function(t){return t.length}),y=null!==(h=l.ylower)&&void 0!==h?h:0,b=null!==(d=l.yupper)&&void 0!==d?d:x,w=Y_().domain([y,b]).range([n,0]),M=t.append("g").attr("transform",`translate(0,${n.toString()})`).attr("class","x axis"),S=nm(_);void 0!==l.xticks&&S.ticks(l.xticks),M.append("g").call(S);const E=null!==(p=l.xlabel)&&void 0!==p?p:i.label;M.append("text").attr("x",e).attr("y",32).style("text-anchor","end").text(E+" ["+o.toText()+"]");const T=t.append("g").attr("transform","translate(0,0)").attr("class","y axis"),A=im(w);void 0!==l.yticks&&A.ticks(l.yticks),T.append("g").call(A),T.append("text").attr("x",-16).attr("y",-16).style("text-anchor","left").text(null!==(f=l.ylabel)&&void 0!==f?f:"");const C=new zx("pacioli tooltip histogram");t.selectAll(".bar").data(v).enter().append("g").attr("class","bar").attr("transform",function(t){return`translate(${_(t.x0).toString()}, ${w(t.length).toString()})`}).append("rect").attr("x",l.gap).attr("width",t=>Hf([0,_(t.x1)-_(t.x0)-2*l.gap+1])).attr("height",function(t){return n-w(t.length)}).on("click",(t,e)=>{var n;if(c){C.hide();const t=xy(e,i,null!==(n=l.decimals)&&void 0!==n?n:2),r=new CustomEvent("onclick",{detail:{values:t.value,frequency:t.frequency,lower:t.lower,upper:t.upper,options:l}});setTimeout(()=>{c(r)},0)}}).on("mouseover",(t,e)=>{var n;if(u){const r=xy(e,i,null!==(n=l.decimals)&&void 0!==n?n:2),s=new CustomEvent("tooltip",{detail:{values:r.value,frequency:r.frequency,lower:r.lower,upper:r.upper,options:l}});C.show(u(s),t.pageX+l.tooltipOffset.dx,t.pageY+l.tooltipOffset.dy)}}).on("mouseout",()=>{C.hide()})}(t,r,s,n,c,u,h,n.unit,this.options,this.clickHandler,this.tooltipText)}Hx(a,this.options)}nrBins(){var t;return null===(t=this.params)||void 0===t?void 0:t.nrBins}lower(){var t;return null===(t=this.params)||void 0===t?void 0:t.lower}upper(){var t;return null===(t=this.params)||void 0===t?void 0:t.upper}}function my(t){const{frequency:e,lower:n,upper:i}=t.detail,r="There are "+e.toFixed(0)+" values in the range "+n.toFixed(t.detail.options.decimals)+" to "+i.toFixed(t.detail.options.decimals);alert(r)}function gy(t){const{frequency:e,lower:n,upper:i,options:r}=t.detail;return`${n.toFixed(r.decimals)}..${i.toFixed(r.decimals)}: ${e.toFixed(0)}`}function vy(t){return Math.ceil(Math.log2(t.length))}function _y(t,e,n){const i=$f(t,.25),r=$f(t,.75);if(void 0!==i&&void 0!==r){const s=2*(r-i)/Math.pow(t.length,1/3);return 0===s?1:Math.ceil((n-e)/s)}throw new Error("cannot compute Freedman-Diaconis. Is the data valid?")}function xy(t,e,n){var i,r;const s=null!==(i=t.x0)&&void 0!==i?i:0,a=null!==(r=t.x1)&&void 0!==r?r:0,o=t.length,l=[];for(const t of e.entries){const e=t.value;s<=e&&efunction(t){if("tuple"===t.kind){const e=t[0],n=t[1];return[e.value,n.getNum(0,0)]}throw new Error("data wordcloud data kind '"+t.kind+"' unknown")}(t));throw new Error("data wordcloud data kind '"+t.kind+"' unknown")}(this.data).map(function(t){return{text:t[0],size:t[1]}}),i=Bx(wy,Fx(this.options.margin)),r=this.options.width-i.left-i.right,s=this.options.height-i.top-i.bottom,a=r+i.left+i.right,o=s+i.top+i.bottom,l=K_(t).append("svg").attr("width",a).attr("height",o).attr("class","pacioli wordcloud");0===n.length?Vx(l,"No words to display",e):function(t,e,n,i,r,s,a){const o=by()().size([n,i]).words(e).padding(5).rotate(function(){return Math.trunc(Math.random()*r.angles)*(180/r.angles)}).font("Impact").fontSize(t=>t.size).on("end",function(e){const n=new zx("pacioli tooltip wordcloud");t.append("g").attr("transform",`translate(${(o.size()[0]/2).toString()},${(o.size()[1]/2).toString()})`).selectAll("text").data(e).enter().append("text").style("font-size",function(t){return t.size.toString()+"px"}).style("font-family","Impact").attr("text-anchor","middle").attr("transform",function(t){return`translate(${t.x.toString()},${t.y.toString()})rotate(${t.rotate.toString()})`}).text(function(t){return t.text}).on("click",(t,e)=>{if(s){n.hide();const t=new CustomEvent("onclick",{detail:{value:e.text,size:e.size,options:r}});setTimeout(()=>{s(t)},0)}}).on("mouseover",(t,e)=>{if(a){const i=new CustomEvent("tooltip",{detail:{value:e.text,size:e.size,options:r}});n.show(a(i),t.pageX+r.tooltipOffset.dx,t.pageY+r.tooltipOffset.dy)}}).on("mouseout",()=>{n.hide()})});o.start()}(l.append("g").attr("transform",`translate(${i.left.toString()},${i.top.toString()})`),n,a,o,e,this.clickHandler,this.tooltipText),Hx(l,this.options)}}function Ay(t,e="definition"){let n=null,i=null;const r=t.getAttribute(e);if(null!==r){const t=r.split(":");if(2===t.length)n=t[0],i=t[1];else{if(3!==t.length||"lib"!==t[0])throw new Error(`definition ${r} is invalid. Expected a string of the form 'script:definition'.`);n="$"+t[1]+"_"+t[1],i=t[2]}}if(null===n||null===i)throw new Error("definition not found.\n\n Please give a 'definition' attribute of the form 'script:definition' with a valid value or function name.");const s=Ki(n,i);if(s instanceof et){const e=Cy(t).map(t=>Py(t)).map(t=>t.pacioliValue);return s.apply(e)}return s}function Cy(t){return[...t.children].filter(t=>"PARAMETER"===t.nodeName)}function Ry(t,e){const n=Cy(t);if(n.length!==e.length){const i=t.getAttribute("definition");throw new Error(`invalid number of arugments for definition '${null!=i?i:"unknown"}'. Expected ${n.length.toString()}, but got ${e.length.toString()}.`)}for(const[t,i]of n.entries())i.innerText=e[t]}function Py(t){var e,n,i;const r=null!==(e=t.getAttribute("label"))&&void 0!==e?e:"n/a",s=null!==(n=t.getAttribute("type"))&&void 0!==n?n:"number",a=null!==(i=t.getAttribute("unit"))&&void 0!==i?i:"1",o=t.innerText;try{switch(s){case"string":return{type:"string",label:r,value:o,pacioliValue:Nt(o)};case"number":{if(""===o)throw new Error(`invalid value for ${s} parameter ${r}`);const t=lr(o+" * "+a);return{type:"number",label:r,value:o,unit:a,pacioliUnit:t.unit,pacioliValue:ar(Number(t.magnitude),t.unit)}}case"boole":return{type:"boole",label:r,value:o,pacioliValue:"true"===o?Q:tt};default:throw new Error(`unexpected parameter type '${s}' for parameter '${r}'. Expected 'string', 'number', or 'boole'.`)}}catch(t){throw new Error(`cannot read value ${o} for ${s} parameter ${r}:\n\n ${t instanceof Error?t.message:String(t)}.`)}}function Ny(t){const e=t.getAttribute("for");if(null===e)throw new Zt("No 'for' attribute found. Provide a 'for' attribute with the target's element id as value.");{const t=[];for(const n of e.split(",")){const e=n.trim(),i=document.getElementById(e);if(null===i)throw new Zt(`Could not find element '${e}'. Provide a valid element id in the 'for' attribute.`);t.push(i)}return t}}function Ly(t,e){return Object.assign(Object.assign(Object.assign({},function(t,e){let n={};for(const i of e){const e=t.getAttribute(i);null!==e&&(n=Object.assign(Object.assign({},n),{[i]:e}))}return n}(t,e.strings)),function(t,e){let n={};for(const i of e)n=Object.assign(Object.assign({},n),{[i]:t.hasAttribute(i)});return n}(t,e.booleans)),function(t,e){let n={};for(const i of e){const e=t.getAttribute(i);if(null!==e){const t=Number(e);if(!Number.isFinite(t))throw new Error(`Invalid number ${e} for attritube ${i}`);n=Object.assign(Object.assign({},n),{[i]:t})}}return n}(t,e.numbers))}function Uy(t,e){if(!t.hasAttribute("options"))return{};const n=Ay(t,"options");if("list"===n.kind){const t=new Map;for(const e of n){if("tuple"!==e.kind)throw new Error(`found a ${e.kind} in the options instead of a tuple. Chart options must be pairs (tuple) of strings.`);if("string"!==e[0].kind)throw new Error(`chart option key must be a string, got a ${e[0].kind}`);if("string"!==e[1].kind)throw new Error(`chart option value for ${e[0].value} must be a string, got a ${e[1].kind}`);t.has(e[0].value)&&console.warn(`Duplicate chart attribute ${e[0].value}`);const n=e[0].value,i=e[1].value;t.set(n,i)}let i={};for(const n of e.strings)t.has(n)&&(i=Object.assign(Object.assign({},i),{[n]:t.get(n)}),t.set(n,null));for(const n of e.booleans)t.has(n)&&(i=Object.assign(Object.assign({},i),{[n]:"true"===t.get(n)}),t.set(n,null));for(const n of e.numbers)if(t.has(n)){const e=t.get(n),r=Number(e);if(!Number.isFinite(r))throw new Error(`invalid number ${r.toString()} for attritube ${n}`);i=Object.assign(Object.assign({},i),{[n]:r}),t.set(n,null)}for(const e of t.keys())null!==t.get(e)&&console.warn(`Ignoring unknown chart option '${e}'`);return i}throw new Error(`attribute options must be a list, got a ${n.kind}`)}function Dy(t,e){t.addEventListener("change",t=>{t.preventDefault();const n=t.target;e(n.value)})}function Iy(t,e){t.addEventListener("click",t=>{e(),t.preventDefault()})}function Oy(t,e){t.addEventListener("change",t=>{t.preventDefault(),e(t.target.checked)})}function ky(t,e,n=0){const i=t.getAttribute(e);return Number(null!=i?i:n)}function Fy(t,e,n){var i;return null!==(i=t.getAttribute(e))&&void 0!==i?i:n}function By(t,e){return t.hasAttribute(e)}function zy(...t){return t.reduce((t,e)=>({strings:[...t.strings,...e.strings],booleans:[...t.booleans,...e.booleans],numbers:[...t.numbers,...e.numbers]}),{strings:[],booleans:[],numbers:[]})}function Vy(t){return[...t.strings,...t.booleans,...t.numbers]}const Hy=document.createElement("template");Hy.innerHTML='\n \n
\n
\n    \n  
\n
\n
\n';const Gy={strings:["definition","caption"],booleans:[],numbers:["width","height"]};class Wy extends HTMLElement{constructor(){super(...arguments),this.isInitialized=!1}set definition(t){this.setStringAttribute("definition",t)}get definition(){return this.getStringAttribute("definition")}get caption(){return this.getStringAttribute("caption")}set caption(t){this.setStringAttribute("caption",t)}set width(t){this.setNumberAttribute("width",t)}get width(){return this.getNumberAttribute("width",0)}set height(t){this.setNumberAttribute("height",t)}get height(){return this.getNumberAttribute("height",0)}connectedCallback(){try{this.rootElement().appendChild(Hy.content.cloneNode(!0)),this.errorCloseButton().addEventListener("click",()=>{this.clearErrors()}),this.clearErrors(),t=this,new MutationObserver(()=>{try{t.parametersChanged()}catch(e){t.displayError(e instanceof Error?e.message:String(e))}}).observe(t,{attributes:!1,childList:!0,subtree:!0}),setTimeout(()=>{try{this.isInitialized||(this.parametersChanged(),this.isInitialized=!0)}catch(t){this.displayError(t instanceof Error?t.message:String(t))}},1)}catch(t){this.displayError(t instanceof Error?t.message:String(t))}var t}contentParent(){const t=this.rootElement().querySelector(".content");if(null===t)throw new Error("Cannot find content parent");return t}clearContent(){const t=this.contentParent();for(;t.firstChild;)t.firstChild.remove()}findElement(t){const e=this.rootElement().querySelector(t);if(null===e)throw new Error(`Cannot find element '${t}'`);return e}parametersChanged(){}setParameters(t){Ry(this,t);try{this.parametersChanged()}catch(t){this.displayError(t instanceof Error?t.message:String(t))}}evaluateDefinition(){return Ay(this)}isBusy(){return!1}displayError(t){try{const e=this.errorRoot(),n=this.errorContentParent();e.hidden=!1,n.innerText=t+"\n\n"+n.innerText}catch(e){const n=e instanceof Error?e.message:String(e);console.log(`Error: ${t}.\n\nThe error is displayed in the console because of the following: ${n}`)}}clearErrors(){try{this.errorContentParent().innerText="",this.errorRoot().hidden=!0}catch(t){const e=t instanceof Error?t.message:String(t);console.log(`Error while clearing the errors: ${e}`)}}errorRoot(){const t=this.rootElement().querySelector(".error-root");if(null===t)throw new Error("Error root element does not exist");return t}errorContentParent(){const t=this.rootElement().querySelector(".error-content");if(null===t)throw new Error("Error content element does not exist");return t}errorCloseButton(){const t=this.rootElement().querySelector(".close-button");if(null===t)throw new Error("Error close button element does not exist");return t}getNumberAttribute(t,e=0){return ky(this,t,e)}setNumberAttribute(t,e){!function(t,e,n){void 0===n?t.removeAttribute(e):t.setAttribute(e,n.toString())}(this,t,e)}getStringAttribute(t,e){return Fy(this,t,e)}setStringAttribute(t,e){!function(t,e,n){void 0===n?t.removeAttribute(e):t.setAttribute(e,n)}(this,t,e)}getBooleAttribute(t){return By(this,t)}setBooleAttribute(t,e){!function(t,e,n){!0===n?t.setAttribute(e,""):t.removeAttribute(e)}(this,t,e)}}class jy extends Wy{constructor(){super(),this.root=this.attachShadow({mode:"open"})}rootElement(){return this.root}adoptStyles(t){const e=new CSSStyleSheet;e.replaceSync(t),this.root.adoptedStyleSheets=[e]}}const Xy=zy(Gy,{strings:["unitx","unity","unitz","background","axisColorsX","axisColorsY","axisColorsZ","gridColor","ambientColor","labelColor"],booleans:["axis","grid","orthographic","hideLabels","autoRotation"],numbers:["axisSize","ambientIntensity","gridSize","gridDivisions","cameraNear","cameraFar","cameraX","cameraY","cameraZ","secondsPerRotation"]});class $y extends jy{constructor(){super(),this.adoptStyles(" \n .content{ display: inline; }")}connectedCallback(){super.connectedCallback(),this.space=new of(this.contentParent(),this.spaceOptions())}attributeChangedCallback(t,e,n){try{switch(t){case"unit":this.unit=or(n);break;case"unitx":this.unitX=or(n);break;case"unity":this.unitY=or(n);break;case"unitz":this.unitZ=or(n)}}catch(t){this.displayError(t instanceof Error?t.message:String(t))}}parametersChanged(){void 0!==this.space&&(this.fetchedData=this.evaluateDefinition(),this.loadData(this.space))}kind(){const t=this.getAttribute("kind");if(null===t)return"scene";if("scene"===t||"animation"===t||"stateful-animation"===t)return t;throw new Error(`cannot set kind '${t}' on PacioliControlsComponent. Valid kinds are 'scene', 'animation' or 'stateful-animation'`)}isAnimation(){const t=this.kind();return"animation"===t||"stateful-animation"===t}spaceOptions(){return Object.assign({unitX:this.unitX||this.unit||or("metre"),unitY:this.unitY||this.unit||or("metre"),unitZ:this.unitZ||this.unit||or("metre")},Ly(this,Xy))}reset(){this.space&&!this.space.isRunning()&&this.loadData(this.space)}isBusy(){var t;return null!==(t=this.isRunning())&&void 0!==t&&t}isRunning(){return this.space&&this.space.isRunning()}setRunning(t){this.space&&this.space.setRunning(t)}step(){this.space&&!this.space.isRunning()&&this.space.updateScene()}openImage(t){const e=this.findElement("canvas").toDataURL("image/png");if(void 0===t)window.open(e,"_blank");else{const n=document.createElement("a");n.href=e,n.download=`${t}.png`,n.click()}}loadData(t){this.fetchedData&&(function(t,e,n){switch(n){case"scene":if("tuple"!==e.kind)throw new Zt(`Cannot load scene. Expected a tuple but got a ${n}`);if(7!==e.length)throw new Zt('Invalid scene. Could it be an animation? In that case add kind="animation" or kind="stateful-animation"');t.loadScene(e);break;case"animation":t.loadAnimation(e);break;case"stateful-animation":t.loadStatefulAnimation(e)}}(t,this.fetchedData,this.kind()),t.draw())}}$y.observedAttributes=Vy(Xy),customElements.define("pacioli-scene",$y);const qy=document.createElement("template");qy.innerHTML='\n \n\n
\n \n \n \n \n
\n \n
\n \n \n \n \n
\n';class Yy extends jy{attributeChangedCallback(t,e,n){"for"===t&&this.isConnected&&this.updateControls()}connectedCallback(){super.connectedCallback(),this.contentParent().appendChild(qy.content.cloneNode(!0)),this.addEventListeners(),setTimeout(()=>{this.updateControls()},1)}sceneElements(){const t=[];for(const e of Ny(this))"PACIOLI-SCENE"===e.nodeName&&t.push(e);return t}addEventListeners(){Iy(this.animationButton('[part="button run"]'),()=>{this.startButtonClicked()}),Iy(this.animationButton('[part="button step"]'),()=>{this.stepButtonClicked()}),Iy(this.animationButton('[part="button reset"]'),()=>{this.resetButtonClicked()}),Oy(this.configurationLabel(".axis"),t=>{this.axisCheckBoxClicked(t)}),Oy(this.configurationLabel(".grid"),t=>{this.gridCheckBoxClicked(t)}),Oy(this.configurationLabel(".labels"),t=>{this.labelsCheckBoxClicked(t)}),Oy(this.configurationLabel(".rotate"),t=>{this.autoRotateCheckboxClicked(t)}),Iy(this.animationButton(".snapshot"),()=>{this.snapshotButtonClicked()})}startButtonClicked(){for(const t of this.sceneElements())try{const e=t.isRunning();void 0!==e&&(t.setRunning(!e),this.updateControls())}catch(e){t.displayError(e instanceof Error?e.message:String(e))}}stepButtonClicked(){for(const t of this.sceneElements())try{t.step(),this.updateControls()}catch(e){t.displayError(e instanceof Error?e.message:String(e))}}resetButtonClicked(){for(const t of this.sceneElements())try{t.reset(),this.updateControls()}catch(e){t.displayError(e instanceof Error?e.message:String(e))}}axisCheckBoxClicked(t){for(const e of this.sceneElements())if(e.space)try{t?e.space.showAxis():e.space.hideAxis()}catch(t){e.displayError(t instanceof Error?t.message:String(t))}}labelsCheckBoxClicked(t){for(const e of this.sceneElements())if(e.space)try{t?e.space.showLabels():e.space.hideLabels()}catch(t){e.displayError(t instanceof Error?t.message:String(t))}}gridCheckBoxClicked(t){for(const e of this.sceneElements())if(e.space)try{t?e.space.showGrid():e.space.hideGrid()}catch(t){e.displayError(t instanceof Error?t.message:String(t))}}autoRotateCheckboxClicked(t){for(const e of this.sceneElements())if(e.space)try{t?e.space.startAutoRotation(Yy.SECONDS_PER_ROTATION):e.space.stopAutoRotation()}catch(t){e.displayError(t instanceof Error?t.message:String(t))}}snapshotButtonClicked(){const t=this.sceneElements();0===t.length&&alert("No scene to take snapshot of");for(const e of t)e.openImage(e.id)}updateControls(){const t=this.animationButton(".run"),e=this.animationButton(".step"),n=this.animationButton(".reset"),i=this.sceneElements(),r=0===i.length?void 0:i[0];if(null==r?void 0:r.space){const i=r.space;if(this.configurationCheckbox(".axis").checked=i.hasAxis(),this.configurationCheckbox(".grid").checked=i.hasGrid(),this.configurationCheckbox(".labels").checked=i.hasLabels(),this.configurationCheckbox(".rotate").checked=i.autoRotateSpeed()>0,r.isAnimation()){const r=i.isRunning();t.style.display="",e.style.display="",n.style.display="",t.innerText=r?"Pause":"Run",e.innerText="Step "+i.runningTime().toFixed(2)+"s",t.disabled=!1,e.disabled=r,n.disabled=r}else t.style.display="none",e.style.display="none",n.style.display="none"}else t.style.display="",e.style.display="",n.style.display="",t.disabled=!1,e.disabled=!1,n.disabled=!1}animationButton(t){return this.findElement(t)}configurationLabel(t){return this.findElement(`.configuration ${t}`)}configurationCheckbox(t){return this.configurationLabel(t).children[0]}}Yy.observedAttributes=["for"],Yy.SECONDS_PER_ROTATION=30,customElements.define("pacioli-controls",Yy);const Zy=document.createElement("template");Zy.innerHTML='\n \n\n
\n\n \n';class Ky extends jy{attributeChangedCallback(t,e,n){try{"for"===t&&this.isConnected&&(this.removeTableRows(),this.createAndAppendTableRows())}catch(t){this.displayError(t instanceof Error?t.message:String(t))}}connectedCallback(){try{super.connectedCallback(),this.contentParent().className="content",this.contentParent().appendChild(Zy.content.cloneNode(!0)),setTimeout(()=>{try{this.findElement(".apply").addEventListener("click",()=>{this.applyButtonClicked()}),this.createAndAppendTableRows()}catch(t){this.displayError(t instanceof Error?t.message:String(t))}},1)}catch(t){this.displayError(t instanceof Error?t.message:String(t))}}createAndAppendTableRows(){this.targets=this.createTargetsInfo(),function(t,e){for(const n of e)for(const e of n.inputs){const n=document.createElement("tr"),i=document.createElement("td"),r=document.createElement("td"),s=document.createElement("td");switch(i.innerText=e.parameter.label,r.appendChild(e.element),e.parameter.type){case"string":case"boole":s.innerText="";break;case"number":s.innerText=e.parameter.pacioliUnit.toText()}n.appendChild(i),n.appendChild(r),n.appendChild(s),t.appendChild(n)}}(this.tableElement(),this.targets)}removeTableRows(){for(;this.tableElement().rows.length>0;)this.tableElement().deleteRow(0);this.targets=void 0}createTargetsInfo(){const t=!this.hasAttribute("calm"),e=[];for(const n of Ny(this)){const i=Qy(Cy(n).map(t=>Py(t)),t,()=>{this.applyButtonClicked()});e.push({element:n,inputs:i})}return e}applyButtonClicked(){var t;try{for(const e of null!==(t=this.targets)&&void 0!==t?t:[])Ry(e.element,e.inputs.map(t=>"boole"===t.parameter.type?t.element.checked?"true":"false":t.element.value))}catch(t){this.displayError(t instanceof Error?t.message:String(t))}}tableElement(){return this.findElement(".parameters")}}Ky.observedAttributes=["for"];const Jy=!0;function Qy(t,e,n){return t.map(t=>{const i=document.createElement("input");return i.className="pacioli-controls-input","boole"===t.type?(i.checked="true"===t.value,i.type="checkbox"):(i.value="number"===t.type?t.value.trim():t.value,i.type=t.type),n&&(e&&"boole"===t.type&&i.addEventListener("change",t=>{Jy&&(t.preventDefault(),n())}),i.addEventListener("keypress",t=>{"Enter"===t.key&&(t.preventDefault(),n())})),{parameter:t,element:i}})}customElements.define("pacioli-inputs",Ky);const tb={strings:["zero"],booleans:["raw","exponential","ascii","clipboard"],numbers:["decimals"]};class eb extends jy{get decimals(){return this.getNumberAttribute("decimals")}set decimals(t){this.setNumberAttribute("decimals",t)}get zero(){return this.getStringAttribute("zero")}set zero(t){this.setStringAttribute("zero",t)}get raw(){return this.getBooleAttribute("raw")}set raw(t){this.setBooleAttribute("raw",t)}get exponential(){return this.getBooleAttribute("exponential")}set exponential(t){this.setBooleAttribute("exponential",t)}get ascii(){return this.getBooleAttribute("ascii")}set ascii(t){this.setBooleAttribute("ascii",t)}get clipboard(){return this.getBooleAttribute("clipboard")}set clipboard(t){this.setBooleAttribute("clipboard",t)}}const nb={strings:["margin"],booleans:["nopopup","notooltip"],numbers:[]};class ib extends eb{get margin(){return this.getStringAttribute("margin")}set margin(t){this.setStringAttribute("margin",t)}get nopopup(){return this.getBooleAttribute("nopopup")}set nopopup(t){this.setBooleAttribute("nopopup",t)}get notooltip(){return this.getBooleAttribute("notooltip")}set notooltip(t){this.setBooleAttribute("notooltip",t)}attributeChangedCallback(t,e,n){try{void 0!==this.data&&("definition"===t&&(this.data=this.evaluateDefinition()),this.drawChart(this.data))}catch(t){this.displayError(t instanceof Error?t.message:String(t))}}parametersChanged(){this.data=this.evaluateDefinition(),this.drawChart(this.data)}}const rb=zy(Gy,tb,nb,{strings:["label","xlabel","unit","xunit","yunit"],booleans:["smooth","rotate"],numbers:["norm","ylower","yupper","xticks","yticks"]});class sb extends ib{get unit(){return this.getStringAttribute("unit")}set unit(t){this.setStringAttribute("unit",t)}get xunit(){return this.getStringAttribute("xunit")}set xunit(t){this.setStringAttribute("xunit",t)}get yunit(){return this.getStringAttribute("yunit")}set yunit(t){this.setStringAttribute("yunit",t)}get ylower(){return this.getNumberAttribute("ylower",0)}set ylower(t){this.setNumberAttribute("ylower",t)}get yupper(){return this.getNumberAttribute("yupper",1)}set yupper(t){this.setNumberAttribute("yupper",t)}get smooth(){return this.getBooleAttribute("smooth")}set smooth(t){this.setBooleAttribute("smooth",t)}constructor(){super(),this.adoptStyles("\n\n.data {\n stroke: steelblue;\n stroke-width: 1;\n fill: none;\n}\n \n.axis {\n shape-rendering: crispEdges;\n}\n\n.axis text {\n font-size: 10pt;\n}\n\n.axis path,\n.axis line {\n stroke-opacity: .5;\n stroke: lightgrey;\n}\n\n.x.axis path {\n display: none;\n}\n\n.dot {\n fill: lightblue !important ;\n stroke: darkgray;\n}\n")}drawChart(t){this.clearContent(),this.clearErrors();const e=Object.assign(Object.assign({},Uy(this,rb)),Ly(this,rb));this.chart=new Qx(t,Z.si(),e);const n=this.chart.clickHandler;this.chart.clickHandler=t=>{this.dispatchEvent(t),!this.nopopup&&n&&n(t)},this.notooltip&&(this.chart.tooltipText=void 0),this.chart.draw(this.contentParent())}}sb.observedAttributes=Vy(rb),customElements.define("pacioli-line-chart",sb);const ab=zy(Gy,tb,nb,{strings:["xlabel","ylabel","unit"],booleans:[],numbers:["ylower","yupper","padding"]});class ob extends ib{get xlabel(){return this.getStringAttribute("xlabel","")}set xlabel(t){this.setStringAttribute("xlabel",t)}get ylabel(){return this.getStringAttribute("ylabel","")}set ylabel(t){this.setStringAttribute("ylabel",t)}get unit(){return this.getStringAttribute("unit")}set unit(t){this.setStringAttribute("unit",t)}get ylower(){return this.getNumberAttribute("ylower",0)}set ylower(t){this.setNumberAttribute("ylower",t)}get yupper(){return this.getNumberAttribute("yupper",1)}set yupper(t){this.setNumberAttribute("yupper",t)}get padding(){return this.getNumberAttribute("padding",1)}set padding(t){this.setNumberAttribute("padding",t)}constructor(){super(),this.adoptStyles(" \n .bar {\n fill: steelblue;\n }\n .bar:hover {\n fill: brown;\n }")}drawChart(t){this.clearContent(),this.clearErrors();const e=Object.assign(Object.assign({},Uy(this,ab)),Ly(this,ab)),n=new Zx(t,Z.si(),e),i=n.clickHandler;n.clickHandler=t=>{this.dispatchEvent(t),!this.nopopup&&i&&i(t)},this.notooltip&&(n.tooltipText=void 0),this.chart=n,this.chart.draw(this.contentParent())}}ob.observedAttributes=Vy(ab),customElements.define("pacioli-bar-chart",ob);const lb=zy(Gy,tb,nb,{strings:["unit","xlabel","ylabel","heuristic"],booleans:[],numbers:["bins","lower","upper","gap","ylower","yupper","xticks","yticks"]});class cb extends ib{get xlabel(){return this.getStringAttribute("xlabel","")}set xlabel(t){this.setStringAttribute("xlabel",t)}get ylabel(){return this.getStringAttribute("ylabel","")}set ylabel(t){this.setStringAttribute("ylabel",t)}get unit(){return this.getStringAttribute("unit")}set unit(t){this.setStringAttribute("unit",t)}get heuristic(){return this.getStringAttribute("heuristic")}set heuristic(t){this.setStringAttribute("heuristic",t)}get lower(){return this.getNumberAttribute("lower",0)}set lower(t){this.setNumberAttribute("lower",t)}get gap(){return this.getNumberAttribute("gap",0)}set gap(t){this.setNumberAttribute("gap",t)}get yupper(){return this.getNumberAttribute("yupper",1)}set yupper(t){this.setNumberAttribute("yupper",t)}constructor(){super(),this.adoptStyles(" \n\n.axis {\n shape-rendering: crispEdges;\n}\n\n.bar {\n fill: steelblue;\n}\n\n.bar:hover {\n fill: brown;\n}\n\n.axis text {\n font-size: 10pt;\n}\n\n.axis path,\n.axis line {\n stroke-opacity: .5;\n stroke: lightgrey;\n}\n\n.x.axis path {\n display: none;\n}\n\n ")}drawChart(t){this.clearContent(),this.clearErrors();const e=Object.assign(Object.assign({},Uy(this,lb)),Ly(this,lb));this.chart=new fy(t,Z.si(),e);const n=this.chart.clickHandler;this.chart.clickHandler=t=>{this.dispatchEvent(t),!this.nopopup&&n&&n(t)},this.notooltip&&(this.chart.tooltipText=void 0),this.chart.draw(this.contentParent())}}cb.observedAttributes=Vy(lb),customElements.define("pacioli-histogram",cb);class ub extends Wy{constructor(){super(...arguments),this.parentDiv=document.createElement("div")}connectedCallback(){this.rootElement().appendChild(this.contentParent())}rootElement(){return this}contentParent(){return this.parentDiv}clearContent(){const t=this.contentParent();for(;t.firstChild;)t.firstChild.remove()}findElement(t){const e=this.rootElement().querySelector(t);if(null===e)throw new Error(`Cannot find element '${t}'`);return e}}const hb=document.createElement("template");hb.innerHTML='\n \n
\n \n \n \n \n
\n
\n \n \n \n
\n';class db extends ub{connectedCallback(){super.connectedCallback(),this.contentParent().appendChild(hb.content.cloneNode(!0)),this.contentParent().className="pacioli histogram options",this.addEventListeners(),setTimeout(()=>{this.updateInputs()},1)}histogramElement(){const t=Ny(this);return t.length>0?t[0]:void 0}addEventListeners(){const t=[[".bins input","bins"],[".lower input","lower"],[".upper input","upper"]];for(const[e,n]of t)Dy(this.inputElement(e),t=>{var e,i;""===t?null===(e=this.histogramElement())||void 0===e||e.removeAttribute(n):null===(i=this.histogramElement())||void 0===i||i.setAttribute(n,t)});Iy(this.buttonElement(".custom"),()=>{var t,e;const n=this.inputElement(".bins input").value;""===n?null===(t=this.histogramElement())||void 0===t||t.removeAttribute("bins"):null===(e=this.histogramElement())||void 0===e||e.setAttribute("bins",n)});const e=[[".d3","d3"],[".sturges","sturges"],[".freedman-diaconis","freedman-diaconis"]];for(const[t,n]of e)Iy(this.buttonElement(t),()=>{var t,e;null===(t=this.histogramElement())||void 0===t||t.removeAttribute("bins"),null===(e=this.histogramElement())||void 0===e||e.setAttribute("heuristic",n)})}updateInputs(){const t=this.inputElement(".bins input"),e=this.inputElement(".lower input"),n=this.inputElement(".upper input"),i=this.histogramElement();if(i){const r=i.getAttribute("nrBins");null!==r&&(t.value=r);const s=i.getAttribute("lower");null!==s&&(e.value=s);const a=i.getAttribute("upper");null!==a&&(n.value=a)}}inputElement(t){return this.findElement(t)}buttonElement(t){return this.findElement(t)}}db.observedAttributes=["for"],customElements.define("pacioli-histogram-options",db);const pb=zy(Gy,tb,nb,{strings:["unit","label"],booleans:[],numbers:["radius","labelOffset"]});class fb extends ib{get label(){return this.getStringAttribute("label","")}set label(t){this.setStringAttribute("label",t)}get unit(){return this.getStringAttribute("unit")}set unit(t){this.setStringAttribute("unit",t)}get radius(){return this.getNumberAttribute("radius",0)}set radius(t){this.setNumberAttribute("radius",t)}constructor(){super(),this.adoptStyles("\n\n")}drawChart(t){this.clearContent(),this.clearErrors();const e=Object.assign(Object.assign({},Uy(this,pb)),Ly(this,pb));this.chart=new ay(t,Z.si(),e);const n=this.chart.clickHandler;this.chart.clickHandler=t=>{this.dispatchEvent(t),!this.nopopup&&n&&n(t)},this.notooltip&&(this.chart.tooltipText=void 0),this.chart.draw(this.contentParent())}}fb.observedAttributes=Vy(pb),customElements.define("pacioli-pie-chart",fb);const mb=zy(Gy,tb,nb,{strings:["label","xunit","yunit"],booleans:["trendline"],numbers:["xlower","xupper","ylower","yupper","xticks","yticks","radius"]});class gb extends ib{get xunit(){return this.getStringAttribute("xunit","")}set xunit(t){this.setStringAttribute("xunit",t)}get yunit(){return this.getStringAttribute("yunit","")}set yunit(t){this.setStringAttribute("yunit",t)}get xlower(){return this.getNumberAttribute("xlower",0)}set xlower(t){this.setNumberAttribute("xlower",t)}get xupper(){return this.getNumberAttribute("xupper",1)}set xupper(t){this.setNumberAttribute("xupper",t)}get ylower(){return this.getNumberAttribute("ylower",0)}set ylower(t){this.setNumberAttribute("ylower",t)}get yupper(){return this.getNumberAttribute("yupper",1)}set yupper(t){this.setNumberAttribute("yupper",t)}constructor(){super(),this.adoptStyles("\n\n.axis {\n shape-rendering: crispEdges;\n}\n\n.axis text {\n font-size: 10pt;\n}\n\n.axis path,\n.axis line {\n stroke-opacity: .5;\n stroke: lightgrey;\n}\n\n\n.dot {\n fill: lightblue !important ;\n stroke: darkgray;\n}")}drawChart(t){this.clearContent(),this.clearErrors();const e=Object.assign(Object.assign({},Uy(this,mb)),Ly(this,mb));this.chart=new cy(t,Z.si(),e);const n=this.chart.clickHandler;this.chart.clickHandler=t=>{this.dispatchEvent(t),!this.nopopup&&n&&n(t)},this.notooltip&&(this.chart.tooltipText=void 0),this.chart.draw(this.contentParent())}}gb.observedAttributes=Vy(mb),customElements.define("pacioli-scatter-plot",gb);const vb=zy(Gy,{strings:[],booleans:["nopopup","notooltip"],numbers:[]});class _b extends jy{get nopopup(){return this.getBooleAttribute("nopopup")}set nopopup(t){this.setBooleAttribute("nopopup",t)}get notooltip(){return this.getBooleAttribute("notooltip")}set notooltip(t){this.setBooleAttribute("notooltip",t)}constructor(){super(),this.adoptStyles("")}attributeChangedCallback(t,e,n){try{void 0!==this.data&&("definition"===t&&(this.data=this.evaluateDefinition()),this.drawChart(this.data))}catch(t){this.displayError(t instanceof Error?t.message:String(t))}}parametersChanged(){this.data=this.evaluateDefinition(),this.drawChart(this.data)}drawChart(t){this.clearContent();const e=Object.assign(Object.assign({},Uy(this,vb)),Ly(this,vb)),n=new Ty(t,e),i=n.clickHandler;n.clickHandler=t=>{this.dispatchEvent(t),!this.nopopup&&i&&i(t)},this.notooltip&&(n.tooltipText=void 0),this.chart=n,this.chart.draw(this.contentParent())}}_b.observedAttributes=Vy(vb),customElements.define("pacioli-wordcloud",_b);const xb=zy(Gy,tb,{strings:[],booleans:["totals"],numbers:[]});class yb extends eb{constructor(){super(),this.adoptStyles("\n.pacioli-table {\n\nborder-spacing: 0;\nborder-collapse: collapse;\n\ntr {\n height: 28px;\n}\n\ntd {\n border-bottom: solid lightgrey;\n}\n\nth {\n border-width: 1px 1px 1px 1px;\n padding-left: 1em;\n text-align: left;\n}\n\ntd.key {\n padding-left: 1em;\n padding-right: 0.25em;\n border-width: 1px 1px 1px 1px;\n}\n\ntd.value {\n padding-left: 1em;\n border-width: 1px 0px 1px 1px;\n text-align: right;\n}\n\ntd.unit {\n padding-left: 0.25em;\n padding-right: 0.25em;\n border-width: 1px 1px 1px 0px;\n text-align: left;\n white-space: nowrap;\n}\n\ntd.total {\n font-weight: bold;\n}\n}\n")}attributeChangedCallback(t,e,n){try{void 0!==this.data&&("definition"===t&&(this.data=this.evaluateDefinition()),this.drawTable(this.data))}catch(t){this.displayError(t instanceof Error?t.message:String(t))}}parametersChanged(){this.data=this.evaluateDefinition(),this.drawTable(this.data)}drawTable(t){this.clearContent(),this.clearErrors();const e=Object.assign(Object.assign({},Uy(this,xb)),Ly(this,xb));this.contentParent().appendChild(ht(t,e))}}yb.observedAttributes=Vy(xb),customElements.define("pacioli-value",yb);const bb=zy(Gy,tb,{strings:[],booleans:["nozerorows","totals"],numbers:[]});function wb(t){return new Zt(`Unexpected data for table. ${t}\n\n${Mb}`)}const Mb="Valid chart data for a table is \n - a list of (number, number) pairs\n - a pair of number lists\n - a pair of number vectors\n - a vector\n - a list of numbers";class Sb extends eb{get totals(){return this.getBooleAttribute("totals")}set totals(t){this.setBooleAttribute("totals",t)}get nozerorows(){return this.getBooleAttribute("nozerorows")}set nozerorows(t){this.setBooleAttribute("nozerorows",t)}constructor(){super(),this.adoptStyles(" \ntable {\n border-spacing: 0;\n border-collapse: collapse;\n}\n\ntr {\n height: 28px;\n}\n\ntd {\n border-bottom: solid lightgrey;\n}\n\nth {\n border-width: 1px 1px 1px 1px;\n padding-left: 1em;\n text-align: left;\n}\n\ntd.key {\n padding-left: 1em;\n padding-right: 0.25em;\n border-width: 1px 1px 1px 1px;\n}\n\ntd.value {\n padding-left: 1em;\n border-width: 1px 0px 1px 1px;\n text-align: right;\n}\n\ntd.unit {\n padding-left: 0.25em;\n padding-right: 0.25em;\n border-width: 1px 1px 1px 0px;\n text-align: left;\n white-space: nowrap;\n}\n\ntd.total {\n font-weight: bold;\n}\n")}attributeChangedCallback(t,e,n){try{void 0!==this.columns&&("definition"===t&&(this.columns=this.collectColumns()),this.drawTable(this.columns))}catch(t){this.displayError(t instanceof Error?t.message:String(t))}}parametersChanged(){this.columns=this.collectColumns(),void 0!==this.columns&&this.columns.length>0&&this.drawTable(this.columns)}collectColumns(){return[...(t=this,t.hasAttribute("definition")?function(t){if("tuple"===t.kind||"list"===t.kind){const e=t.map(t=>{if("tuple"===t.kind)return function(t){if(t.length<2||t.length>5)throw wb(`Invalid column. Expected a (string, value, ...) tuple, got ${t.length.toString()} tuple elements instead of 2 to 5.`);if("string"!==t[0].kind)throw wb(`Invalid column. Expected a (string, value, ...) tuple, but the first tuple element is a '${t[0].kind}'.`);const e=t[0].value;if("matrix"!==t[1].kind&&"list"!==t[1].kind)throw wb(`Column '${e}'' is invalid. Expected a vector or list value, but the second tuple element is a '${t[1].kind}'.`);try{const e=t.length>2?function(t){if("matrix"===t.kind)return t.getNum(0,0);if("maybe"===t.kind){const e=t.value;if(void 0===e)return;if("matrix"===e.kind)return e.getNum(0,0)}throw wb(`Invalid decimals. Expected a number or a maybe number, got a '${t.kind}'`)}(t[2]):void 0,n=t.length>3?function(t){if("boole"===t.kind)return t.value;if("maybe"===t.kind){const e=t.value;if(void 0===e)return;if("boole"===e.kind)return e.value}throw wb(`Invalid show totals value. Expected a boole or a maybe, got a '${t.kind}'`)}(t[3]):void 0,i=t.length>4?function(t){if("matrix"===t.kind)return t;if("maybe"===t.kind){const e=t.value;if(void 0===e||"matrix"===e.kind)return e}throw wb(`Invalid total. Expected a number, got a '${t.kind}'`)}(t[4]):void 0;return{header:t[0].value,value:t[1],decimals:e,showTotal:n,total:i}}catch(t){throw wb(`Error in column '${e}': ${t instanceof Error?t.message:String(t)}`)}}(t);throw wb(`Invalid column. Expected a tuple, got a '${t.kind}'`)});return e}throw wb(`Expected a tuple or list of columns, got a '${t.kind}'`)}(Ay(t)):[]),...Eb(this)];var t}drawTable(t){this.clearContent(),this.clearErrors();const e=Object.assign(Object.assign({},Uy(this,bb)),Ly(this,bb));this.contentParent().appendChild(pt(t,e))}}function Eb(t){const e=[];for(const n of t.children)if("COLUMN"===n.nodeName){const t=n,i=Fy(t,"header","No 'header' attribute"),r=t.hasAttribute("decimals")?ky(t,"decimals"):void 0,s=By(t,"raw"),a=By(t,"exponential"),o=By(t,"totals"),l=Fy(t,"unit"),c=void 0===l?void 0:or(l),u=Ay(t);if("matrix"!==u.kind&&"list"!==u.kind)throw wb(`Invalid column '${i}'. Expected a matrix or a list, got a '${u.kind}'`);e.push({header:i,value:u,unit:c,decimals:r,raw:s,exponential:a,showTotal:o})}return e}Sb.observedAttributes=Vy(bb),customElements.define("pacioli-table",Sb);class Tb{constructor(t,e,n,i={}){this.cells=t,this.rowNames=e,this.columnNames=n,this.options=i}static fromMatrix(t,e){return function(t,e){const n=[],i=t.shape,r=i.nrRows(),s=i.nrColumns();if(0===r||0===s)throw new Error("No rows and columns?");{const e=O(t.numbers);for(let t=0;t{if(0===e.names.length)return"";const n=t?` [${e.unit.toText()}]`:"";return e.names.join(",")+n})}columnHeaders(t){return this.columnNames.map(e=>{if(0===e.names.length)return"";const n=t?` [${e.unit.toText()}]`:"";return e.names.join(",")+n})}dom(){return function(t,e,n,i,r,s,a){const o=document.createElement("table");if(o.className=r?"fixed":"",o.part="table",void 0!==a&&(o.style.width=`${a.toString()}px`),i){const t=document.createElement("thead"),e=document.createElement("tr");e.part="header row";const i=document.createElement("th");i.className="key",i.part="header key",i.innerHTML="",e.appendChild(i);for(const t of n){const n=document.createElement("th");n.className="value",n.part="header value",n.innerHTML=t,s&&(n.colSpan=2),e.appendChild(n)}o.appendChild(t),t.appendChild(e)}const l=document.createElement("tbody");o.appendChild(l);for(const[n,r]of t.entries()){const t=document.createElement("tr");if(t.part="body row",i){const i=document.createElement("th");i.className="key",i.part="body key",i.innerHTML=e[n],t.appendChild(i)}for(const e of r){const n=document.createElement("td");if(n.className="value",n.part="body value",n.innerHTML=e.magnitude,t.appendChild(n),s){const n=document.createElement("td");n.className="unit",n.part="body unit",n.appendChild(document.createTextNode(e.unit)),t.appendChild(n)}}l.appendChild(t)}return o}(this.stringifiedCells(),this.rowHeaders(!0===this.options.headerunits),this.columnHeaders(!0===this.options.headerunits),!0===this.options.headers,!0===this.options.evenwidth,!0!==this.options.nounits,this.options.width)}ascii(){return function(t,e,n,i,r,s){const a=t.length,o=0===a?0:t[0].length;if(0===a||0===o)return"";const l=n.map(t=>0),c=n.map(t=>0);for(const e of t)for(const[t,n]of e.entries())l[t]=Math.max(l[t],n.magnitude.length),c[t]=Math.max(c[t],n.unit.length);const u=n.map((t,e)=>{const n=i?t.length:0;return s?Math.max(n,l[e]+c[e]+1):Math.max(n,l[e])});r&&u.fill(u.reduce((t,e)=>Math.max(t,e),0));const h=e.map(t=>t.length).reduce((t,e)=>Math.max(t,e),0);let d="";i&&(d+="".padStart(h),d+=" "+n.map((t,e)=>t.padEnd(u[e])).join(" ")+"\n");for(const[n,r]of t.entries()){const t=[];i&&t.push(e[n].padEnd(h));for(const[e,n]of r.entries()){const i=s?u[e]-c[e]-1:u[e],r=c[e];t.push(n.magnitude.padStart(i)),s&&t.push(n.unit.padEnd(r))}d+=t.join(" ")+"\n"}return d}(this.stringifiedCells(),this.rowHeaders(!0===this.options.headerunits),this.columnHeaders(!0===this.options.headerunits),!0===this.options.headers,!0===this.options.evenwidth,!0!==this.options.nounits)}clipboardText(){return"TODO: clipboardText for MatrixBuilder"}}const Ab=zy(Gy,tb,{strings:["order"],booleans:["headers","headerunits","nounits","evenwidth"],numbers:[]});class Cb extends eb{get headers(){return this.getBooleAttribute("headers")}set headers(t){this.setBooleAttribute("headers",t)}get evenwidth(){return this.getBooleAttribute("evenwidth")}set evenwidth(t){this.setBooleAttribute("evenwidth",t)}get order(){var t;return null!==(t=this.getAttribute("order"))&&void 0!==t?t:void 0}set order(t){this.setStringAttribute("order",t)}get nounits(){return this.getBooleAttribute("nounits")}set nounits(t){this.setBooleAttribute("nounits",t)}get headerunits(){return this.getBooleAttribute("headerunits")}set headerunits(t){this.setBooleAttribute("headerunits",t)}constructor(){super(),this.adoptStyles("\ntable {\n border-spacing: 0;\n border-collapse: collapse;\n}\n\n.fixed {\n table-layout: fixed;\n}\n\ntr {\n height: 24pt;\n}\n\nth.value {\n height: 24pt;\n}\n\ntd, th {\n border-bottom: solid lightgrey;\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n}\n\nth {\n border-width: 1px 1px 1px 1px;\n padding-left: 8pt;\n text-align: left;\n white-space: nowrap;\n font-weight: normal;\n}\n\ntd.key {\n padding-left: 8pt;\n padding-right: 8pt;\n border-width: 1px 1px 1px 1px;\n}\n\ntd.value {\n padding-left: 8pt;\n border-width: 1px 0px 1px 1px;\n text-align: right;\n white-space: nowrap;\n}\n\ntd.unit {\n padding-left: 2pt;\n padding-right: 8pt;\n border-width: 1px 1px 1px 0px;\n text-align: left;\n white-space: nowrap;\n}\n")}attributeChangedCallback(t,e,n){try{void 0!==this.matrix&&("definition"===t&&(this.matrix=this.readDefinition()),this.drawMatrix(this.matrix))}catch(t){this.displayError(t instanceof Error?t.message:String(t))}}parametersChanged(){this.matrix=this.readDefinition(),this.drawMatrix(this.matrix)}readDefinition(){const t=Ay(this);if("matrix"===t.kind)return t;throw e=`Expected a matrix, got ${t.kind}`,new Zt(`Invalid matrix for pacioli-matrix. ${e}`);var e}drawMatrix(t){this.clearContent(),this.clearErrors();const e=Object.assign(Object.assign({},Uy(this,Ab)),Ly(this,Ab));this.contentParent().appendChild(function(t,e){let n=t;if(void 0!==e.order){const[i,r]=function(t){const e=t.split(",");if(2!==e.length)throw new Zt(`Invalid order '${t}'. Expected two integers separated by a comma, for example 2,0`);const n=Number.parseInt(e[0].trim()),i=Number.parseInt(e[1].trim());if(!Number.isInteger(n))throw new Zt(`Invalid row order in '${t}'. Expected an integer`);if(!Number.isInteger(i))throw new Zt(`Invalid column order in '${t}'. Expected an integer`);return[n,i]}(e.order);n=t.reorder(i,r)}const i=Tb.fromMatrix(n,e);if(!0!==e.ascii&&!0!==e.clipboard)return i.dom();const r=document.createElement("pre");return!0===e.ascii?r.innerText=i.ascii():!0===e.clipboard&&(r.innerText=i.clipboardText()),r}(t,e))}}Cb.observedAttributes=Vy(Ab),customElements.define("pacioli-matrix",Cb)})(),Pacioli=__webpack_exports__})();