@maptalks/3dtiles 0.12.6 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maptalks.3dtiles-browser.mjs +23 -0
- package/dist/maptalks.3dtiles.js +19 -6015
- package/dist/maptalks.3dtiles.mjs +11 -0
- package/package.json +17 -13
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @maptalks/3dtiles v0.13.1
|
|
3
|
+
* LICENSE : UNLICENSED
|
|
4
|
+
* (c) 2016-2022 maptalks.org
|
|
5
|
+
*/
|
|
6
|
+
import*as t from"maptalks";import*as e from"@maptalks/gl";import{reshader as n,mat4 as r,vec3 as s,mat3 as i,vec4 as o,quat as a,createREGL as c}from"@maptalks/gl";const h='function(t){var e=1e-6,n="undefined"!=typeof Float32Array?Float32Array:Array;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],y=e[10],d=e[11],m=e[12],b=e[13],p=e[14],w=e[15],g=n[0],T=n[1],_=n[2],A=n[3];return t[0]=g*r+T*a+_*h+A*m,t[1]=g*s+T*c+_*l+A*b,t[2]=g*i+T*u+_*y+A*p,t[3]=g*o+T*f+_*d+A*w,g=n[4],T=n[5],_=n[6],A=n[7],t[4]=g*r+T*a+_*h+A*m,t[5]=g*s+T*c+_*l+A*b,t[6]=g*i+T*u+_*y+A*p,t[7]=g*o+T*f+_*d+A*w,g=n[8],T=n[9],_=n[10],A=n[11],t[8]=g*r+T*a+_*h+A*m,t[9]=g*s+T*c+_*l+A*b,t[10]=g*i+T*u+_*y+A*p,t[11]=g*o+T*f+_*d+A*w,g=n[12],T=n[13],_=n[14],A=n[15],t[12]=g*r+T*a+_*h+A*m,t[13]=g*s+T*c+_*l+A*b,t[14]=g*i+T*u+_*y+A*p,t[15]=g*o+T*f+_*d+A*w,t}function i(){var t=new n(3);return n!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function o(t){var e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function a(t,e,r){var s=new n(3);return s[0]=t,s[1]=e,s[2]=r,s}function c(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function u(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t}function f(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function h(t,e,n){return t[0]=e[0]*n[0],t[1]=e[1]*n[1],t[2]=e[2]*n[2],t}function l(t,e,n){return t[0]=e[0]*n,t[1]=e[1]*n,t[2]=e[2]*n,t}function y(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 d(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function m(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 b(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 p=function(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t},w=h,g=o;function T(t,e,n,r,s){return t[0]=e,t[1]=n,t[2]=r,t[3]=s,t}function _(){var t=new n(4);return n!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function A(t,n,r,s){var i=n[0],o=n[1],a=n[2],c=n[3],u=r[0],f=r[1],h=r[2],l=r[3],y=void 0,d=void 0,m=void 0,b=void 0,p=void 0;return(d=i*u+o*f+a*h+c*l)<0&&(d=-d,u=-u,f=-f,h=-h,l=-l),1-d>e?(y=Math.acos(d),m=Math.sin(y),b=Math.sin((1-s)*y)/m,p=Math.sin(s*y)/m):(b=1-s,p=s),t[0]=b*i+p*u,t[1]=b*o+p*f,t[2]=b*a+p*h,t[3]=b*c+p*l,t}i(),function(){var t,e=(t=new n(4),n!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var S,O=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};i(),a(1,0,0),a(0,1,0),_(),_(),S=new n(9),n!=Float32Array&&(S[1]=0,S[2]=0,S[3]=0,S[5]=0,S[6]=0,S[7]=0),S[0]=1,S[4]=1,S[8]=1;\n/*!\n * @maptalks/gltf-loader v0.25.6\n * LICENSE : UNLICENSED\n * (c) 2016-2022 maptalks.org\n */\nlet I=0;function M(t){return null==t}function x(t){return!M(t)}function v(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 U(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 N(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function B(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 E=[],P=[],L=[],C=[0,0,0],D=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}([]),F=[1,1,1];function k(t,e,n,r,s,i,o){const a=U(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}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 R="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function z(t,e,n){const r=new Uint8Array(t,e,n);return R.decode(r)}const V={get:function(t,e={}){e||(e={});const n=new AbortController,r={signal:n.signal,method:e.method||"GET",referrerPolicy:"origin"};"POST"===e.method&&(M(e.body)||(r.body=JSON.stringify(e.body))),M(e.headers)||(r.headers=e.headers),M(e.credentials)||(r.credentials=e.credentials);const s=fetch(t,r).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 s.xhr=n,s},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",V.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?V.jsonp(t):((e=e||{}).responseType="json",V.get(t,e))}};V.jsonp=function(t){const e="_maptalks_jsonp_"+I++;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 q{constructor(t,e,n){this.i=t,this.decoders=e,this.o=n,this.images={},this.u={}}requestImageFromBufferURI(t,e,n){if(this.buffers[t.id]){const r=this.buffers[t.id],s=this.h(e,r);return this.getImageByBuffer(s,n)}if(this.u[t.id])return this.u[t.id].then((()=>{const r=this.buffers[t.id],s=this.h(e,r);return this.getImageByBuffer(s,n)}));if(N(t.uri)){const r=this.buffers[t.id]=B(t.uri),s=this.h(e,r);return this.getImageByBuffer(s,n)}return this.u[t.id]=V.getArrayBuffer(t.uri,null).then((r=>{const s=this.buffers[t.id]=r.data,i=this.h(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;if(n[e.mimeType])return n[e.mimeType](t,{supportedFormats:this.o});if("image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType)return console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null);{const n=new Blob([t],{type:e.mimeType}),r=URL.createObjectURL(n);return this.l(e.id,r)}}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;if(this.u[t.id])return this.u[t.id].then((()=>this.images[t.id]));return this.u[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 $=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16];class j{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(N(e.uri)){const t=this.buffers[e.id]=B(e.uri);return Promise.resolve({buffer:t,byteOffset:0})}let t;t=e.uri.indexOf("://")>0||e.uri.indexOf("blob:")>=0?e.uri:this.rootPath+"/"+e.uri;return this.requests[e.id]=V.getArrayBuffer(t,null).then((t=>({buffer:this.buffers[e.id]=t.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),u=U(i.componentType),f=o.byteStride||0;const h={array:undefined,name:t,accessorName:e,byteLength:i.count*c*u.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:c};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.S(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);h.array=k(t,n,i.count,c,f,a+(i.byteOffset||0),i.componentType)}else h.byteStride=0,h.array=this.S(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)}S(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=$.indexOf(t);return $[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=z(s,i+(e.byteOffset||0),n);return t.content=o,t}))}if(t.uri){if(N(t.uri)){const e=B(t.uri),n=z(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return V.get(e).then((e=>(t.content=e,t)))}}return Promise.resolve(t)}));return Promise.all(n).then((()=>t))}}class G extends q{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 j(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(x(t.name)&&(e.name=t.name),x(t.children)&&(e.children=t.children),x(t.jointName)&&(e.jointName=t.jointName),x(t.matrix)&&(e.matrix=t.matrix),x(t.rotation)&&(e.rotation=t.rotation),x(t.scale)&&(e.scale=t.scale),x(t.translation)&&(e.translation=t.translation),x(t.extras)&&(e.extras=t.extras),x(t.meshes)&&(e.mesh=t.meshes[0]),e.translation||e.rotation||e.scale){const t=function(t,e){if(e.matrix)return e.matrix;if(e.translation||e.scale||e.rotation){const n=function(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}(E,e.translation||C),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,u=n*o,f=r*o,h=r*a,l=s*o,y=s*a,d=s*c,m=i*o,b=i*a,p=i*c;return t[0]=1-h-d,t[1]=f+p,t[2]=l-b,t[3]=0,t[4]=f-p,t[5]=1-u-d,t[6]=y+m,t[7]=0,t[8]=l+b,t[9]=y-m,t[10]=1-u-h,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(P,e.rotation||D),i=function(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(L,e.scale||F);return s(i,r,i),s(t,n,i)}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}I(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.I(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 H extends q{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 j(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 v(e,t),!x(t.weights)&&this.gltf.meshes&&x(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;const n=this.gltf.images[e.source];return this.I(n).then((t=>{if(!t)return null;const r={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:n.mimeType,name:n.name,extensions:n.extensions,extras:n.extras}};v(r,e);const s=x(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return s&&(r.sampler=s),t.format&&(r.format=t.format),r}))}I(t){if(!x(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.v(e,t)}return null}v(t,e){const n=this.h(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(n,e)}h(t,e,n){n=n||0;const r=t.byteOffset+n,s=t.byteLength;return new Uint8Array(e,r,s)}U(t,e){const n=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)n[e]=String.fromCharCode(t[e]);n.join("");const r="data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)));return r}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++)(x(t[n].input)||x(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 J="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null,K=1313821514,X=5130562;class Q{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 Q.readV1(r,e);if(2===s)return Q.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=W(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,c===K)n=W(t,e+12+o,a);else if(c===X){s=e+12+o,r=a;break}o+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function W(t,e,n){if(J){const r=new Uint8Array(t,e,n);return J.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=Y[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 Y=[1,1,1,1,2,2,3,0];const Z=[0,0,0],tt=[0,0,0,1],et=[1,1,1],nt={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},rt={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},st={N(t,e,n,r,s,i,o,a){const u=x(t)?e.animations:[e.animations[0]],f={};for(let e=0;e<u.length;e++){const h=u[e],l=h.name||e;if(x(t)&&l!==t)continue;const y=h.channelsMap[n];if(y)for(let t=0;t<y.length;t++){const e=y[t];"translation"===e.target.path?(this.B(s,h.samplers[e.sampler],r,1),f.translation=c(Z,s)):"rotation"===e.target.path?(this.P(i,h.samplers[e.sampler],r,1),f.rotation=O(tt,i)):"scale"===e.target.path?(this.B(o,h.samplers[e.sampler],r,1),f.scale=c(et,o)):"weights"===e.target.path&&a&&(this.B(a,h.samplers[e.sampler],r,a.length),f.weights=a)}}return f},B(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.L(rt,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(rt,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(rt,e,n,3*r);s&&(t=this.C(t,s,e.input.array,3*r));break}}return t},P(t,e,n){switch(e.interpolation){case"LINEAR":{const r=this.L(rt,e,n,1);r&&A(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.L(rt,e,n,1);r&&(t=T(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.L(rt,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.C(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: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},C(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;u(Z,...nt.TRANSLATION),T(tt,...nt.ROTATION),u(et,...nt.SCALE);return this.N(r,t,e,n,Z,tt,et,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?x(e)?n[e]:n[Object.keys(n)[0]]:null}};let it=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(t){}t&&"undefined"!=typeof createImageBitmap&&(it=!0)}const ot="undefined"==typeof document?null:document.createElement("canvas");class at{constructor(t,e,n){if(this.options=n||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:n,glbBuffer:r}=Q.read(e.buffer,e.byteOffset,e.byteLength);this.F(t,n,r)}else this.F(t,e);this.k=new j(this.rootPath,this.gltf,this.glbBuffer),this.R()}R(){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.k.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.j(),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 st.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return st.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return U(t)}static readInterleavedArray(t,e,n,r,s,i,o){return k(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=it?ht:this.options.requestImage||ct,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new H(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 G(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(!(n=t.children[0],"number"==typeof n&&isFinite(n)||function(t){return!M(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}(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}q(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,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={asset:this.gltf.asset,scene:n,scenes:e,nodes:t,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins};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.X(n).then((t=>{t.index=r,this.skins.push(t)})))}),"skins"),t}X(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)))}$(){const t=this.gltf.animations;return x(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.Y(t,e))).filter((t=>!!t));return Promise.all(n).then((e=>{const n={};return v(n,t),n.primitives=e,n}))}j(){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++)if(e[t]&&e[t].image.array){const n=e[t].image.array.buffer;n&&this.transferables.indexOf(n)<0&&this.transferables.push(n)}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(x(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.k._(a).then((n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:i,byteLength:c}=a;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.g(t,e[t]);n&&r.push(n)}if(x(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;l(t,t,s),f(t,t,i),l(n,n,s),f(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=x(t.mode)?t.mode:4,x(t.extras)&&(i.extras=t.extras),i}))}}function ct(t,e){const n=new Image;n.crossOrigin="",n.onload=()=>{if(!ot)return void e(new Error("There is no canvas to draw image!"));ot.width=n.width,ot.height=n.height;const t=ot.getContext("2d");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 ut,ft;function ht(t,e){ut||(ut=new OffscreenCanvas(2,2),ft=ut.getContext("2d")),fetch(t).then((t=>t.blob())).then((t=>createImageBitmap(t))).then((t=>{let{width:n,height:r}=t;lt(n)||(n=yt(n)),lt(r)||(r=yt(r)),ut.width=n,ut.height=r,ft.drawImage(t,0,0,n,r),t.close();const s=ft.getImageData(0,0,n,r);e(null,{width:n,height:r,data:new Uint8Array(s.data)})})).catch((t=>{console.warn(t),e(t)}))}function lt(t){return 0==(t&t-1)&&0!==t}function yt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function dt(t){return t/Math.PI*180}function mt(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const bt=[1,1,1,1,2,2,3,0];function pt(t){const e=t.length;let n="";for(let r=0;r<e;){let s=t[r++];if(128&s){let n=bt[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 wt=[1/6378137,1/6378137,1/6356752.314245179],gt=[1/40680631590769,1/40680631590769,1/40408299984661.445],Tt=new Array(3),_t=new Array(3),At=new Array(3);function St(t,e){const n=gt,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,y=o*o*u*u,d=a*a*f*f,m=h+y+d,b=Math.sqrt(1/m),p=l(Ot,e,b);if(m<s)return isFinite(b)?p:void 0;const w=r[0],g=r[1],T=r[2],_=It;_[0]=p[0]*w*2,_[1]=p[1]*g*2,_[2]=p[2]*T*2;let A,S,O,I,M,x,v,U,N,B,E,P=(1-b)*Mt(e)/(.5*Mt(_)),L=0;do{P-=L,O=1/(1+P*w),I=1/(1+P*g),M=1/(1+P*T),x=O*O,v=I*I,U=M*M,N=x*O,B=v*I,E=U*M,A=h*x+y*v+d*U-1,S=h*N*w+y*B*g+d*E*T;L=A/(-2*S)}while(Math.abs(A)>1e-12);return t[0]=i*O,t[1]=o*I,t[2]=a*M,t}(Tt,e,wt,n,.1);let s=w(_t,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=p(At,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=mt(d(i,e))*Mt(i);return t[0]=dt(o),t[1]=dt(a),t[2]=c,t}const Ot=new Array(3),It=new Array(3);function Mt(t){return o(t)}function xt(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const vt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Ut(t,e,n){const r=new Uint8Array(t,e,n);return vt?JSON.parse(vt.decode(r)):JSON.parse(pt(r))}function Nt(t,e,n){const r=new Uint8Array(t,e,n);return vt?JSON.parse(vt.decode(r)):JSON.parse(pt(r))}function Bt(t,e,n){return{offset:e,byteLength:n}}function Et(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=function(t){return Ct[t]}(i),u=function(t){if(!t)return 1;return Lt[t]}(o);return{byteStride:0,byteOffset:s+n,itemSize:u,count:r*u,componentType:c,array:new a(e,n+s,r*u)}}function Pt(t,e,n,r){t.componentType||(t.componentType="UNSIGNED_SHORT");const s=Et(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}const Lt={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const Ct={"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 Dt(t){for(let e in Ct)if(t===Ct[e].ctor)return Ct[e].type;throw new Error("unrecognized ctor:"+t)}function Ft(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 kt(t,e,n){let r=t.getUint32(12,!0),s=t.getUint32(16,!0),i=t.getUint32(20,!0),o=t.getUint32(24,!0);const a=t.buffer;let c,u,f={},h={};r>0&&(f=Ut(a,e,r),e+=r),s>0&&(c=function(t,e,n){return{offset:e,byteLength:n}}(0,e,s),e+=s),i>0&&(h=Nt(a,e,i),e+=i);const l=Bt(0,e,o);return u=a.slice(l.offset,l.offset+l.byteLength),n.push(u),{featureTable:f,featureTableBin:c,batchTable:h,batchTableBin:u}}var Rt={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},zt={},Vt={east:[],north:[],up:[],west:[],south:[],down:[]},qt=[],$t=[],jt=[];const Gt=[0,0,0];function Ht(t,e,n,r){n=n||0,r=r||n;var s=Math.abs(t-e);return s<=r||s<=n*Math.max(Math.abs(t),Math.abs(e))}const Jt=(Wt={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="east"][Xt="north"],zt[Yt=Kt+Xt]?Qt=zt[Yt]:(Qt=function(t,n,r){if(u=Gt,f=(a=t)[0],d=a[1],b=a[2],p=u[0],w=u[1],g=u[2],Math.abs(f-p)<=e*Math.max(1,Math.abs(f),Math.abs(p))&&Math.abs(d-w)<=e*Math.max(1,Math.abs(d),Math.abs(w))&&Math.abs(b-g)<=e*Math.max(1,Math.abs(b),Math.abs(g)))c(qt,Rt[Kt]),c($t,Rt[Xt]),c(jt,Rt[Wt]);else if(Ht(t[0],0,1e-14)&&Ht(t[1],0,1e-14)){var s=mt(t[2]);c(qt,Rt[Kt]),"east"!==Kt&&"west"!==Kt&&l(qt,qt,s),c($t,Rt[Xt]),"east"!==Xt&&"west"!==Xt&&l($t,$t,s),c(jt,Rt[Wt]),"east"!==Wt&&"west"!==Wt&&l(jt,jt,s)}else{!function(t,e){h(e,t,gt),y(e,e)}(t,Vt.up);var i=Vt.up,o=Vt.east;o[0]=-t[1],o[1]=t[0],o[2]=0,y(Vt.east,o),m(Vt.north,i,o),l(Vt.down,Vt.up,-1),l(Vt.west,Vt.east,-1),l(Vt.south,Vt.north,-1),qt=Vt[Kt],$t=Vt[Xt],jt=Vt[Wt]}var a,u,f,d,b,p,w,g;return r[0]=qt[0],r[1]=qt[1],r[2]=qt[2],r[3]=0,r[4]=$t[0],r[5]=$t[1],r[6]=$t[2],r[7]=0,r[8]=jt[0],r[9]=jt[1],r[10]=jt[2],r[11]=0,r[12]=t[0],r[13]=t[1],r[14]=t[2],r[15]=1,r},zt[Yt]=Qt),Qt);\n/*!\n * @maptalks/gl v0.67.5\n * LICENSE : UNLICENSED\n * (c) 2016-2022 maptalks.com\n */var Kt,Xt,Qt,Wt,Yt;const Zt=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")},te=Zt(),ee=te.gl_trans__coders=te.gl_trans__coders||{};ee.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=te.gl_trans__coders=te.gl_trans__coders||{};let i=`${r}\\n const _____getGlobal = ${Zt.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},ee.registerTranscoder=function(t,e){ee[t]=e},ee.getTranscoder=function(t){return ee[t]};class ne{constructor(t,e,n){this.i=t,this.Z=e||at,this.o=n,this.tt={"image/crn":ee.crn&&ee.crn(),"image/ktx2":ee.ktx2&&ee.ktx2(),"image/cttf":ee.ktx2&&ee.ktx2(),"draco":ee.draco&&ee.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.et(t,e,n,r)):V.getArrayBuffer(t,{}).then((e=>{const s=e.data;return r||(r=s.byteLength),this.et(t,s,n,r)}))}et(t,e,n,r){const s=this.nt(e,n,r,t);if(s.error)return Promise.resolve(s);const i=t.substring(0,t.lastIndexOf("/")),o=new this.Z(i,s.glb,{transferable:!0,requestImage:this.i,decoders:this.tt,supportedFormats:this.o});return o.load().then((e=>{e.url=`${t}-${n}-${r}`;const i=o.transferables;for(let t=0;t<s.transferables.length;t++)i.indexOf(s.transferables[t])<0&&i.push(s.transferables[t]);return{magic:"b3dm",count:s.count,transferables:i,featureTable:s.featureTable,batchTable:s.batchTable,batchTableBin:s.batchTableBin,gltf:e}}))}nt(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 y,d,m;if(a>0?(y=Ut(t,h,a),h+=a,o=y.BATCH_LENGTH):y={"BATCH_LENGTH":o},c>0&&(h+=c),u>0&&(d=Nt(t,h,u),h+=u,f>0)){const e=Bt(0,h,f);m=t.slice(e.offset,e.offset+e.byteLength),h+=f,l.push(m)}const b=y.BATCH_LENGTH,p={};if(y&&y.BATCH_ID){p.BATCH_ID=Pt(y.BATCH_ID,t,undefined.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:y,batchTable:d,batchTableBin:m,b3dm:p,glb:{buffer:t,byteOffset:h,byteLength:s.byteLength+s.byteOffset-h}}}rt(){return null}}class re{constructor(t,e,n){this.i=t,this.Z=e||at,this.o=n,this.tt={"image/crn":ee.crn&&ee.crn(),"image/ktx2":ee.ktx2&&ee.ktx2(),"image/cttf":ee.ktx2&&ee.ktx2(),"draco":ee.draco&&ee.draco()}}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.et(t,e,n,r)):V.getArrayBuffer(t,{}).then((e=>{const s=e.data;return r||(r=s.byteLength),this.et(t,s,n,r)}))}et(t,e,n,r){return this.st(t,e,n,r).then((({gltf:s,transferables:i})=>{const o=this.it(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})}))}st(t,e,n,r){const s={transferable:!0,requestImage:this.i,decoders:this.tt,supportedFormats:this.o},i=new DataView(e,n,r),o=32+i.getUint32(12,!0)+i.getUint32(16,!0)+i.getUint32(20,!0)+i.getUint32(24,!0);if(0===i.getUint32(28,!0)){let r=pt(new Uint8Array(e,o+n,i.byteLength-o));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?V.getArrayBuffer(r,{}).then((t=>this.ot(r,{buffer:t.data,byteOffset:0},s))):V.getJSON(r,{}).then((t=>this.ot(r,t,s)))}{const r={buffer:e,byteOffset:o+n,byteLength:i.byteLength-o};return this.ot(t,r,s)}}ot(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.Z(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}}))}it(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}=kt(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.at(new Uint16Array(t,r+c.offset,3*l),e,n)},o.push(h.POSITION.array.buffer)}if(a.BATCH_ID){h.BATCH_ID=Pt(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.ct(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.ct(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}}ct(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)se(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}at(t,e,n){return Ft(new Float32Array(t.length),t,e,n)}rt(){return null}}function se(t,e,n,r){if(t[0]=ie(e,r),t[1]=ie(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]))*oe(e),t[1]=(1-Math.abs(e))*oe(t[1])}return y(t,t)}function ie(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 oe(t){return t<0?-1:1}class ae{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.et(t,e,n,r)):V.getArrayBuffer(t,{}).then((e=>{const s=e.data;return r||(r=s.byteLength),this.et(t,s,n,r)}))}et(t,e,n,r){return this.ut(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}))}ut(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}=kt(s,e+28,o),h=a.QUANTIZED_VOLUME_OFFSET,l=a.QUANTIZED_VOLUME_SCALE,y=a.POINTS_LENGTH;let d,m={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){m=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,m.byteOffset+c.offset,m.byteLength);const e={attributes:m.properties,useUniqueIDs:!1};return this.ft||(this.ft=ee.draco()),this.ft(d,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,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:Dt(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?r.BATCH_ID=Pt(a.BATCH_ID,t,c.offset,y):r.BATCH_ID=ce(y);const e=r.BATCH_ID.array&&r.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:y,batchTable:u,batchTableBin:f,featureTable:a,pnts:r,transferables:o}}))}const b=this.ht(t,a,c.offset,y,o,h,l);if(a.BATCH_ID||Object.keys(u).length){a.BATCH_ID?b.BATCH_ID=Pt(a.BATCH_ID,t,c.offset,y):b.BATCH_ID=ce(y);const e=b.BATCH_ID.array&&b.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:y,batchTable:u,batchTableBin:f,featureTable:a,pnts:b,transferables:o})}ht(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,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.at(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}at(t,e,n){return Ft(new Float32Array(t.length),t,e,n)}rt(){return null}}function ce(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:Dt(e),array:r}}class ue{constructor(t,e){this.i=t,this.Z=e||at}load(t,e,n=0,r=0){return e?this.et(t,e,n,r):V.getArrayBuffer(t,{}).then((e=>{const s=e.data;return this.et(t,s,n,r)}))}et(t,e,n,r){r||(r=e.byteLength);const s=this.lt(e,t,n,r),i=[];for(let n=0;n<s.length;n++){let r;if("b3dm"===s[n].magic)r=new ne(this.i,this.Z);else if("i3dm"===s[n].magic)r=new re(this.i,this.Z);else if("pnts"===s[n].magic)r=new ae;else{if("cmpt"!==s[n].magic){console.warn("Unsupported magic in CMPT tile:",s[n].magic);continue}r=new ue(this.i,this.Z)}i.push(r.load(t,e,s[n].offset,s[n].byteLength).then((t=>t)))}return Promise.all(i).then((t=>({magic:"cmpt",tiles:t})))}lt(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=xt(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}function fe(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)}}}function he(t,e,n,r){if(t.matrix&&e.push(t.matrix),t.children&&t.children.length)for(let s=0,i=t.children.length;s<i;s++)he(t.children[s],e,n,r);if(void 0!==t.mesh){const s=t.mesh,i=n.meshes[s];if(i){const t=e.slice(0),o=i.primitives;for(let e=0,i=o.length;e<i;e++){const i=o[e];i&&(i.matrices=t,r(i,s,e,n))}}}}function le(t,e){let{componentType:n,byteOffset:r,byteStride:s,count:i,itemSize:o}=t;const a=t.array.buffer,c=n?at.getTypedArrayCtor(n):t.array.constructor;if(r=void 0===r?t.array.byteOffset:r,s=s||0,i=i||t.array.length/o,(!s||s===o*c.BYTES_PER_ELEMENT)&&r%c.BYTES_PER_ELEMENT==0){const t=new c(a,r,i*o);for(let n=0;n<i*o;n+=o){e(new c(t.buffer,r+n*c.BYTES_PER_ELEMENT,o),n/o)}return}const u=new Uint8Array(o*c.BYTES_PER_ELEMENT);s||(s=o*c.BYTES_PER_ELEMENT);for(let t=0;t<i;t++){const n=new Uint8Array(a,s*t+r,o*c.BYTES_PER_ELEMENT);u.set(n);e(new c(u.buffer),t),n.set(u)}}const ye=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],de=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],me="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;let be,pe,we=!1;if("undefined"!=typeof OffscreenCanvas){try{pe=new OffscreenCanvas(2,2).getContext("2d")}catch(t){}pe&&"undefined"!=typeof createImageBitmap&&(we=!0)}const ge=r([]),Te=[0,0,0],_e=[],Ae=[];class Se{constructor(t,e,n,r){this.id=t,this.options=e,this.yt=this.requestImage.bind(this),this.dt=n,this.bt={},r(null,{},[])}wt(t){this.gt||(this.Tt=new ae,this.gt=new ne(this.yt,at,t),this._t=new re(this.yt,at,t))}requestImage(t,e){we?fetch(t).then((t=>t.blob())).then((t=>createImageBitmap(t))).then((t=>{be.width=t.width,be.height=t.height,pe.drawImage(t,0,0);const n=pe.getImageData(0,0,be.width,be.height);e(null,{width:t.width,height:t.height,data:new Uint8Array(n.data)})})):this.dt("requestImage",{url:t},null,e)}loadTile(t,e){this.wt(t.supportedFormats);const n=t.url,r=t.arraybuffer;if(r){delete this.bt[n];const s=xt(new DataView(r),0);if("{"===s[0]||" "===s[0]){const t=function(t,e,n){if(me){const r=new Uint8Array(t,e,n);return me.decode(r)}return pt(new Uint8Array(t,e,n))}(r,0,r.byteLength),n=JSON.parse(t);e(null,n)}else if("b3dm"===s){this.gt.load(n,r).then((n=>{if(n.error)return void e(n);const{content:r,transferables:s}=this.At(n,t);e(null,r,s)})).catch((t=>{e(t)}))}else if("pnts"===s){const s=t.transform;this.Tt.load(n,r).then((n=>{const{content:r,transferables:i}=this.St(n,s,t.rootIdx);e(null,r,i)}))}else if("i3dm"===s){const s=t.transform;this._t.load(n,r).then((n=>{const{content:r,transferables:i}=this.St(n,s,t.rootIdx);e(null,r,i)}))}else if("cmpt"===s){new ue(this.yt,at).load(n,r).then((n=>{const{content:r,transferables:s}=this.Ot(n,t);e(null,r,s)})).catch((t=>{e(t)}))}}else{const r=this.options.services[t.rootIdx];let s=r.urlParams;s&&(s=(n.indexOf("?")>0?"&":"?")+s);let i=V.getArrayBuffer(n+(s||""),r.fetchOptions);const o=i.xhr;i=i.then((r=>{delete this.bt[n],r&&r.status?e(r):(t.arraybuffer=r&&r.data,this.loadTile(t,e))})).catch((t=>{delete this.bt[n],e(t)})),this.bt[n]=o}}Ot(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.At(n[t],e);Me(s,o),r.content.push(i)}else if("i3dm"===i||"pnts"===i){const{transform:i,rootIdx:o}=e,{content:a,transferables:c}=this.St(n[t],i,o);Me(s,c),r.content.push(a)}else if("cmpt"===i){const{content:i,transferables:o}=this.Ot(n[t],e);Me(s,o),r.content.push(i)}}return{content:r,transferables:s}}At(t,e){const{gltf:n,transferables:r,featureTable:s}=t;return this.It(t.gltf),this.convertCoordinates(n,s,e.upAxis,e.transform),delete t.transferables,{content:t,transferables:r}}St(t,e,n){const{featureTable:r}=t,s=t.pnts||t.i3dm;let i=r&&r.RTC_CENTER||[0,0,0];if(r.EAST_NORTH_UP&&!s.NORMAL_UP&&!s.NORMAL_UP_OCT32P){const e=new Float32Array(3*s.POSITION.array.length),n=[],r=[],o=[];le(s.POSITION,((t,s)=>{f(o,t,i),Jt(o,null,n),function(t,e){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]}(r,n);!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*s,9*(s+1)),r)})),s.INSTANCE_ROTATION={byteStride:0,byteOffset:0,itemSize:9,componentType:5126,array:e},t.transferables.push(e.buffer)}const o={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};Oe(s.POSITION.array,3,i,ge,o);const a=Ie(o),u=c([],a),h=[1/0,1/0,1/0],l=[-1/0,-1/0,-1/0];le(s.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]<h[0]&&(h[0]=t[0]),t[1]<h[1]&&(h[1]=t[1]),t[2]<h[2]&&(h[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])})),s.POSITION.min=h,s.POSITION.max=l,e&&b(a,a,e);const y=this.Mt(a);t.rtcCenter=u,t.rtcCoord=y,t.rootIdx=n;const d=t.transferables;return delete t.transferables,{content:t,transferables:d}}It(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){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.bt[t.url];n&&n.abort(),delete this.bt[t.url],e(null)}convertCoordinates(t,e,n,i){let o=e&&e.RTC_CENTER||t.extensions&&t.extensions.CESIUM_RTC&&t.extensions.CESIUM_RTC.center,a=ye;"X"===(n=n&&n.toUpperCase())?a=de:"Z"===n&&(a=ge),t.extensions=t.extensions||{},t.extensions.CESIUM_RTC||(t.extensions.CESIUM_RTC={}),o&&(t.extensions.CESIUM_RTC.center=o);const u={xmin:1/0,xmax:-1/0,ymin:1/0,ymax:-1/0,hmin:1/0,hmax:-1/0};fe(t,(t=>{if(!(t.attributes&&t.attributes.POSITION))return;const e=r(_e);if(t.matrices)for(let n=t.matrices.length-1;n>=0;n--)s(e,e,t.matrices[n]);const n=t.attributes.POSITION.array,i=t.attributes.POSITION.itemSize;s(e,a,e),Oe(n,i,o||Te,e,u)}));const f=Ie(u),h=c([],f);i&&b(f,f,i),t.extensions.CESIUM_RTC.coord=this.Mt(f),o||(fe(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(_e);if(t.matrices)for(let e=t.matrices.length-1;e>=0;e--)s(n,n,t.matrices[e]);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],y=e[11],d=e[12],m=e[13],b=e[14],p=e[15],w=n*a-r*o,g=n*c-s*o,T=n*u-i*o,_=r*c-s*a,A=r*u-i*a,S=s*u-i*c,O=f*m-h*d,I=f*b-l*d,M=f*p-y*d,x=h*b-l*m,v=h*p-y*m,U=l*p-y*b,N=w*U-g*v+T*x+_*M-A*I+S*O;return N?(N=1/N,t[0]=(a*U-c*v+u*x)*N,t[1]=(s*v-r*U-i*x)*N,t[2]=(m*S-b*A+p*_)*N,t[3]=(l*A-h*S-y*_)*N,t[4]=(c*M-o*U-u*I)*N,t[5]=(n*U-s*M+i*I)*N,t[6]=(b*T-d*S-p*g)*N,t[7]=(f*S-l*T+y*g)*N,t[8]=(o*v-a*M+u*O)*N,t[9]=(r*M-n*v-i*O)*N,t[10]=(d*A-m*T+p*w)*N,t[11]=(h*T-f*A-y*w)*N,t[12]=(a*I-o*x-c*O)*N,t[13]=(n*x-r*I+s*O)*N,t[14]=(m*g-d*_-b*w)*N,t[15]=(f*_-h*g+l*w)*N,t):null}(Ae,n),o=[1/0,1/0,1/0],c=[-1/0,-1/0,-1/0];le(e,(t=>{b(t,t,n),t[0]=t[0]-h[0],t[1]=t[1]-h[1],t[2]=t[2]-h[2],b(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=h)}Mt(t){return 0===g(t)?u([],0,0,-6378137):St([],t)}onRemove(){}}function Oe(t,e,n,r,s){const i=[];for(let o=0,a=t.length;o<a;o+=e){const{xmin:a,ymin:c,xmax:h,ymax:l,hmin:y,hmax:d}=s;u(i,t[o],t[o+1],t[o+2]),b(i,i,r);const m=f(i,n,i);m[0]<a&&(s.xmin=m[0]),m[0]>h&&(s.xmax=m[0]),m[1]<c&&(s.ymin=m[1]),m[1]>l&&(s.ymax=m[1]),e>2&&(m[2]<y&&(s.hmin=m[2]),m[2]>d&&(s.hmax=m[2]))}}function Ie(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 Me(t,e){for(let n=0;n<e.length;n++)t.indexOf(e[n])<0&&t.push(e[n])}let xe=0;class ve{constructor(t){this.workerId=t,this.workers={},this.xt={}}addLayer({actorId:t,mapId:e,layerId:n,params:r},s){if(this.vt(e,n))return;const i=this.Ut(e,n),o=r.options,a=this.send.bind(this,t);this.workers[i]=new Se(n,o,a,s)}removeLayer({mapId:t,layerId:e},n){const r=this.vt(t,e),s=this.Ut(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.xt[e];delete this.xt[e],n&&t.error?n(new Error(t.error)):n&&n(null,t.data)}send(t,e,n,r,s){const i=s?`${t}-${xe++}`:null;s&&(this.xt[i]=s),postMessage({type:"<request>",workerId:this.workerId,actorId:t,command:e,params:n,callback:String(i)},r||[])}Ut(t,e){return`${t}-${e}`}vt(t,e){const n=this.Ut(t,e);return this.workers[n]}}t.initialize=function(){},t.onmessage=function(t,e){const n=t.data;this.dispatcher||(this.dispatcher=new ve(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)=>{e(t,n,r)}))},Object.defineProperty(t,"Nt",{value:!0})}';for(
|
|
7
|
+
/*!
|
|
8
|
+
* Contains code from THREE.js
|
|
9
|
+
* MIT License
|
|
10
|
+
* https://github.com/mrdoob/three.js
|
|
11
|
+
*/
|
|
12
|
+
var u=[],f=0;f<6;f++)u[f]=[];var l=[];function d(t,e,n){b(t);for(var r=0;r<6;r++)if(!n||"0"!==n.charAt(r)){var s=u[r];if(l[0]=s[0]>0?e[1][0]:e[0][0],l[1]=s[1]>0?e[1][1]:e[0][1],l[2]=s[2]>0?e[1][2]:e[0][2],p(s,l)<0)return!1}return!0}function m(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=p(t,n);return!(h<=-c)}function b(t){var e=t,n=e[0],r=e[1],s=e[2],i=e[3],o=e[4],a=e[5],c=e[6],h=e[7],f=e[8],l=e[9],d=e[10],m=e[11],b=e[12],p=e[13],g=e[14],T=e[15];y(u[0],i-n,h-o,m-f,T-b),y(u[1],i+n,h+o,m+f,T+b),y(u[2],i+r,h+a,m+l,T+p),y(u[3],i-r,h-a,m-l,T-p),y(u[4],i-s,h-c,m-d,T-g),y(u[5],i+s,h+c,m+d,T+g)}function y(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 p(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]}function g(t){return null==t}function T(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 w(t){return null!=t&&("function"==typeof t||null!==t.constructor&&t.constructor===Function)}function _(t){return t*Math.PI/180}function O(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 I(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 S(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 M(t,e,n){return t[3*n]=e[0],t[3*n+1]=e[1],t[3*n+2]=e[2],t}function N(t){return t.flat?t.flat(1/0):t.reduce(((t,e)=>t.concat(e)),[])}function v(t){return t<256?Uint8Array:t<65536?Uint16Array:Uint32Array}function E(t){return 0===t.indexOf("data:")}function R(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}var L=Object.freeze({__proto__:null,isNil:g,extend:T,isFunction:w,toRadian:_,toDegree:O,getAbsoluteURL:A,sign:I,stringFromUTF8Array:S,setColumn3:M,flatArr:N,getBatchIdArrayType:v,isBase64:E,base64URLToArrayBuffer:R}),B="undefined"!=typeof Float32Array?Float32Array:Array;function P(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],b=e[12],y=e[13],p=e[14],g=e[15],T=n[0],w=n[1],_=n[2],O=n[3];return t[0]=T*r+w*a+_*f+O*b,t[1]=T*s+w*c+_*l+O*y,t[2]=T*i+w*h+_*d+O*p,t[3]=T*o+w*u+_*m+O*g,T=n[4],w=n[5],_=n[6],O=n[7],t[4]=T*r+w*a+_*f+O*b,t[5]=T*s+w*c+_*l+O*y,t[6]=T*i+w*h+_*d+O*p,t[7]=T*o+w*u+_*m+O*g,T=n[8],w=n[9],_=n[10],O=n[11],t[8]=T*r+w*a+_*f+O*b,t[9]=T*s+w*c+_*l+O*y,t[10]=T*i+w*h+_*d+O*p,t[11]=T*o+w*u+_*m+O*g,T=n[12],w=n[13],_=n[14],O=n[15],t[12]=T*r+w*a+_*f+O*b,t[13]=T*s+w*c+_*l+O*y,t[14]=T*i+w*h+_*d+O*p,t[15]=T*o+w*u+_*m+O*g,t}function U(){var t=new B(3);return B!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function C(t){var e=t[0],n=t[1],r=t[2];return Math.sqrt(e*e+n*n+r*r)}function D(t,e,n){var r=new B(3);return r[0]=t,r[1]=e,r[2]=n,r}function V(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function F(t,e,n,r){return t[0]=e,t[1]=n,t[2]=r,t}function k(t,e,n){return t[0]=e[0]+n[0],t[1]=e[1]+n[1],t[2]=e[2]+n[2],t}function H(t,e,n){return t[0]=e[0]-n[0],t[1]=e[1]-n[1],t[2]=e[2]-n[2],t}function G(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,t[1]=e[1]*n,t[2]=e[2]*n,t}function j(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 z(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function $(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 X=H,Z=G,K=C;function Y(t,e,n,r,s){return t[0]=e,t[1]=n,t[2]=r,t[3]=s,t}function W(){var t=new B(4);return B!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function J(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,b=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),b=Math.sin((1-r)*l)/m,y=Math.sin(r*l)/m):(b=1-r,y=r),t[0]=b*s+y*c,t[1]=b*i+y*h,t[2]=b*o+y*u,t[3]=b*a+y*f,t}U(),function(){var t,e=(t=new B(4),B!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var Q,tt=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};U(),D(1,0,0),D(0,1,0),W(),W(),Q=new B(9),B!=Float32Array&&(Q[1]=0,Q[2]=0,Q[3]=0,Q[5]=0,Q[6]=0,Q[7]=0),Q[0]=1,Q[4]=1,Q[8]=1;
|
|
13
|
+
/*!
|
|
14
|
+
* @maptalks/gltf-loader v0.25.6
|
|
15
|
+
* LICENSE : UNLICENSED
|
|
16
|
+
* (c) 2016-2022 maptalks.org
|
|
17
|
+
*/
|
|
18
|
+
let et=0;function nt(t){return null==t}function rt(t){return!nt(t)}function st(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 it(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 ot(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function at(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 ct=[],ht=[],ut=[],ft=[0,0,0],lt=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}([]),dt=[1,1,1];function mt(t,e,n,r,s,i,o){const a=it(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}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 bt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function yt(t,e,n){const r=new Uint8Array(t,e,n);return bt.decode(r)}const pt={get:function(t,e={}){e||(e={});const n=new AbortController,r={signal:n.signal,method:e.method||"GET",referrerPolicy:"origin"};"POST"===e.method&&(nt(e.body)||(r.body=JSON.stringify(e.body))),nt(e.headers)||(r.headers=e.headers),nt(e.credentials)||(r.credentials=e.credentials);const s=fetch(t,r).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 s.xhr=n,s},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",pt.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?pt.jsonp(t):((e=e||{}).responseType="json",pt.get(t,e))}};pt.jsonp=function(t){const e="_maptalks_jsonp_"+et++;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 gt{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(ot(t.uri)){const r=this.buffers[t.id]=at(t.uri),s=this.u(e,r);return this.getImageByBuffer(s,n)}return this.h[t.id]=pt.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;if(n[e.mimeType])return n[e.mimeType](t,{supportedFormats:this.o});if("image/crn"===e.mimeType||"image/ktx2"===e.mimeType||"image/cttf"===e.mimeType)return console.warn("missing transcoder for "+e.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null);{const n=new Blob([t],{type:e.mimeType}),r=URL.createObjectURL(n);return this.l(e.id,r)}}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;if(this.h[t.id])return this.h[t.id].then((()=>this.images[t.id]));return 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 Tt=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16];class wt{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(ot(e.uri)){const t=this.buffers[e.id]=at(e.uri);return Promise.resolve({buffer:t,byteOffset:0})}let t;t=e.uri.indexOf("://")>0||e.uri.indexOf("blob:")>=0?e.uri:this.rootPath+"/"+e.uri;return this.requests[e.id]=pt.getArrayBuffer(t,null).then((t=>({buffer:this.buffers[e.id]=t.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.O(i.type),h=it(i.componentType),u=o.byteStride||0;const f={array:undefined,name:t,accessorName:e,byteLength:i.count*c*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:c};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.A(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);f.array=mt(t,n,i.count,c,u,a+(i.byteOffset||0),i.componentType)}else f.byteStride=0,f.array=this.A(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)}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=Tt.indexOf(t);return Tt[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=yt(s,i+(e.byteOffset||0),n);return t.content=o,t}))}if(t.uri){if(ot(t.uri)){const e=at(t.uri),n=yt(e,0,e.byteLength);return t.content=n,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return pt.get(e).then((e=>(t.content=e,t)))}}return Promise.resolve(t)}));return Promise.all(n).then((()=>t))}}class _t extends gt{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 wt(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(rt(t.name)&&(e.name=t.name),rt(t.children)&&(e.children=t.children),rt(t.jointName)&&(e.jointName=t.jointName),rt(t.matrix)&&(e.matrix=t.matrix),rt(t.rotation)&&(e.rotation=t.rotation),rt(t.scale)&&(e.scale=t.scale),rt(t.translation)&&(e.translation=t.translation),rt(t.extras)&&(e.extras=t.extras),rt(t.meshes)&&(e.mesh=t.meshes[0]),e.translation||e.rotation||e.scale){const t=function(t,e){if(e.matrix)return e.matrix;if(e.translation||e.scale||e.rotation){const n=function(t,e){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=e[0],t[13]=e[1],t[14]=e[2],t[15]=1,t}(ct,e.translation||ft),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,b=i*o,y=i*a,p=i*c;return t[0]=1-f-m,t[1]=u+p,t[2]=l-y,t[3]=0,t[4]=u-p,t[5]=1-h-m,t[6]=d+b,t[7]=0,t[8]=l+y,t[9]=d-b,t[10]=1-h-f,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(ht,e.rotation||lt),s=function(t,e){return t[0]=e[0],t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=e[1],t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=e[2],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(ut,e.scale||dt);return P(s,r,s),P(t,n,s)}return function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}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 Ot extends gt{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 wt(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 st(e,t),!rt(t.weights)&&this.gltf.meshes&&rt(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;const n=this.gltf.images[e.source];return this.S(n).then((t=>{if(!t)return null;const r={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:n.mimeType,name:n.name,extensions:n.extensions,extras:n.extras}};st(r,e);const s=rt(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return s&&(r.sampler=s),t.format&&(r.format=t.format),r}))}S(t){if(!rt(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]);n.join("");const r="data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(n)));return r}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++)(rt(t[n].input)||rt(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 At="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null,It=1313821514,xt=5130562;class St{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 St.readV1(r,e);if(2===s)return St.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=Mt(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,c===It)n=Mt(t,e+12+o,a);else if(c===xt){s=e+12+o,r=a;break}o+=a}return{json:JSON.parse(n),glbBuffer:{byteOffset:s,buffer:t,byteLength:r}}}}function Mt(t,e,n){if(At){const r=new Uint8Array(t,e,n);return At.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=Nt[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 Nt=[1,1,1,1,2,2,3,0];const vt=[0,0,0],Et=[0,0,0,1],Rt=[1,1,1],Lt={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},Bt={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Pt={R(t,e,n,r,s,i,o,a){const c=rt(t)?e.animations:[e.animations[0]],h={};for(let e=0;e<c.length;e++){const u=c[e],f=u.name||e;if(rt(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.L(s,u.samplers[e.sampler],r,1),h.translation=V(vt,s)):"rotation"===e.target.path?(this.B(i,u.samplers[e.sampler],r,1),h.rotation=tt(Et,i)):"scale"===e.target.path?(this.L(o,u.samplers[e.sampler],r,1),h.scale=V(Rt,o)):"weights"===e.target.path&&a&&(this.L(a,u.samplers[e.sampler],r,a.length),h.weights=a)}}return h},L(t,e,n,r){switch(e.interpolation){case"LINEAR":{const s=this.P(Bt,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(Bt,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(Bt,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.P(Bt,e,n,1);r&&J(t,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this.P(Bt,e,n,1);r&&(t=Y(t,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this.P(Bt,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},C(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.C(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},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],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;F(vt,...Lt.TRANSLATION),Y(Et,...Lt.ROTATION),F(Rt,...Lt.SCALE);return this.R(r,t,e,n,vt,Et,Rt,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?rt(e)?n[e]:n[Object.keys(n)[0]]:null}};let Ut=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(t){}t&&"undefined"!=typeof createImageBitmap&&(Ut=!0)}const Ct="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}=St.read(e.buffer,e.byteOffset,e.byteLength);this.D(t,n,r)}else this.D(t,e);this.V=new wt(this.rootPath,this.gltf,this.glbBuffer),this.F()}F(){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")}}k(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.V.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then((e=>(t.KHR_techniques_webgl=e,t))):Promise.resolve(t)}load(t){t=t||{};const e=this.H(t),n=this.G(),r=this.q(),s=this.k();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 Pt.getAnimationClip(t,e,n,r)}static getAnimationTimeSpan(t,e){return Pt.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return it(t)}static readInterleavedArray(t,e,n,r,s,i,o){return mt(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=Ut?Ht:this.options.requestImage||Vt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new Ot(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 _t(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"))}j(t,e){if(t.children&&t.children.length>0){if(!(n=t.children[0],"number"==typeof n&&isFinite(n)||function(t){return!nt(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}(t.children[0])))return t;const r=t.children.map((t=>{const n=e[t];return n.nodeIndex=t,this.j(n,e)}));t.children=r}var n;return t}H(t){return this.$(t).then((t=>{const e=this.scenes=[];let n;for(const e in t)t[e]=this.j(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate(((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={asset:this.gltf.asset,scene:n,scenes:e,nodes:t,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins};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}))}$(t){return this.X(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}))}Z(){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)))}G(){const t=this.gltf.animations;return rt(t)?this.adapter.getAnimations(t):null}X(t){this.meshes={};let e=[];return this.adapter.iterate(((n,r,s)=>{e.push(this.Y(r,t).then((t=>{t.index=s,this.meshes[n]=t})))}),"meshes"),e=e.concat(this.Z()),Promise.all(e)}Y(t,e){const n=t.primitives.map((t=>this.W(t,e))).filter((t=>!!t));return Promise.all(n).then((e=>{const n={};return st(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.M(n));return Promise.all(e).then((e=>{if(this.transferables)for(let t=0;t<e.length;t++)if(e[t]&&e[t].image.array){const n=e[t].image.array.buffer;n&&this.transferables.indexOf(n)<0&&this.transferables.push(n)}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}))}W(t,e){let n;const r=[],s=t.extensions;if(rt(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.V._(a).then((n=>{const{buffer:r,byteOffset:s}=n;let{byteOffset:i,byteLength:c}=a;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(rt(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=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;q(t,t,s),k(t,t,i),q(n,n,s),k(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}),{}),o={attributes:i,material:t.material};return n&&(o.indices=n),r&&(o.morphTargets=r),o.mode=rt(t.mode)?t.mode:4,rt(t.extras)&&(o.extras=t.extras),o}))}}function Vt(t,e){const n=new Image;n.crossOrigin="",n.onload=()=>{if(!Ct)return void e(new Error("There is no canvas to draw image!"));Ct.width=n.width,Ct.height=n.height;const t=Ct.getContext("2d");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 Ft,kt;function Ht(t,e){Ft||(Ft=new OffscreenCanvas(2,2),kt=Ft.getContext("2d")),fetch(t).then((t=>t.blob())).then((t=>createImageBitmap(t))).then((t=>{let{width:n,height:r}=t;Gt(n)||(n=qt(n)),Gt(r)||(r=qt(r)),Ft.width=n,Ft.height=r,kt.drawImage(t,0,0,n,r),t.close();const s=kt.getImageData(0,0,n,r);e(null,{width:n,height:r,data:new Uint8Array(s.data)})})).catch((t=>{console.warn(t),e(t)}))}function Gt(t){return 0==(t&t-1)&&0!==t}function qt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}const jt="undefined"==typeof document?null:document.createElement("canvas");class zt extends t.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(!jt)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if($t(t.width)&&$t(t.height))return t;let e=t.width,n=t.height;$t(e)||(e=Xt(e));$t(n)||(n=Xt(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);jt.width=t.width,jt.height=t.height;const r=jt.getContext("2d");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 $t(t){return 0==(t&t-1)&&0!==t}function Xt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}class Zt{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(let 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 Kt(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=[];Yt(r[n],s,t,e)}}}function Yt(t,e,n,r){if(t.matrix&&e.push(t.matrix),t.children&&t.children.length)for(let s=0,i=t.children.length;s<i;s++)Yt(t.children[s],e,n,r);if(void 0!==t.mesh){const s=t.mesh,i=n.meshes[s];if(i){const t=e.slice(0),o=i.primitives;for(let e=0,i=o.length;e<i;e++){const i=o[e];i&&(i.matrices=t,r(i,s,e,n))}}}}function Wt(t,e,n){let{componentType:r,byteOffset:s,byteStride:i,itemSize:o}=e;const a=e.array.buffer,c=r?Dt.getTypedArrayCtor(r):e.array.constructor;if(s=void 0===s?e.array.byteOffset:s,i=i||0,!i||i===o*c.BYTES_PER_ELEMENT&&s%c.BYTES_PER_ELEMENT==0){const e=new c(a,s+n*o*c.BYTES_PER_ELEMENT,o);return t.set(e),t}i||(i=o*c.BYTES_PER_ELEMENT);const h=new Uint8Array(a,i*n+s,o*c.BYTES_PER_ELEMENT);return new Uint8Array(t.buffer).set(h),t}function Jt(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 Qt=new Array(3),te=new Array(3),ee=[40680631590769,40680631590769,40408299984661.445];function ne(t,e,n,r){const s=ee,i=Math.cos(n);Qt[0]=i*Math.cos(e),Qt[1]=i*Math.sin(e),Qt[2]=Math.sin(n),le(Qt,Qt),G(te,s,Qt);const o=Math.sqrt(z(Qt,te));var a,c,h;return c=te,h=o,(a=te)[0]=c[0]/h,a[1]=c[1]/h,a[2]=c[2]/h,q(Qt,Qt,r),k(t,te,Qt)}const re=[1/6378137,1/6378137,1/6356752.314245179],se=[1/40680631590769,1/40680631590769,1/40408299984661.445],ie=new Array(3),oe=new Array(3),ae=new Array(3);function ce(t,e){const n=se,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,b=Math.sqrt(1/m),y=q(he,e,b);if(m<s)return isFinite(b)?y:void 0;const p=r[0],g=r[1],T=r[2],w=ue;w[0]=y[0]*p*2,w[1]=y[1]*g*2,w[2]=y[2]*T*2;let _,O,A,I,x,S,M,N,v,E,R,L=(1-b)*fe(e)/(.5*fe(w)),B=0;do{L-=B,A=1/(1+L*p),I=1/(1+L*g),x=1/(1+L*T),S=A*A,M=I*I,N=x*x,v=S*A,E=M*I,R=N*x,_=f*S+l*M+d*N-1,O=f*v*p+l*E*g+d*R*T;B=_/(-2*O)}while(Math.abs(_)>1e-12);return t[0]=i*A,t[1]=o*I,t[2]=a*x,t}(ie,e,re,n,.1);let s=Z(oe,r,n);s=le(s,s);const i=X(ae,e,r),o=Math.atan2(s[1],s[0]),a=Math.asin(s[2]),c=I(z(i,e))*fe(i);return t[0]=O(o),t[1]=O(a),t[2]=c,t}const he=new Array(3),ue=new Array(3);function fe(t){return C(t)}function le(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 de(t,e){return G(e,t,se),j(e,e)}var me=Object.freeze({__proto__:null,radianToCartesian3:ne,cartesian3ToDegree:ce,normalizeCartesian:le,geodeticSurfaceNormal:de});function be(t,e){let n="";for(let r=0;r<4;r++){const s=t.getUint8(e+r);n+=String.fromCharCode(s)}return n}const ye="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function pe(t,e,n){const r=new Uint8Array(t,e,n);return ye?JSON.parse(ye.decode(r)):JSON.parse(S(r))}function ge(t,e,n){const r=new Uint8Array(t,e,n);return ye?JSON.parse(ye.decode(r)):JSON.parse(S(r))}function Te(t,e,n){return{offset:e,byteLength:n}}function we(t,e,n,r){const{byteOffset:s,componentType:i,type:o}=t,{ctor:a,type:c}=function(t){return Ae[t]}(i),h=function(t){if(!t)return 1;return Oe[t]}(o);return{byteStride:0,byteOffset:s+n,itemSize:h,count:r*h,componentType:c,array:new a(e,n+s,r*h)}}function _e(t,e,n,r){t.componentType||(t.componentType="UNSIGNED_SHORT");const s=we(t,e,n,r);return s.array.buffer.byteLength!==e.byteLength&&(s.array=s.array.slice()),s}const Oe={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const Ae={"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 Ie(t){for(let e in Ae)if(t===Ae[e].ctor)return Ae[e].type;throw new Error("unrecognized ctor:"+t)}function xe(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 Se(t,e,n){let r=t.getUint32(12,!0),s=t.getUint32(16,!0),i=t.getUint32(20,!0),o=t.getUint32(24,!0);const a=t.buffer;let c,h,u={},f={};r>0&&(u=pe(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=ge(a,e,i),e+=i);const l=Te(0,e,o);return h=a.slice(l.offset,l.offset+l.byteLength),n.push(h),{featureTable:u,featureTableBin:c,batchTable:f,batchTableBin:h}}var Me={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Ne={},ve={east:[],north:[],up:[],west:[],south:[],down:[]},Ee=[],Re=[],Le=[];const Be=[0,0,0];function Pe(t,e,n,r){n=n||0,r=r||n;var s=Math.abs(t-e);return s<=r||s<=n*Math.max(Math.abs(t),Math.abs(e))}function Ue(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 Ce=(ke={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"}}[De="east"][Ve="north"],Ne[He=De+Ve]?Fe=Ne[He]:(Fe=function(t,e,n){if(a=Be,c=(o=t)[0],h=o[1],u=o[2],f=a[0],l=a[1],d=a[2],Math.abs(c-f)<=1e-6*Math.max(1,Math.abs(c),Math.abs(f))&&Math.abs(h-l)<=1e-6*Math.max(1,Math.abs(h),Math.abs(l))&&Math.abs(u-d)<=1e-6*Math.max(1,Math.abs(u),Math.abs(d)))V(Ee,Me[De]),V(Re,Me[Ve]),V(Le,Me[ke]);else if(Pe(t[0],0,1e-14)&&Pe(t[1],0,1e-14)){var r=I(t[2]);V(Ee,Me[De]),"east"!==De&&"west"!==De&&q(Ee,Ee,r),V(Re,Me[Ve]),"east"!==Ve&&"west"!==Ve&&q(Re,Re,r),V(Le,Me[ke]),"east"!==ke&&"west"!==ke&&q(Le,Le,r)}else{de(t,ve.up);var s=ve.up,i=ve.east;i[0]=-t[1],i[1]=t[0],i[2]=0,j(ve.east,i),$(ve.north,s,i),q(ve.down,ve.up,-1),q(ve.west,ve.east,-1),q(ve.south,ve.north,-1),Ee=ve[De],Re=ve[Ve],Le=ve[ke]}var o,a,c,h,u,f,l,d;return n[0]=Ee[0],n[1]=Ee[1],n[2]=Ee[2],n[3]=0,n[4]=Re[0],n[5]=Re[1],n[6]=Re[2],n[7]=0,n[8]=Le[0],n[9]=Le[1],n[10]=Le[2],n[11]=0,n[12]=t[0],n[13]=t[1],n[14]=t[2],n[15]=1,n},Ne[He]=Fe),Fe);var De,Ve,Fe,ke,He;const Ge=[],qe=[],je=[],ze=[],$e=[],Xe=[],Ze=[],Ke={x:0,y:0},Ye={x:0,y:0},We=Math.PI/180;const{getTextureMagFilter:Je,getTextureMinFilter:Qe,getTextureWrap:tn,getMaterialType:en,getMaterialFormat:nn,getPrimitive:rn,getUniqueREGLBuffer:sn}=n.REGLHelper,on=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],an=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:cn,logoutIBLResOnCanvas:hn,getIBLResOnCanvas:un,getPBRUniforms:fn}=n.pbr.PBRUtils,ln={factor:0,units:0},dn={specularStrength:0,materialShininess:1},mn=[1,1,1],bn=r.identity([]),yn=t=>t.material instanceof n.PhongMaterial,pn=t=>t.material instanceof n.pbr.StandardMaterial,gn=[!0,!0,!0,!0],Tn=[],wn=new t.Coordinate(0,0),_n=[],On=[],An={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT"};class In{constructor(e,r){this.J=r,this.tt=r.getRenderer().canvas,this.et=new t.SpatialReference,this.nt=e,this.rt=new n.Renderer(e),this.st={},this.it={},this.ot={},this.at={},this.ct={},this.ht={},this.ut={},this.ft=new n.Scene,this.lt=new n.Scene,this.dt=new n.Scene,this.bt=new n.Scene,this.yt=new n.ResourceLoader(e.texture(2)),this.gt=this.Tt.bind(this),this.wt=new n.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this._t(),this.Ot=new n.KHRTechniquesWebglManager(this.nt,this.At(),this.yt)}getI3DMMeshes(){return this.ct}getPNTSMeshes(){return this.at}getB3DMMeshes(){return this.ot}getMap(){return this.J.getMap()}paint(t,e,n,r){const s=this.getMap();if(!t.length||!s)return;const i=this.It(),o=s.projViewMatrix,a=this.J.options.services,c=[];let h=[];for(let n=0,r=t.length;n<r;n++){let r=this.xt(t[n].data.node);if(!r){if(r=this.ht[t[n].data.node.id],!r)continue;r=N(r)}const s=t[n].node;let u=a[s.St].polygonOffset||ln;w(u)&&(u=u());const f=a[s.St].ambientLight;for(let a=0,l=r.length;a<l;a++)"b3dm"===r[a].properties.magic&&(r[a].getBoundingBox&&!d(o,r[a].getBoundingBox())||(r[a].properties.level=t[n].selectionDepth,r[a].properties.polygonOffset=u,Object.prototype.hasOwnProperty.call(r[a].uniforms,"ambientColor")||Object.defineProperty(r[a].uniforms,"ambientColor",{enumerable:!0,get:function(){return f||i.ambientColor}}),r[a].Mt=s,e[s.id]||c.push(r[a]),h.push(r[a])))}let u=0;const f=this.Ot.getExcludeFilter();u+=this.Nt(this.vt,i,[n,yn,f],r,c,h),u+=this.Nt(this.Et,i,[n,pn,f],r,c,h),this.Ot.forEachShader(((t,e,s)=>{const i=this.It(s);u+=this.Nt(t,i,[n,e],r,c,h)}));const l=[];for(const t in this.at)l.push(this.at[t]);this.lt.setMeshes(l);const m=this.Rt();return u+=this.rt.render(this.Lt,m,this.lt,r&&r.fbo),u}Nt(t,e,n,r,s,i){t.filter=n.filter((t=>!!t)),e.debug=!1,this.ft.setMeshes(s),e.stencilEnable=!1,e.debug=!1,e.cullFace="back",e.colorMask=gn;let o=0;this.ft.setMeshes(i),o+=this.rt.render(t,e,this.ft,r&&r.fbo),e.stencilEnable=!1;const a=[];for(const t in this.ct)a.push(...this.ct[t]);return this.dt.setMeshes(a),o+=this.rt.render(t,e,this.dt,r&&r.fbo),o}Bt(t,e){return e.Mt.Pt-t.Mt.Pt}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.Ut(e);r&&(r.getBoundingBox&&!d(o,r.getBoundingBox())||a.push(r))}this.Ct.filter=r,this.bt.setMeshes(a);const c=this.Dt(n);this.rt.render(this.Ct,c,this.bt,s&&s.fbo)}deleteTile(t){const e=t.node.id;this.Vt(e)}Vt(t){const e=this.it[t];e&&(e.geometry.dispose(),e.dispose(),delete this.it[t]);let n=this.ot[t]||this.at[t]||this.ct[t]||this.ht[t]||this.st[t];this.ht[t]?this.Ft(t):n&&(this.kt(n),delete this.ot[t],delete this.at[t],delete this.ct[t],delete this.st[t])}Ft(t){let e=this.ht[t];e=N(e);for(let t=0;t<e.length;t++){const{id:n}=e[t].properties;this.Vt(n)}delete this.ht[t]}kt(t){if(Array.isArray(t))for(let e=0,n=t.length;e<n;e++)this.kt(t[e]);else{const e=t.geometry.properties.url;if(e){const t=this.ut[e];t&&(t.refCount--,t.refCount<=0&&(t.geometry.dispose(),t.material.dispose(),delete this.ut[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.J;hn(t.getRenderer().canvas,t.getMap());for(const t in this.ht)this.Ft(t);this.ht={};for(const t in this.ot)this.Vt(t);this.ot={};for(const t in this.at)this.Vt(t);this.at={};for(const t in this.ct)this.Vt(t);this.ct={};for(const t in this.st)this.Vt(t);this.st={};for(const t in this.it)this.Vt(t);this.it={},this.vt&&(this.vt.dispose(),delete this.vt),this.Et&&(this.Et.dispose(),delete this.Et),this.Lt&&(this.Lt.dispose(),delete this.Lt),this.Ct&&(this.Ct.dispose(),delete this.Ct),this.Ot.dispose()}Ut(e){if(!e.boundingVolume||!e.boundingVolume.region)return null;if(this.it[e.id])return this.it[e.id];const s=e.boundingVolume.region;let i=new t.Coordinate(O(s[0]),O(s[1])),o=new t.Coordinate(O(s[2]),O(s[3]));i=this.Ht(i),o=this.Ht(o);const a=i.add(o).Gt(.5);i._sub(a),o._sub(a);const c=this.qt(s[4],s[5]),h=c.x,u=c.y,f=[i.x,i.y,u,o.x,i.y,u,o.x,o.y,u,i.x,o.y,u,i.x,i.y,h,o.x,i.y,h,o.x,o.y,h,i.x,o.y,h],l=new n.Geometry({aPosition:f},[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"});l.generateBuffers(this.nt);const d=new n.Mesh(l),m=r.identity([]);return d.setLocalTransform(r.translate(m,m,[a.x,a.y,0])),this.it[e.id]=d,d}xt(t){return this.ot[t.id]}has(t){return this.xt(t)||this.at[t.id]||this.ct[t.id]||this.ht[t.id]||this.st[t.id]}createPntsMesh(t,e,s,i){if(this.at[e]){const t=this.at[e];return console.warn(`pnts mesh with id(${e}) was already created.`),i(null,{id:e,mesh:t}),t}const{pnts:o,featureTable:a,rootIdx:c}=t,h=a.POINTS_LENGTH,u=new n.Geometry(o,null,h,{primitive:"points",positionAttribute:"POSITION"});u.generateBuffers(this.nt);const f={};o.POSITION?f.HAS_POSITION=1:o.POSITION_QUANTIZED&&(f.HAS_POSITION_QUANTIZED=1),o.RGB?f.HAS_RGB=1:o.RGBA?f.HAS_RGBA=1:o.RGB565&&(f.HAS_RGB565=1),(o.NORMAL||o.NORMAL_OCT16P)&&(f.HAS_NORMAL=1,o.NORMAL_OCT16P&&(f.HAS_NORMAL_OCT16P=1)),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map((t=>t/255)));const{rtcCenter:l,rtcCoord:d}=t,m=this.jt(d),b=this.zt(s,l,d);r.multiply(b,b,m);const y=this.J.options.services[c],p=new n.Mesh(u);return p.properties.magic="pnts",p.properties.id=e,p.properties.count=h,p.properties.batchTable=t.batchTable,p.properties.batchTableBin=t.batchTableBin,p.setDefines(f),Object.defineProperty(p.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:y&&y.pointColor||[1,1,1,1]}}),Object.defineProperty(p.uniforms,"pointSize",{enumerable:!0,get:function(){return y&&y.pointSize||2}}),Object.defineProperty(p.uniforms,"pointOpacity",{enumerable:!0,get:function(){return y&&y.pointOpacity||1}}),p.setLocalTransform(b),this.at[e]=p,i(null,{id:e,mesh:[p]}),[p]}createI3DMMesh(t,e,i,o){if(this.ct[e]){const t=this.ct[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.st[e]||o(null,{id:e,mesh:t}),t}const c=this.$t(i.Xt),{i3dm:h,featureTable:u,gltf:f,batchTable:l,batchTableBin:d,count:m}=t,b=u.INSTANCES_LENGTH,{rtcCenter:y,rtcCoord:p}=t,g=this.jt(p),T=this.zt(i,y,p),{POSITION:w,NORMAL_UP:_,NORMAL_RIGHT:O,SCALE:A,SCALE_NON_UNIFORM:I,INSTANCE_ROTATION:x}=h,S={"instance_vectorA":new Float32Array(4*b),"instance_vectorB":new Float32Array(4*b),"instance_vectorC":new Float32Array(4*b)},N=new Float32Array(3),v=new Float32Array(3),E=[],R=new Float32Array(1),L=new Float32Array(3),B=[],P=[],U=[],C=[],D=new Float32Array(9);!function(t,e){let{componentType:n,byteOffset:r,byteStride:s,count:i,itemSize:o}=t;const a=t.array.buffer,c=n?Dt.getTypedArrayCtor(n):t.array.constructor;if(r=void 0===r?t.array.byteOffset:r,s=s||0,i=i||t.array.length/o,(!s||s===o*c.BYTES_PER_ELEMENT)&&r%c.BYTES_PER_ELEMENT==0){const t=new c(a,r,i*o);for(let n=0;n<i*o;n+=o)e(new c(t.buffer,r+n*c.BYTES_PER_ELEMENT,o),n/o);return}const h=new Uint8Array(o*c.BYTES_PER_ELEMENT);s||(s=o*c.BYTES_PER_ELEMENT);for(let t=0;t<i;t++){const n=new Uint8Array(a,s*t+r,o*c.BYTES_PER_ELEMENT);h.set(n),e(new c(h.buffer),t),n.set(h)}}(w,((t,e)=>{_?(Wt(v,O,e),Wt(N,_,e),s.cross(E,v,N),s.normalize(E,E),M(B,v,0),M(B,N,1),M(B,E,2),a.fromMat3(P,B)):x?(Wt(D,x,e),a.fromMat3(P,D)):a.identity(P),A?(Wt(R,A,e),s.set(U,R[0],R[0],R[0])):I?(Wt(L,I,e),s.set(U,...L)):s.set(U,1,1,1),r.fromRotationTranslationScale(C,P,t,U),Jt(S.instance_vectorA,e,C,0),Jt(S.instance_vectorB,e,C,1),Jt(S.instance_vectorC,e,C,2)}));const V={};for(const t in S)V[t]={buffer:this.nt.buffer({dimension:S[t].length/b,data:S[t]}),divisor:1};const F=this.J.options.services[i.St].shader||"phong";let k=0,H=!0;const G=[];return Kt(f,((t,s,o,a)=>{let{geometry:h,material:u}=this.Zt(t,s,o,a,i,!0,F);u&&!u.isReady()&&(H=!1,k++);const f=new n.InstancedMesh(V,b,h,u);f.properties.magic="i3dm",f.properties.id=e,f.properties.count=m,f.properties.batchTable=l,f.properties.batchTableBin=d;const y=this.Kt(t,h,u,i.St),p=r.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.multiply(p,p,t.matrices[e]);r.multiply(p,c,p),f.setPositionMatrix(p),r.multiply(g,T,g),f.setLocalTransform(g),f.setDefines(y),f.properties.polygonOffset={offset:0,factor:0},G.push(f)})),H?(this.ct[e]=G,o(null,{id:e,mesh:G})):(this.st[e]={meshes:G,count:k},G.Yt=o),G}createB3DMMesh(e,s,i,o){if(this.ot[s]||this.st[s]){const t=this.ot[s];return console.warn(`mesh with id(${s}) was already created.`),this.st[s]||o(null,{id:s,mesh:t}),t}let a;if(i.maxExtent){const e=new t.Extent(i.maxExtent).convertTo((t=>this._pointToPrj(t)));a=[e.xmin,e.ymin,e.xmax,e.ymax]}const c=this.$t(i.Xt),h=e.gltf,{center:u,coord:f}=h.extensions.CESIUM_RTC,l=this.J.options.services[i.St].heightOffset||0;l&&(f[2]+=l);const d=this.jt(f,i.St),m=this.J.options.services[i.St].shader||"phong",b=[];let y=0,p=!0;return Kt(h,((t,o,h,l)=>{let{geometry:g,material:T}=this.Zt(t,o,h,l,i,!1,m);T&&!T.isReady()&&(p=!1,y++);const w=new n.Mesh(g,T);w.properties.magic="b3dm",w.properties.id=s,w.properties.batchTable=e.batchTable,w.properties.batchTableBin=e.batchTableBin,w.properties.count=e.featureTable.BATCH_LENGTH;const _=this.Kt(t,g,T,i.St);w.setDefines(_),a&&(_.USE_MAX_EXTENT=1,w.setUniform("maxPrjExtent",a));let O=r.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.multiply(O,O,t.matrices[e]);const A=this.zt(i,u,f);r.multiply(O,c,O),r.multiply(O,d,O),r.multiply(O,A,O),w.setLocalTransform(O),b.push(w)})),p?(this.ot[s]=b,o(null,{id:s,mesh:b})):(this.st[s]={meshes:b,count:y},b.Yt=o),b}zt(e,n,i){const o=this.getMap(),a=this.J.options.services[e.St].heightOffset||0,c=new t.Coordinate(i),h=o.distanceToPointAtRes(100,0,o.getGLRes(),c).x/100;let u=e.matrix?r.copy([],e.matrix):r.identity([]);if(n){Ue(u,s.transformMat4(Tn,n,u),u)}const f=function(t,e,n,r,s,i,o){e=V(Ge,e);const a=ne(Ge,e[0]*We,e[1]*We,e[2]),c=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}(qe,n),h=r.ellipsoid;var u;u=0===K(c)?F(je,0,0,-6378137):ce(je,c),Ke.x=u[0],Ke.y=u[1];const f=r.project(Ke,Ye);ze[0]=f.x/s,ze[1]=f.y/s,ze[2]=(u[2]+o)*i;const l=Ce(a,h,$e),d=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],b=e[13],y=e[14],p=e[15],g=n*a-r*o,T=n*c-s*o,w=n*h-i*o,_=r*c-s*a,O=r*h-i*a,A=s*h-i*c,I=u*b-f*m,x=u*y-l*m,S=u*p-d*m,M=f*y-l*b,N=f*p-d*b,v=l*p-d*y,E=g*v-T*N+w*M+_*S-O*x+A*I;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]=(b*A-y*O+p*_)*E,t[3]=(l*O-f*A-d*_)*E,t[4]=(c*S-o*v-h*x)*E,t[5]=(n*v-s*S+i*x)*E,t[6]=(y*w-m*A-p*T)*E,t[7]=(u*A-l*w+d*T)*E,t[8]=(o*N-a*S+h*I)*E,t[9]=(r*S-n*N-i*I)*E,t[10]=(m*O-b*w+p*g)*E,t[11]=(f*w-u*O-d*g)*E,t[12]=(a*x-o*M-c*I)*E,t[13]=(n*M-r*x+s*I)*E,t[14]=(b*T-m*_-y*g)*E,t[15]=(u*_-f*T+l*g)*E,t):null}(Xe,l),m=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}(Ze,n),b=function(t,e,n){var 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],b=e[3],y=e[4],p=e[5],g=e[6],T=e[7],w=e[8],_=r*l+o*d+h*m,O=s*l+a*d+u*m,A=i*l+c*d+f*m,I=r*b+o*y+h*p,x=s*b+a*y+u*p,S=i*b+c*y+f*p,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]=O,n[2]=A,n[3]=0,n[4]=I,n[5]=x,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}(d,m,t);return Ue(t,ze,b),t}(u,i,u,o.getProjection(),o.getGLRes(),h,a),l=function(t,e){return F(t,e[12],e[13],e[14]),t}(On,f);let d=this.J.options.offset;if(w(d)){d=d(this.J.Wt(e.id).center)}return s.set(_n,d[0],d[1],0),s.sub(l,l,_n),Ue(f,l,f),f}createCMPTMesh(t,e,n,r){if(this.ht[e]){const t=this.ht[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.ht[e]=i,r(null,{id:e,mesh:i}),i}Kt(t,e,n,r){return("phong"===(this.J.options.services[r].shader||"phong")?this.vt:this.Et).getGeometryDefines(e)}Zt(t,e,n,r,s,i,o){const a=r.url+"-"+e+"-"+n;if(this.ut[a])return this.ut[a].refCount++,this.ut[a];let c,h;const u=r.materials[t.material];if(r.extensions&&r.extensions.KHR_techniques_webgl&&u.extensions&&u.extensions.KHR_techniques_webgl){const e=this.Jt(t,r,i);c=e.material,h=e.geometry}else{h=this.Qt(t,i,An);const e=this.J.options.services[s.St].material;c=this.te(t.material,r,o,e||dn)}c&&!c.isReady()?c.ee=s.id:c||(c=this.wt);const f={refCount:1,geometry:h,material:c};return h.properties.url=a,this.ut[a]=f,f}Jt(t,e,n){const{geometry:r,material:s}=this.Ot.createMesh(t,e,n);return{geometry:r,material:s}}Qt(t,e,r){const s=t.attributes,i=r.COLOR_0;if(s[i]&&s[i]instanceof Float32Array){const t=new Uint8Array(s[i].length);for(let e=0;e<t.length;e++)t[e]=Math.round(255*s[i][e]);s[i]=t}const o={};for(const t in s){const e=sn(this.nt,s[t],{dimension:s[t].itemSize}),n=r[t]||t;o[n]={buffer:e},n===r.POSITION&&(o[n].array=s[t].array,o[n].min=s[t].min,o[n].max=s[t].max)}delete t.attributes;const a=new n.Geometry(o,t.indices.array?t.indices.array:t.indices,0,{positionAttribute:r.POSITION,normalAttribute:r.NORMAL,uv0Attribute:r.TEXCOORD_0,uv1Attribute:r.TEXCOORD_1,color0Attribute:r.COLOR_0,tangentAttribute:r.TANGENT,primitive:void 0===t.mode?"triangles":rn(t.mode)});return a.generateBuffers(this.nt,{excludeElementsInVAO:e}),a}jt(t){const e=r.identity([]),n=this.getMap(),i=this.ne();wn.x=t[0],wn.y=t[1];const o=n.distanceToPointAtRes(100,100,n.getGLRes(),wn);return s.set(i,o.x/100*1.01,o.y/100*1.01,o.y/100),r.scale(e,e,i),e}_t(){const t={x:0,y:0,width:()=>this.tt?this.tt.width:1,height:()=>this.tt?this.tt.height:1};this.Ct=new n.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;\nuniform vec3 color;\nvoid main() {\n gl_FragColor = vec4(color, 1.0);\n}\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],s=[];this.Lt=new n.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\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 = 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)=>r.multiply(s,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,n)=>i.fromMat4(e,n.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 o=this.At();this.vt=new n.PhongShader({extraCommandProps:o}),this.Et=new n.pbr.StandardShader({extraCommandProps:o});const a=this.J;cn(a.getRenderer().canvas,this.nt,a.getMap())}At(){return{viewport:{x:0,y:0,width:()=>this.tt?this.tt.width:1,height:()=>this.tt?this.tt.height:1},colorMask:(t,e)=>e.colorMask||gn,cull:{enable:!0,face:(t,e)=>e.cullFace},stencil:{enable:(t,e)=>e.stencilEnable,func:{cmp:">=",ref:(t,e)=>e.meshProperties.level},opFront:{fail:"keep",zfail:"keep",zpass:"replace"},opBack:{fail:"keep",zfail:"keep",zpass:"keep"}},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},polygonOffset:{enable:!0,offset:(t,e)=>e.meshProperties.polygonOffset}}}Dt(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}Rt(t){const e=this.getMap(),n=e.getLightManager(),r=(n&&n.getDirectionalLight()||{}).direction||[1,1,-1],i=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:i,lightDir:s.normalize(r,r)}}It(){const t=this.getMap(),e=this.J.getRenderer().canvas,{iblTexes:n,dfgLUT:r}=un(e),s=fn(t,n,r);return T(s,{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}),s}te(t,e,r,s){const i=e.materials[t];if(!i||!i.baseColorTexture&&!i.pbrMetallicRoughness)return null;const a=T({},s);if(i.baseColorTexture){const t=e.textures[i.baseColorTexture.index];let n;t&&!t.image.color&&(n=this.M(t)),a.baseColorFactor=t&&t.image.color||i.baseColorFactor||[1,1,1,1],n&&(a.baseColorTexture=n)}else{if(i.normalTexture){const t=this.M(e.textures[i.normalTexture.index]),n=i.normalTexture.scale||1;a.normalTexture=t,a.normalMapFactor=n}if(i.occlusionTexture){const t=this.M(e.textures[i.occlusionTexture.index]),n=i.occlusionTexture.strength||1;a.occlusionTexture=t,a.occlusionFactor=n}if(i.emissiveTexture){const t=this.M(e.textures[i.emissiveTexture.index]);a.emissiveTexture=t}i.emissiveFactor;const t=i.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(a.baseColorFactor=t.baseColorFactor),t.baseColorTexture){const n=e.textures[t.baseColorTexture.index];n.image.color?a.baseColorFactor=a.baseColorFactor?o.multiply(a.baseColorFactor,a.baseColorFactor,n.image.color):n.image.color:a.baseColorTexture=this.M(n)}if(g(t.metallicFactor)||(a.metallicFactor=t.metallicFactor),g(t.roughnessFactor)||(a.roughnessFactor=t.roughnessFactor),i.metallicRoughnessTexture){const t=this.M(e.textures[i.metallicRoughnessTexture.index]);a.metallicRoughnessTexture=t}}}let c=new n.pbr.StandardMaterial(a);return"phong"===r&&(c=n.PhongMaterial.convertFrom(c)),c.once("complete",this.gt),c}M(t){const e={type:t.type?en(t.type):"uint8",format:t.format?nn(t.format):"rgba",flipY:!1},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.sampler;return s&&(s.magFilter&&(e.mag=Je(s.magFilter)),s.minFilter&&(e.min=Qe(s.minFilter)),s.wrapS&&(e.wrapS=tn(s.wrapS)),s.wrapT&&(e.wrapT=tn(s.wrapT))),new n.Texture2D(e,this.yt)}re(t){const e=t.image,n=window.URL||window.webkitURL,r=new Blob([e.array],{type:e.mimeType});return n.createObjectURL(r)}Tt({target:t}){const e=t.ee,n=this.st[e];if(n.count--,!n.count){const t=n.meshes;this.ot[e]=t,delete this.st[e];const r=t.Yt;delete t.Yt,r(null,{mesh:n.meshes,id:e})}}ne(){return mn}Ht(t){return this.J.Ht(t)}qt(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())}$t(t){return"Y"===t?on:"X"===t?an:bn}}class xn extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Zt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.se={},this.ie=[]}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.ie.length||super.needToRedraw())}drawOnInteracting(t,e,n){this.draw(e,n)}draw(t,e){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.oe();const{selectedTiles:o,leaves:a,requests:c}=this.ae(r,s);c.length&&this.loadTiles(c),this.ce(o,a,e),this.he(),c.length||this.completeRender()}ae(t,e){let n=[];this.ue();let r=0;const s=this.fe(),i={};let o=!1,a=!1;for(let t=0;t<e.length;t++){const s=e[t],c=s.node;if(i[c.id])continue;i[c.id]=1;let h=!1;const u=this.le(c.id);if(this.de(c.id)?(r++,h=a=!0,this.tilesLoading[c.id].current=!0):u?(this.getTileOpacity(u)<1&&(h=a=!0),o=!0,s.selected=!0,s.data=u):this.painter.has(c)||(h=a=!0,n.push(c)),!h)continue;if(this.me(s))o=!0;else{this.be(s).length&&(o=!0)}}let c=[],h={};if(o&&({selectedTiles:c,leaves:h}=this.ye(t)),n.length>1&&(n.sort(Sn),s)){const t=s-r;n=t>0?n.slice(0,t):[]}return{loading:a,requests:n,selectedTiles:c,leaves:h}}ye(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.pe===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.pe=s.length}for(let t=0;t<o.length;t++)s.push(o[t])}return{selectedTiles:e,leaves:n}}me(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}be(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const n=t.ge+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.Te(s[i],t);n.selected=!0,n.data=this.tileCache.get(o),t.children.push(n),e.push(n)}else s[i].ge<=n&&r.push(s[i])}}return e}ce(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=n&&n.renderTarget,i=n&&n.sceneFilter,o=this.painter.paint(t,e,i,s);this.layer.options.debug&&this.painter.paintRegion(t,{color:this.layer.options.debugOutline},i,s),this.onDrawTileEnd(r),o&&this.layer.fire("canvasisdirty",{renderCount:o})}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(E(e)){const n=R(e);return void this.we(e,n,t)}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&(e=t.baseUrl+e);const n=this.layer.options.services[t.St];if(n.ajaxInMainThread){let r=n.urlParams;r&&(r=(e.indexOf("?")>0?"&":"?")+r);let s=pt.getArrayBuffer(e+(r||""),n.fetchOptions);const i=s.xhr;s=s.then((n=>{delete this.se[e],n?this.we(e,n.data,t):this.onTileError(null,t)})).catch((n=>{delete this.se[e],this.onTileError(n,t)})),this.se[e]=i}else this.we(e,null,t)}we(t,e,r){let s=this.o;s||(s=n.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=s),this.workerConn.loadTile(this.layer.getId(),{url:t,arraybuffer:e,rootIdx:r.St,upAxis:r.Xt,transform:r.matrix,supportedFormats:s},((e,n)=>{if(e)return void this.onTileError(e,r);const{magic:s}=n;"b3dm"===s||"pnts"===s||"i3dm"===s||"cmpt"===s?this.ie.push({data:n,tile:r}):this.onTilesetLoad(n,r,t)}))}oe(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let n=0;for(;this.ie.length&&(n<e||!t.isInteracting());){const{data:t,tile:e}=this.ie.shift(),{magic:r}=t;"b3dm"===r?this.painter.createB3DMMesh(t,e.id,e,((n,{mesh:r})=>{this._e(t,e,n,r)})):"pnts"===r?this.painter.createPntsMesh(t,e.id,e,((n,{mesh:r})=>{this._e(t,e,n,r)})):"i3dm"===r?this.painter.createI3DMMesh(t,e.id,e,((n,{mesh:r})=>{this._e(t,e,n,r)})):"cmpt"===r&&this.painter.createCMPTMesh(t,e.id,e,((n,{mesh:r})=>{this._e(t,e,n,r)})),n++}}_e(t,e,n,r){if(n)this.onTileError(n,e);else{const n=this.Oe(r);e.memorySize=n,this.onTileLoad(t,e)}}Oe(t){let e=0;if(Array.isArray(t))for(let n=0;n<t.length;n++)t[n]&&(e+=this.Oe(t[n]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.Ae(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,n){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,n))}onTileError(t,e){if(!this.layer)return;const n=e.content.url;console.warn("failed to load 3d tile: "+n),console.warn(t),delete this.tilesLoading[e.id],this.Ae(e),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}le(t){return this.tileCache.get(t)}Ae(e){const n={loadTime:t.Util.now(),current:!0,node:e};this.tileCache.add(e.id,n)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.options.services[t.node.St].ajaxInMainThread){const t=this.se[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.se[e]}ue(){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};this.canvas.gl&&this.canvas.gl.wrap?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.Ie(this.canvas,e)),this.regl=this.regl||c({gl:this.gl,attributes:e,extensions:["OES_element_index_uint","WEBGL_compressed_texture_s3tc"],optionalExtensions:t.options.optionalExtensions||[]}),this.painter=new In(this.regl,t)}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new zt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let n=this.layer.options||{};n=T({},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.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.he(!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}he(t){this.xe||(this.xe=Date.now());const e=Date.now();if(t||!(e-this.xe<this.layer.options.retireInterval)){this.xe=e;for(const e in this.tilesLoading){const n=this.tilesLoading[e];!t&&n.current||this.abortTileLoading(n)}}}fe(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Ie(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}de(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 we(t,e,0,n)}}function Sn(t,e){return t.Pt-e.Pt}function Mn(t,e,n){return t[0]=e[n],t[1]=e[n+3],t[2]=e[n+6],t}function Nn(t,e,n){return Math.sqrt(function(t,e,n){var r=H(vn,n,t),s=Mn(En,e,0),i=Mn(Rn,e,1),o=Mn(Ln,e,2),a=K(s),c=K(i),h=K(o);j(s,s),j(i,i),j(o,o);var u=Bn;u[0]=z(r,s),u[1]=z(r,i),u[2]=z(r,o);var f,l=0;u[0]<-a?l+=(f=u[0]+a)*f:u[0]>a&&(l+=(f=u[0]-a)*f);u[1]<-c?l+=(f=u[1]+c)*f:u[1]>c&&(l+=(f=u[1]-c)*f);u[2]<-h?l+=(f=u[2]+h)*f:u[2]>h&&(l+=(f=u[2]-h)*f);return l}(t,e,n))}const vn=[],En=[],Rn=[],Ln=[],Bn=[];const Pn=t.projection.EPSG3857,Un=new t.Extent(0,0,0,0),Cn=new t.Extent(0,0,0,0),Dn=[],Vn=[],Fn=[],kn=[],Hn=new t.Point(0,0),Gn=new t.Coordinate(0,0),qn=new t.Coordinate(0,0),jn=[],zn=new t.Coordinate(0,0),$n=r.identity([]);class Xn extends t.Layer{constructor(t,e){super(t,e),this.Se(),this.se={},this.Me=[]}Se(){let t=this.options.services.map((t=>t.url));this.Ne=t.map(((t,e)=>function(t,e){t=A(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.identity([]),St:e,ge:0}}(t,e))),this.fire("rootready",{roots:this.Ne.slice(0)})}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.Ne.length;t++)if(this.Ne[t].boundingVolume){const n=this.boundingVolumeToExtent(this.Ne[t]);e._combine(n)}return e}return this.Ne[e]&&this.Ne[e].boundingVolume?this.boundingVolumeToExtent(this.Ne[e]):null}boundingVolumeToExtent(e){const n=e.boundingVolume.ve?$n:e.matrix,r=this.getMap();if(e.boundingVolume.region){const n=e.boundingVolume.region;return new t.Extent(O(n[0]),O(n[1]),O(n[2]),O(n[3]))}if(e.boundingVolume.sphere){const i=e.boundingVolume.sphere,o=ce([],s.transformMat4([],i,n)),a=i[3],c=r.locate(o,-a,a),h=r.locate(o,a,-a);return new t.Extent(c,h)}if(e.boundingVolume.box){const o=e.boundingVolume.box,a=s.transformMat4([],o,n),c=new t.Coordinate(ce([],a)),h=o.slice(3);i.multiply(h,i.fromMat4([],e.matrix),h);const u=s.length(h.slice(0,3)),f=s.length(h.slice(3,6)),l=s.length(h.slice(6,9)),d=Math.max(u,f,l),m=r.locate(c,-d,d),b=r.locate(c,d,-d);return new t.Extent(m,b)}return null}getRootTiles(){return this.Ne}getTiles(){if(!this.getRenderer().ready)return this.Ee(),{tiles:kn};const t=this.getMap(),e=t.cameraPosition;let n,r;if(t.getGLZoom)r=t.pointToDistance(e[2],0,t.getGLZoom()),zn.set(e[0],e[1]),n=t.pointToCoord(zn,t.getGLZoom());else{const s=t.getGLRes();r=t.pointAtResToDistance(e[2],0,s),zn.set(e[0],e[1]),n=t.pointAtResToCoord(zn,s)}this.Re=this.Re||[],s.set(this.Re,_(n.x),_(n.y),r),this.Le=ne(this.Le||[],this.Re[0],this.Re[1],this.Re[2]),this.Be=2*Math.tan(.5*_(t.getFov())),this.Pe=Pn.project(n).toArray();const i=t.projViewMatrix,o={children:[],level:-1};let a=o;const c=[];for(let t=0;t<this.Ne.length;t++){let e=1/0;const n=[this.Ne[t]],r=this.Ue(t);for(;n.length>0;){const t=n.pop();for(t.id||this.Ce(t);a.level>=t.ge;)a=a.parent;const s=this.De(t,r,i);if(s<1){let n=a;for(;n&&!n.content;)n=n.parent;0===s&&n&&n.content&&this.Ve(c,n);if(!1===this.options.services[t.St].alwaysShow)continue;if(!(0===s&&t.ge<=e))continue;t.content&&(e=t.ge)}t.Pt<1/0&&this.Fe(t);const o=this.Te(t,a);a.children.push(o);const h=t.children,u=h&&h.length,f=o.content;if(!u&&f&&this.Ve(c,o),u){f&&"add"===t.refine&&this.Ve(c,o),a=o;const e=h[0].parent;for(let r=0,s=h.length;r<s;r++){if(!e){h[r].parent=t,h[r].Xt=t.Xt,h[r].baseUrl=t.baseUrl;const e=h[r].content&&(h[r].content.url||h[r].content.uri);e&&(E(e)?h[r].baseUrl=t.baseUrl:-1===e.indexOf("http://")&&-1===e.indexOf("https://")?h[r].content.url=t.baseUrl+e:h[r].baseUrl=e.substring(0,e.lastIndexOf("/")+1))}n.push(h[r])}}}}return{root:o,tiles:c}}Ve(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 Zn(n,e);if(n.box)return 0===Kn(n,e)}return!1}
|
|
19
|
+
/*!
|
|
20
|
+
* @maptalks/gl v0.67.5
|
|
21
|
+
* LICENSE : UNLICENSED
|
|
22
|
+
* (c) 2016-2022 maptalks.com
|
|
23
|
+
*/(this.Re,this.Le,n)||t.push(e)}Te(t,e){return{id:t.id,node:t,children:[],level:t.ge,parent:e,content:t.content&&t.content.url}}Ce(e){e.id=t.Util.GUID(),e.matrix=e.transform||r.identity([]),e.ke=this.He(e),e.parent&&(e.matrix=r.multiply(e.matrix,e.parent.matrix,e.matrix),e.St=e.parent.St,void 0===e.ge&&(e.ge=e.parent.ge+1),e.maxExtent=e.parent.maxExtent),e.refine=e.refine&&e.refine.toLowerCase()||"replace",e.content&&!e.content.url&&e.content.uri&&(e.content.url=e.content.uri),this.Ge(e)}Ge(t){const e=t.boundingVolume;if(!e||e.ve)return;const n=this.options.services[t.St].heightOffset||0,i=this.options.offset,o=w(i)||i[0]||i[1];if(!t.boundingVolume||!n&&r.exactEquals(t.matrix,$n)&&!o)return;const{region:a,box:c,sphere:h}=e;if(a){const t=this.qe([O(a[0]),O(a[1])]);a[0]=_(t.x),a[1]=_(t.y);const e=this.qe([O(a[2]),O(a[3])]);a[2]=_(e.x),a[3]=_(e.y),a[4]+=n,a[5]+=n}else if(c||h){const e=c||h,r=s.transformMat4(Dn,e,t.matrix),i=ce(Vn,r),o=this.qe([i[0],i[1]]);i[0]=o.x,i[1]=o.y,i[2]+=n,ne(e,_(i[0]),_(i[1]),i[2])}e.ve=!0}He(t){return void 0===t.geometricError||!t.boundingVolume}Fe(t){let e=t.parent;for(;e&&e.ke&&!(e.Pt<=t.Pt);)e.Pt=t.Pt,e=t.parent}onTilesetLoad(t,e,n){if(!t)return void console.warn("invalid tileset at : "+n);const s=(t.asset&&t.asset.gltfUpAxis||e&&e.Xt||this.options.services[e.St].upAxis||"Y").toUpperCase();if(t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1),t.root.Xt=s,e){const n=e.boundingVolume;T(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",n&&(e.boundingVolume=n);const s=t.root.transform;s&&(e.parent?e.matrix=r.multiply([],e.parent.matrix,s):e.matrix=s),this.Ge(e),e.je=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.ke=this.He(e);const i=e.content&&(e.content.url||e.content.uri);i&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),i&&!E(i)&&-1===i.indexOf("http://")&&-1===i.indexOf("https://")&&(e.content.url=e.baseUrl+i)}this.Ee(),this.fire("loadtileset",{tileset:t,index:e.St,url:n})}De(t,e,n){if(t.Pt=1/0,0===t.ge||t.ke)return 1;if(!this.ze(t,e,n))return-1;if(0===t.geometricError)return 1;let r=this.options.services[t.St].maximumScreenSpaceError;null==r&&(r=8);let s=this.$e(t);return 0===s&&t.parent&&(s=.5*(t.parent.Xe||0)),s>=r?1:0}Ht(e,n){n||(n=new t.Point(0,0));const r=this.getMap();return r.getGLZoom?r.coordToPoint(e,r.getGLZoom(),n):r.coordToPointAtRes(e,r.getGLRes(),n)}ze(e,n,s){const o=e.id;let a=this.Me[o];const{boundingVolume:c}=e,h=c.sphere,f=c.region,l=c.box;if(!a){let n,s,c;if(f){n=Un.set(O(f[0]),O(f[1]),O(f[2]),O(f[3]));const t=n.getCenter(),e=this.Ze(t);n=n.convertTo((t=>this.Ht(t,Hn)),Cn),c=f[4],s=f[5],a=this.Me[o]=[[n.xmin,n.ymin,c*e[2]],[n.xmax,n.ymax,s*e[2]]],a.center=t}else if(h){const e=ce(Dn,h),n=new t.Coordinate(e),r=this.Ht(n,Hn).toArray(),s=this.Ze(n);r.push(e[2]*s[2]),a=this.Me[o]=[r,h[3]*s[2]],a.center=n}else if(l){const n=ce(Dn,l),s=new t.Coordinate(n),c=this.Ht(s,Hn).toArray(),h=this.Ze(s);c.push(n[2]*h[2]);const u=l.slice(3);r.exactEquals(e.matrix,$n)||i.multiply(u,i.fromMat4(jn,e.matrix),u);for(let t=0;t<u.length;t++)u[t]*=h[t%3],l[3+t]=u[t];a=this.Me[o]=[...c,...u],a.center=s}}if(n){if(f)Un.xmin=a[0][0],Un.ymin=a[0][1],Un.xmax=a[1][0],Un.ymax=a[1][1];else if(h){const t=a[2];Un.xmin=a[0][0]-t,Un.ymin=a[0][1]-t,Un.xmax=a[0][0]+t,Un.ymax=a[0][1]+t}else if(l){const t=a[1],e=a[2];Un.xmin=a[0][0]-t,Un.ymin=a[0][1]-e,Un.xmax=a[0][0]+t,Un.ymax=a[0][1]+e}if(!n.intersects(Un))return!1}return f?d(s,a):h?function(t,e,n){b(t);for(var r=e[0],s=-e[1],i=0;i<6;i++)if((!n||"0"!==n.charAt(i))&&p(u[i],r)<s)return!1;return!0}(s,a):!!l&&function(t,e,n){b(t);for(var r=0;r<6;r++)if(!(n&&"0"===n.charAt(r)||m(u[r],e)))return!1;return!0}(s,a)}Ze(t){const e=this.getMap(),n=e.distanceToPointAtRes(100,100,e.getGLRes(),t);return s.set(Fn,n.x/100*1.01,n.y/100*1.01,n.y/100),Fn}qe(e){Array.isArray(e)&&(e=new t.Coordinate(e));let n=this.options.offset;if(w(n)&&(n=n(Array.isArray(e)?new t.Coordinate(e):e)),n[0]||n[1]){const t=this.getMap(),r=t.getGLRes(),s=t.coordToPointAtRes(e,r);return s._sub(n),t.pointAtResToCoord(s,r)}return e}Ue(e){const n=this.options.services[e].maxExtent;if(!n)return null;const r=this.Ne[e];return r.maxExtent||(r.maxExtent=new t.Extent(n).convertTo((t=>this.Ht(t)))),r.maxExtent}$e(t){const e=this.Be,n=t.geometricError;if(0===n)return 0;const r=this.getMap();let s;if(t.boundingVolume.region){const e=this.Me[t.id].center,n=(r.getGLZoom?r.distanceToPoint(100,0,r.getGLZoom(),e):r.distanceToPointAtRes(100,0,r.getGLRes(),e)).x/100;s=function(t,e,n,r){const s=t.boundingVolume.region;let i=t.Ke;i||(i=t.Ke=[Yn(s[0],s[1]),Yn(s[0],s[3]),Yn(s[2],s[1]),Yn(s[2],s[3]),Yn(s[0],s[1]),Yn(s[0],s[3]),Yn(s[2],s[1]),Yn(s[2],s[3])],t.Ye=[Math.min.apply(Math,i.map((t=>t[0]))),Math.min.apply(Math,i.map((t=>t[1])))],t.We=[Math.max.apply(Math,i.map((t=>t[0]))),Math.max.apply(Math,i.map((t=>t[1])))]);if(n[0]>=s[0]&&n[0]<=s[2]&&n[1]>=s[1]&&n[1]<=s[3])return n[2]<=s[5]?0:n[2]-s[5];const o=(a=t.Ye,c=t.We,h=e,u=Math.max(a[0]-h[0],0,h[0]-c[0]),f=Math.max(a[1]-h[1],0,h[1]-c[1]),Math.sqrt(u*u+f*f)/r);var a,c,h,u,f;let l=0;n[2]>s[5]&&(l=n[2]-s[5]);return Math.sqrt(o*o+l*l)}(t,this.Pe,this.Re,n)}else t.boundingVolume.sphere?s=Zn(t.boundingVolume,this.Le):t.boundingVolume.box&&(s=Kn(t.boundingVolume,this.Le));const i=Math.max(Math.abs(s),1e-7),o=n*r.height/(i*e);return t.Pt=s,t.Xe=o,o}Ee(){const t=this.getRenderer();t&&t.setToRedraw()}Wt(t){return this.Me[t]}}function Zn(t,e){const n=t.sphere,r=s.dist(n,e),i=t.sphere[3];return r<i?0:r-i}function Kn(t,e){const n=t.box;return Nn(s.set(Dn,n[0],n[1],n[2]),i.set(jn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}function Yn(t,e){return Gn.x=O(t),Gn.y=O(e),Pn.project(Gn,qn).toArray()}Xn.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,"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]}),Xn.registerRenderer("gl",xn);const Wn=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")},Jn=Wn(),Qn=Jn.gl_trans__coders=Jn.gl_trans__coders||{};Qn.inject=function(t){const e=t.toString(),n=e.indexOf("{")+1,r=e.substring(0,n),s=Jn.gl_trans__coders=Jn.gl_trans__coders||{};let i=`${r}\n const _____getGlobal = ${Wn.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]};class tr{constructor(t,e,n){this.i=t,this.Je=e||Dt,this.o=n,this.Qe={"image/crn":Qn.crn&&Qn.crn(),"image/ktx2":Qn.ktx2&&Qn.ktx2(),"image/cttf":Qn.ktx2&&Qn.ktx2(),"draco":Qn.draco&&Qn.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.tn(t,e,n,r)):pt.getArrayBuffer(t,{}).then((e=>{const s=e.data;return r||(r=s.byteLength),this.tn(t,s,n,r)}))}tn(t,e,n,r){const s=this.en(e,n,r,t);if(s.error)return Promise.resolve(s);const i=t.substring(0,t.lastIndexOf("/")),o=new this.Je(i,s.glb,{transferable:!0,requestImage:this.i,decoders:this.Qe,supportedFormats:this.o});return o.load().then((e=>{e.url=`${t}-${n}-${r}`;const i=o.transferables;for(let t=0;t<s.transferables.length;t++)i.indexOf(s.transferables[t])<0&&i.push(s.transferables[t]);return{magic:"b3dm",count:s.count,transferables:i,featureTable:s.featureTable,batchTable:s.batchTable,batchTableBin:s.batchTableBin,gltf:e}}))}en(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,b;if(a>0?(d=pe(t,f,a),f+=a,o=d.BATCH_LENGTH):d={"BATCH_LENGTH":o},c>0&&(f+=c),h>0&&(m=ge(t,f,h),f+=h,u>0)){const e=Te(0,f,u);b=t.slice(e.offset,e.offset+e.byteLength),f+=u,l.push(b)}const y=d.BATCH_LENGTH,p={};if(d&&d.BATCH_ID){p.BATCH_ID=_e(d.BATCH_ID,t,undefined.offset,y);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:m,batchTableBin:b,b3dm:p,glb:{buffer:t,byteOffset:f,byteLength:s.byteLength+s.byteOffset-f}}}nn(){return null}}class er{constructor(t,e,n){this.i=t,this.Je=e||Dt,this.o=n,this.Qe={"image/crn":Qn.crn&&Qn.crn(),"image/ktx2":Qn.ktx2&&Qn.ktx2(),"image/cttf":Qn.ktx2&&Qn.ktx2(),"draco":Qn.draco&&Qn.draco()}}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.tn(t,e,n,r)):pt.getArrayBuffer(t,{}).then((e=>{const s=e.data;return r||(r=s.byteLength),this.tn(t,s,n,r)}))}tn(t,e,n,r){return this.rn(t,e,n,r).then((({gltf:s,transferables:i})=>{const o=this.sn(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})}))}rn(t,e,n,r){const s={transferable:!0,requestImage:this.i,decoders:this.Qe,supportedFormats:this.o},i=new DataView(e,n,r),o=32+i.getUint32(12,!0)+i.getUint32(16,!0)+i.getUint32(20,!0)+i.getUint32(24,!0);if(0===i.getUint32(28,!0)){let r=S(new Uint8Array(e,o+n,i.byteLength-o));-1==r.indexOf("://")&&(r=t.substring(0,t.lastIndexOf("/"))+"/"+r);return r.indexOf(".glb")>0?pt.getArrayBuffer(r,{}).then((t=>this.an(r,{buffer:t.data,byteOffset:0},s))):pt.getJSON(r,{}).then((t=>this.an(r,t,s)))}{const r={buffer:e,byteOffset:o+n,byteLength:i.byteLength-o};return this.an(t,r,s)}}an(t,e,n){const r=t.substring(0,t.lastIndexOf("/")),s=new this.Je(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}}))}sn(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}=Se(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.cn(new Uint16Array(t,r+c.offset,3*l),e,n)},o.push(f.POSITION.array.buffer)}if(a.BATCH_ID){f.BATCH_ID=_e(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.hn(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.hn(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}}hn(t){const e=t.length/2,n=new Float32Array(3*e),r=[];for(let s=0;s<e;s++)nr(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}cn(t,e,n){return xe(new Float32Array(t.length),t,e,n)}nn(){return null}}function nr(t,e,n,r){if(t[0]=rr(e,r),t[1]=rr(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]))*sr(e),t[1]=(1-Math.abs(e))*sr(t[1])}return j(t,t)}function rr(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 sr(t){return t<0?-1:1}class ir{constructor(){}load(t,e,n=0,r=0){return e?(r||(r=e.byteLength),this.tn(t,e,n,r)):pt.getArrayBuffer(t,{}).then((e=>{const s=e.data;return r||(r=s.byteLength),this.tn(t,s,n,r)}))}tn(t,e,n,r){return this.un(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}))}un(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}=Se(s,e+28,o),f=a.QUANTIZED_VOLUME_OFFSET,l=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.ln||(this.ln=Qn.draco()),this.ln(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.dn(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:Ie(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?r.BATCH_ID=_e(a.BATCH_ID,t,c.offset,d):r.BATCH_ID=or(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.dn(t,a,c.offset,d,o,f,l);if(a.BATCH_ID||Object.keys(h).length){a.BATCH_ID?y.BATCH_ID=_e(a.BATCH_ID,t,c.offset,d):y.BATCH_ID=or(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})}dn(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,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.cn(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}cn(t,e,n){return xe(new Float32Array(t.length),t,e,n)}nn(){return null}}function or(t){const e=v(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:Ie(e),array:n}}class ar{constructor(t,e){this.i=t,this.Je=e||Dt}load(t,e,n=0,r=0){return e?this.tn(t,e,n,r):pt.getArrayBuffer(t,{}).then((e=>{const s=e.data;return this.tn(t,s,n,r)}))}tn(t,e,n,r){r||(r=e.byteLength);const s=this.mn(e,t,n,r),i=[];for(let n=0;n<s.length;n++){let r;if("b3dm"===s[n].magic)r=new tr(this.i,this.Je);else if("i3dm"===s[n].magic)r=new er(this.i,this.Je);else if("pnts"===s[n].magic)r=new ir;else{if("cmpt"!==s[n].magic){console.warn("Unsupported magic in CMPT tile:",s[n].magic);continue}r=new ar(this.i,this.Je)}i.push(r.load(t,e,s[n].offset,s[n].byteLength).then((t=>t)))}return Promise.all(i).then((t=>({magic:"cmpt",tiles:t})))}mn(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=be(s,c),r=s.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+n,byteLength:r}),c+=r}return o}}if(e.transcoders){const n=t.Map.VERSION;if(n.indexOf("1.0.0-beta")>=0||n.indexOf("1.0.0-alpha")>=0){const n=e.transcoders.inject(h);t.registerWorkerAdapter("@maptalks/3dtiles",n)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(h)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",h);export{tr as B3DMLoader,ar as CMPTLoader,Xn as Geo3DTilesLayer,L as Geo3DTilesUtil,me as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.13.1");
|