hacdc-klipper/dirs/mainsail/assets/Heightmap-7418030f.js
2024-04-05 21:22:02 -04:00

2 lines
440 KiB
JavaScript

import{m as us,B as fs,C as ds,T as vs,a as ms,b as ps,c as _s,d as gs,e as ys,f as xs,g as Ts,h as Es,i as As,W as Ss,j as bs,_ as St,n as ws}from"./index-97b4652c.js";import{j as mr,m as dn,A as Cs,L as Rs,p as ua,R as fa,k as Ms,r as Ns,l as pr,n as Ls,o as Ps,q as Ds,s as Is,Z as Os,C as da,v as _t,w as Ar,x as Bs,y as Fs,M as Us,z as Oi,B as Bi,D as Hs,E as va,F as ma,G as pa,H as _a,I as zs,J as Gs,K as ks,O as Vs,N as Ws,P as Xs,Q as wr,S as vn,T as js,U as Ys,V as qs,W as Zs,X as $s,Y as Ks,_ as Qs,$ as Js,a0 as Cr,a1 as eo,u as to,a2 as ro,a3 as io}from"./echarts-9bc570b0.js";import{l as it,m as Me,f as Te,c as ht,i as nt,A as no,M as ao,E as Rr,w as kt,z as so,q as oo,F as lo,h as Mr,n as mn,o as Nr,d as Lr}from"./vuetify-52f40ce5.js";import"./overlayscrollbars-44d87bcf.js";function pn(e,t,r){typeof t=="object"&&(r=t,t=null);var i=this,n;if(!(e instanceof Function)){n=[];for(var a in e)e.hasOwnProperty(a)&&n.push(a)}var s=function(l){if(i.apply(this,arguments),e instanceof Function?_n(this,e.call(this,l)):co(this,e,n),this.constructor===s)for(var c=s.__initializers__,h=0;h<c.length;h++)c[h].apply(this,arguments)};s.__super__=i,i.__initializers__?s.__initializers__=i.__initializers__.slice():s.__initializers__=[],t&&s.__initializers__.push(t);var o=function(){};return o.prototype=i.prototype,s.prototype=new o,s.prototype.constructor=s,_n(s.prototype,r),s.extend=i.extend,s.derive=i.extend,s}function _n(e,t){if(t)for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}function co(e,t,r){for(var i=0;i<r.length;i++){var n=r[i];e[n]=t[n]}}const ho={extend:pn,derive:pn};function uo(e,t){this.action=e,this.context=t}var fo={trigger:function(e){if(this.hasOwnProperty("__handlers__")&&this.__handlers__.hasOwnProperty(e)){var t=this.__handlers__[e],r=t.length,i=-1,n=arguments;switch(n.length){case 1:for(;++i<r;)t[i].action.call(t[i].context);return;case 2:for(;++i<r;)t[i].action.call(t[i].context,n[1]);return;case 3:for(;++i<r;)t[i].action.call(t[i].context,n[1],n[2]);return;case 4:for(;++i<r;)t[i].action.call(t[i].context,n[1],n[2],n[3]);return;case 5:for(;++i<r;)t[i].action.call(t[i].context,n[1],n[2],n[3],n[4]);return;default:for(;++i<r;)t[i].action.apply(t[i].context,Array.prototype.slice.call(n,1));return}}},on:function(e,t,r){if(!(!e||!t)){var i=this.__handlers__||(this.__handlers__={});if(!i[e])i[e]=[];else if(this.has(e,t))return;var n=new uo(t,r||this);return i[e].push(n),this}},once:function(e,t,r){if(!e||!t)return;var i=this;function n(){i.off(e,n),t.apply(this,arguments)}return this.on(e,n,r)},before:function(e,t,r){if(!(!e||!t))return e="before"+e,this.on(e,t,r)},after:function(e,t,r){if(!(!e||!t))return e="after"+e,this.on(e,t,r)},success:function(e,t){return this.once("success",e,t)},error:function(e,t){return this.once("error",e,t)},off:function(e,t){var r=this.__handlers__||(this.__handlers__={});if(!t){r[e]=[];return}if(r[e]){for(var i=r[e],n=[],a=0;a<i.length;a++)t&&i[a].action!==t&&n.push(i[a]);r[e]=n}return this},has:function(e,t){var r=this.__handlers__;if(!r||!r[e])return!1;for(var i=r[e],n=0;n<i.length;n++)if(i[n].action===t)return!0}};const $i=fo;var vo=0,mo=Array.prototype,po=mo.forEach,ur={genGUID:function(){return++vo},relative2absolute:function(e,t){if(!t||e.match(/^\//))return e;for(var r=e.split("/"),i=t.split("/"),n=r[0];n==="."||n==="..";)n===".."&&i.pop(),r.shift(),n=r[0];return i.join("/")+"/"+r.join("/")},extend:function(e,t){if(t)for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e},defaults:function(e,t){if(t)for(var r in t)e[r]===void 0&&(e[r]=t[r]);return e},extendWithPropList:function(e,t,r){if(t)for(var i=0;i<r.length;i++){var n=r[i];e[n]=t[n]}return e},defaultsWithPropList:function(e,t,r){if(t)for(var i=0;i<r.length;i++){var n=r[i];e[n]==null&&(e[n]=t[n])}return e},each:function(e,t,r){if(e&&t)if(e.forEach&&e.forEach===po)e.forEach(t,r);else if(e.length===+e.length)for(var i=0,n=e.length;i<n;i++)t.call(r,e[i],i,e);else for(var a in e)e.hasOwnProperty(a)&&t.call(r,e[a],a,e)},isObject:function(e){return e===Object(e)},isArray:function(e){return Array.isArray(e)},isArrayLike:function(e){return e?e.length===+e.length:!1},clone:function(e){if(ur.isObject(e)){if(ur.isArray(e))return e.slice();if(ur.isArrayLike(e)){for(var t=new e.constructor(e.length),r=0;r<e.length;r++)t[r]=e[r];return t}else return ur.extend({},e)}else return e}};const De=ur;var ai=function(){this.__uid__=De.genGUID()};ai.__initializers__=[function(e){De.extend(this,e)}];De.extend(ai,ho);De.extend(ai.prototype,$i);const qe=ai;var gn=["OES_texture_float","OES_texture_half_float","OES_texture_float_linear","OES_texture_half_float_linear","OES_standard_derivatives","OES_vertex_array_object","OES_element_index_uint","WEBGL_compressed_texture_s3tc","WEBGL_depth_texture","EXT_texture_filter_anisotropic","EXT_shader_texture_lod","WEBGL_draw_buffers","EXT_frag_depth","EXT_sRGB","ANGLE_instanced_arrays"],yn=["MAX_TEXTURE_SIZE","MAX_CUBE_MAP_TEXTURE_SIZE"];function _o(e){for(var t={},r={},i=0;i<gn.length;i++){var n=gn[i];s(n)}for(var i=0;i<yn.length;i++){var a=yn[i];r[a]=e.getParameter(e[a])}this.getExtension=function(o){return o in t||s(o),t[o]},this.getParameter=function(o){return r[o]};function s(o){if(e.getExtension){var l=e.getExtension(o);l||(l=e.getExtension("MOZ_"+o)),l||(l=e.getExtension("WEBKIT_"+o)),t[o]=l}}}const A={DEPTH_BUFFER_BIT:256,STENCIL_BUFFER_BIT:1024,COLOR_BUFFER_BIT:16384,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,ZERO:0,ONE:1,SRC_COLOR:768,ONE_MINUS_SRC_COLOR:769,SRC_ALPHA:770,ONE_MINUS_SRC_ALPHA:771,DST_ALPHA:772,ONE_MINUS_DST_ALPHA:773,DST_COLOR:774,ONE_MINUS_DST_COLOR:775,SRC_ALPHA_SATURATE:776,FUNC_ADD:32774,BLEND_EQUATION:32777,BLEND_EQUATION_RGB:32777,BLEND_EQUATION_ALPHA:34877,FUNC_SUBTRACT:32778,FUNC_REVERSE_SUBTRACT:32779,BLEND_DST_RGB:32968,BLEND_SRC_RGB:32969,BLEND_DST_ALPHA:32970,BLEND_SRC_ALPHA:32971,CONSTANT_COLOR:32769,ONE_MINUS_CONSTANT_COLOR:32770,CONSTANT_ALPHA:32771,ONE_MINUS_CONSTANT_ALPHA:32772,BLEND_COLOR:32773,ARRAY_BUFFER:34962,ELEMENT_ARRAY_BUFFER:34963,ARRAY_BUFFER_BINDING:34964,ELEMENT_ARRAY_BUFFER_BINDING:34965,STREAM_DRAW:35040,STATIC_DRAW:35044,DYNAMIC_DRAW:35048,BUFFER_SIZE:34660,BUFFER_USAGE:34661,CURRENT_VERTEX_ATTRIB:34342,FRONT:1028,BACK:1029,FRONT_AND_BACK:1032,CULL_FACE:2884,BLEND:3042,DITHER:3024,STENCIL_TEST:2960,DEPTH_TEST:2929,SCISSOR_TEST:3089,POLYGON_OFFSET_FILL:32823,SAMPLE_ALPHA_TO_COVERAGE:32926,SAMPLE_COVERAGE:32928,NO_ERROR:0,INVALID_ENUM:1280,INVALID_VALUE:1281,INVALID_OPERATION:1282,OUT_OF_MEMORY:1285,CW:2304,CCW:2305,LINE_WIDTH:2849,ALIASED_POINT_SIZE_RANGE:33901,ALIASED_LINE_WIDTH_RANGE:33902,CULL_FACE_MODE:2885,FRONT_FACE:2886,DEPTH_RANGE:2928,DEPTH_WRITEMASK:2930,DEPTH_CLEAR_VALUE:2931,DEPTH_FUNC:2932,STENCIL_CLEAR_VALUE:2961,STENCIL_FUNC:2962,STENCIL_FAIL:2964,STENCIL_PASS_DEPTH_FAIL:2965,STENCIL_PASS_DEPTH_PASS:2966,STENCIL_REF:2967,STENCIL_VALUE_MASK:2963,STENCIL_WRITEMASK:2968,STENCIL_BACK_FUNC:34816,STENCIL_BACK_FAIL:34817,STENCIL_BACK_PASS_DEPTH_FAIL:34818,STENCIL_BACK_PASS_DEPTH_PASS:34819,STENCIL_BACK_REF:36003,STENCIL_BACK_VALUE_MASK:36004,STENCIL_BACK_WRITEMASK:36005,VIEWPORT:2978,SCISSOR_BOX:3088,COLOR_CLEAR_VALUE:3106,COLOR_WRITEMASK:3107,UNPACK_ALIGNMENT:3317,PACK_ALIGNMENT:3333,MAX_TEXTURE_SIZE:3379,MAX_VIEWPORT_DIMS:3386,SUBPIXEL_BITS:3408,RED_BITS:3410,GREEN_BITS:3411,BLUE_BITS:3412,ALPHA_BITS:3413,DEPTH_BITS:3414,STENCIL_BITS:3415,POLYGON_OFFSET_UNITS:10752,POLYGON_OFFSET_FACTOR:32824,TEXTURE_BINDING_2D:32873,SAMPLE_BUFFERS:32936,SAMPLES:32937,SAMPLE_COVERAGE_VALUE:32938,SAMPLE_COVERAGE_INVERT:32939,COMPRESSED_TEXTURE_FORMATS:34467,DONT_CARE:4352,FASTEST:4353,NICEST:4354,GENERATE_MIPMAP_HINT:33170,BYTE:5120,UNSIGNED_BYTE:5121,SHORT:5122,UNSIGNED_SHORT:5123,INT:5124,UNSIGNED_INT:5125,FLOAT:5126,DEPTH_COMPONENT:6402,ALPHA:6406,RGB:6407,RGBA:6408,LUMINANCE:6409,LUMINANCE_ALPHA:6410,UNSIGNED_SHORT_4_4_4_4:32819,UNSIGNED_SHORT_5_5_5_1:32820,UNSIGNED_SHORT_5_6_5:33635,FRAGMENT_SHADER:35632,VERTEX_SHADER:35633,MAX_VERTEX_ATTRIBS:34921,MAX_VERTEX_UNIFORM_VECTORS:36347,MAX_VARYING_VECTORS:36348,MAX_COMBINED_TEXTURE_IMAGE_UNITS:35661,MAX_VERTEX_TEXTURE_IMAGE_UNITS:35660,MAX_TEXTURE_IMAGE_UNITS:34930,MAX_FRAGMENT_UNIFORM_VECTORS:36349,SHADER_TYPE:35663,DELETE_STATUS:35712,LINK_STATUS:35714,VALIDATE_STATUS:35715,ATTACHED_SHADERS:35717,ACTIVE_UNIFORMS:35718,ACTIVE_ATTRIBUTES:35721,SHADING_LANGUAGE_VERSION:35724,CURRENT_PROGRAM:35725,NEVER:512,LESS:513,EQUAL:514,LEQUAL:515,GREATER:516,NOTEQUAL:517,GEQUAL:518,ALWAYS:519,KEEP:7680,REPLACE:7681,INCR:7682,DECR:7683,INVERT:5386,INCR_WRAP:34055,DECR_WRAP:34056,VENDOR:7936,RENDERER:7937,VERSION:7938,NEAREST:9728,LINEAR:9729,NEAREST_MIPMAP_NEAREST:9984,LINEAR_MIPMAP_NEAREST:9985,NEAREST_MIPMAP_LINEAR:9986,LINEAR_MIPMAP_LINEAR:9987,TEXTURE_MAG_FILTER:10240,TEXTURE_MIN_FILTER:10241,TEXTURE_WRAP_S:10242,TEXTURE_WRAP_T:10243,TEXTURE_2D:3553,TEXTURE:5890,TEXTURE_CUBE_MAP:34067,TEXTURE_BINDING_CUBE_MAP:34068,TEXTURE_CUBE_MAP_POSITIVE_X:34069,TEXTURE_CUBE_MAP_NEGATIVE_X:34070,TEXTURE_CUBE_MAP_POSITIVE_Y:34071,TEXTURE_CUBE_MAP_NEGATIVE_Y:34072,TEXTURE_CUBE_MAP_POSITIVE_Z:34073,TEXTURE_CUBE_MAP_NEGATIVE_Z:34074,MAX_CUBE_MAP_TEXTURE_SIZE:34076,TEXTURE0:33984,TEXTURE1:33985,TEXTURE2:33986,TEXTURE3:33987,TEXTURE4:33988,TEXTURE5:33989,TEXTURE6:33990,TEXTURE7:33991,TEXTURE8:33992,TEXTURE9:33993,TEXTURE10:33994,TEXTURE11:33995,TEXTURE12:33996,TEXTURE13:33997,TEXTURE14:33998,TEXTURE15:33999,TEXTURE16:34e3,TEXTURE17:34001,TEXTURE18:34002,TEXTURE19:34003,TEXTURE20:34004,TEXTURE21:34005,TEXTURE22:34006,TEXTURE23:34007,TEXTURE24:34008,TEXTURE25:34009,TEXTURE26:34010,TEXTURE27:34011,TEXTURE28:34012,TEXTURE29:34013,TEXTURE30:34014,TEXTURE31:34015,ACTIVE_TEXTURE:34016,REPEAT:10497,CLAMP_TO_EDGE:33071,MIRRORED_REPEAT:33648,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,INT_VEC2:35667,INT_VEC3:35668,INT_VEC4:35669,BOOL:35670,BOOL_VEC2:35671,BOOL_VEC3:35672,BOOL_VEC4:35673,FLOAT_MAT2:35674,FLOAT_MAT3:35675,FLOAT_MAT4:35676,SAMPLER_2D:35678,SAMPLER_CUBE:35680,VERTEX_ATTRIB_ARRAY_ENABLED:34338,VERTEX_ATTRIB_ARRAY_SIZE:34339,VERTEX_ATTRIB_ARRAY_STRIDE:34340,VERTEX_ATTRIB_ARRAY_TYPE:34341,VERTEX_ATTRIB_ARRAY_NORMALIZED:34922,VERTEX_ATTRIB_ARRAY_POINTER:34373,VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:34975,COMPILE_STATUS:35713,LOW_FLOAT:36336,MEDIUM_FLOAT:36337,HIGH_FLOAT:36338,LOW_INT:36339,MEDIUM_INT:36340,HIGH_INT:36341,FRAMEBUFFER:36160,RENDERBUFFER:36161,RGBA4:32854,RGB5_A1:32855,RGB565:36194,DEPTH_COMPONENT16:33189,STENCIL_INDEX:6401,STENCIL_INDEX8:36168,DEPTH_STENCIL:34041,RENDERBUFFER_WIDTH:36162,RENDERBUFFER_HEIGHT:36163,RENDERBUFFER_INTERNAL_FORMAT:36164,RENDERBUFFER_RED_SIZE:36176,RENDERBUFFER_GREEN_SIZE:36177,RENDERBUFFER_BLUE_SIZE:36178,RENDERBUFFER_ALPHA_SIZE:36179,RENDERBUFFER_DEPTH_SIZE:36180,RENDERBUFFER_STENCIL_SIZE:36181,FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:36048,FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:36049,FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:36050,FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:36051,COLOR_ATTACHMENT0:36064,DEPTH_ATTACHMENT:36096,STENCIL_ATTACHMENT:36128,DEPTH_STENCIL_ATTACHMENT:33306,NONE:0,FRAMEBUFFER_COMPLETE:36053,FRAMEBUFFER_INCOMPLETE_ATTACHMENT:36054,FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:36055,FRAMEBUFFER_INCOMPLETE_DIMENSIONS:36057,FRAMEBUFFER_UNSUPPORTED:36061,FRAMEBUFFER_BINDING:36006,RENDERBUFFER_BINDING:36007,MAX_RENDERBUFFER_SIZE:34024,INVALID_FRAMEBUFFER_OPERATION:1286,UNPACK_FLIP_Y_WEBGL:37440,UNPACK_PREMULTIPLY_ALPHA_WEBGL:37441,CONTEXT_LOST_WEBGL:37442,UNPACK_COLORSPACE_CONVERSION_WEBGL:37443,BROWSER_DEFAULT_WEBGL:37444};function go(e){var t=new XMLHttpRequest;t.open("get",e.url),t.responseType=e.responseType||"text",e.onprogress&&(t.onprogress=function(r){if(r.lengthComputable){var i=r.loaded/r.total;e.onprogress(i,r.loaded,r.total)}else e.onprogress(null)}),t.onload=function(r){t.status>=400?e.onerror&&e.onerror():e.onload&&e.onload(t.response)},e.onerror&&(t.onerror=e.onerror),t.send(null)}const yo={get:go};var fi,Xe={};Xe.supportWebGL=function(){if(fi==null)try{var e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");if(!t)throw new Error}catch{fi=!1}return fi};Xe.Int8Array=typeof Int8Array>"u"?Array:Int8Array;Xe.Uint8Array=typeof Uint8Array>"u"?Array:Uint8Array;Xe.Uint16Array=typeof Uint16Array>"u"?Array:Uint16Array;Xe.Uint32Array=typeof Uint32Array>"u"?Array:Uint32Array;Xe.Int16Array=typeof Int16Array>"u"?Array:Int16Array;Xe.Float32Array=typeof Float32Array>"u"?Array:Float32Array;Xe.Float64Array=typeof Float64Array>"u"?Array:Float64Array;var Ot={};typeof window<"u"?Ot=window:typeof global<"u"&&(Ot=global);Xe.requestAnimationFrame=Ot.requestAnimationFrame||Ot.msRequestAnimationFrame||Ot.mozRequestAnimationFrame||Ot.webkitRequestAnimationFrame||function(e){setTimeout(e,16)};Xe.createCanvas=function(){return document.createElement("canvas")};Xe.createImage=function(){return new Ot.Image};Xe.request={get:yo.get};Xe.addEventListener=function(e,t,r,i){e.addEventListener(t,r,i)};Xe.removeEventListener=function(e,t,r){e.removeEventListener(t,r)};const be=Xe;var Le=function(){this.head=null,this.tail=null,this._length=0};Le.prototype.insert=function(e){var t=new Le.Entry(e);return this.insertEntry(t),t};Le.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 Le.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)}};Le.prototype.insertBeforeEntry=function(e,t){var r=new Le.Entry(e),i=t.prev;i?(i.next=r,r.prev=i):this.head=r,r.next=t,t.prev=r,this._length++};Le.prototype.insertEntry=function(e){this.head?(this.tail.next=e,e.prev=this.tail,this.tail=e):this.head=this.tail=e,this._length++};Le.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--};Le.prototype.removeAt=function(e){if(!(e<0)){for(var t=this.head,r=0;t&&r!=e;)t=t.next,r++;if(t)return this.remove(t),t.value}};Le.prototype.getHead=function(){if(this.head)return this.head.value};Le.prototype.getTail=function(){if(this.tail)return this.tail.value};Le.prototype.getAt=function(e){if(!(e<0)){for(var t=this.head,r=0;t&&r!=e;)t=t.next,r++;return t.value}};Le.prototype.indexOf=function(e){for(var t=this.head,r=0;t;){if(t.value===e)return r;t=t.next,r++}};Le.prototype.length=function(){return this._length};Le.prototype.isEmpty=function(){return this._length===0};Le.prototype.forEach=function(e,t){for(var r=this.head,i=0,n=typeof t<"u";r;)n?e.call(t,r.value,i):e(r.value,i),r=r.next,i++};Le.prototype.clear=function(){this.tail=this.head=null,this._length=0};Le.Entry=function(e){this.value=e,this.next=null,this.prev=null};const xo=Le;var ir=function(e){this._list=new xo,this._map={},this._maxSize=e||10};ir.prototype.setMaxSize=function(e){this._maxSize=e};ir.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}};ir.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};ir.prototype.remove=function(e){var t=this._map[e];typeof t<"u"&&(delete this._map[e],this._list.remove(t))};ir.prototype.clear=function(){this._list.clear(),this._map={}};const ga=ir;var pe={},xn={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 ot(e){return e=Math.round(e),e<0?0:e>255?255:e}function To(e){return e=Math.round(e),e<0?0:e>360?360:e}function _r(e){return e<0?0:e>1?1:e}function di(e){return e.length&&e.charAt(e.length-1)==="%"?ot(parseFloat(e)/100*255):ot(parseInt(e,10))}function Jt(e){return e.length&&e.charAt(e.length-1)==="%"?_r(parseFloat(e)/100):_r(parseFloat(e))}function vi(e,t,r){return r<0?r+=1:r>1&&(r-=1),r*6<1?e+(t-e)*r*6:r*2<1?t:r*3<2?e+(t-e)*(2/3-r)*6:e}function bt(e,t,r){return e+(t-e)*r}function st(e,t,r,i,n){return e[0]=t,e[1]=r,e[2]=i,e[3]=n,e}function Fi(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}var ya=new ga(20),Pr=null;function Vt(e,t){Pr&&Fi(Pr,t),Pr=ya.put(e,Pr||t.slice())}pe.parse=function(e,t){if(e){t=t||[];var r=ya.get(e);if(r)return Fi(t,r);e=e+"";var i=e.replace(/ /g,"").toLowerCase();if(i in xn)return Fi(t,xn[i]),Vt(e,t),t;if(i.charAt(0)==="#"){if(i.length===4){var n=parseInt(i.substr(1),16);if(!(n>=0&&n<=4095)){st(t,0,0,0,1);return}return st(t,(n&3840)>>4|(n&3840)>>8,n&240|(n&240)>>4,n&15|(n&15)<<4,1),Vt(e,t),t}else if(i.length===7){var n=parseInt(i.substr(1),16);if(!(n>=0&&n<=16777215)){st(t,0,0,0,1);return}return st(t,(n&16711680)>>16,(n&65280)>>8,n&255,1),Vt(e,t),t}return}var a=i.indexOf("("),s=i.indexOf(")");if(a!==-1&&s+1===i.length){var o=i.substr(0,a),l=i.substr(a+1,s-(a+1)).split(","),c=1;switch(o){case"rgba":if(l.length!==4){st(t,0,0,0,1);return}c=Jt(l.pop());case"rgb":if(l.length!==3){st(t,0,0,0,1);return}return st(t,di(l[0]),di(l[1]),di(l[2]),c),Vt(e,t),t;case"hsla":if(l.length!==4){st(t,0,0,0,1);return}return l[3]=Jt(l[3]),Ui(l,t),Vt(e,t),t;case"hsl":if(l.length!==3){st(t,0,0,0,1);return}return Ui(l,t),Vt(e,t),t;default:return}}st(t,0,0,0,1)}};pe.parseToFloat=function(e,t){if(t=pe.parse(e,t),!!t)return t[0]/=255,t[1]/=255,t[2]/=255,t};function Ui(e,t){var r=(parseFloat(e[0])%360+360)%360/360,i=Jt(e[1]),n=Jt(e[2]),a=n<=.5?n*(i+1):n+i-n*i,s=n*2-a;return t=t||[],st(t,ot(vi(s,a,r+1/3)*255),ot(vi(s,a,r)*255),ot(vi(s,a,r-1/3)*255),1),e.length===4&&(t[3]=e[3]),t}function Eo(e){if(e){var t=e[0]/255,r=e[1]/255,i=e[2]/255,n=Math.min(t,r,i),a=Math.max(t,r,i),s=a-n,o=(a+n)/2,l,c;if(s===0)l=0,c=0;else{o<.5?c=s/(a+n):c=s/(2-a-n);var h=((a-t)/6+s/2)/s,u=((a-r)/6+s/2)/s,d=((a-i)/6+s/2)/s;t===a?l=d-u:r===a?l=1/3+h-d:i===a&&(l=2/3+u-h),l<0&&(l+=1),l>1&&(l-=1)}var f=[l*360,c,o];return e[3]!=null&&f.push(e[3]),f}}pe.lift=function(e,t){var r=pe.parse(e);if(r){for(var i=0;i<3;i++)t<0?r[i]=r[i]*(1-t)|0:r[i]=(255-r[i])*t+r[i]|0;return pe.stringify(r,r.length===4?"rgba":"rgb")}};pe.toHex=function(e){var t=pe.parse(e);if(t)return((1<<24)+(t[0]<<16)+(t[1]<<8)+ +t[2]).toString(16).slice(1)};pe.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),s=t[n],o=t[a],l=i-n;return r[0]=ot(bt(s[0],o[0],l)),r[1]=ot(bt(s[1],o[1],l)),r[2]=ot(bt(s[2],o[2],l)),r[3]=_r(bt(s[3],o[3],l)),r}};pe.fastMapToColor=pe.fastLerp;pe.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),s=pe.parse(t[n]),o=pe.parse(t[a]),l=i-n,c=pe.stringify([ot(bt(s[0],o[0],l)),ot(bt(s[1],o[1],l)),ot(bt(s[2],o[2],l)),_r(bt(s[3],o[3],l))],"rgba");return r?{color:c,leftIndex:n,rightIndex:a,value:i}:c}};pe.mapToColor=pe.lerp;pe.modifyHSL=function(e,t,r,i){if(e=pe.parse(e),e)return e=Eo(e),t!=null&&(e[0]=To(t)),r!=null&&(e[1]=Jt(r)),i!=null&&(e[2]=Jt(i)),pe.stringify(Ui(e),"rgba")};pe.modifyAlpha=function(e,t){if(e=pe.parse(e),e&&t!=null)return e[3]=_r(t),pe.stringify(e,"rgba")};pe.stringify=function(e,t){if(!(!e||!e.length)){var r=e[0]+","+e[1]+","+e[2];return(t==="rgba"||t==="hsva"||t==="hsla")&&(r+=","+e[3]),t+"("+r+")"}};const Ao=pe;var So=Ao.parseToFloat,mi={};function Tn(e){var t=Object.keys(e);t.sort();for(var r=[],i=0;i<t.length;i++){var n=t[i],a=e[n];a===null?r.push(n):r.push(n+" "+a.toString())}return r.join("\n")}function bo(e,t,r){r.sort();for(var i=[],n=0;n<r.length;n++){var a=r[n];i.push(a)}var s=Tn(e)+"\n"+Tn(t)+"\n"+i.join("\n");if(mi[s])return mi[s];var o=De.genGUID();return mi[s]=o,o}var wo=qe.extend(function(){return{name:"",depthTest:!0,depthMask:!0,transparent:!1,blend:null,autoUpdateTextureStatus:!0,uniforms:{},vertexDefines:{},fragmentDefines:{},_textureStatus:{},_enabledUniforms:null}},function(){this.name||(this.name="MATERIAL_"+this.__uid__),this.shader&&this.attachShader(this.shader,!0)},{precision:"highp",setUniform:function(e,t){t===void 0&&console.warn('Uniform value "'+e+'" is undefined');var r=this.uniforms[e];r&&(typeof t=="string"&&(t=So(t)||t),r.value=t,this.autoUpdateTextureStatus&&r.type==="t"&&(t?this.enableTexture(e):this.disableTexture(e)))},setUniforms:function(e){for(var t in e){var r=e[t];this.setUniform(t,r)}},isUniformEnabled:function(e){return this._enabledUniforms.indexOf(e)>=0},getEnabledUniforms:function(){return this._enabledUniforms},getTextureUniforms:function(){return this._textureUniforms},set:function(e,t){if(typeof e=="object")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(c){var h=this.uniforms[c].type;return h==="t"||h==="tv"},this);var n=this.vertexDefines,a=this.fragmentDefines;if(this.vertexDefines=De.clone(e.vertexDefines),this.fragmentDefines=De.clone(e.fragmentDefines),t){for(var s in r)i[s]&&(i[s].value=r[s].value);De.defaults(this.vertexDefines,n),De.defaults(this.fragmentDefines,a)}var o={};for(var l in e.textures)o[l]={shaderType:e.textures[l].shaderType,type:e.textures[l].type,enabled:t&&this._textureStatus[l]?this._textureStatus[l].enabled:!1};this._textureStatus=o,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=De.clone(this.vertexDefines),e.fragmentDefines=De.clone(this.fragmentDefines),e.enableTexture(this.getEnabledTextures()),e.precision=this.precision,e},define:function(e,t,r){var i=this.vertexDefines,n=this.fragmentDefines;e!=="vertex"&&e!=="fragment"&&e!=="both"&&arguments.length<3&&(r=t,t=e,e="both"),r=r!=null?r:null,(e==="vertex"||e==="both")&&i[t]!==r&&(i[t]=r,this._programKey=""),(e==="fragment"||e==="both")&&n[t]!==r&&(n[t]=r,e!=="both"&&(this._programKey=""))},undefine:function(e,t){e!=="vertex"&&e!=="fragment"&&e!=="both"&&arguments.length<2&&(t=e,e="both"),(e==="vertex"||e==="both")&&this.isDefined("vertex",t)&&(delete this.vertexDefines[t],this._programKey=""),(e==="fragment"||e==="both")&&this.isDefined("fragment",t)&&(delete this.fragmentDefines[t],e!=="both"&&(this._programKey=""))},isDefined:function(e,t){switch(e){case"vertex":return this.vertexDefines[t]!==void 0;case"fragment":return this.fragmentDefines[t]!==void 0}},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;t<e.length;t++)this.enableTexture(e[t]);return}var r=this._textureStatus[e];if(r){var i=r.enabled;i||(r.enabled=!0,this._programKey="")}},enableTexturesAll:function(){var e=this._textureStatus;for(var t in e)e[t].enabled=!0;this._programKey=""},disableTexture:function(e){if(Array.isArray(e)){for(var t=0;t<e.length;t++)this.disableTexture(e[t]);return}var r=this._textureStatus[e];if(r){var i=!r.enabled;i||(r.enabled=!1,this._programKey="")}},disableTexturesAll:function(){var e=this._textureStatus;for(var t in e)e[t].enabled=!1;this._programKey=""},isTextureEnabled:function(e){var t=this._textureStatus;return!!t[e]&&t[e].enabled},getEnabledTextures:function(){var e=[],t=this._textureStatus;for(var r in t)t[r].enabled&&e.push(r);return e},dirtyDefines:function(){this._programKey=""},getProgramKey:function(){return this._programKey||(this._programKey=bo(this.vertexDefines,this.fragmentDefines,this.getEnabledTextures())),this._programKey}});const yt=wo;var Vr=1e-6,Ie=Array,Kt=Math.random,$={};$.create=function(){var e=new Ie(2);return e[0]=0,e[1]=0,e};$.clone=function(e){var t=new Ie(2);return t[0]=e[0],t[1]=e[1],t};$.fromValues=function(e,t){var r=new Ie(2);return r[0]=e,r[1]=t,r};$.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e};$.set=function(e,t,r){return e[0]=t,e[1]=r,e};$.add=function(e,t,r){return e[0]=t[0]+r[0],e[1]=t[1]+r[1],e};$.subtract=function(e,t,r){return e[0]=t[0]-r[0],e[1]=t[1]-r[1],e};$.sub=$.subtract;$.multiply=function(e,t,r){return e[0]=t[0]*r[0],e[1]=t[1]*r[1],e};$.mul=$.multiply;$.divide=function(e,t,r){return e[0]=t[0]/r[0],e[1]=t[1]/r[1],e};$.div=$.divide;$.min=function(e,t,r){return e[0]=Math.min(t[0],r[0]),e[1]=Math.min(t[1],r[1]),e};$.max=function(e,t,r){return e[0]=Math.max(t[0],r[0]),e[1]=Math.max(t[1],r[1]),e};$.scale=function(e,t,r){return e[0]=t[0]*r,e[1]=t[1]*r,e};$.scaleAndAdd=function(e,t,r,i){return e[0]=t[0]+r[0]*i,e[1]=t[1]+r[1]*i,e};$.distance=function(e,t){var r=t[0]-e[0],i=t[1]-e[1];return Math.sqrt(r*r+i*i)};$.dist=$.distance;$.squaredDistance=function(e,t){var r=t[0]-e[0],i=t[1]-e[1];return r*r+i*i};$.sqrDist=$.squaredDistance;$.length=function(e){var t=e[0],r=e[1];return Math.sqrt(t*t+r*r)};$.len=$.length;$.squaredLength=function(e){var t=e[0],r=e[1];return t*t+r*r};$.sqrLen=$.squaredLength;$.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e};$.inverse=function(e,t){return e[0]=1/t[0],e[1]=1/t[1],e};$.normalize=function(e,t){var r=t[0],i=t[1],n=r*r+i*i;return n>0&&(n=1/Math.sqrt(n),e[0]=t[0]*n,e[1]=t[1]*n),e};$.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]};$.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};$.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};$.random=function(e,t){t=t||1;var r=GLMAT_RANDOM()*2*Math.PI;return e[0]=Math.cos(r)*t,e[1]=Math.sin(r)*t,e};$.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};$.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};$.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};$.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};$.forEach=function(){var e=$.create();return function(t,r,i,n,a,s){var o,l;for(r||(r=2),i||(i=0),n?l=Math.min(n*r+i,t.length):l=t.length,o=i;o<l;o+=r)e[0]=t[o],e[1]=t[o+1],a(e,e,s),t[o]=e[0],t[o+1]=e[1];return t}}();const H=$;var Q=function(e,t){e=e||0,t=t||0,this.array=H.fromValues(e,t),this._dirty=!0};Q.prototype={constructor:Q,add:function(e){return H.add(this.array,this.array,e.array),this._dirty=!0,this},set:function(e,t){return this.array[0]=e,this.array[1]=t,this._dirty=!0,this},setArray:function(e){return this.array[0]=e[0],this.array[1]=e[1],this._dirty=!0,this},clone:function(){return new Q(this.x,this.y)},copy:function(e){return H.copy(this.array,e.array),this._dirty=!0,this},cross:function(e,t){return H.cross(e.array,this.array,t.array),e._dirty=!0,this},dist:function(e){return H.dist(this.array,e.array)},distance:function(e){return H.distance(this.array,e.array)},div:function(e){return H.div(this.array,this.array,e.array),this._dirty=!0,this},divide:function(e){return H.divide(this.array,this.array,e.array),this._dirty=!0,this},dot:function(e){return H.dot(this.array,e.array)},len:function(){return H.len(this.array)},length:function(){return H.length(this.array)},lerp:function(e,t,r){return H.lerp(this.array,e.array,t.array,r),this._dirty=!0,this},min:function(e){return H.min(this.array,this.array,e.array),this._dirty=!0,this},max:function(e){return H.max(this.array,this.array,e.array),this._dirty=!0,this},mul:function(e){return H.mul(this.array,this.array,e.array),this._dirty=!0,this},multiply:function(e){return H.multiply(this.array,this.array,e.array),this._dirty=!0,this},negate:function(){return H.negate(this.array,this.array),this._dirty=!0,this},normalize:function(){return H.normalize(this.array,this.array),this._dirty=!0,this},random:function(e){return H.random(this.array,e),this._dirty=!0,this},scale:function(e){return H.scale(this.array,this.array,e),this._dirty=!0,this},scaleAndAdd:function(e,t){return H.scaleAndAdd(this.array,this.array,e.array,t),this._dirty=!0,this},sqrDist:function(e){return H.sqrDist(this.array,e.array)},squaredDistance:function(e){return H.squaredDistance(this.array,e.array)},sqrLen:function(){return H.sqrLen(this.array)},squaredLength:function(){return H.squaredLength(this.array)},sub:function(e){return H.sub(this.array,this.array,e.array),this._dirty=!0,this},subtract:function(e){return H.subtract(this.array,this.array,e.array),this._dirty=!0,this},transformMat2:function(e){return H.transformMat2(this.array,this.array,e.array),this._dirty=!0,this},transformMat2d:function(e){return H.transformMat2d(this.array,this.array,e.array),this._dirty=!0,this},transformMat3:function(e){return H.transformMat3(this.array,this.array,e.array),this._dirty=!0,this},transformMat4:function(e){return H.transformMat4(this.array,this.array,e.array),this._dirty=!0,this},toString:function(){return"["+Array.prototype.join.call(this.array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this.array)}};if(Object.defineProperty){var En=Q.prototype;Object.defineProperty(En,"x",{get:function(){return this.array[0]},set:function(e){this.array[0]=e,this._dirty=!0}}),Object.defineProperty(En,"y",{get:function(){return this.array[1]},set:function(e){this.array[1]=e,this._dirty=!0}})}Q.add=function(e,t,r){return H.add(e.array,t.array,r.array),e._dirty=!0,e};Q.set=function(e,t,r){return H.set(e.array,t,r),e._dirty=!0,e};Q.copy=function(e,t){return H.copy(e.array,t.array),e._dirty=!0,e};Q.cross=function(e,t,r){return H.cross(e.array,t.array,r.array),e._dirty=!0,e};Q.dist=function(e,t){return H.distance(e.array,t.array)};Q.distance=Q.dist;Q.div=function(e,t,r){return H.divide(e.array,t.array,r.array),e._dirty=!0,e};Q.divide=Q.div;Q.dot=function(e,t){return H.dot(e.array,t.array)};Q.len=function(e){return H.length(e.array)};Q.lerp=function(e,t,r,i){return H.lerp(e.array,t.array,r.array,i),e._dirty=!0,e};Q.min=function(e,t,r){return H.min(e.array,t.array,r.array),e._dirty=!0,e};Q.max=function(e,t,r){return H.max(e.array,t.array,r.array),e._dirty=!0,e};Q.mul=function(e,t,r){return H.multiply(e.array,t.array,r.array),e._dirty=!0,e};Q.multiply=Q.mul;Q.negate=function(e,t){return H.negate(e.array,t.array),e._dirty=!0,e};Q.normalize=function(e,t){return H.normalize(e.array,t.array),e._dirty=!0,e};Q.random=function(e,t){return H.random(e.array,t),e._dirty=!0,e};Q.scale=function(e,t,r){return H.scale(e.array,t.array,r),e._dirty=!0,e};Q.scaleAndAdd=function(e,t,r,i){return H.scaleAndAdd(e.array,t.array,r.array,i),e._dirty=!0,e};Q.sqrDist=function(e,t){return H.sqrDist(e.array,t.array)};Q.squaredDistance=Q.sqrDist;Q.sqrLen=function(e){return H.sqrLen(e.array)};Q.squaredLength=Q.sqrLen;Q.sub=function(e,t,r){return H.subtract(e.array,t.array,r.array),e._dirty=!0,e};Q.subtract=Q.sub;Q.transformMat2=function(e,t,r){return H.transformMat2(e.array,t.array,r.array),e._dirty=!0,e};Q.transformMat2d=function(e,t,r){return H.transformMat2d(e.array,t.array,r.array),e._dirty=!0,e};Q.transformMat3=function(e,t,r){return H.transformMat3(e.array,t.array,r.array),e._dirty=!0,e};Q.transformMat4=function(e,t,r){return H.transformMat4(e.array,t.array,r.array),e._dirty=!0,e};const $e=Q;var An=1,Sn=2,pi=3,bn={};function Co(e){for(var t=e.split("\n"),r=0,i=t.length;r<i;r++)t[r]=r+1+": "+t[r];return t.join("\n")}function wn(e,t,r){if(!e.getShaderParameter(t,e.COMPILE_STATUS))return[e.getShaderInfoLog(t),Co(r)].join("\n")}var Cn=new be.Float32Array(16),Ro=qe.extend({uniformSemantics:{},attributes:{}},function(){this._locations={},this._textureSlot=0,this._program=null},{bind:function(e){this._textureSlot=0,e.gl.useProgram(this._program)},hasUniform:function(e){var t=this._locations[e];return t!=null},useTextureSlot:function(e,t,r){t&&(e.gl.activeTexture(e.gl.TEXTURE0+r),t.isRenderable()?t.bind(e):t.unbind(e))},currentTextureSlot:function(){return this._textureSlot},resetTextureSlot:function(e){this._textureSlot=e||0},takeCurrentTextureSlot:function(e,t){var r=this._textureSlot;return this.useTextureSlot(e,t,r),this._textureSlot++,r},setUniform:function(e,t,r,i){var n=this._locations,a=n[r];if(a==null)return!1;switch(t){case"m4":if(!(i instanceof Float32Array)){for(var s=0;s<i.length;s++)Cn[s]=i[s];i=Cn}e.uniformMatrix4fv(a,!1,i);break;case"2i":e.uniform2i(a,i[0],i[1]);break;case"2f":e.uniform2f(a,i[0],i[1]);break;case"3i":e.uniform3i(a,i[0],i[1],i[2]);break;case"3f":e.uniform3f(a,i[0],i[1],i[2]);break;case"4i":e.uniform4i(a,i[0],i[1],i[2],i[3]);break;case"4f":e.uniform4f(a,i[0],i[1],i[2],i[3]);break;case"1i":e.uniform1i(a,i);break;case"1f":e.uniform1f(a,i);break;case"1fv":e.uniform1fv(a,i);break;case"1iv":e.uniform1iv(a,i);break;case"2iv":e.uniform2iv(a,i);break;case"2fv":e.uniform2fv(a,i);break;case"3iv":e.uniform3iv(a,i);break;case"3fv":e.uniform3fv(a,i);break;case"4iv":e.uniform4iv(a,i);break;case"4fv":e.uniform4fv(a,i);break;case"m2":case"m2v":e.uniformMatrix2fv(a,!1,i);break;case"m3":case"m3v":e.uniformMatrix3fv(a,!1,i);break;case"m4v":if(Array.isArray(i)&&Array.isArray(i[0])){for(var o=new be.Float32Array(i.length*16),l=0,s=0;s<i.length;s++)for(var c=i[s],h=0;h<16;h++)o[l++]=c[h];e.uniformMatrix4fv(a,!1,o)}else e.uniformMatrix4fv(a,!1,i);break}return!0},setUniformOfSemantic:function(e,t,r){var i=this.uniformSemantics[t];return i?this.setUniform(e,i.type,i.symbol,r):!1},enableAttributes:function(e,t,r){var i=e.gl,n=this._program,a=this._locations,s;r?s=r.__enabledAttributeList:s=bn[e.__uid__],s||(r?s=r.__enabledAttributeList=[]:s=bn[e.__uid__]=[]);for(var o=[],l=0;l<t.length;l++){var c=t[l];if(!this.attributes[c]){o[l]=-1;continue}var h=a[c];if(h==null){if(h=i.getAttribLocation(n,c),h===-1){o[l]=-1;continue}a[c]=h}o[l]=h,s[h]?s[h]=Sn:s[h]=An}for(var l=0;l<s.length;l++)switch(s[l]){case An:i.enableVertexAttribArray(l),s[l]=pi;break;case Sn:s[l]=pi;break;case pi:i.disableVertexAttribArray(l),s[l]=0;break}return o},getAttribLocation:function(e,t){var r=this._locations,i=r[t];return i==null&&(i=e.getAttribLocation(this._program,t),r[t]=i),i},buildProgram:function(e,t,r,i){var n=e.createShader(e.VERTEX_SHADER),a=e.createProgram();e.shaderSource(n,r),e.compileShader(n);var s=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(s,i),e.compileShader(s);var o=wn(e,n,r);if(o||(o=wn(e,s,i),o))return o;if(e.attachShader(a,n),e.attachShader(a,s),t.attributeSemantics.POSITION)e.bindAttribLocation(a,0,t.attributeSemantics.POSITION.symbol);else{var l=Object.keys(this.attributes);e.bindAttribLocation(a,0,l[0])}if(e.linkProgram(a),e.deleteShader(n),e.deleteShader(s),this._program=a,this.vertexCode=r,this.fragmentCode=i,!e.getProgramParameter(a,e.LINK_STATUS))return"Could not link program\n"+e.getProgramInfoLog(a);for(var c=0;c<t.uniforms.length;c++){var h=t.uniforms[c];this._locations[h]=e.getUniformLocation(a,h)}}});const Mo=Ro;var No=/for\s*?\(int\s*?_idx_\s*\=\s*([\w-]+)\;\s*_idx_\s*<\s*([\w-]+);\s*_idx_\s*\+\+\s*\)\s*\{\{([\s\S]+?)(?=\}\})\}\}/g;function Rn(e,t,r){function i(s,o,l,c){var h="";isNaN(o)&&(o in t?o=t[o]:o=n[o]),isNaN(l)&&(l in t?l=t[l]:l=n[l]);for(var u=parseInt(o);u<parseInt(l);u++)h+="{"+c.replace(/float\s*\(\s*_idx_\s*\)/g,u.toFixed(1)).replace(/_idx_/g,u)+"}";return h}var n={};for(var a in r)n[a+"_COUNT"]=r[a];return e.replace(No,i)}function _i(e,t,r){var i=[];if(t)for(var n in t){var a=t[n];a>0&&i.push("#define "+n.toUpperCase()+"_COUNT "+a)}if(r)for(var s=0;s<r.length;s++){var o=r[s];i.push("#define "+o.toUpperCase()+"_ENABLED")}for(var o in e){var l=e[o];l===null?i.push("#define "+o):i.push("#define "+o+" "+l.toString())}return i.join("\n")}function Lo(e){for(var t=[],r=0;r<e.length;r++)t.push("#extension GL_"+e[r]+" : enable");return t.join("\n")}function Po(e){return["precision",e,"float"].join(" ")+";\n"+["precision",e,"int"].join(" ")+";\n"+["precision",e,"sampler2D"].join(" ")+";\n"}function xa(e){this._renderer=e,this._cache={}}xa.prototype.getProgram=function(e,t,r){var i=this._cache,n=e.isSkinnedMesh&&e.isSkinnedMesh(),a=e.isInstancedMesh&&e.isInstancedMesh(),s="s"+t.shader.shaderID+"m"+t.getProgramKey();r&&(s+="se"+r.getProgramKey(e.lightGroup)),n&&(s+=",sk"+e.joints.length),a&&(s+=",is");var g=i[s];if(g)return g;var o=r?r.getLightsNumbers(e.lightGroup):{},l=this._renderer,c=l.gl,h=t.getEnabledTextures(),u="";if(n){var d={SKINNING:null,JOINT_COUNT:e.joints.length};e.joints.length>l.getMaxJointNumber()&&(d.USE_SKIN_MATRICES_TEXTURE=null),u+="\n"+_i(d)+"\n"}a&&(u+="\n#define INSTANCING\n");var f=u+_i(t.vertexDefines,o,h),v=u+_i(t.fragmentDefines,o,h),m=f+"\n"+t.shader.vertex,p=["OES_standard_derivatives","EXT_shader_texture_lod"].filter(function(S){return l.getGLExtension(S)!=null});p.indexOf("EXT_shader_texture_lod")>=0&&(v+="\n#define SUPPORT_TEXTURE_LOD"),p.indexOf("OES_standard_derivatives")>=0&&(v+="\n#define SUPPORT_STANDARD_DERIVATIVES");var _=Lo(p)+"\n"+Po(t.precision)+"\n"+v+"\n"+t.shader.fragment,T=Rn(m,t.vertexDefines,o),y=Rn(_,t.fragmentDefines,o),g=new Mo;g.uniformSemantics=t.shader.uniformSemantics,g.attributes=t.shader.attributes;var E=g.buildProgram(c,t.shader,T,y);return g.__error=E,i[s]=g,g};var Mn=/uniform\s+(bool|float|int|vec2|vec3|vec4|ivec2|ivec3|ivec4|mat2|mat3|mat4|sampler2D|samplerCube)\s+([\s\S]*?);/g,Do=/attribute\s+(float|int|vec2|vec3|vec4)\s+([\s\S]*?);/g,Nn=/#define\s+(\w+)?(\s+[\d-.]+)?\s*;?\s*\n/g,Io={bool:"1i",int:"1i",sampler2D:"t",samplerCube:"t",float:"1f",vec2:"2f",vec3:"3f",vec4:"4f",ivec2:"2i",ivec3:"3i",ivec4:"4i",mat2:"m2",mat3:"m3",mat4:"m4"};function mt(e){for(var t=[],r=0;r<e;r++)t[r]=0;return t}var Ln={bool:function(){return!0},int:function(){return 0},float:function(){return 0},sampler2D:function(){return null},samplerCube:function(){return null},vec2:function(){return mt(2)},vec3:function(){return mt(3)},vec4:function(){return mt(4)},ivec2:function(){return mt(2)},ivec3:function(){return mt(3)},ivec4:function(){return mt(4)},mat2:function(){return mt(4)},mat3:function(){return mt(9)},mat4:function(){return mt(16)},array:function(){return[]}},Hi=["POSITION","NORMAL","BINORMAL","TANGENT","TEXCOORD","TEXCOORD_0","TEXCOORD_1","COLOR","JOINT","WEIGHT"],Ta=["SKIN_MATRIX","VIEWPORT_SIZE","VIEWPORT","DEVICEPIXELRATIO","WINDOW_SIZE","NEAR","FAR","TIME"],Ea=["WORLD","VIEW","PROJECTION","WORLDVIEW","VIEWPROJECTION","WORLDVIEWPROJECTION","WORLDINVERSE","VIEWINVERSE","PROJECTIONINVERSE","WORLDVIEWINVERSE","VIEWPROJECTIONINVERSE","WORLDVIEWPROJECTIONINVERSE","WORLDTRANSPOSE","VIEWTRANSPOSE","PROJECTIONTRANSPOSE","WORLDVIEWTRANSPOSE","VIEWPROJECTIONTRANSPOSE","WORLDVIEWPROJECTIONTRANSPOSE","WORLDINVERSETRANSPOSE","VIEWINVERSETRANSPOSE","PROJECTIONINVERSETRANSPOSE","WORLDVIEWINVERSETRANSPOSE","VIEWPROJECTIONINVERSETRANSPOSE","WORLDVIEWPROJECTIONINVERSETRANSPOSE"],Oo={vec4:4,vec3:3,vec2:2,float:1},gi={},Aa={};function Bo(e,t){var r="vertex:"+e+"fragment:"+t;if(gi[r])return gi[r];var i=De.genGUID();return gi[r]=i,Aa[i]={vertex:e,fragment:t},i}function Pn(e){return e.replace(/[ \t]*\/\/.*\n/g,"").replace(/[ \t]*\/\*[\s\S]*?\*\//g,"")}function Wt(){console.error("Wrong uniform/attributes syntax")}function Dn(e,t){for(var r=/[,=\(\):]/,i=t.replace(/:\s*\[\s*(.*)\s*\]/g,"="+e+"($1)").replace(/\s+/g,"").split(/(?=[,=\(\):])/g),n=[],a=0;a<i.length;a++)i[a].match(r)?n.push(i[a].charAt(0),i[a].slice(1)):n.push(i[a]);i=n;var s=0,o=1,l=2,c=3,h=4,u=5,d=s,f={},v=null,m;p(i[0]);function p(y){y||Wt();var g=y.match(/\[(.*?)\]/);m=y.replace(/\[(.*?)\]/,""),f[m]={},g&&(f[m].isArray=!0,f[m].arraySize=g[1])}for(var a=1;a<i.length;a++){var _=i[a];if(_){if(_==="="){if(d!==s&&d!==c){Wt();break}d=o;continue}else if(_===":"){d=h;continue}else if(_===","){if(d===l){if(!(v instanceof Array)){Wt();break}v.push(+i[++a])}else d=u;continue}else if(_===")"){f[m].value=new be.Float32Array(v),v=null,d=u;continue}else if(_==="("){if(d!==l){Wt();break}if(!(v instanceof Array)){Wt();break}v.push(+i[++a]);continue}else if(_.indexOf("vec")>=0){if(d!==o&&d!==h){Wt();break}d=l,v=[];continue}else if(d===o){e==="bool"?f[m].value=_==="true":f[m].value=parseFloat(_),v=null;continue}else if(d===h){var T=_;Hi.indexOf(T)>=0||Ta.indexOf(T)>=0||Ea.indexOf(T)>=0?f[m].semantic=T:T==="ignore"||T==="unconfigurable"?f[m].ignore=!0:e==="bool"?f[m].value=T==="true":f[m].value=parseFloat(T);continue}p(_),d=s}}return f}function N(e,t){typeof e=="object"&&(t=e.fragment,e=e.vertex),e=Pn(e),t=Pn(t),this._shaderID=Bo(e,t),this._vertexCode=N.parseImport(e),this._fragmentCode=N.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()}N.prototype={constructor:N,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=N.parseImport(this.vertex),this._fragmentCode=N.parseImport(this.fragment)},_addSemanticUniform:function(e,t,r){if(Hi.indexOf(r)>=0)this.attributeSemantics[r]={symbol:e,type:t};else if(Ea.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 Ta.indexOf(r)>=0&&(this.uniformSemantics[r]={symbol:e,type:t})},_addMaterialUniform:function(e,t,r,i,n,a){a[e]={type:r,value:n?Ln.array:i||Ln[t],semantic:null}},_parseUniforms:function(){var e={},t=this,r="vertex";this._uniformList=[],this._vertexCode=this._vertexCode.replace(Mn,n),r="fragment",this._fragmentCode=this._fragmentCode.replace(Mn,n),t.matrixSemanticKeys=Object.keys(this.matrixSemantics);function i(a){return a!=null?function(){return a}:null}function n(a,s,o){var l=Dn(s,o),c=[];for(var h in l){var u=l[h],d=u.semantic,f=h,v=Io[s],m=i(l[h].value);l[h].isArray&&(f+="["+l[h].arraySize+"]",v+="v"),c.push(f),t._uniformList.push(h),u.ignore||((s==="sampler2D"||s==="samplerCube")&&(t.textures[h]={shaderType:r,type:s}),d?t._addSemanticUniform(h,v,d):t._addMaterialUniform(h,s,v,m,l[h].isArray,e))}return c.length>0?"uniform "+s+" "+c.join(",")+";\n":""}this.uniformTemplates=e},_parseAttributes:function(){var e={},t=this;this._vertexCode=this._vertexCode.replace(Do,r);function r(i,n,a){var s=Dn(n,a),o=Oo[n]||1,l=[];for(var c in s){var h=s[c].semantic;if(e[c]={type:"float",size:o,semantic:h||null},h){if(Hi.indexOf(h)<0)throw new Error('Unkown semantic "'+h+'"');t.attributeSemantics[h]={symbol:c,type:n}}l.push(c)}return"attribute "+n+" "+l.join(",")+";\n"}this.attributes=e},_parseDefines:function(){var e=this,t="vertex";this._vertexCode=this._vertexCode.replace(Nn,r),t="fragment",this._fragmentCode=this._fragmentCode.replace(Nn,r);function r(i,n,a){var s=t==="vertex"?e.vertexDefines:e.fragmentDefines;return s[n]||(a==="false"?s[n]=!1:a==="true"?s[n]=!0:s[n]=a?isNaN(parseFloat(a))?a.trim():parseFloat(a):null),""}},clone:function(){var e=Aa[this._shaderID],t=new N(e.vertex,e.fragment);return t}};Object.defineProperty&&(Object.defineProperty(N.prototype,"shaderID",{get:function(){return this._shaderID}}),Object.defineProperty(N.prototype,"vertex",{get:function(){return this._vertexCode}}),Object.defineProperty(N.prototype,"fragment",{get:function(){return this._fragmentCode}}),Object.defineProperty(N.prototype,"uniforms",{get:function(){return this._uniformList}}));var Fo=/(@import)\s*([0-9a-zA-Z_\-\.]*)/g;N.parseImport=function(e){return e=e.replace(Fo,function(n,r,i){var n=N.source(i);return n?N.parseImport(n):(console.error('Shader chunk "'+i+'" not existed in library'),"")}),e};var Uo=/(@export)\s*([0-9a-zA-Z_\-\.]*)\s*\n([\s\S]*?)@end/g;N.import=function(e){e.replace(Uo,function(t,r,i,a){var a=a.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+\x24)/g,"");if(a){for(var s=i.split("."),o=N.codes,l=0,c;l<s.length-1;)c=s[l++],o[c]||(o[c]={}),o=o[c];c=s[l],o[c]=a}return a})};N.codes={};N.source=function(e){for(var t=e.split("."),r=N.codes,i=0;r&&i<t.length;){var n=t[i++];r=r[n]}return typeof r!="string"?(console.error('Shader "'+e+'" not existed in library'),""):r};const Sa="@export clay.prez.vertex\nuniform mat4 WVP : WORLDVIEWPROJECTION;\nattribute vec3 pos : POSITION;\nattribute vec2 uv : TEXCOORD_0;\nuniform vec2 uvRepeat : [1.0, 1.0];\nuniform vec2 uvOffset : [0.0, 0.0];\n@import clay.chunk.skinning_header\n@import clay.chunk.instancing_header\nvarying vec2 v_Texcoord;\nvoid main()\n{\n vec4 P = vec4(pos, 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 = WVP * P;\n v_Texcoord = uv * uvRepeat + uvOffset;\n}\n@end\n@export clay.prez.fragment\nuniform sampler2D alphaMap;\nuniform float alphaCutoff: 0.0;\nvarying vec2 v_Texcoord;\nvoid main()\n{\n if (alphaCutoff > 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 le={};le.create=function(){var e=new Ie(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};le.clone=function(e){var t=new Ie(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};le.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};le.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};le.transpose=function(e,t){if(e===t){var r=t[1],i=t[2],n=t[3],a=t[6],s=t[7],o=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]=s,e[14]=o}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};le.invert=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=t[4],o=t[5],l=t[6],c=t[7],h=t[8],u=t[9],d=t[10],f=t[11],v=t[12],m=t[13],p=t[14],_=t[15],T=r*o-i*s,y=r*l-n*s,g=r*c-a*s,E=i*l-n*o,S=i*c-a*o,R=n*c-a*l,b=h*m-u*v,M=h*p-d*v,F=h*_-f*v,w=u*p-d*m,U=u*_-f*m,O=d*_-f*p,L=T*O-y*U+g*w+E*F-S*M+R*b;return L?(L=1/L,e[0]=(o*O-l*U+c*w)*L,e[1]=(n*U-i*O-a*w)*L,e[2]=(m*R-p*S+_*E)*L,e[3]=(d*S-u*R-f*E)*L,e[4]=(l*F-s*O-c*M)*L,e[5]=(r*O-n*F+a*M)*L,e[6]=(p*g-v*R-_*y)*L,e[7]=(h*R-d*g+f*y)*L,e[8]=(s*U-o*F+c*b)*L,e[9]=(i*F-r*U-a*b)*L,e[10]=(v*S-m*g+_*T)*L,e[11]=(u*g-h*S-f*T)*L,e[12]=(o*M-s*w-l*b)*L,e[13]=(r*w-i*M+n*b)*L,e[14]=(m*y-v*E-p*T)*L,e[15]=(h*E-u*y+d*T)*L,e):null};le.adjoint=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=t[4],o=t[5],l=t[6],c=t[7],h=t[8],u=t[9],d=t[10],f=t[11],v=t[12],m=t[13],p=t[14],_=t[15];return e[0]=o*(d*_-f*p)-u*(l*_-c*p)+m*(l*f-c*d),e[1]=-(i*(d*_-f*p)-u*(n*_-a*p)+m*(n*f-a*d)),e[2]=i*(l*_-c*p)-o*(n*_-a*p)+m*(n*c-a*l),e[3]=-(i*(l*f-c*d)-o*(n*f-a*d)+u*(n*c-a*l)),e[4]=-(s*(d*_-f*p)-h*(l*_-c*p)+v*(l*f-c*d)),e[5]=r*(d*_-f*p)-h*(n*_-a*p)+v*(n*f-a*d),e[6]=-(r*(l*_-c*p)-s*(n*_-a*p)+v*(n*c-a*l)),e[7]=r*(l*f-c*d)-s*(n*f-a*d)+h*(n*c-a*l),e[8]=s*(u*_-f*m)-h*(o*_-c*m)+v*(o*f-c*u),e[9]=-(r*(u*_-f*m)-h*(i*_-a*m)+v*(i*f-a*u)),e[10]=r*(o*_-c*m)-s*(i*_-a*m)+v*(i*c-a*o),e[11]=-(r*(o*f-c*u)-s*(i*f-a*u)+h*(i*c-a*o)),e[12]=-(s*(u*p-d*m)-h*(o*p-l*m)+v*(o*d-l*u)),e[13]=r*(u*p-d*m)-h*(i*p-n*m)+v*(i*d-n*u),e[14]=-(r*(o*p-l*m)-s*(i*p-n*m)+v*(i*l-n*o)),e[15]=r*(o*d-l*u)-s*(i*d-n*u)+h*(i*l-n*o),e};le.determinant=function(e){var t=e[0],r=e[1],i=e[2],n=e[3],a=e[4],s=e[5],o=e[6],l=e[7],c=e[8],h=e[9],u=e[10],d=e[11],f=e[12],v=e[13],m=e[14],p=e[15],_=t*s-r*a,T=t*o-i*a,y=t*l-n*a,g=r*o-i*s,E=r*l-n*s,S=i*l-n*o,R=c*v-h*f,b=c*m-u*f,M=c*p-d*f,F=h*m-u*v,w=h*p-d*v,U=u*p-d*m;return _*U-T*w+y*F+g*M-E*b+S*R};le.multiply=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=t[6],h=t[7],u=t[8],d=t[9],f=t[10],v=t[11],m=t[12],p=t[13],_=t[14],T=t[15],y=r[0],g=r[1],E=r[2],S=r[3];return e[0]=y*i+g*o+E*u+S*m,e[1]=y*n+g*l+E*d+S*p,e[2]=y*a+g*c+E*f+S*_,e[3]=y*s+g*h+E*v+S*T,y=r[4],g=r[5],E=r[6],S=r[7],e[4]=y*i+g*o+E*u+S*m,e[5]=y*n+g*l+E*d+S*p,e[6]=y*a+g*c+E*f+S*_,e[7]=y*s+g*h+E*v+S*T,y=r[8],g=r[9],E=r[10],S=r[11],e[8]=y*i+g*o+E*u+S*m,e[9]=y*n+g*l+E*d+S*p,e[10]=y*a+g*c+E*f+S*_,e[11]=y*s+g*h+E*v+S*T,y=r[12],g=r[13],E=r[14],S=r[15],e[12]=y*i+g*o+E*u+S*m,e[13]=y*n+g*l+E*d+S*p,e[14]=y*a+g*c+E*f+S*_,e[15]=y*s+g*h+E*v+S*T,e};le.multiplyAffine=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[4],o=t[5],l=t[6],c=t[8],h=t[9],u=t[10],d=t[12],f=t[13],v=t[14],m=r[0],p=r[1],_=r[2];return e[0]=m*i+p*s+_*c,e[1]=m*n+p*o+_*h,e[2]=m*a+p*l+_*u,m=r[4],p=r[5],_=r[6],e[4]=m*i+p*s+_*c,e[5]=m*n+p*o+_*h,e[6]=m*a+p*l+_*u,m=r[8],p=r[9],_=r[10],e[8]=m*i+p*s+_*c,e[9]=m*n+p*o+_*h,e[10]=m*a+p*l+_*u,m=r[12],p=r[13],_=r[14],e[12]=m*i+p*s+_*c+d,e[13]=m*n+p*o+_*h+f,e[14]=m*a+p*l+_*u+v,e};le.mul=le.multiply;le.mulAffine=le.multiplyAffine;le.translate=function(e,t,r){var i=r[0],n=r[1],a=r[2],s,o,l,c,h,u,d,f,v,m,p,_;return t===e?(e[12]=t[0]*i+t[4]*n+t[8]*a+t[12],e[13]=t[1]*i+t[5]*n+t[9]*a+t[13],e[14]=t[2]*i+t[6]*n+t[10]*a+t[14],e[15]=t[3]*i+t[7]*n+t[11]*a+t[15]):(s=t[0],o=t[1],l=t[2],c=t[3],h=t[4],u=t[5],d=t[6],f=t[7],v=t[8],m=t[9],p=t[10],_=t[11],e[0]=s,e[1]=o,e[2]=l,e[3]=c,e[4]=h,e[5]=u,e[6]=d,e[7]=f,e[8]=v,e[9]=m,e[10]=p,e[11]=_,e[12]=s*i+h*n+v*a+t[12],e[13]=o*i+u*n+m*a+t[13],e[14]=l*i+d*n+p*a+t[14],e[15]=c*i+f*n+_*a+t[15]),e};le.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};le.rotate=function(e,t,r,i){var n=i[0],a=i[1],s=i[2],o=Math.sqrt(n*n+a*a+s*s),l,c,h,u,d,f,v,m,p,_,T,y,g,E,S,R,b,M,F,w,U,O,L,G;return Math.abs(o)<Vr?null:(o=1/o,n*=o,a*=o,s*=o,l=Math.sin(r),c=Math.cos(r),h=1-c,u=t[0],d=t[1],f=t[2],v=t[3],m=t[4],p=t[5],_=t[6],T=t[7],y=t[8],g=t[9],E=t[10],S=t[11],R=n*n*h+c,b=a*n*h+s*l,M=s*n*h-a*l,F=n*a*h-s*l,w=a*a*h+c,U=s*a*h+n*l,O=n*s*h+a*l,L=a*s*h-n*l,G=s*s*h+c,e[0]=u*R+m*b+y*M,e[1]=d*R+p*b+g*M,e[2]=f*R+_*b+E*M,e[3]=v*R+T*b+S*M,e[4]=u*F+m*w+y*U,e[5]=d*F+p*w+g*U,e[6]=f*F+_*w+E*U,e[7]=v*F+T*w+S*U,e[8]=u*O+m*L+y*G,e[9]=d*O+p*L+g*G,e[10]=f*O+_*L+E*G,e[11]=v*O+T*L+S*G,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)};le.rotateX=function(e,t,r){var i=Math.sin(r),n=Math.cos(r),a=t[4],s=t[5],o=t[6],l=t[7],c=t[8],h=t[9],u=t[10],d=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=a*n+c*i,e[5]=s*n+h*i,e[6]=o*n+u*i,e[7]=l*n+d*i,e[8]=c*n-a*i,e[9]=h*n-s*i,e[10]=u*n-o*i,e[11]=d*n-l*i,e};le.rotateY=function(e,t,r){var i=Math.sin(r),n=Math.cos(r),a=t[0],s=t[1],o=t[2],l=t[3],c=t[8],h=t[9],u=t[10],d=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=a*n-c*i,e[1]=s*n-h*i,e[2]=o*n-u*i,e[3]=l*n-d*i,e[8]=a*i+c*n,e[9]=s*i+h*n,e[10]=o*i+u*n,e[11]=l*i+d*n,e};le.rotateZ=function(e,t,r){var i=Math.sin(r),n=Math.cos(r),a=t[0],s=t[1],o=t[2],l=t[3],c=t[4],h=t[5],u=t[6],d=t[7];return t!==e&&(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[0]=a*n+c*i,e[1]=s*n+h*i,e[2]=o*n+u*i,e[3]=l*n+d*i,e[4]=c*n-a*i,e[5]=h*n-s*i,e[6]=u*n-o*i,e[7]=d*n-l*i,e};le.fromRotationTranslation=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=i+i,l=n+n,c=a+a,h=i*o,u=i*l,d=i*c,f=n*l,v=n*c,m=a*c,p=s*o,_=s*l,T=s*c;return e[0]=1-(f+m),e[1]=u+T,e[2]=d-_,e[3]=0,e[4]=u-T,e[5]=1-(h+m),e[6]=v+p,e[7]=0,e[8]=d+_,e[9]=v-p,e[10]=1-(h+f),e[11]=0,e[12]=r[0],e[13]=r[1],e[14]=r[2],e[15]=1,e};le.fromQuat=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=r+r,o=i+i,l=n+n,c=r*s,h=i*s,u=i*o,d=n*s,f=n*o,v=n*l,m=a*s,p=a*o,_=a*l;return e[0]=1-u-v,e[1]=h+_,e[2]=d-p,e[3]=0,e[4]=h-_,e[5]=1-c-v,e[6]=f+m,e[7]=0,e[8]=d+p,e[9]=f-m,e[10]=1-c-u,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e};le.frustum=function(e,t,r,i,n,a,s){var o=1/(r-t),l=1/(n-i),c=1/(a-s);return e[0]=a*2*o,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=a*2*l,e[6]=0,e[7]=0,e[8]=(r+t)*o,e[9]=(n+i)*l,e[10]=(s+a)*c,e[11]=-1,e[12]=0,e[13]=0,e[14]=s*a*2*c,e[15]=0,e};le.perspective=function(e,t,r,i,n){var a=1/Math.tan(t/2),s=1/(i-n);return e[0]=a/r,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=a,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=(n+i)*s,e[11]=-1,e[12]=0,e[13]=0,e[14]=2*n*i*s,e[15]=0,e};le.ortho=function(e,t,r,i,n,a,s){var o=1/(t-r),l=1/(i-n),c=1/(a-s);return e[0]=-2*o,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*l,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*c,e[11]=0,e[12]=(t+r)*o,e[13]=(n+i)*l,e[14]=(s+a)*c,e[15]=1,e};le.lookAt=function(e,t,r,i){var n,a,s,o,l,c,h,u,d,f,v=t[0],m=t[1],p=t[2],_=i[0],T=i[1],y=i[2],g=r[0],E=r[1],S=r[2];return Math.abs(v-g)<Vr&&Math.abs(m-E)<Vr&&Math.abs(p-S)<Vr?le.identity(e):(h=v-g,u=m-E,d=p-S,f=1/Math.sqrt(h*h+u*u+d*d),h*=f,u*=f,d*=f,n=T*d-y*u,a=y*h-_*d,s=_*u-T*h,f=Math.sqrt(n*n+a*a+s*s),f?(f=1/f,n*=f,a*=f,s*=f):(n=0,a=0,s=0),o=u*s-d*a,l=d*n-h*s,c=h*a-u*n,f=Math.sqrt(o*o+l*l+c*c),f?(f=1/f,o*=f,l*=f,c*=f):(o=0,l=0,c=0),e[0]=n,e[1]=o,e[2]=h,e[3]=0,e[4]=a,e[5]=l,e[6]=u,e[7]=0,e[8]=s,e[9]=c,e[10]=d,e[11]=0,e[12]=-(n*v+a*m+s*p),e[13]=-(o*v+l*m+c*p),e[14]=-(h*v+u*m+d*p),e[15]=1,e)};le.frob=function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2)+Math.pow(e[4],2)+Math.pow(e[5],2)+Math.pow(e[6],2)+Math.pow(e[7],2)+Math.pow(e[8],2)+Math.pow(e[9],2)+Math.pow(e[10],2)+Math.pow(e[11],2)+Math.pow(e[12],2)+Math.pow(e[13],2)+Math.pow(e[14],2)+Math.pow(e[15],2))};const C=le;var X={};X.create=function(){var e=new Ie(3);return e[0]=0,e[1]=0,e[2]=0,e};X.clone=function(e){var t=new Ie(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t};X.fromValues=function(e,t,r){var i=new Ie(3);return i[0]=e,i[1]=t,i[2]=r,i};X.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e};X.set=function(e,t,r,i){return e[0]=t,e[1]=r,e[2]=i,e};X.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};X.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};X.sub=X.subtract;X.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};X.mul=X.multiply;X.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};X.div=X.divide;X.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};X.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};X.scale=function(e,t,r){return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e};X.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};X.distance=function(e,t){var r=t[0]-e[0],i=t[1]-e[1],n=t[2]-e[2];return Math.sqrt(r*r+i*i+n*n)};X.dist=X.distance;X.squaredDistance=function(e,t){var r=t[0]-e[0],i=t[1]-e[1],n=t[2]-e[2];return r*r+i*i+n*n};X.sqrDist=X.squaredDistance;X.length=function(e){var t=e[0],r=e[1],i=e[2];return Math.sqrt(t*t+r*r+i*i)};X.len=X.length;X.squaredLength=function(e){var t=e[0],r=e[1],i=e[2];return t*t+r*r+i*i};X.sqrLen=X.squaredLength;X.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e};X.inverse=function(e,t){return e[0]=1/t[0],e[1]=1/t[1],e[2]=1/t[2],e};X.normalize=function(e,t){var r=t[0],i=t[1],n=t[2],a=r*r+i*i+n*n;return a>0&&(a=1/Math.sqrt(a),e[0]=t[0]*a,e[1]=t[1]*a,e[2]=t[2]*a),e};X.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]};X.cross=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=r[0],o=r[1],l=r[2];return e[0]=n*l-a*o,e[1]=a*s-i*l,e[2]=i*o-n*s,e};X.lerp=function(e,t,r,i){var n=t[0],a=t[1],s=t[2];return e[0]=n+i*(r[0]-n),e[1]=a+i*(r[1]-a),e[2]=s+i*(r[2]-s),e};X.random=function(e,t){t=t||1;var r=Kt()*2*Math.PI,i=Kt()*2-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};X.transformMat4=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=r[3]*i+r[7]*n+r[11]*a+r[15];return s=s||1,e[0]=(r[0]*i+r[4]*n+r[8]*a+r[12])/s,e[1]=(r[1]*i+r[5]*n+r[9]*a+r[13])/s,e[2]=(r[2]*i+r[6]*n+r[10]*a+r[14])/s,e};X.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};X.transformQuat=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=r[0],o=r[1],l=r[2],c=r[3],h=c*i+o*a-l*n,u=c*n+l*i-s*a,d=c*a+s*n-o*i,f=-s*i-o*n-l*a;return e[0]=h*c+f*-s+u*-l-d*-o,e[1]=u*c+f*-o+d*-s-h*-l,e[2]=d*c+f*-l+h*-o-u*-s,e};X.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};X.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};X.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};X.forEach=function(){var e=X.create();return function(t,r,i,n,a,s){var o,l;for(r||(r=3),i||(i=0),n?l=Math.min(n*r+i,t.length):l=t.length,o=i;o<l;o+=r)e[0]=t[o],e[1]=t[o+1],e[2]=t[o+2],a(e,e,s),t[o]=e[0],t[o+1]=e[1],t[o+2]=e[2];return t}}();X.angle=function(e,t){var r=X.fromValues(e[0],e[1],e[2]),i=X.fromValues(t[0],t[1],t[2]);X.normalize(r,r),X.normalize(i,i);var n=X.dot(r,i);return n>1?0:Math.acos(n)};const x=X;N.import(Sa);var de=C.create,In={};function On(e){return e.material}function Ho(e,t,r){return t.uniforms[r].value}function zo(e,t,r,i){return r!==i}function Go(e){return!0}function Bn(){}var Fn={float:A.FLOAT,byte:A.BYTE,ubyte:A.UNSIGNED_BYTE,short:A.SHORT,ushort:A.UNSIGNED_SHORT};function ko(e,t,r){this.availableAttributes=e,this.availableAttributeSymbols=t,this.indicesBuffer=r,this.vao=null}function Vo(e){var t,r;this.bind=function(i){t||(t=be.createCanvas(),t.width=t.height=1,t.getContext("2d"));var n=i.gl,a=!r;a&&(r=n.createTexture()),n.bindTexture(n.TEXTURE_2D,r),a&&n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t)},this.unbind=function(i){i.gl.bindTexture(i.gl.TEXTURE_2D,null)},this.isRenderable=function(){return!0}}var wt=qe.extend(function(){return{canvas:null,_width:100,_height:100,devicePixelRatio:typeof window<"u"&&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=be.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 _o(this.gl),this.gl.targetRenderer&&console.error("Already created a renderer"),this.gl.targetRenderer=this,this.resize()}catch(r){throw"Error creating WebGL Context "+r}this._programMgr=new xa(this),this._placeholderTexture=new Vo},{resize:function(e,t){var r=this.canvas,i=this.devicePixelRatio;e!=null?(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(typeof e=="object"){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 s=this.viewport,o=!1,l=s.devicePixelRatio;(s.width!==this._width||s.height!==this._height||l&&l!==this.devicePixelRatio||s.x||s.y)&&(o=!0,n.enable(n.SCISSOR_TEST),n.scissor(s.x*l,s.y*l,s.width*l,s.height*l)),n.clearColor(a[0],a[1],a[2],a[3]),n.clear(this.clearBit),o&&n.disable(n.SCISSOR_TEST)}if(r||e.update(!1),e.updateLights(),t=t||e.getMainCamera(),!t){console.error("Can't find camera in the scene.");return}t.update();var c=e.updateRenderList(t,!0);this._sceneRendering=e;var h=c.opaque,u=c.transparent,d=e.material;e.trigger("beforerender",this,e,t,c),i?(this.renderPreZ(h,e,t),n.depthFunc(n.LEQUAL)):n.depthFunc(n.LESS);for(var f=de(),v=x.create(),m=0;m<u.length;m++){var p=u[m];C.multiplyAffine(f,t.viewMatrix.array,p.worldTransform.array),x.transformMat4(v,p.position.array,f),p.__depth=v[2]}this.renderPass(h,t,{getMaterial:function(_){return d||_.material},sortCompare:this.opaqueSortCompare}),this.renderPass(u,t,{getMaterial:function(_){return d||_.material},sortCompare:this.transparentSortCompare}),e.trigger("afterrender",this,e,t,c),this._sceneRendering=null},getProgram:function(e,t,r){return t=t||e.material,this._programMgr.getProgram(e,t,r)},validateProgram:function(e){if(e.__error){var t=e.__error;if(In[e.__uid__])return;if(In[e.__uid__]=!0,this.throwError)throw new Error(t);this.trigger("error",t)}},updatePrograms:function(e,t,r){var i=r&&r.getMaterial||On;t=t||null;for(var n=0;n<e.length;n++){var a=e[n],s=i.call(this,a);if(n>0){var o=e[n-1],l=o.joints?o.joints.length:0,c=a.joints?a.joints.length:0;if(c===l&&a.material===o.material&&a.lightGroup===o.lightGroup){a.__program=o.__program;continue}}var h=this._programMgr.getProgram(a,s,t);this.validateProgram(h),a.__program=h}},renderPass:function(e,t,r){this.trigger("beforerenderpass",this,e,t,r),r=r||{},r.getMaterial=r.getMaterial||On,r.getUniform=r.getUniform||Ho,r.isMaterialChanged=r.isMaterialChanged||zo,r.beforeRender=r.beforeRender||Bn,r.afterRender=r.afterRender||Bn;var i=r.ifRender||Go;this.updatePrograms(e,this._sceneRendering,r),r.sortCompare&&e.sort(r.sortCompare);var n=this.viewport,a=n.devicePixelRatio,s=[n.x*a,n.y*a,n.width*a,n.height*a],o=this.devicePixelRatio,l=this.__currentFrameBuffer?[this.__currentFrameBuffer.getTextureWidth(),this.__currentFrameBuffer.getTextureHeight()]:[this._width*o,this._height*o],c=[s[2],s[3]],h=Date.now();t?(C.copy(fe.VIEW,t.viewMatrix.array),C.copy(fe.PROJECTION,t.projectionMatrix.array),C.copy(fe.VIEWINVERSE,t.worldTransform.array)):(C.identity(fe.VIEW),C.identity(fe.PROJECTION),C.identity(fe.VIEWINVERSE)),C.multiply(fe.VIEWPROJECTION,fe.PROJECTION,fe.VIEW),C.invert(fe.PROJECTIONINVERSE,fe.PROJECTION),C.invert(fe.VIEWPROJECTIONINVERSE,fe.VIEWPROJECTION);for(var u=this.gl,d=this._sceneRendering,f,v,m,p,_,T,y,g,E,S,R,b,M=null,F=0;F<e.length;F++){var w=e[F],U=w.worldTransform!=null,O;if(i(w)){U&&(O=w.isSkinnedMesh&&w.isSkinnedMesh()?w.offsetMatrix?w.offsetMatrix.array:fe.IDENTITY:w.worldTransform.array);var L=w.geometry,G=r.getMaterial.call(this,w),B=w.__program,Z=G.shader,I=L.__uid__+"-"+B.__uid__,ue=I!==S;S=I,ue&&M&&M.bindVertexArrayOES(null),U&&(C.copy(fe.WORLD,O),C.multiply(fe.WORLDVIEWPROJECTION,fe.VIEWPROJECTION,O),C.multiplyAffine(fe.WORLDVIEW,fe.VIEW,O),(Z.matrixSemantics.WORLDINVERSE||Z.matrixSemantics.WORLDINVERSETRANSPOSE)&&C.invert(fe.WORLDINVERSE,O),(Z.matrixSemantics.WORLDVIEWINVERSE||Z.matrixSemantics.WORLDVIEWINVERSETRANSPOSE)&&C.invert(fe.WORLDVIEWINVERSE,fe.WORLDVIEW),(Z.matrixSemantics.WORLDVIEWPROJECTIONINVERSE||Z.matrixSemantics.WORLDVIEWPROJECTIONINVERSETRANSPOSE)&&C.invert(fe.WORLDVIEWPROJECTIONINVERSE,fe.WORLDVIEWPROJECTION)),w.beforeRender&&w.beforeRender(this),r.beforeRender.call(this,w,G,f);var k=B!==v;k?(B.bind(this),B.setUniformOfSemantic(u,"VIEWPORT",s),B.setUniformOfSemantic(u,"WINDOW_SIZE",l),t&&(B.setUniformOfSemantic(u,"NEAR",t.near),B.setUniformOfSemantic(u,"FAR",t.far)),B.setUniformOfSemantic(u,"DEVICEPIXELRATIO",a),B.setUniformOfSemantic(u,"TIME",h),B.setUniformOfSemantic(u,"VIEWPORT_SIZE",c),d&&d.setLightUniforms(B,w.lightGroup,this)):B=v,(k||r.isMaterialChanged(w,m,G,f))&&(G.depthTest!==p&&(G.depthTest?u.enable(u.DEPTH_TEST):u.disable(u.DEPTH_TEST),p=G.depthTest),G.depthMask!==_&&(u.depthMask(G.depthMask),_=G.depthMask),G.transparent!==E&&(G.transparent?u.enable(u.BLEND):u.disable(u.BLEND),E=G.transparent),G.transparent&&(G.blend?G.blend(u):(u.blendEquationSeparate(u.FUNC_ADD,u.FUNC_ADD),u.blendFuncSeparate(u.SRC_ALPHA,u.ONE_MINUS_SRC_ALPHA,u.ONE,u.ONE_MINUS_SRC_ALPHA))),b=this._bindMaterial(w,G,B,m||null,f||null,v||null,r.getUniform),f=G);var ye=Z.matrixSemanticKeys;if(U)for(var ae=0;ae<ye.length;ae++){var ve=ye[ae],me=Z.matrixSemantics[ve],Oe=fe[ve];if(me.isTranspose){var Be=fe[me.semanticNoTranspose];C.transpose(Oe,Be)}B.setUniform(u,me.type,me.symbol,Oe)}w.cullFace!==y&&(y=w.cullFace,u.cullFace(y)),w.frontFace!==g&&(g=w.frontFace,u.frontFace(g)),w.culling!==T&&(T=w.culling,T?u.enable(u.CULL_FACE):u.disable(u.CULL_FACE)),this._updateSkeleton(w,B,b),ue&&(R=this._bindVAO(M,Z,L,B)),this._renderObject(w,R,B),r.afterRender(this,w),w.afterRender&&w.afterRender(this),v=B,m=w}}this.trigger("afterrenderpass",this,e,t,r)},getMaxJointNumber:function(){return this.maxJointNumber},_updateSkeleton:function(e,t,r){var i=this.gl,n=e.skeleton;if(n)if(n.update(),e.joints.length>this.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 s=n.getSubSkinMatrices(e.__uid__,e.joints);t.setUniformOfSemantic(i,"SKIN_MATRIX",s)}},_renderObject:function(e,t,r){var i=this.gl,n=e.geometry,a=e.mode;a==null&&(a=4);var s=null,o=e.isInstancedMesh&&e.isInstancedMesh();if(o&&(s=this.getGLExtension("ANGLE_instanced_arrays"),!s)){console.warn("Device not support ANGLE_instanced_arrays extension");return}var l;if(o&&(l=this._bindInstancedAttributes(e,r,s)),t.indicesBuffer){var c=this.getGLExtension("OES_element_index_uint"),h=c&&n.indices instanceof Uint32Array,u=h?i.UNSIGNED_INT:i.UNSIGNED_SHORT;o?s.drawElementsInstancedANGLE(a,t.indicesBuffer.count,u,0,e.getInstanceCount()):i.drawElements(a,t.indicesBuffer.count,u,0)}else o?s.drawArraysInstancedANGLE(a,0,n.vertexCount,e.getInstanceCount()):i.drawArrays(a,0,n.vertexCount);if(o)for(var d=0;d<l.length;d++)i.disableVertexAttribArray(l[d])},_bindInstancedAttributes:function(e,t,r){for(var i=this.gl,n=e.getInstancedAttributesBuffers(this),a=[],s=0;s<n.length;s++){var o=n[s],l=t.getAttribLocation(i,o.symbol);if(!(l<0)){var c=Fn[o.type]||i.FLOAT;i.enableVertexAttribArray(l),i.bindBuffer(i.ARRAY_BUFFER,o.buffer),i.vertexAttribPointer(l,o.size,c,!1,0,0),r.vertexAttribDivisorANGLE(l,o.divisor),a.push(l)}}return a},_bindMaterial:function(e,t,r,i,n,a,s){for(var o=this.gl,l=a===r,c=r.currentTextureSlot(),h=t.getEnabledUniforms(),u=t.getTextureUniforms(),d=this._placeholderTexture,f=0;f<u.length;f++){var v=u[f],m=s(e,t,v),p=t.uniforms[v].type;if(p==="t"&&m)m.__slot=-1;else if(p==="tv")for(var _=0;_<m.length;_++)m[_]&&(m[_].__slot=-1)}d.__slot=-1;for(var f=0;f<h.length;f++){var v=h[f],T=t.uniforms[v],m=s(e,t,v),p=T.type,y=p==="t";if(y&&(!m||!m.isRenderable())&&(m=d),n&&l){var g=s(i,n,v);if(y&&(!g||!g.isRenderable())&&(g=d),g===m){if(y)r.takeCurrentTextureSlot(this,null);else if(p==="tv"&&m)for(var _=0;_<m.length;_++)r.takeCurrentTextureSlot(this,null);continue}}if(m!=null)if(y)if(m.__slot<0){var E=r.currentTextureSlot(),S=r.setUniform(o,"1i",v,E);S&&(r.takeCurrentTextureSlot(this,m),m.__slot=E)}else r.setUniform(o,"1i",v,m.__slot);else if(Array.isArray(m)){if(m.length===0)continue;if(p==="tv"){if(!r.hasUniform(v))continue;for(var R=[],_=0;_<m.length;_++){var b=m[_];if(b.__slot<0){var E=r.currentTextureSlot();R.push(E),r.takeCurrentTextureSlot(this,b),b.__slot=E}else R.push(b.__slot)}r.setUniform(o,"1iv",v,R)}else r.setUniform(o,T.type,v,m)}else r.setUniform(o,T.type,v,m)}var M=r.currentTextureSlot();return r.resetTextureSlot(c),M},_bindVAO:function(e,t,r,i){var n=!r.dynamic,a=this.gl,s=this.__uid__+"-"+i.__uid__,o=r.__vaoCache[s];if(!o){var l=r.getBufferChunks(this);if(!l||!l.length)return;for(var c=l[0],h=c.attributeBuffers,g=c.indicesBuffer,y=[],u=[],d=0;d<h.length;d++){var f=h[d],v=f.name,m=f.semantic,p;if(m){var _=t.attributeSemantics[m];p=_&&_.symbol}else p=v;p&&i.attributes[p]&&(y.push(f),u.push(p))}o=new ko(y,u,g),n&&(r.__vaoCache[s]=o)}var T=!0;e&&n&&(o.vao==null?o.vao=e.createVertexArrayOES():T=!1,e.bindVertexArrayOES(o.vao));var y=o.availableAttributes,g=o.indicesBuffer;if(T){for(var E=i.enableAttributes(this,o.availableAttributeSymbols,e&&n&&o),d=0;d<y.length;d++){var S=E[d];if(S!==-1){var f=y[d],R=f.buffer,b=f.size,M=Fn[f.type]||a.FLOAT;a.bindBuffer(a.ARRAY_BUFFER,R),a.vertexAttribPointer(S,b,M,!1,0,0)}}r.isUseIndices()&&a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,g.buffer)}return o},renderPreZ:function(e,t,r){var i=this.gl,n=this._prezMaterial||new yt({shader:new N(N.source("clay.prez.vertex"),N.source("clay.prez.fragment"))});this._prezMaterial=n,i.colorMask(!1,!1,!1,!1),i.depthMask(!0),this.renderPass(e,r,{ifRender:function(a){return!a.ignorePreZ},isMaterialChanged:function(a,s){var o=a.material,l=s.material;return o.get("diffuseMap")!==l.get("diffuseMap")||(o.get("alphaCutoff")||0)!==(l.get("alphaCutoff")||0)},getUniform:function(a,s,o){if(o==="alphaMap")return a.material.get("diffuseMap");if(o==="alphaCutoff"){if(a.material.isDefined("fragment","ALPHA_TEST")&&a.material.get("diffuseMap")){var l=a.material.get("alphaCutoff");return l||0}return 0}else return o==="uvRepeat"?a.material.get("uvRepeat"):o==="uvOffset"?a.material.get("uvOffset"):s.get(o)},getMaterial:function(){return n},sort:this.opaqueSortCompare}),i.colorMask(!0,!0,!0,!0),i.depthMask(!0)},disposeScene:function(e){this.disposeNode(e,!0,!0),e.dispose()},disposeNode:function(e,t,r){e.getParent()&&e.getParent().remove(e);var i={};e.traverse(function(n){var a=n.material;if(n.geometry&&t&&n.geometry.dispose(this),r&&a&&!i[a.__uid__]){for(var s=a.getTextureUniforms(),o=0;o<s.length;o++){var l=s[o],c=a.uniforms[l].value,h=a.uniforms[l].type;if(c){if(h==="t")c.dispose&&c.dispose(this);else if(h==="tv")for(var u=0;u<c.length;u++)c[u]&&c[u].dispose&&c[u].dispose(this)}}i[a.__uid__]=!0}n.dispose&&n.dispose(this)},this)},disposeGeometry:function(e){e.dispose(this)},disposeTexture:function(e){e.dispose(this)},disposeFrameBuffer:function(e){e.dispose(this)},dispose:function(){},screenToNDC:function(e,t,r){r||(r=new $e),t=this._height-t;var i=this.viewport,n=r.array;return n[0]=(e-i.x)/i.width,n[0]=n[0]*2-1,n[1]=(t-i.y)/i.height,n[1]=n[1]*2-1,r}});wt.opaqueSortCompare=wt.prototype.opaqueSortCompare=function(e,t){return e.renderOrder===t.renderOrder?e.__program===t.__program?e.material===t.material?e.geometry.__uid__-t.geometry.__uid__:e.material.__uid__-t.material.__uid__:e.__program&&t.__program?e.__program.__uid__-t.__program.__uid__:0:e.renderOrder-t.renderOrder};wt.transparentSortCompare=wt.prototype.transparentSortCompare=function(e,t){return e.renderOrder===t.renderOrder?e.__depth===t.__depth?e.__program===t.__program?e.material===t.material?e.geometry.__uid__-t.geometry.__uid__:e.material.__uid__-t.material.__uid__:e.__program&&t.__program?e.__program.__uid__-t.__program.__uid__:0:e.__depth-t.__depth:e.renderOrder-t.renderOrder};var fe={IDENTITY:de(),WORLD:de(),VIEW:de(),PROJECTION:de(),WORLDVIEW:de(),VIEWPROJECTION:de(),WORLDVIEWPROJECTION:de(),WORLDINVERSE:de(),VIEWINVERSE:de(),PROJECTIONINVERSE:de(),WORLDVIEWINVERSE:de(),VIEWPROJECTIONINVERSE:de(),WORLDVIEWPROJECTIONINVERSE:de(),WORLDTRANSPOSE:de(),VIEWTRANSPOSE:de(),PROJECTIONTRANSPOSE:de(),WORLDVIEWTRANSPOSE:de(),VIEWPROJECTIONTRANSPOSE:de(),WORLDVIEWPROJECTIONTRANSPOSE:de(),WORLDINVERSETRANSPOSE:de(),VIEWINVERSETRANSPOSE:de(),PROJECTIONINVERSETRANSPOSE:de(),WORLDVIEWINVERSETRANSPOSE:de(),VIEWPROJECTIONINVERSETRANSPOSE:de(),WORLDVIEWPROJECTIONINVERSETRANSPOSE:de()};wt.COLOR_BUFFER_BIT=A.COLOR_BUFFER_BIT;wt.DEPTH_BUFFER_BIT=A.DEPTH_BUFFER_BIT;wt.STENCIL_BUFFER_BIT=A.STENCIL_BUFFER_BIT;const vr=wt;var W=function(e,t,r){e=e||0,t=t||0,r=r||0,this.array=x.fromValues(e,t,r),this._dirty=!0};W.prototype={constructor:W,add:function(e){return x.add(this.array,this.array,e.array),this._dirty=!0,this},set:function(e,t,r){return this.array[0]=e,this.array[1]=t,this.array[2]=r,this._dirty=!0,this},setArray:function(e){return this.array[0]=e[0],this.array[1]=e[1],this.array[2]=e[2],this._dirty=!0,this},clone:function(){return new W(this.x,this.y,this.z)},copy:function(e){return x.copy(this.array,e.array),this._dirty=!0,this},cross:function(e,t){return x.cross(this.array,e.array,t.array),this._dirty=!0,this},dist:function(e){return x.dist(this.array,e.array)},distance:function(e){return x.distance(this.array,e.array)},div:function(e){return x.div(this.array,this.array,e.array),this._dirty=!0,this},divide:function(e){return x.divide(this.array,this.array,e.array),this._dirty=!0,this},dot:function(e){return x.dot(this.array,e.array)},len:function(){return x.len(this.array)},length:function(){return x.length(this.array)},lerp:function(e,t,r){return x.lerp(this.array,e.array,t.array,r),this._dirty=!0,this},min:function(e){return x.min(this.array,this.array,e.array),this._dirty=!0,this},max:function(e){return x.max(this.array,this.array,e.array),this._dirty=!0,this},mul:function(e){return x.mul(this.array,this.array,e.array),this._dirty=!0,this},multiply:function(e){return x.multiply(this.array,this.array,e.array),this._dirty=!0,this},negate:function(){return x.negate(this.array,this.array),this._dirty=!0,this},normalize:function(){return x.normalize(this.array,this.array),this._dirty=!0,this},random:function(e){return x.random(this.array,e),this._dirty=!0,this},scale:function(e){return x.scale(this.array,this.array,e),this._dirty=!0,this},scaleAndAdd:function(e,t){return x.scaleAndAdd(this.array,this.array,e.array,t),this._dirty=!0,this},sqrDist:function(e){return x.sqrDist(this.array,e.array)},squaredDistance:function(e){return x.squaredDistance(this.array,e.array)},sqrLen:function(){return x.sqrLen(this.array)},squaredLength:function(){return x.squaredLength(this.array)},sub:function(e){return x.sub(this.array,this.array,e.array),this._dirty=!0,this},subtract:function(e){return x.subtract(this.array,this.array,e.array),this._dirty=!0,this},transformMat3:function(e){return x.transformMat3(this.array,this.array,e.array),this._dirty=!0,this},transformMat4:function(e){return x.transformMat4(this.array,this.array,e.array),this._dirty=!0,this},transformQuat:function(e){return x.transformQuat(this.array,this.array,e.array),this._dirty=!0,this},applyProjection:function(e){var t=this.array;if(e=e.array,e[15]===0){var r=-1/t[2];t[0]=e[0]*t[0]*r,t[1]=e[5]*t[1]*r,t[2]=(e[10]*t[2]+e[14])*r}else t[0]=e[0]*t[0]+e[12],t[1]=e[5]*t[1]+e[13],t[2]=e[10]*t[2]+e[14];return this._dirty=!0,this},eulerFromQuat:function(e,t){W.eulerFromQuat(this,e,t)},eulerFromMat3:function(e,t){W.eulerFromMat3(this,e,t)},toString:function(){return"["+Array.prototype.join.call(this.array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this.array)}};var Dr=Object.defineProperty;if(Dr){var yi=W.prototype;Dr(yi,"x",{get:function(){return this.array[0]},set:function(e){this.array[0]=e,this._dirty=!0}}),Dr(yi,"y",{get:function(){return this.array[1]},set:function(e){this.array[1]=e,this._dirty=!0}}),Dr(yi,"z",{get:function(){return this.array[2]},set:function(e){this.array[2]=e,this._dirty=!0}})}W.add=function(e,t,r){return x.add(e.array,t.array,r.array),e._dirty=!0,e};W.set=function(e,t,r,i){x.set(e.array,t,r,i),e._dirty=!0};W.copy=function(e,t){return x.copy(e.array,t.array),e._dirty=!0,e};W.cross=function(e,t,r){return x.cross(e.array,t.array,r.array),e._dirty=!0,e};W.dist=function(e,t){return x.distance(e.array,t.array)};W.distance=W.dist;W.div=function(e,t,r){return x.divide(e.array,t.array,r.array),e._dirty=!0,e};W.divide=W.div;W.dot=function(e,t){return x.dot(e.array,t.array)};W.len=function(e){return x.length(e.array)};W.lerp=function(e,t,r,i){return x.lerp(e.array,t.array,r.array,i),e._dirty=!0,e};W.min=function(e,t,r){return x.min(e.array,t.array,r.array),e._dirty=!0,e};W.max=function(e,t,r){return x.max(e.array,t.array,r.array),e._dirty=!0,e};W.mul=function(e,t,r){return x.multiply(e.array,t.array,r.array),e._dirty=!0,e};W.multiply=W.mul;W.negate=function(e,t){return x.negate(e.array,t.array),e._dirty=!0,e};W.normalize=function(e,t){return x.normalize(e.array,t.array),e._dirty=!0,e};W.random=function(e,t){return x.random(e.array,t),e._dirty=!0,e};W.scale=function(e,t,r){return x.scale(e.array,t.array,r),e._dirty=!0,e};W.scaleAndAdd=function(e,t,r,i){return x.scaleAndAdd(e.array,t.array,r.array,i),e._dirty=!0,e};W.sqrDist=function(e,t){return x.sqrDist(e.array,t.array)};W.squaredDistance=W.sqrDist;W.sqrLen=function(e){return x.sqrLen(e.array)};W.squaredLength=W.sqrLen;W.sub=function(e,t,r){return x.subtract(e.array,t.array,r.array),e._dirty=!0,e};W.subtract=W.sub;W.transformMat3=function(e,t,r){return x.transformMat3(e.array,t.array,r.array),e._dirty=!0,e};W.transformMat4=function(e,t,r){return x.transformMat4(e.array,t.array,r.array),e._dirty=!0,e};W.transformQuat=function(e,t,r){return x.transformQuat(e.array,t.array,r.array),e._dirty=!0,e};function Je(e,t,r){return e<t?t:e>r?r:e}var oe=Math.atan2,et=Math.asin,Xt=Math.abs;W.eulerFromQuat=function(e,t,d){e._dirty=!0,t=t.array;var i=e.array,n=t[0],a=t[1],s=t[2],o=t[3],l=n*n,c=a*a,h=s*s,u=o*o,d=(d||"XYZ").toUpperCase();switch(d){case"XYZ":i[0]=oe(2*(n*o-a*s),u-l-c+h),i[1]=et(Je(2*(n*s+a*o),-1,1)),i[2]=oe(2*(s*o-n*a),u+l-c-h);break;case"YXZ":i[0]=et(Je(2*(n*o-a*s),-1,1)),i[1]=oe(2*(n*s+a*o),u-l-c+h),i[2]=oe(2*(n*a+s*o),u-l+c-h);break;case"ZXY":i[0]=et(Je(2*(n*o+a*s),-1,1)),i[1]=oe(2*(a*o-s*n),u-l-c+h),i[2]=oe(2*(s*o-n*a),u-l+c-h);break;case"ZYX":i[0]=oe(2*(n*o+s*a),u-l-c+h),i[1]=et(Je(2*(a*o-n*s),-1,1)),i[2]=oe(2*(n*a+s*o),u+l-c-h);break;case"YZX":i[0]=oe(2*(n*o-s*a),u-l+c-h),i[1]=oe(2*(a*o-n*s),u+l-c-h),i[2]=et(Je(2*(n*a+s*o),-1,1));break;case"XZY":i[0]=oe(2*(n*o+a*s),u-l+c-h),i[1]=oe(2*(n*s+a*o),u+l-c-h),i[2]=et(Je(2*(s*o-n*a),-1,1));break;default:console.warn("Unkown order: "+d)}return e};W.eulerFromMat3=function(e,t,v){var i=t.array,n=i[0],a=i[3],s=i[6],o=i[1],l=i[4],c=i[7],h=i[2],u=i[5],d=i[8],f=e.array,v=(v||"XYZ").toUpperCase();switch(v){case"XYZ":f[1]=et(Je(s,-1,1)),Xt(s)<.99999?(f[0]=oe(-c,d),f[2]=oe(-a,n)):(f[0]=oe(u,l),f[2]=0);break;case"YXZ":f[0]=et(-Je(c,-1,1)),Xt(c)<.99999?(f[1]=oe(s,d),f[2]=oe(o,l)):(f[1]=oe(-h,n),f[2]=0);break;case"ZXY":f[0]=et(Je(u,-1,1)),Xt(u)<.99999?(f[1]=oe(-h,d),f[2]=oe(-a,l)):(f[1]=0,f[2]=oe(o,n));break;case"ZYX":f[1]=et(-Je(h,-1,1)),Xt(h)<.99999?(f[0]=oe(u,d),f[2]=oe(o,n)):(f[0]=0,f[2]=oe(-a,l));break;case"YZX":f[2]=et(Je(o,-1,1)),Xt(o)<.99999?(f[0]=oe(-c,l),f[1]=oe(-h,n)):(f[0]=0,f[1]=oe(s,d));break;case"XZY":f[2]=et(-Je(a,-1,1)),Xt(a)<.99999?(f[0]=oe(u,l),f[1]=oe(s,n)):(f[0]=oe(-c,d),f[1]=0);break;default:console.warn("Unkown order: "+v)}return e._dirty=!0,e};Object.defineProperties(W,{POSITIVE_X:{get:function(){return new W(1,0,0)}},NEGATIVE_X:{get:function(){return new W(-1,0,0)}},POSITIVE_Y:{get:function(){return new W(0,1,0)}},NEGATIVE_Y:{get:function(){return new W(0,-1,0)}},POSITIVE_Z:{get:function(){return new W(0,0,1)}},NEGATIVE_Z:{get:function(){return new W(0,0,-1)}},UP:{get:function(){return new W(0,1,0)}},ZERO:{get:function(){return new W}}});const P=W;var xi=1e-5,Wr=function(e,t){this.origin=e||new P,this.direction=t||new P};Wr.prototype={constructor:Wr,intersectPlane:function(e,t){var r=e.normal.array,i=e.distance,n=this.origin.array,a=this.direction.array,s=x.dot(r,a);if(s===0)return null;t||(t=new P);var o=(x.dot(r,n)-i)/s;return x.scaleAndAdd(t.array,n,a,-o),t._dirty=!0,t},mirrorAgainstPlane:function(e){var t=x.dot(e.normal.array,this.direction.array);x.scaleAndAdd(this.direction.array,this.direction.array,e.normal.array,-t*2),this.direction._dirty=!0},distanceToPoint:function(){var e=x.create();return function(t){x.sub(e,t,this.origin.array);var r=x.dot(e,this.direction.array);if(r<0)return x.distance(this.origin.array,t);var i=x.lenSquared(e);return Math.sqrt(i-r*r)}}(),intersectSphere:function(){var e=x.create();return function(t,r,i){var n=this.origin.array,a=this.direction.array;t=t.array,x.sub(e,t,n);var s=x.dot(e,a),o=x.squaredLength(e),l=o-s*s,c=r*r;if(!(l>c)){var h=Math.sqrt(c-l),u=s-h,d=s+h;return i||(i=new P),u<0?d<0?null:(x.scaleAndAdd(i.array,n,a,d),i):(x.scaleAndAdd(i.array,n,a,u),i)}}}(),intersectBoundingBox:function(e,t){var r=this.direction.array,i=this.origin.array,n=e.min.array,a=e.max.array,s=1/r[0],o=1/r[1],l=1/r[2],c,h,u,d,f,v;if(s>=0?(c=(n[0]-i[0])*s,h=(a[0]-i[0])*s):(h=(n[0]-i[0])*s,c=(a[0]-i[0])*s),o>=0?(u=(n[1]-i[1])*o,d=(a[1]-i[1])*o):(d=(n[1]-i[1])*o,u=(a[1]-i[1])*o),c>d||u>h||((u>c||c!==c)&&(c=u),(d<h||h!==h)&&(h=d),l>=0?(f=(n[2]-i[2])*l,v=(a[2]-i[2])*l):(v=(n[2]-i[2])*l,f=(a[2]-i[2])*l),c>v||f>h)||((f>c||c!==c)&&(c=f),(v<h||h!==h)&&(h=v),h<0))return null;var m=c>=0?c:h;return t||(t=new P),x.scaleAndAdd(t.array,i,r,m),t},intersectTriangle:function(){var e=x.create(),t=x.create(),r=x.create(),i=x.create();return function(n,a,s,o,l,c){var h=this.direction.array,u=this.origin.array;n=n.array,a=a.array,s=s.array,x.sub(e,a,n),x.sub(t,s,n),x.cross(i,t,h);var d=x.dot(e,i);if(o){if(d>-xi)return null}else if(d>-xi&&d<xi)return null;x.sub(r,u,n);var f=x.dot(i,r)/d;if(f<0||f>1)return null;x.cross(i,e,r);var v=x.dot(h,i)/d;if(v<0||v>1||f+v>1)return null;x.cross(i,e,t);var m=-x.dot(r,i)/d;return m<0?null:(l||(l=new P),c&&P.set(c,1-f-v,f,v),x.scaleAndAdd(l.array,u,h,m),l)}}(),applyTransform:function(e){P.add(this.direction,this.direction,this.origin),P.transformMat4(this.origin,this.origin,e),P.transformMat4(this.direction,this.direction,e),P.sub(this.direction,this.direction,this.origin),P.normalize(this.direction,this.direction)},copy:function(e){P.copy(this.origin,e.origin),P.copy(this.direction,e.direction)},clone:function(){var e=new Wr;return e.copy(this),e}};const $r=Wr;var K={};K.create=function(){var e=new Ie(4);return e[0]=0,e[1]=0,e[2]=0,e[3]=0,e};K.clone=function(e){var t=new Ie(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};K.fromValues=function(e,t,r,i){var n=new Ie(4);return n[0]=e,n[1]=t,n[2]=r,n[3]=i,n};K.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e};K.set=function(e,t,r,i,n){return e[0]=t,e[1]=r,e[2]=i,e[3]=n,e};K.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};K.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};K.sub=K.subtract;K.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};K.mul=K.multiply;K.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};K.div=K.divide;K.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};K.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};K.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};K.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};K.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)};K.dist=K.distance;K.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};K.sqrDist=K.squaredDistance;K.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)};K.len=K.length;K.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};K.sqrLen=K.squaredLength;K.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=-t[3],e};K.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};K.normalize=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=r*r+i*i+n*n+a*a;return s>0&&(s=1/Math.sqrt(s),e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e[3]=t[3]*s),e};K.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]};K.lerp=function(e,t,r,i){var n=t[0],a=t[1],s=t[2],o=t[3];return e[0]=n+i*(r[0]-n),e[1]=a+i*(r[1]-a),e[2]=s+i*(r[2]-s),e[3]=o+i*(r[3]-o),e};K.random=function(e,t){return t=t||1,e[0]=Kt(),e[1]=Kt(),e[2]=Kt(),e[3]=Kt(),K.normalize(e,e),K.scale(e,e,t),e};K.transformMat4=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3];return e[0]=r[0]*i+r[4]*n+r[8]*a+r[12]*s,e[1]=r[1]*i+r[5]*n+r[9]*a+r[13]*s,e[2]=r[2]*i+r[6]*n+r[10]*a+r[14]*s,e[3]=r[3]*i+r[7]*n+r[11]*a+r[15]*s,e};K.transformQuat=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=r[0],o=r[1],l=r[2],c=r[3],h=c*i+o*a-l*n,u=c*n+l*i-s*a,d=c*a+s*n-o*i,f=-s*i-o*n-l*a;return e[0]=h*c+f*-s+u*-l-d*-o,e[1]=u*c+f*-o+d*-s-h*-l,e[2]=d*c+f*-l+h*-o-u*-s,e};K.forEach=function(){var e=K.create();return function(t,r,i,n,a,s){var o,l;for(r||(r=4),i||(i=0),n?l=Math.min(n*r+i,t.length):l=t.length,o=i;o<l;o+=r)e[0]=t[o],e[1]=t[o+1],e[2]=t[o+2],e[3]=t[o+3],a(e,e,s),t[o]=e[0],t[o+1]=e[1],t[o+2]=e[2],t[o+3]=e[3];return t}}();const D=K;var Ce={};Ce.create=function(){var e=new Ie(9);return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e};Ce.fromMat4=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e};Ce.clone=function(e){var t=new Ie(9);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t};Ce.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};Ce.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=1,e[5]=0,e[6]=0,e[7]=0,e[8]=1,e};Ce.transpose=function(e,t){if(e===t){var r=t[1],i=t[2],n=t[5];e[1]=t[3],e[2]=t[6],e[3]=r,e[5]=t[7],e[6]=i,e[7]=n}else e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8];return e};Ce.invert=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=t[4],o=t[5],l=t[6],c=t[7],h=t[8],u=h*s-o*c,d=-h*a+o*l,f=c*a-s*l,v=r*u+i*d+n*f;return v?(v=1/v,e[0]=u*v,e[1]=(-h*i+n*c)*v,e[2]=(o*i-n*s)*v,e[3]=d*v,e[4]=(h*r-n*l)*v,e[5]=(-o*r+n*a)*v,e[6]=f*v,e[7]=(-c*r+i*l)*v,e[8]=(s*r-i*a)*v,e):null};Ce.adjoint=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=t[4],o=t[5],l=t[6],c=t[7],h=t[8];return e[0]=s*h-o*c,e[1]=n*c-i*h,e[2]=i*o-n*s,e[3]=o*l-a*h,e[4]=r*h-n*l,e[5]=n*a-r*o,e[6]=a*c-s*l,e[7]=i*l-r*c,e[8]=r*s-i*a,e};Ce.determinant=function(e){var t=e[0],r=e[1],i=e[2],n=e[3],a=e[4],s=e[5],o=e[6],l=e[7],c=e[8];return t*(c*a-s*l)+r*(-c*n+s*o)+i*(l*n-a*o)};Ce.multiply=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=t[6],h=t[7],u=t[8],d=r[0],f=r[1],v=r[2],m=r[3],p=r[4],_=r[5],T=r[6],y=r[7],g=r[8];return e[0]=d*i+f*s+v*c,e[1]=d*n+f*o+v*h,e[2]=d*a+f*l+v*u,e[3]=m*i+p*s+_*c,e[4]=m*n+p*o+_*h,e[5]=m*a+p*l+_*u,e[6]=T*i+y*s+g*c,e[7]=T*n+y*o+g*h,e[8]=T*a+y*l+g*u,e};Ce.mul=Ce.multiply;Ce.translate=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=t[6],h=t[7],u=t[8],d=r[0],f=r[1];return e[0]=i,e[1]=n,e[2]=a,e[3]=s,e[4]=o,e[5]=l,e[6]=d*i+f*s+c,e[7]=d*n+f*o+h,e[8]=d*a+f*l+u,e};Ce.rotate=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=t[6],h=t[7],u=t[8],d=Math.sin(r),f=Math.cos(r);return e[0]=f*i+d*s,e[1]=f*n+d*o,e[2]=f*a+d*l,e[3]=f*s-d*i,e[4]=f*o-d*n,e[5]=f*l-d*a,e[6]=c,e[7]=h,e[8]=u,e};Ce.scale=function(e,t,r){var i=r[0],n=r[1];return e[0]=i*t[0],e[1]=i*t[1],e[2]=i*t[2],e[3]=n*t[3],e[4]=n*t[4],e[5]=n*t[5],e[6]=t[6],e[7]=t[7],e[8]=t[8],e};Ce.fromMat2d=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=0,e[3]=t[2],e[4]=t[3],e[5]=0,e[6]=t[4],e[7]=t[5],e[8]=1,e};Ce.fromQuat=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=r+r,o=i+i,l=n+n,c=r*s,h=i*s,u=i*o,d=n*s,f=n*o,v=n*l,m=a*s,p=a*o,_=a*l;return e[0]=1-u-v,e[3]=h-_,e[6]=d+p,e[1]=h+_,e[4]=1-c-v,e[7]=f-m,e[2]=d-p,e[5]=f+m,e[8]=1-c-u,e};Ce.normalFromMat4=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=t[4],o=t[5],l=t[6],c=t[7],h=t[8],u=t[9],d=t[10],f=t[11],v=t[12],m=t[13],p=t[14],_=t[15],T=r*o-i*s,y=r*l-n*s,g=r*c-a*s,E=i*l-n*o,S=i*c-a*o,R=n*c-a*l,b=h*m-u*v,M=h*p-d*v,F=h*_-f*v,w=u*p-d*m,U=u*_-f*m,O=d*_-f*p,L=T*O-y*U+g*w+E*F-S*M+R*b;return L?(L=1/L,e[0]=(o*O-l*U+c*w)*L,e[1]=(l*F-s*O-c*M)*L,e[2]=(s*U-o*F+c*b)*L,e[3]=(n*U-i*O-a*w)*L,e[4]=(r*O-n*F+a*M)*L,e[5]=(i*F-r*U-a*b)*L,e[6]=(m*R-p*S+_*E)*L,e[7]=(p*g-v*R-_*y)*L,e[8]=(v*S-m*g+_*T)*L,e):null};Ce.frob=function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2)+Math.pow(e[4],2)+Math.pow(e[5],2)+Math.pow(e[6],2)+Math.pow(e[7],2)+Math.pow(e[8],2))};const ee=Ce;var ie={};ie.create=function(){var e=new Ie(4);return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e};ie.rotationTo=function(){var e=x.create(),t=x.fromValues(1,0,0),r=x.fromValues(0,1,0);return function(i,n,a){var s=x.dot(n,a);return s<-.999999?(x.cross(e,t,n),x.length(e)<1e-6&&x.cross(e,r,n),x.normalize(e,e),ie.setAxisAngle(i,e,Math.PI),i):s>.999999?(i[0]=0,i[1]=0,i[2]=0,i[3]=1,i):(x.cross(e,n,a),i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=1+s,ie.normalize(i,i))}}();ie.setAxes=function(){var e=ee.create();return function(t,r,i,n){return e[0]=i[0],e[3]=i[1],e[6]=i[2],e[1]=n[0],e[4]=n[1],e[7]=n[2],e[2]=-r[0],e[5]=-r[1],e[8]=-r[2],ie.normalize(t,ie.fromMat3(t,e))}}();ie.clone=D.clone;ie.fromValues=D.fromValues;ie.copy=D.copy;ie.set=D.set;ie.identity=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e};ie.setAxisAngle=function(e,t,r){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};ie.add=D.add;ie.multiply=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=r[0],l=r[1],c=r[2],h=r[3];return e[0]=i*h+s*o+n*c-a*l,e[1]=n*h+s*l+a*o-i*c,e[2]=a*h+s*c+i*l-n*o,e[3]=s*h-i*o-n*l-a*c,e};ie.mul=ie.multiply;ie.scale=D.scale;ie.rotateX=function(e,t,r){r*=.5;var i=t[0],n=t[1],a=t[2],s=t[3],o=Math.sin(r),l=Math.cos(r);return e[0]=i*l+s*o,e[1]=n*l+a*o,e[2]=a*l-n*o,e[3]=s*l-i*o,e};ie.rotateY=function(e,t,r){r*=.5;var i=t[0],n=t[1],a=t[2],s=t[3],o=Math.sin(r),l=Math.cos(r);return e[0]=i*l-a*o,e[1]=n*l+s*o,e[2]=a*l+i*o,e[3]=s*l-n*o,e};ie.rotateZ=function(e,t,r){r*=.5;var i=t[0],n=t[1],a=t[2],s=t[3],o=Math.sin(r),l=Math.cos(r);return e[0]=i*l+n*o,e[1]=n*l-i*o,e[2]=a*l+s*o,e[3]=s*l-a*o,e};ie.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};ie.dot=D.dot;ie.lerp=D.lerp;ie.slerp=function(e,t,r,i){var n=t[0],a=t[1],s=t[2],o=t[3],l=r[0],c=r[1],h=r[2],u=r[3],d,f,v,m,p;return f=n*l+a*c+s*h+o*u,f<0&&(f=-f,l=-l,c=-c,h=-h,u=-u),1-f>1e-6?(d=Math.acos(f),v=Math.sin(d),m=Math.sin((1-i)*d)/v,p=Math.sin(i*d)/v):(m=1-i,p=i),e[0]=m*n+p*l,e[1]=m*a+p*c,e[2]=m*s+p*h,e[3]=m*o+p*u,e};ie.invert=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=r*r+i*i+n*n+a*a,o=s?1/s:0;return e[0]=-r*o,e[1]=-i*o,e[2]=-n*o,e[3]=a*o,e};ie.conjugate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e};ie.length=D.length;ie.len=ie.length;ie.squaredLength=D.squaredLength;ie.sqrLen=ie.squaredLength;ie.normalize=D.normalize;ie.fromMat3=function(e,t){var r=t[0]+t[4]+t[8],i;if(r>0)i=Math.sqrt(r+1),e[3]=.5*i,i=.5/i,e[0]=(t[5]-t[7])*i,e[1]=(t[6]-t[2])*i,e[2]=(t[1]-t[3])*i;else{var n=0;t[4]>t[0]&&(n=1),t[8]>t[n*3+n]&&(n=2);var a=(n+1)%3,s=(n+2)%3;i=Math.sqrt(t[n*3+n]-t[a*3+a]-t[s*3+s]+1),e[n]=.5*i,i=.5/i,e[3]=(t[a*3+s]-t[s*3+a])*i,e[a]=(t[a*3+n]+t[n*3+a])*i,e[s]=(t[s*3+n]+t[n*3+s])*i}return e};const Y=ie;var he=function(){this._axisX=new P,this._axisY=new P,this._axisZ=new P,this.array=C.create(),this._dirty=!0};he.prototype={constructor:he,setArray:function(e){for(var t=0;t<this.array.length;t++)this.array[t]=e[t];return this._dirty=!0,this},adjoint:function(){return C.adjoint(this.array,this.array),this._dirty=!0,this},clone:function(){return new he().copy(this)},copy:function(e){return C.copy(this.array,e.array),this._dirty=!0,this},determinant:function(){return C.determinant(this.array)},fromQuat:function(e){return C.fromQuat(this.array,e.array),this._dirty=!0,this},fromRotationTranslation:function(e,t){return C.fromRotationTranslation(this.array,e.array,t.array),this._dirty=!0,this},fromMat2d:function(e){return he.fromMat2d(this,e),this},frustum:function(e,t,r,i,n,a){return C.frustum(this.array,e,t,r,i,n,a),this._dirty=!0,this},identity:function(){return C.identity(this.array),this._dirty=!0,this},invert:function(){return C.invert(this.array,this.array),this._dirty=!0,this},lookAt:function(e,t,r){return C.lookAt(this.array,e.array,t.array,r.array),this._dirty=!0,this},mul:function(e){return C.mul(this.array,this.array,e.array),this._dirty=!0,this},mulLeft:function(e){return C.mul(this.array,e.array,this.array),this._dirty=!0,this},multiply:function(e){return C.multiply(this.array,this.array,e.array),this._dirty=!0,this},multiplyLeft:function(e){return C.multiply(this.array,e.array,this.array),this._dirty=!0,this},ortho:function(e,t,r,i,n,a){return C.ortho(this.array,e,t,r,i,n,a),this._dirty=!0,this},perspective:function(e,t,r,i){return C.perspective(this.array,e,t,r,i),this._dirty=!0,this},rotate:function(e,t){return C.rotate(this.array,this.array,e,t.array),this._dirty=!0,this},rotateX:function(e){return C.rotateX(this.array,this.array,e),this._dirty=!0,this},rotateY:function(e){return C.rotateY(this.array,this.array,e),this._dirty=!0,this},rotateZ:function(e){return C.rotateZ(this.array,this.array,e),this._dirty=!0,this},scale:function(e){return C.scale(this.array,this.array,e.array),this._dirty=!0,this},translate:function(e){return C.translate(this.array,this.array,e.array),this._dirty=!0,this},transpose:function(){return C.transpose(this.array,this.array),this._dirty=!0,this},decomposeMatrix:function(){var e=x.create(),t=x.create(),r=x.create(),i=ee.create();return function(n,a,s){var o=this.array;x.set(e,o[0],o[1],o[2]),x.set(t,o[4],o[5],o[6]),x.set(r,o[8],o[9],o[10]);var l=x.length(e),c=x.length(t),h=x.length(r),u=this.determinant();u<0&&(l=-l),n&&n.set(l,c,h),s.set(o[12],o[13],o[14]),ee.fromMat4(i,o),i[0]/=l,i[1]/=l,i[2]/=l,i[3]/=c,i[4]/=c,i[5]/=c,i[6]/=h,i[7]/=h,i[8]/=h,Y.fromMat3(a.array,i),Y.normalize(a.array,a.array),a._dirty=!0,s._dirty=!0}}(),toString:function(){return"["+Array.prototype.join.call(this.array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this.array)}};var Ir=Object.defineProperty;if(Ir){var Ti=he.prototype;Ir(Ti,"z",{get:function(){var e=this.array;return this._axisZ.set(e[8],e[9],e[10]),this._axisZ},set:function(e){var t=this.array;e=e.array,t[8]=e[0],t[9]=e[1],t[10]=e[2],this._dirty=!0}}),Ir(Ti,"y",{get:function(){var e=this.array;return this._axisY.set(e[4],e[5],e[6]),this._axisY},set:function(e){var t=this.array;e=e.array,t[4]=e[0],t[5]=e[1],t[6]=e[2],this._dirty=!0}}),Ir(Ti,"x",{get:function(){var e=this.array;return this._axisX.set(e[0],e[1],e[2]),this._axisX},set:function(e){var t=this.array;e=e.array,t[0]=e[0],t[1]=e[1],t[2]=e[2],this._dirty=!0}})}he.adjoint=function(e,t){return C.adjoint(e.array,t.array),e._dirty=!0,e};he.copy=function(e,t){return C.copy(e.array,t.array),e._dirty=!0,e};he.determinant=function(e){return C.determinant(e.array)};he.identity=function(e){return C.identity(e.array),e._dirty=!0,e};he.ortho=function(e,t,r,i,n,a,s){return C.ortho(e.array,t,r,i,n,a,s),e._dirty=!0,e};he.perspective=function(e,t,r,i,n){return C.perspective(e.array,t,r,i,n),e._dirty=!0,e};he.lookAt=function(e,t,r,i){return C.lookAt(e.array,t.array,r.array,i.array),e._dirty=!0,e};he.invert=function(e,t){return C.invert(e.array,t.array),e._dirty=!0,e};he.mul=function(e,t,r){return C.mul(e.array,t.array,r.array),e._dirty=!0,e};he.multiply=he.mul;he.fromQuat=function(e,t){return C.fromQuat(e.array,t.array),e._dirty=!0,e};he.fromRotationTranslation=function(e,t,r){return C.fromRotationTranslation(e.array,t.array,r.array),e._dirty=!0,e};he.fromMat2d=function(i,r){i._dirty=!0;var r=r.array,i=i.array;return i[0]=r[0],i[4]=r[2],i[12]=r[4],i[1]=r[1],i[5]=r[3],i[13]=r[5],i};he.rotate=function(e,t,r,i){return C.rotate(e.array,t.array,r,i.array),e._dirty=!0,e};he.rotateX=function(e,t,r){return C.rotateX(e.array,t.array,r),e._dirty=!0,e};he.rotateY=function(e,t,r){return C.rotateY(e.array,t.array,r),e._dirty=!0,e};he.rotateZ=function(e,t,r){return C.rotateZ(e.array,t.array,r),e._dirty=!0,e};he.scale=function(e,t,r){return C.scale(e.array,t.array,r.array),e._dirty=!0,e};he.transpose=function(e,t){return C.transpose(e.array,t.array),e._dirty=!0,e};he.translate=function(e,t,r){return C.translate(e.array,t.array,r.array),e._dirty=!0,e};const z=he;var se=function(e,t,r,i){e=e||0,t=t||0,r=r||0,i=i===void 0?1:i,this.array=Y.fromValues(e,t,r,i),this._dirty=!0};se.prototype={constructor:se,add:function(e){return Y.add(this.array,this.array,e.array),this._dirty=!0,this},calculateW:function(){return Y.calculateW(this.array,this.array),this._dirty=!0,this},set:function(e,t,r,i){return this.array[0]=e,this.array[1]=t,this.array[2]=r,this.array[3]=i,this._dirty=!0,this},setArray:function(e){return this.array[0]=e[0],this.array[1]=e[1],this.array[2]=e[2],this.array[3]=e[3],this._dirty=!0,this},clone:function(){return new se(this.x,this.y,this.z,this.w)},conjugate:function(){return Y.conjugate(this.array,this.array),this._dirty=!0,this},copy:function(e){return Y.copy(this.array,e.array),this._dirty=!0,this},dot:function(e){return Y.dot(this.array,e.array)},fromMat3:function(e){return Y.fromMat3(this.array,e.array),this._dirty=!0,this},fromMat4:function(){var e=ee.create();return function(t){return ee.fromMat4(e,t.array),ee.transpose(e,e),Y.fromMat3(this.array,e),this._dirty=!0,this}}(),identity:function(){return Y.identity(this.array),this._dirty=!0,this},invert:function(){return Y.invert(this.array,this.array),this._dirty=!0,this},len:function(){return Y.len(this.array)},length:function(){return Y.length(this.array)},lerp:function(e,t,r){return Y.lerp(this.array,e.array,t.array,r),this._dirty=!0,this},mul:function(e){return Y.mul(this.array,this.array,e.array),this._dirty=!0,this},mulLeft:function(e){return Y.multiply(this.array,e.array,this.array),this._dirty=!0,this},multiply:function(e){return Y.multiply(this.array,this.array,e.array),this._dirty=!0,this},multiplyLeft:function(e){return Y.multiply(this.array,e.array,this.array),this._dirty=!0,this},normalize:function(){return Y.normalize(this.array,this.array),this._dirty=!0,this},rotateX:function(e){return Y.rotateX(this.array,this.array,e),this._dirty=!0,this},rotateY:function(e){return Y.rotateY(this.array,this.array,e),this._dirty=!0,this},rotateZ:function(e){return Y.rotateZ(this.array,this.array,e),this._dirty=!0,this},rotationTo:function(e,t){return Y.rotationTo(this.array,e.array,t.array),this._dirty=!0,this},setAxes:function(e,t,r){return Y.setAxes(this.array,e.array,t.array,r.array),this._dirty=!0,this},setAxisAngle:function(e,t){return Y.setAxisAngle(this.array,e.array,t),this._dirty=!0,this},slerp:function(e,t,r){return Y.slerp(this.array,e.array,t.array,r),this._dirty=!0,this},sqrLen:function(){return Y.sqrLen(this.array)},squaredLength:function(){return Y.squaredLength(this.array)},fromEuler:function(e,t){return se.fromEuler(this,e,t)},toString:function(){return"["+Array.prototype.join.call(this.array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this.array)}};var ar=Object.defineProperty;if(ar){var Or=se.prototype;ar(Or,"x",{get:function(){return this.array[0]},set:function(e){this.array[0]=e,this._dirty=!0}}),ar(Or,"y",{get:function(){return this.array[1]},set:function(e){this.array[1]=e,this._dirty=!0}}),ar(Or,"z",{get:function(){return this.array[2]},set:function(e){this.array[2]=e,this._dirty=!0}}),ar(Or,"w",{get:function(){return this.array[3]},set:function(e){this.array[3]=e,this._dirty=!0}})}se.add=function(e,t,r){return Y.add(e.array,t.array,r.array),e._dirty=!0,e};se.set=function(e,t,r,i,n){Y.set(e.array,t,r,i,n),e._dirty=!0};se.copy=function(e,t){return Y.copy(e.array,t.array),e._dirty=!0,e};se.calculateW=function(e,t){return Y.calculateW(e.array,t.array),e._dirty=!0,e};se.conjugate=function(e,t){return Y.conjugate(e.array,t.array),e._dirty=!0,e};se.identity=function(e){return Y.identity(e.array),e._dirty=!0,e};se.invert=function(e,t){return Y.invert(e.array,t.array),e._dirty=!0,e};se.dot=function(e,t){return Y.dot(e.array,t.array)};se.len=function(e){return Y.length(e.array)};se.lerp=function(e,t,r,i){return Y.lerp(e.array,t.array,r.array,i),e._dirty=!0,e};se.slerp=function(e,t,r,i){return Y.slerp(e.array,t.array,r.array,i),e._dirty=!0,e};se.mul=function(e,t,r){return Y.multiply(e.array,t.array,r.array),e._dirty=!0,e};se.multiply=se.mul;se.rotateX=function(e,t,r){return Y.rotateX(e.array,t.array,r),e._dirty=!0,e};se.rotateY=function(e,t,r){return Y.rotateY(e.array,t.array,r),e._dirty=!0,e};se.rotateZ=function(e,t,r){return Y.rotateZ(e.array,t.array,r),e._dirty=!0,e};se.setAxisAngle=function(e,t,r){return Y.setAxisAngle(e.array,t.array,r),e._dirty=!0,e};se.normalize=function(e,t){return Y.normalize(e.array,t.array),e._dirty=!0,e};se.sqrLen=function(e){return Y.sqrLen(e.array)};se.squaredLength=se.sqrLen;se.fromMat3=function(e,t){return Y.fromMat3(e.array,t.array),e._dirty=!0,e};se.setAxes=function(e,t,r,i){return Y.setAxes(e.array,t.array,r.array,i.array),e._dirty=!0,e};se.rotationTo=function(e,t,r){return Y.rotationTo(e.array,t.array,r.array),e._dirty=!0,e};se.fromEuler=function(e,t,h){e._dirty=!0,t=t.array;var i=e.array,n=Math.cos(t[0]/2),a=Math.cos(t[1]/2),s=Math.cos(t[2]/2),o=Math.sin(t[0]/2),l=Math.sin(t[1]/2),c=Math.sin(t[2]/2),h=(h||"XYZ").toUpperCase();switch(h){case"XYZ":i[0]=o*a*s+n*l*c,i[1]=n*l*s-o*a*c,i[2]=n*a*c+o*l*s,i[3]=n*a*s-o*l*c;break;case"YXZ":i[0]=o*a*s+n*l*c,i[1]=n*l*s-o*a*c,i[2]=n*a*c-o*l*s,i[3]=n*a*s+o*l*c;break;case"ZXY":i[0]=o*a*s-n*l*c,i[1]=n*l*s+o*a*c,i[2]=n*a*c+o*l*s,i[3]=n*a*s-o*l*c;break;case"ZYX":i[0]=o*a*s-n*l*c,i[1]=n*l*s+o*a*c,i[2]=n*a*c-o*l*s,i[3]=n*a*s+o*l*c;break;case"YZX":i[0]=o*a*s+n*l*c,i[1]=n*l*s+o*a*c,i[2]=n*a*c-o*l*s,i[3]=n*a*s-o*l*c;break;case"XZY":i[0]=o*a*s-n*l*c,i[1]=n*l*s-o*a*c,i[2]=n*a*c+o*l*s,i[3]=n*a*s+o*l*c;break}};const ba=se;var Et=x.set,Br=x.copy,Xr=function(e,t){this.min=e||new P(1/0,1/0,1/0),this.max=t||new P(-1/0,-1/0,-1/0),this.vertices=null};Xr.prototype={constructor:Xr,updateFromVertices:function(e){if(e.length>0){var t=this.min,r=this.max,i=t.array,n=r.array;Br(i,e[0]),Br(n,e[0]);for(var a=1;a<e.length;a++){var s=e[a];s[0]<i[0]&&(i[0]=s[0]),s[1]<i[1]&&(i[1]=s[1]),s[2]<i[2]&&(i[2]=s[2]),s[0]>n[0]&&(n[0]=s[0]),s[1]>n[1]&&(n[1]=s[1]),s[2]>n[2]&&(n[2]=s[2])}t._dirty=!0,r._dirty=!0}},union:function(e){var t=this.min,r=this.max;return x.min(t.array,t.array,e.min.array),x.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 x.max(t.array,t.array,e.min.array),x.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]<i[0]||r[1]<i[1]||r[2]<i[2])},containBoundingBox:function(e){var t=this.min.array,r=this.max.array,i=e.min.array,n=e.max.array;return t[0]<=i[0]&&t[1]<=i[1]&&t[2]<=i[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:function(){var e=x.create(),t=x.create(),r=x.create(),i=x.create(),n=x.create(),a=x.create();return function(s,o){var l=s.min.array,c=s.max.array,h=o.array;return e[0]=h[0]*l[0],e[1]=h[1]*l[0],e[2]=h[2]*l[0],t[0]=h[0]*c[0],t[1]=h[1]*c[0],t[2]=h[2]*c[0],r[0]=h[4]*l[1],r[1]=h[5]*l[1],r[2]=h[6]*l[1],i[0]=h[4]*c[1],i[1]=h[5]*c[1],i[2]=h[6]*c[1],n[0]=h[8]*l[2],n[1]=h[9]*l[2],n[2]=h[10]*l[2],a[0]=h[8]*c[2],a[1]=h[9]*c[2],a[2]=h[10]*c[2],l=this.min.array,c=this.max.array,l[0]=Math.min(e[0],t[0])+Math.min(r[0],i[0])+Math.min(n[0],a[0])+h[12],l[1]=Math.min(e[1],t[1])+Math.min(r[1],i[1])+Math.min(n[1],a[1])+h[13],l[2]=Math.min(e[2],t[2])+Math.min(r[2],i[2])+Math.min(n[2],a[2])+h[14],c[0]=Math.max(e[0],t[0])+Math.max(r[0],i[0])+Math.max(n[0],a[0])+h[12],c[1]=Math.max(e[1],t[1])+Math.max(r[1],i[1])+Math.max(n[1],a[1])+h[13],c[2]=Math.max(e[2],t[2])+Math.max(r[2],i[2])+Math.max(n[2],a[2])+h[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],s=t[2],o=r[0],l=r[1],c=t[2],h=r[0],u=r[1],d=r[2];if(i[15]===1)t[0]=i[0]*n+i[12],t[1]=i[5]*a+i[13],r[2]=i[10]*s+i[14],r[0]=i[0]*h+i[12],r[1]=i[5]*u+i[13],t[2]=i[10]*d+i[14];else{var f=-1/s;t[0]=i[0]*n*f,t[1]=i[5]*a*f,r[2]=(i[10]*s+i[14])*f,f=-1/c,r[0]=i[0]*o*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]=x.fromValues(0,0,0);this.vertices=e}var r=this.min.array,i=this.max.array;return Et(e[0],r[0],r[1],r[2]),Et(e[1],r[0],i[1],r[2]),Et(e[2],i[0],r[1],r[2]),Et(e[3],i[0],i[1],r[2]),Et(e[4],r[0],r[1],i[2]),Et(e[5],r[0],i[1],i[2]),Et(e[6],i[0],r[1],i[2]),Et(e[7],i[0],i[1],i[2]),this},copy:function(e){var t=this.min,r=this.max;return Br(t.array,e.min.array),Br(r.array,e.max.array),t._dirty=!0,r._dirty=!0,this},clone:function(){var e=new Xr;return e.copy(this),e}};const ke=Xr;var Wo=0,Xo=qe.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")+"_"+Wo++),this.position||(this.position=new P),this.rotation||(this.rotation=new ba),this.scale||(this.scale=new P(1,1,1)),this.worldTransform=new z,this.localTransform=new z,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;t<e.length;t++)e[t]._parent=null,this._scene&&e[t].traverse(this._removeSelfFromScene,this);this._children=[]},getScene:function(){return this._scene},getParent:function(){return this._parent},_removeSelfFromScene:function(e){e._scene.removeFromScene(e),e._scene=null},_addSelfToScene:function(e){this._scene.addToScene(e),e._scene=this._scene},isAncestor:function(e){for(var t=e._parent;t;){if(t===this)return!0;t=t._parent}return!1},children:function(){return this._children.slice()},childAt:function(e){return this._children[e]},getChildByName:function(e){for(var t=this._children,r=0;r<t.length;r++)if(t[r].name===e)return t[r]},getDescendantByName:function(e){for(var t=this._children,r=0;r<t.length;r++){var i=t[r];if(i.name===e)return i;var n=i.getDescendantByName(e);if(n)return n}},queryNode:function(e){if(e){for(var t=e.split("/"),r=this,i=0;i<t.length;i++){var n=t[i];if(n){for(var a=!1,s=r._children,o=0;o<s.length;o++){var l=s[o];if(l.name===n){r=l,a=!0;break}}if(!a)return}}return r}},getPath:function(e){if(!this._parent)return"/";for(var t=this._parent,r=this.name;t._parent&&(r=t.name+"/"+r,t._parent!=e);)t=t._parent;return!t._parent&&e?null:r},traverse:function(e,t){e.call(t,this);for(var r=this._children,i=0,n=r.length;i<n;i++)r[i].traverse(e,t)},eachChild:function(e,t){for(var r=this._children,i=0,n=r.length;i<n;i++){var a=r[i];e.call(t,a,i)}},setLocalTransform:function(e){C.copy(this.localTransform.array,e.array),this.decomposeLocalTransform()},decomposeLocalTransform:function(e){var t=e?null:this.scale;this.localTransform.decomposeMatrix(t,this.rotation,this.position)},setWorldTransform:function(e){C.copy(this.worldTransform.array,e.array),this.decomposeWorldTransform()},decomposeWorldTransform:function(){var e=C.create();return function(t){var r=this.localTransform,i=this.worldTransform;this._parent?(C.invert(e,this._parent.worldTransform.array),C.multiply(r.array,e,i.array)):C.copy(r.array,i.array);var n=t?null:this.scale;r.decomposeMatrix(n,this.rotation,this.position)}}(),transformNeedsUpdate:function(){return this.position._dirty||this.rotation._dirty||this.scale._dirty},updateLocalTransform:function(){var e=this.position,t=this.rotation,r=this.scale;if(this.transformNeedsUpdate()){var i=this.localTransform.array;C.fromRotationTranslation(i,t.array,e.array),C.scale(i,i,r.array),t._dirty=!1,r._dirty=!1,e._dirty=!1,this._needsUpdateWorldTransform=!0}},_updateWorldTransformTopDown:function(){var e=this.localTransform.array,t=this.worldTransform.array;this._parent?C.multiplyAffine(t,this._parent.worldTransform.array,e):C.copy(t,e)},updateWorldTransform:function(){for(var e=this;e&&e.getParent()&&e.getParent().transformNeedsUpdate();)e=e.getParent();e.update()},update:function(e){this.autoUpdateLocalTransform?this.updateLocalTransform():e=!0,(e||this._needsUpdateWorldTransform)&&(this._updateWorldTransformTopDown(),e=!0,this._needsUpdateWorldTransform=!1);for(var t=this._children,r=0,i=t.length;r<i;r++)t[r].update(e)},getBoundingBox:function(){function e(n){return!n.invisible&&n.geometry}var t=new ke,r=new z,i=new z;return function(n,a){return a=a||new ke,this._parent?z.invert(i,this._parent.worldTransform):z.identity(i),this.traverse(function(s){s.geometry&&s.geometry.boundingBox&&(t.copy(s.geometry.boundingBox),z.multiply(r,i,s.worldTransform),t.applyTransform(r),a.union(t))},this,e),a}}(),getWorldPosition:function(e){this.transformNeedsUpdate()&&this.updateWorldTransform();var t=this.worldTransform.array;if(e){var r=e.array;return r[0]=t[12],r[1]=t[13],r[2]=t[14],e}else return new P(t[12],t[13],t[14])},clone:function(){var e=new this.constructor,t=this._children;e.setName(this.name),e.position.copy(this.position),e.rotation.copy(this.rotation),e.scale.copy(this.scale);for(var r=0;r<t.length;r++)e.add(t[r].clone());return e},rotateAround:function(){var e=new P,t=new z;return function(r,i,n){e.copy(this.position).subtract(r);var a=this.localTransform;a.identity(),a.translate(r),a.rotate(n,i),t.fromRotationTranslation(this.rotation,e),a.multiply(t),a.scale(this.scale),this.decomposeLocalTransform(),this._needsUpdateWorldTransform=!0}}(),lookAt:function(){var e=new z;return function(t,r){e.lookAt(this.position,t,r||this.localTransform.y).invert(),this.setLocalTransform(e),this.target=t}}()});const dt=Xo;var Ke=dt.extend({material:null,geometry:null,mode:A.TRIANGLES,_renderInfo:null},{__program:null,lightGroup:0,renderOrder:0,culling:!0,cullFace:A.BACK,frontFace:A.CCW,frustumCulling:!0,receiveShadow:!0,castShadow:!0,ignorePicking:!1,ignorePreZ:!1,ignoreGBuffer:!1,isRenderable:function(){return this.geometry&&this.material&&this.material.shader&&!this.invisible&&this.geometry.vertexCount>0},beforeRender:function(e){},afterRender:function(e,t){},getBoundingBox:function(e,t){return t=dt.prototype.getBoundingBox.call(this,e,t),this.geometry&&this.geometry.boundingBox&&t.union(this.geometry.boundingBox),t},clone:function(){var e=["castShadow","receiveShadow","mode","culling","cullFace","frontFace","frustumCulling","renderOrder","lineWidth","ignorePicking","ignorePreZ","ignoreGBuffer"];return function(){var t=dt.prototype.clone.call(this);t.geometry=this.geometry,t.material=this.material;for(var r=0;r<e.length;r++){var i=e[r];t[i]!==this[i]&&(t[i]=this[i])}return t}}()});Ke.POINTS=A.POINTS;Ke.LINES=A.LINES;Ke.LINE_LOOP=A.LINE_LOOP;Ke.LINE_STRIP=A.LINE_STRIP;Ke.TRIANGLES=A.TRIANGLES;Ke.TRIANGLE_STRIP=A.TRIANGLE_STRIP;Ke.TRIANGLE_FAN=A.TRIANGLE_FAN;Ke.BACK=A.BACK;Ke.FRONT=A.FRONT;Ke.FRONT_AND_BACK=A.FRONT_AND_BACK;Ke.CW=A.CW;Ke.CCW=A.CCW;const zi=Ke;var Ki=qe.extend({scene:null,camera:null,renderer:null},function(){this._ray=new $r,this._ndc=new $e},{pick:function(e,t,r){var i=this.pickAll(e,t,[],r);return i[0]||null},pickAll:function(e,t,r,i){return this.renderer.screenToNDC(e,t,this._ndc),this.camera.castRay(this._ndc,this._ray),r=r||[],this._intersectNode(this.scene,r,i||!1),r.sort(this._intersectionCompareFunc),r},_intersectNode:function(e,t,r){e instanceof zi&&e.isRenderable()&&(!e.ignorePicking||r)&&(e.mode===A.TRIANGLES&&e.geometry.isUseIndices()||e.geometry.pickByRay||e.geometry.pick)&&this._intersectRenderable(e,t);for(var i=0;i<e._children.length;i++)this._intersectNode(e._children[i],t,r)},_intersectRenderable:function(){var e=new P,t=new P,r=new P,i=new $r,n=new z;return function(a,s){var o=a.isSkinnedMesh();i.copy(this._ray),z.invert(n,a.worldTransform),o||i.applyTransform(n);var l=a.geometry,c=o?a.skeleton.boundingBox:l.boundingBox;if(!(c&&!i.intersectBoundingBox(c))){if(l.pick){l.pick(this._ndc.x,this._ndc.y,this.renderer,this.camera,a,s);return}else if(l.pickByRay){l.pickByRay(i,a,s);return}var h=a.cullFace===A.BACK&&a.frontFace===A.CCW||a.cullFace===A.FRONT&&a.frontFace===A.CW,u,d=l.indices,f=l.attributes.position,v=l.attributes.weight,m=l.attributes.joint,p,_=[];if(!(!f||!f.value||!d)){if(o){p=a.skeleton.getSubSkinMatrices(a.__uid__,a.joints);for(var T=0;T<a.joints.length;T++){_[T]=_[T]||[];for(var y=0;y<16;y++)_[T][y]=p[T*16+y]}var g=[],E=[],S=[],R=[],b=[],M=l.attributes.skinnedPosition;(!M||!M.value)&&(l.createAttribute("skinnedPosition","f",3),M=l.attributes.skinnedPosition,M.init(l.vertexCount));for(var T=0;T<l.vertexCount;T++){f.get(T,g),v.get(T,E),m.get(T,S),E[3]=1-E[0]-E[1]-E[2],x.set(R,0,0,0);for(var y=0;y<4;y++)S[y]>=0&&E[y]>1e-4&&(x.transformMat4(b,g,_[S[y]]),x.scaleAndAdd(R,R,b,E[y]));M.set(T,R)}}for(var T=0;T<d.length;T+=3){var F=d[T],w=d[T+1],U=d[T+2],O=o?l.attributes.skinnedPosition:f;if(O.get(F,e.array),O.get(w,t.array),O.get(U,r.array),h?u=i.intersectTriangle(e,t,r,a.culling):u=i.intersectTriangle(e,r,t,a.culling),u){var L=new P;o?P.copy(L,u):P.transformMat4(L,u,a.worldTransform),s.push(new Ki.Intersection(u,L,a,[F,w,U],T/3,P.dist(L,this._ray.origin)))}}}}}}(),_intersectionCompareFunc:function(e,t){return e.distance-t.distance}});Ki.Intersection=function(e,t,r,i,n,a){this.point=e,this.pointWorld=t,this.target=r,this.triangle=i,this.triangleIndex=n,this.distance=a};const jo=Ki;var sr="__dt__",Kr=function(){this._contextId=0,this._caches=[],this._context={}};Kr.prototype={use:function(e,t){var r=this._caches;r[e]||(r[e]={},t&&(r[e]=t())),this._contextId=e,this._context=r[e]},put:function(e,t){this._context[e]=t},get:function(e){return this._context[e]},dirty:function(e){e=e||"";var t=sr+e;this.put(t,!0)},dirtyAll:function(e){e=e||"";for(var t=sr+e,r=this._caches,i=0;i<r.length;i++)r[i]&&(r[i][t]=!0)},fresh:function(e){e=e||"";var t=sr+e;this.put(t,!1)},freshAll:function(e){e=e||"";for(var t=sr+e,r=this._caches,i=0;i<r.length;i++)r[i]&&(r[i][t]=!1)},isDirty:function(e){e=e||"";var t=sr+e,r=this._context;return!r.hasOwnProperty(t)||r[t]===!0},deleteContext:function(e){delete this._caches[e],this._context={}},delete:function(e){delete this._context[e]},clearAll:function(){this._caches={}},getContext:function(){return this._context},eachContext:function(e,t){var r=Object.keys(this._caches);r.forEach(function(i){e&&e.call(t,i)})},miss:function(e){return!this._context.hasOwnProperty(e)}};Kr.prototype.constructor=Kr;const Qi=Kr;var te=qe.extend({width:512,height:512,type:A.UNSIGNED_BYTE,format:A.RGBA,wrapS:A.REPEAT,wrapT:A.REPEAT,minFilter:A.LINEAR_MIPMAP_LINEAR,magFilter:A.LINEAR,useMipmap:!0,anisotropic:1,flipY:!0,sRGB:!0,unpackAlignment:4,premultiplyAlpha:!1,dynamic:!1,NPOT:!1,__used:0},function(){this._cache=new Qi},{getWebGLTexture:function(e){var t=e.gl,r=this._cache;return r.use(e.__uid__),r.miss("webgl_texture")&&r.put("webgl_texture",t.createTexture()),this.dynamic?this.update(e):r.isDirty()&&(this.update(e),r.fresh()),r.get("webgl_texture")},bind:function(){},unbind:function(){},dirty:function(){this._cache&&this._cache.dirtyAll()},update:function(e){},updateCommon:function(e){var t=e.gl;t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,this.flipY),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this.premultiplyAlpha),t.pixelStorei(t.UNPACK_ALIGNMENT,this.unpackAlignment),this.format===A.DEPTH_COMPONENT&&(this.useMipmap=!1);var r=e.getGLExtension("EXT_sRGB");this.format===te.SRGB&&!r&&(this.format=te.RGB),this.format===te.SRGB_ALPHA&&!r&&(this.format=te.RGBA),this.NPOT=!this.isPowerOfTwo()},getAvailableWrapS:function(){return this.NPOT?A.CLAMP_TO_EDGE:this.wrapS},getAvailableWrapT:function(){return this.NPOT?A.CLAMP_TO_EDGE:this.wrapT},getAvailableMinFilter:function(){var e=this.minFilter;return this.NPOT||!this.useMipmap?e===A.NEAREST_MIPMAP_NEAREST||e===A.NEAREST_MIPMAP_LINEAR?A.NEAREST:e===A.LINEAR_MIPMAP_LINEAR||e===A.LINEAR_MIPMAP_NEAREST?A.LINEAR:e:e},getAvailableMagFilter:function(){return this.magFilter},nextHighestPowerOfTwo:function(e){--e;for(var t=1;t<32;t<<=1)e=e|e>>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(te.prototype,"width",{get:function(){return this._width},set:function(e){this._width=e}});Object.defineProperty(te.prototype,"height",{get:function(){return this._height},set:function(e){this._height=e}});te.BYTE=A.BYTE;te.UNSIGNED_BYTE=A.UNSIGNED_BYTE;te.SHORT=A.SHORT;te.UNSIGNED_SHORT=A.UNSIGNED_SHORT;te.INT=A.INT;te.UNSIGNED_INT=A.UNSIGNED_INT;te.FLOAT=A.FLOAT;te.HALF_FLOAT=36193;te.UNSIGNED_INT_24_8_WEBGL=34042;te.DEPTH_COMPONENT=A.DEPTH_COMPONENT;te.DEPTH_STENCIL=A.DEPTH_STENCIL;te.ALPHA=A.ALPHA;te.RGB=A.RGB;te.RGBA=A.RGBA;te.LUMINANCE=A.LUMINANCE;te.LUMINANCE_ALPHA=A.LUMINANCE_ALPHA;te.SRGB=35904;te.SRGB_ALPHA=35906;te.COMPRESSED_RGB_S3TC_DXT1_EXT=33776;te.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777;te.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778;te.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779;te.NEAREST=A.NEAREST;te.LINEAR=A.LINEAR;te.NEAREST_MIPMAP_NEAREST=A.NEAREST_MIPMAP_NEAREST;te.LINEAR_MIPMAP_NEAREST=A.LINEAR_MIPMAP_NEAREST;te.NEAREST_MIPMAP_LINEAR=A.NEAREST_MIPMAP_LINEAR;te.LINEAR_MIPMAP_LINEAR=A.LINEAR_MIPMAP_LINEAR;te.REPEAT=A.REPEAT;te.CLAMP_TO_EDGE=A.CLAMP_TO_EDGE;te.MIRRORED_REPEAT=A.MIRRORED_REPEAT;const q=te;var Qe=zi.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=zi.prototype.clone.call(this);return e.skeleton=this.skeleton,this.joints&&(e.joints=this.joints.slice()),e}});Qe.POINTS=A.POINTS;Qe.LINES=A.LINES;Qe.LINE_LOOP=A.LINE_LOOP;Qe.LINE_STRIP=A.LINE_STRIP;Qe.TRIANGLES=A.TRIANGLES;Qe.TRIANGLE_STRIP=A.TRIANGLE_STRIP;Qe.TRIANGLE_FAN=A.TRIANGLE_FAN;Qe.BACK=A.BACK;Qe.FRONT=A.FRONT;Qe.FRONT_AND_BACK=A.FRONT_AND_BACK;Qe.CW=A.CW;Qe.CCW=A.CCW;const Ji=Qe;var si={};si.isPowerOfTwo=function(e){return(e&e-1)===0};si.nextPowerOfTwo=function(e){return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e};si.nearestPowerOfTwo=function(e){return Math.pow(2,Math.round(Math.log(e)/Math.LN2))};const wa=si;var Un=wa.isPowerOfTwo;function Hn(e){return Math.pow(2,Math.round(Math.log(e)/Math.LN2))}function Yo(e,t){var r=Hn(e.width),i=Hn(e.height);t=t||document.createElement("canvas"),t.width=r,t.height=i;var n=t.getContext("2d");return n.drawImage(e.image,0,0,r,i),t}var en=q.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===q.REPEAT||this.wrapT===q.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),i===36193){var s=e.getGLExtension("OES_texture_half_float");s||(i=A.FLOAT)}if(this.mipmaps.length)for(var o=this.width,l=this.height,c=0;c<this.mipmaps.length;c++){var h=this.mipmaps[c];this._updateTextureData(t,h,c,o,l,r,i,!1),o/=2,l/=2}else this._updateTextureData(t,this,0,this.width,this.height,r,i,n),this.useMipmap&&(!this.NPOT||n)&&t.generateMipmap(t.TEXTURE_2D);t.bindTexture(t.TEXTURE_2D,null)},_updateTextureData:function(e,t,r,i,n,a,s,o){if(t.image){var l=t.image;o&&(this._potCanvas=Yo(this,this._potCanvas),l=this._potCanvas),e.texImage2D(e.TEXTURE_2D,r,a,a,s,l)}else a<=q.COMPRESSED_RGBA_S3TC_DXT5_EXT&&a>=q.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,s,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 Un(this.width)&&Un(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=be.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(en.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(en.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 ne=en;function Ca(e){return{byte:be.Int8Array,ubyte:be.Uint8Array,short:be.Int16Array,ushort:be.Uint16Array}[e]||be.Float32Array}function Ei(e){return"attr_"+e}function er(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(n){return this.value[n]},this.set=function(n,a){this.value[n]=a},this.copy=function(n,a){this.value[n]=this.value[n]};break;case 2:this.get=function(n,a){var s=this.value;return a[0]=s[n*2],a[1]=s[n*2+1],a},this.set=function(n,a){var s=this.value;s[n*2]=a[0],s[n*2+1]=a[1]},this.copy=function(n,a){var s=this.value;a*=2,n*=2,s[n]=s[a],s[n+1]=s[a+1]};break;case 3:this.get=function(n,a){var s=n*3,o=this.value;return a[0]=o[s],a[1]=o[s+1],a[2]=o[s+2],a},this.set=function(n,a){var s=n*3,o=this.value;o[s]=a[0],o[s+1]=a[1],o[s+2]=a[2]},this.copy=function(n,a){var s=this.value;a*=3,n*=3,s[n]=s[a],s[n+1]=s[a+1],s[n+2]=s[a+2]};break;case 4:this.get=function(n,a){var s=this.value,o=n*4;return a[0]=s[o],a[1]=s[o+1],a[2]=s[o+2],a[3]=s[o+3],a},this.set=function(n,a){var s=this.value,o=n*4;s[o]=a[0],s[o+1]=a[1],s[o+2]=a[2],s[o+3]=a[3]},this.copy=function(n,a){var s=this.value;a*=4,n*=4,s[n]=s[a],s[n+1]=s[a+1],s[n+2]=s[a+2],s[n+3]=s[a+3]}}}er.prototype.init=function(e){if(!this.value||this.value.length!==e*this.size){var t=Ca(this.type);this.value=new t(e*this.size)}};er.prototype.fromArray=function(e){var t=Ca(this.type),r;if(e[0]&&e[0].length){var i=0,n=this.size;r=new t(e.length*n);for(var a=0;a<e.length;a++)for(var s=0;s<n;s++)r[i++]=e[a][s]}else r=new t(e);this.value=r};er.prototype.clone=function(e){var t=new er(this.name,this.type,this.size,this.semantic);return e&&console.warn("todo"),t};function Ra(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 Ma(e){this.buffer=e,this.count=0}var gt=qe.extend(function(){return{attributes:{},indices:null,dynamic:!0,_enabledAttributes:null,__used:0}},function(){this._cache=new Qi,this._attributeList=Object.keys(this.attributes),this.__vaoCache={}},{mainAttribute:"",pick:null,pickByRay:null,dirty:function(){for(var e=this.getEnabledAttributes(),t=0;t<e.length;t++)this.dirtyAttribute(e[t]);this.dirtyIndices(),this._enabledAttributes=null,this._cache.dirty("any")},dirtyIndices:function(){this._cache.dirtyAll("indices")},dirtyAttribute:function(e){this._cache.dirtyAll(Ei(e)),this._cache.dirtyAll("attributes")},getTriangleIndices:function(e,t){if(e<this.triangleCount&&e>=0){t||(t=[]);var r=this.indices;return t[0]=r[e*3],t[1]=r[e*3+1],t[2]=r[e*3+2],t}},setTriangleIndices:function(e,t){var r=this.indices;r[e*3]=t[0],r[e*3+1]=t[1],r[e*3+2]=t[2]},isUseIndices:function(){return!!this.indices},initIndicesFromArray:function(e){var t,r=this.vertexCount>65535?be.Uint32Array:be.Uint16Array;if(e[0]&&e[0].length){var i=0,n=3;t=new r(e.length*n);for(var a=0;a<e.length;a++)for(var s=0;s<n;s++)t[i++]=e[a][s]}else t=new r(e);this.indices=t},createAttribute:function(e,t,r,i){var n=new er(e,t,r,i);return this.attributes[e]&&this.removeAttribute(e),this.attributes[e]=n,this._attributeList.push(e),n},removeAttribute:function(e){var t=this._attributeList,r=t.indexOf(e);return r>=0?(t.splice(r,1),delete this.attributes[e],!0):!1},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;n<t.length;n++){var a=t[n],s=this.attributes[a];s.value&&s.value.length===i*s.size&&r.push(a)}return this._enabledAttributes=r,r},getBufferChunks:function(e){var t=this._cache;t.use(e.__uid__);var r=t.isDirty("attributes"),i=t.isDirty("indices");if(r||i){this._updateBuffer(e.gl,r,i);for(var n=this.getEnabledAttributes(),a=0;a<n.length;a++)t.fresh(Ei(n[a]));t.fresh("attributes"),t.fresh("indices")}return t.fresh("any"),t.get("chunks")},_updateBuffer:function(e,t,r){var i=this._cache,n=i.get("chunks"),a=!1;n||(n=[],n[0]={attributeBuffers:[],indicesBuffer:null},i.put("chunks",n),a=!0);var s=n[0],o=s.attributeBuffers,l=s.indicesBuffer;if(t||a){var c=this.getEnabledAttributes(),h={};if(!a)for(var u=0;u<o.length;u++)h[o[u].name]=o[u];for(var d=0;d<c.length;d++){var f=c[d],v=this.attributes[f],m;a||(m=h[f]);var p;m?p=m.buffer:p=e.createBuffer(),i.isDirty(Ei(f))&&(e.bindBuffer(e.ARRAY_BUFFER,p),e.bufferData(e.ARRAY_BUFFER,v.value,this.dynamic?e.DYNAMIC_DRAW:e.STATIC_DRAW)),o[d]=new Ra(f,v.type,p,v.size,v.semantic)}for(var u=d;u<o.length;u++)e.deleteBuffer(o[u].buffer);o.length=d}this.isUseIndices()&&(r||a)&&(l||(l=new Ma(e.createBuffer()),s.indicesBuffer=l),l.count=this.indices.length,e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,l.buffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,this.indices,this.dynamic?e.DYNAMIC_DRAW:e.STATIC_DRAW))},dispose:function(e){var t=this._cache;t.use(e.__uid__);var r=t.get("chunks");if(r)for(var i=0;i<r.length;i++){for(var n=r[i],a=0;a<n.attributeBuffers.length;a++){var s=n.attributeBuffers[a];e.gl.deleteBuffer(s.buffer)}n.indicesBuffer&&e.gl.deleteBuffer(n.indicesBuffer.buffer)}if(this.__vaoCache){var o=e.getGLExtension("OES_vertex_array_object");for(var l in this.__vaoCache){var c=this.__vaoCache[l].vao;c&&o.deleteVertexArrayOES(c)}}this.__vaoCache={},t.deleteContext(e.__uid__)}});Object.defineProperty&&(Object.defineProperty(gt.prototype,"vertexCount",{enumerable:!1,get:function(){var e=this.attributes[this.mainAttribute];return e||(e=this.attributes[this._attributeList[0]]),!e||!e.value?0:e.value.length/e.size}}),Object.defineProperty(gt.prototype,"triangleCount",{enumerable:!1,get:function(){var e=this.indices;return e?e.length/3:0}}));gt.STATIC_DRAW=A.STATIC_DRAW;gt.DYNAMIC_DRAW=A.DYNAMIC_DRAW;gt.STREAM_DRAW=A.STREAM_DRAW;gt.AttributeBuffer=Ra;gt.IndicesBuffer=Ma;gt.Attribute=er;const Ht=gt;var Ge=x.create,jt=x.add,Rt=x.set,ut=Ht.Attribute,zt=Ht.extend(function(){return{attributes:{position:new ut("position","float",3,"POSITION"),texcoord0:new ut("texcoord0","float",2,"TEXCOORD_0"),texcoord1:new ut("texcoord1","float",2,"TEXCOORD_1"),normal:new ut("normal","float",3,"NORMAL"),tangent:new ut("tangent","float",4,"TANGENT"),color:new ut("color","float",4,"COLOR"),weight:new ut("weight","float",3,"WEIGHT"),joint:new ut("joint","float",4,"JOINT"),barycentric:new ut("barycentric","float",3,null)},boundingBox:null}},{mainAttribute:"position",updateBoundingBox:function(){var e=this.boundingBox;e||(e=this.boundingBox=new ke);var t=this.attributes.position.value;if(t&&t.length){var r=e.min,i=e.max,n=r.array,a=i.array;x.set(n,t[0],t[1],t[2]),x.set(a,t[0],t[1],t[2]);for(var s=3;s<t.length;){var o=t[s++],l=t[s++],c=t[s++];o<n[0]&&(n[0]=o),l<n[1]&&(n[1]=l),c<n[2]&&(n[2]=c),o>a[0]&&(a[0]=o),l>a[1]&&(a[1]=l),c>a[2]&&(a[2]=c)}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)i=t.normal.value=new be.Float32Array(r.length);else for(var n=0;n<i.length;n++)i[n]=0;for(var a=Ge(),s=Ge(),o=Ge(),l=Ge(),c=Ge(),h=Ge(),u=e?e.length:this.vertexCount,d,f,v,m=0;m<u;){e?(d=e[m++],f=e[m++],v=e[m++]):(d=m++,f=m++,v=m++),Rt(a,r[d*3],r[d*3+1],r[d*3+2]),Rt(s,r[f*3],r[f*3+1],r[f*3+2]),Rt(o,r[v*3],r[v*3+1],r[v*3+2]),x.sub(l,a,s),x.sub(c,s,o),x.cross(h,l,c);for(var n=0;n<3;n++)i[d*3+n]=i[d*3+n]+h[n],i[f*3+n]=i[f*3+n]+h[n],i[v*3+n]=i[v*3+n]+h[n]}for(var n=0;n<i.length;)Rt(h,i[n],i[n+1],i[n+2]),x.normalize(h,h),i[n++]=h[0],i[n++]=h[1],i[n++]=h[2];this.dirty()}},generateFaceNormals:function(){if(this.vertexCount){this.isUniqueVertex()||this.generateUniqueVertex();var e=this.indices,t=this.attributes,r=t.position.value,i=t.normal.value,n=Ge(),a=Ge(),s=Ge(),o=Ge(),l=Ge(),c=Ge();i||(i=t.normal.value=new Float32Array(r.length));for(var h=e?e.length:this.vertexCount,u,d,f,v=0;v<h;){e?(u=e[v++],d=e[v++],f=e[v++]):(u=v++,d=v++,f=v++),Rt(n,r[u*3],r[u*3+1],r[u*3+2]),Rt(a,r[d*3],r[d*3+1],r[d*3+2]),Rt(s,r[f*3],r[f*3+1],r[f*3+2]),x.sub(o,n,a),x.sub(l,a,s),x.cross(c,o,l),x.normalize(c,c);for(var m=0;m<3;m++)i[u*3+m]=c[m],i[d*3+m]=c[m],i[f*3+m]=c[m]}this.dirty()}},generateTangents:function(){if(this.vertexCount){var e=this.vertexCount,t=this.attributes;t.tangent.value||(t.tangent.value=new Float32Array(e*4));var r=t.texcoord0.value,i=t.position.value,n=t.tangent.value,a=t.normal.value;if(!r){console.warn("Geometry without texcoords can't generate tangents.");return}for(var s=[],o=[],l=0;l<e;l++)s[l]=[0,0,0],o[l]=[0,0,0];for(var c=[0,0,0],h=[0,0,0],u=this.indices,d=u?u.length:this.vertexCount,f,v,m,l=0;l<d;){u?(f=u[l++],v=u[l++],m=u[l++]):(f=l++,v=l++,m=l++);var p=r[f*2],_=r[v*2],T=r[m*2],y=r[f*2+1],g=r[v*2+1],E=r[m*2+1],S=i[f*3],R=i[v*3],b=i[m*3],M=i[f*3+1],F=i[v*3+1],w=i[m*3+1],U=i[f*3+2],O=i[v*3+2],L=i[m*3+2],G=R-S,B=b-S,Z=F-M,I=w-M,ue=O-U,k=L-U,ye=_-p,ae=T-p,ve=g-y,me=E-y,Oe=1/(ye*me-ve*ae);c[0]=(me*G-ve*B)*Oe,c[1]=(me*Z-ve*I)*Oe,c[2]=(me*ue-ve*k)*Oe,h[0]=(ye*B-ae*G)*Oe,h[1]=(ye*I-ae*Z)*Oe,h[2]=(ye*k-ae*ue)*Oe,jt(s[f],s[f],c),jt(s[v],s[v],c),jt(s[m],s[m],c),jt(o[f],o[f],h),jt(o[v],o[v],h),jt(o[m],o[m],h)}for(var Be=Ge(),Re=Ge(),ze=Ge(),l=0;l<e;l++){ze[0]=a[l*3],ze[1]=a[l*3+1],ze[2]=a[l*3+2];var Ze=s[l];x.scale(Be,ze,x.dot(ze,Ze)),x.sub(Be,Ze,Be),x.normalize(Be,Be),x.cross(Re,ze,Ze),n[l*4]=Be[0],n[l*4+1]=Be[1],n[l*4+2]=Be[2],n[l*4+3]=x.dot(Re,o[l])<0?-1:1}this.dirty()}},isUniqueVertex:function(){return this.isUseIndices()?this.vertexCount===this.indices.length:!0},generateUniqueVertex:function(){if(!(!this.vertexCount||!this.indices)){this.indices.length>65535&&(this.indices=new be.Uint32Array(this.indices));for(var e=this.attributes,t=this.indices,r=this.getEnabledAttributes(),i={},n=0;n<r.length;n++){var a=r[n];i[a]=e[a].value,e[a].init(this.indices.length)}for(var s=0,o=0;o<t.length;o++){for(var l=t[o],n=0;n<r.length;n++)for(var a=r[n],c=e[a].value,h=e[a].size,u=0;u<h;u++)c[s*h+u]=i[a][l*h+u];t[o]=s,s++}this.dirty()}},generateBarycentric:function(){if(this.vertexCount){this.isUniqueVertex()||this.generateUniqueVertex();var e=this.attributes,t=e.barycentric.value,r=this.indices;if(!(t&&t.length===r.length*3)){t=e.barycentric.value=new Float32Array(r.length*3);for(var i=0;i<(r?r.length:this.vertexCount/3);)for(var n=0;n<3;n++){var a=r?r[i++]:i*3+n;t[a*3+n]=1}this.dirty()}}},applyTransform:function(e){var t=this.attributes,r=t.position.value,i=t.normal.value,n=t.tangent.value;e=e.array;var a=C.create();C.invert(a,e),C.transpose(a,a);var s=x.transformMat4,o=x.forEach;o(r,3,0,null,s,e),i&&o(i,3,0,null,s,a),n&&o(n,4,0,null,s,a),this.boundingBox&&this.updateBoundingBox()},dispose:function(e){var t=this._cache;t.use(e.__uid__);var r=t.get("chunks");if(r)for(var i=0;i<r.length;i++){for(var n=r[i],a=0;a<n.attributeBuffers.length;a++){var s=n.attributeBuffers[a];e.gl.deleteBuffer(s.buffer)}n.indicesBuffer&&e.gl.deleteBuffer(n.indicesBuffer.buffer)}if(this.__vaoCache){var o=e.getGLExtension("OES_vertex_array_object");for(var l in this.__vaoCache){var c=this.__vaoCache[l].vao;c&&o.deleteVertexArrayOES(c)}}this.__vaoCache={},t.deleteContext(e.__uid__)}});zt.STATIC_DRAW=Ht.STATIC_DRAW;zt.DYNAMIC_DRAW=Ht.DYNAMIC_DRAW;zt.STREAM_DRAW=Ht.STREAM_DRAW;zt.AttributeBuffer=Ht.AttributeBuffer;zt.IndicesBuffer=Ht.IndicesBuffer;zt.Attribute=ut;const Ae=zt,qo="vec3 calcAmbientSHLight(int idx, vec3 N) {\n int offset = 9 * idx;\n return ambientSHLightCoefficients[0]\n + ambientSHLightCoefficients[1] * N.x\n + ambientSHLightCoefficients[2] * N.y\n + ambientSHLightCoefficients[3] * N.z\n + ambientSHLightCoefficients[4] * N.x * N.z\n + ambientSHLightCoefficients[5] * N.z * N.y\n + ambientSHLightCoefficients[6] * N.y * N.x\n + ambientSHLightCoefficients[7] * (3.0 * N.z * N.z - 1.0)\n + ambientSHLightCoefficients[8] * (N.x * N.x - N.y * N.y);\n}";var at="uniform vec3 ",or="uniform float ",Yt="@export clay.header.",qt="@end",Pe=":unconfigurable;";const Zo=[Yt+"directional_light",at+"directionalLightDirection[DIRECTIONAL_LIGHT_COUNT]"+Pe,at+"directionalLightColor[DIRECTIONAL_LIGHT_COUNT]"+Pe,qt,Yt+"ambient_light",at+"ambientLightColor[AMBIENT_LIGHT_COUNT]"+Pe,qt,Yt+"ambient_sh_light",at+"ambientSHLightColor[AMBIENT_SH_LIGHT_COUNT]"+Pe,at+"ambientSHLightCoefficients[AMBIENT_SH_LIGHT_COUNT * 9]"+Pe,qo,qt,Yt+"ambient_cubemap_light",at+"ambientCubemapLightColor[AMBIENT_CUBEMAP_LIGHT_COUNT]"+Pe,"uniform samplerCube ambientCubemapLightCubemap[AMBIENT_CUBEMAP_LIGHT_COUNT]"+Pe,"uniform sampler2D ambientCubemapLightBRDFLookup[AMBIENT_CUBEMAP_LIGHT_COUNT]"+Pe,qt,Yt+"point_light",at+"pointLightPosition[POINT_LIGHT_COUNT]"+Pe,or+"pointLightRange[POINT_LIGHT_COUNT]"+Pe,at+"pointLightColor[POINT_LIGHT_COUNT]"+Pe,qt,Yt+"spot_light",at+"spotLightPosition[SPOT_LIGHT_COUNT]"+Pe,at+"spotLightDirection[SPOT_LIGHT_COUNT]"+Pe,or+"spotLightRange[SPOT_LIGHT_COUNT]"+Pe,or+"spotLightUmbraAngleCosine[SPOT_LIGHT_COUNT]"+Pe,or+"spotLightPenumbraAngleCosine[SPOT_LIGHT_COUNT]"+Pe,or+"spotLightFalloffFactor[SPOT_LIGHT_COUNT]"+Pe,at+"spotLightColor[SPOT_LIGHT_COUNT]"+Pe,qt].join("\n");N.import(Zo);var $o=dt.extend(function(){return{color:[1,1,1],intensity:1,castShadow:!0,shadowResolution:512,group:0}},{type:"",clone:function(){var e=dt.prototype.clone.call(this);return e.color=Array.prototype.slice.call(this.color),e.intensity=this.intensity,e.castShadow=this.castShadow,e.shadowResolution=this.shadowResolution,e}});const lt=$o;var jr=function(e,t){this.normal=e||new P(0,1,0),this.distance=t||0};jr.prototype={constructor:jr,distanceToPoint:function(e){return x.dot(e.array,this.normal.array)-this.distance},projectPoint:function(e,t){t||(t=new P);var r=this.distanceToPoint(e);return x.scaleAndAdd(t.array,e.array,this.normal.array,-r),t._dirty=!0,t},normalize:function(){var e=1/x.len(this.normal.array);x.scale(this.normal.array,e),this.distance*=e},intersectFrustum:function(e){for(var t=e.vertices,r=this.normal.array,i=x.dot(t[0].array,r)>this.distance,n=1;n<8;n++)if(x.dot(t[n].array,r)>this.distance!=i)return!0},intersectLine:function(){var e=x.create();return function(t,r,i){var n=this.distanceToPoint(t),a=this.distanceToPoint(r);if(n>0&&a>0||n<0&&a<0)return null;var s=this.normal.array,o=this.distance,l=t.array;x.sub(e,r.array,t.array),x.normalize(e,e);var c=x.dot(s,e);if(c===0)return null;i||(i=new P);var h=(x.dot(s,l)-o)/c;return x.scaleAndAdd(i.array,l,e,-h),i._dirty=!0,i}}(),applyTransform:function(){var e=C.create(),t=D.create(),r=D.create();return r[3]=1,function(i){i=i.array,x.scale(r,this.normal.array,this.distance),D.transformMat4(r,r,i),this.distance=x.dot(r,this.normal.array),C.invert(e,i),C.transpose(e,e),t[3]=0,x.copy(t,this.normal.array),D.transformMat4(t,t,e),x.copy(this.normal.array,t)}}(),copy:function(e){x.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 Na=jr;var Ee=x.set,zn=x.copy,Gn=x.transformMat4,Ai=Math.min,Si=Math.max,La=function(){this.planes=[];for(var e=0;e<6;e++)this.planes.push(new Na);this.boundingBox=new ke,this.vertices=[];for(var e=0;e<8;e++)this.vertices[e]=x.fromValues(0,0,0)};La.prototype={setFromProjection:function(e){var t=this.planes,r=e.array,i=r[0],n=r[1],a=r[2],s=r[3],o=r[4],l=r[5],c=r[6],h=r[7],u=r[8],d=r[9],f=r[10],v=r[11],m=r[12],p=r[13],_=r[14],T=r[15];Ee(t[0].normal.array,s-i,h-o,v-u),t[0].distance=-(T-m),t[0].normalize(),Ee(t[1].normal.array,s+i,h+o,v+u),t[1].distance=-(T+m),t[1].normalize(),Ee(t[2].normal.array,s+n,h+l,v+d),t[2].distance=-(T+p),t[2].normalize(),Ee(t[3].normal.array,s-n,h-l,v-d),t[3].distance=-(T-p),t[3].normalize(),Ee(t[4].normal.array,s-a,h-c,v-f),t[4].distance=-(T-_),t[4].normalize(),Ee(t[5].normal.array,s+a,h+c,v+f),t[5].distance=-(T+_),t[5].normalize();var y=this.boundingBox,g=this.vertices;if(T===0){var E=l/i,S=-_/(f-1),R=-_/(f+1),b=-R/l,M=-S/l;y.min.set(-b*E,-b,R),y.max.set(b*E,b,S),Ee(g[0],-b*E,-b,R),Ee(g[1],-b*E,b,R),Ee(g[2],b*E,-b,R),Ee(g[3],b*E,b,R),Ee(g[4],-M*E,-M,S),Ee(g[5],-M*E,M,S),Ee(g[6],M*E,-M,S),Ee(g[7],M*E,M,S)}else{var F=(-1-m)/i,w=(1-m)/i,U=(1-p)/l,O=(-1-p)/l,L=(-1-_)/f,G=(1-_)/f;y.min.set(Math.min(F,w),Math.min(O,U),Math.min(G,L)),y.max.set(Math.max(w,F),Math.max(U,O),Math.max(L,G));var B=y.min.array,Z=y.max.array;Ee(g[0],B[0],B[1],B[2]),Ee(g[1],B[0],Z[1],B[2]),Ee(g[2],Z[0],B[1],B[2]),Ee(g[3],Z[0],Z[1],B[2]),Ee(g[4],B[0],B[1],Z[2]),Ee(g[5],B[0],Z[1],Z[2]),Ee(g[6],Z[0],B[1],Z[2]),Ee(g[7],Z[0],Z[1],Z[2])}},getTransformedBoundingBox:function(){var e=x.create();return function(t,r){var i=this.vertices,n=r.array,a=t.min,s=t.max,o=a.array,l=s.array,c=i[0];Gn(e,c,n),zn(o,e),zn(l,e);for(var h=1;h<8;h++)c=i[h],Gn(e,c,n),o[0]=Ai(e[0],o[0]),o[1]=Ai(e[1],o[1]),o[2]=Ai(e[2],o[2]),l[0]=Si(e[0],l[0]),l[1]=Si(e[1],l[1]),l[2]=Si(e[2],l[2]);return a._dirty=!0,s._dirty=!0,t}}()};const tn=La;var Ko=dt.extend(function(){return{projectionMatrix:new z,invProjectionMatrix:new z,viewMatrix:new z,frustum:new tn}},function(){this.update(!0)},{update:function(e){dt.prototype.update.call(this,e),z.invert(this.viewMatrix,this.worldTransform),this.updateProjectionMatrix(),z.invert(this.invProjectionMatrix,this.projectionMatrix),this.frustum.setFromProjection(this.projectionMatrix)},setViewMatrix:function(e){z.copy(this.viewMatrix,e),z.invert(this.worldTransform,e),this.decomposeWorldTransform()},decomposeProjectionMatrix:function(){},setProjectionMatrix:function(e){z.copy(this.projectionMatrix,e),z.invert(this.invProjectionMatrix,e),this.decomposeProjectionMatrix()},updateProjectionMatrix:function(){},castRay:function(){var e=D.create();return function(t,r){var i=r!==void 0?r:new $r,n=t.array[0],a=t.array[1];return D.set(e,n,a,-1,1),D.transformMat4(e,e,this.invProjectionMatrix.array),D.transformMat4(e,e,this.worldTransform.array),x.scale(i.origin.array,e,1/e[3]),D.set(e,n,a,1,1),D.transformMat4(e,e,this.invProjectionMatrix.array),D.transformMat4(e,e,this.worldTransform.array),x.scale(e,e,1/e[3]),x.sub(i.direction.array,e,i.origin.array),x.normalize(i.direction.array,i.direction.array),i.direction._dirty=!0,i.origin._dirty=!0,i}}()});const tr=Ko;var Qo=C.create(),kn=C.create(),bi={};function Jo(e){var t=[],r=Object.keys(e);r.sort();for(var i=0;i<r.length;i++){var n=r[i];t.push(n+" "+e[n])}var a=t.join("\n");if(bi[a])return bi[a];var s=De.genGUID();return bi[a]=s,s}function oi(){this.opaque=[],this.transparent=[],this._opaqueCount=0,this._transparentCount=0}oi.prototype.startCount=function(){this._opaqueCount=0,this._transparentCount=0};oi.prototype.add=function(e,t){t?this.transparent[this._transparentCount++]=e:this.opaque[this._opaqueCount++]=e};oi.prototype.endCount=function(){this.transparent.length=this._transparentCount,this.opaque.length=this._opaqueCount};var el=dt.extend(function(){return{material:null,lights:[],viewBoundingBoxLastFrame:new ke,shadowUniforms:{},_cameraList:[],_lightUniforms:{},_previousLightNumber:{},_lightNumber:{},_lightProgramKeys:{},_nodeRepository:{},_renderLists:new ga(20)}},function(){this._scene=this},{addToScene:function(e){e instanceof tr?(this._cameraList.length>0&&console.warn("Found multiple camera in one scene. Use the fist one."),this._cameraList.push(e)):e instanceof lt&&this.lights.push(e),e.name&&(this._nodeRepository[e.name]=e)},removeFromScene:function(e){var t;e instanceof tr?(t=this._cameraList.indexOf(e),t>=0&&this._cameraList.splice(t,1)):e instanceof lt&&(t=this.lights.indexOf(e),t>=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;r<e.length;r++){var i=e[r];if(!i.invisible){var n=i.group;t[n]||(t[n]={}),t[n][i.type]=t[n][i.type]||0,t[n][i.type]++}}this._lightNumber=t;for(var a in t)this._lightProgramKeys[a]=Jo(t[a]);this._updateLightUniforms()},cloneNode:function(e){var t=e.clone(),r={};function i(n,a){r[n.__uid__]=a;for(var s=0;s<n._children.length;s++){var o=n._children[s],l=a._children[s];i(o,l)}}return i(e,t),t.traverse(function(n){n.skeleton&&(n.skeleton=n.skeleton.clone(r)),n.material&&(n.material=n.material.clone())}),t},updateRenderList:function(e,t){var r=e.__uid__,i=this._renderLists.get(r);i||(i=new oi,this._renderLists.put(r,i)),i.startCount(),t&&(this.viewBoundingBoxLastFrame.min.set(1/0,1/0,1/0),this.viewBoundingBoxLastFrame.max.set(-1/0,-1/0,-1/0));var n=this.material&&this.material.transparent||!1;return this._doUpdateRenderList(this,e,n,i,t),i.endCount(),i},getRenderList:function(e){return this._renderLists.get(e.__uid__)},_doUpdateRenderList:function(e,t,r,i,n){if(!e.invisible)for(var a=0;a<e._children.length;a++){var s=e._children[a];if(s.isRenderable()){var o=s.isSkinnedMesh()?Qo:s.worldTransform.array,l=s.geometry;C.multiplyAffine(kn,t.viewMatrix.array,o),(n&&!l.boundingBox||!this.isFrustumCulled(s,t,kn))&&i.add(s,s.material.transparent||r)}s._children.length>0&&this._doUpdateRenderList(s,t,r,i,n)}},isFrustumCulled:function(){var e=new ke,t=new z;return function(r,i,n){var a=r.boundingBox;if(a||(r.skeleton&&r.skeleton.boundingBox?a=r.skeleton.boundingBox:a=r.geometry.boundingBox),!a)return!1;if(t.array=n,e.transformFrom(a,t),r.castShadow&&this.viewBoundingBoxLastFrame.union(e),r.frustumCulling){if(!e.intersectBoundingBox(i.frustum.boundingBox))return!0;t.array=i.projectionMatrix.array,e.max.array[2]>0&&e.min.array[2]<0&&(e.max.array[2]=-1e-20),e.applyProjection(t);var s=e.min.array,o=e.max.array;if(o[0]<-1||s[0]>1||o[1]<-1||s[1]>1||o[2]<-1||s[2]>1)return!0}return!1}}(),_updateLightUniforms:function(){var e=this.lights;e.sort(tl);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<e.length;n++){var a=e[n];if(!a.invisible){var r=a.group;for(var i in a.uniformTemplates){var s=a.uniformTemplates[i],o=s.value(a);if(o!=null){t[r]||(t[r]={}),t[r][i]||(t[r][i]={type:"",value:[]});var l=t[r][i];switch(l.type=s.type+"v",s.type){case"1i":case"1f":case"t":l.value.push(o);break;case"2f":case"3f":case"4f":for(var c=0;c<o.length;c++)l.value.push(o[c]);break;default:console.error("Unkown light uniform type "+s.type)}}}}}},getLightGroups:function(){var e=[];for(var t in this._lightNumber)e.push(t);return e},getNumberChangedLightGroups:function(){var e=[];for(var t in this._lightNumber)this.isLightNumberChanged(t)&&e.push(t);return e},isLightNumberChanged:function(e){var t=this._previousLightNumber,r=this._lightNumber;for(var i in r[e])if(!t[e]||r[e][i]!==t[e][i])return!0;for(var i in t[e])if(!r[e]||r[e][i]!==t[e][i])return!0;return!1},getLightsNumbers:function(e){return this._lightNumber[e]},getProgramKey:function(e){return this._lightProgramKeys[e]},setLightUniforms:function(){function e(t,r,i){for(var n in t){var a=t[n];if(a.type==="tv"){if(!r.hasUniform(n))continue;for(var s=[],o=0;o<a.value.length;o++){var l=a.value[o],c=r.takeCurrentTextureSlot(i,l);s.push(c)}r.setUniform(i.gl,"1iv",n,s)}else r.setUniform(i.gl,a.type,n,a.value)}}return function(t,r,i){e(this._lightUniforms[r],t,i),e(this.shadowUniforms,t,i)}}(),dispose:function(){this.material=null,this._opaqueList=[],this._transparentList=[],this.lights=[],this._lightUniforms={},this._lightNumber={},this._nodeRepository={}}});function tl(e,t){if(t.castShadow&&!e.castShadow)return!0}const Ct=el;var Fr=wa.isPowerOfTwo,rl=["px","nx","py","ny","pz","nz"],rn=q.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),i===36193){var a=e.getGLExtension("OES_texture_half_float");a||(i=A.FLOAT)}if(this.mipmaps.length)for(var s=this.width,o=this.height,l=0;l<this.mipmaps.length;l++){var c=this.mipmaps[l];this._updateTextureData(t,c,l,s,o,r,i),s/=2,o/=2}else this._updateTextureData(t,this,0,this.width,this.height,r,i),!this.NPOT&&this.useMipmap&&t.generateMipmap(t.TEXTURE_CUBE_MAP);t.bindTexture(t.TEXTURE_CUBE_MAP,null)},_updateTextureData:function(e,t,r,i,n,a,s){for(var o=0;o<6;o++){var l=rl[o],c=t.image&&t.image[l];c?e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+o,r,a,a,s,c):e.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+o,r,a,i,n,0,a,s,t.pixels&&t.pixels[l])}},generateMipmap:function(e){var t=e.gl;this.useMipmap&&!this.NPOT&&(t.bindTexture(t.TEXTURE_CUBE_MAP,this._cache.get("webgl_texture")),t.generateMipmap(t.TEXTURE_CUBE_MAP))},bind:function(e){e.gl.bindTexture(e.gl.TEXTURE_CUBE_MAP,this.getWebGLTexture(e))},unbind:function(e){e.gl.bindTexture(e.gl.TEXTURE_CUBE_MAP,null)},isPowerOfTwo:function(){return this.image.px?Fr(this.image.px.width)&&Fr(this.image.px.height):Fr(this.width)&&Fr(this.height)},isRenderable:function(){return this.image.px?Zt(this.image.px)&&Zt(this.image.nx)&&Zt(this.image.py)&&Zt(this.image.ny)&&Zt(this.image.pz)&&Zt(this.image.nz):!!(this.width&&this.height)},load:function(e,t){var r=0,i=this;return De.each(e,function(n,a){var s=be.createImage();t&&(s.crossOrigin=t),s.onload=function(){r--,r===0&&(i.dirty(),i.trigger("success",i))},s.onerror=function(){r--},r++,s.src=n,i.image[a]=s}),this}});Object.defineProperty(rn.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(rn.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)}});function Zt(e){return e.width>0&&e.height>0}const gr=rn;var il=tr.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=Math.atan(1/e[5])*2;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=tr.prototype.clone.call(this);return e.fov=this.fov,e.aspect=this.aspect,e.near=this.near,e.far=this.far,e}});const Ne=il;var Ur="framebuffer",pt="renderbuffer",Vn=pt+"_width",Wn=pt+"_height",wi=pt+"_attached",Ci="depthtexture_attached",Mt=A.FRAMEBUFFER,lr=A.RENDERBUFFER,fr=A.DEPTH_ATTACHMENT,Pa=A.COLOR_ATTACHMENT0,Sr=qe.extend({depthBuffer:!0,viewport:null,_width:0,_height:0,_textures:null,_boundRenderer:null},function(){this._cache=new Qi,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(Mt,this._getFrameBufferGL(e)),this._boundRenderer=e;var r=this._cache;r.put("viewport",e.viewport);var i=!1,n,a;for(var s in this._textures){i=!0;var o=this._textures[s];o&&(n=o.texture.width,a=o.texture.height,this._doAttach(e,o.texture,s,o.target))}this._width=n,this._height=a,!i&&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,n,a,1);var l=r.get("attached_textures");if(l){for(var s in l)if(!this._textures[s]){var c=l[s];this._doDetach(t,s,c)}}if(!r.get(Ci)&&this.depthBuffer){r.miss(pt)&&r.put(pt,t.createRenderbuffer());var h=r.get(pt);(n!==r.get(Vn)||a!==r.get(Wn))&&(t.bindRenderbuffer(lr,h),t.renderbufferStorage(lr,t.DEPTH_COMPONENT16,n,a),r.put(Vn,n),r.put(Wn,a),t.bindRenderbuffer(lr,null)),r.get(wi)||(t.framebufferRenderbuffer(Mt,fr,lr,h),r.put(wi,!0))}},unbind:function(e){e.__currentFrameBuffer=null;var t=e.gl;t.bindFramebuffer(Mt,null),this._boundRenderer=null,this._cache.use(e.__uid__);var r=this._cache.get("viewport");r&&e.setViewport(r),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===q.LINEAR_MIPMAP_LINEAR){var a=n.textureType==="textureCube"?A.TEXTURE_CUBE_MAP:A.TEXTURE_2D;t.bindTexture(a,n.getWebGLTexture(e)),t.generateMipmap(a),t.bindTexture(a,null)}}}},checkStatus:function(e){return e.checkFramebufferStatus(Mt)},_getFrameBufferGL:function(e){var t=this._cache;return t.use(e.__uid__),t.miss(Ur)&&t.put(Ur,e.gl.createFramebuffer()),t.get(Ur)},attach:function(e,t,r){if(!e.width)throw new Error("The texture attached to color buffer is not a valid.");t=t||Pa,r=r||A.TEXTURE_2D;var i=this._boundRenderer,n=i&&i.gl,a;if(n){var s=this._cache;s.use(i.__uid__),a=s.get("attached_textures")}var o=this._textures[t];if(!(o&&o.target===r&&o.texture===e&&a&&a[t]!=null)){var l=!0;i&&(l=this._doAttach(i,e,t,r),this.viewport||i.setViewport(0,0,e.width,e.height,1)),l&&(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),s=this._cache.get("attached_textures");if(s&&s[r]){var o=s[r];if(o.texture===t&&o.target===i)return}r=+r;var l=!0;if(r===fr||r===A.DEPTH_STENCIL_ATTACHMENT){var c=e.getGLExtension("WEBGL_depth_texture");if(c||(console.error("Depth texture is not supported by the browser"),l=!1),t.format!==A.DEPTH_COMPONENT&&t.format!==A.DEPTH_STENCIL&&(console.error("The texture attached to depth buffer is not a valid."),l=!1),l){var h=this._cache.get(pt);h&&(n.framebufferRenderbuffer(Mt,fr,lr,null),n.deleteRenderbuffer(h),this._cache.put(pt,!1)),this._cache.put(wi,!1),this._cache.put(Ci,!0)}}return n.framebufferTexture2D(Mt,r,i,a,0),s||(s={},this._cache.put("attached_textures",s)),s[r]=s[r]||{},s[r].texture=t,s[r].target=i,l},_doDetach:function(e,t,r){e.framebufferTexture2D(Mt,t,r,null,0);var i=this._cache.get("attached_textures");i&&i[t]&&(i[t]=null),(t===fr||t===A.DEPTH_STENCIL_ATTACHMENT)&&this._cache.put(Ci,!1)},detach:function(e,t){if(this._textures[e]=null,this._boundRenderer){var r=this._cache;r.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(pt);i&&t.deleteRenderbuffer(i);var n=r.get(Ur);n&&t.deleteFramebuffer(n),r.deleteContext(e.__uid__),this._textures={}}});Sr.DEPTH_ATTACHMENT=fr;Sr.COLOR_ATTACHMENT0=Pa;Sr.STENCIL_ATTACHMENT=A.STENCIL_ATTACHMENT;Sr.DEPTH_STENCIL_ATTACHMENT=A.DEPTH_STENCIL_ATTACHMENT;const Ue=Sr;var nl=["px","nx","py","ny","pz","nz"],al=qe.extend(function(){var e={position:new P,far:1e3,near:.1,texture:null,shadowMapPass:null},t=e._cameras={px:new Ne({fov:90}),nx:new Ne({fov:90}),py:new Ne({fov:90}),ny:new Ne({fov:90}),pz:new Ne({fov:90}),nz:new Ne({fov:90})};return t.px.lookAt(P.POSITIVE_X,P.NEGATIVE_Y),t.nx.lookAt(P.NEGATIVE_X,P.NEGATIVE_Y),t.py.lookAt(P.POSITIVE_Y,P.POSITIVE_Z),t.ny.lookAt(P.NEGATIVE_Y,P.NEGATIVE_Z),t.pz.lookAt(P.POSITIVE_Z,P.NEGATIVE_Y),t.nz.lookAt(P.NEGATIVE_Z,P.NEGATIVE_Y),e._frameBuffer=new Ue,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,s=0;s<6;s++){var o=nl[s],l=this._cameras[o];if(P.copy(l.position,this.position),l.far=this.far,l.near=this.near,l.fov=a,this.shadowMapPass){l.update();var c=t.getBoundingBox();c.applyTransform(l.viewMatrix),t.viewBoundingBoxLastFrame.copy(c),this.shadowMapPass.render(e,t,l,!0)}this._frameBuffer.attach(this.texture,i.COLOR_ATTACHMENT0,i.TEXTURE_CUBE_MAP_POSITIVE_X+s),this._frameBuffer.bind(e),e.render(t,l,!0),this._frameBuffer.unbind(e)}},dispose:function(e){this._frameBuffer.dispose(e)}});const nn=al;var sl=Ae.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=[],s=[],o=0;o<=e;o++)for(var l=o/e,c=0;c<=t;c++){var h=c/t;if(i.push([2*h-1,2*l-1,0]),n&&n.push([h,l]),a&&a.push([0,0,1]),c<t&&o<e){var u=c+o*(t+1);s.push([u,u+1,u+t+1]),s.push([u+t+1,u+1,u+t+2])}}r.position.fromArray(i),r.texcoord0.fromArray(n),r.normal.fromArray(a),this.initIndicesFromArray(s),this.boundingBox=new ke,this.boundingBox.min.set(-1,-1,0),this.boundingBox.max.set(1,1,0)}});const an=sl;var ge=new z,ol=Ae.extend({dynamic:!1,widthSegments:1,heightSegments:1,depthSegments:1,inside:!1},function(){this.build()},{build:function(){var e={px:$t("px",this.depthSegments,this.heightSegments),nx:$t("nx",this.depthSegments,this.heightSegments),py:$t("py",this.widthSegments,this.depthSegments),ny:$t("ny",this.widthSegments,this.depthSegments),pz:$t("pz",this.widthSegments,this.heightSegments),nz:$t("nz",this.widthSegments,this.heightSegments)},t=["position","texcoord0","normal"],r=0,i=0;for(var n in e)r+=e[n].vertexCount,i+=e[n].indices.length;for(var a=0;a<t.length;a++)this.attributes[t[a]].init(r);this.indices=new be.Uint16Array(i);var s=0,o=0;for(var n in e){for(var l=e[n],a=0;a<t.length;a++)for(var c=t[a],h=l.attributes[c].value,u=l.attributes[c].size,d=c==="normal",f=0;f<h.length;f++){var v=h[f];this.inside&&d&&(v=-v),this.attributes[c].value[f+u*o]=v}for(var m=l.indices.length,f=0;f<l.indices.length;f++)this.indices[f+s]=o+l.indices[this.inside?m-f-1:f];s+=l.indices.length,o+=l.vertexCount}this.boundingBox=new ke,this.boundingBox.max.set(1,1,1),this.boundingBox.min.set(-1,-1,-1)}});function $t(e,t,r){ge.identity();var i=new an({widthSegments:t,heightSegments:r});switch(e){case"px":z.translate(ge,ge,P.POSITIVE_X),z.rotateY(ge,ge,Math.PI/2);break;case"nx":z.translate(ge,ge,P.NEGATIVE_X),z.rotateY(ge,ge,-Math.PI/2);break;case"py":z.translate(ge,ge,P.POSITIVE_Y),z.rotateX(ge,ge,-Math.PI/2);break;case"ny":z.translate(ge,ge,P.NEGATIVE_Y),z.rotateX(ge,ge,Math.PI/2);break;case"pz":z.translate(ge,ge,P.POSITIVE_Z);break;case"nz":z.translate(ge,ge,P.NEGATIVE_Z),z.rotateY(ge,ge,Math.PI);break}return i.applyTransform(ge),i}const Da=ol,ll="@export clay.skybox.vertex\n#define SHADER_NAME skybox\nuniform mat4 world : WORLD;\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nattribute vec3 position : POSITION;\nvarying vec3 v_WorldPosition;\nvoid main()\n{\n v_WorldPosition = (world * vec4(position, 1.0)).xyz;\n gl_Position = worldViewProjection * vec4(position, 1.0);\n}\n@end\n@export clay.skybox.fragment\n#define PI 3.1415926\nuniform mat4 viewInverse : VIEWINVERSE;\n#ifdef EQUIRECTANGULAR\nuniform sampler2D environmentMap;\n#else\nuniform samplerCube environmentMap;\n#endif\nuniform float lod: 0.0;\nvarying vec3 v_WorldPosition;\n@import clay.util.rgbm\n@import clay.util.srgb\n@import clay.util.ACES\nvoid main()\n{\n vec3 eyePos = viewInverse[3].xyz;\n vec3 V = normalize(v_WorldPosition - eyePos);\n#ifdef EQUIRECTANGULAR\n float phi = acos(V.y);\n float theta = atan(-V.x, V.z) + PI * 0.5;\n vec2 uv = vec2(theta / 2.0 / PI, phi / PI);\n vec4 texel = decodeHDR(texture2D(environmentMap, fract(uv)));\n#else\n #if defined(LOD) || defined(SUPPORT_TEXTURE_LOD)\n vec4 texel = decodeHDR(textureCubeLodEXT(environmentMap, V, lod));\n #else\n vec4 texel = decodeHDR(textureCube(environmentMap, V));\n #endif\n#endif\n#ifdef SRGB_DECODE\n texel = sRGBToLinear(texel);\n#endif\n#ifdef TONEMAPPING\n texel.rgb = ACESToneMapping(texel.rgb);\n#endif\n#ifdef SRGB_ENCODE\n texel = linearTosRGB(texel);\n#endif\n gl_FragColor = encodeHDR(vec4(texel.rgb, 1.0));\n}\n@end";N.import(ll);var cl=Ji.extend(function(){var e=new N({vertex:N.source("clay.skybox.vertex"),fragment:N.source("clay.skybox.fragment")}),t=new yt({shader:e,depthMask:!1});return{scene:null,geometry:new Da,material:t,environmentMap:null,culling:!1,_dummyCamera:new Ne}},function(){var e=this.scene;e&&this.attachScene(e),this.environmentMap&&this.setEnvironmentMap(this.environmentMap)},{attachScene:function(e){this.scene&&this.detachScene(),e.skybox=this,this.scene=e,e.on("beforerender",this._beforeRenderScene,this)},detachScene:function(){this.scene&&(this.scene.off("beforerender",this._beforeRenderScene),this.scene.skybox=null),this.scene=null},dispose:function(e){this.detachScene(),this.geometry.dispose(e)},setEnvironmentMap:function(e){e.textureType==="texture2D"?(this.material.define("EQUIRECTANGULAR"),e.minFilter=q.LINEAR):this.material.undefine("EQUIRECTANGULAR"),this.material.set("environmentMap",e)},getEnvironmentMap:function(){return this.material.get("environmentMap")},_beforeRenderScene:function(e,t,r){this.renderSkybox(e,r)},renderSkybox:function(e,t){var r=this._dummyCamera;r.aspect=e.getViewportAspect(),r.fov=t.fov||50,r.updateProjectionMatrix(),z.invert(r.invProjectionMatrix,r.projectionMatrix),r.worldTransform.copy(t.worldTransform),r.viewMatrix.copy(t.viewMatrix),this.position.copy(t.getWorldPosition()),this.update(),e.gl.disable(e.gl.BLEND),this.material.get("lod")>0?this.material.define("fragment","LOD"):this.material.undefine("fragment","LOD"),e.renderPass([this],r)}});const yr=cl;var hl=542327876,ul=131072,fl=512,dl=4;function sn(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}var vl=31,ml=sn("DXT1"),pl=sn("DXT3"),_l=sn("DXT5"),gl=0,yl=1,xl=2,Tl=3,El=4,Al=7,Sl=20,bl=21,wl=28,Cl={parse:function(e,t){var r=new Int32Array(e,0,vl);if(r[gl]!==hl||!r(Sl)&dl)return null;var i=r(bl),n=r[El],a=r[Tl],s=r[wl]&fl,o=r[xl]&ul,l,c;switch(i){case ml:l=8,c=q.COMPRESSED_RGB_S3TC_DXT1_EXT;break;case pl:l=16,c=q.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case _l:l=16,c=q.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;default:return null}var h=r[yl]+4,u=s?6:1,d=1;o&&(d=Math.max(1,r[Al]));for(var f=[],v=0;v<u;v++){var m=n,p=a;f[v]=new ne({width:m,height:p,format:c});for(var _=[],T=0;T<d;T++){var y=Math.max(4,m)/4*Math.max(4,p)/4*l,g=new Uint8Array(e,h,y);h+=y,m*=.5,p*=.5,_[T]=g}f[v].pixels=_[0],o&&(f[v].mipmaps=_)}if(t)t.width=f[0].width,t.height=f[0].height,t.format=f[0].format,t.pixels=f[0].pixels,t.mipmaps=f[0].mipmaps;else return f[0]}};const Rl=Cl;var Yr=String.fromCharCode,Ml=8,Nl=32767;function Ll(e,t,r,i){if(e[3]>0){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 Pl(e,t,r){for(var i="",n=t;n<r;n++)i+=Yr(e[n]);return i}function Dl(e,t){t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3]}function Xn(e,t,r,i){for(var n=0,a=0,s=i;s>0;)if(e[a][0]=t[r++],e[a][1]=t[r++],e[a][2]=t[r++],e[a][3]=t[r++],e[a][0]===1&&e[a][1]===1&&e[a][2]===1){for(var o=e[a][3]<<n>>>0;o>0;o--)Dl(e[a-1],e[a]),a++,s--;n+=8}else a++,s--,n=0;return r}function Il(e,t,r,i){if(i<Ml|i>Nl)return Xn(e,t,r,i);var n=t[r++];if(n!=2)return Xn(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;a<i;){var s=t[r++];if(s>128){s=(s&127)>>>0;for(var o=t[r++];s--;)e[a++][n]=o}else for(;s--;)e[a++][n]=t[r++]}return r}var Ol={parseRGBE:function(e,t,r){r==null&&(r=0);var i=new Uint8Array(e),n=i.length;if(Pl(i,0,2)==="#?"){for(var a=2;a<n&&!(Yr(i[a])==="\n"&&Yr(i[a+1])==="\n");a++);if(!(a>=n)){a+=2;for(var s="";a<n;a++){var o=Yr(i[a]);if(o==="\n")break;s+=o}var l=s.split(" "),c=parseInt(l[1]),h=parseInt(l[3]);if(!(!h||!c)){for(var u=a+1,d=[],f=0;f<h;f++){d[f]=[];for(var v=0;v<4;v++)d[f][v]=0}for(var m=new Float32Array(h*c*4),p=0,_=0;_<c;_++){var u=Il(d,i,u,h);if(!u)return null;for(var f=0;f<h;f++)Ll(d[f],m,p,r),p+=4}return t||(t=new ne),t.width=h,t.height=c,t.pixels=m,t.type=q.FLOAT,t}}}},parseRGBEFromPNG:function(e){}};const Bl=Ol;var qr={loadTexture:function(e,t,r,i){var n;if(typeof t=="function"?(r=t,i=r,t={}):t=t||{},typeof e=="string"){if(e.match(/.hdr$/)||t.fileType==="hdr")return n=new ne({width:0,height:0,sRGB:!1}),qr._fetchTexture(e,function(a){Bl.parseRGBE(a,n,t.exposure),n.dirty(),r&&r(n)},i),n;e.match(/.dds$/)||t.fileType==="dds"?(n=new ne({width:0,height:0}),qr._fetchTexture(e,function(a){Rl.parse(a,n),n.dirty(),r&&r(n)},i)):(n=new ne,n.load(e),n.success(r),n.error(i))}else typeof e=="object"&&typeof e.px<"u"&&(n=new gr,n.load(e),n.success(r),n.error(i));return n},loadPanorama:function(e,t,r,i,n,a){var s=this;typeof i=="function"?(n=i,a=n,i={}):i=i||{},qr.loadTexture(t,i,function(o){o.flipY=i.flipY||!1,s.panoramaToCubeMap(e,o,r,i),o.dispose(e),n&&n(r)},a)},panoramaToCubeMap:function(e,t,r,i){var n=new nn,a=new yr({scene:new Ct});return a.setEnvironmentMap(t),i=i||{},i.encodeRGBM&&a.material.define("fragment","RGBM_ENCODE"),r.sRGB=t.sRGB,n.texture=r,n.render(e,a.scene),n.texture=null,n.dispose(e),r},heightToNormal:function(e,t){var r=document.createElement("canvas"),i=r.width=e.width,n=r.height=e.height,a=r.getContext("2d");a.drawImage(e,0,0,i,n),t=t||!1;for(var s=a.getImageData(0,0,i,n),o=a.createImageData(i,n),l=0;l<s.data.length;l+=4){if(t){var c=s.data[l],h=s.data[l+1],u=s.data[l+2],d=Math.abs(c-h)+Math.abs(h-u);if(d>20)return console.warn("Given image is not a height map"),e}var f,v,m,p;l%(i*4)===0?(f=s.data[l],m=s.data[l+4]):l%(i*4)===(i-1)*4?(f=s.data[l-4],m=s.data[l]):(f=s.data[l-4],m=s.data[l+4]),l<i*4?(v=s.data[l],p=s.data[l+i*4]):l>i*(n-1)*4?(v=s.data[l-i*4],p=s.data[l]):(v=s.data[l-i*4],p=s.data[l+i*4]),o.data[l]=f-m+127,o.data[l+1]=v-p+127,o.data[l+2]=255,o.data[l+3]=255}return a.putImageData(o,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 s=n.getImageData(0,0,a,a),o=0;o<s.data.length;o+=4){var l=s.data[o],c=s.data[o+1],h=s.data[o+2],u=Math.abs(l-c)+Math.abs(c-h);if(u>r)return!1}return!0},_fetchTexture:function(e,t,r){be.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 s=a.getContext("2d");s.fillStyle=i,s.fillRect(0,0,e,e),s.fillStyle=r;for(var o=0;o<n;o++)for(var l=0;l<n;l++){var c=l%2?o%2:o%2-1;c&&s.fillRect(o*t,l*t,t,t)}var h=new ne({image:a,anisotropic:8});return h},createBlank:function(e){var t=document.createElement("canvas");t.width=1,t.height=1;var r=t.getContext("2d");r.fillStyle=e,r.fillRect(0,0,1,1);var i=new ne({image:t});return i}};const Ft=qr;var Gi=["mousedown","mouseup","mousemove","mouseover","mouseout","click","dblclick","contextmenu"];function ki(e){return"_on"+e}var Vi=function(e){var t=this;this._texture=new ne({anisotropic:32,flipY:!1,surface:this,dispose:function(r){t.dispose(),ne.prototype.dispose.call(this,r)}}),Gi.forEach(function(r){this[ki(r)]=function(i){i.triangle&&this._meshes.forEach(function(n){this.dispatchEvent(r,n,i.triangle,i.point)},this)}},this),this._meshes=[],e&&this.setECharts(e),this.onupdate=null};Vi.prototype={constructor:Vi,getTexture:function(){return this._texture},setECharts:function(e){this._chart=e;var t=e.getDom();if(!(t instanceof HTMLCanvasElement))console.error("ECharts must init on canvas if it is used as texture."),t=document.createElement("canvas");else{var r=this,i=e.getZr(),n=i.__oldRefreshImmediately||i.refreshImmediately;i.refreshImmediately=function(){n.call(this),r._texture.dirty(),r.onupdate&&r.onupdate()},i.__oldRefreshImmediately=n}this._texture.image=t,this._texture.dirty(),this.onupdate&&this.onupdate()},dispatchEvent:function(){var e=new P,t=new P,r=new P,i=new $e,n=new $e,a=new $e,s=new $e,o=new P;return function(l,c,h,u){var d=c.geometry,f=d.attributes.position,v=d.attributes.texcoord0,m=P.dot,p=P.cross;f.get(h[0],e.array),f.get(h[1],t.array),f.get(h[2],r.array),v.get(h[0],i.array),v.get(h[1],n.array),v.get(h[2],a.array),p(o,t,r);var _=m(e,o),T=m(u,o)/_;p(o,r,e);var y=m(u,o)/_;p(o,e,t);var g=m(u,o)/_;$e.scale(s,i,T),$e.scaleAndAdd(s,s,n,y),$e.scaleAndAdd(s,s,a,g);var E=s.x*this._chart.getWidth(),S=s.y*this._chart.getHeight();this._chart.getZr().handler.dispatch(l,{zrX:E,zrY:S})}}(),attachToMesh:function(e){this._meshes.indexOf(e)>=0||(Gi.forEach(function(t){e.on(t,this[ki(t)],this)},this),this._meshes.push(e))},detachFromMesh:function(e){var t=this._meshes.indexOf(e);t>=0&&this._meshes.splice(t,1),Gi.forEach(function(r){e.off(r,this[ki(r)])},this)},dispose:function(){this._meshes.forEach(function(e){this.detachFromMesh(e)},this)}};const Fl=Vi;var Ul=tr.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=tr.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}});const xr=Ul,Hl="\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";N.import(Hl);var zl=new an,jn=new Ji({geometry:zl,frustumCulling:!1}),Gl=new xr,kl=qe.extend(function(){return{fragment:"",outputs:null,material:null,blendWithPrevious:!1,clearColor:!1,clearDepth:!0}},function(){var e=new N(N.source("clay.compositor.vertex"),this.fragment),t=new yt({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||A.COLOR_ATTACHMENT0,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,a>=r.COLOR_ATTACHMENT0&&a<=r.COLOR_ATTACHMENT0+8&&n.push(a);i.drawBuffersEXT(n)}}this.trigger("beforerender",this,e);var s=this.clearDepth?r.DEPTH_BUFFER_BIT:0;if(r.depthMask(!0),this.clearColor){s=s|r.COLOR_BUFFER_BIT,r.colorMask(!0,!0,!0,!0);var o=this.clearColor;Array.isArray(o)&&r.clearColor(o[0],o[1],o[2],o[3])}r.clear(s),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){jn.material=this.material,e.renderPass([jn],Gl)},dispose:function(e){}});const Ve=kl,Vl="#define SAMPLE_NUMBER 1024\n#define PI 3.14159265358979\nuniform sampler2D normalDistribution;\nuniform vec2 viewportSize : [512, 256];\nconst vec3 N = vec3(0.0, 0.0, 1.0);\nconst float fSampleNumber = float(SAMPLE_NUMBER);\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}\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",Wl="#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";var Ut={},Ri=["px","nx","py","ny","pz","nz"];Ut.prefilterEnvironmentMap=function(e,t,r,i,n){(!n||!i)&&(i=Ut.generateNormalDistribution(),n=Ut.integrateBRDF(e,i)),r=r||{};var a=r.width||64,s=r.height||64,o=r.type||t.type,l=new gr({width:a,height:s,type:o,flipY:!1,mipmaps:[]});l.isPowerOfTwo()||console.warn("Width and height must be power of two to enable mipmap.");var c=Math.min(a,s),h=Math.log(c)/Math.log(2)+1,u=new yt({shader:new N({vertex:N.source("clay.skybox.vertex"),fragment:Wl})});u.set("normalDistribution",i),r.encodeRGBM&&u.define("fragment","RGBM_ENCODE"),r.decodeRGBM&&u.define("fragment","RGBM_DECODE");var d=new Ct,f;if(t.textureType==="texture2D"){var v=new gr({width:a,height:s,type:o===q.FLOAT?q.HALF_FLOAT:o});Ft.panoramaToCubeMap(e,t,v,{encodeRGBM:r.decodeRGBM}),t=v}f=new yr({scene:d,material:u}),f.material.set("environmentMap",t);var m=new nn({texture:l});r.encodeRGBM&&(o=l.type=q.UNSIGNED_BYTE);for(var p=new ne({width:a,height:s,type:o}),_=new Ue({depthBuffer:!1}),T=be[o===q.UNSIGNED_BYTE?"Uint8Array":"Float32Array"],y=0;y<h;y++){l.mipmaps[y]={pixels:{}},f.material.set("roughness",y/(h-1));for(var g=p.width,E=2*Math.atan(g/(g-.5))/Math.PI*180,S=0;S<Ri.length;S++){var R=new T(p.width*p.height*4);_.attach(p),_.bind(e);var b=m.getCamera(Ri[S]);b.fov=E,e.render(d,b),e.gl.readPixels(0,0,p.width,p.height,q.RGBA,o,R),_.unbind(e),l.mipmaps[y].pixels[Ri[S]]=R}p.width/=2,p.height/=2,p.dirty()}return _.dispose(e),p.dispose(e),f.dispose(e),i.dispose(e),{environmentMap:l,brdfLookup:n,normalDistribution:i,maxMipmapLevel:h}};Ut.integrateBRDF=function(e,t){t=t||Ut.generateNormalDistribution();var r=new Ue({depthBuffer:!1}),i=new Ve({fragment:Vl}),n=new ne({width:512,height:256,type:q.HALF_FLOAT,wrapS:q.CLAMP_TO_EDGE,wrapT:q.CLAMP_TO_EDGE,minFilter:q.NEAREST,magFilter:q.NEAREST,useMipmap:!1});return i.setUniform("normalDistribution",t),i.setUniform("viewportSize",[512,256]),i.attachOutput(n),i.render(e,r),r.dispose(e),n};Ut.generateNormalDistribution=function(r,i){for(var r=r||256,i=i||1024,n=new ne({width:r,height:i,type:q.FLOAT,minFilter:q.NEAREST,magFilter:q.NEAREST,wrapS:q.CLAMP_TO_EDGE,wrapT:q.CLAMP_TO_EDGE,useMipmap:!1}),a=new Float32Array(i*r*4),s=[],o=0;o<r;o++){for(var l=o/r,c=l*l,h=0;h<i;h++){var u=(h<<16|h>>>16)>>>0;u=((u&1431655765)<<1|(u&2863311530)>>>1)>>>0,u=((u&858993459)<<2|(u&3435973836)>>>2)>>>0,u=((u&252645135)<<4|(u&4042322160)>>>4)>>>0,u=(((u&16711935)<<8|(u&4278255360)>>>8)>>>0)/4294967296;var d=Math.sqrt((1-u)/(1+(c*c-1)*u));s[h]=d}for(var h=0;h<i;h++){var f=(h*r+o)*4,d=s[h],v=Math.sqrt(1-d*d),m=h/i,p=2*Math.PI*m;a[f]=v*Math.cos(p),a[f+1]=d,a[f+2]=v*Math.sin(p),a[f+3]=1}}return n.pixels=a,n};const Zr=Ut;var Xl=lt.extend({cubemap:null,castShadow:!1,_normalDistribution:null,_brdfLookup:null},{type:"AMBIENT_CUBEMAP_LIGHT",prefilter:function(e,t){if(!e.getGLExtension("EXT_shader_texture_lod")){console.warn("Device not support textureCubeLodEXT");return}this._brdfLookup||(this._normalDistribution=Zr.generateNormalDistribution(),this._brdfLookup=Zr.integrateBRDF(e,this._normalDistribution));var r=this.cubemap;if(!r.__prefiltered){var i=Zr.prefilterEnvironmentMap(e,r,{encodeRGBM:!0,width:t,height:t},this._normalDistribution,this._brdfLookup);this.cubemap=i.environmentMap,this.cubemap.__prefiltered=!0,r.dispose(e)}},getBRDFLookup:function(){return this._brdfLookup},uniformTemplates:{ambientCubemapLightColor:{type:"3f",value:function(e){var t=e.color,r=e.intensity;return[t[0]*r,t[1]*r,t[2]*r]}},ambientCubemapLightCubemap:{type:"t",value:function(e){return e.cubemap}},ambientCubemapLightBRDFLookup:{type:"t",value:function(e){return e._brdfLookup}}}});const jl=Xl;var Yl=lt.extend({castShadow:!1,coefficients:[]},function(){this._coefficientsTmpArr=new be.Float32Array(9*3)},{type:"AMBIENT_SH_LIGHT",uniformTemplates:{ambientSHLightColor:{type:"3f",value:function(e){var t=e.color,r=e.intensity;return[t[0]*r,t[1]*r,t[2]*r]}},ambientSHLightCoefficients:{type:"3f",value:function(e){for(var t=e._coefficientsTmpArr,r=0;r<e.coefficients.length;r++)t[r]=e.coefficients[r];return t}}}});const ql=Yl;var Ia={},Bt=["px","nx","py","ny","pz","nz"];function Zl(e,t){var r=e[0],i=e[1],n=e[2];return t===0?1:t===1?r:t===2?i:t===3?n:t===4?r*n:t===5?i*n:t===6?r*i:t===7?3*n*n-1:r*r-i*i}var $l={px:[2,1,0,-1,-1,1],nx:[2,1,0,1,-1,-1],py:[0,2,1,1,-1,-1],ny:[0,2,1,1,1,1],pz:[0,1,2,-1,-1,-1],nz:[0,1,2,1,-1,1]};function Kl(e,t,r,i){for(var n=new be.Float32Array(27),a=x.create(),s=x.create(),o=x.create(),l=0;l<9;l++){for(var c=x.create(),h=0;h<Bt.length;h++){for(var u=t[Bt[h]],d=x.create(),f=0,v=0,m=$l[Bt[h]],p=0;p<i;p++)for(var _=0;_<r;_++){a[0]=_/(r-1)*2-1,a[1]=p/(i-1)*2-1,a[2]=-1,x.normalize(a,a),o[0]=a[m[0]]*m[3],o[1]=a[m[1]]*m[4],o[2]=a[m[2]]*m[5],s[0]=u[v++]/255,s[1]=u[v++]/255,s[2]=u[v++]/255;var T=u[v++]/255*8.12;s[0]*=T,s[1]*=T,s[2]*=T,x.scaleAndAdd(d,d,s,Zl(o,l)*-a[2]),f+=-a[2]}x.scaleAndAdd(c,c,d,1/f)}n[l*3]=c[0]/6,n[l*3+1]=c[1]/6,n[l*3+2]=c[2]/6}return n}Ia.projectEnvironmentMap=function(e,t,r){r=r||{},r.lod=r.lod||0;var i,n=new Ct,a=64;t.textureType==="texture2D"?i=new yr({scene:n,environmentMap:t}):(a=t.image&&t.image.px?t.image.px.width:t.width,i=new yr({scene:n,environmentMap:t}));var s=Math.ceil(a/Math.pow(2,r.lod)),o=Math.ceil(a/Math.pow(2,r.lod)),l=new ne({width:s,height:o}),c=new Ue;i.material.define("fragment","RGBM_ENCODE"),r.decodeRGBM&&i.material.define("fragment","RGBM_DECODE"),i.material.set("lod",r.lod);for(var h=new nn({texture:l}),u={},d=0;d<Bt.length;d++){u[Bt[d]]=new Uint8Array(s*o*4);var f=h.getCamera(Bt[d]);f.fov=90,c.attach(l),c.bind(e),e.render(n,f),e.gl.readPixels(0,0,s,o,q.RGBA,q.UNSIGNED_BYTE,u[Bt[d]]),c.unbind(e)}return i.dispose(e),c.dispose(e),l.dispose(e),Kl(e,u,s,o)};const Ql=Ia;var Jl={firstNotNull:function(){for(var e=0,t=arguments.length;e<t;e++)if(arguments[e]!=null)return arguments[e]},queryDataIndex:function(e,t){if(t.dataIndexInside!=null)return t.dataIndexInside;if(t.dataIndex!=null)return mr(t.dataIndex)?dn(t.dataIndex,function(r){return e.indexOfRawIndex(r)}):e.indexOfRawIndex(t.dataIndex);if(t.name!=null)return mr(t.name)?dn(t.name,function(r){return e.indexOfName(r)}):e.indexOfName(t.name)}};const tt=Jl;var ec=Ae.extend({dynamic:!1,widthSegments:40,heightSegments:20,phiStart:0,phiLength:Math.PI*2,thetaStart:0,thetaLength:Math.PI,radius:1},function(){this.build()},{build:function(){var e=this.heightSegments,t=this.widthSegments,r=this.attributes.position,i=this.attributes.texcoord0,n=this.attributes.normal,a=(t+1)*(e+1);r.init(a),i.init(a),n.init(a);var s=a>65535?Uint32Array:Uint16Array,o=this.indices=new s(t*e*6),l,c,h,u,d,f,v,y=this.radius,m=this.phiStart,p=this.phiLength,_=this.thetaStart,T=this.thetaLength,y=this.radius,g=[],E=[],S=0,R=1/y;for(v=0;v<=e;v++)for(f=0;f<=t;f++)u=f/t,d=v/e,l=-y*Math.cos(m+u*p)*Math.sin(_+d*T),c=y*Math.cos(_+d*T),h=y*Math.sin(m+u*p)*Math.sin(_+d*T),g[0]=l,g[1]=c,g[2]=h,E[0]=u,E[1]=d,r.set(S,g),i.set(S,E),g[0]*=R,g[1]*=R,g[2]*=R,n.set(S,g),S++;var b,M,F,w,U=t+1,O=0;for(v=0;v<e;v++)for(f=0;f<t;f++)M=v*U+f,b=v*U+f+1,w=(v+1)*U+f+1,F=(v+1)*U+f,o[O++]=b,o[O++]=M,o[O++]=w,o[O++]=M,o[O++]=F,o[O++]=w;this.boundingBox=new ke,this.boundingBox.max.set(y,y,y),this.boundingBox.min.set(-y,-y,-y)}});const tc=ec;var rc=lt.extend({castShadow:!1},{type:"AMBIENT_LIGHT",uniformTemplates:{ambientLightColor:{type:"3f",value:function(e){var t=e.color,r=e.intensity;return[t[0]*r,t[1]*r,t[2]*r]}}}});const ic=rc;var nc=lt.extend({shadowBias:.001,shadowSlopeScale:2,shadowCascade:1,cascadeSplitLogFactor:.2},{type:"DIRECTIONAL_LIGHT",uniformTemplates:{directionalLightDirection:{type:"3f",value:function(e){return e.__dir=e.__dir||new P,e.__dir.copy(e.worldTransform.z).normalize().negate().array}},directionalLightColor:{type:"3f",value:function(e){var t=e.color,r=e.intensity;return[t[0]*r,t[1]*r,t[2]*r]}}},clone:function(){var e=lt.prototype.clone.call(this);return e.shadowBias=this.shadowBias,e.shadowSlopeScale=this.shadowSlopeScale,e}});const ac=nc;var sc=lt.extend({range:100,castShadow:!1},{type:"POINT_LIGHT",uniformTemplates:{pointLightPosition:{type:"3f",value:function(e){return e.getWorldPosition().array}},pointLightRange:{type:"1f",value:function(e){return e.range}},pointLightColor:{type:"3f",value:function(e){var t=e.color,r=e.intensity;return[t[0]*r,t[1]*r,t[2]*r]}}},clone:function(){var e=lt.prototype.clone.call(this);return e.range=this.range,e}});const oc=sc;var lc=lt.extend({range:20,umbraAngle:30,penumbraAngle:45,falloffFactor:2,shadowBias:.001,shadowSlopeScale:2},{type:"SPOT_LIGHT",uniformTemplates:{spotLightPosition:{type:"3f",value:function(e){return e.getWorldPosition().array}},spotLightRange:{type:"1f",value:function(e){return e.range}},spotLightUmbraAngleCosine:{type:"1f",value:function(e){return Math.cos(e.umbraAngle*Math.PI/180)}},spotLightPenumbraAngleCosine:{type:"1f",value:function(e){return Math.cos(e.penumbraAngle*Math.PI/180)}},spotLightFalloffFactor:{type:"1f",value:function(e){return e.falloffFactor}},spotLightDirection:{type:"3f",value:function(e){return e.__dir=e.__dir||new P,e.__dir.copy(e.worldTransform.z).negate().array}},spotLightColor:{type:"3f",value:function(e){var t=e.color,r=e.intensity;return[t[0]*r,t[1]*r,t[2]*r]}}},clone:function(){var e=lt.prototype.clone.call(this);return e.range=this.range,e.umbraAngle=this.umbraAngle,e.penumbraAngle=this.penumbraAngle,e.falloffFactor=this.falloffFactor,e.shadowBias=this.shadowBias,e.shadowSlopeScale=this.shadowSlopeScale,e}});const cc=lc;var re=function(e,t,r,i){e=e||0,t=t||0,r=r||0,i=i||0,this.array=D.fromValues(e,t,r,i),this._dirty=!0};re.prototype={constructor:re,add:function(e){return D.add(this.array,this.array,e.array),this._dirty=!0,this},set:function(e,t,r,i){return this.array[0]=e,this.array[1]=t,this.array[2]=r,this.array[3]=i,this._dirty=!0,this},setArray:function(e){return this.array[0]=e[0],this.array[1]=e[1],this.array[2]=e[2],this.array[3]=e[3],this._dirty=!0,this},clone:function(){return new re(this.x,this.y,this.z,this.w)},copy:function(e){return D.copy(this.array,e.array),this._dirty=!0,this},dist:function(e){return D.dist(this.array,e.array)},distance:function(e){return D.distance(this.array,e.array)},div:function(e){return D.div(this.array,this.array,e.array),this._dirty=!0,this},divide:function(e){return D.divide(this.array,this.array,e.array),this._dirty=!0,this},dot:function(e){return D.dot(this.array,e.array)},len:function(){return D.len(this.array)},length:function(){return D.length(this.array)},lerp:function(e,t,r){return D.lerp(this.array,e.array,t.array,r),this._dirty=!0,this},min:function(e){return D.min(this.array,this.array,e.array),this._dirty=!0,this},max:function(e){return D.max(this.array,this.array,e.array),this._dirty=!0,this},mul:function(e){return D.mul(this.array,this.array,e.array),this._dirty=!0,this},multiply:function(e){return D.multiply(this.array,this.array,e.array),this._dirty=!0,this},negate:function(){return D.negate(this.array,this.array),this._dirty=!0,this},normalize:function(){return D.normalize(this.array,this.array),this._dirty=!0,this},random:function(e){return D.random(this.array,e),this._dirty=!0,this},scale:function(e){return D.scale(this.array,this.array,e),this._dirty=!0,this},scaleAndAdd:function(e,t){return D.scaleAndAdd(this.array,this.array,e.array,t),this._dirty=!0,this},sqrDist:function(e){return D.sqrDist(this.array,e.array)},squaredDistance:function(e){return D.squaredDistance(this.array,e.array)},sqrLen:function(){return D.sqrLen(this.array)},squaredLength:function(){return D.squaredLength(this.array)},sub:function(e){return D.sub(this.array,this.array,e.array),this._dirty=!0,this},subtract:function(e){return D.subtract(this.array,this.array,e.array),this._dirty=!0,this},transformMat4:function(e){return D.transformMat4(this.array,this.array,e.array),this._dirty=!0,this},transformQuat:function(e){return D.transformQuat(this.array,this.array,e.array),this._dirty=!0,this},toString:function(){return"["+Array.prototype.join.call(this.array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this.array)}};var cr=Object.defineProperty;if(cr){var Hr=re.prototype;cr(Hr,"x",{get:function(){return this.array[0]},set:function(e){this.array[0]=e,this._dirty=!0}}),cr(Hr,"y",{get:function(){return this.array[1]},set:function(e){this.array[1]=e,this._dirty=!0}}),cr(Hr,"z",{get:function(){return this.array[2]},set:function(e){this.array[2]=e,this._dirty=!0}}),cr(Hr,"w",{get:function(){return this.array[3]},set:function(e){this.array[3]=e,this._dirty=!0}})}re.add=function(e,t,r){return D.add(e.array,t.array,r.array),e._dirty=!0,e};re.set=function(e,t,r,i,n){D.set(e.array,t,r,i,n),e._dirty=!0};re.copy=function(e,t){return D.copy(e.array,t.array),e._dirty=!0,e};re.dist=function(e,t){return D.distance(e.array,t.array)};re.distance=re.dist;re.div=function(e,t,r){return D.divide(e.array,t.array,r.array),e._dirty=!0,e};re.divide=re.div;re.dot=function(e,t){return D.dot(e.array,t.array)};re.len=function(e){return D.length(e.array)};re.lerp=function(e,t,r,i){return D.lerp(e.array,t.array,r.array,i),e._dirty=!0,e};re.min=function(e,t,r){return D.min(e.array,t.array,r.array),e._dirty=!0,e};re.max=function(e,t,r){return D.max(e.array,t.array,r.array),e._dirty=!0,e};re.mul=function(e,t,r){return D.multiply(e.array,t.array,r.array),e._dirty=!0,e};re.multiply=re.mul;re.negate=function(e,t){return D.negate(e.array,t.array),e._dirty=!0,e};re.normalize=function(e,t){return D.normalize(e.array,t.array),e._dirty=!0,e};re.random=function(e,t){return D.random(e.array,t),e._dirty=!0,e};re.scale=function(e,t,r){return D.scale(e.array,t.array,r),e._dirty=!0,e};re.scaleAndAdd=function(e,t,r,i){return D.scaleAndAdd(e.array,t.array,r.array,i),e._dirty=!0,e};re.sqrDist=function(e,t){return D.sqrDist(e.array,t.array)};re.squaredDistance=re.sqrDist;re.sqrLen=function(e){return D.sqrLen(e.array)};re.squaredLength=re.sqrLen;re.sub=function(e,t,r){return D.subtract(e.array,t.array,r.array),e._dirty=!0,e};re.subtract=re.sub;re.transformMat4=function(e,t,r){return D.transformMat4(e.array,t.array,r.array),e._dirty=!0,e};re.transformQuat=function(e,t,r){return D.transformQuat(e.array,t.array,r.array),e._dirty=!0,e};const hc=re;var He={};He.create=function(){var e=new Ie(4);return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e};He.clone=function(e){var t=new Ie(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};He.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e};He.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e};He.transpose=function(e,t){if(e===t){var r=t[1];e[1]=t[2],e[2]=r}else e[0]=t[0],e[1]=t[2],e[2]=t[1],e[3]=t[3];return e};He.invert=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=r*a-n*i;return s?(s=1/s,e[0]=a*s,e[1]=-i*s,e[2]=-n*s,e[3]=r*s,e):null};He.adjoint=function(e,t){var r=t[0];return e[0]=t[3],e[1]=-t[1],e[2]=-t[2],e[3]=r,e};He.determinant=function(e){return e[0]*e[3]-e[2]*e[1]};He.multiply=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=r[0],l=r[1],c=r[2],h=r[3];return e[0]=i*o+a*l,e[1]=n*o+s*l,e[2]=i*c+a*h,e[3]=n*c+s*h,e};He.mul=He.multiply;He.rotate=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=Math.sin(r),l=Math.cos(r);return e[0]=i*l+a*o,e[1]=n*l+s*o,e[2]=i*-o+a*l,e[3]=n*-o+s*l,e};He.scale=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=r[0],l=r[1];return e[0]=i*o,e[1]=n*o,e[2]=a*l,e[3]=s*l,e};He.frob=function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2))};He.LDU=function(e,t,r,i){return e[2]=i[2]/i[0],r[0]=i[0],r[1]=i[1],r[3]=i[3]-e[2]*r[1],[e,t,r]};const xe=He;var We=function(){this.array=xe.create(),this._dirty=!0};We.prototype={constructor:We,setArray:function(e){for(var t=0;t<this.array.length;t++)this.array[t]=e[t];return this._dirty=!0,this},clone:function(){return new We().copy(this)},copy:function(e){return xe.copy(this.array,e.array),this._dirty=!0,this},adjoint:function(){return xe.adjoint(this.array,this.array),this._dirty=!0,this},determinant:function(){return xe.determinant(this.array)},identity:function(){return xe.identity(this.array),this._dirty=!0,this},invert:function(){return xe.invert(this.array,this.array),this._dirty=!0,this},mul:function(e){return xe.mul(this.array,this.array,e.array),this._dirty=!0,this},mulLeft:function(e){return xe.mul(this.array,e.array,this.array),this._dirty=!0,this},multiply:function(e){return xe.multiply(this.array,this.array,e.array),this._dirty=!0,this},multiplyLeft:function(e){return xe.multiply(this.array,e.array,this.array),this._dirty=!0,this},rotate:function(e){return xe.rotate(this.array,this.array,e),this._dirty=!0,this},scale:function(e){return xe.scale(this.array,this.array,e.array),this._dirty=!0,this},transpose:function(){return xe.transpose(this.array,this.array),this._dirty=!0,this},toString:function(){return"["+Array.prototype.join.call(this.array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this.array)}};We.adjoint=function(e,t){return xe.adjoint(e.array,t.array),e._dirty=!0,e};We.copy=function(e,t){return xe.copy(e.array,t.array),e._dirty=!0,e};We.determinant=function(e){return xe.determinant(e.array)};We.identity=function(e){return xe.identity(e.array),e._dirty=!0,e};We.invert=function(e,t){return xe.invert(e.array,t.array),e._dirty=!0,e};We.mul=function(e,t,r){return xe.mul(e.array,t.array,r.array),e._dirty=!0,e};We.multiply=We.mul;We.rotate=function(e,t,r){return xe.rotate(e.array,t.array,r),e._dirty=!0,e};We.scale=function(e,t,r){return xe.scale(e.array,t.array,r.array),e._dirty=!0,e};We.transpose=function(e,t){return xe.transpose(e.array,t.array),e._dirty=!0,e};const uc=We;var Ye={};Ye.create=function(){var e=new Ie(6);return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e[4]=0,e[5]=0,e};Ye.clone=function(e){var t=new Ie(6);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t};Ye.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};Ye.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e[4]=0,e[5]=0,e};Ye.invert=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],s=t[4],o=t[5],l=r*a-i*n;return l?(l=1/l,e[0]=a*l,e[1]=-i*l,e[2]=-n*l,e[3]=r*l,e[4]=(n*o-a*s)*l,e[5]=(i*s-r*o)*l,e):null};Ye.determinant=function(e){return e[0]*e[3]-e[1]*e[2]};Ye.multiply=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=r[0],h=r[1],u=r[2],d=r[3],f=r[4],v=r[5];return e[0]=i*c+a*h,e[1]=n*c+s*h,e[2]=i*u+a*d,e[3]=n*u+s*d,e[4]=i*f+a*v+o,e[5]=n*f+s*v+l,e};Ye.mul=Ye.multiply;Ye.rotate=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=Math.sin(r),h=Math.cos(r);return e[0]=i*h+a*c,e[1]=n*h+s*c,e[2]=i*-c+a*h,e[3]=n*-c+s*h,e[4]=o,e[5]=l,e};Ye.scale=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=r[0],h=r[1];return e[0]=i*c,e[1]=n*c,e[2]=a*h,e[3]=s*h,e[4]=o,e[5]=l,e};Ye.translate=function(e,t,r){var i=t[0],n=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=r[0],h=r[1];return e[0]=i,e[1]=n,e[2]=a,e[3]=s,e[4]=i*c+a*h+o,e[5]=n*c+s*h+l,e};Ye.frob=function(e){return Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2)+Math.pow(e[3],2)+Math.pow(e[4],2)+Math.pow(e[5],2)+1)};const Se=Ye;var je=function(){this.array=Se.create(),this._dirty=!0};je.prototype={constructor:je,setArray:function(e){for(var t=0;t<this.array.length;t++)this.array[t]=e[t];return this._dirty=!0,this},clone:function(){return new je().copy(this)},copy:function(e){return Se.copy(this.array,e.array),this._dirty=!0,this},determinant:function(){return Se.determinant(this.array)},identity:function(){return Se.identity(this.array),this._dirty=!0,this},invert:function(){return Se.invert(this.array,this.array),this._dirty=!0,this},mul:function(e){return Se.mul(this.array,this.array,e.array),this._dirty=!0,this},mulLeft:function(e){return Se.mul(this.array,e.array,this.array),this._dirty=!0,this},multiply:function(e){return Se.multiply(this.array,this.array,e.array),this._dirty=!0,this},multiplyLeft:function(e){return Se.multiply(this.array,e.array,this.array),this._dirty=!0,this},rotate:function(e){return Se.rotate(this.array,this.array,e),this._dirty=!0,this},scale:function(e){return Se.scale(this.array,this.array,e.array),this._dirty=!0,this},translate:function(e){return Se.translate(this.array,this.array,e.array),this._dirty=!0,this},toString:function(){return"["+Array.prototype.join.call(this.array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this.array)}};je.copy=function(e,t){return Se.copy(e.array,t.array),e._dirty=!0,e};je.determinant=function(e){return Se.determinant(e.array)};je.identity=function(e){return Se.identity(e.array),e._dirty=!0,e};je.invert=function(e,t){return Se.invert(e.array,t.array),e._dirty=!0,e};je.mul=function(e,t,r){return Se.mul(e.array,t.array,r.array),e._dirty=!0,e};je.multiply=je.mul;je.rotate=function(e,t,r){return Se.rotate(e.array,t.array,r),e._dirty=!0,e};je.scale=function(e,t,r){return Se.scale(e.array,t.array,r.array),e._dirty=!0,e};je.translate=function(e,t,r){return Se.translate(e.array,t.array,r.array),e._dirty=!0,e};const fc=je;var we=function(){this.array=ee.create(),this._dirty=!0};we.prototype={constructor:we,setArray:function(e){for(var t=0;t<this.array.length;t++)this.array[t]=e[t];return this._dirty=!0,this},adjoint:function(){return ee.adjoint(this.array,this.array),this._dirty=!0,this},clone:function(){return new we().copy(this)},copy:function(e){return ee.copy(this.array,e.array),this._dirty=!0,this},determinant:function(){return ee.determinant(this.array)},fromMat2d:function(e){return ee.fromMat2d(this.array,e.array),this._dirty=!0,this},fromMat4:function(e){return ee.fromMat4(this.array,e.array),this._dirty=!0,this},fromQuat:function(e){return ee.fromQuat(this.array,e.array),this._dirty=!0,this},identity:function(){return ee.identity(this.array),this._dirty=!0,this},invert:function(){return ee.invert(this.array,this.array),this._dirty=!0,this},mul:function(e){return ee.mul(this.array,this.array,e.array),this._dirty=!0,this},mulLeft:function(e){return ee.mul(this.array,e.array,this.array),this._dirty=!0,this},multiply:function(e){return ee.multiply(this.array,this.array,e.array),this._dirty=!0,this},multiplyLeft:function(e){return ee.multiply(this.array,e.array,this.array),this._dirty=!0,this},rotate:function(e){return ee.rotate(this.array,this.array,e),this._dirty=!0,this},scale:function(e){return ee.scale(this.array,this.array,e.array),this._dirty=!0,this},translate:function(e){return ee.translate(this.array,this.array,e.array),this._dirty=!0,this},normalFromMat4:function(e){return ee.normalFromMat4(this.array,e.array),this._dirty=!0,this},transpose:function(){return ee.transpose(this.array,this.array),this._dirty=!0,this},toString:function(){return"["+Array.prototype.join.call(this.array,",")+"]"},toArray:function(){return Array.prototype.slice.call(this.array)}};we.adjoint=function(e,t){return ee.adjoint(e.array,t.array),e._dirty=!0,e};we.copy=function(e,t){return ee.copy(e.array,t.array),e._dirty=!0,e};we.determinant=function(e){return ee.determinant(e.array)};we.identity=function(e){return ee.identity(e.array),e._dirty=!0,e};we.invert=function(e,t){return ee.invert(e.array,t.array),e};we.mul=function(e,t,r){return ee.mul(e.array,t.array,r.array),e._dirty=!0,e};we.multiply=we.mul;we.fromMat2d=function(e,t){return ee.fromMat2d(e.array,t.array),e._dirty=!0,e};we.fromMat4=function(e,t){return ee.fromMat4(e.array,t.array),e._dirty=!0,e};we.fromQuat=function(e,t){return ee.fromQuat(e.array,t.array),e._dirty=!0,e};we.normalFromMat4=function(e,t){return ee.normalFromMat4(e.array,t.array),e._dirty=!0,e};we.rotate=function(e,t,r){return ee.rotate(e.array,t.array,r),e._dirty=!0,e};we.scale=function(e,t,r){return ee.scale(e.array,t.array,r.array),e._dirty=!0,e};we.transpose=function(e,t){return ee.transpose(e.array,t.array),e._dirty=!0,e};we.translate=function(e,t,r){return ee.translate(e.array,t.array,r.array),e._dirty=!0,e};const dc=we;var vc={_animators:null,getAnimators:function(){return this._animators=this._animators||[],this._animators},animate:function(e,t){this._animators=this._animators||[];var r=this,i;if(e){for(var n=e.split("."),a=r,s=0,o=n.length;s<o;s++)a&&(a=a[n[s]]);a&&(i=a)}else i=r;if(i==null)throw new Error("Target "+e+" not exists");var l=this._animators,c=new Cs(i,t),h=this;return c.during(function(){h.__zr&&h.__zr.refresh()}).done(function(){var u=l.indexOf(c);u>=0&&l.splice(u,1)}),l.push(c),this.__zr&&this.__zr.animation.addAnimator(c),c},stopAnimation:function(e){this._animators=this._animators||[];for(var t=this._animators,r=t.length,i=0;i<r;i++)t[i].stop(e);return t.length=0,this},addAnimatorsToZr:function(e){if(this._animators)for(var t=0;t<this._animators.length;t++)e.animation.addAnimator(this._animators[t])},removeAnimatorsFromZr:function(e){if(this._animators)for(var t=0;t<this._animators.length;t++)e.animation.removeAnimator(this._animators[t])}};const mc=vc,pc="\n@export clay.util.rand\nhighp float rand(vec2 uv) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot(uv.xy, vec2(a,b)), sn = mod(dt, 3.141592653589793);\n return fract(sin(sn) * c);\n}\n@end\n@export clay.util.calculate_attenuation\nuniform float attenuationFactor : 5.0;\nfloat lightAttenuation(float dist, float range)\n{\n float attenuation = 1.0;\n attenuation = dist*dist/(range*range+1.0);\n float att_s = attenuationFactor;\n attenuation = 1.0/(attenuation*att_s+1.0);\n att_s = 1.0/(att_s+1.0);\n attenuation = attenuation - att_s;\n attenuation /= 1.0 - att_s;\n return clamp(attenuation, 0.0, 1.0);\n}\n@end\n@export clay.util.edge_factor\n#ifdef SUPPORT_STANDARD_DERIVATIVES\nfloat edgeFactor(float width)\n{\n vec3 d = fwidth(v_Barycentric);\n vec3 a3 = smoothstep(vec3(0.0), d * width, v_Barycentric);\n return min(min(a3.x, a3.y), a3.z);\n}\n#else\nfloat edgeFactor(float width)\n{\n return 1.0;\n}\n#endif\n@end\n@export clay.util.encode_float\nvec4 encodeFloat(const in float depth)\n{\n const vec4 bitShifts = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);\n const vec4 bit_mask = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);\n vec4 res = fract(depth * bitShifts);\n res -= res.xxyz * bit_mask;\n return res;\n}\n@end\n@export clay.util.decode_float\nfloat decodeFloat(const in vec4 color)\n{\n const vec4 bitShifts = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);\n return dot(color, bitShifts);\n}\n@end\n@export clay.util.float\n@import clay.util.encode_float\n@import clay.util.decode_float\n@end\n@export clay.util.rgbm_decode\nvec3 RGBMDecode(vec4 rgbm, float range) {\n return range * rgbm.rgb * rgbm.a;\n}\n@end\n@export clay.util.rgbm_encode\nvec4 RGBMEncode(vec3 color, float range) {\n if (dot(color, color) == 0.0) {\n return vec4(0.0);\n }\n vec4 rgbm;\n color /= range;\n rgbm.a = clamp(max(max(color.r, color.g), max(color.b, 1e-6)), 0.0, 1.0);\n rgbm.a = ceil(rgbm.a * 255.0) / 255.0;\n rgbm.rgb = color / rgbm.a;\n return rgbm;\n}\n@end\n@export clay.util.rgbm\n@import clay.util.rgbm_decode\n@import clay.util.rgbm_encode\nvec4 decodeHDR(vec4 color)\n{\n#if defined(RGBM_DECODE) || defined(RGBM)\n return vec4(RGBMDecode(color, 8.12), 1.0);\n#else\n return color;\n#endif\n}\nvec4 encodeHDR(vec4 color)\n{\n#if defined(RGBM_ENCODE) || defined(RGBM)\n return RGBMEncode(color.xyz, 8.12);\n#else\n return color;\n#endif\n}\n@end\n@export clay.util.srgb\nvec4 sRGBToLinear(in vec4 value) {\n return vec4(mix(pow(value.rgb * 0.9478672986 + vec3(0.0521327014), vec3(2.4)), value.rgb * 0.0773993808, vec3(lessThanEqual(value.rgb, vec3(0.04045)))), value.w);\n}\nvec4 linearTosRGB(in vec4 value) {\n return vec4(mix(pow(value.rgb, vec3(0.41666)) * 1.055 - vec3(0.055), value.rgb * 12.92, vec3(lessThanEqual(value.rgb, vec3(0.0031308)))), value.w);\n}\n@end\n@export clay.chunk.skinning_header\n#ifdef SKINNING\nattribute vec3 weight : WEIGHT;\nattribute vec4 joint : JOINT;\n#ifdef USE_SKIN_MATRICES_TEXTURE\nuniform sampler2D skinMatricesTexture : ignore;\nuniform float skinMatricesTextureSize: ignore;\nmat4 getSkinMatrix(sampler2D tex, float idx) {\n float j = idx * 4.0;\n float x = mod(j, skinMatricesTextureSize);\n float y = floor(j / skinMatricesTextureSize) + 0.5;\n vec2 scale = vec2(skinMatricesTextureSize);\n return mat4(\n texture2D(tex, vec2(x + 0.5, y) / scale),\n texture2D(tex, vec2(x + 1.5, y) / scale),\n texture2D(tex, vec2(x + 2.5, y) / scale),\n texture2D(tex, vec2(x + 3.5, y) / scale)\n );\n}\nmat4 getSkinMatrix(float idx) {\n return getSkinMatrix(skinMatricesTexture, idx);\n}\n#else\nuniform mat4 skinMatrix[JOINT_COUNT] : SKIN_MATRIX;\nmat4 getSkinMatrix(float idx) {\n return skinMatrix[int(idx)];\n}\n#endif\n#endif\n@end\n@export clay.chunk.skin_matrix\nmat4 skinMatrixWS = getSkinMatrix(joint.x) * weight.x;\nif (weight.y > 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",_c="\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",gc="@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",yc="/**\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",xc="@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",Tc="@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",Ec="@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";Object.assign(dt.prototype,mc);N.import(pc);N.import(Sa);N.import(_c);N.import(gc);N.import(yc);N.import(xc);N.import(Tc);N.import(Ec);function Ac(e){return!e||e==="none"}function Oa(e){return e instanceof HTMLCanvasElement||e instanceof HTMLImageElement||e instanceof Image}function Sc(e){return e.getZr&&e.setOption}var bc=Ct.prototype.addToScene,wc=Ct.prototype.removeFromScene;Ct.prototype.addToScene=function(e){if(bc.call(this,e),this.__zr){var t=this.__zr;e.traverse(function(r){r.__zr=t,r.addAnimatorsToZr&&r.addAnimatorsToZr(t)})}};Ct.prototype.removeFromScene=function(e){wc.call(this,e),e.traverse(function(t){var r=t.__zr;t.__zr=null,r&&t.removeAnimatorsFromZr&&t.removeAnimatorsFromZr(r)})};yt.prototype.setTextureImage=function(e,t,r,i){if(this.shader){var n=r.getZr(),a=this,s;return a.autoUpdateTextureStatus=!1,a.disableTexture(e),Ac(t)||(s=j.loadTexture(t,r,i,function(o){a.enableTexture(e),n&&n.refresh()}),a.set(e,s)),s}};var j={};j.Renderer=vr;j.Node=dt;j.Mesh=Ji;j.Shader=N;j.Material=yt;j.Texture=q;j.Texture2D=ne;j.Geometry=Ae;j.SphereGeometry=tc;j.PlaneGeometry=an;j.CubeGeometry=Da;j.AmbientLight=ic;j.DirectionalLight=ac;j.PointLight=oc;j.SpotLight=cc;j.PerspectiveCamera=Ne;j.OrthographicCamera=xr;j.Vector2=$e;j.Vector3=P;j.Vector4=hc;j.Quaternion=ba;j.Matrix2=uc;j.Matrix2d=fc;j.Matrix3=dc;j.Matrix4=z;j.Plane=Na;j.Ray=$r;j.BoundingBox=ke;j.Frustum=tn;var zr=null;function Cc(){return zr!==null||(zr=Ft.createBlank("rgba(255,255,255,0)").image),zr}function Yn(e){return Math.pow(2,Math.round(Math.log(e)/Math.LN2))}function qn(e){if((e.wrapS===q.REPEAT||e.wrapT===q.REPEAT)&&e.image){var t=Yn(e.width),r=Yn(e.height);if(t!==e.width||r!==e.height){var i=document.createElement("canvas");i.width=t,i.height=r;var n=i.getContext("2d");n.drawImage(e.image,0,0,t,r),e.image=i}}}j.loadTexture=function(e,t,r,i){typeof r=="function"&&(i=r,r={}),r=r||{};for(var n=Object.keys(r).sort(),a="",s=0;s<n.length;s++)a+=n[s]+"_"+r[n[s]]+"_";var o=t.__textureCache=t.__textureCache||new Rs(20);if(Sc(e)){var l=e.__textureid__,c=o.get(a+l);if(c)c.texture.surface.setECharts(e),i&&i(c.texture);else{var h=new Fl(e);h.onupdate=function(){t.getZr().refresh()},c={texture:h.getTexture()};for(var s=0;s<n.length;s++)c.texture[n[s]]=r[n[s]];l=e.__textureid__||"__ecgl_ec__"+c.texture.__uid__,e.__textureid__=l,o.put(a+l,c),i&&i(c.texture)}return c.texture}else if(Oa(e)){var l=e.__textureid__,c=o.get(a+l);if(!c){c={texture:new j.Texture2D({image:e})};for(var s=0;s<n.length;s++)c.texture[n[s]]=r[n[s]];l=e.__textureid__||"__ecgl_image__"+c.texture.__uid__,e.__textureid__=l,o.put(a+l,c),qn(c.texture),i&&i(c.texture)}return c.texture}else{var c=o.get(a+e);if(c)c.callbacks?c.callbacks.push(i):i&&i(c.texture);else if(e.match(/.hdr$|^data:application\/octet-stream/)){c={callbacks:[i]};var u=Ft.loadTexture(e,{exposure:r.exposure,fileType:"hdr"},function(){u.dirty(),c.callbacks.forEach(function(v){v&&v(u)}),c.callbacks=null});c.texture=u,o.put(a+e,c)}else{for(var u=new j.Texture2D({image:new Image}),s=0;s<n.length;s++)u[n[s]]=r[n[s]];c={texture:u,callbacks:[i]};var d=u.image;d.onload=function(){u.image=d,qn(u),u.dirty(),c.callbacks.forEach(function(m){m&&m(u)}),c.callbacks=null},d.crossOrigin="Anonymous",d.src=e,u.image=Cc(),o.put(a+e,c)}return c.texture}};j.createAmbientCubemap=function(e,t,r,i){e=e||{};var n=e.texture,a=tt.firstNotNull(e.exposure,1),s=new jl({intensity:tt.firstNotNull(e.specularIntensity,1)}),o=new ql({intensity:tt.firstNotNull(e.diffuseIntensity,1),coefficients:[.844,.712,.691,-.037,.083,.167,.343,.288,.299,-.041,-.021,-.009,-.003,-.041,-.064,-.011,-.007,-.004,-.031,.034,.081,-.06,-.049,-.06,.046,.056,.05]});return s.cubemap=j.loadTexture(n,r,{exposure:a},function(){s.cubemap.flipY=!1,s.prefilter(t,32),o.coefficients=Ql.projectEnvironmentMap(t,s.cubemap,{lod:1}),i&&i()}),{specular:s,diffuse:o}};j.createBlankTexture=Ft.createBlank;j.isImage=Oa;j.additiveBlend=function(e){e.blendEquation(e.FUNC_ADD),e.blendFunc(e.SRC_ALPHA,e.ONE)};j.parseColor=function(e,t){return e instanceof Array?(t||(t=[]),t[0]=e[0],t[1]=e[1],t[2]=e[2],e.length>3?t[3]=e[3]:t[3]=1,t):(t=ua(e||"#000",t)||[0,0,0,0],t[0]/=255,t[1]/=255,t[2]/=255,t)};j.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};j.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;break}return t};j.COMMON_SHADERS=["lambert","color","realistic","hatching","shadow"];j.createShader=function(e){e==="ecgl.shadow"&&(e="ecgl.displayShadow");var t=N.source(e+".vertex"),r=N.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 N(t,r);return i.name=e,i};j.createMaterial=function(e,t){t instanceof Array||(t=[t]);var r=j.createShader(e),i=new yt({shader:r});return t.forEach(function(n){typeof n=="string"&&i.define(n)}),i};j.setMaterialFromModel=function(e,t,r,i){t.autoUpdateTextureStatus=!1;var n=r.getModel(e+"Material"),a=n.get("detailTexture"),s=tt.firstNotNull(n.get("textureTiling"),1),o=tt.firstNotNull(n.get("textureOffset"),0);typeof s=="number"&&(s=[s,s]),typeof o=="number"&&(o=[o,o]);var l=s[0]>1||s[1]>1?j.Texture.REPEAT:j.Texture.CLAMP_TO_EDGE,c={anisotropic:8,wrapS:l,wrapT:l};if(e==="realistic"){var h=n.get("roughness"),u=n.get("metalness");u!=null?isNaN(u)&&(t.setTextureImage("metalnessMap",u,i,c),u=tt.firstNotNull(n.get("metalnessAdjust"),.5)):u=0,h!=null?isNaN(h)&&(t.setTextureImage("roughnessMap",h,i,c),h=tt.firstNotNull(n.get("roughnessAdjust"),.5)):h=.5;var d=n.get("normalTexture");t.setTextureImage("detailMap",a,i,c),t.setTextureImage("normalMap",d,i,c),t.set({roughness:h,metalness:u,detailUvRepeat:s,detailUvOffset:o})}else if(e==="lambert")t.setTextureImage("detailMap",a,i,c),t.set({detailUvRepeat:s,detailUvOffset:o});else if(e==="color")t.setTextureImage("detailMap",a,i,c),t.set({detailUvRepeat:s,detailUvOffset:o});else if(e==="hatching"){var f=n.get("hatchingTextures")||[];f.length<6;for(var v=0;v<6;v++)t.setTextureImage("hatch"+(v+1),f[v],i,{anisotropic:8,wrapS:j.Texture.REPEAT,wrapT:j.Texture.REPEAT});t.set({detailUvRepeat:s,detailUvOffset:o})}};j.updateVertexAnimation=function(e,t,r,i){var n=i.get("animation"),a=i.get("animationDurationUpdate"),s=i.get("animationEasingUpdate"),o=r.shadowDepthMaterial;if(n&&t&&a>0&&t.geometry.vertexCount===r.geometry.vertexCount){r.material.define("vertex","VERTEX_ANIMATION"),r.ignorePreZ=!0,o&&o.define("vertex","VERTEX_ANIMATION");for(var l=0;l<e.length;l++)r.geometry.attributes[e[l][0]].value=t.geometry.attributes[e[l][1]].value;r.geometry.dirty(),r.__percent=0,r.material.set("percent",0),r.stopAnimation(),r.animate().when(a,{__percent:1}).during(function(){r.material.set("percent",r.__percent),o&&o.set("percent",r.__percent)}).done(function(){r.ignorePreZ=!1,r.material.undefine("vertex","VERTEX_ANIMATION"),o&&o.undefine("vertex","VERTEX_ANIMATION")}).start(s)}else r.material.undefine("vertex","VERTEX_ANIMATION"),o&&o.undefine("vertex","VERTEX_ANIMATION")};const V=j;var ce=function(e,t){this.id=e,this.zr=t;try{this.renderer=new vr({clearBit:0,devicePixelRatio:t.painter.dpr,preserveDrawingBuffer:!0,premultipliedAlpha:!0}),this.renderer.resize(t.painter.getWidth(),t.painter.getHeight())}catch(i){this.renderer=null,this.dom=document.createElement("div"),this.dom.style.cssText="position:absolute; left: 0; top: 0; right: 0; bottom: 0;",this.dom.className="ecgl-nowebgl",this.dom.innerHTML="Sorry, your browser does not support WebGL",console.error(i);return}this.onglobalout=this.onglobalout.bind(this),t.on("globalout",this.onglobalout),this.dom=this.renderer.canvas;var r=this.dom.style;r.position="absolute",r.left="0",r.top="0",this.views=[],this._picking=new jo({renderer:this.renderer}),this._viewsToDispose=[],this._accumulatingId=0,this._zrEventProxy=new fa({shape:{x:-1,y:-1,width:2,height:2},__isGLToZRProxy:!0}),this._backgroundColor=null,this._disposed=!1};ce.prototype.setUnpainted=function(){};ce.prototype.addView=function(e){if(e.layer!==this){var t=this._viewsToDispose.indexOf(e);t>=0&&this._viewsToDispose.splice(t,1),this.views.push(e),e.layer=this;var r=this.zr;e.scene.traverse(function(i){i.__zr=r,i.addAnimatorsToZr&&i.addAnimatorsToZr(r)})}};function Ba(e){var t=e.__zr;e.__zr=null,t&&e.removeAnimatorsFromZr&&e.removeAnimatorsFromZr(t)}ce.prototype.removeView=function(e){if(e.layer===this){var t=this.views.indexOf(e);t>=0&&(this.views.splice(t,1),e.scene.traverse(Ba,this),e.layer=null,this._viewsToDispose.push(e))}};ce.prototype.removeViewsAll=function(){this.views.forEach(function(e){e.scene.traverse(Ba,this),e.layer=null,this._viewsToDispose.push(e)},this),this.views.length=0};ce.prototype.resize=function(e,t){var r=this.renderer;r.resize(e,t)};ce.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)};ce.prototype.clearDepth=function(){var e=this.renderer.gl;e.clear(e.DEPTH_BUFFER_BIT)};ce.prototype.clearColor=function(){var e=this.renderer.gl;e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)};ce.prototype.needsRefresh=function(){this.zr.refresh()};ce.prototype.refresh=function(e){this._backgroundColor=e?V.parseColor(e):[0,0,0,0],this.renderer.clearColor=this._backgroundColor;for(var t=0;t<this.views.length;t++)this.views[t].prepareRender(this.renderer);this._doRender(!1),this._trackAndClean();for(var t=0;t<this._viewsToDispose.length;t++)this._viewsToDispose[t].dispose(this.renderer);this._viewsToDispose.length=0,this._startAccumulating()};ce.prototype.renderToCanvas=function(e){this._startAccumulating(!0),e.drawImage(this.dom,0,0,e.canvas.width,e.canvas.height)};ce.prototype._doRender=function(e){this.clear(),this.renderer.saveViewport();for(var t=0;t<this.views.length;t++)this.views[t].render(this.renderer,e);this.renderer.restoreViewport()};ce.prototype._stopAccumulating=function(){this._accumulatingId=0,clearTimeout(this._accumulatingTimeout)};var Rc=1;ce.prototype._startAccumulating=function(e){var t=this;this._stopAccumulating();for(var r=!1,i=0;i<this.views.length;i++)r=this.views[i].needsAccumulate()||r;if(!r)return;function n(a){if(!(!t._accumulatingId||a!==t._accumulatingId)){for(var s=!0,o=0;o<t.views.length;o++)s=t.views[o].isAccumulateFinished()&&r;s||(t._doRender(!0),e?n(a):Ns(function(){n(a)}))}}this._accumulatingId=Rc++,e?n(t._accumulatingId):this._accumulatingTimeout=setTimeout(function(){n(t._accumulatingId)},50)};ce.prototype._trackAndClean=function(){var e=[],t=[];this._textureList&&(Qr(this._textureList),Qr(this._geometriesList));for(var r=0;r<this.views.length;r++)Mc(this.views[r].scene,e,t);this._textureList&&(Jr(this.renderer,this._textureList),Jr(this.renderer,this._geometriesList)),this._textureList=e,this._geometriesList=t};function Qr(e){for(var t=0;t<e.length;t++)e[t].__used__=0}function Jr(e,t){for(var r=0;r<t.length;r++)t[r].__used__||t[r].dispose(e)}function Gr(e,t){e.__used__=e.__used__||0,e.__used__++,e.__used__===1&&t.push(e)}function Mc(e,t,r){var i,n;e.traverse(function(s){if(s.isRenderable()){var o=s.geometry,l=s.material;if(l!==i)for(var c=l.getTextureUniforms(),h=0;h<c.length;h++){var u=c[h],d=l.uniforms[u].value;if(d){if(d instanceof q)Gr(d,t);else if(d instanceof Array)for(var f=0;f<d.length;f++)d[f]instanceof q&&Gr(d[f],t)}}o!==n&&Gr(o,r),i=l,n=o}});for(var a=0;a<e.lights.length;a++)e.lights[a].cubemap&&Gr(e.lights[a].cubemap,t)}ce.prototype.dispose=function(){this._disposed||(this._stopAccumulating(),this._textureList&&(Qr(this._textureList),Qr(this._geometriesList),Jr(this.renderer,this._textureList),Jr(this.renderer,this._geometriesList)),this.zr.off("globalout",this.onglobalout),this._disposed=!0)};ce.prototype.onmousedown=function(e){if(!(e.target&&e.target.__isGLToZRProxy)){e=e.event;var t=this.pickObject(e.offsetX,e.offsetY);t&&(this._dispatchEvent("mousedown",e,t),this._dispatchDataEvent("mousedown",e,t)),this._downX=e.offsetX,this._downY=e.offsetY}};ce.prototype.onmousemove=function(e){if(!(e.target&&e.target.__isGLToZRProxy)){e=e.event;var t=this.pickObject(e.offsetX,e.offsetY),r=t&&t.target,i=this._hovered;this._hovered=t,i&&r!==i.target&&(i.relatedTarget=r,this._dispatchEvent("mouseout",e,i),this.zr.setCursorStyle("default")),this._dispatchEvent("mousemove",e,t),t&&(this.zr.setCursorStyle("pointer"),(!i||r!==i.target)&&this._dispatchEvent("mouseover",e,t)),this._dispatchDataEvent("mousemove",e,t)}};ce.prototype.onmouseup=function(e){if(!(e.target&&e.target.__isGLToZRProxy)){e=e.event;var t=this.pickObject(e.offsetX,e.offsetY);t&&(this._dispatchEvent("mouseup",e,t),this._dispatchDataEvent("mouseup",e,t)),this._upX=e.offsetX,this._upY=e.offsetY}};ce.prototype.onclick=ce.prototype.dblclick=function(e){if(!(e.target&&e.target.__isGLToZRProxy)){var t=this._upX-this._downX,r=this._upY-this._downY;if(!(Math.sqrt(t*t+r*r)>20)){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);if(n){var a=n.view.setDOFFocusOnPoint(n.distance);a&&this.zr.refresh()}}}};ce.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};ce.prototype.onglobalout=function(e){var t=this._hovered;t&&this._dispatchEvent("mouseout",e,{target:t.target})};ce.prototype.pickObject=function(e,t){for(var r=[],i=this.renderer,n=i.viewport,a=0;a<this.views.length;a++){var s=this.views[a];s.containPoint(e,t)&&(this._picking.scene=s.scene,this._picking.camera=s.camera,i.viewport=s.viewport,this._picking.pickAll(e,t,r))}return i.viewport=n,r.sort(function(o,l){return o.distance-l.distance}),r[0]};ce.prototype._dispatchEvent=function(e,t,r){r||(r={});var i=r.target;for(r.cancelBubble=!1,r.event=t,r.type=e,r.offsetX=t.offsetX,r.offsetY=t.offsetY;i&&(i.trigger(e,r),i=i.getParent(),!r.cancelBubble););this._dispatchToView(e,r)};ce.prototype._dispatchDataEvent=function(e,t,r){var i=r&&r.target,n=i&&i.dataIndex,a=i&&i.seriesIndex,s=i&&i.eventData,o=!1,l=this._zrEventProxy;l.x=t.offsetX,l.y=t.offsetY,l.update();var c={target:l};const h=Ms(l);e==="mousemove"&&(n!=null?n!==this._lastDataIndex&&(parseInt(this._lastDataIndex,10)>=0&&(h.dataIndex=this._lastDataIndex,h.seriesIndex=this._lastSeriesIndex,this.zr.handler.dispatchToElement(c,"mouseout",t)),o=!0):s!=null&&s!==this._lastEventData&&(this._lastEventData!=null&&(h.eventData=this._lastEventData,this.zr.handler.dispatchToElement(c,"mouseout",t)),o=!0),this._lastEventData=s,this._lastDataIndex=n,this._lastSeriesIndex=a),h.eventData=s,h.dataIndex=n,h.seriesIndex=a,(s!=null||parseInt(n,10)>=0&&parseInt(a,10)>=0)&&(this.zr.handler.dispatchToElement(c,e,t),o&&this.zr.handler.dispatchToElement(c,"mouseover",t))};ce.prototype._dispatchToView=function(e,t){for(var r=0;r<this.views.length;r++)this.views[r].containPoint(t.offsetX,t.offsetY)&&this.views[r].trigger(e,t)};Object.assign(ce.prototype,$i);const Fa=ce;var Nc=["bar3D","line3D","map3D","scatter3D","surface","lines3D","scatterGL","scatter3D"];function dr(e,t){if(e&&e[t]&&(e[t].normal||e[t].emphasis)){var r=e[t].normal,i=e[t].emphasis;r&&(e[t]=r),i&&(e.emphasis=e.emphasis||{},e.emphasis[t]=i)}}function Lc(e){dr(e,"itemStyle"),dr(e,"lineStyle"),dr(e,"areaStyle"),dr(e,"label")}function kr(e){e&&(e instanceof Array||(e=[e]),pr(e,function(t){if(t.axisLabel){var r=t.axisLabel;Object.assign(r,r.textStyle),r.textStyle=null}}))}function Pc(e){pr(e.series,function(t){Ls(Nc,t.type)>=0&&(Lc(t),t.coordinateSystem==="mapbox"&&(t.coordinateSystem="mapbox3D",e.mapbox3D=e.mapbox))}),kr(e.xAxis3D),kr(e.yAxis3D),kr(e.zAxis3D),kr(e.grid3D),dr(e.geo3D)}function Ua(e){this._layers={},this._zr=e}Ua.prototype.update=function(e,t){var r=this,i=t.getZr();if(!i.getWidth()||!i.getHeight()){console.warn("Dom has no width or height");return}function n(o){i.setSleepAfterStill(0);var l;o.coordinateSystem&&o.coordinateSystem.model,l=o.get("zlevel");var c=r._layers,h=c[l];if(!h){if(h=c[l]=new Fa("gl-"+l,i),i.painter.isSingleCanvas()){h.virtual=!0;var u=new Os({z:1e4,style:{image:h.renderer.canvas},silent:!0});h.__hostImage=u,i.add(u)}i.painter.insertLayer(l,h)}return h.__hostImage&&h.__hostImage.setStyle({width:h.renderer.getWidth(),height:h.renderer.getHeight()}),h}function a(o,l){o&&o.traverse(function(c){c.isRenderable&&c.isRenderable()&&(c.ignorePicking=c.$ignorePicking!=null?c.$ignorePicking:l)})}for(var s in this._layers)this._layers[s].removeViewsAll();e.eachComponent(function(o,l){if(o!=="series"){var c=t.getViewOfComponentModel(l),h=l.coordinateSystem;if(c.__ecgl__){var u;if(h){if(!h.viewGL){console.error("Can't find viewGL in coordinateSystem of component "+l.id);return}u=h.viewGL}else{if(!l.viewGL){console.error("Can't find viewGL of component "+l.id);return}u=h.viewGL}var u=h.viewGL,d=n(l);d.addView(u),c.afterRender&&c.afterRender(l,e,t,d),a(c.groupGL,l.get("silent"))}}}),e.eachSeries(function(o){var l=t.getViewOfSeriesModel(o),c=o.coordinateSystem;if(l.__ecgl__){if(c&&!c.viewGL&&!l.viewGL){console.error("Can't find viewGL of series "+l.id);return}var h=c&&c.viewGL||l.viewGL,u=n(o);u.addView(h),l.afterRender&&l.afterRender(o,e,t,u),a(l.groupGL,o.get("silent"))}})};Ps(function(e){var t=e.getZr(),r=t.painter.dispose;t.painter.dispose=function(){typeof this.eachOtherLayer=="function"&&this.eachOtherLayer(function(i){i instanceof Fa&&i.dispose()}),r.call(this)},t.painter.getRenderedCanvas=function(i){if(i=i||{},this._singleCanvas)return this._layers[0].dom;var n=document.createElement("canvas"),a=i.pixelRatio||this.dpr;n.width=this.getWidth()*a,n.height=this.getHeight()*a;var s=n.getContext("2d");s.dpr=a,s.clearRect(0,0,n.width,n.height),i.backgroundColor&&(s.fillStyle=i.backgroundColor,s.fillRect(0,0,n.width,n.height));var o=this.storage.getDisplayList(!0),l={},c,h=this;function u(m,p){var _=h._zlevelList;m==null&&(m=-1/0);for(var T,y=0;y<_.length;y++){var g=_[y],E=h._layers[g];if(!E.__builtin__&&g>m&&g<p){T=E;break}}T&&T.renderToCanvas&&(s.save(),T.renderToCanvas(s),s.restore())}for(var d={ctx:s},f=0;f<o.length;f++){var v=o[f];v.zlevel!==c&&(u(c,v.zlevel),c=v.zlevel),this._doPaintEl(v,d,!0,null,l)}return u(c,1/0),n}});Ds(function(e,t){var r=t.getZr(),i=r.__egl=r.__egl||new Ua(r);i.update(e,t)});Is(Pc);const Dc={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||{},e.alpha!=null&&(this.option.viewControl.alpha=e.alpha),e.beta!=null&&(this.option.viewControl.beta=e.beta),e.distance!=null&&(this.option.viewControl.distance=e.distance),e.center!=null&&(this.option.viewControl.center=e.center)}},Ic={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"}}},Oc={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 li=da.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}}});_t(li.prototype,Dc);_t(li.prototype,Ic);_t(li.prototype,Oc);const Bc=li;var hr=tt.firstNotNull,Zn={left:0,middle:1,right:2};function $n(e){return e instanceof Array||(e=[e,e]),e}var Ha=qe.extend(function(){return{zr:null,viewGL:null,_center:new P,minDistance:.5,maxDistance:1.5,maxOrthographicSize:300,minOrthographicSize:30,minAlpha:-90,maxAlpha:90,minBeta:-1/0,maxBeta:1/0,autoRotateAfterStill:0,autoRotateDirection:"cw",autoRotateSpeed:60,damping:.8,rotateSensitivity:1,zoomSensitivity:1,panSensitivity:1,panMouseButton:"middle",rotateMouseButton:"left",_mode:"rotate",_camera:null,_needsUpdate:!1,_rotating:!1,_phi:0,_theta:0,_mouseX:0,_mouseY:0,_rotateVelocity:new $e,_panVelocity:new $e,_distance:500,_zoomSpeed:0,_stillTimeout:0,_animators:[]}},function(){["_mouseDownHandler","_mouseWheelHandler","_mouseMoveHandler","_mouseUpHandler","_pinchHandler","_contextMenuHandler","_update"].forEach(function(e){this[e]=this[e].bind(this)},this)},{init:function(){var e=this.zr;e&&(e.on("mousedown",this._mouseDownHandler),e.on("globalout",this._mouseUpHandler),e.on("mousewheel",this._mouseWheelHandler),e.on("pinch",this._pinchHandler),e.animation.on("frame",this._update),e.dom.addEventListener("contextmenu",this._contextMenuHandler))},dispose:function(){var e=this.zr;e&&(e.off("mousedown",this._mouseDownHandler),e.off("mousemove",this._mouseMoveHandler),e.off("mouseup",this._mouseUpHandler),e.off("mousewheel",this._mouseWheelHandler),e.off("pinch",this._pinchHandler),e.off("globalout",this._mouseUpHandler),e.dom.removeEventListener("contextmenu",this._contextMenuHandler),e.animation.off("frame",this._update)),this.stopAllAnimation()},getDistance:function(){return this._distance},setDistance:function(e){this._distance=e,this._needsUpdate=!0},getOrthographicSize:function(){return this._orthoSize},setOrthographicSize:function(e){this._orthoSize=e,this._needsUpdate=!0},getAlpha:function(){return this._theta/Math.PI*180},getBeta:function(){return-this._phi/Math.PI*180},getCenter:function(){return this._center.toArray()},setAlpha:function(e){e=Math.max(Math.min(this.maxAlpha,e),this.minAlpha),this._theta=e/180*Math.PI,this._needsUpdate=!0},setBeta:function(e){e=Math.max(Math.min(this.maxBeta,e),this.minBeta),this._phi=-e/180*Math.PI,this._needsUpdate=!0},setCenter:function(e){this._center.setArray(e)},setViewGL:function(e){this.viewGL=e},getCamera:function(){return this.viewGL.camera},setFromViewControlModel:function(e,t){t=t||{};var r=t.baseDistance||0,i=t.baseOrthoSize||1,n=e.get("projection");n!=="perspective"&&n!=="orthographic"&&n!=="isometric"&&(n="perspective"),this._projection=n,this.viewGL.setProjection(n);var a=e.get("distance")+r,s=e.get("orthographicSize")+i;[["damping",.8],["autoRotate",!1],["autoRotateAfterStill",3],["autoRotateDirection","cw"],["autoRotateSpeed",10],["minDistance",30],["maxDistance",400],["minOrthographicSize",30],["maxOrthographicSize",300],["minAlpha",-90],["maxAlpha",90],["minBeta",-1/0],["maxBeta",1/0],["rotateSensitivity",1],["zoomSensitivity",1],["panSensitivity",1],["panMouseButton","left"],["rotateMouseButton","middle"]].forEach(function(d){this[d[0]]=hr(e.get(d[0]),d[1])},this),this.minDistance+=r,this.maxDistance+=r,this.minOrthographicSize+=i,this.maxOrthographicSize+=i;var o=e.ecModel,l={};["animation","animationDurationUpdate","animationEasingUpdate"].forEach(function(d){l[d]=hr(e.get(d),o&&o.get(d))});var c=hr(t.alpha,e.get("alpha"))||0,h=hr(t.beta,e.get("beta"))||0,u=hr(t.center,e.get("center"))||[0,0,0];l.animation&&l.animationDurationUpdate>0&&this._notFirst?this.animateTo({alpha:c,beta:h,center:u,distance:a,orthographicSize:s,easing:l.animationEasingUpdate,duration:l.animationDurationUpdate}):(this.setDistance(a),this.setAlpha(c),this.setBeta(h),this.setCenter(u),this.setOrthographicSize(s)),this._notFirst=!0,this._validateProperties()},_validateProperties:function(){},animateTo:function(e){var t=this.zr,r=this,i={},n={};return e.distance!=null&&(i.distance=this.getDistance(),n.distance=e.distance),e.orthographicSize!=null&&(i.orthographicSize=this.getOrthographicSize(),n.orthographicSize=e.orthographicSize),e.alpha!=null&&(i.alpha=this.getAlpha(),n.alpha=e.alpha),e.beta!=null&&(i.beta=this.getBeta(),n.beta=e.beta),e.center!=null&&(i.center=this.getCenter(),n.center=e.center),this._addAnimator(t.animation.animate(i).when(e.duration||1e3,n).during(function(){i.alpha!=null&&r.setAlpha(i.alpha),i.beta!=null&&r.setBeta(i.beta),i.distance!=null&&r.setDistance(i.distance),i.center!=null&&r.setCenter(i.center),i.orthographicSize!=null&&r.setOrthographicSize(i.orthographicSize),r._needsUpdate=!0})).start(e.easing||"linear")},stopAllAnimation:function(){for(var e=0;e<this._animators.length;e++)this._animators[e].stop();this._animators.length=0},update:function(){this._needsUpdate=!0,this._update(20)},_isAnimating:function(){return this._animators.length>0},_update:function(e){if(this._rotating){var t=(this.autoRotateDirection==="cw"?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){this._projection==="perspective"?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 P,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},e*1e3))},_vectorDamping:function(e,t){var r=e.len();r=r*t,r<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?e.event.targetTouches.length===1&&(this._mode="rotate"):e.event.button===Zn[this.rotateMouseButton]?this._mode="rotate":e.event.button===Zn[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=$n(this.panSensitivity),r=$n(this.rotateSensitivity);this._mode==="rotate"?(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]):this._mode==="pan"&&(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(t!==0){var r=e.offsetX,i=e.offsetY;if(!(this.viewGL&&!this.viewGL.containPoint(r,i))){var n;this._projection==="perspective"?n=Math.max(Math.max(Math.min(this._distance-this.minDistance,this.maxDistance-this._distance))/20,.5):n=Math.max(Math.max(Math.min(this._orthoSize-this.minOrthographicSize,this.maxOrthographicSize-this._orthoSize))/20,.5),this._zoomSpeed=(t>0?-1:1)*n*this.zoomSensitivity,this._rotating=!1,this.autoRotate&&this._mode==="rotate"&&this._startCountingStill(),e.event.preventDefault()}}},_mouseUpHandler:function(){this.zr.off("mousemove",this._mouseMoveHandler),this.zr.off("mouseup",this._mouseUpHandler)},_isRightMouseButtonUsed:function(){return this.rotateMouseButton==="right"||this.panMouseButton==="right"},_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(Ha.prototype,"autoRotate",{get:function(e){return this._autoRotate},set:function(e){this._autoRotate=e,this._rotating=e}});const Fc=Ha,on={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()}},ci={vec2:H,vec3:x,vec4:D,mat2:xe,mat2d:Se,mat3:ee,mat4:C,quat:Y};var Mi=ci.vec3,Kn=[[0,0],[1,1]],za=Ae.extend(function(){return{segmentScale:1,dynamic:!0,useNativeLine:!0,attributes:{position:new Ae.Attribute("position","float",3,"POSITION"),positionPrev:new Ae.Attribute("positionPrev","float",3),positionNext:new Ae.Attribute("positionNext","float",3),prevPositionPrev:new Ae.Attribute("prevPositionPrev","float",3),prevPosition:new Ae.Attribute("prevPosition","float",3),prevPositionNext:new Ae.Attribute("prevPositionNext","float",3),offset:new Ae.Attribute("offset","float",1),color:new Ae.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&&(e===0?this.indices=null:this.indices=this.vertexCount>65535?new Uint32Array(e*3):new Uint16Array(e*3))},_getCubicCurveApproxStep:function(e,t,r,i){var n=Mi.dist(e,t)+Mi.dist(r,t)+Mi.dist(i,r),a=1/(n+1)*this.segmentScale;return a},getCubicCurveVertexCount:function(e,t,r,i){var n=this._getCubicCurveApproxStep(e,t,r,i),a=Math.ceil(1/n);return this.useNativeLine?a*2:a*2+2},getCubicCurveTriangleCount:function(e,t,r,i){var n=this._getCubicCurveApproxStep(e,t,r,i),a=Math.ceil(1/n);return this.useNativeLine?0:a*2},getLineVertexCount:function(){return this.getPolylineVertexCount(Kn)},getLineTriangleCount:function(){return this.getPolylineTriangleCount(Kn)},getPolylineVertexCount:function(e){var t;if(typeof e=="number")t=e;else{var r=typeof e[0]!="number";t=r?e.length:e.length/3}return this.useNativeLine?(t-1)*2:(t-1)*2+2},getPolylineTriangleCount:function(e){var t;if(typeof e=="number")t=e;else{var r=typeof e[0]!="number";t=r?e.length:e.length/3}return this.useNativeLine?0:Math.max(t-1,0)*2},addCubicCurve:function(e,t,r,i,n,a){a==null&&(a=1);for(var s=e[0],o=e[1],l=e[2],c=t[0],h=t[1],u=t[2],d=r[0],f=r[1],v=r[2],m=i[0],p=i[1],_=i[2],T=this._getCubicCurveApproxStep(e,t,r,i),y=T*T,g=y*T,E=3*T,S=3*y,R=6*y,b=6*g,M=s-c*2+d,F=o-h*2+f,w=l-u*2+v,U=(c-d)*3-s+m,O=(h-f)*3-o+p,L=(u-v)*3-l+_,G=s,B=o,Z=l,I=(c-s)*E+M*S+U*g,ue=(h-o)*E+F*S+O*g,k=(u-l)*E+w*S+L*g,ye=M*R+U*b,ae=F*R+O*b,ve=w*R+L*b,me=U*b,Oe=O*b,Be=L*b,Re=0,ze=0,Ze=Math.ceil(1/T),Fe=new Float32Array((Ze+1)*3),Fe=[],rt=0,ze=0;ze<Ze+1;ze++)Fe[rt++]=G,Fe[rt++]=B,Fe[rt++]=Z,G+=I,B+=ue,Z+=k,I+=ye,ue+=ae,k+=ve,ye+=me,ae+=Oe,ve+=Be,Re+=T,Re>1&&(G=I>0?Math.min(G,m):Math.max(G,m),B=ue>0?Math.min(B,p):Math.max(B,p),Z=k>0?Math.min(Z,_):Math.max(Z,_));return this.addPolyline(Fe,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=typeof e[0]!="number";if(n==null&&(n=a?e.length:e.length/3),!(n<2)){i==null&&(i=0),r==null&&(r=1),this._itemVertexOffsets.push(this._vertexOffset);var a=typeof e[0]!="number",s=a?typeof t[0]!="number":t.length/4===n,o=this.attributes.position,l=this.attributes.positionPrev,c=this.attributes.positionNext,h=this.attributes.color,u=this.attributes.offset,d=this.indices,f=this._vertexOffset,v,m;r=Math.max(r,.01);for(var p=i;p<n;p++){if(a)v=e[p],s?m=t[p]:m=t;else{var _=p*3;if(v=v||[],v[0]=e[_],v[1]=e[_+1],v[2]=e[_+2],s){var T=p*4;m=m||[],m[0]=t[T],m[1]=t[T+1],m[2]=t[T+2],m[3]=t[T+3]}else m=t}if(this.useNativeLine?p>1&&(o.copy(f,f-1),h.copy(f,f-1),f++):(p<n-1&&(l.set(f+2,v),l.set(f+3,v)),p>0&&(c.set(f-2,v),c.set(f-1,v)),o.set(f,v),o.set(f+1,v),h.set(f,m),h.set(f+1,m),u.set(f,r/2),u.set(f+1,-r/2),f+=2),this.useNativeLine)h.set(f,m),o.set(f,v),f++;else if(p>0){var y=this._triangleOffset*3,d=this.indices;d[y]=f-4,d[y+1]=f-3,d[y+2]=f-2,d[y+3]=f-3,d[y+4]=f-1,d[y+5]=f-2,this._triangleOffset+=2}}if(!this.useNativeLine){var g=this._vertexOffset,E=this._vertexOffset+n*2;l.copy(g,g+2),l.copy(g+1,g+3),c.copy(E-1,E-3),c.copy(E-2,E-4)}return this._vertexOffset=f,this._vertexOffset}}},setItemColor:function(e,t){for(var r=this._itemVertexOffsets[e],i=e<this._itemVertexOffsets.length-1?this._itemVertexOffsets[e+1]:this._vertexOffset,n=r;n<i;n++)this.attributes.color.set(n,t);this.dirty("color")},currentTriangleOffset:function(){return this._triangleOffset},currentVertexOffset:function(){return this._vertexOffset}});Ar(za.prototype,on);const ln=za;function ei(e,t,r,i,n,a,s){this._zr=e,this._x=0,this._y=0,this._rowHeight=0,this.width=i,this.height=n,this.offsetX=t,this.offsetY=r,this.dpr=s,this.gap=a}ei.prototype={constructor:ei,clear:function(){this._x=0,this._y=0,this._rowHeight=0},add:function(e,t,r){var i=e.getBoundingRect();t==null&&(t=i.width),r==null&&(r=i.height),t*=this.dpr,r*=this.dpr,this._fitElement(e,t,r);var n=this._x,a=this._y,s=this.width*this.dpr,o=this.height*this.dpr,l=this.gap;if(n+t+l>s&&(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>o)return null;e.x+=this.offsetX*this.dpr+n,e.y+=this.offsetY*this.dpr+a,this._zr.add(e);var c=[this.offsetX/this.width,this.offsetY/this.height],h=[[n/s+c[0],a/o+c[1]],[(n+t)/s+c[0],(a+r)/o+c[1]]];return h},_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()}};function Wi(e){e=e||{},e.width=e.width||512,e.height=e.height||512,e.devicePixelRatio=e.devicePixelRatio||1,e.gap=e.gap==null?2:e.gap;var t=document.createElement("canvas");t.width=e.width*e.devicePixelRatio,t.height=e.height*e.devicePixelRatio,this._canvas=t,this._texture=new ne({image:t,flipY:!1});var r=this;this._zr=Bs(t);var i=this._zr.refreshImmediately;this._zr.refreshImmediately=function(){i.call(this),r._texture.dirty(),r.onupdate&&r.onupdate()},this._dpr=e.devicePixelRatio,this._coords={},this.onupdate=e.onupdate,this._gap=e.gap,this._textureAtlasNodes=[new ei(this._zr,0,0,e.width,e.height,this._gap,this._dpr)],this._nodeWidth=e.width,this._nodeHeight=e.height,this._currentNodeIdx=0}Wi.prototype={clear:function(){for(var e=0;e<this._textureAtlasNodes.length;e++)this._textureAtlasNodes[e].clear();this._currentNodeIdx=0,this._zr.clear(),this._coords={}},getWidth:function(){return this._width},getHeight:function(){return this._height},getTexture:function(){return this._texture},getDevicePixelRatio:function(){return this._dpr},getZr:function(){return this._zr},_getCurrentNode:function(){return this._textureAtlasNodes[this._currentNodeIdx]},_expand:function(){if(this._currentNodeIdx++,this._textureAtlasNodes[this._currentNodeIdx])return this._textureAtlasNodes[this._currentNodeIdx];var e=4096/this._dpr,t=this._textureAtlasNodes,r=t.length,i=r*this._nodeWidth%e,n=Math.floor(r*this._nodeWidth/e)*this._nodeHeight;if(!(n>=e)){var a=(i+this._nodeWidth)*this._dpr,s=(n+this._nodeHeight)*this._dpr;try{this._zr.resize({width:a,height:s})}catch{this._canvas.width=a,this._canvas.height=s}var o=new ei(this._zr,i,n,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()}};function Xi(){}Xi.prototype={constructor:Xi,setScene:function(e){this._scene=e,this._skybox&&this._skybox.attachScene(this._scene)},initLight:function(e){this._lightRoot=e,this.mainLight=new V.DirectionalLight({shadowBias:.005}),this.ambientLight=new V.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=V.parseColor(n.get("color")).slice(0,3),r.color=V.parseColor(a.get("color")).slice(0,3);var s=n.get("alpha")||0,o=n.get("beta")||0;t.position.setArray(V.directionFromAlphaBeta(s,o)),t.lookAt(V.Vector3.ZERO),t.castShadow=n.get("shadow"),t.shadowResolution=V.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 s=this;a=this._cubemapLightsCache[n]=V.createAmbientCubemap(i.option,e,r,function(){s._isSkyboxFromAmbientCubemap&&s._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 i=t.get("environment"),n=this;function a(){return n._skybox=n._skybox||new yr,n._skybox}var s=a();if(i&&i!=="none")if(i==="auto")if(this._isSkyboxFromAmbientCubemap=!0,this._currentCubemapLights){var o=this._currentCubemapLights.specular.cubemap;s.setEnvironmentMap(o),this._scene&&s.attachScene(this._scene),s.material.set("lod",3)}else this._skybox&&this._skybox.detachScene();else if(typeof i=="object"&&i.colorStops||typeof i=="string"&&ua(i)){this._isSkyboxFromAmbientCubemap=!1;var l=new V.Texture2D({anisotropic:8,flipY:!1});s.setEnvironmentMap(l);var c=l.image=document.createElement("canvas");c.width=c.height=16;var h=c.getContext("2d"),u=new fa({shape:{x:0,y:0,width:16,height:16},style:{fill:i}});Fs(h,u),s.attachScene(this._scene)}else{this._isSkyboxFromAmbientCubemap=!1;var l=V.loadTexture(i,r,{anisotropic:8,flipY:!1});s.setEnvironmentMap(l),s.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&&i!=="auto"&&!(i.match&&i.match(/.hdr$/))){var f=d.viewGL.isLinearSpace()?"define":"undefine";this._skybox.material[f]("fragment","SRGB_DECODE")}else this._skybox.material.undefine("fragment","SRGB_DECODE")}};var Nt=ci.vec3,Ga=Ae.extend(function(){return{segmentScale:1,useNativeLine:!0,attributes:{position:new Ae.Attribute("position","float",3,"POSITION"),normal:new Ae.Attribute("normal","float",3,"NORMAL"),color:new Ae.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(i*3):new Uint16Array(i*3))},getQuadVertexCount:function(){return 4},getQuadTriangleCount:function(){return 2},addQuad:function(){var e=Nt.create(),t=Nt.create(),r=Nt.create(),i=[0,3,1,3,2,1];return function(n,a){var s=this.attributes.position,o=this.attributes.normal,l=this.attributes.color;Nt.sub(e,n[1],n[0]),Nt.sub(t,n[2],n[1]),Nt.cross(r,e,t),Nt.normalize(r,r);for(var c=0;c<4;c++)s.set(this._vertexOffset+c,n[c]),l.set(this._vertexOffset+c,a),o.set(this._vertexOffset+c,r);for(var h=this._faceOffset*3,c=0;c<6;c++)this.indices[h+c]=i[c]+this._vertexOffset;this._vertexOffset+=4,this._faceOffset+=2}}()});Ar(Ga.prototype,on);const Uc=Ga;var ji=tt.firstNotNull,Hc={x:0,y:2,z:1};function zc(e,t,r,i){var n=[0,0,0],a=i<0?r.getExtentMin():r.getExtentMax();n[Hc[r.dim]]=a,e.position.setArray(n),e.rotation.identity(),t.distance=-Math.abs(a),t.normal.set(0,0,0),r.dim==="x"?(e.rotation.rotateY(i*Math.PI/2),t.normal.x=-i):r.dim==="z"?(e.rotation.rotateX(-i*Math.PI/2),t.normal.y=-i):(i>0&&e.rotation.rotateY(Math.PI),t.normal.z=-i)}function hi(e,t,r){this.rootNode=new V.Node;var i=new V.Mesh({geometry:new ln({useNativeLine:!1}),material:t,castShadow:!1,ignorePicking:!0,$ignorePicking:!0,renderOrder:1}),n=new V.Mesh({geometry:new Uc,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 V.Plane,this.linesMesh=i,this.quadsMesh=n}hi.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,s=this.quadsMesh.geometry;a.convertToDynamicArray(!0),s.convertToDynamicArray(!0),this._updateSplitLines(a,n,e,r),this._udpateSplitAreas(s,n,e,r),a.convertToTypedArray(),s.convertToTypedArray();var o=i.getAxis(this.faceInfo[2]);zc(this.rootNode,this.plane,o,this.faceInfo[3])};hi.prototype._updateSplitLines=function(e,t,r,i){var n=i.getDevicePixelRatio();t.forEach(function(a,s){var o=a.model,l=t[1-s].getExtent();if(!a.scale.isBlank()){var c=o.getModel("splitLine",r.getModel("splitLine"));if(c.get("show")){var h=c.getModel("lineStyle"),u=h.get("color"),d=ji(h.get("opacity"),1),f=ji(h.get("width"),1);u=mr(u)?u:[u];for(var v=a.getTicksCoords({tickModel:c}),m=0,p=0;p<v.length;p++){var _=v[p].coord,T=V.parseColor(u[m%u.length]);T[3]*=d;var y=[0,0,0],g=[0,0,0];y[s]=g[s]=_,y[1-s]=l[0],g[1-s]=l[1],e.addLine(y,g,T,f*n),m++}}}})};hi.prototype._udpateSplitAreas=function(e,t,r,i){t.forEach(function(n,a){var s=n.model,o=t[1-a].getExtent();if(!n.scale.isBlank()){var l=s.getModel("splitArea",r.getModel("splitArea"));if(l.get("show")){var c=l.getModel("areaStyle"),h=c.get("color"),u=ji(c.get("opacity"),1);h=mr(h)?h:[h];for(var d=n.getTicksCoords({tickModel:l,clamp:!0}),f=0,v=[0,0,0],m=[0,0,0],p=0;p<d.length;p++){var _=d[p].coord,T=[0,0,0],y=[0,0,0];if(T[a]=y[a]=_,T[1-a]=o[0],y[1-a]=o[1],p===0){v=T,m=y;continue}var g=V.parseColor(h[f%h.length]);g[3]*=u,e.addQuad([v,T,y,m],g),v=T,m=y,f++}}}})};var Qn=[0,1,2,0,2,3],ka=Ae.extend(function(){return{attributes:{position:new Ae.Attribute("position","float",3,"POSITION"),texcoord:new Ae.Attribute("texcoord","float",2,"TEXCOORD_0"),offset:new Ae.Attribute("offset","float",2),color:new Ae.Attribute("color","float",4,"COLOR")}}},{resetOffset:function(){this._vertexOffset=0,this._faceOffset=0},setSpriteCount:function(e){this._spriteCount=e;var t=e*4,r=e*2;this.vertexCount!==t&&(this.attributes.position.init(t),this.attributes.offset.init(t),this.attributes.color.init(t)),this.triangleCount!==r&&(this.indices=t>65535?new Uint32Array(r*3):new Uint16Array(r*3))},setSpriteAlign:function(e,t,r,i,n){r==null&&(r="left"),i==null&&(i="top");var a,s,o,l;switch(n=n||0,r){case"left":a=n,o=t[0]+n;break;case"center":case"middle":a=-t[0]/2,o=t[0]/2;break;case"right":a=-t[0]-n,o=-n;break}switch(i){case"bottom":s=n,l=t[1]+n;break;case"middle":s=-t[1]/2,l=t[1]/2;break;case"top":s=-t[1]-n,l=-n;break}var c=e*4,h=this.attributes.offset;h.set(c,[a,l]),h.set(c+1,[o,l]),h.set(c+2,[o,s]),h.set(c+3,[a,s])},addSprite:function(e,t,r,i,n,a){var s=this._vertexOffset;this.setSprite(this._vertexOffset/4,e,t,r,i,n,a);for(var o=0;o<Qn.length;o++)this.indices[this._faceOffset*3+o]=Qn[o]+s;return this._faceOffset+=2,this._vertexOffset+=4,s/4},setSprite:function(e,t,r,i,n,a,s){for(var o=e*4,l=this.attributes,c=0;c<4;c++)l.position.set(o+c,t);var h=l.texcoord;h.set(o,[i[0][0],i[0][1]]),h.set(o+1,[i[1][0],i[0][1]]),h.set(o+2,[i[1][0],i[1][1]]),h.set(o+3,[i[0][0],i[1][1]]),this.setSpriteAlign(e,r,n,a,s)}});Ar(ka.prototype,on);const Gc=ka,kc="@export ecgl.labels.vertex\n\nattribute vec3 position: POSITION;\nattribute vec2 texcoord: TEXCOORD_0;\nattribute vec2 offset;\n#ifdef VERTEX_COLOR\nattribute vec4 a_Color : COLOR;\nvarying vec4 v_Color;\n#endif\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nuniform vec4 viewport : VIEWPORT;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n vec4 proj = worldViewProjection * vec4(position, 1.0);\n\n vec2 screen = (proj.xy / abs(proj.w) + 1.0) * 0.5 * viewport.zw;\n\n screen += offset;\n\n proj.xy = (screen / viewport.zw - 0.5) * 2.0 * abs(proj.w);\n gl_Position = proj;\n#ifdef VERTEX_COLOR\n v_Color = a_Color;\n#endif\n v_Texcoord = texcoord;\n}\n@end\n\n\n@export ecgl.labels.fragment\n\nuniform vec3 color : [1.0, 1.0, 1.0];\nuniform float alpha : 1.0;\nuniform sampler2D textureAtlas;\nuniform vec2 uvScale: [1.0, 1.0];\n\n#ifdef VERTEX_COLOR\nvarying vec4 v_Color;\n#endif\nvarying float v_Miter;\n\nvarying vec2 v_Texcoord;\n\nvoid main()\n{\n gl_FragColor = vec4(color, alpha) * texture2D(textureAtlas, v_Texcoord * uvScale);\n#ifdef VERTEX_COLOR\n gl_FragColor *= v_Color;\n#endif\n}\n\n@end";V.Shader.import(kc);const Va=V.Mesh.extend(function(){var e=new Gc({dynamic:!0}),t=new V.Material({shader:V.createShader("ecgl.labels"),transparent:!0,depthMask:!1});return{geometry:e,material:t,culling:!1,castShadow:!1,ignorePicking:!0}});var Lt=tt.firstNotNull,Pt={x:0,y:2,z:1};function cn(e,t){var r=new V.Mesh({geometry:new ln({useNativeLine:!1}),material:t,castShadow:!1,ignorePicking:!0,renderOrder:2}),i=new Va;i.material.depthMask=!1;var n=new V.Node;n.add(r),n.add(i),this.rootNode=n,this.dim=e,this.linesMesh=r,this.labelsMesh=i,this.axisLineCoords=null,this.labelElements=[]}var Ni={x:"y",y:"x",z:"y"};cn.prototype.update=function(e,t,r){var i=e.coordinateSystem,n=i.getAxis(this.dim),a=this.linesMesh.geometry,s=this.labelsMesh.geometry;a.convertToDynamicArray(!0),s.convertToDynamicArray(!0);var o=n.model,l=n.getExtent(),w=r.getDevicePixelRatio(),c=o.getModel("axisLine",e.getModel("axisLine")),h=o.getModel("axisTick",e.getModel("axisTick")),u=o.getModel("axisLabel",e.getModel("axisLabel")),d=c.get("lineStyle.color");if(c.get("show")){var f=c.getModel("lineStyle"),v=[0,0,0],m=[0,0,0],p=Pt[n.dim];v[p]=l[0],m[p]=l[1],this.axisLineCoords=[v,m];var _=V.parseColor(d),T=Lt(f.get("width"),1),y=Lt(f.get("opacity"),1);_[3]*=y,a.addLine(v,m,_,T*w)}if(h.get("show")){var g=h.getModel("lineStyle"),E=V.parseColor(Lt(g.get("color"),d)),T=Lt(g.get("width"),1);E[3]*=Lt(g.get("opacity"),1);for(var S=n.getTicksCoords(),R=h.get("length"),b=0;b<S.length;b++){var M=S[b].coord,v=[0,0,0],m=[0,0,0],p=Pt[n.dim],F=Pt[Ni[n.dim]];v[p]=m[p]=M,m[F]=R,a.addLine(v,m,E,T*w)}}this.labelElements=[];var w=r.getDevicePixelRatio();if(u.get("show"))for(var S=n.getTicksCoords(),U=o.get("data"),O=u.get("margin"),L=n.getViewLabels(),b=0;b<L.length;b++){var G=L[b].tickValue,B=L[b].formattedLabel,Z=L[b].rawLabel,M=n.dataToCoord(G),I=[0,0,0],p=Pt[n.dim],F=Pt[Ni[n.dim]];I[p]=I[p]=M,I[F]=O;var ue=u;U&&U[G]&&U[G].textStyle&&(ue=new Us(U[G].textStyle,u,o.ecModel));var k=Lt(ue.get("color"),d),ye=new Oi({style:Bi(ue,{text:B,fill:typeof k=="function"?k(n.type==="category"?Z:n.type==="value"?G+"":G,b):k,verticalAlign:"top",align:"left"})}),ae=t.add(ye),ve=ye.getBoundingRect();s.addSprite(I,[ve.width*w,ve.height*w],ae),this.labelElements.push(ye)}if(o.get("name")){var me=o.getModel("nameTextStyle"),I=[0,0,0],p=Pt[n.dim],F=Pt[Ni[n.dim]],Oe=Lt(me.get("color"),d),Be=me.get("borderColor"),T=me.get("borderWidth");I[p]=I[p]=(l[0]+l[1])/2,I[F]=o.get("nameGap");var ye=new Oi({style:Bi(me,{text:o.get("name"),fill:Oe,stroke:Be,lineWidth:T})}),ae=t.add(ye),ve=ye.getBoundingRect();s.addSprite(I,[ve.width*w,ve.height*w],ae),ye.__idx=this.labelElements.length,this.nameLabelElement=ye}this.labelsMesh.material.set("textureAtlas",t.getTexture()),this.labelsMesh.material.set("uvScale",t.getCoordsScale()),a.convertToTypedArray(),s.convertToTypedArray()};cn.prototype.setSpriteAlign=function(e,t,r){for(var i=r.getDevicePixelRatio(),n=this.labelsMesh.geometry,a=0;a<this.labelElements.length;a++){var s=this.labelElements[a],o=s.getBoundingRect();n.setSpriteAlign(a,[o.width*i,o.height*i],e,t)}var l=this.nameLabelElement;if(l){var o=l.getBoundingRect();n.setSpriteAlign(l.__idx,[o.width*i,o.height*i],e,t),n.dirty()}this.textAlign=e,this.textVerticalAlign=t};const Vc="@export ecgl.lines3D.vertex\n\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\n\nattribute vec3 position: POSITION;\nattribute vec4 a_Color : COLOR;\nvarying vec4 v_Color;\n\nvoid main()\n{\n gl_Position = worldViewProjection * vec4(position, 1.0);\n v_Color = a_Color;\n}\n\n@end\n\n@export ecgl.lines3D.fragment\n\nuniform vec4 color : [1.0, 1.0, 1.0, 1.0];\n\nvarying vec4 v_Color;\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@end\n\n\n\n@export ecgl.lines3D.clipNear\n\nvec4 clipNear(vec4 p1, vec4 p2) {\n float n = (p1.w - near) / (p1.w - p2.w);\n return vec4(mix(p1.xy, p2.xy, n), -near, near);\n}\n\n@end\n\n@export ecgl.lines3D.expandLine\n#ifdef VERTEX_ANIMATION\n vec4 prevProj = worldViewProjection * vec4(mix(prevPositionPrev, positionPrev, percent), 1.0);\n vec4 currProj = worldViewProjection * vec4(mix(prevPosition, position, percent), 1.0);\n vec4 nextProj = worldViewProjection * vec4(mix(prevPositionNext, positionNext, percent), 1.0);\n#else\n vec4 prevProj = worldViewProjection * vec4(positionPrev, 1.0);\n vec4 currProj = worldViewProjection * vec4(position, 1.0);\n vec4 nextProj = worldViewProjection * vec4(positionNext, 1.0);\n#endif\n\n if (currProj.w < 0.0) {\n if (nextProj.w > 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 Jn=tt.firstNotNull;V.Shader.import(Vc);var Dt={x:0,y:2,z:1};const Wc=Hs.extend({type:"grid3D",__ecgl__:!0,init:function(e,t){var r=[["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"]],i=["x","y","z"],n=new V.Material({shader:V.createShader("ecgl.color"),depthMask:!1,transparent:!0}),a=new V.Material({shader:V.createShader("ecgl.meshLines3D"),depthMask:!1,transparent:!0});n.define("fragment","DOUBLE_SIDED"),n.define("both","VERTEX_COLOR"),this.groupGL=new V.Node,this._control=new Fc({zr:t.getZr()}),this._control.init(),this._faces=r.map(function(o){var l=new hi(o,a,n);return this.groupGL.add(l.rootNode),l},this),this._axes=i.map(function(o){var l=new cn(o,a);return this.groupGL.add(l.rootNode),l},this);var s=t.getDevicePixelRatio();this._axisLabelSurface=new Wi({width:256,height:256,devicePixelRatio:s}),this._axisLabelSurface.onupdate=function(){t.getZr().refresh()},this._axisPointerLineMesh=new V.Mesh({geometry:new ln({useNativeLine:!1}),material:a,castShadow:!1,ignorePicking:!0,renderOrder:3}),this.groupGL.add(this._axisPointerLineMesh),this._axisPointerLabelsSurface=new Wi({width:128,height:128,devicePixelRatio:s}),this._axisPointerLabelsMesh=new Va({ignorePicking:!0,renderOrder:4,castShadow:!1}),this._axisPointerLabelsMesh.material.set("textureAtlas",this._axisPointerLabelsSurface.getTexture()),this.groupGL.add(this._axisPointerLabelsMesh),this._lightRoot=new V.Node,this._sceneHelper=new Xi,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(s){s.update(e,t,r)},this),this._axes.forEach(function(s){s.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,r=t.viewGL;e.get("show")&&e.get("axisPointer.show")?r.on("mousemove",this._updateAxisPointerOnMousePosition,this):r.off("mousemove",this._updateAxisPointerOnMousePosition)},_updateAxisPointerOnMousePosition:function(e){if(!e.target){for(var t=this._model,r=t.coordinateSystem,i=r.viewGL,n=i.castRay(e.offsetX,e.offsetY,new V.Ray),a,s=0;s<this._faces.length;s++){var o=this._faces[s];if(!o.rootNode.invisible){o.plane.normal.dot(i.camera.worldTransform.z)<0&&o.plane.normal.negate();var l=n.intersectPlane(o.plane);if(l){var c=r.getAxis(o.faceInfo[0]),h=r.getAxis(o.faceInfo[1]),u=Dt[o.faceInfo[0]],d=Dt[o.faceInfo[1]];c.contain(l.array[u])&&h.contain(l.array[d])&&(a=l)}}}if(a){var f=r.pointToData(a.array,[],!0);this._updateAxisPointer(f),this._doShowAxisPointer()}else this._doHideAxisPointer()}},_onCameraChange:function(e,t){e.get("show")&&(this._updateFaceVisibility(),this._updateAxisLinePosition());var r=this._control;t.dispatchAction({type:"grid3DChangeCamera",alpha:r.getAlpha(),beta:r.getBeta(),distance:r.getDistance(),center:r.getCenter(),from:this.uid,grid3DId:e.id})},_updateFaceVisibility:function(){var e=this._control.getCamera(),t=new V.Vector3;e.update();for(var r=0;r<this._faces.length/2;r++){for(var i=[],n=0;n<2;n++){var a=this._faces[r*2+n];a.rootNode.getWorldPosition(t),t.transformMat4(e.viewMatrix),i[n]=t.z}var s=i[0]>i[1]?0:1,o=this._faces[r*2+s],l=this._faces[r*2+1-s];o.rootNode.invisible=!0,l.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(),s=t.getExtentMin(),o=t.getExtentMax(),l=r.getExtentMax(),c=r.getExtentMin(),h=this._axes[0].rootNode,u=this._axes[1].rootNode,d=this._axes[2].rootNode,f=this._faces,v=f[4].rootNode.invisible?c:l,m=f[2].rootNode.invisible?n:a,p=f[0].rootNode.invisible?s:o,_=f[2].rootNode.invisible?n:a,T=f[0].rootNode.invisible?o:s,y=f[4].rootNode.invisible?c:l;h.rotation.identity(),u.rotation.identity(),d.rotation.identity(),f[4].rootNode.invisible&&(this._axes[0].flipped=!0,h.rotation.rotateX(Math.PI)),f[0].rootNode.invisible&&(this._axes[1].flipped=!0,u.rotation.rotateZ(Math.PI)),f[4].rootNode.invisible&&(this._axes[2].flipped=!0,d.rotation.rotateY(Math.PI)),h.position.set(0,m,v),u.position.set(p,_,0),d.position.set(T,0,y),h.update(),u.update(),d.update(),this._updateAxisLabelAlign()},_updateAxisLabelAlign:function(){var e=this._control.getCamera(),t=[new V.Vector4,new V.Vector4],r=new V.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){var n=i.axisLineCoords;i.labelsMesh.geometry;for(var a=0;a<t.length;a++)t[a].setArray(n[a]),t[a].w=1,t[a].transformMat4(i.rootNode.worldTransform).transformMat4(e.viewMatrix).transformMat4(e.projectionMatrix),t[a].x/=t[a].w,t[a].y/=t[a].w;var s=t[1].x-t[0].x,o=t[1].y-t[0].y,l=(t[1].x+t[0].x)/2,c=(t[1].y+t[0].y)/2,h,u;Math.abs(o/s)<.5?(h="center",u=c>r.y?"bottom":"top"):(u="middle",h=l>r.x?"left":"right"),i.setSpriteAlign(h,u,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,n=i.geometry,a=this._model.getModel("axisPointer"),s=this._api.getDevicePixelRatio();n.convertToDynamicArray(!0);function o(b){return tt.firstNotNull(b.model.get("axisPointer.show"),a.get("show"))}function l(b){var M=b.model.getModel("axisPointer",a),F=M.getModel("lineStyle"),w=V.parseColor(F.get("color")),U=Jn(F.get("width"),1),O=Jn(F.get("opacity"),1);return w[3]*=O,{color:w,lineWidth:U}}for(var c=0;c<this._faces.length;c++){var h=this._faces[c];if(!h.rootNode.invisible){for(var u=h.faceInfo,d=u[3]<0?t.getAxis(u[2]).getExtentMin():t.getAxis(u[2]).getExtentMax(),f=Dt[u[2]],v=0;v<2;v++){var m=u[v],p=u[1-v],_=t.getAxis(m),T=t.getAxis(p);if(o(_)){var y=[0,0,0],g=[0,0,0],E=Dt[m],S=Dt[p];y[E]=g[E]=r[E],y[f]=g[f]=d,y[S]=T.getExtentMin(),g[S]=T.getExtentMax();var R=l(_);n.addLine(y,g,R.color,R.lineWidth*s)}}if(o(t.getAxis(u[2]))){var y=r.slice(),g=r.slice();g[f]=d;var R=l(t.getAxis(u[2]));n.addLine(y,g,R.color,R.lineWidth*s)}}}n.convertToTypedArray(),this._updateAxisPointerLabelsMesh(e),this._api.getZr().refresh()},_updateAxisPointerLabelsMesh:function(e){var t=this._model,r=this._axisPointerLabelsMesh,i=this._axisPointerLabelsSurface,n=t.coordinateSystem,a=t.getModel("axisPointer");r.geometry.convertToDynamicArray(!0),i.clear();var s={x:"y",y:"x",z:"y"};this._axes.forEach(function(o,l){var c=n.getAxis(o.dim),h=c.model,u=h.getModel("axisPointer",a),d=u.getModel("label"),f=u.get("lineStyle.color");if(!(!d.get("show")||!u.get("show"))){var v=e[l],m=d.get("formatter"),p=c.scale.getLabel({value:v});if(m!=null)p=m(p,e);else if(c.scale.type==="interval"||c.scale.type==="log"){var _=va(c.scale.getTicks()[0]);p=v.toFixed(_+2)}var T=d.get("color"),y=new Oi({style:Bi(d,{text:p,fill:T||f,align:"left",verticalAlign:"top"})}),g=i.add(y),E=y.getBoundingRect(),S=this._api.getDevicePixelRatio(),R=o.rootNode.position.toArray(),b=Dt[s[o.dim]];R[b]+=(o.flipped?-1:1)*d.get("margin"),R[Dt[o.dim]]=c.dataToCoord(e[l]),r.geometry.addSprite(R,[E.width*S,E.height*S],g,o.textAlign,o.textVerticalAlign)}},this),i.getZr().refreshImmediately(),r.material.set("uvScale",i.getCoordsScale()),r.geometry.convertToTypedArray()},dispose:function(){this.groupGL.removeAll(),this._control.dispose(),this._axisLabelSurface.dispose(),this._axisPointerLabelsSurface.dispose()}});function Tr(e){ma.call(this,e),this.type="cartesian3D",this.dimensions=["x","y","z"],this.size=[0,0,0]}Tr.prototype={constructor:Tr,model:null,containPoint:function(e){return this.getAxis("x").contain(e[0])&&this.getAxis("y").contain(e[2])&&this.getAxis("z").contain(e[1])},containData:function(e){return this.getAxis("x").containData(e[0])&&this.getAxis("y").containData(e[1])&&this.getAxis("z").containData(e[2])},dataToPoint:function(e,t,r){return t=t||[],t[0]=this.getAxis("x").dataToCoord(e[0],r),t[2]=this.getAxis("y").dataToCoord(e[1],r),t[1]=this.getAxis("z").dataToCoord(e[2],r),t},pointToData:function(e,t,r){return t=t||[],t[0]=this.getAxis("x").coordToData(e[0],r),t[1]=this.getAxis("y").coordToData(e[2],r),t[2]=this.getAxis("z").coordToData(e[1],r),t}};pa(Tr,ma);function ti(e,t,r){_a.call(this,e,t,r)}ti.prototype={constructor:ti,getExtentMin:function(){var e=this._extent;return Math.min(e[0],e[1])},getExtentMax:function(){var e=this._extent;return Math.max(e[0],e[1])},calculateCategoryInterval:function(){return Math.floor(this.scale.count()/8)}};pa(ti,_a);var Yi=function(){this._pool={},this._allocatedTextures=[]};Yi.prototype={constructor:Yi,get:function(e){var t=ea(e);this._pool.hasOwnProperty(t)||(this._pool[t]=[]);var r=this._pool[t];if(!r.length){var i=new ne(e);return this._allocatedTextures.push(i),i}return r.pop()},put:function(e){var t=ea(e);this._pool.hasOwnProperty(t)||(this._pool[t]=[]);var r=this._pool[t];r.push(e)},clear:function(e){for(var t=0;t<this._allocatedTextures.length;t++)this._allocatedTextures[t].dispose(e);this._pool={},this._allocatedTextures=[]}};var Wa={width:512,height:512,type:A.UNSIGNED_BYTE,format:A.RGBA,wrapS:A.CLAMP_TO_EDGE,wrapT:A.CLAMP_TO_EDGE,minFilter:A.LINEAR_MIPMAP_LINEAR,magFilter:A.LINEAR,useMipmap:!0,anisotropic:1,flipY:!0,unpackAlignment:4,premultiplyAlpha:!1},Li=Object.keys(Wa);function ea(e){De.defaultsWithPropList(e,Wa,Li),Xc(e);for(var t="",r=0;r<Li.length;r++){var i=Li[r],n=e[i].toString();t+=n}return t}function Xc(e){var t=jc(e.width,e.height);e.format===A.DEPTH_COMPONENT&&(e.useMipmap=!1),(!t||!e.useMipmap)&&(e.minFilter==A.NEAREST_MIPMAP_NEAREST||e.minFilter==A.NEAREST_MIPMAP_LINEAR?e.minFilter=A.NEAREST:(e.minFilter==A.LINEAR_MIPMAP_LINEAR||e.minFilter==A.LINEAR_MIPMAP_NEAREST)&&(e.minFilter=A.LINEAR)),t||(e.wrapS=A.CLAMP_TO_EDGE,e.wrapT=A.CLAMP_TO_EDGE)}function jc(e,t){return(e&e-1)===0&&(t&t-1)===0}const Xa=Yi,Yc="@export clay.sm.depth.vertex\nuniform mat4 worldViewProjection : WORLDVIEWPROJECTION;\nattribute vec3 position : POSITION;\nattribute vec2 texcoord : TEXCOORD_0;\nuniform vec2 uvRepeat = vec2(1.0, 1.0);\nuniform vec2 uvOffset = vec2(0.0, 0.0);\n@import clay.chunk.skinning_header\n@import clay.chunk.instancing_header\nvarying vec4 v_ViewPosition;\nvarying vec2 v_Texcoord;\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 v_ViewPosition = worldViewProjection * P;\n gl_Position = v_ViewPosition;\n v_Texcoord = texcoord * uvRepeat + uvOffset;\n}\n@end\n@export clay.sm.depth.fragment\nvarying vec4 v_ViewPosition;\nvarying vec2 v_Texcoord;\nuniform float bias : 0.001;\nuniform float slopeScale : 1.0;\nuniform sampler2D alphaMap;\nuniform float alphaCutoff: 0.0;\n@import clay.util.encode_float\nvoid main(){\n float depth = v_ViewPosition.z / v_ViewPosition.w;\n if (alphaCutoff > 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 At=["px","nx","py","ny","pz","nz"];N.import(Yc);function Pi(e,t,r){if(r==="alphaMap")return e.material.get("diffuseMap");if(r==="alphaCutoff"){if(e.material.isDefined("fragment","ALPHA_TEST")&&e.material.get("diffuseMap")){var i=e.material.get("alphaCutoff");return i||0}return 0}else return r==="uvRepeat"?e.material.get("uvRepeat"):r==="uvOffset"?e.material.get("uvOffset"):t.get(r)}function ta(e,t){var r=e.material,i=t.material;return r.get("diffuseMap")!==i.get("diffuseMap")||(r.get("alphaCutoff")||0)!==(i.get("alphaCutoff")||0)}var ft=qe.extend(function(){return{softShadow:ft.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 Ue,_textures:{},_shadowMapNumber:{POINT_LIGHT:0,DIRECTIONAL_LIGHT:0,SPOT_LIGHT:0},_depthMaterials:{},_distanceMaterials:{},_receivers:[],_lightsCastShadow:[],_lightCameras:{},_lightMaterials:{},_texturePool:new Xa}},function(){this._gaussianPassH=new Ve({fragment:N.source("clay.compositor.gaussian_blur")}),this._gaussianPassV=new Ve({fragment:N.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 Ve({fragment:N.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=0,a=t||r.width/4,s=a;this.softShadow===ft.VSM?this._outputDepthPass.material.define("fragment","USE_VSM"):this._outputDepthPass.material.undefine("fragment","USE_VSM");for(var o in this._textures){var l=this._textures[o];e.setViewport(i,n,a*l.width/l.height,s),this._outputDepthPass.setUniform("depthMap",l),this._outputDepthPass.render(e),i+=a*l.width/l.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===ft.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(a){a.isRenderable()&&r._updateReceivers(e,a)});for(var i=0;i<t.lights.length;i++){var n=t.lights[i];n.castShadow&&!n.invisible&&this._lightsCastShadow.push(n)}},_renderShadowPass:function(e,t,r,i){for(var n in this._shadowMapNumber)this._shadowMapNumber[n]=0;this._lightsCastShadow.length=0,this._receivers.length=0;var a=e.gl;if(i||t.update(),r&&r.update(),t.updateLights(),this._update(e,t),!this._lightsCastShadow.length&&this._lastRenderNotCastShadow)return;this._lastRenderNotCastShadow=this._lightsCastShadow===0,a.enable(a.DEPTH_TEST),a.depthMask(!0),a.disable(a.BLEND),a.clearColor(1,1,1,1);for(var s=[],o=[],l=[],c=[],h=[],u=[],d,f=0;f<this._lightsCastShadow.length;f++){var v=this._lightsCastShadow[f];if(v.type==="DIRECTIONAL_LIGHT"){if(d){console.warn("Only one direectional light supported with shadow cascade");continue}if(v.shadowCascade>4){console.warn("Support at most 4 cascade");continue}v.shadowCascade>1&&(d=v),this.renderDirectionalLightShadow(e,t,r,v,h,c,l)}else v.type==="SPOT_LIGHT"?this.renderSpotLightShadow(e,t,v,o,s):v.type==="POINT_LIGHT"&&this.renderPointLightShadow(e,t,v,u);this._shadowMapNumber[v.type]++}for(var m in this._shadowMapNumber)for(var p=this._shadowMapNumber[m],_=m+"_SHADOWMAP_COUNT",f=0;f<this._receivers.length;f++){var T=this._receivers[f],y=T.material;y.fragmentDefines[_]!==p&&(p>0?y.define("fragment",_,p):y.isDefined("fragment",_)&&y.undefine("fragment",_))}for(var f=0;f<this._receivers.length;f++){var T=this._receivers[f],y=T.material;d?y.define("fragment","SHADOW_CASCADE",d.shadowCascade):y.undefine("fragment","SHADOW_CASCADE")}var g=t.shadowUniforms;function E(F){return F.height}if(l.length>0){var S=l.map(E);if(g.directionalLightShadowMaps={value:l,type:"tv"},g.directionalLightMatrices={value:c,type:"m4v"},g.directionalLightShadowMapSizes={value:S,type:"1fv"},d){var R=h.slice(),b=h.slice();R.pop(),b.shift(),R.reverse(),b.reverse(),c.reverse(),g.shadowCascadeClipsNear={value:R,type:"1fv"},g.shadowCascadeClipsFar={value:b,type:"1fv"}}}if(s.length>0){var M=s.map(E),g=t.shadowUniforms;g.spotLightShadowMaps={value:s,type:"tv"},g.spotLightMatrices={value:o,type:"m4v"},g.spotLightShadowMapSizes={value:M,type:"1fv"}}u.length>0&&(g.pointLightShadowMaps={value:u,type:"tv"})},renderDirectionalLightShadow:function(){var e=new tn,t=new z,r=new ke,i=new z,n=new z,a=new z,s=new z;return function(o,l,c,h,u,d,f){var v=this._getDepthMaterial(h),m={getMaterial:function(ve){return ve.shadowDepthMaterial||v},isMaterialChanged:ta,getUniform:Pi,ifRender:function(ve){return ve.castShadow},sortCompare:vr.opaqueSortCompare};if(!l.viewBoundingBoxLastFrame.isFinite()){var p=l.getBoundingBox();l.viewBoundingBoxLastFrame.copy(p).applyTransform(c.viewMatrix)}var _=Math.min(-l.viewBoundingBoxLastFrame.min.z,c.far),T=Math.max(-l.viewBoundingBoxLastFrame.max.z,c.near),y=this._getDirectionalLightCamera(h,l,c),g=a.array;s.copy(y.projectionMatrix),C.invert(n.array,y.worldTransform.array),C.multiply(n.array,n.array,c.worldTransform.array),C.multiply(g,s.array,n.array);for(var E=[],S=c instanceof Ne,R=(c.near+c.far)/(c.near-c.far),b=2*c.near*c.far/(c.near-c.far),M=0;M<=h.shadowCascade;M++){var F=T*Math.pow(_/T,M/h.shadowCascade),w=T+(_-T)*M/h.shadowCascade,U=F*h.cascadeSplitLogFactor+w*(1-h.cascadeSplitLogFactor);E.push(U),u.push(-(-U*R+b)/-U)}var O=this._getTexture(h,h.shadowCascade);f.push(O);var L=o.viewport,G=o.gl;this._frameBuffer.attach(O),this._frameBuffer.bind(o),G.clear(G.COLOR_BUFFER_BIT|G.DEPTH_BUFFER_BIT);for(var M=0;M<h.shadowCascade;M++){var B=E[M],Z=E[M+1];S?C.perspective(t.array,c.fov/180*Math.PI,c.aspect,B,Z):C.ortho(t.array,c.left,c.right,c.bottom,c.top,B,Z),e.setFromProjection(t),e.getTransformedBoundingBox(r,n),r.applyProjection(s);var I=r.min.array,ue=r.max.array;I[0]=Math.max(I[0],-1),I[1]=Math.max(I[1],-1),ue[0]=Math.min(ue[0],1),ue[1]=Math.min(ue[1],1),i.ortho(I[0],ue[0],I[1],ue[1],1,-1),y.projectionMatrix.multiplyLeft(i);var k=h.shadowResolution||512;o.setViewport((h.shadowCascade-M-1)*k,0,k,k,1);var ye=l.updateRenderList(y);o.renderPass(ye.opaque,y,m),this.softShadow===ft.VSM&&this._gaussianFilter(o,O,O.width);var ae=new z;ae.copy(y.viewMatrix).multiplyLeft(y.projectionMatrix),d.push(ae.array),y.projectionMatrix.copy(s)}this._frameBuffer.unbind(o),o.setViewport(L)}}(),renderSpotLightShadow:function(e,t,r,i,n){var a=this._getTexture(r),s=this._getSpotLightCamera(r),o=e.gl;this._frameBuffer.attach(a),this._frameBuffer.bind(e),o.clear(o.COLOR_BUFFER_BIT|o.DEPTH_BUFFER_BIT);var l=this._getDepthMaterial(r),c={getMaterial:function(d){return d.shadowDepthMaterial||l},isMaterialChanged:ta,getUniform:Pi,ifRender:function(d){return d.castShadow},sortCompare:vr.opaqueSortCompare},h=t.updateRenderList(s);e.renderPass(h.opaque,s,c),this._frameBuffer.unbind(e),this.softShadow===ft.VSM&&this._gaussianFilter(e,a,a.width);var u=new z;u.copy(s.worldTransform).invert().multiplyLeft(s.projectionMatrix),n.push(a),i.push(u.array)},renderPointLightShadow:function(e,t,r,i){var n=this._getTexture(r),a=e.gl;i.push(n);var s=this._getDepthMaterial(r),o={getMaterial:function(T){return T.shadowDepthMaterial||s},getUniform:Pi,sortCompare:vr.opaqueSortCompare},l={px:[],py:[],pz:[],nx:[],ny:[],nz:[]},c=new ke,h=r.getWorldPosition().array,u=new ke,d=r.range;u.min.setArray(h),u.max.setArray(h);var f=new P(d,d,d);u.max.add(f),u.min.sub(f);var v={px:!1,py:!1,pz:!1,nx:!1,ny:!1,nz:!1};t.traverse(function(T){if(T.isRenderable()&&T.castShadow){var y=T.geometry;if(!y.boundingBox){for(var g=0;g<At.length;g++)l[At[g]].push(T);return}if(c.transformFrom(y.boundingBox,T.worldTransform),!c.intersectBoundingBox(u))return;c.updateVertices();for(var g=0;g<At.length;g++)v[At[g]]=!1;for(var g=0;g<8;g++){var E=c.vertices[g],S=E[0]-h[0],R=E[1]-h[1],b=E[2]-h[2],M=Math.abs(S),F=Math.abs(R),w=Math.abs(b);M>F?M>w?v[S>0?"px":"nx"]=!0:v[b>0?"pz":"nz"]=!0:F>w?v[R>0?"py":"ny"]=!0:v[b>0?"pz":"nz"]=!0}for(var g=0;g<At.length;g++)v[At[g]]&&l[At[g]].push(T)}});for(var m=0;m<6;m++){var p=At[m],_=this._getPointLightCamera(r,p);this._frameBuffer.attach(n,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X+m),this._frameBuffer.bind(e),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT),e.renderPass(l[p],_,o)}this._frameBuffer.unbind(e)},_getDepthMaterial:function(e){var t=this._lightMaterials[e.__uid__],r=e.type==="POINT_LIGHT";if(!t){var i=r?"clay.sm.distance.":"clay.sm.depth.";t=new yt({precision:this.precision,shader:new N(N.source(i+"vertex"),N.source(i+"fragment"))}),this._lightMaterials[e.__uid__]=t}return e.shadowSlopeScale!=null&&t.setUniform("slopeScale",e.shadowSlopeScale),e.shadowBias!=null&&t.setUniform("bias",e.shadowBias),this.softShadow===ft.VSM?t.define("fragment","USE_VSM"):t.undefine("fragment","USE_VSM"),r&&(t.set("lightPosition",e.getWorldPosition().array),t.set("range",e.range)),t},_gaussianFilter:function(e,t,r){var i={width:r,height:r,type:q.FLOAT},n=this._texturePool.get(i);this._frameBuffer.attach(n),this._frameBuffer.bind(e),this._gaussianPassH.setUniform("texture",t),this._gaussianPassH.setUniform("textureWidth",r),this._gaussianPassH.render(e),this._frameBuffer.attach(t),this._gaussianPassV.setUniform("texture",n),this._gaussianPassV.setUniform("textureHeight",r),this._gaussianPassV.render(e),this._frameBuffer.unbind(e),this._texturePool.put(n)},_getTexture:function(e,t){var r=e.__uid__,i=this._textures[r],n=e.shadowResolution||512;return t=t||1,i||(e.type==="POINT_LIGHT"?i=new gr:i=new ne,i.width=n*t,i.height=n,this.softShadow===ft.VSM?(i.type=q.FLOAT,i.anisotropic=4):(i.minFilter=A.NEAREST,i.magFilter=A.NEAREST,i.useMipmap=!1),this._textures[r]=i),i},_getPointLightCamera:function(e,t){this._lightCameras.point||(this._lightCameras.point={px:new Ne,nx:new Ne,py:new Ne,ny:new Ne,pz:new Ne,nz:new Ne});var r=this._lightCameras.point[t];switch(r.far=e.range,r.fov=90,r.position.set(0,0,0),t){case"px":r.lookAt(P.POSITIVE_X,P.NEGATIVE_Y);break;case"nx":r.lookAt(P.NEGATIVE_X,P.NEGATIVE_Y);break;case"py":r.lookAt(P.POSITIVE_Y,P.POSITIVE_Z);break;case"ny":r.lookAt(P.NEGATIVE_Y,P.NEGATIVE_Z);break;case"pz":r.lookAt(P.POSITIVE_Z,P.NEGATIVE_Y);break;case"nz":r.lookAt(P.NEGATIVE_Z,P.NEGATIVE_Y);break}return e.getWorldPosition(r.position),r.update(),r},_getDirectionalLightCamera:function(){var e=new z,t=new ke,r=new ke;return function(i,n,a){this._lightCameras.directional||(this._lightCameras.directional=new xr);var s=this._lightCameras.directional;t.copy(n.viewBoundingBoxLastFrame),t.intersection(a.frustum.boundingBox),s.position.copy(t.min).add(t.max).scale(.5).transformMat4(a.worldTransform),s.rotation.copy(i.rotation),s.scale.copy(i.scale),s.updateWorldTransform(),z.invert(e,s.worldTransform),z.multiply(e,e,a.worldTransform),r.copy(t).applyTransform(e);var o=r.min.array,l=r.max.array;return s.position.set((o[0]+l[0])/2,(o[1]+l[1])/2,l[2]).transformMat4(s.worldTransform),s.near=0,s.far=-o[2]+l[2],isNaN(this.lightFrustumBias)?s.far*=4:s.far+=this.lightFrustumBias,s.left=o[0],s.right=l[0],s.top=l[1],s.bottom=o[1],s.update(!0),s}}(),_getSpotLightCamera:function(e){this._lightCameras.spot||(this._lightCameras.spot=new Ne);var t=this._lightCameras.spot;return t.fov=e.penumbraAngle*2,t.far=e.range,t.worldTransform.copy(e.worldTransform),t.updateProjectionMatrix(),C.invert(t.viewMatrix.array,t.worldTransform.array),t},dispose:function(e){var t=e.gl||e;this._frameBuffer&&this._frameBuffer.dispose(t);for(var r in this._textures)this._textures[r].dispose(t);this._texturePool.clear(e.gl),this._depthMaterials={},this._distanceMaterials={},this._textures={},this._lightCameras={},this._shadowMapNumber={POINT_LIGHT:0,DIRECTIONAL_LIGHT:0,SPOT_LIGHT:0},this._meshMaterials={};for(var i=0;i<this._receivers.length;i++){var n=this._receivers[i];if(n.material){var a=n.material;a.undefine("fragment","POINT_LIGHT_SHADOW_COUNT"),a.undefine("fragment","DIRECTIONAL_LIGHT_SHADOW_COUNT"),a.undefine("fragment","AMBIENT_LIGHT_SHADOW_COUNT"),a.set("shadowEnabled",0)}}this._receivers=[],this._lightsCastShadow=[]}});ft.VSM=1;ft.PCF=2;const qc=ft;var Zc=qe.extend(function(){return{name:"",inputLinks:{},outputLinks:{},_prevOutputTextures:{},_outputTextures:{},_outputReferences:{},_rendering:!1,_rendered:!1,_compositor:null}},{updateParameter:function(e,t){var r=this.outputs[e],i=r.parameters,n=r._parametersCopy;if(n||(n=r._parametersCopy={}),i)for(var a in i)a!=="width"&&a!=="height"&&(n[a]=i[a]);var s,o;return i.width instanceof Function?s=i.width.call(this,t):s=i.width,i.height instanceof Function?o=i.height.call(this,t):o=i.height,(n.width!==s||n.height!==o)&&this._outputTextures[e]&&this._outputTextures[e].dispose(t.gl),n.width=s,n.height=o,n},setParameter:function(e,t){},getParameter:function(e){},setParameters:function(e){for(var t in e)this.setParameter(t,e[t])},render:function(){},getOutput:function(e,t){if(t==null)return t=e,this._outputTextures[t];var r=this.outputs[t];if(r)return this._rendered?r.outputLastFrame?this._prevOutputTextures[t]:this._outputTextures[t]:this._rendering?(this._prevOutputTextures[t]||(this._prevOutputTextures[t]=this._compositor.allocateTexture(r.parameters||{})),this._prevOutputTextures[t]):(this.render(e),this._outputTextures[t])},removeReference:function(e){if(this._outputReferences[e]--,this._outputReferences[e]===0){var t=this.outputs[e];t.keepLastFrame?(this._prevOutputTextures[e]&&this._compositor.releaseTexture(this._prevOutputTextures[e]),this._prevOutputTextures[e]=this._outputTextures[e]):this._compositor.releaseTexture(this._outputTextures[e])}},link:function(e,t,r){this.inputLinks[e]={node:t,pin:r},t.outputLinks[r]||(t.outputLinks[r]=[]),t.outputLinks[r].push({node:this,pin:e}),this.pass.material.enableTexture(e)},clear:function(){this.inputLinks={},this.outputLinks={}},updateReference:function(e){if(!this._rendering){this._rendering=!0;for(var t in this.inputLinks){var r=this.inputLinks[t];r.node.updateReference(r.pin)}this._rendering=!1}e&&this._outputReferences[e]++},beforeFrame:function(){this._rendered=!1;for(var e in this.outputLinks)this._outputReferences[e]=0},afterFrame:function(){for(var e in this.outputLinks)if(this._outputReferences[e]>0){var t=this.outputs[e];t.keepLastFrame?(this._prevOutputTextures[e]&&this._compositor.releaseTexture(this._prevOutputTextures[e]),this._prevOutputTextures[e]=this._outputTextures[e]):this._compositor.releaseTexture(this._outputTextures[e])}}});const Er=Zc;var $c=qe.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){typeof e=="string"&&(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<this.nodes.length;t++)if(this.nodes[t].name===e)return this.nodes[t]},update:function(){for(var e=0;e<this.nodes.length;e++)this.nodes[e].clear();for(var e=0;e<this.nodes.length;e++){var t=this.nodes[e];if(t.inputs){for(var r in t.inputs)if(t.inputs[r]){if(t.pass&&!t.pass.material.isUniformEnabled(r)){console.warn("Pin "+t.name+"."+r+" not used.");continue}var i=t.inputs[r],n=this.findPin(i);n?t.link(r,n.node,n.pin):console.warn(typeof i=="string"?"Node "+i+" not exist":"Pin of "+i.node+"."+i.pin+" not exist")}}}},findPin:function(e){var t;if((typeof e=="string"||e instanceof Er)&&(e={node:e}),typeof e.node=="string")for(var r=0;r<this.nodes.length;r++){var i=this.nodes[r];i.name===e.node&&(t=i)}else t=e.node;if(t){var n=e.pin;if(n||t.outputs&&(n=Object.keys(t.outputs)[0]),t.outputs[n])return{node:t,pin:n}}}});const ra=$c;var Kc=ra.extend(function(){return{_outputs:[],_texturePool:new Xa,_frameBuffer:new Ue({depthBuffer:!1})}},{addNode:function(e){ra.prototype.addNode.call(this,e),e._compositor=this},render:function(e,t){if(this._dirty){this.update(),this._dirty=!1,this._outputs.length=0;for(var r=0;r<this.nodes.length;r++)this.nodes[r].outputs||this._outputs.push(this.nodes[r])}for(var r=0;r<this.nodes.length;r++)this.nodes[r].beforeFrame();for(var r=0;r<this._outputs.length;r++)this._outputs[r].updateReference();for(var r=0;r<this._outputs.length;r++)this._outputs[r].render(e,t);for(var r=0;r<this.nodes.length;r++)this.nodes[r].afterFrame()},allocateTexture:function(e){return this._texturePool.get(e)},releaseTexture:function(e){this._texturePool.put(e)},getFrameBuffer:function(){return this._frameBuffer},dispose:function(e){this._texturePool.clear(e)}});const Qc=Kc;var Jc=Er.extend({name:"scene",scene:null,camera:null,autoUpdateScene:!0,preZ:!1},function(){this.frameBuffer=new Ue},{render:function(e){this._rendering=!0;var t=e.gl;this.trigger("beforerender");var r;if(!this.outputs)r=e.render(this.scene,this.camera,!this.autoUpdateScene,this.preZ);else{var i=this.frameBuffer;for(var n in this.outputs){var a=this.updateParameter(n,e),s=this.outputs[n],o=this._compositor.allocateTexture(a);this._outputTextures[n]=o;var l=s.attachment||t.COLOR_ATTACHMENT0;typeof l=="string"&&(l=t[l]),i.attach(o,l)}i.bind(e);var c=e.getGLExtension("EXT_draw_buffers");if(c){var h=[];for(var l in this.outputs)l=parseInt(l),l>=t.COLOR_ATTACHMENT0&&l<=t.COLOR_ATTACHMENT0+8&&h.push(l);c.drawBuffersEXT(h)}e.saveClear(),e.clearBit=A.DEPTH_BUFFER_BIT|A.COLOR_BUFFER_BIT,r=e.render(this.scene,this.camera,!this.autoUpdateScene,this.preZ),e.restoreClear(),i.unbind(e)}this.trigger("afterrender",r),this._rendering=!1,this._rendered=!0}});const eh=Jc;var th=Er.extend(function(){return{texture:null,outputs:{color:{}}}},function(){},{getOutput:function(e,t){return this.texture},beforeFrame:function(){},afterFrame:function(){}});const rh=th;var ih=Er.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 Ve({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=this.inputLinks[i],a=n.node.getOutput(e,n.pin);this.pass.setUniform(i,a)}if(!this.outputs)this.pass.outputs=null,this._compositor.getFrameBuffer().unbind(e),this.pass.render(e,t);else{this.pass.outputs={};var s={};for(var o in this.outputs){var l=this.updateParameter(o,e);isNaN(l.width)&&this.updateParameter(o,e);var c=this.outputs[o],h=this._compositor.allocateTexture(l);this._outputTextures[o]=h;var u=c.attachment||r.COLOR_ATTACHMENT0;typeof u=="string"&&(u=r[u]),s[u]=h}this._compositor.getFrameBuffer().bind(e);for(var u in s)this._compositor.getFrameBuffer().attach(s[u],u);this.pass.render(e),this._compositor.getFrameBuffer().updateMipmap(e)}for(var i in this.inputLinks){var n=this.inputLinks[i];n.node.removeReference(n.pin)}this._rendering=!1,this._rendered=!0,this.trigger("afterrender",e)},updateParameter:function(e,t){var r=this.outputs[e],i=r.parameters,n=r._parametersCopy;if(n||(n=r._parametersCopy={}),i)for(var a in i)a!=="width"&&a!=="height"&&(n[a]=i[a]);var s,o;return typeof i.width=="function"?s=i.width.call(this,t):s=i.width,typeof i.height=="function"?o=i.height.call(this,t):o=i.height,s=Math.ceil(s),o=Math.ceil(o),(n.width!==s||n.height!==o)&&this._outputTextures[e]&&this._outputTextures[e].dispose(t),n.width=s,n.height=o,n},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){if(this._outputReferences[e]--,this._outputReferences[e]===0){var t=this.outputs[e];t.keepLastFrame?(this._prevOutputTextures[e]&&this._compositor.releaseTexture(this._prevOutputTextures[e]),this._prevOutputTextures[e]=this._outputTextures[e]):this._compositor.releaseTexture(this._outputTextures[e])}},clear:function(){Er.prototype.clear.call(this),this.pass.material.disableTexturesAll()}});const nh=ih,ah="@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",ja="@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",sh="@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",Ya="\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",oh="@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",qa="@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",Za="@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",$a="@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",Ka="\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",Qa="@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",lh="@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",Ja="@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",es="@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 ch(e){e.import(ah),e.import(ja),e.import(sh),e.import(Ya),e.import(oh),e.import(qa),e.import(Za),e.import($a),e.import(Ka),e.import(Qa),e.import(lh),e.import(Ja),e.import(es)}ch(N);var hh=/^#source\((.*?)\)/;function uh(e,t){var r=new Qc;t=t||{};var i={textures:{},parameters:{}},n=function(o,l){for(var c=0;c<e.nodes.length;c++){var h=e.nodes[c],u=fh(h,i,t);u&&r.addNode(u)}};for(var a in e.parameters){var s=e.parameters[a];i.parameters[a]=hn(s)}return mh(e,i,t,function(o){i.textures=o,n()}),r}function fh(e,t,r){var i=e.type||"filter",n,a,s;if(i==="filter"){var o=e.shader.trim(),l=hh.exec(o);if(l?n=N.source(l[1].trim()):o.charAt(0)==="#"&&(n=t.shaders[o.substr(1)]),n||(n=o),!n)return}if(e.inputs){a={};for(var c in e.inputs)typeof e.inputs[c]=="string"?a[c]=e.inputs[c]:a[c]={node:e.inputs[c].node,pin:e.inputs[c].pin}}if(e.outputs){s={};for(var c in e.outputs){var h=e.outputs[c];s[c]={},h.attachment!=null&&(s[c].attachment=h.attachment),h.keepLastFrame!=null&&(s[c].keepLastFrame=h.keepLastFrame),h.outputLastFrame!=null&&(s[c].outputLastFrame=h.outputLastFrame),h.parameters&&(s[c].parameters=hn(h.parameters))}}var u;if(i==="scene"?u=new eh({name:e.name,scene:r.scene,camera:r.camera,outputs:s}):i==="texture"?u=new rh({name:e.name,outputs:s}):u=new nh({name:e.name,shader:n,inputs:a,outputs:s}),u){if(e.parameters)for(var c in e.parameters){var d=e.parameters[c];typeof d=="string"?(d=d.trim(),d.charAt(0)==="#"?d=t.textures[d.substr(1)]:u.on("beforerender",ph(c,ts(d)))):typeof d=="function"&&u.on("beforerender",d),u.setParameter(c,d)}if(e.defines&&u.pass)for(var c in e.defines){var d=e.defines[c];u.pass.material.define("fragment",c,d)}}return u}function dh(e,t){return e}function vh(e,t){return t}function hn(e){var t={};if(!e)return t;["type","minFilter","magFilter","wrapS","wrapT","flipY","useMipmap"].forEach(function(i){var n=e[i];n!=null&&(typeof n=="string"&&(n=q[n]),t[i]=n)});var r=e.scale||1;return["width","height"].forEach(function(i){if(e[i]!=null){var n=e[i];typeof n=="string"?(n=n.trim(),t[i]=_h(i,ts(n),r)):t[i]=n}}),t.width||(t.width=dh),t.height||(t.height=vh),e.useMipmap!=null&&(t.useMipmap=e.useMipmap),t}function mh(e,t,r,i){if(!e.textures){i({});return}var n={},a=0,s=!1,o=r.textureRootPath;De.each(e.textures,function(l,c){var h,u=l.path,d=hn(l.parameters);if(Array.isArray(u)&&u.length===6)o&&(u=u.map(function(f){return De.relative2absolute(f,o)})),h=new gr(d);else if(typeof u=="string")o&&(u=De.relative2absolute(u,o)),h=new ne(d);else return;h.load(u),a++,h.once("success",function(){n[c]=h,a--,a===0&&(i(n),s=!0)})}),a===0&&!s&&i(n)}function ph(e,t){return function(r){var i=r.getDevicePixelRatio(),n=r.getWidth(),a=r.getHeight(),s=t(n,a,i);this.setParameter(e,s)}}function _h(e,t,r){return r=r||1,function(i){var n=i.getDevicePixelRatio(),a=i.getWidth()*r,s=i.getHeight()*r;return t(a,s,n)}}function ts(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{throw new Error("Invalid expression.")}}function rr(e,t){for(var r=0,i=1/t,n=e;n>0;)r=r+i*(n%t),n=Math.floor(n/t),i=i/t;return r}const gh="@export ecgl.ssao.estimate\n\nuniform sampler2D depthTex;\n\nuniform sampler2D normalTex;\n\nuniform sampler2D noiseTex;\n\nuniform vec2 depthTexSize;\n\nuniform vec2 noiseTexSize;\n\nuniform mat4 projection;\n\nuniform mat4 projectionInv;\n\nuniform mat4 viewInverseTranspose;\n\nuniform vec3 kernel[KERNEL_SIZE];\n\nuniform float radius : 1;\n\nuniform float power : 1;\n\nuniform float bias: 1e-2;\n\nuniform float intensity: 1.0;\n\nvarying vec2 v_Texcoord;\n\nfloat ssaoEstimator(in vec3 originPos, in mat3 kernelBasis) {\n float occlusion = 0.0;\n\n for (int i = 0; i < KERNEL_SIZE; i++) {\n vec3 samplePos = kernel[i];\n#ifdef NORMALTEX_ENABLED\n samplePos = kernelBasis * samplePos;\n#endif\n samplePos = samplePos * radius + originPos;\n\n vec4 texCoord = projection * vec4(samplePos, 1.0);\n texCoord.xy /= texCoord.w;\n\n vec4 depthTexel = texture2D(depthTex, texCoord.xy * 0.5 + 0.5);\n\n float sampleDepth = depthTexel.r * 2.0 - 1.0;\n if (projection[3][3] == 0.0) {\n sampleDepth = projection[3][2] / (sampleDepth * projection[2][3] - projection[2][2]);\n }\n else {\n sampleDepth = (sampleDepth - projection[3][2]) / projection[2][2];\n }\n \n float rangeCheck = smoothstep(0.0, 1.0, radius / abs(originPos.z - sampleDepth));\n occlusion += rangeCheck * step(samplePos.z, sampleDepth - bias);\n }\n#ifdef NORMALTEX_ENABLED\n occlusion = 1.0 - occlusion / float(KERNEL_SIZE);\n#else\n occlusion = 1.0 - clamp((occlusion / float(KERNEL_SIZE) - 0.6) * 2.5, 0.0, 1.0);\n#endif\n return pow(occlusion, power);\n}\n\nvoid main()\n{\n\n vec4 depthTexel = texture2D(depthTex, v_Texcoord);\n\n#ifdef NORMALTEX_ENABLED\n vec4 tex = texture2D(normalTex, v_Texcoord);\n if (dot(tex.rgb, tex.rgb) == 0.0) {\n gl_FragColor = vec4(1.0);\n return;\n }\n vec3 N = tex.rgb * 2.0 - 1.0;\n N = (viewInverseTranspose * vec4(N, 0.0)).xyz;\n\n vec2 noiseTexCoord = depthTexSize / vec2(noiseTexSize) * v_Texcoord;\n vec3 rvec = texture2D(noiseTex, noiseTexCoord).rgb * 2.0 - 1.0;\n vec3 T = normalize(rvec - N * dot(rvec, N));\n vec3 BT = normalize(cross(N, T));\n mat3 kernelBasis = mat3(T, BT, N);\n#else\n if (depthTexel.r > 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";N.import(gh);function rs(e){for(var t=new Uint8Array(e*e*4),r=0,i=new P,n=0;n<e;n++)for(var a=0;a<e;a++)i.set(Math.random()*2-1,Math.random()*2-1,0).normalize(),t[r++]=(i.x*.5+.5)*255,t[r++]=(i.y*.5+.5)*255,t[r++]=0,t[r++]=255;return t}function ia(e){return new ne({pixels:rs(e),wrapS:q.REPEAT,wrapT:q.REPEAT,width:e,height:e})}function yh(e,t,r){var i=new Float32Array(e*3);t=t||0;for(var n=0;n<e;n++){var a=rr(n+t,2)*(r?1:2)*Math.PI,s=rr(n+t,3)*Math.PI,o=Math.random(),l=Math.cos(a)*Math.sin(s)*o,c=Math.cos(s)*o,h=Math.sin(a)*Math.sin(s)*o;i[n*3]=l,i[n*3+1]=c,i[n*3+2]=h}return i}function xt(e){e=e||{},this._ssaoPass=new Ve({fragment:N.source("ecgl.ssao.estimate")}),this._blurPass=new Ve({fragment:N.source("ecgl.ssao.blur")}),this._framebuffer=new Ue({depthBuffer:!1}),this._ssaoTexture=new ne,this._blurTexture=new ne,this._blurTexture2=new ne,this._depthTex=e.depthTexture,this._normalTex=e.normalTexture,this.setNoiseSize(4),this.setKernelSize(e.kernelSize||12),e.radius!=null&&this.setParameter("radius",e.radius),e.power!=null&&this.setParameter("power",e.power),this._normalTex||(this._ssaoPass.material.disableTexture("normalTex"),this._blurPass.material.disableTexture("normalTex")),this._depthTex||this._blurPass.material.disableTexture("depthTex"),this._blurPass.material.setUniform("normalTex",this._normalTex),this._blurPass.material.setUniform("depthTex",this._depthTex)}xt.prototype.setDepthTexture=function(e){this._depthTex=e};xt.prototype.setNormalTexture=function(e){this._normalTex=e,this._ssaoPass.material[e?"enableTexture":"disableTexture"]("normalTex"),this.setKernelSize(this._kernelSize)};xt.prototype.update=function(e,t,r){var i=e.getWidth(),n=e.getHeight(),a=this._ssaoPass,s=this._blurPass;a.setUniform("kernel",this._kernels[r%this._kernels.length]),a.setUniform("depthTex",this._depthTex),this._normalTex!=null&&a.setUniform("normalTex",this._normalTex),a.setUniform("depthTexSize",[this._depthTex.width,this._depthTex.height]);var o=new z;z.transpose(o,t.worldTransform),a.setUniform("projection",t.projectionMatrix.array),a.setUniform("projectionInv",t.invProjectionMatrix.array),a.setUniform("viewInverseTranspose",o.array);var l=this._ssaoTexture,c=this._blurTexture,h=this._blurTexture2;l.width=i/2,l.height=n/2,c.width=i,c.height=n,h.width=i,h.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),s.setUniform("textureSize",[i/2,n/2]),s.setUniform("projection",t.projectionMatrix.array),this._framebuffer.attach(c),s.setUniform("direction",0),s.setUniform("ssaoTexture",l),s.render(e),this._framebuffer.attach(h),s.setUniform("textureSize",[i,n]),s.setUniform("direction",1),s.setUniform("ssaoTexture",c),s.render(e),this._framebuffer.unbind(e);var u=e.clearColor;e.gl.clearColor(u[0],u[1],u[2],u[3])};xt.prototype.getTargetTexture=function(){return this._blurTexture2};xt.prototype.setParameter=function(e,t){e==="noiseTexSize"?this.setNoiseSize(t):e==="kernelSize"?this.setKernelSize(t):e==="intensity"?this._ssaoPass.material.set("intensity",t):this._ssaoPass.setUniform(e,t)};xt.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]=yh(e,t*e,!!this._normalTex)};xt.prototype.setNoiseSize=function(e){var t=this._ssaoPass.getUniform("noiseTex");t?(t.data=rs(e),t.width=t.height=e,t.dirty()):(t=ia(e),this._ssaoPass.setUniform("noiseTex",ia(e))),this._ssaoPass.setUniform("noiseTexSize",[e,e])};xt.prototype.dispose=function(e){this._blurTexture.dispose(e),this._ssaoTexture.dispose(e),this._blurTexture2.dispose(e)};const xh="@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";N.import(xh);function Tt(e){e=e||{},this._ssrPass=new Ve({fragment:N.source("ecgl.ssr.main"),clearColor:[0,0,0,0]}),this._blurPass1=new Ve({fragment:N.source("ecgl.ssr.blur"),clearColor:[0,0,0,0]}),this._blurPass2=new Ve({fragment:N.source("ecgl.ssr.blur"),clearColor:[0,0,0,0]}),this._blendPass=new Ve({fragment:N.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 ne({type:q.HALF_FLOAT}),this._texture2=new ne({type:q.HALF_FLOAT}),this._texture3=new ne({type:q.HALF_FLOAT}),this._prevTexture=new ne({type:q.HALF_FLOAT}),this._currentTexture=new ne({type:q.HALF_FLOAT}),this._frameBuffer=new Ue({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}Tt.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")};Tt.prototype.update=function(e,t,r,i){var n=e.getWidth(),a=e.getHeight(),s=this._ssrTexture,o=this._texture2,l=this._texture3;s.width=this._prevTexture.width=this._currentTexture.width=n/this._downScale,s.height=this._prevTexture.height=this._currentTexture.height=a/this._downScale,o.width=l.width=n,o.height=l.height=a;var c=this._frameBuffer,h=this._ssrPass,u=this._blurPass1,d=this._blurPass2,f=this._blendPass,v=new z,m=new z;z.transpose(v,t.worldTransform),z.transpose(m,t.viewMatrix),h.setUniform("sourceTexture",r),h.setUniform("projection",t.projectionMatrix.array),h.setUniform("projectionInv",t.invProjectionMatrix.array),h.setUniform("toViewSpace",v.array),h.setUniform("toWorldSpace",m.array),h.setUniform("nearZ",t.near);var p=i/this._totalSamples*this._samplePerFrame;if(h.setUniform("jitterOffset",p),h.setUniform("sampleOffset",i*this._samplePerFrame),u.setUniform("textureSize",[s.width,s.height]),d.setUniform("textureSize",[n,a]),d.setUniform("sourceTexture",r),u.setUniform("projection",t.projectionMatrix.array),d.setUniform("projection",t.projectionMatrix.array),c.attach(s),c.bind(e),h.render(e),this._physicallyCorrect&&(c.attach(this._currentTexture),f.setUniform("texture1",this._prevTexture),f.setUniform("texture2",s),f.material.set({weight1:i>=1?.95:0,weight2:i>=1?.05:1}),f.render(e)),c.attach(o),u.setUniform("texture",this._physicallyCorrect?this._currentTexture:s),u.render(e),c.attach(l),d.setUniform("texture",o),d.render(e),c.unbind(e),this._physicallyCorrect){var _=this._prevTexture;this._prevTexture=this._currentTexture,this._currentTexture=_}};Tt.prototype.getTargetTexture=function(){return this._texture3};Tt.prototype.setParameter=function(e,t){e==="maxIteration"?this._ssrPass.material.define("fragment","MAX_ITERATION",t):this._ssrPass.setUniform(e,t)};Tt.prototype.setPhysicallyCorrect=function(e){e?(this._normalDistribution||(this._normalDistribution=Zr.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};Tt.prototype.setSSAOTexture=function(e){var t=this._blurPass2;e?(t.material.enableTexture("ssaoTex"),t.material.set("ssaoTex",e)):t.material.disableTexture("ssaoTex")};Tt.prototype.isFinished=function(e){return this._physicallyCorrect?e>this._totalSamples/this._samplePerFrame:!0};Tt.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 na=[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],Th="@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";N.import(Th);function Di(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 Eh(e,t,r,i,n){var a,s,o,l,c=e.gl;return function(h,u,d){if(!(l&&l.material===h.material)){var f=h.material,v=h.__program,m=f.get("roughness");m==null&&(m=1);var p=f.get("normalMap")||t,_=f.get("roughnessMap"),T=f.get("bumpMap"),y=f.get("uvRepeat"),g=f.get("uvOffset"),E=f.get("detailUvRepeat"),S=f.get("detailUvOffset"),R=!!T&&f.isTextureEnabled("bumpMap"),b=!!_&&f.isTextureEnabled("roughnessMap"),M=f.isDefined("fragment","DOUBLE_SIDED");T=T||r,_=_||i,d!==u?(u.set("normalMap",p),u.set("bumpMap",T),u.set("roughnessMap",_),u.set("useBumpMap",R),u.set("useRoughnessMap",b),u.set("doubleSide",M),y!=null&&u.set("uvRepeat",y),g!=null&&u.set("uvOffset",g),E!=null&&u.set("detailUvRepeat",E),S!=null&&u.set("detailUvOffset",S),u.set("roughness",m)):(v.setUniform(c,"1f","roughness",m),a!==p&&Di(e,v,"normalMap",p,0),s!==T&&T&&Di(e,v,"bumpMap",T,1),o!==_&&_&&Di(e,v,"roughnessMap",_,2),y!=null&&v.setUniform(c,"2f","uvRepeat",y),g!=null&&v.setUniform(c,"2f","uvOffset",g),E!=null&&v.setUniform(c,"2f","detailUvRepeat",E),S!=null&&v.setUniform(c,"2f","detailUvOffset",S),v.setUniform(c,"1i","useBumpMap",+R),v.setUniform(c,"1i","useRoughnessMap",+b),v.setUniform(c,"1i","doubleSide",+M)),a=p,s=T,o=_,l=h}}}function nr(e){this._depthTex=new ne({format:q.DEPTH_COMPONENT,type:q.UNSIGNED_INT}),this._normalTex=new ne({type:q.HALF_FLOAT}),this._framebuffer=new Ue,this._framebuffer.attach(this._normalTex),this._framebuffer.attach(this._depthTex,Ue.DEPTH_ATTACHMENT),this._normalMaterial=new yt({shader:new N(N.source("ecgl.normal.vertex"),N.source("ecgl.normal.fragment"))}),this._normalMaterial.enableTexture(["normalMap","bumpMap","roughnessMap"]),this._defaultNormalMap=Ft.createBlank("#000"),this._defaultBumpMap=Ft.createBlank("#000"),this._defaultRoughessMap=Ft.createBlank("#000"),this._debugPass=new Ve({fragment:N.source("clay.compositor.output")}),this._debugPass.setUniform("texture",this._normalTex),this._debugPass.material.undefine("fragment","OUTPUT_ALPHA")}nr.prototype.getDepthTexture=function(){return this._depthTex};nr.prototype.getNormalTexture=function(){return this._normalTex};nr.prototype.update=function(e,t,r){var i=e.getWidth(),n=e.getHeight(),a=this._depthTex,s=this._normalTex,o=this._normalMaterial;a.width=i,a.height=n,s.width=i,s.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 o},ifRender:function(c){return c.renderNormal},beforeRender:Eh(e,this._defaultNormalMap,this._defaultBumpMap,this._defaultRoughessMap,this._normalMaterial),sort:e.opaqueSortCompare}),this._framebuffer.unbind(e)};nr.prototype.renderDebug=function(e){this._debugPass.render(e)};nr.prototype.dispose=function(e){this._depthTex.dispose(e),this._normalTex.dispose(e)};function br(e){e=e||{},this._edgePass=new Ve({fragment:N.source("ecgl.edge")}),this._edgePass.setUniform("normalTexture",e.normalTexture),this._edgePass.setUniform("depthTexture",e.depthTexture),this._targetTexture=new ne({type:q.HALF_FLOAT}),this._frameBuffer=new Ue,this._frameBuffer.attach(this._targetTexture)}br.prototype.update=function(e,t,r,i){var n=e.getWidth(),a=e.getHeight(),s=this._targetTexture;s.width=n,s.height=a;var o=this._frameBuffer;o.bind(e),this._edgePass.setUniform("projectionInv",t.invProjectionMatrix.array),this._edgePass.setUniform("textureSize",[n,a]),this._edgePass.setUniform("texture",r),this._edgePass.render(e),o.unbind(e)};br.prototype.getTargetTexture=function(){return this._targetTexture};br.prototype.setParameter=function(e,t){this._edgePass.setUniform(e,t)};br.prototype.dispose=function(e){this._targetTexture.dispose(e),this._frameBuffer.dispose(e)};const Ah={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"}}]},Sh="@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",bh="@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";N.import(ja);N.import(Ya);N.import(qa);N.import(Za);N.import($a);N.import(Ka);N.import(Qa);N.import(Ja);N.import(es);N.import(Sh);N.import(bh);function is(e,t){return{color:{parameters:{width:e,height:t}}}}var un=["composite","FXAA"];function J(){this._width,this._height,this._dpr,this._sourceTexture=new ne({type:q.HALF_FLOAT}),this._depthTexture=new ne({format:q.DEPTH_COMPONENT,type:q.UNSIGNED_INT}),this._framebuffer=new Ue,this._framebuffer.attach(this._sourceTexture),this._framebuffer.attach(this._depthTexture,Ue.DEPTH_ATTACHMENT),this._normalPass=new nr,this._compositor=uh(Ah);var e=this._compositor.getNodeByName("source");e.texture=this._sourceTexture;var t=this._compositor.getNodeByName("coc");this._sourceNode=e,this._cocNode=t,this._compositeNode=this._compositor.getNodeByName("composite"),this._fxaaNode=this._compositor.getNodeByName("FXAA"),this._dofBlurNodes=["dof_far_blur","dof_near_blur","dof_coc_blur"].map(function(i){return this._compositor.getNodeByName(i)},this),this._dofBlurKernel=0,this._dofBlurKernelSize=new Float32Array(0),this._finalNodesChain=un.map(function(i){return this._compositor.getNodeByName(i)},this);var r={normalTexture:this._normalPass.getNormalTexture(),depthTexture:this._normalPass.getDepthTexture()};this._ssaoPass=new xt(r),this._ssrPass=new Tt(r),this._edgePass=new br(r)}J.prototype.resize=function(i,n,r){r=r||1;var i=i*r,n=n*r,a=this._sourceTexture,s=this._depthTexture;a.width=i,a.height=n,s.width=i,s.height=n;var o={getWidth:function(){return i},getHeight:function(){return n},getDevicePixelRatio:function(){return r}};function l(c,h){if(typeof c[h]=="function"){var u=c[h].__original||c[h];c[h]=function(d){return u.call(this,o)},c[h].__original=u}}this._compositor.nodes.forEach(function(c){for(var h in c.outputs){var u=c.outputs[h].parameters;u&&(l(u,"width"),l(u,"height"))}for(var d in c.parameters)l(c.parameters,d)}),this._width=i,this._height=n,this._dpr=r};J.prototype.getWidth=function(){return this._width};J.prototype.getHeight=function(){return this._height};J.prototype._ifRenderNormalPass=function(){return this._enableSSAO||this._enableEdge||this._enableSSR};J.prototype._getPrevNode=function(e){for(var t=un.indexOf(e.name)-1,r=this._finalNodesChain[t];r&&!this._compositor.getNodeByName(r.name);)t-=1,r=this._finalNodesChain[t];return r};J.prototype._getNextNode=function(e){for(var t=un.indexOf(e.name)+1,r=this._finalNodesChain[t];r&&!this._compositor.getNodeByName(r.name);)t+=1,r=this._finalNodesChain[t];return r};J.prototype._addChainNode=function(e){var t=this._getPrevNode(e),r=this._getNextNode(e);t&&(e.inputs.texture=t.name,r?(e.outputs=is(this.getWidth.bind(this),this.getHeight.bind(this)),r.inputs.texture=e.name):e.outputs=null,this._compositor.addNode(e))};J.prototype._removeChainNode=function(e){var t=this._getPrevNode(e),r=this._getNextNode(e);t&&(r?(t.outputs=is(this.getWidth.bind(this),this.getHeight.bind(this)),r.inputs.texture=t.name):t.outputs=null,this._compositor.removeNode(e))};J.prototype.updateNormal=function(e,t,r,i){this._ifRenderNormalPass()&&this._normalPass.update(e,t,r)};J.prototype.updateSSAO=function(e,t,r,i){this._ssaoPass.update(e,r,i)};J.prototype.enableSSAO=function(){this._enableSSAO=!0};J.prototype.disableSSAO=function(){this._enableSSAO=!1};J.prototype.enableSSR=function(){this._enableSSR=!0};J.prototype.disableSSR=function(){this._enableSSR=!1};J.prototype.getSSAOTexture=function(){return this._ssaoPass.getTargetTexture()};J.prototype.getSourceFrameBuffer=function(){return this._framebuffer};J.prototype.getSourceTexture=function(){return this._sourceTexture};J.prototype.disableFXAA=function(){this._removeChainNode(this._fxaaNode)};J.prototype.enableFXAA=function(){this._addChainNode(this._fxaaNode)};J.prototype.enableBloom=function(){this._compositeNode.inputs.bloom="bloom_composite",this._compositor.dirty()};J.prototype.disableBloom=function(){this._compositeNode.inputs.bloom=null,this._compositor.dirty()};J.prototype.enableDOF=function(){this._compositeNode.inputs.texture="dof_composite",this._compositor.dirty()};J.prototype.disableDOF=function(){this._compositeNode.inputs.texture="source",this._compositor.dirty()};J.prototype.enableColorCorrection=function(){this._compositeNode.define("COLOR_CORRECTION"),this._enableColorCorrection=!0};J.prototype.disableColorCorrection=function(){this._compositeNode.undefine("COLOR_CORRECTION"),this._enableColorCorrection=!1};J.prototype.enableEdge=function(){this._enableEdge=!0};J.prototype.disableEdge=function(){this._enableEdge=!1};J.prototype.setBloomIntensity=function(e){this._compositeNode.setParameter("bloomIntensity",e)};J.prototype.setSSAOParameter=function(e,t){switch(e){case"quality":var r={low:6,medium:12,high:32,ultra:62}[t]||12;this._ssaoPass.setParameter("kernelSize",r);break;case"radius":this._ssaoPass.setParameter(e,t),this._ssaoPass.setParameter("bias",t/200);break;case"intensity":this._ssaoPass.setParameter(e,t);break}};J.prototype.setDOFParameter=function(e,t){switch(e){case"focalDistance":case"focalRange":case"fstop":this._cocNode.setParameter(e,t);break;case"blurRadius":for(var r=0;r<this._dofBlurNodes.length;r++)this._dofBlurNodes[r].setParameter("blurRadius",t);break;case"quality":var i={low:4,medium:8,high:16,ultra:32}[t]||8;this._dofBlurKernelSize=i;for(var r=0;r<this._dofBlurNodes.length;r++)this._dofBlurNodes[r].pass.material.define("POISSON_KERNEL_SIZE",i);this._dofBlurKernel=new Float32Array(i*2);break}};J.prototype.setSSRParameter=function(e,t){if(t!=null)switch(e){case"quality":var r={low:10,medium:15,high:30,ultra:80}[t]||20,i={low:32,medium:16,high:8,ultra:4}[t]||16;this._ssrPass.setParameter("maxIteration",r),this._ssrPass.setParameter("pixelStride",i);break;case"maxRoughness":this._ssrPass.setParameter("minGlossiness",Math.max(Math.min(1-t,1),0));break;case"physical":this.setPhysicallyCorrectSSR(t);break;default:console.warn("Unkown SSR parameter "+e)}};J.prototype.setPhysicallyCorrectSSR=function(e){this._ssrPass.setPhysicallyCorrect(e)};J.prototype.setEdgeColor=function(e){var t=V.parseColor(e);this._edgePass.setParameter("edgeColor",t)};J.prototype.setExposure=function(e){this._compositeNode.setParameter("exposure",Math.pow(2,e))};J.prototype.setColorLookupTexture=function(e,t){this._compositeNode.pass.material.setTextureImage("lut",this._enableColorCorrection?e:"none",t,{minFilter:V.Texture.NEAREST,magFilter:V.Texture.NEAREST,flipY:!1})};J.prototype.setColorCorrection=function(e,t){this._compositeNode.setParameter(e,t)};J.prototype.isSSREnabled=function(){return this._enableSSR};J.prototype.composite=function(e,t,r,i,n){var a=this._sourceTexture,s=a;this._enableEdge&&(this._edgePass.update(e,r,a,n),a=s=this._edgePass.getTargetTexture()),this._enableSSR&&(this._ssrPass.update(e,r,a,n),s=this._ssrPass.getTargetTexture(),this._ssrPass.setSSAOTexture(this._enableSSAO?this._ssaoPass.getTargetTexture():null)),this._sourceNode.texture=s,this._cocNode.setParameter("depth",this._depthTexture);for(var o=this._dofBlurKernel,l=this._dofBlurKernelSize,c=Math.floor(na.length/2/l),h=n%c,u=0;u<l*2;u++)o[u]=na[u+h*l*2];for(var u=0;u<this._dofBlurNodes.length;u++)this._dofBlurNodes[u].setParameter("percent",n/30),this._dofBlurNodes[u].setParameter("poissonKernel",o);this._cocNode.setParameter("zNear",r.near),this._cocNode.setParameter("zFar",r.far),this._compositor.render(e,i)};J.prototype.dispose=function(e){this._sourceTexture.dispose(e),this._depthTexture.dispose(e),this._framebuffer.dispose(e),this._compositor.dispose(e),this._normalPass.dispose(e),this._ssaoPass.dispose(e)};function qi(e){for(var t=[],r=0;r<30;r++)t.push([rr(r,2),rr(r,3)]);this._haltonSequence=t,this._frame=0,this._sourceTex=new ne,this._sourceFb=new Ue,this._sourceFb.attach(this._sourceTex),this._prevFrameTex=new ne,this._outputTex=new ne;var i=this._blendPass=new Ve({fragment:N.source("clay.compositor.blend")});i.material.disableTexturesAll(),i.material.enableTexture(["texture1","texture2"]),this._blendFb=new Ue({depthBuffer:!1}),this._outputPass=new Ve({fragment:N.source("clay.compositor.output"),blendWithPrevious:!0}),this._outputPass.material.define("fragment","OUTPUT_ALPHA"),this._outputPass.material.blend=function(n){n.blendEquationSeparate(n.FUNC_ADD,n.FUNC_ADD),n.blendFuncSeparate(n.ONE,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA)}}qi.prototype={constructor:qi,jitterProjection:function(e,t){var r=e.viewport,i=r.devicePixelRatio||e.getDevicePixelRatio(),n=r.width*i,a=r.height*i,s=this._haltonSequence[this._frame%this._haltonSequence.length],o=new z;o.array[12]=(s[0]*2-1)/n,o.array[13]=(s[1]*2-1)/a,z.mul(t.projectionMatrix,o,t.projectionMatrix),z.invert(t.invProjectionMatrix,t.projectionMatrix)},resetFrame:function(){this._frame=0},getFrame:function(){return this._frame},getSourceFrameBuffer:function(){return this._sourceFb},getOutputTexture:function(){return this._outputTex},resize:function(e,t){this._prevFrameTex.width=e,this._prevFrameTex.height=t,this._outputTex.width=e,this._outputTex.height=t,this._sourceTex.width=e,this._sourceTex.height=t,this._prevFrameTex.dirty(),this._outputTex.dirty(),this._sourceTex.dirty()},isFinished:function(){return this._frame>=this._haltonSequence.length},render:function(e,t,r){var i=this._blendPass;this._frame===0?(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)}};function _e(e){e=e||"perspective",this.layer=null,this.scene=new Ct,this.rootNode=this.scene,this.viewport={x:0,y:0,width:0,height:0},this.setProjection(e),this._compositor=new J,this._temporalSS=new qi,this._shadowMapPass=new qc;for(var t=[],r=0,i=0;i<30;i++){for(var n=[],a=0;a<6;a++)n.push(rr(r,2)*4-2),n.push(rr(r,3)*4-2),r++;t.push(n)}this._pcfKernels=t,this.scene.on("beforerender",function(s,o,l){this.needsTemporalSS()&&this._temporalSS.jitterProjection(s,l)},this)}_e.prototype.setProjection=function(e){var t=this.camera;t&&t.update(),e==="perspective"?this.camera instanceof Ne||(this.camera=new Ne,t&&this.camera.setLocalTransform(t.localTransform)):this.camera instanceof xr||(this.camera=new xr,t&&this.camera.setLocalTransform(t.localTransform)),this.camera.near=.1,this.camera.far=2e3};_e.prototype.setViewport=function(e,t,r,i,n){this.camera instanceof Ne&&(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)};_e.prototype.containPoint=function(e,t){var r=this.viewport,i=this.layer.renderer.getHeight();return t=i-t,e>=r.x&&t>=r.y&&e<=r.x+r.width&&t<=r.y+r.height};var aa=new $e;_e.prototype.castRay=function(e,t,r){var i=this.layer.renderer,n=i.viewport;return i.viewport=this.viewport,i.screenToNDC(e,t,aa),this.camera.castRay(aa,r),i.viewport=n,r};_e.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;t<e.transparent.length;t++){var r=e.transparent[t],i=r.geometry;i.needsSortVerticesProgressively&&i.needsSortVerticesProgressively()&&(this._needsSortProgressively=!0),i.needsSortTrianglesProgressively&&i.needsSortTrianglesProgressively()&&(this._needsSortProgressively=!0)}this._frame=0,this._temporalSS.resetFrame()};_e.prototype.render=function(e,t){this._doRender(e,t,this._frame),this._frame++};_e.prototype.needsAccumulate=function(){return this.needsTemporalSS()||this._needsSortProgressively};_e.prototype.needsTemporalSS=function(){var e=this._enableTemporalSS;return e==="auto"&&(e=this._enablePostEffect),e};_e.prototype.hasDOF=function(){return this._enableDOF};_e.prototype.isAccumulateFinished=function(){return this.needsTemporalSS()?this._temporalSS.isFinished():this._frame>30};_e.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=e.clearColor;if(e.gl.clearColor(a[0],a[1],a[2],a[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){var s=this._compositor.getSourceFrameBuffer();s.bind(e),e.gl.clear(e.gl.DEPTH_BUFFER_BIT|e.gl.COLOR_BUFFER_BIT),e.render(i,n,!0,!0),s.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))}else if(this.needsTemporalSS()&&t){var s=this._temporalSS.getSourceFrameBuffer();s.bind(e),e.saveClear(),e.clearBit=e.gl.DEPTH_BUFFER_BIT|e.gl.COLOR_BUFFER_BIT,e.render(i,n,!0,!0),e.restoreClear(),s.unbind(e),e.setViewport(this.viewport),this._temporalSS.render(e)}else e.setViewport(this.viewport),e.render(i,n,!0,!0)};_e.prototype._updateTransparent=function(e,t,r,i){for(var n=new P,a=new z,s=r.getWorldPosition(),o=t.getRenderList(r).transparent,l=0;l<o.length;l++){var c=o[l],h=c.geometry;z.invert(a,c.worldTransform),P.transformMat4(n,s,a),h.needsSortTriangles&&h.needsSortTriangles()&&h.doSortTriangles(n,i),h.needsSortVertices&&h.needsSortVertices()&&h.doSortVertices(n,i)}};_e.prototype._updateSSAO=function(e,t,r){var i=this._enableSSAO&&this._enablePostEffect;i&&this._compositor.updateSSAO(e,t,r,this._temporalSS.getFrame());for(var n=t.getRenderList(r),a=0;a<n.opaque.length;a++){var s=n.opaque[a];s.renderNormal&&s.material[i?"enableTexture":"disableTexture"]("ssaoMap"),i&&s.material.set("ssaoMap",this._compositor.getSSAOTexture())}};_e.prototype._updateShadowPCFKernel=function(e){for(var t=this._pcfKernels[e%this._pcfKernels.length],r=this.scene.getRenderList(this.camera),i=r.opaque,n=0;n<i.length;n++)i[n].receiveShadow&&(i[n].material.set("pcfKernel",t),i[n].material.define("fragment","PCF_KERNEL_SIZE",t.length/2))};_e.prototype.dispose=function(e){this._compositor.dispose(e.gl),this._temporalSS.dispose(e.gl),this._shadowMapPass.dispose(e)};_e.prototype.setPostEffect=function(e,t){var r=this._compositor;this._enablePostEffect=e.get("enable");var i=e.getModel("bloom"),n=e.getModel("edge"),a=e.getModel("DOF",e.getModel("depthOfField")),s=e.getModel("SSAO",e.getModel("screenSpaceAmbientOcclusion")),o=e.getModel("SSR",e.getModel("screenSpaceReflection")),l=e.getModel("FXAA"),c=e.getModel("colorCorrection");i.get("enable")?r.enableBloom():r.disableBloom(),a.get("enable")?r.enableDOF():r.disableDOF(),o.get("enable")?r.enableSSR():r.disableSSR(),c.get("enable")?r.enableColorCorrection():r.disableColorCorrection(),n.get("enable")?r.enableEdge():r.disableEdge(),l.get("enable")?r.enableFXAA():r.disableFXAA(),this._enableDOF=a.get("enable"),this._enableSSAO=s.get("enable"),this._enableSSAO?r.enableSSAO():r.disableSSAO(),r.setBloomIntensity(i.get("intensity")),r.setEdgeColor(n.get("color")),r.setColorLookupTexture(c.get("lookupTexture"),t),r.setExposure(c.get("exposure")),["radius","quality","intensity"].forEach(function(h){r.setSSAOParameter(h,s.get(h))}),["quality","maxRoughness","physical"].forEach(function(h){r.setSSRParameter(h,o.get(h))}),["quality","focalDistance","focalRange","blurRadius","fstop"].forEach(function(h){r.setDOFParameter(h,a.get(h))}),["brightness","contrast","saturation"].forEach(function(h){r.setColorCorrection(h,c.get(h))})};_e.prototype.setDOFFocusOnPoint=function(e){if(this._enablePostEffect)return e>this.camera.far||e<this.camera.near?void 0:(this._compositor.setDOFParameter("focalDistance",e),!0)};_e.prototype.setTemporalSuperSampling=function(e){this._enableTemporalSS=e.get("enable")};_e.prototype.isLinearSpace=function(){return this._enablePostEffect};_e.prototype.setRootNode=function(e){if(this.rootNode!==e){for(var t=this.rootNode.children(),r=0;r<t.length;r++)e.add(t[r]);e!==this.scene&&this.scene.add(e),this.rootNode=e}};_e.prototype.add=function(e){this.rootNode.add(e)};_e.prototype.remove=function(e){this.rootNode.remove(e)};_e.prototype.removeAll=function(e){this.rootNode.removeAll(e)};Object.assign(_e.prototype,$i);function wh(e,t){var r=e.getBoxLayoutParams(),i=zs(r,{width:t.getWidth(),height:t.getHeight()});i.y=t.getHeight()-i.y-i.height,this.viewGL.setViewport(i.x,i.y,i.width,i.height,t.getDevicePixelRatio());var n=e.get("boxWidth"),a=e.get("boxHeight"),s=e.get("boxDepth");this.getAxis("x").setExtent(-n/2,n/2),this.getAxis("y").setExtent(s/2,-s/2),this.getAxis("z").setExtent(-a/2,a/2),this.size=[n,a,s]}function Ch(e,t){var r={};function i(n,a){r[n]=r[n]||[1/0,-1/0],r[n][0]=Math.min(a[0],r[n][0]),r[n][1]=Math.max(a[1],r[n][1])}e.eachSeries(function(n){if(n.coordinateSystem===this){var a=n.getData();["x","y","z"].forEach(function(s){a.mapDimensionsAll(s,!0).forEach(function(o){i(s,a.getDataExtent(o,!0))})})}},this),["xAxis3D","yAxis3D","zAxis3D"].forEach(function(n){e.eachComponent(n,function(a){var s=n.charAt(0),o=a.getReferringComponents("grid3D").models[0],l=o.coordinateSystem;if(l===this){var c=l.getAxis(s);if(!c){var h=Gs(r[s]||[1/0,-1/0],a);c=new ti(s,h),c.type=a.get("type");var u=c.type==="category";c.onBand=u&&a.get("boundaryGap"),c.inverse=a.get("inverse"),a.axis=c,c.model=a,c.getLabelModel=function(){return a.getModel("axisLabel",o.getModel("axisLabel"))},c.getTickModel=function(){return a.getModel("axisTick",o.getModel("axisTick"))},l.addAxis(c)}}},this)},this),this.resize(this.model,t)}var Rh={dimensions:Tr.prototype.dimensions,create:function(e,t){var r=[];e.eachComponent("grid3D",function(a){a.__viewGL=a.__viewGL||new _e;var s=new Tr;s.model=a,s.viewGL=a.__viewGL,a.coordinateSystem=s,r.push(s),s.resize=wh,s.update=Ch});var i=["xAxis3D","yAxis3D","zAxis3D"];function n(a,s){return i.map(function(o){var l=a.getReferringComponents(o).models[0];return l==null&&(l=s.getComponent(o)),l})}return e.eachSeries(function(a){if(a.get("coordinateSystem")==="cartesian3D"){var s=a.getReferringComponents("grid3D").models[0];if(s==null){var o=n(a,e),s=o[0].getCoordSysModel();o.forEach(function(h){h.getCoordSysModel()})}var l=s.coordinateSystem;a.coordinateSystem=l}}),r}};const Mh=Rh;var ns=da.extend({type:"cartesian3DAxis",axis:null,getCoordSysModel:function(){return this.ecModel.queryComponents({mainType:"grid3D",index:this.option.gridIndex,id:this.option.gridId})[0]}});ks(ns);const Nh=ns;var as={show:!0,grid3DIndex:0,inverse:!1,name:"",nameLocation:"middle",nameTextStyle:{fontSize:16},nameGap:20,axisPointer:{},axisLine:{},axisTick:{},axisLabel:{},splitArea:{}},Lh=_t({boundaryGap:!0,axisTick:{alignWithLabel:!1,interval:"auto"},axisLabel:{interval:"auto"},axisPointer:{label:{show:!1}}},as),fn=_t({boundaryGap:[0,0],splitNumber:5,axisPointer:{label:{}}},as),Ph=Ar({scale:!0,min:"dataMin",max:"dataMax"},fn),ss=Ar({logBase:10},fn);ss.scale=!0;const Dh={categoryAxis3D:Lh,valueAxis3D:fn,timeAxis3D:Ph,logAxis3D:ss};var Ih=["value","category","time","log"];function Oh(e,t,r,i,n){Ih.forEach(function(a){var s=r.extend({type:t+"Axis3D."+a,__ordinalMeta:null,mergeDefaultAndTheme:function(o,l){var c=l.getTheme();_t(o,c.get(a+"Axis3D")),_t(o,this.getDefaultOption()),o.type=i(t,o)},optionUpdated:function(){var o=this.option;o.type==="category"&&(this.__ordinalMeta=Vs.createByAxisModel(this))},getCategories:function(){if(this.option.type==="category")return this.__ordinalMeta.categories},getOrdinalMeta:function(){return this.__ordinalMeta},defaultOption:_t(Ws(Dh[a+"Axis3D"]),n||{},!0)});e.registerComponentModel(s)}),e.registerSubTypeDefaulter(t+"Axis3D",Xs(i,t))}function Bh(e,t){return t.type||(t.data?"category":"value")}function Fh(e){e.registerComponentModel(Bc),e.registerComponentView(Wc),e.registerCoordinateSystem("grid3D",Mh),["x","y","z"].forEach(function(t){Oh(e,t,Nh,Bh,{name:t.toUpperCase()});const r=e.ComponentView.extend({type:t+"Axis3D"});e.registerComponentView(r)}),e.registerAction({type:"grid3DChangeCamera",event:"grid3dcamerachanged",update:"series:updateCamera"},function(t,r){r.eachComponent({mainType:"grid3D",query:t},function(i){i.setView(t)})}),e.registerAction({type:"grid3DShowAxisPointer",event:"grid3dshowaxispointer",update:"grid3D:showAxisPointer"},function(t,r){}),e.registerAction({type:"grid3DHideAxisPointer",event:"grid3dhideaxispointer",update:"grid3D:hideAxisPointer"},function(t,r){})}const Uh={defaultOption:{shading:null,realisticMaterial:{textureTiling:1,textureOffset:0,detailTexture:null},lambertMaterial:{textureTiling:1,textureOffset:0,detailTexture:null},colorMaterial:{textureTiling:1,textureOffset:0,detailTexture:null},hatchingMaterial:{textureTiling:1,textureOffset:0,paperColor:"#fff"}}};function Ii(e,t,r){var i=e[t];e[t]=e[r],e[r]=i}function os(e,t,r,i,n){var a=r,s=e[t];Ii(e,t,i);for(var o=r;o<i;o++)n(e[o],s)<0&&(Ii(e,o,a),a++);return Ii(e,i,a),a}function ri(e,t,r,i){if(r<i){var n=Math.floor((r+i)/2),a=os(e,n,r,i,t);ri(e,t,r,a-1),ri(e,t,a+1,i)}}function ii(){this._parts=[]}ii.prototype.step=function(e,t,r){var i=e.length;if(r===0){this._parts=[],this._sorted=!1;var n=Math.floor(i/2);this._parts.push({pivot:n,left:0,right:i-1}),this._currentSortPartIdx=0}if(!this._sorted){var a=this._parts;if(a.length===0)return this._sorted=!0,!0;if(a.length<512){for(var s=0;s<a.length;s++)a[s].pivot=os(e,a[s].pivot,a[s].left,a[s].right,t);for(var o=[],s=0;s<a.length;s++){var l=a[s].left,c=a[s].pivot-1;c>l&&o.push({pivot:Math.floor((c+l)/2),left:l,right:c});var l=a[s].pivot+1,c=a[s].right;c>l&&o.push({pivot:Math.floor((c+l)/2),left:l,right:c})}a=this._parts=o}else for(var s=0;s<Math.floor(a.length/10);s++){var h=a.length-1-this._currentSortPartIdx;if(ri(e,t,a[h].left,a[h].right),this._currentSortPartIdx++,this._currentSortPartIdx===a.length)return this._sorted=!0,!0}return!1}};ii.sort=ri;var Qt=ci.vec3,sa=Qt.create(),oa=Qt.create(),la=Qt.create();const Hh={needsSortTriangles:function(){return this.indices&&this.sortTriangles},needsSortTrianglesProgressively:function(){return this.needsSortTriangles()&&this.triangleCount>=2e4},doSortTriangles:function(e,t){var r=this.indices;if(t===0){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=0,a,s=0;s<r.length;){i.get(r[s++],sa),i.get(r[s++],oa),i.get(r[s++],la);var o=Qt.sqrDist(sa,e),l=Qt.sqrDist(oa,e),c=Qt.sqrDist(la,e),h=Math.min(o,l);h=Math.min(h,c),s===3?(a=h,h=0):h=h-a,this._triangleZList[n++]=h}}for(var u=this._sortedTriangleIndices,s=0;s<u.length;s++)u[s]=s;if(this.triangleCount<2e4)t===0&&this._simpleSort(!0);else for(var s=0;s<3;s++)this._progressiveQuickSort(t*3+s);for(var d=this._indicesTmp,f=this._triangleZListTmp,v=this._triangleZList,s=0;s<this.triangleCount;s++){var m=u[s]*3,p=s*3;d[p++]=r[m++],d[p++]=r[m++],d[p]=r[m],f[s]=v[u[s]]}var _=this._indicesTmp;this._indicesTmp=this.indices,this.indices=_;var _=this._triangleZListTmp;this._triangleZListTmp=this._triangleZList,this._triangleZList=_,this.dirtyIndices()},_simpleSort:function(e){var t=this._triangleZList,r=this._sortedTriangleIndices;function i(n,a){return t[a]-t[n]}e?Array.prototype.sort.call(r,i):ii.sort(r,i,0,r.length-1)},_progressiveQuickSort:function(e){var t=this._triangleZList,r=this._sortedTriangleIndices;this._quickSort=this._quickSort||new ii,this._quickSort.step(r,function(i,n){return t[n]-t[i]},e)}};function Zi(e,t){const r=e.getItemVisual(t,"style");if(r){const i=e.getVisual("drawType");return r[i]}}function ca(e,t){const r=e.getItemVisual(t,"style");return r&&r.opacity}function zh(e,t){var r=[];return pr(e.dimensions,function(i){var n=e.getDimensionInfo(i),a=n.otherDims,s=a[t];s!=null&&s!==!1&&(r[s]=n.name)}),r}function Gh(e,t,r){function i(u){var d=[],f=zh(n,"tooltip");f.length?pr(f,function(m){v(n.get(m,t),m)}):pr(u,v);function v(m,p){var _=n.getDimensionInfo(p);if(!(!_||_.otherDims.tooltip===!1)){var T=_.type,y="- "+(_.tooltipName||_.name)+": "+(T==="ordinal"?m+"":T==="time"?r?"":qs("yyyy/MM/dd hh:mm:ss",m):vn(m));y&&d.push(wr(y))}}return"<br/>"+d.join("<br/>")}var n=e.getData(),a=e.getRawValue(t),s=mr(a)?i(a):wr(vn(a)),o=n.getName(t),l=Zi(n,t);js(l)&&l.colorStops&&(l=(l.colorStops[0]||{}).color),l=l||"transparent";var c=Ys(l),h=e.name;return h==="\0-"&&(h=""),h=h?wr(h)+(r?": ":"<br/>"):"",r?c+h+s:h+c+(o?wr(o)+": "+s:s)}function kh(e,t,r){r=r||e.getSource();var i=t||Zs(e.get("coordinateSystem"))||["x","y","z"],n=$s(r,{dimensionsDefine:r.dimensionsDefine||e.get("dimensions"),encodeDefine:r.encodeDefine||e.get("encode"),coordDimensions:i.map(function(o){var l=e.getReferringComponents(o+"Axis3D").models[0];return{type:l&&l.get("type")==="category"?"ordinal":"float",name:o}})});e.get("coordinateSystem")==="cartesian3D"&&n.forEach(function(o){if(i.indexOf(o.coordDim)>=0){var l=e.getReferringComponents(o.coordDim+"Axis3D").models[0];l&&l.get("type")==="category"&&(o.ordinalMeta=l.getOrdinalMeta())}});var a=Ks.enableDataStack(e,n,{byIndex:!0,stackedCoordDimension:"z"}),s=new Qs(n,e);return s.setCalculationInfo(a),s.initData(r),s}var ls=Js.extend({type:"series.surface",dependencies:["globe","grid3D","geo3D"],visualStyleAccessPath:"itemStyle",formatTooltip:function(e){return Gh(this,e)},getInitialData:function(e,t){var r=e.data;function i(Z){return!(isNaN(Z.min)||isNaN(Z.max)||isNaN(Z.step))}function n(Z){var I=va;return Math.max(I(Z.min),I(Z.max),I(Z.step))+1}if(!r)if(e.parametric){var g=e.parametricEquation||{},E=g.u||{},S=g.v||{};["u","v"].forEach(function(I){i(g[I])}),["x","y","z"].forEach(function(I){g[I]});var R=Math.floor((E.max+E.step-E.min)/E.step),b=Math.floor((S.max+S.step-S.min)/S.step);r=new Float32Array(R*b*5);for(var M=n(E),F=n(S),d=0,f=0;f<b;f++)for(var v=0;v<R;v++){var w=v*E.step+E.min,U=f*S.step+S.min,O=Cr(Math.min(w,E.max),M),L=Cr(Math.min(U,S.max),F),m=g.x(O,L),p=g.y(O,L),y=g.z(O,L);r[d++]=m,r[d++]=p,r[d++]=y,r[d++]=O,r[d++]=L}}else{var a=e.equation||{},s=a.x||{},o=a.y||{};if(["x","y"].forEach(function(Z){i(a[Z])}),typeof a.z!="function")return;var l=Math.floor((s.max+s.step-s.min)/s.step),c=Math.floor((o.max+o.step-o.min)/o.step);r=new Float32Array(l*c*3);for(var h=n(s),u=n(o),d=0,f=0;f<c;f++)for(var v=0;v<l;v++){var m=v*s.step+s.min,p=f*o.step+o.min,_=Cr(Math.min(m,s.max),h),T=Cr(Math.min(p,o.max),u),y=a.z(_,T);r[d++]=_,r[d++]=T,r[d++]=y}}var G=["x","y","z"];e.parametric&&G.push("u","v");var B=kh(this,G,r);return B},defaultOption:{coordinateSystem:"cartesian3D",zlevel:-10,grid3DIndex:0,shading:"lambert",parametric:!1,wireframe:{show:!0,lineStyle:{color:"rgba(0,0,0,0.5)",width:1}},equation:{x:{min:-1,max:1,step:.1},y:{min:-1,max:1,step:.1},z:null},parametricEquation:{u:{min:-1,max:1,step:.1},v:{min:-1,max:1,step:.1},x:null,y:null,z:null},dataShape:null,itemStyle:{},animationDurationUpdate:500}});_t(ls.prototype,Uh);const Vh=ls;var It=ci.vec3;function Wh(e){return isNaN(e[0])||isNaN(e[1])||isNaN(e[2])}const Xh=eo.extend({type:"surface",__ecgl__:!0,init:function(e,t){this.groupGL=new V.Node},render:function(e,t,r){var i=this._prevSurfaceMesh;this._prevSurfaceMesh=this._surfaceMesh,this._surfaceMesh=i,this._surfaceMesh||(this._surfaceMesh=this._createSurfaceMesh()),this.groupGL.remove(this._prevSurfaceMesh),this.groupGL.add(this._surfaceMesh);var n=e.coordinateSystem,a=e.get("shading"),s=e.getData(),o="ecgl."+a;if((!this._surfaceMesh.material||this._surfaceMesh.material.shader.name!==o)&&(this._surfaceMesh.material=V.createMaterial(o,["VERTEX_COLOR","DOUBLE_SIDED"])),V.setMaterialFromModel(a,this._surfaceMesh.material,e,r),n&&n.viewGL){n.viewGL.add(this.groupGL);var l=n.viewGL.isLinearSpace()?"define":"undefine";this._surfaceMesh.material[l]("fragment","SRGB_DECODE")}var c=e.get("parametric"),h=e.get("dataShape");h||(h=this._getDataShape(s,c));var u=e.getModel("wireframe"),d=u.get("lineStyle.width"),f=u.get("show")&&d>0;this._updateSurfaceMesh(this._surfaceMesh,e,h,f);var v=this._surfaceMesh.material;f?(v.define("WIREFRAME_QUAD"),v.set("wireframeLineWidth",d),v.set("wireframeLineColor",V.parseColor(u.get("lineStyle.color")))):v.undefine("WIREFRAME_QUAD"),this._initHandler(e,r),this._updateAnimation(e)},_updateAnimation:function(e){V.updateVertexAnimation([["prevPosition","position"],["prevNormal","normal"]],this._prevSurfaceMesh,this._surfaceMesh,e)},_createSurfaceMesh:function(){var e=new V.Mesh({geometry:new V.Geometry({dynamic:!0,sortTriangles:!0}),shadowDepthMaterial:new V.Material({shader:new V.Shader(V.Shader.source("ecgl.sm.depth.vertex"),V.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,Hh),e},_initHandler:function(e,t){var r=e.getData(),i=this._surfaceMesh,n=e.coordinateSystem;function a(o,l){for(var c=1/0,h=-1,u=[],d=0;d<o.length;d++){i.geometry.attributes.position.get(o[d],u);var f=It.dist(l.array,u);f<c&&(c=f,h=o[d])}return h}i.seriesIndex=e.seriesIndex;var s=-1;i.off("mousemove"),i.off("mouseout"),i.on("mousemove",function(o){var l=a(o.triangle,o.point);if(l>=0){var c=[];i.geometry.attributes.position.get(l,c);for(var h=n.pointToData(c),u=1/0,d=-1,f=[],v=0;v<r.count();v++){f[0]=r.get("x",v),f[1]=r.get("y",v),f[2]=r.get("z",v);var m=It.squaredDistance(f,h);m<u&&(d=v,u=m)}d!==s&&t.dispatchAction({type:"grid3DShowAxisPointer",value:h}),s=d,i.dataIndex=d}else i.dataIndex=-1},this),i.on("mouseout",function(o){s=-1,i.dataIndex=-1,t.dispatchAction({type:"grid3DHideAxisPointer"})},this)},_updateSurfaceMesh:function(e,t,r,i){var n=e.geometry,a=t.getData(),s=a.getLayout("points"),o=0;a.each(function(ct){a.hasValue(ct)||o++});var l=o||i,c=n.attributes.position,h=n.attributes.normal,u=n.attributes.texcoord0,d=n.attributes.barycentric,f=n.attributes.color,v=r[0],m=r[1],p=t.get("shading"),_=p!=="color";if(l){var T=(v-1)*(m-1)*4;c.init(T),i&&d.init(T)}else c.value=new Float32Array(s);f.init(n.vertexCount),u.init(n.vertexCount);var y=[0,3,1,1,3,2],g=[[1,1,0,0],[0,1,0,1],[1,0,0,1],[1,0,1,0]],E=n.indices=new(n.vertexCount>65535?Uint32Array:Uint16Array)((v-1)*(m-1)*6),S=function(ct,Gt,vt){vt[1]=ct*m+Gt,vt[0]=ct*m+Gt+1,vt[3]=(ct+1)*m+Gt+1,vt[2]=(ct+1)*m+Gt},R=!1;if(l){var b=[],M=[],F=0;_?h.init(n.vertexCount):h.value=null;for(var w=[[],[],[]],U=[],O=[],L=It.create(),G=function(ct,Gt,vt){var ui=Gt*3;return vt[0]=ct[ui],vt[1]=ct[ui+1],vt[2]=ct[ui+2],vt},B=new Float32Array(s.length),Z=new Float32Array(s.length/3*4),I=0;I<a.count();I++)if(a.hasValue(I)){var Fe=V.parseColor(Zi(a,I)),ue=ca(a,I);ue!=null&&(Fe[3]*=ue),Fe[3]<.99&&(R=!0);for(var k=0;k<4;k++)Z[I*4+k]=Fe[k]}for(var ye=[1e7,1e7,1e7],I=0;I<v-1;I++)for(var ae=0;ae<m-1;ae++){var ve=I*(m-1)+ae,me=ve*4;S(I,ae,b);for(var Oe=!1,k=0;k<4;k++)G(s,b[k],M),Wh(M)&&(Oe=!0);for(var k=0;k<4;k++)Oe?c.set(me+k,ye):(G(s,b[k],M),c.set(me+k,M)),i&&d.set(me+k,g[k]);for(var k=0;k<6;k++)E[F++]=y[k]+me;if(_&&!Oe)for(var k=0;k<2;k++){for(var Be=k*3,Re=0;Re<3;Re++){var ze=b[y[Be]+Re];G(s,ze,w[Re])}It.sub(U,w[0],w[1]),It.sub(O,w[1],w[2]),It.cross(L,U,O);for(var Re=0;Re<3;Re++){var Ze=b[y[Be]+Re]*3;B[Ze]=B[Ze]+L[0],B[Ze+1]=B[Ze+1]+L[1],B[Ze+2]=B[Ze+2]+L[2]}}}if(_)for(var I=0;I<B.length/3;I++)G(B,I,L),It.normalize(L,L),B[I*3]=L[0],B[I*3+1]=L[1],B[I*3+2]=L[2];for(var Fe=[],rt=[],I=0;I<v-1;I++)for(var ae=0;ae<m-1;ae++){var ve=I*(m-1)+ae,me=ve*4;S(I,ae,b);for(var k=0;k<4;k++){for(var Re=0;Re<4;Re++)Fe[Re]=Z[b[k]*4+Re];f.set(me+k,Fe),_&&(G(B,b[k],L),h.set(me+k,L));var ze=b[k];rt[0]=ze%m/(m-1),rt[1]=Math.floor(ze/m)/(v-1),u.set(me+k,rt)}ve++}}else{for(var rt=[],I=0;I<a.count();I++){rt[0]=I%m/(m-1),rt[1]=Math.floor(I/m)/(v-1);var Fe=V.parseColor(Zi(a,I)),ue=ca(a,I);ue!=null&&(Fe[3]*=ue),Fe[3]<.99&&(R=!0),f.set(I,Fe),u.set(I,rt)}for(var b=[],hs=0,I=0;I<v-1;I++)for(var ae=0;ae<m-1;ae++){S(I,ae,b);for(var k=0;k<6;k++)E[hs++]=b[y[k]]}_?n.generateVertexNormals():h.value=null}e.material.get("normalMap")&&n.generateTangents(),n.updateBoundingBox(),n.dirty(),e.material.transparent=R,e.material.depthMask=!R},_getDataShape:function(e,t){for(var r=-1/0,i=0,n=0,a=!1,s=t?"u":"x",o=e.count(),l=0;l<o;l++){var c=e.get(s,l);c<r&&(n=0,i++),r=c,n++}if((!i||n===1)&&(a=!0),!a)return[i+1,n];for(var h=Math.floor(Math.sqrt(o));h>0;){if(Math.floor(o/h)===o/h)return[h,o/h];h--}return h=Math.floor(Math.sqrt(o)),[h,h]},dispose:function(){this.groupGL.removeAll()},remove:function(){this.groupGL.removeAll()}});function jh(e){e.registerChartView(Xh),e.registerSeriesModel(Vh),e.registerLayout(function(t,r){t.eachSeriesByType("surface",function(i){var n=i.coordinateSystem;!n||n.type;var a=i.getData(),s=new Float32Array(3*a.count()),o=[NaN,NaN,NaN];if(n&&n.type==="cartesian3D"){var l=n.dimensions,c=l.map(function(h){return i.coordDimToDataDim(h)[0]});a.each(c,function(h,u,d,f){var v;a.hasValue(f)?v=n.dataToPoint([h,u,d]):v=o,s[f*3]=v[0],s[f*3+1]=v[1],s[f*3+2]=v[2]})}a.setLayout("points",s)})})}var Yh=Object.defineProperty,qh=Object.getOwnPropertyDescriptor,cs=(e,t,r,i)=>{for(var n=i>1?void 0:i?qh(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(n=(i?s(t,r,n):s(n))||n);return i&&n&&Yh(t,r,n),n};to([ro,io,Fh,jh]);let ni=class extends us(fs,ds,vs){constructor(){super(...arguments),this.mdiGrid=ms,this.mdiHome=ps,this.mdiInformation=_s,this.mdiStackOverflow=gs,this.mdiLockOutline=ys,this.mdiCloseThick=xs,this.mdiPencil=Ts,this.mdiDelete=Es,this.mdiProgressUpload=As,this.renameDialog=!1,this.removeDialogProfile="",this.removeDialog=!1,this.saveConfigDialog=!1,this.calibrateDialog={boolShow:!1,name:"default",isInvalidName:!1},this.newName="",this.oldName="",this.isInvalidName=!0,this.createInputRules=[e=>!!e||this.$t("Heightmap.InvalidNameEmpty"),e=>e===e.replace(/[^\x00-\x7F]/g,"")||this.$t("Heightmap.InvalidNameAscii")],this.renameInputRules=[e=>!!e||this.$t("Heightmap.InvalidNameEmpty"),e=>e!=="default"||this.$t("Heightmap.InvalidNameReserved"),e=>!this.existsProfileName(e)||this.$t("Heightmap.InvalidNameAlreadyExists"),e=>e===e.replace(/[^\x00-\x7F]/g,"")||this.$t("Heightmap.InvalidNameAscii")],this.probedOpacity=1,this.meshOpacity=1,this.flatOpacity=.5,this.fontSizeVisualMap=14}get chartOptions(){return{tooltip:{backgroundColor:this.bgColor(.9),borderWidth:0,textStyle:{color:this.fgColor(1),fontSize:"14px"},padding:15,formatter:this.tooltipFormatter},darkMode:this.$vuetify.theme.dark,animation:!1,legend:{show:!1,selected:this.selected},visualMap:{show:!0,min:this.visualMapRange[0],max:this.visualMapRange[1],calculable:!0,dimension:2,inRange:{color:this.colorMap},seriesIndex:this.visualMapSeriesIndex,left:this.isMobile?10:30,top:20,bottom:0,itemWidth:this.isMobile?10:30,itemHeight:550,precision:3,textStyle:{color:this.fgColorHi,fontSize:this.fontSizeVisualMap}},xAxis3D:{type:"value",nameTextStyle:{color:this.fgColorMid},min:this.rangeX[0],max:this.rangeX[1],minInterval:1},yAxis3D:{type:"value",nameTextStyle:{color:this.fgColorMid},min:this.rangeY[0],max:this.rangeY[1]},zAxis3D:{type:"value",min:this.scaleZMax*-1,max:this.scaleZMax,nameTextStyle:{color:this.fgColorMid},axisPointer:{label:{formatter:function(e){return e=parseFloat(e),e.toFixed(2)}}}},grid3D:{axisLabel:{textStyle:{color:this.fgColorMid}},axisLine:{lineStyle:{color:this.fgColorLow}},axisTick:{lineStyle:{color:this.fgColorLow}},splitLine:{lineStyle:{color:this.fgColorLow}},axisPointer:{lineStyle:{color:this.fgColorHi},label:{textStyle:{color:this.fgColorHi}}},boxWidth:100*this.scaleX,boxDepth:100*this.scaleY,viewControl:{distance:150}},series:this.series}}get chart(){var e,t;return(t=(e=this.$refs.heightmap)==null?void 0:e.chart)!=null?t:null}get profiles(){return this.$store.getters["printer/getBedMeshProfiles"]}get bed_mesh(){var e;return(e=this.$store.state.printer.bed_mesh)!=null?e:null}get currentProfileName(){var e,t;return(t=(e=this.bed_mesh)==null?void 0:e.profile_name)!=null?t:""}get currentProfile(){return this.profiles.find(e=>e.name===this.currentProfileName)}bed_meshChanged(){var e;(e=this.chart)==null||e.setOption(this.chartOptions)}get showProbed(){var e;return(e=this.$store.state.gui.view.heightmap.probed)!=null?e:!0}set showProbed(e){this.$store.dispatch("gui/saveSetting",{name:"view.heightmap.probed",value:e})}get showMesh(){var e;return(e=this.$store.state.gui.view.heightmap.mesh)!=null?e:!0}set showMesh(e){this.$store.dispatch("gui/saveSetting",{name:"view.heightmap.mesh",value:e})}get showFlat(){var e;return(e=this.$store.state.gui.view.heightmap.flat)!=null?e:!0}set showFlat(e){this.$store.dispatch("gui/saveSetting",{name:"view.heightmap.flat",value:e})}get wireframe(){var e;return(e=this.$store.state.gui.view.heightmap.wireframe)!=null?e:!0}set wireframe(e){this.$store.dispatch("gui/saveSetting",{name:"view.heightmap.wireframe",value:e})}get scaleGradient(){var e;return(e=this.$store.state.gui.view.heightmap.scaleGradient)!=null?e:!1}set scaleGradient(e){this.$store.dispatch("gui/saveSetting",{name:"view.heightmap.scaleGradient",value:e})}get absRangeX(){return this.rangeX[1]-this.rangeX[0]}get absRangeY(){return this.rangeY[1]-this.rangeY[0]}get minRangeXY(){return Math.min(this.absRangeX,this.absRangeY)}get scaleX(){return this.minRangeXY===0?1:this.absRangeX/this.minRangeXY}get scaleY(){return this.minRangeXY===0?1:this.absRangeY/this.minRangeXY}get scaleZMax(){var e;return(e=this.$store.state.gui.view.heightmap.scaleZMax)!=null?e:.5}set scaleZMax(e){this.$store.dispatch("gui/saveSetting",{name:"view.heightmap.scaleZMax",value:e})}get rangeX(){var r,i,n,a;const e=(r=this.$store.state.printer.toolhead)==null?void 0:r.axis_minimum,t=(i=this.$store.state.printer.toolhead)==null?void 0:i.axis_maximum;return[(n=e[0])!=null?n:0,(a=t[0])!=null?a:0]}get rangeY(){var r,i,n,a,s,o;const e=(i=(r=this.$store.state.printer.toolhead)==null?void 0:r.axis_minimum)!=null?i:[0,0],t=(a=(n=this.$store.state.printer.toolhead)==null?void 0:n.axis_maximum)!=null?a:[0,0];return[(s=e[1])!=null?s:0,(o=t[1])!=null?o:0]}get heightmapLimit(){let e=0,t=0;if(this.bed_mesh){const r=[];if(this.showProbed)for(const i of this.bed_mesh.probed_matrix)for(const n of i)r.push(n);if(this.showMesh)for(const i of this.bed_mesh.mesh_matrix)for(const n of i)r.push(n);e=Math.min(e,...r),t=Math.max(t,...r)}return[e,t]}get probedHeightmapLimit(){let e=0,t=0;return this.currentProfile&&(e=this.currentProfile.min,t=this.currentProfile.max),[e,t]}get heightmapRangeLimit(){const[e,t]=this.heightmapLimit,r=Math.round(Math.max(Math.abs(e),Math.abs(t))*10)/10,i=Math.max(r,1);return[r,i]}get selected(){return{probed:this.showProbed,mesh:this.showMesh,flat:this.showFlat}}get series(){const e=[];return this.bed_mesh&&(e.push(this.seriesProbed),e.push(this.seriesMesh),e.push(this.seriesFlat)),e}get seriesProbed(){const e={type:"surface",name:"probed",data:[],itemStyle:{opacity:this.probedOpacity},wireframe:{show:this.wireframe}};if(this.bed_mesh){const t=this.bed_mesh.probed_matrix[0].length,r=this.bed_mesh.probed_matrix.length,i=this.bed_mesh.mesh_min[0],n=this.bed_mesh.mesh_max[0],a=this.bed_mesh.mesh_min[1],s=this.bed_mesh.mesh_max[1],o=(n-i)/(t-1),l=(s-a)/(r-1),c=[];let h=0;this.bed_mesh.probed_matrix.forEach(u=>{let d=0;u.forEach(f=>{c.push([i+o*d,a+l*h,f]),d++}),h++}),e.data=c,e.dataShape=[r,t]}return e}get seriesMesh(){const e={type:"surface",name:"mesh",data:[],itemStyle:{opacity:this.meshOpacity},wireframe:{show:this.wireframe}};if(this.bed_mesh){const t=this.bed_mesh.mesh_matrix[0].length,r=this.bed_mesh.mesh_matrix.length,i=this.bed_mesh.mesh_min[0],n=this.bed_mesh.mesh_max[0],a=this.bed_mesh.mesh_min[1],s=this.bed_mesh.mesh_max[1],o=(n-i)/(t-1),l=(s-a)/(r-1),c=[];let h=0;this.bed_mesh.mesh_matrix.forEach(u=>{let d=0;u.forEach(f=>{c.push([i+o*d,a+l*h,f]),d++}),h++}),e.data=c,e.dataShape=[r,t]}return e}get seriesFlat(){var r,i;const e={type:"surface",name:"flat",data:[],itemStyle:{color:[1,1,1,1],opacity:this.flatOpacity},wireframe:{show:this.wireframe}},t=(i=(r=this.$store.state.printer.configfile)==null?void 0:r.settings)==null?void 0:i.bed_mesh;if(t){let n=[1,1];t.probe_count&&typeof t.probe_count=="string"?n=t.probe_count.split(","):t.probe_count?n=t.probe_count.length<2?[t.probe_count,t.probe_count]:t.probe_count:t.round_probe_count&&(n=[t.round_probe_count,t.round_probe_count]);let a=[],s=[];t.mesh_min&&t.mesh_max?(a=typeof t.mesh_min=="string"?t.mesh_min.split(","):t.mesh_min,s=typeof t.mesh_max=="string"?t.mesh_max.split(","):t.mesh_max):(a=[t.mesh_radius*-1,t.mesh_radius*-1],s=[t.mesh_radius,t.mesh_radius]);const o=n[0],l=n[1],c=parseFloat(a[0]),h=parseFloat(s[0]),u=parseFloat(a[1]),d=parseFloat(s[1]),f=(h-c)/(o-1),v=(d-u)/(l-1),m=[];for(let p=0;p<l;p++)for(let _=0;_<o;_++)m.push([c+f*_,u+v*p,0]);e.data=m,e.dataShape=[l,o]}return e}get visualMapRange(){return this.scaleGradient?this.heightmapLimit:[-.1,.1]}get visualMapSeriesIndex(){const e=[];return this.showProbed?e.push(0):this.showMesh&&e.push(1),e}get probed_matrix(){var e;return(e=this.bed_mesh.probed_matrix)!=null?e:[[]]}get bedMeshXLength(){let e=this.probed_matrix[0].length-1;return e<1&&(e=1),e}get bedMeshYLength(){let e=this.probed_matrix.length-1;return e<1&&(e=1),e}get bedMeshMaxPoint(){if(this.bed_mesh.profile_name==="")return{row:0,col:0,positionX:0,positionY:0,value:0};const[,e]=this.probedHeightmapLimit;let t=0,r=0;this.bed_mesh.probed_matrix.forEach((a,s)=>{Math.max(...a)===e&&(t=s+1,r=a.findIndex(o=>o===e)+1)});const i=Math.round((this.bed_mesh.mesh_min[0]+(this.bed_mesh.mesh_max[0]-this.bed_mesh.mesh_min[0])/this.bedMeshXLength*(r-1))*10)/10,n=Math.round((this.bed_mesh.mesh_min[1]+(this.bed_mesh.mesh_max[1]-this.bed_mesh.mesh_min[1])/this.bedMeshYLength*(t-1))*10)/10;return{row:t,col:r,positionX:i,positionY:n,value:e}}get bedMeshMinPoint(){if(this.bed_mesh.profile_name==="")return{row:0,col:0,positionX:0,positionY:0,value:0};const[e]=this.probedHeightmapLimit;let t=0,r=0;this.bed_mesh.probed_matrix.forEach((a,s)=>{Math.min(...a)===e&&(t=s+1,r=a.findIndex(o=>o===e)+1)});const i=Math.round((this.bed_mesh.mesh_min[0]+(this.bed_mesh.mesh_max[0]-this.bed_mesh.mesh_min[0])/this.bedMeshXLength*(r-1))*10)/10,n=Math.round((this.bed_mesh.mesh_min[1]+(this.bed_mesh.mesh_max[1]-this.bed_mesh.mesh_min[1])/this.bedMeshYLength*(t-1))*10)/10;return{row:t,col:r,positionX:i,positionY:n,value:e}}get meshLoaded(){return this.bed_mesh!==null?this.bed_mesh.profile_name!=="":!1}get colorMap(){return this.$store.getters["gui/heightmap/getActiveColorSchemeList"]}tooltipFormatter(e){const t=[];return t.push("<b>"+e.seriesName+"</b>"),Object.keys(e.encode).sort().forEach(r=>{t.push("<b>"+r.toUpperCase()+"</b>: "+e.data[e.encode[r][0]].toFixed(r==="z"?3:1)+" mm")}),t.join("<br />")}loadProfile(e){const t='BED_MESH_PROFILE LOAD="'+e+'"';this.$store.dispatch("server/addEvent",{message:t,type:"command"}),this.$socket.emit("printer.gcode.script",{script:t},{loading:"bedMeshLoad_"+e})}openRenameProfile(){var e,t;this.newName=(t=(e=this.bed_mesh)==null?void 0:e.profile_name)!=null?t:"",this.oldName=this.bed_mesh.profile_name,this.renameDialog=!0,this.isInvalidName=!1,setTimeout(()=>{var r;(r=this.$refs.inputDialogRenameHeightmapName)==null||r.focus()},200)}existsProfileName(e){return this.profiles.findIndex(t=>t.name===e)>=0}renameProfile(){this.renameDialog=!1;const e='BED_MESH_PROFILE SAVE="'+this.newName+'"',t='BED_MESH_PROFILE REMOVE="'+this.oldName+'"';this.$store.dispatch("server/addEvent",{message:e,type:"command"}),this.$store.dispatch("server/addEvent",{message:t,type:"command"}),this.$socket.emit("printer.gcode.script",{script:e},{loading:"bedMeshRename"}),this.$socket.emit("printer.gcode.script",{script:t},{loading:"bedMeshRename"}),this.newName="",this.oldName=""}openRemoveProfile(e){this.removeDialogProfile=e,this.removeDialog=!0}removeProfile(){this.removeDialog=!1;const e='BED_MESH_PROFILE REMOVE="'+this.removeDialogProfile+'"';this.$store.dispatch("server/addEvent",{message:e,type:"command"}),this.$socket.emit("printer.gcode.script",{script:e},{action:"printer/removeBedMeshProfile",actionPayload:{name:this.removeDialogProfile},loading:"bedMeshRename_"+this.removeDialogProfile}),this.removeDialogProfile="",this.saveConfigDialog=!0}homePrinter(){const e="G28";this.$store.dispatch("server/addEvent",{message:e,type:"command"}),this.$socket.emit("printer.gcode.script",{script:e},{loading:"homeAll"})}clearBedMesh(){const e="BED_MESH_CLEAR";this.$store.dispatch("server/addEvent",{message:e,type:"command"}),this.$socket.emit("printer.gcode.script",{script:e},{loading:"bedMeshClear"})}openCalibrateMesh(){this.calibrateDialog.name="default",this.calibrateDialog.boolShow=!0,setTimeout(()=>{var e;(e=this.$refs.inputFieldCalibrateBedMeshName)==null||e.focus()},200)}calibrateMesh(){this.calibrateDialog.boolShow=!1;const e='BED_MESH_CALIBRATE PROFILE="'+this.calibrateDialog.name+'"';this.$store.dispatch("server/addEvent",{message:e,type:"command"}),this.$socket.emit("printer.gcode.script",{script:e},{loading:"bedMeshCalibrate"})}saveConfig(){const e="SAVE_CONFIG";this.$store.dispatch("server/addEvent",{message:e,type:"command"}),this.$socket.emit("printer.gcode.script",{script:e},{loading:"topbarSaveConfig"}),this.saveConfigDialog=!1}beforeDestroy(){typeof window>"u"||this.chart&&this.chart.dispose()}};cs([Ss("bed_mesh",{deep:!0})],ni.prototype,"bed_meshChanged",1);ni=cs([bs({components:{Panel:St}})],ni);var Zh=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("div",[e.klipperReadyForGui?r(it,[r(Me,{staticClass:"col-12 col-md-8 pb-0"},[r(St,{attrs:{"card-class":"heightmap-map-panel",title:e.$t("Heightmap.Heightmap"),icon:e.mdiGrid},scopedSlots:e._u([{key:"buttons",fn:function(){return[r(Te,{staticClass:"d-none d-sm-flex",attrs:{icon:"",tile:"",disabled:e.printerIsPrinting,color:e.homedAxes.includes("xyz")?"primary":"warning",loading:e.loadings.includes("homeAll"),title:e.$t("Heightmap.TitleHomeAll"),ripple:!0},on:{click:e.homePrinter}},[r(ht,[e._v(e._s(e.mdiHome))])],1),e.meshLoaded?r(Te,{staticClass:"d-none d-sm-flex",attrs:{text:"",tile:"",loading:e.loadings.includes("bedMeshClear"),title:e.$t("Heightmap.TitleClear")},on:{click:e.clearBedMesh}},[e._v(" "+e._s(e.$t("Heightmap.Clear"))+" ")]):e._e(),r(Te,{staticClass:"d-none d-sm-flex",attrs:{text:"",tile:"",loading:e.loadings.includes("bedMeshCalibrate"),disabled:e.printerIsPrinting,title:e.$t("Heightmap.TitleCalibrate")},on:{click:e.openCalibrateMesh}},[e._v(" "+e._s(e.$t("Heightmap.Calibrate"))+" ")])]},proxy:!0}],null,!1,2015509893)},[r(nt,{staticClass:"d-sm-none text-center pb-0"},[r(no,{staticClass:"v-btn-toggle",attrs:{tile:"",name:"controllers"}},[r(Te,{staticClass:"px-2 minwidth-0",attrs:{text:"",small:"",disabled:e.printerIsPrinting,color:e.homedAxes.includes("xyz")?"primary":"warning",loading:e.loadings.includes("homeAll"),title:e.$t("Heightmap.TitleHomeAll")},on:{click:e.homePrinter}},[r(ht,{attrs:{color:e.homedAxes.includes("xyz")?"primary":"warning",small:""}},[e._v(" "+e._s(e.mdiHome)+" ")])],1),e.bed_mesh?r(Te,{staticClass:"px-2 minwidth-0",attrs:{text:"",small:"",color:"primary",loading:e.loadings.includes("bedMeshClear"),title:e.$t("Heightmap.TitleClear")},on:{click:e.clearBedMesh}},[e._v(" "+e._s(e.$t("Heightmap.Clear"))+" ")]):e._e(),r(Te,{staticClass:"px-2 minwidth-0",attrs:{text:"",small:"",color:"primary",loading:e.loadings.includes("bedMeshCalibrate"),disabled:e.printerIsPrinting,title:e.$t("Heightmap.TitleCalibrate")},on:{click:e.openCalibrateMesh}},[e._v(" "+e._s(e.$t("Heightmap.Calibrate"))+" ")])],1)],1),e.meshLoaded?[r(nt,{staticClass:"py-0 px-0"},[r(it,[r(Me,{},[r("e-chart",{ref:"heightmap",staticStyle:{height:"600px",width:"100%",overflow:"hidden"},attrs:{option:e.chartOptions,"init-options":{renderer:"canvas"}}})],1)],1),r(it,[r(Me,{staticClass:"col-12 col-sm-auto pt-0 pb-0 pl-lg-6 d-flex justify-center justify-sm-start"},[r(ao,{staticClass:"mt-0 ml-5",attrs:{label:e.$t("Heightmap.ScaleGradient")},model:{value:e.scaleGradient,callback:function(i){e.scaleGradient=i},expression:"scaleGradient"}})],1),r(Me,{staticClass:"d-flex justify-center pt-0 pb-6 pb-lg-3"},[r(Rr,{staticClass:"mx-3 mt-0",attrs:{label:e.$t("Heightmap.Probed"),"hide-details":""},model:{value:e.showProbed,callback:function(i){e.showProbed=i},expression:"showProbed"}}),r(Rr,{staticClass:"mx-3 mt-0",attrs:{label:e.$t("Heightmap.Mesh"),"hide-details":""},model:{value:e.showMesh,callback:function(i){e.showMesh=i},expression:"showMesh"}}),r(Rr,{staticClass:"mx-3 mt-0",attrs:{label:e.$t("Heightmap.Flat"),"hide-details":""},model:{value:e.showFlat,callback:function(i){e.showFlat=i},expression:"showFlat"}}),r(Rr,{staticClass:"mx-3 mt-0",attrs:{label:e.$t("Heightmap.Wireframe"),"hide-details":""},model:{value:e.wireframe,callback:function(i){e.wireframe=i},expression:"wireframe"}})],1)],1)],1),r(kt),r(nt,{staticClass:"pt-0 pb-3"},[r(it,[r(Me,[r(so,{staticClass:"mt-4",attrs:{label:e.$t("Heightmap.ScaleZMax"),min:e.heightmapRangeLimit[0],max:e.heightmapRangeLimit[1],step:.1,ticks:"always","hide-details":""},model:{value:e.scaleZMax,callback:function(i){e.scaleZMax=i},expression:"scaleZMax"}})],1)],1)],1)]:[r(nt,{staticClass:"text-center py-3 font-italic"},[e._v(" "+e._s(e.$t("Heightmap.NoBedMeshHasBeenLoadedYet"))+" ")])]],2)],1),r(Me,{staticClass:"col-12 col-md-4"},[e.currentProfile?r(St,{staticClass:"mt-0",attrs:{title:e.$t("Heightmap.CurrentMesh.Headline"),"card-class":"heightmap-current-mesh-panel",icon:e.mdiInformation,collapsible:!0}},[r(nt,{staticClass:"py-3 px-0"},[r(it,{staticClass:"px-3"},[r(Me,[e._v(e._s(e.$t("Heightmap.CurrentMesh.Name")))]),r(Me,{staticClass:"text-right"},[r("span",{staticClass:"currentMeshName font-weight-bold",on:{click:function(i){return e.openRenameProfile()}}},[r(ht,{attrs:{left:"",small:"",color:"primary"}},[e._v(e._s(e.mdiPencil))]),e._v(" "+e._s(e.currentProfileName)+" ")],1)])],1),r(kt,{staticClass:"my-3"}),"data"in e.currentProfile?r(it,{staticClass:"px-3"},[r(Me,[e._v(e._s(e.$t("Heightmap.CurrentMesh.Size")))]),r(Me,{staticClass:"text-right"},[e._v(" "+e._s(e.currentProfile.data.x_count)+"x"+e._s(e.currentProfile.data.y_count)+" ")])],1):e._e(),r(kt,{staticClass:"my-3"}),r(it,{staticClass:"px-3"},[r(Me,[e._v(" "+e._s(e.$t("Heightmap.CurrentMesh.Max"))+" ["+e._s(e.bedMeshMaxPoint.positionX)+", "+e._s(e.bedMeshMaxPoint.positionY)+"] ")]),r(Me,{staticClass:"text-right"},[e._v(e._s(e.currentProfile.max.toFixed(3))+" mm")])],1),r(kt,{staticClass:"my-3"}),r(it,{staticClass:"px-3"},[r(Me,[e._v(" "+e._s(e.$t("Heightmap.CurrentMesh.Min"))+" ["+e._s(e.bedMeshMinPoint.positionX)+", "+e._s(e.bedMeshMinPoint.positionY)+"] ")]),r(Me,{staticClass:"text-right"},[e._v(e._s(e.currentProfile.min.toFixed(3))+" mm")])],1),r(kt,{staticClass:"my-3"}),r(it,{staticClass:"px-3"},[r(Me,[e._v(e._s(e.$t("Heightmap.CurrentMesh.Range")))]),r(Me,{staticClass:"text-right"},[e._v(e._s(e.currentProfile.variance.toFixed(3))+" mm")])],1)],1)],1):e._e(),r(St,{staticClass:"mt-6 mt-md-0",attrs:{title:e.$t("Heightmap.Profiles"),"card-class":"heightmap-profiles-panel",icon:e.mdiStackOverflow,collapsible:!0}},[e.profiles.length?r(nt,{staticClass:"px-0 py-3"},[e._l(e.profiles,function(i,n){return[n?r(kt,{key:"deliver_"+n,staticClass:"my-3"}):e._e(),r(it,{key:n,staticClass:"rowProfile"},[r(Me,{staticClass:"pl-6 py-0 colName"},[r("span",{class:i.is_active?"current":"",staticStyle:{cursor:"pointer"},on:{click:function(a){i.is_active?e.openRenameProfile():e.loadProfile(i.name)}}},[e._v(" "+e._s(i.name)+" ")])]),r(Me,{staticClass:"text-center py-0 colVariance"},[r(oo,{attrs:{top:"",color:"rgba(0,0,0,0.8)"},scopedSlots:e._u([{key:"activator",fn:function(a){var s=a.on,o=a.attrs;return[r("small",e._g(e._b({},"small",o,!1),s),[e._v(" "+e._s(i.variance.toFixed(3))+" ")])]}}],null,!0)},[r("span",[e._v(" max: "+e._s(i.max)+" "),r("br"),e._v(" min: "+e._s(i.min)+" ")])])],1),r(Me,{staticClass:"py-0 colActions"},[i.is_active?r(Te,{staticClass:"px-2 minwidth-0",attrs:{text:"",tile:"",loading:e.loadings.includes("bedMeshLoad_"+i.name)},on:{click:e.openRenameProfile}},[r(ht,[e._v(e._s(e.mdiPencil))])],1):r(Te,{staticClass:"px-2 minwidth-0",attrs:{text:"",tile:"",loading:e.loadings.includes("bedMeshLoad_"+i.name)},on:{click:function(a){return e.loadProfile(i.name)}}},[r(ht,[e._v(e._s(e.mdiProgressUpload))])],1),r(Te,{staticClass:"px-2 minwidth-0",attrs:{text:"",tile:"",loading:e.loadings.includes("bedMeshRemove_"+i.name),title:e.$t("Heightmap.DeleteBedMeshProfile")},on:{click:function(a){return e.openRemoveProfile(i.name)}}},[r(ht,[e._v(e._s(e.mdiDelete))])],1)],1)],1)]})],2):r(nt,[r("p",{staticClass:"mb-0"},[e._v(e._s(e.$t("Heightmap.NoProfile")))])])],1)],1)],1):r(it,[r(lo,{staticClass:"mx-auto mt-6",attrs:{dense:"",text:"",type:"warning",elevation:"2","max-width":"500",icon:e.mdiLockOutline}},[e._v(" "+e._s(e.$t("Heightmap.ErrorKlipperNotReady"))+" ")])],1),r(Mr,{attrs:{persistent:"","max-width":400},on:{keydown:function(i){if(!i.type.indexOf("key")&&e._k(i.keyCode,"esc",27,i.key,["Esc","Escape"]))return null;e.renameDialog=!1}},model:{value:e.renameDialog,callback:function(i){e.renameDialog=i},expression:"renameDialog"}},[r(St,{attrs:{title:e.$t("Heightmap.RenameBedMeshProfile"),icon:e.mdiGrid,"card-class":"heightmap-rename-dialog","margin-bottom":!1},scopedSlots:e._u([{key:"buttons",fn:function(){return[r(Te,{attrs:{icon:"",tile:""},on:{click:function(i){e.renameDialog=!1}}},[r(ht,[e._v(e._s(e.mdiCloseThick))])],1)]},proxy:!0}])},[r(nt,[r(mn,{ref:"inputDialogRenameHeightmapName",attrs:{label:e.$t("Heightmap.Name"),required:"",rules:e.renameInputRules},on:{"update:error":function(i){e.isInvalidName=i},keyup:function(i){return!i.type.indexOf("key")&&e._k(i.keyCode,"enter",13,i.key,"Enter")?null:e.renameProfile.apply(null,arguments)}},model:{value:e.newName,callback:function(i){e.newName=i},expression:"newName"}})],1),r(Nr,[r(Lr),r(Te,{attrs:{text:""},on:{click:function(i){e.renameDialog=!1}}},[e._v(e._s(e.$t("Heightmap.Abort")))]),r(Te,{attrs:{disabled:e.isInvalidName,color:"primary",text:""},on:{click:e.renameProfile}},[e._v(" "+e._s(e.$t("Heightmap.Rename"))+" ")])],1)],1)],1),r(Mr,{attrs:{persistent:"","max-width":400},on:{keydown:function(i){if(!i.type.indexOf("key")&&e._k(i.keyCode,"esc",27,i.key,["Esc","Escape"]))return null;e.calibrateDialog.boolShow=!1}},model:{value:e.calibrateDialog.boolShow,callback:function(i){e.$set(e.calibrateDialog,"boolShow",i)},expression:"calibrateDialog.boolShow"}},[r(St,{attrs:{title:e.$t("Heightmap.BedMeshCalibrate"),icon:e.mdiGrid,"card-class":"heightmap-calibrate-dialog","margin-bottom":!1},scopedSlots:e._u([{key:"buttons",fn:function(){return[r(Te,{attrs:{icon:"",tile:""},on:{click:function(i){e.calibrateDialog.boolShow=!1}}},[r(ht,[e._v(e._s(e.mdiCloseThick))])],1)]},proxy:!0}])},[r(nt,[r(mn,{ref:"inputFieldCalibrateBedMeshName",attrs:{label:e.$t("Heightmap.Name"),rules:e.createInputRules,required:""},on:{"update:error":function(i){e.calibrateDialog.isInvalidName=i},keyup:function(i){return!i.type.indexOf("key")&&e._k(i.keyCode,"enter",13,i.key,"Enter")?null:e.calibrateMesh.apply(null,arguments)}},model:{value:e.calibrateDialog.name,callback:function(i){e.$set(e.calibrateDialog,"name",i)},expression:"calibrateDialog.name"}})],1),r(Nr,[r(Lr),r(Te,{attrs:{text:""},on:{click:function(i){e.calibrateDialog.boolShow=!1}}},[e._v(e._s(e.$t("Heightmap.Abort")))]),r(Te,{attrs:{disabled:e.calibrateDialog.isInvalidName,color:"primary",text:""},on:{click:e.calibrateMesh}},[e._v(" "+e._s(e.$t("Heightmap.Calibrate"))+" ")])],1)],1)],1),r(Mr,{attrs:{persistent:"","max-width":400},on:{keydown:function(i){if(!i.type.indexOf("key")&&e._k(i.keyCode,"esc",27,i.key,["Esc","Escape"]))return null;e.removeDialog=!1}},model:{value:e.removeDialog,callback:function(i){e.removeDialog=i},expression:"removeDialog"}},[r(St,{attrs:{title:e.$t("Heightmap.BedMeshRemove"),icon:e.mdiGrid,"card-class":"heightmap-remove-dialog","margin-bottom":!1},scopedSlots:e._u([{key:"buttons",fn:function(){return[r(Te,{attrs:{icon:"",tile:""},on:{click:function(i){e.removeDialog=!1}}},[r(ht,[e._v(e._s(e.mdiCloseThick))])],1)]},proxy:!0}])},[r(nt,[r("p",{staticClass:"mb-0"},[e._v(e._s(e.$t("Heightmap.DoYouReallyWantToDelete",{name:e.removeDialogProfile})))])]),r(Nr,[r(Lr),r(Te,{attrs:{text:""},on:{click:function(i){e.removeDialog=!1}}},[e._v(e._s(e.$t("Heightmap.Abort")))]),r(Te,{attrs:{color:"error",text:""},on:{click:e.removeProfile}},[e._v(e._s(e.$t("Heightmap.Remove")))])],1)],1)],1),r(Mr,{attrs:{persistent:"","max-width":400},on:{keydown:function(i){if(!i.type.indexOf("key")&&e._k(i.keyCode,"esc",27,i.key,["Esc","Escape"]))return null;e.saveConfigDialog=!1}},model:{value:e.saveConfigDialog,callback:function(i){e.saveConfigDialog=i},expression:"saveConfigDialog"}},[r(St,{attrs:{title:e.$t("Heightmap.SAVE_CONFIG"),icon:e.mdiGrid,"card-class":"heightmap-remove-save-dialog","margin-bottom":!1},scopedSlots:e._u([{key:"buttons",fn:function(){return[r(Te,{attrs:{icon:"",tile:""},on:{click:function(i){e.saveConfigDialog=!1}}},[r(ht,[e._v(e._s(e.mdiCloseThick))])],1)]},proxy:!0}])},[r(nt,[r("p",{staticClass:"mb-0"},[e._v(e._s(e.$t("Heightmap.RemoveSaveDescription")))])]),r(Nr,[r(Lr),e.printerIsPrinting?[r(Te,{attrs:{text:""},on:{click:function(i){e.saveConfigDialog=!1}}},[e._v(e._s(e.$t("Heightmap.Ok")))])]:[r(Te,{attrs:{color:"primary",text:""},on:{click:e.saveConfig}},[e._v(" "+e._s(e.$t("Heightmap.SAVE_CONFIG"))+" ")]),r(Te,{attrs:{text:""},on:{click:function(i){e.saveConfigDialog=!1}}},[e._v(e._s(e.$t("Heightmap.Later")))])]],2)],1)],1)],1)},$h=[];const ha={};var Kh=ws(ni,Zh,$h,!1,Qh,"37c48ba8",null,null);function Qh(e){for(let t in ha)this[t]=ha[t]}const iu=function(){return Kh.exports}();export{iu as default};