mainsail/assets/Heightmap-a5103d86.js

2 lines
444 KiB
JavaScript

import{m as Et,B as At,a as Xs,C as vt,_ as Wt,b as hi,c as vn,W as za,P as Ke,n as St,d as $s,e as Ga,f as js,g as qs,h as Ys,i as Zs,j as Ks,T as Qs}from"./index-17a5ec1d.js";import{h as fi,f as Pe,c as gt,i as ft,n as Va,o as di,d as vi,l as ht,m as we,r as Js,x as nr,V as eo,B as to,M as ro,p as Ur,A as no,F as io}from"./vuetify-4c65b4c3.js";import{j as Ar,m as Ii,A as ao,L as so,p as ka,R as Wa,k as oo,r as lo,l as Sr,n as co,o as uo,q as ho,s as fo,Z as vo,C as Xa,v as xt,w as Ir,x as _o,y as mo,M as po,z as $n,B as jn,D as go,E as $a,F as ja,G as qa,H as Ya,I as xo,J as yo,K as To,O as Eo,N as Ao,P as So,Q as Hr,S as Bi,T as wo,U as bo,V as Co,W as Ro,X as Mo,Y as Lo,_ as No,$ as Po,a0 as zr,a1 as Do,u as Oo,a2 as Io,a3 as Bo}from"./echarts-ff51454d.js";import"./overlayscrollbars-44d87bcf.js";var Fo=Object.defineProperty,Uo=Object.getOwnPropertyDescriptor,Ho=(e,t,r,n)=>{for(var i=n>1?void 0:n?Uo(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&Fo(t,r,i),i};let qn=class extends Et(At){constructor(){super(...arguments),this.mdiLockOutline=Xs}};qn=Ho([vt({components:{Panel:Wt}})],qn);var zo=Object.defineProperty,Go=Object.getOwnPropertyDescriptor,_n=(e,t,r,n)=>{for(var i=n>1?void 0:n?Go(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&zo(t,r,i),i};let sr=class extends Et(At){constructor(){super(...arguments),this.mdiCloseThick=hi,this.mdiGrid=vn,this.isInvalidName=!1,this.newName="",this.rules=[t=>!!t||this.$t("Heightmap.InvalidNameEmpty"),t=>t!=="default"||this.$t("Heightmap.InvalidNameReserved"),t=>!this.profileNames.includes(t)||this.$t("Heightmap.InvalidNameAlreadyExists"),t=>t===t.replace(/[^\x00-\x7F]/g,"")||this.$t("Heightmap.InvalidNameAscii")]}get profileNames(){var t,r;return Object.keys((r=(t=this.$store.state.printer.bed_mesh)==null?void 0:t.profiles)!=null?r:{})}renameProfile(){const t='BED_MESH_PROFILE SAVE="'.concat(this.newName,'"\nBED_MESH_PROFILE REMOVE="').concat(this.name,'"');this.$store.dispatch("server/addEvent",{message:t,type:"command"}),this.$socket.emit("printer.gcode.script",{script:t},{loading:"bedMeshRename"}),this.closeDialog()}closeDialog(){this.$emit("close")}showChanged(){this.show&&(this.newName=this.name,this.$nextTick(()=>{setTimeout(()=>{var t;(t=this.$refs.input)==null||t.focus()},100)}))}};_n([Ke({type:Boolean,required:!0})],sr.prototype,"show",2);_n([Ke({type:String,required:!0})],sr.prototype,"name",2);_n([za("show")],sr.prototype,"showChanged",1);sr=_n([vt],sr);var Vo=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r(fi,{attrs:{value:e.show,persistent:"","max-width":400},on:{keydown:function(n){return!n.type.indexOf("key")&&e._k(n.keyCode,"esc",27,n.key,["Esc","Escape"])?null:e.closeDialog.apply(null,arguments)}}},[r(Wt,{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(Pe,{attrs:{icon:"",tile:""},on:{click:e.closeDialog}},[r(gt,[e._v(e._s(e.mdiCloseThick))])],1)]},proxy:!0}])},[r(ft,[r(Va,{ref:"input",attrs:{label:e.$t("Heightmap.Name"),required:"",rules:e.rules},on:{"update:error":function(n){e.isInvalidName=n},keyup:function(n){return!n.type.indexOf("key")&&e._k(n.keyCode,"enter",13,n.key,"Enter")?null:e.renameProfile.apply(null,arguments)}},model:{value:e.newName,callback:function(n){e.newName=n},expression:"newName"}})],1),r(di,[r(vi),r(Pe,{attrs:{text:""},on:{click:e.closeDialog}},[e._v(e._s(e.$t("Heightmap.Abort")))]),r(Pe,{attrs:{disabled:e.isInvalidName,color:"primary",text:""},on:{click:e.renameProfile}},[e._v(" "+e._s(e.$t("Heightmap.Rename"))+" ")])],1)],1)],1)},ko=[];const Fi={};var Wo=St(sr,Vo,ko,!1,Xo,null,null,null);function Xo(e){for(let t in Fi)this[t]=Fi[t]}const _i=function(){return Wo.exports}();var $o=Object.defineProperty,jo=Object.getOwnPropertyDescriptor,mi=(e,t,r,n)=>{for(var i=n>1?void 0:n?jo(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&$o(t,r,i),i};let wr=class extends Et(At){constructor(){super(...arguments),this.mdiCloseThick=hi,this.mdiGrid=vn}removeProfile(){const e='BED_MESH_PROFILE REMOVE="'.concat(this.name,'"');this.$store.dispatch("server/addEvent",{message:e,type:"command"}),this.$socket.emit("printer.gcode.script",{script:e},{loading:"bedMeshRemove"}),this.closeDialog()}closeDialog(){this.$emit("close")}};mi([Ke({type:Boolean,required:!0})],wr.prototype,"show",2);mi([Ke({type:String,required:!0})],wr.prototype,"name",2);wr=mi([vt],wr);var qo=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r(fi,{attrs:{value:e.show,persistent:"","max-width":400},on:{keydown:function(n){return!n.type.indexOf("key")&&e._k(n.keyCode,"esc",27,n.key,["Esc","Escape"])?null:e.closeDialog.apply(null,arguments)}}},[r(Wt,{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(Pe,{attrs:{icon:"",tile:""},on:{click:e.closeDialog}},[r(gt,[e._v(e._s(e.mdiCloseThick))])],1)]},proxy:!0}])},[r(ft,[r("p",{staticClass:"mb-0"},[e._v(e._s(e.$t("Heightmap.DoYouReallyWantToDelete",{name:e.name})))])]),r(di,[r(vi),r(Pe,{attrs:{text:""},on:{click:e.closeDialog}},[e._v(e._s(e.$t("Heightmap.Abort")))]),r(Pe,{attrs:{color:"error",text:""},on:{click:e.removeProfile}},[e._v(e._s(e.$t("Heightmap.Remove")))])],1)],1)],1)},Yo=[];const Ui={};var Zo=St(wr,qo,Yo,!1,Ko,null,null,null);function Ko(e){for(let t in Ui)this[t]=Ui[t]}const Za=function(){return Zo.exports}();var Qo=Object.defineProperty,Jo=Object.getOwnPropertyDescriptor,pi=(e,t,r,n)=>{for(var i=n>1?void 0:n?Jo(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&Qo(t,r,i),i};let br=class extends Et(At){constructor(){super(...arguments),this.mdiDelete=$s,this.mdiPencil=Ga,this.mdiProgressUpload=js,this.showRemove=!1,this.showRename=!1}get points(){const e=[];for(let t=0;t<this.profile.points.length;t++)for(let r=0;r<this.profile.points[t].length;r++)e.push(this.profile.points[t][r]);return e}get min(){return Math.round(Math.min(...this.points)*1e3)/1e3}get max(){return Math.round(Math.max(...this.points)*1e3)/1e3}get variance(){return Math.abs(this.min-this.max).toFixed(3)}get is_active(){var t,r;return((r=(t=this.$store.state.printer.bed_mesh)==null?void 0:t.profile_name)!=null?r:"")===this.name}get loadingNameLoad(){return"bedMeshLoad_".concat(this.name)}get loadingNameRemove(){return"bedMeshRemove_".concat(this.name)}get isLoadingLoad(){return this.loadings.includes(this.loadingNameLoad)}get isLoadingRemove(){return this.loadings.includes(this.loadingNameRemove)}clickOnName(){if(this.is_active){this.showRename=!0;return}this.loadProfile()}loadProfile(){const e='BED_MESH_PROFILE LOAD="'.concat(this.name,'"');this.$store.dispatch("server/addEvent",{message:e,type:"command"}),this.$socket.emit("printer.gcode.script",{script:e},{loading:this.loadingNameLoad})}};pi([Ke({type:String,required:!0})],br.prototype,"name",2);pi([Ke({type:Object,required:!0})],br.prototype,"profile",2);br=pi([vt({components:{HeightmapRenameProfileDialog:_i,HeightmapRemoveProfileDialog:Za}})],br);var el=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r(ht,{staticClass:"rowProfile"},[r(we,{staticClass:"pl-6"},[r("span",{class:{"font-weight-bold":e.is_active,currentMeshName:e.is_active,"cursor-pointer":!0},on:{click:e.clickOnName}},[e._v(" "+e._s(e.name)+" ")])]),r(we,{staticClass:"col-auto text-center d-flex align-center justify-center pr-6"},[r(Js,{attrs:{top:"",color:"rgba(0,0,0,0.8)"},scopedSlots:e._u([{key:"activator",fn:function(n){var i=n.on,a=n.attrs;return[r("small",e._g(e._b({},"small",a,!1),i),[e._v(e._s(e.variance))])]}}])},[r("span",[e._v(" max: "+e._s(e.max)+" "),r("br"),e._v(" min: "+e._s(e.min)+" ")])])],1),r(we,{staticClass:"col-auto py-0 d-flex flex-row align-center justify-end"},[e.is_active?r(Pe,{staticClass:"px-2 minwidth-0",staticStyle:{height:"48px",width:"48px"},attrs:{text:"",tile:"",loading:e.isLoadingLoad},on:{click:function(n){e.showRename=!0}}},[r(gt,[e._v(e._s(e.mdiPencil))])],1):r(Pe,{staticClass:"px-2 minwidth-0",staticStyle:{height:"48px",width:"48px"},attrs:{text:"",tile:"",loading:e.isLoadingLoad},on:{click:e.loadProfile}},[r(gt,[e._v(e._s(e.mdiProgressUpload))])],1),r(Pe,{staticClass:"px-2 minwidth-0",staticStyle:{height:"48px",width:"48px"},attrs:{text:"",tile:"",loading:e.isLoadingRemove,title:e.$t("Heightmap.DeleteBedMeshProfile")},on:{click:function(n){e.showRemove=!0}}},[r(gt,[e._v(e._s(e.mdiDelete))])],1)],1),r(Za,{attrs:{show:e.showRemove,name:e.name},on:{close:function(n){e.showRemove=!1}}}),r(_i,{attrs:{show:e.showRename,name:e.name},on:{close:function(n){e.showRename=!1}}})],1)},tl=[];const Hi={};var rl=St(br,el,tl,!1,nl,"2234b010",null,null);function nl(e){for(let t in Hi)this[t]=Hi[t]}const Ka=function(){return rl.exports}();var il=Object.defineProperty,al=Object.getOwnPropertyDescriptor,sl=(e,t,r,n)=>{for(var i=n>1?void 0:n?al(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&il(t,r,i),i};let Yn=class extends Et(At){constructor(){super(...arguments),this.mdiStackOverflow=qs}get profiles(){var e,t;return(t=(e=this.$store.state.printer.bed_mesh)==null?void 0:e.profiles)!=null?t:{}}};Yn=sl([vt({components:{HeightmapProfilesPanelRow:Ka}})],Yn);var ol=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r(Wt,{staticClass:"mt-6 mt-md-0",attrs:{title:e.$t("Heightmap.Profiles"),"card-class":"heightmap-profiles-panel",icon:e.mdiStackOverflow,collapsible:!0}},[Object.keys(e.profiles).length?r(ft,{staticClass:"px-0 py-3"},[e._l(e.profiles,function(n,i,a){return[a?r(nr,{key:"deliver_".concat(i),staticClass:"my-3"}):e._e(),r(Ka,{key:"profile_".concat(i),attrs:{profile:n,name:i}})]})],2):r(ft,[r("p",{staticClass:"mb-0"},[e._v(e._s(e.$t("Heightmap.NoProfile")))])])],1)},ll=[];const zi={};var cl=St(Yn,ol,ll,!1,ul,null,null,null);function ul(e){for(let t in zi)this[t]=zi[t]}const hl=function(){return cl.exports}();var fl=Object.defineProperty,dl=Object.getOwnPropertyDescriptor,vl=(e,t,r,n)=>{for(var i=n>1?void 0:n?dl(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&fl(t,r,i),i};let Cr=class extends eo{get bed_mesh(){var e;return(e=this.$store.state.printer.bed_mesh)!=null?e:{}}get profiles(){var e;return(e=this.bed_mesh.profiles)!=null?e:{}}get mesh_min(){var e;return(e=this.bed_mesh.mesh_min)!=null?e:[0,0]}get mesh_max(){var e;return(e=this.bed_mesh.mesh_max)!=null?e:[0,0]}get min(){return Math.min(...this.points)}get max(){return Math.max(...this.points)}get variance(){return Math.abs(this.min-this.max).toFixed(3)}get is_active(){return this.bed_mesh.profile_name!==""?!0:this.mesh_min[0]!==0||this.mesh_min[1]!==0||this.mesh_max[0]!==0||this.mesh_max[1]!==0}get name(){return this.bed_mesh.profile_name!==""?this.bed_mesh.profile_name:"Unknown"}get probed_matrix(){var e;return(e=this.bed_mesh.probed_matrix)!=null?e:[]}get points(){const e=[];for(let t=0;t<this.probed_matrix.length;t++)for(let r=0;r<this.probed_matrix[t].length;r++)e.push(this.probed_matrix[t][r]);return e}};Cr=vl([vt],Cr);var _l=Object.defineProperty,ml=Object.getOwnPropertyDescriptor,pl=(e,t,r,n)=>{for(var i=n>1?void 0:n?ml(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&_l(t,r,i),i};let Zn=class extends Et(At,Cr){constructor(){super(...arguments),this.mdiInformation=Ys,this.mdiPencil=Ga,this.showRename=!1}get x_count(){var e,t;return(t=(e=this.bed_mesh.probed_matrix[0])==null?void 0:e.length)!=null?t:0}get y_count(){var e,t;return(t=(e=this.bed_mesh.probed_matrix)==null?void 0:e.length)!=null?t:0}get x_step_size(){return this.x_count<1?0:(this.mesh_max[0]-this.mesh_min[0])/(this.x_count-1)}get y_step_size(){return this.y_count<1?0:(this.mesh_max[1]-this.mesh_min[1])/(this.y_count-1)}get index_max(){return this.points.indexOf(this.max)}get index_max_y(){return Math.trunc(this.index_max/this.x_count)}get index_max_x(){return this.index_max%this.y_count}get position_max_x(){return this.mesh_min[0]+this.index_max_x*this.x_step_size}get position_max_y(){return this.mesh_min[1]+this.index_max_y*this.y_step_size}get index_min(){return this.points.indexOf(this.min)}get index_min_y(){return Math.trunc(this.index_min/this.x_count)}get index_min_x(){return this.index_min%this.y_count}get position_min_x(){return this.mesh_min[0]+this.index_min_x*this.x_step_size}get position_min_y(){return this.mesh_min[1]+this.index_min_y*this.y_step_size}};Zn=pl([vt({components:{}})],Zn);var gl=function(){var e=this,t=e.$createElement,r=e._self._c||t;return e.is_active?r(Wt,{staticClass:"mt-0",attrs:{title:e.$t("Heightmap.CurrentMesh.Headline"),"card-class":"heightmap-current-mesh-panel",icon:e.mdiInformation,collapsible:!0}},[r(ft,{staticClass:"py-3 px-0"},[r(ht,{staticClass:"px-3"},[r(we,[e._v(e._s(e.$t("Heightmap.CurrentMesh.Name")))]),r(we,{staticClass:"text-right"},[e.name.startsWith("adaptive-")?r("span",{staticClass:"font-weight-bold"},[e._v(e._s(e.name))]):r("span",{staticClass:"currentMeshName cursor-pointer font-weight-bold",on:{click:function(n){e.showRename=!0}}},[r(gt,{attrs:{left:"",small:"",color:"primary"}},[e._v(e._s(e.mdiPencil))]),e._v(" "+e._s(e.name)+" ")],1)])],1),r(nr,{staticClass:"my-3"}),r(ht,{staticClass:"px-3"},[r(we,[e._v(e._s(e.$t("Heightmap.CurrentMesh.Size")))]),r(we,{staticClass:"text-right"},[e._v(e._s(e.x_count)+"x"+e._s(e.y_count))])],1),r(nr,{staticClass:"my-3"}),e.index_max>-1?r(ht,{staticClass:"px-3"},[r(we,[e._v(" "+e._s(e.$t("Heightmap.CurrentMesh.Max"))+" ["+e._s(e.position_max_x.toFixed(1))+", "+e._s(e.position_max_y.toFixed(1))+"] ")]),r(we,{staticClass:"text-right"},[e._v(e._s(e.max.toFixed(3))+" mm")])],1):e._e(),r(nr,{staticClass:"my-3"}),r(ht,{staticClass:"px-3"},[r(we,[e._v(" "+e._s(e.$t("Heightmap.CurrentMesh.Min"))+" ["+e._s(e.position_min_x.toFixed(1))+", "+e._s(e.position_min_y.toFixed(1))+"] ")]),r(we,{staticClass:"text-right"},[e._v(e._s(e.min.toFixed(3))+" mm")])],1),r(nr,{staticClass:"my-3"}),r(ht,{staticClass:"px-3"},[r(we,[e._v(e._s(e.$t("Heightmap.CurrentMesh.Range")))]),r(we,{staticClass:"text-right"},[e._v(e._s(e.variance)+" mm")])],1)],1),r(_i,{attrs:{show:e.showRename,name:e.name},on:{close:function(n){e.showRename=!1}}})],1):e._e()},xl=[];const Gi={};var yl=St(Zn,gl,xl,!1,Tl,"a3cfb25c",null,null);function Tl(e){for(let t in Gi)this[t]=Gi[t]}const El=function(){return yl.exports}();var Al=Object.defineProperty,Sl=Object.getOwnPropertyDescriptor,gi=(e,t,r,n)=>{for(var i=n>1?void 0:n?Sl(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&Al(t,r,i),i};let Rr=class extends Et(At){constructor(){super(...arguments),this.mdiCloseThick=hi,this.mdiGrid=vn,this.isInvalidName=!1,this.name="",this.rules=[e=>!!e||this.$t("Heightmap.InvalidNameEmpty"),e=>e===e.replace(/[^\x00-\x7F]/g,"")||this.$t("Heightmap.InvalidNameAscii")]}calibrateMesh(){const e='BED_MESH_CALIBRATE PROFILE="'.concat(this.name,'"');this.$store.dispatch("server/addEvent",{message:e,type:"command"}),this.$socket.emit("printer.gcode.script",{script:e},{loading:"bedMeshCalibrate"}),this.closeDialog()}closeDialog(){this.$emit("close")}showChanged(){this.show&&(this.name="default",this.$nextTick(()=>{setTimeout(()=>{var e;(e=this.$refs.input)==null||e.focus()},100)}))}};gi([Ke({type:Boolean,required:!0})],Rr.prototype,"show",2);gi([za("show")],Rr.prototype,"showChanged",1);Rr=gi([vt],Rr);var wl=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r(fi,{attrs:{value:e.show,persistent:"","max-width":400},on:{keydown:function(n){return!n.type.indexOf("key")&&e._k(n.keyCode,"esc",27,n.key,["Esc","Escape"])?null:e.closeDialog.apply(null,arguments)}}},[r(Wt,{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(Pe,{attrs:{icon:"",tile:""},on:{click:e.closeDialog}},[r(gt,[e._v(e._s(e.mdiCloseThick))])],1)]},proxy:!0}])},[r(ft,[r(Va,{ref:"input",attrs:{label:e.$t("Heightmap.Name"),required:"",rules:e.rules},on:{"update:error":function(n){e.isInvalidName=n},keyup:function(n){return!n.type.indexOf("key")&&e._k(n.keyCode,"enter",13,n.key,"Enter")?null:e.calibrateMesh.apply(null,arguments)}},model:{value:e.name,callback:function(n){e.name=n},expression:"name"}})],1),r(di,[r(vi),r(Pe,{attrs:{text:""},on:{click:e.closeDialog}},[e._v(e._s(e.$t("Heightmap.Abort")))]),r(Pe,{attrs:{disabled:e.isInvalidName,color:"primary",text:""},on:{click:e.calibrateMesh}},[e._v(" "+e._s(e.$t("Heightmap.Calibrate"))+" ")])],1)],1)],1)},bl=[];const Vi={};var Cl=St(Rr,wl,bl,!1,Rl,null,null,null);function Rl(e){for(let t in Vi)this[t]=Vi[t]}const Qa=function(){return Cl.exports}();var Ml=Object.defineProperty,Ll=Object.getOwnPropertyDescriptor,Nl=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ll(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&Ml(t,r,i),i};let Kn=class extends Et(At,Zs,Cr){constructor(){super(...arguments),this.mdiGrid=vn,this.mdiHome=Ks,this.calibrateDialog=!1}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 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 heightmapRangeLimit(){const e=Math.round(Math.max(Math.abs(this.min),Math.abs(this.max))*10)/10,t=Math.max(e,1);return[e,t]}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"})}};Kn=Nl([vt({components:{HeightmapCalibrateMeshDialog:Qa}})],Kn);function ki(e,t,r){typeof t=="object"&&(r=t,t=null);var n=this,i;if(!(e instanceof Function)){i=[];for(var a in e)e.hasOwnProperty(a)&&i.push(a)}var s=function(l){if(n.apply(this,arguments),e instanceof Function?Wi(this,e.call(this,l)):Pl(this,e,i),this.constructor===s)for(var c=s.__initializers__,u=0;u<c.length;u++)c[u].apply(this,arguments)};s.__super__=n,n.__initializers__?s.__initializers__=n.__initializers__.slice():s.__initializers__=[],t&&s.__initializers__.push(t);var o=function(){};return o.prototype=n.prototype,s.prototype=new o,s.prototype.constructor=s,Wi(s.prototype,r),s.extend=n.extend,s.derive=n.extend,s}function Wi(e,t){if(t)for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])}function Pl(e,t,r){for(var n=0;n<r.length;n++){var i=r[n];e[i]=t[i]}}const Dl={extend:ki,derive:ki};function Ol(e,t){this.action=e,this.context=t}var Il={trigger:function(e){if(this.hasOwnProperty("__handlers__")&&this.__handlers__.hasOwnProperty(e)){var t=this.__handlers__[e],r=t.length,n=-1,i=arguments;switch(i.length){case 1:for(;++n<r;)t[n].action.call(t[n].context);return;case 2:for(;++n<r;)t[n].action.call(t[n].context,i[1]);return;case 3:for(;++n<r;)t[n].action.call(t[n].context,i[1],i[2]);return;case 4:for(;++n<r;)t[n].action.call(t[n].context,i[1],i[2],i[3]);return;case 5:for(;++n<r;)t[n].action.call(t[n].context,i[1],i[2],i[3],i[4]);return;default:for(;++n<r;)t[n].action.apply(t[n].context,Array.prototype.slice.call(i,1));return}}},on:function(e,t,r){if(!(!e||!t)){var n=this.__handlers__||(this.__handlers__={});if(!n[e])n[e]=[];else if(this.has(e,t))return;var i=new Ol(t,r||this);return n[e].push(i),this}},once:function(e,t,r){if(!e||!t)return;var n=this;function i(){n.off(e,i),t.apply(this,arguments)}return this.on(e,i,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 n=r[e],i=[],a=0;a<n.length;a++)t&&n[a].action!==t&&i.push(n[a]);r[e]=i}return this},has:function(e,t){var r=this.__handlers__;if(!r||!r[e])return!1;for(var n=r[e],i=0;i<n.length;i++)if(n[i].action===t)return!0}};const xi=Il;var Bl=0,Fl=Array.prototype,Ul=Fl.forEach,xr={genGUID:function(){return++Bl},relative2absolute:function(e,t){if(!t||e.match(/^\//))return e;for(var r=e.split("/"),n=t.split("/"),i=r[0];i==="."||i==="..";)i===".."&&n.pop(),r.shift(),i=r[0];return n.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 n=0;n<r.length;n++){var i=r[n];e[i]=t[i]}return e},defaultsWithPropList:function(e,t,r){if(t)for(var n=0;n<r.length;n++){var i=r[n];e[i]==null&&(e[i]=t[i])}return e},each:function(e,t,r){if(e&&t)if(e.forEach&&e.forEach===Ul)e.forEach(t,r);else if(e.length===+e.length)for(var n=0,i=e.length;n<i;n++)t.call(r,e[n],n,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(xr.isObject(e)){if(xr.isArray(e))return e.slice();if(xr.isArrayLike(e)){for(var t=new e.constructor(e.length),r=0;r<e.length;r++)t[r]=e[r];return t}else return xr.extend({},e)}else return e}};const De=xr;var mn=function(){this.__uid__=De.genGUID()};mn.__initializers__=[function(e){De.extend(this,e)}];De.extend(mn,Dl);De.extend(mn.prototype,xi);const qe=mn;var Xi=["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"],$i=["MAX_TEXTURE_SIZE","MAX_CUBE_MAP_TEXTURE_SIZE"];function Hl(e){for(var t={},r={},n=0;n<Xi.length;n++){var i=Xi[n];s(i)}for(var n=0;n<$i.length;n++){var a=$i[n];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 zl(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 n=r.loaded/r.total;e.onprogress(n,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 Gl={get:zl};var An,Xe={};Xe.supportWebGL=function(){if(An==null)try{var e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");if(!t)throw new Error}catch{An=!1}return An};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 zt={};typeof window<"u"?zt=window:typeof global<"u"&&(zt=global);Xe.requestAnimationFrame=zt.requestAnimationFrame||zt.msRequestAnimationFrame||zt.mozRequestAnimationFrame||zt.webkitRequestAnimationFrame||function(e){setTimeout(e,16)};Xe.createCanvas=function(){return document.createElement("canvas")};Xe.createImage=function(){return new zt.Image};Xe.request={get:Gl.get};Xe.addEventListener=function(e,t,r,n){e.addEventListener(t,r,n)};Xe.removeEventListener=function(e,t,r){e.removeEventListener(t,r)};const Se=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,n=0;r&&n!=e;)r=r.next,n++;if(r){var i=new Le.Entry(t),a=r.prev;a?(a.next=i,i.prev=a):this.head=i,i.next=r,r.prev=i}else this.insert(t)}};Le.prototype.insertBeforeEntry=function(e,t){var r=new Le.Entry(e),n=t.prev;n?(n.next=r,r.prev=n):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,n=0,i=typeof t<"u";r;)i?e.call(t,r.value,n):e(r.value,n),r=r.next,n++};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 Vl=Le;var hr=function(e){this._list=new Vl,this._map={},this._maxSize=e||10};hr.prototype.setMaxSize=function(e){this._maxSize=e};hr.prototype.put=function(e,t){if(!this._map.hasOwnProperty(e)){var r=this._list.length();if(r>=this._maxSize&&r>0){var n=this._list.head;this._list.remove(n),delete this._map[n.key]}var i=this._list.insert(t);i.key=e,this._map[e]=i}};hr.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};hr.prototype.remove=function(e){var t=this._map[e];typeof t<"u"&&(delete this._map[e],this._list.remove(t))};hr.prototype.clear=function(){this._list.clear(),this._map={}};const Ja=hr;var me={},ji={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 st(e){return e=Math.round(e),e<0?0:e>255?255:e}function kl(e){return e=Math.round(e),e<0?0:e>360?360:e}function Mr(e){return e<0?0:e>1?1:e}function Sn(e){return e.length&&e.charAt(e.length-1)==="%"?st(parseFloat(e)/100*255):st(parseInt(e,10))}function or(e){return e.length&&e.charAt(e.length-1)==="%"?Mr(parseFloat(e)/100):Mr(parseFloat(e))}function wn(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 Lt(e,t,r){return e+(t-e)*r}function at(e,t,r,n,i){return e[0]=t,e[1]=r,e[2]=n,e[3]=i,e}function Qn(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}var es=new Ja(20),Gr=null;function Yt(e,t){Gr&&Qn(Gr,t),Gr=es.put(e,Gr||t.slice())}me.parse=function(e,t){if(e){t=t||[];var r=es.get(e);if(r)return Qn(t,r);e=e+"";var n=e.replace(/ /g,"").toLowerCase();if(n in ji)return Qn(t,ji[n]),Yt(e,t),t;if(n.charAt(0)==="#"){if(n.length===4){var i=parseInt(n.substr(1),16);if(!(i>=0&&i<=4095)){at(t,0,0,0,1);return}return at(t,(i&3840)>>4|(i&3840)>>8,i&240|(i&240)>>4,i&15|(i&15)<<4,1),Yt(e,t),t}else if(n.length===7){var i=parseInt(n.substr(1),16);if(!(i>=0&&i<=16777215)){at(t,0,0,0,1);return}return at(t,(i&16711680)>>16,(i&65280)>>8,i&255,1),Yt(e,t),t}return}var a=n.indexOf("("),s=n.indexOf(")");if(a!==-1&&s+1===n.length){var o=n.substr(0,a),l=n.substr(a+1,s-(a+1)).split(","),c=1;switch(o){case"rgba":if(l.length!==4){at(t,0,0,0,1);return}c=or(l.pop());case"rgb":if(l.length!==3){at(t,0,0,0,1);return}return at(t,Sn(l[0]),Sn(l[1]),Sn(l[2]),c),Yt(e,t),t;case"hsla":if(l.length!==4){at(t,0,0,0,1);return}return l[3]=or(l[3]),Jn(l,t),Yt(e,t),t;case"hsl":if(l.length!==3){at(t,0,0,0,1);return}return Jn(l,t),Yt(e,t),t;default:return}}at(t,0,0,0,1)}};me.parseToFloat=function(e,t){if(t=me.parse(e,t),!!t)return t[0]/=255,t[1]/=255,t[2]/=255,t};function Jn(e,t){var r=(parseFloat(e[0])%360+360)%360/360,n=or(e[1]),i=or(e[2]),a=i<=.5?i*(n+1):i+n-i*n,s=i*2-a;return t=t||[],at(t,st(wn(s,a,r+1/3)*255),st(wn(s,a,r)*255),st(wn(s,a,r-1/3)*255),1),e.length===4&&(t[3]=e[3]),t}function Wl(e){if(e){var t=e[0]/255,r=e[1]/255,n=e[2]/255,i=Math.min(t,r,n),a=Math.max(t,r,n),s=a-i,o=(a+i)/2,l,c;if(s===0)l=0,c=0;else{o<.5?c=s/(a+i):c=s/(2-a-i);var u=((a-t)/6+s/2)/s,h=((a-r)/6+s/2)/s,d=((a-n)/6+s/2)/s;t===a?l=d-h:r===a?l=1/3+u-d:n===a&&(l=2/3+h-u),l<0&&(l+=1),l>1&&(l-=1)}var f=[l*360,c,o];return e[3]!=null&&f.push(e[3]),f}}me.lift=function(e,t){var r=me.parse(e);if(r){for(var n=0;n<3;n++)t<0?r[n]=r[n]*(1-t)|0:r[n]=(255-r[n])*t+r[n]|0;return me.stringify(r,r.length===4?"rgba":"rgb")}};me.toHex=function(e){var t=me.parse(e);if(t)return((1<<24)+(t[0]<<16)+(t[1]<<8)+ +t[2]).toString(16).slice(1)};me.fastLerp=function(e,t,r){if(!(!(t&&t.length)||!(e>=0&&e<=1))){r=r||[];var n=e*(t.length-1),i=Math.floor(n),a=Math.ceil(n),s=t[i],o=t[a],l=n-i;return r[0]=st(Lt(s[0],o[0],l)),r[1]=st(Lt(s[1],o[1],l)),r[2]=st(Lt(s[2],o[2],l)),r[3]=Mr(Lt(s[3],o[3],l)),r}};me.fastMapToColor=me.fastLerp;me.lerp=function(e,t,r){if(!(!(t&&t.length)||!(e>=0&&e<=1))){var n=e*(t.length-1),i=Math.floor(n),a=Math.ceil(n),s=me.parse(t[i]),o=me.parse(t[a]),l=n-i,c=me.stringify([st(Lt(s[0],o[0],l)),st(Lt(s[1],o[1],l)),st(Lt(s[2],o[2],l)),Mr(Lt(s[3],o[3],l))],"rgba");return r?{color:c,leftIndex:i,rightIndex:a,value:n}:c}};me.mapToColor=me.lerp;me.modifyHSL=function(e,t,r,n){if(e=me.parse(e),e)return e=Wl(e),t!=null&&(e[0]=kl(t)),r!=null&&(e[1]=or(r)),n!=null&&(e[2]=or(n)),me.stringify(Jn(e),"rgba")};me.modifyAlpha=function(e,t){if(e=me.parse(e),e&&t!=null)return e[3]=Mr(t),me.stringify(e,"rgba")};me.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 Xl=me;var $l=Xl.parseToFloat,bn={};function qi(e){var t=Object.keys(e);t.sort();for(var r=[],n=0;n<t.length;n++){var i=t[n],a=e[i];a===null?r.push(i):r.push(i+" "+a.toString())}return r.join("\n")}function jl(e,t,r){r.sort();for(var n=[],i=0;i<r.length;i++){var a=r[i];n.push(a)}var s=qi(e)+"\n"+qi(t)+"\n"+n.join("\n");if(bn[s])return bn[s];var o=De.genGUID();return bn[s]=o,o}var ql=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=$l(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 n=e[r];this.setUniform(r,n)}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 n=this.uniforms;this._enabledUniforms=Object.keys(n),this._enabledUniforms.sort(),this._textureUniforms=this._enabledUniforms.filter(function(c){var u=this.uniforms[c].type;return u==="t"||u==="tv"},this);var i=this.vertexDefines,a=this.fragmentDefines;if(this.vertexDefines=De.clone(e.vertexDefines),this.fragmentDefines=De.clone(e.fragmentDefines),t){for(var s in r)n[s]&&(n[s].value=r[s].value);De.defaults(this.vertexDefines,i),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 n=this.vertexDefines,i=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")&&n[t]!==r&&(n[t]=r,this._programKey=""),(e==="fragment"||e==="both")&&i[t]!==r&&(i[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 n=r.enabled;n||(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 n=!r.enabled;n||(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=jl(this.vertexDefines,this.fragmentDefines,this.getEnabledTextures())),this._programKey}});const wt=ql;var Qr=1e-6,Oe=Array,ir=Math.random,Z={};Z.create=function(){var e=new Oe(2);return e[0]=0,e[1]=0,e};Z.clone=function(e){var t=new Oe(2);return t[0]=e[0],t[1]=e[1],t};Z.fromValues=function(e,t){var r=new Oe(2);return r[0]=e,r[1]=t,r};Z.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e};Z.set=function(e,t,r){return e[0]=t,e[1]=r,e};Z.add=function(e,t,r){return e[0]=t[0]+r[0],e[1]=t[1]+r[1],e};Z.subtract=function(e,t,r){return e[0]=t[0]-r[0],e[1]=t[1]-r[1],e};Z.sub=Z.subtract;Z.multiply=function(e,t,r){return e[0]=t[0]*r[0],e[1]=t[1]*r[1],e};Z.mul=Z.multiply;Z.divide=function(e,t,r){return e[0]=t[0]/r[0],e[1]=t[1]/r[1],e};Z.div=Z.divide;Z.min=function(e,t,r){return e[0]=Math.min(t[0],r[0]),e[1]=Math.min(t[1],r[1]),e};Z.max=function(e,t,r){return e[0]=Math.max(t[0],r[0]),e[1]=Math.max(t[1],r[1]),e};Z.scale=function(e,t,r){return e[0]=t[0]*r,e[1]=t[1]*r,e};Z.scaleAndAdd=function(e,t,r,n){return e[0]=t[0]+r[0]*n,e[1]=t[1]+r[1]*n,e};Z.distance=function(e,t){var r=t[0]-e[0],n=t[1]-e[1];return Math.sqrt(r*r+n*n)};Z.dist=Z.distance;Z.squaredDistance=function(e,t){var r=t[0]-e[0],n=t[1]-e[1];return r*r+n*n};Z.sqrDist=Z.squaredDistance;Z.length=function(e){var t=e[0],r=e[1];return Math.sqrt(t*t+r*r)};Z.len=Z.length;Z.squaredLength=function(e){var t=e[0],r=e[1];return t*t+r*r};Z.sqrLen=Z.squaredLength;Z.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e};Z.inverse=function(e,t){return e[0]=1/t[0],e[1]=1/t[1],e};Z.normalize=function(e,t){var r=t[0],n=t[1],i=r*r+n*n;return i>0&&(i=1/Math.sqrt(i),e[0]=t[0]*i,e[1]=t[1]*i),e};Z.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]};Z.cross=function(e,t,r){var n=t[0]*r[1]-t[1]*r[0];return e[0]=e[1]=0,e[2]=n,e};Z.lerp=function(e,t,r,n){var i=t[0],a=t[1];return e[0]=i+n*(r[0]-i),e[1]=a+n*(r[1]-a),e};Z.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};Z.transformMat2=function(e,t,r){var n=t[0],i=t[1];return e[0]=r[0]*n+r[2]*i,e[1]=r[1]*n+r[3]*i,e};Z.transformMat2d=function(e,t,r){var n=t[0],i=t[1];return e[0]=r[0]*n+r[2]*i+r[4],e[1]=r[1]*n+r[3]*i+r[5],e};Z.transformMat3=function(e,t,r){var n=t[0],i=t[1];return e[0]=r[0]*n+r[3]*i+r[6],e[1]=r[1]*n+r[4]*i+r[7],e};Z.transformMat4=function(e,t,r){var n=t[0],i=t[1];return e[0]=r[0]*n+r[4]*i+r[12],e[1]=r[1]*n+r[5]*i+r[13],e};Z.forEach=function(){var e=Z.create();return function(t,r,n,i,a,s){var o,l;for(r||(r=2),n||(n=0),i?l=Math.min(i*r+n,t.length):l=t.length,o=n;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=Z;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 Yi=Q.prototype;Object.defineProperty(Yi,"x",{get:function(){return this.array[0]},set:function(e){this.array[0]=e,this._dirty=!0}}),Object.defineProperty(Yi,"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,n){return H.lerp(e.array,t.array,r.array,n),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,n){return H.scaleAndAdd(e.array,t.array,r.array,n),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 Ze=Q;var Zi=1,Ki=2,Cn=3,Qi={};function Yl(e){for(var t=e.split("\n"),r=0,n=t.length;r<n;r++)t[r]=r+1+": "+t[r];return t.join("\n")}function Ji(e,t,r){if(!e.getShaderParameter(t,e.COMPILE_STATUS))return[e.getShaderInfoLog(t),Yl(r)].join("\n")}var ea=new Se.Float32Array(16),Zl=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,n){var i=this._locations,a=i[r];if(a==null)return!1;switch(t){case"m4":if(!(n instanceof Float32Array)){for(var s=0;s<n.length;s++)ea[s]=n[s];n=ea}e.uniformMatrix4fv(a,!1,n);break;case"2i":e.uniform2i(a,n[0],n[1]);break;case"2f":e.uniform2f(a,n[0],n[1]);break;case"3i":e.uniform3i(a,n[0],n[1],n[2]);break;case"3f":e.uniform3f(a,n[0],n[1],n[2]);break;case"4i":e.uniform4i(a,n[0],n[1],n[2],n[3]);break;case"4f":e.uniform4f(a,n[0],n[1],n[2],n[3]);break;case"1i":e.uniform1i(a,n);break;case"1f":e.uniform1f(a,n);break;case"1fv":e.uniform1fv(a,n);break;case"1iv":e.uniform1iv(a,n);break;case"2iv":e.uniform2iv(a,n);break;case"2fv":e.uniform2fv(a,n);break;case"3iv":e.uniform3iv(a,n);break;case"3fv":e.uniform3fv(a,n);break;case"4iv":e.uniform4iv(a,n);break;case"4fv":e.uniform4fv(a,n);break;case"m2":case"m2v":e.uniformMatrix2fv(a,!1,n);break;case"m3":case"m3v":e.uniformMatrix3fv(a,!1,n);break;case"m4v":if(Array.isArray(n)&&Array.isArray(n[0])){for(var o=new Se.Float32Array(n.length*16),l=0,s=0;s<n.length;s++)for(var c=n[s],u=0;u<16;u++)o[l++]=c[u];e.uniformMatrix4fv(a,!1,o)}else e.uniformMatrix4fv(a,!1,n);break}return!0},setUniformOfSemantic:function(e,t,r){var n=this.uniformSemantics[t];return n?this.setUniform(e,n.type,n.symbol,r):!1},enableAttributes:function(e,t,r){var n=e.gl,i=this._program,a=this._locations,s;r?s=r.__enabledAttributeList:s=Qi[e.__uid__],s||(r?s=r.__enabledAttributeList=[]:s=Qi[e.__uid__]=[]);for(var o=[],l=0;l<t.length;l++){var c=t[l];if(!this.attributes[c]){o[l]=-1;continue}var u=a[c];if(u==null){if(u=n.getAttribLocation(i,c),u===-1){o[l]=-1;continue}a[c]=u}o[l]=u,s[u]?s[u]=Ki:s[u]=Zi}for(var l=0;l<s.length;l++)switch(s[l]){case Zi:n.enableVertexAttribArray(l),s[l]=Cn;break;case Ki:s[l]=Cn;break;case Cn:n.disableVertexAttribArray(l),s[l]=0;break}return o},getAttribLocation:function(e,t){var r=this._locations,n=r[t];return n==null&&(n=e.getAttribLocation(this._program,t),r[t]=n),n},buildProgram:function(e,t,r,n){var i=e.createShader(e.VERTEX_SHADER),a=e.createProgram();e.shaderSource(i,r),e.compileShader(i);var s=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(s,n),e.compileShader(s);var o=Ji(e,i,r);if(o||(o=Ji(e,s,n),o))return o;if(e.attachShader(a,i),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(i),e.deleteShader(s),this._program=a,this.vertexCode=r,this.fragmentCode=n,!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 u=t.uniforms[c];this._locations[u]=e.getUniformLocation(a,u)}}});const Kl=Zl;var Ql=/for\s*?\(int\s*?_idx_\s*\=\s*([\w-]+)\;\s*_idx_\s*<\s*([\w-]+);\s*_idx_\s*\+\+\s*\)\s*\{\{([\s\S]+?)(?=\}\})\}\}/g;function ta(e,t,r){function n(s,o,l,c){var u="";isNaN(o)&&(o in t?o=t[o]:o=i[o]),isNaN(l)&&(l in t?l=t[l]:l=i[l]);for(var h=parseInt(o);h<parseInt(l);h++)u+="{"+c.replace(/float\s*\(\s*_idx_\s*\)/g,h.toFixed(1)).replace(/_idx_/g,h)+"}";return u}var i={};for(var a in r)i[a+"_COUNT"]=r[a];return e.replace(Ql,n)}function Rn(e,t,r){var n=[];if(t)for(var i in t){var a=t[i];a>0&&n.push("#define "+i.toUpperCase()+"_COUNT "+a)}if(r)for(var s=0;s<r.length;s++){var o=r[s];n.push("#define "+o.toUpperCase()+"_ENABLED")}for(var o in e){var l=e[o];l===null?n.push("#define "+o):n.push("#define "+o+" "+l.toString())}return n.join("\n")}function Jl(e){for(var t=[],r=0;r<e.length;r++)t.push("#extension GL_"+e[r]+" : enable");return t.join("\n")}function ec(e){return["precision",e,"float"].join(" ")+";\n"+["precision",e,"int"].join(" ")+";\n"+["precision",e,"sampler2D"].join(" ")+";\n"}function ts(e){this._renderer=e,this._cache={}}ts.prototype.getProgram=function(e,t,r){var n=this._cache,i=e.isSkinnedMesh&&e.isSkinnedMesh(),a=e.isInstancedMesh&&e.isInstancedMesh(),s="s"+t.shader.shaderID+"m"+t.getProgramKey();r&&(s+="se"+r.getProgramKey(e.lightGroup)),i&&(s+=",sk"+e.joints.length),a&&(s+=",is");var x=n[s];if(x)return x;var o=r?r.getLightsNumbers(e.lightGroup):{},l=this._renderer,c=l.gl,u=t.getEnabledTextures(),h="";if(i){var d={SKINNING:null,JOINT_COUNT:e.joints.length};e.joints.length>l.getMaxJointNumber()&&(d.USE_SKIN_MATRICES_TEXTURE=null),h+="\n"+Rn(d)+"\n"}a&&(h+="\n#define INSTANCING\n");var f=h+Rn(t.vertexDefines,o,u),v=h+Rn(t.fragmentDefines,o,u),_=f+"\n"+t.shader.vertex,m=["OES_standard_derivatives","EXT_shader_texture_lod"].filter(function(S){return l.getGLExtension(S)!=null});m.indexOf("EXT_shader_texture_lod")>=0&&(v+="\n#define SUPPORT_TEXTURE_LOD"),m.indexOf("OES_standard_derivatives")>=0&&(v+="\n#define SUPPORT_STANDARD_DERIVATIVES");var p=Jl(m)+"\n"+ec(t.precision)+"\n"+v+"\n"+t.shader.fragment,y=ta(_,t.vertexDefines,o),g=ta(p,t.fragmentDefines,o),x=new Kl;x.uniformSemantics=t.shader.uniformSemantics,x.attributes=t.shader.attributes;var E=x.buildProgram(c,t.shader,y,g);return x.__error=E,n[s]=x,x};var ra=/uniform\s+(bool|float|int|vec2|vec3|vec4|ivec2|ivec3|ivec4|mat2|mat3|mat4|sampler2D|samplerCube)\s+([\s\S]*?);/g,tc=/attribute\s+(float|int|vec2|vec3|vec4)\s+([\s\S]*?);/g,na=/#define\s+(\w+)?(\s+[\d-.]+)?\s*;?\s*\n/g,rc={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 ia={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[]}},ei=["POSITION","NORMAL","BINORMAL","TANGENT","TEXCOORD","TEXCOORD_0","TEXCOORD_1","COLOR","JOINT","WEIGHT"],rs=["SKIN_MATRIX","VIEWPORT_SIZE","VIEWPORT","DEVICEPIXELRATIO","WINDOW_SIZE","NEAR","FAR","TIME"],ns=["WORLD","VIEW","PROJECTION","WORLDVIEW","VIEWPROJECTION","WORLDVIEWPROJECTION","WORLDINVERSE","VIEWINVERSE","PROJECTIONINVERSE","WORLDVIEWINVERSE","VIEWPROJECTIONINVERSE","WORLDVIEWPROJECTIONINVERSE","WORLDTRANSPOSE","VIEWTRANSPOSE","PROJECTIONTRANSPOSE","WORLDVIEWTRANSPOSE","VIEWPROJECTIONTRANSPOSE","WORLDVIEWPROJECTIONTRANSPOSE","WORLDINVERSETRANSPOSE","VIEWINVERSETRANSPOSE","PROJECTIONINVERSETRANSPOSE","WORLDVIEWINVERSETRANSPOSE","VIEWPROJECTIONINVERSETRANSPOSE","WORLDVIEWPROJECTIONINVERSETRANSPOSE"],nc={vec4:4,vec3:3,vec2:2,float:1},Mn={},is={};function ic(e,t){var r="vertex:"+e+"fragment:"+t;if(Mn[r])return Mn[r];var n=De.genGUID();return Mn[r]=n,is[n]={vertex:e,fragment:t},n}function aa(e){return e.replace(/[ \t]*\/\/.*\n/g,"").replace(/[ \t]*\/\*[\s\S]*?\*\//g,"")}function Zt(){console.error("Wrong uniform/attributes syntax")}function sa(e,t){for(var r=/[,=\(\):]/,n=t.replace(/:\s*\[\s*(.*)\s*\]/g,"="+e+"($1)").replace(/\s+/g,"").split(/(?=[,=\(\):])/g),i=[],a=0;a<n.length;a++)n[a].match(r)?i.push(n[a].charAt(0),n[a].slice(1)):i.push(n[a]);n=i;var s=0,o=1,l=2,c=3,u=4,h=5,d=s,f={},v=null,_;m(n[0]);function m(g){g||Zt();var x=g.match(/\[(.*?)\]/);_=g.replace(/\[(.*?)\]/,""),f[_]={},x&&(f[_].isArray=!0,f[_].arraySize=x[1])}for(var a=1;a<n.length;a++){var p=n[a];if(p){if(p==="="){if(d!==s&&d!==c){Zt();break}d=o;continue}else if(p===":"){d=u;continue}else if(p===","){if(d===l){if(!(v instanceof Array)){Zt();break}v.push(+n[++a])}else d=h;continue}else if(p===")"){f[_].value=new Se.Float32Array(v),v=null,d=h;continue}else if(p==="("){if(d!==l){Zt();break}if(!(v instanceof Array)){Zt();break}v.push(+n[++a]);continue}else if(p.indexOf("vec")>=0){if(d!==o&&d!==u){Zt();break}d=l,v=[];continue}else if(d===o){e==="bool"?f[_].value=p==="true":f[_].value=parseFloat(p),v=null;continue}else if(d===u){var y=p;ei.indexOf(y)>=0||rs.indexOf(y)>=0||ns.indexOf(y)>=0?f[_].semantic=y:y==="ignore"||y==="unconfigurable"?f[_].ignore=!0:e==="bool"?f[_].value=y==="true":f[_].value=parseFloat(y);continue}m(p),d=s}}return f}function L(e,t){typeof e=="object"&&(t=e.fragment,e=e.vertex),e=aa(e),t=aa(t),this._shaderID=ic(e,t),this._vertexCode=L.parseImport(e),this._fragmentCode=L.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()}L.prototype={constructor:L,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=L.parseImport(this.vertex),this._fragmentCode=L.parseImport(this.fragment)},_addSemanticUniform:function(e,t,r){if(ei.indexOf(r)>=0)this.attributeSemantics[r]={symbol:e,type:t};else if(ns.indexOf(r)>=0){var n=!1,i=r;r.match(/TRANSPOSE$/)&&(n=!0,i=r.slice(0,-9)),this.matrixSemantics[r]={symbol:e,type:t,isTranspose:n,semanticNoTranspose:i}}else rs.indexOf(r)>=0&&(this.uniformSemantics[r]={symbol:e,type:t})},_addMaterialUniform:function(e,t,r,n,i,a){a[e]={type:r,value:i?ia.array:n||ia[t],semantic:null}},_parseUniforms:function(){var e={},t=this,r="vertex";this._uniformList=[],this._vertexCode=this._vertexCode.replace(ra,i),r="fragment",this._fragmentCode=this._fragmentCode.replace(ra,i),t.matrixSemanticKeys=Object.keys(this.matrixSemantics);function n(a){return a!=null?function(){return a}:null}function i(a,s,o){var l=sa(s,o),c=[];for(var u in l){var h=l[u],d=h.semantic,f=u,v=rc[s],_=n(l[u].value);l[u].isArray&&(f+="["+l[u].arraySize+"]",v+="v"),c.push(f),t._uniformList.push(u),h.ignore||((s==="sampler2D"||s==="samplerCube")&&(t.textures[u]={shaderType:r,type:s}),d?t._addSemanticUniform(u,v,d):t._addMaterialUniform(u,s,v,_,l[u].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(tc,r);function r(n,i,a){var s=sa(i,a),o=nc[i]||1,l=[];for(var c in s){var u=s[c].semantic;if(e[c]={type:"float",size:o,semantic:u||null},u){if(ei.indexOf(u)<0)throw new Error('Unkown semantic "'+u+'"');t.attributeSemantics[u]={symbol:c,type:i}}l.push(c)}return"attribute "+i+" "+l.join(",")+";\n"}this.attributes=e},_parseDefines:function(){var e=this,t="vertex";this._vertexCode=this._vertexCode.replace(na,r),t="fragment",this._fragmentCode=this._fragmentCode.replace(na,r);function r(n,i,a){var s=t==="vertex"?e.vertexDefines:e.fragmentDefines;return s[i]||(a==="false"?s[i]=!1:a==="true"?s[i]=!0:s[i]=a?isNaN(parseFloat(a))?a.trim():parseFloat(a):null),""}},clone:function(){var e=is[this._shaderID],t=new L(e.vertex,e.fragment);return t}};Object.defineProperty&&(Object.defineProperty(L.prototype,"shaderID",{get:function(){return this._shaderID}}),Object.defineProperty(L.prototype,"vertex",{get:function(){return this._vertexCode}}),Object.defineProperty(L.prototype,"fragment",{get:function(){return this._fragmentCode}}),Object.defineProperty(L.prototype,"uniforms",{get:function(){return this._uniformList}}));var ac=/(@import)\s*([0-9a-zA-Z_\-\.]*)/g;L.parseImport=function(e){return e=e.replace(ac,function(i,r,n){var i=L.source(n);return i?L.parseImport(i):(console.error('Shader chunk "'+n+'" not existed in library'),"")}),e};var sc=/(@export)\s*([0-9a-zA-Z_\-\.]*)\s*\n([\s\S]*?)@end/g;L.import=function(e){e.replace(sc,function(t,r,n,a){var a=a.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+\x24)/g,"");if(a){for(var s=n.split("."),o=L.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})};L.codes={};L.source=function(e){for(var t=e.split("."),r=L.codes,n=0;r&&n<t.length;){var i=t[n++];r=r[i]}return typeof r!="string"?(console.error('Shader "'+e+'" not existed in library'),""):r};const as="@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 Oe(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 Oe(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],n=t[2],i=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]=n,e[9]=a,e[11]=t[14],e[12]=i,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],n=t[1],i=t[2],a=t[3],s=t[4],o=t[5],l=t[6],c=t[7],u=t[8],h=t[9],d=t[10],f=t[11],v=t[12],_=t[13],m=t[14],p=t[15],y=r*o-n*s,g=r*l-i*s,x=r*c-a*s,E=n*l-i*o,S=n*c-a*o,R=i*c-a*l,w=u*_-h*v,M=u*m-d*v,F=u*p-f*v,b=h*m-d*_,U=h*p-f*_,I=d*p-f*m,N=y*I-g*U+x*b+E*F-S*M+R*w;return N?(N=1/N,e[0]=(o*I-l*U+c*b)*N,e[1]=(i*U-n*I-a*b)*N,e[2]=(_*R-m*S+p*E)*N,e[3]=(d*S-h*R-f*E)*N,e[4]=(l*F-s*I-c*M)*N,e[5]=(r*I-i*F+a*M)*N,e[6]=(m*x-v*R-p*g)*N,e[7]=(u*R-d*x+f*g)*N,e[8]=(s*U-o*F+c*w)*N,e[9]=(n*F-r*U-a*w)*N,e[10]=(v*S-_*x+p*y)*N,e[11]=(h*x-u*S-f*y)*N,e[12]=(o*M-s*b-l*w)*N,e[13]=(r*b-n*M+i*w)*N,e[14]=(_*g-v*E-m*y)*N,e[15]=(u*E-h*g+d*y)*N,e):null};le.adjoint=function(e,t){var r=t[0],n=t[1],i=t[2],a=t[3],s=t[4],o=t[5],l=t[6],c=t[7],u=t[8],h=t[9],d=t[10],f=t[11],v=t[12],_=t[13],m=t[14],p=t[15];return e[0]=o*(d*p-f*m)-h*(l*p-c*m)+_*(l*f-c*d),e[1]=-(n*(d*p-f*m)-h*(i*p-a*m)+_*(i*f-a*d)),e[2]=n*(l*p-c*m)-o*(i*p-a*m)+_*(i*c-a*l),e[3]=-(n*(l*f-c*d)-o*(i*f-a*d)+h*(i*c-a*l)),e[4]=-(s*(d*p-f*m)-u*(l*p-c*m)+v*(l*f-c*d)),e[5]=r*(d*p-f*m)-u*(i*p-a*m)+v*(i*f-a*d),e[6]=-(r*(l*p-c*m)-s*(i*p-a*m)+v*(i*c-a*l)),e[7]=r*(l*f-c*d)-s*(i*f-a*d)+u*(i*c-a*l),e[8]=s*(h*p-f*_)-u*(o*p-c*_)+v*(o*f-c*h),e[9]=-(r*(h*p-f*_)-u*(n*p-a*_)+v*(n*f-a*h)),e[10]=r*(o*p-c*_)-s*(n*p-a*_)+v*(n*c-a*o),e[11]=-(r*(o*f-c*h)-s*(n*f-a*h)+u*(n*c-a*o)),e[12]=-(s*(h*m-d*_)-u*(o*m-l*_)+v*(o*d-l*h)),e[13]=r*(h*m-d*_)-u*(n*m-i*_)+v*(n*d-i*h),e[14]=-(r*(o*m-l*_)-s*(n*m-i*_)+v*(n*l-i*o)),e[15]=r*(o*d-l*h)-s*(n*d-i*h)+u*(n*l-i*o),e};le.determinant=function(e){var t=e[0],r=e[1],n=e[2],i=e[3],a=e[4],s=e[5],o=e[6],l=e[7],c=e[8],u=e[9],h=e[10],d=e[11],f=e[12],v=e[13],_=e[14],m=e[15],p=t*s-r*a,y=t*o-n*a,g=t*l-i*a,x=r*o-n*s,E=r*l-i*s,S=n*l-i*o,R=c*v-u*f,w=c*_-h*f,M=c*m-d*f,F=u*_-h*v,b=u*m-d*v,U=h*m-d*_;return p*U-y*b+g*F+x*M-E*w+S*R};le.multiply=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=t[6],u=t[7],h=t[8],d=t[9],f=t[10],v=t[11],_=t[12],m=t[13],p=t[14],y=t[15],g=r[0],x=r[1],E=r[2],S=r[3];return e[0]=g*n+x*o+E*h+S*_,e[1]=g*i+x*l+E*d+S*m,e[2]=g*a+x*c+E*f+S*p,e[3]=g*s+x*u+E*v+S*y,g=r[4],x=r[5],E=r[6],S=r[7],e[4]=g*n+x*o+E*h+S*_,e[5]=g*i+x*l+E*d+S*m,e[6]=g*a+x*c+E*f+S*p,e[7]=g*s+x*u+E*v+S*y,g=r[8],x=r[9],E=r[10],S=r[11],e[8]=g*n+x*o+E*h+S*_,e[9]=g*i+x*l+E*d+S*m,e[10]=g*a+x*c+E*f+S*p,e[11]=g*s+x*u+E*v+S*y,g=r[12],x=r[13],E=r[14],S=r[15],e[12]=g*n+x*o+E*h+S*_,e[13]=g*i+x*l+E*d+S*m,e[14]=g*a+x*c+E*f+S*p,e[15]=g*s+x*u+E*v+S*y,e};le.multiplyAffine=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[4],o=t[5],l=t[6],c=t[8],u=t[9],h=t[10],d=t[12],f=t[13],v=t[14],_=r[0],m=r[1],p=r[2];return e[0]=_*n+m*s+p*c,e[1]=_*i+m*o+p*u,e[2]=_*a+m*l+p*h,_=r[4],m=r[5],p=r[6],e[4]=_*n+m*s+p*c,e[5]=_*i+m*o+p*u,e[6]=_*a+m*l+p*h,_=r[8],m=r[9],p=r[10],e[8]=_*n+m*s+p*c,e[9]=_*i+m*o+p*u,e[10]=_*a+m*l+p*h,_=r[12],m=r[13],p=r[14],e[12]=_*n+m*s+p*c+d,e[13]=_*i+m*o+p*u+f,e[14]=_*a+m*l+p*h+v,e};le.mul=le.multiply;le.mulAffine=le.multiplyAffine;le.translate=function(e,t,r){var n=r[0],i=r[1],a=r[2],s,o,l,c,u,h,d,f,v,_,m,p;return t===e?(e[12]=t[0]*n+t[4]*i+t[8]*a+t[12],e[13]=t[1]*n+t[5]*i+t[9]*a+t[13],e[14]=t[2]*n+t[6]*i+t[10]*a+t[14],e[15]=t[3]*n+t[7]*i+t[11]*a+t[15]):(s=t[0],o=t[1],l=t[2],c=t[3],u=t[4],h=t[5],d=t[6],f=t[7],v=t[8],_=t[9],m=t[10],p=t[11],e[0]=s,e[1]=o,e[2]=l,e[3]=c,e[4]=u,e[5]=h,e[6]=d,e[7]=f,e[8]=v,e[9]=_,e[10]=m,e[11]=p,e[12]=s*n+u*i+v*a+t[12],e[13]=o*n+h*i+_*a+t[13],e[14]=l*n+d*i+m*a+t[14],e[15]=c*n+f*i+p*a+t[15]),e};le.scale=function(e,t,r){var n=r[0],i=r[1],a=r[2];return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*i,e[5]=t[5]*i,e[6]=t[6]*i,e[7]=t[7]*i,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,n){var i=n[0],a=n[1],s=n[2],o=Math.sqrt(i*i+a*a+s*s),l,c,u,h,d,f,v,_,m,p,y,g,x,E,S,R,w,M,F,b,U,I,N,G;return Math.abs(o)<Qr?null:(o=1/o,i*=o,a*=o,s*=o,l=Math.sin(r),c=Math.cos(r),u=1-c,h=t[0],d=t[1],f=t[2],v=t[3],_=t[4],m=t[5],p=t[6],y=t[7],g=t[8],x=t[9],E=t[10],S=t[11],R=i*i*u+c,w=a*i*u+s*l,M=s*i*u-a*l,F=i*a*u-s*l,b=a*a*u+c,U=s*a*u+i*l,I=i*s*u+a*l,N=a*s*u-i*l,G=s*s*u+c,e[0]=h*R+_*w+g*M,e[1]=d*R+m*w+x*M,e[2]=f*R+p*w+E*M,e[3]=v*R+y*w+S*M,e[4]=h*F+_*b+g*U,e[5]=d*F+m*b+x*U,e[6]=f*F+p*b+E*U,e[7]=v*F+y*b+S*U,e[8]=h*I+_*N+g*G,e[9]=d*I+m*N+x*G,e[10]=f*I+p*N+E*G,e[11]=v*I+y*N+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 n=Math.sin(r),i=Math.cos(r),a=t[4],s=t[5],o=t[6],l=t[7],c=t[8],u=t[9],h=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*i+c*n,e[5]=s*i+u*n,e[6]=o*i+h*n,e[7]=l*i+d*n,e[8]=c*i-a*n,e[9]=u*i-s*n,e[10]=h*i-o*n,e[11]=d*i-l*n,e};le.rotateY=function(e,t,r){var n=Math.sin(r),i=Math.cos(r),a=t[0],s=t[1],o=t[2],l=t[3],c=t[8],u=t[9],h=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*i-c*n,e[1]=s*i-u*n,e[2]=o*i-h*n,e[3]=l*i-d*n,e[8]=a*n+c*i,e[9]=s*n+u*i,e[10]=o*n+h*i,e[11]=l*n+d*i,e};le.rotateZ=function(e,t,r){var n=Math.sin(r),i=Math.cos(r),a=t[0],s=t[1],o=t[2],l=t[3],c=t[4],u=t[5],h=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*i+c*n,e[1]=s*i+u*n,e[2]=o*i+h*n,e[3]=l*i+d*n,e[4]=c*i-a*n,e[5]=u*i-s*n,e[6]=h*i-o*n,e[7]=d*i-l*n,e};le.fromRotationTranslation=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=n+n,l=i+i,c=a+a,u=n*o,h=n*l,d=n*c,f=i*l,v=i*c,_=a*c,m=s*o,p=s*l,y=s*c;return e[0]=1-(f+_),e[1]=h+y,e[2]=d-p,e[3]=0,e[4]=h-y,e[5]=1-(u+_),e[6]=v+m,e[7]=0,e[8]=d+p,e[9]=v-m,e[10]=1-(u+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],n=t[1],i=t[2],a=t[3],s=r+r,o=n+n,l=i+i,c=r*s,u=n*s,h=n*o,d=i*s,f=i*o,v=i*l,_=a*s,m=a*o,p=a*l;return e[0]=1-h-v,e[1]=u+p,e[2]=d-m,e[3]=0,e[4]=u-p,e[5]=1-c-v,e[6]=f+_,e[7]=0,e[8]=d+m,e[9]=f-_,e[10]=1-c-h,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e};le.frustum=function(e,t,r,n,i,a,s){var o=1/(r-t),l=1/(i-n),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]=(i+n)*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,n,i){var a=1/Math.tan(t/2),s=1/(n-i);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]=(i+n)*s,e[11]=-1,e[12]=0,e[13]=0,e[14]=2*i*n*s,e[15]=0,e};le.ortho=function(e,t,r,n,i,a,s){var o=1/(t-r),l=1/(n-i),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]=(i+n)*l,e[14]=(s+a)*c,e[15]=1,e};le.lookAt=function(e,t,r,n){var i,a,s,o,l,c,u,h,d,f,v=t[0],_=t[1],m=t[2],p=n[0],y=n[1],g=n[2],x=r[0],E=r[1],S=r[2];return Math.abs(v-x)<Qr&&Math.abs(_-E)<Qr&&Math.abs(m-S)<Qr?le.identity(e):(u=v-x,h=_-E,d=m-S,f=1/Math.sqrt(u*u+h*h+d*d),u*=f,h*=f,d*=f,i=y*d-g*h,a=g*u-p*d,s=p*h-y*u,f=Math.sqrt(i*i+a*a+s*s),f?(f=1/f,i*=f,a*=f,s*=f):(i=0,a=0,s=0),o=h*s-d*a,l=d*i-u*s,c=u*a-h*i,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]=i,e[1]=o,e[2]=u,e[3]=0,e[4]=a,e[5]=l,e[6]=h,e[7]=0,e[8]=s,e[9]=c,e[10]=d,e[11]=0,e[12]=-(i*v+a*_+s*m),e[13]=-(o*v+l*_+c*m),e[14]=-(u*v+h*_+d*m),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 Oe(3);return e[0]=0,e[1]=0,e[2]=0,e};X.clone=function(e){var t=new Oe(3);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t};X.fromValues=function(e,t,r){var n=new Oe(3);return n[0]=e,n[1]=t,n[2]=r,n};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,n){return e[0]=t,e[1]=r,e[2]=n,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,n){return e[0]=t[0]+r[0]*n,e[1]=t[1]+r[1]*n,e[2]=t[2]+r[2]*n,e};X.distance=function(e,t){var r=t[0]-e[0],n=t[1]-e[1],i=t[2]-e[2];return Math.sqrt(r*r+n*n+i*i)};X.dist=X.distance;X.squaredDistance=function(e,t){var r=t[0]-e[0],n=t[1]-e[1],i=t[2]-e[2];return r*r+n*n+i*i};X.sqrDist=X.squaredDistance;X.length=function(e){var t=e[0],r=e[1],n=e[2];return Math.sqrt(t*t+r*r+n*n)};X.len=X.length;X.squaredLength=function(e){var t=e[0],r=e[1],n=e[2];return t*t+r*r+n*n};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],n=t[1],i=t[2],a=r*r+n*n+i*i;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 n=t[0],i=t[1],a=t[2],s=r[0],o=r[1],l=r[2];return e[0]=i*l-a*o,e[1]=a*s-n*l,e[2]=n*o-i*s,e};X.lerp=function(e,t,r,n){var i=t[0],a=t[1],s=t[2];return e[0]=i+n*(r[0]-i),e[1]=a+n*(r[1]-a),e[2]=s+n*(r[2]-s),e};X.random=function(e,t){t=t||1;var r=ir()*2*Math.PI,n=ir()*2-1,i=Math.sqrt(1-n*n)*t;return e[0]=Math.cos(r)*i,e[1]=Math.sin(r)*i,e[2]=n*t,e};X.transformMat4=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=r[3]*n+r[7]*i+r[11]*a+r[15];return s=s||1,e[0]=(r[0]*n+r[4]*i+r[8]*a+r[12])/s,e[1]=(r[1]*n+r[5]*i+r[9]*a+r[13])/s,e[2]=(r[2]*n+r[6]*i+r[10]*a+r[14])/s,e};X.transformMat3=function(e,t,r){var n=t[0],i=t[1],a=t[2];return e[0]=n*r[0]+i*r[3]+a*r[6],e[1]=n*r[1]+i*r[4]+a*r[7],e[2]=n*r[2]+i*r[5]+a*r[8],e};X.transformQuat=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=r[0],o=r[1],l=r[2],c=r[3],u=c*n+o*a-l*i,h=c*i+l*n-s*a,d=c*a+s*i-o*n,f=-s*n-o*i-l*a;return e[0]=u*c+f*-s+h*-l-d*-o,e[1]=h*c+f*-o+d*-s-u*-l,e[2]=d*c+f*-l+u*-o-h*-s,e};X.rotateX=function(e,t,r,n){var i=[],a=[];return i[0]=t[0]-r[0],i[1]=t[1]-r[1],i[2]=t[2]-r[2],a[0]=i[0],a[1]=i[1]*Math.cos(n)-i[2]*Math.sin(n),a[2]=i[1]*Math.sin(n)+i[2]*Math.cos(n),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,n){var i=[],a=[];return i[0]=t[0]-r[0],i[1]=t[1]-r[1],i[2]=t[2]-r[2],a[0]=i[2]*Math.sin(n)+i[0]*Math.cos(n),a[1]=i[1],a[2]=i[2]*Math.cos(n)-i[0]*Math.sin(n),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,n){var i=[],a=[];return i[0]=t[0]-r[0],i[1]=t[1]-r[1],i[2]=t[2]-r[2],a[0]=i[0]*Math.cos(n)-i[1]*Math.sin(n),a[1]=i[0]*Math.sin(n)+i[1]*Math.cos(n),a[2]=i[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,n,i,a,s){var o,l;for(r||(r=3),n||(n=0),i?l=Math.min(i*r+n,t.length):l=t.length,o=n;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]),n=X.fromValues(t[0],t[1],t[2]);X.normalize(r,r),X.normalize(n,n);var i=X.dot(r,n);return i>1?0:Math.acos(i)};const T=X;L.import(as);var de=C.create,oa={};function la(e){return e.material}function oc(e,t,r){return t.uniforms[r].value}function lc(e,t,r,n){return r!==n}function cc(e){return!0}function ca(){}var ua={float:A.FLOAT,byte:A.BYTE,ubyte:A.UNSIGNED_BYTE,short:A.SHORT,ushort:A.UNSIGNED_SHORT};function uc(e,t,r){this.availableAttributes=e,this.availableAttributeSymbols=t,this.indicesBuffer=r,this.vao=null}function hc(e){var t,r;this.bind=function(n){t||(t=Se.createCanvas(),t.width=t.height=1,t.getContext("2d"));var i=n.gl,a=!r;a&&(r=i.createTexture()),i.bindTexture(i.TEXTURE_2D,r),a&&i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t)},this.unbind=function(n){n.gl.bindTexture(n.gl.TEXTURE_2D,null)},this.isRenderable=function(){return!0}}var Nt=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=Se.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 Hl(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 ts(this),this._placeholderTexture=new hc},{resize:function(e,t){var r=this.canvas,n=this.devicePixelRatio;e!=null?(r.style&&(r.style.width=e+"px",r.style.height=t+"px"),r.width=e*n,r.height=t*n,this._width=e,this._height=t):(this._width=r.width/n,this._height=r.height/n),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,n,i){if(typeof e=="object"){var a=e;e=a.x,t=a.y,r=a.width,n=a.height,i=a.devicePixelRatio}i=i||this.devicePixelRatio,this.gl.viewport(e*i,t*i,r*i,n*i),this.viewport={x:e,y:t,width:r,height:n,devicePixelRatio:i}},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,n){var i=this.gl,a=this.clearColor;if(this.clearBit){i.colorMask(!0,!0,!0,!0),i.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,i.enable(i.SCISSOR_TEST),i.scissor(s.x*l,s.y*l,s.width*l,s.height*l)),i.clearColor(a[0],a[1],a[2],a[3]),i.clear(this.clearBit),o&&i.disable(i.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 u=c.opaque,h=c.transparent,d=e.material;e.trigger("beforerender",this,e,t,c),n?(this.renderPreZ(u,e,t),i.depthFunc(i.LEQUAL)):i.depthFunc(i.LESS);for(var f=de(),v=T.create(),_=0;_<h.length;_++){var m=h[_];C.multiplyAffine(f,t.viewMatrix.array,m.worldTransform.array),T.transformMat4(v,m.position.array,f),m.__depth=v[2]}this.renderPass(u,t,{getMaterial:function(p){return d||p.material},sortCompare:this.opaqueSortCompare}),this.renderPass(h,t,{getMaterial:function(p){return d||p.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(oa[e.__uid__])return;if(oa[e.__uid__]=!0,this.throwError)throw new Error(t);this.trigger("error",t)}},updatePrograms:function(e,t,r){var n=r&&r.getMaterial||la;t=t||null;for(var i=0;i<e.length;i++){var a=e[i],s=n.call(this,a);if(i>0){var o=e[i-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 u=this._programMgr.getProgram(a,s,t);this.validateProgram(u),a.__program=u}},renderPass:function(e,t,r){this.trigger("beforerenderpass",this,e,t,r),r=r||{},r.getMaterial=r.getMaterial||la,r.getUniform=r.getUniform||oc,r.isMaterialChanged=r.isMaterialChanged||lc,r.beforeRender=r.beforeRender||ca,r.afterRender=r.afterRender||ca;var n=r.ifRender||cc;this.updatePrograms(e,this._sceneRendering,r),r.sortCompare&&e.sort(r.sortCompare);var i=this.viewport,a=i.devicePixelRatio,s=[i.x*a,i.y*a,i.width*a,i.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]],u=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 h=this.gl,d=this._sceneRendering,f,v,_,m,p,y,g,x,E,S,R,w,M=null,F=0;F<e.length;F++){var b=e[F],U=b.worldTransform!=null,I;if(n(b)){U&&(I=b.isSkinnedMesh&&b.isSkinnedMesh()?b.offsetMatrix?b.offsetMatrix.array:fe.IDENTITY:b.worldTransform.array);var N=b.geometry,G=r.getMaterial.call(this,b),B=b.__program,Y=G.shader,O=N.__uid__+"-"+B.__uid__,he=O!==S;S=O,he&&M&&M.bindVertexArrayOES(null),U&&(C.copy(fe.WORLD,I),C.multiply(fe.WORLDVIEWPROJECTION,fe.VIEWPROJECTION,I),C.multiplyAffine(fe.WORLDVIEW,fe.VIEW,I),(Y.matrixSemantics.WORLDINVERSE||Y.matrixSemantics.WORLDINVERSETRANSPOSE)&&C.invert(fe.WORLDINVERSE,I),(Y.matrixSemantics.WORLDVIEWINVERSE||Y.matrixSemantics.WORLDVIEWINVERSETRANSPOSE)&&C.invert(fe.WORLDVIEWINVERSE,fe.WORLDVIEW),(Y.matrixSemantics.WORLDVIEWPROJECTIONINVERSE||Y.matrixSemantics.WORLDVIEWPROJECTIONINVERSETRANSPOSE)&&C.invert(fe.WORLDVIEWPROJECTIONINVERSE,fe.WORLDVIEWPROJECTION)),b.beforeRender&&b.beforeRender(this),r.beforeRender.call(this,b,G,f);var V=B!==v;V?(B.bind(this),B.setUniformOfSemantic(h,"VIEWPORT",s),B.setUniformOfSemantic(h,"WINDOW_SIZE",l),t&&(B.setUniformOfSemantic(h,"NEAR",t.near),B.setUniformOfSemantic(h,"FAR",t.far)),B.setUniformOfSemantic(h,"DEVICEPIXELRATIO",a),B.setUniformOfSemantic(h,"TIME",u),B.setUniformOfSemantic(h,"VIEWPORT_SIZE",c),d&&d.setLightUniforms(B,b.lightGroup,this)):B=v,(V||r.isMaterialChanged(b,_,G,f))&&(G.depthTest!==m&&(G.depthTest?h.enable(h.DEPTH_TEST):h.disable(h.DEPTH_TEST),m=G.depthTest),G.depthMask!==p&&(h.depthMask(G.depthMask),p=G.depthMask),G.transparent!==E&&(G.transparent?h.enable(h.BLEND):h.disable(h.BLEND),E=G.transparent),G.transparent&&(G.blend?G.blend(h):(h.blendEquationSeparate(h.FUNC_ADD,h.FUNC_ADD),h.blendFuncSeparate(h.SRC_ALPHA,h.ONE_MINUS_SRC_ALPHA,h.ONE,h.ONE_MINUS_SRC_ALPHA))),w=this._bindMaterial(b,G,B,_||null,f||null,v||null,r.getUniform),f=G);var xe=Y.matrixSemanticKeys;if(U)for(var ae=0;ae<xe.length;ae++){var ve=xe[ae],_e=Y.matrixSemantics[ve],Ie=fe[ve];if(_e.isTranspose){var Be=fe[_e.semanticNoTranspose];C.transpose(Ie,Be)}B.setUniform(h,_e.type,_e.symbol,Ie)}b.cullFace!==g&&(g=b.cullFace,h.cullFace(g)),b.frontFace!==x&&(x=b.frontFace,h.frontFace(x)),b.culling!==y&&(y=b.culling,y?h.enable(h.CULL_FACE):h.disable(h.CULL_FACE)),this._updateSkeleton(b,B,w),he&&(R=this._bindVAO(M,Y,N,B)),this._renderObject(b,R,B),r.afterRender(this,b),b.afterRender&&b.afterRender(this),v=B,_=b}}this.trigger("afterrenderpass",this,e,t,r)},getMaxJointNumber:function(){return this.maxJointNumber},_updateSkeleton:function(e,t,r){var n=this.gl,i=e.skeleton;if(i)if(i.update(),e.joints.length>this.getMaxJointNumber()){var a=i.getSubSkinMatricesTexture(e.__uid__,e.joints);t.useTextureSlot(this,a,r),t.setUniform(n,"1i","skinMatricesTexture",r),t.setUniform(n,"1f","skinMatricesTextureSize",a.width)}else{var s=i.getSubSkinMatrices(e.__uid__,e.joints);t.setUniformOfSemantic(n,"SKIN_MATRIX",s)}},_renderObject:function(e,t,r){var n=this.gl,i=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"),u=c&&i.indices instanceof Uint32Array,h=u?n.UNSIGNED_INT:n.UNSIGNED_SHORT;o?s.drawElementsInstancedANGLE(a,t.indicesBuffer.count,h,0,e.getInstanceCount()):n.drawElements(a,t.indicesBuffer.count,h,0)}else o?s.drawArraysInstancedANGLE(a,0,i.vertexCount,e.getInstanceCount()):n.drawArrays(a,0,i.vertexCount);if(o)for(var d=0;d<l.length;d++)n.disableVertexAttribArray(l[d])},_bindInstancedAttributes:function(e,t,r){for(var n=this.gl,i=e.getInstancedAttributesBuffers(this),a=[],s=0;s<i.length;s++){var o=i[s],l=t.getAttribLocation(n,o.symbol);if(!(l<0)){var c=ua[o.type]||n.FLOAT;n.enableVertexAttribArray(l),n.bindBuffer(n.ARRAY_BUFFER,o.buffer),n.vertexAttribPointer(l,o.size,c,!1,0,0),r.vertexAttribDivisorANGLE(l,o.divisor),a.push(l)}}return a},_bindMaterial:function(e,t,r,n,i,a,s){for(var o=this.gl,l=a===r,c=r.currentTextureSlot(),u=t.getEnabledUniforms(),h=t.getTextureUniforms(),d=this._placeholderTexture,f=0;f<h.length;f++){var v=h[f],_=s(e,t,v),m=t.uniforms[v].type;if(m==="t"&&_)_.__slot=-1;else if(m==="tv")for(var p=0;p<_.length;p++)_[p]&&(_[p].__slot=-1)}d.__slot=-1;for(var f=0;f<u.length;f++){var v=u[f],y=t.uniforms[v],_=s(e,t,v),m=y.type,g=m==="t";if(g&&(!_||!_.isRenderable())&&(_=d),i&&l){var x=s(n,i,v);if(g&&(!x||!x.isRenderable())&&(x=d),x===_){if(g)r.takeCurrentTextureSlot(this,null);else if(m==="tv"&&_)for(var p=0;p<_.length;p++)r.takeCurrentTextureSlot(this,null);continue}}if(_!=null)if(g)if(_.__slot<0){var E=r.currentTextureSlot(),S=r.setUniform(o,"1i",v,E);S&&(r.takeCurrentTextureSlot(this,_),_.__slot=E)}else r.setUniform(o,"1i",v,_.__slot);else if(Array.isArray(_)){if(_.length===0)continue;if(m==="tv"){if(!r.hasUniform(v))continue;for(var R=[],p=0;p<_.length;p++){var w=_[p];if(w.__slot<0){var E=r.currentTextureSlot();R.push(E),r.takeCurrentTextureSlot(this,w),w.__slot=E}else R.push(w.__slot)}r.setUniform(o,"1iv",v,R)}else r.setUniform(o,y.type,v,_)}else r.setUniform(o,y.type,v,_)}var M=r.currentTextureSlot();return r.resetTextureSlot(c),M},_bindVAO:function(e,t,r,n){var i=!r.dynamic,a=this.gl,s=this.__uid__+"-"+n.__uid__,o=r.__vaoCache[s];if(!o){var l=r.getBufferChunks(this);if(!l||!l.length)return;for(var c=l[0],u=c.attributeBuffers,x=c.indicesBuffer,g=[],h=[],d=0;d<u.length;d++){var f=u[d],v=f.name,_=f.semantic,m;if(_){var p=t.attributeSemantics[_];m=p&&p.symbol}else m=v;m&&n.attributes[m]&&(g.push(f),h.push(m))}o=new uc(g,h,x),i&&(r.__vaoCache[s]=o)}var y=!0;e&&i&&(o.vao==null?o.vao=e.createVertexArrayOES():y=!1,e.bindVertexArrayOES(o.vao));var g=o.availableAttributes,x=o.indicesBuffer;if(y){for(var E=n.enableAttributes(this,o.availableAttributeSymbols,e&&i&&o),d=0;d<g.length;d++){var S=E[d];if(S!==-1){var f=g[d],R=f.buffer,w=f.size,M=ua[f.type]||a.FLOAT;a.bindBuffer(a.ARRAY_BUFFER,R),a.vertexAttribPointer(S,w,M,!1,0,0)}}r.isUseIndices()&&a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,x.buffer)}return o},renderPreZ:function(e,t,r){var n=this.gl,i=this._prezMaterial||new wt({shader:new L(L.source("clay.prez.vertex"),L.source("clay.prez.fragment"))});this._prezMaterial=i,n.colorMask(!1,!1,!1,!1),n.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 i},sort:this.opaqueSortCompare}),n.colorMask(!0,!0,!0,!0),n.depthMask(!0)},disposeScene:function(e){this.disposeNode(e,!0,!0),e.dispose()},disposeNode:function(e,t,r){e.getParent()&&e.getParent().remove(e);var n={};e.traverse(function(i){var a=i.material;if(i.geometry&&t&&i.geometry.dispose(this),r&&a&&!n[a.__uid__]){for(var s=a.getTextureUniforms(),o=0;o<s.length;o++){var l=s[o],c=a.uniforms[l].value,u=a.uniforms[l].type;if(c){if(u==="t")c.dispose&&c.dispose(this);else if(u==="tv")for(var h=0;h<c.length;h++)c[h]&&c[h].dispose&&c[h].dispose(this)}}n[a.__uid__]=!0}i.dispose&&i.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 Ze),t=this._height-t;var n=this.viewport,i=r.array;return i[0]=(e-n.x)/n.width,i[0]=i[0]*2-1,i[1]=(t-n.y)/n.height,i[1]=i[1]*2-1,r}});Nt.opaqueSortCompare=Nt.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};Nt.transparentSortCompare=Nt.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()};Nt.COLOR_BUFFER_BIT=A.COLOR_BUFFER_BIT;Nt.DEPTH_BUFFER_BIT=A.DEPTH_BUFFER_BIT;Nt.STENCIL_BUFFER_BIT=A.STENCIL_BUFFER_BIT;const Er=Nt;var W=function(e,t,r){e=e||0,t=t||0,r=r||0,this.array=T.fromValues(e,t,r),this._dirty=!0};W.prototype={constructor:W,add:function(e){return T.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 T.copy(this.array,e.array),this._dirty=!0,this},cross:function(e,t){return T.cross(this.array,e.array,t.array),this._dirty=!0,this},dist:function(e){return T.dist(this.array,e.array)},distance:function(e){return T.distance(this.array,e.array)},div:function(e){return T.div(this.array,this.array,e.array),this._dirty=!0,this},divide:function(e){return T.divide(this.array,this.array,e.array),this._dirty=!0,this},dot:function(e){return T.dot(this.array,e.array)},len:function(){return T.len(this.array)},length:function(){return T.length(this.array)},lerp:function(e,t,r){return T.lerp(this.array,e.array,t.array,r),this._dirty=!0,this},min:function(e){return T.min(this.array,this.array,e.array),this._dirty=!0,this},max:function(e){return T.max(this.array,this.array,e.array),this._dirty=!0,this},mul:function(e){return T.mul(this.array,this.array,e.array),this._dirty=!0,this},multiply:function(e){return T.multiply(this.array,this.array,e.array),this._dirty=!0,this},negate:function(){return T.negate(this.array,this.array),this._dirty=!0,this},normalize:function(){return T.normalize(this.array,this.array),this._dirty=!0,this},random:function(e){return T.random(this.array,e),this._dirty=!0,this},scale:function(e){return T.scale(this.array,this.array,e),this._dirty=!0,this},scaleAndAdd:function(e,t){return T.scaleAndAdd(this.array,this.array,e.array,t),this._dirty=!0,this},sqrDist:function(e){return T.sqrDist(this.array,e.array)},squaredDistance:function(e){return T.squaredDistance(this.array,e.array)},sqrLen:function(){return T.sqrLen(this.array)},squaredLength:function(){return T.squaredLength(this.array)},sub:function(e){return T.sub(this.array,this.array,e.array),this._dirty=!0,this},subtract:function(e){return T.subtract(this.array,this.array,e.array),this._dirty=!0,this},transformMat3:function(e){return T.transformMat3(this.array,this.array,e.array),this._dirty=!0,this},transformMat4:function(e){return T.transformMat4(this.array,this.array,e.array),this._dirty=!0,this},transformQuat:function(e){return T.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 Vr=Object.defineProperty;if(Vr){var Ln=W.prototype;Vr(Ln,"x",{get:function(){return this.array[0]},set:function(e){this.array[0]=e,this._dirty=!0}}),Vr(Ln,"y",{get:function(){return this.array[1]},set:function(e){this.array[1]=e,this._dirty=!0}}),Vr(Ln,"z",{get:function(){return this.array[2]},set:function(e){this.array[2]=e,this._dirty=!0}})}W.add=function(e,t,r){return T.add(e.array,t.array,r.array),e._dirty=!0,e};W.set=function(e,t,r,n){T.set(e.array,t,r,n),e._dirty=!0};W.copy=function(e,t){return T.copy(e.array,t.array),e._dirty=!0,e};W.cross=function(e,t,r){return T.cross(e.array,t.array,r.array),e._dirty=!0,e};W.dist=function(e,t){return T.distance(e.array,t.array)};W.distance=W.dist;W.div=function(e,t,r){return T.divide(e.array,t.array,r.array),e._dirty=!0,e};W.divide=W.div;W.dot=function(e,t){return T.dot(e.array,t.array)};W.len=function(e){return T.length(e.array)};W.lerp=function(e,t,r,n){return T.lerp(e.array,t.array,r.array,n),e._dirty=!0,e};W.min=function(e,t,r){return T.min(e.array,t.array,r.array),e._dirty=!0,e};W.max=function(e,t,r){return T.max(e.array,t.array,r.array),e._dirty=!0,e};W.mul=function(e,t,r){return T.multiply(e.array,t.array,r.array),e._dirty=!0,e};W.multiply=W.mul;W.negate=function(e,t){return T.negate(e.array,t.array),e._dirty=!0,e};W.normalize=function(e,t){return T.normalize(e.array,t.array),e._dirty=!0,e};W.random=function(e,t){return T.random(e.array,t),e._dirty=!0,e};W.scale=function(e,t,r){return T.scale(e.array,t.array,r),e._dirty=!0,e};W.scaleAndAdd=function(e,t,r,n){return T.scaleAndAdd(e.array,t.array,r.array,n),e._dirty=!0,e};W.sqrDist=function(e,t){return T.sqrDist(e.array,t.array)};W.squaredDistance=W.sqrDist;W.sqrLen=function(e){return T.sqrLen(e.array)};W.squaredLength=W.sqrLen;W.sub=function(e,t,r){return T.subtract(e.array,t.array,r.array),e._dirty=!0,e};W.subtract=W.sub;W.transformMat3=function(e,t,r){return T.transformMat3(e.array,t.array,r.array),e._dirty=!0,e};W.transformMat4=function(e,t,r){return T.transformMat4(e.array,t.array,r.array),e._dirty=!0,e};W.transformQuat=function(e,t,r){return T.transformQuat(e.array,t.array,r.array),e._dirty=!0,e};function et(e,t,r){return e<t?t:e>r?r:e}var oe=Math.atan2,tt=Math.asin,Kt=Math.abs;W.eulerFromQuat=function(e,t,d){e._dirty=!0,t=t.array;var n=e.array,i=t[0],a=t[1],s=t[2],o=t[3],l=i*i,c=a*a,u=s*s,h=o*o,d=(d||"XYZ").toUpperCase();switch(d){case"XYZ":n[0]=oe(2*(i*o-a*s),h-l-c+u),n[1]=tt(et(2*(i*s+a*o),-1,1)),n[2]=oe(2*(s*o-i*a),h+l-c-u);break;case"YXZ":n[0]=tt(et(2*(i*o-a*s),-1,1)),n[1]=oe(2*(i*s+a*o),h-l-c+u),n[2]=oe(2*(i*a+s*o),h-l+c-u);break;case"ZXY":n[0]=tt(et(2*(i*o+a*s),-1,1)),n[1]=oe(2*(a*o-s*i),h-l-c+u),n[2]=oe(2*(s*o-i*a),h-l+c-u);break;case"ZYX":n[0]=oe(2*(i*o+s*a),h-l-c+u),n[1]=tt(et(2*(a*o-i*s),-1,1)),n[2]=oe(2*(i*a+s*o),h+l-c-u);break;case"YZX":n[0]=oe(2*(i*o-s*a),h-l+c-u),n[1]=oe(2*(a*o-i*s),h+l-c-u),n[2]=tt(et(2*(i*a+s*o),-1,1));break;case"XZY":n[0]=oe(2*(i*o+a*s),h-l+c-u),n[1]=oe(2*(i*s+a*o),h+l-c-u),n[2]=tt(et(2*(s*o-i*a),-1,1));break;default:console.warn("Unkown order: "+d)}return e};W.eulerFromMat3=function(e,t,v){var n=t.array,i=n[0],a=n[3],s=n[6],o=n[1],l=n[4],c=n[7],u=n[2],h=n[5],d=n[8],f=e.array,v=(v||"XYZ").toUpperCase();switch(v){case"XYZ":f[1]=tt(et(s,-1,1)),Kt(s)<.99999?(f[0]=oe(-c,d),f[2]=oe(-a,i)):(f[0]=oe(h,l),f[2]=0);break;case"YXZ":f[0]=tt(-et(c,-1,1)),Kt(c)<.99999?(f[1]=oe(s,d),f[2]=oe(o,l)):(f[1]=oe(-u,i),f[2]=0);break;case"ZXY":f[0]=tt(et(h,-1,1)),Kt(h)<.99999?(f[1]=oe(-u,d),f[2]=oe(-a,l)):(f[1]=0,f[2]=oe(o,i));break;case"ZYX":f[1]=tt(-et(u,-1,1)),Kt(u)<.99999?(f[0]=oe(h,d),f[2]=oe(o,i)):(f[0]=0,f[2]=oe(-a,l));break;case"YZX":f[2]=tt(et(o,-1,1)),Kt(o)<.99999?(f[0]=oe(-c,l),f[1]=oe(-u,i)):(f[0]=0,f[1]=oe(s,d));break;case"XZY":f[2]=tt(-et(a,-1,1)),Kt(a)<.99999?(f[0]=oe(h,l),f[1]=oe(s,i)):(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 Nn=1e-5,Jr=function(e,t){this.origin=e||new P,this.direction=t||new P};Jr.prototype={constructor:Jr,intersectPlane:function(e,t){var r=e.normal.array,n=e.distance,i=this.origin.array,a=this.direction.array,s=T.dot(r,a);if(s===0)return null;t||(t=new P);var o=(T.dot(r,i)-n)/s;return T.scaleAndAdd(t.array,i,a,-o),t._dirty=!0,t},mirrorAgainstPlane:function(e){var t=T.dot(e.normal.array,this.direction.array);T.scaleAndAdd(this.direction.array,this.direction.array,e.normal.array,-t*2),this.direction._dirty=!0},distanceToPoint:function(){var e=T.create();return function(t){T.sub(e,t,this.origin.array);var r=T.dot(e,this.direction.array);if(r<0)return T.distance(this.origin.array,t);var n=T.lenSquared(e);return Math.sqrt(n-r*r)}}(),intersectSphere:function(){var e=T.create();return function(t,r,n){var i=this.origin.array,a=this.direction.array;t=t.array,T.sub(e,t,i);var s=T.dot(e,a),o=T.squaredLength(e),l=o-s*s,c=r*r;if(!(l>c)){var u=Math.sqrt(c-l),h=s-u,d=s+u;return n||(n=new P),h<0?d<0?null:(T.scaleAndAdd(n.array,i,a,d),n):(T.scaleAndAdd(n.array,i,a,h),n)}}}(),intersectBoundingBox:function(e,t){var r=this.direction.array,n=this.origin.array,i=e.min.array,a=e.max.array,s=1/r[0],o=1/r[1],l=1/r[2],c,u,h,d,f,v;if(s>=0?(c=(i[0]-n[0])*s,u=(a[0]-n[0])*s):(u=(i[0]-n[0])*s,c=(a[0]-n[0])*s),o>=0?(h=(i[1]-n[1])*o,d=(a[1]-n[1])*o):(d=(i[1]-n[1])*o,h=(a[1]-n[1])*o),c>d||h>u||((h>c||c!==c)&&(c=h),(d<u||u!==u)&&(u=d),l>=0?(f=(i[2]-n[2])*l,v=(a[2]-n[2])*l):(v=(i[2]-n[2])*l,f=(a[2]-n[2])*l),c>v||f>u)||((f>c||c!==c)&&(c=f),(v<u||u!==u)&&(u=v),u<0))return null;var _=c>=0?c:u;return t||(t=new P),T.scaleAndAdd(t.array,n,r,_),t},intersectTriangle:function(){var e=T.create(),t=T.create(),r=T.create(),n=T.create();return function(i,a,s,o,l,c){var u=this.direction.array,h=this.origin.array;i=i.array,a=a.array,s=s.array,T.sub(e,a,i),T.sub(t,s,i),T.cross(n,t,u);var d=T.dot(e,n);if(o){if(d>-Nn)return null}else if(d>-Nn&&d<Nn)return null;T.sub(r,h,i);var f=T.dot(n,r)/d;if(f<0||f>1)return null;T.cross(n,e,r);var v=T.dot(u,n)/d;if(v<0||v>1||f+v>1)return null;T.cross(n,e,t);var _=-T.dot(r,n)/d;return _<0?null:(l||(l=new P),c&&P.set(c,1-f-v,f,v),T.scaleAndAdd(l.array,h,u,_),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 Jr;return e.copy(this),e}};const sn=Jr;var K={};K.create=function(){var e=new Oe(4);return e[0]=0,e[1]=0,e[2]=0,e[3]=0,e};K.clone=function(e){var t=new Oe(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,n){var i=new Oe(4);return i[0]=e,i[1]=t,i[2]=r,i[3]=n,i};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,n,i){return e[0]=t,e[1]=r,e[2]=n,e[3]=i,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,n){return e[0]=t[0]+r[0]*n,e[1]=t[1]+r[1]*n,e[2]=t[2]+r[2]*n,e[3]=t[3]+r[3]*n,e};K.distance=function(e,t){var r=t[0]-e[0],n=t[1]-e[1],i=t[2]-e[2],a=t[3]-e[3];return Math.sqrt(r*r+n*n+i*i+a*a)};K.dist=K.distance;K.squaredDistance=function(e,t){var r=t[0]-e[0],n=t[1]-e[1],i=t[2]-e[2],a=t[3]-e[3];return r*r+n*n+i*i+a*a};K.sqrDist=K.squaredDistance;K.length=function(e){var t=e[0],r=e[1],n=e[2],i=e[3];return Math.sqrt(t*t+r*r+n*n+i*i)};K.len=K.length;K.squaredLength=function(e){var t=e[0],r=e[1],n=e[2],i=e[3];return t*t+r*r+n*n+i*i};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],n=t[1],i=t[2],a=t[3],s=r*r+n*n+i*i+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,n){var i=t[0],a=t[1],s=t[2],o=t[3];return e[0]=i+n*(r[0]-i),e[1]=a+n*(r[1]-a),e[2]=s+n*(r[2]-s),e[3]=o+n*(r[3]-o),e};K.random=function(e,t){return t=t||1,e[0]=ir(),e[1]=ir(),e[2]=ir(),e[3]=ir(),K.normalize(e,e),K.scale(e,e,t),e};K.transformMat4=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3];return e[0]=r[0]*n+r[4]*i+r[8]*a+r[12]*s,e[1]=r[1]*n+r[5]*i+r[9]*a+r[13]*s,e[2]=r[2]*n+r[6]*i+r[10]*a+r[14]*s,e[3]=r[3]*n+r[7]*i+r[11]*a+r[15]*s,e};K.transformQuat=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=r[0],o=r[1],l=r[2],c=r[3],u=c*n+o*a-l*i,h=c*i+l*n-s*a,d=c*a+s*i-o*n,f=-s*n-o*i-l*a;return e[0]=u*c+f*-s+h*-l-d*-o,e[1]=h*c+f*-o+d*-s-u*-l,e[2]=d*c+f*-l+u*-o-h*-s,e};K.forEach=function(){var e=K.create();return function(t,r,n,i,a,s){var o,l;for(r||(r=4),n||(n=0),i?l=Math.min(i*r+n,t.length):l=t.length,o=n;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 Oe(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 Oe(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],n=t[2],i=t[5];e[1]=t[3],e[2]=t[6],e[3]=r,e[5]=t[7],e[6]=n,e[7]=i}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],n=t[1],i=t[2],a=t[3],s=t[4],o=t[5],l=t[6],c=t[7],u=t[8],h=u*s-o*c,d=-u*a+o*l,f=c*a-s*l,v=r*h+n*d+i*f;return v?(v=1/v,e[0]=h*v,e[1]=(-u*n+i*c)*v,e[2]=(o*n-i*s)*v,e[3]=d*v,e[4]=(u*r-i*l)*v,e[5]=(-o*r+i*a)*v,e[6]=f*v,e[7]=(-c*r+n*l)*v,e[8]=(s*r-n*a)*v,e):null};Ce.adjoint=function(e,t){var r=t[0],n=t[1],i=t[2],a=t[3],s=t[4],o=t[5],l=t[6],c=t[7],u=t[8];return e[0]=s*u-o*c,e[1]=i*c-n*u,e[2]=n*o-i*s,e[3]=o*l-a*u,e[4]=r*u-i*l,e[5]=i*a-r*o,e[6]=a*c-s*l,e[7]=n*l-r*c,e[8]=r*s-n*a,e};Ce.determinant=function(e){var t=e[0],r=e[1],n=e[2],i=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*i+s*o)+n*(l*i-a*o)};Ce.multiply=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=t[6],u=t[7],h=t[8],d=r[0],f=r[1],v=r[2],_=r[3],m=r[4],p=r[5],y=r[6],g=r[7],x=r[8];return e[0]=d*n+f*s+v*c,e[1]=d*i+f*o+v*u,e[2]=d*a+f*l+v*h,e[3]=_*n+m*s+p*c,e[4]=_*i+m*o+p*u,e[5]=_*a+m*l+p*h,e[6]=y*n+g*s+x*c,e[7]=y*i+g*o+x*u,e[8]=y*a+g*l+x*h,e};Ce.mul=Ce.multiply;Ce.translate=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=t[6],u=t[7],h=t[8],d=r[0],f=r[1];return e[0]=n,e[1]=i,e[2]=a,e[3]=s,e[4]=o,e[5]=l,e[6]=d*n+f*s+c,e[7]=d*i+f*o+u,e[8]=d*a+f*l+h,e};Ce.rotate=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=t[6],u=t[7],h=t[8],d=Math.sin(r),f=Math.cos(r);return e[0]=f*n+d*s,e[1]=f*i+d*o,e[2]=f*a+d*l,e[3]=f*s-d*n,e[4]=f*o-d*i,e[5]=f*l-d*a,e[6]=c,e[7]=u,e[8]=h,e};Ce.scale=function(e,t,r){var n=r[0],i=r[1];return e[0]=n*t[0],e[1]=n*t[1],e[2]=n*t[2],e[3]=i*t[3],e[4]=i*t[4],e[5]=i*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],n=t[1],i=t[2],a=t[3],s=r+r,o=n+n,l=i+i,c=r*s,u=n*s,h=n*o,d=i*s,f=i*o,v=i*l,_=a*s,m=a*o,p=a*l;return e[0]=1-h-v,e[3]=u-p,e[6]=d+m,e[1]=u+p,e[4]=1-c-v,e[7]=f-_,e[2]=d-m,e[5]=f+_,e[8]=1-c-h,e};Ce.normalFromMat4=function(e,t){var r=t[0],n=t[1],i=t[2],a=t[3],s=t[4],o=t[5],l=t[6],c=t[7],u=t[8],h=t[9],d=t[10],f=t[11],v=t[12],_=t[13],m=t[14],p=t[15],y=r*o-n*s,g=r*l-i*s,x=r*c-a*s,E=n*l-i*o,S=n*c-a*o,R=i*c-a*l,w=u*_-h*v,M=u*m-d*v,F=u*p-f*v,b=h*m-d*_,U=h*p-f*_,I=d*p-f*m,N=y*I-g*U+x*b+E*F-S*M+R*w;return N?(N=1/N,e[0]=(o*I-l*U+c*b)*N,e[1]=(l*F-s*I-c*M)*N,e[2]=(s*U-o*F+c*w)*N,e[3]=(i*U-n*I-a*b)*N,e[4]=(r*I-i*F+a*M)*N,e[5]=(n*F-r*U-a*w)*N,e[6]=(_*R-m*S+p*E)*N,e[7]=(m*x-v*R-p*g)*N,e[8]=(v*S-_*x+p*y)*N,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 ne={};ne.create=function(){var e=new Oe(4);return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e};ne.rotationTo=function(){var e=T.create(),t=T.fromValues(1,0,0),r=T.fromValues(0,1,0);return function(n,i,a){var s=T.dot(i,a);return s<-.999999?(T.cross(e,t,i),T.length(e)<1e-6&&T.cross(e,r,i),T.normalize(e,e),ne.setAxisAngle(n,e,Math.PI),n):s>.999999?(n[0]=0,n[1]=0,n[2]=0,n[3]=1,n):(T.cross(e,i,a),n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=1+s,ne.normalize(n,n))}}();ne.setAxes=function(){var e=ee.create();return function(t,r,n,i){return e[0]=n[0],e[3]=n[1],e[6]=n[2],e[1]=i[0],e[4]=i[1],e[7]=i[2],e[2]=-r[0],e[5]=-r[1],e[8]=-r[2],ne.normalize(t,ne.fromMat3(t,e))}}();ne.clone=D.clone;ne.fromValues=D.fromValues;ne.copy=D.copy;ne.set=D.set;ne.identity=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e};ne.setAxisAngle=function(e,t,r){r=r*.5;var n=Math.sin(r);return e[0]=n*t[0],e[1]=n*t[1],e[2]=n*t[2],e[3]=Math.cos(r),e};ne.add=D.add;ne.multiply=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=r[0],l=r[1],c=r[2],u=r[3];return e[0]=n*u+s*o+i*c-a*l,e[1]=i*u+s*l+a*o-n*c,e[2]=a*u+s*c+n*l-i*o,e[3]=s*u-n*o-i*l-a*c,e};ne.mul=ne.multiply;ne.scale=D.scale;ne.rotateX=function(e,t,r){r*=.5;var n=t[0],i=t[1],a=t[2],s=t[3],o=Math.sin(r),l=Math.cos(r);return e[0]=n*l+s*o,e[1]=i*l+a*o,e[2]=a*l-i*o,e[3]=s*l-n*o,e};ne.rotateY=function(e,t,r){r*=.5;var n=t[0],i=t[1],a=t[2],s=t[3],o=Math.sin(r),l=Math.cos(r);return e[0]=n*l-a*o,e[1]=i*l+s*o,e[2]=a*l+n*o,e[3]=s*l-i*o,e};ne.rotateZ=function(e,t,r){r*=.5;var n=t[0],i=t[1],a=t[2],s=t[3],o=Math.sin(r),l=Math.cos(r);return e[0]=n*l+i*o,e[1]=i*l-n*o,e[2]=a*l+s*o,e[3]=s*l-a*o,e};ne.calculateW=function(e,t){var r=t[0],n=t[1],i=t[2];return e[0]=r,e[1]=n,e[2]=i,e[3]=Math.sqrt(Math.abs(1-r*r-n*n-i*i)),e};ne.dot=D.dot;ne.lerp=D.lerp;ne.slerp=function(e,t,r,n){var i=t[0],a=t[1],s=t[2],o=t[3],l=r[0],c=r[1],u=r[2],h=r[3],d,f,v,_,m;return f=i*l+a*c+s*u+o*h,f<0&&(f=-f,l=-l,c=-c,u=-u,h=-h),1-f>1e-6?(d=Math.acos(f),v=Math.sin(d),_=Math.sin((1-n)*d)/v,m=Math.sin(n*d)/v):(_=1-n,m=n),e[0]=_*i+m*l,e[1]=_*a+m*c,e[2]=_*s+m*u,e[3]=_*o+m*h,e};ne.invert=function(e,t){var r=t[0],n=t[1],i=t[2],a=t[3],s=r*r+n*n+i*i+a*a,o=s?1/s:0;return e[0]=-r*o,e[1]=-n*o,e[2]=-i*o,e[3]=a*o,e};ne.conjugate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e};ne.length=D.length;ne.len=ne.length;ne.squaredLength=D.squaredLength;ne.sqrLen=ne.squaredLength;ne.normalize=D.normalize;ne.fromMat3=function(e,t){var r=t[0]+t[4]+t[8],n;if(r>0)n=Math.sqrt(r+1),e[3]=.5*n,n=.5/n,e[0]=(t[5]-t[7])*n,e[1]=(t[6]-t[2])*n,e[2]=(t[1]-t[3])*n;else{var i=0;t[4]>t[0]&&(i=1),t[8]>t[i*3+i]&&(i=2);var a=(i+1)%3,s=(i+2)%3;n=Math.sqrt(t[i*3+i]-t[a*3+a]-t[s*3+s]+1),e[i]=.5*n,n=.5/n,e[3]=(t[a*3+s]-t[s*3+a])*n,e[a]=(t[a*3+i]+t[i*3+a])*n,e[s]=(t[s*3+i]+t[i*3+s])*n}return e};const j=ne;var ue=function(){this._axisX=new P,this._axisY=new P,this._axisZ=new P,this.array=C.create(),this._dirty=!0};ue.prototype={constructor:ue,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 ue().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 ue.fromMat2d(this,e),this},frustum:function(e,t,r,n,i,a){return C.frustum(this.array,e,t,r,n,i,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,n,i,a){return C.ortho(this.array,e,t,r,n,i,a),this._dirty=!0,this},perspective:function(e,t,r,n){return C.perspective(this.array,e,t,r,n),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=T.create(),t=T.create(),r=T.create(),n=ee.create();return function(i,a,s){var o=this.array;T.set(e,o[0],o[1],o[2]),T.set(t,o[4],o[5],o[6]),T.set(r,o[8],o[9],o[10]);var l=T.length(e),c=T.length(t),u=T.length(r),h=this.determinant();h<0&&(l=-l),i&&i.set(l,c,u),s.set(o[12],o[13],o[14]),ee.fromMat4(n,o),n[0]/=l,n[1]/=l,n[2]/=l,n[3]/=c,n[4]/=c,n[5]/=c,n[6]/=u,n[7]/=u,n[8]/=u,j.fromMat3(a.array,n),j.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 kr=Object.defineProperty;if(kr){var Pn=ue.prototype;kr(Pn,"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}}),kr(Pn,"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}}),kr(Pn,"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}})}ue.adjoint=function(e,t){return C.adjoint(e.array,t.array),e._dirty=!0,e};ue.copy=function(e,t){return C.copy(e.array,t.array),e._dirty=!0,e};ue.determinant=function(e){return C.determinant(e.array)};ue.identity=function(e){return C.identity(e.array),e._dirty=!0,e};ue.ortho=function(e,t,r,n,i,a,s){return C.ortho(e.array,t,r,n,i,a,s),e._dirty=!0,e};ue.perspective=function(e,t,r,n,i){return C.perspective(e.array,t,r,n,i),e._dirty=!0,e};ue.lookAt=function(e,t,r,n){return C.lookAt(e.array,t.array,r.array,n.array),e._dirty=!0,e};ue.invert=function(e,t){return C.invert(e.array,t.array),e._dirty=!0,e};ue.mul=function(e,t,r){return C.mul(e.array,t.array,r.array),e._dirty=!0,e};ue.multiply=ue.mul;ue.fromQuat=function(e,t){return C.fromQuat(e.array,t.array),e._dirty=!0,e};ue.fromRotationTranslation=function(e,t,r){return C.fromRotationTranslation(e.array,t.array,r.array),e._dirty=!0,e};ue.fromMat2d=function(n,r){n._dirty=!0;var r=r.array,n=n.array;return n[0]=r[0],n[4]=r[2],n[12]=r[4],n[1]=r[1],n[5]=r[3],n[13]=r[5],n};ue.rotate=function(e,t,r,n){return C.rotate(e.array,t.array,r,n.array),e._dirty=!0,e};ue.rotateX=function(e,t,r){return C.rotateX(e.array,t.array,r),e._dirty=!0,e};ue.rotateY=function(e,t,r){return C.rotateY(e.array,t.array,r),e._dirty=!0,e};ue.rotateZ=function(e,t,r){return C.rotateZ(e.array,t.array,r),e._dirty=!0,e};ue.scale=function(e,t,r){return C.scale(e.array,t.array,r.array),e._dirty=!0,e};ue.transpose=function(e,t){return C.transpose(e.array,t.array),e._dirty=!0,e};ue.translate=function(e,t,r){return C.translate(e.array,t.array,r.array),e._dirty=!0,e};const z=ue;var se=function(e,t,r,n){e=e||0,t=t||0,r=r||0,n=n===void 0?1:n,this.array=j.fromValues(e,t,r,n),this._dirty=!0};se.prototype={constructor:se,add:function(e){return j.add(this.array,this.array,e.array),this._dirty=!0,this},calculateW:function(){return j.calculateW(this.array,this.array),this._dirty=!0,this},set:function(e,t,r,n){return this.array[0]=e,this.array[1]=t,this.array[2]=r,this.array[3]=n,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 j.conjugate(this.array,this.array),this._dirty=!0,this},copy:function(e){return j.copy(this.array,e.array),this._dirty=!0,this},dot:function(e){return j.dot(this.array,e.array)},fromMat3:function(e){return j.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),j.fromMat3(this.array,e),this._dirty=!0,this}}(),identity:function(){return j.identity(this.array),this._dirty=!0,this},invert:function(){return j.invert(this.array,this.array),this._dirty=!0,this},len:function(){return j.len(this.array)},length:function(){return j.length(this.array)},lerp:function(e,t,r){return j.lerp(this.array,e.array,t.array,r),this._dirty=!0,this},mul:function(e){return j.mul(this.array,this.array,e.array),this._dirty=!0,this},mulLeft:function(e){return j.multiply(this.array,e.array,this.array),this._dirty=!0,this},multiply:function(e){return j.multiply(this.array,this.array,e.array),this._dirty=!0,this},multiplyLeft:function(e){return j.multiply(this.array,e.array,this.array),this._dirty=!0,this},normalize:function(){return j.normalize(this.array,this.array),this._dirty=!0,this},rotateX:function(e){return j.rotateX(this.array,this.array,e),this._dirty=!0,this},rotateY:function(e){return j.rotateY(this.array,this.array,e),this._dirty=!0,this},rotateZ:function(e){return j.rotateZ(this.array,this.array,e),this._dirty=!0,this},rotationTo:function(e,t){return j.rotationTo(this.array,e.array,t.array),this._dirty=!0,this},setAxes:function(e,t,r){return j.setAxes(this.array,e.array,t.array,r.array),this._dirty=!0,this},setAxisAngle:function(e,t){return j.setAxisAngle(this.array,e.array,t),this._dirty=!0,this},slerp:function(e,t,r){return j.slerp(this.array,e.array,t.array,r),this._dirty=!0,this},sqrLen:function(){return j.sqrLen(this.array)},squaredLength:function(){return j.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 dr=Object.defineProperty;if(dr){var Wr=se.prototype;dr(Wr,"x",{get:function(){return this.array[0]},set:function(e){this.array[0]=e,this._dirty=!0}}),dr(Wr,"y",{get:function(){return this.array[1]},set:function(e){this.array[1]=e,this._dirty=!0}}),dr(Wr,"z",{get:function(){return this.array[2]},set:function(e){this.array[2]=e,this._dirty=!0}}),dr(Wr,"w",{get:function(){return this.array[3]},set:function(e){this.array[3]=e,this._dirty=!0}})}se.add=function(e,t,r){return j.add(e.array,t.array,r.array),e._dirty=!0,e};se.set=function(e,t,r,n,i){j.set(e.array,t,r,n,i),e._dirty=!0};se.copy=function(e,t){return j.copy(e.array,t.array),e._dirty=!0,e};se.calculateW=function(e,t){return j.calculateW(e.array,t.array),e._dirty=!0,e};se.conjugate=function(e,t){return j.conjugate(e.array,t.array),e._dirty=!0,e};se.identity=function(e){return j.identity(e.array),e._dirty=!0,e};se.invert=function(e,t){return j.invert(e.array,t.array),e._dirty=!0,e};se.dot=function(e,t){return j.dot(e.array,t.array)};se.len=function(e){return j.length(e.array)};se.lerp=function(e,t,r,n){return j.lerp(e.array,t.array,r.array,n),e._dirty=!0,e};se.slerp=function(e,t,r,n){return j.slerp(e.array,t.array,r.array,n),e._dirty=!0,e};se.mul=function(e,t,r){return j.multiply(e.array,t.array,r.array),e._dirty=!0,e};se.multiply=se.mul;se.rotateX=function(e,t,r){return j.rotateX(e.array,t.array,r),e._dirty=!0,e};se.rotateY=function(e,t,r){return j.rotateY(e.array,t.array,r),e._dirty=!0,e};se.rotateZ=function(e,t,r){return j.rotateZ(e.array,t.array,r),e._dirty=!0,e};se.setAxisAngle=function(e,t,r){return j.setAxisAngle(e.array,t.array,r),e._dirty=!0,e};se.normalize=function(e,t){return j.normalize(e.array,t.array),e._dirty=!0,e};se.sqrLen=function(e){return j.sqrLen(e.array)};se.squaredLength=se.sqrLen;se.fromMat3=function(e,t){return j.fromMat3(e.array,t.array),e._dirty=!0,e};se.setAxes=function(e,t,r,n){return j.setAxes(e.array,t.array,r.array,n.array),e._dirty=!0,e};se.rotationTo=function(e,t,r){return j.rotationTo(e.array,t.array,r.array),e._dirty=!0,e};se.fromEuler=function(e,t,u){e._dirty=!0,t=t.array;var n=e.array,i=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),u=(u||"XYZ").toUpperCase();switch(u){case"XYZ":n[0]=o*a*s+i*l*c,n[1]=i*l*s-o*a*c,n[2]=i*a*c+o*l*s,n[3]=i*a*s-o*l*c;break;case"YXZ":n[0]=o*a*s+i*l*c,n[1]=i*l*s-o*a*c,n[2]=i*a*c-o*l*s,n[3]=i*a*s+o*l*c;break;case"ZXY":n[0]=o*a*s-i*l*c,n[1]=i*l*s+o*a*c,n[2]=i*a*c+o*l*s,n[3]=i*a*s-o*l*c;break;case"ZYX":n[0]=o*a*s-i*l*c,n[1]=i*l*s+o*a*c,n[2]=i*a*c-o*l*s,n[3]=i*a*s+o*l*c;break;case"YZX":n[0]=o*a*s+i*l*c,n[1]=i*l*s+o*a*c,n[2]=i*a*c-o*l*s,n[3]=i*a*s-o*l*c;break;case"XZY":n[0]=o*a*s-i*l*c,n[1]=i*l*s-o*a*c,n[2]=i*a*c+o*l*s,n[3]=i*a*s+o*l*c;break}};const ss=se;var Rt=T.set,Xr=T.copy,en=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};en.prototype={constructor:en,updateFromVertices:function(e){if(e.length>0){var t=this.min,r=this.max,n=t.array,i=r.array;Xr(n,e[0]),Xr(i,e[0]);for(var a=1;a<e.length;a++){var s=e[a];s[0]<n[0]&&(n[0]=s[0]),s[1]<n[1]&&(n[1]=s[1]),s[2]<n[2]&&(n[2]=s[2]),s[0]>i[0]&&(i[0]=s[0]),s[1]>i[1]&&(i[1]=s[1]),s[2]>i[2]&&(i[2]=s[2])}t._dirty=!0,r._dirty=!0}},union:function(e){var t=this.min,r=this.max;return T.min(t.array,t.array,e.min.array),T.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 T.max(t.array,t.array,e.min.array),T.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,n=e.min.array,i=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])},containBoundingBox:function(e){var t=this.min.array,r=this.max.array,n=e.min.array,i=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]},containPoint:function(e){var t=this.min.array,r=this.max.array,n=e.array;return t[0]<=n[0]&&t[1]<=n[1]&&t[2]<=n[2]&&r[0]>=n[0]&&r[1]>=n[1]&&r[2]>=n[2]},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=T.create(),t=T.create(),r=T.create(),n=T.create(),i=T.create(),a=T.create();return function(s,o){var l=s.min.array,c=s.max.array,u=o.array;return e[0]=u[0]*l[0],e[1]=u[1]*l[0],e[2]=u[2]*l[0],t[0]=u[0]*c[0],t[1]=u[1]*c[0],t[2]=u[2]*c[0],r[0]=u[4]*l[1],r[1]=u[5]*l[1],r[2]=u[6]*l[1],n[0]=u[4]*c[1],n[1]=u[5]*c[1],n[2]=u[6]*c[1],i[0]=u[8]*l[2],i[1]=u[9]*l[2],i[2]=u[10]*l[2],a[0]=u[8]*c[2],a[1]=u[9]*c[2],a[2]=u[10]*c[2],l=this.min.array,c=this.max.array,l[0]=Math.min(e[0],t[0])+Math.min(r[0],n[0])+Math.min(i[0],a[0])+u[12],l[1]=Math.min(e[1],t[1])+Math.min(r[1],n[1])+Math.min(i[1],a[1])+u[13],l[2]=Math.min(e[2],t[2])+Math.min(r[2],n[2])+Math.min(i[2],a[2])+u[14],c[0]=Math.max(e[0],t[0])+Math.max(r[0],n[0])+Math.max(i[0],a[0])+u[12],c[1]=Math.max(e[1],t[1])+Math.max(r[1],n[1])+Math.max(i[1],a[1])+u[13],c[2]=Math.max(e[2],t[2])+Math.max(r[2],n[2])+Math.max(i[2],a[2])+u[14],this.min._dirty=!0,this.max._dirty=!0,this}}(),applyProjection:function(e){var t=this.min.array,r=this.max.array,n=e.array,i=t[0],a=t[1],s=t[2],o=r[0],l=r[1],c=t[2],u=r[0],h=r[1],d=r[2];if(n[15]===1)t[0]=n[0]*i+n[12],t[1]=n[5]*a+n[13],r[2]=n[10]*s+n[14],r[0]=n[0]*u+n[12],r[1]=n[5]*h+n[13],t[2]=n[10]*d+n[14];else{var f=-1/s;t[0]=n[0]*i*f,t[1]=n[5]*a*f,r[2]=(n[10]*s+n[14])*f,f=-1/c,r[0]=n[0]*o*f,r[1]=n[5]*l*f,f=-1/d,t[2]=(n[10]*d+n[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]=T.fromValues(0,0,0);this.vertices=e}var r=this.min.array,n=this.max.array;return Rt(e[0],r[0],r[1],r[2]),Rt(e[1],r[0],n[1],r[2]),Rt(e[2],n[0],r[1],r[2]),Rt(e[3],n[0],n[1],r[2]),Rt(e[4],r[0],r[1],n[2]),Rt(e[5],r[0],n[1],n[2]),Rt(e[6],n[0],r[1],n[2]),Rt(e[7],n[0],n[1],n[2]),this},copy:function(e){var t=this.min,r=this.max;return Xr(t.array,e.min.array),Xr(r.array,e.max.array),t._dirty=!0,r._dirty=!0,this},clone:function(){var e=new en;return e.copy(this),e}};const Ve=en;var fc=0,dc=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")+"_"+fc++),this.position||(this.position=new P),this.rotation||(this.rotation=new ss),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 n=t[r];if(n.name===e)return n;var i=n.getDescendantByName(e);if(i)return i}},queryNode:function(e){if(e){for(var t=e.split("/"),r=this,n=0;n<t.length;n++){var i=t[n];if(i){for(var a=!1,s=r._children,o=0;o<s.length;o++){var l=s[o];if(l.name===i){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,n=0,i=r.length;n<i;n++)r[n].traverse(e,t)},eachChild:function(e,t){for(var r=this._children,n=0,i=r.length;n<i;n++){var a=r[n];e.call(t,a,n)}},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,n=this.worldTransform;this._parent?(C.invert(e,this._parent.worldTransform.array),C.multiply(r.array,e,n.array)):C.copy(r.array,n.array);var i=t?null:this.scale;r.decomposeMatrix(i,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 n=this.localTransform.array;C.fromRotationTranslation(n,t.array,e.array),C.scale(n,n,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,n=t.length;r<n;r++)t[r].update(e)},getBoundingBox:function(){function e(i){return!i.invisible&&i.geometry}var t=new Ve,r=new z,n=new z;return function(i,a){return a=a||new Ve,this._parent?z.invert(n,this._parent.worldTransform):z.identity(n),this.traverse(function(s){s.geometry&&s.geometry.boundingBox&&(t.copy(s.geometry.boundingBox),z.multiply(r,n,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,n,i){e.copy(this.position).subtract(r);var a=this.localTransform;a.identity(),a.translate(r),a.rotate(i,n),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=dc;var Qe=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 n=e[r];t[n]!==this[n]&&(t[n]=this[n])}return t}}()});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 ti=Qe;var yi=qe.extend({scene:null,camera:null,renderer:null},function(){this._ray=new sn,this._ndc=new Ze},{pick:function(e,t,r){var n=this.pickAll(e,t,[],r);return n[0]||null},pickAll:function(e,t,r,n){return this.renderer.screenToNDC(e,t,this._ndc),this.camera.castRay(this._ndc,this._ray),r=r||[],this._intersectNode(this.scene,r,n||!1),r.sort(this._intersectionCompareFunc),r},_intersectNode:function(e,t,r){e instanceof ti&&e.isRenderable()&&(!e.ignorePicking||r)&&(e.mode===A.TRIANGLES&&e.geometry.isUseIndices()||e.geometry.pickByRay||e.geometry.pick)&&this._intersectRenderable(e,t);for(var n=0;n<e._children.length;n++)this._intersectNode(e._children[n],t,r)},_intersectRenderable:function(){var e=new P,t=new P,r=new P,n=new sn,i=new z;return function(a,s){var o=a.isSkinnedMesh();n.copy(this._ray),z.invert(i,a.worldTransform),o||n.applyTransform(i);var l=a.geometry,c=o?a.skeleton.boundingBox:l.boundingBox;if(!(c&&!n.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(n,a,s);return}var u=a.cullFace===A.BACK&&a.frontFace===A.CCW||a.cullFace===A.FRONT&&a.frontFace===A.CW,h,d=l.indices,f=l.attributes.position,v=l.attributes.weight,_=l.attributes.joint,m,p=[];if(!(!f||!f.value||!d)){if(o){m=a.skeleton.getSubSkinMatrices(a.__uid__,a.joints);for(var y=0;y<a.joints.length;y++){p[y]=p[y]||[];for(var g=0;g<16;g++)p[y][g]=m[y*16+g]}var x=[],E=[],S=[],R=[],w=[],M=l.attributes.skinnedPosition;(!M||!M.value)&&(l.createAttribute("skinnedPosition","f",3),M=l.attributes.skinnedPosition,M.init(l.vertexCount));for(var y=0;y<l.vertexCount;y++){f.get(y,x),v.get(y,E),_.get(y,S),E[3]=1-E[0]-E[1]-E[2],T.set(R,0,0,0);for(var g=0;g<4;g++)S[g]>=0&&E[g]>1e-4&&(T.transformMat4(w,x,p[S[g]]),T.scaleAndAdd(R,R,w,E[g]));M.set(y,R)}}for(var y=0;y<d.length;y+=3){var F=d[y],b=d[y+1],U=d[y+2],I=o?l.attributes.skinnedPosition:f;if(I.get(F,e.array),I.get(b,t.array),I.get(U,r.array),u?h=n.intersectTriangle(e,t,r,a.culling):h=n.intersectTriangle(e,r,t,a.culling),h){var N=new P;o?P.copy(N,h):P.transformMat4(N,h,a.worldTransform),s.push(new yi.Intersection(h,N,a,[F,b,U],y/3,P.dist(N,this._ray.origin)))}}}}}}(),_intersectionCompareFunc:function(e,t){return e.distance-t.distance}});yi.Intersection=function(e,t,r,n,i,a){this.point=e,this.pointWorld=t,this.target=r,this.triangle=n,this.triangleIndex=i,this.distance=a};const vc=yi;var vr="__dt__",on=function(){this._contextId=0,this._caches=[],this._context={}};on.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=vr+e;this.put(t,!0)},dirtyAll:function(e){e=e||"";for(var t=vr+e,r=this._caches,n=0;n<r.length;n++)r[n]&&(r[n][t]=!0)},fresh:function(e){e=e||"";var t=vr+e;this.put(t,!1)},freshAll:function(e){e=e||"";for(var t=vr+e,r=this._caches,n=0;n<r.length;n++)r[n]&&(r[n][t]=!1)},isDirty:function(e){e=e||"";var t=vr+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(n){e&&e.call(t,n)})},miss:function(e){return!this._context.hasOwnProperty(e)}};on.prototype.constructor=on;const Ti=on;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 Ti},{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 Je=ti.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=ti.prototype.clone.call(this);return e.skeleton=this.skeleton,this.joints&&(e.joints=this.joints.slice()),e}});Je.POINTS=A.POINTS;Je.LINES=A.LINES;Je.LINE_LOOP=A.LINE_LOOP;Je.LINE_STRIP=A.LINE_STRIP;Je.TRIANGLES=A.TRIANGLES;Je.TRIANGLE_STRIP=A.TRIANGLE_STRIP;Je.TRIANGLE_FAN=A.TRIANGLE_FAN;Je.BACK=A.BACK;Je.FRONT=A.FRONT;Je.FRONT_AND_BACK=A.FRONT_AND_BACK;Je.CW=A.CW;Je.CCW=A.CCW;const Ei=Je;var pn={};pn.isPowerOfTwo=function(e){return(e&e-1)===0};pn.nextPowerOfTwo=function(e){return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e};pn.nearestPowerOfTwo=function(e){return Math.pow(2,Math.round(Math.log(e)/Math.LN2))};const os=pn;var ha=os.isPowerOfTwo;function fa(e){return Math.pow(2,Math.round(Math.log(e)/Math.LN2))}function _c(e,t){var r=fa(e.width),n=fa(e.height);t=t||document.createElement("canvas"),t.width=r,t.height=n;var i=t.getContext("2d");return i.drawImage(e.image,0,0,r,n),t}var Ai=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,n=this.type,i=!!(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,i?this.wrapS:this.getAvailableWrapS()),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,i?this.wrapT:this.getAvailableWrapT()),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,i?this.magFilter:this.getAvailableMagFilter()),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,i?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),n===36193){var s=e.getGLExtension("OES_texture_half_float");s||(n=A.FLOAT)}if(this.mipmaps.length)for(var o=this.width,l=this.height,c=0;c<this.mipmaps.length;c++){var u=this.mipmaps[c];this._updateTextureData(t,u,c,o,l,r,n,!1),o/=2,l/=2}else this._updateTextureData(t,this,0,this.width,this.height,r,n,i),this.useMipmap&&(!this.NPOT||i)&&t.generateMipmap(t.TEXTURE_2D);t.bindTexture(t.TEXTURE_2D,null)},_updateTextureData:function(e,t,r,n,i,a,s,o){if(t.image){var l=t.image;o&&(this._potCanvas=_c(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,n,i,0,t.pixels):e.texImage2D(e.TEXTURE_2D,r,a,n,i,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 ha(this.width)&&ha(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=Se.createImage();t&&(r.crossOrigin=t);var n=this;return r.onload=function(){n.dirty(),n.trigger("success",n)},r.onerror=function(){n.trigger("error",n)},r.src=e,this.image=r,this}});Object.defineProperty(Ai.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(Ai.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 ie=Ai;function ls(e){return{byte:Se.Int8Array,ubyte:Se.Uint8Array,short:Se.Int16Array,ushort:Se.Uint16Array}[e]||Se.Float32Array}function Dn(e){return"attr_"+e}function lr(e,t,r,n){switch(this.name=e,this.type=t,this.size=r,this.semantic=n||"",this.value=null,r){case 1:this.get=function(i){return this.value[i]},this.set=function(i,a){this.value[i]=a},this.copy=function(i,a){this.value[i]=this.value[i]};break;case 2:this.get=function(i,a){var s=this.value;return a[0]=s[i*2],a[1]=s[i*2+1],a},this.set=function(i,a){var s=this.value;s[i*2]=a[0],s[i*2+1]=a[1]},this.copy=function(i,a){var s=this.value;a*=2,i*=2,s[i]=s[a],s[i+1]=s[a+1]};break;case 3:this.get=function(i,a){var s=i*3,o=this.value;return a[0]=o[s],a[1]=o[s+1],a[2]=o[s+2],a},this.set=function(i,a){var s=i*3,o=this.value;o[s]=a[0],o[s+1]=a[1],o[s+2]=a[2]},this.copy=function(i,a){var s=this.value;a*=3,i*=3,s[i]=s[a],s[i+1]=s[a+1],s[i+2]=s[a+2]};break;case 4:this.get=function(i,a){var s=this.value,o=i*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(i,a){var s=this.value,o=i*4;s[o]=a[0],s[o+1]=a[1],s[o+2]=a[2],s[o+3]=a[3]},this.copy=function(i,a){var s=this.value;a*=4,i*=4,s[i]=s[a],s[i+1]=s[a+1],s[i+2]=s[a+2],s[i+3]=s[a+3]}}}lr.prototype.init=function(e){if(!this.value||this.value.length!==e*this.size){var t=ls(this.type);this.value=new t(e*this.size)}};lr.prototype.fromArray=function(e){var t=ls(this.type),r;if(e[0]&&e[0].length){var n=0,i=this.size;r=new t(e.length*i);for(var a=0;a<e.length;a++)for(var s=0;s<i;s++)r[n++]=e[a][s]}else r=new t(e);this.value=r};lr.prototype.clone=function(e){var t=new lr(this.name,this.type,this.size,this.semantic);return e&&console.warn("todo"),t};function cs(e,t,r,n,i){this.name=e,this.type=t,this.buffer=r,this.size=n,this.semantic=i,this.symbol="",this.needsRemove=!1}function us(e){this.buffer=e,this.count=0}var yt=qe.extend(function(){return{attributes:{},indices:null,dynamic:!0,_enabledAttributes:null,__used:0}},function(){this._cache=new Ti,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(Dn(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?Se.Uint32Array:Se.Uint16Array;if(e[0]&&e[0].length){var n=0,i=3;t=new r(e.length*i);for(var a=0;a<e.length;a++)for(var s=0;s<i;s++)t[n++]=e[a][s]}else t=new r(e);this.indices=t},createAttribute:function(e,t,r,n){var i=new lr(e,t,r,n);return this.attributes[e]&&this.removeAttribute(e),this.attributes[e]=i,this._attributeList.push(e),i},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=[],n=this.vertexCount,i=0;i<t.length;i++){var a=t[i],s=this.attributes[a];s.value&&s.value.length===n*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"),n=t.isDirty("indices");if(r||n){this._updateBuffer(e.gl,r,n);for(var i=this.getEnabledAttributes(),a=0;a<i.length;a++)t.fresh(Dn(i[a]));t.fresh("attributes"),t.fresh("indices")}return t.fresh("any"),t.get("chunks")},_updateBuffer:function(e,t,r){var n=this._cache,i=n.get("chunks"),a=!1;i||(i=[],i[0]={attributeBuffers:[],indicesBuffer:null},n.put("chunks",i),a=!0);var s=i[0],o=s.attributeBuffers,l=s.indicesBuffer;if(t||a){var c=this.getEnabledAttributes(),u={};if(!a)for(var h=0;h<o.length;h++)u[o[h].name]=o[h];for(var d=0;d<c.length;d++){var f=c[d],v=this.attributes[f],_;a||(_=u[f]);var m;_?m=_.buffer:m=e.createBuffer(),n.isDirty(Dn(f))&&(e.bindBuffer(e.ARRAY_BUFFER,m),e.bufferData(e.ARRAY_BUFFER,v.value,this.dynamic?e.DYNAMIC_DRAW:e.STATIC_DRAW)),o[d]=new cs(f,v.type,m,v.size,v.semantic)}for(var h=d;h<o.length;h++)e.deleteBuffer(o[h].buffer);o.length=d}this.isUseIndices()&&(r||a)&&(l||(l=new us(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 n=0;n<r.length;n++){for(var i=r[n],a=0;a<i.attributeBuffers.length;a++){var s=i.attributeBuffers[a];e.gl.deleteBuffer(s.buffer)}i.indicesBuffer&&e.gl.deleteBuffer(i.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(yt.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(yt.prototype,"triangleCount",{enumerable:!1,get:function(){var e=this.indices;return e?e.length/3:0}}));yt.STATIC_DRAW=A.STATIC_DRAW;yt.DYNAMIC_DRAW=A.DYNAMIC_DRAW;yt.STREAM_DRAW=A.STREAM_DRAW;yt.AttributeBuffer=cs;yt.IndicesBuffer=us;yt.Attribute=lr;const Xt=yt;var Ge=T.create,Qt=T.add,Dt=T.set,ct=Xt.Attribute,$t=Xt.extend(function(){return{attributes:{position:new ct("position","float",3,"POSITION"),texcoord0:new ct("texcoord0","float",2,"TEXCOORD_0"),texcoord1:new ct("texcoord1","float",2,"TEXCOORD_1"),normal:new ct("normal","float",3,"NORMAL"),tangent:new ct("tangent","float",4,"TANGENT"),color:new ct("color","float",4,"COLOR"),weight:new ct("weight","float",3,"WEIGHT"),joint:new ct("joint","float",4,"JOINT"),barycentric:new ct("barycentric","float",3,null)},boundingBox:null}},{mainAttribute:"position",updateBoundingBox:function(){var e=this.boundingBox;e||(e=this.boundingBox=new Ve);var t=this.attributes.position.value;if(t&&t.length){var r=e.min,n=e.max,i=r.array,a=n.array;T.set(i,t[0],t[1],t[2]),T.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<i[0]&&(i[0]=o),l<i[1]&&(i[1]=l),c<i[2]&&(i[2]=c),o>a[0]&&(a[0]=o),l>a[1]&&(a[1]=l),c>a[2]&&(a[2]=c)}r._dirty=!0,n._dirty=!0}},generateVertexNormals:function(){if(this.vertexCount){var e=this.indices,t=this.attributes,r=t.position.value,n=t.normal.value;if(!n||n.length!==r.length)n=t.normal.value=new Se.Float32Array(r.length);else for(var i=0;i<n.length;i++)n[i]=0;for(var a=Ge(),s=Ge(),o=Ge(),l=Ge(),c=Ge(),u=Ge(),h=e?e.length:this.vertexCount,d,f,v,_=0;_<h;){e?(d=e[_++],f=e[_++],v=e[_++]):(d=_++,f=_++,v=_++),Dt(a,r[d*3],r[d*3+1],r[d*3+2]),Dt(s,r[f*3],r[f*3+1],r[f*3+2]),Dt(o,r[v*3],r[v*3+1],r[v*3+2]),T.sub(l,a,s),T.sub(c,s,o),T.cross(u,l,c);for(var i=0;i<3;i++)n[d*3+i]=n[d*3+i]+u[i],n[f*3+i]=n[f*3+i]+u[i],n[v*3+i]=n[v*3+i]+u[i]}for(var i=0;i<n.length;)Dt(u,n[i],n[i+1],n[i+2]),T.normalize(u,u),n[i++]=u[0],n[i++]=u[1],n[i++]=u[2];this.dirty()}},generateFaceNormals:function(){if(this.vertexCount){this.isUniqueVertex()||this.generateUniqueVertex();var e=this.indices,t=this.attributes,r=t.position.value,n=t.normal.value,i=Ge(),a=Ge(),s=Ge(),o=Ge(),l=Ge(),c=Ge();n||(n=t.normal.value=new Float32Array(r.length));for(var u=e?e.length:this.vertexCount,h,d,f,v=0;v<u;){e?(h=e[v++],d=e[v++],f=e[v++]):(h=v++,d=v++,f=v++),Dt(i,r[h*3],r[h*3+1],r[h*3+2]),Dt(a,r[d*3],r[d*3+1],r[d*3+2]),Dt(s,r[f*3],r[f*3+1],r[f*3+2]),T.sub(o,i,a),T.sub(l,a,s),T.cross(c,o,l),T.normalize(c,c);for(var _=0;_<3;_++)n[h*3+_]=c[_],n[d*3+_]=c[_],n[f*3+_]=c[_]}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,n=t.position.value,i=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],u=[0,0,0],h=this.indices,d=h?h.length:this.vertexCount,f,v,_,l=0;l<d;){h?(f=h[l++],v=h[l++],_=h[l++]):(f=l++,v=l++,_=l++);var m=r[f*2],p=r[v*2],y=r[_*2],g=r[f*2+1],x=r[v*2+1],E=r[_*2+1],S=n[f*3],R=n[v*3],w=n[_*3],M=n[f*3+1],F=n[v*3+1],b=n[_*3+1],U=n[f*3+2],I=n[v*3+2],N=n[_*3+2],G=R-S,B=w-S,Y=F-M,O=b-M,he=I-U,V=N-U,xe=p-m,ae=y-m,ve=x-g,_e=E-g,Ie=1/(xe*_e-ve*ae);c[0]=(_e*G-ve*B)*Ie,c[1]=(_e*Y-ve*O)*Ie,c[2]=(_e*he-ve*V)*Ie,u[0]=(xe*B-ae*G)*Ie,u[1]=(xe*O-ae*Y)*Ie,u[2]=(xe*V-ae*he)*Ie,Qt(s[f],s[f],c),Qt(s[v],s[v],c),Qt(s[_],s[_],c),Qt(o[f],o[f],u),Qt(o[v],o[v],u),Qt(o[_],o[_],u)}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 Ye=s[l];T.scale(Be,ze,T.dot(ze,Ye)),T.sub(Be,Ye,Be),T.normalize(Be,Be),T.cross(Re,ze,Ye),i[l*4]=Be[0],i[l*4+1]=Be[1],i[l*4+2]=Be[2],i[l*4+3]=T.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 Se.Uint32Array(this.indices));for(var e=this.attributes,t=this.indices,r=this.getEnabledAttributes(),n={},i=0;i<r.length;i++){var a=r[i];n[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],i=0;i<r.length;i++)for(var a=r[i],c=e[a].value,u=e[a].size,h=0;h<u;h++)c[s*u+h]=n[a][l*u+h];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 n=0;n<(r?r.length:this.vertexCount/3);)for(var i=0;i<3;i++){var a=r?r[n++]:n*3+i;t[a*3+i]=1}this.dirty()}}},applyTransform:function(e){var t=this.attributes,r=t.position.value,n=t.normal.value,i=t.tangent.value;e=e.array;var a=C.create();C.invert(a,e),C.transpose(a,a);var s=T.transformMat4,o=T.forEach;o(r,3,0,null,s,e),n&&o(n,3,0,null,s,a),i&&o(i,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 n=0;n<r.length;n++){for(var i=r[n],a=0;a<i.attributeBuffers.length;a++){var s=i.attributeBuffers[a];e.gl.deleteBuffer(s.buffer)}i.indicesBuffer&&e.gl.deleteBuffer(i.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__)}});$t.STATIC_DRAW=Xt.STATIC_DRAW;$t.DYNAMIC_DRAW=Xt.DYNAMIC_DRAW;$t.STREAM_DRAW=Xt.STREAM_DRAW;$t.AttributeBuffer=Xt.AttributeBuffer;$t.IndicesBuffer=Xt.IndicesBuffer;$t.Attribute=ct;const Ee=$t,mc="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 it="uniform vec3 ",_r="uniform float ",Jt="@export clay.header.",er="@end",Ne=":unconfigurable;";const pc=[Jt+"directional_light",it+"directionalLightDirection[DIRECTIONAL_LIGHT_COUNT]"+Ne,it+"directionalLightColor[DIRECTIONAL_LIGHT_COUNT]"+Ne,er,Jt+"ambient_light",it+"ambientLightColor[AMBIENT_LIGHT_COUNT]"+Ne,er,Jt+"ambient_sh_light",it+"ambientSHLightColor[AMBIENT_SH_LIGHT_COUNT]"+Ne,it+"ambientSHLightCoefficients[AMBIENT_SH_LIGHT_COUNT * 9]"+Ne,mc,er,Jt+"ambient_cubemap_light",it+"ambientCubemapLightColor[AMBIENT_CUBEMAP_LIGHT_COUNT]"+Ne,"uniform samplerCube ambientCubemapLightCubemap[AMBIENT_CUBEMAP_LIGHT_COUNT]"+Ne,"uniform sampler2D ambientCubemapLightBRDFLookup[AMBIENT_CUBEMAP_LIGHT_COUNT]"+Ne,er,Jt+"point_light",it+"pointLightPosition[POINT_LIGHT_COUNT]"+Ne,_r+"pointLightRange[POINT_LIGHT_COUNT]"+Ne,it+"pointLightColor[POINT_LIGHT_COUNT]"+Ne,er,Jt+"spot_light",it+"spotLightPosition[SPOT_LIGHT_COUNT]"+Ne,it+"spotLightDirection[SPOT_LIGHT_COUNT]"+Ne,_r+"spotLightRange[SPOT_LIGHT_COUNT]"+Ne,_r+"spotLightUmbraAngleCosine[SPOT_LIGHT_COUNT]"+Ne,_r+"spotLightPenumbraAngleCosine[SPOT_LIGHT_COUNT]"+Ne,_r+"spotLightFalloffFactor[SPOT_LIGHT_COUNT]"+Ne,it+"spotLightColor[SPOT_LIGHT_COUNT]"+Ne,er].join("\n");L.import(pc);var gc=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 ot=gc;var tn=function(e,t){this.normal=e||new P(0,1,0),this.distance=t||0};tn.prototype={constructor:tn,distanceToPoint:function(e){return T.dot(e.array,this.normal.array)-this.distance},projectPoint:function(e,t){t||(t=new P);var r=this.distanceToPoint(e);return T.scaleAndAdd(t.array,e.array,this.normal.array,-r),t._dirty=!0,t},normalize:function(){var e=1/T.len(this.normal.array);T.scale(this.normal.array,e),this.distance*=e},intersectFrustum:function(e){for(var t=e.vertices,r=this.normal.array,n=T.dot(t[0].array,r)>this.distance,i=1;i<8;i++)if(T.dot(t[i].array,r)>this.distance!=n)return!0},intersectLine:function(){var e=T.create();return function(t,r,n){var i=this.distanceToPoint(t),a=this.distanceToPoint(r);if(i>0&&a>0||i<0&&a<0)return null;var s=this.normal.array,o=this.distance,l=t.array;T.sub(e,r.array,t.array),T.normalize(e,e);var c=T.dot(s,e);if(c===0)return null;n||(n=new P);var u=(T.dot(s,l)-o)/c;return T.scaleAndAdd(n.array,l,e,-u),n._dirty=!0,n}}(),applyTransform:function(){var e=C.create(),t=D.create(),r=D.create();return r[3]=1,function(n){n=n.array,T.scale(r,this.normal.array,this.distance),D.transformMat4(r,r,n),this.distance=T.dot(r,this.normal.array),C.invert(e,n),C.transpose(e,e),t[3]=0,T.copy(t,this.normal.array),D.transformMat4(t,t,e),T.copy(this.normal.array,t)}}(),copy:function(e){T.copy(this.normal.array,e.normal.array),this.normal._dirty=!0,this.distance=e.distance},clone:function(){var e=new tn;return e.copy(this),e}};const hs=tn;var Te=T.set,da=T.copy,va=T.transformMat4,On=Math.min,In=Math.max,fs=function(){this.planes=[];for(var e=0;e<6;e++)this.planes.push(new hs);this.boundingBox=new Ve,this.vertices=[];for(var e=0;e<8;e++)this.vertices[e]=T.fromValues(0,0,0)};fs.prototype={setFromProjection:function(e){var t=this.planes,r=e.array,n=r[0],i=r[1],a=r[2],s=r[3],o=r[4],l=r[5],c=r[6],u=r[7],h=r[8],d=r[9],f=r[10],v=r[11],_=r[12],m=r[13],p=r[14],y=r[15];Te(t[0].normal.array,s-n,u-o,v-h),t[0].distance=-(y-_),t[0].normalize(),Te(t[1].normal.array,s+n,u+o,v+h),t[1].distance=-(y+_),t[1].normalize(),Te(t[2].normal.array,s+i,u+l,v+d),t[2].distance=-(y+m),t[2].normalize(),Te(t[3].normal.array,s-i,u-l,v-d),t[3].distance=-(y-m),t[3].normalize(),Te(t[4].normal.array,s-a,u-c,v-f),t[4].distance=-(y-p),t[4].normalize(),Te(t[5].normal.array,s+a,u+c,v+f),t[5].distance=-(y+p),t[5].normalize();var g=this.boundingBox,x=this.vertices;if(y===0){var E=l/n,S=-p/(f-1),R=-p/(f+1),w=-R/l,M=-S/l;g.min.set(-w*E,-w,R),g.max.set(w*E,w,S),Te(x[0],-w*E,-w,R),Te(x[1],-w*E,w,R),Te(x[2],w*E,-w,R),Te(x[3],w*E,w,R),Te(x[4],-M*E,-M,S),Te(x[5],-M*E,M,S),Te(x[6],M*E,-M,S),Te(x[7],M*E,M,S)}else{var F=(-1-_)/n,b=(1-_)/n,U=(1-m)/l,I=(-1-m)/l,N=(-1-p)/f,G=(1-p)/f;g.min.set(Math.min(F,b),Math.min(I,U),Math.min(G,N)),g.max.set(Math.max(b,F),Math.max(U,I),Math.max(N,G));var B=g.min.array,Y=g.max.array;Te(x[0],B[0],B[1],B[2]),Te(x[1],B[0],Y[1],B[2]),Te(x[2],Y[0],B[1],B[2]),Te(x[3],Y[0],Y[1],B[2]),Te(x[4],B[0],B[1],Y[2]),Te(x[5],B[0],Y[1],Y[2]),Te(x[6],Y[0],B[1],Y[2]),Te(x[7],Y[0],Y[1],Y[2])}},getTransformedBoundingBox:function(){var e=T.create();return function(t,r){var n=this.vertices,i=r.array,a=t.min,s=t.max,o=a.array,l=s.array,c=n[0];va(e,c,i),da(o,e),da(l,e);for(var u=1;u<8;u++)c=n[u],va(e,c,i),o[0]=On(e[0],o[0]),o[1]=On(e[1],o[1]),o[2]=On(e[2],o[2]),l[0]=In(e[0],l[0]),l[1]=In(e[1],l[1]),l[2]=In(e[2],l[2]);return a._dirty=!0,s._dirty=!0,t}}()};const Si=fs;var xc=dt.extend(function(){return{projectionMatrix:new z,invProjectionMatrix:new z,viewMatrix:new z,frustum:new Si}},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 n=r!==void 0?r:new sn,i=t.array[0],a=t.array[1];return D.set(e,i,a,-1,1),D.transformMat4(e,e,this.invProjectionMatrix.array),D.transformMat4(e,e,this.worldTransform.array),T.scale(n.origin.array,e,1/e[3]),D.set(e,i,a,1,1),D.transformMat4(e,e,this.invProjectionMatrix.array),D.transformMat4(e,e,this.worldTransform.array),T.scale(e,e,1/e[3]),T.sub(n.direction.array,e,n.origin.array),T.normalize(n.direction.array,n.direction.array),n.direction._dirty=!0,n.origin._dirty=!0,n}}()});const cr=xc;var yc=C.create(),_a=C.create(),Bn={};function Tc(e){var t=[],r=Object.keys(e);r.sort();for(var n=0;n<r.length;n++){var i=r[n];t.push(i+" "+e[i])}var a=t.join("\n");if(Bn[a])return Bn[a];var s=De.genGUID();return Bn[a]=s,s}function gn(){this.opaque=[],this.transparent=[],this._opaqueCount=0,this._transparentCount=0}gn.prototype.startCount=function(){this._opaqueCount=0,this._transparentCount=0};gn.prototype.add=function(e,t){t?this.transparent[this._transparentCount++]=e:this.opaque[this._opaqueCount++]=e};gn.prototype.endCount=function(){this.transparent.length=this._transparentCount,this.opaque.length=this._opaqueCount};var Ec=dt.extend(function(){return{material:null,lights:[],viewBoundingBoxLastFrame:new Ve,shadowUniforms:{},_cameraList:[],_lightUniforms:{},_previousLightNumber:{},_lightNumber:{},_lightProgramKeys:{},_nodeRepository:{},_renderLists:new Ja(20)}},function(){this._scene=this},{addToScene:function(e){e instanceof cr?(this._cameraList.length>0&&console.warn("Found multiple camera in one scene. Use the fist one."),this._cameraList.push(e)):e instanceof ot&&this.lights.push(e),e.name&&(this._nodeRepository[e.name]=e)},removeFromScene:function(e){var t;e instanceof cr?(t=this._cameraList.indexOf(e),t>=0&&this._cameraList.splice(t,1)):e instanceof ot&&(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 n=e[r];if(!n.invisible){var i=n.group;t[i]||(t[i]={}),t[i][n.type]=t[i][n.type]||0,t[i][n.type]++}}this._lightNumber=t;for(var a in t)this._lightProgramKeys[a]=Tc(t[a]);this._updateLightUniforms()},cloneNode:function(e){var t=e.clone(),r={};function n(i,a){r[i.__uid__]=a;for(var s=0;s<i._children.length;s++){var o=i._children[s],l=a._children[s];n(o,l)}}return n(e,t),t.traverse(function(i){i.skeleton&&(i.skeleton=i.skeleton.clone(r)),i.material&&(i.material=i.material.clone())}),t},updateRenderList:function(e,t){var r=e.__uid__,n=this._renderLists.get(r);n||(n=new gn,this._renderLists.put(r,n)),n.startCount(),t&&(this.viewBoundingBoxLastFrame.min.set(1/0,1/0,1/0),this.viewBoundingBoxLastFrame.max.set(-1/0,-1/0,-1/0));var i=this.material&&this.material.transparent||!1;return this._doUpdateRenderList(this,e,i,n,t),n.endCount(),n},getRenderList:function(e){return this._renderLists.get(e.__uid__)},_doUpdateRenderList:function(e,t,r,n,i){if(!e.invisible)for(var a=0;a<e._children.length;a++){var s=e._children[a];if(s.isRenderable()){var o=s.isSkinnedMesh()?yc:s.worldTransform.array,l=s.geometry;C.multiplyAffine(_a,t.viewMatrix.array,o),(i&&!l.boundingBox||!this.isFrustumCulled(s,t,_a))&&n.add(s,s.material.transparent||r)}s._children.length>0&&this._doUpdateRenderList(s,t,r,n,i)}},isFrustumCulled:function(){var e=new Ve,t=new z;return function(r,n,i){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=i,e.transformFrom(a,t),r.castShadow&&this.viewBoundingBoxLastFrame.union(e),r.frustumCulling){if(!e.intersectBoundingBox(n.frustum.boundingBox))return!0;t.array=n.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(Ac);var t=this._lightUniforms;for(var r in t)for(var n in t[r])t[r][n].value.length=0;for(var i=0;i<e.length;i++){var a=e[i];if(!a.invisible){var r=a.group;for(var n in a.uniformTemplates){var s=a.uniformTemplates[n],o=s.value(a);if(o!=null){t[r]||(t[r]={}),t[r][n]||(t[r][n]={type:"",value:[]});var l=t[r][n];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 n in r[e])if(!t[e]||r[e][n]!==t[e][n])return!0;for(var n in t[e])if(!r[e]||r[e][n]!==t[e][n])return!0;return!1},getLightsNumbers:function(e){return this._lightNumber[e]},getProgramKey:function(e){return this._lightProgramKeys[e]},setLightUniforms:function(){function e(t,r,n){for(var i in t){var a=t[i];if(a.type==="tv"){if(!r.hasUniform(i))continue;for(var s=[],o=0;o<a.value.length;o++){var l=a.value[o],c=r.takeCurrentTextureSlot(n,l);s.push(c)}r.setUniform(n.gl,"1iv",i,s)}else r.setUniform(n.gl,a.type,i,a.value)}}return function(t,r,n){e(this._lightUniforms[r],t,n),e(this.shadowUniforms,t,n)}}(),dispose:function(){this.material=null,this._opaqueList=[],this._transparentList=[],this.lights=[],this._lightUniforms={},this._lightNumber={},this._nodeRepository={}}});function Ac(e,t){if(t.castShadow&&!e.castShadow)return!0}const Pt=Ec;var $r=os.isPowerOfTwo,Sc=["px","nx","py","ny","pz","nz"],wi=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,n=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 i=e.getGLExtension("EXT_texture_filter_anisotropic");if(i&&this.anisotropic>1&&t.texParameterf(t.TEXTURE_CUBE_MAP,i.TEXTURE_MAX_ANISOTROPY_EXT,this.anisotropic),n===36193){var a=e.getGLExtension("OES_texture_half_float");a||(n=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,n),s/=2,o/=2}else this._updateTextureData(t,this,0,this.width,this.height,r,n),!this.NPOT&&this.useMipmap&&t.generateMipmap(t.TEXTURE_CUBE_MAP);t.bindTexture(t.TEXTURE_CUBE_MAP,null)},_updateTextureData:function(e,t,r,n,i,a,s){for(var o=0;o<6;o++){var l=Sc[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,n,i,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?$r(this.image.px.width)&&$r(this.image.px.height):$r(this.width)&&$r(this.height)},isRenderable:function(){return this.image.px?tr(this.image.px)&&tr(this.image.nx)&&tr(this.image.py)&&tr(this.image.ny)&&tr(this.image.pz)&&tr(this.image.nz):!!(this.width&&this.height)},load:function(e,t){var r=0,n=this;return De.each(e,function(i,a){var s=Se.createImage();t&&(s.crossOrigin=t),s.onload=function(){r--,r===0&&(n.dirty(),n.trigger("success",n))},s.onerror=function(){r--},r++,s.src=i,n.image[a]=s}),this}});Object.defineProperty(wi.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(wi.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 tr(e){return e.width>0&&e.height>0}const Lr=wi;var wc=cr.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=cr.prototype.clone.call(this);return e.fov=this.fov,e.aspect=this.aspect,e.near=this.near,e.far=this.far,e}});const Me=wc;var jr="framebuffer",pt="renderbuffer",ma=pt+"_width",pa=pt+"_height",Fn=pt+"_attached",Un="depthtexture_attached",Ot=A.FRAMEBUFFER,mr=A.RENDERBUFFER,yr=A.DEPTH_ATTACHMENT,ds=A.COLOR_ATTACHMENT0,Br=qe.extend({depthBuffer:!0,viewport:null,_width:0,_height:0,_textures:null,_boundRenderer:null},function(){this._cache=new Ti,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(Ot,this._getFrameBufferGL(e)),this._boundRenderer=e;var r=this._cache;r.put("viewport",e.viewport);var n=!1,i,a;for(var s in this._textures){n=!0;var o=this._textures[s];o&&(i=o.texture.width,a=o.texture.height,this._doAttach(e,o.texture,s,o.target))}this._width=i,this._height=a,!n&&this.depthBuffer&&console.error("Must attach texture before bind, or renderbuffer may have incorrect width and height."),this.viewport?e.setViewport(this.viewport):e.setViewport(0,0,i,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(Un)&&this.depthBuffer){r.miss(pt)&&r.put(pt,t.createRenderbuffer());var u=r.get(pt);(i!==r.get(ma)||a!==r.get(pa))&&(t.bindRenderbuffer(mr,u),t.renderbufferStorage(mr,t.DEPTH_COMPONENT16,i,a),r.put(ma,i),r.put(pa,a),t.bindRenderbuffer(mr,null)),r.get(Fn)||(t.framebufferRenderbuffer(Ot,yr,mr,u),r.put(Fn,!0))}},unbind:function(e){e.__currentFrameBuffer=null;var t=e.gl;t.bindFramebuffer(Ot,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 n=this._textures[r];if(n){var i=n.texture;if(!i.NPOT&&i.useMipmap&&i.minFilter===q.LINEAR_MIPMAP_LINEAR){var a=i.textureType==="textureCube"?A.TEXTURE_CUBE_MAP:A.TEXTURE_2D;t.bindTexture(a,i.getWebGLTexture(e)),t.generateMipmap(a),t.bindTexture(a,null)}}}},checkStatus:function(e){return e.checkFramebufferStatus(Ot)},_getFrameBufferGL:function(e){var t=this._cache;return t.use(e.__uid__),t.miss(jr)&&t.put(jr,e.gl.createFramebuffer()),t.get(jr)},attach:function(e,t,r){if(!e.width)throw new Error("The texture attached to color buffer is not a valid.");t=t||ds,r=r||A.TEXTURE_2D;var n=this._boundRenderer,i=n&&n.gl,a;if(i){var s=this._cache;s.use(n.__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;n&&(l=this._doAttach(n,e,t,r),this.viewport||n.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,n){var i=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===n)return}r=+r;var l=!0;if(r===yr||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 u=this._cache.get(pt);u&&(i.framebufferRenderbuffer(Ot,yr,mr,null),i.deleteRenderbuffer(u),this._cache.put(pt,!1)),this._cache.put(Fn,!1),this._cache.put(Un,!0)}}return i.framebufferTexture2D(Ot,r,n,a,0),s||(s={},this._cache.put("attached_textures",s)),s[r]=s[r]||{},s[r].texture=t,s[r].target=n,l},_doDetach:function(e,t,r){e.framebufferTexture2D(Ot,t,r,null,0);var n=this._cache.get("attached_textures");n&&n[t]&&(n[t]=null),(t===yr||t===A.DEPTH_STENCIL_ATTACHMENT)&&this._cache.put(Un,!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 n=r.get(pt);n&&t.deleteRenderbuffer(n);var i=r.get(jr);i&&t.deleteFramebuffer(i),r.deleteContext(e.__uid__),this._textures={}}});Br.DEPTH_ATTACHMENT=yr;Br.COLOR_ATTACHMENT0=ds;Br.STENCIL_ATTACHMENT=A.STENCIL_ATTACHMENT;Br.DEPTH_STENCIL_ATTACHMENT=A.DEPTH_STENCIL_ATTACHMENT;const Ue=Br;var bc=["px","nx","py","ny","pz","nz"],Cc=qe.extend(function(){var e={position:new P,far:1e3,near:.1,texture:null,shadowMapPass:null},t=e._cameras={px:new Me({fov:90}),nx:new Me({fov:90}),py:new Me({fov:90}),ny:new Me({fov:90}),pz:new Me({fov:90}),nz:new Me({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 n=e.gl;r||t.update();for(var i=this.texture.width,a=2*Math.atan(i/(i-.5))/Math.PI*180,s=0;s<6;s++){var o=bc[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,n.COLOR_ATTACHMENT0,n.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 bi=Cc;var Rc=Ee.extend({dynamic:!1,widthSegments:1,heightSegments:1},function(){this.build()},{build:function(){for(var e=this.heightSegments,t=this.widthSegments,r=this.attributes,n=[],i=[],a=[],s=[],o=0;o<=e;o++)for(var l=o/e,c=0;c<=t;c++){var u=c/t;if(n.push([2*u-1,2*l-1,0]),i&&i.push([u,l]),a&&a.push([0,0,1]),c<t&&o<e){var h=c+o*(t+1);s.push([h,h+1,h+t+1]),s.push([h+t+1,h+1,h+t+2])}}r.position.fromArray(n),r.texcoord0.fromArray(i),r.normal.fromArray(a),this.initIndicesFromArray(s),this.boundingBox=new Ve,this.boundingBox.min.set(-1,-1,0),this.boundingBox.max.set(1,1,0)}});const Ci=Rc;var ge=new z,Mc=Ee.extend({dynamic:!1,widthSegments:1,heightSegments:1,depthSegments:1,inside:!1},function(){this.build()},{build:function(){var e={px:rr("px",this.depthSegments,this.heightSegments),nx:rr("nx",this.depthSegments,this.heightSegments),py:rr("py",this.widthSegments,this.depthSegments),ny:rr("ny",this.widthSegments,this.depthSegments),pz:rr("pz",this.widthSegments,this.heightSegments),nz:rr("nz",this.widthSegments,this.heightSegments)},t=["position","texcoord0","normal"],r=0,n=0;for(var i in e)r+=e[i].vertexCount,n+=e[i].indices.length;for(var a=0;a<t.length;a++)this.attributes[t[a]].init(r);this.indices=new Se.Uint16Array(n);var s=0,o=0;for(var i in e){for(var l=e[i],a=0;a<t.length;a++)for(var c=t[a],u=l.attributes[c].value,h=l.attributes[c].size,d=c==="normal",f=0;f<u.length;f++){var v=u[f];this.inside&&d&&(v=-v),this.attributes[c].value[f+h*o]=v}for(var _=l.indices.length,f=0;f<l.indices.length;f++)this.indices[f+s]=o+l.indices[this.inside?_-f-1:f];s+=l.indices.length,o+=l.vertexCount}this.boundingBox=new Ve,this.boundingBox.max.set(1,1,1),this.boundingBox.min.set(-1,-1,-1)}});function rr(e,t,r){ge.identity();var n=new Ci({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 n.applyTransform(ge),n}const vs=Mc,Lc="@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";L.import(Lc);var Nc=Ei.extend(function(){var e=new L({vertex:L.source("clay.skybox.vertex"),fragment:L.source("clay.skybox.fragment")}),t=new wt({shader:e,depthMask:!1});return{scene:null,geometry:new vs,material:t,environmentMap:null,culling:!1,_dummyCamera:new Me}},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 Nr=Nc;var Pc=542327876,Dc=131072,Oc=512,Ic=4;function Ri(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}var Bc=31,Fc=Ri("DXT1"),Uc=Ri("DXT3"),Hc=Ri("DXT5"),zc=0,Gc=1,Vc=2,kc=3,Wc=4,Xc=7,$c=20,jc=21,qc=28,Yc={parse:function(e,t){var r=new Int32Array(e,0,Bc);if(r[zc]!==Pc||!r($c)&Ic)return null;var n=r(jc),i=r[Wc],a=r[kc],s=r[qc]&Oc,o=r[Vc]&Dc,l,c;switch(n){case Fc:l=8,c=q.COMPRESSED_RGB_S3TC_DXT1_EXT;break;case Uc:l=16,c=q.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case Hc:l=16,c=q.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;default:return null}var u=r[Gc]+4,h=s?6:1,d=1;o&&(d=Math.max(1,r[Xc]));for(var f=[],v=0;v<h;v++){var _=i,m=a;f[v]=new ie({width:_,height:m,format:c});for(var p=[],y=0;y<d;y++){var g=Math.max(4,_)/4*Math.max(4,m)/4*l,x=new Uint8Array(e,u,g);u+=g,_*=.5,m*=.5,p[y]=x}f[v].pixels=p[0],o&&(f[v].mipmaps=p)}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 Zc=Yc;var rn=String.fromCharCode,Kc=8,Qc=32767;function Jc(e,t,r,n){if(e[3]>0){var i=Math.pow(2,e[3]-128-8+n);t[r+0]=e[0]*i,t[r+1]=e[1]*i,t[r+2]=e[2]*i}else t[r+0]=0,t[r+1]=0,t[r+2]=0;return t[r+3]=1,t}function eu(e,t,r){for(var n="",i=t;i<r;i++)n+=rn(e[i]);return n}function tu(e,t){t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3]}function ga(e,t,r,n){for(var i=0,a=0,s=n;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]<<i>>>0;o>0;o--)tu(e[a-1],e[a]),a++,s--;i+=8}else a++,s--,i=0;return r}function ru(e,t,r,n){if(n<Kc|n>Qc)return ga(e,t,r,n);var i=t[r++];if(i!=2)return ga(e,t,r-1,n);if(e[0][1]=t[r++],e[0][2]=t[r++],i=t[r++],(e[0][2]<<8>>>0|i)>>>0!==n)return null;for(var i=0;i<4;i++)for(var a=0;a<n;){var s=t[r++];if(s>128){s=(s&127)>>>0;for(var o=t[r++];s--;)e[a++][i]=o}else for(;s--;)e[a++][i]=t[r++]}return r}var nu={parseRGBE:function(e,t,r){r==null&&(r=0);var n=new Uint8Array(e),i=n.length;if(eu(n,0,2)==="#?"){for(var a=2;a<i&&!(rn(n[a])==="\n"&&rn(n[a+1])==="\n");a++);if(!(a>=i)){a+=2;for(var s="";a<i;a++){var o=rn(n[a]);if(o==="\n")break;s+=o}var l=s.split(" "),c=parseInt(l[1]),u=parseInt(l[3]);if(!(!u||!c)){for(var h=a+1,d=[],f=0;f<u;f++){d[f]=[];for(var v=0;v<4;v++)d[f][v]=0}for(var _=new Float32Array(u*c*4),m=0,p=0;p<c;p++){var h=ru(d,n,h,u);if(!h)return null;for(var f=0;f<u;f++)Jc(d[f],_,m,r),m+=4}return t||(t=new ie),t.width=u,t.height=c,t.pixels=_,t.type=q.FLOAT,t}}}},parseRGBEFromPNG:function(e){}};const iu=nu;var nn={loadTexture:function(e,t,r,n){var i;if(typeof t=="function"?(r=t,n=r,t={}):t=t||{},typeof e=="string"){if(e.match(/.hdr$/)||t.fileType==="hdr")return i=new ie({width:0,height:0,sRGB:!1}),nn._fetchTexture(e,function(a){iu.parseRGBE(a,i,t.exposure),i.dirty(),r&&r(i)},n),i;e.match(/.dds$/)||t.fileType==="dds"?(i=new ie({width:0,height:0}),nn._fetchTexture(e,function(a){Zc.parse(a,i),i.dirty(),r&&r(i)},n)):(i=new ie,i.load(e),i.success(r),i.error(n))}else typeof e=="object"&&typeof e.px<"u"&&(i=new Lr,i.load(e),i.success(r),i.error(n));return i},loadPanorama:function(e,t,r,n,i,a){var s=this;typeof n=="function"?(i=n,a=i,n={}):n=n||{},nn.loadTexture(t,n,function(o){o.flipY=n.flipY||!1,s.panoramaToCubeMap(e,o,r,n),o.dispose(e),i&&i(r)},a)},panoramaToCubeMap:function(e,t,r,n){var i=new bi,a=new Nr({scene:new Pt});return a.setEnvironmentMap(t),n=n||{},n.encodeRGBM&&a.material.define("fragment","RGBM_ENCODE"),r.sRGB=t.sRGB,i.texture=r,i.render(e,a.scene),i.texture=null,i.dispose(e),r},heightToNormal:function(e,t){var r=document.createElement("canvas"),n=r.width=e.width,i=r.height=e.height,a=r.getContext("2d");a.drawImage(e,0,0,n,i),t=t||!1;for(var s=a.getImageData(0,0,n,i),o=a.createImageData(n,i),l=0;l<s.data.length;l+=4){if(t){var c=s.data[l],u=s.data[l+1],h=s.data[l+2],d=Math.abs(c-u)+Math.abs(u-h);if(d>20)return console.warn("Given image is not a height map"),e}var f,v,_,m;l%(n*4)===0?(f=s.data[l],_=s.data[l+4]):l%(n*4)===(n-1)*4?(f=s.data[l-4],_=s.data[l]):(f=s.data[l-4],_=s.data[l+4]),l<n*4?(v=s.data[l],m=s.data[l+n*4]):l>n*(i-1)*4?(v=s.data[l-n*4],m=s.data[l]):(v=s.data[l-n*4],m=s.data[l+n*4]),o.data[l]=f-_+127,o.data[l+1]=v-m+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 n=document.createElement("canvas"),i=n.getContext("2d"),a=t||32;r=r||20,n.width=n.height=a,i.drawImage(e,0,0,a,a);for(var s=i.getImageData(0,0,a,a),o=0;o<s.data.length;o+=4){var l=s.data[o],c=s.data[o+1],u=s.data[o+2],h=Math.abs(l-c)+Math.abs(c-u);if(h>r)return!1}return!0},_fetchTexture:function(e,t,r){Se.request.get({url:e,responseType:"arraybuffer",onload:t,onerror:r})},createChessboard:function(e,t,r,n){e=e||512,t=t||64,r=r||"black",n=n||"white";var i=Math.ceil(e/t),a=document.createElement("canvas");a.width=e,a.height=e;var s=a.getContext("2d");s.fillStyle=n,s.fillRect(0,0,e,e),s.fillStyle=r;for(var o=0;o<i;o++)for(var l=0;l<i;l++){var c=l%2?o%2:o%2-1;c&&s.fillRect(o*t,l*t,t,t)}var u=new ie({image:a,anisotropic:8});return u},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 n=new ie({image:t});return n}};const Vt=nn;var ri=["mousedown","mouseup","mousemove","mouseover","mouseout","click","dblclick","contextmenu"];function ni(e){return"_on"+e}var ii=function(e){var t=this;this._texture=new ie({anisotropic:32,flipY:!1,surface:this,dispose:function(r){t.dispose(),ie.prototype.dispose.call(this,r)}}),ri.forEach(function(r){this[ni(r)]=function(n){n.triangle&&this._meshes.forEach(function(i){this.dispatchEvent(r,i,n.triangle,n.point)},this)}},this),this._meshes=[],e&&this.setECharts(e),this.onupdate=null};ii.prototype={constructor:ii,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,n=e.getZr(),i=n.__oldRefreshImmediately||n.refreshImmediately;n.refreshImmediately=function(){i.call(this),r._texture.dirty(),r.onupdate&&r.onupdate()},n.__oldRefreshImmediately=i}this._texture.image=t,this._texture.dirty(),this.onupdate&&this.onupdate()},dispatchEvent:function(){var e=new P,t=new P,r=new P,n=new Ze,i=new Ze,a=new Ze,s=new Ze,o=new P;return function(l,c,u,h){var d=c.geometry,f=d.attributes.position,v=d.attributes.texcoord0,_=P.dot,m=P.cross;f.get(u[0],e.array),f.get(u[1],t.array),f.get(u[2],r.array),v.get(u[0],n.array),v.get(u[1],i.array),v.get(u[2],a.array),m(o,t,r);var p=_(e,o),y=_(h,o)/p;m(o,r,e);var g=_(h,o)/p;m(o,e,t);var x=_(h,o)/p;Ze.scale(s,n,y),Ze.scaleAndAdd(s,s,i,g),Ze.scaleAndAdd(s,s,a,x);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||(ri.forEach(function(t){e.on(t,this[ni(t)],this)},this),this._meshes.push(e))},detachFromMesh:function(e){var t=this._meshes.indexOf(e);t>=0&&this._meshes.splice(t,1),ri.forEach(function(r){e.off(r,this[ni(r)])},this)},dispose:function(){this._meshes.forEach(function(e){this.detachFromMesh(e)},this)}};const au=ii;var su=cr.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=cr.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 Pr=su,ou="\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";L.import(ou);var lu=new Ci,xa=new Ei({geometry:lu,frustumCulling:!1}),cu=new Pr,uu=qe.extend(function(){return{fragment:"",outputs:null,material:null,blendWithPrevious:!1,clearColor:!1,clearDepth:!0}},function(){var e=new L(L.source("clay.compositor.vertex"),this.fragment),t=new wt({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 n=this.outputs[r];n&&t.attach(n,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 n=e.getGLExtension("EXT_draw_buffers");if(n&&this.outputs){var i=[];for(var a in this.outputs)a=+a,a>=r.COLOR_ATTACHMENT0&&a<=r.COLOR_ATTACHMENT0+8&&i.push(a);n.drawBuffersEXT(i)}}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){xa.material=this.material,e.renderPass([xa],cu)},dispose:function(e){}});const ke=uu,hu="#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",fu="#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 kt={},Hn=["px","nx","py","ny","pz","nz"];kt.prefilterEnvironmentMap=function(e,t,r,n,i){(!i||!n)&&(n=kt.generateNormalDistribution(),i=kt.integrateBRDF(e,n)),r=r||{};var a=r.width||64,s=r.height||64,o=r.type||t.type,l=new Lr({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),u=Math.log(c)/Math.log(2)+1,h=new wt({shader:new L({vertex:L.source("clay.skybox.vertex"),fragment:fu})});h.set("normalDistribution",n),r.encodeRGBM&&h.define("fragment","RGBM_ENCODE"),r.decodeRGBM&&h.define("fragment","RGBM_DECODE");var d=new Pt,f;if(t.textureType==="texture2D"){var v=new Lr({width:a,height:s,type:o===q.FLOAT?q.HALF_FLOAT:o});Vt.panoramaToCubeMap(e,t,v,{encodeRGBM:r.decodeRGBM}),t=v}f=new Nr({scene:d,material:h}),f.material.set("environmentMap",t);var _=new bi({texture:l});r.encodeRGBM&&(o=l.type=q.UNSIGNED_BYTE);for(var m=new ie({width:a,height:s,type:o}),p=new Ue({depthBuffer:!1}),y=Se[o===q.UNSIGNED_BYTE?"Uint8Array":"Float32Array"],g=0;g<u;g++){l.mipmaps[g]={pixels:{}},f.material.set("roughness",g/(u-1));for(var x=m.width,E=2*Math.atan(x/(x-.5))/Math.PI*180,S=0;S<Hn.length;S++){var R=new y(m.width*m.height*4);p.attach(m),p.bind(e);var w=_.getCamera(Hn[S]);w.fov=E,e.render(d,w),e.gl.readPixels(0,0,m.width,m.height,q.RGBA,o,R),p.unbind(e),l.mipmaps[g].pixels[Hn[S]]=R}m.width/=2,m.height/=2,m.dirty()}return p.dispose(e),m.dispose(e),f.dispose(e),n.dispose(e),{environmentMap:l,brdfLookup:i,normalDistribution:n,maxMipmapLevel:u}};kt.integrateBRDF=function(e,t){t=t||kt.generateNormalDistribution();var r=new Ue({depthBuffer:!1}),n=new ke({fragment:hu}),i=new ie({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 n.setUniform("normalDistribution",t),n.setUniform("viewportSize",[512,256]),n.attachOutput(i),n.render(e,r),r.dispose(e),i};kt.generateNormalDistribution=function(r,n){for(var r=r||256,n=n||1024,i=new ie({width:r,height:n,type:q.FLOAT,minFilter:q.NEAREST,magFilter:q.NEAREST,wrapS:q.CLAMP_TO_EDGE,wrapT:q.CLAMP_TO_EDGE,useMipmap:!1}),a=new Float32Array(n*r*4),s=[],o=0;o<r;o++){for(var l=o/r,c=l*l,u=0;u<n;u++){var h=(u<<16|u>>>16)>>>0;h=((h&1431655765)<<1|(h&2863311530)>>>1)>>>0,h=((h&858993459)<<2|(h&3435973836)>>>2)>>>0,h=((h&252645135)<<4|(h&4042322160)>>>4)>>>0,h=(((h&16711935)<<8|(h&4278255360)>>>8)>>>0)/4294967296;var d=Math.sqrt((1-h)/(1+(c*c-1)*h));s[u]=d}for(var u=0;u<n;u++){var f=(u*r+o)*4,d=s[u],v=Math.sqrt(1-d*d),_=u/n,m=2*Math.PI*_;a[f]=v*Math.cos(m),a[f+1]=d,a[f+2]=v*Math.sin(m),a[f+3]=1}}return i.pixels=a,i};const an=kt;var du=ot.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=an.generateNormalDistribution(),this._brdfLookup=an.integrateBRDF(e,this._normalDistribution));var r=this.cubemap;if(!r.__prefiltered){var n=an.prefilterEnvironmentMap(e,r,{encodeRGBM:!0,width:t,height:t},this._normalDistribution,this._brdfLookup);this.cubemap=n.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 vu=du;var _u=ot.extend({castShadow:!1,coefficients:[]},function(){this._coefficientsTmpArr=new Se.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 mu=_u;var _s={},Gt=["px","nx","py","ny","pz","nz"];function pu(e,t){var r=e[0],n=e[1],i=e[2];return t===0?1:t===1?r:t===2?n:t===3?i:t===4?r*i:t===5?n*i:t===6?r*n:t===7?3*i*i-1:r*r-n*n}var gu={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 xu(e,t,r,n){for(var i=new Se.Float32Array(27),a=T.create(),s=T.create(),o=T.create(),l=0;l<9;l++){for(var c=T.create(),u=0;u<Gt.length;u++){for(var h=t[Gt[u]],d=T.create(),f=0,v=0,_=gu[Gt[u]],m=0;m<n;m++)for(var p=0;p<r;p++){a[0]=p/(r-1)*2-1,a[1]=m/(n-1)*2-1,a[2]=-1,T.normalize(a,a),o[0]=a[_[0]]*_[3],o[1]=a[_[1]]*_[4],o[2]=a[_[2]]*_[5],s[0]=h[v++]/255,s[1]=h[v++]/255,s[2]=h[v++]/255;var y=h[v++]/255*8.12;s[0]*=y,s[1]*=y,s[2]*=y,T.scaleAndAdd(d,d,s,pu(o,l)*-a[2]),f+=-a[2]}T.scaleAndAdd(c,c,d,1/f)}i[l*3]=c[0]/6,i[l*3+1]=c[1]/6,i[l*3+2]=c[2]/6}return i}_s.projectEnvironmentMap=function(e,t,r){r=r||{},r.lod=r.lod||0;var n,i=new Pt,a=64;t.textureType==="texture2D"?n=new Nr({scene:i,environmentMap:t}):(a=t.image&&t.image.px?t.image.px.width:t.width,n=new Nr({scene:i,environmentMap:t}));var s=Math.ceil(a/Math.pow(2,r.lod)),o=Math.ceil(a/Math.pow(2,r.lod)),l=new ie({width:s,height:o}),c=new Ue;n.material.define("fragment","RGBM_ENCODE"),r.decodeRGBM&&n.material.define("fragment","RGBM_DECODE"),n.material.set("lod",r.lod);for(var u=new bi({texture:l}),h={},d=0;d<Gt.length;d++){h[Gt[d]]=new Uint8Array(s*o*4);var f=u.getCamera(Gt[d]);f.fov=90,c.attach(l),c.bind(e),e.render(i,f),e.gl.readPixels(0,0,s,o,q.RGBA,q.UNSIGNED_BYTE,h[Gt[d]]),c.unbind(e)}return n.dispose(e),c.dispose(e),l.dispose(e),xu(e,h,s,o)};const yu=_s;var Tu={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 Ar(t.dataIndex)?Ii(t.dataIndex,function(r){return e.indexOfRawIndex(r)}):e.indexOfRawIndex(t.dataIndex);if(t.name!=null)return Ar(t.name)?Ii(t.name,function(r){return e.indexOfName(r)}):e.indexOfName(t.name)}};const rt=Tu;var Eu=Ee.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,n=this.attributes.texcoord0,i=this.attributes.normal,a=(t+1)*(e+1);r.init(a),n.init(a),i.init(a);var s=a>65535?Uint32Array:Uint16Array,o=this.indices=new s(t*e*6),l,c,u,h,d,f,v,g=this.radius,_=this.phiStart,m=this.phiLength,p=this.thetaStart,y=this.thetaLength,g=this.radius,x=[],E=[],S=0,R=1/g;for(v=0;v<=e;v++)for(f=0;f<=t;f++)h=f/t,d=v/e,l=-g*Math.cos(_+h*m)*Math.sin(p+d*y),c=g*Math.cos(p+d*y),u=g*Math.sin(_+h*m)*Math.sin(p+d*y),x[0]=l,x[1]=c,x[2]=u,E[0]=h,E[1]=d,r.set(S,x),n.set(S,E),x[0]*=R,x[1]*=R,x[2]*=R,i.set(S,x),S++;var w,M,F,b,U=t+1,I=0;for(v=0;v<e;v++)for(f=0;f<t;f++)M=v*U+f,w=v*U+f+1,b=(v+1)*U+f+1,F=(v+1)*U+f,o[I++]=w,o[I++]=M,o[I++]=b,o[I++]=M,o[I++]=F,o[I++]=b;this.boundingBox=new Ve,this.boundingBox.max.set(g,g,g),this.boundingBox.min.set(-g,-g,-g)}});const Au=Eu;var Su=ot.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 wu=Su;var bu=ot.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=ot.prototype.clone.call(this);return e.shadowBias=this.shadowBias,e.shadowSlopeScale=this.shadowSlopeScale,e}});const Cu=bu;var Ru=ot.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=ot.prototype.clone.call(this);return e.range=this.range,e}});const Mu=Ru;var Lu=ot.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=ot.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 Nu=Lu;var re=function(e,t,r,n){e=e||0,t=t||0,r=r||0,n=n||0,this.array=D.fromValues(e,t,r,n),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,n){return this.array[0]=e,this.array[1]=t,this.array[2]=r,this.array[3]=n,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 pr=Object.defineProperty;if(pr){var qr=re.prototype;pr(qr,"x",{get:function(){return this.array[0]},set:function(e){this.array[0]=e,this._dirty=!0}}),pr(qr,"y",{get:function(){return this.array[1]},set:function(e){this.array[1]=e,this._dirty=!0}}),pr(qr,"z",{get:function(){return this.array[2]},set:function(e){this.array[2]=e,this._dirty=!0}}),pr(qr,"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,n,i){D.set(e.array,t,r,n,i),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,n){return D.lerp(e.array,t.array,r.array,n),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,n){return D.scaleAndAdd(e.array,t.array,r.array,n),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 Pu=re;var He={};He.create=function(){var e=new Oe(4);return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e};He.clone=function(e){var t=new Oe(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],n=t[1],i=t[2],a=t[3],s=r*a-i*n;return s?(s=1/s,e[0]=a*s,e[1]=-n*s,e[2]=-i*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 n=t[0],i=t[1],a=t[2],s=t[3],o=r[0],l=r[1],c=r[2],u=r[3];return e[0]=n*o+a*l,e[1]=i*o+s*l,e[2]=n*c+a*u,e[3]=i*c+s*u,e};He.mul=He.multiply;He.rotate=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=Math.sin(r),l=Math.cos(r);return e[0]=n*l+a*o,e[1]=i*l+s*o,e[2]=n*-o+a*l,e[3]=i*-o+s*l,e};He.scale=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=r[0],l=r[1];return e[0]=n*o,e[1]=i*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,n){return e[2]=n[2]/n[0],r[0]=n[0],r[1]=n[1],r[3]=n[3]-e[2]*r[1],[e,t,r]};const ye=He;var We=function(){this.array=ye.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 ye.copy(this.array,e.array),this._dirty=!0,this},adjoint:function(){return ye.adjoint(this.array,this.array),this._dirty=!0,this},determinant:function(){return ye.determinant(this.array)},identity:function(){return ye.identity(this.array),this._dirty=!0,this},invert:function(){return ye.invert(this.array,this.array),this._dirty=!0,this},mul:function(e){return ye.mul(this.array,this.array,e.array),this._dirty=!0,this},mulLeft:function(e){return ye.mul(this.array,e.array,this.array),this._dirty=!0,this},multiply:function(e){return ye.multiply(this.array,this.array,e.array),this._dirty=!0,this},multiplyLeft:function(e){return ye.multiply(this.array,e.array,this.array),this._dirty=!0,this},rotate:function(e){return ye.rotate(this.array,this.array,e),this._dirty=!0,this},scale:function(e){return ye.scale(this.array,this.array,e.array),this._dirty=!0,this},transpose:function(){return ye.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 ye.adjoint(e.array,t.array),e._dirty=!0,e};We.copy=function(e,t){return ye.copy(e.array,t.array),e._dirty=!0,e};We.determinant=function(e){return ye.determinant(e.array)};We.identity=function(e){return ye.identity(e.array),e._dirty=!0,e};We.invert=function(e,t){return ye.invert(e.array,t.array),e._dirty=!0,e};We.mul=function(e,t,r){return ye.mul(e.array,t.array,r.array),e._dirty=!0,e};We.multiply=We.mul;We.rotate=function(e,t,r){return ye.rotate(e.array,t.array,r),e._dirty=!0,e};We.scale=function(e,t,r){return ye.scale(e.array,t.array,r.array),e._dirty=!0,e};We.transpose=function(e,t){return ye.transpose(e.array,t.array),e._dirty=!0,e};const Du=We;var je={};je.create=function(){var e=new Oe(6);return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e[4]=0,e[5]=0,e};je.clone=function(e){var t=new Oe(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};je.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};je.identity=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=1,e[4]=0,e[5]=0,e};je.invert=function(e,t){var r=t[0],n=t[1],i=t[2],a=t[3],s=t[4],o=t[5],l=r*a-n*i;return l?(l=1/l,e[0]=a*l,e[1]=-n*l,e[2]=-i*l,e[3]=r*l,e[4]=(i*o-a*s)*l,e[5]=(n*s-r*o)*l,e):null};je.determinant=function(e){return e[0]*e[3]-e[1]*e[2]};je.multiply=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=r[0],u=r[1],h=r[2],d=r[3],f=r[4],v=r[5];return e[0]=n*c+a*u,e[1]=i*c+s*u,e[2]=n*h+a*d,e[3]=i*h+s*d,e[4]=n*f+a*v+o,e[5]=i*f+s*v+l,e};je.mul=je.multiply;je.rotate=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=Math.sin(r),u=Math.cos(r);return e[0]=n*u+a*c,e[1]=i*u+s*c,e[2]=n*-c+a*u,e[3]=i*-c+s*u,e[4]=o,e[5]=l,e};je.scale=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=r[0],u=r[1];return e[0]=n*c,e[1]=i*c,e[2]=a*u,e[3]=s*u,e[4]=o,e[5]=l,e};je.translate=function(e,t,r){var n=t[0],i=t[1],a=t[2],s=t[3],o=t[4],l=t[5],c=r[0],u=r[1];return e[0]=n,e[1]=i,e[2]=a,e[3]=s,e[4]=n*c+a*u+o,e[5]=i*c+s*u+l,e};je.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 Ae=je;var $e=function(){this.array=Ae.create(),this._dirty=!0};$e.prototype={constructor:$e,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 $e().copy(this)},copy:function(e){return Ae.copy(this.array,e.array),this._dirty=!0,this},determinant:function(){return Ae.determinant(this.array)},identity:function(){return Ae.identity(this.array),this._dirty=!0,this},invert:function(){return Ae.invert(this.array,this.array),this._dirty=!0,this},mul:function(e){return Ae.mul(this.array,this.array,e.array),this._dirty=!0,this},mulLeft:function(e){return Ae.mul(this.array,e.array,this.array),this._dirty=!0,this},multiply:function(e){return Ae.multiply(this.array,this.array,e.array),this._dirty=!0,this},multiplyLeft:function(e){return Ae.multiply(this.array,e.array,this.array),this._dirty=!0,this},rotate:function(e){return Ae.rotate(this.array,this.array,e),this._dirty=!0,this},scale:function(e){return Ae.scale(this.array,this.array,e.array),this._dirty=!0,this},translate:function(e){return Ae.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)}};$e.copy=function(e,t){return Ae.copy(e.array,t.array),e._dirty=!0,e};$e.determinant=function(e){return Ae.determinant(e.array)};$e.identity=function(e){return Ae.identity(e.array),e._dirty=!0,e};$e.invert=function(e,t){return Ae.invert(e.array,t.array),e._dirty=!0,e};$e.mul=function(e,t,r){return Ae.mul(e.array,t.array,r.array),e._dirty=!0,e};$e.multiply=$e.mul;$e.rotate=function(e,t,r){return Ae.rotate(e.array,t.array,r),e._dirty=!0,e};$e.scale=function(e,t,r){return Ae.scale(e.array,t.array,r.array),e._dirty=!0,e};$e.translate=function(e,t,r){return Ae.translate(e.array,t.array,r.array),e._dirty=!0,e};const Ou=$e;var be=function(){this.array=ee.create(),this._dirty=!0};be.prototype={constructor:be,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 be().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)}};be.adjoint=function(e,t){return ee.adjoint(e.array,t.array),e._dirty=!0,e};be.copy=function(e,t){return ee.copy(e.array,t.array),e._dirty=!0,e};be.determinant=function(e){return ee.determinant(e.array)};be.identity=function(e){return ee.identity(e.array),e._dirty=!0,e};be.invert=function(e,t){return ee.invert(e.array,t.array),e};be.mul=function(e,t,r){return ee.mul(e.array,t.array,r.array),e._dirty=!0,e};be.multiply=be.mul;be.fromMat2d=function(e,t){return ee.fromMat2d(e.array,t.array),e._dirty=!0,e};be.fromMat4=function(e,t){return ee.fromMat4(e.array,t.array),e._dirty=!0,e};be.fromQuat=function(e,t){return ee.fromQuat(e.array,t.array),e._dirty=!0,e};be.normalFromMat4=function(e,t){return ee.normalFromMat4(e.array,t.array),e._dirty=!0,e};be.rotate=function(e,t,r){return ee.rotate(e.array,t.array,r),e._dirty=!0,e};be.scale=function(e,t,r){return ee.scale(e.array,t.array,r.array),e._dirty=!0,e};be.transpose=function(e,t){return ee.transpose(e.array,t.array),e._dirty=!0,e};be.translate=function(e,t,r){return ee.translate(e.array,t.array,r.array),e._dirty=!0,e};const Iu=be;var Bu={_animators:null,getAnimators:function(){return this._animators=this._animators||[],this._animators},animate:function(e,t){this._animators=this._animators||[];var r=this,n;if(e){for(var i=e.split("."),a=r,s=0,o=i.length;s<o;s++)a&&(a=a[i[s]]);a&&(n=a)}else n=r;if(n==null)throw new Error("Target "+e+" not exists");var l=this._animators,c=new ao(n,t),u=this;return c.during(function(){u.__zr&&u.__zr.refresh()}).done(function(){var h=l.indexOf(c);h>=0&&l.splice(h,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,n=0;n<r;n++)t[n].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 Fu=Bu,Uu="\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",Hu="\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",zu="@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",Gu="/**\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",Vu="@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",ku="@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",Wu="@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,Fu);L.import(Uu);L.import(as);L.import(Hu);L.import(zu);L.import(Gu);L.import(Vu);L.import(ku);L.import(Wu);function Xu(e){return!e||e==="none"}function ms(e){return e instanceof HTMLCanvasElement||e instanceof HTMLImageElement||e instanceof Image}function $u(e){return e.getZr&&e.setOption}var ju=Pt.prototype.addToScene,qu=Pt.prototype.removeFromScene;Pt.prototype.addToScene=function(e){if(ju.call(this,e),this.__zr){var t=this.__zr;e.traverse(function(r){r.__zr=t,r.addAnimatorsToZr&&r.addAnimatorsToZr(t)})}};Pt.prototype.removeFromScene=function(e){qu.call(this,e),e.traverse(function(t){var r=t.__zr;t.__zr=null,r&&t.removeAnimatorsFromZr&&t.removeAnimatorsFromZr(r)})};wt.prototype.setTextureImage=function(e,t,r,n){if(this.shader){var i=r.getZr(),a=this,s;return a.autoUpdateTextureStatus=!1,a.disableTexture(e),Xu(t)||(s=$.loadTexture(t,r,n,function(o){a.enableTexture(e),i&&i.refresh()}),a.set(e,s)),s}};var $={};$.Renderer=Er;$.Node=dt;$.Mesh=Ei;$.Shader=L;$.Material=wt;$.Texture=q;$.Texture2D=ie;$.Geometry=Ee;$.SphereGeometry=Au;$.PlaneGeometry=Ci;$.CubeGeometry=vs;$.AmbientLight=wu;$.DirectionalLight=Cu;$.PointLight=Mu;$.SpotLight=Nu;$.PerspectiveCamera=Me;$.OrthographicCamera=Pr;$.Vector2=Ze;$.Vector3=P;$.Vector4=Pu;$.Quaternion=ss;$.Matrix2=Du;$.Matrix2d=Ou;$.Matrix3=Iu;$.Matrix4=z;$.Plane=hs;$.Ray=sn;$.BoundingBox=Ve;$.Frustum=Si;var Yr=null;function Yu(){return Yr!==null||(Yr=Vt.createBlank("rgba(255,255,255,0)").image),Yr}function ya(e){return Math.pow(2,Math.round(Math.log(e)/Math.LN2))}function Ta(e){if((e.wrapS===q.REPEAT||e.wrapT===q.REPEAT)&&e.image){var t=ya(e.width),r=ya(e.height);if(t!==e.width||r!==e.height){var n=document.createElement("canvas");n.width=t,n.height=r;var i=n.getContext("2d");i.drawImage(e.image,0,0,t,r),e.image=n}}}$.loadTexture=function(e,t,r,n){typeof r=="function"&&(n=r,r={}),r=r||{};for(var i=Object.keys(r).sort(),a="",s=0;s<i.length;s++)a+=i[s]+"_"+r[i[s]]+"_";var o=t.__textureCache=t.__textureCache||new so(20);if($u(e)){var l=e.__textureid__,c=o.get(a+l);if(c)c.texture.surface.setECharts(e),n&&n(c.texture);else{var u=new au(e);u.onupdate=function(){t.getZr().refresh()},c={texture:u.getTexture()};for(var s=0;s<i.length;s++)c.texture[i[s]]=r[i[s]];l=e.__textureid__||"__ecgl_ec__"+c.texture.__uid__,e.__textureid__=l,o.put(a+l,c),n&&n(c.texture)}return c.texture}else if(ms(e)){var l=e.__textureid__,c=o.get(a+l);if(!c){c={texture:new $.Texture2D({image:e})};for(var s=0;s<i.length;s++)c.texture[i[s]]=r[i[s]];l=e.__textureid__||"__ecgl_image__"+c.texture.__uid__,e.__textureid__=l,o.put(a+l,c),Ta(c.texture),n&&n(c.texture)}return c.texture}else{var c=o.get(a+e);if(c)c.callbacks?c.callbacks.push(n):n&&n(c.texture);else if(e.match(/.hdr$|^data:application\/octet-stream/)){c={callbacks:[n]};var h=Vt.loadTexture(e,{exposure:r.exposure,fileType:"hdr"},function(){h.dirty(),c.callbacks.forEach(function(v){v&&v(h)}),c.callbacks=null});c.texture=h,o.put(a+e,c)}else{for(var h=new $.Texture2D({image:new Image}),s=0;s<i.length;s++)h[i[s]]=r[i[s]];c={texture:h,callbacks:[n]};var d=h.image;d.onload=function(){h.image=d,Ta(h),h.dirty(),c.callbacks.forEach(function(_){_&&_(h)}),c.callbacks=null},d.crossOrigin="Anonymous",d.src=e,h.image=Yu(),o.put(a+e,c)}return c.texture}};$.createAmbientCubemap=function(e,t,r,n){e=e||{};var i=e.texture,a=rt.firstNotNull(e.exposure,1),s=new vu({intensity:rt.firstNotNull(e.specularIntensity,1)}),o=new mu({intensity:rt.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=$.loadTexture(i,r,{exposure:a},function(){s.cubemap.flipY=!1,s.prefilter(t,32),o.coefficients=yu.projectEnvironmentMap(t,s.cubemap,{lod:1}),n&&n()}),{specular:s,diffuse:o}};$.createBlankTexture=Vt.createBlank;$.isImage=ms;$.additiveBlend=function(e){e.blendEquation(e.FUNC_ADD),e.blendFunc(e.SRC_ALPHA,e.ONE)};$.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=ka(e||"#000",t)||[0,0,0,0],t[0]/=255,t[1]/=255,t[2]/=255,t)};$.directionFromAlphaBeta=function(e,t){var r=e/180*Math.PI+Math.PI/2,n=-t/180*Math.PI+Math.PI/2,i=[],a=Math.sin(r);return i[0]=a*Math.cos(n),i[1]=-Math.cos(r),i[2]=a*Math.sin(n),i};$.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};$.COMMON_SHADERS=["lambert","color","realistic","hatching","shadow"];$.createShader=function(e){e==="ecgl.shadow"&&(e="ecgl.displayShadow");var t=L.source(e+".vertex"),r=L.source(e+".fragment");t||console.error("Vertex shader of '%s' not exits",e),r||console.error("Fragment shader of '%s' not exits",e);var n=new L(t,r);return n.name=e,n};$.createMaterial=function(e,t){t instanceof Array||(t=[t]);var r=$.createShader(e),n=new wt({shader:r});return t.forEach(function(i){typeof i=="string"&&n.define(i)}),n};$.setMaterialFromModel=function(e,t,r,n){t.autoUpdateTextureStatus=!1;var i=r.getModel(e+"Material"),a=i.get("detailTexture"),s=rt.firstNotNull(i.get("textureTiling"),1),o=rt.firstNotNull(i.get("textureOffset"),0);typeof s=="number"&&(s=[s,s]),typeof o=="number"&&(o=[o,o]);var l=s[0]>1||s[1]>1?$.Texture.REPEAT:$.Texture.CLAMP_TO_EDGE,c={anisotropic:8,wrapS:l,wrapT:l};if(e==="realistic"){var u=i.get("roughness"),h=i.get("metalness");h!=null?isNaN(h)&&(t.setTextureImage("metalnessMap",h,n,c),h=rt.firstNotNull(i.get("metalnessAdjust"),.5)):h=0,u!=null?isNaN(u)&&(t.setTextureImage("roughnessMap",u,n,c),u=rt.firstNotNull(i.get("roughnessAdjust"),.5)):u=.5;var d=i.get("normalTexture");t.setTextureImage("detailMap",a,n,c),t.setTextureImage("normalMap",d,n,c),t.set({roughness:u,metalness:h,detailUvRepeat:s,detailUvOffset:o})}else if(e==="lambert")t.setTextureImage("detailMap",a,n,c),t.set({detailUvRepeat:s,detailUvOffset:o});else if(e==="color")t.setTextureImage("detailMap",a,n,c),t.set({detailUvRepeat:s,detailUvOffset:o});else if(e==="hatching"){var f=i.get("hatchingTextures")||[];f.length<6;for(var v=0;v<6;v++)t.setTextureImage("hatch"+(v+1),f[v],n,{anisotropic:8,wrapS:$.Texture.REPEAT,wrapT:$.Texture.REPEAT});t.set({detailUvRepeat:s,detailUvOffset:o})}};$.updateVertexAnimation=function(e,t,r,n){var i=n.get("animation"),a=n.get("animationDurationUpdate"),s=n.get("animationEasingUpdate"),o=r.shadowDepthMaterial;if(i&&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 k=$;var ce=function(e,t){this.id=e,this.zr=t;try{this.renderer=new Er({clearBit:0,devicePixelRatio:t.painter.dpr,preserveDrawingBuffer:!0,premultipliedAlpha:!0}),this.renderer.resize(t.painter.getWidth(),t.painter.getHeight())}catch(n){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(n);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 vc({renderer:this.renderer}),this._viewsToDispose=[],this._accumulatingId=0,this._zrEventProxy=new Wa({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(n){n.__zr=r,n.addAnimatorsToZr&&n.addAnimatorsToZr(r)})}};function ps(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(ps,this),e.layer=null,this._viewsToDispose.push(e))}};ce.prototype.removeViewsAll=function(){this.views.forEach(function(e){e.scene.traverse(ps,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?k.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 Zu=1;ce.prototype._startAccumulating=function(e){var t=this;this._stopAccumulating();for(var r=!1,n=0;n<this.views.length;n++)r=this.views[n].needsAccumulate()||r;if(!r)return;function i(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?i(a):lo(function(){i(a)}))}}this._accumulatingId=Zu++,e?i(t._accumulatingId):this._accumulatingTimeout=setTimeout(function(){i(t._accumulatingId)},50)};ce.prototype._trackAndClean=function(){var e=[],t=[];this._textureList&&(ln(this._textureList),ln(this._geometriesList));for(var r=0;r<this.views.length;r++)Ku(this.views[r].scene,e,t);this._textureList&&(cn(this.renderer,this._textureList),cn(this.renderer,this._geometriesList)),this._textureList=e,this._geometriesList=t};function ln(e){for(var t=0;t<e.length;t++)e[t].__used__=0}function cn(e,t){for(var r=0;r<t.length;r++)t[r].__used__||t[r].dispose(e)}function Zr(e,t){e.__used__=e.__used__||0,e.__used__++,e.__used__===1&&t.push(e)}function Ku(e,t,r){var n,i;e.traverse(function(s){if(s.isRenderable()){var o=s.geometry,l=s.material;if(l!==n)for(var c=l.getTextureUniforms(),u=0;u<c.length;u++){var h=c[u],d=l.uniforms[h].value;if(d){if(d instanceof q)Zr(d,t);else if(d instanceof Array)for(var f=0;f<d.length;f++)d[f]instanceof q&&Zr(d[f],t)}}o!==i&&Zr(o,r),n=l,i=o}});for(var a=0;a<e.lights.length;a++)e.lights[a].cubemap&&Zr(e.lights[a].cubemap,t)}ce.prototype.dispose=function(){this._disposed||(this._stopAccumulating(),this._textureList&&(ln(this._textureList),ln(this._geometriesList),cn(this.renderer,this._textureList),cn(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,n=this._hovered;this._hovered=t,n&&r!==n.target&&(n.relatedTarget=r,this._dispatchEvent("mouseout",e,n),this.zr.setCursorStyle("default")),this._dispatchEvent("mousemove",e,t),t&&(this.zr.setCursorStyle("pointer"),(!n||r!==n.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 n=this.pickObject(e.offsetX,e.offsetY);n&&(this._dispatchEvent(e.type,e,n),this._dispatchDataEvent(e.type,e,n));var i=this._clickToSetFocusPoint(e);if(i){var a=i.view.setDOFFocusOnPoint(i.distance);a&&this.zr.refresh()}}}};ce.prototype._clickToSetFocusPoint=function(e){for(var t=this.renderer,r=t.viewport,n=this.views.length-1;n>=0;n--){var i=this.views[n];if(i.hasDOF()&&i.containPoint(e.offsetX,e.offsetY)){this._picking.scene=i.scene,this._picking.camera=i.camera,t.viewport=i.viewport;var a=this._picking.pick(e.offsetX,e.offsetY,!0);if(a)return a.view=i,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=[],n=this.renderer,i=n.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,n.viewport=s.viewport,this._picking.pickAll(e,t,r))}return n.viewport=i,r.sort(function(o,l){return o.distance-l.distance}),r[0]};ce.prototype._dispatchEvent=function(e,t,r){r||(r={});var n=r.target;for(r.cancelBubble=!1,r.event=t,r.type=e,r.offsetX=t.offsetX,r.offsetY=t.offsetY;n&&(n.trigger(e,r),n=n.getParent(),!r.cancelBubble););this._dispatchToView(e,r)};ce.prototype._dispatchDataEvent=function(e,t,r){var n=r&&r.target,i=n&&n.dataIndex,a=n&&n.seriesIndex,s=n&&n.eventData,o=!1,l=this._zrEventProxy;l.x=t.offsetX,l.y=t.offsetY,l.update();var c={target:l};const u=oo(l);e==="mousemove"&&(i!=null?i!==this._lastDataIndex&&(parseInt(this._lastDataIndex,10)>=0&&(u.dataIndex=this._lastDataIndex,u.seriesIndex=this._lastSeriesIndex,this.zr.handler.dispatchToElement(c,"mouseout",t)),o=!0):s!=null&&s!==this._lastEventData&&(this._lastEventData!=null&&(u.eventData=this._lastEventData,this.zr.handler.dispatchToElement(c,"mouseout",t)),o=!0),this._lastEventData=s,this._lastDataIndex=i,this._lastSeriesIndex=a),u.eventData=s,u.dataIndex=i,u.seriesIndex=a,(s!=null||parseInt(i,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,xi);const gs=ce;var Qu=["bar3D","line3D","map3D","scatter3D","surface","lines3D","scatterGL","scatter3D"];function Tr(e,t){if(e&&e[t]&&(e[t].normal||e[t].emphasis)){var r=e[t].normal,n=e[t].emphasis;r&&(e[t]=r),n&&(e.emphasis=e.emphasis||{},e.emphasis[t]=n)}}function Ju(e){Tr(e,"itemStyle"),Tr(e,"lineStyle"),Tr(e,"areaStyle"),Tr(e,"label")}function Kr(e){e&&(e instanceof Array||(e=[e]),Sr(e,function(t){if(t.axisLabel){var r=t.axisLabel;Object.assign(r,r.textStyle),r.textStyle=null}}))}function eh(e){Sr(e.series,function(t){co(Qu,t.type)>=0&&(Ju(t),t.coordinateSystem==="mapbox"&&(t.coordinateSystem="mapbox3D",e.mapbox3D=e.mapbox))}),Kr(e.xAxis3D),Kr(e.yAxis3D),Kr(e.zAxis3D),Kr(e.grid3D),Tr(e.geo3D)}function xs(e){this._layers={},this._zr=e}xs.prototype.update=function(e,t){var r=this,n=t.getZr();if(!n.getWidth()||!n.getHeight()){console.warn("Dom has no width or height");return}function i(o){n.setSleepAfterStill(0);var l;o.coordinateSystem&&o.coordinateSystem.model,l=o.get("zlevel");var c=r._layers,u=c[l];if(!u){if(u=c[l]=new gs("gl-"+l,n),n.painter.isSingleCanvas()){u.virtual=!0;var h=new vo({z:1e4,style:{image:u.renderer.canvas},silent:!0});u.__hostImage=h,n.add(h)}n.painter.insertLayer(l,u)}return u.__hostImage&&u.__hostImage.setStyle({width:u.renderer.getWidth(),height:u.renderer.getHeight()}),u}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),u=l.coordinateSystem;if(c.__ecgl__){var h;if(u){if(!u.viewGL){console.error("Can't find viewGL in coordinateSystem of component "+l.id);return}h=u.viewGL}else{if(!l.viewGL){console.error("Can't find viewGL of component "+l.id);return}h=u.viewGL}var h=u.viewGL,d=i(l);d.addView(h),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 u=c&&c.viewGL||l.viewGL,h=i(o);h.addView(u),l.afterRender&&l.afterRender(o,e,t,h),a(l.groupGL,o.get("silent"))}})};uo(function(e){var t=e.getZr(),r=t.painter.dispose;t.painter.dispose=function(){typeof this.eachOtherLayer=="function"&&this.eachOtherLayer(function(n){n instanceof gs&&n.dispose()}),r.call(this)},t.painter.getRenderedCanvas=function(n){if(n=n||{},this._singleCanvas)return this._layers[0].dom;var i=document.createElement("canvas"),a=n.pixelRatio||this.dpr;i.width=this.getWidth()*a,i.height=this.getHeight()*a;var s=i.getContext("2d");s.dpr=a,s.clearRect(0,0,i.width,i.height),n.backgroundColor&&(s.fillStyle=n.backgroundColor,s.fillRect(0,0,i.width,i.height));var o=this.storage.getDisplayList(!0),l={},c,u=this;function h(_,m){var p=u._zlevelList;_==null&&(_=-1/0);for(var y,g=0;g<p.length;g++){var x=p[g],E=u._layers[x];if(!E.__builtin__&&x>_&&x<m){y=E;break}}y&&y.renderToCanvas&&(s.save(),y.renderToCanvas(s),s.restore())}for(var d={ctx:s},f=0;f<o.length;f++){var v=o[f];v.zlevel!==c&&(h(c,v.zlevel),c=v.zlevel),this._doPaintEl(v,d,!0,null,l)}return h(c,1/0),i}});ho(function(e,t){var r=t.getZr(),n=r.__egl=r.__egl||new xs(r);n.update(e,t)});fo(eh);const th={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)}},rh={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"}}},nh={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 xn=Xa.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}}});xt(xn.prototype,th);xt(xn.prototype,rh);xt(xn.prototype,nh);const ih=xn;var gr=rt.firstNotNull,Ea={left:0,middle:1,right:2};function Aa(e){return e instanceof Array||(e=[e,e]),e}var ys=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 Ze,_panVelocity:new Ze,_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,n=t.baseOrthoSize||1,i=e.get("projection");i!=="perspective"&&i!=="orthographic"&&i!=="isometric"&&(i="perspective"),this._projection=i,this.viewGL.setProjection(i);var a=e.get("distance")+r,s=e.get("orthographicSize")+n;[["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]]=gr(e.get(d[0]),d[1])},this),this.minDistance+=r,this.maxDistance+=r,this.minOrthographicSize+=n,this.maxOrthographicSize+=n;var o=e.ecModel,l={};["animation","animationDurationUpdate","animationEasingUpdate"].forEach(function(d){l[d]=gr(e.get(d),o&&o.get(d))});var c=gr(t.alpha,e.get("alpha"))||0,u=gr(t.beta,e.get("beta"))||0,h=gr(t.center,e.get("center"))||[0,0,0];l.animation&&l.animationDurationUpdate>0&&this._notFirst?this.animateTo({alpha:c,beta:u,center:h,distance:a,orthographicSize:s,easing:l.animationEasingUpdate,duration:l.animationDurationUpdate}):(this.setDistance(a),this.setAlpha(c),this.setBeta(u),this.setCenter(h),this.setOrthographicSize(s)),this._notFirst=!0,this._validateProperties()},_validateProperties:function(){},animateTo:function(e){var t=this.zr,r=this,n={},i={};return e.distance!=null&&(n.distance=this.getDistance(),i.distance=e.distance),e.orthographicSize!=null&&(n.orthographicSize=this.getOrthographicSize(),i.orthographicSize=e.orthographicSize),e.alpha!=null&&(n.alpha=this.getAlpha(),i.alpha=e.alpha),e.beta!=null&&(n.beta=this.getBeta(),i.beta=e.beta),e.center!=null&&(n.center=this.getCenter(),i.center=e.center),this._addAnimator(t.animation.animate(n).when(e.duration||1e3,i).during(function(){n.alpha!=null&&r.setAlpha(n.alpha),n.beta!=null&&r.setBeta(n.beta),n.distance!=null&&r.setDistance(n.distance),n.center!=null&&r.setCenter(n.center),n.orthographicSize!=null&&r.setOrthographicSize(n.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,n=r/this.viewGL.viewport.height*this.viewGL.viewport.width;t.left=-n/2,t.right=n/2,t.top=r/2,t.bottom=-r/2},_updatePan:function(e){var t=this._panVelocity,r=this._distance,n=this.getCamera(),i=n.worldTransform.y,a=n.worldTransform.x;this._center.scaleAndAdd(a,-t.x*r/200).scaleAndAdd(i,-t.y*r/200),this._vectorDamping(t,0)},_updateTransform:function(){var e=this.getCamera(),t=new P,r=this._theta+Math.PI/2,n=this._phi+Math.PI/2,i=Math.sin(r);t.x=i*Math.cos(n),t.y=-Math.cos(r),t.z=i*Math.sin(n),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===Ea[this.rotateMouseButton]?this._mode="rotate":e.event.button===Ea[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=Aa(this.panSensitivity),r=Aa(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,n=e.offsetY;if(!(this.viewGL&&!this.viewGL.containPoint(r,n))){var i;this._projection==="perspective"?i=Math.max(Math.max(Math.min(this._distance-this.minDistance,this.maxDistance-this._distance))/20,.5):i=Math.max(Math.max(Math.min(this._orthoSize-this.minOrthographicSize,this.maxOrthographicSize-this._orthoSize))/20,.5),this._zoomSpeed=(t>0?-1:1)*i*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(ys.prototype,"autoRotate",{get:function(e){return this._autoRotate},set:function(e){this._autoRotate=e,this._rotating=e}});const ah=ys,Mi={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()}},yn={vec2:H,vec3:T,vec4:D,mat2:ye,mat2d:Ae,mat3:ee,mat4:C,quat:j};var zn=yn.vec3,Sa=[[0,0],[1,1]],Ts=Ee.extend(function(){return{segmentScale:1,dynamic:!0,useNativeLine:!0,attributes:{position:new Ee.Attribute("position","float",3,"POSITION"),positionPrev:new Ee.Attribute("positionPrev","float",3),positionNext:new Ee.Attribute("positionNext","float",3),prevPositionPrev:new Ee.Attribute("prevPositionPrev","float",3),prevPosition:new Ee.Attribute("prevPosition","float",3),prevPositionNext:new Ee.Attribute("prevPositionNext","float",3),offset:new Ee.Attribute("offset","float",1),color:new Ee.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,n){var i=zn.dist(e,t)+zn.dist(r,t)+zn.dist(n,r),a=1/(i+1)*this.segmentScale;return a},getCubicCurveVertexCount:function(e,t,r,n){var i=this._getCubicCurveApproxStep(e,t,r,n),a=Math.ceil(1/i);return this.useNativeLine?a*2:a*2+2},getCubicCurveTriangleCount:function(e,t,r,n){var i=this._getCubicCurveApproxStep(e,t,r,n),a=Math.ceil(1/i);return this.useNativeLine?0:a*2},getLineVertexCount:function(){return this.getPolylineVertexCount(Sa)},getLineTriangleCount:function(){return this.getPolylineTriangleCount(Sa)},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,n,i,a){a==null&&(a=1);for(var s=e[0],o=e[1],l=e[2],c=t[0],u=t[1],h=t[2],d=r[0],f=r[1],v=r[2],_=n[0],m=n[1],p=n[2],y=this._getCubicCurveApproxStep(e,t,r,n),g=y*y,x=g*y,E=3*y,S=3*g,R=6*g,w=6*x,M=s-c*2+d,F=o-u*2+f,b=l-h*2+v,U=(c-d)*3-s+_,I=(u-f)*3-o+m,N=(h-v)*3-l+p,G=s,B=o,Y=l,O=(c-s)*E+M*S+U*x,he=(u-o)*E+F*S+I*x,V=(h-l)*E+b*S+N*x,xe=M*R+U*w,ae=F*R+I*w,ve=b*R+N*w,_e=U*w,Ie=I*w,Be=N*w,Re=0,ze=0,Ye=Math.ceil(1/y),Fe=new Float32Array((Ye+1)*3),Fe=[],nt=0,ze=0;ze<Ye+1;ze++)Fe[nt++]=G,Fe[nt++]=B,Fe[nt++]=Y,G+=O,B+=he,Y+=V,O+=xe,he+=ae,V+=ve,xe+=_e,ae+=Ie,ve+=Be,Re+=y,Re>1&&(G=O>0?Math.min(G,_):Math.max(G,_),B=he>0?Math.min(B,m):Math.max(B,m),Y=V>0?Math.min(Y,p):Math.max(Y,p));return this.addPolyline(Fe,i,a)},addLine:function(e,t,r,n){return this.addPolyline([e,t],r,n)},addPolyline:function(e,t,r,n,i){if(e.length){var a=typeof e[0]!="number";if(i==null&&(i=a?e.length:e.length/3),!(i<2)){n==null&&(n=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===i,o=this.attributes.position,l=this.attributes.positionPrev,c=this.attributes.positionNext,u=this.attributes.color,h=this.attributes.offset,d=this.indices,f=this._vertexOffset,v,_;r=Math.max(r,.01);for(var m=n;m<i;m++){if(a)v=e[m],s?_=t[m]:_=t;else{var p=m*3;if(v=v||[],v[0]=e[p],v[1]=e[p+1],v[2]=e[p+2],s){var y=m*4;_=_||[],_[0]=t[y],_[1]=t[y+1],_[2]=t[y+2],_[3]=t[y+3]}else _=t}if(this.useNativeLine?m>1&&(o.copy(f,f-1),u.copy(f,f-1),f++):(m<i-1&&(l.set(f+2,v),l.set(f+3,v)),m>0&&(c.set(f-2,v),c.set(f-1,v)),o.set(f,v),o.set(f+1,v),u.set(f,_),u.set(f+1,_),h.set(f,r/2),h.set(f+1,-r/2),f+=2),this.useNativeLine)u.set(f,_),o.set(f,v),f++;else if(m>0){var g=this._triangleOffset*3,d=this.indices;d[g]=f-4,d[g+1]=f-3,d[g+2]=f-2,d[g+3]=f-3,d[g+4]=f-1,d[g+5]=f-2,this._triangleOffset+=2}}if(!this.useNativeLine){var x=this._vertexOffset,E=this._vertexOffset+i*2;l.copy(x,x+2),l.copy(x+1,x+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],n=e<this._itemVertexOffsets.length-1?this._itemVertexOffsets[e+1]:this._vertexOffset,i=r;i<n;i++)this.attributes.color.set(i,t);this.dirty("color")},currentTriangleOffset:function(){return this._triangleOffset},currentVertexOffset:function(){return this._vertexOffset}});Ir(Ts.prototype,Mi);const Li=Ts;function un(e,t,r,n,i,a,s){this._zr=e,this._x=0,this._y=0,this._rowHeight=0,this.width=n,this.height=i,this.offsetX=t,this.offsetY=r,this.dpr=s,this.gap=a}un.prototype={constructor:un,clear:function(){this._x=0,this._y=0,this._rowHeight=0},add:function(e,t,r){var n=e.getBoundingRect();t==null&&(t=n.width),r==null&&(r=n.height),t*=this.dpr,r*=this.dpr,this._fitElement(e,t,r);var i=this._x,a=this._y,s=this.width*this.dpr,o=this.height*this.dpr,l=this.gap;if(i+t+l>s&&(i=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+i,e.y+=this.offsetY*this.dpr+a,this._zr.add(e);var c=[this.offsetX/this.width,this.offsetY/this.height],u=[[i/s+c[0],a/o+c[1]],[(i+t)/s+c[0],(a+r)/o+c[1]]];return u},_fitElement:function(e,t,r){var n=e.getBoundingRect(),i=t/n.width,a=r/n.height;e.x=-n.x*i,e.y=-n.y*a,e.scaleX=i,e.scaleY=a,e.update()}};function ai(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 ie({image:t,flipY:!1});var r=this;this._zr=_o(t);var n=this._zr.refreshImmediately;this._zr.refreshImmediately=function(){n.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 un(this._zr,0,0,e.width,e.height,this._gap,this._dpr)],this._nodeWidth=e.width,this._nodeHeight=e.height,this._currentNodeIdx=0}ai.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,n=r*this._nodeWidth%e,i=Math.floor(r*this._nodeWidth/e)*this._nodeHeight;if(!(i>=e)){var a=(n+this._nodeWidth)*this._dpr,s=(i+this._nodeHeight)*this._dpr;try{this._zr.resize({width:a,height:s})}catch{this._canvas.width=a,this._canvas.height=s}var o=new un(this._zr,n,i,this._nodeWidth,this._nodeHeight,this._gap,this._dpr);return this._textureAtlasNodes.push(o),o}},add:function(e,t,r){if(this._coords[e.id])return this._coords[e.id];var n=this._getCurrentNode().add(e,t,r);if(!n){var i=this._expand();if(!i)return;n=i.add(e,t,r)}return this._coords[e.id]=n,n},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 si(){}si.prototype={constructor:si,setScene:function(e){this._scene=e,this._skybox&&this._skybox.attachScene(this._scene)},initLight:function(e){this._lightRoot=e,this.mainLight=new k.DirectionalLight({shadowBias:.005}),this.ambientLight=new k.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,n=e.getModel("light"),i=n.getModel("main"),a=n.getModel("ambient");t.intensity=i.get("intensity"),r.intensity=a.get("intensity"),t.color=k.parseColor(i.get("color")).slice(0,3),r.color=k.parseColor(a.get("color")).slice(0,3);var s=i.get("alpha")||0,o=i.get("beta")||0;t.position.setArray(k.directionFromAlphaBeta(s,o)),t.lookAt(k.Vector3.ZERO),t.castShadow=i.get("shadow"),t.shadowResolution=k.getShadowResolution(i.get("shadowQuality"))},updateAmbientCubemap:function(e,t,r){var n=t.getModel("light.ambientCubemap"),i=n.get("texture");if(i){this._cubemapLightsCache=this._cubemapLightsCache||{};var a=this._cubemapLightsCache[i];if(!a){var s=this;a=this._cubemapLightsCache[i]=k.createAmbientCubemap(n.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 n=t.get("environment"),i=this;function a(){return i._skybox=i._skybox||new Nr,i._skybox}var s=a();if(n&&n!=="none")if(n==="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 n=="object"&&n.colorStops||typeof n=="string"&&ka(n)){this._isSkyboxFromAmbientCubemap=!1;var l=new k.Texture2D({anisotropic:8,flipY:!1});s.setEnvironmentMap(l);var c=l.image=document.createElement("canvas");c.width=c.height=16;var u=c.getContext("2d"),h=new Wa({shape:{x:0,y:0,width:16,height:16},style:{fill:n}});mo(u,h),s.attachScene(this._scene)}else{this._isSkyboxFromAmbientCubemap=!1;var l=k.loadTexture(n,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&&n!=="auto"&&!(n.match&&n.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 It=yn.vec3,Es=Ee.extend(function(){return{segmentScale:1,useNativeLine:!0,attributes:{position:new Ee.Attribute("position","float",3,"POSITION"),normal:new Ee.Attribute("normal","float",3,"NORMAL"),color:new Ee.Attribute("color","float",4,"COLOR")}}},{resetOffset:function(){this._vertexOffset=0,this._faceOffset=0},setQuadCount:function(e){var t=this.attributes,r=this.getQuadVertexCount()*e,n=this.getQuadTriangleCount()*e;this.vertexCount!==r&&(t.position.init(r),t.normal.init(r),t.color.init(r)),this.triangleCount!==n&&(this.indices=r>65535?new Uint32Array(n*3):new Uint16Array(n*3))},getQuadVertexCount:function(){return 4},getQuadTriangleCount:function(){return 2},addQuad:function(){var e=It.create(),t=It.create(),r=It.create(),n=[0,3,1,3,2,1];return function(i,a){var s=this.attributes.position,o=this.attributes.normal,l=this.attributes.color;It.sub(e,i[1],i[0]),It.sub(t,i[2],i[1]),It.cross(r,e,t),It.normalize(r,r);for(var c=0;c<4;c++)s.set(this._vertexOffset+c,i[c]),l.set(this._vertexOffset+c,a),o.set(this._vertexOffset+c,r);for(var u=this._faceOffset*3,c=0;c<6;c++)this.indices[u+c]=n[c]+this._vertexOffset;this._vertexOffset+=4,this._faceOffset+=2}}()});Ir(Es.prototype,Mi);const sh=Es;var oi=rt.firstNotNull,oh={x:0,y:2,z:1};function lh(e,t,r,n){var i=[0,0,0],a=n<0?r.getExtentMin():r.getExtentMax();i[oh[r.dim]]=a,e.position.setArray(i),e.rotation.identity(),t.distance=-Math.abs(a),t.normal.set(0,0,0),r.dim==="x"?(e.rotation.rotateY(n*Math.PI/2),t.normal.x=-n):r.dim==="z"?(e.rotation.rotateX(-n*Math.PI/2),t.normal.y=-n):(n>0&&e.rotation.rotateY(Math.PI),t.normal.z=-n)}function Tn(e,t,r){this.rootNode=new k.Node;var n=new k.Mesh({geometry:new Li({useNativeLine:!1}),material:t,castShadow:!1,ignorePicking:!0,$ignorePicking:!0,renderOrder:1}),i=new k.Mesh({geometry:new sh,material:r,castShadow:!1,culling:!1,ignorePicking:!0,$ignorePicking:!0,renderOrder:0});this.rootNode.add(i),this.rootNode.add(n),this.faceInfo=e,this.plane=new k.Plane,this.linesMesh=n,this.quadsMesh=i}Tn.prototype.update=function(e,t,r){var n=e.coordinateSystem,i=[n.getAxis(this.faceInfo[0]),n.getAxis(this.faceInfo[1])],a=this.linesMesh.geometry,s=this.quadsMesh.geometry;a.convertToDynamicArray(!0),s.convertToDynamicArray(!0),this._updateSplitLines(a,i,e,r),this._udpateSplitAreas(s,i,e,r),a.convertToTypedArray(),s.convertToTypedArray();var o=n.getAxis(this.faceInfo[2]);lh(this.rootNode,this.plane,o,this.faceInfo[3])};Tn.prototype._updateSplitLines=function(e,t,r,n){var i=n.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 u=c.getModel("lineStyle"),h=u.get("color"),d=oi(u.get("opacity"),1),f=oi(u.get("width"),1);h=Ar(h)?h:[h];for(var v=a.getTicksCoords({tickModel:c}),_=0,m=0;m<v.length;m++){var p=v[m].coord,y=k.parseColor(h[_%h.length]);y[3]*=d;var g=[0,0,0],x=[0,0,0];g[s]=x[s]=p,g[1-s]=l[0],x[1-s]=l[1],e.addLine(g,x,y,f*i),_++}}}})};Tn.prototype._udpateSplitAreas=function(e,t,r,n){t.forEach(function(i,a){var s=i.model,o=t[1-a].getExtent();if(!i.scale.isBlank()){var l=s.getModel("splitArea",r.getModel("splitArea"));if(l.get("show")){var c=l.getModel("areaStyle"),u=c.get("color"),h=oi(c.get("opacity"),1);u=Ar(u)?u:[u];for(var d=i.getTicksCoords({tickModel:l,clamp:!0}),f=0,v=[0,0,0],_=[0,0,0],m=0;m<d.length;m++){var p=d[m].coord,y=[0,0,0],g=[0,0,0];if(y[a]=g[a]=p,y[1-a]=o[0],g[1-a]=o[1],m===0){v=y,_=g;continue}var x=k.parseColor(u[f%u.length]);x[3]*=h,e.addQuad([v,y,g,_],x),v=y,_=g,f++}}}})};var wa=[0,1,2,0,2,3],As=Ee.extend(function(){return{attributes:{position:new Ee.Attribute("position","float",3,"POSITION"),texcoord:new Ee.Attribute("texcoord","float",2,"TEXCOORD_0"),offset:new Ee.Attribute("offset","float",2),color:new Ee.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,n,i){r==null&&(r="left"),n==null&&(n="top");var a,s,o,l;switch(i=i||0,r){case"left":a=i,o=t[0]+i;break;case"center":case"middle":a=-t[0]/2,o=t[0]/2;break;case"right":a=-t[0]-i,o=-i;break}switch(n){case"bottom":s=i,l=t[1]+i;break;case"middle":s=-t[1]/2,l=t[1]/2;break;case"top":s=-t[1]-i,l=-i;break}var c=e*4,u=this.attributes.offset;u.set(c,[a,l]),u.set(c+1,[o,l]),u.set(c+2,[o,s]),u.set(c+3,[a,s])},addSprite:function(e,t,r,n,i,a){var s=this._vertexOffset;this.setSprite(this._vertexOffset/4,e,t,r,n,i,a);for(var o=0;o<wa.length;o++)this.indices[this._faceOffset*3+o]=wa[o]+s;return this._faceOffset+=2,this._vertexOffset+=4,s/4},setSprite:function(e,t,r,n,i,a,s){for(var o=e*4,l=this.attributes,c=0;c<4;c++)l.position.set(o+c,t);var u=l.texcoord;u.set(o,[n[0][0],n[0][1]]),u.set(o+1,[n[1][0],n[0][1]]),u.set(o+2,[n[1][0],n[1][1]]),u.set(o+3,[n[0][0],n[1][1]]),this.setSpriteAlign(e,r,i,a,s)}});Ir(As.prototype,Mi);const ch=As,uh="@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";k.Shader.import(uh);const Ss=k.Mesh.extend(function(){var e=new ch({dynamic:!0}),t=new k.Material({shader:k.createShader("ecgl.labels"),transparent:!0,depthMask:!1});return{geometry:e,material:t,culling:!1,castShadow:!1,ignorePicking:!0}});var Bt=rt.firstNotNull,Ft={x:0,y:2,z:1};function Ni(e,t){var r=new k.Mesh({geometry:new Li({useNativeLine:!1}),material:t,castShadow:!1,ignorePicking:!0,renderOrder:2}),n=new Ss;n.material.depthMask=!1;var i=new k.Node;i.add(r),i.add(n),this.rootNode=i,this.dim=e,this.linesMesh=r,this.labelsMesh=n,this.axisLineCoords=null,this.labelElements=[]}var Gn={x:"y",y:"x",z:"y"};Ni.prototype.update=function(e,t,r){var n=e.coordinateSystem,i=n.getAxis(this.dim),a=this.linesMesh.geometry,s=this.labelsMesh.geometry;a.convertToDynamicArray(!0),s.convertToDynamicArray(!0);var o=i.model,l=i.getExtent(),b=r.getDevicePixelRatio(),c=o.getModel("axisLine",e.getModel("axisLine")),u=o.getModel("axisTick",e.getModel("axisTick")),h=o.getModel("axisLabel",e.getModel("axisLabel")),d=c.get("lineStyle.color");if(c.get("show")){var f=c.getModel("lineStyle"),v=[0,0,0],_=[0,0,0],m=Ft[i.dim];v[m]=l[0],_[m]=l[1],this.axisLineCoords=[v,_];var p=k.parseColor(d),y=Bt(f.get("width"),1),g=Bt(f.get("opacity"),1);p[3]*=g,a.addLine(v,_,p,y*b)}if(u.get("show")){var x=u.getModel("lineStyle"),E=k.parseColor(Bt(x.get("color"),d)),y=Bt(x.get("width"),1);E[3]*=Bt(x.get("opacity"),1);for(var S=i.getTicksCoords(),R=u.get("length"),w=0;w<S.length;w++){var M=S[w].coord,v=[0,0,0],_=[0,0,0],m=Ft[i.dim],F=Ft[Gn[i.dim]];v[m]=_[m]=M,_[F]=R,a.addLine(v,_,E,y*b)}}this.labelElements=[];var b=r.getDevicePixelRatio();if(h.get("show"))for(var S=i.getTicksCoords(),U=o.get("data"),I=h.get("margin"),N=i.getViewLabels(),w=0;w<N.length;w++){var G=N[w].tickValue,B=N[w].formattedLabel,Y=N[w].rawLabel,M=i.dataToCoord(G),O=[0,0,0],m=Ft[i.dim],F=Ft[Gn[i.dim]];O[m]=O[m]=M,O[F]=I;var he=h;U&&U[G]&&U[G].textStyle&&(he=new po(U[G].textStyle,h,o.ecModel));var V=Bt(he.get("color"),d),xe=new $n({style:jn(he,{text:B,fill:typeof V=="function"?V(i.type==="category"?Y:i.type==="value"?G+"":G,w):V,verticalAlign:"top",align:"left"})}),ae=t.add(xe),ve=xe.getBoundingRect();s.addSprite(O,[ve.width*b,ve.height*b],ae),this.labelElements.push(xe)}if(o.get("name")){var _e=o.getModel("nameTextStyle"),O=[0,0,0],m=Ft[i.dim],F=Ft[Gn[i.dim]],Ie=Bt(_e.get("color"),d),Be=_e.get("borderColor"),y=_e.get("borderWidth");O[m]=O[m]=(l[0]+l[1])/2,O[F]=o.get("nameGap");var xe=new $n({style:jn(_e,{text:o.get("name"),fill:Ie,stroke:Be,lineWidth:y})}),ae=t.add(xe),ve=xe.getBoundingRect();s.addSprite(O,[ve.width*b,ve.height*b],ae),xe.__idx=this.labelElements.length,this.nameLabelElement=xe}this.labelsMesh.material.set("textureAtlas",t.getTexture()),this.labelsMesh.material.set("uvScale",t.getCoordsScale()),a.convertToTypedArray(),s.convertToTypedArray()};Ni.prototype.setSpriteAlign=function(e,t,r){for(var n=r.getDevicePixelRatio(),i=this.labelsMesh.geometry,a=0;a<this.labelElements.length;a++){var s=this.labelElements[a],o=s.getBoundingRect();i.setSpriteAlign(a,[o.width*n,o.height*n],e,t)}var l=this.nameLabelElement;if(l){var o=l.getBoundingRect();i.setSpriteAlign(l.__idx,[o.width*n,o.height*n],e,t),i.dirty()}this.textAlign=e,this.textVerticalAlign=t};const hh="@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 ba=rt.firstNotNull;k.Shader.import(hh);var Ut={x:0,y:2,z:1};const fh=go.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"]],n=["x","y","z"],i=new k.Material({shader:k.createShader("ecgl.color"),depthMask:!1,transparent:!0}),a=new k.Material({shader:k.createShader("ecgl.meshLines3D"),depthMask:!1,transparent:!0});i.define("fragment","DOUBLE_SIDED"),i.define("both","VERTEX_COLOR"),this.groupGL=new k.Node,this._control=new ah({zr:t.getZr()}),this._control.init(),this._faces=r.map(function(o){var l=new Tn(o,a,i);return this.groupGL.add(l.rootNode),l},this),this._axes=n.map(function(o){var l=new Ni(o,a);return this.groupGL.add(l.rootNode),l},this);var s=t.getDevicePixelRatio();this._axisLabelSurface=new ai({width:256,height:256,devicePixelRatio:s}),this._axisLabelSurface.onupdate=function(){t.getZr().refresh()},this._axisPointerLineMesh=new k.Mesh({geometry:new Li({useNativeLine:!1}),material:a,castShadow:!1,ignorePicking:!0,renderOrder:3}),this.groupGL.add(this._axisPointerLineMesh),this._axisPointerLabelsSurface=new ai({width:128,height:128,devicePixelRatio:s}),this._axisPointerLabelsMesh=new Ss({ignorePicking:!0,renderOrder:4,castShadow:!1}),this._axisPointerLabelsMesh.material.set("textureAtlas",this._axisPointerLabelsSurface.getTexture()),this.groupGL.add(this._axisPointerLabelsMesh),this._lightRoot=new k.Node,this._sceneHelper=new si,this._sceneHelper.initLight(this._lightRoot)},render:function(e,t,r){this._model=e,this._api=r;var n=e.coordinateSystem;n.viewGL.add(this._lightRoot),e.get("show")?n.viewGL.add(this.groupGL):n.viewGL.remove(this.groupGL);var i=this._control;i.setViewGL(n.viewGL);var a=e.getModel("viewControl");i.setFromViewControlModel(a,0),this._axisLabelSurface.clear(),i.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)),i.on("update",this._onCameraChange.bind(this,e,r),this),this._sceneHelper.setScene(n.viewGL.scene),this._sceneHelper.updateLight(e),n.viewGL.setPostEffect(e.getModel("postEffect"),r),n.viewGL.setTemporalSuperSampling(e.getModel("temporalSuperSampling")),this._initMouseHandler(e)},afterRender:function(e,t,r,n){var i=n.renderer;this._sceneHelper.updateAmbientCubemap(i,e,r),this._sceneHelper.updateSkybox(i,e,r)},showAxisPointer:function(e,t,r,n){this._doShowAxisPointer(),this._updateAxisPointer(n.value)},hideAxisPointer:function(e,t,r,n){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,n=r.viewGL,i=n.castRay(e.offsetX,e.offsetY,new k.Ray),a,s=0;s<this._faces.length;s++){var o=this._faces[s];if(!o.rootNode.invisible){o.plane.normal.dot(n.camera.worldTransform.z)<0&&o.plane.normal.negate();var l=i.intersectPlane(o.plane);if(l){var c=r.getAxis(o.faceInfo[0]),u=r.getAxis(o.faceInfo[1]),h=Ut[o.faceInfo[0]],d=Ut[o.faceInfo[1]];c.contain(l.array[h])&&u.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 k.Vector3;e.update();for(var r=0;r<this._faces.length/2;r++){for(var n=[],i=0;i<2;i++){var a=this._faces[r*2+i];a.rootNode.getWorldPosition(t),t.transformMat4(e.viewMatrix),n[i]=t.z}var s=n[0]>n[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"),n=e.getAxis("z"),i=n.getExtentMax(),a=n.getExtentMin(),s=t.getExtentMin(),o=t.getExtentMax(),l=r.getExtentMax(),c=r.getExtentMin(),u=this._axes[0].rootNode,h=this._axes[1].rootNode,d=this._axes[2].rootNode,f=this._faces,v=f[4].rootNode.invisible?c:l,_=f[2].rootNode.invisible?i:a,m=f[0].rootNode.invisible?s:o,p=f[2].rootNode.invisible?i:a,y=f[0].rootNode.invisible?o:s,g=f[4].rootNode.invisible?c:l;u.rotation.identity(),h.rotation.identity(),d.rotation.identity(),f[4].rootNode.invisible&&(this._axes[0].flipped=!0,u.rotation.rotateX(Math.PI)),f[0].rootNode.invisible&&(this._axes[1].flipped=!0,h.rotation.rotateZ(Math.PI)),f[4].rootNode.invisible&&(this._axes[2].flipped=!0,d.rotation.rotateY(Math.PI)),u.position.set(0,_,v),h.position.set(m,p,0),d.position.set(y,0,g),u.update(),h.update(),d.update(),this._updateAxisLabelAlign()},_updateAxisLabelAlign:function(){var e=this._control.getCamera(),t=[new k.Vector4,new k.Vector4],r=new k.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(n){var i=n.axisLineCoords;n.labelsMesh.geometry;for(var a=0;a<t.length;a++)t[a].setArray(i[a]),t[a].w=1,t[a].transformMat4(n.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,u,h;Math.abs(o/s)<.5?(u="center",h=c>r.y?"bottom":"top"):(h="middle",u=l>r.x?"left":"right"),n.setSpriteAlign(u,h,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),n=this._axisPointerLineMesh,i=n.geometry,a=this._model.getModel("axisPointer"),s=this._api.getDevicePixelRatio();i.convertToDynamicArray(!0);function o(w){return rt.firstNotNull(w.model.get("axisPointer.show"),a.get("show"))}function l(w){var M=w.model.getModel("axisPointer",a),F=M.getModel("lineStyle"),b=k.parseColor(F.get("color")),U=ba(F.get("width"),1),I=ba(F.get("opacity"),1);return b[3]*=I,{color:b,lineWidth:U}}for(var c=0;c<this._faces.length;c++){var u=this._faces[c];if(!u.rootNode.invisible){for(var h=u.faceInfo,d=h[3]<0?t.getAxis(h[2]).getExtentMin():t.getAxis(h[2]).getExtentMax(),f=Ut[h[2]],v=0;v<2;v++){var _=h[v],m=h[1-v],p=t.getAxis(_),y=t.getAxis(m);if(o(p)){var g=[0,0,0],x=[0,0,0],E=Ut[_],S=Ut[m];g[E]=x[E]=r[E],g[f]=x[f]=d,g[S]=y.getExtentMin(),x[S]=y.getExtentMax();var R=l(p);i.addLine(g,x,R.color,R.lineWidth*s)}}if(o(t.getAxis(h[2]))){var g=r.slice(),x=r.slice();x[f]=d;var R=l(t.getAxis(h[2]));i.addLine(g,x,R.color,R.lineWidth*s)}}}i.convertToTypedArray(),this._updateAxisPointerLabelsMesh(e),this._api.getZr().refresh()},_updateAxisPointerLabelsMesh:function(e){var t=this._model,r=this._axisPointerLabelsMesh,n=this._axisPointerLabelsSurface,i=t.coordinateSystem,a=t.getModel("axisPointer");r.geometry.convertToDynamicArray(!0),n.clear();var s={x:"y",y:"x",z:"y"};this._axes.forEach(function(o,l){var c=i.getAxis(o.dim),u=c.model,h=u.getModel("axisPointer",a),d=h.getModel("label"),f=h.get("lineStyle.color");if(!(!d.get("show")||!h.get("show"))){var v=e[l],_=d.get("formatter"),m=c.scale.getLabel({value:v});if(_!=null)m=_(m,e);else if(c.scale.type==="interval"||c.scale.type==="log"){var p=$a(c.scale.getTicks()[0]);m=v.toFixed(p+2)}var y=d.get("color"),g=new $n({style:jn(d,{text:m,fill:y||f,align:"left",verticalAlign:"top"})}),x=n.add(g),E=g.getBoundingRect(),S=this._api.getDevicePixelRatio(),R=o.rootNode.position.toArray(),w=Ut[s[o.dim]];R[w]+=(o.flipped?-1:1)*d.get("margin"),R[Ut[o.dim]]=c.dataToCoord(e[l]),r.geometry.addSprite(R,[E.width*S,E.height*S],x,o.textAlign,o.textVerticalAlign)}},this),n.getZr().refreshImmediately(),r.material.set("uvScale",n.getCoordsScale()),r.geometry.convertToTypedArray()},dispose:function(){this.groupGL.removeAll(),this._control.dispose(),this._axisLabelSurface.dispose(),this._axisPointerLabelsSurface.dispose()}});function Dr(e){ja.call(this,e),this.type="cartesian3D",this.dimensions=["x","y","z"],this.size=[0,0,0]}Dr.prototype={constructor:Dr,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}};qa(Dr,ja);function hn(e,t,r){Ya.call(this,e,t,r)}hn.prototype={constructor:hn,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)}};qa(hn,Ya);var li=function(){this._pool={},this._allocatedTextures=[]};li.prototype={constructor:li,get:function(e){var t=Ca(e);this._pool.hasOwnProperty(t)||(this._pool[t]=[]);var r=this._pool[t];if(!r.length){var n=new ie(e);return this._allocatedTextures.push(n),n}return r.pop()},put:function(e){var t=Ca(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 ws={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},Vn=Object.keys(ws);function Ca(e){De.defaultsWithPropList(e,ws,Vn),dh(e);for(var t="",r=0;r<Vn.length;r++){var n=Vn[r],i=e[n].toString();t+=i}return t}function dh(e){var t=vh(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 vh(e,t){return(e&e-1)===0&&(t&t-1)===0}const bs=li,_h="@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 Mt=["px","nx","py","ny","pz","nz"];L.import(_h);function kn(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 n=e.material.get("alphaCutoff");return n||0}return 0}else return r==="uvRepeat"?e.material.get("uvRepeat"):r==="uvOffset"?e.material.get("uvOffset"):t.get(r)}function Ra(e,t){var r=e.material,n=t.material;return r.get("diffuseMap")!==n.get("diffuseMap")||(r.get("alphaCutoff")||0)!==(n.get("alphaCutoff")||0)}var ut=qe.extend(function(){return{softShadow:ut.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 bs}},function(){this._gaussianPassH=new ke({fragment:L.source("clay.compositor.gaussian_blur")}),this._gaussianPassV=new ke({fragment:L.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 ke({fragment:L.source("clay.sm.debug_depth")})},{render:function(e,t,r,n){r||(r=t.getMainCamera()),this.trigger("beforerender",this,e,t,r),this._renderShadowPass(e,t,r,n),this.trigger("afterrender",this,e,t,r)},renderDebug:function(e,t){e.saveClear();var r=e.viewport,n=0,i=0,a=t||r.width/4,s=a;this.softShadow===ut.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(n,i,a*l.width/l.height,s),this._outputDepthPass.setUniform("depthMap",l),this._outputDepthPass.render(e),n+=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===ut.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 n=0;n<t.lights.length;n++){var i=t.lights[n];i.castShadow&&!i.invisible&&this._lightsCastShadow.push(i)}},_renderShadowPass:function(e,t,r,n){for(var i in this._shadowMapNumber)this._shadowMapNumber[i]=0;this._lightsCastShadow.length=0,this._receivers.length=0;var a=e.gl;if(n||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=[],u=[],h=[],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,u,c,l)}else v.type==="SPOT_LIGHT"?this.renderSpotLightShadow(e,t,v,o,s):v.type==="POINT_LIGHT"&&this.renderPointLightShadow(e,t,v,h);this._shadowMapNumber[v.type]++}for(var _ in this._shadowMapNumber)for(var m=this._shadowMapNumber[_],p=_+"_SHADOWMAP_COUNT",f=0;f<this._receivers.length;f++){var y=this._receivers[f],g=y.material;g.fragmentDefines[p]!==m&&(m>0?g.define("fragment",p,m):g.isDefined("fragment",p)&&g.undefine("fragment",p))}for(var f=0;f<this._receivers.length;f++){var y=this._receivers[f],g=y.material;d?g.define("fragment","SHADOW_CASCADE",d.shadowCascade):g.undefine("fragment","SHADOW_CASCADE")}var x=t.shadowUniforms;function E(F){return F.height}if(l.length>0){var S=l.map(E);if(x.directionalLightShadowMaps={value:l,type:"tv"},x.directionalLightMatrices={value:c,type:"m4v"},x.directionalLightShadowMapSizes={value:S,type:"1fv"},d){var R=u.slice(),w=u.slice();R.pop(),w.shift(),R.reverse(),w.reverse(),c.reverse(),x.shadowCascadeClipsNear={value:R,type:"1fv"},x.shadowCascadeClipsFar={value:w,type:"1fv"}}}if(s.length>0){var M=s.map(E),x=t.shadowUniforms;x.spotLightShadowMaps={value:s,type:"tv"},x.spotLightMatrices={value:o,type:"m4v"},x.spotLightShadowMapSizes={value:M,type:"1fv"}}h.length>0&&(x.pointLightShadowMaps={value:h,type:"tv"})},renderDirectionalLightShadow:function(){var e=new Si,t=new z,r=new Ve,n=new z,i=new z,a=new z,s=new z;return function(o,l,c,u,h,d,f){var v=this._getDepthMaterial(u),_={getMaterial:function(ve){return ve.shadowDepthMaterial||v},isMaterialChanged:Ra,getUniform:kn,ifRender:function(ve){return ve.castShadow},sortCompare:Er.opaqueSortCompare};if(!l.viewBoundingBoxLastFrame.isFinite()){var m=l.getBoundingBox();l.viewBoundingBoxLastFrame.copy(m).applyTransform(c.viewMatrix)}var p=Math.min(-l.viewBoundingBoxLastFrame.min.z,c.far),y=Math.max(-l.viewBoundingBoxLastFrame.max.z,c.near),g=this._getDirectionalLightCamera(u,l,c),x=a.array;s.copy(g.projectionMatrix),C.invert(i.array,g.worldTransform.array),C.multiply(i.array,i.array,c.worldTransform.array),C.multiply(x,s.array,i.array);for(var E=[],S=c instanceof Me,R=(c.near+c.far)/(c.near-c.far),w=2*c.near*c.far/(c.near-c.far),M=0;M<=u.shadowCascade;M++){var F=y*Math.pow(p/y,M/u.shadowCascade),b=y+(p-y)*M/u.shadowCascade,U=F*u.cascadeSplitLogFactor+b*(1-u.cascadeSplitLogFactor);E.push(U),h.push(-(-U*R+w)/-U)}var I=this._getTexture(u,u.shadowCascade);f.push(I);var N=o.viewport,G=o.gl;this._frameBuffer.attach(I),this._frameBuffer.bind(o),G.clear(G.COLOR_BUFFER_BIT|G.DEPTH_BUFFER_BIT);for(var M=0;M<u.shadowCascade;M++){var B=E[M],Y=E[M+1];S?C.perspective(t.array,c.fov/180*Math.PI,c.aspect,B,Y):C.ortho(t.array,c.left,c.right,c.bottom,c.top,B,Y),e.setFromProjection(t),e.getTransformedBoundingBox(r,i),r.applyProjection(s);var O=r.min.array,he=r.max.array;O[0]=Math.max(O[0],-1),O[1]=Math.max(O[1],-1),he[0]=Math.min(he[0],1),he[1]=Math.min(he[1],1),n.ortho(O[0],he[0],O[1],he[1],1,-1),g.projectionMatrix.multiplyLeft(n);var V=u.shadowResolution||512;o.setViewport((u.shadowCascade-M-1)*V,0,V,V,1);var xe=l.updateRenderList(g);o.renderPass(xe.opaque,g,_),this.softShadow===ut.VSM&&this._gaussianFilter(o,I,I.width);var ae=new z;ae.copy(g.viewMatrix).multiplyLeft(g.projectionMatrix),d.push(ae.array),g.projectionMatrix.copy(s)}this._frameBuffer.unbind(o),o.setViewport(N)}}(),renderSpotLightShadow:function(e,t,r,n,i){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:Ra,getUniform:kn,ifRender:function(d){return d.castShadow},sortCompare:Er.opaqueSortCompare},u=t.updateRenderList(s);e.renderPass(u.opaque,s,c),this._frameBuffer.unbind(e),this.softShadow===ut.VSM&&this._gaussianFilter(e,a,a.width);var h=new z;h.copy(s.worldTransform).invert().multiplyLeft(s.projectionMatrix),i.push(a),n.push(h.array)},renderPointLightShadow:function(e,t,r,n){var i=this._getTexture(r),a=e.gl;n.push(i);var s=this._getDepthMaterial(r),o={getMaterial:function(y){return y.shadowDepthMaterial||s},getUniform:kn,sortCompare:Er.opaqueSortCompare},l={px:[],py:[],pz:[],nx:[],ny:[],nz:[]},c=new Ve,u=r.getWorldPosition().array,h=new Ve,d=r.range;h.min.setArray(u),h.max.setArray(u);var f=new P(d,d,d);h.max.add(f),h.min.sub(f);var v={px:!1,py:!1,pz:!1,nx:!1,ny:!1,nz:!1};t.traverse(function(y){if(y.isRenderable()&&y.castShadow){var g=y.geometry;if(!g.boundingBox){for(var x=0;x<Mt.length;x++)l[Mt[x]].push(y);return}if(c.transformFrom(g.boundingBox,y.worldTransform),!c.intersectBoundingBox(h))return;c.updateVertices();for(var x=0;x<Mt.length;x++)v[Mt[x]]=!1;for(var x=0;x<8;x++){var E=c.vertices[x],S=E[0]-u[0],R=E[1]-u[1],w=E[2]-u[2],M=Math.abs(S),F=Math.abs(R),b=Math.abs(w);M>F?M>b?v[S>0?"px":"nx"]=!0:v[w>0?"pz":"nz"]=!0:F>b?v[R>0?"py":"ny"]=!0:v[w>0?"pz":"nz"]=!0}for(var x=0;x<Mt.length;x++)v[Mt[x]]&&l[Mt[x]].push(y)}});for(var _=0;_<6;_++){var m=Mt[_],p=this._getPointLightCamera(r,m);this._frameBuffer.attach(i,a.COLOR_ATTACHMENT0,a.TEXTURE_CUBE_MAP_POSITIVE_X+_),this._frameBuffer.bind(e),a.clear(a.COLOR_BUFFER_BIT|a.DEPTH_BUFFER_BIT),e.renderPass(l[m],p,o)}this._frameBuffer.unbind(e)},_getDepthMaterial:function(e){var t=this._lightMaterials[e.__uid__],r=e.type==="POINT_LIGHT";if(!t){var n=r?"clay.sm.distance.":"clay.sm.depth.";t=new wt({precision:this.precision,shader:new L(L.source(n+"vertex"),L.source(n+"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===ut.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 n={width:r,height:r,type:q.FLOAT},i=this._texturePool.get(n);this._frameBuffer.attach(i),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",i),this._gaussianPassV.setUniform("textureHeight",r),this._gaussianPassV.render(e),this._frameBuffer.unbind(e),this._texturePool.put(i)},_getTexture:function(e,t){var r=e.__uid__,n=this._textures[r],i=e.shadowResolution||512;return t=t||1,n||(e.type==="POINT_LIGHT"?n=new Lr:n=new ie,n.width=i*t,n.height=i,this.softShadow===ut.VSM?(n.type=q.FLOAT,n.anisotropic=4):(n.minFilter=A.NEAREST,n.magFilter=A.NEAREST,n.useMipmap=!1),this._textures[r]=n),n},_getPointLightCamera:function(e,t){this._lightCameras.point||(this._lightCameras.point={px:new Me,nx:new Me,py:new Me,ny:new Me,pz:new Me,nz:new Me});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 Ve,r=new Ve;return function(n,i,a){this._lightCameras.directional||(this._lightCameras.directional=new Pr);var s=this._lightCameras.directional;t.copy(i.viewBoundingBoxLastFrame),t.intersection(a.frustum.boundingBox),s.position.copy(t.min).add(t.max).scale(.5).transformMat4(a.worldTransform),s.rotation.copy(n.rotation),s.scale.copy(n.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 Me);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 n=0;n<this._receivers.length;n++){var i=this._receivers[n];if(i.material){var a=i.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=[]}});ut.VSM=1;ut.PCF=2;const mh=ut;var ph=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],n=r.parameters,i=r._parametersCopy;if(i||(i=r._parametersCopy={}),n)for(var a in n)a!=="width"&&a!=="height"&&(i[a]=n[a]);var s,o;return n.width instanceof Function?s=n.width.call(this,t):s=n.width,n.height instanceof Function?o=n.height.call(this,t):o=n.height,(i.width!==s||i.height!==o)&&this._outputTextures[e]&&this._outputTextures[e].dispose(t.gl),i.width=s,i.height=o,i},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 Or=ph;var gh=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 n=t.inputs[r],i=this.findPin(n);i?t.link(r,i.node,i.pin):console.warn(typeof n=="string"?"Node "+n+" not exist":"Pin of "+n.node+"."+n.pin+" not exist")}}}},findPin:function(e){var t;if((typeof e=="string"||e instanceof Or)&&(e={node:e}),typeof e.node=="string")for(var r=0;r<this.nodes.length;r++){var n=this.nodes[r];n.name===e.node&&(t=n)}else t=e.node;if(t){var i=e.pin;if(i||t.outputs&&(i=Object.keys(t.outputs)[0]),t.outputs[i])return{node:t,pin:i}}}});const Ma=gh;var xh=Ma.extend(function(){return{_outputs:[],_texturePool:new bs,_frameBuffer:new Ue({depthBuffer:!1})}},{addNode:function(e){Ma.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 yh=xh;var Th=Or.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 n=this.frameBuffer;for(var i in this.outputs){var a=this.updateParameter(i,e),s=this.outputs[i],o=this._compositor.allocateTexture(a);this._outputTextures[i]=o;var l=s.attachment||t.COLOR_ATTACHMENT0;typeof l=="string"&&(l=t[l]),n.attach(o,l)}n.bind(e);var c=e.getGLExtension("EXT_draw_buffers");if(c){var u=[];for(var l in this.outputs)l=parseInt(l),l>=t.COLOR_ATTACHMENT0&&l<=t.COLOR_ATTACHMENT0+8&&u.push(l);c.drawBuffersEXT(u)}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(),n.unbind(e)}this.trigger("afterrender",r),this._rendering=!1,this._rendered=!0}});const Eh=Th;var Ah=Or.extend(function(){return{texture:null,outputs:{color:{}}}},function(){},{getOutput:function(e,t){return this.texture},beforeFrame:function(){},afterFrame:function(){}});const Sh=Ah;var wh=Or.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 ke({fragment:this.shader});this.pass=e},{render:function(e,t){this.trigger("beforerender",e),this._rendering=!0;var r=e.gl;for(var n in this.inputLinks){var i=this.inputLinks[n],a=i.node.getOutput(e,i.pin);this.pass.setUniform(n,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],u=this._compositor.allocateTexture(l);this._outputTextures[o]=u;var h=c.attachment||r.COLOR_ATTACHMENT0;typeof h=="string"&&(h=r[h]),s[h]=u}this._compositor.getFrameBuffer().bind(e);for(var h in s)this._compositor.getFrameBuffer().attach(s[h],h);this.pass.render(e),this._compositor.getFrameBuffer().updateMipmap(e)}for(var n in this.inputLinks){var i=this.inputLinks[n];i.node.removeReference(i.pin)}this._rendering=!1,this._rendered=!0,this.trigger("afterrender",e)},updateParameter:function(e,t){var r=this.outputs[e],n=r.parameters,i=r._parametersCopy;if(i||(i=r._parametersCopy={}),n)for(var a in n)a!=="width"&&a!=="height"&&(i[a]=n[a]);var s,o;return typeof n.width=="function"?s=n.width.call(this,t):s=n.width,typeof n.height=="function"?o=n.height.call(this,t):o=n.height,s=Math.ceil(s),o=Math.ceil(o),(i.width!==s||i.height!==o)&&this._outputTextures[e]&&this._outputTextures[e].dispose(t),i.width=s,i.height=o,i},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(){Or.prototype.clear.call(this),this.pass.material.disableTexturesAll()}});const bh=wh,Ch="@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",Cs="@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",Rh="@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",Rs="\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",Mh="@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",Ms="@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",Ls="@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",Ns="@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",Ps="\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",Ds="@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",Os="@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",Is="@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 Nh(e){e.import(Ch),e.import(Cs),e.import(Rh),e.import(Rs),e.import(Mh),e.import(Ms),e.import(Ls),e.import(Ns),e.import(Ps),e.import(Ds),e.import(Lh),e.import(Os),e.import(Is)}Nh(L);var Ph=/^#source\((.*?)\)/;function Dh(e,t){var r=new yh;t=t||{};var n={textures:{},parameters:{}},i=function(o,l){for(var c=0;c<e.nodes.length;c++){var u=e.nodes[c],h=Oh(u,n,t);h&&r.addNode(h)}};for(var a in e.parameters){var s=e.parameters[a];n.parameters[a]=Pi(s)}return Fh(e,n,t,function(o){n.textures=o,i()}),r}function Oh(e,t,r){var n=e.type||"filter",i,a,s;if(n==="filter"){var o=e.shader.trim(),l=Ph.exec(o);if(l?i=L.source(l[1].trim()):o.charAt(0)==="#"&&(i=t.shaders[o.substr(1)]),i||(i=o),!i)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 u=e.outputs[c];s[c]={},u.attachment!=null&&(s[c].attachment=u.attachment),u.keepLastFrame!=null&&(s[c].keepLastFrame=u.keepLastFrame),u.outputLastFrame!=null&&(s[c].outputLastFrame=u.outputLastFrame),u.parameters&&(s[c].parameters=Pi(u.parameters))}}var h;if(n==="scene"?h=new Eh({name:e.name,scene:r.scene,camera:r.camera,outputs:s}):n==="texture"?h=new Sh({name:e.name,outputs:s}):h=new bh({name:e.name,shader:i,inputs:a,outputs:s}),h){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)]:h.on("beforerender",Uh(c,Bs(d)))):typeof d=="function"&&h.on("beforerender",d),h.setParameter(c,d)}if(e.defines&&h.pass)for(var c in e.defines){var d=e.defines[c];h.pass.material.define("fragment",c,d)}}return h}function Ih(e,t){return e}function Bh(e,t){return t}function Pi(e){var t={};if(!e)return t;["type","minFilter","magFilter","wrapS","wrapT","flipY","useMipmap"].forEach(function(n){var i=e[n];i!=null&&(typeof i=="string"&&(i=q[i]),t[n]=i)});var r=e.scale||1;return["width","height"].forEach(function(n){if(e[n]!=null){var i=e[n];typeof i=="string"?(i=i.trim(),t[n]=Hh(n,Bs(i),r)):t[n]=i}}),t.width||(t.width=Ih),t.height||(t.height=Bh),e.useMipmap!=null&&(t.useMipmap=e.useMipmap),t}function Fh(e,t,r,n){if(!e.textures){n({});return}var i={},a=0,s=!1,o=r.textureRootPath;De.each(e.textures,function(l,c){var u,h=l.path,d=Pi(l.parameters);if(Array.isArray(h)&&h.length===6)o&&(h=h.map(function(f){return De.relative2absolute(f,o)})),u=new Lr(d);else if(typeof h=="string")o&&(h=De.relative2absolute(h,o)),u=new ie(d);else return;u.load(h),a++,u.once("success",function(){i[c]=u,a--,a===0&&(n(i),s=!0)})}),a===0&&!s&&n(i)}function Uh(e,t){return function(r){var n=r.getDevicePixelRatio(),i=r.getWidth(),a=r.getHeight(),s=t(i,a,n);this.setParameter(e,s)}}function Hh(e,t,r){return r=r||1,function(n){var i=n.getDevicePixelRatio(),a=n.getWidth()*r,s=n.getHeight()*r;return t(a,s,i)}}function Bs(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 ur(e,t){for(var r=0,n=1/t,i=e;i>0;)r=r+n*(i%t),i=Math.floor(i/t),n=n/t;return r}const zh="@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";L.import(zh);function Fs(e){for(var t=new Uint8Array(e*e*4),r=0,n=new P,i=0;i<e;i++)for(var a=0;a<e;a++)n.set(Math.random()*2-1,Math.random()*2-1,0).normalize(),t[r++]=(n.x*.5+.5)*255,t[r++]=(n.y*.5+.5)*255,t[r++]=0,t[r++]=255;return t}function La(e){return new ie({pixels:Fs(e),wrapS:q.REPEAT,wrapT:q.REPEAT,width:e,height:e})}function Gh(e,t,r){var n=new Float32Array(e*3);t=t||0;for(var i=0;i<e;i++){var a=ur(i+t,2)*(r?1:2)*Math.PI,s=ur(i+t,3)*Math.PI,o=Math.random(),l=Math.cos(a)*Math.sin(s)*o,c=Math.cos(s)*o,u=Math.sin(a)*Math.sin(s)*o;n[i*3]=l,n[i*3+1]=c,n[i*3+2]=u}return n}function bt(e){e=e||{},this._ssaoPass=new ke({fragment:L.source("ecgl.ssao.estimate")}),this._blurPass=new ke({fragment:L.source("ecgl.ssao.blur")}),this._framebuffer=new Ue({depthBuffer:!1}),this._ssaoTexture=new ie,this._blurTexture=new ie,this._blurTexture2=new ie,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)}bt.prototype.setDepthTexture=function(e){this._depthTex=e};bt.prototype.setNormalTexture=function(e){this._normalTex=e,this._ssaoPass.material[e?"enableTexture":"disableTexture"]("normalTex"),this.setKernelSize(this._kernelSize)};bt.prototype.update=function(e,t,r){var n=e.getWidth(),i=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,u=this._blurTexture2;l.width=n/2,l.height=i/2,c.width=n,c.height=i,u.width=n,u.height=i,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",[n/2,i/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(u),s.setUniform("textureSize",[n,i]),s.setUniform("direction",1),s.setUniform("ssaoTexture",c),s.render(e),this._framebuffer.unbind(e);var h=e.clearColor;e.gl.clearColor(h[0],h[1],h[2],h[3])};bt.prototype.getTargetTexture=function(){return this._blurTexture2};bt.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)};bt.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]=Gh(e,t*e,!!this._normalTex)};bt.prototype.setNoiseSize=function(e){var t=this._ssaoPass.getUniform("noiseTex");t?(t.data=Fs(e),t.width=t.height=e,t.dirty()):(t=La(e),this._ssaoPass.setUniform("noiseTex",La(e))),this._ssaoPass.setUniform("noiseTexSize",[e,e])};bt.prototype.dispose=function(e){this._blurTexture.dispose(e),this._ssaoTexture.dispose(e),this._blurTexture2.dispose(e)};const Vh="@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";L.import(Vh);function Ct(e){e=e||{},this._ssrPass=new ke({fragment:L.source("ecgl.ssr.main"),clearColor:[0,0,0,0]}),this._blurPass1=new ke({fragment:L.source("ecgl.ssr.blur"),clearColor:[0,0,0,0]}),this._blurPass2=new ke({fragment:L.source("ecgl.ssr.blur"),clearColor:[0,0,0,0]}),this._blendPass=new ke({fragment:L.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 ie({type:q.HALF_FLOAT}),this._texture2=new ie({type:q.HALF_FLOAT}),this._texture3=new ie({type:q.HALF_FLOAT}),this._prevTexture=new ie({type:q.HALF_FLOAT}),this._currentTexture=new ie({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}Ct.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")};Ct.prototype.update=function(e,t,r,n){var i=e.getWidth(),a=e.getHeight(),s=this._ssrTexture,o=this._texture2,l=this._texture3;s.width=this._prevTexture.width=this._currentTexture.width=i/this._downScale,s.height=this._prevTexture.height=this._currentTexture.height=a/this._downScale,o.width=l.width=i,o.height=l.height=a;var c=this._frameBuffer,u=this._ssrPass,h=this._blurPass1,d=this._blurPass2,f=this._blendPass,v=new z,_=new z;z.transpose(v,t.worldTransform),z.transpose(_,t.viewMatrix),u.setUniform("sourceTexture",r),u.setUniform("projection",t.projectionMatrix.array),u.setUniform("projectionInv",t.invProjectionMatrix.array),u.setUniform("toViewSpace",v.array),u.setUniform("toWorldSpace",_.array),u.setUniform("nearZ",t.near);var m=n/this._totalSamples*this._samplePerFrame;if(u.setUniform("jitterOffset",m),u.setUniform("sampleOffset",n*this._samplePerFrame),h.setUniform("textureSize",[s.width,s.height]),d.setUniform("textureSize",[i,a]),d.setUniform("sourceTexture",r),h.setUniform("projection",t.projectionMatrix.array),d.setUniform("projection",t.projectionMatrix.array),c.attach(s),c.bind(e),u.render(e),this._physicallyCorrect&&(c.attach(this._currentTexture),f.setUniform("texture1",this._prevTexture),f.setUniform("texture2",s),f.material.set({weight1:n>=1?.95:0,weight2:n>=1?.05:1}),f.render(e)),c.attach(o),h.setUniform("texture",this._physicallyCorrect?this._currentTexture:s),h.render(e),c.attach(l),d.setUniform("texture",o),d.render(e),c.unbind(e),this._physicallyCorrect){var p=this._prevTexture;this._prevTexture=this._currentTexture,this._currentTexture=p}};Ct.prototype.getTargetTexture=function(){return this._texture3};Ct.prototype.setParameter=function(e,t){e==="maxIteration"?this._ssrPass.material.define("fragment","MAX_ITERATION",t):this._ssrPass.setUniform(e,t)};Ct.prototype.setPhysicallyCorrect=function(e){e?(this._normalDistribution||(this._normalDistribution=an.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};Ct.prototype.setSSAOTexture=function(e){var t=this._blurPass2;e?(t.material.enableTexture("ssaoTex"),t.material.set("ssaoTex",e)):t.material.disableTexture("ssaoTex")};Ct.prototype.isFinished=function(e){return this._physicallyCorrect?e>this._totalSamples/this._samplePerFrame:!0};Ct.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],kh="@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";L.import(kh);function Wn(e,t,r,n,i){var a=e.gl;t.setUniform(a,"1i",r,i),a.activeTexture(a.TEXTURE0+i),n.isRenderable()?n.bind(e):n.unbind(e)}function Wh(e,t,r,n,i){var a,s,o,l,c=e.gl;return function(u,h,d){if(!(l&&l.material===u.material)){var f=u.material,v=u.__program,_=f.get("roughness");_==null&&(_=1);var m=f.get("normalMap")||t,p=f.get("roughnessMap"),y=f.get("bumpMap"),g=f.get("uvRepeat"),x=f.get("uvOffset"),E=f.get("detailUvRepeat"),S=f.get("detailUvOffset"),R=!!y&&f.isTextureEnabled("bumpMap"),w=!!p&&f.isTextureEnabled("roughnessMap"),M=f.isDefined("fragment","DOUBLE_SIDED");y=y||r,p=p||n,d!==h?(h.set("normalMap",m),h.set("bumpMap",y),h.set("roughnessMap",p),h.set("useBumpMap",R),h.set("useRoughnessMap",w),h.set("doubleSide",M),g!=null&&h.set("uvRepeat",g),x!=null&&h.set("uvOffset",x),E!=null&&h.set("detailUvRepeat",E),S!=null&&h.set("detailUvOffset",S),h.set("roughness",_)):(v.setUniform(c,"1f","roughness",_),a!==m&&Wn(e,v,"normalMap",m,0),s!==y&&y&&Wn(e,v,"bumpMap",y,1),o!==p&&p&&Wn(e,v,"roughnessMap",p,2),g!=null&&v.setUniform(c,"2f","uvRepeat",g),x!=null&&v.setUniform(c,"2f","uvOffset",x),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",+w),v.setUniform(c,"1i","doubleSide",+M)),a=m,s=y,o=p,l=u}}}function fr(e){this._depthTex=new ie({format:q.DEPTH_COMPONENT,type:q.UNSIGNED_INT}),this._normalTex=new ie({type:q.HALF_FLOAT}),this._framebuffer=new Ue,this._framebuffer.attach(this._normalTex),this._framebuffer.attach(this._depthTex,Ue.DEPTH_ATTACHMENT),this._normalMaterial=new wt({shader:new L(L.source("ecgl.normal.vertex"),L.source("ecgl.normal.fragment"))}),this._normalMaterial.enableTexture(["normalMap","bumpMap","roughnessMap"]),this._defaultNormalMap=Vt.createBlank("#000"),this._defaultBumpMap=Vt.createBlank("#000"),this._defaultRoughessMap=Vt.createBlank("#000"),this._debugPass=new ke({fragment:L.source("clay.compositor.output")}),this._debugPass.setUniform("texture",this._normalTex),this._debugPass.material.undefine("fragment","OUTPUT_ALPHA")}fr.prototype.getDepthTexture=function(){return this._depthTex};fr.prototype.getNormalTexture=function(){return this._normalTex};fr.prototype.update=function(e,t,r){var n=e.getWidth(),i=e.getHeight(),a=this._depthTex,s=this._normalTex,o=this._normalMaterial;a.width=n,a.height=i,s.width=n,s.height=i;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:Wh(e,this._defaultNormalMap,this._defaultBumpMap,this._defaultRoughessMap,this._normalMaterial),sort:e.opaqueSortCompare}),this._framebuffer.unbind(e)};fr.prototype.renderDebug=function(e){this._debugPass.render(e)};fr.prototype.dispose=function(e){this._depthTex.dispose(e),this._normalTex.dispose(e)};function Fr(e){e=e||{},this._edgePass=new ke({fragment:L.source("ecgl.edge")}),this._edgePass.setUniform("normalTexture",e.normalTexture),this._edgePass.setUniform("depthTexture",e.depthTexture),this._targetTexture=new ie({type:q.HALF_FLOAT}),this._frameBuffer=new Ue,this._frameBuffer.attach(this._targetTexture)}Fr.prototype.update=function(e,t,r,n){var i=e.getWidth(),a=e.getHeight(),s=this._targetTexture;s.width=i,s.height=a;var o=this._frameBuffer;o.bind(e),this._edgePass.setUniform("projectionInv",t.invProjectionMatrix.array),this._edgePass.setUniform("textureSize",[i,a]),this._edgePass.setUniform("texture",r),this._edgePass.render(e),o.unbind(e)};Fr.prototype.getTargetTexture=function(){return this._targetTexture};Fr.prototype.setParameter=function(e,t){this._edgePass.setUniform(e,t)};Fr.prototype.dispose=function(e){this._targetTexture.dispose(e),this._frameBuffer.dispose(e)};const Xh={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"}}]},$h="@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",jh="@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";L.import(Cs);L.import(Rs);L.import(Ms);L.import(Ls);L.import(Ns);L.import(Ps);L.import(Ds);L.import(Os);L.import(Is);L.import($h);L.import(jh);function Us(e,t){return{color:{parameters:{width:e,height:t}}}}var Di=["composite","FXAA"];function J(){this._width,this._height,this._dpr,this._sourceTexture=new ie({type:q.HALF_FLOAT}),this._depthTexture=new ie({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 fr,this._compositor=Dh(Xh);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(n){return this._compositor.getNodeByName(n)},this),this._dofBlurKernel=0,this._dofBlurKernelSize=new Float32Array(0),this._finalNodesChain=Di.map(function(n){return this._compositor.getNodeByName(n)},this);var r={normalTexture:this._normalPass.getNormalTexture(),depthTexture:this._normalPass.getDepthTexture()};this._ssaoPass=new bt(r),this._ssrPass=new Ct(r),this._edgePass=new Fr(r)}J.prototype.resize=function(n,i,r){r=r||1;var n=n*r,i=i*r,a=this._sourceTexture,s=this._depthTexture;a.width=n,a.height=i,s.width=n,s.height=i;var o={getWidth:function(){return n},getHeight:function(){return i},getDevicePixelRatio:function(){return r}};function l(c,u){if(typeof c[u]=="function"){var h=c[u].__original||c[u];c[u]=function(d){return h.call(this,o)},c[u].__original=h}}this._compositor.nodes.forEach(function(c){for(var u in c.outputs){var h=c.outputs[u].parameters;h&&(l(h,"width"),l(h,"height"))}for(var d in c.parameters)l(c.parameters,d)}),this._width=n,this._height=i,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=Di.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=Di.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=Us(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=Us(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,n){this._ifRenderNormalPass()&&this._normalPass.update(e,t,r)};J.prototype.updateSSAO=function(e,t,r,n){this._ssaoPass.update(e,r,n)};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 n={low:4,medium:8,high:16,ultra:32}[t]||8;this._dofBlurKernelSize=n;for(var r=0;r<this._dofBlurNodes.length;r++)this._dofBlurNodes[r].pass.material.define("POISSON_KERNEL_SIZE",n);this._dofBlurKernel=new Float32Array(n*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,n={low:32,medium:16,high:8,ultra:4}[t]||16;this._ssrPass.setParameter("maxIteration",r),this._ssrPass.setParameter("pixelStride",n);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=k.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:k.Texture.NEAREST,magFilter:k.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,n,i){var a=this._sourceTexture,s=a;this._enableEdge&&(this._edgePass.update(e,r,a,i),a=s=this._edgePass.getTargetTexture()),this._enableSSR&&(this._ssrPass.update(e,r,a,i),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),u=i%c,h=0;h<l*2;h++)o[h]=Na[h+u*l*2];for(var h=0;h<this._dofBlurNodes.length;h++)this._dofBlurNodes[h].setParameter("percent",i/30),this._dofBlurNodes[h].setParameter("poissonKernel",o);this._cocNode.setParameter("zNear",r.near),this._cocNode.setParameter("zFar",r.far),this._compositor.render(e,n)};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 ci(e){for(var t=[],r=0;r<30;r++)t.push([ur(r,2),ur(r,3)]);this._haltonSequence=t,this._frame=0,this._sourceTex=new ie,this._sourceFb=new Ue,this._sourceFb.attach(this._sourceTex),this._prevFrameTex=new ie,this._outputTex=new ie;var n=this._blendPass=new ke({fragment:L.source("clay.compositor.blend")});n.material.disableTexturesAll(),n.material.enableTexture(["texture1","texture2"]),this._blendFb=new Ue({depthBuffer:!1}),this._outputPass=new ke({fragment:L.source("clay.compositor.output"),blendWithPrevious:!0}),this._outputPass.material.define("fragment","OUTPUT_ALPHA"),this._outputPass.material.blend=function(i){i.blendEquationSeparate(i.FUNC_ADD,i.FUNC_ADD),i.blendFuncSeparate(i.ONE,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)}}ci.prototype={constructor:ci,jitterProjection:function(e,t){var r=e.viewport,n=r.devicePixelRatio||e.getDevicePixelRatio(),i=r.width*n,a=r.height*n,s=this._haltonSequence[this._frame%this._haltonSequence.length],o=new z;o.array[12]=(s[0]*2-1)/i,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 n=this._blendPass;this._frame===0?(n.setUniform("weight1",0),n.setUniform("weight2",1)):(n.setUniform("weight1",.9),n.setUniform("weight2",.1)),n.setUniform("texture1",this._prevFrameTex),n.setUniform("texture2",t||this._sourceTex),this._blendFb.attach(this._outputTex),this._blendFb.bind(e),n.render(e),this._blendFb.unbind(e),r||(this._outputPass.setUniform("texture",this._outputTex),this._outputPass.render(e));var i=this._prevFrameTex;this._prevFrameTex=this._outputTex,this._outputTex=i,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 pe(e){e=e||"perspective",this.layer=null,this.scene=new Pt,this.rootNode=this.scene,this.viewport={x:0,y:0,width:0,height:0},this.setProjection(e),this._compositor=new J,this._temporalSS=new ci,this._shadowMapPass=new mh;for(var t=[],r=0,n=0;n<30;n++){for(var i=[],a=0;a<6;a++)i.push(ur(r,2)*4-2),i.push(ur(r,3)*4-2),r++;t.push(i)}this._pcfKernels=t,this.scene.on("beforerender",function(s,o,l){this.needsTemporalSS()&&this._temporalSS.jitterProjection(s,l)},this)}pe.prototype.setProjection=function(e){var t=this.camera;t&&t.update(),e==="perspective"?this.camera instanceof Me||(this.camera=new Me,t&&this.camera.setLocalTransform(t.localTransform)):this.camera instanceof Pr||(this.camera=new Pr,t&&this.camera.setLocalTransform(t.localTransform)),this.camera.near=.1,this.camera.far=2e3};pe.prototype.setViewport=function(e,t,r,n,i){this.camera instanceof Me&&(this.camera.aspect=r/n),i=i||1,this.viewport.x=e,this.viewport.y=t,this.viewport.width=r,this.viewport.height=n,this.viewport.devicePixelRatio=i,this._compositor.resize(r*i,n*i),this._temporalSS.resize(r*i,n*i)};pe.prototype.containPoint=function(e,t){var r=this.viewport,n=this.layer.renderer.getHeight();return t=n-t,e>=r.x&&t>=r.y&&e<=r.x+r.width&&t<=r.y+r.height};var Pa=new Ze;pe.prototype.castRay=function(e,t,r){var n=this.layer.renderer,i=n.viewport;return n.viewport=this.viewport,n.screenToNDC(e,t,Pa),this.camera.castRay(Pa,r),n.viewport=i,r};pe.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],n=r.geometry;n.needsSortVerticesProgressively&&n.needsSortVerticesProgressively()&&(this._needsSortProgressively=!0),n.needsSortTrianglesProgressively&&n.needsSortTrianglesProgressively()&&(this._needsSortProgressively=!0)}this._frame=0,this._temporalSS.resetFrame()};pe.prototype.render=function(e,t){this._doRender(e,t,this._frame),this._frame++};pe.prototype.needsAccumulate=function(){return this.needsTemporalSS()||this._needsSortProgressively};pe.prototype.needsTemporalSS=function(){var e=this._enableTemporalSS;return e==="auto"&&(e=this._enablePostEffect),e};pe.prototype.hasDOF=function(){return this._enableDOF};pe.prototype.isAccumulateFinished=function(){return this.needsTemporalSS()?this._temporalSS.isFinished():this._frame>30};pe.prototype._doRender=function(e,t,r){var n=this.scene,i=this.camera;r=r||0,this._updateTransparent(e,n,i,r),t||(this._shadowMapPass.kernelPCF=this._pcfKernels[0],this._shadowMapPass.render(e,n,i,!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,i),this._compositor.updateNormal(e,n,i,this._temporalSS.getFrame())),this._updateSSAO(e,n,i,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(n,i,!0,!0),s.unbind(e),this.needsTemporalSS()&&t?(this._compositor.composite(e,n,i,this._temporalSS.getSourceFrameBuffer(),this._temporalSS.getFrame()),e.setViewport(this.viewport),this._temporalSS.render(e)):(e.setViewport(this.viewport),this._compositor.composite(e,n,i,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(n,i,!0,!0),e.restoreClear(),s.unbind(e),e.setViewport(this.viewport),this._temporalSS.render(e)}else e.setViewport(this.viewport),e.render(n,i,!0,!0)};pe.prototype._updateTransparent=function(e,t,r,n){for(var i=new P,a=new z,s=r.getWorldPosition(),o=t.getRenderList(r).transparent,l=0;l<o.length;l++){var c=o[l],u=c.geometry;z.invert(a,c.worldTransform),P.transformMat4(i,s,a),u.needsSortTriangles&&u.needsSortTriangles()&&u.doSortTriangles(i,n),u.needsSortVertices&&u.needsSortVertices()&&u.doSortVertices(i,n)}};pe.prototype._updateSSAO=function(e,t,r){var n=this._enableSSAO&&this._enablePostEffect;n&&this._compositor.updateSSAO(e,t,r,this._temporalSS.getFrame());for(var i=t.getRenderList(r),a=0;a<i.opaque.length;a++){var s=i.opaque[a];s.renderNormal&&s.material[n?"enableTexture":"disableTexture"]("ssaoMap"),n&&s.material.set("ssaoMap",this._compositor.getSSAOTexture())}};pe.prototype._updateShadowPCFKernel=function(e){for(var t=this._pcfKernels[e%this._pcfKernels.length],r=this.scene.getRenderList(this.camera),n=r.opaque,i=0;i<n.length;i++)n[i].receiveShadow&&(n[i].material.set("pcfKernel",t),n[i].material.define("fragment","PCF_KERNEL_SIZE",t.length/2))};pe.prototype.dispose=function(e){this._compositor.dispose(e.gl),this._temporalSS.dispose(e.gl),this._shadowMapPass.dispose(e)};pe.prototype.setPostEffect=function(e,t){var r=this._compositor;this._enablePostEffect=e.get("enable");var n=e.getModel("bloom"),i=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");n.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(),i.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(n.get("intensity")),r.setEdgeColor(i.get("color")),r.setColorLookupTexture(c.get("lookupTexture"),t),r.setExposure(c.get("exposure")),["radius","quality","intensity"].forEach(function(u){r.setSSAOParameter(u,s.get(u))}),["quality","maxRoughness","physical"].forEach(function(u){r.setSSRParameter(u,o.get(u))}),["quality","focalDistance","focalRange","blurRadius","fstop"].forEach(function(u){r.setDOFParameter(u,a.get(u))}),["brightness","contrast","saturation"].forEach(function(u){r.setColorCorrection(u,c.get(u))})};pe.prototype.setDOFFocusOnPoint=function(e){if(this._enablePostEffect)return e>this.camera.far||e<this.camera.near?void 0:(this._compositor.setDOFParameter("focalDistance",e),!0)};pe.prototype.setTemporalSuperSampling=function(e){this._enableTemporalSS=e.get("enable")};pe.prototype.isLinearSpace=function(){return this._enablePostEffect};pe.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}};pe.prototype.add=function(e){this.rootNode.add(e)};pe.prototype.remove=function(e){this.rootNode.remove(e)};pe.prototype.removeAll=function(e){this.rootNode.removeAll(e)};Object.assign(pe.prototype,xi);function qh(e,t){var r=e.getBoxLayoutParams(),n=xo(r,{width:t.getWidth(),height:t.getHeight()});n.y=t.getHeight()-n.y-n.height,this.viewGL.setViewport(n.x,n.y,n.width,n.height,t.getDevicePixelRatio());var i=e.get("boxWidth"),a=e.get("boxHeight"),s=e.get("boxDepth");this.getAxis("x").setExtent(-i/2,i/2),this.getAxis("y").setExtent(s/2,-s/2),this.getAxis("z").setExtent(-a/2,a/2),this.size=[i,a,s]}function Yh(e,t){var r={};function n(i,a){r[i]=r[i]||[1/0,-1/0],r[i][0]=Math.min(a[0],r[i][0]),r[i][1]=Math.max(a[1],r[i][1])}e.eachSeries(function(i){if(i.coordinateSystem===this){var a=i.getData();["x","y","z"].forEach(function(s){a.mapDimensionsAll(s,!0).forEach(function(o){n(s,a.getDataExtent(o,!0))})})}},this),["xAxis3D","yAxis3D","zAxis3D"].forEach(function(i){e.eachComponent(i,function(a){var s=i.charAt(0),o=a.getReferringComponents("grid3D").models[0],l=o.coordinateSystem;if(l===this){var c=l.getAxis(s);if(!c){var u=yo(r[s]||[1/0,-1/0],a);c=new hn(s,u),c.type=a.get("type");var h=c.type==="category";c.onBand=h&&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 Zh={dimensions:Dr.prototype.dimensions,create:function(e,t){var r=[];e.eachComponent("grid3D",function(a){a.__viewGL=a.__viewGL||new pe;var s=new Dr;s.model=a,s.viewGL=a.__viewGL,a.coordinateSystem=s,r.push(s),s.resize=qh,s.update=Yh});var n=["xAxis3D","yAxis3D","zAxis3D"];function i(a,s){return n.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=i(a,e),s=o[0].getCoordSysModel();o.forEach(function(u){u.getCoordSysModel()})}var l=s.coordinateSystem;a.coordinateSystem=l}}),r}};const Kh=Zh;var Hs=Xa.extend({type:"cartesian3DAxis",axis:null,getCoordSysModel:function(){return this.ecModel.queryComponents({mainType:"grid3D",index:this.option.gridIndex,id:this.option.gridId})[0]}});To(Hs);const Qh=Hs;var zs={show:!0,grid3DIndex:0,inverse:!1,name:"",nameLocation:"middle",nameTextStyle:{fontSize:16},nameGap:20,axisPointer:{},axisLine:{},axisTick:{},axisLabel:{},splitArea:{}},Jh=xt({boundaryGap:!0,axisTick:{alignWithLabel:!1,interval:"auto"},axisLabel:{interval:"auto"},axisPointer:{label:{show:!1}}},zs),Oi=xt({boundaryGap:[0,0],splitNumber:5,axisPointer:{label:{}}},zs),ef=Ir({scale:!0,min:"dataMin",max:"dataMax"},Oi),Gs=Ir({logBase:10},Oi);Gs.scale=!0;const tf={categoryAxis3D:Jh,valueAxis3D:Oi,timeAxis3D:ef,logAxis3D:Gs};var rf=["value","category","time","log"];function nf(e,t,r,n,i){rf.forEach(function(a){var s=r.extend({type:t+"Axis3D."+a,__ordinalMeta:null,mergeDefaultAndTheme:function(o,l){var c=l.getTheme();xt(o,c.get(a+"Axis3D")),xt(o,this.getDefaultOption()),o.type=n(t,o)},optionUpdated:function(){var o=this.option;o.type==="category"&&(this.__ordinalMeta=Eo.createByAxisModel(this))},getCategories:function(){if(this.option.type==="category")return this.__ordinalMeta.categories},getOrdinalMeta:function(){return this.__ordinalMeta},defaultOption:xt(Ao(tf[a+"Axis3D"]),i||{},!0)});e.registerComponentModel(s)}),e.registerSubTypeDefaulter(t+"Axis3D",So(n,t))}function af(e,t){return t.type||(t.data?"category":"value")}function sf(e){e.registerComponentModel(ih),e.registerComponentView(fh),e.registerCoordinateSystem("grid3D",Kh),["x","y","z"].forEach(function(t){nf(e,t,Qh,af,{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(n){n.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 of={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 Xn(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function Vs(e,t,r,n,i){var a=r,s=e[t];Xn(e,t,n);for(var o=r;o<n;o++)i(e[o],s)<0&&(Xn(e,o,a),a++);return Xn(e,n,a),a}function fn(e,t,r,n){if(r<n){var i=Math.floor((r+n)/2),a=Vs(e,i,r,n,t);fn(e,t,r,a-1),fn(e,t,a+1,n)}}function dn(){this._parts=[]}dn.prototype.step=function(e,t,r){var n=e.length;if(r===0){this._parts=[],this._sorted=!1;var i=Math.floor(n/2);this._parts.push({pivot:i,left:0,right:n-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=Vs(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 u=a.length-1-this._currentSortPartIdx;if(fn(e,t,a[u].left,a[u].right),this._currentSortPartIdx++,this._currentSortPartIdx===a.length)return this._sorted=!0,!0}return!1}};dn.sort=fn;var ar=yn.vec3,Da=ar.create(),Oa=ar.create(),Ia=ar.create();const lf={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 n=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 i=0,a,s=0;s<r.length;){n.get(r[s++],Da),n.get(r[s++],Oa),n.get(r[s++],Ia);var o=ar.sqrDist(Da,e),l=ar.sqrDist(Oa,e),c=ar.sqrDist(Ia,e),u=Math.min(o,l);u=Math.min(u,c),s===3?(a=u,u=0):u=u-a,this._triangleZList[i++]=u}}for(var h=this._sortedTriangleIndices,s=0;s<h.length;s++)h[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 _=h[s]*3,m=s*3;d[m++]=r[_++],d[m++]=r[_++],d[m]=r[_],f[s]=v[h[s]]}var p=this._indicesTmp;this._indicesTmp=this.indices,this.indices=p;var p=this._triangleZListTmp;this._triangleZListTmp=this._triangleZList,this._triangleZList=p,this.dirtyIndices()},_simpleSort:function(e){var t=this._triangleZList,r=this._sortedTriangleIndices;function n(i,a){return t[a]-t[i]}e?Array.prototype.sort.call(r,n):dn.sort(r,n,0,r.length-1)},_progressiveQuickSort:function(e){var t=this._triangleZList,r=this._sortedTriangleIndices;this._quickSort=this._quickSort||new dn,this._quickSort.step(r,function(n,i){return t[i]-t[n]},e)}};function ui(e,t){const r=e.getItemVisual(t,"style");if(r){const n=e.getVisual("drawType");return r[n]}}function Ba(e,t){const r=e.getItemVisual(t,"style");return r&&r.opacity}function cf(e,t){var r=[];return Sr(e.dimensions,function(n){var i=e.getDimensionInfo(n),a=i.otherDims,s=a[t];s!=null&&s!==!1&&(r[s]=i.name)}),r}function uf(e,t,r){function n(h){var d=[],f=cf(i,"tooltip");f.length?Sr(f,function(_){v(i.get(_,t),_)}):Sr(h,v);function v(_,m){var p=i.getDimensionInfo(m);if(!(!p||p.otherDims.tooltip===!1)){var y=p.type,g="- "+(p.tooltipName||p.name)+": "+(y==="ordinal"?_+"":y==="time"?r?"":Co("yyyy/MM/dd hh:mm:ss",_):Bi(_));g&&d.push(Hr(g))}}return"<br/>"+d.join("<br/>")}var i=e.getData(),a=e.getRawValue(t),s=Ar(a)?n(a):Hr(Bi(a)),o=i.getName(t),l=ui(i,t);wo(l)&&l.colorStops&&(l=(l.colorStops[0]||{}).color),l=l||"transparent";var c=bo(l),u=e.name;return u==="\0-"&&(u=""),u=u?Hr(u)+(r?": ":"<br/>"):"",r?c+u+s:u+c+(o?Hr(o)+": "+s:s)}function hf(e,t,r){r=r||e.getSource();var n=t||Ro(e.get("coordinateSystem"))||["x","y","z"],i=Mo(r,{dimensionsDefine:r.dimensionsDefine||e.get("dimensions"),encodeDefine:r.encodeDefine||e.get("encode"),coordDimensions:n.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"&&i.forEach(function(o){if(n.indexOf(o.coordDim)>=0){var l=e.getReferringComponents(o.coordDim+"Axis3D").models[0];l&&l.get("type")==="category"&&(o.ordinalMeta=l.getOrdinalMeta())}});var a=Lo.enableDataStack(e,i,{byIndex:!0,stackedCoordDimension:"z"}),s=new No(i,e);return s.setCalculationInfo(a),s.initData(r),s}var ks=Po.extend({type:"series.surface",dependencies:["globe","grid3D","geo3D"],visualStyleAccessPath:"itemStyle",formatTooltip:function(e){return uf(this,e)},getInitialData:function(e,t){var r=e.data;function n(Y){return!(isNaN(Y.min)||isNaN(Y.max)||isNaN(Y.step))}function i(Y){var O=$a;return Math.max(O(Y.min),O(Y.max),O(Y.step))+1}if(!r)if(e.parametric){var x=e.parametricEquation||{},E=x.u||{},S=x.v||{};["u","v"].forEach(function(O){n(x[O])}),["x","y","z"].forEach(function(O){x[O]});var R=Math.floor((E.max+E.step-E.min)/E.step),w=Math.floor((S.max+S.step-S.min)/S.step);r=new Float32Array(R*w*5);for(var M=i(E),F=i(S),d=0,f=0;f<w;f++)for(var v=0;v<R;v++){var b=v*E.step+E.min,U=f*S.step+S.min,I=zr(Math.min(b,E.max),M),N=zr(Math.min(U,S.max),F),_=x.x(I,N),m=x.y(I,N),g=x.z(I,N);r[d++]=_,r[d++]=m,r[d++]=g,r[d++]=I,r[d++]=N}}else{var a=e.equation||{},s=a.x||{},o=a.y||{};if(["x","y"].forEach(function(Y){n(a[Y])}),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 u=i(s),h=i(o),d=0,f=0;f<c;f++)for(var v=0;v<l;v++){var _=v*s.step+s.min,m=f*o.step+o.min,p=zr(Math.min(_,s.max),u),y=zr(Math.min(m,o.max),h),g=a.z(p,y);r[d++]=p,r[d++]=y,r[d++]=g}}var G=["x","y","z"];e.parametric&&G.push("u","v");var B=hf(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}});xt(ks.prototype,of);const ff=ks;var Ht=yn.vec3;function df(e){return isNaN(e[0])||isNaN(e[1])||isNaN(e[2])}const vf=Do.extend({type:"surface",__ecgl__:!0,init:function(e,t){this.groupGL=new k.Node},render:function(e,t,r){var n=this._prevSurfaceMesh;this._prevSurfaceMesh=this._surfaceMesh,this._surfaceMesh=n,this._surfaceMesh||(this._surfaceMesh=this._createSurfaceMesh()),this.groupGL.remove(this._prevSurfaceMesh),this.groupGL.add(this._surfaceMesh);var i=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=k.createMaterial(o,["VERTEX_COLOR","DOUBLE_SIDED"])),k.setMaterialFromModel(a,this._surfaceMesh.material,e,r),i&&i.viewGL){i.viewGL.add(this.groupGL);var l=i.viewGL.isLinearSpace()?"define":"undefine";this._surfaceMesh.material[l]("fragment","SRGB_DECODE")}var c=e.get("parametric"),u=e.get("dataShape");u||(u=this._getDataShape(s,c));var h=e.getModel("wireframe"),d=h.get("lineStyle.width"),f=h.get("show")&&d>0;this._updateSurfaceMesh(this._surfaceMesh,e,u,f);var v=this._surfaceMesh.material;f?(v.define("WIREFRAME_QUAD"),v.set("wireframeLineWidth",d),v.set("wireframeLineColor",k.parseColor(h.get("lineStyle.color")))):v.undefine("WIREFRAME_QUAD"),this._initHandler(e,r),this._updateAnimation(e)},_updateAnimation:function(e){k.updateVertexAnimation([["prevPosition","position"],["prevNormal","normal"]],this._prevSurfaceMesh,this._surfaceMesh,e)},_createSurfaceMesh:function(){var e=new k.Mesh({geometry:new k.Geometry({dynamic:!0,sortTriangles:!0}),shadowDepthMaterial:new k.Material({shader:new k.Shader(k.Shader.source("ecgl.sm.depth.vertex"),k.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,lf),e},_initHandler:function(e,t){var r=e.getData(),n=this._surfaceMesh,i=e.coordinateSystem;function a(o,l){for(var c=1/0,u=-1,h=[],d=0;d<o.length;d++){n.geometry.attributes.position.get(o[d],h);var f=Ht.dist(l.array,h);f<c&&(c=f,u=o[d])}return u}n.seriesIndex=e.seriesIndex;var s=-1;n.off("mousemove"),n.off("mouseout"),n.on("mousemove",function(o){var l=a(o.triangle,o.point);if(l>=0){var c=[];n.geometry.attributes.position.get(l,c);for(var u=i.pointToData(c),h=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 _=Ht.squaredDistance(f,u);_<h&&(d=v,h=_)}d!==s&&t.dispatchAction({type:"grid3DShowAxisPointer",value:u}),s=d,n.dataIndex=d}else n.dataIndex=-1},this),n.on("mouseout",function(o){s=-1,n.dataIndex=-1,t.dispatchAction({type:"grid3DHideAxisPointer"})},this)},_updateSurfaceMesh:function(e,t,r,n){var i=e.geometry,a=t.getData(),s=a.getLayout("points"),o=0;a.each(function(lt){a.hasValue(lt)||o++});var l=o||n,c=i.attributes.position,u=i.attributes.normal,h=i.attributes.texcoord0,d=i.attributes.barycentric,f=i.attributes.color,v=r[0],_=r[1],m=t.get("shading"),p=m!=="color";if(l){var y=(v-1)*(_-1)*4;c.init(y),n&&d.init(y)}else c.value=new Float32Array(s);f.init(i.vertexCount),h.init(i.vertexCount);var g=[0,3,1,1,3,2],x=[[1,1,0,0],[0,1,0,1],[1,0,0,1],[1,0,1,0]],E=i.indices=new(i.vertexCount>65535?Uint32Array:Uint16Array)((v-1)*(_-1)*6),S=function(lt,qt,_t){_t[1]=lt*_+qt,_t[0]=lt*_+qt+1,_t[3]=(lt+1)*_+qt+1,_t[2]=(lt+1)*_+qt},R=!1;if(l){var w=[],M=[],F=0;p?u.init(i.vertexCount):u.value=null;for(var b=[[],[],[]],U=[],I=[],N=Ht.create(),G=function(lt,qt,_t){var En=qt*3;return _t[0]=lt[En],_t[1]=lt[En+1],_t[2]=lt[En+2],_t},B=new Float32Array(s.length),Y=new Float32Array(s.length/3*4),O=0;O<a.count();O++)if(a.hasValue(O)){var Fe=k.parseColor(ui(a,O)),he=Ba(a,O);he!=null&&(Fe[3]*=he),Fe[3]<.99&&(R=!0);for(var V=0;V<4;V++)Y[O*4+V]=Fe[V]}for(var xe=[1e7,1e7,1e7],O=0;O<v-1;O++)for(var ae=0;ae<_-1;ae++){var ve=O*(_-1)+ae,_e=ve*4;S(O,ae,w);for(var Ie=!1,V=0;V<4;V++)G(s,w[V],M),df(M)&&(Ie=!0);for(var V=0;V<4;V++)Ie?c.set(_e+V,xe):(G(s,w[V],M),c.set(_e+V,M)),n&&d.set(_e+V,x[V]);for(var V=0;V<6;V++)E[F++]=g[V]+_e;if(p&&!Ie)for(var V=0;V<2;V++){for(var Be=V*3,Re=0;Re<3;Re++){var ze=w[g[Be]+Re];G(s,ze,b[Re])}Ht.sub(U,b[0],b[1]),Ht.sub(I,b[1],b[2]),Ht.cross(N,U,I);for(var Re=0;Re<3;Re++){var Ye=w[g[Be]+Re]*3;B[Ye]=B[Ye]+N[0],B[Ye+1]=B[Ye+1]+N[1],B[Ye+2]=B[Ye+2]+N[2]}}}if(p)for(var O=0;O<B.length/3;O++)G(B,O,N),Ht.normalize(N,N),B[O*3]=N[0],B[O*3+1]=N[1],B[O*3+2]=N[2];for(var Fe=[],nt=[],O=0;O<v-1;O++)for(var ae=0;ae<_-1;ae++){var ve=O*(_-1)+ae,_e=ve*4;S(O,ae,w);for(var V=0;V<4;V++){for(var Re=0;Re<4;Re++)Fe[Re]=Y[w[V]*4+Re];f.set(_e+V,Fe),p&&(G(B,w[V],N),u.set(_e+V,N));var ze=w[V];nt[0]=ze%_/(_-1),nt[1]=Math.floor(ze/_)/(v-1),h.set(_e+V,nt)}ve++}}else{for(var nt=[],O=0;O<a.count();O++){nt[0]=O%_/(_-1),nt[1]=Math.floor(O/_)/(v-1);var Fe=k.parseColor(ui(a,O)),he=Ba(a,O);he!=null&&(Fe[3]*=he),Fe[3]<.99&&(R=!0),f.set(O,Fe),h.set(O,nt)}for(var w=[],Ws=0,O=0;O<v-1;O++)for(var ae=0;ae<_-1;ae++){S(O,ae,w);for(var V=0;V<6;V++)E[Ws++]=w[g[V]]}p?i.generateVertexNormals():u.value=null}e.material.get("normalMap")&&i.generateTangents(),i.updateBoundingBox(),i.dirty(),e.material.transparent=R,e.material.depthMask=!R},_getDataShape:function(e,t){for(var r=-1/0,n=0,i=0,a=!1,s=t?"u":"x",o=e.count(),l=0;l<o;l++){var c=e.get(s,l);c<r&&(i=0,n++),r=c,i++}if((!n||i===1)&&(a=!0),!a)return[n+1,i];for(var u=Math.floor(Math.sqrt(o));u>0;){if(Math.floor(o/u)===o/u)return[u,o/u];u--}return u=Math.floor(Math.sqrt(o)),[u,u]},dispose:function(){this.groupGL.removeAll()},remove:function(){this.groupGL.removeAll()}});function _f(e){e.registerChartView(vf),e.registerSeriesModel(ff),e.registerLayout(function(t,r){t.eachSeriesByType("surface",function(n){var i=n.coordinateSystem;!i||i.type;var a=n.getData(),s=new Float32Array(3*a.count()),o=[NaN,NaN,NaN];if(i&&i.type==="cartesian3D"){var l=i.dimensions,c=l.map(function(u){return n.coordDimToDataDim(u)[0]});a.each(c,function(u,h,d,f){var v;a.hasValue(f)?v=i.dataToPoint([u,h,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 mf=Object.defineProperty,pf=Object.getOwnPropertyDescriptor,jt=(e,t,r,n)=>{for(var i=n>1?void 0:n?pf(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=(n?s(t,r,i):s(i))||i);return n&&i&&mf(t,r,i),i};Oo([Io,Bo,sf,_f]);let Tt=class extends Et(At,Cr,Qs){get chart(){var e,t;return(t=(e=this.$refs.heightmap)==null?void 0:e.chart)!=null?t:null}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:14}},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 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:1},wireframe:{show:this.wireframe}};if(this.bed_mesh){const t=this.bed_mesh.probed_matrix[0].length,r=this.bed_mesh.probed_matrix.length,n=this.bed_mesh.mesh_min[0],i=this.bed_mesh.mesh_max[0],a=this.bed_mesh.mesh_min[1],s=this.bed_mesh.mesh_max[1],o=(i-n)/(t-1),l=(s-a)/(r-1),c=[];let u=0;this.bed_mesh.probed_matrix.forEach(h=>{let d=0;h.forEach(f=>{c.push([n+o*d,a+l*u,f]),d++}),u++}),e.data=c,e.dataShape=[r,t]}return e}get seriesMesh(){const e={type:"surface",name:"mesh",data:[],itemStyle:{opacity:1},wireframe:{show:this.wireframe}};if(this.bed_mesh){const t=this.bed_mesh.mesh_matrix[0].length,r=this.bed_mesh.mesh_matrix.length,n=this.bed_mesh.mesh_min[0],i=this.bed_mesh.mesh_max[0],a=this.bed_mesh.mesh_min[1],s=this.bed_mesh.mesh_max[1],o=(i-n)/(t-1),l=(s-a)/(r-1),c=[];let u=0;this.bed_mesh.mesh_matrix.forEach(h=>{let d=0;h.forEach(f=>{c.push([n+o*d,a+l*u,f]),d++}),u++}),e.data=c,e.dataShape=[r,t]}return e}get seriesFlat(){var r,n,i,a;const e={type:"surface",name:"flat",data:[],itemStyle:{color:[1,1,1,1],opacity:.5},wireframe:{show:this.wireframe}},t=(n=(r=this.$store.state.printer.configfile)==null?void 0:r.settings)==null?void 0:n.bed_mesh;if(t){let s=[1,1];t.probe_count&&typeof t.probe_count=="string"?s=t.probe_count.split(","):t.probe_count?s=t.probe_count.length<2?[t.probe_count,t.probe_count]:t.probe_count:t.round_probe_count&&(s=[t.round_probe_count,t.round_probe_count]);let o=(i=t.mesh_min)!=null?i:[0,0],l=(a=t.mesh_max)!=null?a:[200,200];"mesh_radius"in t&&(o=[t.mesh_radius*-1,t.mesh_radius*-1],l=[t.mesh_radius,t.mesh_radius]);const c=s[0],u=s[1],h=parseFloat(o[0]),d=parseFloat(l[0]),f=parseFloat(o[1]),v=parseFloat(l[1]),_=(d-h)/(c-1),m=(v-f)/(u-1),p=[];for(let y=0;y<u;y++)for(let g=0;g<c;g++)p.push([h+_*g,f+m*y,0]);e.data=p,e.dataShape=[u,c]}return e}get colorMap(){return this.$store.getters["gui/heightmap/getActiveColorSchemeList"]}get visualMapSeriesIndex(){const e=[];return this.showProbed?e.push(0):this.showMesh&&e.push(1),e}get visualMapRange(){return this.scaleGradient?this.heightmapLimit:[-.1,.1]}get heightmapLimit(){let e=0,t=0;if(this.bed_mesh){const r=[];if(this.showProbed)for(const n of this.bed_mesh.probed_matrix)for(const i of n)r.push(i);if(this.showMesh)for(const n of this.bed_mesh.mesh_matrix)for(const i of n)r.push(i);e=Math.min(e,...r),t=Math.max(t,...r)}return[e,t]}get rangeX(){var r,n,i,a;const e=(r=this.$store.state.printer.toolhead)==null?void 0:r.axis_minimum,t=(n=this.$store.state.printer.toolhead)==null?void 0:n.axis_maximum;return[(i=e[0])!=null?i:0,(a=t[0])!=null?a:0]}get rangeY(){var r,n,i,a,s,o;const e=(n=(r=this.$store.state.printer.toolhead)==null?void 0:r.axis_minimum)!=null?n:[0,0],t=(a=(i=this.$store.state.printer.toolhead)==null?void 0:i.axis_maximum)!=null?a:[0,0];return[(s=e[1])!=null?s:0,(o=t[1])!=null?o:0]}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}tooltipFormatter(e){const t=[];return t.push("<b>".concat(e.seriesName,"</b>")),Object.keys(e.encode).sort().forEach(r=>{const n=e.data[e.encode[r][0]].toFixed(r==="z"?3:1);t.push("<b>".concat(r.toUpperCase(),"</b>: ").concat(n," mm"))}),t.join("<br />")}beforeDestroy(){typeof window>"u"||this.chart&&this.chart.dispose()}};jt([Ke({type:Boolean,default:!1})],Tt.prototype,"showProbed",2);jt([Ke({type:Boolean,default:!1})],Tt.prototype,"showMesh",2);jt([Ke({type:Boolean,default:!1})],Tt.prototype,"showFlat",2);jt([Ke({type:Boolean,default:!1})],Tt.prototype,"wireframe",2);jt([Ke({type:Boolean,default:!1})],Tt.prototype,"scaleGradient",2);jt([Ke({type:Number,default:1})],Tt.prototype,"scaleZMax",2);Tt=jt([vt],Tt);var gf=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("e-chart",{ref:"heightmap",staticStyle:{height:"600px",width:"100%",overflow:"hidden"},attrs:{option:e.chartOptions,"init-options":{renderer:"canvas"}}})},xf=[];const Fa={};var yf=St(Tt,gf,xf,!1,Tf,null,null,null);function Tf(e){for(let t in Fa)this[t]=Fa[t]}const Ef=function(){return yf.exports}();var Af=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r(Wt,{attrs:{"card-class":"heightmap-map-panel",title:e.$t("Heightmap.Heightmap"),icon:e.mdiGrid},scopedSlots:e._u([{key:"buttons",fn:function(){return[r(Pe,{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(gt,[e._v(e._s(e.mdiHome))])],1),e.is_active?r(Pe,{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(Pe,{staticClass:"d-none d-sm-flex",attrs:{text:"",tile:"",loading:e.loadings.includes("bedMeshCalibrate"),disabled:e.printerIsPrinting,title:e.$t("Heightmap.TitleCalibrate")},on:{click:function(n){e.calibrateDialog=!0}}},[e._v(" "+e._s(e.$t("Heightmap.Calibrate"))+" ")])]},proxy:!0}])},[r(ft,{staticClass:"d-sm-none text-center pb-0"},[r(to,{staticClass:"v-btn-toggle",attrs:{tile:"",name:"controllers"}},[r(Pe,{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(gt,{attrs:{color:e.homedAxes.includes("xyz")?"primary":"warning",small:""}},[e._v(" "+e._s(e.mdiHome)+" ")])],1),e.bed_mesh?r(Pe,{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(Pe,{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:function(n){e.calibrateDialog=!0}}},[e._v(" "+e._s(e.$t("Heightmap.Calibrate"))+" ")])],1)],1),e.is_active?[r(ft,{staticClass:"py-0 px-0"},[r(ht,[r(we,{},[r(Ef,{attrs:{"show-probed":e.showProbed,"show-mesh":e.showMesh,"show-flat":e.showFlat,wireframe:e.wireframe,"scale-gradient":e.scaleGradient,"scale-z-max":e.scaleZMax}})],1)],1),r(ht,[r(we,{staticClass:"col-12 col-sm-auto pt-0 pb-0 pl-lg-6 d-flex justify-center justify-sm-start"},[r(ro,{staticClass:"mt-0 ml-5",attrs:{label:e.$t("Heightmap.ScaleGradient")},model:{value:e.scaleGradient,callback:function(n){e.scaleGradient=n},expression:"scaleGradient"}})],1),r(we,{staticClass:"d-flex justify-center pt-0 pb-6 pb-lg-3"},[r(Ur,{staticClass:"mx-3 mt-0",attrs:{label:e.$t("Heightmap.Probed"),"hide-details":""},model:{value:e.showProbed,callback:function(n){e.showProbed=n},expression:"showProbed"}}),r(Ur,{staticClass:"mx-3 mt-0",attrs:{label:e.$t("Heightmap.Mesh"),"hide-details":""},model:{value:e.showMesh,callback:function(n){e.showMesh=n},expression:"showMesh"}}),r(Ur,{staticClass:"mx-3 mt-0",attrs:{label:e.$t("Heightmap.Flat"),"hide-details":""},model:{value:e.showFlat,callback:function(n){e.showFlat=n},expression:"showFlat"}}),r(Ur,{staticClass:"mx-3 mt-0",attrs:{label:e.$t("Heightmap.Wireframe"),"hide-details":""},model:{value:e.wireframe,callback:function(n){e.wireframe=n},expression:"wireframe"}})],1)],1)],1),r(nr),r(ft,{staticClass:"pt-0 pb-3"},[r(ht,[r(we,[r(no,{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(n){e.scaleZMax=n},expression:"scaleZMax"}})],1)],1)],1)]:[r(ft,{staticClass:"text-center py-3 font-italic"},[e._v(" "+e._s(e.$t("Heightmap.NoBedMeshHasBeenLoadedYet"))+" ")])],r(Qa,{attrs:{show:e.calibrateDialog},on:{close:function(n){e.calibrateDialog=!1}}})],2)},Sf=[];const Ua={};var wf=St(Kn,Af,Sf,!1,bf,null,null,null);function bf(e){for(let t in Ua)this[t]=Ua[t]}const Cf=function(){return wf.exports}();var Rf=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("div",[r(ht,[e.klipperReadyForGui?[r(we,{staticClass:"col-12 col-md-8 pb-0"},[r(Cf)],1),r(we,{staticClass:"col-12 col-md-4"},[r(El),r(hl)],1)]:[r(we,[r(io,{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)]],2)],1)},Mf=[];const Ha={};var Lf=St(qn,Rf,Mf,!1,Nf,null,null,null);function Nf(e){for(let t in Ha)this[t]=Ha[t]}const Ff=function(){return Lf.exports}();export{Ff as default};