@maptalks/gpu 0.110.0 → 0.115.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.
- package/dist/maptalksgpu.d.ts +39 -15
- package/dist/maptalksgpu.es.js +459 -293
- package/dist/maptalksgpu.es.js.map +1 -1
- package/dist/maptalksgpu.js +14988 -4484
- package/dist/maptalksgpu.js.map +1 -1
- package/dist/transcoders.js +1 -1
- package/package.json +4 -4
package/dist/maptalksgpu.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/gpu v0.
|
|
2
|
+
* @maptalks/gpu v0.115.1
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2025 maptalks.com
|
|
5
5
|
*/
|
|
@@ -8,7 +8,7 @@ export { default as createREGL } from '@maptalks/regl';
|
|
|
8
8
|
import { mat4, vec3, vec4, mat3, vec2, quat, glMatrix, mat2, mat2d, quat2 } from 'gl-matrix';
|
|
9
9
|
export { mat2, mat2d, mat3, mat4, quat, quat2, vec2, vec3, vec4 } from 'gl-matrix';
|
|
10
10
|
import * as maptalks from 'maptalks';
|
|
11
|
-
import { Coordinate, Util as Util$1, Point, Polygon, Extent, Map as Map$1, renderer } from 'maptalks';
|
|
11
|
+
import { Coordinate, Util as Util$1, Point, Polygon, Extent, worker, Map as Map$1, renderer } from 'maptalks';
|
|
12
12
|
import { buildTangents, packTangentFrame, buildNormals } from '@maptalks/tbn-packer';
|
|
13
13
|
import { GLContext } from '@maptalks/fusiongl';
|
|
14
14
|
export { GLContext } from '@maptalks/fusiongl';
|
|
@@ -65,12 +65,12 @@ function registerGLTFLoaderBundle(fn) {
|
|
|
65
65
|
transcoders.registerTranscoder = registerTranscoder;
|
|
66
66
|
transcoders.getTranscoder = getTranscoder;
|
|
67
67
|
|
|
68
|
-
function gltfLoaderExport(
|
|
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.
|
|
70
|
+
* @maptalks/gltf-loader v0.115.1
|
|
71
71
|
* LICENSE : UNLICENSED
|
|
72
72
|
* (c) 2016-2025 maptalks.org
|
|
73
|
-
*/var n="undefined"!=typeof Float32Array?Float32Array:Array;function s(t,e,n){var s=e[0],r=e[1],i=e[2],o=e[3],h=e[4],u=e[5],c=e[6],a=e[7],f=e[8],l=e[9],d=e[10],m=e[11],p=e[12],w=e[13],y=e[14],g=e[15],b=n[0],_=n[1],A=n[2],x=n[3];return t[0]=b*s+_*h+A*f+x*p,t[1]=b*r+_*u+A*l+x*w,t[2]=b*i+_*c+A*d+x*y,t[3]=b*o+_*a+A*m+x*g,b=n[4],_=n[5],A=n[6],x=n[7],t[4]=b*s+_*h+A*f+x*p,t[5]=b*r+_*u+A*l+x*w,t[6]=b*i+_*c+A*d+x*y,t[7]=b*o+_*a+A*m+x*g,b=n[8],_=n[9],A=n[10],x=n[11],t[8]=b*s+_*h+A*f+x*p,t[9]=b*r+_*u+A*l+x*w,t[10]=b*i+_*c+A*d+x*y,t[11]=b*o+_*a+A*m+x*g,b=n[12],_=n[13],A=n[14],x=n[15],t[12]=b*s+_*h+A*f+x*p,t[13]=b*r+_*u+A*l+x*w,t[14]=b*i+_*c+A*d+x*y,t[15]=b*o+_*a+A*m+x*g,t}function r(){var t=new n(3);return n!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function i(t,e,s){var r=new n(3);return r[0]=t,r[1]=e,r[2]=s,r}function o(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function h(t,e,n,s){return t[0]=e,t[1]=n,t[2]=s,t}function u(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function c(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function a(t,e,n,s,r){return t[0]=e,t[1]=n,t[2]=s,t[3]=r,t}function f(t,e,n){var s=e[0],r=e[1],i=e[2],o=e[3];return t[0]=n[0]*s+n[4]*r+n[8]*i+n[12]*o,t[1]=n[1]*s+n[5]*r+n[9]*i+n[13]*o,t[2]=n[2]*s+n[6]*r+n[10]*i+n[14]*o,t[3]=n[3]*s+n[7]*r+n[11]*i+n[15]*o,t}function l(){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)}),r(),function(){var t;t=new n(4),n!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0);}();var d,m=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};r(),i(1,0,0),i(0,1,0),l(),l(),d=new n(9),n!=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 p=0;function w(t){return null==t}function y(t){return !w(t)}function g(t){return !w(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}function b(t){for(let e=1;e<arguments.length;e++){const n=arguments[e];for(const e in n)t[e]=n[e];}return t}function _(t){switch(t){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: "+t)}function A(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function x(t){const e=function(t){return "undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),n=e.length,s=new Uint8Array(n);for(let t=0;t<n;t++)s[t]=e.charCodeAt(t);return s.buffer}const T=[],M=[],I=[],E=[0,0,0],v=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}([]),P=[1,1,1];function O(t,e,n,s,r,i,o){const h=_(o),u=h.BYTES_PER_ELEMENT;if((0===r||r===s*u)&&i%u==0){const r=new h(e,i,n*s);return t.set(r),t}0===r&&(r=s*u);const c=new Uint8Array(s*u);for(let o=0;o<n;o++){let n=null;const a=new Uint8Array(e,r*o+i,s*u);c.set(a),n=new h(c.buffer,0,s);for(let e=0;e<s;e++)t[o*s+e]=n[e];}return t}const N="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function S(t,e,n){const s=new Uint8Array(t,e,n);return N.decode(s)}const B={get:function(t,e={},n){e||(e={});const s=new AbortController,r=s.signal,i=b({},e);i.signal=r,i.method||(i.method="GET"),i.referrerPolicy=i.referrerPolicy||"origin","undefined"==typeof window||i.referrer||(i.referrer=window.location.href),n&&(t=n(t));const o=fetch(t,i).then((t=>{const n=this.t(t,e.responseType);return n.message?n:n.then((n=>"arraybuffer"===e.responseType?{data:n,cacheControl:t.headers.get("Cache-Control"),expires:t.headers.get("Expires"),contentType:t.headers.get("Content-Type")}:n)).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 o.xhr=s,o},t:(t,e)=>200!==t.status?{status:t.status,statusText:t.statusText,message:`incorrect http request with status code(${t.status}): ${t.statusText}`}:"arraybuffer"===e?t.arrayBuffer():"json"===e?t.json():t.text(),getArrayBuffer:(t,e={},n)=>(e||(e={}),e.responseType="arraybuffer",B.get(t,e,n)),getJSON:function(t,e={},n){return e&&e.jsonp?B.jsonp(t):((e=e||{}).responseType="json",B.get(t,e,n))},jsonp:function(t){const e="_maptalks_jsonp_"+p++;t.match(/\?/)?t+="&callback="+e:t+="?callback="+e;let n=document.createElement("script");return n.type="text/javascript",n.src=t,new Promise((t=>{window[e]=function(s){document.getElementsByTagName("head")[0].removeChild(n),n=null,delete window[e],t(s);},document.getElementsByTagName("head")[0].appendChild(n);}))}};class R{constructor(t,e,n,s,r){this.i=t,this.decoders=e,this.o=n,this.images={},this.h={},this.u=s||{},this.l=r;}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const s=this.buffers[t.id],r=this.m(e,s);return this.getImageByBuffer(r,n)}if(this.h[t.id])return this.h[t.id].then((()=>{const s=this.buffers[t.id],r=this.m(e,s);return this.getImageByBuffer(r,n)}));if(A(t.uri)){const s=this.buffers[t.id]=x(t.uri),r=this.m(e,s);return this.getImageByBuffer(r,n)}let s;const r=t.uri.indexOf("blob:")>=0;return s=t.uri.indexOf("://")>0||r?t.uri:this.rootPath+"/"+t.uri,this.h[t.id]=B.getArrayBuffer(s,this.u,this.l).then((s=>{const r=this.buffers[t.id]=s.data,i=this.m(e,r);return this.getImageByBuffer(i,n)}))}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;if(n[e.mimeType])return n[e.mimeType](t,{supportedFormats:this.o});if("image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType)throw new Error("missing transcoder for "+e.mimeType,"");return this.p(e.id,t)}requestExternalImage(t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=0===t.uri.indexOf("data:image/")?t.uri:this.rootPath+"/"+t.uri;return this.h[t.id]?this.h[t.id].then((()=>this.images[t.id])):this.h[t.id]=this.p(t.id,e)}p(t,e){return new Promise(((n,s)=>{let r=e;this.l&&(r=this.l(e)),this.i(r,this.u,((r,i)=>{r?s(r):(URL.revokeObjectURL(e),this.images[t]=i,n(this.images[t]));}));}))}}const C=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],U=[];class k{constructor(t,e,n,s,r){this.rootPath=t,this.gltf=e,this._=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.A(),this.u=s,this.l=r;}T(t,e){const n=this.gltf,s=n.accessors[e];if(void 0===s.bufferView)return this.accessors[s.id]=this.M(t,e,null,0),Promise.resolve(this.accessors[s.id]);if(s&&this.accessors[s.id])return Promise.resolve(this.accessors[s.id]);const r=n.bufferViews[s.bufferView];return this.I(r).then((n=>{const{buffer:r,byteOffset:i}=n;return this.accessors[s.id]=this.M(t,e,r,i)}))}I(t){const e=this.gltf.buffers[t.buffer];if(this.buffers[e.id]){const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})}if(this.requests[e.id])return this.requests[e.id].then((()=>{const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})}));if("binary_glTF"!==t.buffer&&"KHR_binary_glTF"!==t.buffer&&e.uri){if(A(e.uri)){const t=this.buffers[e.id]=x(e.uri);return Promise.resolve({buffer:t,byteOffset:0})}let t;const n=e.uri.indexOf("blob:")>=0;return t=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri,this.requests[e.id]=B.getArrayBuffer(t,this.u,!n&&this.l).then((s=>(n&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=s.data,byteOffset:0})))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}M(t,e,n,s=0){const r=this.gltf,i=r.accessors[e],o=void 0!==i.bufferView?r.bufferViews[i.bufferView]:{},h=(o.byteOffset||0)+s,u=this.v(i.type),c=_(i.componentType),a=o.byteStride||0,l={array:void 0,name:t,accessorName:e,byteLength:i.count*u*c.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:u,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(l.min=i.min),i.max&&(l.max=i.max),n)if(this._)l.byteStride=a,l.byteOffset=h+(i.byteOffset||0),!a||a===u*c.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(l.array=this.P(n,i.count,u,h+(i.byteOffset||0),c),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(n,h,o.byteLength);else if(i.interleaved){l.byteStride=0,l.byteOffset=0;const t=new c(i.count*u);if(l.array=O(t,n,i.count,u,a,h+(i.byteOffset||0),i.componentType),l.extensions&&l.extensions.WEB3D_quantized_attributes&&u>2){const t=new Float32Array(l.array.length),{decodeMatrix:e}=l.extensions.WEB3D_quantized_attributes;for(let n=0;n<l.array.length;n+=u){U[0]=l.array[n],U[1]=l.array[n+1],U[2]=l.array[n+2],U[3]=1;const s=f(U,U,e);t[n]=s[0],t[n+1]=s[1],t[n+2]=s[2];}l.componentType=5126,l.array=t;}}else l.byteStride=0,l.array=this.P(n,i.count,u,h+(i.byteOffset||0),c),l.byteOffset=l.array.byteOffset;else {l.array=new c(i.count);const t=l.min||l.max;t&&(l.array[0]=t[0],l.array[1]=t[1],l.array[2]=t[2]);}return l}A(){const t=this.gltf.accessors;if(Array.isArray(t))for(let e=0;e<t.length;e++)for(let n=0;n<t.length;n++)e!==n&&t[e].bufferView===t[n].bufferView&&(t[e].interleaved=t[n].interleaved=!0);else for(const e in t)for(const n in t)e!==n&&t[e].bufferView===t[n].bufferView&&(t[e].interleaved=t[n].interleaved=!0);}P(t,e,n,s,r){return s%r.BYTES_PER_ELEMENT!=0&&(t=t.slice(s,s+e*n*r.BYTES_PER_ELEMENT),s=0),new r(t,s,n*e)}v(t){const e=C.indexOf(t);return C[e+1]}requestKHRTechniquesWebgl(t){const{shaders:e}=t,n=e.map((t=>{if(void 0!==t.bufferView){const e=this.gltf.bufferViews[t.bufferView],{byteLength:n}=e;return this.I(e).then((s=>{const{buffer:r,byteOffset:i}=s,o=S(r,i+(e.byteOffset||0),n);return t.content=o,t}))}if(t.uri){if(A(t.uri)){const e=x(t.uri),n=S(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return B.get(e,this.u,this.l).then((e=>(t.content=e,t)))}}return Promise.resolve(t)}));return Promise.all(n).then((()=>t))}}class L extends R{constructor(t,e,n,s,r,i,o,h){super(s,r,i,o,h),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new k(t,e,n,o,h);}iterate(t,e){const n=this.gltf[e];if(!n)return;let s=0;for(const e in n)t(e,n[e],s++);}createNode(t){const e={};if(y(t.name)&&(e.name=t.name),y(t.children)&&(e.children=t.children),y(t.jointName)&&(e.jointName=t.jointName),y(t.matrix)&&(e.matrix=t.matrix),y(t.rotation)&&(e.rotation=t.rotation),y(t.scale)&&(e.scale=t.scale),y(t.translation)&&(e.translation=t.translation),y(t.extras)&&(e.extras=t.extras),y(t.meshes)&&(e.mesh=t.meshes[0]),e.translation||e.rotation||e.scale){const t=function(t,e){if(e.matrix)return e.matrix;if(e.translation||e.scale||e.rotation){const n=function(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}(T,e.translation||E),r=function(t,e){var n=e[0],s=e[1],r=e[2],i=e[3],o=n+n,h=s+s,u=r+r,c=n*o,a=s*o,f=s*h,l=r*o,d=r*h,m=r*u,p=i*o,w=i*h,y=i*u;return t[0]=1-f-m,t[1]=a+y,t[2]=l-w,t[3]=0,t[4]=a-y,t[5]=1-c-m,t[6]=d+p,t[7]=0,t[8]=l+w,t[9]=d-p,t[10]=1-c-f,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(M,e.rotation||v),i=function(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(I,e.scale||P);return s(i,r,i),s(t,n,i)}return function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t;}return e}O(t){const e={};for(const n in t){const s=t[n];let r,i;s.instanceTechnique&&s.instanceTechnique.values?(r=s.instanceTechnique,i=r.values.diffuse):(r=s,i=r.values.tex||r.values.diffuseTex||r.values.diffuse);const o={baseColorTexture:{index:i}};s.name&&(o.name=s.name),s.extensions&&(o.extensions=s.extensions),s.extras&&(o.extras=s.extras),e[n]=o;}return e}N(t){if(t.bufferView||t.extensions&&(t.extensions.KHR_binary_glTF||t.extensions.binary_glTF)){const e=t.bufferView?t:t.extensions.KHR_binary_glTF||t.extensions.binary_glTF;t.extensions&&(t.mimeType=e.mimeType,t.width=e.width,t.height=e.height);const n=this.gltf.bufferViews[e.bufferView],s=(n.byteOffset||0)+this.glbBuffer.byteOffset,r=n.byteLength,i=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,s,r);return this.getImageByBuffer(i,t)}return this.requestExternalImage(t)}S(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.N(n).then((t=>{const s=this.gltf.samplers[e.sampler];return {image:{array:t.data,width:t.width,height:t.height,index:e.source,mimeType:n.mimeType,name:n.name,extras:n.extras},sampler:s}}))}getBaseColorTexture(t){const e=this.gltf.materials[t];let n,s;if(e.instanceTechnique&&e.instanceTechnique.values?(n=e.instanceTechnique,s=n.values.diffuse):(n=e,s=n.values.tex||n.values.diffuseTex||n.values.diffuse),void 0===s||void 0===this.gltf.textures)return null;const r=this.gltf.textures[s];if(!r)return null;const i=this.gltf.samplers[r.sampler];return {format:r.format||6408,internalFormat:r.internalFormat||6408,type:r.type||5121,sampler:i,source:this.gltf.images[r.source]}}getMaterial(){return null}getAnimations(){return null}}const q=9729;class F extends R{constructor(t,e,n,s,r,i,o,h){super(s,r,i,o,h),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new k(t,e,n,o,h);}iterate(t,e){const n=this.gltf[e];if(n)for(let e=0;e<n.length;e++)t(e,n[e],e);}createNode(t){const e={};return b(e,t),!y(t.weights)&&this.gltf.meshes&&y(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}S(t){const e=this.gltf.textures[t];if(!e)return null;let n=e.source;if(e.extensions&&e.extensions.EXT_texture_webp?n=e.extensions.EXT_texture_webp.source:e.extensions&&e.extensions.KHR_texture_basisu&&(n=e.extensions.KHR_texture_basisu.source),!y(n))return null;const s=this.gltf.images[n];return this.N(s).then((t=>{if(!t)return null;const n={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:s.mimeType,name:s.name,extensions:s.extensions,extras:s.extras}};b(n,e);const r=y(e.sampler)?this.gltf.samplers[e.sampler]:void 0;if(r&&(n.sampler=r,n.sampler.magFilter=r.magFilter||q,n.sampler.minFilter=r.minFilter||9987,n.sampler.wrapS=r.wrapS||10497,n.sampler.wrapT=r.wrapT||10497),"image/ktx2"===n.image.mimeType&&!n.image.mipmap&&n.sampler&&n.sampler.minFilter!==q&&9728!==n.sampler.minFilter){const t=n.sampler.minFilter;n.sampler.minFilter=9984===t||9986===t?9728:q;}return t.format&&(n.format=t.format),n}))}N(t){if(!y(t.bufferView))return this.requestExternalImage(t);{const e=this.gltf.bufferViews[t.bufferView],n=this.gltf.buffers[e.buffer];if(n.uri)return this.requestImageFromBufferURI(n,e,t);if(this.glbBuffer)return this.B(e,t)}return null}B(t,e){const n=this.m(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}m(t,e,n){n=n||0;const s=(t.byteOffset||0)+n,r=t.byteLength;return new Uint8Array(e,s,r)}R(t,e){const n=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)n[e]=String.fromCharCode(t[e]);n.join("");const s="data:"+(e=e||"image/png")+";base64,"+function(t){return "undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)));return s}getAnimations(t){const e=[];return t.forEach((t=>{e.push(this.getSamplers(t.samplers));})),Promise.all(e).then((e=>{for(let n=0;n<e.length;n++)t[n].samplers=e[n];return t}))}getSamplers(t){const e=[];for(let n=0;n<t.length;n++)(y(t[n].input)||y(t[n].output))&&(e.push(this.accessor.T("input",t[n].input)),e.push(this.accessor.T("output",t[n].output)));return Promise.all(e).then((e=>{for(let n=0;n<e.length/2;n++)t[n].input=e[2*n],t[n].output=e[2*n+1],t[n].interpolation||(t[n].interpolation="LINEAR");return t}))}}const D="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class V{static read(t,e=0,n=0){n||(n=t.byteLength);const s=new DataView(t,e,n),r=s.getUint32(4,!0);if(1===r)return V.readV1(s,e);if(2===r)return V.readV2(t,e);throw new Error("Unsupported glb version : "+r)}static readV1(t,e){const n=t.getUint32(8,!0),s=t.getUint32(12,!0);if(n!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const r=j(t.buffer,20+e,s);return {json:JSON.parse(r),glbBuffer:{byteOffset:20+e+s,buffer:t.buffer,byteLength:n}}}static readV2(t,e){let n,s,r;const i=new DataView(t,e+12);let o=0;for(;o+8<i.byteLength;){const h=i.getUint32(o,!0);o+=4;const u=i.getUint32(o,!0);if(o+=4,1313821514===u)n=j(t,e+12+o,h);else if(5130562===u){r=e+12+o,s=h;break}o+=h;}return {json:JSON.parse(n),glbBuffer:{byteOffset:r,buffer:t,byteLength:s}}}}function j(t,e,n){if(D){const s=new Uint8Array(t,e,n);return D.decode(s)}return function(t){const e=t.length;let n="";for(let s=0;s<e;){let r=t[s++];if(128&r){let n=K[r>>3&7];if(!(64&r)||!n||s+n>e)return null;for(r&=63>>n;n>0;n-=1){const e=t[s++];if(128!=(192&e))return null;r=r<<6|63&e;}}n+=String.fromCharCode(r);}return n}(new Uint8Array(t,e,n))}const K=[1,1,1,1,2,2,3,0],H=[0,0,0],X=[0,0,0,1],$=[1,1,1],z={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},G={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},J={C(t,e,n,s,r,i,h,u){const c=y(t)?e.animations:[e.animations[0]],a={};for(let e=0;e<c.length;e++){const f=c[e],l=f.name||e;if(y(t)&&l!==t)continue;const d=f.channelsMap[n];if(d)for(let t=0;t<d.length;t++){const e=d[t];"translation"===e.target.path?(this.U(r,f.samplers[e.sampler],s,1),a.translation=o(H,r)):"rotation"===e.target.path?(this.k(i,f.samplers[e.sampler],s,1),a.rotation=m(X,i)):"scale"===e.target.path?(this.U(h,f.samplers[e.sampler],s,1),a.scale=o($,h)):"weights"===e.target.path&&u&&(this.U(u,f.samplers[e.sampler],s,u.length),a.weights=u);}}return a},U(t,e,n,s){switch(e.interpolation){case"LINEAR":{const r=this.L(G,e,n,1*s);r&&(t=function(t,e,n,s){for(let r=0;r<t.length;r++)t[r]=e[r]+s*(n[r]-e[r]);return t}(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION));break}case"STEP":{const r=this.L(G,e,n,1*s);r&&(t=function(t,e){for(let n=0;n<t.length;n++)t[n]=e[n];return t}(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.L(G,e,n,3*s);r&&(t=this.q(t,r,e.input.array,3*s));break}}return t},k(t,e,n){switch(e.interpolation){case"LINEAR":{const s=this.L(G,e,n,1);s&&function(t,e,n,s){var r,i,o,h,u,c=e[0],a=e[1],f=e[2],l=e[3],d=n[0],m=n[1],p=n[2],w=n[3];(i=c*d+a*m+f*p+l*w)<0&&(i=-i,d=-d,m=-m,p=-p,w=-w),1-i>1e-6?(r=Math.acos(i),o=Math.sin(r),h=Math.sin((1-s)*r)/o,u=Math.sin(s*r)/o):(h=1-s,u=s),t[0]=h*c+u*d,t[1]=h*a+u*m,t[2]=h*f+u*p,t[3]=h*l+u*w;}(t,s.PREVIOUS,s.NEXT,s.INTERPOLATION);break}case"STEP":{const s=this.L(G,e,n,1);s&&(t=a(t,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.L(G,e,n,3);if(s){for(let t=0;t<s.PREVIOUS.length;t++)s.PREVIOUS[t]=Math.acos(s.PREVIOUS[t]),s.NEXT[t]=Math.acos(s.NEXT[t]);t=this.q(t,s,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e]);}break}}return t},F(t,e){const n=t.length;let s,r,i,o=0,h=n-1,u=Math.floor((o+h)/2);for(;o<=n-1&&h>=0;){if(o===h)return null;if(t[u]<=e&&e<=t[u+1]){const n=t[u];return s=u,r=u+1,i=(e-n)/(t[u+1]-n),{preIndx:s,nextIndex:r,interpolation:i}}e<t[u]?(h=u,u=Math.floor((o+h)/2)):t[u+1]<e&&(o=u,u=Math.floor((o+h)/2));}return null},L(t,e,n,s){const r=e.input.array,i=e.output.array,o=e.output.itemSize;(n<r[0]||n>r[r.length-1])&&(n=Math.max(r[0],Math.min(r[r.length-1],n))),n===r[r.length-1]&&(n=r[0]);const h=this.F(r,n);if(!h||!h.nextIndex)return null;const{preIndx:u,nextIndex:c,interpolation:a}=h;t.PREINDEX=u,t.NEXTINDEX=c,t.INTERPOLATION=a;const f=o*s;return t.PREVIOUS=i.subarray(t.PREINDEX*f,(t.PREINDEX+1)*f),t.NEXT=i.subarray(t.NEXTINDEX*f,(t.NEXTINDEX+1)*f),t},q(t,e,n,s){const r=e.INTERPOLATION,i=n[e.PREINDEX],o=n[e.NEXTINDEX];for(let n=0;n<3;n++){const h=e.PREVIOUS[s+n],u=(o-i)*e.PREVIOUS[2*s+n],c=e.NEXT[3+n],a=(o-i)*e.NEXT[n],f=(2*Math.pow(r,3)-3*Math.pow(r,2)+1)*h+(Math.pow(r,3)-2*Math.pow(r,2)+r)*u+(2*-Math.pow(r,3)+3*Math.pow(r,2))*c+(Math.pow(r,3)-Math.pow(r,2))*a;t[n]=f;}return t},getAnimationClip(t,e,n,s){const r=t.nodes[e]&&t.nodes[e].weights;return h(H,...z.TRANSLATION),a(X,...z.ROTATION),h($,...z.SCALE),this.C(s,t,e,n,H,X,$,r)},getTimeSpan(t){if(!t.animations)return null;if(t.timeSpan)return t.timeSpan;const e=t.animations;return t.timeSpan={},e.forEach(((e,n)=>{let s=-1/0,r=1/0;const i=e.channels;for(let t=0;t<i.length;t++){const n=i[t],o=e.samplers[n.sampler].input.array;o[o.length-1]>s&&(s=o[o.length-1]),o[0]<r&&(r=o[0]);}const o=e.name||n;t.timeSpan[o]={max:s,min:r};})),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?y(e)?n[e]:n[Object.keys(n)[0]]:null}};let W=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d");}catch(n){}t&&"undefined"!=typeof createImageBitmap&&(W=!0);}const Q="undefined"==typeof document?null:document.createElement("canvas");function Y(t,e,n){const s=new Image;s.crossOrigin="",s.onload=()=>{if(!Q)return void n(new Error("There is no canvas to draw image!"));Q.width=s.width,Q.height=s.height;const t=Q.getContext("2d",{willReadFrequently:!0});t.drawImage(s,0,0,s.width,s.height);const e=t.getImageData(0,0,s.width,s.height),r={width:s.width,height:s.height,data:new Uint8Array(e.data)};n(null,r);},s.onerror=function(t){n(t);},s.src=t;}const Z=[],tt=[],et=30;let nt,st;function rt(t,e,n){nt||(nt=new OffscreenCanvas(2,2),st=nt.getContext("2d",{willReadFrequently:!0}));let s=null;if(g(t))this.options.urlModifier&&(t=this.options.urlModifier(t)),Z.push([t,e,n,this]),it();else {const e=new Blob([t]);s=createImageBitmap(e),s.then(ot.bind(this)).then((t=>{n(null,t);})).catch((t=>{console.warn(t),n(t);}));}}function it(){if(!Z.length||tt.length>et)return;const t=Z.shift(),[e,n,s,r]=t;tt.push(t),fetch(e,n).then((t=>t.arrayBuffer())).then((t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)})).then(ot.bind(r)).then((e=>{s.call(r,null,e);const n=tt.indexOf(t);tt.splice(n,1),it();})).catch((e=>{console.warn(e),s.call(r,e);const n=tt.indexOf(t);tt.splice(n,1),it();}));}function ot(t){let{width:e,height:n}=t;ht(e)||(e=ut(e)),ht(n)||(n=ut(n));const s=this.options.maxTextureSize;s&&(e=Math.min(s,e),n=Math.min(s,n)),nt.width=e,nt.height=n,st.drawImage(t,0,0,e,n),t.close();const r=st.getImageData(0,0,e,n);return {width:e,height:n,data:new Uint8Array(r.data)}}function ht(t){return !(t&t-1)&&0!==t}function ut(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function ct(t,e){for(const n in t)if(t[n]===e)return n;return e}t.Ajax=B,t.GLTFLoader=class{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),this.u=this.options.fetchOptions||{},e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:s}=V.read(e.buffer,e.byteOffset,e.byteLength);this.D(t,n,s);}else this.D(t,e);this.V=new k(this.rootPath,this.gltf,this.glbBuffer,this.u,this.options.urlModifier),this.j();}j(){const t=this.gltf.extensionsRequired;if(t){if(t.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(t.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(t.indexOf("EXT_meshopt_compression")>=0)throw new Error("EXT_meshopt_compression extension is not supported yet.")}}K(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.V.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then((e=>(t.KHR_techniques_webgl=e,t))):Promise.resolve(t)}H(){if(!Array.isArray(this.gltf.programs))return;const t=this.gltf.materials;for(let e=0;e<t.length;e++)t[e]&&t[e].extensions&&t[e].extensions.KHR_technique_webgl&&(t[e].extensions.KHR_techniques_webgl=t[e].extensions.KHR_technique_webgl,delete t[e].extensions.KHR_technique_webgl);const e=this.gltf.extensions||{},n=this.gltf.techniques;e.KHR_techniques_webgl={programs:this.gltf.programs,shaders:this.gltf.shaders,techniques:n};for(let e=0;e<t.length;e++){const r=(s=t[e])&&s.extensions&&s.extensions.KHR_techniques_webgl;if(r){const{values:t,technique:e}=r,s=n[e];if(!s||!t)continue;const{uniforms:i,parameters:o}=s,h={};for(const e in t){const n=ct(i,e);h[n]=t[e],o[e]&&35678===o[e].type&&(h[n]={index:t[e]});}r.values=h;}}var s;for(let t=0;t<n.length;t++){const e=n[t];if(!e)continue;const{attributes:s,uniforms:r,parameters:i}=e;if(s)for(const t in s){const e=s[t];s[t]=i[e];}if(r)for(const t in r){const e=r[t];r[t]=i[e];}delete e.parameters;}return delete this.gltf.programs,delete this.gltf.shaders,delete this.gltf.techniques,this.gltf.extensions=e,e}load(t){t=t||{},this.H();const e=this.X(t),n=this.$(),s=this.G(),r=this.K();return Promise.all([e,n,s,r]).then((t=>(t[0].animations=t[1],t[0].textures=t[2],t[0].extensions=t[3],t[0].transferables=this.transferables||[],this.createChannelsMap(t[0]),t[0])))}createChannelsMap(t){const e=t.animations;if(e)for(let t=0;t<e.length;t++){const n=e[t];n.channelsMap={};for(let t=0;t<n.channels.length;t++){const e=n.channels[t];n.channelsMap[e.target.node]||(n.channelsMap[e.target.node]=[]),n.channelsMap[e.target.node].push(e);}}}getExternalResources(){const t=[];if(this.gltf){const{buffers:e,images:n}=this.gltf;for(let n=0;n<e.length;n++)e[n].uri&&e[n].uri.indexOf("data:application/octet-stream;base64")<0&&t.push({type:"buffer",uri:e[n].uri});for(let e=0;e<n.length;e++)n[e].uri&&n[e].uri.indexOf("data:image/")<0&&t.push({type:"image",uri:n[e].uri});}return t}static getAnimationClip(t,e,n,s){return J.getAnimationClip(t,e,n,s)}static getAnimationTimeSpan(t,e){return J.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return _(t)}static readInterleavedArray(t,e,n,s,r,i,o){return O(t,e,n,s,r,i,o)}D(t,e,n){this.gltf=e,this.glbBuffer=n,this.version=e.asset?+e.asset.version:1,this.rootPath=t,this.buffers={},this.requests={},this.options.requestImage=W?rt.bind(this):this.options.requestImage||Y,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new F(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.u,this.options.urlModifier),this.adapter.iterate(((t,e,n)=>{e.id="buffer_"+n;}),"buffers"),this.adapter.iterate(((t,e,n)=>{e.id="image_"+n;}),"images"),this.adapter.iterate(((t,e,n)=>{e.id="accessor_"+n;}),"accessors")):(this.adapter=new L(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.u,this.options.urlModifier),this.adapter.iterate(((t,e,n)=>{e.id="accessor_"+n;}),"accessors"),this.adapter.iterate(((t,e,n)=>{e.id="image_"+n;}),"images"));}J(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||g(t.children[0])))return t;const s=t.children.map((t=>{const n=e[t];return n.nodeIndex=t,this.J(n,e)}));t.children=s;}var n;return t}X(t){return this.W(t).then((t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.J(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate(((s,r,i)=>{const o={};r.name&&(o.name=r.name),r.nodes&&(o.nodes=r.nodes.map((e=>t[e]))),this.gltf.scene===s&&(n=i),e.push(o);}),"scenes");const s={textures:this.gltf.textures,asset:this.gltf.asset,scene:n,scenes:e,nodes:t,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(s.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.O(this.gltf.materials);s.materials=t;}return delete this.gltf.buffers,s.json=this.gltf,s}))}W(t){return this.Y(t).then((()=>{const t=this.nodes={};return this.adapter.iterate(((e,n)=>{const s=this.adapter.createNode(n,this.meshes,this.skins);t[e]=s;}),"nodes"),t}))}Z(){this.skins=[];const t=[];return this.adapter.iterate(((e,n,s)=>{t.push(this.tt(n).then((t=>{t.index=s,this.skins.push(t);})));}),"skins"),t}tt(t){const e=t.inverseBindMatrices;return this.adapter.accessor.T("inverseBindMatrices",e).then((e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t)))}$(){const t=this.gltf.animations;return y(t)?this.adapter.getAnimations(t):null}Y(t){this.meshes={};let e=[];return this.adapter.iterate(((n,s,r)=>{e.push(this.et(s,t).then((t=>{t.index=r,this.meshes[n]=t;})));}),"meshes"),e=e.concat(this.Z()),Promise.all(e)}et(t,e){const n=t.primitives.map((t=>this.nt(t,e))).filter((t=>!!t));return Promise.all(n).then((e=>{const n={};return b(n,t),n.primitives=e,n}))}G(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const n in t)e.push(this.adapter.S(n));return Promise.all(e).then((e=>{if(this.transferables)for(let t=0;t<e.length;t++){const n=e[t]&&e[t].image.array;if(n){let t;t=n instanceof ImageBitmap?n:n.buffer,t&&this.transferables.indexOf(t)<0&&this.transferables.push(t);}}if(!Array.isArray(t)){const n={},s=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(n[s[t]]=e[t]);return n}return e}))}nt(t,e){let n;const s=[],r=t.extensions;if(y(t.targets))for(let e=0;e<t.targets.length;e++){const n=t.targets[e];for(const t in n){const r=this.adapter.accessor.T(`morphTargets_${t}_${e}`,n[t]);r&&s.push(r);}}if(r&&r.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const t=this.options.decoders.draco,{bufferView:i,attributes:o}=r.KHR_draco_mesh_compression,h=this.gltf.bufferViews[i],u=this.V.I(h).then((n=>{const{buffer:s,byteOffset:r}=n;let{byteOffset:i}=h;const u=h.byteLength;i||(i=0);const c=new DataView(s,r+i,u),a={attributes:o,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(c,a).then((t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e}))}));s.push(u),n=Promise.all(s);}else {const e=t.attributes;for(const t in e){const n=this.adapter.accessor.T(t,e[t]);n&&s.push(n);}if(y(t.indices)){const e=this.adapter.accessor.T("indices",t.indices);e&&s.push(e);}n=Promise.all(s);}return n.then((e=>{if(r&&r.KHR_draco_mesh_compression){const n=t.targets?t.targets.length:0;e[n]=e[n].concat(e.slice(0,n)),e=e[n];}let n,s;const i={attributes:e.reduce(((t,e)=>{if("indices"===e.name)n=e;else if(e.name.indexOf("morphTargets_")>-1)s=s||{},s[e.name.slice(13)]=e;else {if(!("POSITION"!==e.name||e.min&&e.max)){const t=[1/0,1/0,1/0],n=[-1/0,-1/0,-1/0],{itemSize:s,array:r}=e,i=r.length/s;for(let e=0;e<i;e++)for(let i=0;i<s;i++){const o=e*s+i;r[o]<t[i]&&(t[i]=r[o]),r[o]>n[i]&&(n[i]=r[o]);}if(e.quantization){const s=e.quantization,r=s.range/(1<<s.quantizationBits),i=s.minValues;c(t,t,r),u(t,t,i),c(n,n,r),u(n,n,i);}e.min=t,e.max=n;}t[e.name]=e;}return this.transferables&&e.array.buffer&&this.transferables.indexOf(e.array.buffer)<0&&this.transferables.push(e.array.buffer),t}),{}),material:t.material};return n&&(i.indices=n),s&&(i.morphTargets=s),i.mode=y(t.mode)?t.mode:4,y(t.extras)&&(i.extras=t.extras),i}))}},e().maptalks_gltf_loader=t;}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;}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({});
|
|
74
74
|
|
|
75
75
|
const getGlobal = function () {
|
|
76
76
|
if (typeof globalThis !== 'undefined') {
|
|
@@ -10808,22 +10808,20 @@ fn encodeFloat32(f: f32) -> vec4f {
|
|
|
10808
10808
|
Exponent = floor(log2(F) + 127.0) + floor(log2(Mantissa));
|
|
10809
10809
|
var rgba = vec4(0.0);
|
|
10810
10810
|
rgba[0] = 128.0 * Sign + floor(Exponent*exp2(-1.0));
|
|
10811
|
-
rgba[1] = 128.0 *
|
|
10812
|
-
rgba[2] = floor(
|
|
10813
|
-
rgba[3] = floor(exp2(23.0)*
|
|
10811
|
+
rgba[1] = 128.0 * (Exponent % 2.0) + (floor(Mantissa*128.0) % 128.0);
|
|
10812
|
+
rgba[2] = floor((floor(Mantissa*exp2(23.0 -8.0)) % exp2(8.0)));
|
|
10813
|
+
rgba[3] = floor(exp2(23.0)*(Mantissa % exp2(-15.0)));
|
|
10814
10814
|
return rgba / 255.0;
|
|
10815
10815
|
}
|
|
10816
10816
|
|
|
10817
|
-
fn decodeFloat32(
|
|
10818
|
-
rgba
|
|
10817
|
+
fn decodeFloat32(inputRgba: vec4f) -> f32 {
|
|
10818
|
+
var rgba = inputRgba * 255.0;
|
|
10819
10819
|
var Sign = 1.0 - step(128.0,rgba[0])*2.0;
|
|
10820
|
-
var Exponent = 2.0 *
|
|
10821
|
-
var Mantissa =
|
|
10820
|
+
var Exponent = 2.0 * (rgba[0] % 128.0) + step(128.0,rgba[1]) - 127.0;
|
|
10821
|
+
var Mantissa = (rgba[1] % 128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + 0x800000;
|
|
10822
10822
|
var Result = Sign * exp2(Exponent) * (Mantissa * exp2(-23.0 ));
|
|
10823
10823
|
return Result;
|
|
10824
10824
|
}
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
10825
|
`;
|
|
10828
10826
|
const frag$n = vert$f;
|
|
10829
10827
|
var common_pack_float = {
|
|
@@ -11395,8 +11393,8 @@ class PipelineDescriptor {
|
|
|
11395
11393
|
}
|
|
11396
11394
|
this.depthBias = depthBias;
|
|
11397
11395
|
this.depthBiasSlopeScale = depthBiasSlopeScale;
|
|
11398
|
-
let depthCompare = '
|
|
11399
|
-
let depthWriteEnable =
|
|
11396
|
+
let depthCompare = 'always';
|
|
11397
|
+
let depthWriteEnable = false;
|
|
11400
11398
|
const depthProps = commandProps.depth;
|
|
11401
11399
|
if (depthEnabled && depthProps && isEnable(depthProps.enable, uniformValues)) {
|
|
11402
11400
|
if (depthProps.func) {
|
|
@@ -11421,14 +11419,16 @@ class PipelineDescriptor {
|
|
|
11421
11419
|
}
|
|
11422
11420
|
this.depthCompare = depthCompare;
|
|
11423
11421
|
this.depthWriteEnabled = depthWriteEnable;
|
|
11424
|
-
let stencilFrontCompare
|
|
11422
|
+
let stencilFrontCompare = 'always';
|
|
11423
|
+
let stencilFrontPassOp = 'keep';
|
|
11425
11424
|
const stencilProps = commandProps.stencil;
|
|
11426
11425
|
if (stencilEnabled && stencilProps && isEnable(stencilProps.enable, uniformValues)) {
|
|
11427
11426
|
if (stencilProps.op) {
|
|
11428
11427
|
// 目前还没遇到op是函数的情况,所以可以直接读取
|
|
11429
11428
|
stencilFrontPassOp = stencilProps.op.zpass;
|
|
11430
11429
|
if (isFunction$1(stencilFrontPassOp)) {
|
|
11431
|
-
|
|
11430
|
+
const stencilFrontPassOpFn = stencilFrontPassOp;
|
|
11431
|
+
stencilFrontPassOp = stencilFrontPassOpFn(null, uniformValues);
|
|
11432
11432
|
this.functionProps.push({ func: stencilProps.op.zpass, v: stencilFrontPassOp });
|
|
11433
11433
|
}
|
|
11434
11434
|
}
|
|
@@ -11570,6 +11570,7 @@ function isEnable(enable, props) {
|
|
|
11570
11570
|
return !!enable;
|
|
11571
11571
|
}
|
|
11572
11572
|
|
|
11573
|
+
let arrayBuffer = new ArrayBuffer(1024 * 1024 * 4);
|
|
11573
11574
|
class GraphicsTexture {
|
|
11574
11575
|
constructor(device, config) {
|
|
11575
11576
|
//@internal
|
|
@@ -11577,7 +11578,7 @@ class GraphicsTexture {
|
|
|
11577
11578
|
this.device = device;
|
|
11578
11579
|
this.config = config;
|
|
11579
11580
|
this.gpuFormat = toTextureFormat(config.format, config.type);
|
|
11580
|
-
this.
|
|
11581
|
+
this._updateTexture();
|
|
11581
11582
|
}
|
|
11582
11583
|
get width() {
|
|
11583
11584
|
return this.texture && this.texture.width || this.config && this.config.width;
|
|
@@ -11603,9 +11604,15 @@ class GraphicsTexture {
|
|
|
11603
11604
|
}
|
|
11604
11605
|
this.config.width = width;
|
|
11605
11606
|
this.config.height = height;
|
|
11606
|
-
this.
|
|
11607
|
+
this._updateTexture();
|
|
11607
11608
|
}
|
|
11608
11609
|
update(config) {
|
|
11610
|
+
extend$1(this.config, config);
|
|
11611
|
+
this.gpuFormat = toTextureFormat(this.config.format, this.config.type);
|
|
11612
|
+
this._updateTexture();
|
|
11613
|
+
}
|
|
11614
|
+
_updateTexture() {
|
|
11615
|
+
const config = this.config;
|
|
11609
11616
|
const device = this.device.wgpu;
|
|
11610
11617
|
if (this.texture) {
|
|
11611
11618
|
this.texture.destroy();
|
|
@@ -11644,16 +11651,55 @@ class GraphicsTexture {
|
|
|
11644
11651
|
texture = device.createTexture(options);
|
|
11645
11652
|
if (config.data) {
|
|
11646
11653
|
if (isArray(config.data)) {
|
|
11647
|
-
|
|
11648
|
-
|
|
11649
|
-
|
|
11654
|
+
const data = config.data;
|
|
11655
|
+
const isUint8 = !config.type || config.type === 'uint8';
|
|
11656
|
+
let byteLength;
|
|
11657
|
+
if (Array.isArray(data)) {
|
|
11658
|
+
byteLength = isUint8 ? data.length : data.length * 4;
|
|
11659
|
+
}
|
|
11660
|
+
else {
|
|
11661
|
+
byteLength = data.byteLength;
|
|
11662
|
+
}
|
|
11663
|
+
const isRGBA = !config.format || config.format === 'rgba';
|
|
11664
|
+
const isPremultipliedAlpha = isRGBA && config.premultiplyAlpha;
|
|
11665
|
+
let dataToWrite;
|
|
11666
|
+
if (isPremultipliedAlpha || Array.isArray(data)) {
|
|
11667
|
+
if (arrayBuffer.byteLength < byteLength) {
|
|
11668
|
+
arrayBuffer = new ArrayBuffer(byteLength);
|
|
11669
|
+
}
|
|
11670
|
+
if (isUint8) {
|
|
11671
|
+
dataToWrite = new Uint8Array(arrayBuffer, 0, byteLength);
|
|
11672
|
+
}
|
|
11673
|
+
else {
|
|
11674
|
+
dataToWrite = new Float32Array(arrayBuffer, 0, byteLength / 4);
|
|
11675
|
+
}
|
|
11650
11676
|
}
|
|
11651
|
-
|
|
11677
|
+
if (isPremultipliedAlpha) {
|
|
11678
|
+
const ratio = isUint8 ? 255 : 1;
|
|
11679
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
11680
|
+
const alpha = data[i + 3] / ratio;
|
|
11681
|
+
dataToWrite[i] = data[i] * alpha;
|
|
11682
|
+
dataToWrite[i + 1] = data[i + 1] * alpha;
|
|
11683
|
+
dataToWrite[i + 2] = data[i + 2] * alpha;
|
|
11684
|
+
dataToWrite[i + 3] = data[i + 3];
|
|
11685
|
+
}
|
|
11686
|
+
}
|
|
11687
|
+
else {
|
|
11688
|
+
if (Array.isArray(data)) {
|
|
11689
|
+
for (let i = 0; i < data.length; i++) {
|
|
11690
|
+
dataToWrite[i] = data[i];
|
|
11691
|
+
}
|
|
11692
|
+
}
|
|
11693
|
+
else {
|
|
11694
|
+
dataToWrite = data;
|
|
11695
|
+
}
|
|
11696
|
+
}
|
|
11697
|
+
device.queue.writeTexture({ texture: texture }, dataToWrite.buffer, {
|
|
11652
11698
|
bytesPerRow: width * this.gpuFormat.bytesPerTexel
|
|
11653
11699
|
}, [width, height]);
|
|
11654
11700
|
}
|
|
11655
11701
|
else {
|
|
11656
|
-
device.queue.copyExternalImageToTexture({ source: config.data, flipY: !!this.config.flipY }, { texture: texture, premultipliedAlpha:
|
|
11702
|
+
device.queue.copyExternalImageToTexture({ source: config.data, flipY: !!this.config.flipY }, { texture: texture, premultipliedAlpha: !!this.config.premultiplyAlpha }, [width, height]);
|
|
11657
11703
|
}
|
|
11658
11704
|
}
|
|
11659
11705
|
}
|
|
@@ -12561,7 +12607,7 @@ class CommandBuilder {
|
|
|
12561
12607
|
],
|
|
12562
12608
|
};
|
|
12563
12609
|
}
|
|
12564
|
-
if (pipelineDesc.stencilFrontCompare) {
|
|
12610
|
+
if (pipelineOptions.depthStencil && pipelineDesc.stencilFrontCompare) {
|
|
12565
12611
|
pipelineOptions.depthStencil.stencilBack =
|
|
12566
12612
|
pipelineOptions.depthStencil.stencilFront = {
|
|
12567
12613
|
compare: pipelineDesc.stencilFrontCompare,
|
|
@@ -13601,7 +13647,7 @@ class BoxBlurShader extends QuadShader {
|
|
|
13601
13647
|
|
|
13602
13648
|
var vert$b = "#include <gl2_vert>\nattribute vec2 aPosition;\nattribute vec2 aTexCoord;\nuniform mat4 projViewModelMatrix;\nvarying vec2 vTexCoord;\nvoid main() {\n gl_Position = projViewModelMatrix * vec4(aPosition, 0., 1.);\n vTexCoord = aTexCoord;\n}";
|
|
13603
13649
|
|
|
13604
|
-
var frag$f = "precision mediump float;\n#include <gl2_frag>\nuniform sampler2D baseColorTexture;\nuniform float opacity;\nuniform vec4 baseColor;\nuniform float alphaTest;\n#ifdef HAS_DEBUG\nuniform sampler2D debugTexture;\n#endif\nvarying vec2 vTexCoord;\nvoid main() {\n
|
|
13650
|
+
var frag$f = "precision mediump float;\n#include <gl2_frag>\nuniform sampler2D baseColorTexture;\nuniform float opacity;\nuniform vec4 baseColor;\nuniform float alphaTest;\n#ifdef HAS_DEBUG\nuniform sampler2D debugTexture;\n#endif\nvarying vec2 vTexCoord;\nvoid main() {\n glFragColor = texture2D(baseColorTexture, vTexCoord);\n glFragColor *= baseColor;\n#ifdef HAS_DEBUG\nvec4 c = texture2D(debugTexture, vTexCoord);\n glFragColor = vec4(c.rgb + glFragColor.rgb * (1. - c.a), c.a + glFragColor.a * (1. - c.a));\n#endif\nif(glFragColor.a < alphaTest) {\n discard;\n }\n glFragColor *= opacity;\n#if __VERSION__ == 100\ngl_FragColor = glFragColor;\n#endif\n}";
|
|
13605
13651
|
|
|
13606
13652
|
var wgslVert$2 = "struct Uniforms {\n projViewModelMatrix : mat4x4f\n}\n@group(0) @binding(0) var<uniform> uniforms : Uniforms;\nstruct VertexOutput {\n @builtin(position) Position : vec4f,\n @location(0) vTexCoord : vec2f\n}\n@vertex\nfn main(\n @location(0) aPosition : vec2i,\n @location(1) aTexCoord : vec2u\n) -> VertexOutput {\n var output : VertexOutput;\n output.Position = uniforms.projViewModelMatrix * vec4f(vec2f(aPosition), 0.0, 1.0);\n output.vTexCoord = vec2f(aTexCoord);\n return output;\n}";
|
|
13607
13653
|
|
|
@@ -16839,7 +16885,7 @@ const normalTransform = {
|
|
|
16839
16885
|
const targets = ['px', 'nx', 'py', 'ny', 'pz', 'nz'];
|
|
16840
16886
|
|
|
16841
16887
|
// Project on cpu.
|
|
16842
|
-
function projectEnvironmentMapCPU(cubePixels, width, height) {
|
|
16888
|
+
function projectEnvironmentMapCPU$1(cubePixels, width, height) {
|
|
16843
16889
|
const coeff = new Array(9);
|
|
16844
16890
|
const normal = [];
|
|
16845
16891
|
const texel = [];
|
|
@@ -16933,6 +16979,20 @@ const skyboxFrag = ShaderLib.compile(skyboxRawFrag);
|
|
|
16933
16979
|
* @param config - config
|
|
16934
16980
|
*/
|
|
16935
16981
|
function createIBLMaps(regl, config = {}) {
|
|
16982
|
+
return _createIBLMaps(regl, config);
|
|
16983
|
+
|
|
16984
|
+
}
|
|
16985
|
+
|
|
16986
|
+
function createIBLMapsAsync(regl, config = {}) {
|
|
16987
|
+
return new Promise((resolve) => {
|
|
16988
|
+
_createIBLMaps(regl, config, (maps) => {
|
|
16989
|
+
maps.updateTime = config.updateTime;
|
|
16990
|
+
resolve(maps);
|
|
16991
|
+
});
|
|
16992
|
+
});
|
|
16993
|
+
}
|
|
16994
|
+
|
|
16995
|
+
function _createIBLMaps(regl, config = {}, callback) {
|
|
16936
16996
|
regl = getREGL(regl);
|
|
16937
16997
|
// config values
|
|
16938
16998
|
|
|
@@ -16981,55 +17041,74 @@ function createIBLMaps(regl, config = {}) {
|
|
|
16981
17041
|
// cube.destroy();
|
|
16982
17042
|
// }
|
|
16983
17043
|
// const lod = regl.hasExtension('EXT_shader_texture_lod') ? '1.0' : undefined;
|
|
17044
|
+
const flat = (shList) => {
|
|
17045
|
+
const flatten = [];
|
|
17046
|
+
for (let i = 0; i < shList.length; i++) {
|
|
17047
|
+
flatten.push(...shList[i]);
|
|
17048
|
+
}
|
|
17049
|
+
return flatten;
|
|
17050
|
+
};
|
|
16984
17051
|
const faces = getEnvmapPixels(regl, prefilterMap, size, false, config.environmentExposure, true);
|
|
16985
|
-
|
|
16986
|
-
|
|
16987
|
-
|
|
16988
|
-
|
|
17052
|
+
const { projectEnvironmentMapCPU } = config;
|
|
17053
|
+
if (projectEnvironmentMapCPU) {
|
|
17054
|
+
projectEnvironmentMapCPU({ cubePixels: faces, width: size, height: size }, (shList) => {
|
|
17055
|
+
sh = flat(shList);
|
|
17056
|
+
callback(createMap());
|
|
17057
|
+
});
|
|
17058
|
+
return;
|
|
16989
17059
|
}
|
|
16990
|
-
sh =
|
|
17060
|
+
sh = projectEnvironmentMapCPU$1(faces, size, size);
|
|
17061
|
+
|
|
17062
|
+
sh = flat(sh);
|
|
16991
17063
|
// cubeMap.destroy();
|
|
16992
17064
|
}
|
|
16993
17065
|
|
|
16994
17066
|
// const irradianceMap = createIrradianceCube(regl, envMap, irradianceCubeSize);
|
|
16995
17067
|
|
|
16996
|
-
|
|
16997
|
-
|
|
16998
|
-
|
|
16999
|
-
|
|
17000
|
-
|
|
17001
|
-
|
|
17068
|
+
function createMap() {
|
|
17069
|
+
const maps = {
|
|
17070
|
+
envMap,
|
|
17071
|
+
isHDR,
|
|
17072
|
+
prefilterMap,
|
|
17073
|
+
// dfgLUT
|
|
17074
|
+
};
|
|
17002
17075
|
|
|
17003
|
-
|
|
17004
|
-
|
|
17005
|
-
|
|
17076
|
+
if (sh) {
|
|
17077
|
+
maps['sh'] = sh;
|
|
17078
|
+
}
|
|
17006
17079
|
|
|
17007
|
-
|
|
17008
|
-
|
|
17009
|
-
|
|
17010
|
-
|
|
17011
|
-
|
|
17012
|
-
|
|
17013
|
-
|
|
17014
|
-
|
|
17015
|
-
|
|
17016
|
-
|
|
17017
|
-
|
|
17018
|
-
|
|
17019
|
-
|
|
17020
|
-
|
|
17080
|
+
if (config.format === 'array') {
|
|
17081
|
+
maps['envMap'] = {
|
|
17082
|
+
width: envMap.width,
|
|
17083
|
+
height: envMap.height,
|
|
17084
|
+
faces: getEnvmapPixels(regl, envMap, envCubeSize, isHDR)
|
|
17085
|
+
};
|
|
17086
|
+
maps['prefilterMap'] = {
|
|
17087
|
+
width: prefilterMap.width,
|
|
17088
|
+
height: prefilterMap.height,
|
|
17089
|
+
faces: prefilterMipmap
|
|
17090
|
+
};
|
|
17091
|
+
envMap.destroy();
|
|
17092
|
+
prefilterMap.destroy();
|
|
17093
|
+
}
|
|
17021
17094
|
|
|
17022
|
-
|
|
17095
|
+
return maps;
|
|
17096
|
+
}
|
|
17097
|
+
if (callback) {
|
|
17098
|
+
callback(createMap());
|
|
17099
|
+
return;
|
|
17100
|
+
}
|
|
17101
|
+
return createMap();
|
|
17023
17102
|
}
|
|
17024
17103
|
|
|
17025
17104
|
function createSkybox(regl, cubemap, size) {
|
|
17026
17105
|
const drawCube = regl({
|
|
17027
|
-
frag
|
|
17028
|
-
vert
|
|
17029
|
-
attributes
|
|
17030
|
-
'aPosition'
|
|
17106
|
+
frag: skyboxFrag,
|
|
17107
|
+
vert: cubemapVS,
|
|
17108
|
+
attributes: {
|
|
17109
|
+
'aPosition': cubeData.vertices
|
|
17031
17110
|
},
|
|
17032
|
-
uniforms
|
|
17111
|
+
uniforms: {
|
|
17033
17112
|
'hsv': [0, 0, 0],
|
|
17034
17113
|
'projMatrix': regl.context('projMatrix'),
|
|
17035
17114
|
'viewMatrix': regl.context('viewMatrix'),
|
|
@@ -17039,7 +17118,7 @@ function createSkybox(regl, cubemap, size) {
|
|
|
17039
17118
|
'environmentExposure': 1,
|
|
17040
17119
|
'backgroundIntensity': 1
|
|
17041
17120
|
},
|
|
17042
|
-
elements
|
|
17121
|
+
elements: cubeData.indices
|
|
17043
17122
|
});
|
|
17044
17123
|
const color = regl.cube({
|
|
17045
17124
|
width: size,
|
|
@@ -17068,33 +17147,33 @@ function createSkybox(regl, cubemap, size) {
|
|
|
17068
17147
|
|
|
17069
17148
|
function getEnvmapPixels(regl, cubemap, envCubeSize, isHDR, environmentExposure = 1, encodeRGBM = false) {
|
|
17070
17149
|
const drawCube = regl({
|
|
17071
|
-
frag
|
|
17072
|
-
vert
|
|
17073
|
-
attributes
|
|
17074
|
-
'aPosition'
|
|
17150
|
+
frag: (encodeRGBM ? '#define ENCODE_RGBM\n' : '') + cubemapFS,
|
|
17151
|
+
vert: cubemapVS,
|
|
17152
|
+
attributes: {
|
|
17153
|
+
'aPosition': cubeData.vertices
|
|
17075
17154
|
},
|
|
17076
|
-
uniforms
|
|
17077
|
-
'projMatrix'
|
|
17078
|
-
'viewMatrix'
|
|
17079
|
-
'cubeMap'
|
|
17155
|
+
uniforms: {
|
|
17156
|
+
'projMatrix': regl.context('projMatrix'),
|
|
17157
|
+
'viewMatrix': regl.context('viewMatrix'),
|
|
17158
|
+
'cubeMap': cubemap,
|
|
17080
17159
|
'exposure': environmentExposure
|
|
17081
17160
|
},
|
|
17082
|
-
elements
|
|
17161
|
+
elements: cubeData.indices
|
|
17083
17162
|
});
|
|
17084
17163
|
const faces = [];
|
|
17085
17164
|
const color = regl.texture({
|
|
17086
|
-
radius
|
|
17087
|
-
min
|
|
17088
|
-
mag
|
|
17165
|
+
radius: envCubeSize,
|
|
17166
|
+
min: 'linear',
|
|
17167
|
+
mag: 'linear',
|
|
17089
17168
|
type: isHDR ? 'float' : 'uint8',
|
|
17090
17169
|
format: 'rgba'
|
|
17091
17170
|
});
|
|
17092
17171
|
const tmpFBO = regl.framebuffer({
|
|
17093
|
-
radius
|
|
17172
|
+
radius: envCubeSize,
|
|
17094
17173
|
color
|
|
17095
17174
|
});
|
|
17096
17175
|
renderToCube(regl, tmpFBO, drawCube, {
|
|
17097
|
-
size
|
|
17176
|
+
size: envCubeSize
|
|
17098
17177
|
}, function (/* context, props, batchId */) {
|
|
17099
17178
|
const pixels = regl.read();
|
|
17100
17179
|
if (isHDR) {
|
|
@@ -17126,16 +17205,16 @@ function createEquirectangularMapCube(regl, texture, size) {
|
|
|
17126
17205
|
size = size || 512;
|
|
17127
17206
|
const drawCube = regl({
|
|
17128
17207
|
frag: equirectangularMapFS,
|
|
17129
|
-
vert
|
|
17130
|
-
attributes
|
|
17131
|
-
'aPosition'
|
|
17208
|
+
vert: cubemapVS,
|
|
17209
|
+
attributes: {
|
|
17210
|
+
'aPosition': cubeData.vertices
|
|
17132
17211
|
},
|
|
17133
|
-
uniforms
|
|
17134
|
-
'projMatrix'
|
|
17135
|
-
'viewMatrix'
|
|
17136
|
-
'equirectangularMap'
|
|
17212
|
+
uniforms: {
|
|
17213
|
+
'projMatrix': regl.context('projMatrix'),
|
|
17214
|
+
'viewMatrix': regl.context('viewMatrix'),
|
|
17215
|
+
'equirectangularMap': texture
|
|
17137
17216
|
},
|
|
17138
|
-
elements
|
|
17217
|
+
elements: cubeData.indices
|
|
17139
17218
|
});
|
|
17140
17219
|
|
|
17141
17220
|
const color = regl.cube({
|
|
@@ -17172,21 +17251,21 @@ function createPrefilterMipmap(regl, fromCubeMap, SIZE, sampleSize, roughnessLev
|
|
|
17172
17251
|
});
|
|
17173
17252
|
|
|
17174
17253
|
const drawCube = regl({
|
|
17175
|
-
frag
|
|
17176
|
-
vert
|
|
17177
|
-
attributes
|
|
17178
|
-
'aPosition'
|
|
17254
|
+
frag: prefilterFS,
|
|
17255
|
+
vert: cubemapVS,
|
|
17256
|
+
attributes: {
|
|
17257
|
+
'aPosition': cubeData.vertices
|
|
17179
17258
|
},
|
|
17180
|
-
uniforms
|
|
17181
|
-
'projMatrix'
|
|
17182
|
-
'viewMatrix'
|
|
17183
|
-
'environmentMap'
|
|
17184
|
-
'distributionMap'
|
|
17185
|
-
'roughness'
|
|
17259
|
+
uniforms: {
|
|
17260
|
+
'projMatrix': regl.context('projMatrix'),
|
|
17261
|
+
'viewMatrix': regl.context('viewMatrix'),
|
|
17262
|
+
'environmentMap': fromCubeMap,
|
|
17263
|
+
'distributionMap': distributionMap,
|
|
17264
|
+
'roughness': regl.prop('roughness'),
|
|
17186
17265
|
'resolution': SIZE
|
|
17187
17266
|
},
|
|
17188
|
-
elements
|
|
17189
|
-
viewport
|
|
17267
|
+
elements: cubeData.indices,
|
|
17268
|
+
viewport: {
|
|
17190
17269
|
x: 0,
|
|
17191
17270
|
y: 0,
|
|
17192
17271
|
width: regl.prop('size'),
|
|
@@ -17196,9 +17275,9 @@ function createPrefilterMipmap(regl, fromCubeMap, SIZE, sampleSize, roughnessLev
|
|
|
17196
17275
|
let size = SIZE;
|
|
17197
17276
|
|
|
17198
17277
|
const color = regl.texture({
|
|
17199
|
-
radius
|
|
17200
|
-
min
|
|
17201
|
-
mag
|
|
17278
|
+
radius: SIZE,
|
|
17279
|
+
min: 'linear',
|
|
17280
|
+
mag: 'linear',
|
|
17202
17281
|
type: isHDR ? 'float' : 'uint8'
|
|
17203
17282
|
});
|
|
17204
17283
|
const tmpFBO = regl.framebuffer({
|
|
@@ -17216,7 +17295,7 @@ function createPrefilterMipmap(regl, fromCubeMap, SIZE, sampleSize, roughnessLev
|
|
|
17216
17295
|
//分别绘制六个方向,读取fbo的pixel,作为某个方向的mipmap级别数据
|
|
17217
17296
|
renderToCube(regl, tmpFBO, drawCube, {
|
|
17218
17297
|
roughness: roughness,
|
|
17219
|
-
size
|
|
17298
|
+
size: size
|
|
17220
17299
|
}, function (/* context, props, batchId */) {
|
|
17221
17300
|
const pixels = regl.read({ framebuffer: tmpFBO });
|
|
17222
17301
|
let data = pixels;
|
|
@@ -17230,7 +17309,7 @@ function createPrefilterMipmap(regl, fromCubeMap, SIZE, sampleSize, roughnessLev
|
|
|
17230
17309
|
if (!mipmap[faceId]) {
|
|
17231
17310
|
//regl要求的cube face的mipmap数据格式
|
|
17232
17311
|
mipmap[faceId] = {
|
|
17233
|
-
mipmap
|
|
17312
|
+
mipmap: []
|
|
17234
17313
|
};
|
|
17235
17314
|
}
|
|
17236
17315
|
mipmap[faceId].mipmap.push(data);
|
|
@@ -17267,11 +17346,11 @@ function createPrefilterCube(regl, fromCubeMap, SIZE, sampleSize, roughnessLevel
|
|
|
17267
17346
|
const mipmap = createPrefilterMipmap(regl, fromCubeMap, SIZE, sampleSize, roughnessLevels, isHDR);
|
|
17268
17347
|
// debugger
|
|
17269
17348
|
const prefilterMap = regl.cube({
|
|
17270
|
-
radius
|
|
17271
|
-
min
|
|
17272
|
-
mag
|
|
17273
|
-
type:
|
|
17274
|
-
faces
|
|
17349
|
+
radius: SIZE,
|
|
17350
|
+
min: 'linear',
|
|
17351
|
+
mag: 'linear',
|
|
17352
|
+
type: isHDR ? 'float16' : 'uint8',
|
|
17353
|
+
faces: mipmap,
|
|
17275
17354
|
format: 'rgba'
|
|
17276
17355
|
});
|
|
17277
17356
|
// mipmapCube.destroy();
|
|
@@ -17280,9 +17359,9 @@ function createPrefilterCube(regl, fromCubeMap, SIZE, sampleSize, roughnessLevel
|
|
|
17280
17359
|
|
|
17281
17360
|
const quadVertices = new Int8Array([
|
|
17282
17361
|
// positions // texture Coords
|
|
17283
|
-
-1.0,
|
|
17362
|
+
-1.0, 1.0, 0.0,
|
|
17284
17363
|
-1.0, -1.0, 0.0,
|
|
17285
|
-
1.0,
|
|
17364
|
+
1.0, 1.0, 0.0,
|
|
17286
17365
|
1.0, -1.0, 0.0,
|
|
17287
17366
|
]);
|
|
17288
17367
|
const quadTexcoords = new Int8Array([
|
|
@@ -17306,11 +17385,11 @@ function generateDFGLUT(device, size, sampleSize, roughnessLevels) {
|
|
|
17306
17385
|
|
|
17307
17386
|
// const type = regl.hasExtension('OES_texture_half_float') ? 'float16' : 'float';
|
|
17308
17387
|
const distributionMap = regl.texture({
|
|
17309
|
-
data
|
|
17310
|
-
width
|
|
17311
|
-
height
|
|
17312
|
-
min
|
|
17313
|
-
mag
|
|
17388
|
+
data: distro,
|
|
17389
|
+
width: roughnessLevels,
|
|
17390
|
+
height: sampleSize,
|
|
17391
|
+
min: 'nearest',
|
|
17392
|
+
mag: 'nearest'
|
|
17314
17393
|
});
|
|
17315
17394
|
|
|
17316
17395
|
const quadBuf = regl.buffer({ data: quadVertices, name: 'aPosition' });
|
|
@@ -17327,20 +17406,20 @@ function generateDFGLUT(device, size, sampleSize, roughnessLevels) {
|
|
|
17327
17406
|
frag: dfgFS,
|
|
17328
17407
|
vert: dfgVS,
|
|
17329
17408
|
attributes: {
|
|
17330
|
-
'aPosition'
|
|
17331
|
-
buffer
|
|
17409
|
+
'aPosition': {
|
|
17410
|
+
buffer: quadBuf,
|
|
17332
17411
|
// stride : 5 * FSIZE,
|
|
17333
17412
|
// size : 3
|
|
17334
17413
|
},
|
|
17335
|
-
'aTexCoord'
|
|
17336
|
-
buffer
|
|
17414
|
+
'aTexCoord': {
|
|
17415
|
+
buffer: quadTexBuf,
|
|
17337
17416
|
// offset : 3 * FSIZE,
|
|
17338
17417
|
// stride : 5 * FSIZE,
|
|
17339
17418
|
// size : 2,
|
|
17340
17419
|
}
|
|
17341
17420
|
},
|
|
17342
17421
|
uniforms: {
|
|
17343
|
-
'distributionMap'
|
|
17422
|
+
'distributionMap': distributionMap
|
|
17344
17423
|
},
|
|
17345
17424
|
framebuffer: fbo,
|
|
17346
17425
|
viewport: {
|
|
@@ -17425,6 +17504,7 @@ function supportFloat16(regl) {
|
|
|
17425
17504
|
var PBRHelper = /*#__PURE__*/Object.freeze({
|
|
17426
17505
|
__proto__: null,
|
|
17427
17506
|
createIBLMaps: createIBLMaps,
|
|
17507
|
+
createIBLMapsAsync: createIBLMapsAsync,
|
|
17428
17508
|
generateDFGLUT: generateDFGLUT,
|
|
17429
17509
|
supportFloat16: supportFloat16
|
|
17430
17510
|
});
|
|
@@ -24478,6 +24558,7 @@ function createWebGLContext(canvas, preserveDrawingBuffer, onlyWebGL1, extension
|
|
|
24478
24558
|
gl: gl,
|
|
24479
24559
|
reglGL: reglGL,
|
|
24480
24560
|
regl,
|
|
24561
|
+
device: regl,
|
|
24481
24562
|
getImageData: (sx, sy, sw, sh) => {
|
|
24482
24563
|
const pixels = new Uint8Array(sw * sh * 4);
|
|
24483
24564
|
regl.read({
|
|
@@ -24538,17 +24619,8 @@ const canvasCompatible = function (Base) {
|
|
|
24538
24619
|
this.regl = regl;
|
|
24539
24620
|
this.reglGL = reglGL;
|
|
24540
24621
|
this.context = context;
|
|
24541
|
-
|
|
24542
|
-
|
|
24543
|
-
clearContext() {
|
|
24544
|
-
if (!this.regl) {
|
|
24545
|
-
return;
|
|
24546
|
-
}
|
|
24547
|
-
this.regl.clear({
|
|
24548
|
-
color: [0, 0, 0, 0],
|
|
24549
|
-
depth: 1,
|
|
24550
|
-
stencil: 0xFF
|
|
24551
|
-
});
|
|
24622
|
+
this.context.device = regl;
|
|
24623
|
+
this.device = this.regl;
|
|
24552
24624
|
}
|
|
24553
24625
|
};
|
|
24554
24626
|
return compatible;
|
|
@@ -25074,7 +25146,7 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
|
|
|
25074
25146
|
regl.clear({
|
|
25075
25147
|
color: EMPTY_COLOR$1,
|
|
25076
25148
|
depth: 1,
|
|
25077
|
-
stencil:
|
|
25149
|
+
stencil: 0,
|
|
25078
25150
|
framebuffer: this._targetFBO
|
|
25079
25151
|
});
|
|
25080
25152
|
// regl.clear({
|
|
@@ -25102,14 +25174,14 @@ class GroupGLLayerRenderer extends canvasCompatible(LayerAbstractRenderer$3) {
|
|
|
25102
25174
|
regl.clear({
|
|
25103
25175
|
color: EMPTY_COLOR$1,
|
|
25104
25176
|
depth: 1,
|
|
25105
|
-
stencil:
|
|
25177
|
+
stencil: 0,
|
|
25106
25178
|
framebuffer: this._outlineFBO
|
|
25107
25179
|
});
|
|
25108
25180
|
}
|
|
25109
25181
|
// regl.clear({
|
|
25110
25182
|
// color: EMPTY_COLOR,
|
|
25111
25183
|
// depth: 1,
|
|
25112
|
-
// stencil:
|
|
25184
|
+
// stencil: 0
|
|
25113
25185
|
// });
|
|
25114
25186
|
}
|
|
25115
25187
|
|
|
@@ -28206,11 +28278,12 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28206
28278
|
_createTerrainMaskTexture() {
|
|
28207
28279
|
const regl = this.device;
|
|
28208
28280
|
const tileSize = this.layer.getTileSize().width;
|
|
28209
|
-
const width = tileSize
|
|
28210
|
-
const height = tileSize
|
|
28281
|
+
const width = tileSize / 2;
|
|
28282
|
+
const height = tileSize / 2;
|
|
28211
28283
|
const color = regl.texture({
|
|
28212
|
-
min
|
|
28213
|
-
|
|
28284
|
+
// min 和 mag 必须用nearest,选择别的值会造成mask的高程值发生错误
|
|
28285
|
+
min: 'nearest',
|
|
28286
|
+
mag: 'nearest',
|
|
28214
28287
|
type: 'uint8',
|
|
28215
28288
|
format: 'rgba',
|
|
28216
28289
|
width,
|
|
@@ -28243,12 +28316,16 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28243
28316
|
_createTerrainTexture(tileInfo/*, tileImage*/) {
|
|
28244
28317
|
const tileSize = this.layer.getTileSize().width;
|
|
28245
28318
|
// 乘以2是为了瓦片(缩放时)被放大后保持清晰度
|
|
28246
|
-
|
|
28247
|
-
|
|
28319
|
+
let width = tileSize * 2;
|
|
28320
|
+
let height = tileSize * 2;
|
|
28248
28321
|
const regl = this.device;
|
|
28249
28322
|
const colorsTexture = tileInfo.colorsTexture;
|
|
28250
28323
|
let color;
|
|
28251
|
-
if (colorsTexture && colorsTexture
|
|
28324
|
+
if (maptalks.Util.isImageBitMap(colorsTexture) && colorsTexture.width > 0) {
|
|
28325
|
+
//不同的打包环境下,framebuffer 的大小和texture不同的,有的报错,有的不报错,why? 我也不知道
|
|
28326
|
+
//确保framebuffer 的大小和texture相同
|
|
28327
|
+
width = colorsTexture.width;
|
|
28328
|
+
height = colorsTexture.height;
|
|
28252
28329
|
color = regl.texture({
|
|
28253
28330
|
data: colorsTexture,
|
|
28254
28331
|
min: 'linear',
|
|
@@ -28507,6 +28584,7 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28507
28584
|
|
|
28508
28585
|
// this.consumeTile(terrainData, tile);
|
|
28509
28586
|
tile.colorsTexture = terrainData.colorsTexture;
|
|
28587
|
+
delete terrainData.colorsTexture;
|
|
28510
28588
|
this.onTileLoad(terrainData, tile);
|
|
28511
28589
|
});
|
|
28512
28590
|
};
|
|
@@ -28549,9 +28627,16 @@ class TerrainLayerRenderer extends MaskRendererMixin(TileLayerRendererable$1(Lay
|
|
|
28549
28627
|
}
|
|
28550
28628
|
delete info.skinTileIds;
|
|
28551
28629
|
this._deleteTerrainImage(tile.info, image);
|
|
28630
|
+
|
|
28552
28631
|
}
|
|
28553
28632
|
|
|
28554
28633
|
_deleteTerrainImage(tileInfo, image) {
|
|
28634
|
+
if (tileInfo && tileInfo.colorsTexture) {
|
|
28635
|
+
if (tileInfo.colorsTexture.close) {
|
|
28636
|
+
tileInfo.colorsTexture.close();
|
|
28637
|
+
}
|
|
28638
|
+
delete tileInfo.colorsTexture;
|
|
28639
|
+
}
|
|
28555
28640
|
const skin = image.skin;
|
|
28556
28641
|
if (skin) {
|
|
28557
28642
|
skin.destroy();
|
|
@@ -30235,7 +30320,8 @@ class TerrainLayer extends MaskLayerMixin(maptalks.TileLayer) {
|
|
|
30235
30320
|
TerrainLayer.mergeOptions(options$2);
|
|
30236
30321
|
TerrainLayer.registerJSONType('TerrainLayer');
|
|
30237
30322
|
|
|
30238
|
-
TerrainLayer.registerRenderer('gl', TerrainLayerRenderer);
|
|
30323
|
+
TerrainLayer.registerRenderer('gl', TerrainLayerRenderer);
|
|
30324
|
+
TerrainLayer.registerRenderer('gpu', TerrainLayerRenderer);
|
|
30239
30325
|
|
|
30240
30326
|
const TRIANGLE = [], POS_A = [], POS_B = [], POS_C = [], TEMP_POINT$1 = new Point(0, 0), NULL_ALTITUDES = [];
|
|
30241
30327
|
const TEMP_VEC_AB = [], TEMP_VEC_AC = [];
|
|
@@ -31095,6 +31181,7 @@ class GroupGLLayer extends maptalks.Layer {
|
|
|
31095
31181
|
GroupGLLayer.mergeOptions(options$1);
|
|
31096
31182
|
GroupGLLayer.registerJSONType('GroupGLLayer');
|
|
31097
31183
|
GroupGLLayer.registerRenderer('gl', GroupGLLayerRenderer);
|
|
31184
|
+
GroupGLLayer.registerRenderer('gpu', GroupGLLayerRenderer);
|
|
31098
31185
|
GroupGLLayer.registerRenderer('canvas', null);
|
|
31099
31186
|
function empty() { return; }
|
|
31100
31187
|
function sortLayersByZIndex(a, b) {
|
|
@@ -31120,6 +31207,34 @@ var SkyboxMode;
|
|
|
31120
31207
|
SkyboxMode[SkyboxMode["REALISTIC"] = 1] = "REALISTIC";
|
|
31121
31208
|
})(SkyboxMode || (SkyboxMode = {}));
|
|
31122
31209
|
|
|
31210
|
+
let actor;
|
|
31211
|
+
function getWorkerActor() {
|
|
31212
|
+
if (!actor) {
|
|
31213
|
+
actor = new worker.Actor('maplight');
|
|
31214
|
+
}
|
|
31215
|
+
return actor;
|
|
31216
|
+
}
|
|
31217
|
+
|
|
31218
|
+
//cal projectEnvironmentMapCPU by worker
|
|
31219
|
+
function projectEnvironmentMapCPU(params, callback) {
|
|
31220
|
+
const { cubePixels, width, height } = params;
|
|
31221
|
+
const buffers = cubePixels.map(face => {
|
|
31222
|
+
return face.buffer;
|
|
31223
|
+
});
|
|
31224
|
+
getWorkerActor().send({
|
|
31225
|
+
cubePixels: buffers,
|
|
31226
|
+
width,
|
|
31227
|
+
height,
|
|
31228
|
+
}, buffers, (err, data) => {
|
|
31229
|
+
if (err) {
|
|
31230
|
+
console.error(err);
|
|
31231
|
+
return;
|
|
31232
|
+
}
|
|
31233
|
+
callback(data.shList);
|
|
31234
|
+
});
|
|
31235
|
+
|
|
31236
|
+
}
|
|
31237
|
+
|
|
31123
31238
|
const PREFILTER_CUBE_SIZE = 512;
|
|
31124
31239
|
|
|
31125
31240
|
class LightManager {
|
|
@@ -31127,6 +31242,7 @@ class LightManager {
|
|
|
31127
31242
|
constructor(map) {
|
|
31128
31243
|
this._map = map;
|
|
31129
31244
|
this._loader = new ResourceLoader();
|
|
31245
|
+
this.updateTime = Util$1.now();
|
|
31130
31246
|
}
|
|
31131
31247
|
|
|
31132
31248
|
getDirectionalLight() {
|
|
@@ -31212,7 +31328,7 @@ class LightManager {
|
|
|
31212
31328
|
this._onSkyboxLoaded(images);
|
|
31213
31329
|
}
|
|
31214
31330
|
};
|
|
31215
|
-
const onerror = function() {
|
|
31331
|
+
const onerror = function () {
|
|
31216
31332
|
throw new Error(`skybox image with url(${this.src}) failed to load, please check the image's url.`);
|
|
31217
31333
|
};
|
|
31218
31334
|
const urlModifier = this._urlModifier;
|
|
@@ -31227,10 +31343,14 @@ class LightManager {
|
|
|
31227
31343
|
envUrls = [nx, px, nz, pz, py, ny];
|
|
31228
31344
|
}
|
|
31229
31345
|
count = envUrls.length;
|
|
31346
|
+
const crossOrigin = resource.crossOrigin;
|
|
31230
31347
|
for (let i = 0; i < count; i++) {
|
|
31231
31348
|
const img = new Image();
|
|
31232
31349
|
img.onload = onload;
|
|
31233
31350
|
img.onerror = onerror;
|
|
31351
|
+
if (!Util$1.isNil(crossOrigin)) {
|
|
31352
|
+
img.crossOrigin = crossOrigin;
|
|
31353
|
+
}
|
|
31234
31354
|
img.src = urlModifier && urlModifier(envUrls[i]) || envUrls[i];
|
|
31235
31355
|
images[i] = img;
|
|
31236
31356
|
}
|
|
@@ -31263,10 +31383,16 @@ class LightManager {
|
|
|
31263
31383
|
|
|
31264
31384
|
_onHDRLoaded() {
|
|
31265
31385
|
if (this._hdr) {
|
|
31266
|
-
this.
|
|
31386
|
+
this._createIBLMaps(this._hdr).then(maps => {
|
|
31387
|
+
this._iblMaps = maps;
|
|
31388
|
+
this._map.fire('updatelights', { 'ambientUpdate': true });
|
|
31389
|
+
if (this.getAmbientLight().debug) {
|
|
31390
|
+
console.log(`ambientLight hdr loadend`);
|
|
31391
|
+
}
|
|
31392
|
+
});
|
|
31267
31393
|
// this._hdr.dispose();
|
|
31268
31394
|
// delete this._hdr;
|
|
31269
|
-
|
|
31395
|
+
|
|
31270
31396
|
}
|
|
31271
31397
|
}
|
|
31272
31398
|
|
|
@@ -31275,42 +31401,59 @@ class LightManager {
|
|
|
31275
31401
|
}
|
|
31276
31402
|
|
|
31277
31403
|
_onSkyboxLoaded(images) {
|
|
31278
|
-
this.
|
|
31279
|
-
|
|
31404
|
+
this._createIBLMaps(images).then(maps => {
|
|
31405
|
+
this._iblMaps = maps;
|
|
31406
|
+
this._map.fire('updatelights', { 'ambientUpdate': true });
|
|
31407
|
+
if (this.getAmbientLight().debug) {
|
|
31408
|
+
console.log(`ambientLight skybox loadend`);
|
|
31409
|
+
}
|
|
31410
|
+
});
|
|
31280
31411
|
}
|
|
31281
31412
|
|
|
31282
31413
|
_createIBLMaps(envTexture) {
|
|
31283
|
-
|
|
31284
|
-
|
|
31285
|
-
|
|
31286
|
-
|
|
31287
|
-
|
|
31288
|
-
|
|
31289
|
-
|
|
31290
|
-
|
|
31291
|
-
|
|
31292
|
-
|
|
31293
|
-
|
|
31294
|
-
|
|
31295
|
-
|
|
31296
|
-
|
|
31297
|
-
|
|
31298
|
-
|
|
31299
|
-
|
|
31300
|
-
|
|
31301
|
-
|
|
31302
|
-
|
|
31414
|
+
this.updateTime = Util$1.now();
|
|
31415
|
+
return new Promise((resolve) => {
|
|
31416
|
+
const config = this._config.ambient.resource;
|
|
31417
|
+
const cubeSize = config.prefilterCubeSize || PREFILTER_CUBE_SIZE;
|
|
31418
|
+
const regl = this._tryToGetREGLContext(this._map);
|
|
31419
|
+
const asynchronous = config.asynchronous;
|
|
31420
|
+
pbr.PBRHelper.createIBLMapsAsync(regl, {
|
|
31421
|
+
updateTime: this.updateTime,
|
|
31422
|
+
asynchronous,
|
|
31423
|
+
envTexture: Array.isArray(envTexture) ? envTexture : envTexture.getREGLTexture(regl),
|
|
31424
|
+
ignoreSH: !!config['sh'],
|
|
31425
|
+
envCubeSize: cubeSize,
|
|
31426
|
+
prefilterCubeSize: cubeSize,
|
|
31427
|
+
environmentExposure: this._config.ambient.exposure,
|
|
31428
|
+
format: 'array',
|
|
31429
|
+
projectEnvironmentMapCPU: asynchronous ? projectEnvironmentMapCPU : null
|
|
31430
|
+
}).then((maps) => {
|
|
31431
|
+
//单位时间内多次更新,永远使用最新的
|
|
31432
|
+
if (maps.updateTime !== this.updateTime) {
|
|
31433
|
+
return;
|
|
31303
31434
|
}
|
|
31304
|
-
|
|
31305
|
-
|
|
31306
|
-
|
|
31307
|
-
|
|
31308
|
-
|
|
31309
|
-
|
|
31310
|
-
|
|
31311
|
-
|
|
31312
|
-
|
|
31313
|
-
|
|
31435
|
+
// hdr.dispose();
|
|
31436
|
+
if (config['sh']) {
|
|
31437
|
+
maps.sh = config['sh'];
|
|
31438
|
+
//兼容老的[[], [], ..]形式的sh
|
|
31439
|
+
if (Array.isArray(maps['sh'][0])) {
|
|
31440
|
+
const sh = maps['sh'];
|
|
31441
|
+
const flatten = [];
|
|
31442
|
+
for (let i = 0; i < sh.length; i++) {
|
|
31443
|
+
flatten.push(...sh[i]);
|
|
31444
|
+
}
|
|
31445
|
+
maps['sh'] = flatten;
|
|
31446
|
+
}
|
|
31447
|
+
}
|
|
31448
|
+
if (regl._temp) {
|
|
31449
|
+
delete this._hdr;
|
|
31450
|
+
regl.destroy();
|
|
31451
|
+
}
|
|
31452
|
+
resolve(maps);
|
|
31453
|
+
});
|
|
31454
|
+
|
|
31455
|
+
});
|
|
31456
|
+
|
|
31314
31457
|
}
|
|
31315
31458
|
|
|
31316
31459
|
_disposeCubeLight() {
|
|
@@ -31537,11 +31680,11 @@ class MapGLRenderer extends renderer.MapAbstractRenderer {
|
|
|
31537
31680
|
if (!this.regl) {
|
|
31538
31681
|
return;
|
|
31539
31682
|
}
|
|
31540
|
-
const renderer = layer.getRenderer();
|
|
31541
31683
|
this.regl.clear({
|
|
31542
31684
|
depth: 1,
|
|
31543
31685
|
stencil: 0
|
|
31544
31686
|
});
|
|
31687
|
+
const renderer = layer.getRenderer();
|
|
31545
31688
|
renderer.clearContext();
|
|
31546
31689
|
}
|
|
31547
31690
|
|
|
@@ -31553,6 +31696,7 @@ class MapGLRenderer extends renderer.MapAbstractRenderer {
|
|
|
31553
31696
|
this.gl = gl;
|
|
31554
31697
|
this.regl = regl;
|
|
31555
31698
|
this.reglGL = reglGL;
|
|
31699
|
+
this.device = regl;
|
|
31556
31700
|
this.context = context;
|
|
31557
31701
|
return Promise.resolve();
|
|
31558
31702
|
}
|
|
@@ -31578,6 +31722,10 @@ class MapGLRenderer extends renderer.MapAbstractRenderer {
|
|
|
31578
31722
|
return this.gl.wrap();
|
|
31579
31723
|
}
|
|
31580
31724
|
|
|
31725
|
+
isWebGL() {
|
|
31726
|
+
return true;
|
|
31727
|
+
}
|
|
31728
|
+
|
|
31581
31729
|
isWebGPU() {
|
|
31582
31730
|
return false;
|
|
31583
31731
|
}
|
|
@@ -31589,6 +31737,115 @@ Map$1.registerRenderer('gl', MapGLRenderer);
|
|
|
31589
31737
|
// renderer: ['gl', 'gpu']
|
|
31590
31738
|
// });
|
|
31591
31739
|
|
|
31740
|
+
/******************************************************************************
|
|
31741
|
+
Copyright (c) Microsoft Corporation.
|
|
31742
|
+
|
|
31743
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
31744
|
+
purpose with or without fee is hereby granted.
|
|
31745
|
+
|
|
31746
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
31747
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
31748
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
31749
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
31750
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
31751
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
31752
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
31753
|
+
***************************************************************************** */
|
|
31754
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
31755
|
+
|
|
31756
|
+
|
|
31757
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
31758
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
31759
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31760
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31761
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
31762
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31763
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31764
|
+
});
|
|
31765
|
+
}
|
|
31766
|
+
|
|
31767
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
31768
|
+
var e = new Error(message);
|
|
31769
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
31770
|
+
};
|
|
31771
|
+
|
|
31772
|
+
let gpuAdapter;
|
|
31773
|
+
let gpuDevice;
|
|
31774
|
+
function initGPUDevice() {
|
|
31775
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31776
|
+
var _a;
|
|
31777
|
+
if (gpuDevice) {
|
|
31778
|
+
return gpuDevice;
|
|
31779
|
+
}
|
|
31780
|
+
gpuAdapter = yield ((_a = navigator.gpu) === null || _a === void 0 ? void 0 : _a.requestAdapter());
|
|
31781
|
+
gpuDevice = yield (gpuAdapter === null || gpuAdapter === void 0 ? void 0 : gpuAdapter.requestDevice({
|
|
31782
|
+
// requiredLimits: {
|
|
31783
|
+
// maxVertexBuffers: 16
|
|
31784
|
+
// }
|
|
31785
|
+
}));
|
|
31786
|
+
return { gpuDevice, gpuAdapter };
|
|
31787
|
+
});
|
|
31788
|
+
}
|
|
31789
|
+
class MapGPURenderer extends renderer.MapAbstractRenderer {
|
|
31790
|
+
drawLayers(layers, framestamp) {
|
|
31791
|
+
const updated = super.drawLayers(layers, framestamp);
|
|
31792
|
+
if (updated) {
|
|
31793
|
+
this.device.submit();
|
|
31794
|
+
}
|
|
31795
|
+
return updated;
|
|
31796
|
+
}
|
|
31797
|
+
clearCanvas() {
|
|
31798
|
+
if (!this.device) {
|
|
31799
|
+
return;
|
|
31800
|
+
}
|
|
31801
|
+
// depth and stencil will be cleared in clearLayerCanvasContext
|
|
31802
|
+
this.device.clear({
|
|
31803
|
+
color: [0, 0, 0, 0]
|
|
31804
|
+
});
|
|
31805
|
+
}
|
|
31806
|
+
clearLayerCanvasContext(layer) {
|
|
31807
|
+
if (!this.device) {
|
|
31808
|
+
return;
|
|
31809
|
+
}
|
|
31810
|
+
// const renderer = layer.getRenderer();
|
|
31811
|
+
this.device.clear({
|
|
31812
|
+
depth: 1,
|
|
31813
|
+
stencil: 0
|
|
31814
|
+
});
|
|
31815
|
+
// renderer.clearContext();
|
|
31816
|
+
}
|
|
31817
|
+
isWebGL() {
|
|
31818
|
+
return false;
|
|
31819
|
+
}
|
|
31820
|
+
isWebGPU() {
|
|
31821
|
+
return true;
|
|
31822
|
+
}
|
|
31823
|
+
createContext() {
|
|
31824
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31825
|
+
const { gpuDevice, gpuAdapter } = yield initGPUDevice();
|
|
31826
|
+
const context = this.canvas.getContext('webgpu');
|
|
31827
|
+
this.device = new GraphicsDevice(gpuDevice, context, gpuAdapter);
|
|
31828
|
+
this.context = {
|
|
31829
|
+
context,
|
|
31830
|
+
device: this.device,
|
|
31831
|
+
getImageData: (sx, sy, sw, sh) => {
|
|
31832
|
+
const pixels = new Uint8Array(sw * sh * 4);
|
|
31833
|
+
const canvas = this.canvas;
|
|
31834
|
+
this.device.read({
|
|
31835
|
+
x: sx,
|
|
31836
|
+
y: canvas.height - sy,
|
|
31837
|
+
width: sw,
|
|
31838
|
+
height: sh,
|
|
31839
|
+
data: pixels
|
|
31840
|
+
});
|
|
31841
|
+
return new ImageData(new Uint8ClampedArray(pixels.buffer), sw, sh);
|
|
31842
|
+
}
|
|
31843
|
+
};
|
|
31844
|
+
});
|
|
31845
|
+
}
|
|
31846
|
+
}
|
|
31847
|
+
Map$1.registerRenderer('gpu', MapGPURenderer);
|
|
31848
|
+
|
|
31592
31849
|
const COLOR = [];
|
|
31593
31850
|
|
|
31594
31851
|
|
|
@@ -31946,7 +32203,8 @@ function createImageMesh(geometry, image, extent2d, offset, scale, uniforms) {
|
|
|
31946
32203
|
const config = {
|
|
31947
32204
|
data: image,
|
|
31948
32205
|
mag: 'nearest',
|
|
31949
|
-
mipmap: true
|
|
32206
|
+
mipmap: true,
|
|
32207
|
+
premultiplyAlpha: true
|
|
31950
32208
|
};
|
|
31951
32209
|
let texture = this.getTexture();
|
|
31952
32210
|
if (!texture) {
|
|
@@ -32252,12 +32510,15 @@ class TileLayerGLRenderer2 extends TexturePoolable(canvasCompatible(TileLayerRen
|
|
|
32252
32510
|
},
|
|
32253
32511
|
depth: {
|
|
32254
32512
|
enable: true,
|
|
32255
|
-
func: '<='
|
|
32513
|
+
func: '<=',
|
|
32514
|
+
mask: () => {
|
|
32515
|
+
return !!this.layer.options['depthMask'];
|
|
32516
|
+
}
|
|
32256
32517
|
},
|
|
32257
32518
|
blend: {
|
|
32258
32519
|
enable: true,
|
|
32259
32520
|
func: {
|
|
32260
|
-
src:
|
|
32521
|
+
src: 1,
|
|
32261
32522
|
dst: 'one minus src alpha'
|
|
32262
32523
|
},
|
|
32263
32524
|
equation: 'add'
|
|
@@ -32334,6 +32595,7 @@ class TileLayerGLRenderer2 extends TexturePoolable(canvasCompatible(TileLayerRen
|
|
|
32334
32595
|
}
|
|
32335
32596
|
}
|
|
32336
32597
|
maptalks.TileLayer.registerRenderer('gl', TileLayerGLRenderer2);
|
|
32598
|
+
maptalks.TileLayer.registerRenderer('gpu', TileLayerGLRenderer2);
|
|
32337
32599
|
function drawDebug(ctx, debugInfo, color, lineWidth, left, top, width, height, textOffsetY = 0) {
|
|
32338
32600
|
ctx.font = '20px monospace';
|
|
32339
32601
|
ctx.fillStyle = color;
|
|
@@ -32478,112 +32740,7 @@ class ImageLayerGLRenderer2 extends TexturePoolable(canvasCompatible(ImageLayerR
|
|
|
32478
32740
|
}
|
|
32479
32741
|
}
|
|
32480
32742
|
maptalks.ImageLayer.registerRenderer('gl', ImageLayerGLRenderer2);
|
|
32481
|
-
|
|
32482
|
-
/******************************************************************************
|
|
32483
|
-
Copyright (c) Microsoft Corporation.
|
|
32484
|
-
|
|
32485
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
32486
|
-
purpose with or without fee is hereby granted.
|
|
32487
|
-
|
|
32488
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
32489
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
32490
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
32491
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
32492
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
32493
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
32494
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
32495
|
-
***************************************************************************** */
|
|
32496
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
32497
|
-
|
|
32498
|
-
|
|
32499
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
32500
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
32501
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
32502
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32503
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32504
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
32505
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32506
|
-
});
|
|
32507
|
-
}
|
|
32508
|
-
|
|
32509
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
32510
|
-
var e = new Error(message);
|
|
32511
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
32512
|
-
};
|
|
32513
|
-
|
|
32514
|
-
let gpuAdapter;
|
|
32515
|
-
let gpuDevice;
|
|
32516
|
-
function initGPUDevice() {
|
|
32517
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32518
|
-
var _a;
|
|
32519
|
-
if (gpuDevice) {
|
|
32520
|
-
return gpuDevice;
|
|
32521
|
-
}
|
|
32522
|
-
gpuAdapter = yield ((_a = navigator.gpu) === null || _a === void 0 ? void 0 : _a.requestAdapter());
|
|
32523
|
-
gpuDevice = yield (gpuAdapter === null || gpuAdapter === void 0 ? void 0 : gpuAdapter.requestDevice({
|
|
32524
|
-
// requiredLimits: {
|
|
32525
|
-
// maxVertexBuffers: 16
|
|
32526
|
-
// }
|
|
32527
|
-
}));
|
|
32528
|
-
return { gpuDevice, gpuAdapter };
|
|
32529
|
-
});
|
|
32530
|
-
}
|
|
32531
|
-
class MapGPURenderer extends renderer.MapAbstractRenderer {
|
|
32532
|
-
drawLayers(layers, framestamp) {
|
|
32533
|
-
const updated = super.drawLayers(layers, framestamp);
|
|
32534
|
-
if (updated) {
|
|
32535
|
-
this.device.submit();
|
|
32536
|
-
}
|
|
32537
|
-
return updated;
|
|
32538
|
-
}
|
|
32539
|
-
clearCanvas() {
|
|
32540
|
-
if (!this.device) {
|
|
32541
|
-
return;
|
|
32542
|
-
}
|
|
32543
|
-
// depth and stencil will be cleared in clearLayerCanvasContext
|
|
32544
|
-
this.device.clear({
|
|
32545
|
-
color: [0, 0, 0, 0]
|
|
32546
|
-
});
|
|
32547
|
-
}
|
|
32548
|
-
clearLayerCanvasContext(layer) {
|
|
32549
|
-
if (!this.device) {
|
|
32550
|
-
return;
|
|
32551
|
-
}
|
|
32552
|
-
const renderer = layer.getRenderer();
|
|
32553
|
-
this.device.clear({
|
|
32554
|
-
depth: 1,
|
|
32555
|
-
stencil: 0
|
|
32556
|
-
});
|
|
32557
|
-
renderer.clearContext();
|
|
32558
|
-
}
|
|
32559
|
-
isWebGPU() {
|
|
32560
|
-
return true;
|
|
32561
|
-
}
|
|
32562
|
-
createContext() {
|
|
32563
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32564
|
-
const { gpuDevice, gpuAdapter } = yield initGPUDevice();
|
|
32565
|
-
const context = this.canvas.getContext('webgpu');
|
|
32566
|
-
this.device = new GraphicsDevice(gpuDevice, context, gpuAdapter);
|
|
32567
|
-
this.context = {
|
|
32568
|
-
context,
|
|
32569
|
-
device: this.device,
|
|
32570
|
-
getImageData: (sx, sy, sw, sh) => {
|
|
32571
|
-
const pixels = new Uint8Array(sw * sh * 4);
|
|
32572
|
-
const canvas = this.canvas;
|
|
32573
|
-
this.device.read({
|
|
32574
|
-
x: sx,
|
|
32575
|
-
y: canvas.height - sy,
|
|
32576
|
-
width: sw,
|
|
32577
|
-
height: sh,
|
|
32578
|
-
data: pixels
|
|
32579
|
-
});
|
|
32580
|
-
return new ImageData(new Uint8ClampedArray(pixels.buffer), sw, sh);
|
|
32581
|
-
}
|
|
32582
|
-
};
|
|
32583
|
-
});
|
|
32584
|
-
}
|
|
32585
|
-
}
|
|
32586
|
-
Map$1.registerRenderer('gpu', MapGPURenderer);
|
|
32743
|
+
maptalks.ImageLayer.registerRenderer('gpu', ImageLayerGLRenderer2);
|
|
32587
32744
|
|
|
32588
32745
|
//参考:
|
|
32589
32746
|
// * https://blog.mapbox.com/introducing-heatmaps-in-mapbox-gl-js-71355ada9e6c
|
|
@@ -33729,19 +33886,28 @@ class Height3DTool extends Measure3DTool {
|
|
|
33729
33886
|
}
|
|
33730
33887
|
}
|
|
33731
33888
|
|
|
33732
|
-
const e = "${"; const code = `function(t){
|
|
33889
|
+
const e = "${"; const code$1 = `function(t){
|
|
33733
33890
|
/*!
|
|
33734
|
-
* @maptalks/gltf-loader v0.
|
|
33891
|
+
* @maptalks/gltf-loader v0.115.1
|
|
33735
33892
|
* LICENSE : UNLICENSED
|
|
33736
33893
|
* (c) 2016-2025 maptalks.org
|
|
33737
33894
|
*/
|
|
33738
|
-
var r,
|
|
33739
|
-
/** @license zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */function(){function t(t){throw t}var r=void 0,e=!0,i=this;function n(t,e){var n,s=t.split("."),a=i;!(s[0]in a)&&a.execScript&&a.execScript("var "+s[0]);for(;s.length&&(n=s.shift());)s.length||e===r?a=a[n]?a[n]:a[n]={}:a[n]=e}var s="undefined"!=typeof Uint8Array&&"undefined"!=typeof Uint16Array&&"undefined"!=typeof Uint32Array&&"undefined"!=typeof DataView;function a(r,e){this.index="number"==typeof e?e:0,this.i=0,this.buffer=r instanceof(s?Uint8Array:Array)?r: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,r=this.buffer,e=r.length,i=new(s?Uint8Array:Array)(e<<1);if(s)i.set(r);else for(t=0;t<e;++t)i[t]=r[t];return this.buffer=i},a.prototype.d=function(t,r,e){var i,n=this.buffer,s=this.index,a=this.i,o=n[s];if(e&&1<r&&(t=8<r?(l[255&t]<<24|l[t>>>8&255]<<16|l[t>>>16&255]<<8|l[t>>>24&255])>>32-r:l[t]>>8-r),8>r+a)o=o<<r|t,a+=r;else for(i=0;i<r;++i)o=o<<1|t>>r-i-1&1,8==++a&&(a=0,n[s++]=l[o],o=0,s===n.length&&(n=this.f()));n[s]=o,this.buffer=n,this.i=a,this.index=s},a.prototype.finish=function(){var t,r=this.buffer,e=this.index;return 0<this.i&&(r[e]<<=8-this.i,r[e]=l[r[e]],e++),s?t=r.subarray(0,e):(r.length=e,t=r),t};var o,h=new(s?Uint8Array:Array)(256);for(o=0;256>o;++o){for(var c=u=o,f=7,u=u>>>1;u;u>>>=1)c<<=1,c|=1&u,--f;h[o]=(c<<f&255)>>>0}var l=h;function d(t){this.buffer=new(s?Uint16Array:Array)(2*t),this.length=0}function y(t){var r,e,i,n,a,o,h,c,f,u,l=t.length,d=0,y=Number.POSITIVE_INFINITY;for(c=0;c<l;++c)t[c]>d&&(d=t[c]),t[c]<y&&(y=t[c]);for(r=1<<d,e=new(s?Uint32Array:Array)(r),i=1,n=0,a=2;i<=d;){for(c=0;c<l;++c)if(t[c]===i){for(o=0,h=n,f=0;f<i;++f)o=o<<1|1&h,h>>=1;for(u=i<<16|c,f=o;f<r;f+=a)e[f]=u;++n}++i,n<<=1,a<<=1}return[e,d,y]}function w(t,r){this.h=v,this.w=0,this.input=s&&t instanceof Array?new Uint8Array(t):t,this.b=0,r&&(r.lazy&&(this.w=r.lazy),"number"==typeof r.compressionType&&(this.h=r.compressionType),r.outputBuffer&&(this.a=s&&r.outputBuffer instanceof Array?new Uint8Array(r.outputBuffer):r.outputBuffer),"number"==typeof r.outputIndex&&(this.b=r.outputIndex)),this.a||(this.a=new(s?Uint8Array:Array)(32768))}d.prototype.getParent=function(t){return 2*((t-2)/4|0)},d.prototype.push=function(t,r){var e,i,n,s=this.buffer;for(e=this.length,s[this.length++]=r,s[this.length++]=t;0<e&&(i=this.getParent(e),s[e]>s[i]);)n=s[e],s[e]=s[i],s[i]=n,n=s[e+1],s[e+1]=s[i+1],s[i+1]=n,e=i;return this.length},d.prototype.pop=function(){var t,r,e,i,n,s=this.buffer;for(r=s[0],t=s[1],this.length-=2,s[0]=s[this.length],s[1]=s[this.length+1],n=0;!((i=2*n+2)>=this.length)&&(i+2<this.length&&s[i+2]>s[i]&&(i+=2),s[i]>s[n]);)e=s[n],s[n]=s[i],s[i]=e,e=s[n+1],s[n+1]=s[i+1],s[i+1]=e,n=i;return{index:t,value:r,length:this.length}};var A,v=2,p={NONE:0,r:1,k:v,N:3},b=[];for(A=0;288>A;A++)switch(e){case 143>=A:b.push([A+48,8]);break;case 255>=A:b.push([A-144+400,9]);break;case 279>=A:b.push([A-256+0,7]);break;case 287>=A:b.push([A-280+192,8]);break;default:t("invalid literal: "+A)}function k(t,r){this.length=t,this.G=r}w.prototype.j=function(){var i,n,o,h,c=this.input;switch(this.h){case 0:for(o=0,h=c.length;o<h;){var f,u,l,d=n=s?c.subarray(o,o+65535):c.slice(o,o+65535),y=(o+=n.length)===h,w=r,A=r,p=this.a,k=this.b;if(s){for(p=new Uint8Array(this.a.buffer);p.length<=k+d.length+5;)p=new Uint8Array(p.length<<1);p.set(this.a)}if(f=y?1:0,p[k++]=0|f,l=65536+~(u=d.length)&65535,p[k++]=255&u,p[k++]=u>>>8&255,p[k++]=255&l,p[k++]=l>>>8&255,s)p.set(d,k),k+=d.length,p=p.subarray(0,k);else{for(w=0,A=d.length;w<A;++w)p[k++]=d[w];p.length=k}this.b=k,this.a=p}break;case 1:var m=new a(s?new Uint8Array(this.a.buffer):this.a,this.b);m.d(1,1,e),m.d(1,2,e);var g,x,S,T=U(this,c);for(g=0,x=T.length;g<x;g++)if(S=T[g],a.prototype.d.apply(m,b[S]),256<S)m.d(T[++g],T[++g],e),m.d(T[++g],5),m.d(T[++g],T[++g],e);else if(256===S)break;this.a=m.finish(),this.b=this.a.length;break;case v:var F,I,D,O,C,q,z,N,j,W,Z,H,V,$,_,B=new a(s?new Uint8Array(this.a.buffer):this.a,this.b),L=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],P=Array(19);for(F=v,B.d(1,1,e),B.d(F,2,e),I=U(this,c),z=E(q=M(this.L,15)),j=E(N=M(this.K,7)),D=286;257<D&&0===q[D-1];D--);for(O=30;1<O&&0===N[O-1];O--);var R,G,J,Y,K,X,Q=D,tt=O,rt=new(s?Uint32Array:Array)(Q+tt),et=new(s?Uint32Array:Array)(316),it=new(s?Uint8Array:Array)(19);for(R=G=0;R<Q;R++)rt[G++]=q[R];for(R=0;R<tt;R++)rt[G++]=N[R];if(!s)for(R=0,Y=it.length;R<Y;++R)it[R]=0;for(R=K=0,Y=rt.length;R<Y;R+=G){for(G=1;R+G<Y&&rt[R+G]===rt[R];++G);if(J=G,0===rt[R])if(3>J)for(;0<J--;)et[K++]=0,it[0]++;else for(;0<J;)(X=138>J?J:138)>J-3&&X<J&&(X=J-3),10>=X?(et[K++]=17,et[K++]=X-3,it[17]++):(et[K++]=18,et[K++]=X-11,it[18]++),J-=X;else if(et[K++]=rt[R],it[rt[R]]++,3>--J)for(;0<J--;)et[K++]=rt[R],it[rt[R]]++;else for(;0<J;)(X=6>J?J:6)>J-3&&X<J&&(X=J-3),et[K++]=16,et[K++]=X-3,it[16]++,J-=X}for(i=s?et.subarray(0,K):et.slice(0,K),W=M(it,7),$=0;19>$;$++)P[$]=W[L[$]];for(C=19;4<C&&0===P[C-1];C--);for(Z=E(W),B.d(D-257,5,e),B.d(O-1,5,e),B.d(C-4,4,e),$=0;$<C;$++)B.d(P[$],3,e);for($=0,_=i.length;$<_;$++)if(H=i[$],B.d(Z[H],W[H],e),16<=H){switch($++,H){case 16:V=2;break;case 17:V=3;break;case 18:V=7;break;default:t("invalid code: "+H)}B.d(i[$],V,e)}var nt,st,at,ot,ht,ct,ft,ut,lt=[z,q],dt=[j,N];for(ht=lt[0],ct=lt[1],ft=dt[0],ut=dt[1],nt=0,st=I.length;nt<st;++nt)if(at=I[nt],B.d(ht[at],ct[at],e),256<at)B.d(I[++nt],I[++nt],e),ot=I[++nt],B.d(ft[ot],ut[ot],e),B.d(I[++nt],I[++nt],e);else if(256===at)break;this.a=B.finish(),this.b=this.a.length;break;default:t("invalid compression type")}return this.a};var m=function(){function r(r){switch(e){case 3===r:return[257,r-3,0];case 4===r:return[258,r-4,0];case 5===r:return[259,r-5,0];case 6===r:return[260,r-6,0];case 7===r:return[261,r-7,0];case 8===r:return[262,r-8,0];case 9===r:return[263,r-9,0];case 10===r:return[264,r-10,0];case 12>=r:return[265,r-11,1];case 14>=r:return[266,r-13,1];case 16>=r:return[267,r-15,1];case 18>=r:return[268,r-17,1];case 22>=r:return[269,r-19,2];case 26>=r:return[270,r-23,2];case 30>=r:return[271,r-27,2];case 34>=r:return[272,r-31,2];case 42>=r:return[273,r-35,3];case 50>=r:return[274,r-43,3];case 58>=r:return[275,r-51,3];case 66>=r:return[276,r-59,3];case 82>=r:return[277,r-67,4];case 98>=r:return[278,r-83,4];case 114>=r:return[279,r-99,4];case 130>=r:return[280,r-115,4];case 162>=r:return[281,r-131,5];case 194>=r:return[282,r-163,5];case 226>=r:return[283,r-195,5];case 257>=r:return[284,r-227,5];case 258===r:return[285,r-258,0];default:t("invalid length: "+r)}}var i,n,s=[];for(i=3;258>=i;i++)n=r(i),s[i]=n[2]<<24|n[1]<<16|n[0];return s}(),g=s?new Uint32Array(m):m;function U(i,n){function a(r,i){var n,s,a,o,h=r.G,c=[],f=0;switch(n=g[r.length],c[f++]=65535&n,c[f++]=n>>16&255,c[f++]=n>>24,e){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(n=s,c[f++]=n[0],c[f++]=n[1],c[f++]=n[2],a=0,o=c.length;a<o;++a)v[p++]=c[a];k[c[0]]++,m[c[3]]++,b=r.length+i-1,y=null}var o,h,c,f,u,l,d,y,w,A={},v=s?new Uint16Array(2*n.length):[],p=0,b=0,k=new(s?Uint32Array:Array)(286),m=new(s?Uint32Array:Array)(30),U=i.w;if(!s){for(c=0;285>=c;)k[c++]=0;for(c=0;29>=c;)m[c++]=0}for(k[256]=1,o=0,h=n.length;o<h;++o){for(c=u=0,f=3;c<f&&o+c!==h;++c)u=u<<8|n[o+c];if(A[u]===r&&(A[u]=[]),l=A[u],!(0<b--)){for(;0<l.length&&32768<o-l[0];)l.shift();if(o+3>=h){for(y&&a(y,-1),c=0,f=h-o;c<f;++c)w=n[o+c],v[p++]=w,++k[w];break}0<l.length?(d=x(n,o,l),y?y.length<d.length?(w=n[o-1],v[p++]=w,++k[w],a(d,0)):a(y,-1):d.length<U?y=d:a(d,0)):y?a(y,-1):(w=n[o],v[p++]=w,++k[w])}l.push(o)}return v[p++]=256,k[256]++,i.L=k,i.K=m,s?v.subarray(0,p):v}function x(t,r,e){var i,n,s,a,o,h,c=0,f=t.length;a=0,h=e.length;t:for(;a<h;a++){if(i=e[h-a-1],s=3,3<c){for(o=c;3<o;o--)if(t[i+o-1]!==t[r+o-1])continue t;s=c}for(;258>s&&r+s<f&&t[i+s]===t[r+s];)++s;if(s>c&&(n=i,c=s),258===s)break}return new k(c,r-n)}function M(t,r){var e,i,n,a,o,h=t.length,c=new d(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(e=Array(c.length/2),i=new(s?Uint32Array:Array)(c.length/2),1===e.length)return f[c.pop().index]=1,f;for(a=0,o=c.length/2;a<o;++a)e[a]=c.pop(),i[a]=e[a].value;for(n=function(t,r,e){function i(t){var e=y[t][w[t]];e===r?(i(t+1),i(t+1)):--l[e],++w[t]}var n,a,o,h,c,f=new(s?Uint16Array:Array)(e),u=new(s?Uint8Array:Array)(e),l=new(s?Uint8Array:Array)(r),d=Array(e),y=Array(e),w=Array(e),A=(1<<e)-r,v=1<<e-1;for(f[e-1]=r,a=0;a<e;++a)A<v?u[a]=0:(u[a]=1,A-=v),A<<=1,f[e-2-a]=(f[e-1-a]/2|0)+r;for(f[0]=u[0],d[0]=Array(f[0]),y[0]=Array(f[0]),a=1;a<e;++a)f[a]>2*f[a-1]+u[a]&&(f[a]=2*f[a-1]+u[a]),d[a]=Array(f[a]),y[a]=Array(f[a]);for(n=0;n<r;++n)l[n]=e;for(o=0;o<f[e-1];++o)d[e-1][o]=t[o],y[e-1][o]=o;for(n=0;n<e;++n)w[n]=0;for(1===u[e-1]&&(--l[0],++w[e-1]),a=e-2;0<=a;--a){for(h=n=0,c=w[a+1],o=0;o<f[a];o++)(h=d[a+1][c]+d[a+1][c+1])>t[n]?(d[a][o]=h,y[a][o]=r,c+=2):(d[a][o]=t[n],y[a][o]=n,++n);w[a]=0,1===u[a]&&i(a)}return l}(i,i.length,r),a=0,o=e.length;a<o;++a)f[e[a].index]=n[a];return f}function E(t){var r,e,i,n,a=new(s?Uint16Array:Array)(t.length),o=[],h=[],c=0;for(r=0,e=t.length;r<e;r++)o[t[r]]=1+(0|o[t[r]]);for(r=1,e=16;r<=e;r++)h[r]=c,c+=0|o[r],c<<=1;for(r=0,e=t.length;r<e;r++)for(c=h[t[r]],h[t[r]]+=1,i=a[r]=0,n=t[r];i<n;i++)a[r]=a[r]<<1|1&c,c>>>=1;return a}function S(r,e){switch(this.l=[],this.m=32768,this.e=this.g=this.c=this.q=0,this.input=s?new Uint8Array(r):r,this.s=!1,this.n=F,this.B=!1,!e&&(e={})||(e.index&&(this.c=e.index),e.bufferSize&&(this.m=e.bufferSize),e.bufferType&&(this.n=e.bufferType),e.resize&&(this.B=e.resize)),this.n){case T:this.b=32768,this.a=new(s?Uint8Array:Array)(32768+this.m+258);break;case F: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 T=0,F=1,I={D:T,C:F};S.prototype.p=function(){for(;!this.s;){var i=J(this,3);switch(1&i&&(this.s=e),i>>>=1){case 0:var n=this.input,a=this.c,o=this.a,h=this.b,c=n.length,f=r,u=o.length,l=r;switch(this.e=this.g=0,a+1>=c&&t(Error("invalid uncompressed block header: LEN")),f=n[a++]|n[a++]<<8,a+1>=c&&t(Error("invalid uncompressed block header: NLEN")),f===~(n[a++]|n[a++]<<8)&&t(Error("invalid uncompressed block header: length verify")),a+f>n.length&&t(Error("input buffer is broken")),this.n){case T:for(;h+f>o.length;){if(f-=l=u-h,s)o.set(n.subarray(a,a+l),h),h+=l,a+=l;else for(;l--;)o[h++]=n[a++];this.b=h,o=this.f(),h=this.b}break;case F:for(;h+f>o.length;)o=this.f({v:2});break;default:t(Error("invalid inflate mode"))}if(s)o.set(n.subarray(a,a+f),h),h+=f,a+=f;else for(;f--;)o[h++]=n[a++];this.c=a,this.b=h,this.a=o;break;case 1:this.o(P,G);break;case 2:var d,w,A,v,p=J(this,5)+257,b=J(this,5)+1,k=J(this,4)+4,m=new(s?Uint8Array:Array)(q.length),g=r,U=r,x=r,M=r,E=r;for(E=0;E<k;++E)m[q[E]]=J(this,3);if(!s)for(E=k,k=m.length;E<k;++E)m[q[E]]=0;for(d=y(m),g=new(s?Uint8Array:Array)(p+b),E=0,v=p+b;E<v;)switch(U=Y(this,d),U){case 16:for(M=3+J(this,2);M--;)g[E++]=x;break;case 17:for(M=3+J(this,3);M--;)g[E++]=0;x=0;break;case 18:for(M=11+J(this,7);M--;)g[E++]=0;x=0;break;default:x=g[E++]=U}w=y(s?g.subarray(0,p):g.slice(0,p)),A=y(s?g.subarray(p):g.slice(p)),this.o(w,A);break;default:t(Error("unknown BTYPE: "+i))}}return this.t()};var D,O,C=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],q=s?new Uint16Array(C):C,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],N=s?new Uint16Array(z):z,j=[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],W=s?new Uint8Array(j):j,Z=[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],H=s?new Uint16Array(Z):Z,V=[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],$=s?new Uint8Array(V):V,_=new(s?Uint8Array:Array)(288);for(D=0,O=_.length;D<O;++D)_[D]=143>=D?8:255>=D?9:279>=D?7:8;var B,L,P=y(_),R=new(s?Uint8Array:Array)(30);for(B=0,L=R.length;B<L;++B)R[B]=5;var G=y(R);function J(r,e){for(var i,n=r.g,s=r.e,a=r.input,o=r.c,h=a.length;s<e;)o>=h&&t(Error("input buffer is broken")),n|=a[o++]<<s,s+=8;return i=n&(1<<e)-1,r.g=n>>>e,r.e=s-e,r.c=o,i}function Y(r,e){for(var i,n,s=r.g,a=r.e,o=r.input,h=r.c,c=o.length,f=e[0],u=e[1];a<u&&!(h>=c);)s|=o[h++]<<a,a+=8;return(n=(i=f[s&(1<<u)-1])>>>16)>a&&t(Error("invalid code length: "+n)),r.g=s>>n,r.e=a-n,r.c=h,65535&i}function K(t){if("string"==typeof t){var r,e,i=t.split("");for(r=0,e=i.length;r<e;r++)i[r]=(255&i[r].charCodeAt(0))>>>0;t=i}for(var n,s=1,a=0,o=t.length,h=0;0<o;){o-=n=1024<o?1024:o;do{a+=s+=t[h++]}while(--n);s%=65521,a%=65521}return(a<<16|s)>>>0}function X(r,e){var i,n;if(this.input=r,this.c=0,!e&&(e={})||(e.index&&(this.c=e.index),e.verify&&(this.M=e.verify)),i=r[this.c++],n=r[this.c++],(15&i)===Q)this.method=Q;else t(Error("unsupported compression method"));0!=((i<<8)+n)%31&&t(Error("invalid fcheck flag:"+((i<<8)+n)%31)),32&n&&t(Error("fdict flag is not supported")),this.A=new S(r,{index:this.c,bufferSize:e.bufferSize,bufferType:e.bufferType,resize:e.resize})}S.prototype.o=function(t,r){var e=this.a,i=this.b;this.u=t;for(var n,s,a,o,h=e.length-258;256!==(n=Y(this,t));)if(256>n)i>=h&&(this.b=i,e=this.f(),i=this.b),e[i++]=n;else for(o=N[s=n-257],0<W[s]&&(o+=J(this,W[s])),n=Y(this,r),a=H[n],0<$[n]&&(a+=J(this,$[n])),i>=h&&(this.b=i,e=this.f(),i=this.b);o--;)e[i]=e[i++-a];for(;8<=this.e;)this.e-=8,this.c--;this.b=i},S.prototype.I=function(t,r){var e=this.a,i=this.b;this.u=t;for(var n,s,a,o,h=e.length;256!==(n=Y(this,t));)if(256>n)i>=h&&(h=(e=this.f()).length),e[i++]=n;else for(o=N[s=n-257],0<W[s]&&(o+=J(this,W[s])),n=Y(this,r),a=H[n],0<$[n]&&(a+=J(this,$[n])),i+o>h&&(h=(e=this.f()).length);o--;)e[i]=e[i++-a];for(;8<=this.e;)this.e-=8,this.c--;this.b=i},S.prototype.f=function(){var t,r,e=new(s?Uint8Array:Array)(this.b-32768),i=this.b-32768,n=this.a;if(s)e.set(n.subarray(32768,e.length));else for(t=0,r=e.length;t<r;++t)e[t]=n[t+32768];if(this.l.push(e),this.q+=e.length,s)n.set(n.subarray(i,i+32768));else for(t=0;32768>t;++t)n[t]=n[i+t];return this.b=32768,n},S.prototype.J=function(t){var r,e,i,n=this.input.length/this.c+1|0,a=this.input,o=this.a;return t&&("number"==typeof t.v&&(n=t.v),"number"==typeof t.F&&(n+=t.F)),2>n?e=(i=(a.length-this.c)/this.u[2]/2*258|0)<o.length?o.length+i:o.length<<1:e=o.length*n,s?(r=new Uint8Array(e)).set(o):r=o,this.a=r},S.prototype.t=function(){var t,r,e,i,n,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(r=0,e=h.length;r<e;++r)for(i=0,n=(t=h[r]).length;i<n;++i)c[a++]=t[i];for(r=32768,e=this.b;r<e;++r)c[a++]=o[r];return this.l=[],this.buffer=c},S.prototype.H=function(){var t,r=this.b;return s?this.B?(t=new Uint8Array(r)).set(this.a.subarray(0,r)):t=this.a.subarray(0,r):(this.a.length>r&&(this.a.length=r),t=this.a),this.buffer=t},X.prototype.p=function(){var r,e=this.input;return r=this.A.p(),this.c=this.A.c,this.M&&((e[this.c++]<<24|e[this.c++]<<16|e[this.c++]<<8|e[this.c++])>>>0!==K(r)&&t(Error("invalid adler-32 checksum"))),r};var Q=8;function tt(t,r){this.input=t,this.a=new(s?Uint8Array:Array)(32768),this.h=rt.k;var e,i={};for(e in!r&&(r={})||"number"!=typeof r.compressionType||(this.h=r.compressionType),r)i[e]=r[e];i.outputBuffer=this.a,this.z=new w(this.input,i)}var rt=p;function et(t,r){var e,i,s,a;if(Object.keys)e=Object.keys(r);else for(i in e=[],s=0,r)e[s++]=i;for(s=0,a=e.length;s<a;++s)n(t+"."+(i=e[s]),r[i])}tt.prototype.j=function(){var r,e,i,n,a,o,h,c=0;if(h=this.a,(r=Q)===Q)e=Math.LOG2E*Math.log(32768)-8;else t(Error("invalid compression method"));if(i=e<<4|r,h[c++]=i,r===Q)switch(this.h){case rt.NONE:a=0;break;case rt.r:a=1;break;case rt.k:a=2;break;default:t(Error("unsupported compression type"))}else t(Error("invalid compression method"));return n=a<<6,h[c++]=n|31-(256*i+n)%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},n("Zlib.Inflate",X),n("Zlib.Inflate.prototype.decompress",X.prototype.p),et("Zlib.Inflate.BufferType",{ADAPTIVE:I.C,BLOCK:I.D}),n("Zlib.Deflate",tt),n("Zlib.Deflate.compress",(function(t,r){return new tt(t,r).j()})),n("Zlib.Deflate.prototype.compress",tt.prototype.j),et("Zlib.Deflate.CompressionType",{NONE:rt.NONE,FIXED:rt.r,DYNAMIC:rt.k})}.call(self);var c="undefined"!=typeof Float32Array?Float32Array:Array;Math.hypot||(Math.hypot=function(){for(var t=0,r=arguments.length;r--;)t+=arguments[r]*arguments[r];return Math.sqrt(t)});var f,u=function(t,r,e){return t[0]=r[0]-e[0],t[1]=r[1]-e[1],t[2]=r[2]-e[2],t};function l(t,r,e){return t[0]=r,t[1]=e,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 d{constructor(t=257){this.gridSize=t;const r=t-1;if(r&r-1)throw new Error(\`Expected grid size to be 2^n+1, got ${e}t}.\`);this.numTriangles=r*r*2-2,this.numParentTriangles=this.numTriangles-r*r,this.indices=new Uint32Array(this.gridSize*this.gridSize),this.coords=new Uint16Array(4*this.numTriangles);for(let t=0;t<this.numTriangles;t++){let e=t+2,i=0,n=0,s=0,a=0,o=0,h=0;for(1&e?s=a=o=r:i=n=h=r;(e>>=1)>1;){const t=i+s>>1,r=n+a>>1;1&e?(s=i,a=n,i=o,n=h):(i=s,n=a,s=o,a=h),o=t,h=r}const c=4*t;this.coords[c+0]=i,this.coords[c+1]=n,this.coords[c+2]=s,this.coords[c+3]=a}}createTile(t){return new y(t,this)}}class y{constructor(t,r){const e=r.gridSize;if(t.length!==e*e)throw new Error(\`Expected terrain data of length ${e}e*e} (${e}e} x ${e}e}), got ${e}t.length}.\`);this.terrain=t,this.martini=r,this.errors=new Float32Array(t.length),this.update()}update(){const{numTriangles:t,numParentTriangles:r,coords:e,gridSize:i}=this.martini,{terrain:n,errors:s}=this;for(let a=t-1;a>=0;a--){const t=4*a,o=e[t+0],h=e[t+1],c=e[t+2],f=e[t+3],u=o+c>>1,l=h+f>>1,d=u+l-h,y=l+o-u,w=(n[h*i+o]+n[f*i+c])/2,A=l*i+u,v=Math.abs(w-n[A]);if(s[A]=Math.max(s[A],v),a<r){const t=(h+y>>1)*i+(o+d>>1),r=(f+y>>1)*i+(c+d>>1);s[A]=Math.max(s[A],s[t],s[r])}}}getMesh(t=0){const{gridSize:r,indices:e}=this.martini,{errors:i}=this;let n=0,s=0;const a=r-1;function o(a,h,c,f,u,l){const d=a+c>>1,y=h+f>>1;Math.abs(a-u)+Math.abs(h-l)>1&&i[y*r+d]>t?(o(u,l,a,h,d,y),o(c,f,u,l,d,y)):(e[h*r+a]=e[h*r+a]||++n,e[f*r+c]=e[f*r+c]||++n,e[l*r+u]=e[l*r+u]||++n,s++)}e.fill(0),o(0,0,a,a,a,0),o(a,a,0,0,0,a);const h=new Uint16Array(2*n),c=new Uint32Array(3*s);let f=0;function u(n,s,a,o,l,d){const y=n+a>>1,w=s+o>>1;if(Math.abs(n-l)+Math.abs(s-d)>1&&i[w*r+y]>t)u(l,d,n,s,y,w),u(a,o,l,d,y,w);else{const t=e[s*r+n]-1,i=e[o*r+a]-1,u=e[d*r+l]-1;h[2*t]=n,h[2*t+1]=s,h[2*i]=a,h[2*i+1]=o,h[2*u]=l,h[2*u+1]=d,c[f++]=t,c[f++]=i,c[f++]=u}}return u(0,0,a,a,a,0),u(a,a,0,0,0,a),{vertices:h,triangles:c}}getMeshWithSkirts(t=0,r){const{gridSize:e,indices:i}=this.martini,{errors:n}=this;let s=0,a=0;const o=e-1;let h,c,f=0;const u=[],l=[],d=[],y=[];function w(r,A,v,p,b,k){const m=r+v>>1,g=A+p>>1;Math.abs(r-b)+Math.abs(A-k)>1&&n[g*e+m]>t?(w(b,k,r,A,m,g),w(v,p,b,k,m,g)):(h=A*e+r,c=p*e+v,f=k*e+b,0===i[h]&&(0===r?u.push(s):r===o&&l.push(s),0===A?d.push(s):A===o&&y.push(s),i[h]=++s),0===i[c]&&(0===v?u.push(s):v===o&&l.push(s),0===p?d.push(s):p===o&&y.push(s),i[c]=++s),0===i[f]&&(0===b?u.push(s):b===o&&l.push(s),0===k?d.push(s):k===o&&y.push(s),i[f]=++s),a++)}let A;i.fill(0),w(0,0,o,o,o,0),w(o,o,0,0,0,o),A=r?2*(s+3*u.length-2+3*l.length-2+3*d.length-2+3*y.length-2):2*(s+u.length+l.length+d.length+y.length);const v=3*(a+2*(u.length-1)+2*(l.length-1)+2*(d.length-1)+2*(y.length-1)),p=new Uint16Array(A),b=new Uint32Array(v);let k=0;function m(r,s,a,o,h,c){const f=r+a>>1,u=s+o>>1;if(Math.abs(r-h)+Math.abs(s-c)>1&&n[u*e+f]>t)m(h,c,r,s,f,u),m(a,o,h,c,f,u);else{const t=i[s*e+r]-1,n=i[o*e+a]-1,f=i[c*e+h]-1;p[2*t]=r,p[2*t+1]=s,p[2*n]=a,p[2*n+1]=o,p[2*f]=h,p[2*f+1]=c,b[k++]=t,b[k++]=n,b[k++]=f}}m(0,0,o,o,o,0),m(o,o,0,0,0,o),u.sort(((t,r)=>p[2*t+1]-p[2*r+1])),l.sort(((t,r)=>p[2*r+1]-p[2*t+1])),d.sort(((t,r)=>p[2*r]-p[2*t])),y.sort(((t,r)=>p[2*t]-p[2*r]));let g,U,x,M,E=2*s,S=0;function T(t){S=t.length;for(let e=0;e<S-1;e++)g=t[e],U=t[e+1],x=E/2,M=(E+(r?6:2))/2,p[E++]=2*g,p[E++]=2*g+1,r&&(p[E++]=2*g,p[E++]=2*g+1,p[E++]=2*U,p[E++]=2*U+1),r?(b[k++]=x+1,b[k++]=x,b[k++]=x+2,b[k++]=x,b[k++]=M,b[k++]=x+2):(b[k++]=g,b[k++]=x,b[k++]=U,b[k++]=x,b[k++]=M,b[k++]=U);p[E++]=2*t[S-1],p[E++]=2*t[S-1]+1}T(u);const F=E;T(l);const I=E;T(d);const D=E;T(y);return{vertices:p,triangles:b,numVerticesWithoutSkirts:s,numTrianglesWithoutSkirts:a,leftSkirtIndex:F,rightSkirtIndex:I,bottomSkirtIndex:D,topSkirtIndex:E}}}const w={};let A;const v={width:100,height:10};let p,b=!1;try{const t=new OffscreenCanvas(1,1);t.getContext("2d").fillText("hello",0,0),b=!0}catch(t){b=!1}function k(){if(!A){const{width:t,height:r}=v;b?A=new OffscreenCanvas(t,r):(A=document.createElement("canvas"),A.width=t,A.height=r)}return A}class m{constructor(t,r={}){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 e=1/0,i=-1/0;for(let r=0,n=t.length;r<n;r++){const n=t[r][0];e=Math.min(n,e),i=Math.max(n,i)}this.min=e,this.max=i,this.valueOffset=this.max-this.min,this.options=Object.assign({},v,r),this.S()}getImageData(){return this.imgData}S(){const t=k(),{width:r,height:e}=this.options;t.width=r,t.height=e;const i=t.getContext("2d");i.clearRect(0,0,t.width,t.height);const n=i.createLinearGradient(0,0,t.width,0),{colors:s,valueOffset:a}=this;for(let t=0,r=s.length;t<r;t++){const[r,e]=s[t],i=(r-this.min)/a;n.addColorStop(i,e)}i.fillStyle=n,i.fillRect(0,0,t.width,t.height),this.imgData=i.getImageData(0,0,t.width,t.height)}getColor(t){t=Math.max(this.min,t);const r=((t=Math.min(t,this.max))-this.min)/this.valueOffset;let e=Math.round(r*this.imgData.width);e=Math.min(e,this.imgData.width-1);const i=4*e;return[this.imgData.data[i],this.imgData.data[i+1],this.imgData.data[i+2],this.imgData.data[i+3]]}}let g=null,U=null;const x=[0,0,0],M=[256,256];function E(){try{g||(g=new OffscreenCanvas(1,1))}catch(t){console.error(t)}}const S={},T={},F={width:64,height:64,elementsPerHeight:3,heightOffset:-1e3,exaggeration:1,heightScale:.001,elementMultiplier:256,stride:4,skirtHeight:.002,skirtOffset:.01},I={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,*/*"}};I["cesium-ion"]=I.cesium;const D=32767;let O=null,C=null;function q(t,r){const e=function(t){if(t.length<1e3)return null;const r=new Zlib.Inflate(t);return r?r.decompress():null}(new Uint8Array(t));if(!e)throw new Error((i=new Uint8Array(t),z.decode(i)));var i;const n=function(t){const r=t,e=F.width,i=F.height,n=new Uint8Array(e*i*F.stride);let s,a,o,h,c;for(let t=0;t<i;t++)for(let f=0;f<e;f++){h=parseInt(149*t/(i-1)),c=parseInt(149*f/(e-1)),a=2*(150*h+c),s=r[a]+256*r[a+1],(s>1e4||s<-2e3)&&(s=0),o=4*(t*e+f);const u=(s+1e3)/F.heightScale,l=F.elementMultiplier;n[o]=u/(l*l),n[o+1]=(u-n[o]*l*l)/l,n[o+2]=u-n[o]*l*l-n[o+1]*l,n[o+3]=255}return n}(e),s=function(t,r){const e=r,i=r,n=e+1,s=i+1,a=F.elementsPerHeight,o=F.heightOffset,h=F.heightScale,c=F.elementMultiplier,f=F.skirtHeight,u=new Float32Array(n*s);let l=0,d=1/0,y=-1/0;for(let r=0;r<n;r++){const n=r>=i?i-1:r;for(let r=0;r<s;r++){let i=0;const s=n*(4*e)+4*(r>=e?e-1:r);for(let r=0;r<a;r++)i=i*c+t[s+r];i=1*(i*h+o),i-=f,u[l]=i,i<d&&(d=i),i>y&&(y=i),l++}}return{data:u,min:d,max:y}}(n,r-1);return s.width=s.height=r,s}const z=new TextDecoder("utf-8");function N(t){return t>>1^-(1&t)}const j=[];function W(t){let r=0;const e=3*Float64Array.BYTES_PER_ELEMENT,i=3*Uint16Array.BYTES_PER_ELEMENT;let n=Uint16Array.BYTES_PER_ELEMENT;const s=new DataView(t);r+=e;const a=s.getFloat32(r,!0);r+=Float32Array.BYTES_PER_ELEMENT;const o=s.getFloat32(r,!0);r+=Float32Array.BYTES_PER_ELEMENT,r+=e;const h=s.getFloat64(r,!0);r+=Float64Array.BYTES_PER_ELEMENT,r+=e;const c=s.getUint32(r,!0);r+=Uint32Array.BYTES_PER_ELEMENT;const f=new Uint16Array(t,r,3*c);r+=c*i,c>65536&&(n=Uint32Array.BYTES_PER_ELEMENT);!function(t,r,e){const i=t.length;let n=0,s=0,a=0;for(let o=0;o<i;++o)n+=N(t[o]),s+=N(r[o]),t[o]=n,r[o]=s,e&&(a+=N(e[o]),e[o]=a)}(f.subarray(0,c),f.subarray(c,2*c),f.subarray(2*c,3*c)),r%n!=0&&(r+=n-r%n);const u=s.getUint32(r,!0);r+=Uint32Array.BYTES_PER_ELEMENT;const l=c>65536?new Uint32Array(t,r,3*u):new Uint16Array(t,r,3*u);let d=0;const y=l.length;for(let t=0;t<y;++t){const r=l[t];l[t]=d-r,0===r&&++d}const w={minimumHeight:a,maximumHeight:o,quantizedVertices:f,indices:l}.quantizedVertices,A=w.length/3,v=w.subarray(0,A),p=w.subarray(A,2*A),b=w.subarray(2*A,3*A),k=j;for(let t=0;t<A;++t){const r=v[t],e=p[t],i=r/D,n=e/D,s=(m=a,g=o,(1-(U=b[t]/D))*m+U*g);k[3*t]=i,k[3*t+1]=1-n,k[3*t+2]=s}var m,g,U;return{positions:k,radius:h,min:a,max:o,indices:l}}const Z=[],H=[],V=[],$=[],_=[];class B{constructor(t,r,e,i,n){this.p0=[],this.p1=[],this.p2=[],this.normal=[],this.min=[],this.max=[],this.set(t,r,e,i,n)}set(t,r,e,i,n){this.radius=n;let s=3*r,a=3*r+1,o=3*r+2;this.p0[0]=t[s]*n,this.p0[1]=t[a]*n,this.p0[2]=t[o],s=3*e,a=3*e+1,o=3*e+2,this.p1[0]=t[s]*n,this.p1[1]=t[a]*n,this.p1[2]=t[o],s=3*i,a=3*i+1,o=3*i+2,this.p2[0]=t[s]*n,this.p2[1]=t[a]*n,this.p2[2]=t[o],this.min[0]=Math.min(this.p0[0],this.p1[0],this.p2[0]),this.min[1]=Math.min(this.p0[1],this.p1[1],this.p2[1]),this.max[0]=Math.max(this.p0[0],this.p1[0],this.p2[0]),this.max[1]=Math.max(this.p0[1],this.p1[1],this.p2[1]);const h=u(Z,this.p1,this.p0),c=u(H,this.p2,this.p1);this.normal=function(t,r){var e=r[0],i=r[1],n=r[2],s=e*e+i*i+n*n;return s>0&&(s=1/Math.sqrt(s)),t[0]=r[0]*s,t[1]=r[1]*s,t[2]=r[2]*s,t}(this.normal,function(t,r,e){var i=r[0],n=r[1],s=r[2],a=e[0],o=e[1],h=e[2];return t[0]=n*h-s*o,t[1]=s*a-i*h,t[2]=i*o-n*a,t}(this.normal,h,c))}contains(t,r){if(t<this.min[0]||t>this.max[0]||r<this.min[1]||r>this.max[1])return!1;l(V,this.p0[0],this.p0[1]),l($,this.p1[0],this.p1[1]),l(_,this.p2[0],this.p2[1]);const e=G(V[0],V[1],$[0],$[1],_[0],_[1]);return G(t,r,V[0],V[1],_[0],_[1])+G(t,r,V[0],V[1],$[0],$[1])+G(t,r,$[0],$[1],_[0],_[1])-e<=1e-4}getHeight(t,r){const e=this.normal;return this.p0[2]-((t-this.p0[0])*e[0]+(r-this.p0[1])*e[1])/e[2]}}let L=null;function P(t,r,e){if(L&&L.contains(r,e))return L.getHeight(r,e);for(let i=0;i<t.length;i++)if(t[i].contains(r,e))return L=t[i],t[i].getHeight(r,e);return 0}const R=[];function G(t,r,e,i,n,s){return.5*Math.abs(t*i+e*s+n*r-t*s-e*r-n*i)}function J(t,r,e,i,n,s){"cesium-ion"===e&&(r.Authorization="Bearer "+O),function(t,r,e){const i={method:"GET",referrer:e,headers:r},n=h.getArrayBuffer(t,i),s=n.xhr;return T[t]=s,n.then((r=>(delete T[t],r)))}(t,r,origin).then((t=>{if(!t||t.message)s(t?{empty:!0,originalError:t}:{error:{canceled:!0}});else{const r=t.data;let a=null;if("tianditu"===e){const t=q(r,i);K(n,t,i,null,!0,s)}else if("cesium-ion"===e||"cesium"===e){a=W(r);const t=function(t,r){const{positions:e,min:i,max:n,indices:s,radius:a}=t,o=[];let h=0;for(let t=0;t<s.length;t+=3){let r=R[h];r?r.set(e,s[t],s[t+1],s[t+2],2*a):r=R[h]=new B(e,s[t],s[t+1],s[t+2],2*a),h++,o.push(r)}const c=new Float32Array(r*r);h=0;for(let t=0;t<r;t++)for(let e=0;e<r;e++)c[h++]=P(o,e/r*a*2,t/r*a*2);return{data:c,min:i,max:n,width:r,height:r}}(a,i);K(n,t,i,null,!0,s)}else"mapbox"===e&&(a=function(t){const r=new self.Blob([new Uint8Array(t)]);return self.createImageBitmap(r)}(r),a.then((t=>{const r=Q(X(t),i);K(n,r,i,t,!0,s)})))}})).catch((r=>{delete T[t],s({empty:!0,originalError:r})}))}function Y(t,r){const e=Math.floor(10*(t+1e4)),i=e>>16,n=e>>8&255,s=255&e;return r?(r[0]=i,r[1]=n,r[2]=s,r):[i,n,s]}function K(t,r,e,i,n,s){const a=function(t,r,e){let i=w[e];i||(i=w[e]=new d(e));const n=i.createTile(r).getMeshWithSkirts(t,!0),{triangles:s,vertices:a,leftSkirtIndex:o,rightSkirtIndex:h,bottomSkirtIndex:c,topSkirtIndex:f}=n;let{numVerticesWithoutSkirts:u,numTrianglesWithoutSkirts:l}=n;u||(u=a.length/2,l=s.length/3);const y=a.length/2,A=new Float32Array(3*y),v=new Float32Array(2*y);let p=1/0,b=-1/0;const k=e-1;for(let t=0;t<y;t++){const i=a[2*t],n=a[2*t+1];if(t>=u){const r=i/2*3;let e,n=.001;(t-(t<o/2?u:t<h/2?o/2:t<c/2?h/2:c/2))%3==0?(e=Math.min(0,p),n=0):e=A[r+2],A[3*t]=A[r],A[3*t+1]=A[r+1],A[3*t+2]=e,v[2*t]=A[r]/k+n,v[2*t+1]=-A[r+1]/k+n}else{const s=r[n*e+i];A[3*t]=1*i,A[3*t+1]=1*-n,A[3*t+2]=s,v[2*t]=i/k,v[2*t+1]=n/k,s<p&&(p=s),s>b&&(b=s)}}return{positions:A,texcoords:v,triangles:s,leftSkirtIndex:o,rightSkirtIndex:h,bottomSkirtIndex:c,topSkirtIndex:f,numTrianglesWithoutSkirts:l,numVerticesWithoutSkirts:u,minHeight:Math.min(0,p),maxHeight:b,terrainWidth:e}}(t/2,r.data,e),o=[a.positions.buffer,a.texcoords.buffer,a.triangles.buffer];i||(i=function(t){if(E(),!g)return;const{width:r,height:e,data:i}=t;if(r&&e&&i)try{let t=g.getContext("2d",{willReadFrequently:!0});const n=t.createImageData(r,e);for(let t=0,r=i.length;t<r;t++){const r=i[t],[e,s,a]=Y(r,x),o=4*t;n.data[o]=e,n.data[o+1]=s,n.data[o+2]=a,n.data[o+3]=255}return g.width=r,g.height=e,t=g.getContext("2d",{willReadFrequently:!0}),tt(t),t.putImageData(n,0,0),g.transferToImageBitmap()}catch(t){console.log(t)}}(r)),i&&o.push(i);const h={mesh:a};h.image=i,h.data=r,o.push(r.data.buffer),s(h,o)}function X(t){const{width:r,height:e}=t;return g||(g=new OffscreenCanvas(1,1),U=g.getContext("2d",{willReadFrequently:!0})),g.width=r,g.height=e,U.drawImage(t,0,0,r,e),U.getImageData(0,0,r,e)}function Q(t,r){const{data:e,width:i}=t;let n=1/0,s=-1/0;const a=new Float32Array(r*r),o=Math.round(i/r);for(let t=0;t<r;t++)for(let h=0;h<r;h++){const c=t+h*r;let f=0,u=0;const l=t,d=h;for(let t=0;t<o;t++)for(let r=0;r<o;r++){let n=l*o+t,s=d*o+r;s>i-1&&(s=i-1),n>i-1&&(n=i-1);const a=n+s*i,h=e[4*a],c=e[4*a+1],y=e[4*a+2];0===e[4*a+3]?u+=1:f+=.1*(256*h*256+256*c+y)-1e4}f/=o*o-u||1,f>s&&(s=f),f<n&&(n=f),a[c]=f}return{data:a,width:r,height:r,min:n,max:s}}function tt(t){const r=t.canvas,{width:e,height:i}=r;t.clearRect(0,0,e,i)}function rt(t,r,e){if(!r||!Array.isArray(r)||r.length<2)return;if(!t||!t.image)return null;let{width:i,height:n}=t.image;(e=e||M)[0]===i&&e[1]===n||(i=e[0],n=e[1]),i*=2,n*=2;try{if(E(),!g)return;const e=g;e.width=i,e.height=n;const s=e.getContext("2d",{willReadFrequently:!0});tt(s),s.drawImage(t.image,0,0,i,n);const a=s.getImageData(0,0,i,n);return function(t,r){const e=JSON.stringify(r);S[e]||(S[e]=new m(r));const i=S[e],n=t.data;for(let t=0,r=n.length;t<r;t+=4){const r=n[t],e=n[t+1],s=n[t+2];let a=0;0!==n[t+3]&&(a=.1*(256*r*256+256*e+s)-1e4,a=Math.max(a,0));const[o,h,c]=i.getColor(a);n[t]=o,n[t+1]=h,n[t+2]=c,n[t+3]=255}}(a,r),new Uint8Array(a.data)}catch(t){console.error(t)}}t.initialize=function(){},t.onmessage=function(t,r){const e=t.data;if("addLayer"===e.command||"removeLayer"===e.command)p=t.workerId,self.postMessage({type:"<response>",actorId:e.actorId,workerId:p,params:"ok",callback:t.callback});else if("fetchTerrain"===e.command){const t=(e.params||{}).colors,i=(e.params||{}).tileSize;!function(t,r){const{url:e,origin:i,type:n,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,r)}const c=t.headers||I[n];if("tianditu"===n)J(e,c,n,a,o,r);else if("cesium-ion"===n){const h=t.cesiumIonTokenURL+s;O?J(e,c,n,a,o,r):(C||(C=fetch(h,{responseType:"json",method:"GET",referrer:i,headers:{Accept:"application/json,*/*;q=0.01","Accept-Encoding":"gzip, deflate, br"}}).then((t=>t.json())).then((t=>{O=t.accessToken,C=null}))),C.then((()=>{J(e,c,n,a,o,r)})))}else("cesium"===n||"mapbox"===n)&&J(e,c,n,a,o,r)}(e.params,((e,n)=>{const s=rt(e,t,i);s&&(e.colorsTexture=s,(n=n||[]).push(s.buffer)),r(e.error,e,n)}))}else"abortTerrain"===e.command&&(i=e.params.url,T[i]&&(T[i].abort(),delete T[i]));var i}}`;
|
|
33895
|
+
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"),
|
|
33896
|
+
/** @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}}`;
|
|
33897
|
+
|
|
33898
|
+
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}
|
|
33899
|
+
/*!
|
|
33900
|
+
* from claygl
|
|
33901
|
+
* https://github.com/pissang/claygl/
|
|
33902
|
+
* License: BSD-2-Clause
|
|
33903
|
+
*/
|
|
33904
|
+
function i(t,n){const r=t[0],o=t[1],e=t[2];return 0===n?1:1===n?r:2===n?o:3===n?e:4===n?r*e:5===n?o*e:6===n?r*o:7===n?3*e*e-1:r*r-o*o}Math.hypot||(Math.hypot=function(){for(var t=0,n=arguments.length;n--;)t+=arguments[n]*arguments[n];return Math.sqrt(t)}),n=new r(3),r!=Float32Array&&(n[0]=0,n[1]=0,n[2]=0);const c={px:[2,1,0,-1,-1,1],nx:[2,1,0,1,-1,-1],py:[0,2,1,1,-1,-1],ny:[0,2,1,1,1,1],pz:[0,1,2,-1,-1,-1],nz:[0,1,2,1,-1,1]},u=["px","nx","py","ny","pz","nz"];t.initialize=function(){},t.onmessage=function(t,n){const r=t.data||{},{cubePixels:s,width:f,height:l}=r;if(!s||!f||!l){const t="Invalid parameters to create light projectEnvironmentMapCPU.";return console.error(r),void n({error:t})}const p=function(t,n,r){const s=new Array(9),f=[],l=[],p=[];for(let h=0;h<9;h++){const y=[0,0,0];for(let o=0;o<u.length;o++){const s=t[o],d=[0,0,0];let v=0,x=0;const A=c[u[o]];for(let t=0;t<r;t++)for(let o=0;o<n;o++){f[0]=o/(n-1)*2-1,f[1]=t/(r-1)*2-1,f[2]=-1,a(f,f),p[0]=f[A[0]]*A[3],p[1]=f[A[1]]*A[4],p[2]=f[A[2]]*A[5],l[0]=s[x++]/255,l[1]=s[x++]/255,l[2]=s[x++]/255;const c=s[x++]/255*7;l[0]*=c,l[1]*=c,l[2]*=c,e(d,d,l,i(p,h)*-f[2]),v+=-f[2]}e(y,y,d,1/v)}s[h]=o(y,y,1/6)}return s}(s.map((t=>new Uint8Array(t))),f,l);n(null,{shList:p})}}`;
|
|
33740
33905
|
|
|
33741
33906
|
registerGLTFLoaderBundle(gltfLoaderExport);
|
|
33742
|
-
maptalks.registerWorkerAdapter('@maptalks/terrain', code);
|
|
33907
|
+
maptalks.registerWorkerAdapter('@maptalks/terrain', code$1);
|
|
33908
|
+
maptalks.registerWorkerAdapter('maplight', code);
|
|
33743
33909
|
|
|
33744
|
-
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, MaskLayerMixin, MaskRendererMixin, Measure3DTool, RayCaster, VideoMask, Color$1 as color, earcut$1 as earcut, index as reshader, transcoders };
|
|
33910
|
+
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 };
|
|
33745
33911
|
|
|
33746
|
-
typeof console !== 'undefined' && console.log('@maptalks/gpu v0.
|
|
33912
|
+
typeof console !== 'undefined' && console.log('@maptalks/gpu v0.115.1');
|
|
33747
33913
|
//# sourceMappingURL=maptalksgpu.es.js.map
|