@maptalks/3dtiles 0.89.3 → 0.91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,23 @@
1
1
  /*!
2
- * @maptalks/3dtiles v0.89.3
2
+ * @maptalks/3dtiles v0.91.0
3
3
  * LICENSE : UNLICENSED
4
4
  * (c) 2016-2023 maptalks.org
5
5
  */
6
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("maptalks"),require("@maptalks/gl")):"function"==typeof define&&define.amd?define(["exports","maptalks","@maptalks/gl"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).maptalks=t.maptalks||{},t.maptalks,t.maptalksgl)}(this,(function(t,e,n){"use strict";function r(t){if(t&&t.t)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var s=r(e),i=r(n);const o='function(t){var e="undefined"!=typeof Float32Array?Float32Array:Array;function n(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}function r(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}function s(t,e,n){var r=e[0],s=e[1],o=e[2],i=e[3],a=e[4],c=e[5],u=e[6],f=e[7],l=e[8],h=e[9],y=e[10],m=e[11],d=e[12],p=e[13],b=e[14],w=e[15],T=n[0],g=n[1],A=n[2],_=n[3];return t[0]=T*r+g*a+A*l+_*d,t[1]=T*s+g*c+A*h+_*p,t[2]=T*o+g*u+A*y+_*b,t[3]=T*i+g*f+A*m+_*w,T=n[4],g=n[5],A=n[6],_=n[7],t[4]=T*r+g*a+A*l+_*d,t[5]=T*s+g*c+A*h+_*p,t[6]=T*o+g*u+A*y+_*b,t[7]=T*i+g*f+A*m+_*w,T=n[8],g=n[9],A=n[10],_=n[11],t[8]=T*r+g*a+A*l+_*d,t[9]=T*s+g*c+A*h+_*p,t[10]=T*o+g*u+A*y+_*b,t[11]=T*i+g*f+A*m+_*w,T=n[12],g=n[13],A=n[14],_=n[15],t[12]=T*r+g*a+A*l+_*d,t[13]=T*s+g*c+A*h+_*p,t[14]=T*o+g*u+A*y+_*b,t[15]=T*i+g*f+A*m+_*w,t}function o(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}function i(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}function a(t,e){var n=e[0],r=e[1],s=e[2],o=e[3],i=n+n,a=r+r,c=s+s,u=n*i,f=r*i,l=r*a,h=s*i,y=s*a,m=s*c,d=o*i,p=o*a,b=o*c;return t[0]=1-l-m,t[1]=f+b,t[2]=h-p,t[3]=0,t[4]=f-b,t[5]=1-u-m,t[6]=y+d,t[7]=0,t[8]=h+p,t[9]=y-d,t[10]=1-u-l,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function c(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function u(){var t=new e(3);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function f(t){var e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function l(t,n,r){var s=new e(3);return s[0]=t,s[1]=n,s[2]=r,s}function h(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function y(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t}function m(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function d(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function p(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function b(t,e){var n=e[0],r=e[1],s=e[2],o=n*n+r*r+s*s;return o>0&&(o=1/Math.sqrt(o),t[0]=e[0]*o,t[1]=e[1]*o,t[2]=e[2]*o),t}function w(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function T(t,e,n){var r=e[0],s=e[1],o=e[2],i=n[0],a=n[1],c=n[2];return t[0]=s*c-o*a,t[1]=o*i-r*c,t[2]=r*a-s*i,t}function g(t,e,n){var r=e[0],s=e[1],o=e[2],i=n[3]*r+n[7]*s+n[11]*o+n[15];return i=i||1,t[0]=(n[0]*r+n[4]*s+n[8]*o+n[12])/i,t[1]=(n[1]*r+n[5]*s+n[9]*o+n[13])/i,t[2]=(n[2]*r+n[6]*s+n[10]*o+n[14])/i,t}var A=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t},_=d,S=f;function M(t,e,n,r,s){return t[0]=e,t[1]=n,t[2]=r,t[3]=s,t}function O(t,e,n){var r=e[0],s=e[1],o=e[2],i=e[3];return t[0]=n[0]*r+n[4]*s+n[8]*o+n[12]*i,t[1]=n[1]*r+n[5]*s+n[9]*o+n[13]*i,t[2]=n[2]*r+n[6]*s+n[10]*o+n[14]*i,t[3]=n[3]*r+n[7]*s+n[11]*o+n[15]*i,t}function x(){var t=new e(4);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function I(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function v(t,e,n,r){var s=e[0],o=e[1],i=e[2],a=e[3],c=n[0],u=n[1],f=n[2],l=n[3],h=void 0,y=void 0,m=void 0,d=void 0,p=void 0;return(y=s*c+o*u+i*f+a*l)<0&&(y=-y,c=-c,u=-u,f=-f,l=-l),1-y>1e-6?(h=Math.acos(y),m=Math.sin(h),d=Math.sin((1-r)*h)/m,p=Math.sin(r*h)/m):(d=1-r,p=r),t[0]=d*s+p*c,t[1]=d*o+p*u,t[2]=d*i+p*f,t[3]=d*a+p*l,t}u(),function(){var t,n=(t=new e(4),e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var C,U=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};u(),l(1,0,0),l(0,1,0),x(),x(),C=new e(9),e!=Float32Array&&(C[1]=0,C[2]=0,C[3]=0,C[5]=0,C[6]=0,C[7]=0),C[0]=1,C[4]=1,C[8]=1;\n/*!\n * @maptalks/gltf-loader v0.89.1\n * LICENSE : UNLICENSED\n * (c) 2016-2023 maptalks.org\n */\nlet E=0;function P(t){return null==t}function N(t){return!P(t)}function B(t){return!P(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}function F(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 D(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 R(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function L(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r.buffer}const z=[],V=[],k=[],j=[0,0,0],q=I([]),G=[1,1,1];function H(t,e,n,r,s,o,i){const a=D(i);if((0===s||s===r*a.BYTES_PER_ELEMENT)&&o%a.BYTES_PER_ELEMENT==0){const s=new a(e,o,n*r);return t.set(s),t}0===s&&(s=r*a.BYTES_PER_ELEMENT);const c=new Uint8Array(r*a.BYTES_PER_ELEMENT);for(let i=0;i<n;i++){let n=null;const u=new Uint8Array(e,s*i+o,r*a.BYTES_PER_ELEMENT);c.set(u),n=new a(c.buffer,0,r);for(let e=0;e<r;e++)t[i*r+e]=n[e]}return t}const $="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function X(t,e,n){const r=new Uint8Array(t,e,n);return $.decode(r)}const J={get:function(t,e={}){e||(e={});const n=new AbortController,r=n.signal,s=F({},e);s.signal=r,s.method||(s.method="GET");const o=fetch(t,s).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=n,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={})=>(e||(e={}),e.responseType="arraybuffer",J.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?J.jsonp(t):((e=e||{}).responseType="json",J.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+E++;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(r){document.getElementsByTagName("head")[0].removeChild(n),n=null,delete window[e],t(r)},document.getElementsByTagName("head")[0].appendChild(n)})}};class K{constructor(t,e,n){this.s=t,this.decoders=e,this.o=n,this.images={},this.i={}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)}if(this.i[t.id])return this.i[t.id].then(()=>{const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)});if(R(t.uri)){const r=this.buffers[t.id]=L(t.uri),s=this.u(e,r);return this.getImageByBuffer(s,n)}return this.i[t.id]=J.getArrayBuffer(t.uri,null).then(r=>{const s=this.buffers[t.id]=r.data,o=this.u(e,s);return this.getImageByBuffer(o,n)})}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;return n[e.mimeType]?n[e.mimeType](t,{supportedFormats:this.o}):"image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType?(console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.l(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.i[t.id]?this.i[t.id].then(()=>this.images[t.id]):this.i[t.id]=this.l(t.id,e)}l(t,e){return new Promise((n,r)=>{this.s(e,(s,o)=>{s?r(s):(URL.revokeObjectURL(e),this.images[t]=o,n(this.images[t]))})})}}const Y=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],Q=[];class W{constructor(t,e,n){this.rootPath=t,this.gltf=e,this.h=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.m()}p(t,e){const n=this.gltf,r=n.accessors[e];if(void 0===r.bufferView)return this.accessors[r.id]=this.T(t,e,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const s=n.bufferViews[r.bufferView];return this.g(s).then(n=>{const{buffer:s,byteOffset:o}=n;return this.accessors[r.id]=this.T(t,e,s,o)})}g(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(R(e.uri)){const t=this.buffers[e.id]=L(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]=J.getArrayBuffer(t,null).then(r=>(n&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=r.data,byteOffset:0}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}T(t,e,n,r=0){const s=this.gltf,o=s.accessors[e],i=void 0!==o.bufferView?s.bufferViews[o.bufferView]:{},a=(i.byteOffset||0)+r,c=this.A(o.type),u=D(o.componentType),f=i.byteStride||0,l={array:void 0,name:t,accessorName:e,byteLength:o.count*c*u.BYTES_PER_ELEMENT,componentType:o.componentType,count:o.count,type:o.type,itemSize:c,max:o.max,min:o.min,extensions:o.extensions};if(o.min&&(l.min=o.min),o.max&&(l.max=o.max),n)if(this.h)l.byteStride=f,l.byteOffset=a+(o.byteOffset||0),!f||f===c*u.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(l.array=this._(n,o.count,c,a+(o.byteOffset||0),u),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(n,a,i.byteLength);else if(o.interleaved){l.byteStride=0,l.byteOffset=0;const t=new u(o.count*c);if(l.array=H(t,n,o.count,c,f,a+(o.byteOffset||0),o.componentType),l.extensions&&l.extensions.WEB3D_quantized_attributes&&c>2){const t=new Float32Array(l.array.length),{decodeMatrix:e}=l.extensions.WEB3D_quantized_attributes;for(let n=0;n<l.array.length;n+=c){Q[0]=l.array[n],Q[1]=l.array[n+1],Q[2]=l.array[n+2],Q[3]=1;const r=O(Q,Q,e);t[n]=r[0],t[n+1]=r[1],t[n+2]=r[2]}l.componentType=5126,l.array=t}}else l.byteStride=0,l.array=this._(n,o.count,c,a+(o.byteOffset||0),u),l.byteOffset=l.array.byteOffset;else{l.array=new u(o.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}m(){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)}_(t,e,n,r,s){return r%s.BYTES_PER_ELEMENT!=0&&(t=t.slice(r,r+e*n*s.BYTES_PER_ELEMENT),r=0),new s(t,r,n*e)}A(t){const e=Y.indexOf(t);return Y[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.g(e).then(r=>{const{buffer:s,byteOffset:o}=r,i=X(s,o+(e.byteOffset||0),n);return t.content=i,t})}if(t.uri){if(R(t.uri)){const e=L(t.uri),n=X(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return J.get(e).then(e=>(t.content=e,t))}}return Promise.resolve(t)});return Promise.all(n).then(()=>t)}}class Z extends K{constructor(t,e,n,r,s,o){super(r,s,o),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new W(t,e,n)}iterate(t,e){const n=this.gltf[e];if(!n)return;let r=0;for(const e in n)t(e,n[e],r++)}createNode(t){const e={};if(N(t.name)&&(e.name=t.name),N(t.children)&&(e.children=t.children),N(t.jointName)&&(e.jointName=t.jointName),N(t.matrix)&&(e.matrix=t.matrix),N(t.rotation)&&(e.rotation=t.rotation),N(t.scale)&&(e.scale=t.scale),N(t.translation)&&(e.translation=t.translation),N(t.extras)&&(e.extras=t.extras),N(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=o(z,e.translation||j),r=a(V,e.rotation||q),c=i(k,e.scale||G);return s(c,r,c),s(t,n,c)}return r(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}S(t){const e={};for(const n in t){const r=t[n];let s,o;r.instanceTechnique&&r.instanceTechnique.values?(s=r.instanceTechnique,o=s.values.diffuse):(s=r,o=s.values.tex||s.values.diffuseTex||s.values.diffuse);const i={baseColorTexture:{index:o}};r.name&&(i.name=r.name),r.extensions&&(i.extensions=r.extensions),r.extras&&(i.extras=r.extras),e[n]=i}return e}M(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],r=(n.byteOffset||0)+this.glbBuffer.byteOffset,s=n.byteLength,o=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,s);return this.getImageByBuffer(o,t)}return this.requestExternalImage(t)}O(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.M(n).then(t=>{const r=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:r}})}getBaseColorTexture(t){const e=this.gltf.materials[t];let n,r;if(e.instanceTechnique&&e.instanceTechnique.values?(n=e.instanceTechnique,r=n.values.diffuse):(n=e,r=n.values.tex||n.values.diffuseTex||n.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const s=this.gltf.textures[r];if(!s)return null;const o=this.gltf.samplers[s.sampler];return{format:s.format||6408,internalFormat:s.internalFormat||6408,type:s.type||5121,sampler:o,source:this.gltf.images[s.source]}}getMaterial(){return null}getAnimations(){return null}}class tt extends K{constructor(t,e,n,r,s,o){super(r,s,o),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new W(t,e,n)}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 F(e,t),!N(t.weights)&&this.gltf.meshes&&N(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}O(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),!N(n))return null;const r=this.gltf.images[n];return this.M(r).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:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};F(n,e);const s=N(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return s&&(n.sampler=s,n.sampler.magFilter=s.magFilter||9729,n.sampler.minFilter=s.minFilter||9729,n.sampler.wrapS=s.wrapS||10497,n.sampler.wrapT=s.wrapT||10497),t.format&&(n.format=t.format),n})}M(t){if(!N(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.I(e,t)}return null}I(t,e){const n=this.u(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}u(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}v(t,e){const n=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)n[e]=String.fromCharCode(t[e]);return n.join(""),"data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)))}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++)(N(t[n].input)||N(t[n].output))&&(e.push(this.accessor.p("input",t[n].input)),e.push(this.accessor.p("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 et="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class nt{static read(t,e=0,n=0){n||(n=t.byteLength);const r=new DataView(t,e,n),s=r.getUint32(4,!0);if(1===s)return nt.readV1(r,e);if(2===s)return nt.readV2(t,e);throw new Error("Unsupported glb version : "+s)}static readV1(t,e){const n=t.getUint32(8,!0),r=t.getUint32(12,!0);if(n!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb\'s byte length.");const s=rt(t.buffer,20+e,r);return{json:JSON.parse(s),glbBuffer:{byteOffset:20+e+r,buffer:t.buffer,byteLength:n}}}static readV2(t,e){let n,r,s;const o=new DataView(t,e+12);let i=0;for(;i<o.byteLength;){const a=o.getUint32(i,!0);i+=4;const c=o.getUint32(i,!0);if(i+=4,1313821514===c)n=rt(t,e+12+i,a);else if(5130562===c){s=e+12+i,r=a;break}i+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function rt(t,e,n){if(et){const r=new Uint8Array(t,e,n);return et.decode(r)}return function(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=st[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}(new Uint8Array(t,e,n))}const st=[1,1,1,1,2,2,3,0],ot=[0,0,0],it=[0,0,0,1],at=[1,1,1],ct={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},ut={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},ft={C(t,e,n,r,s,o,i,a){const c=N(t)?e.animations:[e.animations[0]],u={};for(let e=0;e<c.length;e++){const f=c[e],l=f.name||e;if(N(t)&&l!==t)continue;const y=f.channelsMap[n];if(y)for(let t=0;t<y.length;t++){const e=y[t];"translation"===e.target.path?(this.U(s,f.samplers[e.sampler],r,1),u.translation=h(ot,s)):"rotation"===e.target.path?(this.P(o,f.samplers[e.sampler],r,1),u.rotation=U(it,o)):"scale"===e.target.path?(this.U(i,f.samplers[e.sampler],r,1),u.scale=h(at,i)):"weights"===e.target.path&&a&&(this.U(a,f.samplers[e.sampler],r,a.length),u.weights=a)}}return u},U(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.N(ut,e,n,1*r);s&&(t=function(t,e,n,r){for(let s=0;s<t.length;s++)t[s]=e[s]+r*(n[s]-e[s]);return t}(t,s.PREVIOUS,s.NEXT,s.INTERPOLATION));break}case"STEP":{const s=this.N(ut,e,n,1*r);s&&(t=function(t,e){for(let n=0;n<t.length;n++)t[n]=e[n];return t}(t,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.N(ut,e,n,3*r);s&&(t=this.B(t,s,e.input.array,3*r));break}}return t},P(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.N(ut,e,n,1);r&&v(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.N(ut,e,n,1);r&&(t=M(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.N(ut,e,n,3);if(r){for(let t=0;t<r.PREVIOUS.length;t++)r.PREVIOUS[t]=Math.acos(r.PREVIOUS[t]),r.NEXT[t]=Math.acos(r.NEXT[t]);t=this.B(t,r,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 r,s,o,i=0,a=n-1,c=Math.floor((i+a)/2);for(;i<=n-1&&a>=0;){if(i===a)return null;if(t[c]<=e&&e<=t[c+1]){const n=t[c];return r=c,s=c+1,o=(e-n)/(t[c+1]-n),{preIndx:r,nextIndex:s,interpolation:o}}e<t[c]?(a=c,c=Math.floor((i+a)/2)):t[c+1]<e&&(i=c,c=Math.floor((i+a)/2))}return null},N(t,e,n,r){const s=e.input.array,o=e.output.array,i=e.output.itemSize;(n<s[0]||n>s[s.length-1])&&(n=Math.max(s[0],Math.min(s[s.length-1],n))),n===s[s.length-1]&&(n=s[0]);const a=this.F(s,n);if(!a||!a.nextIndex)return null;const{preIndx:c,nextIndex:u,interpolation:f}=a;t.PREINDEX=c,t.NEXTINDEX=u,t.INTERPOLATION=f;const l=i*r;return t.PREVIOUS=o.subarray(t.PREINDEX*l,(t.PREINDEX+1)*l),t.NEXT=o.subarray(t.NEXTINDEX*l,(t.NEXTINDEX+1)*l),t},B(t,e,n,r){const s=e.INTERPOLATION,o=n[e.PREINDEX],i=n[e.NEXTINDEX];for(let n=0;n<3;n++){const a=e.PREVIOUS[r+n],c=(i-o)*e.PREVIOUS[2*r+n],u=e.NEXT[3+n],f=(i-o)*e.NEXT[n],l=(2*Math.pow(s,3)-3*Math.pow(s,2)+1)*a+(Math.pow(s,3)-2*Math.pow(s,2)+s)*c+(2*-Math.pow(s,3)+3*Math.pow(s,2))*u+(Math.pow(s,3)-Math.pow(s,2))*f;t[n]=l}return t},getAnimationClip(t,e,n,r){const s=t.nodes[e]&&t.nodes[e].weights;return y(ot,...ct.TRANSLATION),M(it,...ct.ROTATION),y(at,...ct.SCALE),this.C(r,t,e,n,ot,it,at,s)},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 r=-1/0,s=1/0;const o=e.channels;for(let t=0;t<o.length;t++){const n=o[t],i=e.samplers[n.sampler].input.array;i[i.length-1]>r&&(r=i[i.length-1]),i[0]<s&&(s=i[0])}const i=e.name||n;t.timeSpan[i]={max:r,min:s}}),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?N(e)?n[e]:n[Object.keys(n)[0]]:null}};let lt=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(ae){}t&&"undefined"!=typeof createImageBitmap&&(lt=!0)}const ht="undefined"==typeof document?null:document.createElement("canvas");class yt{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=nt.read(e.buffer,e.byteOffset,e.byteLength);this.D(t,n,r)}else this.D(t,e);this.R=new W(this.rootPath,this.gltf,this.glbBuffer),this.L()}L(){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.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}V(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.R.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then(e=>(t.KHR_techniques_webgl=e,t)):Promise.resolve(t)}load(t){t=t||{};const e=this.k(t),n=this.j(),r=this.q(),s=this.V();return Promise.all([e,n,r,s]).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,r){return ft.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return ft.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return D(t)}static readInterleavedArray(t,e,n,r,s,o,i){return H(t,e,n,r,s,o,i)}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=lt?bt.bind(this):this.options.requestImage||mt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new tt(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),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 Z(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"))}G(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||B(t.children[0])))return t;const r=t.children.map(t=>{const n=e[t];return n.nodeIndex=t,this.G(n,e)});t.children=r}var n;return t}k(t){return this.H(t).then(t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.G(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate((r,s,o)=>{const i={};s.name&&(i.name=s.name),s.nodes&&(i.nodes=s.nodes.map(e=>t[e])),this.gltf.scene===r&&(n=o),e.push(i)},"scenes");const r={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&&(r.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.S(this.gltf.materials);r.materials=t}return r})}H(t){return this.$(t).then(()=>{const t=this.nodes={};return this.adapter.iterate((e,n)=>{const r=this.adapter.createNode(n,this.meshes,this.skins);t[e]=r},"nodes"),t})}X(){this.skins=[];const t=[];return this.adapter.iterate((e,n,r)=>{t.push(this.J(n).then(t=>{t.index=r,this.skins.push(t)}))},"skins"),t}J(t){const e=t.inverseBindMatrices;return this.adapter.accessor.p("inverseBindMatrices",e).then(e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t))}j(){const t=this.gltf.animations;return N(t)?this.adapter.getAnimations(t):null}$(t){this.meshes={};let e=[];return this.adapter.iterate((n,r,s)=>{e.push(this.K(r,t).then(t=>{t.index=s,this.meshes[n]=t}))},"meshes"),e=e.concat(this.X()),Promise.all(e)}K(t,e){const n=t.primitives.map(t=>this.Y(t,e)).filter(t=>!!t);return Promise.all(n).then(e=>{const n={};return F(n,t),n.primitives=e,n})}q(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const n in t)e.push(this.adapter.O(n));return Promise.all(e).then(e=>{if(this.transferables)for(let t=0;t<e.length;t++){const n=e[t].image.array;if(e[t]&&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={},r=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(n[r[t]]=e[t]);return n}return e})}Y(t,e){let n;const r=[],s=t.extensions;if(N(t.targets))for(let e=0;e<t.targets.length;e++){const n=t.targets[e];for(const t in n){const s=this.adapter.accessor.p(`morphTargets_${t}_${e}`,n[t]);s&&r.push(s)}}if(s&&s.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:o,attributes:i}=s.KHR_draco_mesh_compression,a=this.gltf.bufferViews[o],c=this.R.g(a).then(n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:o}=a;const c=a.byteLength;o||(o=0);const u=new DataView(r,s+o,c),f={attributes:i,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(u,f).then(t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e})});r.push(c),n=Promise.all(r)}else{const e=t.attributes;for(const t in e){const n=this.adapter.accessor.p(t,e[t]);n&&r.push(n)}if(N(t.indices)){const e=this.adapter.accessor.p("indices",t.indices);e&&r.push(e)}n=Promise.all(r)}return n.then(e=>{if(s&&s.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,r;const o={attributes:e.reduce((t,e)=>{if("indices"===e.name)n=e;else if(e.name.indexOf("morphTargets_")>-1)r=r||{},r[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:r,array:s}=e,o=s.length/r;for(let e=0;e<o;e++)for(let o=0;o<r;o++){const i=e*r+o;s[i]<t[o]&&(t[o]=s[i]),s[i]>n[o]&&(n[o]=s[i])}if(e.quantization){const r=e.quantization,s=r.range/(1<<r.quantizationBits),o=r.minValues;p(t,t,s),m(t,t,o),p(n,n,s),m(n,n,o)}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&&(o.indices=n),r&&(o.morphTargets=r),o.mode=N(t.mode)?t.mode:4,N(t.extras)&&(o.extras=t.extras),o})}}function mt(t,e){const n=new Image;n.crossOrigin="",n.onload=()=>{if(!ht)return void e(new Error("There is no canvas to draw image!"));ht.width=n.width,ht.height=n.height;const t=ht.getContext("2d",{willReadFrequently:!0});t.drawImage(n,0,0,n.width,n.height);const r=t.getImageData(0,0,n.width,n.height),s={width:n.width,height:n.height,data:new Uint8Array(r.data)};e(null,s)},n.onerror=function(t){e(t)},n.src=t}let dt,pt;function bt(t,e){dt||(dt=new OffscreenCanvas(2,2),pt=dt.getContext("2d",{willReadFrequently:!0}));let n=null;if(B(t))n=fetch(t).then(t=>t.arrayBuffer()).then(t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)});else{const e=new Blob([t]);n=createImageBitmap(e)}n.then(wt.bind(this)).then(t=>{e(null,t)}).catch(t=>{console.warn(t),e(t)})}function wt(t){let{width:e,height:n}=t;Tt(e)||(e=gt(e)),Tt(n)||(n=gt(n));const r=this.options.maxTextureSize;r&&(e=Math.min(r,e),n=Math.min(r,n)),dt.width=e,dt.height=n,pt.drawImage(t,0,0,e,n),t.close();const s=pt.getImageData(0,0,e,n);return{width:e,height:n,data:new Uint8Array(s.data)}}function Tt(t){return 0==(t&t-1)&&0!==t}function gt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function At(t){return"object"==typeof t&&!!t}function _t(t){return t/Math.PI*180}function St(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const Mt=[1,1,1,1,2,2,3,0];function Ot(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=Mt[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}new Array(3),new Array(3);const xt=[1/6378137,1/6378137,1/6356752.314245179],It=[1/40680631590769,1/40680631590769,1/40408299984661.445],vt=new Array(3),Ct=new Array(3),Ut=new Array(3);function Et(t,e){const n=It,r=function(t,e,n,r,s){const o=e[0],i=e[1],a=e[2],c=n[0],u=n[1],f=n[2],l=o*o*c*c,h=i*i*u*u,y=a*a*f*f,m=l+h+y,d=Math.sqrt(1/m),b=p(Pt,e,d);if(m<s)return isFinite(d)?b:void 0;const w=r[0],T=r[1],g=r[2],A=Nt;A[0]=b[0]*w*2,A[1]=b[1]*T*2,A[2]=b[2]*g*2;let _,S,M,O,x,I,v,C,U,E,P,N=(1-d)*Bt(e)/(.5*Bt(A)),B=0;do{N-=B,M=1/(1+N*w),O=1/(1+N*T),x=1/(1+N*g),I=M*M,v=O*O,C=x*x,U=I*M,E=v*O,P=C*x,_=l*I+h*v+y*C-1,S=l*U*w+h*E*T+y*P*g;B=_/(-2*S)}while(Math.abs(_)>1e-12);return t[0]=o*M,t[1]=i*O,t[2]=a*x,t}(vt,e,xt,n,.1);let s=_(Ct,r,n);s=function(t,e){const n=e[0],r=e[1],s=e[2];let o=n*n+r*r+s*s;o>0&&(o=Math.sqrt(o),t[0]=e[0]/o,t[1]=e[1]/o,t[2]=e[2]/o);return t}(s,s);const o=A(Ut,e,r),i=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=St(w(o,e))*Bt(o);return t[0]=_t(i),t[1]=_t(a),t[2]=c,t}const Pt=new Array(3),Nt=new Array(3);function Bt(t){return f(t)}function Ft(t,e,n,r){n=n||0,r=r||n;const s=Math.abs(t-e);return s<=r||s<=n*Math.max(Math.abs(t),Math.abs(e))}function Dt(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const Rt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Lt(t,e,n){const r=new Uint8Array(t,e,n);return Rt?JSON.parse(Rt.decode(r)):JSON.parse(Ot(r))}function zt(t,e,n){const r=new Uint8Array(t,e,n);return Rt?JSON.parse(Rt.decode(r)):JSON.parse(Ot(r))}function Vt(t,e,n){return{offset:e,byteLength:n}}function kt(t,e,n,r){const{byteOffset:s,componentType:o,type:i}=t,{ctor:a,type:c}=function(t){return Gt[t]}(o||"UNSIGNED_SHORT"),u=function(t){if(!t)return 1;return qt[t]}(i);return{byteStride:0,byteOffset:s+n,itemSize:u,count:r*u,componentType:c,array:new a(e,n+s,r*u)}}function jt(t,e,n,r){const s=kt(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}const qt={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const Gt={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function Ht(t){for(const e in Gt)if(t===Gt[e].ctor)return Gt[e].type;throw new Error("unrecognized ctor:"+t)}function $t(t,e,n,r){const s=t,o=e.length/3;for(let t=0;t<o;t++)s[3*t]=e[3*t]/65535*r[0]+n[0],s[3*t+1]=e[3*t+1]/65535*r[1]+n[1],s[3*t+2]=e[3*t+2]/65535*r[2]+n[2];return s}function Xt(t,e,n){const r=t.getUint32(12,!0),s=t.getUint32(16,!0),o=t.getUint32(20,!0),i=t.getUint32(24,!0),a=t.buffer;let c,u={},f={},l=null;r>0&&(u=Lt(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),o>0&&(f=zt(a,e,o),e+=o);const h=Vt(0,e,i);return l=a.slice(h.offset,h.offset+h.byteLength),n.push(l),{featureTable:u,featureTableBin:c,batchTable:f,batchTableBin:l}}const Jt={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}},Kt={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Yt={},Qt={east:[],north:[],up:[],west:[],south:[],down:[]};let Wt=[],Zt=[],te=[];const ee=[0,0,0];const ne=function(t,e){const n=Jt[t][e];let r;const s=t+e;return Yt[s]?r=Yt[s]:(r=function(r,s,o){if(function(t,e){var n=t[0],r=t[1],s=t[2],o=e[0],i=e[1],a=e[2];return Math.abs(n-o)<=1e-6*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(r-i)<=1e-6*Math.max(1,Math.abs(r),Math.abs(i))&&Math.abs(s-a)<=1e-6*Math.max(1,Math.abs(s),Math.abs(a))}(r,ee))h(Wt,Kt[t]),h(Zt,Kt[e]),h(te,Kt[n]);else if(Ft(r[0],0,1e-14)&&Ft(r[1],0,1e-14)){const s=St(r[2]);h(Wt,Kt[t]),"east"!==t&&"west"!==t&&p(Wt,Wt,s),h(Zt,Kt[e]),"east"!==e&&"west"!==e&&p(Zt,Zt,s),h(te,Kt[n]),"east"!==n&&"west"!==n&&p(te,te,s)}else{!function(t,e){d(e,t,It),b(e,e)}(r,Qt.up);const s=Qt.up,o=Qt.east;o[0]=-r[1],o[1]=r[0],o[2]=0,b(Qt.east,o),T(Qt.north,s,o),p(Qt.down,Qt.up,-1),p(Qt.west,Qt.east,-1),p(Qt.south,Qt.north,-1),Wt=Qt[t],Zt=Qt[e],te=Qt[n]}return o[0]=Wt[0],o[1]=Wt[1],o[2]=Wt[2],o[3]=0,o[4]=Zt[0],o[5]=Zt[1],o[6]=Zt[2],o[7]=0,o[8]=te[0],o[9]=te[1],o[10]=te[2],o[11]=0,o[12]=r[0],o[13]=r[1],o[14]=r[2],o[15]=1,o},Yt[s]=r),r}("east","north"),re={5120:Int8Array,5122:Int16Array,5124:Int32Array,5121:Uint8Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function se(t){for(const e in re)if(t===re[e])return+e;throw new Error("unrecognized ctor:"+t)}\n/*!\n * @maptalks/gl v0.89.3\n * LICENSE : UNLICENSED\n * (c) 2016-2023 maptalks.com\n */const oe=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof undefined)return global;throw new Error("unable to locate global object")},ie=oe(),ae=ie.gl_trans__coders=ie.gl_trans__coders||{};ae.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=ie.gl_trans__coders=ie.gl_trans__coders||{};let o=`${r}\\n const _____getGlobal = ${oe.toString()};\\n const g___lobals = _____getGlobal()\\n const tran_____scoders = g___lobals[\'gl_trans__coders\'] = g___lobals[\'gl_trans__coders\'] || {};`;for(const t in s)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(o+=\'tran_____scoders["\'+t+\'"] =\'+s[t].toString()+"\\n;");return o+="\\n"+e.substring(r.length),o},ae.registerTranscoder=function(t,e){ae[t]=e},ae.getTranscoder=function(t){return ae[t]};let ce=null;function ue(){return ce||(ce={"image/crn":ae.crn&&ae.crn(),"image/ktx2":ae.ktx2&&ae.ktx2(),"image/cttf":ae.ktx2&&ae.ktx2(),"draco":ae.draco&&ae.draco()}),ce}class fe{constructor(t,e,n){this.s=t,this.W=e||yt,this.o=n,this.Z=ue()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.tt(t,e,n,r,s)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.tt(t,s,n,r)})}tt(t,e,n,r,s){const o=s&&s.maxTextureSize,i=this.et(e,n,r,t);if(i.error)return Promise.resolve(i);const a=t.substring(0,t.lastIndexOf("/")),c=new this.W(a,i.glb,{transferable:!0,requestImage:this.s,decoders:this.Z,supportedFormats:this.o,maxTextureSize:o});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<i.transferables.length;t++)s.indexOf(i.transferables[t])<0&&s.push(i.transferables[t]);return{magic:"b3dm",count:i.count,transferables:s,featureTable:i.featureTable,batchTable:i.batchTable,batchTableBin:i.batchTableBin,gltf:e}})}et(t,e,n,r){const s=new DataView(t,e,n),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported b3dm version: "+o+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm\'s byte length, url: "+r;return console.warn(t),{error:t}}let i,a=s.getUint32(12,!0),c=s.getUint32(16,!0),u=s.getUint32(20,!0),f=s.getUint32(24,!0),l=28+e;u>=570425344?(l-=8,i=a,u=c,f=0,a=0,c=0):f>=570425344&&(l-=4,i=u,u=a,f=c,a=0,c=0);const h=[t];let y,m,d;if(a>0?(y=Lt(t,l,a),l+=a,i=y.BATCH_LENGTH):y={"BATCH_LENGTH":i},c>0&&(l+=c),u>0&&(m=zt(t,l,u),l+=u,f>0)){const e=Vt(0,l,f);d=t.slice(e.offset,e.offset+e.byteLength),l+=f,h.push(d)}const p=y.BATCH_LENGTH,b={};if(y&&y.BATCH_ID){b.BATCH_ID=jt(y.BATCH_ID,t,(void 0).offset,p);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&h.indexOf(e)<0&&h.push(e)}return{count:i,transferables:h,featureTable:y,batchTable:m,batchTableBin:d,b3dm:b,glb:{buffer:t,byteOffset:l,byteLength:s.byteLength+s.byteOffset-l}}}nt(){return null}}class le{constructor(t,e,n,r){this.s=t,this.W=e||yt,this.o=n,this.Z=ue(),this.rt=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.tt(t,e,n,r,s)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.tt(t,s,n,r)})}tt(t,e,n,r,s){return this.st(t,e,n,r,s).then(({gltf:s,transferables:o})=>{const i=this.ot(e,n,r,t);if(i.error)return Promise.resolve(i);for(let t=0;t<o.length;t++)-1===i.transferables.indexOf(o[t])&&i.transferables.push(o[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:i.count,transferables:i.transferables,featureTable:i.featureTable,batchTable:i.batchTable,batchTableBin:i.batchTableBin,i3dm:i.i3dm,gltf:s})})}st(t,e,n,r,s){const o=s&&s.maxTextureSize,i={transferable:!0,requestImage:this.s,decoders:this.Z,supportedFormats:this.o,maxTextureSize:o},a=new DataView(e,n,r),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let r=Ot(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?J.getArrayBuffer(r,{}).then(t=>this.it(r,{buffer:t.data,byteOffset:0},i)):J.getJSON(r,{}).then(t=>this.it(r,t,i))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.it(t,r,i)}}it(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.W(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,o=0;return e.buffer&&(r=e.byteOffset||0,o=e.byteLength||0),n.url=`${t}-${r}-${o}`,{transferables:s.transferables,gltf:n}})}ot(t,e,n,r){const s=new DataView(t,e,n),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported pnts version: "+o+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts\'s byte length, url: "+r;return console.warn(t),{error:t}}const i=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=Xt(s,32+e,i),l={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;l.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.push(l.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;l.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.ct(new Uint16Array(t,r+c.offset,3*h),e,n)},i.push(l.POSITION.array.buffer)}if(a.BATCH_ID){l.BATCH_ID=jt(a.BATCH_ID,t,c.offset,h);const e=l.BATCH_ID.array&&l.BATCH_ID.array.buffer;e&&i.indexOf(e)<0&&i.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.push(l.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.ut(new Uint16Array(t,e+c.offset,2*h))},i.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.ut(new Uint16Array(t,e+c.offset,2*h))},i.push(l.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;l.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},i.push(l.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;l.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},i.push(l.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:u,batchTableBin:f,featureTable:a,i3dm:l,transferables:i}}ut(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)he(r,t[2*s],t[2*s+1],65535),n[3*s]=r[0],n[3*s+1]=r[1],n[3*s+2]=r[2];return n}ct(t,e,n){return $t(new Float32Array(t.length),t,e,n)}nt(){return null}}function he(t,e,n,r){if(t[0]=ye(e,r),t[1]=ye(n,r),t[2]=1-(Math.abs(t[0])+Math.abs(t[1])),t[2]<0){const e=t[0];t[0]=(1-Math.abs(t[1]))*me(e),t[1]=(1-Math.abs(e))*me(t[1])}return b(t,t)}function ye(t,e){return function(t,e,n){return t<e?e:t>n?n:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function me(t){return t<0?-1:1}class de{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.tt(t,e,n,r)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.tt(t,s,n,r)})}tt(t,e,n,r){return this.ft(e,n,r,t).then(t=>t.error?t:{magic:"pnts",count:t.count,transferables:t.transferables,featureTable:t.featureTable,batchTable:t.batchTable,batchTableBin:t.batchTableBin,pnts:t.pnts})}ft(t,e,n,r){const s=new DataView(t,e,n),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported pnts version: "+o+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts\'s byte length, url: "+r;return console.warn(t),{error:t}}const i=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=Xt(s,e+28,i),l=a.QUANTIZED_VOLUME_OFFSET,h=a.QUANTIZED_VOLUME_SCALE,y=a.POINTS_LENGTH;let m,d={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){d=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,d.byteOffset+c.offset,d.byteLength);const e={attributes:d.properties,useUniqueIDs:!1};return this.lt||(this.lt=ue().draco),this.lt(m,e).then(e=>{const n=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||n.POSITION||n.POSITION_QUANTIZED||(n.POSITION=a.POSITION,n.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||n.RGB||n.RGBA||n.RGB565||(n.RGB=a.RGB,n.RGBA=a.RGBA,n.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||n.NORMAL||n.NORMAL_OCT16P||(n.NORMAL=a.NORMAL,n.NORMAL_OCT16P=a.NORMAL_OCT16P);const r=this.ht(t,e.attributes,c.offset,y,i,l,h);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Ht(t.constructor),array:t},i.push(t.buffer)}else if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?r.BATCH_ID=jt(a.BATCH_ID,t,c.offset,y):r.BATCH_ID=pe(y);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&i.indexOf(e)<0&&i.push(e)}return{count:y,batchTable:u,batchTableBin:f,featureTable:a,pnts:r,transferables:i}})}const p=this.ht(t,a,c.offset,y,i,l,h);if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?p.BATCH_ID=jt(a.BATCH_ID,t,c.offset,y):p.BATCH_ID=pe(y);const e=p.BATCH_ID.array&&p.BATCH_ID.array.buffer;e&&i.indexOf(e)<0&&i.push(e)}return Promise.resolve({count:y,batchTable:u,batchTableBin:f,featureTable:a,pnts:p,transferables:i})}ht(t,e,n,r,s,o,i){const a={};if(e.POSITION){let{byteOffset:o,array:i}=e.POSITION;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+3*r*4);i=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:i},s.push(i.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c}=e.POSITION_QUANTIZED;const{array:u}=e.POSITION_QUANTIZED;c=c||0;const f=u?0:n;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:this.ct(u||new Uint16Array(t,c+f,3*r),o,i)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:o,array:i}=e.RGBA;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+4*r);i=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:i},s.push(i.buffer)}else if(e.RGB){let{byteOffset:o,array:i}=e.RGB;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+3*r);i=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:i},s.push(i.buffer)}else if(e.RGB565){let{byteOffset:o,array:i}=e.RGB565;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+2*r);i=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:i},s.push(i.buffer)}if(e.NORMAL){let{byteOffset:o,array:i}=e.NORMAL;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+3*r*4);i=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:i},s.push(i.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:o,array:i}=e.NORMAL_OCT16P;o=o||0;const c=i?0:n;if(!i){const e=t.slice(o+c,o+c+2*r);i=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:i},s.push(i.buffer)}return a}ct(t,e,n){return $t(new Float32Array(t.length),t,e,n)}nt(){return null}}function pe(t){const e=(n=t)<256?Uint8Array:n<65536?Uint16Array:Uint32Array;var n;const r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:Ht(e),array:r}}class be{constructor(t,e,n,r){this.o=n,this.s=t,this.W=e||yt,this.rt=r}load(t,e,n=0,r=0,s){return e?this.tt(t,e,n,r,s):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.tt(t,s,n,r)})}tt(t,e,n,r,s){r||(r=e.byteLength);const o=this.yt(e,t,n,r),i=[];for(let n=0;n<o.length;n++){let r;if("b3dm"===o[n].magic)r=new fe(this.s,this.W,this.o);else if("i3dm"===o[n].magic)r=new le(this.s,this.W,this.o,this.rt);else if("pnts"===o[n].magic)r=new de;else{if("cmpt"!==o[n].magic){console.warn("Unsupported magic in CMPT tile:",o[n].magic);continue}r=new be(this.s,this.W,this.o,this.rt)}i.push(r.load(t,e,o[n].offset,o[n].byteLength,s).then(t=>t))}return Promise.all(i).then(t=>({magic:"cmpt",tiles:t}))}yt(t,e,n,r){const s=new DataView(t,n,r),o=s.getUint32(4,!0);if(1!==o){const t="Unsupported cmpt version: "+o+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const i=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=Dt(s,c),r=s.getUint32(c+8,!0);i.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return i}}function we(t,e){if(t.scenes&&t.scenes.length)for(let n=0,r=t.scenes.length;n<r;n++){const r=t.scenes[n].nodes;for(let n=0,s=r.length;n<s;n++){const s=[];Oe(r[n],s,t,e)}}}const Te=[],ge=[],Ae=[],_e=[0,0,0],Se=I([]),Me=[1,1,1];function Oe(t,e,n,r){const c=e.slice(0);if(t.matrix)c.push(t.matrix);else if(t.rotation||t.translation||t.scale){const e=o(Te,t.translation||_e),n=a(ge,t.rotation||Se),r=i(Ae,t.scale||Me);s(r,n,r);const u=s([],e,r);c.push(u)}if(t.children&&t.children.length)for(let e=0,s=t.children.length;e<s;e++)Oe(t.children[e],c,n,r);if(void 0!==t.mesh){const e=t.mesh,s=n.meshes[e];if(s){const t=c.slice(0),o=s.primitives;for(let s=0,i=o.length;s<i;s++){const i=o[s];i&&(i.matrices=t,r(i,e,s,n))}}}}function xe(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:o,itemSize:i}=t,a=t.array.buffer,c=o?yt.getTypedArrayCtor(o):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/i,(!r||r===i*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*i);for(let r=0;r<s*i;r+=i){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,i),r/i)}return}const u=new Uint8Array(i*c.BYTES_PER_ELEMENT);r||(r=i*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,i*c.BYTES_PER_ELEMENT);u.set(s);e(new c(u.buffer),t),s.set(u)}}var Ie=Pe("DXT1"),ve=Pe("DXT3"),Ce=Pe("DXT5"),Ue=Pe("DX10"),Ee=function(t){var e,n,r=new Int32Array(t,0,31);if(542327876!==r[0])throw new Error("Invalid magic number in DDS header");if(4&!r[20])throw new Error("Unsupported format, must contain a FourCC code");var s=r[21];switch(s){case Ie:e=8,n="dxt1";break;case ve:e=16,n="dxt3";break;case Ce:e=16,n="dxt5";break;case 116:n="rgba32f";break;case Ue:var o=new Uint32Array(t.slice(128,148));n=o[0];var i=o[1];if(o[2],o[3],o[4],3!==i||2!==n)throw new Error("Unsupported DX10 texture format "+n);n="rgba32f";break;default:throw new Error("Unsupported FourCC code: "+(a=s,String.fromCharCode(255&a,a>>8&255,a>>16&255,a>>24&255)))}var a;var c=r[2],u=1;131072&c&&(u=Math.max(1,r[7]));var f=!1;512&r[28]&&(f=!0);var l,h=r[4],y=r[3],m=r[1]+4,d=h,p=y,b=[];s===Ue&&(m+=20);if(f)for(var w=0;w<6;w++){if("rgba32f"!==n)throw new Error("Only RGBA32f cubemaps are supported");h=d,y=p;for(var T=Math.log(h)/Math.log(2)+1,g=0;g<T;g++)l=h*y*16,b.push({offset:m,length:l,shape:[h,y]}),g<u&&(m+=l),h=Math.floor(h/2),y=Math.floor(y/2)}else for(g=0;g<u;g++)l=Math.max(4,h)/4*Math.max(4,y)/4*e,b.push({offset:m,length:l,shape:[h,y]}),m+=l,h=Math.floor(h/2),y=Math.floor(y/2);return{shape:[d,p],images:b,format:n,flags:c,cubemap:f}};function Pe(t){return t.charCodeAt(0)+(t.charCodeAt(1)<<8)+(t.charCodeAt(2)<<16)+(t.charCodeAt(3)<<24)}const Ne=Math.PI/180,Be=6378137*Math.PI/180;function Fe(t,e,n){if("EPSG:3857"===n)return function(t,e){const n=85.0511287798,r=e[0],s=Math.max(Math.min(n,e[1]),-n);let o;o=0===s?0:Math.log(Math.tan((90+s)*Ne/2))/Ne;return t[0]=r*Be,t[1]=o*Be,t}(t,e);if("EPSG:4326"===n||"EPSG:4490"===n||"identity"===n)return De(t,e);if("baidu"===n)return De(t,e);throw new Error("unsupported projection:"+n)}function De(t,e){return t[0]=e[0],t[1]=e[1],t}const Re=r([]),Le=ue().draco,ze=ue().ktx2,Ve={"pbrMetallicRoughness":{"baseColorFactor":[.5,.5,.5,1],"metallicFactor":0,"roughnessFactor":.5}},ke={"position":{name:"POSITION",accessor:{"componentType":5126,"type":"VEC3"}},"normal":{name:"NORMAL",accessor:{"componentType":5126,"type":"VEC3"}},"uv0":{name:"TEXCOORD_0",accessor:{"componentType":5126,"type":"VEC2"}},"color":{name:"COLOR_0",accessor:{"componentType":5121,"type":"VEC4"}},"uv-region":{name:"uvRegion",accessor:{"componentType":5123,"type":"VEC4"}},"feature-index":{name:"_BATCHID",accessor:{"componentType":5125,"type":"SCALAR"}},"faceRange":{name:"faceRange",accessor:{"componentType":5125,"type":"VEC2"}}};function je(t,e,n,s){const o=[],i=[],a=[];for(let e=0;e<t.meshes.length;e++){const{geometry:n,material:r}=t.meshes[e],s=J.getArrayBuffer(n.url);s.xhr.url=n.url,a.push(s.xhr);const c=s.then(t=>({buffer:t}));o.push(c);const u=[];if(Ke(r,u),u.length){const t=u.map(t=>{const e=J.getArrayBuffer(t.url);return e.xhr.url=t.url,a.push(e.xhr),e.then(e=>e&&e.status?null:{buffer:e,mimeType:t.mimeType,format:t.format})});o.push(...t)}i[e]=u.length}const c=Promise.all(o).then(o=>{for(let t=0;t<o.length;t++)if(!o[t]||!o[t].buffer)return Promise.resolve(null);const a=[];let c=0;for(let t=0;t<i.length;t++){const e=i[t];a.push({geoBuffer:{data:o[c].buffer.data},textureBuffers:o.slice(c+1,e+c+1).map(t=>({data:t.buffer.data,mimeType:t.mimeType,format:t.format}))}),c+=1+e}return function(t,e,n,s,o){const i={asset:{generator:"i3s",version:"2.0"},extensions:{},scene:0,scenes:[{nodes:[]}],nodes:{},meshes:{},materials:[],skins:[],animations:null,textures:[],transferables:[]},a=[];for(let c=0;c<t.meshes.length;c++){let{material:u}=t.meshes[c];const{geometry:f}=t.meshes[c];let l;const h=e[c].geoBuffer.data;if(!h)continue;const y=en(h);l=y?Ge(i,c,f,h,t.transform,t.center,o):$e(i,c,f,h,t.transform,t.center,o),a.push(l),i.nodes[c]={mesh:c,nodeIndex:c,matrix:r([])},i.scenes[0].nodes[c]=i.nodes[c],u||(u=Ve);const m=Je(c,i,u,e[c].textureBuffers,n,s);a.push(m)}return Promise.all(a).then(()=>({gltf:i,featureTable:{BATCH_LENGTH:0},transferables:i.transferables}))}(t,a,e,s,n)});return c.xhr=a,c}const qe={"magFilter":9728,"minFilter":9728,"wrapR":33071,"wrapS":33071,"wrapT":33071};function Ge(t,e,n,r,s,o,i){const a=n.info.compressedAttributes.attributes.reduce((t,e,n)=>{const r=ke[e];if(!r)return t;return t[r.name||e]=n,t},{});return Le(r,{attributes:a,metadatas:{"POSITION":[{name:"i3s-scale_x",type:"double"},{name:"i3s-scale_y",type:"double"}]},useUniqueIDs:!1,skipAttributeTransform:!1}).then(n=>Xe(n,t,e,s,o,i))}const He={position:function(t,e,n){const r=3*t.vertexCount,s=new Float32Array(e,n,r);return t.position={array:s,componentType:5126,itemSize:3,count:r/3,meta:{"i3s-scale_x":1,"i3s-scale_y":1},type:"VEC3"},n+=4*r},normal:function(t,e,n){const r=3*t.vertexCount,s=new Float32Array(e,n,r);return t.normal={array:s,componentType:5126,itemSize:3,count:r/3,type:"VEC3"},n+=4*r},uv0:function(t,e,n){const r=2*t.vertexCount,s=new Float32Array(e,n,r);return t.uv0={array:s,componentType:5126,itemSize:2,count:r/2,type:"VEC2"},n+=4*r},color:function(t,e,n){const r=4*t.vertexCount,s=new Uint8Array(e,n,r);return t.color={array:s,componentType:5121,itemSize:4,count:r/4,type:"VEC4"},n+=r},featureId:function(t,e,n){return n+=8*t.featureCount},id:function(t,e,n){return n+=8*t.featureCount},faceRange:function(t,e,n){const r=2*t.featureCount,s=new Uint32Array(e,n,r);return t.faceRange={array:s,componentType:5125,itemSize:2,count:r/2,type:"VEC2"},n+=4*r},uvRegion:function(t,e,n){const r=4*t.vertexCount,s=new Uint16Array(e,n,r);return t["uv-region"]={array:s,componentType:5123,itemSize:4,count:r/4,type:"VEC4"},n+=2*r},region:function(t,e,n){const r=4*t.vertexCount,s=new Uint16Array(e,n,r);return t["uv-region"]={array:s,componentType:5123,itemSize:4,count:r/4,type:"VEC4"},n+=2*r}};function $e(t,e,n,r,s,o,i){const a={vertexCount:0},c=new DataView(r);try{let t=0;a.vertexCount=c.getUint32(t,1),t+=4,a.featureCount=c.getUint32(t,1),t+=4;const e=n.info.ordering?null:n.info;if(e){const n=[];for(const t in e)"offset"!==t&&""!==t&&n.push(t);for(let e=0;e<n.length;e++)He[n[e]]?t=He[n[e]](a,r,t):console.error("Unknown decoder for",n[e])}else{const e=n.info;let s=e.ordering,o=e.featureAttributeOrder;const i=null;i&&i.geometryData&&i.geometryData[0]&&i.geometryData[0].params;for(let e=0;e<s.length;e++){const n=He[s[e]];n||console.log(s[e]),t=n(a,r,t)}for(let e=0;e<o.length;e++){const n=He[o[e]];n||console.log(o[e]),t=n(a,r,t)}}}catch(t){}a.scale_x=1,a.scale_y=1;const u={};for(const t in a){const e=ke[t]&&ke[t].name;e&&(u[e]=a[t])}if(a.faceRange){const t=a.faceRange.array,e=t.length/2,n=(f=e)<=255?Uint8Array:f<=65535?Uint16Array:Uint32Array,r=new n(u.POSITION.array.length/3);for(let e=0;e<t.length-1;e+=2){const n=e/2,s=t[e],o=t[e+1];for(let t=s;t<=o;t++)r[3*t]=n,r[3*t+1]=n,r[3*t+2]=n}u._BATCHID={componentType:se(n),array:r,itemSize:1,count:r.length,type:"SCALAR"}}var f;return Xe({attributes:u},t,e,s,o,i)}function Xe(t,e,n,r,s,o){const i={attributes:t.attributes,material:n,indices:t.indices,mode:4};!function(t){const e=t.array,n=t.meta&&t.meta["i3s-scale_x"],r=t.meta&&t.meta["i3s-scale_y"];if(n&&r&&(1!==n||1!==r))for(let t=0;t<e.length;t+=3)e[t]*=n.value,e[t+1]*=r.value}(t.attributes.POSITION);const a=function(t,e,n,r){const s=n;let o,i=[0,0,0,1];const a=[0,0],u=Fe([],n,r);u[2]=n[2];const f=e&&c(Re,e);return xe(t,t=>(i[0]=t[0],i[1]=t[1],i[2]=t[2],f||(i=g(i,i,e)),s&&m(i,i,s),Fe(a,i,r),o=i[2],t[0]=a[0]-u[0],t[1]=a[1]-u[1],t[2]=o-u[2],t)),u}(t.attributes.POSITION,r,s,o);e.meshes[n]={primitives:[i],index:n},e.extensions.MAPTALKS_RTC={projCenter:a},e.extensions.CESIUM_RTC={rtcCoord:s};for(const n in t.attributes)tn(e.transferables,t.attributes[n].array.buffer);return t.indices&&tn(e.transferables,t.indices.array.buffer),i}function Je(t,e,n,r,s,o){const i=r.map(t=>function(t,e,n,r,s){if("dds"===e){const e=Ee(t),r=e.images.map(e=>new Uint8Array(t,e.offset,e.length)),s="dxt1"===e.format?33777:33779;return Promise.resolve({image:{mipmap:r,width:e.shape[0],height:e.shape[1],mimeType:n},sampler:qe,format:s})}if("png"===e||"jpg"===e)return function(t,e){Ye||(Ye=new OffscreenCanvas(2,2),Qe=Ye.getContext("2d",{willReadFrequently:!0}));const n=new Blob([new Uint8Array(t)]);return createImageBitmap(n).then(t=>{let{width:n,height:r}=t;We(n)||(n=Ze(n)),We(r)||(r=Ze(r));const s=e;s&&(n=Math.min(s,n),r=Math.min(s,r)),Ye.width=n,Ye.height=r,Qe.drawImage(t,0,0,n,r),t.close();const o=Qe.getImageData(0,0,n,r);return{width:n,height:r,array:new Uint8Array(o.data)}}).catch(()=>({width:2,height:2,array:new Uint8Array(4)}))}(t,s).then(t=>{t.mimeType=n;return{image:t,sampler:qe,format:6408}});if("ktx2"===e)return ze(t,r).then(t=>(t.mimeType=n,{image:t,sampler:qe,format:t.format}));return null}(t.data,t.format,t.mimeType,s,o).then(t=>{if(t.image)if(t.image.array)tn(e.transferables,t.image.array.buffer);else if(t.image.mipmap)for(let n=0;n<t.image.mipmap.length;n++)tn(e.transferables,t.image.mipmap[n].buffer);return t}));return Promise.all(i).then(r=>{!function t(e,n,r,s){const o=JSON.parse(JSON.stringify(r)),i=n.textures;s.ptr||(s.ptr=0);for(const e in r)r[e]&&r[e].url?(i.push(s[s.ptr++]),o[e]={index:i.length-1},void 0!==r[e].factor&&(o[e].scale=r[e].factor)):At(r[e])&&(o[e]=t(-1,n,r[e],s));e>=0&&(n.materials[e]=o);return o}(t,e,n,r)})}function Ke(t,e){for(const n in t)t[n]&&t[n].url?e.push({url:t[n].url,mimeType:t[n].mimeType,format:t[n].format}):At(t[n])&&Ke(t[n],e)}let Ye,Qe;function We(t){return 0==(t&t-1)&&0!==t}function Ze(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function tn(t,e){e&&(t.indexOf(e)>=0||t.push(e))}function en(t){const e=new Uint8Array(t,0,5);return e[0]==="D".charCodeAt()&&e[1]==="R".charCodeAt()&&e[2]==="A".charCodeAt()&&e[3]==="C".charCodeAt()&&e[4]==="O".charCodeAt()}const nn=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],rn=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],sn=2*Math.PI*6378137/360,on="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;let an,cn=!1;if("undefined"!=typeof OffscreenCanvas){try{an=new OffscreenCanvas(2,2).getContext("2d",{willReadFrequently:!0})}catch(t){}an&&"undefined"!=typeof createImageBitmap&&(cn=!0)}const un=r([]),fn=[0,0,0],ln=[],hn=[],yn=[],mn=[],dn={"POSITION":1,"TEXCOORD_0":1,"TEXCOORD_1":1,"NORMAL":1,"TANGENT":1};class pn{constructor(t,e,n,r){this.id=t,this.options=e,this.dt=this.requestImage.bind(this),this.pt=n,this.bt={},r(null,{},[])}wt(t){this.Tt||(this.o=t,this.gt=new de,this.Tt=new fe(this.dt,yt,t),this.At=new le(this.dt,yt,t))}requestImage(t,e){cn?fetch(t).then(t=>t.arrayBuffer()).then(t=>{const e=new self.Blob([new Uint8Array(t)]);return createImageBitmap(e)}).then(t=>{(void 0).width=t.width,(void 0).height=t.height,an.drawImage(t,0,0);const n=an.getImageData(0,0,(void 0).width,(void 0).height);t.close(),e(null,{width:t.width,height:t.height,data:new Uint8Array(n.data)})}):this.pt("requestImage",{url:t},null,e)}loadTile(t,e){this.wt(t.supportedFormats);const n=t.service,r=t.url,s=t.arraybuffer;if(function(t){return t.indexOf("i3s:")>=0}(r)){const s=t.i3sInfo,o=n.maxTextureSize||1024,i=je(s,t.supportedFormats,this.options.projection,o);return i.then(t=>{if(delete this.bt[r],!t)return void e({status:404,url:r,i3sInfo:s});if(!Object.keys(t.gltf.meshes).length)return void e({status:404,url:r,i3sInfo:s});t.gltf.url=r;const{transferables:n}=t;t.magic="b3dm",this._t(t.gltf),e(null,t,n)}),void(this.bt[r]=i.xhr)}if(s){delete this.bt[r];const n=Dt(new DataView(s),0);if("{"===n[0]||" "===n[0]||"<"===n[0]){const n=function(t,e,n){if(on){const r=new Uint8Array(t,e,n);return on.decode(r)}return Ot(new Uint8Array(t,e,n))}(s,0,s.byteLength),o=JSON.parse(n);this.St(t.rootIdx,o,s,r,e)}else this.Mt(s,r,t,n,e)}else{let s=n.urlParams;s&&(s=(r.indexOf("?")>0?"&":"?")+s);const o=r.replace(/\\+/g,"%2B");let i=J.getArrayBuffer(o+(s||""),n.fetchOptions);const a=i.xhr;i=i.then(n=>{delete this.bt[r],n&&n.status?e(n):(t.arraybuffer=n&&n.data,this.loadTile(t,e))}).catch(t=>{delete this.bt[r],e(t)}),this.bt[r]=a}}Mt(t,e,n,r,s){const o=n.service;if("b3dm"===r){this.Tt.load(e,t,0,0,{maxTextureSize:o.maxTextureSize||1024}).then(t=>{if(t.error)return void s(t);const{content:e,transferables:r}=this.Ot(t,n);this._t(e.gltf),s(null,e,r)}).catch(t=>{s(t)})}else if("pnts"===r){const r=n.transform;this.gt.load(e,t).then(t=>{const{content:e,transferables:o}=this.xt(t,r,n.rootIdx);this.It(e),s(null,e,o)})}else if("i3dm"===r){const r=n.transform;this.At.load(e,t,0,0,{maxTextureSize:o.maxTextureSize||1024}).then(t=>{const{content:e,transferables:o}=this.xt(t,r,n.rootIdx);this._t(e.gltf),s(null,e,o)})}else if("cmpt"===r){new be(this.dt,yt,this.o,o.maxTextureSize||1024).load(e,t,0,0,{maxTextureSize:o.maxTextureSize||1024}).then(t=>{const{content:e,transferables:r}=this.vt(t,n);this.Ct(e),s(null,e,r)}).catch(t=>{s(t)})}}Ct(t){t.content?t.content.forEach(t=>{this.Ct(t)}):this._t(t.gltf)}_t(t){if(!t||!t.meshes||t.extensionsUsed&&t.extensionsUsed.indexOf("KHR_techniques_webgl")>-1)return;const e=t.meshes;for(const t in e){e[t].primitives.forEach(t=>{t.compressed_int16_params={};const e=t.attributes;for(const n in e)if(dn[n]&&e[n].array&&e[n].array instanceof Float32Array){const r=this.options.projection;let s=1;"EPSG:4326"!==r&&"EPSG:4490"!==r||"POSITION"!==n||(s=sn,t.compressed_int16_params.compressed_ratio=s);const{array:o,range:i}=_n(e[n].array,s,e[n].min,e[n].max);e[n].array=o,t.compressed_int16_params[n]=i}})}}It(t){if(!t||!t.pnts)return;const e=t.pnts;t.compressed_int16_params={};for(const n in e)if(dn[n]&&e[n].array&&e[n].array instanceof Float32Array){const{array:r,range:s}=_n(e[n].array,e[n].min,e[n].max);e[n].array=r,t.compressed_int16_params[n]=s}}Ut(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n];if(!r.childTile)continue;const s={boundingVolume:{sphere:[r.boundingSphere.center.x,r.boundingSphere.center.y,r.boundingSphere.center.z,r.boundingSphere.radius]},content:{uri:r.childTile},geometricError:r.boundingSphere.radius/r.rangeList*16,refine:"REPLACE"};e.push(s)}return e}St(t,e,n,r,s){return e.capabilities,void s(null,e)}vt(t,e){const{tiles:n}=t,r={magic:"cmpt",content:[]},s=[];for(let t=0;t<n.length;t++){const{magic:o}=n[t];if("b3dm"===o){const{content:o,transferables:i}=this.Ot(n[t],e);gn(s,i),r.content.push(o)}else if("i3dm"===o||"pnts"===o){const{transform:o,rootIdx:i}=e,{content:a,transferables:c}=this.xt(n[t],o,i);gn(s,c),r.content.push(a)}else if("cmpt"===o){const{content:o,transferables:i}=this.vt(n[t],e);gn(s,i),r.content.push(o)}}return{content:r,transferables:s}}Ot(t,e){const{gltf:n,transferables:r,featureTable:s}=t,o=function(t){if(!t||!t.meshes)return!1;let e=1;const n=[];for(const r in t.meshes){const s=t.meshes[r],{primitives:o}=s;if(o)for(let t=0;t<o.length;t++){const r=o[t].attributes&&o[t].attributes.POSITION;if(!r||!r.array)continue;r.array.buffer.visited||(r.array.buffer.visited=e++);const s=e-1+"-"+(r.byteOffset||0);if(n.indexOf(s)>=0)return!0;n.push(s)}}return!1}(n);return this.Et(t.gltf),t.gltf.asset||(t.gltf.asset={}),o?(t.gltf.asset.sharePosition=!0,this.Pt(n,s,e.upAxis,e.transform)):this.Nt(n,s,e.upAxis,e.transform),delete t.transferables,{content:t,transferables:r}}xt(t,e,r){const{featureTable:s}=t,o=t.pnts||t.i3dm,i=s&&s.RTC_CENTER||[0,0,0];if(s.EAST_NORTH_UP&&!o.NORMAL_UP&&!o.NORMAL_UP_OCT32P){const e=new Float32Array(3*o.POSITION.array.length),r=[],s=[],a=[];xe(o.POSITION,(t,o)=>{m(a,t,i),ne(a,null,r),n(s,r);!function(t,e){t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8]}(e.subarray(9*o,9*(o+1)),s)}),o.INSTANCE_ROTATION={byteStride:0,byteOffset:0,itemSize:9,componentType:5126,array:e},t.transferables.push(e.buffer)}const a={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};wn(o.POSITION.array,3,i,un,a);const c=Tn(a),u=h([],c),f=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];xe(o.POSITION,t=>{t[0]=t[0]+i[0]-u[0],t[1]=t[1]+i[1]-u[1],t[2]=t[2]+i[2]-u[2],t[0]<f[0]&&(f[0]=t[0]),t[1]<f[1]&&(f[1]=t[1]),t[2]<f[2]&&(f[2]=t[2]),t[0]>l[0]&&(l[0]=t[0]),t[1]>l[1]&&(l[1]=t[1]),t[2]>l[2]&&(l[2]=t[2])}),o.POSITION.min=f,o.POSITION.max=l,e&&g(c,c,e);const y=this.Bt(c);t.rtcCenter=u,t.rtcCoord=y,t.rootIdx=r;const d=t.transferables;return delete t.transferables,{content:t,transferables:d}}Et(t){if(!Array.isArray(t.textures))return;const e=t.textures;for(let t=0;t<e.length;t++){const n=e[t].image&&e[t].image.array;if(n&&n.length){const r=n[0],s=n[1],o=n[2],i=n[3];let a=!0;for(let t=4;t<n.length;t+=4)if(n[t]!==r||n[t+1]!==s||n[t+2]!==o||n[t+3]!==i){a=!1;break}a&&(e[t].image.color=[r/255,s/255,o/255,i/255],delete e[t].image.array)}}}abortTileLoading(t,e){const n=this.bt[t.url];if(Array.isArray(n))for(let t=0;t<n.length;t++)n[t].abort();else n&&n.abort&&n.abort();delete this.bt[t.url],e(null)}Ft(t,e,n,o){const i=e&&e.RTC_CENTER||t.extensions&&t.extensions.CESIUM_RTC&&t.extensions.CESIUM_RTC.center;let a=nn;"X"===(n=n&&n.toUpperCase())?a=rn:"Z"===n&&(a=un),t.extensions=t.extensions||{},t.extensions.CESIUM_RTC||(t.extensions.CESIUM_RTC={}),i&&(t.extensions.CESIUM_RTC.center=i),t.extensions.MAPTALKS_RTC={};const c={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};we(t,t=>{if(!(t.attributes&&t.attributes.POSITION))return;const e=r(ln);t.matrices&&An(e,t.matrices);const n=t.attributes.POSITION.array,u=t.attributes.POSITION.itemSize;s(e,a,e),o&&s(e,o,e),wn(n,u,i||fn,e,c,t.compressUniforms)});const u=Tn(c);return{rtcCenter:i,modelCenter:u,upAxisTransform:a}}Pt(t,e,n,o){const{modelCenter:i,upAxisTransform:a,rtcCenter:c}=this.Ft(t,e,n),u=h([],i);o&&g(i,i,o),t.extensions.CESIUM_RTC.rtcCoord=this.Bt(i),c||(we(t,t=>{if(t.attributes&&t.attributes.POSITION){const e=t.attributes.POSITION;if(e.array.buffer.projected&&e.array.buffer.projected[e.byteOffset])return;const n=r(ln);t.matrices&&An(n,t.matrices),s(n,a,n);const o=function(t,e){var n=e[0],r=e[1],s=e[2],o=e[3],i=e[4],a=e[5],c=e[6],u=e[7],f=e[8],l=e[9],h=e[10],y=e[11],m=e[12],d=e[13],p=e[14],b=e[15],w=n*a-r*i,T=n*c-s*i,g=n*u-o*i,A=r*c-s*a,_=r*u-o*a,S=s*u-o*c,M=f*d-l*m,O=f*p-h*m,x=f*b-y*m,I=l*p-h*d,v=l*b-y*d,C=h*b-y*p,U=w*C-T*v+g*I+A*x-_*O+S*M;return U?(U=1/U,t[0]=(a*C-c*v+u*I)*U,t[1]=(s*v-r*C-o*I)*U,t[2]=(d*S-p*_+b*A)*U,t[3]=(h*_-l*S-y*A)*U,t[4]=(c*x-i*C-u*O)*U,t[5]=(n*C-s*x+o*O)*U,t[6]=(p*g-m*S-b*T)*U,t[7]=(f*S-h*g+y*T)*U,t[8]=(i*v-a*x+u*M)*U,t[9]=(r*x-n*v-o*M)*U,t[10]=(m*_-d*g+b*w)*U,t[11]=(l*g-f*_-y*w)*U,t[12]=(a*O-i*I-c*M)*U,t[13]=(n*I-r*O+s*M)*U,t[14]=(d*T-m*A-p*w)*U,t[15]=(f*A-l*T+h*w)*U,t):null}(hn,n),i=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];xe(e,t=>{g(t,t,n),t[0]=t[0]-u[0],t[1]=t[1]-u[1],t[2]=t[2]-u[2],g(t,t,o),t[0]<i[0]&&(i[0]=t[0]),t[1]<i[1]&&(i[1]=t[1]),t[2]<i[2]&&(i[2]=t[2]),t[0]>c[0]&&(c[0]=t[0]),t[1]>c[1]&&(c[1]=t[1]),t[2]>c[2]&&(c[2]=t[2])}),e.min=i,e.max=c,e.array.buffer.projected||(e.array.buffer.projected={}),e.array.buffer.projected[e.byteOffset]=1}}),t.extensions.CESIUM_RTC.center=u)}Nt(t,e,n,r){const{modelCenter:s,rtcCenter:o}=this.Ft(t,e,n,r),i=this.Dt(s);t.extensions.MAPTALKS_RTC.projCenter=i,t.extensions.CESIUM_RTC.rtcCoord=this.Bt(s),we(t,e=>{if(e.attributes&&e.attributes.POSITION){e.attributes.NORMAL&&this.Rt(e.attributes.NORMAL,e.matrices,n),e.attributes.TANGENT&&this.Rt(e.attributes.TANGENT,e.matrices,n);const{newPositions:s}=this.Lt(e.attributes.POSITION,e.matrices,o,t.extensions.MAPTALKS_RTC,n,r,e.compressUniforms),{componentType:i}=e.attributes.POSITION;5126!==i&&(e.attributes.POSITION.array=new Float32Array(s))}});for(const e in t.nodes){t.nodes[e].matrix=un}}Dt(t){0===S(t)?y(yn,0,0,-6378137):Et(yn,t);const e=this.options.projection;Fe(mn,yn,e);const n=yn[2],r=[];return r[0]=mn[0],r[1]=mn[1],r[2]=n,r}Rt(t,e,r){let s;s="Y"===r?nn:"X"===r?rn:un;const o=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}([],s);if(An(o,e),c(o,un))return;const i=n([],o),a=[];xe(t,t=>(function(t,e,n){var r=e[0],s=e[1],o=e[2];t[0]=r*n[0]+s*n[3]+o*n[6],t[1]=r*n[1]+s*n[4]+o*n[7],t[2]=r*n[2]+s*n[5]+o*n[8]}(a,t,i),b(a,a),h(t,a),a))}Lt(t,e,n,s,o,i,a){if(t.array.buffer.projected&&t.array.buffer.projected[t.byteOffset])return null;const u=r([]);An(u,e);const f=this.options.projection;o=o&&o.toUpperCase();const l=n;let h=null;"Y"===o?h=nn:"X"===o&&(h=rn);let d=[0,0,0,1];const p=[0,0,0],b=[0,0],w=s.projCenter,T=i&&c(un,i),A=t.min=t.min||[],_=t.max=t.max||[];y(A,1/0,1/0,1/0),y(_,-1/0,-1/0,-1/0);const M=a||{},{decode_position_min:O,decode_position_normConstant:x}=M;let I=[0,0,0,0],v=1;O&&(I=O),x&&(v=x);const C=[];return xe(t,t=>{if(d[0]=t[0]*v+I[0],d[1]=t[1]*v+I[1],d[2]=t[2]*v+I[2],d=g(d,d,u),h&&(d=g(d,d,h)),l&&m(d,d,l),i&&!T&&(d=g(d,d,i)),0===S(d)?y(p,0,0,-6378137):Et(p,d),Fe(b,p,f),t instanceof Float32Array)t[0]=b[0]-w[0],t[1]=b[1]-w[1],t[2]=p[2]-w[2];else{const e=b[0]-w[0],n=b[1]-w[1],r=p[2]-w[2];C.push(e),C.push(n),C.push(r),C.push(t[3])}return t[0]<A[0]&&(A[0]=t[0]),t[1]<A[1]&&(A[1]=t[1]),t[2]<A[2]&&(A[2]=t[2]),t[0]>_[0]&&(_[0]=t[0]),t[1]>_[1]&&(_[1]=t[1]),t[2]>_[2]&&(_[2]=t[2]),t}),t.array.buffer.projected||(t.array.buffer.projected={}),t.array.buffer.projected[t.byteOffset]=1,{projCenter:w,newPositions:C}}Bt(t){return 0===S(t)?y([],0,0,-6378137):Et([],t)}onRemove(){}}const bn=[];function wn(t,e,n,r,s,o){const i=o||{},{decode_position_min:a,decode_position_normConstant:c}=i;let u=[0,0,0,0],f=1;a&&(u=a),c&&(f=c);for(let o=0,i=t.length;o<i;o+=e){const{xmin:i,ymin:a,xmax:c,ymax:l,hmin:h,hmax:d}=s;y(bn,t[o]*f+u[0],t[o+1]*f+u[1],t[o+2]*f+u[2]),g(bn,bn,r);const p=m(bn,n,bn);p[0]<i&&(s.xmin=p[0]),p[0]>c&&(s.xmax=p[0]),p[1]<a&&(s.ymin=p[1]),p[1]>l&&(s.ymax=p[1]),e>2&&(p[2]<h&&(s.hmin=p[2]),p[2]>d&&(s.hmax=p[2]))}}function Tn(t){const{xmax:e,ymax:n,xmin:r,ymin:s,hmin:o,hmax:i}=t,a=[(r+e)/2,(s+n)/2,(o+i)/2];return e===-1/0&&(a[0]=0),n===-1/0&&(a[1]=0),i===-1/0&&(a[2]=0),isNaN(a[2])&&(a[2]=0),a}function gn(t,e){for(let n=0;n<e.length;n++)t.indexOf(e[n])<0&&t.push(e[n])}function An(t,e){const n=t;for(let t=e.length-1;t>=0;t--)s(n,e[t],n);return n}function _n(t,e,n,r){if(e&&e>1)for(let n=0;n<t.length;n++)(n+1)%3!=0&&(t[n]*=e);let s,o;if(n&&r&&1===e)s=Math.min(...n),o=Math.max(...r);else{const{min:e,max:n}=function(t){let e=1/0,n=-1/0;for(let r=0;r<t.length;r++)t[r]>n&&(n=t[r]),t[r]<e&&(e=t[r]);return{min:e,max:n}}(t);s=e,o=n}return function(t,e,n){const r=new Int16Array(t.length);for(let s=0;s<t.length;s++){const o=2*(t[s]-e)/(n-e)-1,i=Math.max(-1,Math.min(1,o));r[s]=i<0?32768*i:32767*i}return{array:r,range:[e,n]}}(t,s,o)}let Sn=0;class Mn{constructor(t){this.workerId=t,this.workers={},this.zt={}}addLayer({actorId:t,mapId:e,layerId:n,params:r},s){if(this.Vt(e,n))return;const o=this.kt(e,n),i=r.options,a=this.send.bind(this,t);this.workers[o]=new pn(n,i,a,s)}removeLayer({mapId:t,layerId:e},n){const r=this.Vt(t,e),s=this.kt(t,e);delete this.workers[s],r&&r.onRemove(n)}loadTile({mapId:t,layerId:e,params:n},r){const s=this.Vt(t,e);s&&s.loadTile(n,r)}abortTileLoading({mapId:t,layerId:e,params:n},r){const s=this.Vt(t,e);s&&s.abortTileLoading(n,r)}receive(t){const e=t.callback,n=this.zt[e];delete this.zt[e],n&&t.error?n(new Error(t.error)):n&&n(null,t.data)}send(t,e,n,r,s){const o=s?`${t}-${Sn++}`:null;s&&(this.zt[o]=s),postMessage({type:"<request>",workerId:this.workerId,actorId:t,command:e,params:n,callback:String(o)},r||[])}kt(t,e){return`${t}-${e}`}Vt(t,e){const n=this.kt(t,e);return this.workers[n]}}t.initialize=function(){},t.onmessage=function(t,e){const n=t.data;this.dispatcher||(this.dispatcher=new Mn(t.workerId)),"<response>"===t.type?this.dispatcher.workerId===t.workerId&&this.dispatcher.receive(t):this.dispatcher[n.command]({actorId:n.actorId,mapId:n.mapId,layerId:n.layerId,params:n.params},(t,n,r)=>{t instanceof Error&&(t={message:t.message}),e(t,n,r)})},Object.defineProperty(t,"jt",{value:!0})}';for(
6
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("maptalks"),require("@maptalks/gl")):"function"==typeof define&&define.amd?define(["exports","maptalks","@maptalks/gl"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).maptalks=t.maptalks||{},t.maptalks,t.maptalksgl)}(this,(function(t,e,n){"use strict";function r(t){if(t&&t.t)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var s=r(e),i=r(n);const o='function(t){var e="undefined"!=typeof Float32Array?Float32Array:Array;function n(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}function r(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}function s(t,e,n){var r=e[0],s=e[1],i=e[2],o=e[3],a=e[4],c=e[5],u=e[6],f=e[7],h=e[8],l=e[9],d=e[10],y=e[11],m=e[12],b=e[13],p=e[14],w=e[15],g=n[0],v=n[1],M=n[2],T=n[3];return t[0]=g*r+v*a+M*h+T*m,t[1]=g*s+v*c+M*l+T*b,t[2]=g*i+v*u+M*d+T*p,t[3]=g*o+v*f+M*y+T*w,g=n[4],v=n[5],M=n[6],T=n[7],t[4]=g*r+v*a+M*h+T*m,t[5]=g*s+v*c+M*l+T*b,t[6]=g*i+v*u+M*d+T*p,t[7]=g*o+v*f+M*y+T*w,g=n[8],v=n[9],M=n[10],T=n[11],t[8]=g*r+v*a+M*h+T*m,t[9]=g*s+v*c+M*l+T*b,t[10]=g*i+v*u+M*d+T*p,t[11]=g*o+v*f+M*y+T*w,g=n[12],v=n[13],M=n[14],T=n[15],t[12]=g*r+v*a+M*h+T*m,t[13]=g*s+v*c+M*l+T*b,t[14]=g*i+v*u+M*d+T*p,t[15]=g*o+v*f+M*y+T*w,t}function i(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}function o(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}function a(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,u=n*o,f=r*o,h=r*a,l=s*o,d=s*a,y=s*c,m=i*o,b=i*a,p=i*c;return t[0]=1-h-y,t[1]=f+p,t[2]=l-b,t[3]=0,t[4]=f-p,t[5]=1-u-y,t[6]=d+m,t[7]=0,t[8]=l+b,t[9]=d-m,t[10]=1-u-h,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function c(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]&&t[9]===e[9]&&t[10]===e[10]&&t[11]===e[11]&&t[12]===e[12]&&t[13]===e[13]&&t[14]===e[14]&&t[15]===e[15]}function u(){var t=new e(3);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function f(t){var e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function h(t,n,r){var s=new e(3);return s[0]=t,s[1]=n,s[2]=r,s}function l(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function d(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t}function y(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function m(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function b(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function p(t,e){var n=e[0],r=e[1],s=e[2],i=n*n+r*r+s*s;return i>0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i),t}function w(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function g(t,e,n){var r=e[0],s=e[1],i=e[2],o=n[0],a=n[1],c=n[2];return t[0]=s*c-i*a,t[1]=i*o-r*c,t[2]=r*a-s*o,t}function v(t,e,n){var r=e[0],s=e[1],i=e[2],o=n[3]*r+n[7]*s+n[11]*i+n[15];return o=o||1,t[0]=(n[0]*r+n[4]*s+n[8]*i+n[12])/o,t[1]=(n[1]*r+n[5]*s+n[9]*i+n[13])/o,t[2]=(n[2]*r+n[6]*s+n[10]*i+n[14])/o,t}var M=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t},T=m,A=f;function _(t,e,n,r,s){return t[0]=e,t[1]=n,t[2]=r,t[3]=s,t}function O(t,e,n){var r=e[0],s=e[1],i=e[2],o=e[3];return t[0]=n[0]*r+n[4]*s+n[8]*i+n[12]*o,t[1]=n[1]*r+n[5]*s+n[9]*i+n[13]*o,t[2]=n[2]*r+n[6]*s+n[10]*i+n[14]*o,t[3]=n[3]*r+n[7]*s+n[11]*i+n[15]*o,t}function S(){var t=new e(4);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function x(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function I(t,e,n,r){var s=e[0],i=e[1],o=e[2],a=e[3],c=n[0],u=n[1],f=n[2],h=n[3],l=void 0,d=void 0,y=void 0,m=void 0,b=void 0;return(d=s*c+i*u+o*f+a*h)<0&&(d=-d,c=-c,u=-u,f=-f,h=-h),1-d>1e-6?(l=Math.acos(d),y=Math.sin(l),m=Math.sin((1-r)*l)/y,b=Math.sin(r*l)/y):(m=1-r,b=r),t[0]=m*s+b*c,t[1]=m*i+b*u,t[2]=m*o+b*f,t[3]=m*a+b*h,t}u(),function(){var t,n=(t=new e(4),e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var k,E=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};u(),h(1,0,0),h(0,1,0),S(),S(),k=new e(9),e!=Float32Array&&(k[1]=0,k[2]=0,k[3]=0,k[5]=0,k[6]=0,k[7]=0),k[0]=1,k[4]=1,k[8]=1;\n/*!\n * @maptalks/gltf-loader v0.91.0\n * LICENSE : UNLICENSED\n * (c) 2016-2023 maptalks.org\n */\nlet C=0;function U(t){return null==t}function N(t){return!U(t)}function F(t){return!U(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}function P(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 B(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 D(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function R(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r.buffer}const L=[],z=[],j=[],V=[0,0,0],q=x([]),$=[1,1,1];function G(t,e,n,r,s,i,o){const a=B(o);if((0===s||s===r*a.BYTES_PER_ELEMENT)&&i%a.BYTES_PER_ELEMENT==0){const s=new a(e,i,n*r);return t.set(s),t}0===s&&(s=r*a.BYTES_PER_ELEMENT);const c=new Uint8Array(r*a.BYTES_PER_ELEMENT);for(let o=0;o<n;o++){let n=null;const u=new Uint8Array(e,s*o+i,r*a.BYTES_PER_ELEMENT);c.set(u),n=new a(c.buffer,0,r);for(let e=0;e<r;e++)t[o*r+e]=n[e]}return t}const X="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function H(t,e,n){const r=new Uint8Array(t,e,n);return X.decode(r)}const J={get:function(t,e={}){e||(e={});const n=new AbortController,r=n.signal,s=P({},e);s.signal=r,s.method||(s.method="GET");const i=fetch(t,s).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 i.xhr=n,i},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={})=>(e||(e={}),e.responseType="arraybuffer",J.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?J.jsonp(t):((e=e||{}).responseType="json",J.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+C++;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(r){document.getElementsByTagName("head")[0].removeChild(n),n=null,delete window[e],t(r)},document.getElementsByTagName("head")[0].appendChild(n)})}};class K{constructor(t,e,n){this.s=t,this.decoders=e,this.i=n,this.images={},this.o={}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)}if(this.o[t.id])return this.o[t.id].then(()=>{const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)});if(D(t.uri)){const r=this.buffers[t.id]=R(t.uri),s=this.u(e,r);return this.getImageByBuffer(s,n)}return this.o[t.id]=J.getArrayBuffer(t.uri,null).then(r=>{const s=this.buffers[t.id]=r.data,i=this.u(e,s);return this.getImageByBuffer(i,n)})}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;return n[e.mimeType]?n[e.mimeType](t,{supportedFormats:this.i}):"image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType?(console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.h(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.o[t.id]?this.o[t.id].then(()=>this.images[t.id]):this.o[t.id]=this.h(t.id,e)}h(t,e){return new Promise((n,r)=>{this.s(e,(s,i)=>{s?r(s):(URL.revokeObjectURL(e),this.images[t]=i,n(this.images[t]))})})}}const Y=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],Q=[];class W{constructor(t,e,n){this.rootPath=t,this.gltf=e,this.m=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.p()}v(t,e){const n=this.gltf,r=n.accessors[e];if(void 0===r.bufferView)return this.accessors[r.id]=this.M(t,e,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const s=n.bufferViews[r.bufferView];return this.T(s).then(n=>{const{buffer:s,byteOffset:i}=n;return this.accessors[r.id]=this.M(t,e,s,i)})}T(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(D(e.uri)){const t=this.buffers[e.id]=R(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]=J.getArrayBuffer(t,null).then(r=>(n&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=r.data,byteOffset:0}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}M(t,e,n,r=0){const s=this.gltf,i=s.accessors[e],o=void 0!==i.bufferView?s.bufferViews[i.bufferView]:{},a=(o.byteOffset||0)+r,c=this.A(i.type),u=B(i.componentType),f=o.byteStride||0,h={array:void 0,name:t,accessorName:e,byteLength:i.count*c*u.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:c,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(h.min=i.min),i.max&&(h.max=i.max),n)if(this.m)h.byteStride=f,h.byteOffset=a+(i.byteOffset||0),!f||f===c*u.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(h.array=this._(n,i.count,c,a+(i.byteOffset||0),u),h.array.buffer.byteLength===h.byteLength&&(h.byteOffset=0)):h.array=new Uint8Array(n,a,o.byteLength);else if(i.interleaved){h.byteStride=0,h.byteOffset=0;const t=new u(i.count*c);if(h.array=G(t,n,i.count,c,f,a+(i.byteOffset||0),i.componentType),h.extensions&&h.extensions.WEB3D_quantized_attributes&&c>2){const t=new Float32Array(h.array.length),{decodeMatrix:e}=h.extensions.WEB3D_quantized_attributes;for(let n=0;n<h.array.length;n+=c){Q[0]=h.array[n],Q[1]=h.array[n+1],Q[2]=h.array[n+2],Q[3]=1;const r=O(Q,Q,e);t[n]=r[0],t[n+1]=r[1],t[n+2]=r[2]}h.componentType=5126,h.array=t}}else h.byteStride=0,h.array=this._(n,i.count,c,a+(i.byteOffset||0),u),h.byteOffset=h.array.byteOffset;else{h.array=new u(i.count);const t=h.min||h.max;t&&(h.array[0]=t[0],h.array[1]=t[1],h.array[2]=t[2])}return h}p(){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)}_(t,e,n,r,s){return r%s.BYTES_PER_ELEMENT!=0&&(t=t.slice(r,r+e*n*s.BYTES_PER_ELEMENT),r=0),new s(t,r,n*e)}A(t){const e=Y.indexOf(t);return Y[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.T(e).then(r=>{const{buffer:s,byteOffset:i}=r,o=H(s,i+(e.byteOffset||0),n);return t.content=o,t})}if(t.uri){if(D(t.uri)){const e=R(t.uri),n=H(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return J.get(e).then(e=>(t.content=e,t))}}return Promise.resolve(t)});return Promise.all(n).then(()=>t)}}class Z extends K{constructor(t,e,n,r,s,i){super(r,s,i),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new W(t,e,n)}iterate(t,e){const n=this.gltf[e];if(!n)return;let r=0;for(const e in n)t(e,n[e],r++)}createNode(t){const e={};if(N(t.name)&&(e.name=t.name),N(t.children)&&(e.children=t.children),N(t.jointName)&&(e.jointName=t.jointName),N(t.matrix)&&(e.matrix=t.matrix),N(t.rotation)&&(e.rotation=t.rotation),N(t.scale)&&(e.scale=t.scale),N(t.translation)&&(e.translation=t.translation),N(t.extras)&&(e.extras=t.extras),N(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=i(L,e.translation||V),r=a(z,e.rotation||q),c=o(j,e.scale||$);return s(c,r,c),s(t,n,c)}return r(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 r=t[n];let s,i;r.instanceTechnique&&r.instanceTechnique.values?(s=r.instanceTechnique,i=s.values.diffuse):(s=r,i=s.values.tex||s.values.diffuseTex||s.values.diffuse);const o={baseColorTexture:{index:i}};r.name&&(o.name=r.name),r.extensions&&(o.extensions=r.extensions),r.extras&&(o.extras=r.extras),e[n]=o}return e}S(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],r=(n.byteOffset||0)+this.glbBuffer.byteOffset,s=n.byteLength,i=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,s);return this.getImageByBuffer(i,t)}return this.requestExternalImage(t)}I(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.S(n).then(t=>{const r=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:r}})}getBaseColorTexture(t){const e=this.gltf.materials[t];let n,r;if(e.instanceTechnique&&e.instanceTechnique.values?(n=e.instanceTechnique,r=n.values.diffuse):(n=e,r=n.values.tex||n.values.diffuseTex||n.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const s=this.gltf.textures[r];if(!s)return null;const i=this.gltf.samplers[s.sampler];return{format:s.format||6408,internalFormat:s.internalFormat||6408,type:s.type||5121,sampler:i,source:this.gltf.images[s.source]}}getMaterial(){return null}getAnimations(){return null}}class tt extends K{constructor(t,e,n,r,s,i){super(r,s,i),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new W(t,e,n)}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 P(e,t),!N(t.weights)&&this.gltf.meshes&&N(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}I(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),!N(n))return null;const r=this.gltf.images[n];return this.S(r).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:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};P(n,e);const s=N(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return s&&(n.sampler=s,n.sampler.magFilter=s.magFilter||9729,n.sampler.minFilter=s.minFilter||9729,n.sampler.wrapS=s.wrapS||10497,n.sampler.wrapT=s.wrapT||10497),t.format&&(n.format=t.format),n})}S(t){if(!N(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.k(e,t)}return null}k(t,e){const n=this.u(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}u(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}C(t,e){const n=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)n[e]=String.fromCharCode(t[e]);return n.join(""),"data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)))}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++)(N(t[n].input)||N(t[n].output))&&(e.push(this.accessor.v("input",t[n].input)),e.push(this.accessor.v("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 et="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class nt{static read(t,e=0,n=0){n||(n=t.byteLength);const r=new DataView(t,e,n),s=r.getUint32(4,!0);if(1===s)return nt.readV1(r,e);if(2===s)return nt.readV2(t,e);throw new Error("Unsupported glb version : "+s)}static readV1(t,e){const n=t.getUint32(8,!0),r=t.getUint32(12,!0);if(n!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb\'s byte length.");const s=rt(t.buffer,20+e,r);return{json:JSON.parse(s),glbBuffer:{byteOffset:20+e+r,buffer:t.buffer,byteLength:n}}}static readV2(t,e){let n,r,s;const i=new DataView(t,e+12);let o=0;for(;o<i.byteLength;){const a=i.getUint32(o,!0);o+=4;const c=i.getUint32(o,!0);if(o+=4,1313821514===c)n=rt(t,e+12+o,a);else if(5130562===c){s=e+12+o,r=a;break}o+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function rt(t,e,n){if(et){const r=new Uint8Array(t,e,n);return et.decode(r)}return function(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=st[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}(new Uint8Array(t,e,n))}const st=[1,1,1,1,2,2,3,0],it=[0,0,0],ot=[0,0,0,1],at=[1,1,1],ct={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},ut={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},ft={U(t,e,n,r,s,i,o,a){const c=N(t)?e.animations:[e.animations[0]],u={};for(let e=0;e<c.length;e++){const f=c[e],h=f.name||e;if(N(t)&&h!==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.N(s,f.samplers[e.sampler],r,1),u.translation=l(it,s)):"rotation"===e.target.path?(this.F(i,f.samplers[e.sampler],r,1),u.rotation=E(ot,i)):"scale"===e.target.path?(this.N(o,f.samplers[e.sampler],r,1),u.scale=l(at,o)):"weights"===e.target.path&&a&&(this.N(a,f.samplers[e.sampler],r,a.length),u.weights=a)}}return u},N(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.P(ut,e,n,1*r);s&&(t=function(t,e,n,r){for(let s=0;s<t.length;s++)t[s]=e[s]+r*(n[s]-e[s]);return t}(t,s.PREVIOUS,s.NEXT,s.INTERPOLATION));break}case"STEP":{const s=this.P(ut,e,n,1*r);s&&(t=function(t,e){for(let n=0;n<t.length;n++)t[n]=e[n];return t}(t,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.P(ut,e,n,3*r);s&&(t=this.B(t,s,e.input.array,3*r));break}}return t},F(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.P(ut,e,n,1);r&&I(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.P(ut,e,n,1);r&&(t=_(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.P(ut,e,n,3);if(r){for(let t=0;t<r.PREVIOUS.length;t++)r.PREVIOUS[t]=Math.acos(r.PREVIOUS[t]),r.NEXT[t]=Math.acos(r.NEXT[t]);t=this.B(t,r,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},D(t,e){const n=t.length;let r,s,i,o=0,a=n-1,c=Math.floor((o+a)/2);for(;o<=n-1&&a>=0;){if(o===a)return null;if(t[c]<=e&&e<=t[c+1]){const n=t[c];return r=c,s=c+1,i=(e-n)/(t[c+1]-n),{preIndx:r,nextIndex:s,interpolation:i}}e<t[c]?(a=c,c=Math.floor((o+a)/2)):t[c+1]<e&&(o=c,c=Math.floor((o+a)/2))}return null},P(t,e,n,r){const s=e.input.array,i=e.output.array,o=e.output.itemSize;(n<s[0]||n>s[s.length-1])&&(n=Math.max(s[0],Math.min(s[s.length-1],n))),n===s[s.length-1]&&(n=s[0]);const a=this.D(s,n);if(!a||!a.nextIndex)return null;const{preIndx:c,nextIndex:u,interpolation:f}=a;t.PREINDEX=c,t.NEXTINDEX=u,t.INTERPOLATION=f;const h=o*r;return t.PREVIOUS=i.subarray(t.PREINDEX*h,(t.PREINDEX+1)*h),t.NEXT=i.subarray(t.NEXTINDEX*h,(t.NEXTINDEX+1)*h),t},B(t,e,n,r){const s=e.INTERPOLATION,i=n[e.PREINDEX],o=n[e.NEXTINDEX];for(let n=0;n<3;n++){const a=e.PREVIOUS[r+n],c=(o-i)*e.PREVIOUS[2*r+n],u=e.NEXT[3+n],f=(o-i)*e.NEXT[n],h=(2*Math.pow(s,3)-3*Math.pow(s,2)+1)*a+(Math.pow(s,3)-2*Math.pow(s,2)+s)*c+(2*-Math.pow(s,3)+3*Math.pow(s,2))*u+(Math.pow(s,3)-Math.pow(s,2))*f;t[n]=h}return t},getAnimationClip(t,e,n,r){const s=t.nodes[e]&&t.nodes[e].weights;return d(it,...ct.TRANSLATION),_(ot,...ct.ROTATION),d(at,...ct.SCALE),this.U(r,t,e,n,it,ot,at,s)},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 r=-1/0,s=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]>r&&(r=o[o.length-1]),o[0]<s&&(s=o[0])}const o=e.name||n;t.timeSpan[o]={max:r,min:s}}),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?N(e)?n[e]:n[Object.keys(n)[0]]:null}};let ht=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(Ye){}t&&"undefined"!=typeof createImageBitmap&&(ht=!0)}const lt="undefined"==typeof document?null:document.createElement("canvas");class dt{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=nt.read(e.buffer,e.byteOffset,e.byteLength);this.R(t,n,r)}else this.R(t,e);this.L=new W(this.rootPath,this.gltf,this.glbBuffer),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.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}V(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.L.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then(e=>(t.KHR_techniques_webgl=e,t)):Promise.resolve(t)}load(t){t=t||{};const e=this.q(t),n=this.$(),r=this.G(),s=this.V();return Promise.all([e,n,r,s]).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,r){return ft.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return ft.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return B(t)}static readInterleavedArray(t,e,n,r,s,i,o){return G(t,e,n,r,s,i,o)}R(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=ht?pt.bind(this):this.options.requestImage||yt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new tt(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),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 Z(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"))}X(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||F(t.children[0])))return t;const r=t.children.map(t=>{const n=e[t];return n.nodeIndex=t,this.X(n,e)});t.children=r}var n;return t}q(t){return this.H(t).then(t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.X(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate((r,s,i)=>{const o={};s.name&&(o.name=s.name),s.nodes&&(o.nodes=s.nodes.map(e=>t[e])),this.gltf.scene===r&&(n=i),e.push(o)},"scenes");const r={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&&(r.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.O(this.gltf.materials);r.materials=t}return r})}H(t){return this.J(t).then(()=>{const t=this.nodes={};return this.adapter.iterate((e,n)=>{const r=this.adapter.createNode(n,this.meshes,this.skins);t[e]=r},"nodes"),t})}K(){this.skins=[];const t=[];return this.adapter.iterate((e,n,r)=>{t.push(this.Y(n).then(t=>{t.index=r,this.skins.push(t)}))},"skins"),t}Y(t){const e=t.inverseBindMatrices;return this.adapter.accessor.v("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 N(t)?this.adapter.getAnimations(t):null}J(t){this.meshes={};let e=[];return this.adapter.iterate((n,r,s)=>{e.push(this.W(r,t).then(t=>{t.index=s,this.meshes[n]=t}))},"meshes"),e=e.concat(this.K()),Promise.all(e)}W(t,e){const n=t.primitives.map(t=>this.Z(t,e)).filter(t=>!!t);return Promise.all(n).then(e=>{const n={};return P(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.I(n));return Promise.all(e).then(e=>{if(this.transferables)for(let t=0;t<e.length;t++){const n=e[t].image.array;if(e[t]&&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={},r=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(n[r[t]]=e[t]);return n}return e})}Z(t,e){let n;const r=[],s=t.extensions;if(N(t.targets))for(let e=0;e<t.targets.length;e++){const n=t.targets[e];for(const t in n){const s=this.adapter.accessor.v(`morphTargets_${t}_${e}`,n[t]);s&&r.push(s)}}if(s&&s.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}=s.KHR_draco_mesh_compression,a=this.gltf.bufferViews[i],c=this.L.T(a).then(n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:i}=a;const c=a.byteLength;i||(i=0);const u=new DataView(r,s+i,c),f={attributes:o,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(u,f).then(t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e})});r.push(c),n=Promise.all(r)}else{const e=t.attributes;for(const t in e){const n=this.adapter.accessor.v(t,e[t]);n&&r.push(n)}if(N(t.indices)){const e=this.adapter.accessor.v("indices",t.indices);e&&r.push(e)}n=Promise.all(r)}return n.then(e=>{if(s&&s.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,r;const i={attributes:e.reduce((t,e)=>{if("indices"===e.name)n=e;else if(e.name.indexOf("morphTargets_")>-1)r=r||{},r[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:r,array:s}=e,i=s.length/r;for(let e=0;e<i;e++)for(let i=0;i<r;i++){const o=e*r+i;s[o]<t[i]&&(t[i]=s[o]),s[o]>n[i]&&(n[i]=s[o])}if(e.quantization){const r=e.quantization,s=r.range/(1<<r.quantizationBits),i=r.minValues;b(t,t,s),y(t,t,i),b(n,n,s),y(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),r&&(i.morphTargets=r),i.mode=N(t.mode)?t.mode:4,N(t.extras)&&(i.extras=t.extras),i})}}function yt(t,e){const n=new Image;n.crossOrigin="",n.onload=()=>{if(!lt)return void e(new Error("There is no canvas to draw image!"));lt.width=n.width,lt.height=n.height;const t=lt.getContext("2d",{willReadFrequently:!0});t.drawImage(n,0,0,n.width,n.height);const r=t.getImageData(0,0,n.width,n.height),s={width:n.width,height:n.height,data:new Uint8Array(r.data)};e(null,s)},n.onerror=function(t){e(t)},n.src=t}let mt,bt;function pt(t,e){mt||(mt=new OffscreenCanvas(2,2),bt=mt.getContext("2d",{willReadFrequently:!0}));let n=null;if(F(t))n=fetch(t).then(t=>t.arrayBuffer()).then(t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)});else{const e=new Blob([t]);n=createImageBitmap(e)}n.then(wt.bind(this)).then(t=>{e(null,t)}).catch(t=>{console.warn(t),e(t)})}function wt(t){let{width:e,height:n}=t;gt(e)||(e=vt(e)),gt(n)||(n=vt(n));const r=this.options.maxTextureSize;r&&(e=Math.min(r,e),n=Math.min(r,n)),mt.width=e,mt.height=n,bt.drawImage(t,0,0,e,n),t.close();const s=bt.getImageData(0,0,e,n);return{width:e,height:n,data:new Uint8Array(s.data)}}function gt(t){return 0==(t&t-1)&&0!==t}function vt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}var Mt={exports:{}},Tt={"aliceblue":[240,248,255],"antiquewhite":[250,235,215],"aqua":[0,255,255],"aquamarine":[127,255,212],"azure":[240,255,255],"beige":[245,245,220],"bisque":[255,228,196],"black":[0,0,0],"blanchedalmond":[255,235,205],"blue":[0,0,255],"blueviolet":[138,43,226],"brown":[165,42,42],"burlywood":[222,184,135],"cadetblue":[95,158,160],"chartreuse":[127,255,0],"chocolate":[210,105,30],"coral":[255,127,80],"cornflowerblue":[100,149,237],"cornsilk":[255,248,220],"crimson":[220,20,60],"cyan":[0,255,255],"darkblue":[0,0,139],"darkcyan":[0,139,139],"darkgoldenrod":[184,134,11],"darkgray":[169,169,169],"darkgreen":[0,100,0],"darkgrey":[169,169,169],"darkkhaki":[189,183,107],"darkmagenta":[139,0,139],"darkolivegreen":[85,107,47],"darkorange":[255,140,0],"darkorchid":[153,50,204],"darkred":[139,0,0],"darksalmon":[233,150,122],"darkseagreen":[143,188,143],"darkslateblue":[72,61,139],"darkslategray":[47,79,79],"darkslategrey":[47,79,79],"darkturquoise":[0,206,209],"darkviolet":[148,0,211],"deeppink":[255,20,147],"deepskyblue":[0,191,255],"dimgray":[105,105,105],"dimgrey":[105,105,105],"dodgerblue":[30,144,255],"firebrick":[178,34,34],"floralwhite":[255,250,240],"forestgreen":[34,139,34],"fuchsia":[255,0,255],"gainsboro":[220,220,220],"ghostwhite":[248,248,255],"gold":[255,215,0],"goldenrod":[218,165,32],"gray":[128,128,128],"green":[0,128,0],"greenyellow":[173,255,47],"grey":[128,128,128],"honeydew":[240,255,240],"hotpink":[255,105,180],"indianred":[205,92,92],"indigo":[75,0,130],"ivory":[255,255,240],"khaki":[240,230,140],"lavender":[230,230,250],"lavenderblush":[255,240,245],"lawngreen":[124,252,0],"lemonchiffon":[255,250,205],"lightblue":[173,216,230],"lightcoral":[240,128,128],"lightcyan":[224,255,255],"lightgoldenrodyellow":[250,250,210],"lightgray":[211,211,211],"lightgreen":[144,238,144],"lightgrey":[211,211,211],"lightpink":[255,182,193],"lightsalmon":[255,160,122],"lightseagreen":[32,178,170],"lightskyblue":[135,206,250],"lightslategray":[119,136,153],"lightslategrey":[119,136,153],"lightsteelblue":[176,196,222],"lightyellow":[255,255,224],"lime":[0,255,0],"limegreen":[50,205,50],"linen":[250,240,230],"magenta":[255,0,255],"maroon":[128,0,0],"mediumaquamarine":[102,205,170],"mediumblue":[0,0,205],"mediumorchid":[186,85,211],"mediumpurple":[147,112,219],"mediumseagreen":[60,179,113],"mediumslateblue":[123,104,238],"mediumspringgreen":[0,250,154],"mediumturquoise":[72,209,204],"mediumvioletred":[199,21,133],"midnightblue":[25,25,112],"mintcream":[245,255,250],"mistyrose":[255,228,225],"moccasin":[255,228,181],"navajowhite":[255,222,173],"navy":[0,0,128],"oldlace":[253,245,230],"olive":[128,128,0],"olivedrab":[107,142,35],"orange":[255,165,0],"orangered":[255,69,0],"orchid":[218,112,214],"palegoldenrod":[238,232,170],"palegreen":[152,251,152],"paleturquoise":[175,238,238],"palevioletred":[219,112,147],"papayawhip":[255,239,213],"peachpuff":[255,218,185],"peru":[205,133,63],"pink":[255,192,203],"plum":[221,160,221],"powderblue":[176,224,230],"purple":[128,0,128],"rebeccapurple":[102,51,153],"red":[255,0,0],"rosybrown":[188,143,143],"royalblue":[65,105,225],"saddlebrown":[139,69,19],"salmon":[250,128,114],"sandybrown":[244,164,96],"seagreen":[46,139,87],"seashell":[255,245,238],"sienna":[160,82,45],"silver":[192,192,192],"skyblue":[135,206,235],"slateblue":[106,90,205],"slategray":[112,128,144],"slategrey":[112,128,144],"snow":[255,250,250],"springgreen":[0,255,127],"steelblue":[70,130,180],"tan":[210,180,140],"teal":[0,128,128],"thistle":[216,191,216],"tomato":[255,99,71],"turquoise":[64,224,208],"violet":[238,130,238],"wheat":[245,222,179],"white":[255,255,255],"whitesmoke":[245,245,245],"yellow":[255,255,0],"yellowgreen":[154,205,50]},At={exports:{}},_t=function(t){return!(!t||"string"==typeof t)&&(t instanceof Array||Array.isArray(t)||t.length>=0&&(t.splice instanceof Function||Object.getOwnPropertyDescriptor(t,t.length-1)&&"String"!==t.constructor.name))},Ot=Array.prototype.concat,St=Array.prototype.slice,xt=At.exports=function(t){for(var e=[],n=0,r=t.length;n<r;n++){var s=t[n];_t(s)?e=Ot.call(e,St.call(s)):e.push(s)}return e};xt.wrap=function(t){return function(){return t(xt(arguments))}};var It=Tt,kt=At.exports,Et=Object.hasOwnProperty,Ct=Object.create(null);for(var Ut in It)Et.call(It,Ut)&&(Ct[It[Ut]]=Ut);var Nt=Mt.exports={to:{},get:{}};function Ft(t,e,n){return Math.min(Math.max(e,t),n)}function Pt(t){var e=Math.round(t).toString(16).toUpperCase();return e.length<2?"0"+e:e}Nt.get=function(t){var e,n;switch(t.substring(0,3).toLowerCase()){case"hsl":e=Nt.get.hsl(t),n="hsl";break;case"hwb":e=Nt.get.hwb(t),n="hwb";break;default:e=Nt.get.rgb(t),n="rgb"}return e?{model:n,value:e}:null},Nt.get.rgb=function(t){if(!t)return null;var e,n,r,s=[0,0,0,1];if(e=t.match(/^#([a-f0-9]{6})([a-f0-9]{2})?$/i)){for(r=e[2],e=e[1],n=0;n<3;n++){var i=2*n;s[n]=parseInt(e.slice(i,i+2),16)}r&&(s[3]=parseInt(r,16)/255)}else if(e=t.match(/^#([a-f0-9]{3,4})$/i)){for(r=(e=e[1])[3],n=0;n<3;n++)s[n]=parseInt(e[n]+e[n],16);r&&(s[3]=parseInt(r+r,16)/255)}else if(e=t.match(/^rgba?\\(\\s*([+-]?\\d+)(?=[\\s,])\\s*(?:,\\s*)?([+-]?\\d+)(?=[\\s,])\\s*(?:,\\s*)?([+-]?\\d+)\\s*(?:[,|\\/]\\s*([+-]?[\\d\\.]+)(%?)\\s*)?\\)$/)){for(n=0;n<3;n++)s[n]=parseInt(e[n+1],0);e[4]&&(e[5]?s[3]=.01*parseFloat(e[4]):s[3]=parseFloat(e[4]))}else{if(!(e=t.match(/^rgba?\\(\\s*([+-]?[\\d\\.]+)\\%\\s*,?\\s*([+-]?[\\d\\.]+)\\%\\s*,?\\s*([+-]?[\\d\\.]+)\\%\\s*(?:[,|\\/]\\s*([+-]?[\\d\\.]+)(%?)\\s*)?\\)$/)))return(e=t.match(/^(\\w+)$/))?"transparent"===e[1]?[0,0,0,0]:Et.call(It,e[1])?((s=It[e[1]])[3]=1,s):null:null;for(n=0;n<3;n++)s[n]=Math.round(2.55*parseFloat(e[n+1]));e[4]&&(e[5]?s[3]=.01*parseFloat(e[4]):s[3]=parseFloat(e[4]))}for(n=0;n<3;n++)s[n]=Ft(s[n],0,255);return s[3]=Ft(s[3],0,1),s},Nt.get.hsl=function(t){if(!t)return null;var e=t.match(/^hsla?\\(\\s*([+-]?(?:\\d{0,3}\\.)?\\d+)(?:deg)?\\s*,?\\s*([+-]?[\\d\\.]+)%\\s*,?\\s*([+-]?[\\d\\.]+)%\\s*(?:[,|\\/]\\s*([+-]?(?=\\.\\d|\\d)(?:0|[1-9]\\d*)?(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)\\s*)?\\)$/);if(e){var n=parseFloat(e[4]);return[(parseFloat(e[1])%360+360)%360,Ft(parseFloat(e[2]),0,100),Ft(parseFloat(e[3]),0,100),Ft(isNaN(n)?1:n,0,1)]}return null},Nt.get.hwb=function(t){if(!t)return null;var e=t.match(/^hwb\\(\\s*([+-]?\\d{0,3}(?:\\.\\d+)?)(?:deg)?\\s*,\\s*([+-]?[\\d\\.]+)%\\s*,\\s*([+-]?[\\d\\.]+)%\\s*(?:,\\s*([+-]?(?=\\.\\d|\\d)(?:0|[1-9]\\d*)?(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)\\s*)?\\)$/);if(e){var n=parseFloat(e[4]);return[(parseFloat(e[1])%360+360)%360,Ft(parseFloat(e[2]),0,100),Ft(parseFloat(e[3]),0,100),Ft(isNaN(n)?1:n,0,1)]}return null},Nt.to.hex=function(){var t=kt(arguments);return"#"+Pt(t[0])+Pt(t[1])+Pt(t[2])+(t[3]<1?Pt(Math.round(255*t[3])):"")},Nt.to.rgb=function(){var t=kt(arguments);return t.length<4||1===t[3]?"rgb("+Math.round(t[0])+", "+Math.round(t[1])+", "+Math.round(t[2])+")":"rgba("+Math.round(t[0])+", "+Math.round(t[1])+", "+Math.round(t[2])+", "+t[3]+")"},Nt.to.rgb.percent=function(){var t=kt(arguments),e=Math.round(t[0]/255*100),n=Math.round(t[1]/255*100),r=Math.round(t[2]/255*100);return t.length<4||1===t[3]?"rgb("+e+"%, "+n+"%, "+r+"%)":"rgba("+e+"%, "+n+"%, "+r+"%, "+t[3]+")"},Nt.to.hsl=function(){var t=kt(arguments);return t.length<4||1===t[3]?"hsl("+t[0]+", "+t[1]+"%, "+t[2]+"%)":"hsla("+t[0]+", "+t[1]+"%, "+t[2]+"%, "+t[3]+")"},Nt.to.hwb=function(){var t=kt(arguments),e="";return t.length>=4&&1!==t[3]&&(e=", "+t[3]),"hwb("+t[0]+", "+t[1]+"%, "+t[2]+"%"+e+")"},Nt.to.keyword=function(t){return Ct[t.slice(0,3)]};var Bt={exports:{}},Dt=Tt,Rt={};for(var Lt in Dt)Dt.hasOwnProperty(Lt)&&(Rt[Dt[Lt]]=Lt);var zt=Bt.exports={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};for(var jt in zt)if(zt.hasOwnProperty(jt)){if(!("channels"in zt[jt]))throw new Error("missing channels property: "+jt);if(!("labels"in zt[jt]))throw new Error("missing channel labels property: "+jt);if(zt[jt].labels.length!==zt[jt].channels)throw new Error("channel and label counts mismatch: "+jt);var Vt=zt[jt].channels,qt=zt[jt].labels;delete zt[jt].channels,delete zt[jt].labels,Object.defineProperty(zt[jt],"channels",{value:Vt}),Object.defineProperty(zt[jt],"labels",{value:qt})}function $t(t,e){return Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2)}zt.rgb.hsl=function(t){var e,n,r=t[0]/255,s=t[1]/255,i=t[2]/255,o=Math.min(r,s,i),a=Math.max(r,s,i),c=a-o;return a===o?e=0:r===a?e=(s-i)/c:s===a?e=2+(i-r)/c:i===a&&(e=4+(r-s)/c),(e=Math.min(60*e,360))<0&&(e+=360),n=(o+a)/2,[e,100*(a===o?0:n<=.5?c/(a+o):c/(2-a-o)),100*n]},zt.rgb.hsv=function(t){var e,n,r,s,i,o=t[0]/255,a=t[1]/255,c=t[2]/255,u=Math.max(o,a,c),f=u-Math.min(o,a,c),h=function(t){return(u-t)/6/f+.5};return 0===f?s=i=0:(i=f/u,e=h(o),n=h(a),r=h(c),o===u?s=r-n:a===u?s=1/3+e-r:c===u&&(s=2/3+n-e),s<0?s+=1:s>1&&(s-=1)),[360*s,100*i,100*u]},zt.rgb.hwb=function(t){var e=t[0],n=t[1],r=t[2];return[zt.rgb.hsl(t)[0],100*(1/255*Math.min(e,Math.min(n,r))),100*(r=1-1/255*Math.max(e,Math.max(n,r)))]},zt.rgb.cmyk=function(t){var e,n=t[0]/255,r=t[1]/255,s=t[2]/255;return[100*((1-n-(e=Math.min(1-n,1-r,1-s)))/(1-e)||0),100*((1-r-e)/(1-e)||0),100*((1-s-e)/(1-e)||0),100*e]},zt.rgb.keyword=function(t){var e=Rt[t];if(e)return e;var n,r=1/0;for(var s in Dt)if(Dt.hasOwnProperty(s)){var i=$t(t,Dt[s]);i<r&&(r=i,n=s)}return n},zt.keyword.rgb=function(t){return Dt[t]},zt.rgb.xyz=function(t){var e=t[0]/255,n=t[1]/255,r=t[2]/255;return[100*(.4124*(e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92)+.3576*(n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.1805*(r=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92)),100*(.2126*e+.7152*n+.0722*r),100*(.0193*e+.1192*n+.9505*r)]},zt.rgb.lab=function(t){var e=zt.rgb.xyz(t),n=e[0],r=e[1],s=e[2];return r/=100,s/=108.883,n=(n/=95.047)>.008856?Math.pow(n,1/3):7.787*n+16/116,[116*(r=r>.008856?Math.pow(r,1/3):7.787*r+16/116)-16,500*(n-r),200*(r-(s=s>.008856?Math.pow(s,1/3):7.787*s+16/116))]},zt.hsl.rgb=function(t){var e,n,r,s,i,o=t[0]/360,a=t[1]/100,c=t[2]/100;if(0===a)return[i=255*c,i,i];e=2*c-(n=c<.5?c*(1+a):c+a-c*a),s=[0,0,0];for(var u=0;u<3;u++)(r=o+1/3*-(u-1))<0&&r++,r>1&&r--,i=6*r<1?e+6*(n-e)*r:2*r<1?n:3*r<2?e+(n-e)*(2/3-r)*6:e,s[u]=255*i;return s},zt.hsl.hsv=function(t){var e=t[0],n=t[1]/100,r=t[2]/100,s=n,i=Math.max(r,.01);return n*=(r*=2)<=1?r:2-r,s*=i<=1?i:2-i,[e,100*(0===r?2*s/(i+s):2*n/(r+n)),100*((r+n)/2)]},zt.hsv.rgb=function(t){var e=t[0]/60,n=t[1]/100,r=t[2]/100,s=Math.floor(e)%6,i=e-Math.floor(e),o=255*r*(1-n),a=255*r*(1-n*i),c=255*r*(1-n*(1-i));switch(r*=255,s){case 0:return[r,c,o];case 1:return[a,r,o];case 2:return[o,r,c];case 3:return[o,a,r];case 4:return[c,o,r];case 5:return[r,o,a]}},zt.hsv.hsl=function(t){var e,n,r,s=t[0],i=t[1]/100,o=t[2]/100,a=Math.max(o,.01);return r=(2-i)*o,n=i*a,[s,100*(n=(n/=(e=(2-i)*a)<=1?e:2-e)||0),100*(r/=2)]},zt.hwb.rgb=function(t){var e,n,r,s,i,o,a,c=t[0]/360,u=t[1]/100,f=t[2]/100,h=u+f;switch(h>1&&(u/=h,f/=h),r=6*c-(e=Math.floor(6*c)),0!=(1&e)&&(r=1-r),s=u+r*((n=1-f)-u),e){default:case 6:case 0:i=n,o=s,a=u;break;case 1:i=s,o=n,a=u;break;case 2:i=u,o=n,a=s;break;case 3:i=u,o=s,a=n;break;case 4:i=s,o=u,a=n;break;case 5:i=n,o=u,a=s}return[255*i,255*o,255*a]},zt.cmyk.rgb=function(t){var e=t[0]/100,n=t[1]/100,r=t[2]/100,s=t[3]/100;return[255*(1-Math.min(1,e*(1-s)+s)),255*(1-Math.min(1,n*(1-s)+s)),255*(1-Math.min(1,r*(1-s)+s))]},zt.xyz.rgb=function(t){var e,n,r,s=t[0]/100,i=t[1]/100,o=t[2]/100;return n=-.9689*s+1.8758*i+.0415*o,r=.0557*s+-.204*i+1.057*o,e=(e=3.2406*s+-1.5372*i+-.4986*o)>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e,n=n>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,r=r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r,[255*(e=Math.min(Math.max(0,e),1)),255*(n=Math.min(Math.max(0,n),1)),255*(r=Math.min(Math.max(0,r),1))]},zt.xyz.lab=function(t){var e=t[0],n=t[1],r=t[2];return n/=100,r/=108.883,e=(e/=95.047)>.008856?Math.pow(e,1/3):7.787*e+16/116,[116*(n=n>.008856?Math.pow(n,1/3):7.787*n+16/116)-16,500*(e-n),200*(n-(r=r>.008856?Math.pow(r,1/3):7.787*r+16/116))]},zt.lab.xyz=function(t){var e,n,r,s=t[0];e=t[1]/500+(n=(s+16)/116),r=n-t[2]/200;var i=Math.pow(n,3),o=Math.pow(e,3),a=Math.pow(r,3);return n=i>.008856?i:(n-16/116)/7.787,e=o>.008856?o:(e-16/116)/7.787,r=a>.008856?a:(r-16/116)/7.787,[e*=95.047,n*=100,r*=108.883]},zt.lab.lch=function(t){var e,n=t[0],r=t[1],s=t[2];return(e=360*Math.atan2(s,r)/2/Math.PI)<0&&(e+=360),[n,Math.sqrt(r*r+s*s),e]},zt.lch.lab=function(t){var e,n=t[0],r=t[1];return e=t[2]/360*2*Math.PI,[n,r*Math.cos(e),r*Math.sin(e)]},zt.rgb.ansi16=function(t){var e=t[0],n=t[1],r=t[2],s=1 in arguments?arguments[1]:zt.rgb.hsv(t)[2];if(0===(s=Math.round(s/50)))return 30;var i=30+(Math.round(r/255)<<2|Math.round(n/255)<<1|Math.round(e/255));return 2===s&&(i+=60),i},zt.hsv.ansi16=function(t){return zt.rgb.ansi16(zt.hsv.rgb(t),t[2])},zt.rgb.ansi256=function(t){var e=t[0],n=t[1],r=t[2];return e===n&&n===r?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(n/255*5)+Math.round(r/255*5)},zt.ansi16.rgb=function(t){var e=t%10;if(0===e||7===e)return t>50&&(e+=3.5),[e=e/10.5*255,e,e];var n=.5*(1+~~(t>50));return[(1&e)*n*255,(e>>1&1)*n*255,(e>>2&1)*n*255]},zt.ansi256.rgb=function(t){if(t>=232){var e=10*(t-232)+8;return[e,e,e]}var n;return t-=16,[Math.floor(t/36)/5*255,Math.floor((n=t%36)/6)/5*255,n%6/5*255]},zt.rgb.hex=function(t){var e=(((255&Math.round(t[0]))<<16)+((255&Math.round(t[1]))<<8)+(255&Math.round(t[2]))).toString(16).toUpperCase();return"000000".substring(e.length)+e},zt.hex.rgb=function(t){var e=t.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!e)return[0,0,0];var n=e[0];3===e[0].length&&(n=n.split("").map((function(t){return t+t})).join(""));var r=parseInt(n,16);return[r>>16&255,r>>8&255,255&r]},zt.rgb.hcg=function(t){var e,n=t[0]/255,r=t[1]/255,s=t[2]/255,i=Math.max(Math.max(n,r),s),o=Math.min(Math.min(n,r),s),a=i-o;return e=a<=0?0:i===n?(r-s)/a%6:i===r?2+(s-n)/a:4+(n-r)/a+4,e/=6,[360*(e%=1),100*a,100*(a<1?o/(1-a):0)]},zt.hsl.hcg=function(t){var e=t[1]/100,n=t[2]/100,r=1,s=0;return(r=n<.5?2*e*n:2*e*(1-n))<1&&(s=(n-.5*r)/(1-r)),[t[0],100*r,100*s]},zt.hsv.hcg=function(t){var e=t[1]/100,n=t[2]/100,r=e*n,s=0;return r<1&&(s=(n-r)/(1-r)),[t[0],100*r,100*s]},zt.hcg.rgb=function(t){var e=t[0]/360,n=t[1]/100,r=t[2]/100;if(0===n)return[255*r,255*r,255*r];var s,i=[0,0,0],o=e%1*6,a=o%1,c=1-a;switch(Math.floor(o)){case 0:i[0]=1,i[1]=a,i[2]=0;break;case 1:i[0]=c,i[1]=1,i[2]=0;break;case 2:i[0]=0,i[1]=1,i[2]=a;break;case 3:i[0]=0,i[1]=c,i[2]=1;break;case 4:i[0]=a,i[1]=0,i[2]=1;break;default:i[0]=1,i[1]=0,i[2]=c}return s=(1-n)*r,[255*(n*i[0]+s),255*(n*i[1]+s),255*(n*i[2]+s)]},zt.hcg.hsv=function(t){var e=t[1]/100,n=e+t[2]/100*(1-e),r=0;return n>0&&(r=e/n),[t[0],100*r,100*n]},zt.hcg.hsl=function(t){var e=t[1]/100,n=t[2]/100*(1-e)+.5*e,r=0;return n>0&&n<.5?r=e/(2*n):n>=.5&&n<1&&(r=e/(2*(1-n))),[t[0],100*r,100*n]},zt.hcg.hwb=function(t){var e=t[1]/100,n=e+t[2]/100*(1-e);return[t[0],100*(n-e),100*(1-n)]},zt.hwb.hcg=function(t){var e=t[1]/100,n=1-t[2]/100,r=n-e,s=0;return r<1&&(s=(n-r)/(1-r)),[t[0],100*r,100*s]},zt.apple.rgb=function(t){return[t[0]/65535*255,t[1]/65535*255,t[2]/65535*255]},zt.rgb.apple=function(t){return[t[0]/255*65535,t[1]/255*65535,t[2]/255*65535]},zt.gray.rgb=function(t){return[t[0]/100*255,t[0]/100*255,t[0]/100*255]},zt.gray.hsl=zt.gray.hsv=function(t){return[0,0,t[0]]},zt.gray.hwb=function(t){return[0,100,t[0]]},zt.gray.cmyk=function(t){return[0,0,0,t[0]]},zt.gray.lab=function(t){return[t[0],0,0]},zt.gray.hex=function(t){var e=255&Math.round(t[0]/100*255),n=((e<<16)+(e<<8)+e).toString(16).toUpperCase();return"000000".substring(n.length)+n},zt.rgb.gray=function(t){return[(t[0]+t[1]+t[2])/3/255*100]};var Gt=Bt.exports;function Xt(t){var e=function(){for(var t={},e=Object.keys(Gt),n=e.length,r=0;r<n;r++)t[e[r]]={distance:-1,parent:null};return t}(),n=[t];for(e[t].distance=0;n.length;)for(var r=n.pop(),s=Object.keys(Gt[r]),i=s.length,o=0;o<i;o++){var a=s[o],c=e[a];-1===c.distance&&(c.distance=e[r].distance+1,c.parent=r,n.unshift(a))}return e}function Ht(t,e){return function(n){return e(t(n))}}function Jt(t,e){for(var n=[e[t].parent,t],r=Gt[e[t].parent][t],s=e[t].parent;e[s].parent;)n.unshift(e[s].parent),r=Ht(Gt[e[s].parent][s],r),s=e[s].parent;return r.conversion=n,r}var Kt=Bt.exports,Yt=function(t){for(var e=Xt(t),n={},r=Object.keys(e),s=r.length,i=0;i<s;i++){var o=r[i];null!==e[o].parent&&(n[o]=Jt(o,e))}return n},Qt={};Object.keys(Kt).forEach((function(t){Qt[t]={},Object.defineProperty(Qt[t],"channels",{value:Kt[t].channels}),Object.defineProperty(Qt[t],"labels",{value:Kt[t].labels});var e=Yt(t);Object.keys(e).forEach((function(n){var r=e[n];Qt[t][n]=function(t){var e=function(e){if(null==e)return e;arguments.length>1&&(e=Array.prototype.slice.call(arguments));var n=t(e);if("object"==typeof n)for(var r=n.length,s=0;s<r;s++)n[s]=Math.round(n[s]);return n};return"conversion"in t&&(e.conversion=t.conversion),e}(r),Qt[t][n].raw=function(t){var e=function(e){return null==e?e:(arguments.length>1&&(e=Array.prototype.slice.call(arguments)),t(e))};return"conversion"in t&&(e.conversion=t.conversion),e}(r)}))}));var Wt=Qt,Zt=Mt.exports,te=Wt,ee=[].slice,ne=["keyword","gray","hex"],re={};Object.keys(te).forEach((function(t){re[ee.call(te[t].labels).sort().join("")]=t}));var se={};function ie(t,e){if(!(this instanceof ie))return new ie(t,e);if(e&&e in ne&&(e=null),e&&!(e in te))throw new Error("Unknown model: "+e);var n,r;if(null==t)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(t instanceof ie)this.model=t.model,this.color=t.color.slice(),this.valpha=t.valpha;else if("string"==typeof t){var s=Zt.get(t);if(null===s)throw new Error("Unable to parse color from string: "+t);this.model=s.model,r=te[this.model].channels,this.color=s.value.slice(0,r),this.valpha="number"==typeof s.value[r]?s.value[r]:1}else if(t.length){this.model=e||"rgb",r=te[this.model].channels;var i=ee.call(t,0,r);this.color=ue(i,r),this.valpha="number"==typeof t[r]?t[r]:1}else if("number"==typeof t)t&=16777215,this.model="rgb",this.color=[t>>16&255,t>>8&255,255&t],this.valpha=1;else{this.valpha=1;var o=Object.keys(t);"alpha"in t&&(o.splice(o.indexOf("alpha"),1),this.valpha="number"==typeof t.alpha?t.alpha:0);var a=o.sort().join("");if(!(a in re))throw new Error("Unable to parse color from object: "+JSON.stringify(t));this.model=re[a];var c=te[this.model].labels,u=[];for(n=0;n<c.length;n++)u.push(t[c[n]]);this.color=ue(u)}if(se[this.model])for(r=te[this.model].channels,n=0;n<r;n++){var f=se[this.model][n];f&&(this.color[n]=f(this.color[n]))}this.valpha=Math.max(0,Math.min(1,this.valpha)),Object.freeze&&Object.freeze(this)}function oe(t,e,n){return(t=Array.isArray(t)?t:[t]).forEach((function(t){(se[t]||(se[t]=[]))[e]=n})),t=t[0],function(r){var s;return arguments.length?(n&&(r=n(r)),(s=this[t]()).color[e]=r,s):(s=this[t]().color[e],n&&(s=n(s)),s)}}function ae(t){return function(e){return Math.max(0,Math.min(t,e))}}function ce(t){return Array.isArray(t)?t:[t]}function ue(t,e){for(var n=0;n<e;n++)"number"!=typeof t[n]&&(t[n]=0);return t}function fe(t){return"object"==typeof t&&!!t}function he(t){return t/Math.PI*180}function le(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}ie.prototype={toString:function(){return this.string()},toJSON:function(){return this[this.model]()},string:function(t){var e=this.model in Zt.to?this:this.rgb(),n=1===(e=e.round("number"==typeof t?t:1)).valpha?e.color:e.color.concat(this.valpha);return Zt.to[e.model](n)},percentString:function(t){var e=this.rgb().round("number"==typeof t?t:1),n=1===e.valpha?e.color:e.color.concat(this.valpha);return Zt.to.rgb.percent(n)},array:function(){return 1===this.valpha?this.color.slice():this.color.concat(this.valpha)},object:function(){for(var t={},e=te[this.model].channels,n=te[this.model].labels,r=0;r<e;r++)t[n[r]]=this.color[r];return 1!==this.valpha&&(t.alpha=this.valpha),t},unitArray:function(){var t=this.rgb().color;return t[0]/=255,t[1]/=255,t[2]/=255,1!==this.valpha&&t.push(this.valpha),t},unitObject:function(){var t=this.rgb().object();return t.r/=255,t.g/=255,t.b/=255,1!==this.valpha&&(t.alpha=this.valpha),t},round:function(t){return t=Math.max(t||0,0),new ie(this.color.map(function(t){return function(e){return function(t,e){return Number(t.toFixed(e))}(e,t)}}(t)).concat(this.valpha),this.model)},alpha:function(t){return arguments.length?new ie(this.color.concat(Math.max(0,Math.min(1,t))),this.model):this.valpha},red:oe("rgb",0,ae(255)),green:oe("rgb",1,ae(255)),blue:oe("rgb",2,ae(255)),hue:oe(["hsl","hsv","hsl","hwb","hcg"],0,(function(t){return(t%360+360)%360})),saturationl:oe("hsl",1,ae(100)),lightness:oe("hsl",2,ae(100)),saturationv:oe("hsv",1,ae(100)),value:oe("hsv",2,ae(100)),chroma:oe("hcg",1,ae(100)),gray:oe("hcg",2,ae(100)),white:oe("hwb",1,ae(100)),wblack:oe("hwb",2,ae(100)),cyan:oe("cmyk",0,ae(100)),magenta:oe("cmyk",1,ae(100)),yellow:oe("cmyk",2,ae(100)),black:oe("cmyk",3,ae(100)),x:oe("xyz",0,ae(100)),y:oe("xyz",1,ae(100)),z:oe("xyz",2,ae(100)),l:oe("lab",0,ae(100)),a:oe("lab",1),b:oe("lab",2),keyword:function(t){return arguments.length?new ie(t):te[this.model].keyword(this.color)},hex:function(t){return arguments.length?new ie(t):Zt.to.hex(this.rgb().round().color)},rgbNumber:function(){var t=this.rgb().color;return(255&t[0])<<16|(255&t[1])<<8|255&t[2]},luminosity:function(){for(var t=this.rgb().color,e=[],n=0;n<t.length;n++){var r=t[n]/255;e[n]=r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4)}return.2126*e[0]+.7152*e[1]+.0722*e[2]},contrast:function(t){var e=this.luminosity(),n=t.luminosity();return e>n?(e+.05)/(n+.05):(n+.05)/(e+.05)},level:function(t){var e=this.contrast(t);return e>=7.1?"AAA":e>=4.5?"AA":""},isDark:function(){var t=this.rgb().color;return(299*t[0]+587*t[1]+114*t[2])/1e3<128},isLight:function(){return!this.isDark()},negate:function(){for(var t=this.rgb(),e=0;e<3;e++)t.color[e]=255-t.color[e];return t},lighten:function(t){var e=this.hsl();return e.color[2]+=e.color[2]*t,e},darken:function(t){var e=this.hsl();return e.color[2]-=e.color[2]*t,e},saturate:function(t){var e=this.hsl();return e.color[1]+=e.color[1]*t,e},desaturate:function(t){var e=this.hsl();return e.color[1]-=e.color[1]*t,e},whiten:function(t){var e=this.hwb();return e.color[1]+=e.color[1]*t,e},blacken:function(t){var e=this.hwb();return e.color[2]+=e.color[2]*t,e},grayscale:function(){var t=this.rgb().color,e=.3*t[0]+.59*t[1]+.11*t[2];return ie.rgb(e,e,e)},fade:function(t){return this.alpha(this.valpha-this.valpha*t)},opaquer:function(t){return this.alpha(this.valpha+this.valpha*t)},rotate:function(t){var e=this.hsl(),n=e.color[0];return n=(n=(n+t)%360)<0?360+n:n,e.color[0]=n,e},mix:function(t,e){if(!t||!t.rgb)throw new Error(\'Argument to "mix" was not a Color instance, but rather an instance of \'+typeof t);var n=t.rgb(),r=this.rgb(),s=void 0===e?.5:e,i=2*s-1,o=n.alpha()-r.alpha(),a=((i*o==-1?i:(i+o)/(1+i*o))+1)/2,c=1-a;return ie.rgb(a*n.red()+c*r.red(),a*n.green()+c*r.green(),a*n.blue()+c*r.blue(),n.alpha()*s+r.alpha()*(1-s))}},Object.keys(te).forEach((function(t){if(-1===ne.indexOf(t)){var e=te[t].channels;ie.prototype[t]=function(){if(this.model===t)return new ie(this);if(arguments.length)return new ie(arguments,t);var n="number"==typeof arguments[e]?e:this.valpha;return new ie(ce(te[this.model][t].raw(this.color)).concat(n),t)},ie[t]=function(n){return"number"==typeof n&&(n=ue(ee.call(arguments),e)),new ie(n,t)}}}));const de=[1,1,1,1,2,2,3,0];function ye(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=de[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}new Array(3),new Array(3);const me=[1/6378137,1/6378137,1/6356752.314245179],be=[1/40680631590769,1/40680631590769,1/40408299984661.445],pe=new Array(3),we=new Array(3),ge=new Array(3);function ve(t,e){const n=be,r=function(t,e,n,r,s){const i=e[0],o=e[1],a=e[2],c=n[0],u=n[1],f=n[2],h=i*i*c*c,l=o*o*u*u,d=a*a*f*f,y=h+l+d,m=Math.sqrt(1/y),p=b(Me,e,m);if(y<s)return isFinite(m)?p:void 0;const w=r[0],g=r[1],v=r[2],M=Te;M[0]=p[0]*w*2,M[1]=p[1]*g*2,M[2]=p[2]*v*2;let T,A,_,O,S,x,I,k,E,C,U,N=(1-m)*Ae(e)/(.5*Ae(M)),F=0;do{N-=F,_=1/(1+N*w),O=1/(1+N*g),S=1/(1+N*v),x=_*_,I=O*O,k=S*S,E=x*_,C=I*O,U=k*S,T=h*x+l*I+d*k-1,A=h*E*w+l*C*g+d*U*v;F=T/(-2*A)}while(Math.abs(T)>1e-12);return t[0]=i*_,t[1]=o*O,t[2]=a*S,t}(pe,e,me,n,.1);let s=T(we,r,n);s=function(t,e){const n=e[0],r=e[1],s=e[2];let i=n*n+r*r+s*s;i>0&&(i=Math.sqrt(i),t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i);return t}(s,s);const i=M(ge,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=le(w(i,e))*Ae(i);return t[0]=he(o),t[1]=he(a),t[2]=c,t}const Me=new Array(3),Te=new Array(3);function Ae(t){return f(t)}function _e(t,e,n,r){n=n||0,r=r||n;const s=Math.abs(t-e);return s<=r||s<=n*Math.max(Math.abs(t),Math.abs(e))}function Oe(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const Se="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function xe(t,e,n){const r=new Uint8Array(t,e,n);return Se?JSON.parse(Se.decode(r)):JSON.parse(ye(r))}function Ie(t,e,n){const r=new Uint8Array(t,e,n);return Se?JSON.parse(Se.decode(r)):JSON.parse(ye(r))}function ke(t,e,n){return{offset:e,byteLength:n}}function Ee(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=function(t){return Ne[t]}(i||"UNSIGNED_SHORT"),u=function(t){if(!t)return 1;return Ue[t]}(o);return{byteStride:0,byteOffset:s+n,itemSize:u,count:r*u,componentType:c,array:new a(e,n+s,r*u)}}function Ce(t,e,n,r){const s=Ee(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}const Ue={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const Ne={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function Fe(t){for(const e in Ne)if(t===Ne[e].ctor)return Ne[e].type;throw new Error("unrecognized ctor:"+t)}function Pe(t,e,n,r){const s=t,i=e.length/3;for(let t=0;t<i;t++)s[3*t]=e[3*t]/65535*r[0]+n[0],s[3*t+1]=e[3*t+1]/65535*r[1]+n[1],s[3*t+2]=e[3*t+2]/65535*r[2]+n[2];return s}function Be(t,e,n){const r=t.getUint32(12,!0),s=t.getUint32(16,!0),i=t.getUint32(20,!0),o=t.getUint32(24,!0),a=t.buffer;let c,u={},f={},h=null;r>0&&(u=xe(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),i>0&&(f=Ie(a,e,i),e+=i);const l=ke(0,e,o);return h=a.slice(l.offset,l.offset+l.byteLength),n.push(h),{featureTable:u,featureTableBin:c,batchTable:f,batchTableBin:h}}const De={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}},Re={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Le={},ze={east:[],north:[],up:[],west:[],south:[],down:[]};let je=[],Ve=[],qe=[];const $e=[0,0,0];const Ge=function(t,e){const n=De[t][e];let r;const s=t+e;return Le[s]?r=Le[s]:(r=function(r,s,i){if(function(t,e){var n=t[0],r=t[1],s=t[2],i=e[0],o=e[1],a=e[2];return Math.abs(n-i)<=1e-6*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(s-a)<=1e-6*Math.max(1,Math.abs(s),Math.abs(a))}(r,$e))l(je,Re[t]),l(Ve,Re[e]),l(qe,Re[n]);else if(_e(r[0],0,1e-14)&&_e(r[1],0,1e-14)){const s=le(r[2]);l(je,Re[t]),"east"!==t&&"west"!==t&&b(je,je,s),l(Ve,Re[e]),"east"!==e&&"west"!==e&&b(Ve,Ve,s),l(qe,Re[n]),"east"!==n&&"west"!==n&&b(qe,qe,s)}else{!function(t,e){m(e,t,be),p(e,e)}(r,ze.up);const s=ze.up,i=ze.east;i[0]=-r[1],i[1]=r[0],i[2]=0,p(ze.east,i),g(ze.north,s,i),b(ze.down,ze.up,-1),b(ze.west,ze.east,-1),b(ze.south,ze.north,-1),je=ze[t],Ve=ze[e],qe=ze[n]}return i[0]=je[0],i[1]=je[1],i[2]=je[2],i[3]=0,i[4]=Ve[0],i[5]=Ve[1],i[6]=Ve[2],i[7]=0,i[8]=qe[0],i[9]=qe[1],i[10]=qe[2],i[11]=0,i[12]=r[0],i[13]=r[1],i[14]=r[2],i[15]=1,i},Le[s]=r),r}("east","north"),Xe={5120:Int8Array,5122:Int16Array,5124:Int32Array,5121:Uint8Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array};function He(t){for(const e in Xe)if(t===Xe[e])return+e;throw new Error("unrecognized ctor:"+t)}\n/*!\n * @maptalks/gl v0.91.0\n * LICENSE : UNLICENSED\n * (c) 2016-2023 maptalks.com\n */const Je=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof undefined)return global;throw new Error("unable to locate global object")},Ke=Je(),Ye=Ke.gl_trans__coders=Ke.gl_trans__coders||{};Ye.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=Ke.gl_trans__coders=Ke.gl_trans__coders||{};let i=`${r}\\n const _____getGlobal = ${Je.toString()};\\n const g___lobals = _____getGlobal()\\n const tran_____scoders = g___lobals[\'gl_trans__coders\'] = g___lobals[\'gl_trans__coders\'] || {};`;for(const t in s)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(i+=\'tran_____scoders["\'+t+\'"] =\'+s[t].toString()+"\\n;");return i+="\\n"+e.substring(r.length),i},Ye.registerTranscoder=function(t,e){Ye[t]=e},Ye.getTranscoder=function(t){return Ye[t]};let Qe=null;function We(){return Qe||(Qe={"image/crn":Ye.crn&&Ye.crn(),"image/ktx2":Ye.ktx2&&Ye.ktx2(),"image/cttf":Ye.ktx2&&Ye.ktx2(),"draco":Ye.draco&&Ye.draco()}),Qe}class Ze{constructor(t,e,n){this.s=t,this.tt=e||dt,this.i=n,this.et=We()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.nt(t,e,n,r,s)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.nt(t,s,n,r)})}nt(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.rt(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.tt(a,o.glb,{transferable:!0,requestImage:this.s,decoders:this.et,supportedFormats:this.i,maxTextureSize:i});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<o.transferables.length;t++)s.indexOf(o.transferables[t])<0&&s.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:s,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}})}rt(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm\'s byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),u=s.getUint32(20,!0),f=s.getUint32(24,!0),h=28+e;u>=570425344?(h-=8,o=a,u=c,f=0,a=0,c=0):f>=570425344&&(h-=4,o=u,u=a,f=c,a=0,c=0);const l=[t];let d,y,m;if(a>0?(d=xe(t,h,a),h+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(h+=c),u>0&&(y=Ie(t,h,u),h+=u,f>0)){const e=ke(0,h,f);m=t.slice(e.offset,e.offset+e.byteLength),h+=f,l.push(m)}const b=d.BATCH_LENGTH,p={};if(d&&d.BATCH_ID){p.BATCH_ID=Ce(d.BATCH_ID,t,(void 0).offset,b);const e=p.BATCH_ID.array&&p.BATCH_ID.array.buffer;e&&l.indexOf(e)<0&&l.push(e)}return{count:o,transferables:l,featureTable:d,batchTable:y,batchTableBin:m,b3dm:p,glb:{buffer:t,byteOffset:h,byteLength:s.byteLength+s.byteOffset-h}}}st(){return null}}class tn{constructor(t,e,n,r){this.s=t,this.tt=e||dt,this.i=n,this.et=We(),this.it=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.nt(t,e,n,r,s)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.nt(t,s,n,r)})}nt(t,e,n,r,s){return this.ot(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.ct(e,n,r,t);if(o.error)return Promise.resolve(o);for(let t=0;t<i.length;t++)-1===o.transferables.indexOf(i[t])&&o.transferables.push(i[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:s})})}ot(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.s,decoders:this.et,supportedFormats:this.i,maxTextureSize:i},a=new DataView(e,n,r),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let r=ye(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?J.getArrayBuffer(r,{}).then(t=>this.ut(r,{buffer:t.data,byteOffset:0},o)):J.getJSON(r,{}).then(t=>this.ut(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.ut(t,r,o)}}ut(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.tt(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,i=0;return e.buffer&&(r=e.byteOffset||0,i=e.byteLength||0),n.url=`${t}-${r}-${i}`,{transferables:s.transferables,gltf:n}})}ct(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts\'s byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=Be(s,32+e,o),h={},l=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;h.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;h.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.ft(new Uint16Array(t,r+c.offset,3*l),e,n)},o.push(h.POSITION.array.buffer)}if(a.BATCH_ID){h.BATCH_ID=Ce(a.BATCH_ID,t,c.offset,l);const e=h.BATCH_ID.array&&h.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;h.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.ht(new Uint16Array(t,e+c.offset,2*l))},o.push(h.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,h.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.ht(new Uint16Array(t,e+c.offset,2*l))},o.push(h.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;h.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,l).slice()},o.push(h.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;h.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(h.SCALE_NON_UNIFORM.array.buffer)}return{count:l,batchTable:u,batchTableBin:f,featureTable:a,i3dm:h,transferables:o}}ht(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)en(r,t[2*s],t[2*s+1],65535),n[3*s]=r[0],n[3*s+1]=r[1],n[3*s+2]=r[2];return n}ft(t,e,n){return Pe(new Float32Array(t.length),t,e,n)}st(){return null}}function en(t,e,n,r){if(t[0]=nn(e,r),t[1]=nn(n,r),t[2]=1-(Math.abs(t[0])+Math.abs(t[1])),t[2]<0){const e=t[0];t[0]=(1-Math.abs(t[1]))*rn(e),t[1]=(1-Math.abs(e))*rn(t[1])}return p(t,t)}function nn(t,e){return function(t,e,n){return t<e?e:t>n?n:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function rn(t){return t<0?-1:1}class sn{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.nt(t,e,n,r)):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.nt(t,s,n,r)})}nt(t,e,n,r){return this.lt(e,n,r,t).then(t=>t.error?t:{magic:"pnts",count:t.count,transferables:t.transferables,featureTable:t.featureTable,batchTable:t.batchTable,batchTableBin:t.batchTableBin,pnts:t.pnts})}lt(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts\'s byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:u,batchTableBin:f}=Be(s,e+28,o),h=a.QUANTIZED_VOLUME_OFFSET,l=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let y,m={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){m=a.extensions["3DTILES_draco_point_compression"],y=new DataView(t,m.byteOffset+c.offset,m.byteLength);const e={attributes:m.properties,useUniqueIDs:!1};return this.dt||(this.dt=We().draco),this.dt(y,e).then(e=>{const n=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||n.POSITION||n.POSITION_QUANTIZED||(n.POSITION=a.POSITION,n.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||n.RGB||n.RGBA||n.RGB565||(n.RGB=a.RGB,n.RGBA=a.RGBA,n.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||n.NORMAL||n.NORMAL_OCT16P||(n.NORMAL=a.NORMAL,n.NORMAL_OCT16P=a.NORMAL_OCT16P);const r=this.yt(t,e.attributes,c.offset,d,o,h,l);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Fe(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?r.BATCH_ID=Ce(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=on(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:u,batchTableBin:f,featureTable:a,pnts:r,transferables:o}})}const b=this.yt(t,a,c.offset,d,o,h,l);if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?b.BATCH_ID=Ce(a.BATCH_ID,t,c.offset,d):b.BATCH_ID=on(d);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:u,batchTableBin:f,featureTable:a,pnts:b,transferables:o})}yt(t,e,n,r,s,i,o){const a={};if(e.POSITION){let{byteOffset:i,array:o}=e.POSITION;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c}=e.POSITION_QUANTIZED;const{array:u}=e.POSITION_QUANTIZED;c=c||0;const f=u?0:n;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:this.ft(u||new Uint16Array(t,c+f,3*r),i,o)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:i,array:o}=e.RGBA;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+4*r);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB){let{byteOffset:i,array:o}=e.RGB;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB565){let{byteOffset:i,array:o}=e.RGB565;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:o},s.push(o.buffer)}if(e.NORMAL){let{byteOffset:i,array:o}=e.NORMAL;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:i,array:o}=e.NORMAL_OCT16P;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:o},s.push(o.buffer)}return a}ft(t,e,n){return Pe(new Float32Array(t.length),t,e,n)}st(){return null}}function on(t){const e=(n=t)<256?Uint8Array:n<65536?Uint16Array:Uint32Array;var n;const r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:Fe(e),array:r}}class an{constructor(t,e,n,r){this.i=n,this.s=t,this.tt=e||dt,this.it=r}load(t,e,n=0,r=0,s){return e?this.nt(t,e,n,r,s):J.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.nt(t,s,n,r)})}nt(t,e,n,r,s){r||(r=e.byteLength);const i=this.bt(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new Ze(this.s,this.tt,this.i);else if("i3dm"===i[n].magic)r=new tn(this.s,this.tt,this.i,this.it);else if("pnts"===i[n].magic)r=new sn;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new an(this.s,this.tt,this.i,this.it)}o.push(r.load(t,e,i[n].offset,i[n].byteLength,s).then(t=>t))}return Promise.all(o).then(t=>({magic:"cmpt",tiles:t}))}bt(t,e,n,r){const s=new DataView(t,n,r),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported cmpt version: "+i+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const o=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=Oe(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}function cn(t,e){if(t.scenes&&t.scenes.length)for(let n=0,r=t.scenes.length;n<r;n++){const r=t.scenes[n].nodes;for(let n=0,s=r.length;n<s;n++){const s=[];mn(r[n],s,t,e)}}}const un=[],fn=[],hn=[],ln=[0,0,0],dn=x([]),yn=[1,1,1];function mn(t,e,n,r){const c=e.slice(0);if(t.matrix)c.push(t.matrix);else if(t.rotation||t.translation||t.scale){const e=i(un,t.translation||ln),n=a(fn,t.rotation||dn),r=o(hn,t.scale||yn);s(r,n,r);const u=s([],e,r);c.push(u)}if(t.children&&t.children.length)for(let e=0,s=t.children.length;e<s;e++)mn(t.children[e],c,n,r);if(void 0!==t.mesh){const e=t.mesh,s=n.meshes[e];if(s){const t=c.slice(0),i=s.primitives;for(let s=0,o=i.length;s<o;s++){const o=i[s];o&&(o.matrices=t,r(o,e,s,n))}}}}function bn(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:i,itemSize:o}=t,a=t.array.buffer,c=i?dt.getTypedArrayCtor(i):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/o,(!r||r===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o)}return}const u=new Uint8Array(o*c.BYTES_PER_ELEMENT);r||(r=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,o*c.BYTES_PER_ELEMENT);u.set(s);e(new c(u.buffer),t),s.set(u)}}var pn=Tn("DXT1"),wn=Tn("DXT3"),gn=Tn("DXT5"),vn=Tn("DX10"),Mn=function(t){var e,n,r=new Int32Array(t,0,31);if(542327876!==r[0])throw new Error("Invalid magic number in DDS header");if(4&!r[20])throw new Error("Unsupported format, must contain a FourCC code");var s=r[21];switch(s){case pn:e=8,n="dxt1";break;case wn:e=16,n="dxt3";break;case gn:e=16,n="dxt5";break;case 116:n="rgba32f";break;case vn:var i=new Uint32Array(t.slice(128,148));n=i[0];var o=i[1];if(i[2],i[3],i[4],3!==o||2!==n)throw new Error("Unsupported DX10 texture format "+n);n="rgba32f";break;default:throw new Error("Unsupported FourCC code: "+(a=s,String.fromCharCode(255&a,a>>8&255,a>>16&255,a>>24&255)))}var a;var c=r[2],u=1;131072&c&&(u=Math.max(1,r[7]));var f=!1;512&r[28]&&(f=!0);var h,l=r[4],d=r[3],y=r[1]+4,m=l,b=d,p=[];s===vn&&(y+=20);if(f)for(var w=0;w<6;w++){if("rgba32f"!==n)throw new Error("Only RGBA32f cubemaps are supported");l=m,d=b;for(var g=Math.log(l)/Math.log(2)+1,v=0;v<g;v++)h=l*d*16,p.push({offset:y,length:h,shape:[l,d]}),v<u&&(y+=h),l=Math.floor(l/2),d=Math.floor(d/2)}else for(v=0;v<u;v++)h=Math.max(4,l)/4*Math.max(4,d)/4*e,p.push({offset:y,length:h,shape:[l,d]}),y+=h,l=Math.floor(l/2),d=Math.floor(d/2);return{shape:[m,b],images:p,format:n,flags:c,cubemap:f}};function Tn(t){return t.charCodeAt(0)+(t.charCodeAt(1)<<8)+(t.charCodeAt(2)<<16)+(t.charCodeAt(3)<<24)}const An=Math.PI/180,_n=6378137*Math.PI/180;function On(t,e,n){if("EPSG:3857"===n)return function(t,e){const n=85.0511287798,r=e[0],s=Math.max(Math.min(n,e[1]),-n);let i;i=0===s?0:Math.log(Math.tan((90+s)*An/2))/An;return t[0]=r*_n,t[1]=i*_n,t}(t,e);if("EPSG:4326"===n||"EPSG:4490"===n||"identity"===n)return Sn(t,e);if("baidu"===n)return Sn(t,e);throw new Error("unsupported projection:"+n)}function Sn(t,e){return t[0]=e[0],t[1]=e[1],t}const xn=r([]),In=We().draco,kn=We().ktx2,En={"pbrMetallicRoughness":{"baseColorFactor":[.5,.5,.5,1],"metallicFactor":0,"roughnessFactor":.5}},Cn={"position":{name:"POSITION",accessor:{"componentType":5126,"type":"VEC3"}},"normal":{name:"NORMAL",accessor:{"componentType":5126,"type":"VEC3"}},"uv0":{name:"TEXCOORD_0",accessor:{"componentType":5126,"type":"VEC2"}},"color":{name:"COLOR_0",accessor:{"componentType":5121,"type":"VEC4"}},"uv-region":{name:"uvRegion",accessor:{"componentType":5123,"type":"VEC4"}},"feature-index":{name:"_BATCHID",accessor:{"componentType":5125,"type":"SCALAR"}},"faceRange":{name:"faceRange",accessor:{"componentType":5125,"type":"VEC2"}}};function Un(t,e,n,s){const i=[],o=[],a=[];for(let e=0;e<t.meshes.length;e++){const{geometry:n,material:r}=t.meshes[e],s=J.getArrayBuffer(n.url);s.xhr.url=n.url,a.push(s.xhr);const c=s.then(t=>({buffer:t}));i.push(c);const u=[];if(Ln(r,u),u.length){const t=u.map(t=>{const e=J.getArrayBuffer(t.url);return e.xhr.url=t.url,a.push(e.xhr),e.then(e=>e&&e.status?null:{buffer:e,mimeType:t.mimeType,format:t.format})});i.push(...t)}o[e]=u.length}const c=Promise.all(i).then(i=>{for(let t=0;t<i.length;t++)if(!i[t]||!i[t].buffer)return Promise.resolve(null);const a=[];let c=0;for(let t=0;t<o.length;t++){const e=o[t];a.push({geoBuffer:{data:i[c].buffer.data},textureBuffers:i.slice(c+1,e+c+1).map(t=>({data:t.buffer.data,mimeType:t.mimeType,format:t.format}))}),c+=1+e}return function(t,e,n,s,i){const o={asset:{generator:"i3s",version:"2.0"},extensions:{},scene:0,scenes:[{nodes:[]}],nodes:{},meshes:{},materials:[],skins:[],animations:null,textures:[],transferables:[]},a=[];for(let c=0;c<t.meshes.length;c++){let{material:u}=t.meshes[c];const{geometry:f}=t.meshes[c];let h;const l=e[c].geoBuffer.data;if(!l)continue;const d=Gn(l);h=d?Fn(o,c,f,l,t.transform,t.center,i):Bn(o,c,f,l,t.transform,t.center,i),a.push(h),o.nodes[c]={mesh:c,nodeIndex:c,matrix:r([])},o.scenes[0].nodes[c]=o.nodes[c],u||(u=En);const y=Rn(c,o,u,e[c].textureBuffers,n,s);a.push(y)}return Promise.all(a).then(()=>({gltf:o,featureTable:{BATCH_LENGTH:0},transferables:o.transferables}))}(t,a,e,s,n)});return c.xhr=a,c}const Nn={"magFilter":9728,"minFilter":9728,"wrapR":33071,"wrapS":33071,"wrapT":33071};function Fn(t,e,n,r,s,i,o){const a=n.info.compressedAttributes.attributes.reduce((t,e,n)=>{const r=Cn[e];if(!r)return t;return t[r.name||e]=n,t},{});return In(r,{attributes:a,metadatas:{"POSITION":[{name:"i3s-scale_x",type:"double"},{name:"i3s-scale_y",type:"double"}]},useUniqueIDs:!1,skipAttributeTransform:!1}).then(n=>Dn(n,t,e,s,i,o))}const Pn={position:function(t,e,n){const r=3*t.vertexCount,s=new Float32Array(e,n,r);return t.position={array:s,componentType:5126,itemSize:3,count:r/3,meta:{"i3s-scale_x":1,"i3s-scale_y":1},type:"VEC3"},n+=4*r},normal:function(t,e,n){const r=3*t.vertexCount,s=new Float32Array(e,n,r);return t.normal={array:s,componentType:5126,itemSize:3,count:r/3,type:"VEC3"},n+=4*r},uv0:function(t,e,n){const r=2*t.vertexCount,s=new Float32Array(e,n,r);return t.uv0={array:s,componentType:5126,itemSize:2,count:r/2,type:"VEC2"},n+=4*r},color:function(t,e,n){const r=4*t.vertexCount,s=new Uint8Array(e,n,r);return t.color={array:s,componentType:5121,itemSize:4,count:r/4,type:"VEC4"},n+=r},featureId:function(t,e,n){return n+=8*t.featureCount},id:function(t,e,n){return n+=8*t.featureCount},faceRange:function(t,e,n){const r=2*t.featureCount,s=new Uint32Array(e,n,r);return t.faceRange={array:s,componentType:5125,itemSize:2,count:r/2,type:"VEC2"},n+=4*r},uvRegion:function(t,e,n){const r=4*t.vertexCount,s=new Uint16Array(e,n,r);return t["uv-region"]={array:s,componentType:5123,itemSize:4,count:r/4,type:"VEC4"},n+=2*r},region:function(t,e,n){const r=4*t.vertexCount,s=new Uint16Array(e,n,r);return t["uv-region"]={array:s,componentType:5123,itemSize:4,count:r/4,type:"VEC4"},n+=2*r}};function Bn(t,e,n,r,s,i,o){const a={vertexCount:0},c=new DataView(r);try{let t=0;a.vertexCount=c.getUint32(t,1),t+=4,a.featureCount=c.getUint32(t,1),t+=4;const e=n.info.ordering?null:n.info;if(e){const n=[];for(const t in e)"offset"!==t&&""!==t&&n.push(t);for(let e=0;e<n.length;e++)Pn[n[e]]?t=Pn[n[e]](a,r,t):console.error("Unknown decoder for",n[e])}else{const e=n.info;let s=e.ordering,i=e.featureAttributeOrder;const o=null;o&&o.geometryData&&o.geometryData[0]&&o.geometryData[0].params;for(let e=0;e<s.length;e++){const n=Pn[s[e]];n||console.log(s[e]),t=n(a,r,t)}for(let e=0;e<i.length;e++){const n=Pn[i[e]];n||console.log(i[e]),t=n(a,r,t)}}}catch(t){}a.scale_x=1,a.scale_y=1;const u={};for(const t in a){const e=Cn[t]&&Cn[t].name;e&&(u[e]=a[t])}if(a.faceRange){const t=a.faceRange.array,e=t.length/2,n=(f=e)<=255?Uint8Array:f<=65535?Uint16Array:Uint32Array,r=new n(u.POSITION.array.length/3);for(let e=0;e<t.length-1;e+=2){const n=e/2,s=t[e],i=t[e+1];for(let t=s;t<=i;t++)r[3*t]=n,r[3*t+1]=n,r[3*t+2]=n}u._BATCHID={componentType:He(n),array:r,itemSize:1,count:r.length,type:"SCALAR"}}var f;return Dn({attributes:u},t,e,s,i,o)}function Dn(t,e,n,r,s,i){const o={attributes:t.attributes,material:n,indices:t.indices,mode:4};!function(t){const e=t.array,n=t.meta&&t.meta["i3s-scale_x"],r=t.meta&&t.meta["i3s-scale_y"];if(n&&r&&(1!==n||1!==r))for(let t=0;t<e.length;t+=3)e[t]*=n.value,e[t+1]*=r.value}(t.attributes.POSITION);const a=function(t,e,n,r){const s=n;let i,o=[0,0,0,1];const a=[0,0],u=On([],n,r);u[2]=n[2];const f=e&&c(xn,e);return bn(t,t=>(o[0]=t[0],o[1]=t[1],o[2]=t[2],f||(o=v(o,o,e)),s&&y(o,o,s),On(a,o,r),i=o[2],t[0]=a[0]-u[0],t[1]=a[1]-u[1],t[2]=i-u[2],t)),u}(t.attributes.POSITION,r,s,i);e.meshes[n]={primitives:[o],index:n},e.extensions.MAPTALKS_RTC={projCenter:a},e.extensions.CESIUM_RTC={rtcCoord:s};for(const n in t.attributes)$n(e.transferables,t.attributes[n].array.buffer);return t.indices&&$n(e.transferables,t.indices.array.buffer),o}function Rn(t,e,n,r,s,i){const o=r.map(t=>function(t,e,n,r,s){if("dds"===e){const e=Mn(t),r=e.images.map(e=>new Uint8Array(t,e.offset,e.length)),s="dxt1"===e.format?33777:33779;return Promise.resolve({image:{mipmap:r,width:e.shape[0],height:e.shape[1],mimeType:n},sampler:Nn,format:s})}if("png"===e||"jpg"===e)return function(t,e){zn||(zn=new OffscreenCanvas(2,2),jn=zn.getContext("2d",{willReadFrequently:!0}));const n=new Blob([new Uint8Array(t)]);return createImageBitmap(n).then(t=>{let{width:n,height:r}=t;Vn(n)||(n=qn(n)),Vn(r)||(r=qn(r));const s=e;s&&(n=Math.min(s,n),r=Math.min(s,r)),zn.width=n,zn.height=r,jn.drawImage(t,0,0,n,r),t.close();const i=jn.getImageData(0,0,n,r);return{width:n,height:r,array:new Uint8Array(i.data)}}).catch(()=>({width:2,height:2,array:new Uint8Array(4)}))}(t,s).then(t=>{t.mimeType=n;return{image:t,sampler:Nn,format:6408}});if("ktx2"===e)return kn(t,r).then(t=>(t.mimeType=n,{image:t,sampler:Nn,format:t.format}));return null}(t.data,t.format,t.mimeType,s,i).then(t=>{if(t.image)if(t.image.array)$n(e.transferables,t.image.array.buffer);else if(t.image.mipmap)for(let n=0;n<t.image.mipmap.length;n++)$n(e.transferables,t.image.mipmap[n].buffer);return t}));return Promise.all(o).then(r=>{!function t(e,n,r,s){const i=JSON.parse(JSON.stringify(r)),o=n.textures;s.ptr||(s.ptr=0);for(const e in r)r[e]&&r[e].url?(o.push(s[s.ptr++]),i[e]={index:o.length-1},void 0!==r[e].factor&&(i[e].scale=r[e].factor)):fe(r[e])&&(i[e]=t(-1,n,r[e],s));e>=0&&(n.materials[e]=i);return i}(t,e,n,r)})}function Ln(t,e){for(const n in t)t[n]&&t[n].url?e.push({url:t[n].url,mimeType:t[n].mimeType,format:t[n].format}):fe(t[n])&&Ln(t[n],e)}let zn,jn;function Vn(t){return 0==(t&t-1)&&0!==t}function qn(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function $n(t,e){e&&(t.indexOf(e)>=0||t.push(e))}function Gn(t){const e=new Uint8Array(t,0,5);return e[0]==="D".charCodeAt()&&e[1]==="R".charCodeAt()&&e[2]==="A".charCodeAt()&&e[3]==="C".charCodeAt()&&e[4]==="O".charCodeAt()}const Xn=[];const Hn=[],Jn=[],Kn=[],Yn=[],Qn=[],Wn=[],Zn=[];function tr(t,e,n,r,s,i){d(Yn,t[3*e],t[3*e+1],t[3*e+2]),d(Qn,t[3*n],t[3*n+1],t[3*n+2]),d(Wn,t[3*r],t[3*r+1],t[3*r+2]);const o=M(Hn,Wn,Qn),a=M(Jn,Yn,Qn),c=g(Kn,o,a);p(Zn,c),s[3*e]+=Zn[0],s[3*n]+=Zn[0],s[3*r]+=Zn[0],s[3*e+1]+=Zn[1],s[3*n+1]+=Zn[1],s[3*r+1]+=Zn[1],s[3*e+2]+=Zn[2],s[3*n+2]+=Zn[2],s[3*r+2]+=Zn[2],i[e]+=1,i[n]+=1,i[r]+=1}const er=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],nr=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],rr=2*Math.PI*6378137/360,sr="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;let ir,or=!1;if("undefined"!=typeof OffscreenCanvas){try{ir=new OffscreenCanvas(2,2).getContext("2d",{willReadFrequently:!0})}catch(t){}ir&&"undefined"!=typeof createImageBitmap&&(or=!0)}const ar=r([]),cr=[0,0,0],ur=[],fr=[],hr=[],lr=[],dr={"POSITION":1,"TEXCOORD_0":1,"TEXCOORD_1":1,"NORMAL":1,"TANGENT":1},yr={"TEXCOORD_0":1e-4,"TEXCOORD_1":1e-4};class mr{constructor(t,e,n,r){this.id=t,this.options=e,this.pt=this.requestImage.bind(this),this.wt=n,this.gt={},r(null,{},[])}vt(t){this.Mt||(this.i=t,this.Tt=new sn,this.Mt=new Ze(this.pt,dt,t),this.At=new tn(this.pt,dt,t))}requestImage(t,e){or?fetch(t).then(t=>t.arrayBuffer()).then(t=>{const e=new self.Blob([new Uint8Array(t)]);return createImageBitmap(e)}).then(t=>{(void 0).width=t.width,(void 0).height=t.height,ir.drawImage(t,0,0);const n=ir.getImageData(0,0,(void 0).width,(void 0).height);t.close(),e(null,{width:t.width,height:t.height,data:new Uint8Array(n.data)})}):this.wt("requestImage",{url:t},null,e)}loadTile(t,e){this.vt(t.supportedFormats);const n=t.service,r=t.url,s=t.arraybuffer;if(function(t){return t.indexOf("i3s:")>=0}(r)){const s=t.i3sInfo,i=n.maxTextureSize||1024,o=Un(s,t.supportedFormats,this.options.projection,i);return o.then(t=>{if(delete this.gt[r],!t)return void e({status:404,url:r,i3sInfo:s});if(!Object.keys(t.gltf.meshes).length)return void e({status:404,url:r,i3sInfo:s});t.gltf.url=r;const{transferables:n}=t;t.magic="b3dm",this._t(t.gltf),e(null,t,n)}),void(this.gt[r]=o.xhr)}if(s){delete this.gt[r];const n=Oe(new DataView(s),0);if("{"===n[0]||" "===n[0]||"<"===n[0]){const n=function(t,e,n){if(sr){const r=new Uint8Array(t,e,n);return sr.decode(r)}return ye(new Uint8Array(t,e,n))}(s,0,s.byteLength),i=JSON.parse(n);this.Ot(t.rootIdx,i,s,r,e)}else this.St(s,r,t,n,e)}else{let s=n.urlParams;s&&(s=(r.indexOf("?")>0?"&":"?")+s);const i=r.replace(/\\+/g,"%2B");let o=J.getArrayBuffer(i+(s||""),n.fetchOptions);const a=o.xhr;o=o.then(n=>{delete this.gt[r],n&&n.status?e(n):(t.arraybuffer=n&&n.data,this.loadTile(t,e))}).catch(t=>{delete this.gt[r],e(t)}),this.gt[r]=a}}St(t,e,n,r,s){const i=n.service;if("b3dm"===r){this.Mt.load(e,t,0,0,{maxTextureSize:i.maxTextureSize||1024}).then(t=>{if(t.error)return void s(t);const{content:e,transferables:r}=this.xt(t,n);this._t(e.gltf),s(null,e,r)}).catch(t=>{s(t)})}else if("pnts"===r){const r=n.transform;this.Tt.load(e,t).then(t=>{const{content:e,transferables:i}=this.It(t,r,n.rootIdx);this.kt(e),s(null,e,i)})}else if("i3dm"===r){const r=n.transform;this.At.load(e,t,0,0,{maxTextureSize:i.maxTextureSize||1024}).then(t=>{const{content:e,transferables:i}=this.It(t,r,n.rootIdx);this._t(e.gltf),s(null,e,i)})}else if("cmpt"===r){new an(this.pt,dt,this.i,i.maxTextureSize||1024).load(e,t,0,0,{maxTextureSize:i.maxTextureSize||1024}).then(t=>{const{content:e,transferables:r}=this.Et(t,n);this.Ct(e),s(null,e,r)}).catch(t=>{s(t)})}else s(new Error("unsupported tile format: "+r))}Ct(t){t.content?t.content.forEach(t=>{this.Ct(t)}):this._t(t.gltf)}Ut(t,e){const n=e.materials[t.material];if(n&&n.extensions&&n.extensions.KHR_materials_unlit)return;if(t.attributes.TANGENT)return;if(t.attributes.TEXCOORD_0&&!t.attributes.NORMAL){const e=t.attributes.POSITION.array,n=function(t,e,n){const r=n||[];r.setLength&&r.setLength(t.length);const s=Xn;s.length<t.length/3&&(s.length=t.length/3),s.fill(0,0,t.length/3),r.fill(0,0,t.length);for(let n=0;n<e.length/3;n++)tr(t,e[3*n],e[3*n+1],e[3*n+2],r,s);for(let t=0;t<r.length;t+=3){const e=s[t/3];0!==e&&(r[t]/=e,r[t+1]/=e,r[t+2]/=e)}return r}(e,t.indices.array,new Float32Array(e.length));t.attributes.NORMAL={array:n,byteLength:n.byteLength,byteOffset:0,byteStride:0,componentType:5126,count:n.length/3,itemSize:3,name:"NORMAL",type:"VEC3"}}}_t(t){if(!t||!t.meshes||t.extensionsUsed&&t.extensionsUsed.indexOf("KHR_techniques_webgl")>-1)return;const e=t.meshes;for(const n in e){e[n].primitives.forEach(e=>{this.Ut(e,t),e.compressed_int16_params={};const n=e.attributes;for(const t in n)if(dr[t]&&n[t].array&&n[t].array instanceof Float32Array){const r=this.options.projection;let s=1;"EPSG:4326"!==r&&"EPSG:4490"!==r||"POSITION"!==t||(s=rr,e.compressed_int16_params.compressed_ratio=s);const i=Mr(n[t].array,s,n[t].min,n[t].max,t);if(!i)continue;const{array:o,range:a}=i;n[t].array=o,e.compressed_int16_params[t]=a}})}}kt(t){if(!t||!t.pnts)return;const e=t.pnts;t.compressed_int16_params={};for(const n in e)if(dr[n]&&e[n].array&&e[n].array instanceof Float32Array){const r=this.options.projection;let s=1;"EPSG:4326"!==r&&"EPSG:4490"!==r||"POSITION"!==n||(s=rr,t.compressed_int16_params.compressed_ratio=s);const{array:i,range:o}=Mr(e[n].array,s,e[n].min,e[n].max,n);e[n].array=i,t.compressed_int16_params[n]=o}}Nt(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n];if(!r.childTile)continue;const s={boundingVolume:{sphere:[r.boundingSphere.center.x,r.boundingSphere.center.y,r.boundingSphere.center.z,r.boundingSphere.radius]},content:{uri:r.childTile},geometricError:r.boundingSphere.radius/r.rangeList*16,refine:"REPLACE"};e.push(s)}return e}Ot(t,e,n,r,s){return e.capabilities,void s(null,e)}Et(t,e){const{tiles:n}=t,r={magic:"cmpt",content:[]},s=[];for(let t=0;t<n.length;t++){const{magic:i}=n[t];if("b3dm"===i){const{content:i,transferables:o}=this.xt(n[t],e);gr(s,o),r.content.push(i)}else if("i3dm"===i||"pnts"===i){const{transform:i,rootIdx:o}=e,{content:a,transferables:c}=this.It(n[t],i,o);gr(s,c),r.content.push(a)}else if("cmpt"===i){const{content:i,transferables:o}=this.Et(n[t],e);gr(s,o),r.content.push(i)}}return{content:r,transferables:s}}xt(t,e){const{gltf:n,transferables:r,featureTable:s}=t,i=function(t){if(!t||!t.meshes)return!1;let e=1;const n=[];for(const r in t.meshes){const s=t.meshes[r],{primitives:i}=s;if(i)for(let t=0;t<i.length;t++){const r=i[t].attributes&&i[t].attributes.POSITION;if(!r||!r.array)continue;r.array.buffer.visited||(r.array.buffer.visited=e++);const s=e-1+"-"+(r.byteOffset||0);if(n.indexOf(s)>=0)return!0;n.push(s)}}return!1}(n);return this.Ft(t.gltf),t.gltf.asset||(t.gltf.asset={}),i?(t.gltf.asset.sharePosition=!0,this.Pt(n,s,e.upAxis,e.transform)):this.Bt(n,s,e.upAxis,e.transform),delete t.transferables,{content:t,transferables:r}}It(t,e,r){const{featureTable:s}=t,i=t.pnts||t.i3dm,o=s&&s.RTC_CENTER||[0,0,0];if(s.EAST_NORTH_UP&&!i.NORMAL_UP&&!i.NORMAL_UP_OCT32P){const e=new Float32Array(3*i.POSITION.array.length),r=[],s=[],a=[];bn(i.POSITION,(t,i)=>{y(a,t,o),Ge(a,null,r),n(s,r);!function(t,e){t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8]}(e.subarray(9*i,9*(i+1)),s)}),i.INSTANCE_ROTATION={byteStride:0,byteOffset:0,itemSize:9,componentType:5126,array:e},t.transferables.push(e.buffer)}const a={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};pr(i.POSITION.array,3,o,ar,a);const c=wr(a),u=l([],c),f=[1/0,1/0,1/0],h=[-1/0,-1/0,-1/0];bn(i.POSITION,t=>{t[0]=t[0]+o[0]-u[0],t[1]=t[1]+o[1]-u[1],t[2]=t[2]+o[2]-u[2],t[0]<f[0]&&(f[0]=t[0]),t[1]<f[1]&&(f[1]=t[1]),t[2]<f[2]&&(f[2]=t[2]),t[0]>h[0]&&(h[0]=t[0]),t[1]>h[1]&&(h[1]=t[1]),t[2]>h[2]&&(h[2]=t[2])}),i.POSITION.min=f,i.POSITION.max=h,e&&v(c,c,e);const d=this.Dt(c);t.rtcCenter=u,t.rtcCoord=d,t.rootIdx=r;const m=t.transferables;return delete t.transferables,{content:t,transferables:m}}Ft(t){if(!Array.isArray(t.textures))return;const e=t.textures;for(let t=0;t<e.length;t++){const n=e[t].image&&e[t].image.array;if(n&&n.length){const r=n[0],s=n[1],i=n[2],o=n[3];let a=!0;for(let t=4;t<n.length;t+=4)if(n[t]!==r||n[t+1]!==s||n[t+2]!==i||n[t+3]!==o){a=!1;break}a&&(e[t].image.color=[r/255,s/255,i/255,o/255],delete e[t].image.array)}}}abortTileLoading(t,e){const n=this.gt[t.url];if(Array.isArray(n))for(let t=0;t<n.length;t++)n[t].abort();else n&&n.abort&&n.abort();delete this.gt[t.url],e(null)}Rt(t,e,n,i){const o=e&&e.RTC_CENTER||t.extensions&&t.extensions.CESIUM_RTC&&t.extensions.CESIUM_RTC.center;let a=er;"X"===(n=n&&n.toUpperCase())?a=nr:"Z"===n&&(a=ar),t.extensions=t.extensions||{},t.extensions.CESIUM_RTC||(t.extensions.CESIUM_RTC={}),o&&(t.extensions.CESIUM_RTC.center=o),t.extensions.MAPTALKS_RTC={};const c={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};cn(t,t=>{if(!(t.attributes&&t.attributes.POSITION))return;const e=r(ur);t.matrices&&vr(e,t.matrices);const n=t.attributes.POSITION.array,u=t.attributes.POSITION.itemSize;s(e,a,e),i&&s(e,i,e),pr(n,u,o||cr,e,c,t.compressUniforms)});const u=wr(c);return{rtcCenter:o,modelCenter:u,upAxisTransform:a}}Pt(t,e,n,i){const{modelCenter:o,upAxisTransform:a,rtcCenter:c}=this.Rt(t,e,n),u=l([],o);i&&v(o,o,i),t.extensions.CESIUM_RTC.rtcCoord=this.Dt(o),c||(cn(t,t=>{if(t.attributes&&t.attributes.POSITION){const e=t.attributes.POSITION;if(e.array.buffer.projected&&e.array.buffer.projected[e.byteOffset])return;const n=r(ur);t.matrices&&vr(n,t.matrices),s(n,a,n);const i=function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],a=e[5],c=e[6],u=e[7],f=e[8],h=e[9],l=e[10],d=e[11],y=e[12],m=e[13],b=e[14],p=e[15],w=n*a-r*o,g=n*c-s*o,v=n*u-i*o,M=r*c-s*a,T=r*u-i*a,A=s*u-i*c,_=f*m-h*y,O=f*b-l*y,S=f*p-d*y,x=h*b-l*m,I=h*p-d*m,k=l*p-d*b,E=w*k-g*I+v*x+M*S-T*O+A*_;return E?(E=1/E,t[0]=(a*k-c*I+u*x)*E,t[1]=(s*I-r*k-i*x)*E,t[2]=(m*A-b*T+p*M)*E,t[3]=(l*T-h*A-d*M)*E,t[4]=(c*S-o*k-u*O)*E,t[5]=(n*k-s*S+i*O)*E,t[6]=(b*v-y*A-p*g)*E,t[7]=(f*A-l*v+d*g)*E,t[8]=(o*I-a*S+u*_)*E,t[9]=(r*S-n*I-i*_)*E,t[10]=(y*T-m*v+p*w)*E,t[11]=(h*v-f*T-d*w)*E,t[12]=(a*O-o*x-c*_)*E,t[13]=(n*x-r*O+s*_)*E,t[14]=(m*g-y*M-b*w)*E,t[15]=(f*M-h*g+l*w)*E,t):null}(fr,n),o=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];bn(e,t=>{v(t,t,n),t[0]=t[0]-u[0],t[1]=t[1]-u[1],t[2]=t[2]-u[2],v(t,t,i),t[0]<o[0]&&(o[0]=t[0]),t[1]<o[1]&&(o[1]=t[1]),t[2]<o[2]&&(o[2]=t[2]),t[0]>c[0]&&(c[0]=t[0]),t[1]>c[1]&&(c[1]=t[1]),t[2]>c[2]&&(c[2]=t[2])}),e.min=o,e.max=c,e.array.buffer.projected||(e.array.buffer.projected={}),e.array.buffer.projected[e.byteOffset]=1}}),t.extensions.CESIUM_RTC.center=u)}Bt(t,e,n,r){const{modelCenter:s,rtcCenter:i}=this.Rt(t,e,n,r),o=this.Lt(s);t.extensions.MAPTALKS_RTC.projCenter=o,t.extensions.CESIUM_RTC.rtcCoord=this.Dt(s),cn(t,e=>{if(e.attributes&&e.attributes.POSITION){e.attributes.NORMAL&&this.zt(e.attributes.NORMAL,e.matrices,n),e.attributes.TANGENT&&this.zt(e.attributes.TANGENT,e.matrices,n);const{newPositions:s}=this.jt(e.attributes.POSITION,e.matrices,i,t.extensions.MAPTALKS_RTC,n,r,e.compressUniforms),{componentType:o}=e.attributes.POSITION;5126!==o&&(e.attributes.POSITION.array=new Float32Array(s))}});for(const e in t.nodes){t.nodes[e].matrix=ar}}Lt(t){0===A(t)?d(hr,0,0,-6378137):ve(hr,t);const e=this.options.projection;On(lr,hr,e);const n=hr[2],r=[];return r[0]=lr[0],r[1]=lr[1],r[2]=n,r}zt(t,e,r){let s;s="Y"===r?er:"X"===r?nr:ar;const i=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}([],s);if(vr(i,e),c(i,ar))return;const o=n([],i),a=[];bn(t,t=>(function(t,e,n){var r=e[0],s=e[1],i=e[2];t[0]=r*n[0]+s*n[3]+i*n[6],t[1]=r*n[1]+s*n[4]+i*n[7],t[2]=r*n[2]+s*n[5]+i*n[8]}(a,t,o),p(a,a),l(t,a),a))}jt(t,e,n,s,i,o,a){if(t.array.buffer.projected&&t.array.buffer.projected[t.byteOffset])return null;const u=r([]);vr(u,e);const f=this.options.projection;i=i&&i.toUpperCase();const h=n;let l=null;"Y"===i?l=er:"X"===i&&(l=nr);let m=[0,0,0,1];const b=[0,0,0],p=[0,0],w=s.projCenter,g=o&&c(ar,o),M=t.min=t.min||[],T=t.max=t.max||[];d(M,1/0,1/0,1/0),d(T,-1/0,-1/0,-1/0);const _=a||{},{decode_position_min:O,decode_position_normConstant:S}=_;let x=[0,0,0,0],I=1;O&&(x=O),S&&(I=S);const k=[];return bn(t,t=>{if(m[0]=t[0]*I+x[0],m[1]=t[1]*I+x[1],m[2]=t[2]*I+x[2],m=v(m,m,u),l&&(m=v(m,m,l)),h&&y(m,m,h),o&&!g&&(m=v(m,m,o)),0===A(m)?d(b,0,0,-6378137):ve(b,m),On(p,b,f),t instanceof Float32Array)t[0]=p[0]-w[0],t[1]=p[1]-w[1],t[2]=b[2]-w[2];else{const e=p[0]-w[0],n=p[1]-w[1],r=b[2]-w[2];k.push(e),k.push(n),k.push(r),k.push(t[3])}return t[0]<M[0]&&(M[0]=t[0]),t[1]<M[1]&&(M[1]=t[1]),t[2]<M[2]&&(M[2]=t[2]),t[0]>T[0]&&(T[0]=t[0]),t[1]>T[1]&&(T[1]=t[1]),t[2]>T[2]&&(T[2]=t[2]),t}),t.array.buffer.projected||(t.array.buffer.projected={}),t.array.buffer.projected[t.byteOffset]=1,{projCenter:w,newPositions:k}}Dt(t){return 0===A(t)?d([],0,0,-6378137):ve([],t)}onRemove(){}}const br=[];function pr(t,e,n,r,s,i){const o=i||{},{decode_position_min:a,decode_position_normConstant:c}=o;let u=[0,0,0,0],f=1;a&&(u=a),c&&(f=c);for(let i=0,o=t.length;i<o;i+=e){const{xmin:o,ymin:a,xmax:c,ymax:h,hmin:l,hmax:m}=s;d(br,t[i]*f+u[0],t[i+1]*f+u[1],t[i+2]*f+u[2]),v(br,br,r);const b=y(br,n,br);b[0]<o&&(s.xmin=b[0]),b[0]>c&&(s.xmax=b[0]),b[1]<a&&(s.ymin=b[1]),b[1]>h&&(s.ymax=b[1]),e>2&&(b[2]<l&&(s.hmin=b[2]),b[2]>m&&(s.hmax=b[2]))}}function wr(t){const{xmax:e,ymax:n,xmin:r,ymin:s,hmin:i,hmax:o}=t,a=[(r+e)/2,(s+n)/2,(i+o)/2];return e===-1/0&&(a[0]=0),n===-1/0&&(a[1]=0),o===-1/0&&(a[2]=0),isNaN(a[2])&&(a[2]=0),a}function gr(t,e){for(let n=0;n<e.length;n++)t.indexOf(e[n])<0&&t.push(e[n])}function vr(t,e){const n=t;for(let t=e.length-1;t>=0;t--)s(n,e[t],n);return n}function Mr(t,e,n,r,s){if(e&&e>1)for(let n=0;n<t.length;n++)(n+1)%3!=0&&(t[n]*=e);let i,o;if(n&&r&&1===e)i=Math.min(...n),o=Math.max(...r);else{const{min:e,max:n}=function(t){let e=1/0,n=-1/0;for(let r=0;r<t.length;r++)t[r]>n&&(n=t[r]),t[r]<e&&(e=t[r]);return{min:e,max:n}}(t);i=e,o=n}return!function(t,e,n,r){for(let s=0;s<t.length;s++){const i=Tr(Ar(t[s],e,n),e,n);if(Math.abs(i-t[s])>yr[r])return!1}return!0}(t,i,o,s)&&yr[s]?(console.warn(s+" is not compressed!"),null):function(t,e,n){const r=new Int16Array(t.length);for(let s=0;s<t.length;s++)r[s]=Ar(t[s],e,n);return{array:r,range:[e,n]}}(t,i,o)}function Tr(t,e,n){return((t>=32768?-(65536-t)/32768:t/32767)+1)*(n-e)/2+e}function Ar(t,e,n){const r=2*(t-e)/(n-e)-1,s=Math.max(-1,Math.min(1,r));return s<0?32768*s:32767*s}let _r=0;class Or{constructor(t){this.workerId=t,this.workers={},this.Vt={}}addLayer({actorId:t,mapId:e,layerId:n,params:r},s){if(this.qt(e,n))return;const i=this.$t(e,n),o=r.options,a=this.send.bind(this,t);this.workers[i]=new mr(n,o,a,s)}removeLayer({mapId:t,layerId:e},n){const r=this.qt(t,e),s=this.$t(t,e);delete this.workers[s],r&&r.onRemove(n)}loadTile({mapId:t,layerId:e,params:n},r){const s=this.qt(t,e);s&&s.loadTile(n,r)}abortTileLoading({mapId:t,layerId:e,params:n},r){const s=this.qt(t,e);s&&s.abortTileLoading(n,r)}receive(t){const e=t.callback,n=this.Vt[e];delete this.Vt[e],n&&t.error?n(new Error(t.error)):n&&n(null,t.data)}send(t,e,n,r,s){const i=s?`${t}-${_r++}`:null;s&&(this.Vt[i]=s),postMessage({type:"<request>",workerId:this.workerId,actorId:t,command:e,params:n,callback:String(i)},r||[])}$t(t,e){return`${t}-${e}`}qt(t,e){const n=this.$t(t,e);return this.workers[n]}}t.initialize=function(){},t.onmessage=function(t,e){const n=t.data;this.dispatcher||(this.dispatcher=new Or(t.workerId)),"<response>"===t.type?this.dispatcher.workerId===t.workerId&&this.dispatcher.receive(t):this.dispatcher[n.command]({actorId:n.actorId,mapId:n.mapId,layerId:n.layerId,params:n.params},(t,n,r)=>{t instanceof Error&&(t={message:t.message}),e(t,n,r)})},Object.defineProperty(t,"Gt",{value:!0})}';for(
7
7
  /*!
8
8
  * Contains code from THREE.js
9
9
  * MIT License
10
10
  * https://github.com/mrdoob/three.js
11
11
  */
12
- var a=[],c=0;c<6;c++)a[c]=[];var h=[];function u(t,e,n){l(t);for(var r=0;r<6;r++)if(!n||"0"!==n.charAt(r)){var s=a[r];if(h[0]=s[0]>0?e[1][0]:e[0][0],h[1]=s[1]>0?e[1][1]:e[0][1],h[2]=s[2]>0?e[1][2]:e[0][2],m(s,h)<0)return!1}return!0}function f(t,e){var n=e,r=t,s=e,i=r[0],o=r[1],a=r[2],c=Math.abs(i*s[3]+o*s[6]+a*s[9])+Math.abs(i*s[4]+o*s[7]+a*s[10])+Math.abs(i*s[5]+o*s[8]+a*s[11]),h=m(t,n);return!(h<=-c)}function l(t){var e=t,n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],c=e[5],h=e[6],u=e[7],f=e[8],l=e[9],m=e[10],p=e[11],y=e[12],b=e[13],g=e[14],T=e[15];d(a[0],i-n,u-o,p-f,T-y),d(a[1],i+n,u+o,p+f,T+y),d(a[2],i+r,u+c,p+l,T+b),d(a[3],i-r,u-c,p-l,T-b),d(a[4],i-s,u-h,p-m,T-g),d(a[5],i+s,u+h,p+m,T+g)}function d(t,e,n,r,s){var i=1/Math.sqrt(e*e+n*n+r*r);return t[0]=e*i,t[1]=n*i,t[2]=r*i,t[3]=s*i,t}function m(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]}function p(t){return null==t}function y(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 b(t){return null!=t&&("function"==typeof t||null!==t.constructor&&t.constructor===Function)}function g(t){return"object"==typeof t&&!!t}function T(t){return"number"==typeof t&&!isNaN(t)}function w(t){return t*Math.PI/180}function _(t){return t/Math.PI*180}function A(t){let e=document.createElement("a");return e.href=t,t=e.href,e=null,t}function O(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const x=[1,1,1,1,2,2,3,0];function I(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=x[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}function S(t,e,n){return t[3*n]=e[0],t[3*n+1]=e[1],t[3*n+2]=e[2],t}function M(t){return t.flat?t.flat(1/0):t.reduce((t,e)=>t.concat(e),[])}function N(t){return t<256?Uint8Array:t<65536?Uint16Array:Uint32Array}function v(t){return 0===t.indexOf("data:")}function E(t){const e=t.indexOf("base64,"),n=t.substring(e+7),r=window.atob(n),s=r.length,i=new Uint8Array(s);for(let t=0;t<s;t++)i[t]=r.charCodeAt(t);return i.buffer}function C(t){for(let e=1;e<arguments.length;e++){const n=arguments[e];if(n)for(let e=0,r=n.length;e<r;e++)t.push(n[e])}return t.length}var R=Object.freeze({__proto__:null,isNil:p,extend:y,isFunction:b,isObject:g,isNumber:T,toRadian:w,toDegree:_,getAbsoluteURL:A,sign:O,stringFromUTF8Array:I,setColumn3:S,flatArr:M,getBatchIdArrayType:N,isBase64:v,base64URLToArrayBuffer:E,pushIn:C});var P="undefined"!=typeof Float32Array?Float32Array:Array;function U(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}function B(t,e,n){var r=e[0],s=e[1],i=e[2],o=e[3],a=e[4],c=e[5],h=e[6],u=e[7],f=e[8],l=e[9],d=e[10],m=e[11],p=e[12],y=e[13],b=e[14],g=e[15],T=n[0],w=n[1],_=n[2],A=n[3];return t[0]=T*r+w*a+_*f+A*p,t[1]=T*s+w*c+_*l+A*y,t[2]=T*i+w*h+_*d+A*b,t[3]=T*o+w*u+_*m+A*g,T=n[4],w=n[5],_=n[6],A=n[7],t[4]=T*r+w*a+_*f+A*p,t[5]=T*s+w*c+_*l+A*y,t[6]=T*i+w*h+_*d+A*b,t[7]=T*o+w*u+_*m+A*g,T=n[8],w=n[9],_=n[10],A=n[11],t[8]=T*r+w*a+_*f+A*p,t[9]=T*s+w*c+_*l+A*y,t[10]=T*i+w*h+_*d+A*b,t[11]=T*o+w*u+_*m+A*g,T=n[12],w=n[13],_=n[14],A=n[15],t[12]=T*r+w*a+_*f+A*p,t[13]=T*s+w*c+_*l+A*y,t[14]=T*i+w*h+_*d+A*b,t[15]=T*o+w*u+_*m+A*g,t}function L(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}function D(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}function F(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,h=n*o,u=r*o,f=r*a,l=s*o,d=s*a,m=s*c,p=i*o,y=i*a,b=i*c;return t[0]=1-f-m,t[1]=u+b,t[2]=l-y,t[3]=0,t[4]=u-b,t[5]=1-h-m,t[6]=d+p,t[7]=0,t[8]=l+y,t[9]=d-p,t[10]=1-h-f,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function k(){var t=new P(3);return P!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function H(t){var e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function V(t,e,n){var r=new P(3);return r[0]=t,r[1]=e,r[2]=n,r}function j(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function G(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t}function z(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function q(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t}function X(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function $(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function W(t,e){var n=e[0],r=e[1],s=e[2],i=n*n+r*r+s*s;return i>0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i),t}function K(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function Q(t,e,n){var r=e[0],s=e[1],i=e[2],o=n[0],a=n[1],c=n[2];return t[0]=s*c-i*a,t[1]=i*o-r*c,t[2]=r*a-s*o,t}var Z=q,J=X,Y=H;function tt(t,e,n,r,s){return t[0]=e,t[1]=n,t[2]=r,t[3]=s,t}function et(t,e,n){var r=e[0],s=e[1],i=e[2],o=e[3];return t[0]=n[0]*r+n[4]*s+n[8]*i+n[12]*o,t[1]=n[1]*r+n[5]*s+n[9]*i+n[13]*o,t[2]=n[2]*r+n[6]*s+n[10]*i+n[14]*o,t[3]=n[3]*r+n[7]*s+n[11]*i+n[15]*o,t}function nt(){var t=new P(4);return P!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function rt(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function st(t,e,n,r){var s=e[0],i=e[1],o=e[2],a=e[3],c=n[0],h=n[1],u=n[2],f=n[3],l=void 0,d=void 0,m=void 0,p=void 0,y=void 0;return(d=s*c+i*h+o*u+a*f)<0&&(d=-d,c=-c,h=-h,u=-u,f=-f),1-d>1e-6?(l=Math.acos(d),m=Math.sin(l),p=Math.sin((1-r)*l)/m,y=Math.sin(r*l)/m):(p=1-r,y=r),t[0]=p*s+y*c,t[1]=p*i+y*h,t[2]=p*o+y*u,t[3]=p*a+y*f,t}k(),function(){var t,e=(t=new P(4),P!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var it,ot=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};k(),V(1,0,0),V(0,1,0),nt(),nt(),it=new P(9),P!=Float32Array&&(it[1]=0,it[2]=0,it[3]=0,it[5]=0,it[6]=0,it[7]=0),it[0]=1,it[4]=1,it[8]=1;
12
+ var a=[],c=0;c<6;c++)a[c]=[];var h=[];function u(t,e,n){f(t);for(var r=0;r<6;r++)if(!n||"0"!==n.charAt(r)){var s=a[r];if(h[0]=s[0]>0?e[1][0]:e[0][0],h[1]=s[1]>0?e[1][1]:e[0][1],h[2]=s[2]>0?e[1][2]:e[0][2],m(s,h)<0)return!1}return!0}function l(t,e){var n=e,r=t,s=e,i=r[0],o=r[1],a=r[2],c=Math.abs(i*s[3]+o*s[6]+a*s[9])+Math.abs(i*s[4]+o*s[7]+a*s[10])+Math.abs(i*s[5]+o*s[8]+a*s[11]),h=m(t,n);return!(h<=-c)}function f(t){var e=t,n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],c=e[5],h=e[6],u=e[7],l=e[8],f=e[9],m=e[10],b=e[11],p=e[12],g=e[13],y=e[14],w=e[15];d(a[0],i-n,u-o,b-l,w-p),d(a[1],i+n,u+o,b+l,w+p),d(a[2],i+r,u+c,b+f,w+g),d(a[3],i-r,u-c,b-f,w-g),d(a[4],i-s,u-h,b-m,w-y),d(a[5],i+s,u+h,b+m,w+y)}function d(t,e,n,r,s){var i=1/Math.sqrt(e*e+n*n+r*r);return t[0]=e*i,t[1]=n*i,t[2]=r*i,t[3]=s*i,t}function m(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]}var b={exports:{}},p={"aliceblue":[240,248,255],"antiquewhite":[250,235,215],"aqua":[0,255,255],"aquamarine":[127,255,212],"azure":[240,255,255],"beige":[245,245,220],"bisque":[255,228,196],"black":[0,0,0],"blanchedalmond":[255,235,205],"blue":[0,0,255],"blueviolet":[138,43,226],"brown":[165,42,42],"burlywood":[222,184,135],"cadetblue":[95,158,160],"chartreuse":[127,255,0],"chocolate":[210,105,30],"coral":[255,127,80],"cornflowerblue":[100,149,237],"cornsilk":[255,248,220],"crimson":[220,20,60],"cyan":[0,255,255],"darkblue":[0,0,139],"darkcyan":[0,139,139],"darkgoldenrod":[184,134,11],"darkgray":[169,169,169],"darkgreen":[0,100,0],"darkgrey":[169,169,169],"darkkhaki":[189,183,107],"darkmagenta":[139,0,139],"darkolivegreen":[85,107,47],"darkorange":[255,140,0],"darkorchid":[153,50,204],"darkred":[139,0,0],"darksalmon":[233,150,122],"darkseagreen":[143,188,143],"darkslateblue":[72,61,139],"darkslategray":[47,79,79],"darkslategrey":[47,79,79],"darkturquoise":[0,206,209],"darkviolet":[148,0,211],"deeppink":[255,20,147],"deepskyblue":[0,191,255],"dimgray":[105,105,105],"dimgrey":[105,105,105],"dodgerblue":[30,144,255],"firebrick":[178,34,34],"floralwhite":[255,250,240],"forestgreen":[34,139,34],"fuchsia":[255,0,255],"gainsboro":[220,220,220],"ghostwhite":[248,248,255],"gold":[255,215,0],"goldenrod":[218,165,32],"gray":[128,128,128],"green":[0,128,0],"greenyellow":[173,255,47],"grey":[128,128,128],"honeydew":[240,255,240],"hotpink":[255,105,180],"indianred":[205,92,92],"indigo":[75,0,130],"ivory":[255,255,240],"khaki":[240,230,140],"lavender":[230,230,250],"lavenderblush":[255,240,245],"lawngreen":[124,252,0],"lemonchiffon":[255,250,205],"lightblue":[173,216,230],"lightcoral":[240,128,128],"lightcyan":[224,255,255],"lightgoldenrodyellow":[250,250,210],"lightgray":[211,211,211],"lightgreen":[144,238,144],"lightgrey":[211,211,211],"lightpink":[255,182,193],"lightsalmon":[255,160,122],"lightseagreen":[32,178,170],"lightskyblue":[135,206,250],"lightslategray":[119,136,153],"lightslategrey":[119,136,153],"lightsteelblue":[176,196,222],"lightyellow":[255,255,224],"lime":[0,255,0],"limegreen":[50,205,50],"linen":[250,240,230],"magenta":[255,0,255],"maroon":[128,0,0],"mediumaquamarine":[102,205,170],"mediumblue":[0,0,205],"mediumorchid":[186,85,211],"mediumpurple":[147,112,219],"mediumseagreen":[60,179,113],"mediumslateblue":[123,104,238],"mediumspringgreen":[0,250,154],"mediumturquoise":[72,209,204],"mediumvioletred":[199,21,133],"midnightblue":[25,25,112],"mintcream":[245,255,250],"mistyrose":[255,228,225],"moccasin":[255,228,181],"navajowhite":[255,222,173],"navy":[0,0,128],"oldlace":[253,245,230],"olive":[128,128,0],"olivedrab":[107,142,35],"orange":[255,165,0],"orangered":[255,69,0],"orchid":[218,112,214],"palegoldenrod":[238,232,170],"palegreen":[152,251,152],"paleturquoise":[175,238,238],"palevioletred":[219,112,147],"papayawhip":[255,239,213],"peachpuff":[255,218,185],"peru":[205,133,63],"pink":[255,192,203],"plum":[221,160,221],"powderblue":[176,224,230],"purple":[128,0,128],"rebeccapurple":[102,51,153],"red":[255,0,0],"rosybrown":[188,143,143],"royalblue":[65,105,225],"saddlebrown":[139,69,19],"salmon":[250,128,114],"sandybrown":[244,164,96],"seagreen":[46,139,87],"seashell":[255,245,238],"sienna":[160,82,45],"silver":[192,192,192],"skyblue":[135,206,235],"slateblue":[106,90,205],"slategray":[112,128,144],"slategrey":[112,128,144],"snow":[255,250,250],"springgreen":[0,255,127],"steelblue":[70,130,180],"tan":[210,180,140],"teal":[0,128,128],"thistle":[216,191,216],"tomato":[255,99,71],"turquoise":[64,224,208],"violet":[238,130,238],"wheat":[245,222,179],"white":[255,255,255],"whitesmoke":[245,245,245],"yellow":[255,255,0],"yellowgreen":[154,205,50]},g={exports:{}},y=function(t){return!(!t||"string"==typeof t)&&(t instanceof Array||Array.isArray(t)||t.length>=0&&(t.splice instanceof Function||Object.getOwnPropertyDescriptor(t,t.length-1)&&"String"!==t.constructor.name))},w=Array.prototype.concat,v=Array.prototype.slice,T=g.exports=function(t){for(var e=[],n=0,r=t.length;n<r;n++){var s=t[n];y(s)?e=w.call(e,v.call(s)):e.push(s)}return e};T.wrap=function(t){return function(){return t(T(arguments))}};var _=p,M=g.exports,O=Object.hasOwnProperty,A=Object.create(null);for(var x in _)O.call(_,x)&&(A[_[x]]=x);var I=b.exports={to:{},get:{}};function S(t,e,n){return Math.min(Math.max(e,t),n)}function E(t){var e=Math.round(t).toString(16).toUpperCase();return e.length<2?"0"+e:e}I.get=function(t){var e,n;switch(t.substring(0,3).toLowerCase()){case"hsl":e=I.get.hsl(t),n="hsl";break;case"hwb":e=I.get.hwb(t),n="hwb";break;default:e=I.get.rgb(t),n="rgb"}return e?{model:n,value:e}:null},I.get.rgb=function(t){if(!t)return null;var e,n,r,s=[0,0,0,1];if(e=t.match(/^#([a-f0-9]{6})([a-f0-9]{2})?$/i)){for(r=e[2],e=e[1],n=0;n<3;n++){var i=2*n;s[n]=parseInt(e.slice(i,i+2),16)}r&&(s[3]=parseInt(r,16)/255)}else if(e=t.match(/^#([a-f0-9]{3,4})$/i)){for(r=(e=e[1])[3],n=0;n<3;n++)s[n]=parseInt(e[n]+e[n],16);r&&(s[3]=parseInt(r+r,16)/255)}else if(e=t.match(/^rgba?\(\s*([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)(?=[\s,])\s*(?:,\s*)?([+-]?\d+)\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/)){for(n=0;n<3;n++)s[n]=parseInt(e[n+1],0);e[4]&&(e[5]?s[3]=.01*parseFloat(e[4]):s[3]=parseFloat(e[4]))}else{if(!(e=t.match(/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*,?\s*([+-]?[\d\.]+)\%\s*(?:[,|\/]\s*([+-]?[\d\.]+)(%?)\s*)?\)$/)))return(e=t.match(/^(\w+)$/))?"transparent"===e[1]?[0,0,0,0]:O.call(_,e[1])?((s=_[e[1]])[3]=1,s):null:null;for(n=0;n<3;n++)s[n]=Math.round(2.55*parseFloat(e[n+1]));e[4]&&(e[5]?s[3]=.01*parseFloat(e[4]):s[3]=parseFloat(e[4]))}for(n=0;n<3;n++)s[n]=S(s[n],0,255);return s[3]=S(s[3],0,1),s},I.get.hsl=function(t){if(!t)return null;var e=t.match(/^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/);if(e){var n=parseFloat(e[4]);return[(parseFloat(e[1])%360+360)%360,S(parseFloat(e[2]),0,100),S(parseFloat(e[3]),0,100),S(isNaN(n)?1:n,0,1)]}return null},I.get.hwb=function(t){if(!t)return null;var e=t.match(/^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?(?=\.\d|\d)(?:0|[1-9]\d*)?(?:\.\d*)?(?:[eE][+-]?\d+)?)\s*)?\)$/);if(e){var n=parseFloat(e[4]);return[(parseFloat(e[1])%360+360)%360,S(parseFloat(e[2]),0,100),S(parseFloat(e[3]),0,100),S(isNaN(n)?1:n,0,1)]}return null},I.to.hex=function(){var t=M(arguments);return"#"+E(t[0])+E(t[1])+E(t[2])+(t[3]<1?E(Math.round(255*t[3])):"")},I.to.rgb=function(){var t=M(arguments);return t.length<4||1===t[3]?"rgb("+Math.round(t[0])+", "+Math.round(t[1])+", "+Math.round(t[2])+")":"rgba("+Math.round(t[0])+", "+Math.round(t[1])+", "+Math.round(t[2])+", "+t[3]+")"},I.to.rgb.percent=function(){var t=M(arguments),e=Math.round(t[0]/255*100),n=Math.round(t[1]/255*100),r=Math.round(t[2]/255*100);return t.length<4||1===t[3]?"rgb("+e+"%, "+n+"%, "+r+"%)":"rgba("+e+"%, "+n+"%, "+r+"%, "+t[3]+")"},I.to.hsl=function(){var t=M(arguments);return t.length<4||1===t[3]?"hsl("+t[0]+", "+t[1]+"%, "+t[2]+"%)":"hsla("+t[0]+", "+t[1]+"%, "+t[2]+"%, "+t[3]+")"},I.to.hwb=function(){var t=M(arguments),e="";return t.length>=4&&1!==t[3]&&(e=", "+t[3]),"hwb("+t[0]+", "+t[1]+"%, "+t[2]+"%"+e+")"},I.to.keyword=function(t){return A[t.slice(0,3)]};var N={exports:{}},C=p,R={};for(var P in C)C.hasOwnProperty(P)&&(R[C[P]]=P);var k=N.exports={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};for(var B in k)if(k.hasOwnProperty(B)){if(!("channels"in k[B]))throw new Error("missing channels property: "+B);if(!("labels"in k[B]))throw new Error("missing channel labels property: "+B);if(k[B].labels.length!==k[B].channels)throw new Error("channel and label counts mismatch: "+B);var L=k[B].channels,U=k[B].labels;delete k[B].channels,delete k[B].labels,Object.defineProperty(k[B],"channels",{value:L}),Object.defineProperty(k[B],"labels",{value:U})}function D(t,e){return Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2)+Math.pow(t[2]-e[2],2)}k.rgb.hsl=function(t){var e,n,r=t[0]/255,s=t[1]/255,i=t[2]/255,o=Math.min(r,s,i),a=Math.max(r,s,i),c=a-o;return a===o?e=0:r===a?e=(s-i)/c:s===a?e=2+(i-r)/c:i===a&&(e=4+(r-s)/c),(e=Math.min(60*e,360))<0&&(e+=360),n=(o+a)/2,[e,100*(a===o?0:n<=.5?c/(a+o):c/(2-a-o)),100*n]},k.rgb.hsv=function(t){var e,n,r,s,i,o=t[0]/255,a=t[1]/255,c=t[2]/255,h=Math.max(o,a,c),u=h-Math.min(o,a,c),l=function(t){return(h-t)/6/u+.5};return 0===u?s=i=0:(i=u/h,e=l(o),n=l(a),r=l(c),o===h?s=r-n:a===h?s=1/3+e-r:c===h&&(s=2/3+n-e),s<0?s+=1:s>1&&(s-=1)),[360*s,100*i,100*h]},k.rgb.hwb=function(t){var e=t[0],n=t[1],r=t[2];return[k.rgb.hsl(t)[0],100*(1/255*Math.min(e,Math.min(n,r))),100*(r=1-1/255*Math.max(e,Math.max(n,r)))]},k.rgb.cmyk=function(t){var e,n=t[0]/255,r=t[1]/255,s=t[2]/255;return[100*((1-n-(e=Math.min(1-n,1-r,1-s)))/(1-e)||0),100*((1-r-e)/(1-e)||0),100*((1-s-e)/(1-e)||0),100*e]},k.rgb.keyword=function(t){var e=R[t];if(e)return e;var n,r=1/0;for(var s in C)if(C.hasOwnProperty(s)){var i=D(t,C[s]);i<r&&(r=i,n=s)}return n},k.keyword.rgb=function(t){return C[t]},k.rgb.xyz=function(t){var e=t[0]/255,n=t[1]/255,r=t[2]/255;return[100*(.4124*(e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92)+.3576*(n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)+.1805*(r=r>.04045?Math.pow((r+.055)/1.055,2.4):r/12.92)),100*(.2126*e+.7152*n+.0722*r),100*(.0193*e+.1192*n+.9505*r)]},k.rgb.lab=function(t){var e=k.rgb.xyz(t),n=e[0],r=e[1],s=e[2];return r/=100,s/=108.883,n=(n/=95.047)>.008856?Math.pow(n,1/3):7.787*n+16/116,[116*(r=r>.008856?Math.pow(r,1/3):7.787*r+16/116)-16,500*(n-r),200*(r-(s=s>.008856?Math.pow(s,1/3):7.787*s+16/116))]},k.hsl.rgb=function(t){var e,n,r,s,i,o=t[0]/360,a=t[1]/100,c=t[2]/100;if(0===a)return[i=255*c,i,i];e=2*c-(n=c<.5?c*(1+a):c+a-c*a),s=[0,0,0];for(var h=0;h<3;h++)(r=o+1/3*-(h-1))<0&&r++,r>1&&r--,i=6*r<1?e+6*(n-e)*r:2*r<1?n:3*r<2?e+(n-e)*(2/3-r)*6:e,s[h]=255*i;return s},k.hsl.hsv=function(t){var e=t[0],n=t[1]/100,r=t[2]/100,s=n,i=Math.max(r,.01);return n*=(r*=2)<=1?r:2-r,s*=i<=1?i:2-i,[e,100*(0===r?2*s/(i+s):2*n/(r+n)),100*((r+n)/2)]},k.hsv.rgb=function(t){var e=t[0]/60,n=t[1]/100,r=t[2]/100,s=Math.floor(e)%6,i=e-Math.floor(e),o=255*r*(1-n),a=255*r*(1-n*i),c=255*r*(1-n*(1-i));switch(r*=255,s){case 0:return[r,c,o];case 1:return[a,r,o];case 2:return[o,r,c];case 3:return[o,a,r];case 4:return[c,o,r];case 5:return[r,o,a]}},k.hsv.hsl=function(t){var e,n,r,s=t[0],i=t[1]/100,o=t[2]/100,a=Math.max(o,.01);return r=(2-i)*o,n=i*a,[s,100*(n=(n/=(e=(2-i)*a)<=1?e:2-e)||0),100*(r/=2)]},k.hwb.rgb=function(t){var e,n,r,s,i,o,a,c=t[0]/360,h=t[1]/100,u=t[2]/100,l=h+u;switch(l>1&&(h/=l,u/=l),r=6*c-(e=Math.floor(6*c)),0!=(1&e)&&(r=1-r),s=h+r*((n=1-u)-h),e){default:case 6:case 0:i=n,o=s,a=h;break;case 1:i=s,o=n,a=h;break;case 2:i=h,o=n,a=s;break;case 3:i=h,o=s,a=n;break;case 4:i=s,o=h,a=n;break;case 5:i=n,o=h,a=s}return[255*i,255*o,255*a]},k.cmyk.rgb=function(t){var e=t[0]/100,n=t[1]/100,r=t[2]/100,s=t[3]/100;return[255*(1-Math.min(1,e*(1-s)+s)),255*(1-Math.min(1,n*(1-s)+s)),255*(1-Math.min(1,r*(1-s)+s))]},k.xyz.rgb=function(t){var e,n,r,s=t[0]/100,i=t[1]/100,o=t[2]/100;return n=-.9689*s+1.8758*i+.0415*o,r=.0557*s+-.204*i+1.057*o,e=(e=3.2406*s+-1.5372*i+-.4986*o)>.0031308?1.055*Math.pow(e,1/2.4)-.055:12.92*e,n=n>.0031308?1.055*Math.pow(n,1/2.4)-.055:12.92*n,r=r>.0031308?1.055*Math.pow(r,1/2.4)-.055:12.92*r,[255*(e=Math.min(Math.max(0,e),1)),255*(n=Math.min(Math.max(0,n),1)),255*(r=Math.min(Math.max(0,r),1))]},k.xyz.lab=function(t){var e=t[0],n=t[1],r=t[2];return n/=100,r/=108.883,e=(e/=95.047)>.008856?Math.pow(e,1/3):7.787*e+16/116,[116*(n=n>.008856?Math.pow(n,1/3):7.787*n+16/116)-16,500*(e-n),200*(n-(r=r>.008856?Math.pow(r,1/3):7.787*r+16/116))]},k.lab.xyz=function(t){var e,n,r,s=t[0];e=t[1]/500+(n=(s+16)/116),r=n-t[2]/200;var i=Math.pow(n,3),o=Math.pow(e,3),a=Math.pow(r,3);return n=i>.008856?i:(n-16/116)/7.787,e=o>.008856?o:(e-16/116)/7.787,r=a>.008856?a:(r-16/116)/7.787,[e*=95.047,n*=100,r*=108.883]},k.lab.lch=function(t){var e,n=t[0],r=t[1],s=t[2];return(e=360*Math.atan2(s,r)/2/Math.PI)<0&&(e+=360),[n,Math.sqrt(r*r+s*s),e]},k.lch.lab=function(t){var e,n=t[0],r=t[1];return e=t[2]/360*2*Math.PI,[n,r*Math.cos(e),r*Math.sin(e)]},k.rgb.ansi16=function(t){var e=t[0],n=t[1],r=t[2],s=1 in arguments?arguments[1]:k.rgb.hsv(t)[2];if(0===(s=Math.round(s/50)))return 30;var i=30+(Math.round(r/255)<<2|Math.round(n/255)<<1|Math.round(e/255));return 2===s&&(i+=60),i},k.hsv.ansi16=function(t){return k.rgb.ansi16(k.hsv.rgb(t),t[2])},k.rgb.ansi256=function(t){var e=t[0],n=t[1],r=t[2];return e===n&&n===r?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(n/255*5)+Math.round(r/255*5)},k.ansi16.rgb=function(t){var e=t%10;if(0===e||7===e)return t>50&&(e+=3.5),[e=e/10.5*255,e,e];var n=.5*(1+~~(t>50));return[(1&e)*n*255,(e>>1&1)*n*255,(e>>2&1)*n*255]},k.ansi256.rgb=function(t){if(t>=232){var e=10*(t-232)+8;return[e,e,e]}var n;return t-=16,[Math.floor(t/36)/5*255,Math.floor((n=t%36)/6)/5*255,n%6/5*255]},k.rgb.hex=function(t){var e=(((255&Math.round(t[0]))<<16)+((255&Math.round(t[1]))<<8)+(255&Math.round(t[2]))).toString(16).toUpperCase();return"000000".substring(e.length)+e},k.hex.rgb=function(t){var e=t.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!e)return[0,0,0];var n=e[0];3===e[0].length&&(n=n.split("").map((function(t){return t+t})).join(""));var r=parseInt(n,16);return[r>>16&255,r>>8&255,255&r]},k.rgb.hcg=function(t){var e,n=t[0]/255,r=t[1]/255,s=t[2]/255,i=Math.max(Math.max(n,r),s),o=Math.min(Math.min(n,r),s),a=i-o;return e=a<=0?0:i===n?(r-s)/a%6:i===r?2+(s-n)/a:4+(n-r)/a+4,e/=6,[360*(e%=1),100*a,100*(a<1?o/(1-a):0)]},k.hsl.hcg=function(t){var e=t[1]/100,n=t[2]/100,r=1,s=0;return(r=n<.5?2*e*n:2*e*(1-n))<1&&(s=(n-.5*r)/(1-r)),[t[0],100*r,100*s]},k.hsv.hcg=function(t){var e=t[1]/100,n=t[2]/100,r=e*n,s=0;return r<1&&(s=(n-r)/(1-r)),[t[0],100*r,100*s]},k.hcg.rgb=function(t){var e=t[0]/360,n=t[1]/100,r=t[2]/100;if(0===n)return[255*r,255*r,255*r];var s,i=[0,0,0],o=e%1*6,a=o%1,c=1-a;switch(Math.floor(o)){case 0:i[0]=1,i[1]=a,i[2]=0;break;case 1:i[0]=c,i[1]=1,i[2]=0;break;case 2:i[0]=0,i[1]=1,i[2]=a;break;case 3:i[0]=0,i[1]=c,i[2]=1;break;case 4:i[0]=a,i[1]=0,i[2]=1;break;default:i[0]=1,i[1]=0,i[2]=c}return s=(1-n)*r,[255*(n*i[0]+s),255*(n*i[1]+s),255*(n*i[2]+s)]},k.hcg.hsv=function(t){var e=t[1]/100,n=e+t[2]/100*(1-e),r=0;return n>0&&(r=e/n),[t[0],100*r,100*n]},k.hcg.hsl=function(t){var e=t[1]/100,n=t[2]/100*(1-e)+.5*e,r=0;return n>0&&n<.5?r=e/(2*n):n>=.5&&n<1&&(r=e/(2*(1-n))),[t[0],100*r,100*n]},k.hcg.hwb=function(t){var e=t[1]/100,n=e+t[2]/100*(1-e);return[t[0],100*(n-e),100*(1-n)]},k.hwb.hcg=function(t){var e=t[1]/100,n=1-t[2]/100,r=n-e,s=0;return r<1&&(s=(n-r)/(1-r)),[t[0],100*r,100*s]},k.apple.rgb=function(t){return[t[0]/65535*255,t[1]/65535*255,t[2]/65535*255]},k.rgb.apple=function(t){return[t[0]/255*65535,t[1]/255*65535,t[2]/255*65535]},k.gray.rgb=function(t){return[t[0]/100*255,t[0]/100*255,t[0]/100*255]},k.gray.hsl=k.gray.hsv=function(t){return[0,0,t[0]]},k.gray.hwb=function(t){return[0,100,t[0]]},k.gray.cmyk=function(t){return[0,0,0,t[0]]},k.gray.lab=function(t){return[t[0],0,0]},k.gray.hex=function(t){var e=255&Math.round(t[0]/100*255),n=((e<<16)+(e<<8)+e).toString(16).toUpperCase();return"000000".substring(n.length)+n},k.rgb.gray=function(t){return[(t[0]+t[1]+t[2])/3/255*100]};var z=N.exports;function F(t){var e=function(){for(var t={},e=Object.keys(z),n=e.length,r=0;r<n;r++)t[e[r]]={distance:-1,parent:null};return t}(),n=[t];for(e[t].distance=0;n.length;)for(var r=n.pop(),s=Object.keys(z[r]),i=s.length,o=0;o<i;o++){var a=s[o],c=e[a];-1===c.distance&&(c.distance=e[r].distance+1,c.parent=r,n.unshift(a))}return e}function j(t,e){return function(n){return e(t(n))}}function V(t,e){for(var n=[e[t].parent,t],r=z[e[t].parent][t],s=e[t].parent;e[s].parent;)n.unshift(e[s].parent),r=j(z[e[s].parent][s],r),s=e[s].parent;return r.conversion=n,r}var q=N.exports,H=function(t){for(var e=F(t),n={},r=Object.keys(e),s=r.length,i=0;i<s;i++){var o=r[i];null!==e[o].parent&&(n[o]=V(o,e))}return n},G={};Object.keys(q).forEach((function(t){G[t]={},Object.defineProperty(G[t],"channels",{value:q[t].channels}),Object.defineProperty(G[t],"labels",{value:q[t].labels});var e=H(t);Object.keys(e).forEach((function(n){var r=e[n];G[t][n]=function(t){var e=function(e){if(null==e)return e;arguments.length>1&&(e=Array.prototype.slice.call(arguments));var n=t(e);if("object"==typeof n)for(var r=n.length,s=0;s<r;s++)n[s]=Math.round(n[s]);return n};return"conversion"in t&&(e.conversion=t.conversion),e}(r),G[t][n].raw=function(t){var e=function(e){return null==e?e:(arguments.length>1&&(e=Array.prototype.slice.call(arguments)),t(e))};return"conversion"in t&&(e.conversion=t.conversion),e}(r)}))}));var $=G,X=b.exports,J=$,Z=[].slice,K=["keyword","gray","hex"],Y={};Object.keys(J).forEach((function(t){Y[Z.call(J[t].labels).sort().join("")]=t}));var Q={};function W(t,e){if(!(this instanceof W))return new W(t,e);if(e&&e in K&&(e=null),e&&!(e in J))throw new Error("Unknown model: "+e);var n,r;if(null==t)this.model="rgb",this.color=[0,0,0],this.valpha=1;else if(t instanceof W)this.model=t.model,this.color=t.color.slice(),this.valpha=t.valpha;else if("string"==typeof t){var s=X.get(t);if(null===s)throw new Error("Unable to parse color from string: "+t);this.model=s.model,r=J[this.model].channels,this.color=s.value.slice(0,r),this.valpha="number"==typeof s.value[r]?s.value[r]:1}else if(t.length){this.model=e||"rgb",r=J[this.model].channels;var i=Z.call(t,0,r);this.color=rt(i,r),this.valpha="number"==typeof t[r]?t[r]:1}else if("number"==typeof t)t&=16777215,this.model="rgb",this.color=[t>>16&255,t>>8&255,255&t],this.valpha=1;else{this.valpha=1;var o=Object.keys(t);"alpha"in t&&(o.splice(o.indexOf("alpha"),1),this.valpha="number"==typeof t.alpha?t.alpha:0);var a=o.sort().join("");if(!(a in Y))throw new Error("Unable to parse color from object: "+JSON.stringify(t));this.model=Y[a];var c=J[this.model].labels,h=[];for(n=0;n<c.length;n++)h.push(t[c[n]]);this.color=rt(h)}if(Q[this.model])for(r=J[this.model].channels,n=0;n<r;n++){var u=Q[this.model][n];u&&(this.color[n]=u(this.color[n]))}this.valpha=Math.max(0,Math.min(1,this.valpha)),Object.freeze&&Object.freeze(this)}function tt(t,e,n){return(t=Array.isArray(t)?t:[t]).forEach((function(t){(Q[t]||(Q[t]=[]))[e]=n})),t=t[0],function(r){var s;return arguments.length?(n&&(r=n(r)),(s=this[t]()).color[e]=r,s):(s=this[t]().color[e],n&&(s=n(s)),s)}}function et(t){return function(e){return Math.max(0,Math.min(t,e))}}function nt(t){return Array.isArray(t)?t:[t]}function rt(t,e){for(var n=0;n<e;n++)"number"!=typeof t[n]&&(t[n]=0);return t}W.prototype={toString:function(){return this.string()},toJSON:function(){return this[this.model]()},string:function(t){var e=this.model in X.to?this:this.rgb(),n=1===(e=e.round("number"==typeof t?t:1)).valpha?e.color:e.color.concat(this.valpha);return X.to[e.model](n)},percentString:function(t){var e=this.rgb().round("number"==typeof t?t:1),n=1===e.valpha?e.color:e.color.concat(this.valpha);return X.to.rgb.percent(n)},array:function(){return 1===this.valpha?this.color.slice():this.color.concat(this.valpha)},object:function(){for(var t={},e=J[this.model].channels,n=J[this.model].labels,r=0;r<e;r++)t[n[r]]=this.color[r];return 1!==this.valpha&&(t.alpha=this.valpha),t},unitArray:function(){var t=this.rgb().color;return t[0]/=255,t[1]/=255,t[2]/=255,1!==this.valpha&&t.push(this.valpha),t},unitObject:function(){var t=this.rgb().object();return t.r/=255,t.g/=255,t.b/=255,1!==this.valpha&&(t.alpha=this.valpha),t},round:function(t){return t=Math.max(t||0,0),new W(this.color.map(function(t){return function(e){return function(t,e){return Number(t.toFixed(e))}(e,t)}}(t)).concat(this.valpha),this.model)},alpha:function(t){return arguments.length?new W(this.color.concat(Math.max(0,Math.min(1,t))),this.model):this.valpha},red:tt("rgb",0,et(255)),green:tt("rgb",1,et(255)),blue:tt("rgb",2,et(255)),hue:tt(["hsl","hsv","hsl","hwb","hcg"],0,(function(t){return(t%360+360)%360})),saturationl:tt("hsl",1,et(100)),lightness:tt("hsl",2,et(100)),saturationv:tt("hsv",1,et(100)),value:tt("hsv",2,et(100)),chroma:tt("hcg",1,et(100)),gray:tt("hcg",2,et(100)),white:tt("hwb",1,et(100)),wblack:tt("hwb",2,et(100)),cyan:tt("cmyk",0,et(100)),magenta:tt("cmyk",1,et(100)),yellow:tt("cmyk",2,et(100)),black:tt("cmyk",3,et(100)),x:tt("xyz",0,et(100)),y:tt("xyz",1,et(100)),z:tt("xyz",2,et(100)),l:tt("lab",0,et(100)),a:tt("lab",1),b:tt("lab",2),keyword:function(t){return arguments.length?new W(t):J[this.model].keyword(this.color)},hex:function(t){return arguments.length?new W(t):X.to.hex(this.rgb().round().color)},rgbNumber:function(){var t=this.rgb().color;return(255&t[0])<<16|(255&t[1])<<8|255&t[2]},luminosity:function(){for(var t=this.rgb().color,e=[],n=0;n<t.length;n++){var r=t[n]/255;e[n]=r<=.03928?r/12.92:Math.pow((r+.055)/1.055,2.4)}return.2126*e[0]+.7152*e[1]+.0722*e[2]},contrast:function(t){var e=this.luminosity(),n=t.luminosity();return e>n?(e+.05)/(n+.05):(n+.05)/(e+.05)},level:function(t){var e=this.contrast(t);return e>=7.1?"AAA":e>=4.5?"AA":""},isDark:function(){var t=this.rgb().color;return(299*t[0]+587*t[1]+114*t[2])/1e3<128},isLight:function(){return!this.isDark()},negate:function(){for(var t=this.rgb(),e=0;e<3;e++)t.color[e]=255-t.color[e];return t},lighten:function(t){var e=this.hsl();return e.color[2]+=e.color[2]*t,e},darken:function(t){var e=this.hsl();return e.color[2]-=e.color[2]*t,e},saturate:function(t){var e=this.hsl();return e.color[1]+=e.color[1]*t,e},desaturate:function(t){var e=this.hsl();return e.color[1]-=e.color[1]*t,e},whiten:function(t){var e=this.hwb();return e.color[1]+=e.color[1]*t,e},blacken:function(t){var e=this.hwb();return e.color[2]+=e.color[2]*t,e},grayscale:function(){var t=this.rgb().color,e=.3*t[0]+.59*t[1]+.11*t[2];return W.rgb(e,e,e)},fade:function(t){return this.alpha(this.valpha-this.valpha*t)},opaquer:function(t){return this.alpha(this.valpha+this.valpha*t)},rotate:function(t){var e=this.hsl(),n=e.color[0];return n=(n=(n+t)%360)<0?360+n:n,e.color[0]=n,e},mix:function(t,e){if(!t||!t.rgb)throw new Error('Argument to "mix" was not a Color instance, but rather an instance of '+typeof t);var n=t.rgb(),r=this.rgb(),s=void 0===e?.5:e,i=2*s-1,o=n.alpha()-r.alpha(),a=((i*o==-1?i:(i+o)/(1+i*o))+1)/2,c=1-a;return W.rgb(a*n.red()+c*r.red(),a*n.green()+c*r.green(),a*n.blue()+c*r.blue(),n.alpha()*s+r.alpha()*(1-s))}},Object.keys(J).forEach((function(t){if(-1===K.indexOf(t)){var e=J[t].channels;W.prototype[t]=function(){if(this.model===t)return new W(this);if(arguments.length)return new W(arguments,t);var n="number"==typeof arguments[e]?e:this.valpha;return new W(nt(J[this.model][t].raw(this.color)).concat(n),t)},W[t]=function(n){return"number"==typeof n&&(n=rt(Z.call(arguments),e)),new W(n,t)}}}));var st=W;function it(t){return null==t}function ot(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 at(t){return null!=t&&("function"==typeof t||null!==t.constructor&&t.constructor===Function)}function ct(t){return"object"==typeof t&&!!t}function ht(t){return"number"==typeof t&&!isNaN(t)}function ut(t){return t*Math.PI/180}function lt(t){return t/Math.PI*180}function ft(t){let e=document.createElement("a");return e.href=t,t=e.href,e=null,t}function dt(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const mt=[1,1,1,1,2,2,3,0];function bt(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=mt[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}function pt(t,e,n){return t[3*n]=e[0],t[3*n+1]=e[1],t[3*n+2]=e[2],t}function gt(t){return t.flat?t.flat(1/0):t.reduce((t,e)=>t.concat(e),[])}function yt(t){return t<256?Uint8Array:t<65536?Uint16Array:Uint32Array}function wt(t){return 0===t.indexOf("data:")}function vt(t){const e=t.indexOf("base64,"),n=t.substring(e+7),r=window.atob(n),s=r.length,i=new Uint8Array(s);for(let t=0;t<s;t++)i[t]=r.charCodeAt(t);return i.buffer}function Tt(t){for(let e=1;e<arguments.length;e++){const n=arguments[e];if(n)for(let e=0,r=n.length;e<r;e++)t.push(n[e])}return t.length}const _t={};function Mt(t,e){if(!Array.isArray(e)){const t=e;e=_t[t]=_t[t]||st(e).array().map(t=>t/255)}for(let n=0;n<e.length;n++)t[n]=e[n];return 3===e.length&&(t[3]=1),t}var Ot=Object.freeze({__proto__:null,isNil:it,extend:ot,isFunction:at,isObject:ct,isNumber:ht,toRadian:ut,toDegree:lt,getAbsoluteURL:ft,sign:dt,stringFromUTF8Array:bt,setColumn3:pt,flatArr:gt,getBatchIdArrayType:yt,isBase64:wt,base64URLToArrayBuffer:vt,pushIn:Tt,normalizeColor:Mt});function At(t){return-1===t.indexOf("http://")&&-1===t.indexOf("https://")&&-1===t.indexOf("file://")}var xt="undefined"!=typeof Float32Array?Float32Array:Array;function It(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}function St(t,e,n){var r=e[0],s=e[1],i=e[2],o=e[3],a=e[4],c=e[5],h=e[6],u=e[7],l=e[8],f=e[9],d=e[10],m=e[11],b=e[12],p=e[13],g=e[14],y=e[15],w=n[0],v=n[1],T=n[2],_=n[3];return t[0]=w*r+v*a+T*l+_*b,t[1]=w*s+v*c+T*f+_*p,t[2]=w*i+v*h+T*d+_*g,t[3]=w*o+v*u+T*m+_*y,w=n[4],v=n[5],T=n[6],_=n[7],t[4]=w*r+v*a+T*l+_*b,t[5]=w*s+v*c+T*f+_*p,t[6]=w*i+v*h+T*d+_*g,t[7]=w*o+v*u+T*m+_*y,w=n[8],v=n[9],T=n[10],_=n[11],t[8]=w*r+v*a+T*l+_*b,t[9]=w*s+v*c+T*f+_*p,t[10]=w*i+v*h+T*d+_*g,t[11]=w*o+v*u+T*m+_*y,w=n[12],v=n[13],T=n[14],_=n[15],t[12]=w*r+v*a+T*l+_*b,t[13]=w*s+v*c+T*f+_*p,t[14]=w*i+v*h+T*d+_*g,t[15]=w*o+v*u+T*m+_*y,t}function Et(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}function Nt(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}function Ct(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,h=n*o,u=r*o,l=r*a,f=s*o,d=s*a,m=s*c,b=i*o,p=i*a,g=i*c;return t[0]=1-l-m,t[1]=u+g,t[2]=f-p,t[3]=0,t[4]=u-g,t[5]=1-h-m,t[6]=d+b,t[7]=0,t[8]=f+p,t[9]=d-b,t[10]=1-h-l,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function Rt(){var t=new xt(3);return xt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function Pt(t){var e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function kt(t,e,n){var r=new xt(3);return r[0]=t,r[1]=e,r[2]=n,r}function Bt(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function Lt(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t}function Ut(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function Dt(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t}function zt(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function Ft(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function jt(t,e){var n=e[0],r=e[1],s=e[2],i=n*n+r*r+s*s;return i>0&&(i=1/Math.sqrt(i),t[0]=e[0]*i,t[1]=e[1]*i,t[2]=e[2]*i),t}function Vt(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function qt(t,e,n){var r=e[0],s=e[1],i=e[2],o=n[0],a=n[1],c=n[2];return t[0]=s*c-i*a,t[1]=i*o-r*c,t[2]=r*a-s*o,t}var Ht=Dt,Gt=zt,$t=Pt;function Xt(t,e,n,r,s){return t[0]=e,t[1]=n,t[2]=r,t[3]=s,t}function Jt(t,e,n){var r=e[0],s=e[1],i=e[2],o=e[3];return t[0]=n[0]*r+n[4]*s+n[8]*i+n[12]*o,t[1]=n[1]*r+n[5]*s+n[9]*i+n[13]*o,t[2]=n[2]*r+n[6]*s+n[10]*i+n[14]*o,t[3]=n[3]*r+n[7]*s+n[11]*i+n[15]*o,t}function Zt(){var t=new xt(4);return xt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function Kt(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}function Yt(t,e,n,r){var s=e[0],i=e[1],o=e[2],a=e[3],c=n[0],h=n[1],u=n[2],l=n[3],f=void 0,d=void 0,m=void 0,b=void 0,p=void 0;return(d=s*c+i*h+o*u+a*l)<0&&(d=-d,c=-c,h=-h,u=-u,l=-l),1-d>1e-6?(f=Math.acos(d),m=Math.sin(f),b=Math.sin((1-r)*f)/m,p=Math.sin(r*f)/m):(b=1-r,p=r),t[0]=b*s+p*c,t[1]=b*i+p*h,t[2]=b*o+p*u,t[3]=b*a+p*l,t}Rt(),function(){var t,e=(t=new xt(4),xt!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var Qt,Wt=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};Rt(),kt(1,0,0),kt(0,1,0),Zt(),Zt(),Qt=new xt(9),xt!=Float32Array&&(Qt[1]=0,Qt[2]=0,Qt[3]=0,Qt[5]=0,Qt[6]=0,Qt[7]=0),Qt[0]=1,Qt[4]=1,Qt[8]=1;
13
13
  /*!
14
- * @maptalks/gltf-loader v0.89.1
14
+ * @maptalks/gltf-loader v0.91.0
15
15
  * LICENSE : UNLICENSED
16
16
  * (c) 2016-2023 maptalks.org
17
17
  */
18
- let at=0;function ct(t){return null==t}function ht(t){return!ct(t)}function ut(t){return!ct(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}function ft(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 lt(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 dt(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function mt(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r.buffer}const pt=[],yt=[],bt=[],gt=[0,0,0],Tt=rt([]),wt=[1,1,1];function _t(t,e,n,r,s,i,o){const a=lt(o);if((0===s||s===r*a.BYTES_PER_ELEMENT)&&i%a.BYTES_PER_ELEMENT==0){const s=new a(e,i,n*r);return t.set(s),t}0===s&&(s=r*a.BYTES_PER_ELEMENT);const c=new Uint8Array(r*a.BYTES_PER_ELEMENT);for(let o=0;o<n;o++){let n=null;const h=new Uint8Array(e,s*o+i,r*a.BYTES_PER_ELEMENT);c.set(h),n=new a(c.buffer,0,r);for(let e=0;e<r;e++)t[o*r+e]=n[e]}return t}const At="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Ot(t,e,n){const r=new Uint8Array(t,e,n);return At.decode(r)}const xt={get:function(t,e={}){e||(e={});const n=new AbortController,r=n.signal,s=ft({},e);s.signal=r,s.method||(s.method="GET");const i=fetch(t,s).then(t=>{const n=this.s(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 i.xhr=n,i},s:(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={})=>(e||(e={}),e.responseType="arraybuffer",xt.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?xt.jsonp(t):((e=e||{}).responseType="json",xt.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+at++;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(r){document.getElementsByTagName("head")[0].removeChild(n),n=null,delete window[e],t(r)},document.getElementsByTagName("head")[0].appendChild(n)})}};class It{constructor(t,e,n){this.i=t,this.decoders=e,this.o=n,this.images={},this.h={}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)}if(this.h[t.id])return this.h[t.id].then(()=>{const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)});if(dt(t.uri)){const r=this.buffers[t.id]=mt(t.uri),s=this.u(e,r);return this.getImageByBuffer(s,n)}return this.h[t.id]=xt.getArrayBuffer(t.uri,null).then(r=>{const s=this.buffers[t.id]=r.data,i=this.u(e,s);return this.getImageByBuffer(i,n)})}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;return n[e.mimeType]?n[e.mimeType](t,{supportedFormats:this.o}):"image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType?(console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.l(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.l(t.id,e)}l(t,e){return new Promise((n,r)=>{this.i(e,(s,i)=>{s?r(s):(URL.revokeObjectURL(e),this.images[t]=i,n(this.images[t]))})})}}const St=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],Mt=[];class Nt{constructor(t,e,n){this.rootPath=t,this.gltf=e,this.m=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.p()}g(t,e){const n=this.gltf,r=n.accessors[e];if(void 0===r.bufferView)return this.accessors[r.id]=this.T(t,e,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const s=n.bufferViews[r.bufferView];return this._(s).then(n=>{const{buffer:s,byteOffset:i}=n;return this.accessors[r.id]=this.T(t,e,s,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(dt(e.uri)){const t=this.buffers[e.id]=mt(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]=xt.getArrayBuffer(t,null).then(r=>(n&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=r.data,byteOffset:0}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}T(t,e,n,r=0){const s=this.gltf,i=s.accessors[e],o=void 0!==i.bufferView?s.bufferViews[i.bufferView]:{},a=(o.byteOffset||0)+r,c=this.A(i.type),h=lt(i.componentType),u=o.byteStride||0,f={array:void 0,name:t,accessorName:e,byteLength:i.count*c*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:c,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(f.min=i.min),i.max&&(f.max=i.max),n)if(this.m)f.byteStride=u,f.byteOffset=a+(i.byteOffset||0),!u||u===c*h.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(f.array=this.O(n,i.count,c,a+(i.byteOffset||0),h),f.array.buffer.byteLength===f.byteLength&&(f.byteOffset=0)):f.array=new Uint8Array(n,a,o.byteLength);else if(i.interleaved){f.byteStride=0,f.byteOffset=0;const t=new h(i.count*c);if(f.array=_t(t,n,i.count,c,u,a+(i.byteOffset||0),i.componentType),f.extensions&&f.extensions.WEB3D_quantized_attributes&&c>2){const t=new Float32Array(f.array.length),{decodeMatrix:e}=f.extensions.WEB3D_quantized_attributes;for(let n=0;n<f.array.length;n+=c){Mt[0]=f.array[n],Mt[1]=f.array[n+1],Mt[2]=f.array[n+2],Mt[3]=1;const r=et(Mt,Mt,e);t[n]=r[0],t[n+1]=r[1],t[n+2]=r[2]}f.componentType=5126,f.array=t}}else f.byteStride=0,f.array=this.O(n,i.count,c,a+(i.byteOffset||0),h),f.byteOffset=f.array.byteOffset;else{f.array=new h(i.count);const t=f.min||f.max;t&&(f.array[0]=t[0],f.array[1]=t[1],f.array[2]=t[2])}return f}p(){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)}O(t,e,n,r,s){return r%s.BYTES_PER_ELEMENT!=0&&(t=t.slice(r,r+e*n*s.BYTES_PER_ELEMENT),r=0),new s(t,r,n*e)}A(t){const e=St.indexOf(t);return St[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._(e).then(r=>{const{buffer:s,byteOffset:i}=r,o=Ot(s,i+(e.byteOffset||0),n);return t.content=o,t})}if(t.uri){if(dt(t.uri)){const e=mt(t.uri),n=Ot(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return xt.get(e).then(e=>(t.content=e,t))}}return Promise.resolve(t)});return Promise.all(n).then(()=>t)}}class vt extends It{constructor(t,e,n,r,s,i){super(r,s,i),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new Nt(t,e,n)}iterate(t,e){const n=this.gltf[e];if(!n)return;let r=0;for(const e in n)t(e,n[e],r++)}createNode(t){const e={};if(ht(t.name)&&(e.name=t.name),ht(t.children)&&(e.children=t.children),ht(t.jointName)&&(e.jointName=t.jointName),ht(t.matrix)&&(e.matrix=t.matrix),ht(t.rotation)&&(e.rotation=t.rotation),ht(t.scale)&&(e.scale=t.scale),ht(t.translation)&&(e.translation=t.translation),ht(t.extras)&&(e.extras=t.extras),ht(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=L(pt,e.translation||gt),r=F(yt,e.rotation||Tt),s=D(bt,e.scale||wt);return B(s,r,s),B(t,n,s)}return U(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}I(t){const e={};for(const n in t){const r=t[n];let s,i;r.instanceTechnique&&r.instanceTechnique.values?(s=r.instanceTechnique,i=s.values.diffuse):(s=r,i=s.values.tex||s.values.diffuseTex||s.values.diffuse);const o={baseColorTexture:{index:i}};r.name&&(o.name=r.name),r.extensions&&(o.extensions=r.extensions),r.extras&&(o.extras=r.extras),e[n]=o}return e}S(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],r=(n.byteOffset||0)+this.glbBuffer.byteOffset,s=n.byteLength,i=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,s);return this.getImageByBuffer(i,t)}return this.requestExternalImage(t)}M(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.S(n).then(t=>{const r=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:r}})}getBaseColorTexture(t){const e=this.gltf.materials[t];let n,r;if(e.instanceTechnique&&e.instanceTechnique.values?(n=e.instanceTechnique,r=n.values.diffuse):(n=e,r=n.values.tex||n.values.diffuseTex||n.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const s=this.gltf.textures[r];if(!s)return null;const i=this.gltf.samplers[s.sampler];return{format:s.format||6408,internalFormat:s.internalFormat||6408,type:s.type||5121,sampler:i,source:this.gltf.images[s.source]}}getMaterial(){return null}getAnimations(){return null}}class Et extends It{constructor(t,e,n,r,s,i){super(r,s,i),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new Nt(t,e,n)}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 ft(e,t),!ht(t.weights)&&this.gltf.meshes&&ht(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}M(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),!ht(n))return null;const r=this.gltf.images[n];return this.S(r).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:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};ft(n,e);const s=ht(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return s&&(n.sampler=s,n.sampler.magFilter=s.magFilter||9729,n.sampler.minFilter=s.minFilter||9729,n.sampler.wrapS=s.wrapS||10497,n.sampler.wrapT=s.wrapT||10497),t.format&&(n.format=t.format),n})}S(t){if(!ht(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.N(e,t)}return null}N(t,e){const n=this.u(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}u(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}v(t,e){const n=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)n[e]=String.fromCharCode(t[e]);return n.join(""),"data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)))}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++)(ht(t[n].input)||ht(t[n].output))&&(e.push(this.accessor.g("input",t[n].input)),e.push(this.accessor.g("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 Ct="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class Rt{static read(t,e=0,n=0){n||(n=t.byteLength);const r=new DataView(t,e,n),s=r.getUint32(4,!0);if(1===s)return Rt.readV1(r,e);if(2===s)return Rt.readV2(t,e);throw new Error("Unsupported glb version : "+s)}static readV1(t,e){const n=t.getUint32(8,!0),r=t.getUint32(12,!0);if(n!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const s=Pt(t.buffer,20+e,r);return{json:JSON.parse(s),glbBuffer:{byteOffset:20+e+r,buffer:t.buffer,byteLength:n}}}static readV2(t,e){let n,r,s;const i=new DataView(t,e+12);let o=0;for(;o<i.byteLength;){const a=i.getUint32(o,!0);o+=4;const c=i.getUint32(o,!0);if(o+=4,1313821514===c)n=Pt(t,e+12+o,a);else if(5130562===c){s=e+12+o,r=a;break}o+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function Pt(t,e,n){if(Ct){const r=new Uint8Array(t,e,n);return Ct.decode(r)}return function(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=Ut[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}(new Uint8Array(t,e,n))}const Ut=[1,1,1,1,2,2,3,0],Bt=[0,0,0],Lt=[0,0,0,1],Dt=[1,1,1],Ft={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},kt={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Ht={C(t,e,n,r,s,i,o,a){const c=ht(t)?e.animations:[e.animations[0]],h={};for(let e=0;e<c.length;e++){const u=c[e],f=u.name||e;if(ht(t)&&f!==t)continue;const l=u.channelsMap[n];if(l)for(let t=0;t<l.length;t++){const e=l[t];"translation"===e.target.path?(this.R(s,u.samplers[e.sampler],r,1),h.translation=j(Bt,s)):"rotation"===e.target.path?(this.P(i,u.samplers[e.sampler],r,1),h.rotation=ot(Lt,i)):"scale"===e.target.path?(this.R(o,u.samplers[e.sampler],r,1),h.scale=j(Dt,o)):"weights"===e.target.path&&a&&(this.R(a,u.samplers[e.sampler],r,a.length),h.weights=a)}}return h},R(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.U(kt,e,n,1*r);s&&(t=function(t,e,n,r){for(let s=0;s<t.length;s++)t[s]=e[s]+r*(n[s]-e[s]);return t}(t,s.PREVIOUS,s.NEXT,s.INTERPOLATION));break}case"STEP":{const s=this.U(kt,e,n,1*r);s&&(t=function(t,e){for(let n=0;n<t.length;n++)t[n]=e[n];return t}(t,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.U(kt,e,n,3*r);s&&(t=this.B(t,s,e.input.array,3*r));break}}return t},P(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.U(kt,e,n,1);r&&st(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.U(kt,e,n,1);r&&(t=tt(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.U(kt,e,n,3);if(r){for(let t=0;t<r.PREVIOUS.length;t++)r.PREVIOUS[t]=Math.acos(r.PREVIOUS[t]),r.NEXT[t]=Math.acos(r.NEXT[t]);t=this.B(t,r,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},L(t,e){const n=t.length;let r,s,i,o=0,a=n-1,c=Math.floor((o+a)/2);for(;o<=n-1&&a>=0;){if(o===a)return null;if(t[c]<=e&&e<=t[c+1]){const n=t[c];return r=c,s=c+1,i=(e-n)/(t[c+1]-n),{preIndx:r,nextIndex:s,interpolation:i}}e<t[c]?(a=c,c=Math.floor((o+a)/2)):t[c+1]<e&&(o=c,c=Math.floor((o+a)/2))}return null},U(t,e,n,r){const s=e.input.array,i=e.output.array,o=e.output.itemSize;(n<s[0]||n>s[s.length-1])&&(n=Math.max(s[0],Math.min(s[s.length-1],n))),n===s[s.length-1]&&(n=s[0]);const a=this.L(s,n);if(!a||!a.nextIndex)return null;const{preIndx:c,nextIndex:h,interpolation:u}=a;t.PREINDEX=c,t.NEXTINDEX=h,t.INTERPOLATION=u;const f=o*r;return t.PREVIOUS=i.subarray(t.PREINDEX*f,(t.PREINDEX+1)*f),t.NEXT=i.subarray(t.NEXTINDEX*f,(t.NEXTINDEX+1)*f),t},B(t,e,n,r){const s=e.INTERPOLATION,i=n[e.PREINDEX],o=n[e.NEXTINDEX];for(let n=0;n<3;n++){const a=e.PREVIOUS[r+n],c=(o-i)*e.PREVIOUS[2*r+n],h=e.NEXT[3+n],u=(o-i)*e.NEXT[n],f=(2*Math.pow(s,3)-3*Math.pow(s,2)+1)*a+(Math.pow(s,3)-2*Math.pow(s,2)+s)*c+(2*-Math.pow(s,3)+3*Math.pow(s,2))*h+(Math.pow(s,3)-Math.pow(s,2))*u;t[n]=f}return t},getAnimationClip(t,e,n,r){const s=t.nodes[e]&&t.nodes[e].weights;return G(Bt,...Ft.TRANSLATION),tt(Lt,...Ft.ROTATION),G(Dt,...Ft.SCALE),this.C(r,t,e,n,Bt,Lt,Dt,s)},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 r=-1/0,s=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]>r&&(r=o[o.length-1]),o[0]<s&&(s=o[0])}const o=e.name||n;t.timeSpan[o]={max:r,min:s}}),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?ht(e)?n[e]:n[Object.keys(n)[0]]:null}};let Vt=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(qn){}t&&"undefined"!=typeof createImageBitmap&&(Vt=!0)}const jt="undefined"==typeof document?null:document.createElement("canvas");class Gt{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=Rt.read(e.buffer,e.byteOffset,e.byteLength);this.D(t,n,r)}else this.D(t,e);this.F=new Nt(this.rootPath,this.gltf,this.glbBuffer),this.k()}k(){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.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}H(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.F.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then(e=>(t.KHR_techniques_webgl=e,t)):Promise.resolve(t)}load(t){t=t||{};const e=this.V(t),n=this.j(),r=this.G(),s=this.H();return Promise.all([e,n,r,s]).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,r){return Ht.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return Ht.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return lt(t)}static readInterleavedArray(t,e,n,r,s,i,o){return _t(t,e,n,r,s,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=Vt?$t.bind(this):this.options.requestImage||zt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new Et(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),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 vt(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"))}q(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||ut(t.children[0])))return t;const r=t.children.map(t=>{const n=e[t];return n.nodeIndex=t,this.q(n,e)});t.children=r}var n;return t}V(t){return this.X(t).then(t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.q(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate((r,s,i)=>{const o={};s.name&&(o.name=s.name),s.nodes&&(o.nodes=s.nodes.map(e=>t[e])),this.gltf.scene===r&&(n=i),e.push(o)},"scenes");const r={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&&(r.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.I(this.gltf.materials);r.materials=t}return r})}X(t){return this.$(t).then(()=>{const t=this.nodes={};return this.adapter.iterate((e,n)=>{const r=this.adapter.createNode(n,this.meshes,this.skins);t[e]=r},"nodes"),t})}W(){this.skins=[];const t=[];return this.adapter.iterate((e,n,r)=>{t.push(this.K(n).then(t=>{t.index=r,this.skins.push(t)}))},"skins"),t}K(t){const e=t.inverseBindMatrices;return this.adapter.accessor.g("inverseBindMatrices",e).then(e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t))}j(){const t=this.gltf.animations;return ht(t)?this.adapter.getAnimations(t):null}$(t){this.meshes={};let e=[];return this.adapter.iterate((n,r,s)=>{e.push(this.Z(r,t).then(t=>{t.index=s,this.meshes[n]=t}))},"meshes"),e=e.concat(this.W()),Promise.all(e)}Z(t,e){const n=t.primitives.map(t=>this.J(t,e)).filter(t=>!!t);return Promise.all(n).then(e=>{const n={};return ft(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.M(n));return Promise.all(e).then(e=>{if(this.transferables)for(let t=0;t<e.length;t++){const n=e[t].image.array;if(e[t]&&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={},r=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(n[r[t]]=e[t]);return n}return e})}J(t,e){let n;const r=[],s=t.extensions;if(ht(t.targets))for(let e=0;e<t.targets.length;e++){const n=t.targets[e];for(const t in n){const s=this.adapter.accessor.g(`morphTargets_${t}_${e}`,n[t]);s&&r.push(s)}}if(s&&s.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}=s.KHR_draco_mesh_compression,a=this.gltf.bufferViews[i],c=this.F._(a).then(n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:i}=a;const c=a.byteLength;i||(i=0);const h=new DataView(r,s+i,c),u={attributes:o,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(h,u).then(t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e})});r.push(c),n=Promise.all(r)}else{const e=t.attributes;for(const t in e){const n=this.adapter.accessor.g(t,e[t]);n&&r.push(n)}if(ht(t.indices)){const e=this.adapter.accessor.g("indices",t.indices);e&&r.push(e)}n=Promise.all(r)}return n.then(e=>{if(s&&s.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,r;const i={attributes:e.reduce((t,e)=>{if("indices"===e.name)n=e;else if(e.name.indexOf("morphTargets_")>-1)r=r||{},r[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:r,array:s}=e,i=s.length/r;for(let e=0;e<i;e++)for(let i=0;i<r;i++){const o=e*r+i;s[o]<t[i]&&(t[i]=s[o]),s[o]>n[i]&&(n[i]=s[o])}if(e.quantization){const r=e.quantization,s=r.range/(1<<r.quantizationBits),i=r.minValues;$(t,t,s),z(t,t,i),$(n,n,s),z(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),r&&(i.morphTargets=r),i.mode=ht(t.mode)?t.mode:4,ht(t.extras)&&(i.extras=t.extras),i})}}function zt(t,e){const n=new Image;n.crossOrigin="",n.onload=()=>{if(!jt)return void e(new Error("There is no canvas to draw image!"));jt.width=n.width,jt.height=n.height;const t=jt.getContext("2d",{willReadFrequently:!0});t.drawImage(n,0,0,n.width,n.height);const r=t.getImageData(0,0,n.width,n.height),s={width:n.width,height:n.height,data:new Uint8Array(r.data)};e(null,s)},n.onerror=function(t){e(t)},n.src=t}let qt,Xt;function $t(t,e){qt||(qt=new OffscreenCanvas(2,2),Xt=qt.getContext("2d",{willReadFrequently:!0}));let n=null;if(ut(t))n=fetch(t).then(t=>t.arrayBuffer()).then(t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)});else{const e=new Blob([t]);n=createImageBitmap(e)}n.then(Wt.bind(this)).then(t=>{e(null,t)}).catch(t=>{console.warn(t),e(t)})}function Wt(t){let{width:e,height:n}=t;Kt(e)||(e=Qt(e)),Kt(n)||(n=Qt(n));const r=this.options.maxTextureSize;r&&(e=Math.min(r,e),n=Math.min(r,n)),qt.width=e,qt.height=n,Xt.drawImage(t,0,0,e,n),t.close();const s=Xt.getImageData(0,0,e,n);return{width:e,height:n,data:new Uint8Array(s.data)}}function Kt(t){return 0==(t&t-1)&&0!==t}function Qt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}const Zt="undefined"==typeof document?null:document.createElement("canvas");class Jt extends s.worker.Actor{constructor(t,e){super(t),this.mapId=e}initialize(t){t(null)}loadTile(t,e,n){let r=null;e&&e.arraybuffer&&(r=[e.arraybuffer]);const s={mapId:this.mapId,layerId:t,command:"loadTile",params:e};this.send(s,r,n)}abortTileLoading(t,e,n){const r={mapId:this.mapId,layerId:t,command:"abortTileLoading",params:{url:e}};this.broadcast(r,null,n)}addLayer(t,e,n){const r={actorId:this.actorId,mapId:this.mapId,layerId:t,command:"addLayer",params:{options:e}};this.broadcast(r,null,n)}removeLayer(t,e){const n={mapId:this.mapId,layerId:t,command:"removeLayer"};this.broadcast(n,null,e)}requestImage({url:t},e){const n=new Image;n.onload=()=>{if(!this.isActive())return;if(!Zt)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if(Yt(t.width)&&Yt(t.height))return t;let e=t.width,n=t.height;Yt(e)||(e=te(e));Yt(n)||(n=te(n));const r=document.createElement("canvas");r.width=e,r.height=n,r.getContext("2d").drawImage(t,0,0,e,n);const s=t.src,i=s.lastIndexOf("/")+1,o=s.substring(i);return console.warn(`Texture(${o})'s size is not power of two, resize from (${t.width}, ${t.height}) to (${e}, ${n})`),r}(n);Zt.width=t.width,Zt.height=t.height;const r=Zt.getContext("2d",{willReadFrequently:!0});r.drawImage(t,0,0,t.width,t.height);const s=r.getImageData(0,0,t.width,t.height),i={width:t.width,height:t.height,data:new Uint8Array(s.data)};e(null,i,[i.data.buffer])},n.onerror=function(t){e(t)},n.src=t}}function Yt(t){return 0==(t&t-1)&&0!==t}function te(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}class ee{constructor(t,e){this.max=t,this.currentSize=0,this.onRemove=e,this.reset()}reset(){if(this.data){const t=this.data.values();for(const e of t)this.onRemove(e)}return this.data=new Map,this.currentSize=0,this}clear(){this.reset(),delete this.onRemove}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const n=this.data.get(t);n&&n.node&&n.node.memorySize&&(this.currentSize-=n.node.memorySize),this.data.delete(t),this.data.set(t,e)}else this.data.set(t,e);return this}shrink(){if(this.currentSize>this.max){const t=this.data.keys();let e=t.next();for(;this.currentSize>this.max&&void 0!==e.value;){if(!this.data.get(e.value).current){const t=this.getAndRemove(e.value);t&&this.onRemove(t)}e=t.next()}}}has(t){return this.data.has(t)}keys(){const t=new Array(this.data.size);let e=0;const n=this.data.keys();for(const r of n)t[e++]=r;return t}getAndRemove(t){if(!this.has(t))return null;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),e}get(t){if(!this.has(t))return null;const e=this.data.get(t);return this.data.delete(t),this.data.set(t,e),e}remove(t){if(!this.has(t))return this;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),this.onRemove(e),this}setMaxSize(t){return this.max=t,this.shrink(),this}getMemorySize(){let t=0;const e=this.data.values();for(const n of e){const e=n&&n.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t){const e=this.data.values();for(const n of e)n.current=t}}function ne(t,e){if(t.scenes&&t.scenes.length)for(let n=0,r=t.scenes.length;n<r;n++){const r=t.scenes[n].nodes;for(let n=0,s=r.length;n<s;n++){const s=[];he(r[n],s,t,e)}}}const re=[],se=[],ie=[],oe=[0,0,0],ae=rt([]),ce=[1,1,1];function he(t,e,n,r){const s=e.slice(0);if(t.matrix)s.push(t.matrix);else if(t.rotation||t.translation||t.scale){const e=L(re,t.translation||oe),n=F(se,t.rotation||ae),r=D(ie,t.scale||ce);B(r,n,r);const i=B([],e,r);s.push(i)}if(t.children&&t.children.length)for(let e=0,i=t.children.length;e<i;e++)he(t.children[e],s,n,r);if(void 0!==t.mesh){const e=t.mesh,i=n.meshes[e];if(i){const t=s.slice(0),o=i.primitives;for(let s=0,i=o.length;s<i;s++){const i=o[s];i&&(i.matrices=t,r(i,e,s,n))}}}}function ue(t,e,n){let{byteOffset:r,byteStride:s}=e;const{componentType:i,itemSize:o}=e,a=e.array.buffer,c=i?Gt.getTypedArrayCtor(i):e.array.constructor;if(r=void 0===r?e.array.byteOffset:r,s=s||0,!s||s===o*c.BYTES_PER_ELEMENT&&r%c.BYTES_PER_ELEMENT==0){const e=new c(a,r+n*o*c.BYTES_PER_ELEMENT,o);return t.set(e),t}s||(s=o*c.BYTES_PER_ELEMENT);const h=new Uint8Array(a,s*n+r,o*c.BYTES_PER_ELEMENT);return new Uint8Array(t.buffer).set(h),t}function fe(t,e,n,r){t[4*e]=n[r],t[4*e+1]=n[r+4],t[4*e+2]=n[r+8],t[4*e+3]=n[r+12]}const le=new Array(3),de=new Array(3),me=[40680631590769,40680631590769,40408299984661.445];function pe(t,e,n,r){const s=me,i=Math.cos(n);le[0]=i*Math.cos(e),le[1]=i*Math.sin(e),le[2]=Math.sin(n),Ie(le,le),X(de,s,le);const o=Math.sqrt(K(le,de));var a,c,h;return c=de,h=o,(a=de)[0]=c[0]/h,a[1]=c[1]/h,a[2]=c[2]/h,$(le,le,r),z(t,de,le)}const ye=[1/6378137,1/6378137,1/6356752.314245179],be=[1/40680631590769,1/40680631590769,1/40408299984661.445],ge=new Array(3),Te=new Array(3),we=new Array(3);function _e(t,e){const n=be,r=function(t,e,n,r,s){const i=e[0],o=e[1],a=e[2],c=n[0],h=n[1],u=n[2],f=i*i*c*c,l=o*o*h*h,d=a*a*u*u,m=f+l+d,p=Math.sqrt(1/m),y=$(Ae,e,p);if(m<s)return isFinite(p)?y:void 0;const b=r[0],g=r[1],T=r[2],w=Oe;w[0]=y[0]*b*2,w[1]=y[1]*g*2,w[2]=y[2]*T*2;let _,A,O,x,I,S,M,N,v,E,C,R=(1-p)*xe(e)/(.5*xe(w)),P=0;do{R-=P,O=1/(1+R*b),x=1/(1+R*g),I=1/(1+R*T),S=O*O,M=x*x,N=I*I,v=S*O,E=M*x,C=N*I,_=f*S+l*M+d*N-1,A=f*v*b+l*E*g+d*C*T;P=_/(-2*A)}while(Math.abs(_)>1e-12);return t[0]=i*O,t[1]=o*x,t[2]=a*I,t}(ge,e,ye,n,.1);let s=J(Te,r,n);s=Ie(s,s);const i=Z(we,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=O(K(i,e))*xe(i);return t[0]=_(o),t[1]=_(a),t[2]=c,t}const Ae=new Array(3),Oe=new Array(3);function xe(t){return H(t)}function Ie(t,e){const n=e[0],r=e[1],s=e[2];let i=n*n+r*r+s*s;return i>0&&(i=Math.sqrt(i),t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t}function Se(t,e){return X(e,t,be),W(e,e)}function Me(t,e){const n=t[0],r=t[1],s=Math.cos(r),i=s*Math.cos(n),o=s*Math.sin(n),a=Math.sin(r);return e.x=i,e.y=o,e.z=a,W(e,e)}var Ne=Object.freeze({__proto__:null,radianToCartesian3:pe,cartesian3ToDegree:_e,normalizeCartesian:Ie,geodeticSurfaceNormal:Se,geodeticSurfaceNormalCartographic:Me});function ve(t,e,n,r){n=n||0,r=r||n;const s=Math.abs(t-e);return s<=r||s<=n*Math.max(Math.abs(t),Math.abs(e))}function Ee(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const Ce="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Re(t,e,n){const r=new Uint8Array(t,e,n);return Ce?JSON.parse(Ce.decode(r)):JSON.parse(I(r))}function Pe(t,e,n){const r=new Uint8Array(t,e,n);return Ce?JSON.parse(Ce.decode(r)):JSON.parse(I(r))}function Ue(t,e,n){return{offset:e,byteLength:n}}function Be(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=Ve(i||"UNSIGNED_SHORT"),h=ke(o);return{byteStride:0,byteOffset:s+n,itemSize:h,count:r*h,componentType:c,array:new a(e,n+s,r*h)}}function Le(t,e,n,r){const s=Be(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}function De(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a}=Ve(i||"UNSIGNED_SHORT"),c=ke(o),h=new a(e,s,n*c);return 1===c?h[r]:h.subarray(r*c,r*c+c)}const Fe={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};function ke(t){return t?Fe[t]:1}const He={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function Ve(t){return He[t]}function je(t){for(const e in He)if(t===He[e].ctor)return He[e].type;throw new Error("unrecognized ctor:"+t)}function Ge(t,e,n,r){const s=t,i=e.length/3;for(let t=0;t<i;t++)s[3*t]=e[3*t]/65535*r[0]+n[0],s[3*t+1]=e[3*t+1]/65535*r[1]+n[1],s[3*t+2]=e[3*t+2]/65535*r[2]+n[2];return s}function ze(t,e,n){const r=t.getUint32(12,!0),s=t.getUint32(16,!0),i=t.getUint32(20,!0),o=t.getUint32(24,!0),a=t.buffer;let c,h={},u={},f=null;r>0&&(h=Re(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),i>0&&(u=Pe(a,e,i),e+=i);const l=Ue(0,e,o);return f=a.slice(l.offset,l.offset+l.byteLength),n.push(f),{featureTable:h,featureTableBin:c,batchTable:u,batchTableBin:f}}const qe={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}},Xe={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},$e={},We={east:[],north:[],up:[],west:[],south:[],down:[]};let Ke=[],Qe=[],Ze=[];const Je=[0,0,0];function Ye(t,e,n){return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n[4]=t[4],n[5]=t[5],n[6]=t[6],n[7]=t[7],n[8]=t[8],n[9]=t[9],n[10]=t[10],n[11]=t[11],n[12]=e[0],n[13]=e[1],n[14]=e[2],n[15]=t[15],n}const tn=function(t,e){const n=qe[t][e];let r;const s=t+e;return $e[s]?r=$e[s]:(r=function(r,s,i){if(function(t,e){var n=t[0],r=t[1],s=t[2],i=e[0],o=e[1],a=e[2];return Math.abs(n-i)<=1e-6*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(s-a)<=1e-6*Math.max(1,Math.abs(s),Math.abs(a))}(r,Je))j(Ke,Xe[t]),j(Qe,Xe[e]),j(Ze,Xe[n]);else if(ve(r[0],0,1e-14)&&ve(r[1],0,1e-14)){const s=O(r[2]);j(Ke,Xe[t]),"east"!==t&&"west"!==t&&$(Ke,Ke,s),j(Qe,Xe[e]),"east"!==e&&"west"!==e&&$(Qe,Qe,s),j(Ze,Xe[n]),"east"!==n&&"west"!==n&&$(Ze,Ze,s)}else{Se(r,We.up);const s=We.up,i=We.east;i[0]=-r[1],i[1]=r[0],i[2]=0,W(We.east,i),Q(We.north,s,i),$(We.down,We.up,-1),$(We.west,We.east,-1),$(We.south,We.north,-1),Ke=We[t],Qe=We[e],Ze=We[n]}return i[0]=Ke[0],i[1]=Ke[1],i[2]=Ke[2],i[3]=0,i[4]=Qe[0],i[5]=Qe[1],i[6]=Qe[2],i[7]=0,i[8]=Ze[0],i[9]=Ze[1],i[10]=Ze[2],i[11]=0,i[12]=r[0],i[13]=r[1],i[14]=r[2],i[15]=1,i},$e[s]=r),r}("east","north"),en=[],nn=[],rn=[],sn=[],on=[],an=[],cn=[],hn={x:0,y:0},un={x:0,y:0},fn=Math.PI/180;const{getTextureMagFilter:ln,getTextureMinFilter:dn,getTextureWrap:mn,getMaterialType:pn,getMaterialFormat:yn,getPrimitive:bn,getUniqueREGLBuffer:gn}=n.reshader.REGLHelper,Tn=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],wn=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:_n,logoutIBLResOnCanvas:An,getIBLResOnCanvas:On,getPBRUniforms:xn}=n.reshader.pbr.PBRUtils,In={factor:0,units:0},Sn={specularStrength:0,materialShininess:1},Mn=[1,1,1],Nn=n.mat4.identity([]),vn=[0,0],En=t=>t.material instanceof n.reshader.PhongMaterial,Cn=t=>t.material instanceof n.reshader.pbr.StandardMaterial,Rn=[],Pn=new s.Coordinate(0,0),Un=new s.Point(0,0),Bn=new s.Point(0,0),Ln=new s.Point(0,0),Dn=[],Fn=[],kn=[],Hn=[],Vn={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"};class jn{constructor(t,e){this.Y=e,this.tt=e.getRenderer().canvas,this.pickingFBO=e.getRenderer().pickingFBO,this.et=new s.SpatialReference,this.nt=t,this.rt=new n.reshader.Renderer(t),this.st={},this.it={},this.ot={},this.ct={},this.ht={},this.ut={},this.ft={},this.lt=new n.reshader.Scene,this.dt=new n.reshader.Scene,this.pt=new n.reshader.Scene,this.yt=new n.reshader.Scene,this.bt=new n.reshader.ResourceLoader(t.texture(2)),this.gt=this.Tt.bind(this),this.wt=new n.reshader.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this._t(),this.At=new n.reshader.KHRTechniquesWebglManager(this.nt,this.Ot(),this.bt);const r=this.getMap();r.altitudeToPoint&&(this.xt=r.altitudeToPoint(100,r.getGLRes())/100)}getI3DMMeshes(){return this.ht}getPNTSMeshes(){return this.ct}getB3DMMeshes(){return this.ot}getPaintedMeshes(){return this.It}getMap(){return this.Y.getMap()}paint(t,e,r){const s=r&&r.renderTarget,i=r&&r.sceneFilter,o=this.getMap();if(!t.length||!o)return null;const a=this.St(),c=o.projViewMatrix,h=[],f=[],l=[],d=[],m=[],p=this.Mt(t);for(let s=0,i=t.length;s<i;s++){const i=t[s].data.node;let o=this.Nt(i);if(!o)continue;const a=this.Y.vt(i.Et),y=a.heightOffset||0,g=a.coordOffset||vn;this.ut[i.id]&&(o=this.ut[i.id],o=M(o));let T=a.polygonOffset||In;b(T)&&(T=T()),Array.isArray(o)||(h[0]=o,o=h);for(let t=0,s=o.length;t<s;t++){const s=o[t].properties.magic;if(o[t].properties.heightOffset===y&&o[t].properties.coordOffset[0]===g[0]&&o[t].properties.coordOffset[1]===g[1]||this.Ct(o[t]),"b3dm"===s){if(o[t].getBoundingBox&&!u(c,o[t].getBoundingBox()))continue;const{batchIdData:e,batchIdMap:s}=o[t].geometry.properties;if(e&&s){const e=o[t].properties.node.Et;this.Rt&&this.Rt[e]?n.HighlightUtil.highlightMesh(this.nt,o[t],this.Rt[e],this.Pt,s):this.Rt&&this.Rt[e]||n.HighlightUtil.highlightMesh(this.nt,o[t],null,this.Pt,s),n.HighlightUtil.showOnly(this.nt,o[t],this.Ut&&this.Ut[e],this.Bt,s)}r&&r.bloom&&o[t].properties.hlBloomMesh&&(o[t].properties.hlBloomMesh.properties.depthFunc="always",o[t].properties.hlBloomMesh.properties.polygonOffset=T,l.push(o[t].properties.hlBloomMesh)),l.push(o[t])}else"pnts"===s?d.push(o[t]):"i3dm"===s&&m.push(o[t]);o[t].properties.isLeaf=!!e[i.id],o[t].properties.level=p.get(i.Lt),o[t].properties.polygonOffset=T,o[t].Dt=i,e[i.id]||f.push(o[t]),this.Ft(o[t])}}let y=0;const g=this.At.getExcludeFilter();y+=this.kt(this.Ht,a,[i,En,g],s,f,l,m),y+=this.kt(this.Vt,a,[i,Cn,g],s,f,l,m),this.At.forEachShader((t,e,n)=>{const r=this.St(n);y+=this.kt(t,r,[i,e],s,f,l,m)}),this.dt.setMeshes(d);const T=this.jt();return y+=this.rt.render(this.Gt,T,this.dt,s&&s.fbo),this.It={pntsMeshes:d,i3dmMeshes:m,b3dmMeshes:l},y}kt(t,e,n,r,s,i,o){t.filter=n.filter(t=>!!t),e.debug=!1,e.debug=!1;let a=0;return this.lt.setMeshes(i),a+=this.rt.render(t,e,this.lt,r&&r.fbo),this.pt.setMeshes(o),a+=this.rt.render(t,e,this.pt,r&&r.fbo),a}zt(t,e){return e.Dt.qt-t.Dt.qt}paintRegion(t,e,n,r,s){const i=this.getMap();if(!t.length&&!e.length)return;const o=i.projViewMatrix,a=[];for(let n=0,r=(t=t.concat(e)).length;n<r;n++){const e=t[n].node,r=this.Xt(e);r&&(r.getBoundingBox&&!u(o,r.getBoundingBox())||a.push(r))}this.$t.filter=r,this.yt.setMeshes(a);const c=this.Wt(n);this.rt.render(this.$t,c,this.yt,s&&s.fbo)}deleteTile(t){const e=t.node.id;this.Kt(e)}Kt(t){const e=this.it[t];e&&(e.geometry.dispose(),e.dispose(),delete this.it[t]);const n=this.ot[t]||this.ct[t]||this.ht[t]||this.ut[t]||this.st[t];this.ut[t]?this.Qt(t):n&&(this.Zt(n),delete this.ot[t],delete this.ct[t],delete this.ht[t],delete this.st[t])}Qt(t){let e=this.ut[t];e=M(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.Kt(n)}delete this.ut[t]}Zt(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.Zt(t[e]);else{n.HighlightUtil.showOnly(this.nt,t),n.HighlightUtil.highlightMesh(this.nt,t);const e=t.geometry.properties.url;if(e){const t=this.ft[e];t&&(t.refCount--,t.refCount<=0&&(t.geometry.dispose(),t.material.dispose(),delete this.ft[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.Y;An(t.getRenderer().canvas,t.getMap());for(const t in this.ut)this.Qt(t);this.ut={};for(const t in this.ot)this.Kt(t);this.ot={};for(const t in this.ct)this.Kt(t);this.ct={};for(const t in this.ht)this.Kt(t);this.ht={};for(const t in this.st)this.Kt(t);this.st={};for(const t in this.it)this.Kt(t);this.it={},this.Ht&&(this.Ht.dispose(),delete this.Ht),this.Vt&&(this.Vt.dispose(),delete this.Vt),this.Gt&&(this.Gt.dispose(),delete this.Gt),this.$t&&(this.$t.dispose(),delete this.$t),this.At.dispose(),this.picking&&this.picking.dispose()}Xt(t){if(!t.boundingVolume||!t.boundingVolume.region)return null;if(this.it[t.id])return this.it[t.id];const e=t.boundingVolume.region;let r=new s.Coordinate(_(e[0]),_(e[1])),i=new s.Coordinate(_(e[2]),_(e[3]));r=this.Jt(r),i=this.Jt(i);const o=r.add(i).Yt(.5);r._sub(o),i._sub(o);const a=this.te(e[4],e[5]),c=a.x,h=a.y,u=[r.x,r.y,h,i.x,r.y,h,i.x,i.y,h,r.x,i.y,h,r.x,r.y,c,i.x,r.y,c,i.x,i.y,c,r.x,i.y,c],f=new n.reshader.Geometry({aPosition:u},[0,1,1,2,2,3,3,0,0,4,1,5,2,6,3,7,4,5,5,6,6,7,7,4],0,{primitive:"lines"});f.generateBuffers(this.nt);const l=new n.reshader.Mesh(f),d=n.mat4.identity([]);return l.setLocalTransform(n.mat4.translate(d,d,[o.x,o.y,0])),this.it[t.id]=l,l}Nt(t){return this.ot[t.id]||this.ct[t.id]||this.ht[t.id]||this.ut[t.id]}has(t){return this.Nt(t)||this.st[t.id]}Ct(t){const e=t.properties.magic;"b3dm"===e?this.ee(t):"i3dm"===e?this.ne(t):"pnts"===e&&this.re(t)}createPntsMesh(t,e,r,s){if(this.ct[e]){const t=this.ct[e];return console.warn(`pnts mesh with id(${e}) was already created.`),s(null,{id:e,mesh:t}),t}const{pnts:i,featureTable:o,rootIdx:a,compressed_int16_params:c}=t,h=o.POINTS_LENGTH,u=new n.reshader.Geometry(i,null,h,{primitive:"points",positionAttribute:"POSITION"});u.generateBuffers(this.nt);const f={};i.POSITION?f.HAS_POSITION=1:i.POSITION_QUANTIZED&&(f.HAS_POSITION_QUANTIZED=1),i.RGB?f.HAS_RGB=1:i.RGBA?f.HAS_RGBA=1:i.RGB565&&(f.HAS_RGB565=1),(i.NORMAL||i.NORMAL_OCT16P)&&(f.HAS_NORMAL=1,i.NORMAL_OCT16P&&(f.HAS_NORMAL_OCT16P=1)),this.se(f,c),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map(t=>t/255));const{rtcCenter:l,rtcCoord:d}=t,m=this.Y.vt(a),p=new n.reshader.Mesh(u);return p.properties.magic="pnts",p.properties.id=e,p.properties.node=r,p.properties.count=h,p.properties.batchTable=t.batchTable,p.properties.batchTableBin=t.batchTableBin,p.properties.serviceIndex=a,p.properties.rtcCoord=d,p.properties.rtcCenter=l,p.setDefines(f),Object.defineProperty(p.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:m&&m.pointColor||[1,1,1,1]}}),Object.defineProperty(p.uniforms,"pointSize",{enumerable:!0,get:function(){return m&&m.pointSize||2}}),Object.defineProperty(p.uniforms,"pointOpacity",{enumerable:!0,get:function(){return m&&m.pointOpacity||1}}),this.ie(p,c),this.re(p),this.ct[e]=p,s(null,{id:e,mesh:[p]}),[p]}re(t){const{rtcCenter:e,rtcCoord:r,node:s}=t.properties,i=this.oe(kn,r),o=t.localTransform||[];this.ae(o,s,e,r),n.mat4.multiply(o,o,i);const a=this.Y.vt(s.Et);if(a.coordOffset){const t=this.ce(s.Et,r);n.mat4.multiply(o,t,o)}t.setLocalTransform(o),t.properties.heightOffset=a.heightOffset||0,t.properties.coordOffset=a.coordOffset&&a.coordOffset.slice(0)||vn}createI3DMMesh(t,e,r,s){if(this.ht[e]){const t=this.ht[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.st[e]||s(null,{id:e,mesh:t}),t}const i=this.Y.vt(r.Et),o=this.he(r.ue),{i3dm:a,featureTable:c,gltf:h,batchTable:u,batchTableBin:f,count:l}=t,d=c.INSTANCES_LENGTH,{rtcCenter:m,rtcCoord:p}=t,y=this.oe(kn,p),b=this.ae(Hn,r,m,p);n.mat4.multiply(y,b,y);const{POSITION:g,NORMAL_UP:T,NORMAL_RIGHT:w,SCALE:_,SCALE_NON_UNIFORM:A,INSTANCE_ROTATION:O}=a,x={"instance_vectorA":new Float32Array(4*d),"instance_vectorB":new Float32Array(4*d),"instance_vectorC":new Float32Array(4*d)},I=new Float32Array(3),M=new Float32Array(3),N=[],v=new Float32Array(1),E=new Float32Array(3),C=[],R=[],P=[],U=[],B=new Float32Array(9);!function(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:i,itemSize:o}=t,a=t.array.buffer,c=i?Gt.getTypedArrayCtor(i):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/o,(!r||r===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o)}return}const h=new Uint8Array(o*c.BYTES_PER_ELEMENT);r||(r=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,o*c.BYTES_PER_ELEMENT);h.set(s);e(new c(h.buffer),t),s.set(h)}}(g,(t,e)=>{T?(ue(M,w,e),ue(I,T,e),n.vec3.cross(N,M,I),n.vec3.normalize(N,N),S(C,M,0),S(C,I,1),S(C,N,2),n.quat.fromMat3(R,C)):O?(ue(B,O,e),n.quat.fromMat3(R,B)):n.quat.identity(R),_?(ue(v,_,e),n.vec3.set(P,v[0],v[0],v[0])):A?(ue(E,A,e),n.vec3.set(P,...E)):n.vec3.set(P,1,1,1),n.mat4.fromRotationTranslationScale(U,R,t,P),fe(x.instance_vectorA,e,U,0),fe(x.instance_vectorB,e,U,1),fe(x.instance_vectorC,e,U,2)});const L={};for(const t in x)L[t]={buffer:this.nt.buffer({dimension:x[t].length/d,data:x[t]}),divisor:1};const D=i.shader||"pbr";let F=0,k=!0;const H=[];return ne(h,(t,s,i,a)=>{const{geometry:c,material:h}=this.fe(t,s,i,a,r,!0,D);h&&!h.isReady()&&(k=!1,F++);const b=new n.reshader.InstancedMesh(L,d,c,h);b.properties.magic="i3dm",b.properties.id=e,b.properties.count=l,b.properties.batchTable=u,b.properties.batchTableBin=f,b.properties.serviceIndex=r.Et,b.properties.rtcCoord=p,b.properties.rtcCenter=m,b.properties.node=r;const g=this.le(t,c,h,r.Et,a);t.compressed_int16_params&&this.ie(b,t.compressed_int16_params),this.de(b,t.attributes);const T=n.mat4.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)n.mat4.multiply(T,T,t.matrices[e]);n.mat4.multiply(T,o,T),b.setPositionMatrix(T),this.ne(b,y),b.setDefines(g),b.properties.polygonOffset={offset:0,factor:0},H.push(b),delete t.attributes}),k?(this.ht[e]=H,s(null,{id:e,mesh:H})):(this.st[e]={meshes:H,count:F},H.me=s),H}ne(t,e){const{rtcCenter:r,rtcCoord:s,node:i}=t.properties;if(!e){e=this.oe(kn,s);const t=this.ae(Hn,i,r,s);n.mat4.multiply(e,t,e)}const o=this.Y.vt(i.Et),a=t.localTransform||[];if(o.coordOffset){const t=this.ce(i.Et,s);n.mat4.multiply(a,t,e)}else n.mat4.copy(a,e);t.setLocalTransform(a),t.properties.heightOffset=o.heightOffset||0,t.properties.coordOffset=o.coordOffset&&o.coordOffset.slice(0)||vn}createB3DMMesh(t,e,r,i){if(this.ot[e]||this.st[e]){const t=this.ot[e];return console.warn(`mesh with id(${e}) was already created.`),this.st[e]||i(null,{id:e,mesh:t}),t}let o;if(r.maxExtent){const t=new s.Extent(r.maxExtent).convertTo(t=>this._pointToPrj(t));o=[t.xmin,t.ymin,t.xmax,t.ymax]}const a=t.gltf,{projCenter:c}=a.extensions.MAPTALKS_RTC,{rtcCoord:h,center:u}=a.extensions.CESIUM_RTC,f=a.asset.sharePosition,l=this.he(r.ue);let d;d=f?this.oe(kn,h):this.pe(kn,h,c,r.Et);const m=this.Y.vt(r.Et);let p=m.shader||"pbr";if(a.materials)for(let t=0;t<a.materials.length;t++)if(a.materials[t]&&a.materials[t].extensions&&a.materials[t].extensions.KHR_materials_unlit){p=m.shader="phong";break}const y=[];let b=0,g=!0;return ne(a,(s,i,a,w)=>{const{geometry:_,material:A}=this.fe(s,i,a,w,r,!1,p);A&&!A.isReady()&&(g=!1,b++);const O=new n.reshader.Mesh(_,A);O.properties.magic="b3dm",O.properties.id=e,O.properties.node=r,O.properties.batchTable=t.batchTable,O.properties.batchTableBin=t.batchTableBin,O.properties.count=t.featureTable.BATCH_LENGTH,O.properties.serviceIndex=r.Et;const x=this.le(s,_,A,r.Et,w);O.setDefines(x);const I=s.compressUniforms;if(I)for(const t in I)O.setUniform(t,I[t]);s.compressed_int16_params&&this.ie(O,s.compressed_int16_params),this.de(O,s.attributes),o&&(x.USE_MAX_EXTENT=1,O.setUniform("maxPrjExtent",o)),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonOpacity")||Object.defineProperty(O.uniforms,"polygonOpacity",{enumerable:!0,get:function(){return T(m.opacity)?m.opacity:1}});const S=n.mat4.identity([]);if(f&&s.matrices&&s.matrices.length)for(let t=0;t<s.matrices.length;t++)n.mat4.multiply(S,S,s.matrices[t]);f&&n.mat4.multiply(S,l,S),O.properties.node=r,O.properties.projCenter=c,O.properties.nodeMatrix=S,O.properties.isSharedPosition=f,O.properties.rtcCoord=h,O.properties.rtcCenter=u,this.ee(O,d),y.push(O),delete s.attributes}),g?(this.ot[e]=y,i(null,{id:e,mesh:y})):(this.st[e]={meshes:y,count:b},y.me=i),y}ie(t,e){e.POSITION&&t.setUniform("compressedPositionRange",e.POSITION),e.TEXCOORD_0&&t.setUniform("compressedTexcoordRange_0",e.TEXCOORD_0),e.TEXCOORD_1&&t.setUniform("compressedTexcoordRange_1",e.TEXCOORD_0),e.NORMAL&&t.setUniform("compressedNormalRange",e.NORMAL),e.TANGENT&&t.setUniform("compressedTangentRange",e.TANGENT),e.compressed_ratio&&t.setUniform("compressed_ratio",e.compressed_ratio)}ee(t,e){const{isSharedPosition:r,rtcCoord:s,rtcCenter:i,projCenter:o,nodeMatrix:a,node:c}=t.properties;e||(e=r?this.oe(kn,s):this.pe(kn,s,o,c.Et));const h=t.localTransform||n.mat4.identity([]);if(r){const t=this.ae(Hn,c,i,s);n.mat4.multiply(h,e,a),n.mat4.multiply(h,t,h)}else n.mat4.multiply(h,e,a);const u=this.Y.vt(c.Et);if(u.coordOffset){const t=this.ce(Hn,c.Et,s);n.mat4.multiply(h,t,h)}t.setLocalTransform(h),t.properties.heightOffset=u.heightOffset||0,t.properties.coordOffset=u.coordOffset&&u.coordOffset.slice(0)||vn}de(t,e){if(e&&e.TEXCOORD_0&&e.TEXCOORD_0.extensions&&e.TEXCOORD_0.extensions.WEB3D_quantized_attributes){const n=e.TEXCOORD_0.extensions.WEB3D_quantized_attributes.decodeMatrix;t.setUniform("decodeMatrix",n)}}ae(t,e,r,i){const o=this.getMap(),a=this.Y.vt(e.Et).heightOffset||0,c=new s.Coordinate(i);let h;h=o.altitudeToPoint?this.xt:o.distanceToPointAtRes(100,100,o.getGLRes(),c).y/100;const u=e.matrix?n.mat4.copy(t,e.matrix):n.mat4.identity(t);if(r){Ye(u,n.vec3.transformMat4(Rn,r,u),u)}const f=function(t,e,n,r,s,i,o){e=j(en,e);const a=pe(en,e[0]*fn,e[1]*fn,e[2]),c=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}(nn,n),h=r.ellipsoid;let u;u=0===Y(c)?G(rn,0,0,-6378137):_e(rn,c),hn.x=u[0],hn.y=u[1];const f=r.project(hn,un);sn[0]=f.x/s,sn[1]=f.y/s,sn[2]=(u[2]+o)*i;const l=tn(a,h,on),d=function(t,e,n){const r=t[0],s=t[1],i=t[2],o=t[4],a=t[5],c=t[6],h=t[8],u=t[9],f=t[10],l=e[0],d=e[1],m=e[2],p=e[3],y=e[4],b=e[5],g=e[6],T=e[7],w=e[8],_=r*l+o*d+h*m,A=s*l+a*d+u*m,O=i*l+c*d+f*m,x=r*p+o*y+h*b,I=s*p+a*y+u*b,S=i*p+c*y+f*b,M=r*g+o*T+h*w,N=s*g+a*T+u*w,v=i*g+c*T+f*w;return n[0]=_,n[1]=A,n[2]=O,n[3]=0,n[4]=x,n[5]=I,n[6]=S,n[7]=0,n[8]=M,n[9]=N,n[10]=v,n[11]=0,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}(function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],a=e[5],c=e[6],h=e[7],u=e[8],f=e[9],l=e[10],d=e[11],m=e[12],p=e[13],y=e[14],b=e[15],g=n*a-r*o,T=n*c-s*o,w=n*h-i*o,_=r*c-s*a,A=r*h-i*a,O=s*h-i*c,x=u*p-f*m,I=u*y-l*m,S=u*b-d*m,M=f*y-l*p,N=f*b-d*p,v=l*b-d*y,E=g*v-T*N+w*M+_*S-A*I+O*x;return E?(E=1/E,t[0]=(a*v-c*N+h*M)*E,t[1]=(s*N-r*v-i*M)*E,t[2]=(p*O-y*A+b*_)*E,t[3]=(l*A-f*O-d*_)*E,t[4]=(c*S-o*v-h*I)*E,t[5]=(n*v-s*S+i*I)*E,t[6]=(y*w-m*O-b*T)*E,t[7]=(u*O-l*w+d*T)*E,t[8]=(o*N-a*S+h*x)*E,t[9]=(r*S-n*N-i*x)*E,t[10]=(m*A-p*w+b*g)*E,t[11]=(f*w-u*A-d*g)*E,t[12]=(a*I-o*M-c*x)*E,t[13]=(n*M-r*I+s*x)*E,t[14]=(p*T-m*_-y*g)*E,t[15]=(u*_-f*T+l*g)*E,t):null}(an,l),function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}(cn,n),t);return Ye(t,sn,d),t}(u,i,u,o.getProjection(),o.getGLRes(),h,a),l=function(t,e){return G(t,e[12],e[13],e[14]),t}(Fn,f);let d=this.Y.options.offset;if(b(d)){const t=this.Y.ye(e.id).center;d=d.call(this.Y,t)}return n.vec3.set(Dn,d[0],d[1],0),n.vec3.sub(l,l,Dn),Ye(f,l,f),f}ce(t,e,r){const s=this.Y.vt(e);if(!s.coordOffset)return null;const i=this.getMap(),o=i.getGLRes();Pn.set(r[0],r[1]);const a=i.coordToPointAtRes(Pn,o,Bn),c=s.coordOffset,h=Pn.set(r[0]+c[0],r[1]+c[1]),u=i.coordToPointAtRes(h,o,Ln),f=u.x-a.x,l=u.y-a.y,d=this.be(),m=n.vec3.set(Dn,f,l,(c[2]||0)*d);return n.mat4.fromTranslation(t,m)}be(){const t=this.getMap();let e;return e=t.altitudeToPoint?this.xt:t.distanceToPointAtRes(100,100,t.getGLRes(),Pn).y/100,e}createCMPTMesh(t,e,n,r){if(this.ut[e]){const t=this.ut[e];return console.warn(`mesh with id(${e}) was already created.`),r(null,{id:e,mesh:t}),t}const{content:s}=t,i=[];for(let t=0;t<s.length;t++){const{magic:r}=s[t],o=e+"."+t;"b3dm"===r?this.createB3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"i3dm"===r?this.createI3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"pnts"===r?this.createPntsMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"cmpt"===r&&this.createCMPTMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)})}return this.ut[e]=i,r(null,{id:e,mesh:i}),i}le(t,e,n,r,s){const i=("phong"===(this.Y.vt(r).shader||"pbr")?this.Ht:this.Vt).getGeometryDefines(e);s.asset&&"S3M"===s.asset.generator&&this.ge(i,e),e.data.uvRegion&&(i.HAS_I3S_UVREGION=1),e.data[e.desc.normalAttribute]&&(i.VertexNormal=1),e.data[e.desc.color0Attribute]&&(i.VertexColor=1),e.data[e.desc.uv0Attribute]&&(i.TexCoord=1),e.data[e.desc.textureCoordMatrixAttribute]&&(i.HAS_TextureCoordMatrix=1),n.get("uTexture")&&(i.COMPUTE_TEXCOORD=1),n.get("uTexture2")&&(i.TexCoord2=1),"MESHOPT"===this.Y.Te&&(i.MeshOPT_Compress=1),this.hasIBL()&&(i.HAS_IBL_LIGHTING=1),t.attributes&&t.attributes.TEXCOORD_0&&"WEB3D_quantized_attributes"===t.attributes.TEXCOORD_0.extensions&&(i.HAS_WEB3D_quantized_attributes_TEXCOORD=1),this.se(i,t.compressed_int16_params);return y(i,t.compressDefines),i}se(t,e){e&&(t.HAS_COMPRESSED_INT16=1,e.POSITION&&(t.HAS_COMPRESSED_INT16_POSITION=1),e.TEXCOORD_0&&(t.HAS_COMPRESSED_INT16_TEXCOORD_0=1),e.TEXCOORD_1&&(t.HAS_COMPRESSED_INT16_TEXCOORD_1=1),e.NORMAL&&(t.HAS_COMPRESSED_INT16_NORMAL=1),e.TANGENT&&(t.HAS_COMPRESSED_INT16_TANGENT=1),e.compressed_ratio&&(t.HAS_COMPRESSED_INT16_RATIO=1))}Ft(t){const e=this.Y.getRenderer();e&&e.updateMaskDefines(t)}ge(t,e){e.data.aNormal&&(t.VertexNormal=1),e.data.instanceId&&(t.Instance=1),e.data.aTexCoord0&&(t.TexCoord=1),e.data.aColor&&(t.VertexColor=1),e.data.aTexCoord1&&(t.TexCoord2=1),e.data.uv2&&(t.InstanceBim=1)}fe(t,e,n,r,s,i,o){let a=!1;r.asset&&"S3M"===r.asset.generator&&(a=!0,r.extensions=r.extensions||{});const c=r.url+"-"+e+"-"+n;if(this.ft[c])return this.ft[c].refCount++,this.ft[c];let h,u;const f=r.materials&&r.materials[t.material],l=r.extensions&&r.extensions.KHR_techniques_webgl,d=this.Y.vt(s.Et);if(l&&f.extensions&&f.extensions.KHR_techniques_webgl){const e=this.we(t,r,i,a);h=e.material,u=e.geometry,d.fillEmptyDataInMissingAttribute&&(u.desc.fillEmptyDataInMissingAttribute=!0)}else{u=this._e(t,i,Vn);const e=d.ambientLight;let n=d.environmentExposure;const s=d.material,a=this.getMap().getLightManager(),c=a&&a.getAmbientLight();if(e&&(!c||c.color)&&void 0===n){const t=c&&c.color?c.color[0]:.2;n=e[0]/t}h=this.Ae(t.material,r,o,s||Sn,n||1)}Object.defineProperty(h.uniforms,"alphaTest",{enumerable:!0,get:function(){const t=d.alphaTest;return p(t)?.1:t}}),h&&!h.isReady()?h.Oe=s.id:h||(h=this.wt);const m={refCount:1,geometry:u,material:h};return u.properties.url=c,this.ft[c]=m,m}we(t,e,n,r){const{geometry:s,material:i}=this.At.createMesh(t,e,n,r);return{geometry:s,material:i}}_e(t,e,r){const s=t.attributes;let i=s._BATCHID&&s._BATCHID.array;if(i&&i.byteOffset&&(i=new i.constructor(i)),s.COLOR_0){const t=s.COLOR_0.array||s.COLOR_0;if(t instanceof Float32Array){const e=new Uint8Array(t.length);for(let n=0;n<e.length;n++)e[n]=Math.round(255*t[n]);s.COLOR_0.array?(s.COLOR_0.array=e,s.COLOR_0.componentType=5121):s.COLOR_0=e}}const o={};for(const t in s){const e=gn(this.nt,s[t],{dimension:s[t].itemSize}),n=r[t]||t;o[n]={buffer:e},s[t].quantization&&(o[n].quantization=s[t].quantization),n===r.POSITION&&(o[n].array=s[t].array,o[n].min=s[t].min,o[n].max=s[t].max)}const a=t.indices?t.indices.array?t.indices.array.slice():t.indices:null,c=new n.reshader.Geometry(o,a,0,{positionAttribute:r.POSITION,normalAttribute:r.NORMAL,uv0Attribute:r.TEXCOORD_0,uv1Attribute:r.TEXCOORD_1,color0Attribute:r.COLOR_0,tangentAttribute:r.TANGENT,pickingIdAttribute:r._BATCHID,primitive:void 0===t.mode?"triangles":bn(t.mode)});return i&&a&&(c.properties.batchIdData=i,c.properties.batchIdMap=function(t,e){if(!e)return null;const n=new Map;for(let r=0;r<e.length;r++){const s=e[r],i=t[s];let o=n.get(i);o||(o=[],n.set(i,o)),o.push(s)}return n}
18
+ let te=0;function ee(t){return null==t}function ne(t){return!ee(t)}function re(t){return!ee(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}function se(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 ie(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 oe(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function ae(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),n=e.length,r=new Uint8Array(n);for(let t=0;t<n;t++)r[t]=e.charCodeAt(t);return r.buffer}const ce=[],he=[],ue=[],le=[0,0,0],fe=Kt([]),de=[1,1,1];function me(t,e,n,r,s,i,o){const a=ie(o);if((0===s||s===r*a.BYTES_PER_ELEMENT)&&i%a.BYTES_PER_ELEMENT==0){const s=new a(e,i,n*r);return t.set(s),t}0===s&&(s=r*a.BYTES_PER_ELEMENT);const c=new Uint8Array(r*a.BYTES_PER_ELEMENT);for(let o=0;o<n;o++){let n=null;const h=new Uint8Array(e,s*o+i,r*a.BYTES_PER_ELEMENT);c.set(h),n=new a(c.buffer,0,r);for(let e=0;e<r;e++)t[o*r+e]=n[e]}return t}const be="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function pe(t,e,n){const r=new Uint8Array(t,e,n);return be.decode(r)}const ge={get:function(t,e={}){e||(e={});const n=new AbortController,r=n.signal,s=se({},e);s.signal=r,s.method||(s.method="GET");const i=fetch(t,s).then(t=>{const n=this.s(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 i.xhr=n,i},s:(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={})=>(e||(e={}),e.responseType="arraybuffer",ge.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?ge.jsonp(t):((e=e||{}).responseType="json",ge.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+te++;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(r){document.getElementsByTagName("head")[0].removeChild(n),n=null,delete window[e],t(r)},document.getElementsByTagName("head")[0].appendChild(n)})}};class ye{constructor(t,e,n){this.i=t,this.decoders=e,this.o=n,this.images={},this.h={}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)}if(this.h[t.id])return this.h[t.id].then(()=>{const r=this.buffers[t.id],s=this.u(e,r);return this.getImageByBuffer(s,n)});if(oe(t.uri)){const r=this.buffers[t.id]=ae(t.uri),s=this.u(e,r);return this.getImageByBuffer(s,n)}return this.h[t.id]=ge.getArrayBuffer(t.uri,null).then(r=>{const s=this.buffers[t.id]=r.data,i=this.u(e,s);return this.getImageByBuffer(i,n)})}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const n=this.decoders;return n[e.mimeType]?n[e.mimeType](t,{supportedFormats:this.o}):"image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType?(console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.m(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.m(t.id,e)}m(t,e){return new Promise((n,r)=>{this.i(e,(s,i)=>{s?r(s):(URL.revokeObjectURL(e),this.images[t]=i,n(this.images[t]))})})}}const we=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],ve=[];class Te{constructor(t,e,n){this.rootPath=t,this.gltf=e,this.p=!1,this.glbBuffer=n,this.buffers={},this.requests={},this.accessors={},this.v()}T(t,e){const n=this.gltf,r=n.accessors[e];if(void 0===r.bufferView)return this.accessors[r.id]=this._(t,e,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const s=n.bufferViews[r.bufferView];return this.M(s).then(n=>{const{buffer:s,byteOffset:i}=n;return this.accessors[r.id]=this._(t,e,s,i)})}M(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(oe(e.uri)){const t=this.buffers[e.id]=ae(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]=ge.getArrayBuffer(t,null).then(r=>(n&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=r.data,byteOffset:0}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}_(t,e,n,r=0){const s=this.gltf,i=s.accessors[e],o=void 0!==i.bufferView?s.bufferViews[i.bufferView]:{},a=(o.byteOffset||0)+r,c=this.O(i.type),h=ie(i.componentType),u=o.byteStride||0,l={array:void 0,name:t,accessorName:e,byteLength:i.count*c*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:c,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.p)l.byteStride=u,l.byteOffset=a+(i.byteOffset||0),!u||u===c*h.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(l.array=this.A(n,i.count,c,a+(i.byteOffset||0),h),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(n,a,o.byteLength);else if(i.interleaved){l.byteStride=0,l.byteOffset=0;const t=new h(i.count*c);if(l.array=me(t,n,i.count,c,u,a+(i.byteOffset||0),i.componentType),l.extensions&&l.extensions.WEB3D_quantized_attributes&&c>2){const t=new Float32Array(l.array.length),{decodeMatrix:e}=l.extensions.WEB3D_quantized_attributes;for(let n=0;n<l.array.length;n+=c){ve[0]=l.array[n],ve[1]=l.array[n+1],ve[2]=l.array[n+2],ve[3]=1;const r=Jt(ve,ve,e);t[n]=r[0],t[n+1]=r[1],t[n+2]=r[2]}l.componentType=5126,l.array=t}}else l.byteStride=0,l.array=this.A(n,i.count,c,a+(i.byteOffset||0),h),l.byteOffset=l.array.byteOffset;else{l.array=new h(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}v(){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)}A(t,e,n,r,s){return r%s.BYTES_PER_ELEMENT!=0&&(t=t.slice(r,r+e*n*s.BYTES_PER_ELEMENT),r=0),new s(t,r,n*e)}O(t){const e=we.indexOf(t);return we[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.M(e).then(r=>{const{buffer:s,byteOffset:i}=r,o=pe(s,i+(e.byteOffset||0),n);return t.content=o,t})}if(t.uri){if(oe(t.uri)){const e=ae(t.uri),n=pe(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return ge.get(e).then(e=>(t.content=e,t))}}return Promise.resolve(t)});return Promise.all(n).then(()=>t)}}class _e extends ye{constructor(t,e,n,r,s,i){super(r,s,i),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=n,this.accessor=new Te(t,e,n)}iterate(t,e){const n=this.gltf[e];if(!n)return;let r=0;for(const e in n)t(e,n[e],r++)}createNode(t){const e={};if(ne(t.name)&&(e.name=t.name),ne(t.children)&&(e.children=t.children),ne(t.jointName)&&(e.jointName=t.jointName),ne(t.matrix)&&(e.matrix=t.matrix),ne(t.rotation)&&(e.rotation=t.rotation),ne(t.scale)&&(e.scale=t.scale),ne(t.translation)&&(e.translation=t.translation),ne(t.extras)&&(e.extras=t.extras),ne(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=Et(ce,e.translation||le),r=Ct(he,e.rotation||fe),s=Nt(ue,e.scale||de);return St(s,r,s),St(t,n,s)}return It(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}I(t){const e={};for(const n in t){const r=t[n];let s,i;r.instanceTechnique&&r.instanceTechnique.values?(s=r.instanceTechnique,i=s.values.diffuse):(s=r,i=s.values.tex||s.values.diffuseTex||s.values.diffuse);const o={baseColorTexture:{index:i}};r.name&&(o.name=r.name),r.extensions&&(o.extensions=r.extensions),r.extras&&(o.extras=r.extras),e[n]=o}return e}S(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],r=(n.byteOffset||0)+this.glbBuffer.byteOffset,s=n.byteLength,i=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,s);return this.getImageByBuffer(i,t)}return this.requestExternalImage(t)}N(t){const e=this.gltf.textures[t];if(!e)return null;const n=this.gltf.images[e.source];return this.S(n).then(t=>{const r=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:r}})}getBaseColorTexture(t){const e=this.gltf.materials[t];let n,r;if(e.instanceTechnique&&e.instanceTechnique.values?(n=e.instanceTechnique,r=n.values.diffuse):(n=e,r=n.values.tex||n.values.diffuseTex||n.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const s=this.gltf.textures[r];if(!s)return null;const i=this.gltf.samplers[s.sampler];return{format:s.format||6408,internalFormat:s.internalFormat||6408,type:s.type||5121,sampler:i,source:this.gltf.images[s.source]}}getMaterial(){return null}getAnimations(){return null}}class Me extends ye{constructor(t,e,n,r,s,i){super(r,s,i),this.rootPath=t,this.gltf=e,this.glbBuffer=n,this.buffers={},this.requests={},this.accessor=new Te(t,e,n)}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 se(e,t),!ne(t.weights)&&this.gltf.meshes&&ne(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}N(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),!ne(n))return null;const r=this.gltf.images[n];return this.S(r).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:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};se(n,e);const s=ne(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return s&&(n.sampler=s,n.sampler.magFilter=s.magFilter||9729,n.sampler.minFilter=s.minFilter||9729,n.sampler.wrapS=s.wrapS||10497,n.sampler.wrapT=s.wrapT||10497),t.format&&(n.format=t.format),n})}S(t){if(!ne(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.C(e,t)}return null}C(t,e){const n=this.u(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}u(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}R(t,e){const n=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)n[e]=String.fromCharCode(t[e]);return n.join(""),"data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)))}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++)(ne(t[n].input)||ne(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 Oe="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class Ae{static read(t,e=0,n=0){n||(n=t.byteLength);const r=new DataView(t,e,n),s=r.getUint32(4,!0);if(1===s)return Ae.readV1(r,e);if(2===s)return Ae.readV2(t,e);throw new Error("Unsupported glb version : "+s)}static readV1(t,e){const n=t.getUint32(8,!0),r=t.getUint32(12,!0);if(n!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const s=xe(t.buffer,20+e,r);return{json:JSON.parse(s),glbBuffer:{byteOffset:20+e+r,buffer:t.buffer,byteLength:n}}}static readV2(t,e){let n,r,s;const i=new DataView(t,e+12);let o=0;for(;o<i.byteLength;){const a=i.getUint32(o,!0);o+=4;const c=i.getUint32(o,!0);if(o+=4,1313821514===c)n=xe(t,e+12+o,a);else if(5130562===c){s=e+12+o,r=a;break}o+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function xe(t,e,n){if(Oe){const r=new Uint8Array(t,e,n);return Oe.decode(r)}return function(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=Ie[s>>3&7];if(!(64&s)||!n||r+n>e)return null;for(s&=63>>n;n>0;n-=1){const e=t[r++];if(128!=(192&e))return null;s=s<<6|63&e}}n+=String.fromCharCode(s)}return n}(new Uint8Array(t,e,n))}const Ie=[1,1,1,1,2,2,3,0],Se=[0,0,0],Ee=[0,0,0,1],Ne=[1,1,1],Ce={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},Re={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Pe={P(t,e,n,r,s,i,o,a){const c=ne(t)?e.animations:[e.animations[0]],h={};for(let e=0;e<c.length;e++){const u=c[e],l=u.name||e;if(ne(t)&&l!==t)continue;const f=u.channelsMap[n];if(f)for(let t=0;t<f.length;t++){const e=f[t];"translation"===e.target.path?(this.k(s,u.samplers[e.sampler],r,1),h.translation=Bt(Se,s)):"rotation"===e.target.path?(this.B(i,u.samplers[e.sampler],r,1),h.rotation=Wt(Ee,i)):"scale"===e.target.path?(this.k(o,u.samplers[e.sampler],r,1),h.scale=Bt(Ne,o)):"weights"===e.target.path&&a&&(this.k(a,u.samplers[e.sampler],r,a.length),h.weights=a)}}return h},k(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.L(Re,e,n,1*r);s&&(t=function(t,e,n,r){for(let s=0;s<t.length;s++)t[s]=e[s]+r*(n[s]-e[s]);return t}(t,s.PREVIOUS,s.NEXT,s.INTERPOLATION));break}case"STEP":{const s=this.L(Re,e,n,1*r);s&&(t=function(t,e){for(let n=0;n<t.length;n++)t[n]=e[n];return t}(t,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.L(Re,e,n,3*r);s&&(t=this.U(t,s,e.input.array,3*r));break}}return t},B(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.L(Re,e,n,1);r&&Yt(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.L(Re,e,n,1);r&&(t=Xt(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.L(Re,e,n,3);if(r){for(let t=0;t<r.PREVIOUS.length;t++)r.PREVIOUS[t]=Math.acos(r.PREVIOUS[t]),r.NEXT[t]=Math.acos(r.NEXT[t]);t=this.U(t,r,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},D(t,e){const n=t.length;let r,s,i,o=0,a=n-1,c=Math.floor((o+a)/2);for(;o<=n-1&&a>=0;){if(o===a)return null;if(t[c]<=e&&e<=t[c+1]){const n=t[c];return r=c,s=c+1,i=(e-n)/(t[c+1]-n),{preIndx:r,nextIndex:s,interpolation:i}}e<t[c]?(a=c,c=Math.floor((o+a)/2)):t[c+1]<e&&(o=c,c=Math.floor((o+a)/2))}return null},L(t,e,n,r){const s=e.input.array,i=e.output.array,o=e.output.itemSize;(n<s[0]||n>s[s.length-1])&&(n=Math.max(s[0],Math.min(s[s.length-1],n))),n===s[s.length-1]&&(n=s[0]);const a=this.D(s,n);if(!a||!a.nextIndex)return null;const{preIndx:c,nextIndex:h,interpolation:u}=a;t.PREINDEX=c,t.NEXTINDEX=h,t.INTERPOLATION=u;const l=o*r;return t.PREVIOUS=i.subarray(t.PREINDEX*l,(t.PREINDEX+1)*l),t.NEXT=i.subarray(t.NEXTINDEX*l,(t.NEXTINDEX+1)*l),t},U(t,e,n,r){const s=e.INTERPOLATION,i=n[e.PREINDEX],o=n[e.NEXTINDEX];for(let n=0;n<3;n++){const a=e.PREVIOUS[r+n],c=(o-i)*e.PREVIOUS[2*r+n],h=e.NEXT[3+n],u=(o-i)*e.NEXT[n],l=(2*Math.pow(s,3)-3*Math.pow(s,2)+1)*a+(Math.pow(s,3)-2*Math.pow(s,2)+s)*c+(2*-Math.pow(s,3)+3*Math.pow(s,2))*h+(Math.pow(s,3)-Math.pow(s,2))*u;t[n]=l}return t},getAnimationClip(t,e,n,r){const s=t.nodes[e]&&t.nodes[e].weights;return Lt(Se,...Ce.TRANSLATION),Xt(Ee,...Ce.ROTATION),Lt(Ne,...Ce.SCALE),this.P(r,t,e,n,Se,Ee,Ne,s)},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 r=-1/0,s=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]>r&&(r=o[o.length-1]),o[0]<s&&(s=o[0])}const o=e.name||n;t.timeSpan[o]={max:r,min:s}}),t.timeSpan},getTimeSpanByName(t,e){const n=this.getTimeSpan(t);return n?ne(e)?n[e]:n[Object.keys(n)[0]]:null}};let ke=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(Yr){}t&&"undefined"!=typeof createImageBitmap&&(ke=!0)}const Be="undefined"==typeof document?null:document.createElement("canvas");class Le{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=Ae.read(e.buffer,e.byteOffset,e.byteLength);this.F(t,n,r)}else this.F(t,e);this.j=new Te(this.rootPath,this.gltf,this.glbBuffer),this.V()}V(){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.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}q(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.j.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then(e=>(t.KHR_techniques_webgl=e,t)):Promise.resolve(t)}load(t){t=t||{};const e=this.H(t),n=this.G(),r=this.$(),s=this.q();return Promise.all([e,n,r,s]).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,r){return Pe.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return Pe.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return ie(t)}static readInterleavedArray(t,e,n,r,s,i,o){return me(t,e,n,r,s,i,o)}F(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=ke?Fe.bind(this):this.options.requestImage||Ue,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new Me(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),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 _e(t,e,n,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate((t,e,n)=>{e.id="accessor_"+n},"accessors"),this.adapter.iterate((t,e,n)=>{e.id="image_"+n},"images"))}X(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(n=t.children[0])&&isFinite(n)||re(t.children[0])))return t;const r=t.children.map(t=>{const n=e[t];return n.nodeIndex=t,this.X(n,e)});t.children=r}var n;return t}H(t){return this.J(t).then(t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.X(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate((r,s,i)=>{const o={};s.name&&(o.name=s.name),s.nodes&&(o.nodes=s.nodes.map(e=>t[e])),this.gltf.scene===r&&(n=i),e.push(o)},"scenes");const r={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&&(r.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.I(this.gltf.materials);r.materials=t}return r})}J(t){return this.Z(t).then(()=>{const t=this.nodes={};return this.adapter.iterate((e,n)=>{const r=this.adapter.createNode(n,this.meshes,this.skins);t[e]=r},"nodes"),t})}K(){this.skins=[];const t=[];return this.adapter.iterate((e,n,r)=>{t.push(this.Y(n).then(t=>{t.index=r,this.skins.push(t)}))},"skins"),t}Y(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))}G(){const t=this.gltf.animations;return ne(t)?this.adapter.getAnimations(t):null}Z(t){this.meshes={};let e=[];return this.adapter.iterate((n,r,s)=>{e.push(this.W(r,t).then(t=>{t.index=s,this.meshes[n]=t}))},"meshes"),e=e.concat(this.K()),Promise.all(e)}W(t,e){const n=t.primitives.map(t=>this.tt(t,e)).filter(t=>!!t);return Promise.all(n).then(e=>{const n={};return se(n,t),n.primitives=e,n})}$(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const n in t)e.push(this.adapter.N(n));return Promise.all(e).then(e=>{if(this.transferables)for(let t=0;t<e.length;t++){const n=e[t].image.array;if(e[t]&&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={},r=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(n[r[t]]=e[t]);return n}return e})}tt(t,e){let n;const r=[],s=t.extensions;if(ne(t.targets))for(let e=0;e<t.targets.length;e++){const n=t.targets[e];for(const t in n){const s=this.adapter.accessor.T(`morphTargets_${t}_${e}`,n[t]);s&&r.push(s)}}if(s&&s.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}=s.KHR_draco_mesh_compression,a=this.gltf.bufferViews[i],c=this.j.M(a).then(n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:i}=a;const c=a.byteLength;i||(i=0);const h=new DataView(r,s+i,c),u={attributes:o,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(h,u).then(t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e})});r.push(c),n=Promise.all(r)}else{const e=t.attributes;for(const t in e){const n=this.adapter.accessor.T(t,e[t]);n&&r.push(n)}if(ne(t.indices)){const e=this.adapter.accessor.T("indices",t.indices);e&&r.push(e)}n=Promise.all(r)}return n.then(e=>{if(s&&s.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,r;const i={attributes:e.reduce((t,e)=>{if("indices"===e.name)n=e;else if(e.name.indexOf("morphTargets_")>-1)r=r||{},r[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:r,array:s}=e,i=s.length/r;for(let e=0;e<i;e++)for(let i=0;i<r;i++){const o=e*r+i;s[o]<t[i]&&(t[i]=s[o]),s[o]>n[i]&&(n[i]=s[o])}if(e.quantization){const r=e.quantization,s=r.range/(1<<r.quantizationBits),i=r.minValues;Ft(t,t,s),Ut(t,t,i),Ft(n,n,s),Ut(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),r&&(i.morphTargets=r),i.mode=ne(t.mode)?t.mode:4,ne(t.extras)&&(i.extras=t.extras),i})}}function Ue(t,e){const n=new Image;n.crossOrigin="",n.onload=()=>{if(!Be)return void e(new Error("There is no canvas to draw image!"));Be.width=n.width,Be.height=n.height;const t=Be.getContext("2d",{willReadFrequently:!0});t.drawImage(n,0,0,n.width,n.height);const r=t.getImageData(0,0,n.width,n.height),s={width:n.width,height:n.height,data:new Uint8Array(r.data)};e(null,s)},n.onerror=function(t){e(t)},n.src=t}let De,ze;function Fe(t,e){De||(De=new OffscreenCanvas(2,2),ze=De.getContext("2d",{willReadFrequently:!0}));let n=null;if(re(t))n=fetch(t).then(t=>t.arrayBuffer()).then(t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)});else{const e=new Blob([t]);n=createImageBitmap(e)}n.then(je.bind(this)).then(t=>{e(null,t)}).catch(t=>{console.warn(t),e(t)})}function je(t){let{width:e,height:n}=t;Ve(e)||(e=qe(e)),Ve(n)||(n=qe(n));const r=this.options.maxTextureSize;r&&(e=Math.min(r,e),n=Math.min(r,n)),De.width=e,De.height=n,ze.drawImage(t,0,0,e,n),t.close();const s=ze.getImageData(0,0,e,n);return{width:e,height:n,data:new Uint8Array(s.data)}}function Ve(t){return 0==(t&t-1)&&0!==t}function qe(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}const He="undefined"==typeof document?null:document.createElement("canvas");class Ge extends s.worker.Actor{constructor(t,e){super(t),this.mapId=e}initialize(t){t(null)}loadTile(t,e,n){let r=null;e&&e.arraybuffer&&(r=[e.arraybuffer]);const s={mapId:this.mapId,layerId:t,command:"loadTile",params:e};this.send(s,r,n)}abortTileLoading(t,e,n){const r={mapId:this.mapId,layerId:t,command:"abortTileLoading",params:{url:e}};this.broadcast(r,null,n)}addLayer(t,e,n){const r={actorId:this.actorId,mapId:this.mapId,layerId:t,command:"addLayer",params:{options:e}};this.broadcast(r,null,n)}removeLayer(t,e){const n={mapId:this.mapId,layerId:t,command:"removeLayer"};this.broadcast(n,null,e)}requestImage({url:t},e){const n=new Image;n.onload=()=>{if(!this.isActive())return;if(!He)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if($e(t.width)&&$e(t.height))return t;let e=t.width,n=t.height;$e(e)||(e=Xe(e));$e(n)||(n=Xe(n));const r=document.createElement("canvas");r.width=e,r.height=n,r.getContext("2d").drawImage(t,0,0,e,n);const s=t.src,i=s.lastIndexOf("/")+1,o=s.substring(i);return console.warn(`Texture(${o})'s size is not power of two, resize from (${t.width}, ${t.height}) to (${e}, ${n})`),r}(n);He.width=t.width,He.height=t.height;const r=He.getContext("2d",{willReadFrequently:!0});r.drawImage(t,0,0,t.width,t.height);const s=r.getImageData(0,0,t.width,t.height),i={width:t.width,height:t.height,data:new Uint8Array(s.data)};e(null,i,[i.data.buffer])},n.onerror=function(t){e(t)},n.src=t}}function $e(t){return 0==(t&t-1)&&0!==t}function Xe(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}class Je{constructor(t,e,n){this.et=t,this.max=e,this.currentSize=0,this.onRemove=n,this.reset()}reset(){if(this.data){const t=this.data.values();for(const e of t)this.onRemove(e)}return this.data=new Map,this.currentSize=0,this}clear(){this.reset(),delete this.onRemove}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const n=this.data.get(t);n&&n.node&&n.node.memorySize&&(this.currentSize-=n.node.memorySize),this.data.delete(t),this.data.set(t,e)}else this.data.set(t,e);return this}shrink(){if(this.currentSize>this.max){let t=!1;const e=this.data.keys();let n=e.next();for(;this.currentSize>this.max&&void 0!==n.value;){!t&&this.data.get(n.value).current&&(t=!0,console.warn(`layer(${this.et})'s maxGPUMemory is not enough, one or more current tiles will be discarded.`));const r=this.getAndRemove(n.value);r&&this.onRemove(r),n=e.next()}}}has(t){return this.data.has(t)}keys(){const t=new Array(this.data.size);let e=0;const n=this.data.keys();for(const r of n)t[e++]=r;return t}getAndRemove(t){if(!this.has(t))return null;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),e}get(t){if(!this.has(t))return null;const e=this.data.get(t);return this.data.delete(t),this.data.set(t,e),e}remove(t){if(!this.has(t))return this;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),this.onRemove(e),this}setMaxSize(t){return this.max=t,this.shrink(),this}getMemorySize(){let t=0;const e=this.data.values();for(const n of e){const e=n&&n.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t){const e=this.data.values();for(const n of e)n.current=t}}function Ze(t,e){if(t.scenes&&t.scenes.length)for(let n=0,r=t.scenes.length;n<r;n++){const r=t.scenes[n].nodes;for(let n=0,s=r.length;n<s;n++){const s=[];nn(r[n],s,t,e)}}}const Ke=[],Ye=[],Qe=[],We=[0,0,0],tn=Kt([]),en=[1,1,1];function nn(t,e,n,r){const s=e.slice(0);if(t.matrix)s.push(t.matrix);else if(t.rotation||t.translation||t.scale){const e=Et(Ke,t.translation||We),n=Ct(Ye,t.rotation||tn),r=Nt(Qe,t.scale||en);St(r,n,r);const i=St([],e,r);s.push(i)}if(t.children&&t.children.length)for(let e=0,i=t.children.length;e<i;e++)nn(t.children[e],s,n,r);if(void 0!==t.mesh){const e=t.mesh,i=n.meshes[e];if(i){const t=s.slice(0),o=i.primitives;for(let s=0,i=o.length;s<i;s++){const i=o[s];i&&(i.matrices=t,r(i,e,s,n))}}}}function rn(t,e,n){let{byteOffset:r,byteStride:s}=e;const{componentType:i,itemSize:o}=e,a=e.array.buffer,c=i?Le.getTypedArrayCtor(i):e.array.constructor;if(r=void 0===r?e.array.byteOffset:r,s=s||0,!s||s===o*c.BYTES_PER_ELEMENT&&r%c.BYTES_PER_ELEMENT==0){const e=new c(a,r+n*o*c.BYTES_PER_ELEMENT,o);return t.set(e),t}s||(s=o*c.BYTES_PER_ELEMENT);const h=new Uint8Array(a,s*n+r,o*c.BYTES_PER_ELEMENT);return new Uint8Array(t.buffer).set(h),t}function sn(t,e,n,r){t[4*e]=n[r],t[4*e+1]=n[r+4],t[4*e+2]=n[r+8],t[4*e+3]=n[r+12]}const on=new Array(3),an=new Array(3),cn=[40680631590769,40680631590769,40408299984661.445];function hn(t,e,n,r){const s=cn,i=Math.cos(n);on[0]=i*Math.cos(e),on[1]=i*Math.sin(e),on[2]=Math.sin(n),wn(on,on),zt(an,s,on);const o=Math.sqrt(Vt(on,an));var a,c,h;return c=an,h=o,(a=an)[0]=c[0]/h,a[1]=c[1]/h,a[2]=c[2]/h,Ft(on,on,r),Ut(t,an,on)}const un=[1/6378137,1/6378137,1/6356752.314245179],ln=[1/40680631590769,1/40680631590769,1/40408299984661.445],fn=new Array(3),dn=new Array(3),mn=new Array(3);function bn(t,e){const n=ln,r=function(t,e,n,r,s){const i=e[0],o=e[1],a=e[2],c=n[0],h=n[1],u=n[2],l=i*i*c*c,f=o*o*h*h,d=a*a*u*u,m=l+f+d,b=Math.sqrt(1/m),p=Ft(pn,e,b);if(m<s)return isFinite(b)?p:void 0;const g=r[0],y=r[1],w=r[2],v=gn;v[0]=p[0]*g*2,v[1]=p[1]*y*2,v[2]=p[2]*w*2;let T,_,M,O,A,x,I,S,E,N,C,R=(1-b)*yn(e)/(.5*yn(v)),P=0;do{R-=P,M=1/(1+R*g),O=1/(1+R*y),A=1/(1+R*w),x=M*M,I=O*O,S=A*A,E=x*M,N=I*O,C=S*A,T=l*x+f*I+d*S-1,_=l*E*g+f*N*y+d*C*w;P=T/(-2*_)}while(Math.abs(T)>1e-12);return t[0]=i*M,t[1]=o*O,t[2]=a*A,t}(fn,e,un,n,.1);let s=Gt(dn,r,n);s=wn(s,s);const i=Ht(mn,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=dt(Vt(i,e))*yn(i);return t[0]=lt(o),t[1]=lt(a),t[2]=c,t}const pn=new Array(3),gn=new Array(3);function yn(t){return Pt(t)}function wn(t,e){const n=e[0],r=e[1],s=e[2];let i=n*n+r*r+s*s;return i>0&&(i=Math.sqrt(i),t[0]=e[0]/i,t[1]=e[1]/i,t[2]=e[2]/i),t}function vn(t,e){return zt(e,t,ln),jt(e,e)}function Tn(t,e){const n=t[0],r=t[1],s=Math.cos(r),i=s*Math.cos(n),o=s*Math.sin(n),a=Math.sin(r);return e.x=i,e.y=o,e.z=a,jt(e,e)}var _n=Object.freeze({__proto__:null,radianToCartesian3:hn,cartesian3ToDegree:bn,normalizeCartesian:wn,geodeticSurfaceNormal:vn,geodeticSurfaceNormalCartographic:Tn});function Mn(t,e,n,r){n=n||0,r=r||n;const s=Math.abs(t-e);return s<=r||s<=n*Math.max(Math.abs(t),Math.abs(e))}function On(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const An="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function xn(t,e,n){const r=new Uint8Array(t,e,n);return An?JSON.parse(An.decode(r)):JSON.parse(bt(r))}function In(t,e,n){const r=new Uint8Array(t,e,n);return An?JSON.parse(An.decode(r)):JSON.parse(bt(r))}function Sn(t,e,n){return{offset:e,byteLength:n}}function En(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=Bn(i||"UNSIGNED_SHORT"),h=Pn(o);return{byteStride:0,byteOffset:s+n,itemSize:h,count:r*h,componentType:c,array:new a(e,n+s,r*h)}}function Nn(t,e,n,r){const s=En(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}function Cn(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a}=Bn(i||"UNSIGNED_SHORT"),c=Pn(o),h=new a(e,s,n*c);return 1===c?h[r]:h.subarray(r*c,r*c+c)}const Rn={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};function Pn(t){return t?Rn[t]:1}const kn={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function Bn(t){return kn[t]}function Ln(t){for(const e in kn)if(t===kn[e].ctor)return kn[e].type;throw new Error("unrecognized ctor:"+t)}function Un(t,e,n,r){const s=t,i=e.length/3;for(let t=0;t<i;t++)s[3*t]=e[3*t]/65535*r[0]+n[0],s[3*t+1]=e[3*t+1]/65535*r[1]+n[1],s[3*t+2]=e[3*t+2]/65535*r[2]+n[2];return s}function Dn(t,e,n){const r=t.getUint32(12,!0),s=t.getUint32(16,!0),i=t.getUint32(20,!0),o=t.getUint32(24,!0),a=t.buffer;let c,h={},u={},l=null;r>0&&(h=xn(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),i>0&&(u=In(a,e,i),e+=i);const f=Sn(0,e,o);return l=a.slice(f.offset,f.offset+f.byteLength),n.push(l),{featureTable:h,featureTableBin:c,batchTable:u,batchTableBin:l}}const zn={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}},Fn={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},jn={},Vn={east:[],north:[],up:[],west:[],south:[],down:[]};let qn=[],Hn=[],Gn=[];const $n=[0,0,0];function Xn(t,e,n){return n[0]=t[0],n[1]=t[1],n[2]=t[2],n[3]=t[3],n[4]=t[4],n[5]=t[5],n[6]=t[6],n[7]=t[7],n[8]=t[8],n[9]=t[9],n[10]=t[10],n[11]=t[11],n[12]=e[0],n[13]=e[1],n[14]=e[2],n[15]=t[15],n}const Jn=function(t,e){const n=zn[t][e];let r;const s=t+e;return jn[s]?r=jn[s]:(r=function(r,s,i){if(function(t,e){var n=t[0],r=t[1],s=t[2],i=e[0],o=e[1],a=e[2];return Math.abs(n-i)<=1e-6*Math.max(1,Math.abs(n),Math.abs(i))&&Math.abs(r-o)<=1e-6*Math.max(1,Math.abs(r),Math.abs(o))&&Math.abs(s-a)<=1e-6*Math.max(1,Math.abs(s),Math.abs(a))}(r,$n))Bt(qn,Fn[t]),Bt(Hn,Fn[e]),Bt(Gn,Fn[n]);else if(Mn(r[0],0,1e-14)&&Mn(r[1],0,1e-14)){const s=dt(r[2]);Bt(qn,Fn[t]),"east"!==t&&"west"!==t&&Ft(qn,qn,s),Bt(Hn,Fn[e]),"east"!==e&&"west"!==e&&Ft(Hn,Hn,s),Bt(Gn,Fn[n]),"east"!==n&&"west"!==n&&Ft(Gn,Gn,s)}else{vn(r,Vn.up);const s=Vn.up,i=Vn.east;i[0]=-r[1],i[1]=r[0],i[2]=0,jt(Vn.east,i),qt(Vn.north,s,i),Ft(Vn.down,Vn.up,-1),Ft(Vn.west,Vn.east,-1),Ft(Vn.south,Vn.north,-1),qn=Vn[t],Hn=Vn[e],Gn=Vn[n]}return i[0]=qn[0],i[1]=qn[1],i[2]=qn[2],i[3]=0,i[4]=Hn[0],i[5]=Hn[1],i[6]=Hn[2],i[7]=0,i[8]=Gn[0],i[9]=Gn[1],i[10]=Gn[2],i[11]=0,i[12]=r[0],i[13]=r[1],i[14]=r[2],i[15]=1,i},jn[s]=r),r}("east","north"),Zn=[],Kn=[],Yn=[],Qn=[],Wn=[],tr=[],er=[],nr={x:0,y:0},rr={x:0,y:0},sr=Math.PI/180;const{getTextureMagFilter:ir,getTextureMinFilter:or,getTextureWrap:ar,getMaterialType:cr,getMaterialFormat:hr,getPrimitive:ur,getUniqueREGLBuffer:lr}=n.reshader.REGLHelper,fr=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],dr=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:mr,logoutIBLResOnCanvas:br,getIBLResOnCanvas:pr,getPBRUniforms:gr}=n.reshader.pbr.PBRUtils,yr={factor:0,units:0},wr=[1,1,1,1],vr=[0,0,0],Tr={specularStrength:0,materialShininess:1},_r=[1,1,1],Mr=n.mat4.identity([]),Or=[0,0],Ar=t=>t.material instanceof n.reshader.PhongMaterial,xr=t=>t.material instanceof n.reshader.pbr.StandardMaterial,Ir=[],Sr=new s.Coordinate(0,0),Er=new s.Point(0,0),Nr=new s.Point(0,0),Cr=new s.Point(0,0),Rr=[],Pr=[],kr=[],Br=[],Lr=[],Ur=[],Dr=[],zr=[0,0,0],Fr=[],jr=[],Vr={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"},qr=[0,1,1,2,2,3,3,0,0,4,1,5,2,6,3,7,4,5,5,6,6,7,7,4],Hr=function(t,e){const n=2*Math.PI/t,r=[],s=[];for(let s=0;s<=t;s++){const t=Math.cos(n*s)*e,i=Math.sin(n*s)*e,o=0;r[3*s]=t,r[3*s+1]=i,r[3*s+2]=o}for(let s=t;s<=2*t;s++){const t=Math.cos(n*s)*e,i=Math.sin(n*s)*e,o=0;r[3*s]=o,r[3*s+1]=t,r[3*s+2]=i}for(let s=2*t;s<=3*t;s++){const t=Math.cos(n*s)*e,i=Math.sin(n*s)*e,o=0;r[3*s]=t,r[3*s+1]=o,r[3*s+2]=i}const i=r.length/3-1;for(let e=0;e<i;e++)e!==t-1&&e!==2*t-1&&(s[2*e]=e,s[2*e+1]=e+1);return r.push(0,0,0),r.push(e,0,0),r.push(0,e,0),r.push(0,0,e),s.push(i+1,i+2),s.push(i+1,i+3),s.push(i+1,i+4),{vertices:r,indices:s}}
19
19
  /*!
20
- * @maptalks/gl v0.89.3
20
+ * @maptalks/gl v0.91.0
21
21
  * LICENSE : UNLICENSED
22
22
  * (c) 2016-2023 maptalks.com
23
- */(i,a)),c.generateBuffers(this.nt,{excludeElementsInVAO:e}),c}pe(t,e,r,s){const i=n.mat4.identity(t),o=this.getMap();Pn.x=r[0],Pn.y=r[1];const a=this._prjToPoint(Pn),c=this.xe(),h=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes());Pn.x=e[0],Pn.y=e[1];const u=this.be();let f=this.Y.options.offset;b(f)&&(f=f.call(this.Y,Pn));const l=this.Y.vt(s).heightOffset||0;return n.vec3.set(Fn,a.x-f[0],a.y-f[1],u*r[2]+u*l),n.mat4.translate(i,i,Fn),n.vec3.set(c,h,h,u),n.mat4.scale(i,i,c),i}oe(t,e){const r=n.mat4.identity(t),s=this.getMap(),i=this.xe();Pn.x=e[0],Pn.y=e[1];const o=s.distanceToPointAtRes(100,100,s.getGLRes(),Pn);let a;return a=s.altitudeToPoint?this.xt:o.y/100,n.vec3.set(i,o.x/100*1.01,o.y/100*1.01,a),n.mat4.scale(r,r,i),r}_t(){const t={x:0,y:0,width:()=>this.tt?this.tt.width:1,height:()=>this.tt?this.tt.height:1};this.$t=new n.reshader.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\n\n\n\nuniform vec3 color;\n\n\n\nvoid main() {\n\n gl_FragColor = vec4(color, 1.0);\n\n}\n\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.mat4.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],r=[];this.Gt=new n.reshader.MeshShader({vert:"const float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n#include <draco_decode_vert>\n\nvoid main() {\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_POSITION\n\n vec3 localPos = decode_getPosition(POSITION);\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.mat4.multiply(r,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>n.mat3.fromMat4(e,r.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const s=this.Ot();this.Ht=new n.reshader.PhongShader({extraCommandProps:s}),this.Vt=new n.reshader.pbr.StandardShader({extraCommandProps:s});const i=this.Y;_n(i.getRenderer().canvas,this.nt,i.getMap()),this.picking=new n.reshader.FBORayPicking(this.rt,{vert:this.Vt.vert,extraCommandProps:s,uniforms:this.Vt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}Ot(){return{viewport:{x:0,y:0,width:()=>this.tt?this.tt.width:1,height:()=>this.tt?this.tt.height:1},cull:{enable:!0},stencil:{enable:!0,func:{cmp:(t,e)=>e.meshProperties.isLeaf?"always":">=",ref:(t,e)=>e.meshProperties.level},opFront:{fail:"keep",zfail:"keep",zpass:"replace"},opBack:{fail:"keep",zfail:"keep",zpass:"replace"}},depth:{enable:!0,range:[0,1],func:(t,e)=>e.meshProperties.depthFunc||"<"},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},polygonOffset:{enable:!0,offset:(t,e)=>e.meshProperties.polygonOffset}}}Wt(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}jt(t){const e=this.getMap(),r=e.getLightManager(),s=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:n.vec3.normalize(s,s)}}St(){const t=this.getMap(),e=this.Y.getRenderer().canvas,{iblTexes:n,dfgLUT:r}=On(e),s=xn(t,n,r),i=this.Y.getRenderer().getMaskUniforms();return y(s,{czm_lightDirectionEC:s.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),y(s,i),s}Ae(t,e,r,s,i){const o=e.materials&&e.materials[t];if(!o||!o.baseColorTexture&&!o.pbrMetallicRoughness)return null;const a=y({},s);if(o.baseColorTexture){const t=e.textures[o.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.M(t)),a.baseColorFactor=t&&t.image.color||o.baseColorFactor||[1,1,1,1],n&&(a.baseColorTexture=n)}else{if(o.normalTexture){const t=this.M(e.textures[o.normalTexture.index]),n=o.normalTexture.scale||1;a.normalTexture=t,a.normalMapFactor=n}if(o.occlusionTexture){const t=this.M(e.textures[o.occlusionTexture.index]),n=o.occlusionTexture.strength||1;a.occlusionTexture=t,a.occlusionFactor=n}if(o.emissiveTexture){const t=this.M(e.textures[o.emissiveTexture.index]);a.emissiveTexture=t}o.emissiveFactor&&(a.emissiveFactor=o.emissiveFactor);const t=o.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(a.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];r.image&&r.image.color?a.baseColorFactor=a.baseColorFactor?n.vec4.multiply(a.baseColorFactor,a.baseColorFactor,r.image.color):r.image.color:(a.baseColorTexture=this.M(r),a.baseColorTexture.getREGLTexture(this.nt))}if(p(t.metallicFactor)||(a.metallicFactor=t.metallicFactor),p(t.roughnessFactor)||(a.roughnessFactor=t.roughnessFactor),o.metallicRoughnessTexture){const t=this.M(e.textures[o.metallicRoughnessTexture.index]);a.metallicRoughnessTexture=t}}}if(o.s3mMaterial)return new n.reshader.Material(a);if(a.environmentExposure=i,a.alphaTest=.1,o.extensions&&o.extensions.KHR_materials_unlit)return a.environmentExposure=1,a.ambientColor=[1,1,1],a.light0_diffuse=[0,0,0,0],a.lightSpecular=[0,0,0],new n.reshader.PhongMaterial(a);let c=new n.reshader.pbr.StandardMaterial(a);"phong"===r&&(c=n.reshader.PhongMaterial.convertFrom(c));const h=o.pbrMetallicRoughness,u=h&&h.baseColorTexture&&h.baseColorTexture.extensions;return u&&u.KHR_texture_transform&&(c.set("khr_offset",u.KHR_texture_transform.offset||[0,0]),c.set("khr_rotation",u.KHR_texture_transform.rotation||0),c.set("khr_scale",u.KHR_texture_transform.scale||[1,1])),c.once("complete",this.gt),c}M(t){const e={type:t.type?pn(t.type):"uint8",format:t.format?yn(t.format):"rgba",flipY:!!t.flipY},r=t.image;r.array?e.data=r.array:r.mipmap&&(e.mipmap=r.mipmap),e.width=r.width,e.height=r.height;const s=t.sampler||t.texture&&t.texture.sampler;return s&&(s.magFilter&&(e.mag=ln(s.magFilter)),s.minFilter&&(e.min=dn(s.minFilter)),s.wrapS&&(e.wrapS=mn(s.wrapS)),s.wrapT&&(e.wrapT=mn(s.wrapT))),new n.reshader.Texture2D(e,this.bt)}Tt({target:t}){const e=t.Oe,n=this.st[e];if(n.count--,!n.count){const t=n.meshes;this.ot[e]=t,delete this.st[e];const r=t.me;delete t.me,r(null,{mesh:n.meshes,id:e})}}xe(){return Mn}Jt(t){return this.Y.Jt(t)}te(t,e){const n=this.getMap();return n.getGLZoom?n.distanceToPoint(t,e,n.getGLZoom()):n.distanceToPointAtRes(t,e,n.getGLRes())}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),Un)}he(t){return"Y"===t?Tn:"X"===t?wn:Nn}pick(t,e,n=3){const r=this.Y;if(!r||!r.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const s=this.getMap(),i=this.St(),o=this.picking;o.render(this.lt.getMeshes().filter(t=>!t.bloom),i,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,n,i,{viewMatrix:s.viewMatrix,projMatrix:s.projMatrix,returnPoint:r.options.pickingPoint}));const{meshId:c,pickingId:h,point:u,coordinate:f}=a,l=(0===c||c)&&o.getMeshAt(c);if(!l||!l.geometry)return[];const d=l.properties;u&&u.length&&(u[0]=Math.round(1e5*u[0])/1e5,u[1]=Math.round(1e5*u[1])/1e5,u[2]=Math.round(1e5*u[2])/1e5);const m={batchId:h};if(r.options.debug&&(m.debugInfo=d),d&&d.batchTable){const{batchTable:t,batchTableBin:e,count:n}=d,r=h;for(const s in t)void 0!==t[s].byteOffset?m[s]=De(t[s],e,n,r):m[s]=t[s][r]}return[{service:l.properties.serviceIndex,data:m,point:u,coordinate:f}]}Mt(t){let e=new Set;for(let n=0,r=t.length;n<r;n++){const r=t[n].data.node;this.Nt(r)&&e.add(r.Lt)}e=Array.from(e),e.sort();const n=new Map,r=e.length;for(let t=0;t<r;t++)n.set(e[t],t);return n}highlight(t){this.Rt=t;const e=this.Y.getRenderer();this.Pt=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.Rt=null;const t=this.Y.getRenderer();this.Pt=t.getFrameTimestamp(),t.setToRedraw(!0)}showOnly(t){this.Ut=t;const e=this.Y.getRenderer();this.Bt=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelShowOnly(){this.Ut=null;const t=this.Y.getRenderer();this.Bt=t.getFrameTimestamp(),t.setToRedraw(!0)}Ie(){if(!this.It)return[];const t={},e=[];for(const n in this.It){const r=this.It[n];if(r)for(let n=0;n<r.length;n++){const s=r[n],i=s&&s.geometry;if(!s||!i)continue;const o=s.properties.serviceIndex;t[o]||(t[o]=new Set);const a=i.properties.batchIdData;if(a)for(let n=0;n<a.length;n++)t[o].has(a[n])||(e.push({id:a[n],service:o}),t[o].add(a[n]))}}return e}hasIBL(){const t=this.getMap().getLightManager();return!!(t&&t.getAmbientResource())}}const Gn=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")},zn=Gn(),qn=zn.gl_trans__coders=zn.gl_trans__coders||{};function Xn(t,e){if(e)for(let n=0;n<e.length;n++){t[e[n].id||e[n].index]=e[n]}}qn.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=zn.gl_trans__coders=zn.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${Gn.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in s)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(i+='tran_____scoders["'+t+'"] ='+s[t].toString()+"\n;");return i+="\n"+e.substring(r.length),i},qn.registerTranscoder=function(t,e){qn[t]=e},qn.getTranscoder=function(t){return qn[t]};const $n=[];class Wn{constructor(t,e,n,r){this.Se=t,this.Et=e,this.Me=r,this.Ne=n.version,t.indexOf("i3s:tileset:")<0?(this.Ne<=1.6?this.ve="root":this.ve=0,n.version=this.Ne):(this.ve=t.substring("i3s:tileset:".length),this.Ne>1.6&&(this.ve=parseInt(this.ve))),this.Se=t,this.Ee=n}load(){const t=this.Ee,e=t.layerScene.baseUrl;if(this.Ne<=1.6)return t[this.ve]&&t[this.ve].lodSelection?(this.Ce=t[this.ve],this.Re()):new Promise(n=>{let r=e+"/nodes/"+this.ve;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Me(this.Et,r,()=>{this.Ce=t[this.ve],n(this.Re())})});if(this.Ne>=1.7){if(t[this.ve])return this.Ce=t[this.ve],this.Re();const n=Math.floor(this.ve/t.nodesPerPage);return new Promise(r=>{let s=e+"/nodepages/"+n;t.layerScene.eslpk&&(s+=".json"),this.Me(this.Et,s,()=>{this.Ce=t[this.ve],r(this.Re())})})}return null}getTileset(){return this.Pe}getChildrenURL(){return this.Ue}Re(){const t=this.Ee,e=t.layerScene.baseUrl,n=this.Ce.children,r=[],s={};if(n)for(let i=0;i<n.length;i++)if(this.Ne<=1.6){const o=n[i].id;if(t[o])continue;const a=o;s[a]||(s[a]=new Promise(n=>{let r=e+"/nodes/"+a;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Me(this.Et,r,()=>{n()})}),r.push(s[a]))}else{const o=n[i];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);s[a]||(s[a]=new Promise(n=>{let r=e+"/nodepages/"+a;t.layerScene.eslpk&&(r+=".json"),this.Me(this.Et,r,()=>{n()})}),r.push(s[a]))}return r.length?Promise.all(r).then(()=>this.Be()):this.Be()}Be(){return Promise.resolve(this.Le())}De(t){Xn(this.Ee,t)}Le(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Fe(this.Ce,!0)}}Fe(t){const e=this.Ne,n=this.Ee,r=t,s=r.obb,i=r.mbs,o={};let a;if(i)a=Kn([],i[0],i[1],i[2]),o.sphere=[...a,i[3]];else if(s){a=Kn([],s.center[0],s.center[1],s.center[2]);const t=function(t,e,n){const r=function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,h=n*o,u=r*o,f=r*a,l=s*o,d=s*a,m=s*c,p=i*o,y=i*a,b=i*c;return t[0]=1-f-m,t[3]=u-b,t[6]=l+y,t[1]=u+b,t[4]=1-h-m,t[7]=d-p,t[2]=l-y,t[5]=d+p,t[8]=1-h-f,t}([],n);return r[0]=r[0]*e[0],r[1]=r[1]*e[0],r[2]=r[2]*e[0],r[3]=r[3]*e[1],r[4]=r[4]*e[1],r[5]=r[5]*e[1],r[6]=r[6]*e[2],r[7]=r[7]*e[2],r[8]=r[8]*e[2],[...t,...r]}(a,s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],n=t[4]+t[7]+t[10],r=t[5]+t[8]+t[11];G($n,e,n,r);const i=Y($n);o.sphere=[...a,i]}let c=1/0,h=0;if(r.mbs?h=r.mbs[3]:r.obb&&(h=Math.max(Math.max(r.obb.halfSize[0],r.obb.halfSize[1]),r.obb.halfSize[2])),void 0!==r.lodThreshold)if("maxScreenThresholdSQ"===n.lodSelectionMetricType){c=h/(Math.sqrt(r.lodThreshold)/(.25*Math.PI))}else console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==r.lodSelection)for(let t=0;t<r.lodSelection.length;t++)"maxScreenThreshold"===r.lodSelection[t].metricType&&(c=h/r.lodSelection[t].maxError);(c===1/0||isNaN(c))&&(c=1e5);const u=16*c,f=U([]),l=r.children;let d;if(l){d=[];const t=this.Ee;for(let n=0;n<l.length;n++){const r=e<=1.6?l[n].id:l[n];if(!t[r]){d=null;break}d.push(this.Fe(t[r]))}}const m={refine:"REPLACE",boundingVolume:o,transform:f,geometricError:u};return e<=1.6?t.lodSelection?t.geometryData&&(m.content={uri:"i3s:mesh:"+(t.id||t.index)}):m.content={uri:"i3s:tileset:"+(t.id||t.index)}:l&&l.length&&!d?m.content={uri:"i3s:tileset:"+(t.id||t.index)}:r.mesh&&(m.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(m.children=d),m}getJSON(){return this.Ce}}function Kn(t,e,n,r){return pe(t,w(e),w(n),r)}const Qn=!!qn.ktx2,Zn=n.mat4.identity([]),Jn=(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){const t=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(t instanceof WebAssembly.Module)return new WebAssembly.Instance(t)instanceof WebAssembly.Instance}}catch(t){}return!1})();function Yn(t){return t.indexOf("i3s:mesh")>=0}const tr="i3s:mesh:".length;function er(t,e,n,r,s){const i=e.layerScene.eslpk,o=function(t,e){const n=e.substring(tr);return t>=1.7?parseInt(n):n}(e.version,t),a=e[o],c=e.layerScene.baseUrl,h=[];let u=!1;const f=Zn;let l,d;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;if(!t)return null;let n=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;i&&(n+=".bin");const r={geometry:{url:n,info:e.layerScene.store.defaultGeometrySchema}};let s=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(s){const t=e.layerScene.store.textureEncoding[0];let n;n="image/jpeg"===t?"jpg":"png",i&&(s+="."+n);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+s,factor:1,format:n,mimeType:t},metallicFactor:0}};r.material=o}h.push(r)}else{l=a.mesh.geometry,d=a.mesh.material;const t=e.layerScene.geometryDefinitions[l.definition],{geometryBuffers:o}=t;u=r&&2===o.length;const f=qn.draco&&u?o[1]:o[0],m=qn.draco&&u?1:0;let p=c+`/nodes/${l.resource}/geometries/`+m;i&&(p+=".bin");const y={geometry:{url:p,info:f}};if(s&&Jn&&u&&!qn.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const b=e.layerScene.materialDefinitions,T=e.layerScene.textureSetDefinitions;let w,_=0;if(d&&(_=b[d.definition]),b){w=function(t,e,n,r,s,i){const o=JSON.parse(JSON.stringify(t));return function t(e,n,r,s,i,o){for(const a in e)if(e[a]&&e[a].textureSetDefinitionId>=0){const t=n[e[a].textureSetDefinitionId],c="images/"+t.formats[0].format,h=nr(t.formats,i),u={url:r+`/nodes/${s}/textures/${h.name}`,factor:void 0===e[a].factor?1:e[a].factor,format:h.format,mimeType:c};if(o){let t="";switch(h.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=h.format}u.url+="."+t}e[a]=u}else g(e[a])&&t(e[a],n,r,s,i,o)}(o,e,n,r,s,i),o}(_,T,c,d.resource,n,e.layerScene.eslpk)}else w={pbrMetallicRoughness:{metallicFactor:0}};y.material=w,h.push(y)}return{dracoCompression:u,meshes:h,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:f}}function nr(t,e){for(let n=0;n<=t.length;n++){const r=t[n].format;if("dds"===r&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[n];if("jpg"===r||"png"===r)return t[n];if("ktx2"===r&&Qn)return t[n]}return null}const rr=[];class sr extends(n.MaskRendererMixin(s.renderer.CanvasRenderer)){constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new ee(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.ke={},this.He=[],this.Me=this.Ve.bind(this)}getAnalysisMeshes(){if(!this.painter)return rr;const t=this.painter.getPaintedMeshes();if(!t)return rr;const e=[],{b3dmMeshes:n,pntsMeshes:r,i3dmMeshes:s}=t;return n.length&&C(e,n),r.length&&C(e,r),s.length&&C(e,s),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.He.length||super.needToRedraw())}getFrameTimestamp(){return this.je}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){this.je=t;const n=this.prepareCanvas();if(n&&!n.intersects(this.canvasExtent2D))return void this.completeRender();const{root:r,tiles:s}=this.layer.getTiles(),i=s.length;if(!s||!i)return void this.completeRender();this.Ge(),this.ze();const{selectedTiles:o,leaves:a,requests:c}=this.qe(r,s);c.length&&this.loadTiles(c),this.Xe(o,a,e),this.$e(),c.length||this.completeRender()}qe(t,e){const n=this.layer.getRootTiles();let r=[];this.We();let s=0;const i=this.Ke(),o={};let a=!1,c=!1;for(let t=0;t<e.length;t++){const i=e[t],h=i.node;if(o[h.id])continue;const u=n[h.Et];o[h.id]=1;let f=!1;const l=this.getCachedTile(h.id);if(this.Qe(h.id)?(s++,f=c=!0,this.tilesLoading[h.id].current=!0):l?(this.getTileOpacity(l)<1&&(f=c=!0),(!i.node.Ze||u.isS3M||!i.node.children||i.node.Ze<=500)&&(a=!0,i.selected=!0,i.data=l)):this.painter.has(h)||(f=c=!0,r.push(h)),!f)continue;if(this.Je(i))a=!0;else{this.Ye(i).length&&(a=!0)}}let h=[],u={};if(a&&({selectedTiles:h,leaves:u}=this.tn(t)),r.length>1&&(r.sort(ir),i)){const t=i-s;r=t>0?r.slice(0,t):[]}return{loading:c,requests:r,selectedTiles:h,leaves:u}}tn(t){const e=[],n={};let r;const s=[t],i=[];for(;s.length>0||i.length>0;){if(i.length>0){const t=i[i.length-1];if(t.en===s.length){i.pop(),t===r&&(t.leave=!0,n[t.node.id]=1),e.push(t);continue}}const t=s.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)n[t.node.id]=1,t.selectionDepth=i.length,e.push(t);else{if(t.selectionDepth=i.length,r=t,0===o.length){t.leave=!0,n[t.node.id]=1,e.push(t);continue}i.push(t),t.en=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}Je(t){if(!t.parent)return null;let e=t.parent;for(;e&&e.level>=0;){const t=e.node.id;if(this.tileCache.has(t))return e.selected=!0,e.data=this.tileCache.get(t),e;e=e.parent}return null}Ye(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.Lt+1,r=[t.node];for(;r.length>0;){const s=r.pop().children;for(let i=0,o=s.length;i<o;i++){if((!s[i].content||!s[i].content.url)&&s[i].children&&s[i].children.length){r.push(s[i]);continue}const o=s[i].id;if(this.tileCache.has(o)){const n=this.layer.nn(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].Lt<=n&&r.push(s[i])}}return e}Xe(t,e,n){this.tileCache.markAll(!1);for(let e=0,n=t.length;e<n;e++){const n=t[e].data;n.current=!0,this.tileCache.add(t[e].node.id,n)}this.tileCache.shrink();const r={tiles:t,leaves:e};this.onDrawTileStart(r);const s=this.painter.paint(t,e,n);this.onDrawTileEnd(r),s&&this.layer.fire("canvasisdirty",{renderCount:s})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,n=t.length;e<n;e++){const n=t[e];this.tilesLoading[n.id]={current:!0,node:n},this.loadTile(n)}}loadTile(t){let e=t.content.url;if(v(e)){const n=E(e);return this.rn(e,n,t),null}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const n=t.Et,r=this.sn[n];return new Wn(e,n,r,this.Me).load().then(n=>{this.onTilesetLoad(n,t,e)})}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Yn(e)&&(e=t.baseUrl+e);const n=this.layer.vt(t.Et);if(n.ajaxInMainThread){let r=n.urlParams;r&&(r=(e.indexOf("?")>0?"&":"?")+r);let s=xt.getArrayBuffer(e+(r||""),n.fetchOptions);const i=s.xhr;s=s.then(n=>{delete this.ke[e],n?this.rn(e,n.data,t):this.onTileError(null,t,e)}).catch(n=>{delete this.ke[e],this.onTileError(n,t,e)}),this.ke[e]=i}else this.rn(e,null,t);return null}rn(t,e,r){let s=this.o;s||(s=n.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=s);const i=this.layer.vt(r.Et);i.isSuperMapiServer&&(t=function(t,e){const n=t.substring(e.length).split("/"),r=[];for(let t=0;t<n.length;t++)r.push(encodeURIComponent(n[t]));return e+r.join("/")}(t,r.baseUrl));const o={url:t=this.layer.getTileUrl(t,r.baseUrl,this.layer.in[r.Et]),arraybuffer:e,rootIdx:r.Et,upAxis:r.ue,transform:r.matrix,supportedFormats:s};if(Yn(t)){const e=this.sn[r.Et];if(o.i3sInfo=er(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},r,t)}o.service=y({},i),i.offset&&delete o.service.offset,this.workerConn.loadTile(this.layer.getId(),o,(e,n)=>{if(e)return void this.onTileError(e,r,t);const{magic:s}=n;"b3dm"===s||"pnts"===s||"i3dm"===s||"cmpt"===s?this.He.push({data:n,tile:r}):this.onTilesetLoad(n,r,t)})}ze(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.He.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.He.shift(),{magic:r}=t;"b3dm"===r?this.painter.createB3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.an(t,e,n,r)}):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,(n,{mesh:r})=>{this.an(t,e,n,r)}):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.an(t,e,n,r)}):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,(n,{mesh:r})=>{this.an(t,e,n,r)}),n++}}an(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this.cn(r);e.memorySize=n,this.onTileLoad(t,e)}}cn(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this.cn(t[n]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.hn(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(this.layer.Te=t.extensions&&t.extensions["s3m:VertexCompressionType"],t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.un(t,e,n):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,n)))}onTileError(t,e,n){if(!this.layer)return;const r=n||e.content.url;console.warn("failed to load 3d tile: "+r),console.warn(t),delete this.tilesLoading[e.id],this.ln(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}ln(t,e){const n={loadTime:s.Util.now(),current:!0,error:e,node:t};this.tileCache.add(t.id,n)}hn(t){const e={loadTime:s.Util.now(),current:!0,node:t};this.tileCache.add(t.id,e)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.vt(t.node.Et).ajaxInMainThread){const t=this.ke[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.ke[e]}We(){if(this.tilesLoading)for(const t in this.tilesLoading)this.tilesLoading[t].current=!1}deleteTile(t){this.painter.deleteTile(t)}createContext(){const t=this.layer,e=t.options.glOptions||{alpha:!0,depth:!0,stencil:!0,preserveDrawingBuffer:!0,antialias:t.options.antialias},r=this.canvas.gl&&this.canvas.gl.wrap;r?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.dn(this.canvas,e)),this.regl=this.regl||n.createREGL({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),r&&(this.canvas.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height)),this.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height),this.painter=new jn(this.regl,t),this.layer.mn()}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Jt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=y({},n),delete n.offset,n.projection=t.getSpatialReference().getProjection().code;const r=this.layer.getId();e.addLayer(r,n,t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))})}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),t=>{if(t)throw t}),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.$e(!0),this.tileCache.reset(),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}$e(t){this.pn||(this.pn=Date.now());const e=Date.now();if(t||!(e-this.pn<this.layer.options.retireInterval)){this.pn=e;for(const e in this.tilesLoading){const n=this.tilesLoading[e];!t&&n.current||this.abortTileLoading(n)}}}Ke(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}dn(t,e){const n=["webgl","experimental-webgl"];let r=null;for(let s=0;s<n.length;++s){try{r=t.getContext(n[s],e)}catch(t){}if(r)break}return r}Qe(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,n){return Be(t,e,0,n)}Ge(){if(!this.yn)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const n=[];for(const r in this.yn){const s=this.yn[r];if("pending"===s.status)continue;s.status="pending";const i=s.rootIdx;if(n.push(xt.getJSON(r).then(t=>{delete this.yn[r];const e=this.sn[i];if(e){t.nodes?Xn(e,t.nodes):(e[t.id]=t,Xn(e,t.children));for(let t=0;t<s.length;t++)s[t]();this.setToRedraw()}else this.setToRedraw()})),e++,e>=t)break}n.length&&Promise.all(n)}Ve(t,e,n){this.yn||(this.yn={}),this.yn[e]=this.yn[e]||[],this.yn[e].rootIdx=t,this.yn[e].push(n),this.setToRedraw()}un(t,e,n){this.sn||(this.sn=[]);const r=e.Et;this.sn[r]||(this.sn[r]={});const s=this.sn[r],i=this.layer.vt(r);t.layers&&(t=t.layers[0],"/"!==n[n.length-1]&&(n+="/"),n+="layers/0"),s.version=+(i.i3sVersion||t.store.version),function(t,e,n,r,s,i){if(!s.layerScene){s.layerScene=t,s.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,s.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=r;s.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0;if(e.endsWith(".json")){const t=r.lastIndexOf("/");e=t<0?"./":r.substring(0,t)}s.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new Wn(r,e,s,i).load()}(t,r,0,n,s,this.Me).then(t=>{this.onTilesetLoad(t,e,n)})}pick(t,e,n){if(!this.painter)return[];const r=this.pickingFBO,{width:s,height:i}=this.canvas;return!this.pickingFBO||r.width===s&&r.height===i||r.resize(s,i),this.painter.pick(t,e,n&&n.tolerance)}highlight(t){if(this.Rt||(this.Rt=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Rt[n];r||(r=this.Rt[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Rt[e];n||(n=this.Rt[e]=new Map),n.set(t.id,t)}this.painter.highlight(this.Rt)}cancelHighlight(t,e){if(!this.Rt)return;const n=this.Rt[t];if(n){if(Array.isArray(e))for(let t=0;t<e.length;t++)n.delete(e[t]);else n.delete(e);n.size||(this.Rt[t]=null),this.painter.highlight(this.Rt)}}cancelAllHighlight(){delete this.Rt,this.painter.cancelAllHighlight()}showOnly(t){if(this.Ut||(this.Ut=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Ut[n];r||(r=this.Ut[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Ut[e];n||(n=this.Ut[e]=new Map),n.set(t.id,t)}this.painter.showOnly(this.Ut)}cancelShowOnly(){delete this.Ut,this.painter.cancelShowOnly()}Ie(){return this.painter?this.painter.Ie():[]}}function ir(t,e){return t.qt-e.qt}function or(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function ar(t,e,n){return Math.sqrt(function(t,e,n){const r=q(cr,n,t),s=or(hr,e,0),i=or(ur,e,1),o=or(fr,e,2),a=Y(s),c=Y(i),h=Y(o);W(s,s),W(i,i),W(o,o);const u=lr;u[0]=K(r,s),u[1]=K(r,i),u[2]=K(r,o);let f,l=0;u[0]<-a?(f=u[0]+a,l+=f*f):u[0]>a&&(f=u[0]-a,l+=f*f);u[1]<-c?(f=u[1]+c,l+=f*f):u[1]>c&&(f=u[1]-c,l+=f*f);u[2]<-h?(f=u[2]+h,l+=f*f):u[2]>h&&(f=u[2]-h,l+=f*f);return l}(t,e,n))}const cr=[],hr=[],ur=[],fr=[],lr=[];const dr=2*Math.PI;class mr{constructor(t,e,n,r){this.west=t,this.south=e,this.east=n,this.north=r}static contains(t,e){let n=e[0];const r=e[1],s=t.west;let i=t.east;return i<s&&(i+=dr,n<0&&(n+=dr)),(n>s||ve(n,s,1e-14))&&(n<i||ve(n,i,1e-14))&&r>=t.south&&r<=t.north}static southwest(t,e){return e[0]=t.west,e[1]=t.south,e[2]=0,e}static northeast(t,e){return e[0]=t.east,e[1]=t.north,e[2]=0,e}static southeast(t,e){return e[0]=t.east,e[1]=t.south,e[2]=0,e}static northwest(t,e){return e[0]=t.west,e[1]=t.north,e[2]=0,e}}const pr=[0,0,1];function yr(t,e){return pe(e,t[0],t[1],t[2])}class br{constructor(t,e){this.normal=n.vec3.copy([],t),this.distance=e}static fromPointNormal(t,e,r){const s=-n.vec3.dot(e,t);return n.vec3.copy(r.normal,e),r.distance=s,r}}const gr=[],Tr=[],wr=[],_r=[],Ar=[],Or=[],xr=[],Ir=[],Sr=[],Mr=[],Nr=new br([1,0,0],0),vr=[];class Er{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new mr(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){let r=0;if(!mr.contains(this.rectangle,e)){const e=this.southwestCornerCartesian,s=this.northeastCornerCartesian,i=this.westNormal,o=this.southNormal,a=this.eastNormal,c=this.northNormal,h=n.vec3.subtract(vr,t,e),u=n.vec3.dot(h,i),f=n.vec3.dot(h,o),l=n.vec3.subtract(vr,t,s),d=n.vec3.dot(l,a),m=n.vec3.dot(l,c);u>0?r+=u*u:d>0&&(r+=d*d),f>0?r+=f*f:m>0&&(r+=m*m)}const s=e[2],i=this.minimumHeight,o=this.maximumHeight;if(s>o){const t=s-o;r+=t*t}else if(s<i){const t=i-s;r+=t*t}return Math.sqrt(r)}computeBox(t){const e=this;yr(mr.southwest(t,Tr),e.southwestCornerCartesian),yr(mr.northeast(t,Tr),e.northeastCornerCartesian),gr[0]=t.west,gr[1]=.5*(t.south+t.north),gr[2]=0;const r=yr(gr,wr),s=n.vec3.cross(Ar,r,pr);n.vec3.normalize(e.westNormal,s),gr[0]=t.east;const i=yr(gr,Ir),o=n.vec3.cross(Ar,pr,i);n.vec3.normalize(e.eastNormal,o);const a=n.vec3.subtract(Ar,r,i),c=n.vec3.normalize(_r,a),h=t.south;let u;if(h>0){gr[0]=.5*(t.west+t.east),gr[1]=h;const r=yr(gr,Sr);n.vec3.copy(Mr,c);const s=br.fromPointNormal(e.southwestCornerCartesian,e.westNormal,Nr);Cr(Sr,Mr,s,e.southwestCornerCartesian),u=Se(r,Or)}else u=Me(mr.southeast(t,Tr),Or);const f=n.vec3.cross(xr,u,a);n.vec3.normalize(e.southNormal,f);const l=t.north;let d;if(l<0){gr[0]=.5*(t.west+t.east),gr[1]=l;const r=yr(gr,Sr);n.vec3.scale(Mr,c,-1);const s=br.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,Nr);Cr(Sr,Mr,s,e.northeastCornerCartesian),d=Se(r,Or)}else d=Me(mr.northwest(t,Tr),Or);const m=n.vec3.cross(xr,a,d);n.vec3.normalize(e.northNormal,m)}}function Cr(t,e,r,s){const i=t,o=e,a=r.normal,c=n.vec3.dot(a,o);if(Math.abs(c)<1e-15)return;const h=(-r.distance-n.vec3.dot(a,i))/c;return h<0?void 0:(s=n.vec3.scale(s,o,h),n.vec3.add(s,i,s))}const Rr=new s.Extent(0,0,0,0),Pr=new s.Extent(0,0,0,0),Ur=[],Br=[],Lr=[],Dr=[],Fr=new s.Point(0,0),kr=[],Hr=new s.Coordinate(0,0),Vr=n.mat4.identity([]),jr=[0,0];class Gr extends(n.MaskLayerMixin(s.Layer)){constructor(t,e){super(t,e),this.bn(),this.ke={},this.gn=[]}bn(){const t=this.options.services.map(t=>t.url);this.Tn=this.Tn||{},this.in=this.in||[];for(let e=0;e<t.length;e++){const n=t[e];let r=this.Tn[n];void 0===r&&(r=this.Tn[n]=this.in.length),this.in[r]=Xr(n,r,this.options.services[e])}this.fire("rootready",{roots:this.in.slice(0)})}showService(t){return this.updateService(t,{visible:1}),this}hideService(t){return this.updateService(t,{visible:0}),this}setToRedraw(){const t=this.getRenderer();t&&t.setToRedraw()}addService(t){this.options.services=this.options.services||[],this.options.services.push(t),this.bn();const e=this.getRenderer();return e&&e.setToRedraw(),this}updateService(t,e){if(!e)return this;const n=this.options.services;if(n&&n[t]&&y(n[t],e),!p(e.visible)){const r=n[t].url,s=this.Tn[r];this.in&&this.in[s]&&(this.in[s].visible=e.visible)}const r=this.getRenderer();return r&&r.setToRedraw(),this}removeService(t){const e=this.options.services;if(e&&e[t]){const n=e[t].url,r=this.Tn[n];this.in[r]&&(this.in[r]=null),delete this.Tn[n],e.splice(t,1)}const n=this.getRenderer();return n&&n.setToRedraw(),this}getTileUrl(t,e,n){const r=n&&n.service&&n.service.subdomains;if(r&&n.domainKey){const e=r.length;if(e){const s=[...t].reduce((t,e)=>t+e.charCodeAt()-96,0)%e;return t.replace(n.domainKey,r[s])}}return t}getExtent(t){if(!t&&0!==t){const t=new s.Extent;for(let e=0;e<this.in.length;e++)if(this.in[e].boundingVolume){const n=this.boundingVolumeToExtent(this.in[e]);t._combine(n)}return t}return this.in[t]&&this.in[t].boundingVolume?this.boundingVolumeToExtent(this.in[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.wn?Vr:t.matrix,r=this.getMap();if(t.boundingVolume.region){const e=t.boundingVolume.region;return new s.Extent(_(e[0]),_(e[1]),_(e[2]),_(e[3]))}if(t.boundingVolume.sphere){const i=t.boundingVolume.sphere,o=_e([],n.vec3.transformMat4([],i,e)),a=i[3],c=r.locate(o,-a,a),h=r.locate(o,a,-a);return new s.Extent(c,h)}if(t.boundingVolume.box){const i=t.boundingVolume.box,o=n.vec3.transformMat4([],i,e),a=new s.Coordinate(_e([],o)),c=i.slice(3);n.mat3.multiply(c,n.mat3.fromMat4([],t.matrix),c);const h=n.vec3.length(c.slice(0,3)),u=n.vec3.length(c.slice(3,6)),f=n.vec3.length(c.slice(6,9)),l=Math.max(h,u,f),d=r.locate(a,-l,l),m=r.locate(a,l,-l);return new s.Extent(d,m)}return null}getRootTiles(){return this.in}getTiles(){const t=this.getRenderer();if(!t.ready)return this._n(),{tiles:Dr};const e=this.getMap(),r=e.cameraPosition;let s,i;if(e.getGLZoom)i=e.pointToDistance(r[2],0,e.getGLZoom()),Hr.set(r[0],r[1]),s=e.pointToCoord(Hr,e.getGLZoom());else{const t=e.getGLRes();i=e.pointAtResToDistance(r[2],0,t),Hr.set(r[0],r[1]),s=e.pointAtResToCoord(Hr,t)}this.An=this.An||[],n.vec3.set(this.An,w(s.x),w(s.y),i),this.On=pe(this.On||[],this.An[0],this.An[1],this.An[2]),this.xn=2*Math.tan(.5*w(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const h=[];for(let e=0;e<this.in.length;e++){const n=this.in[e];if(!n||!n.visible)continue;let r=1/0;const s=[n],i=this.In(e);for(;s.length>0;){const e=s.pop();for(e.id||this.Sn(e);c.level>=e.Lt;)c=c.parent;const n=this.Mn(e,i,o);if(n<1){let t=c;for(;t&&!t.content;)t=t.parent;0===n&&t&&t.content&&this.Nn(h,t);if(!1===this.options.services[e.Et].alwaysShow)continue;if(!(0===n&&e.Lt<=r))continue;e.content&&(r=e.Lt)}e.qt<1/0&&this.vn(e);const a=this.nn(e,c);c.children.push(a);const u=e.children,f=u&&u.length,l=a.content;if(!f&&l&&this.Nn(h,a),f){l&&"add"===e.refine&&this.Nn(h,a),c=a;const n=u[0].parent;let r=!1;for(let i=0,o=u.length;i<o;i++){if(n){const e=t.getCachedTile(u[i].id);if(e&&e.error&&404!==e.error.status)continue;r=!0}else{r=!0,u[i].parent=e,u[i].ue=e.ue,u[i].baseUrl=e.baseUrl;const t=u[i].content&&(u[i].content.url||u[i].content.uri);t&&(v(t)||t.indexOf("i3s:")>=0?u[i].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?u[i].content.url=e.baseUrl+t:u[i].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}s.push(u[i])}!r&&l&&this.Nn(h,a)}}}return{root:a,tiles:h}}Nn(t,e){const{viewerRequestVolume:n}=e.node;n&&!function(t,e,n){if(n.region){const e=n.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(n.sphere)return zr(n,e);if(n.box)return 0===qr(n,e)}return!1}(this.An,this.On,n)||t.push(e)}nn(t,e){return{id:t.id,node:t,children:[],level:t.Lt,parent:e,content:t.content&&t.content.url}}Sn(t){t.id=s.Util.GUID(),t.matrix=t.transform||n.mat4.identity([]),t.En=this.Cn(t),t.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(t)||(t.matrix=n.mat4.multiply(t.matrix,t.parent.matrix,t.matrix)),t.Et=t.parent.Et,void 0===t.Lt&&(t.Lt=t.parent.Lt+1),t.maxExtent=t.parent.maxExtent),t.refine=t.refine&&t.refine.toLowerCase()||"replace",t.content&&!t.content.url&&t.content.uri&&(t.content.url=t.content.uri)}vt(t){return this.in[t].service}Rn(t){const e=t.boundingVolume;if(!e||e.wn&&!this.Pn(t))return;const r=this.vt(t.Et),s=r.heightOffset||0,i=this.options.offset,o=b(i)||i[0]||i[1],a=r.coordOffset||jr;if(!Array.isArray(a))throw new Error("service.coordOffset must be an array");if(!e.wn&&(!t.boundingVolume||!s&&n.mat4.exactEquals(t.matrix,Vr)&&!o&&a===jr))return;e.box&&e.region&&delete e.region;const{region:c,box:h,sphere:u}=e;if(e.coordOffset=[a[0],a[1]],e.heightOffset=s,c){e.originalVolume||(e.originalVolume=c.slice(0));const t=e.originalVolume,n=this.Un([_(t[0]),_(t[1])]);c[0]=w(n.x+a[0]),c[1]=w(n.y+a[1]);const r=this.Un([_(t[2]),_(t[3])]);c[2]=w(r.x+a[0]),c[3]=w(r.y+a[1]),c[4]=t[4]+s+(a[2]||0),c[5]=t[5]+s+(a[2]||0)}else if(h||u){e.originalVolume||(e.originalVolume=(h||u).slice(0));const r=h||u,i=e.originalVolume,o=n.vec3.transformMat4(Ur,i,t.matrix),c=_e(Br,o),f=this.Un([c[0]+a[0],c[1]+a[1]]);c[0]=f.x,c[1]=f.y,c[2]+=s+(a[2]||0),pe(r,w(c[0]),w(c[1]),c[2])}e.wn=!0}Pn(t){const e=t.boundingVolume,n=this.vt(t.Et),r=n.heightOffset||0,s=n.coordOffset||jr;return e.coordOffset[0]!==s[0]||e.coordOffset[1]!==s[1]||e.heightOffset!==r}Cn(t){return void 0===t.geometricError||!t.boundingVolume}vn(t){let e=t.parent;for(;e&&e.En&&!(e.qt<=t.qt);)e.qt=t.qt,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const n=e.content.url;e.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const r=this.getRenderer();r&&r.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const s=this.vt(e.Et),i=(t.asset&&t.asset.gltfUpAxis||e&&e.ue||s.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.Lt&&(t.asset&&t.asset.s3mType&&o||s.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s,c=!!t.asset.s3mType;if(t.root.ue=i,e){const r=e.Et,s=this.in[r];c&&!s.isS3M&&(s.isS3M=c);const i=e.boundingVolume;y(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",i&&(e.boundingVolume=i);const o=t.root.transform;o&&(e.parent?a||(e.matrix=n.mat4.multiply([],e.parent.matrix,o)):e.matrix=o),e.Bn=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.En=this.Cn(e);const h=e.content&&(e.content.url||e.content.uri);h&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),a||!h||v(h)||-1!==h.indexOf("http://")||-1!==h.indexOf("https://")||(e.content.url=e.baseUrl+h)}this._n(),this.fire("loadtileset",{tileset:t,index:e&&e.Et,url:r})}Mn(t,e,n){if(t.qt=1/0,0===t.Lt||t.En)return 1;if(this.Rn(t),!this.Ln(t,e,n))return-1;if(0===t.geometricError)return 1;let r=this.vt(t.Et).maximumScreenSpaceError;null==r&&(r=16);let s=this.Dn(t);return 0===s&&t.parent&&(s=.5*(t.parent.Ze||0)),s>=r?1:0}Jt(t,e){e||(e=new s.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(t,n.getGLZoom(),e):n.coordToPointAtRes(t,n.getGLRes(),e)}Ln(t,e,r){const i=t.id;let o=this.gn[i];const{boundingVolume:c}=t,h=c.sphere;let d=c.region;const p=c.box;if(!o){let e,r,a;if(p&&(d=function(t,e){for(let e=0;e<9;e++)t[e+3]!==1/0&&t[e+3]!==-1/0||(t[e+3]=6378137*Math.sign(t[e+3])*3),ns[e]=t[e+3];const r=ns;n.mat4.exactEquals(e,Vr)||n.mat3.multiply(r,n.mat3.fromMat4(kr,e),r);const s=n.vec3.copy($r,t),i=n.vec3.set(Wr,r[0],r[1],r[2]),o=n.vec3.set(Kr,r[3],r[4],r[5]),a=n.vec3.set(Qr,r[6],r[7],r[8]);Zr[0]=Zr[0]||[];const c=n.vec3.copy(Zr[0],s);n.vec3.sub(c,c,i),n.vec3.sub(c,c,o),n.vec3.sub(c,c,a),Zr[1]=Zr[1]||[];const h=n.vec3.copy(Zr[1],s);n.vec3.sub(h,h,i),n.vec3.sub(h,h,o),n.vec3.add(h,h,a),Zr[2]=Zr[2]||[];const u=n.vec3.copy(Zr[2],s);n.vec3.sub(u,u,i),n.vec3.add(u,u,o),n.vec3.sub(u,u,a),Zr[3]=Zr[3]||[];const f=n.vec3.copy(Zr[3],s);n.vec3.sub(f,f,i),n.vec3.add(f,f,o),n.vec3.add(f,f,a),Zr[4]=Zr[4]||[];const l=n.vec3.copy(Zr[4],s);n.vec3.add(l,l,i),n.vec3.sub(l,l,o),n.vec3.sub(l,l,a),Zr[5]=Zr[5]||[];const d=n.vec3.copy(Zr[5],s);n.vec3.add(d,d,i),n.vec3.sub(d,d,o),n.vec3.add(d,d,a),Zr[6]=Zr[6]||[];const m=n.vec3.copy(Zr[6],s);n.vec3.add(m,m,i),n.vec3.add(m,m,o),n.vec3.sub(m,m,a),Zr[7]=Zr[7]||[];const p=n.vec3.copy(Zr[7],s);n.vec3.add(p,p,i),n.vec3.add(p,p,o),n.vec3.add(p,p,a);for(let t=0;t<Zr.length;t++)Jr[t]=Jr[t]||[],_e(Jr[t],Zr[t]),Yr[t]=Jr[t][0],ts[t]=Jr[t][1],es[t]=Jr[t][2];return[w(Math.min(...Yr)),w(Math.min(...ts)),w(Math.max(...Yr)),w(Math.max(...ts)),Math.min(...es),Math.max(...es)]}(p,t.matrix),c.region=d),d){e=Rr.set(_(d[0]),_(d[1]),_(d[2]),_(d[3]));const t=e.getCenter(),n=this.Fn(t);e=e.convertTo(t=>this.Jt(t,Fr),Pr),a=d[4],r=d[5],o=this.gn[i]=[[e.xmin,e.ymin,a*n[2]],[e.xmax,e.ymax,r*n[2]]],o.center=t}else if(h){const t=_e(Ur,h),e=new s.Coordinate(t),n=this.Jt(e,Fr).toArray(),r=this.Fn(e);n.push(t[2]*r[2]),o=this.gn[i]=[n,h[3]*r[2]],o.center=e}}if(e){if(d)Rr.xmin=o[0][0],Rr.ymin=o[0][1],Rr.xmax=o[1][0],Rr.ymax=o[1][1];else if(h){const t=o[2];Rr.xmin=o[0][0]-t,Rr.ymin=o[0][1]-t,Rr.xmax=o[0][0]+t,Rr.ymax=o[0][1]+t}else if(p){const t=o[1],e=o[2];Rr.xmin=o[0][0]-t,Rr.ymin=o[0][1]-e,Rr.xmax=o[0][0]+t,Rr.ymax=o[0][1]+e}if(!e.intersects(Rr))return!1}return d?u(r,o):h?function(t,e,n){l(t);for(var r=e[0],s=-e[1],i=0;i<6;i++){if(!n||"0"!==n.charAt(i))if(m(a[i],r)<s)return!1}return!0}(r,o):!!p&&function(t,e,n){l(t);for(var r=0;r<6;r++){if(!n||"0"!==n.charAt(r))if(!f(a[r],e))return!1}return!0}(r,o)}Fn(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let s;return s=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:r.y/100,n.vec3.set(Lr,r.x/100*1.01,r.y/100*1.01,s),Lr}Un(t){Array.isArray(t)&&(t=new s.Coordinate(t));let e=this.options.offset;if(b(e)&&(e=e.call(this,Array.isArray(t)?new s.Coordinate(t):t)),e[0]||e[1]){const n=this.getMap(),r=n.getGLRes(),s=n.coordToPointAtRes(t,r);return s._sub(e),n.pointAtResToCoord(s,r)}return t}In(t){const e=this.vt(t).maxExtent;if(!e)return null;const n=this.in[t];return n.maxExtent||(n.maxExtent=new s.Extent(e).convertTo(t=>this.Jt(t))),n.maxExtent}Dn(t){const e=this.xn,n=t.geometricError;if(0===n)return t.Ze=0,0;const r=this.getMap();let s;t.boundingVolume.region?s=function(t,e,n){t.kn||(t.kn=new Er(t.boundingVolume.region));return t.kn.distanceToCamera(e,n)}(t,this.On,this.An):t.boundingVolume.sphere?s=zr(t.boundingVolume,this.On):t.boundingVolume.box&&(s=qr(t.boundingVolume,this.On));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.qt=s,t.Ze=o,o}_n(){const t=this.getRenderer();t&&t.setToRedraw()}ye(t){return this.gn[t]}identify(t,e={}){const n=this.getMap(),r=this.getRenderer();if(!n||!r)return[];const i=n.coordToContainerPoint(new s.Coordinate(t));return this.identifyAtPoint(i,e)}identifyAtPoint(t,e={}){const n=[];if(!e.excludeMasks){const r=this.identifyMask(t,e);r&&r.length&&C(n,r)}const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.getDevicePixelRatio();return C(n,s.pick(t.x*i,t.y*i,e)),n}getCurrentBatchIDs(){const t=this.getMap(),e=this.getRenderer();return t&&e?e.Ie():[]}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.Rt||(this.Rt=[]),this.Rt.push(t),this)}mn(){if(this.Rt){for(let t=0;t<this.Rt.length;t++)this.highlight(this.Rt[t]);delete this.Rt}}cancelHighlight(t,e){const n=this.getRenderer();return n?(n.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}showOnly(t){const e=this.getRenderer();return e?(e.showOnly(t),this):(this.Ut||(this.Ut=[]),this.Ut.push(t),this)}Hn(){if(this.Ut){for(let t=0;t<this.Ut.length;t++)this.showOnly(this.Ut[t]);delete this.Ut}}cancelShowOnly(t){const e=this.getRenderer();return e?(e.cancelShowOnly(t),this):this}setServiceOpacity(t,e){const n=this.options.services[t];n&&(n.opacity=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}}function zr(t,e){const r=t.sphere,s=n.vec3.dist(r,e),i=t.sphere[3];return s<i?0:s-i}function qr(t,e){const r=t.box;return ar(n.vec3.set(Ur,r[0],r[1],r[2]),n.mat3.set(kr,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}function Xr(t,e,r){const s=(t=A(t)).indexOf("{s}")>=0?"{s}":t.indexOf("%7Bs%7D")>=0?"%7Bs%7D":null;return{service:r,visible:p(r.visible)?1:r.visible,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.mat4.identity([]),Et:e,Lt:0,domainKey:s}}Gr.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]}),Gr.registerRenderer("gl",sr),Gr.registerJSONType("Geo3DTilesLayer");const $r=[],Wr=[],Kr=[],Qr=[],Zr=[],Jr=[],Yr=[],ts=[],es=[],ns=[];let rs=null;function ss(){return rs||(rs={"image/crn":qn.crn&&qn.crn(),"image/ktx2":qn.ktx2&&qn.ktx2(),"image/cttf":qn.ktx2&&qn.ktx2(),"draco":qn.draco&&qn.draco()}),rs}class is{constructor(t,e,n){this.i=t,this.Vn=e||Gt,this.o=n,this.jn=ss()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.Gn(t,e,n,r,s)):xt.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.Gn(t,s,n,r)})}Gn(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.zn(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.Vn(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.jn,supportedFormats:this.o,maxTextureSize:i});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<o.transferables.length;t++)s.indexOf(o.transferables[t])<0&&s.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:s,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}})}zn(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),h=s.getUint32(20,!0),u=s.getUint32(24,!0),f=28+e;h>=570425344?(f-=8,o=a,h=c,u=0,a=0,c=0):u>=570425344&&(f-=4,o=h,h=a,u=c,a=0,c=0);const l=[t];let d,m,p;if(a>0?(d=Re(t,f,a),f+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(f+=c),h>0&&(m=Pe(t,f,h),f+=h,u>0)){const e=Ue(0,f,u);p=t.slice(e.offset,e.offset+e.byteLength),f+=u,l.push(p)}const y=d.BATCH_LENGTH,b={};if(d&&d.BATCH_ID){b.BATCH_ID=Le(d.BATCH_ID,t,(void 0).offset,y);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&l.indexOf(e)<0&&l.push(e)}return{count:o,transferables:l,featureTable:d,batchTable:m,batchTableBin:p,b3dm:b,glb:{buffer:t,byteOffset:f,byteLength:s.byteLength+s.byteOffset-f}}}qn(){return null}}class os{constructor(t,e,n,r){this.i=t,this.Vn=e||Gt,this.o=n,this.jn=ss(),this.Xn=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.Gn(t,e,n,r,s)):xt.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.Gn(t,s,n,r)})}Gn(t,e,n,r,s){return this.$n(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.Wn(e,n,r,t);if(o.error)return Promise.resolve(o);for(let t=0;t<i.length;t++)-1===o.transferables.indexOf(i[t])&&o.transferables.push(i[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:s})})}$n(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.jn,supportedFormats:this.o,maxTextureSize:i},a=new DataView(e,n,r),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let r=I(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?xt.getArrayBuffer(r,{}).then(t=>this.Kn(r,{buffer:t.data,byteOffset:0},o)):xt.getJSON(r,{}).then(t=>this.Kn(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.Kn(t,r,o)}}Kn(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.Vn(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,i=0;return e.buffer&&(r=e.byteOffset||0,i=e.byteLength||0),n.url=`${t}-${r}-${i}`,{transferables:s.transferables,gltf:n}})}Wn(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=ze(s,32+e,o),f={},l=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;f.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(f.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;f.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.Qn(new Uint16Array(t,r+c.offset,3*l),e,n)},o.push(f.POSITION.array.buffer)}if(a.BATCH_ID){f.BATCH_ID=Le(a.BATCH_ID,t,c.offset,l);const e=f.BATCH_ID.array&&f.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;f.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(f.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,f.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(f.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;f.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.Zn(new Uint16Array(t,e+c.offset,2*l))},o.push(f.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,f.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:this.Zn(new Uint16Array(t,e+c.offset,2*l))},o.push(f.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;f.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,l).slice()},o.push(f.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;f.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:l,componentType:5126,array:new Float32Array(t,e+c.offset,3*l).slice()},o.push(f.SCALE_NON_UNIFORM.array.buffer)}return{count:l,batchTable:h,batchTableBin:u,featureTable:a,i3dm:f,transferables:o}}Zn(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)as(r,t[2*s],t[2*s+1],65535),n[3*s]=r[0],n[3*s+1]=r[1],n[3*s+2]=r[2];return n}Qn(t,e,n){return Ge(new Float32Array(t.length),t,e,n)}qn(){return null}}function as(t,e,n,r){if(t[0]=cs(e,r),t[1]=cs(n,r),t[2]=1-(Math.abs(t[0])+Math.abs(t[1])),t[2]<0){const e=t[0];t[0]=(1-Math.abs(t[1]))*hs(e),t[1]=(1-Math.abs(e))*hs(t[1])}return W(t,t)}function cs(t,e){return function(t,e,n){return t<e?e:t>n?n:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function hs(t){return t<0?-1:1}class us{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.Gn(t,e,n,r)):xt.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.Gn(t,s,n,r)})}Gn(t,e,n,r){return this.Jn(e,n,r,t).then(t=>t.error?t:{magic:"pnts",count:t.count,transferables:t.transferables,featureTable:t.featureTable,batchTable:t.batchTable,batchTableBin:t.batchTableBin,pnts:t.pnts})}Jn(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=ze(s,e+28,o),f=a.QUANTIZED_VOLUME_OFFSET,l=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let m,p={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){p=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,p.byteOffset+c.offset,p.byteLength);const e={attributes:p.properties,useUniqueIDs:!1};return this.Yn||(this.Yn=ss().draco),this.Yn(m,e).then(e=>{const n=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||n.POSITION||n.POSITION_QUANTIZED||(n.POSITION=a.POSITION,n.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||n.RGB||n.RGBA||n.RGB565||(n.RGB=a.RGB,n.RGBA=a.RGBA,n.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||n.NORMAL||n.NORMAL_OCT16P||(n.NORMAL=a.NORMAL,n.NORMAL_OCT16P=a.NORMAL_OCT16P);const r=this.tr(t,e.attributes,c.offset,d,o,f,l);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:je(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=Le(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=fs(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:r,transferables:o}})}const y=this.tr(t,a,c.offset,d,o,f,l);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?y.BATCH_ID=Le(a.BATCH_ID,t,c.offset,d):y.BATCH_ID=fs(d);const e=y.BATCH_ID.array&&y.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:y,transferables:o})}tr(t,e,n,r,s,i,o){const a={};if(e.POSITION){let{byteOffset:i,array:o}=e.POSITION;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c}=e.POSITION_QUANTIZED;const{array:h}=e.POSITION_QUANTIZED;c=c||0;const u=h?0:n;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:this.Qn(h||new Uint16Array(t,c+u,3*r),i,o)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:i,array:o}=e.RGBA;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+4*r);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB){let{byteOffset:i,array:o}=e.RGB;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB565){let{byteOffset:i,array:o}=e.RGB565;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:o},s.push(o.buffer)}if(e.NORMAL){let{byteOffset:i,array:o}=e.NORMAL;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:i,array:o}=e.NORMAL_OCT16P;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:o},s.push(o.buffer)}return a}Qn(t,e,n){return Ge(new Float32Array(t.length),t,e,n)}qn(){return null}}function fs(t){const e=N(t),n=new e(t);for(let e=0;e<t;e++)n[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:je(e),array:n}}class ls{constructor(t,e,n,r){this.o=n,this.i=t,this.Vn=e||Gt,this.Xn=r}load(t,e,n=0,r=0,s){return e?this.Gn(t,e,n,r,s):xt.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.Gn(t,s,n,r)})}Gn(t,e,n,r,s){r||(r=e.byteLength);const i=this.er(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new is(this.i,this.Vn,this.o);else if("i3dm"===i[n].magic)r=new os(this.i,this.Vn,this.o,this.Xn);else if("pnts"===i[n].magic)r=new us;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new ls(this.i,this.Vn,this.o,this.Xn)}o.push(r.load(t,e,i[n].offset,i[n].byteLength,s).then(t=>t))}return Promise.all(o).then(t=>({magic:"cmpt",tiles:t}))}er(t,e,n,r){const s=new DataView(t,n,r),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported cmpt version: "+i+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const o=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=Ee(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}if(i.transcoders){const t=s.Map.VERSION;if(t.indexOf("1.0.0-beta")>=0||t.indexOf("1.0.0-alpha")>=0){const t=i.transcoders.inject(o);s.registerWorkerAdapter("@maptalks/3dtiles",t)}else s.registerWorkerAdapter("@maptalks/3dtiles",(function(){return i.transcoders.inject(o)}))}else s.registerWorkerAdapter("@maptalks/3dtiles",o);t.B3DMLoader=is,t.CMPTLoader=ls,t.Geo3DTilesLayer=Gr,t.Geo3DTilesUtil=R,t.Geo3DTransform=Ne,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.89.3")}));
23
+ */(100,1),Gr=[0,0,0,1],$r=[1,1,1];class Xr{constructor(t,e){this.nt=e,this.rt=e.getRenderer().canvas,this.pickingFBO=e.getRenderer().pickingFBO,this.st=new s.SpatialReference,this.it=t,this.ot=new n.reshader.Renderer(t),this.ct={},this.ht={},this.ut={},this.lt={},this.ft={},this.dt={},this.bt=new n.reshader.Scene,this.pt=new n.reshader.Scene,this.gt=new n.reshader.Scene,this.yt=new n.reshader.Scene,this.wt=new n.reshader.ResourceLoader(t.texture(2)),this.vt=this.Tt.bind(this),this._t=new n.reshader.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.Mt(),this.Ot=new n.reshader.KHRTechniquesWebglManager(this.it,this.At(),this.wt);const r=this.getMap();r.altitudeToPoint&&(this.xt=r.altitudeToPoint(100,r.getGLRes())/100)}getI3DMMeshes(){return this.lt}getPNTSMeshes(){return this.ut}getB3DMMeshes(){return this.ht}getPaintedMeshes(){return this.It}getMap(){return this.nt.getMap()}paint(t,e,r){const s=r&&r.renderTarget,i=r&&r.sceneFilter,o=this.getMap();if(!t.length||!o)return null;const a=this.St(),c=o.projViewMatrix,h=[],l=[],f=[],d=[],m=[],b=this.Et(t),p=[];for(let s=0,i=t.length;s<i;s++){const i=t[s].data.node;let o=this.Nt(i);if(!o)continue;const a=this.nt.Ct(i.Rt);i.Pt&&a.debugShowBoundingVolume&&p.push(i.Pt);const g=a.heightOffset||0,y=a.coordOffset||Or;this.ft[i.id]&&(o=this.ft[i.id],o=gt(o));let w=a.polygonOffset||yr;at(w)&&(w=w()),Array.isArray(o)||(h[0]=o,o=h);for(let t=0,s=o.length;t<s;t++){const s=o[t].properties.magic;if(o[t].properties.heightOffset===g&&o[t].properties.coordOffset[0]===y[0]&&o[t].properties.coordOffset[1]===y[1]||(this.kt(o[t]),o[t].Bt=n.mat4.copy([],o[t].localTransform)),"b3dm"===s){if(o[t].getBoundingBox&&!u(c,o[t].getBoundingBox()))continue;const{batchIdData:e,batchIdMap:s}=o[t].geometry.properties;if(e&&s){const e=o[t].properties.node.Rt;this.Lt&&this.Lt[e]?n.HighlightUtil.highlightMesh(this.it,o[t],this.Lt[e],this.Ut,s):this.Lt&&this.Lt[e]||n.HighlightUtil.highlightMesh(this.it,o[t],null,this.Ut,s),n.HighlightUtil.showOnly(this.it,o[t],this.Dt&&this.Dt[e],this.zt,s)}r&&r.bloom&&o[t].properties.hlBloomMesh&&(o[t].properties.hlBloomMesh.properties.depthFunc="always",o[t].properties.hlBloomMesh.properties.polygonOffset=w,f.push(o[t].properties.hlBloomMesh)),f.push(o[t])}else"pnts"===s?d.push(o[t]):"i3dm"===s&&m.push(o[t]);o[t].properties.isLeaf=!!e[i.id],o[t].properties.level=b.get(i.Ft),o[t].properties.polygonOffset=w,o[t].jt=i,e[i.id]||l.push(o[t]),this.Vt(o[t]),this.qt(o[t],i)}}let g=0;const y=this.Ot.getExcludeFilter();g+=this.Ht(this.Gt,a,[i,Ar,y],s,l,f,m),g+=this.Ht(this.$t,a,[i,xr,y],s,l,f,m),this.Ot.forEachShader((t,e,n)=>{const r=this.St(n);g+=this.Ht(t,r,[i,e],s,l,f,m)}),this.pt.setMeshes(d);const w=this.Xt();return g+=this.ot.render(this.Jt,w,this.pt,s&&s.fbo),this.It={pntsMeshes:d,i3dmMeshes:m,b3dmMeshes:f},p.forEach(t=>{this.Zt(t)}),this.yt.setMeshes(p),this.ot.render(this.Kt,a,this.yt,s&&s.fbo),g}Zt(t){const e=t.properties.node,r=this.nt.Ct(e.Rt),s=r.heightOffset||0,i=this.Yt(),o=r.Qt,a=n.vec3.set(Fr,0,0,i*(s-o));let c=r.rotation||[0,0,0];c=n.quat.fromEuler(Ur,c[0],c[1],c[2]);const h=r.scale||[1,1,1],u=n.mat4.fromRotationTranslationScale(Lr,c,a,h);n.mat4.multiply(t.localTransform,t.Bt,u)}Ht(t,e,n,r,s,i,o){t.filter=n.filter(t=>!!t),e.debug=!1,e.debug=!1;let a=0;return this.bt.setMeshes(i),a+=this.ot.render(t,e,this.bt,r&&r.fbo),this.gt.setMeshes(o),a+=this.ot.render(t,e,this.gt,r&&r.fbo),a}Wt(t,e){return e.jt.te-t.jt.te}deleteTile(t){const e=t.node;e.Pt&&(e.Pt.geometry.dispose(),e.Pt.dispose(),delete e.Pt);const n=e.id;this.ee(n)}ee(t){const e=this.ht[t]||this.ut[t]||this.lt[t]||this.ft[t]||this.ct[t];this.ft[t]?this.ne(t):e&&(this.re(e),delete this.ht[t],delete this.ut[t],delete this.lt[t],delete this.ct[t])}ne(t){let e=this.ft[t];e=gt(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.ee(n)}delete this.ft[t]}re(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.re(t[e]);else{n.HighlightUtil.showOnly(this.it,t),n.HighlightUtil.highlightMesh(this.it,t);const e=t.geometry.properties.url;if(e){const n=this.dt[e];n&&n.refMeshes&&(n.refMeshes.delete(t.uuid),n.refMeshes.size||(n.geometry.dispose(),n.material.dispose(),delete this.dt[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.nt;br(t.getRenderer().canvas,t.getMap());for(const t in this.ft)this.ne(t);this.ft={};for(const t in this.ht)this.ee(t);this.ht={};for(const t in this.ut)this.ee(t);this.ut={};for(const t in this.lt)this.ee(t);this.lt={};for(const t in this.ct)this.ee(t);this.ct={},this.Gt&&(this.Gt.dispose(),delete this.Gt),this.$t&&(this.$t.dispose(),delete this.$t),this.Jt&&(this.Jt.dispose(),delete this.Jt),this.Kt&&(this.Kt.dispose(),delete this.Kt),this.Ot.dispose(),this.picking&&this.picking.dispose()}Nt(t){return this.ht[t.id]||this.ut[t.id]||this.lt[t.id]||this.ft[t.id]}has(t){return this.Nt(t)||this.ct[t.id]}kt(t){const e=t.properties.magic;"b3dm"===e?this.se(t):"i3dm"===e?this.ie(t):"pnts"===e&&this.oe(t)}createPntsMesh(t,e,r,s){if(this.ut[e]){const t=this.ut[e];return console.warn(`pnts mesh with id(${e}) was already created.`),s(null,{id:e,mesh:t}),t}const{pnts:i,featureTable:o,rootIdx:a,compressed_int16_params:c}=t,h=o.POINTS_LENGTH,u=new n.reshader.Geometry(i,null,h,{static:!0,primitive:"points",positionAttribute:"POSITION"});u.generateBuffers(this.it);const l={};i.POSITION?l.HAS_POSITION=1:i.POSITION_QUANTIZED&&(l.HAS_POSITION_QUANTIZED=1),i.RGB?l.HAS_RGB=1:i.RGBA?l.HAS_RGBA=1:i.RGB565&&(l.HAS_RGB565=1),(i.NORMAL||i.NORMAL_OCT16P)&&(l.HAS_NORMAL=1,i.NORMAL_OCT16P&&(l.HAS_NORMAL_OCT16P=1)),this.ae(l,c),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map(t=>t/255));const{rtcCenter:f,rtcCoord:d}=t,m=this.nt.Ct(a),b=new n.reshader.Mesh(u);return b.properties.magic="pnts",b.properties.id=e,b.properties.node=r,b.properties.count=h,b.properties.batchTable=t.batchTable,b.properties.batchTableBin=t.batchTableBin,b.properties.serviceIndex=a,b.properties.rtcCoord=d,b.properties.rtcCenter=f,b.setDefines(l),Object.defineProperty(b.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:m&&m.pointColor||[1,1,1,1]}}),Object.defineProperty(b.uniforms,"pointSize",{enumerable:!0,get:function(){return m&&m.pointSize||2}}),Object.defineProperty(b.uniforms,"pointOpacity",{enumerable:!0,get:function(){return m&&m.pointOpacity||1}}),this.ce(b,c),this.oe(b),b.Bt=n.mat4.copy([],b.localTransform),this.ut[e]=b,s(null,{id:e,mesh:[b]}),[b]}oe(t){const{rtcCenter:e,rtcCoord:r,node:s}=t.properties,i=this.he(kr,r),o=t.localTransform||[];this.ue(o,s,e,r),n.mat4.multiply(o,o,i);const a=this.nt.Ct(s.Rt);if(a.coordOffset){const t=this.le(Br,s.Rt,r);n.mat4.multiply(o,t,o)}t.setLocalTransform(o),t.properties.heightOffset=a.heightOffset||0,t.properties.coordOffset=a.coordOffset&&a.coordOffset.slice(0)||Or}createI3DMMesh(t,e,r,s){if(this.lt[e]){const t=this.lt[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.ct[e]||s(null,{id:e,mesh:t}),t}const i=this.nt.Ct(r.Rt),o=this.fe(r.de),{i3dm:a,featureTable:c,gltf:h,batchTable:u,batchTableBin:l,count:f}=t,d=c.INSTANCES_LENGTH,{rtcCenter:m,rtcCoord:b}=t,p=this.he(kr,b),g=this.ue(Br,r,m,b);n.mat4.multiply(p,g,p);const{POSITION:y,NORMAL_UP:w,NORMAL_RIGHT:v,SCALE:T,SCALE_NON_UNIFORM:_,INSTANCE_ROTATION:M}=a,O={"instance_vectorA":new Float32Array(4*d),"instance_vectorB":new Float32Array(4*d),"instance_vectorC":new Float32Array(4*d)},A=new Float32Array(3),x=new Float32Array(3),I=[],S=new Float32Array(1),E=new Float32Array(3),N=[],C=[],R=[],P=[],k=new Float32Array(9);!function(t,e){let{byteOffset:n,byteStride:r,count:s}=t;const{componentType:i,itemSize:o}=t,a=t.array.buffer,c=i?Le.getTypedArrayCtor(i):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,r=r||0,s=s||t.array.length/o,(!r||r===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o){e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o)}return}const h=new Uint8Array(o*c.BYTES_PER_ELEMENT);r||(r=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const s=new Uint8Array(a,r*t+n,o*c.BYTES_PER_ELEMENT);h.set(s);e(new c(h.buffer),t),s.set(h)}}(y,(t,e)=>{w?(rn(x,v,e),rn(A,w,e),n.vec3.cross(I,x,A),n.vec3.normalize(I,I),pt(N,x,0),pt(N,A,1),pt(N,I,2),n.quat.fromMat3(C,N)):M?(rn(k,M,e),n.quat.fromMat3(C,k)):n.quat.identity(C),T?(rn(S,T,e),n.vec3.set(R,S[0],S[0],S[0])):_?(rn(E,_,e),n.vec3.set(R,...E)):n.vec3.set(R,1,1,1),n.mat4.fromRotationTranslationScale(P,C,t,R),sn(O.instance_vectorA,e,P,0),sn(O.instance_vectorB,e,P,1),sn(O.instance_vectorC,e,P,2)});const B={};for(const t in O)B[t]={buffer:this.it.buffer({dimension:O[t].length/d,data:O[t]}),divisor:1};const L=i.shader||"pbr";let U=0,D=!0;const z=[],F=[];return Ze(h,(t,s,i,a)=>{const c=this.me(t,s,i,a,r,!0,L,F),{geometry:h,material:g}=c;g&&!g.isReady()&&(D=!1,U++);const y=new n.reshader.InstancedMesh(B,d,h,g);c.refMeshes||(c.refMeshes=new Set,c.refMeshes.add(y.uuid)),y.properties.magic="i3dm",y.properties.id=e,y.properties.count=f,y.properties.batchTable=u,y.properties.batchTableBin=l,y.properties.serviceIndex=r.Rt,y.properties.rtcCoord=b,y.properties.rtcCenter=m,y.properties.node=r;const w=this.be(t,h,g,r.Rt,a);t.compressed_int16_params&&this.ce(y,t.compressed_int16_params),this.pe(y,t.attributes);const v=n.mat4.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)n.mat4.multiply(v,v,t.matrices[e]);n.mat4.multiply(v,o,v),y.setPositionMatrix(v),this.ie(y,p),y.setDefines(w),y.properties.polygonOffset={offset:0,factor:0},z.push(y),delete t.attributes,y.Bt=n.mat4.copy([],y.localTransform)}),Jr(F),D?(this.lt[e]=z,s(null,{id:e,mesh:z})):(this.ct[e]={meshes:z,count:U},z.ge=s),z}ie(t,e){const{rtcCenter:r,rtcCoord:s,node:i}=t.properties;if(!e){e=this.he(kr,s);const t=this.ue(Br,i,r,s);n.mat4.multiply(e,t,e)}const o=this.nt.Ct(i.Rt),a=t.localTransform||[];if(o.coordOffset){const t=this.le(Br,i.Rt,s);n.mat4.multiply(a,t,e)}else n.mat4.copy(a,e);t.setLocalTransform(a),t.properties.heightOffset=o.heightOffset||0,t.properties.coordOffset=o.coordOffset&&o.coordOffset.slice(0)||Or}createB3DMMesh(t,e,r,i){if(t.gltf&&(t.gltf.transferables=null),this.ht[e]||this.ct[e]){const t=this.ht[e];return console.warn(`mesh with id(${e}) was already created.`),this.ct[e]||i(null,{id:e,mesh:t}),t}let o;if(r.maxExtent){const t=new s.Extent(r.maxExtent).convertTo(t=>this._pointToPrj(t));o=[t.xmin,t.ymin,t.xmax,t.ymax]}const a=t.gltf,{projCenter:c}=a.extensions.MAPTALKS_RTC,{rtcCoord:h,center:u}=a.extensions.CESIUM_RTC,l=a.asset.sharePosition,f=this.fe(r.de);let d;d=l?this.he(kr,h):this.ye(kr,h,c,r.Rt);const m=this.nt.Ct(r.Rt);let b=m.shader||"pbr";if(m.unlit)b="phong";else if(a.materials)for(let t=0;t<a.materials.length;t++)if(a.materials[t]&&a.materials[t].extensions&&a.materials[t].extensions.KHR_materials_unlit){b="phong";break}const p=[],g=[];let y=0,w=!0;return Ze(a,(s,i,a,v)=>{const T=this.me(s,i,a,v,r,!1,b,p),{geometry:_,material:M}=T;M&&!M.isReady()&&(w=!1,y++);const O=new n.reshader.Mesh(_,M);T.refMeshes||(T.refMeshes=new Set,T.refMeshes.add(O.uuid)),O.properties.magic="b3dm",O.properties.id=e,O.properties.node=r,O.properties.batchTable=t.batchTable,O.properties.batchTableBin=t.batchTableBin,O.properties.count=t.featureTable.BATCH_LENGTH,O.properties.serviceIndex=r.Rt;const A=this.be(s,_,M,r.Rt,v);O.setDefines(A);const x=s.compressUniforms;if(x)for(const t in x)O.setUniform(t,x[t]);s.compressed_int16_params&&this.ce(O,s.compressed_int16_params),this.pe(O,s.attributes),o&&(A.USE_MAX_EXTENT=1,O.setUniform("maxPrjExtent",o)),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonOpacity")||Object.defineProperty(O.uniforms,"polygonOpacity",{enumerable:!0,get:function(){return ht(m.opacity)?m.opacity:1}}),Object.prototype.hasOwnProperty.call(O.uniforms,"polygonFill")||Object.defineProperty(O.uniforms,"polygonFill",{enumerable:!0,get:function(){return Mt([],m.polygonFill||wr)}}),Object.prototype.hasOwnProperty.call(O.material.uniforms,"hsv")||Object.defineProperty(O.material.uniforms,"hsv",{enumerable:!0,get:function(){return m.hsv||vr}});const I=n.mat4.identity([]);if(l&&s.matrices&&s.matrices.length)for(let t=0;t<s.matrices.length;t++)n.mat4.multiply(I,I,s.matrices[t]);l&&n.mat4.multiply(I,f,I),O.properties.node=r,O.properties.projCenter=c,O.properties.nodeMatrix=I,O.properties.isSharedPosition=l,O.properties.rtcCoord=h,O.properties.rtcCenter=u,this.se(O,d),g.push(O),delete s.attributes,O.Bt=n.mat4.copy([],O.localTransform)}),Jr(p),w?(this.ht[e]=g,i(null,{id:e,mesh:g})):(this.ct[e]={meshes:g,count:y},g.ge=i),g}we(t){const e=this.nt.ve[t.id];if(!e)return;let r,s,i,o;if(e.length){if(2===e.length){const t=e[0],n=e[1];r=Hr.vertices,s=Hr.indices,i=t,o=[n,n,n]}}else{r=e.boxPosition,s=qr;i=this.nt.Ct(t.Rt).Te,o=$r}const a=new n.reshader.Geometry({POSITION:r},s,0,{primitive:"lines",positionAttribute:"POSITION"}),c=new n.reshader.Mesh(a,new n.reshader.Material({lineColor:[.8,.8,.1,1],lineOpacity:1})),h=n.mat4.identity([]);n.mat4.fromRotationTranslationScale(h,Gr,i,o),c.localTransform=h,c.Bt=n.mat4.copy([],h),c.properties.node=t,t.Pt=c}ce(t,e){e.POSITION&&t.setUniform("compressedPositionRange",e.POSITION),e.TEXCOORD_0&&t.setUniform("compressedTexcoordRange_0",e.TEXCOORD_0),e.TEXCOORD_1&&t.setUniform("compressedTexcoordRange_1",e.TEXCOORD_0),e.NORMAL&&t.setUniform("compressedNormalRange",e.NORMAL),e.TANGENT&&t.setUniform("compressedTangentRange",e.TANGENT),e.compressed_ratio&&t.setUniform("compressed_ratio",e.compressed_ratio)}se(t,e){const{isSharedPosition:r,rtcCoord:s,rtcCenter:i,projCenter:o,nodeMatrix:a,node:c}=t.properties;e||(e=r?this.he(kr,s):this.ye(kr,s,o,c.Rt));const h=t.localTransform||n.mat4.identity([]);if(r){const t=this.ue(Br,c,i,s);n.mat4.multiply(h,e,a),n.mat4.multiply(h,t,h)}else n.mat4.multiply(h,e,a);const u=this.nt.Ct(c.Rt);if(u.coordOffset){const t=this.le(Br,c.Rt,s);n.mat4.multiply(h,t,h)}t.setLocalTransform(h),t.properties.heightOffset=u.heightOffset||0,t.properties.coordOffset=u.coordOffset&&u.coordOffset.slice(0)||Or}pe(t,e){if(e&&e.TEXCOORD_0&&e.TEXCOORD_0.extensions&&e.TEXCOORD_0.extensions.WEB3D_quantized_attributes){const n=e.TEXCOORD_0.extensions.WEB3D_quantized_attributes.decodeMatrix;t.setUniform("decodeMatrix",n)}}ue(t,e,r,i){const o=this.getMap(),a=this.nt.Ct(e.Rt).heightOffset||0,c=new s.Coordinate(i);let h;h=o.altitudeToPoint?this.xt:o.distanceToPointAtRes(100,100,o.getGLRes(),c).y/100;const u=e.matrix?n.mat4.copy(t,e.matrix):n.mat4.identity(t);if(r){Xn(u,n.vec3.transformMat4(Ir,r,u),u)}const l=function(t,e,n,r,s,i,o){e=Bt(Zn,e);const a=hn(Zn,e[0]*sr,e[1]*sr,e[2]),c=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}(Kn,n),h=r.ellipsoid;let u;u=0===$t(c)?Lt(Yn,0,0,-6378137):bn(Yn,c),nr.x=u[0],nr.y=u[1];const l=r.project(nr,rr);Qn[0]=l.x/s,Qn[1]=l.y/s,Qn[2]=(u[2]+o)*i;const f=Jn(a,h,Wn),d=function(t,e,n){const r=t[0],s=t[1],i=t[2],o=t[4],a=t[5],c=t[6],h=t[8],u=t[9],l=t[10],f=e[0],d=e[1],m=e[2],b=e[3],p=e[4],g=e[5],y=e[6],w=e[7],v=e[8],T=r*f+o*d+h*m,_=s*f+a*d+u*m,M=i*f+c*d+l*m,O=r*b+o*p+h*g,A=s*b+a*p+u*g,x=i*b+c*p+l*g,I=r*y+o*w+h*v,S=s*y+a*w+u*v,E=i*y+c*w+l*v;return n[0]=T,n[1]=_,n[2]=M,n[3]=0,n[4]=O,n[5]=A,n[6]=x,n[7]=0,n[8]=I,n[9]=S,n[10]=E,n[11]=0,n[12]=t[12],n[13]=t[13],n[14]=t[14],n[15]=t[15],n}(function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],a=e[5],c=e[6],h=e[7],u=e[8],l=e[9],f=e[10],d=e[11],m=e[12],b=e[13],p=e[14],g=e[15],y=n*a-r*o,w=n*c-s*o,v=n*h-i*o,T=r*c-s*a,_=r*h-i*a,M=s*h-i*c,O=u*b-l*m,A=u*p-f*m,x=u*g-d*m,I=l*p-f*b,S=l*g-d*b,E=f*g-d*p,N=y*E-w*S+v*I+T*x-_*A+M*O;return N?(N=1/N,t[0]=(a*E-c*S+h*I)*N,t[1]=(s*S-r*E-i*I)*N,t[2]=(b*M-p*_+g*T)*N,t[3]=(f*_-l*M-d*T)*N,t[4]=(c*x-o*E-h*A)*N,t[5]=(n*E-s*x+i*A)*N,t[6]=(p*v-m*M-g*w)*N,t[7]=(u*M-f*v+d*w)*N,t[8]=(o*S-a*x+h*O)*N,t[9]=(r*x-n*S-i*O)*N,t[10]=(m*_-b*v+g*y)*N,t[11]=(l*v-u*_-d*y)*N,t[12]=(a*A-o*I-c*O)*N,t[13]=(n*I-r*A+s*O)*N,t[14]=(b*w-m*T-p*y)*N,t[15]=(u*T-l*w+f*y)*N,t):null}(tr,f),function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[4],t[4]=e[5],t[5]=e[6],t[6]=e[8],t[7]=e[9],t[8]=e[10],t}(er,n),t);return Xn(t,Qn,d),t}(u,i,u,o.getProjection(),o.getGLRes(),h,a),f=function(t,e){return Lt(t,e[12],e[13],e[14]),t}(Pr,l);let d=this.nt.options.offset;if(at(d)){const t=this.nt._e(e.id).center;d=d.call(this.nt,t)}return n.vec3.set(Rr,d[0],d[1],0),n.vec3.sub(f,f,Rr),Xn(l,f,l),l}le(t,e,r){const s=this.nt.Ct(e);if(!s.coordOffset)return null;const i=this.getMap(),o=i.getGLRes();Sr.set(r[0],r[1]);const a=i.coordToPointAtRes(Sr,o,Nr),c=s.coordOffset,h=Sr.set(r[0]+c[0],r[1]+c[1]),u=i.coordToPointAtRes(h,o,Cr),l=u.x-a.x,f=u.y-a.y,d=this.Yt(),m=n.vec3.set(Rr,l,f,(c[2]||0)*d);return n.mat4.fromTranslation(t,m)}Yt(){const t=this.getMap();let e;return e=t.altitudeToPoint?this.xt:t.distanceToPointAtRes(100,100,t.getGLRes(),Sr).y/100,e}createCMPTMesh(t,e,n,r){if(this.ft[e]){const t=this.ft[e];return console.warn(`mesh with id(${e}) was already created.`),r(null,{id:e,mesh:t}),t}const{content:s}=t,i=[];for(let t=0;t<s.length;t++){const{magic:r}=s[t],o=e+"."+t;"b3dm"===r?this.createB3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"i3dm"===r?this.createI3DMMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"pnts"===r?this.createPntsMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)}):"cmpt"===r&&this.createCMPTMesh(s[t],o,n,(t,{mesh:e})=>{i.push(e)})}return this.ft[e]=i,r(null,{id:e,mesh:i}),i}be(t,e,n,r,s){const i=("phong"===(this.nt.Ct(r).shader||"pbr")?this.Gt:this.$t).getGeometryDefines(e);s.asset&&"S3M"===s.asset.generator&&this.Me(i,e),e.data.uvRegion&&(i.HAS_I3S_UVREGION=1),e.data[e.desc.normalAttribute]&&(i.VertexNormal=1),e.data[e.desc.color0Attribute]&&(i.VertexColor=1),e.data[e.desc.uv0Attribute]&&(i.TexCoord=1),e.data[e.desc.textureCoordMatrixAttribute]&&(i.HAS_TextureCoordMatrix=1),n.get("uTexture")&&(i.COMPUTE_TEXCOORD=1),n.get("uTexture2")&&(i.TexCoord2=1),"MESHOPT"===this.nt.Oe&&(i.MeshOPT_Compress=1),this.hasIBL()&&(i.HAS_IBL_LIGHTING=1),t.attributes&&t.attributes.TEXCOORD_0&&"WEB3D_quantized_attributes"===t.attributes.TEXCOORD_0.extensions&&(i.HAS_WEB3D_quantized_attributes_TEXCOORD=1),i.HAS_MIN_ALTITUDE=1,i.HAS_LAYER_OPACITY=1,this.ae(i,t.compressed_int16_params);return ot(i,t.compressDefines),i}ae(t,e){e&&Object.keys(e).length>0&&(t.HAS_COMPRESSED_INT16=1,e.POSITION&&(t.HAS_COMPRESSED_INT16_POSITION=1),e.TEXCOORD_0&&(t.HAS_COMPRESSED_INT16_TEXCOORD_0=1),e.TEXCOORD_1&&(t.HAS_COMPRESSED_INT16_TEXCOORD_1=1),e.NORMAL&&(t.HAS_COMPRESSED_INT16_NORMAL=1),e.TANGENT&&(t.HAS_COMPRESSED_INT16_TANGENT=1),e.compressed_ratio&&(t.HAS_COMPRESSED_INT16_RATIO=1))}Vt(t){const e=this.nt.getRenderer();e&&e.updateMaskDefines(t)}Me(t,e){e.data.aNormal&&(t.VertexNormal=1),e.data.instanceId&&(t.Instance=1),e.data.aTexCoord0&&(t.TexCoord=1),e.data.aColor&&(t.VertexColor=1),e.data.aTexCoord1&&(t.TexCoord2=1),e.data.uv2&&(t.InstanceBim=1)}me(t,e,n,r,s,i,o,a){let c=!1;r.asset&&"S3M"===r.asset.generator&&(c=!0,r.extensions=r.extensions||{});const h=r.url+"-"+e+"-"+n;if(this.dt[h])return this.dt[h];let u,l;a.push(t);const f=r.materials&&r.materials[t.material],d=r.extensions&&r.extensions.KHR_techniques_webgl,m=this.nt.Ct(s.Rt);if(d&&f.extensions&&f.extensions.KHR_techniques_webgl){const e=this.Ae(t,r,i,c);u=e.material,l=e.geometry,m.fillEmptyDataInMissingAttribute&&(l.desc.fillEmptyDataInMissingAttribute=!0)}else{l=this.xe(t,i,Vr);const e=m.ambientLight;let n=m.environmentExposure;const s=m.material,c=this.getMap().getLightManager(),h=c&&c.getAmbientLight();if(e&&(!h||h.color)&&void 0===n){const t=h&&h.color?h.color[0]:.2;n=e[0]/t}u=this.Ie(t.material,r,o,s||Tr,n||1,a,m)}u&&Object.defineProperty(u.uniforms,"alphaTest",{enumerable:!0,get:function(){const t=m.alphaTest;return it(t)?.1:t}}),u&&!u.isReady()?u.Se=s.id:u||(u=this._t);const b={geometry:l,material:u};return l.properties.url=h,this.dt[h]=b,b}Ae(t,e,n,r){const{geometry:s,material:i}=this.Ot.createMesh(t,e,n,r);return{geometry:s,material:i}}xe(t,e,r){const s=t.attributes;let i=s._BATCHID&&s._BATCHID.array;if(i&&i.byteOffset&&(i=new i.constructor(i)),s.COLOR_0){const t=s.COLOR_0.array||s.COLOR_0;if(t instanceof Float32Array){const e=new Uint8Array(t.length);for(let n=0;n<e.length;n++)e[n]=Math.round(255*t[n]);s.COLOR_0.array?(s.COLOR_0.array=e,s.COLOR_0.componentType=5121):s.COLOR_0=e}}const o={};for(const t in s){const e=lr(this.it,s[t],{dimension:s[t].itemSize}),n=r[t]||t;o[n]={buffer:e},s[t].quantization&&(o[n].quantization=s[t].quantization),n===r.POSITION&&(o[n].array=s[t].array,o[n].min=s[t].min,o[n].max=s[t].max)}const a=t.indices?t.indices.array?t.indices.array.slice():t.indices:null,c=new n.reshader.Geometry(o,a,0,{static:!0,positionAttribute:r.POSITION,normalAttribute:r.NORMAL,uv0Attribute:r.TEXCOORD_0,uv1Attribute:r.TEXCOORD_1,color0Attribute:r.COLOR_0,tangentAttribute:r.TANGENT,pickingIdAttribute:r._BATCHID,primitive:void 0===t.mode?"triangles":ur(t.mode)});return i&&a&&(c.properties.batchIdData=i,c.properties.batchIdMap=function(t,e){if(!e)return null;const n=new Map;for(let r=0;r<e.length;r++){const s=e[r],i=t[s];let o=n.get(i);o||(o=[],n.set(i,o)),o.push(s)}return n}(i,a)),c.generateBuffers(this.it,{excludeElementsInVAO:e}),c}ye(t,e,r,s){const i=n.mat4.identity(t),o=this.getMap();Sr.x=r[0],Sr.y=r[1];const a=this._prjToPoint(Sr),c=this.Ee(),h=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes());Sr.x=e[0],Sr.y=e[1];const u=this.Yt();let l=this.nt.options.offset;at(l)&&(l=l.call(this.nt,Sr));const f=this.nt.Ct(s).heightOffset||0;return n.vec3.set(Pr,a.x-l[0],a.y-l[1],u*r[2]+u*f),n.mat4.translate(i,i,Pr),n.vec3.set(c,h,h,u),n.mat4.scale(i,i,c),i}qt(t,e){const r=this.nt.Ct(e.Rt),s=r.Te;let i=r.rotation||[0,0,0];i=n.quat.fromEuler(Dr,i[0],i[1],i[2]);const o=r.scale||[1,1,1],a=n.mat4.fromRotationTranslationScale([],i,zr,o),c=n.mat4.identity([]),h=n.mat4.identity([]);n.mat4.translate(c,c,n.vec3.scale(jr,s,-1)),n.mat4.translate(h,h,s);const u=n.mat4.multiply(c,c,t.Bt);n.mat4.multiply(a,a,u);const l=n.mat4.multiply(h,h,a);t.localTransform=l}he(t,e){const r=n.mat4.identity(t),s=this.getMap(),i=this.Ee();Sr.x=e[0],Sr.y=e[1];const o=s.distanceToPointAtRes(100,100,s.getGLRes(),Sr);let a;return a=s.altitudeToPoint?this.xt:o.y/100,n.vec3.set(i,o.x/100*1.01,o.y/100*1.01,a),n.mat4.scale(r,r,i),r}Mt(){const t={x:0,y:0,width:()=>this.rt?this.rt.width:1,height:()=>this.rt?this.rt.height:1},e=[],r=[];this.Jt=new n.reshader.MeshShader({vert:"const float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n#include <draco_decode_vert>\n\nvoid main() {\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_POSITION\n\n vec3 localPos = decode_getPosition(POSITION);\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>n.mat4.multiply(r,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>n.mat3.fromMat4(e,r.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const s=this.At();this.Gt=new n.reshader.PhongShader({extraCommandProps:s}),this.$t=new n.reshader.pbr.StandardShader({extraCommandProps:s}),this.Kt=new n.reshader.EdgeShader({extraCommandProps:{viewport:{x:0,y:0,width:()=>this.rt?this.rt.width:1,height:()=>this.rt?this.rt.height:1},blend:{enable:!0,func:{srcRGB:"src alpha",srcAlpha:1,dstRGB:"one minus src alpha",dstAlpha:"one minus src alpha"},equation:"add"}}});const i=this.nt;mr(i.getRenderer().canvas,this.it,i.getMap()),this.picking=new n.reshader.FBORayPicking(this.ot,{vert:this.$t.vert,extraCommandProps:s,uniforms:this.$t.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO,this.getMap())}At(){return{viewport:{x:0,y:0,width:()=>this.rt?this.rt.width:1,height:()=>this.rt?this.rt.height:1},cull:{enable:!0},stencil:{enable:!0,func:{cmp:(t,e)=>e.meshProperties.isLeaf?"always":">=",ref:(t,e)=>e.meshProperties.level},opFront:{fail:"keep",zfail:"keep",zpass:"replace"},opBack:{fail:"keep",zfail:"keep",zpass:"replace"}},depth:{enable:!0,range:[0,1],func:(t,e)=>e.meshProperties.depthFunc||"<"},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},polygonOffset:{enable:!0,offset:(t,e)=>e.meshProperties.polygonOffset}}}Xt(t){const e=this.getMap(),r=e.getLightManager(),s=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:n.vec3.normalize(s,s)}}St(){const t=this.getMap(),e=this.nt,n=e.getRenderer().canvas,{iblTexes:r,dfgLUT:s}=pr(n),i=gr(t,r,s),o=this.nt.getRenderer(),a=o.getMaskUniforms();i.minAltitude=e.options.altitude||0;const c=o.canvas.gl&&o.canvas.gl.wrap?e.options.opacity||0:1;return i.layerOpacity=c,ot(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[n.width,n.height],polygonFill:[1,1,1,1],polygonOpacity:1}),ot(i,a),i}Ie(t,e,r,s,i,o,a){const c=e.materials&&e.materials[t];if(!c||!c.baseColorTexture&&!c.pbrMetallicRoughness)return null;const h=ot({},s);if(c.baseColorTexture){const t=e.textures[c.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.N(t,o)),h.baseColorFactor=t&&t.image.color||c.baseColorFactor||[1,1,1,1],n&&(h.baseColorTexture=n)}else{if(c.normalTexture){const t=this.N(e.textures[c.normalTexture.index],o),n=c.normalTexture.scale||1;h.normalTexture=t,h.normalMapFactor=n}if(c.occlusionTexture){const t=this.N(e.textures[c.occlusionTexture.index],o),n=c.occlusionTexture.strength||1;h.occlusionTexture=t,h.occlusionFactor=n}if(c.emissiveTexture){const t=this.N(e.textures[c.emissiveTexture.index],o);h.emissiveTexture=t}c.emissiveFactor&&(h.emissiveFactor=c.emissiveFactor);const t=c.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(h.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];r.image&&r.image.color?h.baseColorFactor=h.baseColorFactor?n.vec4.multiply(h.baseColorFactor,h.baseColorFactor,r.image.color):r.image.color:(h.baseColorTexture=this.N(r,o),h.baseColorTexture.getREGLTexture(this.it))}if(it(t.metallicFactor)||(h.metallicFactor=t.metallicFactor),it(t.roughnessFactor)||(h.roughnessFactor=t.roughnessFactor),c.metallicRoughnessTexture){const t=this.N(e.textures[c.metallicRoughnessTexture.index],o);h.metallicRoughnessTexture=t}}}if(c.s3mMaterial)return new n.reshader.Material(h);if(h.environmentExposure=i,h.alphaTest=.1,a.unlit||c.extensions&&c.extensions.KHR_materials_unlit)return h.ambientColor=[1,1,1],h.light0_diffuse=[0,0,0,0],h.lightSpecular=[0,0,0],new n.reshader.PhongMaterial(h);let u=new n.reshader.pbr.StandardMaterial(h);"phong"===r&&(u=n.reshader.PhongMaterial.convertFrom(u));const l=c.pbrMetallicRoughness,f=l&&l.baseColorTexture&&l.baseColorTexture.extensions;return f&&f.KHR_texture_transform&&(u.set("khr_offset",f.KHR_texture_transform.offset||[0,0]),u.set("khr_rotation",f.KHR_texture_transform.rotation||0),u.set("khr_scale",f.KHR_texture_transform.scale||[1,1])),u.doubleSided=!(!a.doubleSided&&!c.doubleSided),u.once("complete",this.vt),u}N(t,e){const r={type:t.type?cr(t.type):"uint8",format:t.format?hr(t.format):"rgba",flipY:!!t.flipY},s=t.image;e.push(s),s.array?r.data=s.array:s.mipmap&&(r.mipmap=s.mipmap),r.width=s.width,r.height=s.height;const i=t.sampler||t.texture&&t.texture.sampler;return i&&(i.magFilter&&(r.mag=ir(i.magFilter)),i.minFilter&&(r.min=or(i.minFilter)),i.wrapS&&(r.wrapS=ar(i.wrapS)),i.wrapT&&(r.wrapT=ar(i.wrapT))),new n.reshader.Texture2D(r,this.wt)}Tt({target:t}){const e=t.Se,n=this.ct[e];if(n.count--,!n.count){const t=n.meshes;this.ht[e]=t,delete this.ct[e];const r=t.ge;delete t.ge,r(null,{mesh:n.meshes,id:e})}}Ee(){return _r}Ne(t){return this.nt.Ne(t)}_pointToPrj(t){const e=this.getMap();return e.getGLZoom?e._pointToPrj(t,e.getGLZoom()):e._pointToPrjAtRes(t,e.getGLRes())}_prjToPoint(t){const e=this.getMap();return e.getGLZoom?e._prjToPoint(t,e.getGLZoom()):e._prjToPointAtRes(t,e.getGLRes(),Er)}fe(t){return"Y"===t?fr:"X"===t?dr:Mr}pick(t,e,n=3){const r=this.nt;if(!r||!r.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const s=this.getMap(),i=this.St(),o=this.picking;o.render(this.bt.getMeshes().filter(t=>!t.bloom),i,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,n,i,{viewMatrix:s.viewMatrix,projMatrix:s.projMatrix,returnPoint:r.options.pickingPoint}));const{meshId:c,pickingId:h,point:u,coordinate:l}=a,f=(0===c||c)&&o.getMeshAt(c);if(!f||!f.geometry)return[];const d=f.properties;u&&u.length&&(u[0]=Math.round(1e5*u[0])/1e5,u[1]=Math.round(1e5*u[1])/1e5,u[2]=Math.round(1e5*u[2])/1e5);const m={batchId:h};if(r.options.debug&&(m.debugInfo=d),d&&d.batchTable){const{batchTable:t,batchTableBin:e,count:n}=d,r=h;for(const s in t)void 0!==t[s].byteOffset?m[s]=Cn(t[s],e,n,r):m[s]=t[s][r]}return[{service:f.properties.serviceIndex,data:m,point:u,coordinate:l}]}Et(t){let e=new Set;for(let n=0,r=t.length;n<r;n++){const r=t[n].data.node;this.Nt(r)&&e.add(r.Ft)}e=Array.from(e),e.sort();const n=new Map,r=e.length;for(let t=0;t<r;t++)n.set(e[t],t);return n}highlight(t){this.Lt=t;const e=this.nt.getRenderer();this.Ut=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelAllHighlight(){this.Lt=null;const t=this.nt.getRenderer();this.Ut=t.getFrameTimestamp(),t.setToRedraw(!0)}showOnly(t){this.Dt=t;const e=this.nt.getRenderer();this.zt=e.getFrameTimestamp(),e.setToRedraw(!0)}cancelShowOnly(){this.Dt=null;const t=this.nt.getRenderer();this.zt=t.getFrameTimestamp(),t.setToRedraw(!0)}Ce(){if(!this.It)return[];const t={},e=[];for(const n in this.It){const r=this.It[n];if(r)for(let n=0;n<r.length;n++){const s=r[n],i=s&&s.geometry;if(!s||!i)continue;const o=s.properties.serviceIndex;t[o]||(t[o]=new Set);const a=i.properties.batchIdData;if(a)for(let n=0;n<a.length;n++)t[o].has(a[n])||(e.push({id:a[n],service:o}),t[o].add(a[n]))}}return e}hasIBL(){const t=this.getMap().getLightManager();return!!(t&&t.getAmbientResource())}}function Jr(t){for(let e=0;e<t.length;e++)t[e]&&(t[e].array&&(t[e].array=null),t[e].mipmap&&(t[e].mipmap=null),t[e].indices&&(t[e].indices=null))}const Zr=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")},Kr=Zr(),Yr=Kr.gl_trans__coders=Kr.gl_trans__coders||{};function Qr(t,e){if(e)for(let n=0;n<e.length;n++){t[e[n].id||e[n].index]=e[n]}}Yr.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=Kr.gl_trans__coders=Kr.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${Zr.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in s)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(i+='tran_____scoders["'+t+'"] ='+s[t].toString()+"\n;");return i+="\n"+e.substring(r.length),i},Yr.registerTranscoder=function(t,e){Yr[t]=e},Yr.getTranscoder=function(t){return Yr[t]};const Wr=[];class ts{constructor(t,e,n,r){this.Re=t,this.Rt=e,this.Pe=r,this.ke=n.version,t.indexOf("i3s:tileset:")<0?(this.ke<=1.6?this.Be="root":this.Be=0,n.version=this.ke):(this.Be=t.substring("i3s:tileset:".length),this.ke>1.6&&(this.Be=parseInt(this.Be))),this.Re=t,this.Le=n}load(){const t=this.Le,e=t.layerScene.baseUrl;if(this.ke<=1.6)return t[this.Be]&&t[this.Be].lodSelection?(this.Ue=t[this.Be],this.De()):new Promise(n=>{let r=e+"/nodes/"+this.Be;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Pe(this.Rt,r,()=>{this.Ue=t[this.Be],n(this.De())})});if(this.ke>=1.7){if(t[this.Be])return this.Ue=t[this.Be],this.De();const n=Math.floor(this.Be/t.nodesPerPage);return new Promise(r=>{let s=e+"/nodepages/"+n;t.layerScene.eslpk&&(s+=".json"),this.Pe(this.Rt,s,()=>{this.Ue=t[this.Be],r(this.De())})})}return null}getTileset(){return this.ze}getChildrenURL(){return this.Fe}De(){const t=this.Le,e=t.layerScene.baseUrl,n=this.Ue.children,r=[],s={};if(n)for(let i=0;i<n.length;i++)if(this.ke<=1.6){const o=n[i].id;if(t[o])continue;const a=o;s[a]||(s[a]=new Promise(n=>{let r=e+"/nodes/"+a;t.layerScene.eslpk&&(r+="/3dNodeIndexDocument.json"),this.Pe(this.Rt,r,()=>{n()})}),r.push(s[a]))}else{const o=n[i];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);s[a]||(s[a]=new Promise(n=>{let r=e+"/nodepages/"+a;t.layerScene.eslpk&&(r+=".json"),this.Pe(this.Rt,r,()=>{n()})}),r.push(s[a]))}return r.length?Promise.all(r).then(()=>this.je()):this.je()}je(){return Promise.resolve(this.Ve())}qe(t){Qr(this.Le,t)}Ve(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.He(this.Ue,!0)}}He(t){const e=this.ke,n=this.Le,r=t,s=r.obb,i=r.mbs,o={};let a;if(i)a=es([],i[0],i[1],i[2]),o.sphere=[...a,i[3]];else if(s){a=es([],s.center[0],s.center[1],s.center[2]);const t=function(t,e,n){const r=function(t,e){var n=e[0],r=e[1],s=e[2],i=e[3],o=n+n,a=r+r,c=s+s,h=n*o,u=r*o,l=r*a,f=s*o,d=s*a,m=s*c,b=i*o,p=i*a,g=i*c;return t[0]=1-l-m,t[3]=u-g,t[6]=f+p,t[1]=u+g,t[4]=1-h-m,t[7]=d-b,t[2]=f-p,t[5]=d+b,t[8]=1-h-l,t}([],n);return r[0]=r[0]*e[0],r[1]=r[1]*e[0],r[2]=r[2]*e[0],r[3]=r[3]*e[1],r[4]=r[4]*e[1],r[5]=r[5]*e[1],r[6]=r[6]*e[2],r[7]=r[7]*e[2],r[8]=r[8]*e[2],[...t,...r]}(a,s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],n=t[4]+t[7]+t[10],r=t[5]+t[8]+t[11];Lt(Wr,e,n,r);const i=$t(Wr);o.sphere=[...a,i]}let c=1/0,h=0;if(r.mbs?h=r.mbs[3]:r.obb&&(h=Math.max(Math.max(r.obb.halfSize[0],r.obb.halfSize[1]),r.obb.halfSize[2])),void 0!==r.lodThreshold)if("maxScreenThresholdSQ"===n.lodSelectionMetricType){c=h/(Math.sqrt(r.lodThreshold)/(.25*Math.PI))}else console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==r.lodSelection)for(let t=0;t<r.lodSelection.length;t++)"maxScreenThreshold"===r.lodSelection[t].metricType&&(c=h/r.lodSelection[t].maxError);(c===1/0||isNaN(c))&&(c=1e5);const u=16*c,l=It([]),f=r.children;let d;if(f){d=[];const t=this.Le;for(let n=0;n<f.length;n++){const r=e<=1.6?f[n].id:f[n];if(!t[r]){d=null;break}d.push(this.He(t[r]))}}const m={refine:"REPLACE",boundingVolume:o,transform:l,geometricError:u};return e<=1.6?t.lodSelection?t.geometryData&&(m.content={uri:"i3s:mesh:"+(t.id||t.index)}):m.content={uri:"i3s:tileset:"+(t.id||t.index)}:f&&f.length&&!d?m.content={uri:"i3s:tileset:"+(t.id||t.index)}:r.mesh&&(m.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(m.children=d),m}getJSON(){return this.Ue}}function es(t,e,n,r){return hn(t,ut(e),ut(n),r)}const ns=!!Yr.ktx2,rs=n.mat4.identity([]),ss=(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){const t=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(t instanceof WebAssembly.Module)return new WebAssembly.Instance(t)instanceof WebAssembly.Instance}}catch(t){}return!1})();function is(t){return t.indexOf("i3s:mesh")>=0}const os="i3s:mesh:".length;function as(t,e,n,r,s){const i=e.layerScene.eslpk,o=function(t,e){const n=e.substring(os);return t>=1.7?parseInt(n):n}(e.version,t),a=e[o],c=e.layerScene.baseUrl,h=[];let u=!1;const l=rs;let f,d;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;if(!t)return null;let n=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;i&&(n+=".bin");const r={geometry:{url:n,info:e.layerScene.store.defaultGeometrySchema}};let s=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(s){const t=e.layerScene.store.textureEncoding[0];let n;n="image/jpeg"===t?"jpg":"png",i&&(s+="."+n);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+s,factor:1,format:n,mimeType:t},metallicFactor:0}};r.material=o}h.push(r)}else{f=a.mesh.geometry,d=a.mesh.material;const t=e.layerScene.geometryDefinitions[f.definition],{geometryBuffers:o}=t;u=r&&2===o.length;const l=Yr.draco&&u?o[1]:o[0],m=Yr.draco&&u?1:0;let b=c+`/nodes/${f.resource}/geometries/`+m;i&&(b+=".bin");const p={geometry:{url:b,info:l}};if(s&&ss&&u&&!Yr.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const g=e.layerScene.materialDefinitions,y=e.layerScene.textureSetDefinitions;let w,v=0;if(d&&(v=g[d.definition]),g){w=function(t,e,n,r,s,i){const o=JSON.parse(JSON.stringify(t));return function t(e,n,r,s,i,o){for(const a in e)if(e[a]&&e[a].textureSetDefinitionId>=0){const t=n[e[a].textureSetDefinitionId],c="images/"+t.formats[0].format,h=cs(t.formats,i),u={url:r+`/nodes/${s}/textures/${h.name}`,factor:void 0===e[a].factor?1:e[a].factor,format:h.format,mimeType:c};if(o){let t="";switch(h.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=h.format}u.url+="."+t}e[a]=u}else ct(e[a])&&t(e[a],n,r,s,i,o)}(o,e,n,r,s,i),o}(v,y,c,d.resource,n,e.layerScene.eslpk)}else w={pbrMetallicRoughness:{metallicFactor:0}};p.material=w,h.push(p)}return{dracoCompression:u,meshes:h,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:l}}function cs(t,e){for(let n=0;n<=t.length;n++){const r=t[n].format;if("dds"===r&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[n];if("jpg"===r||"png"===r)return t[n];if("ktx2"===r&&ns)return t[n]}return null}const hs=new Set,us=[];class ls extends(n.MaskRendererMixin(s.renderer.CanvasRenderer)){constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Je(t.getId(),1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.Ge={},this.$e=[],this.Pe=this.Xe.bind(this)}getAnalysisMeshes(){if(!this.painter)return us;const t=this.painter.getPaintedMeshes();if(!t)return us;const e=[],{b3dmMeshes:n,pntsMeshes:r,i3dmMeshes:s}=t;return n.length&&Tt(e,n),r.length&&Tt(e,r),s.length&&Tt(e,s),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.$e.length||super.needToRedraw())}getFrameTimestamp(){return this.Je}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){this.Je=t;const n=this.prepareCanvas();if(n&&!n.intersects(this.canvasExtent2D))return void this.completeRender();const{root:r,tiles:s}=this.layer.getTiles(),i=s.length;if(!s||!i)return void this.completeRender();this.Ze(),this.Ke();const{selectedTiles:o,leaves:a,requests:c}=this.Ye(r,s);c.length&&this.loadTiles(c),this.Qe(o,a,e),this.We(),c.length||this.completeRender()}Ye(t,e){const n=this.layer.getRootTiles();let r=[];this.tn();let s=0;const i=this.nn(),o={};let a=!1,c=!1;for(let t=0;t<e.length;t++){const i=e[t],h=i.node;if(o[h.id])continue;const u=n[h.Rt];o[h.id]=1;let l=!1;const f=this.getCachedTile(h.id);if(this.rn(h.id)?(s++,l=c=!0,this.tilesLoading[h.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=c=!0),(!i.node.sn||u.isS3M||!i.node.children||i.node.sn<=500)&&(a=!0,i.selected=!0,i.data=f)):this.painter.has(h)||(l=c=!0,r.push(h)),!l)continue;if(this.in(i))a=!0;else{this.an(i).length&&(a=!0)}}let h=[],u={};if(a&&({selectedTiles:h,leaves:u}=this.cn(t)),r.length>1&&(r.sort(fs),i)){const t=i-s;r=t>0?r.slice(0,t):[]}return{loading:c,requests:r,selectedTiles:h,leaves:u}}cn(t){const e=[],n={};let r;const s=[t],i=[];for(;s.length>0||i.length>0;){if(i.length>0){const t=i[i.length-1];if(t.hn===s.length){i.pop(),t===r&&(t.leave=!0,n[t.node.id]=1),e.push(t);continue}}const t=s.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)n[t.node.id]=1,t.selectionDepth=i.length,e.push(t);else{if(t.selectionDepth=i.length,r=t,0===o.length){t.leave=!0,n[t.node.id]=1,e.push(t);continue}i.push(t),t.hn=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}in(t){if(!t.parent)return null;let e=t.parent;for(;e&&e.level>=0;){const t=e.node.id;if(this.tileCache.has(t))return e.selected=!0,e.data=this.tileCache.get(t),e;e=e.parent}return null}an(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.Ft+1,r=[t.node];for(;r.length>0;){const s=r.pop().children;for(let i=0,o=s.length;i<o;i++){if((!s[i].content||!s[i].content.url)&&s[i].children&&s[i].children.length){r.push(s[i]);continue}const o=s[i].id;if(this.tileCache.has(o)){const n=this.layer.un(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].Ft<=n&&r.push(s[i])}}return e}Qe(t,e,n){this.tileCache.markAll(!1);for(let e=0,n=t.length;e<n;e++){const n=t[e].data;n.current=!0,this.tileCache.add(t[e].node.id,n)}this.tileCache.shrink();const r={tiles:t,leaves:e};this.onDrawTileStart(r);const s=this.painter.paint(t,e,n);this.onDrawTileEnd(r),s&&this.layer.fire("canvasisdirty",{renderCount:s})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,n=t.length;e<n;e++){const n=t[e];this.tilesLoading[n.id]={current:!0,node:n},this.loadTile(n)}}loadTile(t){let e=t.content.url;if(wt(e)){const n=vt(e);return this.ln(e,n,t),null}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const n=t.Rt,r=this.dn[n];return new ts(e,n,r,this.Pe).load().then(n=>{this.onTilesetLoad(n,t,e)})}t&&At(e)&&!is(e)&&(e=t.baseUrl+e);const n=this.layer.Ct(t.Rt);if(n.ajaxInMainThread){let r=n.urlParams;r&&(r=(e.indexOf("?")>0?"&":"?")+r);let s=ge.getArrayBuffer(e+(r||""),n.fetchOptions);const i=s.xhr;s=s.then(n=>{delete this.Ge[e],n?this.ln(e,n.data,t):this.onTileError(null,t,e)}).catch(n=>{delete this.Ge[e],this.onTileError(n,t,e)}),this.Ge[e]=i}else this.ln(e,null,t);return null}ln(t,e,r){let s=this.o;s||(s=n.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=s);const i=this.layer.Ct(r.Rt);i.isSuperMapiServer&&(t=function(t,e){const n=t.substring(e.length).split("/"),r=[];for(let t=0;t<n.length;t++)r.push(encodeURIComponent(n[t]));return e+r.join("/")}(t,r.baseUrl));const o={url:this.layer.getTileUrl(t,r.baseUrl,this.layer.mn[r.Rt]),arraybuffer:e,rootIdx:r.Rt,upAxis:r.de,transform:r.matrix,supportedFormats:s};if(is(t)){const e=this.dn[r.Rt];if(o.i3sInfo=as(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},r,t)}o.service=ot({},i),i.offset&&delete o.service.offset,this.workerConn.loadTile(this.layer.getId(),o,(e,n)=>{if(e)return void this.onTileError(e,r,t);const{magic:s}=n;"b3dm"===s||"pnts"===s||"i3dm"===s||"cmpt"===s?this.$e.push({data:n,tile:r}):this.onTilesetLoad(n,r,t),i.debugShowBoundingVolume&&this.painter.we(r)})}Ke(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.$e.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.$e.shift(),{magic:r}=t;"b3dm"===r?this.painter.createB3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.bn(t,e,n,r)}):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,(n,{mesh:r})=>{this.bn(t,e,n,r)}):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,(n,{mesh:r})=>{this.bn(t,e,n,r)}):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,(n,{mesh:r})=>{this.bn(t,e,n,r)}),n++}}bn(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this.pn(r);e.memorySize=n,this.onTileLoad(t,e)}}pn(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this.pn(t[n]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.gn(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(this.layer.Oe=t.extensions&&t.extensions["s3m:VertexCompressionType"],t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.yn(t,e,n):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,n)))}onTileError(t,e,n){if(!this.layer)return;const r=n||e.content.url,s=t&&t.message||t;hs.has(s)||(console.warn("failed to load 3d tile: "+r),console.warn(t),hs.add(s)),delete this.tilesLoading[e.id],this.wn(e,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}wn(t,e){const n={loadTime:s.Util.now(),current:!0,error:e,node:t};this.tileCache.add(t.id,n)}gn(t){const e={loadTime:s.Util.now(),current:!0,node:t};this.tileCache.add(t.id,e)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.Ct(t.node.Rt).ajaxInMainThread){const t=this.Ge[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.Ge[e]}tn(){if(this.tilesLoading)for(const t in this.tilesLoading)this.tilesLoading[t].current=!1}deleteTile(t){this.painter.deleteTile(t)}createContext(){const t=this.layer,e=t.options.glOptions||{alpha:!0,depth:!0,stencil:!0,preserveDrawingBuffer:!0,antialias:t.options.antialias},r=this.canvas.gl&&this.canvas.gl.wrap;r?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.vn(this.canvas,e)),this.regl=this.regl||n.createREGL({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),r&&(this.canvas.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height)),this.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height),this.painter=new Xr(this.regl,t),this.layer.Tn(),this.layer.fire("contextcreate",{regl:this.regl})}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Ge("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=ot({},n),delete n.offset,n.projection=t.getSpatialReference().getProjection().code;const r=this.layer.getId();e.addLayer(r,n,t=>{if(t)throw t;this.layer&&(this.ready=!0,this.layer.fire("workerready"))})}onRemove(){this.painter&&this.painter.remove(),this.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),t=>{if(t)throw t}),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.We(!0),this.tileCache.reset(),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}We(t){this._n||(this._n=Date.now());const e=Date.now();if(t||!(e-this._n<this.layer.options.retireInterval)){this._n=e;for(const e in this.tilesLoading){const n=this.tilesLoading[e];!t&&n.current||this.abortTileLoading(n)}}}nn(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}vn(t,e){const n=["webgl","experimental-webgl"];let r=null;for(let s=0;s<n.length;++s){try{r=t.getContext(n[s],e)}catch(t){}if(r)break}return r}rn(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,n){return En(t,e,0,n)}Ze(){if(!this.Mn)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const n=[];for(const r in this.Mn){const s=this.Mn[r];if("pending"===s.status)continue;s.status="pending";const i=s.rootIdx;if(n.push(ge.getJSON(r).then(t=>{delete this.Mn[r];const e=this.dn[i];if(e){t.nodes?Qr(e,t.nodes):(e[t.id]=t,Qr(e,t.children));for(let t=0;t<s.length;t++)s[t]();this.setToRedraw()}else this.setToRedraw()})),e++,e>=t)break}n.length&&Promise.all(n)}Xe(t,e,n){this.Mn||(this.Mn={}),this.Mn[e]=this.Mn[e]||[],this.Mn[e].rootIdx=t,this.Mn[e].push(n),this.setToRedraw()}yn(t,e,n){this.dn||(this.dn=[]);const r=e.Rt;this.dn[r]||(this.dn[r]={});const s=this.dn[r],i=this.layer.Ct(r);t.layers&&(t=t.layers[0],"/"!==n[n.length-1]&&(n+="/"),n+="layers/0"),s.version=+(i.i3sVersion||t.store.version),function(t,e,n,r,s,i){if(!s.layerScene){s.layerScene=t,s.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,s.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=r;s.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0;if(e.endsWith(".json")){const t=r.lastIndexOf("/");e=t<0?"./":r.substring(0,t)}s.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new ts(r,e,s,i).load()}(t,r,0,n,s,this.Pe).then(t=>{this.onTilesetLoad(t,e,n)})}pick(t,e,n){if(!this.painter)return[];const r=this.pickingFBO,{width:s,height:i}=this.canvas;return!this.pickingFBO||r.width===s&&r.height===i||r.resize(s,i),this.painter.pick(t,e,n&&n.tolerance)}highlight(t){if(this.Lt||(this.Lt=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Lt[n];r||(r=this.Lt[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Lt[e];n||(n=this.Lt[e]=new Map),n.set(t.id,t)}this.painter.highlight(this.Lt)}cancelHighlight(t,e){if(!this.Lt)return;const n=this.Lt[t];if(n){if(Array.isArray(e))for(let t=0;t<e.length;t++)n.delete(e[t]);else n.delete(e);n.size||(this.Lt[t]=null),this.painter.highlight(this.Lt)}}cancelAllHighlight(){delete this.Lt,this.painter.cancelAllHighlight()}showOnly(t){if(this.Dt||(this.Dt=[]),Array.isArray(t))for(let e=0;e<t.length;e++){const n=t[e].service||0;let r=this.Dt[n];r||(r=this.Dt[n]=new Map),r.set(t[e].id,t[e])}else{const e=t.service||0;let n=this.Dt[e];n||(n=this.Dt[e]=new Map),n.set(t.id,t)}this.painter.showOnly(this.Dt)}cancelShowOnly(){delete this.Dt,this.painter.cancelShowOnly()}Ce(){return this.painter?this.painter.Ce():[]}}function fs(t,e){return t.te-e.te}function ds(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function ms(t,e,n){return Math.sqrt(function(t,e,n){const r=Dt(bs,n,t),s=ds(ps,e,0),i=ds(gs,e,1),o=ds(ys,e,2),a=$t(s),c=$t(i),h=$t(o);jt(s,s),jt(i,i),jt(o,o);const u=ws;u[0]=Vt(r,s),u[1]=Vt(r,i),u[2]=Vt(r,o);let l,f=0;u[0]<-a?(l=u[0]+a,f+=l*l):u[0]>a&&(l=u[0]-a,f+=l*l);u[1]<-c?(l=u[1]+c,f+=l*l):u[1]>c&&(l=u[1]-c,f+=l*l);u[2]<-h?(l=u[2]+h,f+=l*l):u[2]>h&&(l=u[2]-h,f+=l*l);return f}(t,e,n))}const bs=[],ps=[],gs=[],ys=[],ws=[];const vs=2*Math.PI;class Ts{constructor(t,e,n,r){this.west=t,this.south=e,this.east=n,this.north=r}static contains(t,e){let n=e[0];const r=e[1],s=t.west;let i=t.east;return i<s&&(i+=vs,n<0&&(n+=vs)),(n>s||Mn(n,s,1e-14))&&(n<i||Mn(n,i,1e-14))&&r>=t.south&&r<=t.north}static southwest(t,e){return e[0]=t.west,e[1]=t.south,e[2]=0,e}static northeast(t,e){return e[0]=t.east,e[1]=t.north,e[2]=0,e}static southeast(t,e){return e[0]=t.east,e[1]=t.south,e[2]=0,e}static northwest(t,e){return e[0]=t.west,e[1]=t.north,e[2]=0,e}}const _s=[0,0,1];function Ms(t,e){return hn(e,t[0],t[1],t[2])}class Os{constructor(t,e){this.normal=n.vec3.copy([],t),this.distance=e}static fromPointNormal(t,e,r){const s=-n.vec3.dot(e,t);return n.vec3.copy(r.normal,e),r.distance=s,r}}const As=[],xs=[],Is=[],Ss=[],Es=[],Ns=[],Cs=[],Rs=[],Ps=[],ks=[],Bs=new Os([1,0,0],0),Ls=[];class Us{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new Ts(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){let r=0;if(!Ts.contains(this.rectangle,e)){const e=this.southwestCornerCartesian,s=this.northeastCornerCartesian,i=this.westNormal,o=this.southNormal,a=this.eastNormal,c=this.northNormal,h=n.vec3.subtract(Ls,t,e),u=n.vec3.dot(h,i),l=n.vec3.dot(h,o),f=n.vec3.subtract(Ls,t,s),d=n.vec3.dot(f,a),m=n.vec3.dot(f,c);u>0?r+=u*u:d>0&&(r+=d*d),l>0?r+=l*l:m>0&&(r+=m*m)}const s=e[2],i=this.minimumHeight,o=this.maximumHeight;if(s>o){const t=s-o;r+=t*t}else if(s<i){const t=i-s;r+=t*t}return Math.sqrt(r)}computeBox(t){const e=this;Ms(Ts.southwest(t,xs),e.southwestCornerCartesian),Ms(Ts.northeast(t,xs),e.northeastCornerCartesian),As[0]=t.west,As[1]=.5*(t.south+t.north),As[2]=0;const r=Ms(As,Is),s=n.vec3.cross(Es,r,_s);n.vec3.normalize(e.westNormal,s),As[0]=t.east;const i=Ms(As,Rs),o=n.vec3.cross(Es,_s,i);n.vec3.normalize(e.eastNormal,o);const a=n.vec3.subtract(Es,r,i),c=n.vec3.normalize(Ss,a),h=t.south;let u;if(h>0){As[0]=.5*(t.west+t.east),As[1]=h;const r=Ms(As,Ps);n.vec3.copy(ks,c);const s=Os.fromPointNormal(e.southwestCornerCartesian,e.westNormal,Bs);Ds(Ps,ks,s,e.southwestCornerCartesian),u=vn(r,Ns)}else u=Tn(Ts.southeast(t,xs),Ns);const l=n.vec3.cross(Cs,u,a);n.vec3.normalize(e.southNormal,l);const f=t.north;let d;if(f<0){As[0]=.5*(t.west+t.east),As[1]=f;const r=Ms(As,Ps);n.vec3.scale(ks,c,-1);const s=Os.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,Bs);Ds(Ps,ks,s,e.northeastCornerCartesian),d=vn(r,Ns)}else d=Tn(Ts.northwest(t,xs),Ns);const m=n.vec3.cross(Cs,a,d);n.vec3.normalize(e.northNormal,m)}}function Ds(t,e,r,s){const i=t,o=e,a=r.normal,c=n.vec3.dot(a,o);if(Math.abs(c)<1e-15)return;const h=(-r.distance-n.vec3.dot(a,i))/c;return h<0?void 0:(s=n.vec3.scale(s,o,h),n.vec3.add(s,i,s))}const zs={"maxGPUMemory":s.Browser.mobile?32:1024,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":5,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]},Fs=new s.Extent(0,0,0,0),js=[],Vs=[],qs=[],Hs=[],Gs=new s.Point(0,0),$s=[],Xs=new s.Coordinate(0,0),Js=n.mat4.identity([]),Zs=[0,0],Ks=[1,1,1,1,-1,1,-1,-1,1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,-1,1,-1];class Ys extends(n.MaskLayerMixin(s.Layer)){constructor(t,e){super(t,e),this.On(),this.Ge={},this.ve=[]}On(){const t=this.options.services.map(t=>t.url);this.An=this.An||{},this.mn=this.mn||[];for(let e=0;e<t.length;e++){const n=t[e];let r=this.An[n];void 0===r&&(r=this.An[n]=this.mn.length),this.mn[r]=ti(n,r,this.options.services[e])}this.fire("rootready",{roots:this.mn.slice(0)})}showService(t){return this.updateService(t,{visible:1}),this}hideService(t){return this.updateService(t,{visible:0}),this}setToRedraw(){const t=this.getRenderer();t&&t.setToRedraw()}addService(t){this.options.services=this.options.services||[],this.options.services.push(t),this.On();const e=this.getRenderer();return e&&e.setToRedraw(),this}updateService(t,e){if(!e)return this;const n=this.options.services;if(n&&n[t]&&ot(n[t],e),!it(e.visible)){const r=n[t].url,s=this.An[r];this.mn&&this.mn[s]&&(this.mn[s].visible=e.visible)}const r=this.getRenderer();return r&&r.setToRedraw(),this}removeService(t){const e=this.options.services;if(e&&e[t]){const n=e[t].url,r=this.An[n];this.mn[r]&&(this.mn[r]=null),delete this.An[n],e.splice(t,1)}const n=this.getRenderer();return n&&n.setToRedraw(),this}getTileUrl(t,e,n){const r=n&&n.service&&n.service.subdomains;if(r&&n.domainKey){const e=r.length;if(e){const s=[...t].reduce((t,e)=>t+e.charCodeAt(),0)%e;return t.replace(n.domainKey,r[s])}}return t}getExtent(t){if(!t&&0!==t){const t=new s.Extent;for(let e=0;e<this.mn.length;e++)if(this.mn[e].boundingVolume){const n=this.boundingVolumeToExtent(this.mn[e]);t._combine(n)}return t}return this.mn[t]&&this.mn[t].boundingVolume?this.boundingVolumeToExtent(this.mn[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.xn?Js:t.matrix,r=this.getMap();if(t.boundingVolume.region){const e=t.boundingVolume.region;return new s.Extent(lt(e[0]),lt(e[1]),lt(e[2]),lt(e[3]))}if(t.boundingVolume.sphere){const i=t.boundingVolume.sphere,o=bn([],n.vec3.transformMat4([],i,e)),a=i[3],c=r.locate(o,-a,a),h=r.locate(o,a,-a);return new s.Extent(c,h)}if(t.boundingVolume.box){const i=t.boundingVolume.box,o=n.vec3.transformMat4([],i,e),a=new s.Coordinate(bn([],o)),c=i.slice(3);n.mat3.multiply(c,n.mat3.fromMat4([],t.matrix),c);const h=n.vec3.length(c.slice(0,3)),u=n.vec3.length(c.slice(3,6)),l=n.vec3.length(c.slice(6,9)),f=Math.max(h,u,l),d=r.locate(a,-f,f),m=r.locate(a,f,-f);return new s.Extent(d,m)}return null}getRootTiles(){return this.mn}getTiles(){const t=this.getRenderer();if(!t.ready)return this.In(),{tiles:Hs};const e=this.getMap(),r=e.cameraPosition;let s,i;if(e.getGLZoom)i=e.pointToDistance(r[2],0,e.getGLZoom()),Xs.set(r[0],r[1]),s=e.pointToCoord(Xs,e.getGLZoom());else{const t=e.getGLRes();i=e.pointAtResToDistance(r[2],0,t),Xs.set(r[0],r[1]),s=e.pointAtResToCoord(Xs,t)}this.Sn=this.Sn||[],n.vec3.set(this.Sn,ut(s.x),ut(s.y),i),this.En=hn(this.En||[],this.Sn[0],this.Sn[1],this.Sn[2]),this.Nn=2*Math.tan(.5*ut(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const h=[];for(let e=0;e<this.mn.length;e++){const n=this.mn[e];if(!n||!n.visible)continue;let r=1/0;const s=[n],i=this.Cn(e);for(;s.length>0;){const e=s.pop();for(e.id||this.Rn(e);c.level>=e.Ft;)c=c.parent;const n=this.Pn(e,i,o);if(n<1){let t=c;for(;t&&!t.content;)t=t.parent;0===n&&t&&t.content&&this.kn(h,t);if(!1===this.options.services[e.Rt].alwaysShow)continue;if(!(0===n&&e.Ft<=r))continue;e.content&&(r=e.Ft)}e.te<1/0&&this.Bn(e);const a=this.un(e,c);c.children.push(a);const u=e.children,l=u&&u.length,f=a.content;if(!l&&f&&this.kn(h,a),l){f&&"add"===e.refine&&this.kn(h,a),c=a;const n=u[0].parent;let r=!1;for(let i=0,o=u.length;i<o;i++){if(n){const e=t.getCachedTile(u[i].id);if(e&&e.error&&404!==e.error.status)continue;r=!0}else{r=!0,u[i].parent=e,u[i].de=e.de,u[i].baseUrl=e.baseUrl;const t=u[i].content&&(u[i].content.url||u[i].content.uri);t&&(wt(t)||t.indexOf("i3s:")>=0?u[i].baseUrl=e.baseUrl:At(t)?u[i].content.url=e.baseUrl+t:u[i].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}s.push(u[i])}!r&&f&&this.kn(h,a)}}}return{root:a,tiles:h}}kn(t,e){const{viewerRequestVolume:n}=e.node;n&&!function(t,e,n){if(n.region){const e=n.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(n.sphere)return Qs(n,e);if(n.box)return 0===Ws(n,e)}return!1}(this.Sn,this.En,n)||t.push(e)}un(t,e){return{id:t.id,node:t,children:[],level:t.Ft,parent:e,content:t.content&&t.content.url}}Rn(t){t.id=s.Util.GUID(),t.matrix=t.transform||n.mat4.identity([]),t.Ln=this.Un(t),t.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(t)||(t.matrix=n.mat4.multiply(t.matrix,t.parent.matrix,t.matrix)),t.Rt=t.parent.Rt,void 0===t.Ft&&(t.Ft=t.parent.Ft+1),t.maxExtent=t.parent.maxExtent),t.refine=t.refine&&t.refine.toLowerCase()||"replace",t.content&&!t.content.url&&t.content.uri&&(t.content.url=t.content.uri)}Ct(t){return this.mn[t].service}Dn(t){const e=t.boundingVolume;if(!e||e.xn&&!this.zn(t))return;const r=this.Ct(t.Rt),s=r.heightOffset||0,i=this.options.offset,o=at(i)||i[0]||i[1],a=r.coordOffset||Zs;if(!Array.isArray(a))throw new Error("service.coordOffset must be an array");if(!e.xn&&(!t.boundingVolume||!s&&n.mat4.exactEquals(t.matrix,Js)&&!o&&a===Zs))return;e.box&&e.region&&delete e.region;const{region:c,box:h,sphere:u}=e;if(e.coordOffset=[a[0],a[1]],e.heightOffset=s,c){e.originalVolume||(e.originalVolume=c.slice(0));const t=e.originalVolume,n=this.Fn([lt(t[0]),lt(t[1])]);c[0]=ut(n.x+a[0]),c[1]=ut(n.y+a[1]);const r=this.Fn([lt(t[2]),lt(t[3])]);c[2]=ut(r.x+a[0]),c[3]=ut(r.y+a[1]),c[4]=t[4]+s+(a[2]||0),c[5]=t[5]+s+(a[2]||0)}else if(h||u){e.originalVolume||(e.originalVolume=(h||u).slice(0));const r=h||u,i=e.originalVolume,o=n.vec3.transformMat4(js,i,t.matrix),c=bn(Vs,o),l=this.Fn([c[0]+a[0],c[1]+a[1]]);c[0]=l.x,c[1]=l.y,c[2]+=s+(a[2]||0),hn(r,ut(c[0]),ut(c[1]),c[2])}e.xn=!0}zn(t){const e=t.boundingVolume,n=this.Ct(t.Rt),r=n.heightOffset||0,s=n.coordOffset||Zs;return e.coordOffset[0]!==s[0]||e.coordOffset[1]!==s[1]||e.heightOffset!==r}Un(t){return void 0===t.geometricError||!t.boundingVolume}Bn(t){let e=t.parent;for(;e&&e.Ln&&!(e.te<=t.te);)e.te=t.te,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const n=e.content.url;e.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const r=this.getRenderer();r&&r.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const s=this.Ct(e.Rt),i=(t.asset&&t.asset.gltfUpAxis||e&&e.de||s.upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const o=r.indexOf("realspace/")>-1;0===e.Ft&&(t.asset&&t.asset.s3mType&&o||s.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s,c=!!t.asset.s3mType;if(t.root.de=i,e){const r=e.Rt,s=this.mn[r];c&&!s.isS3M&&(s.isS3M=c);const i=e.boundingVolume;ot(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",i&&(e.boundingVolume=i);const o=t.root.transform;o&&(e.parent?a||(e.matrix=n.mat4.multiply([],e.parent.matrix,o)):e.matrix=o),e.jn=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.Ln=this.Un(e);const h=e.content&&(e.content.url||e.content.uri);h&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),!a&&h&&!wt(h)&&At(h)&&(e.content.url=e.baseUrl+h),t.root&&!e.parent&&this.Vn(e)}this.In(),this.fire("loadtileset",{tileset:t,index:e&&e.Rt,url:r})}Pn(t,e,n){if(t.te=1/0,0===t.Ft||t.Ln)return this.Vn(t),1;if(this.Dn(t),!this.qn(t,e,n))return-1;if(0===t.geometricError)return 1;let r=this.Ct(t.Rt).maximumScreenSpaceError;null==r&&(r=16);let s=this.Hn(t);return 0===s&&t.parent&&(s=.5*(t.parent.sn||0)),s>=r?1:0}Ne(t,e){e||(e=new s.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(t,n.getGLZoom(),e):n.coordToPointAtRes(t,n.getGLRes(),e)}qn(t,e,n){const r=t.id;let i=this.ve[r]&&this.ve[r].obbox;const{boundingVolume:o}=t,c=o.region,h=o.box,d=o.sphere;if(!i)if(c)this.ve[r]=this.Gn(t),i=this.ve[r].bbox,i.center=this.ve[r].coordCenter;else if(h)this.ve[r]=this.$n(t),i=this.ve[r].obbox,i.center=this.ve[r].coordCenter;else if(d){i=this.ve[r]=this.Xn(t);const e=bn(js,d),n=new s.Coordinate(e);i.center=n}if(e){if(c)Fs.xmin=i[0][0],Fs.ymin=i[0][1],Fs.xmax=i[1][0],Fs.ymax=i[1][1];else if(d){const t=i[2];Fs.xmin=i[0][0]-t,Fs.ymin=i[0][1]-t,Fs.xmax=i[0][0]+t,Fs.ymax=i[0][1]+t}else if(h){const t=i[1],e=i[2];Fs.xmin=i[0][0]-t,Fs.ymin=i[0][1]-e,Fs.xmax=i[0][0]+t,Fs.ymax=i[0][1]+e}if(!e.intersects(Fs))return!1}return c?u(n,i):d?function(t,e,n){f(t);for(var r=e[0],s=-e[1],i=0;i<6;i++){if(!n||"0"!==n.charAt(i))if(m(a[i],r)<s)return!1}return!0}(n,i):!!h&&function(t,e,n){f(t);for(var r=0;r<6;r++){if(!n||"0"!==n.charAt(r))if(!l(a[r],e))return!1}return!0}(n,i)}Gn(t){const e=this.getMap(),n=e.getGLRes(),r=t.boundingVolume.region;let{ws:i,en:o}=function(t){const e=t[0],n=t[1],r=t[2],s=t[3],i=t[4],o=t[5],a=hn([],e,n,i),c=hn([],r,s,o),h=bn(a,a),u=bn(c,c);return{ws:h,en:u}}(r);i=new s.Coordinate(i),o=new s.Coordinate(o);const a=e.coordToPointAtRes(i,n);a.z=e.altitudeToPoint(i.z,n);const c=e.coordToPointAtRes(o,n);c.z=e.altitudeToPoint(o.z,n);const h=[c.x,a.y,c.z,c.x,c.y,c.z,a.x,c.y,c.z,a.x,a.y,c.z,c.x,a.y,a.z,c.x,c.y,a.z,a.x,c.y,a.z,a.x,a.y,a.z],u=[(h[0]+h[18])/2,(h[1]+h[19])/2,(h[2]+h[20])/2],l=e.pointAtResToCoord(new s.Point(u),n);l.z=(i.z+o.z)/2;const f=this.Ct(t.Rt).Te,d=[h.slice(21,24),h.slice(3,6)];if(f)for(let t=0;t<h.length;t+=3)h[t]-=f[0],h[t+1]-=f[1],h[t+2]-=f[2];return{bbox:d,boxPosition:h,pointCenter:u,coordCenter:l}}$n(t){const e=this.getMap(),r=e.getGLRes(),i=t.boundingVolume.box,o=i.slice(0,3),a=ei(this.Jn(i,t.matrix),o),c=this.Zn(t),h=[],u=this.Ct(t.Rt).Te;Gs.set(u[0],u[1]);const l=e.pointAtResToCoord(Gs,r);for(let t=0;t<Ks.length;t+=3){const i=Ks.slice(t,t+3);n.vec3.transformMat4(i,i,a);const o=new s.Coordinate(bn(i,i));let c=e.coordToPointAtRes(o,r);c=[c.x,c.y,e.altitudeToPoint(o.z,r)],h[t]=c[0]-u[0],h[t+1]=c[1]-u[1],h[t+2]=c[2]-u[2]}return{obbox:this.Kn(h,c),boxPosition:h,boxCenter:c,coordCenter:l}}Xn(t){const e=this.getMap(),n=t.boundingVolume.sphere,r=n;let i=js;0===r[0]&&0===r[1]&&0===r[2]?i=[0,0,-6378137]:bn(i,r);const o=new s.Coordinate(i),a=this.Ne(o,Gs).toArray();a[2]=e.altitudeToPoint(o.z,e.getGLRes());const c=this.Yn(o);return[a,n[3]*c[2]]}Kn(t,e){const n=[(t[3]+t[12])/2,(t[4]+t[13])/2,(t[5]+t[14])/2],r=[(t[3]+t[18])/2,(t[4]+t[19])/2,(t[5]+t[20])/2],s=[(t[3]+t[9])/2,(t[4]+t[10])/2,(t[5]+t[11])/2],i=e.slice(0);return i[3]=n[0]-e[0],i[4]=n[1]-e[1],i[5]=n[2]-e[2],i[6]=r[0]-e[0],i[7]=r[1]-e[1],i[8]=r[2]-e[2],i[9]=s[0]-e[0],i[10]=s[1]-e[1],i[11]=s[2]-e[2],i}Zn(t){const e=this.getMap(),r=e.getGLRes(),i=t.boundingVolume.box,o=i.slice(0,3),a=ei(this.Jn(i,t.matrix),o),c=[0,0,0];n.vec3.transformMat4(c,c,a);const h=new s.Coordinate(bn(c,c)),u=e.coordToPointAtRes(h,r);return[u.x,u.y,e.altitudeToPoint(h.z,r)]}Vn(t){if(!t.boundingVolume)return;const e=t.boundingVolume.box,n=t.boundingVolume.region,r=t.boundingVolume.sphere,s=this.Ct(t.Rt);let i=null;if(e){i=this.Qn(t).pointCenter}else if(n){i=this.Wn(t).pointCenter}else r&&(i=this.Xn(t)[0]);const o=s.heightOffset||0,a=s.coordOffset||[0,0];s.tr=[a[0]||0,a[1]||0],s.Qt=o,s.Te=i}Wn(t){if(!t.boundingVolume)return null;this.Dn(t);return this.Gn(t)}Qn(t){if(!t.boundingVolume)return null;this.Dn(t);const e=this.getMap(),r=e.getGLRes(),i=t.boundingVolume.box,o=i.slice(0,3),a=ei(this.Jn(i,t.matrix),o),c=[0,0,0];n.vec3.transformMat4(c,c,a);const h=new s.Coordinate(bn(c,c));let u=e.coordToPointAtRes(h,r);return u.z=e.altitudeToPoint(h.z,r),u=[u.x,u.y,u.z],{pointCenter:u,coordCenter:h}}Jn(t,e){let n=t.slice(3,12);return n=function(t,e,n){const r=t[0]*e[0]+t[3]*e[1]+t[6]*e[2],s=t[1]*e[0]+t[4]*e[1]+t[7]*e[2],i=t[2]*e[0]+t[5]*e[1]+t[8]*e[2],o=t[0]*e[3]+t[3]*e[4]+t[6]*e[5],a=t[1]*e[3]+t[4]*e[4]+t[7]*e[5],c=t[2]*e[3]+t[5]*e[4]+t[8]*e[5],h=t[0]*e[6]+t[3]*e[7]+t[6]*e[8],u=t[1]*e[6]+t[4]*e[7]+t[7]*e[8],l=t[2]*e[6]+t[5]*e[7]+t[8]*e[8];return n[0]=r,n[1]=s,n[2]=i,n[3]=o,n[4]=a,n[5]=c,n[6]=h,n[7]=u,n[8]=l,n}(this.er(e,[]),n,n),n}er(t,e){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[4],e[4]=t[5],e[5]=t[6],e[6]=t[8],e[7]=t[9],e[8]=t[10],e}Yn(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let s;return s=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:r.y/100,n.vec3.set(qs,r.x/100*1.01,r.y/100*1.01,s),qs}Fn(t){Array.isArray(t)&&(t=new s.Coordinate(t));let e=this.options.offset;if(at(e)&&(e=e.call(this,Array.isArray(t)?new s.Coordinate(t):t)),e[0]||e[1]){const n=this.getMap(),r=n.getGLRes(),s=n.coordToPointAtRes(t,r);return s._sub(e),n.pointAtResToCoord(s,r)}return t}Cn(t){const e=this.Ct(t).maxExtent;if(!e)return null;const n=this.mn[t];return n.maxExtent||(n.maxExtent=new s.Extent(e).convertTo(t=>this.Ne(t))),n.maxExtent}Hn(t){const e=this.Nn,n=t.geometricError;if(0===n)return t.sn=0,0;const r=this.getMap();let s;t.boundingVolume.region?s=function(t,e,n){t.nr||(t.nr=new Us(t.boundingVolume.region));return t.nr.distanceToCamera(e,n)}(t,this.En,this.Sn):t.boundingVolume.sphere?s=Qs(t.boundingVolume,this.En):t.boundingVolume.box&&(s=Ws(t.boundingVolume,this.En));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.te=s,t.sn=o,o}In(){const t=this.getRenderer();t&&t.setToRedraw()}_e(t){return this.ve[t]}identify(t,e={}){const n=this.getMap(),r=this.getRenderer();if(!n||!r)return[];const i=n.coordToContainerPoint(new s.Coordinate(t));return this.identifyAtPoint(i,e)}identifyAtPoint(t,e={}){const n=[];if(!e.excludeMasks){const r=this.identifyMask(t,e);r&&r.length&&Tt(n,r)}const r=this.getMap(),s=this.getRenderer();if(!r||!s)return[];const i=r.getDevicePixelRatio();return Tt(n,s.pick(t.x*i,t.y*i,e)),n}getCurrentBatchIDs(){const t=this.getMap(),e=this.getRenderer();return t&&e?e.Ce():[]}highlight(t){const e=this.getRenderer();return e?(e.highlight(t),this):(this.Lt||(this.Lt=[]),this.Lt.push(t),this)}Tn(){if(this.Lt){for(let t=0;t<this.Lt.length;t++)this.highlight(this.Lt[t]);delete this.Lt}}cancelHighlight(t,e){const n=this.getRenderer();return n?(n.cancelHighlight(t,e),this):this}cancelAllHighlight(){const t=this.getRenderer();return t?(t.cancelAllHighlight(),this):this}showOnly(t){const e=this.getRenderer();return e?(e.showOnly(t),this):(this.Dt||(this.Dt=[]),this.Dt.push(t),this)}rr(){if(this.Dt){for(let t=0;t<this.Dt.length;t++)this.showOnly(this.Dt[t]);delete this.Dt}}cancelShowOnly(t){const e=this.getRenderer();return e?(e.cancelShowOnly(t),this):this}setServiceOpacity(t,e){const n=this.options.services[t];n&&(n.opacity=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}setServiceDebugBoundingVolume(t,e){const n=this.options.services[t];n&&(n.debugShowBoundingVolume=e);const r=this.getRenderer();return r?(r.setToRedraw(),this):this}}function Qs(t,e){const r=t.sphere,s=n.vec3.dist(r,e),i=t.sphere[3];return s<i?0:s-i}function Ws(t,e){const r=t.box;return ms(n.vec3.set(js,r[0],r[1],r[2]),n.mat3.set($s,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}function ti(t,e,r){const s=(t=ft(t)).indexOf("{s}")>=0?"{s}":t.indexOf("%7Bs%7D")>=0?"%7Bs%7D":null;return{service:r,visible:it(r.visible)?1:r.visible,baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.mat4.identity([]),Rt:e,Ft:0,domainKey:s}}function ei(t,e){return new ni(t[0],t[3],t[6],e[0],t[1],t[4],t[7],e[1],t[2],t[5],t[8],e[2],0,0,0,1)}function ni(t,e,n,r,s,i,o,a,c,h,u,l,f,d,m,b){this[0]=t||0,this[1]=s||0,this[2]=c||0,this[3]=f||0,this[4]=e||0,this[5]=i||0,this[6]=h||0,this[7]=d||0,this[8]=n||0,this[9]=o||0,this[10]=u||0,this[11]=m||0,this[12]=r||0,this[13]=a||0,this[14]=l||0,this[15]=b||0}Ys.mergeOptions(zs),Ys.registerRenderer("gl",ls),Ys.registerJSONType("Geo3DTilesLayer");let ri=null;function si(){return ri||(ri={"image/crn":Yr.crn&&Yr.crn(),"image/ktx2":Yr.ktx2&&Yr.ktx2(),"image/cttf":Yr.ktx2&&Yr.ktx2(),"draco":Yr.draco&&Yr.draco()}),ri}class ii{constructor(t,e,n){this.i=t,this.sr=e||Le,this.o=n,this.ir=si()}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.or(t,e,n,r,s)):ge.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.or(t,s,n,r)})}or(t,e,n,r,s){const i=s&&s.maxTextureSize,o=this.ar(e,n,r,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.sr(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.ir,supportedFormats:this.o,maxTextureSize:i});return c.load({skipAttributeTransform:!1}).then(e=>{e.url=`${t}-${n}-${r}`;const s=c.transferables;for(let t=0;t<o.transferables.length;t++)s.indexOf(o.transferables[t])<0&&s.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:s,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}})}ar(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported b3dm version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+r;return console.warn(t),{error:t}}let o,a=s.getUint32(12,!0),c=s.getUint32(16,!0),h=s.getUint32(20,!0),u=s.getUint32(24,!0),l=28+e;h>=570425344?(l-=8,o=a,h=c,u=0,a=0,c=0):u>=570425344&&(l-=4,o=h,h=a,u=c,a=0,c=0);const f=[t];let d,m,b;if(a>0?(d=xn(t,l,a),l+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(l+=c),h>0&&(m=In(t,l,h),l+=h,u>0)){const e=Sn(0,l,u);b=t.slice(e.offset,e.offset+e.byteLength),l+=u,f.push(b)}const p=d.BATCH_LENGTH,g={};if(d&&d.BATCH_ID){g.BATCH_ID=Nn(d.BATCH_ID,t,(void 0).offset,p);const e=g.BATCH_ID.array&&g.BATCH_ID.array.buffer;e&&f.indexOf(e)<0&&f.push(e)}return{count:o,transferables:f,featureTable:d,batchTable:m,batchTableBin:b,b3dm:g,glb:{buffer:t,byteOffset:l,byteLength:s.byteLength+s.byteOffset-l}}}cr(){return null}}class oi{constructor(t,e,n,r){this.i=t,this.sr=e||Le,this.o=n,this.ir=si(),this.hr=r}load(t,e,n=0,r=0,s){return e?(r||(r=e.byteLength),this.or(t,e,n,r,s)):ge.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.or(t,s,n,r)})}or(t,e,n,r,s){return this.ur(t,e,n,r,s).then(({gltf:s,transferables:i})=>{const o=this.lr(e,n,r,t);if(o.error)return Promise.resolve(o);for(let t=0;t<i.length;t++)-1===o.transferables.indexOf(i[t])&&o.transferables.push(i[t]);return delete s.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:s})})}ur(t,e,n,r,s){const i=s&&s.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.ir,supportedFormats:this.o,maxTextureSize:i},a=new DataView(e,n,r),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let r=bt(new Uint8Array(e,c+n,a.byteLength-c));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?ge.getArrayBuffer(r,{}).then(t=>this.dr(r,{buffer:t.data,byteOffset:0},o)):ge.getJSON(r,{}).then(t=>this.dr(r,t,o))}{const r={buffer:e,byteOffset:c+n,byteLength:a.byteLength-c};return this.dr(t,r,o)}}dr(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.sr(r,e,n);return s.load({skipAttributeTransform:!0}).then(n=>{let r=0,i=0;return e.buffer&&(r=e.byteOffset||0,i=e.byteLength||0),n.url=`${t}-${r}-${i}`,{transferables:s.transferables,gltf:n}})}lr(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=Dn(s,32+e,o),l={},f=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;l.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,n=a.QUANTIZED_VOLUME_SCALE,{byteOffset:r}=a.POSITION_QUANTIZED;l.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.mr(new Uint16Array(t,r+c.offset,3*f),e,n)},o.push(l.POSITION.array.buffer)}if(a.BATCH_ID){l.BATCH_ID=Nn(a.BATCH_ID,t,c.offset,f);const e=l.BATCH_ID.array&&l.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;l.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.br(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,l.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:this.br(new Uint16Array(t,e+c.offset,2*f))},o.push(l.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;l.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,f).slice()},o.push(l.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;l.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:f,componentType:5126,array:new Float32Array(t,e+c.offset,3*f).slice()},o.push(l.SCALE_NON_UNIFORM.array.buffer)}return{count:f,batchTable:h,batchTableBin:u,featureTable:a,i3dm:l,transferables:o}}br(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)ai(r,t[2*s],t[2*s+1],65535),n[3*s]=r[0],n[3*s+1]=r[1],n[3*s+2]=r[2];return n}mr(t,e,n){return Un(new Float32Array(t.length),t,e,n)}cr(){return null}}function ai(t,e,n,r){if(t[0]=ci(e,r),t[1]=ci(n,r),t[2]=1-(Math.abs(t[0])+Math.abs(t[1])),t[2]<0){const e=t[0];t[0]=(1-Math.abs(t[1]))*hi(e),t[1]=(1-Math.abs(e))*hi(t[1])}return jt(t,t)}function ci(t,e){return function(t,e,n){return t<e?e:t>n?n:t}(t,0,e=function(t,e){if(null!=t)return t;return e}(e,255))/e*2-1}function hi(t){return t<0?-1:1}class ui{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.or(t,e,n,r)):ge.getArrayBuffer(t,{}).then(e=>{const s=e.data;return r||(r=s.byteLength),this.or(t,s,n,r)})}or(t,e,n,r){return this.pr(e,n,r,t).then(t=>t.error?t:{magic:"pnts",count:t.count,transferables:t.transferables,featureTable:t.featureTable,batchTable:t.batchTable,batchTableBin:t.batchTableBin,pnts:t.pnts})}pr(t,e,n,r){const s=new DataView(t,e,n),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported pnts version: "+i+", url:"+r;return console.warn(t),{error:t}}if(s.getUint32(8,!0)!==s.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+r;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:h,batchTableBin:u}=Dn(s,e+28,o),l=a.QUANTIZED_VOLUME_OFFSET,f=a.QUANTIZED_VOLUME_SCALE,d=a.POINTS_LENGTH;let m,b={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){b=a.extensions["3DTILES_draco_point_compression"],m=new DataView(t,b.byteOffset+c.offset,b.byteLength);const e={attributes:b.properties,useUniqueIDs:!1};return this.gr||(this.gr=si().draco),this.gr(m,e).then(e=>{const n=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||n.POSITION||n.POSITION_QUANTIZED||(n.POSITION=a.POSITION,n.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||n.RGB||n.RGBA||n.RGB565||(n.RGB=a.RGB,n.RGBA=a.RGBA,n.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||n.NORMAL||n.NORMAL_OCT16P||(n.NORMAL=a.NORMAL,n.NORMAL_OCT16P=a.NORMAL_OCT16P);const r=this.yr(t,e.attributes,c.offset,d,o,l,f);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;r.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Ln(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=Nn(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=li(d);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:r,transferables:o}})}const p=this.yr(t,a,c.offset,d,o,l,f);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?p.BATCH_ID=Nn(a.BATCH_ID,t,c.offset,d):p.BATCH_ID=li(d);const e=p.BATCH_ID.array&&p.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:d,batchTable:h,batchTableBin:u,featureTable:a,pnts:p,transferables:o})}yr(t,e,n,r,s,i,o){const a={};if(e.POSITION){let{byteOffset:i,array:o}=e.POSITION;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c}=e.POSITION_QUANTIZED;const{array:h}=e.POSITION_QUANTIZED;c=c||0;const u=h?0:n;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:this.mr(h||new Uint16Array(t,c+u,3*r),i,o)},s.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:i,array:o}=e.RGBA;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+4*r);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB){let{byteOffset:i,array:o}=e.RGB;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5121,array:o},s.push(o.buffer)}else if(e.RGB565){let{byteOffset:i,array:o}=e.RGB565;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:r,componentType:5123,array:o},s.push(o.buffer)}if(e.NORMAL){let{byteOffset:i,array:o}=e.NORMAL;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+3*r*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:r,componentType:5126,array:o},s.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:i,array:o}=e.NORMAL_OCT16P;i=i||0;const c=o?0:n;if(!o){const e=t.slice(i+c,i+c+2*r);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:r,componentType:5121,array:o},s.push(o.buffer)}return a}mr(t,e,n){return Un(new Float32Array(t.length),t,e,n)}cr(){return null}}function li(t){const e=yt(t),n=new e(t);for(let e=0;e<t;e++)n[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:Ln(e),array:n}}class fi{constructor(t,e,n,r){this.o=n,this.i=t,this.sr=e||Le,this.hr=r}load(t,e,n=0,r=0,s){return e?this.or(t,e,n,r,s):ge.getArrayBuffer(t,{}).then(e=>{const s=e.data;return this.or(t,s,n,r)})}or(t,e,n,r,s){r||(r=e.byteLength);const i=this.wr(e,t,n,r),o=[];for(let n=0;n<i.length;n++){let r;if("b3dm"===i[n].magic)r=new ii(this.i,this.sr,this.o);else if("i3dm"===i[n].magic)r=new oi(this.i,this.sr,this.o,this.hr);else if("pnts"===i[n].magic)r=new ui;else{if("cmpt"!==i[n].magic){console.warn("Unsupported magic in CMPT tile:",i[n].magic);continue}r=new fi(this.i,this.sr,this.o,this.hr)}o.push(r.load(t,e,i[n].offset,i[n].byteLength,s).then(t=>t))}return Promise.all(o).then(t=>({magic:"cmpt",tiles:t}))}wr(t,e,n,r){const s=new DataView(t,n,r),i=s.getUint32(4,!0);if(1!==i){const t="Unsupported cmpt version: "+i+", url:"+e;return console.warn(t),{error:t}}if(16===s.byteLength)return[];const o=[],a=s.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=On(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}if(i.transcoders){const t=s.Map.VERSION;if(t.indexOf("1.0.0-beta")>=0||t.indexOf("1.0.0-alpha")>=0){const t=i.transcoders.inject(o);s.registerWorkerAdapter("@maptalks/3dtiles",t)}else s.registerWorkerAdapter("@maptalks/3dtiles",(function(){return i.transcoders.inject(o)}))}else s.registerWorkerAdapter("@maptalks/3dtiles",o);t.B3DMLoader=ii,t.CMPTLoader=fi,t.Geo3DTilesLayer=Ys,t.Geo3DTilesUtil=Ot,t.Geo3DTransform=_n,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.91.0")}));