@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.
package/dist/maptalks.3dtiles.js
CHANGED
|
@@ -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 @@
|
|
|
9
9
|
* MIT License
|
|
10
10
|
* https://github.com/mrdoob/three.js
|
|
11
11
|
*/
|
|
12
|
-
var a=[],c=0;c<6;c++)a[c]=[];var l=[];function f(t,e,r){h(t);for(var n=0;n<6;n++)if(!r||"0"!==r.charAt(n)){var i=a[n];if(l[0]=i[0]>0?e[1][0]:e[0][0],l[1]=i[1]>0?e[1][1]:e[0][1],l[2]=i[2]>0?e[1][2]:e[0][2],d(i,l)<0)return!1}return!0}function u(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=d(t,r);return!(l<=-c)}function h(t){var e=t,r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],c=e[5],l=e[6],f=e[7],u=e[8],h=e[9],d=e[10],E=e[11],T=e[12],m=e[13],A=e[14],p=e[15];_(a[0],s-r,f-o,E-u,p-T),_(a[1],s+r,f+o,E+u,p+T),_(a[2],s+n,f+c,E+h,p+m),_(a[3],s-n,f-c,E-h,p-m),_(a[4],s-i,f-l,E-d,p-A),_(a[5],s+i,f+l,E+d,p+A)}function _(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 d(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]}function E(t){return null==t}function T(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 m(t){return null!=t&&("function"==typeof t||null!==t.constructor&&t.constructor===Function)}function A(t){return"object"==typeof t&&!!t}function p(t){return t*Math.PI/180}function y(t){return t/Math.PI*180}function g(t){let e=document.createElement("a");return e.href=t,t=e.href,e=null,t}function R(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const b=[1,1,1,1,2,2,3,0];function I(t){const e=t.length;let r="";for(let n=0;n<e;){let i=t[n++];if(128&i){let r=b[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 N(t,e,r){return t[3*r]=e[0],t[3*r+1]=e[1],t[3*r+2]=e[2],t}function S(t){return t.flat?t.flat(1/0):t.reduce(((t,e)=>t.concat(e)),[])}function w(t){return t<256?Uint8Array:t<65536?Uint16Array:Uint32Array}function M(t){return 0===t.indexOf("data:")}function O(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 a=[],c=0;c<6;c++)a[c]=[];var l=[];function f(t,e,r){h(t);for(var n=0;n<6;n++)if(!r||"0"!==r.charAt(n)){var i=a[n];if(l[0]=i[0]>0?e[1][0]:e[0][0],l[1]=i[1]>0?e[1][1]:e[0][1],l[2]=i[2]>0?e[1][2]:e[0][2],d(i,l)<0)return!1}return!0}function u(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=d(t,r);return!(l<=-c)}function h(t){var e=t,r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],c=e[5],l=e[6],f=e[7],u=e[8],h=e[9],d=e[10],E=e[11],T=e[12],m=e[13],A=e[14],p=e[15];_(a[0],s-r,f-o,E-u,p-T),_(a[1],s+r,f+o,E+u,p+T),_(a[2],s+n,f+c,E+h,p+m),_(a[3],s-n,f-c,E-h,p-m),_(a[4],s-i,f-l,E-d,p-A),_(a[5],s+i,f+l,E+d,p+A)}function _(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 d(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]}function E(t){return null==t}function T(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 m(t){return null!=t&&("function"==typeof t||null!==t.constructor&&t.constructor===Function)}function A(t){return"object"==typeof t&&!!t}function p(t){return t*Math.PI/180}function y(t){return t/Math.PI*180}function g(t){let e=document.createElement("a");return e.href=t,t=e.href,e=null,t}function R(t){return Math.sign?Math.sign(t):0===(t=+t)||isNaN(t)?Number(t):t>0?1:-1}const b=[1,1,1,1,2,2,3,0];function I(t){const e=t.length;let r="";for(let n=0;n<e;){let i=t[n++];if(128&i){let r=b[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 N(t,e,r){return t[3*r]=e[0],t[3*r+1]=e[1],t[3*r+2]=e[2],t}function S(t){return t.flat?t.flat(1/0):t.reduce(((t,e)=>t.concat(e)),[])}function w(t){return t<256?Uint8Array:t<65536?Uint16Array:Uint32Array}function M(t){return 0===t.indexOf("data:")}function O(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 v(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 C=Object.freeze({__proto__:null,isNil:E,extend:T,isFunction:m,isObject:A,toRadian:p,toDegree:y,getAbsoluteURL:g,sign:R,stringFromUTF8Array:I,setColumn3:N,flatArr:S,getBatchIdArrayType:w,isBase64:M,base64URLToArrayBuffer:O,pushIn:v}),x=1e-6,U="undefined"!=typeof Float32Array?Float32Array:Array;function B(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 P(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 L(){var t=new U(3);return U!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function D(t){var e=t[0],r=t[1],n=t[2];return Math.sqrt(e*e+r*r+n*n)}function F(t,e,r){var n=new U(3);return n[0]=t,n[1]=e,n[2]=r,n}function G(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t}function k(t,e,r,n){return t[0]=e,t[1]=r,t[2]=n,t}function H(t,e,r){return t[0]=e[0]+r[0],t[1]=e[1]+r[1],t[2]=e[2]+r[2],t}function V(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[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,t[1]=e[1]*r,t[2]=e[2]*r,t}function Y(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 Z(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]}function W(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 j=V,K=z,q=D;function $(t,e,r,n,i){return t[0]=e,t[1]=r,t[2]=n,t[3]=i,t}function J(){var t=new U(4);return U!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function Q(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-_>x?(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}L(),function(){var t,e=(t=new U(4),U!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var tt,et=function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t};L(),F(1,0,0),F(0,1,0),J(),J(),tt=new U(9),U!=Float32Array&&(tt[1]=0,tt[2]=0,tt[3]=0,tt[5]=0,tt[6]=0,tt[7]=0),tt[0]=1,tt[4]=1,tt[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 et=0;function rt(t){return null==t}function nt(t){return!rt(t)}function it(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 st(t){switch(t){case 5120:return Int8Array;case 5121:return Uint8Array;case 5122:return Int16Array;case 5123:return Uint16Array;case 5124:return Int32Array;case 5125:return Uint32Array;case 5126:return Float32Array}throw new Error("unsupported bufferView's component type: "+t)}function ot(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function at(t){const e=function(t){return"undefined"!=typeof self?self.atob(t):window.atob(t)}(t.substring(t.indexOf(",")+1)),r=e.length,n=new Uint8Array(r);for(let t=0;t<r;t++)n[t]=e.charCodeAt(t);return n.buffer}const ct=[],lt=[],ft=[],ut=[0,0,0],ht=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}([]),_t=[1,1,1];function dt(t,e,r,n,i,s,o){const a=st(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 Et="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Tt(t,e,r){const n=new Uint8Array(t,e,r);return Et.decode(n)}const mt={get:function(t,e={}){e||(e={});const r=new AbortController,n=r.signal,i=it({},e);i.signal=n,i.method||(i.method="GET");const s=fetch(t,i).then((t=>{const r=this.i(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},i:(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",mt.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?mt.jsonp(t):((e=e||{}).responseType="json",mt.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+et++;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 At{constructor(t,e,r){this.o=t,this.decoders=e,this.l=r,this.images={},this.u={}}requestImageFromBufferURI(t,e,r){if(this.buffers[t.id]){const n=this.buffers[t.id],i=this.h(e,n);return this.getImageByBuffer(i,r)}if(this.u[t.id])return this.u[t.id].then((()=>{const n=this.buffers[t.id],i=this.h(e,n);return this.getImageByBuffer(i,r)}));if(ot(t.uri)){const n=this.buffers[t.id]=at(t.uri),i=this.h(e,n);return this.getImageByBuffer(i,r)}return this.u[t.id]=mt.getArrayBuffer(t.uri,null).then((n=>{const i=this.buffers[t.id]=n.data,s=this.h(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.l});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._(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.u[t.id]?this.u[t.id].then((()=>this.images[t.id])):this.u[t.id]=this._(t.id,e)}_(t,e){return new Promise(((r,n)=>{this.o(e,((i,s)=>{i?n(i):(URL.revokeObjectURL(e),this.images[t]=s,r(this.images[t]))}))}))}}const pt=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16];class yt{constructor(t,e,r){this.rootPath=t,this.gltf=e,this.T=!1,this.glbBuffer=r,this.buffers={},this.requests={},this.accessors={},this.m()}A(t,e){const r=this.gltf,n=r.accessors[e];if(void 0===n.bufferView)return this.accessors[n.id]=this.p(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.g(i).then((r=>{const{buffer:i,byteOffset:s}=r;return this.accessors[n.id]=this.p(t,e,i,s)}))}g(t){const e=this.gltf.buffers[t.buffer];if(this.buffers[e.id]){const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})}if(this.requests[e.id])return this.requests[e.id].then((()=>{const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})}));if("binary_glTF"!==t.buffer&&"KHR_binary_glTF"!==t.buffer&&e.uri){if(ot(e.uri)){const t=this.buffers[e.id]=at(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]=mt.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})}p(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.R(s.type),l=st(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.T)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.I(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=dt(t,r,s.count,c,f,a+(s.byteOffset||0),s.componentType)}else u.byteStride=0,u.array=this.I(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}m(){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)}I(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)}R(t){const e=pt.indexOf(t);return pt[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.g(e).then((n=>{const{buffer:i,byteOffset:s}=n,o=Tt(i,s+(e.byteOffset||0),r);return t.content=o,t}))}if(t.uri){if(ot(t.uri)){const e=at(t.uri),r=Tt(e,0,e.byteLength);return t.content=r,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return mt.get(e).then((e=>(t.content=e,t)))}}return Promise.resolve(t)}));return Promise.all(r).then((()=>t))}}class gt extends At{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 yt(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(nt(t.name)&&(e.name=t.name),nt(t.children)&&(e.children=t.children),nt(t.jointName)&&(e.jointName=t.jointName),nt(t.matrix)&&(e.matrix=t.matrix),nt(t.rotation)&&(e.rotation=t.rotation),nt(t.scale)&&(e.scale=t.scale),nt(t.translation)&&(e.translation=t.translation),nt(t.extras)&&(e.extras=t.extras),nt(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}(ct,e.translation||ut),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}(lt,e.rotation||ht),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}(ft,e.scale||_t);return B(i,n,i),B(t,r,i)}return U(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}N(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}S(t){if(t.bufferView||t.extensions&&(t.extensions.KHR_binary_glTF||t.extensions.binary_glTF)){const e=t.bufferView?t:t.extensions.KHR_binary_glTF||t.extensions.binary_glTF;t.extensions&&(t.mimeType=e.mimeType,t.width=e.width,t.height=e.height);const 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)}M(t){const e=this.gltf.textures[t];if(!e)return null;const r=this.gltf.images[e.source];return this.S(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 Rt extends At{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 yt(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 it(e,t),!nt(t.weights)&&this.gltf.meshes&&nt(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}M(t){const e=this.gltf.textures[t];if(!e)return null;const r=this.gltf.images[e.source];return this.S(r).then((t=>{if(!t)return null;const n={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};it(n,e);const i=nt(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return i&&(n.sampler=i),t.format&&(n.format=t.format),n}))}S(t){if(!nt(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.O(e,t)}return null}O(t,e){const r=this.h(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(r,e)}h(t,e,r){r=r||0;const n=t.byteOffset+r,i=t.byteLength;return new Uint8Array(e,n,i)}v(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++)(nt(t[r].input)||nt(t[r].output))&&(e.push(this.accessor.A("input",t[r].input)),e.push(this.accessor.A("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 bt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class It{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 It.readV1(n,e);if(2===i)return It.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=Nt(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=Nt(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 Nt(t,e,r){if(bt){const n=new Uint8Array(t,e,r);return bt.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=St[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 St=[1,1,1,1,2,2,3,0],wt=[0,0,0],Mt=[0,0,0,1],Ot=[1,1,1],vt={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},Ct={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},xt={C(t,e,r,n,i,s,o,a){const c=nt(t)?e.animations:[e.animations[0]],l={};for(let e=0;e<c.length;e++){const f=c[e],u=f.name||e;if(nt(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.U(i,f.samplers[e.sampler],n,1),l.translation=F(wt,i)):"rotation"===e.target.path?(this.B(s,f.samplers[e.sampler],n,1),l.rotation=tt(Mt,s)):"scale"===e.target.path?(this.U(o,f.samplers[e.sampler],n,1),l.scale=F(Ot,o)):"weights"===e.target.path&&a&&(this.U(a,f.samplers[e.sampler],n,a.length),l.weights=a)}}return l},U(t,e,r,n){switch(e.interpolation){case"LINEAR":{const i=this.P(Ct,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.P(Ct,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.P(Ct,e,r,3*n);i&&(t=this.L(t,i,e.input.array,3*n));break}}return t},B(t,e,r){switch(e.interpolation){case"LINEAR":{const n=this.P(Ct,e,r,1);n&&J(t,n.PREVIOUS,n.NEXT,n.INTERPOLATION);break}case"STEP":{const n=this.P(Ct,e,r,1);n&&(t=q(t,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this.P(Ct,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.L(t,n,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},D(t,e){const 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},P(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.D(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},L(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 G(wt,...vt.TRANSLATION),q(Mt,...vt.ROTATION),G(Ot,...vt.SCALE),this.C(n,t,e,r,wt,Mt,Ot,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?nt(e)?r[e]:r[Object.keys(r)[0]]:null}};let Ut=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(Sr){}t&&"undefined"!=typeof createImageBitmap&&(Ut=!0)}const Bt="undefined"==typeof document?null:document.createElement("canvas");class Pt{constructor(t,e,r){if(this.options=r||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:r,glbBuffer:n}=It.read(e.buffer,e.byteOffset,e.byteLength);this.F(t,r,n)}else this.F(t,e);this.G=new yt(this.rootPath,this.gltf,this.glbBuffer),this.k()}k(){const t=this.gltf.extensionsRequired;if(t){if(t.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(t.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}H(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.G.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then((e=>(t.KHR_techniques_webgl=e,t))):Promise.resolve(t)}load(t){t=t||{};const e=this.V(t),r=this.X(),n=this.Y(),i=this.H();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 xt.getAnimationClip(t,e,r,n)}static getAnimationTimeSpan(t,e){return xt.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return st(t)}static readInterleavedArray(t,e,r,n,i,s,o){return dt(t,e,r,n,i,s,o)}F(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=Ut?Gt.bind(this):this.options.requestImage||Lt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new Rt(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 gt(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"))}Z(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(r=t.children[0])&&isFinite(r)||function(t){return!rt(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.Z(r,e)}));t.children=n}var r;return t}V(t){return this.W(t).then((t=>{const e=this.scenes=[];let r;for(const e in t)t[e]=this.Z(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.N(this.gltf.materials);n.materials=t}return n}))}W(t){return this.j(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}))}K(){this.skins=[];const t=[];return this.adapter.iterate(((e,r,n)=>{t.push(this.q(r).then((t=>{t.index=n,this.skins.push(t)})))}),"skins"),t}q(t){const e=t.inverseBindMatrices;return this.adapter.accessor.A("inverseBindMatrices",e).then((e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t)))}X(){const t=this.gltf.animations;return nt(t)?this.adapter.getAnimations(t):null}j(t){this.meshes={};let e=[];return this.adapter.iterate(((r,n,i)=>{e.push(this.$(n,t).then((t=>{t.index=i,this.meshes[r]=t})))}),"meshes"),e=e.concat(this.K()),Promise.all(e)}$(t,e){const r=t.primitives.map((t=>this.J(t,e))).filter((t=>!!t));return Promise.all(r).then((e=>{const r={};return it(r,t),r.primitives=e,r}))}Y(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const r in t)e.push(this.adapter.M(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}))}J(t,e){let r;const n=[],i=t.extensions;if(nt(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.A(`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.G.g(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.A(t,e[t]);r&&n.push(r)}if(nt(t.indices)){const e=this.adapter.accessor.A("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),k(t,t,s),z(r,r,i),k(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=nt(t.mode)?t.mode:4,nt(t.extras)&&(s.extras=t.extras),s}))}}function Lt(t,e){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!Bt)return void e(new Error("There is no canvas to draw image!"));Bt.width=r.width,Bt.height=r.height;const t=Bt.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 Dt,Ft;function Gt(t,e){Dt||(Dt=new OffscreenCanvas(2,2),Ft=Dt.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;kt(r)||(r=Ht(r)),kt(n)||(n=Ht(n));const i=this.options.maxTextureSize;i&&(r=Math.min(i,r),n=Math.min(i,n)),Dt.width=r,Dt.height=n,Ft.drawImage(t,0,0,r,n),t.close();const s=Ft.getImageData(0,0,r,n);e(null,{width:r,height:n,data:new Uint8Array(s.data)})})).catch((t=>{console.warn(t),e(t)}))}function kt(t){return 0==(t&t-1)&&0!==t}function Ht(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}const Vt="undefined"==typeof document?null:document.createElement("canvas");class zt extends i.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(!Vt)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if(Xt(t.width)&&Xt(t.height))return t;let e=t.width,r=t.height;Xt(e)||(e=Yt(e));Xt(r)||(r=Yt(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);Vt.width=t.width,Vt.height=t.height;const n=Vt.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 Xt(t){return 0==(t&t-1)&&0!==t}function Yt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}class Zt{constructor(t,e){this.max=t,this.currentSize=0,this.onRemove=e,this.reset()}reset(){if(this.data){const t=this.data.values();for(const e of t)this.onRemove(e)}return this.data=new Map,this.currentSize=0,this}clear(){this.reset(),delete this.onRemove}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const 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 Wt(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=[];jt(n[r],i,t,e)}}}function jt(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++)jt(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 Kt(t,e,r){let{componentType:n,byteOffset:i,byteStride:s,itemSize:o}=e;const a=e.array.buffer,c=n?Pt.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 $t=new Array(3),Jt=new Array(3),Qt=[40680631590769,40680631590769,40408299984661.445];function te(t,e,r,n){const i=Qt,s=Math.cos(r);$t[0]=s*Math.cos(e),$t[1]=s*Math.sin(e),$t[2]=Math.sin(r),fe($t,$t),V(Jt,i,$t);const o=Math.sqrt(Y($t,Jt));var a,c,l;return c=Jt,l=o,(a=Jt)[0]=c[0]/l,a[1]=c[1]/l,a[2]=c[2]/l,z($t,$t,n),k(t,Jt,$t)}const ee=[1/6378137,1/6378137,1/6356752.314245179],re=[1/40680631590769,1/40680631590769,1/40408299984661.445],ne=new Array(3),ie=new Array(3),se=new Array(3);function oe(t,e){const r=re,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(ae,e,E);if(d<i)return isFinite(E)?T:void 0;const m=n[0],A=n[1],p=n[2],y=ce;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)*le(e)/(.5*le(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}(ne,e,ee,r,.1);let i=j(ie,n,r);i=fe(i,i);const s=W(se,e,n),o=Math.atan2(i[1],i[0]),a=Math.asin(i[2]),c=R(Y(s,e))*le(s);return t[0]=y(o),t[1]=y(a),t[2]=c,t}const ae=new Array(3),ce=new Array(3);function le(t){return L(t)}function fe(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 ue(t,e){return V(e,t,re),X(e,e)}function he(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,X(e,e)}var _e=Object.freeze({__proto__:null,radianToCartesian3:te,cartesian3ToDegree:oe,normalizeCartesian:fe,geodeticSurfaceNormal:ue,geodeticSurfaceNormalCartographic:he});function de(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 Ee(t,e){let r="";for(let n=0;n<4;n++){const i=t.getUint8(e+n);r+=String.fromCharCode(i)}return r}const Te="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function me(t,e,r){const n=new Uint8Array(t,e,r);return Te?JSON.parse(Te.decode(n)):JSON.parse(I(n))}function Ae(t,e,r){const n=new Uint8Array(t,e,r);return Te?JSON.parse(Te.decode(n)):JSON.parse(I(n))}function pe(t,e,r){return{offset:e,byteLength:r}}function ye(t,e,r,n){const{byteOffset:i,componentType:s,type:o}=t,{ctor:a,type:c}=function(t){return be[t]}(s),l=function(t){if(!t)return 1;return Re[t]}(o);return{byteStride:0,byteOffset:i+r,itemSize:l,count:n*l,componentType:c,array:new a(e,r+i,n*l)}}function ge(t,e,r,n){t.componentType||(t.componentType="UNSIGNED_SHORT");const i=ye(t,e,r,n);return i.array.buffer.byteLength!==e.byteLength&&(i.array=i.array.slice()),i}const Re={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const be={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function Ie(t){for(let e in be)if(t===be[e].ctor)return be[e].type;throw new Error("unrecognized ctor:"+t)}function Ne(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 Se(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=me(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=Ae(a,e,s),e+=s);const h=pe(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 we={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Me={},Oe={east:[],north:[],up:[],west:[],south:[],down:[]},ve=[],Ce=[],xe=[];const Ue=[0,0,0];function Be(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 Pe=(Ge={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"}}[Le="east"][De="north"],Me[ke=Le+De]?Fe=Me[ke]:(Fe=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)<=C*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(n-o)<=C*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=C*Math.max(1,Math.abs(i),Math.abs(a))}(t,Ue))F(ve,we[Le]),F(Ce,we[De]),F(xe,we[Ge]);else if(de(t[0],0,1e-14)&&de(t[1],0,1e-14)){var n=R(t[2]);F(ve,we[Le]),"east"!==Le&&"west"!==Le&&z(ve,ve,n),F(Ce,we[De]),"east"!==De&&"west"!==De&&z(Ce,Ce,n),F(xe,we[Ge]),"east"!==Ge&&"west"!==Ge&&z(xe,xe,n)}else{ue(t,Oe.up);var i=Oe.up,s=Oe.east;s[0]=-t[1],s[1]=t[0],s[2]=0,X(Oe.east,s),Z(Oe.north,i,s),z(Oe.down,Oe.up,-1),z(Oe.west,Oe.east,-1),z(Oe.south,Oe.north,-1),ve=Oe[Le],Ce=Oe[De],xe=Oe[Ge]}return r[0]=ve[0],r[1]=ve[1],r[2]=ve[2],r[3]=0,r[4]=Ce[0],r[5]=Ce[1],r[6]=Ce[2],r[7]=0,r[8]=xe[0],r[9]=xe[1],r[10]=xe[2],r[11]=0,r[12]=t[0],r[13]=t[1],r[14]=t[2],r[15]=1,r},Me[ke]=Fe),Fe);var Le,De,Fe,Ge,ke;const He=[],Ve=[],ze=[],Xe=[],Ye=[],Ze=[],We=[],je={x:0,y:0},Ke={x:0,y:0},qe=Math.PI/180;const $e={"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:Je,getTextureMinFilter:Qe,getTextureWrap:tr,getMaterialType:er,getMaterialFormat:rr,getPrimitive:nr,getUniqueREGLBuffer:ir}=r.reshader.REGLHelper,sr=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],or=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:ar,logoutIBLResOnCanvas:cr,getIBLResOnCanvas:lr,getPBRUniforms:fr}=r.reshader.pbr.PBRUtils,ur={factor:0,units:0},hr={specularStrength:0,materialShininess:1},_r=[1,1,1],dr=r.mat4.identity([]),Er=t=>t.material instanceof r.reshader.PhongMaterial,Tr=t=>t.material instanceof r.reshader.pbr.StandardMaterial,mr=[!0,!0,!0,!0],Ar=[],pr=new i.Coordinate(0,0),yr=[],gr=[],Rr={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"};class br{constructor(t,e){this.tt=e,this.et=e.getRenderer().canvas,this.rt=new i.SpatialReference,this.nt=t,this.it=new r.reshader.Renderer(t),this.st={},this.ot={},this.at={},this.ct={},this.lt={},this.ft={},this.ut={},this.ht=new r.reshader.Scene,this._t=new r.reshader.Scene,this.dt=new r.reshader.Scene,this.Et=new r.reshader.Scene,this.Tt=new r.reshader.ResourceLoader(t.texture(2)),this.At=this.yt.bind(this),this.gt=new r.reshader.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.Rt(),this.bt=new r.reshader.KHRTechniquesWebglManager(this.nt,this.It(),this.Tt)}getI3DMMeshes(){return this.lt}getPNTSMeshes(){return this.ct}getB3DMMeshes(){return this.at}getMap(){return this.tt.getMap()}paint(t,e,r,n){const i=this.getMap();if(!t.length||!i)return;const s=this.Nt(),o=i.projViewMatrix,a=this.tt.options.services,c=[],l=[];let u=[];const 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.ft[n.id]&&(i=this.ft[n.id],i=S(i));let d=a[n.wt].polygonOffset||ur;m(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&&!f(o,i[a].getBoundingBox()))continue;const c=i[a].properties.magic;"b3dm"===c?u.push(i[a]):"pnts"===c?h.push(i[a]):"i3dm"===c&&_.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.bt.getExcludeFilter();d+=this.Ot(this.vt,s,[r,Er,E],n,l,u,_),d+=this.Ot(this.Ct,s,[r,Tr,E],n,l,u,_),this.bt.forEachShader(((t,e,i)=>{const s=this.Nt(i);d+=this.Ot(t,s,[r,e],n,l,u,_)})),this._t.setMeshes(h);const T=this.xt();return d+=this.it.render(this.Ut,T,this._t,n&&n.fbo),d}Ot(t,e,r,n,i,s,o){t.filter=r.filter((t=>!!t)),e.debug=!1,this.ht.setMeshes(i),e.stencilEnable=!1,e.debug=!1,e.cullFace="back",e.colorMask=mr;let a=0;return this.ht.setMeshes(s),a+=this.it.render(t,e,this.ht,n&&n.fbo),e.stencilEnable=!1,this.dt.setMeshes(o),a+=this.it.render(t,e,this.dt,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&&!f(o,n.getBoundingBox())||a.push(n))}this.Dt.filter=n,this.Et.setMeshes(a);const c=this.Ft(r);this.it.render(this.Dt,c,this.Et,i&&i.fbo)}deleteTile(t){const e=t.node.id;this.Gt(e)}Gt(t){const e=this.ot[t];e&&(e.geometry.dispose(),e.dispose(),delete this.ot[t]);let r=this.at[t]||this.ct[t]||this.lt[t]||this.ft[t]||this.st[t];this.ft[t]?this.kt(t):r&&(this.Ht(r),delete this.at[t],delete this.ct[t],delete this.lt[t],delete this.st[t])}kt(t){let e=this.ft[t];e=S(e);for(let t=0;t<e.length;t++){const{id:r}=e[t].properties;this.Gt(r)}delete this.ft[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.ut[e];t&&(t.refCount--,t.refCount<=0&&(t.geometry.dispose(),t.material.dispose(),delete this.ut[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.tt;cr(t.getRenderer().canvas,t.getMap());for(const t in this.ft)this.kt(t);this.ft={};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.lt)this.Gt(t);this.lt={};for(const t in this.st)this.Gt(t);this.st={};for(const t in this.ot)this.Gt(t);this.ot={},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.bt.dispose()}Lt(t){if(!t.boundingVolume||!t.boundingVolume.region)return null;if(this.ot[t.id])return this.ot[t.id];const e=t.boundingVolume.region;let n=new i.Coordinate(y(e[0]),y(e[1])),s=new i.Coordinate(y(e[2]),y(e[3]));n=this.Vt(n),s=this.Vt(s);const o=n.add(s).zt(.5);n._sub(o),s._sub(o);const a=this.Xt(e[4],e[5]),c=a.x,l=a.y,f=[n.x,n.y,l,s.x,n.y,l,s.x,s.y,l,n.x,s.y,l,n.x,n.y,c,s.x,n.y,c,s.x,s.y,c,n.x,s.y,c],u=new r.reshader.Geometry({aPosition:f},[0,1,1,2,2,3,3,0,0,4,1,5,2,6,3,7,4,5,5,6,6,7,7,4],0,{primitive:"lines"});u.generateBuffers(this.nt);const h=new r.reshader.Mesh(u),_=r.mat4.identity([]);return h.setLocalTransform(r.mat4.translate(_,_,[o.x,o.y,0])),this.ot[t.id]=h,h}St(t){return this.at[t.id]||this.ct[t.id]||this.lt[t.id]||this.ft[t.id]}has(t){return this.St(t)||this.st[t.id]}createPntsMesh(t,e,n,i){if(this.ct[e]){const t=this.ct[e];return console.warn(`pnts mesh with id(${e}) was already created.`),i(null,{id:e,mesh:t}),t}const{pnts:s,featureTable:o,rootIdx:a}=t,c=o.POINTS_LENGTH,l=new r.reshader.Geometry(s,null,c,{primitive:"points",positionAttribute:"POSITION"});l.generateBuffers(this.nt);const f={};s.POSITION?f.HAS_POSITION=1:s.POSITION_QUANTIZED&&(f.HAS_POSITION_QUANTIZED=1),s.RGB?f.HAS_RGB=1:s.RGBA?f.HAS_RGBA=1:s.RGB565&&(f.HAS_RGB565=1),(s.NORMAL||s.NORMAL_OCT16P)&&(f.HAS_NORMAL=1,s.NORMAL_OCT16P&&(f.HAS_NORMAL_OCT16P=1)),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map((t=>t/255)));const{rtcCenter:u,rtcCoord:h}=t,_=this.Yt(h),d=this.Zt(n,u,h);r.mat4.multiply(d,d,_);const E=this.tt.options.services[a],T=new r.reshader.Mesh(l);return T.properties.magic="pnts",T.properties.id=e,T.properties.count=c,T.properties.batchTable=t.batchTable,T.properties.batchTableBin=t.batchTableBin,T.setDefines(f),Object.defineProperty(T.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:E&&E.pointColor||[1,1,1,1]}}),Object.defineProperty(T.uniforms,"pointSize",{enumerable:!0,get:function(){return E&&E.pointSize||2}}),Object.defineProperty(T.uniforms,"pointOpacity",{enumerable:!0,get:function(){return E&&E.pointOpacity||1}}),T.setLocalTransform(d),this.ct[e]=T,i(null,{id:e,mesh:[T]}),[T]}createI3DMMesh(t,e,n,i){if(this.lt[e]){const t=this.lt[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.st[e]||i(null,{id:e,mesh:t}),t}const s=this.Wt(n.jt),{i3dm:o,featureTable:a,gltf:c,batchTable:l,batchTableBin:f,count:u}=t,h=a.INSTANCES_LENGTH,{rtcCenter:_,rtcCoord:d}=t,E=this.Yt(d),T=this.Zt(n,_,d),{POSITION:m,NORMAL_UP:A,NORMAL_RIGHT:p,SCALE:y,SCALE_NON_UNIFORM:g,INSTANCE_ROTATION:R}=o,b={"instance_vectorA":new Float32Array(4*h),"instance_vectorB":new Float32Array(4*h),"instance_vectorC":new Float32Array(4*h)},I=new Float32Array(3),S=new Float32Array(3),w=[],M=new Float32Array(1),O=new Float32Array(3),v=[],C=[],x=[],U=[],B=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?Pt.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)}}(m,((t,e)=>{A?(Kt(S,p,e),Kt(I,A,e),r.vec3.cross(w,S,I),r.vec3.normalize(w,w),N(v,S,0),N(v,I,1),N(v,w,2),r.quat.fromMat3(C,v)):R?(Kt(B,R,e),r.quat.fromMat3(C,B)):r.quat.identity(C),y?(Kt(M,y,e),r.vec3.set(x,M[0],M[0],M[0])):g?(Kt(O,g,e),r.vec3.set(x,...O)):r.vec3.set(x,1,1,1),r.mat4.fromRotationTranslationScale(U,C,t,x),qt(b.instance_vectorA,e,U,0),qt(b.instance_vectorB,e,U,1),qt(b.instance_vectorC,e,U,2)}));const P={};for(const t in b)P[t]={buffer:this.nt.buffer({dimension:b[t].length/h,data:b[t]}),divisor:1};const L=this.tt.options.services[n.wt].shader||"phong";let D=0,F=!0;const G=[];return Wt(c,((t,i,o,a)=>{let{geometry:c,material:_}=this.Kt(t,i,o,a,n,!0,L);_&&!_.isReady()&&(F=!1,D++);const d=new r.reshader.InstancedMesh(P,h,c,_);d.properties.magic="i3dm",d.properties.id=e,d.properties.count=u,d.properties.batchTable=l,d.properties.batchTableBin=f;const m=this.qt(t,c,_,n.wt,a),A=r.mat4.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.mat4.multiply(A,A,t.matrices[e]);r.mat4.multiply(A,s,A),d.setPositionMatrix(A),r.mat4.multiply(E,T,E),d.setLocalTransform(E),d.setDefines(m),d.properties.polygonOffset={offset:0,factor:0},G.push(d)})),F?(this.lt[e]=G,i(null,{id:e,mesh:G})):(this.st[e]={meshes:G,count:D},G.$t=i),G}createB3DMMesh(t,e,n,s){if(this.at[e]||this.st[e]){const t=this.at[e];return console.warn(`mesh with id(${e}) was already created.`),this.st[e]||s(null,{id:e,mesh:t}),t}const o=t.gltf.asset&&"i3s"===t.gltf.asset.generator;let a;if(n.maxExtent){const t=new i.Extent(n.maxExtent).convertTo((t=>this._pointToPrj(t)));a=[t.xmin,t.ymin,t.xmax,t.ymax]}const c=this.Wt(n.jt),l=t.gltf,{center:f,coord:u}=l.extensions.CESIUM_RTC,h=this.tt.options.services[n.wt].heightOffset||0;let _;if(h&&u&&(u[2]+=h),o){const{i3sProjCenter:t}=l.extensions.CESIUM_RTC;_=this.Jt(t,n.wt)}else _=this.Yt(u,n.wt);const d=this.tt.options.services[n.wt].shader||"phong",E=[];let T=0,m=!0;return Wt(l,((i,s,l,h)=>{let{geometry:A,material:p}=this.Kt(i,s,l,h,n,!1,d);p&&!p.isReady()&&(m=!1,T++);const y=new r.reshader.Mesh(A,p);y.properties.magic="b3dm",y.properties.id=e,y.properties.batchTable=t.batchTable,y.properties.batchTableBin=t.batchTableBin,y.properties.count=t.featureTable.BATCH_LENGTH;const g=this.qt(i,A,p,n.wt,h);y.setDefines(g),a&&(g.USE_MAX_EXTENT=1,y.setUniform("maxPrjExtent",a));let R=r.mat4.identity([]);if(i.matrices&&i.matrices.length)for(let t=0;t<i.matrices.length;t++)r.mat4.multiply(R,R,i.matrices[t]);const b=o?dr:this.Zt(n,f,u);r.mat4.multiply(R,c,R),r.mat4.multiply(R,_,R),r.mat4.multiply(R,b,R),y.setLocalTransform(R),E.push(y)})),m?(this.at[e]=E,s(null,{id:e,mesh:E})):(this.st[e]={meshes:E,count:T},E.$t=s),E}Zt(t,e,n){const s=this.getMap(),o=this.tt.options.services[t.wt].heightOffset||0,a=new i.Coordinate(n),c=s.distanceToPointAtRes(100,0,s.getGLRes(),a).x/100;let l=t.matrix?r.mat4.copy([],t.matrix):r.mat4.identity([]);if(e){Be(l,r.vec3.transformMat4(Ar,e,l),l)}const f=function(t,e,r,n,i,s,o){e=F(He,e);const a=te(He,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}(Ve,r),l=n.ellipsoid;var f;f=0===K(c)?G(ze,0,0,-6378137):oe(ze,c),je.x=f[0],je.y=f[1];const u=n.project(je,Ke);Xe[0]=u.x/i,Xe[1]=u.y/i,Xe[2]=(f[2]+o)*s;const h=Pe(a,l,Ye),_=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}(Ze,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}(We,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 Be(t,Xe,E),t}(l,n,l,s.getProjection(),s.getGLRes(),c,o),u=function(t,e){return G(t,e[12],e[13],e[14]),t}(gr,f);let h=this.tt.options.offset;if(m(h)){h=h(this.tt.Qt(t.id).center)}return r.vec3.set(yr,h[0],h[1],0),r.vec3.sub(u,u,yr),Be(f,u,f),f}createCMPTMesh(t,e,r,n){if(this.ft[e]){const t=this.ft[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.ft[e]=s,n(null,{id:e,mesh:s}),s}qt(t,e,r,n,i){const s=("phong"===(this.tt.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=$e);const c=n.url+"-"+e+"-"+r;if(this.ut[c])return this.ut[c].refCount++,this.ut[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.tt.options.services[i.wt].fillEmptyDataInMissingAttribute&&(f.desc.fillEmptyDataInMissingAttribute=!0)}else{f=this.re(t,s,Rr);const e=this.tt.options.services[i.wt].material;l=this.ne(t.material,n,o,e||hr)}l&&!l.isReady()?l.ie=i.id:l||(l=this.gt);const h={refCount:1,geometry:f,material:l};return f.properties.url=c,this.ut[c]=h,h}ee(t,e,r,n){const{geometry:i,material:s}=this.bt.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=ir(this.nt,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.reshader.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":nr(t.mode)});return o.generateBuffers(this.nt,{excludeElementsInVAO:e}),o}Yt(t){const e=r.mat4.identity([]),n=this.getMap(),i=this.se();pr.x=t[0],pr.y=t[1];const s=n.distanceToPointAtRes(100,100,n.getGLRes(),pr);return r.vec3.set(i,s.x/100*1.01,s.y/100*1.01,s.y/100),r.mat4.scale(e,e,i),e}Jt(t,e){const n=r.mat4.identity([]),s=this.getMap(),o=this._prjToPoint(new i.Coordinate(t)),a=this.se(),c=1/(s.getGLZoom?s.getResolution(s.getGLZoom()):s.getGLRes()),l=r.vec3.set(gr,o.x,o.y,c*t[2]);r.mat4.translate(n,n,l);const f=this.tt.options.services[e].heightOffset;if(f){const e=s.getProjection().unproject(new i.Coordinate(t)),o=s.distanceToPointAtRes(100,100,s.getGLRes(),e).y/100;r.mat4.translate(n,n,[0,0,f*o])}return r.mat4.scale(n,n,r.vec3.scale([],a,c)),n}Rt(){const t={x:0,y:0,width:()=>this.et?this.et.width:1,height:()=>this.et?this.et.height:1};this.Dt=new r.reshader.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\nuniform vec3 color;\nvoid main() {\n gl_FragColor = vec4(color, 1.0);\n}\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.mat4.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],n=[];this.Ut=new r.reshader.MeshShader({vert:"const float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n\n\nvoid main() {\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_POSITION\n\n vec3 localPos = POSITION;\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.mat4.multiply(n,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,n)=>r.mat3.fromMat4(e,n.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const i=this.It();this.vt=new r.reshader.PhongShader({extraCommandProps:i}),this.Ct=new r.reshader.pbr.StandardShader({extraCommandProps:i});const s=this.tt;ar(s.getRenderer().canvas,this.nt,s.getMap())}It(){return{viewport:{x:0,y:0,width:()=>this.et?this.et.width:1,height:()=>this.et?this.et.height:1},colorMask:(t,e)=>e.colorMask||mr,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(),n=e.getLightManager(),i=(n&&n.getDirectionalLight()||{}).direction||[1,1,-1],s=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:s,lightDir:r.vec3.normalize(i,i)}}Nt(){const t=this.getMap(),e=this.tt.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=lr(e),i=fr(t,r,n);return T(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 o=T({},i);if(s.baseColorTexture){const t=e.textures[s.baseColorTexture.index];let r;t&&!t.image.color&&(r=this.M(t)),o.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(o.baseColorTexture=r)}else{if(s.normalTexture){const t=this.M(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;o.normalTexture=t,o.normalMapFactor=r}if(s.occlusionTexture){const t=this.M(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;o.occlusionTexture=t,o.occlusionFactor=r}if(s.emissiveTexture){const t=this.M(e.textures[s.emissiveTexture.index]);o.emissiveTexture=t}s.emissiveFactor;const t=s.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(o.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const n=e.textures[t.baseColorTexture.index];n.image&&n.image.color?o.baseColorFactor=o.baseColorFactor?r.vec4.multiply(o.baseColorFactor,o.baseColorFactor,n.image.color):n.image.color:(o.baseColorTexture=this.M(n),o.baseColorTexture.getREGLTexture(this.nt))}if(E(t.metallicFactor)||(o.metallicFactor=t.metallicFactor),E(t.roughnessFactor)||(o.roughnessFactor=t.roughnessFactor),s.metallicRoughnessTexture){const t=this.M(e.textures[s.metallicRoughnessTexture.index]);o.metallicRoughnessTexture=t}}}if(s.s3mMaterial)return new r.reshader.Material(o);let a=new r.reshader.pbr.StandardMaterial(o);return"phong"===n&&(a=r.reshader.PhongMaterial.convertFrom(a)),a.once("complete",this.At),a}M(t){const e={type:t.type?er(t.type):"uint8",format:t.format?rr(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=Je(i.magFilter)),i.minFilter&&(e.min=Qe(i.minFilter)),i.wrapS&&(e.wrapS=tr(i.wrapS)),i.wrapT&&(e.wrapT=tr(i.wrapT))),new r.reshader.Texture2D(e,this.Tt)}oe(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}yt({target:t}){const e=t.ie,r=this.st[e];if(r.count--,!r.count){const t=r.meshes;this.at[e]=t,delete this.st[e];const n=t.$t;delete t.$t,n(null,{mesh:r.meshes,id:e})}}se(){return _r}Vt(t){return this.tt.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?sr:"X"===t?or:dr}}
|
|
18
|
+
let rt=0;function nt(t){return null==t}function it(t){return!nt(t)}function st(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 ot(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 at(t){return 0===t.indexOf("data:")&&t.indexOf("base64,")>0}function ct(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 lt=[],ft=[],ut=[],ht=[0,0,0],_t=function(t){return t[0]=0,t[1]=0,t[2]=0,t[3]=1,t}([]),dt=[1,1,1];function Et(t,e,r,n,i,s,o){const a=ot(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 Tt="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function mt(t,e,r){const n=new Uint8Array(t,e,r);return Tt.decode(n)}const At={get:function(t,e={}){e||(e={});const r=new AbortController,n=r.signal,i=st({},e);i.signal=n,i.method||(i.method="GET");const s=fetch(t,i).then((t=>{const r=this.i(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},i:(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",At.get(t,e)),getJSON:function(t,e={}){return e&&e.jsonp?At.jsonp(t):((e=e||{}).responseType="json",At.get(t,e))},jsonp:function(t){const e="_maptalks_jsonp_"+rt++;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 pt{constructor(t,e,r){this.o=t,this.decoders=e,this.l=r,this.images={},this.u={}}requestImageFromBufferURI(t,e,r){if(this.buffers[t.id]){const n=this.buffers[t.id],i=this.h(e,n);return this.getImageByBuffer(i,r)}if(this.u[t.id])return this.u[t.id].then((()=>{const n=this.buffers[t.id],i=this.h(e,n);return this.getImageByBuffer(i,r)}));if(at(t.uri)){const n=this.buffers[t.id]=ct(t.uri),i=this.h(e,n);return this.getImageByBuffer(i,r)}return this.u[t.id]=At.getArrayBuffer(t.uri,null).then((n=>{const i=this.buffers[t.id]=n.data,s=this.h(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.l});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._(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.u[t.id]?this.u[t.id].then((()=>this.images[t.id])):this.u[t.id]=this._(t.id,e)}_(t,e){return new Promise(((r,n)=>{this.o(e,((i,s)=>{i?n(i):(URL.revokeObjectURL(e),this.images[t]=s,r(this.images[t]))}))}))}}const yt=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16];class gt{constructor(t,e,r){this.rootPath=t,this.gltf=e,this.T=!1,this.glbBuffer=r,this.buffers={},this.requests={},this.accessors={},this.m()}A(t,e){const r=this.gltf,n=r.accessors[e];if(void 0===n.bufferView)return this.accessors[n.id]=this.p(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.g(i).then((r=>{const{buffer:i,byteOffset:s}=r;return this.accessors[n.id]=this.p(t,e,i,s)}))}g(t){const e=this.gltf.buffers[t.buffer];if(this.buffers[e.id]){const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})}if(this.requests[e.id])return this.requests[e.id].then((()=>{const t=this.buffers[e.id];return Promise.resolve({buffer:t,byteOffset:0})}));if("binary_glTF"!==t.buffer&&"KHR_binary_glTF"!==t.buffer&&e.uri){if(at(e.uri)){const t=this.buffers[e.id]=ct(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]=At.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})}p(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.R(s.type),l=ot(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.T)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.I(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=Et(t,r,s.count,c,f,a+(s.byteOffset||0),s.componentType)}else u.byteStride=0,u.array=this.I(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}m(){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)}I(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)}R(t){const e=yt.indexOf(t);return yt[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.g(e).then((n=>{const{buffer:i,byteOffset:s}=n,o=mt(i,s+(e.byteOffset||0),r);return t.content=o,t}))}if(t.uri){if(at(t.uri)){const e=ct(t.uri),r=mt(e,0,e.byteLength);return t.content=r,Promise.resolve(t)}{const e=this.rootPath+"/"+t.uri;return At.get(e).then((e=>(t.content=e,t)))}}return Promise.resolve(t)}));return Promise.all(r).then((()=>t))}}class Rt extends pt{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 gt(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(it(t.name)&&(e.name=t.name),it(t.children)&&(e.children=t.children),it(t.jointName)&&(e.jointName=t.jointName),it(t.matrix)&&(e.matrix=t.matrix),it(t.rotation)&&(e.rotation=t.rotation),it(t.scale)&&(e.scale=t.scale),it(t.translation)&&(e.translation=t.translation),it(t.extras)&&(e.extras=t.extras),it(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}(lt,e.translation||ht),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}(ft,e.rotation||_t),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}(ut,e.scale||dt);return P(i,n,i),P(t,r,i)}return B(t)}([],e);delete e.translation,delete e.rotation,delete e.scale,e.matrix=t}return e}N(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}S(t){if(t.bufferView||t.extensions&&(t.extensions.KHR_binary_glTF||t.extensions.binary_glTF)){const e=t.bufferView?t:t.extensions.KHR_binary_glTF||t.extensions.binary_glTF;t.extensions&&(t.mimeType=e.mimeType,t.width=e.width,t.height=e.height);const 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)}M(t){const e=this.gltf.textures[t];if(!e)return null;const r=this.gltf.images[e.source];return this.S(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 bt extends pt{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 gt(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 st(e,t),!it(t.weights)&&this.gltf.meshes&&it(e.mesh)?e.weights=this.gltf.meshes[e.mesh].weights:t.weights&&(e.weights=t.weights),e}M(t){const e=this.gltf.textures[t];if(!e)return null;const r=this.gltf.images[e.source];return this.S(r).then((t=>{if(!t)return null;const n={image:{array:t.data,mipmap:t.mipmap,width:t.width,height:t.height,index:e.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};st(n,e);const i=it(e.sampler)?this.gltf.samplers[e.sampler]:void 0;return i&&(n.sampler=i),t.format&&(n.format=t.format),n}))}S(t){if(!it(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.O(e,t)}return null}O(t,e){const r=this.h(t,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(r,e)}h(t,e,r){r=r||0;const n=t.byteOffset+r,i=t.byteLength;return new Uint8Array(e,n,i)}v(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++)(it(t[r].input)||it(t[r].output))&&(e.push(this.accessor.A("input",t[r].input)),e.push(this.accessor.A("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 It="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class Nt{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 Nt.readV1(n,e);if(2===i)return Nt.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=St(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=St(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 St(t,e,r){if(It){const n=new Uint8Array(t,e,r);return It.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=wt[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 wt=[1,1,1,1,2,2,3,0],Mt=[0,0,0],Ot=[0,0,0,1],vt=[1,1,1],Ct={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},xt={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Ut={C(t,e,r,n,i,s,o,a){const c=it(t)?e.animations:[e.animations[0]],l={};for(let e=0;e<c.length;e++){const f=c[e],u=f.name||e;if(it(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.U(i,f.samplers[e.sampler],n,1),l.translation=G(Mt,i)):"rotation"===e.target.path?(this.B(s,f.samplers[e.sampler],n,1),l.rotation=et(Ot,s)):"scale"===e.target.path?(this.U(o,f.samplers[e.sampler],n,1),l.scale=G(vt,o)):"weights"===e.target.path&&a&&(this.U(a,f.samplers[e.sampler],n,a.length),l.weights=a)}}return l},U(t,e,r,n){switch(e.interpolation){case"LINEAR":{const i=this.P(xt,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.P(xt,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.P(xt,e,r,3*n);i&&(t=this.L(t,i,e.input.array,3*n));break}}return t},B(t,e,r){switch(e.interpolation){case"LINEAR":{const n=this.P(xt,e,r,1);n&&Q(t,n.PREVIOUS,n.NEXT,n.INTERPOLATION);break}case"STEP":{const n=this.P(xt,e,r,1);n&&(t=$(t,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this.P(xt,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.L(t,n,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},D(t,e){const 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},P(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.D(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},L(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 k(Mt,...Ct.TRANSLATION),$(Ot,...Ct.ROTATION),k(vt,...Ct.SCALE),this.C(n,t,e,r,Mt,Ot,vt,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?it(e)?r[e]:r[Object.keys(r)[0]]:null}};let Bt=!1;if("undefined"!=typeof OffscreenCanvas){let t;try{t=new OffscreenCanvas(2,2).getContext("2d")}catch(wr){}t&&"undefined"!=typeof createImageBitmap&&(Bt=!0)}const Pt="undefined"==typeof document?null:document.createElement("canvas");class Lt{constructor(t,e,r){if(this.options=r||{},this.options.decoders||(this.options.decoders={}),e.buffer instanceof ArrayBuffer){const{json:r,glbBuffer:n}=Nt.read(e.buffer,e.byteOffset,e.byteLength);this.F(t,r,n)}else this.F(t,e);this.G=new gt(this.rootPath,this.gltf,this.glbBuffer),this.k()}k(){const t=this.gltf.extensionsRequired;if(t){if(t.indexOf("KHR_draco_mesh_compression")>=0&&!this.options.decoders.draco)throw new Error("KHR_draco_mesh_compression is required but @maptalks/transcoders.draco is not loaded");if(t.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders.ktx2)throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded")}}H(){const t=this.gltf.extensions;return t&&t.KHR_techniques_webgl?this.G.requestKHRTechniquesWebgl(t.KHR_techniques_webgl).then((e=>(t.KHR_techniques_webgl=e,t))):Promise.resolve(t)}load(t){t=t||{};const e=this.V(t),r=this.X(),n=this.Y(),i=this.H();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 Ut.getAnimationClip(t,e,r,n)}static getAnimationTimeSpan(t,e){return Ut.getTimeSpanByName(t,e)}static getTypedArrayCtor(t){return ot(t)}static readInterleavedArray(t,e,r,n,i,s,o){return Et(t,e,r,n,i,s,o)}F(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=Bt?kt.bind(this):this.options.requestImage||Dt,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new bt(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 Rt(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"))}Z(t,e){if(t.children&&t.children.length>0){if(!("number"==typeof(r=t.children[0])&&isFinite(r)||function(t){return!nt(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.Z(r,e)}));t.children=n}var r;return t}V(t){return this.W(t).then((t=>{const e=this.scenes=[];let r;for(const e in t)t[e]=this.Z(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.N(this.gltf.materials);n.materials=t}return n}))}W(t){return this.j(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}))}K(){this.skins=[];const t=[];return this.adapter.iterate(((e,r,n)=>{t.push(this.q(r).then((t=>{t.index=n,this.skins.push(t)})))}),"skins"),t}q(t){const e=t.inverseBindMatrices;return this.adapter.accessor.A("inverseBindMatrices",e).then((e=>(t.inverseBindMatrices=e,e&&e.buffer&&this.transferables&&this.transferables.indexOf(e.buffer)<0&&this.transferables.push(e.buffer),t)))}X(){const t=this.gltf.animations;return it(t)?this.adapter.getAnimations(t):null}j(t){this.meshes={};let e=[];return this.adapter.iterate(((r,n,i)=>{e.push(this.$(n,t).then((t=>{t.index=i,this.meshes[r]=t})))}),"meshes"),e=e.concat(this.K()),Promise.all(e)}$(t,e){const r=t.primitives.map((t=>this.J(t,e))).filter((t=>!!t));return Promise.all(r).then((e=>{const r={};return st(r,t),r.primitives=e,r}))}Y(){const t=this.gltf.textures;if(!t)return null;const e=[];for(const r in t)e.push(this.adapter.M(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}))}J(t,e){let r;const n=[],i=t.extensions;if(it(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.A(`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.G.g(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.A(t,e[t]);r&&n.push(r)}if(it(t.indices)){const e=this.adapter.accessor.A("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;X(t,t,i),H(t,t,s),X(r,r,i),H(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=it(t.mode)?t.mode:4,it(t.extras)&&(s.extras=t.extras),s}))}}function Dt(t,e){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!Pt)return void e(new Error("There is no canvas to draw image!"));Pt.width=r.width,Pt.height=r.height;const t=Pt.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 Ft,Gt;function kt(t,e){Ft||(Ft=new OffscreenCanvas(2,2),Gt=Ft.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;Ht(r)||(r=Vt(r)),Ht(n)||(n=Vt(n));const i=this.options.maxTextureSize;i&&(r=Math.min(i,r),n=Math.min(i,n)),Ft.width=r,Ft.height=n,Gt.drawImage(t,0,0,r,n),t.close();const s=Gt.getImageData(0,0,r,n);e(null,{width:r,height:n,data:new Uint8Array(s.data)})})).catch((t=>{console.warn(t),e(t)}))}function Ht(t){return 0==(t&t-1)&&0!==t}function Vt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}const zt="undefined"==typeof document?null:document.createElement("canvas");class Xt extends i.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(!zt)return void e(new Error("There is no canvas to draw image!"));const t=function(t){if(Yt(t.width)&&Yt(t.height))return t;let e=t.width,r=t.height;Yt(e)||(e=Zt(e));Yt(r)||(r=Zt(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);zt.width=t.width,zt.height=t.height;const n=zt.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 Yt(t){return 0==(t&t-1)&&0!==t}function Zt(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}class Wt{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 jt(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=[];Kt(n[r],i,t,e)}}}function Kt(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++)Kt(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 qt(t,e,r){let{componentType:n,byteOffset:i,byteStride:s,itemSize:o}=e;const a=e.array.buffer,c=n?Lt.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 $t(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 Jt=new Array(3),Qt=new Array(3),te=[40680631590769,40680631590769,40408299984661.445];function ee(t,e,r,n){const i=te,s=Math.cos(r);Jt[0]=s*Math.cos(e),Jt[1]=s*Math.sin(e),Jt[2]=Math.sin(r),ue(Jt,Jt),z(Qt,i,Jt);const o=Math.sqrt(Z(Jt,Qt));var a,c,l;return c=Qt,l=o,(a=Qt)[0]=c[0]/l,a[1]=c[1]/l,a[2]=c[2]/l,X(Jt,Jt,n),H(t,Qt,Jt)}const re=[1/6378137,1/6378137,1/6356752.314245179],ne=[1/40680631590769,1/40680631590769,1/40408299984661.445],ie=new Array(3),se=new Array(3),oe=new Array(3);function ae(t,e){const r=ne,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=X(ce,e,E);if(d<i)return isFinite(E)?T:void 0;const m=n[0],A=n[1],p=n[2],y=le;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)*fe(e)/(.5*fe(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}(ie,e,re,r,.1);let i=K(se,n,r);i=ue(i,i);const s=j(oe,e,n),o=Math.atan2(i[1],i[0]),a=Math.asin(i[2]),c=R(Z(s,e))*fe(s);return t[0]=y(o),t[1]=y(a),t[2]=c,t}const ce=new Array(3),le=new Array(3);function fe(t){return D(t)}function ue(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 he(t,e){return z(e,t,ne),Y(e,e)}function _e(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,Y(e,e)}var de=Object.freeze({__proto__:null,radianToCartesian3:ee,cartesian3ToDegree:ae,normalizeCartesian:ue,geodeticSurfaceNormal:he,geodeticSurfaceNormalCartographic:_e});function Ee(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 Te(t,e){let r="";for(let n=0;n<4;n++){const i=t.getUint8(e+n);r+=String.fromCharCode(i)}return r}const me="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function Ae(t,e,r){const n=new Uint8Array(t,e,r);return me?JSON.parse(me.decode(n)):JSON.parse(I(n))}function pe(t,e,r){const n=new Uint8Array(t,e,r);return me?JSON.parse(me.decode(n)):JSON.parse(I(n))}function ye(t,e,r){return{offset:e,byteLength:r}}function ge(t,e,r,n){const{byteOffset:i,componentType:s,type:o}=t,{ctor:a,type:c}=function(t){return Ie[t]}(s),l=function(t){if(!t)return 1;return be[t]}(o);return{byteStride:0,byteOffset:i+r,itemSize:l,count:n*l,componentType:c,array:new a(e,r+i,n*l)}}function Re(t,e,r,n){t.componentType||(t.componentType="UNSIGNED_SHORT");const i=ge(t,e,r,n);return i.array.buffer.byteLength!==e.byteLength&&(i.array=i.array.slice()),i}const be={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};const Ie={"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 Ne(t){for(let e in Ie)if(t===Ie[e].ctor)return Ie[e].type;throw new Error("unrecognized ctor:"+t)}function Se(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 we(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=Ae(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=pe(a,e,s),e+=s);const h=ye(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 Me={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},Oe={},ve={east:[],north:[],up:[],west:[],south:[],down:[]},Ce=[],xe=[],Ue=[];const Be=[0,0,0];function Pe(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 Le=(ke={up:{south:"east",north:"west",west:"south",east:"north"},down:{south:"west",north:"east",west:"north",east:"south"},south:{up:"west",down:"east",west:"down",east:"up"},north:{up:"east",down:"west",west:"up",east:"down"},west:{up:"north",down:"south",north:"down",south:"up"},east:{up:"south",down:"north",north:"up",south:"down"}}[De="east"][Fe="north"],Oe[He=De+Fe]?Ge=Oe[He]:(Ge=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)<=x*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(n-o)<=x*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=x*Math.max(1,Math.abs(i),Math.abs(a))}(t,Be))G(Ce,Me[De]),G(xe,Me[Fe]),G(Ue,Me[ke]);else if(Ee(t[0],0,1e-14)&&Ee(t[1],0,1e-14)){var n=R(t[2]);G(Ce,Me[De]),"east"!==De&&"west"!==De&&X(Ce,Ce,n),G(xe,Me[Fe]),"east"!==Fe&&"west"!==Fe&&X(xe,xe,n),G(Ue,Me[ke]),"east"!==ke&&"west"!==ke&&X(Ue,Ue,n)}else{he(t,ve.up);var i=ve.up,s=ve.east;s[0]=-t[1],s[1]=t[0],s[2]=0,Y(ve.east,s),W(ve.north,i,s),X(ve.down,ve.up,-1),X(ve.west,ve.east,-1),X(ve.south,ve.north,-1),Ce=ve[De],xe=ve[Fe],Ue=ve[ke]}return r[0]=Ce[0],r[1]=Ce[1],r[2]=Ce[2],r[3]=0,r[4]=xe[0],r[5]=xe[1],r[6]=xe[2],r[7]=0,r[8]=Ue[0],r[9]=Ue[1],r[10]=Ue[2],r[11]=0,r[12]=t[0],r[13]=t[1],r[14]=t[2],r[15]=1,r},Oe[He]=Ge),Ge);var De,Fe,Ge,ke,He;const Ve=[],ze=[],Xe=[],Ye=[],Ze=[],We=[],je=[],Ke={x:0,y:0},qe={x:0,y:0},$e=Math.PI/180;const Je={"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:Qe,getTextureMinFilter:tr,getTextureWrap:er,getMaterialType:rr,getMaterialFormat:nr,getPrimitive:ir,getUniqueREGLBuffer:sr}=r.reshader.REGLHelper,or=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],ar=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:cr,logoutIBLResOnCanvas:lr,getIBLResOnCanvas:fr,getPBRUniforms:ur}=r.reshader.pbr.PBRUtils,hr={factor:0,units:0},_r={specularStrength:0,materialShininess:1},dr=[1,1,1],Er=r.mat4.identity([]),Tr=t=>t.material instanceof r.reshader.PhongMaterial,mr=t=>t.material instanceof r.reshader.pbr.StandardMaterial,Ar=[!0,!0,!0,!0],pr=[],yr=new i.Coordinate(0,0),gr=[],Rr=[],br={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"};class Ir{constructor(t,e){this.tt=e,this.et=e.getRenderer().canvas,this.rt=new i.SpatialReference,this.nt=t,this.it=new r.reshader.Renderer(t),this.st={},this.ot={},this.at={},this.ct={},this.lt={},this.ft={},this.ut={},this.ht=new r.reshader.Scene,this._t=new r.reshader.Scene,this.dt=new r.reshader.Scene,this.Et=new r.reshader.Scene,this.Tt=new r.reshader.ResourceLoader(t.texture(2)),this.At=this.yt.bind(this),this.gt=new r.reshader.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.Rt(),this.bt=new r.reshader.KHRTechniquesWebglManager(this.nt,this.It(),this.Tt)}getI3DMMeshes(){return this.lt}getPNTSMeshes(){return this.ct}getB3DMMeshes(){return this.at}getPaintedMeshes(){return this.Nt}getMap(){return this.tt.getMap()}paint(t,e,r,n){const i=this.getMap();if(!t.length||!i)return;const s=this.St(),o=i.projViewMatrix,a=this.tt.options.services,c=[],l=[];let u=[];const h=[],_=[];for(let r=0,n=t.length;r<n;r++){const n=t[r].data.node;let i=this.wt(n);if(!i)continue;this.ft[n.id]&&(i=this.ft[n.id],i=S(i));let d=a[n.Mt].polygonOffset||hr;m(d)&&(d=d());const E=a[n.Mt].ambientLight;Array.isArray(i)||(c[0]=i,i=c);for(let a=0,c=i.length;a<c;a++){if(i[a].getBoundingBox&&!f(o,i[a].getBoundingBox()))continue;const c=i[a].properties.magic;"b3dm"===c?u.push(i[a]):"pnts"===c?h.push(i[a]):"i3dm"===c&&_.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].Ot=n,e[n.id]||l.push(i[a])}}let d=0;const E=this.bt.getExcludeFilter();d+=this.vt(this.Ct,s,[r,Tr,E],n,l,u,_),d+=this.vt(this.xt,s,[r,mr,E],n,l,u,_),this.bt.forEachShader(((t,e,i)=>{const s=this.St(i);d+=this.vt(t,s,[r,e],n,l,u,_)})),this._t.setMeshes(h);const T=this.Ut();return d+=this.it.render(this.Bt,T,this._t,n&&n.fbo),this.Nt={pntsMeshes:h,i3dmMeshes:_,b3dmMeshes:u},d}vt(t,e,r,n,i,s,o){t.filter=r.filter((t=>!!t)),e.debug=!1,this.ht.setMeshes(i),e.stencilEnable=!1,e.debug=!1,e.cullFace="back",e.colorMask=Ar;let a=0;return this.ht.setMeshes(s),a+=this.it.render(t,e,this.ht,n&&n.fbo),e.stencilEnable=!1,this.dt.setMeshes(o),a+=this.it.render(t,e,this.dt,n&&n.fbo),a}Pt(t,e){return e.Ot.Lt-t.Ot.Lt}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.Dt(e);n&&(n.getBoundingBox&&!f(o,n.getBoundingBox())||a.push(n))}this.Ft.filter=n,this.Et.setMeshes(a);const c=this.Gt(r);this.it.render(this.Ft,c,this.Et,i&&i.fbo)}deleteTile(t){const e=t.node.id;this.kt(e)}kt(t){const e=this.ot[t];e&&(e.geometry.dispose(),e.dispose(),delete this.ot[t]);let r=this.at[t]||this.ct[t]||this.lt[t]||this.ft[t]||this.st[t];this.ft[t]?this.Ht(t):r&&(this.Vt(r),delete this.at[t],delete this.ct[t],delete this.lt[t],delete this.st[t])}Ht(t){let e=this.ft[t];e=S(e);for(let t=0;t<e.length;t++){const{id:r}=e[t].properties;this.kt(r)}delete this.ft[t]}Vt(t){if(Array.isArray(t))for(let e=0,r=t.length;e<r;e++)this.Vt(t[e]);else{const e=t.geometry.properties.url;if(e){const t=this.ut[e];t&&(t.refCount--,t.refCount<=0&&(t.geometry.dispose(),t.material.dispose(),delete this.ut[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.tt;lr(t.getRenderer().canvas,t.getMap());for(const t in this.ft)this.Ht(t);this.ft={};for(const t in this.at)this.kt(t);this.at={};for(const t in this.ct)this.kt(t);this.ct={};for(const t in this.lt)this.kt(t);this.lt={};for(const t in this.st)this.kt(t);this.st={};for(const t in this.ot)this.kt(t);this.ot={},this.Ct&&(this.Ct.dispose(),delete this.Ct),this.xt&&(this.xt.dispose(),delete this.xt),this.Bt&&(this.Bt.dispose(),delete this.Bt),this.Ft&&(this.Ft.dispose(),delete this.Ft),this.bt.dispose()}Dt(t){if(!t.boundingVolume||!t.boundingVolume.region)return null;if(this.ot[t.id])return this.ot[t.id];const e=t.boundingVolume.region;let n=new i.Coordinate(y(e[0]),y(e[1])),s=new i.Coordinate(y(e[2]),y(e[3]));n=this.zt(n),s=this.zt(s);const o=n.add(s).Xt(.5);n._sub(o),s._sub(o);const a=this.Yt(e[4],e[5]),c=a.x,l=a.y,f=[n.x,n.y,l,s.x,n.y,l,s.x,s.y,l,n.x,s.y,l,n.x,n.y,c,s.x,n.y,c,s.x,s.y,c,n.x,s.y,c],u=new r.reshader.Geometry({aPosition:f},[0,1,1,2,2,3,3,0,0,4,1,5,2,6,3,7,4,5,5,6,6,7,7,4],0,{primitive:"lines"});u.generateBuffers(this.nt);const h=new r.reshader.Mesh(u),_=r.mat4.identity([]);return h.setLocalTransform(r.mat4.translate(_,_,[o.x,o.y,0])),this.ot[t.id]=h,h}wt(t){return this.at[t.id]||this.ct[t.id]||this.lt[t.id]||this.ft[t.id]}has(t){return this.wt(t)||this.st[t.id]}createPntsMesh(t,e,n,i){if(this.ct[e]){const t=this.ct[e];return console.warn(`pnts mesh with id(${e}) was already created.`),i(null,{id:e,mesh:t}),t}const{pnts:s,featureTable:o,rootIdx:a}=t,c=o.POINTS_LENGTH,l=new r.reshader.Geometry(s,null,c,{primitive:"points",positionAttribute:"POSITION"});l.generateBuffers(this.nt);const f={};s.POSITION?f.HAS_POSITION=1:s.POSITION_QUANTIZED&&(f.HAS_POSITION_QUANTIZED=1),s.RGB?f.HAS_RGB=1:s.RGBA?f.HAS_RGBA=1:s.RGB565&&(f.HAS_RGB565=1),(s.NORMAL||s.NORMAL_OCT16P)&&(f.HAS_NORMAL=1,s.NORMAL_OCT16P&&(f.HAS_NORMAL_OCT16P=1)),t.featureTable.CONSTANT_RGBA&&(t.featureTable.CONSTANT_RGBA=t.featureTable.CONSTANT_RGBA.map((t=>t/255)));const{rtcCenter:u,rtcCoord:h}=t,_=this.Zt(h),d=this.Wt(n,u,h);r.mat4.multiply(d,d,_);const E=this.tt.options.services[a],T=new r.reshader.Mesh(l);return T.properties.magic="pnts",T.properties.id=e,T.properties.count=c,T.properties.batchTable=t.batchTable,T.properties.batchTableBin=t.batchTableBin,T.setDefines(f),Object.defineProperty(T.uniforms,"pointColor",{enumerable:!0,get:function(){return t.featureTable.CONSTANT_RGBA?t.featureTable.CONSTANT_RGBA:E&&E.pointColor||[1,1,1,1]}}),Object.defineProperty(T.uniforms,"pointSize",{enumerable:!0,get:function(){return E&&E.pointSize||2}}),Object.defineProperty(T.uniforms,"pointOpacity",{enumerable:!0,get:function(){return E&&E.pointOpacity||1}}),T.setLocalTransform(d),this.ct[e]=T,i(null,{id:e,mesh:[T]}),[T]}createI3DMMesh(t,e,n,i){if(this.lt[e]){const t=this.lt[e];return console.warn(`i3dm mesh with id(${e}) was already created.`),this.st[e]||i(null,{id:e,mesh:t}),t}const s=this.jt(n.Kt),{i3dm:o,featureTable:a,gltf:c,batchTable:l,batchTableBin:f,count:u}=t,h=a.INSTANCES_LENGTH,{rtcCenter:_,rtcCoord:d}=t,E=this.Zt(d),T=this.Wt(n,_,d),{POSITION:m,NORMAL_UP:A,NORMAL_RIGHT:p,SCALE:y,SCALE_NON_UNIFORM:g,INSTANCE_ROTATION:R}=o,b={"instance_vectorA":new Float32Array(4*h),"instance_vectorB":new Float32Array(4*h),"instance_vectorC":new Float32Array(4*h)},I=new Float32Array(3),S=new Float32Array(3),w=[],M=new Float32Array(1),O=new Float32Array(3),v=[],C=[],x=[],U=[],B=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?Lt.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)}}(m,((t,e)=>{A?(qt(S,p,e),qt(I,A,e),r.vec3.cross(w,S,I),r.vec3.normalize(w,w),N(v,S,0),N(v,I,1),N(v,w,2),r.quat.fromMat3(C,v)):R?(qt(B,R,e),r.quat.fromMat3(C,B)):r.quat.identity(C),y?(qt(M,y,e),r.vec3.set(x,M[0],M[0],M[0])):g?(qt(O,g,e),r.vec3.set(x,...O)):r.vec3.set(x,1,1,1),r.mat4.fromRotationTranslationScale(U,C,t,x),$t(b.instance_vectorA,e,U,0),$t(b.instance_vectorB,e,U,1),$t(b.instance_vectorC,e,U,2)}));const P={};for(const t in b)P[t]={buffer:this.nt.buffer({dimension:b[t].length/h,data:b[t]}),divisor:1};const L=this.tt.options.services[n.Mt].shader||"phong";let D=0,F=!0;const G=[];return jt(c,((t,i,o,a)=>{let{geometry:c,material:_}=this.qt(t,i,o,a,n,!0,L);_&&!_.isReady()&&(F=!1,D++);const d=new r.reshader.InstancedMesh(P,h,c,_);d.properties.magic="i3dm",d.properties.id=e,d.properties.count=u,d.properties.batchTable=l,d.properties.batchTableBin=f;const m=this.$t(t,c,_,n.Mt,a),A=r.mat4.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.mat4.multiply(A,A,t.matrices[e]);r.mat4.multiply(A,s,A),d.setPositionMatrix(A),r.mat4.multiply(E,T,E),d.setLocalTransform(E),d.setDefines(m),d.properties.polygonOffset={offset:0,factor:0},G.push(d)})),F?(this.lt[e]=G,i(null,{id:e,mesh:G})):(this.st[e]={meshes:G,count:D},G.Jt=i),G}createB3DMMesh(t,e,n,s){if(this.at[e]||this.st[e]){const t=this.at[e];return console.warn(`mesh with id(${e}) was already created.`),this.st[e]||s(null,{id:e,mesh:t}),t}const o=t.gltf.asset&&"i3s"===t.gltf.asset.generator;let a;if(n.maxExtent){const t=new i.Extent(n.maxExtent).convertTo((t=>this._pointToPrj(t)));a=[t.xmin,t.ymin,t.xmax,t.ymax]}const c=this.jt(n.Kt),l=t.gltf,{center:f,coord:u}=l.extensions.CESIUM_RTC,h=this.tt.options.services[n.Mt].heightOffset||0;let _;if(h&&u&&(u[2]+=h),o){const{i3sProjCenter:t}=l.extensions.CESIUM_RTC;_=this.Qt(t,n.Mt)}else _=this.Zt(u,n.Mt);const d=this.tt.options.services[n.Mt].shader||"phong",E=[];let T=0,m=!0;return jt(l,((i,s,l,h)=>{let{geometry:A,material:p}=this.qt(i,s,l,h,n,!1,d);p&&!p.isReady()&&(m=!1,T++);const y=new r.reshader.Mesh(A,p);y.properties.magic="b3dm",y.properties.id=e,y.properties.batchTable=t.batchTable,y.properties.batchTableBin=t.batchTableBin,y.properties.count=t.featureTable.BATCH_LENGTH;const g=this.$t(i,A,p,n.Mt,h);y.setDefines(g),a&&(g.USE_MAX_EXTENT=1,y.setUniform("maxPrjExtent",a));let R=r.mat4.identity([]);if(i.matrices&&i.matrices.length)for(let t=0;t<i.matrices.length;t++)r.mat4.multiply(R,R,i.matrices[t]);const b=o?Er:this.Wt(n,f,u);r.mat4.multiply(R,c,R),r.mat4.multiply(R,_,R),r.mat4.multiply(R,b,R),y.setLocalTransform(R),E.push(y)})),m?(this.at[e]=E,s(null,{id:e,mesh:E})):(this.st[e]={meshes:E,count:T},E.Jt=s),E}Wt(t,e,n){const s=this.getMap(),o=this.tt.options.services[t.Mt].heightOffset||0,a=new i.Coordinate(n),c=s.distanceToPointAtRes(100,0,s.getGLRes(),a).x/100;let l=t.matrix?r.mat4.copy([],t.matrix):r.mat4.identity([]);if(e){Pe(l,r.vec3.transformMat4(pr,e,l),l)}const f=function(t,e,r,n,i,s,o){e=G(Ve,e);const a=ee(Ve,e[0]*$e,e[1]*$e,e[2]),c=function(t,e){return t[0]=e[12],t[1]=e[13],t[2]=e[14],t}(ze,r),l=n.ellipsoid;var f;f=0===q(c)?k(Xe,0,0,-6378137):ae(Xe,c),Ke.x=f[0],Ke.y=f[1];const u=n.project(Ke,qe);Ye[0]=u.x/i,Ye[1]=u.y/i,Ye[2]=(f[2]+o)*s;const h=Le(a,l,Ze),_=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}(We,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}(je,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 Pe(t,Ye,E),t}(l,n,l,s.getProjection(),s.getGLRes(),c,o),u=function(t,e){return k(t,e[12],e[13],e[14]),t}(Rr,f);let h=this.tt.options.offset;if(m(h)){h=h(this.tt.te(t.id).center)}return r.vec3.set(gr,h[0],h[1],0),r.vec3.sub(u,u,gr),Pe(f,u,f),f}createCMPTMesh(t,e,r,n){if(this.ft[e]){const t=this.ft[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.ft[e]=s,n(null,{id:e,mesh:s}),s}$t(t,e,r,n,i){const s=("phong"===(this.tt.options.services[n].shader||"phong")?this.Ct:this.xt).getGeometryDefines(e);return i.asset&&"S3M"===i.asset.generator&&this.ee(s,e,i),s}ee(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)}qt(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=Je);const c=n.url+"-"+e+"-"+r;if(this.ut[c])return this.ut[c].refCount++,this.ut[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.re(t,n,s,a);l=e.material,f=e.geometry;this.tt.options.services[i.Mt].fillEmptyDataInMissingAttribute&&(f.desc.fillEmptyDataInMissingAttribute=!0)}else{f=this.ne(t,s,br);const e=this.tt.options.services[i.Mt].material;l=this.ie(t.material,n,o,e||_r)}l&&!l.isReady()?l.se=i.id:l||(l=this.gt);const h={refCount:1,geometry:f,material:l};return f.properties.url=c,this.ut[c]=h,h}re(t,e,r,n){const{geometry:i,material:s}=this.bt.createMesh(t,e,r,n);return{geometry:i,material:s}}ne(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=sr(this.nt,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.reshader.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":ir(t.mode)});return o.generateBuffers(this.nt,{excludeElementsInVAO:e}),o}Zt(t){const e=r.mat4.identity([]),n=this.getMap(),i=this.oe();yr.x=t[0],yr.y=t[1];const s=n.distanceToPointAtRes(100,100,n.getGLRes(),yr);return r.vec3.set(i,s.x/100*1.01,s.y/100*1.01,s.y/100),r.mat4.scale(e,e,i),e}Qt(t,e){const n=r.mat4.identity([]),s=this.getMap(),o=this._prjToPoint(new i.Coordinate(t)),a=this.oe(),c=1/(s.getGLZoom?s.getResolution(s.getGLZoom()):s.getGLRes()),l=r.vec3.set(Rr,o.x,o.y,c*t[2]);r.mat4.translate(n,n,l);const f=this.tt.options.services[e].heightOffset;if(f){const e=s.getProjection().unproject(new i.Coordinate(t)),o=s.distanceToPointAtRes(100,100,s.getGLRes(),e).y/100;r.mat4.translate(n,n,[0,0,f*o])}return r.mat4.scale(n,n,r.vec3.scale([],a,c)),n}Rt(){const t={x:0,y:0,width:()=>this.et?this.et.width:1,height:()=>this.et?this.et.height:1};this.Ft=new r.reshader.MeshShader({vert:"attribute vec3 aPosition;\n\n\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main() {\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n}\n\n",frag:"precision mediump float;\nuniform vec3 color;\nvoid main() {\n gl_FragColor = vec4(color, 1.0);\n}\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.mat4.multiply([],e.projViewMatrix,e.modelMatrix)}],extraCommandProps:{viewport:t}});const e=[],n=[];this.Bt=new r.reshader.MeshShader({vert:"const float SHIFT_RIGHT_11 = 1.0 / 2048.0;\n\nconst float SHIFT_RIGHT_5 = 1.0 / 32.0;\n\nconst float SHIFT_LEFT_11 = 2048.0;\n\nconst float SHIFT_LEFT_5 = 32.0;\n\nconst float NORMALIZE_6 = 1.0 / 64.0;\n\nconst float NORMALIZE_5 = 1.0 / 32.0;\n\n\n\n#ifdef HAS_POSITION\n\n attribute vec3 POSITION;\n\n#endif\n\n\n\n#if defined(HAS_RGB)\n\n attribute vec3 RGB;\n\n#elif defined(HAS_RGBA)\n\n attribute vec4 RGBA;\n\n#elif defined(HAS_RGB565)\n\n attribute float RGB565;\n\n#endif\n\n\n\nuniform vec4 pointColor;\n\nuniform float pointSize;\n\n\n\nuniform mat4 projViewModelMatrix;\n\nuniform float pointOpacity;\n\n\n\nvarying vec4 vColor;\n\n\n\n#ifdef HAS_NORMAL\n\n #ifdef HAS_NORMAL_OCT16P\n\n attribute vec2 NORMAL_OCT16P;\n\n float signNotZero(float value) {\n\n return value >= 0.0 ? 1.0 : -1.0;\n\n }\n\n vec2 signNotZero(vec2 value) {\n\n return vec2(signNotZero(value.x), signNotZero(value.y));\n\n }\n\n vec3 octDecode(vec2 encoded, float range) {\n\n if (encoded.x == 0.0 && encoded.y == 0.0) {\n\n return vec3(0.0, 0.0, 0.0);\n\n }\n\n encoded = encoded / range * 2.0 - 1.0;\n\n vec3 v = vec3(encoded.x, encoded.y, 1.0 - abs(encoded.x) - abs(encoded.y));\n\n if (v.z < 0.0) {\n\n v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);\n\n }\n\n return normalize(v);\n\n }\n\n vec3 octDecode(vec2 encoded) {\n\n return octDecode(encoded, 255.0);\n\n }\n\n #else\n\n attribute vec3 NORMAL;\n\n #endif\n\n uniform vec3 lightDir;\n\n uniform mat3 modelNormalMatrix;\n\n uniform mat4 positionMatrix;\n\n float getLambertDiffuse(vec3 lightDir, vec3 normal) {\n\n return max(dot(-lightDir, normal), 0.0);\n\n }\n\n#endif\n\n\n\nvoid main() {\n\n #if defined(HAS_RGB)\n\n vColor = vec4(RGB / 255.0, 1.0) * pointOpacity;\n\n #elif defined(HAS_RGBA)\n\n vColor = RGBA / 255.0 * pointOpacity;\n\n #elif defined(HAS_RGB565)\n\n float compressed = RGB565;\n\n float r = floor(compressed * SHIFT_RIGHT_11);\n\n compressed -= r * SHIFT_LEFT_11;\n\n float g = floor(compressed * SHIFT_RIGHT_5);\n\n compressed -= g * SHIFT_LEFT_5;\n\n float b = compressed;\n\n vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5);\n\n vColor = vec4(rgb, 1.0);\n\n #else\n\n vColor = pointColor;\n\n #endif\n\n\n\n #ifdef HAS_POSITION\n\n vec3 localPos = POSITION;\n\n #endif\n\n\n\n #ifdef HAS_NORMAL\n\n mat3 positionNormalMatrix = mat3(positionMatrix);\n\n mat3 normalMatrix = modelNormalMatrix * positionNormalMatrix;\n\n #ifdef HAS_NORMAL_OCT16P\n\n vec3 localNormal = octDecode(NORMAL_OCT16P);\n\n #else\n\n vec3 localNormal = NORMAL;\n\n #endif\n\n vec3 normal = normalize(normalMatrix * localNormal);\n\n float colorStrength = getLambertDiffuse(lightDir, normal);\n\n colorStrength = max(colorStrength, 0.5);\n\n vColor *= colorStrength;\n\n #endif\n\n\n\n gl_Position = projViewModelMatrix * vec4(localPos, 1.0);\n\n gl_PointSize = pointSize;\n\n}\n\n",frag:"#define SHADER_NAME PNTS\n\nprecision mediump float;\n\n\n\nvarying vec4 vColor;\n\n\n\nvoid main() {\n\n gl_FragColor = vColor;\n\n}\n\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>r.mat4.multiply(n,e.projViewMatrix,e.modelMatrix)},{name:"modelNormalMatrix",type:"function",fn:(t,n)=>r.mat3.fromMat4(e,n.modelMatrix)}],extraCommandProps:{viewport:t,blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"},depth:{enable:!0,range:[0,1],func:"<"}}});const i=this.It();this.Ct=new r.reshader.PhongShader({extraCommandProps:i}),this.xt=new r.reshader.pbr.StandardShader({extraCommandProps:i});const s=this.tt;cr(s.getRenderer().canvas,this.nt,s.getMap())}It(){return{viewport:{x:0,y:0,width:()=>this.et?this.et.width:1,height:()=>this.et?this.et.height:1},colorMask:(t,e)=>e.colorMask||Ar,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}}}Gt(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}Ut(t){const e=this.getMap(),n=e.getLightManager(),i=(n&&n.getDirectionalLight()||{}).direction||[1,1,-1],s=t&&t.pointOpacity||1;return{projViewMatrix:e.projViewMatrix,pointOpacity:s,lightDir:r.vec3.normalize(i,i)}}St(){const t=this.getMap(),e=this.tt.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=fr(e),i=ur(t,r,n);return T(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}ie(t,e,n,i){const s=e.materials[t];if(!s||!s.baseColorTexture&&!s.pbrMetallicRoughness)return null;const o=T({},i);if(s.baseColorTexture){const t=e.textures[s.baseColorTexture.index];let r;t&&!t.image.color&&(r=this.M(t)),o.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(o.baseColorTexture=r)}else{if(s.normalTexture){const t=this.M(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;o.normalTexture=t,o.normalMapFactor=r}if(s.occlusionTexture){const t=this.M(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;o.occlusionTexture=t,o.occlusionFactor=r}if(s.emissiveTexture){const t=this.M(e.textures[s.emissiveTexture.index]);o.emissiveTexture=t}s.emissiveFactor;const t=s.pbrMetallicRoughness;if(t){if(t.baseColorFactor&&(o.baseColorFactor=t.baseColorFactor),t.baseColorTexture&&void 0!==t.baseColorTexture.index){const n=e.textures[t.baseColorTexture.index];n.image&&n.image.color?o.baseColorFactor=o.baseColorFactor?r.vec4.multiply(o.baseColorFactor,o.baseColorFactor,n.image.color):n.image.color:(o.baseColorTexture=this.M(n),o.baseColorTexture.getREGLTexture(this.nt))}if(E(t.metallicFactor)||(o.metallicFactor=t.metallicFactor),E(t.roughnessFactor)||(o.roughnessFactor=t.roughnessFactor),s.metallicRoughnessTexture){const t=this.M(e.textures[s.metallicRoughnessTexture.index]);o.metallicRoughnessTexture=t}}}if(s.s3mMaterial)return new r.reshader.Material(o);let a=new r.reshader.pbr.StandardMaterial(o);return"phong"===n&&(a=r.reshader.PhongMaterial.convertFrom(a)),a.once("complete",this.At),a}M(t){const e={type:t.type?rr(t.type):"uint8",format:t.format?nr(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=Qe(i.magFilter)),i.minFilter&&(e.min=tr(i.minFilter)),i.wrapS&&(e.wrapS=er(i.wrapS)),i.wrapT&&(e.wrapT=er(i.wrapT))),new r.reshader.Texture2D(e,this.Tt)}ae(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}yt({target:t}){const e=t.se,r=this.st[e];if(r.count--,!r.count){const t=r.meshes;this.at[e]=t,delete this.st[e];const n=t.Jt;delete t.Jt,n(null,{mesh:r.meshes,id:e})}}oe(){return dr}zt(t){return this.tt.zt(t)}Yt(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())}jt(t){return"Y"===t?or:"X"===t?ar:Er}}
|
|
19
19
|
/*!
|
|
20
20
|
* @maptalks/gl v0.68.1
|
|
21
21
|
* LICENSE : UNLICENSED
|
|
22
22
|
* (c) 2016-2022 maptalks.com
|
|
23
|
-
*/const Ir=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")},Nr=Ir(),Sr=Nr.gl_trans__coders=Nr.gl_trans__coders||{};function wr(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Sr.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Nr.gl_trans__coders=Nr.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Ir.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},Sr.registerTranscoder=function(t,e){Sr[t]=e},Sr.getTranscoder=function(t){return Sr[t]};const Mr=[];class Or{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){wr(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=vr([],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=vr([],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];G(Mr,e,r,n);const o=K(Mr);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=U([]),_=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 vr(t,e,r,n){return te(t,p(e),p(r),n)}const Cr=!!Sr.ktx2,xr=r.mat4.identity([]),Ur=(()=>{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 Br(t){return t.indexOf("i3s:mesh")>=0}const Pr="i3s:mesh:".length;function Lr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Pr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const u=xr;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=Sr.draco&&f?o[1]:o[0],d=Sr.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};if(i&&Ur&&f&&!Sr.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 Dr(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 Dr(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=Fr(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 A(t[o])&&Dr(t[o],e,r,n,i,s)}function Fr(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&&Cr)return t[r]}return null}class Gr extends i.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Zt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.ye={},this.ge=[],this.ce=this.Re.bind(this)}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(kr),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(M(e)){const r=O(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 Or(e,r,n,this.ce).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Br(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=mt.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.l;i||(i=r.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.l=i);const s={url:t,arraybuffer:e,rootIdx:n.wt,upAxis:n.jt,transform:n.matrix,supportedFormats:i};if(Br(t)){const e=this.Fe[n.wt];if(s.i3sInfo=Lr(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(t){const e={loadTime:i.Util.now(),current:!0,error:!0,node:t};this.tileCache.add(t.id,e)}He(t){const e={loadTime:i.Util.now(),current:!0,node:t};this.tileCache.add(t.id,e)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.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||r.createREGL({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),this.painter=new br(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=T({},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 ye(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(mt.getJSON(n).then((t=>{delete this.Ze[n];const e=this.Fe[s];if(e){t.nodes?wr(e,t.nodes):(e[t.id]=t,wr(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 Or(n,e,i,s).load()}(t,n,0,r,i,this.ce).then((t=>{this.onTilesetLoad(t,e,r)}))}}function kr(t,e){return t.Pt-e.Pt}function Hr(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function Vr(t,e,r){return Math.sqrt(function(t,e,r){var n=H(zr,r,t),i=Hr(Xr,e,0),s=Hr(Yr,e,1),o=Hr(Zr,e,2),a=K(i),c=K(s),l=K(o);X(i,i),X(s,s),X(o,o);var f=Wr;f[0]=Y(n,i),f[1]=Y(n,s),f[2]=Y(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 zr=[],Xr=[],Yr=[],Zr=[],Wr=[];const jr=2*Math.PI;class Kr{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||de(r,i,1e-14))&&(r<s||de(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 qr=[0,0,1];function $r(t,e){return te(e,t[0],t[1],t[2])}class Jr{constructor(t,e){this.normal=r.vec3.copy([],t),this.distance=e}static fromPointNormal(t,e,n){var i=-r.vec3.dot(e,t);return r.vec3.copy(n.normal,e),n.distance=i,n}}const Qr=[],tn=[],en=[],rn=[],nn=[],sn=[],on=[],an=[],cn=[],ln=[],fn=new Jr([1,0,0],0),un=[];class hn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new Kr(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var n,i,s,o=0;if(!Kr.contains(this.rectangle,e)){var a=this.southwestCornerCartesian,c=this.northeastCornerCartesian,l=this.westNormal,f=this.southNormal,u=this.eastNormal,h=this.northNormal,_=r.vec3.subtract(un,t,a),d=r.vec3.dot(_,l),E=r.vec3.dot(_,f),T=r.vec3.subtract(un,t,c),m=r.vec3.dot(T,u),A=r.vec3.dot(T,h);d>0?o+=d*d:m>0&&(o+=m*m),E>0?o+=E*E:A>0&&(o+=A*A)}if(n=e[2],i=this.minimumHeight,n>(s=this.maximumHeight)){var p=n-s;o+=p*p}else if(n<i){var y=i-n;o+=y*y}return Math.sqrt(o)}computeBox(t){const e=this;$r(Kr.southwest(t,tn),e.southwestCornerCartesian),$r(Kr.northeast(t,tn),e.northeastCornerCartesian),Qr[0]=t.west,Qr[1]=.5*(t.south+t.north),Qr[2]=0;var n=$r(Qr,en),i=r.vec3.cross(nn,n,qr);r.vec3.normalize(e.westNormal,i),Qr[0]=t.east;var s=$r(Qr,an),o=r.vec3.cross(nn,qr,s);r.vec3.normalize(e.eastNormal,o);var a,c=r.vec3.subtract(nn,n,s),l=r.vec3.normalize(rn,c),f=t.south;if(f>0){Qr[0]=.5*(t.west+t.east),Qr[1]=f;var u=$r(Qr,cn);r.vec3.copy(ln,l);var h=Jr.fromPointNormal(e.southwestCornerCartesian,e.westNormal,fn);_n(cn,ln,h,e.southwestCornerCartesian),a=ue(u,sn)}else a=he(Kr.southeast(t,tn),sn);var _=r.vec3.cross(on,a,c);r.vec3.normalize(e.southNormal,_);var d,E=t.north;if(E<0){Qr[0]=.5*(t.west+t.east),Qr[1]=E;var T=$r(Qr,cn);r.vec3.scale(ln,l,-1);var m=Jr.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,fn);_n(cn,ln,m,e.northeastCornerCartesian),d=ue(T,sn)}else d=he(Kr.northwest(t,tn),sn);var A=r.vec3.cross(on,c,d);r.vec3.normalize(e.northNormal,A)}}function _n(t,e,n,i){var s=t,o=e,a=n.normal,c=r.vec3.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-n.distance-r.vec3.dot(a,s))/c;if(!(l<0))return i=r.vec3.scale(i,o,l),r.vec3.add(i,s,i)}}const dn=new i.Extent(0,0,0,0),En=new i.Extent(0,0,0,0),Tn=[],mn=[],An=[],pn=[],yn=new i.Point(0,0),gn=[],Rn=new i.Coordinate(0,0),bn=r.mat4.identity([]);class In extends i.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=g(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.mat4.identity([]),wt:e,Pe:0}}(t,e))),this.fire("rootready",{roots:this.Ke.slice(0)})}getExtent(t){if(!t&&0!==t){const t=new i.Extent;for(let e=0;e<this.Ke.length;e++)if(this.Ke[e].boundingVolume){const r=this.boundingVolumeToExtent(this.Ke[e]);t._combine(r)}return t}return this.Ke[t]&&this.Ke[t].boundingVolume?this.boundingVolumeToExtent(this.Ke[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.qe?bn:t.matrix,n=this.getMap();if(t.boundingVolume.region){const e=t.boundingVolume.region;return new i.Extent(y(e[0]),y(e[1]),y(e[2]),y(e[3]))}if(t.boundingVolume.sphere){const s=t.boundingVolume.sphere,o=oe([],r.vec3.transformMat4([],s,e)),a=s[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new i.Extent(c,l)}if(t.boundingVolume.box){const s=t.boundingVolume.box,o=r.vec3.transformMat4([],s,e),a=new i.Coordinate(oe([],o)),c=s.slice(3);r.mat3.multiply(c,r.mat3.fromMat4([],t.matrix),c);const l=r.vec3.length(c.slice(0,3)),f=r.vec3.length(c.slice(3,6)),u=r.vec3.length(c.slice(6,9)),h=Math.max(l,f,u),_=n.locate(a,-h,h),d=n.locate(a,h,-h);return new i.Extent(_,d)}return null}getRootTiles(){return this.Ke}getTiles(){const t=this.getRenderer();if(!t.ready)return this.$e(),{tiles:pn};const e=this.getMap(),n=e.cameraPosition;let i,s;if(e.getGLZoom)s=e.pointToDistance(n[2],0,e.getGLZoom()),Rn.set(n[0],n[1]),i=e.pointToCoord(Rn,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(n[2],0,t),Rn.set(n[0],n[1]),i=e.pointAtResToCoord(Rn,t)}this.Je=this.Je||[],r.vec3.set(this.Je,p(i.x),p(i.y),s),this.Qe=te(this.Qe||[],this.Je[0],this.Je[1],this.Je[2]),this.tr=2*Math.tan(.5*p(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&&(M(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 Nn(r,e);if(r.box)return 0===Sn(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(t){t.id=i.Util.GUID(),t.matrix=t.transform||r.mat4.identity([]),t.ar=this.cr(t),t.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(t)||(t.matrix=r.mat4.multiply(t.matrix,t.parent.matrix,t.matrix)),t.wt=t.parent.wt,void 0===t.Pe&&(t.Pe=t.parent.Pe+1),t.maxExtent=t.parent.maxExtent),t.refine=t.refine&&t.refine.toLowerCase()||"replace",t.content&&!t.content.url&&t.content.uri&&(t.content.url=t.content.uri),this.lr(t)}lr(t){const e=t.boundingVolume;if(!e||e.qe)return;const n=this.options.services[t.wt].heightOffset||0,i=this.options.offset,s=m(i)||i[0]||i[1];if(!t.boundingVolume||!n&&r.mat4.exactEquals(t.matrix,bn)&&!s)return;const{region:o,box:a,sphere:c}=e;if(o){const t=this.ur([y(o[0]),y(o[1])]);o[0]=p(t.x),o[1]=p(t.y);const e=this.ur([y(o[2]),y(o[3])]);o[2]=p(e.x),o[3]=p(e.y),o[4]+=n,o[5]+=n}else if(a||c){const e=a||c,i=r.vec3.transformMat4(Tn,e,t.matrix),s=oe(mn,i),o=this.ur([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=n,te(e,p(s[0]),p(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,n){if(!t)return void console.warn("invalid tileset at : "+n);const i=(t.asset&&t.asset.gltfUpAxis||e&&e.jt||this.options.services[e.wt].upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const s=n.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 n=e.boundingVolume;T(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",n&&(e.boundingVolume=n);const i=t.root.transform;i&&(e.parent?o||(e.matrix=r.mat4.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||M(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:n})}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(t,e){e||(e=new i.Point(0,0));const r=this.getMap();return r.getGLZoom?r.coordToPoint(t,r.getGLZoom(),e):r.coordToPointAtRes(t,r.getGLRes(),e)}_r(t,e,n){const s=t.id;let o=this.je[s];const{boundingVolume:c}=t,l=c.sphere,_=c.region,E=c.box;if(!o){let e,n,a;if(_){e=dn.set(y(_[0]),y(_[1]),y(_[2]),y(_[3]));const t=e.getCenter(),r=this.Tr(t);e=e.convertTo((t=>this.Vt(t,yn)),En),a=_[4],n=_[5],o=this.je[s]=[[e.xmin,e.ymin,a*r[2]],[e.xmax,e.ymax,n*r[2]]],o.center=t}else if(l){const t=oe(Tn,l),e=new i.Coordinate(t),r=this.Vt(e,yn).toArray(),n=this.Tr(e);r.push(t[2]*n[2]),o=this.je[s]=[r,l[3]*n[2]],o.center=e}else if(E){const e=oe(Tn,E),n=new i.Coordinate(e),a=this.Vt(n,yn).toArray(),c=this.Tr(n);a.push(e[2]*c[2]);const l=E.slice(3);r.mat4.exactEquals(t.matrix,bn)||r.mat3.multiply(l,r.mat3.fromMat4(gn,t.matrix),l);for(let t=0;t<l.length;t++)l[t]*=c[t%3],E[3+t]=l[t];o=this.je[s]=[...a,...l],o.center=n}}if(e){if(_)dn.xmin=o[0][0],dn.ymin=o[0][1],dn.xmax=o[1][0],dn.ymax=o[1][1];else if(l){const t=o[2];dn.xmin=o[0][0]-t,dn.ymin=o[0][1]-t,dn.xmax=o[0][0]+t,dn.ymax=o[0][1]+t}else if(E){const t=o[1],e=o[2];dn.xmin=o[0][0]-t,dn.ymin=o[0][1]-e,dn.xmax=o[0][0]+t,dn.ymax=o[0][1]+e}if(!e.intersects(dn))return!1}return _?f(n,o):l?function(t,e,r){h(t);for(var n=e[0],i=-e[1],s=0;s<6;s++)if((!r||"0"!==r.charAt(s))&&d(a[s],n)<i)return!1;return!0}(n,o):!!E&&function(t,e,r){h(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||u(a[n],e)))return!1;return!0}(n,o)}Tr(t){const e=this.getMap(),n=e.distanceToPointAtRes(100,100,e.getGLRes(),t);return r.vec3.set(An,n.x/100*1.01,n.y/100*1.01,n.y/100),An}ur(t){Array.isArray(t)&&(t=new i.Coordinate(t));let e=this.options.offset;if(m(e)&&(e=e(Array.isArray(t)?new i.Coordinate(t):t)),e[0]||e[1]){const r=this.getMap(),n=r.getGLRes(),i=r.coordToPointAtRes(t,n);return i._sub(e),r.pointAtResToCoord(i,n)}return t}er(t){const e=this.options.services[t].maxExtent;if(!e)return null;const r=this.Ke[t];return r.maxExtent||(r.maxExtent=new i.Extent(e).convertTo((t=>this.Vt(t)))),r.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 hn(t.boundingVolume.region));return t.mr.distanceToCamera(e,r)}(t,this.Qe,this.Je):t.boundingVolume.sphere?i=Nn(t.boundingVolume,this.Qe):t.boundingVolume.box&&(i=Sn(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 Nn(t,e){const n=t.sphere,i=r.vec3.dist(n,e),s=t.sphere[3];return i<s?0:i-s}function Sn(t,e){const n=t.box;return Vr(r.vec3.set(Tn,n[0],n[1],n[2]),r.mat3.set(gn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}In.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]}),In.registerRenderer("gl",Gr),In.registerJSONType("Geo3DTilesLayer");class wn{constructor(t,e,r){this.o=t,this.Ar=e||Pt,this.l=r,this.pr={"image/crn":Sr.crn&&Sr.crn(),"image/ktx2":Sr.ktx2&&Sr.ktx2(),"image/cttf":Sr.ktx2&&Sr.ktx2(),"draco":Sr.draco&&Sr.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)):mt.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.o,decoders:this.pr,supportedFormats:this.l,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?(_=me(t,u,a),u+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(u+=c),l>0&&(d=Ae(t,u,l),u+=l,f>0)){const e=pe(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=ge(_.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 Mn{constructor(t,e,r,n){this.o=t,this.Ar=e||Pt,this.l=r,this.pr={"image/crn":Sr.crn&&Sr.crn(),"image/ktx2":Sr.ktx2&&Sr.ktx2(),"image/cttf":Sr.ktx2&&Sr.ktx2(),"draco":Sr.draco&&Sr.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)):mt.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.o,decoders:this.pr,supportedFormats:this.l,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=I(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?mt.getArrayBuffer(n,{}).then((t=>this.Sr(n,{buffer:t.data,byteOffset:0},o))):mt.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}=Se(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=ge(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++)On(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 Ne(new Float32Array(t.length),t,e,r)}Rr(){return null}}function On(t,e,r,n){if(t[0]=vn(e,n),t[1]=vn(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]))*Cn(e),t[1]=(1-Math.abs(e))*Cn(t[1])}return X(t,t)}function vn(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 Cn(t){return t<0?-1:1}class xn{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.yr(t,e,r,n)):mt.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}=Se(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=Sr.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:Ie(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=ge(a.BATCH_ID,t,c.offset,_):n.BATCH_ID=Un(_);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=ge(a.BATCH_ID,t,c.offset,_):T.BATCH_ID=Un(_);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 Ne(new Float32Array(t.length),t,e,r)}Rr(){return null}}function Un(t){const e=w(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:Ie(e),array:r}}class Bn{constructor(t,e){this.o=t,this.Ar=e||Pt}load(t,e,r=0,n=0,i){return e?this.yr(t,e,r,n,i):mt.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 wn(this.o,this.Ar);else if("i3dm"===s[r].magic)n=new Mn(this.o,this.Ar);else if("pnts"===s[r].magic)n=new xn;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Bn(this.o,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=Ee(i,c),n=i.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+r,byteLength:n}),c+=n}return o}}if(s.transcoders){const t=i.Map.VERSION;if(t.indexOf("1.0.0-beta")>=0||t.indexOf("1.0.0-alpha")>=0){const t=s.transcoders.inject(o);i.registerWorkerAdapter("@maptalks/3dtiles",t)}else i.registerWorkerAdapter("@maptalks/3dtiles",(function(){return s.transcoders.inject(o)}))}else i.registerWorkerAdapter("@maptalks/3dtiles",o);t.B3DMLoader=wn,t.CMPTLoader=Bn,t.Geo3DTilesLayer=In,t.Geo3DTilesUtil=v,t.Geo3DTransform=_e,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.15.1")}));
|
|
23
|
+
*/const Nr=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")},Sr=Nr(),wr=Sr.gl_trans__coders=Sr.gl_trans__coders||{};function Mr(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}wr.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=Sr.gl_trans__coders=Sr.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Nr.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},wr.registerTranscoder=function(t,e){wr[t]=e},wr.getTranscoder=function(t){return wr[t]};const Or=[];class vr{constructor(t,e,r,n){this.ce=t,this.Mt=e,this.le=n,this.fe=r.version,t.indexOf("i3s:tileset:")<0?(this.fe<=1.6?this.ue="root":this.ue=0,r.version=this.fe):(this.ue=t.substring("i3s:tileset:".length),this.fe>1.6&&(this.ue=parseInt(this.ue))),this.ce=t,this.he=r}load(){const t=this.he,e=t.layerScene.baseUrl;if(this.fe<=1.6)return t[this.ue]&&t[this.ue].lodSelection?(this._e=t[this.ue],this.de()):new Promise((r=>{let n=e+"/nodes/"+this.ue;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.le(this.Mt,n,(()=>{this._e=t[this.ue],r(this.de())}))}));if(this.fe>=1.7){if(t[this.ue])return this._e=t[this.ue],this.de();const r=Math.floor(this.ue/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.le(this.Mt,i,(()=>{this._e=t[this.ue],n(this.de())}))}))}return null}getTileset(){return this.Ee}getChildrenURL(){return this.Te}de(){const t=this.he,e=t.layerScene.baseUrl,r=this._e.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.fe<=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.le(this.Mt,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.le(this.Mt,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.me())):this.me()}me(){return Promise.resolve(this.Ae())}pe(t){Mr(this.he,t)}Ae(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.ye(this._e,!0)}}ye(t){const e=this.fe,r=this.he,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Cr([],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=Cr([],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];k(Or,e,r,n);const o=q(Or);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=B([]),_=n.children;var d;if(_){d=[];const t=this.he;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.ye(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._e}}function Cr(t,e,r,n){return ee(t,p(e),p(r),n)}const xr=!!wr.ktx2,Ur=r.mat4.identity([]),Br=(()=>{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 Pr(t){return t.indexOf("i3s:mesh")>=0}const Lr="i3s:mesh:".length;function Dr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Lr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const u=Ur;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=wr.draco&&f?o[1]:o[0],d=wr.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};if(i&&Br&&f&&!wr.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 Fr(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 Fr(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=Gr(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 A(t[o])&&Fr(t[o],e,r,n,i,s)}function Gr(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&&xr)return t[r]}return null}const kr=[];class Hr extends i.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Wt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.ge={},this.Re=[],this.le=this.be.bind(this)}getAnalysisMeshes(){if(!this.painter)return kr;const t=this.painter.getPaintedMeshes();if(!t)return kr;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&v(e,r),n.length&&v(e,n),i.length&&v(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Re.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.Ie(),this.Ne();const{selectedTiles:o,leaves:a,requests:c}=this.Se(n,i);c.length&&this.loadTiles(c),this.we(o,a,e),this.Me(),c.length||this.completeRender()}Se(t,e){let r=[];this.Oe();let n=0;const i=this.ve(),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.Ce(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.xe(i))o=!0;else{this.Ue(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Be(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}}Be(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.Pe===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.Pe=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}xe(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}Ue(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Le+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.De(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Le<=r&&n.push(i[s])}}return e}we(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(M(e)){const r=O(e);return void this.Fe(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.Mt,n=this.Ge[r];return new vr(e,r,n,this.le).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Pr(e)&&(e=t.baseUrl+e);const r=this.layer.options.services[t.Mt];if(r.ajaxInMainThread){let n=r.urlParams;n&&(n=(e.indexOf("?")>0?"&":"?")+n);let i=At.getArrayBuffer(e+(n||""),r.fetchOptions);const s=i.xhr;i=i.then((r=>{delete this.ge[e],r?this.Fe(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.ge[e],this.onTileError(r,t)})),this.ge[e]=s}else this.Fe(e,null,t)}Fe(t,e,n){let i=this.l;i||(i=r.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.l=i);const s={url:t,arraybuffer:e,rootIdx:n.Mt,upAxis:n.Kt,transform:n.matrix,supportedFormats:i};if(Pr(t)){const e=this.Ge[n.Mt];if(s.i3sInfo=Dr(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.Re.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}Ne(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.Re.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.Re.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.ke(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.ke(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.ke(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.ke(t,e,r,n)})),r++}}ke(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.He(n);e.memorySize=r,this.onTileLoad(t,e)}}He(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.He(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.Ve(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.ze(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.Xe(e),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Xe(t){const e={loadTime:i.Util.now(),current:!0,error:!0,node:t};this.tileCache.add(t.id,e)}Ve(t){const e={loadTime:i.Util.now(),current:!0,node:t};this.tileCache.add(t.id,e)}abortTileLoading(t){if(!t||!this.workerConn)return;const e=t.node.content.url;if(this.layer.options.services[t.node.Mt].ajaxInMainThread){const t=this.ge[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.ge[e]}Oe(){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.Ye(this.canvas,e)),this.regl=this.regl||r.createREGL({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),this.painter=new Ir(this.regl,t)}prepareWorker(){const t=this.getMap();this.workerConn||(this.workerConn=new Xt("@maptalks/3dtiles",t.id));const e=this.workerConn;if(!e.isActive())return;let r=this.layer.options||{};r=T({},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.Me(!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}Me(t){this.Ze||(this.Ze=Date.now());const e=Date.now();if(t||!(e-this.Ze<this.layer.options.retireInterval)){this.Ze=e;for(const e in this.tilesLoading){const r=this.tilesLoading[e];!t&&r.current||this.abortTileLoading(r)}}}ve(){return this.getMap().isInteracting()?this.layer.options.loadingLimitOnInteracting:this.layer.options.loadingLimit}Ye(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}Ce(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 ge(t,e,0,r)}Ie(){if(!this.We)return;const t=this.layer.options.i3sNodepageLimitPerFrame||Number.MAX_VALUE;let e=0;const r=[];for(const n in this.We){const i=this.We[n];if("pending"===i.status)continue;i.status="pending";const s=i.rootIdx;if(r.push(At.getJSON(n).then((t=>{delete this.We[n];const e=this.Ge[s];if(e){t.nodes?Mr(e,t.nodes):(e[t.id]=t,Mr(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)}be(t,e,r){this.We||(this.We={}),this.We[e]=this.We[e]||[],this.We[e].rootIdx=t,this.We[e].push(r),this.setToRedraw()}ze(t,e,r){this.Ge||(this.Ge=[]);const n=e.Mt;this.Ge[n]||(this.Ge[n]={});const i=this.Ge[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 vr(n,e,i,s).load()}(t,n,0,r,i,this.le).then((t=>{this.onTilesetLoad(t,e,r)}))}}function Vr(t,e){return t.Lt-e.Lt}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=V(Yr,r,t),i=zr(Zr,e,0),s=zr(Wr,e,1),o=zr(jr,e,2),a=q(i),c=q(s),l=q(o);Y(i,i),Y(s,s),Y(o,o);var f=Kr;f[0]=Z(n,i),f[1]=Z(n,s),f[2]=Z(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||Ee(r,i,1e-14))&&(r<s||Ee(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 ee(e,t[0],t[1],t[2])}class tn{constructor(t,e){this.normal=r.vec3.copy([],t),this.distance=e}static fromPointNormal(t,e,n){var i=-r.vec3.dot(e,t);return r.vec3.copy(n.normal,e),n.distance=i,n}}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 n,i,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,_=r.vec3.subtract(_n,t,a),d=r.vec3.dot(_,l),E=r.vec3.dot(_,f),T=r.vec3.subtract(_n,t,c),m=r.vec3.dot(T,u),A=r.vec3.dot(T,h);d>0?o+=d*d:m>0&&(o+=m*m),E>0?o+=E*E:A>0&&(o+=A*A)}if(n=e[2],i=this.minimumHeight,n>(s=this.maximumHeight)){var p=n-s;o+=p*p}else if(n<i){var y=i-n;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 n=Qr(en,nn),i=r.vec3.cross(on,n,Jr);r.vec3.normalize(e.westNormal,i),en[0]=t.east;var s=Qr(en,ln),o=r.vec3.cross(on,Jr,s);r.vec3.normalize(e.eastNormal,o);var a,c=r.vec3.subtract(on,n,s),l=r.vec3.normalize(sn,c),f=t.south;if(f>0){en[0]=.5*(t.west+t.east),en[1]=f;var u=Qr(en,fn);r.vec3.copy(un,l);var h=tn.fromPointNormal(e.southwestCornerCartesian,e.westNormal,hn);En(fn,un,h,e.southwestCornerCartesian),a=he(u,an)}else a=_e($r.southeast(t,rn),an);var _=r.vec3.cross(cn,a,c);r.vec3.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);r.vec3.scale(un,l,-1);var m=tn.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,hn);En(fn,un,m,e.northeastCornerCartesian),d=he(T,an)}else d=_e($r.northwest(t,rn),an);var A=r.vec3.cross(cn,c,d);r.vec3.normalize(e.northNormal,A)}}function En(t,e,n,i){var s=t,o=e,a=n.normal,c=r.vec3.dot(a,o);if(!(Math.abs(c)<1e-15)){var l=(-n.distance-r.vec3.dot(a,s))/c;if(!(l<0))return i=r.vec3.scale(i,o,l),r.vec3.add(i,s,i)}}const Tn=new i.Extent(0,0,0,0),mn=new i.Extent(0,0,0,0),An=[],pn=[],yn=[],gn=[],Rn=new i.Point(0,0),bn=[],In=new i.Coordinate(0,0),Nn=r.mat4.identity([]);class Sn extends i.Layer{constructor(t,e){super(t,e),this.je(),this.ge={},this.Ke=[]}je(){let t=this.options.services.map((t=>t.url));this.qe=t.map(((t,e)=>function(t,e){t=g(t);return{baseUrl:t.substring(0,t.lastIndexOf("/"))+"/",content:{url:t},refine:"replace",matrix:r.mat4.identity([]),Mt:e,Le:0}}(t,e))),this.fire("rootready",{roots:this.qe.slice(0)})}getExtent(t){if(!t&&0!==t){const t=new i.Extent;for(let e=0;e<this.qe.length;e++)if(this.qe[e].boundingVolume){const r=this.boundingVolumeToExtent(this.qe[e]);t._combine(r)}return t}return this.qe[t]&&this.qe[t].boundingVolume?this.boundingVolumeToExtent(this.qe[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.$e?Nn:t.matrix,n=this.getMap();if(t.boundingVolume.region){const e=t.boundingVolume.region;return new i.Extent(y(e[0]),y(e[1]),y(e[2]),y(e[3]))}if(t.boundingVolume.sphere){const s=t.boundingVolume.sphere,o=ae([],r.vec3.transformMat4([],s,e)),a=s[3],c=n.locate(o,-a,a),l=n.locate(o,a,-a);return new i.Extent(c,l)}if(t.boundingVolume.box){const s=t.boundingVolume.box,o=r.vec3.transformMat4([],s,e),a=new i.Coordinate(ae([],o)),c=s.slice(3);r.mat3.multiply(c,r.mat3.fromMat4([],t.matrix),c);const l=r.vec3.length(c.slice(0,3)),f=r.vec3.length(c.slice(3,6)),u=r.vec3.length(c.slice(6,9)),h=Math.max(l,f,u),_=n.locate(a,-h,h),d=n.locate(a,h,-h);return new i.Extent(_,d)}return null}getRootTiles(){return this.qe}getTiles(){const t=this.getRenderer();if(!t.ready)return this.Je(),{tiles:gn};const e=this.getMap(),n=e.cameraPosition;let i,s;if(e.getGLZoom)s=e.pointToDistance(n[2],0,e.getGLZoom()),In.set(n[0],n[1]),i=e.pointToCoord(In,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(n[2],0,t),In.set(n[0],n[1]),i=e.pointAtResToCoord(In,t)}this.Qe=this.Qe||[],r.vec3.set(this.Qe,p(i.x),p(i.y),s),this.tr=ee(this.tr||[],this.Qe[0],this.Qe[1],this.Qe[2]),this.er=2*Math.tan(.5*p(e.getFov()));const o=e.projViewMatrix,a={children:[],level:-1};let c=a;const l=[];for(let e=0;e<this.qe.length;e++){let r=1/0;const n=[this.qe[e]],i=this.rr(e);for(;n.length>0;){const e=n.pop();for(e.id||this.nr(e);c.level>=e.Le;)c=c.parent;const s=this.ir(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.sr(l,t);if(!1===this.options.services[e.Mt].alwaysShow)continue;if(!(0===s&&e.Le<=r))continue;e.content&&(r=e.Le)}e.Lt<1/0&&this.ar(e);const a=this.De(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.sr(l,a),u){h&&"add"===e.refine&&this.sr(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].Kt=e.Kt,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(M(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.sr(l,a)}}}return{root:a,tiles:l}}sr(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.Qe,this.tr,r)||t.push(e)}De(t,e){return{id:t.id,node:t,children:[],level:t.Le,parent:e,content:t.content&&t.content.url}}nr(t){t.id=i.Util.GUID(),t.matrix=t.transform||r.mat4.identity([]),t.cr=this.lr(t),t.parent&&(function(t){return t.content&&t.content.uri&&t.content.uri.indexOf("i3s:")>=0}(t)||(t.matrix=r.mat4.multiply(t.matrix,t.parent.matrix,t.matrix)),t.Mt=t.parent.Mt,void 0===t.Le&&(t.Le=t.parent.Le+1),t.maxExtent=t.parent.maxExtent),t.refine=t.refine&&t.refine.toLowerCase()||"replace",t.content&&!t.content.url&&t.content.uri&&(t.content.url=t.content.uri),this.ur(t)}ur(t){const e=t.boundingVolume;if(!e||e.$e)return;const n=this.options.services[t.Mt].heightOffset||0,i=this.options.offset,s=m(i)||i[0]||i[1];if(!t.boundingVolume||!n&&r.mat4.exactEquals(t.matrix,Nn)&&!s)return;const{region:o,box:a,sphere:c}=e;if(o){const t=this.hr([y(o[0]),y(o[1])]);o[0]=p(t.x),o[1]=p(t.y);const e=this.hr([y(o[2]),y(o[3])]);o[2]=p(e.x),o[3]=p(e.y),o[4]+=n,o[5]+=n}else if(a||c){const e=a||c,i=r.vec3.transformMat4(An,e,t.matrix),s=ae(pn,i),o=this.hr([s[0],s[1]]);s[0]=o.x,s[1]=o.y,s[2]+=n,ee(e,p(s[0]),p(s[1]),s[2])}e.$e=!0}lr(t){return void 0===t.geometricError||!t.boundingVolume}ar(t){let e=t.parent;for(;e&&e.cr&&!(e.Lt<=t.Lt);)e.Lt=t.Lt,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,n){if(!t)return void console.warn("invalid tileset at : "+n);const i=(t.asset&&t.asset.gltfUpAxis||e&&e.Kt||this.options.services[e.Mt].upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const s=n.indexOf("realspace/")>-1;t.asset&&t.asset.s3mType&&s&&(t.root.baseUrl+="data/path/");const o=t.asset.i3s;if(t.root.Kt=i,e){const n=e.boundingVolume;T(e,t.root),e.refine=e.refine&&e.refine.toLowerCase()||"replace",n&&(e.boundingVolume=n);const i=t.root.transform;i&&(e.parent?o||(e.matrix=r.mat4.multiply([],e.parent.matrix,i)):e.matrix=i),this.ur(e),e._r=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.cr=this.lr(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||M(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.Je(),this.fire("loadtileset",{tileset:t,index:e.Mt,url:n})}ir(t,e,r){if(t.Lt=1/0,0===t.Le||t.cr)return 1;if(!this.dr(t,e,r))return-1;if(0===t.geometricError)return 1;let n=this.options.services[t.Mt].maximumScreenSpaceError;null==n&&(n=8);let i=this.Er(t);return 0===i&&t.parent&&(i=.5*(t.parent.Tr||0)),i>=n?1:0}zt(t,e){e||(e=new i.Point(0,0));const r=this.getMap();return r.getGLZoom?r.coordToPoint(t,r.getGLZoom(),e):r.coordToPointAtRes(t,r.getGLRes(),e)}dr(t,e,n){const s=t.id;let o=this.Ke[s];const{boundingVolume:c}=t,l=c.sphere,_=c.region,E=c.box;if(!o){let e,n,a;if(_){e=Tn.set(y(_[0]),y(_[1]),y(_[2]),y(_[3]));const t=e.getCenter(),r=this.mr(t);e=e.convertTo((t=>this.zt(t,Rn)),mn),a=_[4],n=_[5],o=this.Ke[s]=[[e.xmin,e.ymin,a*r[2]],[e.xmax,e.ymax,n*r[2]]],o.center=t}else if(l){const t=ae(An,l),e=new i.Coordinate(t),r=this.zt(e,Rn).toArray(),n=this.mr(e);r.push(t[2]*n[2]),o=this.Ke[s]=[r,l[3]*n[2]],o.center=e}else if(E){const e=ae(An,E),n=new i.Coordinate(e),a=this.zt(n,Rn).toArray(),c=this.mr(n);a.push(e[2]*c[2]);const l=E.slice(3);r.mat4.exactEquals(t.matrix,Nn)||r.mat3.multiply(l,r.mat3.fromMat4(bn,t.matrix),l);for(let t=0;t<l.length;t++)l[t]*=c[t%3],E[3+t]=l[t];o=this.Ke[s]=[...a,...l],o.center=n}}if(e){if(_)Tn.xmin=o[0][0],Tn.ymin=o[0][1],Tn.xmax=o[1][0],Tn.ymax=o[1][1];else if(l){const t=o[2];Tn.xmin=o[0][0]-t,Tn.ymin=o[0][1]-t,Tn.xmax=o[0][0]+t,Tn.ymax=o[0][1]+t}else if(E){const t=o[1],e=o[2];Tn.xmin=o[0][0]-t,Tn.ymin=o[0][1]-e,Tn.xmax=o[0][0]+t,Tn.ymax=o[0][1]+e}if(!e.intersects(Tn))return!1}return _?f(n,o):l?function(t,e,r){h(t);for(var n=e[0],i=-e[1],s=0;s<6;s++)if((!r||"0"!==r.charAt(s))&&d(a[s],n)<i)return!1;return!0}(n,o):!!E&&function(t,e,r){h(t);for(var n=0;n<6;n++)if(!(r&&"0"===r.charAt(n)||u(a[n],e)))return!1;return!0}(n,o)}mr(t){const e=this.getMap(),n=e.distanceToPointAtRes(100,100,e.getGLRes(),t);return r.vec3.set(yn,n.x/100*1.01,n.y/100*1.01,n.y/100),yn}hr(t){Array.isArray(t)&&(t=new i.Coordinate(t));let e=this.options.offset;if(m(e)&&(e=e(Array.isArray(t)?new i.Coordinate(t):t)),e[0]||e[1]){const r=this.getMap(),n=r.getGLRes(),i=r.coordToPointAtRes(t,n);return i._sub(e),r.pointAtResToCoord(i,n)}return t}rr(t){const e=this.options.services[t].maxExtent;if(!e)return null;const r=this.qe[t];return r.maxExtent||(r.maxExtent=new i.Extent(e).convertTo((t=>this.zt(t)))),r.maxExtent}Er(t){const e=this.er,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.Ar||(t.Ar=new dn(t.boundingVolume.region));return t.Ar.distanceToCamera(e,r)}(t,this.tr,this.Qe):t.boundingVolume.sphere?i=wn(t.boundingVolume,this.tr):t.boundingVolume.box&&(i=Mn(t.boundingVolume,this.tr));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Lt=i,t.Tr=o,o}Je(){const t=this.getRenderer();t&&t.setToRedraw()}te(t){return this.Ke[t]}}function wn(t,e){const n=t.sphere,i=r.vec3.dist(n,e),s=t.sphere[3];return i<s?0:i-s}function Mn(t,e){const n=t.box;return Xr(r.vec3.set(An,n[0],n[1],n[2]),r.mat3.set(bn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[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.o=t,this.pr=e||Lt,this.l=r,this.yr={"image/crn":wr.crn&&wr.crn(),"image/ktx2":wr.ktx2&&wr.ktx2(),"image/cttf":wr.ktx2&&wr.ktx2(),"draco":wr.draco&&wr.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.gr(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.gr(t,i,r,n)}))}gr(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Rr(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.pr(a,o.glb,{transferable:!0,requestImage:this.o,decoders:this.yr,supportedFormats:this.l,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}}))}Rr(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?(_=Ae(t,u,a),u+=a,o=_.BATCH_LENGTH):_={"BATCH_LENGTH":o},c>0&&(u+=c),l>0&&(d=pe(t,u,l),u+=l,f>0)){const e=ye(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=Re(_.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}}}br(){return null}}class vn{constructor(t,e,r,n){this.o=t,this.pr=e||Lt,this.l=r,this.yr={"image/crn":wr.crn&&wr.crn(),"image/ktx2":wr.ktx2&&wr.ktx2(),"image/cttf":wr.ktx2&&wr.ktx2(),"draco":wr.draco&&wr.draco()},this.Ir=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.gr(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.gr(t,i,r,n)}))}gr(t,e,r,n,i){return this.Nr(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Sr(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})}))}Nr(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.o,decoders:this.yr,supportedFormats:this.l,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=I(new Uint8Array(e,c+r,a.byteLength-c));-1==n.indexOf("://")&&(n=t.substring(0,t.lastIndexOf("/"))+"/"+n);return n.indexOf(".glb")>0?At.getArrayBuffer(n,{}).then((t=>this.wr(n,{buffer:t.data,byteOffset:0},o))):At.getJSON(n,{}).then((t=>this.wr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.wr(t,n,o)}}wr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.pr(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}}))}Sr(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}=we(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.Mr(new Uint16Array(t,n+c.offset,3*h),e,r)},o.push(u.POSITION.array.buffer)}if(a.BATCH_ID){u.BATCH_ID=Re(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.Or(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.Or(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}}Or(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}Mr(t,e,r){return Se(new Float32Array(t.length),t,e,r)}br(){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 Y(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.gr(t,e,r,n)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.gr(t,i,r,n)}))}gr(t,e,r,n){return this.vr(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}))}vr(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}=we(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.Cr||(this.Cr=wr.draco()),this.Cr(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.Ur(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:Ne(t.constructor),array:t},o.push(t.buffer)}else if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?n.BATCH_ID=Re(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.Ur(t,a,c.offset,_,o,u,h);if(a.BATCH_ID||Object.keys(l).length){a.BATCH_ID?T.BATCH_ID=Re(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})}Ur(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.Mr(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}Mr(t,e,r){return Se(new Float32Array(t.length),t,e,r)}br(){return null}}function Pn(t){const e=w(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:Ne(e),array:r}}class Ln{constructor(t,e){this.o=t,this.pr=e||Lt}load(t,e,r=0,n=0,i){return e?this.gr(t,e,r,n,i):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.gr(t,i,r,n)}))}gr(t,e,r,n,i){n||(n=e.byteLength);const s=this.Br(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new On(this.o,this.pr);else if("i3dm"===s[r].magic)n=new vn(this.o,this.pr);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.o,this.pr)}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})))}Br(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=Te(i,c),n=i.getUint32(c+8,!0);o.push({magic:e,buffer:t,offset:c+r,byteLength:n}),c+=n}return o}}if(s.transcoders){const t=i.Map.VERSION;if(t.indexOf("1.0.0-beta")>=0||t.indexOf("1.0.0-alpha")>=0){const t=s.transcoders.inject(o);i.registerWorkerAdapter("@maptalks/3dtiles",t)}else i.registerWorkerAdapter("@maptalks/3dtiles",(function(){return s.transcoders.inject(o)}))}else i.registerWorkerAdapter("@maptalks/3dtiles",o);t.B3DMLoader=On,t.CMPTLoader=Ln,t.Geo3DTilesLayer=Sn,t.Geo3DTilesUtil=C,t.Geo3DTransform=de,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.15.2")}));
|