@maptalks/gpu 0.119.0 → 0.121.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @maptalks/gpu v0.119.0
2
+ * @maptalks/gpu v0.121.0
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2026 maptalks.com
5
5
  */
@@ -67,10 +67,10 @@ transcoders.getTranscoder = getTranscoder;
67
67
 
68
68
  function gltfLoaderExport(e){var t=function(){return "undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0};if(t().maptalks_gltf_loader)return;
69
69
  /*!
70
- * @maptalks/gltf-loader v0.119.0
70
+ * @maptalks/gltf-loader v0.121.0
71
71
  * LICENSE : UNLICENSED
72
72
  * (c) 2016-2026 maptalks.org
73
- */var s="undefined"!=typeof Float32Array?Float32Array:Array;function r(e,t,s){var r=t[0],n=t[1],i=t[2],a=t[3],o=t[4],f=t[5],u=t[6],h=t[7],c=t[8],l=t[9],d=t[10],m=t[11],g=t[12],p=t[13],b=t[14],_=t[15],y=s[0],x=s[1],w=s[2],T=s[3];return e[0]=y*r+x*o+w*c+T*g,e[1]=y*n+x*f+w*l+T*p,e[2]=y*i+x*u+w*d+T*b,e[3]=y*a+x*h+w*m+T*_,y=s[4],x=s[5],w=s[6],T=s[7],e[4]=y*r+x*o+w*c+T*g,e[5]=y*n+x*f+w*l+T*p,e[6]=y*i+x*u+w*d+T*b,e[7]=y*a+x*h+w*m+T*_,y=s[8],x=s[9],w=s[10],T=s[11],e[8]=y*r+x*o+w*c+T*g,e[9]=y*n+x*f+w*l+T*p,e[10]=y*i+x*u+w*d+T*b,e[11]=y*a+x*h+w*m+T*_,y=s[12],x=s[13],w=s[14],T=s[15],e[12]=y*r+x*o+w*c+T*g,e[13]=y*n+x*f+w*l+T*p,e[14]=y*i+x*u+w*d+T*b,e[15]=y*a+x*h+w*m+T*_,e}function n(){var e=new s(3);return s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function i(e,t,r){var n=new s(3);return n[0]=e,n[1]=t,n[2]=r,n}function a(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function o(e,t,s,r){return e[0]=t,e[1]=s,e[2]=r,e}function f(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e}function u(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e}function h(e,t,s,r,n){return e[0]=t,e[1]=s,e[2]=r,e[3]=n,e}function c(e,t,s){var r=t[0],n=t[1],i=t[2],a=t[3];return e[0]=s[0]*r+s[4]*n+s[8]*i+s[12]*a,e[1]=s[1]*r+s[5]*n+s[9]*i+s[13]*a,e[2]=s[2]*r+s[6]*n+s[10]*i+s[14]*a,e[3]=s[3]*r+s[7]*n+s[11]*i+s[15]*a,e}function l(){var e=new s(4);return s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)}),n(),function(){var e;e=new s(4),s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0);}();var d,m=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e};n(),i(1,0,0),i(0,1,0),l(),l(),d=new s(9),s!=Float32Array&&(d[1]=0,d[2]=0,d[3]=0,d[5]=0,d[6]=0,d[7]=0),d[0]=1,d[4]=1,d[8]=1;let g=0;function p(e){return null==e}function b(e){return !p(e)}function _(e){return !p(e)&&("string"==typeof e||null!==e.constructor&&e.constructor===String)}function y(e){for(let t=1;t<arguments.length;t++){const s=arguments[t];for(const t in s)e[t]=s[t];}return e}function x(e){switch(e){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5124:return Int32Array;case 5125:return Uint32Array;case 5126:return Float32Array}throw new Error("unsupported bufferView's component type: "+e)}function w(e){return 0===e.indexOf("data:")&&e.indexOf("base64,")>0}function T(e){const t=function(e){return "undefined"!=typeof self?self.atob(e):window.atob(e)}(e.substring(e.indexOf(",")+1)),s=t.length,r=new Uint8Array(s);for(let e=0;e<s;e++)r[e]=t.charCodeAt(e);return r.buffer}const E=[],O=[],I=[],R=[0,0,0],A=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}([]),q=[1,1,1];function B(e,t,s,r,n,i,a){const o=x(a),f=o.BYTES_PER_ELEMENT;if((0===n||n===r*f)&&i%f==0){const n=new o(t,i,s*r);return e.set(n),e}0===n&&(n=r*f);const u=new Uint8Array(r*f);for(let a=0;a<s;a++){let s=null;const h=new Uint8Array(t,n*a+i,r*f);u.set(h),s=new o(u.buffer,0,r);for(let t=0;t<r;t++)e[a*r+t]=s[t];}return e}const N="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function v(e,t,s){const r=new Uint8Array(e,t,s);return N.decode(r)}const P={get:function(e,t={},s){t||(t={});const r=new AbortController,n=r.signal,i=y({},t);i.signal=n,i.method||(i.method="GET"),i.referrerPolicy=i.referrerPolicy||"origin","undefined"==typeof window||i.referrer||(i.referrer=window.location.href),s&&(e=s(e));const a=fetch(e,i).then((e=>{const s=this._parseResponse(e,t.responseType);return s.message?s:s.then((s=>"arraybuffer"===t.responseType?{data:s,cacheControl:e.headers.get("Cache-Control"),expires:e.headers.get("Expires"),contentType:e.headers.get("Content-Type")}:s)).catch((e=>{if(!e.code||e.code!==DOMException.ABORT_ERR)throw e}))})).catch((e=>{if(!e.code||e.code!==DOMException.ABORT_ERR)throw e}));return a.xhr=r,a},_parseResponse:(e,t)=>200!==e.status?{status:e.status,statusText:e.statusText,message:`incorrect http request with status code(${e.status}): ${e.statusText}`}:"arraybuffer"===t?e.arrayBuffer():"json"===t?e.json():e.text(),getArrayBuffer:(e,t={},s)=>(t||(t={}),t.responseType="arraybuffer",P.get(e,t,s)),getJSON:function(e,t={},s){return t&&t.jsonp?P.jsonp(e):((t=t||{}).responseType="json",P.get(e,t,s))},jsonp:function(e){const t="_maptalks_jsonp_"+g++;e.match(/\?/)?e+="&callback="+t:e+="?callback="+t;let s=document.createElement("script");return s.type="text/javascript",s.src=e,new Promise((e=>{window[t]=function(r){document.getElementsByTagName("head")[0].removeChild(s),s=null,delete window[t],e(r);},document.getElementsByTagName("head")[0].appendChild(s);}))}};class M{constructor(e,t,s,r,n){this._requestImage=e,this.decoders=t,this._supportedFormats=s,this.images={},this._imgRequests={},this._fetchOptions=r||{},this._urlModifier=n;}requestImageFromBufferURI(e,t,s){if(this.buffers[e.id]){const r=this.buffers[e.id],n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}if(this._imgRequests[e.id])return this._imgRequests[e.id].then((()=>{const r=this.buffers[e.id],n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}));if(w(e.uri)){const r=this.buffers[e.id]=T(e.uri),n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}let r;const n=e.uri.indexOf("blob:")>=0;return r=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri,this._imgRequests[e.id]=P.getArrayBuffer(r,this._fetchOptions,this._urlModifier).then((r=>{const n=this.buffers[e.id]=r.data,i=this._createDataView(t,n);return this.getImageByBuffer(i,s)}))}getImageByBuffer(e,t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const s=this.decoders;if(s[t.mimeType])return s[t.mimeType](e,{supportedFormats:this._supportedFormats});if("image/crn"===t.mimeType||"image/ktx2"===t.mimeType||"image/cttf"===t.mimeType)throw new Error("missing transcoder for "+t.mimeType,"");return this._getImageInfo(t.id,e)}requestExternalImage(e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const t=0===e.uri.indexOf("data:image/")?e.uri:this.rootPath+"/"+e.uri;return this._imgRequests[e.id]?this._imgRequests[e.id].then((()=>this.images[e.id])):this._imgRequests[e.id]=this._getImageInfo(e.id,t)}_getImageInfo(e,t){return new Promise(((s,r)=>{let n=t;this._urlModifier&&(n=this._urlModifier(t)),this._requestImage(n,this._fetchOptions,((n,i)=>{n?r(n):(URL.revokeObjectURL(t),this.images[e]=i,s(this.images[e]));}));}))}}const S=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],V=[];class L{constructor(e,t,s,r,n){this.rootPath=e,this.gltf=t,this._enableInterleave=!1,this.glbBuffer=s,this.buffers={},this.requests={},this.accessors={},this._compareAccessor(),this._fetchOptions=r,this._urlModifier=n;}_requestData(e,t){const s=this.gltf,r=s.accessors[t];if(void 0===r.bufferView)return this.accessors[r.id]=this._toBufferData(e,t,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const n=s.bufferViews[r.bufferView];return this._requestBufferOfBufferView(n).then((s=>{const{buffer:n,byteOffset:i}=s;return this.accessors[r.id]=this._toBufferData(e,t,n,i)}))}_requestBufferOfBufferView(e){const t=this.gltf.buffers[e.buffer];if(this.buffers[t.id]){const e=this.buffers[t.id];return Promise.resolve({buffer:e,byteOffset:0})}if(this.requests[t.id])return this.requests[t.id].then((()=>{const e=this.buffers[t.id];return Promise.resolve({buffer:e,byteOffset:0})}));if("binary_glTF"!==e.buffer&&"KHR_binary_glTF"!==e.buffer&&t.uri){if(w(t.uri)){const e=this.buffers[t.id]=T(t.uri);return Promise.resolve({buffer:e,byteOffset:0})}let e;const s=t.uri.indexOf("blob:")>=0;return e=t.uri.indexOf("://")>0||s?t.uri:this.rootPath+"/"+t.uri,this.requests[t.id]=P.getArrayBuffer(e,this._fetchOptions,!s&&this._urlModifier).then((r=>(s&&URL.revokeObjectURL(e),{buffer:this.buffers[t.id]=r.data,byteOffset:0})))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}_toBufferData(e,t,s,r=0){const n=this.gltf,i=n.accessors[t],a=void 0!==i.bufferView?n.bufferViews[i.bufferView]:{},o=(a.byteOffset||0)+r,f=this._getTypeItemSize(i.type),u=x(i.componentType),h=a.byteStride||0,l={array:void 0,name:e,accessorName:t,byteLength:i.count*f*u.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:f,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(l.min=i.min),i.max&&(l.max=i.max),s)if(this._enableInterleave)l.byteStride=h,l.byteOffset=o+(i.byteOffset||0),!h||h===f*u.BYTES_PER_ELEMENT||"indices"===e||"input"===e||"output"===e||e.indexOf("morph")>=0?(l.array=this._typedArray(s,i.count,f,o+(i.byteOffset||0),u),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(s,o,a.byteLength);else if(i.interleaved){l.byteStride=0,l.byteOffset=0;const e=new u(i.count*f);if(l.array=B(e,s,i.count,f,h,o+(i.byteOffset||0),i.componentType),l.extensions&&l.extensions.WEB3D_quantized_attributes&&f>2){const e=new Float32Array(l.array.length),{decodeMatrix:t}=l.extensions.WEB3D_quantized_attributes;for(let s=0;s<l.array.length;s+=f){V[0]=l.array[s],V[1]=l.array[s+1],V[2]=l.array[s+2],V[3]=1;const r=c(V,V,t);e[s]=r[0],e[s+1]=r[1],e[s+2]=r[2];}l.componentType=5126,l.array=e;}}else l.byteStride=0,l.array=this._typedArray(s,i.count,f,o+(i.byteOffset||0),u),l.byteOffset=l.array.byteOffset;else {l.array=new u(i.count);const e=l.min||l.max;e&&(l.array[0]=e[0],l.array[1]=e[1],l.array[2]=e[2]);}return l}_compareAccessor(){const e=this.gltf.accessors;if(Array.isArray(e))for(let t=0;t<e.length;t++)for(let s=0;s<e.length;s++)t!==s&&e[t].bufferView===e[s].bufferView&&(e[t].interleaved=e[s].interleaved=!0);else for(const t in e)for(const s in e)t!==s&&e[t].bufferView===e[s].bufferView&&(e[t].interleaved=e[s].interleaved=!0);}_typedArray(e,t,s,r,n){return r%n.BYTES_PER_ELEMENT!=0&&(e=e.slice(r,r+t*s*n.BYTES_PER_ELEMENT),r=0),new n(e,r,s*t)}_getTypeItemSize(e){const t=S.indexOf(e);return S[t+1]}requestKHRTechniquesWebgl(e){const{shaders:t}=e,s=t.map((e=>{if(void 0!==e.bufferView){const t=this.gltf.bufferViews[e.bufferView],{byteLength:s}=t;return this._requestBufferOfBufferView(t).then((r=>{const{buffer:n,byteOffset:i}=r,a=v(n,i+(t.byteOffset||0),s);return e.content=a,e}))}if(e.uri){if(w(e.uri)){const t=T(e.uri),s=v(t,0,t.byteLength);return e.content=s,Promise.resolve(e)}{const t=this.rootPath+"/"+e.uri;return P.get(t,this._fetchOptions,this._urlModifier).then((t=>(e.content=t,e)))}}return Promise.resolve(e)}));return Promise.all(s).then((()=>e))}}class D extends M{constructor(e,t,s,r,n,i,a,o){super(r,n,i,a,o),this.rootPath=e,this.gltf=t,this.requests={},this.buffers={},this.glbBuffer=s,this.accessor=new L(e,t,s,a,o);}iterate(e,t){const s=this.gltf[t];if(!s)return;let r=0;for(const t in s)e(t,s[t],r++);}createNode(e){const t={};if(b(e.name)&&(t.name=e.name),b(e.children)&&(t.children=e.children),b(e.jointName)&&(t.jointName=e.jointName),b(e.matrix)&&(t.matrix=e.matrix),b(e.rotation)&&(t.rotation=e.rotation),b(e.scale)&&(t.scale=e.scale),b(e.translation)&&(t.translation=e.translation),b(e.extras)&&(t.extras=e.extras),b(e.meshes)&&(t.mesh=e.meshes[0]),t.translation||t.rotation||t.scale){const e=function(e,t){if(t.matrix)return t.matrix;if(t.translation||t.scale||t.rotation){const s=function(e,t){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]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}(E,t.translation||R),n=function(e,t){var s=t[0],r=t[1],n=t[2],i=t[3],a=s+s,o=r+r,f=n+n,u=s*a,h=r*a,c=r*o,l=n*a,d=n*o,m=n*f,g=i*a,p=i*o,b=i*f;return e[0]=1-c-m,e[1]=h+b,e[2]=l-p,e[3]=0,e[4]=h-b,e[5]=1-u-m,e[6]=d+g,e[7]=0,e[8]=l+p,e[9]=d-g,e[10]=1-u-c,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(O,t.rotation||A),i=function(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(I,t.scale||q);return r(i,n,i),r(e,s,i)}return 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}(e)}([],t);delete t.translation,delete t.rotation,delete t.scale,t.matrix=e;}return t}_loadMaterials(e){const t={};for(const s in e){const r=e[s];let n,i;r.instanceTechnique&&r.instanceTechnique.values?(n=r.instanceTechnique,i=n.values.diffuse):(n=r,i=n.values.tex||n.values.diffuseTex||n.values.diffuse);const a={baseColorTexture:{index:i}};r.name&&(a.name=r.name),r.extensions&&(a.extensions=r.extensions),r.extras&&(a.extras=r.extras),t[s]=a;}return t}_loadImage(e){if(e.bufferView||e.extensions&&(e.extensions.KHR_binary_glTF||e.extensions.binary_glTF)){const t=e.bufferView?e:e.extensions.KHR_binary_glTF||e.extensions.binary_glTF;e.extensions&&(e.mimeType=t.mimeType,e.width=t.width,e.height=t.height);const s=this.gltf.bufferViews[t.bufferView],r=(s.byteOffset||0)+this.glbBuffer.byteOffset,n=s.byteLength,i=this.buffers[t.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,n);return this.getImageByBuffer(i,e)}return this.requestExternalImage(e)}_getTexture(e){const t=this.gltf.textures[e];if(!t)return null;const s=this.gltf.images[t.source];return this._loadImage(s).then((e=>{const r=this.gltf.samplers[t.sampler];return {image:{array:e.data,width:e.width,height:e.height,index:t.source,mimeType:s.mimeType,name:s.name,extras:s.extras},sampler:r}}))}getBaseColorTexture(e){const t=this.gltf.materials[e];let s,r;if(t.instanceTechnique&&t.instanceTechnique.values?(s=t.instanceTechnique,r=s.values.diffuse):(s=t,r=s.values.tex||s.values.diffuseTex||s.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const n=this.gltf.textures[r];if(!n)return null;const i=this.gltf.samplers[n.sampler];return {format:n.format||6408,internalFormat:n.internalFormat||6408,type:n.type||5121,sampler:i,source:this.gltf.images[n.source]}}getMaterial(){return null}getAnimations(){return null}}const U=9729;class C extends M{constructor(e,t,s,r,n,i,a,o){super(r,n,i,a,o),this.rootPath=e,this.gltf=t,this.glbBuffer=s,this.buffers={},this.requests={},this.accessor=new L(e,t,s,a,o);}iterate(e,t){const s=this.gltf[t];if(s)for(let t=0;t<s.length;t++)e(t,s[t],t);}createNode(e){const t={};return y(t,e),!b(e.weights)&&this.gltf.meshes&&b(t.mesh)?t.weights=this.gltf.meshes[t.mesh].weights:e.weights&&(t.weights=e.weights),t}_getTexture(e){const t=this.gltf.textures[e];if(!t)return null;let s=t.source;if(t.extensions&&t.extensions.EXT_texture_webp?s=t.extensions.EXT_texture_webp.source:t.extensions&&t.extensions.KHR_texture_basisu&&(s=t.extensions.KHR_texture_basisu.source),!b(s))return null;const r=this.gltf.images[s];return this._loadImage(r).then((e=>{if(!e)return null;const s={image:{array:e.data,mipmap:e.mipmap,width:e.width,height:e.height,index:t.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};y(s,t);const n=b(t.sampler)?this.gltf.samplers[t.sampler]:void 0;if(n&&(s.sampler=n,s.sampler.magFilter=n.magFilter||U,s.sampler.minFilter=n.minFilter||9987,s.sampler.wrapS=n.wrapS||10497,s.sampler.wrapT=n.wrapT||10497),"image/ktx2"===s.image.mimeType&&!s.image.mipmap&&s.sampler&&s.sampler.minFilter!==U&&9728!==s.sampler.minFilter){const e=s.sampler.minFilter;s.sampler.minFilter=9984===e||9986===e?9728:U;}if(e.format&&(s.format=e.format),6407===s.format){const e=s.image.array&&s.image.array.length;e&&e===s.image.width*s.image.height*4&&(s.format=6408);}return s}))}_loadImage(e){if(!b(e.bufferView))return this.requestExternalImage(e);{const t=this.gltf.bufferViews[e.bufferView],s=this.gltf.buffers[t.buffer];if(s.uri)return this.requestImageFromBufferURI(s,t,e);if(this.glbBuffer)return this._requestFromGlbBuffer(t,e)}return null}_requestFromGlbBuffer(e,t){const s=this._createDataView(e,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(s,t)}_createDataView(e,t,s){s=s||0;const r=(e.byteOffset||0)+s,n=e.byteLength;return new Uint8Array(t,r,n)}_transformArrayBufferToBase64(e,t){const s=new Array(e.byteLength);for(let t=0;t<e.byteLength;t++)s[t]=String.fromCharCode(e[t]);s.join("");const r="data:"+(t=t||"image/png")+";base64,"+function(e){return "undefined"!=typeof self?self.btoa(e):window.btoa(e)}(unescape(encodeURIComponent(s)));return r}getAnimations(e){const t=[];return e.forEach((e=>{t.push(this.getSamplers(e.samplers));})),Promise.all(t).then((t=>{for(let s=0;s<t.length;s++)e[s].samplers=t[s];return e}))}getSamplers(e){const t=[];for(let s=0;s<e.length;s++)(b(e[s].input)||b(e[s].output))&&(t.push(this.accessor._requestData("input",e[s].input)),t.push(this.accessor._requestData("output",e[s].output)));return Promise.all(t).then((t=>{for(let s=0;s<t.length/2;s++)e[s].input=t[2*s],e[s].output=t[2*s+1],e[s].interpolation||(e[s].interpolation="LINEAR");return e}))}}const F="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class k{static read(e,t=0,s=0){s||(s=e.byteLength);const r=new DataView(e,t,s),n=r.getUint32(4,!0);if(1===n)return k.readV1(r,t);if(2===n)return k.readV2(e,t);throw new Error("Unsupported glb version : "+n)}static readV1(e,t){const s=e.getUint32(8,!0),r=e.getUint32(12,!0);if(s!==e.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const n=X(e.buffer,20+t,r);return {json:JSON.parse(n),glbBuffer:{byteOffset:20+t+r,buffer:e.buffer,byteLength:s}}}static readV2(e,t){let s,r,n;const i=new DataView(e,t+12);let a=0;for(;a+8<i.byteLength;){const o=i.getUint32(a,!0);a+=4;const f=i.getUint32(a,!0);if(a+=4,1313821514===f)s=X(e,t+12+a,o);else if(5130562===f){n=t+12+a,r=o;break}a+=o;}return {json:JSON.parse(s),glbBuffer:{byteOffset:n,buffer:e,byteLength:r}}}}function X(e,t,s){if(F){const r=new Uint8Array(e,t,s);return F.decode(r)}return function(e){const t=e.length;let s="";for(let r=0;r<t;){let n=e[r++];if(128&n){let s=K[n>>3&7];if(!(64&n)||!s||r+s>t)return null;for(n&=63>>s;s>0;s-=1){const t=e[r++];if(128!=(192&t))return null;n=n<<6|63&t;}}s+=String.fromCharCode(n);}return s}(new Uint8Array(e,t,s))}const K=[1,1,1,1,2,2,3,0],H=[0,0,0],j=[0,0,0,1],z=[1,1,1],W={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},G={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Y={_getTRSW(e,t,s,r,n,i,o,f){const u=b(e)?t.animations:[t.animations[0]],h={};for(let t=0;t<u.length;t++){const c=u[t],l=c.name||t;if(b(e)&&l!==e)continue;const d=c.channelsMap[s];if(d)for(let e=0;e<d.length;e++){const t=d[e];"translation"===t.target.path?(this._getAnimateData(n,c.samplers[t.sampler],r,1),h.translation=a(H,n)):"rotation"===t.target.path?(this._getQuaternion(i,c.samplers[t.sampler],r,1),h.rotation=m(j,i)):"scale"===t.target.path?(this._getAnimateData(o,c.samplers[t.sampler],r,1),h.scale=a(z,o)):"weights"===t.target.path&&f&&(this._getAnimateData(f,c.samplers[t.sampler],r,f.length),h.weights=f);}}return h},_getAnimateData(e,t,s,r){switch(t.interpolation){case"LINEAR":{const n=this._getPreNext(G,t,s,1*r);n&&(e=function(e,t,s,r){for(let n=0;n<e.length;n++)e[n]=t[n]+r*(s[n]-t[n]);return e}(e,n.PREVIOUS,n.NEXT,n.INTERPOLATION));break}case"STEP":{const n=this._getPreNext(G,t,s,1*r);n&&(e=function(e,t){for(let s=0;s<e.length;s++)e[s]=t[s];return e}(e,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this._getPreNext(G,t,s,3*r);n&&(e=this._getCubicSpline(e,n,t.input.array,3*r));break}}return e},_getQuaternion(e,t,s){switch(t.interpolation){case"LINEAR":{const r=this._getPreNext(G,t,s,1);r&&function(e,t,s,r){var n,i,a,o,f,u=t[0],h=t[1],c=t[2],l=t[3],d=s[0],m=s[1],g=s[2],p=s[3];(i=u*d+h*m+c*g+l*p)<0&&(i=-i,d=-d,m=-m,g=-g,p=-p),1-i>1e-6?(n=Math.acos(i),a=Math.sin(n),o=Math.sin((1-r)*n)/a,f=Math.sin(r*n)/a):(o=1-r,f=r),e[0]=o*u+f*d,e[1]=o*h+f*m,e[2]=o*c+f*g,e[3]=o*l+f*p;}(e,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this._getPreNext(G,t,s,1);r&&(e=h(e,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this._getPreNext(G,t,s,3);if(r){for(let e=0;e<r.PREVIOUS.length;e++)r.PREVIOUS[e]=Math.acos(r.PREVIOUS[e]),r.NEXT[e]=Math.acos(r.NEXT[e]);e=this._getCubicSpline(e,r,t.input.array,3);for(let t=0;t<e.length;t++)e[t]=Math.cos(e[t]);}break}}return e},_search(e,t){const s=e.length;let r,n,i,a=0,o=s-1,f=Math.floor((a+o)/2);for(;a<=s-1&&o>=0;){if(a===o)return null;if(e[f]<=t&&t<=e[f+1]){const s=e[f];return r=f,n=f+1,i=(t-s)/(e[f+1]-s),{preIndx:r,nextIndex:n,interpolation:i}}t<e[f]?(o=f,f=Math.floor((a+o)/2)):e[f+1]<t&&(a=f,f=Math.floor((a+o)/2));}return null},_getPreNext(e,t,s,r){const n=t.input.array,i=t.output.array,a=t.output.itemSize;(s<n[0]||s>n[n.length-1])&&(s=Math.max(n[0],Math.min(n[n.length-1],s))),s===n[n.length-1]&&(s=n[0]);const o=this._search(n,s);if(!o||!o.nextIndex)return null;const{preIndx:f,nextIndex:u,interpolation:h}=o;e.PREINDEX=f,e.NEXTINDEX=u,e.INTERPOLATION=h;const c=a*r;return e.PREVIOUS=i.subarray(e.PREINDEX*c,(e.PREINDEX+1)*c),e.NEXT=i.subarray(e.NEXTINDEX*c,(e.NEXTINDEX+1)*c),e},_getCubicSpline(e,t,s,r){const n=t.INTERPOLATION,i=s[t.PREINDEX],a=s[t.NEXTINDEX];for(let s=0;s<3;s++){const o=t.PREVIOUS[r+s],f=(a-i)*t.PREVIOUS[2*r+s],u=t.NEXT[3+s],h=(a-i)*t.NEXT[s],c=(2*Math.pow(n,3)-3*Math.pow(n,2)+1)*o+(Math.pow(n,3)-2*Math.pow(n,2)+n)*f+(2*-Math.pow(n,3)+3*Math.pow(n,2))*u+(Math.pow(n,3)-Math.pow(n,2))*h;e[s]=c;}return e},getAnimationClip(e,t,s,r){const n=e.nodes[t]&&e.nodes[t].weights;return o(H,...W.TRANSLATION),h(j,...W.ROTATION),o(z,...W.SCALE),this._getTRSW(r,e,t,s,H,j,z,n)},getTimeSpan(e){if(!e.animations)return null;if(e.timeSpan)return e.timeSpan;const t=e.animations;return e.timeSpan={},t.forEach(((t,s)=>{let r=-1/0,n=1/0;const i=t.channels;for(let e=0;e<i.length;e++){const s=i[e],a=t.samplers[s.sampler].input.array;a[a.length-1]>r&&(r=a[a.length-1]),a[0]<n&&(n=a[0]);}const a=t.name||s;e.timeSpan[a]={max:r,min:n};})),e.timeSpan},getTimeSpanByName(e,t){const s=this.getTimeSpan(e);return s?b(t)?s[t]:s[Object.keys(s)[0]]:null}};let $=!1;if("undefined"!=typeof OffscreenCanvas){let e;try{e=new OffscreenCanvas(2,2).getContext("2d");}catch(s){}e&&"undefined"!=typeof createImageBitmap&&($=!0);}const J="undefined"==typeof document?null:document.createElement("canvas");function Q(e,t,s){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!J)return void s(new Error("There is no canvas to draw image!"));J.width=r.width,J.height=r.height;const e=J.getContext("2d",{willReadFrequently:!0});e.drawImage(r,0,0,r.width,r.height);const t=e.getImageData(0,0,r.width,r.height),n={width:r.width,height:r.height,data:new Uint8Array(t.data)};s(null,n);},r.onerror=function(e){s(e);},r.src=e;}const Z=[],ee=[],te=30;let se,re;function ne(e,t,s){se||(se=new OffscreenCanvas(2,2),re=se.getContext("2d",{willReadFrequently:!0}));let r=null;if(_(e))this.options.urlModifier&&(e=this.options.urlModifier(e)),Z.push([e,t,s,this]),ie();else {const t=new Blob([e]);r=createImageBitmap(t),r.then(ae.bind(this)).then((e=>{s(null,e);})).catch((e=>{console.warn(e),s(e);}));}}function ie(){if(!Z.length||ee.length>te)return;const e=Z.shift(),[t,s,r,n]=e;ee.push(e),fetch(t,s).then((e=>e.arrayBuffer())).then((e=>{const t=new Blob([new Uint8Array(e)]);return createImageBitmap(t)})).then(ae.bind(n)).then((t=>{r.call(n,null,t);const s=ee.indexOf(e);ee.splice(s,1),ie();})).catch((t=>{console.warn(t),r.call(n,t);const s=ee.indexOf(e);ee.splice(s,1),ie();}));}function ae(e){let{width:t,height:s}=e;oe(t)||(t=fe(t)),oe(s)||(s=fe(s));const r=this.options.maxTextureSize;r&&(t=Math.min(r,t),s=Math.min(r,s)),se.width=t,se.height=s,re.drawImage(e,0,0,t,s),e.close();const n=re.getImageData(0,0,t,s);return {width:t,height:s,data:new Uint8Array(n.data)}}function oe(e){return !(e&e-1)&&0!==e}function fe(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))}function ue(e,t){for(const s in e)if(e[s]===t)return s;return t}e.Ajax=P,e.GLTFLoader=class{constructor(e,t,s){if(this.options=s||{},this.options.decoders||(this.options.decoders={}),this._fetchOptions=this.options.fetchOptions||{},t.buffer instanceof ArrayBuffer){const{json:s,glbBuffer:r}=k.read(t.buffer,t.byteOffset,t.byteLength);this._init(e,s,r);}else this._init(e,t);this._accessor=new L(this.rootPath,this.gltf,this.glbBuffer,this._fetchOptions,this.options.urlModifier),this._checkExtensions();}_checkExtensions(){const e=this.gltf.extensionsRequired;if(e){if(e.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(e.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders["image/ktx2"])throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded");if(e.indexOf("EXT_meshopt_compression")>=0)throw new Error("EXT_meshopt_compression extension is not supported yet.")}}_loadExtensions(){const e=this.gltf.extensions;return e&&e.KHR_techniques_webgl?this._accessor.requestKHRTechniquesWebgl(e.KHR_techniques_webgl).then((t=>(e.KHR_techniques_webgl=t,e))):Promise.resolve(e)}_convertKhrTechiqueToTechiques(){if(!Array.isArray(this.gltf.programs))return;const e=this.gltf.materials;for(let t=0;t<e.length;t++)e[t]&&e[t].extensions&&e[t].extensions.KHR_technique_webgl&&(e[t].extensions.KHR_techniques_webgl=e[t].extensions.KHR_technique_webgl,delete e[t].extensions.KHR_technique_webgl);const t=this.gltf.extensions||{},s=this.gltf.techniques;t.KHR_techniques_webgl={programs:this.gltf.programs,shaders:this.gltf.shaders,techniques:s};for(let t=0;t<e.length;t++){const n=(r=e[t])&&r.extensions&&r.extensions.KHR_techniques_webgl;if(n){const{values:e,technique:t}=n,r=s[t];if(!r||!e)continue;const{uniforms:i,parameters:a}=r,o={};for(const t in e){const s=ue(i,t);o[s]=e[t],a[t]&&35678===a[t].type&&(o[s]={index:e[t]});}n.values=o;}}var r;for(let e=0;e<s.length;e++){const t=s[e];if(!t)continue;const{attributes:r,uniforms:n,parameters:i}=t;if(r)for(const e in r){const t=r[e];r[e]=i[t];}if(n)for(const e in n){const t=n[e];n[e]=i[t];}delete t.parameters;}return delete this.gltf.programs,delete this.gltf.shaders,delete this.gltf.techniques,this.gltf.extensions=t,t}load(e){e=e||{},this._convertKhrTechiqueToTechiques();const t=this._loadScene(e),s=this._loadAnimations(),r=this._loadTextures(),n=this._loadExtensions();return Promise.all([t,s,r,n]).then((e=>(e[0].animations=e[1],e[0].textures=e[2],e[0].extensions=e[3],e[0].transferables=this.transferables||[],this.createChannelsMap(e[0]),e[0])))}createChannelsMap(e){const t=e.animations;if(t)for(let e=0;e<t.length;e++){const s=t[e];s.channelsMap={};for(let e=0;e<s.channels.length;e++){const t=s.channels[e];s.channelsMap[t.target.node]||(s.channelsMap[t.target.node]=[]),s.channelsMap[t.target.node].push(t);}}}getExternalResources(){const e=[];if(this.gltf){const{buffers:t,images:s}=this.gltf;for(let s=0;s<t.length;s++)t[s].uri&&t[s].uri.indexOf("data:application/octet-stream;base64")<0&&e.push({type:"buffer",uri:t[s].uri});for(let t=0;t<s.length;t++)s[t].uri&&s[t].uri.indexOf("data:image/")<0&&e.push({type:"image",uri:s[t].uri});}return e}static getAnimationClip(e,t,s,r){return Y.getAnimationClip(e,t,s,r)}static getAnimationTimeSpan(e,t){return Y.getTimeSpanByName(e,t)}static getTypedArrayCtor(e){return x(e)}static readInterleavedArray(e,t,s,r,n,i,a){return B(e,t,s,r,n,i,a)}_init(e,t,s){this.gltf=t,this.glbBuffer=s,this.version=t.asset?+t.asset.version:1,this.rootPath=e,this.buffers={},this.requests={},this.options.requestImage=$?ne.bind(this):this.options.requestImage||Q,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new C(e,t,s,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this._fetchOptions,this.options.urlModifier),this.adapter.iterate(((e,t,s)=>{t.id="buffer_"+s;}),"buffers"),this.adapter.iterate(((e,t,s)=>{t.id="image_"+s;}),"images"),this.adapter.iterate(((e,t,s)=>{t.id="accessor_"+s;}),"accessors")):(this.adapter=new D(e,t,s,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this._fetchOptions,this.options.urlModifier),this.adapter.iterate(((e,t,s)=>{t.id="accessor_"+s;}),"accessors"),this.adapter.iterate(((e,t,s)=>{t.id="image_"+s;}),"images"));}_parseNodes(e,t){if(e.children&&e.children.length>0){if(!("number"==typeof(s=e.children[0])&&isFinite(s)||_(e.children[0])))return e;const r=e.children.map((e=>{const s=t[e];return s.nodeIndex=e,this._parseNodes(s,t)}));e.children=r;}var s;return e}_loadScene(e){return this._loadNodes(e).then((e=>{const t=this.scenes=[];let s;for(const t in e)e[t]=this._parseNodes(e[t],e),e[t].nodeIndex=Number(t)?Number(t):t;this.adapter.iterate(((r,n,i)=>{const a={};n.name&&(a.name=n.name),n.nodes&&(a.nodes=n.nodes.map((t=>e[t]))),this.gltf.scene===r&&(s=i),t.push(a);}),"scenes");const r={textures:this.gltf.textures,asset:this.gltf.asset,scene:s,scenes:t,nodes:e,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(r.extensions=this.gltf.extensions),1===this.version){const e=this.adapter._loadMaterials(this.gltf.materials);r.materials=e;}return delete this.gltf.buffers,r.json=this.gltf,r}))}_loadNodes(e){return this._loadMeshes(e).then((()=>{const e=this.nodes={};return this.adapter.iterate(((t,s)=>{const r=this.adapter.createNode(s,this.meshes,this.skins);e[t]=r;}),"nodes"),e}))}_loadSkins(){this.skins=[];const e=[];return this.adapter.iterate(((t,s,r)=>{e.push(this._loadSkin(s).then((e=>{e.index=r,this.skins.push(e);})));}),"skins"),e}_loadSkin(e){const t=e.inverseBindMatrices;return this.adapter.accessor._requestData("inverseBindMatrices",t).then((t=>(e.inverseBindMatrices=t,t&&t.buffer&&this.transferables&&this.transferables.indexOf(t.buffer)<0&&this.transferables.push(t.buffer),e)))}_loadAnimations(){const e=this.gltf.animations;return b(e)?this.adapter.getAnimations(e):null}_loadMeshes(e){this.meshes={};let t=[];return this.adapter.iterate(((s,r,n)=>{t.push(this._loadMesh(r,e).then((e=>{e.index=n,this.meshes[s]=e;})));}),"meshes"),t=t.concat(this._loadSkins()),Promise.all(t)}_loadMesh(e,t){const s=e.primitives.map((e=>this._loadPrimitive(e,t))).filter((e=>!!e));return Promise.all(s).then((t=>{const s={};return y(s,e),s.primitives=t,s}))}_loadTextures(){const e=this.gltf.textures;if(!e)return null;const t=[];for(const s in e)t.push(this.adapter._getTexture(s));return Promise.all(t).then((t=>{if(this.transferables)for(let e=0;e<t.length;e++){const s=t[e]&&t[e].image.array;if(s){let e;e=s instanceof ImageBitmap?s:s.buffer,e&&this.transferables.indexOf(e)<0&&this.transferables.push(e);}}if(!Array.isArray(e)){const s={},r=Object.keys(e);for(let e=0;e<t.length;e++)t[e]&&(s[r[e]]=t[e]);return s}return t}))}_loadPrimitive(e,t){let s;const r=[],n=e.extensions;if(b(e.targets))for(let t=0;t<e.targets.length;t++){const s=e.targets[t];for(const e in s){const n=this.adapter.accessor._requestData(`morphTargets_${e}_${t}`,s[e]);n&&r.push(n);}}if(n&&n.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const e=this.options.decoders.draco,{bufferView:i,attributes:a}=n.KHR_draco_mesh_compression,o=this.gltf.bufferViews[i],f=this._accessor._requestBufferOfBufferView(o).then((s=>{const{buffer:r,byteOffset:n}=s;let{byteOffset:i}=o;const f=o.byteLength;i||(i=0);const u=new DataView(r,n+i,f),h={attributes:a,useUniqueIDs:!1,skipAttributeTransform:t.skipAttributeTransform};return e(u,h).then((e=>{const t=Object.values(e.attributes);return e.indices&&t.push(e.indices),t}))}));r.push(f),s=Promise.all(r);}else {const t=e.attributes;for(const e in t){const s=this.adapter.accessor._requestData(e,t[e]);s&&r.push(s);}if(b(e.indices)){const t=this.adapter.accessor._requestData("indices",e.indices);t&&r.push(t);}s=Promise.all(r);}return s.then((t=>{if(n&&n.KHR_draco_mesh_compression){const s=e.targets?e.targets.length:0;t[s]=t[s].concat(t.slice(0,s)),t=t[s];}let s,r;const i={attributes:t.reduce(((e,t)=>{if("indices"===t.name)s=t;else if(t.name.indexOf("morphTargets_")>-1)r=r||{},r[t.name.slice(13)]=t;else {if(!("POSITION"!==t.name||t.min&&t.max)){const e=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0],{itemSize:r,array:n}=t,i=n.length/r;for(let t=0;t<i;t++)for(let i=0;i<r;i++){const a=t*r+i;n[a]<e[i]&&(e[i]=n[a]),n[a]>s[i]&&(s[i]=n[a]);}if(t.quantization){const r=t.quantization,n=r.range/(1<<r.quantizationBits),i=r.minValues;u(e,e,n),f(e,e,i),u(s,s,n),f(s,s,i);}t.min=e,t.max=s;}e[t.name]=t;}return this.transferables&&t.array.buffer&&this.transferables.indexOf(t.array.buffer)<0&&this.transferables.push(t.array.buffer),e}),{}),material:e.material};return s&&(i.indices=s),r&&(i.morphTargets=r),i.mode=b(e.mode)?e.mode:4,b(e.extras)&&(i.extras=e.extras),i}))}},t().maptalks_gltf_loader=e;}gltfLoaderExport({});
73
+ */var s="undefined"!=typeof Float32Array?Float32Array:Array;function r(e,t,s){var r=t[0],n=t[1],i=t[2],a=t[3],o=t[4],f=t[5],u=t[6],h=t[7],c=t[8],l=t[9],d=t[10],m=t[11],g=t[12],p=t[13],b=t[14],_=t[15],y=s[0],x=s[1],w=s[2],T=s[3];return e[0]=y*r+x*o+w*c+T*g,e[1]=y*n+x*f+w*l+T*p,e[2]=y*i+x*u+w*d+T*b,e[3]=y*a+x*h+w*m+T*_,y=s[4],x=s[5],w=s[6],T=s[7],e[4]=y*r+x*o+w*c+T*g,e[5]=y*n+x*f+w*l+T*p,e[6]=y*i+x*u+w*d+T*b,e[7]=y*a+x*h+w*m+T*_,y=s[8],x=s[9],w=s[10],T=s[11],e[8]=y*r+x*o+w*c+T*g,e[9]=y*n+x*f+w*l+T*p,e[10]=y*i+x*u+w*d+T*b,e[11]=y*a+x*h+w*m+T*_,y=s[12],x=s[13],w=s[14],T=s[15],e[12]=y*r+x*o+w*c+T*g,e[13]=y*n+x*f+w*l+T*p,e[14]=y*i+x*u+w*d+T*b,e[15]=y*a+x*h+w*m+T*_,e}function n(){var e=new s(3);return s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function i(e,t,r){var n=new s(3);return n[0]=e,n[1]=t,n[2]=r,n}function a(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function o(e,t,s,r){return e[0]=t,e[1]=s,e[2]=r,e}function f(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e}function u(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e}function h(e,t,s,r,n){return e[0]=t,e[1]=s,e[2]=r,e[3]=n,e}function c(e,t,s){var r=t[0],n=t[1],i=t[2],a=t[3];return e[0]=s[0]*r+s[4]*n+s[8]*i+s[12]*a,e[1]=s[1]*r+s[5]*n+s[9]*i+s[13]*a,e[2]=s[2]*r+s[6]*n+s[10]*i+s[14]*a,e[3]=s[3]*r+s[7]*n+s[11]*i+s[15]*a,e}function l(){var e=new s(4);return s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)}),n(),function(){var e;e=new s(4),s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0);}();var d,m=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e};n(),i(1,0,0),i(0,1,0),l(),l(),d=new s(9),s!=Float32Array&&(d[1]=0,d[2]=0,d[3]=0,d[5]=0,d[6]=0,d[7]=0),d[0]=1,d[4]=1,d[8]=1;let g=0;function p(e){return null==e}function b(e){return !p(e)}function _(e){return !p(e)&&("string"==typeof e||null!==e.constructor&&e.constructor===String)}function y(e){for(let t=1;t<arguments.length;t++){const s=arguments[t];for(const t in s)e[t]=s[t];}return e}function x(e){switch(e){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5124:return Int32Array;case 5125:return Uint32Array;case 5126:return Float32Array}throw new Error("unsupported bufferView's component type: "+e)}function w(e){return 0===e.indexOf("data:")&&e.indexOf("base64,")>0}function T(e){const t=function(e){return "undefined"!=typeof self?self.atob(e):window.atob(e)}(e.substring(e.indexOf(",")+1)),s=t.length,r=new Uint8Array(s);for(let e=0;e<s;e++)r[e]=t.charCodeAt(e);return r.buffer}const E=[],O=[],I=[],R=[0,0,0],A=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}([]),q=[1,1,1];function B(e,t,s,r,n,i,a){const o=x(a),f=o.BYTES_PER_ELEMENT;if((0===n||n===r*f)&&i%f==0){const n=new o(t,i,s*r);return e.set(n),e}0===n&&(n=r*f);const u=new Uint8Array(r*f);for(let a=0;a<s;a++){let s=null;const h=new Uint8Array(t,n*a+i,r*f);u.set(h),s=new o(u.buffer,0,r);for(let t=0;t<r;t++)e[a*r+t]=s[t];}return e}const N="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function v(e,t,s){const r=new Uint8Array(e,t,s);return N.decode(r)}const P={get:function(e,t={},s){t||(t={}),t=y({},t);const r=new AbortController,n=r.signal,i=y({},t);i.signal=n,i.method||(i.method="GET"),i.referrerPolicy=i.referrerPolicy||"origin","undefined"==typeof window||i.referrer||(i.referrer=window.location.href),s&&(e=s(e));const a=fetch(e,i).then((e=>{const s=this._parseResponse(e,t.responseType);return s.message?s:s.then((s=>"arraybuffer"===t.responseType?{data:s,cacheControl:e.headers.get("Cache-Control"),expires:e.headers.get("Expires"),contentType:e.headers.get("Content-Type")}:s)).catch((e=>{if(!e.code||e.code!==DOMException.ABORT_ERR)throw e}))})).catch((e=>{if(!e.code||e.code!==DOMException.ABORT_ERR)throw e}));return a.xhr=r,a},_parseResponse:(e,t)=>200!==e.status?{status:e.status,statusText:e.statusText,message:`incorrect http request with status code(${e.status}): ${e.statusText}`}:"arraybuffer"===t?e.arrayBuffer():"json"===t?e.json():e.text(),getArrayBuffer:(e,t={},s)=>(t||(t={}),t.responseType="arraybuffer",P.get(e,t,s)),getJSON:function(e,t={},s){return t&&t.jsonp?P.jsonp(e):((t=t||{}).responseType="json",P.get(e,t,s))},jsonp:function(e){const t="_maptalks_jsonp_"+g++;e.match(/\?/)?e+="&callback="+t:e+="?callback="+t;let s=document.createElement("script");return s.type="text/javascript",s.src=e,new Promise((e=>{window[t]=function(r){document.getElementsByTagName("head")[0].removeChild(s),s=null,delete window[t],e(r);},document.getElementsByTagName("head")[0].appendChild(s);}))}};class M{constructor(e,t,s,r,n){this._requestImage=e,this.decoders=t,this._supportedFormats=s,this.images={},this._imgRequests={},this._fetchOptions=r||{},this._urlModifier=n;}requestImageFromBufferURI(e,t,s){if(this.buffers[e.id]){const r=this.buffers[e.id],n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}if(this._imgRequests[e.id])return this._imgRequests[e.id].then((()=>{const r=this.buffers[e.id],n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}));if(w(e.uri)){const r=this.buffers[e.id]=T(e.uri),n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}let r;const n=e.uri.indexOf("blob:")>=0;return r=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri,this._imgRequests[e.id]=P.getArrayBuffer(r,this._fetchOptions,this._urlModifier).then((r=>{const n=this.buffers[e.id]=r.data,i=this._createDataView(t,n);return this.getImageByBuffer(i,s)}))}getImageByBuffer(e,t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const s=this.decoders;if(s[t.mimeType])return s[t.mimeType](e,{supportedFormats:this._supportedFormats});if("image/crn"===t.mimeType||"image/ktx2"===t.mimeType||"image/cttf"===t.mimeType)throw new Error("missing transcoder for "+t.mimeType,"");return this._getImageInfo(t.id,e)}requestExternalImage(e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const t=0===e.uri.indexOf("data:image/")?e.uri:this.rootPath+"/"+e.uri;return this._imgRequests[e.id]?this._imgRequests[e.id].then((()=>this.images[e.id])):this._imgRequests[e.id]=this._getImageInfo(e.id,t)}_getImageInfo(e,t){return new Promise(((s,r)=>{let n=t;this._urlModifier&&(n=this._urlModifier(t)),this._requestImage(n,this._fetchOptions,((n,i)=>{n?r(n):(URL.revokeObjectURL(t),this.images[e]=i,s(this.images[e]));}));}))}}const S=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],V=[];class L{constructor(e,t,s,r,n){this.rootPath=e,this.gltf=t,this._enableInterleave=!1,this.glbBuffer=s,this.buffers={},this.requests={},this.accessors={},this._compareAccessor(),this._fetchOptions=r,this._urlModifier=n;}_requestData(e,t){const s=this.gltf,r=s.accessors[t];if(void 0===r.bufferView)return this.accessors[r.id]=this._toBufferData(e,t,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const n=s.bufferViews[r.bufferView];return this._requestBufferOfBufferView(n).then((s=>{const{buffer:n,byteOffset:i}=s;return this.accessors[r.id]=this._toBufferData(e,t,n,i)}))}_requestBufferOfBufferView(e){const t=this.gltf.buffers[e.buffer];if(this.buffers[t.id]){const e=this.buffers[t.id];return Promise.resolve({buffer:e,byteOffset:0})}if(this.requests[t.id])return this.requests[t.id].then((()=>{const e=this.buffers[t.id];return Promise.resolve({buffer:e,byteOffset:0})}));if("binary_glTF"!==e.buffer&&"KHR_binary_glTF"!==e.buffer&&t.uri){if(w(t.uri)){const e=this.buffers[t.id]=T(t.uri);return Promise.resolve({buffer:e,byteOffset:0})}let e;const s=t.uri.indexOf("blob:")>=0;return e=t.uri.indexOf("://")>0||s?t.uri:this.rootPath+"/"+t.uri,this.requests[t.id]=P.getArrayBuffer(e,this._fetchOptions,!s&&this._urlModifier).then((r=>(s&&URL.revokeObjectURL(e),{buffer:this.buffers[t.id]=r.data,byteOffset:0})))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}_toBufferData(e,t,s,r=0){const n=this.gltf,i=n.accessors[t],a=void 0!==i.bufferView?n.bufferViews[i.bufferView]:{},o=(a.byteOffset||0)+r,f=this._getTypeItemSize(i.type),u=x(i.componentType),h=a.byteStride||0,l={array:void 0,name:e,accessorName:t,byteLength:i.count*f*u.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:f,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(l.min=i.min),i.max&&(l.max=i.max),s)if(this._enableInterleave)l.byteStride=h,l.byteOffset=o+(i.byteOffset||0),!h||h===f*u.BYTES_PER_ELEMENT||"indices"===e||"input"===e||"output"===e||e.indexOf("morph")>=0?(l.array=this._typedArray(s,i.count,f,o+(i.byteOffset||0),u),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(s,o,a.byteLength);else if(i.interleaved){l.byteStride=0,l.byteOffset=0;const e=new u(i.count*f);if(l.array=B(e,s,i.count,f,h,o+(i.byteOffset||0),i.componentType),l.extensions&&l.extensions.WEB3D_quantized_attributes&&f>2){const e=new Float32Array(l.array.length),{decodeMatrix:t}=l.extensions.WEB3D_quantized_attributes;for(let s=0;s<l.array.length;s+=f){V[0]=l.array[s],V[1]=l.array[s+1],V[2]=l.array[s+2],V[3]=1;const r=c(V,V,t);e[s]=r[0],e[s+1]=r[1],e[s+2]=r[2];}l.componentType=5126,l.array=e;}}else l.byteStride=0,l.array=this._typedArray(s,i.count,f,o+(i.byteOffset||0),u),l.byteOffset=l.array.byteOffset;else {l.array=new u(i.count);const e=l.min||l.max;e&&(l.array[0]=e[0],l.array[1]=e[1],l.array[2]=e[2]);}return l}_compareAccessor(){const e=this.gltf.accessors;if(Array.isArray(e))for(let t=0;t<e.length;t++)for(let s=0;s<e.length;s++)t!==s&&e[t].bufferView===e[s].bufferView&&(e[t].interleaved=e[s].interleaved=!0);else for(const t in e)for(const s in e)t!==s&&e[t].bufferView===e[s].bufferView&&(e[t].interleaved=e[s].interleaved=!0);}_typedArray(e,t,s,r,n){return r%n.BYTES_PER_ELEMENT!=0&&(e=e.slice(r,r+t*s*n.BYTES_PER_ELEMENT),r=0),new n(e,r,s*t)}_getTypeItemSize(e){const t=S.indexOf(e);return S[t+1]}requestKHRTechniquesWebgl(e){const{shaders:t}=e,s=t.map((e=>{if(void 0!==e.bufferView){const t=this.gltf.bufferViews[e.bufferView],{byteLength:s}=t;return this._requestBufferOfBufferView(t).then((r=>{const{buffer:n,byteOffset:i}=r,a=v(n,i+(t.byteOffset||0),s);return e.content=a,e}))}if(e.uri){if(w(e.uri)){const t=T(e.uri),s=v(t,0,t.byteLength);return e.content=s,Promise.resolve(e)}{const t=this.rootPath+"/"+e.uri;return P.get(t,this._fetchOptions,this._urlModifier).then((t=>(e.content=t,e)))}}return Promise.resolve(e)}));return Promise.all(s).then((()=>e))}}class D extends M{constructor(e,t,s,r,n,i,a,o){super(r,n,i,a,o),this.rootPath=e,this.gltf=t,this.requests={},this.buffers={},this.glbBuffer=s,this.accessor=new L(e,t,s,a,o);}iterate(e,t){const s=this.gltf[t];if(!s)return;let r=0;for(const t in s)e(t,s[t],r++);}createNode(e){const t={};if(b(e.name)&&(t.name=e.name),b(e.children)&&(t.children=e.children),b(e.jointName)&&(t.jointName=e.jointName),b(e.matrix)&&(t.matrix=e.matrix),b(e.rotation)&&(t.rotation=e.rotation),b(e.scale)&&(t.scale=e.scale),b(e.translation)&&(t.translation=e.translation),b(e.extras)&&(t.extras=e.extras),b(e.meshes)&&(t.mesh=e.meshes[0]),t.translation||t.rotation||t.scale){const e=function(e,t){if(t.matrix)return t.matrix;if(t.translation||t.scale||t.rotation){const s=function(e,t){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]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}(E,t.translation||R),n=function(e,t){var s=t[0],r=t[1],n=t[2],i=t[3],a=s+s,o=r+r,f=n+n,u=s*a,h=r*a,c=r*o,l=n*a,d=n*o,m=n*f,g=i*a,p=i*o,b=i*f;return e[0]=1-c-m,e[1]=h+b,e[2]=l-p,e[3]=0,e[4]=h-b,e[5]=1-u-m,e[6]=d+g,e[7]=0,e[8]=l+p,e[9]=d-g,e[10]=1-u-c,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(O,t.rotation||A),i=function(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(I,t.scale||q);return r(i,n,i),r(e,s,i)}return 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}(e)}([],t);delete t.translation,delete t.rotation,delete t.scale,t.matrix=e;}return t}_loadMaterials(e){const t={};for(const s in e){const r=e[s];let n,i;r.instanceTechnique&&r.instanceTechnique.values?(n=r.instanceTechnique,i=n.values.diffuse):(n=r,i=n.values.tex||n.values.diffuseTex||n.values.diffuse);const a={baseColorTexture:{index:i}};r.name&&(a.name=r.name),r.extensions&&(a.extensions=r.extensions),r.extras&&(a.extras=r.extras),t[s]=a;}return t}_loadImage(e){if(e.bufferView||e.extensions&&(e.extensions.KHR_binary_glTF||e.extensions.binary_glTF)){const t=e.bufferView?e:e.extensions.KHR_binary_glTF||e.extensions.binary_glTF;e.extensions&&(e.mimeType=t.mimeType,e.width=t.width,e.height=t.height);const s=this.gltf.bufferViews[t.bufferView],r=(s.byteOffset||0)+this.glbBuffer.byteOffset,n=s.byteLength,i=this.buffers[t.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,n);return this.getImageByBuffer(i,e)}return this.requestExternalImage(e)}_getTexture(e){const t=this.gltf.textures[e];if(!t)return null;const s=this.gltf.images[t.source];return this._loadImage(s).then((e=>{const r=this.gltf.samplers[t.sampler];return {image:{array:e.data,width:e.width,height:e.height,index:t.source,mimeType:s.mimeType,name:s.name,extras:s.extras},sampler:r}}))}getBaseColorTexture(e){const t=this.gltf.materials[e];let s,r;if(t.instanceTechnique&&t.instanceTechnique.values?(s=t.instanceTechnique,r=s.values.diffuse):(s=t,r=s.values.tex||s.values.diffuseTex||s.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const n=this.gltf.textures[r];if(!n)return null;const i=this.gltf.samplers[n.sampler];return {format:n.format||6408,internalFormat:n.internalFormat||6408,type:n.type||5121,sampler:i,source:this.gltf.images[n.source]}}getMaterial(){return null}getAnimations(){return null}}const U=9729;class C extends M{constructor(e,t,s,r,n,i,a,o){super(r,n,i,a,o),this.rootPath=e,this.gltf=t,this.glbBuffer=s,this.buffers={},this.requests={},this.accessor=new L(e,t,s,a,o);}iterate(e,t){const s=this.gltf[t];if(s)for(let t=0;t<s.length;t++)e(t,s[t],t);}createNode(e){const t={};return y(t,e),!b(e.weights)&&this.gltf.meshes&&b(t.mesh)?t.weights=this.gltf.meshes[t.mesh].weights:e.weights&&(t.weights=e.weights),t}_getTexture(e){const t=this.gltf.textures[e];if(!t)return null;let s=t.source;if(t.extensions&&t.extensions.EXT_texture_webp?s=t.extensions.EXT_texture_webp.source:t.extensions&&t.extensions.KHR_texture_basisu&&(s=t.extensions.KHR_texture_basisu.source),!b(s))return null;const r=this.gltf.images[s];return this._loadImage(r).then((e=>{if(!e)return null;const s={image:{array:e.data,mipmap:e.mipmap,width:e.width,height:e.height,index:t.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};y(s,t);const n=b(t.sampler)?this.gltf.samplers[t.sampler]:void 0;if(n&&(s.sampler=n,s.sampler.magFilter=n.magFilter||U,s.sampler.minFilter=n.minFilter||9987,s.sampler.wrapS=n.wrapS||10497,s.sampler.wrapT=n.wrapT||10497),"image/ktx2"===s.image.mimeType&&!s.image.mipmap&&s.sampler&&s.sampler.minFilter!==U&&9728!==s.sampler.minFilter){const e=s.sampler.minFilter;s.sampler.minFilter=9984===e||9986===e?9728:U;}if(e.format&&(s.format=e.format),6407===s.format){const e=s.image.array&&s.image.array.length;e&&e===s.image.width*s.image.height*4&&(s.format=6408);}return s}))}_loadImage(e){if(!b(e.bufferView))return this.requestExternalImage(e);{const t=this.gltf.bufferViews[e.bufferView],s=this.gltf.buffers[t.buffer];if(s.uri)return this.requestImageFromBufferURI(s,t,e);if(this.glbBuffer)return this._requestFromGlbBuffer(t,e)}return null}_requestFromGlbBuffer(e,t){const s=this._createDataView(e,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(s,t)}_createDataView(e,t,s){s=s||0;const r=(e.byteOffset||0)+s,n=e.byteLength;return new Uint8Array(t,r,n)}_transformArrayBufferToBase64(e,t){const s=new Array(e.byteLength);for(let t=0;t<e.byteLength;t++)s[t]=String.fromCharCode(e[t]);s.join("");const r="data:"+(t=t||"image/png")+";base64,"+function(e){return "undefined"!=typeof self?self.btoa(e):window.btoa(e)}(unescape(encodeURIComponent(s)));return r}getAnimations(e){const t=[];return e.forEach((e=>{t.push(this.getSamplers(e.samplers));})),Promise.all(t).then((t=>{for(let s=0;s<t.length;s++)e[s].samplers=t[s];return e}))}getSamplers(e){const t=[];for(let s=0;s<e.length;s++)(b(e[s].input)||b(e[s].output))&&(t.push(this.accessor._requestData("input",e[s].input)),t.push(this.accessor._requestData("output",e[s].output)));return Promise.all(t).then((t=>{for(let s=0;s<t.length/2;s++)e[s].input=t[2*s],e[s].output=t[2*s+1],e[s].interpolation||(e[s].interpolation="LINEAR");return e}))}}const F="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class k{static read(e,t=0,s=0){s||(s=e.byteLength);const r=new DataView(e,t,s),n=r.getUint32(4,!0);if(1===n)return k.readV1(r,t);if(2===n)return k.readV2(e,t);throw new Error("Unsupported glb version : "+n)}static readV1(e,t){const s=e.getUint32(8,!0),r=e.getUint32(12,!0);if(s!==e.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const n=X(e.buffer,20+t,r);return {json:JSON.parse(n),glbBuffer:{byteOffset:20+t+r,buffer:e.buffer,byteLength:s}}}static readV2(e,t){let s,r,n;const i=new DataView(e,t+12);let a=0;for(;a+8<i.byteLength;){const o=i.getUint32(a,!0);a+=4;const f=i.getUint32(a,!0);if(a+=4,1313821514===f)s=X(e,t+12+a,o);else if(5130562===f){n=t+12+a,r=o;break}a+=o;}return {json:JSON.parse(s),glbBuffer:{byteOffset:n,buffer:e,byteLength:r}}}}function X(e,t,s){if(F){const r=new Uint8Array(e,t,s);return F.decode(r)}return function(e){const t=e.length;let s="";for(let r=0;r<t;){let n=e[r++];if(128&n){let s=K[n>>3&7];if(!(64&n)||!s||r+s>t)return null;for(n&=63>>s;s>0;s-=1){const t=e[r++];if(128!=(192&t))return null;n=n<<6|63&t;}}s+=String.fromCharCode(n);}return s}(new Uint8Array(e,t,s))}const K=[1,1,1,1,2,2,3,0],H=[0,0,0],j=[0,0,0,1],z=[1,1,1],W={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},G={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Y={_getTRSW(e,t,s,r,n,i,o,f){const u=b(e)?t.animations:[t.animations[0]],h={};for(let t=0;t<u.length;t++){const c=u[t],l=c.name||t;if(b(e)&&l!==e)continue;const d=c.channelsMap[s];if(d)for(let e=0;e<d.length;e++){const t=d[e];"translation"===t.target.path?(this._getAnimateData(n,c.samplers[t.sampler],r,1),h.translation=a(H,n)):"rotation"===t.target.path?(this._getQuaternion(i,c.samplers[t.sampler],r,1),h.rotation=m(j,i)):"scale"===t.target.path?(this._getAnimateData(o,c.samplers[t.sampler],r,1),h.scale=a(z,o)):"weights"===t.target.path&&f&&(this._getAnimateData(f,c.samplers[t.sampler],r,f.length),h.weights=f);}}return h},_getAnimateData(e,t,s,r){switch(t.interpolation){case"LINEAR":{const n=this._getPreNext(G,t,s,1*r);n&&(e=function(e,t,s,r){for(let n=0;n<e.length;n++)e[n]=t[n]+r*(s[n]-t[n]);return e}(e,n.PREVIOUS,n.NEXT,n.INTERPOLATION));break}case"STEP":{const n=this._getPreNext(G,t,s,1*r);n&&(e=function(e,t){for(let s=0;s<e.length;s++)e[s]=t[s];return e}(e,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this._getPreNext(G,t,s,3*r);n&&(e=this._getCubicSpline(e,n,t.input.array,3*r));break}}return e},_getQuaternion(e,t,s){switch(t.interpolation){case"LINEAR":{const r=this._getPreNext(G,t,s,1);r&&function(e,t,s,r){var n,i,a,o,f,u=t[0],h=t[1],c=t[2],l=t[3],d=s[0],m=s[1],g=s[2],p=s[3];(i=u*d+h*m+c*g+l*p)<0&&(i=-i,d=-d,m=-m,g=-g,p=-p),1-i>1e-6?(n=Math.acos(i),a=Math.sin(n),o=Math.sin((1-r)*n)/a,f=Math.sin(r*n)/a):(o=1-r,f=r),e[0]=o*u+f*d,e[1]=o*h+f*m,e[2]=o*c+f*g,e[3]=o*l+f*p;}(e,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this._getPreNext(G,t,s,1);r&&(e=h(e,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this._getPreNext(G,t,s,3);if(r){for(let e=0;e<r.PREVIOUS.length;e++)r.PREVIOUS[e]=Math.acos(r.PREVIOUS[e]),r.NEXT[e]=Math.acos(r.NEXT[e]);e=this._getCubicSpline(e,r,t.input.array,3);for(let t=0;t<e.length;t++)e[t]=Math.cos(e[t]);}break}}return e},_search(e,t){const s=e.length;let r,n,i,a=0,o=s-1,f=Math.floor((a+o)/2);for(;a<=s-1&&o>=0;){if(a===o)return null;if(e[f]<=t&&t<=e[f+1]){const s=e[f];return r=f,n=f+1,i=(t-s)/(e[f+1]-s),{preIndx:r,nextIndex:n,interpolation:i}}t<e[f]?(o=f,f=Math.floor((a+o)/2)):e[f+1]<t&&(a=f,f=Math.floor((a+o)/2));}return null},_getPreNext(e,t,s,r){const n=t.input.array,i=t.output.array,a=t.output.itemSize;(s<n[0]||s>n[n.length-1])&&(s=Math.max(n[0],Math.min(n[n.length-1],s))),s===n[n.length-1]&&(s=n[0]);const o=this._search(n,s);if(!o||!o.nextIndex)return null;const{preIndx:f,nextIndex:u,interpolation:h}=o;e.PREINDEX=f,e.NEXTINDEX=u,e.INTERPOLATION=h;const c=a*r;return e.PREVIOUS=i.subarray(e.PREINDEX*c,(e.PREINDEX+1)*c),e.NEXT=i.subarray(e.NEXTINDEX*c,(e.NEXTINDEX+1)*c),e},_getCubicSpline(e,t,s,r){const n=t.INTERPOLATION,i=s[t.PREINDEX],a=s[t.NEXTINDEX];for(let s=0;s<3;s++){const o=t.PREVIOUS[r+s],f=(a-i)*t.PREVIOUS[2*r+s],u=t.NEXT[3+s],h=(a-i)*t.NEXT[s],c=(2*Math.pow(n,3)-3*Math.pow(n,2)+1)*o+(Math.pow(n,3)-2*Math.pow(n,2)+n)*f+(2*-Math.pow(n,3)+3*Math.pow(n,2))*u+(Math.pow(n,3)-Math.pow(n,2))*h;e[s]=c;}return e},getAnimationClip(e,t,s,r){const n=e.nodes[t]&&e.nodes[t].weights;return o(H,...W.TRANSLATION),h(j,...W.ROTATION),o(z,...W.SCALE),this._getTRSW(r,e,t,s,H,j,z,n)},getTimeSpan(e){if(!e.animations)return null;if(e.timeSpan)return e.timeSpan;const t=e.animations;return e.timeSpan={},t.forEach(((t,s)=>{let r=-1/0,n=1/0;const i=t.channels;for(let e=0;e<i.length;e++){const s=i[e],a=t.samplers[s.sampler].input.array;a[a.length-1]>r&&(r=a[a.length-1]),a[0]<n&&(n=a[0]);}const a=t.name||s;e.timeSpan[a]={max:r,min:n};})),e.timeSpan},getTimeSpanByName(e,t){const s=this.getTimeSpan(e);return s?b(t)?s[t]:s[Object.keys(s)[0]]:null}};let $=!1;if("undefined"!=typeof OffscreenCanvas){let e;try{e=new OffscreenCanvas(2,2).getContext("2d");}catch(s){}e&&"undefined"!=typeof createImageBitmap&&($=!0);}const J="undefined"==typeof document?null:document.createElement("canvas");function Q(e,t,s){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!J)return void s(new Error("There is no canvas to draw image!"));J.width=r.width,J.height=r.height;const e=J.getContext("2d",{willReadFrequently:!0});e.drawImage(r,0,0,r.width,r.height);const t=e.getImageData(0,0,r.width,r.height),n={width:r.width,height:r.height,data:new Uint8Array(t.data)};s(null,n);},r.onerror=function(e){s(e);},r.src=e;}const Z=[],ee=[],te=30;let se,re;function ne(e,t,s){se||(se=new OffscreenCanvas(2,2),re=se.getContext("2d",{willReadFrequently:!0}));let r=null;if(_(e))this.options.urlModifier&&(e=this.options.urlModifier(e)),Z.push([e,t,s,this]),ie();else {const t=new Blob([e]);r=createImageBitmap(t),r.then(ae.bind(this)).then((e=>{s(null,e);})).catch((e=>{console.warn(e),s(e);}));}}function ie(){if(!Z.length||ee.length>te)return;const e=Z.shift(),[t,s,r,n]=e;ee.push(e),fetch(t,s).then((e=>e.arrayBuffer())).then((e=>{const t=new Blob([new Uint8Array(e)]);return createImageBitmap(t)})).then(ae.bind(n)).then((t=>{r.call(n,null,t);const s=ee.indexOf(e);ee.splice(s,1),ie();})).catch((t=>{console.warn(t),r.call(n,t);const s=ee.indexOf(e);ee.splice(s,1),ie();}));}function ae(e){let{width:t,height:s}=e;oe(t)||(t=fe(t)),oe(s)||(s=fe(s));const r=this.options.maxTextureSize;r&&(t=Math.min(r,t),s=Math.min(r,s)),se.width=t,se.height=s,re.drawImage(e,0,0,t,s),e.close();const n=re.getImageData(0,0,t,s);return {width:t,height:s,data:new Uint8Array(n.data)}}function oe(e){return !(e&e-1)&&0!==e}function fe(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))}function ue(e,t){for(const s in e)if(e[s]===t)return s;return t}e.Ajax=P,e.GLTFLoader=class{constructor(e,t,s){if(this.options=s||{},this.options.decoders||(this.options.decoders={}),this._fetchOptions=this.options.fetchOptions||{},t.buffer instanceof ArrayBuffer){const{json:s,glbBuffer:r}=k.read(t.buffer,t.byteOffset,t.byteLength);this._init(e,s,r);}else this._init(e,t);this._accessor=new L(this.rootPath,this.gltf,this.glbBuffer,this._fetchOptions,this.options.urlModifier),this._checkExtensions();}_checkExtensions(){const e=this.gltf.extensionsRequired;if(e){if(e.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(e.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders["image/ktx2"])throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded");if(e.indexOf("EXT_meshopt_compression")>=0)throw new Error("EXT_meshopt_compression extension is not supported yet.")}}_loadExtensions(){const e=this.gltf.extensions;return e&&e.KHR_techniques_webgl?this._accessor.requestKHRTechniquesWebgl(e.KHR_techniques_webgl).then((t=>(e.KHR_techniques_webgl=t,e))):Promise.resolve(e)}_convertKhrTechiqueToTechiques(){if(!Array.isArray(this.gltf.programs))return;const e=this.gltf.materials;for(let t=0;t<e.length;t++)e[t]&&e[t].extensions&&e[t].extensions.KHR_technique_webgl&&(e[t].extensions.KHR_techniques_webgl=e[t].extensions.KHR_technique_webgl,delete e[t].extensions.KHR_technique_webgl);const t=this.gltf.extensions||{},s=this.gltf.techniques;t.KHR_techniques_webgl={programs:this.gltf.programs,shaders:this.gltf.shaders,techniques:s};for(let t=0;t<e.length;t++){const n=(r=e[t])&&r.extensions&&r.extensions.KHR_techniques_webgl;if(n){const{values:e,technique:t}=n,r=s[t];if(!r||!e)continue;const{uniforms:i,parameters:a}=r,o={};for(const t in e){const s=ue(i,t);o[s]=e[t],a[t]&&35678===a[t].type&&(o[s]={index:e[t]});}n.values=o;}}var r;for(let e=0;e<s.length;e++){const t=s[e];if(!t)continue;const{attributes:r,uniforms:n,parameters:i}=t;if(r)for(const e in r){const t=r[e];r[e]=i[t];}if(n)for(const e in n){const t=n[e];n[e]=i[t];}delete t.parameters;}return delete this.gltf.programs,delete this.gltf.shaders,delete this.gltf.techniques,this.gltf.extensions=t,t}load(e){e=e||{},this._convertKhrTechiqueToTechiques();const t=this._loadScene(e),s=this._loadAnimations(),r=this._loadTextures(),n=this._loadExtensions();return Promise.all([t,s,r,n]).then((e=>(e[0].animations=e[1],e[0].textures=e[2],e[0].extensions=e[3],e[0].transferables=this.transferables||[],this.createChannelsMap(e[0]),e[0])))}createChannelsMap(e){const t=e.animations;if(t)for(let e=0;e<t.length;e++){const s=t[e];s.channelsMap={};for(let e=0;e<s.channels.length;e++){const t=s.channels[e];s.channelsMap[t.target.node]||(s.channelsMap[t.target.node]=[]),s.channelsMap[t.target.node].push(t);}}}getExternalResources(){const e=[];if(this.gltf){const{buffers:t,images:s}=this.gltf;for(let s=0;s<t.length;s++)t[s].uri&&t[s].uri.indexOf("data:application/octet-stream;base64")<0&&e.push({type:"buffer",uri:t[s].uri});for(let t=0;t<s.length;t++)s[t].uri&&s[t].uri.indexOf("data:image/")<0&&e.push({type:"image",uri:s[t].uri});}return e}static getAnimationClip(e,t,s,r){return Y.getAnimationClip(e,t,s,r)}static getAnimationTimeSpan(e,t){return Y.getTimeSpanByName(e,t)}static getTypedArrayCtor(e){return x(e)}static readInterleavedArray(e,t,s,r,n,i,a){return B(e,t,s,r,n,i,a)}_init(e,t,s){this.gltf=t,this.glbBuffer=s,this.version=t.asset?+t.asset.version:1,this.rootPath=e,this.buffers={},this.requests={},this.options.requestImage=$?ne.bind(this):this.options.requestImage||Q,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new C(e,t,s,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this._fetchOptions,this.options.urlModifier),this.adapter.iterate(((e,t,s)=>{t.id="buffer_"+s;}),"buffers"),this.adapter.iterate(((e,t,s)=>{t.id="image_"+s;}),"images"),this.adapter.iterate(((e,t,s)=>{t.id="accessor_"+s;}),"accessors")):(this.adapter=new D(e,t,s,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this._fetchOptions,this.options.urlModifier),this.adapter.iterate(((e,t,s)=>{t.id="accessor_"+s;}),"accessors"),this.adapter.iterate(((e,t,s)=>{t.id="image_"+s;}),"images"));}_parseNodes(e,t){if(e.children&&e.children.length>0){if(!("number"==typeof(s=e.children[0])&&isFinite(s)||_(e.children[0])))return e;const r=e.children.map((e=>{const s=t[e];return s.nodeIndex=e,this._parseNodes(s,t)}));e.children=r;}var s;return e}_loadScene(e){return this._loadNodes(e).then((e=>{const t=this.scenes=[];let s;for(const t in e)e[t]=this._parseNodes(e[t],e),e[t].nodeIndex=Number(t)?Number(t):t;this.adapter.iterate(((r,n,i)=>{const a={};n.name&&(a.name=n.name),n.nodes&&(a.nodes=n.nodes.map((t=>e[t]))),this.gltf.scene===r&&(s=i),t.push(a);}),"scenes");const r={textures:this.gltf.textures,asset:this.gltf.asset,scene:s,scenes:t,nodes:e,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(r.extensions=this.gltf.extensions),1===this.version){const e=this.adapter._loadMaterials(this.gltf.materials);r.materials=e;}return delete this.gltf.buffers,r.json=this.gltf,r}))}_loadNodes(e){return this._loadMeshes(e).then((()=>{const e=this.nodes={};return this.adapter.iterate(((t,s)=>{const r=this.adapter.createNode(s,this.meshes,this.skins);e[t]=r;}),"nodes"),e}))}_loadSkins(){this.skins=[];const e=[];return this.adapter.iterate(((t,s,r)=>{e.push(this._loadSkin(s).then((e=>{e.index=r,this.skins.push(e);})));}),"skins"),e}_loadSkin(e){const t=e.inverseBindMatrices;return this.adapter.accessor._requestData("inverseBindMatrices",t).then((t=>(e.inverseBindMatrices=t,t&&t.buffer&&this.transferables&&this.transferables.indexOf(t.buffer)<0&&this.transferables.push(t.buffer),e)))}_loadAnimations(){const e=this.gltf.animations;return b(e)?this.adapter.getAnimations(e):null}_loadMeshes(e){this.meshes={};let t=[];return this.adapter.iterate(((s,r,n)=>{t.push(this._loadMesh(r,e).then((e=>{e.index=n,this.meshes[s]=e;})));}),"meshes"),t=t.concat(this._loadSkins()),Promise.all(t)}_loadMesh(e,t){const s=e.primitives.map((e=>this._loadPrimitive(e,t))).filter((e=>!!e));return Promise.all(s).then((t=>{const s={};return y(s,e),s.primitives=t,s}))}_loadTextures(){const e=this.gltf.textures;if(!e)return null;const t=[];for(const s in e)t.push(this.adapter._getTexture(s));return Promise.all(t).then((t=>{if(this.transferables)for(let e=0;e<t.length;e++){const s=t[e]&&t[e].image.array;if(s){let e;e=s instanceof ImageBitmap?s:s.buffer,e&&this.transferables.indexOf(e)<0&&this.transferables.push(e);}}if(!Array.isArray(e)){const s={},r=Object.keys(e);for(let e=0;e<t.length;e++)t[e]&&(s[r[e]]=t[e]);return s}return t}))}_loadPrimitive(e,t){let s;const r=[],n=e.extensions;if(b(e.targets))for(let t=0;t<e.targets.length;t++){const s=e.targets[t];for(const e in s){const n=this.adapter.accessor._requestData(`morphTargets_${e}_${t}`,s[e]);n&&r.push(n);}}if(n&&n.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const e=this.options.decoders.draco,{bufferView:i,attributes:a}=n.KHR_draco_mesh_compression,o=this.gltf.bufferViews[i],f=this._accessor._requestBufferOfBufferView(o).then((s=>{const{buffer:r,byteOffset:n}=s;let{byteOffset:i}=o;const f=o.byteLength;i||(i=0);const u=new DataView(r,n+i,f),h={attributes:a,useUniqueIDs:!1,skipAttributeTransform:t.skipAttributeTransform};return e(u,h).then((e=>{const t=Object.values(e.attributes);return e.indices&&t.push(e.indices),t}))}));r.push(f),s=Promise.all(r);}else {const t=e.attributes;for(const e in t){const s=this.adapter.accessor._requestData(e,t[e]);s&&r.push(s);}if(b(e.indices)){const t=this.adapter.accessor._requestData("indices",e.indices);t&&r.push(t);}s=Promise.all(r);}return s.then((t=>{if(n&&n.KHR_draco_mesh_compression){const s=e.targets?e.targets.length:0;t[s]=t[s].concat(t.slice(0,s)),t=t[s];}let s,r;const i={attributes:t.reduce(((e,t)=>{if("indices"===t.name)s=t;else if(t.name.indexOf("morphTargets_")>-1)r=r||{},r[t.name.slice(13)]=t;else {if(!("POSITION"!==t.name||t.min&&t.max)){const e=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0],{itemSize:r,array:n}=t,i=n.length/r;for(let t=0;t<i;t++)for(let i=0;i<r;i++){const a=t*r+i;n[a]<e[i]&&(e[i]=n[a]),n[a]>s[i]&&(s[i]=n[a]);}if(t.quantization){const r=t.quantization,n=r.range/(1<<r.quantizationBits),i=r.minValues;u(e,e,n),f(e,e,i),u(s,s,n),f(s,s,i);}t.min=e,t.max=s;}e[t.name]=t;}return this.transferables&&t.array.buffer&&this.transferables.indexOf(t.array.buffer)<0&&this.transferables.push(t.array.buffer),e}),{}),material:e.material};return s&&(i.indices=s),r&&(i.morphTargets=r),i.mode=b(e.mode)?e.mode:4,b(e.extras)&&(i.extras=e.extras),i}))}},t().maptalks_gltf_loader=e;}gltfLoaderExport({});
74
74
 
75
75
  const getGlobal = function () {
76
76
  if (typeof globalThis !== 'undefined') {
@@ -609,7 +609,8 @@ function isTextureDestroyed(texture) {
609
609
  return true;
610
610
  }
611
611
  function isTextureLike(texture) {
612
- return texture && (texture.dispose || texture.destroy);
612
+ // not a GPUBuffer or a REGLBuffer
613
+ return texture && !texture.mapAsync && (texture.dispose || texture.destroy);
613
614
  }
614
615
 
615
616
  var Util = /*#__PURE__*/Object.freeze({
@@ -1862,7 +1863,7 @@ class Geometry {
1862
1863
  return device.buffer(data);
1863
1864
  }
1864
1865
  }
1865
- static padGPUBufferAlignment(array, vertexCount) {
1866
+ static padGPUBufferAlignment(array, vertexCount, transient = false) {
1866
1867
  if (vertexCount === 0) {
1867
1868
  return array;
1868
1869
  }
@@ -1877,7 +1878,13 @@ class Geometry {
1877
1878
  if (itemSize === 3) {
1878
1879
  // itemSize 为 3时,补位为 4,wgsl中需要相应修改类型声明
1879
1880
  const newItemSize = ensureAlignment(itemSize, bytesPerElement);
1880
- const newArray = getTempParamArray(ctor, newItemSize * vertexCount); //new ctor(newItemSize * vertexCount);
1881
+ let newArray;
1882
+ if (transient) {
1883
+ newArray = getTempParamArray(ctor, newItemSize * vertexCount); //new ctor(newItemSize * vertexCount);
1884
+ }
1885
+ else {
1886
+ newArray = new ctor(newItemSize * vertexCount);
1887
+ }
1881
1888
  for (let i = 0; i < vertexCount; i++) {
1882
1889
  for (let ii = 0; ii < itemSize; ii++) {
1883
1890
  newArray[i * newItemSize + ii] = array[i * itemSize + ii];
@@ -1888,7 +1895,13 @@ class Geometry {
1888
1895
  else {
1889
1896
  // itemSize 为 1或2时,提升数组的类型,不影响wgsl中的类型声明
1890
1897
  const newCtor = getPadArrayCtor(ctor, itemSize);
1891
- const newArray = getTempParamArray(newCtor, itemSize * vertexCount); //new newCtor(itemSize * vertexCount);
1898
+ let newArray;
1899
+ if (transient) {
1900
+ newArray = getTempParamArray(newCtor, itemSize * vertexCount); //new newCtor(itemSize * vertexCount);
1901
+ }
1902
+ else {
1903
+ newArray = new newCtor(itemSize * vertexCount);
1904
+ }
1892
1905
  newArray.set(array);
1893
1906
  return newArray;
1894
1907
  }
@@ -2162,11 +2175,20 @@ class Geometry {
2162
2175
  }
2163
2176
  }
2164
2177
  else {
2165
- const arr = data[key].data ? data[key].data : data[key];
2166
- const dimension = arr.length / vertexCount;
2178
+ let arr = data[key].data ? data[key].data : data[key];
2179
+ const dimension = Math.floor(arr.length / vertexCount);
2180
+ if (dimension * vertexCount !== arr.length) {
2181
+ arr = arr.slice(0, vertexCount * dimension);
2182
+ if (data[key].data) {
2183
+ data[key].data = arr;
2184
+ }
2185
+ else {
2186
+ data[key] = arr;
2187
+ }
2188
+ }
2167
2189
  let bufferData = arr;
2168
2190
  if (isWebGPU) {
2169
- bufferData = Geometry.padGPUBufferAlignment(arr, vertexCount);
2191
+ bufferData = Geometry.padGPUBufferAlignment(arr, vertexCount, true);
2170
2192
  }
2171
2193
  const info = data[key].data ? data[key] : {};
2172
2194
  info.data = bufferData;
@@ -2327,7 +2349,7 @@ class Geometry {
2327
2349
  if (buffer) {
2328
2350
  if (buffer.buffer.mapState) {
2329
2351
  //webgpu buffer
2330
- data = Geometry.padGPUBufferAlignment(data, this._vertexCount);
2352
+ data = Geometry.padGPUBufferAlignment(data, this._vertexCount, true);
2331
2353
  buffer.buffer = this._updateGPUBuffer(buffer.buffer, data, 0, data.buffer.byteLength);
2332
2354
  }
2333
2355
  else {
@@ -2357,7 +2379,7 @@ class Geometry {
2357
2379
  buffer.destroy();
2358
2380
  return newBuffer;
2359
2381
  }
2360
- device.wgpu.queue.writeBuffer(buffer, 0, data.buffer, offset, byteLength);
2382
+ device.wgpu.queue.writeBuffer(buffer, offset, data.buffer, 0, byteLength);
2361
2383
  return buffer;
2362
2384
  }
2363
2385
  updateSubData(name, data, offset) {
@@ -2375,14 +2397,16 @@ class Geometry {
2375
2397
  }
2376
2398
  if (buffer) {
2377
2399
  if (buffer.buffer.mapState) {
2400
+ const itemSize = buffer.buffer.itemCount / this._vertexCount;
2401
+ const itemCount = data.length / itemSize;
2378
2402
  //webgpu buffer
2379
- data = Geometry.padGPUBufferAlignment(data, this._vertexCount);
2403
+ data = Geometry.padGPUBufferAlignment(data, itemCount, true);
2380
2404
  const byteWidth = buffer.buffer.bytesPerElement;
2381
2405
  if (data.BYTES_PER_ELEMENT !== byteWidth) {
2382
2406
  const ctor = getTypeCtor(data, byteWidth);
2383
2407
  data = new ctor(data);
2384
2408
  }
2385
- buffer.buffer = this._updateGPUBuffer(buffer.buffer, data, offset * byteWidth, data.buffer.byteLength);
2409
+ buffer.buffer = this._updateGPUBuffer(buffer.buffer, data, offset * byteWidth, data.length * byteWidth);
2386
2410
  }
2387
2411
  else {
2388
2412
  const byteWidth = REGL_TYPE_WIDTH[buffer.buffer['_buffer'].dtype];
@@ -3041,7 +3065,7 @@ function getItemFormat(data, itemSize) {
3041
3065
  return itemSize > 1 ? (format + 'x' + itemSize) : format;
3042
3066
  }
3043
3067
  function getAttrArray(data) {
3044
- return data.data || (data.buffer.destroy && data.buffer) || data;
3068
+ return data.data || (data.buffer && data.buffer.destroy && data.buffer) || data;
3045
3069
  }
3046
3070
  function createGPUBuffer(device, data, usage, label) {
3047
3071
  data = data.data || data;
@@ -8698,7 +8722,7 @@ class InstancedMesh extends Mesh {
8698
8722
  data[key] = new Float32Array(data[key]);
8699
8723
  }
8700
8724
  else if (isWebGPU && isArray(data[key])) {
8701
- data[key] = Geometry.padGPUBufferAlignment(data[key], instanceCount);
8725
+ data[key] = Geometry.padGPUBufferAlignment(data[key], instanceCount, true);
8702
8726
  }
8703
8727
  const attrBuf = data[key];
8704
8728
  if (attrBuf.buffer !== undefined && attrBuf.buffer.destroy) {
@@ -9841,7 +9865,7 @@ function replace(match, include) {
9841
9865
  return parseIncludes(replace);
9842
9866
  }
9843
9867
 
9844
- const vert$q = /* wgsl */ `
9868
+ const vert$p = /* wgsl */ `
9845
9869
  @group(0) @binding($b) var<uniform> terrainAltitudeScale: f32;
9846
9870
 
9847
9871
  // 获取实例属性矩阵函数
@@ -9912,11 +9936,11 @@ const attributes$5 = [
9912
9936
  }
9913
9937
  ];
9914
9938
  var instance = {
9915
- vert: vert$q, attributes: attributes$5,
9939
+ vert: vert$p, attributes: attributes$5,
9916
9940
  defines: ['HAS_INSTANCE']
9917
9941
  };
9918
9942
 
9919
- const vert$p = /* wgsl */ `
9943
+ const vert$o = /* wgsl */ `
9920
9944
  // 矩阵求逆函数
9921
9945
  fn invert_matrix(matrix: mat4x4f) -> mat4x4f {
9922
9946
  let vector1 = matrix[0];
@@ -10021,12 +10045,12 @@ fn transpose_matrix(matrix: mat4x4f) -> mat4x4f {
10021
10045
  return m;
10022
10046
  }
10023
10047
  `;
10024
- const frag$t = vert$p;
10048
+ const frag$t = vert$o;
10025
10049
  var invert_matrix = {
10026
- vert: vert$p, frag: frag$t
10050
+ vert: vert$o, frag: frag$t
10027
10051
  };
10028
10052
 
10029
- const vert$o = /* wgsl */ `
10053
+ const vert$n = /* wgsl */ `
10030
10054
  #define ALTITUDE_SCALE 32767.0
10031
10055
  #define EXTRUDE_SCALE 63.0
10032
10056
 
@@ -10082,12 +10106,12 @@ const attributes$4 = [
10082
10106
  }
10083
10107
  ];
10084
10108
  var line_extrusion = {
10085
- vert: vert$o,
10109
+ vert: vert$n,
10086
10110
  attributes: attributes$4,
10087
10111
  defines: ['IS_LINE_EXTRUSION']
10088
10112
  };
10089
10113
 
10090
- const vert$n = /* wgsl */ `
10114
+ const vert$m = /* wgsl */ `
10091
10115
  #ifdef HAS_MASK_EXTENT
10092
10116
  struct MaskUniforms {
10093
10117
  mask_extent: vec4f,
@@ -10188,18 +10212,16 @@ const varyings$4 = [
10188
10212
  ];
10189
10213
  var mask = {
10190
10214
  defines: ['HAS_MASK_EXTENT'],
10191
- vert: vert$n,
10215
+ vert: vert$m,
10192
10216
  varyings: varyings$4
10193
10217
  };
10194
10218
 
10195
- const vert$m = /* wgsl */ `
10219
+ const vert$l = /* wgsl */ `
10196
10220
  #include <invert_matrix>
10197
10221
  #include <draco_decode_vert>
10198
10222
 
10199
-
10200
10223
  #include <instance_vert>
10201
10224
 
10202
-
10203
10225
  #ifdef HAS_SKIN
10204
10226
  struct SkinUniforms {
10205
10227
  skinAnimation: i32,
@@ -10226,8 +10248,11 @@ const vert$m = /* wgsl */ `
10226
10248
  #endif
10227
10249
 
10228
10250
  #ifdef HAS_TERRAIN_FLAT_MASK
10251
+ struct TerrainMaskUniforms {
10252
+ maskResolution: vec2f
10253
+ };
10254
+ @group(0) @binding($b) var<uniform> terrainMaskUniforms: TerrainMaskUniforms;
10229
10255
  @group(0) @binding($b) var flatMask: texture_2d<f32>;
10230
- @group(0) @binding($b) var flatMaskSampler: sampler;
10231
10256
  #endif
10232
10257
 
10233
10258
  fn getPositionMatrix(input: VertexInput, vertexOutput: ptr<function, VertexOutput>, positionMatrix: mat4x4f) -> mat4x4f {
@@ -10279,9 +10304,10 @@ fn getPosition(inputPosition: vec3f, vertexInput: VertexInput) -> vec4f {
10279
10304
  outputPosition.z += vertexInput.aTerrainAltitude * 100.0;
10280
10305
  #endif
10281
10306
  #ifdef HAS_TERRAIN_FLAT_MASK
10282
- var uv = aTexCoord;
10307
+ var uv = vertexInput.aTexCoord;
10283
10308
  uv.y = 1.0 - uv.y;
10284
- let encodedHeight = textureSample(flatMask, flatMaskSampler, uv);
10309
+ let texCoord = vec2i(uv * terrainMaskUniforms.maskResolution);
10310
+ let encodedHeight = textureLoad(flatMask, texCoord, 0);
10285
10311
  if (length(encodedHeight) < 2.0) {
10286
10312
  let maskHeight = decodeFloat32(encodedHeight);
10287
10313
  outputPosition.z = min(outputPosition.z, maskHeight);
@@ -10388,10 +10414,10 @@ const attributes$3 = [
10388
10414
  var get_output = {
10389
10415
  attributes: attributes$3,
10390
10416
  varyings: varyings$3,
10391
- vert: vert$m
10417
+ vert: vert$l
10392
10418
  };
10393
10419
 
10394
- const vert$l = /* wgsl */ `
10420
+ const vert$k = /* wgsl */ `
10395
10421
  // 定义 uniform 变量
10396
10422
  struct JoinUniforms {
10397
10423
  numJoints: f32, // 关节数量
@@ -10440,13 +10466,13 @@ const attributes$2 = [
10440
10466
  }
10441
10467
  ];
10442
10468
  var skin = {
10443
- vert: vert$l,
10469
+ vert: vert$k,
10444
10470
  attributes: attributes$2,
10445
10471
  defines: ['HAS_SKIN']
10446
10472
  };
10447
10473
 
10448
10474
  //用于识别顶点颜色类型: topPolygonFill 还是 bottomPolygonFill
10449
- const vert$k = /* wgsl */ `
10475
+ const vert$j = /* wgsl */ `
10450
10476
  struct VertexColorsUniforms {
10451
10477
  vertexColorsOfType: array<vec4f, VERTEX_TYPES_COUNT>
10452
10478
  }
@@ -10479,11 +10505,11 @@ const varyings$2 = [
10479
10505
  }
10480
10506
  ];
10481
10507
  var vertex_color = {
10482
- vert: vert$k, frag: frag$s, attributes: attributes$1, varyings: varyings$2,
10508
+ vert: vert$j, frag: frag$s, attributes: attributes$1, varyings: varyings$2,
10483
10509
  defines: ['HAS_VERTEX_COLOR']
10484
10510
  };
10485
10511
 
10486
- const vert$j = /* wgsl */ `
10512
+ const vert$i = /* wgsl */ `
10487
10513
  struct ShadowUniforms {
10488
10514
  shadow_lightProjViewModelMatrix: mat4x4f,
10489
10515
  };
@@ -10562,10 +10588,10 @@ var vsm_shadow = {
10562
10588
  defines: (defines) => {
10563
10589
  return defines['HAS_SHADOWING'] && !defines['HAS_BLOOM'];
10564
10590
  },
10565
- vert: vert$j, frag: frag$r, varyings: varyings$1
10591
+ vert: vert$i, frag: frag$r, varyings: varyings$1
10566
10592
  };
10567
10593
 
10568
- const vert$i = /* wgsl */ `
10594
+ const vert$h = /* wgsl */ `
10569
10595
  #if HAS_DRACO_NORMAL || HAS_DRACO_POSITION || HAS_DRACO_TEXCOORD || HAS_WEB3D_QUANTIZED_ATTRIBUTES_TEXCOORD || HAS_COMPRESSED_INT16
10570
10596
  // 定义 uniform 变量
10571
10597
  struct DracoUniforms {
@@ -10712,10 +10738,10 @@ const vert$i = /* wgsl */ `
10712
10738
  }
10713
10739
  `;
10714
10740
  var draco_decode = {
10715
- vert: vert$i
10741
+ vert: vert$h
10716
10742
  };
10717
10743
 
10718
- const vert$h = /* wgsl */ `
10744
+ const vert$g = /* wgsl */ `
10719
10745
 
10720
10746
  // 顶点着色器函数
10721
10747
  fn highlight_setVarying(input: VertexInput, output: ptr<function, VertexOutput>) {
@@ -10740,9 +10766,8 @@ const frag$q = /* wgsl */ `
10740
10766
  let highlightColor = output.vHighlightColor;
10741
10767
  let opacity = highlightColor.a;
10742
10768
  outColor = vec4f(outColor.rgb * (1.0 - opacity) + highlightColor.rgb * opacity, outColor.a);
10743
- #if HAS_HIGHLIGHT_COLOR_POINT
10744
- #else
10745
- // 如果没有高亮颜色点
10769
+ #ifndef HAS_HIGHLIGHT_COLOR_POINT
10770
+ // 如果没有高亮颜色点
10746
10771
  outColor.a = outColor.a * (1.0 - opacity) + opacity;
10747
10772
  #endif
10748
10773
  #endif
@@ -10783,7 +10808,7 @@ var highlight$1 = {
10783
10808
  defines: (defines) => {
10784
10809
  return defines['HAS_HIGHLIGHT_OPACITY'] || defines['HAS_HIGHLIGHT_COLOR'];
10785
10810
  },
10786
- vert: vert$h, frag: frag$q, attributes, varyings
10811
+ vert: vert$g, frag: frag$q, attributes, varyings
10787
10812
  };
10788
10813
 
10789
10814
  const frag$p = /* wgsl */ `
@@ -10826,7 +10851,7 @@ var compute_texcoord = {
10826
10851
  frag: frag$p
10827
10852
  };
10828
10853
 
10829
- const vert$g = /*wgsl*/ `
10854
+ const vert$f = /*wgsl*/ `
10830
10855
  //--------------------------
10831
10856
  // Picking
10832
10857
  //
@@ -10865,7 +10890,7 @@ fn fbo_picking_setData(input: VertexInput, output: ptr<function, VertexOutput>,
10865
10890
  }
10866
10891
  `;
10867
10892
  var fbo_picking = {
10868
- vert: vert$g,
10893
+ vert: vert$f,
10869
10894
  attributes: [
10870
10895
  {
10871
10896
  defines: (defines) => {
@@ -10898,7 +10923,7 @@ var fbo_picking = {
10898
10923
  ]
10899
10924
  };
10900
10925
 
10901
- const vert$f = /* wgsl */ `
10926
+ const vert$e = /* wgsl */ `
10902
10927
  const COMMON_FLOAT_MAX: f32 = 1.70141184e38;
10903
10928
  const COMMON_FLOAT_MIN: f32 = 1.17549435e-38;
10904
10929
 
@@ -10994,12 +11019,12 @@ fn decodeFloat32(inputRgba: vec4f) -> f32 {
10994
11019
  return Result;
10995
11020
  }
10996
11021
  `;
10997
- const frag$o = vert$f;
11022
+ const frag$o = vert$e;
10998
11023
  var common_pack_float = {
10999
- vert: vert$f, frag: frag$o
11024
+ vert: vert$e, frag: frag$o
11000
11025
  };
11001
11026
 
11002
- const vert$e = /*wgsl*/ `
11027
+ const vert$d = /*wgsl*/ `
11003
11028
  #ifdef HAS_EXCAVATE_ANALYSIS
11004
11029
  struct ExcavateUniforms {
11005
11030
  excavateExtent: vec4f
@@ -11058,7 +11083,7 @@ fn excavateColor(fragColor: vec4f, vertexOutput: VertexOutput) -> vec4f {
11058
11083
  `;
11059
11084
  var excavate = {
11060
11085
  defines: ['HAS_EXCAVATE_ANALYSIS'],
11061
- vert: vert$e,
11086
+ vert: vert$d,
11062
11087
  frag: frag$n,
11063
11088
  varyings: [
11064
11089
  {
@@ -11186,17 +11211,15 @@ const frag$j = /*wgsl*/ `
11186
11211
  struct TerrainNormalUniforms {
11187
11212
  terrainHeightMapResolution: vec2f,
11188
11213
  terrainResolution: vec2f,
11189
- terrainHeightScale: f32,
11190
- terrainTileResolution: f32,
11191
11214
  terrainUnpackFactors: vec4f
11192
11215
  };
11193
11216
 
11194
11217
  @group(0) @binding($b) var<uniform> terrainNormalUniforms: TerrainNormalUniforms;
11195
11218
  @group(0) @binding($b) var terrainHeightTexture: texture_2d<f32>;
11196
- @group(0) @binding($b) var terrainHeightSampler: sampler;
11219
+ @group(0) @binding($b) var terrainHeightTextureSampler: sampler;
11197
11220
 
11198
11221
  fn getHeight(uv: vec2f) -> f32 {
11199
- let color = textureSample(terrainHeightTexture, terrainHeightSampler, uv) * 255.0;
11222
+ let color = textureSample(terrainHeightTexture, terrainHeightTextureSampler, uv) * 255.0;
11200
11223
  let colorWithAlpha = vec4f(color.rgb, -1.0);
11201
11224
  return dot(colorWithAlpha, terrainNormalUniforms.terrainUnpackFactors) / 4.0;
11202
11225
  }
@@ -11227,7 +11250,7 @@ var terrain_normal = {
11227
11250
  frag: frag$j
11228
11251
  };
11229
11252
 
11230
- const vert$d = /*wgsl*/ `
11253
+ const vert$c = /*wgsl*/ `
11231
11254
  #include <fbo_picking_vert>
11232
11255
  #include <get_output>
11233
11256
 
@@ -11256,7 +11279,7 @@ struct VertexOutput {
11256
11279
  fn main(input: VertexInput) -> VertexOutput {
11257
11280
  var output: VertexOutput;
11258
11281
 
11259
- let localPositionMatrix = getPositionMatrix(input, &output, uniforms.modelMatrix);
11282
+ let localPositionMatrix = getPositionMatrix(input, &output, uniforms.positionMatrix);
11260
11283
  let localPosition = getPosition(vec3f(input.aPosition.xyz), input);
11261
11284
 
11262
11285
  output.position = uniforms.projViewModelMatrix * localPositionMatrix * localPosition;
@@ -11267,7 +11290,7 @@ fn main(input: VertexInput) -> VertexOutput {
11267
11290
  }
11268
11291
  `;
11269
11292
  var mesh_picking = {
11270
- vert: vert$d
11293
+ vert: vert$c
11271
11294
  };
11272
11295
 
11273
11296
  const frag$i = /*wgsl*/ `
@@ -11339,6 +11362,7 @@ var WgslShaderLib = {
11339
11362
  }
11340
11363
  };
11341
11364
  const pattern = /^[ \t]*#include +<([\w\d.]+)>/gm;
11365
+ const attrInputPattern = /\bstruct\s+AttributeInput\b/;
11342
11366
  const vertexInputPattern = /\bstruct\s+VertexInput\b/;
11343
11367
  const vertexOutputPattern = /\bstruct\s+VertexOutput\b/;
11344
11368
  class SourceCompiler {
@@ -11402,6 +11426,9 @@ class SourceCompiler {
11402
11426
  });
11403
11427
  }
11404
11428
  fillAttributes(source) {
11429
+ if (source.indexOf('AttributeInput') > 0) {
11430
+ return this.fillStruct(source, attrInputPattern, '$i', this.attributes);
11431
+ }
11405
11432
  return this.fillStruct(source, vertexInputPattern, '$i', this.attributes);
11406
11433
  }
11407
11434
  fillVaryings(source) {
@@ -11571,30 +11598,39 @@ class PipelineDescriptor {
11571
11598
  }
11572
11599
  else {
11573
11600
  const offsetProps = commandProps.polygonOffset.offset;
11574
- if (offsetProps && !isNil$2(offsetProps.units)) {
11575
- if (isFunction$1(offsetProps.units)) {
11576
- depthBias = offsetProps.units(null, uniformValues);
11577
- this.functionProps.push({ func: offsetProps.units, v: depthBias });
11578
- }
11579
- else {
11580
- depthBias = offsetProps.units;
11581
- }
11601
+ if (isFunction$1(offsetProps)) {
11602
+ const offset = offsetProps(null, uniformValues);
11603
+ depthBias = offset.units;
11604
+ depthBiasSlopeScale = offset.factor;
11605
+ this.functionProps.push({ func: (_, props) => { return offsetProps(null, props).units; }, v: depthBias });
11606
+ this.functionProps.push({ func: (_, props) => { return offsetProps(null, props).factor; }, v: depthBiasSlopeScale });
11582
11607
  }
11583
- if (offsetProps && !isNil$2(offsetProps.factor)) {
11584
- if (isFunction$1(offsetProps.factor)) {
11585
- depthBiasSlopeScale = offsetProps.factor(null, uniformValues);
11586
- this.functionProps.push({ func: offsetProps.factor, v: depthBiasSlopeScale });
11608
+ else {
11609
+ if (offsetProps && !isNil$2(offsetProps.units)) {
11610
+ if (isFunction$1(offsetProps.units)) {
11611
+ depthBias = offsetProps.units(null, uniformValues);
11612
+ this.functionProps.push({ func: offsetProps.units, v: depthBias });
11613
+ }
11614
+ else {
11615
+ depthBias = offsetProps.units;
11616
+ }
11587
11617
  }
11588
- else {
11589
- depthBiasSlopeScale = offsetProps.factor;
11618
+ if (offsetProps && !isNil$2(offsetProps.factor)) {
11619
+ if (isFunction$1(offsetProps.factor)) {
11620
+ depthBiasSlopeScale = offsetProps.factor(null, uniformValues);
11621
+ this.functionProps.push({ func: offsetProps.factor, v: depthBiasSlopeScale });
11622
+ }
11623
+ else {
11624
+ depthBiasSlopeScale = offsetProps.factor;
11625
+ }
11590
11626
  }
11591
11627
  }
11592
11628
  }
11593
11629
  }
11594
11630
  this.depthBias = depthBias;
11595
11631
  this.depthBiasSlopeScale = depthBiasSlopeScale;
11596
- let depthCompare = 'always';
11597
- let depthWriteEnable = false;
11632
+ let depthCompare = 'less';
11633
+ let depthWriteEnable = true;
11598
11634
  const depthProps = commandProps.depth;
11599
11635
  if (depthEnabled && depthProps && isEnable(depthProps.enable, uniformValues)) {
11600
11636
  if (depthProps.func) {
@@ -11770,14 +11806,15 @@ function isEnable(enable, props) {
11770
11806
  return !!enable;
11771
11807
  }
11772
11808
 
11773
- let arrayBuffer = new ArrayBuffer(1024 * 1024 * 4);
11809
+ const arrayBuffer = new ArrayBuffer(1024 * 1024 * 4);
11810
+ const flipYBuffer = new ArrayBuffer(1024 * 1024 * 4);
11774
11811
  class GraphicsTexture {
11775
11812
  constructor(device, config) {
11776
- //@internal
11777
- this._bindGroups = [];
11813
+ this.version = 0;
11778
11814
  this.device = device;
11779
11815
  this.config = config;
11780
11816
  this.gpuFormat = toTextureFormat(config.format, config.type);
11817
+ this.dirty = false;
11781
11818
  this._updateTexture();
11782
11819
  }
11783
11820
  get width() {
@@ -11786,57 +11823,47 @@ class GraphicsTexture {
11786
11823
  get height() {
11787
11824
  return this.texture && this.texture.height || this.config && this.config.height;
11788
11825
  }
11826
+ get arrayLayers() {
11827
+ return 1;
11828
+ }
11789
11829
  // called when minFilter or magFilter changed
11790
11830
  updateFilter() {
11791
- this._clearBindGroups();
11792
- }
11793
- _clearBindGroups() {
11794
- if (this._bindGroups.length) {
11795
- for (let i = 0; i < this._bindGroups.length; i++) {
11796
- this._bindGroups[i].outdated = true;
11797
- }
11798
- this._bindGroups = [];
11831
+ if (this.texture) {
11832
+ this.version++;
11799
11833
  }
11800
11834
  }
11801
11835
  resize(width, height) {
11802
11836
  if (this.texture && this.texture.width === width && this.texture.height === height) {
11803
11837
  return;
11804
11838
  }
11839
+ this.dirty = true;
11805
11840
  this.config.width = width;
11806
11841
  this.config.height = height;
11807
11842
  this._updateTexture();
11808
11843
  }
11809
11844
  update(config) {
11845
+ if (this.texture) {
11846
+ this.dirty = this._isDirty(config);
11847
+ }
11848
+ const { width, height } = this._getSize(config);
11810
11849
  extend$1(this.config, config);
11850
+ this.config.width = width;
11851
+ this.config.height = height;
11811
11852
  this.gpuFormat = toTextureFormat(this.config.format, this.config.type);
11812
11853
  this._updateTexture();
11813
11854
  }
11814
11855
  _updateTexture() {
11815
11856
  const config = this.config;
11857
+ const { width, height } = this._getSize(config);
11816
11858
  const device = this.device.wgpu;
11817
- if (this.texture) {
11818
- this.texture.destroy();
11819
- this._clearBindGroups();
11859
+ if (this.dirty) {
11860
+ this.version++;
11861
+ this.device.addToDestroyList(this.texture);
11862
+ this.texture = null;
11863
+ this.dirty = false;
11820
11864
  }
11821
- let texture;
11865
+ let texture = this.texture;
11822
11866
  {
11823
- let width = isFunction$1(config.width) ? config.width() : config.width;
11824
- let height = isFunction$1(config.height) ? config.height() : config.height;
11825
- if (width === undefined || height === undefined) {
11826
- const data = config.data;
11827
- if (!data) {
11828
- width = height = 1;
11829
- }
11830
- else if (isArray(config.data)) {
11831
- const length = config.data.length;
11832
- width = Math.sqrt(length / 4);
11833
- height = width;
11834
- }
11835
- else {
11836
- width = data.width;
11837
- height = data.height;
11838
- }
11839
- }
11840
11867
  const format = this.gpuFormat.format;
11841
11868
  const isDepth = format === 'depth24plus' || format === 'depth24plus-stencil8';
11842
11869
  const usage = isDepth ?
@@ -11844,84 +11871,213 @@ class GraphicsTexture {
11844
11871
  :
11845
11872
  GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT;
11846
11873
  const options = {
11847
- size: [width, height, 1],
11874
+ size: [width, height, this.arrayLayers],
11848
11875
  format,
11849
- usage
11876
+ usage,
11877
+ mipLevelCount: this.getMipLevelCount()
11850
11878
  };
11851
11879
  if (config.sampleCount) {
11852
11880
  options.sampleCount = config.sampleCount;
11853
11881
  }
11854
- texture = device.createTexture(options);
11855
- if (config.data) {
11856
- if (isArray(config.data)) {
11857
- const data = config.data;
11858
- const isUint8 = !config.type || config.type === 'uint8';
11859
- let byteLength;
11860
- if (Array.isArray(data)) {
11861
- byteLength = isUint8 ? data.length : data.length * 4;
11862
- }
11863
- else {
11864
- byteLength = data.byteLength;
11865
- }
11866
- const isRGBA = !config.format || config.format === 'rgba';
11867
- const isPremultipliedAlpha = isRGBA && config.premultiplyAlpha;
11868
- let dataToWrite;
11869
- if (isPremultipliedAlpha || Array.isArray(data)) {
11870
- if (arrayBuffer.byteLength < byteLength) {
11871
- arrayBuffer = new ArrayBuffer(byteLength);
11872
- }
11873
- if (isUint8) {
11874
- dataToWrite = new Uint8Array(arrayBuffer, 0, byteLength);
11875
- }
11876
- else {
11877
- dataToWrite = new Float32Array(arrayBuffer, 0, byteLength / 4);
11878
- }
11879
- }
11880
- if (isPremultipliedAlpha) {
11881
- const ratio = isUint8 ? 255 : 1;
11882
- for (let i = 0; i < data.length; i += 4) {
11883
- const alpha = data[i + 3] / ratio;
11884
- dataToWrite[i] = data[i] * alpha;
11885
- dataToWrite[i + 1] = data[i + 1] * alpha;
11886
- dataToWrite[i + 2] = data[i + 2] * alpha;
11887
- dataToWrite[i + 3] = data[i + 3];
11888
- }
11889
- }
11890
- else {
11891
- if (Array.isArray(data)) {
11892
- for (let i = 0; i < data.length; i++) {
11893
- dataToWrite[i] = data[i];
11894
- }
11895
- }
11896
- else {
11897
- dataToWrite = data;
11898
- }
11899
- }
11900
- device.queue.writeTexture({ texture: texture }, dataToWrite.buffer, {
11901
- bytesPerRow: width * this.gpuFormat.bytesPerTexel
11902
- }, [width, height]);
11903
- }
11904
- else {
11905
- device.queue.copyExternalImageToTexture({ source: config.data, flipY: !!this.config.flipY }, { texture: texture, premultipliedAlpha: !!this.config.premultiplyAlpha }, [width, height]);
11882
+ texture = texture || device.createTexture(options);
11883
+ this.fillData(texture, width, height);
11884
+ }
11885
+ this.texture = texture;
11886
+ }
11887
+ _isDirty(newConfig) {
11888
+ if (!this.texture) {
11889
+ return false;
11890
+ }
11891
+ const { width, height } = this._getSize(newConfig);
11892
+ if (width !== this.texture.width) {
11893
+ return true;
11894
+ }
11895
+ if (height !== this.texture.height) {
11896
+ return true;
11897
+ }
11898
+ if (newConfig.format && newConfig.format !== this.config.format) {
11899
+ return true;
11900
+ }
11901
+ if (newConfig.type && newConfig.type !== this.config.type) {
11902
+ return true;
11903
+ }
11904
+ if (this.getMipLevelCount(newConfig.data) !== this.getMipLevelCount()) {
11905
+ return true;
11906
+ }
11907
+ return false;
11908
+ }
11909
+ _getSize(config) {
11910
+ let width = isFunction$1(config.width) ? config.width() : config.width;
11911
+ let height = isFunction$1(config.height) ? config.height() : config.height;
11912
+ if (width === undefined || height === undefined) {
11913
+ const data = config.data;
11914
+ if (!data) {
11915
+ width = height = 1;
11916
+ }
11917
+ else if (isArray(config.data)) {
11918
+ const length = config.data.length;
11919
+ width = Math.sqrt(length / 4);
11920
+ height = width;
11921
+ }
11922
+ else {
11923
+ width = data.videoWidth || data.width;
11924
+ height = data.videoHeight || data.height;
11925
+ }
11926
+ }
11927
+ return { width, height };
11928
+ }
11929
+ getMipLevelCount(data) {
11930
+ data = data || this.config.data;
11931
+ if (data && data.mipmap) {
11932
+ return data.mipmap.length;
11933
+ }
11934
+ return 1;
11935
+ }
11936
+ fillData(texture, width, height) {
11937
+ const config = this.config;
11938
+ const origin = [0, 0, 0];
11939
+ if (config.data) {
11940
+ if (this.isArrayData(config.data)) {
11941
+ this.fillArrayData(texture, config.data, width, height, origin);
11942
+ }
11943
+ else {
11944
+ this.fillImageData(texture, config.data, width, height, origin);
11945
+ }
11946
+ }
11947
+ }
11948
+ fillImageData(texture, data, width, height, origin) {
11949
+ const device = this.device.wgpu;
11950
+ const flipY = !!this.config.flipY;
11951
+ const premultipliedAlpha = !!this.config.premultiplyAlpha;
11952
+ if (data.mipmap) {
11953
+ const mipmap = data.mipmap;
11954
+ for (let i = 0; i < mipmap.length; i++) {
11955
+ device.queue.copyExternalImageToTexture({ source: mipmap[i], flipY }, { texture, premultipliedAlpha, mipLevel: i, origin }, [Math.max(1, width >> i), Math.max(1, height >> i)]);
11956
+ }
11957
+ }
11958
+ else {
11959
+ device.queue.copyExternalImageToTexture({ source: data, flipY }, { texture: texture, premultipliedAlpha, origin }, [width, height]);
11960
+ }
11961
+ }
11962
+ fillArrayData(texture, data, width, height, origin) {
11963
+ if (data.mipmap) {
11964
+ for (let i = 0; i < data.mipmap.length; i++) {
11965
+ this._fillMipmap(texture, i, data.mipmap[i], Math.max(1, texture.width >> i), Math.max(1, texture.width >> i), origin);
11966
+ }
11967
+ }
11968
+ else {
11969
+ this._fillMipmap(texture, 0, data, width, height, origin);
11970
+ }
11971
+ }
11972
+ _fillMipmap(texture, mipLevel, data, width, height, origin) {
11973
+ const device = this.device.wgpu;
11974
+ const dataToWrite = this.formatTextureArray(data, arrayBuffer, width, height);
11975
+ device.queue.writeTexture({ texture, mipLevel, origin }, dataToWrite, {
11976
+ bytesPerRow: width * this.gpuFormat.bytesPerTexel
11977
+ }, [width, height]);
11978
+ }
11979
+ formatTextureArray(data, arrayBuffer, width, height) {
11980
+ const config = this.config;
11981
+ const isUint8 = !config.type || config.type === 'uint8';
11982
+ let byteLength;
11983
+ if (Array.isArray(data)) {
11984
+ byteLength = isUint8 ? data.length : data.length * 4;
11985
+ }
11986
+ else {
11987
+ byteLength = data.byteLength;
11988
+ }
11989
+ const isRGBA = !config.format || config.format === 'rgba';
11990
+ const isPremultipliedAlpha = isRGBA && config.premultiplyAlpha;
11991
+ let dataToWrite;
11992
+ if (isPremultipliedAlpha || Array.isArray(data)) {
11993
+ if (arrayBuffer.byteLength < byteLength) {
11994
+ arrayBuffer.resize(byteLength);
11995
+ }
11996
+ if (isUint8) {
11997
+ dataToWrite = new Uint8Array(arrayBuffer, 0, byteLength);
11998
+ }
11999
+ else {
12000
+ dataToWrite = new Float32Array(arrayBuffer, 0, byteLength / 4);
12001
+ }
12002
+ }
12003
+ if (isPremultipliedAlpha) {
12004
+ const ratio = isUint8 ? 255 : 1;
12005
+ for (let i = 0; i < data.length; i += 4) {
12006
+ const alpha = data[i + 3] / ratio;
12007
+ dataToWrite[i] = data[i] * alpha;
12008
+ dataToWrite[i + 1] = data[i + 1] * alpha;
12009
+ dataToWrite[i + 2] = data[i + 2] * alpha;
12010
+ dataToWrite[i + 3] = data[i + 3];
12011
+ }
12012
+ }
12013
+ else {
12014
+ if (Array.isArray(data)) {
12015
+ for (let i = 0; i < data.length; i++) {
12016
+ dataToWrite[i] = data[i];
11906
12017
  }
11907
12018
  }
12019
+ else {
12020
+ dataToWrite = data;
12021
+ }
11908
12022
  }
11909
- this.texture = texture;
12023
+ if (this.config.flipY) {
12024
+ dataToWrite = flipY(dataToWrite, width, height, byteLength);
12025
+ }
12026
+ return dataToWrite;
12027
+ }
12028
+ isArrayData(data) {
12029
+ if (!data.mipmap && !isArray(data)) {
12030
+ return false;
12031
+ }
12032
+ if (data.mipmap) {
12033
+ return isArray(data.mipmap[0]);
12034
+ }
12035
+ return true;
11910
12036
  }
11911
12037
  getView(descriptor) {
11912
12038
  return this.texture.createView(descriptor);
11913
12039
  }
11914
- addBindGroup(bindGroup) {
11915
- this._bindGroups.push(bindGroup);
11916
- }
11917
12040
  destroy() {
11918
12041
  if (this.texture) {
11919
12042
  this.texture.destroy();
11920
12043
  delete this.texture;
11921
12044
  }
11922
- delete this._bindGroups;
11923
12045
  }
11924
12046
  }
12047
+ /**
12048
+ * 对Uint8Array图像数据进行垂直翻转
12049
+ * @param imageData - 原始图像数据
12050
+ * @param width - 图像宽度(像素)
12051
+ * @param height - 图像高度(像素)
12052
+ * @param bytesPerPixel - 每像素字节数(通常为3-RGB或4-RGBA)
12053
+ * @returns {Uint8Array} - 垂直翻转后的图像数据
12054
+ */
12055
+ function flipY(imageData, width, height, byteLength) {
12056
+ if (flipYBuffer.byteLength < arrayBuffer.byteLength) {
12057
+ flipYBuffer.resize(arrayBuffer.byteLength);
12058
+ }
12059
+ const bytesPerPixel = imageData instanceof Float32Array ? 4 * 4 : 4;
12060
+ // 创建相同大小的新数组
12061
+ let flippedData;
12062
+ if (imageData instanceof Float32Array) {
12063
+ flippedData = new Float32Array(flipYBuffer, 0, byteLength / 4);
12064
+ }
12065
+ else {
12066
+ flippedData = new Uint8Array(flipYBuffer, 0, byteLength);
12067
+ }
12068
+ // 每行的字节数
12069
+ const rowBytes = width * bytesPerPixel;
12070
+ // 遍历每一行
12071
+ for (let y = 0; y < height; y++) {
12072
+ // 原始数据的行起始位置
12073
+ const originalRowStart = y * rowBytes;
12074
+ // 翻转后数据的行起始位置(从底部开始)
12075
+ const flippedRowStart = (height - 1 - y) * rowBytes;
12076
+ // 复制整行数据
12077
+ flippedData.set(imageData.subarray(originalRowStart, originalRowStart + rowBytes), flippedRowStart);
12078
+ }
12079
+ return flippedData;
12080
+ }
11925
12081
 
11926
12082
  class GraphicsFramebuffer {
11927
12083
  constructor(device, options) {
@@ -11957,6 +12113,22 @@ class GraphicsFramebuffer {
11957
12113
  }
11958
12114
  }
11959
12115
  }
12116
+ getCommandKey() {
12117
+ if (this._cmdKey) {
12118
+ return this._cmdKey;
12119
+ }
12120
+ const colorTexture = this.colorTexture;
12121
+ const depthTexture = this.depthTexture;
12122
+ let key = '';
12123
+ if (colorTexture) {
12124
+ key += `${colorTexture.gpuFormat.format}-${colorTexture.config.sampleCount};`;
12125
+ }
12126
+ if (depthTexture) {
12127
+ key += `${depthTexture.gpuFormat.format};`;
12128
+ }
12129
+ this._cmdKey = key;
12130
+ return key;
12131
+ }
11960
12132
  _update() {
11961
12133
  let color = this.options.colors && this.options.colors[0] || this.options.color;
11962
12134
  const colorFormat = this.options.colorFormat;
@@ -12077,7 +12249,7 @@ class GraphicsFramebuffer {
12077
12249
  depthStencilAttachment.depthLoadOp = this.depthLoadOp || 'load';
12078
12250
  depthStencilAttachment.depthClearValue = this.depthClearValue || 1;
12079
12251
  const depthTexture = this.depthTexture;
12080
- if (depthTexture.gpuFormat.isDepthStencil) {
12252
+ if (depthTexture && depthTexture.gpuFormat.isDepthStencil) {
12081
12253
  depthStencilAttachment.stencilLoadOp = this.stencilLoadOp || 'load';
12082
12254
  depthStencilAttachment.stencilClearValue = this.stencilClearValue || 0;
12083
12255
  }
@@ -12087,7 +12259,7 @@ class GraphicsFramebuffer {
12087
12259
  depthStencilAttachment.view = depthTexture.getView();
12088
12260
  }
12089
12261
  }
12090
- this._resetClearOptions();
12262
+ this.resetClearOptions();
12091
12263
  return this._renderPass;
12092
12264
  }
12093
12265
  setClearOptions(options) {
@@ -12104,7 +12276,7 @@ class GraphicsFramebuffer {
12104
12276
  this.stencilClearValue = options.stencil;
12105
12277
  }
12106
12278
  }
12107
- _resetClearOptions() {
12279
+ resetClearOptions() {
12108
12280
  this.colorLoadOp = null;
12109
12281
  this.colorClearValue = null;
12110
12282
  this.depthLoadOp = null;
@@ -12122,6 +12294,10 @@ class GraphicsFramebuffer {
12122
12294
  delete this.depthTexture;
12123
12295
  delete this._ownDepthTexture;
12124
12296
  }
12297
+ this._destroyed = true;
12298
+ }
12299
+ isDestroyed() {
12300
+ return !!this._destroyed;
12125
12301
  }
12126
12302
  }
12127
12303
 
@@ -12183,13 +12359,11 @@ class BindGroupFormat {
12183
12359
  label,
12184
12360
  entries: []
12185
12361
  }),
12186
- outdated: false,
12187
12362
  uniformTextures: {}
12188
12363
  };
12189
12364
  }
12190
12365
  const groups = this.groups[0];
12191
12366
  const entries = [];
12192
- const textures = [];
12193
12367
  for (let i = 0; i < groups.length; i++) {
12194
12368
  const group = groups[i];
12195
12369
  if (!group) {
@@ -12234,13 +12408,17 @@ class BindGroupFormat {
12234
12408
  if (!graphicsTexture) {
12235
12409
  continue;
12236
12410
  }
12237
- textures.push(graphicsTexture);
12238
12411
  let descriptor;
12239
12412
  if (graphicsTexture.gpuFormat.isDepthStencil) {
12240
12413
  descriptor = {
12241
12414
  aspect: 'depth-only'
12242
12415
  };
12243
12416
  }
12417
+ else if (group.type.name === 'texture_cube') {
12418
+ descriptor = {
12419
+ dimension: 'cube'
12420
+ };
12421
+ }
12244
12422
  entries.push({
12245
12423
  binding: group.binding,
12246
12424
  resource: graphicsTexture.getView(descriptor)
@@ -12264,10 +12442,7 @@ class BindGroupFormat {
12264
12442
  label,
12265
12443
  entries
12266
12444
  });
12267
- for (let i = 0; i < textures.length; i++) {
12268
- textures[i].addBindGroup(bindGroup);
12269
- }
12270
- return { bindGroup, outdated: false, uniformTextures: {} };
12445
+ return { bindGroup, uniformTextures: {} };
12271
12446
  }
12272
12447
  copyTextures(bindGroup, props) {
12273
12448
  for (const p in props) {
@@ -12282,7 +12457,7 @@ class BindGroupFormat {
12282
12457
  continue;
12283
12458
  }
12284
12459
  if (isTextureLike(v)) {
12285
- bindGroup.uniformTextures[p] = v;
12460
+ bindGroup.uniformTextures[p] = { texture: v, version: v.version };
12286
12461
  }
12287
12462
  }
12288
12463
  }
@@ -12367,7 +12542,7 @@ function ParseDefines(strings, values) {
12367
12542
  // let depth = 1;
12368
12543
  const assertTemplateFollows = (match, string) => {
12369
12544
  if (match.index + match[0].length != string.length) {
12370
- throw new Error(`#${match[1]} must be immediately followed by a template expression (ie: \${value})`);
12545
+ throw new Error(`#${match[1]} must be immediately followed by a template expression (${string})`);
12371
12546
  }
12372
12547
  };
12373
12548
  for (let i = 0; i < strings.length; ++i) {
@@ -12697,13 +12872,17 @@ class CommandBuilder {
12697
12872
  if (format && format.startsWith('depth')) {
12698
12873
  sampleType = 'depth';
12699
12874
  }
12875
+ const texture = {
12876
+ multisampled,
12877
+ sampleType
12878
+ };
12879
+ if (groupInfo.type && groupInfo.type.name === 'texture_cube') {
12880
+ texture.viewDimension = 'cube';
12881
+ }
12700
12882
  return {
12701
12883
  binding,
12702
12884
  visibility,
12703
- texture: {
12704
- multisampled,
12705
- sampleType
12706
- }
12885
+ texture
12707
12886
  };
12708
12887
  }
12709
12888
  else {
@@ -12872,7 +13051,8 @@ class CommandBuilder {
12872
13051
  },
12873
13052
  primitive: {
12874
13053
  topology: pipelineDesc.topology,
12875
- cullMode: pipelineDesc.cullMode
13054
+ cullMode: pipelineDesc.cullMode,
13055
+ frontFace: pipelineDesc.frontFace
12876
13056
  }
12877
13057
  };
12878
13058
  const sampleCount = fbo && fbo.colorTexture && fbo.colorTexture.config.sampleCount;
@@ -13351,17 +13531,21 @@ const pipelineDesc = new PipelineDescriptor();
13351
13531
  class GPUShader extends GLShader {
13352
13532
  getShaderCommandKey(device, mesh, renderProps) {
13353
13533
  if (device && device.wgpu) {
13534
+ let fboKey = '';
13535
+ if (this._gpuFramebuffer) {
13536
+ fboKey = `-${this._gpuFramebuffer.getCommandKey()}`;
13537
+ }
13354
13538
  // 获取pipeline所需要的特征变量,即任何变量发生变化后,就需要创建新的pipeline
13355
13539
  const fnValues = mesh.getShaderFnValues(this.uid);
13356
13540
  if (fnValues) {
13357
13541
  const { funcs, key, commandKey } = fnValues;
13358
13542
  if (!funcs.length) {
13359
- return commandKey;
13543
+ return commandKey + fboKey;
13360
13544
  }
13361
13545
  const values = funcs.map(func => func(null, renderProps));
13362
13546
  const currentKey = pipelineDesc.generateValuesKey(values);
13363
13547
  if (currentKey === key) {
13364
- return commandKey;
13548
+ return commandKey + fboKey;
13365
13549
  }
13366
13550
  }
13367
13551
  const fbo = this._gpuFramebuffer;
@@ -13373,7 +13557,7 @@ class GPUShader extends GLShader {
13373
13557
  key: pipelineDesc.getFnValuesKey(),
13374
13558
  commandKey
13375
13559
  });
13376
- return commandKey;
13560
+ return commandKey + fboKey;
13377
13561
  }
13378
13562
  else {
13379
13563
  // regl
@@ -13407,6 +13591,9 @@ class GPUShader extends GLShader {
13407
13591
  }
13408
13592
  }
13409
13593
  _compileWGSLSource(defines) {
13594
+ if (!this.wgslVert) {
13595
+ throw new Error(`(${this.name}) WGSL vertex shader source is not provided.`);
13596
+ }
13410
13597
  const vert = WgslShaderLib.compile(this.wgslVert, defines);
13411
13598
  let frag;
13412
13599
  if (this.wgslFrag) {
@@ -13426,8 +13613,8 @@ class GPUShader extends GLShader {
13426
13613
  const device = deviceOrRegl;
13427
13614
  this.isGPU = true;
13428
13615
  const buffersPool = device.dynamicBufferPool;
13429
- const passEncoder = this._getCurrentRenderPassEncoder(device);
13430
- passEncoder.setPipeline(command.pipeline);
13616
+ const renderPass = this._getCurrentRenderPassEncoder(device);
13617
+ renderPass.setPipeline(command.pipeline);
13431
13618
  const { uid, bindGroupFormat, vertexInfo, layout } = command;
13432
13619
  // 1. 生成shader uniform 需要的dynamic buffer
13433
13620
  if (!this._buffers) {
@@ -13447,6 +13634,7 @@ class GPUShader extends GLShader {
13447
13634
  // 向buffer中填入shader uniform值
13448
13635
  shaderBuffer.writeBuffer(props[0], this._shaderDynamicOffsets);
13449
13636
  const shaderDynamicOffsets = this._shaderDynamicOffsets.getItems();
13637
+ const stencil = this.extraCommandProps['stencil'];
13450
13638
  for (let i = 0; i < props.length; i++) {
13451
13639
  this._dynamicOffsets.reset();
13452
13640
  const mesh = props[i].meshObject;
@@ -13456,10 +13644,10 @@ class GPUShader extends GLShader {
13456
13644
  + mesh.textureVersion + '-' + (mesh.material && mesh.material.textureVersion || 0);
13457
13645
  // 获取或者生成bind group
13458
13646
  let bindGroup = mesh.getBindGroup(groupKey);
13459
- if (bindGroup && !this._checkBindGroupTextures(bindGroup, props[i])) {
13460
- bindGroup.outdated = true;
13647
+ if (bindGroup && this._checkBindGroupOutdated(bindGroup, props[i])) {
13648
+ bindGroup = null;
13461
13649
  }
13462
- if (!bindGroup || bindGroup.outdated) {
13650
+ if (!bindGroup) {
13463
13651
  bindGroup = bindGroupFormat.createFormatBindGroup(device, mesh, props[i], layout, shaderBuffer, meshBuffer);
13464
13652
  bindGroupFormat.copyTextures(bindGroup, props[i]);
13465
13653
  // 缓存bind group,只要buffer和texture没有发生变化,即可以重用
@@ -13468,7 +13656,7 @@ class GPUShader extends GLShader {
13468
13656
  // 获取 dynamicOffsets
13469
13657
  this._dynamicOffsets.addItems(shaderDynamicOffsets);
13470
13658
  const dynamicOffsets = this._dynamicOffsets.getDynamicOffsets();
13471
- passEncoder.setBindGroup(0, bindGroup.bindGroup, dynamicOffsets);
13659
+ renderPass.setBindGroup(0, bindGroup.bindGroup, dynamicOffsets);
13472
13660
  let instancedMesh;
13473
13661
  if (mesh instanceof InstancedMesh) {
13474
13662
  instancedMesh = mesh;
@@ -13479,7 +13667,18 @@ class GPUShader extends GLShader {
13479
13667
  if (!vertexBuffer && instancedMesh) {
13480
13668
  vertexBuffer = instancedMesh.getInstancedBuffer(name);
13481
13669
  }
13482
- passEncoder.setVertexBuffer(vertex.location, vertexBuffer, 0, vertexBuffer.byteLength);
13670
+ renderPass.setVertexBuffer(vertex.location, vertexBuffer, 0, vertexBuffer.byteLength);
13671
+ }
13672
+ if (stencil && isEnable(stencil.enable, props[i])) {
13673
+ let ref = stencil.func && stencil.func.ref;
13674
+ if (ref !== undefined) {
13675
+ if (isFunction$1(ref)) {
13676
+ ref = ref(null, props[i]);
13677
+ }
13678
+ if (ref >= 0) {
13679
+ renderPass.setStencilReference(ref);
13680
+ }
13681
+ }
13483
13682
  }
13484
13683
  const elements = mesh.getElements();
13485
13684
  const drawOffset = mesh.geometry.getDrawOffset();
@@ -13489,27 +13688,28 @@ class GPUShader extends GLShader {
13489
13688
  instanceCount = instancedMesh.instanceCount;
13490
13689
  }
13491
13690
  if (mesh.geometry.isIndexedElements()) {
13492
- passEncoder.setIndexBuffer(elements, elements.itemType);
13493
- passEncoder.drawIndexed(drawCount, instanceCount, drawOffset);
13691
+ renderPass.setIndexBuffer(elements, elements.itemType);
13692
+ renderPass.drawIndexed(drawCount, instanceCount, drawOffset);
13494
13693
  }
13495
13694
  else {
13496
- passEncoder.draw(drawCount, instanceCount, drawOffset);
13695
+ renderPass.draw(drawCount, instanceCount, drawOffset);
13497
13696
  }
13498
13697
  device.incrDrawCall();
13499
13698
  }
13500
- passEncoder.end();
13699
+ renderPass.end();
13501
13700
  }
13502
- _checkBindGroupTextures(bindGroup, props) {
13701
+ _checkBindGroupOutdated(bindGroup, props) {
13503
13702
  if (!bindGroup.uniformTextures) {
13504
- return true;
13703
+ return false;
13505
13704
  }
13705
+ // 当纹理的version不同,或纹理不同时,则认为bindGroup过期,需要重新创建
13506
13706
  const uniformTextures = bindGroup.uniformTextures;
13507
13707
  for (const p in uniformTextures) {
13508
- if (uniformTextures[p] !== props[p]) {
13509
- return false;
13708
+ if (uniformTextures[p].texture !== props[p] || uniformTextures[p].version !== props[p].version) {
13709
+ return true;
13510
13710
  }
13511
13711
  }
13512
- return true;
13712
+ return false;
13513
13713
  }
13514
13714
  _getCurrentRenderPassEncoder(device) {
13515
13715
  // stencilLoadOp?: GPULoadOp,
@@ -13687,7 +13887,7 @@ class MeshShader extends GPUShader {
13687
13887
  }
13688
13888
  const meshKey = mesh.getCommandKey(device);
13689
13889
  if (!storedKeys[meshKey]) {
13690
- storedKeys[meshKey] = key + '_' + mesh.getCommandKey();
13890
+ storedKeys[meshKey] = key + '_' + meshKey;
13691
13891
  }
13692
13892
  const dKey = storedKeys[meshKey];
13693
13893
  // const key = this.dkey || '';
@@ -13751,9 +13951,9 @@ var phongFrag = "precision mediump float;\n#include <gl2_frag>\nuniform vec4 bas
13751
13951
 
13752
13952
  var phongVert = "#include <gl2_vert>\nattribute vec3 aPosition;\n#include <line_extrusion_vert>\n#ifdef HAS_MAP\nuniform vec2 uvScale;\nuniform vec2 uvOffset;\nattribute vec2 aTexCoord;\nvarying vec2 vTexCoord;\n#ifdef HAS_I3S_UVREGION\nattribute vec4 uvRegion;\nvarying vec4 vUvRegion;\n#endif\n#if defined(HAS_AO_MAP)\nattribute vec2 aTexCoord1;\nvarying vec2 vTexCoord1;\n#endif\n#endif\n#if defined(HAS_COLOR)\nattribute vec4 aColor;\nvarying vec4 vColor;\n#elif defined(HAS_COLOR0)\n#if COLOR0_SIZE == 3\nattribute vec3 aColor0;\n#else\nattribute vec4 aColor0;\n#endif\nvarying vec4 vColor;\n#endif\nvarying vec3 vFragPos;\nvarying vec3 vNormal;\nuniform mat4 projMatrix;\nuniform mat3 modelNormalMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 positionMatrix;\nuniform vec2 halton;\nuniform vec2 outSize;\nuniform mat4 projViewMatrix;\n#include <highlight_vert>\n#include <get_output>\n#include <heatmap_render_vert>\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_vert>\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\nattribute float aExtrusionOpacity;\nvarying float vExtrusionOpacity;\n#endif\n#if defined(HAS_TANGENT)\nvarying vec4 vTangent;\n#endif\nvoid c(const highp vec4 q, out highp vec3 d) {\n d = vec3(.0, .0, 1.) + vec3(2., -2., -2.) * q.x * q.zwx + vec3(2., 2., -2.) * q.y * q.wzy;\n}\nvoid c(const highp vec4 q, out highp vec3 d, out highp vec3 t) {\n c(q, d);\n t = vec3(1., .0, .0) + vec3(-2., 2., -2.) * q.y * q.yxw + vec3(-2., 2., 2.) * q.z * q.zwx;\n}\n#include <vertex_color_vert>\nvoid main() {\n \n#ifdef IS_LINE_EXTRUSION\nvec4 e = getPosition(getLineExtrudePosition(aPosition));\n#else\nvec4 e = getPosition(aPosition);\n#endif\nmat4 f = getPositionMatrix();\n vFragPos = vec3(modelMatrix * f * e);\n#if defined(HAS_NORMAL) || defined(HAS_TANGENT)\nmat3 h = modelNormalMatrix * mat3(f);\n vec3 i;\n#if defined(HAS_TANGENT)\nvec3 t;\n c(aTangent, i, t);\n vTangent = vec4(h * t, aTangent.w);\n#else\ni = decode_getNormal(aNormal);\n#endif\nvec3 j = appendMorphNormal(i);\n vNormal = normalize(h * j);\n#else\nvNormal = vec3(.0);\n#endif\nmat4 k = projMatrix;\n k[2].xy += halton.xy / outSize.xy;\n#ifdef HAS_MASK_EXTENT\ngl_Position = k * getMaskPosition(f * e, modelMatrix);\n#else\ngl_Position = k * modelViewMatrix * f * e;\n#endif\n#ifdef HAS_MAP\nvec2 l = decode_getTexcoord(aTexCoord);\n vTexCoord = l * uvScale + uvOffset;\n#endif\n#ifdef HAS_AO_MAP\nvec2 m = decode_getTexcoord(aTexCoord1);\n vTexCoord1 = m * uvScale + uvOffset;\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\nvExtrusionOpacity = aExtrusionOpacity;\n#endif\n#if defined(HAS_COLOR)\nvColor = aColor / 255.;\n#elif defined(HAS_COLOR0)\n#if COLOR0_SIZE == 3\nvColor = vec4(aColor0 / 255., 1.);\n#else\nvColor = aColor0 / 255.;\n#endif\n#endif\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nshadow_computeShadowPars(f * e);\n#endif\n#ifdef HAS_HEATMAP\nheatmap_compute(projMatrix * modelViewMatrix * f, e);\n#endif\n#ifdef HAS_I3S_UVREGION\nvUvRegion = uvRegion / 65535.;\n#endif\nhighlight_setVarying();\n#ifdef HAS_VERTEX_COLOR\nvertexColor_update();\n#endif\n}";
13753
13953
 
13754
- var wgslVert$4 = "struct VertexInput {\n#if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n#else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n#endif\n#ifdef HAS_MAP\n #if HAS_DRACO_TEXCOORD || HAS_COMPRESSED_INT16_TEXCOORD_0\n @location($i) aTexCoord: vec2i,\n #else\n @location($i) aTexCoord: vec2f,\n #endif\n#ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR\n @location($i) aColor: vec4f,\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n @location($i) aColor0: vec3f,\n#else\n @location($i) aColor0: vec4f,\n#endif\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n @location($i) aExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($i) aTangent: vec4f,\n#endif\n#ifdef HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #else\n @location($i) aNormal: vec3f,\n #endif\n#endif\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vFragPos: vec3f,\n @location($o) vNormal: vec3f,\n#ifdef HAS_MAP\n @location($o) vTexCoord: vec2f,\n#ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR || HAS_COLOR0\n @location($o) vColor: vec4f,\n#endif\n#if HAS_EXTRUSION_OPACITY\n @location($o) vExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($o) vTangent: vec4f,\n#endif\n};\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n projViewMatrix: mat4x4f,\n};\nstruct ModelUniforms {\n modelNormalMatrix: mat3x3f,\n modelViewMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct UvUniforms {\n uvScale: vec2f,\n uvOffset: vec2f,\n};\nstruct JitterUniforms {\n halton: vec2f,\n outSize: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> modelUniforms: ModelUniforms;\n@group(0) @binding($b) var<uniform> uvUniforms: UvUniforms;\n@group(0) @binding($b) var<uniform> jitterUniforms: JitterUniforms;\n#include <line_extrusion_vert>\n#include <highlight_vert>\n#include <get_output>\n#if HAS_SHADOWING && !HAS_BLOOM\n#include <vsm_shadow_vert>\n#endif\n#include <vertex_color_vert>\nfn toTangentFrame1(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nfn toTangentFrame(q: vec4f, n: ptr<function, vec3f>, t: ptr<function, vec3f>) {\n *n = toTangentFrame1(q);\n *t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput : VertexOutput;\n#if IS_LINE_EXTRUSION\n let localPosition = getPosition(getLineExtrudePosition(vec3f(vertexInput.aPosition.xyz), vertexInput), vertexInput);\n#else\n let localPosition = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n#endif\n let localPositionMatrix = getPositionMatrix(vertexInput, &vertexOutput, modelUniforms.positionMatrix);\n vertexOutput.vFragPos = (modelUniforms.modelMatrix * localPositionMatrix * localPosition).xyz;\n#if HAS_NORMAL || HAS_TANGENT\n let localNormalMatrix = modelUniforms.modelNormalMatrix * mat3x3f(localPositionMatrix[0].xyz, localPositionMatrix[1].xyz, localPositionMatrix[2].xyz);\n var Normal: vec3f;\n#if HAS_TANGENT\n var t: vec3f;\n toTangentFrame(vertexInput.aTangent, Normal, t);\n vertexOutput.vTangent = vec4f(localNormalMatrix * t, vertexInput.aTangent.w);\n#else\n Normal = decode_getNormal(vec3f(vertexInput.aNormal.xyz));\n#endif\n let localNormal = appendMorphNormal(Normal, vertexInput);\n vertexOutput.vNormal = normalize(localNormalMatrix * localNormal);\n#else\n vertexOutput.vNormal = vec3f(0.0);\n#endif\n var jitteredProjection = uniforms.projMatrix;\n#ifdef HAS_MASK_EXTENT\n vertexOutput.position = jitteredProjection * getMaskPosition(localPositionMatrix * localPosition, uniforms.modelMatrix);\n#else\n vertexOutput.position = jitteredProjection * modelUniforms.modelViewMatrix * localPositionMatrix * localPosition;\n#endif\n#ifdef HAS_MAP\n let decodedTexCoord = decode_getTexcoord(vec2f(vertexInput.aTexCoord));\n vertexOutput.vTexCoord = decodedTexCoord * uvUniforms.uvScale + uvUniforms.uvOffset;\n#endif\n#ifdef HAS_AO_MAP\n let decodedTexCoord1 = decode_getTexcoord(vec2f(vertexInput.aTexCoord1));\n vertexOutput.vTexCoord1 = decodedTexCoord1 * uvUniforms.uvScale + uvUniforms.uvOffset;\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n vertexOutput.vExtrusionOpacity = vertexInput.aExtrusionOpacity;\n#endif\n#if HAS_COLOR\n vertexOutput.vColor = vertexInput.aColor / 255.0;\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n vertexOutput.vColor = vec4f(vertexInput.aColor0 / 255.0, 1.0);\n#else\n vertexOutput.vColor = vertexInput.aColor0 / 255.0;\n#endif\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(localPositionMatrix * localPosition, &vertexOutput);\n#endif\n#ifdef HAS_I3S_UVREGION\n vertexOutput.vUvRegion = vertexInput.uvRegion / 65535.0;\n#endif\n#if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(vertexInput, &vertexOutput);\n#endif\n#ifdef HAS_VERTEX_COLOR\n vertexColor_update(vertexInput, &vertexOutput);\n#endif\n return vertexOutput;\n}";
13954
+ var wgslVert$5 = "struct VertexInput {\n#if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n#else\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n#endif\n#ifdef HAS_MAP\n #if HAS_DRACO_TEXCOORD || HAS_COMPRESSED_INT16_TEXCOORD_0\n @location($i) aTexCoord: vec2i,\n #else\n @location($i) aTexCoord: vec2f,\n #endif\n#ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR\n @location($i) aColor: vec4f,\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n @location($i) aColor0: vec3f,\n#else\n @location($i) aColor0: vec4f,\n#endif\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n @location($i) aExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($i) aTangent: vec4f,\n#endif\n#ifdef HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #else\n @location($i) aNormal: vec3f,\n #endif\n#endif\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vFragPos: vec3f,\n @location($o) vNormal: vec3f,\n#ifdef HAS_MAP\n @location($o) vTexCoord: vec2f,\n#ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n#endif\n#ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n#endif\n#endif\n#ifdef HAS_COLOR || HAS_COLOR0\n @location($o) vColor: vec4f,\n#endif\n#if HAS_EXTRUSION_OPACITY\n @location($o) vExtrusionOpacity: f32,\n#endif\n#ifdef HAS_TANGENT\n @location($o) vTangent: vec4f,\n#endif\n};\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n projViewMatrix: mat4x4f,\n};\nstruct ModelUniforms {\n modelNormalMatrix: mat3x3f,\n modelViewMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n uvScale: vec2f,\n uvOffset: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> modelUniforms: ModelUniforms;\n#include <line_extrusion_vert>\n#include <highlight_vert>\n#include <get_output>\n#if HAS_SHADOWING && !HAS_BLOOM\n#include <vsm_shadow_vert>\n#endif\n#include <vertex_color_vert>\nfn toTangentFrame1(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nfn toTangentFrame(q: vec4f, n: ptr<function, vec3f>, t: ptr<function, vec3f>) {\n *n = toTangentFrame1(q);\n *t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput : VertexOutput;\n#if IS_LINE_EXTRUSION\n let localPosition = getPosition(getLineExtrudePosition(vec3f(vertexInput.aPosition.xyz), vertexInput), vertexInput);\n#else\n let localPosition = getPosition(vec3f(vertexInput.aPosition.xyz), vertexInput);\n#endif\n let localPositionMatrix = getPositionMatrix(vertexInput, &vertexOutput, modelUniforms.positionMatrix);\n vertexOutput.vFragPos = (modelUniforms.modelMatrix * localPositionMatrix * localPosition).xyz;\n#if HAS_NORMAL || HAS_TANGENT\n let localNormalMatrix = modelUniforms.modelNormalMatrix * mat3x3f(localPositionMatrix[0].xyz, localPositionMatrix[1].xyz, localPositionMatrix[2].xyz);\n var Normal: vec3f;\n#if HAS_TANGENT\n var t: vec3f;\n toTangentFrame(vertexInput.aTangent, Normal, t);\n vertexOutput.vTangent = vec4f(localNormalMatrix * t, vertexInput.aTangent.w);\n#else\n Normal = decode_getNormal(vec3f(vertexInput.aNormal.xyz));\n#endif\n let localNormal = appendMorphNormal(Normal, vertexInput);\n vertexOutput.vNormal = normalize(localNormalMatrix * localNormal);\n#else\n vertexOutput.vNormal = vec3f(0.0);\n#endif\n var jitteredProjection = uniforms.projMatrix;\n#ifdef HAS_MASK_EXTENT\n vertexOutput.position = jitteredProjection * getMaskPosition(localPositionMatrix * localPosition, uniforms.modelMatrix);\n#else\n vertexOutput.position = jitteredProjection * modelUniforms.modelViewMatrix * localPositionMatrix * localPosition;\n#endif\n#ifdef HAS_MAP\n let decodedTexCoord = decode_getTexcoord(vec2f(vertexInput.aTexCoord));\n vertexOutput.vTexCoord = decodedTexCoord * modelUniforms.uvScale + modelUniforms.uvOffset;\n#endif\n#ifdef HAS_AO_MAP\n let decodedTexCoord1 = decode_getTexcoord(vec2f(vertexInput.aTexCoord1));\n vertexOutput.vTexCoord1 = decodedTexCoord1 * modelUniforms.uvScale + modelUniforms.uvOffset;\n#endif\n#ifdef HAS_EXTRUSION_OPACITY\n vertexOutput.vExtrusionOpacity = vertexInput.aExtrusionOpacity;\n#endif\n#if HAS_COLOR\n vertexOutput.vColor = vertexInput.aColor / 255.0;\n#elif HAS_COLOR0\n#if COLOR0_SIZE == 3\n vertexOutput.vColor = vec4f(vertexInput.aColor0 / 255.0, 1.0);\n#else\n vertexOutput.vColor = vertexInput.aColor0 / 255.0;\n#endif\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(localPositionMatrix * localPosition, &vertexOutput);\n#endif\n#ifdef HAS_I3S_UVREGION\n vertexOutput.vUvRegion = vertexInput.uvRegion / 65535.0;\n#endif\n#if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(vertexInput, &vertexOutput);\n#endif\n#ifdef HAS_VERTEX_COLOR\n vertexColor_update(vertexInput, &vertexOutput);\n#endif\n return vertexOutput;\n}";
13755
13955
 
13756
- var wgslFrag$7 = "struct LightUniforms {\n light0_viewDirection: vec3f,\n ambientColor: vec3f,\n light0_diffuse: vec4f,\n lightSpecular: vec3f,\n cameraPosition: vec3f,\n #ifdef HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n};\nstruct MaterialUniforms {\n environmentExposure: f32,\n specularStrength: f32,\n baseColorFactor: vec4f,\n materialShininess: f32,\n alphaTest: f32,\n#ifdef HAS_EXTRUSION_OPACITY\n extrusionOpacityRange: vec2f,\n#endif\n#ifdef SHADING_MODEL_SPECULAR_GLOSSINESS\n diffuseFactor: vec4f,\n specularFactor: vec3f,\n#endif\n#ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n lineOpacity: f32,\n#else\n polygonFill: vec4f,\n polygonOpacity: f32,\n#endif\n};\n@group(0) @binding($b) var<uniform> lightUniforms: LightUniforms;\n@group(0) @binding($b) var<uniform> materialUniforms: MaterialUniforms;\n#ifdef HAS_BASECOLOR_MAP\n@group(0) @binding($b) var baseColorTextureSampler: sampler;\n@group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_AO_MAP\n@group(0) @binding($b) var occlusionTextureSampler: sampler;\n@group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_NORMAL_MAP\n@group(0) @binding($b) var normalTextureSampler: sampler;\n@group(0) @binding($b) var normalTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_EMISSIVE_MAP\n@group(0) @binding($b) var emissiveTextureSampler: sampler;\n@group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n#endif\n#ifdef SHADING_MODEL_SPECULAR_GLOSSINESS\n#ifdef HAS_DIFFUSE_MAP\n@group(0) @binding($b) var diffuseTextureSampler: sampler;\n@group(0) @binding($b0) var diffuseTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_SPECULARGLOSSINESS_MAP\n@group(0) @binding($b1) var specularGlossinessTextureSampler: sampler;\n@group(0) @binding($b2) var specularGlossinessTexture: texture_2d<f32>;\n#endif\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n#include <vsm_shadow_frag>\n#endif\n#include <highlight_frag>\n#include <mask_frag>\n#include <vertex_color_frag>\n#ifdef HAS_MAP\n #include <compute_texcoord_frag>\n#endif\nfn transformNormal(vertexOutput: VertexOutput) -> vec3f {\n#ifdef HAS_NORMAL_MAP\n let n = normalize(vertexOutput.vNormal);\n let normal = textureSample(normalTexture, normalTextureSampler, computeTexCoord(vertexOutput)).xyz * 2.0 - 1.0;\n#ifdef HAS_TANGENT\n let t = normalize(vertexOutput.vTangent.xyz);\n let b = normalize(cross(n, t) * sign(vertexOutput.vTangent.w));\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n#else\n return normalize(normal);\n#endif\n#else\n return normalize(vertexOutput.vNormal);\n#endif\n}\nfn getBaseColor(vertexOutput: VertexOutput) -> vec4f {\n#ifdef HAS_BASECOLOR_MAP\n return textureSample(baseColorTexture, baseColorTextureSampler, computeTexCoord(vertexOutput));\n#elif HAS_DIFFUSE_MAP\n return textureSample(diffuseTexture, diffuseTextureSampler, computeTexCoord(vertexOutput));\n#elif SHADING_MODEL_SPECULAR_GLOSSINESS\n return materialUniforms.diffuseFactor;\n#else\n return materialUniforms.baseColorFactor;\n#endif\n}\nfn getSpecularColor(vertexOutput: VertexOutput) -> vec3f {\n#ifdef HAS_SPECULARGLOSSINESS_MAP\n return textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, computeTexCoord(vertexOutput)).rgb;\n#elif SHADING_MODEL_SPECULAR_GLOSSINESS\n return materialUniforms.specularFactor;\n#else\n return vec3f(1.0);\n#endif\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let baseColor = getBaseColor(vertexOutput);\n#ifdef SHADING_MODEL_UNLIT\n let ambientColor = vec3f(1.0);\n#else\n let ambientColor = lightUniforms.ambientColor;\n#endif\n var ambient = materialUniforms.environmentExposure * ambientColor * baseColor.rgb;\n#ifdef HAS_INSTANCE_COLOR\n ambient *= vertexOutput.vInstanceColor.rgb;\n#endif\n let norm = transformNormal(vertexOutput);\n let lightDir = normalize(-lightUniforms.light0_viewDirection);\n var diff = max(dot(norm, lightDir), 0.0);\n#ifdef SHADING_MODEL_UNLIT\n let lightDiffuse = vec3f(0.0);\n#else\n let lightDiffuse = lightUniforms.light0_diffuse.rgb;\n#endif\n var diffuse = lightDiffuse * diff * baseColor.rgb;\n#if HAS_COLOR || HAS_COLOR0\n var color = vertexOutput.vColor.rgb;\n#elif IS_LINE_EXTRUSION\n var color = materialUniforms.lineColor.rgb;\n#else\n var color = materialUniforms.polygonFill.rgb;\n#endif\n#ifdef HAS_INSTANCE_COLOR\n color *= vertexOutput.vInstanceColor.rgb;\n#endif\n ambient *= color.rgb;\n diffuse *= color.rgb;\n let viewDir = normalize(lightUniforms.cameraPosition - vertexOutput.vFragPos);\n let halfwayDir = normalize(lightDir + viewDir);\n var spec = pow(max(dot(norm, halfwayDir), 0.0), materialUniforms.materialShininess);\n#ifdef SHADING_MODEL_UNLIT\n let lightSpecular = vec3f(0.0);\n#else\n let lightSpecular = lightUniforms.lightSpecular;\n#endif\n var specular = materialUniforms.specularStrength * lightSpecular * spec * getSpecularColor(vertexOutput);\n#ifdef HAS_OCCLUSION_MAP\n let ao = textureSample(occlusionTexture, occlusionTextureSampler, computeTexCoord(vertexOutput1)).r;\n ambient *= ao;\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n diffuse = shadow_blend(diffuse, shadowCoeff).rgb;\n specular = shadow_blend(specular, shadowCoeff).rgb;\n ambient = shadow_blend(ambient, shadowCoeff).rgb;\n#endif\n var result = ambient + diffuse + specular;\n#ifdef HAS_EMISSIVE_MAP\n let emit = textureSample(emissiveTexture, emissiveTextureSampler, computeTexCoord(vertexOutput)).rgb;\n result += emit;\n#endif\n#ifdef IS_LINE_EXTRUSION\n var fragColor = vec4f(result, materialUniforms.lineOpacity * baseColor.a);\n#else\n var fragColor = vec4f(result, materialUniforms.polygonOpacity * baseColor.a);\n#endif\n#if HAS_COLOR || HAS_COLOR0\n let colorAlpha = vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n let colorAlpha = materialUniforms.lineColor.a;\n#else\n let colorAlpha = materialUniforms.polygonFill.a;\n#endif\n fragColor *= colorAlpha;\n#ifdef HAS_EXTRUSION_OPACITY\n let topAlpha = materialUniforms.extrusionOpacityRange.x;\n let bottomAlpha = materialUniforms.extrusionOpacityRange.y;\n let alpha = topAlpha + vertexOutput.vExtrusionOpacity * (bottomAlpha - topAlpha);\n let alpha = clamp(alpha, 0.0, 1.0);\n fragColor *= alpha;\n#endif\n if (fragColor.a < materialUniforms.alphaTest) {\n discard;\n }\n#ifdef HAS_VERTEX_COLOR\n fragColor *= vertexColor_get();\n#endif\n#ifdef HAS_HEATMAP\n fragColor = heatmap_getColor(fragColor);\n#endif\n#if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n fragColor = highlight_blendColor(fragColor, vertexOutput);\n#endif\n#ifdef HAS_LAYER_OPACITY\n fragColor *= lightUniforms.layerOpacity;\n#endif\n#ifdef HAS_MASK_EXTENT\n fragColor = setMask(fragColor);\n#endif\n return fragColor;\n}";
13956
+ var wgslFrag$9 = "struct LightUniforms {\n light0_viewDirection: vec3f,\n ambientColor: vec3f,\n light0_diffuse: vec4f,\n lightSpecular: vec3f,\n cameraPosition: vec3f,\n #ifdef HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n};\nstruct MaterialUniforms {\n environmentExposure: f32,\n specularStrength: f32,\n baseColorFactor: vec4f,\n materialShininess: f32,\n alphaTest: f32,\n#ifdef HAS_EXTRUSION_OPACITY\n extrusionOpacityRange: vec2f,\n#endif\n#ifdef SHADING_MODEL_SPECULAR_GLOSSINESS\n diffuseFactor: vec4f,\n specularFactor: vec3f,\n#endif\n#ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n lineOpacity: f32,\n#else\n polygonFill: vec4f,\n polygonOpacity: f32,\n#endif\n};\n@group(0) @binding($b) var<uniform> lightUniforms: LightUniforms;\n@group(0) @binding($b) var<uniform> materialUniforms: MaterialUniforms;\n#ifdef HAS_BASECOLOR_MAP\n@group(0) @binding($b) var baseColorTextureSampler: sampler;\n@group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_AO_MAP\n@group(0) @binding($b) var occlusionTextureSampler: sampler;\n@group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_NORMAL_MAP\n@group(0) @binding($b) var normalTextureSampler: sampler;\n@group(0) @binding($b) var normalTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_EMISSIVE_MAP\n@group(0) @binding($b) var emissiveTextureSampler: sampler;\n@group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n#endif\n#ifdef SHADING_MODEL_SPECULAR_GLOSSINESS\n#ifdef HAS_DIFFUSE_MAP\n@group(0) @binding($b) var diffuseTextureSampler: sampler;\n@group(0) @binding($b0) var diffuseTexture: texture_2d<f32>;\n#endif\n#ifdef HAS_SPECULARGLOSSINESS_MAP\n@group(0) @binding($b1) var specularGlossinessTextureSampler: sampler;\n@group(0) @binding($b2) var specularGlossinessTexture: texture_2d<f32>;\n#endif\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n#include <vsm_shadow_frag>\n#endif\n#include <highlight_frag>\n#include <mask_frag>\n#include <vertex_color_frag>\n#ifdef HAS_MAP\n #include <compute_texcoord_frag>\n#endif\nfn transformNormal(vertexOutput: VertexOutput) -> vec3f {\n#ifdef HAS_NORMAL_MAP\n let n = normalize(vertexOutput.vNormal);\n let normal = textureSample(normalTexture, normalTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput)).xyz * 2.0 - 1.0;\n#ifdef HAS_TANGENT\n let t = normalize(vertexOutput.vTangent.xyz);\n let b = normalize(cross(n, t) * sign(vertexOutput.vTangent.w));\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n#else\n return normalize(normal);\n#endif\n#else\n return normalize(vertexOutput.vNormal);\n#endif\n}\nfn getBaseColor(vertexOutput: VertexOutput) -> vec4f {\n#ifdef HAS_BASECOLOR_MAP\n return textureSample(baseColorTexture, baseColorTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput));\n#elif HAS_DIFFUSE_MAP\n return textureSample(diffuseTexture, diffuseTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput));\n#elif SHADING_MODEL_SPECULAR_GLOSSINESS\n return materialUniforms.diffuseFactor;\n#else\n return materialUniforms.baseColorFactor;\n#endif\n}\nfn getSpecularColor(vertexOutput: VertexOutput) -> vec3f {\n#ifdef HAS_SPECULARGLOSSINESS_MAP\n return textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput)).rgb;\n#elif SHADING_MODEL_SPECULAR_GLOSSINESS\n return materialUniforms.specularFactor;\n#else\n return vec3f(1.0);\n#endif\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n let baseColor = getBaseColor(vertexOutput);\n#ifdef SHADING_MODEL_UNLIT\n let ambientColor = vec3f(1.0);\n#else\n let ambientColor = lightUniforms.ambientColor;\n#endif\n var ambient = materialUniforms.environmentExposure * ambientColor * baseColor.rgb;\n#ifdef HAS_INSTANCE_COLOR\n ambient *= vertexOutput.vInstanceColor.rgb;\n#endif\n let norm = transformNormal(vertexOutput);\n let lightDir = normalize(-lightUniforms.light0_viewDirection);\n var diff = max(dot(norm, lightDir), 0.0);\n#ifdef SHADING_MODEL_UNLIT\n let lightDiffuse = vec3f(0.0);\n#else\n let lightDiffuse = lightUniforms.light0_diffuse.rgb;\n#endif\n var diffuse = lightDiffuse * diff * baseColor.rgb;\n#if HAS_COLOR || HAS_COLOR0\n var color = vertexOutput.vColor.rgb;\n#elif IS_LINE_EXTRUSION\n var color = materialUniforms.lineColor.rgb;\n#else\n var color = materialUniforms.polygonFill.rgb;\n#endif\n#ifdef HAS_INSTANCE_COLOR\n color *= vertexOutput.vInstanceColor.rgb;\n#endif\n ambient *= color.rgb;\n diffuse *= color.rgb;\n let viewDir = normalize(lightUniforms.cameraPosition - vertexOutput.vFragPos);\n let halfwayDir = normalize(lightDir + viewDir);\n var spec = pow(max(dot(norm, halfwayDir), 0.0), materialUniforms.materialShininess);\n#ifdef SHADING_MODEL_UNLIT\n let lightSpecular = vec3f(0.0);\n#else\n let lightSpecular = lightUniforms.lightSpecular;\n#endif\n var specular = materialUniforms.specularStrength * lightSpecular * spec * getSpecularColor(vertexOutput);\n#ifdef HAS_OCCLUSION_MAP\n let ao = textureSample(occlusionTexture, occlusionTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput1)).r;\n ambient *= ao;\n#endif\n#if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n diffuse = shadow_blend(diffuse, shadowCoeff).rgb;\n specular = shadow_blend(specular, shadowCoeff).rgb;\n ambient = shadow_blend(ambient, shadowCoeff).rgb;\n#endif\n var result = ambient + diffuse + specular;\n#ifdef HAS_EMISSIVE_MAP\n let emit = textureSample(emissiveTexture, emissiveTextureSampler, computeTexCoord(vertexOutput.vTexCoord, vertexOutput)).rgb;\n result += emit;\n#endif\n#ifdef IS_LINE_EXTRUSION\n var fragColor = vec4f(result, materialUniforms.lineOpacity * baseColor.a);\n#else\n var fragColor = vec4f(result, materialUniforms.polygonOpacity * baseColor.a);\n#endif\n#if HAS_COLOR || HAS_COLOR0\n let colorAlpha = vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n let colorAlpha = materialUniforms.lineColor.a;\n#else\n let colorAlpha = materialUniforms.polygonFill.a;\n#endif\n fragColor *= colorAlpha;\n#ifdef HAS_EXTRUSION_OPACITY\n let topAlpha = materialUniforms.extrusionOpacityRange.x;\n let bottomAlpha = materialUniforms.extrusionOpacityRange.y;\n let alpha = topAlpha + vertexOutput.vExtrusionOpacity * (bottomAlpha - topAlpha);\n let alpha = clamp(alpha, 0.0, 1.0);\n fragColor *= alpha;\n#endif\n if (fragColor.a < materialUniforms.alphaTest) {\n discard;\n }\n#ifdef HAS_VERTEX_COLOR\n fragColor *= vertexColor_get();\n#endif\n#ifdef HAS_HEATMAP\n fragColor = heatmap_getColor(fragColor);\n#endif\n#if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n fragColor = highlight_blendColor(fragColor, vertexOutput);\n#endif\n#ifdef HAS_LAYER_OPACITY\n fragColor *= lightUniforms.layerOpacity;\n#endif\n#ifdef HAS_MASK_EXTENT\n fragColor = setMask(fragColor);\n#endif\n return fragColor;\n}";
13757
13957
 
13758
13958
  class PhongShader extends MeshShader {
13759
13959
  constructor(config = {}) {
@@ -13783,8 +13983,8 @@ class PhongShader extends MeshShader {
13783
13983
  name: 'phong',
13784
13984
  vert: config.vert || phongVert,
13785
13985
  frag: config.frag || phongFrag,
13786
- wgslVert: wgslVert$4,
13787
- wgslFrag: wgslFrag$7,
13986
+ wgslVert: wgslVert$5,
13987
+ wgslFrag: wgslFrag$9,
13788
13988
  uniforms,
13789
13989
  defines: config.defines || {},
13790
13990
  extraCommandProps: config.extraCommandProps || {}
@@ -13828,9 +14028,9 @@ class PointLineShader extends MeshShader {
13828
14028
  }
13829
14029
  }
13830
14030
 
13831
- var vert$c = "#if __VERSION__ == 300\n#define attribute in\n#define varying out\n#endif\nattribute vec2 aPosition;\nattribute vec2 aTexCoord;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_Position = vec4(aPosition, 0., 1.);\n vTexCoord = aTexCoord;\n}";
14031
+ var vert$b = "#if __VERSION__ == 300\n#define attribute in\n#define varying out\n#endif\nattribute vec2 aPosition;\nattribute vec2 aTexCoord;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_Position = vec4(aPosition, 0., 1.);\n vTexCoord = aTexCoord;\n}";
13832
14032
 
13833
- var wgslVert$3 = "struct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vTexCoord: vec2f\n}\n@vertex\nfn main(\n @location($i) aPosition: vec2f,\n @location($i) aTexCoord: vec2f\n) -> VertexOutput {\n var output: VertexOutput;\n output.position = vec4f(aPosition, 0., 1.);\n output.vTexCoord = aTexCoord;\n return output;\n}";
14033
+ var wgslVert$4 = "struct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vTexCoord: vec2f\n}\n@vertex\nfn main(\n @location($i) aPosition: vec2f,\n @location($i) aTexCoord: vec2f\n) -> VertexOutput {\n var output: VertexOutput;\n output.position = vec4f(aPosition, 0., 1.);\n output.vTexCoord = aTexCoord;\n return output;\n}";
13834
14034
 
13835
14035
  const quadVertices$1 = new Float32Array([
13836
14036
  // positions
@@ -13852,8 +14052,8 @@ const quadTexcoords$1 = new Float32Array([
13852
14052
 
13853
14053
  class QuadShader extends MeshShader {
13854
14054
  constructor(config) {
13855
- config.vert = config.vert || vert$c;
13856
- config.wgslVert = config.wgslVert || wgslVert$3;
14055
+ config.vert = config.vert || vert$b;
14056
+ config.wgslVert = config.wgslVert || wgslVert$4;
13857
14057
  config.extraCommandProps = config.extraCommandProps || {};
13858
14058
  if (!config.extraCommandProps.depth) {
13859
14059
  //disable depth
@@ -13878,12 +14078,14 @@ class QuadShader extends MeshShader {
13878
14078
  return super.draw(regl, this._quadMesh);
13879
14079
  }
13880
14080
 
13881
- getMeshCommand(regl) {
13882
- const keys = this.dkey || '';
13883
- if (!this.commands[keys + '_quad']) {
13884
- this.commands[keys + '_quad'] = this.createMeshCommand(regl, this._quadMesh[0]);
14081
+ getMeshCommand(regl, mesh, renderProps) {
14082
+ const key = this.dkey || '';
14083
+ const shaderKey = this.getShaderCommandKey(regl, mesh, renderProps);
14084
+ const cmdKey = key + shaderKey + '_quad';
14085
+ if (!this.commands[cmdKey]) {
14086
+ this.commands[cmdKey] = this.createMeshCommand(regl, mesh);
13885
14087
  }
13886
- return this.commands[keys + '_quad'];
14088
+ return this.commands[cmdKey];
13887
14089
  }
13888
14090
 
13889
14091
  _createQuadMesh(regl) {
@@ -13916,13 +14118,13 @@ class QuadShader extends MeshShader {
13916
14118
 
13917
14119
  var frag$h = "#define SHADER_NAME FXAA\nprecision mediump float;\nvarying vec2 vTexCoord;\nuniform float enableFXAA;\nuniform float enableToneMapping;\nuniform float enableSharpen;\nuniform vec2 resolution;\nuniform sampler2D textureSource;\n#ifdef HAS_NOAA_TEX\nuniform sampler2D noAaTextureSource;\n#endif\n#ifdef HAS_POINT_TEX\nuniform sampler2D pointTextureSource;\n#endif\n#ifdef HAS_TAA_TEX\nuniform sampler2D taaTextureSource;\n#ifdef HAS_FXAA_TEX\nuniform sampler2D fxaaTextureSource;\n#endif\n#endif\nuniform float pixelRatio;\nuniform float sharpFactor;\n#ifdef HAS_OUTLINE_TEX\nuniform sampler2D textureOutline;\nuniform float highlightFactor;\nuniform float outlineFactor;\nuniform float outlineWidth;\nuniform vec3 outlineColor;\n#endif\nvec2 c;\nvec4 d(vec2 e) {\n \n#ifdef HAS_TAA_TEX\nvec4 f = texture2D(textureSource, e);\n vec4 taa = texture2D(taaTextureSource, e);\n#ifdef HAS_FXAA_TEX\nvec4 h = texture2D(fxaaTextureSource, e);\n#else\nvec4 h = vec4(.0);\n#endif\nvec4 i = taa + f * (1. - taa.a);\n return h + i * (1. - h.a);\n#else\nreturn texture2D(textureSource, e);\n#endif\n}\nvec3 j(const in vec3 k, const float l) {\n vec2 m = pixelRatio / resolution.xy;\n float n = .0;\n vec4 o = texture2D(textureSource, c + m * vec2(-1., -1.));\n o.rgb = mix(vec3(.0), o.rgb, sign(o.a));\n n += mix(.0, 1., sign(o.a));\n vec4 u = texture2D(textureSource, c + m * vec2(1.));\n u.rgb = mix(vec3(.0), u.rgb, sign(u.a));\n n += mix(.0, 1., sign(u.a));\n vec4 v = texture2D(textureSource, c + m * vec2(1., -1.));\n v.rgb = mix(vec3(.0), v.rgb, sign(v.a));\n n += mix(.0, 1., sign(v.a));\n vec4 A = texture2D(textureSource, c + m * vec2(-1., 1.));\n A.rgb = mix(vec3(.0), A.rgb, sign(A.a));\n n += mix(.0, 1., sign(A.a));\n return k + l * (n * k - o.rgb - v.rgb - A.rgb - u.rgb);\n}\nvec4 B(const in vec4 k) {\n return vec4(j(k.rgb, sharpFactor), k.a);\n}\nvec3 C(const vec3 x) {\n const float a = 2.51;\n const float b = .03;\n const float D = 2.43;\n const float E = .59;\n const float F = .14;\n return (x * (a * x + b)) / (x * (D * x + E) + F);\n}\nvec3 G(vec3 k) {\n k = k / (k + vec3(1.));\n return k = pow(k, vec3(1. / 2.2));\n}\n#ifdef HAS_OUTLINE_TEX\nvec4 H() {\n float I = 2.;\n float J = 1.;\n float K = pixelRatio / resolution[0] * outlineWidth;\n float L = pixelRatio / resolution[1] * outlineWidth;\n vec4 M = (texture2D(textureOutline, c + vec2(K, L)));\n vec4 N = (texture2D(textureOutline, c + vec2(K, .0)));\n vec4 O = (texture2D(textureOutline, c + vec2(K, -L)));\n vec4 P = (texture2D(textureOutline, c + vec2(.0, -L)));\n vec4 Q = (texture2D(textureOutline, c + vec2(-K, -L)));\n vec4 R = (texture2D(textureOutline, c + vec2(-K, .0)));\n vec4 S = (texture2D(textureOutline, c + vec2(-K, L)));\n vec4 T = (texture2D(textureOutline, c + vec2(.0, L)));\n vec4 U = -I * R + I * N + -J * S + J * M + -J * Q + J * O;\n vec4 V = -I * P + I * T + -J * Q + J * S + -J * O + J * M;\n float W = sqrt(dot(V, V) + dot(U, U));\n bool X = W < 1. / 65025.;\n vec3 Y = (texture2D(textureOutline, c)).r * outlineColor;\n if(Y == vec3(.0) || (highlightFactor == .0 && X)) {\n return vec4(.0);\n }\n float Z = X ? highlightFactor : min(1., sqrt(W) * outlineFactor);\n return Z * vec4(Y, 1.);\n}\nvec4 ba(const in vec4 k) {\n vec4 H = H();\n return H + vec4(k) * (1. - H.a);\n}\n#endif\nvoid main() {\n c = vTexCoord;\n vec4 k;\n if(enableFXAA == 1.) {\n \n } else {\n k = d(vTexCoord);\n }\n if(enableSharpen == 1.) {\n k = B(k);\n }\n#if defined(HAS_NOAA_TEX) || defined(HAS_POINT_TEX)\nvec4 bb = vec4(.0);\n vec4 bc = vec4(.0);\n#ifdef HAS_POINT_TEX\nbb = texture2D(pointTextureSource, vTexCoord);\n#endif\n#ifdef HAS_NOAA_TEX\nbc = texture2D(noAaTextureSource, vTexCoord);\n#endif\nvec4 bd = bb + bc * (1. - bb.a);\n k = bd + k * (1. - bd.a);\n#endif\nif(enableToneMapping == 1.) {\n k.rgb = G(k.rgb);\n }\n#ifdef HAS_OUTLINE_TEX\nk = ba(k);\n#endif\ngl_FragColor = k;\n}";
13918
14120
 
13919
- var wgslFrag$6 = "struct FxaaUniforms {\n enableFXAA: f32,\n enableToneMapping: f32,\n enableSharpen: f32,\n resolution: vec2f,\n pixelRatio: f32,\n sharpFactor: f32,\n #ifdef HAS_OUTLINE_TEX\n highlightFactor: f32,\n outlineFactor: f32,\n outlineWidth: f32,\n outlineColor: vec3f,\n #endif\n};\n@binding($b) @group(0) var<uniform> uniforms: FxaaUniforms;\n#ifdef HAS_MULTISAMPLED\n@binding($b) @group(0) var textureSource: texture_multisampled_2d<f32>;\n#else\n@binding($b) @group(0) var textureSource: texture_2d<f32>;\n#endif\n@binding($b) @group(0) var textureSourceSampler: sampler;\n#ifdef HAS_OUTLINE_TEX\n#ifdef HAS_MULTISAMPLED\n@binding($b) @group(0) var textureOutline: texture_multisampled_2d<f32>;\n#else\n@binding($b) @group(0) var textureOutline: texture_2d<f32>;\n#endif\n@binding($b) @group(0) var textureOutlineSampler: sampler;\n#endif\nvar<private> gTexCoord: vec2f;\nfn fetchSourceTexel(uv: vec2f) -> vec4f {\n let flipUV = vec2f(uv.x, 1.0 - uv.y);\n#ifdef HAS_MULTISAMPLED\n return textureLoad(textureSource, vec2i(flipUV * vec2f(uniforms.resolution)), 0);\n#else\n return textureSample(textureSource, textureSourceSampler, flipUV);\n#endif\n}\n#ifdef HAS_OUTLINE_TEX\n fn fetchOutlineTexel(uv: vec2f) -> vec4f {\n let flipUV = vec2f(uv.x, 1.0 - uv.y);\n #ifdef HAS_MULTISAMPLED\n return textureLoad(textureOutline, vec2i(flipUV * vec2f(uniforms.resolution)), 0);\n #else\n return textureSample(textureOutline, textureOutlineSampler, flipUV);\n #endif\n }\n#endif\nfn readFXAATexture(uv: vec2f) -> vec4f {\n return fetchSourceTexel(uv);\n}\nfn sharpColorFactor(color: vec3f, sharp: f32) -> vec3f {\n let off = uniforms.pixelRatio / uniforms.resolution;\n var count: f32 = 0.0;\n let rgbNW = fetchSourceTexel(gTexCoord + off * vec2f(-1.0, -1.0));\n let rgbNW_rgb = select(vec3f(0.0), rgbNW.rgb, rgbNW.a > 0.0);\n count += select(0.0, 1.0, rgbNW.a > 0.0);\n let rgbSE = fetchSourceTexel(gTexCoord + off * vec2f(1.0, 1.0));\n let rgbSE_rgb = select(vec3f(0.0), rgbSE.rgb, rgbSE.a > 0.0);\n count += select(0.0, 1.0, rgbSE.a > 0.0);\n let rgbNE = fetchSourceTexel(gTexCoord + off * vec2f(1.0, -1.0));\n let rgbNE_rgb = select(vec3f(0.0), rgbNE.rgb, rgbNE.a > 0.0);\n count += select(0.0, 1.0, rgbNE.a > 0.0);\n let rgbSW = fetchSourceTexel(gTexCoord + off * vec2f(-1.0, 1.0));\n let rgbSW_rgb = select(vec3f(0.0), rgbSW.rgb, rgbSW.a > 0.0);\n count += select(0.0, 1.0, rgbSW.a > 0.0);\n return color + sharp * (count * color - rgbNW_rgb - rgbNE_rgb - rgbSW_rgb - rgbSE_rgb);\n}\nfn sharpen(color: vec4f) -> vec4f {\n return vec4f(sharpColorFactor(color.rgb, uniforms.sharpFactor), color.a);\n}\nfn HDR_ACES(x: vec3f) -> vec3f {\n let a: f32 = 2.51;\n let b: f32 = 0.03;\n let c: f32 = 2.43;\n let d: f32 = 0.59;\n let e: f32 = 0.14;\n return (x * (a * x + b)) / (x * (c * x + d) + e);\n}\nfn tonemap(color: vec3f) -> vec3f {\n var result = color / (color + vec3f(1.0));\n result = pow(result, vec3f(1.0 / 2.2));\n return result;\n}\n#ifdef HAS_OUTLINE_TEX\nfn outline() -> vec4f {\n let offsetx = uniforms.pixelRatio / uniforms.resolution.x * uniforms.outlineWidth;\n let offsety = uniforms.pixelRatio / uniforms.resolution.y * uniforms.outlineWidth;\n let fac0: f32 = 2.0;\n let fac1: f32 = 1.0;\n let texel0 = fetchOutlineTexel(gTexCoord + vec2f(offsetx, offsety));\n let texel1 = fetchOutlineTexel(gTexCoord + vec2f(offsetx, 0.0));\n let texel2 = fetchOutlineTexel(gTexCoord + vec2f(offsetx, -offsety));\n let texel3 = fetchOutlineTexel(gTexCoord + vec2f(0.0, -offsety));\n let texel4 = fetchOutlineTexel(gTexCoord + vec2f(-offsetx, -offsety));\n let texel5 = fetchOutlineTexel(gTexCoord + vec2f(-offsetx, 0.0));\n let texel6 = fetchOutlineTexel(gTexCoord + vec2f(-offsetx, offsety));\n let texel7 = fetchOutlineTexel(gTexCoord + vec2f(0.0, offsety));\n let rowx = -fac0 * texel5 + fac0 * texel1 + -fac1 * texel6 + fac1 * texel0 + -fac1 * texel4 + fac1 * texel2;\n let rowy = -fac0 * texel3 + fac0 * texel7 + -fac1 * texel4 + fac1 * texel6 + -fac1 * texel2 + fac1 * texel0;\n let magSqr = sqrt(dot(rowy, rowy) + dot(rowx, rowx));\n let infMag = magSqr < 1.0 / 65025.0;\n let texelCenter = fetchOutlineTexel(gTexCoord).r * uniforms.outlineColor;\n if (all(texelCenter == vec3f(0.0)) || (uniforms.highlightFactor == 0.0 && infMag)) {\n return vec4f(0.0);\n }\n let finalFactor = select(min(1.0, sqrt(magSqr) * uniforms.outlineFactor), uniforms.highlightFactor, infMag);\n return finalFactor * vec4f(texelCenter, 1.0);\n}\nfn composeOutline(color: vec4f) -> vec4f {\n let outlineColor = outline();\n return outlineColor + color * (1.0 - outlineColor.a);\n}\n#endif\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n gTexCoord = vertexOutput.vTexCoord;\n var color: vec4f;\n if (uniforms.enableFXAA == 1.0) {\n color = readFXAATexture(vertexOutput.vTexCoord);\n } else {\n color = readFXAATexture(vertexOutput.vTexCoord);\n }\n if (uniforms.enableSharpen == 1.0) {\n color = sharpen(color);\n }\n if (uniforms.enableToneMapping == 1.0) {\n color = vec4(tonemap(color.rgb), color.a);\n }\n #ifdef HAS_OUTLINE_TEX\n color = composeOutline(color);\n #endif\n return color;\n}";
14121
+ var wgslFrag$8 = "struct FxaaUniforms {\n enableFXAA: f32,\n enableToneMapping: f32,\n enableSharpen: f32,\n resolution: vec2f,\n pixelRatio: f32,\n sharpFactor: f32,\n #ifdef HAS_OUTLINE_TEX\n highlightFactor: f32,\n outlineFactor: f32,\n outlineWidth: f32,\n outlineColor: vec3f,\n #endif\n};\n@binding($b) @group(0) var<uniform> uniforms: FxaaUniforms;\n#ifdef HAS_MULTISAMPLED\n@binding($b) @group(0) var textureSource: texture_multisampled_2d<f32>;\n#else\n@binding($b) @group(0) var textureSource: texture_2d<f32>;\n#endif\n@binding($b) @group(0) var textureSourceSampler: sampler;\n#ifdef HAS_OUTLINE_TEX\n#ifdef HAS_MULTISAMPLED\n@binding($b) @group(0) var textureOutline: texture_multisampled_2d<f32>;\n#else\n@binding($b) @group(0) var textureOutline: texture_2d<f32>;\n#endif\n@binding($b) @group(0) var textureOutlineSampler: sampler;\n#endif\nvar<private> gTexCoord: vec2f;\nfn fetchSourceTexel(uv: vec2f) -> vec4f {\n let flipUV = vec2f(uv.x, 1.0 - uv.y);\n#ifdef HAS_MULTISAMPLED\n return textureLoad(textureSource, vec2i(flipUV * vec2f(uniforms.resolution)), 0);\n#else\n return textureSample(textureSource, textureSourceSampler, flipUV);\n#endif\n}\n#ifdef HAS_OUTLINE_TEX\n fn fetchOutlineTexel(uv: vec2f) -> vec4f {\n let flipUV = vec2f(uv.x, 1.0 - uv.y);\n #ifdef HAS_MULTISAMPLED\n return textureLoad(textureOutline, vec2i(flipUV * vec2f(uniforms.resolution)), 0);\n #else\n return textureSample(textureOutline, textureOutlineSampler, flipUV);\n #endif\n }\n#endif\nfn readFXAATexture(uv: vec2f) -> vec4f {\n return fetchSourceTexel(uv);\n}\nfn sharpColorFactor(color: vec3f, sharp: f32) -> vec3f {\n let off = uniforms.pixelRatio / uniforms.resolution;\n var count: f32 = 0.0;\n let rgbNW = fetchSourceTexel(gTexCoord + off * vec2f(-1.0, -1.0));\n let rgbNW_rgb = select(vec3f(0.0), rgbNW.rgb, rgbNW.a > 0.0);\n count += select(0.0, 1.0, rgbNW.a > 0.0);\n let rgbSE = fetchSourceTexel(gTexCoord + off * vec2f(1.0, 1.0));\n let rgbSE_rgb = select(vec3f(0.0), rgbSE.rgb, rgbSE.a > 0.0);\n count += select(0.0, 1.0, rgbSE.a > 0.0);\n let rgbNE = fetchSourceTexel(gTexCoord + off * vec2f(1.0, -1.0));\n let rgbNE_rgb = select(vec3f(0.0), rgbNE.rgb, rgbNE.a > 0.0);\n count += select(0.0, 1.0, rgbNE.a > 0.0);\n let rgbSW = fetchSourceTexel(gTexCoord + off * vec2f(-1.0, 1.0));\n let rgbSW_rgb = select(vec3f(0.0), rgbSW.rgb, rgbSW.a > 0.0);\n count += select(0.0, 1.0, rgbSW.a > 0.0);\n return color + sharp * (count * color - rgbNW_rgb - rgbNE_rgb - rgbSW_rgb - rgbSE_rgb);\n}\nfn sharpen(color: vec4f) -> vec4f {\n return vec4f(sharpColorFactor(color.rgb, uniforms.sharpFactor), color.a);\n}\nfn HDR_ACES(x: vec3f) -> vec3f {\n let a: f32 = 2.51;\n let b: f32 = 0.03;\n let c: f32 = 2.43;\n let d: f32 = 0.59;\n let e: f32 = 0.14;\n return (x * (a * x + b)) / (x * (c * x + d) + e);\n}\nfn tonemap(color: vec3f) -> vec3f {\n var result = color / (color + vec3f(1.0));\n result = pow(result, vec3f(1.0 / 2.2));\n return result;\n}\n#ifdef HAS_OUTLINE_TEX\nfn outline() -> vec4f {\n let offsetx = uniforms.pixelRatio / uniforms.resolution.x * uniforms.outlineWidth;\n let offsety = uniforms.pixelRatio / uniforms.resolution.y * uniforms.outlineWidth;\n let fac0: f32 = 2.0;\n let fac1: f32 = 1.0;\n let texel0 = fetchOutlineTexel(gTexCoord + vec2f(offsetx, offsety));\n let texel1 = fetchOutlineTexel(gTexCoord + vec2f(offsetx, 0.0));\n let texel2 = fetchOutlineTexel(gTexCoord + vec2f(offsetx, -offsety));\n let texel3 = fetchOutlineTexel(gTexCoord + vec2f(0.0, -offsety));\n let texel4 = fetchOutlineTexel(gTexCoord + vec2f(-offsetx, -offsety));\n let texel5 = fetchOutlineTexel(gTexCoord + vec2f(-offsetx, 0.0));\n let texel6 = fetchOutlineTexel(gTexCoord + vec2f(-offsetx, offsety));\n let texel7 = fetchOutlineTexel(gTexCoord + vec2f(0.0, offsety));\n let rowx = -fac0 * texel5 + fac0 * texel1 + -fac1 * texel6 + fac1 * texel0 + -fac1 * texel4 + fac1 * texel2;\n let rowy = -fac0 * texel3 + fac0 * texel7 + -fac1 * texel4 + fac1 * texel6 + -fac1 * texel2 + fac1 * texel0;\n let magSqr = sqrt(dot(rowy, rowy) + dot(rowx, rowx));\n let infMag = magSqr < 1.0 / 65025.0;\n let texelCenter = fetchOutlineTexel(gTexCoord).r * uniforms.outlineColor;\n if (all(texelCenter == vec3f(0.0)) || (uniforms.highlightFactor == 0.0 && infMag)) {\n return vec4f(0.0);\n }\n let finalFactor = select(min(1.0, sqrt(magSqr) * uniforms.outlineFactor), uniforms.highlightFactor, infMag);\n return finalFactor * vec4f(texelCenter, 1.0);\n}\nfn composeOutline(color: vec4f) -> vec4f {\n let outlineColor = outline();\n return outlineColor + color * (1.0 - outlineColor.a);\n}\n#endif\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n gTexCoord = vertexOutput.vTexCoord;\n var color: vec4f;\n if (uniforms.enableFXAA == 1.0) {\n color = readFXAATexture(vertexOutput.vTexCoord);\n } else {\n color = readFXAATexture(vertexOutput.vTexCoord);\n }\n if (uniforms.enableSharpen == 1.0) {\n color = sharpen(color);\n }\n if (uniforms.enableToneMapping == 1.0) {\n color = vec4(tonemap(color.rgb), color.a);\n }\n #ifdef HAS_OUTLINE_TEX\n color = composeOutline(color);\n #endif\n return color;\n}";
13920
14122
 
13921
14123
  class FxaaShader extends QuadShader {
13922
14124
  constructor() {
13923
14125
  super({
13924
14126
  name: 'fxaa',
13925
- frag: frag$h, wgslFrag: wgslFrag$6,
14127
+ frag: frag$h, wgslFrag: wgslFrag$8,
13926
14128
  extraCommandProps: {
13927
14129
  viewport: {
13928
14130
  x: 0,
@@ -13937,15 +14139,6 @@ class FxaaShader extends QuadShader {
13937
14139
  }
13938
14140
  });
13939
14141
  }
13940
-
13941
- getMeshCommand(regl, mesh) {
13942
- const key = this.dkey || '';
13943
- const cmdKey = key + '_fxaa';
13944
- if (!this.commands[cmdKey]) {
13945
- this.commands[cmdKey] = this.createMeshCommand(regl, mesh);
13946
- }
13947
- return this.commands[cmdKey];
13948
- }
13949
14142
  }
13950
14143
 
13951
14144
  var frag$g = "precision highp float;\nvarying vec2 vTexCoord;\nuniform sampler2D textureSource;\nuniform vec2 resolution;\nuniform float ignoreTransparent;\nvoid main() {\n vec4 c = vec4(.0);\n float d = .0;\n for(int x = -BOXBLUR_OFFSET; x <= BOXBLUR_OFFSET; ++x)\n for(int y = -BOXBLUR_OFFSET; y <= BOXBLUR_OFFSET; ++y) {\n vec2 e = vTexCoord.st + vec2(float(x) / resolution.x, float(y) / resolution.y);\n e = clamp(e, .0, 1.);\n vec4 f = texture2D(textureSource, e);\n float h;\n if(ignoreTransparent == 1.) {\n h = sign(f.a);\n } else {\n h = 1.;\n }\n d += h;\n c += h * f;\n }\n gl_FragColor = c / max(d, 1.) * clamp(sign(d - 1.), .0, 1.);\n}";
@@ -13954,7 +14147,7 @@ class BoxBlurShader extends QuadShader {
13954
14147
 
13955
14148
  constructor({ blurOffset }) {
13956
14149
  super({
13957
- vert: vert$c, frag: frag$g,
14150
+ vert: vert$b, frag: frag$g,
13958
14151
  defines : {
13959
14152
  'BOXBLUR_OFFSET' : blurOffset || 2
13960
14153
  },
@@ -13983,26 +14176,26 @@ class BoxBlurShader extends QuadShader {
13983
14176
  }
13984
14177
  }
13985
14178
 
13986
- var vert$b = "#include <gl2_vert>\nattribute vec2 aPosition;\nattribute vec2 aTexCoord;\nuniform mat4 projViewModelMatrix;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_Position = projViewModelMatrix * vec4(aPosition, 0., 1.);\n vTexCoord = aTexCoord;\n}";
14179
+ var vert$a = "#include <gl2_vert>\nattribute vec2 aPosition;\nattribute vec2 aTexCoord;\nuniform mat4 projViewModelMatrix;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_Position = projViewModelMatrix * vec4(aPosition, 0., 1.);\n vTexCoord = aTexCoord;\n}";
13987
14180
 
13988
14181
  var frag$f = "precision mediump float;\n#include <gl2_frag>\nuniform sampler2D baseColorTexture;\nuniform float opacity;\nuniform vec4 baseColor;\nuniform float alphaTest;\n#ifdef HAS_DEBUG\nuniform sampler2D debugTexture;\n#endif\nvarying vec2 vTexCoord;\nvoid main() {\n glFragColor = texture2D(baseColorTexture, vTexCoord);\n glFragColor *= baseColor;\n#ifdef HAS_DEBUG\nvec4 c = texture2D(debugTexture, vTexCoord);\n glFragColor = vec4(c.rgb + glFragColor.rgb * (1. - c.a), c.a + glFragColor.a * (1. - c.a));\n#endif\nif(glFragColor.a < alphaTest) {\n discard;\n }\n glFragColor *= opacity;\n#if __VERSION__ == 100\ngl_FragColor = glFragColor;\n#endif\n}";
13989
14182
 
13990
- var wgslVert$2 = "struct Uniforms {\n projViewModelMatrix : mat4x4f\n}\n@group(0) @binding(0) var<uniform> uniforms : Uniforms;\nstruct VertexOutput {\n @builtin(position) Position : vec4f,\n @location(0) vTexCoord : vec2f\n}\n@vertex\nfn main(\n @location(0) aPosition : vec2i,\n @location(1) aTexCoord : vec2u\n) -> VertexOutput {\n var output : VertexOutput;\n output.Position = uniforms.projViewModelMatrix * vec4f(vec2f(aPosition), 0.0, 1.0);\n output.vTexCoord = vec2f(aTexCoord);\n return output;\n}";
14183
+ var wgslVert$3 = "struct Uniforms {\n projViewModelMatrix : mat4x4f\n}\n@group(0) @binding(0) var<uniform> uniforms : Uniforms;\nstruct VertexOutput {\n @builtin(position) Position : vec4f,\n @location(0) vTexCoord : vec2f\n}\n@vertex\nfn main(\n @location(0) aPosition : vec2i,\n @location(1) aTexCoord : vec2u\n) -> VertexOutput {\n var output : VertexOutput;\n output.Position = uniforms.projViewModelMatrix * vec4f(vec2f(aPosition), 0.0, 1.0);\n output.vTexCoord = vec2f(aTexCoord);\n return output;\n}";
13991
14184
 
13992
- var wgslFrag$5 = "struct Scene {\n opacity : f32,\n baseColor : vec4f,\n alphaTest : f32,\n}\n@group(0) @binding(1) var<uniform> scene: Scene;\n@group(0) @binding(2) var baseColorTextureSampler: sampler;\n@group(0) @binding(3) var baseColorTexture: texture_2d<f32>;\n#if HAS_DEBUG\n @group(0) @binding(4) var debugTextureSampler: sampler;\n @group(0) @binding(5) var debugTexture: texture_2d<f32>;\n#endif\n@fragment\nfn main(\n input : VertexOutput,\n) -> @location(0) vec4f {\n var fragColor = textureSample(baseColorTexture, baseColorTextureSampler, input.vTexCoord);\n fragColor *= scene.baseColor;\n #if HAS_DEBUG\n var debugColor = textureSample(debugTexture, debugTextureSampler, input.vTexCoord);\n fragColor = vec4f(\n debugColor.rgb + fragColor.rgb * (1.0 - debugColor.a),\n debugColor.a + fragColor.a * (1.0 - debugColor.a)\n );\n #endif\n if (fragColor.a < scene.alphaTest) {\n discard;\n }\n return fragColor * scene.opacity;\n}";
14185
+ var wgslFrag$7 = "struct Scene {\n opacity : f32,\n baseColor : vec4f,\n alphaTest : f32,\n}\n@group(0) @binding(1) var<uniform> scene: Scene;\n@group(0) @binding(2) var baseColorTextureSampler: sampler;\n@group(0) @binding(3) var baseColorTexture: texture_2d<f32>;\n#if HAS_DEBUG\n @group(0) @binding(4) var debugTextureSampler: sampler;\n @group(0) @binding(5) var debugTexture: texture_2d<f32>;\n#endif\n@fragment\nfn main(\n input : VertexOutput,\n) -> @location(0) vec4f {\n var fragColor = textureSample(baseColorTexture, baseColorTextureSampler, input.vTexCoord);\n fragColor *= scene.baseColor;\n #if HAS_DEBUG\n var debugColor = textureSample(debugTexture, debugTextureSampler, input.vTexCoord);\n fragColor = vec4f(\n debugColor.rgb + fragColor.rgb * (1.0 - debugColor.a),\n debugColor.a + fragColor.a * (1.0 - debugColor.a)\n );\n #endif\n if (fragColor.a < scene.alphaTest) {\n discard;\n }\n return fragColor * scene.opacity;\n}";
13993
14186
 
13994
14187
  class ImageShader extends MeshShader {
13995
14188
  constructor(config) {
13996
14189
  const projViewModelMatrix = [];
13997
14190
  const extraCommandProps = config ? config.extraCommandProps || {} : {};
13998
- config.vert = vert$b;
14191
+ config.vert = vert$a;
13999
14192
  config.frag = frag$f;
14000
14193
  super({
14001
14194
  name: 'image',
14002
- vert: vert$b,
14195
+ vert: vert$a,
14003
14196
  frag: frag$f,
14004
- wgslVert: wgslVert$2,
14005
- wgslFrag: wgslFrag$5,
14197
+ wgslVert: wgslVert$3,
14198
+ wgslFrag: wgslFrag$7,
14006
14199
  uniforms: [
14007
14200
  {
14008
14201
  name: 'projViewModelMatrix',
@@ -14016,12 +14209,14 @@ class ImageShader extends MeshShader {
14016
14209
  });
14017
14210
  }
14018
14211
 
14019
- getMeshCommand(regl, mesh) {
14020
- const key = mesh.getCommandKey(regl);
14021
- if (!this.commands['image_' + key]) {
14022
- this.commands['image_' + key] = this.createMeshCommand(regl, mesh);
14212
+ getMeshCommand(regl, mesh, renderProps) {
14213
+ const key = this.getShaderCommandKey(regl, mesh, renderProps);
14214
+ const meshKey = mesh.getCommandKey(regl);
14215
+ const dKey = key + '_' + meshKey;
14216
+ if (!this.commands['image_' + dKey]) {
14217
+ this.commands['image_' + dKey] = this.createMeshCommand(regl, mesh, null, renderProps);
14023
14218
  }
14024
- return this.commands['image_' + key];
14219
+ return this.commands['image_' + dKey];
14025
14220
  }
14026
14221
  }
14027
14222
 
@@ -14030,7 +14225,7 @@ var frag$e = "precision mediump float;\nvarying vec2 vTexCoord;\nuniform vec2 re
14030
14225
  class PostProcessShader extends QuadShader {
14031
14226
  constructor() {
14032
14227
  super({
14033
- vert: vert$c, frag: frag$e,
14228
+ vert: vert$b, frag: frag$e,
14034
14229
  extraCommandProps: {
14035
14230
  viewport: {
14036
14231
  x: 0,
@@ -14460,7 +14655,7 @@ class BlurPass {
14460
14655
  _initShaders() {
14461
14656
  if (!this._blur0Shader) {
14462
14657
  const config = {
14463
- vert: vert$c,
14658
+ vert: vert$b,
14464
14659
  extraCommandProps: {
14465
14660
  viewport: {
14466
14661
  x: 0,
@@ -14643,9 +14838,9 @@ class BloomPass {
14643
14838
  this._blurPass = new BlurPass(this._regl, false);
14644
14839
  this._combineShader = new QuadShader({
14645
14840
  name: 'bloom-combine',
14646
- vert: vert$c,
14841
+ vert: vert$b,
14647
14842
  frag: combineFrag,
14648
- wgslVert: wgslVert$3,
14843
+ wgslVert: wgslVert$4,
14649
14844
  wgslFrag: combineFragWgsl,
14650
14845
  extraCommandProps: {
14651
14846
  viewport
@@ -14657,7 +14852,7 @@ class BloomPass {
14657
14852
 
14658
14853
  var frag$d = "precision highp float;\n#include <gl2_frag>\n#define SHADER_NAME COPY_DEPTH\nuniform sampler2D TextureDepth;\nuniform vec2 textureSize;\n#include <common_pack_float>\nvoid main(void) {\n vec2 c = gl_FragCoord.xy / textureSize.xy;\n float d = texture2D(TextureDepth, c).r;\n glFragColor = common_encodeDepth(d);\n#if __VERSION__ == 100\ngl_FragColor = glFragColor;\n#endif\n}";
14659
14854
 
14660
- var wgslFrag$4 = "#define SHADER_NAME COPY_DEPTH\n#include <common_pack_float>\nstruct CopyDepthUniforms {\n textureSize: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: CopyDepthUniforms;\n#ifdef HAS_MULTISAMPLED\n @group(0) @binding($b) var TextureDepth: texture_depth_multisampled_2d;\n#else\n @group(0) @binding($b) var TextureDepth: texture_depth_2d;\n#endif\n@group(0) @binding($b) var TextureDepthSampler: sampler;\n@fragment\nfn main(\n vertexOutput: VertexOutput\n) -> @location(0) vec4f {\n let uv = vertexOutput.vTexCoord;\n #ifdef HAS_MULTISAMPLED\n let depth = textureLoad(TextureDepth, vec2i(uv * uniforms.textureSize), 0);\n #else\n let depth = textureSample(TextureDepth, TextureDepthSampler, uv);\n #endif\n var fragColor = common_encodeDepth(depth);\n return fragColor;\n}";
14855
+ var wgslFrag$6 = "#define SHADER_NAME COPY_DEPTH\n#include <common_pack_float>\nstruct CopyDepthUniforms {\n textureSize: vec2f,\n};\n@group(0) @binding($b) var<uniform> uniforms: CopyDepthUniforms;\n#ifdef HAS_MULTISAMPLED\n @group(0) @binding($b) var TextureDepth: texture_depth_multisampled_2d;\n#else\n @group(0) @binding($b) var TextureDepth: texture_depth_2d;\n#endif\n@group(0) @binding($b) var TextureDepthSampler: sampler;\n@fragment\nfn main(\n vertexOutput: VertexOutput\n) -> @location(0) vec4f {\n let uv = vertexOutput.vTexCoord;\n #ifdef HAS_MULTISAMPLED\n let depth = textureLoad(TextureDepth, vec2i(uv * uniforms.textureSize), 0);\n #else\n let depth = textureSample(TextureDepth, TextureDepthSampler, uv);\n #endif\n var fragColor = common_encodeDepth(depth);\n return fragColor;\n}";
14661
14856
 
14662
14857
  //DEPRECATED
14663
14858
 
@@ -14666,8 +14861,8 @@ class CopyDepthShader extends QuadShader {
14666
14861
  const size = [];
14667
14862
  super({
14668
14863
  name: 'copy-depth',
14669
- vert: vert$c, frag: frag$d,
14670
- wgslVert: wgslVert$3, wgslFrag: wgslFrag$4,
14864
+ vert: vert$b, frag: frag$d,
14865
+ wgslVert: wgslVert$4, wgslFrag: wgslFrag$6,
14671
14866
  uniforms: [
14672
14867
  {
14673
14868
  name: 'textureSize',
@@ -14952,7 +15147,7 @@ class SsrPass {
14952
15147
  }
14953
15148
  }
14954
15149
 
14955
- var vert$a = "#define SHADER_NAME HEATMAP\nuniform mat4 projViewModelMatrix;\nuniform float extrudeScale;\nuniform float heatmapIntensity;\nattribute vec3 aPosition;\nvarying vec2 vExtrude;\n#ifdef HAS_HEAT_WEIGHT\nattribute highp float aWeight;\nvarying highp float weight;\n#else\nuniform highp float heatmapWeight;\n#endif\nuniform mediump float heatmapRadius;\nconst highp float c = 1. / 255. / 16.;\n#define GAUSS_COEF 0.3989422804014327\nvoid main(void) {\n \n#ifdef HAS_HEAT_WEIGHT\nhighp float d = aWeight / 255.;\n weight = d;\n#else\nhighp float d = heatmapWeight;\n#endif\nmediump float e = heatmapRadius;\n vec2 f = vec2(mod(aPosition.xy, 2.) * 2. - 1.);\n float h = sqrt(-2. * log(c / d / heatmapIntensity / GAUSS_COEF)) / 3.;\n vExtrude = h * f;\n vec2 i = vExtrude * e * extrudeScale;\n vec4 j = vec4(floor(aPosition.xy * .5) + i, aPosition.z, 1);\n gl_Position = projViewModelMatrix * j;\n}";
15150
+ var vert$9 = "#define SHADER_NAME HEATMAP\nuniform mat4 projViewModelMatrix;\nuniform float extrudeScale;\nuniform float heatmapIntensity;\nattribute vec3 aPosition;\nvarying vec2 vExtrude;\n#ifdef HAS_HEAT_WEIGHT\nattribute highp float aWeight;\nvarying highp float weight;\n#else\nuniform highp float heatmapWeight;\n#endif\nuniform mediump float heatmapRadius;\nconst highp float c = 1. / 255. / 16.;\n#define GAUSS_COEF 0.3989422804014327\nvoid main(void) {\n \n#ifdef HAS_HEAT_WEIGHT\nhighp float d = aWeight / 255.;\n weight = d;\n#else\nhighp float d = heatmapWeight;\n#endif\nmediump float e = heatmapRadius;\n vec2 f = vec2(mod(aPosition.xy, 2.) * 2. - 1.);\n float h = sqrt(-2. * log(c / d / heatmapIntensity / GAUSS_COEF)) / 3.;\n vExtrude = h * f;\n vec2 i = vExtrude * e * extrudeScale;\n vec4 j = vec4(floor(aPosition.xy * .5) + i, aPosition.z, 1);\n gl_Position = projViewModelMatrix * j;\n}";
14956
15151
 
14957
15152
  var frag$c = "#define SHADER_NAME HEATMAP\nprecision mediump float;\nuniform highp float heatmapIntensity;\nvarying vec2 vExtrude;\n#ifdef HAS_HEAT_WEIGHT\nvarying highp float weight;\n#else\nuniform highp float heatmapWeight;\n#endif\n#define GAUSS_COEF 0.3989422804014327\nvoid main() {\n \n#ifdef HAS_HEAT_WEIGHT\nhighp float c = weight;\n#else\nhighp float c = heatmapWeight;\n#endif\nfloat d = -.5 * 3. * 3. * dot(vExtrude, vExtrude);\n float e = c * heatmapIntensity * GAUSS_COEF * exp(d);\n gl_FragColor = vec4(e, 1., 1., 1.);\n}";
14958
15153
 
@@ -14961,7 +15156,7 @@ class HeatmapShader extends MeshShader {
14961
15156
  const extraCommandProps = config ? config.extraCommandProps || {} : {};
14962
15157
  const projViewModelMatrix = [];
14963
15158
  super({
14964
- vert: vert$a, frag: frag$c,
15159
+ vert: vert$9, frag: frag$c,
14965
15160
  uniforms: [
14966
15161
  {
14967
15162
  name: 'extrudeScale',
@@ -15039,15 +15234,22 @@ var skyboxData = {
15039
15234
  ]
15040
15235
  };
15041
15236
 
15042
- var vert$9 = "#include <gl2_vert>\nattribute vec3 aPosition;\nuniform mat4 projMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 transformMatrix;\nvarying vec3 vWorldPos;\nvoid main() {\n vWorldPos = aPosition;\n mat4 c = mat4(mat3(viewMatrix) * transformMatrix);\n vec4 d = projMatrix * c * vec4(vWorldPos, 1.);\n gl_Position = d.xyww;\n}";
15237
+ var vert$8 = "#include <gl2_vert>\nattribute vec3 aPosition;\nuniform mat4 projMatrix;\nuniform mat4 viewMatrix;\nuniform mat3 transformMatrix;\nvarying vec3 vWorldPos;\nvoid main() {\n vWorldPos = aPosition;\n mat4 c = mat4(mat3(viewMatrix) * transformMatrix);\n vec4 d = projMatrix * c * vec4(vWorldPos, 1.);\n gl_Position = d.xyww;\n}";
15043
15238
 
15044
15239
  var skyboxRawFrag = "#define SHADER_NAME SKYBOX\n#if __VERSION__ == 100\n#ifdef GL_EXT_shader_texture_lod\n#extension GL_EXT_shader_texture_lod : enable\n#define textureCubeLod(tex, uv, lod) textureCubeLodEXT(tex, uv, lod)\n#else\n#define textureCubeLod(tex, uv, lod) textureCube(tex, uv, lod)\n#endif\n#else\n#define textureCubeLod(tex, uv, lod) textureLod(tex, uv, lod)\n#endif\nprecision highp float;\n#define saturate(x) clamp(x, 0.0, 1.0)\n#include <gl2_frag>\n#include <hsv_frag>\nuniform vec3 hsv;\nvarying vec3 vWorldPos;\n#ifdef USE_AMBIENT\nuniform vec3 diffuseSPH[9];\n#else\nuniform samplerCube cubeMap;\nuniform float bias;\nuniform float size;\n#endif\nuniform float environmentExposure;\nuniform float backgroundIntensity;\nvec4 c(const in samplerCube d, const in vec3 e, const in float f, const in float h) {\n vec3 i = e;\n return textureCubeLod(d, i, h);\n}\nvec3 j(const in vec3 k, const in vec3 l[9]) {\n float x = k.x;\n float y = k.y;\n float z = k.z;\n vec3 m = (l[0] + l[1] * x + l[2] * y + l[3] * z + l[4] * z * x + l[5] * y * z + l[6] * y * x + l[7] * (3. * z * z - 1.) + l[8] * (x * x - y * y));\n return max(m, vec3(.0));\n}\nfloat n(const in vec2 o) {\n vec3 u = fract(vec3(o.xyx) * .1031);\n u += dot(u, u.yzx + 19.19);\n return fract((u.x + u.y) * u.z);\n}\n#if defined(TONE_MAPPING)\nconst float v = 1.;\nvec3 A(vec3 B) {\n vec3 a = B * (B + .0245786) - .000090537;\n vec3 b = B * (.983729 * B + .4329510) + .238081;\n return a / b;\n}\nvec3 C(vec3 D) {\n const mat3 E = mat3(vec3(.59719, .07600, .02840), vec3(.35458, .90834, .13383), vec3(.04823, .01566, .83777));\n const mat3 F = mat3(vec3(1.60475, -.10208, -.00327), vec3(-.53108, 1.10813, -.07276), vec3(-.07367, -.00605, 1.07602));\n D *= v / .6;\n D = E * D;\n D = A(D);\n D = F * D;\n return saturate(D);\n}\nvec3 G(vec3 D) {\n return C(D);\n}\nvec4 H(in vec4 I) {\n return vec4(mix(pow(I.rgb, vec3(.41666)) * 1.055 - vec3(.055), I.rgb * 12.92, vec3(lessThanEqual(I.rgb, vec3(.0031308)))), I.a);\n}\nvec4 J(vec4 I) {\n return (H(I));\n}\n#endif\nvoid main() {\n vec4 K;\n#ifdef USE_AMBIENT\nvec3 k = normalize(vWorldPos + mix(-.5 / 255., .5 / 255., n(gl_FragCoord.xy)) * 2.);\n K = vec4(j(k, diffuseSPH), 1.);\n#else\nK = c(cubeMap, vWorldPos, size, bias);\n#endif\nK.rgb *= environmentExposure;\n K.rgb *= backgroundIntensity;\n glFragColor = K;\n if(length(hsv) > .0) {\n glFragColor.rgb = hsv_apply(clamp(glFragColor.rgb, .0, 1.), hsv);\n }\n#if defined(TONE_MAPPING)\nglFragColor.rgb = G(glFragColor.rgb);\n glFragColor = J(glFragColor);\n#endif\n#if __VERSION__ == 100\ngl_FragColor = glFragColor;\n#endif\n}";
15045
15240
 
15241
+ var wgslVert$2 = "struct Uniforms {\n projMatrix: mat4x4f,\n viewMatrix: mat4x4f,\n transformMatrix: mat3x3f,\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n};\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location($o) vWorldPos: vec3f,\n};\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n output.vWorldPos = vertexInput.aPosition;\n let viewMatrix = uniforms.viewMatrix;\n let m3 = mat3x3f(viewMatrix[0].xyz, viewMatrix[1].xyz, viewMatrix[2].xyz) * uniforms.transformMatrix;\n let rotViewMatrix: mat4x4f = mat4x4f(\n vec4<f32>(m3[0], 0.0),\n vec4<f32>(m3[1], 0.0),\n vec4<f32>(m3[2], 0.0),\n vec4<f32>(0.0, 0.0, 0.0, 1.0)\n );\n let clipPos: vec4f = uniforms.projMatrix * rotViewMatrix * vec4f(output.vWorldPos, 1.0);\n output.position = vec4f(clipPos.xy, clipPos.w, clipPos.w);\n return output;\n}";
15242
+
15243
+ var wgslFrag$5 = "#include <hsv_frag>\nstruct SkyboxUniforms {\n hsv: vec3f,\n #ifdef USE_AMBIENT\n diffuseSPH: array<vec3f, 9>,\n #else\n bias: f32,\n size: f32,\n #endif\n environmentExposure: f32,\n backgroundIntensity: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: SkyboxUniforms;\n#ifndef USE_AMBIENT\n @group(0) @binding($b) var cubeMap: texture_cube<f32>;\n @group(0) @binding($b) var cubeMapSampler: sampler;\n#endif\nfn textureCubeFixed(tex: texture_cube<f32>, texSampler: sampler, R: vec3f, size: f32, bias: f32) -> vec4f {\n var dir: vec3f = R;\n return textureSampleLevel(tex, texSampler, dir, bias);\n}\nfn computeDiffuseSPH(normal: vec3f, diffuseSPH: array<vec3f, 9>) -> vec3f {\n let x: f32 = normal.x;\n let y: f32 = normal.y;\n let z: f32 = normal.z;\n var result: vec3f = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x * x - y * y)\n );\n return max(result, vec3f(0.0));\n}\nfn pseudoRandom(fragCoord: vec2f) -> f32 {\n var p3: vec3f = fract(vec3f(fragCoord.x, fragCoord.y, fragCoord.x) * 0.1031);\n p3 += dot(p3, p3.yzx + 19.19);\n return fract((p3.x + p3.y) * p3.z);\n}\n#if TONE_MAPPING\n const toneMappingExposure: f32 = 1.0;\n fn RRTAndODTFit(v: vec3f) -> vec3f {\n let a: vec3f = v * (v + 0.0245786) - 0.000090537;\n let b: vec3f = v * (0.983729 * v + 0.4329510) + 0.238081;\n return a / b;\n }\n fn ACESFilmicToneMapping(color: vec3f) -> vec3f {\n const ACESInputMat: mat3x3f = mat3x3f(\n vec3f(0.59719, 0.07600, 0.02840),\n vec3f(0.35458, 0.90834, 0.13383),\n vec3f(0.04823, 0.01566, 0.83777)\n );\n const ACESOutputMat: mat3x3f = mat3x3f(\n vec3f(1.60475, -0.10208, -0.00327),\n vec3f(-0.53108, 1.10813, -0.07276),\n vec3f(-0.07367, -0.00605, 1.07602)\n );\n var adjustedColor: vec3f = color * toneMappingExposure / 0.6;\n adjustedColor = ACESInputMat * adjustedColor;\n adjustedColor = RRTAndODTFit(adjustedColor);\n adjustedColor = ACESOutputMat * adjustedColor;\n return clamp(adjustedColor, 0, 1);\n }\n fn toneMapping(color: vec3f) -> vec3f {\n return ACESFilmicToneMapping(color);\n }\n fn sRGBTransferOETF(value: vec4f) -> vec4f {\n var result: vec3f;\n let threshold: vec3f = vec3f(0.0031308);\n for (var i: i32 = 0; i < 3; i++) {\n if (value[i] <= threshold[i]) {\n result[i] = value[i] * 12.92;\n } else {\n result[i] = pow(value[i], 0.41666) * 1.055 - 0.055;\n }\n }\n return vec4f(result, value.a);\n }\n fn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n }\n#endif\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var envColor: vec4f;\n #ifdef USE_AMBIENT\n var normal: vec3f = normalize(\n vertexOutput.vWorldPos +\n mix(-0.5/255.0, 0.5/255.0, pseudoRandom(vertexOutput.fragCoord.xy)) * 2.0\n );\n envColor = vec4f(computeDiffuseSPH(normal, uniforms.diffuseSPH), 1.0);\n #else\n envColor = textureCubeFixed(\n cubeMap,\n cubeMapSampler,\n vertexOutput.vWorldPos,\n uniforms.size,\n uniforms.bias\n );\n #endif\n var rgb = envColor.rgb;\n rgb *= uniforms.environmentExposure;\n rgb *= uniforms.backgroundIntensity;\n if (length(uniforms.hsv) > 0.0) {\n rgb = hsv_apply3(clamp(rgb, vec3f(0.0), vec3f(1.0)), uniforms.hsv);\n }\n #if TONE_MAPPING\n rgb = toneMapping(rgb);\n let fragColor = linearToOutputTexel(vec4f(rgb, envColor.a));\n #else\n let fragColor = vec4f(rgb, envColor.a);\n #endif\n return fragColor;\n}";
15244
+
15046
15245
  class SkyboxShader extends MeshShader {
15047
15246
  constructor() {
15048
15247
  const config = {
15049
- vert: vert$9,
15248
+ name: 'skybox',
15249
+ vert: vert$8,
15050
15250
  frag: skyboxRawFrag,
15251
+ wgslVert: wgslVert$2,
15252
+ wgslFrag: wgslFrag$5,
15051
15253
  extraCommandProps: {
15052
15254
  depth: {
15053
15255
  enable : true,
@@ -15057,8 +15259,8 @@ class SkyboxShader extends MeshShader {
15057
15259
  viewport: {
15058
15260
  x: 0,
15059
15261
  y: 0,
15060
- width: (context, props) => { return props.resolution[0]; },
15061
- height: (context, props) => { return props.resolution[1]; },
15262
+ width: (_, props) => { return props.resolution[0]; },
15263
+ height: (_, props) => { return props.resolution[1]; },
15062
15264
  }
15063
15265
  }
15064
15266
  };
@@ -15096,7 +15298,7 @@ class SkyboxShader extends MeshShader {
15096
15298
  _createSkyboxMesh(regl) {
15097
15299
  const geometry = new Geometry(
15098
15300
  {
15099
- aPosition: new Int8Array(skyboxData.vertices)
15301
+ aPosition: new Float32Array(skyboxData.vertices)
15100
15302
  },
15101
15303
  null,
15102
15304
  skyboxData.vertices.length / 3
@@ -15120,7 +15322,7 @@ class SkyboxShader extends MeshShader {
15120
15322
  }
15121
15323
  }
15122
15324
 
15123
- var vert$8 = "#define SHADER_NAME HEATMAP_DISPLAY\nuniform mat4 projViewModelMatrix;\nattribute vec3 aPosition;\nvoid main() {\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.);\n}";
15325
+ var vert$7 = "#define SHADER_NAME HEATMAP_DISPLAY\nuniform mat4 projViewModelMatrix;\nattribute vec3 aPosition;\nvoid main() {\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.);\n}";
15124
15326
 
15125
15327
  var frag$b = "#define SHADER_NAME HEATMAP_DISPLAY\nprecision mediump float;\nuniform sampler2D inputTexture;\nuniform sampler2D colorRamp;\nuniform vec2 textureOutputSize;\nuniform float heatmapOpacity;\nvoid main() {\n vec2 c = gl_FragCoord.xy / textureOutputSize.xy;\n float t = texture2D(inputTexture, c).r;\n vec4 d = texture2D(colorRamp, vec2(t, .5));\n gl_FragColor = d * heatmapOpacity;\n}";
15126
15328
 
@@ -15142,7 +15344,7 @@ class HeatmapDisplayShader extends MeshShader {
15142
15344
  }
15143
15345
  const projViewModelMatrix = [];
15144
15346
  super({
15145
- vert: vert$8, frag: frag$b,
15347
+ vert: vert$7, frag: frag$b,
15146
15348
  uniforms: [
15147
15349
  {
15148
15350
  name: 'projViewModelMatrix',
@@ -15174,13 +15376,13 @@ class WaterShader extends MeshShader {
15174
15376
 
15175
15377
  var frag$a = "precision highp float;\nuniform sampler2D texture;\nuniform vec2 size;\nuniform float enableSharpen;\nuniform float sharpFactor;\nuniform float pixelRatio;\nvec2 c;\nvec3 d(const in vec3 e, const float f) {\n vec2 h = pixelRatio / size.xy;\n float i = .0;\n vec4 j = texture2D(texture, c + h * vec2(-1., -1.));\n j.rgb = mix(vec3(.0), j.rgb, sign(j.a));\n i += mix(.0, 1., sign(j.a));\n vec4 k = texture2D(texture, c + h * vec2(1.));\n k.rgb = mix(vec3(.0), k.rgb, sign(k.a));\n i += mix(.0, 1., sign(k.a));\n vec4 l = texture2D(texture, c + h * vec2(1., -1.));\n l.rgb = mix(vec3(.0), l.rgb, sign(l.a));\n i += mix(.0, 1., sign(l.a));\n vec4 m = texture2D(texture, c + h * vec2(-1., 1.));\n m.rgb = mix(vec3(.0), m.rgb, sign(m.a));\n i += mix(.0, 1., sign(m.a));\n return e + f * (i * e - j.rgb - l.rgb - m.rgb - k.rgb);\n}\nvoid main() {\n c = gl_FragCoord.xy / size;\n vec4 e = texture2D(texture, c);\n if(enableSharpen == 1.) {\n e.rgb = d(e.rgb, sharpFactor);\n }\n gl_FragColor = e;\n}";
15176
15378
 
15177
- var wgslFrag$3 = "struct SharpenUniforms {\n size: vec2f,\n enableSharpen: f32,\n sharpFactor: f32,\n pixelRatio: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: SharpenUniforms;\n#ifdef HAS_MULTISAMPLED\n@binding($b) @group(0) var texture: texture_multisampled_2d<f32>;\n#else\n@binding($b) @group(0) var texture: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var textureSampler: sampler;\nvar<private> gTexCoord: vec2f;\nfn fetchSourceTexel(uv: vec2f) -> vec4f {\n#ifdef HAS_MULTISAMPLED\n return textureLoad(texture, vec2i(uv * vec2f(uniforms.size)), 0);\n#else\n return textureSample(texture, textureSampler, uv);\n#endif\n}\nfn sharpColorFactor(color: vec3f, sharp: f32) -> vec3f {\n let off = uniforms.pixelRatio / uniforms.size;\n var count: f32 = 0.0;\n var rgbNW = fetchSourceTexel(gTexCoord + off * vec2f(-1.0, -1.0));\n rgbNW = vec4f(select(vec3f(0.0), rgbNW.rgb, rgbNW.a > 0.0), rgbNW.a);\n count += select(0.0, 1.0, rgbNW.a > 0.0);\n var rgbSE = fetchSourceTexel(gTexCoord + off * vec2f(1.0, 1.0));\n rgbSE = vec4f(select(vec3f(0.0), rgbSE.rgb, rgbSE.a > 0.0), rgbSE.a);\n count += select(0.0, 1.0, rgbSE.a > 0.0);\n var rgbNE = fetchSourceTexel(gTexCoord + off * vec2f(1.0, -1.0));\n rgbNE = vec4f(select(vec3f(0.0), rgbNE.rgb, rgbNE.a > 0.0), rgbNE.a);\n count += select(0.0, 1.0, rgbNE.a > 0.0);\n var rgbSW = fetchSourceTexel(gTexCoord + off * vec2f(-1.0, 1.0));\n rgbSW = vec4f(select(vec3f(0.0), rgbSW.rgb, rgbSW.a > 0.0), rgbSW.a);\n count += select(0.0, 1.0, rgbSW.a > 0.0);\n return color + sharp * (count * color - rgbNW.rgb - rgbNE.rgb - rgbSW.rgb - rgbSE.rgb);\n}\n@fragment\nfn main(\n input : VertexOutput,\n) -> @location(0) vec4f {\n gTexCoord = input.position.xy / uniforms.size;\n var color = fetchSourceTexel(gTexCoord);\n if (uniforms.enableSharpen == 1.0) {\n color = vec4f(sharpColorFactor(color.rgb, uniforms.sharpFactor), color.a);\n }\n return color;\n}";
15379
+ var wgslFrag$4 = "struct SharpenUniforms {\n size: vec2f,\n enableSharpen: f32,\n sharpFactor: f32,\n pixelRatio: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: SharpenUniforms;\n#ifdef HAS_MULTISAMPLED\n@binding($b) @group(0) var texture: texture_multisampled_2d<f32>;\n#else\n@binding($b) @group(0) var texture: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var textureSampler: sampler;\nvar<private> gTexCoord: vec2f;\nfn fetchSourceTexel(uv: vec2f) -> vec4f {\n#ifdef HAS_MULTISAMPLED\n return textureLoad(texture, vec2i(uv * vec2f(uniforms.size)), 0);\n#else\n return textureSample(texture, textureSampler, uv);\n#endif\n}\nfn sharpColorFactor(color: vec3f, sharp: f32) -> vec3f {\n let off = uniforms.pixelRatio / uniforms.size;\n var count: f32 = 0.0;\n var rgbNW = fetchSourceTexel(gTexCoord + off * vec2f(-1.0, -1.0));\n rgbNW = vec4f(select(vec3f(0.0), rgbNW.rgb, rgbNW.a > 0.0), rgbNW.a);\n count += select(0.0, 1.0, rgbNW.a > 0.0);\n var rgbSE = fetchSourceTexel(gTexCoord + off * vec2f(1.0, 1.0));\n rgbSE = vec4f(select(vec3f(0.0), rgbSE.rgb, rgbSE.a > 0.0), rgbSE.a);\n count += select(0.0, 1.0, rgbSE.a > 0.0);\n var rgbNE = fetchSourceTexel(gTexCoord + off * vec2f(1.0, -1.0));\n rgbNE = vec4f(select(vec3f(0.0), rgbNE.rgb, rgbNE.a > 0.0), rgbNE.a);\n count += select(0.0, 1.0, rgbNE.a > 0.0);\n var rgbSW = fetchSourceTexel(gTexCoord + off * vec2f(-1.0, 1.0));\n rgbSW = vec4f(select(vec3f(0.0), rgbSW.rgb, rgbSW.a > 0.0), rgbSW.a);\n count += select(0.0, 1.0, rgbSW.a > 0.0);\n return color + sharp * (count * color - rgbNW.rgb - rgbNE.rgb - rgbSW.rgb - rgbSE.rgb);\n}\n@fragment\nfn main(\n input : VertexOutput,\n) -> @location(0) vec4f {\n gTexCoord = input.position.xy / uniforms.size;\n var color = fetchSourceTexel(gTexCoord);\n if (uniforms.enableSharpen == 1.0) {\n color = vec4f(sharpColorFactor(color.rgb, uniforms.sharpFactor), color.a);\n }\n return color;\n}";
15178
15380
 
15179
15381
  class CopyShader extends QuadShader {
15180
15382
  constructor() {
15181
15383
  super({
15182
15384
  name: 'copy',
15183
- wgslFrag: wgslFrag$3,
15385
+ wgslFrag: wgslFrag$4,
15184
15386
  frag: frag$a,
15185
15387
  extraCommandProps: {
15186
15388
  viewport: {
@@ -15209,7 +15411,7 @@ class CopyShader extends QuadShader {
15209
15411
 
15210
15412
  var frag$9 = "precision mediump float;\nuniform vec4 lineColor;\nuniform float lineOpacity;\nvoid main() {\n gl_FragColor = lineColor;\n gl_FragColor.a *= lineOpacity;\n}";
15211
15413
 
15212
- var vert$7 = "attribute vec3 aPosition;\nuniform mat4 projMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 positionMatrix;\nuniform mat4 modelViewMatrix;\n#include <get_output>\nvoid main() {\n vec4 c = getPosition(aPosition);\n mat4 d = getPositionMatrix();\n gl_Position = projMatrix * modelViewMatrix * d * c;\n}";
15414
+ var vert$6 = "attribute vec3 aPosition;\nuniform mat4 projMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 positionMatrix;\nuniform mat4 modelViewMatrix;\n#include <get_output>\nvoid main() {\n vec4 c = getPosition(aPosition);\n mat4 d = getPositionMatrix();\n gl_Position = projMatrix * modelViewMatrix * d * c;\n}";
15213
15415
 
15214
15416
  class EdgeShader extends MeshShader {
15215
15417
  constructor(config = {}) {
@@ -15228,7 +15430,7 @@ class EdgeShader extends MeshShader {
15228
15430
  uniforms.push(...extraUniforms);
15229
15431
  }
15230
15432
  super({
15231
- vert: vert$7,
15433
+ vert: vert$6,
15232
15434
  frag: frag$9,
15233
15435
  uniforms,
15234
15436
  defines: config.defines || {},
@@ -15239,7 +15441,7 @@ class EdgeShader extends MeshShader {
15239
15441
 
15240
15442
  var frag$8 = "#if __VERSION__ == 100\n#if defined(GL_EXT_shader_texture_lod)\n#extension GL_EXT_shader_texture_lod : enable\n#define textureCubeLod(tex, uv, lod) textureCubeLodEXT(tex, uv, lod)\n#else\n#define textureCubeLod(tex, uv, lod) textureCube(tex, uv, lod)\n#endif\n#if defined(GL_OES_standard_derivatives)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#else\n#define textureCubeLod(tex, uv, lod) textureLod(tex, uv, lod)\n#endif\n#define saturate(x) clamp(x, 0.0, 1.0)\nprecision mediump float;\n#include <gl2_frag>\n#include <hsv_frag>\nuniform vec3 hsv;\n#define GET_BASEMAP(UV) (texture2D(baseColorTexture, (UV)))\nuniform mat4 viewMatrix;\nuniform mat4 projMatrix;\nuniform vec3 cameraPosition;\n#if defined(HAS_IBL_LIGHTING)\nuniform mat4 viewMatrixInverse;\n#endif\nuniform vec4 baseColorFactor;\nuniform vec3 emissiveFactor;\nuniform vec3 specularFactor;\nuniform float opacity;\nuniform float envRotationSin;\nuniform float envRotationCos;\nuniform float rgbmRange;\n#if defined(HAS_MAP)\n#include <compute_texcoord_frag>\n#endif\n#ifdef HAS_BASECOLOR_MAP\nuniform sampler2D baseColorTexture;\n#endif\n#ifdef HAS_NORMAL_MAP\nuniform sampler2D normalTexture;\nvec3 c(vec3 d, vec3 e) {\n vec3 f = dFdx(d.xyz);\n vec3 h = dFdy(d.xyz);\n vec3 i = normalize(f - h);\n vec3 j = normalize(-f + h);\n vec3 k = normalize(e);\n vec3 l = texture2D(normalTexture, computeTexCoord(vTexCoord)).rgb * 2. - 1.;\n mat3 m = mat3(i, j, k);\n return normalize(m * l);\n}\n#endif\n#ifdef HAS_EMISSIVE_MAP\nuniform sampler2D emissiveTexture;\n#endif\n#ifdef SHADING_MODEL_SPECULAR_GLOSSINESS\nuniform vec4 diffuseFactor;\n#ifdef HAS_DIFFUSE_MAP\nuniform sampler2D diffuseTexture;\n#endif\n#ifdef HAS_SPECULARGLOSSINESS_MAP\nuniform sampler2D specularGlossinessTexture;\n#endif\n#endif\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_frag>\n#endif\n#if defined(HAS_COLOR) || defined(HAS_COLOR0)\nvarying vec4 vColor;\n#endif\n#ifdef GAMMA_INPUT\nvec3 n(vec3 o) {\n return o * o;\n}\nfloat n(float o) {\n return o * o;\n}\n#else\nvec3 n(vec3 o) {\n return o;\n}\nfloat n(float o) {\n return o;\n}\n#endif\nvec3 u() {\n \n#ifdef SHADING_MODEL_SPECULAR_GLOSSINESS\n#ifdef HAS_SPECULARGLOSSINESS_MAP\nreturn texture2D(specularGlossinessTexture, computeTexCoord(vTexCoord)).rgb;\n#else\nreturn specularFactor;\n#endif\n#else\nreturn specularFactor;\n#endif\n}\nvec3 v() {\n \n#ifdef HAS_EMISSIVE_MAP\nreturn texture2D(emissiveTexture, computeTexCoord(vTexCoord)).rgb;\n#else\nreturn emissiveFactor;\n#endif\n}\n#if defined(TONEMAP_OUTPUT)\n#if TONEMAP_OUTPUT > 0\nuniform float exposureBias;\nfloat A(vec3 rgb) {\n return dot(rgb, vec3(.299, .587, .114));\n}\nfloat B(vec3 rgb) {\n return dot(rgb, vec3(.212671, .715160, .072169));\n}\nvec3 C(vec3 xyz) {\n vec3 D = vec3(3.240479, -1.53715, -.498535);\n vec3 E = vec3(-.969256, 1.875992, .041556);\n vec3 F = vec3(.055648, -.204043, 1.057311);\n vec3 rgb;\n rgb.b = dot(xyz, F);\n rgb.g = dot(xyz, E);\n rgb.r = dot(xyz, D);\n return rgb;\n}\nvec3 H(vec3 rgb) {\n vec3 I = vec3(.412453, .35758, .180423);\n vec3 J = vec3(.212671, .71516, .0721688);\n vec3 K = vec3(.0193338, .119194, .950227);\n vec3 xyz;\n xyz.x = dot(rgb, I);\n xyz.y = dot(rgb, J);\n xyz.z = dot(rgb, K);\n return xyz;\n}\nvec3 L(vec3 xyz) {\n float M = xyz.x + xyz.y + xyz.z;\n M = 1. / M;\n vec3 O;\n O.z = xyz.y;\n O.x = xyz.x * M;\n O.y = xyz.y * M;\n return O;\n}\nvec3 P(vec3 O) {\n float x = O.x;\n float y = O.y;\n float J = O.z;\n vec3 xyz;\n xyz.y = J;\n xyz.x = x * (J / y);\n xyz.z = (1. - x - y) * (J / y);\n return xyz;\n}\nfloat Q(float x) {\n float U = pow(x, 1.60525727);\n float V = ((1.05542877 * 4.68037409) * U) / (4.68037409 * U + 1.);\n return clamp(V, .0, 1.);\n}\nconst float W = 1. / .18;\nfloat ba(float x) {\n x *= W;\n const float bb = .2;\n const float F = .34;\n const float bc = .002;\n const float bd = 1.68;\n const float be = .0005;\n const float bf = .252;\n const float bg = 1. / .833837;\n return ((x * (bb * x + bc * F) + bd * be) / (x * (bb * x + F) + bd * bf) - be / bf) * bg;\n}\nvec3 bh(vec3 x) {\n x *= W;\n const float bb = .27;\n const float F = .29;\n const float bc = .052;\n const float bd = .2;\n const float bf = .18;\n const float bg = 1. / .897105;\n return ((x * (bb * x + bc * F)) / (x * (bb * x + F) + bd * bf)) * bg;\n}\nvec3 bi(vec3 x) {\n vec3 bj = x.rgb;\n bj = min(bj, vec3(3.));\n float bk = B(bj);\n if(bk > .0) {\n float bl = Q(bk);\n bj = bj * (bl / bk);\n bj = clamp(bj, vec3(.0), vec3(1.));\n }\n float bm = 1. / 2.2;\n bj = pow(bj, vec3(bm));\n return bj;\n}\n#endif\n#endif\n#if defined(IRR_RGBM) || defined(ENV_RGBM) || defined(ENV_GAMMA) || defined(IRR_GAMMA)\nuniform float envMapExposure;\n#endif\nuniform vec4 themingColor;\nuniform mat3 environmentTransform;\nvec3 bn(vec3 bo, vec3 bp) {\n \n#if defined(HAS_SHADOWMAP)\nfloat bq = dot(shadowLightDir, bp);\n float br = (bq + 1.) / 2.;\n br = min(1., br * 1.5);\n float bs = 1.;\n vec3 bt = bo * min(bs, br);\n return bt;\n#else\nreturn bo;\n#endif\n}\n#ifdef HAS_IBL_LIGHTING\nuniform float reflectivity;\nuniform vec3 hdrHSV;\nuniform samplerCube prefilterMap;\nuniform vec3 diffuseSPH[9];\nuniform vec2 prefilterMiplevel;\nuniform vec2 prefilterSize;\n#else\nuniform vec3 ambientColor;\n#endif\n#if defined(HAS_IBL_LIGHTING)\nvec3 bu(const in vec3 bv) {\n vec3 bw = environmentTransform * bv;\n float x = bw.x;\n float y = bw.y;\n float z = bw.z;\n vec3 bt = (diffuseSPH[0] + diffuseSPH[1] * x + diffuseSPH[2] * y + diffuseSPH[3] * z + diffuseSPH[4] * z * x + diffuseSPH[5] * y * z + diffuseSPH[6] * y * x + diffuseSPH[7] * (3. * z * z - 1.) + diffuseSPH[8] * (x * x - y * y));\n if(length(hdrHSV) > .0) {\n bt = hsv_apply(bt, hdrHSV);\n }\n return max(bt, vec3(.0));\n}\nvec3 bx(const in vec4 by, const in float bz) {\n if(bz <= .0)\n return by.rgb;\n return bz * by.rgb * by.a;\n}\nfloat bA(const in float bB) {\n return bB;\n}\nvec3 bC(const in float bD, const in vec3 D) {\n vec3 bE = D;\n float bF = prefilterMiplevel.x;\n float bG = min(bF, bA(bD) * prefilterMiplevel.y);\n vec3 bH = bx(textureCubeLod(prefilterMap, bE, bG), rgbmRange);\n if(length(hdrHSV) > .0) {\n return hsv_apply(bH, hdrHSV);\n } else {\n return bH;\n }\n}\nvec3 bI(const in vec3 k, const in vec3 D, const in float bJ) {\n float bK = 1. - bJ;\n float bL = bK * (sqrt(bK) + bJ);\n return mix(k, D, bL);\n}\nvec3 bM(const in vec3 bv, const in vec3 bN, const in float bO, const in vec3 bP) {\n vec3 D = reflect(-bN, bv);\n D = bI(bv, D, bO);\n vec3 bQ = bC(bO, environmentTransform * D);\n float bR = clamp(1. + dot(D, bP), .0, 1.);\n bQ *= bR * bR;\n return bQ;\n}\n#else\nvec3 bM(const in vec3 bv, const in vec3 bN, const in float bO, const in vec3 bP) {\n return ambientColor;\n}\n#endif\nvarying highp vec3 vViewPosition;\nvec3 bS(vec3 bT, float bU) {\n float bV = max(1. - bU, .0);\n return bT + (1. - bT) * pow(bV, 5.);\n}\nfloat bW(float bT, float bU) {\n float bV = max(1. - bU, .0);\n return bT + (1. - bT) * pow(bV, 5.);\n}\n#include <srgb_frag>\nvoid main() {\n glFragColor = vec4(vec3(1.), opacity);\n#ifdef HAS_BASECOLOR_MAP\nvec4 bX = GET_BASEMAP(computeTexCoord(vTexCoord));\n#ifdef GAMMA_INPUT\nbX.xyz *= bX.xyz;\n#endif\nglFragColor = glFragColor * bX;\n#endif\n#ifdef ALPHATEST\nif(glFragColor.a < ALPHATEST)\n discard;\n \n#endif\nfloat bY = 1.;\n vec3 bZ = dFdx(vViewPosition);\n vec3 ca = dFdy(vViewPosition);\n vec3 bv = normalize(cross(bZ, ca));\n vec3 cb;\n if(projMatrix[3][3] == .0) {\n cb = normalize(vViewPosition);\n } else {\n cb = vec3(.0, .0, 1.);\n }\n bv = faceforward(bv, -cb, bv);\n vec3 cc = bv;\n#ifdef HAS_NORMAL_MAP\nbv = c(-vViewPosition, bv);\n#endif\nvec3 cd = vec3(.0);\n vec3 ce = vec3(.0);\n#ifdef HAS_IBL_LIGHTING\nvec3 bp = mat3(viewMatrixInverse) * bv;\n vec3 cf = glFragColor.rgb * bu(bp) * .5;\n cf = bn(cf, bp);\n cd += n(baseColorFactor.rgb) * cf;\n#endif\nvec3 cg = v();\n#ifdef METAL\nglFragColor.xyz = glFragColor.xyz * (n(cg) + cd + n(baseColorFactor.rgb) + ce);\n#else\nglFragColor.xyz = glFragColor.xyz * (n(cg) + cd + n(baseColorFactor.rgb)) + ce;\n#endif\nvec3 ch;\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nfloat ci = shadow_computeShadow();\n ch = shadow_blend(ch, ci).rgb;\n#endif\n#ifdef HAS_COLOR\nglFragColor = glFragColor * vColor;\n#endif\nglFragColor.rgb += ch;\n glFragColor.rgb = linearTosRGB(glFragColor.rgb);\n#if defined(HAS_IBL_LIGHTING)\nvec3 cj;\n#if defined(HAS_NORMAL_MAP)\n#ifdef ENVMAP_MODE_REFLECTION\ncj = reflect(-cb, bv);\n#else\ncj = refract(-cb, bv, 1.);\n#endif\n#else\ncj = reflect(-cb, bv);\n#endif\ncj = mat3(viewMatrixInverse) * cj;\n float ck = 1.;\n vec3 cl;\n#ifdef HAS_IBL_LIGHTING\ncl = vec3(.0);\n#elif\ncl = ambientColor;\n#endif\ncl *= ck;\n float bV = dot(cb, bv);\n if(bV < -1e-2 || reflectivity == .0)\n bV = 1.;\n else\n bV = max(1e-6, bV);\n vec3 cm;\n vec3 cn = u();\n#ifdef METAL\ncm = n(cn);\n#else\ncm = bS(n(cn), bV) * (1. - envRotationSin);\n glFragColor.a = mix(glFragColor.a, bW(glFragColor.a, bV), reflectivity) * envRotationCos;\n float co = pow(1. - bV * .5, 5.);\n float cp = (28. / 23.) * (1. - co) * (1. - co);\n glFragColor.rgb *= cp * (1. - n(cn));\n#endif\nglFragColor.rgb += cl.rgb * bY * cm.rgb;\n#endif\n#if defined(TONEMAP_OUTPUT)\n#if TONEMAP_OUTPUT == 1\nglFragColor.rgb = bi(exposureBias * glFragColor.rgb);\n#elif TONEMAP_OUTPUT == 2\nglFragColor.rgb = bh(exposureBias * glFragColor.rgb);\n#endif\n#endif\nglFragColor.rgb = mix(glFragColor.rgb, themingColor.rgb, themingColor.a);\n#if __VERSION__ == 100\ngl_FragColor = glFragColor;\n#endif\n}";
15241
15443
 
15242
- var vert$6 = "precision mediump float;\n#include <gl2_vert>\nattribute vec3 aPosition;\n#include <line_extrusion_vert>\n#ifdef HAS_MAP\nuniform vec2 uvScale;\nuniform vec2 uvOffset;\nattribute vec2 aTexCoord;\nvarying vec2 vTexCoord;\n#ifdef HAS_I3S_UVREGION\nattribute vec4 uvRegion;\nvarying vec4 vUvRegion;\n#endif\n#endif\n#if defined(HAS_COLOR)\nattribute vec4 aColor;\n#elif defined(HAS_COLOR0)\n#if COLOR0_SIZE == 3\nattribute vec3 aColor0;\n#else\nattribute vec4 aColor0;\n#endif\nvarying vec4 vColor;\n#endif\nuniform mat4 projMatrix;\nuniform mat3 modelNormalMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 positionMatrix;\nuniform vec2 halton;\nuniform vec2 outSize;\nuniform mat4 projViewMatrix;\n#include <get_output>\n#include <heatmap_render_vert>\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_vert>\n#endif\nvarying vec3 vViewPosition;\nvoid main() {\n \n#ifdef IS_LINE_EXTRUSION\nvec4 c = getPosition(getLineExtrudePosition(aPosition));\n#else\nvec4 c = getPosition(aPosition);\n#endif\nmat4 d = getPositionMatrix();\n mat4 e = projMatrix;\n e[2].xy += halton.xy / outSize.xy;\n#ifdef HAS_MASK_EXTENT\ngl_Position = e * getMaskPosition(d * c, modelMatrix);\n#else\ngl_Position = e * modelViewMatrix * d * c;\n#endif\nvec4 f = modelViewMatrix * d * c;\n vViewPosition = -f.xyz;\n#ifdef HAS_MAP\nvec2 h = decode_getTexcoord(aTexCoord);\n vTexCoord = h * uvScale + uvOffset;\n#endif\n#if defined(HAS_COLOR)\nvColor = aColor / 255.;\n#elif defined(HAS_COLOR0)\n#if COLOR0_SIZE == 3\nvColor = vec4(aColor0 / 255., 1.);\n#else\nvColor = aColor0 / 255.;\n#endif\n#endif\n}";
15444
+ var vert$5 = "precision mediump float;\n#include <gl2_vert>\nattribute vec3 aPosition;\n#include <line_extrusion_vert>\n#ifdef HAS_MAP\nuniform vec2 uvScale;\nuniform vec2 uvOffset;\nattribute vec2 aTexCoord;\nvarying vec2 vTexCoord;\n#ifdef HAS_I3S_UVREGION\nattribute vec4 uvRegion;\nvarying vec4 vUvRegion;\n#endif\n#endif\n#if defined(HAS_COLOR)\nattribute vec4 aColor;\n#elif defined(HAS_COLOR0)\n#if COLOR0_SIZE == 3\nattribute vec3 aColor0;\n#else\nattribute vec4 aColor0;\n#endif\nvarying vec4 vColor;\n#endif\nuniform mat4 projMatrix;\nuniform mat3 modelNormalMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 modelMatrix;\nuniform mat4 positionMatrix;\nuniform vec2 halton;\nuniform vec2 outSize;\nuniform mat4 projViewMatrix;\n#include <get_output>\n#include <heatmap_render_vert>\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_vert>\n#endif\nvarying vec3 vViewPosition;\nvoid main() {\n \n#ifdef IS_LINE_EXTRUSION\nvec4 c = getPosition(getLineExtrudePosition(aPosition));\n#else\nvec4 c = getPosition(aPosition);\n#endif\nmat4 d = getPositionMatrix();\n mat4 e = projMatrix;\n e[2].xy += halton.xy / outSize.xy;\n#ifdef HAS_MASK_EXTENT\ngl_Position = e * getMaskPosition(d * c, modelMatrix);\n#else\ngl_Position = e * modelViewMatrix * d * c;\n#endif\nvec4 f = modelViewMatrix * d * c;\n vViewPosition = -f.xyz;\n#ifdef HAS_MAP\nvec2 h = decode_getTexcoord(aTexCoord);\n vTexCoord = h * uvScale + uvOffset;\n#endif\n#if defined(HAS_COLOR)\nvColor = aColor / 255.;\n#elif defined(HAS_COLOR0)\n#if COLOR0_SIZE == 3\nvColor = vec4(aColor0 / 255., 1.);\n#else\nvColor = aColor0 / 255.;\n#endif\n#endif\n}";
15243
15445
 
15244
15446
  const TEMP_MAT4$1 = [];
15245
15447
  const environmentTransform = [];
@@ -15275,7 +15477,7 @@ class StandardLiteShader extends MeshShader {
15275
15477
  uniforms.push(...extraUniforms);
15276
15478
  }
15277
15479
  super({
15278
- vert: vert$6,
15480
+ vert: vert$5,
15279
15481
  frag: frag$8,
15280
15482
  uniforms,
15281
15483
  defines: config.defines || {},
@@ -15290,7 +15492,7 @@ var frag$7 = "#if __VERSION__ == 100\n#ifdef GL_OES_standard_derivatives\n#exten
15290
15492
  class EffectShader extends QuadShader {
15291
15493
  constructor() {
15292
15494
  super({
15293
- vert: vert$c, frag: frag$7,
15495
+ vert: vert$b, frag: frag$7,
15294
15496
  extraCommandProps: {
15295
15497
  viewport: {
15296
15498
  x: 0,
@@ -15392,7 +15594,7 @@ var frag$6 = "#if __VERSION__ == 100\n#ifdef GL_OES_standard_derivatives\n#exten
15392
15594
  class FogShader extends QuadShader {
15393
15595
  constructor() {
15394
15596
  super({
15395
- vert: vert$c, frag: frag$6,
15597
+ vert: vert$b, frag: frag$6,
15396
15598
  extraCommandProps: {
15397
15599
  viewport: {
15398
15600
  x: 0,
@@ -15569,7 +15771,7 @@ class RainRipplePass {
15569
15771
  }
15570
15772
  }
15571
15773
 
15572
- var vert$5 = "attribute vec3 aPosition;\nuniform mat4 positionMatrix;\nuniform mat4 projViewModelMatrix;\n#ifdef HAS_TEXTURE\nattribute vec2 aTexCoord;\nvarying vec2 uv;\nvarying vec4 vPos;\n#endif\n#include <get_output>\nvoid main() {\n mat4 c = getPositionMatrix();\n vec4 d = c * getPosition(aPosition);\n gl_Position = projViewModelMatrix * d;\n#ifdef HAS_TEXTURE\nuv = aTexCoord;\n vPos = getPosition(aPosition);\n#endif\n}";
15774
+ var vert$4 = "attribute vec3 aPosition;\nuniform mat4 positionMatrix;\nuniform mat4 projViewModelMatrix;\n#ifdef HAS_TEXTURE\nattribute vec2 aTexCoord;\nvarying vec2 uv;\nvarying vec4 vPos;\n#endif\n#include <get_output>\nvoid main() {\n mat4 c = getPositionMatrix();\n vec4 d = c * getPosition(aPosition);\n gl_Position = projViewModelMatrix * d;\n#ifdef HAS_TEXTURE\nuv = aTexCoord;\n vPos = getPosition(aPosition);\n#endif\n}";
15573
15775
 
15574
15776
  var maskColorExtent = "#ifdef GL_ES\nprecision highp float;\n#endif\nuniform vec4 maskColor;\n#ifdef HAS_TEXTURE\nuniform sampler2D maskTexture;\nvarying vec2 uv;\nuniform vec3 mask_position0;\nuniform vec3 mask_position1;\nuniform vec3 mask_position2;\nuniform vec3 mask_position3;\nvarying vec4 vPos;\nvec2 c(vec2 d, vec2 a, vec2 b, vec2 e, vec2 f) {\n vec2 h = vec2(.5);\n for(int i = 0; i < 10; i++) {\n float j = h.x;\n float k = h.y;\n vec2 l = (1. - j) * (1. - k) * a + j * (1. - k) * b + j * k * e + (1. - j) * k * f;\n vec2 m = d - l;\n if(length(m) < .001)\n break;\n vec2 n = -(1. - k) * a + (1. - k) * b + k * e - k * f;\n vec2 o = -(1. - j) * a - j * b + j * e + (1. - j) * f;\n float A = n.x * o.y - n.y * o.x;\n if(abs(A) > .0001) {\n vec2 B = vec2((m.x * o.y - m.y * o.x) / A, (m.y * n.x - m.x * n.y) / A);\n h += B;\n }\n h = clamp(h, .0, 1.);\n }\n return h;\n}\n#endif\nvoid main() {\n \n#ifdef HAS_TEXTURE\nvec2 d = vPos.xy;\n vec2 C = c(d, mask_position0.xy, mask_position1.xy, mask_position2.xy, mask_position3.xy);\n gl_FragColor = texture2D(maskTexture, C);\n gl_FragColor.a *= maskColor.a;\n#else\nif(maskColor.a == .0) {\n discard;\n }\n gl_FragColor = maskColor;\n#endif\n}";
15575
15777
 
@@ -15615,7 +15817,7 @@ class ExtentPass {
15615
15817
  }
15616
15818
  ];
15617
15819
  this._maskColorShader = new MeshShader({
15618
- vert: vert$5,
15820
+ vert: vert$4,
15619
15821
  frag: maskColorExtent,
15620
15822
  uniforms,
15621
15823
  extraCommandProps: {
@@ -15627,7 +15829,7 @@ class ExtentPass {
15627
15829
  }
15628
15830
  });
15629
15831
  this._maskModeShader = new MeshShader({
15630
- vert: vert$5,
15832
+ vert: vert$4,
15631
15833
  frag: maskModeExtent,
15632
15834
  uniforms,
15633
15835
  extraCommandProps: {
@@ -15699,7 +15901,7 @@ class ExtentPass {
15699
15901
 
15700
15902
  // import vert from './scaneffect.vert';
15701
15903
  // import frag from './scaneffect.frag';
15702
- const vert$4 = `#include <gl2_vert>
15904
+ const vert$3 = `#include <gl2_vert>
15703
15905
  #define SHADER_NAME SCANEFFECT
15704
15906
  precision highp float;
15705
15907
  attribute vec3 aPosition;
@@ -15812,7 +16014,7 @@ class ScanEffectPass {
15812
16014
  }
15813
16015
  const fragStr = this._createFragSource(effectInfos);
15814
16016
  this._shader = new MeshShader({
15815
- vert: vert$4,
16017
+ vert: vert$3,
15816
16018
  frag: fragStr,
15817
16019
  uniforms: [
15818
16020
  {
@@ -17141,7 +17343,13 @@ const renderToCube = function () {
17141
17343
  const aspect = 1;
17142
17344
  const near = 0.5;
17143
17345
  const far = 1.1;
17144
- const projMatrix = mat4.perspective(pmat, fov, aspect, near, far);
17346
+ const isWebGPU = !!regl.wgpu;
17347
+ let projMatrix;
17348
+ if (isWebGPU) {
17349
+ projMatrix = mat4.perspectiveZO(pmat, fov, aspect, near, far);
17350
+ } else {
17351
+ projMatrix = mat4.perspective(pmat, fov, aspect, near, far);
17352
+ }
17145
17353
 
17146
17354
  const config = {
17147
17355
  context : {
@@ -17754,7 +17962,8 @@ function createPrefilterCube(regl, fromCubeMap, SIZE, sampleSize, roughnessLevel
17754
17962
  const mipmap = createPrefilterMipmap(regl, fromCubeMap, SIZE, sampleSize, roughnessLevels, isHDR);
17755
17963
  // debugger
17756
17964
  const prefilterMap = regl.cube({
17757
- radius: SIZE,
17965
+ width: SIZE,
17966
+ height: SIZE,
17758
17967
  min: 'linear',
17759
17968
  mag: 'linear',
17760
17969
  type: isHDR ? 'float16' : 'uint8',
@@ -18060,13 +18269,13 @@ class StandardMaterial extends Material {
18060
18269
  class StandardSpecularGlossinessMaterial extends SpecularGlossinessMixin(StandardMaterial) {
18061
18270
  }
18062
18271
 
18063
- var vert$3 = "#include <gl2_vert>\n#define SHADER_NAME PBR\nattribute vec3 aPosition;\n#if defined(HAS_MAP) || defined(HAS_TERRAIN_FLAT_MASK)\nattribute vec2 aTexCoord;\n#include <common_pack_float>\n#endif\n#if defined(HAS_MAP)\nuniform vec2 uvOrigin;\nuniform vec2 uvScale;\nuniform vec2 uvOffset;\nuniform float uvRotation;\n#ifdef HAS_I3S_UVREGION\nattribute vec4 uvRegion;\nvarying vec4 vUvRegion;\n#endif\n#if defined(HAS_AO_MAP)\nattribute vec2 aTexCoord1;\nvarying vec2 vTexCoord1;\n#endif\n#endif\nvec3 c;\nvec3 d;\nvec4 e;\nuniform mat4 modelMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 positionMatrix;\nuniform mat4 projMatrix;\nuniform mediump vec3 cameraPosition;\nuniform mat3 modelNormalMatrix;\n#ifdef HAS_SSR\nuniform mat3 modelViewNormalMatrix;\nvarying vec3 vViewNormal;\n#ifdef HAS_TANGENT\nvarying vec4 vViewTangent;\n#endif\n#endif\nvarying vec3 vModelNormal;\nvarying vec4 vViewVertex;\n#if defined(HAS_TANGENT)\nvarying vec4 vModelTangent;\nvarying vec3 vModelBiTangent;\n#endif\nvarying vec3 vModelVertex;\n#if defined(HAS_MAP)\nvarying vec2 vTexCoord;\n#endif\n#if defined(HAS_COLOR)\nattribute vec4 aColor;\nvarying vec4 vColor;\n#endif\n#ifdef HAS_OPACITY\nattribute float aOpacity;\n#endif\nvarying float vOpacity;\n#include <highlight_vert>\n#if defined(HAS_COLOR0)\n#if COLOR0_SIZE == 3\nattribute vec3 aColor0;\nvarying vec3 vColor0;\n#else\nattribute vec4 aColor0;\nvarying vec4 vColor0;\n#endif\n#endif\n#include <line_extrusion_vert>\n#include <get_output>\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_vert>\n#endif\n#include <heatmap_render_vert>\n#include <vertex_color_vert>\n#if defined(HAS_BUMP_MAP) && defined(HAS_TANGENT)\nvarying vec3 vTangentViewPos;\nvarying vec3 vTangentFragPos;\n#if __VERSION__ == 100\nmat3 f(in mat3 h) {\n vec3 i = h[0];\n vec3 j = h[1];\n vec3 k = h[2];\n return mat3(vec3(i.x, j.x, k.x), vec3(i.y, j.y, k.y), vec3(i.z, j.z, k.z));\n}\n#else\nmat3 f(in mat3 h) {\n return transpose(h);\n}\n#endif\n#endif\nvoid l(const highp vec4 q, out highp vec3 m) {\n m = vec3(.0, .0, 1.) + vec3(2., -2., -2.) * q.x * q.zwx + vec3(2., 2., -2.) * q.y * q.wzy;\n}\nvoid l(const highp vec4 q, out highp vec3 m, out highp vec3 t) {\n l(q, m);\n t = vec3(1., .0, .0) + vec3(-2., 2., -2.) * q.y * q.yxw + vec3(-2., 2., 2.) * q.z * q.zwx;\n}\nconst float o = .5;\nvec2 u(vec2 v, float A) {\n return vec2(cos(A) * (v.x - o) + sin(A) * (v.y - o) + o, cos(A) * (v.y - o) - sin(A) * (v.x - o) + o);\n}\n#if defined(HAS_MAP)\nvec2 B(vec2 v) {\n vec2 C = decode_getTexcoord(v);\n#ifdef HAS_RANDOM_TEX\nvec2 D = uvOrigin;\n vec2 E = C * uvScale + uvOffset;\n return mod(D, 1.) + E;\n#else\nvec2 D = uvOrigin;\n vec2 E = C * uvScale;\n if(uvRotation != .0) {\n D = u(D, uvRotation);\n E = u(E, uvRotation);\n }\n return mod(D, 1.) + E + uvOffset;\n#endif\n}\n#endif\n#ifdef PICKING_MODE\n#include <fbo_picking_vert>\n#endif\n#include <excavate_vert>\nvoid main() {\n mat4 F = getPositionMatrix();\n#ifdef IS_LINE_EXTRUSION\nvec3 G = getLineExtrudePosition(aPosition);\n vec4 H = getPosition(G);\n#else\nvec4 H = getPosition(aPosition);\n#endif\nvModelVertex = (modelMatrix * H).xyz;\n vec4 I = F * H;\n vec4 J = modelViewMatrix * I;\n vViewVertex = J;\n#ifdef HAS_MASK_EXTENT\ngl_Position = projMatrix * getMaskPosition(I, modelMatrix);\n#else\ngl_Position = projMatrix * J;\n#endif\n#ifdef PICKING_MODE\nfloat K = 1.;\n#if defined(HAS_COLOR)\nK *= aColor.a;\n#endif\n#if defined(HAS_COLOR0) && COLOR0_SIZE == 4\nK *= aColor0.a;\n#endif\nfbo_picking_setData(gl_Position.w, K != .0);\n#else\n#if defined(HAS_MAP)\nvTexCoord = B(aTexCoord);\n#ifdef HAS_AO_MAP\nvTexCoord1 = B(aTexCoord1);\n#endif\n#ifdef HAS_I3S_UVREGION\nvUvRegion = uvRegion / 65535.;\n#endif\n#endif\n#if defined(HAS_TANGENT) || defined(HAS_NORMAL)\nmat3 L = mat3(F);\n mat3 M = modelNormalMatrix * L;\n#if defined(HAS_TANGENT)\nvec3 t;\n l(aTangent, d, t);\n vModelTangent = vec4(M * t, aTangent.w);\n#else\nd = decode_getNormal(aNormal);\n#endif\nvec3 N = d;\n vModelNormal = M * N;\n#else\nd = vec3(.0);\n vModelNormal = vec3(.0);\n#endif\n#if defined(HAS_TANGENT)\nvModelBiTangent = cross(vModelNormal, vModelTangent.xyz) * sign(aTangent.w);\n#endif\n#ifdef HAS_SSR\nmat3 O = modelViewNormalMatrix * L;\n vViewNormal = O * d;\n#if defined(HAS_TANGENT)\nvec4 P = vec4(t, aTangent.w);\n vViewTangent = vec4(O * P.xyz, P.w);\n#endif\n#endif\n#if defined(HAS_COLOR)\nvColor = aColor / 255.;\n#endif\n#ifdef HAS_OPACITY\nvOpacity = aOpacity / 255.;\n#else\nvOpacity = 1.;\n#endif\nhighlight_setVarying();\n#if defined(HAS_COLOR0)\nvColor0 = aColor0 / 255.;\n#endif\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nshadow_computeShadowPars(I);\n#endif\n#ifdef HAS_HEATMAP\nheatmap_compute(projMatrix * modelViewMatrix * F, H);\n#endif\n#if defined(HAS_BUMP_MAP) && defined(HAS_TANGENT)\nmat3 Q = f(mat3(vModelTangent.xyz, vModelBiTangent, vModelNormal));\n vTangentViewPos = Q * cameraPosition;\n vTangentFragPos = Q * vModelVertex;\n#endif\n#ifdef HAS_VERTEX_COLOR\nvertexColor_update();\n#endif\n#ifdef HAS_EXCAVATE_ANALYSIS\nvCoordinateTexcoord = getCoordinateTexcoord(I);\n vExcavateHeight = getWorldHeight(I);\n#endif\n#endif\n}";
18272
+ var vert$2 = "#include <gl2_vert>\n#define SHADER_NAME PBR\nattribute vec3 aPosition;\n#if defined(HAS_MAP) || defined(HAS_TERRAIN_FLAT_MASK)\nattribute vec2 aTexCoord;\n#include <common_pack_float>\n#endif\n#if defined(HAS_MAP)\nuniform vec2 uvOrigin;\nuniform vec2 uvScale;\nuniform vec2 uvOffset;\nuniform float uvRotation;\n#ifdef HAS_I3S_UVREGION\nattribute vec4 uvRegion;\nvarying vec4 vUvRegion;\n#endif\n#if defined(HAS_AO_MAP)\nattribute vec2 aTexCoord1;\nvarying vec2 vTexCoord1;\n#endif\n#endif\nvec3 c;\nvec3 d;\nvec4 e;\nuniform mat4 modelMatrix;\nuniform mat4 modelViewMatrix;\nuniform mat4 positionMatrix;\nuniform mat4 projMatrix;\nuniform mediump vec3 cameraPosition;\nuniform mat3 modelNormalMatrix;\n#ifdef HAS_SSR\nuniform mat3 modelViewNormalMatrix;\nvarying vec3 vViewNormal;\n#ifdef HAS_TANGENT\nvarying vec4 vViewTangent;\n#endif\n#endif\nvarying vec3 vModelNormal;\nvarying vec4 vViewVertex;\n#if defined(HAS_TANGENT)\nvarying vec4 vModelTangent;\nvarying vec3 vModelBiTangent;\n#endif\nvarying vec3 vModelVertex;\n#if defined(HAS_MAP)\nvarying vec2 vTexCoord;\n#endif\n#if defined(HAS_COLOR)\nattribute vec4 aColor;\nvarying vec4 vColor;\n#endif\n#ifdef HAS_OPACITY\nattribute float aOpacity;\n#endif\nvarying float vOpacity;\n#include <highlight_vert>\n#if defined(HAS_COLOR0)\n#if COLOR0_SIZE == 3\nattribute vec3 aColor0;\nvarying vec3 vColor0;\n#else\nattribute vec4 aColor0;\nvarying vec4 vColor0;\n#endif\n#endif\n#include <line_extrusion_vert>\n#include <get_output>\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_vert>\n#endif\n#include <heatmap_render_vert>\n#include <vertex_color_vert>\n#if defined(HAS_BUMP_MAP) && defined(HAS_TANGENT)\nvarying vec3 vTangentViewPos;\nvarying vec3 vTangentFragPos;\n#if __VERSION__ == 100\nmat3 f(in mat3 h) {\n vec3 i = h[0];\n vec3 j = h[1];\n vec3 k = h[2];\n return mat3(vec3(i.x, j.x, k.x), vec3(i.y, j.y, k.y), vec3(i.z, j.z, k.z));\n}\n#else\nmat3 f(in mat3 h) {\n return transpose(h);\n}\n#endif\n#endif\nvoid l(const highp vec4 q, out highp vec3 m) {\n m = vec3(.0, .0, 1.) + vec3(2., -2., -2.) * q.x * q.zwx + vec3(2., 2., -2.) * q.y * q.wzy;\n}\nvoid l(const highp vec4 q, out highp vec3 m, out highp vec3 t) {\n l(q, m);\n t = vec3(1., .0, .0) + vec3(-2., 2., -2.) * q.y * q.yxw + vec3(-2., 2., 2.) * q.z * q.zwx;\n}\nconst float o = .5;\nvec2 u(vec2 v, float A) {\n return vec2(cos(A) * (v.x - o) + sin(A) * (v.y - o) + o, cos(A) * (v.y - o) - sin(A) * (v.x - o) + o);\n}\n#if defined(HAS_MAP)\nvec2 B(vec2 v) {\n vec2 C = decode_getTexcoord(v);\n#ifdef HAS_RANDOM_TEX\nvec2 D = uvOrigin;\n vec2 E = C * uvScale + uvOffset;\n return mod(D, 1.) + E;\n#else\nvec2 D = uvOrigin;\n vec2 E = C * uvScale;\n if(uvRotation != .0) {\n D = u(D, uvRotation);\n E = u(E, uvRotation);\n }\n return mod(D, 1.) + E + uvOffset;\n#endif\n}\n#endif\n#ifdef PICKING_MODE\n#include <fbo_picking_vert>\n#endif\n#include <excavate_vert>\nvoid main() {\n mat4 F = getPositionMatrix();\n#ifdef IS_LINE_EXTRUSION\nvec3 G = getLineExtrudePosition(aPosition);\n vec4 H = getPosition(G);\n#else\nvec4 H = getPosition(aPosition);\n#endif\nvModelVertex = (modelMatrix * H).xyz;\n vec4 I = F * H;\n vec4 J = modelViewMatrix * I;\n vViewVertex = J;\n#ifdef HAS_MASK_EXTENT\ngl_Position = projMatrix * getMaskPosition(I, modelMatrix);\n#else\ngl_Position = projMatrix * J;\n#endif\n#ifdef PICKING_MODE\nfloat K = 1.;\n#if defined(HAS_COLOR)\nK *= aColor.a;\n#endif\n#if defined(HAS_COLOR0) && COLOR0_SIZE == 4\nK *= aColor0.a;\n#endif\nfbo_picking_setData(gl_Position.w, K != .0);\n#else\n#if defined(HAS_MAP)\nvTexCoord = B(aTexCoord);\n#ifdef HAS_AO_MAP\nvTexCoord1 = B(aTexCoord1);\n#endif\n#ifdef HAS_I3S_UVREGION\nvUvRegion = uvRegion / 65535.;\n#endif\n#endif\n#if defined(HAS_TANGENT) || defined(HAS_NORMAL)\nmat3 L = mat3(F);\n mat3 M = modelNormalMatrix * L;\n#if defined(HAS_TANGENT)\nvec3 t;\n l(aTangent, d, t);\n vModelTangent = vec4(M * t, aTangent.w);\n#else\nd = decode_getNormal(aNormal);\n#endif\nvec3 N = d;\n vModelNormal = M * N;\n#else\nd = vec3(.0);\n vModelNormal = vec3(.0);\n#endif\n#if defined(HAS_TANGENT)\nvModelBiTangent = cross(vModelNormal, vModelTangent.xyz) * sign(aTangent.w);\n#endif\n#ifdef HAS_SSR\nmat3 O = modelViewNormalMatrix * L;\n vViewNormal = O * d;\n#if defined(HAS_TANGENT)\nvec4 P = vec4(t, aTangent.w);\n vViewTangent = vec4(O * P.xyz, P.w);\n#endif\n#endif\n#if defined(HAS_COLOR)\nvColor = aColor / 255.;\n#endif\n#ifdef HAS_OPACITY\nvOpacity = aOpacity / 255.;\n#else\nvOpacity = 1.;\n#endif\nhighlight_setVarying();\n#if defined(HAS_COLOR0)\nvColor0 = aColor0 / 255.;\n#endif\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nshadow_computeShadowPars(I);\n#endif\n#ifdef HAS_HEATMAP\nheatmap_compute(projMatrix * modelViewMatrix * F, H);\n#endif\n#if defined(HAS_BUMP_MAP) && defined(HAS_TANGENT)\nmat3 Q = f(mat3(vModelTangent.xyz, vModelBiTangent, vModelNormal));\n vTangentViewPos = Q * cameraPosition;\n vTangentFragPos = Q * vModelVertex;\n#endif\n#ifdef HAS_VERTEX_COLOR\nvertexColor_update();\n#endif\n#ifdef HAS_EXCAVATE_ANALYSIS\nvCoordinateTexcoord = getCoordinateTexcoord(I);\n vExcavateHeight = getWorldHeight(I);\n#endif\n#endif\n}";
18064
18273
 
18065
18274
  var frag$4 = "#define PI 3.141593\n#define RECIPROCAL_PI 1.0\n#if __VERSION__ == 100\n#if defined(GL_EXT_shader_texture_lod)\n#extension GL_EXT_shader_texture_lod : enable\n#define textureCubeLod(tex, uv, lod) textureCubeLodEXT(tex, uv, lod)\n#else\n#define textureCubeLod(tex, uv, lod) textureCube(tex, uv, lod)\n#endif\n#if defined(GL_OES_standard_derivatives)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#else\n#define textureCubeLod(tex, uv, lod) textureLod(tex, uv, lod)\n#endif\n#define saturate(x) clamp(x, 0.0, 1.0)\nprecision mediump float;\n#include <gl2_frag>\n#include <hsv_frag>\n#include <srgb_frag>\nuniform vec3 hsv;\nuniform float contrast;\nstruct MaterialUniforms {\n vec2 roughnessMetalness;\n vec3 albedo;\n float alpha;\n vec3 normal;\n vec3 emit;\n float ao;\n vec3 specularColor;\n float glossiness;\n vec4 skinColor;\n} c;\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_frag>\n#endif\nuniform vec3 cameraPosition;\nuniform float alphaTest;\n#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)\nuniform vec4 diffuseFactor;\nuniform vec3 specularFactor;\nuniform float glossinessFactor;\n#if defined(HAS_DIFFUSE_MAP)\nuniform sampler2D diffuseTexture;\n#endif\n#if defined(HAS_SPECULARGLOSSINESS_MAP)\nuniform sampler2D specularGlossinessTexture;\n#endif\n#endif\nuniform vec3 emissiveFactor;\nuniform vec4 baseColorFactor;\nuniform float baseColorIntensity;\nuniform float emitColorFactor;\nuniform float occlusionFactor;\nuniform float environmentExposure;\nuniform float roughnessFactor;\nuniform float metallicFactor;\nuniform float normalMapFactor;\nuniform float specularF0;\nuniform int emitMultiplicative;\nuniform int normalMapFlipY;\nuniform int outputSRGB;\nuniform mat3 environmentTransform;\n#if defined(HAS_ALBEDO_MAP)\nuniform sampler2D baseColorTexture;\n#endif\n#if defined(HAS_METALLICROUGHNESS_MAP)\nuniform sampler2D metallicRoughnessTexture;\n#endif\n#if defined(HAS_EMISSIVE_MAP)\nuniform sampler2D emissiveTexture;\n#endif\n#if defined(HAS_AO_MAP)\nuniform sampler2D occlusionTexture;\nvarying vec2 vTexCoord1;\n#endif\n#if defined(HAS_NORMAL_MAP) && defined(HAS_TANGENT)\nuniform sampler2D normalTexture;\n#endif\n#if defined(HAS_SKIN_MAP)\nuniform sampler2D skinTexture;\n#endif\n#if defined(ALPHA_MODE) && ALPHA_MODE == 1\nuniform float alphaCutoff;\n#endif\n#ifdef HAS_RANDOM_TEX\nuniform highp vec2 uvOrigin;\nuniform sampler2D noiseTexture;\n#endif\nuniform sampler2D brdfLUT;\n#if defined(HAS_IBL_LIGHTING)\nuniform vec3 hdrHSV;\nuniform samplerCube prefilterMap;\nuniform vec3 diffuseSPH[9];\nuniform vec2 prefilterMiplevel;\nuniform vec2 prefilterSize;\n#else\nuniform vec3 ambientColor;\n#endif\nuniform vec2 cameraNearFar;\nuniform vec3 light0_viewDirection;\nuniform vec4 light0_diffuse;\n#ifdef HAS_SSR\nvarying vec3 vViewNormal;\n#if defined(HAS_TANGENT)\nvarying vec4 vViewTangent;\n#endif\n#endif\nvarying vec3 vModelVertex;\nvarying vec4 vViewVertex;\n#if defined(HAS_MAP)\n#include <compute_texcoord_frag>\n#endif\nvarying vec3 vModelNormal;\n#if defined(HAS_TANGENT)\nvarying vec4 vModelTangent;\nvarying vec3 vModelBiTangent;\n#endif\n#if defined(HAS_COLOR0)\n#if COLOR0_SIZE == 3\nvarying vec3 vColor0;\n#else\nvarying vec4 vColor0;\n#endif\n#endif\n#if defined(HAS_COLOR)\nvarying vec4 vColor;\n#elif defined(IS_LINE_EXTRUSION)\nuniform vec4 lineColor;\n#else\nuniform vec4 polygonFill;\n#endif\n#ifdef HAS_LAYER_OPACITY\nuniform float layerOpacity;\n#endif\nvarying float vOpacity;\n#ifdef HAS_INSTANCE_COLOR\nvarying vec4 vInstanceColor;\n#endif\n#ifdef IS_LINE_EXTRUSION\nuniform float lineOpacity;\n#else\nuniform float polygonOpacity;\n#endif\n#ifdef HAS_PATTERN\nuniform sampler2D linePatternFile;\nuniform vec2 atlasSize;\nuniform float flipY;\nuniform float currentTime;\nuniform float animSpeedScale;\n#ifdef HAS_PATTERN_ANIM\nvarying float vLinePatternAnimSpeed;\n#else\nuniform float linePatternAnimSpeed;\n#endif\n#ifdef HAS_PATTERN_GAP\nvarying float vLinePatternGap;\n#else\nuniform float linePatternGap;\n#endif\nuniform vec4 linePatternGapColor;\nuniform vec2 uvScale;\nvarying float vPatternHeight;\nvarying float vLinesofar;\nvarying vec4 vTexInfo;\nvarying float vNormalY;\nvec2 d(vec2 e) {\n vec2 f = mod(e, 1.);\n vec2 h = vTexInfo.xy;\n vec2 i = vTexInfo.zw;\n return (h + f * i) / atlasSize;\n}\n#endif\n#include <heatmap_render_frag>\n#include <snow_frag>\n#include <mask_frag>\n#include <terrain_normal_frag>\n#include <vertex_color_frag>\n#include <excavate_frag>\n#ifdef HAS_RANDOM_TEX\nconst float j = .5;\nvec2 k(vec2 f, float l) {\n return vec2(cos(l) * (f.x - j) + sin(l) * (f.y - j) + j, cos(l) * (f.y - j) - sin(l) * (f.x - j) + j);\n}\nfloat m(vec3 n) {\n return n.x + n.y + n.z;\n}\n#endif\nvec4 o(sampler2D u, in vec2 f) {\n \n#ifdef HAS_RANDOM_TEX\nhighp vec2 A = uvOrigin;\n highp vec2 B = f + A - mod(A, 1.);\n float C = texture2D(noiseTexture, .005 * B).x;\n vec2 D = dFdx(B);\n vec2 E = dFdx(B);\n float F = C * 8.;\n float G = fract(F);\n#if 1\nfloat H = floor(F);\n float I = H + 1.;\n#else\nfloat H = floor(F + .5);\n float I = floor(F);\n G = min(G, 1. - G) * 2.;\n#endif\nvec2 J = sin(vec2(3., 7.) * H);\n vec2 K = sin(vec2(3., 7.) * I);\n float L = .5;\n vec4 M = texture2DGradEXT(u, f + L * J, D, E);\n vec4 N = texture2DGradEXT(u, f + L * K, D, E);\n return mix(M, N, smoothstep(.2, .8, G - .1 * m(M.xyz - N.xyz)));\n#else\nreturn texture2D(u, f);\n#endif\n}\n#if defined(HAS_BUMP_MAP) && defined(HAS_TANGENT)\nuniform sampler2D bumpTexture;\nuniform float bumpScale;\nuniform float bumpMaxLayers;\nuniform float bumpMinLayers;\nvec2 O(vec2 f, vec3 P) {\n float Q = mix(bumpMaxLayers, bumpMinLayers, abs(dot(vec3(.0, .0, 1.), P)));\n float R = 1. / Q;\n float S = .0;\n vec2 T = P.xy * bumpScale / (P.z * Q);\n vec2 U = f;\n float V = o(bumpTexture, U).r;\n for(int W = 0; W < 30; W++) {\n S += R;\n U -= T;\n V = o(bumpTexture, U).r;\n if(V < S) {\n break;\n }\n }\n vec2 X = U + T;\n float Y = V - S;\n float Z = o(bumpTexture, X).r - S + R;\n return mix(U, X, Y / (Y - Z));\n}\nvarying vec3 vTangentViewPos;\nvarying vec3 vTangentFragPos;\n#endif\n#define SHADER_NAME PBR\nvec3 ba() {\n return c.albedo;\n}\nfloat bb() {\n return c.alpha;\n}\nfloat bc() {\n return c.roughnessMetalness.y;\n}\nfloat bd() {\n \n#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)\nreturn 1. - c.glossiness;\n#else\nreturn c.roughnessMetalness.x;\n#endif\n}\nvec3 be() {\n return c.emit;\n}\nvec4 bf() {\n return c.skinColor;\n}\nvec3 bg() {\n return c.normal;\n}\nfloat bh() {\n return c.ao;\n}\nfloat bi(const in vec4 bj) {\n return bj.r + bj.g / 255.;\n}\nvec3 bk(const in float bl, in vec3 bm, const in vec3 t, const in vec3 b, in vec3 bn) {\n bm.xy = bl * bm.xy;\n mat3 bo = mat3(t, b, bn);\n return normalize(bo * bm);\n}\nfloat bp(const float bq, const vec3 bm, const vec3 br) {\n float bs = clamp(dot(bm, br), 0., 1.);\n float a = bq * bq;\n float bt = a * a;\n float bu = (bs * bt - bs) * bs + 1.;\n return bt / (PI * bu * bu);\n}\nvec3 bv(const vec3 bw, const float bx, const in vec3 by, const in vec3 br) {\n float bz = clamp(dot(by, br), 0., 1.);\n bz = pow(1. - bz, 5.);\n return bx * bz + (1. - bz) * bw;\n}\nfloat bA(const in vec3 bm, const in vec3 bB, const in float bq, const float bC) {\n float bD = clamp(dot(bm, bB), 0., 1.);\n float a = bq * bq;\n float bE = bD * (bC * (1. - a) + a);\n float bF = bC * (bD * (1. - a) + a);\n return .5 / (bF + bE);\n}\nvec3 bG(const float bq, const vec3 bm, const vec3 bB, const vec3 by, const vec3 bH, const float bC, const float bx) {\n vec3 br = normalize(bB + by);\n float bI = bp(bq, bm, br);\n float bJ = bA(bm, bB, bq, bC);\n vec3 bK = bv(bH, bx, by, br);\n return (bI * bJ * PI) * bK;\n}\nvec3 bL(const in vec3 bM) {\n return RECIPROCAL_PI * bM;\n}\nvoid bN(const in vec3 bm, const in vec3 bB, const in float bC, const in float bq, const in vec3 bO, const in vec3 bH, const in vec3 bP, const in vec3 by, const in float bx, out vec3 bQ, out vec3 bR) {\n if(bC <= .0) {\n bR = bQ = vec3(.0);\n return;\n }\n vec3 a = bC * bP;\n vec3 bS = bG(bq, bm, bB, by, bH, bC, bx);\n bR = a * bS;\n bQ = a * bL(bO);\n}\n#if defined(HAS_IBL_LIGHTING)\nvec3 bT(const in vec3 bm) {\n vec3 bn = environmentTransform * bm;\n float x = bn.x;\n float y = bn.y;\n float z = bn.z;\n vec3 bU = (diffuseSPH[0] + diffuseSPH[1] * x + diffuseSPH[2] * y + diffuseSPH[3] * z + diffuseSPH[4] * z * x + diffuseSPH[5] * y * z + diffuseSPH[6] * y * x + diffuseSPH[7] * (3. * z * z - 1.) + diffuseSPH[8] * (x * x - y * y));\n if(length(hdrHSV) > .0) {\n bU = hsv_apply(bU, hdrHSV);\n }\n return max(bU, vec3(.0));\n}\nvec3 bV(const in float bq, const in vec3 bW) {\n vec3 bX = bW;\n float bY = prefilterMiplevel.x;\n float bZ = min(bY, bq * prefilterMiplevel.y);\n vec3 ca = textureCubeLod(prefilterMap, bX, bZ).rgb;\n if(length(hdrHSV) > .0) {\n return hsv_apply(ca, hdrHSV);\n } else {\n return ca;\n }\n}\nvec3 cb(const in vec3 cc, const in vec3 bB, const in float bq, const in vec3 cd, const in vec3 bO) {\n float ce = 1. - bq;\n vec3 bW = mix(cc, reflect(-bB, cc), ce * (sqrt(ce) + bq));\n float bl = clamp(1. + dot(bW, cd), .0, 1.);\n vec3 cf = bV(bq, environmentTransform * bW) * bl * bl;\n return cf;\n}\n#else\nvec3 cb(const in vec3 bm, const in vec3 cg, const in float bq, const in vec3 cd, const in vec3 bO) {\n return ambientColor * bL(bO);\n}\n#endif\nvec3 ch(const in vec3 ci, const in float bq, const in float bD, const in float bx) {\n vec4 rgba = texture2D(brdfLUT, vec2(bD, bq)) * vec4(255., 65280.0, 255., 65280.0);\n float b = (rgba[3] + rgba[2]);\n float a = (rgba[1] + rgba[0]);\n return (ci * a + b * bx) / 65535.;\n}\nvec3 cj(const in vec3 bm, const in vec3 cg, const in float bD, const in float bq, const in vec3 bH, const in vec3 cd, const in float bx, const in vec3 bO) {\n return cb(bm, cg, bq, cd, bO) * ch(bH, bq, bD, bx);\n}\nfloat ck(const in float cl, const in float bD) {\n float bu = bD + cl;\n return clamp(bu * bu - 1. + cl, .0, 1.);\n}\nvoid cm() {\n \n#ifdef HAS_MAP\nvec2 f = computeTexCoord(vTexCoord);\n#endif\n#ifdef HAS_UV_FLIP\nf.y = 1. - f.y;\n#endif\n#if defined(HAS_BUMP_MAP) && defined(HAS_TANGENT)\nf = O(f, normalize(vTangentViewPos - vTangentFragPos));\n#endif\nc.albedo = baseColorIntensity * baseColorFactor.rgb;\n c.alpha = baseColorFactor.a * vOpacity;\n#if defined(HAS_PATTERN)\nfloat cn = vLinesofar;\n vec2 i = vTexInfo.zw;\n#ifdef HAS_PATTERN_GAP\nfloat co = vLinePatternGap;\n#else\nfloat co = linePatternGap;\n#endif\n#ifdef HAS_PATTERN_ANIM\nfloat cp = vLinePatternAnimSpeed;\n#else\nfloat cp = linePatternAnimSpeed;\n#endif\nfloat cq = ceil(i.x * vPatternHeight / i.y);\n float cr = cq * (1. + co);\n cp /= animSpeedScale;\n cn += mod(currentTime * -cp * .2, cr);\n float cs = mod(cn / cr, 1.);\n float ct = mod(flipY * vNormalY, 1.);\n vec2 f = d(vec2(cs * (1. + co) * uvScale[0], ct * uvScale[1]));\n vec4 cu = texture2D(linePatternFile, f);\n float cv = clamp(sign(1. / (1. + co) - cs) + .000001, .0, 1.);\n cu = mix(linePatternGapColor, cu, cv);\n#ifdef IS_SQUARE_TUBE\nfloat n = clamp(sign(abs(vNormalY) - .999999), .0, 1.);\n cu = mix(cu, vec4(1.), n);\n#endif\nc.albedo *= cu.rgb;\n c.alpha *= cu.a;\n#endif\n#if defined(HAS_ALBEDO_MAP)\nvec4 cw = o(baseColorTexture, f);\n c.albedo *= sRGBToLinear(cw.rgb);\n c.alpha *= cw.a;\n#endif\n#if defined(HAS_SKIN_MAP)\nvec4 cx = o(skinTexture, f);\n c.skinColor = cx;\n#endif\n#if defined(HAS_COLOR0)\nc.albedo *= vColor0.rgb;\n#if COLOR0_SIZE == 4\nc.alpha *= vColor0.a;\n#endif\n#endif\n#if defined(HAS_COLOR)\nc.albedo *= vColor.rgb;\n c.alpha *= vColor.a;\n#elif defined(IS_LINE_EXTRUSION)\nc.albedo *= lineColor.rgb;\n c.alpha *= lineColor.a;\n#else\nc.albedo *= polygonFill.rgb;\n c.alpha *= polygonFill.a;\n#endif\n#if defined(HAS_INSTANCE_COLOR)\nc.albedo *= vInstanceColor.rgb;\n c.alpha *= vInstanceColor.a;\n#endif\n#if defined(HAS_METALLICROUGHNESS_MAP)\nc.roughnessMetalness = o(metallicRoughnessTexture, f).gb * vec2(roughnessFactor, metallicFactor);\n#else\nc.roughnessMetalness = vec2(roughnessFactor, metallicFactor);\n#endif\nc.emit = emissiveFactor;\n#if defined(HAS_EMISSIVE_MAP)\nif(emitMultiplicative == 1) {\n c.emit *= sRGBToLinear(o(emissiveTexture, f).rgb);\n } else {\n c.emit += sRGBToLinear(o(emissiveTexture, f).rgb);\n }\n#endif\nc.emit *= emitColorFactor;\n#if defined(HAS_AO_MAP)\nvec2 cy = computeTexCoord(vTexCoord1);\n c.ao = o(occlusionTexture, cy).r;\n#else\nc.ao = 1.;\n#endif\nc.ao *= occlusionFactor;\n#if defined(HAS_NORMAL_MAP) && defined(HAS_TANGENT)\nvec3 cz = o(normalTexture, f).xyz * 2. - 1.;\n cz.y = normalMapFlipY == 1 ? -cz.y : cz.y;\n c.normal = cz;\n#else\nc.normal = normalize(vModelNormal);\n#endif\n#if defined(HAS_TERRAIN_NORMAL) && defined(HAS_TANGENT)\nvec3 cz = convertTerrainHeightToNormalMap(f);\n cz.y = normalMapFlipY == 1 ? -cz.y : cz.y;\n c.normal = cz;\n#endif\n#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)\nc.albedo *= diffuseFactor.rgb;\n c.alpha *= diffuseFactor.a;\n#if defined(HAS_DIFFUSE_MAP)\nvec4 cA = o(diffuseTexture, f);\n c.albedo *= sRGBToLinear(cA.rgb);\n c.alpha *= cA.a;\n#endif\nc.specularColor = specularFactor;\n c.glossiness = glossinessFactor;\n#if defined(HAS_SPECULARGLOSSINESS_MAP)\nvec4 cB = o(specularGlossinessTexture, f);\n c.specularColor *= sRGBToLinear(cB.rgb);\n c.glossiness *= cB.a;\n#endif\n#endif\n}\nvec3 cC(const vec3 x) {\n const float a = 2.51;\n const float b = .03;\n const float cD = 2.43;\n const float bu = .59;\n const float cE = .14;\n return (x * (a * x + b)) / (x * (cD * x + bu) + cE);\n}\nvec3 cF(vec3 cG) {\n cG = cC(cG);\n return cG = pow(cG, vec3(1. / 2.2));\n}\nuniform float specularAAVariance;\nuniform float specularAAThreshold;\nfloat cH(float bq, const vec3 cI) {\n \n#if defined(GL_OES_standard_derivatives) || __VERSION__ == 300\nvec3 cJ = dFdx(cI);\n vec3 cK = dFdy(cI);\n float cL = specularAAVariance * (dot(cJ, cJ) + dot(cK, cK));\n float cM = min(2. * cL, specularAAThreshold);\n float cN = saturate(bq * bq + cM);\n return sqrt(cN);\n#else\nreturn bq;\n#endif\n}\n#ifdef HAS_SSR\nuniform sampler2D TextureDepth;\nuniform highp vec2 outSize;\nuniform float ssrFactor;\nuniform float ssrQuality;\nuniform sampler2D TextureReflected;\nuniform highp mat4 projMatrix;\nuniform mat4 invProjMatrix;\nuniform vec4 outputFovInfo[2];\nuniform mat4 reprojViewProjMatrix;\nvec3 cO(const in mat4 cP, const in vec3 cQ) {\n vec4 cR = cP * vec4(cQ, 1.);\n return vec3(.5 + .5 * cR.xy / cR.w, cR.w);\n}\nvec3 cS(const in float cT, const in vec2 f) {\n return texture2D(TextureReflected, f).rgb;\n}\nfloat cU(float cV) {\n highp mat4 cP = projMatrix;\n highp float z = cV * 2. - 1.;\n return -cP[3].z / (z + cP[2].z);\n}\nfloat cW(const vec2 f) {\n float cV = bi(texture2D(TextureDepth, f));\n return cV;\n}\nfloat cX(const in vec2 cY, const in float cZ) {\n vec3 da = vec3(.06711056, .00583715, 52.9829189);\n return fract(da.z * fract(dot(cY.xy + cZ * vec2(47., 17.) * .695, da.xy))) * .5;\n}\nvec3 db(const in float cZ, const in vec3 dc, const in vec3 dd, const in vec3 de, const in vec3 cg, const in float df) {\n vec2 dg;\n dg.x = cX(gl_FragCoord.yx, cZ);\n dg.y = fract(dg.x * 52.9829189);\n dg.y = mix(dg.y, 1., .7);\n float dh = 2. * 3.14159 * dg.x;\n float di = pow(max(dg.y, .000001), df / (2. - df));\n float dj = sqrt(1. - di * di);\n vec3 dk = vec3(dj * cos(dh), dj * sin(dh), di);\n dk = dk.x * dc + dk.y * dd + dk.z * de;\n return normalize((2. * dot(cg, dk)) * dk - cg);\n}\nfloat dl(const in float cZ) {\n return (cX(gl_FragCoord.xy, cZ) - .5);\n}\nvec3 dm(const in vec3 dn, const in float dp, const in vec3 dq) {\n vec3 dr = cO(projMatrix, vViewVertex.xyz + dq * dp);\n dr.z = 1. / dr.z;\n dr -= dn;\n float ds = min(1., .99 * (1. - dn.x) / max(1e-5, dr.x));\n float dt = min(1., .99 * (1. - dn.y) / max(1e-5, dr.y));\n float dw = min(1., .99 * dn.x / max(1e-5, -dr.x));\n float dx = min(1., .99 * dn.y / max(1e-5, -dr.y));\n return dr * min(ds, dt) * min(dw, dx);\n}\nfloat dy(const in vec3 dn, const in vec3 dr, inout float dz, inout float dA) {\n float dB = (dA + dz) * .5;\n vec3 dC = dn + dr * dB;\n float z = cW(dC.xy);\n float cV = cU(z);\n float dD = -1. / dC.z;\n dz = cV > dD ? dz : dB;\n dA = cV > dD ? dB : dA;\n return dB;\n}\nvec4 dE(const in vec3 dn, const in float dp, in float dF, const in vec3 dq, const in float bq, const in float cZ) {\n int dG = 20;\n float dH = 1. / float(dG);\n dF *= dH;\n vec3 dr = dm(dn, dp, dq);\n float dI = dH;\n vec3 dJ = vec3(.0, dI, 1.);\n vec3 dC;\n float z, cV, dD, dK, dL, dM;\n bool dN;\n float dO = 1.;\n float dB;\n for(int W = 0; W < dG; W++) {\n dC = dn + dr * dJ.y;\n z = cW(dC.xy);\n cV = cU(z);\n dD = -1. / dC.z;\n float dP = clamp(sign(.999 - z), .0, 1.);\n dK = dP * (dD - cV);\n dK *= clamp(sign(abs(dK) - dp * dH * dH), .0, 1.);\n dN = abs(dK + dF) < dF;\n dL = clamp(dJ.x / (dJ.x - dK), .0, 1.);\n dM = dN ? dJ.y + dL * dH - dH : 1.;\n dJ.z = min(dJ.z, dM);\n dJ.x = dK;\n if(dN) {\n float dz = dJ.y - dH;\n float dA = dJ.y;\n dB = dy(dn, dr, dz, dA);\n dB = dy(dn, dr, dz, dA);\n dB = dy(dn, dr, dz, dA);\n dO = dB;\n break;\n }\n dJ.y += dH;\n }\n return vec4(dn + dr * dO, 1. - dO);\n}\nvec4 dQ(in vec4 dR, const in float dS, const in vec3 dT, const in vec3 dU, const in float bq) {\n vec4 dV = mix(outputFovInfo[0], outputFovInfo[1], dR.x);\n dR.xyz = vec3(mix(dV.xy, dV.zw, dR.y), 1.) * -1. / dR.z;\n dR.xyz = (reprojViewProjMatrix * vec4(dR.xyz, 1.)).xyw;\n dR.xy /= dR.z;\n float dW = clamp(6. - 6. * max(abs(dR.x), abs(dR.y)), .0, 1.);\n dR.xy = .5 + .5 * dR.xy;\n vec3 dX = dU * cS(bq * (1. - dR.w), dR.xy);\n return vec4(mix(dT, dX, dS * dW), 1.);\n}\nvec3 ssr(const in vec3 dT, const in vec3 dU, const in float bq, const in vec3 bm, const in vec3 cg) {\n float dY = .0;\n vec4 bU = vec4(.0);\n float df = bq * bq;\n df = df * df;\n vec3 dZ = abs(bm.z) < .999 ? vec3(.0, .0, 1.) : vec3(1., .0, .0);\n vec3 dc = normalize(cross(dZ, bm));\n vec3 dd = cross(bm, dc);\n float dS = ssrFactor * clamp(-4. * dot(cg, bm) + 3.8, .0, 1.);\n dS *= clamp(4.7 - bq * 5., .0, 1.);\n vec3 dn = cO(projMatrix, vViewVertex.xyz);\n dn.z = 1. / dn.z;\n vec3 dq = db(dY, dc, dd, bm, cg, df);\n float dp = mix(cameraNearFar.y + vViewVertex.z, -vViewVertex.z - cameraNearFar.x, dq.z * .5 + .5);\n float dF = .5 * dp;\n vec4 dR;\n if(dot(dq, bm) > .001 && dS > .0) {\n dR = dE(dn, dp, dF, dq, bq, dY);\n if(dR.w > .0)\n bU += dQ(dR, dS, dT, dU, bq);\n \n }\n return bU.w > .0 ? bU.rgb / bU.w : dT;\n}\n#endif\n#include <highlight_frag>\nvec4 ea(in vec4 eb) {\n return vec4(mix(pow(eb.rgb, vec3(.41666)) * 1.055 - vec3(.055), eb.rgb * 12.92, vec3(lessThanEqual(eb.rgb, vec3(.0031308)))), eb.a);\n}\nvec4 ec(vec4 eb) {\n return (ea(eb));\n}\nvoid main() {\n cm();\n vec3 cg = normalize(cameraPosition - vModelVertex.xyz);\n#if defined(HAS_DOUBLE_SIDE)\nvec3 cd = gl_FrontFacing ? normalize(vModelNormal) : -normalize(vModelNormal);\n#else\nvec3 cd = normalize(vModelNormal);\n#endif\n#if defined(HAS_TANGENT)\nvec4 ed;\n ed = vModelTangent;\n#if defined(HAS_DOUBLE_SIDE)\ned.xyz = gl_FrontFacing ? normalize(ed.xyz) : -normalize(ed.xyz);\n#else\ned.xyz = normalize(ed.xyz);\n#endif\nvec3 ee = normalize(vModelBiTangent);\n#endif\nfloat bw = .08 * specularF0;\n float ef = bc();\n vec3 bO = ba();\n#if defined(SHADING_MODEL_SPECULAR_GLOSSINESS)\nvec3 eg = c.specularColor;\n#else\nvec3 eg = mix(vec3(bw), bO, ef);\n#endif\nbO *= 1. - ef;\n float eh = clamp(50.0 * eg.g, .0, 1.);\n float ei = bd();\n if(specularAAVariance > .0) {\n ei = cH(ei, cd);\n }\n vec3 ej = be();\n vec3 ek = bg();\n vec3 el = vec3(ek);\n#if defined(HAS_TANGENT) && (defined(HAS_NORMAL_MAP) || defined(HAS_TERRAIN_NORMAL))\nel = bk(normalMapFactor, el, ed.xyz, ee, cd);\n#endif\nvec3 cA = vec3(.0);\n vec3 bH = vec3(.0);\n#if defined(HAS_IBL_LIGHTING)\ncA = bO * bT(el) * .5;\n#else\ncA = bO * ambientColor;\n#endif\nfloat bD = dot(el, cg);\n bH = cj(el, cg, bD, ei, eg, cd, eh, bO);\n float em;\n float en = 1.;\n float eo = bh();\n cA *= environmentExposure * eo;\n#ifdef HAS_IBL_LIGHTING\nen = ck(eo, bD);\n#endif\n#ifdef HAS_SSR\nvec3 ep = normalize(gl_FrontFacing ? vViewNormal : -vViewNormal);\n vec3 eq = ep;\n#if defined(HAS_TANGENT) && (defined(HAS_NORMAL_MAP) || defined(HAS_TERRAIN_NORMAL))\nvec4 er;\n er = vViewTangent;\n er = gl_FrontFacing ? er : -er;\n er.xyz = normalize(er.xyz);\n vec3 es = normalize(cross(ep, er.xyz)) * er.w;\n eq = bk(normalMapFactor, ek, er.xyz, es, ep);\n#endif\nbH = ssr(bH, eg * en, ei, eq, -normalize(vViewVertex.xyz));\n#endif\nbH *= environmentExposure * en;\n vec3 et, eu;\n vec3 ev = vModelNormal;\n vec3 ew = -light0_viewDirection;\n float ex = saturate(dot(ew, el));\n bN(el, cg, ex, max(.045, ei), bO, eg, light0_diffuse.rgb, ew, eh, eu, et);\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nfloat ey = shadow_computeShadow();\n eu = shadow_blend(eu, ey).rgb;\n et = shadow_blend(et, ey).rgb;\n#endif\ncA += eu;\n bH += et;\n cA += ej;\n vec3 ez = bH + cA;\n if(outputSRGB == 1)\n ez = linearTosRGB(ez);\n \n#ifdef HAS_SKIN_MAP\nvec4 eA = bf();\n ez.rgb = ez.rgb * (1. - eA.a) + eA.rgb * eA.a;\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nez.rgb = shadow_blend(ez.rgb, ey).rgb;\n#endif\n#endif\nfloat eB = bb();\n if(eB < alphaTest) {\n discard;\n }\n#if defined(ALPHA_MODE)\n#if ALPHA_MODE == 1\nif(eB < alphaCutoff) {\n discard;\n } else {\n eB = 1.;\n }\n#else\neB = 1.;\n#endif\n#endif\n#if defined(IS_LINE_EXTRUSION)\neB *= lineOpacity;\n#else\neB *= polygonOpacity;\n#endif\nglFragColor = vec4(ez * eB, eB);\n#ifdef HAS_VERTEX_COLOR\nglFragColor *= vertexColor_get();\n#endif\n#ifdef HAS_EXCAVATE_ANALYSIS\nglFragColor = excavateColor(glFragColor);\n#endif\n#ifdef HAS_HEATMAP\nglFragColor = heatmap_getColor(glFragColor);\n#endif\n#ifdef HAS_SNOW\nglFragColor.rgb = snow(glFragColor, bg(), 1.);\n#endif\nif(contrast != 1.) {\n glFragColor = contrastMatrix(contrast) * glFragColor;\n }\n if(length(hsv) > .0) {\n glFragColor = hsv_apply(glFragColor, hsv);\n }\n#ifdef OUTPUT_NORMAL\nglFragColor = vec4(cd, 1.);\n#endif\nglFragColor = highlight_blendColor(glFragColor);\n#ifdef HAS_LAYER_OPACITY\nglFragColor *= layerOpacity;\n#endif\n#ifdef HAS_MASK_EXTENT\nglFragColor = setMask(glFragColor);\n#endif\n#if __VERSION__ == 100\ngl_FragColor = glFragColor;\n#endif\n}";
18066
18275
 
18067
- var wgslVert$1 = "#include <highlight_vert>\n#include <line_extrusion_vert>\n#include <get_output>\n#include <vsm_shadow_vert>\n#include <vertex_color_vert>\n#ifdef PICKING_MODE\n #include <fbo_picking_vert>\n#endif\n#include <excavate_vert>\n#include <common_pack_float>\nstruct VertexInput {\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #if HAS_MAP || HAS_TERRAIN_FLAT_MASK\n @location($i) aTexCoord: vec2f,\n #endif\n #if HAS_MAP\n #ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n #endif\n #if HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #ifdef HAS_OPACITY\n @location($i) aOpacity: u32,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n #if HAS_TANGENT || HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #else\n @location($i) aNormal: vec3f,\n #endif\n #if HAS_TANGENT\n @location($i) aTangent: vec4f,\n #endif\n #endif\n}\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n #ifdef HAS_SSR\n @location($o) vViewNormal: vec3f,\n #ifdef HAS_TANGENT\n @location($o) vViewTangent: vec4f,\n #endif\n #endif\n @location($o) vModelNormal: vec3f,\n @location($o) vViewVertex: vec4f,\n #if HAS_TANGENT\n @location($o) vModelTangent: vec4f,\n @location($o) vModelBiTangent: vec3f,\n #endif\n @location($o) vModelVertex: vec3f,\n #if HAS_MAP\n @location($o) vTexCoord: vec2f,\n #ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n #endif\n #ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n #endif\n #endif\n #if HAS_COLOR\n @location($o) vColor: vec4f,\n #endif\n @location($o) vOpacity: f32,\n #if HAS_COLOR0\n @location($o) vColor0: vec4f,\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n @location($o) vTangentViewPos: vec3f,\n @location($o) vTangentFragPos: vec3f,\n #endif\n}\nstruct ShaderUniforms {\n cameraPosition: vec3f,\n projMatrix: mat4x4f,\n}\nstruct Uniforms {\n uvOrigin: vec2f,\n uvScale: vec2f,\n uvOffset: vec2f,\n uvRotation: f32,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelNormalMatrix: mat3x3f,\n #ifdef HAS_SSR\n modelViewNormalMatrix: mat3x3f,\n #endif\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nvar<private> Vertex: vec3f;\nvar<private> Normal: vec3f;\nvar<private> Tangent: vec4f;\nconst mid = 0.5;\nfn toTangentFrame(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nstruct TangentFrame {\n n: vec3f,\n t: vec3f\n}\nfn toTangentFrameWithTangent(q: vec4f) -> TangentFrame {\n var out: TangentFrame;\n out.n = toTangentFrame(q);\n out.t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n return out;\n}\nfn rotateUV(uv: vec2f, rotation: f32) -> vec2f {\n return vec2f(\n cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,\n cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid\n );\n}\n#if HAS_MAP\nfn transformTexcoord(uv: vec2f) -> vec2f {\n let decodedTexCoord = decode_getTexcoord(uv);\n #ifdef HAS_RANDOM_TEX\n let origin = uniforms.uvOrigin;\n let texCoord = decodedTexCoord * uniforms.uvScale + uniforms.uvOffset;\n return (origin % 1.0) + texCoord;\n #else\n var origin = uniforms.uvOrigin;\n var texCoord = decodedTexCoord * uniforms.uvScale;\n if (uniforms.uvRotation != 0.0) {\n origin = rotateUV(origin, uniforms.uvRotation);\n texCoord = rotateUV(texCoord, uniforms.uvRotation);\n }\n return (origin % 1.0) + texCoord + uniforms.uvOffset;\n #endif\n}\n#endif\nfn transposeMat3(inMat: mat3x3f) -> mat3x3f {\n let i0 = inMat[0];\n let i1 = inMat[1];\n let i2 = inMat[2];\n return mat3x3f(\n vec3f(i0.x, i1.x, i2.x),\n vec3f(i0.y, i1.y, i2.y),\n vec3f(i0.z, i1.z, i2.z)\n );\n}\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(input, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(input.aPosition.xyz), input);\n let localVertex = getPosition(linePosition, input);\n #else\n let localVertex = getPosition(vec3f(input.aPosition.xyz), input);\n #endif\n output.vModelVertex = (uniforms.modelMatrix * localVertex).xyz;\n let position = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelViewMatrix * position;\n output.vViewVertex = viewVertex;\n #ifdef HAS_MASK_EXTENT\n output.position = shaderUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = shaderUniforms.projMatrix * viewVertex;\n #endif\n #ifdef PICKING_MODE\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= f32(input.aColor.a);\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= f32(input.aColor0.a);\n #endif\n fbo_picking_setData(vertex, &output, output.position.w, alpha != 0.0);\n #else\n #if HAS_MAP\n output.vTexCoord = transformTexcoord(input.aTexCoord);\n #ifdef HAS_AO_MAP\n output.vTexCoord1 = transformTexcoord(input.aTexCoord1);\n #endif\n #ifdef HAS_I3S_UVREGION\n output.vUvRegion = input.uvRegion / 65535.0;\n #endif\n #endif\n #if HAS_TANGENT || HAS_NORMAL\n let positionNormalMatrix = mat3x3f(\n localPositionMatrix[0].xyz,\n localPositionMatrix[1].xyz,\n localPositionMatrix[2].xyz\n );\n let normalMatrix = uniforms.modelNormalMatrix * positionNormalMatrix;\n #if HAS_TANGENT\n let tangentFrame = toTangentFrameWithTangent(input.aTangent);\n Normal = tangentFrame.n;\n let t = tangentFrame.t;\n output.vModelTangent = vec4f(normalMatrix * t, input.aTangent.w);\n #else\n Normal = decode_getNormal(vec3f(input.aNormal.xyz));\n #endif\n let localNormal = Normal;\n output.vModelNormal = normalMatrix * localNormal;\n #else\n Normal = vec3f(0);\n output.vModelNormal = vec3f(0);\n #endif\n #if HAS_TANGENT\n output.vModelBiTangent = cross(output.vModelNormal, output.vModelTangent.xyz) * sign(input.aTangent.w);\n #endif\n #ifdef HAS_SSR\n let ssrNormalMatrix = uniforms.modelViewNormalMatrix * positionNormalMatrix;\n output.vViewNormal = ssrNormalMatrix * Normal;\n #if HAS_TANGENT\n let localTangent = vec4f(t, input.aTangent.w);\n output.vViewTangent = vec4f(ssrNormalMatrix * localTangent.xyz, localTangent.w);\n #endif\n #endif\n #if HAS_COLOR\n output.vColor = vec4f(input.aColor) / 255.0;\n #endif\n #ifdef HAS_OPACITY\n output.vOpacity = f32(input.aOpacity) / 255.0;\n #else\n output.vOpacity = 1.0;\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(input, &output);\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n output.vColor0 = vec4f(vec3f(input.aColor0), 255.0) / 255.0;\n #else\n output.vColor0 = vec4f(input.aColor0) / 255.0;\n #endif\n #endif\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &output);\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n let TBN = transposeMat3(mat3x3f(output.vModelTangent.xyz, output.vModelBiTangent, output.vModelNormal));\n output.vTangentViewPos = TBN * shaderUniforms.cameraPosition;\n output.vTangentFragPos = TBN * output.vModelVertex;\n #endif\n #ifdef HAS_VERTEX_COLOR\n vertexColor_update(input, &output);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n output.vCoordinateTexcoord = getCoordinateTexcoord(position, uniforms.modelMatrix);\n output.vExcavateHeight = getWorldHeight(position, uniforms.modelMatrix);\n #endif\n #endif\n return output;\n}";
18276
+ var wgslVert$1 = "#include <highlight_vert>\n#include <line_extrusion_vert>\n#include <get_output>\n#include <vsm_shadow_vert>\n#include <vertex_color_vert>\n#ifdef PICKING_MODE\n #include <fbo_picking_vert>\n#endif\n#include <excavate_vert>\n#include <common_pack_float>\nstruct VertexInput {\n #ifdef POSITION_IS_INT\n @location($i) aPosition: vec4i,\n #else\n @location($i) aPosition: vec3f,\n #endif\n #if HAS_MAP || HAS_TERRAIN_FLAT_MASK\n @location($i) aTexCoord: vec2f,\n #endif\n #if HAS_MAP\n #ifdef HAS_I3S_UVREGION\n @location($i) uvRegion: vec4f,\n #endif\n #if HAS_AO_MAP\n @location($i) aTexCoord1: vec2f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) aColor: vec4u,\n #endif\n #ifdef HAS_OPACITY\n @location($i) aOpacity: u32,\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n @location($i) aColor0: vec3u,\n #else\n @location($i) aColor0: vec4u,\n #endif\n #endif\n #if HAS_TANGENT\n @location($i) aTangent: vec4f,\n #elif HAS_NORMAL\n #ifdef NORMAL_IS_INT\n @location($i) aNormal: vec4i,\n #else\n @location($i) aNormal: vec3f,\n #endif\n #endif\n}\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n #ifdef HAS_SSR\n @location($o) vViewNormal: vec3f,\n #ifdef HAS_TANGENT\n @location($o) vViewTangent: vec4f,\n #endif\n #endif\n @location($o) vModelNormal: vec3f,\n @location($o) vViewVertex: vec4f,\n #if HAS_TANGENT\n @location($o) vModelTangent: vec4f,\n @location($o) vModelBiTangent: vec3f,\n #endif\n @location($o) vModelVertex: vec3f,\n #if HAS_MAP\n @location($o) vTexCoord: vec2f,\n #ifdef HAS_AO_MAP\n @location($o) vTexCoord1: vec2f,\n #endif\n #ifdef HAS_I3S_UVREGION\n @location($o) vUvRegion: vec4f,\n #endif\n #endif\n #if HAS_COLOR\n @location($o) vColor: vec4f,\n #endif\n @location($o) vOpacity: f32,\n #if HAS_COLOR0\n @location($o) vColor0: vec4f,\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n @location($o) vTangentViewPos: vec3f,\n @location($o) vTangentFragPos: vec3f,\n #endif\n}\nstruct ShaderUniforms {\n cameraPosition: vec3f,\n projMatrix: mat4x4f,\n}\nstruct Uniforms {\n uvOrigin: vec2f,\n uvScale: vec2f,\n uvOffset: vec2f,\n uvRotation: f32,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n modelNormalMatrix: mat3x3f,\n #ifdef HAS_SSR\n modelViewNormalMatrix: mat3x3f,\n #endif\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\nvar<private> Vertex: vec3f;\nvar<private> Normal: vec3f;\nvar<private> Tangent: vec4f;\nconst mid = 0.5;\nfn toTangentFrame(q: vec4f) -> vec3f {\n return vec3f(0.0, 0.0, 1.0) +\n vec3f(2.0, -2.0, -2.0) * q.x * q.zwx +\n vec3f(2.0, 2.0, -2.0) * q.y * q.wzy;\n}\nstruct TangentFrame {\n n: vec3f,\n t: vec3f\n}\nfn toTangentFrameWithTangent(q: vec4f) -> TangentFrame {\n var out: TangentFrame;\n out.n = toTangentFrame(q);\n out.t = vec3f(1.0, 0.0, 0.0) +\n vec3f(-2.0, 2.0, -2.0) * q.y * q.yxw +\n vec3f(-2.0, 2.0, 2.0) * q.z * q.zwx;\n return out;\n}\nfn rotateUV(uv: vec2f, rotation: f32) -> vec2f {\n return vec2f(\n cos(rotation) * (uv.x - mid) + sin(rotation) * (uv.y - mid) + mid,\n cos(rotation) * (uv.y - mid) - sin(rotation) * (uv.x - mid) + mid\n );\n}\n#if HAS_MAP\nfn transformTexcoord(uv: vec2f) -> vec2f {\n let decodedTexCoord = decode_getTexcoord(uv);\n #ifdef HAS_RANDOM_TEX\n let origin = uniforms.uvOrigin;\n let texCoord = decodedTexCoord * uniforms.uvScale + uniforms.uvOffset;\n return (origin % 1.0) + texCoord;\n #else\n var origin = uniforms.uvOrigin;\n var texCoord = decodedTexCoord * uniforms.uvScale;\n if (uniforms.uvRotation != 0.0) {\n origin = rotateUV(origin, uniforms.uvRotation);\n texCoord = rotateUV(texCoord, uniforms.uvRotation);\n }\n return (origin % 1.0) + texCoord + uniforms.uvOffset;\n #endif\n}\n#endif\nfn transposeMat3(inMat: mat3x3f) -> mat3x3f {\n let i0 = inMat[0];\n let i1 = inMat[1];\n let i2 = inMat[2];\n return mat3x3f(\n vec3f(i0.x, i1.x, i2.x),\n vec3f(i0.y, i1.y, i2.y),\n vec3f(i0.z, i1.z, i2.z)\n );\n}\n@vertex\nfn main(input: VertexInput) -> VertexOutput {\n var output: VertexOutput;\n let localPositionMatrix = getPositionMatrix(input, &output, uniforms.positionMatrix);\n #ifdef IS_LINE_EXTRUSION\n let linePosition = getLineExtrudePosition(vec3f(input.aPosition.xyz), input);\n let localVertex = getPosition(linePosition, input);\n #else\n let localVertex = getPosition(vec3f(input.aPosition.xyz), input);\n #endif\n output.vModelVertex = (uniforms.modelMatrix * localVertex).xyz;\n let position = localPositionMatrix * localVertex;\n let viewVertex = uniforms.modelViewMatrix * position;\n output.vViewVertex = viewVertex;\n #ifdef HAS_MASK_EXTENT\n output.position = shaderUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix);\n #else\n output.position = shaderUniforms.projMatrix * viewVertex;\n #endif\n #ifdef PICKING_MODE\n var alpha = 1.0;\n #if HAS_COLOR\n alpha *= f32(input.aColor.a);\n #endif\n #if HAS_COLOR0 && COLOR0_SIZE == 4\n alpha *= f32(input.aColor0.a);\n #endif\n fbo_picking_setData(input, &output, output.position.w, alpha != 0.0);\n #else\n #if HAS_MAP\n output.vTexCoord = transformTexcoord(input.aTexCoord);\n #ifdef HAS_AO_MAP\n output.vTexCoord1 = transformTexcoord(input.aTexCoord1);\n #endif\n #ifdef HAS_I3S_UVREGION\n output.vUvRegion = input.uvRegion / 65535.0;\n #endif\n #endif\n #if HAS_TANGENT || HAS_NORMAL\n let positionNormalMatrix = mat3x3f(\n localPositionMatrix[0].xyz,\n localPositionMatrix[1].xyz,\n localPositionMatrix[2].xyz\n );\n let normalMatrix = uniforms.modelNormalMatrix * positionNormalMatrix;\n #if HAS_TANGENT\n let tangentFrame = toTangentFrameWithTangent(input.aTangent);\n Normal = tangentFrame.n;\n let t = tangentFrame.t;\n output.vModelTangent = vec4f(normalMatrix * t, input.aTangent.w);\n #else\n Normal = decode_getNormal(vec3f(input.aNormal.xyz));\n #endif\n let localNormal = Normal;\n output.vModelNormal = normalMatrix * localNormal;\n #else\n Normal = vec3f(0);\n output.vModelNormal = vec3f(0);\n #endif\n #if HAS_TANGENT\n output.vModelBiTangent = cross(output.vModelNormal, output.vModelTangent.xyz) * sign(input.aTangent.w);\n #endif\n #ifdef HAS_SSR\n let ssrNormalMatrix = uniforms.modelViewNormalMatrix * positionNormalMatrix;\n output.vViewNormal = ssrNormalMatrix * Normal;\n #if HAS_TANGENT\n let localTangent = vec4f(t, input.aTangent.w);\n output.vViewTangent = vec4f(ssrNormalMatrix * localTangent.xyz, localTangent.w);\n #endif\n #endif\n #if HAS_COLOR\n output.vColor = vec4f(input.aColor) / 255.0;\n #endif\n #ifdef HAS_OPACITY\n output.vOpacity = f32(input.aOpacity) / 255.0;\n #else\n output.vOpacity = 1.0;\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n highlight_setVarying(input, &output);\n #endif\n #if HAS_COLOR0\n #if COLOR0_SIZE == 3\n output.vColor0 = vec4f(vec3f(input.aColor0), 255.0) / 255.0;\n #else\n output.vColor0 = vec4f(input.aColor0) / 255.0;\n #endif\n #endif\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &output);\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n let TBN = transposeMat3(mat3x3f(output.vModelTangent.xyz, output.vModelBiTangent, output.vModelNormal));\n output.vTangentViewPos = TBN * shaderUniforms.cameraPosition;\n output.vTangentFragPos = TBN * output.vModelVertex;\n #endif\n #ifdef HAS_VERTEX_COLOR\n vertexColor_update(input, &output);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n output.vCoordinateTexcoord = getCoordinateTexcoord(position, uniforms.modelMatrix);\n output.vExcavateHeight = getWorldHeight(position, uniforms.modelMatrix);\n #endif\n #endif\n return output;\n}";
18068
18277
 
18069
- var wgslFrag$2 = "#include <hsv_frag>\n#include <srgb_frag>\n#include <highlight_frag>\n#include <snow_frag>\n#include <mask_frag>\n#include <terrain_normal_frag>\n#include <vertex_color_frag>\n#include <excavate_frag>\n#include <compute_texcoord_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\n#define PI 3.141593\n#define RECIPROCAL_PI 0.3183099\nstruct MaterialUniforms {\n roughnessMetalness: vec2f,\n albedo: vec3f,\n alpha: f32,\n normal: vec3f,\n emit: vec3f,\n ao: f32,\n specularColor: vec3f,\n glossiness: f32,\n skinColor: vec4f\n};\nvar<private> materialUniforms: MaterialUniforms;\nstruct SceneUniforms {\n alphaTest: f32,\n emissiveFactor: vec3f,\n baseColorFactor: vec4f,\n baseColorIntensity: f32,\n emitColorFactor: f32,\n occlusionFactor: f32,\n roughnessFactor: f32,\n metallicFactor: f32,\n normalMapFactor: f32,\n specularF0: f32,\n emitMultiplicative: f32,\n normalMapFlipY: f32,\n outputSRGB: f32,\n contrast: f32,\n hsv: vec3f,\n specularAAVariance: f32,\n specularAAThreshold: f32,\n #if HAS_SSR\n invProjMatrix: mat4x4f,\n outputFovInfo: array<vec4f, 2>,\n reprojViewProjMatrix: mat4x4f,\n #endif\n #ifndef HAS_COLOR\n #ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n #else\n polygonFill: vec4f,\n #endif\n #endif\n #ifdef HAS_PATTERN\n #ifndef HAS_PATTERN_ANIM\n linePatternAnimSpeed: f32,\n #endif\n #ifndef HAS_PATTERN_GAP\n linePatternGap: f32,\n #endif\n linePatternGapColor: vec4f,\n flipY: f32,\n animSpeedScale: f32,\n uvScale: vec2f,\n atlasSize: vec2f,\n #endif\n};\nstruct ShaderUniforms {\n #if HAS_IBL_LIGHTING\n hdrHSV: vec3f,\n diffuseSPH: vec3f,\n prefilterMiplevel: vec2f,\n prefilterSize: vec2f,\n #else\n ambientColor: vec3f,\n #endif\n cameraPosition: vec3f,\n cameraNearFar: vec2f,\n environmentExposure: f32,\n environmentTransform: mat3x3f,\n light0_viewDirection: vec3f,\n light0_diffuse: vec4f,\n #if HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n #if HAS_SSR\n outSize: vec2f,\n ssrFactor: f32,\n ssrQuality: f32,\n projMatrix: mat4x4f,\n #endif\n #ifdef HAS_PATTERN\n currentTime: f32,\n #endif\n}\n@group(0) @binding($b) var<uniform> uniforms: SceneUniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\n#if HAS_ALBEDO_MAP\n @group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n @group(0) @binding($b) var baseColorTextureSampler: sampler;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n @group(0) @binding($b) var metallicRoughnessTexture: texture_2d<f32>;\n @group(0) @binding($b) var metallicRoughnessTextureSampler: sampler;\n#endif\n#if HAS_EMISSIVE_MAP\n @group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n @group(0) @binding($b) var emissiveTextureSampler: sampler;\n#endif\n#if HAS_AO_MAP\n @group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n @group(0) @binding($b) var occlusionTextureSampler: sampler;\n#endif\n#if HAS_NORMAL_MAP && HAS_TANGENT\n @group(0) @binding($b) var normalTexture: texture_2d<f32>;\n @group(0) @binding($b) var normalTextureSampler: sampler;\n#endif\n#if HAS_SKIN_MAP\n @group(0) @binding($b) var skinTexture: texture_2d<f32>;\n @group(0) @binding($b) var skinTextureSampler: sampler;\n#endif\n#if HAS_RANDOM_TEX\n @group(0) @binding($b) var noiseTexture: texture_2d<f32>;\n @group(0) @binding($b) var noiseTextureSampler: sampler;\n#endif\n@group(0) @binding($b) var brdfLUT: texture_2d<f32>;\n@group(0) @binding($b) var brdfLUTSampler: sampler;\n#if HAS_IBL_LIGHTING\n @group(0) @binding($b) var prefilterMap: texture_cube<f32>;\n @group(0) @binding($b) var prefilterSampler: sampler;\n#endif\n#if HAS_SSR\n @group(0) @binding($b) var TextureDepth: texture_2d<f32>;\n @group(0) @binding($b) var TextureDepthSampler: sampler;\n @group(0) @binding($b) var TextureReflected: texture_2d<f32>;\n @group(0) @binding($b) var TextureReflectedSampler: sampler;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n @group(0) @binding($b) var bumpTexture: texture_2d<f32>;\n @group(0) @binding($b) var bumpSampler: sampler;\n#endif\n#if HAS_PATTERN\n @group(0) @binding($b) var linePatternFile: texture_2d<f32>;\n @group(0) @binding($b) var linePatternFileSampler: sampler;\n#endif\nfn getMaterialAlbedo() -> vec3f {\n return materialUniforms.albedo;\n}\nfn getMaterialAlpha() -> f32 {\n return materialUniforms.alpha;\n}\nfn getMaterialMetalness() -> f32 {\n return materialUniforms.roughnessMetalness.y;\n}\nfn getMaterialRoughness() -> f32 {\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n return 1.0 - materialUniforms.glossiness;\n #else\n return materialUniforms.roughnessMetalness.x;\n #endif\n}\nfn getMaterialEmitColor() -> vec3f {\n return materialUniforms.emit;\n}\nfn getMaterialSkinColor() -> vec4f {\n return materialUniforms.skinColor;\n}\nfn getMaterialNormalMap() -> vec3f {\n return materialUniforms.normal;\n}\nfn getMaterialOcclusion() -> f32 {\n return materialUniforms.ao;\n}\nfn decodeDepth(pack: vec4f) -> f32 {\n return pack.r + pack.g / 255.0;\n}\nfn transformNormal(factor: f32, normalToTransform: vec3f, t: vec3f, b: vec3f, n: vec3f) -> vec3f {\n let normal = vec3f(normalToTransform.xy * factor, normalToTransform.z);\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n}\nfn D_GGX(roughness: f32, normal: vec3f, H: vec3f) -> f32 {\n let NoH = clamp(dot(normal, H), 0.0, 1.0);\n let a = roughness * roughness;\n let a2 = a * a;\n let d = (NoH * a2 - NoH) * NoH + 1.0;\n return a2 / ( PI * d * d);\n}\nfn F_Schlick(f0: vec3f, f90: f32, L: vec3f, H: vec3f) -> vec3f {\n var VoH = clamp(dot(L, H), 0.0, 1.0);\n VoH = pow(1.0 - VoH, 5.0);\n return f90 * VoH + (1.0 - VoH) * f0;\n}\nfn V_SmithGGXCorrelated(normal: vec3f, V: vec3f, roughness: f32, NoL: f32) -> f32 {\n let NoV = clamp(dot(normal, V), 0.0, 1.0);\n let a = roughness * roughness;\n let GGXL = NoV * (NoL * (1.0 - a) + a);\n let GGXV = NoL * (NoV * (1.0 - a) + a);\n return 0.5 / (GGXV + GGXL);\n}\nfn computeSpecularBRDF(roughness: f32, normal: vec3f, V: vec3f, L: vec3f, specular: vec3f, NoL: f32, f90: f32) -> vec3f {\n let H = normalize(V + L);\n let D = D_GGX(roughness, normal, H);\n let V_S = V_SmithGGXCorrelated(normal, V, roughness, NoL);\n let F = F_Schlick(specular, f90, L, H);\n return (D * V_S * PI) * F;\n}\nfn BRDF_Lambert(diffuseColor: vec3f) -> vec3f {\n return RECIPROCAL_PI * diffuseColor;\n}\nstruct LambertLight {\n diffuse: vec3f,\n specular: vec3f\n}\nfn computeLambert(\n normal: vec3f,\n V: vec3f,\n NoL: f32,\n roughness: f32,\n materialDiffuse: vec3f,\n specular: vec3f,\n lightColor: vec3f,\n L: vec3f,\n f90: f32\n) -> LambertLight {\n var lambert: LambertLight;\n if (NoL <= 0.0) {\n lambert.diffuse = vec3f(0.0);\n lambert.specular = vec3f(0.0);\n return lambert;\n }\n let a = NoL * lightColor;\n let brdf = computeSpecularBRDF(roughness, normal, V, L, specular, NoL, f90);\n lambert.specular = a * brdf;\n lambert.diffuse = a * BRDF_Lambert(materialDiffuse);\n return lambert;\n}\n#if HAS_IBL_LIGHTING\n fn computeDiffuseSPH(normal: vec3f) -> vec3f {\n let n = uniforms.environmentTransform * normal;\n let diffuseSPH = shaderUniforms.diffuseSPH;\n let x = n.x;\n let y = n.y;\n let z = n.z;\n let result = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x*x - y*y)\n );\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n return hsv_apply3(result, shaderUniforms.hdrHSV);\n }\n return max(result, vec3f(0.0));\n }\n fn fetchEnvMap(roughness: f32, R: vec3f) -> vec3f {\n let dir = R;\n let maxLevels = shaderUniforms.prefilterMiplevel.x;\n let lod = min(maxLevels, roughness * shaderUniforms.prefilterMiplevel.y);\n var envLight = textureSampleLevel(prefilterMap, prefilterSampler, dir, lod).rgb;\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n envLight = hsv_apply3(envLight, shaderUniforms.hdrHSV);\n }\n return envLight;\n }\n fn getIBLEnvMap(N: vec3f, V: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n let smoothness = 1.0 - roughness;\n let R = mix(N, reflect(-V, N), smoothness * (sqrt(smoothness) + roughness));\n let factor = clamp(1.0 + dot(R, frontNormal), 0.0, 1.0);\n let prefilteredEnvColor = fetchEnvMap(roughness, uniforms.environmentTransform * R) * factor * factor;\n return prefilteredEnvColor;\n }\n#else\n fn getIBLEnvMap(normal: vec3f, eyeVector: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n return shaderUniforms.ambientColor * BRDF_Lambert(materialDiffuse);\n }\n#endif\nfn computeBRDF(spec: vec3f, roughness: f32, NoV: f32, f90: f32) -> vec3f {\n let rgba = textureSample(brdfLUT, brdfLUTSampler, vec2f(NoV, roughness)) * vec4f(255.0, 65280.0, 255.0, 65280.0);\n let b = (rgba[3] + rgba[2]);\n let a = (rgba[1] + rgba[0]);\n return (spec * a + b * f90) / 65535.0;\n}\nfn computeIBLSpecular(\n normal: vec3f,\n eyeVector: vec3f,\n NoV: f32,\n roughness: f32,\n specular: vec3f,\n frontNormal: vec3f,\n f90: f32,\n materialDiffuse: vec3f\n) -> vec3f {\n return getIBLEnvMap(normal, eyeVector, roughness, frontNormal, materialDiffuse) * computeBRDF(specular, roughness, NoV, f90);\n}\nfn computeSpecularAO(ao: f32, NoV: f32) -> f32 {\n let d = NoV + ao;\n return clamp((d * d) - 1.0 + ao, 0.0, 1.0);\n}\n#ifdef HAS_PATTERN\n fn computeUV(input: VertexOutput, texCoord: vec2f) -> vec2f {\n let uv = texCoord % 1.0;\n let uvStart = vec2f(input.vTexInfo.xy);\n let uvSize = vec2f(input.vTexInfo.zw);\n return (uvStart + uv * uvSize) / uniforms.atlasSize;\n }\n#endif\nfn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {\n var materialUniforms: MaterialUniforms;\n var uv: vec2f;\n#ifdef HAS_MAP\n uv = computeTexCoord(vertexOutput.vTexCoord, vertexOutput);\n#endif\n#ifdef HAS_UV_FLIP\n uv.y = 1.0 - uv.y;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n uv = bumpUV(uv, normalize(vertexOutput.vTangentViewPos - vertexOutput.vTangentFragPos));\n#endif\n materialUniforms.albedo = uniforms.baseColorIntensity * uniforms.baseColorFactor.rgb;\n materialUniforms.alpha = uniforms.baseColorFactor.a * vertexOutput.vOpacity;\n#if HAS_PATTERN\n var linesofar = vertexOutput.vLinesofar;\n let uvSize = vertexOutput.vTexInfo.zw;\n#ifdef HAS_PATTERN_GAP\n let myGap = vertexOutput.vLinePatternGap;\n#else\n let myGap = uniforms.linePatternGap;\n#endif\n#ifdef HAS_PATTERN_ANIM\n let myAnimSpeed = vertexOutput.vLinePatternAnimSpeed;\n#else\n let myAnimSpeed = uniforms.linePatternAnimSpeed;\n#endif\n let patternWidth = ceil(uvSize.x * vertexOutput.vPatternHeight / uvSize.y);\n let plusGapWidth = patternWidth * (1.0 + myGap);\n let animSpeed = myAnimSpeed / uniforms.animSpeedScale;\n linesofar += (shaderUniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;\n let patternx = (linesofar / plusGapWidth) % 1.0;\n let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;\n let texCoord = vec2f(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]);\n uv = computeUV(vertexOutput, texCoord);\n var patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);\n let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);\n patternColor = mix(uniforms.linePatternGapColor, patternColor, inGap);\n#ifdef IS_SQUARE_TUBE\n let v = clamp(sign(abs(vertexOutput.vNormalY) - 0.999999), 0.0, 1.0);\n patternColor = mix(patternColor, vec4(1.0), v);\n#endif\n materialUniforms.albedo *= patternColor.rgb;\n materialUniforms.alpha *= patternColor.a;\n#endif\n#if HAS_ALBEDO_MAP\n let baseColor = textureSample(baseColorTexture, baseColorTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(baseColor.rgb);\n materialUniforms.alpha *= baseColor.a;\n#endif\n#if HAS_SKIN_MAP\n let skinColorValue = textureSample(skinTexture, skinTextureSampler, uv);\n materialUniforms.skinColor = skinColorValue;\n#endif\n#if HAS_COLOR0\n materialUniforms.albedo *= vertexOutput.vColor0.rgb;\n#if COLOR0_SIZE == 4\n materialUniforms.alpha *= vertexOutput.vColor0.a;\n#endif\n#endif\n#if HAS_COLOR\n materialUniforms.albedo *= vertexOutput.vColor.rgb;\n materialUniforms.alpha *= vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n materialUniforms.albedo *= uniforms.lineColor.rgb;\n materialUniforms.alpha *= uniforms.lineColor.a;\n#else\n materialUniforms.albedo *= uniforms.polygonFill.rgb;\n materialUniforms.alpha *= uniforms.polygonFill.a;\n#endif\n#if HAS_INSTANCE_COLOR\n materialUniforms.albedo *= vertexOutput.vInstanceColor.rgb;\n materialUniforms.alpha *= vertexOutput.vInstanceColor.a;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n let mrSample = textureSample(metallicRoughnessTexture, metallicRoughnessTextureSampler, uv).gb;\n materialUniforms.roughnessMetalness = mrSample * vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#else\n materialUniforms.roughnessMetalness = vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#endif\n materialUniforms.emit = uniforms.emissiveFactor;\n#if HAS_EMISSIVE_MAP\n if (uniforms.emitMultiplicative == 1.0) {\n materialUniforms.emit *= sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n } else {\n materialUniforms.emit += sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n }\n#endif\n materialUniforms.emit *= uniforms.emitColorFactor;\n#if HAS_AO_MAP\n let aoTexCoord = computeTexCoord(vertexOutput.vTexCoord1, vertexOutput);\n materialUniforms.ao = textureSample(occlusionTexture, occlusionTextureSampler, aoTexCoord).r;\n#else\n materialUniforms.ao = 1.0;\n#endif\n materialUniforms.ao *= uniforms.occlusionFactor;\n#if HAS_NORMAL_MAP && HAS_TANGENT\n var nmap = textureSample(normalTexture, normalTextureSampler, uv).xyz * 2.0 - 1.0;\n nmap.y = select(nmap.y, -namp.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#else\n materialUniforms.normal = normalize(vertexOutput.vModelNormal);\n#endif\n#if HAS_TERRAIN_NORMAL && HAS_TANGENT\n var nmap = convertTerrainHeightToNormalMap(uv);\n nmap.y = select(nmap.y, -namp.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#endif\n#if SHADING_MODEL_SPECULAR_GLOSSINESS\n materialUniforms.albedo *= uniforms.diffuseFactor.rgb;\n materialUniforms.alpha *= uniforms.diffuseFactor.a;\n#if HAS_DIFFUSE_MAP\n let diffuse = textureSample(diffuseTexture, diffuseTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(diffuse.rgb);\n materialUniforms.alpha *= diffuse.a;\n#endif\n materialUniforms.specularColor = uniforms.specularFactor;\n materialUniforms.glossiness = uniforms.glossinessFactor;\n#if HAS_SPECULARGLOSSINESS_MAP\n let specularGlossiness = textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, uv);\n materialUniforms.specularColor *= sRGBToLinear(specularGlossiness.rgb);\n materialUniforms.glossiness *= specularGlossiness.a;\n#endif\n#endif\n return materialUniforms;\n}\nfn HDR_ACES(x: vec3f) -> vec3f {\n const a = 2.51;\n const b = 0.03;\n const c = 2.43;\n const d = 0.59;\n const e = 0.14;\n return (x * (a * x + b)) / (x * (c * x + d) + e);\n}\nfn tonemap(color: vec3f) -> vec3f {\n let tonemapped = HDR_ACES(color);\n return pow(tonemapped, vec3f(1.0/2.2));\n}\nfn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {\n let du = dpdx(worldNormal);\n let dv = dpdy(worldNormal);\n let variance = uniforms.specularAAVariance * (dot(du, du) + dot(dv, dv));\n let kernelRoughness = min(2.0 * variance, uniforms.specularAAThreshold);\n let squareRoughness = saturate(roughness * roughness + kernelRoughness);\n return sqrt(squareRoughness);\n}\n#if HAS_SSR\n fn ssrViewToScreen(projection: mat4x4f, viewVertex: vec3f) -> vec3f {\n let projected = projection * vec4f(viewVertex, 1.0);\n return vec3f(0.5 + 0.5 * projected.xy / projected.w, projected.w);\n }\n fn fetchColorLod(level: f32, uv: vec2f) -> vec3f {\n return textureSampleLevel(TextureReflected, TextureReflectedSampler, uv, level).rgb;\n }\n fn linearizeDepth(depth: f32) -> f32 {\n let projection = uniforms.projMatrix;\n let z = depth * 2.0 - 1.0; return -projection[3].z / (z + projection[2].z);\n }\n fn fetchDepth(uv: vec2f) -> f32 {\n let depth = decodeDepth(textureSample(TextureDepth, TextureDepthSampler, uv));\n return depth;\n }\n fn interleavedGradientNoise(fragCoord: vec2f, frameMod: f32) -> f32 {\n let magic = vec3f(0.06711056, 0.00583715, 52.9829189);\n return fract(magic.z * fract(dot(fragCoord.xy + frameMod * vec2f(47.0, 17.0) * 0.695, magic.xy))) * 0.5;\n }\n fn importanceSampling(\n frameMod: f32,\n tangentX: vec3f,\n tangentY: vec3f,\n tangentZ: vec3f,\n eyeVector: vec3f,\n rough4: f32\n ) -> vec3f {\n var E: vec2f;\n E.x = interleavedGradientNoise(fragCoord.yx, frameMod);\n E.y = fract(E.x * 52.9829189);\n E.y = mix(E.y, 1.0, 0.7);\n let phi = 2.0 * 3.14159 * E.x;\n let cosTheta = pow(max(E.y, 0.000001), rough4 / (2.0 - rough4));\n let sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n var h = vec3f(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n h = h.x * tangentX + h.y * tangentY + h.z * tangentZ;\n return normalize((2.0 * dot(eyeVector, h)) * h - eyeVector);\n }\n fn getStepOffset(frameMod: f32) -> f32 {\n return (interleavedGradientNoise(fragCoord.xy, frameMod) - 0.5);\n }\n fn computeRayDirUV(rayOriginUV: vec3f, rayLen: f32, rayDirView: vec3f) -> vec3f {\n let rayDirUV = ssrViewToScreen(uniforms.projMatrix, vViewVertex.xyz + rayDirView * rayLen);\n rayDirUV.z = 1.0 / rayDirUV.z;\n rayDirUV -= rayOriginUV;\n let scaleMaxX = min(1.0, 0.99 * (1.0 - rayOriginUV.x) / max(1e-5, rayDirUV.x));\n let scaleMaxY = min(1.0, 0.99 * (1.0 - rayOriginUV.y) / max(1e-5, rayDirUV.y));\n let scaleMinX = min(1.0, 0.99 * rayOriginUV.x / max(1e-5, -rayDirUV.x));\n let scaleMinY = min(1.0, 0.99 * rayOriginUV.y / max(1e-5, -rayDirUV.y));\n return rayDirUV * min(scaleMaxX, scaleMaxY) * min(scaleMinX, scaleMinY);\n }\n fn binarySearch(rayOriginUV: vec3f, rayDirUV: vec3f, startSteps: ptr<function, f32>, endSteps: ptr<function, f32>) -> f32 {\n let steps = (*startSteps + *endSteps) * 0.5;\n let sampleUV = rayOriginUV + rayDirUV * steps;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n *startSteps = select(steps, *startSteps, depth > sampleDepth);\n *endSteps = select(*endSteps, steps, depth > sampleDepth);\n return steps;\n }\n fn rayTrace(\n rayOriginUV: vec3f,\n rayLen: f32,\n depthTolerance: f32,\n rayDirView: vec3f,\n roughness: f32,\n frameMod: f32\n ) -> vec4f {\n let checkSteps = 20;\n let invNumSteps = 1.0 / f32(checkSteps);\n depthTolerance *= invNumSteps;\n let rayDirUV = computeRayDirUV(rayOriginUV, rayLen, rayDirView);\n let sampleTime = invNumSteps;\n var diffSampleW = vec3f(0.0, sampleTime, 1.0);\n var sampleUV: vec3f;\n var hit = false;\n var hitDepth = 1.0;\n var steps: f32;\n for (var i = 0; i < checkSteps; i++) {\n sampleUV = rayOriginUV + rayDirUV * diffSampleW.y;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n let validDepth = clamp(sign(0.999 - z), 0.0, 1.0);\n var depthDiff = validDepth * (sampleDepth - depth);\n depthDiff *= clamp(sign(abs(depthDiff) - rayLen * invNumSteps * invNumSteps), 0.0, 1.0);\n hit = abs(depthDiff + depthTolerance) < depthTolerance;\n let timeLerp = clamp(diffSampleW.x / (diffSampleW.x - depthDiff), 0.0, 1.0);\n let hitTime = select(1.0, (diffSampleW.y + timeLerp * invNumSteps - invNumSteps), hit);\n diffSampleW.z = min(diffSampleW.z, hitTime);\n diffSampleW.x = depthDiff;\n if (hit) {\n var startSteps = diffSampleW.y - invNumSteps;\n var endSteps = diffSampleW.y;\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n hitDepth = steps;\n break;\n }\n diffSampleW.y += invNumSteps;\n }\n return vec4f(rayOriginUV + rayDirUV * hitDepth, 1.0 - hitDepth);\n }\n fn fetchColorInRay(\n resRay: vec4f,\n maskSsr: f32,\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32\n ) -> vec4f {\n let AB = mix(uniforms.outputFovInfo[0], uniforms.outputFovInfo[1], resRay.x);\n resRay.xyz = vec3f(mix(AB.xy, AB.zw, resRay.y), 1.0) * -1.0 / resRay.z;\n resRay.xyz = (uniforms.reprojViewProjMatrix * vec4f(resRay.xyz, 1.0)).xyw;\n resRay.xy /= resRay.z;\n let maskEdge = clamp(6.0 - 6.0 * max(abs(resRay.x), abs(resRay.y)), 0.0, 1.0);\n resRay.xy = 0.5 + 0.5 * resRay.xy;\n let fetchColor = specularColor * fetchColorLod(roughness * (1.0 - resRay.w), resRay.xy);\n return vec4f(mix(specularEnvironment, fetchColor, maskSsr * maskEdge), 1.0);\n }\n fn ssr(\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32,\n normal: vec3f,\n eyeVector: vec3f\n ) -> vec3f {\n let taaSS = 0.0;\n var result = vec4f(0.0);\n var rough4 = roughness * roughness;\n rough4 = rough4 * rough4;\n let upVector = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(normal.z) < 0.999);\n let tangentX = normalize(cross(upVector, normal));\n let tangentY = cross(normal, tangentX);\n var maskSsr = shaderUniforms.ssrFactor * clamp(-4.0 * dot(eyeVector, normal) + 3.8, 0.0, 1.0);\n maskSsr *= clamp(4.7 - roughness * 5.0, 0.0, 1.0);\n let rayOriginUV = ssrViewToScreen(shaderUniforms.projMatrix, vViewVertex.xyz);\n rayOriginUV.z = 1.0 / rayOriginUV.z;\n let rayDirView = importanceSampling(taaSS, tangentX, tangentY, normal, eyeVector, rough4);\n let rayLen = mix(shaderUniforms.cameraNearFar.y + vViewVertex.z, -vViewVertex.z - shaderUniforms.cameraNearFar.x, rayDirView.z * 0.5 + 0.5);\n let depthTolerance = 0.5 * rayLen;\n var resRay: vec4f;\n if (dot(rayDirView, normal) > 0.001 && maskSsr > 0.0) {\n resRay = rayTrace(rayOriginUV, rayLen, depthTolerance, rayDirView, roughness, taaSS);\n if (resRay.w > 0.0) {\n result += fetchColorInRay(resRay, maskSsr, specularEnvironment, specularColor, roughness);\n }\n }\n return select(specularEnvironment, result.rgb / result.w, result.w > 0.0);\n }\n#endif\nfn sRGBTransferOETF(value: vec4f) -> vec4f {\n let isLow: vec3<bool> = value.rgb <= vec3f(0.0031308);\n let highPart: vec3f = pow(value.rgb, vec3f(0.41666)) * 1.055 - vec3f(0.055);\n let lowPart: vec3f = value.rgb * 12.92;\n let rgb: vec3f = select(highPart, lowPart, isLow);\n return vec4f(rgb, value.a);\n}\nfn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n materialUniforms = initMaterial(vertexOutput);\n var glFragColor: vec4f;\n let eyeVector = normalize(shaderUniforms.cameraPosition - vertexOutput.vModelVertex);\n #if HAS_DOUBLE_SIDE\n let frontNormal = select(-normalize(vertexOutput.vModelNormal), normalize(vertexOutput.vModelNormal), gl_FrontFacing);\n #else\n let frontNormal = normalize(vertexOutput.vModelNormal);\n #endif\n let f0 = 0.08 * uniforms.specularF0;\n let metal = getMaterialMetalness();\n var materialDiffuse = getMaterialAlbedo();\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n let materialSpecular = materialUniforms.specularColor;\n #else\n let materialSpecular = mix(vec3f(f0), materialDiffuse, metal);\n #endif\n materialDiffuse *= 1.0 - metal;\n let materialF90 = clamp(50.0 * materialSpecular.g, 0.0, 1.0);\n var materialRoughness = getMaterialRoughness();\n if (uniforms.specularAAVariance > 0.0) {\n materialRoughness = normalFiltering(materialRoughness, frontNormal);\n }\n let materialEmit = getMaterialEmitColor();\n var materialNormal = getMaterialNormalMap();\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n materialNormal = transformNormal(uniforms.normalMapFactor, materialNormal, vertexOutput.vModelTangent.xyz, vertexOutput.vModelBiTangent, frontNormal);\n #endif\n #endif\n var diffuse = vec3f(0.0);\n var specular = vec3f(0.0);\n #if HAS_IBL_LIGHTING\n diffuse = materialDiffuse * computeDiffuseSPH(materialNormal) * 0.5;\n #else\n diffuse = materialDiffuse * shaderUniforms.ambientColor;\n #endif\n let NoV = dot(materialNormal, eyeVector);\n specular = computeIBLSpecular(materialNormal, eyeVector, NoV, materialRoughness, materialSpecular, frontNormal, materialF90, materialDiffuse);\n var specularAO = 1.0;\n let materialAO = getMaterialOcclusion();\n diffuse *= shaderUniforms.environmentExposure * materialAO;\n #if HAS_IBL_LIGHTING\n specularAO = computeSpecularAO(materialAO, NoV);\n #endif\n #if HAS_SSR\n var ssrfrontNormal = normalize(select(-vertexOutput.vViewNormal, vertexOutput.vViewNormal, gl_FrontFacing));\n var viewNormal = ssrfrontNormal;\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n var ssrTangent = select(-vertexOutput.vViewTangent, vertexOutput.vViewTangent, gl_FrontFacing);\n ssrTangent.xyz = normalize(ssrTangent.xyz);\n let ssrBinormal = normalize(cross(ssrfrontNormal, ssrTangent.xyz)) * ssrTangent.w;\n viewNormal = transformNormal(uniforms.normalMapFactor, materialNormal, ssrTangent.xyz, ssrBinormal, ssrfrontNormal);\n #endif\n #endif\n specular = ssr(specular, materialSpecular * specularAO, materialRoughness, viewNormal, -normalize(vertexOutput.vViewVertex.xyz));\n #endif\n specular *= shaderUniforms.environmentExposure * specularAO;\n let modelNormal = vertexOutput.vModelNormal;\n let lightDir = -shaderUniforms.light0_viewDirection;\n let dotNL = saturate(dot(lightDir, materialNormal));\n let lambertResult = computeLambert(materialNormal, eyeVector, dotNL, max(0.045, materialRoughness), materialDiffuse, materialSpecular, shaderUniforms.light0_diffuse.rgb, lightDir, materialF90);\n var ambientDiffuse = lambertResult.diffuse;\n var ambientSpecular = lambertResult.specular;\n #if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n ambientDiffuse = shadow_blend(ambientDiffuse, shadowCoeff).rgb;\n ambientSpecular = shadow_blend(ambientSpecular, shadowCoeff).rgb;\n #endif\n diffuse += ambientDiffuse;\n specular += ambientSpecular;\n diffuse += materialEmit;\n var frag = specular + diffuse;\n if (uniforms.outputSRGB == 1.0) {\n frag = linearTosRGB(frag);\n }\n #if HAS_SKIN_MAP\n let skinColor = getMaterialSkinColor();\n frag.rgb = frag.rgb * (1.0 - skinColor.a) + skinColor.rgb * skinColor.a;\n #if HAS_SHADOWING && !HAS_BLOOM\n frag.rgb = shadow_blend(frag.rgb, shadowCoeff).rgb;\n #endif\n #endif\n var alpha = getMaterialAlpha();\n if (alpha < uniforms.alphaTest) {\n discard;\n }\n #if ALPHA_MODE\n #if ALPHA_MODE == 1\n if (alpha < uniforms.alphaCutoff) {\n discard;\n } else {\n alpha = 1.0;\n }\n #else\n alpha = 1.0;\n #endif\n #endif\n glFragColor = vec4f(frag * alpha, alpha);\n #ifdef HAS_VERTEX_COLOR\n glFragColor *= vertexColor_get(vertexOutput);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n glFragColor = excavateColor(glFragColor);\n #endif\n #ifdef HAS_SNOW\n glFragColor.rgb = snow(glFragColor, getMaterialNormalMap(), 1.0);\n #endif\n if (uniforms.contrast != 1.0) {\n glFragColor = contrastMatrix(uniforms.contrast) * glFragColor;\n }\n if (length(uniforms.hsv) > 0.0) {\n glFragColor = hsv_apply4(glFragColor, uniforms.hsv);\n }\n #ifdef OUTPUT_NORMAL\n glFragColor = vec4f(frontNormal, 1.0);\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n glFragColor = highlight_blendColor(glFragColor, vertexOutput);\n #endif\n #ifdef HAS_LAYER_OPACITY\n glFragColor *= shaderUniforms.layerOpacity;\n #endif\n #ifdef HAS_MASK_EXTENT\n glFragColor = setMask(glFragColor);\n #endif\n return glFragColor;\n}";
18278
+ var wgslFrag$3 = "#include <hsv_frag>\n#include <srgb_frag>\n#include <highlight_frag>\n#include <snow_frag>\n#include <mask_frag>\n#include <terrain_normal_frag>\n#include <vertex_color_frag>\n#include <excavate_frag>\n#include <compute_texcoord_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\n#define PI 3.141593\n#define RECIPROCAL_PI 0.3183099\nstruct MaterialUniforms {\n roughnessMetalness: vec2f,\n albedo: vec3f,\n alpha: f32,\n normal: vec3f,\n emit: vec3f,\n ao: f32,\n specularColor: vec3f,\n glossiness: f32,\n skinColor: vec4f\n};\nvar<private> materialUniforms: MaterialUniforms;\nstruct SceneUniforms {\n alphaTest: f32,\n emissiveFactor: vec3f,\n baseColorFactor: vec4f,\n baseColorIntensity: f32,\n emitColorFactor: f32,\n occlusionFactor: f32,\n roughnessFactor: f32,\n metallicFactor: f32,\n normalMapFactor: f32,\n specularF0: f32,\n emitMultiplicative: f32,\n normalMapFlipY: f32,\n outputSRGB: f32,\n contrast: f32,\n hsv: vec3f,\n specularAAVariance: f32,\n specularAAThreshold: f32,\n #if HAS_SSR\n invProjMatrix: mat4x4f,\n outputFovInfo: array<vec4f, 2>,\n reprojViewProjMatrix: mat4x4f,\n #endif\n #ifndef HAS_COLOR\n #ifdef IS_LINE_EXTRUSION\n lineColor: vec4f,\n #else\n polygonFill: vec4f,\n #endif\n #endif\n #ifdef HAS_PATTERN\n #ifndef HAS_PATTERN_ANIM\n linePatternAnimSpeed: f32,\n #endif\n #ifndef HAS_PATTERN_GAP\n linePatternGap: f32,\n #endif\n linePatternGapColor: vec4f,\n flipY: f32,\n animSpeedScale: f32,\n uvScale: vec2f,\n atlasSize: vec2f,\n #endif\n};\nstruct ShaderUniforms {\n #if HAS_IBL_LIGHTING\n hdrHSV: vec3f,\n diffuseSPH: array<vec3f, 9>,\n prefilterMiplevel: vec2f,\n prefilterSize: vec2f,\n #else\n ambientColor: vec3f,\n #endif\n cameraPosition: vec3f,\n cameraNearFar: vec2f,\n environmentExposure: f32,\n environmentTransform: mat3x3f,\n light0_viewDirection: vec3f,\n light0_diffuse: vec4f,\n #if HAS_LAYER_OPACITY\n layerOpacity: f32,\n #endif\n #if HAS_SSR\n outSize: vec2f,\n ssrFactor: f32,\n ssrQuality: f32,\n projMatrix: mat4x4f,\n #endif\n #ifdef HAS_PATTERN\n currentTime: f32,\n #endif\n}\n@group(0) @binding($b) var<uniform> uniforms: SceneUniforms;\n@group(0) @binding($b) var<uniform> shaderUniforms: ShaderUniforms;\n#if HAS_ALBEDO_MAP\n @group(0) @binding($b) var baseColorTexture: texture_2d<f32>;\n @group(0) @binding($b) var baseColorTextureSampler: sampler;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n @group(0) @binding($b) var metallicRoughnessTexture: texture_2d<f32>;\n @group(0) @binding($b) var metallicRoughnessTextureSampler: sampler;\n#endif\n#if HAS_EMISSIVE_MAP\n @group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n @group(0) @binding($b) var emissiveTextureSampler: sampler;\n#endif\n#if HAS_AO_MAP\n @group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n @group(0) @binding($b) var occlusionTextureSampler: sampler;\n#endif\n#if HAS_NORMAL_MAP && HAS_TANGENT\n @group(0) @binding($b) var normalTexture: texture_2d<f32>;\n @group(0) @binding($b) var normalTextureSampler: sampler;\n#endif\n#if HAS_SKIN_MAP\n @group(0) @binding($b) var skinTexture: texture_2d<f32>;\n @group(0) @binding($b) var skinTextureSampler: sampler;\n#endif\n#if HAS_RANDOM_TEX\n @group(0) @binding($b) var noiseTexture: texture_2d<f32>;\n @group(0) @binding($b) var noiseTextureSampler: sampler;\n#endif\n@group(0) @binding($b) var brdfLUT: texture_2d<f32>;\n@group(0) @binding($b) var brdfLUTSampler: sampler;\n#if HAS_IBL_LIGHTING\n @group(0) @binding($b) var prefilterMap: texture_cube<f32>;\n @group(0) @binding($b) var prefilterMapSampler: sampler;\n#endif\n#if HAS_SSR\n @group(0) @binding($b) var TextureDepth: texture_2d<f32>;\n @group(0) @binding($b) var TextureDepthSampler: sampler;\n @group(0) @binding($b) var TextureReflected: texture_2d<f32>;\n @group(0) @binding($b) var TextureReflectedSampler: sampler;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n @group(0) @binding($b) var bumpTexture: texture_2d<f32>;\n @group(0) @binding($b) var bumpSampler: sampler;\n#endif\n#if HAS_PATTERN\n @group(0) @binding($b) var linePatternFile: texture_2d<f32>;\n @group(0) @binding($b) var linePatternFileSampler: sampler;\n#endif\nfn getMaterialAlbedo() -> vec3f {\n return materialUniforms.albedo;\n}\nfn getMaterialAlpha() -> f32 {\n return materialUniforms.alpha;\n}\nfn getMaterialMetalness() -> f32 {\n return materialUniforms.roughnessMetalness.y;\n}\nfn getMaterialRoughness() -> f32 {\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n return 1.0 - materialUniforms.glossiness;\n #else\n return materialUniforms.roughnessMetalness.x;\n #endif\n}\nfn getMaterialEmitColor() -> vec3f {\n return materialUniforms.emit;\n}\nfn getMaterialSkinColor() -> vec4f {\n return materialUniforms.skinColor;\n}\nfn getMaterialNormalMap() -> vec3f {\n return materialUniforms.normal;\n}\nfn getMaterialOcclusion() -> f32 {\n return materialUniforms.ao;\n}\nfn decodeDepth(pack: vec4f) -> f32 {\n return pack.r + pack.g / 255.0;\n}\nfn transformNormal(factor: f32, normalToTransform: vec3f, t: vec3f, b: vec3f, n: vec3f) -> vec3f {\n let normal = vec3f(normalToTransform.xy * factor, normalToTransform.z);\n let tbn = mat3x3f(t, b, n);\n return normalize(tbn * normal);\n}\nfn D_GGX(roughness: f32, normal: vec3f, H: vec3f) -> f32 {\n let NoH = clamp(dot(normal, H), 0.0, 1.0);\n let a = roughness * roughness;\n let a2 = a * a;\n let d = (NoH * a2 - NoH) * NoH + 1.0;\n return a2 / ( PI * d * d);\n}\nfn F_Schlick(f0: vec3f, f90: f32, L: vec3f, H: vec3f) -> vec3f {\n var VoH = clamp(dot(L, H), 0.0, 1.0);\n VoH = pow(1.0 - VoH, 5.0);\n return f90 * VoH + (1.0 - VoH) * f0;\n}\nfn V_SmithGGXCorrelated(normal: vec3f, V: vec3f, roughness: f32, NoL: f32) -> f32 {\n let NoV = clamp(dot(normal, V), 0.0, 1.0);\n let a = roughness * roughness;\n let GGXL = NoV * (NoL * (1.0 - a) + a);\n let GGXV = NoL * (NoV * (1.0 - a) + a);\n return 0.5 / (GGXV + GGXL);\n}\nfn computeSpecularBRDF(roughness: f32, normal: vec3f, V: vec3f, L: vec3f, specular: vec3f, NoL: f32, f90: f32) -> vec3f {\n let H = normalize(V + L);\n let D = D_GGX(roughness, normal, H);\n let V_S = V_SmithGGXCorrelated(normal, V, roughness, NoL);\n let F = F_Schlick(specular, f90, L, H);\n return (D * V_S * PI) * F;\n}\nfn BRDF_Lambert(diffuseColor: vec3f) -> vec3f {\n return RECIPROCAL_PI * diffuseColor;\n}\nstruct LambertLight {\n diffuse: vec3f,\n specular: vec3f\n}\nfn computeLambert(\n normal: vec3f,\n V: vec3f,\n NoL: f32,\n roughness: f32,\n materialDiffuse: vec3f,\n specular: vec3f,\n lightColor: vec3f,\n L: vec3f,\n f90: f32\n) -> LambertLight {\n var lambert: LambertLight;\n if (NoL <= 0.0) {\n lambert.diffuse = vec3f(0.0);\n lambert.specular = vec3f(0.0);\n return lambert;\n }\n let a = NoL * lightColor;\n let brdf = computeSpecularBRDF(roughness, normal, V, L, specular, NoL, f90);\n lambert.specular = a * brdf;\n lambert.diffuse = a * BRDF_Lambert(materialDiffuse);\n return lambert;\n}\n#if HAS_IBL_LIGHTING\n fn computeDiffuseSPH(normal: vec3f) -> vec3f {\n let n = shaderUniforms.environmentTransform * normal;\n let diffuseSPH = shaderUniforms.diffuseSPH;\n let x = n.x;\n let y = n.y;\n let z = n.z;\n let result = (\n diffuseSPH[0] +\n diffuseSPH[1] * x +\n diffuseSPH[2] * y +\n diffuseSPH[3] * z +\n diffuseSPH[4] * z * x +\n diffuseSPH[5] * y * z +\n diffuseSPH[6] * y * x +\n diffuseSPH[7] * (3.0 * z * z - 1.0) +\n diffuseSPH[8] * (x*x - y*y)\n );\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n return hsv_apply3(result, shaderUniforms.hdrHSV);\n }\n return max(result, vec3f(0.0));\n }\n fn fetchEnvMap(roughness: f32, R: vec3f) -> vec3f {\n let dir = R;\n let maxLevels = shaderUniforms.prefilterMiplevel.x;\n let lod = min(maxLevels, roughness * shaderUniforms.prefilterMiplevel.y);\n var envLight = textureSampleLevel(prefilterMap, prefilterMapSampler, dir, lod).rgb;\n if (length(shaderUniforms.hdrHSV) > 0.0) {\n envLight = hsv_apply3(envLight, shaderUniforms.hdrHSV);\n }\n return envLight;\n }\n fn getIBLEnvMap(N: vec3f, V: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n let smoothness = 1.0 - roughness;\n let R = mix(N, reflect(-V, N), smoothness * (sqrt(smoothness) + roughness));\n let factor = clamp(1.0 + dot(R, frontNormal), 0.0, 1.0);\n let prefilteredEnvColor = fetchEnvMap(roughness, shaderUniforms.environmentTransform * R) * factor * factor;\n return prefilteredEnvColor;\n }\n#else\n fn getIBLEnvMap(normal: vec3f, eyeVector: vec3f, roughness: f32, frontNormal: vec3f, materialDiffuse: vec3f) -> vec3f {\n return shaderUniforms.ambientColor * BRDF_Lambert(materialDiffuse);\n }\n#endif\nfn computeBRDF(spec: vec3f, roughness: f32, NoV: f32, f90: f32) -> vec3f {\n let rgba = textureSample(brdfLUT, brdfLUTSampler, vec2f(NoV, roughness)) * vec4f(255.0, 65280.0, 255.0, 65280.0);\n let b = (rgba[3] + rgba[2]);\n let a = (rgba[1] + rgba[0]);\n return (spec * a + b * f90) / 65535.0;\n}\nfn computeIBLSpecular(\n normal: vec3f,\n eyeVector: vec3f,\n NoV: f32,\n roughness: f32,\n specular: vec3f,\n frontNormal: vec3f,\n f90: f32,\n materialDiffuse: vec3f\n) -> vec3f {\n return getIBLEnvMap(normal, eyeVector, roughness, frontNormal, materialDiffuse) * computeBRDF(specular, roughness, NoV, f90);\n}\nfn computeSpecularAO(ao: f32, NoV: f32) -> f32 {\n let d = NoV + ao;\n return clamp((d * d) - 1.0 + ao, 0.0, 1.0);\n}\n#ifdef HAS_PATTERN\n fn computeUV(input: VertexOutput, texCoord: vec2f) -> vec2f {\n let uv = texCoord % 1.0;\n let uvStart = vec2f(input.vTexInfo.xy);\n let uvSize = vec2f(input.vTexInfo.zw);\n return (uvStart + uv * uvSize) / uniforms.atlasSize;\n }\n#endif\nfn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {\n var materialUniforms: MaterialUniforms;\n var uv: vec2f;\n#ifdef HAS_MAP\n uv = computeTexCoord(vertexOutput.vTexCoord, vertexOutput);\n#endif\n#ifdef HAS_UV_FLIP\n uv.y = 1.0 - uv.y;\n#endif\n#if HAS_BUMP_MAP && HAS_TANGENT\n uv = bumpUV(uv, normalize(vertexOutput.vTangentViewPos - vertexOutput.vTangentFragPos));\n#endif\n materialUniforms.albedo = uniforms.baseColorIntensity * uniforms.baseColorFactor.rgb;\n materialUniforms.alpha = uniforms.baseColorFactor.a * vertexOutput.vOpacity;\n#if HAS_PATTERN\n var linesofar = vertexOutput.vLinesofar;\n let uvSize = vertexOutput.vTexInfo.zw;\n#ifdef HAS_PATTERN_GAP\n let myGap = vertexOutput.vLinePatternGap;\n#else\n let myGap = uniforms.linePatternGap;\n#endif\n#ifdef HAS_PATTERN_ANIM\n let myAnimSpeed = vertexOutput.vLinePatternAnimSpeed;\n#else\n let myAnimSpeed = uniforms.linePatternAnimSpeed;\n#endif\n let patternWidth = ceil(uvSize.x * vertexOutput.vPatternHeight / uvSize.y);\n let plusGapWidth = patternWidth * (1.0 + myGap);\n let animSpeed = myAnimSpeed / uniforms.animSpeedScale;\n linesofar += (shaderUniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;\n let patternx = (linesofar / plusGapWidth) % 1.0;\n let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;\n let texCoord = vec2f(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]);\n uv = computeUV(vertexOutput, texCoord);\n var patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);\n let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);\n patternColor = mix(uniforms.linePatternGapColor, patternColor, inGap);\n#ifdef IS_SQUARE_TUBE\n let v = clamp(sign(abs(vertexOutput.vNormalY) - 0.999999), 0.0, 1.0);\n patternColor = mix(patternColor, vec4(1.0), v);\n#endif\n materialUniforms.albedo *= patternColor.rgb;\n materialUniforms.alpha *= patternColor.a;\n#endif\n#if HAS_ALBEDO_MAP\n let baseColor = textureSample(baseColorTexture, baseColorTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(baseColor.rgb);\n materialUniforms.alpha *= baseColor.a;\n#endif\n#if HAS_SKIN_MAP\n let skinColorValue = textureSample(skinTexture, skinTextureSampler, uv);\n materialUniforms.skinColor = skinColorValue;\n#endif\n#if HAS_COLOR0\n materialUniforms.albedo *= vertexOutput.vColor0.rgb;\n#if COLOR0_SIZE == 4\n materialUniforms.alpha *= vertexOutput.vColor0.a;\n#endif\n#endif\n#if HAS_COLOR\n materialUniforms.albedo *= vertexOutput.vColor.rgb;\n materialUniforms.alpha *= vertexOutput.vColor.a;\n#elif IS_LINE_EXTRUSION\n materialUniforms.albedo *= uniforms.lineColor.rgb;\n materialUniforms.alpha *= uniforms.lineColor.a;\n#else\n materialUniforms.albedo *= uniforms.polygonFill.rgb;\n materialUniforms.alpha *= uniforms.polygonFill.a;\n#endif\n#if HAS_INSTANCE_COLOR\n materialUniforms.albedo *= vertexOutput.vInstanceColor.rgb;\n materialUniforms.alpha *= vertexOutput.vInstanceColor.a;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n let mrSample = textureSample(metallicRoughnessTexture, metallicRoughnessTextureSampler, uv).gb;\n materialUniforms.roughnessMetalness = mrSample * vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#else\n materialUniforms.roughnessMetalness = vec2(uniforms.roughnessFactor, uniforms.metallicFactor);\n#endif\n materialUniforms.emit = uniforms.emissiveFactor;\n#if HAS_EMISSIVE_MAP\n if (uniforms.emitMultiplicative == 1.0) {\n materialUniforms.emit *= sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n } else {\n materialUniforms.emit += sRGBToLinear(textureSample(emissiveTexture, emissiveTextureSampler, uv).rgb);\n }\n#endif\n materialUniforms.emit *= uniforms.emitColorFactor;\n#if HAS_AO_MAP\n let aoTexCoord = computeTexCoord(vertexOutput.vTexCoord1, vertexOutput);\n materialUniforms.ao = textureSample(occlusionTexture, occlusionTextureSampler, aoTexCoord).r;\n#else\n materialUniforms.ao = 1.0;\n#endif\n materialUniforms.ao *= uniforms.occlusionFactor;\n#if HAS_NORMAL_MAP && HAS_TANGENT\n var nmap = textureSample(normalTexture, normalTextureSampler, uv).xyz * 2.0 - 1.0;\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#else\n materialUniforms.normal = normalize(vertexOutput.vModelNormal);\n#endif\n#if HAS_TERRAIN_NORMAL && HAS_TANGENT\n var nmap = convertTerrainHeightToNormalMap(uv);\n nmap.y = select(nmap.y, -nmap.y, uniforms.normalMapFlipY == 1.0);\n materialUniforms.normal = nmap;\n#endif\n#if SHADING_MODEL_SPECULAR_GLOSSINESS\n materialUniforms.albedo *= uniforms.diffuseFactor.rgb;\n materialUniforms.alpha *= uniforms.diffuseFactor.a;\n#if HAS_DIFFUSE_MAP\n let diffuse = textureSample(diffuseTexture, diffuseTextureSampler, uv);\n materialUniforms.albedo *= sRGBToLinear(diffuse.rgb);\n materialUniforms.alpha *= diffuse.a;\n#endif\n materialUniforms.specularColor = uniforms.specularFactor;\n materialUniforms.glossiness = uniforms.glossinessFactor;\n#if HAS_SPECULARGLOSSINESS_MAP\n let specularGlossiness = textureSample(specularGlossinessTexture, specularGlossinessTextureSampler, uv);\n materialUniforms.specularColor *= sRGBToLinear(specularGlossiness.rgb);\n materialUniforms.glossiness *= specularGlossiness.a;\n#endif\n#endif\n return materialUniforms;\n}\nfn HDR_ACES(x: vec3f) -> vec3f {\n const a = 2.51;\n const b = 0.03;\n const c = 2.43;\n const d = 0.59;\n const e = 0.14;\n return (x * (a * x + b)) / (x * (c * x + d) + e);\n}\nfn tonemap(color: vec3f) -> vec3f {\n let tonemapped = HDR_ACES(color);\n return pow(tonemapped, vec3f(1.0/2.2));\n}\nfn normalFiltering(roughness: f32, worldNormal: vec3f) -> f32 {\n let du = dpdx(worldNormal);\n let dv = dpdy(worldNormal);\n let variance = uniforms.specularAAVariance * (dot(du, du) + dot(dv, dv));\n let kernelRoughness = min(2.0 * variance, uniforms.specularAAThreshold);\n let squareRoughness = saturate(roughness * roughness + kernelRoughness);\n return sqrt(squareRoughness);\n}\n#if HAS_SSR\n fn ssrViewToScreen(projection: mat4x4f, viewVertex: vec3f) -> vec3f {\n let projected = projection * vec4f(viewVertex, 1.0);\n return vec3f(0.5 + 0.5 * projected.xy / projected.w, projected.w);\n }\n fn fetchColorLod(level: f32, uv: vec2f) -> vec3f {\n return textureSampleLevel(TextureReflected, TextureReflectedSampler, uv, level).rgb;\n }\n fn linearizeDepth(depth: f32) -> f32 {\n let projection = uniforms.projMatrix;\n let z = depth * 2.0 - 1.0; return -projection[3].z / (z + projection[2].z);\n }\n fn fetchDepth(uv: vec2f) -> f32 {\n let depth = decodeDepth(textureSample(TextureDepth, TextureDepthSampler, uv));\n return depth;\n }\n fn interleavedGradientNoise(fragCoord: vec2f, frameMod: f32) -> f32 {\n let magic = vec3f(0.06711056, 0.00583715, 52.9829189);\n return fract(magic.z * fract(dot(fragCoord.xy + frameMod * vec2f(47.0, 17.0) * 0.695, magic.xy))) * 0.5;\n }\n fn importanceSampling(\n frameMod: f32,\n tangentX: vec3f,\n tangentY: vec3f,\n tangentZ: vec3f,\n eyeVector: vec3f,\n rough4: f32\n ) -> vec3f {\n var E: vec2f;\n E.x = interleavedGradientNoise(fragCoord.yx, frameMod);\n E.y = fract(E.x * 52.9829189);\n E.y = mix(E.y, 1.0, 0.7);\n let phi = 2.0 * 3.14159 * E.x;\n let cosTheta = pow(max(E.y, 0.000001), rough4 / (2.0 - rough4));\n let sinTheta = sqrt(1.0 - cosTheta * cosTheta);\n var h = vec3f(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);\n h = h.x * tangentX + h.y * tangentY + h.z * tangentZ;\n return normalize((2.0 * dot(eyeVector, h)) * h - eyeVector);\n }\n fn getStepOffset(frameMod: f32) -> f32 {\n return (interleavedGradientNoise(fragCoord.xy, frameMod) - 0.5);\n }\n fn computeRayDirUV(rayOriginUV: vec3f, rayLen: f32, rayDirView: vec3f) -> vec3f {\n let rayDirUV = ssrViewToScreen(uniforms.projMatrix, vViewVertex.xyz + rayDirView * rayLen);\n rayDirUV.z = 1.0 / rayDirUV.z;\n rayDirUV -= rayOriginUV;\n let scaleMaxX = min(1.0, 0.99 * (1.0 - rayOriginUV.x) / max(1e-5, rayDirUV.x));\n let scaleMaxY = min(1.0, 0.99 * (1.0 - rayOriginUV.y) / max(1e-5, rayDirUV.y));\n let scaleMinX = min(1.0, 0.99 * rayOriginUV.x / max(1e-5, -rayDirUV.x));\n let scaleMinY = min(1.0, 0.99 * rayOriginUV.y / max(1e-5, -rayDirUV.y));\n return rayDirUV * min(scaleMaxX, scaleMaxY) * min(scaleMinX, scaleMinY);\n }\n fn binarySearch(rayOriginUV: vec3f, rayDirUV: vec3f, startSteps: ptr<function, f32>, endSteps: ptr<function, f32>) -> f32 {\n let steps = (*startSteps + *endSteps) * 0.5;\n let sampleUV = rayOriginUV + rayDirUV * steps;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n *startSteps = select(steps, *startSteps, depth > sampleDepth);\n *endSteps = select(*endSteps, steps, depth > sampleDepth);\n return steps;\n }\n fn rayTrace(\n rayOriginUV: vec3f,\n rayLen: f32,\n depthTolerance: f32,\n rayDirView: vec3f,\n roughness: f32,\n frameMod: f32\n ) -> vec4f {\n let checkSteps = 20;\n let invNumSteps = 1.0 / f32(checkSteps);\n depthTolerance *= invNumSteps;\n let rayDirUV = computeRayDirUV(rayOriginUV, rayLen, rayDirView);\n let sampleTime = invNumSteps;\n var diffSampleW = vec3f(0.0, sampleTime, 1.0);\n var sampleUV: vec3f;\n var hit = false;\n var hitDepth = 1.0;\n var steps: f32;\n for (var i = 0; i < checkSteps; i++) {\n sampleUV = rayOriginUV + rayDirUV * diffSampleW.y;\n let z = fetchDepth(sampleUV.xy);\n let depth = linearizeDepth(z);\n let sampleDepth = -1.0 / sampleUV.z;\n let validDepth = clamp(sign(0.999 - z), 0.0, 1.0);\n var depthDiff = validDepth * (sampleDepth - depth);\n depthDiff *= clamp(sign(abs(depthDiff) - rayLen * invNumSteps * invNumSteps), 0.0, 1.0);\n hit = abs(depthDiff + depthTolerance) < depthTolerance;\n let timeLerp = clamp(diffSampleW.x / (diffSampleW.x - depthDiff), 0.0, 1.0);\n let hitTime = select(1.0, (diffSampleW.y + timeLerp * invNumSteps - invNumSteps), hit);\n diffSampleW.z = min(diffSampleW.z, hitTime);\n diffSampleW.x = depthDiff;\n if (hit) {\n var startSteps = diffSampleW.y - invNumSteps;\n var endSteps = diffSampleW.y;\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n steps = binarySearch(rayOriginUV, rayDirUV, &startSteps, &endSteps);\n hitDepth = steps;\n break;\n }\n diffSampleW.y += invNumSteps;\n }\n return vec4f(rayOriginUV + rayDirUV * hitDepth, 1.0 - hitDepth);\n }\n fn fetchColorInRay(\n resRay: vec4f,\n maskSsr: f32,\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32\n ) -> vec4f {\n let AB = mix(uniforms.outputFovInfo[0], uniforms.outputFovInfo[1], resRay.x);\n resRay.xyz = vec3f(mix(AB.xy, AB.zw, resRay.y), 1.0) * -1.0 / resRay.z;\n resRay.xyz = (uniforms.reprojViewProjMatrix * vec4f(resRay.xyz, 1.0)).xyw;\n resRay.xy /= resRay.z;\n let maskEdge = clamp(6.0 - 6.0 * max(abs(resRay.x), abs(resRay.y)), 0.0, 1.0);\n resRay.xy = 0.5 + 0.5 * resRay.xy;\n let fetchColor = specularColor * fetchColorLod(roughness * (1.0 - resRay.w), resRay.xy);\n return vec4f(mix(specularEnvironment, fetchColor, maskSsr * maskEdge), 1.0);\n }\n fn ssr(\n specularEnvironment: vec3f,\n specularColor: vec3f,\n roughness: f32,\n normal: vec3f,\n eyeVector: vec3f\n ) -> vec3f {\n let taaSS = 0.0;\n var result = vec4f(0.0);\n var rough4 = roughness * roughness;\n rough4 = rough4 * rough4;\n let upVector = select(vec3f(1.0, 0.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(normal.z) < 0.999);\n let tangentX = normalize(cross(upVector, normal));\n let tangentY = cross(normal, tangentX);\n var maskSsr = shaderUniforms.ssrFactor * clamp(-4.0 * dot(eyeVector, normal) + 3.8, 0.0, 1.0);\n maskSsr *= clamp(4.7 - roughness * 5.0, 0.0, 1.0);\n let rayOriginUV = ssrViewToScreen(shaderUniforms.projMatrix, vViewVertex.xyz);\n rayOriginUV.z = 1.0 / rayOriginUV.z;\n let rayDirView = importanceSampling(taaSS, tangentX, tangentY, normal, eyeVector, rough4);\n let rayLen = mix(shaderUniforms.cameraNearFar.y + vViewVertex.z, -vViewVertex.z - shaderUniforms.cameraNearFar.x, rayDirView.z * 0.5 + 0.5);\n let depthTolerance = 0.5 * rayLen;\n var resRay: vec4f;\n if (dot(rayDirView, normal) > 0.001 && maskSsr > 0.0) {\n resRay = rayTrace(rayOriginUV, rayLen, depthTolerance, rayDirView, roughness, taaSS);\n if (resRay.w > 0.0) {\n result += fetchColorInRay(resRay, maskSsr, specularEnvironment, specularColor, roughness);\n }\n }\n return select(specularEnvironment, result.rgb / result.w, result.w > 0.0);\n }\n#endif\nfn sRGBTransferOETF(value: vec4f) -> vec4f {\n let isLow: vec3<bool> = value.rgb <= vec3f(0.0031308);\n let highPart: vec3f = pow(value.rgb, vec3f(0.41666)) * 1.055 - vec3f(0.055);\n let lowPart: vec3f = value.rgb * 12.92;\n let rgb: vec3f = select(highPart, lowPart, isLow);\n return vec4f(rgb, value.a);\n}\nfn linearToOutputTexel(value: vec4f) -> vec4f {\n return sRGBTransferOETF(value);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n materialUniforms = initMaterial(vertexOutput);\n var glFragColor: vec4f;\n let eyeVector = normalize(shaderUniforms.cameraPosition - vertexOutput.vModelVertex);\n #if HAS_DOUBLE_SIDE\n let frontNormal = select(-normalize(vertexOutput.vModelNormal), normalize(vertexOutput.vModelNormal), gl_FrontFacing);\n #else\n let frontNormal = normalize(vertexOutput.vModelNormal);\n #endif\n let f0 = 0.08 * uniforms.specularF0;\n let metal = getMaterialMetalness();\n var materialDiffuse = getMaterialAlbedo();\n #if SHADING_MODEL_SPECULAR_GLOSSINESS\n let materialSpecular = materialUniforms.specularColor;\n #else\n let materialSpecular = mix(vec3f(f0), materialDiffuse, metal);\n #endif\n materialDiffuse *= 1.0 - metal;\n let materialF90 = clamp(50.0 * materialSpecular.g, 0.0, 1.0);\n var materialRoughness = getMaterialRoughness();\n if (uniforms.specularAAVariance > 0.0) {\n materialRoughness = normalFiltering(materialRoughness, frontNormal);\n }\n let materialEmit = getMaterialEmitColor();\n var materialNormal = getMaterialNormalMap();\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n materialNormal = transformNormal(uniforms.normalMapFactor, materialNormal, vertexOutput.vModelTangent.xyz, vertexOutput.vModelBiTangent, frontNormal);\n #endif\n #endif\n var diffuse = vec3f(0.0);\n var specular = vec3f(0.0);\n #if HAS_IBL_LIGHTING\n diffuse = materialDiffuse * computeDiffuseSPH(materialNormal) * 0.5;\n #else\n diffuse = materialDiffuse * shaderUniforms.ambientColor;\n #endif\n let NoV = dot(materialNormal, eyeVector);\n specular = computeIBLSpecular(materialNormal, eyeVector, NoV, materialRoughness, materialSpecular, frontNormal, materialF90, materialDiffuse);\n var specularAO = 1.0;\n let materialAO = getMaterialOcclusion();\n diffuse *= shaderUniforms.environmentExposure * materialAO;\n #if HAS_IBL_LIGHTING\n specularAO = computeSpecularAO(materialAO, NoV);\n #endif\n #if HAS_SSR\n var ssrfrontNormal = normalize(select(-vertexOutput.vViewNormal, vertexOutput.vViewNormal, gl_FrontFacing));\n var viewNormal = ssrfrontNormal;\n #if HAS_TANGENT\n #if HAS_NORMAL_MAP || HAS_TERRAIN_NORMAL\n var ssrTangent = select(-vertexOutput.vViewTangent, vertexOutput.vViewTangent, gl_FrontFacing);\n ssrTangent.xyz = normalize(ssrTangent.xyz);\n let ssrBinormal = normalize(cross(ssrfrontNormal, ssrTangent.xyz)) * ssrTangent.w;\n viewNormal = transformNormal(uniforms.normalMapFactor, materialNormal, ssrTangent.xyz, ssrBinormal, ssrfrontNormal);\n #endif\n #endif\n specular = ssr(specular, materialSpecular * specularAO, materialRoughness, viewNormal, -normalize(vertexOutput.vViewVertex.xyz));\n #endif\n specular *= shaderUniforms.environmentExposure * specularAO;\n let modelNormal = vertexOutput.vModelNormal;\n let lightDir = -shaderUniforms.light0_viewDirection;\n let dotNL = saturate(dot(lightDir, materialNormal));\n let lambertResult = computeLambert(materialNormal, eyeVector, dotNL, max(0.045, materialRoughness), materialDiffuse, materialSpecular, shaderUniforms.light0_diffuse.rgb, lightDir, materialF90);\n var ambientDiffuse = lambertResult.diffuse;\n var ambientSpecular = lambertResult.specular;\n #if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow(vertexOutput);\n ambientDiffuse = shadow_blend(ambientDiffuse, shadowCoeff).rgb;\n ambientSpecular = shadow_blend(ambientSpecular, shadowCoeff).rgb;\n #endif\n diffuse += ambientDiffuse;\n specular += ambientSpecular;\n diffuse += materialEmit;\n var frag = specular + diffuse;\n if (uniforms.outputSRGB == 1.0) {\n frag = linearTosRGB(frag);\n }\n #if HAS_SKIN_MAP\n let skinColor = getMaterialSkinColor();\n frag = frag.rgb * (1.0 - skinColor.a) + skinColor.rgb * skinColor.a;\n #if HAS_SHADOWING && !HAS_BLOOM\n frag = shadow_blend(rgb, shadowCoeff).rgb;\n #endif\n #endif\n var alpha = getMaterialAlpha();\n if (alpha < uniforms.alphaTest) {\n discard;\n }\n #if ALPHA_MODE\n #if ALPHA_MODE == 1\n if (alpha < uniforms.alphaCutoff) {\n discard;\n } else {\n alpha = 1.0;\n }\n #else\n alpha = 1.0;\n #endif\n #endif\n glFragColor = vec4f(frag * alpha, alpha);\n #ifdef HAS_VERTEX_COLOR\n glFragColor *= vertexColor_get(vertexOutput);\n #endif\n #ifdef HAS_EXCAVATE_ANALYSIS\n glFragColor = excavateColor(glFragColor);\n #endif\n #ifdef HAS_SNOW\n glFragColor.rgb = snow(glFragColor, getMaterialNormalMap(), 1.0);\n #endif\n if (uniforms.contrast != 1.0) {\n glFragColor = contrastMatrix(uniforms.contrast) * glFragColor;\n }\n if (length(uniforms.hsv) > 0.0) {\n glFragColor = hsv_apply4(glFragColor, uniforms.hsv);\n }\n #ifdef OUTPUT_NORMAL\n glFragColor = vec4f(frontNormal, 1.0);\n #endif\n #if HAS_HIGHLIGHT_OPACITY || HAS_HIGHLIGHT_COLOR\n glFragColor = highlight_blendColor(glFragColor, vertexOutput);\n #endif\n #ifdef HAS_LAYER_OPACITY\n glFragColor *= shaderUniforms.layerOpacity;\n #endif\n #ifdef HAS_MASK_EXTENT\n glFragColor = setMask(glFragColor);\n #endif\n return glFragColor;\n}";
18070
18279
 
18071
18280
  //http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/
18072
18281
  class StandardShader extends MeshShader {
@@ -18156,10 +18365,10 @@ class StandardShader extends MeshShader {
18156
18365
  if (extraUniforms) {
18157
18366
  uniforms.push(...extraUniforms);
18158
18367
  }
18159
- const vertSource = config.vert || vert$3;
18368
+ const vertSource = config.vert || vert$2;
18160
18369
  const fragSource = config.frag || frag$4;
18161
18370
  const wgslVertSource = config.wgslVert || wgslVert$1;
18162
- const wgslFragSource = config.wgslFrag || wgslFrag$2;
18371
+ const wgslFragSource = config.wgslFrag || wgslFrag$3;
18163
18372
  const shaderConfig = {
18164
18373
  vert: vertSource,
18165
18374
  frag: fragSource,
@@ -18192,7 +18401,7 @@ class StandardShader extends MeshShader {
18192
18401
  }
18193
18402
  }
18194
18403
 
18195
- var vert$2 = "#define SHADER_NAME depth_vert\nattribute vec3 aPosition;\n#include <line_extrusion_vert>\nuniform mat4 modelViewMatrix;\nuniform mat4 positionMatrix;\nuniform mat4 projMatrix;\nuniform vec2 outSize;\nuniform vec2 halton;\n#include <get_output>\nvoid main() {\n mat4 c = getPositionMatrix();\n#ifdef IS_LINE_EXTRUSION\nvec4 d = getPosition(getLineExtrudePosition(aPosition));\n#else\nvec4 d = getPosition(aPosition);\n#endif\nvec4 e = modelViewMatrix * c * d;\n mat4 f = projMatrix;\n f[2].xy += halton.xy / outSize.xy;\n gl_Position = f * e;\n}";
18404
+ var vert$1 = "#define SHADER_NAME depth_vert\nattribute vec3 aPosition;\n#include <line_extrusion_vert>\nuniform mat4 modelViewMatrix;\nuniform mat4 positionMatrix;\nuniform mat4 projMatrix;\nuniform vec2 outSize;\nuniform vec2 halton;\n#include <get_output>\nvoid main() {\n mat4 c = getPositionMatrix();\n#ifdef IS_LINE_EXTRUSION\nvec4 d = getPosition(getLineExtrudePosition(aPosition));\n#else\nvec4 d = getPosition(aPosition);\n#endif\nvec4 e = modelViewMatrix * c * d;\n mat4 f = projMatrix;\n f[2].xy += halton.xy / outSize.xy;\n gl_Position = f * e;\n}";
18196
18405
 
18197
18406
  var frag$3 = "#define SHADER_NAME depth_frag\nprecision highp float;\nvoid main() {\n gl_FragColor = vec4(1., .0, .0, 1.);\n}";
18198
18407
 
@@ -18212,7 +18421,7 @@ class StandardDepthShader extends MeshShader {
18212
18421
  ];
18213
18422
  const extraCommandProps = config.extraCommandProps;
18214
18423
  super({
18215
- vert: vert$2,
18424
+ vert: vert$1,
18216
18425
  frag: frag$3,
18217
18426
  uniforms,
18218
18427
  extraCommandProps,
@@ -18460,7 +18669,7 @@ class ShadowMapShader extends MeshShader {
18460
18669
 
18461
18670
  var frag$2 = "precision highp float;\nvarying vec2 vTexCoord;\nuniform sampler2D textureSource;\nuniform vec2 resolution;\n#include <common_pack_float>\nvoid main() {\n float c = .0;\n float d = .0;\n for(int x = -BOXBLUR_OFFSET; x <= BOXBLUR_OFFSET; ++x)\n for(int y = -BOXBLUR_OFFSET; y <= BOXBLUR_OFFSET; ++y) {\n vec2 e = vTexCoord.st + vec2(float(x) / resolution.x, float(y) / resolution.y);\n e = clamp(e, .0, 1.);\n float f = common_decodeDepth(texture2D(textureSource, e));\n float s = max(.0, sign(1. - f));\n d += sign(f) * s;\n c += f;\n }\n float h = c / max(1., d);\n gl_FragColor = common_encodeDepth(h);\n}";
18462
18671
 
18463
- var wgslFrag$1 = "#include <common_pack_float>\nstruct Uniforms {\n resolution: vec2f\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n#ifdef HAS_MULTISAMPLED\n@binding($b) @group(0) var textureSource: texture_multisampled_2d<f32>;\n#else\n@binding($b) @group(0) var textureSource: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var textureSourceSampler: sampler;\nfn sign_positive(x: f32) -> f32 {\n return select(0.0, 1.0, x > 0.0);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var c: f32 = 0.0;\n var weight: f32 = 0.0;\n let offset = BOXBLUR_OFFSET;\n for (var x: i32 = -offset; x <= offset; x++) {\n for (var y: i32 = -offset; y <= offset; y++) {\n var uv: vec2f = vertexOutput.vTexCoord + vec2f(f32(x) / uniforms.resolution.x, f32(y) / uniforms.resolution.y);\n uv = clamp(uv, vec2f(0.0), vec2f(1.0));\n #ifdef HAS_MULTISAMPLED\n let texColor = textureLoad(textureSource, vec2i(uv * vec2f(uniforms.resolution)), 0);\n #else\n let texColor = textureSample(textureSource, textureSourceSampler, uv);\n #endif\n let depth = common_decodeDepth(texColor);\n let s = max(0.0, sign_positive(1.0 - depth));\n weight += sign(depth) * s;\n c += depth;\n }\n }\n let avgDepth: f32 = c / max(1.0, weight);\n let encodedDepth = common_encodeDepth(avgDepth);\n return encodedDepth;\n}";
18672
+ var wgslFrag$2 = "#include <common_pack_float>\nstruct Uniforms {\n resolution: vec2f\n};\n@group(0) @binding($b) var<uniform> uniforms: Uniforms;\n#ifdef HAS_MULTISAMPLED\n@binding($b) @group(0) var textureSource: texture_multisampled_2d<f32>;\n#else\n@binding($b) @group(0) var textureSource: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var textureSourceSampler: sampler;\nfn sign_positive(x: f32) -> f32 {\n return select(0.0, 1.0, x > 0.0);\n}\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var c: f32 = 0.0;\n var weight: f32 = 0.0;\n let offset = BOXBLUR_OFFSET;\n for (var x: i32 = -offset; x <= offset; x++) {\n for (var y: i32 = -offset; y <= offset; y++) {\n var uv: vec2f = vertexOutput.vTexCoord + vec2f(f32(x) / uniforms.resolution.x, f32(y) / uniforms.resolution.y);\n uv = clamp(uv, vec2f(0.0), vec2f(1.0));\n #ifdef HAS_MULTISAMPLED\n let texColor = textureLoad(textureSource, vec2i(uv * vec2f(uniforms.resolution)), 0);\n #else\n let texColor = textureSample(textureSource, textureSourceSampler, uv);\n #endif\n let depth = common_decodeDepth(texColor);\n let s = max(0.0, sign_positive(1.0 - depth));\n weight += sign(depth) * s;\n c += depth;\n }\n }\n let avgDepth: f32 = c / max(1.0, weight);\n let encodedDepth = common_encodeDepth(avgDepth);\n return encodedDepth;\n}";
18464
18673
 
18465
18674
  class BoxShadowBlurShader extends QuadShader {
18466
18675
 
@@ -18468,7 +18677,7 @@ class BoxShadowBlurShader extends QuadShader {
18468
18677
  super({
18469
18678
  name: 'box-shadow-blur',
18470
18679
  frag: frag$2,
18471
- wgslFrag: wgslFrag$1,
18680
+ wgslFrag: wgslFrag$2,
18472
18681
  defines : {
18473
18682
  'BOXBLUR_OFFSET' : blurOffset || 2
18474
18683
  }
@@ -19525,10 +19734,15 @@ class FBORayPicking {
19525
19734
  height: fbo.height
19526
19735
  });
19527
19736
 
19528
- const canvas = document.createElement('canvas');
19737
+ const id = 'picking_debug_canvas';
19738
+ let canvas = document.getElementById(id);
19739
+ if (!canvas) {
19740
+ canvas = document.createElement('canvas');
19741
+ canvas.id = id;
19742
+ document.body.appendChild(canvas);
19743
+ }
19529
19744
  canvas.width = fbo.width;
19530
19745
  canvas.height = fbo.height;
19531
- document.body.appendChild(canvas);
19532
19746
  for (let i = 0; i < data2.length; i += 4) {
19533
19747
  if (data2[i + 3] !== 255) {
19534
19748
  data2[i + 3] = 255;
@@ -20042,6 +20256,34 @@ class DynamicBufferPool {
20042
20256
  }
20043
20257
  }
20044
20258
 
20259
+ class GraphicsCubeTexture extends GraphicsTexture {
20260
+ get arrayLayers() {
20261
+ return 6;
20262
+ }
20263
+ getMipLevelCount() {
20264
+ const data = this.config.faces && this.config.faces[0];
20265
+ if (data && data.mipmap) {
20266
+ return data.mipmap.length;
20267
+ }
20268
+ return 1;
20269
+ }
20270
+ fillData(texture, width, height) {
20271
+ const config = this.config;
20272
+ if (config.faces) {
20273
+ for (let i = 0; i < 6; i++) {
20274
+ const data = config.faces[i];
20275
+ const origin = [0, 0, i];
20276
+ if (this.isArrayData(data)) {
20277
+ this.fillArrayData(texture, data, width, height, origin);
20278
+ }
20279
+ else {
20280
+ this.fillImageData(texture, data, width, height, origin);
20281
+ }
20282
+ }
20283
+ }
20284
+ }
20285
+ }
20286
+
20045
20287
  let uid = 0;
20046
20288
  class GraphicsDevice {
20047
20289
  constructor(device, context, adapter) {
@@ -20049,6 +20291,8 @@ class GraphicsDevice {
20049
20291
  this.commandBuffers = [];
20050
20292
  //@internal
20051
20293
  this._readTargets = {};
20294
+ //@internal
20295
+ this._destroyList = [];
20052
20296
  this.wgpu = device;
20053
20297
  this.adapter = adapter;
20054
20298
  const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
@@ -20108,7 +20352,9 @@ class GraphicsDevice {
20108
20352
  fbo = fbo || this.getDefaultFramebuffer();
20109
20353
  const desc = fbo.getRenderPassDescriptor();
20110
20354
  const commandEncoder = this.getCommandEncoder();
20111
- return commandEncoder.beginRenderPass(desc);
20355
+ const renderPass = commandEncoder.beginRenderPass(desc);
20356
+ renderPass.desc = desc;
20357
+ return renderPass;
20112
20358
  }
20113
20359
  addCommandBuffer(commandBuffer, front) {
20114
20360
  if (front) {
@@ -20127,6 +20373,14 @@ class GraphicsDevice {
20127
20373
  this.wgpu.queue.submit(this.commandBuffers);
20128
20374
  this.commandBuffers.length = 0;
20129
20375
  }
20376
+ for (let i = 0; i < this._destroyList.length; i++) {
20377
+ const resource = this._destroyList[i];
20378
+ resource.destroy();
20379
+ }
20380
+ this._destroyList = [];
20381
+ }
20382
+ addToDestroyList(texture) {
20383
+ this._destroyList.push(texture);
20130
20384
  }
20131
20385
  preserveDrawingBuffer(canvas) {
20132
20386
  canvas.width = this.context.canvas.width;
@@ -20157,6 +20411,9 @@ class GraphicsDevice {
20157
20411
  }
20158
20412
  // implementation of regl.texture
20159
20413
  texture(width, height) {
20414
+ if (width === undefined) {
20415
+ width = 1;
20416
+ }
20160
20417
  let config = width;
20161
20418
  if (isNumber$2(width)) {
20162
20419
  config = {
@@ -20166,6 +20423,10 @@ class GraphicsDevice {
20166
20423
  }
20167
20424
  return new GraphicsTexture(this, config);
20168
20425
  }
20426
+ // implementation of regl.cube
20427
+ cube(options) {
20428
+ return new GraphicsCubeTexture(this, options);
20429
+ }
20169
20430
  // implementation of regl.clear
20170
20431
  clear(options) {
20171
20432
  const fbo = (options.framebuffer || this.getDefaultFramebuffer());
@@ -20310,8 +20571,12 @@ class GraphicsDevice {
20310
20571
  buffer.destroy();
20311
20572
  }
20312
20573
  }
20574
+ if (this.wgpu) {
20575
+ this.wgpu.destroy();
20576
+ delete this.wgpu;
20577
+ }
20313
20578
  this._readTargets = {};
20314
- this._emptyPipelines = {};
20579
+ this._clearPipelines = {};
20315
20580
  }
20316
20581
  incrDrawCall() {
20317
20582
  this._drawCount++;
@@ -20323,33 +20588,42 @@ class GraphicsDevice {
20323
20588
  return this._drawCount;
20324
20589
  }
20325
20590
  _renderToClear(fbo) {
20591
+ if (fbo && fbo.isDestroyed()) {
20592
+ return;
20593
+ }
20326
20594
  const pass = this.getRenderPassEncoder(fbo);
20327
- const pipeline = this._getEmptyPipeline(fbo);
20595
+ const pipeline = this._getClearPipeline(fbo);
20328
20596
  pass.setPipeline(pipeline);
20329
20597
  pass.draw(3);
20330
20598
  pass.end();
20331
20599
  this.submit();
20332
20600
  }
20333
- _getEmptyPipeline(fbo) {
20334
- const hasColorTexture = !!fbo.colorTexture;
20335
- const sampleCount = fbo.colorTexture && fbo.colorTexture.config.sampleCount;
20336
- const depthEnabled = !!fbo.depthTexture;
20337
- this._emptyPipelines = this._emptyPipelines || {};
20338
- const key = hasColorTexture + '-' + depthEnabled + '-' + sampleCount;
20339
- if (this._emptyPipelines[key]) {
20340
- return this._emptyPipelines[key];
20601
+ _getClearPipeline(fbo) {
20602
+ const isDefault = fbo === this.getDefaultFramebuffer();
20603
+ const sampleCount = fbo.colorTexture && fbo.colorTexture.config.sampleCount || 1;
20604
+ const depthFormat = isDefault || fbo.depthTexture && fbo.depthTexture.gpuFormat.format;
20605
+ let format;
20606
+ if (fbo.colorTexture) {
20607
+ format = fbo.colorTexture.gpuFormat.format;
20608
+ }
20609
+ else {
20610
+ format = navigator.gpu.getPreferredCanvasFormat();
20611
+ }
20612
+ this._clearPipelines = this._clearPipelines || {};
20613
+ const key = format + '-' + isDefault + '-' + depthFormat + '-' + sampleCount;
20614
+ if (this._clearPipelines[key]) {
20615
+ return this._clearPipelines[key];
20341
20616
  }
20342
20617
  const device = this.wgpu;
20343
20618
  const module = device.createShaderModule({
20344
- label: 'empty shader',
20345
20619
  code: /* wgsl */ `
20346
20620
  @vertex fn vs(
20347
20621
  @builtin(vertex_index) vertexIndex : u32
20348
20622
  ) -> @builtin(position) vec4f {
20349
20623
  let pos = array(
20350
- vec2f( 0.0, 0.5),
20351
- vec2f(-0.5, -0.5),
20352
- vec2f( 0.5, -0.5)
20624
+ vec2f(2, 2.5),
20625
+ vec2f(1.5, 1.5),
20626
+ vec2f(2.5, 1.5)
20353
20627
  );
20354
20628
  return vec4f(pos[vertexIndex], 0.0, 1.0);
20355
20629
  }
@@ -20358,14 +20632,8 @@ class GraphicsDevice {
20358
20632
  }
20359
20633
  `,
20360
20634
  });
20361
- let format;
20362
- if (fbo.colorTexture) {
20363
- format = fbo.colorTexture.gpuFormat.format;
20364
- }
20365
- else {
20366
- format = navigator.gpu.getPreferredCanvasFormat();
20367
- }
20368
20635
  const options = {
20636
+ label: 'clear',
20369
20637
  layout: 'auto',
20370
20638
  vertex: { module },
20371
20639
  fragment: {
@@ -20373,19 +20641,20 @@ class GraphicsDevice {
20373
20641
  targets: [{ format }],
20374
20642
  },
20375
20643
  };
20376
- if (depthEnabled) {
20644
+ if (depthFormat) {
20377
20645
  options.depthStencil = {
20378
20646
  depthWriteEnabled: false,
20379
20647
  depthCompare: 'always',
20380
- format: 'depth24plus-stencil8',
20648
+ format: depthFormat === true ? 'depth24plus-stencil8' : depthFormat,
20381
20649
  };
20382
20650
  }
20383
20651
  if (sampleCount > 1) {
20384
20652
  options.multisample = { count: sampleCount };
20385
20653
  }
20386
20654
  const pipeline = device.createRenderPipeline(options);
20387
- this._emptyPipelines[key] = pipeline;
20388
- return this._emptyPipelines[key];
20655
+ pipeline.options = options;
20656
+ this._clearPipelines[key] = pipeline;
20657
+ return this._clearPipelines[key];
20389
20658
  }
20390
20659
  }
20391
20660
 
@@ -24835,16 +25104,18 @@ function getDepthTexture$1(fbo) {
24835
25104
  return fbo.depthStencil._texture.texture;
24836
25105
  }
24837
25106
 
24838
- var vert$1 = "#if __VERSION__ == 300\n#define attribute in\n#define varying out\n#endif\nattribute vec2 aPosition;\nattribute vec2 aTexCoord;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_Position = vec4(aPosition, 0., 1.);\n vTexCoord = aTexCoord;\n}";
24839
-
24840
25107
  var frag$1 = "#if __VERSION__ == 100\n#ifdef GL_OES_standard_derivatives\n#extension GL_OES_standard_derivatives : enable\n#endif\n#endif\nprecision mediump float;\n#include <gl2_frag>\nvarying vec2 vTexCoord;\n#ifdef HAS_FLOODANALYSE\nuniform vec3 flood_waterColor;\nuniform float flood_waterOpacity;\nuniform sampler2D floodMap;\n#endif\n#ifdef HAS_SKYLINE\nuniform sampler2D skylineMap;\n#endif\n#ifdef HAS_VIEWSHED\nuniform vec4 viewshed_visibleColor;\nuniform vec4 viewshed_invisibleColor;\nuniform sampler2D viewshedMap;\n#endif\n#ifdef HAS_INSIGHT\nuniform vec4 insight_visibleColor;\nuniform vec4 insight_invisibleColor;\nuniform sampler2D insightMap;\n#endif\n#ifdef HAS_CUT\nuniform sampler2D meshesMap;\nuniform sampler2D invisibleMap;\n#endif\n#ifdef HAS_EXCAVATE\nuniform sampler2D excavateMap;\n#endif\n#ifdef HAS_CROSSCUT\nuniform sampler2D crosscutMap;\nuniform vec4 cutLineColor;\n#endif\n#ifdef HAS_HEIGHTLIMIT\nuniform vec3 limitColor;\nuniform sampler2D heightLimitMap;\n#endif\nuniform sampler2D sceneMap;\nvoid main() {\n vec4 c = texture2D(sceneMap, vTexCoord);\n glFragColor = c;\n#ifdef HAS_VIEWSHED\nvec4 d = texture2D(viewshedMap, vTexCoord);\n if(d.r > .99) {\n glFragColor = vec4(mix(viewshed_invisibleColor.rgb, c.rgb, viewshed_invisibleColor.a), c.a);\n } else if(d.g > .99) {\n glFragColor = vec4(mix(viewshed_visibleColor.rgb, c.rgb, viewshed_visibleColor.a), c.a);\n } else if(d.a < .01) {\n glFragColor = vec4(d.rgb, 1.);\n }\n \n \n#endif\n#ifdef HAS_FLOODANALYSE\nvec4 e = texture2D(floodMap, vTexCoord);\n if(e.r > .0) {\n glFragColor = vec4(mix(glFragColor.rgb, flood_waterColor, flood_waterOpacity), glFragColor.a);\n }\n#endif\n#ifdef HAS_SKYLINE\nvec4 f = texture2D(skylineMap, vTexCoord);\n if(f.r > .0 || f.g > .0 || f.b > .0) {\n glFragColor = f;\n }\n#endif\n#ifdef HAS_INSIGHT\nvec4 h = texture2D(insightMap, vTexCoord);\n if(h.g > .0) {\n glFragColor = insight_visibleColor;\n } else if(h.r > .0) {\n glFragColor = insight_invisibleColor;\n }\n \n#endif\n#ifdef HAS_CUT\nvec4 i = texture2D(invisibleMap, vTexCoord);\n vec4 j = texture2D(meshesMap, vTexCoord);\n if(i.r == 1. && i.g == .0 && i.b == .0) {\n glFragColor = j;\n } else if(i.r == .0 && i.g == 1. && i.b == .0) {\n glFragColor = j;\n } else if(i.r == .0 && i.g == .0 && i.b == 1.) {\n glFragColor = c;\n }\n \n \n#endif\n#ifdef HAS_EXCAVATE\nvec4 k = texture2D(excavateMap, vTexCoord);\n if(k.r == 1. && k.g == .0 && k.b == .0) {\n glFragColor = c;\n } else {\n glFragColor = k;\n }\n#endif\n#ifdef HAS_CROSSCUT\nvec4 l = texture2D(crosscutMap, vTexCoord);\n if(l.r > .0) {\n glFragColor = vec4(mix(cutLineColor.rgb, glFragColor.rgb, .99), glFragColor.a);\n }\n#endif\n#ifdef HAS_HEIGHTLIMIT\nvec4 m = texture2D(heightLimitMap, vTexCoord);\n if(m.r > .0) {\n glFragColor = vec4(mix(limitColor, glFragColor.rgb, .6), glFragColor.a);\n }\n#endif\n#if __VERSION__ == 100\ngl_FragColor = glFragColor;\n#endif\n}";
24841
25108
 
25109
+ var wgslFrag$1 = "struct FragmentUniforms {\n resolution: vec2f,\n #ifdef HAS_FLOODANALYSE\n flood_waterColor: vec3f,\n flood_waterOpacity: f32,\n #endif\n #ifdef HAS_VIEWSHED\n viewshed_visibleColor: vec4f,\n viewshed_invisibleColor: vec4f,\n #endif\n #ifdef HAS_INSIGHT\n insight_visibleColor: vec4f,\n insight_invisibleColor: vec4f,\n #endif\n #ifdef HAS_CROSSCUT\n cutLineColor: vec4f,\n #endif\n #ifdef HAS_HEIGHTLIMIT\n limitColor: vec3f,\n #endif\n};\n#ifdef HAS_FLOODANALYSE\n @group(0) @binding($b) var floodMap: texture_2d<f32>;\n @group(0) @binding($b) var floodMapSampler: sampler;\n#endif\n#ifdef HAS_SKYLINE\n @group(0) @binding($b) var skylineMap: texture_2d<f32>;\n @group(0) @binding($b) var skylineMapSampler: sampler;\n#endif\n#ifdef HAS_VIEWSHED\n @group(0) @binding($b) var viewshedMap: texture_2d<f32>;\n @group(0) @binding($b) var viewshedMapSampler: sampler;\n#endif\n#ifdef HAS_INSIGHT\n @group(0) @binding($b) var insightMap: texture_2d<f32>;\n @group(0) @binding($b) var insightMapSampler: sampler;\n#endif\n#ifdef HAS_CUT\n @group(0) @binding($b) var meshesMap: texture_2d<f32>;\n @group(0) @binding($b) var meshesMapSampler: sampler;\n @group(0) @binding($b) var invisibleMap: texture_2d<f32>;\n @group(0) @binding($b) var invisibleMapSampler: sampler;\n#endif\n#ifdef HAS_EXCAVATE\n @group(0) @binding($b) var excavateMap: texture_2d<f32>;\n @group(0) @binding($b) var excavateMapSampler: sampler;\n#endif\n#ifdef HAS_CROSSCUT\n @group(0) @binding($b) var crosscutMap: texture_2d<f32>;\n @group(0) @binding($b) var crosscutMapSampler: sampler;\n#endif\n#ifdef HAS_HEIGHTLIMIT\n @group(0) @binding($b) var heightLimitMap: texture_2d<f32>;\n @group(0) @binding($b) var heightLimitMapSampler: sampler;\n#endif\n#ifdef HAS_MULTISAMPLED\n @group(0) @binding($b) var sceneMap: texture_multisampled_2d<f32>;\n#else\n @group(0) @binding($b) var sceneMap: texture_2d<f32>;\n#endif\n@group(0) @binding($b) var sceneMapSampler: sampler;\n@group(0) @binding($b) var<uniform> uniforms: FragmentUniforms;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var glFragColor: vec4f;\n var uv = vertexOutput.vTexCoord;\n uv.y = 1.0 - uv.y;\n #ifdef HAS_MULTISAMPLED\n let sceneColor = textureLoad(sceneMap, vec2i(uv * uniforms.resolution), 0);\n #else\n let sceneColor = textureSample(sceneMap, sceneMapSampler, uv);\n #endif\n glFragColor = sceneColor;\n #ifdef HAS_VIEWSHED\n let viewshedColor = textureSample(viewshedMap, viewshedMapSampler, uv);\n if (viewshedColor.r > 0.99) {\n glFragColor = vec4f(\n mix(uniforms.viewshed_invisibleColor.rgb, sceneColor.rgb, uniforms.viewshed_invisibleColor.a),\n sceneColor.a\n );\n } else if (viewshedColor.g > 0.99) {\n glFragColor = vec4f(\n mix(uniforms.viewshed_visibleColor.rgb, sceneColor.rgb, uniforms.viewshed_visibleColor.a),\n sceneColor.a\n );\n } else if (viewshedColor.a < 0.01) {\n glFragColor = vec4f(viewshedColor.rgb, 1.0);\n }\n #endif\n #ifdef HAS_FLOODANALYSE\n let floodColor = textureSample(floodMap, floodMapSampler, uv);\n if (floodColor.r > 0.0) {\n glFragColor = vec4f(\n mix(glFragColor.rgb, uniforms.flood_waterColor, uniforms.flood_waterOpacity),\n glFragColor.a\n );\n }\n #endif\n #ifdef HAS_SKYLINE\n let skylineColor = textureSample(skylineMap, skylineMapSampler, uv);\n if (skylineColor.r > 0.0 || skylineColor.g > 0.0 || skylineColor.b > 0.0) {\n glFragColor = skylineColor;\n }\n #endif\n #ifdef HAS_INSIGHT\n let insightColor = textureSample(insightMap, insightMapSampler, uv);\n if (insightColor.g > 0.0) {\n glFragColor = uniforms.insight_visibleColor;\n } else if (insightColor.r > 0.0) {\n glFragColor = uniforms.insight_invisibleColor;\n }\n #endif\n #ifdef HAS_CUT\n let cutColor = textureSample(invisibleMap, invisibleMapSampler, uv);\n let meshesMapColor = textureSample(meshesMap, meshesMapSampler, uv);\n if (cutColor.r == 1.0 && cutColor.g == 0.0 && cutColor.b == 0.0) {\n glFragColor = meshesMapColor;\n } else if (cutColor.r == 0.0 && cutColor.g == 1.0 && cutColor.b == 0.0) {\n glFragColor = meshesMapColor;\n } else if (cutColor.r == 0.0 && cutColor.g == 0.0 && cutColor.b == 1.0) {\n glFragColor = sceneColor;\n }\n #endif\n #ifdef HAS_EXCAVATE\n let excavateColor = textureSample(excavateMap, excavateMapSampler, uv);\n if (excavateColor.r == 1.0 && excavateColor.g == 0.0 && excavateColor.b == 0.0) {\n glFragColor = sceneColor;\n } else {\n glFragColor = excavateColor;\n }\n #endif\n #ifdef HAS_CROSSCUT\n let crosscutColor = textureSample(crosscutMap, crosscutMapSampler, uv);\n if (crosscutColor.r > 0.0) {\n glFragColor = vec4f(\n mix(uniforms.cutLineColor.rgb, glFragColor.rgb, 0.99),\n glFragColor.a\n );\n }\n #endif\n #ifdef HAS_HEIGHTLIMIT\n let heightLimitColor = textureSample(heightLimitMap, heightLimitMapSampler, uv);\n if (heightLimitColor.r > 0.0) {\n glFragColor = vec4f(\n mix(uniforms.limitColor, glFragColor.rgb, 0.6),\n glFragColor.a\n );\n }\n #endif\n return glFragColor;\n}";
25110
+
24842
25111
  // import QuadShader from '../shader/QuadShader.js';
24843
25112
 
24844
25113
  class AnalysisShader extends QuadShader {
24845
25114
  constructor(viewport) {
24846
25115
  super({
24847
- vert: vert$1, frag: frag$1,
25116
+ name: 'analysis',
25117
+ frag: frag$1,
25118
+ wgslFrag: wgslFrag$1,
24848
25119
  extraCommandProps: {
24849
25120
  viewport,
24850
25121
  cull: {
@@ -24919,20 +25190,24 @@ class AnalysisPainter {
24919
25190
  stencil : 0,
24920
25191
  framebuffer : this._fbo
24921
25192
  });
24922
- delete this._shader.shaderDefines['HAS_FLOODANALYSE'];
24923
- delete this._shader.shaderDefines['HAS_VIEWSHED'];
24924
- delete this._shader.shaderDefines['HAS_SKYLINE'];
24925
- delete this._shader.shaderDefines['HAS_INSIGHT'];
24926
- delete this._shader.shaderDefines['HAS_CUT'];
24927
- delete this._shader.shaderDefines['HAS_CROSSCUT'];
24928
- delete this._shader.shaderDefines['HAS_HEIGHTLIMIT'];
25193
+ const shaderDefines = extend({}, this._shader.shaderDefines);
25194
+ delete shaderDefines['HAS_FLOODANALYSE'];
25195
+ delete shaderDefines['HAS_VIEWSHED'];
25196
+ delete shaderDefines['HAS_SKYLINE'];
25197
+ delete shaderDefines['HAS_INSIGHT'];
25198
+ delete shaderDefines['HAS_CUT'];
25199
+ delete shaderDefines['HAS_CROSSCUT'];
25200
+ delete shaderDefines['HAS_HEIGHTLIMIT'];
25201
+ if (tex.texture && tex.texture.sampleCount > 1) {
25202
+ shaderDefines['HAS_MULTISAMPLED'] = 1;
25203
+ }
24929
25204
  for (let i = 0; i < analysisTaskList.length; i++) {
24930
25205
  const task = analysisTaskList[i];
24931
25206
  if (!task.isEnable()) {
24932
25207
  continue;
24933
25208
  }
24934
25209
  const defines = task.getDefines();
24935
- extend(this._shader.shaderDefines, defines);
25210
+ extend(shaderDefines, defines);
24936
25211
  const map = this.getMap();
24937
25212
  const width = map.width, height = map.height;
24938
25213
  const toAanalysisMeshes = this._getToAnalysisMeshes(layers, task.getExcludeLayers());
@@ -24942,7 +25217,8 @@ class AnalysisPainter {
24942
25217
  }
24943
25218
  }
24944
25219
  uniforms['sceneMap'] = tex;
24945
- this._shader.setDefines(this._shader.shaderDefines);
25220
+ uniforms['resolution'] = [this._fbo.width, this._fbo.height];
25221
+ this._shader.setDefines(shaderDefines);
24946
25222
  this.renderer.render(this._shader, uniforms, null, this._fbo);
24947
25223
  return this._fbo;
24948
25224
  }
@@ -24965,9 +25241,20 @@ class AnalysisPainter {
24965
25241
  return toAnalysisMeshes;
24966
25242
  }
24967
25243
 
25244
+ getViewportSize() {
25245
+ let width, height;
25246
+ if (this._viewport.width.data) {
25247
+ width = Util$1.isFunction(this._viewport.width.data) ? this._viewport.width.data() : this._viewport.width;
25248
+ height = Util$1.isFunction(this._viewport.height.data) ? this._viewport.height.data() : this._viewport.height;
25249
+ } else {
25250
+ width = Util$1.isFunction(this._viewport.width) ? this._viewport.width() : this._viewport.width;
25251
+ height = Util$1.isFunction(this._viewport.height) ? this._viewport.height() : this._viewport.height;
25252
+ }
25253
+ return { width, height };
25254
+ }
25255
+
24968
25256
  _resize() {
24969
- const width = Util$1.isFunction(this._viewport.width.data) ? this._viewport.width.data() : this._viewport.width;
24970
- const height = Util$1.isFunction(this._viewport.height.data) ? this._viewport.height.data() : this._viewport.height;
25257
+ const { width, height } = this.getViewportSize();
24971
25258
  if (this._fbo && (this._fbo.width !== width || this._fbo.height !== height)) {
24972
25259
  this._fbo.resize(width, height);
24973
25260
  }
@@ -26756,7 +27043,7 @@ var skinFrag = "#define SHADER_NAME TERRAIN_SKIN\nprecision mediump float;\nunif
26756
27043
 
26757
27044
  var skinWgslVert = "struct VertexInput {\n @location($i) aPosition: vec2i\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n}\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput: VertexOutput;\n vertexOutput.position = vec4f(vec2f(vertexInput.aPosition), 0.0, 1.0);\n return vertexOutput;\n}";
26758
27045
 
26759
- var skinWgslFrag = "struct TerrrainSkinUniforms {\n tileSize: f32,\n skinDim: vec3f,\n opacity: f32,\n}\n@group(0) @binding($b) var<uniform> uniforms: TerrrainSkinUniforms;\n@group(0) @binding($b) var skinTexture: texture_2d<f32>;\n@group(0) @binding($b) var skinTextureSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var fragCoord = vertexOutput.position.xy / 2.0;\n var resolution = vec2f(uniforms.tileSize);\n var uv = (fragCoord - uniforms.skinDim.xy) / (resolution * uniforms.skinDim.z);\n var color = textureSample(skinTexture, skinTextureSampler, uv);\n var opacity = 0.0;\n if (uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0) {\n opacity = uniforms.opacity;\n }\n return color * opacity;\n}";
27046
+ var skinWgslFrag = "struct TerrrainSkinUniforms {\n tileSize: f32,\n skinDim: vec3f,\n opacity: f32,\n flipY: f32\n}\n@group(0) @binding($b) var<uniform> uniforms: TerrrainSkinUniforms;\n@group(0) @binding($b) var skinTexture: texture_2d<f32>;\n@group(0) @binding($b) var skinTextureSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var fragCoord = vertexOutput.position.xy / 2.0;\n var resolution = vec2f(uniforms.tileSize);\n var uv = (fragCoord - uniforms.skinDim.xy) / (resolution * uniforms.skinDim.z);\n if (uniforms.flipY > 0.5) {\n uv.y = 1.0 - uv.y;\n }\n var color = textureSample(skinTexture, skinTextureSampler, uv);\n var opacity = 0.0;\n if (uv.x >= 0.0 && uv.x <= 1.0 && uv.y >= 0.0 && uv.y <= 1.0) {\n opacity = uniforms.opacity;\n }\n return color * opacity;\n}";
26760
27047
 
26761
27048
  class Martini {
26762
27049
  constructor(gridSize = 257) {
@@ -27121,7 +27408,7 @@ class Tile {
27121
27408
 
27122
27409
  const martinis = {};
27123
27410
 
27124
- function createMartiniData(error, heights, width/* , hasSkirts */) {
27411
+ function createMartiniData(error, heights, width, hasSkirts) {
27125
27412
  let martini = martinis[width];
27126
27413
  if (!martini) {
27127
27414
  martini = martinis[width] = new Martini(width);
@@ -27129,7 +27416,12 @@ function createMartiniData(error, heights, width/* , hasSkirts */) {
27129
27416
  const terrainTile = martini.createTile(heights);
27130
27417
  //TODO 需要增加判断,只有pbr渲染时,才需要把isolateSkirtVertices设成true
27131
27418
  const isolateSkirtVertices = true;
27132
- const mesh = terrainTile.getMeshWithSkirts(error, isolateSkirtVertices);
27419
+ let mesh;
27420
+ if (hasSkirts) {
27421
+ mesh = terrainTile.getMeshWithSkirts(error, isolateSkirtVertices);
27422
+ } else {
27423
+ mesh = terrainTile.getMesh(error);
27424
+ }
27133
27425
 
27134
27426
  const { triangles, vertices, leftSkirtIndex, rightSkirtIndex, bottomSkirtIndex, topSkirtIndex } = mesh;
27135
27427
  let { numVerticesWithoutSkirts, numTrianglesWithoutSkirts } = mesh;
@@ -27342,7 +27634,7 @@ function createEmtpyTerrainHeights(height, size) {
27342
27634
  }
27343
27635
 
27344
27636
  const emptyHeights = createEmtpyTerrainHeights(0, 5);
27345
- const EMPTY_TERRAIN_GEO = createMartiniData(1, emptyHeights.data, emptyHeights.width);
27637
+ const EMPTY_TERRAIN_GEO = createMartiniData(1, emptyHeights.data, emptyHeights.width, true);
27346
27638
  EMPTY_TERRAIN_GEO.empty = true;
27347
27639
 
27348
27640
  function fillIncludes(defines, uniformDeclares, context) {
@@ -27386,7 +27678,7 @@ var frag = "#define SHADER_NAME TERRAIN_MESH\nprecision mediump float;\nuniform
27386
27678
 
27387
27679
  var wgslVert = "#define SHADER_NAME TERRAIN_MESH\n#include <mask_vert>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_vert>\n#endif\nstruct MatrixUniforms {\n projMatrix: mat4x4f,\n heightScale: f32,\n};\nstruct TerrainUniforms {\n minAltitude: f32,\n projViewModelMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n modelViewMatrix: mat4x4f,\n positionMatrix: mat4x4f,\n};\nstruct VertexOutput {\n @builtin(position) position : vec4f,\n @location($o) vUv: vec2f,\n};\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n @location($i) aTexCoord: vec2f,\n};\n@group(0) @binding($b) var<uniform> matrixUniforms: MatrixUniforms;\n@group(0) @binding($b) var<uniform> uniforms: TerrainUniforms;\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput: VertexOutput;\n var position = vec4f(vertexInput.aPosition.xy, (vertexInput.aPosition.z + uniforms.minAltitude) * matrixUniforms.heightScale, 1.0);\n position = uniforms.positionMatrix * position;\n #ifdef HAS_MASK_EXTENT\n vertexOutput.position = matrixUniforms.projMatrix * getMaskPosition(position, uniforms.modelMatrix, vertexOutput);\n #else\n vertexOutput.position = uniforms.projViewModelMatrix * position;\n #endif\n vertexOutput.vUv = vertexInput.aTexCoord;\n #if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(position, &vertexOutput);\n #endif\n return vertexOutput;\n}";
27388
27680
 
27389
- var wgslFrag = "#define SHADER_NAME TERRAIN_MESH\n#include <mask_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\nstruct TerrainUniforms {\n polygonOpacity: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: TerrainUniforms;\n@group(0) @binding($b) var skin: texture_2d<f32>;\n@group(0) @binding($b) var skinSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var uv = vec2f(vertexOutput.vUv);\n uv.y = 1.0 - uv.y;\n var color = textureSample(skin, skinSampler, uv);\n #if HAS_SHADOWING && !HAS_BLOOM\n var shadowCoeff = shadow_computeShadow();\n color.rgb = shadow_blend(color.rgb, shadowCoeff).rgb;\n #endif\n var fragColor = color * uniforms.polygonOpacity;\n #ifdef HAS_MASK_EXTENT\n fragColor = setMask(fragColor);\n #endif\n return fragColor;\n}";
27681
+ var wgslFrag = "#define SHADER_NAME TERRAIN_MESH\n#include <mask_frag>\n#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\nstruct TerrainUniforms {\n polygonOpacity: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: TerrainUniforms;\n@group(0) @binding($b) var skin: texture_2d<f32>;\n@group(0) @binding($b) var skinSampler: sampler;\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n var uv = vec2f(vertexOutput.vUv);\n var color = textureSample(skin, skinSampler, uv);\n #if HAS_SHADOWING && !HAS_BLOOM\n var shadowCoeff = shadow_computeShadow();\n color.rgb = shadow_blend(color.rgb, shadowCoeff).rgb;\n #endif\n var fragColor = color * uniforms.polygonOpacity;\n #ifdef HAS_MASK_EXTENT\n fragColor = setMask(fragColor);\n #endif\n return fragColor;\n}";
27390
27682
 
27391
27683
  const V3 = [];
27392
27684
  const SCALE3 = [];
@@ -27395,12 +27687,12 @@ class TerrainPainter {
27395
27687
  constructor(layer) {
27396
27688
  this.layer = layer;
27397
27689
  const renderer = layer.getRenderer();
27398
- this.graphics = renderer.regl || renderer.device;
27399
- this.renderer = new Renderer(this.graphics);
27690
+ this.device = renderer.regl || renderer.device;
27691
+ this.renderer = new Renderer(this.device);
27400
27692
  this._leafScene = new Scene();
27401
27693
  const pixels = new Uint8Array(16);
27402
27694
  pixels.fill(255);
27403
- this._emptyTileTexture = this.graphics.texture({
27695
+ this._emptyTileTexture = this.device.texture({
27404
27696
  width: 2,
27405
27697
  height: 2,
27406
27698
  data: pixels
@@ -27436,7 +27728,7 @@ class TerrainPainter {
27436
27728
  mesh.geometry.updateData('aPosition', positions);
27437
27729
  mesh.geometry.updateData('aTexCoord', texcoords);
27438
27730
  mesh.geometry.setElements(triangles);
27439
- mesh.geometry.generateBuffers(this.graphics);
27731
+ mesh.geometry.generateBuffers(this.device);
27440
27732
  } else {
27441
27733
  const geo = empty ?
27442
27734
  this._emptyTerrainGeometry :
@@ -27447,7 +27739,7 @@ class TerrainPainter {
27447
27739
  triangles,
27448
27740
  0);
27449
27741
  if (geo !== this._emptyTerrainGeometry) {
27450
- geo.generateBuffers(this.graphics);
27742
+ geo.generateBuffers(this.device);
27451
27743
  }
27452
27744
  if (mesh) {
27453
27745
  mesh.geometry = geo;
@@ -27464,6 +27756,7 @@ class TerrainPainter {
27464
27756
  if (!mesh.uniforms.flatMask) {
27465
27757
  const emptyTexture = this.getEmptyTexture();
27466
27758
  mesh.setUniform('flatMask', emptyTexture);
27759
+ mesh.setUniform('maskResolution', [emptyTexture.width, emptyTexture.height]);
27467
27760
  }
27468
27761
 
27469
27762
  mesh.setUniform('heightTexture', heightTexture);
@@ -27541,7 +27834,9 @@ class TerrainPainter {
27541
27834
  const mesh = tileImage.terrainMesh;
27542
27835
  if (mesh && mesh.geometry && tileImage.skin) {
27543
27836
  mesh.setUniform('skin', tileImage.skin.color[0]);
27544
- mesh.setUniform('flatMask', tileImage.mask.color[0]);
27837
+ const mask = tileImage.mask.color[0];
27838
+ mesh.setUniform('flatMask', mask);
27839
+ mesh.setUniform('maskResolution', [mask.width, mask.height]);
27545
27840
  mesh.setUniform('polygonOpacity', 1.0);
27546
27841
  // const { skirtOffset, skirtCount } = mesh.properties;
27547
27842
  // mesh.geometry.setDrawOffset(skirtOffset);
@@ -27734,7 +28029,7 @@ class TerrainPainter {
27734
28029
  },
27735
28030
  triangles,
27736
28031
  0);
27737
- this._emptyTerrainGeometry.generateBuffers(this.graphics);
28032
+ this._emptyTerrainGeometry.generateBuffers(this.device);
27738
28033
  }
27739
28034
  }
27740
28035
 
@@ -27780,7 +28075,7 @@ class TerrainLitPainter extends TerrainPainter {
27780
28075
 
27781
28076
  createIBLTextures() {
27782
28077
  const canvas = this.getMap().getRenderer().canvas;
27783
- loginIBLResOnCanvas(canvas, this.graphics, this.getMap());
28078
+ loginIBLResOnCanvas(canvas, this.device, this.getMap());
27784
28079
  this.layer.fire('iblupdated');
27785
28080
  }
27786
28081
 
@@ -27819,16 +28114,18 @@ class TerrainLitPainter extends TerrainPainter {
27819
28114
  geo.createTangent('aTangent', tangents);
27820
28115
  delete geo.data.aNormal;
27821
28116
 
27822
- geo.generateBuffers(this.graphics);
28117
+ geo.generateBuffers(this.device);
27823
28118
 
27824
28119
  let terrainHeightTexture;
27825
28120
  if (heightTexture) {
27826
- terrainHeightTexture = this.graphics.texture({
28121
+ const isWebGPU = !!this.device.wgpu;
28122
+ terrainHeightTexture = this.device.texture({
27827
28123
  width: heightTexture.width,
27828
28124
  height: heightTexture.height,
27829
28125
  data: heightTexture,
27830
28126
  min: 'linear',
27831
- mag: 'linear'
28127
+ mag: 'linear',
28128
+ flipY: isWebGPU
27832
28129
  });
27833
28130
  } else {
27834
28131
  terrainHeightTexture = this.getEmptyTexture();
@@ -27844,9 +28141,11 @@ class TerrainLitPainter extends TerrainPainter {
27844
28141
  if (!mesh.uniforms.flatMask) {
27845
28142
  const emptyTexture = this.getEmptyTexture();
27846
28143
  mesh.setUniform('flatMask', emptyTexture);
28144
+ mesh.setUniform('maskResolution', [emptyTexture.width, emptyTexture.height]);
27847
28145
  }
27848
28146
  const defines = mesh.defines;
27849
- defines['HAS_UV_FLIP'] = 1;
28147
+ const isWebGPU = !!this.device.wgpu;
28148
+ defines['HAS_UV_FLIP'] = isWebGPU ? 0 : 1;
27850
28149
  defines['HAS_TERRAIN_NORMAL'] = 1;
27851
28150
  defines['HAS_MAP'] = 1;
27852
28151
  defines['HAS_LAYER_OPACITY'] = 1;
@@ -27870,7 +28169,9 @@ class TerrainLitPainter extends TerrainPainter {
27870
28169
  mesh.material.set('skinTexture', tileImage.skin.color[0]);
27871
28170
  }
27872
28171
  if (tileImage.mask) {
27873
- mesh.setUniform('flatMask', tileImage.mask.color[0]);
28172
+ const mask = tileImage.mask.color[0];
28173
+ mesh.setUniform('flatMask', mask);
28174
+ mesh.setUniform('maskResolution', [mask.width, mask.height]);
27874
28175
  }
27875
28176
  mesh.setUniform('polygonOpacity', 1.0);
27876
28177
  // const { skirtOffset, skirtCount } = mesh.properties;
@@ -28284,7 +28585,9 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28284
28585
  return { data: createEmtpyTerrainHeights(minAltitude || 0, 5), minAltitude, mesh: EMPTY_TERRAIN_GEO, sourceZoom };
28285
28586
  }
28286
28587
  const terrainWidth = heights.width;
28287
- const mesh = createMartiniData(error / 2, heights.data, terrainWidth);
28588
+ const errorScale = this.layer._getErrorScale();
28589
+ const hasSkirts = this.layer.options['hasSkirts'];
28590
+ const mesh = createMartiniData(error * errorScale, heights.data, terrainWidth, hasSkirts);
28288
28591
 
28289
28592
  return { data: heights, mesh, sourceZoom, colorsTexture: heights.colorsTexture };
28290
28593
  }
@@ -28529,7 +28832,6 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28529
28832
  const { info, image } = terrainTiles[i];
28530
28833
  this._prepareMask(info, image);
28531
28834
  this._debugTile(info, 'renderChildTerrainSkin');
28532
- let cleared = false;
28533
28835
  if (this._prepareChildTerrainSkin(skinIndex, info, image, skinImagesToDel)) {
28534
28836
  const skinImages = image.skinImages[skinIndex];
28535
28837
  for (let j = 0; j < skinImages.length; j++) {
@@ -28537,11 +28839,6 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28537
28839
 
28538
28840
  // 检查是否存在重复的瓦片,重复的瓦片只需要绘制一次
28539
28841
  if (!visitedSkinTiles.has(tileId)) {
28540
- if (!cleared && skinImages[j].layer.hasTerrainMask) {
28541
- //FIXME 潜在bug: 如果skinLayers中有多个 hasTerrainMask 的图层,其中一个clearMask并更新mask后,其他的terrainMask图层并没有更新mask
28542
- this._clearMask(image.mask);
28543
- cleared = true;
28544
- }
28545
28842
  skinImages[j].terrainMaskFBO = image.mask;
28546
28843
  layerSkinImages.push(skinImages[j]);
28547
28844
  visitedSkinTiles.add(tileId);
@@ -28770,7 +29067,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28770
29067
  return;
28771
29068
  }
28772
29069
  if (!terrainTileImage.skin) {
28773
- terrainTileImage.skin = this._createTerrainTexture(terrainTileInfo, terrainTileImage);
29070
+ terrainTileImage.skin = this._createTerrainSkinTexture(terrainTileInfo, terrainTileImage);
28774
29071
  this._prepareMask(terrainTileInfo, terrainTileImage);
28775
29072
  } else {
28776
29073
  TERRAIN_CLEAR.framebuffer = terrainTileImage.skin;
@@ -28784,6 +29081,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28784
29081
  const tileSize = this.layer.getTileSize().width;
28785
29082
  const skinImages = terrainTileImage.skinImages;
28786
29083
  if (skinImages) {
29084
+ const isWebGPU = !!this.device.wgpu;
28787
29085
  for (let i = 0; i < skinImages.length; i++) {
28788
29086
  const layerSkinImages = skinImages[i];
28789
29087
  for (let ii = 0; ii < layerSkinImages.length; ii++) {
@@ -28799,8 +29097,18 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28799
29097
  }
28800
29098
 
28801
29099
  }
28802
- const skinDim = computeSkinDimension(terrainTileInfo, tile, tileSize);
29100
+
28803
29101
  const mesh = layerSkinImages[ii].skinMesh || new Mesh(this._skinGeometry);
29102
+
29103
+ // 如果不是FBO,WebGPU 上的 texture 本身需要上下翻转,位置也需要上下调整
29104
+ const isFBO = checkIfFBO(texture);
29105
+ const skinDim = computeSkinDimension(terrainTileInfo, tile, tileSize, isFBO, isWebGPU);
29106
+ if (!isFBO) {
29107
+ mesh.setUniform('flipY', 1);
29108
+ } else {
29109
+ mesh.setUniform('flipY', 0);
29110
+ }
29111
+
28804
29112
  mesh.setUniform('skinTexture', texture);
28805
29113
  const skinTileOpacity = layer.getOpacity();
28806
29114
  mesh.setUniform('opacity', isNil$1(skinTileOpacity) ? 1 : skinTileOpacity);
@@ -28820,6 +29128,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28820
29128
  const debugTexture = terrainTileImage.debugTexture || this._createDebugTexture(terrainTileInfo, tileSize, terrainTileImage.temp);
28821
29129
  terrainTileImage.debugTexture = debugTexture;
28822
29130
  terrainTileImage.skinDebugMesh = debugMesh;
29131
+ debugMesh.setUniform('flipY', 1);
28823
29132
  debugMesh.setUniform('opacity', 1);
28824
29133
  debugMesh.setUniform('skinTexture', debugTexture);
28825
29134
  debugMesh.setUniform('skinDim', [0, 0, 1]);
@@ -28913,11 +29222,22 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28913
29222
  const texture = regl.framebuffer(fboInfo);
28914
29223
  texture.colorTex = color;
28915
29224
  this._clearMask(texture);
29225
+ texture.clearTerrainMask = () => {
29226
+ if (!texture._timestamp) {
29227
+ texture._timestamp = 0;
29228
+ }
29229
+ const timestamp = this.getFrameTimestamp();
29230
+ if (timestamp > texture._timestamp) {
29231
+ TERRAIN_MASK_CLEAR.framebuffer = texture;
29232
+ regl.clear(TERRAIN_MASK_CLEAR);
29233
+ texture._timestamp = timestamp;
29234
+ }
29235
+ };
28916
29236
  // 单独创建的 color 必须要手动destroy回收,光destroy framebuffer,color是不会销毁的
28917
29237
  return texture;
28918
29238
  }
28919
29239
 
28920
- _createTerrainTexture(tileInfo/*, tileImage*/) {
29240
+ _createTerrainSkinTexture(tileInfo/*, tileImage*/) {
28921
29241
  const tileSize = this.layer.getTileSize().width;
28922
29242
  // 乘以2是为了瓦片(缩放时)被放大后保持清晰度
28923
29243
  let width = tileSize * 2;
@@ -29184,7 +29504,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
29184
29504
  type: layerOptions.type,
29185
29505
  accessToken: layerOptions.accessToken,
29186
29506
  cesiumIonTokenURL: layerOptions.cesiumIonTokenURL,
29187
- error: error,
29507
+ error: error * layer._getErrorScale(),
29188
29508
  colors: layerOptions.colors,
29189
29509
  tileSize: tileSize ? [tileSize.width, tileSize.height] : [256, 256],
29190
29510
  command: 'loadTile'
@@ -29831,17 +30151,21 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
29831
30151
  // }
29832
30152
  // }
29833
30153
 
29834
- function computeSkinDimension(terrainTileInfo, tile, terrainTileSize) {
30154
+ function computeSkinDimension(terrainTileInfo, tile, terrainTileSize, isFBO, isWebGPU) {
29835
30155
  const { res, extent2d: terrainExtent, offset: terrainOffset } = terrainTileInfo;
29836
30156
  const { info } = tile;
29837
30157
  const scale = info.res / res;
29838
30158
  const offset = info.offset;
29839
30159
  const xmin = info.extent2d.xmin * scale;
30160
+ const ymax = info.extent2d.ymax * scale;
29840
30161
  const ymin = info.extent2d.ymin * scale;
29841
30162
  const dx = terrainOffset[0] - offset[0];
29842
30163
  const dy = offset[1] - terrainOffset[1];
29843
30164
  const left = xmin - terrainExtent.xmin + dx;
29844
- const bottom = terrainExtent.ymin - ymin + dy;
30165
+ let bottom = terrainExtent.ymin - ymin + dy;
30166
+ if (!isFBO && isWebGPU) {
30167
+ bottom = -(terrainExtent.ymax - ymax + dy);
30168
+ }
29845
30169
  return [left, -bottom, scale * info.tileSize / terrainTileSize];
29846
30170
  }
29847
30171
 
@@ -29889,6 +30213,10 @@ function wrapTileColorsTexture(tile, terrainData) {
29889
30213
  }
29890
30214
  }
29891
30215
 
30216
+ function checkIfFBO(texture) {
30217
+ return !!(texture.colorTexture || texture.color);
30218
+ }
30219
+
29892
30220
  const MASK_MODES = {
29893
30221
  'clip-inside': 0.1, 'clip-outside': 0.2, 'flat-inside': 0.3, 'flat-outside': 0.4, 'color': 0.5, 'texture': 0.6, 'elevate': 0.7
29894
30222
  };
@@ -30549,6 +30877,8 @@ const options$2 = {
30549
30877
  'tileStackDepth': 6,
30550
30878
  'currentTilesFirst': false,
30551
30879
  'exaggeration': 1,
30880
+ 'errorScale': 1,
30881
+ 'hasSkirts': true,
30552
30882
  'colors': []
30553
30883
  };
30554
30884
 
@@ -30967,6 +31297,10 @@ class TerrainLayer extends MaskLayerMixin(maptalks.TileLayer) {
30967
31297
  children: []
30968
31298
  };
30969
31299
  }
31300
+
31301
+ _getErrorScale() {
31302
+ return this.options.errorScale / 6;
31303
+ }
30970
31304
  }
30971
31305
 
30972
31306
  // TerrainLayer.include({
@@ -33006,7 +33340,22 @@ class TileLayerGLRenderer2 extends TexturePoolable(canvasCompatible(TileLayerRen
33006
33340
  fbo
33007
33341
  });
33008
33342
  }
33009
- onDrawTileEnd(context, parentContext) {
33343
+ _drawCurrentTiles(tiles, parentTiles) {
33344
+ super._drawCurrentTiles(tiles, parentTiles);
33345
+ this._submitMeshes(parentTiles);
33346
+ }
33347
+ _drawChildTiles(childTiles, parentContext) {
33348
+ super._drawChildTiles(childTiles, parentContext);
33349
+ this._submitMeshes(parentContext);
33350
+ }
33351
+ _drawParentTiles(parentTiles, parentContext) {
33352
+ super._drawChildTiles(parentTiles, parentContext);
33353
+ this._submitMeshes(parentContext);
33354
+ }
33355
+ onDrawTileEnd(_, parentContext) {
33356
+ this._submitMeshes(parentContext);
33357
+ }
33358
+ _submitMeshes(parentContext) {
33010
33359
  const uniformValues = this._getUniformValues();
33011
33360
  let fbo;
33012
33361
  if (parentContext && parentContext.renderTarget) {
@@ -33014,6 +33363,7 @@ class TileLayerGLRenderer2 extends TexturePoolable(canvasCompatible(TileLayerRen
33014
33363
  }
33015
33364
  this._tileScene.setMeshes(this._tileMeshes);
33016
33365
  this._renderer.render(this._shader, uniformValues, this._tileScene, fbo);
33366
+ this._tileMeshes.length = 0;
33017
33367
  }
33018
33368
  _getUniformValues() {
33019
33369
  const map = this.getMap();
@@ -34586,12 +34936,12 @@ class Height3DTool extends Measure3DTool {
34586
34936
 
34587
34937
  const e = "${"; const code$1 = `function(t){
34588
34938
  /*!
34589
- * @maptalks/gltf-loader v0.119.0
34939
+ * @maptalks/gltf-loader v0.121.0
34590
34940
  * LICENSE : UNLICENSED
34591
34941
  * (c) 2016-2026 maptalks.org
34592
34942
  */
34593
- var e,r,n="undefined"!=typeof Float32Array?Float32Array:Array;function i(){var t=new n(3);return n!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function s(t,e,r){var i=new n(3);return i[0]=t,i[1]=e,i[2]=r,i}function a(){var t=new n(4);return n!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),i(),e=new n(4),n!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),i(),s(1,0,0),s(0,1,0),a(),a(),r=new n(9),n!=Float32Array&&(r[1]=0,r[2]=0,r[3]=0,r[5]=0,r[6]=0,r[7]=0),r[0]=1,r[4]=1,r[8]=1;let o=0;!function(t){t[0]=0,t[1]=0,t[2]=0,t[3]=1}([]),"undefined"!=typeof TextDecoder&&new TextDecoder("utf-8");const h={get:function(t,e={},r){e||(e={});const n=new AbortController,i=n.signal,s=function(t){for(let e=1;e<arguments.length;e++){const r=arguments[e];for(const e in r)t[e]=r[e]}return t}({},e);s.signal=i,s.method||(s.method="GET"),s.referrerPolicy=s.referrerPolicy||"origin","undefined"==typeof window||s.referrer||(s.referrer=window.location.href),r&&(t=r(t));const a=fetch(t,s).then((t=>{const r=this._parseResponse(t,e.responseType);return r.message?r:r.then((r=>"arraybuffer"===e.responseType?{data:r,cacheControl:t.headers.get("Cache-Control"),expires:t.headers.get("Expires"),contentType:t.headers.get("Content-Type")}:r)).catch((t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t}))})).catch((t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t}));return a.xhr=n,a},_parseResponse:(t,e)=>200!==t.status?{status:t.status,statusText:t.statusText,message:\`incorrect http request with status code(${e}t.status}): ${e}t.statusText}\`}:"arraybuffer"===e?t.arrayBuffer():"json"===e?t.json():t.text(),getArrayBuffer:(t,e={},r)=>(e||(e={}),e.responseType="arraybuffer",h.get(t,e,r)),getJSON:function(t,e={},r){return e&&e.jsonp?h.jsonp(t):((e=e||{}).responseType="json",h.get(t,e,r))},jsonp:function(t){const e="_maptalks_jsonp_"+o++;t.match(/\\?/)?t+="&callback="+e:t+="?callback="+e;let r=document.createElement("script");return r.type="text/javascript",r.src=t,new Promise((t=>{window[e]=function(n){document.getElementsByTagName("head")[0].removeChild(r),r=null,delete window[e],t(n)},document.getElementsByTagName("head")[0].appendChild(r)}))}};if("undefined"!=typeof TextDecoder&&new TextDecoder("utf-8"),"undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(n){}}"undefined"!=typeof document&&document.createElement("canvas"),
34594
- /** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */function(){function t(t){throw t}var e=void 0,r=!0,n=this;function i(t,r){var i,s=t.split("."),a=n;!(s[0]in a)&&a.execScript&&a.execScript("var "+s[0]);for(;s.length&&(i=s.shift());)s.length||r===e?a=a[i]?a[i]:a[i]={}:a[i]=r}var s="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array&&"undefined"!=typeof DataView;function a(e,r){this.index="number"==typeof r?r:0,this.i=0,this.buffer=e instanceof(s?Uint8Array:Array)?e:new(s?Uint8Array:Array)(32768),2*this.buffer.length<=this.index&&t(Error("invalid index")),this.buffer.length<=this.index&&this.f()}a.prototype.f=function(){var t,e=this.buffer,r=e.length,n=new(s?Uint8Array:Array)(r<<1);if(s)n.set(e);else for(t=0;t<r;++t)n[t]=e[t];return this.buffer=n},a.prototype.d=function(t,e,r){var n,i=this.buffer,s=this.index,a=this.i,o=i[s];if(r&&1<e&&(t=8<e?(u[255&t]<<24|u[t>>>8&255]<<16|u[t>>>16&255]<<8|u[t>>>24&255])>>32-e:u[t]>>8-e),8>e+a)o=o<<e|t,a+=e;else for(n=0;n<e;++n)o=o<<1|t>>e-n-1&1,8==++a&&(a=0,i[s++]=u[o],o=0,s===i.length&&(i=this.f()));i[s]=o,this.buffer=i,this.i=a,this.index=s},a.prototype.finish=function(){var t,e=this.buffer,r=this.index;return 0<this.i&&(e[r]<<=8-this.i,e[r]=u[e[r]],r++),s?t=e.subarray(0,r):(e.length=r,t=e),t};var o,h=new(s?Uint8Array:Array)(256);for(o=0;256>o;++o){for(var c=l=o,f=7,l=l>>>1;l;l>>>=1)c<<=1,c|=1&l,--f;h[o]=(c<<f&255)>>>0}var u=h;function g(t){this.buffer=new(s?Uint16Array:Array)(2*t),this.length=0}function d(t){var e,r,n,i,a,o,h,c,f,l,u=t.length,g=0,d=Number.POSITIVE_INFINITY;for(c=0;c<u;++c)t[c]>g&&(g=t[c]),t[c]<d&&(d=t[c]);for(e=1<<g,r=new(s?Uint32Array:Array)(e),n=1,i=0,a=2;n<=g;){for(c=0;c<u;++c)if(t[c]===n){for(o=0,h=i,f=0;f<n;++f)o=o<<1|1&h,h>>=1;for(l=n<<16|c,f=o;f<e;f+=a)r[f]=l;++i}++n,i<<=1,a<<=1}return[r,g,d]}function p(t,e){this.h=m,this.w=0,this.input=s&&t instanceof Array?new Uint8Array(t):t,this.b=0,e&&(e.lazy&&(this.w=e.lazy),"number"==typeof e.compressionType&&(this.h=e.compressionType),e.outputBuffer&&(this.a=s&&e.outputBuffer instanceof Array?new Uint8Array(e.outputBuffer):e.outputBuffer),"number"==typeof e.outputIndex&&(this.b=e.outputIndex)),this.a||(this.a=new(s?Uint8Array:Array)(32768))}g.prototype.getParent=function(t){return 2*((t-2)/4|0)},g.prototype.push=function(t,e){var r,n,i,s=this.buffer;for(r=this.length,s[this.length++]=e,s[this.length++]=t;0<r&&(n=this.getParent(r),s[r]>s[n]);)i=s[r],s[r]=s[n],s[n]=i,i=s[r+1],s[r+1]=s[n+1],s[n+1]=i,r=n;return this.length},g.prototype.pop=function(){var t,e,r,n,i,s=this.buffer;for(e=s[0],t=s[1],this.length-=2,s[0]=s[this.length],s[1]=s[this.length+1],i=0;!((n=2*i+2)>=this.length)&&(n+2<this.length&&s[n+2]>s[n]&&(n+=2),s[n]>s[i]);)r=s[i],s[i]=s[n],s[n]=r,r=s[i+1],s[i+1]=s[n+1],s[n+1]=r,i=n;return{index:t,value:e,length:this.length}};var y,m=2,b={NONE:0,r:1,k:m,N:3},w=[];for(y=0;288>y;y++)switch(r){case 143>=y:w.push([y+48,8]);break;case 255>=y:w.push([y-144+400,9]);break;case 279>=y:w.push([y-256+0,7]);break;case 287>=y:w.push([y-280+192,8]);break;default:t("invalid literal: "+y)}function A(t,e){this.length=t,this.G=e}p.prototype.j=function(){var n,i,o,h,c=this.input;switch(this.h){case 0:for(o=0,h=c.length;o<h;){var f,l,u,g=i=s?c.subarray(o,o+65535):c.slice(o,o+65535),d=(o+=i.length)===h,p=e,y=e,b=this.a,A=this.b;if(s){for(b=new Uint8Array(this.a.buffer);b.length<=A+g.length+5;)b=new Uint8Array(b.length<<1);b.set(this.a)}if(f=d?1:0,b[A++]=0|f,u=65536+~(l=g.length)&65535,b[A++]=255&l,b[A++]=l>>>8&255,b[A++]=255&u,b[A++]=u>>>8&255,s)b.set(g,A),A+=g.length,b=b.subarray(0,A);else{for(p=0,y=g.length;p<y;++p)b[A++]=g[p];b.length=A}this.b=A,this.a=b}break;case 1:var v=new a(s?new Uint8Array(this.a.buffer):this.a,this.b);v.d(1,1,r),v.d(1,2,r);var k,x,M,I=E(this,c);for(k=0,x=I.length;k<x;k++)if(M=I[k],a.prototype.d.apply(v,w[M]),256<M)v.d(I[++k],I[++k],r),v.d(I[++k],5),v.d(I[++k],I[++k],r);else if(256===M)break;this.a=v.finish(),this.b=this.a.length;break;case m:var S,D,F,B,z,N,_,C,O,R,P,j,q,L,H,Y=new a(s?new Uint8Array(this.a.buffer):this.a,this.b),W=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],V=Array(19);for(S=m,Y.d(1,1,r),Y.d(S,2,r),D=E(this,c),_=U(N=T(this.L,15)),O=U(C=T(this.K,7)),F=286;257<F&&0===N[F-1];F--);for(B=30;1<B&&0===C[B-1];B--);var Z,G,$,J,K,X,Q=F,tt=B,et=new(s?Uint32Array:Array)(Q+tt),rt=new(s?Uint32Array:Array)(316),nt=new(s?Uint8Array:Array)(19);for(Z=G=0;Z<Q;Z++)et[G++]=N[Z];for(Z=0;Z<tt;Z++)et[G++]=C[Z];if(!s)for(Z=0,J=nt.length;Z<J;++Z)nt[Z]=0;for(Z=K=0,J=et.length;Z<J;Z+=G){for(G=1;Z+G<J&&et[Z+G]===et[Z];++G);if($=G,0===et[Z])if(3>$)for(;0<$--;)rt[K++]=0,nt[0]++;else for(;0<$;)(X=138>$?$:138)>$-3&&X<$&&(X=$-3),10>=X?(rt[K++]=17,rt[K++]=X-3,nt[17]++):(rt[K++]=18,rt[K++]=X-11,nt[18]++),$-=X;else if(rt[K++]=et[Z],nt[et[Z]]++,3>--$)for(;0<$--;)rt[K++]=et[Z],nt[et[Z]]++;else for(;0<$;)(X=6>$?$:6)>$-3&&X<$&&(X=$-3),rt[K++]=16,rt[K++]=X-3,nt[16]++,$-=X}for(n=s?rt.subarray(0,K):rt.slice(0,K),R=T(nt,7),L=0;19>L;L++)V[L]=R[W[L]];for(z=19;4<z&&0===V[z-1];z--);for(P=U(R),Y.d(F-257,5,r),Y.d(B-1,5,r),Y.d(z-4,4,r),L=0;L<z;L++)Y.d(V[L],3,r);for(L=0,H=n.length;L<H;L++)if(j=n[L],Y.d(P[j],R[j],r),16<=j){switch(L++,j){case 16:q=2;break;case 17:q=3;break;case 18:q=7;break;default:t("invalid code: "+j)}Y.d(n[L],q,r)}var it,st,at,ot,ht,ct,ft,lt,ut=[_,N],gt=[O,C];for(ht=ut[0],ct=ut[1],ft=gt[0],lt=gt[1],it=0,st=D.length;it<st;++it)if(at=D[it],Y.d(ht[at],ct[at],r),256<at)Y.d(D[++it],D[++it],r),ot=D[++it],Y.d(ft[ot],lt[ot],r),Y.d(D[++it],D[++it],r);else if(256===at)break;this.a=Y.finish(),this.b=this.a.length;break;default:t("invalid compression type")}return this.a};var v=function(){function e(e){switch(r){case 3===e:return[257,e-3,0];case 4===e:return[258,e-4,0];case 5===e:return[259,e-5,0];case 6===e:return[260,e-6,0];case 7===e:return[261,e-7,0];case 8===e:return[262,e-8,0];case 9===e:return[263,e-9,0];case 10===e:return[264,e-10,0];case 12>=e:return[265,e-11,1];case 14>=e:return[266,e-13,1];case 16>=e:return[267,e-15,1];case 18>=e:return[268,e-17,1];case 22>=e:return[269,e-19,2];case 26>=e:return[270,e-23,2];case 30>=e:return[271,e-27,2];case 34>=e:return[272,e-31,2];case 42>=e:return[273,e-35,3];case 50>=e:return[274,e-43,3];case 58>=e:return[275,e-51,3];case 66>=e:return[276,e-59,3];case 82>=e:return[277,e-67,4];case 98>=e:return[278,e-83,4];case 114>=e:return[279,e-99,4];case 130>=e:return[280,e-115,4];case 162>=e:return[281,e-131,5];case 194>=e:return[282,e-163,5];case 226>=e:return[283,e-195,5];case 257>=e:return[284,e-227,5];case 258===e:return[285,e-258,0];default:t("invalid length: "+e)}}var n,i,s=[];for(n=3;258>=n;n++)i=e(n),s[n]=i[2]<<24|i[1]<<16|i[0];return s}(),k=s?new Uint32Array(v):v;function E(n,i){function a(e,n){var i,s,a,o,h=e.G,c=[],f=0;switch(i=k[e.length],c[f++]=65535&i,c[f++]=i>>16&255,c[f++]=i>>24,r){case 1===h:s=[0,h-1,0];break;case 2===h:s=[1,h-2,0];break;case 3===h:s=[2,h-3,0];break;case 4===h:s=[3,h-4,0];break;case 6>=h:s=[4,h-5,1];break;case 8>=h:s=[5,h-7,1];break;case 12>=h:s=[6,h-9,2];break;case 16>=h:s=[7,h-13,2];break;case 24>=h:s=[8,h-17,3];break;case 32>=h:s=[9,h-25,3];break;case 48>=h:s=[10,h-33,4];break;case 64>=h:s=[11,h-49,4];break;case 96>=h:s=[12,h-65,5];break;case 128>=h:s=[13,h-97,5];break;case 192>=h:s=[14,h-129,6];break;case 256>=h:s=[15,h-193,6];break;case 384>=h:s=[16,h-257,7];break;case 512>=h:s=[17,h-385,7];break;case 768>=h:s=[18,h-513,8];break;case 1024>=h:s=[19,h-769,8];break;case 1536>=h:s=[20,h-1025,9];break;case 2048>=h:s=[21,h-1537,9];break;case 3072>=h:s=[22,h-2049,10];break;case 4096>=h:s=[23,h-3073,10];break;case 6144>=h:s=[24,h-4097,11];break;case 8192>=h:s=[25,h-6145,11];break;case 12288>=h:s=[26,h-8193,12];break;case 16384>=h:s=[27,h-12289,12];break;case 24576>=h:s=[28,h-16385,13];break;case 32768>=h:s=[29,h-24577,13];break;default:t("invalid distance")}for(i=s,c[f++]=i[0],c[f++]=i[1],c[f++]=i[2],a=0,o=c.length;a<o;++a)m[b++]=c[a];A[c[0]]++,v[c[3]]++,w=e.length+n-1,d=null}var o,h,c,f,l,u,g,d,p,y={},m=s?new Uint16Array(2*i.length):[],b=0,w=0,A=new(s?Uint32Array:Array)(286),v=new(s?Uint32Array:Array)(30),E=n.w;if(!s){for(c=0;285>=c;)A[c++]=0;for(c=0;29>=c;)v[c++]=0}for(A[256]=1,o=0,h=i.length;o<h;++o){for(c=l=0,f=3;c<f&&o+c!==h;++c)l=l<<8|i[o+c];if(y[l]===e&&(y[l]=[]),u=y[l],!(0<w--)){for(;0<u.length&&32768<o-u[0];)u.shift();if(o+3>=h){for(d&&a(d,-1),c=0,f=h-o;c<f;++c)p=i[o+c],m[b++]=p,++A[p];break}0<u.length?(g=x(i,o,u),d?d.length<g.length?(p=i[o-1],m[b++]=p,++A[p],a(g,0)):a(d,-1):g.length<E?d=g:a(g,0)):d?a(d,-1):(p=i[o],m[b++]=p,++A[p])}u.push(o)}return m[b++]=256,A[256]++,n.L=A,n.K=v,s?m.subarray(0,b):m}function x(t,e,r){var n,i,s,a,o,h,c=0,f=t.length;a=0,h=r.length;t:for(;a<h;a++){if(n=r[h-a-1],s=3,3<c){for(o=c;3<o;o--)if(t[n+o-1]!==t[e+o-1])continue t;s=c}for(;258>s&&e+s<f&&t[n+s]===t[e+s];)++s;if(s>c&&(i=n,c=s),258===s)break}return new A(c,e-i)}function T(t,e){var r,n,i,a,o,h=t.length,c=new g(572),f=new(s?Uint8Array:Array)(h);if(!s)for(a=0;a<h;a++)f[a]=0;for(a=0;a<h;++a)0<t[a]&&c.push(a,t[a]);if(r=Array(c.length/2),n=new(s?Uint32Array:Array)(c.length/2),1===r.length)return f[c.pop().index]=1,f;for(a=0,o=c.length/2;a<o;++a)r[a]=c.pop(),n[a]=r[a].value;for(i=function(t,e,r){function n(t){var r=d[t][p[t]];r===e?(n(t+1),n(t+1)):--u[r],++p[t]}var i,a,o,h,c,f=new(s?Uint16Array:Array)(r),l=new(s?Uint8Array:Array)(r),u=new(s?Uint8Array:Array)(e),g=Array(r),d=Array(r),p=Array(r),y=(1<<r)-e,m=1<<r-1;for(f[r-1]=e,a=0;a<r;++a)y<m?l[a]=0:(l[a]=1,y-=m),y<<=1,f[r-2-a]=(f[r-1-a]/2|0)+e;for(f[0]=l[0],g[0]=Array(f[0]),d[0]=Array(f[0]),a=1;a<r;++a)f[a]>2*f[a-1]+l[a]&&(f[a]=2*f[a-1]+l[a]),g[a]=Array(f[a]),d[a]=Array(f[a]);for(i=0;i<e;++i)u[i]=r;for(o=0;o<f[r-1];++o)g[r-1][o]=t[o],d[r-1][o]=o;for(i=0;i<r;++i)p[i]=0;for(1===l[r-1]&&(--u[0],++p[r-1]),a=r-2;0<=a;--a){for(h=i=0,c=p[a+1],o=0;o<f[a];o++)(h=g[a+1][c]+g[a+1][c+1])>t[i]?(g[a][o]=h,d[a][o]=e,c+=2):(g[a][o]=t[i],d[a][o]=i,++i);p[a]=0,1===l[a]&&n(a)}return u}(n,n.length,e),a=0,o=r.length;a<o;++a)f[r[a].index]=i[a];return f}function U(t){var e,r,n,i,a=new(s?Uint16Array:Array)(t.length),o=[],h=[],c=0;for(e=0,r=t.length;e<r;e++)o[t[e]]=1+(0|o[t[e]]);for(e=1,r=16;e<=r;e++)h[e]=c,c+=0|o[e],c<<=1;for(e=0,r=t.length;e<r;e++)for(c=h[t[e]],h[t[e]]+=1,n=a[e]=0,i=t[e];n<i;n++)a[e]=a[e]<<1|1&c,c>>>=1;return a}function M(e,r){switch(this.l=[],this.m=32768,this.e=this.g=this.c=this.q=0,this.input=s?new Uint8Array(e):e,this.s=!1,this.n=S,this.B=!1,!r&&(r={})||(r.index&&(this.c=r.index),r.bufferSize&&(this.m=r.bufferSize),r.bufferType&&(this.n=r.bufferType),r.resize&&(this.B=r.resize)),this.n){case I:this.b=32768,this.a=new(s?Uint8Array:Array)(32768+this.m+258);break;case S:this.b=0,this.a=new(s?Uint8Array:Array)(this.m),this.f=this.J,this.t=this.H,this.o=this.I;break;default:t(Error("invalid inflate mode"))}}var I=0,S=1,D={D:I,C:S};M.prototype.p=function(){for(;!this.s;){var n=$(this,3);switch(1&n&&(this.s=r),n>>>=1){case 0:var i=this.input,a=this.c,o=this.a,h=this.b,c=i.length,f=e,l=o.length,u=e;switch(this.e=this.g=0,a+1>=c&&t(Error("invalid uncompressed block header: LEN")),f=i[a++]|i[a++]<<8,a+1>=c&&t(Error("invalid uncompressed block header: NLEN")),f===~(i[a++]|i[a++]<<8)&&t(Error("invalid uncompressed block header: length verify")),a+f>i.length&&t(Error("input buffer is broken")),this.n){case I:for(;h+f>o.length;){if(f-=u=l-h,s)o.set(i.subarray(a,a+u),h),h+=u,a+=u;else for(;u--;)o[h++]=i[a++];this.b=h,o=this.f(),h=this.b}break;case S:for(;h+f>o.length;)o=this.f({v:2});break;default:t(Error("invalid inflate mode"))}if(s)o.set(i.subarray(a,a+f),h),h+=f,a+=f;else for(;f--;)o[h++]=i[a++];this.c=a,this.b=h,this.a=o;break;case 1:this.o(V,G);break;case 2:var g,p,y,m,b=$(this,5)+257,w=$(this,5)+1,A=$(this,4)+4,v=new(s?Uint8Array:Array)(N.length),k=e,E=e,x=e,T=e,U=e;for(U=0;U<A;++U)v[N[U]]=$(this,3);if(!s)for(U=A,A=v.length;U<A;++U)v[N[U]]=0;for(g=d(v),k=new(s?Uint8Array:Array)(b+w),U=0,m=b+w;U<m;)switch(E=J(this,g),E){case 16:for(T=3+$(this,2);T--;)k[U++]=x;break;case 17:for(T=3+$(this,3);T--;)k[U++]=0;x=0;break;case 18:for(T=11+$(this,7);T--;)k[U++]=0;x=0;break;default:x=k[U++]=E}p=d(s?k.subarray(0,b):k.slice(0,b)),y=d(s?k.subarray(b):k.slice(b)),this.o(p,y);break;default:t(Error("unknown BTYPE: "+n))}}return this.t()};var F,B,z=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],N=s?new Uint16Array(z):z,_=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],C=s?new Uint16Array(_):_,O=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],R=s?new Uint8Array(O):O,P=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],j=s?new Uint16Array(P):P,q=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],L=s?new Uint8Array(q):q,H=new(s?Uint8Array:Array)(288);for(F=0,B=H.length;F<B;++F)H[F]=143>=F?8:255>=F?9:279>=F?7:8;var Y,W,V=d(H),Z=new(s?Uint8Array:Array)(30);for(Y=0,W=Z.length;Y<W;++Y)Z[Y]=5;var G=d(Z);function $(e,r){for(var n,i=e.g,s=e.e,a=e.input,o=e.c,h=a.length;s<r;)o>=h&&t(Error("input buffer is broken")),i|=a[o++]<<s,s+=8;return n=i&(1<<r)-1,e.g=i>>>r,e.e=s-r,e.c=o,n}function J(e,r){for(var n,i,s=e.g,a=e.e,o=e.input,h=e.c,c=o.length,f=r[0],l=r[1];a<l&&!(h>=c);)s|=o[h++]<<a,a+=8;return(i=(n=f[s&(1<<l)-1])>>>16)>a&&t(Error("invalid code length: "+i)),e.g=s>>i,e.e=a-i,e.c=h,65535&n}function K(t){if("string"==typeof t){var e,r,n=t.split("");for(e=0,r=n.length;e<r;e++)n[e]=(255&n[e].charCodeAt(0))>>>0;t=n}for(var i,s=1,a=0,o=t.length,h=0;0<o;){o-=i=1024<o?1024:o;do{a+=s+=t[h++]}while(--i);s%=65521,a%=65521}return(a<<16|s)>>>0}function X(e,r){var n,i;if(this.input=e,this.c=0,!r&&(r={})||(r.index&&(this.c=r.index),r.verify&&(this.M=r.verify)),n=e[this.c++],i=e[this.c++],(15&n)===Q)this.method=Q;else t(Error("unsupported compression method"));0!=((n<<8)+i)%31&&t(Error("invalid fcheck flag:"+((n<<8)+i)%31)),32&i&&t(Error("fdict flag is not supported")),this.A=new M(e,{index:this.c,bufferSize:r.bufferSize,bufferType:r.bufferType,resize:r.resize})}M.prototype.o=function(t,e){var r=this.a,n=this.b;this.u=t;for(var i,s,a,o,h=r.length-258;256!==(i=J(this,t));)if(256>i)n>=h&&(this.b=n,r=this.f(),n=this.b),r[n++]=i;else for(o=C[s=i-257],0<R[s]&&(o+=$(this,R[s])),i=J(this,e),a=j[i],0<L[i]&&(a+=$(this,L[i])),n>=h&&(this.b=n,r=this.f(),n=this.b);o--;)r[n]=r[n++-a];for(;8<=this.e;)this.e-=8,this.c--;this.b=n},M.prototype.I=function(t,e){var r=this.a,n=this.b;this.u=t;for(var i,s,a,o,h=r.length;256!==(i=J(this,t));)if(256>i)n>=h&&(h=(r=this.f()).length),r[n++]=i;else for(o=C[s=i-257],0<R[s]&&(o+=$(this,R[s])),i=J(this,e),a=j[i],0<L[i]&&(a+=$(this,L[i])),n+o>h&&(h=(r=this.f()).length);o--;)r[n]=r[n++-a];for(;8<=this.e;)this.e-=8,this.c--;this.b=n},M.prototype.f=function(){var t,e,r=new(s?Uint8Array:Array)(this.b-32768),n=this.b-32768,i=this.a;if(s)r.set(i.subarray(32768,r.length));else for(t=0,e=r.length;t<e;++t)r[t]=i[t+32768];if(this.l.push(r),this.q+=r.length,s)i.set(i.subarray(n,n+32768));else for(t=0;32768>t;++t)i[t]=i[n+t];return this.b=32768,i},M.prototype.J=function(t){var e,r,n,i=this.input.length/this.c+1|0,a=this.input,o=this.a;return t&&("number"==typeof t.v&&(i=t.v),"number"==typeof t.F&&(i+=t.F)),2>i?r=(n=(a.length-this.c)/this.u[2]/2*258|0)<o.length?o.length+n:o.length<<1:r=o.length*i,s?(e=new Uint8Array(r)).set(o):e=o,this.a=e},M.prototype.t=function(){var t,e,r,n,i,a=0,o=this.a,h=this.l,c=new(s?Uint8Array:Array)(this.q+(this.b-32768));if(0===h.length)return s?this.a.subarray(32768,this.b):this.a.slice(32768,this.b);for(e=0,r=h.length;e<r;++e)for(n=0,i=(t=h[e]).length;n<i;++n)c[a++]=t[n];for(e=32768,r=this.b;e<r;++e)c[a++]=o[e];return this.l=[],this.buffer=c},M.prototype.H=function(){var t,e=this.b;return s?this.B?(t=new Uint8Array(e)).set(this.a.subarray(0,e)):t=this.a.subarray(0,e):(this.a.length>e&&(this.a.length=e),t=this.a),this.buffer=t},X.prototype.p=function(){var e,r=this.input;return e=this.A.p(),this.c=this.A.c,this.M&&((r[this.c++]<<24|r[this.c++]<<16|r[this.c++]<<8|r[this.c++])>>>0!==K(e)&&t(Error("invalid adler-32 checksum"))),e};var Q=8;function tt(t,e){this.input=t,this.a=new(s?Uint8Array:Array)(32768),this.h=et.k;var r,n={};for(r in!e&&(e={})||"number"!=typeof e.compressionType||(this.h=e.compressionType),e)n[r]=e[r];n.outputBuffer=this.a,this.z=new p(this.input,n)}var et=b;function rt(t,e){var r,n,s,a;if(Object.keys)r=Object.keys(e);else for(n in r=[],s=0,e)r[s++]=n;for(s=0,a=r.length;s<a;++s)i(t+"."+(n=r[s]),e[n])}tt.prototype.j=function(){var e,r,n,i,a,o,h,c=0;if(h=this.a,(e=Q)===Q)r=Math.LOG2E*Math.log(32768)-8;else t(Error("invalid compression method"));if(n=r<<4|e,h[c++]=n,e===Q)switch(this.h){case et.NONE:a=0;break;case et.r:a=1;break;case et.k:a=2;break;default:t(Error("unsupported compression type"))}else t(Error("invalid compression method"));return i=a<<6,h[c++]=i|31-(256*n+i)%31,o=K(this.input),this.z.b=c,c=(h=this.z.j()).length,s&&((h=new Uint8Array(h.buffer)).length<=c+4&&(this.a=new Uint8Array(h.length+4),this.a.set(h),h=this.a),h=h.subarray(0,c+4)),h[c++]=o>>24&255,h[c++]=o>>16&255,h[c++]=o>>8&255,h[c++]=255&o,h},i("Zlib.Inflate",X),i("Zlib.Inflate.prototype.decompress",X.prototype.p),rt("Zlib.Inflate.BufferType",{ADAPTIVE:D.C,BLOCK:D.D}),i("Zlib.Deflate",tt),i("Zlib.Deflate.compress",(function(t,e){return new tt(t,e).j()})),i("Zlib.Deflate.prototype.compress",tt.prototype.j),rt("Zlib.Deflate.CompressionType",{NONE:et.NONE,FIXED:et.r,DYNAMIC:et.k})}.call(self);var c="undefined"!=typeof Float32Array?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var f,l=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t};function u(t,e,r){return t[0]=e,t[1]=r,t}f=new c(3),c!=Float32Array&&(f[0]=0,f[1]=0,f[2]=0),function(){var t=function(){var t=new c(2);return c!=Float32Array&&(t[0]=0,t[1]=0),t}()}();class g{constructor(t=257){this.gridSize=t;const e=t-1;if(e&e-1)throw new Error(\`Expected grid size to be 2^n+1, got ${e}t}.\`);this.numTriangles=e*e*2-2,this.numParentTriangles=this.numTriangles-e*e,this.indices=new Uint32Array(this.gridSize*this.gridSize),this.coords=new Uint16Array(4*this.numTriangles);for(let t=0;t<this.numTriangles;t++){let r=t+2,n=0,i=0,s=0,a=0,o=0,h=0;for(1&r?s=a=o=e:n=i=h=e;(r>>=1)>1;){const t=n+s>>1,e=i+a>>1;1&r?(s=n,a=i,n=o,i=h):(n=s,i=a,s=o,a=h),o=t,h=e}const c=4*t;this.coords[c+0]=n,this.coords[c+1]=i,this.coords[c+2]=s,this.coords[c+3]=a}}createTile(t){return new d(t,this)}}class d{constructor(t,e){const r=e.gridSize;if(t.length!==r*r)throw new Error(\`Expected terrain data of length ${e}r*r} (${e}r} x ${e}r}), got ${e}t.length}.\`);this.terrain=t,this.martini=e,this.errors=new Float32Array(t.length),this.update()}update(){const{numTriangles:t,numParentTriangles:e,coords:r,gridSize:n}=this.martini,{terrain:i,errors:s}=this;for(let a=t-1;a>=0;a--){const t=4*a,o=r[t+0],h=r[t+1],c=r[t+2],f=r[t+3],l=o+c>>1,u=h+f>>1,g=l+u-h,d=u+o-l,p=(i[h*n+o]+i[f*n+c])/2,y=u*n+l,m=Math.abs(p-i[y]);if(s[y]=Math.max(s[y],m),a<e){const t=(h+d>>1)*n+(o+g>>1),e=(f+d>>1)*n+(c+g>>1);s[y]=Math.max(s[y],s[t],s[e])}}}getMesh(t=0){const{gridSize:e,indices:r}=this.martini,{errors:n}=this;let i=0,s=0;const a=e-1;function o(a,h,c,f,l,u){const g=a+c>>1,d=h+f>>1;Math.abs(a-l)+Math.abs(h-u)>1&&n[d*e+g]>t?(o(l,u,a,h,g,d),o(c,f,l,u,g,d)):(r[h*e+a]=r[h*e+a]||++i,r[f*e+c]=r[f*e+c]||++i,r[u*e+l]=r[u*e+l]||++i,s++)}r.fill(0),o(0,0,a,a,a,0),o(a,a,0,0,0,a);const h=new Uint16Array(2*i),c=new Uint32Array(3*s);let f=0;function l(i,s,a,o,u,g){const d=i+a>>1,p=s+o>>1;if(Math.abs(i-u)+Math.abs(s-g)>1&&n[p*e+d]>t)l(u,g,i,s,d,p),l(a,o,u,g,d,p);else{const t=r[s*e+i]-1,n=r[o*e+a]-1,l=r[g*e+u]-1;h[2*t]=i,h[2*t+1]=s,h[2*n]=a,h[2*n+1]=o,h[2*l]=u,h[2*l+1]=g,c[f++]=t,c[f++]=n,c[f++]=l}}return l(0,0,a,a,a,0),l(a,a,0,0,0,a),{vertices:h,triangles:c}}getMeshWithSkirts(t=0,e){const{gridSize:r,indices:n}=this.martini,{errors:i}=this;let s=0,a=0;const o=r-1;let h,c,f=0;const l=[],u=[],g=[],d=[];function p(e,y,m,b,w,A){const v=e+m>>1,k=y+b>>1;Math.abs(e-w)+Math.abs(y-A)>1&&i[k*r+v]>t?(p(w,A,e,y,v,k),p(m,b,w,A,v,k)):(h=y*r+e,c=b*r+m,f=A*r+w,0===n[h]&&(0===e?l.push(s):e===o&&u.push(s),0===y?g.push(s):y===o&&d.push(s),n[h]=++s),0===n[c]&&(0===m?l.push(s):m===o&&u.push(s),0===b?g.push(s):b===o&&d.push(s),n[c]=++s),0===n[f]&&(0===w?l.push(s):w===o&&u.push(s),0===A?g.push(s):A===o&&d.push(s),n[f]=++s),a++)}let y;n.fill(0),p(0,0,o,o,o,0),p(o,o,0,0,0,o),y=e?2*(s+3*l.length-2+3*u.length-2+3*g.length-2+3*d.length-2):2*(s+l.length+u.length+g.length+d.length);const m=3*(a+2*(l.length-1)+2*(u.length-1)+2*(g.length-1)+2*(d.length-1)),b=new Uint16Array(y),w=new Uint32Array(m);let A=0;function v(e,s,a,o,h,c){const f=e+a>>1,l=s+o>>1;if(Math.abs(e-h)+Math.abs(s-c)>1&&i[l*r+f]>t)v(h,c,e,s,f,l),v(a,o,h,c,f,l);else{const t=n[s*r+e]-1,i=n[o*r+a]-1,f=n[c*r+h]-1;b[2*t]=e,b[2*t+1]=s,b[2*i]=a,b[2*i+1]=o,b[2*f]=h,b[2*f+1]=c,w[A++]=t,w[A++]=i,w[A++]=f}}v(0,0,o,o,o,0),v(o,o,0,0,0,o),l.sort(((t,e)=>b[2*t+1]-b[2*e+1])),u.sort(((t,e)=>b[2*e+1]-b[2*t+1])),g.sort(((t,e)=>b[2*e]-b[2*t])),d.sort(((t,e)=>b[2*t]-b[2*e]));let k,E,x,T,U=2*s,M=0;function I(t){M=t.length;for(let r=0;r<M-1;r++)k=t[r],E=t[r+1],x=U/2,T=(U+(e?6:2))/2,b[U++]=2*k,b[U++]=2*k+1,e&&(b[U++]=2*k,b[U++]=2*k+1,b[U++]=2*E,b[U++]=2*E+1),e?(w[A++]=x+1,w[A++]=x,w[A++]=x+2,w[A++]=x,w[A++]=T,w[A++]=x+2):(w[A++]=k,w[A++]=x,w[A++]=E,w[A++]=x,w[A++]=T,w[A++]=E);b[U++]=2*t[M-1],b[U++]=2*t[M-1]+1}I(l);const S=U;I(u);const D=U;I(g);const F=U;I(d);return{vertices:b,triangles:w,numVerticesWithoutSkirts:s,numTrianglesWithoutSkirts:a,leftSkirtIndex:S,rightSkirtIndex:D,bottomSkirtIndex:F,topSkirtIndex:U}}}const p={};let y;const m={width:100,height:10};let b=!1;try{const t=new OffscreenCanvas(1,1);t.getContext("2d").fillText("hello",0,0),b=!0}catch(t){b=!1}function w(){if(!y){const{width:t,height:e}=m;b?y=new OffscreenCanvas(t,e):(y=document.createElement("canvas"),y.width=t,y.height=e)}return y}class A{constructor(t,e={}){if(!Array.isArray(t))return void console.error("colors is not array");if(t.length<2)return void console.error("colors.length should >1");this.colors=t;let r=1/0,n=-1/0;for(let e=0,i=t.length;e<i;e++){const i=t[e][0];r=Math.min(i,r),n=Math.max(i,n)}this.min=r,this.max=n,this.valueOffset=this.max-this.min,this.options=Object.assign({},m,e),this._initImgData()}getImageData(){return this.imgData}_initImgData(){const t=w(),{width:e,height:r}=this.options;t.width=e,t.height=r;const n=t.getContext("2d");n.clearRect(0,0,t.width,t.height);const i=n.createLinearGradient(0,0,t.width,0),{colors:s,valueOffset:a}=this;for(let t=0,e=s.length;t<e;t++){const[e,r]=s[t],n=(e-this.min)/a;i.addColorStop(n,r)}n.fillStyle=i,n.fillRect(0,0,t.width,t.height),this.imgData=n.getImageData(0,0,t.width,t.height)}getColor(t){t=Math.max(this.min,t);const e=((t=Math.min(t,this.max))-this.min)/this.valueOffset;let r=Math.round(e*this.imgData.width);r=Math.min(r,this.imgData.width-1);const n=4*r;return[this.imgData.data[n],this.imgData.data[n+1],this.imgData.data[n+2],this.imgData.data[n+3]]}}var v="undefined"!=typeof Float32Array?Float32Array:Array;function k(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function E(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function x(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function T(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}var U=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t};
34943
+ var e,r,n="undefined"!=typeof Float32Array?Float32Array:Array;function i(){var t=new n(3);return n!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function s(t,e,r){var i=new n(3);return i[0]=t,i[1]=e,i[2]=r,i}function a(){var t=new n(4);return n!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)}),i(),e=new n(4),n!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),i(),s(1,0,0),s(0,1,0),a(),a(),r=new n(9),n!=Float32Array&&(r[1]=0,r[2]=0,r[3]=0,r[5]=0,r[6]=0,r[7]=0),r[0]=1,r[4]=1,r[8]=1;let o=0;function h(t){for(let e=1;e<arguments.length;e++){const r=arguments[e];for(const e in r)t[e]=r[e]}return t}!function(t){t[0]=0,t[1]=0,t[2]=0,t[3]=1}([]),"undefined"!=typeof TextDecoder&&new TextDecoder("utf-8");const c={get:function(t,e={},r){e||(e={}),e=h({},e);const n=new AbortController,i=n.signal,s=h({},e);s.signal=i,s.method||(s.method="GET"),s.referrerPolicy=s.referrerPolicy||"origin","undefined"==typeof window||s.referrer||(s.referrer=window.location.href),r&&(t=r(t));const a=fetch(t,s).then((t=>{const r=this._parseResponse(t,e.responseType);return r.message?r:r.then((r=>"arraybuffer"===e.responseType?{data:r,cacheControl:t.headers.get("Cache-Control"),expires:t.headers.get("Expires"),contentType:t.headers.get("Content-Type")}:r)).catch((t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t}))})).catch((t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t}));return a.xhr=n,a},_parseResponse:(t,e)=>200!==t.status?{status:t.status,statusText:t.statusText,message:\`incorrect http request with status code(${e}t.status}): ${e}t.statusText}\`}:"arraybuffer"===e?t.arrayBuffer():"json"===e?t.json():t.text(),getArrayBuffer:(t,e={},r)=>(e||(e={}),e.responseType="arraybuffer",c.get(t,e,r)),getJSON:function(t,e={},r){return e&&e.jsonp?c.jsonp(t):((e=e||{}).responseType="json",c.get(t,e,r))},jsonp:function(t){const e="_maptalks_jsonp_"+o++;t.match(/\\?/)?t+="&callback="+e:t+="?callback="+e;let r=document.createElement("script");return r.type="text/javascript",r.src=t,new Promise((t=>{window[e]=function(n){document.getElementsByTagName("head")[0].removeChild(r),r=null,delete window[e],t(n)},document.getElementsByTagName("head")[0].appendChild(r)}))}};if("undefined"!=typeof TextDecoder&&new TextDecoder("utf-8"),"undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(n){}}"undefined"!=typeof document&&document.createElement("canvas"),
34944
+ /** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */function(){function t(t){throw t}var e=void 0,r=!0,n=this;function i(t,r){var i,s=t.split("."),a=n;!(s[0]in a)&&a.execScript&&a.execScript("var "+s[0]);for(;s.length&&(i=s.shift());)s.length||r===e?a=a[i]?a[i]:a[i]={}:a[i]=r}var s="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array&&"undefined"!=typeof DataView;function a(e,r){this.index="number"==typeof r?r:0,this.i=0,this.buffer=e instanceof(s?Uint8Array:Array)?e:new(s?Uint8Array:Array)(32768),2*this.buffer.length<=this.index&&t(Error("invalid index")),this.buffer.length<=this.index&&this.f()}a.prototype.f=function(){var t,e=this.buffer,r=e.length,n=new(s?Uint8Array:Array)(r<<1);if(s)n.set(e);else for(t=0;t<r;++t)n[t]=e[t];return this.buffer=n},a.prototype.d=function(t,e,r){var n,i=this.buffer,s=this.index,a=this.i,o=i[s];if(r&&1<e&&(t=8<e?(u[255&t]<<24|u[t>>>8&255]<<16|u[t>>>16&255]<<8|u[t>>>24&255])>>32-e:u[t]>>8-e),8>e+a)o=o<<e|t,a+=e;else for(n=0;n<e;++n)o=o<<1|t>>e-n-1&1,8==++a&&(a=0,i[s++]=u[o],o=0,s===i.length&&(i=this.f()));i[s]=o,this.buffer=i,this.i=a,this.index=s},a.prototype.finish=function(){var t,e=this.buffer,r=this.index;return 0<this.i&&(e[r]<<=8-this.i,e[r]=u[e[r]],r++),s?t=e.subarray(0,r):(e.length=r,t=e),t};var o,h=new(s?Uint8Array:Array)(256);for(o=0;256>o;++o){for(var c=l=o,f=7,l=l>>>1;l;l>>>=1)c<<=1,c|=1&l,--f;h[o]=(c<<f&255)>>>0}var u=h;function g(t){this.buffer=new(s?Uint16Array:Array)(2*t),this.length=0}function d(t){var e,r,n,i,a,o,h,c,f,l,u=t.length,g=0,d=Number.POSITIVE_INFINITY;for(c=0;c<u;++c)t[c]>g&&(g=t[c]),t[c]<d&&(d=t[c]);for(e=1<<g,r=new(s?Uint32Array:Array)(e),n=1,i=0,a=2;n<=g;){for(c=0;c<u;++c)if(t[c]===n){for(o=0,h=i,f=0;f<n;++f)o=o<<1|1&h,h>>=1;for(l=n<<16|c,f=o;f<e;f+=a)r[f]=l;++i}++n,i<<=1,a<<=1}return[r,g,d]}function p(t,e){this.h=m,this.w=0,this.input=s&&t instanceof Array?new Uint8Array(t):t,this.b=0,e&&(e.lazy&&(this.w=e.lazy),"number"==typeof e.compressionType&&(this.h=e.compressionType),e.outputBuffer&&(this.a=s&&e.outputBuffer instanceof Array?new Uint8Array(e.outputBuffer):e.outputBuffer),"number"==typeof e.outputIndex&&(this.b=e.outputIndex)),this.a||(this.a=new(s?Uint8Array:Array)(32768))}g.prototype.getParent=function(t){return 2*((t-2)/4|0)},g.prototype.push=function(t,e){var r,n,i,s=this.buffer;for(r=this.length,s[this.length++]=e,s[this.length++]=t;0<r&&(n=this.getParent(r),s[r]>s[n]);)i=s[r],s[r]=s[n],s[n]=i,i=s[r+1],s[r+1]=s[n+1],s[n+1]=i,r=n;return this.length},g.prototype.pop=function(){var t,e,r,n,i,s=this.buffer;for(e=s[0],t=s[1],this.length-=2,s[0]=s[this.length],s[1]=s[this.length+1],i=0;!((n=2*i+2)>=this.length)&&(n+2<this.length&&s[n+2]>s[n]&&(n+=2),s[n]>s[i]);)r=s[i],s[i]=s[n],s[n]=r,r=s[i+1],s[i+1]=s[n+1],s[n+1]=r,i=n;return{index:t,value:e,length:this.length}};var y,m=2,b={NONE:0,r:1,k:m,N:3},w=[];for(y=0;288>y;y++)switch(r){case 143>=y:w.push([y+48,8]);break;case 255>=y:w.push([y-144+400,9]);break;case 279>=y:w.push([y-256+0,7]);break;case 287>=y:w.push([y-280+192,8]);break;default:t("invalid literal: "+y)}function A(t,e){this.length=t,this.G=e}p.prototype.j=function(){var n,i,o,h,c=this.input;switch(this.h){case 0:for(o=0,h=c.length;o<h;){var f,l,u,g=i=s?c.subarray(o,o+65535):c.slice(o,o+65535),d=(o+=i.length)===h,p=e,y=e,b=this.a,A=this.b;if(s){for(b=new Uint8Array(this.a.buffer);b.length<=A+g.length+5;)b=new Uint8Array(b.length<<1);b.set(this.a)}if(f=d?1:0,b[A++]=0|f,u=65536+~(l=g.length)&65535,b[A++]=255&l,b[A++]=l>>>8&255,b[A++]=255&u,b[A++]=u>>>8&255,s)b.set(g,A),A+=g.length,b=b.subarray(0,A);else{for(p=0,y=g.length;p<y;++p)b[A++]=g[p];b.length=A}this.b=A,this.a=b}break;case 1:var v=new a(s?new Uint8Array(this.a.buffer):this.a,this.b);v.d(1,1,r),v.d(1,2,r);var k,x,M,I=E(this,c);for(k=0,x=I.length;k<x;k++)if(M=I[k],a.prototype.d.apply(v,w[M]),256<M)v.d(I[++k],I[++k],r),v.d(I[++k],5),v.d(I[++k],I[++k],r);else if(256===M)break;this.a=v.finish(),this.b=this.a.length;break;case m:var S,D,F,B,z,N,_,C,O,R,P,j,q,L,H,Y=new a(s?new Uint8Array(this.a.buffer):this.a,this.b),W=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],V=Array(19);for(S=m,Y.d(1,1,r),Y.d(S,2,r),D=E(this,c),_=U(N=T(this.L,15)),O=U(C=T(this.K,7)),F=286;257<F&&0===N[F-1];F--);for(B=30;1<B&&0===C[B-1];B--);var Z,G,$,J,K,X,Q=F,tt=B,et=new(s?Uint32Array:Array)(Q+tt),rt=new(s?Uint32Array:Array)(316),nt=new(s?Uint8Array:Array)(19);for(Z=G=0;Z<Q;Z++)et[G++]=N[Z];for(Z=0;Z<tt;Z++)et[G++]=C[Z];if(!s)for(Z=0,J=nt.length;Z<J;++Z)nt[Z]=0;for(Z=K=0,J=et.length;Z<J;Z+=G){for(G=1;Z+G<J&&et[Z+G]===et[Z];++G);if($=G,0===et[Z])if(3>$)for(;0<$--;)rt[K++]=0,nt[0]++;else for(;0<$;)(X=138>$?$:138)>$-3&&X<$&&(X=$-3),10>=X?(rt[K++]=17,rt[K++]=X-3,nt[17]++):(rt[K++]=18,rt[K++]=X-11,nt[18]++),$-=X;else if(rt[K++]=et[Z],nt[et[Z]]++,3>--$)for(;0<$--;)rt[K++]=et[Z],nt[et[Z]]++;else for(;0<$;)(X=6>$?$:6)>$-3&&X<$&&(X=$-3),rt[K++]=16,rt[K++]=X-3,nt[16]++,$-=X}for(n=s?rt.subarray(0,K):rt.slice(0,K),R=T(nt,7),L=0;19>L;L++)V[L]=R[W[L]];for(z=19;4<z&&0===V[z-1];z--);for(P=U(R),Y.d(F-257,5,r),Y.d(B-1,5,r),Y.d(z-4,4,r),L=0;L<z;L++)Y.d(V[L],3,r);for(L=0,H=n.length;L<H;L++)if(j=n[L],Y.d(P[j],R[j],r),16<=j){switch(L++,j){case 16:q=2;break;case 17:q=3;break;case 18:q=7;break;default:t("invalid code: "+j)}Y.d(n[L],q,r)}var it,st,at,ot,ht,ct,ft,lt,ut=[_,N],gt=[O,C];for(ht=ut[0],ct=ut[1],ft=gt[0],lt=gt[1],it=0,st=D.length;it<st;++it)if(at=D[it],Y.d(ht[at],ct[at],r),256<at)Y.d(D[++it],D[++it],r),ot=D[++it],Y.d(ft[ot],lt[ot],r),Y.d(D[++it],D[++it],r);else if(256===at)break;this.a=Y.finish(),this.b=this.a.length;break;default:t("invalid compression type")}return this.a};var v=function(){function e(e){switch(r){case 3===e:return[257,e-3,0];case 4===e:return[258,e-4,0];case 5===e:return[259,e-5,0];case 6===e:return[260,e-6,0];case 7===e:return[261,e-7,0];case 8===e:return[262,e-8,0];case 9===e:return[263,e-9,0];case 10===e:return[264,e-10,0];case 12>=e:return[265,e-11,1];case 14>=e:return[266,e-13,1];case 16>=e:return[267,e-15,1];case 18>=e:return[268,e-17,1];case 22>=e:return[269,e-19,2];case 26>=e:return[270,e-23,2];case 30>=e:return[271,e-27,2];case 34>=e:return[272,e-31,2];case 42>=e:return[273,e-35,3];case 50>=e:return[274,e-43,3];case 58>=e:return[275,e-51,3];case 66>=e:return[276,e-59,3];case 82>=e:return[277,e-67,4];case 98>=e:return[278,e-83,4];case 114>=e:return[279,e-99,4];case 130>=e:return[280,e-115,4];case 162>=e:return[281,e-131,5];case 194>=e:return[282,e-163,5];case 226>=e:return[283,e-195,5];case 257>=e:return[284,e-227,5];case 258===e:return[285,e-258,0];default:t("invalid length: "+e)}}var n,i,s=[];for(n=3;258>=n;n++)i=e(n),s[n]=i[2]<<24|i[1]<<16|i[0];return s}(),k=s?new Uint32Array(v):v;function E(n,i){function a(e,n){var i,s,a,o,h=e.G,c=[],f=0;switch(i=k[e.length],c[f++]=65535&i,c[f++]=i>>16&255,c[f++]=i>>24,r){case 1===h:s=[0,h-1,0];break;case 2===h:s=[1,h-2,0];break;case 3===h:s=[2,h-3,0];break;case 4===h:s=[3,h-4,0];break;case 6>=h:s=[4,h-5,1];break;case 8>=h:s=[5,h-7,1];break;case 12>=h:s=[6,h-9,2];break;case 16>=h:s=[7,h-13,2];break;case 24>=h:s=[8,h-17,3];break;case 32>=h:s=[9,h-25,3];break;case 48>=h:s=[10,h-33,4];break;case 64>=h:s=[11,h-49,4];break;case 96>=h:s=[12,h-65,5];break;case 128>=h:s=[13,h-97,5];break;case 192>=h:s=[14,h-129,6];break;case 256>=h:s=[15,h-193,6];break;case 384>=h:s=[16,h-257,7];break;case 512>=h:s=[17,h-385,7];break;case 768>=h:s=[18,h-513,8];break;case 1024>=h:s=[19,h-769,8];break;case 1536>=h:s=[20,h-1025,9];break;case 2048>=h:s=[21,h-1537,9];break;case 3072>=h:s=[22,h-2049,10];break;case 4096>=h:s=[23,h-3073,10];break;case 6144>=h:s=[24,h-4097,11];break;case 8192>=h:s=[25,h-6145,11];break;case 12288>=h:s=[26,h-8193,12];break;case 16384>=h:s=[27,h-12289,12];break;case 24576>=h:s=[28,h-16385,13];break;case 32768>=h:s=[29,h-24577,13];break;default:t("invalid distance")}for(i=s,c[f++]=i[0],c[f++]=i[1],c[f++]=i[2],a=0,o=c.length;a<o;++a)m[b++]=c[a];A[c[0]]++,v[c[3]]++,w=e.length+n-1,d=null}var o,h,c,f,l,u,g,d,p,y={},m=s?new Uint16Array(2*i.length):[],b=0,w=0,A=new(s?Uint32Array:Array)(286),v=new(s?Uint32Array:Array)(30),E=n.w;if(!s){for(c=0;285>=c;)A[c++]=0;for(c=0;29>=c;)v[c++]=0}for(A[256]=1,o=0,h=i.length;o<h;++o){for(c=l=0,f=3;c<f&&o+c!==h;++c)l=l<<8|i[o+c];if(y[l]===e&&(y[l]=[]),u=y[l],!(0<w--)){for(;0<u.length&&32768<o-u[0];)u.shift();if(o+3>=h){for(d&&a(d,-1),c=0,f=h-o;c<f;++c)p=i[o+c],m[b++]=p,++A[p];break}0<u.length?(g=x(i,o,u),d?d.length<g.length?(p=i[o-1],m[b++]=p,++A[p],a(g,0)):a(d,-1):g.length<E?d=g:a(g,0)):d?a(d,-1):(p=i[o],m[b++]=p,++A[p])}u.push(o)}return m[b++]=256,A[256]++,n.L=A,n.K=v,s?m.subarray(0,b):m}function x(t,e,r){var n,i,s,a,o,h,c=0,f=t.length;a=0,h=r.length;t:for(;a<h;a++){if(n=r[h-a-1],s=3,3<c){for(o=c;3<o;o--)if(t[n+o-1]!==t[e+o-1])continue t;s=c}for(;258>s&&e+s<f&&t[n+s]===t[e+s];)++s;if(s>c&&(i=n,c=s),258===s)break}return new A(c,e-i)}function T(t,e){var r,n,i,a,o,h=t.length,c=new g(572),f=new(s?Uint8Array:Array)(h);if(!s)for(a=0;a<h;a++)f[a]=0;for(a=0;a<h;++a)0<t[a]&&c.push(a,t[a]);if(r=Array(c.length/2),n=new(s?Uint32Array:Array)(c.length/2),1===r.length)return f[c.pop().index]=1,f;for(a=0,o=c.length/2;a<o;++a)r[a]=c.pop(),n[a]=r[a].value;for(i=function(t,e,r){function n(t){var r=d[t][p[t]];r===e?(n(t+1),n(t+1)):--u[r],++p[t]}var i,a,o,h,c,f=new(s?Uint16Array:Array)(r),l=new(s?Uint8Array:Array)(r),u=new(s?Uint8Array:Array)(e),g=Array(r),d=Array(r),p=Array(r),y=(1<<r)-e,m=1<<r-1;for(f[r-1]=e,a=0;a<r;++a)y<m?l[a]=0:(l[a]=1,y-=m),y<<=1,f[r-2-a]=(f[r-1-a]/2|0)+e;for(f[0]=l[0],g[0]=Array(f[0]),d[0]=Array(f[0]),a=1;a<r;++a)f[a]>2*f[a-1]+l[a]&&(f[a]=2*f[a-1]+l[a]),g[a]=Array(f[a]),d[a]=Array(f[a]);for(i=0;i<e;++i)u[i]=r;for(o=0;o<f[r-1];++o)g[r-1][o]=t[o],d[r-1][o]=o;for(i=0;i<r;++i)p[i]=0;for(1===l[r-1]&&(--u[0],++p[r-1]),a=r-2;0<=a;--a){for(h=i=0,c=p[a+1],o=0;o<f[a];o++)(h=g[a+1][c]+g[a+1][c+1])>t[i]?(g[a][o]=h,d[a][o]=e,c+=2):(g[a][o]=t[i],d[a][o]=i,++i);p[a]=0,1===l[a]&&n(a)}return u}(n,n.length,e),a=0,o=r.length;a<o;++a)f[r[a].index]=i[a];return f}function U(t){var e,r,n,i,a=new(s?Uint16Array:Array)(t.length),o=[],h=[],c=0;for(e=0,r=t.length;e<r;e++)o[t[e]]=1+(0|o[t[e]]);for(e=1,r=16;e<=r;e++)h[e]=c,c+=0|o[e],c<<=1;for(e=0,r=t.length;e<r;e++)for(c=h[t[e]],h[t[e]]+=1,n=a[e]=0,i=t[e];n<i;n++)a[e]=a[e]<<1|1&c,c>>>=1;return a}function M(e,r){switch(this.l=[],this.m=32768,this.e=this.g=this.c=this.q=0,this.input=s?new Uint8Array(e):e,this.s=!1,this.n=S,this.B=!1,!r&&(r={})||(r.index&&(this.c=r.index),r.bufferSize&&(this.m=r.bufferSize),r.bufferType&&(this.n=r.bufferType),r.resize&&(this.B=r.resize)),this.n){case I:this.b=32768,this.a=new(s?Uint8Array:Array)(32768+this.m+258);break;case S:this.b=0,this.a=new(s?Uint8Array:Array)(this.m),this.f=this.J,this.t=this.H,this.o=this.I;break;default:t(Error("invalid inflate mode"))}}var I=0,S=1,D={D:I,C:S};M.prototype.p=function(){for(;!this.s;){var n=$(this,3);switch(1&n&&(this.s=r),n>>>=1){case 0:var i=this.input,a=this.c,o=this.a,h=this.b,c=i.length,f=e,l=o.length,u=e;switch(this.e=this.g=0,a+1>=c&&t(Error("invalid uncompressed block header: LEN")),f=i[a++]|i[a++]<<8,a+1>=c&&t(Error("invalid uncompressed block header: NLEN")),f===~(i[a++]|i[a++]<<8)&&t(Error("invalid uncompressed block header: length verify")),a+f>i.length&&t(Error("input buffer is broken")),this.n){case I:for(;h+f>o.length;){if(f-=u=l-h,s)o.set(i.subarray(a,a+u),h),h+=u,a+=u;else for(;u--;)o[h++]=i[a++];this.b=h,o=this.f(),h=this.b}break;case S:for(;h+f>o.length;)o=this.f({v:2});break;default:t(Error("invalid inflate mode"))}if(s)o.set(i.subarray(a,a+f),h),h+=f,a+=f;else for(;f--;)o[h++]=i[a++];this.c=a,this.b=h,this.a=o;break;case 1:this.o(V,G);break;case 2:var g,p,y,m,b=$(this,5)+257,w=$(this,5)+1,A=$(this,4)+4,v=new(s?Uint8Array:Array)(N.length),k=e,E=e,x=e,T=e,U=e;for(U=0;U<A;++U)v[N[U]]=$(this,3);if(!s)for(U=A,A=v.length;U<A;++U)v[N[U]]=0;for(g=d(v),k=new(s?Uint8Array:Array)(b+w),U=0,m=b+w;U<m;)switch(E=J(this,g),E){case 16:for(T=3+$(this,2);T--;)k[U++]=x;break;case 17:for(T=3+$(this,3);T--;)k[U++]=0;x=0;break;case 18:for(T=11+$(this,7);T--;)k[U++]=0;x=0;break;default:x=k[U++]=E}p=d(s?k.subarray(0,b):k.slice(0,b)),y=d(s?k.subarray(b):k.slice(b)),this.o(p,y);break;default:t(Error("unknown BTYPE: "+n))}}return this.t()};var F,B,z=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],N=s?new Uint16Array(z):z,_=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],C=s?new Uint16Array(_):_,O=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],R=s?new Uint8Array(O):O,P=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],j=s?new Uint16Array(P):P,q=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],L=s?new Uint8Array(q):q,H=new(s?Uint8Array:Array)(288);for(F=0,B=H.length;F<B;++F)H[F]=143>=F?8:255>=F?9:279>=F?7:8;var Y,W,V=d(H),Z=new(s?Uint8Array:Array)(30);for(Y=0,W=Z.length;Y<W;++Y)Z[Y]=5;var G=d(Z);function $(e,r){for(var n,i=e.g,s=e.e,a=e.input,o=e.c,h=a.length;s<r;)o>=h&&t(Error("input buffer is broken")),i|=a[o++]<<s,s+=8;return n=i&(1<<r)-1,e.g=i>>>r,e.e=s-r,e.c=o,n}function J(e,r){for(var n,i,s=e.g,a=e.e,o=e.input,h=e.c,c=o.length,f=r[0],l=r[1];a<l&&!(h>=c);)s|=o[h++]<<a,a+=8;return(i=(n=f[s&(1<<l)-1])>>>16)>a&&t(Error("invalid code length: "+i)),e.g=s>>i,e.e=a-i,e.c=h,65535&n}function K(t){if("string"==typeof t){var e,r,n=t.split("");for(e=0,r=n.length;e<r;e++)n[e]=(255&n[e].charCodeAt(0))>>>0;t=n}for(var i,s=1,a=0,o=t.length,h=0;0<o;){o-=i=1024<o?1024:o;do{a+=s+=t[h++]}while(--i);s%=65521,a%=65521}return(a<<16|s)>>>0}function X(e,r){var n,i;if(this.input=e,this.c=0,!r&&(r={})||(r.index&&(this.c=r.index),r.verify&&(this.M=r.verify)),n=e[this.c++],i=e[this.c++],(15&n)===Q)this.method=Q;else t(Error("unsupported compression method"));0!=((n<<8)+i)%31&&t(Error("invalid fcheck flag:"+((n<<8)+i)%31)),32&i&&t(Error("fdict flag is not supported")),this.A=new M(e,{index:this.c,bufferSize:r.bufferSize,bufferType:r.bufferType,resize:r.resize})}M.prototype.o=function(t,e){var r=this.a,n=this.b;this.u=t;for(var i,s,a,o,h=r.length-258;256!==(i=J(this,t));)if(256>i)n>=h&&(this.b=n,r=this.f(),n=this.b),r[n++]=i;else for(o=C[s=i-257],0<R[s]&&(o+=$(this,R[s])),i=J(this,e),a=j[i],0<L[i]&&(a+=$(this,L[i])),n>=h&&(this.b=n,r=this.f(),n=this.b);o--;)r[n]=r[n++-a];for(;8<=this.e;)this.e-=8,this.c--;this.b=n},M.prototype.I=function(t,e){var r=this.a,n=this.b;this.u=t;for(var i,s,a,o,h=r.length;256!==(i=J(this,t));)if(256>i)n>=h&&(h=(r=this.f()).length),r[n++]=i;else for(o=C[s=i-257],0<R[s]&&(o+=$(this,R[s])),i=J(this,e),a=j[i],0<L[i]&&(a+=$(this,L[i])),n+o>h&&(h=(r=this.f()).length);o--;)r[n]=r[n++-a];for(;8<=this.e;)this.e-=8,this.c--;this.b=n},M.prototype.f=function(){var t,e,r=new(s?Uint8Array:Array)(this.b-32768),n=this.b-32768,i=this.a;if(s)r.set(i.subarray(32768,r.length));else for(t=0,e=r.length;t<e;++t)r[t]=i[t+32768];if(this.l.push(r),this.q+=r.length,s)i.set(i.subarray(n,n+32768));else for(t=0;32768>t;++t)i[t]=i[n+t];return this.b=32768,i},M.prototype.J=function(t){var e,r,n,i=this.input.length/this.c+1|0,a=this.input,o=this.a;return t&&("number"==typeof t.v&&(i=t.v),"number"==typeof t.F&&(i+=t.F)),2>i?r=(n=(a.length-this.c)/this.u[2]/2*258|0)<o.length?o.length+n:o.length<<1:r=o.length*i,s?(e=new Uint8Array(r)).set(o):e=o,this.a=e},M.prototype.t=function(){var t,e,r,n,i,a=0,o=this.a,h=this.l,c=new(s?Uint8Array:Array)(this.q+(this.b-32768));if(0===h.length)return s?this.a.subarray(32768,this.b):this.a.slice(32768,this.b);for(e=0,r=h.length;e<r;++e)for(n=0,i=(t=h[e]).length;n<i;++n)c[a++]=t[n];for(e=32768,r=this.b;e<r;++e)c[a++]=o[e];return this.l=[],this.buffer=c},M.prototype.H=function(){var t,e=this.b;return s?this.B?(t=new Uint8Array(e)).set(this.a.subarray(0,e)):t=this.a.subarray(0,e):(this.a.length>e&&(this.a.length=e),t=this.a),this.buffer=t},X.prototype.p=function(){var e,r=this.input;return e=this.A.p(),this.c=this.A.c,this.M&&((r[this.c++]<<24|r[this.c++]<<16|r[this.c++]<<8|r[this.c++])>>>0!==K(e)&&t(Error("invalid adler-32 checksum"))),e};var Q=8;function tt(t,e){this.input=t,this.a=new(s?Uint8Array:Array)(32768),this.h=et.k;var r,n={};for(r in!e&&(e={})||"number"!=typeof e.compressionType||(this.h=e.compressionType),e)n[r]=e[r];n.outputBuffer=this.a,this.z=new p(this.input,n)}var et=b;function rt(t,e){var r,n,s,a;if(Object.keys)r=Object.keys(e);else for(n in r=[],s=0,e)r[s++]=n;for(s=0,a=r.length;s<a;++s)i(t+"."+(n=r[s]),e[n])}tt.prototype.j=function(){var e,r,n,i,a,o,h,c=0;if(h=this.a,(e=Q)===Q)r=Math.LOG2E*Math.log(32768)-8;else t(Error("invalid compression method"));if(n=r<<4|e,h[c++]=n,e===Q)switch(this.h){case et.NONE:a=0;break;case et.r:a=1;break;case et.k:a=2;break;default:t(Error("unsupported compression type"))}else t(Error("invalid compression method"));return i=a<<6,h[c++]=i|31-(256*n+i)%31,o=K(this.input),this.z.b=c,c=(h=this.z.j()).length,s&&((h=new Uint8Array(h.buffer)).length<=c+4&&(this.a=new Uint8Array(h.length+4),this.a.set(h),h=this.a),h=h.subarray(0,c+4)),h[c++]=o>>24&255,h[c++]=o>>16&255,h[c++]=o>>8&255,h[c++]=255&o,h},i("Zlib.Inflate",X),i("Zlib.Inflate.prototype.decompress",X.prototype.p),rt("Zlib.Inflate.BufferType",{ADAPTIVE:D.C,BLOCK:D.D}),i("Zlib.Deflate",tt),i("Zlib.Deflate.compress",(function(t,e){return new tt(t,e).j()})),i("Zlib.Deflate.prototype.compress",tt.prototype.j),rt("Zlib.Deflate.CompressionType",{NONE:et.NONE,FIXED:et.r,DYNAMIC:et.k})}.call(self);var f="undefined"!=typeof Float32Array?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var l,u=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t};function g(t,e,r){return t[0]=e,t[1]=r,t}l=new f(3),f!=Float32Array&&(l[0]=0,l[1]=0,l[2]=0),function(){var t=function(){var t=new f(2);return f!=Float32Array&&(t[0]=0,t[1]=0),t}()}();class d{constructor(t=257){this.gridSize=t;const e=t-1;if(e&e-1)throw new Error(\`Expected grid size to be 2^n+1, got ${e}t}.\`);this.numTriangles=e*e*2-2,this.numParentTriangles=this.numTriangles-e*e,this.indices=new Uint32Array(this.gridSize*this.gridSize),this.coords=new Uint16Array(4*this.numTriangles);for(let t=0;t<this.numTriangles;t++){let r=t+2,n=0,i=0,s=0,a=0,o=0,h=0;for(1&r?s=a=o=e:n=i=h=e;(r>>=1)>1;){const t=n+s>>1,e=i+a>>1;1&r?(s=n,a=i,n=o,i=h):(n=s,i=a,s=o,a=h),o=t,h=e}const c=4*t;this.coords[c+0]=n,this.coords[c+1]=i,this.coords[c+2]=s,this.coords[c+3]=a}}createTile(t){return new p(t,this)}}class p{constructor(t,e){const r=e.gridSize;if(t.length!==r*r)throw new Error(\`Expected terrain data of length ${e}r*r} (${e}r} x ${e}r}), got ${e}t.length}.\`);this.terrain=t,this.martini=e,this.errors=new Float32Array(t.length),this.update()}update(){const{numTriangles:t,numParentTriangles:e,coords:r,gridSize:n}=this.martini,{terrain:i,errors:s}=this;for(let a=t-1;a>=0;a--){const t=4*a,o=r[t+0],h=r[t+1],c=r[t+2],f=r[t+3],l=o+c>>1,u=h+f>>1,g=l+u-h,d=u+o-l,p=(i[h*n+o]+i[f*n+c])/2,y=u*n+l,m=Math.abs(p-i[y]);if(s[y]=Math.max(s[y],m),a<e){const t=(h+d>>1)*n+(o+g>>1),e=(f+d>>1)*n+(c+g>>1);s[y]=Math.max(s[y],s[t],s[e])}}}getMesh(t=0){const{gridSize:e,indices:r}=this.martini,{errors:n}=this;let i=0,s=0;const a=e-1;function o(a,h,c,f,l,u){const g=a+c>>1,d=h+f>>1;Math.abs(a-l)+Math.abs(h-u)>1&&n[d*e+g]>t?(o(l,u,a,h,g,d),o(c,f,l,u,g,d)):(r[h*e+a]=r[h*e+a]||++i,r[f*e+c]=r[f*e+c]||++i,r[u*e+l]=r[u*e+l]||++i,s++)}r.fill(0),o(0,0,a,a,a,0),o(a,a,0,0,0,a);const h=new Uint16Array(2*i),c=new Uint32Array(3*s);let f=0;function l(i,s,a,o,u,g){const d=i+a>>1,p=s+o>>1;if(Math.abs(i-u)+Math.abs(s-g)>1&&n[p*e+d]>t)l(u,g,i,s,d,p),l(a,o,u,g,d,p);else{const t=r[s*e+i]-1,n=r[o*e+a]-1,l=r[g*e+u]-1;h[2*t]=i,h[2*t+1]=s,h[2*n]=a,h[2*n+1]=o,h[2*l]=u,h[2*l+1]=g,c[f++]=t,c[f++]=n,c[f++]=l}}return l(0,0,a,a,a,0),l(a,a,0,0,0,a),{vertices:h,triangles:c}}getMeshWithSkirts(t=0,e){const{gridSize:r,indices:n}=this.martini,{errors:i}=this;let s=0,a=0;const o=r-1;let h,c,f=0;const l=[],u=[],g=[],d=[];function p(e,y,m,b,w,A){const v=e+m>>1,k=y+b>>1;Math.abs(e-w)+Math.abs(y-A)>1&&i[k*r+v]>t?(p(w,A,e,y,v,k),p(m,b,w,A,v,k)):(h=y*r+e,c=b*r+m,f=A*r+w,0===n[h]&&(0===e?l.push(s):e===o&&u.push(s),0===y?g.push(s):y===o&&d.push(s),n[h]=++s),0===n[c]&&(0===m?l.push(s):m===o&&u.push(s),0===b?g.push(s):b===o&&d.push(s),n[c]=++s),0===n[f]&&(0===w?l.push(s):w===o&&u.push(s),0===A?g.push(s):A===o&&d.push(s),n[f]=++s),a++)}let y;n.fill(0),p(0,0,o,o,o,0),p(o,o,0,0,0,o),y=e?2*(s+3*l.length-2+3*u.length-2+3*g.length-2+3*d.length-2):2*(s+l.length+u.length+g.length+d.length);const m=3*(a+2*(l.length-1)+2*(u.length-1)+2*(g.length-1)+2*(d.length-1)),b=new Uint16Array(y),w=new Uint32Array(m);let A=0;function v(e,s,a,o,h,c){const f=e+a>>1,l=s+o>>1;if(Math.abs(e-h)+Math.abs(s-c)>1&&i[l*r+f]>t)v(h,c,e,s,f,l),v(a,o,h,c,f,l);else{const t=n[s*r+e]-1,i=n[o*r+a]-1,f=n[c*r+h]-1;b[2*t]=e,b[2*t+1]=s,b[2*i]=a,b[2*i+1]=o,b[2*f]=h,b[2*f+1]=c,w[A++]=t,w[A++]=i,w[A++]=f}}v(0,0,o,o,o,0),v(o,o,0,0,0,o),l.sort(((t,e)=>b[2*t+1]-b[2*e+1])),u.sort(((t,e)=>b[2*e+1]-b[2*t+1])),g.sort(((t,e)=>b[2*e]-b[2*t])),d.sort(((t,e)=>b[2*t]-b[2*e]));let k,E,x,T,U=2*s,M=0;function I(t){M=t.length;for(let r=0;r<M-1;r++)k=t[r],E=t[r+1],x=U/2,T=(U+(e?6:2))/2,b[U++]=2*k,b[U++]=2*k+1,e&&(b[U++]=2*k,b[U++]=2*k+1,b[U++]=2*E,b[U++]=2*E+1),e?(w[A++]=x+1,w[A++]=x,w[A++]=x+2,w[A++]=x,w[A++]=T,w[A++]=x+2):(w[A++]=k,w[A++]=x,w[A++]=E,w[A++]=x,w[A++]=T,w[A++]=E);b[U++]=2*t[M-1],b[U++]=2*t[M-1]+1}I(l);const S=U;I(u);const D=U;I(g);const F=U;I(d);return{vertices:b,triangles:w,numVerticesWithoutSkirts:s,numTrianglesWithoutSkirts:a,leftSkirtIndex:S,rightSkirtIndex:D,bottomSkirtIndex:F,topSkirtIndex:U}}}const y={};let m;const b={width:100,height:10};let w=!1;try{const t=new OffscreenCanvas(1,1);t.getContext("2d").fillText("hello",0,0),w=!0}catch(t){w=!1}function A(){if(!m){const{width:t,height:e}=b;w?m=new OffscreenCanvas(t,e):(m=document.createElement("canvas"),m.width=t,m.height=e)}return m}class v{constructor(t,e={}){if(!Array.isArray(t))return void console.error("colors is not array");if(t.length<2)return void console.error("colors.length should >1");this.colors=t;let r=1/0,n=-1/0;for(let e=0,i=t.length;e<i;e++){const i=t[e][0];r=Math.min(i,r),n=Math.max(i,n)}this.min=r,this.max=n,this.valueOffset=this.max-this.min,this.options=Object.assign({},b,e),this._initImgData()}getImageData(){return this.imgData}_initImgData(){const t=A(),{width:e,height:r}=this.options;t.width=e,t.height=r;const n=t.getContext("2d");n.clearRect(0,0,t.width,t.height);const i=n.createLinearGradient(0,0,t.width,0),{colors:s,valueOffset:a}=this;for(let t=0,e=s.length;t<e;t++){const[e,r]=s[t],n=(e-this.min)/a;i.addColorStop(n,r)}n.fillStyle=i,n.fillRect(0,0,t.width,t.height),this.imgData=n.getImageData(0,0,t.width,t.height)}getColor(t){t=Math.max(this.min,t);const e=((t=Math.min(t,this.max))-this.min)/this.valueOffset;let r=Math.round(e*this.imgData.width);r=Math.min(r,this.imgData.width-1);const n=4*r;return[this.imgData.data[n],this.imgData.data[n+1],this.imgData.data[n+2],this.imgData.data[n+3]]}}var k="undefined"!=typeof Float32Array?Float32Array:Array;function E(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function x(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function T(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function U(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}var M=function(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t};
34595
34945
  /*!
34596
34946
  * Contains code from THREE.JS
34597
34947
  * https://github.com/mrdoob/three.js/
@@ -34599,7 +34949,7 @@ var e,r,n="undefined"!=typeof Float32Array?Float32Array:Array;function i(){var t
34599
34949
  *
34600
34950
  * Generate tangents per vertex.
34601
34951
  */
34602
- function M(t,e,r,n,i){const s=t.length/3,a=new Array(4*s),o=[],h=[];for(let t=0;t<s;t++)o[t]=[0,0,0],h[t]=[0,0,0];const c=[0,0,0],f=[0,0,0],l=[0,0,0],u=[0,0],g=[0,0],d=[0,0],p=[0,0,0],y=[0,0,0];function m(e,n,i){I(c,t,3*e),I(f,t,3*n),I(l,t,3*i),S(u,r,2*e),S(g,r,2*n),S(d,r,2*i);const s=f[0]-c[0],a=l[0]-c[0],m=f[1]-c[1],b=l[1]-c[1],w=f[2]-c[2],A=l[2]-c[2],v=g[0]-u[0],k=d[0]-u[0],T=g[1]-u[1],U=d[1]-u[1],M=1/(v*U-k*T);E(p,(U*s-T*a)*M,(U*m-T*b)*M,(U*w-T*A)*M),E(y,(v*a-k*s)*M,(v*b-k*m)*M,(v*A-k*w)*M),x(o[e],o[e],p),x(o[n],o[n],p),x(o[i],o[i],p),x(h[e],h[e],y),x(h[n],h[n],y),x(h[i],h[i],y)}for(let t=0,e=n.length;t<e;t+=3)m(n[t+0],n[t+1],n[t+2]);const b=[],w=[],A=[],v=[];let M,D,F;function B(t){I(A,e,3*t),k(v,A),D=o[t],k(b,D),U(b,b,function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}(A,A,T(A,D))),function(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;s>0&&(s=1/Math.sqrt(s),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s)}(b,b),function(t,e,r){var n=e[0],i=e[1],s=e[2],a=r[0],o=r[1],h=r[2];t[0]=i*h-s*o,t[1]=s*a-n*h,t[2]=n*o-i*a}(w,v,D),F=T(w,h[t]),M=F<0?-1:1,a[4*t]=b[0],a[4*t+1]=b[1],a[4*t+2]=b[2],a[4*t+3]=M}for(let t=0,e=n.length;t<e;t+=3)B(n[t+0]),B(n[t+1]),B(n[t+2]);return a}function I(t,e,r){return t[0]=e[r],t[1]=e[r+1],t[2]=e[r+2],t}function S(t,e,r){return t[0]=e[r],t[1]=e[r+1],t}function D(t){return"number"==typeof t&&!isNaN(t)}let F;!function(){var t=function(){var t=new v(3);return v!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}()}();let B=null,z=null;const N=[0,0,0],_=[256,256];function C(){try{B||(B=new OffscreenCanvas(1,1))}catch(t){console.error(t)}}const O={},R={},P={width:64,height:64,elementsPerHeight:3,heightOffset:-1e3,exaggeration:1,heightScale:.001,elementMultiplier:256,stride:4,skirtHeight:.002,skirtOffset:.01},j={cesium_request_token:{Accept:"application/json,*/*;q=0.01","Accept-Encoding":"gzip, deflate, br"},tianditu:{"Accept-Encoding":"gzip, deflate, br"},cesium:{"Accept-Encoding":"gzip, deflate, br",Accept:"application/vnd.quantized-mesh,application/octet-stream;q=0.9,*/*;q=0.01"},mapbox:{Accept:"image/webp,*/*"}};j["cesium-ion"]=j.cesium;const q=32767;let L=null,H=null;function Y(t,e){const r=function(t){if(t.length<1e3)return null;const e=new Zlib.Inflate(t);return e?e.decompress():null}(new Uint8Array(t));if(!r)throw new Error((n=new Uint8Array(t),W.decode(n)));var n;const i=function(t){const e=t,r=P.width,n=P.height,i=new Uint8Array(r*n*P.stride);let s,a,o,h,c;for(let t=0;t<n;t++)for(let f=0;f<r;f++){h=parseInt(149*t/(n-1)),c=parseInt(149*f/(r-1)),a=2*(150*h+c),s=e[a]+256*e[a+1],(s>1e4||s<-2e3)&&(s=0),o=4*(t*r+f);const l=(s+1e3)/P.heightScale,u=P.elementMultiplier;i[o]=l/(u*u),i[o+1]=(l-i[o]*u*u)/u,i[o+2]=l-i[o]*u*u-i[o+1]*u,i[o+3]=255}return i}(r),s=function(t,e){const r=e,n=e,i=r+1,s=n+1,a=P.elementsPerHeight,o=P.heightOffset,h=P.heightScale,c=P.elementMultiplier,f=P.skirtHeight,l=new Float32Array(i*s);let u=0,g=1/0,d=-1/0;for(let e=0;e<i;e++){const i=e>=n?n-1:e;for(let e=0;e<s;e++){let n=0;const s=i*(4*r)+4*(e>=r?r-1:e);for(let e=0;e<a;e++)n=n*c+t[s+e];n=1*(n*h+o),n-=f,l[u]=n,n<g&&(g=n),n>d&&(d=n),u++}}return{data:l,min:g,max:d}}(i,e-1);return s.width=s.height=e,s}const W=new TextDecoder("utf-8");function V(t){return t>>1^-(1&t)}const Z=[];function G(t){let e=0;const r=3*Float64Array.BYTES_PER_ELEMENT,n=3*Uint16Array.BYTES_PER_ELEMENT;let i=Uint16Array.BYTES_PER_ELEMENT;const s=new DataView(t);e+=r;const a=s.getFloat32(e,!0);e+=Float32Array.BYTES_PER_ELEMENT;const o=s.getFloat32(e,!0);e+=Float32Array.BYTES_PER_ELEMENT,e+=r;const h=s.getFloat64(e,!0);e+=Float64Array.BYTES_PER_ELEMENT,e+=r;const c=s.getUint32(e,!0);e+=Uint32Array.BYTES_PER_ELEMENT;const f=new Uint16Array(t,e,3*c);e+=c*n,c>65536&&(i=Uint32Array.BYTES_PER_ELEMENT);!function(t,e,r){const n=t.length;let i=0,s=0,a=0;for(let o=0;o<n;++o)i+=V(t[o]),s+=V(e[o]),t[o]=i,e[o]=s,r&&(a+=V(r[o]),r[o]=a)}(f.subarray(0,c),f.subarray(c,2*c),f.subarray(2*c,3*c)),e%i!=0&&(e+=i-e%i);const l=s.getUint32(e,!0);e+=Uint32Array.BYTES_PER_ELEMENT;const u=c>65536?new Uint32Array(t,e,3*l):new Uint16Array(t,e,3*l);let g=0;const d=u.length;for(let t=0;t<d;++t){const e=u[t];u[t]=g-e,0===e&&++g}const p={minimumHeight:a,maximumHeight:o,quantizedVertices:f,indices:u}.quantizedVertices,y=p.length/3,m=p.subarray(0,y),b=p.subarray(y,2*y),w=p.subarray(2*y,3*y),A=Z;for(let t=0;t<y;++t){const e=m[t],r=b[t],n=e/q,i=r/q,s=(v=a,k=o,(1-(E=w[t]/q))*v+E*k);A[3*t]=n,A[3*t+1]=1-i,A[3*t+2]=s}var v,k,E;return{positions:A,radius:h,min:a,max:o,indices:u}}const $=[],J=[],K=[],X=[],Q=[];class tt{constructor(t,e,r,n,i){this.p0=[],this.p1=[],this.p2=[],this.normal=[],this.min=[],this.max=[],this.set(t,e,r,n,i)}set(t,e,r,n,i){this.radius=i;let s=3*e,a=3*e+1,o=3*e+2;this.p0[0]=t[s]*i,this.p0[1]=t[a]*i,this.p0[2]=t[o],s=3*r,a=3*r+1,o=3*r+2,this.p1[0]=t[s]*i,this.p1[1]=t[a]*i,this.p1[2]=t[o],s=3*n,a=3*n+1,o=3*n+2,this.p2[0]=t[s]*i,this.p2[1]=t[a]*i,this.p2[2]=t[o],this.min[0]=Math.min(this.p0[0],this.p1[0],this.p2[0]),this.min[1]=Math.min(this.p0[1],this.p1[1],this.p2[1]),this.max[0]=Math.max(this.p0[0],this.p1[0],this.p2[0]),this.max[1]=Math.max(this.p0[1],this.p1[1],this.p2[1]);const h=l($,this.p1,this.p0),c=l(J,this.p2,this.p1);this.normal=function(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t}(this.normal,function(t,e,r){var n=e[0],i=e[1],s=e[2],a=r[0],o=r[1],h=r[2];return t[0]=i*h-s*o,t[1]=s*a-n*h,t[2]=n*o-i*a,t}(this.normal,h,c))}contains(t,e){if(t<this.min[0]||t>this.max[0]||e<this.min[1]||e>this.max[1])return!1;u(K,this.p0[0],this.p0[1]),u(X,this.p1[0],this.p1[1]),u(Q,this.p2[0],this.p2[1]);const r=it(K[0],K[1],X[0],X[1],Q[0],Q[1]);return it(t,e,K[0],K[1],Q[0],Q[1])+it(t,e,K[0],K[1],X[0],X[1])+it(t,e,X[0],X[1],Q[0],Q[1])-r<=1e-4}getHeight(t,e){const r=this.normal;return this.p0[2]-((t-this.p0[0])*r[0]+(e-this.p0[1])*r[1])/r[2]}}let et=null;function rt(t,e,r){if(et&&et.contains(e,r))return et.getHeight(e,r);for(let n=0;n<t.length;n++)if(t[n].contains(e,r))return et=t[n],t[n].getHeight(e,r);return 0}const nt=[];function it(t,e,r,n,i,s){return.5*Math.abs(t*n+r*s+i*e-t*s-r*e-i*n)}function st(t,e,r,n,i,s){"cesium-ion"===r&&(e.Authorization="Bearer "+L),function(t,e,r){const n={method:"GET",referrer:r,headers:e},i=h.getArrayBuffer(t,n),s=i.xhr;return R[t]=s,i.then((e=>(delete R[t],e)))}(t,e,origin).then((t=>{if(!t||t.message)s(t?{empty:!0,originalError:t}:{error:{canceled:!0}});else{const e=t.data;let a=null;if("tianditu"===r){const t=Y(e,n);ot(i,t,n,null,!0,s)}else if("cesium-ion"===r||"cesium"===r){a=G(e);const t=function(t,e){const{positions:r,min:n,max:i,indices:s,radius:a}=t,o=[];let h=0;for(let t=0;t<s.length;t+=3){let e=nt[h];e?e.set(r,s[t],s[t+1],s[t+2],2*a):e=nt[h]=new tt(r,s[t],s[t+1],s[t+2],2*a),h++,o.push(e)}const c=new Float32Array(e*e);h=0;for(let t=0;t<e;t++)for(let r=0;r<e;r++)c[h++]=rt(o,r/e*a*2,t/e*a*2);return{data:c,min:n,max:i,width:e,height:e}}(a,n);ot(i,t,n,null,!0,s)}else"mapbox"===r&&(a=function(t){const e=new self.Blob([new Uint8Array(t)]);return self.createImageBitmap(e)}(e),a.then((t=>{const e=ct(ht(t),n);ot(i,e,n,t,!0,s)})))}})).catch((e=>{delete R[t],s({empty:!0,originalError:e})}))}function at(t,e){const r=Math.floor(10*(t+1e4)),n=r>>16,i=r>>8&255,s=255&r;return e?(e[0]=n,e[1]=i,e[2]=s,e):[n,i,s]}function ot(t,e,r,n,i,s){const a=function(t,e,r){let n=p[r];n||(n=p[r]=new g(r));const i=n.createTile(e).getMeshWithSkirts(t,!0),{triangles:s,vertices:a,leftSkirtIndex:o,rightSkirtIndex:h,bottomSkirtIndex:c,topSkirtIndex:f}=i;let{numVerticesWithoutSkirts:l,numTrianglesWithoutSkirts:u}=i;l||(l=a.length/2,u=s.length/3);const d=a.length/2,y=new Float32Array(3*d),m=new Float32Array(2*d);let b=1/0,w=-1/0;const A=r-1;for(let t=0;t<d;t++){const n=a[2*t],i=a[2*t+1];if(t>=l){const e=n/2*3;let r,i=.001;(t-(t<o/2?l:t<h/2?o/2:t<c/2?h/2:c/2))%3==0?(r=Math.min(0,b),i=0):r=y[e+2],y[3*t]=y[e],y[3*t+1]=y[e+1],y[3*t+2]=r,m[2*t]=y[e]/A+i,m[2*t+1]=-y[e+1]/A+i}else{const s=e[i*r+n];y[3*t]=1*n,y[3*t+1]=1*-i,y[3*t+2]=s,m[2*t]=n/A,m[2*t+1]=i/A,s<b&&(b=s),s>w&&(w=s)}}return{positions:y,texcoords:m,triangles:s,leftSkirtIndex:o,rightSkirtIndex:h,bottomSkirtIndex:c,topSkirtIndex:f,numTrianglesWithoutSkirts:u,numVerticesWithoutSkirts:l,minHeight:Math.min(0,b),maxHeight:w,terrainWidth:r}}(t/6,e.data,r),o=[a.positions.buffer,a.texcoords.buffer,a.triangles.buffer];n||(n=function(t){if(C(),!B)return;const{width:e,height:r,data:n}=t;if(e&&r&&n)try{let t=B.getContext("2d",{willReadFrequently:!0});const i=t.createImageData(e,r);for(let t=0,e=n.length;t<e;t++){const e=n[t],[r,s,a]=at(e,N),o=4*t;i.data[o]=r,i.data[o+1]=s,i.data[o+2]=a,i.data[o+3]=255}return B.width=e,B.height=r,t=B.getContext("2d",{willReadFrequently:!0}),ft(t),t.putImageData(i,0,0),B.transferToImageBitmap()}catch(t){console.log(t)}}(e)),n&&o.push(n);const h={mesh:a};h.image=n,h.data=e,o.push(e.data.buffer),s(h,o)}function ht(t){const{width:e,height:r}=t;return B||(B=new OffscreenCanvas(1,1),z=B.getContext("2d",{willReadFrequently:!0})),B.width=e,B.height=r,z.drawImage(t,0,0,e,r),z.getImageData(0,0,e,r)}function ct(t,e){const{data:r,width:n}=t;let i=1/0,s=-1/0;const a=new Float32Array(e*e),o=Math.round(n/e);for(let t=0;t<e;t++)for(let h=0;h<e;h++){const c=t+h*e;let f=0,l=0;const u=t,g=h;for(let t=0;t<o;t++)for(let e=0;e<o;e++){let i=u*o+t,s=g*o+e;s>n-1&&(s=n-1),i>n-1&&(i=n-1);const a=i+s*n,h=r[4*a],c=r[4*a+1],d=r[4*a+2];0===r[4*a+3]?l+=1:f+=.1*(256*h*256+256*c+d)-1e4}f/=o*o-l||1,f>s&&(s=f),f<i&&(i=f),a[c]=f}return{data:a,width:e,height:e,min:i,max:s}}function ft(t){const e=t.canvas,{width:r,height:n}=e;t.clearRect(0,0,r,n)}function lt(t,e,r){if(!e||!Array.isArray(e)||e.length<2)return;if(!t||!t.image)return null;let{width:n,height:i}=t.image;(r=r||_)[0]===n&&r[1]===i||(n=r[0],i=r[1]),n*=2,i*=2;try{if(C(),!B)return;const r=B;r.width=n,r.height=i;const s=r.getContext("2d",{willReadFrequently:!0});ft(s),s.drawImage(t.image,0,0,n,i);const a=s.getImageData(0,0,n,i);!function(t,e){const r=JSON.stringify(e);O[r]||(O[r]=new A(e));const n=O[r],i=t.data;for(let t=0,e=i.length;t<e;t+=4){const e=i[t],r=i[t+1],s=i[t+2];let a=0;0!==i[t+3]&&(a=.1*(256*e*256+256*r+s)-1e4,a=Math.max(a,0));const[o,h,c]=n.getColor(a);i[t]=o,i[t+1]=h,i[t+2]=c,i[t+3]=255}}(a,e),s.putImageData(a,0,0);const o=r.transferToImageBitmap();s.save(),s.scale(1,-1),s.drawImage(o,0,-i,n,i),s.restore();const h=r.transferToImageBitmap();return o.close(),h}catch(t){console.error(t)}}t.initialize=function(){},t.onmessage=function(t,e){const r=t.data;if("addLayer"===r.command||"removeLayer"===r.command)F=t.workerId,self.postMessage({type:"<response>",actorId:r.actorId,workerId:F,params:"ok",callback:t.callback});else if("fetchTerrain"===r.command){const t=(r.params||{}).colors,n=(r.params||{}).tileSize;!function(t,e){const{url:r,origin:n,type:i,accessToken:s,terrainWidth:a,error:o,tileImage:h}=t;if(h&&h.close){const t=ct(ht(h),a);return void ot(o,t,a,h,0,e)}const c=t.headers||j[i];if("tianditu"===i)st(r,c,i,a,o,e);else if("cesium-ion"===i){const h=t.cesiumIonTokenURL+s;L?st(r,c,i,a,o,e):(H||(H=fetch(h,{responseType:"json",method:"GET",referrer:n,headers:{Accept:"application/json,*/*;q=0.01","Accept-Encoding":"gzip, deflate, br"}}).then((t=>t.json())).then((t=>{L=t.accessToken,H=null}))),H.then((()=>{st(r,c,i,a,o,e)})))}else("cesium"===i||"mapbox"===i)&&st(r,c,i,a,o,e)}(r.params,((r,i)=>{i=i||[];const s=lt(r,t,n);s&&(r.colorsTexture=s,i.push(s));const a=function(t){if(!t)return;const{positions:e,texcoords:r,triangles:n,leftSkirtIndex:i,rightSkirtIndex:s,bottomSkirtIndex:a,numVerticesWithoutSkirts:o}=t;if(!e||!r||!n)return;if(!(D(i)&&D(s)&&D(a)&&D(o)))return;const h=new Int8Array(e.length);for(let t=2;t<h.length;t+=3)t<3*o?h[t]=1:t<i/2*3?h[t-2]=-1:t<s/2*3?h[t-2]=1:h[t-1]=t<a/2*3?-1:1;const c=M(e,h,r,n);return new Float32Array(c)}(r.mesh);a&&r.mesh&&(r.mesh.tangents=a,i.push(a.buffer)),e(r.error,r,i)}))}else"abortTerrain"===r.command&&(n=r.params.url,R[n]&&(R[n].abort(),delete R[n]));var n}}`;
34952
+ function I(t,e,r,n,i){const s=t.length/3,a=new Array(4*s),o=[],h=[];for(let t=0;t<s;t++)o[t]=[0,0,0],h[t]=[0,0,0];const c=[0,0,0],f=[0,0,0],l=[0,0,0],u=[0,0],g=[0,0],d=[0,0],p=[0,0,0],y=[0,0,0];function m(e,n,i){S(c,t,3*e),S(f,t,3*n),S(l,t,3*i),D(u,r,2*e),D(g,r,2*n),D(d,r,2*i);const s=f[0]-c[0],a=l[0]-c[0],m=f[1]-c[1],b=l[1]-c[1],w=f[2]-c[2],A=l[2]-c[2],v=g[0]-u[0],k=d[0]-u[0],E=g[1]-u[1],U=d[1]-u[1],M=1/(v*U-k*E);x(p,(U*s-E*a)*M,(U*m-E*b)*M,(U*w-E*A)*M),x(y,(v*a-k*s)*M,(v*b-k*m)*M,(v*A-k*w)*M),T(o[e],o[e],p),T(o[n],o[n],p),T(o[i],o[i],p),T(h[e],h[e],y),T(h[n],h[n],y),T(h[i],h[i],y)}for(let t=0,e=n.length;t<e;t+=3)m(n[t+0],n[t+1],n[t+2]);const b=[],w=[],A=[],v=[];let k,I,F;function B(t){S(A,e,3*t),E(v,A),I=o[t],E(b,I),M(b,b,function(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}(A,A,U(A,I))),function(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;s>0&&(s=1/Math.sqrt(s),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s)}(b,b),function(t,e,r){var n=e[0],i=e[1],s=e[2],a=r[0],o=r[1],h=r[2];t[0]=i*h-s*o,t[1]=s*a-n*h,t[2]=n*o-i*a}(w,v,I),F=U(w,h[t]),k=F<0?-1:1,a[4*t]=b[0],a[4*t+1]=b[1],a[4*t+2]=b[2],a[4*t+3]=k}for(let t=0,e=n.length;t<e;t+=3)B(n[t+0]),B(n[t+1]),B(n[t+2]);return a}function S(t,e,r){return t[0]=e[r],t[1]=e[r+1],t[2]=e[r+2],t}function D(t,e,r){return t[0]=e[r],t[1]=e[r+1],t}function F(t){return"number"==typeof t&&!isNaN(t)}let B;!function(){var t=function(){var t=new k(3);return k!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}()}();let z=null,N=null;const _=[0,0,0],C=[256,256];function O(){try{z||(z=new OffscreenCanvas(1,1))}catch(t){console.error(t)}}const R={},P={},j={width:64,height:64,elementsPerHeight:3,heightOffset:-1e3,exaggeration:1,heightScale:.001,elementMultiplier:256,stride:4,skirtHeight:.002,skirtOffset:.01},q={cesium_request_token:{Accept:"application/json,*/*;q=0.01","Accept-Encoding":"gzip, deflate, br"},tianditu:{"Accept-Encoding":"gzip, deflate, br"},cesium:{"Accept-Encoding":"gzip, deflate, br",Accept:"application/vnd.quantized-mesh,application/octet-stream;q=0.9,*/*;q=0.01"},mapbox:{Accept:"image/webp,*/*"}};q["cesium-ion"]=q.cesium;const L=32767;let H=null,Y=null;function W(t,e){const r=function(t){if(t.length<1e3)return null;const e=new Zlib.Inflate(t);return e?e.decompress():null}(new Uint8Array(t));if(!r)throw new Error((n=new Uint8Array(t),V.decode(n)));var n;const i=function(t){const e=t,r=j.width,n=j.height,i=new Uint8Array(r*n*j.stride);let s,a,o,h,c;for(let t=0;t<n;t++)for(let f=0;f<r;f++){h=parseInt(149*t/(n-1)),c=parseInt(149*f/(r-1)),a=2*(150*h+c),s=e[a]+256*e[a+1],(s>1e4||s<-2e3)&&(s=0),o=4*(t*r+f);const l=(s+1e3)/j.heightScale,u=j.elementMultiplier;i[o]=l/(u*u),i[o+1]=(l-i[o]*u*u)/u,i[o+2]=l-i[o]*u*u-i[o+1]*u,i[o+3]=255}return i}(r),s=function(t,e){const r=e,n=e,i=r+1,s=n+1,a=j.elementsPerHeight,o=j.heightOffset,h=j.heightScale,c=j.elementMultiplier,f=j.skirtHeight,l=new Float32Array(i*s);let u=0,g=1/0,d=-1/0;for(let e=0;e<i;e++){const i=e>=n?n-1:e;for(let e=0;e<s;e++){let n=0;const s=i*(4*r)+4*(e>=r?r-1:e);for(let e=0;e<a;e++)n=n*c+t[s+e];n=1*(n*h+o),n-=f,l[u]=n,n<g&&(g=n),n>d&&(d=n),u++}}return{data:l,min:g,max:d}}(i,e-1);return s.width=s.height=e,s}const V=new TextDecoder("utf-8");function Z(t){return t>>1^-(1&t)}const G=[];function $(t){let e=0;const r=3*Float64Array.BYTES_PER_ELEMENT,n=3*Uint16Array.BYTES_PER_ELEMENT;let i=Uint16Array.BYTES_PER_ELEMENT;const s=new DataView(t);e+=r;const a=s.getFloat32(e,!0);e+=Float32Array.BYTES_PER_ELEMENT;const o=s.getFloat32(e,!0);e+=Float32Array.BYTES_PER_ELEMENT,e+=r;const h=s.getFloat64(e,!0);e+=Float64Array.BYTES_PER_ELEMENT,e+=r;const c=s.getUint32(e,!0);e+=Uint32Array.BYTES_PER_ELEMENT;const f=new Uint16Array(t,e,3*c);e+=c*n,c>65536&&(i=Uint32Array.BYTES_PER_ELEMENT);!function(t,e,r){const n=t.length;let i=0,s=0,a=0;for(let o=0;o<n;++o)i+=Z(t[o]),s+=Z(e[o]),t[o]=i,e[o]=s,r&&(a+=Z(r[o]),r[o]=a)}(f.subarray(0,c),f.subarray(c,2*c),f.subarray(2*c,3*c)),e%i!=0&&(e+=i-e%i);const l=s.getUint32(e,!0);e+=Uint32Array.BYTES_PER_ELEMENT;const u=c>65536?new Uint32Array(t,e,3*l):new Uint16Array(t,e,3*l);let g=0;const d=u.length;for(let t=0;t<d;++t){const e=u[t];u[t]=g-e,0===e&&++g}const p={minimumHeight:a,maximumHeight:o,quantizedVertices:f,indices:u}.quantizedVertices,y=p.length/3,m=p.subarray(0,y),b=p.subarray(y,2*y),w=p.subarray(2*y,3*y),A=G;for(let t=0;t<y;++t){const e=m[t],r=b[t],n=e/L,i=r/L,s=(v=a,k=o,(1-(E=w[t]/L))*v+E*k);A[3*t]=n,A[3*t+1]=1-i,A[3*t+2]=s}var v,k,E;return{positions:A,radius:h,min:a,max:o,indices:u}}const J=[],K=[],X=[],Q=[],tt=[];class et{constructor(t,e,r,n,i){this.p0=[],this.p1=[],this.p2=[],this.normal=[],this.min=[],this.max=[],this.set(t,e,r,n,i)}set(t,e,r,n,i){this.radius=i;let s=3*e,a=3*e+1,o=3*e+2;this.p0[0]=t[s]*i,this.p0[1]=t[a]*i,this.p0[2]=t[o],s=3*r,a=3*r+1,o=3*r+2,this.p1[0]=t[s]*i,this.p1[1]=t[a]*i,this.p1[2]=t[o],s=3*n,a=3*n+1,o=3*n+2,this.p2[0]=t[s]*i,this.p2[1]=t[a]*i,this.p2[2]=t[o],this.min[0]=Math.min(this.p0[0],this.p1[0],this.p2[0]),this.min[1]=Math.min(this.p0[1],this.p1[1],this.p2[1]),this.max[0]=Math.max(this.p0[0],this.p1[0],this.p2[0]),this.max[1]=Math.max(this.p0[1],this.p1[1],this.p2[1]);const h=u(J,this.p1,this.p0),c=u(K,this.p2,this.p1);this.normal=function(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;return s>0&&(s=1/Math.sqrt(s)),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s,t}(this.normal,function(t,e,r){var n=e[0],i=e[1],s=e[2],a=r[0],o=r[1],h=r[2];return t[0]=i*h-s*o,t[1]=s*a-n*h,t[2]=n*o-i*a,t}(this.normal,h,c))}contains(t,e){if(t<this.min[0]||t>this.max[0]||e<this.min[1]||e>this.max[1])return!1;g(X,this.p0[0],this.p0[1]),g(Q,this.p1[0],this.p1[1]),g(tt,this.p2[0],this.p2[1]);const r=st(X[0],X[1],Q[0],Q[1],tt[0],tt[1]);return st(t,e,X[0],X[1],tt[0],tt[1])+st(t,e,X[0],X[1],Q[0],Q[1])+st(t,e,Q[0],Q[1],tt[0],tt[1])-r<=1e-4}getHeight(t,e){const r=this.normal;return this.p0[2]-((t-this.p0[0])*r[0]+(e-this.p0[1])*r[1])/r[2]}}let rt=null;function nt(t,e,r){if(rt&&rt.contains(e,r))return rt.getHeight(e,r);for(let n=0;n<t.length;n++)if(t[n].contains(e,r))return rt=t[n],t[n].getHeight(e,r);return 0}const it=[];function st(t,e,r,n,i,s){return.5*Math.abs(t*n+r*s+i*e-t*s-r*e-i*n)}function at(t,e,r,n,i,s,a){"cesium-ion"===r&&(e.Authorization="Bearer "+H),function(t,e,r){const n={method:"GET",referrer:r,headers:e},i=c.getArrayBuffer(t,n),s=i.xhr;return P[t]=s,i.then((e=>(delete P[t],e)))}(t,e,origin).then((t=>{if(!t||t.message)a(t?{empty:!0,originalError:t}:{error:{canceled:!0}});else{const e=t.data;let o=null;if("tianditu"===r){const t=W(e,n);ht(i,t,n,null,s,a)}else if("cesium-ion"===r||"cesium"===r){o=$(e);const t=function(t,e){const{positions:r,min:n,max:i,indices:s,radius:a}=t,o=[];let h=0;for(let t=0;t<s.length;t+=3){let e=it[h];e?e.set(r,s[t],s[t+1],s[t+2],2*a):e=it[h]=new et(r,s[t],s[t+1],s[t+2],2*a),h++,o.push(e)}const c=new Float32Array(e*e);h=0;for(let t=0;t<e;t++)for(let r=0;r<e;r++)c[h++]=nt(o,r/e*a*2,t/e*a*2);return{data:c,min:n,max:i,width:e,height:e}}(o,n);ht(i,t,n,null,s,a)}else"mapbox"===r&&(o=function(t){const e=new self.Blob([new Uint8Array(t)]);return self.createImageBitmap(e)}(e),o.then((t=>{const e=ft(ct(t),n);ht(i,e,n,t,s,a)})))}})).catch((e=>{delete P[t],a({empty:!0,originalError:e})}))}function ot(t,e){const r=Math.floor(10*(t+1e4)),n=r>>16,i=r>>8&255,s=255&r;return e?(e[0]=n,e[1]=i,e[2]=s,e):[n,i,s]}function ht(t,e,r,n,i,s){const a=function(t,e,r,n){let i,s=y[r];s||(s=y[r]=new d(r)),i=s.createTile(e).getMeshWithSkirts(t,!0);const{triangles:a,vertices:o,leftSkirtIndex:h,rightSkirtIndex:c,bottomSkirtIndex:f,topSkirtIndex:l}=i;let{numVerticesWithoutSkirts:u,numTrianglesWithoutSkirts:g}=i;u||(u=o.length/2,g=a.length/3);const p=o.length/2,m=new Float32Array(3*p),b=new Float32Array(2*p);let w=1/0,A=-1/0;const v=r-1;for(let t=0;t<p;t++){const n=o[2*t],i=o[2*t+1];if(t>=u){const e=n/2*3;let r,i=.001;(t-(t<h/2?u:t<c/2?h/2:t<f/2?c/2:f/2))%3==0?(r=Math.min(0,w),i=0):r=m[e+2],m[3*t]=m[e],m[3*t+1]=m[e+1],m[3*t+2]=r,b[2*t]=m[e]/v+i,b[2*t+1]=-m[e+1]/v+i}else{const s=e[i*r+n];m[3*t]=1*n,m[3*t+1]=1*-i,m[3*t+2]=s,b[2*t]=n/v,b[2*t+1]=i/v,s<w&&(w=s),s>A&&(A=s)}}return{positions:m,texcoords:b,triangles:a,leftSkirtIndex:h,rightSkirtIndex:c,bottomSkirtIndex:f,topSkirtIndex:l,numTrianglesWithoutSkirts:g,numVerticesWithoutSkirts:u,minHeight:Math.min(0,w),maxHeight:A,terrainWidth:r}}(t,e.data,r),o=[a.positions.buffer,a.texcoords.buffer,a.triangles.buffer];n||(n=function(t){if(O(),!z)return;const{width:e,height:r,data:n}=t;if(e&&r&&n)try{let t=z.getContext("2d",{willReadFrequently:!0});const i=t.createImageData(e,r);for(let t=0,e=n.length;t<e;t++){const e=n[t],[r,s,a]=ot(e,_),o=4*t;i.data[o]=r,i.data[o+1]=s,i.data[o+2]=a,i.data[o+3]=255}return z.width=e,z.height=r,t=z.getContext("2d",{willReadFrequently:!0}),lt(t),t.putImageData(i,0,0),z.transferToImageBitmap()}catch(t){console.log(t)}}(e)),n&&o.push(n);const h={mesh:a};h.image=n,h.data=e,o.push(e.data.buffer),s(h,o)}function ct(t){const{width:e,height:r}=t;return z||(z=new OffscreenCanvas(1,1),N=z.getContext("2d",{willReadFrequently:!0})),z.width=e,z.height=r,N.drawImage(t,0,0,e,r),N.getImageData(0,0,e,r)}function ft(t,e){const{data:r,width:n}=t;let i=1/0,s=-1/0;const a=new Float32Array(e*e),o=Math.round(n/e);for(let t=0;t<e;t++)for(let h=0;h<e;h++){const c=t+h*e;let f=0,l=0;const u=t,g=h;for(let t=0;t<o;t++)for(let e=0;e<o;e++){let i=u*o+t,s=g*o+e;s>n-1&&(s=n-1),i>n-1&&(i=n-1);const a=i+s*n,h=r[4*a],c=r[4*a+1],d=r[4*a+2];0===r[4*a+3]?l+=1:f+=.1*(256*h*256+256*c+d)-1e4}f/=o*o-l||1,f>s&&(s=f),f<i&&(i=f),a[c]=f}return{data:a,width:e,height:e,min:i,max:s}}function lt(t){const e=t.canvas,{width:r,height:n}=e;t.clearRect(0,0,r,n)}function ut(t,e,r){if(!e||!Array.isArray(e)||e.length<2)return;if(!t||!t.image)return null;let{width:n,height:i}=t.image;(r=r||C)[0]===n&&r[1]===i||(n=r[0],i=r[1]),n*=2,i*=2;try{if(O(),!z)return;const r=z;r.width=n,r.height=i;const s=r.getContext("2d",{willReadFrequently:!0});lt(s),s.drawImage(t.image,0,0,n,i);const a=s.getImageData(0,0,n,i);!function(t,e){const r=JSON.stringify(e);R[r]||(R[r]=new v(e));const n=R[r],i=t.data;for(let t=0,e=i.length;t<e;t+=4){const e=i[t],r=i[t+1],s=i[t+2];let a=0;0!==i[t+3]&&(a=.1*(256*e*256+256*r+s)-1e4,a=Math.max(a,0));const[o,h,c]=n.getColor(a);i[t]=o,i[t+1]=h,i[t+2]=c,i[t+3]=255}}(a,e),s.putImageData(a,0,0);const o=r.transferToImageBitmap();s.save(),s.scale(1,-1),s.drawImage(o,0,-i,n,i),s.restore();const h=r.transferToImageBitmap();return o.close(),h}catch(t){console.error(t)}}t.initialize=function(){},t.onmessage=function(t,e){const r=t.data;if("addLayer"===r.command||"removeLayer"===r.command)B=t.workerId,self.postMessage({type:"<response>",actorId:r.actorId,workerId:B,params:"ok",callback:t.callback});else if("fetchTerrain"===r.command){const t=(r.params||{}).colors,n=(r.params||{}).tileSize;!function(t,e){const{url:r,origin:n,type:i,accessToken:s,terrainWidth:a,error:o,tileImage:h}=t,c=!0;if(h&&h.close){const t=ft(ct(h),a);return void ht(o,t,a,h,0,e)}const f=t.headers||q[i];if("tianditu"===i)at(r,f,i,a,o,c,e);else if("cesium-ion"===i){const h=t.cesiumIonTokenURL+s;H?at(r,f,i,a,o,c,e):(Y||(Y=fetch(h,{responseType:"json",method:"GET",referrer:n,headers:{Accept:"application/json,*/*;q=0.01","Accept-Encoding":"gzip, deflate, br"}}).then((t=>t.json())).then((t=>{H=t.accessToken,Y=null}))),Y.then((()=>{at(r,f,i,a,o,c,e)})))}else("cesium"===i||"mapbox"===i)&&at(r,f,i,a,o,c,e)}(r.params,((r,i)=>{i=i||[];const s=ut(r,t,n);s&&(r.colorsTexture=s,i.push(s));const a=function(t){if(!t)return;const{positions:e,texcoords:r,triangles:n,leftSkirtIndex:i,rightSkirtIndex:s,bottomSkirtIndex:a,numVerticesWithoutSkirts:o}=t;if(!e||!r||!n)return;if(!(F(i)&&F(s)&&F(a)&&F(o)))return;const h=new Int8Array(e.length);for(let t=2;t<h.length;t+=3)t<3*o?h[t]=1:t<i/2*3?h[t-2]=-1:t<s/2*3?h[t-2]=1:h[t-1]=t<a/2*3?-1:1;const c=I(e,h,r,n);return new Float32Array(c)}(r.mesh);a&&r.mesh&&(r.mesh.tangents=a,i.push(a.buffer)),e(r.error,r,i)}))}else"abortTerrain"===r.command&&(n=r.params.url,P[n]&&(P[n].abort(),delete P[n]));var n}}`;
34603
34953
 
34604
34954
  const code = `function(t){var n,r="undefined"!=typeof Float32Array?Float32Array:Array;function o(t,n,r){return t[0]=n[0]*r,t[1]=n[1]*r,t[2]=n[2]*r,t}function e(t,n,r,o){return t[0]=n[0]+r[0]*o,t[1]=n[1]+r[1]*o,t[2]=n[2]+r[2]*o,t}function a(t,n){var r=n[0],o=n[1],e=n[2],a=r*r+o*o+e*e;return a>0&&(a=1/Math.sqrt(a)),t[0]=n[0]*a,t[1]=n[1]*a,t[2]=n[2]*a,t}
34605
34955
  /*!
@@ -34615,5 +34965,5 @@ maptalks.registerWorkerAdapter('maplight', code);
34615
34965
 
34616
34966
  export { Area3DTool, BoxInsideClipper as BoxInsideClipMask, BoxOutsideClipper as BoxOutsideClipMask, canvasCompatible as CanvasCompatible, ClipInsideMask, ClipOutsideMask, ColorMask, context as ContextUtil, Distance3DTool, ElevateMask, FlatInsideMask$1 as FlatInsideMask, FlatInsideMask as FlatOutsideMask, GroundPainter, GroupGLLayer, HeatmapProcess, Height3DTool, highlight as HighlightUtil, ImageMask, MapGLRenderer, MapGPURenderer, MaskLayerMixin, MaskRendererMixin, Measure3DTool, RayCaster, VideoMask, Color$1 as color, earcut$1 as earcut, index as reshader, transcoders };
34617
34967
 
34618
- typeof console !== 'undefined' && console.log('@maptalks/gpu v0.119.0');
34968
+ typeof console !== 'undefined' && console.log('@maptalks/gpu v0.121.0');
34619
34969
  //# sourceMappingURL=maptalksgpu.es.js.map