@maptalks/gpu 0.116.0 → 0.117.1

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.116.0
2
+ * @maptalks/gpu v0.117.1
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2025 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.116.0
70
+ * @maptalks/gltf-loader v0.117.1
71
71
  * LICENSE : UNLICENSED
72
72
  * (c) 2016-2025 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;}return e.format&&(s.format=e.format),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={});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') {
@@ -509,7 +509,7 @@ function hashCode(s) {
509
509
  * @param value - input value
510
510
  * @returns
511
511
  */
512
- function isPowerOfTwo(value) {
512
+ function isPowerOfTwo$1(value) {
513
513
  return (value & (value - 1)) === 0 && value !== 0;
514
514
  }
515
515
  /**
@@ -528,10 +528,10 @@ function floorPowerOfTwo(value) {
528
528
  function resizeFromArray(arr, width, height) {
529
529
  let newWidth = width;
530
530
  let newHeight = height;
531
- if (!isPowerOfTwo(width)) {
531
+ if (!isPowerOfTwo$1(width)) {
532
532
  newWidth = floorPowerOfTwo(width);
533
533
  }
534
- if (!isPowerOfTwo(height)) {
534
+ if (!isPowerOfTwo$1(height)) {
535
535
  newHeight = floorPowerOfTwo(height);
536
536
  }
537
537
  const imageData = new ImageData(new Uint8ClampedArray(arr), width, height);
@@ -558,7 +558,7 @@ function resizeFromArray(arr, width, height) {
558
558
  function resizeToPowerOfTwo(image, width, height) {
559
559
  if (isArray(image)) {
560
560
  image = image;
561
- if (!isPowerOfTwo(width) || !isPowerOfTwo(height)) {
561
+ if (!isPowerOfTwo$1(width) || !isPowerOfTwo$1(height)) {
562
562
  return resizeFromArray(image, width, height);
563
563
  }
564
564
  else {
@@ -566,15 +566,15 @@ function resizeToPowerOfTwo(image, width, height) {
566
566
  }
567
567
  }
568
568
  image = image;
569
- if (isPowerOfTwo(image.width) && isPowerOfTwo(image.height)) {
569
+ if (isPowerOfTwo$1(image.width) && isPowerOfTwo$1(image.height)) {
570
570
  return image;
571
571
  }
572
572
  width = image.width;
573
573
  height = image.height;
574
- if (!isPowerOfTwo(width)) {
574
+ if (!isPowerOfTwo$1(width)) {
575
575
  width = floorPowerOfTwo(width);
576
576
  }
577
- if (!isPowerOfTwo(height)) {
577
+ if (!isPowerOfTwo$1(height)) {
578
578
  height = floorPowerOfTwo(height);
579
579
  }
580
580
  const canvas = document.createElement('canvas');
@@ -625,7 +625,7 @@ var Util = /*#__PURE__*/Object.freeze({
625
625
  isInterleaved: isInterleaved,
626
626
  isNil: isNil$2,
627
627
  isNumber: isNumber$2,
628
- isPowerOfTwo: isPowerOfTwo,
628
+ isPowerOfTwo: isPowerOfTwo$1,
629
629
  isString: isString,
630
630
  isSupportVAO: isSupportVAO,
631
631
  isTextureDestroyed: isTextureDestroyed,
@@ -1849,15 +1849,25 @@ class Geometry {
1849
1849
  const ctor = array.constructor;
1850
1850
  const itemSize = array.length / vertexCount;
1851
1851
  const bytesPerElement = itemBytes / itemSize;
1852
- // 无法对齐时,itemSize 一定是1或者3,补位成2或者4就能对齐了
1853
- const newItemSize = ensureAlignment(itemSize, bytesPerElement);
1854
- const newArray = new ctor(newItemSize * vertexCount);
1855
- for (let i = 0; i < vertexCount; i++) {
1856
- for (let ii = 0; ii < itemSize; ii++) {
1857
- newArray[i * newItemSize + ii] = array[i * itemSize + ii];
1852
+ // 无法对齐时,itemSize 一定是1,2,3,不可能是4
1853
+ if (itemSize === 3) {
1854
+ // itemSize 为 3时,补位为 4,wgsl中需要相应修改类型声明
1855
+ const newItemSize = ensureAlignment(itemSize, bytesPerElement);
1856
+ const newArray = new ctor(newItemSize * vertexCount);
1857
+ for (let i = 0; i < vertexCount; i++) {
1858
+ for (let ii = 0; ii < itemSize; ii++) {
1859
+ newArray[i * newItemSize + ii] = array[i * itemSize + ii];
1860
+ }
1858
1861
  }
1862
+ return newArray;
1863
+ }
1864
+ else {
1865
+ // itemSize 为 1或2时,提升数组的类型,不影响wgsl中的类型声明
1866
+ const newCtor = getPadArrayCtor(ctor, itemSize);
1867
+ const newArray = new newCtor(itemSize * vertexCount);
1868
+ newArray.set(array);
1869
+ return newArray;
1859
1870
  }
1860
- return newArray;
1861
1871
  }
1862
1872
  constructor(data, elements, count, desc) {
1863
1873
  this._version = 0;
@@ -2115,9 +2125,6 @@ class Geometry {
2115
2125
  if (Array.isArray(data[key])) {
2116
2126
  data[key] = new Float32Array(data[key]);
2117
2127
  }
2118
- else if (isWebGPU && isArray(data[key])) {
2119
- data[key] = Geometry.padGPUBufferAlignment(data[key], vertexCount);
2120
- }
2121
2128
  //如果调用过addBuffer,buffer有可能是ArrayBuffer
2122
2129
  if (data[key].buffer !== undefined && !(data[key].buffer instanceof ArrayBuffer)) {
2123
2130
  if (data[key].buffer.destroy) {
@@ -2132,7 +2139,12 @@ class Geometry {
2132
2139
  else {
2133
2140
  const arr = data[key].data ? data[key].data : data[key];
2134
2141
  const dimension = arr.length / vertexCount;
2135
- const info = data[key].data ? data[key] : { data: data[key] };
2142
+ let bufferData = arr;
2143
+ if (isWebGPU) {
2144
+ bufferData = Geometry.padGPUBufferAlignment(arr, vertexCount);
2145
+ }
2146
+ const info = data[key].data ? data[key] : {};
2147
+ info.data = bufferData;
2136
2148
  info.dimension = dimension;
2137
2149
  const buffer = Geometry.createBuffer(device, info, key);
2138
2150
  buffer[REF_COUNT_KEY] = 1;
@@ -2166,9 +2178,16 @@ class Geometry {
2166
2178
  else {
2167
2179
  ctor = this.elements.constructor;
2168
2180
  }
2169
- this.indices = new ctor(elements.length);
2170
- for (let i = 0; i < elements.length; i++) {
2171
- this.indices[i] = elements[i];
2181
+ if (elements instanceof ctor) {
2182
+ //2x faster by new TypeArray(typearray)
2183
+ //https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array
2184
+ this.indices = new ctor(elements);
2185
+ }
2186
+ else {
2187
+ this.indices = new ctor(elements.length);
2188
+ for (let i = 0; i < elements.length; i++) {
2189
+ this.indices[i] = elements[i];
2190
+ }
2172
2191
  }
2173
2192
  }
2174
2193
  this.elements = this.elements.destroy ? this.elements : Geometry.createElementBuffer(device, this.elements);
@@ -2279,7 +2298,8 @@ class Geometry {
2279
2298
  if (buffer) {
2280
2299
  if (buffer.buffer.mapState) {
2281
2300
  //webgpu buffer
2282
- buffer.buffer = this._updateGPUBuffer(buffer.buffer, data);
2301
+ data = Geometry.padGPUBufferAlignment(data, this._vertexCount);
2302
+ buffer.buffer = this._updateGPUBuffer(buffer.buffer, data, 0, data.buffer.byteLength);
2283
2303
  }
2284
2304
  else {
2285
2305
  buffer.buffer(data);
@@ -2293,7 +2313,7 @@ class Geometry {
2293
2313
  delete this._reglData;
2294
2314
  return this;
2295
2315
  }
2296
- _updateGPUBuffer(buffer, data) {
2316
+ _updateGPUBuffer(buffer, data, offset, byteLength) {
2297
2317
  if (Array.isArray(data)) {
2298
2318
  data = new Float32Array(data);
2299
2319
  }
@@ -2305,7 +2325,7 @@ class Geometry {
2305
2325
  buffer.destroy();
2306
2326
  return newBuffer;
2307
2327
  }
2308
- device.wgpu.queue.writeBuffer(buffer, 0, data.buffer, 0, data.buffer.byteLength);
2328
+ device.wgpu.queue.writeBuffer(buffer, 0, data.buffer, offset, byteLength);
2309
2329
  return buffer;
2310
2330
  }
2311
2331
  updateSubData(name, data, offset) {
@@ -2322,12 +2342,24 @@ class Geometry {
2322
2342
  this._updateSubBoundingBox(data);
2323
2343
  }
2324
2344
  if (buffer) {
2325
- const byteWidth = REGL_TYPE_WIDTH[buffer.buffer['_buffer'].dtype];
2326
- if (data.BYTES_PER_ELEMENT !== byteWidth) {
2327
- const ctor = getTypeCtor(data, byteWidth);
2328
- data = new ctor(data);
2345
+ if (buffer.buffer.mapState) {
2346
+ //webgpu buffer
2347
+ data = Geometry.padGPUBufferAlignment(data, this._vertexCount);
2348
+ const byteWidth = buffer.buffer.bytesPerElement;
2349
+ if (data.BYTES_PER_ELEMENT !== byteWidth) {
2350
+ const ctor = getTypeCtor(data, byteWidth);
2351
+ data = new ctor(data);
2352
+ }
2353
+ buffer.buffer = this._updateGPUBuffer(buffer.buffer, data, offset * byteWidth, data.buffer.byteLength);
2354
+ }
2355
+ else {
2356
+ const byteWidth = REGL_TYPE_WIDTH[buffer.buffer['_buffer'].dtype];
2357
+ if (data.BYTES_PER_ELEMENT !== byteWidth) {
2358
+ const ctor = getTypeCtor(data, byteWidth);
2359
+ data = new ctor(data);
2360
+ }
2361
+ buffer.buffer.subdata(data, offset * byteWidth);
2329
2362
  }
2330
- buffer.buffer.subdata(data, offset * byteWidth);
2331
2363
  }
2332
2364
  else {
2333
2365
  const arr = this.data[name].data ? this.data[name].data : this.data[name];
@@ -2365,7 +2397,7 @@ class Geometry {
2365
2397
  const ctor = findElementConstructor(elements);
2366
2398
  elements = new ctor(elements);
2367
2399
  }
2368
- this.elements = this._updateGPUBuffer(e, elements);
2400
+ this.elements = this._updateGPUBuffer(e, elements, 0, elements.buffer.byteLength);
2369
2401
  }
2370
2402
  else {
2371
2403
  this.elements = e(elements);
@@ -2609,13 +2641,19 @@ class Geometry {
2609
2641
  }
2610
2642
  }
2611
2643
  }
2612
- createTangent(name = 'aTangent') {
2644
+ createTangent(name = 'aTangent', tangentsDataArray) {
2613
2645
  this._incrVersion();
2614
2646
  //TODO data 可能是含stride的interleaved类型
2615
2647
  const { normalAttribute, positionAttribute, uv0Attribute } = this.desc;
2616
2648
  const normals = this._getAttributeData(normalAttribute);
2617
2649
  const positions = this._getAttributeData(positionAttribute);
2618
- const tangents = buildTangents(positions, normals, this.data[uv0Attribute], this.elements);
2650
+ let tangents;
2651
+ if (tangentsDataArray && tangentsDataArray.length) {
2652
+ tangents = tangentsDataArray;
2653
+ }
2654
+ else {
2655
+ tangents = buildTangents(positions, normals, this.data[uv0Attribute], this.elements);
2656
+ }
2619
2657
  const aTangent = this.data[name] = new Float32Array(tangents.length);
2620
2658
  const t = [0, 0, 0, 0], n = [0, 0, 0], q = [0, 0, 0, 0];
2621
2659
  for (let i = 0; i < tangents.length; i += 4) {
@@ -3009,6 +3047,34 @@ function ensureAlignment(itemSize, bytesPerElement) {
3009
3047
  }
3010
3048
  return itemSize + (4 - (itemBytes % 4)) / bytesPerElement;
3011
3049
  }
3050
+ // itemSize 只可能是1,2
3051
+ function getPadArrayCtor(ctor, itemSize) {
3052
+ if (ctor === Uint8Array || ctor === Uint8ClampedArray) {
3053
+ if (itemSize === 1) {
3054
+ return Uint32Array;
3055
+ }
3056
+ else {
3057
+ return Uint16Array;
3058
+ }
3059
+ }
3060
+ else if (ctor === Int8Array) {
3061
+ if (itemSize === 1) {
3062
+ return Int32Array;
3063
+ }
3064
+ else {
3065
+ return Int16Array;
3066
+ }
3067
+ }
3068
+ else if (ctor === Uint16Array) {
3069
+ return Uint32Array;
3070
+ }
3071
+ else if (ctor === Int16Array) {
3072
+ return Int32Array;
3073
+ }
3074
+ else {
3075
+ throw new Error('sth unexpected in getPadArrayCtor');
3076
+ }
3077
+ }
3012
3078
 
3013
3079
  const reglPrimitives = ['points', 'lines', 'line strip', 'line loop', 'triangles', 'triangle strip', 'triangle fan'];
3014
3080
  function getPrimitive(mode) {
@@ -8677,6 +8743,9 @@ class Renderer {
8677
8743
  clear(options) {
8678
8744
  this.device.clear(options);
8679
8745
  }
8746
+ isWebGPU() {
8747
+ return !!this.device.wgpu;
8748
+ }
8680
8749
  }
8681
8750
 
8682
8751
  const Ajax = {
@@ -9485,7 +9554,7 @@ class Texture2D extends AbstractTexture {
9485
9554
  config.width = config.data.width;
9486
9555
  config.height = config.data.height;
9487
9556
  }
9488
- else if (!config.hdr && isArray(config.data) && (!isPowerOfTwo(config.width) || !isPowerOfTwo(config.height))) {
9557
+ else if (!config.hdr && isArray(config.data) && (!isPowerOfTwo$1(config.width) || !isPowerOfTwo$1(config.height))) {
9489
9558
  config.data = resizeToPowerOfTwo(config.data, config.width, config.height);
9490
9559
  config.width = config.data.width;
9491
9560
  config.height = config.data.height;
@@ -9507,17 +9576,16 @@ class Texture2D extends AbstractTexture {
9507
9576
  class Plane extends Geometry {
9508
9577
  constructor(z) {
9509
9578
  z = z || 0;
9510
- const arrType = getPosArrayType(z);
9511
9579
  super({
9512
9580
  //width and height are both 1
9513
- aPosition: new arrType([
9581
+ aPosition: new Float32Array([
9514
9582
  -1, -1, z, // left bottom
9515
9583
  1, -1, z, // right bottom
9516
9584
  -1, 1, z, // left top
9517
9585
  1, 1, z, // right top
9518
9586
  ]),
9519
9587
  // Normal
9520
- aNormal: new Int8Array([
9588
+ aNormal: new Float32Array([
9521
9589
  0, 0, 1,
9522
9590
  0, 0, 1,
9523
9591
  0, 0, 1,
@@ -10636,8 +10704,7 @@ const frag$o = /* wgsl */ `
10636
10704
  }
10637
10705
  #endif
10638
10706
 
10639
- fn computeTexCoord(vertexOutput: VertexOutput) -> vec2f {
10640
- let texCoord = vertexOutput.vTexCoord;
10707
+ fn computeTexCoord(texCoord: vec2f, vertexOutput: VertexOutput) -> vec2f {
10641
10708
  #ifdef HAS_I3S_UVREGION
10642
10709
  let atlasScale = vertexOutput.vUvRegion.zw - vertexOutput.vUvRegion.xy;
10643
10710
  let uvAtlas = fract(texCoord) * atlasScale + vertexOutput.vUvRegion.xy;
@@ -11061,7 +11128,11 @@ const vert$d = /*wgsl*/ `
11061
11128
  #include <get_output>
11062
11129
 
11063
11130
  struct VertexInput {
11064
- @location($i) aPosition: vec3f,
11131
+ #ifdef POSITION_IS_INT
11132
+ @location($i) aPosition: vec4i,
11133
+ #else
11134
+ @location($i) aPosition: vec3f,
11135
+ #endif
11065
11136
  }
11066
11137
 
11067
11138
  struct Uniforms {
@@ -11620,8 +11691,8 @@ class GraphicsTexture {
11620
11691
  }
11621
11692
  let texture;
11622
11693
  {
11623
- let width = config.width;
11624
- let height = config.height;
11694
+ let width = isFunction$1(config.width) ? config.width() : config.width;
11695
+ let height = isFunction$1(config.height) ? config.height() : config.height;
11625
11696
  if (width === undefined || height === undefined) {
11626
11697
  const data = config.data;
11627
11698
  if (isArray(config.data)) {
@@ -12351,8 +12422,8 @@ class CommandBuilder {
12351
12422
  fragGroups = fragReflect.getBindGroups();
12352
12423
  }
12353
12424
  // generate bind group layout
12354
- const layout = this._createBindGroupLayout(vertGroups, fragGroups, mesh, this.uniformValues);
12355
- const pipeline = this._createPipeline(device, vert, vertexInfo, frag, layout, mesh, pipelineDesc, fbo);
12425
+ const layout = this._createCommandBindGroupLayout(vertGroups, fragGroups, mesh, this.uniformValues);
12426
+ const pipeline = this._createCommandPipeline(device, vert, vertexInfo, frag, layout, mesh, pipelineDesc, fbo);
12356
12427
  const bindGroupMapping = this._createBindGroupMapping(vertGroups, fragGroups, mesh);
12357
12428
  const alignment = device.wgpu.limits.minUniformBufferOffsetAlignment;
12358
12429
  const bindGroupFormat = new BindGroupFormat(this.name, bindGroupMapping, alignment);
@@ -12373,7 +12444,7 @@ class CommandBuilder {
12373
12444
  attributes.key = attributes.map(attr => attr.name).join();
12374
12445
  return attributes;
12375
12446
  }
12376
- _createBindGroupLayout(vertGroups, fragGroups, mesh, uniformValues) {
12447
+ _createCommandBindGroupLayout(vertGroups, fragGroups, mesh, uniformValues) {
12377
12448
  const entries = [];
12378
12449
  for (let i = 0; i < vertGroups.length; i++) {
12379
12450
  const groupInfo = vertGroups[i];
@@ -12420,6 +12491,7 @@ class CommandBuilder {
12420
12491
  const name = groupInfo.name;
12421
12492
  const texture = uniformValues[name] || mesh.material && mesh.material.get(name);
12422
12493
  let format;
12494
+ let multisampled = false;
12423
12495
  if (texture) {
12424
12496
  if (texture instanceof Texture2D) {
12425
12497
  format = texture.config.type;
@@ -12427,8 +12499,11 @@ class CommandBuilder {
12427
12499
  else if (texture instanceof GraphicsTexture) {
12428
12500
  format = texture.gpuFormat.format;
12429
12501
  }
12502
+ multisampled = !!(texture.config && texture.config.sampleCount > 1);
12430
12503
  }
12431
- let sampleType = 'float'; //sint, uint
12504
+ // https://gpuweb.github.io/gpuweb/#dictdef-gputexturebindinglayout
12505
+ // 根据规范,如果 multisampled 为真,sampleType 不能是float
12506
+ let sampleType = multisampled ? 'unfilterable-float' : 'float';
12432
12507
  if (format && format.startsWith('depth')) {
12433
12508
  sampleType = 'depth';
12434
12509
  }
@@ -12436,6 +12511,7 @@ class CommandBuilder {
12436
12511
  binding,
12437
12512
  visibility,
12438
12513
  texture: {
12514
+ multisampled,
12439
12515
  sampleType
12440
12516
  }
12441
12517
  };
@@ -12537,7 +12613,7 @@ class CommandBuilder {
12537
12613
  }
12538
12614
  }
12539
12615
  // 运行时调用,生成 uniform buffer, 用来存放全局 uniform 变量的值
12540
- _createPipeline(graphicsDevice, vert, vertInfo, frag, layout, mesh, pipelineDesc, fbo) {
12616
+ _createCommandPipeline(graphicsDevice, vert, vertInfo, frag, layout, mesh, pipelineDesc, fbo) {
12541
12617
  const device = graphicsDevice.wgpu;
12542
12618
  const vertModule = device.createShaderModule({
12543
12619
  label: this.name + '-vertmodule',
@@ -13420,9 +13496,9 @@ var phongFrag = "precision mediump float;\n#include <gl2_frag>\nuniform vec4 bas
13420
13496
 
13421
13497
  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}";
13422
13498
 
13423
- var wgslVert$3 = "struct VertexInput {\n#if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n#else\n @location($i) aPosition: vec3f,\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 @location($i) aNormal: vec3f,\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(vertexInput.aNormal);\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);\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}";
13499
+ var wgslVert$4 = "struct VertexInput {\n#if HAS_DRACO_POSITION || HAS_COMPRESSED_INT16_POSITION\n @location($i) aPosition: vec4i,\n#else\n @location($i) aPosition: vec3f,\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 @location($i) aNormal: vec3f,\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(vertexInput.aNormal);\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);\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}";
13424
13500
 
13425
- var wgslFrag$3 = "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\nstruct VertexOutput {\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};\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();\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}";
13501
+ var wgslFrag$4 = "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\nstruct VertexOutput {\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};\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();\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}";
13426
13502
 
13427
13503
  class PhongShader extends MeshShader {
13428
13504
  constructor(config = {}) {
@@ -13452,8 +13528,8 @@ class PhongShader extends MeshShader {
13452
13528
  name: 'phong',
13453
13529
  vert: config.vert || phongVert,
13454
13530
  frag: config.frag || phongFrag,
13455
- wgslVert: wgslVert$3,
13456
- wgslFrag: wgslFrag$3,
13531
+ wgslVert: wgslVert$4,
13532
+ wgslFrag: wgslFrag$4,
13457
13533
  uniforms,
13458
13534
  defines: config.defines || {},
13459
13535
  extraCommandProps: config.extraCommandProps || {}
@@ -13499,7 +13575,9 @@ class PointLineShader extends MeshShader {
13499
13575
 
13500
13576
  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}";
13501
13577
 
13502
- const quadVertices$1 = new Int8Array([
13578
+ 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}";
13579
+
13580
+ const quadVertices$1 = new Float32Array([
13503
13581
  // positions
13504
13582
  -1.0, 1.0,
13505
13583
  -1.0, -1.0,
@@ -13508,7 +13586,7 @@ const quadVertices$1 = new Int8Array([
13508
13586
  -1.0, -1.0,
13509
13587
  1.0, -1.0,
13510
13588
  ]);
13511
- const quadTexcoords$1 = new Uint8Array([
13589
+ const quadTexcoords$1 = new Float32Array([
13512
13590
  0.0, 1.0,
13513
13591
  0.0, 0.0,
13514
13592
  1.0, 1.0,
@@ -13520,6 +13598,7 @@ const quadTexcoords$1 = new Uint8Array([
13520
13598
  class QuadShader extends MeshShader {
13521
13599
  constructor(config) {
13522
13600
  config.vert = config.vert || vert$c;
13601
+ config.wgslVert = config.wgslVert || wgslVert$3;
13523
13602
  config.extraCommandProps = config.extraCommandProps || {};
13524
13603
  if (!config.extraCommandProps.depth) {
13525
13604
  //disable depth
@@ -13582,18 +13661,21 @@ class QuadShader extends MeshShader {
13582
13661
 
13583
13662
  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 enableOutline;\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}";
13584
13663
 
13664
+ var wgslFrag$3 = "struct VertexOutput {\n @location($o) vTexCoord: vec2f\n}\nstruct 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 enableOutline: f32,\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 if (uniforms.enableOutline == 1.0) {\n color = composeOutline(color);\n }\n #endif\n return color;\n}";
13665
+
13585
13666
  class FxaaShader extends QuadShader {
13586
13667
  constructor() {
13587
13668
  super({
13588
- vert: vert$c, frag: frag$h,
13669
+ name: 'fxaa',
13670
+ frag: frag$h, wgslFrag: wgslFrag$3,
13589
13671
  extraCommandProps: {
13590
13672
  viewport: {
13591
13673
  x: 0,
13592
13674
  y: 0,
13593
- width: (context, props) => {
13675
+ width: (_, props) => {
13594
13676
  return props['resolution'][0];
13595
13677
  },
13596
- height: (context, props) => {
13678
+ height: (_, props) => {
13597
13679
  return props['resolution'][1];
13598
13680
  }
13599
13681
  }
@@ -14782,16 +14864,15 @@ var frag$a = "precision highp float;\nuniform sampler2D texture;\nuniform vec2 s
14782
14864
  class CopyShader extends QuadShader {
14783
14865
  constructor() {
14784
14866
  super({
14785
- vert: vert$c,
14786
14867
  frag: frag$a,
14787
14868
  extraCommandProps: {
14788
14869
  viewport: {
14789
14870
  x: 0,
14790
14871
  y: 0,
14791
- width: (context, props) => {
14872
+ width: (_, props) => {
14792
14873
  return props['size'][0];
14793
14874
  },
14794
- height: (context, props) => {
14875
+ height: (_, props) => {
14795
14876
  return props['size'][1];
14796
14877
  }
14797
14878
  }
@@ -15643,663 +15724,671 @@ class GeometryResource {
15643
15724
  }
15644
15725
  }
15645
15726
 
15646
- let timespan = 0;
15647
-
15648
- const MAT4 = [];
15649
- const TEMP_VEC$1 = [];
15650
-
15651
- class GLTFPack {
15652
-
15653
- constructor(gltf, regl) {
15654
- this.gltf = gltf;
15655
- this.regl = regl;
15656
- this.geometries = [];
15657
- if (regl) {
15658
- this._emptyTexture = regl.texture({ width: 2, height: 2 });
15659
- }
15660
- }
15661
-
15662
- getMeshesInfo() {
15663
- if (!this.gltf) {
15664
- return null;
15665
- }
15666
- if (this.geometries.length) {
15667
- return this.geometries;
15668
- }
15669
- this._createTextures(this.gltf.textures);
15670
- this._createSkins(this.gltf.skins);
15671
- const nodes = this.gltf.scenes[0].nodes;
15672
- nodes.forEach((node) => {
15673
- this._parserNode(node, this.geometries);
15674
- });
15675
- this._checkBaseColorFactor();
15676
- return this.geometries;
15677
- }
15678
-
15679
- getGLTFBBox() {
15680
- if (!this.gltf) {
15681
- return null;
15682
- }
15683
- const geometries = this.geometries;
15684
- if (!geometries || !geometries.length) {
15685
- return null;
15686
- }
15687
- const min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];
15688
- for (let i = 0; i < geometries.length; i++) {
15689
- const bbox = geometries[i].bbox;
15690
- const bboxMin = bbox.min, bboxMax = bbox.max;
15691
- if (bboxMin[0] < min[0]) {
15692
- min[0] = bboxMin[0];
15693
- }
15694
- if (bboxMin[1] < min[1]) {
15695
- min[1] = bboxMin[1];
15696
- }
15697
- if (bboxMin[2] < min[2]) {
15698
- min[2] = bboxMin[2];
15699
- }
15700
-
15701
- if (bboxMax[0] > max[0]) {
15702
- max[0] = bboxMax[0];
15703
- }
15704
- if (bboxMax[1] > max[1]) {
15705
- max[1] = bboxMax[1];
15706
- }
15707
- if (bboxMax[2] > max[2]) {
15708
- max[2] = bboxMax[2];
15709
- }
15710
- }
15711
- return { min, max };
15712
- }
15713
-
15714
- _createSkins(skins) {
15715
- if (!skins) {
15716
- return;
15717
- }
15718
- this._skinMap = {};
15719
- for (let i = 0; i < skins.length; i++) {
15720
- const skin = skins[i];
15721
- skin.joints = skin.joints.map(j => this.gltf.nodes[j]);
15722
- this._skinMap[i] = new Skin(this.regl, skin.joints, skin.inverseBindMatrices.array);
15723
- delete skin.inverseBindMatrices;
15724
- }
15725
- }
15726
-
15727
- _createTextures(textures) {
15728
- if (!textures) {
15729
- return;
15730
- }
15731
- this._textureMap = {};
15732
- for (let i = 0; i < textures.length; i++) {
15733
- const texture = textures[i];
15734
- //避免重复创建纹理对象
15735
- if (!this._textureMap[i]) {
15736
- this._textureMap[i] = this._toTexture(texture);
15737
- //图像数据可能占有较大内存,在创建texture完成后可删除
15738
- delete texture.image;
15739
- }
15740
- }
15741
- }
15742
-
15743
- //所有baseColorFactor的alpha为0时,设置为1
15744
- _checkBaseColorFactor() {
15745
- if (!this._checkBaseColorFactorAlpha()) {
15746
- for (let i = 0; i < this.geometries.length; i++) {
15747
- const baseColorFactor = this.geometries[i].materialInfo['baseColorFactor'];
15748
- if (baseColorFactor && baseColorFactor[3] === 0) {
15749
- baseColorFactor[3] = 1;
15750
- }
15751
- }
15752
- }
15753
- }
15754
-
15755
- _checkBaseColorFactorAlpha() {
15756
- for (let i = 0; i < this.geometries.length; i++) {
15757
- const baseColorFactor = this.geometries[i].materialInfo['baseColorFactor'];
15758
- if (baseColorFactor && baseColorFactor[3] > 0) {
15759
- return true;
15760
- }
15761
- }
15762
- return false;
15763
- }
15764
-
15765
- dispose() {
15766
- if (this._emptyTexture) {
15767
- this._emptyTexture.destroy();
15768
- }
15769
- const geometries = this.getMeshesInfo();
15770
- if (!geometries) {
15771
- return;
15772
- }
15773
- geometries.forEach(g => {
15774
- g.geometry.dispose();
15775
- for (const m in g.materialInfo) {
15776
- const materialInfo = g.materialInfo[m];
15777
- //如果是texture对象,需要销毁,如果已经销毁过,不能再重复销毁
15778
- if (materialInfo && materialInfo.destroy && !materialInfo[KEY_DISPOSED]) {
15779
- materialInfo.destroy();
15780
- }
15781
- }
15782
- });
15783
- for (const index in this._textureMap) {
15784
- const tex = this._textureMap[index];
15785
- if (tex && tex.destroy && !tex[KEY_DISPOSED]) {
15786
- tex.destroy();
15787
- }
15788
- }
15789
- delete this.gltf;
15790
- }
15791
-
15792
- updateAnimation(time, loop, speed, animationName, startTime, nodeMatrixMap, skinMap, animationNodes) {
15793
- const json = this.gltf;
15794
- if (!json) {
15795
- return;
15796
- }
15797
- const gltf = getGLTFLoaderBundle();
15798
- timespan = json.animations ? gltf.GLTFLoader.getAnimationTimeSpan(json, animationName) : null;
15799
- //模型切换过快,会导致上一个模型有动画执行,当前模型没有动画数据,就出现timespan为null的情况
15800
- if (!timespan) {
15801
- return;
15802
- }
15803
- time = time - startTime;
15804
- let animTime = 0;
15805
- if (loop || (!loop && this._isFirstLoop(time, speed, animationName, startTime))) {
15806
- animTime = (time * speed * 0.001) % (timespan.max - timespan.min) + timespan.min;
15807
- } else {
15808
- animTime = time * speed * 0.001 + timespan.min;
15809
- }
15810
- json.scenes[0].nodes.forEach(node => {
15811
- this._updateNodeMatrix(animationName, animTime, node, null, nodeMatrixMap, animationNodes);
15812
- });
15813
- for (const index in this.gltf.nodes) {
15814
- const node = this.gltf.nodes[index];
15815
- const nodeMatrix = nodeMatrixMap[node.nodeIndex];
15816
- if (node.skin && nodeMatrix) {
15817
- const jointTexture = node.skin.update(nodeMatrix, nodeMatrixMap, skinMap[node.nodeIndex] && skinMap[node.nodeIndex].jointTexture);
15818
- if (!skinMap[node.nodeIndex]) {
15819
- skinMap[node.nodeIndex] = {
15820
- jointTextureSize: node.skin.jointTextureSize,
15821
- numJoints: node.skin.joints.length
15822
- };
15823
- }
15824
- skinMap[node.nodeIndex].jointTexture = jointTexture;
15825
- }
15826
- }
15827
- return;
15828
- }
15829
-
15830
- _isFirstLoop(time, speed, animationName, startTime) {
15831
- const json = this.gltf;
15832
- if (!startTime || !json) {
15833
- return true;
15834
- }
15835
- const gltf = getGLTFLoaderBundle();
15836
- timespan = json.animations ? gltf.GLTFLoader.getAnimationTimeSpan(json, animationName) : null;
15837
- return (time* speed * 0.001) / (timespan.max - timespan.min) < 1;
15838
- }
15839
-
15840
- hasSkinAnimation() {
15841
- return !!this._isAnimation;
15842
- }
15843
-
15844
- _updateNodeMatrix(animationName, time, node, parentNodeMatrix, nodeMatrixMap, animationNodes) {
15845
- const trs = node.trs;
15846
- if (trs) {
15847
- if (!animationNodes) {
15848
- this._updateNodeTRS(node, time, animationName);
15849
- } else if (animationNodes.indexOf(Number(node.nodeIndex)) > -1) {
15850
- this._updateNodeTRS(node, time, animationName);
15851
- }
15852
- }
15853
- if (parentNodeMatrix) {
15854
- nodeMatrixMap[node.nodeIndex] = mat4.multiply(nodeMatrixMap[node.nodeIndex] || [], parentNodeMatrix, node.matrix || node.trs.getMatrix());
15855
- } else {
15856
- nodeMatrixMap[node.nodeIndex] = mat4.copy(nodeMatrixMap[node.nodeIndex] || [], node.matrix || node.trs.getMatrix());
15857
- }
15858
- if (node.children) {
15859
- node.children.forEach(child => {
15860
- this._updateNodeMatrix(animationName, time, child, nodeMatrixMap[node.nodeIndex], nodeMatrixMap, animationNodes);
15861
- });
15862
- }
15863
- }
15864
-
15865
- _updateNodeTRS(node, time, animationName) {
15866
- const gltf = getGLTFLoaderBundle();
15867
- const animation = gltf.GLTFLoader.getAnimationClip(this.gltf, Number(node.nodeIndex), time, animationName);
15868
- if (animation.weights) {
15869
- this._updateMorph(node, animation.weights);
15870
- }
15871
- node.trs.update(animation);
15872
- }
15873
-
15874
- //更新morph的基本思路是,计算node下每一帧的weights,然后对weights排序,最后根据
15875
- //primitives[i].attributes.POSITION +
15876
- //weights[0] * primitives[i].targets[0].POSITION +
15877
- //weights[1] * primitives[i].targets[1].POSITION +
15878
- //weights[2] * primitives[i].targets[2].POSITION + ...
15879
- //方式去更新POSITION
15880
- //如果morphTargets数量超过8个,例如36个,由于shader中对attributes的数量有限制,每次丢到shader中的morphTargets按照gltf规范,数量为8
15881
- //需要实时计算这8个morphTarget的索引,来决定哪几个丢到shader中。
15882
- _updateMorph(node, weights) {
15883
- const length = weights.length;
15884
- if (!node.influencesList) {
15885
- node.influencesList = [];
15886
- for (let i = 0; i < length; i++) {
15887
- node.influencesList[i] = [i, 0];
15888
- }
15889
- }
15890
- const influences = node.influencesList;
15891
- for (let i = 0; i < influences.length; i++) {
15892
- const influence = influences[i];
15893
- influence[0] = i;
15894
- influence[1] = weights[i];
15895
- }
15896
- influences.sort(absNumericalSort);
15897
- const workInfluences = [];
15898
- for (let i = 0; i < 8; i++) {
15899
- workInfluences[i] = [i, 0];
15900
- }
15901
- for (let i = 0; i < 8; i++) {
15902
- if (i < length && influences[i][1]) {
15903
- workInfluences[i][0] = influences[i][0];
15904
- workInfluences[i][1] = influences[i][1];
15905
- } else {
15906
- workInfluences[i][0] = Number.MAX_SAFE_INTEGER;
15907
- workInfluences[i][1] = 0;
15908
- }
15909
- }
15910
- workInfluences.sort(numericalSort);
15911
- const geometries = node.geometries;
15912
- geometries.forEach(geometry => {
15913
- const morphTargets = geometry.properties.morphTargets;
15914
- for (let ii = 0; ii < 8; ii++) {
15915
- const influence = workInfluences[ii];
15916
- const index = influence[0];
15917
- const value = influence[1];
15918
- if (index !== Number.MAX_SAFE_INTEGER && value) {
15919
- geometry.updateData('POSITION' + ii, morphTargets['POSITION_' + index].array);
15920
- geometry.properties.morphWeights[ii] = value;
15921
- } else {
15922
- geometry.properties.morphWeights[ii] = 0;
15923
- }
15924
- }
15925
- });
15926
- }
15927
-
15928
-
15929
- _parserNode(node, geometries, parentNodeMatrix) {
15930
- if (node.isParsed) {
15931
- return;
15932
- }
15933
- node.nodeMatrix = node.nodeMatrix || mat4.identity([]);
15934
- node.localMatrix = node.localMatrix || mat4.identity([]);
15935
- if (node.matrix) {
15936
- node.trs = new TRS();
15937
- node.trs.decompose(node.matrix);
15938
- } else {
15939
- node.trs = new TRS(node.translation, node.rotation, node.scale);
15940
- }
15941
- node.localMatrix = node.trs.getMatrix();
15942
- if (parentNodeMatrix) {
15943
- mat4.multiply(node.nodeMatrix, parentNodeMatrix, node.matrix || node.localMatrix);
15944
- } else {
15945
- mat4.copy(node.nodeMatrix, node.matrix || node.localMatrix);
15946
- }
15947
- const nodeMatrix = node.nodeMatrix;
15948
- if (node.children) {
15949
- for (let i = 0; i < node.children.length; i++) {
15950
- const child = node.children[i];
15951
- this._parserNode(child, geometries, nodeMatrix);
15952
- }
15953
- }
15954
- if (defined(node.skin)) {
15955
- this._isAnimation = true;
15956
- const skin = node.skin;
15957
- node.trs = new TRS();
15958
- node.skin = this._skinMap[skin];
15959
- }
15960
-
15961
- if (defined(node.mesh)) {
15962
- const meshIndex = node.mesh;
15963
- node.mesh = this.gltf.meshes[meshIndex];
15964
- node.mesh.node = node;
15965
- node.geometries = node.geometries || [];
15966
- node.mesh.primitives.forEach(primitive => {
15967
- const materialInfo = this._createMaterialInfo(primitive.material);
15968
- const geometry = createGeometry(primitive, this.regl, materialInfo.occlusionTexture);
15969
- geometry.properties.morphTargets = primitive.morphTargets;
15970
- //一个node下可能有多个geometry, node附带的weights会影响其下辖的所有geometry的morph变形结果,这里保存
15971
- //geometries,方便后面morph的运算
15972
- node.geometries.push(geometry);
15973
- let bbox = geometry.boundingBox.copy();
15974
- bbox = bbox.transform(mat4.identity(MAT4), nodeMatrix);
15975
- const info = {
15976
- geometry,
15977
- bbox,
15978
- nodeMatrix,
15979
- materialInfo,
15980
- extraInfo: this._createExtralInfo(primitive.material),
15981
- animationMatrix : node.trs.getMatrix(),
15982
- morphWeights: node.weights,
15983
- nodeIndex: node.nodeIndex
15984
- };
15985
- if (node.skin) {
15986
- info.skin = {
15987
- jointTextureSize: [4, 6],
15988
- numJoints: node.skin.joints.length,
15989
- jointTexture: node.skin.jointTexture
15990
- };
15991
- }
15992
- const resource = new GeometryResource(info);
15993
- geometries.push(resource);
15994
- });
15995
- }
15996
- node.isParsed = true;
15997
- }
15998
-
15999
- _createMaterialInfo(materialIndex) {
16000
- const materialUniforms = {
16001
- };
16002
- if (this.gltf.materials && this.gltf.materials[materialIndex]) {
16003
- const material = this.gltf.materials[materialIndex];
16004
- const pbrMetallicRoughness = material.pbrMetallicRoughness;
16005
- if (pbrMetallicRoughness) {
16006
- const metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
16007
- const baseColorTexture = pbrMetallicRoughness.baseColorTexture;
16008
- if (baseColorTexture) {
16009
- materialUniforms['baseColorTexture'] = this._getTexture(baseColorTexture);
16010
- if (baseColorTexture['KHR_texture_transform']) {
16011
- materialUniforms['khr_offset'] = baseColorTexture['KHR_texture_transform'].offset || [0, 0];
16012
- materialUniforms['khr_rotation'] = baseColorTexture['KHR_texture_transform'].rotation ||0;
16013
- materialUniforms['khr_scale'] = baseColorTexture['KHR_texture_transform'].scale || [1, 1];
16014
- }
16015
- }
16016
- if (pbrMetallicRoughness.baseColorFactor) {
16017
- materialUniforms['baseColorFactor'] = pbrMetallicRoughness.baseColorFactor;
16018
- }
16019
- if (metallicRoughnessTexture) {
16020
- materialUniforms['metallicRoughnessTexture'] = this._getTexture(metallicRoughnessTexture);
16021
- } else {
16022
- materialUniforms['metallicFactor'] = defined(pbrMetallicRoughness.metallicFactor) ? pbrMetallicRoughness.metallicFactor : 1.0;
16023
- materialUniforms['roughnessFactor'] = defined(pbrMetallicRoughness.roughnessFactor) ? pbrMetallicRoughness.roughnessFactor : 1.0;
16024
- }
16025
- }
16026
- const extensions = material.extensions;
16027
- if (extensions && extensions['KHR_materials_pbrSpecularGlossiness']) {
16028
- const pbrSpecularGlossiness = extensions['KHR_materials_pbrSpecularGlossiness'];
16029
- materialUniforms.name = 'pbrSpecularGlossiness';
16030
- for (const p in pbrSpecularGlossiness) {
16031
- if (defined(pbrSpecularGlossiness[p].index)) {
16032
- materialUniforms[p] = this._getTexture(pbrSpecularGlossiness[p]);
16033
- } else {
16034
- materialUniforms[p] = pbrSpecularGlossiness[p];
16035
- }
16036
- }
16037
- }
16038
- if (material.normalTexture) {
16039
- materialUniforms['normalTexture'] = this._getTexture(material.normalTexture);
16040
- }
16041
- if (material.occlusionTexture) {
16042
- materialUniforms['occlusionTexture'] = this._getTexture(material.occlusionTexture);
16043
- }
16044
- if (material.emissiveTexture) {
16045
- materialUniforms['emissiveTexture'] = this._getTexture(material.emissiveTexture);
16046
- }
16047
- if (material.emissiveFactor) {
16048
- materialUniforms['emissiveFactor'] = material.emissiveFactor;
16049
- }
16050
- materialUniforms['alphaCutoff'] = material.alphaCutoff || 0.5;
16051
- materialUniforms['doubleSided'] = material.doubleSided;
16052
- materialUniforms['alphaMode'] = material.alphaMode || 'OPAQUE';
16053
- }
16054
- return materialUniforms;
16055
- }
16056
-
16057
- _createExtralInfo(material) {
16058
- const info = {};
16059
- if (this.gltf.materials && this.gltf.materials[material]) {
16060
- const mat = this.gltf.materials[material];
16061
- info['doubleSided'] = mat.doubleSided;
16062
- info['alphaMode'] = mat.alphaMode || 'OPAQUE';
16063
- }
16064
- return info;
16065
- }
16066
-
16067
- _getTexture(texInfo) {
16068
- const extensions = texInfo.extensions;
16069
- const index = texInfo.index;
16070
- if (!defined(index)) {
16071
- return null;
16072
- }
16073
- if (extensions && extensions['KHR_texture_transform']) {
16074
- texInfo['KHR_texture_transform'] = extensions['KHR_texture_transform'];
16075
- }
16076
- const texture = this._textureMap[index];
16077
- texture.texInfo = texInfo;
16078
- return texture;
16079
- }
16080
-
16081
- _toTexture(texture) {
16082
- if (!texture) {
16083
- // empty texture
16084
- return this._emptyTexture;
16085
- }
16086
- const data = texture.image.array;
16087
- const sampler = texture.sampler || {};
16088
- const width = texture.image.width;
16089
- const height = texture.image.height;
16090
- return new Texture2D({
16091
- width,
16092
- height,
16093
- data,
16094
- mag: getTextureMagFilter(sampler.magFilter) || 'linear',
16095
- min: getTextureMinFilter(sampler.minFilter) || 'linear mipmap linear',
16096
- wrapS: getTextureWrap(sampler.wrapS) || 'repeat',
16097
- wrapT: getTextureWrap(sampler.wrapT) || 'repeat'
16098
- });
16099
- }
16100
-
16101
- /**
16102
- *
16103
- * @param map
16104
- * @param from
16105
- * @param to
16106
- * @param dist
16107
- * @param rotationZ 模型绕Z轴旋转角度,弧度
16108
- * @param rotationXY 模型绕Z轴与线段的交叉轴的旋转角度,弧度
16109
- * @param gltfScale
16110
- * @param projectionScale
16111
- * @param options
16112
- * @returns
16113
- */
16114
- arrangeAlongLine(from, to, xyDist, gltfScale, projectionScale, options) {
16115
- const items = [];
16116
- const rotationZ = this._getRotationZ(from, to);
16117
- // cm to mi
16118
- const zDist = (from.z || 0) - (to.z || 0);
16119
- const rotationXY = this._getRotationXY(xyDist, zDist);
16120
- let boxWidth = this._calBoxWidth(gltfScale, options);
16121
- boxWidth /= projectionScale;
16122
- const distance = Math.sqrt(xyDist * xyDist + zDist * zDist);
16123
- const times = Math.floor(distance / boxWidth);
16124
- let scaleIndex = (options.direction || 0);
16125
- // scale的scaleIndex已经是Y_UP后的模型,所以和direction不同
16126
- if (scaleIndex === 1) {
16127
- scaleIndex = 2;
16128
- } else if (scaleIndex === 2) {
16129
- scaleIndex = 1;
16130
- }
16131
- //取余缩放
16132
- if (times >= 1) {
16133
- for (let i = 1; i <= times; i++) {
16134
- const t = boxWidth * (i - 0.5) / distance;
16135
- const item = {
16136
- coordinates: interpolate(from, to, t),
16137
- t,
16138
- scale: [1, 1, 1],
16139
- rotation: [0, 0, rotationZ],
16140
- rotationZ,
16141
- rotationXY
16142
- };
16143
- items.push(item);
16144
- }
16145
- //尾巴
16146
- if (options['scaleVertex']) {
16147
- const t = (boxWidth * times + (distance - boxWidth * times) / 2) / distance;
16148
- const scale = (distance - boxWidth * times) / boxWidth;
16149
- const itemScale = [1, 1, 1];
16150
- itemScale[scaleIndex] = scale;
16151
- const item = {
16152
- coordinates: interpolate(from, to, t),
16153
- t,
16154
- scale: itemScale,
16155
- rotation: [0, 0, rotationZ],
16156
- rotationZ,
16157
- rotationXY
16158
- };
16159
- items.push(item);
16160
- }
16161
- } else if (options['scaleVertex']) {
16162
- const scale = distance / boxWidth;
16163
- const itemScale = [1, 1, 1];
16164
- itemScale[scaleIndex] = scale;
16165
- const item = {
16166
- coordinates: interpolate(from, to, 0.5),
16167
- t: 0.5,
16168
- scale: itemScale,
16169
- rotation: [0, 0, rotationZ],
16170
- rotationZ,
16171
- rotationXY
16172
- };
16173
- items.push(item);
16174
- }
16175
- return items;
16176
- }
16177
-
16178
- calModelHeightScale(out, modelHeight) {
16179
- const bbox = this.getGLTFBBox();
16180
- const fitScale = modelHeight / (Math.abs(bbox.max[1] - bbox.min[1]));//YZ轴做了翻转,所以需要用y方向来算高度比例
16181
- return vec3.set(out, fitScale, fitScale, fitScale);
16182
- }
16183
-
16184
- _calBoxWidth(scale, options) {
16185
- const gltfmodelBBox = this.getGLTFBBox();
16186
- const direction = options.direction || 0;
16187
- const boxExtent = vec3.sub(TEMP_VEC$1, gltfmodelBBox.max, gltfmodelBBox.min);
16188
- vec3.multiply(boxExtent, boxExtent, scale);
16189
- const gapLength = options['gapLength'];
16190
- return boxExtent[direction] + gapLength;
16191
- }
16192
-
16193
- _getRotationZ(from, to) {
16194
- const degree = computeDegree(
16195
- to.x, to.y,
16196
- from.x, from.y
16197
- );
16198
- return degree / Math.PI * 180;
16199
- }
16200
-
16201
- _getRotationXY(xyDist, zDist) {
16202
- const rotation = Math.atan(zDist / xyDist) * 180 / Math.PI;
16203
- return rotation;
16204
- }
16205
- }
16206
-
16207
- function createGeometry(primitive, regl, hasAOMap) {
16208
- const attributes = primitive.attributes;
16209
- const aColor0 = attributes['COLOR_0'];
16210
- //将float类型的颜色值转为0-255的uint8类型
16211
- if (aColor0 && aColor0.array instanceof Float32Array) {
16212
- const color = new Uint8Array(aColor0.array.length);
16213
- for (let i = 0; i < color.length; i++) {
16214
- color[i] = Math.round(aColor0.array[i] * 255);
16215
- }
16216
- aColor0.array = color;
16217
- } else if (aColor0 && (aColor0.array instanceof Uint16Array ||
16218
- aColor0.array instanceof Int16Array ||
16219
- aColor0.array instanceof Uint32Array ||
16220
- aColor0.array instanceof Int32Array)) {
16221
- const color = new Uint8Array(aColor0.array);
16222
- aColor0.array = color;
16223
- }
16224
- if (hasAOMap && attributes['TEXCOORD_0'] && !attributes['TEXCOORD_0']) {
16225
- attributes['TEXCOORD_1'] = attributes['TEXCOORD_0'];
16226
- }
16227
- const attrs = {};
16228
- for (const name in attributes) {
16229
- // 把原有的array赋给attr,用于计算 bbox、buildUniqueVertex
16230
- attrs[name] = extend$1({}, attributes[name]);
16231
- if (regl) {
16232
- attrs[name].buffer = getUniqueREGLBuffer(regl, attributes[name], { dimension: attributes[name].itemSize });
16233
- }
16234
- }
16235
-
16236
- //如果有morph,需要预先填充morph空数据,动画开启后,会不断向这些空数据中填充morphTargets数据
16237
- if (primitive.morphTargets) {
16238
- const length = isInterleaved(attrs['POSITION']) ? attrs['POSITION'].itemSize * attrs['POSITION'].count : attrs['POSITION'].array.length;
16239
- for (let i = 0; i < 8; i++) {
16240
- if (!attrs[`POSITION${i}`]) {
16241
- attrs[`POSITION${i}`] = new Float32Array(length).fill(0);
16242
- }
16243
- }
16244
- for (let i = 0; i < 4; i++) {
16245
- const length = attrs['NORMAL'].array ? attrs['NORMAL'].array.length : attrs['NORMAL'].length;
16246
- if (!attrs[`NORMAL${i}`]) {
16247
- attrs[`NORMAL${i}`] = new Float32Array(length).fill(0);
16248
- }
16249
- }
16250
- }
16251
- let indices = primitive.indices;
16252
- if (indices && indices.bufferView === undefined && indices.array) {
16253
- indices = indices.array;
16254
- }
16255
- const modelGeometry = new Geometry(
16256
- attrs,
16257
- indices,
16258
- 0,
16259
- {
16260
- //绘制类型,例如 triangle strip, line等,根据gltf中primitive的mode来判断,默认是triangles
16261
- primitive : isNumber$2(primitive.mode) ? getPrimitive(primitive.mode) : primitive.mode,
16262
- positionAttribute: 'POSITION',
16263
- normalAttribute: 'NORMAL',
16264
- uv0Attribute: 'TEXCOORD_0',
16265
- uv1Attribute: 'TEXCOORD_1',
16266
- color0Attribute: 'COLOR_0'
16267
- }
16268
- );
16269
- if (primitive.morphTargets) {
16270
- modelGeometry.properties.morphWeights = [];
16271
- }
16272
- if (primitive.mode > 3 && !modelGeometry.data['NORMAL']) {
16273
- modelGeometry.createNormal('NORMAL');
16274
- }
16275
- return modelGeometry;
16276
- }
16277
-
16278
- function numericalSort(a, b) {
16279
- return a[ 0 ] - b[ 0 ];
16280
- }
16281
-
16282
- function absNumericalSort(a, b) {
16283
- return Math.abs(b[1]) - Math.abs(a[1]);
16284
- }
16285
-
16286
- function computeDegree(x0, y0, x1, y1) {
16287
- const dx = x1 - x0;
16288
- const dy = y1 - y0;
16289
- return Math.atan2(dy, dx);
16290
- }
16291
-
16292
- function interpolate(from, to, t) {
16293
- const x = lerp(from.x, to.x, t);
16294
- const y = lerp(from.y, to.y, t);
16295
- const z1 = from.z || 0;
16296
- const z2 = to.z || 0;
16297
- const z = lerp(z1, z2, t);
16298
- return new from.constructor(x, y, z);
16299
- }
16300
-
16301
- function lerp(a, b, t) {
16302
- return a + t * (b - a);
15727
+ const Y_TO_Z = [1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1];
15728
+
15729
+ let timespan = 0;
15730
+
15731
+ const MAT4 = [];
15732
+ const TEMP_VEC$1 = [];
15733
+
15734
+ class GLTFPack {
15735
+
15736
+ constructor(gltf, regl) {
15737
+ this.gltf = gltf;
15738
+ this.regl = regl;
15739
+ this.geometries = [];
15740
+ if (regl) {
15741
+ this._emptyTexture = regl.texture({ width: 2, height: 2 });
15742
+ }
15743
+ }
15744
+
15745
+ getMeshesInfo() {
15746
+ if (!this.gltf) {
15747
+ return null;
15748
+ }
15749
+ if (this.geometries.length) {
15750
+ return this.geometries;
15751
+ }
15752
+ this._createTextures(this.gltf.textures);
15753
+ this._createSkins(this.gltf.skins);
15754
+ const nodes = this.gltf.scenes[0].nodes;
15755
+ nodes.forEach((node) => {
15756
+ this._parserNode(node, this.geometries);
15757
+ });
15758
+ this._checkBaseColorFactor();
15759
+ return this.geometries;
15760
+ }
15761
+
15762
+ getGLTFBBox(transform) {
15763
+ if (!this.gltf) {
15764
+ return null;
15765
+ }
15766
+ const geometries = this.geometries;
15767
+ if (!geometries || !geometries.length) {
15768
+ return null;
15769
+ }
15770
+ const min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];
15771
+ for (let i = 0; i < geometries.length; i++) {
15772
+ const bbox = geometries[i].bbox;
15773
+ const bboxMin = bbox.min, bboxMax = bbox.max;
15774
+ if (bboxMin[0] < min[0]) {
15775
+ min[0] = bboxMin[0];
15776
+ }
15777
+ if (bboxMin[1] < min[1]) {
15778
+ min[1] = bboxMin[1];
15779
+ }
15780
+ if (bboxMin[2] < min[2]) {
15781
+ min[2] = bboxMin[2];
15782
+ }
15783
+
15784
+ if (bboxMax[0] > max[0]) {
15785
+ max[0] = bboxMax[0];
15786
+ }
15787
+ if (bboxMax[1] > max[1]) {
15788
+ max[1] = bboxMax[1];
15789
+ }
15790
+ if (bboxMax[2] > max[2]) {
15791
+ max[2] = bboxMax[2];
15792
+ }
15793
+ }
15794
+ const bbox = new BoundingBox(min, max);
15795
+ if (transform) {
15796
+ bbox.transform(transform);
15797
+ }
15798
+
15799
+ return bbox;
15800
+ }
15801
+
15802
+ _createSkins(skins) {
15803
+ if (!skins) {
15804
+ return;
15805
+ }
15806
+ this._skinMap = {};
15807
+ for (let i = 0; i < skins.length; i++) {
15808
+ const skin = skins[i];
15809
+ skin.joints = skin.joints.map(j => this.gltf.nodes[j]);
15810
+ this._skinMap[i] = new Skin(this.regl, skin.joints, skin.inverseBindMatrices.array);
15811
+ delete skin.inverseBindMatrices;
15812
+ }
15813
+ }
15814
+
15815
+ _createTextures(textures) {
15816
+ if (!textures) {
15817
+ return;
15818
+ }
15819
+ this._textureMap = {};
15820
+ for (let i = 0; i < textures.length; i++) {
15821
+ const texture = textures[i];
15822
+ //避免重复创建纹理对象
15823
+ if (!this._textureMap[i]) {
15824
+ this._textureMap[i] = this._toTexture(texture);
15825
+ //图像数据可能占有较大内存,在创建texture完成后可删除
15826
+ delete texture.image;
15827
+ }
15828
+ }
15829
+ }
15830
+
15831
+ //所有baseColorFactor的alpha为0时,设置为1
15832
+ _checkBaseColorFactor() {
15833
+ if (!this._checkBaseColorFactorAlpha()) {
15834
+ for (let i = 0; i < this.geometries.length; i++) {
15835
+ const baseColorFactor = this.geometries[i].materialInfo['baseColorFactor'];
15836
+ if (baseColorFactor && baseColorFactor[3] === 0) {
15837
+ baseColorFactor[3] = 1;
15838
+ }
15839
+ }
15840
+ }
15841
+ }
15842
+
15843
+ _checkBaseColorFactorAlpha() {
15844
+ for (let i = 0; i < this.geometries.length; i++) {
15845
+ const baseColorFactor = this.geometries[i].materialInfo['baseColorFactor'];
15846
+ if (baseColorFactor && baseColorFactor[3] > 0) {
15847
+ return true;
15848
+ }
15849
+ }
15850
+ return false;
15851
+ }
15852
+
15853
+ dispose() {
15854
+ if (this._emptyTexture) {
15855
+ this._emptyTexture.destroy();
15856
+ }
15857
+ const geometries = this.getMeshesInfo();
15858
+ if (!geometries) {
15859
+ return;
15860
+ }
15861
+ geometries.forEach(g => {
15862
+ g.geometry.dispose();
15863
+ for (const m in g.materialInfo) {
15864
+ const materialInfo = g.materialInfo[m];
15865
+ //如果是texture对象,需要销毁,如果已经销毁过,不能再重复销毁
15866
+ if (materialInfo && materialInfo.destroy && !materialInfo[KEY_DISPOSED]) {
15867
+ materialInfo.destroy();
15868
+ }
15869
+ }
15870
+ });
15871
+ for (const index in this._textureMap) {
15872
+ const tex = this._textureMap[index];
15873
+ if (tex && tex.destroy && !tex[KEY_DISPOSED]) {
15874
+ tex.destroy();
15875
+ }
15876
+ }
15877
+ delete this.gltf;
15878
+ }
15879
+
15880
+ updateAnimation(time, loop, speed, animationName, startTime, nodeMatrixMap, skinMap, animationNodes) {
15881
+ const json = this.gltf;
15882
+ if (!json) {
15883
+ return;
15884
+ }
15885
+ const gltf = getGLTFLoaderBundle();
15886
+ timespan = json.animations ? gltf.GLTFLoader.getAnimationTimeSpan(json, animationName) : null;
15887
+ //模型切换过快,会导致上一个模型有动画执行,当前模型没有动画数据,就出现timespan为null的情况
15888
+ if (!timespan) {
15889
+ return;
15890
+ }
15891
+ time = time - startTime;
15892
+ let animTime = 0;
15893
+ if (loop || (!loop && this._isFirstLoop(time, speed, animationName, startTime))) {
15894
+ animTime = (time * speed * 0.001) % (timespan.max - timespan.min) + timespan.min;
15895
+ } else {
15896
+ animTime = time * speed * 0.001 + timespan.min;
15897
+ }
15898
+ json.scenes[0].nodes.forEach(node => {
15899
+ this._updateNodeMatrix(animationName, animTime, node, null, nodeMatrixMap, animationNodes);
15900
+ });
15901
+ for (const index in this.gltf.nodes) {
15902
+ const node = this.gltf.nodes[index];
15903
+ const nodeMatrix = nodeMatrixMap[node.nodeIndex];
15904
+ if (node.skin && nodeMatrix) {
15905
+ const jointTexture = node.skin.update(nodeMatrix, nodeMatrixMap, skinMap[node.nodeIndex] && skinMap[node.nodeIndex].jointTexture);
15906
+ if (!skinMap[node.nodeIndex]) {
15907
+ skinMap[node.nodeIndex] = {
15908
+ jointTextureSize: node.skin.jointTextureSize,
15909
+ numJoints: node.skin.joints.length
15910
+ };
15911
+ }
15912
+ skinMap[node.nodeIndex].jointTexture = jointTexture;
15913
+ }
15914
+ }
15915
+ return;
15916
+ }
15917
+
15918
+ _isFirstLoop(time, speed, animationName, startTime) {
15919
+ const json = this.gltf;
15920
+ if (!startTime || !json) {
15921
+ return true;
15922
+ }
15923
+ const gltf = getGLTFLoaderBundle();
15924
+ timespan = json.animations ? gltf.GLTFLoader.getAnimationTimeSpan(json, animationName) : null;
15925
+ return (time* speed * 0.001) / (timespan.max - timespan.min) < 1;
15926
+ }
15927
+
15928
+ hasSkinAnimation() {
15929
+ return !!this._isAnimation;
15930
+ }
15931
+
15932
+ _updateNodeMatrix(animationName, time, node, parentNodeMatrix, nodeMatrixMap, animationNodes) {
15933
+ const trs = node.trs;
15934
+ if (trs) {
15935
+ if (!animationNodes) {
15936
+ this._updateNodeTRS(node, time, animationName);
15937
+ } else if (animationNodes.indexOf(Number(node.nodeIndex)) > -1) {
15938
+ this._updateNodeTRS(node, time, animationName);
15939
+ }
15940
+ }
15941
+ if (parentNodeMatrix) {
15942
+ nodeMatrixMap[node.nodeIndex] = mat4.multiply(nodeMatrixMap[node.nodeIndex] || [], parentNodeMatrix, node.matrix || node.trs.getMatrix());
15943
+ } else {
15944
+ nodeMatrixMap[node.nodeIndex] = mat4.copy(nodeMatrixMap[node.nodeIndex] || [], node.matrix || node.trs.getMatrix());
15945
+ }
15946
+ if (node.children) {
15947
+ node.children.forEach(child => {
15948
+ this._updateNodeMatrix(animationName, time, child, nodeMatrixMap[node.nodeIndex], nodeMatrixMap, animationNodes);
15949
+ });
15950
+ }
15951
+ }
15952
+
15953
+ _updateNodeTRS(node, time, animationName) {
15954
+ const gltf = getGLTFLoaderBundle();
15955
+ const animation = gltf.GLTFLoader.getAnimationClip(this.gltf, Number(node.nodeIndex), time, animationName);
15956
+ if (animation.weights) {
15957
+ this._updateMorph(node, animation.weights);
15958
+ }
15959
+ node.trs.update(animation);
15960
+ }
15961
+
15962
+ //更新morph的基本思路是,计算node下每一帧的weights,然后对weights排序,最后根据
15963
+ //primitives[i].attributes.POSITION +
15964
+ //weights[0] * primitives[i].targets[0].POSITION +
15965
+ //weights[1] * primitives[i].targets[1].POSITION +
15966
+ //weights[2] * primitives[i].targets[2].POSITION + ...
15967
+ //方式去更新POSITION
15968
+ //如果morphTargets数量超过8个,例如36个,由于shader中对attributes的数量有限制,每次丢到shader中的morphTargets按照gltf规范,数量为8
15969
+ //需要实时计算这8个morphTarget的索引,来决定哪几个丢到shader中。
15970
+ _updateMorph(node, weights) {
15971
+ const length = weights.length;
15972
+ if (!node.influencesList) {
15973
+ node.influencesList = [];
15974
+ for (let i = 0; i < length; i++) {
15975
+ node.influencesList[i] = [i, 0];
15976
+ }
15977
+ }
15978
+ const influences = node.influencesList;
15979
+ for (let i = 0; i < influences.length; i++) {
15980
+ const influence = influences[i];
15981
+ influence[0] = i;
15982
+ influence[1] = weights[i];
15983
+ }
15984
+ influences.sort(absNumericalSort);
15985
+ const workInfluences = [];
15986
+ for (let i = 0; i < 8; i++) {
15987
+ workInfluences[i] = [i, 0];
15988
+ }
15989
+ for (let i = 0; i < 8; i++) {
15990
+ if (i < length && influences[i][1]) {
15991
+ workInfluences[i][0] = influences[i][0];
15992
+ workInfluences[i][1] = influences[i][1];
15993
+ } else {
15994
+ workInfluences[i][0] = Number.MAX_SAFE_INTEGER;
15995
+ workInfluences[i][1] = 0;
15996
+ }
15997
+ }
15998
+ workInfluences.sort(numericalSort);
15999
+ const geometries = node.geometries;
16000
+ geometries.forEach(geometry => {
16001
+ const morphTargets = geometry.properties.morphTargets;
16002
+ for (let ii = 0; ii < 8; ii++) {
16003
+ const influence = workInfluences[ii];
16004
+ const index = influence[0];
16005
+ const value = influence[1];
16006
+ if (index !== Number.MAX_SAFE_INTEGER && value) {
16007
+ geometry.updateData('POSITION' + ii, morphTargets['POSITION_' + index].array);
16008
+ geometry.properties.morphWeights[ii] = value;
16009
+ } else {
16010
+ geometry.properties.morphWeights[ii] = 0;
16011
+ }
16012
+ }
16013
+ });
16014
+ }
16015
+
16016
+
16017
+ _parserNode(node, geometries, parentNodeMatrix) {
16018
+ if (node.isParsed) {
16019
+ return;
16020
+ }
16021
+ node.nodeMatrix = node.nodeMatrix || mat4.identity([]);
16022
+ node.localMatrix = node.localMatrix || mat4.identity([]);
16023
+ if (node.matrix) {
16024
+ node.trs = new TRS();
16025
+ node.trs.decompose(node.matrix);
16026
+ } else {
16027
+ node.trs = new TRS(node.translation, node.rotation, node.scale);
16028
+ }
16029
+ node.localMatrix = node.trs.getMatrix();
16030
+ if (parentNodeMatrix) {
16031
+ mat4.multiply(node.nodeMatrix, parentNodeMatrix, node.matrix || node.localMatrix);
16032
+ } else {
16033
+ mat4.copy(node.nodeMatrix, node.matrix || node.localMatrix);
16034
+ }
16035
+ const nodeMatrix = node.nodeMatrix;
16036
+ if (node.children) {
16037
+ for (let i = 0; i < node.children.length; i++) {
16038
+ const child = node.children[i];
16039
+ this._parserNode(child, geometries, nodeMatrix);
16040
+ }
16041
+ }
16042
+ if (defined(node.skin)) {
16043
+ this._isAnimation = true;
16044
+ const skin = node.skin;
16045
+ node.trs = new TRS();
16046
+ node.skin = this._skinMap[skin];
16047
+ }
16048
+
16049
+ if (defined(node.mesh)) {
16050
+ const meshIndex = node.mesh;
16051
+ node.mesh = this.gltf.meshes[meshIndex];
16052
+ node.mesh.node = node;
16053
+ node.geometries = node.geometries || [];
16054
+ node.mesh.primitives.forEach(primitive => {
16055
+ const materialInfo = this._createMaterialInfo(primitive.material);
16056
+ const geometry = createGeometry(primitive, this.regl, materialInfo.occlusionTexture);
16057
+ geometry.properties.morphTargets = primitive.morphTargets;
16058
+ //一个node下可能有多个geometry, node附带的weights会影响其下辖的所有geometry的morph变形结果,这里保存
16059
+ //geometries,方便后面morph的运算
16060
+ node.geometries.push(geometry);
16061
+ let bbox = geometry.boundingBox.copy();
16062
+ bbox = bbox.transform(mat4.identity(MAT4), nodeMatrix);
16063
+ const info = {
16064
+ geometry,
16065
+ bbox,
16066
+ nodeMatrix,
16067
+ materialInfo,
16068
+ extraInfo: this._createExtralInfo(primitive.material),
16069
+ animationMatrix : node.trs.getMatrix(),
16070
+ morphWeights: node.weights,
16071
+ nodeIndex: node.nodeIndex
16072
+ };
16073
+ if (node.skin) {
16074
+ info.skin = {
16075
+ jointTextureSize: [4, 6],
16076
+ numJoints: node.skin.joints.length,
16077
+ jointTexture: node.skin.jointTexture
16078
+ };
16079
+ }
16080
+ const resource = new GeometryResource(info);
16081
+ geometries.push(resource);
16082
+ });
16083
+ }
16084
+ node.isParsed = true;
16085
+ }
16086
+
16087
+ _createMaterialInfo(materialIndex) {
16088
+ const materialUniforms = {
16089
+ };
16090
+ if (this.gltf.materials && this.gltf.materials[materialIndex]) {
16091
+ const material = this.gltf.materials[materialIndex];
16092
+ const pbrMetallicRoughness = material.pbrMetallicRoughness;
16093
+ if (pbrMetallicRoughness) {
16094
+ const metallicRoughnessTexture = pbrMetallicRoughness.metallicRoughnessTexture;
16095
+ const baseColorTexture = pbrMetallicRoughness.baseColorTexture;
16096
+ if (baseColorTexture) {
16097
+ materialUniforms['baseColorTexture'] = this._getTexture(baseColorTexture);
16098
+ if (baseColorTexture['KHR_texture_transform']) {
16099
+ materialUniforms['khr_offset'] = baseColorTexture['KHR_texture_transform'].offset || [0, 0];
16100
+ materialUniforms['khr_rotation'] = baseColorTexture['KHR_texture_transform'].rotation ||0;
16101
+ materialUniforms['khr_scale'] = baseColorTexture['KHR_texture_transform'].scale || [1, 1];
16102
+ }
16103
+ }
16104
+ if (pbrMetallicRoughness.baseColorFactor) {
16105
+ materialUniforms['baseColorFactor'] = pbrMetallicRoughness.baseColorFactor;
16106
+ }
16107
+ if (metallicRoughnessTexture) {
16108
+ materialUniforms['metallicRoughnessTexture'] = this._getTexture(metallicRoughnessTexture);
16109
+ } else {
16110
+ materialUniforms['metallicFactor'] = defined(pbrMetallicRoughness.metallicFactor) ? pbrMetallicRoughness.metallicFactor : 1.0;
16111
+ materialUniforms['roughnessFactor'] = defined(pbrMetallicRoughness.roughnessFactor) ? pbrMetallicRoughness.roughnessFactor : 1.0;
16112
+ }
16113
+ }
16114
+ const extensions = material.extensions;
16115
+ if (extensions && extensions['KHR_materials_pbrSpecularGlossiness']) {
16116
+ const pbrSpecularGlossiness = extensions['KHR_materials_pbrSpecularGlossiness'];
16117
+ materialUniforms.name = 'pbrSpecularGlossiness';
16118
+ for (const p in pbrSpecularGlossiness) {
16119
+ if (defined(pbrSpecularGlossiness[p].index)) {
16120
+ materialUniforms[p] = this._getTexture(pbrSpecularGlossiness[p]);
16121
+ } else {
16122
+ materialUniforms[p] = pbrSpecularGlossiness[p];
16123
+ }
16124
+ }
16125
+ }
16126
+ if (material.normalTexture) {
16127
+ materialUniforms['normalTexture'] = this._getTexture(material.normalTexture);
16128
+ }
16129
+ if (material.occlusionTexture) {
16130
+ materialUniforms['occlusionTexture'] = this._getTexture(material.occlusionTexture);
16131
+ }
16132
+ if (material.emissiveTexture) {
16133
+ materialUniforms['emissiveTexture'] = this._getTexture(material.emissiveTexture);
16134
+ }
16135
+ if (material.emissiveFactor) {
16136
+ materialUniforms['emissiveFactor'] = material.emissiveFactor;
16137
+ }
16138
+ materialUniforms['alphaCutoff'] = material.alphaCutoff || 0.5;
16139
+ materialUniforms['doubleSided'] = material.doubleSided;
16140
+ materialUniforms['alphaMode'] = material.alphaMode || 'OPAQUE';
16141
+ }
16142
+ return materialUniforms;
16143
+ }
16144
+
16145
+ _createExtralInfo(material) {
16146
+ const info = {};
16147
+ if (this.gltf.materials && this.gltf.materials[material]) {
16148
+ const mat = this.gltf.materials[material];
16149
+ info['doubleSided'] = mat.doubleSided;
16150
+ info['alphaMode'] = mat.alphaMode || 'OPAQUE';
16151
+ }
16152
+ return info;
16153
+ }
16154
+
16155
+ _getTexture(texInfo) {
16156
+ const extensions = texInfo.extensions;
16157
+ const index = texInfo.index;
16158
+ if (!defined(index)) {
16159
+ return null;
16160
+ }
16161
+ if (extensions && extensions['KHR_texture_transform']) {
16162
+ texInfo['KHR_texture_transform'] = extensions['KHR_texture_transform'];
16163
+ }
16164
+ const texture = this._textureMap[index];
16165
+ texture.texInfo = texInfo;
16166
+ return texture;
16167
+ }
16168
+
16169
+ _toTexture(texture) {
16170
+ if (!texture) {
16171
+ // empty texture
16172
+ return this._emptyTexture;
16173
+ }
16174
+ const data = texture.image.array;
16175
+ const sampler = texture.sampler || {};
16176
+ const width = texture.image.width;
16177
+ const height = texture.image.height;
16178
+ return new Texture2D({
16179
+ width,
16180
+ height,
16181
+ data,
16182
+ mag: getTextureMagFilter(sampler.magFilter) || 'linear',
16183
+ min: getTextureMinFilter(sampler.minFilter) || 'linear mipmap linear',
16184
+ wrapS: getTextureWrap(sampler.wrapS) || 'repeat',
16185
+ wrapT: getTextureWrap(sampler.wrapT) || 'repeat'
16186
+ });
16187
+ }
16188
+
16189
+ /**
16190
+ *
16191
+ * @param map
16192
+ * @param from
16193
+ * @param to
16194
+ * @param dist
16195
+ * @param rotationZ 模型绕Z轴旋转角度,弧度
16196
+ * @param rotationXY 模型绕Z轴与线段的交叉轴的旋转角度,弧度
16197
+ * @param gltfScale
16198
+ * @param projectionScale
16199
+ * @param options
16200
+ * @returns
16201
+ */
16202
+ arrangeAlongLine(from, to, xyDist, gltfScale, projectionScale, rotationScaleMat, options) {
16203
+ const items = [];
16204
+ const rotationZ = this._getRotationZ(from, to);
16205
+ // cm to mi
16206
+ const zDist = (from.z || 0) - (to.z || 0);
16207
+ const rotationXY = this._getRotationXY(xyDist, zDist);
16208
+ let boxWidth = this._calBoxWidth(gltfScale, rotationScaleMat, options);
16209
+ boxWidth /= projectionScale;
16210
+ const distance = Math.sqrt(xyDist * xyDist + zDist * zDist);
16211
+ const times = Math.floor(distance / boxWidth);
16212
+ let scaleIndex = (options.direction || 0);
16213
+ // scale的scaleIndex已经是Y_UP后的模型,所以和direction不同
16214
+ if (scaleIndex === 1) {
16215
+ scaleIndex = 2;
16216
+ } else if (scaleIndex === 2) {
16217
+ scaleIndex = 1;
16218
+ }
16219
+ //取余缩放
16220
+ if (times >= 1) {
16221
+ for (let i = 1; i <= times; i++) {
16222
+ const t = boxWidth * (i - 0.5) / distance;
16223
+ const item = {
16224
+ coordinates: interpolate(from, to, t),
16225
+ t,
16226
+ scale: [1, 1, 1],
16227
+ rotation: [0, 0, rotationZ],
16228
+ rotationZ,
16229
+ rotationXY
16230
+ };
16231
+ items.push(item);
16232
+ }
16233
+ //尾巴
16234
+ if (options['scaleVertex']) {
16235
+ const t = (boxWidth * times + (distance - boxWidth * times) / 2) / distance;
16236
+ const scale = (distance - boxWidth * times) / boxWidth;
16237
+ const itemScale = [1, 1, 1];
16238
+ itemScale[scaleIndex] = scale;
16239
+ const item = {
16240
+ coordinates: interpolate(from, to, t),
16241
+ t,
16242
+ scale: itemScale,
16243
+ rotation: [0, 0, rotationZ],
16244
+ rotationZ,
16245
+ rotationXY
16246
+ };
16247
+ items.push(item);
16248
+ }
16249
+ } else if (options['scaleVertex']) {
16250
+ const scale = distance / boxWidth;
16251
+ const itemScale = [1, 1, 1];
16252
+ itemScale[scaleIndex] = scale;
16253
+ const item = {
16254
+ coordinates: interpolate(from, to, 0.5),
16255
+ t: 0.5,
16256
+ scale: itemScale,
16257
+ rotation: [0, 0, rotationZ],
16258
+ rotationZ,
16259
+ rotationXY
16260
+ };
16261
+ items.push(item);
16262
+ }
16263
+ return items;
16264
+ }
16265
+
16266
+ calModelHeightScale(out, modelHeight) {
16267
+ const bbox = this.getGLTFBBox();
16268
+ const fitScale = modelHeight / (Math.abs(bbox.max[1] - bbox.min[1]));//YZ轴做了翻转,所以需要用y方向来算高度比例
16269
+ return vec3.set(out, fitScale, fitScale, fitScale);
16270
+ }
16271
+
16272
+ _calBoxWidth(scale, rotationScaleMat, options) {
16273
+ const mat = mat4.multiply(MAT4, rotationScaleMat, Y_TO_Z);
16274
+ const gltfmodelBBox = this.getGLTFBBox(mat);
16275
+ const direction = options.direction || 0;
16276
+ const boxExtent = vec3.sub(TEMP_VEC$1, gltfmodelBBox.max, gltfmodelBBox.min);
16277
+ vec3.multiply(boxExtent, boxExtent, scale);
16278
+ const gapLength = options['gapLength'];
16279
+ return boxExtent[direction] + gapLength;
16280
+ }
16281
+
16282
+ _getRotationZ(from, to) {
16283
+ const degree = computeDegree(
16284
+ to.x, to.y,
16285
+ from.x, from.y
16286
+ );
16287
+ return degree / Math.PI * 180;
16288
+ }
16289
+
16290
+ _getRotationXY(xyDist, zDist) {
16291
+ const rotation = Math.atan(zDist / xyDist) * 180 / Math.PI;
16292
+ return rotation;
16293
+ }
16294
+ }
16295
+
16296
+ function createGeometry(primitive, regl, hasAOMap) {
16297
+ const attributes = primitive.attributes;
16298
+ const aColor0 = attributes['COLOR_0'];
16299
+ //将float类型的颜色值转为0-255的uint8类型
16300
+ if (aColor0 && aColor0.array instanceof Float32Array) {
16301
+ const color = new Uint8Array(aColor0.array.length);
16302
+ for (let i = 0; i < color.length; i++) {
16303
+ color[i] = Math.round(aColor0.array[i] * 255);
16304
+ }
16305
+ aColor0.array = color;
16306
+ } else if (aColor0 && (aColor0.array instanceof Uint16Array ||
16307
+ aColor0.array instanceof Int16Array ||
16308
+ aColor0.array instanceof Uint32Array ||
16309
+ aColor0.array instanceof Int32Array)) {
16310
+ const color = new Uint8Array(aColor0.array);
16311
+ aColor0.array = color;
16312
+ }
16313
+ if (hasAOMap && attributes['TEXCOORD_0'] && !attributes['TEXCOORD_0']) {
16314
+ attributes['TEXCOORD_1'] = attributes['TEXCOORD_0'];
16315
+ }
16316
+ const attrs = {};
16317
+ for (const name in attributes) {
16318
+ // 把原有的array赋给attr,用于计算 bbox、buildUniqueVertex
16319
+ attrs[name] = extend$1({}, attributes[name]);
16320
+ if (regl) {
16321
+ attrs[name].buffer = getUniqueREGLBuffer(regl, attributes[name], { dimension: attributes[name].itemSize });
16322
+ }
16323
+ }
16324
+
16325
+ //如果有morph,需要预先填充morph空数据,动画开启后,会不断向这些空数据中填充morphTargets数据
16326
+ if (primitive.morphTargets) {
16327
+ const length = isInterleaved(attrs['POSITION']) ? attrs['POSITION'].itemSize * attrs['POSITION'].count : attrs['POSITION'].array.length;
16328
+ for (let i = 0; i < 8; i++) {
16329
+ if (!attrs[`POSITION${i}`]) {
16330
+ attrs[`POSITION${i}`] = new Float32Array(length).fill(0);
16331
+ }
16332
+ }
16333
+ for (let i = 0; i < 4; i++) {
16334
+ const length = attrs['NORMAL'].array ? attrs['NORMAL'].array.length : attrs['NORMAL'].length;
16335
+ if (!attrs[`NORMAL${i}`]) {
16336
+ attrs[`NORMAL${i}`] = new Float32Array(length).fill(0);
16337
+ }
16338
+ }
16339
+ }
16340
+ let indices = primitive.indices;
16341
+ if (indices && indices.bufferView === undefined && indices.array) {
16342
+ indices = indices.array;
16343
+ }
16344
+ const modelGeometry = new Geometry(
16345
+ attrs,
16346
+ indices,
16347
+ 0,
16348
+ {
16349
+ //绘制类型,例如 triangle strip, line等,根据gltf中primitive的mode来判断,默认是triangles
16350
+ primitive : isNumber$2(primitive.mode) ? getPrimitive(primitive.mode) : primitive.mode,
16351
+ positionAttribute: 'POSITION',
16352
+ normalAttribute: 'NORMAL',
16353
+ uv0Attribute: 'TEXCOORD_0',
16354
+ uv1Attribute: 'TEXCOORD_1',
16355
+ color0Attribute: 'COLOR_0'
16356
+ }
16357
+ );
16358
+ if (primitive.morphTargets) {
16359
+ modelGeometry.properties.morphWeights = [];
16360
+ }
16361
+ if (primitive.mode > 3 && !modelGeometry.data['NORMAL']) {
16362
+ modelGeometry.createNormal('NORMAL');
16363
+ }
16364
+ return modelGeometry;
16365
+ }
16366
+
16367
+ function numericalSort(a, b) {
16368
+ return a[ 0 ] - b[ 0 ];
16369
+ }
16370
+
16371
+ function absNumericalSort(a, b) {
16372
+ return Math.abs(b[1]) - Math.abs(a[1]);
16373
+ }
16374
+
16375
+ function computeDegree(x0, y0, x1, y1) {
16376
+ const dx = x1 - x0;
16377
+ const dy = y1 - y0;
16378
+ return Math.atan2(dy, dx);
16379
+ }
16380
+
16381
+ function interpolate(from, to, t) {
16382
+ const x = lerp(from.x, to.x, t);
16383
+ const y = lerp(from.y, to.y, t);
16384
+ const z1 = from.z || 0;
16385
+ const z2 = to.z || 0;
16386
+ const z = lerp(z1, z2, t);
16387
+ return new from.constructor(x, y, z);
16388
+ }
16389
+
16390
+ function lerp(a, b, t) {
16391
+ return a + t * (b - a);
16303
16392
  }
16304
16393
 
16305
16394
  // options.fetchOptions
@@ -17656,9 +17745,9 @@ var vert$3 = "#include <gl2_vert>\n#define SHADER_NAME PBR\nattribute vec3 aPosi
17656
17745
 
17657
17746
  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}";
17658
17747
 
17659
- 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: f32,\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 let origin = uniforms.uvOrigin;\n let 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 = 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);\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}";
17748
+ 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);\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}";
17660
17749
 
17661
- var wgslFrag$1 = "#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#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};\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}\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 baseColorSampler: sampler;\n#endif\n#if HAS_METALLICROUGHNESS_MAP\n @group(0) @binding($b) var metallicRoughnessTexture: texture_2d<f32>;\n @group(0) @binding($b) var metallicRoughnessSampler: sampler;\n#endif\n#if HAS_EMISSIVE_MAP\n @group(0) @binding($b) var emissiveTexture: texture_2d<f32>;\n @group(0) @binding($b) var emissiveSampler: sampler;\n#endif\n#if HAS_AO_MAP\n @group(0) @binding($b) var occlusionTexture: texture_2d<f32>;\n @group(0) @binding($b) var occlusionSampler: 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 normalSampler: sampler;\n#endif\n#if HAS_SKIN_MAP\n @group(0) @binding($b) var skinTexture: texture_2d<f32>;\n @group(0) @binding($b) var skinSampler: sampler;\n#endif\n#if HAS_RANDOM_TEX\n @group(0) @binding($b) var noiseTexture: texture_2d<f32>;\n @group(0) @binding($b) var noiseSampler: 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 linePatternSampler: sampler;\n#endif\nstruct VertexOutput {\n #ifdef HAS_SSR\n @location($i) vViewNormal: vec3f,\n #ifdef HAS_TANGENT\n @location($i) vViewTangent: vec4f,\n #endif\n #endif\n @location($i) vModelNormal: vec3f,\n @location($i) vViewVertex: vec4f,\n #if HAS_TANGENT\n @location($i) vModelTangent: vec4f,\n @location($i) vModelBiTangent: vec3f,\n #endif\n @location($i) vModelVertex: vec3f,\n #if HAS_MAP\n @location($i) vTexCoord: vec2f,\n #ifdef HAS_AO_MAP\n @location($i) vTexCoord1: vec2f,\n #endif\n #ifdef HAS_I3S_UVREGION\n @location($i) vUvRegion: vec4f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) vColor: vec4f,\n #endif\n @location($i) vOpacity: f32,\n #if HAS_COLOR0\n @location($i) vColor0: vec4f,\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n @location($i) vTangentViewPos: vec3f,\n @location($i) vTangentFragPos: vec3f,\n #endif\n};\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}\nfn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {\n var materialUniforms: MaterialUniforms;\n#ifdef HAS_MAP\n var uv = computeTexCoord(vertexOutput.vTexCoord);\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 += (uniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;\n let patternx = (linesofar / plusGapWidth) % 1.0;\n let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;\n uv = computeUV(vec2(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]));\n let patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);\n let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);\n let 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 let 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);\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();\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}";
17750
+ var wgslFrag$1 = "#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#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};\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}\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\nstruct VertexOutput {\n #ifdef HAS_SSR\n @location($i) vViewNormal: vec3f,\n #ifdef HAS_TANGENT\n @location($i) vViewTangent: vec4f,\n #endif\n #endif\n @location($i) vModelNormal: vec3f,\n @location($i) vViewVertex: vec4f,\n #if HAS_TANGENT\n @location($i) vModelTangent: vec4f,\n @location($i) vModelBiTangent: vec3f,\n #endif\n @location($i) vModelVertex: vec3f,\n #if HAS_MAP\n @location($i) vTexCoord: vec2f,\n #ifdef HAS_AO_MAP\n @location($i) vTexCoord1: vec2f,\n #endif\n #ifdef HAS_I3S_UVREGION\n @location($i) vUvRegion: vec4f,\n #endif\n #endif\n #if HAS_COLOR\n @location($i) vColor: vec4f,\n #endif\n @location($i) vOpacity: f32,\n #if HAS_COLOR0\n @location($i) vColor0: vec4f,\n #endif\n #if HAS_BUMP_MAP && HAS_TANGENT\n @location($i) vTangentViewPos: vec3f,\n @location($i) vTangentFragPos: vec3f,\n #endif\n};\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}\nfn initMaterial(vertexOutput: VertexOutput) -> MaterialUniforms {\n var materialUniforms: MaterialUniforms;\n#ifdef HAS_MAP\n var 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 += (uniforms.currentTime * -animSpeed * 0.2) % plusGapWidth;\n let patternx = (linesofar / plusGapWidth) % 1.0;\n let patterny = (uniforms.flipY * vertexOutput.vNormalY) % 1.0;\n uv = computeUV(vec2(patternx * (1.0 + myGap) * uniforms.uvScale[0], patterny * uniforms.uvScale[1]));\n let patternColor = textureSample(linePatternFile, linePatternFileSampler, uv);\n let inGap = clamp(sign(1.0 / (1.0 + myGap) - patternx) + 0.000001, 0.0, 1.0);\n let 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 let 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();\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}";
17662
17751
 
17663
17752
  //http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/
17664
17753
  class StandardShader extends MeshShader {
@@ -18407,8 +18496,8 @@ const frag0Wgsl = /*wgsl*/`
18407
18496
  @group(0) @binding($b) var<uniform> pickingUniforms: PickingUniforms;
18408
18497
 
18409
18498
  struct VertexOutput {
18410
- @location($i) vPickingId: f32,
18411
18499
  @location($i) vFbo_picking_visible: f32,
18500
+ @location($i) vPickingId: f32,
18412
18501
  };
18413
18502
 
18414
18503
  @fragment
@@ -18473,8 +18562,8 @@ const frag1Wgsl = /*wgsl*/`
18473
18562
  const frag2 = `
18474
18563
  precision highp float;
18475
18564
 
18476
- varying float vPickingId;
18477
18565
  varying float vFbo_picking_visible;
18566
+ varying float vPickingId;
18478
18567
 
18479
18568
  ${unpackFun}
18480
18569
 
@@ -18491,8 +18580,8 @@ const frag2Wgsl = /*wgsl*/`
18491
18580
  ${unpackFunWgsl}
18492
18581
 
18493
18582
  struct VertexOutput {
18494
- @location($i) vPickingId: f32,
18495
18583
  @location($i) vFbo_picking_visible: f32,
18584
+ @location($i) vPickingId: f32,
18496
18585
  };
18497
18586
 
18498
18587
  @fragment
@@ -19744,7 +19833,7 @@ class GraphicsDevice {
19744
19833
  const context = storage.getContext('webgpu');
19745
19834
  context.configure({
19746
19835
  device,
19747
- format: 'bgra8unorm',
19836
+ format: 'rgba8unorm',
19748
19837
  usage: GPUTextureUsage.COPY_DST,
19749
19838
  alphaMode: alphaModes[index]
19750
19839
  });
@@ -19813,6 +19902,10 @@ class GraphicsDevice {
19813
19902
  this._defaultFramebuffer.destroy();
19814
19903
  delete this._defaultFramebuffer;
19815
19904
  }
19905
+ if (this.dynamicBufferPool) {
19906
+ this.dynamicBufferPool.destroy();
19907
+ delete this.dynamicBufferPool;
19908
+ }
19816
19909
  for (const p in this._readTargets) {
19817
19910
  const buffer = this._readTargets[p];
19818
19911
  if (buffer) {
@@ -22386,9 +22479,13 @@ class ShadowProcess {
22386
22479
  }
22387
22480
  }
22388
22481
 
22389
- var fillVert = "attribute vec3 aPosition;\nuniform mat4 projViewModelMatrix;\nuniform mat4 modelMatrix;\n#ifdef HAS_PATTERN\nattribute vec2 aTexCoord;\nuniform vec2 uvScale;\nuniform vec2 uvOffset;\nvarying vec2 vTexCoord;\n#endif\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_vert>\n#endif\nvoid main() {\n \n#ifdef HAS_PATTERN\nvTexCoord = aTexCoord * uvScale + uvOffset;\n#endif\nvec3 c = vec3(aPosition);\n gl_Position = projViewModelMatrix * vec4(c, 1.);\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nshadow_computeShadowPars(vec4(c, 1.));\n#endif\n}";
22482
+ var fillVert = "#define SHADER_NAME BACK_FILL\nattribute vec3 aPosition;\nuniform mat4 projViewModelMatrix;\nuniform mat4 modelMatrix;\n#ifdef HAS_PATTERN\nattribute vec2 aTexCoord;\nuniform vec2 uvScale;\nuniform vec2 uvOffset;\nvarying vec2 vTexCoord;\n#endif\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_vert>\n#endif\nvoid main() {\n \n#ifdef HAS_PATTERN\nvTexCoord = aTexCoord * uvScale + uvOffset;\n#endif\nvec3 c = vec3(aPosition);\n gl_Position = projViewModelMatrix * vec4(c, 1.);\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nshadow_computeShadowPars(vec4(c, 1.));\n#endif\n}";
22390
22483
 
22391
- var fillFrag = "precision mediump float;\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_frag>\n#endif\n#ifdef HAS_PATTERN\nuniform sampler2D polygonPatternFile;\nvarying vec2 vTexCoord;\n#endif\nuniform vec4 polygonFill;\nuniform float polygonOpacity;\nvoid main() {\n \n#ifdef HAS_PATTERN\nvec4 c = texture2D(polygonPatternFile, vTexCoord);\n#else\nvec4 c = polygonFill;\n#endif\ngl_FragColor = c * polygonOpacity;\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nfloat d = shadow_computeShadow();\n gl_FragColor.rgb = shadow_blend(gl_FragColor.rgb, d);\n#endif\n}";
22484
+ var fillFrag = "#define SHADER_NAME BACK_FILL\nprecision mediump float;\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\n#include <vsm_shadow_frag>\n#endif\n#ifdef HAS_PATTERN\nuniform sampler2D polygonPatternFile;\nvarying vec2 vTexCoord;\n#endif\nuniform vec4 polygonFill;\nuniform float polygonOpacity;\nvoid main() {\n \n#ifdef HAS_PATTERN\nvec4 c = texture2D(polygonPatternFile, vTexCoord);\n#else\nvec4 c = polygonFill;\n#endif\ngl_FragColor = c * polygonOpacity;\n#if defined(HAS_SHADOWING) && !defined(HAS_BLOOM)\nfloat d = shadow_computeShadow();\n gl_FragColor.rgb = shadow_blend(gl_FragColor.rgb, d);\n#endif\n}";
22485
+
22486
+ var fillWgslVert = "#include <vsm_shadow_vert>\nstruct VertexInput {\n @location($i) aPosition: vec3f,\n#ifdef HAS_PATTERN\n @location($i) aTexCoord: vec2f,\n#endif\n};\nstruct VertexOutput {\n @builtin(position) Position: vec4f,\n#ifdef HAS_PATTERN\n @location($o) vTexCoord: vec2f,\n#endif\n};\nstruct BackFillUniforms {\n projViewModelMatrix: mat4x4f,\n modelMatrix: mat4x4f,\n#ifdef HAS_PATTERN\n uvScale: vec2f,\n uvOffset: vec2f,\n#endif\n};\n@group(0) @binding($b) var<uniform> uniforms: BackFillUniforms;\n@vertex\nfn main(vertexInput: VertexInput) -> VertexOutput {\n var vertexOutput: VertexOutput;\n#ifdef HAS_PATTERN\n vertexOutput.vTexCoord = vertexInput.aTexCoord * uniforms.uvScale + uniforms.uvOffset;\n#endif\n let position = vec3f(vertexInput.aPosition);\n vertexOutput.Position = uniforms.projViewModelMatrix * vec4f(position, 1.0);\n#if HAS_SHADOWING && !HAS_BLOOM\n shadow_computeShadowPars(uniforms.modelMatrix * vec4f(position, 1.0));\n#endif\n return vertexOutput;\n}";
22487
+
22488
+ var fillWgslFrag = "#if HAS_SHADOWING && !HAS_BLOOM\n #include <vsm_shadow_frag>\n#endif\nstruct VertexOutput {\n @builtin(position) Position: vec4f,\n#ifdef HAS_PATTERN\n @location($i) vTexCoord: vec2f,\n#endif\n};\nstruct BackFillUniforms {\n polygonFill: vec4f,\n polygonOpacity: f32,\n};\n@group(0) @binding($b) var<uniform> uniforms: BackFillUniforms;\n#ifdef HAS_PATTERN\n@group(0) @binding($b) var polygonPatternFile: texture_2d<f32>;\n@group(0) @binding($b) var polygonPatternFileSampler: sampler;\n#endif\n@fragment\nfn main(vertexOutput: VertexOutput) -> @location(0) vec4f {\n#ifdef HAS_PATTERN\n let color = textureSample(polygonPatternFile, polygonPatternFileSampler, vertexOutput.vTexCoord);\n#else\n let color = uniforms.polygonFill;\n#endif\n var fragColor: vec4f = color * uniforms.polygonOpacity;\n#if HAS_SHADOWING && !HAS_BLOOM\n let shadowCoeff = shadow_computeShadow();\n fragColor = vec4(shadow_blend(fragColor.rgb, shadowCoeff), fragColor.a);\n#endif\n return fragColor;\n}";
22392
22489
 
22393
22490
  const DEFAULT_TEX_OFFSET$1 = [0, 0];
22394
22491
  const COORD0$1 = new maptalks.Coordinate(0, 0);
@@ -22719,8 +22816,8 @@ class GroundPainter {
22719
22816
  name: 'ground-fill',
22720
22817
  vert: fillVert,
22721
22818
  frag: fillFrag,
22722
- wgslFrag: null,
22723
- wgslVert: null,
22819
+ wgslVert: fillWgslVert,
22820
+ wgslFrag: fillWgslFrag,
22724
22821
  uniforms: fillUniforms,
22725
22822
  extraCommandProps,
22726
22823
  defines: {}
@@ -22794,7 +22891,7 @@ class GroundPainter {
22794
22891
  }
22795
22892
  _createGround() {
22796
22893
  const planeGeo = new Plane();
22797
- planeGeo.data.aTexCoord = new Uint8Array([
22894
+ planeGeo.data.aTexCoord = new Float32Array([
22798
22895
  0, 0,
22799
22896
  1, 0,
22800
22897
  0, 1,
@@ -24115,6 +24212,12 @@ class PostProcess {
24115
24212
  } else {
24116
24213
  delete shaderDefines['HAS_OUTLINE_TEX'];
24117
24214
  }
24215
+ const useMultiSample = this._layer.options.antialias === true;
24216
+ if (useMultiSample) {
24217
+ shaderDefines['HAS_MULTISAMPLED'] = 1;
24218
+ } else {
24219
+ delete shaderDefines['HAS_MULTISAMPLED'];
24220
+ }
24118
24221
  // if (noAaSource) {
24119
24222
  // shaderDefines['HAS_NOAA_TEX'] = 1;
24120
24223
  // } else {
@@ -24694,6 +24797,7 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
24694
24797
 
24695
24798
  prepareCanvas() {
24696
24799
  super.prepareCanvas();
24800
+ this.resizeCanvas();
24697
24801
  this.forEachRenderer(renderer => {
24698
24802
  renderer.prepareCanvas();
24699
24803
  });
@@ -24725,7 +24829,7 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
24725
24829
  this._renderInMode('default', null, methodName, args, true);
24726
24830
  return;
24727
24831
  }
24728
- const fGL = this.reglGL;
24832
+ // const fGL = this.reglGL;
24729
24833
 
24730
24834
  const sceneConfig = this.layer._getSceneConfig();
24731
24835
  const config = sceneConfig && sceneConfig.postProcess;
@@ -24736,7 +24840,7 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
24736
24840
  drawContext.jitter = NO_JITTER;
24737
24841
  const groundConfig = this.layer.getGroundConfig();
24738
24842
  drawContext.hasSSRGround = !!(ssrMode && groundConfig && groundConfig.enable && groundConfig.symbol && groundConfig.symbol.ssr);
24739
- fGL.resetDrawCalls();
24843
+ // fGL.resetDrawCalls();
24740
24844
  // this._renderInMode(enableTAA ? 'fxaaBeforeTaa' : 'fxaa', this._targetFBO, methodName, args);
24741
24845
  this._renderInMode('default', this._targetFBO, methodName, args, true);
24742
24846
  // this._fxaaDrawCount = fGL.getDrawCalls();
@@ -24802,14 +24906,14 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
24802
24906
  }
24803
24907
 
24804
24908
  // noAa的绘制放在bloom后,避免noAa的数据覆盖了bloom效果
24805
- fGL.resetDrawCalls();
24909
+ // fGL.resetDrawCalls();
24806
24910
  // this._renderInMode('noAa', this._noAaFBO, methodName, args);
24807
24911
  // this._noaaDrawCount = fGL.getDrawCalls();
24808
24912
 
24809
24913
  // fGL.resetDrawCalls();
24810
24914
  // this._renderInMode('point', this._pointFBO, methodName, args, true);
24811
24915
  this._weatherPainter.renderScene(drawContext);
24812
- this._pointDrawCount = fGL.getDrawCalls();
24916
+ // this._pointDrawCount = fGL.getDrawCalls();
24813
24917
 
24814
24918
  // return tex;
24815
24919
  }
@@ -24885,12 +24989,16 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
24885
24989
  const { width, height } = this.canvas;
24886
24990
  let fbo = this._outlineFBO;
24887
24991
  if (!fbo) {
24992
+ const isWebGPU = this.device && this.device.wgpu;
24993
+ const format = isWebGPU ? 'rgba' : 'rgba4';
24994
+ const isAntialias = this.layer.options.antialias;
24995
+ const sampleCount = isAntialias ? 4 : 1;
24888
24996
  const outlineTex = this.regl.texture({
24889
24997
  width: width,
24890
24998
  height: height,
24891
- format: 'rgba4',
24999
+ format,
24892
25000
  // needed by webgpu
24893
- sampleCount: 4
25001
+ sampleCount
24894
25002
  });
24895
25003
  fbo = this._outlineFBO = this.regl.framebuffer({
24896
25004
  width: width,
@@ -25145,48 +25253,23 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
25145
25253
  }
25146
25254
 
25147
25255
  _clearFramebuffers() {
25148
- const regl = this.regl;
25256
+ const device = this.device;
25149
25257
  if (this._targetFBO) {
25150
- regl.clear({
25258
+ device.clear({
25151
25259
  color: EMPTY_COLOR$1,
25152
25260
  depth: 1,
25153
25261
  stencil: 0,
25154
25262
  framebuffer: this._targetFBO
25155
25263
  });
25156
- // regl.clear({
25157
- // color: EMPTY_COLOR,
25158
- // framebuffer: this._noAaFBO
25159
- // });
25160
- // regl.clear({
25161
- // color: EMPTY_COLOR,
25162
- // framebuffer: this._pointFBO
25163
- // });
25164
- // if (this._taaFBO && this._taaDrawCount) {
25165
- // regl.clear({
25166
- // color: EMPTY_COLOR,
25167
- // framebuffer: this._taaFBO
25168
- // });
25169
- // }
25170
- // if (this._fxaaFBO && this._fxaaAfterTaaDrawCount) {
25171
- // regl.clear({
25172
- // color: EMPTY_COLOR,
25173
- // framebuffer: this._fxaaFBO
25174
- // });
25175
- // }
25176
25264
  }
25177
25265
  if (this._outlineFBO) {
25178
- regl.clear({
25266
+ device.clear({
25179
25267
  color: EMPTY_COLOR$1,
25180
25268
  depth: 1,
25181
25269
  stencil: 0,
25182
25270
  framebuffer: this._outlineFBO
25183
25271
  });
25184
25272
  }
25185
- // regl.clear({
25186
- // color: EMPTY_COLOR,
25187
- // depth: 1,
25188
- // stencil: 0
25189
- // });
25190
25273
  }
25191
25274
 
25192
25275
  resizeCanvas() {
@@ -25760,14 +25843,14 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
25760
25843
  const sceneConfig = this.layer._getSceneConfig();
25761
25844
  const config = sceneConfig && sceneConfig.postProcess;
25762
25845
  if (!this._targetFBO) {
25763
- const regl = this.regl;
25846
+ const device = this.device;
25764
25847
  let depthTex = this._depthTex;
25765
25848
  if (!depthTex || !depthTex['_texture'] || depthTex['_texture'].refCount <= 0) {
25766
25849
  depthTex = null;
25767
25850
  }
25768
25851
  const fboInfo = this.createFBOInfo(config, depthTex);
25769
25852
  this._depthTex = fboInfo.depth || fboInfo.depthStencil;
25770
- this._targetFBO = regl.framebuffer(fboInfo);
25853
+ this._targetFBO = device.framebuffer(fboInfo);
25771
25854
  // const noAaInfo = this.createFBOInfo(config, this._depthTex);
25772
25855
  // this._noAaFBO = regl.framebuffer(noAaInfo);
25773
25856
  // const pointInfo = this.createFBOInfo(config, this._depthTex);
@@ -25783,8 +25866,10 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
25783
25866
  width = width || this.canvas.width, height = height || this.canvas.height;
25784
25867
  const regl = this.device;
25785
25868
  const useMultiSamples = this._isUseMultiSample();
25869
+ const isAntialias = this.layer.options.antialias;
25786
25870
  let color;
25787
25871
  if (!forceTexture && useMultiSamples) {
25872
+ // rgba8 是webgl中的格式,regl支持,对应的还有rgba4
25788
25873
  color = regl.renderbuffer({
25789
25874
  width,
25790
25875
  height,
@@ -25792,6 +25877,7 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
25792
25877
  format: 'rgba8'
25793
25878
  });
25794
25879
  } else {
25880
+ const sampleCount = isAntialias ? 4 : 1;
25795
25881
  const type = 'uint8';//colorType || regl.hasExtension('OES_texture_half_float') ? 'float16' : 'float';
25796
25882
  color = regl.texture({
25797
25883
  min: 'nearest',
@@ -25800,7 +25886,7 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
25800
25886
  width,
25801
25887
  height,
25802
25888
  // needed by webgpu
25803
- sampleCount: 4
25889
+ sampleCount
25804
25890
  });
25805
25891
  }
25806
25892
  const fboInfo = {
@@ -25834,6 +25920,8 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
25834
25920
  } else {
25835
25921
  //depth(stencil) buffer 是可以共享的
25836
25922
  if (enableDepthTex) {
25923
+ const isAntialias = this.layer.options.antialias;
25924
+ const sampleCount = isAntialias ? 4 : 1;
25837
25925
  const depthStencilTexture = depthTex || regl.texture({
25838
25926
  min: 'nearest',
25839
25927
  mag: 'nearest',
@@ -25841,7 +25929,9 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
25841
25929
  type: 'depth stencil',
25842
25930
  width,
25843
25931
  height,
25844
- format: 'depth stencil'
25932
+ format: 'depth stencil',
25933
+ // needed by webgpu
25934
+ sampleCount
25845
25935
  });
25846
25936
  fboInfo.depthStencil = depthStencilTexture;
25847
25937
  } else {
@@ -27193,7 +27283,7 @@ class TerrainLitPainter extends TerrainPainter {
27193
27283
 
27194
27284
  createTerrainMesh(tileInfo, terrainImage) {
27195
27285
  const { mesh: terrainGeo, image: heightTexture } = terrainImage;
27196
- const { positions, texcoords, triangles, leftSkirtIndex, rightSkirtIndex, bottomSkirtIndex, numVerticesWithoutSkirts } = terrainGeo;
27286
+ const { positions, texcoords, triangles, leftSkirtIndex, rightSkirtIndex, bottomSkirtIndex, numVerticesWithoutSkirts, tangents } = terrainGeo;
27197
27287
  const normals = new Int8Array(positions.length);
27198
27288
  for (let i = 2; i < normals.length; i += 3) {
27199
27289
  if (i < numVerticesWithoutSkirts * 3) {
@@ -27213,15 +27303,12 @@ class TerrainLitPainter extends TerrainPainter {
27213
27303
  aPosition: positions,
27214
27304
  aTexCoord: texcoords,
27215
27305
  aNormal: normals
27216
- },
27217
- triangles,
27218
- 0);
27219
-
27306
+ }, triangles, 0);
27220
27307
  // 共用端点时,法线值会出现错误,造成视觉上不连续,所以需要唯一化
27221
27308
  // 唯一化后,三角形数量不变,但端点数组大概会膨胀5倍以上
27222
27309
  // geo.buildUniqueVertex();
27223
27310
  // geo.createNormal();
27224
- geo.createTangent();
27311
+ geo.createTangent('aTangent', tangents);
27225
27312
  delete geo.data.aNormal;
27226
27313
 
27227
27314
  geo.generateBuffers(this.graphics);
@@ -27302,7 +27389,7 @@ class TerrainLitPainter extends TerrainPainter {
27302
27389
  extend(uniforms, {
27303
27390
  viewMatrix: map.viewMatrix,
27304
27391
  projMatrix: map.projMatrix,
27305
- projViewMatrix : map.projViewMatrix,
27392
+ projViewMatrix: map.projViewMatrix,
27306
27393
  outSize: [canvas.width, canvas.height],
27307
27394
  polygonFill: [1, 1, 1, 1],
27308
27395
  terrainHeightMapResolution: [tileSize, tileSize],
@@ -27691,7 +27778,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
27691
27778
  const terrainWidth = heights.width;
27692
27779
  const mesh = createMartiniData(error / 2, heights.data, terrainWidth);
27693
27780
 
27694
- return { data: heights, mesh, sourceZoom };
27781
+ return { data: heights, mesh, sourceZoom, colorsTexture: heights.colorsTexture };
27695
27782
  }
27696
27783
 
27697
27784
  _findTileMinAltitude(tile, parentTile) {
@@ -27727,6 +27814,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
27727
27814
  tileImage.sourceZoom = -1;
27728
27815
  } else {
27729
27816
  tileImage = this._createTerrainFromParent(tileInfo, parentTile);
27817
+ wrapTileColorsTexture(tileInfo, tileImage);
27730
27818
  }
27731
27819
  }
27732
27820
  this._createMesh(tileImage, tileInfo);
@@ -28395,6 +28483,27 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28395
28483
  xmin = Math.floor(xmin);
28396
28484
  ymin = Math.floor(ymin);
28397
28485
 
28486
+ let colorsTexture;
28487
+ //parent tile has colorstexture
28488
+ if (info.colorsTexture) {
28489
+ const { width, height } = info.colorsTexture;
28490
+ if (width * height > 0) {
28491
+ const x1 = info.extent2d.xmin;
28492
+ const x2 = info.extent2d.xmax;
28493
+ const y1 = info.extent2d.ymin;
28494
+ const y2 = info.extent2d.ymax;
28495
+ const ax = (width) / (x2 - x1), ay = height / (y2 - y1);
28496
+ const minx = (extent2d.xmin * res / parentRes - parentExtent.xmin) * ax;
28497
+ const maxx = (extent2d.xmax * res / parentRes - parentExtent.xmin) * ax;
28498
+ const miny = (extent2d.ymin * res / parentRes - parentExtent.ymin) * ay;
28499
+ const maxy = (extent2d.ymax * res / parentRes - parentExtent.ymin) * ay;
28500
+ //clip texture from parent tile texture
28501
+ colorsTexture = clipTileTexture(info.colorsTexture, minx, miny, maxx, maxy);
28502
+ }
28503
+
28504
+
28505
+ }
28506
+
28398
28507
  // const tileSize = tileWidth - 1;
28399
28508
  // if (tileSize & (tileSize - 1)) {
28400
28509
  // debugger
@@ -28436,7 +28545,8 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28436
28545
  height: tileWidth,
28437
28546
  data: heights,
28438
28547
  min,
28439
- max
28548
+ max,
28549
+ colorsTexture
28440
28550
  };
28441
28551
  }
28442
28552
 
@@ -28549,6 +28659,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28549
28659
  const args = [x, y, maxAvailableZoom, idx, idy, res, tile.error * Math.pow(2, diff)];
28550
28660
  tile = layer.createTileNode ? layer.createTileNode(...args) : layer._createTileNode(...args);
28551
28661
  } else {
28662
+ wrapTileColorsTexture(tile, terrainData);
28552
28663
  this.onTileLoad(terrainData, tile);
28553
28664
  return terrainData;
28554
28665
  }
@@ -28591,8 +28702,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
28591
28702
  maptalks.Util.extend(terrainData, resource);
28592
28703
 
28593
28704
  // this.consumeTile(terrainData, tile);
28594
- tile.colorsTexture = terrainData.colorsTexture;
28595
- delete terrainData.colorsTexture;
28705
+ wrapTileColorsTexture(tile, terrainData);
28596
28706
  this.onTileLoad(terrainData, tile);
28597
28707
  });
28598
28708
  };
@@ -29233,6 +29343,42 @@ function isValidSkinImage(image) {
29233
29343
 
29234
29344
  function getParentRequestKey(x, y) {
29235
29345
  return x + '-' + y;
29346
+ }
29347
+
29348
+ function isPowerOfTwo(value) {
29349
+ return (value & (value - 1)) === 0 && value !== 0;
29350
+ }
29351
+
29352
+ let tempCanvas;
29353
+
29354
+ function clipTileTexture(image, x1, y1, x2, y2) {
29355
+ if (maptalks.Browser.decodeImageInWorker) {
29356
+ if (!tempCanvas) {
29357
+ tempCanvas = new OffscreenCanvas(1, 1);
29358
+ }
29359
+ const width = Math.floor(x2 - x1), height = Math.floor((y2 - y1));
29360
+ if (!isPowerOfTwo(width) || !isPowerOfTwo(height)) {
29361
+ return;
29362
+ }
29363
+ tempCanvas.width = width;
29364
+ tempCanvas.height = height;
29365
+ const ctx = tempCanvas.getContext('2d');
29366
+ ctx.clearRect(0, 0, width, height);
29367
+ ctx.drawImage(image, x1, y1, width, height, 0, 0, width, height);
29368
+ return tempCanvas.transferToImageBitmap();
29369
+ }
29370
+ }
29371
+
29372
+ function wrapTileColorsTexture(tile, terrainData) {
29373
+ const colorsTexture = terrainData.colorsTexture;
29374
+ delete terrainData.colorsTexture;
29375
+ if (colorsTexture) {
29376
+ if (tile.info) {
29377
+ tile.info.colorsTexture = colorsTexture;
29378
+ } else {
29379
+ tile.colorsTexture = colorsTexture;
29380
+ }
29381
+ }
29236
29382
  }
29237
29383
 
29238
29384
  const MASK_MODES = {
@@ -30395,6 +30541,7 @@ class RayCaster {
30395
30541
 
30396
30542
  _testMesh(mesh, ray, map, positions, altitudes, indices, dim, matrix, count) {
30397
30543
  const coordinates = [];
30544
+ const glRes = map.getGLRes();
30398
30545
  for (let j = 0; j < indices.length; j += 3) {
30399
30546
  if (j > mesh.properties.skirtOffset) {
30400
30547
  break;
@@ -30402,22 +30549,41 @@ class RayCaster {
30402
30549
  const a = indices[j];
30403
30550
  const b = indices[j + 1];
30404
30551
  const c = indices[j + 2];
30405
- const positionsA = vec3.set(pA_VEC, positions[a * dim], positions[a * dim + 1], positions[a * dim + 2]);
30406
- const pA = this._toWorldPosition(POS_A, map, positionsA, altitudes[a] / 100, matrix);
30407
- const positionsB = vec3.set(pB_VEC, positions[b * dim], positions[b * dim + 1], positions[b * dim + 2]);
30408
- const pB = this._toWorldPosition(POS_B, map, positionsB, altitudes[b] / 100, matrix);
30409
- const positionsC = vec3.set(pC_VEC, positions[c * dim], positions[c * dim + 1], positions[c * dim + 2]);
30410
- const pC = this._toWorldPosition(POS_C, map, positionsC, altitudes[c] / 100, matrix);
30552
+ const aindex = a * dim, bindex = b * dim, cindex = c * dim;
30553
+ //高频操作,尽可能的减少function(vec3.set) call,
30554
+ pA_VEC[0] = positions[aindex];
30555
+ pA_VEC[1] = positions[aindex + 1];
30556
+ pA_VEC[2] = positions[aindex + 2];
30557
+
30558
+ pB_VEC[0] = positions[bindex];
30559
+ pB_VEC[1] = positions[bindex + 1];
30560
+ pB_VEC[2] = positions[bindex + 2];
30561
+
30562
+ pC_VEC[0] = positions[cindex];
30563
+ pC_VEC[1] = positions[cindex + 1];
30564
+ pC_VEC[2] = positions[cindex + 2];
30565
+
30566
+
30567
+ const pA = this._toWorldPosition(POS_A, map, pA_VEC, altitudes[a] / 100, matrix);
30568
+ const pB = this._toWorldPosition(POS_B, map, pB_VEC, altitudes[b] / 100, matrix);
30569
+ const pC = this._toWorldPosition(POS_C, map, pC_VEC, altitudes[c] / 100, matrix);
30570
+
30571
+ // const positionsA = vec3.set(pA_VEC, positions[a * dim], positions[a * dim + 1], positions[a * dim + 2]);
30572
+ // const pA = this._toWorldPosition(POS_A, map, positionsA, altitudes[a] / 100, matrix);
30573
+ // const positionsB = vec3.set(pB_VEC, positions[b * dim], positions[b * dim + 1], positions[b * dim + 2]);
30574
+ // const pB = this._toWorldPosition(POS_B, map, positionsB, altitudes[b] / 100, matrix);
30575
+ // const positionsC = vec3.set(pC_VEC, positions[c * dim], positions[c * dim + 1], positions[c * dim + 2]);
30576
+ // const pC = this._toWorldPosition(POS_C, map, positionsC, altitudes[c] / 100, matrix);
30411
30577
 
30412
30578
  const triangle = vec3.set(TRIANGLE, pA, pB, pC);
30413
30579
  const vAB = vec3.sub(TEMP_VEC_AB, pA, pB);
30414
30580
  const vAC = vec3.sub(TEMP_VEC_AC, pA, pC);
30415
30581
  const intersectPoint = this._testIntersection(INTERSECT_POINT, triangle, ray);
30416
30582
  if (intersectPoint) {
30417
- const altitude = map.pointAtResToAltitude(intersectPoint[2], map.getGLRes());
30583
+ const altitude = map.pointAtResToAltitude(intersectPoint[2], glRes);
30418
30584
  TEMP_POINT$1.x = intersectPoint[0];
30419
30585
  TEMP_POINT$1.y = intersectPoint[1];
30420
- const coord = map.pointAtResToCoordinate(TEMP_POINT$1, map.getGLRes());
30586
+ const coord = map.pointAtResToCoordinate(TEMP_POINT$1, glRes);
30421
30587
  coord.z = altitude;
30422
30588
  coordinates.push({
30423
30589
  coordinate: coord,
@@ -31675,20 +31841,20 @@ class MapGLRenderer extends renderer.MapAbstractRenderer {
31675
31841
  // createCanvas, createContext, getContextInstance, clearLayerCanvasContext 和 clearCanvas 方法都应该动态注入
31676
31842
 
31677
31843
  clearCanvas() {
31678
- if (!this.regl) {
31844
+ if (!this.device) {
31679
31845
  return;
31680
31846
  }
31681
31847
  // depth and stencil will be cleared in clearLayerCanvasContext
31682
- this.regl.clear({
31848
+ this.device.clear({
31683
31849
  color: [0, 0, 0, 0]
31684
31850
  });
31685
31851
  }
31686
31852
 
31687
31853
  clearLayerCanvasContext(layer) {
31688
- if (!this.regl) {
31854
+ if (!this.device) {
31689
31855
  return;
31690
31856
  }
31691
- this.regl.clear({
31857
+ this.device.clear({
31692
31858
  depth: 1,
31693
31859
  stencil: 0
31694
31860
  });
@@ -31794,7 +31960,7 @@ function initGPUDevice() {
31794
31960
  return { gpuDevice, gpuAdapter };
31795
31961
  });
31796
31962
  }
31797
- class MapGPURenderer extends renderer.MapAbstractRenderer {
31963
+ class MapGPURenderer extends MapGLRenderer {
31798
31964
  drawLayers(layers, framestamp) {
31799
31965
  const updated = super.drawLayers(layers, framestamp);
31800
31966
  if (updated) {
@@ -31802,32 +31968,6 @@ class MapGPURenderer extends renderer.MapAbstractRenderer {
31802
31968
  }
31803
31969
  return updated;
31804
31970
  }
31805
- clearCanvas() {
31806
- if (!this.device) {
31807
- return;
31808
- }
31809
- // depth and stencil will be cleared in clearLayerCanvasContext
31810
- this.device.clear({
31811
- color: [0, 0, 0, 0]
31812
- });
31813
- }
31814
- clearLayerCanvasContext(layer) {
31815
- if (!this.device) {
31816
- return;
31817
- }
31818
- // const renderer = layer.getRenderer();
31819
- this.device.clear({
31820
- depth: 1,
31821
- stencil: 0
31822
- });
31823
- // renderer.clearContext();
31824
- }
31825
- isWebGL() {
31826
- return false;
31827
- }
31828
- isWebGPU() {
31829
- return true;
31830
- }
31831
31971
  createContext() {
31832
31972
  return initGPUDevice().then(({ gpuDevice, gpuAdapter }) => {
31833
31973
  const context = this.canvas.getContext('webgpu');
@@ -31850,6 +31990,12 @@ class MapGPURenderer extends renderer.MapAbstractRenderer {
31850
31990
  };
31851
31991
  });
31852
31992
  }
31993
+ isWebGL() {
31994
+ return false;
31995
+ }
31996
+ isWebGPU() {
31997
+ return true;
31998
+ }
31853
31999
  }
31854
32000
  Map$1.registerRenderer('gpu', MapGPURenderer);
31855
32001
 
@@ -33898,12 +34044,20 @@ class Height3DTool extends Measure3DTool {
33898
34044
 
33899
34045
  const e = "${"; const code$1 = `function(t){
33900
34046
  /*!
33901
- * @maptalks/gltf-loader v0.116.0
34047
+ * @maptalks/gltf-loader v0.117.1
33902
34048
  * LICENSE : UNLICENSED
33903
34049
  * (c) 2016-2025 maptalks.org
33904
34050
  */
33905
34051
  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"),
33906
- /** @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,B,z,F,_,C,N,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),C=U(_=T(this.L,15)),O=U(N=T(this.K,7)),B=286;257<B&&0===_[B-1];B--);for(z=30;1<z&&0===N[z-1];z--);var Z,G,$,J,K,X,Q=B,tt=z,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++]=_[Z];for(Z=0;Z<tt;Z++)et[G++]=N[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(F=19;4<F&&0===V[F-1];F--);for(P=U(R),Y.d(B-257,5,r),Y.d(z-1,5,r),Y.d(F-4,4,r),L=0;L<F;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=[C,_],gt=[O,N];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)(_.length),k=e,E=e,x=e,T=e,U=e;for(U=0;U<A;++U)v[_[U]]=$(this,3);if(!s)for(U=A,A=v.length;U<A;++U)v[_[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 B,z,F=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],_=s?new Uint16Array(F):F,C=[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],N=s?new Uint16Array(C):C,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(B=0,z=H.length;B<z;++B)H[B]=143>=B?8:255>=B?9:279>=B?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=N[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=N[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 B=U;I(d);return{vertices:b,triangles:w,numVerticesWithoutSkirts:s,numTrianglesWithoutSkirts:a,leftSkirtIndex:S,rightSkirtIndex:D,bottomSkirtIndex:B,topSkirtIndex:U}}}const p={};let y;const m={width:100,height:10};let b,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(!y){const{width:t,height:e}=m;w?y=new OffscreenCanvas(t,e):(y=document.createElement("canvas"),y.width=t,y.height=e)}return y}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({},m,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]]}}let k=null,E=null;const x=[0,0,0],T=[256,256];function U(){try{k||(k=new OffscreenCanvas(1,1))}catch(t){console.error(t)}}const M={},I={},S={width:64,height:64,elementsPerHeight:3,heightOffset:-1e3,exaggeration:1,heightScale:.001,elementMultiplier:256,stride:4,skirtHeight:.002,skirtOffset:.01},D={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,*/*"}};D["cesium-ion"]=D.cesium;const B=32767;let z=null,F=null;function _(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),C.decode(n)));var n;const i=function(t){const e=t,r=S.width,n=S.height,i=new Uint8Array(r*n*S.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)/S.heightScale,u=S.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=S.elementsPerHeight,o=S.heightOffset,h=S.heightScale,c=S.elementMultiplier,f=S.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 C=new TextDecoder("utf-8");function N(t){return t>>1^-(1&t)}const O=[];function R(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+=N(t[o]),s+=N(e[o]),t[o]=i,e[o]=s,r&&(a+=N(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=O;for(let t=0;t<y;++t){const e=m[t],r=b[t],n=e/B,i=r/B,s=(v=a,k=o,(1-(E=w[t]/B))*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 P=[],j=[],q=[],L=[],H=[];class Y{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(P,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(q,this.p0[0],this.p0[1]),u(L,this.p1[0],this.p1[1]),u(H,this.p2[0],this.p2[1]);const r=G(q[0],q[1],L[0],L[1],H[0],H[1]);return G(t,e,q[0],q[1],H[0],H[1])+G(t,e,q[0],q[1],L[0],L[1])+G(t,e,L[0],L[1],H[0],H[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 W=null;function V(t,e,r){if(W&&W.contains(e,r))return W.getHeight(e,r);for(let n=0;n<t.length;n++)if(t[n].contains(e,r))return W=t[n],t[n].getHeight(e,r);return 0}const Z=[];function G(t,e,r,n,i,s){return.5*Math.abs(t*n+r*s+i*e-t*s-r*e-i*n)}function $(t,e,r,n,i,s){"cesium-ion"===r&&(e.Authorization="Bearer "+z),function(t,e,r){const n={method:"GET",referrer:r,headers:e},i=h.getArrayBuffer(t,n),s=i.xhr;return I[t]=s,i.then((e=>(delete I[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=_(e,n);K(i,t,n,null,!0,s)}else if("cesium-ion"===r||"cesium"===r){a=R(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=Z[h];e?e.set(r,s[t],s[t+1],s[t+2],2*a):e=Z[h]=new Y(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++]=V(o,r/e*a*2,t/e*a*2);return{data:c,min:n,max:i,width:e,height:e}}(a,n);K(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=Q(X(t),n);K(i,e,n,t,!0,s)})))}})).catch((e=>{delete I[t],s({empty:!0,originalError:e})}))}function J(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 K(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(U(),!k)return;const{width:e,height:r,data:n}=t;if(e&&r&&n)try{let t=k.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]=J(e,x),o=4*t;i.data[o]=r,i.data[o+1]=s,i.data[o+2]=a,i.data[o+3]=255}return k.width=e,k.height=r,t=k.getContext("2d",{willReadFrequently:!0}),tt(t),t.putImageData(i,0,0),k.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 X(t){const{width:e,height:r}=t;return k||(k=new OffscreenCanvas(1,1),E=k.getContext("2d",{willReadFrequently:!0})),k.width=e,k.height=r,E.drawImage(t,0,0,e,r),E.getImageData(0,0,e,r)}function Q(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 tt(t){const e=t.canvas,{width:r,height:n}=e;t.clearRect(0,0,r,n)}function et(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||T)[0]===n&&r[1]===i||(n=r[0],i=r[1]),[n,i]=T;try{if(U(),!k)return;const r=k;r.width=n,r.height=i;const s=r.getContext("2d",{willReadFrequently:!0});tt(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);M[r]||(M[r]=new v(e));const n=M[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;if(h&&h.close){const t=Q(X(h),a);return void K(o,t,a,h,0,e)}const c=t.headers||D[i];if("tianditu"===i)$(r,c,i,a,o,e);else if("cesium-ion"===i){const h=t.cesiumIonTokenURL+s;z?$(r,c,i,a,o,e):(F||(F=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=>{z=t.accessToken,F=null}))),F.then((()=>{$(r,c,i,a,o,e)})))}else("cesium"===i||"mapbox"===i)&&$(r,c,i,a,o,e)}(r.params,((r,i)=>{const s=et(r,t,n);s&&(r.colorsTexture=s,(i=i||[]).push(s)),e(r.error,r,i)}))}else"abortTerrain"===r.command&&(n=r.params.url,I[n]&&(I[n].abort(),delete I[n]));var n}}`;
34052
+ /** @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};
34053
+ /*!
34054
+ * Contains code from THREE.JS
34055
+ * https://github.com/mrdoob/three.js/
34056
+ * License MIT
34057
+ *
34058
+ * Generate tangents per vertex.
34059
+ */
34060
+ 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}}`;
33907
34061
 
33908
34062
  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}
33909
34063
  /*!
@@ -33919,5 +34073,5 @@ maptalks.registerWorkerAdapter('maplight', code);
33919
34073
 
33920
34074
  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 };
33921
34075
 
33922
- typeof console !== 'undefined' && console.log('@maptalks/gpu v0.116.0');
34076
+ typeof console !== 'undefined' && console.log('@maptalks/gpu v0.117.1');
33923
34077
  //# sourceMappingURL=maptalksgpu.es.js.map