import{z as mr}from"./index.5f349928.js";import{c as Pl,a as Rl,e as Nl,g as Il,m as Ol,A as Bl,M as Nr,b as Fl,n as Ul,u as Ye,d as Gl,f as zl,h as Hl,j as Mt,k as Va,l as Vl,o as kl,p as ss,R as ls,q as Wl,r as ta,s as Dt,t as Xl,v as Zl,w as jl,x as ql,Z as Yl,C as Vr,y as fe,z as Kt,B as Kl,D as hs,E as Ji,F as en,G as Ai,H as us,I as fs,J as cs,K as vn,N as pn,O as Ql,P as $l,Q as Jl,S as ra,T as Ei,U as Pt,V as _a,W as eh,X as th,Y as ka,_ as rh,$ as ih,a0 as nh,a1 as Mr,a2 as Wa,a3 as ah,a4 as oh,a5 as sh,a6 as ds,a7 as St,a8 as At,a9 as lh,aa as hh,ab as Di,ac as uh,ad as fh,ae as vs,af as ch,ag as dh,ah as Xa,ai as Za,aj as ja}from"./index.c9f5bd8b.js";const pp="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAJGSURBVEiJvVcxa9tAGH2nU0NJRFooGJSEEuKYTl7kpRA8OcVL8GC6dOhY6B8IoT8hhGRuyQ/oUjJ0C2kn16O1aGlwG0xoLMjQluJ4cCNdhuZLjuNOltxYb5F1svTe9973HRIDobi0yqO4KsDKAOZwt7hgEEHErRa+//gGAAwA+OPF58LCszsm04LFOIpOzz5wFJdWGfAyD9J/zCiKRw++WjyKq7mRXoNHcdW+zvQG92ybTYPs7+WloN8CrGxjgkZyGjUXAGbXvIXzrZ3OBDrmmLW8+E5eMVVMZA9fv6jMlJZd+dqo2wtHwXGYJEKuGAASiU1ko24v/P32fWd2zVuYKT9x1Ws6EamInUbNNZEBwODj51CtqLC9WVFFDA4OfQA439rppCJe6X56Ja8NDg79tFk6jZpb2H2zIa+dlNb3VWJbdzMpdZp1j45Os+6ZBDiNmmuynVxSMba5CtubFVkEPXAUHIfDtt83RaLGkcpqIhu2/b78AF2OamX0f+oTarSJM9aJGLb9vo4MAGRxuoyNVidZLOc8buRIVKY5lqvTNY5amSlfHbG2q8lqsliuUBWRlC8JOymt76scxuaSLSYROotlMt1I0X2ZrB6Xc9p8gQxbplwNidCNkkqmukDnmcfJNEpOs+6lyRfIME46i0mEacsEki3PPE65bplqRbKItFumiv8iVkWoW2YSdMR7kN678njZA3BhM4hAgD01KZsGGERgRdxqTZtIRcStFsevPz+t+fn7YCjmQcpiHIne2ZfbPHP+aLsCfFQbgbmy9ScAAAAASUVORK5CYII=",mp="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAANnSURBVEiJvZdNTBNBFMf/s7v9gH5Yg1SXraVAQWok8nExISQmRDEGSEQvJHpSE42JF4LEePRACAcvmmiCBxONB9EDIQgBDoqaeICD5WCtBhRKk0rkIy3Ylt31YAeWcVvAQP+n7rw383tv5s2blICqxOXlZaVOBakAYMHuKkag+mWeG8O32a8AQACAd0sXVA6ndhmmK6JgWP4R6uVR4vIS4FI2oH/JKFHz9n3meFmpyxo0JV5W6oTUma7LIAhkL2DJtTWV/lZBKgRss5CszfWi41prDQAYSz0iACSC0+GEPxCOdHSP7zAOC+E80iPtCJsxBVIYBWq/ASD6amgiUwDajAFAyBSWs6u9xtrSUE0XXnk/MRftGw3r+VC/7WafNmMtNNLW2c8CWbkGehqNpR4xXeZsxly6hbSZslChUMph/WfPXumn86zN9SJrZ6ULdna111AoG72t5bTkHnly8UBnezU7L9LW2Q8AtAh3DKZaeT8xx44Rk4kHAM5iNrC2rY5DK93iWt9mzUK2ltMSMZl48/HyfAAQRKfN3trkBk+w/LTvB/WjFW9trhczBZK2qhPB6fVJQqGUk99166zWbq70FZkrfUWpzyEKT/gD/1y1HYG1k9e+h1aXe4fGOYvZIBzKt5urjnqSM3M/45PBMBSosddvt73FGcF62zV/u3sCAOytTW5z1VFPfDIYjty8+5Gdq3dMetItroQ/EAaA3Nrqgn+MfKqxKVBZE71G2mNKJ5447E2bBjiOkNwcWBrqyow+r5j8HgonAlNRao9/CizJC4vzS49fBNXV34p2rvPenZN8nsO2+uZjMDbyYRNcUTa56oMTgamowXWQGH1e0VB82Lb8rO+L1if+KbDEQqVX9xtMPq8rXediwWnvcaSje5yedXFw5CptKqyszfWia6Cn0VRR7gYAQ1lxPriM7QFAhl5Npe3ZwMZTaKw4IgKbn0g1nlwzHSs9HJ8MzoTO3xiEJku2V28Jplnl1lYXaAPQBrL48Pl4tG80DI6D9PLBGT34f4H1AgHSXBkWfu764K6Bt1QKLkhOx2zD5ZfywmIyO+CU+P0Og7ywmAT03+PYboFYUaiOYgKB6ldBTtARNrK9EIHq52SeG9trECuZ58Z4LCz/4ux2MwhKsgElCobV6dC7jULK8p+2P7x6qfFfXN5iAAAAAElFTkSuQmCC",gp="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAK9SURBVEiJvZfBTxNREMa/93ZLESrWGJosW5FQqh7spVxMCKdGMYQ0Eb148KQmGo8EjX8BabhqoglHEy/AoWmQBrmIHOmlHiTVBJHSpDG2aVoMbXeXA52yLtvt1pR+p93NvPnNvDczL8tA8nlHBEUd18ACAHrRXpUYtKQi8A382PsOAAwAhEH5vsZxq80wUzEVa8puelGAzzvCgIedgB6T4dMuXfjGBUUd7xi0JkFRx8XamdblEEV2FrBKtarRswYWEGGzkFzhkOR++mAUALr8QxIAlFM7mXJyO5N9Ob/VYhy9jA/J7/RfjBkTkGAE1L8DQHE5nrAKQJ8xAIhWYXkis6Ou6YkgOT7YTOwXo+sZMxuys5t9w4z10OzMXMwINMq7sjDV5R+SGmVuzJg3cqTPtBkUAPYmH8donSsckprZm4I9kdlRgrZSONmZuRgAUBG2DCYdbCb27UIBwM7OkEyLq77NOkfnp2/LzOkUThkLDIX30V16pYp3hUOSVSANq7qc2qkvEq/I5/ojLyYtEogTvJzcPtVqLYH1i6s/038Li/Et3tvtOGWoQit9/Gx7iy3BZtv1+9V8wo5Ds2Myk2lxlZPbGQDoGQsO2IHVobU20h9TS2CqZrs9SaI2osBbBhej65nicjyhd9ZM8vLrCavJZQsMHM9cOuvh1KcnNFSMcoVDkndlYcoZuD4IAI6rw/3gluMBgMWsJulnNnByFXYFrknAv1ekdlipOm/4Lx9+Tf1K33u+ClWt+zHO6qZgyqpnLDigD0AfSP7th61idD0DziEvvbljBv8vsFkgQIOWMcLvPlttG7ipanBR9rj3Jh4tKbl8pTPgmoSLboeSy1cA8/u41C6QUQQ1UUlk0JIa2E36YozsLMSgJbki8I2zBhmlCHxDQK7wh/f1dYPB1wkoU7Gm7aS/nBRSh3/ajgDbQG0/Bq2jbgAAAABJRU5ErkJggg==",_p="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAMGSURBVEiJvdc9SBtxGAbw5+5MjDHGtmowMYbInbakOsUOgUZCsFSoQVotnboUWtqhS8EhIF06SBHFoUMncXAoGgShVEMcKgak1AytWirWJq2n8TskjRwxXq6DnoQQzeWDPNt98bv/ve+93BEQQ+sZik9YBRAtAMpR2BwREJZ4ipzHOvsLAAgAoAx1PQKJOwXG0oZIwMP/3XRRoPUMATwuBnoqgxaqKn+SFJ+wFg09C8UnrORZTYsaAUQLiQI1Uu2A03zd//lZ7YDTLOH0coq4onbki9aPDdoqOqwtAKAwMTqZXouoxxu87Jq8Ydo73l16s7EeAMIut09hYnRS8Lxgo3vUIW+o0wDAyf5hZOPhS088wAYrOtqaMuE5w/SXyUdyg7YaAGIra6zcqK9R37Npd/qGfFJwMhfU6B51lGiuVQIAt7jsD3Q+/RR2uX3ct9UgAESmZrfCLrcPACp77qZttpJsUdo73l1Sp6kSt8tamxs0zuem7d5+n7hP3dWuE0HxBlKT1aNOrmloxLUQmXSvqOwWpszcbKCUCu7Iu7in7mrXaYf7OkU0+YZygo3uUUdpk1F7fqFKSW33vv3KH4T2VHYLI3AxDolEXAoqGU5upNCIa4FSKSl5o1EXD7DB8MQ0G52ZWz3ZPTiSigISapzcSABw7N8I775591Hd1a6LTM1uAUDpDVqdDQpkWDHtHe8Wa8otLvtlOs1Vld3C8AehvfDENAucNlK26KVw/digTZxIsZU19s/9F25KqeDKzM0Gld3CRGfmVstvt1bngl4I1w44zeLsPdk/jMiN+hqZXoud18PfKaWCE7gYl21NU5N2gCS/g+u3Hnw4Xgtsicd2+9//CLum1/JBgQtWLNNrIQ77eIAN7vQN+cSxl2tNJcFRjzco4hUdbU3xABuMrf7+Vyj0QjgdLtNrUf3qia0Q6KVwKq4wMbpCoRnhVLxQKAAQpLFuCIX/gM+UI5KAsFRkFASEJZKnyPliwzxFzlMIRQ5JtVoBAnQxUCIBjxDY9BLne4r80/Yfqd+V3AcaUT8AAAAASUVORK5CYII=",yp="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAALZSURBVEiJvddbSFNxHAfw7/+cOXU77kKZ7mKoWwWmkA4ko0GFuaLVehB6kCAqeoiCIHoYikhFBaII9lAi4YMPEUIIe/CGBBODLsNYRJKi2Jxmsbm1TZyenR50chg7ulv7vZ0/2++z3+9/2yGIhk6rp9mIkQOpAiBFZiNIwDlZmrJj1jUDAAQA6IOaRo7C2QxjcYNEMMouLA7Q0Gn1BLiaDXRLho7bJ/9O0WzEmDV0O2g2YqS25zSrwYFUUUhgITEmYxH/WVxeIsk3VCr4YzJLvToJW0rt9QlVd2ut5sUjS2Hz7UoAyK3QM9r+jgsl/R2XCSMRAUBxu9Wg6mox8/GykT7zkbl3t4Ty7gqrultrZeYzx9jVv4HQpGM5t0LPaHqfnM9RHVCGJh0zXCC0WdxuNcgbTQb+98pG+sziQ6Xq8I95t1BuUSKo+07bEOv1haNocPz9N9cN6wQfXbr32OYfHHPz0bmGa7akKmZMxqL/iQIATRSyi7GD4dmFIMVI1r29b76wf7zrqaAyS71aefPK4cDoxFI8mFClmpdCv4o/p8miqq4WMwBMl53qSbjVmUJ9A8OfhfLHhcXlJZJMoMsPniYH00q5WKSUS9NF6QJGcNcIzjFhJKLYfZoMqn317KSkrlr/s+n+2zXHV19CFQNAuqj09PEK1uMLsJ7VjYRbDWwdg+mgm+4Vj+u6dSg87wolBWcCXZ+eDQjlj3uAAECOVgVvz2tHqqhIXZinaLpUHrJ/XImXX3DVRbdCKii9XyFWdTY30IoCZu2T83dg2P4r4Vang6qft52jFQWM3zY+FQ/dteJU2xut1G8bn1q6+/CDUH7BioVuGf7hIKmr1vMXkuRETXEiKLDHJREbMku92j84tnO559cclbMe3wZ/yzAmY5FQe2PhTmT+D/xeEaQIOGeWURBwToqlKXu2YZam7DS8fg8lk+WBQJcNlEQwys0vTpCdkSy/tP0DOIOUb4oYb3wAAAAASUVORK5CYII=",xp="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAAL7SURBVEiJvVc9SBthGH6+O5v608aCS+4USUjSgCCCUehgSgZbC02xg6Mt7eLi4lCHgJtChyxCdahTKEIXl4CLSQbFDAVRKF16jdWjxLsipMUYLUYu1+H89FOSu4uEPFO47733eX+e9/0uBBTeLh+vlUM6SC+ANtQXJwT6N43nNvEztwsABAD47s4xncOTOpNVBCkjpf06WOHh7fIR4FUjSA1mePWO9u8cr5VDDSO9AK+VQ00XPbUF5+iw2Do0KLT0BQQAcPjd4tHK2jYA/J5+v23Xjw7SSzh350c7xq5YNNg+NhI0szlaWdu2G4AtYk8yHnH43SJ1fprZUguJtAJcVYEGVcrKyv7TN6tWPnnywPnCzMAViwbbQgOBUlZWDmcXNvIfPv04k/aO6fmZtHdcTGXUczmn3vV233P43eKdLgHFVEa9NTFb3t2Bl59Zwps4k/aOy4Vi8f6zxw+be3ziuZxTzew5s6goqIAAo7SeZDwS2F+fCOyvT3iS8YhzdFgEgEIirVDbjsnxfjOfpsQ0W1YwwvzMZb8BQ9ksiV1xWWZcysoK/U0zK2VlRfKElyRPeKmUlRWH3y3SM3rOBlcTMevIDP++SioAtA4NCrX4qEpMx6VS5A6/W3TFokHn6LBI23Ga2VLZc9ZHTcTAVZkriad9bCQozM9EAEN8lMQViwbZd6uhyewwv7i8I8zPiB2T4/3UMSuelr6AkF9c3qmUGW1BNVhuLrq11Km5VbPSAdfnXvKEl8xsLVVNI7eaS8CoAHB97qvBcmUWUxnV+TwsWK1CdrXmXr/bsCK2tbnyi8s7gCGoSiPCqpva1oXYahVWUnddiAFDzXQjeZLxCH1Ox6eWuxiweR+zoCpn59nuHczCUlw3wV59zT0+EQAOZxc2zK7ASrBdaopCIq2oU3OX2dXSVxZNAE5Q4wd8IZFWWocGr30C1YgTwrvFtzrIo1u8fGsQ6F84jec2G0kKABrPbfL4W/jDOZ3NIPA2gpSUkdLlgwy5fNLgP23/AXH9hd6Of6M+AAAAAElFTkSuQmCC";function vh(e){return Pl(null,e)}var ya={isDimensionStacked:Rl,enableDataStack:Nl,getStackedDimension:Il};function xa(e,t){var r=t;t instanceof Nr||(r=new Nr(t));var i=Fl(r);return i.setExtent(e[0],e[1]),Ul(i,r),i}function ph(e){Ol(e,Bl)}function Tp(e){return mr({url:"/crops/area",method:"get",params:e})}function wp(){return mr({url:"http://121.36.229.60:9080/geoserver/shuzisannong/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=shuzisannong%3Ahuangdaoqu_town&maxFeatures=50&outputFormat=application%2Fjson",method:"get"})}function Sp(e){return mr({url:"crops/cropTypeStatistics",method:"get",params:e})}function Ap(){return mr({url:"http://121.36.229.60:9080/geoserver/shuzisannong/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=shuzisannong%3Ahuangdaoqu_village&maxFeatures=1180&outputFormat=application%2Fjson",method:"get"})}function Ep(){return mr({url:"http://121.36.229.60:9080/geoserver/shuzisannong/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=shuzisannong%3Afenlei&maxFeatures=1180&outputFormat=application%2Fjson",method:"get"})}function bp(e){return mr({url:"crops/cropper",method:"get",params:e})}function Cp(e){return mr({url:"crops/highStandard",method:"get",params:e})}Ye([Gl,zl]);Ye(Hl);function qa(e,t,r){typeof t=="object"&&(r=t,t=null);var i=this,n;if(!(e instanceof Function)){n=[];for(var a in e)e.hasOwnProperty(a)&&n.push(a)}var o=function(l){if(i.apply(this,arguments),e instanceof Function?Ya(this,e.call(this,l)):mh(this,e,n),this.constructor===o)for(var h=o.__initializers__,u=0;u=400?e.onerror&&e.onerror():e.onload&&e.onload(t.response)},e.onerror&&(t.onerror=e.onerror),t.send(null)}const Eh={get:Ah};var Cn,at={};at.supportWebGL=function(){if(Cn==null)try{var e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");if(!t)throw new Error}catch{Cn=!1}return Cn};at.Int8Array=typeof Int8Array>"u"?Array:Int8Array;at.Uint8Array=typeof Uint8Array>"u"?Array:Uint8Array;at.Uint16Array=typeof Uint16Array>"u"?Array:Uint16Array;at.Uint32Array=typeof Uint32Array>"u"?Array:Uint32Array;at.Int16Array=typeof Int16Array>"u"?Array:Int16Array;at.Float32Array=typeof Float32Array>"u"?Array:Float32Array;at.Float64Array=typeof Float64Array>"u"?Array:Float64Array;var sr={};typeof window<"u"?sr=window:typeof global<"u"&&(sr=global);at.requestAnimationFrame=sr.requestAnimationFrame||sr.msRequestAnimationFrame||sr.mozRequestAnimationFrame||sr.webkitRequestAnimationFrame||function(e){setTimeout(e,16)};at.createCanvas=function(){return document.createElement("canvas")};at.createImage=function(){return new sr.Image};at.request={get:Eh.get};at.addEventListener=function(e,t,r,i){e.addEventListener(t,r,i)};at.removeEventListener=function(e,t,r){e.removeEventListener(t,r)};const Pe=at;var We=function(){this.head=null,this.tail=null,this._length=0};We.prototype.insert=function(e){var t=new We.Entry(e);return this.insertEntry(t),t};We.prototype.insertAt=function(e,t){if(!(e<0)){for(var r=this.head,i=0;r&&i!=e;)r=r.next,i++;if(r){var n=new We.Entry(t),a=r.prev;a?(a.next=n,n.prev=a):this.head=n,n.next=r,r.prev=n}else this.insert(t)}};We.prototype.insertBeforeEntry=function(e,t){var r=new We.Entry(e),i=t.prev;i?(i.next=r,r.prev=i):this.head=r,r.next=t,t.prev=r,this._length++};We.prototype.insertEntry=function(e){this.head?(this.tail.next=e,e.prev=this.tail,this.tail=e):this.head=this.tail=e,this._length++};We.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--};We.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}};We.prototype.getHead=function(){if(this.head)return this.head.value};We.prototype.getTail=function(){if(this.tail)return this.tail.value};We.prototype.getAt=function(e){if(!(e<0)){for(var t=this.head,r=0;t&&r!=e;)t=t.next,r++;return t.value}};We.prototype.indexOf=function(e){for(var t=this.head,r=0;t;){if(t.value===e)return r;t=t.next,r++}};We.prototype.length=function(){return this._length};We.prototype.isEmpty=function(){return this._length===0};We.prototype.forEach=function(e,t){for(var r=this.head,i=0,n=typeof t<"u";r;)n?e.call(t,r.value,i):e(r.value,i),r=r.next,i++};We.prototype.clear=function(){this.tail=this.head=null,this._length=0};We.Entry=function(e){this.value=e,this.next=null,this.prev=null};const bh=We;var kr=function(e){this._list=new bh,this._map={},this._maxSize=e||10};kr.prototype.setMaxSize=function(e){this._maxSize=e};kr.prototype.put=function(e,t){if(!this._map.hasOwnProperty(e)){var r=this._list.length();if(r>=this._maxSize&&r>0){var i=this._list.head;this._list.remove(i),delete this._map[i.key]}var n=this._list.insert(t);n.key=e,this._map[e]=n}};kr.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};kr.prototype.remove=function(e){var t=this._map[e];typeof t<"u"&&(delete this._map[e],this._list.remove(t))};kr.prototype.clear=function(){this._list.clear(),this._map={}};const ps=kr;var we={},$a={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 Tt(e){return e=Math.round(e),e<0?0:e>255?255:e}function Ch(e){return e=Math.round(e),e<0?0:e>360?360:e}function di(e){return e<0?0:e>1?1:e}function Ln(e){return e.length&&e.charAt(e.length-1)==="%"?Tt(parseFloat(e)/100*255):Tt(parseInt(e,10))}function Ir(e){return e.length&&e.charAt(e.length-1)==="%"?di(parseFloat(e)/100):di(parseFloat(e))}function Mn(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 Zt(e,t,r){return e+(t-e)*r}function xt(e,t,r,i,n){return e[0]=t,e[1]=r,e[2]=i,e[3]=n,e}function ia(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e}var ms=new ps(20),Pi=null;function xr(e,t){Pi&&ia(Pi,t),Pi=ms.put(e,Pi||t.slice())}we.parse=function(e,t){if(!!e){t=t||[];var r=ms.get(e);if(r)return ia(t,r);e=e+"";var i=e.replace(/ /g,"").toLowerCase();if(i in $a)return ia(t,$a[i]),xr(e,t),t;if(i.charAt(0)==="#"){if(i.length===4){var n=parseInt(i.substr(1),16);if(!(n>=0&&n<=4095)){xt(t,0,0,0,1);return}return xt(t,(n&3840)>>4|(n&3840)>>8,n&240|(n&240)>>4,n&15|(n&15)<<4,1),xr(e,t),t}else if(i.length===7){var n=parseInt(i.substr(1),16);if(!(n>=0&&n<=16777215)){xt(t,0,0,0,1);return}return xt(t,(n&16711680)>>16,(n&65280)>>8,n&255,1),xr(e,t),t}return}var a=i.indexOf("("),o=i.indexOf(")");if(a!==-1&&o+1===i.length){var s=i.substr(0,a),l=i.substr(a+1,o-(a+1)).split(","),h=1;switch(s){case"rgba":if(l.length!==4){xt(t,0,0,0,1);return}h=Ir(l.pop());case"rgb":if(l.length!==3){xt(t,0,0,0,1);return}return xt(t,Ln(l[0]),Ln(l[1]),Ln(l[2]),h),xr(e,t),t;case"hsla":if(l.length!==4){xt(t,0,0,0,1);return}return l[3]=Ir(l[3]),na(l,t),xr(e,t),t;case"hsl":if(l.length!==3){xt(t,0,0,0,1);return}return na(l,t),xr(e,t),t;default:return}}xt(t,0,0,0,1)}};we.parseToFloat=function(e,t){if(t=we.parse(e,t),!!t)return t[0]/=255,t[1]/=255,t[2]/=255,t};function na(e,t){var r=(parseFloat(e[0])%360+360)%360/360,i=Ir(e[1]),n=Ir(e[2]),a=n<=.5?n*(i+1):n+i-n*i,o=n*2-a;return t=t||[],xt(t,Tt(Mn(o,a,r+1/3)*255),Tt(Mn(o,a,r)*255),Tt(Mn(o,a,r-1/3)*255),1),e.length===4&&(t[3]=e[3]),t}function Lh(e){if(!!e){var t=e[0]/255,r=e[1]/255,i=e[2]/255,n=Math.min(t,r,i),a=Math.max(t,r,i),o=a-n,s=(a+n)/2,l,h;if(o===0)l=0,h=0;else{s<.5?h=o/(a+n):h=o/(2-a-n);var u=((a-t)/6+o/2)/o,f=((a-r)/6+o/2)/o,d=((a-i)/6+o/2)/o;t===a?l=d-f:r===a?l=1/3+u-d:i===a&&(l=2/3+f-u),l<0&&(l+=1),l>1&&(l-=1)}var c=[l*360,h,s];return e[3]!=null&&c.push(e[3]),c}}we.lift=function(e,t){var r=we.parse(e);if(r){for(var i=0;i<3;i++)t<0?r[i]=r[i]*(1-t)|0:r[i]=(255-r[i])*t+r[i]|0;return we.stringify(r,r.length===4?"rgba":"rgb")}};we.toHex=function(e){var t=we.parse(e);if(t)return((1<<24)+(t[0]<<16)+(t[1]<<8)+ +t[2]).toString(16).slice(1)};we.fastLerp=function(e,t,r){if(!(!(t&&t.length)||!(e>=0&&e<=1))){r=r||[];var i=e*(t.length-1),n=Math.floor(i),a=Math.ceil(i),o=t[n],s=t[a],l=i-n;return r[0]=Tt(Zt(o[0],s[0],l)),r[1]=Tt(Zt(o[1],s[1],l)),r[2]=Tt(Zt(o[2],s[2],l)),r[3]=di(Zt(o[3],s[3],l)),r}};we.fastMapToColor=we.fastLerp;we.lerp=function(e,t,r){if(!(!(t&&t.length)||!(e>=0&&e<=1))){var i=e*(t.length-1),n=Math.floor(i),a=Math.ceil(i),o=we.parse(t[n]),s=we.parse(t[a]),l=i-n,h=we.stringify([Tt(Zt(o[0],s[0],l)),Tt(Zt(o[1],s[1],l)),Tt(Zt(o[2],s[2],l)),di(Zt(o[3],s[3],l))],"rgba");return r?{color:h,leftIndex:n,rightIndex:a,value:i}:h}};we.mapToColor=we.lerp;we.modifyHSL=function(e,t,r,i){if(e=we.parse(e),e)return e=Lh(e),t!=null&&(e[0]=Ch(t)),r!=null&&(e[1]=Ir(r)),i!=null&&(e[2]=Ir(i)),we.stringify(na(e),"rgba")};we.modifyAlpha=function(e,t){if(e=we.parse(e),e&&t!=null)return e[3]=di(t),we.stringify(e,"rgba")};we.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 Mh=we;var Dh=Mh.parseToFloat,Dn={};function Ja(e){var t=Object.keys(e);t.sort();for(var r=[],i=0;i=0},getEnabledUniforms:function(){return this._enabledUniforms},getTextureUniforms:function(){return this._textureUniforms},set:function(e,t){if(typeof e=="object")for(var r in e){var i=e[r];this.setUniform(r,i)}else this.setUniform(e,t)},get:function(e){var t=this.uniforms[e];if(t)return t.value},attachShader:function(e,t){var r=this.uniforms;this.uniforms=e.createUniforms(),this.shader=e;var i=this.uniforms;this._enabledUniforms=Object.keys(i),this._enabledUniforms.sort(),this._textureUniforms=this._enabledUniforms.filter(function(h){var u=this.uniforms[h].type;return u==="t"||u==="tv"},this);var n=this.vertexDefines,a=this.fragmentDefines;if(this.vertexDefines=je.clone(e.vertexDefines),this.fragmentDefines=je.clone(e.fragmentDefines),t){for(var o in r)i[o]&&(i[o].value=r[o].value);je.defaults(this.vertexDefines,n),je.defaults(this.fragmentDefines,a)}var s={};for(var l in e.textures)s[l]={shaderType:e.textures[l].shaderType,type:e.textures[l].type,enabled:t&&this._textureStatus[l]?this._textureStatus[l].enabled:!1};this._textureStatus=s,this._programKey=""},clone:function(){var e=new this.constructor({name:this.name,shader:this.shader});for(var t in this.uniforms)e.uniforms[t].value=this.uniforms[t].value;return e.depthTest=this.depthTest,e.depthMask=this.depthMask,e.transparent=this.transparent,e.blend=this.blend,e.vertexDefines=je.clone(this.vertexDefines),e.fragmentDefines=je.clone(this.fragmentDefines),e.enableTexture(this.getEnabledTextures()),e.precision=this.precision,e},define:function(e,t,r){var i=this.vertexDefines,n=this.fragmentDefines;e!=="vertex"&&e!=="fragment"&&e!=="both"&&arguments.length<3&&(r=t,t=e,e="both"),r=r!=null?r:null,(e==="vertex"||e==="both")&&i[t]!==r&&(i[t]=r,this._programKey=""),(e==="fragment"||e==="both")&&n[t]!==r&&(n[t]=r,e!=="both"&&(this._programKey=""))},undefine:function(e,t){e!=="vertex"&&e!=="fragment"&&e!=="both"&&arguments.length<2&&(t=e,e="both"),(e==="vertex"||e==="both")&&this.isDefined("vertex",t)&&(delete this.vertexDefines[t],this._programKey=""),(e==="fragment"||e==="both")&&this.isDefined("fragment",t)&&(delete this.fragmentDefines[t],e!=="both"&&(this._programKey=""))},isDefined:function(e,t){switch(e){case"vertex":return this.vertexDefines[t]!==void 0;case"fragment":return this.fragmentDefines[t]!==void 0}},getDefine:function(e,t){switch(e){case"vertex":return this.vertexDefines[t];case"fragment":return this.fragmentDefines[t]}},enableTexture:function(e){if(Array.isArray(e)){for(var t=0;t0&&(n=1/Math.sqrt(n),e[0]=t[0]*n,e[1]=t[1]*n),e};Q.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]};Q.cross=function(e,t,r){var i=t[0]*r[1]-t[1]*r[0];return e[0]=e[1]=0,e[2]=i,e};Q.lerp=function(e,t,r,i){var n=t[0],a=t[1];return e[0]=n+i*(r[0]-n),e[1]=a+i*(r[1]-a),e};Q.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};Q.transformMat2=function(e,t,r){var i=t[0],n=t[1];return e[0]=r[0]*i+r[2]*n,e[1]=r[1]*i+r[3]*n,e};Q.transformMat2d=function(e,t,r){var i=t[0],n=t[1];return e[0]=r[0]*i+r[2]*n+r[4],e[1]=r[1]*i+r[3]*n+r[5],e};Q.transformMat3=function(e,t,r){var i=t[0],n=t[1];return e[0]=r[0]*i+r[3]*n+r[6],e[1]=r[1]*i+r[4]*n+r[7],e};Q.transformMat4=function(e,t,r){var i=t[0],n=t[1];return e[0]=r[0]*i+r[4]*n+r[12],e[1]=r[1]*i+r[5]*n+r[13],e};Q.forEach=function(){var e=Q.create();return function(t,r,i,n,a,o){var s,l;for(r||(r=2),i||(i=0),n?l=Math.min(n*r+i,t.length):l=t.length,s=i;s0&&i.push("#define "+n.toUpperCase()+"_COUNT "+a)}if(r)for(var o=0;ol.getMaxJointNumber()&&(d.USE_SKIN_MATRICES_TEXTURE=null),f+=` `+Rn(d)+` `}a&&(f+=` #define INSTANCING `);var c=f+Rn(t.vertexDefines,s,u),v=f+Rn(t.fragmentDefines,s,u),p=c+` `+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+=` #define SUPPORT_TEXTURE_LOD`),m.indexOf("OES_standard_derivatives")>=0&&(v+=` #define SUPPORT_STANDARD_DERIVATIVES`);var g=Fh(m)+` `+Uh(t.precision)+` `+v+` `+t.shader.fragment,x=oo(p,t.vertexDefines,s),y=oo(g,t.fragmentDefines,s),_=new Oh;_.uniformSemantics=t.shader.uniformSemantics,_.attributes=t.shader.attributes;var w=_.buildProgram(h,t.shader,x,y);return _.__error=w,i[o]=_,_};var so=/uniform\s+(bool|float|int|vec2|vec3|vec4|ivec2|ivec3|ivec4|mat2|mat3|mat4|sampler2D|samplerCube)\s+([\s\S]*?);/g,Gh=/attribute\s+(float|int|vec2|vec3|vec4)\s+([\s\S]*?);/g,lo=/#define\s+(\w+)?(\s+[\d-.]+)?\s*;?\s*\n/g,zh={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 Rt(e){for(var t=[],r=0;r=0){if(d!==s&&d!==u){Tr();break}d=l,v=[];continue}else if(d===s){e==="bool"?c[p].value=g==="true":c[p].value=parseFloat(g),v=null;continue}else if(d===u){var x=g;aa.indexOf(x)>=0||_s.indexOf(x)>=0||ys.indexOf(x)>=0?c[p].semantic=x:x==="ignore"||x==="unconfigurable"?c[p].ignore=!0:e==="bool"?c[p].value=x==="true":c[p].value=parseFloat(x);continue}m(g),d=o}}return c}function N(e,t){typeof e=="object"&&(t=e.fragment,e=e.vertex),e=uo(e),t=uo(t),this._shaderID=Vh(e,t),this._vertexCode=N.parseImport(e),this._fragmentCode=N.parseImport(t),this.attributeSemantics={},this.matrixSemantics={},this.uniformSemantics={},this.matrixSemanticKeys=[],this.uniformTemplates={},this.attributes={},this.textures={},this.vertexDefines={},this.fragmentDefines={},this._parseAttributes(),this._parseUniforms(),this._parseDefines()}N.prototype={constructor:N,createUniforms:function(){var e={};for(var t in this.uniformTemplates){var r=this.uniformTemplates[t];e[t]={type:r.type,value:r.value()}}return e},_parseImport:function(){this._vertexCode=N.parseImport(this.vertex),this._fragmentCode=N.parseImport(this.fragment)},_addSemanticUniform:function(e,t,r){if(aa.indexOf(r)>=0)this.attributeSemantics[r]={symbol:e,type:t};else if(ys.indexOf(r)>=0){var i=!1,n=r;r.match(/TRANSPOSE$/)&&(i=!0,n=r.slice(0,-9)),this.matrixSemantics[r]={symbol:e,type:t,isTranspose:i,semanticNoTranspose:n}}else _s.indexOf(r)>=0&&(this.uniformSemantics[r]={symbol:e,type:t})},_addMaterialUniform:function(e,t,r,i,n,a){a[e]={type:r,value:n?ho.array:i||ho[t],semantic:null}},_parseUniforms:function(){var e={},t=this,r="vertex";this._uniformList=[],this._vertexCode=this._vertexCode.replace(so,n),r="fragment",this._fragmentCode=this._fragmentCode.replace(so,n),t.matrixSemanticKeys=Object.keys(this.matrixSemantics);function i(a){return a!=null?function(){return a}:null}function n(a,o,s){var l=fo(o,s),h=[];for(var u in l){var f=l[u],d=f.semantic,c=u,v=zh[o],p=i(l[u].value);l[u].isArray&&(c+="["+l[u].arraySize+"]",v+="v"),h.push(c),t._uniformList.push(u),f.ignore||((o==="sampler2D"||o==="samplerCube")&&(t.textures[u]={shaderType:r,type:o}),d?t._addSemanticUniform(u,v,d):t._addMaterialUniform(u,o,v,p,l[u].isArray,e))}return h.length>0?"uniform "+o+" "+h.join(",")+`; `:""}this.uniformTemplates=e},_parseAttributes:function(){var e={},t=this;this._vertexCode=this._vertexCode.replace(Gh,r);function r(i,n,a){var o=fo(n,a),s=Hh[n]||1,l=[];for(var h in o){var u=o[h].semantic;if(e[h]={type:"float",size:s,semantic:u||null},u){if(aa.indexOf(u)<0)throw new Error('Unkown semantic "'+u+'"');t.attributeSemantics[u]={symbol:h,type:n}}l.push(h)}return"attribute "+n+" "+l.join(",")+`; `}this.attributes=e},_parseDefines:function(){var e=this,t="vertex";this._vertexCode=this._vertexCode.replace(lo,r),t="fragment",this._fragmentCode=this._fragmentCode.replace(lo,r);function r(i,n,a){var o=t==="vertex"?e.vertexDefines:e.fragmentDefines;return o[n]||(a==="false"?o[n]=!1:a==="true"?o[n]=!0:o[n]=a?isNaN(parseFloat(a))?a.trim():parseFloat(a):null),""}},clone:function(){var e=xs[this._shaderID],t=new N(e.vertex,e.fragment);return t}};Object.defineProperty&&(Object.defineProperty(N.prototype,"shaderID",{get:function(){return this._shaderID}}),Object.defineProperty(N.prototype,"vertex",{get:function(){return this._vertexCode}}),Object.defineProperty(N.prototype,"fragment",{get:function(){return this._fragmentCode}}),Object.defineProperty(N.prototype,"uniforms",{get:function(){return this._uniformList}}));var kh=/(@import)\s*([0-9a-zA-Z_\-\.]*)/g;N.parseImport=function(e){return e=e.replace(kh,function(n,r,i){var n=N.source(i);return n?N.parseImport(n):(console.error('Shader chunk "'+i+'" not existed in library'),"")}),e};var Wh=/(@export)\s*([0-9a-zA-Z_\-\.]*)\s*\n([\s\S]*?)@end/g;N.import=function(e){e.replace(Wh,function(t,r,i,a){var a=a.replace(/(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+\x24)/g,"");if(a){for(var o=i.split("."),s=N.codes,l=0,h;l 0.0) { if (texture2D(alphaMap, v_Texcoord).a <= alphaCutoff) { discard; } } gl_FragColor = vec4(0.0,0.0,0.0,1.0); } @end`;var pe={};pe.create=function(){var e=new Ke(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};pe.clone=function(e){var t=new Ke(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};pe.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};pe.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};pe.transpose=function(e,t){if(e===t){var r=t[1],i=t[2],n=t[3],a=t[6],o=t[7],s=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=r,e[6]=t[9],e[7]=t[13],e[8]=i,e[9]=a,e[11]=t[14],e[12]=n,e[13]=o,e[14]=s}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e};pe.invert=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],o=t[4],s=t[5],l=t[6],h=t[7],u=t[8],f=t[9],d=t[10],c=t[11],v=t[12],p=t[13],m=t[14],g=t[15],x=r*s-i*o,y=r*l-n*o,_=r*h-a*o,w=i*l-n*s,S=i*h-a*s,b=n*h-a*l,A=u*p-f*v,C=u*m-d*v,P=u*g-c*v,L=f*m-d*p,R=f*g-c*p,I=d*g-c*m,D=x*I-y*R+_*L+w*P-S*C+b*A;return D?(D=1/D,e[0]=(s*I-l*R+h*L)*D,e[1]=(n*R-i*I-a*L)*D,e[2]=(p*b-m*S+g*w)*D,e[3]=(d*S-f*b-c*w)*D,e[4]=(l*P-o*I-h*C)*D,e[5]=(r*I-n*P+a*C)*D,e[6]=(m*_-v*b-g*y)*D,e[7]=(u*b-d*_+c*y)*D,e[8]=(o*R-s*P+h*A)*D,e[9]=(i*P-r*R-a*A)*D,e[10]=(v*S-p*_+g*x)*D,e[11]=(f*_-u*S-c*x)*D,e[12]=(s*C-o*L-l*A)*D,e[13]=(r*L-i*C+n*A)*D,e[14]=(p*y-v*w-m*x)*D,e[15]=(u*w-f*y+d*x)*D,e):null};pe.adjoint=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],o=t[4],s=t[5],l=t[6],h=t[7],u=t[8],f=t[9],d=t[10],c=t[11],v=t[12],p=t[13],m=t[14],g=t[15];return e[0]=s*(d*g-c*m)-f*(l*g-h*m)+p*(l*c-h*d),e[1]=-(i*(d*g-c*m)-f*(n*g-a*m)+p*(n*c-a*d)),e[2]=i*(l*g-h*m)-s*(n*g-a*m)+p*(n*h-a*l),e[3]=-(i*(l*c-h*d)-s*(n*c-a*d)+f*(n*h-a*l)),e[4]=-(o*(d*g-c*m)-u*(l*g-h*m)+v*(l*c-h*d)),e[5]=r*(d*g-c*m)-u*(n*g-a*m)+v*(n*c-a*d),e[6]=-(r*(l*g-h*m)-o*(n*g-a*m)+v*(n*h-a*l)),e[7]=r*(l*c-h*d)-o*(n*c-a*d)+u*(n*h-a*l),e[8]=o*(f*g-c*p)-u*(s*g-h*p)+v*(s*c-h*f),e[9]=-(r*(f*g-c*p)-u*(i*g-a*p)+v*(i*c-a*f)),e[10]=r*(s*g-h*p)-o*(i*g-a*p)+v*(i*h-a*s),e[11]=-(r*(s*c-h*f)-o*(i*c-a*f)+u*(i*h-a*s)),e[12]=-(o*(f*m-d*p)-u*(s*m-l*p)+v*(s*d-l*f)),e[13]=r*(f*m-d*p)-u*(i*m-n*p)+v*(i*d-n*f),e[14]=-(r*(s*m-l*p)-o*(i*m-n*p)+v*(i*l-n*s)),e[15]=r*(s*d-l*f)-o*(i*d-n*f)+u*(i*l-n*s),e};pe.determinant=function(e){var t=e[0],r=e[1],i=e[2],n=e[3],a=e[4],o=e[5],s=e[6],l=e[7],h=e[8],u=e[9],f=e[10],d=e[11],c=e[12],v=e[13],p=e[14],m=e[15],g=t*o-r*a,x=t*s-i*a,y=t*l-n*a,_=r*s-i*o,w=r*l-n*o,S=i*l-n*s,b=h*v-u*c,A=h*p-f*c,C=h*m-d*c,P=u*p-f*v,L=u*m-d*v,R=f*m-d*p;return g*R-x*L+y*P+_*C-w*A+S*b};pe.multiply=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=t[3],s=t[4],l=t[5],h=t[6],u=t[7],f=t[8],d=t[9],c=t[10],v=t[11],p=t[12],m=t[13],g=t[14],x=t[15],y=r[0],_=r[1],w=r[2],S=r[3];return e[0]=y*i+_*s+w*f+S*p,e[1]=y*n+_*l+w*d+S*m,e[2]=y*a+_*h+w*c+S*g,e[3]=y*o+_*u+w*v+S*x,y=r[4],_=r[5],w=r[6],S=r[7],e[4]=y*i+_*s+w*f+S*p,e[5]=y*n+_*l+w*d+S*m,e[6]=y*a+_*h+w*c+S*g,e[7]=y*o+_*u+w*v+S*x,y=r[8],_=r[9],w=r[10],S=r[11],e[8]=y*i+_*s+w*f+S*p,e[9]=y*n+_*l+w*d+S*m,e[10]=y*a+_*h+w*c+S*g,e[11]=y*o+_*u+w*v+S*x,y=r[12],_=r[13],w=r[14],S=r[15],e[12]=y*i+_*s+w*f+S*p,e[13]=y*n+_*l+w*d+S*m,e[14]=y*a+_*h+w*c+S*g,e[15]=y*o+_*u+w*v+S*x,e};pe.multiplyAffine=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=t[4],s=t[5],l=t[6],h=t[8],u=t[9],f=t[10],d=t[12],c=t[13],v=t[14],p=r[0],m=r[1],g=r[2];return e[0]=p*i+m*o+g*h,e[1]=p*n+m*s+g*u,e[2]=p*a+m*l+g*f,p=r[4],m=r[5],g=r[6],e[4]=p*i+m*o+g*h,e[5]=p*n+m*s+g*u,e[6]=p*a+m*l+g*f,p=r[8],m=r[9],g=r[10],e[8]=p*i+m*o+g*h,e[9]=p*n+m*s+g*u,e[10]=p*a+m*l+g*f,p=r[12],m=r[13],g=r[14],e[12]=p*i+m*o+g*h+d,e[13]=p*n+m*s+g*u+c,e[14]=p*a+m*l+g*f+v,e};pe.mul=pe.multiply;pe.mulAffine=pe.multiplyAffine;pe.translate=function(e,t,r){var i=r[0],n=r[1],a=r[2],o,s,l,h,u,f,d,c,v,p,m,g;return t===e?(e[12]=t[0]*i+t[4]*n+t[8]*a+t[12],e[13]=t[1]*i+t[5]*n+t[9]*a+t[13],e[14]=t[2]*i+t[6]*n+t[10]*a+t[14],e[15]=t[3]*i+t[7]*n+t[11]*a+t[15]):(o=t[0],s=t[1],l=t[2],h=t[3],u=t[4],f=t[5],d=t[6],c=t[7],v=t[8],p=t[9],m=t[10],g=t[11],e[0]=o,e[1]=s,e[2]=l,e[3]=h,e[4]=u,e[5]=f,e[6]=d,e[7]=c,e[8]=v,e[9]=p,e[10]=m,e[11]=g,e[12]=o*i+u*n+v*a+t[12],e[13]=s*i+f*n+p*a+t[13],e[14]=l*i+d*n+m*a+t[14],e[15]=h*i+c*n+g*a+t[15]),e};pe.scale=function(e,t,r){var i=r[0],n=r[1],a=r[2];return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[3]=t[3]*i,e[4]=t[4]*n,e[5]=t[5]*n,e[6]=t[6]*n,e[7]=t[7]*n,e[8]=t[8]*a,e[9]=t[9]*a,e[10]=t[10]*a,e[11]=t[11]*a,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e};pe.rotate=function(e,t,r,i){var n=i[0],a=i[1],o=i[2],s=Math.sqrt(n*n+a*a+o*o),l,h,u,f,d,c,v,p,m,g,x,y,_,w,S,b,A,C,P,L,R,I,D,O;return Math.abs(s)0&&(a=1/Math.sqrt(a),e[0]=t[0]*a,e[1]=t[1]*a,e[2]=t[2]*a),e};j.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]};j.cross=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=r[0],s=r[1],l=r[2];return e[0]=n*l-a*s,e[1]=a*o-i*l,e[2]=i*s-n*o,e};j.lerp=function(e,t,r,i){var n=t[0],a=t[1],o=t[2];return e[0]=n+i*(r[0]-n),e[1]=a+i*(r[1]-a),e[2]=o+i*(r[2]-o),e};j.random=function(e,t){t=t||1;var r=Dr()*2*Math.PI,i=Dr()*2-1,n=Math.sqrt(1-i*i)*t;return e[0]=Math.cos(r)*n,e[1]=Math.sin(r)*n,e[2]=i*t,e};j.transformMat4=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=r[3]*i+r[7]*n+r[11]*a+r[15];return o=o||1,e[0]=(r[0]*i+r[4]*n+r[8]*a+r[12])/o,e[1]=(r[1]*i+r[5]*n+r[9]*a+r[13])/o,e[2]=(r[2]*i+r[6]*n+r[10]*a+r[14])/o,e};j.transformMat3=function(e,t,r){var i=t[0],n=t[1],a=t[2];return e[0]=i*r[0]+n*r[3]+a*r[6],e[1]=i*r[1]+n*r[4]+a*r[7],e[2]=i*r[2]+n*r[5]+a*r[8],e};j.transformQuat=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=r[0],s=r[1],l=r[2],h=r[3],u=h*i+s*a-l*n,f=h*n+l*i-o*a,d=h*a+o*n-s*i,c=-o*i-s*n-l*a;return e[0]=u*h+c*-o+f*-l-d*-s,e[1]=f*h+c*-s+d*-o-u*-l,e[2]=d*h+c*-l+u*-s-f*-o,e};j.rotateX=function(e,t,r,i){var n=[],a=[];return n[0]=t[0]-r[0],n[1]=t[1]-r[1],n[2]=t[2]-r[2],a[0]=n[0],a[1]=n[1]*Math.cos(i)-n[2]*Math.sin(i),a[2]=n[1]*Math.sin(i)+n[2]*Math.cos(i),e[0]=a[0]+r[0],e[1]=a[1]+r[1],e[2]=a[2]+r[2],e};j.rotateY=function(e,t,r,i){var n=[],a=[];return n[0]=t[0]-r[0],n[1]=t[1]-r[1],n[2]=t[2]-r[2],a[0]=n[2]*Math.sin(i)+n[0]*Math.cos(i),a[1]=n[1],a[2]=n[2]*Math.cos(i)-n[0]*Math.sin(i),e[0]=a[0]+r[0],e[1]=a[1]+r[1],e[2]=a[2]+r[2],e};j.rotateZ=function(e,t,r,i){var n=[],a=[];return n[0]=t[0]-r[0],n[1]=t[1]-r[1],n[2]=t[2]-r[2],a[0]=n[0]*Math.cos(i)-n[1]*Math.sin(i),a[1]=n[0]*Math.sin(i)+n[1]*Math.cos(i),a[2]=n[2],e[0]=a[0]+r[0],e[1]=a[1]+r[1],e[2]=a[2]+r[2],e};j.forEach=function(){var e=j.create();return function(t,r,i,n,a,o){var s,l;for(r||(r=3),i||(i=0),n?l=Math.min(n*r+i,t.length):l=t.length,s=i;s1?0:Math.acos(n)};const E=j;N.import(Ts);var Te=B.create,co={};function vo(e){return e.material}function Xh(e,t,r){return t.uniforms[r].value}function Zh(e,t,r,i){return r!==i}function jh(e){return!0}function po(){}var mo={float:M.FLOAT,byte:M.BYTE,ubyte:M.UNSIGNED_BYTE,short:M.SHORT,ushort:M.UNSIGNED_SHORT};function qh(e,t,r){this.availableAttributes=e,this.availableAttributeSymbols=t,this.indicesBuffer=r,this.vao=null}function Yh(e){var t,r;this.bind=function(i){t||(t=Pe.createCanvas(),t.width=t.height=1,t.getContext("2d"));var n=i.gl,a=!r;a&&(r=n.createTexture()),n.bindTexture(n.TEXTURE_2D,r),a&&n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t)},this.unbind=function(i){i.gl.bindTexture(i.gl.TEXTURE_2D,null)},this.isRenderable=function(){return!0}}var qt=nt.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=Pe.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 Sh(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 gs(this),this._placeholderTexture=new Yh},{resize:function(e,t){var r=this.canvas,i=this.devicePixelRatio;e!=null?(r.style&&(r.style.width=e+"px",r.style.height=t+"px"),r.width=e*i,r.height=t*i,this._width=e,this._height=t):(this._width=r.width/i,this._height=r.height/i),this.setViewport(0,0,this._width,this._height)},getWidth:function(){return this._width},getHeight:function(){return this._height},getViewportAspect:function(){var e=this.viewport;return e.width/e.height},setDevicePixelRatio:function(e){this.devicePixelRatio=e,this.resize(this._width,this._height)},getDevicePixelRatio:function(){return this.devicePixelRatio},getGLExtension:function(e){return this._glinfo.getExtension(e)},getGLParameter:function(e){return this._glinfo.getParameter(e)},setViewport:function(e,t,r,i,n){if(typeof e=="object"){var a=e;e=a.x,t=a.y,r=a.width,i=a.height,n=a.devicePixelRatio}n=n||this.devicePixelRatio,this.gl.viewport(e*n,t*n,r*n,i*n),this.viewport={x:e,y:t,width:r,height:i,devicePixelRatio:n}},saveViewport:function(){this._viewportStack.push(this.viewport)},restoreViewport:function(){this._viewportStack.length>0&&this.setViewport(this._viewportStack.pop())},saveClear:function(){this._clearStack.push({clearBit:this.clearBit,clearColor:this.clearColor})},restoreClear:function(){if(this._clearStack.length>0){var e=this._clearStack.pop();this.clearColor=e.clearColor,this.clearBit=e.clearBit}},bindSceneRendering:function(e){this._sceneRendering=e},render:function(e,t,r,i){var n=this.gl,a=this.clearColor;if(this.clearBit){n.colorMask(!0,!0,!0,!0),n.depthMask(!0);var o=this.viewport,s=!1,l=o.devicePixelRatio;(o.width!==this._width||o.height!==this._height||l&&l!==this.devicePixelRatio||o.x||o.y)&&(s=!0,n.enable(n.SCISSOR_TEST),n.scissor(o.x*l,o.y*l,o.width*l,o.height*l)),n.clearColor(a[0],a[1],a[2],a[3]),n.clear(this.clearBit),s&&n.disable(n.SCISSOR_TEST)}if(r||e.update(!1),e.updateLights(),t=t||e.getMainCamera(),!t){console.error("Can't find camera in the scene.");return}t.update();var h=e.updateRenderList(t,!0);this._sceneRendering=e;var u=h.opaque,f=h.transparent,d=e.material;e.trigger("beforerender",this,e,t,h),i?(this.renderPreZ(u,e,t),n.depthFunc(n.LEQUAL)):n.depthFunc(n.LESS);for(var c=Te(),v=E.create(),p=0;p0){var s=e[n-1],l=s.joints?s.joints.length:0,h=a.joints?a.joints.length:0;if(h===l&&a.material===s.material&&a.lightGroup===s.lightGroup){a.__program=s.__program;continue}}var u=this._programMgr.getProgram(a,o,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||vo,r.getUniform=r.getUniform||Xh,r.isMaterialChanged=r.isMaterialChanged||Zh,r.beforeRender=r.beforeRender||po,r.afterRender=r.afterRender||po;var i=r.ifRender||jh;this.updatePrograms(e,this._sceneRendering,r),r.sortCompare&&e.sort(r.sortCompare);var n=this.viewport,a=n.devicePixelRatio,o=[n.x*a,n.y*a,n.width*a,n.height*a],s=this.devicePixelRatio,l=this.__currentFrameBuffer?[this.__currentFrameBuffer.getTextureWidth(),this.__currentFrameBuffer.getTextureHeight()]:[this._width*s,this._height*s],h=[o[2],o[3]],u=Date.now();t?(B.copy(xe.VIEW,t.viewMatrix.array),B.copy(xe.PROJECTION,t.projectionMatrix.array),B.copy(xe.VIEWINVERSE,t.worldTransform.array)):(B.identity(xe.VIEW),B.identity(xe.PROJECTION),B.identity(xe.VIEWINVERSE)),B.multiply(xe.VIEWPROJECTION,xe.PROJECTION,xe.VIEW),B.invert(xe.PROJECTIONINVERSE,xe.PROJECTION),B.invert(xe.VIEWPROJECTIONINVERSE,xe.VIEWPROJECTION);for(var f=this.gl,d=this._sceneRendering,c,v,p,m,g,x,y,_,w,S,b,A,C=null,P=0;Pthis.getMaxJointNumber()){var a=n.getSubSkinMatricesTexture(e.__uid__,e.joints);t.useTextureSlot(this,a,r),t.setUniform(i,"1i","skinMatricesTexture",r),t.setUniform(i,"1f","skinMatricesTextureSize",a.width)}else{var o=n.getSubSkinMatrices(e.__uid__,e.joints);t.setUniformOfSemantic(i,"SKIN_MATRIX",o)}},_renderObject:function(e,t,r){var i=this.gl,n=e.geometry,a=e.mode;a==null&&(a=4);var o=null,s=e.isInstancedMesh&&e.isInstancedMesh();if(s&&(o=this.getGLExtension("ANGLE_instanced_arrays"),!o)){console.warn("Device not support ANGLE_instanced_arrays extension");return}var l;if(s&&(l=this._bindInstancedAttributes(e,r,o)),t.indicesBuffer){var h=this.getGLExtension("OES_element_index_uint"),u=h&&n.indices instanceof Uint32Array,f=u?i.UNSIGNED_INT:i.UNSIGNED_SHORT;s?o.drawElementsInstancedANGLE(a,t.indicesBuffer.count,f,0,e.getInstanceCount()):i.drawElements(a,t.indicesBuffer.count,f,0)}else s?o.drawArraysInstancedANGLE(a,0,n.vertexCount,e.getInstanceCount()):i.drawArrays(a,0,n.vertexCount);if(s)for(var d=0;dr?r:e}var ve=Math.atan2,mt=Math.asin,wr=Math.abs;Z.eulerFromQuat=function(e,t,d){e._dirty=!0,t=t.array;var i=e.array,n=t[0],a=t[1],o=t[2],s=t[3],l=n*n,h=a*a,u=o*o,f=s*s,d=(d||"XYZ").toUpperCase();switch(d){case"XYZ":i[0]=ve(2*(n*s-a*o),f-l-h+u),i[1]=mt(pt(2*(n*o+a*s),-1,1)),i[2]=ve(2*(o*s-n*a),f+l-h-u);break;case"YXZ":i[0]=mt(pt(2*(n*s-a*o),-1,1)),i[1]=ve(2*(n*o+a*s),f-l-h+u),i[2]=ve(2*(n*a+o*s),f-l+h-u);break;case"ZXY":i[0]=mt(pt(2*(n*s+a*o),-1,1)),i[1]=ve(2*(a*s-o*n),f-l-h+u),i[2]=ve(2*(o*s-n*a),f-l+h-u);break;case"ZYX":i[0]=ve(2*(n*s+o*a),f-l-h+u),i[1]=mt(pt(2*(a*s-n*o),-1,1)),i[2]=ve(2*(n*a+o*s),f+l-h-u);break;case"YZX":i[0]=ve(2*(n*s-o*a),f-l+h-u),i[1]=ve(2*(a*s-n*o),f+l-h-u),i[2]=mt(pt(2*(n*a+o*s),-1,1));break;case"XZY":i[0]=ve(2*(n*s+a*o),f-l+h-u),i[1]=ve(2*(n*o+a*s),f+l-h-u),i[2]=mt(pt(2*(o*s-n*a),-1,1));break;default:console.warn("Unkown order: "+d)}return e};Z.eulerFromMat3=function(e,t,v){var i=t.array,n=i[0],a=i[3],o=i[6],s=i[1],l=i[4],h=i[7],u=i[2],f=i[5],d=i[8],c=e.array,v=(v||"XYZ").toUpperCase();switch(v){case"XYZ":c[1]=mt(pt(o,-1,1)),wr(o)<.99999?(c[0]=ve(-h,d),c[2]=ve(-a,n)):(c[0]=ve(f,l),c[2]=0);break;case"YXZ":c[0]=mt(-pt(h,-1,1)),wr(h)<.99999?(c[1]=ve(o,d),c[2]=ve(s,l)):(c[1]=ve(-u,n),c[2]=0);break;case"ZXY":c[0]=mt(pt(f,-1,1)),wr(f)<.99999?(c[1]=ve(-u,d),c[2]=ve(-a,l)):(c[1]=0,c[2]=ve(s,n));break;case"ZYX":c[1]=mt(-pt(u,-1,1)),wr(u)<.99999?(c[0]=ve(f,d),c[2]=ve(s,n)):(c[0]=0,c[2]=ve(-a,l));break;case"YZX":c[2]=mt(pt(s,-1,1)),wr(s)<.99999?(c[0]=ve(-h,l),c[1]=ve(-u,n)):(c[0]=0,c[1]=ve(o,d));break;case"XZY":c[2]=mt(-pt(a,-1,1)),wr(a)<.99999?(c[0]=ve(f,l),c[1]=ve(o,n)):(c[0]=ve(-h,d),c[1]=0);break;default:console.warn("Unkown order: "+v)}return e._dirty=!0,e};Object.defineProperties(Z,{POSITIVE_X:{get:function(){return new Z(1,0,0)}},NEGATIVE_X:{get:function(){return new Z(-1,0,0)}},POSITIVE_Y:{get:function(){return new Z(0,1,0)}},NEGATIVE_Y:{get:function(){return new Z(0,-1,0)}},POSITIVE_Z:{get:function(){return new Z(0,0,1)}},NEGATIVE_Z:{get:function(){return new Z(0,0,-1)}},UP:{get:function(){return new Z(0,1,0)}},ZERO:{get:function(){return new Z}}});const U=Z;var On=1e-5,ji=function(e,t){this.origin=e||new U,this.direction=t||new U};ji.prototype={constructor:ji,intersectPlane:function(e,t){var r=e.normal.array,i=e.distance,n=this.origin.array,a=this.direction.array,o=E.dot(r,a);if(o===0)return null;t||(t=new U);var s=(E.dot(r,n)-i)/o;return E.scaleAndAdd(t.array,n,a,-s),t._dirty=!0,t},mirrorAgainstPlane:function(e){var t=E.dot(e.normal.array,this.direction.array);E.scaleAndAdd(this.direction.array,this.direction.array,e.normal.array,-t*2),this.direction._dirty=!0},distanceToPoint:function(){var e=E.create();return function(t){E.sub(e,t,this.origin.array);var r=E.dot(e,this.direction.array);if(r<0)return E.distance(this.origin.array,t);var i=E.lenSquared(e);return Math.sqrt(i-r*r)}}(),intersectSphere:function(){var e=E.create();return function(t,r,i){var n=this.origin.array,a=this.direction.array;t=t.array,E.sub(e,t,n);var o=E.dot(e,a),s=E.squaredLength(e),l=s-o*o,h=r*r;if(!(l>h)){var u=Math.sqrt(h-l),f=o-u,d=o+u;return i||(i=new U),f<0?d<0?null:(E.scaleAndAdd(i.array,n,a,d),i):(E.scaleAndAdd(i.array,n,a,f),i)}}}(),intersectBoundingBox:function(e,t){var r=this.direction.array,i=this.origin.array,n=e.min.array,a=e.max.array,o=1/r[0],s=1/r[1],l=1/r[2],h,u,f,d,c,v;if(o>=0?(h=(n[0]-i[0])*o,u=(a[0]-i[0])*o):(u=(n[0]-i[0])*o,h=(a[0]-i[0])*o),s>=0?(f=(n[1]-i[1])*s,d=(a[1]-i[1])*s):(d=(n[1]-i[1])*s,f=(a[1]-i[1])*s),h>d||f>u||((f>h||h!==h)&&(h=f),(d=0?(c=(n[2]-i[2])*l,v=(a[2]-i[2])*l):(v=(n[2]-i[2])*l,c=(a[2]-i[2])*l),h>v||c>u)||((c>h||h!==h)&&(h=c),(v=0?h:u;return t||(t=new U),E.scaleAndAdd(t.array,i,r,p),t},intersectTriangle:function(){var e=E.create(),t=E.create(),r=E.create(),i=E.create();return function(n,a,o,s,l,h){var u=this.direction.array,f=this.origin.array;n=n.array,a=a.array,o=o.array,E.sub(e,a,n),E.sub(t,o,n),E.cross(i,t,u);var d=E.dot(e,i);if(s){if(d>-On)return null}else if(d>-On&&d1)return null;E.cross(i,e,r);var v=E.dot(u,i)/d;if(v<0||v>1||c+v>1)return null;E.cross(i,e,t);var p=-E.dot(r,i)/d;return p<0?null:(l||(l=new U),h&&U.set(h,1-c-v,c,v),E.scaleAndAdd(l.array,f,u,p),l)}}(),applyTransform:function(e){U.add(this.direction,this.direction,this.origin),U.transformMat4(this.origin,this.origin,e),U.transformMat4(this.direction,this.direction,e),U.sub(this.direction,this.direction,this.origin),U.normalize(this.direction,this.direction)},copy:function(e){U.copy(this.origin,e.origin),U.copy(this.direction,e.direction)},clone:function(){var e=new ji;return e.copy(this),e}};const tn=ji;var J={};J.create=function(){var e=new Ke(4);return e[0]=0,e[1]=0,e[2]=0,e[3]=0,e};J.clone=function(e){var t=new Ke(4);return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};J.fromValues=function(e,t,r,i){var n=new Ke(4);return n[0]=e,n[1]=t,n[2]=r,n[3]=i,n};J.copy=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e};J.set=function(e,t,r,i,n){return e[0]=t,e[1]=r,e[2]=i,e[3]=n,e};J.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};J.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};J.sub=J.subtract;J.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};J.mul=J.multiply;J.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};J.div=J.divide;J.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};J.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};J.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};J.scaleAndAdd=function(e,t,r,i){return e[0]=t[0]+r[0]*i,e[1]=t[1]+r[1]*i,e[2]=t[2]+r[2]*i,e[3]=t[3]+r[3]*i,e};J.distance=function(e,t){var r=t[0]-e[0],i=t[1]-e[1],n=t[2]-e[2],a=t[3]-e[3];return Math.sqrt(r*r+i*i+n*n+a*a)};J.dist=J.distance;J.squaredDistance=function(e,t){var r=t[0]-e[0],i=t[1]-e[1],n=t[2]-e[2],a=t[3]-e[3];return r*r+i*i+n*n+a*a};J.sqrDist=J.squaredDistance;J.length=function(e){var t=e[0],r=e[1],i=e[2],n=e[3];return Math.sqrt(t*t+r*r+i*i+n*n)};J.len=J.length;J.squaredLength=function(e){var t=e[0],r=e[1],i=e[2],n=e[3];return t*t+r*r+i*i+n*n};J.sqrLen=J.squaredLength;J.negate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=-t[3],e};J.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};J.normalize=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],o=r*r+i*i+n*n+a*a;return o>0&&(o=1/Math.sqrt(o),e[0]=t[0]*o,e[1]=t[1]*o,e[2]=t[2]*o,e[3]=t[3]*o),e};J.dot=function(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]+e[3]*t[3]};J.lerp=function(e,t,r,i){var n=t[0],a=t[1],o=t[2],s=t[3];return e[0]=n+i*(r[0]-n),e[1]=a+i*(r[1]-a),e[2]=o+i*(r[2]-o),e[3]=s+i*(r[3]-s),e};J.random=function(e,t){return t=t||1,e[0]=Dr(),e[1]=Dr(),e[2]=Dr(),e[3]=Dr(),J.normalize(e,e),J.scale(e,e,t),e};J.transformMat4=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=t[3];return e[0]=r[0]*i+r[4]*n+r[8]*a+r[12]*o,e[1]=r[1]*i+r[5]*n+r[9]*a+r[13]*o,e[2]=r[2]*i+r[6]*n+r[10]*a+r[14]*o,e[3]=r[3]*i+r[7]*n+r[11]*a+r[15]*o,e};J.transformQuat=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=r[0],s=r[1],l=r[2],h=r[3],u=h*i+s*a-l*n,f=h*n+l*i-o*a,d=h*a+o*n-s*i,c=-o*i-s*n-l*a;return e[0]=u*h+c*-o+f*-l-d*-s,e[1]=f*h+c*-s+d*-o-u*-l,e[2]=d*h+c*-l+u*-s-f*-o,e};J.forEach=function(){var e=J.create();return function(t,r,i,n,a,o){var s,l;for(r||(r=4),i||(i=0),n?l=Math.min(n*r+i,t.length):l=t.length,s=i;s.999999?(i[0]=0,i[1]=0,i[2]=0,i[3]=1,i):(E.cross(e,n,a),i[0]=e[0],i[1]=e[1],i[2]=e[2],i[3]=1+o,se.normalize(i,i))}}();se.setAxes=function(){var e=ie.create();return function(t,r,i,n){return e[0]=i[0],e[3]=i[1],e[6]=i[2],e[1]=n[0],e[4]=n[1],e[7]=n[2],e[2]=-r[0],e[5]=-r[1],e[8]=-r[2],se.normalize(t,se.fromMat3(t,e))}}();se.clone=G.clone;se.fromValues=G.fromValues;se.copy=G.copy;se.set=G.set;se.identity=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e};se.setAxisAngle=function(e,t,r){r=r*.5;var i=Math.sin(r);return e[0]=i*t[0],e[1]=i*t[1],e[2]=i*t[2],e[3]=Math.cos(r),e};se.add=G.add;se.multiply=function(e,t,r){var i=t[0],n=t[1],a=t[2],o=t[3],s=r[0],l=r[1],h=r[2],u=r[3];return e[0]=i*u+o*s+n*h-a*l,e[1]=n*u+o*l+a*s-i*h,e[2]=a*u+o*h+i*l-n*s,e[3]=o*u-i*s-n*l-a*h,e};se.mul=se.multiply;se.scale=G.scale;se.rotateX=function(e,t,r){r*=.5;var i=t[0],n=t[1],a=t[2],o=t[3],s=Math.sin(r),l=Math.cos(r);return e[0]=i*l+o*s,e[1]=n*l+a*s,e[2]=a*l-n*s,e[3]=o*l-i*s,e};se.rotateY=function(e,t,r){r*=.5;var i=t[0],n=t[1],a=t[2],o=t[3],s=Math.sin(r),l=Math.cos(r);return e[0]=i*l-a*s,e[1]=n*l+o*s,e[2]=a*l+i*s,e[3]=o*l-n*s,e};se.rotateZ=function(e,t,r){r*=.5;var i=t[0],n=t[1],a=t[2],o=t[3],s=Math.sin(r),l=Math.cos(r);return e[0]=i*l+n*s,e[1]=n*l-i*s,e[2]=a*l+o*s,e[3]=o*l-a*s,e};se.calculateW=function(e,t){var r=t[0],i=t[1],n=t[2];return e[0]=r,e[1]=i,e[2]=n,e[3]=Math.sqrt(Math.abs(1-r*r-i*i-n*n)),e};se.dot=G.dot;se.lerp=G.lerp;se.slerp=function(e,t,r,i){var n=t[0],a=t[1],o=t[2],s=t[3],l=r[0],h=r[1],u=r[2],f=r[3],d,c,v,p,m;return c=n*l+a*h+o*u+s*f,c<0&&(c=-c,l=-l,h=-h,u=-u,f=-f),1-c>1e-6?(d=Math.acos(c),v=Math.sin(d),p=Math.sin((1-i)*d)/v,m=Math.sin(i*d)/v):(p=1-i,m=i),e[0]=p*n+m*l,e[1]=p*a+m*h,e[2]=p*o+m*u,e[3]=p*s+m*f,e};se.invert=function(e,t){var r=t[0],i=t[1],n=t[2],a=t[3],o=r*r+i*i+n*n+a*a,s=o?1/o:0;return e[0]=-r*s,e[1]=-i*s,e[2]=-n*s,e[3]=a*s,e};se.conjugate=function(e,t){return e[0]=-t[0],e[1]=-t[1],e[2]=-t[2],e[3]=t[3],e};se.length=G.length;se.len=se.length;se.squaredLength=G.squaredLength;se.sqrLen=se.squaredLength;se.normalize=G.normalize;se.fromMat3=function(e,t){var r=t[0]+t[4]+t[8],i;if(r>0)i=Math.sqrt(r+1),e[3]=.5*i,i=.5/i,e[0]=(t[5]-t[7])*i,e[1]=(t[6]-t[2])*i,e[2]=(t[1]-t[3])*i;else{var n=0;t[4]>t[0]&&(n=1),t[8]>t[n*3+n]&&(n=2);var a=(n+1)%3,o=(n+2)%3;i=Math.sqrt(t[n*3+n]-t[a*3+a]-t[o*3+o]+1),e[n]=.5*i,i=.5/i,e[3]=(t[a*3+o]-t[o*3+a])*i,e[a]=(t[a*3+n]+t[n*3+a])*i,e[o]=(t[o*3+n]+t[n*3+o])*i}return e};const Y=se;var ye=function(){this._axisX=new U,this._axisY=new U,this._axisZ=new U,this.array=B.create(),this._dirty=!0};ye.prototype={constructor:ye,setArray:function(e){for(var t=0;t0){var t=this.min,r=this.max,i=t.array,n=r.array;Oi(i,e[0]),Oi(n,e[0]);for(var a=1;an[0]&&(n[0]=o[0]),o[1]>n[1]&&(n[1]=o[1]),o[2]>n[2]&&(n[2]=o[2])}t._dirty=!0,r._dirty=!0}},union:function(e){var t=this.min,r=this.max;return E.min(t.array,t.array,e.min.array),E.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 E.max(t.array,t.array,e.min.array),E.min(r.array,r.array,e.max.array),t._dirty=!0,r._dirty=!0,this},intersectBoundingBox:function(e){var t=this.min.array,r=this.max.array,i=e.min.array,n=e.max.array;return!(t[0]>n[0]||t[1]>n[1]||t[2]>n[2]||r[0]=n[0]&&r[1]>=n[1]&&r[2]>=n[2]},containPoint:function(e){var t=this.min.array,r=this.max.array,i=e.array;return t[0]<=i[0]&&t[1]<=i[1]&&t[2]<=i[2]&&r[0]>=i[0]&&r[1]>=i[1]&&r[2]>=i[2]},isFinite:function(){var e=this.min.array,t=this.max.array;return isFinite(e[0])&&isFinite(e[1])&&isFinite(e[2])&&isFinite(t[0])&&isFinite(t[1])&&isFinite(t[2])},applyTransform:function(e){this.transformFrom(this,e)},transformFrom:function(){var e=E.create(),t=E.create(),r=E.create(),i=E.create(),n=E.create(),a=E.create();return function(o,s){var l=o.min.array,h=o.max.array,u=s.array;return e[0]=u[0]*l[0],e[1]=u[1]*l[0],e[2]=u[2]*l[0],t[0]=u[0]*h[0],t[1]=u[1]*h[0],t[2]=u[2]*h[0],r[0]=u[4]*l[1],r[1]=u[5]*l[1],r[2]=u[6]*l[1],i[0]=u[4]*h[1],i[1]=u[5]*h[1],i[2]=u[6]*h[1],n[0]=u[8]*l[2],n[1]=u[9]*l[2],n[2]=u[10]*l[2],a[0]=u[8]*h[2],a[1]=u[9]*h[2],a[2]=u[10]*h[2],l=this.min.array,h=this.max.array,l[0]=Math.min(e[0],t[0])+Math.min(r[0],i[0])+Math.min(n[0],a[0])+u[12],l[1]=Math.min(e[1],t[1])+Math.min(r[1],i[1])+Math.min(n[1],a[1])+u[13],l[2]=Math.min(e[2],t[2])+Math.min(r[2],i[2])+Math.min(n[2],a[2])+u[14],h[0]=Math.max(e[0],t[0])+Math.max(r[0],i[0])+Math.max(n[0],a[0])+u[12],h[1]=Math.max(e[1],t[1])+Math.max(r[1],i[1])+Math.max(n[1],a[1])+u[13],h[2]=Math.max(e[2],t[2])+Math.max(r[2],i[2])+Math.max(n[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,i=e.array,n=t[0],a=t[1],o=t[2],s=r[0],l=r[1],h=t[2],u=r[0],f=r[1],d=r[2];if(i[15]===1)t[0]=i[0]*n+i[12],t[1]=i[5]*a+i[13],r[2]=i[10]*o+i[14],r[0]=i[0]*u+i[12],r[1]=i[5]*f+i[13],t[2]=i[10]*d+i[14];else{var c=-1/o;t[0]=i[0]*n*c,t[1]=i[5]*a*c,r[2]=(i[10]*o+i[14])*c,c=-1/h,r[0]=i[0]*s*c,r[1]=i[5]*l*c,c=-1/d,t[2]=(i[10]*d+i[14])*c}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]=E.fromValues(0,0,0);this.vertices=e}var r=this.min.array,i=this.max.array;return Ht(e[0],r[0],r[1],r[2]),Ht(e[1],r[0],i[1],r[2]),Ht(e[2],i[0],r[1],r[2]),Ht(e[3],i[0],i[1],r[2]),Ht(e[4],r[0],r[1],i[2]),Ht(e[5],r[0],i[1],i[2]),Ht(e[6],i[0],r[1],i[2]),Ht(e[7],i[0],i[1],i[2]),this},copy:function(e){var t=this.min,r=this.max;return Oi(t.array,e.min.array),Oi(r.array,e.max.array),t._dirty=!0,r._dirty=!0,this},clone:function(){var e=new qi;return e.copy(this),e}};const tt=qi;var Kh=0,Qh=nt.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")+"_"+Kh++),this.position||(this.position=new U),this.rotation||(this.rotation=new ws),this.scale||(this.scale=new U(1,1,1)),this.worldTransform=new k,this.localTransform=new k,this._children=[]},{target:null,invisible:!1,isSkinnedMesh:function(){return!1},isRenderable:function(){return!1},setName:function(e){var t=this._scene;if(t){var r=t._nodeRepository;delete r[this.name],r[e]=this}this.name=e},add:function(e){var t=e._parent;if(t!==this){t&&t.remove(e),e._parent=this,this._children.push(e);var r=this._scene;r&&r!==e.scene&&e.traverse(this._addSelfToScene,this),e._needsUpdateWorldTransform=!0}},remove:function(e){var t=this._children,r=t.indexOf(e);r<0||(t.splice(r,1),e._parent=null,this._scene&&e.traverse(this._removeSelfFromScene,this))},removeAll:function(){for(var e=this._children,t=0;t0},beforeRender:function(e){},afterRender:function(e,t){},getBoundingBox:function(e,t){return t=Lt.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=Lt.prototype.clone.call(this);t.geometry=this.geometry,t.material=this.material;for(var r=0;r=0&&w[y]>1e-4&&(E.transformMat4(A,_,g[S[y]]),E.scaleAndAdd(b,b,A,w[y]));C.set(x,b)}}for(var x=0;x>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(ne.prototype,"width",{get:function(){return this._width},set:function(e){this._width=e}});Object.defineProperty(ne.prototype,"height",{get:function(){return this._height},set:function(e){this._height=e}});ne.BYTE=M.BYTE;ne.UNSIGNED_BYTE=M.UNSIGNED_BYTE;ne.SHORT=M.SHORT;ne.UNSIGNED_SHORT=M.UNSIGNED_SHORT;ne.INT=M.INT;ne.UNSIGNED_INT=M.UNSIGNED_INT;ne.FLOAT=M.FLOAT;ne.HALF_FLOAT=36193;ne.UNSIGNED_INT_24_8_WEBGL=34042;ne.DEPTH_COMPONENT=M.DEPTH_COMPONENT;ne.DEPTH_STENCIL=M.DEPTH_STENCIL;ne.ALPHA=M.ALPHA;ne.RGB=M.RGB;ne.RGBA=M.RGBA;ne.LUMINANCE=M.LUMINANCE;ne.LUMINANCE_ALPHA=M.LUMINANCE_ALPHA;ne.SRGB=35904;ne.SRGB_ALPHA=35906;ne.COMPRESSED_RGB_S3TC_DXT1_EXT=33776;ne.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777;ne.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778;ne.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779;ne.NEAREST=M.NEAREST;ne.LINEAR=M.LINEAR;ne.NEAREST_MIPMAP_NEAREST=M.NEAREST_MIPMAP_NEAREST;ne.LINEAR_MIPMAP_NEAREST=M.LINEAR_MIPMAP_NEAREST;ne.NEAREST_MIPMAP_LINEAR=M.NEAREST_MIPMAP_LINEAR;ne.LINEAR_MIPMAP_LINEAR=M.LINEAR_MIPMAP_LINEAR;ne.REPEAT=M.REPEAT;ne.CLAMP_TO_EDGE=M.CLAMP_TO_EDGE;ne.MIRRORED_REPEAT=M.MIRRORED_REPEAT;const W=ne;var ct=oa.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=oa.prototype.clone.call(this);return e.skeleton=this.skeleton,this.joints&&(e.joints=this.joints.slice()),e}});ct.POINTS=M.POINTS;ct.LINES=M.LINES;ct.LINE_LOOP=M.LINE_LOOP;ct.LINE_STRIP=M.LINE_STRIP;ct.TRIANGLES=M.TRIANGLES;ct.TRIANGLE_STRIP=M.TRIANGLE_STRIP;ct.TRIANGLE_FAN=M.TRIANGLE_FAN;ct.BACK=M.BACK;ct.FRONT=M.FRONT;ct.FRONT_AND_BACK=M.FRONT_AND_BACK;ct.CW=M.CW;ct.CCW=M.CCW;const lr=ct;var gn={};gn.isPowerOfTwo=function(e){return(e&e-1)===0};gn.nextPowerOfTwo=function(e){return e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e++,e};gn.nearestPowerOfTwo=function(e){return Math.pow(2,Math.round(Math.log(e)/Math.LN2))};const Ss=gn;var go=Ss.isPowerOfTwo;function _o(e){return Math.pow(2,Math.round(Math.log(e)/Math.LN2))}function Jh(e,t){var r=_o(e.width),i=_o(e.height);t=t||document.createElement("canvas"),t.width=r,t.height=i;var n=t.getContext("2d");return n.drawImage(e.image,0,0,r,i),t}var Aa=W.extend(function(){return{image:null,pixels:null,mipmaps:[],convertToPOT:!1}},{textureType:"texture2D",update:function(e){var t=e.gl;t.bindTexture(t.TEXTURE_2D,this._cache.get("webgl_texture")),this.updateCommon(e);var r=this.format,i=this.type,n=!!(this.convertToPOT&&!this.mipmaps.length&&this.image&&(this.wrapS===W.REPEAT||this.wrapT===W.REPEAT)&&this.NPOT);t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,n?this.wrapS:this.getAvailableWrapS()),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,n?this.wrapT:this.getAvailableWrapT()),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,n?this.magFilter:this.getAvailableMagFilter()),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,n?this.minFilter:this.getAvailableMinFilter());var a=e.getGLExtension("EXT_texture_filter_anisotropic");if(a&&this.anisotropic>1&&t.texParameterf(t.TEXTURE_2D,a.TEXTURE_MAX_ANISOTROPY_EXT,this.anisotropic),i===36193){var o=e.getGLExtension("OES_texture_half_float");o||(i=M.FLOAT)}if(this.mipmaps.length)for(var s=this.width,l=this.height,h=0;h=W.COMPRESSED_RGB_S3TC_DXT1_EXT?e.compressedTexImage2D(e.TEXTURE_2D,r,a,i,n,0,t.pixels):e.texImage2D(e.TEXTURE_2D,r,a,i,n,0,a,o,t.pixels)},generateMipmap:function(e){var t=e.gl;this.useMipmap&&!this.NPOT&&(t.bindTexture(t.TEXTURE_2D,this._cache.get("webgl_texture")),t.generateMipmap(t.TEXTURE_2D))},isPowerOfTwo:function(){return go(this.width)&&go(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=Pe.createImage();t&&(r.crossOrigin=t);var i=this;return r.onload=function(){i.dirty(),i.trigger("success",i)},r.onerror=function(){i.trigger("error",i)},r.src=e,this.image=r,this}});Object.defineProperty(Aa.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(Aa.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 $=Aa;function As(e){return{byte:Pe.Int8Array,ubyte:Pe.Uint8Array,short:Pe.Int16Array,ushort:Pe.Uint16Array}[e]||Pe.Float32Array}function Fn(e){return"attr_"+e}function Or(e,t,r,i){switch(this.name=e,this.type=t,this.size=r,this.semantic=i||"",this.value=null,r){case 1:this.get=function(n){return this.value[n]},this.set=function(n,a){this.value[n]=a},this.copy=function(n,a){this.value[n]=this.value[n]};break;case 2:this.get=function(n,a){var o=this.value;return a[0]=o[n*2],a[1]=o[n*2+1],a},this.set=function(n,a){var o=this.value;o[n*2]=a[0],o[n*2+1]=a[1]},this.copy=function(n,a){var o=this.value;a*=2,n*=2,o[n]=o[a],o[n+1]=o[a+1]};break;case 3:this.get=function(n,a){var o=n*3,s=this.value;return a[0]=s[o],a[1]=s[o+1],a[2]=s[o+2],a},this.set=function(n,a){var o=n*3,s=this.value;s[o]=a[0],s[o+1]=a[1],s[o+2]=a[2]},this.copy=function(n,a){var o=this.value;a*=3,n*=3,o[n]=o[a],o[n+1]=o[a+1],o[n+2]=o[a+2]};break;case 4:this.get=function(n,a){var o=this.value,s=n*4;return a[0]=o[s],a[1]=o[s+1],a[2]=o[s+2],a[3]=o[s+3],a},this.set=function(n,a){var o=this.value,s=n*4;o[s]=a[0],o[s+1]=a[1],o[s+2]=a[2],o[s+3]=a[3]},this.copy=function(n,a){var o=this.value;a*=4,n*=4,o[n]=o[a],o[n+1]=o[a+1],o[n+2]=o[a+2],o[n+3]=o[a+3]}}}Or.prototype.init=function(e){if(!this.value||this.value.length!==e*this.size){var t=As(this.type);this.value=new t(e*this.size)}};Or.prototype.fromArray=function(e){var t=As(this.type),r;if(e[0]&&e[0].length){var i=0,n=this.size;r=new t(e.length*n);for(var a=0;a=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?Pe.Uint32Array:Pe.Uint16Array;if(e[0]&&e[0].length){var i=0,n=3;t=new r(e.length*n);for(var a=0;a=0?(t.splice(r,1),delete this.attributes[e],!0):!1},getAttribute:function(e){return this.attributes[e]},getEnabledAttributes:function(){var e=this._enabledAttributes,t=this._attributeList;if(e)return e;for(var r=[],i=this.vertexCount,n=0;na[0]&&(a[0]=s),l>a[1]&&(a[1]=l),h>a[2]&&(a[2]=h)}r._dirty=!0,i._dirty=!0}},generateVertexNormals:function(){if(!!this.vertexCount){var e=this.indices,t=this.attributes,r=t.position.value,i=t.normal.value;if(!i||i.length!==r.length)i=t.normal.value=new Pe.Float32Array(r.length);else for(var n=0;n65535&&(this.indices=new Pe.Uint32Array(this.indices));for(var e=this.attributes,t=this.indices,r=this.getEnabledAttributes(),i={},n=0;nthis.distance,n=1;n<8;n++)if(E.dot(t[n].array,r)>this.distance!=i)return!0},intersectLine:function(){var e=E.create();return function(t,r,i){var n=this.distanceToPoint(t),a=this.distanceToPoint(r);if(n>0&&a>0||n<0&&a<0)return null;var o=this.normal.array,s=this.distance,l=t.array;E.sub(e,r.array,t.array),E.normalize(e,e);var h=E.dot(o,e);if(h===0)return null;i||(i=new U);var u=(E.dot(o,l)-s)/h;return E.scaleAndAdd(i.array,l,e,-u),i._dirty=!0,i}}(),applyTransform:function(){var e=B.create(),t=G.create(),r=G.create();return r[3]=1,function(i){i=i.array,E.scale(r,this.normal.array,this.distance),G.transformMat4(r,r,i),this.distance=E.dot(r,this.normal.array),B.invert(e,i),B.transpose(e,e),t[3]=0,E.copy(t,this.normal.array),G.transformMat4(t,t,e),E.copy(this.normal.array,t)}}(),copy:function(e){E.copy(this.normal.array,e.normal.array),this.normal._dirty=!0,this.distance=e.distance},clone:function(){var e=new Yi;return e.copy(this),e}};const Cs=Yi;var Le=E.set,yo=E.copy,xo=E.transformMat4,Un=Math.min,Gn=Math.max,Ls=function(){this.planes=[];for(var e=0;e<6;e++)this.planes.push(new Cs);this.boundingBox=new tt,this.vertices=[];for(var e=0;e<8;e++)this.vertices[e]=E.fromValues(0,0,0)};Ls.prototype={setFromProjection:function(e){var t=this.planes,r=e.array,i=r[0],n=r[1],a=r[2],o=r[3],s=r[4],l=r[5],h=r[6],u=r[7],f=r[8],d=r[9],c=r[10],v=r[11],p=r[12],m=r[13],g=r[14],x=r[15];Le(t[0].normal.array,o-i,u-s,v-f),t[0].distance=-(x-p),t[0].normalize(),Le(t[1].normal.array,o+i,u+s,v+f),t[1].distance=-(x+p),t[1].normalize(),Le(t[2].normal.array,o+n,u+l,v+d),t[2].distance=-(x+m),t[2].normalize(),Le(t[3].normal.array,o-n,u-l,v-d),t[3].distance=-(x-m),t[3].normalize(),Le(t[4].normal.array,o-a,u-h,v-c),t[4].distance=-(x-g),t[4].normalize(),Le(t[5].normal.array,o+a,u+h,v+c),t[5].distance=-(x+g),t[5].normalize();var y=this.boundingBox,_=this.vertices;if(x===0){var w=l/i,S=-g/(c-1),b=-g/(c+1),A=-b/l,C=-S/l;y.min.set(-A*w,-A,b),y.max.set(A*w,A,S),Le(_[0],-A*w,-A,b),Le(_[1],-A*w,A,b),Le(_[2],A*w,-A,b),Le(_[3],A*w,A,b),Le(_[4],-C*w,-C,S),Le(_[5],-C*w,C,S),Le(_[6],C*w,-C,S),Le(_[7],C*w,C,S)}else{var P=(-1-p)/i,L=(1-p)/i,R=(1-m)/l,I=(-1-m)/l,D=(-1-g)/c,O=(1-g)/c;y.min.set(Math.min(P,L),Math.min(I,R),Math.min(O,D)),y.max.set(Math.max(L,P),Math.max(R,I),Math.max(D,O));var z=y.min.array,V=y.max.array;Le(_[0],z[0],z[1],z[2]),Le(_[1],z[0],V[1],z[2]),Le(_[2],V[0],z[1],z[2]),Le(_[3],V[0],V[1],z[2]),Le(_[4],z[0],z[1],V[2]),Le(_[5],z[0],V[1],V[2]),Le(_[6],V[0],z[1],V[2]),Le(_[7],V[0],V[1],V[2])}},getTransformedBoundingBox:function(){var e=E.create();return function(t,r){var i=this.vertices,n=r.array,a=t.min,o=t.max,s=a.array,l=o.array,h=i[0];xo(e,h,n),yo(s,e),yo(l,e);for(var u=1;u<8;u++)h=i[u],xo(e,h,n),s[0]=Un(e[0],s[0]),s[1]=Un(e[1],s[1]),s[2]=Un(e[2],s[2]),l[0]=Gn(e[0],l[0]),l[1]=Gn(e[1],l[1]),l[2]=Gn(e[2],l[2]);return a._dirty=!0,o._dirty=!0,t}}()};const Ea=Ls;var iu=Lt.extend(function(){return{projectionMatrix:new k,invProjectionMatrix:new k,viewMatrix:new k,frustum:new Ea}},function(){this.update(!0)},{update:function(e){Lt.prototype.update.call(this,e),k.invert(this.viewMatrix,this.worldTransform),this.updateProjectionMatrix(),k.invert(this.invProjectionMatrix,this.projectionMatrix),this.frustum.setFromProjection(this.projectionMatrix)},setViewMatrix:function(e){k.copy(this.viewMatrix,e),k.invert(this.worldTransform,e),this.decomposeWorldTransform()},decomposeProjectionMatrix:function(){},setProjectionMatrix:function(e){k.copy(this.projectionMatrix,e),k.invert(this.invProjectionMatrix,e),this.decomposeProjectionMatrix()},updateProjectionMatrix:function(){},castRay:function(){var e=G.create();return function(t,r){var i=r!==void 0?r:new tn,n=t.array[0],a=t.array[1];return G.set(e,n,a,-1,1),G.transformMat4(e,e,this.invProjectionMatrix.array),G.transformMat4(e,e,this.worldTransform.array),E.scale(i.origin.array,e,1/e[3]),G.set(e,n,a,1,1),G.transformMat4(e,e,this.invProjectionMatrix.array),G.transformMat4(e,e,this.worldTransform.array),E.scale(e,e,1/e[3]),E.sub(i.direction.array,e,i.origin.array),E.normalize(i.direction.array,i.direction.array),i.direction._dirty=!0,i.origin._dirty=!0,i}}()});const Br=iu;var nu=B.create(),To=B.create(),zn={};function au(e){var t=[],r=Object.keys(e);r.sort();for(var i=0;i0&&console.warn("Found multiple camera in one scene. Use the fist one."),this._cameraList.push(e)):e instanceof wt&&this.lights.push(e),e.name&&(this._nodeRepository[e.name]=e)},removeFromScene:function(e){var t;e instanceof Br?(t=this._cameraList.indexOf(e),t>=0&&this._cameraList.splice(t,1)):e instanceof wt&&(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;r0&&this._doUpdateRenderList(o,t,r,i,n)}},isFrustumCulled:function(){var e=new tt,t=new k;return function(r,i,n){var a=r.boundingBox;if(a||(r.skeleton&&r.skeleton.boundingBox?a=r.skeleton.boundingBox:a=r.geometry.boundingBox),!a)return!1;if(t.array=n,e.transformFrom(a,t),r.castShadow&&this.viewBoundingBoxLastFrame.union(e),r.frustumCulling){if(!e.intersectBoundingBox(i.frustum.boundingBox))return!0;t.array=i.projectionMatrix.array,e.max.array[2]>0&&e.min.array[2]<0&&(e.max.array[2]=-1e-20),e.applyProjection(t);var o=e.min.array,s=e.max.array;if(s[0]<-1||o[0]>1||s[1]<-1||o[1]>1||s[2]<-1||o[2]>1)return!0}return!1}}(),_updateLightUniforms:function(){var e=this.lights;e.sort(su);var t=this._lightUniforms;for(var r in t)for(var i in t[r])t[r][i].value.length=0;for(var n=0;n1&&t.texParameterf(t.TEXTURE_CUBE_MAP,n.TEXTURE_MAX_ANISOTROPY_EXT,this.anisotropic),i===36193){var a=e.getGLExtension("OES_texture_half_float");a||(i=M.FLOAT)}if(this.mipmaps.length)for(var o=this.width,s=this.height,l=0;l0&&e.height>0}const vi=ba;var hu=Br.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=Br.prototype.clone.call(this);return e.fov=this.fov,e.aspect=this.aspect,e.near=this.near,e.far=this.far,e}});const He=hu;var Fi="framebuffer",It="renderbuffer",wo=It+"_width",So=It+"_height",Hn=It+"_attached",Vn="depthtexture_attached",tr=M.FRAMEBUFFER,ti=M.RENDERBUFFER,si=M.DEPTH_ATTACHMENT,Ms=M.COLOR_ATTACHMENT0,bi=nt.extend({depthBuffer:!0,viewport:null,_width:0,_height:0,_textures:null,_boundRenderer:null},function(){this._cache=new Sa,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(tr,this._getFrameBufferGL(e)),this._boundRenderer=e;var r=this._cache;r.put("viewport",e.viewport);var i=!1,n,a;for(var o in this._textures){i=!0;var s=this._textures[o];s&&(n=s.texture.width,a=s.texture.height,this._doAttach(e,s.texture,o,s.target))}this._width=n,this._height=a,!i&&this.depthBuffer&&console.error("Must attach texture before bind, or renderbuffer may have incorrect width and height."),this.viewport?e.setViewport(this.viewport):e.setViewport(0,0,n,a,1);var l=r.get("attached_textures");if(l){for(var o in l)if(!this._textures[o]){var h=l[o];this._doDetach(t,o,h)}}if(!r.get(Vn)&&this.depthBuffer){r.miss(It)&&r.put(It,t.createRenderbuffer());var u=r.get(It);(n!==r.get(wo)||a!==r.get(So))&&(t.bindRenderbuffer(ti,u),t.renderbufferStorage(ti,t.DEPTH_COMPONENT16,n,a),r.put(wo,n),r.put(So,a),t.bindRenderbuffer(ti,null)),r.get(Hn)||(t.framebufferRenderbuffer(tr,si,ti,u),r.put(Hn,!0))}},unbind:function(e){e.__currentFrameBuffer=null;var t=e.gl;t.bindFramebuffer(tr,null),this._boundRenderer=null,this._cache.use(e.__uid__);var r=this._cache.get("viewport");r&&e.setViewport(r),this.updateMipmap(e)},updateMipmap:function(e){var t=e.gl;for(var r in this._textures){var i=this._textures[r];if(i){var n=i.texture;if(!n.NPOT&&n.useMipmap&&n.minFilter===W.LINEAR_MIPMAP_LINEAR){var a=n.textureType==="textureCube"?M.TEXTURE_CUBE_MAP:M.TEXTURE_2D;t.bindTexture(a,n.getWebGLTexture(e)),t.generateMipmap(a),t.bindTexture(a,null)}}}},checkStatus:function(e){return e.checkFramebufferStatus(tr)},_getFrameBufferGL:function(e){var t=this._cache;return t.use(e.__uid__),t.miss(Fi)&&t.put(Fi,e.gl.createFramebuffer()),t.get(Fi)},attach:function(e,t,r){if(!e.width)throw new Error("The texture attached to color buffer is not a valid.");t=t||Ms,r=r||M.TEXTURE_2D;var i=this._boundRenderer,n=i&&i.gl,a;if(n){var o=this._cache;o.use(i.__uid__),a=o.get("attached_textures")}var s=this._textures[t];if(!(s&&s.target===r&&s.texture===e&&a&&a[t]!=null)){var l=!0;i&&(l=this._doAttach(i,e,t,r),this.viewport||i.setViewport(0,0,e.width,e.height,1)),l&&(this._textures[t]=this._textures[t]||{},this._textures[t].texture=e,this._textures[t].target=r)}},_doAttach:function(e,t,r,i){var n=e.gl,a=t.getWebGLTexture(e),o=this._cache.get("attached_textures");if(o&&o[r]){var s=o[r];if(s.texture===t&&s.target===i)return}r=+r;var l=!0;if(r===si||r===M.DEPTH_STENCIL_ATTACHMENT){var h=e.getGLExtension("WEBGL_depth_texture");if(h||(console.error("Depth texture is not supported by the browser"),l=!1),t.format!==M.DEPTH_COMPONENT&&t.format!==M.DEPTH_STENCIL&&(console.error("The texture attached to depth buffer is not a valid."),l=!1),l){var u=this._cache.get(It);u&&(n.framebufferRenderbuffer(tr,si,ti,null),n.deleteRenderbuffer(u),this._cache.put(It,!1)),this._cache.put(Hn,!1),this._cache.put(Vn,!0)}}return n.framebufferTexture2D(tr,r,i,a,0),o||(o={},this._cache.put("attached_textures",o)),o[r]=o[r]||{},o[r].texture=t,o[r].target=i,l},_doDetach:function(e,t,r){e.framebufferTexture2D(tr,t,r,null,0);var i=this._cache.get("attached_textures");i&&i[t]&&(i[t]=null),(t===si||t===M.DEPTH_STENCIL_ATTACHMENT)&&this._cache.put(Vn,!1)},detach:function(e,t){if(this._textures[e]=null,this._boundRenderer){var r=this._cache;r.use(this._boundRenderer.__uid__),this._doDetach(this._boundRenderer.gl,e,t)}},dispose:function(e){var t=e.gl,r=this._cache;r.use(e.__uid__);var i=r.get(It);i&&t.deleteRenderbuffer(i);var n=r.get(Fi);n&&t.deleteFramebuffer(n),r.deleteContext(e.__uid__),this._textures={}}});bi.DEPTH_ATTACHMENT=si;bi.COLOR_ATTACHMENT0=Ms;bi.STENCIL_ATTACHMENT=M.STENCIL_ATTACHMENT;bi.DEPTH_STENCIL_ATTACHMENT=M.DEPTH_STENCIL_ATTACHMENT;const qe=bi;var uu=["px","nx","py","ny","pz","nz"],fu=nt.extend(function(){var e={position:new U,far:1e3,near:.1,texture:null,shadowMapPass:null},t=e._cameras={px:new He({fov:90}),nx:new He({fov:90}),py:new He({fov:90}),ny:new He({fov:90}),pz:new He({fov:90}),nz:new He({fov:90})};return t.px.lookAt(U.POSITIVE_X,U.NEGATIVE_Y),t.nx.lookAt(U.NEGATIVE_X,U.NEGATIVE_Y),t.py.lookAt(U.POSITIVE_Y,U.POSITIVE_Z),t.ny.lookAt(U.NEGATIVE_Y,U.NEGATIVE_Z),t.pz.lookAt(U.POSITIVE_Z,U.NEGATIVE_Y),t.nz.lookAt(U.NEGATIVE_Z,U.NEGATIVE_Y),e._frameBuffer=new qe,e},{getCamera:function(e){return this._cameras[e]},render:function(e,t,r){var i=e.gl;r||t.update();for(var n=this.texture.width,a=2*Math.atan(n/(n-.5))/Math.PI*180,o=0;o<6;o++){var s=uu[o],l=this._cameras[s];if(U.copy(l.position,this.position),l.far=this.far,l.near=this.near,l.fov=a,this.shadowMapPass){l.update();var h=t.getBoundingBox();h.applyTransform(l.viewMatrix),t.viewBoundingBoxLastFrame.copy(h),this.shadowMapPass.render(e,t,l,!0)}this._frameBuffer.attach(this.texture,i.COLOR_ATTACHMENT0,i.TEXTURE_CUBE_MAP_POSITIVE_X+o),this._frameBuffer.bind(e),e.render(t,l,!0),this._frameBuffer.unbind(e)}},dispose:function(e){this._frameBuffer.dispose(e)}});const Ca=fu;var cu=oe.extend({dynamic:!1,widthSegments:1,heightSegments:1},function(){this.build()},{build:function(){for(var e=this.heightSegments,t=this.widthSegments,r=this.attributes,i=[],n=[],a=[],o=[],s=0;s<=e;s++)for(var l=s/e,h=0;h<=t;h++){var u=h/t;if(i.push([2*u-1,2*l-1,0]),n&&n.push([u,l]),a&&a.push([0,0,1]),h0?this.material.define("fragment","LOD"):this.material.undefine("fragment","LOD"),e.renderPass([this],r)}});const pi=pu;var mu=542327876,gu=131072,_u=512,yu=4;function La(e){return e.charCodeAt(0)+(e.charCodeAt(1)<<8)+(e.charCodeAt(2)<<16)+(e.charCodeAt(3)<<24)}var xu=31,Tu=La("DXT1"),wu=La("DXT3"),Su=La("DXT5"),Au=0,Eu=1,bu=2,Cu=3,Lu=4,Mu=7,Du=20,Pu=21,Ru=28,Nu={parse:function(e,t){var r=new Int32Array(e,0,xu);if(r[Au]!==mu||!r(Du)&yu)return null;var i=r(Pu),n=r[Lu],a=r[Cu],o=r[Ru]&_u,s=r[bu]&gu,l,h;switch(i){case Tu:l=8,h=W.COMPRESSED_RGB_S3TC_DXT1_EXT;break;case wu:l=16,h=W.COMPRESSED_RGBA_S3TC_DXT3_EXT;break;case Su:l=16,h=W.COMPRESSED_RGBA_S3TC_DXT5_EXT;break;default:return null}var u=r[Eu]+4,f=o?6:1,d=1;s&&(d=Math.max(1,r[Mu]));for(var c=[],v=0;v0){var n=Math.pow(2,e[3]-128-8+i);t[r+0]=e[0]*n,t[r+1]=e[1]*n,t[r+2]=e[2]*n}else t[r+0]=0,t[r+1]=0,t[r+2]=0;return t[r+3]=1,t}function Uu(e,t,r){for(var i="",n=t;n0;)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 s=e[a][3]<>>0;s>0;s--)Gu(e[a-1],e[a]),a++,o--;n+=8}else a++,o--,n=0;return r}function zu(e,t,r,i){if(iBu)return Ao(e,t,r,i);var n=t[r++];if(n!=2)return Ao(e,t,r-1,i);if(e[0][1]=t[r++],e[0][2]=t[r++],n=t[r++],(e[0][2]<<8>>>0|n)>>>0!==i)return null;for(var n=0;n<4;n++)for(var a=0;a128){o=(o&127)>>>0;for(var s=t[r++];o--;)e[a++][n]=s}else for(;o--;)e[a++][n]=t[r++]}return r}var Hu={parseRGBE:function(e,t,r){r==null&&(r=0);var i=new Uint8Array(e),n=i.length;if(Uu(i,0,2)==="#?"){for(var a=2;a=n)){a+=2;for(var o="";a20)return console.warn("Given image is not a height map"),e}var c,v,p,m;l%(i*4)===0?(c=o.data[l],p=o.data[l+4]):l%(i*4)===(i-1)*4?(c=o.data[l-4],p=o.data[l]):(c=o.data[l-4],p=o.data[l+4]),li*(n-1)*4?(v=o.data[l-i*4],m=o.data[l]):(v=o.data[l-i*4],m=o.data[l+i*4]),s.data[l]=c-p+127,s.data[l+1]=v-m+127,s.data[l+2]=255,s.data[l+3]=255}return a.putImageData(s,0,0),r},isHeightImage:function(e,t,r){if(!e||!e.width||!e.height)return!1;var i=document.createElement("canvas"),n=i.getContext("2d"),a=t||32;r=r||20,i.width=i.height=a,n.drawImage(e,0,0,a,a);for(var o=n.getImageData(0,0,a,a),s=0;sr)return!1}return!0},_fetchTexture:function(e,t,r){Pe.request.get({url:e,responseType:"arraybuffer",onload:t,onerror:r})},createChessboard:function(e,t,r,i){e=e||512,t=t||64,r=r||"black",i=i||"white";var n=Math.ceil(e/t),a=document.createElement("canvas");a.width=e,a.height=e;var o=a.getContext("2d");o.fillStyle=i,o.fillRect(0,0,e,e),o.fillStyle=r;for(var s=0;s=0||(sa.forEach(function(t){e.on(t,this[la(t)],this)},this),this._meshes.push(e))},detachFromMesh:function(e){var t=this._meshes.indexOf(e);t>=0&&this._meshes.splice(t,1),sa.forEach(function(r){e.off(r,this[la(r)])},this)},dispose:function(){this._meshes.forEach(function(e){this.detachFromMesh(e)},this)}};const ku=ha;var Wu=Br.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=Br.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 Fr=Wu,Xu=` @export clay.compositor.vertex uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; attribute vec3 position : POSITION; attribute vec2 texcoord : TEXCOORD_0; varying vec2 v_Texcoord; void main() { v_Texcoord = texcoord; gl_Position = worldViewProjection * vec4(position, 1.0); } @end`;N.import(Xu);var Zu=new yn,Eo=new lr({geometry:Zu,frustumCulling:!1}),ju=new Fr,qu=nt.extend(function(){return{fragment:"",outputs:null,material:null,blendWithPrevious:!1,clearColor:!1,clearDepth:!0}},function(){var e=new N(N.source("clay.compositor.vertex"),this.fragment),t=new gt({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||M.COLOR_ATTACHMENT0,this.outputs[t]=e},detachOutput:function(e){for(var t in this.outputs)this.outputs[t]===e&&(this.outputs[t]=null)},bind:function(e,t){if(this.outputs)for(var r in this.outputs){var i=this.outputs[r];i&&t.attach(i,r)}t&&t.bind(e)},unbind:function(e,t){t.unbind(e)},render:function(e,t){var r=e.gl;if(t){this.bind(e,t);var i=e.getGLExtension("EXT_draw_buffers");if(i&&this.outputs){var n=[];for(var a in this.outputs)a=+a,a>=r.COLOR_ATTACHMENT0&&a<=r.COLOR_ATTACHMENT0+8&&n.push(a);i.drawBuffersEXT(n)}}this.trigger("beforerender",this,e);var o=this.clearDepth?r.DEPTH_BUFFER_BIT:0;if(r.depthMask(!0),this.clearColor){o=o|r.COLOR_BUFFER_BIT,r.colorMask(!0,!0,!0,!0);var s=this.clearColor;Array.isArray(s)&&r.clearColor(s[0],s[1],s[2],s[3])}r.clear(o),this.blendWithPrevious?(r.enable(r.BLEND),this.material.transparent=!0):(r.disable(r.BLEND),this.material.transparent=!1),this.renderQuad(e),this.trigger("afterrender",this,e),t&&this.unbind(e,t)},renderQuad:function(e){Eo.material=this.material,e.renderPass([Eo],ju)},dispose:function(e){}});const Re=qu,Yu=`#define SAMPLE_NUMBER 1024 #define PI 3.14159265358979 uniform sampler2D normalDistribution; uniform vec2 viewportSize : [512, 256]; const vec3 N = vec3(0.0, 0.0, 1.0); const float fSampleNumber = float(SAMPLE_NUMBER); vec3 importanceSampleNormal(float i, float roughness, vec3 N) { vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb; vec3 upVector = abs(N.y) > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0); vec3 tangentX = normalize(cross(N, upVector)); vec3 tangentZ = cross(N, tangentX); return normalize(tangentX * H.x + N * H.y + tangentZ * H.z); } float G_Smith(float roughness, float NoV, float NoL) { float k = roughness * roughness / 2.0; float G1V = NoV / (NoV * (1.0 - k) + k); float G1L = NoL / (NoL * (1.0 - k) + k); return G1L * G1V; } void main() { vec2 uv = gl_FragCoord.xy / viewportSize; float NoV = uv.x; float roughness = uv.y; vec3 V; V.x = sqrt(1.0 - NoV * NoV); V.y = 0.0; V.z = NoV; float A = 0.0; float B = 0.0; for (int i = 0; i < SAMPLE_NUMBER; i++) { vec3 H = importanceSampleNormal(float(i) / fSampleNumber, roughness, N); vec3 L = reflect(-V, H); float NoL = clamp(L.z, 0.0, 1.0); float NoH = clamp(H.z, 0.0, 1.0); float VoH = clamp(dot(V, H), 0.0, 1.0); if (NoL > 0.0) { float G = G_Smith(roughness, NoV, NoL); float G_Vis = G * VoH / (NoH * NoV); float Fc = pow(1.0 - VoH, 5.0); A += (1.0 - Fc) * G_Vis; B += Fc * G_Vis; } } gl_FragColor = vec4(vec2(A, B) / fSampleNumber, 0.0, 1.0); } `,Ku=`#define SHADER_NAME prefilter #define SAMPLE_NUMBER 1024 #define PI 3.14159265358979 uniform mat4 viewInverse : VIEWINVERSE; uniform samplerCube environmentMap; uniform sampler2D normalDistribution; uniform float roughness : 0.5; varying vec2 v_Texcoord; varying vec3 v_WorldPosition; @import clay.util.rgbm vec3 importanceSampleNormal(float i, float roughness, vec3 N) { vec3 H = texture2D(normalDistribution, vec2(roughness, i)).rgb; vec3 upVector = abs(N.y) > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0); vec3 tangentX = normalize(cross(N, upVector)); vec3 tangentZ = cross(N, tangentX); return normalize(tangentX * H.x + N * H.y + tangentZ * H.z); } void main() { vec3 eyePos = viewInverse[3].xyz; vec3 V = normalize(v_WorldPosition - eyePos); vec3 N = V; vec3 prefilteredColor = vec3(0.0); float totalWeight = 0.0; float fMaxSampleNumber = float(SAMPLE_NUMBER); for (int i = 0; i < SAMPLE_NUMBER; i++) { vec3 H = importanceSampleNormal(float(i) / fMaxSampleNumber, roughness, N); vec3 L = reflect(-V, H); float NoL = clamp(dot(N, L), 0.0, 1.0); if (NoL > 0.0) { prefilteredColor += decodeHDR(textureCube(environmentMap, L)).rgb * NoL; totalWeight += NoL; } } gl_FragColor = encodeHDR(vec4(prefilteredColor / totalWeight, 1.0)); } `;var cr={},kn=["px","nx","py","ny","pz","nz"];cr.prefilterEnvironmentMap=function(e,t,r,i,n){(!n||!i)&&(i=cr.generateNormalDistribution(),n=cr.integrateBRDF(e,i)),r=r||{};var a=r.width||64,o=r.height||64,s=r.type||t.type,l=new vi({width:a,height:o,type:s,flipY:!1,mipmaps:[]});l.isPowerOfTwo()||console.warn("Width and height must be power of two to enable mipmap.");var h=Math.min(a,o),u=Math.log(h)/Math.log(2)+1,f=new gt({shader:new N({vertex:N.source("clay.skybox.vertex"),fragment:Ku})});f.set("normalDistribution",i),r.encodeRGBM&&f.define("fragment","RGBM_ENCODE"),r.decodeRGBM&&f.define("fragment","RGBM_DECODE");var d=new Qt,c;if(t.textureType==="texture2D"){var v=new vi({width:a,height:o,type:s===W.FLOAT?W.HALF_FLOAT:s});fr.panoramaToCubeMap(e,t,v,{encodeRGBM:r.decodeRGBM}),t=v}c=new pi({scene:d,material:f}),c.material.set("environmentMap",t);var p=new Ca({texture:l});r.encodeRGBM&&(s=l.type=W.UNSIGNED_BYTE);for(var m=new $({width:a,height:o,type:s}),g=new qe({depthBuffer:!1}),x=Pe[s===W.UNSIGNED_BYTE?"Uint8Array":"Float32Array"],y=0;y>>16)>>>0;f=((f&1431655765)<<1|(f&2863311530)>>>1)>>>0,f=((f&858993459)<<2|(f&3435973836)>>>2)>>>0,f=((f&252645135)<<4|(f&4042322160)>>>4)>>>0,f=(((f&16711935)<<8|(f&4278255360)>>>8)>>>0)/4294967296;var d=Math.sqrt((1-f)/(1+(h*h-1)*f));o[u]=d}for(var u=0;u65535?Uint32Array:Uint16Array,s=this.indices=new o(t*e*6),l,h,u,f,d,c,v,y=this.radius,p=this.phiStart,m=this.phiLength,g=this.thetaStart,x=this.thetaLength,y=this.radius,_=[],w=[],S=0,b=1/y;for(v=0;v<=e;v++)for(c=0;c<=t;c++)f=c/t,d=v/e,l=-y*Math.cos(p+f*m)*Math.sin(g+d*x),h=y*Math.cos(g+d*x),u=y*Math.sin(p+f*m)*Math.sin(g+d*x),_[0]=l,_[1]=h,_[2]=u,w[0]=f,w[1]=d,r.set(S,_),i.set(S,w),_[0]*=b,_[1]*=b,_[2]*=b,n.set(S,_),S++;var A,C,P,L,R=t+1,I=0;for(v=0;v=0&&l.splice(f,1)}),l.push(h),this.__zr&&this.__zr.animation.addAnimator(h),h},stopAnimation:function(e){this._animators=this._animators||[];for(var t=this._animators,r=t.length,i=0;i 1e-4) { skinMatrixWS += getSkinMatrix(joint.y) * weight.y; } if (weight.z > 1e-4) { skinMatrixWS += getSkinMatrix(joint.z) * weight.z; } float weightW = 1.0-weight.x-weight.y-weight.z; if (weightW > 1e-4) { skinMatrixWS += getSkinMatrix(joint.w) * weightW; } @end @export clay.chunk.instancing_header #ifdef INSTANCING attribute vec4 instanceMat1; attribute vec4 instanceMat2; attribute vec4 instanceMat3; #endif @end @export clay.chunk.instancing_matrix mat4 instanceMat = mat4( vec4(instanceMat1.xyz, 0.0), vec4(instanceMat2.xyz, 0.0), vec4(instanceMat3.xyz, 0.0), vec4(instanceMat1.w, instanceMat2.w, instanceMat3.w, 1.0) ); @end @export clay.util.parallax_correct vec3 parallaxCorrect(in vec3 dir, in vec3 pos, in vec3 boxMin, in vec3 boxMax) { vec3 first = (boxMax - pos) / dir; vec3 second = (boxMin - pos) / dir; vec3 further = max(first, second); float dist = min(further.x, min(further.y, further.z)); vec3 fixedPos = pos + dir * dist; vec3 boxCenter = (boxMax + boxMin) * 0.5; return normalize(fixedPos - boxCenter); } @end @export clay.util.clamp_sample vec4 clampSample(const in sampler2D texture, const in vec2 coord) { #ifdef STEREO float eye = step(0.5, coord.x) * 0.5; vec2 coordClamped = clamp(coord, vec2(eye, 0.0), vec2(0.5 + eye, 1.0)); #else vec2 coordClamped = clamp(coord, vec2(0.0), vec2(1.0)); #endif return texture2D(texture, coordClamped); } @end @export clay.util.ACES vec3 ACESToneMapping(vec3 color) { const float A = 2.51; const float B = 0.03; const float C = 2.43; const float D = 0.59; const float E = 0.14; return (color * (A * color + B)) / (color * (C * color + D) + E); } @end`,Sf=` @export ecgl.common.transformUniforms uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; uniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE; uniform mat4 world : WORLD; @end @export ecgl.common.attributes attribute vec3 position : POSITION; attribute vec2 texcoord : TEXCOORD_0; attribute vec3 normal : NORMAL; @end @export ecgl.common.uv.header uniform vec2 uvRepeat : [1.0, 1.0]; uniform vec2 uvOffset : [0.0, 0.0]; uniform vec2 detailUvRepeat : [1.0, 1.0]; uniform vec2 detailUvOffset : [0.0, 0.0]; varying vec2 v_Texcoord; varying vec2 v_DetailTexcoord; @end @export ecgl.common.uv.main v_Texcoord = texcoord * uvRepeat + uvOffset; v_DetailTexcoord = texcoord * detailUvRepeat + detailUvOffset; @end @export ecgl.common.uv.fragmentHeader varying vec2 v_Texcoord; varying vec2 v_DetailTexcoord; @end @export ecgl.common.albedo.main vec4 albedoTexel = vec4(1.0); #ifdef DIFFUSEMAP_ENABLED albedoTexel = texture2D(diffuseMap, v_Texcoord); #ifdef SRGB_DECODE albedoTexel = sRGBToLinear(albedoTexel); #endif #endif #ifdef DETAILMAP_ENABLED vec4 detailTexel = texture2D(detailMap, v_DetailTexcoord); #ifdef SRGB_DECODE detailTexel = sRGBToLinear(detailTexel); #endif albedoTexel.rgb = mix(albedoTexel.rgb, detailTexel.rgb, detailTexel.a); albedoTexel.a = detailTexel.a + (1.0 - detailTexel.a) * albedoTexel.a; #endif @end @export ecgl.common.wireframe.vertexHeader #ifdef WIREFRAME_QUAD attribute vec4 barycentric; varying vec4 v_Barycentric; #elif defined(WIREFRAME_TRIANGLE) attribute vec3 barycentric; varying vec3 v_Barycentric; #endif @end @export ecgl.common.wireframe.vertexMain #if defined(WIREFRAME_QUAD) || defined(WIREFRAME_TRIANGLE) v_Barycentric = barycentric; #endif @end @export ecgl.common.wireframe.fragmentHeader uniform float wireframeLineWidth : 1; uniform vec4 wireframeLineColor: [0, 0, 0, 0.5]; #ifdef WIREFRAME_QUAD varying vec4 v_Barycentric; float edgeFactor () { vec4 d = fwidth(v_Barycentric); vec4 a4 = smoothstep(vec4(0.0), d * wireframeLineWidth, v_Barycentric); return min(min(min(a4.x, a4.y), a4.z), a4.w); } #elif defined(WIREFRAME_TRIANGLE) varying vec3 v_Barycentric; float edgeFactor () { vec3 d = fwidth(v_Barycentric); vec3 a3 = smoothstep(vec3(0.0), d * wireframeLineWidth, v_Barycentric); return min(min(a3.x, a3.y), a3.z); } #endif @end @export ecgl.common.wireframe.fragmentMain #if defined(WIREFRAME_QUAD) || defined(WIREFRAME_TRIANGLE) if (wireframeLineWidth > 0.) { vec4 lineColor = wireframeLineColor; #ifdef SRGB_DECODE lineColor = sRGBToLinear(lineColor); #endif gl_FragColor.rgb = mix(gl_FragColor.rgb, lineColor.rgb, (1.0 - edgeFactor()) * lineColor.a); } #endif @end @export ecgl.common.bumpMap.header #ifdef BUMPMAP_ENABLED uniform sampler2D bumpMap; uniform float bumpScale : 1.0; vec3 bumpNormal(vec3 surfPos, vec3 surfNormal, vec3 baseNormal) { vec2 dSTdx = dFdx(v_Texcoord); vec2 dSTdy = dFdy(v_Texcoord); float Hll = bumpScale * texture2D(bumpMap, v_Texcoord).x; float dHx = bumpScale * texture2D(bumpMap, v_Texcoord + dSTdx).x - Hll; float dHy = bumpScale * texture2D(bumpMap, v_Texcoord + dSTdy).x - Hll; vec3 vSigmaX = dFdx(surfPos); vec3 vSigmaY = dFdy(surfPos); vec3 vN = surfNormal; vec3 R1 = cross(vSigmaY, vN); vec3 R2 = cross(vN, vSigmaX); float fDet = dot(vSigmaX, R1); vec3 vGrad = sign(fDet) * (dHx * R1 + dHy * R2); return normalize(abs(fDet) * baseNormal - vGrad); } #endif @end @export ecgl.common.normalMap.vertexHeader #ifdef NORMALMAP_ENABLED attribute vec4 tangent : TANGENT; varying vec3 v_Tangent; varying vec3 v_Bitangent; #endif @end @export ecgl.common.normalMap.vertexMain #ifdef NORMALMAP_ENABLED if (dot(tangent, tangent) > 0.0) { v_Tangent = normalize((worldInverseTranspose * vec4(tangent.xyz, 0.0)).xyz); v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w); } #endif @end @export ecgl.common.normalMap.fragmentHeader #ifdef NORMALMAP_ENABLED uniform sampler2D normalMap; varying vec3 v_Tangent; varying vec3 v_Bitangent; #endif @end @export ecgl.common.normalMap.fragmentMain #ifdef NORMALMAP_ENABLED if (dot(v_Tangent, v_Tangent) > 0.0) { vec3 normalTexel = texture2D(normalMap, v_DetailTexcoord).xyz; if (dot(normalTexel, normalTexel) > 0.0) { N = normalTexel * 2.0 - 1.0; mat3 tbn = mat3(v_Tangent, v_Bitangent, v_Normal); N = normalize(tbn * N); } } #endif @end @export ecgl.common.vertexAnimation.header #ifdef VERTEX_ANIMATION attribute vec3 prevPosition; attribute vec3 prevNormal; uniform float percent; #endif @end @export ecgl.common.vertexAnimation.main #ifdef VERTEX_ANIMATION vec3 pos = mix(prevPosition, position, percent); vec3 norm = mix(prevNormal, normal, percent); #else vec3 pos = position; vec3 norm = normal; #endif @end @export ecgl.common.ssaoMap.header #ifdef SSAOMAP_ENABLED uniform sampler2D ssaoMap; uniform vec4 viewport : VIEWPORT; #endif @end @export ecgl.common.ssaoMap.main float ao = 1.0; #ifdef SSAOMAP_ENABLED ao = texture2D(ssaoMap, (gl_FragCoord.xy - viewport.xy) / viewport.zw).r; #endif @end @export ecgl.common.diffuseLayer.header #if (LAYER_DIFFUSEMAP_COUNT > 0) uniform float layerDiffuseIntensity[LAYER_DIFFUSEMAP_COUNT]; uniform sampler2D layerDiffuseMap[LAYER_DIFFUSEMAP_COUNT]; #endif @end @export ecgl.common.emissiveLayer.header #if (LAYER_EMISSIVEMAP_COUNT > 0) uniform float layerEmissionIntensity[LAYER_EMISSIVEMAP_COUNT]; uniform sampler2D layerEmissiveMap[LAYER_EMISSIVEMAP_COUNT]; #endif @end @export ecgl.common.layers.header @import ecgl.common.diffuseLayer.header @import ecgl.common.emissiveLayer.header @end @export ecgl.common.diffuseLayer.main #if (LAYER_DIFFUSEMAP_COUNT > 0) for (int _idx_ = 0; _idx_ < LAYER_DIFFUSEMAP_COUNT; _idx_++) {{ float intensity = layerDiffuseIntensity[_idx_]; vec4 texel2 = texture2D(layerDiffuseMap[_idx_], v_Texcoord); #ifdef SRGB_DECODE texel2 = sRGBToLinear(texel2); #endif albedoTexel.rgb = mix(albedoTexel.rgb, texel2.rgb * intensity, texel2.a); albedoTexel.a = texel2.a + (1.0 - texel2.a) * albedoTexel.a; }} #endif @end @export ecgl.common.emissiveLayer.main #if (LAYER_EMISSIVEMAP_COUNT > 0) for (int _idx_ = 0; _idx_ < LAYER_EMISSIVEMAP_COUNT; _idx_++) {{ vec4 texel2 = texture2D(layerEmissiveMap[_idx_], v_Texcoord) * layerEmissionIntensity[_idx_]; #ifdef SRGB_DECODE texel2 = sRGBToLinear(texel2); #endif float intensity = layerEmissionIntensity[_idx_]; gl_FragColor.rgb += texel2.rgb * texel2.a * intensity; }} #endif @end `,Af=`@export ecgl.color.vertex uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; @import ecgl.common.uv.header attribute vec2 texcoord : TEXCOORD_0; attribute vec3 position: POSITION; @import ecgl.common.wireframe.vertexHeader #ifdef VERTEX_COLOR attribute vec4 a_Color : COLOR; varying vec4 v_Color; #endif #ifdef VERTEX_ANIMATION attribute vec3 prevPosition; uniform float percent : 1.0; #endif #ifdef ATMOSPHERE_ENABLED attribute vec3 normal: NORMAL; uniform mat4 worldInverseTranspose : WORLDINVERSETRANSPOSE; varying vec3 v_Normal; #endif void main() { #ifdef VERTEX_ANIMATION vec3 pos = mix(prevPosition, position, percent); #else vec3 pos = position; #endif gl_Position = worldViewProjection * vec4(pos, 1.0); @import ecgl.common.uv.main #ifdef VERTEX_COLOR v_Color = a_Color; #endif #ifdef ATMOSPHERE_ENABLED v_Normal = normalize((worldInverseTranspose * vec4(normal, 0.0)).xyz); #endif @import ecgl.common.wireframe.vertexMain } @end @export ecgl.color.fragment #define LAYER_DIFFUSEMAP_COUNT 0 #define LAYER_EMISSIVEMAP_COUNT 0 uniform sampler2D diffuseMap; uniform sampler2D detailMap; uniform vec4 color : [1.0, 1.0, 1.0, 1.0]; #ifdef ATMOSPHERE_ENABLED uniform mat4 viewTranspose: VIEWTRANSPOSE; uniform vec3 glowColor; uniform float glowPower; varying vec3 v_Normal; #endif #ifdef VERTEX_COLOR varying vec4 v_Color; #endif @import ecgl.common.layers.header @import ecgl.common.uv.fragmentHeader @import ecgl.common.wireframe.fragmentHeader @import clay.util.srgb void main() { #ifdef SRGB_DECODE gl_FragColor = sRGBToLinear(color); #else gl_FragColor = color; #endif #ifdef VERTEX_COLOR gl_FragColor *= v_Color; #endif @import ecgl.common.albedo.main @import ecgl.common.diffuseLayer.main gl_FragColor *= albedoTexel; #ifdef ATMOSPHERE_ENABLED float atmoIntensity = pow(1.0 - dot(v_Normal, (viewTranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowPower); gl_FragColor.rgb += glowColor * atmoIntensity; #endif @import ecgl.common.emissiveLayer.main @import ecgl.common.wireframe.fragmentMain } @end`,Ef=`/** * http: */ @export ecgl.lambert.vertex @import ecgl.common.transformUniforms @import ecgl.common.uv.header @import ecgl.common.attributes @import ecgl.common.wireframe.vertexHeader #ifdef VERTEX_COLOR attribute vec4 a_Color : COLOR; varying vec4 v_Color; #endif @import ecgl.common.vertexAnimation.header varying vec3 v_Normal; varying vec3 v_WorldPosition; void main() { @import ecgl.common.uv.main @import ecgl.common.vertexAnimation.main gl_Position = worldViewProjection * vec4(pos, 1.0); v_Normal = normalize((worldInverseTranspose * vec4(norm, 0.0)).xyz); v_WorldPosition = (world * vec4(pos, 1.0)).xyz; #ifdef VERTEX_COLOR v_Color = a_Color; #endif @import ecgl.common.wireframe.vertexMain } @end @export ecgl.lambert.fragment #define LAYER_DIFFUSEMAP_COUNT 0 #define LAYER_EMISSIVEMAP_COUNT 0 #define NORMAL_UP_AXIS 1 #define NORMAL_FRONT_AXIS 2 @import ecgl.common.uv.fragmentHeader varying vec3 v_Normal; varying vec3 v_WorldPosition; uniform sampler2D diffuseMap; uniform sampler2D detailMap; @import ecgl.common.layers.header uniform float emissionIntensity: 1.0; uniform vec4 color : [1.0, 1.0, 1.0, 1.0]; uniform mat4 viewInverse : VIEWINVERSE; #ifdef ATMOSPHERE_ENABLED uniform mat4 viewTranspose: VIEWTRANSPOSE; uniform vec3 glowColor; uniform float glowPower; #endif #ifdef AMBIENT_LIGHT_COUNT @import clay.header.ambient_light #endif #ifdef AMBIENT_SH_LIGHT_COUNT @import clay.header.ambient_sh_light #endif #ifdef DIRECTIONAL_LIGHT_COUNT @import clay.header.directional_light #endif #ifdef VERTEX_COLOR varying vec4 v_Color; #endif @import ecgl.common.ssaoMap.header @import ecgl.common.bumpMap.header @import clay.util.srgb @import ecgl.common.wireframe.fragmentHeader @import clay.plugin.compute_shadow_map void main() { #ifdef SRGB_DECODE gl_FragColor = sRGBToLinear(color); #else gl_FragColor = color; #endif #ifdef VERTEX_COLOR #ifdef SRGB_DECODE gl_FragColor *= sRGBToLinear(v_Color); #else gl_FragColor *= v_Color; #endif #endif @import ecgl.common.albedo.main @import ecgl.common.diffuseLayer.main gl_FragColor *= albedoTexel; vec3 N = v_Normal; #ifdef DOUBLE_SIDED vec3 eyePos = viewInverse[3].xyz; vec3 V = normalize(eyePos - v_WorldPosition); if (dot(N, V) < 0.0) { N = -N; } #endif float ambientFactor = 1.0; #ifdef BUMPMAP_ENABLED N = bumpNormal(v_WorldPosition, v_Normal, N); ambientFactor = dot(v_Normal, N); #endif vec3 N2 = vec3(N.x, N[NORMAL_UP_AXIS], N[NORMAL_FRONT_AXIS]); vec3 diffuseColor = vec3(0.0, 0.0, 0.0); @import ecgl.common.ssaoMap.main #ifdef AMBIENT_LIGHT_COUNT for(int i = 0; i < AMBIENT_LIGHT_COUNT; i++) { diffuseColor += ambientLightColor[i] * ambientFactor * ao; } #endif #ifdef AMBIENT_SH_LIGHT_COUNT for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++) {{ diffuseColor += calcAmbientSHLight(_idx_, N2) * ambientSHLightColor[_idx_] * ao; }} #endif #ifdef DIRECTIONAL_LIGHT_COUNT #if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT]; if(shadowEnabled) { computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir); } #endif for(int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++) { vec3 lightDirection = -directionalLightDirection[i]; vec3 lightColor = directionalLightColor[i]; float shadowContrib = 1.0; #if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) if (shadowEnabled) { shadowContrib = shadowContribsDir[i]; } #endif float ndl = dot(N, normalize(lightDirection)) * shadowContrib; diffuseColor += lightColor * clamp(ndl, 0.0, 1.0); } #endif gl_FragColor.rgb *= diffuseColor; #ifdef ATMOSPHERE_ENABLED float atmoIntensity = pow(1.0 - dot(v_Normal, (viewTranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowPower); gl_FragColor.rgb += glowColor * atmoIntensity; #endif @import ecgl.common.emissiveLayer.main @import ecgl.common.wireframe.fragmentMain } @end`,bf=`@export ecgl.realistic.vertex @import ecgl.common.transformUniforms @import ecgl.common.uv.header @import ecgl.common.attributes @import ecgl.common.wireframe.vertexHeader #ifdef VERTEX_COLOR attribute vec4 a_Color : COLOR; varying vec4 v_Color; #endif #ifdef NORMALMAP_ENABLED attribute vec4 tangent : TANGENT; varying vec3 v_Tangent; varying vec3 v_Bitangent; #endif @import ecgl.common.vertexAnimation.header varying vec3 v_Normal; varying vec3 v_WorldPosition; void main() { @import ecgl.common.uv.main @import ecgl.common.vertexAnimation.main gl_Position = worldViewProjection * vec4(pos, 1.0); v_Normal = normalize((worldInverseTranspose * vec4(norm, 0.0)).xyz); v_WorldPosition = (world * vec4(pos, 1.0)).xyz; #ifdef VERTEX_COLOR v_Color = a_Color; #endif #ifdef NORMALMAP_ENABLED v_Tangent = normalize((worldInverseTranspose * vec4(tangent.xyz, 0.0)).xyz); v_Bitangent = normalize(cross(v_Normal, v_Tangent) * tangent.w); #endif @import ecgl.common.wireframe.vertexMain } @end @export ecgl.realistic.fragment #define LAYER_DIFFUSEMAP_COUNT 0 #define LAYER_EMISSIVEMAP_COUNT 0 #define PI 3.14159265358979 #define ROUGHNESS_CHANEL 0 #define METALNESS_CHANEL 1 #define NORMAL_UP_AXIS 1 #define NORMAL_FRONT_AXIS 2 #ifdef VERTEX_COLOR varying vec4 v_Color; #endif @import ecgl.common.uv.fragmentHeader varying vec3 v_Normal; varying vec3 v_WorldPosition; uniform sampler2D diffuseMap; uniform sampler2D detailMap; uniform sampler2D metalnessMap; uniform sampler2D roughnessMap; @import ecgl.common.layers.header uniform float emissionIntensity: 1.0; uniform vec4 color : [1.0, 1.0, 1.0, 1.0]; uniform float metalness : 0.0; uniform float roughness : 0.5; uniform mat4 viewInverse : VIEWINVERSE; #ifdef ATMOSPHERE_ENABLED uniform mat4 viewTranspose: VIEWTRANSPOSE; uniform vec3 glowColor; uniform float glowPower; #endif #ifdef AMBIENT_LIGHT_COUNT @import clay.header.ambient_light #endif #ifdef AMBIENT_SH_LIGHT_COUNT @import clay.header.ambient_sh_light #endif #ifdef AMBIENT_CUBEMAP_LIGHT_COUNT @import clay.header.ambient_cubemap_light #endif #ifdef DIRECTIONAL_LIGHT_COUNT @import clay.header.directional_light #endif @import ecgl.common.normalMap.fragmentHeader @import ecgl.common.ssaoMap.header @import ecgl.common.bumpMap.header @import clay.util.srgb @import clay.util.rgbm @import ecgl.common.wireframe.fragmentHeader @import clay.plugin.compute_shadow_map vec3 F_Schlick(float ndv, vec3 spec) { return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0); } float D_Phong(float g, float ndh) { float a = pow(8192.0, g); return (a + 2.0) / 8.0 * pow(ndh, a); } void main() { vec4 albedoColor = color; vec3 eyePos = viewInverse[3].xyz; vec3 V = normalize(eyePos - v_WorldPosition); #ifdef VERTEX_COLOR #ifdef SRGB_DECODE albedoColor *= sRGBToLinear(v_Color); #else albedoColor *= v_Color; #endif #endif @import ecgl.common.albedo.main @import ecgl.common.diffuseLayer.main albedoColor *= albedoTexel; float m = metalness; #ifdef METALNESSMAP_ENABLED float m2 = texture2D(metalnessMap, v_DetailTexcoord)[METALNESS_CHANEL]; m = clamp(m2 + (m - 0.5) * 2.0, 0.0, 1.0); #endif vec3 baseColor = albedoColor.rgb; albedoColor.rgb = baseColor * (1.0 - m); vec3 specFactor = mix(vec3(0.04), baseColor, m); float g = 1.0 - roughness; #ifdef ROUGHNESSMAP_ENABLED float g2 = 1.0 - texture2D(roughnessMap, v_DetailTexcoord)[ROUGHNESS_CHANEL]; g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0); #endif vec3 N = v_Normal; #ifdef DOUBLE_SIDED if (dot(N, V) < 0.0) { N = -N; } #endif float ambientFactor = 1.0; #ifdef BUMPMAP_ENABLED N = bumpNormal(v_WorldPosition, v_Normal, N); ambientFactor = dot(v_Normal, N); #endif @import ecgl.common.normalMap.fragmentMain vec3 N2 = vec3(N.x, N[NORMAL_UP_AXIS], N[NORMAL_FRONT_AXIS]); vec3 diffuseTerm = vec3(0.0); vec3 specularTerm = vec3(0.0); float ndv = clamp(dot(N, V), 0.0, 1.0); vec3 fresnelTerm = F_Schlick(ndv, specFactor); @import ecgl.common.ssaoMap.main #ifdef AMBIENT_LIGHT_COUNT for(int _idx_ = 0; _idx_ < AMBIENT_LIGHT_COUNT; _idx_++) {{ diffuseTerm += ambientLightColor[_idx_] * ambientFactor * ao; }} #endif #ifdef AMBIENT_SH_LIGHT_COUNT for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++) {{ diffuseTerm += calcAmbientSHLight(_idx_, N2) * ambientSHLightColor[_idx_] * ao; }} #endif #ifdef DIRECTIONAL_LIGHT_COUNT #if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT]; if(shadowEnabled) { computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir); } #endif for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{ vec3 L = -directionalLightDirection[_idx_]; vec3 lc = directionalLightColor[_idx_]; vec3 H = normalize(L + V); float ndl = clamp(dot(N, normalize(L)), 0.0, 1.0); float ndh = clamp(dot(N, H), 0.0, 1.0); float shadowContrib = 1.0; #if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) if (shadowEnabled) { shadowContrib = shadowContribsDir[_idx_]; } #endif vec3 li = lc * ndl * shadowContrib; diffuseTerm += li; specularTerm += li * fresnelTerm * D_Phong(g, ndh); }} #endif #ifdef AMBIENT_CUBEMAP_LIGHT_COUNT vec3 L = reflect(-V, N); L = vec3(L.x, L[NORMAL_UP_AXIS], L[NORMAL_FRONT_AXIS]); float rough2 = clamp(1.0 - g, 0.0, 1.0); float bias2 = rough2 * 5.0; vec2 brdfParam2 = texture2D(ambientCubemapLightBRDFLookup[0], vec2(rough2, ndv)).xy; vec3 envWeight2 = specFactor * brdfParam2.x + brdfParam2.y; vec3 envTexel2; for(int _idx_ = 0; _idx_ < AMBIENT_CUBEMAP_LIGHT_COUNT; _idx_++) {{ envTexel2 = RGBMDecode(textureCubeLodEXT(ambientCubemapLightCubemap[_idx_], L, bias2), 8.12); specularTerm += ambientCubemapLightColor[_idx_] * envTexel2 * envWeight2 * ao; }} #endif gl_FragColor.rgb = albedoColor.rgb * diffuseTerm + specularTerm; gl_FragColor.a = albedoColor.a; #ifdef ATMOSPHERE_ENABLED float atmoIntensity = pow(1.0 - dot(v_Normal, (viewTranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowPower); gl_FragColor.rgb += glowColor * atmoIntensity; #endif #ifdef SRGB_ENCODE gl_FragColor = linearTosRGB(gl_FragColor); #endif @import ecgl.common.emissiveLayer.main @import ecgl.common.wireframe.fragmentMain } @end`,Cf=`@export ecgl.hatching.vertex @import ecgl.realistic.vertex @end @export ecgl.hatching.fragment #define NORMAL_UP_AXIS 1 #define NORMAL_FRONT_AXIS 2 @import ecgl.common.uv.fragmentHeader varying vec3 v_Normal; varying vec3 v_WorldPosition; uniform vec4 color : [0.0, 0.0, 0.0, 1.0]; uniform vec4 paperColor : [1.0, 1.0, 1.0, 1.0]; uniform mat4 viewInverse : VIEWINVERSE; #ifdef AMBIENT_LIGHT_COUNT @import clay.header.ambient_light #endif #ifdef AMBIENT_SH_LIGHT_COUNT @import clay.header.ambient_sh_light #endif #ifdef DIRECTIONAL_LIGHT_COUNT @import clay.header.directional_light #endif #ifdef VERTEX_COLOR varying vec4 v_Color; #endif @import ecgl.common.ssaoMap.header @import ecgl.common.bumpMap.header @import clay.util.srgb @import ecgl.common.wireframe.fragmentHeader @import clay.plugin.compute_shadow_map uniform sampler2D hatch1; uniform sampler2D hatch2; uniform sampler2D hatch3; uniform sampler2D hatch4; uniform sampler2D hatch5; uniform sampler2D hatch6; float shade(in float tone) { vec4 c = vec4(1. ,1., 1., 1.); float step = 1. / 6.; vec2 uv = v_DetailTexcoord; if (tone <= step / 2.0) { c = mix(vec4(0.), texture2D(hatch6, uv), 12. * tone); } else if (tone <= step) { c = mix(texture2D(hatch6, uv), texture2D(hatch5, uv), 6. * tone); } if(tone > step && tone <= 2. * step){ c = mix(texture2D(hatch5, uv), texture2D(hatch4, uv) , 6. * (tone - step)); } if(tone > 2. * step && tone <= 3. * step){ c = mix(texture2D(hatch4, uv), texture2D(hatch3, uv), 6. * (tone - 2. * step)); } if(tone > 3. * step && tone <= 4. * step){ c = mix(texture2D(hatch3, uv), texture2D(hatch2, uv), 6. * (tone - 3. * step)); } if(tone > 4. * step && tone <= 5. * step){ c = mix(texture2D(hatch2, uv), texture2D(hatch1, uv), 6. * (tone - 4. * step)); } if(tone > 5. * step){ c = mix(texture2D(hatch1, uv), vec4(1.), 6. * (tone - 5. * step)); } return c.r; } const vec3 w = vec3(0.2125, 0.7154, 0.0721); void main() { #ifdef SRGB_DECODE vec4 inkColor = sRGBToLinear(color); #else vec4 inkColor = color; #endif #ifdef VERTEX_COLOR #ifdef SRGB_DECODE inkColor *= sRGBToLinear(v_Color); #else inkColor *= v_Color; #endif #endif vec3 N = v_Normal; #ifdef DOUBLE_SIDED vec3 eyePos = viewInverse[3].xyz; vec3 V = normalize(eyePos - v_WorldPosition); if (dot(N, V) < 0.0) { N = -N; } #endif float tone = 0.0; float ambientFactor = 1.0; #ifdef BUMPMAP_ENABLED N = bumpNormal(v_WorldPosition, v_Normal, N); ambientFactor = dot(v_Normal, N); #endif vec3 N2 = vec3(N.x, N[NORMAL_UP_AXIS], N[NORMAL_FRONT_AXIS]); @import ecgl.common.ssaoMap.main #ifdef AMBIENT_LIGHT_COUNT for(int i = 0; i < AMBIENT_LIGHT_COUNT; i++) { tone += dot(ambientLightColor[i], w) * ambientFactor * ao; } #endif #ifdef AMBIENT_SH_LIGHT_COUNT for(int _idx_ = 0; _idx_ < AMBIENT_SH_LIGHT_COUNT; _idx_++) {{ tone += dot(calcAmbientSHLight(_idx_, N2) * ambientSHLightColor[_idx_], w) * ao; }} #endif #ifdef DIRECTIONAL_LIGHT_COUNT #if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) float shadowContribsDir[DIRECTIONAL_LIGHT_COUNT]; if(shadowEnabled) { computeShadowOfDirectionalLights(v_WorldPosition, shadowContribsDir); } #endif for(int i = 0; i < DIRECTIONAL_LIGHT_COUNT; i++) { vec3 lightDirection = -directionalLightDirection[i]; float lightTone = dot(directionalLightColor[i], w); float shadowContrib = 1.0; #if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) if (shadowEnabled) { shadowContrib = shadowContribsDir[i]; } #endif float ndl = dot(N, normalize(lightDirection)) * shadowContrib; tone += lightTone * clamp(ndl, 0.0, 1.0); } #endif gl_FragColor = mix(inkColor, paperColor, shade(clamp(tone, 0.0, 1.0))); } @end `,Lf=`@export ecgl.sm.depth.vertex uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; attribute vec3 position : POSITION; attribute vec2 texcoord : TEXCOORD_0; #ifdef VERTEX_ANIMATION attribute vec3 prevPosition; uniform float percent : 1.0; #endif varying vec4 v_ViewPosition; varying vec2 v_Texcoord; void main(){ #ifdef VERTEX_ANIMATION vec3 pos = mix(prevPosition, position, percent); #else vec3 pos = position; #endif v_ViewPosition = worldViewProjection * vec4(pos, 1.0); gl_Position = v_ViewPosition; v_Texcoord = texcoord; } @end @export ecgl.sm.depth.fragment @import clay.sm.depth.fragment @end`;Object.assign(Lt.prototype,wf);N.import(Rs);N.import(Ts);N.import(Sf);N.import(Af);N.import(Ef);N.import(bf);N.import(Cf);N.import(Lf);function Mf(e){return!e||e==="none"}function Ns(e){return e instanceof HTMLCanvasElement||e instanceof HTMLImageElement||e instanceof Image}function Df(e){return e.getZr&&e.setOption}var Pf=Qt.prototype.addToScene,Rf=Qt.prototype.removeFromScene;Qt.prototype.addToScene=function(e){if(Pf.call(this,e),this.__zr){var t=this.__zr;e.traverse(function(r){r.__zr=t,r.addAnimatorsToZr&&r.addAnimatorsToZr(t)})}};Qt.prototype.removeFromScene=function(e){Rf.call(this,e),e.traverse(function(t){var r=t.__zr;t.__zr=null,r&&t.removeAnimatorsFromZr&&t.removeAnimatorsFromZr(r)})};gt.prototype.setTextureImage=function(e,t,r,i){if(!!this.shader){var n=r.getZr(),a=this,o;return a.autoUpdateTextureStatus=!1,a.disableTexture(e),Mf(t)||(o=q.loadTexture(t,r,i,function(s){a.enableTexture(e),n&&n.refresh()}),a.set(e,o)),o}};var q={};q.Renderer=fi;q.Node=Lt;q.Mesh=lr;q.Shader=N;q.Material=gt;q.Texture=W;q.Texture2D=$;q.Geometry=oe;q.SphereGeometry=lf;q.PlaneGeometry=yn;q.CubeGeometry=Ds;q.AmbientLight=uf;q.DirectionalLight=cf;q.PointLight=vf;q.SpotLight=mf;q.PerspectiveCamera=He;q.OrthographicCamera=Fr;q.Vector2=ut;q.Vector3=U;q.Vector4=gf;q.Quaternion=ws;q.Matrix2=_f;q.Matrix2d=yf;q.Matrix3=xf;q.Matrix4=k;q.Plane=Cs;q.Ray=tn;q.BoundingBox=tt;q.Frustum=Ea;var Gi=null;function Nf(){return Gi!==null||(Gi=fr.createBlank("rgba(255,255,255,0)").image),Gi}function bo(e){return Math.pow(2,Math.round(Math.log(e)/Math.LN2))}function Co(e){if((e.wrapS===W.REPEAT||e.wrapT===W.REPEAT)&&e.image){var t=bo(e.width),r=bo(e.height);if(t!==e.width||r!==e.height){var i=document.createElement("canvas");i.width=t,i.height=r;var n=i.getContext("2d");n.drawImage(e.image,0,0,t,r),e.image=i}}}q.loadTexture=function(e,t,r,i){typeof r=="function"&&(i=r,r={}),r=r||{};for(var n=Object.keys(r).sort(),a="",o=0;o3?t[3]=e[3]:t[3]=1,t):(t=ss(e||"#000",t)||[0,0,0,0],t[0]/=255,t[1]/=255,t[2]/=255,t)};q.directionFromAlphaBeta=function(e,t){var r=e/180*Math.PI+Math.PI/2,i=-t/180*Math.PI+Math.PI/2,n=[],a=Math.sin(r);return n[0]=a*Math.cos(i),n[1]=-Math.cos(r),n[2]=a*Math.sin(i),n};q.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};q.COMMON_SHADERS=["lambert","color","realistic","hatching","shadow"];q.createShader=function(e){e==="ecgl.shadow"&&(e="ecgl.displayShadow");var t=N.source(e+".vertex"),r=N.source(e+".fragment");t||console.error("Vertex shader of '%s' not exits",e),r||console.error("Fragment shader of '%s' not exits",e);var i=new N(t,r);return i.name=e,i};q.createMaterial=function(e,t){t instanceof Array||(t=[t]);var r=q.createShader(e),i=new gt({shader:r});return t.forEach(function(n){typeof n=="string"&&i.define(n)}),i};q.setMaterialFromModel=function(e,t,r,i){t.autoUpdateTextureStatus=!1;var n=r.getModel(e+"Material"),a=n.get("detailTexture"),o=K.firstNotNull(n.get("textureTiling"),1),s=K.firstNotNull(n.get("textureOffset"),0);typeof o=="number"&&(o=[o,o]),typeof s=="number"&&(s=[s,s]);var l=o[0]>1||o[1]>1?q.Texture.REPEAT:q.Texture.CLAMP_TO_EDGE,h={anisotropic:8,wrapS:l,wrapT:l};if(e==="realistic"){var u=n.get("roughness"),f=n.get("metalness");f!=null?isNaN(f)&&(t.setTextureImage("metalnessMap",f,i,h),f=K.firstNotNull(n.get("metalnessAdjust"),.5)):f=0,u!=null?isNaN(u)&&(t.setTextureImage("roughnessMap",u,i,h),u=K.firstNotNull(n.get("roughnessAdjust"),.5)):u=.5;var d=n.get("normalTexture");t.setTextureImage("detailMap",a,i,h),t.setTextureImage("normalMap",d,i,h),t.set({roughness:u,metalness:f,detailUvRepeat:o,detailUvOffset:s})}else if(e==="lambert")t.setTextureImage("detailMap",a,i,h),t.set({detailUvRepeat:o,detailUvOffset:s});else if(e==="color")t.setTextureImage("detailMap",a,i,h),t.set({detailUvRepeat:o,detailUvOffset:s});else if(e==="hatching"){var c=n.get("hatchingTextures")||[];c.length<6&&console.error("Invalid hatchingTextures.");for(var v=0;v<6;v++)t.setTextureImage("hatch"+(v+1),c[v],i,{anisotropic:8,wrapS:q.Texture.REPEAT,wrapT:q.Texture.REPEAT});t.set({detailUvRepeat:o,detailUvOffset:s})}};q.updateVertexAnimation=function(e,t,r,i){var n=i.get("animation"),a=i.get("animationDurationUpdate"),o=i.get("animationEasingUpdate"),s=r.shadowDepthMaterial;if(n&&t&&a>0&&t.geometry.vertexCount===r.geometry.vertexCount){r.material.define("vertex","VERTEX_ANIMATION"),r.ignorePreZ=!0,s&&s.define("vertex","VERTEX_ANIMATION");for(var l=0;l=0&&this._viewsToDispose.splice(t,1),this.views.push(e),e.layer=this;var r=this.zr;e.scene.traverse(function(i){i.__zr=r,i.addAnimatorsToZr&&i.addAnimatorsToZr(r)})}};function Is(e){var t=e.__zr;e.__zr=null,t&&e.removeAnimatorsFromZr&&e.removeAnimatorsFromZr(t)}me.prototype.removeView=function(e){if(e.layer===this){var t=this.views.indexOf(e);t>=0&&(this.views.splice(t,1),e.scene.traverse(Is,this),e.layer=null,this._viewsToDispose.push(e))}};me.prototype.removeViewsAll=function(){this.views.forEach(function(e){e.scene.traverse(Is,this),e.layer=null,this._viewsToDispose.push(e)},this),this.views.length=0};me.prototype.resize=function(e,t){var r=this.renderer;r.resize(e,t)};me.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)};me.prototype.clearDepth=function(){var e=this.renderer.gl;e.clear(e.DEPTH_BUFFER_BIT)};me.prototype.clearColor=function(){var e=this.renderer.gl;e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)};me.prototype.needsRefresh=function(){this.zr.refresh()};me.prototype.refresh=function(e){this._backgroundColor=e?T.parseColor(e):[0,0,0,0],this.renderer.clearColor=this._backgroundColor;for(var t=0;t20)){e=e.event;var i=this.pickObject(e.offsetX,e.offsetY);i&&(this._dispatchEvent(e.type,e,i),this._dispatchDataEvent(e.type,e,i));var n=this._clickToSetFocusPoint(e);if(n){var a=n.view.setDOFFocusOnPoint(n.distance);a&&this.zr.refresh()}}}};me.prototype._clickToSetFocusPoint=function(e){for(var t=this.renderer,r=t.viewport,i=this.views.length-1;i>=0;i--){var n=this.views[i];if(n.hasDOF()&&n.containPoint(e.offsetX,e.offsetY)){this._picking.scene=n.scene,this._picking.camera=n.camera,t.viewport=n.viewport;var a=this._picking.pick(e.offsetX,e.offsetY,!0);if(a)return a.view=n,a}}t.viewport=r};me.prototype.onglobalout=function(e){var t=this._hovered;t&&this._dispatchEvent("mouseout",e,{target:t.target})};me.prototype.pickObject=function(e,t){for(var r=[],i=this.renderer,n=i.viewport,a=0;a=0&&(u.dataIndex=this._lastDataIndex,u.seriesIndex=this._lastSeriesIndex,this.zr.handler.dispatchToElement(h,"mouseout",t)),s=!0):o!=null&&o!==this._lastEventData&&(this._lastEventData!=null&&(u.eventData=this._lastEventData,this.zr.handler.dispatchToElement(h,"mouseout",t)),s=!0),this._lastEventData=o,this._lastDataIndex=n,this._lastSeriesIndex=a),u.eventData=o,u.dataIndex=n,u.seriesIndex=a,(o!=null||parseInt(n,10)>=0&&parseInt(a,10)>=0)&&(this.zr.handler.dispatchToElement(h,e,t),s&&this.zr.handler.dispatchToElement(h,"mouseover",t))};me.prototype._dispatchToView=function(e,t){for(var r=0;r=0&&(Ff(t),t.coordinateSystem==="mapbox"&&(t.coordinateSystem="mapbox3D",e.mapbox3D=e.mapbox))}),Hi(e.xAxis3D),Hi(e.yAxis3D),Hi(e.zAxis3D),Hi(e.grid3D),li(e.geo3D)}function Bs(e){this._layers={},this._zr=e}Bs.prototype.update=function(e,t){var r=this,i=t.getZr();if(!i.getWidth()||!i.getHeight()){console.warn("Dom has no width or height");return}function n(s){i.setSleepAfterStill(0);var l;s.coordinateSystem&&s.coordinateSystem.model,l=s.get("zlevel");var h=r._layers,u=h[l];if(!u){if(u=h[l]=new Os("gl-"+l,i),i.painter.isSingleCanvas()){u.virtual=!0;var f=new Yl({z:1e4,style:{image:u.renderer.canvas},silent:!0});u.__hostImage=f,i.add(f)}i.painter.insertLayer(l,u)}return u.__hostImage&&u.__hostImage.setStyle({width:u.renderer.getWidth(),height:u.renderer.getHeight()}),u}function a(s,l){s&&s.traverse(function(h){h.isRenderable&&h.isRenderable()&&(h.ignorePicking=h.$ignorePicking!=null?h.$ignorePicking:l)})}for(var o in this._layers)this._layers[o].removeViewsAll();e.eachComponent(function(s,l){if(s!=="series"){var h=t.getViewOfComponentModel(l),u=l.coordinateSystem;if(h.__ecgl__){var f;if(u){if(!u.viewGL){console.error("Can't find viewGL in coordinateSystem of component "+l.id);return}f=u.viewGL}else{if(!l.viewGL){console.error("Can't find viewGL of component "+l.id);return}f=u.viewGL}var f=u.viewGL,d=n(l);d.addView(f),h.afterRender&&h.afterRender(l,e,t,d),a(h.groupGL,l.get("silent"))}}}),e.eachSeries(function(s){var l=t.getViewOfSeriesModel(s),h=s.coordinateSystem;if(l.__ecgl__){if(h&&!h.viewGL&&!l.viewGL){console.error("Can't find viewGL of series "+l.id);return}var u=h&&h.viewGL||l.viewGL,f=n(s);f.addView(u),l.afterRender&&l.afterRender(s,e,t,f),a(l.groupGL,s.get("silent"))}})};Zl(function(e){var t=e.getZr(),r=t.painter.dispose;t.painter.dispose=function(){typeof this.eachOtherLayer=="function"&&this.eachOtherLayer(function(i){i instanceof Os&&i.dispose()}),r.call(this)},t.painter.getRenderedCanvas=function(i){if(i=i||{},this._singleCanvas)return this._layers[0].dom;var n=document.createElement("canvas"),a=i.pixelRatio||this.dpr;n.width=this.getWidth()*a,n.height=this.getHeight()*a;var o=n.getContext("2d");o.dpr=a,o.clearRect(0,0,n.width,n.height),i.backgroundColor&&(o.fillStyle=i.backgroundColor,o.fillRect(0,0,n.width,n.height));var s=this.storage.getDisplayList(!0),l={},h,u=this;function f(p,m){var g=u._zlevelList;p==null&&(p=-1/0);for(var x,y=0;yp&&_0&&this._notFirst?this.animateTo({alpha:h,beta:u,center:f,distance:a,orthographicSize:o,easing:l.animationEasingUpdate,duration:l.animationDurationUpdate}):(this.setDistance(a),this.setAlpha(h),this.setBeta(u),this.setCenter(f),this.setOrthographicSize(o)),this._notFirst=!0,this._validateProperties()},_validateProperties:function(){Vi[this.panMouseButton]==null&&console.error("Unkown panMouseButton %s. It should be left|middle|right",this.panMouseButton),Vi[this.rotateMouseButton]==null&&console.error("Unkown rotateMouseButton %s. It should be left|middle|right",this.rotateMouseButton),this.autoRotateDirection!=="cw"&&this.autoRotateDirection!=="ccw"&&console.error("Unkown autoRotateDirection %s. It should be cw|ccw",this.autoRotateDirection)},animateTo:function(e){var t=this.zr,r=this,i={},n={};return e.distance!=null&&(i.distance=this.getDistance(),n.distance=e.distance),e.orthographicSize!=null&&(i.orthographicSize=this.getOrthographicSize(),n.orthographicSize=e.orthographicSize),e.alpha!=null&&(i.alpha=this.getAlpha(),n.alpha=e.alpha),e.beta!=null&&(i.beta=this.getBeta(),n.beta=e.beta),e.center!=null&&(i.center=this.getCenter(),n.center=e.center),this._addAnimator(t.animation.animate(i).when(e.duration||1e3,n).during(function(){i.alpha!=null&&r.setAlpha(i.alpha),i.beta!=null&&r.setBeta(i.beta),i.distance!=null&&r.setDistance(i.distance),i.center!=null&&r.setCenter(i.center),i.orthographicSize!=null&&r.setOrthographicSize(i.orthographicSize),r._needsUpdate=!0})).start(e.easing||"linear")},stopAllAnimation:function(){for(var e=0;e0},_update:function(e){if(this._rotating){var t=(this.autoRotateDirection==="cw"?1:-1)*this.autoRotateSpeed/180*Math.PI;this._phi-=t*e/1e3,this._needsUpdate=!0}else this._rotateVelocity.len()>0&&(this._needsUpdate=!0);(Math.abs(this._zoomSpeed)>.1||this._panVelocity.len()>0)&&(this._needsUpdate=!0),this._needsUpdate&&(e=Math.min(e,50),this._updateDistanceOrSize(e),this._updatePan(e),this._updateRotate(e),this._updateTransform(),this.getCamera().update(),this.zr&&this.zr.refresh(),this.trigger("update"),this._needsUpdate=!1)},_updateRotate:function(e){var t=this._rotateVelocity;this._phi=t.y*e/20+this._phi,this._theta=t.x*e/20+this._theta,this.setAlpha(this.getAlpha()),this.setBeta(this.getBeta()),this._vectorDamping(t,Math.pow(this.damping,e/16))},_updateDistanceOrSize:function(e){this._projection==="perspective"?this._setDistance(this._distance+this._zoomSpeed*e/20):this._setOrthoSize(this._orthoSize+this._zoomSpeed*e/20),this._zoomSpeed*=Math.pow(this.damping,e/16)},_setDistance:function(e){this._distance=Math.max(Math.min(e,this.maxDistance),this.minDistance)},_setOrthoSize:function(e){this._orthoSize=Math.max(Math.min(e,this.maxOrthographicSize),this.minOrthographicSize);var t=this.getCamera(),r=this._orthoSize,i=r/this.viewGL.viewport.height*this.viewGL.viewport.width;t.left=-i/2,t.right=i/2,t.top=r/2,t.bottom=-r/2},_updatePan:function(e){var t=this._panVelocity,r=this._distance,i=this.getCamera(),n=i.worldTransform.y,a=i.worldTransform.x;this._center.scaleAndAdd(a,-t.x*r/200).scaleAndAdd(n,-t.y*r/200),this._vectorDamping(t,0)},_updateTransform:function(){var e=this.getCamera(),t=new U,r=this._theta+Math.PI/2,i=this._phi+Math.PI/2,n=Math.sin(r);t.x=n*Math.cos(i),t.y=-Math.cos(r),t.z=n*Math.sin(i),e.position.copy(this._center).scaleAndAdd(t,this._distance),e.rotation.identity().rotateY(-this._phi).rotateX(-this._theta)},_startCountingStill:function(){clearTimeout(this._stillTimeout);var e=this.autoRotateAfterStill,t=this;!isNaN(e)&&e>0&&(this._stillTimeout=setTimeout(function(){t._rotating=!0},e*1e3))},_vectorDamping:function(e,t){var r=e.len();r=r*t,r<1e-4&&(r=0),e.normalize().scale(r)},_decomposeTransform:function(){if(!!this.getCamera()){this.getCamera().updateWorldTransform();var e=this.getCamera().worldTransform.z,t=Math.asin(e.y),r=Math.atan2(e.x,e.z);this._theta=t,this._phi=-r,this.setBeta(this.getBeta()),this.setAlpha(this.getAlpha()),this.getCamera().aspect?this._setDistance(this.getCamera().position.dist(this._center)):this._setOrthoSize(this.getCamera().top-this.getCamera().bottom)}},_mouseDownHandler:function(e){if(!e.target&&!this._isAnimating()){var t=e.offsetX,r=e.offsetY;this.viewGL&&!this.viewGL.containPoint(t,r)||(this.zr.on("mousemove",this._mouseMoveHandler),this.zr.on("mouseup",this._mouseUpHandler),e.event.targetTouches?e.event.targetTouches.length===1&&(this._mode="rotate"):e.event.button===Vi[this.rotateMouseButton]?this._mode="rotate":e.event.button===Vi[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=Lo(this.panSensitivity),r=Lo(this.rotateSensitivity);this._mode==="rotate"?(this._rotateVelocity.y=(e.offsetX-this._mouseX)/this.zr.getHeight()*2*r[0],this._rotateVelocity.x=(e.offsetY-this._mouseY)/this.zr.getWidth()*2*r[1]):this._mode==="pan"&&(this._panVelocity.x=(e.offsetX-this._mouseX)/this.zr.getWidth()*t[0]*400,this._panVelocity.y=(-e.offsetY+this._mouseY)/this.zr.getHeight()*t[1]*400),this._mouseX=e.offsetX,this._mouseY=e.offsetY,e.event.preventDefault()}},_mouseWheelHandler:function(e){if(!this._isAnimating()){var t=e.event.wheelDelta||-e.event.detail;this._zoomHandler(e,t)}},_pinchHandler:function(e){this._isAnimating()||(this._zoomHandler(e,e.pinchScale>1?1:-1),this._mode="")},_zoomHandler:function(e,t){if(t!==0){var r=e.offsetX,i=e.offsetY;if(!(this.viewGL&&!this.viewGL.containPoint(r,i))){var n;this._projection==="perspective"?n=Math.max(Math.max(Math.min(this._distance-this.minDistance,this.maxDistance-this._distance))/20,.5):n=Math.max(Math.max(Math.min(this._orthoSize-this.minOrthographicSize,this.maxOrthographicSize-this._orthoSize))/20,.5),this._zoomSpeed=(t>0?-1:1)*n*this.zoomSensitivity,this._rotating=!1,this.autoRotate&&this._mode==="rotate"&&this._startCountingStill(),e.event.preventDefault()}}},_mouseUpHandler:function(){this.zr.off("mousemove",this._mouseMoveHandler),this.zr.off("mouseup",this._mouseUpHandler)},_isRightMouseButtonUsed:function(){return this.rotateMouseButton==="right"||this.panMouseButton==="right"},_contextMenuHandler:function(e){this._isRightMouseButtonUsed()&&e.preventDefault()},_addAnimator:function(e){var t=this._animators;return t.push(e),e.done(function(){var r=t.indexOf(e);r>=0&&t.splice(r,1)}),e}});Object.defineProperty(Fs.prototype,"autoRotate",{get:function(e){return this._autoRotate},set:function(e){this._autoRotate=e,this._rotating=e}});const wn=Fs,Ci={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()}},Me={vec2:X,vec3:E,vec4:G,mat2:be,mat2d:De,mat3:ie,mat4:B,quat:Y};var Wn=Me.vec3,Mo=[[0,0],[1,1]],Us=oe.extend(function(){return{segmentScale:1,dynamic:!0,useNativeLine:!0,attributes:{position:new oe.Attribute("position","float",3,"POSITION"),positionPrev:new oe.Attribute("positionPrev","float",3),positionNext:new oe.Attribute("positionNext","float",3),prevPositionPrev:new oe.Attribute("prevPositionPrev","float",3),prevPosition:new oe.Attribute("prevPosition","float",3),prevPositionNext:new oe.Attribute("prevPositionNext","float",3),offset:new oe.Attribute("offset","float",1),color:new oe.Attribute("color","float",4,"COLOR")}}},{resetOffset:function(){this._vertexOffset=0,this._triangleOffset=0,this._itemVertexOffsets=[]},setVertexCount:function(e){var t=this.attributes;this.vertexCount!==e&&(t.position.init(e),t.color.init(e),this.useNativeLine||(t.positionPrev.init(e),t.positionNext.init(e),t.offset.init(e)),e>65535?this.indices instanceof Uint16Array&&(this.indices=new Uint32Array(this.indices)):this.indices instanceof Uint32Array&&(this.indices=new Uint16Array(this.indices)))},setTriangleCount:function(e){this.triangleCount!==e&&(e===0?this.indices=null:this.indices=this.vertexCount>65535?new Uint32Array(e*3):new Uint16Array(e*3))},_getCubicCurveApproxStep:function(e,t,r,i){var n=Wn.dist(e,t)+Wn.dist(r,t)+Wn.dist(i,r),a=1/(n+1)*this.segmentScale;return a},getCubicCurveVertexCount:function(e,t,r,i){var n=this._getCubicCurveApproxStep(e,t,r,i),a=Math.ceil(1/n);return this.useNativeLine?a*2:a*2+2},getCubicCurveTriangleCount:function(e,t,r,i){var n=this._getCubicCurveApproxStep(e,t,r,i),a=Math.ceil(1/n);return this.useNativeLine?0:a*2},getLineVertexCount:function(){return this.getPolylineVertexCount(Mo)},getLineTriangleCount:function(){return this.getPolylineTriangleCount(Mo)},getPolylineVertexCount:function(e){var t;if(typeof e=="number")t=e;else{var r=typeof e[0]!="number";t=r?e.length:e.length/3}return this.useNativeLine?(t-1)*2:(t-1)*2+2},getPolylineTriangleCount:function(e){var t;if(typeof e=="number")t=e;else{var r=typeof e[0]!="number";t=r?e.length:e.length/3}return this.useNativeLine?0:Math.max(t-1,0)*2},addCubicCurve:function(e,t,r,i,n,a){a==null&&(a=1);for(var o=e[0],s=e[1],l=e[2],h=t[0],u=t[1],f=t[2],d=r[0],c=r[1],v=r[2],p=i[0],m=i[1],g=i[2],x=this._getCubicCurveApproxStep(e,t,r,i),y=x*x,_=y*x,w=3*x,S=3*y,b=6*y,A=6*_,C=o-h*2+d,P=s-u*2+c,L=l-f*2+v,R=(h-d)*3-o+p,I=(u-c)*3-s+m,D=(f-v)*3-l+g,O=o,z=s,V=l,F=(h-o)*w+C*S+R*_,le=(u-s)*w+P*S+I*_,H=(f-l)*w+L*S+D*_,de=C*b+R*A,he=P*b+I*A,ge=L*b+D*A,_e=R*A,te=I*A,Ne=D*A,Se=0,Ce=0,Qe=Math.ceil(1/x),Xe=new Float32Array((Qe+1)*3),Xe=[],ze=0,Ce=0;Ce1&&(O=F>0?Math.min(O,p):Math.max(O,p),z=le>0?Math.min(z,m):Math.max(z,m),V=H>0?Math.min(V,g):Math.max(V,g));return this.addPolyline(Xe,n,a)},addLine:function(e,t,r,i){return this.addPolyline([e,t],r,i)},addPolyline:function(e,t,r,i,n){if(!!e.length){var a=typeof e[0]!="number";if(n==null&&(n=a?e.length:e.length/3),!(n<2)){i==null&&(i=0),r==null&&(r=1),this._itemVertexOffsets.push(this._vertexOffset);var a=typeof e[0]!="number",o=a?typeof t[0]!="number":t.length/4===n,s=this.attributes.position,l=this.attributes.positionPrev,h=this.attributes.positionNext,u=this.attributes.color,f=this.attributes.offset,d=this.indices,c=this._vertexOffset,v,p;r=Math.max(r,.01);for(var m=i;m1&&(s.copy(c,c-1),u.copy(c,c-1),c++):(m0&&(h.set(c-2,v),h.set(c-1,v)),s.set(c,v),s.set(c+1,v),u.set(c,p),u.set(c+1,p),f.set(c,r/2),f.set(c+1,-r/2),c+=2),this.useNativeLine)u.set(c,p),s.set(c,v),c++;else if(m>0){var y=this._triangleOffset*3,d=this.indices;d[y]=c-4,d[y+1]=c-3,d[y+2]=c-2,d[y+3]=c-3,d[y+4]=c-1,d[y+5]=c-2,this._triangleOffset+=2}}if(!this.useNativeLine){var _=this._vertexOffset,w=this._vertexOffset+n*2;l.copy(_,_+2),l.copy(_+1,_+3),h.copy(w-1,w-3),h.copy(w-2,w-4)}return this._vertexOffset=c,this._vertexOffset}}},setItemColor:function(e,t){for(var r=this._itemVertexOffsets[e],i=eo&&(n=this._x=0,a+=this._rowHeight+l,this._y=a,this._rowHeight=0),this._x+=t+l,this._rowHeight=Math.max(this._rowHeight,r),a+r+l>s)return null;e.x+=this.offsetX*this.dpr+n,e.y+=this.offsetY*this.dpr+a,this._zr.add(e);var h=[this.offsetX/this.width,this.offsetY/this.height],u=[[n/o+h[0],a/s+h[1]],[(n+t)/o+h[0],(a+r)/s+h[1]]];return u},_fitElement:function(e,t,r){var i=e.getBoundingRect(),n=t/i.width,a=r/i.height;e.x=-i.x*n,e.y=-i.y*a,e.scaleX=n,e.scaleY=a,e.update()}};function sn(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 $({image:t,flipY:!1});var r=this;this._zr=Kl(t);var i=this._zr.refreshImmediately;this._zr.refreshImmediately=function(){i.call(this),r._texture.dirty(),r.onupdate&&r.onupdate()},this._dpr=e.devicePixelRatio,this._coords={},this.onupdate=e.onupdate,this._gap=e.gap,this._textureAtlasNodes=[new on(this._zr,0,0,e.width,e.height,this._gap,this._dpr)],this._nodeWidth=e.width,this._nodeHeight=e.height,this._currentNodeIdx=0}sn.prototype={clear:function(){for(var e=0;e=e){console.error("Too much labels. Some will be ignored.");return}var a=(i+this._nodeWidth)*this._dpr,o=(n+this._nodeHeight)*this._dpr;try{this._zr.resize({width:a,height:o})}catch{this._canvas.width=a,this._canvas.height=o}var s=new on(this._zr,i,n,this._nodeWidth,this._nodeHeight,this._gap,this._dpr);return this._textureAtlasNodes.push(s),s},add:function(e,t,r){if(this._coords[e.id])return console.warn("Element already been add"),this._coords[e.id];var i=this._getCurrentNode().add(e,t,r);if(!i){var n=this._expand();if(!n)return;i=n.add(e,t,r)}return this._coords[e.id]=i,i},getCoordsScale:function(){var e=this._dpr;return[this._nodeWidth/this._canvas.width*e,this._nodeHeight/this._canvas.height*e]},getCoords:function(e){return this._coords[e]},dispose:function(){this._zr.dispose()}};function Yt(){}Yt.prototype={constructor:Yt,setScene:function(e){this._scene=e,this._skybox&&this._skybox.attachScene(this._scene)},initLight:function(e){this._lightRoot=e,this.mainLight=new T.DirectionalLight({shadowBias:.005}),this.ambientLight=new T.AmbientLight,e.add(this.mainLight),e.add(this.ambientLight)},dispose:function(){this._lightRoot&&(this._lightRoot.remove(this.mainLight),this._lightRoot.remove(this.ambientLight))},updateLight:function(e){var t=this.mainLight,r=this.ambientLight,i=e.getModel("light"),n=i.getModel("main"),a=i.getModel("ambient");t.intensity=n.get("intensity"),r.intensity=a.get("intensity"),t.color=T.parseColor(n.get("color")).slice(0,3),r.color=T.parseColor(a.get("color")).slice(0,3);var o=n.get("alpha")||0,s=n.get("beta")||0;t.position.setArray(T.directionFromAlphaBeta(o,s)),t.lookAt(T.Vector3.ZERO),t.castShadow=n.get("shadow"),t.shadowResolution=T.getShadowResolution(n.get("shadowQuality"))},updateAmbientCubemap:function(e,t,r){var i=t.getModel("light.ambientCubemap"),n=i.get("texture");if(n){this._cubemapLightsCache=this._cubemapLightsCache||{};var a=this._cubemapLightsCache[n];if(!a){var o=this;a=this._cubemapLightsCache[n]=T.createAmbientCubemap(i.option,e,r,function(){o._isSkyboxFromAmbientCubemap&&o._skybox.setEnvironmentMap(a.specular.cubemap),r.getZr().refresh()})}this._lightRoot.add(a.diffuse),this._lightRoot.add(a.specular),this._currentCubemapLights=a}else this._currentCubemapLights&&(this._lightRoot.remove(this._currentCubemapLights.diffuse),this._lightRoot.remove(this._currentCubemapLights.specular),this._currentCubemapLights=null)},updateSkybox:function(e,t,r){var i=t.get("environment"),n=this;function a(){return n._skybox=n._skybox||new pi,n._skybox}var o=a();if(i&&i!=="none")if(i==="auto")if(this._isSkyboxFromAmbientCubemap=!0,this._currentCubemapLights){var s=this._currentCubemapLights.specular.cubemap;o.setEnvironmentMap(s),this._scene&&o.attachScene(this._scene),o.material.set("lod",3)}else this._skybox&&this._skybox.detachScene();else if(typeof i=="object"&&i.colorStops||typeof i=="string"&&ss(i)){this._isSkyboxFromAmbientCubemap=!1;var l=new T.Texture2D({anisotropic:8,flipY:!1});o.setEnvironmentMap(l);var h=l.image=document.createElement("canvas");h.width=h.height=16;var u=h.getContext("2d"),f=new ls({shape:{x:0,y:0,width:16,height:16},style:{fill:i}});hs(u,f),o.attachScene(this._scene)}else{this._isSkyboxFromAmbientCubemap=!1;var l=T.loadTexture(i,r,{anisotropic:8,flipY:!1});o.setEnvironmentMap(l),o.attachScene(this._scene)}else this._skybox&&this._skybox.detachScene(this._scene),this._skybox=null;var d=t.coordinateSystem;if(this._skybox)if(d&&d.viewGL&&i!=="auto"&&!(i.match&&i.match(/.hdr$/))){var c=d.viewGL.isLinearSpace()?"define":"undefine";this._skybox.material[c]("fragment","SRGB_DECODE")}else this._skybox.material.undefine("fragment","SRGB_DECODE")}};var rr=Me.vec3,Gs=oe.extend(function(){return{segmentScale:1,useNativeLine:!0,attributes:{position:new oe.Attribute("position","float",3,"POSITION"),normal:new oe.Attribute("normal","float",3,"NORMAL"),color:new oe.Attribute("color","float",4,"COLOR")}}},{resetOffset:function(){this._vertexOffset=0,this._faceOffset=0},setQuadCount:function(e){var t=this.attributes,r=this.getQuadVertexCount()*e,i=this.getQuadTriangleCount()*e;this.vertexCount!==r&&(t.position.init(r),t.normal.init(r),t.color.init(r)),this.triangleCount!==i&&(this.indices=r>65535?new Uint32Array(i*3):new Uint16Array(i*3))},getQuadVertexCount:function(){return 4},getQuadTriangleCount:function(){return 2},addQuad:function(){var e=rr.create(),t=rr.create(),r=rr.create(),i=[0,3,1,3,2,1];return function(n,a){var o=this.attributes.position,s=this.attributes.normal,l=this.attributes.color;rr.sub(e,n[1],n[0]),rr.sub(t,n[2],n[1]),rr.cross(r,e,t),rr.normalize(r,r);for(var h=0;h<4;h++)o.set(this._vertexOffset+h,n[h]),l.set(this._vertexOffset+h,a),s.set(this._vertexOffset+h,r);for(var u=this._faceOffset*3,h=0;h<6;h++)this.indices[u+h]=i[h]+this._vertexOffset;this._vertexOffset+=4,this._faceOffset+=2}}()});Kt(Gs.prototype,Ci);const zf=Gs;var ua=K.firstNotNull,Hf={x:0,y:2,z:1};function Vf(e,t,r,i){var n=[0,0,0],a=i<0?r.getExtentMin():r.getExtentMax();n[Hf[r.dim]]=a,e.position.setArray(n),e.rotation.identity(),t.distance=-Math.abs(a),t.normal.set(0,0,0),r.dim==="x"?(e.rotation.rotateY(i*Math.PI/2),t.normal.x=-i):r.dim==="z"?(e.rotation.rotateX(-i*Math.PI/2),t.normal.y=-i):(i>0&&e.rotation.rotateY(Math.PI),t.normal.z=-i)}function Sn(e,t,r){this.rootNode=new T.Node;var i=new T.Mesh({geometry:new yr({useNativeLine:!1}),material:t,castShadow:!1,ignorePicking:!0,$ignorePicking:!0,renderOrder:1}),n=new T.Mesh({geometry:new zf,material:r,castShadow:!1,culling:!1,ignorePicking:!0,$ignorePicking:!0,renderOrder:0});this.rootNode.add(n),this.rootNode.add(i),this.faceInfo=e,this.plane=new T.Plane,this.linesMesh=i,this.quadsMesh=n}Sn.prototype.update=function(e,t,r){var i=e.coordinateSystem,n=[i.getAxis(this.faceInfo[0]),i.getAxis(this.faceInfo[1])],a=this.linesMesh.geometry,o=this.quadsMesh.geometry;a.convertToDynamicArray(!0),o.convertToDynamicArray(!0),this._updateSplitLines(a,n,e,r),this._udpateSplitAreas(o,n,e,r),a.convertToTypedArray(),o.convertToTypedArray();var s=i.getAxis(this.faceInfo[2]);Vf(this.rootNode,this.plane,s,this.faceInfo[3])};Sn.prototype._updateSplitLines=function(e,t,r,i){var n=i.getDevicePixelRatio();t.forEach(function(a,o){var s=a.model,l=t[1-o].getExtent();if(!a.scale.isBlank()){var h=s.getModel("splitLine",r.getModel("splitLine"));if(h.get("show")){var u=h.getModel("lineStyle"),f=u.get("color"),d=ua(u.get("opacity"),1),c=ua(u.get("width"),1);f=Mt(f)?f:[f];for(var v=a.getTicksCoords({tickModel:h}),p=0,m=0;m65535?new Uint32Array(r*3):new Uint16Array(r*3))},setSpriteAlign:function(e,t,r,i,n){r==null&&(r="left"),i==null&&(i="top");var a,o,s,l;switch(n=n||0,r){case"left":a=n,s=t[0]+n;break;case"center":case"middle":a=-t[0]/2,s=t[0]/2;break;case"right":a=-t[0]-n,s=-n;break}switch(i){case"bottom":o=n,l=t[1]+n;break;case"middle":o=-t[1]/2,l=t[1]/2;break;case"top":o=-t[1]-n,l=-n;break}var h=e*4,u=this.attributes.offset;u.set(h,[a,l]),u.set(h+1,[s,l]),u.set(h+2,[s,o]),u.set(h+3,[a,o])},addSprite:function(e,t,r,i,n,a){var o=this._vertexOffset;this.setSprite(this._vertexOffset/4,e,t,r,i,n,a);for(var s=0;s 0.0) { currProj = clipNear(currProj, nextProj); } else if (prevProj.w > 0.0) { currProj = clipNear(currProj, prevProj); } } vec2 prevScreen = (prevProj.xy / abs(prevProj.w) + 1.0) * 0.5 * viewport.zw; vec2 currScreen = (currProj.xy / abs(currProj.w) + 1.0) * 0.5 * viewport.zw; vec2 nextScreen = (nextProj.xy / abs(nextProj.w) + 1.0) * 0.5 * viewport.zw; vec2 dir; float len = offset; if (position == positionPrev) { dir = normalize(nextScreen - currScreen); } else if (position == positionNext) { dir = normalize(currScreen - prevScreen); } else { vec2 dirA = normalize(currScreen - prevScreen); vec2 dirB = normalize(nextScreen - currScreen); vec2 tanget = normalize(dirA + dirB); float miter = 1.0 / max(dot(tanget, dirA), 0.5); len *= miter; dir = tanget; } dir = vec2(-dir.y, dir.x) * len; currScreen += dir; currProj.xy = (currScreen / viewport.zw - 0.5) * 2.0 * abs(currProj.w); @end @export ecgl.meshLines3D.vertex attribute vec3 position: POSITION; attribute vec3 positionPrev; attribute vec3 positionNext; attribute float offset; attribute vec4 a_Color : COLOR; #ifdef VERTEX_ANIMATION attribute vec3 prevPosition; attribute vec3 prevPositionPrev; attribute vec3 prevPositionNext; uniform float percent : 1.0; #endif uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; uniform vec4 viewport : VIEWPORT; uniform float near : NEAR; varying vec4 v_Color; @import ecgl.common.wireframe.vertexHeader @import ecgl.lines3D.clipNear void main() { @import ecgl.lines3D.expandLine gl_Position = currProj; v_Color = a_Color; @import ecgl.common.wireframe.vertexMain } @end @export ecgl.meshLines3D.fragment uniform vec4 color : [1.0, 1.0, 1.0, 1.0]; varying vec4 v_Color; @import ecgl.common.wireframe.fragmentHeader @import clay.util.srgb void main() { #ifdef SRGB_DECODE gl_FragColor = sRGBToLinear(color * v_Color); #else gl_FragColor = color * v_Color; #endif @import ecgl.common.wireframe.fragmentMain } @end`;var Po=K.firstNotNull;T.Shader.import(An);var ar={x:0,y:2,z:1};const Xf=Ai.extend({type:"grid3D",__ecgl__:!0,init:function(e,t){var r=[["y","z","x",-1,"left"],["y","z","x",1,"right"],["x","y","z",-1,"bottom"],["x","y","z",1,"top"],["x","z","y",-1,"far"],["x","z","y",1,"near"]],i=["x","y","z"],n=new T.Material({shader:T.createShader("ecgl.color"),depthMask:!1,transparent:!0}),a=new T.Material({shader:T.createShader("ecgl.meshLines3D"),depthMask:!1,transparent:!0});n.define("fragment","DOUBLE_SIDED"),n.define("both","VERTEX_COLOR"),this.groupGL=new T.Node,this._control=new wn({zr:t.getZr()}),this._control.init(),this._faces=r.map(function(s){var l=new Sn(s,a,n);return this.groupGL.add(l.rootNode),l},this),this._axes=i.map(function(s){var l=new Da(s,a);return this.groupGL.add(l.rootNode),l},this);var o=t.getDevicePixelRatio();this._axisLabelSurface=new sn({width:256,height:256,devicePixelRatio:o}),this._axisLabelSurface.onupdate=function(){t.getZr().refresh()},this._axisPointerLineMesh=new T.Mesh({geometry:new yr({useNativeLine:!1}),material:a,castShadow:!1,ignorePicking:!0,renderOrder:3}),this.groupGL.add(this._axisPointerLineMesh),this._axisPointerLabelsSurface=new sn({width:128,height:128,devicePixelRatio:o}),this._axisPointerLabelsMesh=new Ma({ignorePicking:!0,renderOrder:4,castShadow:!1}),this._axisPointerLabelsMesh.material.set("textureAtlas",this._axisPointerLabelsSurface.getTexture()),this.groupGL.add(this._axisPointerLabelsMesh),this._lightRoot=new T.Node,this._sceneHelper=new Yt,this._sceneHelper.initLight(this._lightRoot)},render:function(e,t,r){this._model=e,this._api=r;var i=e.coordinateSystem;i.viewGL.add(this._lightRoot),e.get("show")?i.viewGL.add(this.groupGL):i.viewGL.remove(this.groupGL);var n=this._control;n.setViewGL(i.viewGL);var a=e.getModel("viewControl");n.setFromViewControlModel(a,0),this._axisLabelSurface.clear(),n.off("update"),e.get("show")&&(this._faces.forEach(function(o){o.update(e,t,r)},this),this._axes.forEach(function(o){o.update(e,this._axisLabelSurface,r)},this)),n.on("update",this._onCameraChange.bind(this,e,r),this),this._sceneHelper.setScene(i.viewGL.scene),this._sceneHelper.updateLight(e),i.viewGL.setPostEffect(e.getModel("postEffect"),r),i.viewGL.setTemporalSuperSampling(e.getModel("temporalSuperSampling")),this._initMouseHandler(e)},afterRender:function(e,t,r,i){var n=i.renderer;this._sceneHelper.updateAmbientCubemap(n,e,r),this._sceneHelper.updateSkybox(n,e,r)},showAxisPointer:function(e,t,r,i){this._doShowAxisPointer(),this._updateAxisPointer(i.value)},hideAxisPointer:function(e,t,r,i){this._doHideAxisPointer()},_initMouseHandler:function(e){var t=e.coordinateSystem,r=t.viewGL;e.get("show")&&e.get("axisPointer.show")?r.on("mousemove",this._updateAxisPointerOnMousePosition,this):r.off("mousemove",this._updateAxisPointerOnMousePosition)},_updateAxisPointerOnMousePosition:function(e){if(!e.target){for(var t=this._model,r=t.coordinateSystem,i=r.viewGL,n=i.castRay(e.offsetX,e.offsetY,new T.Ray),a,o=0;oi[1]?0:1,s=this._faces[r*2+o],l=this._faces[r*2+1-o];s.rootNode.invisible=!0,l.rootNode.invisible=!1}},_updateAxisLinePosition:function(){var e=this._model.coordinateSystem,t=e.getAxis("x"),r=e.getAxis("y"),i=e.getAxis("z"),n=i.getExtentMax(),a=i.getExtentMin(),o=t.getExtentMin(),s=t.getExtentMax(),l=r.getExtentMax(),h=r.getExtentMin(),u=this._axes[0].rootNode,f=this._axes[1].rootNode,d=this._axes[2].rootNode,c=this._faces,v=c[4].rootNode.invisible?h:l,p=c[2].rootNode.invisible?n:a,m=c[0].rootNode.invisible?o:s,g=c[2].rootNode.invisible?n:a,x=c[0].rootNode.invisible?s:o,y=c[4].rootNode.invisible?h:l;u.rotation.identity(),f.rotation.identity(),d.rotation.identity(),c[4].rootNode.invisible&&(this._axes[0].flipped=!0,u.rotation.rotateX(Math.PI)),c[0].rootNode.invisible&&(this._axes[1].flipped=!0,f.rotation.rotateZ(Math.PI)),c[4].rootNode.invisible&&(this._axes[2].flipped=!0,d.rotation.rotateY(Math.PI)),u.position.set(0,p,v),f.position.set(m,g,0),d.position.set(x,0,y),u.update(),f.update(),d.update(),this._updateAxisLabelAlign()},_updateAxisLabelAlign:function(){var e=this._control.getCamera(),t=[new T.Vector4,new T.Vector4],r=new T.Vector4;this.groupGL.getWorldPosition(r),r.w=1,r.transformMat4(e.viewMatrix).transformMat4(e.projectionMatrix),r.x/=r.w,r.y/=r.w,this._axes.forEach(function(i){var n=i.axisLineCoords;i.labelsMesh.geometry;for(var a=0;ar.y?"bottom":"top"):(f="middle",u=l>r.x?"left":"right"),i.setSpriteAlign(u,f,this._api)},this)},_doShowAxisPointer:function(){!this._axisPointerLineMesh.invisible||(this._axisPointerLineMesh.invisible=!1,this._axisPointerLabelsMesh.invisible=!1,this._api.getZr().refresh())},_doHideAxisPointer:function(){this._axisPointerLineMesh.invisible||(this._axisPointerLineMesh.invisible=!0,this._axisPointerLabelsMesh.invisible=!0,this._api.getZr().refresh())},_updateAxisPointer:function(e){var t=this._model.coordinateSystem,r=t.dataToPoint(e),i=this._axisPointerLineMesh,n=i.geometry,a=this._model.getModel("axisPointer"),o=this._api.getDevicePixelRatio();n.convertToDynamicArray(!0);function s(A){return K.firstNotNull(A.model.get("axisPointer.show"),a.get("show"))}function l(A){var C=A.model.getModel("axisPointer",a),P=C.getModel("lineStyle"),L=T.parseColor(P.get("color")),R=Po(P.get("width"),1),I=Po(P.get("opacity"),1);return L[3]*=I,{color:L,lineWidth:R}}for(var h=0;h 0.0) { if (texture2D(alphaMap, v_Texcoord).a <= alphaCutoff) { discard; } } #ifdef USE_VSM depth = depth * 0.5 + 0.5; float moment1 = depth; float moment2 = depth * depth; #ifdef SUPPORT_STANDARD_DERIVATIVES float dx = dFdx(depth); float dy = dFdy(depth); moment2 += 0.25*(dx*dx+dy*dy); #endif gl_FragColor = vec4(moment1, moment2, 0.0, 1.0); #else #ifdef SUPPORT_STANDARD_DERIVATIVES float dx = dFdx(depth); float dy = dFdy(depth); depth += sqrt(dx*dx + dy*dy) * slopeScale + bias; #else depth += bias; #endif gl_FragColor = encodeFloat(depth * 0.5 + 0.5); #endif } @end @export clay.sm.debug_depth uniform sampler2D depthMap; varying vec2 v_Texcoord; @import clay.util.decode_float void main() { vec4 tex = texture2D(depthMap, v_Texcoord); #ifdef USE_VSM gl_FragColor = vec4(tex.rgb, 1.0); #else float depth = decodeFloat(tex); gl_FragColor = vec4(depth, depth, depth, 1.0); #endif } @end @export clay.sm.distance.vertex uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; uniform mat4 world : WORLD; attribute vec3 position : POSITION; @import clay.chunk.skinning_header varying vec3 v_WorldPosition; void main (){ vec4 P = vec4(position, 1.0); #ifdef SKINNING @import clay.chunk.skin_matrix P = skinMatrixWS * P; #endif #ifdef INSTANCING @import clay.chunk.instancing_matrix P = instanceMat * P; #endif gl_Position = worldViewProjection * P; v_WorldPosition = (world * P).xyz; } @end @export clay.sm.distance.fragment uniform vec3 lightPosition; uniform float range : 100; varying vec3 v_WorldPosition; @import clay.util.encode_float void main(){ float dist = distance(lightPosition, v_WorldPosition); #ifdef USE_VSM gl_FragColor = vec4(dist, dist * dist, 0.0, 0.0); #else dist = dist / range; gl_FragColor = encodeFloat(dist); #endif } @end @export clay.plugin.shadow_map_common @import clay.util.decode_float float tapShadowMap(sampler2D map, vec2 uv, float z){ vec4 tex = texture2D(map, uv); return step(z, decodeFloat(tex) * 2.0 - 1.0); } float pcf(sampler2D map, vec2 uv, float z, float textureSize, vec2 scale) { float shadowContrib = tapShadowMap(map, uv, z); vec2 offset = vec2(1.0 / textureSize) * scale; #ifdef PCF_KERNEL_SIZE for (int _idx_ = 0; _idx_ < PCF_KERNEL_SIZE; _idx_++) {{ shadowContrib += tapShadowMap(map, uv + offset * pcfKernel[_idx_], z); }} return shadowContrib / float(PCF_KERNEL_SIZE + 1); #else shadowContrib += tapShadowMap(map, uv+vec2(offset.x, 0.0), z); shadowContrib += tapShadowMap(map, uv+vec2(offset.x, offset.y), z); shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, offset.y), z); shadowContrib += tapShadowMap(map, uv+vec2(0.0, offset.y), z); shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, 0.0), z); shadowContrib += tapShadowMap(map, uv+vec2(-offset.x, -offset.y), z); shadowContrib += tapShadowMap(map, uv+vec2(offset.x, -offset.y), z); shadowContrib += tapShadowMap(map, uv+vec2(0.0, -offset.y), z); return shadowContrib / 9.0; #endif } float pcf(sampler2D map, vec2 uv, float z, float textureSize) { return pcf(map, uv, z, textureSize, vec2(1.0)); } float chebyshevUpperBound(vec2 moments, float z){ float p = 0.0; z = z * 0.5 + 0.5; if (z <= moments.x) { p = 1.0; } float variance = moments.y - moments.x * moments.x; variance = max(variance, 0.0000001); float mD = moments.x - z; float pMax = variance / (variance + mD * mD); pMax = clamp((pMax-0.4)/(1.0-0.4), 0.0, 1.0); return max(p, pMax); } float computeShadowContrib( sampler2D map, mat4 lightVPM, vec3 position, float textureSize, vec2 scale, vec2 offset ) { vec4 posInLightSpace = lightVPM * vec4(position, 1.0); posInLightSpace.xyz /= posInLightSpace.w; float z = posInLightSpace.z; if(all(greaterThan(posInLightSpace.xyz, vec3(-0.99, -0.99, -1.0))) && all(lessThan(posInLightSpace.xyz, vec3(0.99, 0.99, 1.0)))){ vec2 uv = (posInLightSpace.xy+1.0) / 2.0; #ifdef USE_VSM vec2 moments = texture2D(map, uv * scale + offset).xy; return chebyshevUpperBound(moments, z); #else return pcf(map, uv * scale + offset, z, textureSize, scale); #endif } return 1.0; } float computeShadowContrib(sampler2D map, mat4 lightVPM, vec3 position, float textureSize) { return computeShadowContrib(map, lightVPM, position, textureSize, vec2(1.0), vec2(0.0)); } float computeShadowContribOmni(samplerCube map, vec3 direction, float range) { float dist = length(direction); vec4 shadowTex = textureCube(map, direction); #ifdef USE_VSM vec2 moments = shadowTex.xy; float variance = moments.y - moments.x * moments.x; float mD = moments.x - dist; float p = variance / (variance + mD * mD); if(moments.x + 0.001 < dist){ return clamp(p, 0.0, 1.0); }else{ return 1.0; } #else return step(dist, (decodeFloat(shadowTex) + 0.0002) * range); #endif } @end @export clay.plugin.compute_shadow_map #if defined(SPOT_LIGHT_SHADOWMAP_COUNT) || defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) || defined(POINT_LIGHT_SHADOWMAP_COUNT) #ifdef SPOT_LIGHT_SHADOWMAP_COUNT uniform sampler2D spotLightShadowMaps[SPOT_LIGHT_SHADOWMAP_COUNT]:unconfigurable; uniform mat4 spotLightMatrices[SPOT_LIGHT_SHADOWMAP_COUNT]:unconfigurable; uniform float spotLightShadowMapSizes[SPOT_LIGHT_SHADOWMAP_COUNT]:unconfigurable; #endif #ifdef DIRECTIONAL_LIGHT_SHADOWMAP_COUNT #if defined(SHADOW_CASCADE) uniform sampler2D directionalLightShadowMaps[1]:unconfigurable; uniform mat4 directionalLightMatrices[SHADOW_CASCADE]:unconfigurable; uniform float directionalLightShadowMapSizes[1]:unconfigurable; uniform float shadowCascadeClipsNear[SHADOW_CASCADE]:unconfigurable; uniform float shadowCascadeClipsFar[SHADOW_CASCADE]:unconfigurable; #else uniform sampler2D directionalLightShadowMaps[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT]:unconfigurable; uniform mat4 directionalLightMatrices[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT]:unconfigurable; uniform float directionalLightShadowMapSizes[DIRECTIONAL_LIGHT_SHADOWMAP_COUNT]:unconfigurable; #endif #endif #ifdef POINT_LIGHT_SHADOWMAP_COUNT uniform samplerCube pointLightShadowMaps[POINT_LIGHT_SHADOWMAP_COUNT]:unconfigurable; #endif uniform bool shadowEnabled : true; #ifdef PCF_KERNEL_SIZE uniform vec2 pcfKernel[PCF_KERNEL_SIZE]; #endif @import clay.plugin.shadow_map_common #if defined(SPOT_LIGHT_SHADOWMAP_COUNT) void computeShadowOfSpotLights(vec3 position, inout float shadowContribs[SPOT_LIGHT_COUNT] ) { float shadowContrib; for(int _idx_ = 0; _idx_ < SPOT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{ shadowContrib = computeShadowContrib( spotLightShadowMaps[_idx_], spotLightMatrices[_idx_], position, spotLightShadowMapSizes[_idx_] ); shadowContribs[_idx_] = shadowContrib; }} for(int _idx_ = SPOT_LIGHT_SHADOWMAP_COUNT; _idx_ < SPOT_LIGHT_COUNT; _idx_++){{ shadowContribs[_idx_] = 1.0; }} } #endif #if defined(DIRECTIONAL_LIGHT_SHADOWMAP_COUNT) #ifdef SHADOW_CASCADE void computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){ float depth = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) / (gl_DepthRange.far - gl_DepthRange.near); float shadowContrib; shadowContribs[0] = 1.0; for (int _idx_ = 0; _idx_ < SHADOW_CASCADE; _idx_++) {{ if ( depth >= shadowCascadeClipsNear[_idx_] && depth <= shadowCascadeClipsFar[_idx_] ) { shadowContrib = computeShadowContrib( directionalLightShadowMaps[0], directionalLightMatrices[_idx_], position, directionalLightShadowMapSizes[0], vec2(1.0 / float(SHADOW_CASCADE), 1.0), vec2(float(_idx_) / float(SHADOW_CASCADE), 0.0) ); shadowContribs[0] = shadowContrib; } }} for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{ shadowContribs[_idx_] = 1.0; }} } #else void computeShadowOfDirectionalLights(vec3 position, inout float shadowContribs[DIRECTIONAL_LIGHT_COUNT]){ float shadowContrib; for(int _idx_ = 0; _idx_ < DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_++) {{ shadowContrib = computeShadowContrib( directionalLightShadowMaps[_idx_], directionalLightMatrices[_idx_], position, directionalLightShadowMapSizes[_idx_] ); shadowContribs[_idx_] = shadowContrib; }} for(int _idx_ = DIRECTIONAL_LIGHT_SHADOWMAP_COUNT; _idx_ < DIRECTIONAL_LIGHT_COUNT; _idx_++) {{ shadowContribs[_idx_] = 1.0; }} } #endif #endif #if defined(POINT_LIGHT_SHADOWMAP_COUNT) void computeShadowOfPointLights(vec3 position, inout float shadowContribs[POINT_LIGHT_COUNT] ){ vec3 lightPosition; vec3 direction; for(int _idx_ = 0; _idx_ < POINT_LIGHT_SHADOWMAP_COUNT; _idx_++) {{ lightPosition = pointLightPosition[_idx_]; direction = position - lightPosition; shadowContribs[_idx_] = computeShadowContribOmni(pointLightShadowMaps[_idx_], direction, pointLightRange[_idx_]); }} for(int _idx_ = POINT_LIGHT_SHADOWMAP_COUNT; _idx_ < POINT_LIGHT_COUNT; _idx_++) {{ shadowContribs[_idx_] = 1.0; }} } #endif #endif @end`;var Vt=["px","nx","py","ny","pz","nz"];N.import(qf);function jn(e,t,r){if(r==="alphaMap")return e.material.get("diffuseMap");if(r==="alphaCutoff"){if(e.material.isDefined("fragment","ALPHA_TEST")&&e.material.get("diffuseMap")){var i=e.material.get("alphaCutoff");return i||0}return 0}else return r==="uvRepeat"?e.material.get("uvRepeat"):r==="uvOffset"?e.material.get("uvOffset"):t.get(r)}function No(e,t){var r=e.material,i=t.material;return r.get("diffuseMap")!==i.get("diffuseMap")||(r.get("alphaCutoff")||0)!==(i.get("alphaCutoff")||0)}var Ct=nt.extend(function(){return{softShadow:Ct.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 qe,_textures:{},_shadowMapNumber:{POINT_LIGHT:0,DIRECTIONAL_LIGHT:0,SPOT_LIGHT:0},_depthMaterials:{},_distanceMaterials:{},_receivers:[],_lightsCastShadow:[],_lightCameras:{},_lightMaterials:{},_texturePool:new Vs}},function(){this._gaussianPassH=new Re({fragment:N.source("clay.compositor.gaussian_blur")}),this._gaussianPassV=new Re({fragment:N.source("clay.compositor.gaussian_blur")}),this._gaussianPassH.setUniform("blurSize",this.shadowBlur),this._gaussianPassH.setUniform("blurDir",0),this._gaussianPassV.setUniform("blurSize",this.shadowBlur),this._gaussianPassV.setUniform("blurDir",1),this._outputDepthPass=new Re({fragment:N.source("clay.sm.debug_depth")})},{render:function(e,t,r,i){r||(r=t.getMainCamera()),this.trigger("beforerender",this,e,t,r),this._renderShadowPass(e,t,r,i),this.trigger("afterrender",this,e,t,r)},renderDebug:function(e,t){e.saveClear();var r=e.viewport,i=0,n=0,a=t||r.width/4,o=a;this.softShadow===Ct.VSM?this._outputDepthPass.material.define("fragment","USE_VSM"):this._outputDepthPass.material.undefine("fragment","USE_VSM");for(var s in this._textures){var l=this._textures[s];e.setViewport(i,n,a*l.width/l.height,o),this._outputDepthPass.setUniform("depthMap",l),this._outputDepthPass.render(e),i+=a*l.width/l.height}e.setViewport(r),e.restoreClear()},_updateReceivers:function(e,t){if(t.receiveShadow?(this._receivers.push(t),t.material.set("shadowEnabled",1),t.material.set("pcfKernel",this.kernelPCF)):t.material.set("shadowEnabled",0),this.softShadow===Ct.VSM)t.material.define("fragment","USE_VSM"),t.material.undefine("fragment","PCF_KERNEL_SIZE");else{t.material.undefine("fragment","USE_VSM");var r=this.kernelPCF;r&&r.length?t.material.define("fragment","PCF_KERNEL_SIZE",r.length/2):t.material.undefine("fragment","PCF_KERNEL_SIZE")}},_update:function(e,t){var r=this;t.traverse(function(a){a.isRenderable()&&r._updateReceivers(e,a)});for(var i=0;i4){console.warn("Support at most 4 cascade");continue}v.shadowCascade>1&&(d=v),this.renderDirectionalLightShadow(e,t,r,v,u,h,l)}else v.type==="SPOT_LIGHT"?this.renderSpotLightShadow(e,t,v,s,o):v.type==="POINT_LIGHT"&&this.renderPointLightShadow(e,t,v,f);this._shadowMapNumber[v.type]++}for(var p in this._shadowMapNumber)for(var m=this._shadowMapNumber[p],g=p+"_SHADOWMAP_COUNT",c=0;c0?y.define("fragment",g,m):y.isDefined("fragment",g)&&y.undefine("fragment",g))}for(var c=0;c0){var S=l.map(w);if(_.directionalLightShadowMaps={value:l,type:"tv"},_.directionalLightMatrices={value:h,type:"m4v"},_.directionalLightShadowMapSizes={value:S,type:"1fv"},d){var b=u.slice(),A=u.slice();b.pop(),A.shift(),b.reverse(),A.reverse(),h.reverse(),_.shadowCascadeClipsNear={value:b,type:"1fv"},_.shadowCascadeClipsFar={value:A,type:"1fv"}}}if(o.length>0){var C=o.map(w),_=t.shadowUniforms;_.spotLightShadowMaps={value:o,type:"tv"},_.spotLightMatrices={value:s,type:"m4v"},_.spotLightShadowMapSizes={value:C,type:"1fv"}}f.length>0&&(_.pointLightShadowMaps={value:f,type:"tv"})},renderDirectionalLightShadow:function(){var e=new Ea,t=new k,r=new tt,i=new k,n=new k,a=new k,o=new k;return function(s,l,h,u,f,d,c){var v=this._getDepthMaterial(u),p={getMaterial:function(ge){return ge.shadowDepthMaterial||v},isMaterialChanged:No,getUniform:jn,ifRender:function(ge){return ge.castShadow},sortCompare:fi.opaqueSortCompare};if(!l.viewBoundingBoxLastFrame.isFinite()){var m=l.getBoundingBox();l.viewBoundingBoxLastFrame.copy(m).applyTransform(h.viewMatrix)}var g=Math.min(-l.viewBoundingBoxLastFrame.min.z,h.far),x=Math.max(-l.viewBoundingBoxLastFrame.max.z,h.near),y=this._getDirectionalLightCamera(u,l,h),_=a.array;o.copy(y.projectionMatrix),B.invert(n.array,y.worldTransform.array),B.multiply(n.array,n.array,h.worldTransform.array),B.multiply(_,o.array,n.array);for(var w=[],S=h instanceof He,b=(h.near+h.far)/(h.near-h.far),A=2*h.near*h.far/(h.near-h.far),C=0;C<=u.shadowCascade;C++){var P=x*Math.pow(g/x,C/u.shadowCascade),L=x+(g-x)*C/u.shadowCascade,R=P*u.cascadeSplitLogFactor+L*(1-u.cascadeSplitLogFactor);w.push(R),f.push(-(-R*b+A)/-R)}var I=this._getTexture(u,u.shadowCascade);c.push(I);var D=s.viewport,O=s.gl;this._frameBuffer.attach(I),this._frameBuffer.bind(s),O.clear(O.COLOR_BUFFER_BIT|O.DEPTH_BUFFER_BIT);for(var C=0;CP?C>L?v[S>0?"px":"nx"]=!0:v[A>0?"pz":"nz"]=!0:P>L?v[b>0?"py":"ny"]=!0:v[A>0?"pz":"nz"]=!0}for(var _=0;_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 gi=Kf;var Qf=nt.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=t.COLOR_ATTACHMENT0&&l<=t.COLOR_ATTACHMENT0+8&&u.push(l);h.drawBuffersEXT(u)}e.saveClear(),e.clearBit=M.DEPTH_BUFFER_BIT|M.COLOR_BUFFER_BIT,r=e.render(this.scene,this.camera,!this.autoUpdateScene,this.preZ),e.restoreClear(),i.unbind(e)}this.trigger("afterrender",r),this._rendering=!1,this._rendered=!0}});const tc=ec;var rc=gi.extend(function(){return{texture:null,outputs:{color:{}}}},function(){},{getOutput:function(e,t){return this.texture},beforeFrame:function(){},afterFrame:function(){}});const ic=rc;var nc=gi.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 Re({fragment:this.shader});this.pass=e},{render:function(e,t){this.trigger("beforerender",e),this._rendering=!0;var r=e.gl;for(var i in this.inputLinks){var n=this.inputLinks[i],a=n.node.getOutput(e,n.pin);this.pass.setUniform(i,a)}if(!this.outputs)this.pass.outputs=null,this._compositor.getFrameBuffer().unbind(e),this.pass.render(e,t);else{this.pass.outputs={};var o={};for(var s in this.outputs){var l=this.updateParameter(s,e);isNaN(l.width)&&this.updateParameter(s,e);var h=this.outputs[s],u=this._compositor.allocateTexture(l);this._outputTextures[s]=u;var f=h.attachment||r.COLOR_ATTACHMENT0;typeof f=="string"&&(f=r[f]),o[f]=u}this._compositor.getFrameBuffer().bind(e);for(var f in o)this._compositor.getFrameBuffer().attach(o[f],f);this.pass.render(e),this._compositor.getFrameBuffer().updateMipmap(e)}for(var i in this.inputLinks){var n=this.inputLinks[i];n.node.removeReference(n.pin)}this._rendering=!1,this._rendered=!0,this.trigger("afterrender",e)},updateParameter:function(e,t){var r=this.outputs[e],i=r.parameters,n=r._parametersCopy;if(n||(n=r._parametersCopy={}),i)for(var a in i)a!=="width"&&a!=="height"&&(n[a]=i[a]);var o,s;return typeof i.width=="function"?o=i.width.call(this,t):o=i.width,typeof i.height=="function"?s=i.height.call(this,t):s=i.height,o=Math.ceil(o),s=Math.ceil(s),(n.width!==o||n.height!==s)&&this._outputTextures[e]&&this._outputTextures[e].dispose(t),n.width=o,n.height=s,n},setParameter:function(e,t){this.pass.setUniform(e,t)},getParameter:function(e){return this.pass.getUniform(e)},setParameters:function(e){for(var t in e)this.setParameter(t,e[t])},define:function(e,t){this.pass.material.define("fragment",e,t)},undefine:function(e){this.pass.material.undefine("fragment",e)},removeReference:function(e){if(this._outputReferences[e]--,this._outputReferences[e]===0){var t=this.outputs[e];t.keepLastFrame?(this._prevOutputTextures[e]&&this._compositor.releaseTexture(this._prevOutputTextures[e]),this._prevOutputTextures[e]=this._outputTextures[e]):this._compositor.releaseTexture(this._outputTextures[e])}},clear:function(){gi.prototype.clear.call(this),this.pass.material.disableTexturesAll()}});const ac=nc,oc=`@export clay.compositor.coloradjust varying vec2 v_Texcoord; uniform sampler2D texture; uniform float brightness : 0.0; uniform float contrast : 1.0; uniform float exposure : 0.0; uniform float gamma : 1.0; uniform float saturation : 1.0; const vec3 w = vec3(0.2125, 0.7154, 0.0721); void main() { vec4 tex = texture2D( texture, v_Texcoord); vec3 color = clamp(tex.rgb + vec3(brightness), 0.0, 1.0); color = clamp( (color-vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0); color = clamp( color * pow(2.0, exposure), 0.0, 1.0); color = clamp( pow(color, vec3(gamma)), 0.0, 1.0); float luminance = dot( color, w ); color = mix(vec3(luminance), color, saturation); gl_FragColor = vec4(color, tex.a); } @end @export clay.compositor.brightness varying vec2 v_Texcoord; uniform sampler2D texture; uniform float brightness : 0.0; void main() { vec4 tex = texture2D( texture, v_Texcoord); vec3 color = tex.rgb + vec3(brightness); gl_FragColor = vec4(color, tex.a); } @end @export clay.compositor.contrast varying vec2 v_Texcoord; uniform sampler2D texture; uniform float contrast : 1.0; void main() { vec4 tex = texture2D( texture, v_Texcoord); vec3 color = (tex.rgb-vec3(0.5))*contrast+vec3(0.5); gl_FragColor = vec4(color, tex.a); } @end @export clay.compositor.exposure varying vec2 v_Texcoord; uniform sampler2D texture; uniform float exposure : 0.0; void main() { vec4 tex = texture2D(texture, v_Texcoord); vec3 color = tex.rgb * pow(2.0, exposure); gl_FragColor = vec4(color, tex.a); } @end @export clay.compositor.gamma varying vec2 v_Texcoord; uniform sampler2D texture; uniform float gamma : 1.0; void main() { vec4 tex = texture2D(texture, v_Texcoord); vec3 color = pow(tex.rgb, vec3(gamma)); gl_FragColor = vec4(color, tex.a); } @end @export clay.compositor.saturation varying vec2 v_Texcoord; uniform sampler2D texture; uniform float saturation : 1.0; const vec3 w = vec3(0.2125, 0.7154, 0.0721); void main() { vec4 tex = texture2D(texture, v_Texcoord); vec3 color = tex.rgb; float luminance = dot(color, w); color = mix(vec3(luminance), color, saturation); gl_FragColor = vec4(color, tex.a); } @end`,ks=`@export clay.compositor.kernel.gaussian_9 float gaussianKernel[9]; gaussianKernel[0] = 0.07; gaussianKernel[1] = 0.09; gaussianKernel[2] = 0.12; gaussianKernel[3] = 0.14; gaussianKernel[4] = 0.16; gaussianKernel[5] = 0.14; gaussianKernel[6] = 0.12; gaussianKernel[7] = 0.09; gaussianKernel[8] = 0.07; @end @export clay.compositor.kernel.gaussian_13 float gaussianKernel[13]; gaussianKernel[0] = 0.02; gaussianKernel[1] = 0.03; gaussianKernel[2] = 0.06; gaussianKernel[3] = 0.08; gaussianKernel[4] = 0.11; gaussianKernel[5] = 0.13; gaussianKernel[6] = 0.14; gaussianKernel[7] = 0.13; gaussianKernel[8] = 0.11; gaussianKernel[9] = 0.08; gaussianKernel[10] = 0.06; gaussianKernel[11] = 0.03; gaussianKernel[12] = 0.02; @end @export clay.compositor.gaussian_blur #define SHADER_NAME gaussian_blur uniform sampler2D texture;varying vec2 v_Texcoord; uniform float blurSize : 2.0; uniform vec2 textureSize : [512.0, 512.0]; uniform float blurDir : 0.0; @import clay.util.rgbm @import clay.util.clamp_sample void main (void) { @import clay.compositor.kernel.gaussian_9 vec2 off = blurSize / textureSize; off *= vec2(1.0 - blurDir, blurDir); vec4 sum = vec4(0.0); float weightAll = 0.0; for (int i = 0; i < 9; i++) { float w = gaussianKernel[i]; vec4 texel = decodeHDR(clampSample(texture, v_Texcoord + float(i - 4) * off)); sum += texel * w; weightAll += w; } gl_FragColor = encodeHDR(sum / max(weightAll, 0.01)); } @end `,sc=`@export clay.compositor.hdr.log_lum varying vec2 v_Texcoord; uniform sampler2D texture; const vec3 w = vec3(0.2125, 0.7154, 0.0721); @import clay.util.rgbm void main() { vec4 tex = decodeHDR(texture2D(texture, v_Texcoord)); float luminance = dot(tex.rgb, w); luminance = log(luminance + 0.001); gl_FragColor = encodeHDR(vec4(vec3(luminance), 1.0)); } @end @export clay.compositor.hdr.lum_adaption varying vec2 v_Texcoord; uniform sampler2D adaptedLum; uniform sampler2D currentLum; uniform float frameTime : 0.02; @import clay.util.rgbm void main() { float fAdaptedLum = decodeHDR(texture2D(adaptedLum, vec2(0.5, 0.5))).r; float fCurrentLum = exp(encodeHDR(texture2D(currentLum, vec2(0.5, 0.5))).r); fAdaptedLum += (fCurrentLum - fAdaptedLum) * (1.0 - pow(0.98, 30.0 * frameTime)); gl_FragColor = encodeHDR(vec4(vec3(fAdaptedLum), 1.0)); } @end @export clay.compositor.lum varying vec2 v_Texcoord; uniform sampler2D texture; const vec3 w = vec3(0.2125, 0.7154, 0.0721); void main() { vec4 tex = texture2D( texture, v_Texcoord ); float luminance = dot(tex.rgb, w); gl_FragColor = vec4(vec3(luminance), 1.0); } @end`,Ws=` @export clay.compositor.lut varying vec2 v_Texcoord; uniform sampler2D texture; uniform sampler2D lookup; void main() { vec4 tex = texture2D(texture, v_Texcoord); float blueColor = tex.b * 63.0; vec2 quad1; quad1.y = floor(floor(blueColor) / 8.0); quad1.x = floor(blueColor) - (quad1.y * 8.0); vec2 quad2; quad2.y = floor(ceil(blueColor) / 8.0); quad2.x = ceil(blueColor) - (quad2.y * 8.0); vec2 texPos1; texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r); texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g); vec2 texPos2; texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.r); texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * tex.g); vec4 newColor1 = texture2D(lookup, texPos1); vec4 newColor2 = texture2D(lookup, texPos2); vec4 newColor = mix(newColor1, newColor2, fract(blueColor)); gl_FragColor = vec4(newColor.rgb, tex.w); } @end`,lc=`@export clay.compositor.vignette #define OUTPUT_ALPHA varying vec2 v_Texcoord; uniform sampler2D texture; uniform float darkness: 1; uniform float offset: 1; @import clay.util.rgbm void main() { vec4 texel = decodeHDR(texture2D(texture, v_Texcoord)); gl_FragColor.rgb = texel.rgb; vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(offset); gl_FragColor = encodeHDR(vec4(mix(texel.rgb, vec3(1.0 - darkness), dot(uv, uv)), texel.a)); } @end`,Xs=`@export clay.compositor.output #define OUTPUT_ALPHA varying vec2 v_Texcoord; uniform sampler2D texture; @import clay.util.rgbm void main() { vec4 tex = decodeHDR(texture2D(texture, v_Texcoord)); gl_FragColor.rgb = tex.rgb; #ifdef OUTPUT_ALPHA gl_FragColor.a = tex.a; #else gl_FragColor.a = 1.0; #endif gl_FragColor = encodeHDR(gl_FragColor); #ifdef PREMULTIPLY_ALPHA gl_FragColor.rgb *= gl_FragColor.a; #endif } @end`,Zs=`@export clay.compositor.bright uniform sampler2D texture; uniform float threshold : 1; uniform float scale : 1.0; uniform vec2 textureSize: [512, 512]; varying vec2 v_Texcoord; const vec3 lumWeight = vec3(0.2125, 0.7154, 0.0721); @import clay.util.rgbm vec4 median(vec4 a, vec4 b, vec4 c) { return a + b + c - min(min(a, b), c) - max(max(a, b), c); } void main() { vec4 texel = decodeHDR(texture2D(texture, v_Texcoord)); #ifdef ANTI_FLICKER vec3 d = 1.0 / textureSize.xyx * vec3(1.0, 1.0, 0.0); vec4 s1 = decodeHDR(texture2D(texture, v_Texcoord - d.xz)); vec4 s2 = decodeHDR(texture2D(texture, v_Texcoord + d.xz)); vec4 s3 = decodeHDR(texture2D(texture, v_Texcoord - d.zy)); vec4 s4 = decodeHDR(texture2D(texture, v_Texcoord + d.zy)); texel = median(median(texel, s1, s2), s3, s4); #endif float lum = dot(texel.rgb , lumWeight); vec4 color; if (lum > threshold && texel.a > 0.0) { color = vec4(texel.rgb * scale, texel.a * scale); } else { color = vec4(0.0); } gl_FragColor = encodeHDR(color); } @end `,js=`@export clay.compositor.downsample uniform sampler2D texture; uniform vec2 textureSize : [512, 512]; varying vec2 v_Texcoord; @import clay.util.rgbm float brightness(vec3 c) { return max(max(c.r, c.g), c.b); } @import clay.util.clamp_sample void main() { vec4 d = vec4(-1.0, -1.0, 1.0, 1.0) / textureSize.xyxy; #ifdef ANTI_FLICKER vec3 s1 = decodeHDR(clampSample(texture, v_Texcoord + d.xy)).rgb; vec3 s2 = decodeHDR(clampSample(texture, v_Texcoord + d.zy)).rgb; vec3 s3 = decodeHDR(clampSample(texture, v_Texcoord + d.xw)).rgb; vec3 s4 = decodeHDR(clampSample(texture, v_Texcoord + d.zw)).rgb; float s1w = 1.0 / (brightness(s1) + 1.0); float s2w = 1.0 / (brightness(s2) + 1.0); float s3w = 1.0 / (brightness(s3) + 1.0); float s4w = 1.0 / (brightness(s4) + 1.0); float oneDivideSum = 1.0 / (s1w + s2w + s3w + s4w); vec4 color = vec4( (s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * oneDivideSum, 1.0 ); #else vec4 color = decodeHDR(clampSample(texture, v_Texcoord + d.xy)); color += decodeHDR(clampSample(texture, v_Texcoord + d.zy)); color += decodeHDR(clampSample(texture, v_Texcoord + d.xw)); color += decodeHDR(clampSample(texture, v_Texcoord + d.zw)); color *= 0.25; #endif gl_FragColor = encodeHDR(color); } @end`,qs=` @export clay.compositor.upsample #define HIGH_QUALITY uniform sampler2D texture; uniform vec2 textureSize : [512, 512]; uniform float sampleScale: 0.5; varying vec2 v_Texcoord; @import clay.util.rgbm @import clay.util.clamp_sample void main() { #ifdef HIGH_QUALITY vec4 d = vec4(1.0, 1.0, -1.0, 0.0) / textureSize.xyxy * sampleScale; vec4 s; s = decodeHDR(clampSample(texture, v_Texcoord - d.xy)); s += decodeHDR(clampSample(texture, v_Texcoord - d.wy)) * 2.0; s += decodeHDR(clampSample(texture, v_Texcoord - d.zy)); s += decodeHDR(clampSample(texture, v_Texcoord + d.zw)) * 2.0; s += decodeHDR(clampSample(texture, v_Texcoord )) * 4.0; s += decodeHDR(clampSample(texture, v_Texcoord + d.xw)) * 2.0; s += decodeHDR(clampSample(texture, v_Texcoord + d.zy)); s += decodeHDR(clampSample(texture, v_Texcoord + d.wy)) * 2.0; s += decodeHDR(clampSample(texture, v_Texcoord + d.xy)); gl_FragColor = encodeHDR(s / 16.0); #else vec4 d = vec4(-1.0, -1.0, +1.0, +1.0) / textureSize.xyxy; vec4 s; s = decodeHDR(clampSample(texture, v_Texcoord + d.xy)); s += decodeHDR(clampSample(texture, v_Texcoord + d.zy)); s += decodeHDR(clampSample(texture, v_Texcoord + d.xw)); s += decodeHDR(clampSample(texture, v_Texcoord + d.zw)); gl_FragColor = encodeHDR(s / 4.0); #endif } @end`,Ys=`@export clay.compositor.hdr.composite #define TONEMAPPING uniform sampler2D texture; #ifdef BLOOM_ENABLED uniform sampler2D bloom; #endif #ifdef LENSFLARE_ENABLED uniform sampler2D lensflare; uniform sampler2D lensdirt; #endif #ifdef LUM_ENABLED uniform sampler2D lum; #endif #ifdef LUT_ENABLED uniform sampler2D lut; #endif #ifdef COLOR_CORRECTION uniform float brightness : 0.0; uniform float contrast : 1.0; uniform float saturation : 1.0; #endif #ifdef VIGNETTE uniform float vignetteDarkness: 1.0; uniform float vignetteOffset: 1.0; #endif uniform float exposure : 1.0; uniform float bloomIntensity : 0.25; uniform float lensflareIntensity : 1; varying vec2 v_Texcoord; @import clay.util.srgb vec3 ACESToneMapping(vec3 color) { const float A = 2.51; const float B = 0.03; const float C = 2.43; const float D = 0.59; const float E = 0.14; return (color * (A * color + B)) / (color * (C * color + D) + E); } float eyeAdaption(float fLum) { return mix(0.2, fLum, 0.5); } #ifdef LUT_ENABLED vec3 lutTransform(vec3 color) { float blueColor = color.b * 63.0; vec2 quad1; quad1.y = floor(floor(blueColor) / 8.0); quad1.x = floor(blueColor) - (quad1.y * 8.0); vec2 quad2; quad2.y = floor(ceil(blueColor) / 8.0); quad2.x = ceil(blueColor) - (quad2.y * 8.0); vec2 texPos1; texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r); texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g); vec2 texPos2; texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.r); texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * color.g); vec4 newColor1 = texture2D(lut, texPos1); vec4 newColor2 = texture2D(lut, texPos2); vec4 newColor = mix(newColor1, newColor2, fract(blueColor)); return newColor.rgb; } #endif @import clay.util.rgbm void main() { vec4 texel = vec4(0.0); vec4 originalTexel = vec4(0.0); #ifdef TEXTURE_ENABLED texel = decodeHDR(texture2D(texture, v_Texcoord)); originalTexel = texel; #endif #ifdef BLOOM_ENABLED vec4 bloomTexel = decodeHDR(texture2D(bloom, v_Texcoord)); texel.rgb += bloomTexel.rgb * bloomIntensity; texel.a += bloomTexel.a * bloomIntensity; #endif #ifdef LENSFLARE_ENABLED texel += decodeHDR(texture2D(lensflare, v_Texcoord)) * texture2D(lensdirt, v_Texcoord) * lensflareIntensity; #endif texel.a = min(texel.a, 1.0); #ifdef LUM_ENABLED float fLum = texture2D(lum, vec2(0.5, 0.5)).r; float adaptedLumDest = 3.0 / (max(0.1, 1.0 + 10.0*eyeAdaption(fLum))); float exposureBias = adaptedLumDest * exposure; #else float exposureBias = exposure; #endif #ifdef TONEMAPPING texel.rgb *= exposureBias; texel.rgb = ACESToneMapping(texel.rgb); #endif texel = linearTosRGB(texel); #ifdef LUT_ENABLED texel.rgb = lutTransform(clamp(texel.rgb,vec3(0.0),vec3(1.0))); #endif #ifdef COLOR_CORRECTION texel.rgb = clamp(texel.rgb + vec3(brightness), 0.0, 1.0); texel.rgb = clamp((texel.rgb - vec3(0.5))*contrast+vec3(0.5), 0.0, 1.0); float lum = dot(texel.rgb, vec3(0.2125, 0.7154, 0.0721)); texel.rgb = mix(vec3(lum), texel.rgb, saturation); #endif #ifdef VIGNETTE vec2 uv = (v_Texcoord - vec2(0.5)) * vec2(vignetteOffset); texel.rgb = mix(texel.rgb, vec3(1.0 - vignetteDarkness), dot(uv, uv)); #endif gl_FragColor = encodeHDR(texel); #ifdef DEBUG #if DEBUG == 1 gl_FragColor = encodeHDR(decodeHDR(texture2D(texture, v_Texcoord))); #elif DEBUG == 2 gl_FragColor = encodeHDR(decodeHDR(texture2D(bloom, v_Texcoord)) * bloomIntensity); #elif DEBUG == 3 gl_FragColor = encodeHDR(decodeHDR(texture2D(lensflare, v_Texcoord) * lensflareIntensity)); #endif #endif if (originalTexel.a <= 0.01 && gl_FragColor.a > 1e-5) { gl_FragColor.a = dot(gl_FragColor.rgb, vec3(0.2125, 0.7154, 0.0721)); } #ifdef PREMULTIPLY_ALPHA gl_FragColor.rgb *= gl_FragColor.a; #endif } @end`,hc=`@export clay.compositor.lensflare #define SAMPLE_NUMBER 8 uniform sampler2D texture; uniform sampler2D lenscolor; uniform vec2 textureSize : [512, 512]; uniform float dispersal : 0.3; uniform float haloWidth : 0.4; uniform float distortion : 1.0; varying vec2 v_Texcoord; @import clay.util.rgbm vec4 textureDistorted( in vec2 texcoord, in vec2 direction, in vec3 distortion ) { return vec4( decodeHDR(texture2D(texture, texcoord + direction * distortion.r)).r, decodeHDR(texture2D(texture, texcoord + direction * distortion.g)).g, decodeHDR(texture2D(texture, texcoord + direction * distortion.b)).b, 1.0 ); } void main() { vec2 texcoord = -v_Texcoord + vec2(1.0); vec2 textureOffset = 1.0 / textureSize; vec2 ghostVec = (vec2(0.5) - texcoord) * dispersal; vec2 haloVec = normalize(ghostVec) * haloWidth; vec3 distortion = vec3(-textureOffset.x * distortion, 0.0, textureOffset.x * distortion); vec4 result = vec4(0.0); for (int i = 0; i < SAMPLE_NUMBER; i++) { vec2 offset = fract(texcoord + ghostVec * float(i)); float weight = length(vec2(0.5) - offset) / length(vec2(0.5)); weight = pow(1.0 - weight, 10.0); result += textureDistorted(offset, normalize(ghostVec), distortion) * weight; } result *= texture2D(lenscolor, vec2(length(vec2(0.5) - texcoord)) / length(vec2(0.5))); float weight = length(vec2(0.5) - fract(texcoord + haloVec)) / length(vec2(0.5)); weight = pow(1.0 - weight, 10.0); vec2 offset = fract(texcoord + haloVec); result += textureDistorted(offset, normalize(ghostVec), distortion) * weight; gl_FragColor = result; } @end`,Ks=`@export clay.compositor.blend #define SHADER_NAME blend #ifdef TEXTURE1_ENABLED uniform sampler2D texture1; uniform float weight1 : 1.0; #endif #ifdef TEXTURE2_ENABLED uniform sampler2D texture2; uniform float weight2 : 1.0; #endif #ifdef TEXTURE3_ENABLED uniform sampler2D texture3; uniform float weight3 : 1.0; #endif #ifdef TEXTURE4_ENABLED uniform sampler2D texture4; uniform float weight4 : 1.0; #endif #ifdef TEXTURE5_ENABLED uniform sampler2D texture5; uniform float weight5 : 1.0; #endif #ifdef TEXTURE6_ENABLED uniform sampler2D texture6; uniform float weight6 : 1.0; #endif varying vec2 v_Texcoord; @import clay.util.rgbm void main() { vec4 tex = vec4(0.0); #ifdef TEXTURE1_ENABLED tex += decodeHDR(texture2D(texture1, v_Texcoord)) * weight1; #endif #ifdef TEXTURE2_ENABLED tex += decodeHDR(texture2D(texture2, v_Texcoord)) * weight2; #endif #ifdef TEXTURE3_ENABLED tex += decodeHDR(texture2D(texture3, v_Texcoord)) * weight3; #endif #ifdef TEXTURE4_ENABLED tex += decodeHDR(texture2D(texture4, v_Texcoord)) * weight4; #endif #ifdef TEXTURE5_ENABLED tex += decodeHDR(texture2D(texture5, v_Texcoord)) * weight5; #endif #ifdef TEXTURE6_ENABLED tex += decodeHDR(texture2D(texture6, v_Texcoord)) * weight6; #endif gl_FragColor = encodeHDR(tex); } @end`,Qs=`@export clay.compositor.fxaa uniform sampler2D texture; uniform vec4 viewport : VIEWPORT; varying vec2 v_Texcoord; #define FXAA_REDUCE_MIN (1.0/128.0) #define FXAA_REDUCE_MUL (1.0/8.0) #define FXAA_SPAN_MAX 8.0 @import clay.util.rgbm void main() { vec2 resolution = 1.0 / viewport.zw; vec3 rgbNW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, -1.0 ) ) * resolution ) ).xyz; vec3 rgbNE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, -1.0 ) ) * resolution ) ).xyz; vec3 rgbSW = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( -1.0, 1.0 ) ) * resolution ) ).xyz; vec3 rgbSE = decodeHDR( texture2D( texture, ( gl_FragCoord.xy + vec2( 1.0, 1.0 ) ) * resolution ) ).xyz; vec4 rgbaM = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution ) ); vec3 rgbM = rgbaM.xyz; float opacity = rgbaM.w; vec3 luma = vec3( 0.299, 0.587, 0.114 ); float lumaNW = dot( rgbNW, luma ); float lumaNE = dot( rgbNE, luma ); float lumaSW = dot( rgbSW, luma ); float lumaSE = dot( rgbSE, luma ); float lumaM = dot( rgbM, luma ); float lumaMin = min( lumaM, min( min( lumaNW, lumaNE ), min( lumaSW, lumaSE ) ) ); float lumaMax = max( lumaM, max( max( lumaNW, lumaNE) , max( lumaSW, lumaSE ) ) ); vec2 dir; dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); float dirReduce = max( ( lumaNW + lumaNE + lumaSW + lumaSE ) * ( 0.25 * FXAA_REDUCE_MUL ), FXAA_REDUCE_MIN ); float rcpDirMin = 1.0 / ( min( abs( dir.x ), abs( dir.y ) ) + dirReduce ); dir = min( vec2( FXAA_SPAN_MAX, FXAA_SPAN_MAX), max( vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), dir * rcpDirMin)) * resolution; vec3 rgbA = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 1.0 / 3.0 - 0.5 ) ) ).xyz; rgbA += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * ( 2.0 / 3.0 - 0.5 ) ) ).xyz; rgbA *= 0.5; vec3 rgbB = decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * -0.5 ) ).xyz; rgbB += decodeHDR( texture2D( texture, gl_FragCoord.xy * resolution + dir * 0.5 ) ).xyz; rgbB *= 0.25; rgbB += rgbA * 0.5; float lumaB = dot( rgbB, luma ); if ( ( lumaB < lumaMin ) || ( lumaB > lumaMax ) ) { gl_FragColor = vec4( rgbA, opacity ); } else { gl_FragColor = vec4( rgbB, opacity ); } } @end`;function uc(e){e.import(oc),e.import(ks),e.import(sc),e.import(Ws),e.import(lc),e.import(Xs),e.import(Zs),e.import(js),e.import(qs),e.import(Ys),e.import(hc),e.import(Ks),e.import(Qs)}uc(N);var fc=/^#source\((.*?)\)/;function cc(e,t){var r=new Jf;t=t||{};var i={textures:{},parameters:{}},n=function(s,l){for(var h=0;h0;)r=r+i*(n%t),n=Math.floor(n/t),i=i/t;return r}const yc=`@export ecgl.ssao.estimate uniform sampler2D depthTex; uniform sampler2D normalTex; uniform sampler2D noiseTex; uniform vec2 depthTexSize; uniform vec2 noiseTexSize; uniform mat4 projection; uniform mat4 projectionInv; uniform mat4 viewInverseTranspose; uniform vec3 kernel[KERNEL_SIZE]; uniform float radius : 1; uniform float power : 1; uniform float bias: 1e-2; uniform float intensity: 1.0; varying vec2 v_Texcoord; float ssaoEstimator(in vec3 originPos, in mat3 kernelBasis) { float occlusion = 0.0; for (int i = 0; i < KERNEL_SIZE; i++) { vec3 samplePos = kernel[i]; #ifdef NORMALTEX_ENABLED samplePos = kernelBasis * samplePos; #endif samplePos = samplePos * radius + originPos; vec4 texCoord = projection * vec4(samplePos, 1.0); texCoord.xy /= texCoord.w; vec4 depthTexel = texture2D(depthTex, texCoord.xy * 0.5 + 0.5); float sampleDepth = depthTexel.r * 2.0 - 1.0; if (projection[3][3] == 0.0) { sampleDepth = projection[3][2] / (sampleDepth * projection[2][3] - projection[2][2]); } else { sampleDepth = (sampleDepth - projection[3][2]) / projection[2][2]; } float rangeCheck = smoothstep(0.0, 1.0, radius / abs(originPos.z - sampleDepth)); occlusion += rangeCheck * step(samplePos.z, sampleDepth - bias); } #ifdef NORMALTEX_ENABLED occlusion = 1.0 - occlusion / float(KERNEL_SIZE); #else occlusion = 1.0 - clamp((occlusion / float(KERNEL_SIZE) - 0.6) * 2.5, 0.0, 1.0); #endif return pow(occlusion, power); } void main() { vec4 depthTexel = texture2D(depthTex, v_Texcoord); #ifdef NORMALTEX_ENABLED vec4 tex = texture2D(normalTex, v_Texcoord); if (dot(tex.rgb, tex.rgb) == 0.0) { gl_FragColor = vec4(1.0); return; } vec3 N = tex.rgb * 2.0 - 1.0; N = (viewInverseTranspose * vec4(N, 0.0)).xyz; vec2 noiseTexCoord = depthTexSize / vec2(noiseTexSize) * v_Texcoord; vec3 rvec = texture2D(noiseTex, noiseTexCoord).rgb * 2.0 - 1.0; vec3 T = normalize(rvec - N * dot(rvec, N)); vec3 BT = normalize(cross(N, T)); mat3 kernelBasis = mat3(T, BT, N); #else if (depthTexel.r > 0.99999) { gl_FragColor = vec4(1.0); return; } mat3 kernelBasis; #endif float z = depthTexel.r * 2.0 - 1.0; vec4 projectedPos = vec4(v_Texcoord * 2.0 - 1.0, z, 1.0); vec4 p4 = projectionInv * projectedPos; vec3 position = p4.xyz / p4.w; float ao = ssaoEstimator(position, kernelBasis); ao = clamp(1.0 - (1.0 - ao) * intensity, 0.0, 1.0); gl_FragColor = vec4(vec3(ao), 1.0); } @end @export ecgl.ssao.blur #define SHADER_NAME SSAO_BLUR uniform sampler2D ssaoTexture; #ifdef NORMALTEX_ENABLED uniform sampler2D normalTex; #endif varying vec2 v_Texcoord; uniform vec2 textureSize; uniform float blurSize : 1.0; uniform int direction: 0.0; #ifdef DEPTHTEX_ENABLED uniform sampler2D depthTex; uniform mat4 projection; uniform float depthRange : 0.5; float getLinearDepth(vec2 coord) { float depth = texture2D(depthTex, coord).r * 2.0 - 1.0; return projection[3][2] / (depth * projection[2][3] - projection[2][2]); } #endif void main() { float kernel[5]; kernel[0] = 0.122581; kernel[1] = 0.233062; kernel[2] = 0.288713; kernel[3] = 0.233062; kernel[4] = 0.122581; vec2 off = vec2(0.0); if (direction == 0) { off[0] = blurSize / textureSize.x; } else { off[1] = blurSize / textureSize.y; } vec2 coord = v_Texcoord; float sum = 0.0; float weightAll = 0.0; #ifdef NORMALTEX_ENABLED vec3 centerNormal = texture2D(normalTex, v_Texcoord).rgb * 2.0 - 1.0; #endif #if defined(DEPTHTEX_ENABLED) float centerDepth = getLinearDepth(v_Texcoord); #endif for (int i = 0; i < 5; i++) { vec2 coord = clamp(v_Texcoord + vec2(float(i) - 2.0) * off, vec2(0.0), vec2(1.0)); float w = kernel[i]; #ifdef NORMALTEX_ENABLED vec3 normal = texture2D(normalTex, coord).rgb * 2.0 - 1.0; w *= clamp(dot(normal, centerNormal), 0.0, 1.0); #endif #ifdef DEPTHTEX_ENABLED float d = getLinearDepth(coord); w *= (1.0 - smoothstep(abs(centerDepth - d) / depthRange, 0.0, 1.0)); #endif weightAll += w; sum += texture2D(ssaoTexture, coord).r * w; } gl_FragColor = vec4(vec3(sum / weightAll), 1.0); } @end `;N.import(yc);function Js(e){for(var t=new Uint8Array(e*e*4),r=0,i=new U,n=0;n 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0); vec3 tangentX = normalize(cross(N, upVector)); vec3 tangentZ = cross(N, tangentX); return normalize(tangentX * H.x + N * H.y + tangentZ * H.z); } vec3 importanceSampleNormalGGX(float i, float roughness, vec3 N) { float p = fract((i + sampleOffset) / float(TOTAL_SAMPLES)); vec3 H = texture2D(normalDistribution,vec2(roughness, p)).rgb; return transformNormal(H, N); } float G_Smith(float g, float ndv, float ndl) { float roughness = 1.0 - g; float k = roughness * roughness / 2.0; float G1V = ndv / (ndv * (1.0 - k) + k); float G1L = ndl / (ndl * (1.0 - k) + k); return G1L * G1V; } vec3 F_Schlick(float ndv, vec3 spec) { return spec + (1.0 - spec) * pow(1.0 - ndv, 5.0); } #endif float fetchDepth(sampler2D depthTexture, vec2 uv) { vec4 depthTexel = texture2D(depthTexture, uv); return depthTexel.r * 2.0 - 1.0; } float linearDepth(float depth) { if (projection[3][3] == 0.0) { return projection[3][2] / (depth * projection[2][3] - projection[2][2]); } else { return (depth - projection[3][2]) / projection[2][2]; } } bool rayIntersectDepth(float rayZNear, float rayZFar, vec2 hitPixel) { if (rayZFar > rayZNear) { float t = rayZFar; rayZFar = rayZNear; rayZNear = t; } float cameraZ = linearDepth(fetchDepth(gBufferTexture2, hitPixel)); return rayZFar <= cameraZ && rayZNear >= cameraZ - zThicknessThreshold; } bool traceScreenSpaceRay( vec3 rayOrigin, vec3 rayDir, float jitter, out vec2 hitPixel, out vec3 hitPoint, out float iterationCount ) { float rayLength = ((rayOrigin.z + rayDir.z * maxRayDistance) > -nearZ) ? (-nearZ - rayOrigin.z) / rayDir.z : maxRayDistance; vec3 rayEnd = rayOrigin + rayDir * rayLength; vec4 H0 = projection * vec4(rayOrigin, 1.0); vec4 H1 = projection * vec4(rayEnd, 1.0); float k0 = 1.0 / H0.w, k1 = 1.0 / H1.w; vec3 Q0 = rayOrigin * k0, Q1 = rayEnd * k1; vec2 P0 = (H0.xy * k0 * 0.5 + 0.5) * viewportSize; vec2 P1 = (H1.xy * k1 * 0.5 + 0.5) * viewportSize; P1 += dot(P1 - P0, P1 - P0) < 0.0001 ? 0.01 : 0.0; vec2 delta = P1 - P0; bool permute = false; if (abs(delta.x) < abs(delta.y)) { permute = true; delta = delta.yx; P0 = P0.yx; P1 = P1.yx; } float stepDir = sign(delta.x); float invdx = stepDir / delta.x; vec3 dQ = (Q1 - Q0) * invdx; float dk = (k1 - k0) * invdx; vec2 dP = vec2(stepDir, delta.y * invdx); float strideScaler = 1.0 - min(1.0, -rayOrigin.z / pixelStrideZCutoff); float pixStride = 1.0 + strideScaler * pixelStride; dP *= pixStride; dQ *= pixStride; dk *= pixStride; vec4 pqk = vec4(P0, Q0.z, k0); vec4 dPQK = vec4(dP, dQ.z, dk); pqk += dPQK * jitter; float rayZFar = (dPQK.z * 0.5 + pqk.z) / (dPQK.w * 0.5 + pqk.w); float rayZNear; bool intersect = false; vec2 texelSize = 1.0 / viewportSize; iterationCount = 0.0; for (int i = 0; i < MAX_ITERATION; i++) { pqk += dPQK; rayZNear = rayZFar; rayZFar = (dPQK.z * 0.5 + pqk.z) / (dPQK.w * 0.5 + pqk.w); hitPixel = permute ? pqk.yx : pqk.xy; hitPixel *= texelSize; intersect = rayIntersectDepth(rayZNear, rayZFar, hitPixel); iterationCount += 1.0; dPQK *= 1.2; if (intersect) { break; } } Q0.xy += dQ.xy * iterationCount; Q0.z = pqk.z; hitPoint = Q0 / pqk.w; return intersect; } float calculateAlpha( float iterationCount, float reflectivity, vec2 hitPixel, vec3 hitPoint, float dist, vec3 rayDir ) { float alpha = clamp(reflectivity, 0.0, 1.0); alpha *= 1.0 - (iterationCount / float(MAX_ITERATION)); vec2 hitPixelNDC = hitPixel * 2.0 - 1.0; float maxDimension = min(1.0, max(abs(hitPixelNDC.x), abs(hitPixelNDC.y))); alpha *= 1.0 - max(0.0, maxDimension - screenEdgeFadeStart) / (1.0 - screenEdgeFadeStart); float _eyeFadeStart = eyeFadeStart; float _eyeFadeEnd = eyeFadeEnd; if (_eyeFadeStart > _eyeFadeEnd) { float tmp = _eyeFadeEnd; _eyeFadeEnd = _eyeFadeStart; _eyeFadeStart = tmp; } float eyeDir = clamp(rayDir.z, _eyeFadeStart, _eyeFadeEnd); alpha *= 1.0 - (eyeDir - _eyeFadeStart) / (_eyeFadeEnd - _eyeFadeStart); alpha *= 1.0 - clamp(dist / maxRayDistance, 0.0, 1.0); return alpha; } @import clay.util.rand @import clay.util.rgbm void main() { vec4 normalAndGloss = texture2D(gBufferTexture1, v_Texcoord); if (dot(normalAndGloss.rgb, vec3(1.0)) == 0.0) { discard; } float g = normalAndGloss.a; #if !defined(PHYSICALLY_CORRECT) if (g <= minGlossiness) { discard; } #endif float reflectivity = (g - minGlossiness) / (1.0 - minGlossiness); vec3 N = normalize(normalAndGloss.rgb * 2.0 - 1.0); N = normalize((toViewSpace * vec4(N, 0.0)).xyz); vec4 projectedPos = vec4(v_Texcoord * 2.0 - 1.0, fetchDepth(gBufferTexture2, v_Texcoord), 1.0); vec4 pos = projectionInv * projectedPos; vec3 rayOrigin = pos.xyz / pos.w; vec3 V = -normalize(rayOrigin); float ndv = clamp(dot(N, V), 0.0, 1.0); float iterationCount; float jitter = rand(fract(v_Texcoord + jitterOffset)); #ifdef PHYSICALLY_CORRECT vec4 color = vec4(vec3(0.0), 1.0); vec4 albedoMetalness = texture2D(gBufferTexture3, v_Texcoord); vec3 albedo = albedoMetalness.rgb; float m = albedoMetalness.a; vec3 diffuseColor = albedo * (1.0 - m); vec3 spec = mix(vec3(0.04), albedo, m); float jitter2 = rand(fract(v_Texcoord)) * float(TOTAL_SAMPLES); for (int i = 0; i < SAMPLE_PER_FRAME; i++) { vec3 H = importanceSampleNormalGGX(float(i) + jitter2, 1.0 - g, N); vec3 rayDir = normalize(reflect(-V, H)); #else vec3 rayDir = normalize(reflect(-V, N)); #endif vec2 hitPixel; vec3 hitPoint; bool intersect = traceScreenSpaceRay(rayOrigin, rayDir, jitter, hitPixel, hitPoint, iterationCount); float dist = distance(rayOrigin, hitPoint); vec3 hitNormal = texture2D(gBufferTexture1, hitPixel).rgb * 2.0 - 1.0; hitNormal = normalize((toViewSpace * vec4(hitNormal, 0.0)).xyz); #ifdef PHYSICALLY_CORRECT float ndl = clamp(dot(N, rayDir), 0.0, 1.0); float vdh = clamp(dot(V, H), 0.0, 1.0); float ndh = clamp(dot(N, H), 0.0, 1.0); vec3 litTexel = vec3(0.0); if (dot(hitNormal, rayDir) < 0.0 && intersect) { litTexel = texture2D(sourceTexture, hitPixel).rgb; litTexel *= pow(clamp(1.0 - dist / 200.0, 0.0, 1.0), 3.0); } else { #ifdef SPECULARCUBEMAP_ENABLED vec3 rayDirW = normalize(toWorldSpace * vec4(rayDir, 0.0)).rgb; litTexel = RGBMDecode(textureCubeLodEXT(specularCubemap, rayDirW, 0.0), 8.12).rgb * specularIntensity; #endif } color.rgb += ndl * litTexel * ( F_Schlick(ndl, spec) * G_Smith(g, ndv, ndl) * vdh / (ndh * ndv + 0.001) ); } color.rgb /= float(SAMPLE_PER_FRAME); #else #if !defined(SPECULARCUBEMAP_ENABLED) if (dot(hitNormal, rayDir) >= 0.0) { discard; } if (!intersect) { discard; } #endif float alpha = clamp(calculateAlpha(iterationCount, reflectivity, hitPixel, hitPoint, dist, rayDir), 0.0, 1.0); vec4 color = texture2D(sourceTexture, hitPixel); color.rgb *= alpha; #ifdef SPECULARCUBEMAP_ENABLED vec3 rayDirW = normalize(toWorldSpace * vec4(rayDir, 0.0)).rgb; alpha = alpha * (intersect ? 1.0 : 0.0); float bias = (1.0 -g) * 5.0; color.rgb += (1.0 - alpha) * RGBMDecode(textureCubeLodEXT(specularCubemap, rayDirW, bias), 8.12).rgb * specularIntensity; #endif #endif gl_FragColor = encodeHDR(color); } @end @export ecgl.ssr.blur uniform sampler2D texture; uniform sampler2D gBufferTexture1; uniform sampler2D gBufferTexture2; uniform mat4 projection; uniform float depthRange : 0.05; varying vec2 v_Texcoord; uniform vec2 textureSize; uniform float blurSize : 1.0; #ifdef BLEND #ifdef SSAOTEX_ENABLED uniform sampler2D ssaoTex; #endif uniform sampler2D sourceTexture; #endif float getLinearDepth(vec2 coord) { float depth = texture2D(gBufferTexture2, coord).r * 2.0 - 1.0; return projection[3][2] / (depth * projection[2][3] - projection[2][2]); } @import clay.util.rgbm void main() { @import clay.compositor.kernel.gaussian_9 vec4 centerNTexel = texture2D(gBufferTexture1, v_Texcoord); float g = centerNTexel.a; float maxBlurSize = clamp(1.0 - g, 0.0, 1.0) * blurSize; #ifdef VERTICAL vec2 off = vec2(0.0, maxBlurSize / textureSize.y); #else vec2 off = vec2(maxBlurSize / textureSize.x, 0.0); #endif vec2 coord = v_Texcoord; vec4 sum = vec4(0.0); float weightAll = 0.0; vec3 cN = centerNTexel.rgb * 2.0 - 1.0; float cD = getLinearDepth(v_Texcoord); for (int i = 0; i < 9; i++) { vec2 coord = clamp((float(i) - 4.0) * off + v_Texcoord, vec2(0.0), vec2(1.0)); float w = gaussianKernel[i] * clamp(dot(cN, texture2D(gBufferTexture1, coord).rgb * 2.0 - 1.0), 0.0, 1.0); float d = getLinearDepth(coord); w *= (1.0 - smoothstep(abs(cD - d) / depthRange, 0.0, 1.0)); weightAll += w; sum += decodeHDR(texture2D(texture, coord)) * w; } #ifdef BLEND float aoFactor = 1.0; #ifdef SSAOTEX_ENABLED aoFactor = texture2D(ssaoTex, v_Texcoord).r; #endif gl_FragColor = encodeHDR( sum / weightAll * aoFactor + decodeHDR(texture2D(sourceTexture, v_Texcoord)) ); #else gl_FragColor = encodeHDR(sum / weightAll); #endif } @end`;N.import(Tc);function Ut(e){e=e||{},this._ssrPass=new Re({fragment:N.source("ecgl.ssr.main"),clearColor:[0,0,0,0]}),this._blurPass1=new Re({fragment:N.source("ecgl.ssr.blur"),clearColor:[0,0,0,0]}),this._blurPass2=new Re({fragment:N.source("ecgl.ssr.blur"),clearColor:[0,0,0,0]}),this._blendPass=new Re({fragment:N.source("clay.compositor.blend")}),this._blendPass.material.disableTexturesAll(),this._blendPass.material.enableTexture(["texture1","texture2"]),this._ssrPass.setUniform("gBufferTexture1",e.normalTexture),this._ssrPass.setUniform("gBufferTexture2",e.depthTexture),this._blurPass1.setUniform("gBufferTexture1",e.normalTexture),this._blurPass1.setUniform("gBufferTexture2",e.depthTexture),this._blurPass2.setUniform("gBufferTexture1",e.normalTexture),this._blurPass2.setUniform("gBufferTexture2",e.depthTexture),this._blurPass2.material.define("fragment","VERTICAL"),this._blurPass2.material.define("fragment","BLEND"),this._ssrTexture=new $({type:W.HALF_FLOAT}),this._texture2=new $({type:W.HALF_FLOAT}),this._texture3=new $({type:W.HALF_FLOAT}),this._prevTexture=new $({type:W.HALF_FLOAT}),this._currentTexture=new $({type:W.HALF_FLOAT}),this._frameBuffer=new qe({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}Ut.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")};Ut.prototype.update=function(e,t,r,i){var n=e.getWidth(),a=e.getHeight(),o=this._ssrTexture,s=this._texture2,l=this._texture3;o.width=this._prevTexture.width=this._currentTexture.width=n/this._downScale,o.height=this._prevTexture.height=this._currentTexture.height=a/this._downScale,s.width=l.width=n,s.height=l.height=a;var h=this._frameBuffer,u=this._ssrPass,f=this._blurPass1,d=this._blurPass2,c=this._blendPass,v=new k,p=new k;k.transpose(v,t.worldTransform),k.transpose(p,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",p.array),u.setUniform("nearZ",t.near);var m=i/this._totalSamples*this._samplePerFrame;if(u.setUniform("jitterOffset",m),u.setUniform("sampleOffset",i*this._samplePerFrame),f.setUniform("textureSize",[o.width,o.height]),d.setUniform("textureSize",[n,a]),d.setUniform("sourceTexture",r),f.setUniform("projection",t.projectionMatrix.array),d.setUniform("projection",t.projectionMatrix.array),h.attach(o),h.bind(e),u.render(e),this._physicallyCorrect&&(h.attach(this._currentTexture),c.setUniform("texture1",this._prevTexture),c.setUniform("texture2",o),c.material.set({weight1:i>=1?.95:0,weight2:i>=1?.05:1}),c.render(e)),h.attach(s),f.setUniform("texture",this._physicallyCorrect?this._currentTexture:o),f.render(e),h.attach(l),d.setUniform("texture",s),d.render(e),h.unbind(e),this._physicallyCorrect){var g=this._prevTexture;this._prevTexture=this._currentTexture,this._currentTexture=g}};Ut.prototype.getTargetTexture=function(){return this._texture3};Ut.prototype.setParameter=function(e,t){e==="maxIteration"?this._ssrPass.material.define("fragment","MAX_ITERATION",t):this._ssrPass.setUniform(e,t)};Ut.prototype.setPhysicallyCorrect=function(e){e?(this._normalDistribution||(this._normalDistribution=$i.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};Ut.prototype.setSSAOTexture=function(e){var t=this._blurPass2;e?(t.material.enableTexture("ssaoTex"),t.material.set("ssaoTex",e)):t.material.disableTexture("ssaoTex")};Ut.prototype.isFinished=function(e){return this._physicallyCorrect?e>this._totalSamples/this._samplePerFrame:!0};Ut.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 Bo=[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],wc=`@export ecgl.normal.vertex @import ecgl.common.transformUniforms @import ecgl.common.uv.header @import ecgl.common.attributes varying vec3 v_Normal; varying vec3 v_WorldPosition; @import ecgl.common.normalMap.vertexHeader @import ecgl.common.vertexAnimation.header void main() { @import ecgl.common.vertexAnimation.main @import ecgl.common.uv.main v_Normal = normalize((worldInverseTranspose * vec4(normal, 0.0)).xyz); v_WorldPosition = (world * vec4(pos, 1.0)).xyz; @import ecgl.common.normalMap.vertexMain gl_Position = worldViewProjection * vec4(pos, 1.0); } @end @export ecgl.normal.fragment #define ROUGHNESS_CHANEL 0 uniform bool useBumpMap; uniform bool useRoughnessMap; uniform bool doubleSide; uniform float roughness; @import ecgl.common.uv.fragmentHeader varying vec3 v_Normal; varying vec3 v_WorldPosition; uniform mat4 viewInverse : VIEWINVERSE; @import ecgl.common.normalMap.fragmentHeader @import ecgl.common.bumpMap.header uniform sampler2D roughnessMap; void main() { vec3 N = v_Normal; bool flipNormal = false; if (doubleSide) { vec3 eyePos = viewInverse[3].xyz; vec3 V = normalize(eyePos - v_WorldPosition); if (dot(N, V) < 0.0) { flipNormal = true; } } @import ecgl.common.normalMap.fragmentMain if (useBumpMap) { N = bumpNormal(v_WorldPosition, v_Normal, N); } float g = 1.0 - roughness; if (useRoughnessMap) { float g2 = 1.0 - texture2D(roughnessMap, v_DetailTexcoord)[ROUGHNESS_CHANEL]; g = clamp(g2 + (g - 0.5) * 2.0, 0.0, 1.0); } if (flipNormal) { N = -N; } gl_FragColor.rgb = (N.xyz + 1.0) * 0.5; gl_FragColor.a = g; } @end`;N.import(wc);function qn(e,t,r,i,n){var a=e.gl;t.setUniform(a,"1i",r,n),a.activeTexture(a.TEXTURE0+n),i.isRenderable()?i.bind(e):i.unbind(e)}function Sc(e,t,r,i,n){var a,o,s,l,h=e.gl;return function(u,f,d){if(!(l&&l.material===u.material)){var c=u.material,v=u.__program,p=c.get("roughness");p==null&&(p=1);var m=c.get("normalMap")||t,g=c.get("roughnessMap"),x=c.get("bumpMap"),y=c.get("uvRepeat"),_=c.get("uvOffset"),w=c.get("detailUvRepeat"),S=c.get("detailUvOffset"),b=!!x&&c.isTextureEnabled("bumpMap"),A=!!g&&c.isTextureEnabled("roughnessMap"),C=c.isDefined("fragment","DOUBLE_SIDED");x=x||r,g=g||i,d!==f?(f.set("normalMap",m),f.set("bumpMap",x),f.set("roughnessMap",g),f.set("useBumpMap",b),f.set("useRoughnessMap",A),f.set("doubleSide",C),y!=null&&f.set("uvRepeat",y),_!=null&&f.set("uvOffset",_),w!=null&&f.set("detailUvRepeat",w),S!=null&&f.set("detailUvOffset",S),f.set("roughness",p)):(v.setUniform(h,"1f","roughness",p),a!==m&&qn(e,v,"normalMap",m,0),o!==x&&x&&qn(e,v,"bumpMap",x,1),s!==g&&g&&qn(e,v,"roughnessMap",g,2),y!=null&&v.setUniform(h,"2f","uvRepeat",y),_!=null&&v.setUniform(h,"2f","uvOffset",_),w!=null&&v.setUniform(h,"2f","detailUvRepeat",w),S!=null&&v.setUniform(h,"2f","detailUvOffset",S),v.setUniform(h,"1i","useBumpMap",+b),v.setUniform(h,"1i","useRoughnessMap",+A),v.setUniform(h,"1i","doubleSide",+C)),a=m,o=x,s=g,l=u}}}function Zr(e){this._depthTex=new $({format:W.DEPTH_COMPONENT,type:W.UNSIGNED_INT}),this._normalTex=new $({type:W.HALF_FLOAT}),this._framebuffer=new qe,this._framebuffer.attach(this._normalTex),this._framebuffer.attach(this._depthTex,qe.DEPTH_ATTACHMENT),this._normalMaterial=new gt({shader:new N(N.source("ecgl.normal.vertex"),N.source("ecgl.normal.fragment"))}),this._normalMaterial.enableTexture(["normalMap","bumpMap","roughnessMap"]),this._defaultNormalMap=fr.createBlank("#000"),this._defaultBumpMap=fr.createBlank("#000"),this._defaultRoughessMap=fr.createBlank("#000"),this._debugPass=new Re({fragment:N.source("clay.compositor.output")}),this._debugPass.setUniform("texture",this._normalTex),this._debugPass.material.undefine("fragment","OUTPUT_ALPHA")}Zr.prototype.getDepthTexture=function(){return this._depthTex};Zr.prototype.getNormalTexture=function(){return this._normalTex};Zr.prototype.update=function(e,t,r){var i=e.getWidth(),n=e.getHeight(),a=this._depthTex,o=this._normalTex,s=this._normalMaterial;a.width=i,a.height=n,o.width=i,o.height=n;var l=t.getRenderList(r).opaque;this._framebuffer.bind(e),e.gl.clearColor(0,0,0,0),e.gl.clear(e.gl.COLOR_BUFFER_BIT|e.gl.DEPTH_BUFFER_BIT),e.gl.disable(e.gl.BLEND),e.renderPass(l,r,{getMaterial:function(){return s},ifRender:function(h){return h.renderNormal},beforeRender:Sc(e,this._defaultNormalMap,this._defaultBumpMap,this._defaultRoughessMap,this._normalMaterial),sort:e.opaqueSortCompare}),this._framebuffer.unbind(e)};Zr.prototype.renderDebug=function(e){this._debugPass.render(e)};Zr.prototype.dispose=function(e){this._depthTex.dispose(e),this._normalTex.dispose(e)};function Li(e){e=e||{},this._edgePass=new Re({fragment:N.source("ecgl.edge")}),this._edgePass.setUniform("normalTexture",e.normalTexture),this._edgePass.setUniform("depthTexture",e.depthTexture),this._targetTexture=new $({type:W.HALF_FLOAT}),this._frameBuffer=new qe,this._frameBuffer.attach(this._targetTexture)}Li.prototype.update=function(e,t,r,i){var n=e.getWidth(),a=e.getHeight(),o=this._targetTexture;o.width=n,o.height=a;var s=this._frameBuffer;s.bind(e),this._edgePass.setUniform("projectionInv",t.invProjectionMatrix.array),this._edgePass.setUniform("textureSize",[n,a]),this._edgePass.setUniform("texture",r),this._edgePass.render(e),s.unbind(e)};Li.prototype.getTargetTexture=function(){return this._targetTexture};Li.prototype.setParameter=function(e,t){this._edgePass.setUniform(e,t)};Li.prototype.dispose=function(e){this._targetTexture.dispose(e),this._frameBuffer.dispose(e)};const Ac={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"}}]},Ec=`@export ecgl.dof.coc uniform sampler2D depth; uniform float zNear: 0.1; uniform float zFar: 2000; uniform float focalDistance: 3; uniform float focalRange: 1; uniform float focalLength: 30; uniform float fstop: 2.8; varying vec2 v_Texcoord; @import clay.util.encode_float void main() { float z = texture2D(depth, v_Texcoord).r * 2.0 - 1.0; float dist = 2.0 * zNear * zFar / (zFar + zNear - z * (zFar - zNear)); float aperture = focalLength / fstop; float coc; float uppper = focalDistance + focalRange; float lower = focalDistance - focalRange; if (dist <= uppper && dist >= lower) { coc = 0.5; } else { float focalAdjusted = dist > uppper ? uppper : lower; coc = abs(aperture * (focalLength * (dist - focalAdjusted)) / (dist * (focalAdjusted - focalLength))); coc = clamp(coc, 0.0, 2.0) / 2.00001; if (dist < lower) { coc = -coc; } coc = coc * 0.5 + 0.5; } gl_FragColor = encodeFloat(coc); } @end @export ecgl.dof.composite #define DEBUG 0 uniform sampler2D original; uniform sampler2D blurred; uniform sampler2D nearfield; uniform sampler2D coc; uniform sampler2D nearcoc; varying vec2 v_Texcoord; @import clay.util.rgbm @import clay.util.float void main() { vec4 blurredColor = texture2D(blurred, v_Texcoord); vec4 originalColor = texture2D(original, v_Texcoord); float fCoc = decodeFloat(texture2D(coc, v_Texcoord)); fCoc = abs(fCoc * 2.0 - 1.0); float weight = smoothstep(0.0, 1.0, fCoc); #ifdef NEARFIELD_ENABLED vec4 nearfieldColor = texture2D(nearfield, v_Texcoord); float fNearCoc = decodeFloat(texture2D(nearcoc, v_Texcoord)); fNearCoc = abs(fNearCoc * 2.0 - 1.0); gl_FragColor = encodeHDR( mix( nearfieldColor, mix(originalColor, blurredColor, weight), pow(1.0 - fNearCoc, 4.0) ) ); #else gl_FragColor = encodeHDR(mix(originalColor, blurredColor, weight)); #endif } @end @export ecgl.dof.diskBlur #define POISSON_KERNEL_SIZE 16; uniform sampler2D texture; uniform sampler2D coc; varying vec2 v_Texcoord; uniform float blurRadius : 10.0; uniform vec2 textureSize : [512.0, 512.0]; uniform vec2 poissonKernel[POISSON_KERNEL_SIZE]; uniform float percent; float nrand(const in vec2 n) { return fract(sin(dot(n.xy ,vec2(12.9898,78.233))) * 43758.5453); } @import clay.util.rgbm @import clay.util.float void main() { vec2 offset = blurRadius / textureSize; float rnd = 6.28318 * nrand(v_Texcoord + 0.07 * percent ); float cosa = cos(rnd); float sina = sin(rnd); vec4 basis = vec4(cosa, -sina, sina, cosa); #if !defined(BLUR_NEARFIELD) && !defined(BLUR_COC) offset *= abs(decodeFloat(texture2D(coc, v_Texcoord)) * 2.0 - 1.0); #endif #ifdef BLUR_COC float cocSum = 0.0; #else vec4 color = vec4(0.0); #endif float weightSum = 0.0; for (int i = 0; i < POISSON_KERNEL_SIZE; i++) { vec2 ofs = poissonKernel[i]; ofs = vec2(dot(ofs, basis.xy), dot(ofs, basis.zw)); vec2 uv = v_Texcoord + ofs * offset; vec4 texel = texture2D(texture, uv); float w = 1.0; #ifdef BLUR_COC float fCoc = decodeFloat(texel) * 2.0 - 1.0; cocSum += clamp(fCoc, -1.0, 0.0) * w; #else texel = texel; #if !defined(BLUR_NEARFIELD) float fCoc = decodeFloat(texture2D(coc, uv)) * 2.0 - 1.0; w *= abs(fCoc); #endif texel.rgb *= texel.a; color += texel * w; #endif weightSum += w; } #ifdef BLUR_COC gl_FragColor = encodeFloat(clamp(cocSum / weightSum, -1.0, 0.0) * 0.5 + 0.5); #else color /= weightSum; color.rgb /= (color.a + 0.0001); gl_FragColor = color; #endif } @end`,bc=`@export ecgl.edge uniform sampler2D texture; uniform sampler2D normalTexture; uniform sampler2D depthTexture; uniform mat4 projectionInv; uniform vec2 textureSize; uniform vec4 edgeColor: [0,0,0,0.8]; varying vec2 v_Texcoord; vec3 packColor(vec2 coord) { float z = texture2D(depthTexture, coord).r * 2.0 - 1.0; vec4 p = vec4(v_Texcoord * 2.0 - 1.0, z, 1.0); vec4 p4 = projectionInv * p; return vec3( texture2D(normalTexture, coord).rg, -p4.z / p4.w / 5.0 ); } void main() { vec2 cc = v_Texcoord; vec3 center = packColor(cc); float size = clamp(1.0 - (center.z - 10.0) / 100.0, 0.0, 1.0) * 0.5; float dx = size / textureSize.x; float dy = size / textureSize.y; vec2 coord; vec3 topLeft = packColor(cc+vec2(-dx, -dy)); vec3 top = packColor(cc+vec2(0.0, -dy)); vec3 topRight = packColor(cc+vec2(dx, -dy)); vec3 left = packColor(cc+vec2(-dx, 0.0)); vec3 right = packColor(cc+vec2(dx, 0.0)); vec3 bottomLeft = packColor(cc+vec2(-dx, dy)); vec3 bottom = packColor(cc+vec2(0.0, dy)); vec3 bottomRight = packColor(cc+vec2(dx, dy)); vec3 v = -topLeft-2.0*top-topRight+bottomLeft+2.0*bottom+bottomRight; vec3 h = -bottomLeft-2.0*left-topLeft+bottomRight+2.0*right+topRight; float edge = sqrt(dot(h, h) + dot(v, v)); edge = smoothstep(0.8, 1.0, edge); gl_FragColor = mix(texture2D(texture, v_Texcoord), vec4(edgeColor.rgb, 1.0), edgeColor.a * edge); } @end`;N.import(ks);N.import(Ws);N.import(Xs);N.import(Zs);N.import(js);N.import(qs);N.import(Ys);N.import(Ks);N.import(Qs);N.import(Ec);N.import(bc);function el(e,t){return{color:{parameters:{width:e,height:t}}}}var Ra=["composite","FXAA"];function re(){this._width,this._height,this._dpr,this._sourceTexture=new $({type:W.HALF_FLOAT}),this._depthTexture=new $({format:W.DEPTH_COMPONENT,type:W.UNSIGNED_INT}),this._framebuffer=new qe,this._framebuffer.attach(this._sourceTexture),this._framebuffer.attach(this._depthTexture,qe.DEPTH_ATTACHMENT),this._normalPass=new Zr,this._compositor=cc(Ac);var e=this._compositor.getNodeByName("source");e.texture=this._sourceTexture;var t=this._compositor.getNodeByName("coc");this._sourceNode=e,this._cocNode=t,this._compositeNode=this._compositor.getNodeByName("composite"),this._fxaaNode=this._compositor.getNodeByName("FXAA"),this._dofBlurNodes=["dof_far_blur","dof_near_blur","dof_coc_blur"].map(function(i){return this._compositor.getNodeByName(i)},this),this._dofBlurKernel=0,this._dofBlurKernelSize=new Float32Array(0),this._finalNodesChain=Ra.map(function(i){return this._compositor.getNodeByName(i)},this);var r={normalTexture:this._normalPass.getNormalTexture(),depthTexture:this._normalPass.getDepthTexture()};this._ssaoPass=new Ft(r),this._ssrPass=new Ut(r),this._edgePass=new Li(r)}re.prototype.resize=function(i,n,r){r=r||1;var i=i*r,n=n*r,a=this._sourceTexture,o=this._depthTexture;a.width=i,a.height=n,o.width=i,o.height=n;var s={getWidth:function(){return i},getHeight:function(){return n},getDevicePixelRatio:function(){return r}};function l(h,u){if(typeof h[u]=="function"){var f=h[u].__original||h[u];h[u]=function(d){return f.call(this,s)},h[u].__original=f}}this._compositor.nodes.forEach(function(h){for(var u in h.outputs){var f=h.outputs[u].parameters;f&&(l(f,"width"),l(f,"height"))}for(var d in h.parameters)l(h.parameters,d)}),this._width=i,this._height=n,this._dpr=r};re.prototype.getWidth=function(){return this._width};re.prototype.getHeight=function(){return this._height};re.prototype._ifRenderNormalPass=function(){return this._enableSSAO||this._enableEdge||this._enableSSR};re.prototype._getPrevNode=function(e){for(var t=Ra.indexOf(e.name)-1,r=this._finalNodesChain[t];r&&!this._compositor.getNodeByName(r.name);)t-=1,r=this._finalNodesChain[t];return r};re.prototype._getNextNode=function(e){for(var t=Ra.indexOf(e.name)+1,r=this._finalNodesChain[t];r&&!this._compositor.getNodeByName(r.name);)t+=1,r=this._finalNodesChain[t];return r};re.prototype._addChainNode=function(e){var t=this._getPrevNode(e),r=this._getNextNode(e);!t||(e.inputs.texture=t.name,r?(e.outputs=el(this.getWidth.bind(this),this.getHeight.bind(this)),r.inputs.texture=e.name):e.outputs=null,this._compositor.addNode(e))};re.prototype._removeChainNode=function(e){var t=this._getPrevNode(e),r=this._getNextNode(e);!t||(r?(t.outputs=el(this.getWidth.bind(this),this.getHeight.bind(this)),r.inputs.texture=t.name):t.outputs=null,this._compositor.removeNode(e))};re.prototype.updateNormal=function(e,t,r,i){this._ifRenderNormalPass()&&this._normalPass.update(e,t,r)};re.prototype.updateSSAO=function(e,t,r,i){this._ssaoPass.update(e,r,i)};re.prototype.enableSSAO=function(){this._enableSSAO=!0};re.prototype.disableSSAO=function(){this._enableSSAO=!1};re.prototype.enableSSR=function(){this._enableSSR=!0};re.prototype.disableSSR=function(){this._enableSSR=!1};re.prototype.getSSAOTexture=function(){return this._ssaoPass.getTargetTexture()};re.prototype.getSourceFrameBuffer=function(){return this._framebuffer};re.prototype.getSourceTexture=function(){return this._sourceTexture};re.prototype.disableFXAA=function(){this._removeChainNode(this._fxaaNode)};re.prototype.enableFXAA=function(){this._addChainNode(this._fxaaNode)};re.prototype.enableBloom=function(){this._compositeNode.inputs.bloom="bloom_composite",this._compositor.dirty()};re.prototype.disableBloom=function(){this._compositeNode.inputs.bloom=null,this._compositor.dirty()};re.prototype.enableDOF=function(){this._compositeNode.inputs.texture="dof_composite",this._compositor.dirty()};re.prototype.disableDOF=function(){this._compositeNode.inputs.texture="source",this._compositor.dirty()};re.prototype.enableColorCorrection=function(){this._compositeNode.define("COLOR_CORRECTION"),this._enableColorCorrection=!0};re.prototype.disableColorCorrection=function(){this._compositeNode.undefine("COLOR_CORRECTION"),this._enableColorCorrection=!1};re.prototype.enableEdge=function(){this._enableEdge=!0};re.prototype.disableEdge=function(){this._enableEdge=!1};re.prototype.setBloomIntensity=function(e){this._compositeNode.setParameter("bloomIntensity",e)};re.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;default:console.warn("Unkown SSAO parameter "+e)}};re.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._haltonSequence.length},render:function(e,t,r){var i=this._blendPass;this._frame===0?(i.setUniform("weight1",0),i.setUniform("weight2",1)):(i.setUniform("weight1",.9),i.setUniform("weight2",.1)),i.setUniform("texture1",this._prevFrameTex),i.setUniform("texture2",t||this._sourceTex),this._blendFb.attach(this._outputTex),this._blendFb.bind(e),i.render(e),this._blendFb.unbind(e),r||(this._outputPass.setUniform("texture",this._outputTex),this._outputPass.render(e));var n=this._prevFrameTex;this._prevFrameTex=this._outputTex,this._outputTex=n,this._frame++},dispose:function(e){this._sourceFb.dispose(e),this._blendFb.dispose(e),this._prevFrameTex.dispose(e),this._outputTex.dispose(e),this._sourceTex.dispose(e),this._outputPass.dispose(e),this._blendPass.dispose(e)}};function ce(e){e=e||"perspective",this.layer=null,this.scene=new Qt,this.rootNode=this.scene,this.viewport={x:0,y:0,width:0,height:0},this.setProjection(e),this._compositor=new re,this._temporalSS=new ca,this._shadowMapPass=new Yf;for(var t=[],r=0,i=0;i<30;i++){for(var n=[],a=0;a<6;a++)n.push(Ur(r,2)*4-2),n.push(Ur(r,3)*4-2),r++;t.push(n)}this._pcfKernels=t,this.scene.on("beforerender",function(o,s,l){this.needsTemporalSS()&&this._temporalSS.jitterProjection(o,l)},this)}ce.prototype.setProjection=function(e){var t=this.camera;t&&t.update(),e==="perspective"?this.camera instanceof He||(this.camera=new He,t&&this.camera.setLocalTransform(t.localTransform)):this.camera instanceof Fr||(this.camera=new Fr,t&&this.camera.setLocalTransform(t.localTransform)),this.camera.near=.1,this.camera.far=2e3};ce.prototype.setViewport=function(e,t,r,i,n){this.camera instanceof He&&(this.camera.aspect=r/i),n=n||1,this.viewport.x=e,this.viewport.y=t,this.viewport.width=r,this.viewport.height=i,this.viewport.devicePixelRatio=n,this._compositor.resize(r*n,i*n),this._temporalSS.resize(r*n,i*n)};ce.prototype.containPoint=function(e,t){var r=this.viewport,i=this.layer.renderer.getHeight();return t=i-t,e>=r.x&&t>=r.y&&e<=r.x+r.width&&t<=r.y+r.height};var Fo=new ut;ce.prototype.castRay=function(e,t,r){var i=this.layer.renderer,n=i.viewport;return i.viewport=this.viewport,i.screenToNDC(e,t,Fo),this.camera.castRay(Fo,r),i.viewport=n,r};ce.prototype.prepareRender=function(){this.scene.update(),this.camera.update(),this.scene.updateLights();var e=this.scene.updateRenderList(this.camera);this._needsSortProgressively=!1;for(var t=0;t30};ce.prototype._doRender=function(e,t,r){var i=this.scene,n=this.camera;r=r||0,this._updateTransparent(e,i,n,r),t||(this._shadowMapPass.kernelPCF=this._pcfKernels[0],this._shadowMapPass.render(e,i,n,!0)),this._updateShadowPCFKernel(r);var a=e.clearColor;if(e.gl.clearColor(a[0],a[1],a[2],a[3]),this._enablePostEffect&&(this.needsTemporalSS()&&this._temporalSS.jitterProjection(e,n),this._compositor.updateNormal(e,i,n,this._temporalSS.getFrame())),this._updateSSAO(e,i,n,this._temporalSS.getFrame()),this._enablePostEffect){var o=this._compositor.getSourceFrameBuffer();o.bind(e),e.gl.clear(e.gl.DEPTH_BUFFER_BIT|e.gl.COLOR_BUFFER_BIT),e.render(i,n,!0,!0),o.unbind(e),this.needsTemporalSS()&&t?(this._compositor.composite(e,i,n,this._temporalSS.getSourceFrameBuffer(),this._temporalSS.getFrame()),e.setViewport(this.viewport),this._temporalSS.render(e)):(e.setViewport(this.viewport),this._compositor.composite(e,i,n,null,0))}else if(this.needsTemporalSS()&&t){var o=this._temporalSS.getSourceFrameBuffer();o.bind(e),e.saveClear(),e.clearBit=e.gl.DEPTH_BUFFER_BIT|e.gl.COLOR_BUFFER_BIT,e.render(i,n,!0,!0),e.restoreClear(),o.unbind(e),e.setViewport(this.viewport),this._temporalSS.render(e)}else e.setViewport(this.viewport),e.render(i,n,!0,!0)};ce.prototype._updateTransparent=function(e,t,r,i){for(var n=new U,a=new k,o=r.getWorldPosition(),s=t.getRenderList(r).transparent,l=0;lthis.camera.far||e80*r){s=h=e[0],l=u=e[1];for(var v=r;vh&&(h=f),d>u&&(u=d);c=Math.max(h-s,u-l)}return yi(a,o,r,s,l,c),o}function ol(e,t,r,i,n){var a,o;if(n===pa(e,t,r,i)>0)for(a=t;a=t;a-=i)o=Uo(a,e[a],e[a+1],o);return o&&ur(o,o.next)&&(Ti(o),o=o.next),o}function _i(e,t){if(!e)return e;t||(t=e);var r=e,i;do if(i=!1,!r.steiner&&(ur(r,r.next)||rt(r.prev,r,r.next)===0)){if(Ti(r),r=t=r.prev,r===r.next)return null;i=!0}else r=r.next;while(i||r!==t);return t}function yi(e,t,r,i,n,a,o){if(!!e){!o&&a&&qc(e,i,n,a);for(var s=e,l,h;e.prev!==e.next;){if(l=e.prev,h=e.next,a?Hc(e,i,n,a):zc(e)){t.push(l.i/r),t.push(e.i/r),t.push(h.i/r),Ti(e),e=h.next,s=h.next;continue}if(e=h,e===s){o?o===1?(e=Vc(e,t,r),yi(e,t,r,i,n,a,2)):o===2&&kc(e,t,r,i,n,a):yi(_i(e),t,r,i,n,a,1);break}}}}function zc(e){var t=e.prev,r=e,i=e.next;if(rt(t,r,i)>=0)return!1;for(var n=e.next.next;n!==e.prev;){if(hn(t.x,t.y,r.x,r.y,i.x,i.y,n.x,n.y)&&rt(n.prev,n,n.next)>=0)return!1;n=n.next}return!0}function Hc(e,t,r,i){var n=e.prev,a=e,o=e.next;if(rt(n,a,o)>=0)return!1;for(var s=n.xa.x?n.x>o.x?n.x:o.x:a.x>o.x?a.x:o.x,u=n.y>a.y?n.y>o.y?n.y:o.y:a.y>o.y?a.y:o.y,f=da(s,l,t,r,i),d=da(h,u,t,r,i),c=e.nextZ;c&&c.z<=d;){if(c!==e.prev&&c!==e.next&&hn(n.x,n.y,a.x,a.y,o.x,o.y,c.x,c.y)&&rt(c.prev,c,c.next)>=0)return!1;c=c.nextZ}for(c=e.prevZ;c&&c.z>=f;){if(c!==e.prev&&c!==e.next&&hn(n.x,n.y,a.x,a.y,o.x,o.y,c.x,c.y)&&rt(c.prev,c,c.next)>=0)return!1;c=c.prevZ}return!0}function Vc(e,t,r){var i=e;do{var n=i.prev,a=i.next.next;!ur(n,a)&&sl(n,i,i.next,a)&&xi(n,a)&&xi(a,n)&&(t.push(n.i/r),t.push(i.i/r),t.push(a.i/r),Ti(i),Ti(i.next),i=e=a),i=i.next}while(i!==e);return i}function kc(e,t,r,i,n,a){var o=e;do{for(var s=o.next.next;s!==o.prev;){if(o.i!==s.i&&Qc(o,s)){var l=ll(o,s);o=_i(o,o.next),l=_i(l,l.next),yi(o,t,r,i,n,a),yi(l,t,r,i,n,a);return}s=s.next}o=o.next}while(o!==e)}function Wc(e,t,r,i){var n=[],a,o,s,l,h;for(a=0,o=t.length;a=r.next.y&&r.next.y!==r.y){var s=r.x+(n-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(s<=i&&s>a){if(a=s,s===i){if(n===r.y)return r;if(n===r.next.y)return r.next}o=r.x=r.x&&r.x>=h&&i!==r.x&&hn(no.x)&&xi(r,e)&&(o=r,f=d)),r=r.next;return o}function qc(e,t,r,i){var n=e;do n.z===null&&(n.z=da(n.x,n.y,t,r,i)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next;while(n!==e);n.prevZ.nextZ=null,n.prevZ=null,Yc(n)}function Yc(e){var t,r,i,n,a,o,s,l,h=1;do{for(r=e,e=null,a=null,o=0;r;){for(o++,i=r,s=0,t=0;t0||l>0&&i;)s!==0&&(l===0||!i||r.z<=i.z)?(n=r,r=r.nextZ,s--):(n=i,i=i.nextZ,l--),a?a.nextZ=n:e=n,n.prevZ=a,a=n;r=i}a.nextZ=null,h*=2}while(o>1);return e}function da(e,t,r,i,n){return e=32767*(e-r)/n,t=32767*(t-i)/n,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e|t<<1}function Kc(e){var t=e,r=e;do t.x=0&&(e-o)*(i-s)-(r-o)*(t-s)>=0&&(r-o)*(a-s)-(n-o)*(i-s)>=0}function Qc(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!$c(e,t)&&xi(e,t)&&xi(t,e)&&Jc(e,t)}function rt(e,t,r){return(t.y-e.y)*(r.x-t.x)-(t.x-e.x)*(r.y-t.y)}function ur(e,t){return e.x===t.x&&e.y===t.y}function sl(e,t,r,i){return ur(e,t)&&ur(r,i)||ur(e,i)&&ur(r,t)?!0:rt(e,t,r)>0!=rt(e,t,i)>0&&rt(r,i,e)>0!=rt(r,i,t)>0}function $c(e,t){var r=e;do{if(r.i!==e.i&&r.next.i!==e.i&&r.i!==t.i&&r.next.i!==t.i&&sl(r,r.next,e,t))return!0;r=r.next}while(r!==e);return!1}function xi(e,t){return rt(e.prev,e,e.next)<0?rt(e,t,e.next)>=0&&rt(e,e.prev,t)>=0:rt(e,t,e.prev)<0||rt(e,e.next,t)<0}function Jc(e,t){var r=e,i=!1,n=(e.x+t.x)/2,a=(e.y+t.y)/2;do r.y>a!=r.next.y>a&&r.next.y!==r.y&&n<(r.next.x-r.x)*(a-r.y)/(r.next.y-r.y)+r.x&&(i=!i),r=r.next;while(r!==e);return i}function ll(e,t){var r=new va(e.i,e.x,e.y),i=new va(t.i,t.x,t.y),n=e.next,a=t.prev;return e.next=t,t.prev=e,r.next=n,n.prev=r,i.next=r,r.prev=i,a.next=i,i.prev=a,i}function Uo(e,t,r,i){var n=new va(e,t,r);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function Ti(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function va(e,t,r){this.i=e,this.x=t,this.y=r,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}al.deviation=function(e,t,r,i){var n=t&&t.length,a=n?t[0]*r:e.length,o=Math.abs(pa(e,0,a,r));if(n)for(var s=0,l=t.length;sl&&s.push({pivot:Math.floor((h+l)/2),left:l,right:h});var l=a[o].pivot+1,h=a[o].right;h>l&&s.push({pivot:Math.floor((h+l)/2),left:l,right:h})}a=this._parts=s}else for(var o=0;o=2e4},doSortTriangles:function(e,t){var r=this.indices;if(t===0){var i=this.attributes.position,e=e.array;(!this._triangleZList||this._triangleZList.length!==this.triangleCount)&&(this._triangleZList=new Float32Array(this.triangleCount),this._sortedTriangleIndices=new Uint32Array(this.triangleCount),this._indicesTmp=new r.constructor(r.length),this._triangleZListTmp=new Float32Array(this.triangleCount));for(var n=0,a,o=0;o0,r={},i=0;i65535?new Uint32Array(o*3):new Uint16Array(o*3),d.material.shader!==t&&d.material.attachShader(t,!0),T.setMaterialFromModel(t.__shading,d.material,e,r),s>0&&(this._linesMesh.geometry.resetOffset(),this._linesMesh.geometry.setVertexCount(s),this._linesMesh.geometry.setTriangleCount(l)),this._dataIndexOfVertex=new Uint32Array(a),this._vertexRangeOfDataIndex=new Uint32Array((n-i)*2)},_updateRegionMesh:function(e,t,r,i){for(var n=e.getData(),a=0,o=0,s=!1,S=this._polygonMesh,l=this._linesMesh,h=r;h0;w&&(_*=t.getDevicePixelRatio(),this._updateLinesGeometry(l.geometry,e,h,g,_,e.coordinateSystem.transform)),l.invisible=!w,l.material.set({color:p})}var S=this._polygonMesh;S.material.transparent=s,S.material.depthMask=!s,S.geometry.updateBoundingBox(),S.frontFace=this.extrudeY?T.Mesh.CCW:T.Mesh.CW,S.material.get("normalMap")&&S.geometry.generateTangents(),S.seriesIndex=e.seriesIndex,S.on("mousemove",this._onmousemove,this),S.on("mouseout",this._onmouseout,this)},_updateDebugWireframe:function(e){var t=e.getModel("debug.wireframe");if(t.get("show")){var r=T.parseColor(t.get("lineStyle.color")||"rgba(0,0,0,0.5)"),i=K.firstNotNull(t.get("lineStyle.width"),1),n=this._polygonMesh;n.geometry.generateBarycentric(),n.material.define("both","WIREFRAME_TRIANGLE"),n.material.set("wireframeLineColor",r),n.material.set("wireframeLineWidth",i)}},_onmousemove:function(e){var t=this._dataIndexOfVertex[e.triangle[0]];t==null&&(t=-1),t!==this._lastHoverDataIndex&&(this.downplay(this._lastHoverDataIndex),this.highlight(t),this._labelsBuilder.updateLabels([t])),this._lastHoverDataIndex=t,this._polygonMesh.dataIndex=t},_onmouseout:function(e){e.target&&(this.downplay(this._lastHoverDataIndex),this._lastHoverDataIndex=-1,this._polygonMesh.dataIndex=-1),this._labelsBuilder.updateLabels([])},_updateGroundPlane:function(e,t,r){var i=e.getModel("groundPlane",e);if(this._groundMesh.invisible=!i.get("show",!0),!this._groundMesh.invisible){var n=e.get("shading"),a=this._groundMaterials[n];a||(console.warn("Unkown shading "+n),a=this._groundMaterials.lambert),T.setMaterialFromModel(n,a,i,r),a.get("normalMap")&&this._groundMesh.geometry.generateTangents(),this._groundMesh.material=a,this._groundMesh.material.set("color",T.parseColor(i.get("color"))),this._groundMesh.scale.set(t.size[0],t.size[2],1)}},_triangulation:function(e,t,r){this._triangulationResults=[];for(var i=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0],a=e.coordinateSystem,o=t;o1?i:0,O[te][m]=L.points[Se+2],l.set(n+te,O[te]),s?(le[0]=(L.points[Se]*g[0]-x[0])/_,le[1]=(L.points[Se+2]*g[m]-x[m])/_):(le[0]=(Ne?H:H+_e)/_,le[1]=(O[te][p]*g[p]-x[p])/_),u.set(n+te,le)}ot.sub(z,O[1],O[0]),ot.sub(V,O[3],O[0]),ot.cross(F,z,V),ot.normalize(F,F);for(var te=0;te<4;te++)h.set(n+te,F),c&&f.set(n+te,o);for(var te=0;te<6;te++)v[a*3+te]=D[te]+n;n+=4,a+=2,H+=_e}}return t.dirty(),{vertexOffset:n,triangleOffset:a}},_getRegionLinesInfo:function(e,t,r){var i=0,n=0,a=t.getRegionModel(e),o=a.getModel("itemStyle"),s=o.get("borderWidth");if(s>0){var l=t.getRegionPolygonCoords(e);l.forEach(function(h){var u=h.exterior,f=h.interiors;i+=r.getPolylineVertexCount(u),n+=r.getPolylineTriangleCount(u);for(var d=0;dthis._endIndex)){t-=this._startIndex;for(var i=this._vertexRangeOfDataIndex[t*2];i0},_displacementChanged:!0,_displacementScale:0,updateDisplacementHash:function(){var e=this.getDisplacementTexture(),t=this.getDisplacemenScale();this._displacementChanged=this._displacementTexture!==e||this._displacementScale!==t,this._displacementTexture=e,this._displacementScale=t},isDisplacementChanged:function(){return this._displacementChanged}});fe(dr.prototype,xn);fe(dr.prototype,Wr);fe(dr.prototype,Xr);fe(dr.prototype,jr);const hd=dr;var pl=Math.PI,_t=Math.sin,Ot=Math.cos,ml=Math.tan,gl=Math.asin,_l=Math.atan2,vr=pl/180,ud=1e3*60*60*24,fd=2440588,cd=2451545;function dd(e){return e.valueOf()/ud-.5+fd}function vd(e){return dd(e)-cd}var cn=vr*23.4397;function pd(e,t){return _l(_t(e)*Ot(cn)-ml(t)*_t(cn),Ot(e))}function md(e,t){return gl(_t(t)*Ot(cn)+Ot(t)*_t(cn)*_t(e))}function gd(e,t,r){return _l(_t(e),Ot(e)*_t(t)-ml(r)*Ot(t))}function _d(e,t,r){return gl(_t(t)*_t(r)+Ot(t)*Ot(r)*Ot(e))}function yd(e,t){return vr*(280.16+360.9856235*e)-t}function xd(e){return vr*(357.5291+.98560028*e)}function Td(e){var t=vr*(1.9148*_t(e)+.02*_t(2*e)+3e-4*_t(3*e)),r=vr*102.9372;return e+t+r+pl}function wd(e){var t=xd(e),r=Td(t);return{dec:md(r,0),ra:pd(r,0)}}var yl={};yl.getPosition=function(e,t,r){var i=vr*-r,n=vr*t,a=vd(e),o=wd(a),s=yd(a,i)-o.ra;return{azimuth:gd(s,n,o.dec),altitude:_d(s,n,o.dec)}};const Sd=yl,Ad=`@export ecgl.atmosphere.vertex attribute vec3 position: POSITION; attribute vec3 normal : NORMAL; uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; uniform mat4 normalMatrix : WORLDINVERSETRANSPOSE; varying vec3 v_Normal; void main() { v_Normal = normalize((normalMatrix * vec4(normal, 0.0)).xyz); gl_Position = worldViewProjection * vec4(position, 1.0); } @end @export ecgl.atmosphere.fragment uniform mat4 viewTranspose: VIEWTRANSPOSE; uniform float glowPower; uniform vec3 glowColor; varying vec3 v_Normal; void main() { float intensity = pow(1.0 - dot(v_Normal, (viewTranspose * vec4(0.0, 0.0, 1.0, 0.0)).xyz), glowPower); gl_FragColor = vec4(glowColor, intensity * intensity); } @end`;T.Shader.import(Rs);T.Shader.import(Ad);const Ed=Ai.extend({type:"globe",__ecgl__:!0,_displacementScale:0,init:function(e,t){this.groupGL=new T.Node,this._sphereGeometry=new T.SphereGeometry({widthSegments:200,heightSegments:100,dynamic:!0}),this._overlayGeometry=new T.SphereGeometry({widthSegments:80,heightSegments:40}),this._planeGeometry=new T.PlaneGeometry,this._earthMesh=new T.Mesh({renderNormal:!0}),this._atmosphereMesh=new T.Mesh,this._atmosphereGeometry=new T.SphereGeometry({widthSegments:80,heightSegments:40}),this._atmosphereMaterial=new T.Material({shader:new T.Shader(T.Shader.source("ecgl.atmosphere.vertex"),T.Shader.source("ecgl.atmosphere.fragment")),transparent:!0}),this._atmosphereMesh.geometry=this._atmosphereGeometry,this._atmosphereMesh.material=this._atmosphereMaterial,this._atmosphereMesh.frontFace=T.Mesh.CW,this._lightRoot=new T.Node,this._sceneHelper=new Yt,this._sceneHelper.initLight(this._lightRoot),this.groupGL.add(this._atmosphereMesh),this.groupGL.add(this._earthMesh),this._control=new wn({zr:t.getZr()}),this._control.init(),this._layerMeshes={}},render:function(e,t,r){var i=e.coordinateSystem,n=e.get("shading");i.viewGL.add(this._lightRoot),e.get("show")?i.viewGL.add(this.groupGL):i.viewGL.remove(this.groupGL),this._sceneHelper.setScene(i.viewGL.scene),i.viewGL.setPostEffect(e.getModel("postEffect"),r),i.viewGL.setTemporalSuperSampling(e.getModel("temporalSuperSampling"));var a=this._earthMesh;a.geometry=this._sphereGeometry;var o="ecgl."+n;(!a.material||a.material.shader.name!==o)&&(a.material=T.createMaterial(o)),T.setMaterialFromModel(n,a.material,e,r),["roughnessMap","metalnessMap","detailMap","normalMap"].forEach(function(f){var d=a.material.get(f);d&&(d.flipY=!1)}),a.material.set("color",T.parseColor(e.get("baseColor")));var s=i.radius*.99;if(a.scale.set(s,s,s),e.get("atmosphere.show")){a.material.define("both","ATMOSPHERE_ENABLED"),this._atmosphereMesh.invisible=!1,this._atmosphereMaterial.setUniforms({glowPower:e.get("atmosphere.glowPower")||6,glowColor:e.get("atmosphere.color")||"#ffffff"}),a.material.setUniforms({glowPower:e.get("atmosphere.innerGlowPower")||2,glowColor:e.get("atmosphere.color")||"#ffffff"});var l=e.get("atmosphere.offset")||5;this._atmosphereMesh.scale.set(s+l,s+l,s+l)}else a.material.undefine("both","ATMOSPHERE_ENABLED"),this._atmosphereMesh.invisible=!0;var h=a.material.setTextureImage("diffuseMap",e.get("baseTexture"),r,{flipY:!1,anisotropic:8});h&&h.surface&&h.surface.attachToMesh(a);var u=a.material.setTextureImage("bumpMap",e.get("heightTexture"),r,{flipY:!1,anisotropic:8});u&&u.surface&&u.surface.attachToMesh(a),a.material[e.get("postEffect.enable")?"define":"undefine"]("fragment","SRGB_DECODE"),this._updateLight(e,r),this._displaceVertices(e,r),this._updateViewControl(e,r),this._updateLayers(e,r)},afterRender:function(e,t,r,i){var n=i.renderer;this._sceneHelper.updateAmbientCubemap(n,e,r),this._sceneHelper.updateSkybox(n,e,r)},_updateLayers:function(e,t){var r=e.coordinateSystem,i=e.get("layers"),n=r.radius,a=[],o=[],s=[],l=[];Dt(i,function(c){var v=new Nr(c),p=v.get("type"),m=T.loadTexture(v.get("texture"),t,{flipY:!1,anisotropic:8});if(m.surface&&m.surface.attachToMesh(this._earthMesh),p==="blend"){var g=v.get("blendTo"),x=K.firstNotNull(v.get("intensity"),1);g==="emission"?(s.push(m),l.push(x)):(a.push(m),o.push(x))}else{var y=v.get("id"),_=this._layerMeshes[y];_||(_=this._layerMeshes[y]=new T.Mesh({geometry:this._overlayGeometry,castShadow:!1,ignorePicking:!0}));var w=v.get("shading");w==="lambert"?(_.material=_.__lambertMaterial||new T.Material({autoUpdateTextureStatus:!1,shader:T.createShader("ecgl.lambert"),transparent:!0,depthMask:!1}),_.__lambertMaterial=_.material):(_.material=_.__colorMaterial||new T.Material({autoUpdateTextureStatus:!1,shader:T.createShader("ecgl.color"),transparent:!0,depthMask:!1}),_.__colorMaterial=_.material),_.material.enableTexture("diffuseMap");var S=v.get("distance"),b=n+(S==null?r.radius/100:S);_.scale.set(b,b,b),n=b;var A=this._blankTexture||(this._blankTexture=T.createBlankTexture("rgba(255, 255, 255, 0)"));_.material.set("diffuseMap",A),T.loadTexture(v.get("texture"),t,{flipY:!1,anisotropic:8},function(C){C.surface&&C.surface.attachToMesh(_),_.material.set("diffuseMap",C),t.getZr().refresh()}),v.get("show")?this.groupGL.add(_):this.groupGL.remove(_)}},this);var h=this._earthMesh.material;h.define("fragment","LAYER_DIFFUSEMAP_COUNT",a.length),h.define("fragment","LAYER_EMISSIVEMAP_COUNT",s.length),h.set("layerDiffuseMap",a),h.set("layerDiffuseIntensity",o),h.set("layerEmissiveMap",s),h.set("layerEmissionIntensity",l);var u=e.getModel("debug.wireframe");if(u.get("show")){h.define("both","WIREFRAME_TRIANGLE");var f=T.parseColor(u.get("lineStyle.color")||"rgba(0,0,0,0.5)"),d=K.firstNotNull(u.get("lineStyle.width"),1);h.set("wireframeLineWidth",d),h.set("wireframeLineColor",f)}else h.undefine("both","WIREFRAME_TRIANGLE")},_updateViewControl:function(e,t){var r=e.coordinateSystem,i=e.getModel("viewControl");r.viewGL.camera;var n=this;function a(){return{type:"globeChangeCamera",alpha:o.getAlpha(),beta:o.getBeta(),distance:o.getDistance()-r.radius,center:o.getCenter(),from:n.uid,globeId:e.id}}var o=this._control;o.setViewGL(r.viewGL);var s=i.get("targetCoord"),l,h;s!=null&&(h=s[0]+90,l=s[1]),o.setFromViewControlModel(i,{baseDistance:r.radius,alpha:l,beta:h}),o.off("update"),o.on("update",function(){t.dispatchAction(a())})},_displaceVertices:function(e,t){var r=e.get("displacementQuality"),i=e.get("debug.wireframe.show"),n=e.coordinateSystem;if(!(!e.isDisplacementChanged()&&r===this._displacementQuality&&i===this._showDebugWireframe)){this._displacementQuality=r,this._showDebugWireframe=i;var a=this._sphereGeometry,o={low:100,medium:200,high:400,ultra:800}[r]||200,s=o/2;(a.widthSegments!==o||i)&&(a.widthSegments=o,a.heightSegments=s,a.build()),this._doDisplaceVertices(a,n),i&&a.generateBarycentric()}},_doDisplaceVertices:function(e,t){var r=e.attributes.position.value,i=e.attributes.texcoord0.value,n=e.__originalPosition;(!n||n.length!==r.length)&&(n=new Float32Array(r.length),n.set(r),e.__originalPosition=n);for(var a=t.displacementWidth,o=t.displacementHeight,s=t.displacementData,l=0;l50&&(o=1e3);var s=[];kt.perspective(s,Kn,this.width/this.height,1,o),this.viewGL.camera.projectionMatrix.setArray(s),this.viewGL.camera.decomposeProjectionMatrix();var s=kt.identity([]),l=this.dataToPoint(this.center);kt.scale(s,s,[1,-1,1]),kt.translate(s,s,[0,0,-e]),kt.rotateX(s,s,t),kt.rotateZ(s,s,-this.bearing/180*Math.PI),kt.translate(s,s,[-l[0]*this.getScale()*Lr,-l[1]*this.getScale()*Lr,0]),this.viewGL.camera.viewMatrix.array=s;var h=[];kt.invert(h,s),this.viewGL.camera.worldTransform.array=h,this.viewGL.camera.decomposeWorldTransform();var u=ni*this.getScale(),f;if(this.altitudeExtent&&!isNaN(this.boxHeight)){var d=this.altitudeExtent[1]-this.altitudeExtent[0];f=this.boxHeight/d*this.getScale()/Math.pow(2,this._initialZoom-this.zoomOffset)}else f=u/(2*Math.PI*6378e3*Math.abs(Math.cos(this.center[1]*(Math.PI/180))))*this.altitudeScale*Lr;this.viewGL.rootNode.scale.set(this.getScale()*Lr,this.getScale()*Lr,f)}},getScale:function(){return Math.pow(2,this.zoom-this.zoomOffset)},projectOnTile:function(e,t){return this.projectOnTileWithScale(e,this.getScale()*ni,t)},projectOnTileWithScale:function(e,t,r){var i=e[0],n=e[1],a=i*st/180,o=n*st/180,s=t*(a+st)/(2*st),l=t*(st-Math.log(Math.tan(st/4+o*.5)))/(2*st);return r=r||[],r[0]=s,r[1]=l,r},unprojectFromTile:function(e,t){return this.unprojectOnTileWithScale(e,this.getScale()*ni,t)},unprojectOnTileWithScale:function(e,t,r){var i=e[0],n=e[1],a=i/t*(2*st)-st,o=2*(Math.atan(Math.exp(st-n/t*(2*st)))-st/4);return r=r||[],r[0]=a*180/st,r[1]=o*180/st,r},dataToPoint:function(e,t){return t=this.projectOnTileWithScale(e,ni,t),t[0]-=this._origin[0],t[1]-=this._origin[1],t[2]=isNaN(e[2])?0:e[2],isNaN(e[2])||(t[2]=e[2],this.altitudeExtent&&(t[2]-=this.altitudeExtent[0])),t}};function wi(){Hr.apply(this,arguments)}wi.prototype=new Hr;wi.prototype.constructor=wi;wi.prototype.type="mapbox3D";function wl(e,t,r){function i(a,o){var s=o.getWidth(),l=o.getHeight(),h=o.getDevicePixelRatio();this.viewGL.setViewport(0,0,s,l,h),this.width=s,this.height=l,this.altitudeScale=a.get("altitudeScale"),this.boxHeight=a.get("boxHeight")}function n(a,o){if(this.model.get("boxHeight")!=="auto"){var s=[1/0,-1/0];a.eachSeries(function(l){if(l.coordinateSystem===this){var h=l.getData(),u=l.coordDimToDataDim("alt")[0];if(u){var f=h.getDataExtent(u,!0);s[0]=Math.min(s[0],f[0]),s[1]=Math.max(s[1],f[1])}}},this),s&&isFinite(s[1]-s[0])&&(this.altitudeExtent=s)}}return{dimensions:t.prototype.dimensions,create:function(a,o){var s=[];return a.eachComponent(e,function(l){var h=l.__viewGL;h||(h=l.__viewGL=new ce,h.setRootNode(new T.Node));var u=new t;u.viewGL=l.__viewGL,u.resize=i,u.resize(l,o),s.push(u),l.coordinateSystem=u,u.model=l,u.update=n}),a.eachSeries(function(l){if(l.get("coordinateSystem")===e){var h=l.getReferringComponents(e).models[0];if(h||(h=a.getComponent(e)),!h)throw new Error(e+' "'+K.firstNotNull(l.get(e+"Index"),l.get(e+"Id"),0)+'" not found');l.coordinateSystem=h.coordinateSystem}}),r&&r(s,a,o),s}}}var Od=wl("mapbox3D",wi,function(e){e.forEach(function(t){t.setCameraOption(t.model.getMapboxCameraOption())})});const Bd=Od;function Fd(e){e.registerComponentModel(Nd),e.registerComponentView(Id),e.registerCoordinateSystem("mapbox3D",Bd),e.registerAction({type:"mapbox3DChangeCamera",event:"mapbox3dcamerachanged",update:"mapbox3D:updateCamera"},function(t,r){r.eachComponent({mainType:"mapbox3D",query:t},function(i){i.setMapboxCameraOption(t)})})}Ye(Fd);var Xo=["zoom","center","pitch","bearing"],Ba=Vr.extend({type:"maptalks3D",layoutMode:"box",coordinateSystem:null,defaultOption:{zlevel:-10,urlTemplate:"http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png",attribution:'© OpenStreetMap contributors, © CARTO',center:[0,0],zoom:0,pitch:0,bearing:0,light:{main:{alpha:20,beta:30}},altitudeScale:1,boxHeight:"auto"},getMaptalksCameraOption:function(){var e=this;return Xo.reduce(function(t,r){return t[r]=e.get(r),t},{})},setMaptalksCameraOption:function(e){e!=null&&Xo.forEach(function(t){e[t]!=null&&(this.option[t]=e[t])},this)},getMaptalks:function(){return this._maptalks},setMaptalks:function(e){this._maptalks=e}});fe(Ba.prototype,Wr);fe(Ba.prototype,Xr);const Ud=Ba;function Jt(e,t,r,i){if(this.id=e,this.zr=t,this.dom=document.createElement("div"),this.dom.style.cssText="position:absolute;left:0;right:0;top:0;bottom:0;",!maptalks)throw new Error("Maptalks library must be included. See https://maptalks.org");this._maptalks=new maptalks.Map(this.dom,{center:r,zoom:i,doubleClickZoom:!1,fog:!1}),this._initEvents()}Jt.prototype.setUnpainted=function(){};Jt.prototype.resize=function(){this._maptalks.checkSize()};Jt.prototype.getMaptalks=function(){return this._maptalks};Jt.prototype.clear=function(){};Jt.prototype.refresh=function(){this._maptalks.checkSize()};var Sl=["mousedown","mouseup","click","dblclick","mousemove","mousewheel","DOMMouseScroll","touchstart","touchend","touchmove","touchcancel"];Jt.prototype._initEvents=function(){var e=this.dom;this._handlers=this._handlers||{contextmenu:function(t){return t.preventDefault(),!1}},Sl.forEach(function(t){this._handlers[t]=function(r){var i={};for(var n in r)i[n]=r[n];i.bubbles=!1;var a=new r.constructor(r.type,i);t==="mousewheel"||t==="DOMMouseScroll"?e.dispatchEvent(a):e.firstElementChild.dispatchEvent(a)},this.zr.dom.addEventListener(t,this._handlers[t])},this),this.zr.dom.addEventListener("contextmenu",this._handlers.contextmenu)};Jt.prototype.dispose=function(){Sl.forEach(function(e){this.zr.dom.removeEventListener(e,this._handlers[e])},this),this._maptalks.remove()};T.Shader.import(Tl);const Gd=Ai.extend({type:"maptalks3D",__ecgl__:!0,init:function(e,t){this._groundMesh=new T.Mesh({geometry:new T.PlaneGeometry,material:new T.Material({shader:new T.Shader({vertex:T.Shader.source("ecgl.displayShadow.vertex"),fragment:T.Shader.source("ecgl.displayShadow.fragment")}),depthMask:!1}),renderOrder:-100,culling:!1,castShadow:!1,$ignorePicking:!0,renderNormal:!0})},_initMaptalksLayer:function(e,t){var r=t.getZr();this._zrLayer=new Jt("maptalks3D",r,e.get("center"),e.get("zoom")),r.painter.insertLayer(-1e3,this._zrLayer),this._lightRoot=new T.Node,this._sceneHelper=new Yt(this._lightRoot),this._sceneHelper.initLight(this._lightRoot);var i=this._zrLayer.getMaptalks(),n=this._dispatchInteractAction.bind(this,t,i);["zoomend","zooming","zoomstart","dragrotating","pitch","pitchend","movestart","moving","moveend","resize","touchstart","touchmove","touchend","animating"].forEach(function(a){i.on(a,n)})},render:function(e,t,r){this._zrLayer||this._initMaptalksLayer(e,r);var i=this._zrLayer.getMaptalks(),n=e.get("urlTemplate"),a=i.getBaseLayer();n!==this._oldUrlTemplate&&(a?a.setOptions({urlTemplate:n,attribution:e.get("attribution")}):(a=new maptalks.TileLayer("maptalks-echarts-gl-baselayer",{urlTemplate:n,subdomains:["a","b","c"],attribution:e.get("attribution")}),i.setBaseLayer(a))),this._oldUrlTemplate=n,i.setCenter(e.get("center")),i.setZoom(e.get("zoom"),{animation:!1}),i.setPitch(e.get("pitch")),i.setBearing(e.get("bearing")),e.setMaptalks(i);var o=e.coordinateSystem;o.viewGL.scene.add(this._lightRoot),o.viewGL.add(this._groundMesh),this._updateGroundMesh(),this._sceneHelper.setScene(o.viewGL.scene),this._sceneHelper.updateLight(e),o.viewGL.setPostEffect(e.getModel("postEffect"),r),o.viewGL.setTemporalSuperSampling(e.getModel("temporalSuperSampling")),this._maptalks3DModel=e},afterRender:function(e,t,r,i){var n=i.renderer;this._sceneHelper.updateAmbientCubemap(n,e,r),this._sceneHelper.updateSkybox(n,e,r),e.coordinateSystem.viewGL.scene.traverse(function(a){a.material&&(a.material.define("fragment","NORMAL_UP_AXIS",2),a.material.define("fragment","NORMAL_FRONT_AXIS",1))})},updateCamera:function(e,t,r,i){e.coordinateSystem.setCameraOption(i),this._updateGroundMesh(),r.getZr().refresh()},_dispatchInteractAction:function(e,t,r){e.dispatchAction({type:"maptalks3DChangeCamera",pitch:t.getPitch(),zoom:Hd(t.getResolution())+1,center:t.getCenter().toArray(),bearing:t.getBearing(),maptalks3DId:this._maptalks3DModel&&this._maptalks3DModel.id})},_updateGroundMesh:function(){if(this._maptalks3DModel){var e=this._maptalks3DModel.coordinateSystem,t=e.dataToPoint(e.center);this._groundMesh.position.set(t[0],t[1],-.001);var r=new T.Plane(new T.Vector3(0,0,1),0),i=e.viewGL.camera.castRay(new T.Vector2(-1,-1)),n=e.viewGL.camera.castRay(new T.Vector2(1,1)),a=i.intersectPlane(r),o=n.intersectPlane(r),s=a.dist(o)/e.viewGL.rootNode.scale.x;this._groundMesh.scale.set(s,s,1)}},dispose:function(e,t){this._zrLayer&&this._zrLayer.dispose(),t.getZr().painter.delLayer(-1e3)}}),zd=2*6378137*Math.PI/(256*Math.pow(2,20));function Hd(e){return 19-Math.log(e/zd)/Math.LN2}function Si(){Hr.apply(this,arguments),this.maxPitch=85,this.zoomOffset=1}Si.prototype=new Hr;Si.prototype.constructor=Si;Si.prototype.type="maptalks3D";var Vd=wl("maptalks3D",Si,function(e){e.forEach(function(t){t.setCameraOption(t.model.getMaptalksCameraOption())})});const kd=Vd;function Wd(e){e.registerComponentModel(Ud),e.registerComponentView(Gd),e.registerCoordinateSystem("maptalks3D",kd),e.registerAction({type:"maptalks3DChangeCamera",event:"maptalks3dcamerachanged",update:"maptalks3D:updateCamera"},function(t,r){r.eachComponent({mainType:"maptalks3D",query:t},function(i){i.setMaptalksCameraOption(t)})})}Ye(Wd);var Xd=Me.vec3,Zd=ya.isDimensionStacked;function jd(e){var t=e[0],r=e[1];return!(t>0&&r>0||t<0&&r<0)}function qd(e,t){var r=e.getData(),i=e.get("barSize");if(i==null){var n=t.size,a,o,s=t.getAxis("x"),l=t.getAxis("y");s.type==="category"?a=s.getBandWidth()*.7:a=Math.round(n[0]/Math.sqrt(r.count()))*.6,l.type==="category"?o=l.getBandWidth()*.7:o=Math.round(n[1]/Math.sqrt(r.count()))*.6,i=[a,o]}else Mt(i)||(i=[i,i]);var h=t.getAxis("z").scale.getExtent(),u=jd(h),f=["x","y","z"].map(function(v){return e.coordDimToDataDim(v)[0]}),d=Zd(r,f[2]),c=d?r.getCalculationInfo("stackResultDimension"):f[2];r.each(f,function(v,p,m,g){var x=r.get(c,g),y=d?x-m:u?0:h[0],_=t.dataToPoint([v,p,y]),w=t.dataToPoint([v,p,x]),S=Xd.dist(_,w),b=[0,w[1]<_[1]?-1:1,0];Math.abs(S)===0&&(S=.1);var A=[i[0],S,i[1]];r.setItemLayout(g,[_,b,A])}),r.setLayout("orient",[1,0,0])}function Fa(e,t,r){for(var i=e.getDataExtent(t),n=e.getDataExtent(r),a=i[1]-i[0]||i[0],o=n[1]-n[0]||n[0],s=50,l=new Uint8Array(s*s),h=0;h"+d.join("
")}var n=e.getData(),a=e.getRawValue(t),o=Mt(a)?i(a):Mr(Wa(a)),s=n.getName(t),l=ke(n,t);ah(l)&&l.colorStops&&(l=(l.colorStops[0]||{}).color),l=l||"transparent";var h=oh(l),u=e.name;return u==="\0-"&&(u=""),u=u?Mr(u)+(r?": ":"
"):"",r?h+u+o:u+h+(s?Mr(s)+": "+o:o)}function En(e,t,r){r=r||e.getSource();var i=t||ds(e.get("coordinateSystem"))||["x","y","z"],n=Ei(r,{dimensionsDefine:r.dimensionsDefine||e.get("dimensions"),encodeDefine:r.encodeDefine||e.get("encode"),coordDimensions:i.map(function(s){var l=e.getReferringComponents(s+"Axis3D").models[0];return{type:l&&l.get("type")==="category"?"ordinal":"float",name:s}})});e.get("coordinateSystem")==="cartesian3D"&&n.forEach(function(s){if(i.indexOf(s.coordDim)>=0){var l=e.getReferringComponents(s.coordDim+"Axis3D").models[0];l&&l.get("type")==="category"&&(s.ordinalMeta=l.getOrdinalMeta())}});var a=ya.enableDataStack(e,n,{byIndex:!0,stackedCoordDimension:"z"}),o=new Pt(n,e);return o.setCalculationInfo(a),o.initData(r),o}var Al=St.extend({type:"series.bar3D",dependencies:["globe"],visualStyleAccessPathvisu:"itemStyle",getInitialData:function(e,t){return En(this)},getFormattedLabel:function(e,t,r,i){var n=Yr.getFormattedLabel(this,e,t,r,i);return n==null&&(n=this.getData().get("z",e)),n},formatTooltip:function(e){return Mi(this,e)},defaultOption:{coordinateSystem:"cartesian3D",globeIndex:0,grid3DIndex:0,zlevel:-10,bevelSize:0,bevelSmoothness:2,onGridPlane:"xy",shading:"color",minHeight:0,itemStyle:{opacity:1},label:{show:!1,distance:2,textStyle:{fontSize:14,color:"#000",backgroundColor:"rgba(255,255,255,0.7)",padding:3,borderRadius:3}},emphasis:{label:{show:!0}},animationDurationUpdate:500}});fe(Al.prototype,jr);const tv=Al;var Ee=Me.vec3,rv=Me.mat3,za=oe.extend(function(){return{attributes:{position:new oe.Attribute("position","float",3,"POSITION"),normal:new oe.Attribute("normal","float",3,"NORMAL"),color:new oe.Attribute("color","float",4,"COLOR"),prevPosition:new oe.Attribute("prevPosition","float",3),prevNormal:new oe.Attribute("prevNormal","float",3)},dynamic:!0,enableNormal:!1,bevelSize:1,bevelSegments:0,_dataIndices:null,_vertexOffset:0,_triangleOffset:0}},{resetOffset:function(){this._vertexOffset=0,this._triangleOffset=0},setBarCount:function(e){var t=this.enableNormal,r=this.getBarVertexCount()*e,i=this.getBarTriangleCount()*e;this.vertexCount!==r&&(this.attributes.position.init(r),t?this.attributes.normal.init(r):this.attributes.normal.value=null,this.attributes.color.init(r)),this.triangleCount!==i&&(this.indices=r>65535?new Uint32Array(i*3):new Uint16Array(i*3),this._dataIndices=new Uint32Array(r))},getBarVertexCount:function(){var e=this.bevelSize>0?this.bevelSegments:0;return e>0?this._getBevelBarVertexCount(e):this.enableNormal?24:8},getBarTriangleCount:function(){var e=this.bevelSize>0?this.bevelSegments:0;return e>0?this._getBevelBarTriangleCount(e):12},_getBevelBarVertexCount:function(e){return(e+1)*4*(e+1)*2},_getBevelBarTriangleCount:function(e){var t=e*4+3,r=e*2+1;return(t+1)*r*2+4},setColor:function(e,t){for(var r=this.getBarVertexCount(),i=r*e,n=r*(e+1),a=i;a0&&this.bevelSegments>0)this._addBevelBar(y,_,w,S,this.bevelSize,this.bevelSegments,b);else{Ee.copy(n,_),Ee.normalize(n,n),Ee.cross(a,w,n),Ee.normalize(a,a),Ee.cross(i,n,a),Ee.normalize(a,a),Ee.negate(o,i),Ee.negate(s,n),Ee.negate(l,a),t(h[0],y,i,S[0]/2),t(h[0],h[0],a,S[2]/2),t(h[1],y,i,S[0]/2),t(h[1],h[1],l,S[2]/2),t(h[2],y,o,S[0]/2),t(h[2],h[2],l,S[2]/2),t(h[3],y,o,S[0]/2),t(h[3],h[3],a,S[2]/2),t(r,y,n,S[1]),t(h[4],r,i,S[0]/2),t(h[4],h[4],a,S[2]/2),t(h[5],r,i,S[0]/2),t(h[5],h[5],l,S[2]/2),t(h[6],r,o,S[0]/2),t(h[6],h[6],l,S[2]/2),t(h[7],r,o,S[0]/2),t(h[7],h[7],a,S[2]/2);var P=this.attributes;if(this.enableNormal){u[0]=i,u[1]=o,u[2]=n,u[3]=s,u[4]=a,u[5]=l;for(var L=this._vertexOffset,R=0;R0&&(m++,u[3]<.99&&(c=!0))}}),o.geometry.setBarCount(m);var v=r.getLayout("orient"),p=this._barIndexOfData=new Int32Array(r.count()),m=0;r.each(function(x){if(!r.hasValue(x)){p[x]=-1;return}var y=r.getItemLayout(x),_=y[0],w=y[1],S=y[2],b=x*4;u[0]=f[b++],u[1]=f[b++],u[2]=f[b++],u[3]=f[b++],u[3]>0&&(a._barMesh.geometry.addBar(_,w,v,S,u,x),p[x]=m++)}),o.geometry.dirty(),o.geometry.updateBoundingBox();var g=o.material;g.transparent=c,g.depthMask=!c,o.geometry.sortTriangles=c,this._initHandler(e,t)},_initHandler:function(e,t){var r=e.getData(),i=this._barMesh,n=e.coordinateSystem.type==="cartesian3D";i.seriesIndex=e.seriesIndex;var a=-1;i.off("mousemove"),i.off("mouseout"),i.on("mousemove",function(o){var s=i.geometry.getDataIndexOfVertex(o.triangle[0]);s!==a&&(this._downplay(a),this._highlight(s),this._labelsBuilder.updateLabels([s]),n&&t.dispatchAction({type:"grid3DShowAxisPointer",value:[r.get("x",s),r.get("y",s),r.get("z",s,!0)]})),a=s,i.dataIndex=s},this),i.on("mouseout",function(o){this._downplay(a),this._labelsBuilder.updateLabels(),a=-1,i.dataIndex=-1,n&&t.dispatchAction({type:"grid3DHideAxisPointer"})},this)},_highlight:function(e){var t=this._data;if(!!t){var r=this._barIndexOfData[e];if(!(r<0)){var i=t.getItemModel(e),n=i.getModel("emphasis.itemStyle"),a=n.get("color"),o=n.get("opacity");if(a==null){var s=ke(t,e);a=_a(s,-.4)}o==null&&(o=Ve(t,e));var l=T.parseColor(a);l[3]*=o,this._barMesh.geometry.setColor(r,l),this._api.getZr().refresh()}}},_downplay:function(e){var t=this._data;if(!!t){var r=this._barIndexOfData[e];if(!(r<0)){var i=ke(t,e),n=Ve(t,e),a=T.parseColor(i);a[3]*=n,this._barMesh.geometry.setColor(r,a),this._api.getZr().refresh()}}},highlight:function(e,t,r,i){this._toggleStatus("highlight",e,t,r,i)},downplay:function(e,t,r,i){this._toggleStatus("downplay",e,t,r,i)},_toggleStatus:function(e,t,r,i,n){var a=t.getData(),o=K.queryDataIndex(a,n),s=this;o!=null?Dt(Yr.normalizeToArray(o),function(l){e==="highlight"?this._highlight(l):this._downplay(l)},this):a.each(function(l){e==="highlight"?s._highlight(l):s._downplay(l)})},remove:function(){this.groupGL.removeAll()},dispose:function(){this._labelsBuilder.dispose(),this.groupGL.removeAll()}});function ov(e){e.registerChartView(av),e.registerSeriesModel(tv),Jd(e),e.registerProcessor(function(t,r){t.eachSeriesByType("bar3d",function(i){var n=i.getData();n.filterSelf(function(a){return n.hasValue(a)})})})}Ye(ov);var sv=St.extend({type:"series.line3D",dependencies:["grid3D"],visualStyleAccessPath:"lineStyle",visualDrawType:"stroke",getInitialData:function(e,t){return En(this)},formatTooltip:function(e){return Mi(this,e)},defaultOption:{coordinateSystem:"cartesian3D",zlevel:-10,grid3DIndex:0,lineStyle:{width:2},animationDurationUpdate:500}});const lv=sv;var hv=Me.vec3;T.Shader.import(An);const uv=At.extend({type:"line3D",__ecgl__:!0,init:function(e,t){this.groupGL=new T.Node,this._api=t},render:function(e,t,r){var i=this._prevLine3DMesh;this._prevLine3DMesh=this._line3DMesh,this._line3DMesh=i,this._line3DMesh||(this._line3DMesh=new T.Mesh({geometry:new yr({useNativeLine:!1,sortTriangles:!0}),material:new T.Material({shader:T.createShader("ecgl.meshLines3D")}),renderOrder:10}),this._line3DMesh.geometry.pick=this._pick.bind(this)),this.groupGL.remove(this._prevLine3DMesh),this.groupGL.add(this._line3DMesh);var n=e.coordinateSystem;if(n&&n.viewGL){n.viewGL.add(this.groupGL);var a=n.viewGL.isLinearSpace()?"define":"undefine";this._line3DMesh.material[a]("fragment","SRGB_DECODE")}this._doRender(e,r),this._data=e.getData(),this._camera=n.viewGL.camera,this.updateCamera(),this._updateAnimation(e)},updateCamera:function(){this._updateNDCPosition()},_doRender:function(e,t){var r=e.getData(),i=this._line3DMesh;i.geometry.resetOffset();var n=r.getLayout("points"),a=[],o=new Float32Array(n.length/3*4),s=0,l=!1;r.each(function(f){var d=ke(r,f),c=Ve(r,f);c==null&&(c=1),T.parseColor(d,a),a[3]*=c,o[s++]=a[0],o[s++]=a[1],o[s++]=a[2],o[s++]=a[3],a[3]<.99&&(l=!0)}),i.geometry.setVertexCount(i.geometry.getPolylineVertexCount(n)),i.geometry.setTriangleCount(i.geometry.getPolylineTriangleCount(n)),i.geometry.addPolyline(n,o,K.firstNotNull(e.get("lineStyle.width"),1)),i.geometry.dirty(),i.geometry.updateBoundingBox();var h=i.material;h.transparent=l,h.depthMask=!l;var u=e.getModel("debug.wireframe");u.get("show")?(i.geometry.createAttribute("barycentric","float",3),i.geometry.generateBarycentric(),i.material.set("both","WIREFRAME_TRIANGLE"),i.material.set("wireframeLineColor",T.parseColor(u.get("lineStyle.color")||"rgba(0,0,0,0.5)")),i.material.set("wireframeLineWidth",K.firstNotNull(u.get("lineStyle.width"),1))):i.material.set("both","WIREFRAME_TRIANGLE"),this._points=n,this._initHandler(e,t)},_updateAnimation:function(e){T.updateVertexAnimation([["prevPosition","position"],["prevPositionPrev","positionPrev"],["prevPositionNext","positionNext"]],this._prevLine3DMesh,this._line3DMesh,e)},_initHandler:function(e,t){var r=e.getData(),i=e.coordinateSystem,n=this._line3DMesh,a=-1;n.seriesIndex=e.seriesIndex,n.off("mousemove"),n.off("mouseout"),n.on("mousemove",function(o){var s=i.pointToData(o.point.array),l=r.indicesOfNearest("x",s[0])[0];l!==a&&(t.dispatchAction({type:"grid3DShowAxisPointer",value:[r.get("x",l),r.get("y",l),r.get("z",l)]}),n.dataIndex=l),a=l},this),n.on("mouseout",function(o){a=-1,n.dataIndex=-1,t.dispatchAction({type:"grid3DHideAxisPointer"})},this)},_updateNDCPosition:function(){var e=new k,t=this._camera;k.multiply(e,t.projectionMatrix,t.viewMatrix);var r=this._positionNDC,i=this._points,n=i.length/3;(!r||r.length/2!==n)&&(r=this._positionNDC=new Float32Array(n*2));for(var a=[],o=0;o=0){var w=h*3,S=new U(this._points[w],this._points[w+1],this._points[w+2]);a.push({dataIndex:h,point:S,pointWorld:S.clone(),target:this._line3DMesh,distance:this._camera.getWorldPosition().dist(S)})}},remove:function(){this.groupGL.removeAll()},dispose:function(){this.groupGL.removeAll()}});function fv(e){e.registerChartView(uv),e.registerSeriesModel(lv),e.registerLayout(function(t,r){t.eachSeriesByType("line3D",function(i){var n=i.getData(),a=i.coordinateSystem;if(a){if(a.type!=="cartesian3D"){console.error("line3D needs cartesian3D coordinateSystem");return}var o=new Float32Array(n.count()*3),s=[],l=[],h=a.dimensions,u=h.map(function(f){return i.coordDimToDataDim(f)[0]});a&&n.each(u,function(f,d,c,v){s[0]=f,s[1]=d,s[2]=c,a.dataToPoint(s,l),o[v*3]=l[0],o[v*3+1]=l[1],o[v*3+2]=l[2]}),n.setLayout("points",o)}})})}Ye(fv);const cv=St.extend({type:"series.scatter3D",dependencies:["globe","grid3D","geo3D"],visualStyleAccessPath:"itemStyle",hasSymbolVisual:!0,getInitialData:function(e,t){return En(this)},getFormattedLabel:function(e,t,r,i){var n=Yr.getFormattedLabel(this,e,t,r,i);if(n==null){var a=this.getData(),o=a.dimensions[a.dimensions.length-1];n=a.get(o,e)}return n},formatTooltip:function(e){return Mi(this,e)},defaultOption:{coordinateSystem:"cartesian3D",zlevel:-10,progressive:1e5,progressiveThreshold:1e5,grid3DIndex:0,globeIndex:0,symbol:"circle",symbolSize:10,blendMode:"source-over",label:{show:!1,position:"right",distance:5,textStyle:{fontSize:14,color:"#000",backgroundColor:"rgba(255,255,255,0.7)",padding:3,borderRadius:3}},itemStyle:{opacity:.8},emphasis:{label:{show:!0}},animationDurationUpdate:500}});function Qn(e,i,r){var i=i||document.createElement("canvas");i.width=e,i.height=e;var n=i.getContext("2d");return r&&r(n),i}function dv(e,t,r,i){Mt(t)||(t=[t,t]);var n=Ha.getMarginByStyle(r,i),a=t[0]+n.left+n.right,o=t[1]+n.top+n.bottom,s=hh(e,0,0,t[0],t[1]),l=Math.max(a,o);s.x=n.left,s.y=n.top,a>o?s.y+=(l-o)/2:s.x+=(l-a)/2;var h=s.getBoundingRect();return s.x-=h.x,s.y-=h.y,s.setStyle(r),s.update(),s.__size=l,s}function vv(e,t,r){var i=t.width,n=t.height,a=e.canvas.width,o=e.canvas.height,s=i/a,l=n/o;function h(g){return g<128?1:-1}function u(g,x){var y=1/0;g=Math.floor(g*s),x=Math.floor(x*l);for(var _=x*i+g,w=t.data[_*4],S=h(w),b=Math.max(x-r,0);b=2e4},doSortVertices:function(e,t){var r=this.indices,i=qo.create();if(!r){r=this.indices=this.vertexCount>65535?new Uint32Array(this.vertexCount):new Uint16Array(this.vertexCount);for(var n=0;n.05);else for(var n=0;n<3;n++)this._progressiveQuickSort(t*3+n);this.dirtyIndices()},_simpleSort:function(e){var t=this._zList,r=this.indices;function i(n,a){return t[a]-t[n]}e?Array.prototype.sort.call(r,i):Gr.sort(r,i,0,r.length-1)},_progressiveQuickSort:function(e){var t=this._zList,r=this.indices;this._quickSort=this._quickSort||new Gr,this._quickSort.step(r,function(i,n){return t[n]-t[i]},e)}},mv=`@export ecgl.sdfSprite.vertex uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; uniform float elapsedTime : 0; attribute vec3 position : POSITION; #ifdef VERTEX_SIZE attribute float size; #else uniform float u_Size; #endif #ifdef VERTEX_COLOR attribute vec4 a_FillColor: COLOR; varying vec4 v_Color; #endif #ifdef VERTEX_ANIMATION attribute vec3 prevPosition; attribute float prevSize; uniform float percent : 1.0; #endif #ifdef POSITIONTEXTURE_ENABLED uniform sampler2D positionTexture; #endif varying float v_Size; void main() { #ifdef POSITIONTEXTURE_ENABLED gl_Position = worldViewProjection * vec4(texture2D(positionTexture, position.xy).xy, -10.0, 1.0); #else #ifdef VERTEX_ANIMATION vec3 pos = mix(prevPosition, position, percent); #else vec3 pos = position; #endif gl_Position = worldViewProjection * vec4(pos, 1.0); #endif #ifdef VERTEX_SIZE #ifdef VERTEX_ANIMATION v_Size = mix(prevSize, size, percent); #else v_Size = size; #endif #else v_Size = u_Size; #endif #ifdef VERTEX_COLOR v_Color = a_FillColor; #endif gl_PointSize = v_Size; } @end @export ecgl.sdfSprite.fragment uniform vec4 color: [1, 1, 1, 1]; uniform vec4 strokeColor: [1, 1, 1, 1]; uniform float smoothing: 0.07; uniform float lineWidth: 0.0; #ifdef VERTEX_COLOR varying vec4 v_Color; #endif varying float v_Size; uniform sampler2D sprite; @import clay.util.srgb void main() { gl_FragColor = color; vec4 _strokeColor = strokeColor; #ifdef VERTEX_COLOR gl_FragColor *= v_Color; #endif #ifdef SPRITE_ENABLED float d = texture2D(sprite, gl_PointCoord).r; gl_FragColor.a *= smoothstep(0.5 - smoothing, 0.5 + smoothing, d); if (lineWidth > 0.0) { float sLineWidth = lineWidth / 2.0; float outlineMaxValue0 = 0.5 + sLineWidth; float outlineMaxValue1 = 0.5 + sLineWidth + smoothing; float outlineMinValue0 = 0.5 - sLineWidth - smoothing; float outlineMinValue1 = 0.5 - sLineWidth; if (d <= outlineMaxValue1 && d >= outlineMinValue0) { float a = _strokeColor.a; if (d <= outlineMinValue1) { a = a * smoothstep(outlineMinValue0, outlineMinValue1, d); } else { a = a * smoothstep(outlineMaxValue1, outlineMaxValue0, d); } gl_FragColor.rgb = mix(gl_FragColor.rgb * gl_FragColor.a, _strokeColor.rgb, a); gl_FragColor.a = gl_FragColor.a * (1.0 - a) + a; } } #endif #ifdef SRGB_DECODE gl_FragColor = sRGBToLinear(gl_FragColor); #endif } @end`;var $n=Me.vec4;T.Shader.import(mv);var gv=T.Mesh.extend(function(){var e=new T.Geometry({dynamic:!0,attributes:{color:new T.Geometry.Attribute("color","float",4,"COLOR"),position:new T.Geometry.Attribute("position","float",3,"POSITION"),size:new T.Geometry.Attribute("size","float",1),prevPosition:new T.Geometry.Attribute("prevPosition","float",3),prevSize:new T.Geometry.Attribute("prevSize","float",1)}});Object.assign(e,pv);var t=new T.Material({shader:T.createShader("ecgl.sdfSprite"),transparent:!0,depthMask:!1});t.enableTexture("sprite"),t.define("both","VERTEX_COLOR"),t.define("both","VERTEX_SIZE");var r=new T.Texture2D({image:document.createElement("canvas"),flipY:!1});return t.set("sprite",r),e.pick=this._pick.bind(this),{geometry:e,material:t,mode:T.Mesh.POINTS,sizeScale:1}},{_pick:function(e,t,r,i,n,a){var o=this._positionNDC;if(!!o)for(var s=r.viewport,l=2/s.width,h=2/s.height,u=this.geometry.vertexCount-1;u>=0;u--){var f;this.geometry.indices?f=this.geometry.indices[u]:f=u;var d=o[f*2],c=o[f*2+1],v=this.geometry.attributes.size.get(f)/this.sizeScale,p=v/2;if(e>d-p*l&&ec-p*h&&t2?(v=this._updateSymbolSprite(e,d,u,f),s.enableTexture("sprite")):s.disableTexture("sprite"),h.position.init(n-i);var p=[];if(c){s.undefine("VERTEX_SIZE"),s.undefine("VERTEX_COLOR");var m=ed(o),g=td(o);T.parseColor(m,p),p[3]*=g,s.set({color:p,u_Size:u.maxSize*this._sizeScale})}else s.set({color:[1,1,1,1]}),s.define("VERTEX_SIZE"),s.define("VERTEX_COLOR"),h.size.init(n-i),h.color.init(n-i),this._originalOpacity=new Float32Array(n-i);for(var x=o.getLayout("points"),y=h.position.value,_=0;_1?(n[0]=r.maxSize,n[1]=r.maxSize/r.aspect):(n[1]=r.maxSize,n[0]=r.maxSize*r.aspect),n[0]=n[0]||1,n[1]=n[1]||1,(this._symbolType!==r.type||!yv(this._symbolSize,n)||this._lineWidth!==t.lineWidth)&&(jo.createSymbolSprite(r.type,n,{fill:"#fff",lineWidth:t.lineWidth,stroke:"transparent",shadowColor:"transparent",minMargin:Math.min(n[0]/2,10)},this._spriteImageCanvas),jo.createSDFFromCanvas(this._spriteImageCanvas,Math.min(this._spriteImageCanvas.width,32),Yo,this._mesh.material.get("sprite").image),this._symbolType=r.type,this._symbolSize=n,this._lineWidth=t.lineWidth),this._spriteImageCanvas.width/r.maxSize*i},_updateMaterial:function(e,t){var r=e.get("blendMode")==="lighter"?T.additiveBlend:null,i=this._mesh.material;i.blend=r,i.set("lineWidth",t.lineWidth/Yo);var n=T.parseColor(t.stroke);i.set("strokeColor",n),i.transparent=!0,i.depthMask=!1,i.depthTest=!this.is2D,i.sortVertices=!this.is2D},_updateLabelBuilder:function(e,o,r){var i=e.getData(),n=this._mesh.geometry,a=n.attributes.position.value,o=this._startDataIndex,s=this._mesh.sizeScale;this._labelsBuilder.updateData(i,o,r),this._labelsBuilder.getLabelPosition=function(l,h,u){var f=(l-o)*3;return[a[f],a[f+1],a[f+2]]},this._labelsBuilder.getLabelDistance=function(l,h,u){var f=n.attributes.size.get(l-o)/s;return f/2+u},this._labelsBuilder.updateLabels()},_updateAnimation:function(e){T.updateVertexAnimation([["prevPosition","position"],["prevSize","size"]],this._prevMesh,this._mesh,e)},_updateHandler:function(e,t,r){var i=e.getData(),n=this._mesh,a=this,o=-1,s=e.coordinateSystem&&e.coordinateSystem.type==="cartesian3D",l;s&&(l=e.coordinateSystem.model),n.seriesIndex=e.seriesIndex,n.off("mousemove"),n.off("mouseout"),n.on("mousemove",function(h){var u=h.vertexIndex+a._startDataIndex;u!==o&&(this.highlightOnMouseover&&(this.downplay(i,o),this.highlight(i,u),this._labelsBuilder.updateLabels([u])),s&&r.dispatchAction({type:"grid3DShowAxisPointer",value:[i.get(e.coordDimToDataDim("x")[0],u),i.get(e.coordDimToDataDim("y")[0],u),i.get(e.coordDimToDataDim("z")[0],u)],grid3DIndex:l.componentIndex})),n.dataIndex=u,o=u},this),n.on("mouseout",function(h){var u=h.vertexIndex+a._startDataIndex;this.highlightOnMouseover&&(this.downplay(i,u),this._labelsBuilder.updateLabels()),o=-1,n.dataIndex=-1,s&&r.dispatchAction({type:"grid3DHideAxisPointer",grid3DIndex:l.componentIndex})},this)},updateLayout:function(e,t,r){var i=e.getData();if(!!this._mesh){var n=this._mesh.geometry.attributes.position.value,a=i.getLayout("points");if(this.is2D)for(var o=0;othis._endDataIndex||tthis._endDataIndex||t.05&&(o=!0),f!==s&&(l=!0),s=f,a=d}return o&&console.warn("Different symbol width / height ratio will be ignored."),l&&console.warn("Different symbol type will be ignored."),{maxSize:h,type:s,aspect:a}}};const xv=At.extend({type:"scatter3D",hasSymbolVisual:!0,__ecgl__:!0,init:function(e,t){this.groupGL=new T.Node,this._pointsBuilderList=[],this._currentStep=0},render:function(e,t,r){if(this.groupGL.removeAll(),!!e.getData().count()){var i=e.coordinateSystem;if(i&&i.viewGL){i.viewGL.add(this.groupGL),this._camera=i.viewGL.camera;var n=this._pointsBuilderList[0];n||(n=this._pointsBuilderList[0]=new pr(!1,r)),this._pointsBuilderList.length=1,this.groupGL.add(n.rootNode),n.update(e,t,r),n.updateView(i.viewGL.camera)}else throw new Error("Invalid coordinate system")}},incrementalPrepareRender:function(e,t,r){var i=e.coordinateSystem;if(i&&i.viewGL)i.viewGL.add(this.groupGL),this._camera=i.viewGL.camera;else throw new Error("Invalid coordinate system");this.groupGL.removeAll(),this._currentStep=0},incrementalRender:function(e,t,r,i){if(!(e.end<=e.start)){var n=this._pointsBuilderList[this._currentStep];n||(n=new pr(!1,i),this._pointsBuilderList[this._currentStep]=n),this.groupGL.add(n.rootNode),n.update(t,r,i,e.start,e.end),n.updateView(t.coordinateSystem.viewGL.camera),this._currentStep++}},updateCamera:function(){this._pointsBuilderList.forEach(function(e){e.updateView(this._camera)},this)},highlight:function(e,t,r,i){this._toggleStatus("highlight",e,t,r,i)},downplay:function(e,t,r,i){this._toggleStatus("downplay",e,t,r,i)},_toggleStatus:function(e,t,r,i,n){var a=t.getData(),o=K.queryDataIndex(a,n),s=e==="highlight";o!=null?Dt(Yr.normalizeToArray(o),function(l){for(var h=0;h0&&n[0]instanceof Array))throw new Error("Invalid coords "+JSON.stringify(n)+". Lines must have 2d coords array in data item.");t.push(n)}),{coordsList:t}}function Av(e,t){var r=e.getData(),i=e.get("polyline");r.setLayout("lineType",i?"polyline":"cubicBezier");var n=bl(r);r.each(function(a){var o=n.coordsList[a],s=i?El:wv;r.setItemLayout(a,s(o,t))})}function ts(e,t,r){var i=e.getData(),n=e.get("polyline"),a=bl(i);i.setLayout("lineType",n?"polyline":"cubicBezier"),i.each(function(o){var s=a.coordsList[o],l=n?El(s,t):Sv(s,t,r);i.setItemLayout(o,l)})}function Ev(e,t){e.eachSeriesByType("lines3D",function(r){var i=r.coordinateSystem;i.type==="globe"?Av(r,i):i.type==="geo3D"?ts(r,i,[0,1,0]):(i.type==="mapbox3D"||i.type==="maptalks3D")&&ts(r,i,[0,0,1])})}const bv=St.extend({type:"series.lines3D",dependencies:["globe"],visualStyleAccessPath:"lineStyle",visualDrawType:"stroke",getInitialData:function(e,t){var r=new Pt(["value"],this);return r.hasItemOption=!1,r.initData(e.data,[],function(i,n,a,o){if(i instanceof Array)return NaN;r.hasItemOption=!0;var s=i.value;if(s!=null)return s instanceof Array?s[o]:s}),r},defaultOption:{coordinateSystem:"globe",globeIndex:0,geo3DIndex:0,zlevel:-10,polyline:!1,effect:{show:!1,period:4,trailWidth:4,trailLength:.2,spotIntensity:6},silent:!0,blendMode:"source-over",lineStyle:{width:1,opacity:.5}}}),Cv=`@export ecgl.trail2.vertex attribute vec3 position: POSITION; attribute vec3 positionPrev; attribute vec3 positionNext; attribute float offset; attribute float dist; attribute float distAll; attribute float start; attribute vec4 a_Color : COLOR; uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; uniform vec4 viewport : VIEWPORT; uniform float near : NEAR; uniform float speed : 0; uniform float trailLength: 0.3; uniform float time; uniform float period: 1000; uniform float spotSize: 1; varying vec4 v_Color; varying float v_Percent; varying float v_SpotPercent; @import ecgl.common.wireframe.vertexHeader @import ecgl.lines3D.clipNear void main() { @import ecgl.lines3D.expandLine gl_Position = currProj; v_Color = a_Color; @import ecgl.common.wireframe.vertexMain #ifdef CONSTANT_SPEED float t = mod((speed * time + start) / distAll, 1. + trailLength) - trailLength; #else float t = mod((time + start) / period, 1. + trailLength) - trailLength; #endif float trailLen = distAll * trailLength; v_Percent = (dist - t * distAll) / trailLen; v_SpotPercent = spotSize / distAll; } @end @export ecgl.trail2.fragment uniform vec4 color : [1.0, 1.0, 1.0, 1.0]; uniform float spotIntensity: 5; varying vec4 v_Color; varying float v_Percent; varying float v_SpotPercent; @import ecgl.common.wireframe.fragmentHeader @import clay.util.srgb void main() { if (v_Percent > 1.0 || v_Percent < 0.0) { discard; } float fade = v_Percent; #ifdef SRGB_DECODE gl_FragColor = sRGBToLinear(color * v_Color); #else gl_FragColor = color * v_Color; #endif @import ecgl.common.wireframe.fragmentMain if (v_Percent > (1.0 - v_SpotPercent)) { gl_FragColor.rgb *= spotIntensity; } gl_FragColor.a *= fade; } @end`;var rs=Me.vec3;function Lv(e){return e>0?1:-1}T.Shader.import(Cv);const Mv=T.Mesh.extend(function(){var e=new T.Material({shader:new T.Shader(T.Shader.source("ecgl.trail2.vertex"),T.Shader.source("ecgl.trail2.fragment")),transparent:!0,depthMask:!1}),t=new yr({dynamic:!0});return t.createAttribute("dist","float",1),t.createAttribute("distAll","float",1),t.createAttribute("start","float",1),{geometry:t,material:e,culling:!1,$ignorePicking:!0}},{updateData:function(e,t,r){var i=e.hostModel,n=this.geometry,a=i.getModel("effect"),o=a.get("trailWidth")*t.getDevicePixelRatio(),s=a.get("trailLength"),l=i.get("effect.constantSpeed"),h=i.get("effect.period")*1e3,u=l!=null;this.getScene()||console.error("TrailMesh must been add to scene before updateData"),u?this.material.set("speed",l/1e3):this.material.set("period",h),this.material[u?"define":"undefine"]("vertex","CONSTANT_SPEED");var f=i.get("polyline");n.trailLength=s,this.material.set("trailLength",s),n.resetOffset(),["position","positionPrev","positionNext"].forEach(function(b){n.attributes[b].value=r.attributes[b].value});var d=["dist","distAll","start","offset","color"];d.forEach(function(b){n.attributes[b].init(n.vertexCount)}),n.indices=r.indices;var c=[],v=a.get("trailColor"),p=a.get("trailOpacity"),m=v!=null,g=p!=null;this.updateWorldTransform();var x=this.worldTransform.x.len(),y=this.worldTransform.y.len(),_=this.worldTransform.z.len(),w=0,S=0;e.each(function(b){var A=e.getItemLayout(b),C=g?p:Ve(e,b),P=ke(e,b);C==null&&(C=1),c=T.parseColor(m?v:P,c),c[3]*=C;for(var L=f?r.getPolylineVertexCount(A):r.getCubicCurveVertexCount(A[0],A[1],A[2],A[3]),R=0,I=[],D=[],O=w;Ow&&(R+=rs.dist(I,D)),n.attributes.dist.set(O,R),rs.copy(D,I);S=Math.max(S,R);for(var z=Math.random()*(u?R:h),O=w;O0;this._updateSurfaceMesh(this._surfaceMesh,e,u,c);var v=this._surfaceMesh.material;c?(v.define("WIREFRAME_QUAD"),v.set("wireframeLineWidth",d),v.set("wireframeLineColor",T.parseColor(f.get("lineStyle.color")))):v.undefine("WIREFRAME_QUAD"),this._initHandler(e,r),this._updateAnimation(e)},_updateAnimation:function(e){T.updateVertexAnimation([["prevPosition","position"],["prevNormal","normal"]],this._prevSurfaceMesh,this._surfaceMesh,e)},_createSurfaceMesh:function(){var e=new T.Mesh({geometry:new T.Geometry({dynamic:!0,sortTriangles:!0}),shadowDepthMaterial:new T.Material({shader:new T.Shader(T.Shader.source("ecgl.sm.depth.vertex"),T.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,Ia),e},_initHandler:function(e,t){var r=e.getData(),i=this._surfaceMesh,n=e.coordinateSystem;function a(s,l){for(var h=1/0,u=-1,f=[],d=0;d=0){var h=[];i.geometry.attributes.position.get(l,h);for(var u=n.pointToData(h),f=1/0,d=-1,c=[],v=0;v65535?Uint32Array:Uint16Array)((v-1)*(p-1)*6),S=function(Ie,Et,$e){$e[1]=Ie*p+Et,$e[0]=Ie*p+Et+1,$e[3]=(Ie+1)*p+Et+1,$e[2]=(Ie+1)*p+Et},b=!1;if(l){var A=[],C=[],P=0;g?u.init(n.vertexCount):u.value=null;for(var L=[[],[],[]],R=[],I=[],D=or.create(),O=function(Ie,Et,$e){var bn=Et*3;return $e[0]=Ie[bn],$e[1]=Ie[bn+1],$e[2]=Ie[bn+2],$e},z=new Float32Array(o.length),V=new Float32Array(o.length/3*4),F=0;F0;){if(Math.floor(l/f)===l/f)return[f,l/f];f--}return f=Math.floor(Math.sqrt(l)),[f,f]},dispose:function(){this.groupGL.removeAll()},remove:function(){this.groupGL.removeAll()}});function Gv(e){e.registerChartView(Uv),e.registerSeriesModel(Bv),e.registerLayout(function(t,r){t.eachSeriesByType("surface",function(i){var n=i.coordinateSystem;(!n||n.type!=="cartesian3D")&&console.error("Surface chart only support cartesian3D coordinateSystem");var a=i.getData(),o=new Float32Array(3*a.count()),s=[NaN,NaN,NaN];if(n&&n.type==="cartesian3D"){var l=n.dimensions,h=l.map(function(u){return i.coordDimToDataDim(u)[0]});a.each(h,function(u,f,d,c){var v;a.hasValue(c)?v=n.dataToPoint([u,f,d]):v=s,o[c*3]=v[0],o[c*3+1]=v[1],o[c*3+2]=v[2]})}a.setLayout("points",o)})})}Ye(Gv);function ns(e,t){for(var r=[],i=0;i "+d)),h++)}var c,v=Ei(e,{coordDimensions:["value"]});c=new Pt(v,r),c.initData(e);var p=new Pt(["value"],r);return p.initData(l,s),n&&n(c,p),dh({mainData:c,struct:a,structAttr:"graph",datas:{node:c,edge:p},datasAttr:{node:"data",edge:"edgeData"}}),a.update(),a}var hi=St.extend({type:"series.graphGL",visualStyleAccessPath:"itemStyle",hasSymbolVisual:!0,init:function(e){hi.superApply(this,"init",arguments),this.legendDataProvider=function(){return this._categoriesData},this._updateCategoriesData()},mergeOption:function(e){hi.superApply(this,"mergeOption",arguments),this._updateCategoriesData()},getFormattedLabel:function(e,t,r,i){var n=Yr.getFormattedLabel(this,e,t,r,i);if(n==null){var a=this.getData(),o=a.dimensions[a.dimensions.length-1];n=a.get(o,e)}return n},getInitialData:function(e,t){var r=e.edges||e.links||[],i=e.data||e.nodes||[],n=this;if(i&&r)return Zv(i,r,this,!0,a).data;function a(o,s){o.wrapMethod("getItemModel",function(f){const d=n._categoriesModels,c=f.getShallow("category"),v=d[c];return v&&(v.parentModel=f.parentModel,f.parentModel=v),f});const l=t.getModel([]).getModel;function h(f,d){const c=l.call(this,f,d);return c.resolveParentPath=u,c}s.wrapMethod("getItemModel",function(f){return f.resolveParentPath=u,f.getModel=h,f});function u(f){if(f&&(f[0]==="label"||f[1]==="label")){const d=f.slice();return f[0]==="label"?d[0]="edgeLabel":f[1]==="label"&&(d[1]="edgeLabel"),d}return f}}},getGraph:function(){return this.getData().graph},getEdgeData:function(){return this.getGraph().edgeData},getCategoriesData:function(){return this._categoriesData},formatTooltip:function(e,t,r){if(r==="edge"){var i=this.getData(),n=this.getDataParams(e,r),a=i.graph.getEdgeByIndex(e),o=i.getName(a.node1.dataIndex),s=i.getName(a.node2.dataIndex),l=[];return o!=null&&l.push(o),s!=null&&l.push(s),l=Mr(l.join(" > ")),n.value&&(l+=" : "+Mr(n.value)),l}else return hi.superApply(this,"formatTooltip",arguments)},_updateCategoriesData:function(){var e=(this.option.categories||[]).map(function(r){return r.value!=null?r:Object.assign({value:0},r)}),t=new Pt(["value"],this);t.initData(e),this._categoriesData=t,this._categoriesModels=t.mapArray(function(r){return t.getItemModel(r,!0)})},setView:function(e){e.zoom!=null&&(this.option.zoom=e.zoom),e.offset!=null&&(this.option.offset=e.offset)},setNodePosition:function(e){for(var t=0;t65535?this.indices instanceof Uint16Array&&(this.indices=new Uint32Array(this.indices)):this.indices instanceof Uint32Array&&(this.indices=new Uint16Array(this.indices)))},setTriangleCount:function(e){this.triangleCount!==e&&(e===0?this.indices=null:this.indices=this.vertexCount>65535?new Uint32Array(e*3):new Uint16Array(e*3))},_getCubicCurveApproxStep:function(e,t,r,i){var n=Oe.dist(e,t)+Oe.dist(r,t)+Oe.dist(i,r),a=1/(n+1)*this.segmentScale;return a},getCubicCurveVertexCount:function(e,t,r,i){var n=this._getCubicCurveApproxStep(e,t,r,i),a=Math.ceil(1/n);return this.useNativeLine?a*2:a*2+2},getCubicCurveTriangleCount:function(e,t,r,i){var n=this._getCubicCurveApproxStep(e,t,r,i),a=Math.ceil(1/n);return this.useNativeLine?0:a*2},getLineVertexCount:function(){return this.getPolylineVertexCount(as)},getLineTriangleCount:function(){return this.getPolylineTriangleCount(as)},getPolylineVertexCount:function(e){var t;if(typeof e=="number")t=e;else{var r=typeof e[0]!="number";t=r?e.length:e.length/2}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/2}return this.useNativeLine?0:(t-1)*2},addCubicCurve:function(e,t,r,i,n,a){a==null&&(a=1);for(var o=e[0],s=e[1],l=t[0],h=t[1],u=r[0],f=r[1],d=i[0],c=i[1],v=this._getCubicCurveApproxStep(e,t,r,i),p=v*v,m=p*v,g=3*v,x=3*p,y=6*p,_=6*m,w=o-l*2+u,S=s-h*2+f,b=(l-u)*3-o+d,A=(h-f)*3-s+c,C=o,P=s,L=(l-o)*g+w*x+b*m,R=(h-s)*g+S*x+A*m,I=w*y+b*_,D=S*y+A*_,O=b*_,z=A*_,V=0,F=0,le=Math.ceil(1/v),H=new Float32Array((le+1)*3),H=[],de=0,F=0;F1&&(C=L>0?Math.min(C,d):Math.max(C,d),P=R>0?Math.min(P,c):Math.max(P,c));this.addPolyline(H,n,a)},addLine:function(e,t,r,i){this.addPolyline([e,t],r,i)},addPolyline:function(){var e=Oe.create(),t=Oe.create(),r=Oe.create(),i=Oe.create(),n=[],a=[],o=[];return function(s,l,h,u,f){if(!!s.length){var d=typeof s[0]!="number";if(f==null&&(f=d?s.length:s.length/2),!(f<2)){u==null&&(u=0),h==null&&(h=1),this._itemVertexOffsets.push(this._vertexOffset);for(var c=d?typeof l[0]!="number":l.length/4===f,v=this.attributes.position,p=this.attributes.color,m=this.attributes.offset,g=this.attributes.normal,x=this.indices,y=this._vertexOffset,_,w=0;w1&&(v.copy(y,y-1),p.copy(y,y-1),y++);else{var A;if(w0){Oe.sub(e,n,o),Oe.sub(t,a,n),Oe.normalize(e,e),Oe.normalize(t,t),Oe.add(i,e,t),Oe.normalize(i,i);var C=h/2*Math.min(1/Oe.dot(e,i),2);r[0]=-i[1],r[1]=i[0],A=C}else Oe.sub(e,a,n),Oe.normalize(e,e),r[0]=-e[1],r[1]=e[0],A=h/2}else Oe.sub(e,n,o),Oe.normalize(e,e),r[0]=-e[1],r[1]=e[0],A=h/2;g.set(y,r),g.set(y+1,r),m.set(y,A),m.set(y+1,-A),Oe.copy(o,n),v.set(y,n),v.set(y+1,n),p.set(y,_),p.set(y+1,_),y+=2}if(this.useNativeLine)p.set(y,_),v.set(y,n),y++;else if(w>0){var P=this._faceOffset*3,x=this.indices;x[P]=y-4,x[P+1]=y-3,x[P+2]=y-2,x[P+3]=y-3,x[P+4]=y-1,x[P+5]=y-2,this._faceOffset+=2}}this._vertexOffset=y}}}}(),setItemColor:function(e,t){for(var r=this._itemVertexOffsets[e],i=e 0.0) { float factor = 0.0; if (preventOverlap) { float d = sqrt(d2); d = d - n0.w - n1.w; if (d > 0.0) { factor = scaling * n0.z * n1.z / (d * d); } else if (d < 0.0) { factor = scaling * 100.0 * n0.z * n1.z; } } else { factor = scaling * n0.z * n1.z / d2; } force += dir * factor; } } vec2 dir = gravityCenter - n0.xy; float d = 1.0; if (!strongGravityMode) { d = length(dir); } force += dir * n0.z * gravity / (d + 1.0); gl_FragColor = vec4(force, 0.0, 1.0); } @end @export ecgl.forceAtlas2.updateEdgeAttraction.vertex attribute vec2 node1; attribute vec2 node2; attribute float weight; uniform sampler2D positionTex; uniform float edgeWeightInfluence; uniform bool preventOverlap; uniform bool linLogMode; uniform vec2 windowSize: WINDOW_SIZE; varying vec2 v_Force; void main() { vec4 n0 = texture2D(positionTex, node1); vec4 n1 = texture2D(positionTex, node2); vec2 dir = n1.xy - n0.xy; float d = length(dir); float w; if (edgeWeightInfluence == 0.0) { w = 1.0; } else if (edgeWeightInfluence == 1.0) { w = weight; } else { w = pow(weight, edgeWeightInfluence); } vec2 offset = vec2(1.0 / windowSize.x, 1.0 / windowSize.y); vec2 scale = vec2((windowSize.x - 1.0) / windowSize.x, (windowSize.y - 1.0) / windowSize.y); vec2 pos = node1 * scale * 2.0 - 1.0; gl_Position = vec4(pos + offset, 0.0, 1.0); gl_PointSize = 1.0; float factor; if (preventOverlap) { d = d - n1.w - n0.w; } if (d <= 0.0) { v_Force = vec2(0.0); return; } if (linLogMode) { factor = w * log(d) / d; } else { factor = w; } v_Force = dir * factor; } @end @export ecgl.forceAtlas2.updateEdgeAttraction.fragment varying vec2 v_Force; void main() { gl_FragColor = vec4(v_Force, 0.0, 0.0); } @end @export ecgl.forceAtlas2.calcWeightedSum.vertex attribute vec2 node; varying vec2 v_NodeUv; void main() { v_NodeUv = node; gl_Position = vec4(0.0, 0.0, 0.0, 1.0); gl_PointSize = 1.0; } @end @export ecgl.forceAtlas2.calcWeightedSum.fragment varying vec2 v_NodeUv; uniform sampler2D positionTex; uniform sampler2D forceTex; uniform sampler2D forcePrevTex; void main() { vec2 force = texture2D(forceTex, v_NodeUv).rg; vec2 forcePrev = texture2D(forcePrevTex, v_NodeUv).rg; float mass = texture2D(positionTex, v_NodeUv).z; float swing = length(force - forcePrev) * mass; float traction = length(force + forcePrev) * 0.5 * mass; gl_FragColor = vec4(swing, traction, 0.0, 0.0); } @end @export ecgl.forceAtlas2.calcGlobalSpeed uniform sampler2D globalSpeedPrevTex; uniform sampler2D weightedSumTex; uniform float jitterTolerence; void main() { vec2 weightedSum = texture2D(weightedSumTex, vec2(0.5)).xy; float prevGlobalSpeed = texture2D(globalSpeedPrevTex, vec2(0.5)).x; float globalSpeed = jitterTolerence * jitterTolerence * weightedSum.y / weightedSum.x; if (prevGlobalSpeed > 0.0) { globalSpeed = min(globalSpeed / prevGlobalSpeed, 1.5) * prevGlobalSpeed; } gl_FragColor = vec4(globalSpeed, 0.0, 0.0, 1.0); } @end @export ecgl.forceAtlas2.updatePosition uniform sampler2D forceTex; uniform sampler2D forcePrevTex; uniform sampler2D positionTex; uniform sampler2D globalSpeedTex; varying vec2 v_Texcoord; void main() { vec2 force = texture2D(forceTex, v_Texcoord).xy; vec2 forcePrev = texture2D(forcePrevTex, v_Texcoord).xy; vec4 node = texture2D(positionTex, v_Texcoord); float globalSpeed = texture2D(globalSpeedTex, vec2(0.5)).r; float swing = length(force - forcePrev); float speed = 0.1 * globalSpeed / (0.1 + globalSpeed * sqrt(swing)); float df = length(force); if (df > 0.0) { speed = min(df * speed, 10.0) / df; gl_FragColor = vec4(node.xy + speed * force, node.zw); } else { gl_FragColor = node; } } @end @export ecgl.forceAtlas2.edges.vertex uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; attribute vec2 node; attribute vec4 a_Color : COLOR; varying vec4 v_Color; uniform sampler2D positionTex; void main() { gl_Position = worldViewProjection * vec4( texture2D(positionTex, node).xy, -10.0, 1.0 ); v_Color = a_Color; } @end @export ecgl.forceAtlas2.edges.fragment uniform vec4 color : [1.0, 1.0, 1.0, 1.0]; varying vec4 v_Color; void main() { gl_FragColor = color * v_Color; } @end`;T.Shader.import(qv);var ea={repulsionByDegree:!0,linLogMode:!1,strongGravityMode:!1,gravity:1,scaling:1,edgeWeightInfluence:1,jitterTolerence:.1,preventOverlap:!1,dissuadeHubs:!1,gravityCenter:null};function Ue(e){var t={type:T.Texture.FLOAT,minFilter:T.Texture.NEAREST,magFilter:T.Texture.NEAREST};this._positionSourceTex=new T.Texture2D(t),this._positionSourceTex.flipY=!1,this._positionTex=new T.Texture2D(t),this._positionPrevTex=new T.Texture2D(t),this._forceTex=new T.Texture2D(t),this._forcePrevTex=new T.Texture2D(t),this._weightedSumTex=new T.Texture2D(t),this._weightedSumTex.width=this._weightedSumTex.height=1,this._globalSpeedTex=new T.Texture2D(t),this._globalSpeedPrevTex=new T.Texture2D(t),this._globalSpeedTex.width=this._globalSpeedTex.height=1,this._globalSpeedPrevTex.width=this._globalSpeedPrevTex.height=1,this._nodeRepulsionPass=new Re({fragment:T.Shader.source("ecgl.forceAtlas2.updateNodeRepulsion")}),this._positionPass=new Re({fragment:T.Shader.source("ecgl.forceAtlas2.updatePosition")}),this._globalSpeedPass=new Re({fragment:T.Shader.source("ecgl.forceAtlas2.calcGlobalSpeed")}),this._copyPass=new Re({fragment:T.Shader.source("clay.compositor.output")});var r=function(i){i.blendEquation(i.FUNC_ADD),i.blendFunc(i.ONE,i.ONE)};this._edgeForceMesh=new T.Mesh({geometry:new T.Geometry({attributes:{node1:new T.Geometry.Attribute("node1","float",2),node2:new T.Geometry.Attribute("node2","float",2),weight:new T.Geometry.Attribute("weight","float",1)},dynamic:!0,mainAttribute:"node1"}),material:new T.Material({transparent:!0,shader:T.createShader("ecgl.forceAtlas2.updateEdgeAttraction"),blend:r,depthMask:!1,depthText:!1}),mode:T.Mesh.POINTS}),this._weightedSumMesh=new T.Mesh({geometry:new T.Geometry({attributes:{node:new T.Geometry.Attribute("node","float",2)},dynamic:!0,mainAttribute:"node"}),material:new T.Material({transparent:!0,shader:T.createShader("ecgl.forceAtlas2.calcWeightedSum"),blend:r,depthMask:!1,depthText:!1}),mode:T.Mesh.POINTS}),this._framebuffer=new qe({depthBuffer:!1}),this._dummyCamera=new T.OrthographicCamera({left:-1,right:1,top:1,bottom:-1,near:0,far:100}),this._globalSpeed=0}Ue.prototype.updateOption=function(e){for(var t in ea)this[t]=ea[t];var r=this._nodes.length;if(r>5e4?this.jitterTolerence=10:r>5e3?this.jitterTolerence=1:this.jitterTolerence=.1,r>100?this.scaling=2:this.scaling=10,e)for(var t in ea)e[t]!=null&&(this[t]=e[t]);if(this.repulsionByDegree)for(var i=this._positionSourceTex.pixels,n=0;ne};Ue.prototype._swapTexture=function(){var e=this._positionPrevTex;this._positionPrevTex=this._positionTex,this._positionTex=e;var e=this._forcePrevTex;this._forcePrevTex=this._forceTex,this._forceTex=e;var e=this._globalSpeedPrevTex;this._globalSpeedPrevTex=this._globalSpeedTex,this._globalSpeedTex=e};Ue.prototype._initFromSource=function(e){this._framebuffer.attach(this._positionPrevTex),this._framebuffer.bind(e),this._copyPass.setUniform("texture",this._positionSourceTex),this._copyPass.render(e),e.gl.clearColor(0,0,0,0),this._framebuffer.attach(this._forcePrevTex),e.gl.clear(e.gl.COLOR_BUFFER_BIT),this._framebuffer.attach(this._globalSpeedPrevTex),e.gl.clear(e.gl.COLOR_BUFFER_BIT),this._framebuffer.unbind(e)};Ue.prototype._resize=function(e,t){["_positionSourceTex","_positionTex","_positionPrevTex","_forceTex","_forcePrevTex"].forEach(function(r){this[r].width=e,this[r].height=t,this[r].dirty()},this)};Ue.prototype.dispose=function(e){this._framebuffer.dispose(e),this._copyPass.dispose(e),this._nodeRepulsionPass.dispose(e),this._positionPass.dispose(e),this._globalSpeedPass.dispose(e),this._edgeForceMesh.geometry.dispose(e),this._weightedSumMesh.geometry.dispose(e),this._positionSourceTex.dispose(e),this._positionTex.dispose(e),this._positionPrevTex.dispose(e),this._forceTex.dispose(e),this._forcePrevTex.dispose(e),this._weightedSumTex.dispose(e),this._globalSpeedTex.dispose(e),this._globalSpeedPrevTex.dispose(e)};function Yv(){var e={create:function(){return new Float32Array(2)},dist:function(l,h){var u=h[0]-l[0],f=h[1]-l[1];return Math.sqrt(u*u+f*f)},len:function(l){var h=l[0],u=l[1];return Math.sqrt(h*h+u*u)},scaleAndAdd:function(l,h,u,f){return l[0]=h[0]+u[0]*f,l[1]=h[1]+u[1]*f,l},scale:function(l,h,u){return l[0]=h[0]*u,l[1]=h[1]*u,l},add:function(l,h,u){return l[0]=h[0]+u[0],l[1]=h[1]+u[1],l},sub:function(l,h,u){return l[0]=h[0]-u[0],l[1]=h[1]-u[1],l},normalize:function(l,h){var u=h[0],f=h[1],d=u*u+f*f;return d>0&&(d=1/Math.sqrt(d),l[0]=h[0]*d,l[1]=h[1]*d),l},negate:function(l,h){return l[0]=-h[0],l[1]=-h[1],l},copy:function(l,h){return l[0]=h[0],l[1]=h[1],l},set:function(l,h,u){return l[0]=h,l[1]=u,l}};function t(){this.subRegions=[],this.nSubRegions=0,this.node=null,this.mass=0,this.centerOfMass=null,this.bbox=new Float32Array(4),this.size=0}var r=t.prototype;r.beforeUpdate=function(){for(var l=0;l=l&&this.bbox[1]<=h&&this.bbox[3]>=h},r.setBBox=function(l,h,u,f){this.bbox[0]=l,this.bbox[1]=h,this.bbox[2]=u,this.bbox[3]=f,this.size=(u-l+f-h)/2},r._newSubRegion=function(){var l=this.subRegions[this.nSubRegions];return l||(l=new t,this.subRegions[this.nSubRegions]=l),this.nSubRegions++,l},r._addNodeToSubRegion=function(l){var h=this.findSubRegion(l.position[0],l.position[1]),u=this.bbox;if(!h){var f=(u[0]+u[2])/2,d=(u[1]+u[3])/2,c=(u[2]-u[0])/2,v=(u[3]-u[1])/2,p=l.position[0]>=f?1:0,m=l.position[1]>=d?1:0,h=this._newSubRegion();h.setBBox(p*c+u[0],m*v+u[1],(p+1)*c+u[0],(m+1)*v+u[1])}h.addNode(l)},r._updateCenterOfMass=function(l){this.centerOfMass==null&&(this.centerOfMass=new Float32Array(2));var h=this.centerOfMass[0]*this.mass,u=this.centerOfMass[1]*this.mass;h+=l.position[0]*l.mass,u+=l.position[1]*l.mass,this.mass+=l.mass,this.centerOfMass[0]=h/this.mass,this.centerOfMass[1]=u/this.mass};function i(){this.position=new Float32Array(2),this.force=e.create(),this.forcePrev=e.create(),this.mass=1,this.inDegree=0,this.outDegree=0}function n(l,h){this.source=l,this.target=h,this.weight=1}function a(){this.autoSettings=!0,this.barnesHutOptimize=!0,this.barnesHutTheta=1.5,this.repulsionByDegree=!0,this.linLogMode=!1,this.strongGravityMode=!1,this.gravity=1,this.scaling=1,this.edgeWeightInfluence=1,this.jitterTolerence=.1,this.preventOverlap=!1,this.dissuadeHubs=!1,this.rootRegion=new t,this.rootRegion.centerOfMass=e.create(),this.nodes=[],this.edges=[],this.bbox=new Float32Array(4),this.gravityCenter=null,this._massArr=null,this._swingingArr=null,this._sizeArr=null,this._globalSpeed=0}var o=a.prototype;o.initNodes=function(l,h,u){var f=h.length;this.nodes.length=0;for(var d=typeof u<"u",c=0;c0&&(this.strongGravityMode?this.applyNodeStrongGravity(f):this.applyNodeGravity(f))}for(var h=0;h0&&(y=Math.min(y/this._globalSpeed,1.5)*this._globalSpeed),this._globalSpeed=y;for(var h=0;h0&&(_=Math.min(w*_,10)/w,e.scaleAndAdd(u.position,u.position,u.force,_))}},o.applyRegionToNodeRepulsion=function(){var l=e.create();return function(u,f){if(u.node)this.applyNodeToNodeRepulsion(u.node,f,!0);else{e.sub(l,f.position,u.centerOfMass);var d=l[0]*l[0]+l[1]*l[1];if(d>this.barnesHutTheta*u.size*u.size){var c=this.scaling*f.mass*u.mass/d;e.scaleAndAdd(f.force,f.force,l,c)}else for(var v=0;v0)v=this.scaling*u.mass*f.mass/(p*p);else if(p<0)v=this.scaling*100*u.mass*f.mass;else return}else v=this.scaling*u.mass*f.mass/c;e.scaleAndAdd(u.force,u.force,l,v),e.scaleAndAdd(f.force,f.force,l,-v)}}}}(),o.applyEdgeAttraction=function(){var l=e.create();return function(u){var f=u.source,d=u.target;e.sub(l,f.position,d.position);var c=e.len(l),v;this.edgeWeightInfluence===0?v=1:this.edgeWeightInfluence===1?v=u.weight:v=Math.pow(u.weight,this.edgeWeightInfluence);var p;this.preventOverlap&&(c=c-f.size-d.size,c<=0)||(this.linLogMode?p=-v*Math.log(c+1)/(c+1):p=-v,e.scaleAndAdd(f.force,f.force,l,p),e.scaleAndAdd(d.force,d.force,l,-p))}}(),o.applyNodeGravity=function(){var l=e.create();return function(h){e.sub(l,this.gravityCenter,h.position);var u=e.len(l);e.scaleAndAdd(h.force,h.force,l,this.gravity*h.mass/(u+1))}}(),o.applyNodeStrongGravity=function(){var l=e.create();return function(h){e.sub(l,this.gravityCenter,h.position),e.scaleAndAdd(h.force,h.force,l,this.gravity*h.mass)}}(),o.updateBBox=function(){for(var l=1/0,h=1/0,u=-1/0,f=-1/0,d=0;d5e4?t.jitterTolerence=10:a>5e3?t.jitterTolerence=1:t.jitterTolerence=.1,a>100?t.scaling=2:t.scaling=10,a>1e3?t.barnesHutOptimize=!0:t.barnesHutOptimize=!1,e)for(var r in ci)e[r]!=null&&(t[r]=e[r]);if(!t.gravityCenter){for(var o=[1/0,1/0],s=[-1/0,-1/0],l=0;le};dt.prototype.getNodePosition=function(e,t){if(t||(t=new Float32Array(this._nodes.length*2)),this._positionArr)for(var r=0;r0?1.1:.9,a=Math.max(Math.min(this._zoom*n,this.maxZoom),this.minZoom);n=a/this._zoom;var o=this._convertPos(r,i),s=(o.x-this._dx)*(n-1),l=(o.y-this._dy)*(n-1);this._dx-=s,this._dy-=l,this._zoom=a,this._needsUpdate=!0}}},dispose:function(){var e=this.zr;e.off("mousedown",this._mouseDownHandler),e.off("mousemove",this._mouseMoveHandler),e.off("mouseup",this._mouseUpHandler),e.off("mousewheel",this._mouseWheelHandler),e.off("globalout",this._mouseUpHandler),e.animation.off("frame",this._update)}});const Qv=Kv,$v=`@export ecgl.lines2D.vertex uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; attribute vec2 position: POSITION; attribute vec4 a_Color : COLOR; varying vec4 v_Color; #ifdef POSITIONTEXTURE_ENABLED uniform sampler2D positionTexture; #endif void main() { gl_Position = worldViewProjection * vec4(position, -10.0, 1.0); v_Color = a_Color; } @end @export ecgl.lines2D.fragment uniform vec4 color : [1.0, 1.0, 1.0, 1.0]; varying vec4 v_Color; void main() { gl_FragColor = color * v_Color; } @end @export ecgl.meshLines2D.vertex attribute vec2 position: POSITION; attribute vec2 normal; attribute float offset; attribute vec4 a_Color : COLOR; uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; uniform vec4 viewport : VIEWPORT; varying vec4 v_Color; varying float v_Miter; void main() { vec4 p2 = worldViewProjection * vec4(position + normal, -10.0, 1.0); gl_Position = worldViewProjection * vec4(position, -10.0, 1.0); p2.xy /= p2.w; gl_Position.xy /= gl_Position.w; vec2 N = normalize(p2.xy - gl_Position.xy); gl_Position.xy += N * offset / viewport.zw * 2.0; gl_Position.xy *= gl_Position.w; v_Color = a_Color; } @end @export ecgl.meshLines2D.fragment uniform vec4 color : [1.0, 1.0, 1.0, 1.0]; varying vec4 v_Color; varying float v_Miter; void main() { gl_FragColor = color * v_Color; } @end`;var Wi=Me.vec2;T.Shader.import($v);var Jv=1;const ep=At.extend({type:"graphGL",__ecgl__:!0,init:function(e,t){this.groupGL=new T.Node,this.viewGL=new ce("orthographic"),this.viewGL.camera.left=this.viewGL.camera.right=0,this.viewGL.add(this.groupGL),this._pointsBuilder=new pr(!0,t),this._forceEdgesMesh=new T.Mesh({material:new T.Material({shader:T.createShader("ecgl.forceAtlas2.edges"),transparent:!0,depthMask:!1,depthTest:!1}),$ignorePicking:!0,geometry:new T.Geometry({attributes:{node:new T.Geometry.Attribute("node","float",2),color:new T.Geometry.Attribute("color","float",4,"COLOR")},dynamic:!0,mainAttribute:"node"}),renderOrder:-1,mode:T.Mesh.LINES}),this._edgesMesh=new T.Mesh({material:new T.Material({shader:T.createShader("ecgl.meshLines2D"),transparent:!0,depthMask:!1,depthTest:!1}),$ignorePicking:!0,geometry:new Dl({useNativeLine:!1,dynamic:!0}),renderOrder:-1,culling:!1}),this._layoutId=0,this._control=new Qv({zr:t.getZr(),viewGL:this.viewGL}),this._control.setTarget(this.groupGL),this._control.init(),this._clickHandler=this._clickHandler.bind(this)},render:function(e,t,r){this.groupGL.add(this._pointsBuilder.rootNode),this._model=e,this._api=r,this._initLayout(e,t,r),this._pointsBuilder.update(e,t,r),this._forceLayoutInstance instanceof Ue||this.groupGL.remove(this._forceEdgesMesh),this._updateCamera(e,r),this._control.off("update"),this._control.on("update",function(){r.dispatchAction({type:"graphGLRoam",seriesId:e.id,zoom:this._control.getZoom(),offset:this._control.getOffset()}),this._pointsBuilder.updateView(this.viewGL.camera)},this),this._control.setZoom(K.firstNotNull(e.get("zoom"),1)),this._control.setOffset(e.get("offset")||[0,0]);var i=this._pointsBuilder.getPointsMesh();if(i.off("mousemove",this._mousemoveHandler),i.off("mouseout",this._mouseOutHandler,this),r.getZr().off("click",this._clickHandler),this._pointsBuilder.highlightOnMouseover=!0,e.get("focusNodeAdjacency")){var n=e.get("focusNodeAdjacencyOn");n==="click"?r.getZr().on("click",this._clickHandler):n==="mouseover"?(i.on("mousemove",this._mousemoveHandler,this),i.on("mouseout",this._mouseOutHandler,this),this._pointsBuilder.highlightOnMouseover=!1):console.warn("Unkown focusNodeAdjacencyOn value s"+n)}this._lastMouseOverDataIndex=-1},_clickHandler:function(e){if(!this._layouting){var t=this._pointsBuilder.getPointsMesh().dataIndex;t>=0?this._api.dispatchAction({type:"graphGLFocusNodeAdjacency",seriesId:this._model.id,dataIndex:t}):this._api.dispatchAction({type:"graphGLUnfocusNodeAdjacency",seriesId:this._model.id})}},_mousemoveHandler:function(e){if(!this._layouting){var t=this._pointsBuilder.getPointsMesh().dataIndex;t>=0?t!==this._lastMouseOverDataIndex&&this._api.dispatchAction({type:"graphGLFocusNodeAdjacency",seriesId:this._model.id,dataIndex:t}):this._mouseOutHandler(e),this._lastMouseOverDataIndex=t}},_mouseOutHandler:function(e){this._layouting||(this._api.dispatchAction({type:"graphGLUnfocusNodeAdjacency",seriesId:this._model.id}),this._lastMouseOverDataIndex=-1)},_updateForceEdgesGeometry:function(e,t){var r=this._forceEdgesMesh.geometry,i=t.getEdgeData(),n=0,a=this._forceLayoutInstance,o=i.count()*2;r.attributes.node.init(o),r.attributes.color.init(o),i.each(function(s){var l=e[s];r.attributes.node.set(n,a.getNodeUV(l.node1)),r.attributes.node.set(n+1,a.getNodeUV(l.node2));var h=ke(i,l.dataIndex),u=T.parseColor(h);u[3]*=K.firstNotNull(Ve(i,l.dataIndex),1),r.attributes.color.set(n,u),r.attributes.color.set(n+1,u),n+=2}),r.dirty()},_updateMeshLinesGeometry:function(){var t=this._model.getEdgeData(),e=this._edgesMesh.geometry,t=this._model.getEdgeData(),r=this._model.getData().getLayout("points");e.resetOffset(),e.setVertexCount(t.count()*e.getLineVertexCount()),e.setTriangleCount(t.count()*e.getLineTriangleCount());var i=[],n=[],a=["lineStyle","width"];this._originalEdgeColors=new Float32Array(t.count()*4),this._edgeIndicesMap=new Float32Array(t.count()),t.each(function(o){var s=t.graph.getEdgeByIndex(o),l=s.node1.dataIndex*2,h=s.node2.dataIndex*2;i[0]=r[l],i[1]=r[l+1],n[0]=r[h],n[1]=r[h+1];var u=ke(t,s.dataIndex),f=T.parseColor(u);f[3]*=K.firstNotNull(Ve(t,s.dataIndex),1);var d=t.getItemModel(s.dataIndex),c=K.firstNotNull(d.get(a),1)*this._api.getDevicePixelRatio();e.addLine(i,n,f,c);for(var v=0;v<4;v++)this._originalEdgeColors[s.dataIndex*4+v]=f[v];this._edgeIndicesMap[s.dataIndex]=o},this),e.dirty()},_updateForceNodesGeometry:function(e){for(var t=this._pointsBuilder.getPointsMesh(),r=[],i=0;i=v&&(h._syncNodePosition(e),c=0),a.getZr().refresh(),ta(function(){p(m)})})}};ta(function(){h._forceLayoutInstanceToDispose&&(h._forceLayoutInstanceToDispose.dispose(n.layer.renderer),h._forceLayoutInstanceToDispose=null),p(u)}),this._layouting=!0}}},stopLayout:function(e,t,r,i){i&&i.from!=null&&i.from!==this.uid||(this._layoutId=0,this.groupGL.remove(this._forceEdgesMesh),this.groupGL.add(this._edgesMesh),this._forceLayoutInstance&&(!this.viewGL.layer||(i&&i.beforeLayout||(this._syncNodePosition(e),this._updateAfterLayout(e,t,r)),this._api.getZr().refresh(),this._layouting=!1)))},_syncNodePosition:function(e){var t=this._forceLayoutInstance.getNodePosition(this.viewGL.layer.renderer);e.getData().setLayout("points",t),e.setNodePosition(t)},_updateAfterLayout:function(e,t,r){this._updateMeshLinesGeometry(),this._pointsBuilder.removePositionTexture(),this._pointsBuilder.updateLayout(e,t,r),this._pointsBuilder.updateView(this.viewGL.camera),this._pointsBuilder.updateLabels(),this._pointsBuilder.showLabels()},focusNodeAdjacency:function(e,t,r,i){var n=this._model.getData();this._downplayAll();var a=i.dataIndex,o=n.graph,s=[],l=o.getNodeByIndex(a);s.push(l),l.edges.forEach(function(u){u.dataIndex<0||(u.node1!==l&&s.push(u.node1),u.node2!==l&&s.push(u.node2))},this),this._pointsBuilder.fadeOutAll(.05),this._fadeOutEdgesAll(.05),s.forEach(function(u){this._pointsBuilder.highlight(n,u.dataIndex)},this),this._pointsBuilder.updateLabels(s.map(function(u){return u.dataIndex}));var h=[];l.edges.forEach(function(u){u.dataIndex>=0&&(this._highlightEdge(u.dataIndex),h.push(u))},this),this._focusNodes=s,this._focusEdges=h},unfocusNodeAdjacency:function(e,t,r,i){this._downplayAll(),this._pointsBuilder.fadeInAll(),this._fadeInEdgesAll(),this._pointsBuilder.updateLabels()},_highlightEdge:function(e){var t=this._model.getEdgeData().getItemModel(e),r=T.parseColor(t.get("emphasis.lineStyle.color")||t.get("lineStyle.color")),i=K.firstNotNull(t.get("emphasis.lineStyle.opacity"),t.get("lineStyle.opacity"),1);r[3]*=i,this._edgesMesh.geometry.setItemColor(this._edgeIndicesMap[e],r)},_downplayAll:function(){this._focusNodes&&this._focusNodes.forEach(function(e){this._pointsBuilder.downplay(this._model.getData(),e.dataIndex)},this),this._focusEdges&&this._focusEdges.forEach(function(e){this._downplayEdge(e.dataIndex)},this)},_downplayEdge:function(e){var t=this._getColor(e,[]);this._edgesMesh.geometry.setItemColor(this._edgeIndicesMap[e],t)},_setEdgeFade:function(){var e=[];return function(t,r){this._getColor(t,e),e[3]*=r,this._edgesMesh.geometry.setItemColor(this._edgeIndicesMap[t],e)}}(),_getColor:function(e,t){for(var r=0;r<4;r++)t[r]=this._originalEdgeColors[e*4+r];return t},_fadeOutEdgesAll:function(e){var t=this._model.getData().graph;t.eachEdge(function(r){this._setEdgeFade(r.dataIndex,e)},this)},_fadeInEdgesAll:function(){this._fadeOutEdgesAll(1)},_updateCamera:function(e,t){this.viewGL.setViewport(0,0,t.getWidth(),t.getHeight(),t.getDevicePixelRatio());for(var r=this.viewGL.camera,i=e.getData(),n=i.getLayout("points"),a=Wi.create(1/0,1/0),o=Wi.create(-1/0,-1/0),s=[],l=0;lr.left&&ur.top)){var f=Math.max(o[0]-a[0],10),d=f/t.getWidth()*t.getHeight();f*=1.4,d*=1.4,a[0]-=f*.2,r.left=a[0],r.top=h-d/2,r.bottom=h+d/2,r.right=f+a[0],r.near=0,r.far=100}},dispose:function(){var e=this.viewGL.layer.renderer;this._forceLayoutInstance&&this._forceLayoutInstance.dispose(e),this.groupGL.removeAll(),this._layoutId=-1,this._pointsBuilder.dispose()},remove:function(){this.groupGL.removeAll(),this._control.dispose()}});function Xi(e){return e instanceof Array||(e=[e,e]),e}function tp(e){e.registerChartView(ep),e.registerSeriesModel(jv),e.registerVisual(function(r){const i={};r.eachSeriesByType("graphGL",function(n){var a=n.getCategoriesData(),o=n.getData(),s={};a.each(function(l){var h=a.getName(l);s["ec-"+h]=l;var u=a.getItemModel(l),f=u.getModel("itemStyle").getItemStyle();f.fill||(f.fill=n.getColorFromPalette(h,i)),a.setItemVisual(l,"style",f);var d=["symbol","symbolSize","symbolKeepAspect"];for(let v=0;v2)throw new Error("flowGL can only be used on 2d coordinate systems.");i.push("vx","vy");var n=Ei(this.getSource(),{coordDimensions:i,encodeDefine:this.get("encode"),dimensionsDefine:this.get("dimensions")}),a=new Pt(n,this);return a.initData(this.getSource()),a},defaultOption:{coordinateSystem:"cartesian2d",zlevel:10,supersampling:1,particleType:"point",particleDensity:128,particleSize:1,particleSpeed:1,particleTrail:2,colorTexture:null,gridWidth:"auto",gridHeight:"auto",itemStyle:{color:"#fff",opacity:.8}}});var ip=oe.extend(function(){return{dynamic:!0,attributes:{position:new oe.Attribute("position","float",3,"POSITION")}}},{resetOffset:function(){this._vertexOffset=0,this._faceOffset=0},setLineCount:function(e){var t=this.attributes,r=4*e,i=2*e;this.vertexCount!==r&&t.position.init(r),this.triangleCount!==i&&(i===0?this.indices=null:this.indices=this.vertexCount>65535?new Uint32Array(i*3):new Uint16Array(i*3))},addLine:function(e){var t=this._vertexOffset;this.attributes.position.set(t,[e[0],e[1],1]),this.attributes.position.set(t+1,[e[0],e[1],-1]),this.attributes.position.set(t+2,[e[0],e[1],2]),this.attributes.position.set(t+3,[e[0],e[1],-2]),this.setTriangleIndices(this._faceOffset++,[t,t+1,t+2]),this.setTriangleIndices(this._faceOffset++,[t+1,t+2,t+3]),this._vertexOffset+=4}});const np=ip,ap=`@export ecgl.vfParticle.particle.fragment uniform sampler2D particleTexture; uniform sampler2D spawnTexture; uniform sampler2D velocityTexture; uniform float deltaTime; uniform float elapsedTime; uniform float speedScaling : 1.0; uniform vec2 textureSize; uniform vec4 region : [0, 0, 1, 1]; uniform float firstFrameTime; varying vec2 v_Texcoord; void main() { vec4 p = texture2D(particleTexture, v_Texcoord); bool spawn = false; if (p.w <= 0.0) { p = texture2D(spawnTexture, fract(v_Texcoord + elapsedTime / 10.0)); p.w -= firstFrameTime; spawn = true; } vec2 v = texture2D(velocityTexture, fract(p.xy * region.zw + region.xy)).xy; v = (v - 0.5) * 2.0; p.z = length(v); p.xy += v * deltaTime / 10.0 * speedScaling; p.w -= deltaTime; if (spawn || p.xy != fract(p.xy)) { p.z = 0.0; } p.xy = fract(p.xy); gl_FragColor = p; } @end @export ecgl.vfParticle.renderPoints.vertex #define PI 3.1415926 attribute vec2 texcoord : TEXCOORD_0; uniform sampler2D particleTexture; uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; uniform float size : 1.0; varying float v_Mag; varying vec2 v_Uv; void main() { vec4 p = texture2D(particleTexture, texcoord); if (p.w > 0.0 && p.z > 1e-5) { gl_Position = worldViewProjection * vec4(p.xy * 2.0 - 1.0, 0.0, 1.0); } else { gl_Position = vec4(100000.0, 100000.0, 100000.0, 1.0); } v_Mag = p.z; v_Uv = p.xy; gl_PointSize = size; } @end @export ecgl.vfParticle.renderPoints.fragment uniform vec4 color : [1.0, 1.0, 1.0, 1.0]; uniform sampler2D gradientTexture; uniform sampler2D colorTexture; uniform sampler2D spriteTexture; varying float v_Mag; varying vec2 v_Uv; void main() { gl_FragColor = color; #ifdef SPRITETEXTURE_ENABLED gl_FragColor *= texture2D(spriteTexture, gl_PointCoord); if (color.a == 0.0) { discard; } #endif #ifdef GRADIENTTEXTURE_ENABLED gl_FragColor *= texture2D(gradientTexture, vec2(v_Mag, 0.5)); #endif #ifdef COLORTEXTURE_ENABLED gl_FragColor *= texture2D(colorTexture, v_Uv); #endif } @end @export ecgl.vfParticle.renderLines.vertex #define PI 3.1415926 attribute vec3 position : POSITION; uniform sampler2D particleTexture; uniform sampler2D prevParticleTexture; uniform float size : 1.0; uniform vec4 vp: VIEWPORT; uniform mat4 worldViewProjection : WORLDVIEWPROJECTION; varying float v_Mag; varying vec2 v_Uv; @import clay.util.rand void main() { vec4 p = texture2D(particleTexture, position.xy); vec4 p2 = texture2D(prevParticleTexture, position.xy); p.xy = p.xy * 2.0 - 1.0; p2.xy = p2.xy * 2.0 - 1.0; if (p.w > 0.0 && p.z > 1e-5) { vec2 dir = normalize(p.xy - p2.xy); vec2 norm = vec2(dir.y / vp.z, -dir.x / vp.w) * sign(position.z) * size; if (abs(position.z) == 2.0) { gl_Position = vec4(p.xy + norm, 0.0, 1.0); v_Uv = p.xy; v_Mag = p.z; } else { gl_Position = vec4(p2.xy + norm, 0.0, 1.0); v_Mag = p2.z; v_Uv = p2.xy; } gl_Position = worldViewProjection * gl_Position; } else { gl_Position = vec4(100000.0, 100000.0, 100000.0, 1.0); } } @end @export ecgl.vfParticle.renderLines.fragment uniform vec4 color : [1.0, 1.0, 1.0, 1.0]; uniform sampler2D gradientTexture; uniform sampler2D colorTexture; varying float v_Mag; varying vec2 v_Uv; void main() { gl_FragColor = color; #ifdef GRADIENTTEXTURE_ENABLED gl_FragColor *= texture2D(gradientTexture, vec2(v_Mag, 0.5)); #endif #ifdef COLORTEXTURE_ENABLED gl_FragColor *= texture2D(colorTexture, v_Uv); #endif } @end `;N.import(ap);function op(e){var t=document.createElement("canvas");t.width=t.height=e;var r=t.getContext("2d");return r.fillStyle="#fff",r.arc(e/2,e/2,e/2,0,Math.PI*2),r.fill(),t}var ma=function(){this.motionBlurFactor=.99,this.vectorFieldTexture=new $({type:W.FLOAT,flipY:!1}),this.particleLife=[5,20],this._particleType="point",this._particleSize=1,this.particleColor=[1,1,1,1],this.particleSpeedScaling=1,this._thisFrameTexture=null,this._particlePass=null,this._spawnTexture=null,this._particleTexture0=null,this._particleTexture1=null,this._particlePointsMesh=null,this._surfaceFrameBuffer=null,this._elapsedTime=0,this._scene=null,this._camera=null,this._lastFrameTexture=null,this._supersampling=1,this._downsampleTextures=[],this._width=512,this._height=512,this.init()};ma.prototype={constructor:ma,init:function(){var e={type:W.FLOAT,minFilter:W.NEAREST,magFilter:W.NEAREST,useMipmap:!1};this._spawnTexture=new $(e),this._particleTexture0=new $(e),this._particleTexture1=new $(e),this._frameBuffer=new qe({depthBuffer:!1}),this._particlePass=new Re({fragment:N.source("ecgl.vfParticle.particle.fragment")}),this._particlePass.setUniform("velocityTexture",this.vectorFieldTexture),this._particlePass.setUniform("spawnTexture",this._spawnTexture),this._downsamplePass=new Re({fragment:N.source("clay.compositor.downsample")});var t=new lr({renderOrder:10,material:new gt({shader:new N(N.source("ecgl.vfParticle.renderPoints.vertex"),N.source("ecgl.vfParticle.renderPoints.fragment"))}),mode:lr.POINTS,geometry:new oe({dynamic:!0,mainAttribute:"texcoord0"})}),r=new lr({renderOrder:10,material:new gt({shader:new N(N.source("ecgl.vfParticle.renderLines.vertex"),N.source("ecgl.vfParticle.renderLines.fragment"))}),geometry:new np,culling:!1}),i=new lr({material:new gt({shader:new N(N.source("ecgl.color.vertex"),N.source("ecgl.color.fragment"))}),geometry:new yn});i.material.enableTexture("diffuseMap"),this._particlePointsMesh=t,this._particleLinesMesh=r,this._lastFrameFullQuadMesh=i,this._camera=new Fr,this._thisFrameTexture=new $,this._lastFrameTexture=new $},setParticleDensity:function(e,t){for(var r=e*t,i=new Float32Array(r*4),n=0,a=this.particleLife,o=0;o0?e[e.length-1]:this._lastFrameTexture},setRegion:function(e){this._particlePass.setUniform("region",e)},resize:function(e,t){this._lastFrameTexture.width=e*this._supersampling,this._lastFrameTexture.height=t*this._supersampling,this._thisFrameTexture.width=e*this._supersampling,this._thisFrameTexture.height=t*this._supersampling,this._width=e,this._height=t},setParticleSize:function(e){var t=this._getParticleMesh();if(e<=2){t.material.disableTexture("spriteTexture"),t.material.transparent=!1;return}this._spriteTexture||(this._spriteTexture=new $),(!this._spriteTexture.image||this._spriteTexture.image.width!==e)&&(this._spriteTexture.image=op(e),this._spriteTexture.dirty()),t.material.transparent=!0,t.material.enableTexture("spriteTexture"),t.material.set("spriteTexture",this._spriteTexture),this._particleSize=e},setGradientTexture:function(e){var t=this._getParticleMesh().material;t[e?"enableTexture":"disableTexture"]("gradientTexture"),t.setUniform("gradientTexture",e)},setColorTextureImage:function(e,t){var r=this._getParticleMesh().material;r.setTextureImage("colorTexture",e,t,{flipY:!0})},setParticleType:function(e){this._particleType=e},clearFrame:function(e){var t=this._frameBuffer;t.attach(this._lastFrameTexture),t.bind(e),e.gl.clear(e.gl.DEPTH_BUFFER_BIT|e.gl.COLOR_BUFFER_BIT),t.unbind(e)},setSupersampling:function(e){this._supersampling=e,this.resize(this._width,this._height)},_updateDownsampleTextures:function(e,t){for(var r=this._downsampleTextures,i=Math.max(Math.floor(Math.log(this._supersampling/t.getDevicePixelRatio())/Math.log(2)),0),n=2,a=this._width*this._supersampling,o=this._height*this._supersampling,s=0;s=359;s&&(n[0]>0&&(n[0]=0),a[0]0&&r[0]instanceof Array))throw new Error("Invalid coords "+JSON.stringify(r)+". Lines must have 2d coords array in data item.");return r},getLineCoordsCount:function(e){return this._flatCoordsOffset?this._flatCoordsOffset[e*2+1]:this._getCoordsFromItemModel(e).length},getLineCoords:function(e,t){if(this._flatCoordsOffset){for(var r=this._flatCoordsOffset[e*2],i=this._flatCoordsOffset[e*2+1],n=0;nr)throw new Error("Invalid data format.")}}return{flatCoordsOffset:new Uint32Array(i.buffer,0,o),flatCoords:n,count:s}}return{flatCoordsOffset:null,flatCoords:null,count:e.length}},getInitialData:function(e,t){var r=new Pt(["value"],this);return r.hasItemOption=!1,r.initData(e.data,[],function(i,n,a,o){if(i instanceof Array)return NaN;r.hasItemOption=!0;var s=i.value;if(s!=null)return s instanceof Array?s[o]:s}),r},defaultOption:{coordinateSystem:"geo",zlevel:10,progressive:1e4,progressiveThreshold:5e4,blendMode:"source-over",lineStyle:{opacity:.8},postEffect:{enable:!1,colorCorrection:{exposure:0,brightness:0,contrast:1,saturation:1,enable:!0}}}});const up=ga,fp=At.extend({type:"linesGL",__ecgl__:!0,init:function(e,t){this.groupGL=new T.Node,this.viewGL=new ce("orthographic"),this.viewGL.add(this.groupGL),this._glViewHelper=new zt(this.viewGL),this._nativeLinesShader=T.createShader("ecgl.lines3D"),this._meshLinesShader=T.createShader("ecgl.meshLines3D"),this._linesMeshes=[],this._currentStep=0},render:function(e,t,r){this.groupGL.removeAll(),this._glViewHelper.reset(e,r);var i=this._linesMeshes[0];i||(i=this._linesMeshes[0]=this._createLinesMesh(e)),this._linesMeshes.length=1,this.groupGL.add(i),this._updateLinesMesh(e,i,0,e.getData().count()),this.viewGL.setPostEffect(e.getModel("postEffect"),r)},incrementalPrepareRender:function(e,t,r){this.groupGL.removeAll(),this._glViewHelper.reset(e,r),this._currentStep=0,this.viewGL.setPostEffect(e.getModel("postEffect"),r)},incrementalRender:function(e,t,r,i){var n=this._linesMeshes[this._currentStep];n||(n=this._createLinesMesh(t),this._linesMeshes[this._currentStep]=n),this._updateLinesMesh(t,n,e.start,e.end),this.groupGL.add(n),i.getZr().refresh(),this._currentStep++},updateTransform:function(e,t,r){e.coordinateSystem.getRoamTransform&&this._glViewHelper.updateTransform(e,r)},_createLinesMesh:function(e){var t=new T.Mesh({$ignorePicking:!0,material:new T.Material({shader:T.createShader("ecgl.lines3D"),transparent:!0,depthMask:!1,depthTest:!1}),geometry:new Dl({segmentScale:10,useNativeLine:!0,dynamic:!1}),mode:T.Mesh.LINES,culling:!1});return t},_updateLinesMesh:function(e,t,r,i){var n=e.getData();t.material.blend=e.get("blendMode")==="lighter"?T.additiveBlend:null;var a=e.get("lineStyle.curveness")||0,o=e.get("polyline"),s=t.geometry,l=e.coordinateSystem,h=K.firstNotNull(e.get("lineStyle.width"),1);h>1?(t.material.shader!==this._meshLinesShader&&t.material.attachShader(this._meshLinesShader),t.mode=T.Mesh.TRIANGLES):(t.material.shader!==this._nativeLinesShader&&t.material.attachShader(this._nativeLinesShader),t.mode=T.Mesh.LINES),r=r||0,i=i||n.count(),s.resetOffset();var u=0,f=0,d=[],c=[],v=[],p=[],m=[],g=.3,x=.7;function y(){c[0]=d[0]*x+p[0]*g-(d[1]-p[1])*a,c[1]=d[1]*x+p[1]*g-(p[0]-d[0])*a,v[0]=d[0]*g+p[0]*x-(d[1]-p[1])*a,v[1]=d[1]*g+p[1]*x-(p[0]-d[0])*a}if(o||a!==0)for(var _=r;_