!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("echarts")):"function"==typeof define&&define.amd?define(["echarts"],t):"object"==typeof exports?exports["echarts-gl"]=t(require("echarts")):e["echarts-gl"]=t(e.echarts)}(self,(function(e){return(()=>{"use strict";var t={468:(e,t,r)=>{r.r(t);var i=r(83);function n(e,t,r){"object"==typeof t&&(r=t,t=null);var i,n=this;if(!(e instanceof function))for(var s in i=[],e)e.hasownproperty(s)&&i.push(s);var l=function(t){if(n.apply(this,arguments),e instanceof function?a(this,e.call(this,t)):o(this,e,i),this.constructor===l)for(var r=l.__initializers__,s=0;s=400?e.onerror&&e.onerror():e.onload&&e.onload(t.response)},e.onerror&&(t.onerror=e.onerror),t.send(null)}};var f,z={supportwebgl:function(){if(null==f)try{var e=document.createelement("canvas");if(!e.getcontext("webgl")&&!e.getcontext("experimental-webgl"))throw new error}catch(e){f=!1}return f}};z.int8array="undefined"==typeof int8array?array:int8array,z.uint8array="undefined"==typeof uint8array?array:uint8array,z.uint16array="undefined"==typeof uint16array?array:uint16array,z.uint32array="undefined"==typeof uint32array?array:uint32array,z.int16array="undefined"==typeof int16array?array:int16array,z.float32array="undefined"==typeof float32array?array:float32array,z.float64array="undefined"==typeof float64array?array:float64array;var g={};"undefined"!=typeof window?g=window:void 0!==r.g&&(g=r.g),z.requestanimationframe=g.requestanimationframe||g.msrequestanimationframe||g.mozrequestanimationframe||g.webkitrequestanimationframe||function(e){settimeout(e,16)},z.createcanvas=function(){return document.createelement("canvas")},z.createimage=function(){return new g.image},z.request={get:b.get},z.addeventlistener=function(e,t,r,i){e.addeventlistener(t,r,i)},z.removeeventlistener=function(e,t,r){e.removeeventlistener(t,r)};const u=z;var k=function(){this.head=null,this.tail=null,this._length=0};k.prototype.insert=function(e){var t=new k.entry(e);return this.insertentry(t),t},k.prototype.insertat=function(e,t){if(!(e<0)){for(var r=this.head,i=0;r&&i!=e;)r=r.next,i++;if(r){var n=new k.entry(t),a=r.prev;a?(a.next=n,n.prev=a):this.head=n,n.next=r,r.prev=n}else this.insert(t)}},k.prototype.insertbeforeentry=function(e,t){var r=new k.entry(e),i=t.prev;i?(i.next=r,r.prev=i):this.head=r,r.next=t,t.prev=r,this._length++},k.prototype.insertentry=function(e){this.head?(this.tail.next=e,e.prev=this.tail,this.tail=e):this.head=this.tail=e,this._length++},k.prototype.remove=function(e){var t=e.prev,r=e.next;t?t.next=r:this.head=r,r?r.prev=t:this.tail=t,e.next=e.prev=null,this._length--},k.prototype.removeat=function(e){if(!(e<0)){for(var t=this.head,r=0;t&&r!=e;)t=t.next,r++;return t?(this.remove(t),t.value):void 0}},k.prototype.gethead=function(){if(this.head)return this.head.value},k.prototype.gettail=function(){if(this.tail)return this.tail.value},k.prototype.getat=function(e){if(!(e<0)){for(var t=this.head,r=0;t&&r!=e;)t=t.next,r++;return t.value}},k.prototype.indexof=function(e){for(var t=this.head,r=0;t;){if(t.value===e)return r;t=t.next,r++}},k.prototype.length=function(){return this._length},k.prototype.isempty=function(){return 0===this._length},k.prototype.foreach=function(e,t){for(var r=this.head,i=0,n=void 0!==t;r;)n?e.call(t,r.value,i):e(r.value,i),r=r.next,i++},k.prototype.clear=function(){this.tail=this.head=null,this._length=0},k.entry=function(e){this.value=e,this.next=null,this.prev=null};const v=k;var h=function(e){this._list=new v,this._map={},this._maxsize=e||10};h.prototype.setmaxsize=function(e){this._maxsize=e},h.prototype.put=function(e,t){if(!this._map.hasownproperty(e)){var r=this._list.length();if(r>=this._maxsize&&r>0){var i=this._list.head;this._list.remove(i),delete this._map[i.key]}var n=this._list.insert(t);n.key=e,this._map[e]=n}},h.prototype.get=function(e){var t=this._map[e];if(this._map.hasownproperty(e))return t!==this._list.tail&&(this._list.remove(t),this._list.insertentry(t)),t.value},h.prototype.remove=function(e){var t=this._map[e];void 0!==t&&(delete this._map[e],this._list.remove(t))},h.prototype.clear=function(){this._list.clear(),this._map={}};const w=h;var j={},x={transparent:[0,0,0,0],aliceblue:[240,248,255,1],antiquewhite:[250,235,215,1],aqua:[0,255,255,1],aquamarine:[127,255,212,1],azure:[240,255,255,1],beige:[245,245,220,1],bisque:[255,228,196,1],black:[0,0,0,1],blanchedalmond:[255,235,205,1],blue:[0,0,255,1],blueviolet:[138,43,226,1],brown:[165,42,42,1],burlywood:[222,184,135,1],cadetblue:[95,158,160,1],chartreuse:[127,255,0,1],chocolate:[210,105,30,1],coral:[255,127,80,1],cornflowerblue:[100,149,237,1],cornsilk:[255,248,220,1],crimson:[220,20,60,1],cyan:[0,255,255,1],darkblue:[0,0,139,1],darkcyan:[0,139,139,1],darkgoldenrod:[184,134,11,1],darkgray:[169,169,169,1],darkgreen:[0,100,0,1],darkgrey:[169,169,169,1],darkkhaki:[189,183,107,1],darkmagenta:[139,0,139,1],darkolivegreen:[85,107,47,1],darkorange:[255,140,0,1],darkorchid:[153,50,204,1],darkred:[139,0,0,1],darksalmon:[233,150,122,1],darkseagreen:[143,188,143,1],darkslateblue:[72,61,139,1],darkslategray:[47,79,79,1],darkslategrey:[47,79,79,1],darkturquoise:[0,206,209,1],darkviolet:[148,0,211,1],deeppink:[255,20,147,1],deepskyblue:[0,191,255,1],dimgray:[105,105,105,1],dimgrey:[105,105,105,1],dodgerblue:[30,144,255,1],firebrick:[178,34,34,1],floralwhite:[255,250,240,1],forestgreen:[34,139,34,1],fuchsia:[255,0,255,1],gainsboro:[220,220,220,1],ghostwhite:[248,248,255,1],gold:[255,215,0,1],goldenrod:[218,165,32,1],gray:[128,128,128,1],green:[0,128,0,1],greenyellow:[173,255,47,1],grey:[128,128,128,1],honeydew:[240,255,240,1],hotpink:[255,105,180,1],indianred:[205,92,92,1],indigo:[75,0,130,1],ivory:[255,255,240,1],khaki:[240,230,140,1],lavender:[230,230,250,1],lavenderblush:[255,240,245,1],lawngreen:[124,252,0,1],lemonchiffon:[255,250,205,1],lightblue:[173,216,230,1],lightcoral:[240,128,128,1],lightcyan:[224,255,255,1],lightgoldenrodyellow:[250,250,210,1],lightgray:[211,211,211,1],lightgreen:[144,238,144,1],lightgrey:[211,211,211,1],lightpink:[255,182,193,1],lightsalmon:[255,160,122,1],lightseagreen:[32,178,170,1],lightskyblue:[135,206,250,1],lightslategray:[119,136,153,1],lightslategrey:[119,136,153,1],lightsteelblue:[176,196,222,1],lightyellow:[255,255,224,1],lime:[0,255,0,1],limegreen:[50,205,50,1],linen:[250,240,230,1],magenta:[255,0,255,1],maroon:[128,0,0,1],mediumaquamarine:[102,205,170,1],mediumblue:[0,0,205,1],mediumorchid:[186,85,211,1],mediumpurple:[147,112,219,1],mediumseagreen:[60,179,113,1],mediumslateblue:[123,104,238,1],mediumspringgreen:[0,250,154,1],mediumturquoise:[72,209,204,1],mediumvioletred:[199,21,133,1],midnightblue:[25,25,112,1],mintcream:[245,255,250,1],mistyrose:[255,228,225,1],moccasin:[255,228,181,1],navajowhite:[255,222,173,1],navy:[0,0,128,1],oldlace:[253,245,230,1],olive:[128,128,0,1],olivedrab:[107,142,35,1],orange:[255,165,0,1],orangered:[255,69,0,1],orchid:[218,112,214,1],palegoldenrod:[238,232,170,1],palegreen:[152,251,152,1],paleturquoise:[175,238,238,1],palevioletred:[219,112,147,1],papayawhip:[255,239,213,1],peachpuff:[255,218,185,1],peru:[205,133,63,1],pink:[255,192,203,1],plum:[221,160,221,1],powderblue:[176,224,230,1],purple:[128,0,128,1],red:[255,0,0,1],rosybrown:[188,143,143,1],royalblue:[65,105,225,1],saddlebrown:[139,69,19,1],salmon:[250,128,114,1],sandybrown:[244,164,96,1],seagreen:[46,139,87,1],seashell:[255,245,238,1],sienna:[160,82,45,1],silver:[192,192,192,1],skyblue:[135,206,235,1],slateblue:[106,90,205,1],slategray:[112,128,144,1],slategrey:[112,128,144,1],snow:[255,250,250,1],springgreen:[0,255,127,1],steelblue:[70,130,180,1],tan:[210,180,140,1],teal:[0,128,128,1],thistle:[216,191,216,1],tomato:[255,99,71,1],turquoise:[64,224,208,1],violet:[238,130,238,1],wheat:[245,222,179,1],white:[255,255,255,1],whitesmoke:[245,245,245,1],yellow:[255,255,0,1],yellowgreen:[154,205,50,1]};function q(e){return(e=math.round(e))<0?0:e>255?255:e}function z(e){return e<0?0:e>1?1:e}function y(e){return e.length&&"%"===e.charat(e.length-1)?q(parsefloat(e)/100*255):q(parseint(e,10))}function k(e){return e.length&&"%"===e.charat(e.length-1)?z(parsefloat(e)/100):z(parsefloat(e))}function q(e,t,r){return r<0?r+=1:r>1&&(r-=1),6*r<1?e+(t-e)*r*6:2*r<1?t:3*r<2?e+(t-e)*(2/3-r)*6:e}function j(e,t,r){return e+(t-e)*r}function $(e,t,r,i,n){return e[0]=t,e[1]=r,e[2]=i,e[3]=n,e}function ee(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}var te=new w(20),re=null;function ie(e,t){re&&ee(re,t),re=te.put(e,re||t.slice())}function ne(e,t){var r=(parsefloat(e[0])%360+360)%360/360,i=k(e[1]),n=k(e[2]),a=n<=.5?n*(i+1):n+i-n*i,o=2*n-a;return $(t=t||[],q(255*q(o,a,r+1/3)),q(255*q(o,a,r)),q(255*q(o,a,r-1/3)),1),4===e.length&&(t[3]=e[3]),t}j.parse=function(e,t){if(e){t=t||[];var r=te.get(e);if(r)return ee(t,r);var i,n=(e+="").replace(/ /g,"").tolowercase();if(n in x)return ee(t,x[n]),ie(e,t),t;if("#"===n.charat(0))return 4===n.length?(i=parseint(n.substr(1),16))>=0&&i<=4095?($(t,(3840&i)>>4|(3840&i)>>8,240&i|(240&i)>>4,15&i|(15&i)<<4,1),ie(e,t),t):void $(t,0,0,0,1):7===n.length?(i=parseint(n.substr(1),16))>=0&&i<=16777215?($(t,(16711680&i)>>16,(65280&i)>>8,255&i,1),ie(e,t),t):void $(t,0,0,0,1):void 0;var a=n.indexof("("),o=n.indexof(")");if(-1!==a&&o+1===n.length){var s=n.substr(0,a),l=n.substr(a+1,o-(a+1)).split(","),h=1;switch(s){case"rgba":if(4!==l.length)return void $(t,0,0,0,1);h=k(l.pop());case"rgb":return 3!==l.length?void $(t,0,0,0,1):($(t,y(l[0]),y(l[1]),y(l[2]),h),ie(e,t),t);case"hsla":return 4!==l.length?void $(t,0,0,0,1):(l[3]=k(l[3]),ne(l,t),ie(e,t),t);case"hsl":return 3!==l.length?void $(t,0,0,0,1):(ne(l,t),ie(e,t),t);default:return}}$(t,0,0,0,1)}},j.parsetofloat=function(e,t){if(t=j.parse(e,t))return t[0]/=255,t[1]/=255,t[2]/=255,t},j.lift=function(e,t){var r=j.parse(e);if(r){for(var i=0;i<3;i++)r[i]=t<0?r[i]*(1-t)|0:(255-r[i])*t+r[i]|0;return j.stringify(r,4===r.length?"rgba":"rgb")}},j.tohex=function(e){var t=j.parse(e);if(t)return((1<<24)+(t[0]<<16)+(t[1]<<8)+ +t[2]).tostring(16).slice(1)},j.fastlerp=function(e,t,r){if(t&&t.length&&e>=0&&e<=1){r=r||[];var i=e*(t.length-1),n=math.floor(i),a=math.ceil(i),o=t[n],s=t[a],l=i-n;return r[0]=q(j(o[0],s[0],l)),r[1]=q(j(o[1],s[1],l)),r[2]=q(j(o[2],s[2],l)),r[3]=z(j(o[3],s[3],l)),r}},j.fastmaptocolor=j.fastlerp,j.lerp=function(e,t,r){if(t&&t.length&&e>=0&&e<=1){var i=e*(t.length-1),n=math.floor(i),a=math.ceil(i),o=j.parse(t[n]),s=j.parse(t[a]),l=i-n,h=j.stringify([q(j(o[0],s[0],l)),q(j(o[1],s[1],l)),q(j(o[2],s[2],l)),z(j(o[3],s[3],l))],"rgba");return r?{color:h,leftindex:n,rightindex:a,value:i}:h}},j.maptocolor=j.lerp,j.modifyhsl=function(e,t,r,i){if(e=j.parse(e))return e=function(e){if(e){var t,r,i=e[0]/255,n=e[1]/255,a=e[2]/255,o=math.min(i,n,a),s=math.max(i,n,a),l=s-o,h=(s+o)/2;if(0===l)t=0,r=0;else{r=h<.5?l/(s+o):l/(2-s-o);var u=((s-i)/6+l/2)/l,c=((s-n)/6+l/2)/l,d=((s-a)/6+l/2)/l;i===s?t=d-c:n===s?t=1/3+u-d:a===s&&(t=2/3+c-u),t<0&&(t+=1),t>1&&(t-=1)}var f=[360*t,r,h];return null!=e[3]&&f.push(e[3]),f}}(e),null!=t&&(e[0]=(n=t,(n=math.round(n))<0?0:n>360?360:n)),null!=r&&(e[1]=k(r)),null!=i&&(e[2]=k(i)),j.stringify(ne(e),"rgba");var n},j.modifyalpha=function(e,t){if((e=j.parse(e))&&null!=t)return e[3]=z(t),j.stringify(e,"rgba")},j.stringify=function(e,t){if(e&&e.length){var r=e[0]+","+e[1]+","+e[2];return"rgba"!==t&&"hsva"!==t&&"hsla"!==t||(r+=","+e[3]),t+"("+r+")"}};var ae=j.parsetofloat,oe={};function se(e){var t=object.keys(e);t.sort();for(var r=[],i=0;i=0},getenableduniforms:function(){return this._enableduniforms},gettextureuniforms:function(){return this._textureuniforms},set:function(e,t){if("object"==typeof e)for(var r in e){var i=e[r];this.setuniform(r,i)}else this.setuniform(e,t)},get:function(e){var t=this.uniforms[e];if(t)return t.value},attachshader:function(e,t){var r=this.uniforms;this.uniforms=e.createuniforms(),this.shader=e;var i=this.uniforms;this._enableduniforms=object.keys(i),this._enableduniforms.sort(),this._textureuniforms=this._enableduniforms.filter((function(e){var t=this.uniforms[e].type;return"t"===t||"tv"===t}),this);var n=this.vertexdefines,a=this.fragmentdefines;if(this.vertexdefines=f.clone(e.vertexdefines),this.fragmentdefines=f.clone(e.fragmentdefines),t){for(var o in r)i[o]&&(i[o].value=r[o].value);f.defaults(this.vertexdefines,n),f.defaults(this.fragmentdefines,a)}var s={};for(var l in e.textures)s[l]={shadertype:e.textures[l].shadertype,type:e.textures[l].type,enabled:!(!t||!this._texturestatus[l])&&this._texturestatus[l].enabled};this._texturestatus=s,this._programkey=""},clone:function(){var e=new this.constructor({name:this.name,shader:this.shader});for(var t in this.uniforms)e.uniforms[t].value=this.uniforms[t].value;return e.depthtest=this.depthtest,e.depthmask=this.depthmask,e.transparent=this.transparent,e.blend=this.blend,e.vertexdefines=f.clone(this.vertexdefines),e.fragmentdefines=f.clone(this.fragmentdefines),e.enabletexture(this.getenabledtextures()),e.precision=this.precision,e},define:function(e,t,r){var i=this.vertexdefines,n=this.fragmentdefines;"vertex"!==e&&"fragment"!==e&&"both"!==e&&arguments.length<3&&(r=t,t=e,e="both"),r=null!=r?r:null,"vertex"!==e&&"both"!==e||i[t]!==r&&(i[t]=r,this._programkey=""),"fragment"!==e&&"both"!==e||n[t]!==r&&(n[t]=r,"both"!==e&&(this._programkey=""))},undefine:function(e,t){"vertex"!==e&&"fragment"!==e&&"both"!==e&&arguments.length<2&&(t=e,e="both"),"vertex"!==e&&"both"!==e||this.isdefined("vertex",t)&&(delete this.vertexdefines[t],this._programkey=""),"fragment"!==e&&"both"!==e||this.isdefined("fragment",t)&&(delete this.fragmentdefines[t],"both"!==e&&(this._programkey=""))},isdefined:function(e,t){switch(e){case"vertex":return void 0!==this.vertexdefines[t];case"fragment":return void 0!==this.fragmentdefines[t]}},getdefine:function(e,t){switch(e){case"vertex":return this.vertexdefines[t];case"fragment":return this.fragmentdefines[t]}},enabletexture:function(e){if(array.isarray(e))for(var t=0;t0&&(n=1/math.sqrt(n),e[0]=t[0]*n,e[1]=t[1]*n),e},fe.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]},fe.cross=function(e,t,r){var i=t[0]*r[1]-t[1]*r[0];return e[0]=e[1]=0,e[2]=i,e},fe.lerp=function(e,t,r,i){var n=t[0],a=t[1];return e[0]=n+i*(r[0]-n),e[1]=a+i*(r[1]-a),e},fe.random=function(e,t){t=t||1;var r=2*glmat_random()*math.pi;return e[0]=math.cos(r)*t,e[1]=math.sin(r)*t,e},fe.transformmat2=function(e,t,r){var i=t[0],n=t[1];return e[0]=r[0]*i+r[2]*n,e[1]=r[1]*i+r[3]*n,e},fe.transformmat2d=function(e,t,r){var i=t[0],n=t[1];return e[0]=r[0]*i+r[2]*n+r[4],e[1]=r[1]*i+r[3]*n+r[5],e},fe.transformmat3=function(e,t,r){var i=t[0],n=t[1];return e[0]=r[0]*i+r[3]*n+r[6],e[1]=r[1]*i+r[4]*n+r[7],e},fe.transformmat4=function(e,t,r){var i=t[0],n=t[1];return e[0]=r[0]*i+r[4]*n+r[12],e[1]=r[1]*i+r[5]*n+r[13],e},fe.foreach=(he=fe.create(),function(e,t,r,i,n,a){var o,s;for(t||(t=2),r||(r=0),s=i?math.min(i*t+r,e.length):e.length,o=r;o0&&i.push("#define "+n.touppercase()+"_count "+a)}if(r)for(var o=0;ol.getmaxjointnumber()&&(d.use_skin_matrices_texture=null),c+="\n"+me(d)+"\n"}a&&(c+="\n#define instancing\n");var f=c+me(t.vertexdefines,s,u),p=c+me(t.fragmentdefines,s,u),m=f+"\n"+t.shader.vertex,g=["oes_standard_derivatives","ext_shader_texture_lod"].filter((function(e){return null!=l.getglextension(e)}));g.indexof("ext_shader_texture_lod")>=0&&(p+="\n#define support_texture_lod"),g.indexof("oes_standard_derivatives")>=0&&(p+="\n#define support_standard_derivatives");var _,v,y=function(e){for(var t=[],r=0;r=0){if(1!==s&&4!==s){ke();break}s=2,h=[]}else if(1!==s)if(4!==s)u(c),s=0;else{var d=c;ie.indexof(d)>=0||re.indexof(d)>=0||be.indexof(d)>=0?l[o].semantic=d:"ignore"===d||"unconfigurable"===d?l[o].ignore=!0:l[o].value="bool"===e?"true"===d:parsefloat(d)}else l[o].value="bool"===e?"true"===c:parsefloat(c),h=null;else{if(2!==s){ke();break}if(!(h instanceof array)){ke();break}h.push(+i[++a])}else l[o].value=new u.float32array(h),h=null,s=5;else if(2===s){if(!(h instanceof array)){ke();break}h.push(+i[++a])}else s=5;else s=4;else{if(0!==s&&3!==s){ke();break}s=1}}return l}function he(e,t){"object"==typeof e&&(t=e.fragment,e=e.vertex),e=ue(e),t=ue(t),this._shaderid=function(e,t){var r="vertex:"+e+"fragment:"+t;if(ze[r])return ze[r];var i=f.genguid();return ze[r]=i,ge[i]={vertex:e,fragment:t},i}(e,t),this._vertexcode=he.parseimport(e),this._fragmentcode=he.parseimport(t),this.attributesemantics={},this.matrixsemantics={},this.uniformsemantics={},this.matrixsemantickeys=[],this.uniformtemplates={},this.attributes={},this.textures={},this.vertexdefines={},this.fragmentdefines={},this._parseattributes(),this._parseuniforms(),this._parsedefines()}he.prototype={constructor:he,createuniforms:function(){var e={};for(var t in this.uniformtemplates){var r=this.uniformtemplates[t];e[t]={type:r.type,value:r.value()}}return e},_parseimport:function(){this._vertexcode=he.parseimport(this.vertex),this._fragmentcode=he.parseimport(this.fragment)},_addsemanticuniform:function(e,t,r){if(ie.indexof(r)>=0)this.attributesemantics[r]={symbol:e,type:t};else if(be.indexof(r)>=0){var i=!1,n=r;r.match(/transpose$/)&&(i=!0,n=r.slice(0,-9)),this.matrixsemantics[r]={symbol:e,type:t,istranspose:i,semanticnotranspose:n}}else re.indexof(r)>=0&&(this.uniformsemantics[r]={symbol:e,type:t})},_addmaterialuniform:function(e,t,r,i,n,a){a[e]={type:r,value:n?ne.array:i||ne[t],semantic:null}},_parseuniforms:function(){var e={},t=this;function r(e){return null!=e?function(){return e}:null}function i(i,n,a){var o=ve(n,a),s=[];for(var l in o){var h=o[l],u=h.semantic,c=l,d=pe[n],f=r(o[l].value);o[l].isarray&&(c+="["+o[l].arraysize+"]",d+="v"),s.push(c),t._uniformlist.push(l),h.ignore||("sampler2d"!==n&&"samplercube"!==n||(t.textures[l]={shadertype:"fragment",type:n}),u?t._addsemanticuniform(l,d,u):t._addmaterialuniform(l,n,d,f,o[l].isarray,e))}return s.length>0?"uniform "+n+" "+s.join(",")+";\n":""}this._uniformlist=[],this._vertexcode=this._vertexcode.replace(ce,i),this._fragmentcode=this._fragmentcode.replace(ce,i),t.matrixsemantickeys=object.keys(this.matrixsemantics),this.uniformtemplates=e},_parseattributes:function(){var e={},t=this;this._vertexcode=this._vertexcode.replace(de,(function(r,i,n){var a=ve(i,n),o=fe[i]||1,s=[];for(var l in a){var h=a[l].semantic;if(e[l]={type:"float",size:o,semantic:h||null},h){if(ie.indexof(h)<0)throw new error('unkown semantic "'+h+'"');t.attributesemantics[h]={symbol:l,type:i}}s.push(l)}return"attribute "+i+" "+s.join(",")+";\n"})),this.attributes=e},_parsedefines:function(){var e=this;function t(t,r,i){var n=e.fragmentdefines;return n[r]||(n[r]="false"!==i&&("true"===i||(i?isnan(parsefloat(i))?i.trim():parsefloat(i):null))),""}this._vertexcode=this._vertexcode.replace(le,t),this._fragmentcode=this._fragmentcode.replace(le,t)},clone:function(){var e=ge[this._shaderid];return new he(e.vertex,e.fragment)}},object.defineproperty&&(object.defineproperty(he.prototype,"shaderid",{get:function(){return this._shaderid}}),object.defineproperty(he.prototype,"vertex",{get:function(){return this._vertexcode}}),object.defineproperty(he.prototype,"fragment",{get:function(){return this._fragmentcode}}),object.defineproperty(he.prototype,"uniforms",{get:function(){return this._uniformlist}}));var we=/(@import)\s*([0-9a-za-z_\-\.]*)/g;he.parseimport=function(e){return e.replace(we,(function(e,t,r){return(e=he.source(r))?he.parseimport(e):(console.error('shader chunk "'+r+'" not existed in library'),"")}))};var je=/(@export)\s*([0-9a-za-z_\-\.]*)\s*\n([\s\s]*?)@end/g;he.import=function(e){e.replace(je,(function(e,t,r,i){if(i=i.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+\x24)/g,"")){for(var n,a=r.split("."),o=he.codes,s=0;s 0.0) {\n if (texture2d(alphamap, v_texcoord).a <= alphacutoff) {\n discard;\n }\n }\n gl_fragcolor = vec4(0.0,0.0,0.0,1.0);\n}\n@end";var ze={create:function(){var e=new ce(16);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},clone:function(e){var t=new ce(16);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t},copy:function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},identity:function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e},transpose:function(e,t){if(e===t){var r=t[1],i=t[2],n=t[3],a=t[6],o=t[7],s=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=r,e[6]=t[9],e[7]=t[13],e[8]=i,e[9]=a,e[11]=t[14],e[12]=n,e[13]=o,e[14]=s}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e},invert:function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],o=t[4],s=t[5],l=t[6],h=t[7],u=t[8],c=t[9],d=t[10],f=t[11],p=t[12],m=t[13],g=t[14],_=t[15],v=r*s-i*o,y=r*l-n*o,x=r*h-a*o,b=i*l-n*s,w=i*h-a*s,t=n*h-a*l,s=u*m-c*p,m=u*g-d*p,a=u*_-f*p,e=c*g-d*m,c=c*_-f*m,d=d*_-f*g,l=v*d-y*c+x*e+b*a-w*m+t*s;return l?(l=1/l,e[0]=(s*d-l*c+h*e)*l,e[1]=(n*c-i*d-a*e)*l,e[2]=(m*t-g*w+_*b)*l,e[3]=(d*w-c*t-f*b)*l,e[4]=(l*a-o*d-h*m)*l,e[5]=(r*d-n*a+a*m)*l,e[6]=(g*x-p*t-_*y)*l,e[7]=(u*t-d*x+f*y)*l,e[8]=(o*c-s*a+h*s)*l,e[9]=(i*a-r*c-a*s)*l,e[10]=(p*w-m*x+_*v)*l,e[11]=(c*x-u*w-f*v)*l,e[12]=(s*m-o*e-l*s)*l,e[13]=(r*e-i*m+n*s)*l,e[14]=(m*y-p*b-g*v)*l,e[15]=(u*b-c*y+d*v)*l,e):null},adjoint:function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],o=t[4],s=t[5],l=t[6],h=t[7],u=t[8],c=t[9],d=t[10],f=t[11],p=t[12],m=t[13],g=t[14],_=t[15];return e[0]=s*(d*_-f*g)-c*(l*_-h*g)+m*(l*f-h*d),e[1]=-(i*(d*_-f*g)-c*(n*_-a*g)+m*(n*f-a*d)),e[2]=i*(l*_-h*g)-s*(n*_-a*g)+m*(n*h-a*l),e[3]=-(i*(l*f-h*d)-s*(n*f-a*d)+c*(n*h-a*l)),e[4]=-(o*(d*_-f*g)-u*(l*_-h*g)+p*(l*f-h*d)),e[5]=r*(d*_-f*g)-u*(n*_-a*g)+p*(n*f-a*d),e[6]=-(r*(l*_-h*g)-o*(n*_-a*g)+p*(n*h-a*l)),e[7]=r*(l*f-h*d)-o*(n*f-a*d)+u*(n*h-a*l),e[8]=o*(c*_-f*m)-u*(s*_-h*m)+p*(s*f-h*c),e[9]=-(r*(c*_-f*m)-u*(i*_-a*m)+p*(i*f-a*c)),e[10]=r*(s*_-h*m)-o*(i*_-a*m)+p*(i*h-a*s),e[11]=-(r*(s*f-h*c)-o*(i*f-a*c)+u*(i*h-a*s)),e[12]=-(o*(c*g-d*m)-u*(s*g-l*m)+p*(s*d-l*c)),e[13]=r*(c*g-d*m)-u*(i*g-n*m)+p*(i*d-n*c),e[14]=-(r*(s*g-l*m)-o*(i*g-n*m)+p*(i*l-n*s)),e[15]=r*(s*d-l*c)-o*(i*d-n*c)+u*(i*l-n*s),e},determinant:function(e){var t=e[0],r=e[1],i=e[2],n=e[3],a=e[4],o=e[5],s=e[6],l=e[7],h=e[8],u=e[9],c=e[10],d=e[11],f=e[12],p=e[13],m=e[14],g=e[15];return(t*o-r*a)*(c*g-d*m)-(t*s-i*a)*(u*g-d*p)+(t*l-n*a)*(u*m-c*p)+(r*s-i*o)*(h*g-d*f)-(r*l-n*o)*(h*m-c*f)+(i*l-n*s)*(h*p-u*f)},multiply:function(e,t,r){var i=t[0],n=t[1],a=t[2],o=t[3],s=t[4],l=t[5],h=t[6],u=t[7],c=t[8],d=t[9],f=t[10],p=t[11],m=t[12],g=t[13],_=t[14],v=t[15],y=r[0],x=r[1],b=r[2],w=r[3];return e[0]=y*i+x*s+b*c+w*m,e[1]=y*n+x*l+b*d+w*g,e[2]=y*a+x*h+b*f+w*_,e[3]=y*o+x*u+b*p+w*v,y=r[4],x=r[5],b=r[6],w=r[7],e[4]=y*i+x*s+b*c+w*m,e[5]=y*n+x*l+b*d+w*g,e[6]=y*a+x*h+b*f+w*_,e[7]=y*o+x*u+b*p+w*v,y=r[8],x=r[9],b=r[10],w=r[11],e[8]=y*i+x*s+b*c+w*m,e[9]=y*n+x*l+b*d+w*g,e[10]=y*a+x*h+b*f+w*_,e[11]=y*o+x*u+b*p+w*v,y=r[12],x=r[13],b=r[14],w=r[15],e[12]=y*i+x*s+b*c+w*m,e[13]=y*n+x*l+b*d+w*g,e[14]=y*a+x*h+b*f+w*_,e[15]=y*o+x*u+b*p+w*v,e},multiplyaffine:function(e,t,r){var i=t[0],n=t[1],a=t[2],o=t[4],s=t[5],l=t[6],h=t[8],u=t[9],c=t[10],d=t[12],f=t[13],p=t[14],m=r[0],g=r[1],_=r[2];return e[0]=m*i+g*o+_*h,e[1]=m*n+g*s+_*u,e[2]=m*a+g*l+_*c,m=r[4],g=r[5],_=r[6],e[4]=m*i+g*o+_*h,e[5]=m*n+g*s+_*u,e[6]=m*a+g*l+_*c,m=r[8],g=r[9],_=r[10],e[8]=m*i+g*o+_*h,e[9]=m*n+g*s+_*u,e[10]=m*a+g*l+_*c,m=r[12],g=r[13],_=r[14],e[12]=m*i+g*o+_*h+d,e[13]=m*n+g*s+_*u+f,e[14]=m*a+g*l+_*c+p,e}};ze.mul=ze.multiply,ze.mulaffine=ze.multiplyaffine,ze.translate=function(e,t,r){var i,n,a,o,s,l,h,u,c,d,f,p,m=r[0],g=r[1],_=r[2];return t===e?(e[12]=t[0]*m+t[4]*g+t[8]*_+t[12],e[13]=t[1]*m+t[5]*g+t[9]*_+t[13],e[14]=t[2]*m+t[6]*g+t[10]*_+t[14],e[15]=t[3]*m+t[7]*g+t[11]*_+t[15]):(i=t[0],n=t[1],a=t[2],o=t[3],s=t[4],l=t[5],h=t[6],u=t[7],c=t[8],d=t[9],f=t[10],p=t[11],e[0]=i,e[1]=n,e[2]=a,e[3]=o,e[4]=s,e[5]=l,e[6]=h,e[7]=u,e[8]=c,e[9]=d,e[10]=f,e[11]=p,e[12]=i*m+s*g+c*_+t[12],e[13]=n*m+l*g+d*_+t[13],e[14]=a*m+h*g+f*_+t[14],e[15]=o*m+u*g+p*_+t[15]),e},ze.scale=function(e,t,r){var i=r[0],n=r[1],a=r[2];return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[3]=t[3]*i,e[4]=t[4]*n,e[5]=t[5]*n,e[6]=t[6]*n,e[7]=t[7]*n,e[8]=t[8]*a,e[9]=t[9]*a,e[10]=t[10]*a,e[11]=t[11]*a,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e},ze.rotate=function(e,t,r,i){var n,a,o,s,l,h,u,c,d,f,p,m,g,_,v,y,x,b,w,t,s,m,a,e,c=i[0],d=i[1],l=i[2],p=math.sqrt(c*c+d*d+l*l);return math.abs(p)0&&(a=1/math.sqrt(a),e[0]=t[0]*a,e[1]=t[1]*a,e[2]=t[2]*a),e},ke.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]},ke.cross=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=r[0],s=r[1],l=r[2];return e[0]=n*l-a*s,e[1]=a*o-i*l,e[2]=i*s-n*o,e},ke.lerp=function(e,t,r,i){var n=t[0],a=t[1],o=t[2];return e[0]=n+i*(r[0]-n),e[1]=a+i*(r[1]-a),e[2]=o+i*(r[2]-o),e},ke.random=function(e,t){t=t||1;var r=2*de()*math.pi,i=2*de()-1,n=math.sqrt(1-i*i)*t;return e[0]=math.cos(r)*n,e[1]=math.sin(r)*n,e[2]=i*t,e},ke.transformmat4=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=r[3]*i+r[7]*n+r[11]*a+r[15];return o=o||1,e[0]=(r[0]*i+r[4]*n+r[8]*a+r[12])/o,e[1]=(r[1]*i+r[5]*n+r[9]*a+r[13])/o,e[2]=(r[2]*i+r[6]*n+r[10]*a+r[14])/o,e},ke.transformmat3=function(e,t,r){var i=t[0],n=t[1],a=t[2];return e[0]=i*r[0]+n*r[3]+a*r[6],e[1]=i*r[1]+n*r[4]+a*r[7],e[2]=i*r[2]+n*r[5]+a*r[8],e},ke.transformquat=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=r[0],s=r[1],l=r[2],h=r[3],u=h*i+s*a-l*n,c=h*n+l*i-o*a,d=h*a+o*n-s*i,f=-o*i-s*n-l*a;return e[0]=u*h+f*-o+c*-l-d*-s,e[1]=c*h+f*-s+d*-o-u*-l,e[2]=d*h+f*-l+u*-s-c*-o,e},ke.rotatex=function(e,t,r,i){var n=[],a=[];return n[0]=t[0]-r[0],n[1]=t[1]-r[1],n[2]=t[2]-r[2],a[0]=n[0],a[1]=n[1]*math.cos(i)-n[2]*math.sin(i),a[2]=n[1]*math.sin(i)+n[2]*math.cos(i),e[0]=a[0]+r[0],e[1]=a[1]+r[1],e[2]=a[2]+r[2],e},ke.rotatey=function(e,t,r,i){var n=[],a=[];return n[0]=t[0]-r[0],n[1]=t[1]-r[1],n[2]=t[2]-r[2],a[0]=n[2]*math.sin(i)+n[0]*math.cos(i),a[1]=n[1],a[2]=n[2]*math.cos(i)-n[0]*math.sin(i),e[0]=a[0]+r[0],e[1]=a[1]+r[1],e[2]=a[2]+r[2],e},ke.rotatez=function(e,t,r,i){var n=[],a=[];return n[0]=t[0]-r[0],n[1]=t[1]-r[1],n[2]=t[2]-r[2],a[0]=n[0]*math.cos(i)-n[1]*math.sin(i),a[1]=n[0]*math.sin(i)+n[1]*math.cos(i),a[2]=n[2],e[0]=a[0]+r[0],e[1]=a[1]+r[1],e[2]=a[2]+r[2],e},ke.foreach=function(){var e=ke.create();return function(t,r,i,n,a,o){var s,l;for(r||(r=3),i||(i=0),l=n?math.min(n*r+i,t.length):t.length,s=i;s1?0:math.acos(n)};const qe=ke;xe.import(qe);var je=ye.create,$e={};function et(e){return e.material}function tt(e,t,r){return t.uniforms[r].value}function rt(e,t,r,i){return r!==i}function it(e){return!0}function nt(){}var at={float:s,byte:5120,ubyte:t,short:5122,ushort:5123};function ot(e,t,r){this.availableattributes=e,this.availableattributesymbols=t,this.indicesbuffer=r,this.vao=null}function st(e){var t,r;this.bind=function(e){t||((t=u.createcanvas()).width=t.height=1,t.getcontext("2d"));var i=e.gl,n=!r;n&&(r=i.createtexture()),i.bindtexture(i.texture_2d,r),n&&i.teximage2d(i.texture_2d,0,i.rgba,i.rgba,i.unsigned_byte,t)},this.unbind=function(e){e.gl.bindtexture(e.gl.texture_2d,null)},this.isrenderable=function(){return!0}}var lt=m.extend((function(){return{canvas:null,_width:100,_height:100,devicepixelratio:"undefined"!=typeof window&&window.devicepixelratio||1,clearcolor:[0,0,0,0],clearbit:17664,alpha:!0,depth:!0,stencil:!1,antialias:!0,premultipliedalpha:!0,preservedrawingbuffer:!1,throwerror:!0,gl:null,viewport:{},maxjointnumber:20,__currentframebuffer:null,_viewportstack:[],_clearstack:[],_scenerendering:null}}),(function(){this.canvas||(this.canvas=u.createcanvas());var e=this.canvas;try{var t={alpha:this.alpha,depth:this.depth,stencil:this.stencil,antialias:this.antialias,premultipliedalpha:this.premultipliedalpha,preservedrawingbuffer:this.preservedrawingbuffer};if(this.gl=e.getcontext("webgl",t)||e.getcontext("experimental-webgl",t),!this.gl)throw new error;this._glinfo=new v(this.gl),this.gl.targetrenderer&&console.error("already created a renderer"),this.gl.targetrenderer=this,this.resize()}catch(e){throw"error creating webgl context "+e}this._programmgr=new ee(this),this._placeholdertexture=new st(this)}),{resize:function(e,t){var r=this.canvas,i=this.devicepixelratio;null!=e?(r.style&&(r.style.width=e+"px",r.style.height=t+"px"),r.width=e*i,r.height=t*i,this._width=e,this._height=t):(this._width=r.width/i,this._height=r.height/i),this.setviewport(0,0,this._width,this._height)},getwidth:function(){return this._width},getheight:function(){return this._height},getviewportaspect:function(){var e=this.viewport;return e.width/e.height},setdevicepixelratio:function(e){this.devicepixelratio=e,this.resize(this._width,this._height)},getdevicepixelratio:function(){return this.devicepixelratio},getglextension:function(e){return this._glinfo.getextension(e)},getglparameter:function(e){return this._glinfo.getparameter(e)},setviewport:function(e,t,r,i,n){if("object"==typeof e){var a=e;e=a.x,t=a.y,r=a.width,i=a.height,n=a.devicepixelratio}n=n||this.devicepixelratio,this.gl.viewport(e*n,t*n,r*n,i*n),this.viewport={x:e,y:t,width:r,height:i,devicepixelratio:n}},saveviewport:function(){this._viewportstack.push(this.viewport)},restoreviewport:function(){this._viewportstack.length>0&&this.setviewport(this._viewportstack.pop())},saveclear:function(){this._clearstack.push({clearbit:this.clearbit,clearcolor:this.clearcolor})},restoreclear:function(){if(this._clearstack.length>0){var e=this._clearstack.pop();this.clearcolor=e.clearcolor,this.clearbit=e.clearbit}},bindscenerendering:function(e){this._scenerendering=e},render:function(e,t,r,i){var n=this.gl,a=this.clearcolor;if(this.clearbit){n.colormask(!0,!0,!0,!0),n.depthmask(!0);var o=this.viewport,s=!1,l=o.devicepixelratio;(o.width!==this._width||o.height!==this._height||l&&l!==this.devicepixelratio||o.x||o.y)&&(s=!0,n.enable(n.scissor_test),n.scissor(o.x*l,o.y*l,o.width*l,o.height*l)),n.clearcolor(a[0],a[1],a[2],a[3]),n.clear(this.clearbit),s&&n.disable(n.scissor_test)}if(r||e.update(!1),e.updatelights(),t=t||e.getmaincamera()){t.update();var h=e.updaterenderlist(t,!0);this._scenerendering=e;var u=h.opaque,c=h.transparent,d=e.material;e.trigger("beforerender",this,e,t,h),i?(this.renderprez(u,e,t),n.depthfunc(n.lequal)):n.depthfunc(n.less);for(var f=je(),p=qe.create(),m=0;m0){var s=e[n-1],l=s.joints?s.joints.length:0;if((a.joints?a.joints.length:0)===l&&a.material===s.material&&a.lightgroup===s.lightgroup){a.__program=s.__program;continue}}var h=this._programmgr.getprogram(a,o,t);this.validateprogram(h),a.__program=h}},renderpass:function(e,t,r){this.trigger("beforerenderpass",this,e,t,r),(r=r||{}).getmaterial=r.getmaterial||et,r.getuniform=r.getuniform||tt,r.ismaterialchanged=r.ismaterialchanged||rt,r.beforerender=r.beforerender||nt,r.afterrender=r.afterrender||nt;var i=r.ifrender||it;this.updateprograms(e,this._scenerendering,r),r.sortcompare&&e.sort(r.sortcompare);var n=this.viewport,a=n.devicepixelratio,o=[n.x*a,n.y*a,n.width*a,n.height*a],s=this.devicepixelratio,l=this.__currentframebuffer?[this.__currentframebuffer.gettexturewidth(),this.__currentframebuffer.gettextureheight()]:[this._width*s,this._height*s],h=[o[2],o[3]],u=date.now();t?(ye.copy(ht.view,t.viewmatrix.array),ye.copy(ht.projection,t.projectionmatrix.array),ye.copy(ht.viewinverse,t.worldtransform.array)):(ye.identity(ht.view),ye.identity(ht.projection),ye.identity(ht.viewinverse)),ye.multiply(ht.viewprojection,ht.projection,ht.view),ye.invert(ht.projectioninverse,ht.projection),ye.invert(ht.viewprojectioninverse,ht.viewprojection);for(var c,d,f,p,m,g,_,v,y,x,b,w,t=this.gl,s=this._scenerendering,m=0;mthis.getmaxjointnumber()){var a=n.getsubskinmatricestexture(e.__uid__,e.joints);t.usetextureslot(this,a,r),t.setuniform(i,"1i","skinmatricestexture",r),t.setuniform(i,"1f","skinmatricestexturesize",a.width)}else{var o=n.getsubskinmatrices(e.__uid__,e.joints);t.setuniformofsemantic(i,"skin_matrix",o)}},_renderobject:function(e,t,r){var i=this.gl,n=e.geometry,a=e.mode;null==a&&(a=4);var o=null,s=e.isinstancedmesh&&e.isinstancedmesh();if(!s||(o=this.getglextension("angle_instanced_arrays"))){var l;if(s&&(l=this._bindinstancedattributes(e,r,o)),t.indicesbuffer){var h=this.getglextension("oes_element_index_uint")&&n.indices instanceof uint32array?i.unsigned_int:i.unsigned_short;s?o.drawelementsinstancedangle(a,t.indicesbuffer.count,h,0,e.getinstancecount()):i.drawelements(a,t.indicesbuffer.count,h,0)}else s?o.drawarraysinstancedangle(a,0,n.vertexcount,e.getinstancecount()):i.drawarrays(a,0,n.vertexcount);if(s)for(var u=0;ur?r:e}ct.add=function(e,t,r){return qe.add(e.array,t.array,r.array),e._dirty=!0,e},ct.set=function(e,t,r,i){qe.set(e.array,t,r,i),e._dirty=!0},ct.copy=function(e,t){return qe.copy(e.array,t.array),e._dirty=!0,e},ct.cross=function(e,t,r){return qe.cross(e.array,t.array,r.array),e._dirty=!0,e},ct.distance=ct.dist=function(e,t){return qe.distance(e.array,t.array)},ct.divide=ct.div=function(e,t,r){return qe.divide(e.array,t.array,r.array),e._dirty=!0,e},ct.dot=function(e,t){return qe.dot(e.array,t.array)},ct.len=function(e){return qe.length(e.array)},ct.lerp=function(e,t,r,i){return qe.lerp(e.array,t.array,r.array,i),e._dirty=!0,e},ct.min=function(e,t,r){return qe.min(e.array,t.array,r.array),e._dirty=!0,e},ct.max=function(e,t,r){return qe.max(e.array,t.array,r.array),e._dirty=!0,e},ct.multiply=ct.mul=function(e,t,r){return qe.multiply(e.array,t.array,r.array),e._dirty=!0,e},ct.negate=function(e,t){return qe.negate(e.array,t.array),e._dirty=!0,e},ct.normalize=function(e,t){return qe.normalize(e.array,t.array),e._dirty=!0,e},ct.random=function(e,t){return qe.random(e.array,t),e._dirty=!0,e},ct.scale=function(e,t,r){return qe.scale(e.array,t.array,r),e._dirty=!0,e},ct.scaleandadd=function(e,t,r,i){return qe.scaleandadd(e.array,t.array,r.array,i),e._dirty=!0,e},ct.squareddistance=ct.sqrdist=function(e,t){return qe.sqrdist(e.array,t.array)},ct.squaredlength=ct.sqrlen=function(e){return qe.sqrlen(e.array)},ct.subtract=ct.sub=function(e,t,r){return qe.subtract(e.array,t.array,r.array),e._dirty=!0,e},ct.transformmat3=function(e,t,r){return qe.transformmat3(e.array,t.array,r.array),e._dirty=!0,e},ct.transformmat4=function(e,t,r){return qe.transformmat4(e.array,t.array,r.array),e._dirty=!0,e},ct.transformquat=function(e,t,r){return qe.transformquat(e.array,t.array,r.array),e._dirty=!0,e};var mt=math.atan2,gt=math.asin,_t=math.abs;ct.eulerfromquat=function(e,t,r){e._dirty=!0,t=t.array;var i=e.array,n=t[0],a=t[1],o=t[2],s=t[3],l=n*n,h=a*a,u=o*o,c=s*s;switch(r=(r||"xyz").touppercase()){case"xyz":i[0]=mt(2*(n*s-a*o),c-l-h+u),i[1]=gt(pt(2*(n*o+a*s),-1,1)),i[2]=mt(2*(o*s-n*a),c+l-h-u);break;case"yxz":i[0]=gt(pt(2*(n*s-a*o),-1,1)),i[1]=mt(2*(n*o+a*s),c-l-h+u),i[2]=mt(2*(n*a+o*s),c-l+h-u);break;case"zxy":i[0]=gt(pt(2*(n*s+a*o),-1,1)),i[1]=mt(2*(a*s-o*n),c-l-h+u),i[2]=mt(2*(o*s-n*a),c-l+h-u);break;case"zyx":i[0]=mt(2*(n*s+o*a),c-l-h+u),i[1]=gt(pt(2*(a*s-n*o),-1,1)),i[2]=mt(2*(n*a+o*s),c+l-h-u);break;case"yzx":i[0]=mt(2*(n*s-o*a),c-l+h-u),i[1]=mt(2*(a*s-n*o),c+l-h-u),i[2]=gt(pt(2*(n*a+o*s),-1,1));break;case"xzy":i[0]=mt(2*(n*s+a*o),c-l+h-u),i[1]=mt(2*(n*o+a*s),c+l-h-u),i[2]=gt(pt(2*(o*s-n*a),-1,1));break;default:console.warn("unkown order: "+r)}return e},ct.eulerfrommat3=function(e,t,r){var i=t.array,n=i[0],a=i[3],o=i[6],s=i[1],l=i[4],h=i[7],u=i[2],c=i[5],d=i[8],f=e.array;switch(r=(r||"xyz").touppercase()){case"xyz":f[1]=gt(pt(o,-1,1)),_t(o)<.99999?(f[0]=mt(-h,d),f[2]=mt(-a,n)):(f[0]=mt(c,l),f[2]=0);break;case"yxz":f[0]=gt(-pt(h,-1,1)),_t(h)<.99999?(f[1]=mt(o,d),f[2]=mt(s,l)):(f[1]=mt(-u,n),f[2]=0);break;case"zxy":f[0]=gt(pt(c,-1,1)),_t(c)<.99999?(f[1]=mt(-u,d),f[2]=mt(-a,l)):(f[1]=0,f[2]=mt(s,n));break;case"zyx":f[1]=gt(-pt(u,-1,1)),_t(u)<.99999?(f[0]=mt(c,d),f[2]=mt(s,n)):(f[0]=0,f[2]=mt(-a,l));break;case"yzx":f[2]=gt(pt(s,-1,1)),_t(s)<.99999?(f[0]=mt(-h,l),f[1]=mt(-u,n)):(f[0]=0,f[1]=mt(o,d));break;case"xzy":f[2]=gt(-pt(a,-1,1)),_t(a)<.99999?(f[0]=mt(c,l),f[1]=mt(o,n)):(f[0]=mt(-h,d),f[1]=0);break;default:console.warn("unkown order: "+r)}return e._dirty=!0,e},object.defineproperties(ct,{positive_x:{get:function(){return new ct(1,0,0)}},negative_x:{get:function(){return new ct(-1,0,0)}},positive_y:{get:function(){return new ct(0,1,0)}},negative_y:{get:function(){return new ct(0,-1,0)}},positive_z:{get:function(){return new ct(0,0,1)}},negative_z:{get:function(){return new ct(0,0,-1)}},up:{get:function(){return new ct(0,1,0)}},zero:{get:function(){return new ct}}});const vt=ct;var yt,xt,bt,wt,tt,st=function(e,t){this.origin=e||new vt,this.direction=t||new vt};st.prototype={constructor:st,intersectplane:function(e,t){var r=e.normal.array,i=e.distance,n=this.origin.array,a=this.direction.array,o=qe.dot(r,a);if(0===o)return null;t||(t=new vt);var s=(qe.dot(r,n)-i)/o;return qe.scaleandadd(t.array,n,a,-s),t._dirty=!0,t},mirroragainstplane:function(e){var t=qe.dot(e.normal.array,this.direction.array);qe.scaleandadd(this.direction.array,this.direction.array,e.normal.array,2*-t),this.direction._dirty=!0},distancetopoint:(tt=qe.create(),function(e){qe.sub(tt,e,this.origin.array);var t=qe.dot(tt,this.direction.array);if(t<0)return qe.distance(this.origin.array,e);var r=qe.lensquared(tt);return math.sqrt(r-t*t)}),intersectsphere:function(){var e=qe.create();return function(t,r,i){var n=this.origin.array,a=this.direction.array;t=t.array,qe.sub(e,t,n);var o=qe.dot(e,a),s=qe.squaredlength(e)-o*o,l=r*r;if(!(s>l)){var h=math.sqrt(l-s),u=o-h,c=o+h;return i||(i=new vt),u<0?c<0?null:(qe.scaleandadd(i.array,n,a,c),i):(qe.scaleandadd(i.array,n,a,u),i)}}}(),intersectboundingbox:function(e,t){var r,i,n,a,o,s,l=this.direction.array,h=this.origin.array,u=e.min.array,c=e.max.array,d=1/l[0],f=1/l[1],p=1/l[2];if(d>=0?(r=(u[0]-h[0])*d,i=(c[0]-h[0])*d):(i=(u[0]-h[0])*d,r=(c[0]-h[0])*d),f>=0?(n=(u[1]-h[1])*f,a=(c[1]-h[1])*f):(a=(u[1]-h[1])*f,n=(c[1]-h[1])*f),r>a||n>i)return null;if((n>r||r!=r)&&(r=n),(a=0?(o=(u[2]-h[2])*p,s=(c[2]-h[2])*p):(s=(u[2]-h[2])*p,o=(c[2]-h[2])*p),r>s||o>i)return null;if((o>r||r!=r)&&(r=o),(s=0?r:i;return t||(t=new vt),qe.scaleandadd(t.array,h,l,m),t},intersecttriangle:(yt=qe.create(),xt=qe.create(),bt=qe.create(),wt=qe.create(),function(e,t,r,i,n,a){var o=this.direction.array,s=this.origin.array;e=e.array,t=t.array,r=r.array,qe.sub(yt,t,e),qe.sub(xt,r,e),qe.cross(wt,xt,o);var l=qe.dot(yt,wt);if(i){if(l>-1e-5)return null}else if(l>-1e-5&&l<1e-5)return null;qe.sub(bt,s,e);var h=qe.dot(wt,bt)/l;if(h<0||h>1)return null;qe.cross(wt,yt,bt);var u=qe.dot(o,wt)/l;if(u<0||u>1||h+u>1)return null;qe.cross(wt,yt,xt);var c=-qe.dot(bt,wt)/l;return c<0?null:(n||(n=new vt),a&&vt.set(a,1-h-u,h,u),qe.scaleandadd(n.array,s,o,c),n)}),applytransform:function(e){vt.add(this.direction,this.direction,this.origin),vt.transformmat4(this.origin,this.origin,e),vt.transformmat4(this.direction,this.direction,e),vt.sub(this.direction,this.direction,this.origin),vt.normalize(this.direction,this.direction)},copy:function(e){vt.copy(this.origin,e.origin),vt.copy(this.direction,e.direction)},clone:function(){var e=new st;return e.copy(this),e}};const mt=st;var at={create:function(){var e=new ce(4);return e[0]=0,e[1]=0,e[2]=0,e[3]=0,e},clone:function(e){var t=new ce(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t},fromvalues:function(e,t,r,i){var n=new ce(4);return n[0]=e,n[1]=t,n[2]=r,n[3]=i,n},copy:function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e},set:function(e,t,r,i,n){return e[0]=t,e[1]=r,e[2]=i,e[3]=n,e},add:function(e,t,r){return e[0]=t[0]+r[0],e[1]=t[1]+r[1],e[2]=t[2]+r[2],e[3]=t[3]+r[3],e},subtract:function(e,t,r){return e[0]=t[0]-r[0],e[1]=t[1]-r[1],e[2]=t[2]-r[2],e[3]=t[3]-r[3],e}};at.sub=at.subtract,at.multiply=function(e,t,r){return e[0]=t[0]*r[0],e[1]=t[1]*r[1],e[2]=t[2]*r[2],e[3]=t[3]*r[3],e},at.mul=at.multiply,at.divide=function(e,t,r){return e[0]=t[0]/r[0],e[1]=t[1]/r[1],e[2]=t[2]/r[2],e[3]=t[3]/r[3],e},at.div=at.divide,at.min=function(e,t,r){return e[0]=math.min(t[0],r[0]),e[1]=math.min(t[1],r[1]),e[2]=math.min(t[2],r[2]),e[3]=math.min(t[3],r[3]),e},at.max=function(e,t,r){return e[0]=math.max(t[0],r[0]),e[1]=math.max(t[1],r[1]),e[2]=math.max(t[2],r[2]),e[3]=math.max(t[3],r[3]),e},at.scale=function(e,t,r){return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e},at.scaleandadd=function(e,t,r,i){return e[0]=t[0]+r[0]*i,e[1]=t[1]+r[1]*i,e[2]=t[2]+r[2]*i,e[3]=t[3]+r[3]*i,e},at.distance=function(e,t){var r=t[0]-e[0],i=t[1]-e[1],n=t[2]-e[2],a=t[3]-e[3];return math.sqrt(r*r+i*i+n*n+a*a)},at.dist=at.distance,at.squareddistance=function(e,t){var r=t[0]-e[0],i=t[1]-e[1],n=t[2]-e[2],a=t[3]-e[3];return r*r+i*i+n*n+a*a},at.sqrdist=at.squareddistance,at.length=function(e){var t=e[0],r=e[1],i=e[2],n=e[3];return math.sqrt(t*t+r*r+i*i+n*n)},at.len=at.length,at.squaredlength=function(e){var t=e[0],r=e[1],i=e[2],n=e[3];return t*t+r*r+i*i+n*n},at.sqrlen=at.squaredlength,at.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=-t[3],e},at.inverse=function(e,t){return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e[3]=1/t[3],e},at.normalize=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],o=r*r+i*i+n*n+a*a;return o>0&&(o=1/math.sqrt(o),e[0]=t[0]*o,e[1]=t[1]*o,e[2]=t[2]*o,e[3]=t[3]*o),e},at.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]},at.lerp=function(e,t,r,i){var n=t[0],a=t[1],o=t[2],s=t[3];return e[0]=n+i*(r[0]-n),e[1]=a+i*(r[1]-a),e[2]=o+i*(r[2]-o),e[3]=s+i*(r[3]-s),e},at.random=function(e,t){return t=t||1,e[0]=de(),e[1]=de(),e[2]=de(),e[3]=de(),at.normalize(e,e),at.scale(e,e,t),e},at.transformmat4=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=t[3];return e[0]=r[0]*i+r[4]*n+r[8]*a+r[12]*o,e[1]=r[1]*i+r[5]*n+r[9]*a+r[13]*o,e[2]=r[2]*i+r[6]*n+r[10]*a+r[14]*o,e[3]=r[3]*i+r[7]*n+r[11]*a+r[15]*o,e},at.transformquat=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=r[0],s=r[1],l=r[2],h=r[3],u=h*i+s*a-l*n,c=h*n+l*i-o*a,d=h*a+o*n-s*i,f=-o*i-s*n-l*a;return e[0]=u*h+f*-o+c*-l-d*-s,e[1]=c*h+f*-s+d*-o-u*-l,e[2]=d*h+f*-l+u*-s-c*-o,e},at.foreach=function(){var e=at.create();return function(t,r,i,n,a,o){var s,l;for(r||(r=4),i||(i=0),l=n?math.min(n*r+i,t.length):t.length,s=i;s.999999?(e[0]=0,e[1]=0,e[2]=0,e[3]=1,e):(qe.cross(lt,t,r),e[0]=lt[0],e[1]=lt[1],e[2]=lt[2],e[3]=1+i,it.normalize(e,e))}),it.setaxes=(nt=dt.create(),function(e,t,r,i){return nt[0]=r[0],nt[3]=r[1],nt[6]=r[2],nt[1]=i[0],nt[4]=i[1],nt[7]=i[2],nt[2]=-t[0],nt[5]=-t[1],nt[8]=-t[2],it.normalize(e,it.frommat3(e,nt))}),it.clone=et.clone,it.fromvalues=et.fromvalues,it.copy=et.copy,it.set=et.set,it.identity=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e},it.setaxisangle=function(e,t,r){r*=.5;var i=math.sin(r);return e[0]=i*t[0],e[1]=i*t[1],e[2]=i*t[2],e[3]=math.cos(r),e},it.add=et.add,it.multiply=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=t[3],s=r[0],l=r[1],h=r[2],u=r[3];return e[0]=i*u+o*s+n*h-a*l,e[1]=n*u+o*l+a*s-i*h,e[2]=a*u+o*h+i*l-n*s,e[3]=o*u-i*s-n*l-a*h,e},it.mul=it.multiply,it.scale=et.scale,it.rotatex=function(e,t,r){r*=.5;var i=t[0],n=t[1],a=t[2],o=t[3],s=math.sin(r),l=math.cos(r);return e[0]=i*l+o*s,e[1]=n*l+a*s,e[2]=a*l-n*s,e[3]=o*l-i*s,e},it.rotatey=function(e,t,r){r*=.5;var i=t[0],n=t[1],a=t[2],o=t[3],s=math.sin(r),l=math.cos(r);return e[0]=i*l-a*s,e[1]=n*l+o*s,e[2]=a*l+i*s,e[3]=o*l-n*s,e},it.rotatez=function(e,t,r){r*=.5;var i=t[0],n=t[1],a=t[2],o=t[3],s=math.sin(r),l=math.cos(r);return e[0]=i*l+n*s,e[1]=n*l-i*s,e[2]=a*l+o*s,e[3]=o*l-a*s,e},it.calculatew=function(e,t){var r=t[0],i=t[1],n=t[2];return e[0]=r,e[1]=i,e[2]=n,e[3]=math.sqrt(math.abs(1-r*r-i*i-n*n)),e},it.dot=et.dot,it.lerp=et.lerp,it.slerp=function(e,t,r,i){var n,a,o,s,l,h=t[0],u=t[1],c=t[2],d=t[3],f=r[0],p=r[1],m=r[2],g=r[3];return(a=h*f+u*p+c*m+d*g)<0&&(a=-a,f=-f,p=-p,m=-m,g=-g),1-a>1e-6?(n=math.acos(a),o=math.sin(n),s=math.sin((1-i)*n)/o,l=math.sin(i*n)/o):(s=1-i,l=i),e[0]=s*h+l*f,e[1]=s*u+l*p,e[2]=s*c+l*m,e[3]=s*d+l*g,e},it.invert=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],o=r*r+i*i+n*n+a*a,s=o?1/o:0;return e[0]=-r*s,e[1]=-i*s,e[2]=-n*s,e[3]=a*s,e},it.conjugate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e},it.length=et.length,it.len=it.length,it.squaredlength=et.squaredlength,it.sqrlen=it.squaredlength,it.normalize=et.normalize,it.frommat3=function(e,t){var r,i=t[0]+t[4]+t[8];if(i>0)r=math.sqrt(i+1),e[3]=.5*r,r=.5/r,e[0]=(t[5]-t[7])*r,e[1]=(t[6]-t[2])*r,e[2]=(t[1]-t[3])*r;else{var n=0;t[4]>t[0]&&(n=1),t[8]>t[3*n+n]&&(n=2);var a=(n+1)%3,o=(n+2)%3;r=math.sqrt(t[3*n+n]-t[3*a+a]-t[3*o+o]+1),e[n]=.5*r,r=.5/r,e[3]=(t[3*a+o]-t[3*o+a])*r,e[a]=(t[3*a+n]+t[3*n+a])*r,e[o]=(t[3*o+n]+t[3*n+o])*r}return e};const rt=it;var bt,ft,zt,gt,ut=function(){this._axisx=new vt,this._axisy=new vt,this._axisz=new vt,this.array=ye.create(),this._dirty=!0};ut.prototype={constructor:ut,setarray:function(e){for(var t=0;t0){var t=this.min,r=this.max,i=t.array,n=r.array;tr(i,e[0]),tr(n,e[0]);for(var a=1;an[0]&&(n[0]=o[0]),o[1]>n[1]&&(n[1]=o[1]),o[2]>n[2]&&(n[2]=o[2])}t._dirty=!0,r._dirty=!0}},union:function(e){var t=this.min,r=this.max;return qe.min(t.array,t.array,e.min.array),qe.max(r.array,r.array,e.max.array),t._dirty=!0,r._dirty=!0,this},intersection:function(e){var t=this.min,r=this.max;return qe.max(t.array,t.array,e.min.array),qe.min(r.array,r.array,e.max.array),t._dirty=!0,r._dirty=!0,this},intersectboundingbox:function(e){var t=this.min.array,r=this.max.array,i=e.min.array,n=e.max.array;return!(t[0]>n[0]||t[1]>n[1]||t[2]>n[2]||r[0]=n[0]&&r[1]>=n[1]&&r[2]>=n[2]},containpoint:function(e){var t=this.min.array,r=this.max.array,i=e.array;return t[0]<=i[0]&&t[1]<=i[1]&&t[2]<=i[2]&&r[0]>=i[0]&&r[1]>=i[1]&&r[2]>=i[2]},isfinite:function(){var e=this.min.array,t=this.max.array;return isfinite(e[0])&&isfinite(e[1])&&isfinite(e[2])&&isfinite(t[0])&&isfinite(t[1])&&isfinite(t[2])},applytransform:function(e){this.transformfrom(this,e)},transformfrom:(zt=qe.create(),yt=qe.create(),kt=qe.create(),qt=qe.create(),jt=qe.create(),$t=qe.create(),function(e,t){var r=e.min.array,i=e.max.array,n=t.array;return zt[0]=n[0]*r[0],zt[1]=n[1]*r[0],zt[2]=n[2]*r[0],yt[0]=n[0]*i[0],yt[1]=n[1]*i[0],yt[2]=n[2]*i[0],kt[0]=n[4]*r[1],kt[1]=n[5]*r[1],kt[2]=n[6]*r[1],qt[0]=n[4]*i[1],qt[1]=n[5]*i[1],qt[2]=n[6]*i[1],jt[0]=n[8]*r[2],jt[1]=n[9]*r[2],jt[2]=n[10]*r[2],$t[0]=n[8]*i[2],$t[1]=n[9]*i[2],$t[2]=n[10]*i[2],r=this.min.array,i=this.max.array,r[0]=math.min(zt[0],yt[0])+math.min(kt[0],qt[0])+math.min(jt[0],$t[0])+n[12],r[1]=math.min(zt[1],yt[1])+math.min(kt[1],qt[1])+math.min(jt[1],$t[1])+n[13],r[2]=math.min(zt[2],yt[2])+math.min(kt[2],qt[2])+math.min(jt[2],$t[2])+n[14],i[0]=math.max(zt[0],yt[0])+math.max(kt[0],qt[0])+math.max(jt[0],$t[0])+n[12],i[1]=math.max(zt[1],yt[1])+math.max(kt[1],qt[1])+math.max(jt[1],$t[1])+n[13],i[2]=math.max(zt[2],yt[2])+math.max(kt[2],qt[2])+math.max(jt[2],$t[2])+n[14],this.min._dirty=!0,this.max._dirty=!0,this}),applyprojection:function(e){var t=this.min.array,r=this.max.array,i=e.array,n=t[0],a=t[1],o=t[2],s=r[0],l=r[1],h=t[2],u=r[0],c=r[1],d=r[2];if(1===i[15])t[0]=i[0]*n+i[12],t[1]=i[5]*a+i[13],r[2]=i[10]*o+i[14],r[0]=i[0]*u+i[12],r[1]=i[5]*c+i[13],t[2]=i[10]*d+i[14];else{var f=-1/o;t[0]=i[0]*n*f,t[1]=i[5]*a*f,r[2]=(i[10]*o+i[14])*f,f=-1/h,r[0]=i[0]*s*f,r[1]=i[5]*l*f,f=-1/d,t[2]=(i[10]*d+i[14])*f}return this.min._dirty=!0,this.max._dirty=!0,this},updatevertices:function(){var e=this.vertices;if(!e){e=[];for(var t=0;t<8;t++)e[t]=qe.fromvalues(0,0,0);this.vertices=e}var r=this.min.array,i=this.max.array;return er(e[0],r[0],r[1],r[2]),er(e[1],r[0],i[1],r[2]),er(e[2],i[0],r[1],r[2]),er(e[3],i[0],i[1],r[2]),er(e[4],r[0],r[1],i[2]),er(e[5],r[0],i[1],i[2]),er(e[6],i[0],r[1],i[2]),er(e[7],i[0],i[1],i[2]),this},copy:function(e){var t=this.min,r=this.max;return tr(t.array,e.min.array),tr(r.array,e.max.array),t._dirty=!0,r._dirty=!0,this},clone:function(){var e=new rr;return e.copy(this),e}};const ir=rr;var nr,ar,or=0;const sr=m.extend({name:"",position:null,rotation:null,scale:null,worldtransform:null,localtransform:null,autoupdatelocaltransform:!0,_parent:null,_scene:null,_needsupdateworldtransform:!0,_initerating:!1,__depth:0},(function(){this.name||(this.name=(this.type||"node")+"_"+or++),this.position||(this.position=new vt),this.rotation||(this.rotation=new qt),this.scale||(this.scale=new vt(1,1,1)),this.worldtransform=new ht,this.localtransform=new ht,this._children=[]}),{target:null,invisible:!1,isskinnedmesh:function(){return!1},isrenderable:function(){return!1},setname:function(e){var t=this._scene;if(t){var r=t._noderepository;delete r[this.name],r[e]=this}this.name=e},add:function(e){var t=e._parent;if(t!==this){t&&t.remove(e),e._parent=this,this._children.push(e);var r=this._scene;r&&r!==e.scene&&e.traverse(this._addselftoscene,this),e._needsupdateworldtransform=!0}},remove:function(e){var t=this._children,r=t.indexof(e);r<0||(t.splice(r,1),e._parent=null,this._scene&&e.traverse(this._removeselffromscene,this))},removeall:function(){for(var e=this._children,t=0;t0},beforerender:function(e){},afterrender:function(e,t){},getboundingbox:function(e,t){return t=sr.prototype.getboundingbox.call(this,e,t),this.geometry&&this.geometry.boundingbox&&t.union(this.geometry.boundingbox),t},clone:(lr=["castshadow","receiveshadow","mode","culling","cullface","frontface","frustumculling","renderorder","linewidth","ignorepicking","ignoreprez","ignoregbuffer"],function(){var e=sr.prototype.clone.call(this);e.geometry=this.geometry,e.material=this.material;for(var t=0;t=0&&g[p]>1e-4&&(qe.transformmat4(t,m,d[_[p]]),qe.scaleandadd(v,v,t,g[p]));s.set(f,v)}}for(f=0;f>t;return e+1},dispose:function(e){var t=this._cache;t.use(e.__uid__);var r=t.get("webgl_texture");r&&e.gl.deletetexture(r),t.deletecontext(e.__uid__)},isrenderable:function(){},ispoweroftwo:function(){}});object.defineproperty(br.prototype,"width",{get:function(){return this._width},set:function(e){this._width=e}}),object.defineproperty(br.prototype,"height",{get:function(){return this._height},set:function(e){this._height=e}}),br.byte=5120,br.unsigned_byte=t,br.short=5122,br.unsigned_short=5123,br.int=5124,br.unsigned_int=5125,br.float=s,br.half_float=36193,br.unsigned_int_24_8_webgl=34042,br.depth_component=m,br.depth_stencil=34041,br.alpha=6406,br.rgb=6407,br.rgba=a,br.luminance=6409,br.luminance_alpha=6410,br.srgb=35904,br.srgb_alpha=35906,br.compressed_rgb_s3tc_dxt1_ext=33776,br.compressed_rgba_s3tc_dxt1_ext=33777,br.compressed_rgba_s3tc_dxt3_ext=33778,br.compressed_rgba_s3tc_dxt5_ext=33779,br.nearest=e,br.linear=c,br.nearest_mipmap_nearest=d,br.linear_mipmap_nearest=l,br.nearest_mipmap_linear=p,br.linear_mipmap_linear=o,br.repeat=n,br.clamp_to_edge=i,br.mirrored_repeat=33648;const wr=br;var tr=ur.extend({skeleton:null,joints:null},(function(){this.joints||(this.joints=[])}),{offsetmatrix:null,isinstancedmesh:function(){return!1},isskinnedmesh:function(){return!!(this.skeleton&&this.joints&&this.joints.length>0)},clone:function(){var e=ur.prototype.clone.call(this);return e.skeleton=this.skeleton,this.joints&&(e.joints=this.joints.slice()),e}});tr.points=0,tr.lines=1,tr.line_loop=2,tr.line_strip=3,tr.triangles=4,tr.triangle_strip=5,tr.triangle_fan=6,tr.back=x,tr.front=y,tr.front_and_back=1032,tr.cw=b,tr.ccw=w;const sr=tr;const mr={ispoweroftwo:function(e){return 0==(e&e-1)},nextpoweroftwo:function(e){return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e},nearestpoweroftwo:function(e){return math.pow(2,math.round(math.log(e)/math.ln2))}};var ar=mr.ispoweroftwo;function er(e){return math.pow(2,math.round(math.log(e)/math.ln2))}var cr=wr.extend((function(){return{image:null,pixels:null,mipmaps:[],converttopot:!1}}),{texturetype:"texture2d",update:function(e){var t=e.gl;t.bindtexture(t.texture_2d,this._cache.get("webgl_texture")),this.updatecommon(e);var r=this.format,i=this.type,n=!(!this.converttopot||this.mipmaps.length||!this.image||this.wraps!==wr.repeat&&this.wrapt!==wr.repeat||!this.npot);t.texparameteri(t.texture_2d,t.texture_wrap_s,n?this.wraps:this.getavailablewraps()),t.texparameteri(t.texture_2d,t.texture_wrap_t,n?this.wrapt:this.getavailablewrapt()),t.texparameteri(t.texture_2d,t.texture_mag_filter,n?this.magfilter:this.getavailablemagfilter()),t.texparameteri(t.texture_2d,t.texture_min_filter,n?this.minfilter:this.getavailableminfilter());var a=e.getglextension("ext_texture_filter_anisotropic");if(a&&this.anisotropic>1&&t.texparameterf(t.texture_2d,a.texture_max_anisotropy_ext,this.anisotropic),36193===i&&(e.getglextension("oes_texture_half_float")||(i=s)),this.mipmaps.length)for(var o=this.width,s=this.height,l=0;l=wr.compressed_rgb_s3tc_dxt1_ext?e.compressedteximage2d(e.texture_2d,r,a,i,n,0,t.pixels):e.teximage2d(e.texture_2d,r,a,i,n,0,a,o,t.pixels)},generatemipmap:function(e){var t=e.gl;this.usemipmap&&!this.npot&&(t.bindtexture(t.texture_2d,this._cache.get("webgl_texture")),t.generatemipmap(t.texture_2d))},ispoweroftwo:function(){return ar(this.width)&&ar(this.height)},isrenderable:function(){return this.image?this.image.width>0&&this.image.height>0:!(!this.width||!this.height)},bind:function(e){e.gl.bindtexture(e.gl.texture_2d,this.getwebgltexture(e))},unbind:function(e){e.gl.bindtexture(e.gl.texture_2d,null)},load:function(e,t){var r=u.createimage();t&&(r.crossorigin=t);var i=this;return r.onload=function(){i.dirty(),i.trigger("success",i)},r.onerror=function(){i.trigger("error",i)},r.src=e,this.image=r,this}});object.defineproperty(cr.prototype,"width",{get:function(){return this.image?this.image.width:this._width},set:function(e){this.image?console.warn("texture from image can't set width"):(this._width!==e&&this.dirty(),this._width=e)}}),object.defineproperty(cr.prototype,"height",{get:function(){return this.image?this.image.height:this._height},set:function(e){this.image?console.warn("texture from image can't set height"):(this._height!==e&&this.dirty(),this._height=e)}});const dr=cr;function lr(e){return{byte:u.int8array,ubyte:u.uint8array,short:u.int16array,ushort:u.uint16array}[e]||u.float32array}function pr(e){return"attr_"+e}function or(e,t,r,i){switch(this.name=e,this.type=t,this.size=r,this.semantic=i||"",this.value=null,r){case 1:this.get=function(e){return this.value[e]},this.set=function(e,t){this.value[e]=t},this.copy=function(e,t){this.value[e]=this.value[e]};break;case 2:this.get=function(e,t){var r=this.value;return t[0]=r[2*e],t[1]=r[2*e+1],t},this.set=function(e,t){var r=this.value;r[2*e]=t[0],r[2*e+1]=t[1]},this.copy=function(e,t){var r=this.value;t*=2,r[e*=2]=r[t],r[e+1]=r[t+1]};break;case 3:this.get=function(e,t){var r=3*e,i=this.value;return t[0]=i[r],t[1]=i[r+1],t[2]=i[r+2],t},this.set=function(e,t){var r=3*e,i=this.value;i[r]=t[0],i[r+1]=t[1],i[r+2]=t[2]},this.copy=function(e,t){var r=this.value;t*=3,r[e*=3]=r[t],r[e+1]=r[t+1],r[e+2]=r[t+2]};break;case 4:this.get=function(e,t){var r=this.value,i=4*e;return t[0]=r[i],t[1]=r[i+1],t[2]=r[i+2],t[3]=r[i+3],t},this.set=function(e,t){var r=this.value,i=4*e;r[i]=t[0],r[i+1]=t[1],r[i+2]=t[2],r[i+3]=t[3]},this.copy=function(e,t){var r=this.value;t*=4,r[e*=4]=r[t],r[e+1]=r[t+1],r[e+2]=r[t+2],r[e+3]=r[t+3]}}}function nr(e,t,r,i,n){this.name=e,this.type=t,this.buffer=r,this.size=i,this.semantic=n,this.symbol="",this.needsremove=!1}function ir(e){this.buffer=e,this.count=0}or.prototype.init=function(e){if(!this.value||this.value.length!==e*this.size){var t=lr(this.type);this.value=new t(e*this.size)}},or.prototype.fromarray=function(e){var t,r=lr(this.type);if(e[0]&&e[0].length){var i=0,n=this.size;t=new r(e.length*n);for(var a=0;a=0){t||(t=[]);var r=this.indices;return t[0]=r[3*e],t[1]=r[3*e+1],t[2]=r[3*e+2],t}},settriangleindices:function(e,t){var r=this.indices;r[3*e]=t[0],r[3*e+1]=t[1],r[3*e+2]=t[2]},isuseindices:function(){return!!this.indices},initindicesfromarray:function(e){var t,r=this.vertexcount>65535?u.uint32array:u.uint16array;if(e[0]&&e[0].length){var i=0;t=new r(3*e.length);for(var n=0;n=0&&(t.splice(r,1),delete this.attributes[e],!0)},getattribute:function(e){return this.attributes[e]},getenabledattributes:function(){var e=this._enabledattributes,t=this._attributelist;if(e)return e;for(var r=[],i=this.vertexcount,n=0;na[0]&&(a[0]=s),l>a[1]&&(a[1]=l),h>a[2]&&(a[2]=h)}r._dirty=!0,i._dirty=!0}},generatevertexnormals:function(){if(this.vertexcount){var e=this.indices,t=this.attributes,r=t.position.value,i=t.normal.value;if(i&&i.length===r.length)for(var n=0;n65535&&(this.indices=new u.uint32array(this.indices));for(var e=this.attributes,t=this.indices,r=this.getenabledattributes(),i={},n=0;nthis.distance,n=1;n<8;n++)if(qe.dot(t[n].array,r)>this.distance!=i)return!0},intersectline:(qr=qe.create(),function(e,t,r){var i=this.distancetopoint(e),n=this.distancetopoint(t);if(i>0&&n>0||i<0&&n<0)return null;var a=this.normal.array,o=this.distance,s=e.array;qe.sub(qr,t.array,e.array),qe.normalize(qr,qr);var l=qe.dot(a,qr);if(0===l)return null;r||(r=new vt);var h=(qe.dot(a,s)-o)/l;return qe.scaleandadd(r.array,s,qr,-h),r._dirty=!0,r}),applytransform:(zr=ye.create(),yr=et.create(),kr=et.create(),kr[3]=1,function(e){e=e.array,qe.scale(kr,this.normal.array,this.distance),et.transformmat4(kr,kr,e),this.distance=qe.dot(kr,this.normal.array),ye.invert(zr,e),ye.transpose(zr,zr),yr[3]=0,qe.copy(yr,this.normal.array),et.transformmat4(yr,yr,zr),qe.copy(this.normal.array,yr)}),copy:function(e){qe.copy(this.normal.array,e.normal.array),this.normal._dirty=!0,this.distance=e.distance},clone:function(){var e=new jr;return e.copy(this),e}};const $r=jr;var ei,ti=qe.set,ri=qe.copy,ii=qe.transformmat4,ni=math.min,ai=math.max,oi=function(){this.planes=[];for(var e=0;e<6;e++)this.planes.push(new $r);for(this.boundingbox=new ir,this.vertices=[],e=0;e<8;e++)this.vertices[e]=qe.fromvalues(0,0,0)};oi.prototype={setfromprojection:function(e){var t=this.planes,r=e.array,i=r[0],n=r[1],a=r[2],o=r[3],s=r[4],l=r[5],h=r[6],u=r[7],c=r[8],d=r[9],f=r[10],p=r[11],m=r[12],g=r[13],_=r[14],v=r[15];ti(t[0].normal.array,o-i,u-s,p-c),t[0].distance=-(v-m),t[0].normalize(),ti(t[1].normal.array,o+i,u+s,p+c),t[1].distance=-(v+m),t[1].normalize(),ti(t[2].normal.array,o+n,u+l,p+d),t[2].distance=-(v+g),t[2].normalize(),ti(t[3].normal.array,o-n,u-l,p-d),t[3].distance=-(v-g),t[3].normalize(),ti(t[4].normal.array,o-a,u-h,p-f),t[4].distance=-(v-_),t[4].normalize(),ti(t[5].normal.array,o+a,u+h,p+f),t[5].distance=-(v+_),t[5].normalize();var y=this.boundingbox,x=this.vertices;if(0===v){var b=l/i,w=-_/(f-1),t=-_/(f+1),s=-t/l,m=-w/l;y.min.set(-s*b,-s,t),y.max.set(s*b,s,w),ti(x[0],-s*b,-s,t),ti(x[1],-s*b,s,t),ti(x[2],s*b,-s,t),ti(x[3],s*b,s,t),ti(x[4],-m*b,-m,w),ti(x[5],-m*b,m,w),ti(x[6],m*b,-m,w),ti(x[7],m*b,m,w)}else{var a=(-1-m)/i,e=(1-m)/i,c=(1-g)/l,d=(-1-g)/l,l=(-1-_)/f,p=(1-_)/f;y.min.set(math.min(a,e),math.min(d,c),math.min(p,l)),y.max.set(math.max(e,a),math.max(c,d),math.max(l,p));var o=y.min.array,n=y.max.array;ti(x[0],o[0],o[1],o[2]),ti(x[1],o[0],n[1],o[2]),ti(x[2],n[0],o[1],o[2]),ti(x[3],n[0],n[1],o[2]),ti(x[4],o[0],o[1],n[2]),ti(x[5],o[0],n[1],n[2]),ti(x[6],n[0],o[1],n[2]),ti(x[7],n[0],n[1],n[2])}},gettransformedboundingbox:(ei=qe.create(),function(e,t){var r=this.vertices,i=t.array,n=e.min,a=e.max,o=n.array,s=a.array,l=r[0];ii(ei,l,i),ri(o,ei),ri(s,ei);for(var h=1;h<8;h++)l=r[h],ii(ei,l,i),o[0]=ni(ei[0],o[0]),o[1]=ni(ei[1],o[1]),o[2]=ni(ei[2],o[2]),s[0]=ai(ei[0],s[0]),s[1]=ai(ei[1],s[1]),s[2]=ai(ei[2],s[2]);return n._dirty=!0,a._dirty=!0,e})};const si=oi;var li;const hi=sr.extend((function(){return{projectionmatrix:new ht,invprojectionmatrix:new ht,viewmatrix:new ht,frustum:new si}}),(function(){this.update(!0)}),{update:function(e){sr.prototype.update.call(this,e),ht.invert(this.viewmatrix,this.worldtransform),this.updateprojectionmatrix(),ht.invert(this.invprojectionmatrix,this.projectionmatrix),this.frustum.setfromprojection(this.projectionmatrix)},setviewmatrix:function(e){ht.copy(this.viewmatrix,e),ht.invert(this.worldtransform,e),this.decomposeworldtransform()},decomposeprojectionmatrix:function(){},setprojectionmatrix:function(e){ht.copy(this.projectionmatrix,e),ht.invert(this.invprojectionmatrix,e),this.decomposeprojectionmatrix()},updateprojectionmatrix:function(){},castray:(li=et.create(),function(e,t){var r=void 0!==t?t:new mt,i=e.array[0],n=e.array[1];return et.set(li,i,n,-1,1),et.transformmat4(li,li,this.invprojectionmatrix.array),et.transformmat4(li,li,this.worldtransform.array),qe.scale(r.origin.array,li,1/li[3]),et.set(li,i,n,1,1),et.transformmat4(li,li,this.invprojectionmatrix.array),et.transformmat4(li,li,this.worldtransform.array),qe.scale(li,li,1/li[3]),qe.sub(r.direction.array,li,r.origin.array),qe.normalize(r.direction.array,r.direction.array),r.direction._dirty=!0,r.origin._dirty=!0,r})});var ui,ci,di=ye.create(),fi=ye.create(),pi={};function mi(e){var t=[],r=object.keys(e);r.sort();for(var i=0;i0&&console.warn("found multiple camera in one scene. use the fist one."),this._cameralist.push(e)):e instanceof qr&&this.lights.push(e),e.name&&(this._noderepository[e.name]=e)},removefromscene:function(e){var t;e instanceof hi?(t=this._cameralist.indexof(e))>=0&&this._cameralist.splice(t,1):e instanceof qr&&(t=this.lights.indexof(e))>=0&&this.lights.splice(t,1),e.name&&delete this._noderepository[e.name]},getnode:function(e){return this._noderepository[e]},setmaincamera:function(e){var t=this._cameralist.indexof(e);t>=0&&this._cameralist.splice(t,1),this._cameralist.unshift(e)},getmaincamera:function(){return this._cameralist[0]},getlights:function(){return this.lights},updatelights:function(){var e=this.lights;this._previouslightnumber=this._lightnumber;for(var t={},r=0;r0&&this._doupdaterenderlist(o,t,r,i,n)}},isfrustumculled:(ui=new ir,ci=new ht,function(e,t,r){var i=e.boundingbox;if(i||(i=e.skeleton&&e.skeleton.boundingbox?e.skeleton.boundingbox:e.geometry.boundingbox),!i)return!1;if(ci.array=r,ui.transformfrom(i,ci),e.castshadow&&this.viewboundingboxlastframe.union(ui),e.frustumculling){if(!ui.intersectboundingbox(t.frustum.boundingbox))return!0;ci.array=t.projectionmatrix.array,ui.max.array[2]>0&&ui.min.array[2]<0&&(ui.max.array[2]=-1e-20),ui.applyprojection(ci);var n=ui.min.array,a=ui.max.array;if(a[0]<-1||n[0]>1||a[1]<-1||n[1]>1||a[2]<-1||n[2]>1)return!0}return!1}),_updatelightuniforms:function(){var e=this.lights;e.sort(_i);var t=this._lightuniforms;for(var r in t)for(var i in t[r])t[r][i].value.length=0;for(var n=0;n=this._maxsize&&a>0){var s=r.head;r.remove(s),delete i[s.key],n=s.value,this._lastremovedentry=s}o?o.value=t:o=new yi(t),o.key=e,r.insertentry(o),i[e]=o}return n},e.prototype.get=function(e){var t=this._map[e],r=this._list;if(null!=t)return t!==r.tail&&(r.remove(t),r.insertentry(t)),t.value},e.prototype.clear=function(){this._list.clear(),this._map={}},e.prototype.len=function(){return this._list.len()},e}();var wi=mr.ispoweroftwo,ti=["px","nx","py","ny","pz","nz"],si=wr.extend((function(){return{image:{px:null,nx:null,py:null,ny:null,pz:null,nz:null},pixels:{px:null,nx:null,py:null,ny:null,pz:null,nz:null},mipmaps:[]}}),{texturetype:"texturecube",update:function(e){var t=e.gl;t.bindtexture(t.texture_cube_map,this._cache.get("webgl_texture")),this.updatecommon(e);var r=this.format,i=this.type;t.texparameteri(t.texture_cube_map,t.texture_wrap_s,this.getavailablewraps()),t.texparameteri(t.texture_cube_map,t.texture_wrap_t,this.getavailablewrapt()),t.texparameteri(t.texture_cube_map,t.texture_mag_filter,this.getavailablemagfilter()),t.texparameteri(t.texture_cube_map,t.texture_min_filter,this.getavailableminfilter());var n=e.getglextension("ext_texture_filter_anisotropic");if(n&&this.anisotropic>1&&t.texparameterf(t.texture_cube_map,n.texture_max_anisotropy_ext,this.anisotropic),36193===i&&(e.getglextension("oes_texture_half_float")||(i=s)),this.mipmaps.length)for(var a=this.width,o=this.height,s=0;s0&&e.height>0}object.defineproperty(si.prototype,"width",{get:function(){return this.image&&this.image.px?this.image.px.width:this._width},set:function(e){this.image&&this.image.px?console.warn("texture from image can't set width"):(this._width!==e&&this.dirty(),this._width=e)}}),object.defineproperty(si.prototype,"height",{get:function(){return this.image&&this.image.px?this.image.px.height:this._height},set:function(e){this.image&&this.image.px?console.warn("texture from image can't set height"):(this._height!==e&&this.dirty(),this._height=e)}});const ai=si,ei=hi.extend({fov:50,aspect:1,near:.1,far:2e3},{updateprojectionmatrix:function(){var e=this.fov/180*math.pi;this.projectionmatrix.perspective(e,this.aspect,this.near,this.far)},decomposeprojectionmatrix:function(){var e=this.projectionmatrix.array,t=2*math.atan(1/e[5]);this.fov=t/math.pi*180,this.aspect=e[5]/e[0],this.near=e[14]/(e[10]-1),this.far=e[14]/(e[10]+1)},clone:function(){var e=hi.prototype.clone.call(this);return e.fov=this.fov,e.aspect=this.aspect,e.near=this.near,e.far=this.far,e}});var ci="framebuffer",di="renderbuffer",li="renderbuffer_width",pi="renderbuffer_height",oi="renderbuffer_attached",ni="depthtexture_attached",ii=36160,ri=36161,bi=36096,fi=m.extend({depthbuffer:!0,viewport:null,_width:0,_height:0,_textures:null,_boundrenderer:null},(function(){this._cache=new xr,this._textures={}}),{gettexturewidth:function(){return this._width},gettextureheight:function(){return this._height},bind:function(e){if(e.__currentframebuffer){if(e.__currentframebuffer===this)return;console.warn("renderer already bound with another framebuffer. unbind it first")}e.__currentframebuffer=this;var t=e.gl;t.bindframebuffer(ii,this._getframebuffergl(e)),this._boundrenderer=e;var r=this._cache;r.put("viewport",e.viewport);var i,n,a=!1;for(var o in this._textures){a=!0;var s=this._textures[o];s&&(i=s.texture.width,n=s.texture.height,this._doattach(e,s.texture,o,s.target))}this._width=i,this._height=n,!a&&this.depthbuffer&&console.error("must attach texture before bind, or renderbuffer may have incorrect width and height."),this.viewport?e.setviewport(this.viewport):e.setviewport(0,0,i,n,1);var l=r.get("attached_textures");if(l)for(var o in l)if(!this._textures[o]){var h=l[o];this._dodetach(t,o,h)}if(!r.get(ni)&&this.depthbuffer){r.miss(di)&&r.put(di,t.createrenderbuffer());var u=r.get(di);i===r.get(li)&&n===r.get(pi)||(t.bindrenderbuffer(ri,u),t.renderbufferstorage(ri,t.depth_component16,i,n),r.put(li,i),r.put(pi,n),t.bindrenderbuffer(ri,null)),r.get(oi)||(t.framebufferrenderbuffer(ii,bi,ri,u),r.put(oi,!0))}},unbind:function(e){e.__currentframebuffer=null,e.gl.bindframebuffer(ii,null),this._boundrenderer=null,this._cache.use(e.__uid__);var t=this._cache.get("viewport");t&&e.setviewport(t),this.updatemipmap(e)},updatemipmap:function(e){var t=e.gl;for(var r in this._textures){var i=this._textures[r];if(i){var n=i.texture;if(!n.npot&&n.usemipmap&&n.minfilter===wr.linear_mipmap_linear){var a="texturecube"===n.texturetype?34067:3553;t.bindtexture(a,n.getwebgltexture(e)),t.generatemipmap(a),t.bindtexture(a,null)}}}},checkstatus:function(e){return e.checkframebufferstatus(ii)},_getframebuffergl:function(e){var t=this._cache;return t.use(e.__uid__),t.miss(ci)&&t.put(ci,e.gl.createframebuffer()),t.get(ci)},attach:function(e,t,r){if(!e.width)throw new error("the texture attached to color buffer is not a valid.");t=t||36064,r=r||3553;var i,n=this._boundrenderer;if(n&&n.gl){var a=this._cache;a.use(n.__uid__),i=a.get("attached_textures")}var o=this._textures[t];if(!o||o.target!==r||o.texture!==e||!i||null==i[t]){var s=!0;n&&(s=this._doattach(n,e,t,r),this.viewport||n.setviewport(0,0,e.width,e.height,1)),s&&(this._textures[t]=this._textures[t]||{},this._textures[t].texture=e,this._textures[t].target=r)}},_doattach:function(e,t,r,i){var n=e.gl,a=t.getwebgltexture(e),o=this._cache.get("attached_textures");if(o&&o[r]){var s=o[r];if(s.texture===t&&s.target===i)return}var l=!0;if(((r=+r)===bi||r===r)&&(e.getglextension("webgl_depth_texture")||(console.error("depth texture is not supported by the browser"),l=!1),t.format!==m&&34041!==t.format&&(console.error("the texture attached to depth buffer is not a valid."),l=!1),l)){var h=this._cache.get(di);h&&(n.framebufferrenderbuffer(ii,bi,ri,null),n.deleterenderbuffer(h),this._cache.put(di,!1)),this._cache.put(oi,!1),this._cache.put(ni,!0)}return n.framebuffertexture2d(ii,r,i,a,0),o||(o={},this._cache.put("attached_textures",o)),o[r]=o[r]||{},o[r].texture=t,o[r].target=i,l},_dodetach:function(e,t,r){e.framebuffertexture2d(ii,t,r,null,0);var i=this._cache.get("attached_textures");i&&i[t]&&(i[t]=null),t!==bi&&t!==r||this._cache.put(ni,!1)},detach:function(e,t){this._textures[e]=null,this._boundrenderer&&(this._cache.use(this._boundrenderer.__uid__),this._dodetach(this._boundrenderer.gl,e,t))},dispose:function(e){var t=e.gl,r=this._cache;r.use(e.__uid__);var i=r.get(di);i&&t.deleterenderbuffer(i);var n=r.get(ci);n&&t.deleteframebuffer(n),r.deletecontext(e.__uid__),this._textures={}}});fi.depth_attachment=bi,fi.color_attachment0=36064,fi.stencil_attachment=36128,fi.depth_stencil_attachment=r;const zi=fi;var gi=["px","nx","py","ny","pz","nz"];const ui=m.extend((function(){var e={position:new vt,far:1e3,near:.1,texture:null,shadowmappass:null},t=e._cameras={px:new ei({fov:90}),nx:new ei({fov:90}),py:new ei({fov:90}),ny:new ei({fov:90}),pz:new ei({fov:90}),nz:new ei({fov:90})};return t.px.lookat(vt.positive_x,vt.negative_y),t.nx.lookat(vt.negative_x,vt.negative_y),t.py.lookat(vt.positive_y,vt.positive_z),t.ny.lookat(vt.negative_y,vt.negative_z),t.pz.lookat(vt.positive_z,vt.negative_y),t.nz.lookat(vt.negative_z,vt.negative_y),e._framebuffer=new zi,e}),{getcamera:function(e){return this._cameras[e]},render:function(e,t,r){var i=e.gl;r||t.update();for(var n=this.texture.width,a=2*math.atan(n/(n-.5))/math.pi*180,o=0;o<6;o++){var s=gi[o],l=this._cameras[s];if(vt.copy(l.position,this.position),l.far=this.far,l.near=this.near,l.fov=a,this.shadowmappass){l.update();var h=t.getboundingbox();h.applytransform(l.viewmatrix),t.viewboundingboxlastframe.copy(h),this.shadowmappass.render(e,t,l,!0)}this._framebuffer.attach(this.texture,i.color_attachment0,i.texture_cube_map_positive_x+o),this._framebuffer.bind(e),e.render(t,l,!0),this._framebuffer.unbind(e)}},dispose:function(e){this._framebuffer.dispose(e)}}),ki=vr.extend({dynamic:!1,widthsegments:1,heightsegments:1},(function(){this.build()}),{build:function(){for(var e=this.heightsegments,t=this.widthsegments,r=this.attributes,i=[],n=[],a=[],o=[],s=0;s<=e;s++)for(var l=s/e,h=0;h<=t;h++){var u=h/t;if(i.push([2*u-1,2*l-1,0]),n&&n.push([u,l]),a&&a.push([0,0,1]),h0?this.material.define("fragment","lod"):this.material.undefine("fragment","lod"),e.renderpass([this],r)}}),xi=ji;function qi(e){return e.charcodeat(0)+(e.charcodeat(1)<<8)+(e.charcodeat(2)<<16)+(e.charcodeat(3)<<24)}var zi=qi("dxt1"),yi=qi("dxt3"),ki=qi("dxt5");const qi=function(e,t){var r=new int32array(e,0,31);if(542327876!==r[0])return null;if(4&!r(20))return null;var i,n,a=r(21),o=r[4],s=r[3],l=512&r[28],h=131072&r[2];switch(a){case zi:i=8,n=wr.compressed_rgb_s3tc_dxt1_ext;break;case yi:i=16,n=wr.compressed_rgba_s3tc_dxt3_ext;break;case ki:i=16,n=wr.compressed_rgba_s3tc_dxt5_ext;break;default:return null}var u=r[1]+4,c=l?6:1,d=1;h&&(d=math.max(1,r[7]));for(var f=[],p=0;p0){var n=math.pow(2,e[3]-128-8+i);t[r+0]=e[0]*n,t[r+1]=e[1]*n,t[r+2]=e[2]*n}else t[r+0]=0,t[r+1]=0,t[r+2]=0;return t[r+3]=1,t}function en(e,t,r,i){for(var n,a,o=0,s=0,l=i;l>0;)if(e[s][0]=t[r++],e[s][1]=t[r++],e[s][2]=t[r++],e[s][3]=t[r++],1===e[s][0]&&1===e[s][1]&&1===e[s][2]){for(var h=e[s][3]<>>0;h>0;h--)n=e[s-1],(a=e[s])[0]=n[0],a[1]=n[1],a[2]=n[2],a[3]=n[3],s++,l--;o+=8}else s++,l--,o=0;return r}function tn(e,t,r,i){if(i<8|i>32767)return en(e,t,r,i);if(2!=(n=t[r++]))return en(e,t,r-1,i);if(e[0][1]=t[r++],e[0][2]=t[r++],n=t[r++],(e[0][2]<<8>>>0|n)>>>0!==i)return null;for(var n=0;n<4;n++)for(var a=0;a128){o=(127&o)>>>0;for(var s=t[r++];o--;)e[a++][n]=s}else for(;o--;)e[a++][n]=t[r++]}return r}const rn=function(e,t,r){null==r&&(r=0);var i=new uint8array(e),n=i.length;if("#?"===function(e,t,r){for(var i="",n=0;n<2;n++)i+=ji(e[n]);return i}(i)){for(var a=2;a=n)){a+=2;for(var o="";a20)return console.warn("given image is not a height map"),e}var d,f,p,m;l%(4*i)==0?(d=o.data[l],p=o.data[l+4]):l%(4*i)==4*(i-1)?(d=o.data[l-4],p=o.data[l]):(d=o.data[l-4],p=o.data[l+4]),l<4*i?(f=o.data[l],m=o.data[l+4*i]):l>i*(n-1)*4?(f=o.data[l-4*i],m=o.data[l]):(f=o.data[l-4*i],m=o.data[l+4*i]),s.data[l]=d-p+127,s.data[l+1]=f-m+127,s.data[l+2]=255,s.data[l+3]=255}return a.putimagedata(s,0,0),r},isheightimage:function(e,t,r){if(!e||!e.width||!e.height)return!1;var i=document.createelement("canvas"),n=i.getcontext("2d"),a=t||32;r=r||20,i.width=i.height=a,n.drawimage(e,0,0,a,a);for(var o=n.getimagedata(0,0,a,a),s=0;sr)return!1}return!0},_fetchtexture:function(e,t,r){u.request.get({url:e,responsetype:"arraybuffer",onload:t,onerror:r})},createchessboard:function(e,t,r,i){e=e||512,t=t||64,r=r||"black",i=i||"white";var n=math.ceil(e/t),a=document.createelement("canvas");a.width=e,a.height=e;var o=a.getcontext("2d");o.fillstyle=i,o.fillrect(0,0,e,e),o.fillstyle=r;for(var s=0;s=0||(on.foreach((function(t){e.on(t,this[sn(t)],this)}),this),this._meshes.push(e))},detachfrommesh:function(e){var t=this._meshes.indexof(e);t>=0&&this._meshes.splice(t,1),on.foreach((function(t){e.off(t,this[sn(t)])}),this)},dispose:function(){this._meshes.foreach((function(e){this.detachfrommesh(e)}),this)}};const hn=ln,un=hi.extend({left:-1,right:1,near:-1,far:1,top:1,bottom:-1},{updateprojectionmatrix:function(){this.projectionmatrix.ortho(this.left,this.right,this.bottom,this.top,this.near,this.far)},decomposeprojectionmatrix:function(){var e=this.projectionmatrix.array;this.left=(-1-e[12])/e[0],this.right=(1-e[12])/e[0],this.top=(1-e[13])/e[5],this.bottom=(-1-e[13])/e[5],this.near=-(-1-e[14])/e[10],this.far=-(1-e[14])/e[10]},clone:function(){var e=hi.prototype.clone.call(this);return e.left=this.left,e.right=this.right,e.near=this.near,e.far=this.far,e.top=this.top,e.bottom=this.bottom,e}});xe.import("\n@export clay.compositor.vertex\nuniform mat4 worldviewprojection : worldviewprojection;\nattribute vec3 position : position;\nattribute vec2 texcoord : texcoord_0;\nvarying vec2 v_texcoord;\nvoid main()\n{\n v_texcoord = texcoord;\n gl_position = worldviewprojection * vec4(position, 1.0);\n}\n@end");var cn=new ki,dn=new sr({geometry:cn,frustumculling:!1}),fn=new un;const pn=m.extend((function(){return{fragment:"",outputs:null,material:null,blendwithprevious:!1,clearcolor:!1,cleardepth:!0}}),(function(){var e=new xe(xe.source("clay.compositor.vertex"),this.fragment),t=new le({shader:e});t.enabletexturesall(),this.material=t}),{setuniform:function(e,t){this.material.setuniform(e,t)},getuniform:function(e){var t=this.material.uniforms[e];if(t)return t.value},attachoutput:function(e,t){this.outputs||(this.outputs={}),t=t||36064,this.outputs[t]=e},detachoutput:function(e){for(var t in this.outputs)this.outputs[t]===e&&(this.outputs[t]=null)},bind:function(e,t){if(this.outputs)for(var r in this.outputs){var i=this.outputs[r];i&&t.attach(i,r)}t&&t.bind(e)},unbind:function(e,t){t.unbind(e)},render:function(e,t){var r=e.gl;if(t){this.bind(e,t);var i=e.getglextension("ext_draw_buffers");if(i&&this.outputs){var n=[];for(var a in this.outputs)(a=+a)>=r.color_attachment0&&a<=r.color_attachment0+8&&n.push(a);i.drawbuffersext(n)}}this.trigger("beforerender",this,e);var o=this.cleardepth?r.depth_buffer_bit:0;if(r.depthmask(!0),this.clearcolor){o|=r.color_buffer_bit,r.colormask(!0,!0,!0,!0);var s=this.clearcolor;array.isarray(s)&&r.clearcolor(s[0],s[1],s[2],s[3])}r.clear(o),this.blendwithprevious?(r.enable(r.blend),this.material.transparent=!0):(r.disable(r.blend),this.material.transparent=!1),this.renderquad(e),this.trigger("afterrender",this,e),t&&this.unbind(e,t)},renderquad:function(e){dn.material=this.material,e.renderpass([dn],fn)},dispose:function(e){}});var mn={},gn=["px","nx","py","ny","pz","nz"];mn.prefilterenvironmentmap=function(e,t,r,i,n){n&&i||(i=mn.generatenormaldistribution(),n=mn.integratebrdf(e,i));var a=(r=r||{}).width||64,o=r.height||64,s=r.type||t.type,l=new ai({width:a,height:o,type:s,flipy:!1,mipmaps:[]});l.ispoweroftwo()||console.warn("width and height must be power of two to enable mipmap.");var h=math.min(a,o),u=math.log(h)/math.log(2)+1,c=new le({shader:new xe({vertex:xe.source("clay.skybox.vertex"),fragment:"#define shader_name prefilter\n#define sample_number 1024\n#define pi 3.14159265358979\nuniform mat4 viewinverse : viewinverse;\nuniform samplercube environmentmap;\nuniform sampler2d normaldistribution;\nuniform float roughness : 0.5;\nvarying vec2 v_texcoord;\nvarying vec3 v_worldposition;\n@import clay.util.rgbm\nvec3 importancesamplenormal(float i, float roughness, vec3 n) {\n vec3 h = texture2d(normaldistribution, vec2(roughness, i)).rgb;\n vec3 upvector = abs(n.y) > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);\n vec3 tangentx = normalize(cross(n, upvector));\n vec3 tangentz = cross(n, tangentx);\n return normalize(tangentx * h.x + n * h.y + tangentz * h.z);\n}\nvoid main() {\n vec3 eyepos = viewinverse[3].xyz;\n vec3 v = normalize(v_worldposition - eyepos);\n vec3 n = v;\n vec3 prefilteredcolor = vec3(0.0);\n float totalweight = 0.0;\n float fmaxsamplenumber = float(sample_number);\n for (int i = 0; i < sample_number; i++) {\n vec3 h = importancesamplenormal(float(i) / fmaxsamplenumber, roughness, n);\n vec3 l = reflect(-v, h);\n float nol = clamp(dot(n, l), 0.0, 1.0);\n if (nol > 0.0) {\n prefilteredcolor += decodehdr(texturecube(environmentmap, l)).rgb * nol;\n totalweight += nol;\n }\n }\n gl_fragcolor = encodehdr(vec4(prefilteredcolor / totalweight, 1.0));\n}\n"})});c.set("normaldistribution",i),r.encodergbm&&c.define("fragment","rgbm_encode"),r.decodergbm&&c.define("fragment","rgbm_decode");var d,f=new vi;if("texture2d"===t.texturetype){var p=new ai({width:a,height:o,type:s===wr.float?wr.half_float:s});an.panoramatocubemap(e,t,p,{encodergbm:r.decodergbm}),t=p}(d=new ji({scene:f,material:c})).material.set("environmentmap",t);var m=new ui({texture:l});r.encodergbm&&(s=l.type=wr.unsigned_byte);for(var g=new dr({width:a,height:o,type:s}),_=new zi({depthbuffer:!1}),v=u[s===wr.unsigned_byte?"uint8array":"float32array"],y=0;y 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);\n vec3 tangentx = normalize(cross(n, upvector));\n vec3 tangentz = cross(n, tangentx);\n return normalize(tangentx * h.x + n * h.y + tangentz * h.z);\n}\nfloat g_smith(float roughness, float nov, float nol) {\n float k = roughness * roughness / 2.0;\n float g1v = nov / (nov * (1.0 - k) + k);\n float g1l = nol / (nol * (1.0 - k) + k);\n return g1l * g1v;\n}\nvoid main() {\n vec2 uv = gl_fragcoord.xy / viewportsize;\n float nov = uv.x;\n float roughness = uv.y;\n vec3 v;\n v.x = sqrt(1.0 - nov * nov);\n v.y = 0.0;\n v.z = nov;\n float a = 0.0;\n float b = 0.0;\n for (int i = 0; i < sample_number; i++) {\n vec3 h = importancesamplenormal(float(i) / fsamplenumber, roughness, n);\n vec3 l = reflect(-v, h);\n float nol = clamp(l.z, 0.0, 1.0);\n float noh = clamp(h.z, 0.0, 1.0);\n float voh = clamp(dot(v, h), 0.0, 1.0);\n if (nol > 0.0) {\n float g = g_smith(roughness, nov, nol);\n float g_vis = g * voh / (noh * nov);\n float fc = pow(1.0 - voh, 5.0);\n a += (1.0 - fc) * g_vis;\n b += fc * g_vis;\n }\n }\n gl_fragcolor = vec4(vec2(a, b) / fsamplenumber, 0.0, 1.0);\n}\n"}),n=new dr({width:512,height:256,type:wr.half_float,wraps:wr.clamp_to_edge,wrapt:wr.clamp_to_edge,minfilter:wr.nearest,magfilter:wr.nearest,usemipmap:!1});return i.setuniform("normaldistribution",t),i.setuniform("viewportsize",[512,256]),i.attachoutput(n),i.render(e,r),r.dispose(e),n},mn.generatenormaldistribution=function(e,t){for(var r=new dr({width:e=e||256,height:t=t||1024,type:wr.float,minfilter:wr.nearest,magfilter:wr.nearest,wraps:wr.clamp_to_edge,wrapt:wr.clamp_to_edge,usemipmap:!1}),i=new float32array(t*e*4),n=[],a=0;a>>16)>>>0;h=(((16711935&(h=((252645135&(h=((858993459&(h=((1431655765&h)<<1|(2863311530&h)>>>1)>>>0))<<2|(3435973836&h)>>>2)>>>0))<<4|(4042322160&h)>>>4)>>>0))<<8|(4278255360&h)>>>8)>>>0)/4294967296;var u=math.sqrt((1-h)/(1+(s*s-1)*h));n[l]=u}for(l=0;l65535?uint32array:uint16array,v=this.indices=new _(t*e*6),y=this.radius,x=this.phistart,b=this.philength,w=this.thetastart,t=this.thetalength,s=[],m=[],a=0,e=1/(y=this.radius);for(d=0;d<=e;d++)for(c=0;c<=t;c++)h=c/t,u=d/e,o=-y*math.cos(x+h*b)*math.sin(w+u*t),s=y*math.cos(w+u*t),l=y*math.sin(x+h*b)*math.sin(w+u*t),s[0]=o,s[1]=s,s[2]=l,m[0]=h,m[1]=u,r.set(a,s),i.set(a,m),s[0]*=e,s[1]*=e,s[2]*=e,n.set(a,s),a++;var c=t+1,d=0;for(d=0;d255?255:e}function qn(e){return e<0?0:e>1?1:e}function jn(e){var t=e;return t.length&&"%"===t.charat(t.length-1)?kn(parsefloat(t)/100*255):kn(parseint(t,10))}function $n(e){var t=e;return t.length&&"%"===t.charat(t.length-1)?qn(parsefloat(t)/100):qn(parsefloat(t))}function ea(e,t,r){return r<0?r+=1:r>1&&(r-=1),6*r<1?e+(t-e)*r*6:2*r<1?t:3*r<2?e+(t-e)*(2/3-r)*6:e}function ta(e,t,r,i,n){return e[0]=t,e[1]=r,e[2]=i,e[3]=n,e}function ra(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}var ia=new bi(20),na=null;function aa(e,t){na&&ra(na,t),na=ia.put(e,na||t.slice())}function oa(e,t){if(e){t=t||[];var r=ia.get(e);if(r)return ra(t,r);var i=(e+="").replace(/ /g,"").tolowercase();if(i in yn)return ra(t,yn[i]),aa(e,t),t;var n,a=i.length;if("#"===i.charat(0))return 4===a||5===a?(n=parseint(i.slice(1,4),16))>=0&&n<=4095?(ta(t,(3840&n)>>4|(3840&n)>>8,240&n|(240&n)>>4,15&n|(15&n)<<4,5===a?parseint(i.slice(4),16)/15:1),aa(e,t),t):void ta(t,0,0,0,1):7===a||9===a?(n=parseint(i.slice(1,7),16))>=0&&n<=16777215?(ta(t,(16711680&n)>>16,(65280&n)>>8,255&n,9===a?parseint(i.slice(7),16)/255:1),aa(e,t),t):void ta(t,0,0,0,1):void 0;var o=i.indexof("("),s=i.indexof(")");if(-1!==o&&s+1===a){var l=i.substr(0,o),h=i.substr(o+1,s-(o+1)).split(","),u=1;switch(l){case"rgba":if(4!==h.length)return 3===h.length?ta(t,+h[0],+h[1],+h[2],1):ta(t,0,0,0,1);u=$n(h.pop());case"rgb":return 3!==h.length?void ta(t,0,0,0,1):(ta(t,jn(h[0]),jn(h[1]),jn(h[2]),u),aa(e,t),t);case"hsla":return 4!==h.length?void ta(t,0,0,0,1):(h[3]=$n(h[3]),sa(h,t),aa(e,t),t);case"hsl":return 3!==h.length?void ta(t,0,0,0,1):(sa(h,t),aa(e,t),t);default:return}}ta(t,0,0,0,1)}}function sa(e,t){var r=(parsefloat(e[0])%360+360)%360/360,i=$n(e[1]),n=$n(e[2]),a=n<=.5?n*(i+1):n+i-n*i,o=2*n-a;return ta(t=t||[],kn(255*ea(o,a,r+1/3)),kn(255*ea(o,a,r)),kn(255*ea(o,a,r-1/3)),1),4===e.length&&(t[3]=e[3]),t}var la=object.prototype.tostring,ha=array.prototype,ua=ha.foreach,ca=ha.filter,da=ha.slice,fa=ha.map,pa=function(){}.constructor,ma=pa?pa.prototype:null;function ga(e,t){if(object.assign)object.assign(e,t);else for(var r in t)t.hasownproperty(r)&&(e[r]=t[r]);return e}function _a(e,t,r){if(e="prototype"in e?e.prototype:e,t="prototype"in t?t.prototype:t,object.getownpropertynames)for(var i=object.getownpropertynames(t),n=0;no)i.length=o;else for(var s=a;s=2&&this.interpolable},e.prototype.getadditivetrack=function(){return this._additivetrack},e.prototype.addkeyframe=function(e,t){e>=this.maxtime?this.maxtime=e:this._needssort=!0;var r=this.keyframes,i=r.length;if(this.interpolable)if(va(t)){var n=function(e){return va(e&&e[0])?2:1}(t);if(i>0&&this.arrdim!==n)return void(this.interpolable=!1);if(1===n&&"number"!=typeof t[0]||2===n&&"number"!=typeof t[0][0])return void(this.interpolable=!1);if(i>0){var a=r[i-1];this._isallvalueequal&&(1===n&&na(t,a.value)||(this._isallvalueequal=!1))}this.arrdim=n}else{if(this.arrdim>0)return void(this.interpolable=!1);if("string"==typeof t){var o=oa(t);o?(t=o,this.isvaluecolor=!0):this.interpolable=!1}else if("number"!=typeof t||isnan(t))return void(this.interpolable=!1);this._isallvalueequal&&i>0&&(a=r[i-1],(this.isvaluecolor&&!na(a.value,t)||a.value!==t)&&(this._isallvalueequal=!1))}var s={time:e,value:t,percent:0};return this.keyframes.push(s),s},e.prototype.prepare=function(e){var t=this.keyframes;this._needssort&&t.sort((function(e,t){return e.time-t.time}));for(var r=this.arrdim,i=t.length,n=t[i-1],a=0;a0&&a!==i-1&&oa(t[a].value,n.value,r);if(e&&this.needsanimate()&&e.needsanimate()&&r===e.arrdim&&this.isvaluecolor===e.isvaluecolor&&!e._finished){this._additivetrack=e;var o=t[0].value;for(a=0;a=0&&!(a[r].percent<=t);r--);r=math.min(r,o-2)}else{for(r=this._lastframe;rt);r++);r=math.min(r-1,o-2)}var u=a[r+1],c=a[r];if(c&&u){this._lastframe=r,this._lastframepercent=t;var d=u.percent-c.percent;if(0!==d){var f=(t-c.percent)/d,p=i?this._additivevalue:h?za:e[s];if((l>0||h)&&!p&&(p=this._additivevalue=[]),this.usespline){var m=a[r][n],g=a[0===r?r:r-1][n],_=a[r>o-2?o-1:r+1][n],v=a[r>o-3?o-1:r+2][n];if(l>0)1===l?ra(p,g,m,_,v,f,f*f,f*f*f):function(e,t,r,i,n,a,o,s){for(var l=t.length,h=t[0].length,u=0;u0?1===l?da(p,c[n],u[n],f):function(e,t,r,i){for(var n=t.length,a=n&&t[0].length,o=0;o.5?t:e}(c[n],u[n],f),i?this._additivevalue=y:e[s]=y);i&&this._addtotarget(e)}}}},e.prototype._addtotarget=function(e){var t=this.arrdim,r=this.propname,i=this._additivevalue;0===t?this.isvaluecolor?(oa(e[r],za),la(za,za,i,1),e[r]=fa(za)):e[r]=e[r]+i:1===t?la(e[r],e[r],i,1):2===t&&pa(e[r],e[r],i,1)},e}();const ua=function(){function e(e,t,r){this._tracks={},this._trackkeys=[],this._delay=0,this._maxtime=0,this._paused=!1,this._started=0,this._clip=null,this._target=e,this._loop=t,t&&r?function(){for(var e=[],t=0;t0)){this._started=1;for(var r=this,i=[],n=0;n1){var o=a.pop();n.addkeyframe(o.time,e[i]),n.prepare(n.getadditivetrack())}}}},e}(),ka={_animators:null,getanimators:function(){return this._animators=this._animators||[],this._animators},animate:function(e,t){var r;if(this._animators=this._animators||[],e){for(var i=e.split("."),n=this,a=0,o=i.length;a=0&&s.splice(e,1)})),s.push(l),this.__zr&&this.__zr.animation.addanimator(l),l},stopanimation:function(e){this._animators=this._animators||[];for(var t=this._animators,r=t.length,i=0;i 1e-4)\n{\n skinmatrixws += getskinmatrix(joint.y) * weight.y;\n}\nif (weight.z > 1e-4)\n{\n skinmatrixws += getskinmatrix(joint.z) * weight.z;\n}\nfloat weightw = 1.0-weight.x-weight.y-weight.z;\nif (weightw > 1e-4)\n{\n skinmatrixws += getskinmatrix(joint.w) * weightw;\n}\n@end\n@export clay.chunk.instancing_header\n#ifdef instancing\nattribute vec4 instancemat1;\nattribute vec4 instancemat2;\nattribute vec4 instancemat3;\n#endif\n@end\n@export clay.chunk.instancing_matrix\nmat4 instancemat = mat4(\n vec4(instancemat1.xyz, 0.0),\n vec4(instancemat2.xyz, 0.0),\n vec4(instancemat3.xyz, 0.0),\n vec4(instancemat1.w, instancemat2.w, instancemat3.w, 1.0)\n);\n@end\n@export clay.util.parallax_correct\nvec3 parallaxcorrect(in vec3 dir, in vec3 pos, in vec3 boxmin, in vec3 boxmax) {\n vec3 first = (boxmax - pos) / dir;\n vec3 second = (boxmin - pos) / dir;\n vec3 further = max(first, second);\n float dist = min(further.x, min(further.y, further.z));\n vec3 fixedpos = pos + dir * dist;\n vec3 boxcenter = (boxmax + boxmin) * 0.5;\n return normalize(fixedpos - boxcenter);\n}\n@end\n@export clay.util.clamp_sample\nvec4 clampsample(const in sampler2d texture, const in vec2 coord)\n{\n#ifdef stereo\n float eye = step(0.5, coord.x) * 0.5;\n vec2 coordclamped = clamp(coord, vec2(eye, 0.0), vec2(0.5 + eye, 1.0));\n#else\n vec2 coordclamped = clamp(coord, vec2(0.0), vec2(1.0));\n#endif\n return texture2d(texture, coordclamped);\n}\n@end\n@export clay.util.aces\nvec3 acestonemapping(vec3 color)\n{\n const float a = 2.51;\n const float b = 0.03;\n const float c = 2.43;\n const float d = 0.59;\n const float e = 0.14;\n return (color * (a * color + b)) / (color * (c * color + d) + e);\n}\n@end";function ha(e){return e instanceof htmlcanvaselement||e instanceof htmlimageelement||e instanceof image}object.assign(sr.prototype,ka),xe.import(va),xe.import(qe),xe.import("\n@export ecgl.common.transformuniforms\nuniform mat4 worldviewprojection : worldviewprojection;\nuniform mat4 worldinversetranspose : worldinversetranspose;\nuniform mat4 world : world;\n@end\n\n@export ecgl.common.attributes\nattribute vec3 position : position;\nattribute vec2 texcoord : texcoord_0;\nattribute vec3 normal : normal;\n@end\n\n@export ecgl.common.uv.header\nuniform vec2 uvrepeat : [1.0, 1.0];\nuniform vec2 uvoffset : [0.0, 0.0];\nuniform vec2 detailuvrepeat : [1.0, 1.0];\nuniform vec2 detailuvoffset : [0.0, 0.0];\n\nvarying vec2 v_texcoord;\nvarying vec2 v_detailtexcoord;\n@end\n\n@export ecgl.common.uv.main\nv_texcoord = texcoord * uvrepeat + uvoffset;\nv_detailtexcoord = texcoord * detailuvrepeat + detailuvoffset;\n@end\n\n@export ecgl.common.uv.fragmentheader\nvarying vec2 v_texcoord;\nvarying vec2 v_detailtexcoord;\n@end\n\n\n@export ecgl.common.albedo.main\n\n vec4 albedotexel = vec4(1.0);\n#ifdef diffusemap_enabled\n albedotexel = texture2d(diffusemap, v_texcoord);\n #ifdef srgb_decode\n albedotexel = srgbtolinear(albedotexel);\n #endif\n#endif\n\n#ifdef detailmap_enabled\n vec4 detailtexel = texture2d(detailmap, v_detailtexcoord);\n #ifdef srgb_decode\n detailtexel = srgbtolinear(detailtexel);\n #endif\n albedotexel.rgb = mix(albedotexel.rgb, detailtexel.rgb, detailtexel.a);\n albedotexel.a = detailtexel.a + (1.0 - detailtexel.a) * albedotexel.a;\n#endif\n\n@end\n\n@export ecgl.common.wireframe.vertexheader\n\n#ifdef wireframe_quad\nattribute vec4 barycentric;\nvarying vec4 v_barycentric;\n#elif defined(wireframe_triangle)\nattribute vec3 barycentric;\nvarying vec3 v_barycentric;\n#endif\n\n@end\n\n@export ecgl.common.wireframe.vertexmain\n\n#if defined(wireframe_quad) || defined(wireframe_triangle)\n v_barycentric = barycentric;\n#endif\n\n@end\n\n\n@export ecgl.common.wireframe.fragmentheader\n\nuniform float wireframelinewidth : 1;\nuniform vec4 wireframelinecolor: [0, 0, 0, 0.5];\n\n#ifdef wireframe_quad\nvarying vec4 v_barycentric;\nfloat edgefactor () {\n vec4 d = fwidth(v_barycentric);\n vec4 a4 = smoothstep(vec4(0.0), d * wireframelinewidth, v_barycentric);\n return min(min(min(a4.x, a4.y), a4.z), a4.w);\n}\n#elif defined(wireframe_triangle)\nvarying vec3 v_barycentric;\nfloat edgefactor () {\n vec3 d = fwidth(v_barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * wireframelinewidth, v_barycentric);\n return min(min(a3.x, a3.y), a3.z);\n}\n#endif\n\n@end\n\n\n@export ecgl.common.wireframe.fragmentmain\n\n#if defined(wireframe_quad) || defined(wireframe_triangle)\n if (wireframelinewidth > 0.) {\n vec4 linecolor = wireframelinecolor;\n#ifdef srgb_decode\n linecolor = srgbtolinear(linecolor);\n#endif\n\n gl_fragcolor.rgb = mix(gl_fragcolor.rgb, linecolor.rgb, (1.0 - edgefactor()) * linecolor.a);\n }\n#endif\n@end\n\n\n\n\n@export ecgl.common.bumpmap.header\n\n#ifdef bumpmap_enabled\nuniform sampler2d bumpmap;\nuniform float bumpscale : 1.0;\n\n\nvec3 bumpnormal(vec3 surfpos, vec3 surfnormal, vec3 basenormal)\n{\n vec2 dstdx = dfdx(v_texcoord);\n vec2 dstdy = dfdy(v_texcoord);\n\n float hll = bumpscale * texture2d(bumpmap, v_texcoord).x;\n float dhx = bumpscale * texture2d(bumpmap, v_texcoord + dstdx).x - hll;\n float dhy = bumpscale * texture2d(bumpmap, v_texcoord + dstdy).x - hll;\n\n vec3 vsigmax = dfdx(surfpos);\n vec3 vsigmay = dfdy(surfpos);\n vec3 vn = surfnormal;\n\n vec3 r1 = cross(vsigmay, vn);\n vec3 r2 = cross(vn, vsigmax);\n\n float fdet = dot(vsigmax, r1);\n\n vec3 vgrad = sign(fdet) * (dhx * r1 + dhy * r2);\n return normalize(abs(fdet) * basenormal - vgrad);\n\n}\n#endif\n\n@end\n\n@export ecgl.common.normalmap.vertexheader\n\n#ifdef normalmap_enabled\nattribute vec4 tangent : tangent;\nvarying vec3 v_tangent;\nvarying vec3 v_bitangent;\n#endif\n\n@end\n\n@export ecgl.common.normalmap.vertexmain\n\n#ifdef normalmap_enabled\n if (dot(tangent, tangent) > 0.0) {\n v_tangent = normalize((worldinversetranspose * vec4(tangent.xyz, 0.0)).xyz);\n v_bitangent = normalize(cross(v_normal, v_tangent) * tangent.w);\n }\n#endif\n\n@end\n\n\n@export ecgl.common.normalmap.fragmentheader\n\n#ifdef normalmap_enabled\nuniform sampler2d normalmap;\nvarying vec3 v_tangent;\nvarying vec3 v_bitangent;\n#endif\n\n@end\n\n@export ecgl.common.normalmap.fragmentmain\n#ifdef normalmap_enabled\n if (dot(v_tangent, v_tangent) > 0.0) {\n vec3 normaltexel = texture2d(normalmap, v_detailtexcoord).xyz;\n if (dot(normaltexel, normaltexel) > 0.0) { n = normaltexel * 2.0 - 1.0;\n mat3 tbn = mat3(v_tangent, v_bitangent, v_normal);\n n = normalize(tbn * n);\n }\n }\n#endif\n@end\n\n\n\n@export ecgl.common.vertexanimation.header\n\n#ifdef vertex_animation\nattribute vec3 prevposition;\nattribute vec3 prevnormal;\nuniform float percent;\n#endif\n\n@end\n\n@export ecgl.common.vertexanimation.main\n\n#ifdef vertex_animation\n vec3 pos = mix(prevposition, position, percent);\n vec3 norm = mix(prevnormal, normal, percent);\n#else\n vec3 pos = position;\n vec3 norm = normal;\n#endif\n\n@end\n\n\n@export ecgl.common.ssaomap.header\n#ifdef ssaomap_enabled\nuniform sampler2d ssaomap;\nuniform vec4 viewport : viewport;\n#endif\n@end\n\n@export ecgl.common.ssaomap.main\n float ao = 1.0;\n#ifdef ssaomap_enabled\n ao = texture2d(ssaomap, (gl_fragcoord.xy - viewport.xy) / viewport.zw).r;\n#endif\n@end\n\n\n\n\n@export ecgl.common.diffuselayer.header\n\n#if (layer_diffusemap_count > 0)\nuniform float layerdiffuseintensity[layer_diffusemap_count];\nuniform sampler2d layerdiffusemap[layer_diffusemap_count];\n#endif\n\n@end\n\n@export ecgl.common.emissivelayer.header\n\n#if (layer_emissivemap_count > 0)\nuniform float layeremissionintensity[layer_emissivemap_count];\nuniform sampler2d layeremissivemap[layer_emissivemap_count];\n#endif\n\n@end\n\n@export ecgl.common.layers.header\n@import ecgl.common.diffuselayer.header\n@import ecgl.common.emissivelayer.header\n@end\n\n@export ecgl.common.diffuselayer.main\n\n#if (layer_diffusemap_count > 0)\n for (int _idx_ = 0; _idx_ < layer_diffusemap_count; _idx_++) {{\n float intensity = layerdiffuseintensity[_idx_];\n vec4 texel2 = texture2d(layerdiffusemap[_idx_], v_texcoord);\n #ifdef srgb_decode\n texel2 = srgbtolinear(texel2);\n #endif\n albedotexel.rgb = mix(albedotexel.rgb, texel2.rgb * intensity, texel2.a);\n albedotexel.a = texel2.a + (1.0 - texel2.a) * albedotexel.a;\n }}\n#endif\n\n@end\n\n@export ecgl.common.emissivelayer.main\n\n#if (layer_emissivemap_count > 0)\n for (int _idx_ = 0; _idx_ < layer_emissivemap_count; _idx_++)\n {{\n vec4 texel2 = texture2d(layeremissivemap[_idx_], v_texcoord) * layeremissionintensity[_idx_];\n #ifdef srgb_decode\n texel2 = srgbtolinear(texel2);\n #endif\n float intensity = layeremissionintensity[_idx_];\n gl_fragcolor.rgb += texel2.rgb * texel2.a * intensity;\n }}\n#endif\n\n@end\n"),xe.import("@export ecgl.color.vertex\n\nuniform mat4 worldviewprojection : worldviewprojection;\n\n@import ecgl.common.uv.header\n\nattribute vec2 texcoord : texcoord_0;\nattribute vec3 position: position;\n\n@import ecgl.common.wireframe.vertexheader\n\n#ifdef vertex_color\nattribute vec4 a_color : color;\nvarying vec4 v_color;\n#endif\n\n#ifdef vertex_animation\nattribute vec3 prevposition;\nuniform float percent : 1.0;\n#endif\n\n#ifdef atmosphere_enabled\nattribute vec3 normal: normal;\nuniform mat4 worldinversetranspose : worldinversetranspose;\nvarying vec3 v_normal;\n#endif\n\nvoid main()\n{\n#ifdef vertex_animation\n vec3 pos = mix(prevposition, position, percent);\n#else\n vec3 pos = position;\n#endif\n\n gl_position = worldviewprojection * vec4(pos, 1.0);\n\n @import ecgl.common.uv.main\n\n#ifdef vertex_color\n v_color = a_color;\n#endif\n\n#ifdef atmosphere_enabled\n v_normal = normalize((worldinversetranspose * vec4(normal, 0.0)).xyz);\n#endif\n\n @import ecgl.common.wireframe.vertexmain\n\n}\n\n@end\n\n@export ecgl.color.fragment\n\n#define layer_diffusemap_count 0\n#define layer_emissivemap_count 0\n\nuniform sampler2d diffusemap;\nuniform sampler2d detailmap;\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\n#ifdef atmosphere_enabled\nuniform mat4 viewtranspose: viewtranspose;\nuniform vec3 glowcolor;\nuniform float glowpower;\nvarying vec3 v_normal;\n#endif\n\n#ifdef vertex_color\nvarying vec4 v_color;\n#endif\n\n@import ecgl.common.layers.header\n\n@import ecgl.common.uv.fragmentheader\n\n@import ecgl.common.wireframe.fragmentheader\n\n@import clay.util.srgb\n\nvoid main()\n{\n#ifdef srgb_decode\n gl_fragcolor = srgbtolinear(color);\n#else\n gl_fragcolor = color;\n#endif\n\n#ifdef vertex_color\n gl_fragcolor *= v_color;\n#endif\n\n @import ecgl.common.albedo.main\n\n @import ecgl.common.diffuselayer.main\n\n gl_fragcolor *= albedotexel;\n\n#ifdef atmosphere_enabled\n float atmointensity = pow(1.0 - dot(v_normal, (viewtranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowpower);\n gl_fragcolor.rgb += glowcolor * atmointensity;\n#endif\n\n @import ecgl.common.emissivelayer.main\n\n @import ecgl.common.wireframe.fragmentmain\n\n}\n@end"),xe.import("/**\n * http: */\n\n@export ecgl.lambert.vertex\n\n@import ecgl.common.transformuniforms\n\n@import ecgl.common.uv.header\n\n\n@import ecgl.common.attributes\n\n@import ecgl.common.wireframe.vertexheader\n\n#ifdef vertex_color\nattribute vec4 a_color : color;\nvarying vec4 v_color;\n#endif\n\n\n@import ecgl.common.vertexanimation.header\n\n\nvarying vec3 v_normal;\nvarying vec3 v_worldposition;\n\nvoid main()\n{\n @import ecgl.common.uv.main\n\n @import ecgl.common.vertexanimation.main\n\n\n gl_position = worldviewprojection * vec4(pos, 1.0);\n\n v_normal = normalize((worldinversetranspose * vec4(norm, 0.0)).xyz);\n v_worldposition = (world * vec4(pos, 1.0)).xyz;\n\n#ifdef vertex_color\n v_color = a_color;\n#endif\n\n @import ecgl.common.wireframe.vertexmain\n}\n\n@end\n\n\n@export ecgl.lambert.fragment\n\n#define layer_diffusemap_count 0\n#define layer_emissivemap_count 0\n\n#define normal_up_axis 1\n#define normal_front_axis 2\n\n@import ecgl.common.uv.fragmentheader\n\nvarying vec3 v_normal;\nvarying vec3 v_worldposition;\n\nuniform sampler2d diffusemap;\nuniform sampler2d detailmap;\n\n@import ecgl.common.layers.header\n\nuniform float emissionintensity: 1.0;\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nuniform mat4 viewinverse : viewinverse;\n\n#ifdef atmosphere_enabled\nuniform mat4 viewtranspose: viewtranspose;\nuniform vec3 glowcolor;\nuniform float glowpower;\n#endif\n\n#ifdef ambient_light_count\n@import clay.header.ambient_light\n#endif\n#ifdef ambient_sh_light_count\n@import clay.header.ambient_sh_light\n#endif\n\n#ifdef directional_light_count\n@import clay.header.directional_light\n#endif\n\n#ifdef vertex_color\nvarying vec4 v_color;\n#endif\n\n\n@import ecgl.common.ssaomap.header\n\n@import ecgl.common.bumpmap.header\n\n@import clay.util.srgb\n\n@import ecgl.common.wireframe.fragmentheader\n\n@import clay.plugin.compute_shadow_map\n\nvoid main()\n{\n#ifdef srgb_decode\n gl_fragcolor = srgbtolinear(color);\n#else\n gl_fragcolor = color;\n#endif\n\n#ifdef vertex_color\n #ifdef srgb_decode\n gl_fragcolor *= srgbtolinear(v_color);\n #else\n gl_fragcolor *= v_color;\n #endif\n#endif\n\n @import ecgl.common.albedo.main\n\n @import ecgl.common.diffuselayer.main\n\n gl_fragcolor *= albedotexel;\n\n vec3 n = v_normal;\n#ifdef double_sided\n vec3 eyepos = viewinverse[3].xyz;\n vec3 v = normalize(eyepos - v_worldposition);\n\n if (dot(n, v) < 0.0) {\n n = -n;\n }\n#endif\n\n float ambientfactor = 1.0;\n\n#ifdef bumpmap_enabled\n n = bumpnormal(v_worldposition, v_normal, n);\n ambientfactor = dot(v_normal, n);\n#endif\n\n vec3 n2 = vec3(n.x, n[normal_up_axis], n[normal_front_axis]);\n\n vec3 diffusecolor = vec3(0.0, 0.0, 0.0);\n\n @import ecgl.common.ssaomap.main\n\n#ifdef ambient_light_count\n for(int i = 0; i < ambient_light_count; i++)\n {\n diffusecolor += ambientlightcolor[i] * ambientfactor * ao;\n }\n#endif\n#ifdef ambient_sh_light_count\n for(int _idx_ = 0; _idx_ < ambient_sh_light_count; _idx_++)\n {{\n diffusecolor += calcambientshlight(_idx_, n2) * ambientshlightcolor[_idx_] * ao;\n }}\n#endif\n#ifdef directional_light_count\n#if defined(directional_light_shadowmap_count)\n float shadowcontribsdir[directional_light_count];\n if(shadowenabled)\n {\n computeshadowofdirectionallights(v_worldposition, shadowcontribsdir);\n }\n#endif\n for(int i = 0; i < directional_light_count; i++)\n {\n vec3 lightdirection = -directionallightdirection[i];\n vec3 lightcolor = directionallightcolor[i];\n\n float shadowcontrib = 1.0;\n#if defined(directional_light_shadowmap_count)\n if (shadowenabled)\n {\n shadowcontrib = shadowcontribsdir[i];\n }\n#endif\n\n float ndl = dot(n, normalize(lightdirection)) * shadowcontrib;\n\n diffusecolor += lightcolor * clamp(ndl, 0.0, 1.0);\n }\n#endif\n\n gl_fragcolor.rgb *= diffusecolor;\n\n#ifdef atmosphere_enabled\n float atmointensity = pow(1.0 - dot(v_normal, (viewtranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowpower);\n gl_fragcolor.rgb += glowcolor * atmointensity;\n#endif\n\n @import ecgl.common.emissivelayer.main\n\n @import ecgl.common.wireframe.fragmentmain\n}\n\n@end"),xe.import("@export ecgl.realistic.vertex\n\n@import ecgl.common.transformuniforms\n\n@import ecgl.common.uv.header\n\n@import ecgl.common.attributes\n\n\n@import ecgl.common.wireframe.vertexheader\n\n#ifdef vertex_color\nattribute vec4 a_color : color;\nvarying vec4 v_color;\n#endif\n\n#ifdef normalmap_enabled\nattribute vec4 tangent : tangent;\nvarying vec3 v_tangent;\nvarying vec3 v_bitangent;\n#endif\n\n@import ecgl.common.vertexanimation.header\n\nvarying vec3 v_normal;\nvarying vec3 v_worldposition;\n\nvoid main()\n{\n\n @import ecgl.common.uv.main\n\n @import ecgl.common.vertexanimation.main\n\n gl_position = worldviewprojection * vec4(pos, 1.0);\n\n v_normal = normalize((worldinversetranspose * vec4(norm, 0.0)).xyz);\n v_worldposition = (world * vec4(pos, 1.0)).xyz;\n\n#ifdef vertex_color\n v_color = a_color;\n#endif\n\n#ifdef normalmap_enabled\n v_tangent = normalize((worldinversetranspose * vec4(tangent.xyz, 0.0)).xyz);\n v_bitangent = normalize(cross(v_normal, v_tangent) * tangent.w);\n#endif\n\n @import ecgl.common.wireframe.vertexmain\n\n}\n\n@end\n\n\n\n@export ecgl.realistic.fragment\n\n#define layer_diffusemap_count 0\n#define layer_emissivemap_count 0\n#define pi 3.14159265358979\n#define roughness_chanel 0\n#define metalness_chanel 1\n\n#define normal_up_axis 1\n#define normal_front_axis 2\n\n#ifdef vertex_color\nvarying vec4 v_color;\n#endif\n\n@import ecgl.common.uv.fragmentheader\n\nvarying vec3 v_normal;\nvarying vec3 v_worldposition;\n\nuniform sampler2d diffusemap;\n\nuniform sampler2d detailmap;\nuniform sampler2d metalnessmap;\nuniform sampler2d roughnessmap;\n\n@import ecgl.common.layers.header\n\nuniform float emissionintensity: 1.0;\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nuniform float metalness : 0.0;\nuniform float roughness : 0.5;\n\nuniform mat4 viewinverse : viewinverse;\n\n#ifdef atmosphere_enabled\nuniform mat4 viewtranspose: viewtranspose;\nuniform vec3 glowcolor;\nuniform float glowpower;\n#endif\n\n#ifdef ambient_light_count\n@import clay.header.ambient_light\n#endif\n\n#ifdef ambient_sh_light_count\n@import clay.header.ambient_sh_light\n#endif\n\n#ifdef ambient_cubemap_light_count\n@import clay.header.ambient_cubemap_light\n#endif\n\n#ifdef directional_light_count\n@import clay.header.directional_light\n#endif\n\n@import ecgl.common.normalmap.fragmentheader\n\n@import ecgl.common.ssaomap.header\n\n@import ecgl.common.bumpmap.header\n\n@import clay.util.srgb\n\n@import clay.util.rgbm\n\n@import ecgl.common.wireframe.fragmentheader\n\n@import clay.plugin.compute_shadow_map\n\nvec3 f_schlick(float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n\nfloat d_phong(float g, float ndh) {\n float a = pow(8192.0, g);\n return (a + 2.0) / 8.0 * pow(ndh, a);\n}\n\nvoid main()\n{\n vec4 albedocolor = color;\n\n vec3 eyepos = viewinverse[3].xyz;\n vec3 v = normalize(eyepos - v_worldposition);\n#ifdef vertex_color\n #ifdef srgb_decode\n albedocolor *= srgbtolinear(v_color);\n #else\n albedocolor *= v_color;\n #endif\n#endif\n\n @import ecgl.common.albedo.main\n\n @import ecgl.common.diffuselayer.main\n\n albedocolor *= albedotexel;\n\n float m = metalness;\n\n#ifdef metalnessmap_enabled\n float m2 = texture2d(metalnessmap, v_detailtexcoord)[metalness_chanel];\n m = clamp(m2 + (m - 0.5) * 2.0, 0.0, 1.0);\n#endif\n\n vec3 basecolor = albedocolor.rgb;\n albedocolor.rgb = basecolor * (1.0 - m);\n vec3 specfactor = mix(vec3(0.04), basecolor, m);\n\n float g = 1.0 - roughness;\n\n#ifdef roughnessmap_enabled\n float g2 = 1.0 - texture2d(roughnessmap, v_detailtexcoord)[roughness_chanel];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n#endif\n\n vec3 n = v_normal;\n\n#ifdef double_sided\n if (dot(n, v) < 0.0) {\n n = -n;\n }\n#endif\n\n float ambientfactor = 1.0;\n\n#ifdef bumpmap_enabled\n n = bumpnormal(v_worldposition, v_normal, n);\n ambientfactor = dot(v_normal, n);\n#endif\n\n@import ecgl.common.normalmap.fragmentmain\n\n vec3 n2 = vec3(n.x, n[normal_up_axis], n[normal_front_axis]);\n\n vec3 diffuseterm = vec3(0.0);\n vec3 specularterm = vec3(0.0);\n\n float ndv = clamp(dot(n, v), 0.0, 1.0);\n vec3 fresnelterm = f_schlick(ndv, specfactor);\n\n @import ecgl.common.ssaomap.main\n\n#ifdef ambient_light_count\n for(int _idx_ = 0; _idx_ < ambient_light_count; _idx_++)\n {{\n diffuseterm += ambientlightcolor[_idx_] * ambientfactor * ao;\n }}\n#endif\n\n#ifdef ambient_sh_light_count\n for(int _idx_ = 0; _idx_ < ambient_sh_light_count; _idx_++)\n {{\n diffuseterm += calcambientshlight(_idx_, n2) * ambientshlightcolor[_idx_] * ao;\n }}\n#endif\n\n#ifdef directional_light_count\n#if defined(directional_light_shadowmap_count)\n float shadowcontribsdir[directional_light_count];\n if(shadowenabled)\n {\n computeshadowofdirectionallights(v_worldposition, shadowcontribsdir);\n }\n#endif\n for(int _idx_ = 0; _idx_ < directional_light_count; _idx_++)\n {{\n vec3 l = -directionallightdirection[_idx_];\n vec3 lc = directionallightcolor[_idx_];\n\n vec3 h = normalize(l + v);\n float ndl = clamp(dot(n, normalize(l)), 0.0, 1.0);\n float ndh = clamp(dot(n, h), 0.0, 1.0);\n\n float shadowcontrib = 1.0;\n#if defined(directional_light_shadowmap_count)\n if (shadowenabled)\n {\n shadowcontrib = shadowcontribsdir[_idx_];\n }\n#endif\n\n vec3 li = lc * ndl * shadowcontrib;\n\n diffuseterm += li;\n specularterm += li * fresnelterm * d_phong(g, ndh);\n }}\n#endif\n\n\n#ifdef ambient_cubemap_light_count\n vec3 l = reflect(-v, n);\n l = vec3(l.x, l[normal_up_axis], l[normal_front_axis]);\n float rough2 = clamp(1.0 - g, 0.0, 1.0);\n float bias2 = rough2 * 5.0;\n vec2 brdfparam2 = texture2d(ambientcubemaplightbrdflookup[0], vec2(rough2, ndv)).xy;\n vec3 envweight2 = specfactor * brdfparam2.x + brdfparam2.y;\n vec3 envtexel2;\n for(int _idx_ = 0; _idx_ < ambient_cubemap_light_count; _idx_++)\n {{\n envtexel2 = rgbmdecode(texturecubelodext(ambientcubemaplightcubemap[_idx_], l, bias2), 8.12);\n specularterm += ambientcubemaplightcolor[_idx_] * envtexel2 * envweight2 * ao;\n }}\n#endif\n\n gl_fragcolor.rgb = albedocolor.rgb * diffuseterm + specularterm;\n gl_fragcolor.a = albedocolor.a;\n\n#ifdef atmosphere_enabled\n float atmointensity = pow(1.0 - dot(v_normal, (viewtranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowpower);\n gl_fragcolor.rgb += glowcolor * atmointensity;\n#endif\n\n#ifdef srgb_encode\n gl_fragcolor = lineartosrgb(gl_fragcolor);\n#endif\n\n @import ecgl.common.emissivelayer.main\n\n @import ecgl.common.wireframe.fragmentmain\n}\n\n@end"),xe.import("@export ecgl.hatching.vertex\n\n@import ecgl.realistic.vertex\n\n@end\n\n\n@export ecgl.hatching.fragment\n\n#define normal_up_axis 1\n#define normal_front_axis 2\n\n@import ecgl.common.uv.fragmentheader\n\nvarying vec3 v_normal;\nvarying vec3 v_worldposition;\n\nuniform vec4 color : [0.0, 0.0, 0.0, 1.0];\nuniform vec4 papercolor : [1.0, 1.0, 1.0, 1.0];\n\nuniform mat4 viewinverse : viewinverse;\n\n#ifdef ambient_light_count\n@import clay.header.ambient_light\n#endif\n#ifdef ambient_sh_light_count\n@import clay.header.ambient_sh_light\n#endif\n\n#ifdef directional_light_count\n@import clay.header.directional_light\n#endif\n\n#ifdef vertex_color\nvarying vec4 v_color;\n#endif\n\n\n@import ecgl.common.ssaomap.header\n\n@import ecgl.common.bumpmap.header\n\n@import clay.util.srgb\n\n@import ecgl.common.wireframe.fragmentheader\n\n@import clay.plugin.compute_shadow_map\n\nuniform sampler2d hatch1;\nuniform sampler2d hatch2;\nuniform sampler2d hatch3;\nuniform sampler2d hatch4;\nuniform sampler2d hatch5;\nuniform sampler2d hatch6;\n\nfloat shade(in float tone) {\n vec4 c = vec4(1. ,1., 1., 1.);\n float step = 1. / 6.;\n vec2 uv = v_detailtexcoord;\n if (tone <= step / 2.0) {\n c = mix(vec4(0.), texture2d(hatch6, uv), 12. * tone);\n }\n else if (tone <= step) {\n c = mix(texture2d(hatch6, uv), texture2d(hatch5, uv), 6. * tone);\n }\n if(tone > step && tone <= 2. * step){\n c = mix(texture2d(hatch5, uv), texture2d(hatch4, uv) , 6. * (tone - step));\n }\n if(tone > 2. * step && tone <= 3. * step){\n c = mix(texture2d(hatch4, uv), texture2d(hatch3, uv), 6. * (tone - 2. * step));\n }\n if(tone > 3. * step && tone <= 4. * step){\n c = mix(texture2d(hatch3, uv), texture2d(hatch2, uv), 6. * (tone - 3. * step));\n }\n if(tone > 4. * step && tone <= 5. * step){\n c = mix(texture2d(hatch2, uv), texture2d(hatch1, uv), 6. * (tone - 4. * step));\n }\n if(tone > 5. * step){\n c = mix(texture2d(hatch1, uv), vec4(1.), 6. * (tone - 5. * step));\n }\n\n return c.r;\n}\n\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n\nvoid main()\n{\n#ifdef srgb_decode\n vec4 inkcolor = srgbtolinear(color);\n#else\n vec4 inkcolor = color;\n#endif\n\n#ifdef vertex_color\n #ifdef srgb_decode\n inkcolor *= srgbtolinear(v_color);\n #else\n inkcolor *= v_color;\n #endif\n#endif\n\n vec3 n = v_normal;\n#ifdef double_sided\n vec3 eyepos = viewinverse[3].xyz;\n vec3 v = normalize(eyepos - v_worldposition);\n\n if (dot(n, v) < 0.0) {\n n = -n;\n }\n#endif\n\n float tone = 0.0;\n\n float ambientfactor = 1.0;\n\n#ifdef bumpmap_enabled\n n = bumpnormal(v_worldposition, v_normal, n);\n ambientfactor = dot(v_normal, n);\n#endif\n\n vec3 n2 = vec3(n.x, n[normal_up_axis], n[normal_front_axis]);\n\n @import ecgl.common.ssaomap.main\n\n#ifdef ambient_light_count\n for(int i = 0; i < ambient_light_count; i++)\n {\n tone += dot(ambientlightcolor[i], w) * ambientfactor * ao;\n }\n#endif\n#ifdef ambient_sh_light_count\n for(int _idx_ = 0; _idx_ < ambient_sh_light_count; _idx_++)\n {{\n tone += dot(calcambientshlight(_idx_, n2) * ambientshlightcolor[_idx_], w) * ao;\n }}\n#endif\n#ifdef directional_light_count\n#if defined(directional_light_shadowmap_count)\n float shadowcontribsdir[directional_light_count];\n if(shadowenabled)\n {\n computeshadowofdirectionallights(v_worldposition, shadowcontribsdir);\n }\n#endif\n for(int i = 0; i < directional_light_count; i++)\n {\n vec3 lightdirection = -directionallightdirection[i];\n float lighttone = dot(directionallightcolor[i], w);\n\n float shadowcontrib = 1.0;\n#if defined(directional_light_shadowmap_count)\n if (shadowenabled)\n {\n shadowcontrib = shadowcontribsdir[i];\n }\n#endif\n\n float ndl = dot(n, normalize(lightdirection)) * shadowcontrib;\n\n tone += lighttone * clamp(ndl, 0.0, 1.0);\n }\n#endif\n\n gl_fragcolor = mix(inkcolor, papercolor, shade(clamp(tone, 0.0, 1.0)));\n }\n@end\n"),xe.import("@export ecgl.sm.depth.vertex\n\nuniform mat4 worldviewprojection : worldviewprojection;\n\nattribute vec3 position : position;\nattribute vec2 texcoord : texcoord_0;\n\n#ifdef vertex_animation\nattribute vec3 prevposition;\nuniform float percent : 1.0;\n#endif\n\nvarying vec4 v_viewposition;\nvarying vec2 v_texcoord;\n\nvoid main(){\n\n#ifdef vertex_animation\n vec3 pos = mix(prevposition, position, percent);\n#else\n vec3 pos = position;\n#endif\n\n v_viewposition = worldviewprojection * vec4(pos, 1.0);\n gl_position = v_viewposition;\n\n v_texcoord = texcoord;\n\n}\n@end\n\n\n\n@export ecgl.sm.depth.fragment\n\n@import clay.sm.depth.fragment\n\n@end");var wa=vi.prototype.addtoscene,ja=vi.prototype.removefromscene;vi.prototype.addtoscene=function(e){if(wa.call(this,e),this.__zr){var t=this.__zr;e.traverse((function(e){e.__zr=t,e.addanimatorstozr&&e.addanimatorstozr(t)}))}},vi.prototype.removefromscene=function(e){ja.call(this,e),e.traverse((function(e){var t=e.__zr;e.__zr=null,t&&e.removeanimatorsfromzr&&e.removeanimatorsfromzr(t)}))},le.prototype.settextureimage=function(e,t,r,i){if(this.shader){var n,a=r.getzr(),o=this;return o.autoupdatetexturestatus=!1,o.disabletexture(e),!(s=t)||"none"===s||(n=xa.loadtexture(t,r,i,(function(t){o.enabletexture(e),a&&a.refresh()})),o.set(e,n)),n}var s};var xa={};xa.renderer=ut,xa.node=sr,xa.mesh=sr,xa.shader=xe,xa.material=le,xa.texture=wr,xa.texture2d=dr,xa.geometry=vr,xa.spheregeometry=en,xa.planegeometry=ki,xa.cubegeometry=wi,xa.ambientlight=cn,xa.directionallight=dn,xa.pointlight=ln,xa.spotlight=pn,xa.perspectivecamera=ei,xa.orthographiccamera=un,xa.vector2=_e,xa.vector3=vt,xa.vector4=rn,xa.quaternion=qt,xa.matrix2=gn,xa.matrix2d=hn,xa.matrix3=jn,xa.matrix4=ht,xa.plane=$r,xa.ray=mt,xa.boundingbox=ir,xa.frustum=si;var qa=null;function za(e){return math.pow(2,math.round(math.log(e)/math.ln2))}function ya(e){if((e.wraps===wr.repeat||e.wrapt===wr.repeat)&&e.image){var t=za(e.width),r=za(e.height);if(t!==e.width||r!==e.height){var i=document.createelement("canvas");i.width=t,i.height=r,i.getcontext("2d").drawimage(e.image,0,0,t,r),e.image=i}}}xa.loadtexture=function(e,t,r,i){"function"==typeof r&&(i=r,r={}),r=r||{};for(var n=object.keys(r).sort(),a="",o=0;o3?t[3]=e[3]:t[3]=1,t):((t=i.color.parse(e||"#000",t)||[0,0,0,0])[0]/=255,t[1]/=255,t[2]/=255,t)},xa.directionfromalphabeta=function(e,t){var r=e/180*math.pi+math.pi/2,i=-t/180*math.pi+math.pi/2,n=[],a=math.sin(r);return n[0]=a*math.cos(i),n[1]=-math.cos(r),n[2]=a*math.sin(i),n},xa.getshadowresolution=function(e){var t=1024;switch(e){case"low":t=512;break;case"medium":break;case"high":t=2048;break;case"ultra":t=4096}return t},xa.common_shaders=["lambert","color","realistic","hatching","shadow"],xa.createshader=function(e){"ecgl.shadow"===e&&(e="ecgl.displayshadow");var t=xe.source(e+".vertex"),r=xe.source(e+".fragment");t||console.error("vertex shader of '%s' not exits",e),r||console.error("fragment shader of '%s' not exits",e);var i=new xe(t,r);return i.name=e,i},xa.creatematerial=function(e,t){t instanceof array||(t=[t]);var r=xa.createshader(e),i=new le({shader:r});return t.foreach((function(e){"string"==typeof e&&i.define(e)})),i},xa.setmaterialfrommodel=function(e,t,r,i){t.autoupdatetexturestatus=!1;var n=r.getmodel(e+"material"),a=n.get("detailtexture"),o=mn(n.get("texturetiling"),1),s=mn(n.get("textureoffset"),0);"number"==typeof o&&(o=[o,o]),"number"==typeof s&&(s=[s,s]);var l=o[0]>1||o[1]>1?xa.texture.repeat:xa.texture.clamp_to_edge,h={anisotropic:8,wraps:l,wrapt:l};if("realistic"===e){var u=n.get("roughness"),c=n.get("metalness");null!=c?isnan(c)&&(t.settextureimage("metalnessmap",c,i,h),c=mn(n.get("metalnessadjust"),.5)):c=0,null!=u?isnan(u)&&(t.settextureimage("roughnessmap",u,i,h),u=mn(n.get("roughnessadjust"),.5)):u=.5;var d=n.get("normaltexture");t.settextureimage("detailmap",a,i,h),t.settextureimage("normalmap",d,i,h),t.set({roughness:u,metalness:c,detailuvrepeat:o,detailuvoffset:s})}else if("lambert"===e)t.settextureimage("detailmap",a,i,h),t.set({detailuvrepeat:o,detailuvoffset:s});else if("color"===e)t.settextureimage("detailmap",a,i,h),t.set({detailuvrepeat:o,detailuvoffset:s});else if("hatching"===e){var f=n.get("hatchingtextures")||[];f.length;for(var p=0;p<6;p++)t.settextureimage("hatch"+(p+1),f[p],i,{anisotropic:8,wraps:xa.texture.repeat,wrapt:xa.texture.repeat});t.set({detailuvrepeat:o,detailuvoffset:s})}},xa.updatevertexanimation=function(e,t,r,i){var n=i.get("animation"),a=i.get("animationdurationupdate"),o=i.get("animationeasingupdate"),s=r.shadowdepthmaterial;if(n&&t&&a>0&&t.geometry.vertexcount===r.geometry.vertexcount){r.material.define("vertex","vertex_animation"),r.ignoreprez=!0,s&&s.define("vertex","vertex_animation");for(var l=0;l=0&&this._viewstodispose.splice(t,1),this.views.push(e),e.layer=this;var r=this.zr;e.scene.traverse((function(e){e.__zr=r,e.addanimatorstozr&&e.addanimatorstozr(r)}))}},ja.prototype.removeview=function(e){if(e.layer===this){var t=this.views.indexof(e);t>=0&&(this.views.splice(t,1),e.scene.traverse($a,this),e.layer=null,this._viewstodispose.push(e))}},ja.prototype.removeviewsall=function(){this.views.foreach((function(e){e.scene.traverse($a,this),e.layer=null,this._viewstodispose.push(e)}),this),this.views.length=0},ja.prototype.resize=function(e,t){this.renderer.resize(e,t)},ja.prototype.clear=function(){var e=this.renderer.gl,t=this._backgroundcolor||[0,0,0,0];e.clearcolor(t[0],t[1],t[2],t[3]),e.depthmask(!0),e.colormask(!0,!0,!0,!0),e.clear(e.depth_buffer_bit|e.color_buffer_bit)},ja.prototype.cleardepth=function(){var e=this.renderer.gl;e.clear(e.depth_buffer_bit)},ja.prototype.clearcolor=function(){var e=this.renderer.gl;e.clearcolor(0,0,0,0),e.clear(e.color_buffer_bit)},ja.prototype.needsrefresh=function(){this.zr.refresh()},ja.prototype.refresh=function(e){this._backgroundcolor=e?ka.parsecolor(e):[0,0,0,0],this.renderer.clearcolor=this._backgroundcolor;for(var t=0;t20)){e=e.event;var i=this.pickobject(e.offsetx,e.offsety);i&&(this._dispatchevent(e.type,e,i),this._dispatchdataevent(e.type,e,i));var n=this._clicktosetfocuspoint(e);n&&n.view.setdoffocusonpoint(n.distance)&&this.zr.refresh()}}},ja.prototype._clicktosetfocuspoint=function(e){for(var t=this.renderer,r=t.viewport,i=this.views.length-1;i>=0;i--){var n=this.views[i];if(n.hasdof()&&n.containpoint(e.offsetx,e.offsety)){this._picking.scene=n.scene,this._picking.camera=n.camera,t.viewport=n.viewport;var a=this._picking.pick(e.offsetx,e.offsety,!0);if(a)return a.view=n,a}}t.viewport=r},ja.prototype.onglobalout=function(e){var t=this._hovered;t&&this._dispatchevent("mouseout",e,{target:t.target})},ja.prototype.pickobject=function(e,t){for(var r=[],i=this.renderer,n=i.viewport,a=0;a=0&&(c.dataindex=this._lastdataindex,c.seriesindex=this._lastseriesindex,this.zr.handler.dispatchtoelement(u,"mouseout",t)),l=!0):null!=s&&s!==this._lasteventdata&&(null!=this._lasteventdata&&(c.eventdata=this._lasteventdata,this.zr.handler.dispatchtoelement(u,"mouseout",t)),l=!0),this._lasteventdata=s,this._lastdataindex=a,this._lastseriesindex=o),c.eventdata=s,c.dataindex=a,c.seriesindex=o,(null!=s||parseint(a,10)>=0&&parseint(o,10)>=0)&&(this.zr.handler.dispatchtoelement(u,e,t),l&&this.zr.handler.dispatchtoelement(u,"mouseover",t))},ja.prototype._dispatchtoview=function(e,t){for(var r=0;re&&o=0&&(function(e){so(e,"itemstyle"),so(e,"linestyle"),so(e,"areastyle"),so(e,"label")}(t),"mapbox"===t.coordinatesystem&&(t.coordinatesystem="mapbox3d",e.mapbox3d=e.mapbox))})),lo(e.xaxis3d),lo(e.yaxis3d),lo(e.zaxis3d),lo(e.grid3d),so(e.geo3d)}));const uo={defaultoption:{viewcontrol:{projection:"perspective",autorotate:!1,autorotatedirection:"cw",autorotatespeed:10,autorotateafterstill:3,damping:.8,rotatesensitivity:1,zoomsensitivity:1,pansensitivity:1,panmousebutton:"middle",rotatemousebutton:"left",distance:150,mindistance:40,maxdistance:400,orthographicsize:150,maxorthographicsize:400,minorthographicsize:20,center:[0,0,0],alpha:0,beta:0,minalpha:-90,maxalpha:90}},setview:function(e){e=e||{},this.option.viewcontrol=this.option.viewcontrol||{},null!=e.alpha&&(this.option.viewcontrol.alpha=e.alpha),null!=e.beta&&(this.option.viewcontrol.beta=e.beta),null!=e.distance&&(this.option.viewcontrol.distance=e.distance),null!=e.center&&(this.option.viewcontrol.center=e.center)}},co={defaultoption:{posteffect:{enable:!1,bloom:{enable:!0,intensity:.1},depthoffield:{enable:!1,focalrange:20,focaldistance:50,blurradius:10,fstop:2.8,quality:"medium"},screenspaceambientocclusion:{enable:!1,radius:2,quality:"medium",intensity:1},screenspacereflection:{enable:!1,quality:"medium",maxroughness:.8},colorcorrection:{enable:!0,exposure:0,brightness:0,contrast:1,saturation:1,lookuptexture:""},edge:{enable:!1},fxaa:{enable:!1}},temporalsupersampling:{enable:"auto"}}},fo={defaultoption:{light:{main:{shadow:!1,shadowquality:"high",color:"#fff",intensity:1,alpha:0,beta:0},ambient:{color:"#fff",intensity:.2},ambientcubemap:{texture:null,exposure:1,diffuseintensity:.5,specularintensity:.5}}}};var po=i.componentmodel.extend({type:"grid3d",dependencies:["xaxis3d","yaxis3d","zaxis3d"],defaultoption:{show:!0,zlevel:-10,left:0,top:0,width:"100%",height:"100%",environment:"auto",boxwidth:100,boxheight:100,boxdepth:100,axispointer:{show:!0,linestyle:{color:"rgba(0, 0, 0, 0.8)",width:1},label:{show:!0,formatter:null,margin:8,textstyle:{fontsize:14,color:"#fff",backgroundcolor:"rgba(0,0,0,0.5)",padding:3,borderradius:3}}},axisline:{show:!0,linestyle:{color:"#333",width:2,type:"solid"}},axistick:{show:!0,inside:!1,length:3,linestyle:{width:1}},axislabel:{show:!0,inside:!1,rotate:0,margin:8,textstyle:{fontsize:12}},splitline:{show:!0,linestyle:{color:["#ccc"],width:1,type:"solid"}},splitarea:{show:!1,areastyle:{color:["rgba(250,250,250,0.3)","rgba(200,200,200,0.3)"]}},light:{main:{alpha:30,beta:40},ambient:{intensity:.4}},viewcontrol:{alpha:20,beta:40,autorotate:!1,distance:200,mindistance:40,maxdistance:400}}});i.util.merge(po.prototype,uo),i.util.merge(po.prototype,co),i.util.merge(po.prototype,fo);const mo=po;function go(e,t){switch(e){case"center":case"middle":e="50%";break;case"left":case"top":e="0%";break;case"right":case"bottom":e="100%"}return"string"==typeof e?(r=e,r.replace(/^\s+|\s+$/g,"")).match(/%$/)?parsefloat(e)/100*t:parsefloat(e):null==e?nan:+e;var r}function _o(){var e="__ec_inner_"+vo++;return function(t){return t[e]||(t[e]={})}}var vo=math.round(9*math.random()),yo={};function xo(e,t,r,i,n){var a={};return function(e,t,r,i,n){r=r||yo;var a,o=t.ecmodel,s=o&&o.option.textstyle,l=function(e){for(var t;e&&e!==e.ecmodel;){var r=(e.option||yo).rich;if(r){t=t||{};for(var i=ba(r),n=0;n0&&this._notfirst?this.animateto({alpha:h,beta:u,center:c,distance:a,orthographicsize:o,easing:l.animationeasingupdate,duration:l.animationdurationupdate}):(this.setdistance(a),this.setalpha(h),this.setbeta(u),this.setcenter(c),this.setorthographicsize(o)),this._notfirst=!0,this._validateproperties()},_validateproperties:function(){},animateto:function(e){var t=this.zr,r=this,i={},n={};return null!=e.distance&&(i.distance=this.getdistance(),n.distance=e.distance),null!=e.orthographicsize&&(i.orthographicsize=this.getorthographicsize(),n.orthographicsize=e.orthographicsize),null!=e.alpha&&(i.alpha=this.getalpha(),n.alpha=e.alpha),null!=e.beta&&(i.beta=this.getbeta(),n.beta=e.beta),null!=e.center&&(i.center=this.getcenter(),n.center=e.center),this._addanimator(t.animation.animate(i).when(e.duration||1e3,n).during((function(){null!=i.alpha&&r.setalpha(i.alpha),null!=i.beta&&r.setbeta(i.beta),null!=i.distance&&r.setdistance(i.distance),null!=i.center&&r.setcenter(i.center),null!=i.orthographicsize&&r.setorthographicsize(i.orthographicsize),r._needsupdate=!0}))).start(e.easing||"linear")},stopallanimation:function(){for(var e=0;e0},_update:function(e){if(this._rotating){var t=("cw"===this.autorotatedirection?1:-1)*this.autorotatespeed/180*math.pi;this._phi-=t*e/1e3,this._needsupdate=!0}else this._rotatevelocity.len()>0&&(this._needsupdate=!0);(math.abs(this._zoomspeed)>.1||this._panvelocity.len()>0)&&(this._needsupdate=!0),this._needsupdate&&(e=math.min(e,50),this._updatedistanceorsize(e),this._updatepan(e),this._updaterotate(e),this._updatetransform(),this.getcamera().update(),this.zr&&this.zr.refresh(),this.trigger("update"),this._needsupdate=!1)},_updaterotate:function(e){var t=this._rotatevelocity;this._phi=t.y*e/20+this._phi,this._theta=t.x*e/20+this._theta,this.setalpha(this.getalpha()),this.setbeta(this.getbeta()),this._vectordamping(t,math.pow(this.damping,e/16))},_updatedistanceorsize:function(e){"perspective"===this._projection?this._setdistance(this._distance+this._zoomspeed*e/20):this._setorthosize(this._orthosize+this._zoomspeed*e/20),this._zoomspeed*=math.pow(this.damping,e/16)},_setdistance:function(e){this._distance=math.max(math.min(e,this.maxdistance),this.mindistance)},_setorthosize:function(e){this._orthosize=math.max(math.min(e,this.maxorthographicsize),this.minorthographicsize);var t=this.getcamera(),r=this._orthosize,i=r/this.viewgl.viewport.height*this.viewgl.viewport.width;t.left=-i/2,t.right=i/2,t.top=r/2,t.bottom=-r/2},_updatepan:function(e){var t=this._panvelocity,r=this._distance,i=this.getcamera(),n=i.worldtransform.y,a=i.worldtransform.x;this._center.scaleandadd(a,-t.x*r/200).scaleandadd(n,-t.y*r/200),this._vectordamping(t,0)},_updatetransform:function(){var e=this.getcamera(),t=new vt,r=this._theta+math.pi/2,i=this._phi+math.pi/2,n=math.sin(r);t.x=n*math.cos(i),t.y=-math.cos(r),t.z=n*math.sin(i),e.position.copy(this._center).scaleandadd(t,this._distance),e.rotation.identity().rotatey(-this._phi).rotatex(-this._theta)},_startcountingstill:function(){cleartimeout(this._stilltimeout);var e=this.autorotateafterstill,t=this;!isnan(e)&&e>0&&(this._stilltimeout=settimeout((function(){t._rotating=!0}),1e3*e))},_vectordamping:function(e,t){var r=e.len();(r*=t)<1e-4&&(r=0),e.normalize().scale(r)},_decomposetransform:function(){if(this.getcamera()){this.getcamera().updateworldtransform();var e=this.getcamera().worldtransform.z,t=math.asin(e.y),r=math.atan2(e.x,e.z);this._theta=t,this._phi=-r,this.setbeta(this.getbeta()),this.setalpha(this.getalpha()),this.getcamera().aspect?this._setdistance(this.getcamera().position.dist(this._center)):this._setorthosize(this.getcamera().top-this.getcamera().bottom)}},_mousedownhandler:function(e){if(!e.target&&!this._isanimating()){var t=e.offsetx,r=e.offsety;this.viewgl&&!this.viewgl.containpoint(t,r)||(this.zr.on("mousemove",this._mousemovehandler),this.zr.on("mouseup",this._mouseuphandler),e.event.targettouches?1===e.event.targettouches.length&&(this._mode="rotate"):e.event.button===ao[this.rotatemousebutton]?this._mode="rotate":e.event.button===ao[this.panmousebutton]?this._mode="pan":this._mode="",this._rotatevelocity.set(0,0),this._rotating=!1,this.autorotate&&this._startcountingstill(),this._mousex=e.offsetx,this._mousey=e.offsety)}},_mousemovehandler:function(e){if(!(e.target&&e.target.__isgltozrproxy||this._isanimating())){var t=eo(this.pansensitivity),r=eo(this.rotatesensitivity);"rotate"===this._mode?(this._rotatevelocity.y=(e.offsetx-this._mousex)/this.zr.getheight()*2*r[0],this._rotatevelocity.x=(e.offsety-this._mousey)/this.zr.getwidth()*2*r[1]):"pan"===this._mode&&(this._panvelocity.x=(e.offsetx-this._mousex)/this.zr.getwidth()*t[0]*400,this._panvelocity.y=(-e.offsety+this._mousey)/this.zr.getheight()*t[1]*400),this._mousex=e.offsetx,this._mousey=e.offsety,e.event.preventdefault()}},_mousewheelhandler:function(e){if(!this._isanimating()){var t=e.event.wheeldelta||-e.event.detail;this._zoomhandler(e,t)}},_pinchhandler:function(e){this._isanimating()||(this._zoomhandler(e,e.pinchscale>1?1:-1),this._mode="")},_zoomhandler:function(e,t){if(0!==t){var r,i=e.offsetx,n=e.offsety;this.viewgl&&!this.viewgl.containpoint(i,n)||(r="perspective"===this._projection?math.max(math.max(math.min(this._distance-this.mindistance,this.maxdistance-this._distance))/20,.5):math.max(math.max(math.min(this._orthosize-this.minorthographicsize,this.maxorthographicsize-this._orthosize))/20,.5),this._zoomspeed=(t>0?-1:1)*r*this.zoomsensitivity,this._rotating=!1,this.autorotate&&"rotate"===this._mode&&this._startcountingstill(),e.event.preventdefault())}},_mouseuphandler:function(){this.zr.off("mousemove",this._mousemovehandler),this.zr.off("mouseup",this._mouseuphandler)},_isrightmousebuttonused:function(){return"right"===this.rotatemousebutton||"right"===this.panmousebutton},_contextmenuhandler:function(e){this._isrightmousebuttonused()&&e.preventdefault()},_addanimator:function(e){var t=this._animators;return t.push(e),e.done((function(){var r=t.indexof(e);r>=0&&t.splice(r,1)})),e}});object.defineproperty(co.prototype,"autorotate",{get:function(e){return this._autorotate},set:function(e){this._autorotate=e,this._rotating=e}});const do=co,lo={converttodynamicarray:function(e){e&&this.resetoffset();var t=this.attributes;for(var r in t)e||!t[r].value?t[r].value=[]:t[r].value=array.prototype.slice.call(t[r].value);e||!this.indices?this.indices=[]:this.indices=array.prototype.slice.call(this.indices)},converttotypedarray:function(){var e=this.attributes;for(var t in e)e[t].value&&e[t].value.length>0?e[t].value=new float32array(e[t].value):e[t].value=null;this.indices&&this.indices.length>0&&(this.indices=this.vertexcount>65535?new uint32array(this.indices):new uint16array(this.indices)),this.dirty()}},po={vec2:pe,vec3:qe,vec4:et,mat2:fn,mat2d:kn,mat3:dt,mat4:ye,quat:rt};var oo=po.vec3,no=[[0,0],[1,1]],io=vr.extend((function(){return{segmentscale:1,dynamic:!0,usenativeline:!0,attributes:{position:new vr.attribute("position","float",3,"position"),positionprev:new vr.attribute("positionprev","float",3),positionnext:new vr.attribute("positionnext","float",3),prevpositionprev:new vr.attribute("prevpositionprev","float",3),prevposition:new vr.attribute("prevposition","float",3),prevpositionnext:new vr.attribute("prevpositionnext","float",3),offset:new vr.attribute("offset","float",1),color:new vr.attribute("color","float",4,"color")}}}),{resetoffset:function(){this._vertexoffset=0,this._triangleoffset=0,this._itemvertexoffsets=[]},setvertexcount:function(e){var t=this.attributes;this.vertexcount!==e&&(t.position.init(e),t.color.init(e),this.usenativeline||(t.positionprev.init(e),t.positionnext.init(e),t.offset.init(e)),e>65535?this.indices instanceof uint16array&&(this.indices=new uint32array(this.indices)):this.indices instanceof uint32array&&(this.indices=new uint16array(this.indices)))},settrianglecount:function(e){this.trianglecount!==e&&(this.indices=0===e?null:this.vertexcount>65535?new uint32array(3*e):new uint16array(3*e))},_getcubiccurveapproxstep:function(e,t,r,i){return 1/(oo.dist(e,t)+oo.dist(r,t)+oo.dist(i,r)+1)*this.segmentscale},getcubiccurvevertexcount:function(e,t,r,i){var n=this._getcubiccurveapproxstep(e,t,r,i),a=math.ceil(1/n);return this.usenativeline?2*a:2*a+2},getcubiccurvetrianglecount:function(e,t,r,i){var n=this._getcubiccurveapproxstep(e,t,r,i),a=math.ceil(1/n);return this.usenativeline?0:2*a},getlinevertexcount:function(){return this.getpolylinevertexcount(no)},getlinetrianglecount:function(){return this.getpolylinetrianglecount(no)},getpolylinevertexcount:function(e){var t;return t="number"==typeof e?e:"number"!=typeof e[0]?e.length:e.length/3,this.usenativeline?2*(t-1):2*(t-1)+2},getpolylinetrianglecount:function(e){var t;return t="number"==typeof e?e:"number"!=typeof e[0]?e.length:e.length/3,this.usenativeline?0:2*math.max(t-1,0)},addcubiccurve:function(e,t,r,i,n,a){null==a&&(a=1);var o=e[0],s=e[1],l=e[2],h=t[0],u=t[1],c=t[2],d=r[0],f=r[1],p=r[2],m=i[0],g=i[1],_=i[2],v=this._getcubiccurveapproxstep(e,t,r,i),y=v*v,x=y*v,b=3*v,w=3*y,t=6*y,s=6*x,m=o-2*h+d,a=s-2*u+f,e=l-2*c+p,c=3*(h-d)-o+m,d=3*(u-f)-s+g,l=3*(c-p)-l+_,p=o,o=s,n=l,i=(h-o)*b+m*w+c*x,r=(u-s)*b+a*w+d*x,b=(c-l)*b+e*w+l*x,f=m*t+c*s,z=a*t+d*s,g=e*t+l*s,u=c*s,k=d*s,v=l*s,h=0,w=0,j=math.ceil(1/v),x=new float32array(3*(j+1)),q=(x=[],0);for(w=0;w1&&(p=i>0?math.min(p,m):math.max(p,m),o=r>0?math.min(o,g):math.max(o,g),n=b>0?math.min(n,_):math.max(n,_));return this.addpolyline(x,n,a)},addline:function(e,t,r,i){return this.addpolyline([e,t],r,i)},addpolyline:function(e,t,r,i,n){if(e.length){var a="number"!=typeof e[0];if(null==n&&(n=a?e.length:e.length/3),!(n<2)){null==i&&(i=0),null==r&&(r=1),this._itemvertexoffsets.push(this._vertexoffset);var o,s,l=(a="number"!=typeof e[0])?"number"!=typeof t[0]:t.length/4===n,h=this.attributes.position,u=this.attributes.positionprev,c=this.attributes.positionnext,d=this.attributes.color,f=this.attributes.offset,p=this.indices,m=this._vertexoffset;r=math.max(r,.01);for(var g=i;g1&&(h.copy(m,m-1),d.copy(m,m-1),m++):(g0&&(c.set(m-2,o),c.set(m-1,o)),h.set(m,o),h.set(m+1,o),d.set(m,s),d.set(m+1,s),f.set(m,r/2),f.set(m+1,-r/2),m+=2),this.usenativeline)d.set(m,s),h.set(m,o),m++;else if(g>0){var y=3*this._triangleoffset;(p=this.indices)[y]=m-4,p[y+1]=m-3,p[y+2]=m-2,p[y+3]=m-3,p[y+4]=m-1,p[y+5]=m-2,this._triangleoffset+=2}}if(!this.usenativeline){var x=this._vertexoffset,b=this._vertexoffset+2*n;u.copy(x,x+2),u.copy(x+1,x+3),c.copy(b-1,b-3),c.copy(b-2,b-4)}return this._vertexoffset=m,this._vertexoffset}}},setitemcolor:function(e,t){for(var r=this._itemvertexoffsets[e],i=eo&&(n=this._x=0,a+=this._rowheight+l,this._y=a,this._rowheight=0),this._x+=t+l,this._rowheight=math.max(this._rowheight,r),a+r+l>s)return null;e.x+=this.offsetx*this.dpr+n,e.y+=this.offsety*this.dpr+a,this._zr.add(e);var h=[this.offsetx/this.width,this.offsety/this.height];return[[n/o+h[0],a/s+h[1]],[(n+t)/o+h[0],(a+r)/s+h[1]]]},_fitelement:function(e,t,r){var i=e.getboundingrect(),n=t/i.width,a=r/i.height;e.x=-i.x*n,e.y=-i.y*a,e.scalex=n,e.scaley=a,e.update()}},fo.prototype={clear:function(){for(var e=0;e=e)){var n=(r+this._nodewidth)*this._dpr,a=(i+this._nodeheight)*this._dpr;try{this._zr.resize({width:n,height:a})}catch(e){this._canvas.width=n,this._canvas.height=a}var o=new bo(this._zr,r,i,this._nodewidth,this._nodeheight,this._gap,this._dpr);return this._textureatlasnodes.push(o),o}},add:function(e,t,r){if(this._coords[e.id])return this._coords[e.id];var i=this._getcurrentnode().add(e,t,r);if(!i){var n=this._expand();if(!n)return;i=n.add(e,t,r)}return this._coords[e.id]=i,i},getcoordsscale:function(){var e=this._dpr;return[this._nodewidth/this._canvas.width*e,this._nodeheight/this._canvas.height*e]},getcoords:function(e){return this._coords[e]},dispose:function(){this._zr.dispose()}};const zo=fo;function go(){}go.prototype={constructor:go,setscene:function(e){this._scene=e,this._skybox&&this._skybox.attachscene(this._scene)},initlight:function(e){this._lightroot=e,this.mainlight=new ka.directionallight({shadowbias:.005}),this.ambientlight=new ka.ambientlight,e.add(this.mainlight),e.add(this.ambientlight)},dispose:function(){this._lightroot&&(this._lightroot.remove(this.mainlight),this._lightroot.remove(this.ambientlight))},updatelight:function(e){var t=this.mainlight,r=this.ambientlight,i=e.getmodel("light"),n=i.getmodel("main"),a=i.getmodel("ambient");t.intensity=n.get("intensity"),r.intensity=a.get("intensity"),t.color=ka.parsecolor(n.get("color")).slice(0,3),r.color=ka.parsecolor(a.get("color")).slice(0,3);var o=n.get("alpha")||0,s=n.get("beta")||0;t.position.setarray(ka.directionfromalphabeta(o,s)),t.lookat(ka.vector3.zero),t.castshadow=n.get("shadow"),t.shadowresolution=ka.getshadowresolution(n.get("shadowquality"))},updateambientcubemap:function(e,t,r){var i=t.getmodel("light.ambientcubemap"),n=i.get("texture");if(n){this._cubemaplightscache=this._cubemaplightscache||{};var a=this._cubemaplightscache[n];if(!a){var o=this;a=this._cubemaplightscache[n]=ka.createambientcubemap(i.option,e,r,(function(){o._isskyboxfromambientcubemap&&o._skybox.setenvironmentmap(a.specular.cubemap),r.getzr().refresh()}))}this._lightroot.add(a.diffuse),this._lightroot.add(a.specular),this._currentcubemaplights=a}else this._currentcubemaplights&&(this._lightroot.remove(this._currentcubemaplights.diffuse),this._lightroot.remove(this._currentcubemaplights.specular),this._currentcubemaplights=null)},updateskybox:function(e,t,r){var n=t.get("environment"),a=this,o=(a._skybox=a._skybox||new ji,a._skybox);if(n&&"none"!==n)if("auto"===n)if(this._isskyboxfromambientcubemap=!0,this._currentcubemaplights){var s=this._currentcubemaplights.specular.cubemap;o.setenvironmentmap(s),this._scene&&o.attachscene(this._scene),o.material.set("lod",3)}else this._skybox&&this._skybox.detachscene();else if("object"==typeof n&&n.colorstops||"string"==typeof n&&i.color.parse(n)){this._isskyboxfromambientcubemap=!1;var l=new ka.texture2d({anisotropic:8,flipy:!1});o.setenvironmentmap(l);var h=l.image=document.createelement("canvas");h.width=h.height=16;var u=h.getcontext("2d"),c=new i.graphic.rect({shape:{x:0,y:0,width:16,height:16},style:{fill:n}});i.innerdrawelementoncanvas(u,c),o.attachscene(this._scene)}else this._isskyboxfromambientcubemap=!1,l=ka.loadtexture(n,r,{anisotropic:8,flipy:!1}),o.setenvironmentmap(l),o.attachscene(this._scene);else this._skybox&&this._skybox.detachscene(this._scene),this._skybox=null;var d=t.coordinatesystem;if(this._skybox)if(!d||!d.viewgl||"auto"===n||n.match&&n.match(/.hdr$/))this._skybox.material.undefine("fragment","srgb_decode");else{var f=d.viewgl.islinearspace()?"define":"undefine";this._skybox.material[f]("fragment","srgb_decode")}}};const uo=go;var ko=po.vec3,vo=vr.extend((function(){return{segmentscale:1,usenativeline:!0,attributes:{position:new vr.attribute("position","float",3,"position"),normal:new vr.attribute("normal","float",3,"normal"),color:new vr.attribute("color","float",4,"color")}}}),{resetoffset:function(){this._vertexoffset=0,this._faceoffset=0},setquadcount:function(e){var t=this.attributes,r=this.getquadvertexcount()*e,i=this.getquadtrianglecount()*e;this.vertexcount!==r&&(t.position.init(r),t.normal.init(r),t.color.init(r)),this.trianglecount!==i&&(this.indices=r>65535?new uint32array(3*i):new uint16array(3*i))},getquadvertexcount:function(){return 4},getquadtrianglecount:function(){return 2},addquad:function(){var e=ko.create(),t=ko.create(),r=ko.create(),i=[0,3,1,3,2,1];return function(n,a){var o=this.attributes.position,s=this.attributes.normal,l=this.attributes.color;ko.sub(e,n[1],n[0]),ko.sub(t,n[2],n[1]),ko.cross(r,e,t),ko.normalize(r,r);for(var h=0;h<4;h++)o.set(this._vertexoffset+h,n[h]),l.set(this._vertexoffset+h,a),s.set(this._vertexoffset+h,r);var u=3*this._faceoffset;for(h=0;h<6;h++)this.indices[u+h]=i[h]+this._vertexoffset;this._vertexoffset+=4,this._faceoffset+=2}}()});i.util.defaults(vo.prototype,lo);const ho=vo;var wo=mn,jo={x:0,y:2,z:1};function xo(e,t,r){this.rootnode=new ka.node;var i=new ka.mesh({geometry:new ro({usenativeline:!1}),material:t,castshadow:!1,ignorepicking:!0,$ignorepicking:!0,renderorder:1}),n=new ka.mesh({geometry:new ho,material:r,castshadow:!1,culling:!1,ignorepicking:!0,$ignorepicking:!0,renderorder:0});this.rootnode.add(n),this.rootnode.add(i),this.faceinfo=e,this.plane=new ka.plane,this.linesmesh=i,this.quadsmesh=n}xo.prototype.update=function(e,t,r){var i=e.coordinatesystem,n=[i.getaxis(this.faceinfo[0]),i.getaxis(this.faceinfo[1])],a=this.linesmesh.geometry,o=this.quadsmesh.geometry;a.converttodynamicarray(!0),o.converttodynamicarray(!0),this._updatesplitlines(a,n,e,r),this._udpatesplitareas(o,n,e,r),a.converttotypedarray(),o.converttotypedarray();var s=i.getaxis(this.faceinfo[2]);!function(e,t,r,i){var n=[0,0,0],a=i<0?r.getextentmin():r.getextentmax();n[jo[r.dim]]=a,e.position.setarray(n),e.rotation.identity(),t.distance=-math.abs(a),t.normal.set(0,0,0),"x"===r.dim?(e.rotation.rotatey(i*math.pi/2),t.normal.x=-i):"z"===r.dim?(e.rotation.rotatex(-i*math.pi/2),t.normal.y=-i):(i>0&&e.rotation.rotatey(math.pi),t.normal.z=-i)}(this.rootnode,this.plane,s,this.faceinfo[3])},xo.prototype._updatesplitlines=function(e,t,r,n){var a=n.getdevicepixelratio();t.foreach((function(n,o){var s=n.model,l=t[1-o].getextent();if(!n.scale.isblank()){var h=s.getmodel("splitline",r.getmodel("splitline"));if(h.get("show")){var u=h.getmodel("linestyle"),c=u.get("color"),d=wo(u.get("opacity"),1),f=wo(u.get("width"),1);c=i.util.isarray(c)?c:[c];for(var p=n.gettickscoords({tickmodel:h}),m=0,g=0;g65535?new uint32array(3*r):new uint16array(3*r))},setspritealign:function(e,t,r,i,n){var a,o,s,l;switch(null==r&&(r="left"),null==i&&(i="top"),n=n||0,r){case"left":a=n,s=t[0]+n;break;case"center":case"middle":a=-t[0]/2,s=t[0]/2;break;case"right":a=-t[0]-n,s=-n}switch(i){case"bottom":o=n,l=t[1]+n;break;case"middle":o=-t[1]/2,l=t[1]/2;break;case"top":o=-t[1]-n,l=-n}var h=4*e,u=this.attributes.offset;u.set(h,[a,l]),u.set(h+1,[s,l]),u.set(h+2,[s,o]),u.set(h+3,[a,o])},addsprite:function(e,t,r,i,n,a){var o=this._vertexoffset;this.setsprite(this._vertexoffset/4,e,t,r,i,n,a);for(var s=0;s 0.0) {\n currproj = clipnear(currproj, nextproj);\n }\n else if (prevproj.w > 0.0) {\n currproj = clipnear(currproj, prevproj);\n }\n }\n\n vec2 prevscreen = (prevproj.xy / abs(prevproj.w) + 1.0) * 0.5 * viewport.zw;\n vec2 currscreen = (currproj.xy / abs(currproj.w) + 1.0) * 0.5 * viewport.zw;\n vec2 nextscreen = (nextproj.xy / abs(nextproj.w) + 1.0) * 0.5 * viewport.zw;\n\n vec2 dir;\n float len = offset;\n if (position == positionprev) {\n dir = normalize(nextscreen - currscreen);\n }\n else if (position == positionnext) {\n dir = normalize(currscreen - prevscreen);\n }\n else {\n vec2 dira = normalize(currscreen - prevscreen);\n vec2 dirb = normalize(nextscreen - currscreen);\n\n vec2 tanget = normalize(dira + dirb);\n\n float miter = 1.0 / max(dot(tanget, dira), 0.5);\n len *= miter;\n dir = tanget;\n }\n\n dir = vec2(-dir.y, dir.x) * len;\n currscreen += dir;\n\n currproj.xy = (currscreen / viewport.zw - 0.5) * 2.0 * abs(currproj.w);\n@end\n\n\n@export ecgl.meshlines3d.vertex\n\nattribute vec3 position: position;\nattribute vec3 positionprev;\nattribute vec3 positionnext;\nattribute float offset;\nattribute vec4 a_color : color;\n\n#ifdef vertex_animation\nattribute vec3 prevposition;\nattribute vec3 prevpositionprev;\nattribute vec3 prevpositionnext;\nuniform float percent : 1.0;\n#endif\n\nuniform mat4 worldviewprojection : worldviewprojection;\nuniform vec4 viewport : viewport;\nuniform float near : near;\n\nvarying vec4 v_color;\n\n@import ecgl.common.wireframe.vertexheader\n\n@import ecgl.lines3d.clipnear\n\nvoid main()\n{\n @import ecgl.lines3d.expandline\n\n gl_position = currproj;\n\n v_color = a_color;\n\n @import ecgl.common.wireframe.vertexmain\n}\n@end\n\n\n@export ecgl.meshlines3d.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nvarying vec4 v_color;\n\n@import ecgl.common.wireframe.fragmentheader\n\n@import clay.util.srgb\n\nvoid main()\n{\n#ifdef srgb_decode\n gl_fragcolor = srgbtolinear(color * v_color);\n#else\n gl_fragcolor = color * v_color;\n#endif\n\n @import ecgl.common.wireframe.fragmentmain\n}\n\n@end";var ns=mn;ka.shader.import(is);var as={x:0,y:2,z:1};const os=i.componentview.extend({type:"grid3d",__ecgl__:!0,init:function(e,t){var r=new ka.material({shader:ka.createshader("ecgl.color"),depthmask:!1,transparent:!0}),i=new ka.material({shader:ka.createshader("ecgl.meshlines3d"),depthmask:!1,transparent:!0});r.define("fragment","double_sided"),r.define("both","vertex_color"),this.groupgl=new ka.node,this._control=new do({zr:t.getzr()}),this._control.init(),this._faces=[["y","z","x",-1,"left"],["y","z","x",1,"right"],["x","y","z",-1,"bottom"],["x","y","z",1,"top"],["x","z","y",-1,"far"],["x","z","y",1,"near"]].map((function(e){var t=new qo(e,i,r);return this.groupgl.add(t.rootnode),t}),this),this._axes=["x","y","z"].map((function(e){var t=new rs(e,i);return this.groupgl.add(t.rootnode),t}),this);var n=t.getdevicepixelratio();this._axislabelsurface=new zo({width:256,height:256,devicepixelratio:n}),this._axislabelsurface.onupdate=function(){t.getzr().refresh()},this._axispointerlinemesh=new ka.mesh({geometry:new ro({usenativeline:!1}),material:i,castshadow:!1,ignorepicking:!0,renderorder:3}),this.groupgl.add(this._axispointerlinemesh),this._axispointerlabelssurface=new zo({width:128,height:128,devicepixelratio:n}),this._axispointerlabelsmesh=new qo({ignorepicking:!0,renderorder:4,castshadow:!1}),this._axispointerlabelsmesh.material.set("textureatlas",this._axispointerlabelssurface.gettexture()),this.groupgl.add(this._axispointerlabelsmesh),this._lightroot=new ka.node,this._scenehelper=new uo,this._scenehelper.initlight(this._lightroot)},render:function(e,t,r){this._model=e,this._api=r;var i=e.coordinatesystem;i.viewgl.add(this._lightroot),e.get("show")?i.viewgl.add(this.groupgl):i.viewgl.remove(this.groupgl);var n=this._control;n.setviewgl(i.viewgl);var a=e.getmodel("viewcontrol");n.setfromviewcontrolmodel(a,0),this._axislabelsurface.clear(),n.off("update"),e.get("show")&&(this._faces.foreach((function(i){i.update(e,t,r)}),this),this._axes.foreach((function(t){t.update(e,this._axislabelsurface,r)}),this)),n.on("update",this._oncamerachange.bind(this,e,r),this),this._scenehelper.setscene(i.viewgl.scene),this._scenehelper.updatelight(e),i.viewgl.setposteffect(e.getmodel("posteffect"),r),i.viewgl.settemporalsupersampling(e.getmodel("temporalsupersampling")),this._initmousehandler(e)},afterrender:function(e,t,r,i){var n=i.renderer;this._scenehelper.updateambientcubemap(n,e,r),this._scenehelper.updateskybox(n,e,r)},showaxispointer:function(e,t,r,i){this._doshowaxispointer(),this._updateaxispointer(i.value)},hideaxispointer:function(e,t,r,i){this._dohideaxispointer()},_initmousehandler:function(e){var t=e.coordinatesystem.viewgl;e.get("show")&&e.get("axispointer.show")?t.on("mousemove",this._updateaxispointeronmouseposition,this):t.off("mousemove",this._updateaxispointeronmouseposition)},_updateaxispointeronmouseposition:function(e){if(!e.target){for(var t,r=this._model.coordinatesystem,i=r.viewgl,n=i.castray(e.offsetx,e.offsety,new ka.ray),a=0;ai[1]?0:1,o=this._faces[2*r+a],s=this._faces[2*r+1-a];o.rootnode.invisible=!0,s.rootnode.invisible=!1}},_updateaxislineposition:function(){var e=this._model.coordinatesystem,t=e.getaxis("x"),r=e.getaxis("y"),i=e.getaxis("z"),n=i.getextentmax(),a=i.getextentmin(),o=t.getextentmin(),s=t.getextentmax(),l=r.getextentmax(),h=r.getextentmin(),u=this._axes[0].rootnode,c=this._axes[1].rootnode,d=this._axes[2].rootnode,f=this._faces,p=f[4].rootnode.invisible?h:l,m=f[2].rootnode.invisible?n:a,g=f[0].rootnode.invisible?o:s,_=f[2].rootnode.invisible?n:a,v=f[0].rootnode.invisible?s:o,y=f[4].rootnode.invisible?h:l;u.rotation.identity(),c.rotation.identity(),d.rotation.identity(),f[4].rootnode.invisible&&(this._axes[0].flipped=!0,u.rotation.rotatex(math.pi)),f[0].rootnode.invisible&&(this._axes[1].flipped=!0,c.rotation.rotatez(math.pi)),f[4].rootnode.invisible&&(this._axes[2].flipped=!0,d.rotation.rotatey(math.pi)),u.position.set(0,m,p),c.position.set(g,_,0),d.position.set(v,0,y),u.update(),c.update(),d.update(),this._updateaxislabelalign()},_updateaxislabelalign:function(){var e=this._control.getcamera(),t=[new ka.vector4,new ka.vector4],r=new ka.vector4;this.groupgl.getworldposition(r),r.w=1,r.transformmat4(e.viewmatrix).transformmat4(e.projectionmatrix),r.x/=r.w,r.y/=r.w,this._axes.foreach((function(i){for(var n=i.axislinecoords,a=(i.labelsmesh.geometry,0);ar.y?"bottom":"top"):(s="middle",o=u>r.x?"left":"right"),i.setspritealign(o,s,this._api)}),this)},_doshowaxispointer:function(){this._axispointerlinemesh.invisible&&(this._axispointerlinemesh.invisible=!1,this._axispointerlabelsmesh.invisible=!1,this._api.getzr().refresh())},_dohideaxispointer:function(){this._axispointerlinemesh.invisible||(this._axispointerlinemesh.invisible=!0,this._axispointerlabelsmesh.invisible=!0,this._api.getzr().refresh())},_updateaxispointer:function(e){var t=this._model.coordinatesystem,r=t.datatopoint(e),i=this._axispointerlinemesh.geometry,n=this._model.getmodel("axispointer"),a=this._api.getdevicepixelratio();function o(e){return mn(e.model.get("axispointer.show"),n.get("show"))}function s(e){var t=e.model.getmodel("axispointer",n).getmodel("linestyle"),r=ka.parsecolor(t.get("color")),i=ns(t.get("width"),1),a=ns(t.get("opacity"),1);return r[3]*=a,{color:r,linewidth:i}}i.converttodynamicarray(!0);for(var l=0;lp&&(p=y,mp&&(p=x,_=r.x&&e<=r.x+r.width&&t>=r.y&&t<=r.y+r.height},e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e.prototype.copy=function(t){e.copy(this,t)},e.prototype.plain=function(){return{x:this.x,y:this.y,width:this.width,height:this.height}},e.prototype.isfinite=function(){return isfinite(this.x)&&isfinite(this.y)&&isfinite(this.width)&&isfinite(this.height)},e.prototype.iszero=function(){return 0===this.width||0===this.height},e.create=function(t){return new e(t.x,t.y,t.width,t.height)},e.copy=function(e,t){e.x=t.x,e.y=t.y,e.width=t.width,e.height=t.height},e.applytransform=function(t,r,i){if(i){if(i[1]<1e-5&&i[1]>-1e-5&&i[2]<1e-5&&i[2]>-1e-5){var n=i[0],a=i[3],o=i[4],s=i[5];return t.x=r.x*n+o,t.y=r.y*a+s,t.width=r.width*n,t.height=r.height*a,t.width<0&&(t.x+=t.width,t.width=-t.width),void(t.height<0&&(t.y+=t.height,t.height=-t.height))}gs.x=vs.x=r.x,gs.y=ys.y=r.y,_s.x=ys.x=r.x+r.width,_s.y=vs.y=r.y+r.height,gs.transform(i),ys.transform(i),_s.transform(i),vs.transform(i),t.x=ps(gs.x,_s.x,vs.x,ys.x),t.y=ps(gs.y,_s.y,vs.y,ys.y);var l=ms(gs.x,_s.x,vs.x,ys.x),h=ms(gs.y,_s.y,vs.y,ys.y);t.width=l-t.x,t.height=h-t.y}else t!==r&&e.copy(t,r)},e}();function ts(e,t,r,i,n){var a=0,o=0;null==i&&(i=1/0),null==n&&(n=1/0);var s=0;t.eachchild((function(l,h){var u,c,d=l.getboundingrect(),f=t.childat(h+1),p=f&&f.getboundingrect();if("horizontal"===e){var m=d.width+(p?-p.x+d.x:0);(u=a+m)>i||l.newline?(a=0,u=m,o+=s+r,s=d.height):s=math.max(s,d.height)}else{var g=d.height+(p?-p.y+d.y:0);(c=o+g)>n||l.newline?(a+=s+r,o=0,c=g,s=d.width):s=math.max(s,d.width)}l.newline||(l.x=a,l.y=o,l.markredraw(),"horizontal"===e?a=u+r:o=c+r)}))}function ss(e,t,r){r=function(e){if("number"==typeof e)return[e,e,e,e];var t=e.length;return 2===t?[e[0],e[1],e[0],e[1]]:3===t?[e[0],e[1],e[2],e[1]]:e}(r||0);var i=t.width,n=t.height,a=go(e.left,i),o=go(e.top,n),s=go(e.right,i),l=go(e.bottom,n),h=go(e.width,i),u=go(e.height,n),c=r[2]+r[0],d=r[1]+r[3],f=e.aspect;switch(isnan(h)&&(h=i-s-d-a),isnan(u)&&(u=n-l-c-o),null!=f&&(isnan(h)&&isnan(u)&&(f>i/n?h=.8*i:u=.8*n),isnan(h)&&(h=f*u),isnan(u)&&(u=h/f)),isnan(a)&&(a=i-s-h-d),isnan(o)&&(o=n-l-u-c),e.left||e.right){case"center":a=i/2-h/2-r[3];break;case"right":a=i-h-d}switch(e.top||e.bottom){case"middle":case"center":o=n/2-u/2-r[0];break;case"bottom":o=n-u-c}a=a||0,o=o||0,isnan(h)&&(h=i-d-a-(s||0)),isnan(u)&&(u=n-c-o-(l||0));var p=new ws(a+r[3],o+r[0],h,u);return p.margin=r,p}wa(ts,"vertical"),wa(ts,"horizontal");var ms=function(){this._pool={},this._allocatedtextures=[]};ms.prototype={constructor:ms,get:function(e){var t=cs(e);this._pool.hasownproperty(t)||(this._pool[t]=[]);var r=this._pool[t];if(!r.length){var i=new dr(e);return this._allocatedtextures.push(i),i}return r.pop()},put:function(e){var t=cs(e);this._pool.hasownproperty(t)||(this._pool[t]=[]),this._pool[t].push(e)},clear:function(e){for(var t=0;t 0.0) {\n if (texture2d(alphamap, v_texcoord).a <= alphacutoff) {\n discard;\n }\n }\n#ifdef use_vsm\n depth = depth * 0.5 + 0.5;\n float moment1 = depth;\n float moment2 = depth * depth;\n #ifdef support_standard_derivatives\n float dx = dfdx(depth);\n float dy = dfdy(depth);\n moment2 += 0.25*(dx*dx+dy*dy);\n #endif\n gl_fragcolor = vec4(moment1, moment2, 0.0, 1.0);\n#else\n #ifdef support_standard_derivatives\n float dx = dfdx(depth);\n float dy = dfdy(depth);\n depth += sqrt(dx*dx + dy*dy) * slopescale + bias;\n #else\n depth += bias;\n #endif\n gl_fragcolor = encodefloat(depth * 0.5 + 0.5);\n#endif\n}\n@end\n@export clay.sm.debug_depth\nuniform sampler2d depthmap;\nvarying vec2 v_texcoord;\n@import clay.util.decode_float\nvoid main() {\n vec4 tex = texture2d(depthmap, v_texcoord);\n#ifdef use_vsm\n gl_fragcolor = vec4(tex.rgb, 1.0);\n#else\n float depth = decodefloat(tex);\n gl_fragcolor = vec4(depth, depth, depth, 1.0);\n#endif\n}\n@end\n@export clay.sm.distance.vertex\nuniform mat4 worldviewprojection : worldviewprojection;\nuniform mat4 world : world;\nattribute vec3 position : position;\n@import clay.chunk.skinning_header\nvarying vec3 v_worldposition;\nvoid main (){\n vec4 p = vec4(position, 1.0);\n#ifdef skinning\n @import clay.chunk.skin_matrix\n p = skinmatrixws * p;\n#endif\n#ifdef instancing\n @import clay.chunk.instancing_matrix\n p = instancemat * p;\n#endif\n gl_position = worldviewprojection * p;\n v_worldposition = (world * p).xyz;\n}\n@end\n@export clay.sm.distance.fragment\nuniform vec3 lightposition;\nuniform float range : 100;\nvarying vec3 v_worldposition;\n@import clay.util.encode_float\nvoid main(){\n float dist = distance(lightposition, v_worldposition);\n#ifdef use_vsm\n gl_fragcolor = vec4(dist, dist * dist, 0.0, 0.0);\n#else\n dist = dist / range;\n gl_fragcolor = encodefloat(dist);\n#endif\n}\n@end\n@export clay.plugin.shadow_map_common\n@import clay.util.decode_float\nfloat tapshadowmap(sampler2d map, vec2 uv, float z){\n vec4 tex = texture2d(map, uv);\n return step(z, decodefloat(tex) * 2.0 - 1.0);\n}\nfloat pcf(sampler2d map, vec2 uv, float z, float texturesize, vec2 scale) {\n float shadowcontrib = tapshadowmap(map, uv, z);\n vec2 offset = vec2(1.0 / texturesize) * scale;\n#ifdef pcf_kernel_size\n for (int _idx_ = 0; _idx_ < pcf_kernel_size; _idx_++) {{\n shadowcontrib += tapshadowmap(map, uv + offset * pcfkernel[_idx_], z);\n }}\n return shadowcontrib / float(pcf_kernel_size + 1);\n#else\n shadowcontrib += tapshadowmap(map, uv+vec2(offset.x, 0.0), z);\n shadowcontrib += tapshadowmap(map, uv+vec2(offset.x, offset.y), z);\n shadowcontrib += tapshadowmap(map, uv+vec2(-offset.x, offset.y), z);\n shadowcontrib += tapshadowmap(map, uv+vec2(0.0, offset.y), z);\n shadowcontrib += tapshadowmap(map, uv+vec2(-offset.x, 0.0), z);\n shadowcontrib += tapshadowmap(map, uv+vec2(-offset.x, -offset.y), z);\n shadowcontrib += tapshadowmap(map, uv+vec2(offset.x, -offset.y), z);\n shadowcontrib += tapshadowmap(map, uv+vec2(0.0, -offset.y), z);\n return shadowcontrib / 9.0;\n#endif\n}\nfloat pcf(sampler2d map, vec2 uv, float z, float texturesize) {\n return pcf(map, uv, z, texturesize, vec2(1.0));\n}\nfloat chebyshevupperbound(vec2 moments, float z){\n float p = 0.0;\n z = z * 0.5 + 0.5;\n if (z <= moments.x) {\n p = 1.0;\n }\n float variance = moments.y - moments.x * moments.x;\n variance = max(variance, 0.0000001);\n float md = moments.x - z;\n float pmax = variance / (variance + md * md);\n pmax = clamp((pmax-0.4)/(1.0-0.4), 0.0, 1.0);\n return max(p, pmax);\n}\nfloat computeshadowcontrib(\n sampler2d map, mat4 lightvpm, vec3 position, float texturesize, vec2 scale, vec2 offset\n) {\n vec4 posinlightspace = lightvpm * vec4(position, 1.0);\n posinlightspace.xyz /= posinlightspace.w;\n float z = posinlightspace.z;\n if(all(greaterthan(posinlightspace.xyz, vec3(-0.99, -0.99, -1.0))) &&\n all(lessthan(posinlightspace.xyz, vec3(0.99, 0.99, 1.0)))){\n vec2 uv = (posinlightspace.xy+1.0) / 2.0;\n #ifdef use_vsm\n vec2 moments = texture2d(map, uv * scale + offset).xy;\n return chebyshevupperbound(moments, z);\n #else\n return pcf(map, uv * scale + offset, z, texturesize, scale);\n #endif\n }\n return 1.0;\n}\nfloat computeshadowcontrib(sampler2d map, mat4 lightvpm, vec3 position, float texturesize) {\n return computeshadowcontrib(map, lightvpm, position, texturesize, vec2(1.0), vec2(0.0));\n}\nfloat computeshadowcontribomni(samplercube map, vec3 direction, float range)\n{\n float dist = length(direction);\n vec4 shadowtex = texturecube(map, direction);\n#ifdef use_vsm\n vec2 moments = shadowtex.xy;\n float variance = moments.y - moments.x * moments.x;\n float md = moments.x - dist;\n float p = variance / (variance + md * md);\n if(moments.x + 0.001 < dist){\n return clamp(p, 0.0, 1.0);\n }else{\n return 1.0;\n }\n#else\n return step(dist, (decodefloat(shadowtex) + 0.0002) * range);\n#endif\n}\n@end\n@export clay.plugin.compute_shadow_map\n#if defined(spot_light_shadowmap_count) || defined(directional_light_shadowmap_count) || defined(point_light_shadowmap_count)\n#ifdef spot_light_shadowmap_count\nuniform sampler2d spotlightshadowmaps[spot_light_shadowmap_count]:unconfigurable;\nuniform mat4 spotlightmatrices[spot_light_shadowmap_count]:unconfigurable;\nuniform float spotlightshadowmapsizes[spot_light_shadowmap_count]:unconfigurable;\n#endif\n#ifdef directional_light_shadowmap_count\n#if defined(shadow_cascade)\nuniform sampler2d directionallightshadowmaps[1]:unconfigurable;\nuniform mat4 directionallightmatrices[shadow_cascade]:unconfigurable;\nuniform float directionallightshadowmapsizes[1]:unconfigurable;\nuniform float shadowcascadeclipsnear[shadow_cascade]:unconfigurable;\nuniform float shadowcascadeclipsfar[shadow_cascade]:unconfigurable;\n#else\nuniform sampler2d directionallightshadowmaps[directional_light_shadowmap_count]:unconfigurable;\nuniform mat4 directionallightmatrices[directional_light_shadowmap_count]:unconfigurable;\nuniform float directionallightshadowmapsizes[directional_light_shadowmap_count]:unconfigurable;\n#endif\n#endif\n#ifdef point_light_shadowmap_count\nuniform samplercube pointlightshadowmaps[point_light_shadowmap_count]:unconfigurable;\n#endif\nuniform bool shadowenabled : true;\n#ifdef pcf_kernel_size\nuniform vec2 pcfkernel[pcf_kernel_size];\n#endif\n@import clay.plugin.shadow_map_common\n#if defined(spot_light_shadowmap_count)\nvoid computeshadowofspotlights(vec3 position, inout float shadowcontribs[spot_light_count] ) {\n float shadowcontrib;\n for(int _idx_ = 0; _idx_ < spot_light_shadowmap_count; _idx_++) {{\n shadowcontrib = computeshadowcontrib(\n spotlightshadowmaps[_idx_], spotlightmatrices[_idx_], position,\n spotlightshadowmapsizes[_idx_]\n );\n shadowcontribs[_idx_] = shadowcontrib;\n }}\n for(int _idx_ = spot_light_shadowmap_count; _idx_ < spot_light_count; _idx_++){{\n shadowcontribs[_idx_] = 1.0;\n }}\n}\n#endif\n#if defined(directional_light_shadowmap_count)\n#ifdef shadow_cascade\nvoid computeshadowofdirectionallights(vec3 position, inout float shadowcontribs[directional_light_count]){\n float depth = (2.0 * gl_fragcoord.z - gl_depthrange.near - gl_depthrange.far)\n / (gl_depthrange.far - gl_depthrange.near);\n float shadowcontrib;\n shadowcontribs[0] = 1.0;\n for (int _idx_ = 0; _idx_ < shadow_cascade; _idx_++) {{\n if (\n depth >= shadowcascadeclipsnear[_idx_] &&\n depth <= shadowcascadeclipsfar[_idx_]\n ) {\n shadowcontrib = computeshadowcontrib(\n directionallightshadowmaps[0], directionallightmatrices[_idx_], position,\n directionallightshadowmapsizes[0],\n vec2(1.0 / float(shadow_cascade), 1.0),\n vec2(float(_idx_) / float(shadow_cascade), 0.0)\n );\n shadowcontribs[0] = shadowcontrib;\n }\n }}\n for(int _idx_ = directional_light_shadowmap_count; _idx_ < directional_light_count; _idx_++) {{\n shadowcontribs[_idx_] = 1.0;\n }}\n}\n#else\nvoid computeshadowofdirectionallights(vec3 position, inout float shadowcontribs[directional_light_count]){\n float shadowcontrib;\n for(int _idx_ = 0; _idx_ < directional_light_shadowmap_count; _idx_++) {{\n shadowcontrib = computeshadowcontrib(\n directionallightshadowmaps[_idx_], directionallightmatrices[_idx_], position,\n directionallightshadowmapsizes[_idx_]\n );\n shadowcontribs[_idx_] = shadowcontrib;\n }}\n for(int _idx_ = directional_light_shadowmap_count; _idx_ < directional_light_count; _idx_++) {{\n shadowcontribs[_idx_] = 1.0;\n }}\n}\n#endif\n#endif\n#if defined(point_light_shadowmap_count)\nvoid computeshadowofpointlights(vec3 position, inout float shadowcontribs[point_light_count] ){\n vec3 lightposition;\n vec3 direction;\n for(int _idx_ = 0; _idx_ < point_light_shadowmap_count; _idx_++) {{\n lightposition = pointlightposition[_idx_];\n direction = position - lightposition;\n shadowcontribs[_idx_] = computeshadowcontribomni(pointlightshadowmaps[_idx_], direction, pointlightrange[_idx_]);\n }}\n for(int _idx_ = point_light_shadowmap_count; _idx_ < point_light_count; _idx_++) {{\n shadowcontribs[_idx_] = 1.0;\n }}\n}\n#endif\n#endif\n@end");var ns,is,rs,bs,fs,zs,gs,us=m.extend((function(){return{softshadow:us.pcf,shadowblur:1,lightfrustumbias:"auto",kernelpcf:new float32array([1,0,1,1,-1,1,0,1,-1,0,-1,-1,1,-1,0,-1]),precision:"highp",_lastrendernotcastshadow:!1,_framebuffer:new zi,_textures:{},_shadowmapnumber:{point_light:0,directional_light:0,spot_light:0},_depthmaterials:{},_distancematerials:{},_receivers:[],_lightscastshadow:[],_lightcameras:{},_lightmaterials:{},_texturepool:new ds}}),(function(){this._gaussianpassh=new pn({fragment:xe.source("clay.compositor.gaussian_blur")}),this._gaussianpassv=new pn({fragment:xe.source("clay.compositor.gaussian_blur")}),this._gaussianpassh.setuniform("blursize",this.shadowblur),this._gaussianpassh.setuniform("blurdir",0),this._gaussianpassv.setuniform("blursize",this.shadowblur),this._gaussianpassv.setuniform("blurdir",1),this._outputdepthpass=new pn({fragment:xe.source("clay.sm.debug_depth")})}),{render:function(e,t,r,i){r||(r=t.getmaincamera()),this.trigger("beforerender",this,e,t,r),this._rendershadowpass(e,t,r,i),this.trigger("afterrender",this,e,t,r)},renderdebug:function(e,t){e.saveclear();var r=e.viewport,i=0,n=t||r.width/4,a=n;for(var o in this.softshadow===us.vsm?this._outputdepthpass.material.define("fragment","use_vsm"):this._outputdepthpass.material.undefine("fragment","use_vsm"),this._textures){var s=this._textures[o];e.setviewport(i,0,n*s.width/s.height,a),this._outputdepthpass.setuniform("depthmap",s),this._outputdepthpass.render(e),i+=n*s.width/s.height}e.setviewport(r),e.restoreclear()},_updatereceivers:function(e,t){if(t.receiveshadow?(this._receivers.push(t),t.material.set("shadowenabled",1),t.material.set("pcfkernel",this.kernelpcf)):t.material.set("shadowenabled",0),this.softshadow===us.vsm)t.material.define("fragment","use_vsm"),t.material.undefine("fragment","pcf_kernel_size");else{t.material.undefine("fragment","use_vsm");var r=this.kernelpcf;r&&r.length?t.material.define("fragment","pcf_kernel_size",r.length/2):t.material.undefine("fragment","pcf_kernel_size")}},_update:function(e,t){var r=this;t.traverse((function(t){t.isrenderable()&&r._updatereceivers(e,t)}));for(var i=0;i4){console.warn("support at most 4 cascade");continue}p.shadowcascade>1&&(o=p),this.renderdirectionallightshadow(e,t,r,p,c,u,h)}else"spot_light"===p.type?this.renderspotlightshadow(e,t,p,l,s):"point_light"===p.type&&this.renderpointlightshadow(e,t,p,d);this._shadowmapnumber[p.type]++}for(var m in this._shadowmapnumber){var g=this._shadowmapnumber[m],_=m+"_shadowmap_count";for(f=0;f0?v.define("fragment",_,g):v.isdefined("fragment",_)&&v.undefine("fragment",_))}for(f=0;f0){var x=h.map(s);if(y.directionallightshadowmaps={value:h,type:"tv"},y.directionallightmatrices={value:u,type:"m4v"},y.directionallightshadowmapsizes={value:x,type:"1fv"},o){var b=c.slice(),w=c.slice();b.pop(),w.shift(),b.reverse(),w.reverse(),u.reverse(),y.shadowcascadeclipsnear={value:b,type:"1fv"},y.shadowcascadeclipsfar={value:w,type:"1fv"}}}if(s.length>0){var t=s.map(s);(y=t.shadowuniforms).spotlightshadowmaps={value:s,type:"tv"},y.spotlightmatrices={value:l,type:"m4v"},y.spotlightshadowmapsizes={value:t,type:"1fv"}}d.length>0&&(y.pointlightshadowmaps={value:d,type:"tv"})}function s(e){return e.height}},renderdirectionallightshadow:(ns=new si,is=new ht,rs=new ir,bs=new ht,fs=new ht,zs=new ht,gs=new ht,function(e,t,r,i,n,a,o){var s=this._getdepthmaterial(i),l={getmaterial:function(e){return e.shadowdepthmaterial||s},ismaterialchanged:os,getuniform:ps,ifrender:function(e){return e.castshadow},sortcompare:ut.opaquesortcompare};if(!t.viewboundingboxlastframe.isfinite()){var h=t.getboundingbox();t.viewboundingboxlastframe.copy(h).applytransform(r.viewmatrix)}var u=math.min(-t.viewboundingboxlastframe.min.z,r.far),c=math.max(-t.viewboundingboxlastframe.max.z,r.near),d=this._getdirectionallightcamera(i,t,r),f=zs.array;gs.copy(d.projectionmatrix),ye.invert(fs.array,d.worldtransform.array),ye.multiply(fs.array,fs.array,r.worldtransform.array),ye.multiply(f,gs.array,fs.array);for(var p=[],m=r instanceof ei,g=(r.near+r.far)/(r.near-r.far),_=2*r.near*r.far/(r.near-r.far),v=0;v<=i.shadowcascade;v++){var y=c*math.pow(u/c,v/i.shadowcascade),x=c+(u-c)*v/i.shadowcascade,b=y*i.cascadesplitlogfactor+x*(1-i.cascadesplitlogfactor);p.push(b),n.push(-(-b*g+_)/-b)}var w=this._gettexture(i,i.shadowcascade);o.push(w);var t=e.viewport,s=e.gl;for(this._framebuffer.attach(w),this._framebuffer.bind(e),s.clear(s.color_buffer_bit|s.depth_buffer_bit),v=0;vd?s>f?p[n>0?"px":"nx"]=!0:p[o>0?"pz":"nz"]=!0:d>f?p[a>0?"py":"ny"]=!0:p[o>0?"pz":"nz"]=!0}for(r=0;r0&&(this.outputs[e].keeplastframe?(this._prevoutputtextures[e]&&this._compositor.releasetexture(this._prevoutputtextures[e]),this._prevoutputtextures[e]=this._outputtextures[e]):this._compositor.releasetexture(this._outputtextures[e]))}}),hs=m.extend((function(){return{nodes:[]}}),{dirty:function(){this._dirty=!0},addnode:function(e){this.nodes.indexof(e)>=0||(this.nodes.push(e),this._dirty=!0)},removenode:function(e){"string"==typeof e&&(e=this.getnodebyname(e));var t=this.nodes.indexof(e);t>=0&&(this.nodes.splice(t,1),this._dirty=!0)},getnodebyname:function(e){for(var t=0;t=r.color_attachment0&&u<=r.color_attachment0+8&&h.push(u);l.drawbuffersext(h)}e.saveclear(),e.clearbit=16640,t=e.render(this.scene,this.camera,!this.autoupdatescene,this.prez),e.restoreclear(),i.unbind(e)}else t=e.render(this.scene,this.camera,!this.autoupdatescene,this.prez);this.trigger("afterrender",t),this._rendering=!1,this._rendered=!0}}),xs=vs.extend((function(){return{texture:null,outputs:{color:{}}}}),(function(){}),{getoutput:function(e,t){return this.texture},beforeframe:function(){},afterframe:function(){}}),qs=vs.extend((function(){return{name:"",inputs:{},outputs:null,shader:"",inputlinks:{},outputlinks:{},pass:null,_prevoutputtextures:{},_outputtextures:{},_outputreferences:{},_rendering:!1,_rendered:!1,_compositor:null}}),(function(){var e=new pn({fragment:this.shader});this.pass=e}),{render:function(e,t){this.trigger("beforerender",e),this._rendering=!0;var r=e.gl;for(var i in this.inputlinks){var n=(c=this.inputlinks[i]).node.getoutput(e,c.pin);this.pass.setuniform(i,n)}if(this.outputs){this.pass.outputs={};var a={};for(var o in this.outputs){var s=this.updateparameter(o,e);isnan(s.width)&&this.updateparameter(o,e);var l=this.outputs[o],h=this._compositor.allocatetexture(s);this._outputtextures[o]=h,"string"==typeof(u=l.attachment||r.color_attachment0)&&(u=r[u]),a[u]=h}for(var u in this._compositor.getframebuffer().bind(e),a)this._compositor.getframebuffer().attach(a[u],u);this.pass.render(e),this._compositor.getframebuffer().updatemipmap(e)}else this.pass.outputs=null,this._compositor.getframebuffer().unbind(e),this.pass.render(e,t);for(var i in this.inputlinks){var c;(c=this.inputlinks[i]).node.removereference(c.pin)}this._rendering=!1,this._rendered=!0,this.trigger("afterrender",e)},updateparameter:function(e,t){var r,i,n=this.outputs[e],a=n.parameters,o=n._parameterscopy;if(o||(o=n._parameterscopy={}),a)for(var s in a)"width"!==s&&"height"!==s&&(o[s]=a[s]);return r="function"==typeof a.width?a.width.call(this,t):a.width,i="function"==typeof a.height?a.height.call(this,t):a.height,r=math.ceil(r),i=math.ceil(i),o.width===r&&o.height===i||this._outputtextures[e]&&this._outputtextures[e].dispose(t),o.width=r,o.height=i,o},setparameter:function(e,t){this.pass.setuniform(e,t)},getparameter:function(e){return this.pass.getuniform(e)},setparameters:function(e){for(var t in e)this.setparameter(t,e[t])},define:function(e,t){this.pass.material.define("fragment",e,t)},undefine:function(e){this.pass.material.undefine("fragment",e)},removereference:function(e){this._outputreferences[e]--,0===this._outputreferences[e]&&(this.outputs[e].keeplastframe?(this._prevoutputtextures[e]&&this._compositor.releasetexture(this._prevoutputtextures[e]),this._prevoutputtextures[e]=this._outputtextures[e]):this._compositor.releasetexture(this._outputtextures[e]))},clear:function(){vs.prototype.clear.call(this),this.pass.material.disabletexturesall()}}),zs="@export clay.compositor.kernel.gaussian_9\nfloat gaussiankernel[9];\ngaussiankernel[0] = 0.07;\ngaussiankernel[1] = 0.09;\ngaussiankernel[2] = 0.12;\ngaussiankernel[3] = 0.14;\ngaussiankernel[4] = 0.16;\ngaussiankernel[5] = 0.14;\ngaussiankernel[6] = 0.12;\ngaussiankernel[7] = 0.09;\ngaussiankernel[8] = 0.07;\n@end\n@export clay.compositor.kernel.gaussian_13\nfloat gaussiankernel[13];\ngaussiankernel[0] = 0.02;\ngaussiankernel[1] = 0.03;\ngaussiankernel[2] = 0.06;\ngaussiankernel[3] = 0.08;\ngaussiankernel[4] = 0.11;\ngaussiankernel[5] = 0.13;\ngaussiankernel[6] = 0.14;\ngaussiankernel[7] = 0.13;\ngaussiankernel[8] = 0.11;\ngaussiankernel[9] = 0.08;\ngaussiankernel[10] = 0.06;\ngaussiankernel[11] = 0.03;\ngaussiankernel[12] = 0.02;\n@end\n@export clay.compositor.gaussian_blur\n#define shader_name gaussian_blur\nuniform sampler2d texture;varying vec2 v_texcoord;\nuniform float blursize : 2.0;\nuniform vec2 texturesize : [512.0, 512.0];\nuniform float blurdir : 0.0;\n@import clay.util.rgbm\n@import clay.util.clamp_sample\nvoid main (void)\n{\n @import clay.compositor.kernel.gaussian_9\n vec2 off = blursize / texturesize;\n off *= vec2(1.0 - blurdir, blurdir);\n vec4 sum = vec4(0.0);\n float weightall = 0.0;\n for (int i = 0; i < 9; i++) {\n float w = gaussiankernel[i];\n vec4 texel = decodehdr(clampsample(texture, v_texcoord + float(i - 4) * off));\n sum += texel * w;\n weightall += w;\n }\n gl_fragcolor = encodehdr(sum / max(weightall, 0.01));\n}\n@end\n",ys="\n@export clay.compositor.lut\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\nuniform sampler2d lookup;\nvoid main()\n{\n vec4 tex = texture2d(texture, v_texcoord);\n float bluecolor = tex.b * 63.0;\n vec2 quad1;\n quad1.y = floor(floor(bluecolor) / 8.0);\n quad1.x = floor(bluecolor) - (quad1.y * 8.0);\n vec2 quad2;\n quad2.y = floor(ceil(bluecolor) / 8.0);\n quad2.x = ceil(bluecolor) - (quad2.y * 8.0);\n vec2 texpos1;\n texpos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);\n texpos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);\n vec2 texpos2;\n texpos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r);\n texpos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g);\n vec4 newcolor1 = texture2d(lookup, texpos1);\n vec4 newcolor2 = texture2d(lookup, texpos2);\n vec4 newcolor = mix(newcolor1, newcolor2, fract(bluecolor));\n gl_fragcolor = vec4(newcolor.rgb, tex.w);\n}\n@end",ks="@export clay.compositor.output\n#define output_alpha\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\n@import clay.util.rgbm\nvoid main()\n{\n vec4 tex = decodehdr(texture2d(texture, v_texcoord));\n gl_fragcolor.rgb = tex.rgb;\n#ifdef output_alpha\n gl_fragcolor.a = tex.a;\n#else\n gl_fragcolor.a = 1.0;\n#endif\n gl_fragcolor = encodehdr(gl_fragcolor);\n#ifdef premultiply_alpha\n gl_fragcolor.rgb *= gl_fragcolor.a;\n#endif\n}\n@end",qs="@export clay.compositor.bright\nuniform sampler2d texture;\nuniform float threshold : 1;\nuniform float scale : 1.0;\nuniform vec2 texturesize: [512, 512];\nvarying vec2 v_texcoord;\nconst vec3 lumweight = vec3(0.2125, 0.7154, 0.0721);\n@import clay.util.rgbm\nvec4 median(vec4 a, vec4 b, vec4 c)\n{\n return a + b + c - min(min(a, b), c) - max(max(a, b), c);\n}\nvoid main()\n{\n vec4 texel = decodehdr(texture2d(texture, v_texcoord));\n#ifdef anti_flicker\n vec3 d = 1.0 / texturesize.xyx * vec3(1.0, 1.0, 0.0);\n vec4 s1 = decodehdr(texture2d(texture, v_texcoord - d.xz));\n vec4 s2 = decodehdr(texture2d(texture, v_texcoord + d.xz));\n vec4 s3 = decodehdr(texture2d(texture, v_texcoord - d.zy));\n vec4 s4 = decodehdr(texture2d(texture, v_texcoord + d.zy));\n texel = median(median(texel, s1, s2), s3, s4);\n#endif\n float lum = dot(texel.rgb , lumweight);\n vec4 color;\n if (lum > threshold && texel.a > 0.0)\n {\n color = vec4(texel.rgb * scale, texel.a * scale);\n }\n else\n {\n color = vec4(0.0);\n }\n gl_fragcolor = encodehdr(color);\n}\n@end\n",js="@export clay.compositor.downsample\nuniform sampler2d texture;\nuniform vec2 texturesize : [512, 512];\nvarying vec2 v_texcoord;\n@import clay.util.rgbm\nfloat brightness(vec3 c)\n{\n return max(max(c.r, c.g), c.b);\n}\n@import clay.util.clamp_sample\nvoid main()\n{\n vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / texturesize.xyxy;\n#ifdef anti_flicker\n vec3 s1 = decodehdr(clampsample(texture, v_texcoord + d.xy)).rgb;\n vec3 s2 = decodehdr(clampsample(texture, v_texcoord + d.zy)).rgb;\n vec3 s3 = decodehdr(clampsample(texture, v_texcoord + d.xw)).rgb;\n vec3 s4 = decodehdr(clampsample(texture, v_texcoord + d.zw)).rgb;\n float s1w = 1.0 / (brightness(s1) + 1.0);\n float s2w = 1.0 / (brightness(s2) + 1.0);\n float s3w = 1.0 / (brightness(s3) + 1.0);\n float s4w = 1.0 / (brightness(s4) + 1.0);\n float onedividesum = 1.0 / (s1w + s2w + s3w + s4w);\n vec4 color = vec4(\n (s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * onedividesum,\n 1.0\n );\n#else\n vec4 color = decodehdr(clampsample(texture, v_texcoord + d.xy));\n color += decodehdr(clampsample(texture, v_texcoord + d.zy));\n color += decodehdr(clampsample(texture, v_texcoord + d.xw));\n color += decodehdr(clampsample(texture, v_texcoord + d.zw));\n color *= 0.25;\n#endif\n gl_fragcolor = encodehdr(color);\n}\n@end",$s="\n@export clay.compositor.upsample\n#define high_quality\nuniform sampler2d texture;\nuniform vec2 texturesize : [512, 512];\nuniform float samplescale: 0.5;\nvarying vec2 v_texcoord;\n@import clay.util.rgbm\n@import clay.util.clamp_sample\nvoid main()\n{\n#ifdef high_quality\n vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / texturesize.xyxy * samplescale;\n vec4 s;\n s = decodehdr(clampsample(texture, v_texcoord - d.xy));\n s += decodehdr(clampsample(texture, v_texcoord - d.wy)) * 2.0;\n s += decodehdr(clampsample(texture, v_texcoord - d.zy));\n s += decodehdr(clampsample(texture, v_texcoord + d.zw)) * 2.0;\n s += decodehdr(clampsample(texture, v_texcoord )) * 4.0;\n s += decodehdr(clampsample(texture, v_texcoord + d.xw)) * 2.0;\n s += decodehdr(clampsample(texture, v_texcoord + d.zy));\n s += decodehdr(clampsample(texture, v_texcoord + d.wy)) * 2.0;\n s += decodehdr(clampsample(texture, v_texcoord + d.xy));\n gl_fragcolor = encodehdr(s / 16.0);\n#else\n vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / texturesize.xyxy;\n vec4 s;\n s = decodehdr(clampsample(texture, v_texcoord + d.xy));\n s += decodehdr(clampsample(texture, v_texcoord + d.zy));\n s += decodehdr(clampsample(texture, v_texcoord + d.xw));\n s += decodehdr(clampsample(texture, v_texcoord + d.zw));\n gl_fragcolor = encodehdr(s / 4.0);\n#endif\n}\n@end",el="@export clay.compositor.hdr.composite\n#define tonemapping\nuniform sampler2d texture;\n#ifdef bloom_enabled\nuniform sampler2d bloom;\n#endif\n#ifdef lensflare_enabled\nuniform sampler2d lensflare;\nuniform sampler2d lensdirt;\n#endif\n#ifdef lum_enabled\nuniform sampler2d lum;\n#endif\n#ifdef lut_enabled\nuniform sampler2d lut;\n#endif\n#ifdef color_correction\nuniform float brightness : 0.0;\nuniform float contrast : 1.0;\nuniform float saturation : 1.0;\n#endif\n#ifdef vignette\nuniform float vignettedarkness: 1.0;\nuniform float vignetteoffset: 1.0;\n#endif\nuniform float exposure : 1.0;\nuniform float bloomintensity : 0.25;\nuniform float lensflareintensity : 1;\nvarying vec2 v_texcoord;\n@import clay.util.srgb\nvec3 acestonemapping(vec3 color)\n{\n const float a = 2.51;\n const float b = 0.03;\n const float c = 2.43;\n const float d = 0.59;\n const float e = 0.14;\n return (color * (a * color + b)) / (color * (c * color + d) + e);\n}\nfloat eyeadaption(float flum)\n{\n return mix(0.2, flum, 0.5);\n}\n#ifdef lut_enabled\nvec3 luttransform(vec3 color) {\n float bluecolor = color.b * 63.0;\n vec2 quad1;\n quad1.y = floor(floor(bluecolor) / 8.0);\n quad1.x = floor(bluecolor) - (quad1.y * 8.0);\n vec2 quad2;\n quad2.y = floor(ceil(bluecolor) / 8.0);\n quad2.x = ceil(bluecolor) - (quad2.y * 8.0);\n vec2 texpos1;\n texpos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);\n texpos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);\n vec2 texpos2;\n texpos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r);\n texpos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g);\n vec4 newcolor1 = texture2d(lut, texpos1);\n vec4 newcolor2 = texture2d(lut, texpos2);\n vec4 newcolor = mix(newcolor1, newcolor2, fract(bluecolor));\n return newcolor.rgb;\n}\n#endif\n@import clay.util.rgbm\nvoid main()\n{\n vec4 texel = vec4(0.0);\n vec4 originaltexel = vec4(0.0);\n#ifdef texture_enabled\n texel = decodehdr(texture2d(texture, v_texcoord));\n originaltexel = texel;\n#endif\n#ifdef bloom_enabled\n vec4 bloomtexel = decodehdr(texture2d(bloom, v_texcoord));\n texel.rgb += bloomtexel.rgb * bloomintensity;\n texel.a += bloomtexel.a * bloomintensity;\n#endif\n#ifdef lensflare_enabled\n texel += decodehdr(texture2d(lensflare, v_texcoord)) * texture2d(lensdirt, v_texcoord) * lensflareintensity;\n#endif\n texel.a = min(texel.a, 1.0);\n#ifdef lum_enabled\n float flum = texture2d(lum, vec2(0.5, 0.5)).r;\n float adaptedlumdest = 3.0 / (max(0.1, 1.0 + 10.0*eyeadaption(flum)));\n float exposurebias = adaptedlumdest * exposure;\n#else\n float exposurebias = exposure;\n#endif\n#ifdef tonemapping\n texel.rgb *= exposurebias;\n texel.rgb = acestonemapping(texel.rgb);\n#endif\n texel = lineartosrgb(texel);\n#ifdef lut_enabled\n texel.rgb = luttransform(clamp(texel.rgb,vec3(0.0),vec3(1.0)));\n#endif\n#ifdef color_correction\n texel.rgb = clamp(texel.rgb + vec3(brightness), 0.0, 1.0);\n texel.rgb = clamp((texel.rgb - vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);\n float lum = dot(texel.rgb, vec3(0.2125, 0.7154, 0.0721));\n texel.rgb = mix(vec3(lum), texel.rgb, saturation);\n#endif\n#ifdef vignette\n vec2 uv = (v_texcoord - vec2(0.5)) * vec2(vignetteoffset);\n texel.rgb = mix(texel.rgb, vec3(1.0 - vignettedarkness), dot(uv, uv));\n#endif\n gl_fragcolor = encodehdr(texel);\n#ifdef debug\n #if debug == 1\n gl_fragcolor = encodehdr(decodehdr(texture2d(texture, v_texcoord)));\n #elif debug == 2\n gl_fragcolor = encodehdr(decodehdr(texture2d(bloom, v_texcoord)) * bloomintensity);\n #elif debug == 3\n gl_fragcolor = encodehdr(decodehdr(texture2d(lensflare, v_texcoord) * lensflareintensity));\n #endif\n#endif\n if (originaltexel.a <= 0.01 && gl_fragcolor.a > 1e-5) {\n gl_fragcolor.a = dot(gl_fragcolor.rgb, vec3(0.2125, 0.7154, 0.0721));\n }\n#ifdef premultiply_alpha\n gl_fragcolor.rgb *= gl_fragcolor.a;\n#endif\n}\n@end",tl="@export clay.compositor.blend\n#define shader_name blend\n#ifdef texture1_enabled\nuniform sampler2d texture1;\nuniform float weight1 : 1.0;\n#endif\n#ifdef texture2_enabled\nuniform sampler2d texture2;\nuniform float weight2 : 1.0;\n#endif\n#ifdef texture3_enabled\nuniform sampler2d texture3;\nuniform float weight3 : 1.0;\n#endif\n#ifdef texture4_enabled\nuniform sampler2d texture4;\nuniform float weight4 : 1.0;\n#endif\n#ifdef texture5_enabled\nuniform sampler2d texture5;\nuniform float weight5 : 1.0;\n#endif\n#ifdef texture6_enabled\nuniform sampler2d texture6;\nuniform float weight6 : 1.0;\n#endif\nvarying vec2 v_texcoord;\n@import clay.util.rgbm\nvoid main()\n{\n vec4 tex = vec4(0.0);\n#ifdef texture1_enabled\n tex += decodehdr(texture2d(texture1, v_texcoord)) * weight1;\n#endif\n#ifdef texture2_enabled\n tex += decodehdr(texture2d(texture2, v_texcoord)) * weight2;\n#endif\n#ifdef texture3_enabled\n tex += decodehdr(texture2d(texture3, v_texcoord)) * weight3;\n#endif\n#ifdef texture4_enabled\n tex += decodehdr(texture2d(texture4, v_texcoord)) * weight4;\n#endif\n#ifdef texture5_enabled\n tex += decodehdr(texture2d(texture5, v_texcoord)) * weight5;\n#endif\n#ifdef texture6_enabled\n tex += decodehdr(texture2d(texture6, v_texcoord)) * weight6;\n#endif\n gl_fragcolor = encodehdr(tex);\n}\n@end",rl="@export clay.compositor.fxaa\nuniform sampler2d texture;\nuniform vec4 viewport : viewport;\nvarying vec2 v_texcoord;\n#define fxaa_reduce_min (1.0/128.0)\n#define fxaa_reduce_mul (1.0/8.0)\n#define fxaa_span_max 8.0\n@import clay.util.rgbm\nvoid main()\n{\n vec2 resolution = 1.0 / viewport.zw;\n vec3 rgbnw = decodehdr( texture2d( texture, ( gl_fragcoord.xy + vec2( -1.0, -1.0 ) ) * resolution ) ).xyz;\n vec3 rgbne = decodehdr( texture2d( texture, ( gl_fragcoord.xy + vec2( 1.0, -1.0 ) ) * resolution ) ).xyz;\n vec3 rgbsw = decodehdr( texture2d( texture, ( gl_fragcoord.xy + vec2( -1.0, 1.0 ) ) * resolution ) ).xyz;\n vec3 rgbse = decodehdr( texture2d( texture, ( gl_fragcoord.xy + vec2( 1.0, 1.0 ) ) * resolution ) ).xyz;\n vec4 rgbam = decodehdr( texture2d( texture, gl_fragcoord.xy * resolution ) );\n vec3 rgbm = rgbam.xyz;\n float opacity = rgbam.w;\n vec3 luma = vec3( 0.299, 0.587, 0.114 );\n float lumanw = dot( rgbnw, luma );\n float lumane = dot( rgbne, luma );\n float lumasw = dot( rgbsw, luma );\n float lumase = dot( rgbse, luma );\n float lumam = dot( rgbm, luma );\n float lumamin = min( lumam, min( min( lumanw, lumane ), min( lumasw, lumase ) ) );\n float lumamax = max( lumam, max( max( lumanw, lumane) , max( lumasw, lumase ) ) );\n vec2 dir;\n dir.x = -((lumanw + lumane) - (lumasw + lumase));\n dir.y = ((lumanw + lumasw) - (lumane + lumase));\n float dirreduce = max( ( lumanw + lumane + lumasw + lumase ) * ( 0.25 * fxaa_reduce_mul ), fxaa_reduce_min );\n float rcpdirmin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirreduce );\n dir = min( vec2( fxaa_span_max, fxaa_span_max),\n max( vec2(-fxaa_span_max, -fxaa_span_max),\n dir * rcpdirmin)) * resolution;\n vec3 rgba = decodehdr( texture2d( texture, gl_fragcoord.xy * resolution + dir * ( 1.0 / 3.0 - 0.5 ) ) ).xyz;\n rgba += decodehdr( texture2d( texture, gl_fragcoord.xy * resolution + dir * ( 2.0 / 3.0 - 0.5 ) ) ).xyz;\n rgba *= 0.5;\n vec3 rgbb = decodehdr( texture2d( texture, gl_fragcoord.xy * resolution + dir * -0.5 ) ).xyz;\n rgbb += decodehdr( texture2d( texture, gl_fragcoord.xy * resolution + dir * 0.5 ) ).xyz;\n rgbb *= 0.25;\n rgbb += rgba * 0.5;\n float lumab = dot( rgbb, luma );\n if ( ( lumab < lumamin ) || ( lumab > lumamax ) )\n {\n gl_fragcolor = vec4( rgba, opacity );\n }\n else {\n gl_fragcolor = vec4( rgbb, opacity );\n }\n}\n@end";!function(e){e.import("@export clay.compositor.coloradjust\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\nuniform float brightness : 0.0;\nuniform float contrast : 1.0;\nuniform float exposure : 0.0;\nuniform float gamma : 1.0;\nuniform float saturation : 1.0;\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\nvoid main()\n{\n vec4 tex = texture2d( texture, v_texcoord);\n vec3 color = clamp(tex.rgb + vec3(brightness), 0.0, 1.0);\n color = clamp( (color-vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0);\n color = clamp( color * pow(2.0, exposure), 0.0, 1.0);\n color = clamp( pow(color, vec3(gamma)), 0.0, 1.0);\n float luminance = dot( color, w );\n color = mix(vec3(luminance), color, saturation);\n gl_fragcolor = vec4(color, tex.a);\n}\n@end\n@export clay.compositor.brightness\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\nuniform float brightness : 0.0;\nvoid main()\n{\n vec4 tex = texture2d( texture, v_texcoord);\n vec3 color = tex.rgb + vec3(brightness);\n gl_fragcolor = vec4(color, tex.a);\n}\n@end\n@export clay.compositor.contrast\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\nuniform float contrast : 1.0;\nvoid main()\n{\n vec4 tex = texture2d( texture, v_texcoord);\n vec3 color = (tex.rgb-vec3(0.5))*contrast+vec3(0.5);\n gl_fragcolor = vec4(color, tex.a);\n}\n@end\n@export clay.compositor.exposure\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\nuniform float exposure : 0.0;\nvoid main()\n{\n vec4 tex = texture2d(texture, v_texcoord);\n vec3 color = tex.rgb * pow(2.0, exposure);\n gl_fragcolor = vec4(color, tex.a);\n}\n@end\n@export clay.compositor.gamma\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\nuniform float gamma : 1.0;\nvoid main()\n{\n vec4 tex = texture2d(texture, v_texcoord);\n vec3 color = pow(tex.rgb, vec3(gamma));\n gl_fragcolor = vec4(color, tex.a);\n}\n@end\n@export clay.compositor.saturation\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\nuniform float saturation : 1.0;\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\nvoid main()\n{\n vec4 tex = texture2d(texture, v_texcoord);\n vec3 color = tex.rgb;\n float luminance = dot(color, w);\n color = mix(vec3(luminance), color, saturation);\n gl_fragcolor = vec4(color, tex.a);\n}\n@end"),e.import(zs),e.import("@export clay.compositor.hdr.log_lum\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\n@import clay.util.rgbm\nvoid main()\n{\n vec4 tex = decodehdr(texture2d(texture, v_texcoord));\n float luminance = dot(tex.rgb, w);\n luminance = log(luminance + 0.001);\n gl_fragcolor = encodehdr(vec4(vec3(luminance), 1.0));\n}\n@end\n@export clay.compositor.hdr.lum_adaption\nvarying vec2 v_texcoord;\nuniform sampler2d adaptedlum;\nuniform sampler2d currentlum;\nuniform float frametime : 0.02;\n@import clay.util.rgbm\nvoid main()\n{\n float fadaptedlum = decodehdr(texture2d(adaptedlum, vec2(0.5, 0.5))).r;\n float fcurrentlum = exp(encodehdr(texture2d(currentlum, vec2(0.5, 0.5))).r);\n fadaptedlum += (fcurrentlum - fadaptedlum) * (1.0 - pow(0.98, 30.0 * frametime));\n gl_fragcolor = encodehdr(vec4(vec3(fadaptedlum), 1.0));\n}\n@end\n@export clay.compositor.lum\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\nconst vec3 w = vec3(0.2125, 0.7154, 0.0721);\nvoid main()\n{\n vec4 tex = texture2d( texture, v_texcoord );\n float luminance = dot(tex.rgb, w);\n gl_fragcolor = vec4(vec3(luminance), 1.0);\n}\n@end"),e.import(ys),e.import("@export clay.compositor.vignette\n#define output_alpha\nvarying vec2 v_texcoord;\nuniform sampler2d texture;\nuniform float darkness: 1;\nuniform float offset: 1;\n@import clay.util.rgbm\nvoid main()\n{\n vec4 texel = decodehdr(texture2d(texture, v_texcoord));\n gl_fragcolor.rgb = texel.rgb;\n vec2 uv = (v_texcoord - vec2(0.5)) * vec2(offset);\n gl_fragcolor = encodehdr(vec4(mix(texel.rgb, vec3(1.0 - darkness), dot(uv, uv)), texel.a));\n}\n@end"),e.import(ks),e.import(qs),e.import(js),e.import($s),e.import(el),e.import("@export clay.compositor.lensflare\n#define sample_number 8\nuniform sampler2d texture;\nuniform sampler2d lenscolor;\nuniform vec2 texturesize : [512, 512];\nuniform float dispersal : 0.3;\nuniform float halowidth : 0.4;\nuniform float distortion : 1.0;\nvarying vec2 v_texcoord;\n@import clay.util.rgbm\nvec4 texturedistorted(\n in vec2 texcoord,\n in vec2 direction,\n in vec3 distortion\n) {\n return vec4(\n decodehdr(texture2d(texture, texcoord + direction * distortion.r)).r,\n decodehdr(texture2d(texture, texcoord + direction * distortion.g)).g,\n decodehdr(texture2d(texture, texcoord + direction * distortion.b)).b,\n 1.0\n );\n}\nvoid main()\n{\n vec2 texcoord = -v_texcoord + vec2(1.0); vec2 textureoffset = 1.0 / texturesize;\n vec2 ghostvec = (vec2(0.5) - texcoord) * dispersal;\n vec2 halovec = normalize(ghostvec) * halowidth;\n vec3 distortion = vec3(-textureoffset.x * distortion, 0.0, textureoffset.x * distortion);\n vec4 result = vec4(0.0);\n for (int i = 0; i < sample_number; i++)\n {\n vec2 offset = fract(texcoord + ghostvec * float(i));\n float weight = length(vec2(0.5) - offset) / length(vec2(0.5));\n weight = pow(1.0 - weight, 10.0);\n result += texturedistorted(offset, normalize(ghostvec), distortion) * weight;\n }\n result *= texture2d(lenscolor, vec2(length(vec2(0.5) - texcoord)) / length(vec2(0.5)));\n float weight = length(vec2(0.5) - fract(texcoord + halovec)) / length(vec2(0.5));\n weight = pow(1.0 - weight, 10.0);\n vec2 offset = fract(texcoord + halovec);\n result += texturedistorted(offset, normalize(ghostvec), distortion) * weight;\n gl_fragcolor = result;\n}\n@end"),e.import(tl),e.import(rl)}(xe);var il=/^#source\((.*?)\)/;function nl(e,t,r){var i,n,a,o,s=e.type||"filter";if("filter"===s){var l=e.shader.trim(),h=il.exec(l);if(h?i=xe.source(h[1].trim()):"#"===l.charat(0)&&(i=t.shaders[l.substr(1)]),i||(i=l),!i)return}if(e.inputs)for(var u in n={},e.inputs)"string"==typeof e.inputs[u]?n[u]=e.inputs[u]:n[u]={node:e.inputs[u].node,pin:e.inputs[u].pin};if(e.outputs)for(var u in a={},e.outputs){var c=e.outputs[u];a[u]={},null!=c.attachment&&(a[u].attachment=c.attachment),null!=c.keeplastframe&&(a[u].keeplastframe=c.keeplastframe),null!=c.outputlastframe&&(a[u].outputlastframe=c.outputlastframe),c.parameters&&(a[u].parameters=sl(c.parameters))}if(o="scene"===s?new js({name:e.name,scene:r.scene,camera:r.camera,outputs:a}):"texture"===s?new xs({name:e.name,outputs:a}):new qs({name:e.name,shader:i,inputs:n,outputs:a})){if(e.parameters)for(var u in e.parameters)"string"==typeof(d=e.parameters[u])?"#"===(d=d.trim()).charat(0)?d=t.textures[d.substr(1)]:o.on("beforerender",ll(u,hl(d))):"function"==typeof d&&o.on("beforerender",d),o.setparameter(u,d);if(e.defines&&o.pass)for(var u in e.defines){var d=e.defines[u];o.pass.material.define("fragment",u,d)}}return o}function al(e,t){return e}function ol(e,t){return t}function sl(e){var t={};if(!e)return t;["type","minfilter","magfilter","wraps","wrapt","flipy","usemipmap"].foreach((function(r){var i=e[r];null!=i&&("string"==typeof i&&(i=wr[i]),t[r]=i)}));var r=e.scale||1;return["width","height"].foreach((function(i){if(null!=e[i]){var n=e[i];"string"==typeof n?(n=n.trim(),t[i]=(a=hl(n),o=(o=r)||1,function(e){var t=e.getdevicepixelratio(),r=e.getwidth()*o,i=e.getheight()*o;return a(r,i,t)})):t[i]=n}var a,o})),t.width||(t.width=al),t.height||(t.height=ol),null!=e.usemipmap&&(t.usemipmap=e.usemipmap),t}function ll(e,t){return function(r){var i=r.getdevicepixelratio(),n=r.getwidth(),a=r.getheight(),o=t(n,a,i);this.setparameter(e,o)}}function hl(e){var t=/^expr\((.*)\)$/.exec(e);if(t)try{var r=new function("width","height","dpr","return "+t[1]);return r(1,1),r}catch(e){throw new error("invalid expression.")}}const ul=function(e,t){for(var r=0,i=1/t,n=e;n>0;)r+=i*(n%t),n=math.floor(n/t),i/=t;return r};function cl(e){for(var t=new uint8array(e*e*4),r=0,i=new vt,n=0;n 0.99999) {\n gl_fragcolor = vec4(1.0);\n return;\n }\n mat3 kernelbasis;\n#endif\n\n float z = depthtexel.r * 2.0 - 1.0;\n\n vec4 projectedpos = vec4(v_texcoord * 2.0 - 1.0, z, 1.0);\n vec4 p4 = projectioninv * projectedpos;\n\n vec3 position = p4.xyz / p4.w;\n\n float ao = ssaoestimator(position, kernelbasis);\n ao = clamp(1.0 - (1.0 - ao) * intensity, 0.0, 1.0);\n gl_fragcolor = vec4(vec3(ao), 1.0);\n}\n\n@end\n\n\n@export ecgl.ssao.blur\n#define shader_name ssao_blur\n\nuniform sampler2d ssaotexture;\n\n#ifdef normaltex_enabled\nuniform sampler2d normaltex;\n#endif\n\nvarying vec2 v_texcoord;\n\nuniform vec2 texturesize;\nuniform float blursize : 1.0;\n\nuniform int direction: 0.0;\n\n#ifdef depthtex_enabled\nuniform sampler2d depthtex;\nuniform mat4 projection;\nuniform float depthrange : 0.5;\n\nfloat getlineardepth(vec2 coord)\n{\n float depth = texture2d(depthtex, coord).r * 2.0 - 1.0;\n return projection[3][2] / (depth * projection[2][3] - projection[2][2]);\n}\n#endif\n\nvoid main()\n{\n float kernel[5];\n kernel[0] = 0.122581;\n kernel[1] = 0.233062;\n kernel[2] = 0.288713;\n kernel[3] = 0.233062;\n kernel[4] = 0.122581;\n\n vec2 off = vec2(0.0);\n if (direction == 0) {\n off[0] = blursize / texturesize.x;\n }\n else {\n off[1] = blursize / texturesize.y;\n }\n\n vec2 coord = v_texcoord;\n\n float sum = 0.0;\n float weightall = 0.0;\n\n#ifdef normaltex_enabled\n vec3 centernormal = texture2d(normaltex, v_texcoord).rgb * 2.0 - 1.0;\n#endif\n#if defined(depthtex_enabled)\n float centerdepth = getlineardepth(v_texcoord);\n#endif\n\n for (int i = 0; i < 5; i++) {\n vec2 coord = clamp(v_texcoord + vec2(float(i) - 2.0) * off, vec2(0.0), vec2(1.0));\n\n float w = kernel[i];\n#ifdef normaltex_enabled\n vec3 normal = texture2d(normaltex, coord).rgb * 2.0 - 1.0;\n w *= clamp(dot(normal, centernormal), 0.0, 1.0);\n#endif\n#ifdef depthtex_enabled\n float d = getlineardepth(coord);\n w *= (1.0 - smoothstep(abs(centerdepth - d) / depthrange, 0.0, 1.0));\n#endif\n\n weightall += w;\n sum += texture2d(ssaotexture, coord).r * w;\n }\n\n gl_fragcolor = vec4(vec3(sum / weightall), 1.0);\n}\n\n@end\n"),pl.prototype.setdepthtexture=function(e){this._depthtex=e},pl.prototype.setnormaltexture=function(e){this._normaltex=e,this._ssaopass.material[e?"enabletexture":"disabletexture"]("normaltex"),this.setkernelsize(this._kernelsize)},pl.prototype.update=function(e,t,r){var i=e.getwidth(),n=e.getheight(),a=this._ssaopass,o=this._blurpass;a.setuniform("kernel",this._kernels[r%this._kernels.length]),a.setuniform("depthtex",this._depthtex),null!=this._normaltex&&a.setuniform("normaltex",this._normaltex),a.setuniform("depthtexsize",[this._depthtex.width,this._depthtex.height]);var s=new ht;ht.transpose(s,t.worldtransform),a.setuniform("projection",t.projectionmatrix.array),a.setuniform("projectioninv",t.invprojectionmatrix.array),a.setuniform("viewinversetranspose",s.array);var l=this._ssaotexture,h=this._blurtexture,u=this._blurtexture2;l.width=i/2,l.height=n/2,h.width=i,h.height=n,u.width=i,u.height=n,this._framebuffer.attach(l),this._framebuffer.bind(e),e.gl.clearcolor(1,1,1,1),e.gl.clear(e.gl.color_buffer_bit),a.render(e),o.setuniform("texturesize",[i/2,n/2]),o.setuniform("projection",t.projectionmatrix.array),this._framebuffer.attach(h),o.setuniform("direction",0),o.setuniform("ssaotexture",l),o.render(e),this._framebuffer.attach(u),o.setuniform("texturesize",[i,n]),o.setuniform("direction",1),o.setuniform("ssaotexture",h),o.render(e),this._framebuffer.unbind(e);var c=e.clearcolor;e.gl.clearcolor(c[0],c[1],c[2],c[3])},pl.prototype.gettargettexture=function(){return this._blurtexture2},pl.prototype.setparameter=function(e,t){"noisetexsize"===e?this.setnoisesize(t):"kernelsize"===e?this.setkernelsize(t):"intensity"===e?this._ssaopass.material.set("intensity",t):this._ssaopass.setuniform(e,t)},pl.prototype.setkernelsize=function(e){this._kernelsize=e,this._ssaopass.material.define("fragment","kernel_size",e),this._kernels=this._kernels||[];for(var t=0;t<30;t++)this._kernels[t]=fl(e,t*e,!!this._normaltex)},pl.prototype.setnoisesize=function(e){var t=this._ssaopass.getuniform("noisetex");t?(t.data=cl(e),t.width=t.height=e,t.dirty()):(t=dl(e),this._ssaopass.setuniform("noisetex",dl(e))),this._ssaopass.setuniform("noisetexsize",[e,e])},pl.prototype.dispose=function(e){this._blurtexture.dispose(e),this._ssaotexture.dispose(e),this._blurtexture2.dispose(e)};const ml=pl;function gl(e){e=e||{},this._ssrpass=new pn({fragment:xe.source("ecgl.ssr.main"),clearcolor:[0,0,0,0]}),this._blurpass1=new pn({fragment:xe.source("ecgl.ssr.blur"),clearcolor:[0,0,0,0]}),this._blurpass2=new pn({fragment:xe.source("ecgl.ssr.blur"),clearcolor:[0,0,0,0]}),this._blendpass=new pn({fragment:xe.source("clay.compositor.blend")}),this._blendpass.material.disabletexturesall(),this._blendpass.material.enabletexture(["texture1","texture2"]),this._ssrpass.setuniform("gbuffertexture1",e.normaltexture),this._ssrpass.setuniform("gbuffertexture2",e.depthtexture),this._blurpass1.setuniform("gbuffertexture1",e.normaltexture),this._blurpass1.setuniform("gbuffertexture2",e.depthtexture),this._blurpass2.setuniform("gbuffertexture1",e.normaltexture),this._blurpass2.setuniform("gbuffertexture2",e.depthtexture),this._blurpass2.material.define("fragment","vertical"),this._blurpass2.material.define("fragment","blend"),this._ssrtexture=new dr({type:wr.half_float}),this._texture2=new dr({type:wr.half_float}),this._texture3=new dr({type:wr.half_float}),this._prevtexture=new dr({type:wr.half_float}),this._currenttexture=new dr({type:wr.half_float}),this._framebuffer=new zi({depthbuffer:!1}),this._normaldistribution=null,this._totalsamples=256,this._sampleperframe=4,this._ssrpass.material.define("fragment","sample_per_frame",this._sampleperframe),this._ssrpass.material.define("fragment","total_samples",this._totalsamples),this._downscale=1}xe.import("@export ecgl.ssr.main\n\n#define shader_name ssr\n#define max_iteration 20;\n#define sample_per_frame 5;\n#define total_samples 128;\n\nuniform sampler2d sourcetexture;\nuniform sampler2d gbuffertexture1;\nuniform sampler2d gbuffertexture2;\nuniform sampler2d gbuffertexture3;\nuniform samplercube specularcubemap;\nuniform float specularintensity: 1;\n\nuniform mat4 projection;\nuniform mat4 projectioninv;\nuniform mat4 toviewspace;\nuniform mat4 toworldspace;\n\nuniform float maxraydistance: 200;\n\nuniform float pixelstride: 16;\nuniform float pixelstridezcutoff: 50; \nuniform float screenedgefadestart: 0.9; \nuniform float eyefadestart : 0.2; uniform float eyefadeend: 0.8; \nuniform float minglossiness: 0.2; uniform float zthicknessthreshold: 1;\n\nuniform float nearz;\nuniform vec2 viewportsize : viewport_size;\n\nuniform float jitteroffset: 0;\n\nvarying vec2 v_texcoord;\n\n#ifdef depth_decode\n@import clay.util.decode_float\n#endif\n\n#ifdef physically_correct\nuniform sampler2d normaldistribution;\nuniform float sampleoffset: 0;\nuniform vec2 normaldistributionsize;\n\nvec3 transformnormal(vec3 h, vec3 n) {\n vec3 upvector = n.y > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);\n vec3 tangentx = normalize(cross(n, upvector));\n vec3 tangentz = cross(n, tangentx);\n return normalize(tangentx * h.x + n * h.y + tangentz * h.z);\n}\nvec3 importancesamplenormalggx(float i, float roughness, vec3 n) {\n float p = fract((i + sampleoffset) / float(total_samples));\n vec3 h = texture2d(normaldistribution,vec2(roughness, p)).rgb;\n return transformnormal(h, n);\n}\nfloat g_smith(float g, float ndv, float ndl) {\n float roughness = 1.0 - g;\n float k = roughness * roughness / 2.0;\n float g1v = ndv / (ndv * (1.0 - k) + k);\n float g1l = ndl / (ndl * (1.0 - k) + k);\n return g1l * g1v;\n}\nvec3 f_schlick(float ndv, vec3 spec) {\n return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0);\n}\n#endif\n\nfloat fetchdepth(sampler2d depthtexture, vec2 uv)\n{\n vec4 depthtexel = texture2d(depthtexture, uv);\n return depthtexel.r * 2.0 - 1.0;\n}\n\nfloat lineardepth(float depth)\n{\n if (projection[3][3] == 0.0) {\n return projection[3][2] / (depth * projection[2][3] - projection[2][2]);\n }\n else {\n return (depth - projection[3][2]) / projection[2][2];\n }\n}\n\nbool rayintersectdepth(float rayznear, float rayzfar, vec2 hitpixel)\n{\n if (rayzfar > rayznear)\n {\n float t = rayzfar; rayzfar = rayznear; rayznear = t;\n }\n float cameraz = lineardepth(fetchdepth(gbuffertexture2, hitpixel));\n return rayzfar <= cameraz && rayznear >= cameraz - zthicknessthreshold;\n}\n\n\nbool tracescreenspaceray(\n vec3 rayorigin, vec3 raydir, float jitter,\n out vec2 hitpixel, out vec3 hitpoint, out float iterationcount\n)\n{\n float raylength = ((rayorigin.z + raydir.z * maxraydistance) > -nearz)\n ? (-nearz - rayorigin.z) / raydir.z : maxraydistance;\n\n vec3 rayend = rayorigin + raydir * raylength;\n\n vec4 h0 = projection * vec4(rayorigin, 1.0);\n vec4 h1 = projection * vec4(rayend, 1.0);\n\n float k0 = 1.0 / h0.w, k1 = 1.0 / h1.w;\n\n vec3 q0 = rayorigin * k0, q1 = rayend * k1;\n\n vec2 p0 = (h0.xy * k0 * 0.5 + 0.5) * viewportsize;\n vec2 p1 = (h1.xy * k1 * 0.5 + 0.5) * viewportsize;\n\n p1 += dot(p1 - p0, p1 - p0) < 0.0001 ? 0.01 : 0.0;\n vec2 delta = p1 - p0;\n\n bool permute = false;\n if (abs(delta.x) < abs(delta.y)) {\n permute = true;\n delta = delta.yx;\n p0 = p0.yx;\n p1 = p1.yx;\n }\n float stepdir = sign(delta.x);\n float invdx = stepdir / delta.x;\n\n vec3 dq = (q1 - q0) * invdx;\n float dk = (k1 - k0) * invdx;\n\n vec2 dp = vec2(stepdir, delta.y * invdx);\n\n float stridescaler = 1.0 - min(1.0, -rayorigin.z / pixelstridezcutoff);\n float pixstride = 1.0 + stridescaler * pixelstride;\n\n dp *= pixstride; dq *= pixstride; dk *= pixstride;\n\n vec4 pqk = vec4(p0, q0.z, k0);\n vec4 dpqk = vec4(dp, dq.z, dk);\n\n pqk += dpqk * jitter;\n float rayzfar = (dpqk.z * 0.5 + pqk.z) / (dpqk.w * 0.5 + pqk.w);\n float rayznear;\n\n bool intersect = false;\n\n vec2 texelsize = 1.0 / viewportsize;\n\n iterationcount = 0.0;\n\n for (int i = 0; i < max_iteration; i++)\n {\n pqk += dpqk;\n\n rayznear = rayzfar;\n rayzfar = (dpqk.z * 0.5 + pqk.z) / (dpqk.w * 0.5 + pqk.w);\n\n hitpixel = permute ? pqk.yx : pqk.xy;\n hitpixel *= texelsize;\n\n intersect = rayintersectdepth(rayznear, rayzfar, hitpixel);\n\n iterationcount += 1.0;\n\n dpqk *= 1.2;\n\n if (intersect) {\n break;\n }\n }\n\n q0.xy += dq.xy * iterationcount;\n q0.z = pqk.z;\n hitpoint = q0 / pqk.w;\n\n return intersect;\n}\n\nfloat calculatealpha(\n float iterationcount, float reflectivity,\n vec2 hitpixel, vec3 hitpoint, float dist, vec3 raydir\n)\n{\n float alpha = clamp(reflectivity, 0.0, 1.0);\n alpha *= 1.0 - (iterationcount / float(max_iteration));\n vec2 hitpixelndc = hitpixel * 2.0 - 1.0;\n float maxdimension = min(1.0, max(abs(hitpixelndc.x), abs(hitpixelndc.y)));\n alpha *= 1.0 - max(0.0, maxdimension - screenedgefadestart) / (1.0 - screenedgefadestart);\n\n float _eyefadestart = eyefadestart;\n float _eyefadeend = eyefadeend;\n if (_eyefadestart > _eyefadeend) {\n float tmp = _eyefadeend;\n _eyefadeend = _eyefadestart;\n _eyefadestart = tmp;\n }\n\n float eyedir = clamp(raydir.z, _eyefadestart, _eyefadeend);\n alpha *= 1.0 - (eyedir - _eyefadestart) / (_eyefadeend - _eyefadestart);\n\n alpha *= 1.0 - clamp(dist / maxraydistance, 0.0, 1.0);\n\n return alpha;\n}\n\n@import clay.util.rand\n\n@import clay.util.rgbm\n\nvoid main()\n{\n vec4 normalandgloss = texture2d(gbuffertexture1, v_texcoord);\n\n if (dot(normalandgloss.rgb, vec3(1.0)) == 0.0) {\n discard;\n }\n\n float g = normalandgloss.a;\n#if !defined(physically_correct)\n if (g <= minglossiness) {\n discard;\n }\n#endif\n\n float reflectivity = (g - minglossiness) / (1.0 - minglossiness);\n\n vec3 n = normalize(normalandgloss.rgb * 2.0 - 1.0);\n n = normalize((toviewspace * vec4(n, 0.0)).xyz);\n\n vec4 projectedpos = vec4(v_texcoord * 2.0 - 1.0, fetchdepth(gbuffertexture2, v_texcoord), 1.0);\n vec4 pos = projectioninv * projectedpos;\n vec3 rayorigin = pos.xyz / pos.w;\n vec3 v = -normalize(rayorigin);\n\n float ndv = clamp(dot(n, v), 0.0, 1.0);\n float iterationcount;\n float jitter = rand(fract(v_texcoord + jitteroffset));\n\n#ifdef physically_correct\n vec4 color = vec4(vec3(0.0), 1.0);\n vec4 albedometalness = texture2d(gbuffertexture3, v_texcoord);\n vec3 albedo = albedometalness.rgb;\n float m = albedometalness.a;\n vec3 diffusecolor = albedo * (1.0 - m);\n vec3 spec = mix(vec3(0.04), albedo, m);\n\n float jitter2 = rand(fract(v_texcoord)) * float(total_samples);\n\n for (int i = 0; i < sample_per_frame; i++) {\n vec3 h = importancesamplenormalggx(float(i) + jitter2, 1.0 - g, n);\n vec3 raydir = normalize(reflect(-v, h));\n#else\n vec3 raydir = normalize(reflect(-v, n));\n#endif\n vec2 hitpixel;\n vec3 hitpoint;\n\n bool intersect = tracescreenspaceray(rayorigin, raydir, jitter, hitpixel, hitpoint, iterationcount);\n\n float dist = distance(rayorigin, hitpoint);\n\n vec3 hitnormal = texture2d(gbuffertexture1, hitpixel).rgb * 2.0 - 1.0;\n hitnormal = normalize((toviewspace * vec4(hitnormal, 0.0)).xyz);\n#ifdef physically_correct\n float ndl = clamp(dot(n, raydir), 0.0, 1.0);\n float vdh = clamp(dot(v, h), 0.0, 1.0);\n float ndh = clamp(dot(n, h), 0.0, 1.0);\n vec3 littexel = vec3(0.0);\n if (dot(hitnormal, raydir) < 0.0 && intersect) {\n littexel = texture2d(sourcetexture, hitpixel).rgb;\n littexel *= pow(clamp(1.0 - dist / 200.0, 0.0, 1.0), 3.0);\n\n }\n else {\n #ifdef specularcubemap_enabled\n vec3 raydirw = normalize(toworldspace * vec4(raydir, 0.0)).rgb;\n littexel = rgbmdecode(texturecubelodext(specularcubemap, raydirw, 0.0), 8.12).rgb * specularintensity;\n#endif\n }\n color.rgb += ndl * littexel * (\n f_schlick(ndl, spec) * g_smith(g, ndv, ndl) * vdh / (ndh * ndv + 0.001)\n );\n }\n color.rgb /= float(sample_per_frame);\n#else\n #if !defined(specularcubemap_enabled)\n if (dot(hitnormal, raydir) >= 0.0) {\n discard;\n }\n if (!intersect) {\n discard;\n }\n#endif\n float alpha = clamp(calculatealpha(iterationcount, reflectivity, hitpixel, hitpoint, dist, raydir), 0.0, 1.0);\n vec4 color = texture2d(sourcetexture, hitpixel);\n color.rgb *= alpha;\n\n#ifdef specularcubemap_enabled\n vec3 raydirw = normalize(toworldspace * vec4(raydir, 0.0)).rgb;\n alpha = alpha * (intersect ? 1.0 : 0.0);\n float bias = (1.0 -g) * 5.0;\n color.rgb += (1.0 - alpha)\n * rgbmdecode(texturecubelodext(specularcubemap, raydirw, bias), 8.12).rgb\n * specularintensity;\n#endif\n\n#endif\n\n gl_fragcolor = encodehdr(color);\n}\n@end\n\n@export ecgl.ssr.blur\n\nuniform sampler2d texture;\nuniform sampler2d gbuffertexture1;\nuniform sampler2d gbuffertexture2;\nuniform mat4 projection;\nuniform float depthrange : 0.05;\n\nvarying vec2 v_texcoord;\n\nuniform vec2 texturesize;\nuniform float blursize : 1.0;\n\n#ifdef blend\n #ifdef ssaotex_enabled\nuniform sampler2d ssaotex;\n #endif\nuniform sampler2d sourcetexture;\n#endif\n\nfloat getlineardepth(vec2 coord)\n{\n float depth = texture2d(gbuffertexture2, coord).r * 2.0 - 1.0;\n return projection[3][2] / (depth * projection[2][3] - projection[2][2]);\n}\n\n@import clay.util.rgbm\n\n\nvoid main()\n{\n @import clay.compositor.kernel.gaussian_9\n\n vec4 centerntexel = texture2d(gbuffertexture1, v_texcoord);\n float g = centerntexel.a;\n float maxblursize = clamp(1.0 - g, 0.0, 1.0) * blursize;\n#ifdef vertical\n vec2 off = vec2(0.0, maxblursize / texturesize.y);\n#else\n vec2 off = vec2(maxblursize / texturesize.x, 0.0);\n#endif\n\n vec2 coord = v_texcoord;\n\n vec4 sum = vec4(0.0);\n float weightall = 0.0;\n\n vec3 cn = centerntexel.rgb * 2.0 - 1.0;\n float cd = getlineardepth(v_texcoord);\n for (int i = 0; i < 9; i++) {\n vec2 coord = clamp((float(i) - 4.0) * off + v_texcoord, vec2(0.0), vec2(1.0));\n float w = gaussiankernel[i]\n * clamp(dot(cn, texture2d(gbuffertexture1, coord).rgb * 2.0 - 1.0), 0.0, 1.0);\n float d = getlineardepth(coord);\n w *= (1.0 - smoothstep(abs(cd - d) / depthrange, 0.0, 1.0));\n\n weightall += w;\n sum += decodehdr(texture2d(texture, coord)) * w;\n }\n\n#ifdef blend\n float aofactor = 1.0;\n #ifdef ssaotex_enabled\n aofactor = texture2d(ssaotex, v_texcoord).r;\n #endif\n gl_fragcolor = encodehdr(\n sum / weightall * aofactor + decodehdr(texture2d(sourcetexture, v_texcoord))\n );\n#else\n gl_fragcolor = encodehdr(sum / weightall);\n#endif\n}\n\n@end"),gl.prototype.setambientcubemap=function(e,t){this._ssrpass.material.set("specularcubemap",e),this._ssrpass.material.set("specularintensity",t);var r=e&&t;this._ssrpass.material[r?"enabletexture":"disabletexture"]("specularcubemap")},gl.prototype.update=function(e,t,r,i){var n=e.getwidth(),a=e.getheight(),o=this._ssrtexture,s=this._texture2,l=this._texture3;o.width=this._prevtexture.width=this._currenttexture.width=n/this._downscale,o.height=this._prevtexture.height=this._currenttexture.height=a/this._downscale,s.width=l.width=n,s.height=l.height=a;var h=this._framebuffer,u=this._ssrpass,c=this._blurpass1,d=this._blurpass2,f=this._blendpass,p=new ht,m=new ht;ht.transpose(p,t.worldtransform),ht.transpose(m,t.viewmatrix),u.setuniform("sourcetexture",r),u.setuniform("projection",t.projectionmatrix.array),u.setuniform("projectioninv",t.invprojectionmatrix.array),u.setuniform("toviewspace",p.array),u.setuniform("toworldspace",m.array),u.setuniform("nearz",t.near);var g=i/this._totalsamples*this._sampleperframe;if(u.setuniform("jitteroffset",g),u.setuniform("sampleoffset",i*this._sampleperframe),c.setuniform("texturesize",[o.width,o.height]),d.setuniform("texturesize",[n,a]),d.setuniform("sourcetexture",r),c.setuniform("projection",t.projectionmatrix.array),d.setuniform("projection",t.projectionmatrix.array),h.attach(o),h.bind(e),u.render(e),this._physicallycorrect&&(h.attach(this._currenttexture),f.setuniform("texture1",this._prevtexture),f.setuniform("texture2",o),f.material.set({weight1:i>=1?.95:0,weight2:i>=1?.05:1}),f.render(e)),h.attach(s),c.setuniform("texture",this._physicallycorrect?this._currenttexture:o),c.render(e),h.attach(l),d.setuniform("texture",s),d.render(e),h.unbind(e),this._physicallycorrect){var _=this._prevtexture;this._prevtexture=this._currenttexture,this._currenttexture=_}},gl.prototype.gettargettexture=function(){return this._texture3},gl.prototype.setparameter=function(e,t){"maxiteration"===e?this._ssrpass.material.define("fragment","max_iteration",t):this._ssrpass.setuniform(e,t)},gl.prototype.setphysicallycorrect=function(e){e?(this._normaldistribution||(this._normaldistribution=_n.generatenormaldistribution(64,this._totalsamples)),this._ssrpass.material.define("fragment","physically_correct"),this._ssrpass.material.set("normaldistribution",this._normaldistribution),this._ssrpass.material.set("normaldistributionsize",[64,this._totalsamples])):this._ssrpass.material.undefine("fragment","physically_correct"),this._physicallycorrect=e},gl.prototype.setssaotexture=function(e){var t=this._blurpass2;e?(t.material.enabletexture("ssaotex"),t.material.set("ssaotex",e)):t.material.disabletexture("ssaotex")},gl.prototype.isfinished=function(e){return!this._physicallycorrect||e>this._totalsamples/this._sampleperframe},gl.prototype.dispose=function(e){this._ssrtexture.dispose(e),this._texture2.dispose(e),this._texture3.dispose(e),this._prevtexture.dispose(e),this._currenttexture.dispose(e),this._framebuffer.dispose(e)};const _l=gl,vl=[0,0,-.321585265978,-.154972575841,.458126042375,.188473391593,.842080129861,.527766490688,.147304551086,-.659453822776,-.331943915203,-.940619700594,.0479226680259,.54812163202,.701581552186,-.709825561388,-.295436780218,.940589268233,-.901489676764,.237713156085,.973570876096,-.109899459384,-.866792314779,-.451805525005,.330975007087,.800048655954,-.344275183665,.381779221166,-.386139432542,-.437418421534,-.576478634965,-.0148463392551,.385798197415,-.262426961053,-.666302061145,.682427250835,-.628010632582,-.732836215494,.10163141741,-.987658134403,.711995289051,-.320024291314,.0296005138058,.950296523438,.0130612307608,-.351024443122,-.879596633704,-.10478487883,.435712737232,.504254490347,.779203817497,.206477676721,.388264289969,-.896736162545,-.153106280781,-.629203242522,-.245517550697,.657969239148,.126830499058,.26862328493,-.634888119007,-.302301223431,.617074219636,.779817204925];function yl(e,t,r,i,n){var a=e.gl;t.setuniform(a,"1i",r,n),a.activetexture(a.texture0+n),i.isrenderable()?i.bind(e):i.unbind(e)}function xl(e,t,r,i,n){var a,o,s,l,h=e.gl;return function(n,u,c){if(!l||l.material!==n.material){var d=n.material,f=n.__program,p=d.get("roughness");null==p&&(p=1);var m=d.get("normalmap")||t,g=d.get("roughnessmap"),_=d.get("bumpmap"),v=d.get("uvrepeat"),y=d.get("uvoffset"),x=d.get("detailuvrepeat"),b=d.get("detailuvoffset"),w=!!_&&d.istextureenabled("bumpmap"),t=!!g&&d.istextureenabled("roughnessmap"),s=d.isdefined("fragment","double_sided");_=_||r,g=g||i,c!==u?(u.set("normalmap",m),u.set("bumpmap",_),u.set("roughnessmap",g),u.set("usebumpmap",w),u.set("useroughnessmap",t),u.set("doubleside",s),null!=v&&u.set("uvrepeat",v),null!=y&&u.set("uvoffset",y),null!=x&&u.set("detailuvrepeat",x),null!=b&&u.set("detailuvoffset",b),u.set("roughness",p)):(f.setuniform(h,"1f","roughness",p),a!==m&&yl(e,f,"normalmap",m,0),o!==_&&_&&yl(e,f,"bumpmap",_,1),s!==g&&g&&yl(e,f,"roughnessmap",g,2),null!=v&&f.setuniform(h,"2f","uvrepeat",v),null!=y&&f.setuniform(h,"2f","uvoffset",y),null!=x&&f.setuniform(h,"2f","detailuvrepeat",x),null!=b&&f.setuniform(h,"2f","detailuvoffset",b),f.setuniform(h,"1i","usebumpmap",+w),f.setuniform(h,"1i","useroughnessmap",+t),f.setuniform(h,"1i","doubleside",+s)),a=m,o=_,s=g,l=n}}}function bl(e){e=e||{},this._depthtex=new dr({format:wr.depth_component,type:wr.unsigned_int}),this._normaltex=new dr({type:wr.half_float}),this._framebuffer=new zi,this._framebuffer.attach(this._normaltex),this._framebuffer.attach(this._depthtex,zi.depth_attachment),this._normalmaterial=new le({shader:new xe(xe.source("ecgl.normal.vertex"),xe.source("ecgl.normal.fragment"))}),this._normalmaterial.enabletexture(["normalmap","bumpmap","roughnessmap"]),this._defaultnormalmap=an.createblank("#000"),this._defaultbumpmap=an.createblank("#000"),this._defaultroughessmap=an.createblank("#000"),this._debugpass=new pn({fragment:xe.source("clay.compositor.output")}),this._debugpass.setuniform("texture",this._normaltex),this._debugpass.material.undefine("fragment","output_alpha")}xe.import("@export ecgl.normal.vertex\n\n@import ecgl.common.transformuniforms\n\n@import ecgl.common.uv.header\n\n@import ecgl.common.attributes\n\nvarying vec3 v_normal;\nvarying vec3 v_worldposition;\n\n@import ecgl.common.normalmap.vertexheader\n\n@import ecgl.common.vertexanimation.header\n\nvoid main()\n{\n\n @import ecgl.common.vertexanimation.main\n\n @import ecgl.common.uv.main\n\n v_normal = normalize((worldinversetranspose * vec4(normal, 0.0)).xyz);\n v_worldposition = (world * vec4(pos, 1.0)).xyz;\n\n @import ecgl.common.normalmap.vertexmain\n\n gl_position = worldviewprojection * vec4(pos, 1.0);\n\n}\n\n\n@end\n\n\n@export ecgl.normal.fragment\n\n#define roughness_chanel 0\n\nuniform bool usebumpmap;\nuniform bool useroughnessmap;\nuniform bool doubleside;\nuniform float roughness;\n\n@import ecgl.common.uv.fragmentheader\n\nvarying vec3 v_normal;\nvarying vec3 v_worldposition;\n\nuniform mat4 viewinverse : viewinverse;\n\n@import ecgl.common.normalmap.fragmentheader\n@import ecgl.common.bumpmap.header\n\nuniform sampler2d roughnessmap;\n\nvoid main()\n{\n vec3 n = v_normal;\n \n bool flipnormal = false;\n if (doubleside) {\n vec3 eyepos = viewinverse[3].xyz;\n vec3 v = normalize(eyepos - v_worldposition);\n\n if (dot(n, v) < 0.0) {\n flipnormal = true;\n }\n }\n\n @import ecgl.common.normalmap.fragmentmain\n\n if (usebumpmap) {\n n = bumpnormal(v_worldposition, v_normal, n);\n }\n\n float g = 1.0 - roughness;\n\n if (useroughnessmap) {\n float g2 = 1.0 - texture2d(roughnessmap, v_detailtexcoord)[roughness_chanel];\n g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0);\n }\n\n if (flipnormal) {\n n = -n;\n }\n\n gl_fragcolor.rgb = (n.xyz + 1.0) * 0.5;\n gl_fragcolor.a = g;\n}\n@end"),bl.prototype.getdepthtexture=function(){return this._depthtex},bl.prototype.getnormaltexture=function(){return this._normaltex},bl.prototype.update=function(e,t,r){var i=e.getwidth(),n=e.getheight(),a=this._depthtex,o=this._normaltex,s=this._normalmaterial;a.width=i,a.height=n,o.width=i,o.height=n;var l=t.getrenderlist(r).opaque;this._framebuffer.bind(e),e.gl.clearcolor(0,0,0,0),e.gl.clear(e.gl.color_buffer_bit|e.gl.depth_buffer_bit),e.gl.disable(e.gl.blend),e.renderpass(l,r,{getmaterial:function(){return s},ifrender:function(e){return e.rendernormal},beforerender:xl(e,this._defaultnormalmap,this._defaultbumpmap,this._defaultroughessmap,this._normalmaterial),sort:e.opaquesortcompare}),this._framebuffer.unbind(e)},bl.prototype.renderdebug=function(e){this._debugpass.render(e)},bl.prototype.dispose=function(e){this._depthtex.dispose(e),this._normaltex.dispose(e)};const wl=bl;function tl(e){e=e||{},this._edgepass=new pn({fragment:xe.source("ecgl.edge")}),this._edgepass.setuniform("normaltexture",e.normaltexture),this._edgepass.setuniform("depthtexture",e.depthtexture),this._targettexture=new dr({type:wr.half_float}),this._framebuffer=new zi,this._framebuffer.attach(this._targettexture)}tl.prototype.update=function(e,t,r,i){var n=e.getwidth(),a=e.getheight(),o=this._targettexture;o.width=n,o.height=a;var s=this._framebuffer;s.bind(e),this._edgepass.setuniform("projectioninv",t.invprojectionmatrix.array),this._edgepass.setuniform("texturesize",[n,a]),this._edgepass.setuniform("texture",r),this._edgepass.render(e),s.unbind(e)},tl.prototype.gettargettexture=function(){return this._targettexture},tl.prototype.setparameter=function(e,t){this._edgepass.setuniform(e,t)},tl.prototype.dispose=function(e){this._targettexture.dispose(e),this._framebuffer.dispose(e)};const sl=tl,ml={type:"compositor",nodes:[{name:"source",type:"texture",outputs:{color:{}}},{name:"source_half",shader:"#source(clay.compositor.downsample)",inputs:{texture:"source"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 2)",height:"expr(height * 1.0 / 2)",type:"half_float"}}},parameters:{texturesize:"expr( [width * 1.0, height * 1.0] )"}},{name:"bright",shader:"#source(clay.compositor.bright)",inputs:{texture:"source_half"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 2)",height:"expr(height * 1.0 / 2)",type:"half_float"}}},parameters:{threshold:2,scale:4,texturesize:"expr([width * 1.0 / 2, height / 2])"}},{name:"bright_downsample_4",shader:"#source(clay.compositor.downsample)",inputs:{texture:"bright"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 4)",height:"expr(height * 1.0 / 4)",type:"half_float"}}},parameters:{texturesize:"expr( [width * 1.0 / 2, height / 2] )"}},{name:"bright_downsample_8",shader:"#source(clay.compositor.downsample)",inputs:{texture:"bright_downsample_4"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 8)",height:"expr(height * 1.0 / 8)",type:"half_float"}}},parameters:{texturesize:"expr( [width * 1.0 / 4, height / 4] )"}},{name:"bright_downsample_16",shader:"#source(clay.compositor.downsample)",inputs:{texture:"bright_downsample_8"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 16)",height:"expr(height * 1.0 / 16)",type:"half_float"}}},parameters:{texturesize:"expr( [width * 1.0 / 8, height / 8] )"}},{name:"bright_downsample_32",shader:"#source(clay.compositor.downsample)",inputs:{texture:"bright_downsample_16"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 32)",height:"expr(height * 1.0 / 32)",type:"half_float"}}},parameters:{texturesize:"expr( [width * 1.0 / 16, height / 16] )"}},{name:"bright_upsample_16_blur_h",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_downsample_32"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 16)",height:"expr(height * 1.0 / 16)",type:"half_float"}}},parameters:{blursize:1,blurdir:0,texturesize:"expr( [width * 1.0 / 32, height / 32] )"}},{name:"bright_upsample_16_blur_v",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_upsample_16_blur_h"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 16)",height:"expr(height * 1.0 / 16)",type:"half_float"}}},parameters:{blursize:1,blurdir:1,texturesize:"expr( [width * 1.0 / 16, height * 1.0 / 16] )"}},{name:"bright_upsample_8_blur_h",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_downsample_16"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 8)",height:"expr(height * 1.0 / 8)",type:"half_float"}}},parameters:{blursize:1,blurdir:0,texturesize:"expr( [width * 1.0 / 16, height * 1.0 / 16] )"}},{name:"bright_upsample_8_blur_v",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_upsample_8_blur_h"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 8)",height:"expr(height * 1.0 / 8)",type:"half_float"}}},parameters:{blursize:1,blurdir:1,texturesize:"expr( [width * 1.0 / 8, height * 1.0 / 8] )"}},{name:"bright_upsample_8_blend",shader:"#source(clay.compositor.blend)",inputs:{texture1:"bright_upsample_8_blur_v",texture2:"bright_upsample_16_blur_v"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 8)",height:"expr(height * 1.0 / 8)",type:"half_float"}}},parameters:{weight1:.3,weight2:.7}},{name:"bright_upsample_4_blur_h",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_downsample_8"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 4)",height:"expr(height * 1.0 / 4)",type:"half_float"}}},parameters:{blursize:1,blurdir:0,texturesize:"expr( [width * 1.0 / 8, height * 1.0 / 8] )"}},{name:"bright_upsample_4_blur_v",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_upsample_4_blur_h"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 4)",height:"expr(height * 1.0 / 4)",type:"half_float"}}},parameters:{blursize:1,blurdir:1,texturesize:"expr( [width * 1.0 / 4, height * 1.0 / 4] )"}},{name:"bright_upsample_4_blend",shader:"#source(clay.compositor.blend)",inputs:{texture1:"bright_upsample_4_blur_v",texture2:"bright_upsample_8_blend"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 4)",height:"expr(height * 1.0 / 4)",type:"half_float"}}},parameters:{weight1:.3,weight2:.7}},{name:"bright_upsample_2_blur_h",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_downsample_4"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 2)",height:"expr(height * 1.0 / 2)",type:"half_float"}}},parameters:{blursize:1,blurdir:0,texturesize:"expr( [width * 1.0 / 4, height * 1.0 / 4] )"}},{name:"bright_upsample_2_blur_v",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_upsample_2_blur_h"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 2)",height:"expr(height * 1.0 / 2)",type:"half_float"}}},parameters:{blursize:1,blurdir:1,texturesize:"expr( [width * 1.0 / 2, height * 1.0 / 2] )"}},{name:"bright_upsample_2_blend",shader:"#source(clay.compositor.blend)",inputs:{texture1:"bright_upsample_2_blur_v",texture2:"bright_upsample_4_blend"},outputs:{color:{parameters:{width:"expr(width * 1.0 / 2)",height:"expr(height * 1.0 / 2)",type:"half_float"}}},parameters:{weight1:.3,weight2:.7}},{name:"bright_upsample_full_blur_h",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"half_float"}}},parameters:{blursize:1,blurdir:0,texturesize:"expr( [width * 1.0 / 2, height * 1.0 / 2] )"}},{name:"bright_upsample_full_blur_v",shader:"#source(clay.compositor.gaussian_blur)",inputs:{texture:"bright_upsample_full_blur_h"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"half_float"}}},parameters:{blursize:1,blurdir:1,texturesize:"expr( [width * 1.0, height * 1.0] )"}},{name:"bloom_composite",shader:"#source(clay.compositor.blend)",inputs:{texture1:"bright_upsample_full_blur_v",texture2:"bright_upsample_2_blend"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"half_float"}}},parameters:{weight1:.3,weight2:.7}},{name:"coc",shader:"#source(ecgl.dof.coc)",outputs:{color:{parameters:{minfilter:"nearest",magfilter:"nearest",width:"expr(width * 1.0)",height:"expr(height * 1.0)"}}},parameters:{focaldist:50,focalrange:30}},{name:"dof_far_blur",shader:"#source(ecgl.dof.diskblur)",inputs:{texture:"source",coc:"coc"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"half_float"}}},parameters:{texturesize:"expr( [width * 1.0, height * 1.0] )"}},{name:"dof_near_blur",shader:"#source(ecgl.dof.diskblur)",inputs:{texture:"source",coc:"coc"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"half_float"}}},parameters:{texturesize:"expr( [width * 1.0, height * 1.0] )"},defines:{blur_nearfield:null}},{name:"dof_coc_blur",shader:"#source(ecgl.dof.diskblur)",inputs:{texture:"coc"},outputs:{color:{parameters:{minfilter:"nearest",magfilter:"nearest",width:"expr(width * 1.0)",height:"expr(height * 1.0)"}}},parameters:{texturesize:"expr( [width * 1.0, height * 1.0] )"},defines:{blur_coc:null}},{name:"dof_composite",shader:"#source(ecgl.dof.composite)",inputs:{original:"source",blurred:"dof_far_blur",nearfield:"dof_near_blur",coc:"coc",nearcoc:"dof_coc_blur"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)",type:"half_float"}}}},{name:"composite",shader:"#source(clay.compositor.hdr.composite)",inputs:{texture:"source",bloom:"bloom_composite"},outputs:{color:{parameters:{width:"expr(width * 1.0)",height:"expr(height * 1.0)"}}},defines:{}},{name:"fxaa",shader:"#source(clay.compositor.fxaa)",inputs:{texture:"composite"}}]};function al(e,t){return{color:{parameters:{width:e,height:t}}}}xe.import(zs),xe.import(ys),xe.import(ks),xe.import(qs),xe.import(js),xe.import($s),xe.import(el),xe.import(tl),xe.import(rl),xe.import("@export ecgl.dof.coc\n\nuniform sampler2d depth;\n\nuniform float znear: 0.1;\nuniform float zfar: 2000;\n\nuniform float focaldistance: 3;\nuniform float focalrange: 1;\nuniform float focallength: 30;\nuniform float fstop: 2.8;\n\nvarying vec2 v_texcoord;\n\n@import clay.util.encode_float\n\nvoid main()\n{\n float z = texture2d(depth, v_texcoord).r * 2.0 - 1.0;\n\n float dist = 2.0 * znear * zfar / (zfar + znear - z * (zfar - znear));\n\n float aperture = focallength / fstop;\n\n float coc;\n\n float uppper = focaldistance + focalrange;\n float lower = focaldistance - focalrange;\n if (dist <= uppper && dist >= lower) {\n coc = 0.5;\n }\n else {\n float focaladjusted = dist > uppper ? uppper : lower;\n\n coc = abs(aperture * (focallength * (dist - focaladjusted)) / (dist * (focaladjusted - focallength)));\n coc = clamp(coc, 0.0, 2.0) / 2.00001;\n\n if (dist < lower) {\n coc = -coc;\n }\n coc = coc * 0.5 + 0.5;\n }\n\n gl_fragcolor = encodefloat(coc);\n}\n@end\n\n\n@export ecgl.dof.composite\n\n#define debug 0\n\nuniform sampler2d original;\nuniform sampler2d blurred;\nuniform sampler2d nearfield;\nuniform sampler2d coc;\nuniform sampler2d nearcoc;\nvarying vec2 v_texcoord;\n\n@import clay.util.rgbm\n@import clay.util.float\n\nvoid main()\n{\n vec4 blurredcolor = texture2d(blurred, v_texcoord);\n vec4 originalcolor = texture2d(original, v_texcoord);\n\n float fcoc = decodefloat(texture2d(coc, v_texcoord));\n\n fcoc = abs(fcoc * 2.0 - 1.0);\n\n float weight = smoothstep(0.0, 1.0, fcoc);\n \n#ifdef nearfield_enabled\n vec4 nearfieldcolor = texture2d(nearfield, v_texcoord);\n float fnearcoc = decodefloat(texture2d(nearcoc, v_texcoord));\n fnearcoc = abs(fnearcoc * 2.0 - 1.0);\n\n gl_fragcolor = encodehdr(\n mix(\n nearfieldcolor, mix(originalcolor, blurredcolor, weight),\n pow(1.0 - fnearcoc, 4.0)\n )\n );\n#else\n gl_fragcolor = encodehdr(mix(originalcolor, blurredcolor, weight));\n#endif\n\n}\n\n@end\n\n\n\n@export ecgl.dof.diskblur\n\n#define poisson_kernel_size 16;\n\nuniform sampler2d texture;\nuniform sampler2d coc;\nvarying vec2 v_texcoord;\n\nuniform float blurradius : 10.0;\nuniform vec2 texturesize : [512.0, 512.0];\n\nuniform vec2 poissonkernel[poisson_kernel_size];\n\nuniform float percent;\n\nfloat nrand(const in vec2 n) {\n return fract(sin(dot(n.xy ,vec2(12.9898,78.233))) * 43758.5453);\n}\n\n@import clay.util.rgbm\n@import clay.util.float\n\n\nvoid main()\n{\n vec2 offset = blurradius / texturesize;\n\n float rnd = 6.28318 * nrand(v_texcoord + 0.07 * percent );\n float cosa = cos(rnd);\n float sina = sin(rnd);\n vec4 basis = vec4(cosa, -sina, sina, cosa);\n\n#if !defined(blur_nearfield) && !defined(blur_coc)\n offset *= abs(decodefloat(texture2d(coc, v_texcoord)) * 2.0 - 1.0);\n#endif\n\n#ifdef blur_coc\n float cocsum = 0.0;\n#else\n vec4 color = vec4(0.0);\n#endif\n\n\n float weightsum = 0.0;\n\n for (int i = 0; i < poisson_kernel_size; i++) {\n vec2 ofs = poissonkernel[i];\n\n ofs = vec2(dot(ofs, basis.xy), dot(ofs, basis.zw));\n\n vec2 uv = v_texcoord + ofs * offset;\n vec4 texel = texture2d(texture, uv);\n\n float w = 1.0;\n#ifdef blur_coc\n float fcoc = decodefloat(texel) * 2.0 - 1.0;\n cocsum += clamp(fcoc, -1.0, 0.0) * w;\n#else\n texel = texel;\n #if !defined(blur_nearfield)\n float fcoc = decodefloat(texture2d(coc, uv)) * 2.0 - 1.0;\n w *= abs(fcoc);\n #endif\n texel.rgb *= texel.a;\n color += texel * w;\n#endif\n\n weightsum += w;\n }\n\n#ifdef blur_coc\n gl_fragcolor = encodefloat(clamp(cocsum / weightsum, -1.0, 0.0) * 0.5 + 0.5);\n#else\n color /= weightsum;\n color.rgb /= (color.a + 0.0001);\n gl_fragcolor = color;\n#endif\n}\n\n@end"),xe.import("@export ecgl.edge\n\nuniform sampler2d texture;\n\nuniform sampler2d normaltexture;\nuniform sampler2d depthtexture;\n\nuniform mat4 projectioninv;\n\nuniform vec2 texturesize;\n\nuniform vec4 edgecolor: [0,0,0,0.8];\n\nvarying vec2 v_texcoord;\n\nvec3 packcolor(vec2 coord) {\n float z = texture2d(depthtexture, coord).r * 2.0 - 1.0;\n vec4 p = vec4(v_texcoord * 2.0 - 1.0, z, 1.0);\n vec4 p4 = projectioninv * p;\n\n return vec3(\n texture2d(normaltexture, coord).rg,\n -p4.z / p4.w / 5.0\n );\n}\n\nvoid main() {\n vec2 cc = v_texcoord;\n vec3 center = packcolor(cc);\n\n float size = clamp(1.0 - (center.z - 10.0) / 100.0, 0.0, 1.0) * 0.5;\n float dx = size / texturesize.x;\n float dy = size / texturesize.y;\n\n vec2 coord;\n vec3 topleft = packcolor(cc+vec2(-dx, -dy));\n vec3 top = packcolor(cc+vec2(0.0, -dy));\n vec3 topright = packcolor(cc+vec2(dx, -dy));\n vec3 left = packcolor(cc+vec2(-dx, 0.0));\n vec3 right = packcolor(cc+vec2(dx, 0.0));\n vec3 bottomleft = packcolor(cc+vec2(-dx, dy));\n vec3 bottom = packcolor(cc+vec2(0.0, dy));\n vec3 bottomright = packcolor(cc+vec2(dx, dy));\n\n vec3 v = -topleft-2.0*top-topright+bottomleft+2.0*bottom+bottomright;\n vec3 h = -bottomleft-2.0*left-topleft+bottomright+2.0*right+topright;\n\n float edge = sqrt(dot(h, h) + dot(v, v));\n\n edge = smoothstep(0.8, 1.0, edge);\n\n gl_fragcolor = mix(texture2d(texture, v_texcoord), vec4(edgecolor.rgb, 1.0), edgecolor.a * edge);\n}\n@end");var el=["composite","fxaa"];function cl(){this._width,this._height,this._dpr,this._sourcetexture=new dr({type:wr.half_float}),this._depthtexture=new dr({format:wr.depth_component,type:wr.unsigned_int}),this._framebuffer=new zi,this._framebuffer.attach(this._sourcetexture),this._framebuffer.attach(this._depthtexture,zi.depth_attachment),this._normalpass=new wl,this._compositor=function(e,t){var r=new ws;t=t||{};var i={textures:{},parameters:{}};for(var n in e.parameters){var a=e.parameters[n];i.parameters[n]=sl(a)}return function(e,t,r,i){if(e.textures){var n={},a=0,o=!1,s=r.texturerootpath;f.each(e.textures,(function(e,t){var r,l=e.path,h=sl(e.parameters);if(array.isarray(l)&&6===l.length)s&&(l=l.map((function(e){return f.relative2absolute(e,s)}))),r=new ai(h);else{if("string"!=typeof l)return;s&&(l=f.relative2absolute(l,s)),r=new dr(h)}r.load(l),a++,r.once("success",(function(){n[t]=r,0==--a&&(i(n),o=!0)}))})),0!==a||o||i(n)}else i({})}(e,0,t,(function(n){i.textures=n,function(n,a){for(var o=0;o=this._haltonsequence.length},render:function(e,t,r){var i=this._blendpass;0===this._frame?(i.setuniform("weight1",0),i.setuniform("weight2",1)):(i.setuniform("weight1",.9),i.setuniform("weight2",.1)),i.setuniform("texture1",this._prevframetex),i.setuniform("texture2",t||this._sourcetex),this._blendfb.attach(this._outputtex),this._blendfb.bind(e),i.render(e),this._blendfb.unbind(e),r||(this._outputpass.setuniform("texture",this._outputtex),this._outputpass.render(e));var n=this._prevframetex;this._prevframetex=this._outputtex,this._outputtex=n,this._frame++},dispose:function(e){this._sourcefb.dispose(e),this._blendfb.dispose(e),this._prevframetex.dispose(e),this._outputtex.dispose(e),this._sourcetex.dispose(e),this._outputpass.dispose(e),this._blendpass.dispose(e)}};const pl=ll;function ol(e){e=e||"perspective",this.layer=null,this.scene=new vi,this.rootnode=this.scene,this.viewport={x:0,y:0,width:0,height:0},this.setprojection(e),this._compositor=new dl,this._temporalss=new pl,this._shadowmappass=new ks;for(var t=[],r=0,i=0;i<30;i++){for(var n=[],a=0;a<6;a++)n.push(4*ul(r,2)-2),n.push(4*ul(r,3)-2),r++;t.push(n)}this._pcfkernels=t,this.scene.on("beforerender",(function(e,t,r){this.needstemporalss()&&this._temporalss.jitterprojection(e,r)}),this)}ol.prototype.setprojection=function(e){var t=this.camera;t&&t.update(),"perspective"===e?this.camera instanceof ei||(this.camera=new ei,t&&this.camera.setlocaltransform(t.localtransform)):this.camera instanceof un||(this.camera=new un,t&&this.camera.setlocaltransform(t.localtransform)),this.camera.near=.1,this.camera.far=2e3},ol.prototype.setviewport=function(e,t,r,i,n){this.camera instanceof ei&&(this.camera.aspect=r/i),n=n||1,this.viewport.x=e,this.viewport.y=t,this.viewport.width=r,this.viewport.height=i,this.viewport.devicepixelratio=n,this._compositor.resize(r*n,i*n),this._temporalss.resize(r*n,i*n)},ol.prototype.containpoint=function(e,t){var r=this.viewport;return t=this.layer.renderer.getheight()-t,e>=r.x&&t>=r.y&&e<=r.x+r.width&&t<=r.y+r.height};var nl=new _e;ol.prototype.castray=function(e,t,r){var i=this.layer.renderer,n=i.viewport;return i.viewport=this.viewport,i.screentondc(e,t,nl),this.camera.castray(nl,r),i.viewport=n,r},ol.prototype.preparerender=function(){this.scene.update(),this.camera.update(),this.scene.updatelights();var e=this.scene.updaterenderlist(this.camera);this._needssortprogressively=!1;for(var t=0;t30},ol.prototype._dorender=function(e,t,r){var i=this.scene,n=this.camera;r=r||0,this._updatetransparent(e,i,n,r),t||(this._shadowmappass.kernelpcf=this._pcfkernels[0],this._shadowmappass.render(e,i,n,!0)),this._updateshadowpcfkernel(r);var a,o=e.clearcolor;e.gl.clearcolor(o[0],o[1],o[2],o[3]),this._enableposteffect&&(this.needstemporalss()&&this._temporalss.jitterprojection(e,n),this._compositor.updatenormal(e,i,n,this._temporalss.getframe())),this._updatessao(e,i,n,this._temporalss.getframe()),this._enableposteffect?((a=this._compositor.getsourceframebuffer()).bind(e),e.gl.clear(e.gl.depth_buffer_bit|e.gl.color_buffer_bit),e.render(i,n,!0,!0),a.unbind(e),this.needstemporalss()&&t?(this._compositor.composite(e,i,n,this._temporalss.getsourceframebuffer(),this._temporalss.getframe()),e.setviewport(this.viewport),this._temporalss.render(e)):(e.setviewport(this.viewport),this._compositor.composite(e,i,n,null,0))):this.needstemporalss()&&t?((a=this._temporalss.getsourceframebuffer()).bind(e),e.saveclear(),e.clearbit=e.gl.depth_buffer_bit|e.gl.color_buffer_bit,e.render(i,n,!0,!0),e.restoreclear(),a.unbind(e),e.setviewport(this.viewport),this._temporalss.render(e)):(e.setviewport(this.viewport),e.render(i,n,!0,!0))},ol.prototype._updatetransparent=function(e,t,r,i){for(var n=new vt,a=new ht,o=r.getworldposition(),s=t.getrenderlist(r).transparent,l=0;lthis.camera.far||e80*r){i=a=e[0],n=o=e[1];for(var p=r;pa&&(a=s),l>o&&(o=l);h=math.max(a-i,o-n)}return nh(d,f,r,i,n,h),f}function rh(e,t,r,i,n){var a,o;if(n===th(e,t,r,i)>0)for(a=t;a=t;a-=i)o=xh(a,e[a],e[a+1],o);return o&&gh(o,o.next)&&(bh(o),o=o.next),o}function ih(e,t){if(!e)return e;t||(t=e);var r,i=e;do{if(r=!1,i.steiner||!gh(i,i.next)&&0!==mh(i.prev,i,i.next))i=i.next;else{if(bh(i),(i=t=i.prev)===i.next)return null;r=!0}}while(r||i!==t);return t}function nh(e,t,r,i,n,a,o){if(e){!o&&a&&function(e,t,r,i){var n=e;do{null===n.z&&(n.z=ch(n.x,n.y,t,r,i)),n.prevz=n.prev,n.nextz=n.next,n=n.next}while(n!==e);n.prevz.nextz=null,n.prevz=null,function(e){var t,r,i,n,a,o,s,l,h=1;do{for(r=e,e=null,a=null,o=0;r;){for(o++,i=r,s=0,t=0;t0||l>0&&i;)0!==s&&(0===l||!i||r.z<=i.z)?(n=r,r=r.nextz,s--):(n=i,i=i.nextz,l--),a?a.nextz=n:e=n,n.prevz=a,a=n;r=i}a.nextz=null,h*=2}while(o>1)}(n)}(e,i,n,a);for(var s,l,h=e;e.prev!==e.next;)if(s=e.prev,l=e.next,a?oh(e,i,n,a):ah(e))t.push(s.i/r),t.push(e.i/r),t.push(l.i/r),bh(e),e=l.next,h=l.next;else if((e=l)===h){o?1===o?nh(e=sh(e,t,r),t,r,i,n,a,2):2===o&&lh(e,t,r,i,n,a):nh(ih(e),t,r,i,n,a,1);break}}}function ah(e){var t=e.prev,r=e,i=e.next;if(mh(t,r,i)>=0)return!1;for(var n=e.next.next;n!==e.prev;){if(fh(t.x,t.y,r.x,r.y,i.x,i.y,n.x,n.y)&&mh(n.prev,n,n.next)>=0)return!1;n=n.next}return!0}function oh(e,t,r,i){var n=e.prev,a=e,o=e.next;if(mh(n,a,o)>=0)return!1;for(var s=n.xa.x?n.x>o.x?n.x:o.x:a.x>o.x?a.x:o.x,u=n.y>a.y?n.y>o.y?n.y:o.y:a.y>o.y?a.y:o.y,c=ch(s,l,t,r,i),d=ch(h,u,t,r,i),f=e.nextz;f&&f.z<=d;){if(f!==e.prev&&f!==e.next&&fh(n.x,n.y,a.x,a.y,o.x,o.y,f.x,f.y)&&mh(f.prev,f,f.next)>=0)return!1;f=f.nextz}for(f=e.prevz;f&&f.z>=c;){if(f!==e.prev&&f!==e.next&&fh(n.x,n.y,a.x,a.y,o.x,o.y,f.x,f.y)&&mh(f.prev,f,f.next)>=0)return!1;f=f.prevz}return!0}function sh(e,t,r){var i=e;do{var n=i.prev,a=i.next.next;!gh(n,a)&&_h(n,i,i.next,a)&&vh(n,a)&&vh(a,n)&&(t.push(n.i/r),t.push(i.i/r),t.push(a.i/r),bh(i),bh(i.next),i=e=a),i=i.next}while(i!==e);return i}function lh(e,t,r,i,n,a){var o=e;do{for(var s=o.next.next;s!==o.prev;){if(o.i!==s.i&&ph(o,s)){var l=yh(o,s);return o=ih(o,o.next),l=ih(l,l.next),nh(o,t,r,i,n,a),void nh(l,t,r,i,n,a)}s=s.next}o=o.next}while(o!==e)}function hh(e,t){return e.x-t.x}function uh(e,t){if(t=function(e,t){var r,i=t,n=e.x,a=e.y,o=-1/0;do{if(a<=i.y&&a>=i.next.y&&i.next.y!==i.y){var s=i.x+(a-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(s<=n&&s>o){if(o=s,s===n){if(a===i.y)return i;if(a===i.next.y)return i.next}r=i.x=i.x&&i.x>=u&&n!==i.x&&fh(ar.x)&&vh(i,e)&&(r=i,d=l),i=i.next;return r}(e,t)){var r=yh(t,e);ih(r,r.next)}}function ch(e,t,r,i,n){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-r)/n)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)/n)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function dh(e){var t=e,r=e;do{t.x=0&&(e-o)*(i-s)-(r-o)*(t-s)>=0&&(r-o)*(a-s)-(n-o)*(i-s)>=0}function ph(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var r=e;do{if(r.i!==e.i&&r.next.i!==e.i&&r.i!==t.i&&r.next.i!==t.i&&_h(r,r.next,e,t))return!0;r=r.next}while(r!==e);return!1}(e,t)&&vh(e,t)&&vh(t,e)&&function(e,t){var r=e,i=!1,n=(e.x+t.x)/2,a=(e.y+t.y)/2;do{r.y>a!=r.next.y>a&&r.next.y!==r.y&&n<(r.next.x-r.x)*(a-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next}while(r!==e);return i}(e,t)}function mh(e,t,r){return(t.y-e.y)*(r.x-t.x)-(t.x-e.x)*(r.y-t.y)}function gh(e,t){return e.x===t.x&&e.y===t.y}function _h(e,t,r,i){return!!(gh(e,t)&&gh(r,i)||gh(e,i)&&gh(r,t))||mh(e,t,r)>0!=mh(e,t,i)>0&&mh(r,i,e)>0!=mh(r,i,t)>0}function vh(e,t){return mh(e.prev,e,e.next)<0?mh(e,t,e.next)>=0&&mh(e,e.prev,t)>=0:mh(e,t,e.prev)<0||mh(e,e.next,t)<0}function yh(e,t){var r=new wh(e.i,e.x,e.y),i=new wh(t.i,t.x,t.y),n=e.next,a=t.prev;return e.next=t,t.prev=e,r.next=n,n.prev=r,i.next=r,r.prev=i,a.next=i,i.prev=a,i}function xh(e,t,r,i){var n=new wh(e,t,r);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function bh(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevz&&(e.prevz.nextz=e.nextz),e.nextz&&(e.nextz.prevz=e.prevz)}function wh(e,t,r){this.i=e,this.x=t,this.y=r,this.prev=null,this.next=null,this.z=null,this.prevz=null,this.nextz=null,this.steiner=!1}function th(e,t,r,i){for(var n=0,a=t,o=r-i;ah&&s.push({pivot:math.floor((l+h)/2),left:h,right:l}),h=a[o].pivot+1,(l=a[o].right)>h&&s.push({pivot:math.floor((l+h)/2),left:h,right:l})}a=this._parts=s}else for(o=0;o=2e4},dosorttriangles:function(e,t){var r=this.indices;if(0===t){var i=this.attributes.position;e=e.array,this._trianglezlist&&this._trianglezlist.length===this.trianglecount||(this._trianglezlist=new float32array(this.trianglecount),this._sortedtriangleindices=new uint32array(this.trianglecount),this._indicestmp=new r.constructor(r.length),this._trianglezlisttmp=new float32array(this.trianglecount));for(var n,a=0,o=0;o0,r={},n=0;n65535?new uint32array(3*o):new uint16array(3*o),d.material.shader!==t&&d.material.attachshader(t,!0),ka.setmaterialfrommodel(t.__shading,d.material,e,r),s>0&&(this._linesmesh.geometry.resetoffset(),this._linesmesh.geometry.setvertexcount(s),this._linesmesh.geometry.settrianglecount(l)),this._dataindexofvertex=new uint32array(a),this._vertexrangeofdataindex=new uint32array(2*(n-i))},_updateregionmesh:function(e,t,r,i){for(var n=e.getdata(),a=0,o=0,s=!1,l=this._polygonmesh,h=this._linesmesh,u=r;u0;w&&(b*=t.getdevicepixelratio(),this._updatelinesgeometry(h.geometry,e,u,v,b,e.coordinatesystem.transform)),h.invisible=!w,h.material.set({color:g})}(l=this._polygonmesh).material.transparent=s,l.material.depthmask=!s,l.geometry.updateboundingbox(),l.frontface=this.extrudey?ka.mesh.ccw:ka.mesh.cw,l.material.get("normalmap")&&l.geometry.generatetangents(),l.seriesindex=e.seriesindex,l.on("mousemove",this._onmousemove,this),l.on("mouseout",this._onmouseout,this)},_updatedebugwireframe:function(e){var t=e.getmodel("debug.wireframe");if(t.get("show")){var r=ka.parsecolor(t.get("linestyle.color")||"rgba(0,0,0,0.5)"),i=mn(t.get("linestyle.width"),1),n=this._polygonmesh;n.geometry.generatebarycentric(),n.material.define("both","wireframe_triangle"),n.material.set("wireframelinecolor",r),n.material.set("wireframelinewidth",i)}},_onmousemove:function(e){var t=this._dataindexofvertex[e.triangle[0]];null==t&&(t=-1),t!==this._lasthoverdataindex&&(this.downplay(this._lasthoverdataindex),this.highlight(t),this._labelsbuilder.updatelabels([t])),this._lasthoverdataindex=t,this._polygonmesh.dataindex=t},_onmouseout:function(e){e.target&&(this.downplay(this._lasthoverdataindex),this._lasthoverdataindex=-1,this._polygonmesh.dataindex=-1),this._labelsbuilder.updatelabels([])},_updategroundplane:function(e,t,r){var i=e.getmodel("groundplane",e);if(this._groundmesh.invisible=!i.get("show",!0),!this._groundmesh.invisible){var n=e.get("shading"),a=this._groundmaterials[n];a||(a=this._groundmaterials.lambert),ka.setmaterialfrommodel(n,a,i,r),a.get("normalmap")&&this._groundmesh.geometry.generatetangents(),this._groundmesh.material=a,this._groundmesh.material.set("color",ka.parsecolor(i.get("color"))),this._groundmesh.scale.set(t.size[0],t.size[2],1)}},_triangulation:function(e,t,r){this._triangulationresults=[];for(var i=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0],a=e.coordinatesystem,o=t;o1?i:0,l[u][g]=a.points[v+2],l.set(n+u,l[u]),s?(i[0]=(a.points[v]*_[0]-v[0])/x,i[1]=(a.points[v+2]*_[g]-v[g])/x):(i[0]=(k?r:r+g)/x,i[1]=(l[u][m]*_[m]-v[m])/x),u.set(n+u,i)}for(zh.sub(p,l[1],l[0]),zh.sub(o,l[3],l[0]),zh.cross(n,p,o),zh.normalize(n,n),u=0;u<4;u++)h.set(n+u,n),f&&c.set(n+u,o);for(u=0;u<6;u++)p[3*a+u]=d[u]+n;n+=4,a+=2,r+=g}}return t.dirty(),{vertexoffset:n,triangleoffset:a}},_getregionlinesinfo:function(e,t,r){var i=0,n=0;return t.getregionmodel(e).getmodel("itemstyle").get("borderwidth")>0&&t.getregionpolygoncoords(e).foreach((function(e){var t=e.exterior,a=e.interiors;i+=r.getpolylinevertexcount(t),n+=r.getpolylinetrianglecount(t);for(var o=0;othis._endindex)){t-=this._startindex;for(var i=this._vertexrangeofdataindex[2*t];i0},_displacementchanged:!0,_displacementscale:0,updatedisplacementhash:function(){var e=this.getdisplacementtexture(),t=this.getdisplacemenscale();this._displacementchanged=this._displacementtexture!==e||this._displacementscale!==t,this._displacementtexture=e,this._displacementscale=t},isdisplacementchanged:function(){return this._displacementchanged}});i.util.merge(ru.prototype,uo),i.util.merge(ru.prototype,co),i.util.merge(ru.prototype,fo),i.util.merge(ru.prototype,kl);const iu=ru;var nu=math.pi,au=math.sin,ou=math.cos,su=math.tan,lu=math.asin,hu=math.atan2,uu=nu/180,cu=23.4397*uu;function du(e,t){return hu(au(e)*ou(cu)-su(t)*au(cu),ou(e))}function fu(e,t,r){return hu(au(e),ou(e)*au(t)-su(r)*ou(t))}function pu(e,t,r){return lu(au(t)*au(r)+ou(t)*ou(r)*ou(e))}var mu={};mu.getposition=function(e,t,r){var i=uu*-r,n=uu*t,a=function(e){return function(e){return e.valueof()/864e5-.5+2440588}(e)-2451545}(e),o=function(e){var t,r,i=(r=function(e){return uu*(357.5291+.98560028*e)}(e))+uu*(1.9148*au(r)+.02*au(2*r)+3e-4*au(3*r))+102.9372*uu+nu;return{dec:(t=i,lu(au(0)*ou(cu)+ou(0)*au(cu)*au(t))),ra:du(i,0)}}(a),s=function(e,t){return uu*(280.16+360.9856235*e)-t}(a,i)-o.ra;return{azimuth:fu(s,n,o.dec),altitude:pu(s,n,o.dec)}};const gu=mu;ka.shader.import(va),ka.shader.import("@export ecgl.atmosphere.vertex\nattribute vec3 position: position;\nattribute vec3 normal : normal;\nuniform mat4 worldviewprojection : worldviewprojection;\nuniform mat4 normalmatrix : worldinversetranspose;\n\nvarying vec3 v_normal;\n\nvoid main() {\n v_normal = normalize((normalmatrix * vec4(normal, 0.0)).xyz);\n gl_position = worldviewprojection * vec4(position, 1.0);\n}\n@end\n\n\n@export ecgl.atmosphere.fragment\nuniform mat4 viewtranspose: viewtranspose;\nuniform float glowpower;\nuniform vec3 glowcolor;\n\nvarying vec3 v_normal;\n\nvoid main() {\n float intensity = pow(1.0 - dot(v_normal, (viewtranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowpower);\n gl_fragcolor = vec4(glowcolor, intensity * intensity);\n}\n@end");const _u=i.componentview.extend({type:"globe",__ecgl__:!0,_displacementscale:0,init:function(e,t){this.groupgl=new ka.node,this._spheregeometry=new ka.spheregeometry({widthsegments:200,heightsegments:100,dynamic:!0}),this._overlaygeometry=new ka.spheregeometry({widthsegments:80,heightsegments:40}),this._planegeometry=new ka.planegeometry,this._earthmesh=new ka.mesh({rendernormal:!0}),this._atmospheremesh=new ka.mesh,this._atmospheregeometry=new ka.spheregeometry({widthsegments:80,heightsegments:40}),this._atmospherematerial=new ka.material({shader:new ka.shader(ka.shader.source("ecgl.atmosphere.vertex"),ka.shader.source("ecgl.atmosphere.fragment")),transparent:!0}),this._atmospheremesh.geometry=this._atmospheregeometry,this._atmospheremesh.material=this._atmospherematerial,this._atmospheremesh.frontface=ka.mesh.cw,this._lightroot=new ka.node,this._scenehelper=new uo,this._scenehelper.initlight(this._lightroot),this.groupgl.add(this._atmospheremesh),this.groupgl.add(this._earthmesh),this._control=new do({zr:t.getzr()}),this._control.init(),this._layermeshes={}},render:function(e,t,r){var i=e.coordinatesystem,n=e.get("shading");i.viewgl.add(this._lightroot),e.get("show")?i.viewgl.add(this.groupgl):i.viewgl.remove(this.groupgl),this._scenehelper.setscene(i.viewgl.scene),i.viewgl.setposteffect(e.getmodel("posteffect"),r),i.viewgl.settemporalsupersampling(e.getmodel("temporalsupersampling"));var a=this._earthmesh;a.geometry=this._spheregeometry;var o="ecgl."+n;a.material&&a.material.shader.name===o||(a.material=ka.creatematerial(o)),ka.setmaterialfrommodel(n,a.material,e,r),["roughnessmap","metalnessmap","detailmap","normalmap"].foreach((function(e){var t=a.material.get(e);t&&(t.flipy=!1)})),a.material.set("color",ka.parsecolor(e.get("basecolor")));var s=.99*i.radius;if(a.scale.set(s,s,s),e.get("atmosphere.show")){a.material.define("both","atmosphere_enabled"),this._atmospheremesh.invisible=!1,this._atmospherematerial.setuniforms({glowpower:e.get("atmosphere.glowpower")||6,glowcolor:e.get("atmosphere.color")||"#ffffff"}),a.material.setuniforms({glowpower:e.get("atmosphere.innerglowpower")||2,glowcolor:e.get("atmosphere.color")||"#ffffff"});var l=e.get("atmosphere.offset")||5;this._atmospheremesh.scale.set(s+l,s+l,s+l)}else a.material.undefine("both","atmosphere_enabled"),this._atmospheremesh.invisible=!0;var h=a.material.settextureimage("diffusemap",e.get("basetexture"),r,{flipy:!1,anisotropic:8});h&&h.surface&&h.surface.attachtomesh(a);var u=a.material.settextureimage("bumpmap",e.get("heighttexture"),r,{flipy:!1,anisotropic:8});u&&u.surface&&u.surface.attachtomesh(a),a.material[e.get("posteffect.enable")?"define":"undefine"]("fragment","srgb_decode"),this._updatelight(e,r),this._displacevertices(e,r),this._updateviewcontrol(e,r),this._updatelayers(e,r)},afterrender:function(e,t,r,i){var n=i.renderer;this._scenehelper.updateambientcubemap(n,e,r),this._scenehelper.updateskybox(n,e,r)},_updatelayers:function(e,t){var r=e.coordinatesystem,n=e.get("layers"),a=r.radius,o=[],s=[],l=[],h=[];i.util.each(n,(function(e){var n=new i.model(e),u=n.get("type"),c=ka.loadtexture(n.get("texture"),t,{flipy:!1,anisotropic:8});if(c.surface&&c.surface.attachtomesh(this._earthmesh),"blend"===u){var d=n.get("blendto"),f=mn(n.get("intensity"),1);"emission"===d?(l.push(c),h.push(f)):(o.push(c),s.push(f))}else{var p=n.get("id"),m=this._layermeshes[p];m||(m=this._layermeshes[p]=new ka.mesh({geometry:this._overlaygeometry,castshadow:!1,ignorepicking:!0})),"lambert"===n.get("shading")?(m.material=m.__lambertmaterial||new ka.material({autoupdatetexturestatus:!1,shader:ka.createshader("ecgl.lambert"),transparent:!0,depthmask:!1}),m.__lambertmaterial=m.material):(m.material=m.__colormaterial||new ka.material({autoupdatetexturestatus:!1,shader:ka.createshader("ecgl.color"),transparent:!0,depthmask:!1}),m.__colormaterial=m.material),m.material.enabletexture("diffusemap");var g=n.get("distance"),_=a+(null==g?r.radius/100:g);m.scale.set(_,_,_),a=_;var v=this._blanktexture||(this._blanktexture=ka.createblanktexture("rgba(255, 255, 255, 0)"));m.material.set("diffusemap",v),ka.loadtexture(n.get("texture"),t,{flipy:!1,anisotropic:8},(function(e){e.surface&&e.surface.attachtomesh(m),m.material.set("diffusemap",e),t.getzr().refresh()})),n.get("show")?this.groupgl.add(m):this.groupgl.remove(m)}}),this);var u=this._earthmesh.material;u.define("fragment","layer_diffusemap_count",o.length),u.define("fragment","layer_emissivemap_count",l.length),u.set("layerdiffusemap",o),u.set("layerdiffuseintensity",s),u.set("layeremissivemap",l),u.set("layeremissionintensity",h);var c=e.getmodel("debug.wireframe");if(c.get("show")){u.define("both","wireframe_triangle");var d=ka.parsecolor(c.get("linestyle.color")||"rgba(0,0,0,0.5)"),f=mn(c.get("linestyle.width"),1);u.set("wireframelinewidth",f),u.set("wireframelinecolor",d)}else u.undefine("both","wireframe_triangle")},_updateviewcontrol:function(e,t){var r=e.coordinatesystem,i=e.getmodel("viewcontrol"),n=(r.viewgl.camera,this),a=this._control;a.setviewgl(r.viewgl);var o,s,l=i.get("targetcoord");null!=l&&(s=l[0]+90,o=l[1]),a.setfromviewcontrolmodel(i,{basedistance:r.radius,alpha:o,beta:s}),a.off("update"),a.on("update",(function(){t.dispatchaction({type:"globechangecamera",alpha:a.getalpha(),beta:a.getbeta(),distance:a.getdistance()-r.radius,center:a.getcenter(),from:n.uid,globeid:e.id})}))},_displacevertices:function(e,t){var r=e.get("displacementquality"),i=e.get("debug.wireframe.show"),n=e.coordinatesystem;if(e.isdisplacementchanged()||r!==this._displacementquality||i!==this._showdebugwireframe){this._displacementquality=r,this._showdebugwireframe=i;var a=this._spheregeometry,o={low:100,medium:200,high:400,ultra:800}[r]||200,s=o/2;(a.widthsegments!==o||i)&&(a.widthsegments=o,a.heightsegments=s,a.build()),this._dodisplacevertices(a,n),i&&a.generatebarycentric()}},_dodisplacevertices:function(e,t){var r=e.attributes.position.value,i=e.attributes.texcoord0.value,n=e.__originalposition;n&&n.length===r.length||((n=new float32array(r.length)).set(r),e.__originalposition=n);for(var a=t.displacementwidth,o=t.displacementheight,s=t.displacementdata,l=0;l50&&(a=1e3);var o=[];ou.perspective(o,iu,this.width/this.height,1,a),this.viewgl.camera.projectionmatrix.setarray(o),this.viewgl.camera.decomposeprojectionmatrix(),o=ou.identity([]);var s=this.datatopoint(this.center);ou.scale(o,o,[1,-1,1]),ou.translate(o,o,[0,0,-e]),ou.rotatex(o,o,t),ou.rotatez(o,o,-this.bearing/180*math.pi),ou.translate(o,o,[-s[0]*this.getscale()*bu,-s[1]*this.getscale()*bu,0]),this.viewgl.camera.viewmatrix.array=o;var l=[];ou.invert(l,o),this.viewgl.camera.worldtransform.array=l,this.viewgl.camera.decomposeworldtransform();var h,u=nu*this.getscale();if(this.altitudeextent&&!isnan(this.boxheight)){var c=this.altitudeextent[1]-this.altitudeextent[0];h=this.boxheight/c*this.getscale()/math.pow(2,this._initialzoom-this.zoomoffset)}else h=u/(2*math.pi*6378e3*math.abs(math.cos(this.center[1]*(math.pi/180))))*this.altitudescale*bu;this.viewgl.rootnode.scale.set(this.getscale()*bu,this.getscale()*bu,h)}},getscale:function(){return math.pow(2,this.zoom-this.zoomoffset)},projectontile:function(e,t){return this.projectontilewithscale(e,this.getscale()*nu,t)},projectontilewithscale:function(e,t,r){var i=e[0],n=e[1]*ru/180,a=t*(i*ru/180+ru)/(2*ru),o=t*(ru-math.log(math.tan(ru/4+.5*n)))/(2*ru);return(r=r||[])[0]=a,r[1]=o,r},unprojectfromtile:function(e,t){return this.unprojectontilewithscale(e,this.getscale()*nu,t)},unprojectontilewithscale:function(e,t,r){var i=e[0],n=e[1],a=i/t*(2*ru)-ru,o=2*(math.atan(math.exp(ru-n/t*(2*ru)))-ru/4);return(r=r||[])[0]=180*a/ru,r[1]=180*o/ru,r},datatopoint:function(e,t){return(t=this.projectontilewithscale(e,nu,t))[0]-=this._origin[0],t[1]-=this._origin[1],t[2]=isnan(e[2])?0:e[2],isnan(e[2])||(t[2]=e[2],this.altitudeextent&&(t[2]-=this.altitudeextent[0])),t}};const zu=fu;function gu(){zu.apply(this,arguments)}function uu(e,t,r){function i(e,t){var r=t.getwidth(),i=t.getheight(),n=t.getdevicepixelratio();this.viewgl.setviewport(0,0,r,i,n),this.width=r,this.height=i,this.altitudescale=e.get("altitudescale"),this.boxheight=e.get("boxheight")}function n(e,t){if("auto"!==this.model.get("boxheight")){var r=[1/0,-1/0];e.eachseries((function(e){if(e.coordinatesystem===this){var t=e.getdata(),i=e.coorddimtodatadim("alt")[0];if(i){var n=t.getdataextent(i,!0);r[0]=math.min(r[0],n[0]),r[1]=math.max(r[1],n[1])}}}),this),r&&isfinite(r[1]-r[0])&&(this.altitudeextent=r)}}return{dimensions:t.prototype.dimensions,create:function(a,o){var s=[];return a.eachcomponent(e,(function(e){var r=e.__viewgl;r||(r=e.__viewgl=new il).setrootnode(new ka.node);var a=new t;a.viewgl=e.__viewgl,a.resize=i,a.resize(e,o),s.push(a),e.coordinatesystem=a,a.model=e,a.update=n})),a.eachseries((function(t){if(t.get("coordinatesystem")===e){var r=t.getreferringcomponents(e).models[0];if(r||(r=a.getcomponent(e)),!r)throw new error(e+' "'+mn(t.get(e+"index"),t.get(e+"id"),0)+'" not found');t.coordinatesystem=r.coordinatesystem}})),r&&r(s,a,o),s}}}gu.prototype=new zu,gu.prototype.constructor=gu,gu.prototype.type="mapbox3d";const ku=uu("mapbox3d",gu,(function(e){e.foreach((function(e){e.setcameraoption(e.model.getmapboxcameraoption())}))}));(0,i.use)((function(e){e.registercomponentmodel(au),e.registercomponentview(pu),e.registercoordinatesystem("mapbox3d",ku),e.registeraction({type:"mapbox3dchangecamera",event:"mapbox3dcamerachanged",update:"mapbox3d:updatecamera"},(function(e,t){t.eachcomponent({maintype:"mapbox3d",query:e},(function(t){t.setmapboxcameraoption(e)}))}))}));var vu=["zoom","center","pitch","bearing"],hu=i.componentmodel.extend({type:"maptalks3d",layoutmode:"box",coordinatesystem:null,defaultoption:{zlevel:-10,urltemplate:"http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",attribution:'© openstreetmap contributors, © carto',center:[0,0],zoom:0,pitch:0,bearing:0,light:{main:{alpha:20,beta:30}},altitudescale:1,boxheight:"auto"},getmaptalkscameraoption:function(){var e=this;return vu.reduce((function(t,r){return t[r]=e.get(r),t}),{})},setmaptalkscameraoption:function(e){null!=e&&vu.foreach((function(t){null!=e[t]&&(this.option[t]=e[t])}),this)},getmaptalks:function(){return this._maptalks},setmaptalks:function(e){this._maptalks=e}});i.util.merge(hu.prototype,co),i.util.merge(hu.prototype,fo);const wu=hu;function ju(e,t,r,i){if(this.id=e,this.zr=t,this.dom=document.createelement("div"),this.dom.style.csstext="position:absolute;left:0;right:0;top:0;bottom:0;",!maptalks)throw new error("maptalks library must be included. see https://maptalks.org");this._maptalks=new maptalks.map(this.dom,{center:r,zoom:i,doubleclickzoom:!1,fog:!1}),this._initevents()}ju.prototype.setunpainted=function(){},ju.prototype.resize=function(){this._maptalks.checksize()},ju.prototype.getmaptalks=function(){return this._maptalks},ju.prototype.clear=function(){},ju.prototype.refresh=function(){this._maptalks.checksize()};var xu=["mousedown","mouseup","click","dblclick","mousemove","mousewheel","dommousescroll","touchstart","touchend","touchmove","touchcancel"];ju.prototype._initevents=function(){var e=this.dom;this._handlers=this._handlers||{contextmenu:function(e){return e.preventdefault(),!1}},xu.foreach((function(t){this._handlers[t]=function(r){var i={};for(var n in r)i[n]=r[n];i.bubbles=!1;var a=new r.constructor(r.type,i);"mousewheel"===t||"dommousescroll"===t?e.dispatchevent(a):e.firstelementchild.dispatchevent(a)},this.zr.dom.addeventlistener(t,this._handlers[t])}),this),this.zr.dom.addeventlistener("contextmenu",this._handlers.contextmenu)},ju.prototype.dispose=function(){xu.foreach((function(e){this.zr.dom.removeeventlistener(e,this._handlers[e])}),this),this._maptalks.remove()};const qu=ju;ka.shader.import(lu);const zu=i.componentview.extend({type:"maptalks3d",__ecgl__:!0,init:function(e,t){this._groundmesh=new ka.mesh({geometry:new ka.planegeometry,material:new ka.material({shader:new ka.shader({vertex:ka.shader.source("ecgl.displayshadow.vertex"),fragment:ka.shader.source("ecgl.displayshadow.fragment")}),depthmask:!1}),renderorder:-100,culling:!1,castshadow:!1,$ignorepicking:!0,rendernormal:!0})},_initmaptalkslayer:function(e,t){var r=t.getzr();this._zrlayer=new qu("maptalks3d",r,e.get("center"),e.get("zoom")),r.painter.insertlayer(-1e3,this._zrlayer),this._lightroot=new ka.node,this._scenehelper=new uo(this._lightroot),this._scenehelper.initlight(this._lightroot);var i=this._zrlayer.getmaptalks(),n=this._dispatchinteractaction.bind(this,t,i);["zoomend","zooming","zoomstart","dragrotating","pitch","pitchend","movestart","moving","moveend","resize","touchstart","touchmove","touchend","animating"].foreach((function(e){i.on(e,n)}))},render:function(e,t,r){this._zrlayer||this._initmaptalkslayer(e,r);var i=this._zrlayer.getmaptalks(),n=e.get("urltemplate"),a=i.getbaselayer();n!==this._oldurltemplate&&(a?a.setoptions({urltemplate:n,attribution:e.get("attribution")}):(a=new maptalks.tilelayer("maptalks-echarts-gl-baselayer",{urltemplate:n,subdomains:["a","b","c"],attribution:e.get("attribution")}),i.setbaselayer(a))),this._oldurltemplate=n,i.setcenter(e.get("center")),i.setzoom(e.get("zoom"),{animation:!1}),i.setpitch(e.get("pitch")),i.setbearing(e.get("bearing")),e.setmaptalks(i);var o=e.coordinatesystem;o.viewgl.scene.add(this._lightroot),o.viewgl.add(this._groundmesh),this._updategroundmesh(),this._scenehelper.setscene(o.viewgl.scene),this._scenehelper.updatelight(e),o.viewgl.setposteffect(e.getmodel("posteffect"),r),o.viewgl.settemporalsupersampling(e.getmodel("temporalsupersampling")),this._maptalks3dmodel=e},afterrender:function(e,t,r,i){var n=i.renderer;this._scenehelper.updateambientcubemap(n,e,r),this._scenehelper.updateskybox(n,e,r),e.coordinatesystem.viewgl.scene.traverse((function(e){e.material&&(e.material.define("fragment","normal_up_axis",2),e.material.define("fragment","normal_front_axis",1))}))},updatecamera:function(e,t,r,i){e.coordinatesystem.setcameraoption(i),this._updategroundmesh(),r.getzr().refresh()},_dispatchinteractaction:function(e,t,r){var i;e.dispatchaction({type:"maptalks3dchangecamera",pitch:t.getpitch(),zoom:(i=t.getresolution(),19-math.log(i/yu)/math.ln2+1),center:t.getcenter().toarray(),bearing:t.getbearing(),maptalks3did:this._maptalks3dmodel&&this._maptalks3dmodel.id})},_updategroundmesh:function(){if(this._maptalks3dmodel){var e=this._maptalks3dmodel.coordinatesystem,t=e.datatopoint(e.center);this._groundmesh.position.set(t[0],t[1],-.001);var r=new ka.plane(new ka.vector3(0,0,1),0),i=e.viewgl.camera.castray(new ka.vector2(-1,-1)),n=e.viewgl.camera.castray(new ka.vector2(1,1)),a=i.intersectplane(r),o=n.intersectplane(r),s=a.dist(o)/e.viewgl.rootnode.scale.x;this._groundmesh.scale.set(s,s,1)}},dispose:function(e,t){this._zrlayer&&this._zrlayer.dispose(),t.getzr().painter.dellayer(-1e3)}}),yu=12756274*math.pi/(256*math.pow(2,20));function ku(){zu.apply(this,arguments),this.maxpitch=85,this.zoomoffset=1}ku.prototype=new zu,ku.prototype.constructor=ku,ku.prototype.type="maptalks3d";const qu=uu("maptalks3d",ku,(function(e){e.foreach((function(e){e.setcameraoption(e.model.getmaptalkscameraoption())}))}));(0,i.use)((function(e){e.registercomponentmodel(wu),e.registercomponentview(zu),e.registercoordinatesystem("maptalks3d",qu),e.registeraction({type:"maptalks3dchangecamera",event:"maptalks3dcamerachanged",update:"maptalks3d:updatecamera"},(function(e,t){t.eachcomponent({maintype:"maptalks3d",query:e},(function(t){t.setmaptalkscameraoption(e)}))}))}));var ju=po.vec3,$u=i.helper.datastack.isdimensionstacked;function ec(e,t,r){for(var i=e.getdataextent(t),n=e.getdataextent(r),a=i[1]-i[0]||i[0],o=n[1]-n[0]||n[0],s=new uint8array(2500),l=0;l0&&d>0||c<0&&d<0)),m=["x","y","z"].map((function(t){return e.coorddimtodatadim(t)[0]})),g=$u(r,m[2]),_=g?r.getcalculationinfo("stackresultdimension"):m[2];r.each(m,(function(e,i,a,o){var s=r.get(_,o),l=g?s-a:p?0:f[0],h=t.datatopoint([e,i,l]),u=t.datatopoint([e,i,s]),c=ju.dist(h,u),d=[0,u[1]"+a.join("
")}(a):i.format.encodehtml(i.format.addcommas(a)),s=n.getname(t),l=ih(n,t);i.util.isobject(l)&&l.colorstops&&(l=(l.colorstops[0]||{}).color),l=l||"transparent";var h=i.format.gettooltipmarker(l),u=e.name;return"\0-"===u&&(u=""),u=u?i.format.encodehtml(u)+(r?": ":"
"):"",r?h+u+o:u+h+(s?i.format.encodehtml(s)+": "+o:o)}function sc(e,t,r){r=r||e.getsource();var n=t||i.getcoordinatesystemdimensions(e.get("coordinatesystem"))||["x","y","z"],a=i.helper.createdimensions(r,{dimensionsdefine:r.dimensionsdefine||e.get("dimensions"),encodedefine:r.encodedefine||e.get("encode"),coorddimensions:n.map((function(t){var r=e.getreferringcomponents(t+"axis3d").models[0];return{type:r&&"category"===r.get("type")?"ordinal":"float",name:t}}))});"cartesian3d"===e.get("coordinatesystem")&&a.foreach((function(t){if(n.indexof(t.coorddim)>=0){var r=e.getreferringcomponents(t.coorddim+"axis3d").models[0];r&&"category"===r.get("type")&&(t.ordinalmeta=r.getordinalmeta())}}));var o=i.helper.datastack.enabledatastack(e,a,{byindex:!0,stackedcoorddimension:"z"}),s=new i.list(a,e);return s.setcalculationinfo(o),s.initdata(r),s}var lc=i.seriesmodel.extend({type:"series.bar3d",dependencies:["globe"],visualstyleaccesspathvisu:"itemstyle",getinitialdata:function(e,t){return sc(this)},getformattedlabel:function(e,t,r,i){var n=ac.getformattedlabel(this,e,t,r,i);return null==n&&(n=this.getdata().get("z",e)),n},formattooltip:function(e){return oc(this,e)},defaultoption:{coordinatesystem:"cartesian3d",globeindex:0,grid3dindex:0,zlevel:-10,bevelsize:0,bevelsmoothness:2,ongridplane:"xy",shading:"color",minheight:0,itemstyle:{opacity:1},label:{show:!1,distance:2,textstyle:{fontsize:14,color:"#000",backgroundcolor:"rgba(255,255,255,0.7)",padding:3,borderradius:3}},emphasis:{label:{show:!0}},animationdurationupdate:500}});i.util.merge(lc.prototype,kl);const hc=lc;var uc,cc,dc,fc,pc,mc,gc,_c,vc=po.vec3,yc=po.mat3,xc=vr.extend((function(){return{attributes:{position:new vr.attribute("position","float",3,"position"),normal:new vr.attribute("normal","float",3,"normal"),color:new vr.attribute("color","float",4,"color"),prevposition:new vr.attribute("prevposition","float",3),prevnormal:new vr.attribute("prevnormal","float",3)},dynamic:!0,enablenormal:!1,bevelsize:1,bevelsegments:0,_dataindices:null,_vertexoffset:0,_triangleoffset:0}}),{resetoffset:function(){this._vertexoffset=0,this._triangleoffset=0},setbarcount:function(e){var t=this.enablenormal,r=this.getbarvertexcount()*e,i=this.getbartrianglecount()*e;this.vertexcount!==r&&(this.attributes.position.init(r),t?this.attributes.normal.init(r):this.attributes.normal.value=null,this.attributes.color.init(r)),this.trianglecount!==i&&(this.indices=r>65535?new uint32array(3*i):new uint16array(3*i),this._dataindices=new uint32array(r))},getbarvertexcount:function(){var e=this.bevelsize>0?this.bevelsegments:0;return e>0?this._getbevelbarvertexcount(e):this.enablenormal?24:8},getbartrianglecount:function(){var e=this.bevelsize>0?this.bevelsegments:0;return e>0?this._getbevelbartrianglecount(e):12},_getbevelbarvertexcount:function(e){return 4*(e+1)*(e+1)*2},_getbevelbartrianglecount:function(e){return(4*e+3+1)*(2*e+1)*2+4},setcolor:function(e,t){for(var r=this.getbarvertexcount(),i=r*(e+1),n=r*e;n0&&this.bevelsegments>0)this._addbevelbar(e,c,m,g,this.bevelsize,this.bevelsegments,_);else{vc.copy(n,c),vc.normalize(n,n),vc.cross(a,m,n),vc.normalize(a,a),vc.cross(i,n,a),vc.normalize(a,a),vc.negate(o,i),vc.negate(s,n),vc.negate(l,a),t(h[0],e,i,g[0]/2),t(h[0],h[0],a,g[2]/2),t(h[1],e,i,g[0]/2),t(h[1],h[1],l,g[2]/2),t(h[2],e,o,g[0]/2),t(h[2],h[2],l,g[2]/2),t(h[3],e,o,g[0]/2),t(h[3],h[3],a,g[2]/2),t(r,e,n,g[1]),t(h[4],r,i,g[0]/2),t(h[4],h[4],a,g[2]/2),t(h[5],r,i,g[0]/2),t(h[5],h[5],l,g[2]/2),t(h[6],r,o,g[0]/2),t(h[6],h[6],l,g[2]/2),t(h[7],r,o,g[0]/2),t(h[7],h[7],a,g[2]/2);var x=this.attributes;if(this.enablenormal){u[0]=i,u[1]=o,u[2]=n,u[3]=s,u[4]=a,u[5]=l;for(var b=this._vertexoffset,w=0;w0&&(f++,u[3]<.99&&(p=!0))}})),o.geometry.setbarcount(f);var m=r.getlayout("orient"),g=this._barindexofdata=new int32array(r.count());f=0,r.each((function(e){if(r.hasvalue(e)){var t=r.getitemlayout(e),i=t[0],n=t[1],o=t[2],s=4*e;u[0]=c[s++],u[1]=c[s++],u[2]=c[s++],u[3]=c[s++],u[3]>0&&(a._barmesh.geometry.addbar(i,n,m,o,u,e),g[e]=f++)}else g[e]=-1})),o.geometry.dirty(),o.geometry.updateboundingbox();var _=o.material;_.transparent=p,_.depthmask=!p,o.geometry.sorttriangles=p,this._inithandler(e,t)},_inithandler:function(e,t){var r=e.getdata(),i=this._barmesh,n="cartesian3d"===e.coordinatesystem.type;i.seriesindex=e.seriesindex;var a=-1;i.off("mousemove"),i.off("mouseout"),i.on("mousemove",(function(e){var o=i.geometry.getdataindexofvertex(e.triangle[0]);o!==a&&(this._downplay(a),this._highlight(o),this._labelsbuilder.updatelabels([o]),n&&t.dispatchaction({type:"grid3dshowaxispointer",value:[r.get("x",o),r.get("y",o),r.get("z",o,!0)]})),a=o,i.dataindex=o}),this),i.on("mouseout",(function(e){this._downplay(a),this._labelsbuilder.updatelabels(),a=-1,i.dataindex=-1,n&&t.dispatchaction({type:"grid3dhideaxispointer"})}),this)},_highlight:function(e){var t=this._data;if(t){var r=this._barindexofdata[e];if(!(r<0)){var n=t.getitemmodel(e).getmodel("emphasis.itemstyle"),a=n.get("color"),o=n.get("opacity");if(null==a){var s=ih(t,e);a=i.color.lift(s,-.4)}null==o&&(o=rh(t,e));var l=ka.parsecolor(a);l[3]*=o,this._barmesh.geometry.setcolor(r,l),this._api.getzr().refresh()}}},_downplay:function(e){var t=this._data;if(t){var r=this._barindexofdata[e];if(!(r<0)){var i=ih(t,e),n=rh(t,e),a=ka.parsecolor(i);a[3]*=n,this._barmesh.geometry.setcolor(r,a),this._api.getzr().refresh()}}},highlight:function(e,t,r,i){this._togglestatus("highlight",e,t,r,i)},downplay:function(e,t,r,i){this._togglestatus("downplay",e,t,r,i)},_togglestatus:function(e,t,r,n,a){var o=t.getdata(),s=an(o,a),l=this;null!=s?i.util.each(ac.normalizetoarray(s),(function(t){"highlight"===e?this._highlight(t):this._downplay(t)}),this):o.each((function(t){"highlight"===e?l._highlight(t):l._downplay(t)}))},remove:function(){this.groupgl.removeall()},dispose:function(){this._labelsbuilder.dispose(),this.groupgl.removeall()}});(0,i.use)((function(e){e.registerchartview(tc),e.registerseriesmodel(hc),nc(e),e.registerprocessor((function(e,t){e.eachseriesbytype("bar3d",(function(e){var t=e.getdata();t.filterself((function(e){return t.hasvalue(e)}))}))}))}));const sc=i.seriesmodel.extend({type:"series.line3d",dependencies:["grid3d"],visualstyleaccesspath:"linestyle",visualdrawtype:"stroke",getinitialdata:function(e,t){return sc(this)},formattooltip:function(e){return oc(this,e)},defaultoption:{coordinatesystem:"cartesian3d",zlevel:-10,grid3dindex:0,linestyle:{width:2},animationdurationupdate:500}});function mc(e,t,r,i,n,a,o){if(0===n)return!1;var s,l=n;if(o>t+l&&o>i+l||oe+l&&a>r+l||a=0){var g=3*l,_=new vt(this._points[g],this._points[g+1],this._points[g+2]);a.push({dataindex:l,point:_,pointworld:_.clone(),target:this._line3dmesh,distance:this._camera.getworldposition().dist(_)})}},remove:function(){this.groupgl.removeall()},dispose:function(){this.groupgl.removeall()}});(0,i.use)((function(e){e.registerchartview(ec),e.registerseriesmodel(sc),e.registerlayout((function(e,t){e.eachseriesbytype("line3d",(function(e){var t=e.getdata(),r=e.coordinatesystem;if(r){if("cartesian3d"!==r.type)return;var i=new float32array(3*t.count()),n=[],a=[],o=r.dimensions.map((function(t){return e.coorddimtodatadim(t)[0]}));r&&t.each(o,(function(e,t,o,s){n[0]=e,n[1]=t,n[2]=o,r.datatopoint(n,a),i[3*s]=a[0],i[3*s+1]=a[1],i[3*s+2]=a[2]})),t.setlayout("points",i)}}))}))}));const cc=i.seriesmodel.extend({type:"series.scatter3d",dependencies:["globe","grid3d","geo3d"],visualstyleaccesspath:"itemstyle",hassymbolvisual:!0,getinitialdata:function(e,t){return sc(this)},getformattedlabel:function(e,t,r,i){var n=ac.getformattedlabel(this,e,t,r,i);if(null==n){var a=this.getdata(),o=a.dimensions[a.dimensions.length-1];n=a.get(o,e)}return n},formattooltip:function(e){return oc(this,e)},defaultoption:{coordinatesystem:"cartesian3d",zlevel:-10,progressive:1e5,progressivethreshold:1e5,grid3dindex:0,globeindex:0,symbol:"circle",symbolsize:10,blendmode:"source-over",label:{show:!1,position:"right",distance:5,textstyle:{fontsize:14,color:"#000",backgroundcolor:"rgba(255,255,255,0.7)",padding:3,borderradius:3}},itemstyle:{opacity:.8},emphasis:{label:{show:!0}},animationdurationupdate:500}});function dc(e,t,r){(t=t||document.createelement("canvas")).width=e,t.height=e;var i=t.getcontext("2d");return r&&r(i),t}var lc={getmarginbystyle:function(e){var t=e.minmargin||0,r=0;e.stroke&&"none"!==e.stroke&&(r=null==e.linewidth?1:e.linewidth);var i=e.shadowblur||0,n=e.shadowoffsetx||0,a=e.shadowoffsety||0,o={};return o.left=math.max(r/2,-n+i,t),o.right=math.max(r/2,n+i,t),o.top=math.max(r/2,-a+i,t),o.bottom=math.max(r/2,a+i,t),o},createsymbolsprite:function(e,t,r,n){var a=function(e,t,r,n){i.util.isarray(t)||(t=[t,t]);var a=lc.getmarginbystyle(r,void 0),o=t[0]+a.left+a.right,s=t[1]+a.top+a.bottom,l=i.helper.createsymbol(e,0,0,t[0],t[1]),h=math.max(o,s);l.x=a.left,l.y=a.top,o>s?l.y+=(h-s)/2:l.x+=(h-o)/2;var u=l.getboundingrect();return l.x-=u.x,l.y-=u.y,l.setstyle(r),l.update(),l.__size=h,l}(e,t,r),o=lc.getmarginbystyle(r);return{image:dc(a.__size,n,(function(e){i.innerdrawelementoncanvas(e,a)})),margin:o}},createsdffromcanvas:function(e,t,r,i){return dc(t,i,(function(t){var i=e.getcontext("2d").getimagedata(0,0,e.width,e.height);t.putimagedata(function(e,t,r){var i=t.width,n=t.height,a=e.canvas.width,o=e.canvas.height,s=i/a,l=n/o;function h(e){return e<128?1:-1}function u(e,a){var o=1/0;e=math.floor(e*s);for(var u=(a=math.floor(a*l))*i+e,c=h(t.data[4*u]),d=math.max(a-r,0);d=2e4},dosortvertices:function(e,t){var r=this.indices,i=oc.create();if(!r){r=this.indices=this.vertexcount>65535?new uint32array(this.vertexcount):new uint16array(this.vertexcount);for(var n=0;n.05);else for(n=0;n<3;n++)this._progressivequicksort(3*t+n);this.dirtyindices()},_simplesort:function(e){var t=this._zlist,r=this.indices;function i(e,r){return t[r]-t[e]}e?array.prototype.sort.call(r,i):ch.sort(r,i,0,r.length-1)},_progressivequicksort:function(e){var t=this._zlist,r=this.indices;this._quicksort=this._quicksort||new ch,this._quicksort.step(r,(function(e,r){return t[r]-t[e]}),e)}};var ic=po.vec4;ka.shader.import("@export ecgl.sdfsprite.vertex\n\nuniform mat4 worldviewprojection : worldviewprojection;\nuniform float elapsedtime : 0;\n\nattribute vec3 position : position;\n\n#ifdef vertex_size\nattribute float size;\n#else\nuniform float u_size;\n#endif\n\n#ifdef vertex_color\nattribute vec4 a_fillcolor: color;\nvarying vec4 v_color;\n#endif\n\n#ifdef vertex_animation\nattribute vec3 prevposition;\nattribute float prevsize;\nuniform float percent : 1.0;\n#endif\n\n\n#ifdef positiontexture_enabled\nuniform sampler2d positiontexture;\n#endif\n\nvarying float v_size;\n\nvoid main()\n{\n\n#ifdef positiontexture_enabled\n gl_position = worldviewprojection * vec4(texture2d(positiontexture, position.xy).xy, -10.0, 1.0);\n#else\n\n #ifdef vertex_animation\n vec3 pos = mix(prevposition, position, percent);\n #else\n vec3 pos = position;\n #endif\n gl_position = worldviewprojection * vec4(pos, 1.0);\n#endif\n\n#ifdef vertex_size\n#ifdef vertex_animation\n v_size = mix(prevsize, size, percent);\n#else\n v_size = size;\n#endif\n#else\n v_size = u_size;\n#endif\n\n#ifdef vertex_color\n v_color = a_fillcolor;\n #endif\n\n gl_pointsize = v_size;\n}\n\n@end\n\n@export ecgl.sdfsprite.fragment\n\nuniform vec4 color: [1, 1, 1, 1];\nuniform vec4 strokecolor: [1, 1, 1, 1];\nuniform float smoothing: 0.07;\n\nuniform float linewidth: 0.0;\n\n#ifdef vertex_color\nvarying vec4 v_color;\n#endif\n\nvarying float v_size;\n\nuniform sampler2d sprite;\n\n@import clay.util.srgb\n\nvoid main()\n{\n gl_fragcolor = color;\n\n vec4 _strokecolor = strokecolor;\n\n#ifdef vertex_color\n gl_fragcolor *= v_color;\n #endif\n\n#ifdef sprite_enabled\n float d = texture2d(sprite, gl_pointcoord).r;\n gl_fragcolor.a *= smoothstep(0.5 - smoothing, 0.5 + smoothing, d);\n\n if (linewidth > 0.0) {\n float slinewidth = linewidth / 2.0;\n\n float outlinemaxvalue0 = 0.5 + slinewidth;\n float outlinemaxvalue1 = 0.5 + slinewidth + smoothing;\n float outlineminvalue0 = 0.5 - slinewidth - smoothing;\n float outlineminvalue1 = 0.5 - slinewidth;\n\n if (d <= outlinemaxvalue1 && d >= outlineminvalue0) {\n float a = _strokecolor.a;\n if (d <= outlineminvalue1) {\n a = a * smoothstep(outlineminvalue0, outlineminvalue1, d);\n }\n else {\n a = a * smoothstep(outlinemaxvalue1, outlinemaxvalue0, d);\n }\n gl_fragcolor.rgb = mix(gl_fragcolor.rgb * gl_fragcolor.a, _strokecolor.rgb, a);\n gl_fragcolor.a = gl_fragcolor.a * (1.0 - a) + a;\n }\n }\n#endif\n\n#ifdef srgb_decode\n gl_fragcolor = srgbtolinear(gl_fragcolor);\n#endif\n}\n@end");const rc=ka.mesh.extend((function(){var e=new ka.geometry({dynamic:!0,attributes:{color:new ka.geometry.attribute("color","float",4,"color"),position:new ka.geometry.attribute("position","float",3,"position"),size:new ka.geometry.attribute("size","float",1),prevposition:new ka.geometry.attribute("prevposition","float",3),prevsize:new ka.geometry.attribute("prevsize","float",1)}});object.assign(e,nc);var t=new ka.material({shader:ka.createshader("ecgl.sdfsprite"),transparent:!0,depthmask:!1});t.enabletexture("sprite"),t.define("both","vertex_color"),t.define("both","vertex_size");var r=new ka.texture2d({image:document.createelement("canvas"),flipy:!1});return t.set("sprite",r),e.pick=this._pick.bind(this),{geometry:e,material:t,mode:ka.mesh.points,sizescale:1}}),{_pick:function(e,t,r,i,n,a){var o=this._positionndc;if(o)for(var s=r.viewport,l=2/s.width,h=2/s.height,u=this.geometry.vertexcount-1;u>=0;u--){var c,d=o[2*(c=this.geometry.indices?this.geometry.indices[u]:u)],f=o[2*c+1],p=this.geometry.attributes.size.get(c)/this.sizescale/2;if(e>d-p*l&&ef-p*h&&t2?(p=this._updatesymbolsprite(e,d,u,c),s.enabletexture("sprite")):s.disabletexture("sprite"),h.position.init(n-i);var m=[];if(f){s.undefine("vertex_size"),s.undefine("vertex_color");var g=function(e){const t=e.getvisual("style");if(t)return t[e.getvisual("drawtype")]}(o),_=function(e){return e.getvisual("style").opacity}(o);ka.parsecolor(g,m),m[3]*=_,s.set({color:m,u_size:u.maxsize*this._sizescale})}else s.set({color:[1,1,1,1]}),s.define("vertex_size"),s.define("vertex_color"),h.size.init(n-i),h.color.init(n-i),this._originalopacity=new float32array(n-i);for(var v=o.getlayout("points"),y=h.position.value,x=0;x1?(o[0]=r.maxsize,o[1]=r.maxsize/r.aspect):(o[1]=r.maxsize,o[0]=r.maxsize*r.aspect),o[0]=o[0]||1,o[1]=o[1]||1,this._symboltype===r.type&&(a=o,(n=this._symbolsize)&&a&&n[0]===a[0]&&n[1]===a[1])&&this._linewidth===t.linewidth||(pc.createsymbolsprite(r.type,o,{fill:"#fff",linewidth:t.linewidth,stroke:"transparent",shadowcolor:"transparent",minmargin:math.min(o[0]/2,10)},this._spriteimagecanvas),pc.createsdffromcanvas(this._spriteimagecanvas,math.min(this._spriteimagecanvas.width,32),20,this._mesh.material.get("sprite").image),this._symboltype=r.type,this._symbolsize=o,this._linewidth=t.linewidth),this._spriteimagecanvas.width/r.maxsize*i},_updatematerial:function(e,t){var r="lighter"===e.get("blendmode")?ka.additiveblend:null,i=this._mesh.material;i.blend=r,i.set("linewidth",t.linewidth/20);var n=ka.parsecolor(t.stroke);i.set("strokecolor",n),i.transparent=!0,i.depthmask=!1,i.depthtest=!this.is2d,i.sortvertices=!this.is2d},_updatelabelbuilder:function(e,t,r){var i=e.getdata(),n=this._mesh.geometry,a=n.attributes.position.value,o=(t=this._startdataindex,this._mesh.sizescale);this._labelsbuilder.updatedata(i,t,r),this._labelsbuilder.getlabelposition=function(e,r,i){var n=3*(e-t);return[a[n],a[n+1],a[n+2]]},this._labelsbuilder.getlabeldistance=function(e,r,i){return n.attributes.size.get(e-t)/o/2+i},this._labelsbuilder.updatelabels()},_updateanimation:function(e){ka.updatevertexanimation([["prevposition","position"],["prevsize","size"]],this._prevmesh,this._mesh,e)},_updatehandler:function(e,t,r){var i,n=e.getdata(),a=this._mesh,o=this,s=-1,l=e.coordinatesystem&&"cartesian3d"===e.coordinatesystem.type;l&&(i=e.coordinatesystem.model),a.seriesindex=e.seriesindex,a.off("mousemove"),a.off("mouseout"),a.on("mousemove",(function(t){var h=t.vertexindex+o._startdataindex;h!==s&&(this.highlightonmouseover&&(this.downplay(n,s),this.highlight(n,h),this._labelsbuilder.updatelabels([h])),l&&r.dispatchaction({type:"grid3dshowaxispointer",value:[n.get(e.coorddimtodatadim("x")[0],h),n.get(e.coorddimtodatadim("y")[0],h),n.get(e.coorddimtodatadim("z")[0],h)],grid3dindex:i.componentindex})),a.dataindex=h,s=h}),this),a.on("mouseout",(function(e){var t=e.vertexindex+o._startdataindex;this.highlightonmouseover&&(this.downplay(n,t),this._labelsbuilder.updatelabels()),s=-1,a.dataindex=-1,l&&r.dispatchaction({type:"grid3dhideaxispointer",grid3dindex:i.componentindex})}),this)},updatelayout:function(e,t,r){var i=e.getdata();if(this._mesh){var n=this._mesh.geometry.attributes.position.value,a=i.getlayout("points");if(this.is2d)for(var o=0;othis._enddataindex||tthis._enddataindex||t 1.0 || v_percent < 0.0) {\n discard;\n }\n\n float fade = v_percent;\n\n#ifdef srgb_decode\n gl_fragcolor = srgbtolinear(color * v_color);\n#else\n gl_fragcolor = color * v_color;\n#endif\n\n @import ecgl.common.wireframe.fragmentmain\n\n if (v_percent > (1.0 - v_spotpercent)) {\n gl_fragcolor.rgb *= spotintensity;\n }\n\n gl_fragcolor.a *= fade;\n}\n\n@end");const ad=ka.mesh.extend((function(){var e=new ka.material({shader:new ka.shader(ka.shader.source("ecgl.trail2.vertex"),ka.shader.source("ecgl.trail2.fragment")),transparent:!0,depthmask:!1}),t=new ro({dynamic:!0});return t.createattribute("dist","float",1),t.createattribute("distall","float",1),t.createattribute("start","float",1),{geometry:t,material:e,culling:!1,$ignorepicking:!0}}),{updatedata:function(e,t,r){var i=e.hostmodel,n=this.geometry,a=i.getmodel("effect"),o=a.get("trailwidth")*t.getdevicepixelratio(),s=a.get("traillength"),l=i.get("effect.constantspeed"),h=1e3*i.get("effect.period"),u=null!=l;u?this.material.set("speed",l/1e3):this.material.set("period",h),this.material[u?"define":"undefine"]("vertex","constant_speed");var c=i.get("polyline");n.traillength=s,this.material.set("traillength",s),n.resetoffset(),["position","positionprev","positionnext"].foreach((function(e){n.attributes[e].value=r.attributes[e].value})),["dist","distall","start","offset","color"].foreach((function(e){n.attributes[e].init(n.vertexcount)})),n.indices=r.indices;var d=[],f=a.get("trailcolor"),p=a.get("trailopacity"),m=null!=f,g=null!=p;this.updateworldtransform();var _=this.worldtransform.x.len(),v=this.worldtransform.y.len(),y=this.worldtransform.z.len(),x=0,b=0;e.each((function(t){var i=e.getitemlayout(t),a=g?p:rh(e,t),s=ih(e,t);null==a&&(a=1),(d=ka.parsecolor(m?f:s,d))[3]*=a;for(var l=c?r.getpolylinevertexcount(i):r.getcubiccurvevertexcount(i[0],i[1],i[2],i[3]),w=0,t=[],s=[],m=x;mx&&(w+=nd.dist(t,s)),n.attributes.dist.set(m,w),nd.copy(s,t);b=math.max(b,w);var a=math.random()*(u?w:h);for(m=x;m0?1:-1)*o/2),n.attributes.color.set(m,d);x+=l})),this.material.set("spotsize",.1*b*s),this.material.set("spotintensity",a.get("spotintensity")),n.dirty()},setanimationtime:function(e){this.material.set("time",e)}});ka.shader.import(is);const od=i.chartview.extend({type:"lines3d",__ecgl__:!0,init:function(e,t){this.groupgl=new ka.node,this._meshlinesmaterial=new ka.material({shader:ka.createshader("ecgl.meshlines3d"),transparent:!0,depthmask:!1}),this._linesmesh=new ka.mesh({geometry:new ro,material:this._meshlinesmaterial,$ignorepicking:!0}),this._trailmesh=new ad},render:function(e,t,r){this.groupgl.add(this._linesmesh);var i=e.coordinatesystem,n=e.getdata();if(i&&i.viewgl){i.viewgl.add(this.groupgl),this._updatelines(e,t,r);var a=i.viewgl.islinearspace()?"define":"undefine";this._linesmesh.material[a]("fragment","srgb_decode"),this._trailmesh.material[a]("fragment","srgb_decode")}var o=this._trailmesh;if(o.stopanimation(),e.get("effect.show")){this.groupgl.add(o),o.updatedata(n,r,this._linesmesh.geometry),o.__time=o.__time||0;var s=36e5;this._curveeffectsanimator=o.animate("",{loop:!0}).when(s,{__time:s}).during((function(){o.setanimationtime(o.__time)})).start()}else this.groupgl.remove(o),this._curveeffectsanimator=null;this._linesmesh.material.blend=this._trailmesh.material.blend="lighter"===e.get("blendmode")?ka.additiveblend:null},pauseeffect:function(){this._curveeffectsanimator&&this._curveeffectsanimator.pause()},resumeeffect:function(){this._curveeffectsanimator&&this._curveeffectsanimator.resume()},toggleeffect:function(){var e=this._curveeffectsanimator;e&&(e.ispaused()?e.resume():e.pause())},_updatelines:function(e,t,r){var i=e.getdata(),n=e.coordinatesystem,a=this._linesmesh.geometry,o=e.get("polyline");a.expandline=!0;var s=function(e){return null!=e.radius?e.radius:null!=e.size?math.max(e.size[0],e.size[1],e.size[2]):100}(n);a.segmentscale=s/20;var l="linestyle.width".split("."),h=r.getdevicepixelratio(),u=0;i.each((function(e){var t=i.getitemmodel(e).get(l);null==t&&(t=1),i.setitemvisual(e,"linewidth",t),u=math.max(t,u)})),a.usenativeline=!1;var c=0,d=0;i.each((function(e){var t=i.getitemlayout(e);o?(c+=a.getpolylinevertexcount(t),d+=a.getpolylinetrianglecount(t)):(c+=a.getcubiccurvevertexcount(t[0],t[1],t[2],t[3]),d+=a.getcubiccurvetrianglecount(t[0],t[1],t[2],t[3]))})),a.setvertexcount(c),a.settrianglecount(d),a.resetoffset();var f=[];i.each((function(e){var t=i.getitemlayout(e),r=ih(i,e),n=rh(i,e),s=i.getitemvisual(e,"linewidth")*h;null==n&&(n=1),(f=ka.parsecolor(r,f))[3]*=n,o?a.addpolyline(t,f,s):a.addcubiccurve(t[0],t[1],t[2],t[3],f,s)})),a.dirty()},remove:function(){this.groupgl.removeall()},dispose:function(){this.groupgl.removeall()}});function sd(e,t){for(var r=[],i=0;i0;this._updatesurfacemesh(this._surfacemesh,e,u,f);var p=this._surfacemesh.material;f?(p.define("wireframe_quad"),p.set("wireframelinewidth",d),p.set("wireframelinecolor",ka.parsecolor(c.get("linestyle.color")))):p.undefine("wireframe_quad"),this._inithandler(e,r),this._updateanimation(e)},_updateanimation:function(e){ka.updatevertexanimation([["prevposition","position"],["prevnormal","normal"]],this._prevsurfacemesh,this._surfacemesh,e)},_createsurfacemesh:function(){var e=new ka.mesh({geometry:new ka.geometry({dynamic:!0,sorttriangles:!0}),shadowdepthmaterial:new ka.material({shader:new ka.shader(ka.shader.source("ecgl.sm.depth.vertex"),ka.shader.source("ecgl.sm.depth.fragment"))}),culling:!1,renderorder:10,rendernormal:!0});return e.geometry.createattribute("barycentric","float",4),e.geometry.createattribute("prevposition","float",3),e.geometry.createattribute("prevnormal","float",3),object.assign(e.geometry,nh),e},_inithandler:function(e,t){var r=e.getdata(),i=this._surfacemesh,n=e.coordinatesystem;i.seriesindex=e.seriesindex;var a=-1;i.off("mousemove"),i.off("mouseout"),i.on("mousemove",(function(e){var o=function(e,t){for(var r=1/0,n=-1,a=[],o=0;o=0){var s=[];i.geometry.attributes.position.get(o,s);for(var l=n.pointtodata(s),h=1/0,u=-1,c=[],d=0;d65535?uint32array:uint16array)((p-1)*(m-1)*6),w=function(e,t,r){r[1]=e*m+t,r[0]=e*m+t+1,r[3]=(e+1)*m+t+1,r[2]=(e+1)*m+t},t=!1;if(l){var s=[],m=[],a=0;g?u.init(n.vertexcount):u.value=null;for(var e=[[],[],[]],c=[],d=[],l=fd.create(),p=function(e,t,r){var i=3*t;return r[0]=e[i],r[1]=e[i+1],r[2]=e[i+2],r},o=new float32array(o.length),n=new float32array(o.length/3*4),i=0;i0;){if(math.floor(s/u)===s/u)return[u,s/u];u--}return[u=math.floor(math.sqrt(s)),u]},dispose:function(){this.groupgl.removeall()},remove:function(){this.groupgl.removeall()}});function md(e,t){for(var r=[],i=0;i=0&&e.call(t,r[n],n)},e.prototype.eachedge=function(e,t){for(var r=this.edges,i=r.length,n=0;n=0&&r[n].node1.dataindex>=0&&r[n].node2.dataindex>=0&&e.call(t,r[n],n)},e.prototype.breadthfirsttraverse=function(e,t,r,i){if(t instanceof ad||(t=this._nodesmap[sd(t)]),t){for(var n="out"===r?"outedges":"in"===r?"inedges":"edges",a=0;a=0&&r.node2.dataindex>=0})),n=0,a=i.length;n=0&&this[e][t].setitemvisual(this.dataindex,r,i)},getvisual:function(r){return this[e][t].getitemvisual(this.dataindex,r)},setlayout:function(r,i){this.dataindex>=0&&this[e][t].setitemlayout(this.dataindex,r,i)},getlayout:function(){return this[e][t].getitemlayout(this.dataindex)},getgraphicel:function(){return this[e][t].getitemgraphicel(this.dataindex)},getrawindex:function(){return this[e][t].getrawindex(this.dataindex)}}}_a(ad,cd("hostgraph","data")),_a(ed,cd("hostgraph","edgedata"));const dd=md;var ld=_o();function pd(e,t){if(ld(this).maindata===this){var r=ga({},ld(this).datas);r[this.datatype]=t,bd(t,r,e)}else fd(t,this.datatype,ld(this).maindata,e);return t}function od(e,t){return e.struct&&e.struct.update(),t}function nd(e,t){return ya(ld(t).datas,(function(r,i){r!==t&&fd(r.cloneshallow(),i,t,e)})),t}function id(e){var t=ld(this).maindata;return null==e||null==t?t:ld(t).datas[e]}function rd(){var e=ld(this).maindata;return null==e?[{data:e}]:xa(ba(ld(e).datas),(function(t){return{type:t,data:ld(e).datas[t]}}))}function bd(e,t,r){ld(e).datas={},ya(t,(function(t,i){fd(t,i,e,r)}))}function fd(e,t,r,i){ld(r).datas[t]=e,ld(e).maindata=r,e.datatype=t,i.struct&&(e[i.structattr]=i.struct,i.struct[i.datasattr[t]]=e),e.getlinkeddata=id,e.getlinkeddataall=rd}var zd=i.seriesmodel.extend({type:"series.graphgl",visualstyleaccesspath:"itemstyle",hassymbolvisual:!0,init:function(e){zd.superapply(this,"init",arguments),this.legenddataprovider=function(){return this._categoriesdata},this._updatecategoriesdata()},mergeoption:function(e){zd.superapply(this,"mergeoption",arguments),this._updatecategoriesdata()},getformattedlabel:function(e,t,r,i){var n=ac.getformattedlabel(this,e,t,r,i);if(null==n){var a=this.getdata(),o=a.dimensions[a.dimensions.length-1];n=a.get(o,e)}return n},getinitialdata:function(e,t){var r=e.edges||e.links||[],n=e.data||e.nodes||[],a=this;if(n&&r)return function(e,t,r,n,a){for(var o=new dd(!0),s=0;s "+p)),c++)}var m=i.helper.createdimensions(e,{coorddimensions:["value"]});(l=new i.list(m,r)).initdata(e);var g,_,v,y=new i.list(["value"],r);return y.initdata(u,h),a&&a(l,y),_=(g={maindata:l,struct:o,structattr:"graph",datas:{node:l,edge:y},datasattr:{node:"data",edge:"edgedata"}}).maindata,(v=g.datas)||(v={main:_},g.datasattr={main:"data"}),g.datas=g.maindata=null,bd(_,v,g),ya(v,(function(e){ya(_.transferable_methods,(function(t){e.wrapmethod(t,wa(pd,g))}))})),_.wrapmethod("cloneshallow",wa(nd,g)),ya(_.changable_methods,(function(e){_.wrapmethod(e,wa(od,g))})),function(e,t){if(!e)throw new error(void 0)}(v[_.datatype]===_),o.update(),o}(n,r,this,0,(function(e,r){e.wrapmethod("getitemmodel",(function(e){const t=a._categoriesmodels[e.getshallow("category")];return t&&(t.parentmodel=e.parentmodel,e.parentmodel=t),e}));const i=t.getmodel([]).getmodel;function n(e,t){const r=i.call(this,e,t);return r.resolveparentpath=o,r}function o(e){if(e&&("label"===e[0]||"label"===e[1])){const t=e.slice();return"label"===e[0]?t[0]="edgelabel":"label"===e[1]&&(t[1]="edgelabel"),t}return e}r.wrapmethod("getitemmodel",(function(e){return e.resolveparentpath=o,e.getmodel=n,e}))})).data},getgraph:function(){return this.getdata().graph},getedgedata:function(){return this.getgraph().edgedata},getcategoriesdata:function(){return this._categoriesdata},formattooltip:function(e,t,r){if("edge"===r){var n=this.getdata(),a=this.getdataparams(e,r),o=n.graph.getedgebyindex(e),s=n.getname(o.node1.dataindex),l=n.getname(o.node2.dataindex),h=[];return null!=s&&h.push(s),null!=l&&h.push(l),h=i.format.encodehtml(h.join(" > ")),a.value&&(h+=" : "+i.format.encodehtml(a.value)),h}return zd.superapply(this,"formattooltip",arguments)},_updatecategoriesdata:function(){var e=(this.option.categories||[]).map((function(e){return null!=e.value?e:object.assign({value:0},e)})),t=new i.list(["value"],this);t.initdata(e),this._categoriesdata=t,this._categoriesmodels=t.maparray((function(e){return t.getitemmodel(e,!0)}))},setview:function(e){null!=e.zoom&&(this.option.zoom=e.zoom),null!=e.offset&&(this.option.offset=e.offset)},setnodeposition:function(e){for(var t=0;t65535?this.indices instanceof uint16array&&(this.indices=new uint32array(this.indices)):this.indices instanceof uint32array&&(this.indices=new uint16array(this.indices)))},settrianglecount:function(e){this.trianglecount!==e&&(this.indices=0===e?null:this.vertexcount>65535?new uint32array(3*e):new uint16array(3*e))},_getcubiccurveapproxstep:function(e,t,r,i){return 1/(ud.dist(e,t)+ud.dist(r,t)+ud.dist(i,r)+1)*this.segmentscale},getcubiccurvevertexcount:function(e,t,r,i){var n=this._getcubiccurveapproxstep(e,t,r,i),a=math.ceil(1/n);return this.usenativeline?2*a:2*a+2},getcubiccurvetrianglecount:function(e,t,r,i){var n=this._getcubiccurveapproxstep(e,t,r,i),a=math.ceil(1/n);return this.usenativeline?0:2*a},getlinevertexcount:function(){return this.getpolylinevertexcount(kd)},getlinetrianglecount:function(){return this.getpolylinetrianglecount(kd)},getpolylinevertexcount:function(e){var t;return t="number"==typeof e?e:"number"!=typeof e[0]?e.length:e.length/2,this.usenativeline?2*(t-1):2*(t-1)+2},getpolylinetrianglecount:function(e){var t;return t="number"==typeof e?e:"number"!=typeof e[0]?e.length:e.length/2,this.usenativeline?0:2*(t-1)},addcubiccurve:function(e,t,r,i,n,a){null==a&&(a=1);var o=e[0],s=e[1],l=t[0],h=t[1],u=r[0],c=r[1],d=i[0],f=i[1],p=this._getcubiccurveapproxstep(e,t,r,i),m=p*p,g=m*p,_=3*p,v=3*m,y=6*m,x=6*g,b=o-2*l+u,w=s-2*h+c,t=3*(l-u)-o+d,s=3*(h-c)-s+f,m=o,a=s,e=(l-o)*_+b*v+t*g,c=(h-s)*_+w*v+s*g,d=b*y+t*x,l=w*y+s*x,p=t*x,o=s*x,n=0,i=0,r=math.ceil(1/p),b=new float32array(3*(r+1)),f=(b=[],0);for(i=0;i1&&(m=e>0?math.min(m,d):math.max(m,d),a=c>0?math.min(a,f):math.max(a,f));this.addpolyline(b,n,a)},addline:function(e,t,r,i){this.addpolyline([e,t],r,i)},addpolyline:function(){var e=ud.create(),t=ud.create(),r=ud.create(),i=ud.create(),n=[],a=[],o=[];return function(s,l,h,u,c){if(s.length){var d="number"!=typeof s[0];if(null==c&&(c=d?s.length:s.length/2),!(c<2)){null==u&&(u=0),null==h&&(h=1),this._itemvertexoffsets.push(this._vertexoffset);for(var f,p=d?"number"!=typeof l[0]:l.length/4===c,m=this.attributes.position,g=this.attributes.color,_=this.attributes.offset,v=this.attributes.normal,y=this.indices,x=this._vertexoffset,b=0;b1&&(m.copy(x,x-1),g.copy(x,x-1),x++);else{var s;if(b0){ud.sub(e,n,o),ud.sub(t,a,n),ud.normalize(e,e),ud.normalize(t,t),ud.add(i,e,t),ud.normalize(i,i);var m=h/2*math.min(1/ud.dot(e,i),2);r[0]=-i[1],r[1]=i[0],s=m}else ud.sub(e,a,n),ud.normalize(e,e),r[0]=-e[1],r[1]=e[0],s=h/2;else ud.sub(e,n,o),ud.normalize(e,e),r[0]=-e[1],r[1]=e[0],s=h/2;v.set(x,r),v.set(x+1,r),_.set(x,s),_.set(x+1,-s),ud.copy(o,n),m.set(x,n),m.set(x+1,n),g.set(x,f),g.set(x+1,f),x+=2}if(this.usenativeline)g.set(x,f),m.set(x,n),x++;else if(b>0){var a=3*this._faceoffset;(y=this.indices)[a]=x-4,y[a+1]=x-3,y[a+2]=x-2,y[a+3]=x-3,y[a+4]=x-1,y[a+5]=x-2,this._faceoffset+=2}}this._vertexoffset=x}}}}(),setitemcolor:function(e,t){for(var r=this._itemvertexoffsets[e],i=e 0.0) {\n float factor = 0.0;\n if (preventoverlap) {\n float d = sqrt(d2);\n d = d - n0.w - n1.w;\n if (d > 0.0) {\n factor = scaling * n0.z * n1.z / (d * d);\n }\n else if (d < 0.0) {\n factor = scaling * 100.0 * n0.z * n1.z;\n }\n }\n else {\n factor = scaling * n0.z * n1.z / d2;\n }\n force += dir * factor;\n }\n }\n\n vec2 dir = gravitycenter - n0.xy;\n float d = 1.0;\n if (!stronggravitymode) {\n d = length(dir);\n }\n\n force += dir * n0.z * gravity / (d + 1.0);\n\n gl_fragcolor = vec4(force, 0.0, 1.0);\n}\n@end\n\n@export ecgl.forceatlas2.updateedgeattraction.vertex\n\nattribute vec2 node1;\nattribute vec2 node2;\nattribute float weight;\n\nuniform sampler2d positiontex;\nuniform float edgeweightinfluence;\nuniform bool preventoverlap;\nuniform bool linlogmode;\n\nuniform vec2 windowsize: window_size;\n\nvarying vec2 v_force;\n\nvoid main() {\n\n vec4 n0 = texture2d(positiontex, node1);\n vec4 n1 = texture2d(positiontex, node2);\n\n vec2 dir = n1.xy - n0.xy;\n float d = length(dir);\n float w;\n if (edgeweightinfluence == 0.0) {\n w = 1.0;\n }\n else if (edgeweightinfluence == 1.0) {\n w = weight;\n }\n else {\n w = pow(weight, edgeweightinfluence);\n }\n vec2 offset = vec2(1.0 / windowsize.x, 1.0 / windowsize.y);\n vec2 scale = vec2((windowsize.x - 1.0) / windowsize.x, (windowsize.y - 1.0) / windowsize.y);\n vec2 pos = node1 * scale * 2.0 - 1.0;\n gl_position = vec4(pos + offset, 0.0, 1.0);\n gl_pointsize = 1.0;\n\n float factor;\n if (preventoverlap) {\n d = d - n1.w - n0.w;\n }\n if (d <= 0.0) {\n v_force = vec2(0.0);\n return;\n }\n\n if (linlogmode) {\n factor = w * log(d) / d;\n }\n else {\n factor = w;\n }\n v_force = dir * factor;\n}\n@end\n\n@export ecgl.forceatlas2.updateedgeattraction.fragment\n\nvarying vec2 v_force;\n\nvoid main() {\n gl_fragcolor = vec4(v_force, 0.0, 0.0);\n}\n@end\n\n@export ecgl.forceatlas2.calcweightedsum.vertex\n\nattribute vec2 node;\n\nvarying vec2 v_nodeuv;\n\nvoid main() {\n\n v_nodeuv = node;\n gl_position = vec4(0.0, 0.0, 0.0, 1.0);\n gl_pointsize = 1.0;\n}\n@end\n\n@export ecgl.forceatlas2.calcweightedsum.fragment\n\nvarying vec2 v_nodeuv;\n\nuniform sampler2d positiontex;\nuniform sampler2d forcetex;\nuniform sampler2d forceprevtex;\n\nvoid main() {\n vec2 force = texture2d(forcetex, v_nodeuv).rg;\n vec2 forceprev = texture2d(forceprevtex, v_nodeuv).rg;\n\n float mass = texture2d(positiontex, v_nodeuv).z;\n float swing = length(force - forceprev) * mass;\n float traction = length(force + forceprev) * 0.5 * mass;\n\n gl_fragcolor = vec4(swing, traction, 0.0, 0.0);\n}\n@end\n\n@export ecgl.forceatlas2.calcglobalspeed\n\nuniform sampler2d globalspeedprevtex;\nuniform sampler2d weightedsumtex;\nuniform float jittertolerence;\n\nvoid main() {\n vec2 weightedsum = texture2d(weightedsumtex, vec2(0.5)).xy;\n float prevglobalspeed = texture2d(globalspeedprevtex, vec2(0.5)).x;\n float globalspeed = jittertolerence * jittertolerence\n * weightedsum.y / weightedsum.x;\n if (prevglobalspeed > 0.0) {\n globalspeed = min(globalspeed / prevglobalspeed, 1.5) * prevglobalspeed;\n }\n gl_fragcolor = vec4(globalspeed, 0.0, 0.0, 1.0);\n}\n@end\n\n@export ecgl.forceatlas2.updateposition\n\nuniform sampler2d forcetex;\nuniform sampler2d forceprevtex;\nuniform sampler2d positiontex;\nuniform sampler2d globalspeedtex;\n\nvarying vec2 v_texcoord;\n\nvoid main() {\n vec2 force = texture2d(forcetex, v_texcoord).xy;\n vec2 forceprev = texture2d(forceprevtex, v_texcoord).xy;\n vec4 node = texture2d(positiontex, v_texcoord);\n\n float globalspeed = texture2d(globalspeedtex, vec2(0.5)).r;\n float swing = length(force - forceprev);\n float speed = 0.1 * globalspeed / (0.1 + globalspeed * sqrt(swing));\n\n float df = length(force);\n if (df > 0.0) {\n speed = min(df * speed, 10.0) / df;\n\n gl_fragcolor = vec4(node.xy + speed * force, node.zw);\n }\n else {\n gl_fragcolor = node;\n }\n}\n@end\n\n@export ecgl.forceatlas2.edges.vertex\nuniform mat4 worldviewprojection : worldviewprojection;\n\nattribute vec2 node;\nattribute vec4 a_color : color;\nvarying vec4 v_color;\n\nuniform sampler2d positiontex;\n\nvoid main()\n{\n gl_position = worldviewprojection * vec4(\n texture2d(positiontex, node).xy, -10.0, 1.0\n );\n v_color = a_color;\n}\n@end\n\n@export ecgl.forceatlas2.edges.fragment\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\nvarying vec4 v_color;\nvoid main() {\n gl_fragcolor = color * v_color;\n}\n@end");var wd={repulsionbydegree:!0,linlogmode:!1,stronggravitymode:!1,gravity:1,scaling:1,edgeweightinfluence:1,jittertolerence:.1,preventoverlap:!1,dissuadehubs:!1,gravitycenter:null};function jd(e){var t={type:ka.texture.float,minfilter:ka.texture.nearest,magfilter:ka.texture.nearest};this._positionsourcetex=new ka.texture2d(t),this._positionsourcetex.flipy=!1,this._positiontex=new ka.texture2d(t),this._positionprevtex=new ka.texture2d(t),this._forcetex=new ka.texture2d(t),this._forceprevtex=new ka.texture2d(t),this._weightedsumtex=new ka.texture2d(t),this._weightedsumtex.width=this._weightedsumtex.height=1,this._globalspeedtex=new ka.texture2d(t),this._globalspeedprevtex=new ka.texture2d(t),this._globalspeedtex.width=this._globalspeedtex.height=1,this._globalspeedprevtex.width=this._globalspeedprevtex.height=1,this._noderepulsionpass=new pn({fragment:ka.shader.source("ecgl.forceatlas2.updatenoderepulsion")}),this._positionpass=new pn({fragment:ka.shader.source("ecgl.forceatlas2.updateposition")}),this._globalspeedpass=new pn({fragment:ka.shader.source("ecgl.forceatlas2.calcglobalspeed")}),this._copypass=new pn({fragment:ka.shader.source("clay.compositor.output")});var r=function(e){e.blendequation(e.func_add),e.blendfunc(e.one,e.one)};this._edgeforcemesh=new ka.mesh({geometry:new ka.geometry({attributes:{node1:new ka.geometry.attribute("node1","float",2),node2:new ka.geometry.attribute("node2","float",2),weight:new ka.geometry.attribute("weight","float",1)},dynamic:!0,mainattribute:"node1"}),material:new ka.material({transparent:!0,shader:ka.createshader("ecgl.forceatlas2.updateedgeattraction"),blend:r,depthmask:!1,depthtext:!1}),mode:ka.mesh.points}),this._weightedsummesh=new ka.mesh({geometry:new ka.geometry({attributes:{node:new ka.geometry.attribute("node","float",2)},dynamic:!0,mainattribute:"node"}),material:new ka.material({transparent:!0,shader:ka.createshader("ecgl.forceatlas2.calcweightedsum"),blend:r,depthmask:!1,depthtext:!1}),mode:ka.mesh.points}),this._framebuffer=new zi({depthbuffer:!1}),this._dummycamera=new ka.orthographiccamera({left:-1,right:1,top:1,bottom:-1,near:0,far:100}),this._globalspeed=0}jd.prototype.updateoption=function(e){for(var t in wd)this[t]=wd[t];var r=this._nodes.length;if(this.jittertolerence=r>5e4?10:r>5e3?1:.1,this.scaling=r>100?2:10,e)for(var t in wd)null!=e[t]&&(this[t]=e[t]);if(this.repulsionbydegree)for(var i=this._positionsourcetex.pixels,n=0;ne},jd.prototype._swaptexture=function(){var e=this._positionprevtex;this._positionprevtex=this._positiontex,this._positiontex=e,e=this._forceprevtex,this._forceprevtex=this._forcetex,this._forcetex=e,e=this._globalspeedprevtex,this._globalspeedprevtex=this._globalspeedtex,this._globalspeedtex=e},jd.prototype._initfromsource=function(e){this._framebuffer.attach(this._positionprevtex),this._framebuffer.bind(e),this._copypass.setuniform("texture",this._positionsourcetex),this._copypass.render(e),e.gl.clearcolor(0,0,0,0),this._framebuffer.attach(this._forceprevtex),e.gl.clear(e.gl.color_buffer_bit),this._framebuffer.attach(this._globalspeedprevtex),e.gl.clear(e.gl.color_buffer_bit),this._framebuffer.unbind(e)},jd.prototype._resize=function(e,t){["_positionsourcetex","_positiontex","_positionprevtex","_forcetex","_forceprevtex"].foreach((function(r){this[r].width=e,this[r].height=t,this[r].dirty()}),this)},jd.prototype.dispose=function(e){this._framebuffer.dispose(e),this._copypass.dispose(e),this._noderepulsionpass.dispose(e),this._positionpass.dispose(e),this._globalspeedpass.dispose(e),this._edgeforcemesh.geometry.dispose(e),this._weightedsummesh.geometry.dispose(e),this._positionsourcetex.dispose(e),this._positiontex.dispose(e),this._positionprevtex.dispose(e),this._forcetex.dispose(e),this._forceprevtex.dispose(e),this._weightedsumtex.dispose(e),this._globalspeedtex.dispose(e),this._globalspeedprevtex.dispose(e)};const xd=jd;var qd=function(){var e=function(){return new float32array(2)},t=function(e,t){var r=t[0]-e[0],i=t[1]-e[1];return math.sqrt(r*r+i*i)},r=function(e){var t=e[0],r=e[1];return math.sqrt(t*t+r*r)},i=function(e,t,r,i){return e[0]=t[0]+r[0]*i,e[1]=t[1]+r[1]*i,e},n=function(e,t,r){return e[0]=t[0]+r[0],e[1]=t[1]+r[1],e},a=function(e,t,r){return e[0]=t[0]-r[0],e[1]=t[1]-r[1],e},o=function(e,t,r){return e[0]=t,e[1]=r,e};function s(){this.subregions=[],this.nsubregions=0,this.node=null,this.mass=0,this.centerofmass=null,this.bbox=new float32array(4),this.size=0}var l=s.prototype;function h(){this.position=new float32array(2),this.force=e(),this.forceprev=e(),this.mass=1,this.indegree=0,this.outdegree=0}function u(e,t){this.source=e,this.target=t,this.weight=1}function c(){this.autosettings=!0,this.barneshutoptimize=!0,this.barneshuttheta=1.5,this.repulsionbydegree=!0,this.linlogmode=!1,this.stronggravitymode=!1,this.gravity=1,this.scaling=1,this.edgeweightinfluence=1,this.jittertolerence=.1,this.preventoverlap=!1,this.dissuadehubs=!1,this.rootregion=new s,this.rootregion.centerofmass=e(),this.nodes=[],this.edges=[],this.bbox=new float32array(4),this.gravitycenter=null,this._massarr=null,this._swingingarr=null,this._sizearr=null,this._globalspeed=0}l.beforeupdate=function(){for(var e=0;e=e&&this.bbox[1]<=t&&this.bbox[3]>=t},l.setbbox=function(e,t,r,i){this.bbox[0]=e,this.bbox[1]=t,this.bbox[2]=r,this.bbox[3]=i,this.size=(r-e+i-t)/2},l._newsubregion=function(){var e=this.subregions[this.nsubregions];return e||(e=new s,this.subregions[this.nsubregions]=e),this.nsubregions++,e},l._addnodetosubregion=function(e){var t=this.findsubregion(e.position[0],e.position[1]),r=this.bbox;if(!t){var i=(r[0]+r[2])/2,n=(r[1]+r[3])/2,a=(r[2]-r[0])/2,o=(r[3]-r[1])/2,s=e.position[0]>=i?1:0,l=e.position[1]>=n?1:0;(t=this._newsubregion()).setbbox(s*a+r[0],l*o+r[1],(s+1)*a+r[0],(l+1)*o+r[1])}t.addnode(e)},l._updatecenterofmass=function(e){null==this.centerofmass&&(this.centerofmass=new float32array(2));var t=this.centerofmass[0]*this.mass,r=this.centerofmass[1]*this.mass;t+=e.position[0]*e.mass,r+=e.position[1]*e.mass,this.mass+=e.mass,this.centerofmass[0]=t/this.mass,this.centerofmass[1]=r/this.mass};var d=c.prototype;d.initnodes=function(e,t,r){var i=t.length;this.nodes.length=0;for(var n=void 0!==r,a=0;a0&&(this.stronggravitymode?this.applynodestronggravity(c):this.applynodegravity(c))}for(h=0;h0&&(_=math.min(_/this._globalspeed,1.5)*this._globalspeed),this._globalspeed=_,h=0;h0&&(y=math.min(x*y,10)/x,i(u.position,u.position,u.force,y))}},d.applyregiontonoderepulsion=function(){var t=e();return function(e,r){if(e.node)this.applynodetonoderepulsion(e.node,r,!0);else{a(t,r.position,e.centerofmass);var n=t[0]*t[0]+t[1]*t[1];if(n>this.barneshuttheta*e.size*e.size){var o=this.scaling*r.mass*e.mass/n;i(r.force,r.force,t,o)}else for(var s=0;s0)s=this.scaling*e.mass*r.mass/(l*l);else{if(!(l<0))return;s=100*this.scaling*e.mass*r.mass}}else s=this.scaling*e.mass*r.mass/o;i(e.force,e.force,t,s),i(r.force,r.force,t,-s)}}}}(),d.applyedgeattraction=function(){var t=e();return function(e){var n=e.source,o=e.target;a(t,n.position,o.position);var s,l,h=r(t);s=0===this.edgeweightinfluence?1:1===this.edgeweightinfluence?e.weight:math.pow(e.weight,this.edgeweightinfluence),this.preventoverlap&&(h=h-n.size-o.size)<=0||(l=this.linlogmode?-s*math.log(h+1)/(h+1):-s,i(n.force,n.force,t,l),i(o.force,o.force,t,-l))}}(),d.applynodegravity=function(){var t=e();return function(e){a(t,this.gravitycenter,e.position);var n=r(t);i(e.force,e.force,t,this.gravity*e.mass/(n+1))}}(),d.applynodestronggravity=function(){var t=e();return function(e){a(t,this.gravitycenter,e.position),i(e.force,e.force,t,this.gravity*e.mass)}}(),d.updatebbox=function(){for(var e=1/0,t=1/0,r=-1/0,i=-1/0,n=0;n5e4?10:a>5e3?1:.1,t.scaling=a>100?2:10,t.barneshutoptimize=a>1e3,e)for(var r in zd)null!=e[r]&&(t[r]=e[r]);if(!t.gravitycenter){for(var o=[1/0,1/0],s=[-1/0,-1/0],l=0;le},yd.prototype.getnodeposition=function(e,t){if(t||(t=new float32array(2*this._nodes.length)),this._positionarr)for(var r=0;r0?1.1:.9,a=math.max(math.min(this._zoom*n,this.maxzoom),this.minzoom);n=a/this._zoom;var o=this._convertpos(r,i),s=(o.x-this._dx)*(n-1),l=(o.y-this._dy)*(n-1);this._dx-=s,this._dy-=l,this._zoom=a,this._needsupdate=!0}}},dispose:function(){var e=this.zr;e.off("mousedown",this._mousedownhandler),e.off("mousemove",this._mousemovehandler),e.off("mouseup",this._mouseuphandler),e.off("mousewheel",this._mousewheelhandler),e.off("globalout",this._mouseuphandler),e.animation.off("frame",this._update)}});var jd=po.vec2;ka.shader.import("@export ecgl.lines2d.vertex\n\nuniform mat4 worldviewprojection : worldviewprojection;\n\nattribute vec2 position: position;\nattribute vec4 a_color : color;\nvarying vec4 v_color;\n\n#ifdef positiontexture_enabled\nuniform sampler2d positiontexture;\n#endif\n\nvoid main()\n{\n gl_position = worldviewprojection * vec4(position, -10.0, 1.0);\n\n v_color = a_color;\n}\n\n@end\n\n@export ecgl.lines2d.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nvarying vec4 v_color;\n\nvoid main()\n{\n gl_fragcolor = color * v_color;\n}\n@end\n\n\n@export ecgl.meshlines2d.vertex\n\nattribute vec2 position: position;\nattribute vec2 normal;\nattribute float offset;\nattribute vec4 a_color : color;\n\nuniform mat4 worldviewprojection : worldviewprojection;\nuniform vec4 viewport : viewport;\n\nvarying vec4 v_color;\nvarying float v_miter;\n\nvoid main()\n{\n vec4 p2 = worldviewprojection * vec4(position + normal, -10.0, 1.0);\n gl_position = worldviewprojection * vec4(position, -10.0, 1.0);\n\n p2.xy /= p2.w;\n gl_position.xy /= gl_position.w;\n\n vec2 n = normalize(p2.xy - gl_position.xy);\n gl_position.xy += n * offset / viewport.zw * 2.0;\n\n gl_position.xy *= gl_position.w;\n\n v_color = a_color;\n}\n@end\n\n\n@export ecgl.meshlines2d.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nvarying vec4 v_color;\nvarying float v_miter;\n\nvoid main()\n{\n gl_fragcolor = color * v_color;\n}\n\n@end");var $d=1;const ef=i.chartview.extend({type:"graphgl",__ecgl__:!0,init:function(e,t){this.groupgl=new ka.node,this.viewgl=new il("orthographic"),this.viewgl.camera.left=this.viewgl.camera.right=0,this.viewgl.add(this.groupgl),this._pointsbuilder=new fc(!0,t),this._forceedgesmesh=new ka.mesh({material:new ka.material({shader:ka.createshader("ecgl.forceatlas2.edges"),transparent:!0,depthmask:!1,depthtest:!1}),$ignorepicking:!0,geometry:new ka.geometry({attributes:{node:new ka.geometry.attribute("node","float",2),color:new ka.geometry.attribute("color","float",4,"color")},dynamic:!0,mainattribute:"node"}),renderorder:-1,mode:ka.mesh.lines}),this._edgesmesh=new ka.mesh({material:new ka.material({shader:ka.createshader("ecgl.meshlines2d"),transparent:!0,depthmask:!1,depthtest:!1}),$ignorepicking:!0,geometry:new hd({usenativeline:!1,dynamic:!0}),renderorder:-1,culling:!1}),this._layoutid=0,this._control=new qd({zr:t.getzr(),viewgl:this.viewgl}),this._control.settarget(this.groupgl),this._control.init(),this._clickhandler=this._clickhandler.bind(this)},render:function(e,t,r){this.groupgl.add(this._pointsbuilder.rootnode),this._model=e,this._api=r,this._initlayout(e,t,r),this._pointsbuilder.update(e,t,r),this._forcelayoutinstance instanceof xd||this.groupgl.remove(this._forceedgesmesh),this._updatecamera(e,r),this._control.off("update"),this._control.on("update",(function(){r.dispatchaction({type:"graphglroam",seriesid:e.id,zoom:this._control.getzoom(),offset:this._control.getoffset()}),this._pointsbuilder.updateview(this.viewgl.camera)}),this),this._control.setzoom(mn(e.get("zoom"),1)),this._control.setoffset(e.get("offset")||[0,0]);var i=this._pointsbuilder.getpointsmesh();if(i.off("mousemove",this._mousemovehandler),i.off("mouseout",this._mouseouthandler,this),r.getzr().off("click",this._clickhandler),this._pointsbuilder.highlightonmouseover=!0,e.get("focusnodeadjacency")){var n=e.get("focusnodeadjacencyon");"click"===n?r.getzr().on("click",this._clickhandler):"mouseover"===n&&(i.on("mousemove",this._mousemovehandler,this),i.on("mouseout",this._mouseouthandler,this),this._pointsbuilder.highlightonmouseover=!1)}this._lastmouseoverdataindex=-1},_clickhandler:function(e){if(!this._layouting){var t=this._pointsbuilder.getpointsmesh().dataindex;t>=0?this._api.dispatchaction({type:"graphglfocusnodeadjacency",seriesid:this._model.id,dataindex:t}):this._api.dispatchaction({type:"graphglunfocusnodeadjacency",seriesid:this._model.id})}},_mousemovehandler:function(e){if(!this._layouting){var t=this._pointsbuilder.getpointsmesh().dataindex;t>=0?t!==this._lastmouseoverdataindex&&this._api.dispatchaction({type:"graphglfocusnodeadjacency",seriesid:this._model.id,dataindex:t}):this._mouseouthandler(e),this._lastmouseoverdataindex=t}},_mouseouthandler:function(e){this._layouting||(this._api.dispatchaction({type:"graphglunfocusnodeadjacency",seriesid:this._model.id}),this._lastmouseoverdataindex=-1)},_updateforceedgesgeometry:function(e,t){var r=this._forceedgesmesh.geometry,i=t.getedgedata(),n=0,a=this._forcelayoutinstance,o=2*i.count();r.attributes.node.init(o),r.attributes.color.init(o),i.each((function(t){var o=e[t];r.attributes.node.set(n,a.getnodeuv(o.node1)),r.attributes.node.set(n+1,a.getnodeuv(o.node2));var s=ih(i,o.dataindex),l=ka.parsecolor(s);l[3]*=mn(rh(i,o.dataindex),1),r.attributes.color.set(n,l),r.attributes.color.set(n+1,l),n+=2})),r.dirty()},_updatemeshlinesgeometry:function(){var e=this._model.getedgedata(),t=this._edgesmesh.geometry,r=(e=this._model.getedgedata(),this._model.getdata().getlayout("points"));t.resetoffset(),t.setvertexcount(e.count()*t.getlinevertexcount()),t.settrianglecount(e.count()*t.getlinetrianglecount());var i=[],n=[],a=["linestyle","width"];this._originaledgecolors=new float32array(4*e.count()),this._edgeindicesmap=new float32array(e.count()),e.each((function(o){var s=e.graph.getedgebyindex(o),l=2*s.node1.dataindex,h=2*s.node2.dataindex;i[0]=r[l],i[1]=r[l+1],n[0]=r[h],n[1]=r[h+1];var u=ih(e,s.dataindex),c=ka.parsecolor(u);c[3]*=mn(rh(e,s.dataindex),1);var d=e.getitemmodel(s.dataindex),f=mn(d.get(a),1)*this._api.getdevicepixelratio();t.addline(i,n,c,f);for(var p=0;p<4;p++)this._originaledgecolors[4*s.dataindex+p]=c[p];this._edgeindicesmap[s.dataindex]=o}),this),t.dirty()},_updateforcenodesgeometry:function(e){for(var t=this._pointsbuilder.getpointsmesh(),r=[],i=0;i=f&&(l._syncnodeposition(e),d=0),r.getzr().refresh(),qa((function(){p(t)}))}))};qa((function(){l._forcelayoutinstancetodispose&&(l._forcelayoutinstancetodispose.dispose(n.layer.renderer),l._forcelayoutinstancetodispose=null),p(h)})),this._layouting=!0}}},stoplayout:function(e,t,r,i){i&&null!=i.from&&i.from!==this.uid||(this._layoutid=0,this.groupgl.remove(this._forceedgesmesh),this.groupgl.add(this._edgesmesh),this._forcelayoutinstance&&this.viewgl.layer&&(i&&i.beforelayout||(this._syncnodeposition(e),this._updateafterlayout(e,t,r)),this._api.getzr().refresh(),this._layouting=!1))},_syncnodeposition:function(e){var t=this._forcelayoutinstance.getnodeposition(this.viewgl.layer.renderer);e.getdata().setlayout("points",t),e.setnodeposition(t)},_updateafterlayout:function(e,t,r){this._updatemeshlinesgeometry(),this._pointsbuilder.removepositiontexture(),this._pointsbuilder.updatelayout(e,t,r),this._pointsbuilder.updateview(this.viewgl.camera),this._pointsbuilder.updatelabels(),this._pointsbuilder.showlabels()},focusnodeadjacency:function(e,t,r,i){var n=this._model.getdata();this._downplayall();var a=i.dataindex,o=n.graph,s=[],l=o.getnodebyindex(a);s.push(l),l.edges.foreach((function(e){e.dataindex<0||(e.node1!==l&&s.push(e.node1),e.node2!==l&&s.push(e.node2))}),this),this._pointsbuilder.fadeoutall(.05),this._fadeoutedgesall(.05),s.foreach((function(e){this._pointsbuilder.highlight(n,e.dataindex)}),this),this._pointsbuilder.updatelabels(s.map((function(e){return e.dataindex})));var h=[];l.edges.foreach((function(e){e.dataindex>=0&&(this._highlightedge(e.dataindex),h.push(e))}),this),this._focusnodes=s,this._focusedges=h},unfocusnodeadjacency:function(e,t,r,i){this._downplayall(),this._pointsbuilder.fadeinall(),this._fadeinedgesall(),this._pointsbuilder.updatelabels()},_highlightedge:function(e){var t=this._model.getedgedata().getitemmodel(e),r=ka.parsecolor(t.get("emphasis.linestyle.color")||t.get("linestyle.color")),i=mn(t.get("emphasis.linestyle.opacity"),t.get("linestyle.opacity"),1);r[3]*=i,this._edgesmesh.geometry.setitemcolor(this._edgeindicesmap[e],r)},_downplayall:function(){this._focusnodes&&this._focusnodes.foreach((function(e){this._pointsbuilder.downplay(this._model.getdata(),e.dataindex)}),this),this._focusedges&&this._focusedges.foreach((function(e){this._downplayedge(e.dataindex)}),this)},_downplayedge:function(e){var t=this._getcolor(e,[]);this._edgesmesh.geometry.setitemcolor(this._edgeindicesmap[e],t)},_setedgefade:(tf=[],function(e,t){this._getcolor(e,tf),tf[3]*=t,this._edgesmesh.geometry.setitemcolor(this._edgeindicesmap[e],tf)}),_getcolor:function(e,t){for(var r=0;r<4;r++)t[r]=this._originaledgecolors[4*e+r];return t},_fadeoutedgesall:function(e){this._model.getdata().graph.eachedge((function(t){this._setedgefade(t.dataindex,e)}),this)},_fadeinedgesall:function(){this._fadeoutedgesall(1)},_updatecamera:function(e,t){this.viewgl.setviewport(0,0,t.getwidth(),t.getheight(),t.getdevicepixelratio());for(var r=this.viewgl.camera,i=e.getdata().getlayout("points"),n=jd.create(1/0,1/0),a=jd.create(-1/0,-1/0),o=[],s=0;sr.left&&hr.top)){var u=math.max(a[0]-n[0],10),c=u/t.getwidth()*t.getheight();u*=1.4,c*=1.4,n[0]-=.2*u,r.left=n[0],r.top=l-c/2,r.bottom=l+c/2,r.right=u+n[0],r.near=0,r.far=100}},dispose:function(){var e=this.viewgl.layer.renderer;this._forcelayoutinstance&&this._forcelayoutinstance.dispose(e),this.groupgl.removeall(),this._layoutid=-1,this._pointsbuilder.dispose()},remove:function(){this.groupgl.removeall(),this._control.dispose()}});var tf;function rf(e){return e instanceof array||(e=[e,e]),e}(0,i.use)((function(e){function t(){}e.registerchartview(ef),e.registerseriesmodel(gd),e.registervisual((function(e){const t={};e.eachseriesbytype("graphgl",(function(e){var r=e.getcategoriesdata(),n=e.getdata(),a={};r.each((function(i){var n=r.getname(i);a["ec-"+n]=i;var o=r.getitemmodel(i),s=o.getmodel("itemstyle").getitemstyle();s.fill||(s.fill=e.getcolorfrompalette(n,t)),r.setitemvisual(i,"style",s);var l=["symbol","symbolsize","symbolkeepaspect"];for(let e=0;e65535?new uint32array(3*i):new uint16array(3*i))},addline:function(e){var t=this._vertexoffset;this.attributes.position.set(t,[e[0],e[1],1]),this.attributes.position.set(t+1,[e[0],e[1],-1]),this.attributes.position.set(t+2,[e[0],e[1],2]),this.attributes.position.set(t+3,[e[0],e[1],-2]),this.settriangleindices(this._faceoffset++,[t,t+1,t+2]),this.settriangleindices(this._faceoffset++,[t+1,t+2,t+3]),this._vertexoffset+=4}});xe.import("@export ecgl.vfparticle.particle.fragment\n\nuniform sampler2d particletexture;\nuniform sampler2d spawntexture;\nuniform sampler2d velocitytexture;\n\nuniform float deltatime;\nuniform float elapsedtime;\n\nuniform float speedscaling : 1.0;\n\nuniform vec2 texturesize;\nuniform vec4 region : [0, 0, 1, 1];\nuniform float firstframetime;\n\nvarying vec2 v_texcoord;\n\n\nvoid main()\n{\n vec4 p = texture2d(particletexture, v_texcoord);\n bool spawn = false;\n if (p.w <= 0.0) {\n p = texture2d(spawntexture, fract(v_texcoord + elapsedtime / 10.0));\n p.w -= firstframetime;\n spawn = true;\n }\n vec2 v = texture2d(velocitytexture, fract(p.xy * region.zw + region.xy)).xy;\n v = (v - 0.5) * 2.0;\n p.z = length(v);\n p.xy += v * deltatime / 10.0 * speedscaling;\n p.w -= deltatime;\n\n if (spawn || p.xy != fract(p.xy)) {\n p.z = 0.0;\n }\n p.xy = fract(p.xy);\n\n gl_fragcolor = p;\n}\n@end\n\n@export ecgl.vfparticle.renderpoints.vertex\n\n#define pi 3.1415926\n\nattribute vec2 texcoord : texcoord_0;\n\nuniform sampler2d particletexture;\nuniform mat4 worldviewprojection : worldviewprojection;\n\nuniform float size : 1.0;\n\nvarying float v_mag;\nvarying vec2 v_uv;\n\nvoid main()\n{\n vec4 p = texture2d(particletexture, texcoord);\n\n if (p.w > 0.0 && p.z > 1e-5) {\n gl_position = worldviewprojection * vec4(p.xy * 2.0 - 1.0, 0.0, 1.0);\n }\n else {\n gl_position = vec4(100000.0, 100000.0, 100000.0, 1.0);\n }\n\n v_mag = p.z;\n v_uv = p.xy;\n\n gl_pointsize = size;\n}\n\n@end\n\n@export ecgl.vfparticle.renderpoints.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\nuniform sampler2d gradienttexture;\nuniform sampler2d colortexture;\nuniform sampler2d spritetexture;\n\nvarying float v_mag;\nvarying vec2 v_uv;\n\nvoid main()\n{\n gl_fragcolor = color;\n#ifdef spritetexture_enabled\n gl_fragcolor *= texture2d(spritetexture, gl_pointcoord);\n if (color.a == 0.0) {\n discard;\n }\n#endif\n#ifdef gradienttexture_enabled\n gl_fragcolor *= texture2d(gradienttexture, vec2(v_mag, 0.5));\n#endif\n#ifdef colortexture_enabled\n gl_fragcolor *= texture2d(colortexture, v_uv);\n#endif\n}\n\n@end\n\n@export ecgl.vfparticle.renderlines.vertex\n\n#define pi 3.1415926\n\nattribute vec3 position : position;\n\nuniform sampler2d particletexture;\nuniform sampler2d prevparticletexture;\n\nuniform float size : 1.0;\nuniform vec4 vp: viewport;\nuniform mat4 worldviewprojection : worldviewprojection;\n\nvarying float v_mag;\nvarying vec2 v_uv;\n\n@import clay.util.rand\n\nvoid main()\n{\n vec4 p = texture2d(particletexture, position.xy);\n vec4 p2 = texture2d(prevparticletexture, position.xy);\n\n p.xy = p.xy * 2.0 - 1.0;\n p2.xy = p2.xy * 2.0 - 1.0;\n\n if (p.w > 0.0 && p.z > 1e-5) {\n vec2 dir = normalize(p.xy - p2.xy);\n vec2 norm = vec2(dir.y / vp.z, -dir.x / vp.w) * sign(position.z) * size;\n if (abs(position.z) == 2.0) {\n gl_position = vec4(p.xy + norm, 0.0, 1.0);\n v_uv = p.xy;\n v_mag = p.z;\n }\n else {\n gl_position = vec4(p2.xy + norm, 0.0, 1.0);\n v_mag = p2.z;\n v_uv = p2.xy;\n }\n gl_position = worldviewprojection * gl_position;\n }\n else {\n gl_position = vec4(100000.0, 100000.0, 100000.0, 1.0);\n }\n}\n\n@end\n\n@export ecgl.vfparticle.renderlines.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\nuniform sampler2d gradienttexture;\nuniform sampler2d colortexture;\n\nvarying float v_mag;\nvarying vec2 v_uv;\n\nvoid main()\n{\n gl_fragcolor = color;\n #ifdef gradienttexture_enabled\n gl_fragcolor *= texture2d(gradienttexture, vec2(v_mag, 0.5));\n#endif\n#ifdef colortexture_enabled\n gl_fragcolor *= texture2d(colortexture, v_uv);\n#endif\n}\n\n@end\n");var of=function(){this.motionblurfactor=.99,this.vectorfieldtexture=new dr({type:wr.float,flipy:!1}),this.particlelife=[5,20],this._particletype="point",this._particlesize=1,this.particlecolor=[1,1,1,1],this.particlespeedscaling=1,this._thisframetexture=null,this._particlepass=null,this._spawntexture=null,this._particletexture0=null,this._particletexture1=null,this._particlepointsmesh=null,this._surfaceframebuffer=null,this._elapsedtime=0,this._scene=null,this._camera=null,this._lastframetexture=null,this._supersampling=1,this._downsampletextures=[],this._width=512,this._height=512,this.init()};of.prototype={constructor:of,init:function(){var e={type:wr.float,minfilter:wr.nearest,magfilter:wr.nearest,usemipmap:!1};this._spawntexture=new dr(e),this._particletexture0=new dr(e),this._particletexture1=new dr(e),this._framebuffer=new zi({depthbuffer:!1}),this._particlepass=new pn({fragment:xe.source("ecgl.vfparticle.particle.fragment")}),this._particlepass.setuniform("velocitytexture",this.vectorfieldtexture),this._particlepass.setuniform("spawntexture",this._spawntexture),this._downsamplepass=new pn({fragment:xe.source("clay.compositor.downsample")});var t=new sr({renderorder:10,material:new le({shader:new xe(xe.source("ecgl.vfparticle.renderpoints.vertex"),xe.source("ecgl.vfparticle.renderpoints.fragment"))}),mode:sr.points,geometry:new vr({dynamic:!0,mainattribute:"texcoord0"})}),r=new sr({renderorder:10,material:new le({shader:new xe(xe.source("ecgl.vfparticle.renderlines.vertex"),xe.source("ecgl.vfparticle.renderlines.fragment"))}),geometry:new af,culling:!1}),i=new sr({material:new le({shader:new xe(xe.source("ecgl.color.vertex"),xe.source("ecgl.color.fragment"))}),geometry:new ki});i.material.enabletexture("diffusemap"),this._particlepointsmesh=t,this._particlelinesmesh=r,this._lastframefullquadmesh=i,this._camera=new un,this._thisframetexture=new dr,this._lastframetexture=new dr},setparticledensity:function(e,t){for(var r=new float32array(e*t*4),i=0,n=this.particlelife,a=0;a0?e[e.length-1]:this._lastframetexture},setregion:function(e){this._particlepass.setuniform("region",e)},resize:function(e,t){this._lastframetexture.width=e*this._supersampling,this._lastframetexture.height=t*this._supersampling,this._thisframetexture.width=e*this._supersampling,this._thisframetexture.height=t*this._supersampling,this._width=e,this._height=t},setparticlesize:function(e){var t=this._getparticlemesh();if(e<=2)return t.material.disabletexture("spritetexture"),void(t.material.transparent=!1);this._spritetexture||(this._spritetexture=new dr),this._spritetexture.image&&this._spritetexture.image.width===e||(this._spritetexture.image=function(e){var t=document.createelement("canvas");t.width=t.height=e;var r=t.getcontext("2d");return r.fillstyle="#fff",r.arc(e/2,e/2,e/2,0,2*math.pi),r.fill(),t}(e),this._spritetexture.dirty()),t.material.transparent=!0,t.material.enabletexture("spritetexture"),t.material.set("spritetexture",this._spritetexture),this._particlesize=e},setgradienttexture:function(e){var t=this._getparticlemesh().material;t[e?"enabletexture":"disabletexture"]("gradienttexture"),t.setuniform("gradienttexture",e)},setcolortextureimage:function(e,t){this._getparticlemesh().material.settextureimage("colortexture",e,t,{flipy:!0})},setparticletype:function(e){this._particletype=e},clearframe:function(e){var t=this._framebuffer;t.attach(this._lastframetexture),t.bind(e),e.gl.clear(e.gl.depth_buffer_bit|e.gl.color_buffer_bit),t.unbind(e)},setsupersampling:function(e){this._supersampling=e,this.resize(this._width,this._height)},_updatedownsampletextures:function(e,t){for(var r=this._downsampletextures,i=math.max(math.floor(math.log(this._supersampling/t.getdevicepixelratio())/math.log(2)),0),n=2,a=this._width*this._supersampling,o=this._height*this._supersampling,s=0;s=359&&(n[0]>0&&(n[0]=0),a[0]1?(t.material.shader!==this._meshlinesshader&&t.material.attachshader(this._meshlinesshader),t.mode=ka.mesh.triangles):(t.material.shader!==this._nativelinesshader&&t.material.attachshader(this._nativelinesshader),t.mode=ka.mesh.lines),r=r||0,i=i||n.count(),s.resetoffset();var u=0,c=0,d=[],f=[],p=[],m=[],g=[],_=.3,v=.7;function y(){f[0]=d[0]*v+m[0]*_-(d[1]-m[1])*a,f[1]=d[1]*v+m[1]*_-(m[0]-d[0])*a,p[0]=d[0]*_+m[0]*v-(d[1]-m[1])*a,p[1]=d[1]*_+m[1]*v-(m[0]-d[0])*a}if(o||0!==a)for(var x=r;x{t.exports=e}},r={};function i(e){if(r[e])return r[e].exports;var n=r[e]={exports:{}};return t[e](n,n.exports,i),n.exports}return i.g=function(){if("object"==typeof globalthis)return globalthis;try{return this||new function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.r=e=>{"undefined"!=typeof symbol&&symbol.tostringtag&&object.defineproperty(e,symbol.tostringtag,{value:"module"}),object.defineproperty(e,"__esmodule",{value:!0})},i(468)})()}));