@maptalks/3dtiles 0.15.1 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/3dtiles v0.15.
|
|
2
|
+
* @maptalks/3dtiles v0.15.2
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2022 maptalks.org
|
|
5
5
|
*/
|
|
@@ -9,15 +9,15 @@ import*as t from"maptalks";import*as e from"@maptalks/gl";import{reshader as r,m
|
|
|
9
9
|
* MIT License
|
|
10
10
|
* https://github.com/mrdoob/three.js
|
|
11
11
|
*/
|
|
12
|
-
var f=[],u=0;u<6;u++)f[u]=[];var h=[];function _(t,e,r){E(t);for(var n=0;n<6;n++)if(!r||"0"!==r.charAt(n)){var i=f[n];if(h[0]=i[0]>0?e[1][0]:e[0][0],h[1]=i[1]>0?e[1][1]:e[0][1],h[2]=i[2]>0?e[1][2]:e[0][2],m(i,h)<0)return!1}return!0}function d(t,e){var r=e,n=t,i=e,s=n[0],o=n[1],a=n[2],c=Math.abs(s*i[3]+o*i[6]+a*i[9])+Math.abs(s*i[4]+o*i[7]+a*i[10])+Math.abs(s*i[5]+o*i[8]+a*i[11]),l=m(t,r);return!(l<=-c)}function E(t){var e=t,r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],c=e[6],l=e[7],u=e[8],h=e[9],_=e[10],d=e[11],E=e[12],m=e[13],A=e[14],p=e[15];T(f[0],s-r,l-o,d-u,p-E),T(f[1],s+r,l+o,d+u,p+E),T(f[2],s+n,l+a,d+h,p+m),T(f[3],s-n,l-a,d-h,p-m),T(f[4],s-i,l-c,d-_,p-A),T(f[5],s+i,l+c,d+_,p+A)}function T(t,e,r,n,i){var s=1/Math.sqrt(e*e+r*r+n*n);return t[0]=e*s,t[1]=r*s,t[2]=n*s,t[3]=i*s,t}function m(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]}function A(t){return null==t}function p(t){for(let e=1;e<arguments.length;e++){const r=arguments[e];for(const e in r)t[e]=r[e]}return t}function y(t){return null!=t&&("function"==typeof t||null!==t.constructor&&t.constructor===Function)}function g(t){return"object"==typeof t&&!!t}function R(t){return t*Math.PI/180}function b(t){return t/Math.PI*180}function I(t){let e=document.createElement("a");return e.href=t,t=e.href,e=null,t}function N(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const S=[1,1,1,1,2,2,3,0];function w(t){const e=t.length;let r="";for(let n=0;n<e;){let i=t[n++];if(128&i){let r=S[i>>3&7];if(!(64&i)||!r||n+r>e)return null;for(i&=63>>r;r>0;r-=1){const e=t[n++];if(128!=(192&e))return null;i=i<<6|63&e}}r+=String.fromCharCode(i)}return r}function M(t,e,r){return t[3*r]=e[0],t[3*r+1]=e[1],t[3*r+2]=e[2],t}function O(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 C(t){return 0===t.indexOf("data:")}function x(t){const e=t.indexOf("base64,"),r=t.substring(e+7),n=window.atob(r),i=n.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=n.charCodeAt(t);return s.buffer}
|
|
12
|
+
var f=[],u=0;u<6;u++)f[u]=[];var h=[];function _(t,e,r){E(t);for(var n=0;n<6;n++)if(!r||"0"!==r.charAt(n)){var i=f[n];if(h[0]=i[0]>0?e[1][0]:e[0][0],h[1]=i[1]>0?e[1][1]:e[0][1],h[2]=i[2]>0?e[1][2]:e[0][2],m(i,h)<0)return!1}return!0}function d(t,e){var r=e,n=t,i=e,s=n[0],o=n[1],a=n[2],c=Math.abs(s*i[3]+o*i[6]+a*i[9])+Math.abs(s*i[4]+o*i[7]+a*i[10])+Math.abs(s*i[5]+o*i[8]+a*i[11]),l=m(t,r);return!(l<=-c)}function E(t){var e=t,r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],c=e[6],l=e[7],u=e[8],h=e[9],_=e[10],d=e[11],E=e[12],m=e[13],A=e[14],p=e[15];T(f[0],s-r,l-o,d-u,p-E),T(f[1],s+r,l+o,d+u,p+E),T(f[2],s+n,l+a,d+h,p+m),T(f[3],s-n,l-a,d-h,p-m),T(f[4],s-i,l-c,d-_,p-A),T(f[5],s+i,l+c,d+_,p+A)}function T(t,e,r,n,i){var s=1/Math.sqrt(e*e+r*r+n*n);return t[0]=e*s,t[1]=r*s,t[2]=n*s,t[3]=i*s,t}function m(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]}function A(t){return null==t}function p(t){for(let e=1;e<arguments.length;e++){const r=arguments[e];for(const e in r)t[e]=r[e]}return t}function y(t){return null!=t&&("function"==typeof t||null!==t.constructor&&t.constructor===Function)}function g(t){return"object"==typeof t&&!!t}function R(t){return t*Math.PI/180}function b(t){return t/Math.PI*180}function I(t){let e=document.createElement("a");return e.href=t,t=e.href,e=null,t}function N(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const S=[1,1,1,1,2,2,3,0];function w(t){const e=t.length;let r="";for(let n=0;n<e;){let i=t[n++];if(128&i){let r=S[i>>3&7];if(!(64&i)||!r||n+r>e)return null;for(i&=63>>r;r>0;r-=1){const e=t[n++];if(128!=(192&e))return null;i=i<<6|63&e}}r+=String.fromCharCode(i)}return r}function M(t,e,r){return t[3*r]=e[0],t[3*r+1]=e[1],t[3*r+2]=e[2],t}function O(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 C(t){return 0===t.indexOf("data:")}function x(t){const e=t.indexOf("base64,"),r=t.substring(e+7),n=window.atob(r),i=n.length,s=new Uint8Array(i);for(let t=0;t<i;t++)s[t]=n.charCodeAt(t);return s.buffer}function U(t){for(let e=1;e<arguments.length;e++){const r=arguments[e];if(r)for(let e=0,n=r.length;e<n;e++)t.push(r[e])}return t.length}var B=Object.freeze({__proto__:null,isNil:A,extend:p,isFunction:y,isObject:g,toRadian:R,toDegree:b,getAbsoluteURL:I,sign:N,stringFromUTF8Array:w,setColumn3:M,flatArr:O,getBatchIdArrayType:v,isBase64:C,base64URLToArrayBuffer:x,pushIn:U}),P="undefined"!=typeof Float32Array?Float32Array:Array;function L(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 D(t,e,r){var n=e[0],i=e[1],s=e[2],o=e[3],a=e[4],c=e[5],l=e[6],f=e[7],u=e[8],h=e[9],_=e[10],d=e[11],E=e[12],T=e[13],m=e[14],A=e[15],p=r[0],y=r[1],g=r[2],R=r[3];return t[0]=p*n+y*a+g*u+R*E,t[1]=p*i+y*c+g*h+R*T,t[2]=p*s+y*l+g*_+R*m,t[3]=p*o+y*f+g*d+R*A,p=r[4],y=r[5],g=r[6],R=r[7],t[4]=p*n+y*a+g*u+R*E,t[5]=p*i+y*c+g*h+R*T,t[6]=p*s+y*l+g*_+R*m,t[7]=p*o+y*f+g*d+R*A,p=r[8],y=r[9],g=r[10],R=r[11],t[8]=p*n+y*a+g*u+R*E,t[9]=p*i+y*c+g*h+R*T,t[10]=p*s+y*l+g*_+R*m,t[11]=p*o+y*f+g*d+R*A,p=r[12],y=r[13],g=r[14],R=r[15],t[12]=p*n+y*a+g*u+R*E,t[13]=p*i+y*c+g*h+R*T,t[14]=p*s+y*l+g*_+R*m,t[15]=p*o+y*f+g*d+R*A,t}function F(){var t=new P(3);return P!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function G(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function k(t,e,r){var n=new P(3);return n[0]=t,n[1]=e,n[2]=r,n}function H(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function V(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function z(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function X(t,e,r){return t[0]=e[0]-r[0],t[1]=e[1]-r[1],t[2]=e[2]-r[2],t}function Y(t,e,r){return t[0]=e[0]*r[0],t[1]=e[1]*r[1],t[2]=e[2]*r[2],t}function Z(t,e,r){return t[0]=e[0]*r,t[1]=e[1]*r,t[2]=e[2]*r,t}function W(t,e){var r=e[0],n=e[1],i=e[2],s=r*r+n*n+i*i;return s>0&&(s=1/Math.sqrt(s),t[0]=e[0]*s,t[1]=e[1]*s,t[2]=e[2]*s),t}function j(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function K(t,e,r){var n=e[0],i=e[1],s=e[2],o=r[0],a=r[1],c=r[2];return t[0]=i*c-s*a,t[1]=s*o-n*c,t[2]=n*a-i*o,t}var q=X,$=Y,J=G;function Q(t,e,r,n,i){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t}function tt(){var t=new P(4);return P!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function et(t,e,r,n){var i=e[0],s=e[1],o=e[2],a=e[3],c=r[0],l=r[1],f=r[2],u=r[3],h=void 0,_=void 0,d=void 0,E=void 0,T=void 0;return(_=i*c+s*l+o*f+a*u)<0&&(_=-_,c=-c,l=-l,f=-f,u=-u),1-_>1e-6?(h=Math.acos(_),d=Math.sin(h),E=Math.sin((1-n)*h)/d,T=Math.sin(n*h)/d):(E=1-n,T=n),t[0]=E*i+T*c,t[1]=E*s+T*l,t[2]=E*o+T*f,t[3]=E*a+T*u,t}F(),function(){var t,e=(t=new P(4),P!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var rt,nt=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};F(),k(1,0,0),k(0,1,0),tt(),tt(),rt=new P(9),P!=Float32Array&&(rt[1]=0,rt[2]=0,rt[3]=0,rt[5]=0,rt[6]=0,rt[7]=0),rt[0]=1,rt[4]=1,rt[8]=1;
|
|
13
13
|
/*!
|
|
14
14
|
* @maptalks/gltf-loader v0.27.0
|
|
15
15
|
* LICENSE : UNLICENSED
|
|
16
16
|
* (c) 2016-2022 maptalks.org
|
|
17
17
|
*/
|
|
18
|
-
let nt=0;function it(t){return null==t}function st(t){return!it(t)}function ot(t){for(let e=1;e<arguments.length;e++){const r=arguments[e];for(const e in r)t[e]=r[e]}return t}function at(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 ct(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function lt(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),r=e.length,n=new Uint8Array(r);for(let t=0;t<r;t++)n[t]=e.charCodeAt(t);return n.buffer}const ft=[],ut=[],ht=[],_t=[0,0,0],dt=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}([]),Et=[1,1,1];function Tt(t,e,r,n,i,s,o){const a=at(o);if((0===i||i===n*a.BYTES_PER_ELEMENT)&&s%a.BYTES_PER_ELEMENT==0){const i=new a(e,s,r*n);return t.set(i),t}const c=new Uint8Array(n*a.BYTES_PER_ELEMENT);for(let o=0;o<r;o++){let r=null;const l=new Uint8Array(e,i*o+s,n*a.BYTES_PER_ELEMENT);c.set(l),r=new a(c.buffer,0,n);for(let e=0;e<n;e++)t[o*n+e]=r[e]}return t}const mt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function At(t,e,r){const n=new Uint8Array(t,e,r);return mt.decode(n)}const pt={get:function(t,e={}){e||(e={});const r=new AbortController,n=r.signal,i=ot({},e);i.signal=n,i.method||(i.method="GET");const s=fetch(t,i).then((t=>{const r=this.t(t,e.responseType);return r.message?r:r.then((r=>"arraybuffer"===e.responseType?{data:r,cacheControl:t.headers.get("Cache-Control"),expires:t.headers.get("Expires"),contentType:t.headers.get("Content-Type")}:r)).catch((t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t}))})).catch((t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t}));return s.xhr=r,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))},jsonp:function(t){const e="_maptalks_jsonp_"+nt++;t.match(/\?/)?t+="&callback="+e:t+="?callback="+e;let r=document.createElement("script");return r.type="text/javascript",r.src=t,new Promise((t=>{window[e]=function(n){document.getElementsByTagName("head")[0].removeChild(r),r=null,delete window[e],t(n)},document.getElementsByTagName("head")[0].appendChild(r)}))}};class yt{constructor(t,e,r){this.i=t,this.decoders=e,this.o=r,this.images={},this.l={}}requestImageFromBufferURI(t,e,r){if(this.buffers[t.id]){const n=this.buffers[t.id],i=this.u(e,n);return this.getImageByBuffer(i,r)}if(this.l[t.id])return this.l[t.id].then((()=>{const n=this.buffers[t.id],i=this.u(e,n);return this.getImageByBuffer(i,r)}));if(ct(t.uri)){const n=this.buffers[t.id]=lt(t.uri),i=this.u(e,n);return this.getImageByBuffer(i,r)}return this.l[t.id]=pt.getArrayBuffer(t.uri,null).then((n=>{const i=this.buffers[t.id]=n.data,s=this.u(e,i);return this.getImageByBuffer(s,r)}))}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const r=this.decoders;if(r[e.mimeType])return r[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 r=new Blob([t],{type:e.mimeType}),n=URL.createObjectURL(r);return this.h(e.id,n)}}requestExternalImage(t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=0===t.uri.indexOf("data:image/")?t.uri:this.rootPath+"/"+t.uri;return this.l[t.id]?this.l[t.id].then((()=>this.images[t.id])):this.l[t.id]=this.h(t.id,e)}h(t,e){return new Promise(((r,n)=>{this.i(e,((i,s)=>{i?n(i):(URL.revokeObjectURL(e),this.images[t]=s,r(this.images[t]))}))}))}}const gt=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16];class Rt{constructor(t,e,r){this.rootPath=t,this.gltf=e,this._=!1,this.glbBuffer=r,this.buffers={},this.requests={},this.accessors={},this.T()}m(t,e){const r=this.gltf,n=r.accessors[e];if(void 0===n.bufferView)return this.accessors[n.id]=this.A(t,e,null,0),Promise.resolve(this.accessors[n.id]);if(n&&this.accessors[n.id])return Promise.resolve(this.accessors[n.id]);const i=r.bufferViews[n.bufferView];return this.p(i).then((r=>{const{buffer:i,byteOffset:s}=r;return this.accessors[n.id]=this.A(t,e,i,s)}))}p(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(ct(e.uri)){const t=this.buffers[e.id]=lt(e.uri);return Promise.resolve({buffer:t,byteOffset:0})}let t;const r=e.uri.indexOf("blob:")>=0;return t=e.uri.indexOf("://")>0||r?e.uri:this.rootPath+"/"+e.uri,this.requests[e.id]=pt.getArrayBuffer(t,null).then((n=>(r&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=n.data,byteOffset:0})))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}A(t,e,r,n=0){const i=this.gltf,s=i.accessors[e],o=void 0!==s.bufferView?i.bufferViews[s.bufferView]:{},a=(o.byteOffset||0)+n,c=this.g(s.type),l=at(s.componentType),f=o.byteStride||0,u={array:void 0,name:t,accessorName:e,byteLength:s.count*c*l.BYTES_PER_ELEMENT,componentType:s.componentType,count:s.count,type:s.type,itemSize:c};if(s.min&&(u.min=s.min),s.max&&(u.max=s.max),r)if(this._)u.byteStride=f,u.byteOffset=a+(s.byteOffset||0),!f||f===c*l.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(u.array=this.R(r,s.count,c,a+(s.byteOffset||0),l),u.array.buffer.byteLength===u.byteLength&&(u.byteOffset=0)):u.array=new Uint8Array(r,a,o.byteLength);else if(s.interleaved){u.byteStride=0,u.byteOffset=0;const t=new l(s.count*c);u.array=Tt(t,r,s.count,c,f,a+(s.byteOffset||0),s.componentType)}else u.byteStride=0,u.array=this.R(r,s.count,c,a+(s.byteOffset||0),l),u.byteOffset=u.array.byteOffset;else{u.array=new l(s.count);const t=u.min||u.max;t&&(u.array[0]=t[0],u.array[1]=t[1],u.array[2]=t[2])}return u}T(){const t=this.gltf.accessors;if(Array.isArray(t))for(let e=0;e<t.length;e++)for(let r=0;r<t.length;r++)e!==r&&t[e].bufferView===t[r].bufferView&&(t[e].interleaved=t[r].interleaved=!0);else for(const e in t)for(const r in t)e!==r&&t[e].bufferView===t[r].bufferView&&(t[e].interleaved=t[r].interleaved=!0)}R(t,e,r,n,i){return n%i.BYTES_PER_ELEMENT!=0&&(t=t.slice(n,n+e*r*i.BYTES_PER_ELEMENT),n=0),new i(t,n,r*e)}g(t){const e=gt.indexOf(t);return gt[e+1]}requestKHRTechniquesWebgl(t){const{shaders:e}=t,r=e.map((t=>{if(void 0!==t.bufferView){const e=this.gltf.bufferViews[t.bufferView],{byteLength:r}=e;return this.p(e).then((n=>{const{buffer:i,byteOffset:s}=n,o=At(i,s+(e.byteOffset||0),r);return t.content=o,t}))}if(t.uri){if(ct(t.uri)){const e=lt(t.uri),r=At(e,0,e.byteLength);return t.content=r,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(r).then((()=>t))}}class bt extends yt{constructor(t,e,r,n,i,s){super(n,i,s),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=r,this.accessor=new Rt(t,e,r)}iterate(t,e){const r=this.gltf[e];if(!r)return;let n=0;for(const e in r)t(e,r[e],n++)}createNode(t){const e={};if(st(t.name)&&(e.name=t.name),st(t.children)&&(e.children=t.children),st(t.jointName)&&(e.jointName=t.jointName),st(t.matrix)&&(e.matrix=t.matrix),st(t.rotation)&&(e.rotation=t.rotation),st(t.scale)&&(e.scale=t.scale),st(t.translation)&&(e.translation=t.translation),st(t.extras)&&(e.extras=t.extras),st(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 r=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}(ft,e.translation||_t),n=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,c=i+i,l=r*o,f=n*o,u=n*a,h=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-u-d,t[1]=f+m,t[2]=h-T,t[3]=0,t[4]=f-m,t[5]=1-l-d,t[6]=_+E,t[7]=0,t[8]=h+T,t[9]=_-E,t[10]=1-l-u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(ut,e.rotation||dt),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}(ht,e.scale||Et);return L(i,n,i),L(t,r,i)}return P(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}I(t){const e={};for(const r in t){const n=t[r];let i,s;n.instanceTechnique&&n.instanceTechnique.values?(i=n.instanceTechnique,s=i.values.diffuse):(i=n,s=i.values.tex||i.values.diffuseTex||i.values.diffuse);const o={baseColorTexture:{index:s}};n.name&&(o.name=n.name),n.extensions&&(o.extensions=n.extensions),n.extras&&(o.extras=n.extras),e[r]=o}return e}N(t){if(t.bufferView||t.extensions&&(t.extensions.KHR_binary_glTF||t.extensions.binary_glTF)){const e=t.bufferView?t:t.extensions.KHR_binary_glTF||t.extensions.binary_glTF;t.extensions&&(t.mimeType=e.mimeType,t.width=e.width,t.height=e.height);const r=this.gltf.bufferViews[e.bufferView],n=(r.byteOffset||0)+this.glbBuffer.byteOffset,i=r.byteLength,s=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,n,i);return this.getImageByBuffer(s,t)}return this.requestExternalImage(t)}S(t){const e=this.gltf.textures[t];if(!e)return null;const r=this.gltf.images[e.source];return this.N(r).then((t=>{const n=this.gltf.samplers[e.sampler];return{image:{array:t.data,width:t.width,height:t.height,index:e.source,mimeType:r.mimeType,name:r.name,extras:r.extras},sampler:n}}))}getBaseColorTexture(t){const e=this.gltf.materials[t];let r,n;if(e.instanceTechnique&&e.instanceTechnique.values?(r=e.instanceTechnique,n=r.values.diffuse):(r=e,n=r.values.tex||r.values.diffuseTex||r.values.diffuse),void 0===n||void 0===this.gltf.textures)return null;const i=this.gltf.textures[n];if(!i)return null;const s=this.gltf.samplers[i.sampler];return{format:i.format||6408,internalFormat:i.internalFormat||6408,type:i.type||5121,sampler:s,source:this.gltf.images[i.source]}}getMaterial(){return null}getAnimations(){return null}}class It extends yt{constructor(t,e,r,n,i,s){super(n,i,s),this.rootPath=t,this.gltf=e,this.glbBuffer=r,this.buffers={},this.requests={},this.accessor=new Rt(t,e,r)}iterate(t,e){const r=this.gltf[e];if(r)for(let e=0;e<r.length;e++)t(e,r[e],e)}createNode(t){const e={};return ot(e,t),!st(t.weights)&&this.gltf.meshes&&st(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}S(t){const e=this.gltf.textures[t];if(!e)return null;const r=this.gltf.images[e.source];return this.N(r).then((t=>{if(!t)return null;const n={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};ot(n,e);const i=st(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return i&&(n.sampler=i),t.format&&(n.format=t.format),n}))}N(t){if(!st(t.bufferView))return this.requestExternalImage(t);{const e=this.gltf.bufferViews[t.bufferView],r=this.gltf.buffers[e.buffer];if(r.uri)return this.requestImageFromBufferURI(r,e,t);if(this.glbBuffer)return this.M(e,t)}return null}M(t,e){const r=this.u(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(r,e)}u(t,e,r){r=r||0;const n=t.byteOffset+r,i=t.byteLength;return new Uint8Array(e,n,i)}O(t,e){const r=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)r[e]=String.fromCharCode(t[e]);return r.join(""),"data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(r)))}getAnimations(t){const e=[];return t.forEach((t=>{e.push(this.getSamplers(t.samplers))})),Promise.all(e).then((e=>{for(let r=0;r<e.length;r++)t[r].samplers=e[r];return t}))}getSamplers(t){const e=[];for(let r=0;r<t.length;r++)(st(t[r].input)||st(t[r].output))&&(e.push(this.accessor.m("input",t[r].input)),e.push(this.accessor.m("output",t[r].output)));return Promise.all(e).then((e=>{for(let r=0;r<e.length/2;r++)t[r].input=e[2*r],t[r].output=e[2*r+1],t[r].interpolation||(t[r].interpolation="LINEAR");return t}))}}const Nt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class St{static read(t,e=0,r=0){r||(r=t.byteLength);const n=new DataView(t,e,r),i=n.getUint32(4,!0);if(1===i)return St.readV1(n,e);if(2===i)return St.readV2(t,e);throw new Error("Unsupported glb version : "+i)}static readV1(t,e){const r=t.getUint32(8,!0),n=t.getUint32(12,!0);if(r!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const i=wt(t.buffer,20+e,n);return{json:JSON.parse(i),glbBuffer:{byteOffset:20+e+n,buffer:t.buffer,byteLength:r}}}static readV2(t,e){let r,n,i;const s=new DataView(t,e+12);let o=0;for(;o<s.byteLength;){const a=s.getUint32(o,!0);o+=4;const c=s.getUint32(o,!0);if(o+=4,1313821514===c)r=wt(t,e+12+o,a);else if(5130562===c){i=e+12+o,n=a;break}o+=a}return{json:JSON.parse(r),glbBuffer:{byteOffset:i,buffer:t,byteLength:n}}}}function wt(t,e,r){if(Nt){const n=new Uint8Array(t,e,r);return Nt.decode(n)}return function(t){const e=t.length;let r="";for(let n=0;n<e;){let i=t[n++];if(128&i){let r=Mt[i>>3&7];if(!(64&i)||!r||n+r>e)return null;for(i&=63>>r;r>0;r-=1){const e=t[n++];if(128!=(192&e))return null;i=i<<6|63&e}}r+=String.fromCharCode(i)}return r}(new Uint8Array(t,e,r))}const Mt=[1,1,1,1,2,2,3,0],Ot=[0,0,0],vt=[0,0,0,1],Ct=[1,1,1],xt={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},Ut={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Bt={v(t,e,r,n,i,s,o,a){const c=st(t)?e.animations:[e.animations[0]],l={};for(let e=0;e<c.length;e++){const f=c[e],u=f.name||e;if(st(t)&&u!==t)continue;const h=f.channelsMap[r];if(h)for(let t=0;t<h.length;t++){const e=h[t];"translation"===e.target.path?(this.C(i,f.samplers[e.sampler],n,1),l.translation=k(Ot,i)):"rotation"===e.target.path?(this.U(s,f.samplers[e.sampler],n,1),l.rotation=rt(vt,s)):"scale"===e.target.path?(this.C(o,f.samplers[e.sampler],n,1),l.scale=k(Ct,o)):"weights"===e.target.path&&a&&(this.C(a,f.samplers[e.sampler],n,a.length),l.weights=a)}}return l},C(t,e,r,n){switch(e.interpolation){case"LINEAR":{const i=this.B(Ut,e,r,1*n);i&&(t=function(t,e,r,n){for(let i=0;i<t.length;i++)t[i]=e[i]+n*(r[i]-e[i]);return t}(t,i.PREVIOUS,i.NEXT,i.INTERPOLATION));break}case"STEP":{const i=this.B(Ut,e,r,1*n);i&&(t=function(t,e){for(let r=0;r<t.length;r++)t[r]=e[r];return t}(t,...i.PREVIOUS));break}case"CUBICSPLINE":{const i=this.B(Ut,e,r,3*n);i&&(t=this.P(t,i,e.input.array,3*n));break}}return t},U(t,e,r){switch(e.interpolation){case"LINEAR":{const n=this.B(Ut,e,r,1);n&&tt(t,n.PREVIOUS,n.NEXT,n.INTERPOLATION);break}case"STEP":{const n=this.B(Ut,e,r,1);n&&(t=J(t,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this.B(Ut,e,r,3);if(n){for(let t=0;t<n.PREVIOUS.length;t++)n.PREVIOUS[t]=Math.acos(n.PREVIOUS[t]),n.NEXT[t]=Math.acos(n.NEXT[t]);t=this.P(t,n,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},L(t,e){const r=t.length;let n,i,s,o=0,a=r-1,c=Math.floor((o+a)/2);for(;o<=r-1&&a>=0;){if(o===a)return null;if(t[c]<=e&&e<=t[c+1]){const r=t[c];return n=c,i=c+1,s=(e-r)/(t[c+1]-r),{preIndx:n,nextIndex:i,interpolation:s}}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},B(t,e,r,n){const i=e.input.array,s=e.output.array,o=e.output.itemSize;(r<i[0]||r>i[i.length-1])&&(r=Math.max(i[0],Math.min(i[i.length-1],r))),r===i[i.length-1]&&(r=i[0]);const a=this.L(i,r);if(!a||!a.nextIndex)return null;const{preIndx:c,nextIndex:l,interpolation:f}=a;t.PREINDEX=c,t.NEXTINDEX=l,t.INTERPOLATION=f;const u=o*n;return t.PREVIOUS=s.subarray(t.PREINDEX*u,(t.PREINDEX+1)*u),t.NEXT=s.subarray(t.NEXTINDEX*u,(t.NEXTINDEX+1)*u),t},P(t,e,r,n){const i=e.INTERPOLATION,s=r[e.PREINDEX],o=r[e.NEXTINDEX];for(let r=0;r<3;r++){const a=e.PREVIOUS[n+r],c=(o-s)*e.PREVIOUS[2*n+r],l=e.NEXT[3+r],f=(o-s)*e.NEXT[r],u=(2*Math.pow(i,3)-3*Math.pow(i,2)+1)*a+(Math.pow(i,3)-2*Math.pow(i,2)+i)*c+(2*-Math.pow(i,3)+3*Math.pow(i,2))*l+(Math.pow(i,3)-Math.pow(i,2))*f;t[r]=u}return t},getAnimationClip(t,e,r,n){const i=t.nodes[e]&&t.nodes[e].weights;return H(Ot,...xt.TRANSLATION),J(vt,...xt.ROTATION),H(Ct,...xt.SCALE),this.v(n,t,e,r,Ot,vt,Ct,i)},getTimeSpan(t){if(!t.animations)return null;if(t.timeSpan)return t.timeSpan;const e=t.animations;return t.timeSpan={},e.forEach(((e,r)=>{let n=-1/0,i=1/0;const s=e.channels;for(let t=0;t<s.length;t++){const r=s[t],o=e.samplers[r.sampler].input.array;o[o.length-1]>n&&(n=o[o.length-1]),o[0]<i&&(i=o[0])}const o=e.name||r;t.timeSpan[o]={max:n,min:i}})),t.timeSpan},getTimeSpanByName(t,e){const r=this.getTimeSpan(t);return r?st(e)?r[e]:r[Object.keys(r)[0]]:null}};let Pt=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(Mr){}t&&"undefined"!=typeof createImageBitmap&&(Pt=!0)}const Lt="undefined"==typeof document?null:document.createElement("canvas");class Dt{constructor(t,e,r){if(this.options=r||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:r,glbBuffer:n}=St.read(e.buffer,e.byteOffset,e.byteLength);this.D(t,r,n)}else this.D(t,e);this.F=new Rt(this.rootPath,this.gltf,this.glbBuffer),this.G()}G(){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.F.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),r=this.V(),n=this.X(),i=this.k();return Promise.all([e,r,n,i]).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 r=e[t];r.channelsMap={};for(let t=0;t<r.channels.length;t++){const e=r.channels[t];r.channelsMap[e.target.node]||(r.channelsMap[e.target.node]=[]),r.channelsMap[e.target.node].push(e)}}}getExternalResources(){const t=[];if(this.gltf){const{buffers:e,images:r}=this.gltf;for(let r=0;r<e.length;r++)e[r].uri&&e[r].uri.indexOf("data:application/octet-stream;base64")<0&&t.push({type:"buffer",uri:e[r].uri});for(let e=0;e<r.length;e++)r[e].uri&&r[e].uri.indexOf("data:image/")<0&&t.push({type:"image",uri:r[e].uri})}return t}static getAnimationClip(t,e,r,n){return Bt.getAnimationClip(t,e,r,n)}static getAnimationTimeSpan(t,e){return Bt.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return at(t)}static readInterleavedArray(t,e,r,n,i,s,o){return Tt(t,e,r,n,i,s,o)}D(t,e,r){this.gltf=e,this.glbBuffer=r,this.version=e.asset?+e.asset.version:1,this.rootPath=t,this.buffers={},this.requests={},this.options.requestImage=Pt?Ht.bind(this):this.options.requestImage||Ft,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new It(t,e,r,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate(((t,e,r)=>{e.id="buffer_"+r}),"buffers"),this.adapter.iterate(((t,e,r)=>{e.id="image_"+r}),"images"),this.adapter.iterate(((t,e,r)=>{e.id="accessor_"+r}),"accessors")):(this.adapter=new bt(t,e,r,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate(((t,e,r)=>{e.id="accessor_"+r}),"accessors"),this.adapter.iterate(((t,e,r)=>{e.id="image_"+r}),"images"))}Y(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(r=t.children[0])&&isFinite(r)||function(t){return!it(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}(t.children[0])))return t;const n=t.children.map((t=>{const r=e[t];return r.nodeIndex=t,this.Y(r,e)}));t.children=n}var r;return t}H(t){return this.Z(t).then((t=>{const e=this.scenes=[];let r;for(const e in t)t[e]=this.Y(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate(((n,i,s)=>{const o={};i.name&&(o.name=i.name),i.nodes&&(o.nodes=i.nodes.map((e=>t[e]))),this.gltf.scene===n&&(r=s),e.push(o)}),"scenes");const n={asset:this.gltf.asset,scene:r,scenes:e,nodes:t,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins};if(this.gltf.extensions&&(n.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.I(this.gltf.materials);n.materials=t}return n}))}Z(t){return this.W(t).then((()=>{const t=this.nodes={};return this.adapter.iterate(((e,r)=>{const n=this.adapter.createNode(r,this.meshes,this.skins);t[e]=n}),"nodes"),t}))}j(){this.skins=[];const t=[];return this.adapter.iterate(((e,r,n)=>{t.push(this.K(r).then((t=>{t.index=n,this.skins.push(t)})))}),"skins"),t}K(t){const e=t.inverseBindMatrices;return this.adapter.accessor.m("inverseBindMatrices",e).then((e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t)))}V(){const t=this.gltf.animations;return st(t)?this.adapter.getAnimations(t):null}W(t){this.meshes={};let e=[];return this.adapter.iterate(((r,n,i)=>{e.push(this.q(n,t).then((t=>{t.index=i,this.meshes[r]=t})))}),"meshes"),e=e.concat(this.j()),Promise.all(e)}q(t,e){const r=t.primitives.map((t=>this.$(t,e))).filter((t=>!!t));return Promise.all(r).then((e=>{const r={};return ot(r,t),r.primitives=e,r}))}X(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const r in t)e.push(this.adapter.S(r));return Promise.all(e).then((e=>{if(this.transferables)for(let t=0;t<e.length;t++){const r=e[t].image.array;if(e[t]&&r){let t;t=r instanceof ImageBitmap?r:r.buffer,t&&this.transferables.indexOf(t)<0&&this.transferables.push(t)}}if(!Array.isArray(t)){const r={},n=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(r[n[t]]=e[t]);return r}return e}))}$(t,e){let r;const n=[],i=t.extensions;if(st(t.targets))for(let e=0;e<t.targets.length;e++){const r=t.targets[e];for(const t in r){const i=this.adapter.accessor.m(`morphTargets_${t}_${e}`,r[t]);i&&n.push(i)}}if(i&&i.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:s,attributes:o}=i.KHR_draco_mesh_compression,a=this.gltf.bufferViews[s],c=this.F.p(a).then((r=>{const{buffer:n,byteOffset:i}=r;let{byteOffset:s,byteLength:c}=a;s||(s=0);const l=new DataView(n,i+s,c),f={attributes:o,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(l,f).then((t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e}))}));n.push(c),r=Promise.all(n)}else{const e=t.attributes;for(const t in e){const r=this.adapter.accessor.m(t,e[t]);r&&n.push(r)}if(st(t.indices)){const e=this.adapter.accessor.m("indices",t.indices);e&&n.push(e)}r=Promise.all(n)}return r.then((e=>{if(i&&i.KHR_draco_mesh_compression){const r=t.targets?t.targets.length:0;e[r]=e[r].concat(e.slice(0,r)),e=e[r]}let r,n;const s={attributes:e.reduce(((t,e)=>{if("indices"===e.name)r=e;else if(e.name.indexOf("morphTargets_")>-1)n=n||{},n[e.name.slice(13)]=e;else{if(!("POSITION"!==e.name||e.min&&e.max)){const t=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0],{itemSize:n,array:i}=e,s=i.length/n;for(let e=0;e<s;e++)for(let s=0;s<n;s++){const o=e*n+s;i[o]<t[s]&&(t[s]=i[o]),i[o]>r[s]&&(r[s]=i[o])}if(e.quantization){const n=e.quantization,i=n.range/(1<<n.quantizationBits),s=n.minValues;Y(t,t,i),V(t,t,s),Y(r,r,i),V(r,r,s)}e.min=t,e.max=r}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 r&&(s.indices=r),n&&(s.morphTargets=n),s.mode=st(t.mode)?t.mode:4,st(t.extras)&&(s.extras=t.extras),s}))}}function Ft(t,e){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!Lt)return void e(new Error("There is no canvas to draw image!"));Lt.width=r.width,Lt.height=r.height;const t=Lt.getContext("2d");t.drawImage(r,0,0,r.width,r.height);const n=t.getImageData(0,0,r.width,r.height),i={width:r.width,height:r.height,data:new Uint8Array(n.data)};e(null,i)},r.onerror=function(t){e(t)},r.src=t}let Gt,kt;function Ht(t,e){Gt||(Gt=new OffscreenCanvas(2,2),kt=Gt.getContext("2d")),fetch(t).then((t=>t.arrayBuffer())).then((t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)})).then((t=>{let{width:r,height:n}=t;Vt(r)||(r=zt(r)),Vt(n)||(n=zt(n));const i=this.options.maxTextureSize;i&&(r=Math.min(i,r),n=Math.min(i,n)),Gt.width=r,Gt.height=n,kt.drawImage(t,0,0,r,n),t.close();const s=kt.getImageData(0,0,r,n);e(null,{width:r,height:n,data:new Uint8Array(s.data)})})).catch((t=>{console.warn(t),e(t)}))}function Vt(t){return 0==(t&t-1)&&0!==t}function zt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}const Xt="undefined"==typeof document?null:document.createElement("canvas");class Yt extends t.worker.Actor{constructor(t,e){super(t),this.mapId=e}initialize(t){t(null)}loadTile(t,e,r){let n=null;e&&e.arraybuffer&&(n=[e.arraybuffer]);const i={mapId:this.mapId,layerId:t,command:"loadTile",params:e};this.send(i,n,r)}abortTileLoading(t,e,r){const n={mapId:this.mapId,layerId:t,command:"abortTileLoading",params:{url:e}};this.broadcast(n,null,r)}addLayer(t,e,r){const n={actorId:this.actorId,mapId:this.mapId,layerId:t,command:"addLayer",params:{options:e}};this.broadcast(n,null,r)}removeLayer(t,e){const r={mapId:this.mapId,layerId:t,command:"removeLayer"};this.broadcast(r,null,e)}requestImage({url:t},e){const r=new Image;r.onload=()=>{if(!this.isActive())return;if(!Xt)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if(Zt(t.width)&&Zt(t.height))return t;let e=t.width,r=t.height;Zt(e)||(e=Wt(e));Zt(r)||(r=Wt(r));const n=document.createElement("canvas");n.width=e,n.height=r,n.getContext("2d").drawImage(t,0,0,e,r);const i=t.src,s=i.lastIndexOf("/")+1,o=i.substring(s);return console.warn(`Texture(${o})'s size is not power of two, resize from (${t.width}, ${t.height}) to (${e}, ${r})`),n}(r);Xt.width=t.width,Xt.height=t.height;const n=Xt.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const i=n.getImageData(0,0,t.width,t.height),s={width:t.width,height:t.height,data:new Uint8Array(i.data)};e(null,s,[s.data.buffer])},r.onerror=function(t){e(t)},r.src=t}}function Zt(t){return 0==(t&t-1)&&0!==t}function Wt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}class jt{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 r=this.data.get(t);r&&r.node&&r.node.memorySize&&(this.currentSize-=r.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 r=this.data.keys();for(let n of r)t[e++]=n;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 r of e){const e=r&&r.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t){const e=this.data.values();for(const r of e)r.current=t}}function Kt(t,e){if(t.scenes&&t.scenes.length)for(let r=0,n=t.scenes.length;r<n;r++){const n=t.scenes[r].nodes;for(let r=0,i=n.length;r<i;r++){const i=[];qt(n[r],i,t,e)}}}function qt(t,e,r,n){if(t.matrix&&e.push(t.matrix),t.children&&t.children.length)for(let i=0,s=t.children.length;i<s;i++)qt(t.children[i],e,r,n);if(void 0!==t.mesh){const i=t.mesh,s=r.meshes[i];if(s){const t=e.slice(0),o=s.primitives;for(let e=0,s=o.length;e<s;e++){const s=o[e];s&&(s.matrices=t,n(s,i,e,r))}}}}function $t(t,e,r){let{componentType:n,byteOffset:i,byteStride:s,itemSize:o}=e;const a=e.array.buffer,c=n?Dt.getTypedArrayCtor(n):e.array.constructor;if(i=void 0===i?e.array.byteOffset:i,s=s||0,!s||s===o*c.BYTES_PER_ELEMENT&&i%c.BYTES_PER_ELEMENT==0){const e=new c(a,i+r*o*c.BYTES_PER_ELEMENT,o);return t.set(e),t}s||(s=o*c.BYTES_PER_ELEMENT);const l=new Uint8Array(a,s*r+i,o*c.BYTES_PER_ELEMENT);return new Uint8Array(t.buffer).set(l),t}function Jt(t,e,r,n){t[4*e]=r[n],t[4*e+1]=r[n+4],t[4*e+2]=r[n+8],t[4*e+3]=r[n+12]}const Qt=new Array(3),te=new Array(3),ee=[40680631590769,40680631590769,40408299984661.445];function re(t,e,r,n){const i=ee,s=Math.cos(r);Qt[0]=s*Math.cos(e),Qt[1]=s*Math.sin(e),Qt[2]=Math.sin(r),he(Qt,Qt),X(te,i,Qt);const o=Math.sqrt(W(Qt,te));var a,c,l;return c=te,l=o,(a=te)[0]=c[0]/l,a[1]=c[1]/l,a[2]=c[2]/l,Y(Qt,Qt,n),V(t,te,Qt)}const ne=[1/6378137,1/6378137,1/6356752.314245179],ie=[1/40680631590769,1/40680631590769,1/40408299984661.445],se=new Array(3),oe=new Array(3),ae=new Array(3);function ce(t,e){const r=ie,n=function(t,e,r,n,i){const s=e[0],o=e[1],a=e[2],c=r[0],l=r[1],f=r[2],u=s*s*c*c,h=o*o*l*l,_=a*a*f*f,d=u+h+_,E=Math.sqrt(1/d),T=Y(le,e,E);if(d<i)return isFinite(E)?T:void 0;const m=n[0],A=n[1],p=n[2],y=fe;y[0]=T[0]*m*2,y[1]=T[1]*A*2,y[2]=T[2]*p*2;let g,R,b,I,N,S,w,M,O,v,C,x=(1-E)*ue(e)/(.5*ue(y)),U=0;do{x-=U,b=1/(1+x*m),I=1/(1+x*A),N=1/(1+x*p),S=b*b,w=I*I,M=N*N,O=S*b,v=w*I,C=M*N,g=u*S+h*w+_*M-1,R=u*O*m+h*v*A+_*C*p;U=g/(-2*R)}while(Math.abs(g)>1e-12);return t[0]=s*b,t[1]=o*I,t[2]=a*N,t}(se,e,ne,r,.1);let i=q(oe,n,r);i=he(i,i);const s=K(ae,e,n),o=Math.atan2(i[1],i[0]),a=Math.asin(i[2]),c=N(W(s,e))*ue(s);return t[0]=b(o),t[1]=b(a),t[2]=c,t}const le=new Array(3),fe=new Array(3);function ue(t){return F(t)}function he(t,e){const r=e[0],n=e[1],i=e[2];let s=r*r+n*n+i*i;return s>0&&(s=Math.sqrt(s),t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s),t}function _e(t,e){return X(e,t,ie),Z(e,e)}function de(t,e){var r=t[0],n=t[1],i=Math.cos(n),s=i*Math.cos(r),o=i*Math.sin(r),a=Math.sin(n);return e.x=s,e.y=o,e.z=a,Z(e,e)}var Ee=Object.freeze({__proto__:null,radianToCartesian3:re,cartesian3ToDegree:ce,normalizeCartesian:he,geodeticSurfaceNormal:_e,geodeticSurfaceNormalCartographic:de});function Te(t,e,r,n){r=r||0,n=n||r;var i=Math.abs(t-e);return i<=n||i<=r*Math.max(Math.abs(t),Math.abs(e))}function me(t,e){let r="";for(let n=0;n<4;n++){const i=t.getUint8(e+n);r+=String.fromCharCode(i)}return r}const Ae="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function pe(t,e,r){const n=new Uint8Array(t,e,r);return Ae?JSON.parse(Ae.decode(n)):JSON.parse(w(n))}function ye(t,e,r){const n=new Uint8Array(t,e,r);return Ae?JSON.parse(Ae.decode(n)):JSON.parse(w(n))}function ge(t,e,r){return{offset:e,byteLength:r}}function Re(t,e,r,n){const{byteOffset:i,componentType:s,type:o}=t,{ctor:a,type:c}=function(t){return Ne[t]}(s),l=function(t){if(!t)return 1;return Ie[t]}(o);return{byteStride:0,byteOffset:i+r,itemSize:l,count:n*l,componentType:c,array:new a(e,r+i,n*l)}}function be(t,e,r,n){t.componentType||(t.componentType="UNSIGNED_SHORT");const i=Re(t,e,r,n);return i.array.buffer.byteLength!==e.byteLength&&(i.array=i.array.slice()),i}const Ie={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const Ne={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function Se(t){for(let e in Ne)if(t===Ne[e].ctor)return Ne[e].type;throw new Error("unrecognized ctor:"+t)}function we(t,e,r,n){const i=t,s=e.length/3;for(let t=0;t<s;t++)i[3*t]=e[3*t]/65535*n[0]+r[0],i[3*t+1]=e[3*t+1]/65535*n[1]+r[1],i[3*t+2]=e[3*t+2]/65535*n[2]+r[2];return i}function Me(t,e,r){let n=t.getUint32(12,!0),i=t.getUint32(16,!0),s=t.getUint32(20,!0),o=t.getUint32(24,!0);const a=t.buffer;let c,l,f={},u={};n>0&&(f=pe(a,e,n),e+=n),i>0&&(c=function(t,e,r){return{offset:e,byteLength:r}}(0,e,i),e+=i),s>0&&(u=ye(a,e,s),e+=s);const h=ge(0,e,o);return l=a.slice(h.offset,h.offset+h.byteLength),r.push(l),{featureTable:f,featureTableBin:c,batchTable:u,batchTableBin:l}}var Oe={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},ve={},Ce={east:[],north:[],up:[],west:[],south:[],down:[]},xe=[],Ue=[],Be=[];const Pe=[0,0,0];function Le(t,e,r){return r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=t[3],r[4]=t[4],r[5]=t[5],r[6]=t[6],r[7]=t[7],r[8]=t[8],r[9]=t[9],r[10]=t[10],r[11]=t[11],r[12]=e[0],r[13]=e[1],r[14]=e[2],r[15]=t[15],r}const De=(He={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"}}[Fe="east"][Ge="north"],ve[Ve=Fe+Ge]?ke=ve[Ve]:(ke=function(t,e,r){if(function(t,e){var r=t[0],n=t[1],i=t[2],s=e[0],o=e[1],a=e[2];return Math.abs(r-s)<=1e-6*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(n-o)<=1e-6*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=1e-6*Math.max(1,Math.abs(i),Math.abs(a))}(t,Pe))k(xe,Oe[Fe]),k(Ue,Oe[Ge]),k(Be,Oe[He]);else if(Te(t[0],0,1e-14)&&Te(t[1],0,1e-14)){var n=N(t[2]);k(xe,Oe[Fe]),"east"!==Fe&&"west"!==Fe&&Y(xe,xe,n),k(Ue,Oe[Ge]),"east"!==Ge&&"west"!==Ge&&Y(Ue,Ue,n),k(Be,Oe[He]),"east"!==He&&"west"!==He&&Y(Be,Be,n)}else{_e(t,Ce.up);var i=Ce.up,s=Ce.east;s[0]=-t[1],s[1]=t[0],s[2]=0,Z(Ce.east,s),j(Ce.north,i,s),Y(Ce.down,Ce.up,-1),Y(Ce.west,Ce.east,-1),Y(Ce.south,Ce.north,-1),xe=Ce[Fe],Ue=Ce[Ge],Be=Ce[He]}return r[0]=xe[0],r[1]=xe[1],r[2]=xe[2],r[3]=0,r[4]=Ue[0],r[5]=Ue[1],r[6]=Ue[2],r[7]=0,r[8]=Be[0],r[9]=Be[1],r[10]=Be[2],r[11]=0,r[12]=t[0],r[13]=t[1],r[14]=t[2],r[15]=1,r},ve[Ve]=ke),ke);var Fe,Ge,ke,He,Ve;const ze=[],Xe=[],Ye=[],Ze=[],We=[],je=[],Ke=[],qe={x:0,y:0},$e={x:0,y:0},Je=Math.PI/180;const Qe={"programs":[{"attributes":["aPosition","instanceId","batchId","aTexCoord0","aTexCoord1","aNormal","aColor","uv2","uv3","uv4","secondary_colour","uv6"],"fragmentShader":1,"vertexShader":0}],"shaders":[{"type":35633,"content":"#include <gl2_vert>\n\nuniform mat4 czm_modelViewProjection;\n\nuniform mat4 czm_modelView;\n\nuniform mat3 czm_normal;\n\n\n\nattribute vec4 aPosition;\n\n\n\n#ifdef VertexColor\n\n attribute vec4 aColor;\n\n#endif\n\n#ifdef VertexNormal\n\n attribute vec3 aNormal;\n\n#endif\n\n#ifdef Instance\n\n attribute float instanceId;\n\n#else\n\n attribute float batchId;\n\n#endif\n\n\n\n#ifdef TexCoord\n\n attribute vec4 aTexCoord0;\n\n varying vec4 vTexCoord;\n\n uniform mat4 uTexMatrix;\n\n#ifdef COMPUTE_TEXCOORD\n\n uniform float uTexture0Width;\n\n varying vec4 vTexMatrix;\n\n varying vec4 vTexCoordTransform;\n\n varying vec2 vIsRGBA;\n\n#endif\n\n#endif\n\n\n\n#ifdef TexCoord2\n\n attribute vec4 aTexCoord1;\n\n uniform float uTexture1Width;\n\n varying vec4 vTexMatrix2;\n\n#endif\n\n#ifdef InstanceBim\n\n attribute vec4 uv2;\n\n attribute vec4 uv3;\n\n attribute vec4 uv4;\n\n attribute vec4 secondary_colour;\n\n attribute vec4 uv6;\n\n#endif\n\n\n\n uniform vec4 uFillForeColor;\n\n uniform vec4 uSelectedColor;\n\n varying vec4 vSecondColor;\n\n varying vec4 vPositionMC;\n\n varying vec3 vPositionEC;\n\n#ifdef VertexNormal\n\n varying vec3 vNormalEC;\n\n#endif\n\n varying vec4 vColor;\n\n\n\n const float SHIFT_LEFT8 = 256.0;\n\n const float SHIFT_RIGHT8 = 1.0 / 256.0;\n\n const float SHIFT_RIGHT4 = 1.0 / 16.0;\n\n const float SHIFT_LEFT4 = 16.0;\n\n void getTextureMatrixFromZValue(in float nZ, inout float XTran, inout float YTran, inout float scale, inout float isRGBA)\n\n {\n\n if(nZ <= 0.0)\n\n {\n\n return;\n\n }\n\n float nDel8 = floor(nZ * SHIFT_RIGHT8);\n\n float nDel16 = floor(nDel8 * SHIFT_RIGHT8);\n\n float nDel20 = floor(nDel16 * SHIFT_RIGHT4);\n\n isRGBA = floor(nDel20);\n\n YTran = nZ - nDel8 * SHIFT_LEFT8;\n\n XTran = nDel8 - nDel16 * SHIFT_LEFT8;\n\n float nLevel = nDel16 - nDel20 * SHIFT_LEFT4;\n\n scale = 1.0 / pow(2.0, nLevel);\n\n }\n\n\n\n void operation(vec4 operationType, vec4 color, vec4 selectedColor, inout vec4 vertexColor)\n\n {\n\n float right_2 = operationType.x * 0.5;\n\n float right_4 = right_2 * 0.5;\n\n float right_8 = right_4 * 0.5;\n\n float right_16 = right_8 * 0.5;\n\n float isSetColor = fract(right_2);\n\n if(isSetColor > 0.1)\n\n {\n\n vertexColor *= color;\n\n }\n\n float isPicked = fract(floor(right_2)* 0.5);\n\n if(isPicked > 0.1)\n\n {\n\n vertexColor *= selectedColor;\n\n }\n\n float isHide = fract(floor(right_4)* 0.5);\n\n if(isHide > 0.1)\n\n {\n\n vertexColor.a = 0.0;\n\n }\n\n }\n\n\n\n void main()\n\n {\n\n #ifdef TexCoord\n\n vTexCoord.xy = aTexCoord0.xy;\n\n #ifdef COMPUTE_TEXCOORD\n\n vTexMatrix = vec4(0.0,0.0,1.0,0.0);\n\n vIsRGBA.x = 0.0;\n\n vTexCoordTransform.x = aTexCoord0.z;\n\n if(vTexCoordTransform.x < -90000.0)\n\n {\n\n vTexMatrix.z = -1.0;\n\n }\n\n getTextureMatrixFromZValue(floor(vTexCoordTransform.x), vTexMatrix.x, vTexMatrix.y, vTexMatrix.z, vIsRGBA.x);\n\n vTexMatrix.w = log2(uTexture0Width * vTexMatrix.z);\n\n #endif\n\n #endif\n\n\n\n #ifdef TexCoord2\n\n vTexCoord.zw = aTexCoord1.xy;\n\n vTexMatrix2 = vec4(0.0,0.0,1.0,0.0);\n\n vIsRGBA.y = 0.0;\n\n vTexCoordTransform.y = aTexCoord1.z;\n\n if(vTexCoordTransform.y < -90000.0)\n\n {\n\n vTexMatrix2.z = -1.0;\n\n }\n\n getTextureMatrixFromZValue(floor(vTexCoordTransform.y), vTexMatrix2.x, vTexMatrix2.y, vTexMatrix2.z, vIsRGBA.y);\n\n vTexMatrix2.w = log2(uTexture1Width * vTexMatrix.z);\n\n #endif\n\n\n\n vec4 vertexPos = aPosition;\n\n vec4 vertexColor = uFillForeColor;\n\n#ifdef VertexColor\n\n vertexColor *= aColor / 255.0;\n\n#endif\n\n#ifdef VertexNormal\n\n vec3 normal = aNormal;\n\n#endif\n\n #ifdef InstanceBim\n\n mat4 worldMatrix;\n\n worldMatrix[0] = uv2;\n\n worldMatrix[1] = uv3;\n\n worldMatrix[2] = uv4;\n\n worldMatrix[3] = vec4(0, 0, 0, 1);\n\n vertexPos = vec4(vertexPos.xyz,1.0) * worldMatrix;\n\n vertexColor *= secondary_colour;\n\n #endif\n\n\n\n\n\n #ifdef Instance\n\n float index = instanceId;\n\n #else\n\n float index = batchId;\n\n #endif\n\n vec4 positionMC = vec4(vertexPos.xyz, 1.0);\n\n vColor = vertexColor;\n\n #ifdef VertexNormal\n\n vNormalEC = czm_normal * normal;\n\n #endif\n\n vPositionMC = positionMC;\n\n vPositionEC = (czm_modelView * positionMC).xyz;\n\n gl_Position = czm_modelViewProjection * vec4(vertexPos.xyz, 1.0);\n\n }\n\n"},{"type":35632,"content":"#ifdef GL_OES_standard_derivatives\n\n #extension GL_OES_standard_derivatives : enable\n\n #define support_standard_derivatives 1\n\n#endif\n\n#ifdef GL_EXT_shader_texture_lod\n\n #extension GL_EXT_shader_texture_lod : enable\n\n #define support_shader_texture_lod 1\n\n#endif\n\n\n\nprecision highp float;\n\n\n\n#include <gl2_frag>\n\n\n\n#if __VERSION__ == 300\n\n #define support_standard_derivatives 1\n\n #define support_shader_texture_lod 1\n\n#endif\n\n\n\n uniform vec3 czm_lightDirectionEC;\n\n uniform vec4 uDiffuseColor;\n\n#ifdef TexCoord\n\n varying vec4 vTexCoord;\n\n#ifdef COMPUTE_TEXCOORD\n\n uniform sampler2D uTexture;\n\n uniform highp float uTexture0Width;\n\n varying vec4 vTexCoordTransform;\n\n varying vec4 vTexMatrix;\n\n varying vec2 vIsRGBA;\n\n#endif\n\n#endif\n\n\n\n varying vec4 vColor;\n\n varying vec4 vPositionMC;\n\n varying vec3 vPositionEC;\n\n#ifdef VertexNormal\n\n varying vec3 vNormalEC;\n\n#endif\n\n#ifdef TexCoord2\n\n uniform sampler2D uTexture2;\n\n uniform float uTexture1Width;\n\n varying vec4 vTexMatrix2;\n\n#endif\n\n#ifdef COMPUTE_TEXCOORD\n\n void calculateMipLevel(in vec2 inTexCoord, in float vecTile, in float fMaxMip, inout float mipLevel)\n\n {\n\n vec2 dx = dFdx(inTexCoord * vecTile);\n\n vec2 dy = dFdy(inTexCoord * vecTile);\n\n float dotX = dot(dx, dx);\n\n float dotY = dot(dy, dy);\n\n float dMax = max(dotX, dotY);\n\n float dMin = min(dotX, dotY);\n\n float offset = (dMax - dMin) / (dMax + dMin);\n\n offset = clamp(offset, 0.0, 1.0);\n\n float d = dMax * (1.0 - offset) + dMin * offset;\n\n mipLevel = 0.5 * log2(d);\n\n mipLevel = clamp(mipLevel, 0.0, fMaxMip - 1.62);\n\n }\n\n\n\n void calculateTexCoord(in vec3 inTexCoord, in float scale, in float XTran, in float YTran, in float fTile, in float mipLevel, inout vec2 outTexCoord)\n\n {\n\n if(inTexCoord.z < -9000.0)\n\n {\n\n outTexCoord = inTexCoord.xy;\n\n }\n\n else\n\n {\n\n vec2 fTexCoord = fract(inTexCoord.xy);\n\n float offset = 1.0 * pow(2.0, mipLevel) / fTile;\n\n fTexCoord = clamp(fTexCoord, offset, 1.0 - offset);\n\n outTexCoord.x = (fTexCoord.x + XTran) * scale;\n\n outTexCoord.y = (fTexCoord.y + YTran) * scale;\n\n }\n\n }\n\n\n\n vec4 getTexColorForS3M(sampler2D curTexture, vec3 oriTexCoord, float texTileWidth, float fMaxMipLev, float fTexCoordScale, vec2 vecTexCoordTranslate, float isRGBA)\n\n {\n\n vec4 color = vec4(1.0);\n\n float mipLevel = 0.0;\n\n #ifdef support_standard_derivatives\n\n calculateMipLevel(oriTexCoord.xy, texTileWidth, fMaxMipLev, mipLevel);\n\n #endif\n\n vec2 realTexCoord;\n\n calculateTexCoord(oriTexCoord, fTexCoordScale, vecTexCoordTranslate.x, vecTexCoordTranslate.y, texTileWidth, mipLevel, realTexCoord);\n\n if(isRGBA > 0.5)\n\n {\n\n vec2 rgbTexCoord;\n\n rgbTexCoord.x = (realTexCoord.x + vecTexCoordTranslate.x * fTexCoordScale) * 0.5;\n\n rgbTexCoord.y = (realTexCoord.y + vecTexCoordTranslate.y * fTexCoordScale) * 0.5;\n\n color = texture2D(curTexture, rgbTexCoord.xy, -10.0);\n\n vec2 vecAlphaTexCoord;\n\n vecAlphaTexCoord.x = rgbTexCoord.x;\n\n vecAlphaTexCoord.y = rgbTexCoord.y + fTexCoordScale * 0.5;\n\n color.a = texture2D(curTexture, vecAlphaTexCoord.xy, -10.0).r;\n\n }\n\n else\n\n {\n\n if(oriTexCoord.z < -9000.0)\n\n {\n\n color = texture2D(curTexture, realTexCoord.xy);\n\n }\n\n else\n\n {\n\n #ifdef support_shader_texture_lod\n\n color = texture2DLodEXT(curTexture, realTexCoord.xy, mipLevel);\n\n #else\n\n color = texture2D(curTexture, realTexCoord.xy, mipLevel);\n\n #endif\n\n }\n\n }\n\n\n\n return color;\n\n }\n\n\n\n vec4 getTextureColor()\n\n {\n\n if(vTexMatrix.z < 0.0)\n\n {\n\n return vec4(1.0);\n\n }\n\n float texTileWidth0 = vTexMatrix.z * uTexture0Width;\n\n vec3 realTexCoord = vec3(vTexCoord.xy, vTexCoordTransform.x);\n\n vec4 FColor = getTexColorForS3M(uTexture, realTexCoord, texTileWidth0, vTexMatrix.w, vTexMatrix.z, vTexMatrix.xy, vIsRGBA.x);\n\n #ifdef TexCoord2\n\n float texTileWidth1 = vTexMatrix2.z * uTexture1Width;\n\n realTexCoord = vec3(vTexCoord.zw, vTexCoordTransform.y);\n\n vec4 SColor = getTexColorForS3M(uTexture2, realTexCoord, texTileWidth1, vTexMatrix2.w, vTexMatrix2.z, vTexMatrix2.xy, vIsRGBA.y);\n\n SColor.r = clamp(SColor.r, 0.0, 1.0);\n\n SColor.g = clamp(SColor.g, 0.0, 1.0);\n\n SColor.b = clamp(SColor.b, 0.0, 1.0);\n\n return FColor * SColor;\n\n #else\n\n return FColor;\n\n #endif\n\n }\n\n#endif\n\n vec4 SRGBtoLINEAR4(vec4 srgbIn)\n\n {\n\n #ifndef HDR\n\n vec3 linearOut = pow(srgbIn.rgb, vec3(2.2));\n\n return vec4(linearOut, srgbIn.a);\n\n #else\n\n return srgbIn;\n\n #endif\n\n }\n\n vec3 LINEARtoSRGB(vec3 linearIn)\n\n {\n\n #ifndef HDR\n\n return pow(linearIn, vec3(1.0/2.2));\n\n #else\n\n return linearIn;\n\n #endif\n\n }\n\n\n\n vec3 computeNormal(in vec3 oriVertex)\n\n {\n\n vec3 normal = cross(vec3(dFdx(oriVertex.x), dFdx(oriVertex.y), dFdx(oriVertex.z)), vec3(dFdy(oriVertex.x), dFdy(oriVertex.y), dFdy(oriVertex.z)));\n\n normal = normalize(normal);\n\n return normal;\n\n }\n\n\n\n void main()\n\n {\n\n if(vColor.a < 0.1)\n\n {\n\n discard;\n\n }\n\n vec4 baseColorWithAlpha = vColor;\n\n #ifdef COMPUTE_TEXCOORD\n\n baseColorWithAlpha *= SRGBtoLINEAR4(getTextureColor());\n\n #endif\n\n\n\n if(baseColorWithAlpha.a < 0.1)\n\n {\n\n discard;\n\n }\n\n vec3 normal = vec3(0.0);\n\n #ifdef VertexNormal\n\n normal = normalize(vNormalEC);\n\n #endif\n\n normal = length(normal) > 0.1 ? normal : computeNormal(vPositionMC.xyz);\n\n vec3 color = baseColorWithAlpha.rgb;\n\n vec3 dirVectorEC = normalize(czm_lightDirectionEC);\n\n float dotProduct = dot( normal, dirVectorEC );\n\n float dirDiffuseWeight = max( dotProduct, 0.0 );\n\n dirDiffuseWeight = dirDiffuseWeight * 0.5 + 0.5;\n\n color += color * uDiffuseColor.rgb * dirDiffuseWeight;\n\n #ifdef TexCoord\n\n color = LINEARtoSRGB(color);\n\n #endif\n\n glFragColor = vec4(color, baseColorWithAlpha.a);\n\n#if __VERSION__ == 100\n\n gl_FragColor = glFragColor;\n\n#endif\n\n }\n\n"}],"techniques":[{"attributes":{"aPosition":{"semantic":"POSITION","type":35666},"instanceId":{"semantic":"instanceId","type":5126},"batchId":{"semantic":"_BATCHID","type":5126},"aTexCoord0":{"semantic":"TEXCOORD_0","type":35664},"aTexCoord1":{"semantic":"aTexCoord1","type":35666},"aNormal":{"semantic":"aNormal","type":35665},"aColor":{"semantic":"COLOR_0","type":35666},"uv2":{"semantic":"uv2","type":35666},"uv3":{"semantic":"uv3","type":35666},"uv4":{"semantic":"uv4","type":35666},"secondary_colour":{"semantic":"secondary_colour","type":35666},"uv6":{"semantic":"uv6","type":35666}},"program":0,"uniforms":{"czm_modelView":{"type":35676,"semantic":"MODELVIEW"},"czm_normal":{"type":35675,"semantic":"MODELINVERSETRANSPOSE"},"czm_modelViewProjection":{"type":35676,"semantic":"MODELVIEWPROJECTION"},"uTexMatrix":{"type":35676},"uTexture0Width":{"type":5126},"uFillForeColor":{"type":35666},"uSelectedColor":{"type":35666},"uDiffuseColor":{"type":35666},"uTexture":{"type":35678},"uTexture2":{"type":35678},"uTexture1Width":{"type":5126}}}]},{getTextureMagFilter:tr,getTextureMinFilter:er,getTextureWrap:rr,getMaterialType:nr,getMaterialFormat:ir,getPrimitive:sr,getUniqueREGLBuffer:or}=r.REGLHelper,ar=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],cr=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:lr,logoutIBLResOnCanvas:fr,getIBLResOnCanvas:ur,getPBRUniforms:hr}=r.pbr.PBRUtils,_r={factor:0,units:0},dr={specularStrength:0,materialShininess:1},Er=[1,1,1],Tr=n.identity([]),mr=t=>t.material instanceof r.PhongMaterial,Ar=t=>t.material instanceof r.pbr.StandardMaterial,pr=[!0,!0,!0,!0],yr=[],gr=new t.Coordinate(0,0),Rr=[],br=[],Ir={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"};class Nr{constructor(e,n){this.J=n,this.tt=n.getRenderer().canvas,this.et=new t.SpatialReference,this.rt=e,this.nt=new r.Renderer(e),this.it={},this.st={},this.ot={},this.at={},this.ct={},this.lt={},this.ft={},this.ut=new r.Scene,this.ht=new r.Scene,this._t=new r.Scene,this.dt=new r.Scene,this.Et=new r.ResourceLoader(e.texture(2)),this.Tt=this.At.bind(this),this.yt=new r.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.gt(),this.Rt=new r.KHRTechniquesWebglManager(this.rt,this.bt(),this.Et)}getI3DMMeshes(){return this.ct}getPNTSMeshes(){return this.at}getB3DMMeshes(){return this.ot}getMap(){return this.J.getMap()}paint(t,e,r,n){const i=this.getMap();if(!t.length||!i)return;const s=this.It(),o=i.projViewMatrix,a=this.J.options.services,c=[],l=[];let f=[];const u=[],h=[];for(let r=0,n=t.length;r<n;r++){const n=t[r].data.node;let i=this.Nt(n);if(!i)continue;this.lt[n.id]&&(i=this.lt[n.id],i=O(i));let d=a[n.St].polygonOffset||_r;y(d)&&(d=d());const E=a[n.St].ambientLight;Array.isArray(i)||(c[0]=i,i=c);for(let a=0,c=i.length;a<c;a++){if(i[a].getBoundingBox&&!_(o,i[a].getBoundingBox()))continue;const c=i[a].properties.magic;"b3dm"===c?f.push(i[a]):"pnts"===c?u.push(i[a]):"i3dm"===c&&h.push(i[a]),i[a].properties.level=t[r].selectionDepth,i[a].properties.polygonOffset=d,Object.prototype.hasOwnProperty.call(i[a].uniforms,"ambientColor")||Object.defineProperty(i[a].uniforms,"ambientColor",{enumerable:!0,get:function(){return E||s.ambientColor}}),i[a].wt=n,e[n.id]||l.push(i[a])}}let d=0;const E=this.Rt.getExcludeFilter();d+=this.Mt(this.Ot,s,[r,mr,E],n,l,f,h),d+=this.Mt(this.vt,s,[r,Ar,E],n,l,f,h),this.Rt.forEachShader(((t,e,i)=>{const s=this.It(i);d+=this.Mt(t,s,[r,e],n,l,f,h)})),this.ht.setMeshes(u);const T=this.Ct();return d+=this.nt.render(this.xt,T,this.ht,n&&n.fbo),d}Mt(t,e,r,n,i,s,o){t.filter=r.filter((t=>!!t)),e.debug=!1,this.ut.setMeshes(i),e.stencilEnable=!1,e.debug=!1,e.cullFace="back",e.colorMask=pr;let a=0;return this.ut.setMeshes(s),a+=this.nt.render(t,e,this.ut,n&&n.fbo),e.stencilEnable=!1,this._t.setMeshes(o),a+=this.nt.render(t,e,this._t,n&&n.fbo),a}Ut(t,e){return e.wt.Bt-t.wt.Bt}paintRegion(t,e,r,n,i){const s=this.getMap();if(!t.length&&!e.length)return;const o=s.projViewMatrix,a=[];for(let r=0,n=(t=t.concat(e)).length;r<n;r++){const e=t[r].node,n=this.Pt(e);n&&(n.getBoundingBox&&!_(o,n.getBoundingBox())||a.push(n))}this.Lt.filter=n,this.dt.setMeshes(a);const c=this.Dt(r);this.nt.render(this.Lt,c,this.dt,i&&i.fbo)}deleteTile(t){const e=t.node.id;this.Ft(e)}Ft(t){const e=this.st[t];e&&(e.geometry.dispose(),e.dispose(),delete this.st[t]);let r=this.ot[t]||this.at[t]||this.ct[t]||this.lt[t]||this.it[t];this.lt[t]?this.Gt(t):r&&(this.kt(r),delete this.ot[t],delete this.at[t],delete this.ct[t],delete this.it[t])}Gt(t){let e=this.lt[t];e=O(e);for(let t=0;t<e.length;t++){const{id:r}=e[t].properties;this.Ft(r)}delete this.lt[t]}kt(t){if(Array.isArray(t))for(let e=0,r=t.length;e<r;e++)this.kt(t[e]);else{const e=t.geometry.properties.url;if(e){const t=this.ft[e];t&&(t.refCount--,t.refCount<=0&&(t.geometry.dispose(),t.material.dispose(),delete this.ft[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.J;fr(t.getRenderer().canvas,t.getMap());for(const t in this.lt)this.Gt(t);this.lt={};for(const t in this.ot)this.Ft(t);this.ot={};for(const t in this.at)this.Ft(t);this.at={};for(const t in this.ct)this.Ft(t);this.ct={};for(const t in this.it)this.Ft(t);this.it={};for(const t in this.st)this.Ft(t);this.st={},this.Ot&&(this.Ot.dispose(),delete this.Ot),this.vt&&(this.vt.dispose(),delete this.vt),this.xt&&(this.xt.dispose(),delete this.xt),this.Lt&&(this.Lt.dispose(),delete this.Lt),this.Rt.dispose()}Pt(e){if(!e.boundingVolume||!e.boundingVolume.region)return null;if(this.st[e.id])return this.st[e.id];const i=e.boundingVolume.region;let s=new t.Coordinate(b(i[0]),b(i[1])),o=new t.Coordinate(b(i[2]),b(i[3]));s=this.Ht(s),o=this.Ht(o);const a=s.add(o).Vt(.5);s._sub(a),o._sub(a);const c=this.zt(i[4],i[5]),l=c.x,f=c.y,u=[s.x,s.y,f,o.x,s.y,f,o.x,o.y,f,s.x,o.y,f,s.x,s.y,l,o.x,s.y,l,o.x,o.y,l,s.x,o.y,l],h=new r.Geometry({aPosition:u},[0,1,1,2,2,3,3,0,0,4,1,5,2,6,3,7,4,5,5,6,6,7,7,4],0,{primitive:"lines"});h.generateBuffers(this.rt);const _=new r.Mesh(h),d=n.identity([]);return _.setLocalTransform(n.translate(d,d,[a.x,a.y,0])),this.st[e.id]=_,_}Nt(t){return this.ot[t.id]||this.at[t.id]||this.ct[t.id]||this.lt[t.id]}has(t){return this.Nt(t)||this.it[t.id]}createPntsMesh(t,e,i,s){if(this.at[e]){const t=this.at[e];return console.warn(`pnts mesh with id(${e}) was already created.`),s(null,{id:e,mesh:t}),t}const{pnts:o,featureTable:a,rootIdx:c}=t,l=a.POINTS_LENGTH,f=new r.Geometry(o,null,l,{primitive:"points",positionAttribute:"POSITION"});f.generateBuffers(this.rt);const u={};o.POSITION?u.HAS_POSITION=1:o.POSITION_QUANTIZED&&(u.HAS_POSITION_QUANTIZED=1),o.RGB?u.HAS_RGB=1:o.RGBA?u.HAS_RGBA=1:o.RGB565&&(u.HAS_RGB565=1),(o.NORMAL||o.NORMAL_OCT16P)&&(u.HAS_NORMAL=1,o.NORMAL_OCT16P&&(u.HAS_NORMAL_OCT16P=1)),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map((t=>t/255)));const{rtcCenter:h,rtcCoord:_}=t,d=this.Xt(_),E=this.Yt(i,h,_);n.multiply(E,E,d);const T=this.J.options.services[c],m=new r.Mesh(f);return m.properties.magic="pnts",m.properties.id=e,m.properties.count=l,m.properties.batchTable=t.batchTable,m.properties.batchTableBin=t.batchTableBin,m.setDefines(u),Object.defineProperty(m.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:T&&T.pointColor||[1,1,1,1]}}),Object.defineProperty(m.uniforms,"pointSize",{enumerable:!0,get:function(){return T&&T.pointSize||2}}),Object.defineProperty(m.uniforms,"pointOpacity",{enumerable:!0,get:function(){return T&&T.pointOpacity||1}}),m.setLocalTransform(E),this.at[e]=m,s(null,{id:e,mesh:[m]}),[m]}createI3DMMesh(t,e,s,o){if(this.ct[e]){const t=this.ct[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.it[e]||o(null,{id:e,mesh:t}),t}const c=this.Zt(s.Wt),{i3dm:l,featureTable:f,gltf:u,batchTable:h,batchTableBin:_,count:d}=t,E=f.INSTANCES_LENGTH,{rtcCenter:T,rtcCoord:m}=t,A=this.Xt(m),p=this.Yt(s,T,m),{POSITION:y,NORMAL_UP:g,NORMAL_RIGHT:R,SCALE:b,SCALE_NON_UNIFORM:I,INSTANCE_ROTATION:N}=l,S={"instance_vectorA":new Float32Array(4*E),"instance_vectorB":new Float32Array(4*E),"instance_vectorC":new Float32Array(4*E)},w=new Float32Array(3),O=new Float32Array(3),v=[],C=new Float32Array(1),x=new Float32Array(3),U=[],B=[],P=[],L=[],D=new Float32Array(9);!function(t,e){let{componentType:r,byteOffset:n,byteStride:i,count:s,itemSize:o}=t;const a=t.array.buffer,c=r?Dt.getTypedArrayCtor(r):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,i=i||0,s=s||t.array.length/o,(!i||i===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o)e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o);return}const l=new Uint8Array(o*c.BYTES_PER_ELEMENT);i||(i=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const r=new Uint8Array(a,i*t+n,o*c.BYTES_PER_ELEMENT);l.set(r),e(new c(l.buffer),t),r.set(l)}}(y,((t,e)=>{g?($t(O,R,e),$t(w,g,e),i.cross(v,O,w),i.normalize(v,v),M(U,O,0),M(U,w,1),M(U,v,2),a.fromMat3(B,U)):N?($t(D,N,e),a.fromMat3(B,D)):a.identity(B),b?($t(C,b,e),i.set(P,C[0],C[0],C[0])):I?($t(x,I,e),i.set(P,...x)):i.set(P,1,1,1),n.fromRotationTranslationScale(L,B,t,P),Jt(S.instance_vectorA,e,L,0),Jt(S.instance_vectorB,e,L,1),Jt(S.instance_vectorC,e,L,2)}));const F={};for(const t in S)F[t]={buffer:this.rt.buffer({dimension:S[t].length/E,data:S[t]}),divisor:1};const G=this.J.options.services[s.St].shader||"phong";let k=0,H=!0;const V=[];return Kt(u,((t,i,o,a)=>{let{geometry:l,material:f}=this.jt(t,i,o,a,s,!0,G);f&&!f.isReady()&&(H=!1,k++);const u=new r.InstancedMesh(F,E,l,f);u.properties.magic="i3dm",u.properties.id=e,u.properties.count=d,u.properties.batchTable=h,u.properties.batchTableBin=_;const T=this.Kt(t,l,f,s.St,a),m=n.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)n.multiply(m,m,t.matrices[e]);n.multiply(m,c,m),u.setPositionMatrix(m),n.multiply(A,p,A),u.setLocalTransform(A),u.setDefines(T),u.properties.polygonOffset={offset:0,factor:0},V.push(u)})),H?(this.ct[e]=V,o(null,{id:e,mesh:V})):(this.it[e]={meshes:V,count:k},V.qt=o),V}createB3DMMesh(e,i,s,o){if(this.ot[i]||this.it[i]){const t=this.ot[i];return console.warn(`mesh with id(${i}) was already created.`),this.it[i]||o(null,{id:i,mesh:t}),t}const a=e.gltf.asset&&"i3s"===e.gltf.asset.generator;let c;if(s.maxExtent){const e=new t.Extent(s.maxExtent).convertTo((t=>this._pointToPrj(t)));c=[e.xmin,e.ymin,e.xmax,e.ymax]}const l=this.Zt(s.Wt),f=e.gltf,{center:u,coord:h}=f.extensions.CESIUM_RTC,_=this.J.options.services[s.St].heightOffset||0;let d;if(_&&h&&(h[2]+=_),a){const{i3sProjCenter:t}=f.extensions.CESIUM_RTC;d=this.$t(t,s.St)}else d=this.Xt(h,s.St);const E=this.J.options.services[s.St].shader||"phong",T=[];let m=0,A=!0;return Kt(f,((t,o,f,_)=>{let{geometry:p,material:y}=this.jt(t,o,f,_,s,!1,E);y&&!y.isReady()&&(A=!1,m++);const g=new r.Mesh(p,y);g.properties.magic="b3dm",g.properties.id=i,g.properties.batchTable=e.batchTable,g.properties.batchTableBin=e.batchTableBin,g.properties.count=e.featureTable.BATCH_LENGTH;const R=this.Kt(t,p,y,s.St,_);g.setDefines(R),c&&(R.USE_MAX_EXTENT=1,g.setUniform("maxPrjExtent",c));let b=n.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)n.multiply(b,b,t.matrices[e]);const I=a?Tr:this.Yt(s,u,h);n.multiply(b,l,b),n.multiply(b,d,b),n.multiply(b,I,b),g.setLocalTransform(b),T.push(g)})),A?(this.ot[i]=T,o(null,{id:i,mesh:T})):(this.it[i]={meshes:T,count:m},T.qt=o),T}Yt(e,r,s){const o=this.getMap(),a=this.J.options.services[e.St].heightOffset||0,c=new t.Coordinate(s),l=o.distanceToPointAtRes(100,0,o.getGLRes(),c).x/100;let f=e.matrix?n.copy([],e.matrix):n.identity([]);if(r){Le(f,i.transformMat4(yr,r,f),f)}const u=function(t,e,r,n,i,s,o){e=k(ze,e);const a=re(ze,e[0]*Je,e[1]*Je,e[2]),c=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}(Xe,r),l=n.ellipsoid;var f;f=0===$(c)?H(Ye,0,0,-6378137):ce(Ye,c),qe.x=f[0],qe.y=f[1];const u=n.project(qe,$e);Ze[0]=u.x/i,Ze[1]=u.y/i,Ze[2]=(f[2]+o)*s;const h=De(a,l,We),_=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],c=e[6],l=e[7],f=e[8],u=e[9],h=e[10],_=e[11],d=e[12],E=e[13],T=e[14],m=e[15],A=r*a-n*o,p=r*c-i*o,y=r*l-s*o,g=n*c-i*a,R=n*l-s*a,b=i*l-s*c,I=f*E-u*d,N=f*T-h*d,S=f*m-_*d,w=u*T-h*E,M=u*m-_*E,O=h*m-_*T,v=A*O-p*M+y*w+g*S-R*N+b*I;return v?(v=1/v,t[0]=(a*O-c*M+l*w)*v,t[1]=(i*M-n*O-s*w)*v,t[2]=(E*b-T*R+m*g)*v,t[3]=(h*R-u*b-_*g)*v,t[4]=(c*S-o*O-l*N)*v,t[5]=(r*O-i*S+s*N)*v,t[6]=(T*y-d*b-m*p)*v,t[7]=(f*b-h*y+_*p)*v,t[8]=(o*M-a*S+l*I)*v,t[9]=(n*S-r*M-s*I)*v,t[10]=(d*R-E*y+m*A)*v,t[11]=(u*y-f*R-_*A)*v,t[12]=(a*N-o*w-c*I)*v,t[13]=(r*w-n*N+i*I)*v,t[14]=(E*p-d*g-T*A)*v,t[15]=(f*g-u*p+h*A)*v,t):null}(je,h),d=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}(Ke,r),E=function(t,e,r){var n=t[0],i=t[1],s=t[2],o=t[4],a=t[5],c=t[6],l=t[8],f=t[9],u=t[10],h=e[0],_=e[1],d=e[2],E=e[3],T=e[4],m=e[5],A=e[6],p=e[7],y=e[8],g=n*h+o*_+l*d,R=i*h+a*_+f*d,b=s*h+c*_+u*d,I=n*E+o*T+l*m,N=i*E+a*T+f*m,S=s*E+c*T+u*m,w=n*A+o*p+l*y,M=i*A+a*p+f*y,O=s*A+c*p+u*y;return r[0]=g,r[1]=R,r[2]=b,r[3]=0,r[4]=I,r[5]=N,r[6]=S,r[7]=0,r[8]=w,r[9]=M,r[10]=O,r[11]=0,r[12]=t[12],r[13]=t[13],r[14]=t[14],r[15]=t[15],r}(_,d,t);return Le(t,Ze,E),t}(f,s,f,o.getProjection(),o.getGLRes(),l,a),h=function(t,e){return H(t,e[12],e[13],e[14]),t}(br,u);let _=this.J.options.offset;if(y(_)){_=_(this.J.Jt(e.id).center)}return i.set(Rr,_[0],_[1],0),i.sub(h,h,Rr),Le(u,h,u),u}createCMPTMesh(t,e,r,n){if(this.lt[e]){const t=this.lt[e];return console.warn(`mesh with id(${e}) was already created.`),n(null,{id:e,mesh:t}),t}const{content:i}=t,s=[];for(let t=0;t<i.length;t++){const{magic:n}=i[t],o=e+"."+t;"b3dm"===n?this.createB3DMMesh(i[t],o,r,((t,{mesh:e})=>{s.push(e)})):"i3dm"===n?this.createI3DMMesh(i[t],o,r,((t,{mesh:e})=>{s.push(e)})):"pnts"===n?this.createPntsMesh(i[t],o,r,((t,{mesh:e})=>{s.push(e)})):"cmpt"===n&&this.createCMPTMesh(i[t],o,r,((t,{mesh:e})=>{s.push(e)}))}return this.lt[e]=s,n(null,{id:e,mesh:s}),s}Kt(t,e,r,n,i){const s=("phong"===(this.J.options.services[n].shader||"phong")?this.Ot:this.vt).getGeometryDefines(e);return i.asset&&"S3M"===i.asset.generator&&this.Qt(s,e,i),s}Qt(t,e,r){e.data.aNormal&&(t.VertexNormal=1),e.data.instanceId&&(t.Instance=1),e.data.aTexCoord0&&(t.TexCoord=1),e.data.aColor&&(t.VertexColor=1),e.data.aTexCoord1&&(t.TexCoord2=1),e.data.uv2&&(t.InstanceBim=1),e.data.aTexCoord0&&r.textures.length&&(t.COMPUTE_TEXCOORD=1)}jt(t,e,r,n,i,s,o){let a=!1;n.asset&&"S3M"===n.asset.generator&&(a=!0,n.extensions=n.extensions||{},n.extensions.KHR_techniques_webgl=Qe);const c=n.url+"-"+e+"-"+r;if(this.ft[c])return this.ft[c].refCount++,this.ft[c];let l,f;const u=n.materials[t.material];if(n.extensions&&n.extensions.KHR_techniques_webgl&&u.extensions&&u.extensions.KHR_techniques_webgl){const e=this.te(t,n,s,a);l=e.material,f=e.geometry;this.J.options.services[i.St].fillEmptyDataInMissingAttribute&&(f.desc.fillEmptyDataInMissingAttribute=!0)}else{f=this.ee(t,s,Ir);const e=this.J.options.services[i.St].material;l=this.re(t.material,n,o,e||dr)}l&&!l.isReady()?l.ne=i.id:l||(l=this.yt);const h={refCount:1,geometry:f,material:l};return f.properties.url=c,this.ft[c]=h,h}te(t,e,r,n){const{geometry:i,material:s}=this.Rt.createMesh(t,e,r,n);return{geometry:i,material:s}}ee(t,e,n){const i=t.attributes;if(i.COLOR_0){const t=i.COLOR_0.array||i.COLOR_0;if(t instanceof Float32Array){const e=new Uint8Array(t.length);for(let r=0;r<e.length;r++)e[r]=Math.round(255*t[r]);i.COLOR_0.array?(i.COLOR_0.array=e,i.COLOR_0.componentType=5121):i.COLOR_0=e}}const s={};for(const t in i){const e=or(this.rt,i[t],{dimension:i[t].itemSize}),r=n[t]||t;s[r]={buffer:e},i[t].quantization&&(s[r].quantization=i[t].quantization),r===n.POSITION&&(s[r].array=i[t].array,s[r].min=i[t].min,s[r].max=i[t].max)}delete t.attributes;const o=new r.Geometry(s,t.indices?t.indices.array?t.indices.array.slice():t.indices:null,0,{positionAttribute:n.POSITION,normalAttribute:n.NORMAL,uv0Attribute:n.TEXCOORD_0,uv1Attribute:n.TEXCOORD_1,color0Attribute:n.COLOR_0,tangentAttribute:n.TANGENT,batchIdAttribute:n._BATCHID,primitive:void 0===t.mode?"triangles":sr(t.mode)});return o.generateBuffers(this.rt,{excludeElementsInVAO:e}),o}Xt(t){const e=n.identity([]),r=this.getMap(),s=this.ie();gr.x=t[0],gr.y=t[1];const o=r.distanceToPointAtRes(100,100,r.getGLRes(),gr);return i.set(s,o.x/100*1.01,o.y/100*1.01,o.y/100),n.scale(e,e,s),e}$t(e,r){const s=n.identity([]),o=this.getMap(),a=this._prjToPoint(new t.Coordinate(e)),c=this.ie(),l=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes()),f=i.set(br,a.x,a.y,l*e[2]);n.translate(s,s,f);const u=this.J.options.services[r].heightOffset;if(u){const r=o.getProjection().unproject(new t.Coordinate(e)),i=o.distanceToPointAtRes(100,100,o.getGLRes(),r).y/100;n.translate(s,s,[0,0,u*i])}return n.scale(s,s,i.scale([],c,l)),s}gt(){const t={x:0,y:0,width:()=>this.tt?this.tt.width:1,height:()=>this.tt?this.tt.height:1};this.Lt=new r.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)=>n.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],i=[];this.xt=new r.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)=>n.multiply(i,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>s.fromMat4(e,r.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const o=this.bt();this.Ot=new r.PhongShader({extraCommandProps:o}),this.vt=new r.pbr.StandardShader({extraCommandProps:o});const a=this.J;lr(a.getRenderer().canvas,this.rt,a.getMap())}bt(){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||pr,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:"replace"}},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]}}Ct(t){const e=this.getMap(),r=e.getLightManager(),n=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],s=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:s,lightDir:i.normalize(n,n)}}It(){const t=this.getMap(),e=this.J.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=ur(e),i=hr(t,r,n);return p(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),i}re(t,e,n,i){const s=e.materials[t];if(!s||!s.baseColorTexture&&!s.pbrMetallicRoughness)return null;const a=p({},i);if(s.baseColorTexture){const t=e.textures[s.baseColorTexture.index];let r;t&&!t.image.color&&(r=this.S(t)),a.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(a.baseColorTexture=r)}else{if(s.normalTexture){const t=this.S(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;a.normalTexture=t,a.normalMapFactor=r}if(s.occlusionTexture){const t=this.S(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;a.occlusionTexture=t,a.occlusionFactor=r}if(s.emissiveTexture){const t=this.S(e.textures[s.emissiveTexture.index]);a.emissiveTexture=t}s.emissiveFactor;const t=s.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(a.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];r.image&&r.image.color?a.baseColorFactor=a.baseColorFactor?o.multiply(a.baseColorFactor,a.baseColorFactor,r.image.color):r.image.color:(a.baseColorTexture=this.S(r),a.baseColorTexture.getREGLTexture(this.rt))}if(A(t.metallicFactor)||(a.metallicFactor=t.metallicFactor),A(t.roughnessFactor)||(a.roughnessFactor=t.roughnessFactor),s.metallicRoughnessTexture){const t=this.S(e.textures[s.metallicRoughnessTexture.index]);a.metallicRoughnessTexture=t}}}if(s.s3mMaterial)return new r.Material(a);let c=new r.pbr.StandardMaterial(a);return"phong"===n&&(c=r.PhongMaterial.convertFrom(c)),c.once("complete",this.Tt),c}S(t){const e={type:t.type?nr(t.type):"uint8",format:t.format?ir(t.format):"rgba",flipY:!!t.flipY},n=t.image;n.array?e.data=n.array:n.mipmap&&(e.mipmap=n.mipmap),e.width=n.width,e.height=n.height;const i=t.sampler||t.texture.sampler;return i&&(i.magFilter&&(e.mag=tr(i.magFilter)),i.minFilter&&(e.min=er(i.minFilter)),i.wrapS&&(e.wrapS=rr(i.wrapS)),i.wrapT&&(e.wrapT=rr(i.wrapT))),new r.Texture2D(e,this.Et)}se(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}At({target:t}){const e=t.ne,r=this.it[e];if(r.count--,!r.count){const t=r.meshes;this.ot[e]=t,delete this.it[e];const n=t.qt;delete t.qt,n(null,{mesh:r.meshes,id:e})}}ie(){return Er}Ht(t){return this.J.Ht(t)}zt(t,e){const r=this.getMap();return r.getGLZoom?r.distanceToPoint(t,e,r.getGLZoom()):r.distanceToPointAtRes(t,e,r.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())}Zt(t){return"Y"===t?ar:"X"===t?cr:Tr}}
|
|
18
|
+
let it=0;function st(t){return null==t}function ot(t){return!st(t)}function at(t){for(let e=1;e<arguments.length;e++){const r=arguments[e];for(const e in r)t[e]=r[e]}return t}function ct(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 lt(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function ft(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),r=e.length,n=new Uint8Array(r);for(let t=0;t<r;t++)n[t]=e.charCodeAt(t);return n.buffer}const ut=[],ht=[],_t=[],dt=[0,0,0],Et=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}([]),Tt=[1,1,1];function mt(t,e,r,n,i,s,o){const a=ct(o);if((0===i||i===n*a.BYTES_PER_ELEMENT)&&s%a.BYTES_PER_ELEMENT==0){const i=new a(e,s,r*n);return t.set(i),t}const c=new Uint8Array(n*a.BYTES_PER_ELEMENT);for(let o=0;o<r;o++){let r=null;const l=new Uint8Array(e,i*o+s,n*a.BYTES_PER_ELEMENT);c.set(l),r=new a(c.buffer,0,n);for(let e=0;e<n;e++)t[o*n+e]=r[e]}return t}const At="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function pt(t,e,r){const n=new Uint8Array(t,e,r);return At.decode(n)}const yt={get:function(t,e={}){e||(e={});const r=new AbortController,n=r.signal,i=at({},e);i.signal=n,i.method||(i.method="GET");const s=fetch(t,i).then((t=>{const r=this.t(t,e.responseType);return r.message?r:r.then((r=>"arraybuffer"===e.responseType?{data:r,cacheControl:t.headers.get("Cache-Control"),expires:t.headers.get("Expires"),contentType:t.headers.get("Content-Type")}:r)).catch((t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t}))})).catch((t=>{if(!t.code||t.code!==DOMException.ABORT_ERR)throw t}));return s.xhr=r,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",yt.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?yt.jsonp(t):((e=e||{}).responseType="json",yt.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+it++;t.match(/\?/)?t+="&callback="+e:t+="?callback="+e;let r=document.createElement("script");return r.type="text/javascript",r.src=t,new Promise((t=>{window[e]=function(n){document.getElementsByTagName("head")[0].removeChild(r),r=null,delete window[e],t(n)},document.getElementsByTagName("head")[0].appendChild(r)}))}};class gt{constructor(t,e,r){this.i=t,this.decoders=e,this.o=r,this.images={},this.l={}}requestImageFromBufferURI(t,e,r){if(this.buffers[t.id]){const n=this.buffers[t.id],i=this.u(e,n);return this.getImageByBuffer(i,r)}if(this.l[t.id])return this.l[t.id].then((()=>{const n=this.buffers[t.id],i=this.u(e,n);return this.getImageByBuffer(i,r)}));if(lt(t.uri)){const n=this.buffers[t.id]=ft(t.uri),i=this.u(e,n);return this.getImageByBuffer(i,r)}return this.l[t.id]=yt.getArrayBuffer(t.uri,null).then((n=>{const i=this.buffers[t.id]=n.data,s=this.u(e,i);return this.getImageByBuffer(s,r)}))}getImageByBuffer(t,e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const r=this.decoders;if(r[e.mimeType])return r[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 r=new Blob([t],{type:e.mimeType}),n=URL.createObjectURL(r);return this.h(e.id,n)}}requestExternalImage(t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=0===t.uri.indexOf("data:image/")?t.uri:this.rootPath+"/"+t.uri;return this.l[t.id]?this.l[t.id].then((()=>this.images[t.id])):this.l[t.id]=this.h(t.id,e)}h(t,e){return new Promise(((r,n)=>{this.i(e,((i,s)=>{i?n(i):(URL.revokeObjectURL(e),this.images[t]=s,r(this.images[t]))}))}))}}const Rt=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16];class bt{constructor(t,e,r){this.rootPath=t,this.gltf=e,this._=!1,this.glbBuffer=r,this.buffers={},this.requests={},this.accessors={},this.T()}m(t,e){const r=this.gltf,n=r.accessors[e];if(void 0===n.bufferView)return this.accessors[n.id]=this.A(t,e,null,0),Promise.resolve(this.accessors[n.id]);if(n&&this.accessors[n.id])return Promise.resolve(this.accessors[n.id]);const i=r.bufferViews[n.bufferView];return this.p(i).then((r=>{const{buffer:i,byteOffset:s}=r;return this.accessors[n.id]=this.A(t,e,i,s)}))}p(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(lt(e.uri)){const t=this.buffers[e.id]=ft(e.uri);return Promise.resolve({buffer:t,byteOffset:0})}let t;const r=e.uri.indexOf("blob:")>=0;return t=e.uri.indexOf("://")>0||r?e.uri:this.rootPath+"/"+e.uri,this.requests[e.id]=yt.getArrayBuffer(t,null).then((n=>(r&&URL.revokeObjectURL(t),{buffer:this.buffers[e.id]=n.data,byteOffset:0})))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}A(t,e,r,n=0){const i=this.gltf,s=i.accessors[e],o=void 0!==s.bufferView?i.bufferViews[s.bufferView]:{},a=(o.byteOffset||0)+n,c=this.g(s.type),l=ct(s.componentType),f=o.byteStride||0,u={array:void 0,name:t,accessorName:e,byteLength:s.count*c*l.BYTES_PER_ELEMENT,componentType:s.componentType,count:s.count,type:s.type,itemSize:c};if(s.min&&(u.min=s.min),s.max&&(u.max=s.max),r)if(this._)u.byteStride=f,u.byteOffset=a+(s.byteOffset||0),!f||f===c*l.BYTES_PER_ELEMENT||"indices"===t||"input"===t||"output"===t||t.indexOf("morph")>=0?(u.array=this.R(r,s.count,c,a+(s.byteOffset||0),l),u.array.buffer.byteLength===u.byteLength&&(u.byteOffset=0)):u.array=new Uint8Array(r,a,o.byteLength);else if(s.interleaved){u.byteStride=0,u.byteOffset=0;const t=new l(s.count*c);u.array=mt(t,r,s.count,c,f,a+(s.byteOffset||0),s.componentType)}else u.byteStride=0,u.array=this.R(r,s.count,c,a+(s.byteOffset||0),l),u.byteOffset=u.array.byteOffset;else{u.array=new l(s.count);const t=u.min||u.max;t&&(u.array[0]=t[0],u.array[1]=t[1],u.array[2]=t[2])}return u}T(){const t=this.gltf.accessors;if(Array.isArray(t))for(let e=0;e<t.length;e++)for(let r=0;r<t.length;r++)e!==r&&t[e].bufferView===t[r].bufferView&&(t[e].interleaved=t[r].interleaved=!0);else for(const e in t)for(const r in t)e!==r&&t[e].bufferView===t[r].bufferView&&(t[e].interleaved=t[r].interleaved=!0)}R(t,e,r,n,i){return n%i.BYTES_PER_ELEMENT!=0&&(t=t.slice(n,n+e*r*i.BYTES_PER_ELEMENT),n=0),new i(t,n,r*e)}g(t){const e=Rt.indexOf(t);return Rt[e+1]}requestKHRTechniquesWebgl(t){const{shaders:e}=t,r=e.map((t=>{if(void 0!==t.bufferView){const e=this.gltf.bufferViews[t.bufferView],{byteLength:r}=e;return this.p(e).then((n=>{const{buffer:i,byteOffset:s}=n,o=pt(i,s+(e.byteOffset||0),r);return t.content=o,t}))}if(t.uri){if(lt(t.uri)){const e=ft(t.uri),r=pt(e,0,e.byteLength);return t.content=r,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return yt.get(e).then((e=>(t.content=e,t)))}}return Promise.resolve(t)}));return Promise.all(r).then((()=>t))}}class It extends gt{constructor(t,e,r,n,i,s){super(n,i,s),this.rootPath=t,this.gltf=e,this.requests={},this.buffers={},this.glbBuffer=r,this.accessor=new bt(t,e,r)}iterate(t,e){const r=this.gltf[e];if(!r)return;let n=0;for(const e in r)t(e,r[e],n++)}createNode(t){const e={};if(ot(t.name)&&(e.name=t.name),ot(t.children)&&(e.children=t.children),ot(t.jointName)&&(e.jointName=t.jointName),ot(t.matrix)&&(e.matrix=t.matrix),ot(t.rotation)&&(e.rotation=t.rotation),ot(t.scale)&&(e.scale=t.scale),ot(t.translation)&&(e.translation=t.translation),ot(t.extras)&&(e.extras=t.extras),ot(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 r=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}(ut,e.translation||dt),n=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,c=i+i,l=r*o,f=n*o,u=n*a,h=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-u-d,t[1]=f+m,t[2]=h-T,t[3]=0,t[4]=f-m,t[5]=1-l-d,t[6]=_+E,t[7]=0,t[8]=h+T,t[9]=_-E,t[10]=1-l-u,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(ht,e.rotation||Et),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}(_t,e.scale||Tt);return D(i,n,i),D(t,r,i)}return L(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}I(t){const e={};for(const r in t){const n=t[r];let i,s;n.instanceTechnique&&n.instanceTechnique.values?(i=n.instanceTechnique,s=i.values.diffuse):(i=n,s=i.values.tex||i.values.diffuseTex||i.values.diffuse);const o={baseColorTexture:{index:s}};n.name&&(o.name=n.name),n.extensions&&(o.extensions=n.extensions),n.extras&&(o.extras=n.extras),e[r]=o}return e}N(t){if(t.bufferView||t.extensions&&(t.extensions.KHR_binary_glTF||t.extensions.binary_glTF)){const e=t.bufferView?t:t.extensions.KHR_binary_glTF||t.extensions.binary_glTF;t.extensions&&(t.mimeType=e.mimeType,t.width=e.width,t.height=e.height);const r=this.gltf.bufferViews[e.bufferView],n=(r.byteOffset||0)+this.glbBuffer.byteOffset,i=r.byteLength,s=this.buffers[e.bufferView]=new Uint8Array(this.glbBuffer.buffer,n,i);return this.getImageByBuffer(s,t)}return this.requestExternalImage(t)}S(t){const e=this.gltf.textures[t];if(!e)return null;const r=this.gltf.images[e.source];return this.N(r).then((t=>{const n=this.gltf.samplers[e.sampler];return{image:{array:t.data,width:t.width,height:t.height,index:e.source,mimeType:r.mimeType,name:r.name,extras:r.extras},sampler:n}}))}getBaseColorTexture(t){const e=this.gltf.materials[t];let r,n;if(e.instanceTechnique&&e.instanceTechnique.values?(r=e.instanceTechnique,n=r.values.diffuse):(r=e,n=r.values.tex||r.values.diffuseTex||r.values.diffuse),void 0===n||void 0===this.gltf.textures)return null;const i=this.gltf.textures[n];if(!i)return null;const s=this.gltf.samplers[i.sampler];return{format:i.format||6408,internalFormat:i.internalFormat||6408,type:i.type||5121,sampler:s,source:this.gltf.images[i.source]}}getMaterial(){return null}getAnimations(){return null}}class Nt extends gt{constructor(t,e,r,n,i,s){super(n,i,s),this.rootPath=t,this.gltf=e,this.glbBuffer=r,this.buffers={},this.requests={},this.accessor=new bt(t,e,r)}iterate(t,e){const r=this.gltf[e];if(r)for(let e=0;e<r.length;e++)t(e,r[e],e)}createNode(t){const e={};return at(e,t),!ot(t.weights)&&this.gltf.meshes&&ot(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}S(t){const e=this.gltf.textures[t];if(!e)return null;const r=this.gltf.images[e.source];return this.N(r).then((t=>{if(!t)return null;const n={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};at(n,e);const i=ot(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return i&&(n.sampler=i),t.format&&(n.format=t.format),n}))}N(t){if(!ot(t.bufferView))return this.requestExternalImage(t);{const e=this.gltf.bufferViews[t.bufferView],r=this.gltf.buffers[e.buffer];if(r.uri)return this.requestImageFromBufferURI(r,e,t);if(this.glbBuffer)return this.M(e,t)}return null}M(t,e){const r=this.u(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(r,e)}u(t,e,r){r=r||0;const n=t.byteOffset+r,i=t.byteLength;return new Uint8Array(e,n,i)}O(t,e){const r=new Array(t.byteLength);for(let e=0;e<t.byteLength;e++)r[e]=String.fromCharCode(t[e]);return r.join(""),"data:"+(e=e||"image/png")+";base64,"+function(t){return"undefined"!=typeof self?self.btoa(t):window.btoa(t)}(unescape(encodeURIComponent(r)))}getAnimations(t){const e=[];return t.forEach((t=>{e.push(this.getSamplers(t.samplers))})),Promise.all(e).then((e=>{for(let r=0;r<e.length;r++)t[r].samplers=e[r];return t}))}getSamplers(t){const e=[];for(let r=0;r<t.length;r++)(ot(t[r].input)||ot(t[r].output))&&(e.push(this.accessor.m("input",t[r].input)),e.push(this.accessor.m("output",t[r].output)));return Promise.all(e).then((e=>{for(let r=0;r<e.length/2;r++)t[r].input=e[2*r],t[r].output=e[2*r+1],t[r].interpolation||(t[r].interpolation="LINEAR");return t}))}}const St="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class wt{static read(t,e=0,r=0){r||(r=t.byteLength);const n=new DataView(t,e,r),i=n.getUint32(4,!0);if(1===i)return wt.readV1(n,e);if(2===i)return wt.readV2(t,e);throw new Error("Unsupported glb version : "+i)}static readV1(t,e){const r=t.getUint32(8,!0),n=t.getUint32(12,!0);if(r!==t.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const i=Mt(t.buffer,20+e,n);return{json:JSON.parse(i),glbBuffer:{byteOffset:20+e+n,buffer:t.buffer,byteLength:r}}}static readV2(t,e){let r,n,i;const s=new DataView(t,e+12);let o=0;for(;o<s.byteLength;){const a=s.getUint32(o,!0);o+=4;const c=s.getUint32(o,!0);if(o+=4,1313821514===c)r=Mt(t,e+12+o,a);else if(5130562===c){i=e+12+o,n=a;break}o+=a}return{json:JSON.parse(r),glbBuffer:{byteOffset:i,buffer:t,byteLength:n}}}}function Mt(t,e,r){if(St){const n=new Uint8Array(t,e,r);return St.decode(n)}return function(t){const e=t.length;let r="";for(let n=0;n<e;){let i=t[n++];if(128&i){let r=Ot[i>>3&7];if(!(64&i)||!r||n+r>e)return null;for(i&=63>>r;r>0;r-=1){const e=t[n++];if(128!=(192&e))return null;i=i<<6|63&e}}r+=String.fromCharCode(i)}return r}(new Uint8Array(t,e,r))}const Ot=[1,1,1,1,2,2,3,0],vt=[0,0,0],Ct=[0,0,0,1],xt=[1,1,1],Ut={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={v(t,e,r,n,i,s,o,a){const c=ot(t)?e.animations:[e.animations[0]],l={};for(let e=0;e<c.length;e++){const f=c[e],u=f.name||e;if(ot(t)&&u!==t)continue;const h=f.channelsMap[r];if(h)for(let t=0;t<h.length;t++){const e=h[t];"translation"===e.target.path?(this.C(i,f.samplers[e.sampler],n,1),l.translation=H(vt,i)):"rotation"===e.target.path?(this.U(s,f.samplers[e.sampler],n,1),l.rotation=nt(Ct,s)):"scale"===e.target.path?(this.C(o,f.samplers[e.sampler],n,1),l.scale=H(xt,o)):"weights"===e.target.path&&a&&(this.C(a,f.samplers[e.sampler],n,a.length),l.weights=a)}}return l},C(t,e,r,n){switch(e.interpolation){case"LINEAR":{const i=this.B(Bt,e,r,1*n);i&&(t=function(t,e,r,n){for(let i=0;i<t.length;i++)t[i]=e[i]+n*(r[i]-e[i]);return t}(t,i.PREVIOUS,i.NEXT,i.INTERPOLATION));break}case"STEP":{const i=this.B(Bt,e,r,1*n);i&&(t=function(t,e){for(let r=0;r<t.length;r++)t[r]=e[r];return t}(t,...i.PREVIOUS));break}case"CUBICSPLINE":{const i=this.B(Bt,e,r,3*n);i&&(t=this.P(t,i,e.input.array,3*n));break}}return t},U(t,e,r){switch(e.interpolation){case"LINEAR":{const n=this.B(Bt,e,r,1);n&&et(t,n.PREVIOUS,n.NEXT,n.INTERPOLATION);break}case"STEP":{const n=this.B(Bt,e,r,1);n&&(t=Q(t,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this.B(Bt,e,r,3);if(n){for(let t=0;t<n.PREVIOUS.length;t++)n.PREVIOUS[t]=Math.acos(n.PREVIOUS[t]),n.NEXT[t]=Math.acos(n.NEXT[t]);t=this.P(t,n,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},L(t,e){const r=t.length;let n,i,s,o=0,a=r-1,c=Math.floor((o+a)/2);for(;o<=r-1&&a>=0;){if(o===a)return null;if(t[c]<=e&&e<=t[c+1]){const r=t[c];return n=c,i=c+1,s=(e-r)/(t[c+1]-r),{preIndx:n,nextIndex:i,interpolation:s}}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},B(t,e,r,n){const i=e.input.array,s=e.output.array,o=e.output.itemSize;(r<i[0]||r>i[i.length-1])&&(r=Math.max(i[0],Math.min(i[i.length-1],r))),r===i[i.length-1]&&(r=i[0]);const a=this.L(i,r);if(!a||!a.nextIndex)return null;const{preIndx:c,nextIndex:l,interpolation:f}=a;t.PREINDEX=c,t.NEXTINDEX=l,t.INTERPOLATION=f;const u=o*n;return t.PREVIOUS=s.subarray(t.PREINDEX*u,(t.PREINDEX+1)*u),t.NEXT=s.subarray(t.NEXTINDEX*u,(t.NEXTINDEX+1)*u),t},P(t,e,r,n){const i=e.INTERPOLATION,s=r[e.PREINDEX],o=r[e.NEXTINDEX];for(let r=0;r<3;r++){const a=e.PREVIOUS[n+r],c=(o-s)*e.PREVIOUS[2*n+r],l=e.NEXT[3+r],f=(o-s)*e.NEXT[r],u=(2*Math.pow(i,3)-3*Math.pow(i,2)+1)*a+(Math.pow(i,3)-2*Math.pow(i,2)+i)*c+(2*-Math.pow(i,3)+3*Math.pow(i,2))*l+(Math.pow(i,3)-Math.pow(i,2))*f;t[r]=u}return t},getAnimationClip(t,e,r,n){const i=t.nodes[e]&&t.nodes[e].weights;return V(vt,...Ut.TRANSLATION),Q(Ct,...Ut.ROTATION),V(xt,...Ut.SCALE),this.v(n,t,e,r,vt,Ct,xt,i)},getTimeSpan(t){if(!t.animations)return null;if(t.timeSpan)return t.timeSpan;const e=t.animations;return t.timeSpan={},e.forEach(((e,r)=>{let n=-1/0,i=1/0;const s=e.channels;for(let t=0;t<s.length;t++){const r=s[t],o=e.samplers[r.sampler].input.array;o[o.length-1]>n&&(n=o[o.length-1]),o[0]<i&&(i=o[0])}const o=e.name||r;t.timeSpan[o]={max:n,min:i}})),t.timeSpan},getTimeSpanByName(t,e){const r=this.getTimeSpan(t);return r?ot(e)?r[e]:r[Object.keys(r)[0]]:null}};let Lt=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(Or){}t&&"undefined"!=typeof createImageBitmap&&(Lt=!0)}const Dt="undefined"==typeof document?null:document.createElement("canvas");class Ft{constructor(t,e,r){if(this.options=r||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:r,glbBuffer:n}=wt.read(e.buffer,e.byteOffset,e.byteLength);this.D(t,r,n)}else this.D(t,e);this.F=new bt(this.rootPath,this.gltf,this.glbBuffer),this.G()}G(){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.F.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),r=this.V(),n=this.X(),i=this.k();return Promise.all([e,r,n,i]).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 r=e[t];r.channelsMap={};for(let t=0;t<r.channels.length;t++){const e=r.channels[t];r.channelsMap[e.target.node]||(r.channelsMap[e.target.node]=[]),r.channelsMap[e.target.node].push(e)}}}getExternalResources(){const t=[];if(this.gltf){const{buffers:e,images:r}=this.gltf;for(let r=0;r<e.length;r++)e[r].uri&&e[r].uri.indexOf("data:application/octet-stream;base64")<0&&t.push({type:"buffer",uri:e[r].uri});for(let e=0;e<r.length;e++)r[e].uri&&r[e].uri.indexOf("data:image/")<0&&t.push({type:"image",uri:r[e].uri})}return t}static getAnimationClip(t,e,r,n){return Pt.getAnimationClip(t,e,r,n)}static getAnimationTimeSpan(t,e){return Pt.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return ct(t)}static readInterleavedArray(t,e,r,n,i,s,o){return mt(t,e,r,n,i,s,o)}D(t,e,r){this.gltf=e,this.glbBuffer=r,this.version=e.asset?+e.asset.version:1,this.rootPath=t,this.buffers={},this.requests={},this.options.requestImage=Lt?Vt.bind(this):this.options.requestImage||Gt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new Nt(t,e,r,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate(((t,e,r)=>{e.id="buffer_"+r}),"buffers"),this.adapter.iterate(((t,e,r)=>{e.id="image_"+r}),"images"),this.adapter.iterate(((t,e,r)=>{e.id="accessor_"+r}),"accessors")):(this.adapter=new It(t,e,r,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{}),this.adapter.iterate(((t,e,r)=>{e.id="accessor_"+r}),"accessors"),this.adapter.iterate(((t,e,r)=>{e.id="image_"+r}),"images"))}Y(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(r=t.children[0])&&isFinite(r)||function(t){return!st(t)&&("string"==typeof t||null!==t.constructor&&t.constructor===String)}(t.children[0])))return t;const n=t.children.map((t=>{const r=e[t];return r.nodeIndex=t,this.Y(r,e)}));t.children=n}var r;return t}H(t){return this.Z(t).then((t=>{const e=this.scenes=[];let r;for(const e in t)t[e]=this.Y(t[e],t),t[e].nodeIndex=Number(e)?Number(e):e;this.adapter.iterate(((n,i,s)=>{const o={};i.name&&(o.name=i.name),i.nodes&&(o.nodes=i.nodes.map((e=>t[e]))),this.gltf.scene===n&&(r=s),e.push(o)}),"scenes");const n={asset:this.gltf.asset,scene:r,scenes:e,nodes:t,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins};if(this.gltf.extensions&&(n.extensions=this.gltf.extensions),1===this.version){const t=this.adapter.I(this.gltf.materials);n.materials=t}return n}))}Z(t){return this.W(t).then((()=>{const t=this.nodes={};return this.adapter.iterate(((e,r)=>{const n=this.adapter.createNode(r,this.meshes,this.skins);t[e]=n}),"nodes"),t}))}j(){this.skins=[];const t=[];return this.adapter.iterate(((e,r,n)=>{t.push(this.K(r).then((t=>{t.index=n,this.skins.push(t)})))}),"skins"),t}K(t){const e=t.inverseBindMatrices;return this.adapter.accessor.m("inverseBindMatrices",e).then((e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t)))}V(){const t=this.gltf.animations;return ot(t)?this.adapter.getAnimations(t):null}W(t){this.meshes={};let e=[];return this.adapter.iterate(((r,n,i)=>{e.push(this.q(n,t).then((t=>{t.index=i,this.meshes[r]=t})))}),"meshes"),e=e.concat(this.j()),Promise.all(e)}q(t,e){const r=t.primitives.map((t=>this.$(t,e))).filter((t=>!!t));return Promise.all(r).then((e=>{const r={};return at(r,t),r.primitives=e,r}))}X(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const r in t)e.push(this.adapter.S(r));return Promise.all(e).then((e=>{if(this.transferables)for(let t=0;t<e.length;t++){const r=e[t].image.array;if(e[t]&&r){let t;t=r instanceof ImageBitmap?r:r.buffer,t&&this.transferables.indexOf(t)<0&&this.transferables.push(t)}}if(!Array.isArray(t)){const r={},n=Object.keys(t);for(let t=0;t<e.length;t++)e[t]&&(r[n[t]]=e[t]);return r}return e}))}$(t,e){let r;const n=[],i=t.extensions;if(ot(t.targets))for(let e=0;e<t.targets.length;e++){const r=t.targets[e];for(const t in r){const i=this.adapter.accessor.m(`morphTargets_${t}_${e}`,r[t]);i&&n.push(i)}}if(i&&i.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:s,attributes:o}=i.KHR_draco_mesh_compression,a=this.gltf.bufferViews[s],c=this.F.p(a).then((r=>{const{buffer:n,byteOffset:i}=r;let{byteOffset:s,byteLength:c}=a;s||(s=0);const l=new DataView(n,i+s,c),f={attributes:o,useUniqueIDs:!1,skipAttributeTransform:e.skipAttributeTransform};return t(l,f).then((t=>{const e=Object.values(t.attributes);return t.indices&&e.push(t.indices),e}))}));n.push(c),r=Promise.all(n)}else{const e=t.attributes;for(const t in e){const r=this.adapter.accessor.m(t,e[t]);r&&n.push(r)}if(ot(t.indices)){const e=this.adapter.accessor.m("indices",t.indices);e&&n.push(e)}r=Promise.all(n)}return r.then((e=>{if(i&&i.KHR_draco_mesh_compression){const r=t.targets?t.targets.length:0;e[r]=e[r].concat(e.slice(0,r)),e=e[r]}let r,n;const s={attributes:e.reduce(((t,e)=>{if("indices"===e.name)r=e;else if(e.name.indexOf("morphTargets_")>-1)n=n||{},n[e.name.slice(13)]=e;else{if(!("POSITION"!==e.name||e.min&&e.max)){const t=[1/0,1/0,1/0],r=[-1/0,-1/0,-1/0],{itemSize:n,array:i}=e,s=i.length/n;for(let e=0;e<s;e++)for(let s=0;s<n;s++){const o=e*n+s;i[o]<t[s]&&(t[s]=i[o]),i[o]>r[s]&&(r[s]=i[o])}if(e.quantization){const n=e.quantization,i=n.range/(1<<n.quantizationBits),s=n.minValues;Z(t,t,i),z(t,t,s),Z(r,r,i),z(r,r,s)}e.min=t,e.max=r}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 r&&(s.indices=r),n&&(s.morphTargets=n),s.mode=ot(t.mode)?t.mode:4,ot(t.extras)&&(s.extras=t.extras),s}))}}function Gt(t,e){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!Dt)return void e(new Error("There is no canvas to draw image!"));Dt.width=r.width,Dt.height=r.height;const t=Dt.getContext("2d");t.drawImage(r,0,0,r.width,r.height);const n=t.getImageData(0,0,r.width,r.height),i={width:r.width,height:r.height,data:new Uint8Array(n.data)};e(null,i)},r.onerror=function(t){e(t)},r.src=t}let kt,Ht;function Vt(t,e){kt||(kt=new OffscreenCanvas(2,2),Ht=kt.getContext("2d")),fetch(t).then((t=>t.arrayBuffer())).then((t=>{const e=new Blob([new Uint8Array(t)]);return createImageBitmap(e)})).then((t=>{let{width:r,height:n}=t;zt(r)||(r=Xt(r)),zt(n)||(n=Xt(n));const i=this.options.maxTextureSize;i&&(r=Math.min(i,r),n=Math.min(i,n)),kt.width=r,kt.height=n,Ht.drawImage(t,0,0,r,n),t.close();const s=Ht.getImageData(0,0,r,n);e(null,{width:r,height:n,data:new Uint8Array(s.data)})})).catch((t=>{console.warn(t),e(t)}))}function zt(t){return 0==(t&t-1)&&0!==t}function Xt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}const Yt="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,r){let n=null;e&&e.arraybuffer&&(n=[e.arraybuffer]);const i={mapId:this.mapId,layerId:t,command:"loadTile",params:e};this.send(i,n,r)}abortTileLoading(t,e,r){const n={mapId:this.mapId,layerId:t,command:"abortTileLoading",params:{url:e}};this.broadcast(n,null,r)}addLayer(t,e,r){const n={actorId:this.actorId,mapId:this.mapId,layerId:t,command:"addLayer",params:{options:e}};this.broadcast(n,null,r)}removeLayer(t,e){const r={mapId:this.mapId,layerId:t,command:"removeLayer"};this.broadcast(r,null,e)}requestImage({url:t},e){const r=new Image;r.onload=()=>{if(!this.isActive())return;if(!Yt)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if(Wt(t.width)&&Wt(t.height))return t;let e=t.width,r=t.height;Wt(e)||(e=jt(e));Wt(r)||(r=jt(r));const n=document.createElement("canvas");n.width=e,n.height=r,n.getContext("2d").drawImage(t,0,0,e,r);const i=t.src,s=i.lastIndexOf("/")+1,o=i.substring(s);return console.warn(`Texture(${o})'s size is not power of two, resize from (${t.width}, ${t.height}) to (${e}, ${r})`),n}(r);Yt.width=t.width,Yt.height=t.height;const n=Yt.getContext("2d");n.drawImage(t,0,0,t.width,t.height);const i=n.getImageData(0,0,t.width,t.height),s={width:t.width,height:t.height,data:new Uint8Array(i.data)};e(null,s,[s.data.buffer])},r.onerror=function(t){e(t)},r.src=t}}function Wt(t){return 0==(t&t-1)&&0!==t}function jt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}class Kt{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 r=this.data.get(t);r&&r.node&&r.node.memorySize&&(this.currentSize-=r.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 r=this.data.keys();for(let n of r)t[e++]=n;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 r of e){const e=r&&r.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t){const e=this.data.values();for(const r of e)r.current=t}}function qt(t,e){if(t.scenes&&t.scenes.length)for(let r=0,n=t.scenes.length;r<n;r++){const n=t.scenes[r].nodes;for(let r=0,i=n.length;r<i;r++){const i=[];$t(n[r],i,t,e)}}}function $t(t,e,r,n){if(t.matrix&&e.push(t.matrix),t.children&&t.children.length)for(let i=0,s=t.children.length;i<s;i++)$t(t.children[i],e,r,n);if(void 0!==t.mesh){const i=t.mesh,s=r.meshes[i];if(s){const t=e.slice(0),o=s.primitives;for(let e=0,s=o.length;e<s;e++){const s=o[e];s&&(s.matrices=t,n(s,i,e,r))}}}}function Jt(t,e,r){let{componentType:n,byteOffset:i,byteStride:s,itemSize:o}=e;const a=e.array.buffer,c=n?Ft.getTypedArrayCtor(n):e.array.constructor;if(i=void 0===i?e.array.byteOffset:i,s=s||0,!s||s===o*c.BYTES_PER_ELEMENT&&i%c.BYTES_PER_ELEMENT==0){const e=new c(a,i+r*o*c.BYTES_PER_ELEMENT,o);return t.set(e),t}s||(s=o*c.BYTES_PER_ELEMENT);const l=new Uint8Array(a,s*r+i,o*c.BYTES_PER_ELEMENT);return new Uint8Array(t.buffer).set(l),t}function Qt(t,e,r,n){t[4*e]=r[n],t[4*e+1]=r[n+4],t[4*e+2]=r[n+8],t[4*e+3]=r[n+12]}const te=new Array(3),ee=new Array(3),re=[40680631590769,40680631590769,40408299984661.445];function ne(t,e,r,n){const i=re,s=Math.cos(r);te[0]=s*Math.cos(e),te[1]=s*Math.sin(e),te[2]=Math.sin(r),_e(te,te),Y(ee,i,te);const o=Math.sqrt(j(te,ee));var a,c,l;return c=ee,l=o,(a=ee)[0]=c[0]/l,a[1]=c[1]/l,a[2]=c[2]/l,Z(te,te,n),z(t,ee,te)}const ie=[1/6378137,1/6378137,1/6356752.314245179],se=[1/40680631590769,1/40680631590769,1/40408299984661.445],oe=new Array(3),ae=new Array(3),ce=new Array(3);function le(t,e){const r=se,n=function(t,e,r,n,i){const s=e[0],o=e[1],a=e[2],c=r[0],l=r[1],f=r[2],u=s*s*c*c,h=o*o*l*l,_=a*a*f*f,d=u+h+_,E=Math.sqrt(1/d),T=Z(fe,e,E);if(d<i)return isFinite(E)?T:void 0;const m=n[0],A=n[1],p=n[2],y=ue;y[0]=T[0]*m*2,y[1]=T[1]*A*2,y[2]=T[2]*p*2;let g,R,b,I,N,S,w,M,O,v,C,x=(1-E)*he(e)/(.5*he(y)),U=0;do{x-=U,b=1/(1+x*m),I=1/(1+x*A),N=1/(1+x*p),S=b*b,w=I*I,M=N*N,O=S*b,v=w*I,C=M*N,g=u*S+h*w+_*M-1,R=u*O*m+h*v*A+_*C*p;U=g/(-2*R)}while(Math.abs(g)>1e-12);return t[0]=s*b,t[1]=o*I,t[2]=a*N,t}(oe,e,ie,r,.1);let i=$(ae,n,r);i=_e(i,i);const s=q(ce,e,n),o=Math.atan2(i[1],i[0]),a=Math.asin(i[2]),c=N(j(s,e))*he(s);return t[0]=b(o),t[1]=b(a),t[2]=c,t}const fe=new Array(3),ue=new Array(3);function he(t){return G(t)}function _e(t,e){const r=e[0],n=e[1],i=e[2];let s=r*r+n*n+i*i;return s>0&&(s=Math.sqrt(s),t[0]=e[0]/s,t[1]=e[1]/s,t[2]=e[2]/s),t}function de(t,e){return Y(e,t,se),W(e,e)}function Ee(t,e){var r=t[0],n=t[1],i=Math.cos(n),s=i*Math.cos(r),o=i*Math.sin(r),a=Math.sin(n);return e.x=s,e.y=o,e.z=a,W(e,e)}var Te=Object.freeze({__proto__:null,radianToCartesian3:ne,cartesian3ToDegree:le,normalizeCartesian:_e,geodeticSurfaceNormal:de,geodeticSurfaceNormalCartographic:Ee});function me(t,e,r,n){r=r||0,n=n||r;var i=Math.abs(t-e);return i<=n||i<=r*Math.max(Math.abs(t),Math.abs(e))}function Ae(t,e){let r="";for(let n=0;n<4;n++){const i=t.getUint8(e+n);r+=String.fromCharCode(i)}return r}const pe="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function ye(t,e,r){const n=new Uint8Array(t,e,r);return pe?JSON.parse(pe.decode(n)):JSON.parse(w(n))}function ge(t,e,r){const n=new Uint8Array(t,e,r);return pe?JSON.parse(pe.decode(n)):JSON.parse(w(n))}function Re(t,e,r){return{offset:e,byteLength:r}}function be(t,e,r,n){const{byteOffset:i,componentType:s,type:o}=t,{ctor:a,type:c}=function(t){return Se[t]}(s),l=function(t){if(!t)return 1;return Ne[t]}(o);return{byteStride:0,byteOffset:i+r,itemSize:l,count:n*l,componentType:c,array:new a(e,r+i,n*l)}}function Ie(t,e,r,n){t.componentType||(t.componentType="UNSIGNED_SHORT");const i=be(t,e,r,n);return i.array.buffer.byteLength!==e.byteLength&&(i.array=i.array.slice()),i}const Ne={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const Se={"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 we(t){for(let e in Se)if(t===Se[e].ctor)return Se[e].type;throw new Error("unrecognized ctor:"+t)}function Me(t,e,r,n){const i=t,s=e.length/3;for(let t=0;t<s;t++)i[3*t]=e[3*t]/65535*n[0]+r[0],i[3*t+1]=e[3*t+1]/65535*n[1]+r[1],i[3*t+2]=e[3*t+2]/65535*n[2]+r[2];return i}function Oe(t,e,r){let n=t.getUint32(12,!0),i=t.getUint32(16,!0),s=t.getUint32(20,!0),o=t.getUint32(24,!0);const a=t.buffer;let c,l,f={},u={};n>0&&(f=ye(a,e,n),e+=n),i>0&&(c=function(t,e,r){return{offset:e,byteLength:r}}(0,e,i),e+=i),s>0&&(u=ge(a,e,s),e+=s);const h=Re(0,e,o);return l=a.slice(h.offset,h.offset+h.byteLength),r.push(l),{featureTable:f,featureTableBin:c,batchTable:u,batchTableBin:l}}var ve={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Ce={},xe={east:[],north:[],up:[],west:[],south:[],down:[]},Ue=[],Be=[],Pe=[];const Le=[0,0,0];function De(t,e,r){return r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=t[3],r[4]=t[4],r[5]=t[5],r[6]=t[6],r[7]=t[7],r[8]=t[8],r[9]=t[9],r[10]=t[10],r[11]=t[11],r[12]=e[0],r[13]=e[1],r[14]=e[2],r[15]=t[15],r}const Fe=(Ve={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"}}[Ge="east"][ke="north"],Ce[ze=Ge+ke]?He=Ce[ze]:(He=function(t,e,r){if(function(t,e){var r=t[0],n=t[1],i=t[2],s=e[0],o=e[1],a=e[2];return Math.abs(r-s)<=1e-6*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(n-o)<=1e-6*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=1e-6*Math.max(1,Math.abs(i),Math.abs(a))}(t,Le))H(Ue,ve[Ge]),H(Be,ve[ke]),H(Pe,ve[Ve]);else if(me(t[0],0,1e-14)&&me(t[1],0,1e-14)){var n=N(t[2]);H(Ue,ve[Ge]),"east"!==Ge&&"west"!==Ge&&Z(Ue,Ue,n),H(Be,ve[ke]),"east"!==ke&&"west"!==ke&&Z(Be,Be,n),H(Pe,ve[Ve]),"east"!==Ve&&"west"!==Ve&&Z(Pe,Pe,n)}else{de(t,xe.up);var i=xe.up,s=xe.east;s[0]=-t[1],s[1]=t[0],s[2]=0,W(xe.east,s),K(xe.north,i,s),Z(xe.down,xe.up,-1),Z(xe.west,xe.east,-1),Z(xe.south,xe.north,-1),Ue=xe[Ge],Be=xe[ke],Pe=xe[Ve]}return r[0]=Ue[0],r[1]=Ue[1],r[2]=Ue[2],r[3]=0,r[4]=Be[0],r[5]=Be[1],r[6]=Be[2],r[7]=0,r[8]=Pe[0],r[9]=Pe[1],r[10]=Pe[2],r[11]=0,r[12]=t[0],r[13]=t[1],r[14]=t[2],r[15]=1,r},Ce[ze]=He),He);var Ge,ke,He,Ve,ze;const Xe=[],Ye=[],Ze=[],We=[],je=[],Ke=[],qe=[],$e={x:0,y:0},Je={x:0,y:0},Qe=Math.PI/180;const tr={"programs":[{"attributes":["aPosition","instanceId","batchId","aTexCoord0","aTexCoord1","aNormal","aColor","uv2","uv3","uv4","secondary_colour","uv6"],"fragmentShader":1,"vertexShader":0}],"shaders":[{"type":35633,"content":"#include <gl2_vert>\n\nuniform mat4 czm_modelViewProjection;\n\nuniform mat4 czm_modelView;\n\nuniform mat3 czm_normal;\n\n\n\nattribute vec4 aPosition;\n\n\n\n#ifdef VertexColor\n\n attribute vec4 aColor;\n\n#endif\n\n#ifdef VertexNormal\n\n attribute vec3 aNormal;\n\n#endif\n\n#ifdef Instance\n\n attribute float instanceId;\n\n#else\n\n attribute float batchId;\n\n#endif\n\n\n\n#ifdef TexCoord\n\n attribute vec4 aTexCoord0;\n\n varying vec4 vTexCoord;\n\n uniform mat4 uTexMatrix;\n\n#ifdef COMPUTE_TEXCOORD\n\n uniform float uTexture0Width;\n\n varying vec4 vTexMatrix;\n\n varying vec4 vTexCoordTransform;\n\n varying vec2 vIsRGBA;\n\n#endif\n\n#endif\n\n\n\n#ifdef TexCoord2\n\n attribute vec4 aTexCoord1;\n\n uniform float uTexture1Width;\n\n varying vec4 vTexMatrix2;\n\n#endif\n\n#ifdef InstanceBim\n\n attribute vec4 uv2;\n\n attribute vec4 uv3;\n\n attribute vec4 uv4;\n\n attribute vec4 secondary_colour;\n\n attribute vec4 uv6;\n\n#endif\n\n\n\n uniform vec4 uFillForeColor;\n\n uniform vec4 uSelectedColor;\n\n varying vec4 vSecondColor;\n\n varying vec4 vPositionMC;\n\n varying vec3 vPositionEC;\n\n#ifdef VertexNormal\n\n varying vec3 vNormalEC;\n\n#endif\n\n varying vec4 vColor;\n\n\n\n const float SHIFT_LEFT8 = 256.0;\n\n const float SHIFT_RIGHT8 = 1.0 / 256.0;\n\n const float SHIFT_RIGHT4 = 1.0 / 16.0;\n\n const float SHIFT_LEFT4 = 16.0;\n\n void getTextureMatrixFromZValue(in float nZ, inout float XTran, inout float YTran, inout float scale, inout float isRGBA)\n\n {\n\n if(nZ <= 0.0)\n\n {\n\n return;\n\n }\n\n float nDel8 = floor(nZ * SHIFT_RIGHT8);\n\n float nDel16 = floor(nDel8 * SHIFT_RIGHT8);\n\n float nDel20 = floor(nDel16 * SHIFT_RIGHT4);\n\n isRGBA = floor(nDel20);\n\n YTran = nZ - nDel8 * SHIFT_LEFT8;\n\n XTran = nDel8 - nDel16 * SHIFT_LEFT8;\n\n float nLevel = nDel16 - nDel20 * SHIFT_LEFT4;\n\n scale = 1.0 / pow(2.0, nLevel);\n\n }\n\n\n\n void operation(vec4 operationType, vec4 color, vec4 selectedColor, inout vec4 vertexColor)\n\n {\n\n float right_2 = operationType.x * 0.5;\n\n float right_4 = right_2 * 0.5;\n\n float right_8 = right_4 * 0.5;\n\n float right_16 = right_8 * 0.5;\n\n float isSetColor = fract(right_2);\n\n if(isSetColor > 0.1)\n\n {\n\n vertexColor *= color;\n\n }\n\n float isPicked = fract(floor(right_2)* 0.5);\n\n if(isPicked > 0.1)\n\n {\n\n vertexColor *= selectedColor;\n\n }\n\n float isHide = fract(floor(right_4)* 0.5);\n\n if(isHide > 0.1)\n\n {\n\n vertexColor.a = 0.0;\n\n }\n\n }\n\n\n\n void main()\n\n {\n\n #ifdef TexCoord\n\n vTexCoord.xy = aTexCoord0.xy;\n\n #ifdef COMPUTE_TEXCOORD\n\n vTexMatrix = vec4(0.0,0.0,1.0,0.0);\n\n vIsRGBA.x = 0.0;\n\n vTexCoordTransform.x = aTexCoord0.z;\n\n if(vTexCoordTransform.x < -90000.0)\n\n {\n\n vTexMatrix.z = -1.0;\n\n }\n\n getTextureMatrixFromZValue(floor(vTexCoordTransform.x), vTexMatrix.x, vTexMatrix.y, vTexMatrix.z, vIsRGBA.x);\n\n vTexMatrix.w = log2(uTexture0Width * vTexMatrix.z);\n\n #endif\n\n #endif\n\n\n\n #ifdef TexCoord2\n\n vTexCoord.zw = aTexCoord1.xy;\n\n vTexMatrix2 = vec4(0.0,0.0,1.0,0.0);\n\n vIsRGBA.y = 0.0;\n\n vTexCoordTransform.y = aTexCoord1.z;\n\n if(vTexCoordTransform.y < -90000.0)\n\n {\n\n vTexMatrix2.z = -1.0;\n\n }\n\n getTextureMatrixFromZValue(floor(vTexCoordTransform.y), vTexMatrix2.x, vTexMatrix2.y, vTexMatrix2.z, vIsRGBA.y);\n\n vTexMatrix2.w = log2(uTexture1Width * vTexMatrix.z);\n\n #endif\n\n\n\n vec4 vertexPos = aPosition;\n\n vec4 vertexColor = uFillForeColor;\n\n#ifdef VertexColor\n\n vertexColor *= aColor / 255.0;\n\n#endif\n\n#ifdef VertexNormal\n\n vec3 normal = aNormal;\n\n#endif\n\n #ifdef InstanceBim\n\n mat4 worldMatrix;\n\n worldMatrix[0] = uv2;\n\n worldMatrix[1] = uv3;\n\n worldMatrix[2] = uv4;\n\n worldMatrix[3] = vec4(0, 0, 0, 1);\n\n vertexPos = vec4(vertexPos.xyz,1.0) * worldMatrix;\n\n vertexColor *= secondary_colour;\n\n #endif\n\n\n\n\n\n #ifdef Instance\n\n float index = instanceId;\n\n #else\n\n float index = batchId;\n\n #endif\n\n vec4 positionMC = vec4(vertexPos.xyz, 1.0);\n\n vColor = vertexColor;\n\n #ifdef VertexNormal\n\n vNormalEC = czm_normal * normal;\n\n #endif\n\n vPositionMC = positionMC;\n\n vPositionEC = (czm_modelView * positionMC).xyz;\n\n gl_Position = czm_modelViewProjection * vec4(vertexPos.xyz, 1.0);\n\n }\n\n"},{"type":35632,"content":"#ifdef GL_OES_standard_derivatives\n\n #extension GL_OES_standard_derivatives : enable\n\n #define support_standard_derivatives 1\n\n#endif\n\n#ifdef GL_EXT_shader_texture_lod\n\n #extension GL_EXT_shader_texture_lod : enable\n\n #define support_shader_texture_lod 1\n\n#endif\n\n\n\nprecision highp float;\n\n\n\n#include <gl2_frag>\n\n\n\n#if __VERSION__ == 300\n\n #define support_standard_derivatives 1\n\n #define support_shader_texture_lod 1\n\n#endif\n\n\n\n uniform vec3 czm_lightDirectionEC;\n\n uniform vec4 uDiffuseColor;\n\n#ifdef TexCoord\n\n varying vec4 vTexCoord;\n\n#ifdef COMPUTE_TEXCOORD\n\n uniform sampler2D uTexture;\n\n uniform highp float uTexture0Width;\n\n varying vec4 vTexCoordTransform;\n\n varying vec4 vTexMatrix;\n\n varying vec2 vIsRGBA;\n\n#endif\n\n#endif\n\n\n\n varying vec4 vColor;\n\n varying vec4 vPositionMC;\n\n varying vec3 vPositionEC;\n\n#ifdef VertexNormal\n\n varying vec3 vNormalEC;\n\n#endif\n\n#ifdef TexCoord2\n\n uniform sampler2D uTexture2;\n\n uniform float uTexture1Width;\n\n varying vec4 vTexMatrix2;\n\n#endif\n\n#ifdef COMPUTE_TEXCOORD\n\n void calculateMipLevel(in vec2 inTexCoord, in float vecTile, in float fMaxMip, inout float mipLevel)\n\n {\n\n vec2 dx = dFdx(inTexCoord * vecTile);\n\n vec2 dy = dFdy(inTexCoord * vecTile);\n\n float dotX = dot(dx, dx);\n\n float dotY = dot(dy, dy);\n\n float dMax = max(dotX, dotY);\n\n float dMin = min(dotX, dotY);\n\n float offset = (dMax - dMin) / (dMax + dMin);\n\n offset = clamp(offset, 0.0, 1.0);\n\n float d = dMax * (1.0 - offset) + dMin * offset;\n\n mipLevel = 0.5 * log2(d);\n\n mipLevel = clamp(mipLevel, 0.0, fMaxMip - 1.62);\n\n }\n\n\n\n void calculateTexCoord(in vec3 inTexCoord, in float scale, in float XTran, in float YTran, in float fTile, in float mipLevel, inout vec2 outTexCoord)\n\n {\n\n if(inTexCoord.z < -9000.0)\n\n {\n\n outTexCoord = inTexCoord.xy;\n\n }\n\n else\n\n {\n\n vec2 fTexCoord = fract(inTexCoord.xy);\n\n float offset = 1.0 * pow(2.0, mipLevel) / fTile;\n\n fTexCoord = clamp(fTexCoord, offset, 1.0 - offset);\n\n outTexCoord.x = (fTexCoord.x + XTran) * scale;\n\n outTexCoord.y = (fTexCoord.y + YTran) * scale;\n\n }\n\n }\n\n\n\n vec4 getTexColorForS3M(sampler2D curTexture, vec3 oriTexCoord, float texTileWidth, float fMaxMipLev, float fTexCoordScale, vec2 vecTexCoordTranslate, float isRGBA)\n\n {\n\n vec4 color = vec4(1.0);\n\n float mipLevel = 0.0;\n\n #ifdef support_standard_derivatives\n\n calculateMipLevel(oriTexCoord.xy, texTileWidth, fMaxMipLev, mipLevel);\n\n #endif\n\n vec2 realTexCoord;\n\n calculateTexCoord(oriTexCoord, fTexCoordScale, vecTexCoordTranslate.x, vecTexCoordTranslate.y, texTileWidth, mipLevel, realTexCoord);\n\n if(isRGBA > 0.5)\n\n {\n\n vec2 rgbTexCoord;\n\n rgbTexCoord.x = (realTexCoord.x + vecTexCoordTranslate.x * fTexCoordScale) * 0.5;\n\n rgbTexCoord.y = (realTexCoord.y + vecTexCoordTranslate.y * fTexCoordScale) * 0.5;\n\n color = texture2D(curTexture, rgbTexCoord.xy, -10.0);\n\n vec2 vecAlphaTexCoord;\n\n vecAlphaTexCoord.x = rgbTexCoord.x;\n\n vecAlphaTexCoord.y = rgbTexCoord.y + fTexCoordScale * 0.5;\n\n color.a = texture2D(curTexture, vecAlphaTexCoord.xy, -10.0).r;\n\n }\n\n else\n\n {\n\n if(oriTexCoord.z < -9000.0)\n\n {\n\n color = texture2D(curTexture, realTexCoord.xy);\n\n }\n\n else\n\n {\n\n #ifdef support_shader_texture_lod\n\n color = texture2DLodEXT(curTexture, realTexCoord.xy, mipLevel);\n\n #else\n\n color = texture2D(curTexture, realTexCoord.xy, mipLevel);\n\n #endif\n\n }\n\n }\n\n\n\n return color;\n\n }\n\n\n\n vec4 getTextureColor()\n\n {\n\n if(vTexMatrix.z < 0.0)\n\n {\n\n return vec4(1.0);\n\n }\n\n float texTileWidth0 = vTexMatrix.z * uTexture0Width;\n\n vec3 realTexCoord = vec3(vTexCoord.xy, vTexCoordTransform.x);\n\n vec4 FColor = getTexColorForS3M(uTexture, realTexCoord, texTileWidth0, vTexMatrix.w, vTexMatrix.z, vTexMatrix.xy, vIsRGBA.x);\n\n #ifdef TexCoord2\n\n float texTileWidth1 = vTexMatrix2.z * uTexture1Width;\n\n realTexCoord = vec3(vTexCoord.zw, vTexCoordTransform.y);\n\n vec4 SColor = getTexColorForS3M(uTexture2, realTexCoord, texTileWidth1, vTexMatrix2.w, vTexMatrix2.z, vTexMatrix2.xy, vIsRGBA.y);\n\n SColor.r = clamp(SColor.r, 0.0, 1.0);\n\n SColor.g = clamp(SColor.g, 0.0, 1.0);\n\n SColor.b = clamp(SColor.b, 0.0, 1.0);\n\n return FColor * SColor;\n\n #else\n\n return FColor;\n\n #endif\n\n }\n\n#endif\n\n vec4 SRGBtoLINEAR4(vec4 srgbIn)\n\n {\n\n #ifndef HDR\n\n vec3 linearOut = pow(srgbIn.rgb, vec3(2.2));\n\n return vec4(linearOut, srgbIn.a);\n\n #else\n\n return srgbIn;\n\n #endif\n\n }\n\n vec3 LINEARtoSRGB(vec3 linearIn)\n\n {\n\n #ifndef HDR\n\n return pow(linearIn, vec3(1.0/2.2));\n\n #else\n\n return linearIn;\n\n #endif\n\n }\n\n\n\n vec3 computeNormal(in vec3 oriVertex)\n\n {\n\n vec3 normal = cross(vec3(dFdx(oriVertex.x), dFdx(oriVertex.y), dFdx(oriVertex.z)), vec3(dFdy(oriVertex.x), dFdy(oriVertex.y), dFdy(oriVertex.z)));\n\n normal = normalize(normal);\n\n return normal;\n\n }\n\n\n\n void main()\n\n {\n\n if(vColor.a < 0.1)\n\n {\n\n discard;\n\n }\n\n vec4 baseColorWithAlpha = vColor;\n\n #ifdef COMPUTE_TEXCOORD\n\n baseColorWithAlpha *= SRGBtoLINEAR4(getTextureColor());\n\n #endif\n\n\n\n if(baseColorWithAlpha.a < 0.1)\n\n {\n\n discard;\n\n }\n\n vec3 normal = vec3(0.0);\n\n #ifdef VertexNormal\n\n normal = normalize(vNormalEC);\n\n #endif\n\n normal = length(normal) > 0.1 ? normal : computeNormal(vPositionMC.xyz);\n\n vec3 color = baseColorWithAlpha.rgb;\n\n vec3 dirVectorEC = normalize(czm_lightDirectionEC);\n\n float dotProduct = dot( normal, dirVectorEC );\n\n float dirDiffuseWeight = max( dotProduct, 0.0 );\n\n dirDiffuseWeight = dirDiffuseWeight * 0.5 + 0.5;\n\n color += color * uDiffuseColor.rgb * dirDiffuseWeight;\n\n #ifdef TexCoord\n\n color = LINEARtoSRGB(color);\n\n #endif\n\n glFragColor = vec4(color, baseColorWithAlpha.a);\n\n#if __VERSION__ == 100\n\n gl_FragColor = glFragColor;\n\n#endif\n\n }\n\n"}],"techniques":[{"attributes":{"aPosition":{"semantic":"POSITION","type":35666},"instanceId":{"semantic":"instanceId","type":5126},"batchId":{"semantic":"_BATCHID","type":5126},"aTexCoord0":{"semantic":"TEXCOORD_0","type":35664},"aTexCoord1":{"semantic":"aTexCoord1","type":35666},"aNormal":{"semantic":"aNormal","type":35665},"aColor":{"semantic":"COLOR_0","type":35666},"uv2":{"semantic":"uv2","type":35666},"uv3":{"semantic":"uv3","type":35666},"uv4":{"semantic":"uv4","type":35666},"secondary_colour":{"semantic":"secondary_colour","type":35666},"uv6":{"semantic":"uv6","type":35666}},"program":0,"uniforms":{"czm_modelView":{"type":35676,"semantic":"MODELVIEW"},"czm_normal":{"type":35675,"semantic":"MODELINVERSETRANSPOSE"},"czm_modelViewProjection":{"type":35676,"semantic":"MODELVIEWPROJECTION"},"uTexMatrix":{"type":35676},"uTexture0Width":{"type":5126},"uFillForeColor":{"type":35666},"uSelectedColor":{"type":35666},"uDiffuseColor":{"type":35666},"uTexture":{"type":35678},"uTexture2":{"type":35678},"uTexture1Width":{"type":5126}}}]},{getTextureMagFilter:er,getTextureMinFilter:rr,getTextureWrap:nr,getMaterialType:ir,getMaterialFormat:sr,getPrimitive:or,getUniqueREGLBuffer:ar}=r.REGLHelper,cr=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],lr=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:fr,logoutIBLResOnCanvas:ur,getIBLResOnCanvas:hr,getPBRUniforms:_r}=r.pbr.PBRUtils,dr={factor:0,units:0},Er={specularStrength:0,materialShininess:1},Tr=[1,1,1],mr=n.identity([]),Ar=t=>t.material instanceof r.PhongMaterial,pr=t=>t.material instanceof r.pbr.StandardMaterial,yr=[!0,!0,!0,!0],gr=[],Rr=new t.Coordinate(0,0),br=[],Ir=[],Nr={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"};class Sr{constructor(e,n){this.J=n,this.tt=n.getRenderer().canvas,this.et=new t.SpatialReference,this.rt=e,this.nt=new r.Renderer(e),this.it={},this.st={},this.ot={},this.at={},this.ct={},this.lt={},this.ft={},this.ut=new r.Scene,this.ht=new r.Scene,this._t=new r.Scene,this.dt=new r.Scene,this.Et=new r.ResourceLoader(e.texture(2)),this.Tt=this.At.bind(this),this.yt=new r.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.gt(),this.Rt=new r.KHRTechniquesWebglManager(this.rt,this.bt(),this.Et)}getI3DMMeshes(){return this.ct}getPNTSMeshes(){return this.at}getB3DMMeshes(){return this.ot}getPaintedMeshes(){return this.It}getMap(){return this.J.getMap()}paint(t,e,r,n){const i=this.getMap();if(!t.length||!i)return;const s=this.Nt(),o=i.projViewMatrix,a=this.J.options.services,c=[],l=[];let f=[];const u=[],h=[];for(let r=0,n=t.length;r<n;r++){const n=t[r].data.node;let i=this.St(n);if(!i)continue;this.lt[n.id]&&(i=this.lt[n.id],i=O(i));let d=a[n.wt].polygonOffset||dr;y(d)&&(d=d());const E=a[n.wt].ambientLight;Array.isArray(i)||(c[0]=i,i=c);for(let a=0,c=i.length;a<c;a++){if(i[a].getBoundingBox&&!_(o,i[a].getBoundingBox()))continue;const c=i[a].properties.magic;"b3dm"===c?f.push(i[a]):"pnts"===c?u.push(i[a]):"i3dm"===c&&h.push(i[a]),i[a].properties.level=t[r].selectionDepth,i[a].properties.polygonOffset=d,Object.prototype.hasOwnProperty.call(i[a].uniforms,"ambientColor")||Object.defineProperty(i[a].uniforms,"ambientColor",{enumerable:!0,get:function(){return E||s.ambientColor}}),i[a].Mt=n,e[n.id]||l.push(i[a])}}let d=0;const E=this.Rt.getExcludeFilter();d+=this.Ot(this.vt,s,[r,Ar,E],n,l,f,h),d+=this.Ot(this.Ct,s,[r,pr,E],n,l,f,h),this.Rt.forEachShader(((t,e,i)=>{const s=this.Nt(i);d+=this.Ot(t,s,[r,e],n,l,f,h)})),this.ht.setMeshes(u);const T=this.xt();return d+=this.nt.render(this.Ut,T,this.ht,n&&n.fbo),this.It={pntsMeshes:u,i3dmMeshes:h,b3dmMeshes:f},d}Ot(t,e,r,n,i,s,o){t.filter=r.filter((t=>!!t)),e.debug=!1,this.ut.setMeshes(i),e.stencilEnable=!1,e.debug=!1,e.cullFace="back",e.colorMask=yr;let a=0;return this.ut.setMeshes(s),a+=this.nt.render(t,e,this.ut,n&&n.fbo),e.stencilEnable=!1,this._t.setMeshes(o),a+=this.nt.render(t,e,this._t,n&&n.fbo),a}Bt(t,e){return e.Mt.Pt-t.Mt.Pt}paintRegion(t,e,r,n,i){const s=this.getMap();if(!t.length&&!e.length)return;const o=s.projViewMatrix,a=[];for(let r=0,n=(t=t.concat(e)).length;r<n;r++){const e=t[r].node,n=this.Lt(e);n&&(n.getBoundingBox&&!_(o,n.getBoundingBox())||a.push(n))}this.Dt.filter=n,this.dt.setMeshes(a);const c=this.Ft(r);this.nt.render(this.Dt,c,this.dt,i&&i.fbo)}deleteTile(t){const e=t.node.id;this.Gt(e)}Gt(t){const e=this.st[t];e&&(e.geometry.dispose(),e.dispose(),delete this.st[t]);let r=this.ot[t]||this.at[t]||this.ct[t]||this.lt[t]||this.it[t];this.lt[t]?this.kt(t):r&&(this.Ht(r),delete this.ot[t],delete this.at[t],delete this.ct[t],delete this.it[t])}kt(t){let e=this.lt[t];e=O(e);for(let t=0;t<e.length;t++){const{id:r}=e[t].properties;this.Gt(r)}delete this.lt[t]}Ht(t){if(Array.isArray(t))for(let e=0,r=t.length;e<r;e++)this.Ht(t[e]);else{const e=t.geometry.properties.url;if(e){const t=this.ft[e];t&&(t.refCount--,t.refCount<=0&&(t.geometry.dispose(),t.material.dispose(),delete this.ft[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.J;ur(t.getRenderer().canvas,t.getMap());for(const t in this.lt)this.kt(t);this.lt={};for(const t in this.ot)this.Gt(t);this.ot={};for(const t in this.at)this.Gt(t);this.at={};for(const t in this.ct)this.Gt(t);this.ct={};for(const t in this.it)this.Gt(t);this.it={};for(const t in this.st)this.Gt(t);this.st={},this.vt&&(this.vt.dispose(),delete this.vt),this.Ct&&(this.Ct.dispose(),delete this.Ct),this.Ut&&(this.Ut.dispose(),delete this.Ut),this.Dt&&(this.Dt.dispose(),delete this.Dt),this.Rt.dispose()}Lt(e){if(!e.boundingVolume||!e.boundingVolume.region)return null;if(this.st[e.id])return this.st[e.id];const i=e.boundingVolume.region;let s=new t.Coordinate(b(i[0]),b(i[1])),o=new t.Coordinate(b(i[2]),b(i[3]));s=this.Vt(s),o=this.Vt(o);const a=s.add(o).zt(.5);s._sub(a),o._sub(a);const c=this.Xt(i[4],i[5]),l=c.x,f=c.y,u=[s.x,s.y,f,o.x,s.y,f,o.x,o.y,f,s.x,o.y,f,s.x,s.y,l,o.x,s.y,l,o.x,o.y,l,s.x,o.y,l],h=new r.Geometry({aPosition:u},[0,1,1,2,2,3,3,0,0,4,1,5,2,6,3,7,4,5,5,6,6,7,7,4],0,{primitive:"lines"});h.generateBuffers(this.rt);const _=new r.Mesh(h),d=n.identity([]);return _.setLocalTransform(n.translate(d,d,[a.x,a.y,0])),this.st[e.id]=_,_}St(t){return this.ot[t.id]||this.at[t.id]||this.ct[t.id]||this.lt[t.id]}has(t){return this.St(t)||this.it[t.id]}createPntsMesh(t,e,i,s){if(this.at[e]){const t=this.at[e];return console.warn(`pnts mesh with id(${e}) was already created.`),s(null,{id:e,mesh:t}),t}const{pnts:o,featureTable:a,rootIdx:c}=t,l=a.POINTS_LENGTH,f=new r.Geometry(o,null,l,{primitive:"points",positionAttribute:"POSITION"});f.generateBuffers(this.rt);const u={};o.POSITION?u.HAS_POSITION=1:o.POSITION_QUANTIZED&&(u.HAS_POSITION_QUANTIZED=1),o.RGB?u.HAS_RGB=1:o.RGBA?u.HAS_RGBA=1:o.RGB565&&(u.HAS_RGB565=1),(o.NORMAL||o.NORMAL_OCT16P)&&(u.HAS_NORMAL=1,o.NORMAL_OCT16P&&(u.HAS_NORMAL_OCT16P=1)),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map((t=>t/255)));const{rtcCenter:h,rtcCoord:_}=t,d=this.Yt(_),E=this.Zt(i,h,_);n.multiply(E,E,d);const T=this.J.options.services[c],m=new r.Mesh(f);return m.properties.magic="pnts",m.properties.id=e,m.properties.count=l,m.properties.batchTable=t.batchTable,m.properties.batchTableBin=t.batchTableBin,m.setDefines(u),Object.defineProperty(m.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:T&&T.pointColor||[1,1,1,1]}}),Object.defineProperty(m.uniforms,"pointSize",{enumerable:!0,get:function(){return T&&T.pointSize||2}}),Object.defineProperty(m.uniforms,"pointOpacity",{enumerable:!0,get:function(){return T&&T.pointOpacity||1}}),m.setLocalTransform(E),this.at[e]=m,s(null,{id:e,mesh:[m]}),[m]}createI3DMMesh(t,e,s,o){if(this.ct[e]){const t=this.ct[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.it[e]||o(null,{id:e,mesh:t}),t}const c=this.Wt(s.jt),{i3dm:l,featureTable:f,gltf:u,batchTable:h,batchTableBin:_,count:d}=t,E=f.INSTANCES_LENGTH,{rtcCenter:T,rtcCoord:m}=t,A=this.Yt(m),p=this.Zt(s,T,m),{POSITION:y,NORMAL_UP:g,NORMAL_RIGHT:R,SCALE:b,SCALE_NON_UNIFORM:I,INSTANCE_ROTATION:N}=l,S={"instance_vectorA":new Float32Array(4*E),"instance_vectorB":new Float32Array(4*E),"instance_vectorC":new Float32Array(4*E)},w=new Float32Array(3),O=new Float32Array(3),v=[],C=new Float32Array(1),x=new Float32Array(3),U=[],B=[],P=[],L=[],D=new Float32Array(9);!function(t,e){let{componentType:r,byteOffset:n,byteStride:i,count:s,itemSize:o}=t;const a=t.array.buffer,c=r?Ft.getTypedArrayCtor(r):t.array.constructor;if(n=void 0===n?t.array.byteOffset:n,i=i||0,s=s||t.array.length/o,(!i||i===o*c.BYTES_PER_ELEMENT)&&n%c.BYTES_PER_ELEMENT==0){const t=new c(a,n,s*o);for(let r=0;r<s*o;r+=o)e(new c(t.buffer,n+r*c.BYTES_PER_ELEMENT,o),r/o);return}const l=new Uint8Array(o*c.BYTES_PER_ELEMENT);i||(i=o*c.BYTES_PER_ELEMENT);for(let t=0;t<s;t++){const r=new Uint8Array(a,i*t+n,o*c.BYTES_PER_ELEMENT);l.set(r),e(new c(l.buffer),t),r.set(l)}}(y,((t,e)=>{g?(Jt(O,R,e),Jt(w,g,e),i.cross(v,O,w),i.normalize(v,v),M(U,O,0),M(U,w,1),M(U,v,2),a.fromMat3(B,U)):N?(Jt(D,N,e),a.fromMat3(B,D)):a.identity(B),b?(Jt(C,b,e),i.set(P,C[0],C[0],C[0])):I?(Jt(x,I,e),i.set(P,...x)):i.set(P,1,1,1),n.fromRotationTranslationScale(L,B,t,P),Qt(S.instance_vectorA,e,L,0),Qt(S.instance_vectorB,e,L,1),Qt(S.instance_vectorC,e,L,2)}));const F={};for(const t in S)F[t]={buffer:this.rt.buffer({dimension:S[t].length/E,data:S[t]}),divisor:1};const G=this.J.options.services[s.wt].shader||"phong";let k=0,H=!0;const V=[];return qt(u,((t,i,o,a)=>{let{geometry:l,material:f}=this.Kt(t,i,o,a,s,!0,G);f&&!f.isReady()&&(H=!1,k++);const u=new r.InstancedMesh(F,E,l,f);u.properties.magic="i3dm",u.properties.id=e,u.properties.count=d,u.properties.batchTable=h,u.properties.batchTableBin=_;const T=this.qt(t,l,f,s.wt,a),m=n.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)n.multiply(m,m,t.matrices[e]);n.multiply(m,c,m),u.setPositionMatrix(m),n.multiply(A,p,A),u.setLocalTransform(A),u.setDefines(T),u.properties.polygonOffset={offset:0,factor:0},V.push(u)})),H?(this.ct[e]=V,o(null,{id:e,mesh:V})):(this.it[e]={meshes:V,count:k},V.$t=o),V}createB3DMMesh(e,i,s,o){if(this.ot[i]||this.it[i]){const t=this.ot[i];return console.warn(`mesh with id(${i}) was already created.`),this.it[i]||o(null,{id:i,mesh:t}),t}const a=e.gltf.asset&&"i3s"===e.gltf.asset.generator;let c;if(s.maxExtent){const e=new t.Extent(s.maxExtent).convertTo((t=>this._pointToPrj(t)));c=[e.xmin,e.ymin,e.xmax,e.ymax]}const l=this.Wt(s.jt),f=e.gltf,{center:u,coord:h}=f.extensions.CESIUM_RTC,_=this.J.options.services[s.wt].heightOffset||0;let d;if(_&&h&&(h[2]+=_),a){const{i3sProjCenter:t}=f.extensions.CESIUM_RTC;d=this.Jt(t,s.wt)}else d=this.Yt(h,s.wt);const E=this.J.options.services[s.wt].shader||"phong",T=[];let m=0,A=!0;return qt(f,((t,o,f,_)=>{let{geometry:p,material:y}=this.Kt(t,o,f,_,s,!1,E);y&&!y.isReady()&&(A=!1,m++);const g=new r.Mesh(p,y);g.properties.magic="b3dm",g.properties.id=i,g.properties.batchTable=e.batchTable,g.properties.batchTableBin=e.batchTableBin,g.properties.count=e.featureTable.BATCH_LENGTH;const R=this.qt(t,p,y,s.wt,_);g.setDefines(R),c&&(R.USE_MAX_EXTENT=1,g.setUniform("maxPrjExtent",c));let b=n.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)n.multiply(b,b,t.matrices[e]);const I=a?mr:this.Zt(s,u,h);n.multiply(b,l,b),n.multiply(b,d,b),n.multiply(b,I,b),g.setLocalTransform(b),T.push(g)})),A?(this.ot[i]=T,o(null,{id:i,mesh:T})):(this.it[i]={meshes:T,count:m},T.$t=o),T}Zt(e,r,s){const o=this.getMap(),a=this.J.options.services[e.wt].heightOffset||0,c=new t.Coordinate(s),l=o.distanceToPointAtRes(100,0,o.getGLRes(),c).x/100;let f=e.matrix?n.copy([],e.matrix):n.identity([]);if(r){De(f,i.transformMat4(gr,r,f),f)}const u=function(t,e,r,n,i,s,o){e=H(Xe,e);const a=ne(Xe,e[0]*Qe,e[1]*Qe,e[2]),c=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}(Ye,r),l=n.ellipsoid;var f;f=0===J(c)?V(Ze,0,0,-6378137):le(Ze,c),$e.x=f[0],$e.y=f[1];const u=n.project($e,Je);We[0]=u.x/i,We[1]=u.y/i,We[2]=(f[2]+o)*s;const h=Fe(a,l,je),_=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],c=e[6],l=e[7],f=e[8],u=e[9],h=e[10],_=e[11],d=e[12],E=e[13],T=e[14],m=e[15],A=r*a-n*o,p=r*c-i*o,y=r*l-s*o,g=n*c-i*a,R=n*l-s*a,b=i*l-s*c,I=f*E-u*d,N=f*T-h*d,S=f*m-_*d,w=u*T-h*E,M=u*m-_*E,O=h*m-_*T,v=A*O-p*M+y*w+g*S-R*N+b*I;return v?(v=1/v,t[0]=(a*O-c*M+l*w)*v,t[1]=(i*M-n*O-s*w)*v,t[2]=(E*b-T*R+m*g)*v,t[3]=(h*R-u*b-_*g)*v,t[4]=(c*S-o*O-l*N)*v,t[5]=(r*O-i*S+s*N)*v,t[6]=(T*y-d*b-m*p)*v,t[7]=(f*b-h*y+_*p)*v,t[8]=(o*M-a*S+l*I)*v,t[9]=(n*S-r*M-s*I)*v,t[10]=(d*R-E*y+m*A)*v,t[11]=(u*y-f*R-_*A)*v,t[12]=(a*N-o*w-c*I)*v,t[13]=(r*w-n*N+i*I)*v,t[14]=(E*p-d*g-T*A)*v,t[15]=(f*g-u*p+h*A)*v,t):null}(Ke,h),d=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}(qe,r),E=function(t,e,r){var n=t[0],i=t[1],s=t[2],o=t[4],a=t[5],c=t[6],l=t[8],f=t[9],u=t[10],h=e[0],_=e[1],d=e[2],E=e[3],T=e[4],m=e[5],A=e[6],p=e[7],y=e[8],g=n*h+o*_+l*d,R=i*h+a*_+f*d,b=s*h+c*_+u*d,I=n*E+o*T+l*m,N=i*E+a*T+f*m,S=s*E+c*T+u*m,w=n*A+o*p+l*y,M=i*A+a*p+f*y,O=s*A+c*p+u*y;return r[0]=g,r[1]=R,r[2]=b,r[3]=0,r[4]=I,r[5]=N,r[6]=S,r[7]=0,r[8]=w,r[9]=M,r[10]=O,r[11]=0,r[12]=t[12],r[13]=t[13],r[14]=t[14],r[15]=t[15],r}(_,d,t);return De(t,We,E),t}(f,s,f,o.getProjection(),o.getGLRes(),l,a),h=function(t,e){return V(t,e[12],e[13],e[14]),t}(Ir,u);let _=this.J.options.offset;if(y(_)){_=_(this.J.Qt(e.id).center)}return i.set(br,_[0],_[1],0),i.sub(h,h,br),De(u,h,u),u}createCMPTMesh(t,e,r,n){if(this.lt[e]){const t=this.lt[e];return console.warn(`mesh with id(${e}) was already created.`),n(null,{id:e,mesh:t}),t}const{content:i}=t,s=[];for(let t=0;t<i.length;t++){const{magic:n}=i[t],o=e+"."+t;"b3dm"===n?this.createB3DMMesh(i[t],o,r,((t,{mesh:e})=>{s.push(e)})):"i3dm"===n?this.createI3DMMesh(i[t],o,r,((t,{mesh:e})=>{s.push(e)})):"pnts"===n?this.createPntsMesh(i[t],o,r,((t,{mesh:e})=>{s.push(e)})):"cmpt"===n&&this.createCMPTMesh(i[t],o,r,((t,{mesh:e})=>{s.push(e)}))}return this.lt[e]=s,n(null,{id:e,mesh:s}),s}qt(t,e,r,n,i){const s=("phong"===(this.J.options.services[n].shader||"phong")?this.vt:this.Ct).getGeometryDefines(e);return i.asset&&"S3M"===i.asset.generator&&this.te(s,e,i),s}te(t,e,r){e.data.aNormal&&(t.VertexNormal=1),e.data.instanceId&&(t.Instance=1),e.data.aTexCoord0&&(t.TexCoord=1),e.data.aColor&&(t.VertexColor=1),e.data.aTexCoord1&&(t.TexCoord2=1),e.data.uv2&&(t.InstanceBim=1),e.data.aTexCoord0&&r.textures.length&&(t.COMPUTE_TEXCOORD=1)}Kt(t,e,r,n,i,s,o){let a=!1;n.asset&&"S3M"===n.asset.generator&&(a=!0,n.extensions=n.extensions||{},n.extensions.KHR_techniques_webgl=tr);const c=n.url+"-"+e+"-"+r;if(this.ft[c])return this.ft[c].refCount++,this.ft[c];let l,f;const u=n.materials[t.material];if(n.extensions&&n.extensions.KHR_techniques_webgl&&u.extensions&&u.extensions.KHR_techniques_webgl){const e=this.ee(t,n,s,a);l=e.material,f=e.geometry;this.J.options.services[i.wt].fillEmptyDataInMissingAttribute&&(f.desc.fillEmptyDataInMissingAttribute=!0)}else{f=this.re(t,s,Nr);const e=this.J.options.services[i.wt].material;l=this.ne(t.material,n,o,e||Er)}l&&!l.isReady()?l.ie=i.id:l||(l=this.yt);const h={refCount:1,geometry:f,material:l};return f.properties.url=c,this.ft[c]=h,h}ee(t,e,r,n){const{geometry:i,material:s}=this.Rt.createMesh(t,e,r,n);return{geometry:i,material:s}}re(t,e,n){const i=t.attributes;if(i.COLOR_0){const t=i.COLOR_0.array||i.COLOR_0;if(t instanceof Float32Array){const e=new Uint8Array(t.length);for(let r=0;r<e.length;r++)e[r]=Math.round(255*t[r]);i.COLOR_0.array?(i.COLOR_0.array=e,i.COLOR_0.componentType=5121):i.COLOR_0=e}}const s={};for(const t in i){const e=ar(this.rt,i[t],{dimension:i[t].itemSize}),r=n[t]||t;s[r]={buffer:e},i[t].quantization&&(s[r].quantization=i[t].quantization),r===n.POSITION&&(s[r].array=i[t].array,s[r].min=i[t].min,s[r].max=i[t].max)}delete t.attributes;const o=new r.Geometry(s,t.indices?t.indices.array?t.indices.array.slice():t.indices:null,0,{positionAttribute:n.POSITION,normalAttribute:n.NORMAL,uv0Attribute:n.TEXCOORD_0,uv1Attribute:n.TEXCOORD_1,color0Attribute:n.COLOR_0,tangentAttribute:n.TANGENT,batchIdAttribute:n._BATCHID,primitive:void 0===t.mode?"triangles":or(t.mode)});return o.generateBuffers(this.rt,{excludeElementsInVAO:e}),o}Yt(t){const e=n.identity([]),r=this.getMap(),s=this.se();Rr.x=t[0],Rr.y=t[1];const o=r.distanceToPointAtRes(100,100,r.getGLRes(),Rr);return i.set(s,o.x/100*1.01,o.y/100*1.01,o.y/100),n.scale(e,e,s),e}Jt(e,r){const s=n.identity([]),o=this.getMap(),a=this._prjToPoint(new t.Coordinate(e)),c=this.se(),l=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes()),f=i.set(Ir,a.x,a.y,l*e[2]);n.translate(s,s,f);const u=this.J.options.services[r].heightOffset;if(u){const r=o.getProjection().unproject(new t.Coordinate(e)),i=o.distanceToPointAtRes(100,100,o.getGLRes(),r).y/100;n.translate(s,s,[0,0,u*i])}return n.scale(s,s,i.scale([],c,l)),s}gt(){const t={x:0,y:0,width:()=>this.tt?this.tt.width:1,height:()=>this.tt?this.tt.height:1};this.Dt=new r.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)=>n.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],i=[];this.Ut=new r.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)=>n.multiply(i,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,r)=>s.fromMat4(e,r.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const o=this.bt();this.vt=new r.PhongShader({extraCommandProps:o}),this.Ct=new r.pbr.StandardShader({extraCommandProps:o});const a=this.J;fr(a.getRenderer().canvas,this.rt,a.getMap())}bt(){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||yr,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:"replace"}},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},polygonOffset:{enable:!0,offset:(t,e)=>e.meshProperties.polygonOffset}}}Ft(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}xt(t){const e=this.getMap(),r=e.getLightManager(),n=(r&&r.getDirectionalLight()||{}).direction||[1,1,-1],s=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:s,lightDir:i.normalize(n,n)}}Nt(){const t=this.getMap(),e=this.J.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=hr(e),i=_r(t,r,n);return p(i,{czm_lightDirectionEC:i.light0_viewDirection,lightSpecular:[1,1,1],viewMatrix:t.viewMatrix,projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,outSize:[e.width,e.height],polygonFill:[1,1,1,1],polygonOpacity:1}),i}ne(t,e,n,i){const s=e.materials[t];if(!s||!s.baseColorTexture&&!s.pbrMetallicRoughness)return null;const a=p({},i);if(s.baseColorTexture){const t=e.textures[s.baseColorTexture.index];let r;t&&!t.image.color&&(r=this.S(t)),a.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(a.baseColorTexture=r)}else{if(s.normalTexture){const t=this.S(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;a.normalTexture=t,a.normalMapFactor=r}if(s.occlusionTexture){const t=this.S(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;a.occlusionTexture=t,a.occlusionFactor=r}if(s.emissiveTexture){const t=this.S(e.textures[s.emissiveTexture.index]);a.emissiveTexture=t}s.emissiveFactor;const t=s.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(a.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const r=e.textures[t.baseColorTexture.index];r.image&&r.image.color?a.baseColorFactor=a.baseColorFactor?o.multiply(a.baseColorFactor,a.baseColorFactor,r.image.color):r.image.color:(a.baseColorTexture=this.S(r),a.baseColorTexture.getREGLTexture(this.rt))}if(A(t.metallicFactor)||(a.metallicFactor=t.metallicFactor),A(t.roughnessFactor)||(a.roughnessFactor=t.roughnessFactor),s.metallicRoughnessTexture){const t=this.S(e.textures[s.metallicRoughnessTexture.index]);a.metallicRoughnessTexture=t}}}if(s.s3mMaterial)return new r.Material(a);let c=new r.pbr.StandardMaterial(a);return"phong"===n&&(c=r.PhongMaterial.convertFrom(c)),c.once("complete",this.Tt),c}S(t){const e={type:t.type?ir(t.type):"uint8",format:t.format?sr(t.format):"rgba",flipY:!!t.flipY},n=t.image;n.array?e.data=n.array:n.mipmap&&(e.mipmap=n.mipmap),e.width=n.width,e.height=n.height;const i=t.sampler||t.texture.sampler;return i&&(i.magFilter&&(e.mag=er(i.magFilter)),i.minFilter&&(e.min=rr(i.minFilter)),i.wrapS&&(e.wrapS=nr(i.wrapS)),i.wrapT&&(e.wrapT=nr(i.wrapT))),new r.Texture2D(e,this.Et)}oe(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}At({target:t}){const e=t.ie,r=this.it[e];if(r.count--,!r.count){const t=r.meshes;this.ot[e]=t,delete this.it[e];const n=t.$t;delete t.$t,n(null,{mesh:r.meshes,id:e})}}se(){return Tr}Vt(t){return this.J.Vt(t)}Xt(t,e){const r=this.getMap();return r.getGLZoom?r.distanceToPoint(t,e,r.getGLZoom()):r.distanceToPointAtRes(t,e,r.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())}Wt(t){return"Y"===t?cr:"X"===t?lr:mr}}
|
|
19
19
|
/*!
|
|
20
20
|
* @maptalks/gl v0.68.1
|
|
21
21
|
* LICENSE : UNLICENSED
|
|
22
22
|
* (c) 2016-2022 maptalks.com
|
|
23
|
-
*/const Sr=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")},wr=Sr(),Mr=wr.gl_trans__coders=wr.gl_trans__coders||{};function Or(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Mr.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=wr.gl_trans__coders=wr.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Sr.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in i)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(s+='tran_____scoders["'+t+'"] ='+i[t].toString()+"\n;");return s+="\n"+e.substring(n.length),s},Mr.registerTranscoder=function(t,e){Mr[t]=e},Mr.getTranscoder=function(t){return Mr[t]};const vr=[];class Cr{constructor(t,e,r,n){this.oe=t,this.St=e,this.ae=n,this.ce=r.version,t.indexOf("i3s:tileset:")<0?(this.ce<=1.6?this.le="root":this.le=0,r.version=this.ce):(this.le=t.substring("i3s:tileset:".length),this.ce>1.6&&(this.le=parseInt(this.le))),this.oe=t,this.fe=r}load(){const t=this.fe,e=t.layerScene.baseUrl;if(this.ce<=1.6)return t[this.le]&&t[this.le].lodSelection?(this.ue=t[this.le],this.he()):new Promise((r=>{let n=e+"/nodes/"+this.le;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.ae(this.St,n,(()=>{this.ue=t[this.le],r(this.he())}))}));if(this.ce>=1.7){if(t[this.le])return this.ue=t[this.le],this.he();const r=Math.floor(this.le/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.ae(this.St,i,(()=>{this.ue=t[this.le],n(this.he())}))}))}return null}getTileset(){return this._e}getChildrenURL(){return this.de}he(){const t=this.fe,e=t.layerScene.baseUrl,r=this.ue.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.ce<=1.6){const o=r[s].id;if(t[o])continue;const a=o;i[a]||(i[a]=new Promise((r=>{let n=e+"/nodes/"+a;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.ae(this.St,n,(()=>{r()}))})),n.push(i[a]))}else{const o=r[s];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);i[a]||(i[a]=new Promise((r=>{let n=e+"/nodepages/"+a;t.layerScene.eslpk&&(n+=".json"),this.ae(this.St,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.Ee())):this.Ee()}Ee(){return Promise.resolve(this.Te())}me(t){Or(this.fe,t)}Te(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Ae(this.ue,!0)}}Ae(t){const e=this.ce,r=this.fe,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=xr([],o[0],o[1],o[2]),a.sphere=[...i,o[3]];else if(s){const t=function(t,e,r){const n=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,c=i+i,l=r*o,f=n*o,u=n*a,h=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-u-d,t[3]=f-m,t[6]=h+T,t[1]=f+m,t[4]=1-l-d,t[7]=_-E,t[2]=h-T,t[5]=_+E,t[8]=1-l-u,t}([],r);return n[0]=n[0]*e[0],n[1]=n[1]*e[0],n[2]=n[2]*e[0],n[3]=n[3]*e[1],n[4]=n[4]*e[1],n[5]=n[5]*e[1],n[6]=n[6]*e[2],n[7]=n[7]*e[2],n[8]=n[8]*e[2],[...t,...n]}(i=xr([],s.center[0],s.center[1],s.center[2]),s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],r=t[4]+t[7]+t[10],n=t[5]+t[8]+t[11];H(vr,e,r,n);const o=$(vr);a.sphere=[...i,o]}var c=1/0,l=0;if(n.mbs?l=n.mbs[3]:n.obb&&(l=Math.max(Math.max(n.obb.halfSize[0],n.obb.halfSize[1]),n.obb.halfSize[2])),void 0!==n.lodThreshold)"maxScreenThresholdSQ"===r.lodSelectionMetricType?c=l/(Math.sqrt(n.lodThreshold)/(.25*Math.PI)):console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==n.lodSelection)for(var f=0;f<n.lodSelection.length;f++)"maxScreenThreshold"===n.lodSelection[f].metricType&&(c=l/n.lodSelection[f].maxError);(c===1/0||isNaN(c))&&(c=1e5);var u=16*c;const h=P([]),_=n.children;var d;if(_){d=[];const t=this.fe;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Ae(t[n]))}}var E={refine:"REPLACE",boundingVolume:a,transform:h,geometricError:u};return e<=1.6?t.lodSelection?t.geometryData&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}):E.content={uri:"i3s:tileset:"+(t.id||t.index)}:_&&_.length&&!d?E.content={uri:"i3s:tileset:"+(t.id||t.index)}:n.mesh&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(E.children=d),E}getJSON(){return this.ue}}function xr(t,e,r,n){return re(t,R(e),R(r),n)}const Ur=!!Mr.ktx2,Br=n.identity([]),Pr=(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){const t=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(t instanceof WebAssembly.Module)return new WebAssembly.Instance(t)instanceof WebAssembly.Instance}}catch(t){}return!1})();function Lr(t){return t.indexOf("i3s:mesh")>=0}const Dr="i3s:mesh:".length;function Fr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Dr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const u=Br;let h,_;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;let r=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;s&&(r+=".bin");const n={geometry:{url:r,info:e.layerScene.store.defaultGeometrySchema}};let i=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(i){const t=e.layerScene.store.textureEncoding[0];let r;r="image/jpeg"===t?"jpg":"png",s&&(i+="."+r);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+i,factor:1,format:r,mimeType:t},metallicFactor:0}};n.material=o}l.push(n)}else{h=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[h.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const u=Mr.draco&&f?o[1]:o[0],d=Mr.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};if(i&&Pr&&f&&!Mr.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const m=e.layerScene.materialDefinitions,A=e.layerScene.textureSetDefinitions;let p,y=0;if(_&&(y=m[_.definition]),m){p=function(t,e,r,n,i,s){const o=JSON.parse(JSON.stringify(t));return Gr(o,e,r,n,i,s),o}(y,A,c,_.resource,r,e.layerScene.eslpk)}else p={pbrMetallicRoughness:{metallicFactor:0}};T.material=p,l.push(T)}return{dracoCompression:f,meshes:l,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:u}}function Gr(t,e,r,n,i,s){for(const o in t)if(t[o]&&t[o].textureSetDefinitionId>=0){const a=e[t[o].textureSetDefinitionId],c="images/"+a.formats[0].format,l=kr(a.formats,i),f={url:r+`/nodes/${n}/textures/${l.name}`,factor:void 0===t[o].factor?1:t[o].factor,format:l.format,mimeType:c};if(s){let t="";switch(l.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=l.format}f.url+="."+t}t[o]=f}else g(t[o])&&Gr(t[o],e,r,n,i,s)}function kr(t,e){for(let r=0;r<=t.length;r++){const n=t[r].format;if("dds"===n&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[r];if("jpg"===n||"png"===n)return t[r];if("ktx2"===n&&Ur)return t[r]}return null}class Hr extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new jt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.pe={},this.ye=[],this.ae=this.ge.bind(this)}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.ye.length||super.needToRedraw())}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){const r=this.prepareCanvas();if(r&&!r.intersects(this.canvasExtent2D))return void this.completeRender();const{root:n,tiles:i}=this.layer.getTiles(),s=i.length;if(!i||!s)return void this.completeRender();this.Re(),this.be();const{selectedTiles:o,leaves:a,requests:c}=this.Ie(n,i);c.length&&this.loadTiles(c),this.Ne(o,a,e),this.Se(),c.length||this.completeRender()}Ie(t,e){let r=[];this.we();let n=0;const i=this.Me(),s={};let o=!1,a=!1;for(let t=0;t<e.length;t++){const i=e[t],c=i.node;if(s[c.id])continue;s[c.id]=1;let l=!1;const f=this.getCachedTile(c.id);if(this.Oe(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),o=!0,i.selected=!0,i.data=f):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.ve(i))o=!0;else{this.Ce(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.xe(t)),r.length>1&&(r.sort(Vr),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}xe(t){const e=[],r={};let n;const i=[t],s=[];for(;i.length>0||s.length>0;){if(s.length>0){const t=s[s.length-1];if(t.Ue===i.length){s.pop(),t===n&&(t.leave=!0,r[t.node.id]=1),e.push(t);continue}}const t=i.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)r[t.node.id]=1,t.selectionDepth=s.length,e.push(t);else{if(t.selectionDepth=s.length,n=t,0===o.length){t.leave=!0,r[t.node.id]=1,e.push(t);continue}s.push(t),t.Ue=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}ve(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}Ce(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Be+1,n=[t.node];for(;n.length>0;){const i=n.pop().children;for(let s=0,o=i.length;s<o;s++){if((!i[s].content||!i[s].content.url)&&i[s].children&&i[s].children.length){n.push(i[s]);continue}const o=i[s].id;if(this.tileCache.has(o)){const r=this.layer.Pe(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Be<=r&&n.push(i[s])}}return e}Ne(t,e,r){this.tileCache.markAll(!1);for(let e=0,r=t.length;e<r;e++){const r=t[e].data;r.current=!0,this.tileCache.add(t[e].node.id,r)}this.tileCache.shrink();const n={tiles:t,leaves:e};this.onDrawTileStart(n);const i=r&&r.renderTarget,s=r&&r.sceneFilter,o=this.painter.paint(t,e,s,i);this.layer.options.debug&&this.painter.paintRegion(t,{color:this.layer.options.debugOutline},s,i),this.onDrawTileEnd(n),o&&this.layer.fire("canvasisdirty",{renderCount:o})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,r=t.length;e<r;e++){const r=t[e];this.tilesLoading[r.id]={current:!0,node:r},this.loadTile(r)}}loadTile(t){let e=t.content.url;if(C(e)){const r=x(e);return void this.Le(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.St,n=this.De[r];return new Cr(e,r,n,this.ae).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Lr(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.St];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=pt.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.pe[e],r?this.Le(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.pe[e],this.onTileError(r,t)})),this.pe[e]=s}else this.Le(e,null,t)}Le(t,e,n){let i=this.o;i||(i=r.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=i);const s={url:t,arraybuffer:e,rootIdx:n.St,upAxis:n.Wt,transform:n.matrix,supportedFormats:i};if(Lr(t)){const e=this.De[n.St];if(s.i3sInfo=Fr(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!s.i3sInfo)return void this.onTileError({status:404},n)}this.workerConn.loadTile(this.layer.getId(),s,((e,r)=>{if(e)return void this.onTileError(e,n);const{magic:i}=r;"b3dm"===i||"pnts"===i||"i3dm"===i||"cmpt"===i?this.ye.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}be(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.ye.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.ye.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Fe(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.Fe(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Fe(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.Fe(t,e,r,n)})),r++}}Fe(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.Ge(n);e.memorySize=r,this.onTileLoad(t,e)}}Ge(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.Ge(t[r]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.ke(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,r){this.layer&&(t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.He(t,e,r):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,r)))}onTileError(t,e){if(!this.layer)return;const r=e.content.url;console.warn("failed to load 3d tile: "+r),console.warn(t),delete this.tilesLoading[e.id],this.Ve(e),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Ve(e){const r={loadTime:t.Util.now(),current:!0,error:!0,node:e};this.tileCache.add(e.id,r)}ke(e){const r={loadTime:t.Util.now(),current:!0,node:e};this.tileCache.add(e.id,r)}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.pe[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.pe[e]}we(){if(this.tilesLoading)for(const t in this.tilesLoading)this.tilesLoading[t].current=!1}deleteTile(t){this.painter.deleteTile(t)}createContext(){const t=this.layer,e=t.options.glOptions||{alpha:!0,depth:!0,stencil:!0,preserveDrawingBuffer:!0,antialias:t.options.antialias};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.ze(this.canvas,e)),this.regl=this.regl||c({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),this.painter=new Nr(this.regl,t)}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Yt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=p({},r),delete r.offset,r.projection=t.getSpatialReference().getProjection().code;const n=this.layer.getId();e.addLayer(n,r,(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.Se(!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}Se(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 r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}Me(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}ze(t,e){const r=["webgl","experimental-webgl"];let n=null;for(let i=0;i<r.length;++i){try{n=t.getContext(r[i],e)}catch(t){}if(n)break}return n}Oe(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,r){return Re(t,e,0,r)}Re(){if(!this.Ye)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.Ye){const i=this.Ye[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(pt.getJSON(n).then((t=>{delete this.Ye[n];const e=this.De[s];if(e){t.nodes?Or(e,t.nodes):(e[t.id]=t,Or(e,t.children));for(let t=0;t<i.length;t++)i[t]();this.setToRedraw()}else this.setToRedraw()}))),e++,e>=t)break}r.length&&Promise.all(r)}ge(t,e,r){this.Ye||(this.Ye={}),this.Ye[e]=this.Ye[e]||[],this.Ye[e].rootIdx=t,this.Ye[e].push(r),this.setToRedraw()}He(t,e,r){this.De||(this.De=[]);const n=e.St;this.De[n]||(this.De[n]={});const i=this.De[n],s=this.layer.options.services[n];t.layers&&(t=t.layers[0],"/"!==r[r.length-1]&&(r+="/"),r+="layers/0"),i.version=+(s.i3sVersion||t.store.version),function(t,e,r,n,i,s){if(!i.layerScene){i.layerScene=t,i.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,i.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=n;if(i.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0,i.layerScene.eslpk){const t=n.lastIndexOf("/");e=t<0?"./":n.substring(0,t)}i.layerScene.baseUrl=e}return new Cr(n,e,i,s).load()}(t,n,0,r,i,this.ae).then((t=>{this.onTilesetLoad(t,e,r)}))}}function Vr(t,e){return t.Bt-e.Bt}function zr(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function Xr(t,e,r){return Math.sqrt(function(t,e,r){var n=z(Yr,r,t),i=zr(Zr,e,0),s=zr(Wr,e,1),o=zr(jr,e,2),a=$(i),c=$(s),l=$(o);Z(i,i),Z(s,s),Z(o,o);var f=Kr;f[0]=W(n,i),f[1]=W(n,s),f[2]=W(n,o);var u,h=0;f[0]<-a?h+=(u=f[0]+a)*u:f[0]>a&&(h+=(u=f[0]-a)*u);f[1]<-c?h+=(u=f[1]+c)*u:f[1]>c&&(h+=(u=f[1]-c)*u);f[2]<-l?h+=(u=f[2]+l)*u:f[2]>l&&(h+=(u=f[2]-l)*u);return h}(t,e,r))}const Yr=[],Zr=[],Wr=[],jr=[],Kr=[];const qr=2*Math.PI;class $r{constructor(t,e,r,n){this.west=t,this.south=e,this.east=r,this.north=n}static contains(t,e){var r=e[0],n=e[1],i=t.west,s=t.east;return s<i&&(s+=qr,r<0&&(r+=qr)),(r>i||Te(r,i,1e-14))&&(r<s||Te(r,s,1e-14))&&n>=t.south&&n<=t.north}static southwest(t,e){return e[0]=t.west,e[1]=t.south,e[2]=0,e}static northeast(t,e){return e[0]=t.east,e[1]=t.north,e[2]=0,e}static southeast(t,e){return e[0]=t.east,e[1]=t.south,e[2]=0,e}static northwest(t,e){return e[0]=t.west,e[1]=t.north,e[2]=0,e}}const Jr=[0,0,1];function Qr(t,e){return re(e,t[0],t[1],t[2])}class tn{constructor(t,e){this.normal=i.copy([],t),this.distance=e}static fromPointNormal(t,e,r){var n=-i.dot(e,t);return i.copy(r.normal,e),r.distance=n,r}}const en=[],rn=[],nn=[],sn=[],on=[],an=[],cn=[],ln=[],fn=[],un=[],hn=new tn([1,0,0],0),_n=[];class dn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new $r(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var r,n,s,o=0;if(!$r.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,u=this.eastNormal,h=this.northNormal,_=i.subtract(_n,t,a),d=i.dot(_,l),E=i.dot(_,f),T=i.subtract(_n,t,c),m=i.dot(T,u),A=i.dot(T,h);d>0?o+=d*d:m>0&&(o+=m*m),E>0?o+=E*E:A>0&&(o+=A*A)}if(r=e[2],n=this.minimumHeight,r>(s=this.maximumHeight)){var p=r-s;o+=p*p}else if(r<n){var y=n-r;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;Qr($r.southwest(t,rn),e.southwestCornerCartesian),Qr($r.northeast(t,rn),e.northeastCornerCartesian),en[0]=t.west,en[1]=.5*(t.south+t.north),en[2]=0;var r=Qr(en,nn),n=i.cross(on,r,Jr);i.normalize(e.westNormal,n),en[0]=t.east;var s=Qr(en,ln),o=i.cross(on,Jr,s);i.normalize(e.eastNormal,o);var a,c=i.subtract(on,r,s),l=i.normalize(sn,c),f=t.south;if(f>0){en[0]=.5*(t.west+t.east),en[1]=f;var u=Qr(en,fn);i.copy(un,l);var h=tn.fromPointNormal(e.southwestCornerCartesian,e.westNormal,hn);En(fn,un,h,e.southwestCornerCartesian),a=_e(u,an)}else a=de($r.southeast(t,rn),an);var _=i.cross(cn,a,c);i.normalize(e.southNormal,_);var d,E=t.north;if(E<0){en[0]=.5*(t.west+t.east),en[1]=E;var T=Qr(en,fn);i.scale(un,l,-1);var m=tn.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,hn);En(fn,un,m,e.northeastCornerCartesian),d=_e(T,an)}else d=de($r.northwest(t,rn),an);var A=i.cross(cn,c,d);i.normalize(e.northNormal,A)}}function En(t,e,r,n){var s=t,o=e,a=r.normal,c=i.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-r.distance-i.dot(a,s))/c;if(!(l<0))return n=i.scale(n,o,l),i.add(n,s,n)}}const Tn=new t.Extent(0,0,0,0),mn=new t.Extent(0,0,0,0),An=[],pn=[],yn=[],gn=[],Rn=new t.Point(0,0),bn=[],In=new t.Coordinate(0,0),Nn=n.identity([]);class Sn extends t.Layer{constructor(t,e){super(t,e),this.Ze(),this.pe={},this.We=[]}Ze(){let t=this.options.services.map((t=>t.url));this.je=t.map(((t,e)=>function(t,e){t=I(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.identity([]),St:e,Be:0}}(t,e))),this.fire("rootready",{roots:this.je.slice(0)})}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.je.length;t++)if(this.je[t].boundingVolume){const r=this.boundingVolumeToExtent(this.je[t]);e._combine(r)}return e}return this.je[e]&&this.je[e].boundingVolume?this.boundingVolumeToExtent(this.je[e]):null}boundingVolumeToExtent(e){const r=e.boundingVolume.Ke?Nn:e.matrix,n=this.getMap();if(e.boundingVolume.region){const r=e.boundingVolume.region;return new t.Extent(b(r[0]),b(r[1]),b(r[2]),b(r[3]))}if(e.boundingVolume.sphere){const s=e.boundingVolume.sphere,o=ce([],i.transformMat4([],s,r)),a=s[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new t.Extent(c,l)}if(e.boundingVolume.box){const o=e.boundingVolume.box,a=i.transformMat4([],o,r),c=new t.Coordinate(ce([],a)),l=o.slice(3);s.multiply(l,s.fromMat4([],e.matrix),l);const f=i.length(l.slice(0,3)),u=i.length(l.slice(3,6)),h=i.length(l.slice(6,9)),_=Math.max(f,u,h),d=n.locate(c,-_,_),E=n.locate(c,_,-_);return new t.Extent(d,E)}return null}getRootTiles(){return this.je}getTiles(){const t=this.getRenderer();if(!t.ready)return this.qe(),{tiles:gn};const e=this.getMap(),r=e.cameraPosition;let n,s;if(e.getGLZoom)s=e.pointToDistance(r[2],0,e.getGLZoom()),In.set(r[0],r[1]),n=e.pointToCoord(In,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(r[2],0,t),In.set(r[0],r[1]),n=e.pointAtResToCoord(In,t)}this.$e=this.$e||[],i.set(this.$e,R(n.x),R(n.y),s),this.Je=re(this.Je||[],this.$e[0],this.$e[1],this.$e[2]),this.Qe=2*Math.tan(.5*R(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.je.length;e++){let r=1/0;const n=[this.je[e]],i=this.tr(e);for(;n.length>0;){const e=n.pop();for(e.id||this.er(e);c.level>=e.Be;)c=c.parent;const s=this.rr(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.nr(l,t);if(!1===this.options.services[e.St].alwaysShow)continue;if(!(0===s&&e.Be<=r))continue;e.content&&(r=e.Be)}e.Bt<1/0&&this.ir(e);const a=this.Pe(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.nr(l,a),u){h&&"add"===e.refine&&this.nr(l,a),c=a;const r=f[0].parent;let i=!1;for(let s=0,o=f.length;s<o;s++){if(r){const e=t.getCachedTile(f[s].id);if(e&&e.error)continue;i=!0}else{i=!0,f[s].parent=e,f[s].Wt=e.Wt,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(C(t)||t.indexOf("i3s:")>=0?f[s].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?f[s].content.url=e.baseUrl+t:f[s].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}n.push(f[s])}!i&&h&&this.nr(l,a)}}}return{root:a,tiles:l}}nr(t,e){const{viewerRequestVolume:r}=e.node;r&&!function(t,e,r){if(r.region){const e=r.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(r.sphere)return wn(r,e);if(r.box)return 0===Mn(r,e)}return!1}(this.$e,this.Je,r)||t.push(e)}Pe(t,e){return{id:t.id,node:t,children:[],level:t.Be,parent:e,content:t.content&&t.content.url}}er(e){e.id=t.Util.GUID(),e.matrix=e.transform||n.identity([]),e.sr=this.ar(e),e.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(e)||(e.matrix=n.multiply(e.matrix,e.parent.matrix,e.matrix)),e.St=e.parent.St,void 0===e.Be&&(e.Be=e.parent.Be+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.cr(e)}cr(t){const e=t.boundingVolume;if(!e||e.Ke)return;const r=this.options.services[t.St].heightOffset||0,s=this.options.offset,o=y(s)||s[0]||s[1];if(!t.boundingVolume||!r&&n.exactEquals(t.matrix,Nn)&&!o)return;const{region:a,box:c,sphere:l}=e;if(a){const t=this.lr([b(a[0]),b(a[1])]);a[0]=R(t.x),a[1]=R(t.y);const e=this.lr([b(a[2]),b(a[3])]);a[2]=R(e.x),a[3]=R(e.y),a[4]+=r,a[5]+=r}else if(c||l){const e=c||l,n=i.transformMat4(An,e,t.matrix),s=ce(pn,n),o=this.lr([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=r,re(e,R(s[0]),R(s[1]),s[2])}e.Ke=!0}ar(t){return void 0===t.geometricError||!t.boundingVolume}ir(t){let e=t.parent;for(;e&&e.sr&&!(e.Bt<=t.Bt);)e.Bt=t.Bt,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const r=e.content.url;e.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const n=this.getRenderer();n&&n.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const i=(t.asset&&t.asset.gltfUpAxis||e&&e.Wt||this.options.services[e.St].upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const s=r.indexOf("realspace/")>-1;t.asset&&t.asset.s3mType&&s&&(t.root.baseUrl+="data/path/");const o=t.asset.i3s;if(t.root.Wt=i,e){const r=e.boundingVolume;p(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",r&&(e.boundingVolume=r);const i=t.root.transform;i&&(e.parent?o||(e.matrix=n.multiply([],e.parent.matrix,i)):e.matrix=i),this.cr(e),e.ur=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.sr=this.ar(e);const s=e.content&&(e.content.url||e.content.uri);s&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),o||!s||C(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.qe(),this.fire("loadtileset",{tileset:t,index:e.St,url:r})}rr(t,e,r){if(t.Bt=1/0,0===t.Be||t.sr)return 1;if(!this.hr(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.St].maximumScreenSpaceError;null==n&&(n=8);let i=this._r(t);return 0===i&&t.parent&&(i=.5*(t.parent.dr||0)),i>=n?1:0}Ht(e,r){r||(r=new t.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(e,n.getGLZoom(),r):n.coordToPointAtRes(e,n.getGLRes(),r)}hr(e,r,i){const o=e.id;let a=this.We[o];const{boundingVolume:c}=e,l=c.sphere,u=c.region,h=c.box;if(!a){let r,i,c;if(u){r=Tn.set(b(u[0]),b(u[1]),b(u[2]),b(u[3]));const t=r.getCenter(),e=this.Er(t);r=r.convertTo((t=>this.Ht(t,Rn)),mn),c=u[4],i=u[5],a=this.We[o]=[[r.xmin,r.ymin,c*e[2]],[r.xmax,r.ymax,i*e[2]]],a.center=t}else if(l){const e=ce(An,l),r=new t.Coordinate(e),n=this.Ht(r,Rn).toArray(),i=this.Er(r);n.push(e[2]*i[2]),a=this.We[o]=[n,l[3]*i[2]],a.center=r}else if(h){const r=ce(An,h),i=new t.Coordinate(r),c=this.Ht(i,Rn).toArray(),l=this.Er(i);c.push(r[2]*l[2]);const f=h.slice(3);n.exactEquals(e.matrix,Nn)||s.multiply(f,s.fromMat4(bn,e.matrix),f);for(let t=0;t<f.length;t++)f[t]*=l[t%3],h[3+t]=f[t];a=this.We[o]=[...c,...f],a.center=i}}if(r){if(u)Tn.xmin=a[0][0],Tn.ymin=a[0][1],Tn.xmax=a[1][0],Tn.ymax=a[1][1];else if(l){const t=a[2];Tn.xmin=a[0][0]-t,Tn.ymin=a[0][1]-t,Tn.xmax=a[0][0]+t,Tn.ymax=a[0][1]+t}else if(h){const t=a[1],e=a[2];Tn.xmin=a[0][0]-t,Tn.ymin=a[0][1]-e,Tn.xmax=a[0][0]+t,Tn.ymax=a[0][1]+e}if(!r.intersects(Tn))return!1}return u?_(i,a):l?function(t,e,r){E(t);for(var n=e[0],i=-e[1],s=0;s<6;s++)if((!r||"0"!==r.charAt(s))&&m(f[s],n)<i)return!1;return!0}(i,a):!!h&&function(t,e,r){E(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||d(f[n],e)))return!1;return!0}(i,a)}Er(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);return i.set(yn,r.x/100*1.01,r.y/100*1.01,r.y/100),yn}lr(e){Array.isArray(e)&&(e=new t.Coordinate(e));let r=this.options.offset;if(y(r)&&(r=r(Array.isArray(e)?new t.Coordinate(e):e)),r[0]||r[1]){const t=this.getMap(),n=t.getGLRes(),i=t.coordToPointAtRes(e,n);return i._sub(r),t.pointAtResToCoord(i,n)}return e}tr(e){const r=this.options.services[e].maxExtent;if(!r)return null;const n=this.je[e];return n.maxExtent||(n.maxExtent=new t.Extent(r).convertTo((t=>this.Ht(t)))),n.maxExtent}_r(t){const e=this.Qe,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.Tr||(t.Tr=new dn(t.boundingVolume.region));return t.Tr.distanceToCamera(e,r)}(t,this.Je,this.$e):t.boundingVolume.sphere?i=wn(t.boundingVolume,this.Je):t.boundingVolume.box&&(i=Mn(t.boundingVolume,this.Je));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Bt=i,t.dr=o,o}qe(){const t=this.getRenderer();t&&t.setToRedraw()}Jt(t){return this.We[t]}}function wn(t,e){const r=t.sphere,n=i.dist(r,e),s=t.sphere[3];return n<s?0:n-s}function Mn(t,e){const r=t.box;return Xr(i.set(An,r[0],r[1],r[2]),s.set(bn,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}Sn.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"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]}),Sn.registerRenderer("gl",Hr),Sn.registerJSONType("Geo3DTilesLayer");class On{constructor(t,e,r){this.i=t,this.mr=e||Dt,this.o=r,this.Ar={"image/crn":Mr.crn&&Mr.crn(),"image/ktx2":Mr.ktx2&&Mr.ktx2(),"image/cttf":Mr.ktx2&&Mr.ktx2(),"draco":Mr.draco&&Mr.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.pr(t,e,r,n,i)):pt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.pr(t,i,r,n)}))}pr(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.yr(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.mr(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.Ar,supportedFormats:this.o,maxTextureSize:s});return c.load({skipAttributeTransform:!1}).then((e=>{e.url=`${t}-${r}-${n}`;const i=c.transferables;for(let t=0;t<o.transferables.length;t++)i.indexOf(o.transferables[t])<0&&i.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:i,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}}))}yr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported b3dm version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+n;return console.warn(t),{error:t}}let o,a=i.getUint32(12,!0),c=i.getUint32(16,!0),l=i.getUint32(20,!0),f=i.getUint32(24,!0),u=28+e;l>=570425344?(u-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(u-=4,o=l,l=a,f=c,a=0,c=0);const h=[t];let _,d,E;if(a>0?(_=pe(t,u,a),u+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(u+=c),l>0&&(d=ye(t,u,l),u+=l,f>0)){const e=ge(0,u,f);E=t.slice(e.offset,e.offset+e.byteLength),u+=f,h.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=be(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&h.indexOf(e)<0&&h.push(e)}return{count:o,transferables:h,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:u,byteLength:i.byteLength+i.byteOffset-u}}}gr(){return null}}class vn{constructor(t,e,r,n){this.i=t,this.mr=e||Dt,this.o=r,this.Ar={"image/crn":Mr.crn&&Mr.crn(),"image/ktx2":Mr.ktx2&&Mr.ktx2(),"image/cttf":Mr.ktx2&&Mr.ktx2(),"draco":Mr.draco&&Mr.draco()},this.Rr=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.pr(t,e,r,n,i)):pt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.pr(t,i,r,n)}))}pr(t,e,r,n,i){return this.br(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Ir(e,r,n,t);if(o.error)return Promise.resolve(o);for(let t=0;t<s.length;t++)-1===o.transferables.indexOf(s[t])&&o.transferables.push(s[t]);return delete i.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:i})}))}br(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.Ar,supportedFormats:this.o,maxTextureSize:s},a=new DataView(e,r,n),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let n=w(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?pt.getArrayBuffer(n,{}).then((t=>this.Nr(n,{buffer:t.data,byteOffset:0},o))):pt.getJSON(n,{}).then((t=>this.Nr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Nr(t,n,o)}}Nr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.mr(n,e,r);return i.load({skipAttributeTransform:!0}).then((r=>{let n=0,s=0;return e.buffer&&(n=e.byteOffset||0,s=e.byteLength||0),r.url=`${t}-${n}-${s}`,{transferables:i.transferables,gltf:r}}))}Ir(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Me(i,32+e,o),u={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;u.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;u.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Sr(new Uint16Array(t,n+c.offset,3*h),e,r)},o.push(u.POSITION.array.buffer)}if(a.BATCH_ID){u.BATCH_ID=be(a.BATCH_ID,t,c.offset,h);const e=u.BATCH_ID.array&&u.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.wr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.wr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;u.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},o.push(u.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;u.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:l,batchTableBin:f,featureTable:a,i3dm:u,transferables:o}}wr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Cn(n,t[2*i],t[2*i+1],65535),r[3*i]=n[0],r[3*i+1]=n[1],r[3*i+2]=n[2];return r}Sr(t,e,r){return we(new Float32Array(t.length),t,e,r)}gr(){return null}}function Cn(t,e,r,n){if(t[0]=xn(e,n),t[1]=xn(r,n),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]))*Un(e),t[1]=(1-Math.abs(e))*Un(t[1])}return Z(t,t)}function xn(t,e){return e=function(t,e){if(null!=t)return t;return e}(e,255),function(t,e,r){return t<e?e:t>r?r:t}(t,0,e)/e*2-1}function Un(t){return t<0?-1:1}class Bn{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.pr(t,e,r,n)):pt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.pr(t,i,r,n)}))}pr(t,e,r,n){return this.Mr(e,r,n,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}))}Mr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Me(i,e+28,o),u=a.QUANTIZED_VOLUME_OFFSET,h=a.QUANTIZED_VOLUME_SCALE,_=a.POINTS_LENGTH;let d,E={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){E=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,E.byteOffset+c.offset,E.byteLength);const e={attributes:E.properties,useUniqueIDs:!1};return this.Or||(this.Or=Mr.draco()),this.Or(d,e).then((e=>{const r=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||r.POSITION||r.POSITION_QUANTIZED||(r.POSITION=a.POSITION,r.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||r.RGB||r.RGBA||r.RGB565||(r.RGB=a.RGB,r.RGBA=a.RGBA,r.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||r.NORMAL||r.NORMAL_OCT16P||(r.NORMAL=a.NORMAL,r.NORMAL_OCT16P=a.NORMAL_OCT16P);const n=this.vr(t,e.attributes,c.offset,_,o,u,h);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;n.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:Se(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=be(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=Pn(_);const e=n.BATCH_ID.array&&n.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:n,transferables:o}}))}const T=this.vr(t,a,c.offset,_,o,u,h);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=be(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=Pn(_);const e=T.BATCH_ID.array&&T.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:T,transferables:o})}vr(t,e,r,n,i,s,o){const a={};if(e.POSITION){let{byteOffset:s,array:o}=e.POSITION;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c,array:l}=e.POSITION_QUANTIZED;c=c||0;const f=l?0:r;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:this.Sr(l||new Uint16Array(t,c+f,3*n),s,o)},i.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:s,array:o}=e.RGBA;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+4*n);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB){let{byteOffset:s,array:o}=e.RGB;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB565){let{byteOffset:s,array:o}=e.RGB565;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:n,componentType:5123,array:o},i.push(o.buffer)}if(e.NORMAL){let{byteOffset:s,array:o}=e.NORMAL;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:s,array:o}=e.NORMAL_OCT16P;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:n,componentType:5121,array:o},i.push(o.buffer)}return a}Sr(t,e,r){return we(new Float32Array(t.length),t,e,r)}gr(){return null}}function Pn(t){const e=v(t),r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:Se(e),array:r}}class Ln{constructor(t,e){this.i=t,this.mr=e||Dt}load(t,e,r=0,n=0,i){return e?this.pr(t,e,r,n,i):pt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.pr(t,i,r,n)}))}pr(t,e,r,n,i){n||(n=e.byteLength);const s=this.Cr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new On(this.i,this.mr);else if("i3dm"===s[r].magic)n=new vn(this.i,this.mr);else if("pnts"===s[r].magic)n=new Bn;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Ln(this.i,this.mr)}o.push(n.load(t,e,s[r].offset,s[r].byteLength,i).then((t=>t)))}return Promise.all(o).then((t=>({magic:"cmpt",tiles:t})))}Cr(t,e,r,n){const i=new DataView(t,r,n),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported cmpt version: "+s+", url:"+e;return console.warn(t),{error:t}}if(16===i.byteLength)return[];const o=[],a=i.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=me(i,c),n=i.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+r,byteLength:n}),c+=n}return o}}if(e.transcoders){const r=t.Map.VERSION;if(r.indexOf("1.0.0-beta")>=0||r.indexOf("1.0.0-alpha")>=0){const r=e.transcoders.inject(l);t.registerWorkerAdapter("@maptalks/3dtiles",r)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(l)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",l);export{On as B3DMLoader,Ln as CMPTLoader,Sn as Geo3DTilesLayer,U as Geo3DTilesUtil,Ee as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.15.1");
|
|
23
|
+
*/const wr=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")},Mr=wr(),Or=Mr.gl_trans__coders=Mr.gl_trans__coders||{};function vr(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Or.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Mr.gl_trans__coders=Mr.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${wr.toString()};\n const g___lobals = _____getGlobal()\n const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;for(const t in i)"inject"!==t&&"getTranscoder"!==t&&"registerTranscoder"!==t&&(s+='tran_____scoders["'+t+'"] ='+i[t].toString()+"\n;");return s+="\n"+e.substring(n.length),s},Or.registerTranscoder=function(t,e){Or[t]=e},Or.getTranscoder=function(t){return Or[t]};const Cr=[];class xr{constructor(t,e,r,n){this.ae=t,this.wt=e,this.ce=n,this.le=r.version,t.indexOf("i3s:tileset:")<0?(this.le<=1.6?this.fe="root":this.fe=0,r.version=this.le):(this.fe=t.substring("i3s:tileset:".length),this.le>1.6&&(this.fe=parseInt(this.fe))),this.ae=t,this.ue=r}load(){const t=this.ue,e=t.layerScene.baseUrl;if(this.le<=1.6)return t[this.fe]&&t[this.fe].lodSelection?(this.he=t[this.fe],this._e()):new Promise((r=>{let n=e+"/nodes/"+this.fe;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.ce(this.wt,n,(()=>{this.he=t[this.fe],r(this._e())}))}));if(this.le>=1.7){if(t[this.fe])return this.he=t[this.fe],this._e();const r=Math.floor(this.fe/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.ce(this.wt,i,(()=>{this.he=t[this.fe],n(this._e())}))}))}return null}getTileset(){return this.de}getChildrenURL(){return this.Ee}_e(){const t=this.ue,e=t.layerScene.baseUrl,r=this.he.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.le<=1.6){const o=r[s].id;if(t[o])continue;const a=o;i[a]||(i[a]=new Promise((r=>{let n=e+"/nodes/"+a;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.ce(this.wt,n,(()=>{r()}))})),n.push(i[a]))}else{const o=r[s];if(t[o])continue;const a=Math.floor(o/t.nodesPerPage);i[a]||(i[a]=new Promise((r=>{let n=e+"/nodepages/"+a;t.layerScene.eslpk&&(n+=".json"),this.ce(this.wt,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.Te())):this.Te()}Te(){return Promise.resolve(this.me())}Ae(t){vr(this.ue,t)}me(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.pe(this.he,!0)}}pe(t){const e=this.le,r=this.ue,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Ur([],o[0],o[1],o[2]),a.sphere=[...i,o[3]];else if(s){const t=function(t,e,r){const n=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=r+r,a=n+n,c=i+i,l=r*o,f=n*o,u=n*a,h=i*o,_=i*a,d=i*c,E=s*o,T=s*a,m=s*c;return t[0]=1-u-d,t[3]=f-m,t[6]=h+T,t[1]=f+m,t[4]=1-l-d,t[7]=_-E,t[2]=h-T,t[5]=_+E,t[8]=1-l-u,t}([],r);return n[0]=n[0]*e[0],n[1]=n[1]*e[0],n[2]=n[2]*e[0],n[3]=n[3]*e[1],n[4]=n[4]*e[1],n[5]=n[5]*e[1],n[6]=n[6]*e[2],n[7]=n[7]*e[2],n[8]=n[8]*e[2],[...t,...n]}(i=Ur([],s.center[0],s.center[1],s.center[2]),s.halfSize,s.quaternion),e=t[3]+t[6]+t[9],r=t[4]+t[7]+t[10],n=t[5]+t[8]+t[11];V(Cr,e,r,n);const o=J(Cr);a.sphere=[...i,o]}var c=1/0,l=0;if(n.mbs?l=n.mbs[3]:n.obb&&(l=Math.max(Math.max(n.obb.halfSize[0],n.obb.halfSize[1]),n.obb.halfSize[2])),void 0!==n.lodThreshold)"maxScreenThresholdSQ"===r.lodSelectionMetricType?c=l/(Math.sqrt(n.lodThreshold)/(.25*Math.PI)):console.error("Unsupported lodSelectionMetricType in Layer");else if(void 0!==n.lodSelection)for(var f=0;f<n.lodSelection.length;f++)"maxScreenThreshold"===n.lodSelection[f].metricType&&(c=l/n.lodSelection[f].maxError);(c===1/0||isNaN(c))&&(c=1e5);var u=16*c;const h=L([]),_=n.children;var d;if(_){d=[];const t=this.ue;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.pe(t[n]))}}var E={refine:"REPLACE",boundingVolume:a,transform:h,geometricError:u};return e<=1.6?t.lodSelection?t.geometryData&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}):E.content={uri:"i3s:tileset:"+(t.id||t.index)}:_&&_.length&&!d?E.content={uri:"i3s:tileset:"+(t.id||t.index)}:n.mesh&&(E.content={uri:"i3s:mesh:"+(t.id||t.index)}),d&&d.length&&(E.children=d),E}getJSON(){return this.he}}function Ur(t,e,r,n){return ne(t,R(e),R(r),n)}const Br=!!Or.ktx2,Pr=n.identity([]),Lr=(()=>{try{if("object"==typeof WebAssembly&&"function"==typeof WebAssembly.instantiate){const t=new WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(t instanceof WebAssembly.Module)return new WebAssembly.Instance(t)instanceof WebAssembly.Instance}}catch(t){}return!1})();function Dr(t){return t.indexOf("i3s:mesh")>=0}const Fr="i3s:mesh:".length;function Gr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Fr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const u=Pr;let h,_;if(e.version<=1.6){if(!a.geometryData)return null;const t=a.geometryData.length;let r=c+`/nodes/${a.id}/`+a.geometryData[t-1].href;s&&(r+=".bin");const n={geometry:{url:r,info:e.layerScene.store.defaultGeometrySchema}};let i=a.textureData&&a.textureData[0]&&a.textureData[0].href;if(i){const t=e.layerScene.store.textureEncoding[0];let r;r="image/jpeg"===t?"jpg":"png",s&&(i+="."+r);const o={pbrMetallicRoughness:{baseColorTexture:{url:c+`/nodes/${a.id}/`+i,factor:1,format:r,mimeType:t},metallicFactor:0}};n.material=o}l.push(n)}else{h=a.mesh.geometry,_=a.mesh.material;const t=e.layerScene.geometryDefinitions[h.definition],{geometryBuffers:o}=t;f=n&&2===o.length;const u=Or.draco&&f?o[1]:o[0],d=Or.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};if(i&&Lr&&f&&!Or.draco)throw new Error("Must import @maptalks/transcoder.draco to load i3s draco compressed geometry");const m=e.layerScene.materialDefinitions,A=e.layerScene.textureSetDefinitions;let p,y=0;if(_&&(y=m[_.definition]),m){p=function(t,e,r,n,i,s){const o=JSON.parse(JSON.stringify(t));return kr(o,e,r,n,i,s),o}(y,A,c,_.resource,r,e.layerScene.eslpk)}else p={pbrMetallicRoughness:{metallicFactor:0}};T.material=p,l.push(T)}return{dracoCompression:f,meshes:l,nodeIndex:o,center:a.obb&&a.obb.center||a.mbs&&[a.mbs[0],a.mbs[1],a.mbs[2]],transform:u}}function kr(t,e,r,n,i,s){for(const o in t)if(t[o]&&t[o].textureSetDefinitionId>=0){const a=e[t[o].textureSetDefinitionId],c="images/"+a.formats[0].format,l=Hr(a.formats,i),f={url:r+`/nodes/${n}/textures/${l.name}`,factor:void 0===t[o].factor?1:t[o].factor,format:l.format,mimeType:c};if(s){let t="";switch(l.format){case"dds":t="bin.dds";break;case"jpg":case"png":t=l.format}f.url+="."+t}t[o]=f}else g(t[o])&&kr(t[o],e,r,n,i,s)}function Hr(t,e){for(let r=0;r<=t.length;r++){const n=t[r].format;if("dds"===n&&e.hasExtension("WEBGL_compressed_texture_s3tc"))return t[r];if("jpg"===n||"png"===n)return t[r];if("ktx2"===n&&Br)return t[r]}return null}const Vr=[];class zr extends t.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Kt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.ye={},this.ge=[],this.ce=this.Re.bind(this)}getAnalysisMeshes(){if(!this.painter)return Vr;const t=this.painter.getPaintedMeshes();if(!t)return Vr;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&U(e,r),n.length&&U(e,n),i.length&&U(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.ge.length||super.needToRedraw())}drawOnInteracting(t,e,r){this.draw(e,r)}draw(t,e){const r=this.prepareCanvas();if(r&&!r.intersects(this.canvasExtent2D))return void this.completeRender();const{root:n,tiles:i}=this.layer.getTiles(),s=i.length;if(!i||!s)return void this.completeRender();this.be(),this.Ie();const{selectedTiles:o,leaves:a,requests:c}=this.Ne(n,i);c.length&&this.loadTiles(c),this.Se(o,a,e),this.we(),c.length||this.completeRender()}Ne(t,e){let r=[];this.Me();let n=0;const i=this.Oe(),s={};let o=!1,a=!1;for(let t=0;t<e.length;t++){const i=e[t],c=i.node;if(s[c.id])continue;s[c.id]=1;let l=!1;const f=this.getCachedTile(c.id);if(this.ve(c.id)?(n++,l=a=!0,this.tilesLoading[c.id].current=!0):f?(this.getTileOpacity(f)<1&&(l=a=!0),o=!0,i.selected=!0,i.data=f):this.painter.has(c)||(l=a=!0,r.push(c)),!l)continue;if(this.Ce(i))o=!0;else{this.xe(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Ue(t)),r.length>1&&(r.sort(Xr),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}Ue(t){const e=[],r={};let n;const i=[t],s=[];for(;i.length>0||s.length>0;){if(s.length>0){const t=s[s.length-1];if(t.Be===i.length){s.pop(),t===n&&(t.leave=!0,r[t.node.id]=1),e.push(t);continue}}const t=i.pop(),o=t.children;if(t.selected)if("add"===t.node.refine)r[t.node.id]=1,t.selectionDepth=s.length,e.push(t);else{if(t.selectionDepth=s.length,n=t,0===o.length){t.leave=!0,r[t.node.id]=1,e.push(t);continue}s.push(t),t.Be=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}Ce(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}xe(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Pe+1,n=[t.node];for(;n.length>0;){const i=n.pop().children;for(let s=0,o=i.length;s<o;s++){if((!i[s].content||!i[s].content.url)&&i[s].children&&i[s].children.length){n.push(i[s]);continue}const o=i[s].id;if(this.tileCache.has(o)){const r=this.layer.Le(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Pe<=r&&n.push(i[s])}}return e}Se(t,e,r){this.tileCache.markAll(!1);for(let e=0,r=t.length;e<r;e++){const r=t[e].data;r.current=!0,this.tileCache.add(t[e].node.id,r)}this.tileCache.shrink();const n={tiles:t,leaves:e};this.onDrawTileStart(n);const i=r&&r.renderTarget,s=r&&r.sceneFilter,o=this.painter.paint(t,e,s,i);this.layer.options.debug&&this.painter.paintRegion(t,{color:this.layer.options.debugOutline},s,i),this.onDrawTileEnd(n),o&&this.layer.fire("canvasisdirty",{renderCount:o})}onDrawTileStart(){}onDrawTileEnd(){}loadTiles(t){for(let e=0,r=t.length;e<r;e++){const r=t[e];this.tilesLoading[r.id]={current:!0,node:r},this.loadTile(r)}}loadTile(t){let e=t.content.url;if(C(e)){const r=x(e);return void this.De(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.wt,n=this.Fe[r];return new xr(e,r,n,this.ce).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Dr(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.wt];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=yt.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.ye[e],r?this.De(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.ye[e],this.onTileError(r,t)})),this.ye[e]=s}else this.De(e,null,t)}De(t,e,n){let i=this.o;i||(i=r.Util.getSupportedFormats(this.gl.gl||this.gl),this.o=i);const s={url:t,arraybuffer:e,rootIdx:n.wt,upAxis:n.jt,transform:n.matrix,supportedFormats:i};if(Dr(t)){const e=this.Fe[n.wt];if(s.i3sInfo=Gr(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!s.i3sInfo)return void this.onTileError({status:404},n)}this.workerConn.loadTile(this.layer.getId(),s,((e,r)=>{if(e)return void this.onTileError(e,n);const{magic:i}=r;"b3dm"===i||"pnts"===i||"i3dm"===i||"cmpt"===i?this.ge.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Ie(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.ge.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.ge.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ge(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.Ge(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ge(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.Ge(t,e,r,n)})),r++}}Ge(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.ke(n);e.memorySize=r,this.onTileLoad(t,e)}}ke(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.ke(t[r]));else t&&(e+=t.getMemorySize());return e}onTileLoad(t,e){this.layer&&(delete this.tilesLoading[e.id],this.layer.onTileLoad(t,e),this.He(e),this.setToRedraw(),this.layer.fire("tileload",{node:e}))}onTilesetLoad(t,e,r){this.layer&&(t.capabilities||t.layers&&t.layers[0]&&t.layers[0].capabilities?this.Ve(t,e,r):(delete this.tilesLoading[e.id],this.layer.onTilesetLoad(t,e,r)))}onTileError(t,e){if(!this.layer)return;const r=e.content.url;console.warn("failed to load 3d tile: "+r),console.warn(t),delete this.tilesLoading[e.id],this.ze(e),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}ze(e){const r={loadTime:t.Util.now(),current:!0,error:!0,node:e};this.tileCache.add(e.id,r)}He(e){const r={loadTime:t.Util.now(),current:!0,node:e};this.tileCache.add(e.id,r)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.options.services[t.node.wt].ajaxInMainThread){const t=this.ye[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.ye[e]}Me(){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.Xe(this.canvas,e)),this.regl=this.regl||c({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),this.painter=new Sr(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 r=this.layer.options||{};r=p({},r),delete r.offset,r.projection=t.getSpatialReference().getProjection().code;const n=this.layer.getId();e.addLayer(n,r,(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.we(!0),this.tileCache.reset(),this.tilesLoading={},super.clear()}clearCanvas(){this.regl&&this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas()}getTileOpacity(){return 1}getStencilValue(){return 0}we(t){this.Ye||(this.Ye=Date.now());const e=Date.now();if(t||!(e-this.Ye<this.layer.options.retireInterval)){this.Ye=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}Oe(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Xe(t,e){const r=["webgl","experimental-webgl"];let n=null;for(let i=0;i<r.length;++i){try{n=t.getContext(r[i],e)}catch(t){}if(n)break}return n}ve(t){return!!this.tilesLoading[t]}getI3DMMeshes(){return this.painter.getI3DMMeshes()}getPNTSMeshes(){return this.painter.getPNTSMeshes()}getB3DMMeshes(){return this.painter.getB3DMMeshes()}readBatchData(t,e,r){return be(t,e,0,r)}be(){if(!this.Ze)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.Ze){const i=this.Ze[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(yt.getJSON(n).then((t=>{delete this.Ze[n];const e=this.Fe[s];if(e){t.nodes?vr(e,t.nodes):(e[t.id]=t,vr(e,t.children));for(let t=0;t<i.length;t++)i[t]();this.setToRedraw()}else this.setToRedraw()}))),e++,e>=t)break}r.length&&Promise.all(r)}Re(t,e,r){this.Ze||(this.Ze={}),this.Ze[e]=this.Ze[e]||[],this.Ze[e].rootIdx=t,this.Ze[e].push(r),this.setToRedraw()}Ve(t,e,r){this.Fe||(this.Fe=[]);const n=e.wt;this.Fe[n]||(this.Fe[n]={});const i=this.Fe[n],s=this.layer.options.services[n];t.layers&&(t=t.layers[0],"/"!==r[r.length-1]&&(r+="/"),r+="layers/0"),i.version=+(s.i3sVersion||t.store.version),function(t,e,r,n,i,s){if(!i.layerScene){i.layerScene=t,i.nodesPerPage=t.nodePages&&t.nodePages.nodesPerPage||64,i.lodSelectionMetricType=t.nodePages&&t.nodePages.lodSelectionMetricType;let e=n;if(i.layerScene.eslpk=e.indexOf("3dSceneLayer.json")>=0,i.layerScene.eslpk){const t=n.lastIndexOf("/");e=t<0?"./":n.substring(0,t)}i.layerScene.baseUrl=e}return new xr(n,e,i,s).load()}(t,n,0,r,i,this.ce).then((t=>{this.onTilesetLoad(t,e,r)}))}}function Xr(t,e){return t.Pt-e.Pt}function Yr(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function Zr(t,e,r){return Math.sqrt(function(t,e,r){var n=X(Wr,r,t),i=Yr(jr,e,0),s=Yr(Kr,e,1),o=Yr(qr,e,2),a=J(i),c=J(s),l=J(o);W(i,i),W(s,s),W(o,o);var f=$r;f[0]=j(n,i),f[1]=j(n,s),f[2]=j(n,o);var u,h=0;f[0]<-a?h+=(u=f[0]+a)*u:f[0]>a&&(h+=(u=f[0]-a)*u);f[1]<-c?h+=(u=f[1]+c)*u:f[1]>c&&(h+=(u=f[1]-c)*u);f[2]<-l?h+=(u=f[2]+l)*u:f[2]>l&&(h+=(u=f[2]-l)*u);return h}(t,e,r))}const Wr=[],jr=[],Kr=[],qr=[],$r=[];const Jr=2*Math.PI;class Qr{constructor(t,e,r,n){this.west=t,this.south=e,this.east=r,this.north=n}static contains(t,e){var r=e[0],n=e[1],i=t.west,s=t.east;return s<i&&(s+=Jr,r<0&&(r+=Jr)),(r>i||me(r,i,1e-14))&&(r<s||me(r,s,1e-14))&&n>=t.south&&n<=t.north}static southwest(t,e){return e[0]=t.west,e[1]=t.south,e[2]=0,e}static northeast(t,e){return e[0]=t.east,e[1]=t.north,e[2]=0,e}static southeast(t,e){return e[0]=t.east,e[1]=t.south,e[2]=0,e}static northwest(t,e){return e[0]=t.west,e[1]=t.north,e[2]=0,e}}const tn=[0,0,1];function en(t,e){return ne(e,t[0],t[1],t[2])}class rn{constructor(t,e){this.normal=i.copy([],t),this.distance=e}static fromPointNormal(t,e,r){var n=-i.dot(e,t);return i.copy(r.normal,e),r.distance=n,r}}const nn=[],sn=[],on=[],an=[],cn=[],ln=[],fn=[],un=[],hn=[],_n=[],dn=new rn([1,0,0],0),En=[];class Tn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new Qr(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var r,n,s,o=0;if(!Qr.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,u=this.eastNormal,h=this.northNormal,_=i.subtract(En,t,a),d=i.dot(_,l),E=i.dot(_,f),T=i.subtract(En,t,c),m=i.dot(T,u),A=i.dot(T,h);d>0?o+=d*d:m>0&&(o+=m*m),E>0?o+=E*E:A>0&&(o+=A*A)}if(r=e[2],n=this.minimumHeight,r>(s=this.maximumHeight)){var p=r-s;o+=p*p}else if(r<n){var y=n-r;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;en(Qr.southwest(t,sn),e.southwestCornerCartesian),en(Qr.northeast(t,sn),e.northeastCornerCartesian),nn[0]=t.west,nn[1]=.5*(t.south+t.north),nn[2]=0;var r=en(nn,on),n=i.cross(cn,r,tn);i.normalize(e.westNormal,n),nn[0]=t.east;var s=en(nn,un),o=i.cross(cn,tn,s);i.normalize(e.eastNormal,o);var a,c=i.subtract(cn,r,s),l=i.normalize(an,c),f=t.south;if(f>0){nn[0]=.5*(t.west+t.east),nn[1]=f;var u=en(nn,hn);i.copy(_n,l);var h=rn.fromPointNormal(e.southwestCornerCartesian,e.westNormal,dn);mn(hn,_n,h,e.southwestCornerCartesian),a=de(u,ln)}else a=Ee(Qr.southeast(t,sn),ln);var _=i.cross(fn,a,c);i.normalize(e.southNormal,_);var d,E=t.north;if(E<0){nn[0]=.5*(t.west+t.east),nn[1]=E;var T=en(nn,hn);i.scale(_n,l,-1);var m=rn.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,dn);mn(hn,_n,m,e.northeastCornerCartesian),d=de(T,ln)}else d=Ee(Qr.northwest(t,sn),ln);var A=i.cross(fn,c,d);i.normalize(e.northNormal,A)}}function mn(t,e,r,n){var s=t,o=e,a=r.normal,c=i.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-r.distance-i.dot(a,s))/c;if(!(l<0))return n=i.scale(n,o,l),i.add(n,s,n)}}const An=new t.Extent(0,0,0,0),pn=new t.Extent(0,0,0,0),yn=[],gn=[],Rn=[],bn=[],In=new t.Point(0,0),Nn=[],Sn=new t.Coordinate(0,0),wn=n.identity([]);class Mn extends t.Layer{constructor(t,e){super(t,e),this.We(),this.ye={},this.je=[]}We(){let t=this.options.services.map((t=>t.url));this.Ke=t.map(((t,e)=>function(t,e){t=I(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:n.identity([]),wt:e,Pe:0}}(t,e))),this.fire("rootready",{roots:this.Ke.slice(0)})}getExtent(e){if(!e&&0!==e){const e=new t.Extent;for(let t=0;t<this.Ke.length;t++)if(this.Ke[t].boundingVolume){const r=this.boundingVolumeToExtent(this.Ke[t]);e._combine(r)}return e}return this.Ke[e]&&this.Ke[e].boundingVolume?this.boundingVolumeToExtent(this.Ke[e]):null}boundingVolumeToExtent(e){const r=e.boundingVolume.qe?wn:e.matrix,n=this.getMap();if(e.boundingVolume.region){const r=e.boundingVolume.region;return new t.Extent(b(r[0]),b(r[1]),b(r[2]),b(r[3]))}if(e.boundingVolume.sphere){const s=e.boundingVolume.sphere,o=le([],i.transformMat4([],s,r)),a=s[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new t.Extent(c,l)}if(e.boundingVolume.box){const o=e.boundingVolume.box,a=i.transformMat4([],o,r),c=new t.Coordinate(le([],a)),l=o.slice(3);s.multiply(l,s.fromMat4([],e.matrix),l);const f=i.length(l.slice(0,3)),u=i.length(l.slice(3,6)),h=i.length(l.slice(6,9)),_=Math.max(f,u,h),d=n.locate(c,-_,_),E=n.locate(c,_,-_);return new t.Extent(d,E)}return null}getRootTiles(){return this.Ke}getTiles(){const t=this.getRenderer();if(!t.ready)return this.$e(),{tiles:bn};const e=this.getMap(),r=e.cameraPosition;let n,s;if(e.getGLZoom)s=e.pointToDistance(r[2],0,e.getGLZoom()),Sn.set(r[0],r[1]),n=e.pointToCoord(Sn,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(r[2],0,t),Sn.set(r[0],r[1]),n=e.pointAtResToCoord(Sn,t)}this.Je=this.Je||[],i.set(this.Je,R(n.x),R(n.y),s),this.Qe=ne(this.Qe||[],this.Je[0],this.Je[1],this.Je[2]),this.tr=2*Math.tan(.5*R(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.Ke.length;e++){let r=1/0;const n=[this.Ke[e]],i=this.er(e);for(;n.length>0;){const e=n.pop();for(e.id||this.rr(e);c.level>=e.Pe;)c=c.parent;const s=this.nr(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.ir(l,t);if(!1===this.options.services[e.wt].alwaysShow)continue;if(!(0===s&&e.Pe<=r))continue;e.content&&(r=e.Pe)}e.Pt<1/0&&this.sr(e);const a=this.Le(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.ir(l,a),u){h&&"add"===e.refine&&this.ir(l,a),c=a;const r=f[0].parent;let i=!1;for(let s=0,o=f.length;s<o;s++){if(r){const e=t.getCachedTile(f[s].id);if(e&&e.error)continue;i=!0}else{i=!0,f[s].parent=e,f[s].jt=e.jt,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(C(t)||t.indexOf("i3s:")>=0?f[s].baseUrl=e.baseUrl:-1===t.indexOf("http://")&&-1===t.indexOf("https://")?f[s].content.url=e.baseUrl+t:f[s].baseUrl=t.substring(0,t.lastIndexOf("/")+1))}n.push(f[s])}!i&&h&&this.ir(l,a)}}}return{root:a,tiles:l}}ir(t,e){const{viewerRequestVolume:r}=e.node;r&&!function(t,e,r){if(r.region){const e=r.region;if(t[0]>=e[0]&&t[0]<=e[2]&&t[1]>=e[1]&&t[1]<=e[3])return!0}else{if(r.sphere)return On(r,e);if(r.box)return 0===vn(r,e)}return!1}(this.Je,this.Qe,r)||t.push(e)}Le(t,e){return{id:t.id,node:t,children:[],level:t.Pe,parent:e,content:t.content&&t.content.url}}rr(e){e.id=t.Util.GUID(),e.matrix=e.transform||n.identity([]),e.ar=this.cr(e),e.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(e)||(e.matrix=n.multiply(e.matrix,e.parent.matrix,e.matrix)),e.wt=e.parent.wt,void 0===e.Pe&&(e.Pe=e.parent.Pe+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.lr(e)}lr(t){const e=t.boundingVolume;if(!e||e.qe)return;const r=this.options.services[t.wt].heightOffset||0,s=this.options.offset,o=y(s)||s[0]||s[1];if(!t.boundingVolume||!r&&n.exactEquals(t.matrix,wn)&&!o)return;const{region:a,box:c,sphere:l}=e;if(a){const t=this.ur([b(a[0]),b(a[1])]);a[0]=R(t.x),a[1]=R(t.y);const e=this.ur([b(a[2]),b(a[3])]);a[2]=R(e.x),a[3]=R(e.y),a[4]+=r,a[5]+=r}else if(c||l){const e=c||l,n=i.transformMat4(yn,e,t.matrix),s=le(gn,n),o=this.ur([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=r,ne(e,R(s[0]),R(s[1]),s[2])}e.qe=!0}cr(t){return void 0===t.geometricError||!t.boundingVolume}sr(t){let e=t.parent;for(;e&&e.ar&&!(e.Pt<=t.Pt);)e.Pt=t.Pt,e=t.parent}onTileLoad(t,e){if(t.children&&(!e.children||!e.children.length)){e.children=t.children;const r=e.content.url;e.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const n=this.getRenderer();n&&n.setToRedraw()}}onTilesetLoad(t,e,r){if(!t)return void console.warn("invalid tileset at : "+r);const i=(t.asset&&t.asset.gltfUpAxis||e&&e.jt||this.options.services[e.wt].upAxis||"Y").toUpperCase();t.root.baseUrl=r.substring(0,r.lastIndexOf("/")+1);const s=r.indexOf("realspace/")>-1;t.asset&&t.asset.s3mType&&s&&(t.root.baseUrl+="data/path/");const o=t.asset.i3s;if(t.root.jt=i,e){const r=e.boundingVolume;p(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",r&&(e.boundingVolume=r);const i=t.root.transform;i&&(e.parent?o||(e.matrix=n.multiply([],e.parent.matrix,i)):e.matrix=i),this.lr(e),e.hr=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.ar=this.cr(e);const s=e.content&&(e.content.url||e.content.uri);s&&e.content.uri&&(e.content.url=e.content.uri,delete e.content.uri),o||!s||C(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.$e(),this.fire("loadtileset",{tileset:t,index:e.wt,url:r})}nr(t,e,r){if(t.Pt=1/0,0===t.Pe||t.ar)return 1;if(!this._r(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.wt].maximumScreenSpaceError;null==n&&(n=8);let i=this.dr(t);return 0===i&&t.parent&&(i=.5*(t.parent.Er||0)),i>=n?1:0}Vt(e,r){r||(r=new t.Point(0,0));const n=this.getMap();return n.getGLZoom?n.coordToPoint(e,n.getGLZoom(),r):n.coordToPointAtRes(e,n.getGLRes(),r)}_r(e,r,i){const o=e.id;let a=this.je[o];const{boundingVolume:c}=e,l=c.sphere,u=c.region,h=c.box;if(!a){let r,i,c;if(u){r=An.set(b(u[0]),b(u[1]),b(u[2]),b(u[3]));const t=r.getCenter(),e=this.Tr(t);r=r.convertTo((t=>this.Vt(t,In)),pn),c=u[4],i=u[5],a=this.je[o]=[[r.xmin,r.ymin,c*e[2]],[r.xmax,r.ymax,i*e[2]]],a.center=t}else if(l){const e=le(yn,l),r=new t.Coordinate(e),n=this.Vt(r,In).toArray(),i=this.Tr(r);n.push(e[2]*i[2]),a=this.je[o]=[n,l[3]*i[2]],a.center=r}else if(h){const r=le(yn,h),i=new t.Coordinate(r),c=this.Vt(i,In).toArray(),l=this.Tr(i);c.push(r[2]*l[2]);const f=h.slice(3);n.exactEquals(e.matrix,wn)||s.multiply(f,s.fromMat4(Nn,e.matrix),f);for(let t=0;t<f.length;t++)f[t]*=l[t%3],h[3+t]=f[t];a=this.je[o]=[...c,...f],a.center=i}}if(r){if(u)An.xmin=a[0][0],An.ymin=a[0][1],An.xmax=a[1][0],An.ymax=a[1][1];else if(l){const t=a[2];An.xmin=a[0][0]-t,An.ymin=a[0][1]-t,An.xmax=a[0][0]+t,An.ymax=a[0][1]+t}else if(h){const t=a[1],e=a[2];An.xmin=a[0][0]-t,An.ymin=a[0][1]-e,An.xmax=a[0][0]+t,An.ymax=a[0][1]+e}if(!r.intersects(An))return!1}return u?_(i,a):l?function(t,e,r){E(t);for(var n=e[0],i=-e[1],s=0;s<6;s++)if((!r||"0"!==r.charAt(s))&&m(f[s],n)<i)return!1;return!0}(i,a):!!h&&function(t,e,r){E(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||d(f[n],e)))return!1;return!0}(i,a)}Tr(t){const e=this.getMap(),r=e.distanceToPointAtRes(100,100,e.getGLRes(),t);return i.set(Rn,r.x/100*1.01,r.y/100*1.01,r.y/100),Rn}ur(e){Array.isArray(e)&&(e=new t.Coordinate(e));let r=this.options.offset;if(y(r)&&(r=r(Array.isArray(e)?new t.Coordinate(e):e)),r[0]||r[1]){const t=this.getMap(),n=t.getGLRes(),i=t.coordToPointAtRes(e,n);return i._sub(r),t.pointAtResToCoord(i,n)}return e}er(e){const r=this.options.services[e].maxExtent;if(!r)return null;const n=this.Ke[e];return n.maxExtent||(n.maxExtent=new t.Extent(r).convertTo((t=>this.Vt(t)))),n.maxExtent}dr(t){const e=this.tr,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.mr||(t.mr=new Tn(t.boundingVolume.region));return t.mr.distanceToCamera(e,r)}(t,this.Qe,this.Je):t.boundingVolume.sphere?i=On(t.boundingVolume,this.Qe):t.boundingVolume.box&&(i=vn(t.boundingVolume,this.Qe));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Pt=i,t.Er=o,o}$e(){const t=this.getRenderer();t&&t.setToRedraw()}Qt(t){return this.je[t]}}function On(t,e){const r=t.sphere,n=i.dist(r,e),s=t.sphere[3];return n<s?0:n-s}function vn(t,e){const r=t.box;return Zr(i.set(yn,r[0],r[1],r[2]),s.set(Nn,r[3],r[4],r[5],r[6],r[7],r[8],r[9],r[10],r[11]),e)}Mn.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"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]}),Mn.registerRenderer("gl",zr),Mn.registerJSONType("Geo3DTilesLayer");class Cn{constructor(t,e,r){this.i=t,this.Ar=e||Ft,this.o=r,this.pr={"image/crn":Or.crn&&Or.crn(),"image/ktx2":Or.ktx2&&Or.ktx2(),"image/cttf":Or.ktx2&&Or.ktx2(),"draco":Or.draco&&Or.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.yr(t,e,r,n,i)):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.yr(t,i,r,n)}))}yr(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.gr(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.Ar(a,o.glb,{transferable:!0,requestImage:this.i,decoders:this.pr,supportedFormats:this.o,maxTextureSize:s});return c.load({skipAttributeTransform:!1}).then((e=>{e.url=`${t}-${r}-${n}`;const i=c.transferables;for(let t=0;t<o.transferables.length;t++)i.indexOf(o.transferables[t])<0&&i.push(o.transferables[t]);return{magic:"b3dm",count:o.count,transferables:i,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,gltf:e}}))}gr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported b3dm version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in b3dm header is inconsistent with b3dm's byte length, url: "+n;return console.warn(t),{error:t}}let o,a=i.getUint32(12,!0),c=i.getUint32(16,!0),l=i.getUint32(20,!0),f=i.getUint32(24,!0),u=28+e;l>=570425344?(u-=8,o=a,l=c,f=0,a=0,c=0):f>=570425344&&(u-=4,o=l,l=a,f=c,a=0,c=0);const h=[t];let _,d,E;if(a>0?(_=ye(t,u,a),u+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(u+=c),l>0&&(d=ge(t,u,l),u+=l,f>0)){const e=Re(0,u,f);E=t.slice(e.offset,e.offset+e.byteLength),u+=f,h.push(E)}const T=_.BATCH_LENGTH,m={};if(_&&_.BATCH_ID){m.BATCH_ID=Ie(_.BATCH_ID,t,undefined.offset,T);const e=m.BATCH_ID.array&&m.BATCH_ID.array.buffer;e&&h.indexOf(e)<0&&h.push(e)}return{count:o,transferables:h,featureTable:_,batchTable:d,batchTableBin:E,b3dm:m,glb:{buffer:t,byteOffset:u,byteLength:i.byteLength+i.byteOffset-u}}}Rr(){return null}}class xn{constructor(t,e,r,n){this.i=t,this.Ar=e||Ft,this.o=r,this.pr={"image/crn":Or.crn&&Or.crn(),"image/ktx2":Or.ktx2&&Or.ktx2(),"image/cttf":Or.ktx2&&Or.ktx2(),"draco":Or.draco&&Or.draco()},this.br=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.yr(t,e,r,n,i)):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.yr(t,i,r,n)}))}yr(t,e,r,n,i){return this.Ir(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Nr(e,r,n,t);if(o.error)return Promise.resolve(o);for(let t=0;t<s.length;t++)-1===o.transferables.indexOf(s[t])&&o.transferables.push(s[t]);return delete i.transferables,Promise.resolve({magic:"i3dm",count:o.count,transferables:o.transferables,featureTable:o.featureTable,batchTable:o.batchTable,batchTableBin:o.batchTableBin,i3dm:o.i3dm,gltf:i})}))}Ir(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.i,decoders:this.pr,supportedFormats:this.o,maxTextureSize:s},a=new DataView(e,r,n),c=32+a.getUint32(12,!0)+a.getUint32(16,!0)+a.getUint32(20,!0)+a.getUint32(24,!0);if(0===a.getUint32(28,!0)){let n=w(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?yt.getArrayBuffer(n,{}).then((t=>this.Sr(n,{buffer:t.data,byteOffset:0},o))):yt.getJSON(n,{}).then((t=>this.Sr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Sr(t,n,o)}}Sr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.Ar(n,e,r);return i.load({skipAttributeTransform:!0}).then((r=>{let n=0,s=0;return e.buffer&&(n=e.byteOffset||0,s=e.byteLength||0),r.url=`${t}-${n}-${s}`,{transferables:i.transferables,gltf:r}}))}Nr(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Oe(i,32+e,o),u={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;u.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;u.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.wr(new Uint16Array(t,n+c.offset,3*h),e,r)},o.push(u.POSITION.array.buffer)}if(a.BATCH_ID){u.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,h);const e=u.BATCH_ID.array&&u.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}if(a.NORMAL_UP){let{byteOffset:e}=a.NORMAL_UP;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.NORMAL_RIGHT.array.buffer)}else if(a.NORMAL_UP_OCT32P){let{byteOffset:e}=a.NORMAL_UP_OCT32P;u.NORMAL_UP={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Mr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_UP.array.buffer),e=a.NORMAL_RIGHT_OCT32P.byteOffset,u.NORMAL_RIGHT={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Mr(new Uint16Array(t,e+c.offset,2*h))},o.push(u.NORMAL_RIGHT.array.buffer)}if(a.SCALE){const{byteOffset:e}=a.SCALE;u.SCALE={byteStride:0,byteOffset:0,itemSize:1,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,h).slice()},o.push(u.SCALE.array.buffer)}else if(a.SCALE_NON_UNIFORM){const{byteOffset:e}=a.SCALE_NON_UNIFORM;u.SCALE_NON_UNIFORM={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.SCALE_NON_UNIFORM.array.buffer)}return{count:h,batchTable:l,batchTableBin:f,featureTable:a,i3dm:u,transferables:o}}Mr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Un(n,t[2*i],t[2*i+1],65535),r[3*i]=n[0],r[3*i+1]=n[1],r[3*i+2]=n[2];return r}wr(t,e,r){return Me(new Float32Array(t.length),t,e,r)}Rr(){return null}}function Un(t,e,r,n){if(t[0]=Bn(e,n),t[1]=Bn(r,n),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]))*Pn(e),t[1]=(1-Math.abs(e))*Pn(t[1])}return W(t,t)}function Bn(t,e){return e=function(t,e){if(null!=t)return t;return e}(e,255),function(t,e,r){return t<e?e:t>r?r:t}(t,0,e)/e*2-1}function Pn(t){return t<0?-1:1}class Ln{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.yr(t,e,r,n)):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.yr(t,i,r,n)}))}yr(t,e,r,n){return this.Or(e,r,n,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}))}Or(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Oe(i,e+28,o),u=a.QUANTIZED_VOLUME_OFFSET,h=a.QUANTIZED_VOLUME_SCALE,_=a.POINTS_LENGTH;let d,E={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){E=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,E.byteOffset+c.offset,E.byteLength);const e={attributes:E.properties,useUniqueIDs:!1};return this.vr||(this.vr=Or.draco()),this.vr(d,e).then((e=>{const r=e.attributes;!a.POSITION&&!a.POSITION_QUANTIZED||r.POSITION||r.POSITION_QUANTIZED||(r.POSITION=a.POSITION,r.POSITION_QUANTIZED=a.POSITION_QUANTIZED),!(a.RGB||a.RGBA||a.RGB565)||r.RGB||r.RGBA||r.RGB565||(r.RGB=a.RGB,r.RGBA=a.RGBA,r.RGB565=a.RGB565),!a.NORMAL&&!a.NORMAL_OCT16P||r.NORMAL||r.NORMAL_OCT16P||(r.NORMAL=a.NORMAL,r.NORMAL_OCT16P=a.NORMAL_OCT16P);const n=this.Cr(t,e.attributes,c.offset,_,o,u,h);if(e.attributes.BATCH_ID){const t=e.attributes.BATCH_ID.array;n.BATCH_ID={byteStride:0,byteOffset:0,itemSize:1,count:t.length,componentType:we(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=Dn(_);const e=n.BATCH_ID.array&&n.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return{count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:n,transferables:o}}))}const T=this.Cr(t,a,c.offset,_,o,u,h);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=Ie(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=Dn(_);const e=T.BATCH_ID.array&&T.BATCH_ID.array.buffer;e&&o.indexOf(e)<0&&o.push(e)}return Promise.resolve({count:_,batchTable:l,batchTableBin:f,featureTable:a,pnts:T,transferables:o})}Cr(t,e,r,n,i,s,o){const a={};if(e.POSITION){let{byteOffset:s,array:o}=e.POSITION;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.POSITION_QUANTIZED){let{byteOffset:c,array:l}=e.POSITION_QUANTIZED;c=c||0;const f=l?0:r;a.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:this.wr(l||new Uint16Array(t,c+f,3*n),s,o)},i.push(a.POSITION.array.buffer)}if(e.RGBA){let{byteOffset:s,array:o}=e.RGBA;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+4*n);o=new Uint8Array(e)}a.RGBA={byteStride:0,byteOffset:0,itemSize:4,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB){let{byteOffset:s,array:o}=e.RGB;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n);o=new Uint8Array(e)}a.RGB={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5121,array:o},i.push(o.buffer)}else if(e.RGB565){let{byteOffset:s,array:o}=e.RGB565;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint16Array(e)}a.RGB565={byteStride:0,byteOffset:0,itemSize:1,count:n,componentType:5123,array:o},i.push(o.buffer)}if(e.NORMAL){let{byteOffset:s,array:o}=e.NORMAL;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+3*n*4);o=new Float32Array(e)}a.NORMAL={byteStride:0,byteOffset:0,itemSize:3,count:n,componentType:5126,array:o},i.push(o.buffer)}else if(e.NORMAL_OCT16P){let{byteOffset:s,array:o}=e.NORMAL_OCT16P;s=s||0;const c=o?0:r;if(!o){const e=t.slice(s+c,s+c+2*n);o=new Uint8Array(e)}a.NORMAL_OCT16P={byteStride:0,byteOffset:0,itemSize:2,count:n,componentType:5121,array:o},i.push(o.buffer)}return a}wr(t,e,r){return Me(new Float32Array(t.length),t,e,r)}Rr(){return null}}function Dn(t){const e=v(t),r=new e(t);for(let e=0;e<t;e++)r[e]=e;return{byteStride:0,byteOffset:0,itemSize:1,count:t,componentType:we(e),array:r}}class Fn{constructor(t,e){this.i=t,this.Ar=e||Ft}load(t,e,r=0,n=0,i){return e?this.yr(t,e,r,n,i):yt.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.yr(t,i,r,n)}))}yr(t,e,r,n,i){n||(n=e.byteLength);const s=this.Ur(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Cn(this.i,this.Ar);else if("i3dm"===s[r].magic)n=new xn(this.i,this.Ar);else if("pnts"===s[r].magic)n=new Ln;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Fn(this.i,this.Ar)}o.push(n.load(t,e,s[r].offset,s[r].byteLength,i).then((t=>t)))}return Promise.all(o).then((t=>({magic:"cmpt",tiles:t})))}Ur(t,e,r,n){const i=new DataView(t,r,n),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported cmpt version: "+s+", url:"+e;return console.warn(t),{error:t}}if(16===i.byteLength)return[];const o=[],a=i.getUint32(12,!0);let c=16;for(let e=0;e<a;e++){const e=Ae(i,c),n=i.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+r,byteLength:n}),c+=n}return o}}if(e.transcoders){const r=t.Map.VERSION;if(r.indexOf("1.0.0-beta")>=0||r.indexOf("1.0.0-alpha")>=0){const r=e.transcoders.inject(l);t.registerWorkerAdapter("@maptalks/3dtiles",r)}else t.registerWorkerAdapter("@maptalks/3dtiles",(function(){return e.transcoders.inject(l)}))}else t.registerWorkerAdapter("@maptalks/3dtiles",l);export{Cn as B3DMLoader,Fn as CMPTLoader,Mn as Geo3DTilesLayer,B as Geo3DTilesUtil,Te as Geo3DTransform};"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.15.2");
|