@maptalks/3dtiles 0.18.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/maptalks.3dtiles.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/3dtiles v0.18.
|
|
2
|
+
* @maptalks/3dtiles v0.18.1
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2022 maptalks.org
|
|
5
5
|
*/
|
|
@@ -15,9 +15,9 @@ 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++
|
|
|
15
15
|
* LICENSE : UNLICENSED
|
|
16
16
|
* (c) 2016-2022 maptalks.org
|
|
17
17
|
*/
|
|
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}0===i&&(i=n*a.BYTES_PER_ELEMENT);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 L(i,n,i),L(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)}O(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}O(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.M(e,t)}return null}M(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)}C(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],Ot=[0,0,0],xt=[0,0,0,1],Mt=[1,1,1],Ct={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},vt={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Ut={v(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(Ot,i)):"rotation"===e.target.path?(this.B(s,f.samplers[e.sampler],n,1),l.rotation=et(xt,s)):"scale"===e.target.path?(this.U(o,f.samplers[e.sampler],n,1),l.scale=G(Mt,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.L(vt,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.L(vt,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.L(vt,e,r,3*n);i&&(t=this.P(t,i,e.input.array,3*n));break}}return t},B(t,e,r){switch(e.interpolation){case"LINEAR":{const n=this.L(vt,e,r,1);n&&Q(t,n.PREVIOUS,n.NEXT,n.INTERPOLATION);break}case"STEP":{const n=this.L(vt,e,r,1);n&&(t=$(t,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this.L(vt,e,r,3);if(n){for(let t=0;t<n.PREVIOUS.length;t++)n.PREVIOUS[t]=Math.acos(n.PREVIOUS[t]),n.NEXT[t]=Math.acos(n.NEXT[t]);t=this.P(t,n,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},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},L(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},P(t,e,r,n){const i=e.INTERPOLATION,s=r[e.PREINDEX],o=r[e.NEXTINDEX];for(let r=0;r<3;r++){const a=e.PREVIOUS[n+r],c=(o-s)*e.PREVIOUS[2*n+r],l=e.NEXT[3+r],f=(o-s)*e.NEXT[r],u=(2*Math.pow(i,3)-3*Math.pow(i,2)+1)*a+(Math.pow(i,3)-2*Math.pow(i,2)+i)*c+(2*-Math.pow(i,3)+3*Math.pow(i,2))*l+(Math.pow(i,3)-Math.pow(i,2))*f;t[r]=u}return t},getAnimationClip(t,e,r,n){const i=t.nodes[e]&&t.nodes[e].weights;return k(Ot,...Ct.TRANSLATION),$(xt,...Ct.ROTATION),k(Mt,...Ct.SCALE),this.v(n,t,e,r,Ot,xt,Mt,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(Ur){}t&&"undefined"!=typeof createImageBitmap&&(Bt=!0)}const Lt="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}=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.K(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}))}K(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}))}W(){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.W()),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.O(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(!Lt)return void e(new Error("There is no canvas to draw image!"));Lt.width=r.width,Lt.height=r.height;const t=Lt.getContext("2d");t.drawImage(r,0,0,r.width,r.height);const n=t.getImageData(0,0,r.width,r.height),i={width:r.width,height:r.height,data:new Uint8Array(n.data)};e(null,i)},r.onerror=function(t){e(t)},r.src=t}let 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 Kt{constructor(t,e){this.max=t,this.currentSize=0,this.onRemove=e,this.reset()}reset(){if(this.data){const t=this.data.values();for(const e of t)this.onRemove(e)}return this.data=new Map,this.currentSize=0,this}clear(){this.reset(),delete this.onRemove}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const r=this.data.get(t);r&&r.node&&r.node.memorySize&&(this.currentSize-=r.node.memorySize),this.data.delete(t),this.data.set(t,e)}else this.data.set(t,e);return this}shrink(){if(this.currentSize>this.max){const t=this.data.keys();let e=t.next();for(;this.currentSize>this.max&&void 0!==e.value;){if(!this.data.get(e.value).current){const t=this.getAndRemove(e.value);t&&this.onRemove(t)}e=t.next()}}}has(t){return this.data.has(t)}keys(){const t=new Array(this.data.size);let e=0;const r=this.data.keys();for(let n of r)t[e++]=n;return t}getAndRemove(t){if(!this.has(t))return null;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),e}get(t){if(!this.has(t))return null;const e=this.data.get(t);return this.data.delete(t),this.data.set(t,e),e}remove(t){if(!this.has(t))return this;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),this.onRemove(e),this}setMaxSize(t){return this.max=t,this.shrink(),this}getMemorySize(){let t=0;const e=this.data.values();for(const r of e){const e=r&&r.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t){const e=this.data.values();for(const r of e)r.current=t}}function 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=[];Wt(n[r],i,t,e)}}}function Wt(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++)Wt(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?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 $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,O,x,M,C,v=(1-E)*fe(e)/(.5*fe(y)),U=0;do{v-=U,b=1/(1+v*m),I=1/(1+v*A),N=1/(1+v*p),S=b*b,w=I*I,O=N*N,x=S*b,M=w*I,C=O*N,g=u*S+h*w+_*O-1,R=u*x*m+h*M*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=W(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}=we(s||"UNSIGNED_SHORT"),l=Ne(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){const i=ge(t,e,r,n);return i.array.buffer.byteLength!==e.byteLength&&(i.array=i.array.slice()),i}function be(t,e,r,n){const{byteOffset:i,componentType:s,type:o}=t,{ctor:a}=we(s||"UNSIGNED_SHORT"),c=Ne(o),l=new a(e,i,r*c);return 1===c?l[n]:l.subarray(n*c,n*c+c)}const Ie={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};function Ne(t){return t?Ie[t]:1}const Se={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function we(t){return Se[t]}function Oe(t){for(let e in Se)if(t===Se[e].ctor)return Se[e].type;throw new Error("unrecognized ctor:"+t)}function xe(t,e,r,n){const i=t,s=e.length/3;for(let t=0;t<s;t++)i[3*t]=e[3*t]/65535*n[0]+r[0],i[3*t+1]=e[3*t+1]/65535*n[1]+r[1],i[3*t+2]=e[3*t+2]/65535*n[2]+r[2];return i}function Me(t,e,r){let n=t.getUint32(12,!0),i=t.getUint32(16,!0),s=t.getUint32(20,!0),o=t.getUint32(24,!0);const a=t.buffer;let c,l,f={},u={};n>0&&(f=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 Ce={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},ve={},Ue={east:[],north:[],up:[],west:[],south:[],down:[]},Be=[],Le=[],Pe=[];const De=[0,0,0];function Fe(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 Ge=(ze={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"}}[ke="east"][He="north"],ve[Xe=ke+He]?Ve=ve[Xe]:(Ve=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)<=v*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(n-o)<=v*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=v*Math.max(1,Math.abs(i),Math.abs(a))}(t,De))G(Be,Ce[ke]),G(Le,Ce[He]),G(Pe,Ce[ze]);else if(Ee(t[0],0,1e-14)&&Ee(t[1],0,1e-14)){var n=R(t[2]);G(Be,Ce[ke]),"east"!==ke&&"west"!==ke&&X(Be,Be,n),G(Le,Ce[He]),"east"!==He&&"west"!==He&&X(Le,Le,n),G(Pe,Ce[ze]),"east"!==ze&&"west"!==ze&&X(Pe,Pe,n)}else{he(t,Ue.up);var i=Ue.up,s=Ue.east;s[0]=-t[1],s[1]=t[0],s[2]=0,Y(Ue.east,s),K(Ue.north,i,s),X(Ue.down,Ue.up,-1),X(Ue.west,Ue.east,-1),X(Ue.south,Ue.north,-1),Be=Ue[ke],Le=Ue[He],Pe=Ue[ze]}return r[0]=Be[0],r[1]=Be[1],r[2]=Be[2],r[3]=0,r[4]=Le[0],r[5]=Le[1],r[6]=Le[2],r[7]=0,r[8]=Pe[0],r[9]=Pe[1],r[10]=Pe[2],r[11]=0,r[12]=t[0],r[13]=t[1],r[14]=t[2],r[15]=1,r},ve[Xe]=Ve),Ve);var ke,He,Ve,ze,Xe;const Ye=[],Ze=[],Ke=[],je=[],We=[],qe=[],$e=[],Je={x:0,y:0},Qe={x:0,y:0},tr=Math.PI/180;const er={"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:rr,getTextureMinFilter:nr,getTextureWrap:ir,getMaterialType:sr,getMaterialFormat:or,getPrimitive:ar,getUniqueREGLBuffer:cr}=r.reshader.REGLHelper,lr=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],fr=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:ur,logoutIBLResOnCanvas:hr,getIBLResOnCanvas:_r,getPBRUniforms:dr}=r.reshader.pbr.PBRUtils,Er={factor:0,units:0},Tr={specularStrength:0,materialShininess:1},mr=[1,1,1],Ar=r.mat4.identity([]),pr=t=>t.material instanceof r.reshader.PhongMaterial,yr=t=>t.material instanceof r.reshader.pbr.StandardMaterial,gr=[!0,!0,!0,!0],Rr=[],br=new i.Coordinate(0,0),Ir=new i.Point(0,0),Nr=[],Sr=[],wr=[],Or=[],xr={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"};class Mr{constructor(t,e){this.tt=e,this.et=e.getRenderer().canvas,this.pickingFBO=e.getRenderer().pickingFBO,this.rt=new i.SpatialReference,this.nt=t,this.it=new r.reshader.Renderer(t),this.st={},this.ot={},this.ct={},this.lt={},this.ft={},this.ut={},this.ht={},this._t=new r.reshader.Scene,this.dt=new r.reshader.Scene,this.Et=new r.reshader.Scene,this.Tt=new r.reshader.Scene,this.At=new r.reshader.ResourceLoader(t.texture(2)),this.yt=this.gt.bind(this),this.Rt=new r.reshader.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.bt(),this.It=new r.reshader.KHRTechniquesWebglManager(this.nt,this.Nt(),this.At);const n=this.getMap();n.altitudeToPoint&&(this.St=n.altitudeToPoint(100,n.getGLRes())/100)}getI3DMMeshes(){return this.ft}getPNTSMeshes(){return this.lt}getB3DMMeshes(){return this.ct}getPaintedMeshes(){return this.wt}getMap(){return this.tt.getMap()}paint(t,e,r,n){const i=this.getMap();if(!t.length||!i)return;const s=this.Ot(),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.xt(n);if(!i)continue;this.ut[n.id]&&(i=this.ut[n.id],i=S(i));let d=a[n.Mt].polygonOffset||Er;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].Ct=n,e[n.id]||l.push(i[a])}}let d=0;const E=this.It.getExcludeFilter();d+=this.vt(this.Ut,s,[r,pr,E],n,l,u,_),d+=this.vt(this.Bt,s,[r,yr,E],n,l,u,_),this.It.forEachShader(((t,e,i)=>{const s=this.Ot(i);d+=this.vt(t,s,[r,e],n,l,u,_)})),this.dt.setMeshes(h);const T=this.Lt();return d+=this.it.render(this.Pt,T,this.dt,n&&n.fbo),this.wt={pntsMeshes:h,i3dmMeshes:_,b3dmMeshes:u},d}vt(t,e,r,n,i,s,o){t.filter=r.filter((t=>!!t)),e.debug=!1,this._t.setMeshes(i),e.stencilEnable=!1,e.debug=!1,e.cullFace="back",e.colorMask=gr;let a=0;return this._t.setMeshes(s),a+=this.it.render(t,e,this._t,n&&n.fbo),e.stencilEnable=!1,this.Et.setMeshes(o),a+=this.it.render(t,e,this.Et,n&&n.fbo),a}Dt(t,e){return e.Ct.Ft-t.Ct.Ft}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.Gt(e);n&&(n.getBoundingBox&&!f(o,n.getBoundingBox())||a.push(n))}this.kt.filter=n,this.Tt.setMeshes(a);const c=this.Ht(r);this.it.render(this.kt,c,this.Tt,i&&i.fbo)}deleteTile(t){const e=t.node.id;this.Vt(e)}Vt(t){const e=this.ot[t];e&&(e.geometry.dispose(),e.dispose(),delete this.ot[t]);let r=this.ct[t]||this.lt[t]||this.ft[t]||this.ut[t]||this.st[t];this.ut[t]?this.zt(t):r&&(this.Xt(r),delete this.ct[t],delete this.lt[t],delete this.ft[t],delete this.st[t])}zt(t){let e=this.ut[t];e=S(e);for(let t=0;t<e.length;t++){const{id:r}=e[t].properties;this.Vt(r)}delete this.ut[t]}Xt(t){if(Array.isArray(t))for(let e=0,r=t.length;e<r;e++)this.Xt(t[e]);else{const e=t.geometry.properties.url;if(e){const t=this.ht[e];t&&(t.refCount--,t.refCount<=0&&(t.geometry.dispose(),t.material.dispose(),delete this.ht[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.tt;hr(t.getRenderer().canvas,t.getMap());for(const t in this.ut)this.zt(t);this.ut={};for(const t in this.ct)this.Vt(t);this.ct={};for(const t in this.lt)this.Vt(t);this.lt={};for(const t in this.ft)this.Vt(t);this.ft={};for(const t in this.st)this.Vt(t);this.st={};for(const t in this.ot)this.Vt(t);this.ot={},this.Ut&&(this.Ut.dispose(),delete this.Ut),this.Bt&&(this.Bt.dispose(),delete this.Bt),this.Pt&&(this.Pt.dispose(),delete this.Pt),this.kt&&(this.kt.dispose(),delete this.kt),this.It.dispose(),this.picking&&this.picking.dispose()}Gt(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.Yt(n),s=this.Yt(s);const o=n.add(s).Zt(.5);n._sub(o),s._sub(o);const a=this.Kt(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}xt(t){return this.ct[t.id]||this.lt[t.id]||this.ft[t.id]||this.ut[t.id]}has(t){return this.xt(t)||this.st[t.id]}createPntsMesh(t,e,n,i){if(this.lt[e]){const t=this.lt[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.jt(wr,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.lt[e]=T,i(null,{id:e,mesh:[T]}),[T]}createI3DMMesh(t,e,n,i){if(this.ft[e]){const t=this.ft[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.qt(n.$t),{i3dm:o,featureTable:a,gltf:c,batchTable:l,batchTableBin:f,count:u}=t,h=a.INSTANCES_LENGTH,{rtcCenter:_,rtcCoord:d}=t,E=this.jt(wr,d),T=this.Wt(Or,n,_,d);r.mat4.multiply(E,T,E);const{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=[],O=new Float32Array(1),x=new Float32Array(3),M=[],C=[],v=[],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?(qt(S,p,e),qt(I,A,e),r.vec3.cross(w,S,I),r.vec3.normalize(w,w),N(M,S,0),N(M,I,1),N(M,w,2),r.quat.fromMat3(C,M)):R?(qt(B,R,e),r.quat.fromMat3(C,B)):r.quat.identity(C),y?(qt(O,y,e),r.vec3.set(v,O[0],O[0],O[0])):g?(qt(x,g,e),r.vec3.set(v,...x)):r.vec3.set(v,1,1,1),r.mat4.fromRotationTranslationScale(U,C,t,v),$t(b.instance_vectorA,e,U,0),$t(b.instance_vectorB,e,U,1),$t(b.instance_vectorC,e,U,2)}));const L={};for(const t in b)L[t]={buffer:this.nt.buffer({dimension:b[t].length/h,data:b[t]}),divisor:1};const P=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.Jt(t,i,o,a,n,!0,P);_&&!_.isReady()&&(F=!1,D++);const d=new r.reshader.InstancedMesh(L,h,c,_);d.properties.magic="i3dm",d.properties.id=e,d.properties.count=u,d.properties.batchTable=l,d.properties.batchTableBin=f;const T=this.Qt(t,c,_,n.Mt,a),m=r.mat4.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.mat4.multiply(m,m,t.matrices[e]);r.mat4.multiply(m,s,m),d.setPositionMatrix(m),d.setLocalTransform(r.mat4.copy([],E)),d.setDefines(T),d.properties.polygonOffset={offset:0,factor:0},G.push(d)})),F?(this.ft[e]=G,i(null,{id:e,mesh:G})):(this.st[e]={meshes:G,count:D},G.te=i),G}createB3DMMesh(t,e,n,s){if(this.ct[e]||this.st[e]){const t=this.ct[e];return console.warn(`mesh with id(${e}) was already created.`),this.st[e]||s(null,{id:e,mesh:t}),t}let o;if(n.maxExtent){const t=new i.Extent(n.maxExtent).convertTo((t=>this._pointToPrj(t)));o=[t.xmin,t.ymin,t.xmax,t.ymax]}const a=t.gltf,{projCenter:c}=a.extensions.MAPTALKS_RTC,{rtcCoord:l,center:f}=a.extensions.CESIUM_RTC,u=this.qt(n.$t);let h;h=a.asset&&a.asset.sharePosition?this.jt(wr,l):this.ee(wr,l,c,n.Mt);const _=this.tt.options.services[n.Mt].shader||"phong",d=[];let E=0,T=!0;return jt(a,((i,s,a,c)=>{let{geometry:m,material:A}=this.Jt(i,s,a,c,n,!1,_);A&&!A.isReady()&&(T=!1,E++);const p=new r.reshader.Mesh(m,A);p.properties.magic="b3dm",p.properties.id=e,p.properties.batchTable=t.batchTable,p.properties.batchTableBin=t.batchTableBin,p.properties.count=t.featureTable.BATCH_LENGTH;const y=this.Qt(i,m,A,n.Mt,c);p.setDefines(y),o&&(y.USE_MAX_EXTENT=1,p.setUniform("maxPrjExtent",o));let g=r.mat4.identity([]);if(c.asset.sharePosition&&i.matrices&&i.matrices.length)for(let t=0;t<i.matrices.length;t++)r.mat4.multiply(g,g,i.matrices[t]);if(c.asset.sharePosition){const t=this.Wt(Or,n,f,l);r.mat4.multiply(g,u,g),r.mat4.multiply(g,h,g),r.mat4.multiply(g,t,g)}else r.mat4.multiply(g,h,g);p.setLocalTransform(g),d.push(p)})),T?(this.ct[e]=d,s(null,{id:e,mesh:d})):(this.st[e]={meshes:d,count:E},d.te=s),d}Wt(t,e,n,s){const o=this.getMap(),a=this.tt.options.services[e.Mt].heightOffset||0,c=new i.Coordinate(s);let l;l=o.altitudeToPoint?this.St:o.distanceToPointAtRes(100,100,o.getGLRes(),c).y/100;let f=e.matrix?r.mat4.copy(t,e.matrix):r.mat4.identity(t);if(n){Fe(f,r.vec3.transformMat4(Rr,n,f),f)}const u=function(t,e,r,n,i,s,o){e=G(Ye,e);const a=ee(Ye,e[0]*tr,e[1]*tr,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(Ke,0,0,-6378137):ae(Ke,c),Je.x=f[0],Je.y=f[1];const u=n.project(Je,Qe);je[0]=u.x/i,je[1]=u.y/i,je[2]=(f[2]+o)*s;const h=Ge(a,l,We),_=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],c=e[6],l=e[7],f=e[8],u=e[9],h=e[10],_=e[11],d=e[12],E=e[13],T=e[14],m=e[15],A=r*a-n*o,p=r*c-i*o,y=r*l-s*o,g=n*c-i*a,R=n*l-s*a,b=i*l-s*c,I=f*E-u*d,N=f*T-h*d,S=f*m-_*d,w=u*T-h*E,O=u*m-_*E,x=h*m-_*T,M=A*x-p*O+y*w+g*S-R*N+b*I;return M?(M=1/M,t[0]=(a*x-c*O+l*w)*M,t[1]=(i*O-n*x-s*w)*M,t[2]=(E*b-T*R+m*g)*M,t[3]=(h*R-u*b-_*g)*M,t[4]=(c*S-o*x-l*N)*M,t[5]=(r*x-i*S+s*N)*M,t[6]=(T*y-d*b-m*p)*M,t[7]=(f*b-h*y+_*p)*M,t[8]=(o*O-a*S+l*I)*M,t[9]=(n*S-r*O-s*I)*M,t[10]=(d*R-E*y+m*A)*M,t[11]=(u*y-f*R-_*A)*M,t[12]=(a*N-o*w-c*I)*M,t[13]=(r*w-n*N+i*I)*M,t[14]=(E*p-d*g-T*A)*M,t[15]=(f*g-u*p+h*A)*M,t):null}(qe,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}($e,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,O=i*A+a*p+f*y,x=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]=O,r[10]=x,r[11]=0,r[12]=t[12],r[13]=t[13],r[14]=t[14],r[15]=t[15],r}(_,d,t);return Fe(t,je,E),t}(f,s,f,o.getProjection(),o.getGLRes(),l,a),h=function(t,e){return k(t,e[12],e[13],e[14]),t}(Sr,u);let _=this.tt.options.offset;if(m(_)){_=_(this.tt.re(e.id).center)}return r.vec3.set(Nr,_[0],_[1],0),r.vec3.sub(h,h,Nr),Fe(u,h,u),u}createCMPTMesh(t,e,r,n){if(this.ut[e]){const t=this.ut[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.ut[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.Ut:this.Bt).getGeometryDefines(e);return i.asset&&"S3M"===i.asset.generator&&this.ne(s,e,i),e.data.uvRegion&&(s.HAS_I3S_UVREGION=1),s}ne(t,e,r){e.data.aNormal&&(t.VertexNormal=1),e.data.instanceId&&(t.Instance=1),e.data.aTexCoord0&&(t.TexCoord=1),e.data.aColor&&(t.VertexColor=1),e.data.aTexCoord1&&(t.TexCoord2=1),e.data.uv2&&(t.InstanceBim=1),e.data.aTexCoord0&&r.textures.length&&(t.COMPUTE_TEXCOORD=1)}Jt(t,e,r,n,i,s,o){let a=!1;n.asset&&"S3M"===n.asset.generator&&(a=!0,n.extensions=n.extensions||{},n.extensions.KHR_techniques_webgl=er);const c=n.url+"-"+e+"-"+r;if(this.ht[c])return this.ht[c].refCount++,this.ht[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.ie(t,n,s,a);l=e.material,f=e.geometry;this.tt.options.services[i.Mt].fillEmptyDataInMissingAttribute&&(f.desc.fillEmptyDataInMissingAttribute=!0)}else{f=this.se(t,s,xr);const e=this.tt.options.services[i.Mt].material;l=this.oe(t.material,n,o,e||Tr)}l&&!l.isReady()?l.ae=i.id:l||(l=this.Rt);const h={refCount:1,geometry:f,material:l};return f.properties.url=c,this.ht[c]=h,h}ie(t,e,r,n){const{geometry:i,material:s}=this.It.createMesh(t,e,r,n);return{geometry:i,material:s}}se(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=cr(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,pickingIdAttribute:n._BATCHID,primitive:void 0===t.mode?"triangles":ar(t.mode)});return o.generateBuffers(this.nt,{excludeElementsInVAO:e}),o}ee(t,e,n,i){const s=r.mat4.identity(t),o=this.getMap();br.x=n[0],br.y=n[1];const a=this._prjToPoint(br),c=this.ce(),l=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes());let f;br.x=e[0],br.y=e[1],f=o.altitudeToPoint?this.St:o.distanceToPointAtRes(100,100,o.getGLRes(),br).y/100;let u=this.tt.options.offset;m(u)&&(u=u(br));const h=this.tt.options.services[i].heightOffset||0;return r.vec3.set(Sr,a.x-u[0],a.y-u[1],f*n[2]+f*h),r.mat4.translate(s,s,Sr),r.vec3.set(c,l,l,f),r.mat4.scale(s,s,c),s}jt(t,e){const n=r.mat4.identity(t),i=this.getMap(),s=this.ce();br.x=e[0],br.y=e[1];const o=i.distanceToPointAtRes(100,100,i.getGLRes(),br);let a;return a=i.altitudeToPoint?this.St:o.y/100,r.vec3.set(s,o.x/100*1.01,o.y/100*1.01,a),r.mat4.scale(n,n,s),n}bt(){const t={x:0,y:0,width:()=>this.et?this.et.width:1,height:()=>this.et?this.et.height:1};this.kt=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.Pt=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.Nt();this.Ut=new r.reshader.PhongShader({extraCommandProps:i}),this.Bt=new r.reshader.pbr.StandardShader({extraCommandProps:i});const s=this.tt;ur(s.getRenderer().canvas,this.nt,s.getMap()),this.picking=new r.reshader.FBORayPicking(this.it,{vert:this.Bt.vert,extraCommandProps:i,uniforms:this.Bt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO)}Nt(){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||gr,cull:{enable:!0,face:(t,e)=>e.cullFace||"back"},stencil:{enable:(t,e)=>!0===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}}}Ht(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}Lt(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)}}Ot(){const t=this.getMap(),e=this.tt.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=_r(e),i=dr(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}oe(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.O(t)),o.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(o.baseColorTexture=r)}else{if(s.normalTexture){const t=this.O(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;o.normalTexture=t,o.normalMapFactor=r}if(s.occlusionTexture){const t=this.O(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;o.occlusionTexture=t,o.occlusionFactor=r}if(s.emissiveTexture){const t=this.O(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.O(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.O(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.yt),a}O(t){const e={type:t.type?sr(t.type):"uint8",format:t.format?or(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=rr(i.magFilter)),i.minFilter&&(e.min=nr(i.minFilter)),i.wrapS&&(e.wrapS=ir(i.wrapS)),i.wrapT&&(e.wrapT=ir(i.wrapT))),new r.reshader.Texture2D(e,this.At)}le(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}gt({target:t}){const e=t.ae,r=this.st[e];if(r.count--,!r.count){const t=r.meshes;this.ct[e]=t,delete this.st[e];const n=t.te;delete t.te,n(null,{mesh:r.meshes,id:e})}}ce(){return mr}Yt(t){return this.tt.Yt(t)}Kt(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(),Ir)}qt(t){return"Y"===t?lr:"X"===t?fr:Ar}pick(t,e,r=3){const n=this.tt;if(!n||!n.options.picking)return null;if(!this.pickingFBO||!this.picking)return null;const i=this.getMap(),s=this.Ot(),o=this.picking;o.render(this._t.getMeshes(),s,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,r,s,{viewMatrix:i.viewMatrix,projMatrix:i.projMatrix,returnPoint:n.options.pickingPoint}));const{meshId:c,pickingId:l,point:f}=a,u=(0===c||c)&&o.getMeshAt(c);if(!u||!u.geometry)return null;const h=u.properties;f&&f.length&&(f[0]=Math.round(1e5*f[0])/1e5,f[1]=Math.round(1e5*f[1])/1e5,f[2]=Math.round(1e5*f[2])/1e5);const _={batchId:l};if(h&&h.batchTable){const{batchTable:t,batchTableBin:e,count:r}=h,n=l;for(const i in t)void 0!==t[i].byteOffset?_[i]=be(t[i],e,r,n):_[i]=t[i][n]}return{data:_,point:f}}}
|
|
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}0===i&&(i=n*a.BYTES_PER_ELEMENT);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 L(i,n,i),L(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)}O(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}O(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.M(e,t)}return null}M(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)}C(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],Ot=[0,0,0],xt=[0,0,0,1],Mt=[1,1,1],Ct={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},vt={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Ut={v(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(Ot,i)):"rotation"===e.target.path?(this.B(s,f.samplers[e.sampler],n,1),l.rotation=et(xt,s)):"scale"===e.target.path?(this.U(o,f.samplers[e.sampler],n,1),l.scale=G(Mt,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.L(vt,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.L(vt,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.L(vt,e,r,3*n);i&&(t=this.P(t,i,e.input.array,3*n));break}}return t},B(t,e,r){switch(e.interpolation){case"LINEAR":{const n=this.L(vt,e,r,1);n&&Q(t,n.PREVIOUS,n.NEXT,n.INTERPOLATION);break}case"STEP":{const n=this.L(vt,e,r,1);n&&(t=$(t,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this.L(vt,e,r,3);if(n){for(let t=0;t<n.PREVIOUS.length;t++)n.PREVIOUS[t]=Math.acos(n.PREVIOUS[t]),n.NEXT[t]=Math.acos(n.NEXT[t]);t=this.P(t,n,e.input.array,3);for(let e=0;e<t.length;e++)t[e]=Math.cos(t[e])}break}}return t},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},L(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},P(t,e,r,n){const i=e.INTERPOLATION,s=r[e.PREINDEX],o=r[e.NEXTINDEX];for(let r=0;r<3;r++){const a=e.PREVIOUS[n+r],c=(o-s)*e.PREVIOUS[2*n+r],l=e.NEXT[3+r],f=(o-s)*e.NEXT[r],u=(2*Math.pow(i,3)-3*Math.pow(i,2)+1)*a+(Math.pow(i,3)-2*Math.pow(i,2)+i)*c+(2*-Math.pow(i,3)+3*Math.pow(i,2))*l+(Math.pow(i,3)-Math.pow(i,2))*f;t[r]=u}return t},getAnimationClip(t,e,r,n){const i=t.nodes[e]&&t.nodes[e].weights;return k(Ot,...Ct.TRANSLATION),$(xt,...Ct.ROTATION),k(Mt,...Ct.SCALE),this.v(n,t,e,r,Ot,xt,Mt,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(Ur){}t&&"undefined"!=typeof createImageBitmap&&(Bt=!0)}const Lt="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}=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.K(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}))}K(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}))}W(){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.W()),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.O(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(!Lt)return void e(new Error("There is no canvas to draw image!"));Lt.width=r.width,Lt.height=r.height;const t=Lt.getContext("2d");t.drawImage(r,0,0,r.width,r.height);const n=t.getImageData(0,0,r.width,r.height),i={width:r.width,height:r.height,data:new Uint8Array(n.data)};e(null,i)},r.onerror=function(t){e(t)},r.src=t}let 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 Kt{constructor(t,e){this.max=t,this.currentSize=0,this.onRemove=e,this.reset()}reset(){if(this.data){const t=this.data.values();for(const e of t)this.onRemove(e)}return this.data=new Map,this.currentSize=0,this}clear(){this.reset(),delete this.onRemove}add(t,e){if(!e)return this;if(e.node&&e.node.memorySize&&(this.currentSize+=e.node.memorySize),this.has(t)){const r=this.data.get(t);r&&r.node&&r.node.memorySize&&(this.currentSize-=r.node.memorySize),this.data.delete(t),this.data.set(t,e)}else this.data.set(t,e);return this}shrink(){if(this.currentSize>this.max){const t=this.data.keys();let e=t.next();for(;this.currentSize>this.max&&void 0!==e.value;){if(!this.data.get(e.value).current){const t=this.getAndRemove(e.value);t&&this.onRemove(t)}e=t.next()}}}has(t){return this.data.has(t)}keys(){const t=new Array(this.data.size);let e=0;const r=this.data.keys();for(let n of r)t[e++]=n;return t}getAndRemove(t){if(!this.has(t))return null;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),e}get(t){if(!this.has(t))return null;const e=this.data.get(t);return this.data.delete(t),this.data.set(t,e),e}remove(t){if(!this.has(t))return this;const e=this.data.get(t);return e.node&&e.node.memorySize&&(this.currentSize-=e.node.memorySize),this.data.delete(t),this.onRemove(e),this}setMaxSize(t){return this.max=t,this.shrink(),this}getMemorySize(){let t=0;const e=this.data.values();for(const r of e){const e=r&&r.node;e&&e.memorySize&&(t+=e.memorySize)}return t}markAll(t){const e=this.data.values();for(const r of e)r.current=t}}function 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=[];Wt(n[r],i,t,e)}}}function Wt(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++)Wt(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?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 $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,O,x,M,C,v=(1-E)*fe(e)/(.5*fe(y)),U=0;do{v-=U,b=1/(1+v*m),I=1/(1+v*A),N=1/(1+v*p),S=b*b,w=I*I,O=N*N,x=S*b,M=w*I,C=O*N,g=u*S+h*w+_*O-1,R=u*x*m+h*M*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=W(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}=we(s||"UNSIGNED_SHORT"),l=Ne(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){const i=ge(t,e,r,n);return i.array.buffer.byteLength!==e.byteLength&&(i.array=i.array.slice()),i}function be(t,e,r,n){const{byteOffset:i,componentType:s,type:o}=t,{ctor:a}=we(s||"UNSIGNED_SHORT"),c=Ne(o),l=new a(e,i,r*c);return 1===c?l[n]:l.subarray(n*c,n*c+c)}const Ie={"SCALAR":1,"VEC2":2,"VEC3":3,"VEC4":4};function Ne(t){return t?Ie[t]:1}const Se={"BYTE":{ctor:Int8Array,type:5120,name:"Int8Array"},"UNSIGNED_BYTE":{ctor:Uint8Array,type:5121,name:"Uint8Array"},"SHORT":{ctor:Int16Array,type:5122,name:"Int16Array"},"UNSIGNED_SHORT":{ctor:Uint16Array,type:5123,name:"Uint16Array"},"INT":{ctor:Int32Array,type:5124,name:"Int32Array"},"UNSIGNED_INT":{ctor:Uint32Array,type:5125,name:"Uint32Array"},"FLOAT":{ctor:Float32Array,type:5126,name:"Float32Array"},"DOUBLE":{ctor:Float64Array,type:5126,name:"Float64Array"}};function we(t){return Se[t]}function Oe(t){for(let e in Se)if(t===Se[e].ctor)return Se[e].type;throw new Error("unrecognized ctor:"+t)}function xe(t,e,r,n){const i=t,s=e.length/3;for(let t=0;t<s;t++)i[3*t]=e[3*t]/65535*n[0]+r[0],i[3*t+1]=e[3*t+1]/65535*n[1]+r[1],i[3*t+2]=e[3*t+2]/65535*n[2]+r[2];return i}function Me(t,e,r){let n=t.getUint32(12,!0),i=t.getUint32(16,!0),s=t.getUint32(20,!0),o=t.getUint32(24,!0);const a=t.buffer;let c,l,f={},u={};n>0&&(f=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 Ce={north:[-1,0,0],east:[0,1,0],up:[0,0,1],south:[1,0,0],west:[0,-1,0],down:[0,0,-1]},ve={},Ue={east:[],north:[],up:[],west:[],south:[],down:[]},Be=[],Le=[],Pe=[];const De=[0,0,0];function Fe(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 Ge=(ze={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"}}[ke="east"][He="north"],ve[Xe=ke+He]?Ve=ve[Xe]:(Ve=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)<=v*Math.max(1,Math.abs(r),Math.abs(s))&&Math.abs(n-o)<=v*Math.max(1,Math.abs(n),Math.abs(o))&&Math.abs(i-a)<=v*Math.max(1,Math.abs(i),Math.abs(a))}(t,De))G(Be,Ce[ke]),G(Le,Ce[He]),G(Pe,Ce[ze]);else if(Ee(t[0],0,1e-14)&&Ee(t[1],0,1e-14)){var n=R(t[2]);G(Be,Ce[ke]),"east"!==ke&&"west"!==ke&&X(Be,Be,n),G(Le,Ce[He]),"east"!==He&&"west"!==He&&X(Le,Le,n),G(Pe,Ce[ze]),"east"!==ze&&"west"!==ze&&X(Pe,Pe,n)}else{he(t,Ue.up);var i=Ue.up,s=Ue.east;s[0]=-t[1],s[1]=t[0],s[2]=0,Y(Ue.east,s),K(Ue.north,i,s),X(Ue.down,Ue.up,-1),X(Ue.west,Ue.east,-1),X(Ue.south,Ue.north,-1),Be=Ue[ke],Le=Ue[He],Pe=Ue[ze]}return r[0]=Be[0],r[1]=Be[1],r[2]=Be[2],r[3]=0,r[4]=Le[0],r[5]=Le[1],r[6]=Le[2],r[7]=0,r[8]=Pe[0],r[9]=Pe[1],r[10]=Pe[2],r[11]=0,r[12]=t[0],r[13]=t[1],r[14]=t[2],r[15]=1,r},ve[Xe]=Ve),Ve);var ke,He,Ve,ze,Xe;const Ye=[],Ze=[],Ke=[],je=[],We=[],qe=[],$e=[],Je={x:0,y:0},Qe={x:0,y:0},tr=Math.PI/180;const er={"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:rr,getTextureMinFilter:nr,getTextureWrap:ir,getMaterialType:sr,getMaterialFormat:or,getPrimitive:ar,getUniqueREGLBuffer:cr}=r.reshader.REGLHelper,lr=[1,0,0,0,0,0,1,0,0,-1,0,0,0,0,0,1],fr=[0,0,1,0,0,1,0,0,-1,0,0,0,0,0,0,1],{loginIBLResOnCanvas:ur,logoutIBLResOnCanvas:hr,getIBLResOnCanvas:_r,getPBRUniforms:dr}=r.reshader.pbr.PBRUtils,Er={factor:0,units:0},Tr={specularStrength:0,materialShininess:1},mr=[1,1,1],Ar=r.mat4.identity([]),pr=t=>t.material instanceof r.reshader.PhongMaterial,yr=t=>t.material instanceof r.reshader.pbr.StandardMaterial,gr=[!0,!0,!0,!0],Rr=[],br=new i.Coordinate(0,0),Ir=new i.Point(0,0),Nr=[],Sr=[],wr=[],Or=[],xr={"POSITION":"POSITION","NORMAL":"NORMAL","TEXCOORD_0":"TEXCOORD_0","TEXCOORD_1":"TEXCOORD_1","COLOR_0":"COLOR_0","TANGENT":"TANGENT","_BATCHID":"_BATCHID"};class Mr{constructor(t,e){this.tt=e,this.et=e.getRenderer().canvas,this.pickingFBO=e.getRenderer().pickingFBO,this.rt=new i.SpatialReference,this.nt=t,this.it=new r.reshader.Renderer(t),this.st={},this.ot={},this.ct={},this.lt={},this.ft={},this.ut={},this.ht={},this._t=new r.reshader.Scene,this.dt=new r.reshader.Scene,this.Et=new r.reshader.Scene,this.Tt=new r.reshader.Scene,this.At=new r.reshader.ResourceLoader(t.texture(2)),this.yt=this.gt.bind(this),this.Rt=new r.reshader.PhongMaterial({"baseColorFactor":[1,1,1,1]}),this.bt(),this.It=new r.reshader.KHRTechniquesWebglManager(this.nt,this.Nt(),this.At);const n=this.getMap();n.altitudeToPoint&&(this.St=n.altitudeToPoint(100,n.getGLRes())/100)}getI3DMMeshes(){return this.ft}getPNTSMeshes(){return this.lt}getB3DMMeshes(){return this.ct}getPaintedMeshes(){return this.wt}getMap(){return this.tt.getMap()}paint(t,e,r,n){const i=this.getMap();if(!t.length||!i)return;const s=this.Ot(),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.xt(n);if(!i)continue;this.ut[n.id]&&(i=this.ut[n.id],i=S(i));let d=a[n.Mt].polygonOffset||Er;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].Ct=n,e[n.id]||l.push(i[a])}}let d=0;const E=this.It.getExcludeFilter();d+=this.vt(this.Ut,s,[r,pr,E],n,l,u,_),d+=this.vt(this.Bt,s,[r,yr,E],n,l,u,_),this.It.forEachShader(((t,e,i)=>{const s=this.Ot(i);d+=this.vt(t,s,[r,e],n,l,u,_)})),this.dt.setMeshes(h);const T=this.Lt();return d+=this.it.render(this.Pt,T,this.dt,n&&n.fbo),this.wt={pntsMeshes:h,i3dmMeshes:_,b3dmMeshes:u},d}vt(t,e,r,n,i,s,o){t.filter=r.filter((t=>!!t)),e.debug=!1,this._t.setMeshes(i),e.stencilEnable=!1,e.debug=!1,e.cullFace="back",e.colorMask=gr;let a=0;return this._t.setMeshes(s),a+=this.it.render(t,e,this._t,n&&n.fbo),e.stencilEnable=!1,this.Et.setMeshes(o),a+=this.it.render(t,e,this.Et,n&&n.fbo),a}Dt(t,e){return e.Ct.Ft-t.Ct.Ft}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.Gt(e);n&&(n.getBoundingBox&&!f(o,n.getBoundingBox())||a.push(n))}this.kt.filter=n,this.Tt.setMeshes(a);const c=this.Ht(r);this.it.render(this.kt,c,this.Tt,i&&i.fbo)}deleteTile(t){const e=t.node.id;this.Vt(e)}Vt(t){const e=this.ot[t];e&&(e.geometry.dispose(),e.dispose(),delete this.ot[t]);let r=this.ct[t]||this.lt[t]||this.ft[t]||this.ut[t]||this.st[t];this.ut[t]?this.zt(t):r&&(this.Xt(r),delete this.ct[t],delete this.lt[t],delete this.ft[t],delete this.st[t])}zt(t){let e=this.ut[t];e=S(e);for(let t=0;t<e.length;t++){const{id:r}=e[t].properties;this.Vt(r)}delete this.ut[t]}Xt(t){if(Array.isArray(t))for(let e=0,r=t.length;e<r;e++)this.Xt(t[e]);else{const e=t.geometry.properties.url;if(e){const t=this.ht[e];t&&(t.refCount--,t.refCount<=0&&(t.geometry.dispose(),t.material.dispose(),delete this.ht[e]))}else t.geometry.dispose(),t.material&&t.material.dispose();t.dispose()}}remove(){const t=this.tt;hr(t.getRenderer().canvas,t.getMap());for(const t in this.ut)this.zt(t);this.ut={};for(const t in this.ct)this.Vt(t);this.ct={};for(const t in this.lt)this.Vt(t);this.lt={};for(const t in this.ft)this.Vt(t);this.ft={};for(const t in this.st)this.Vt(t);this.st={};for(const t in this.ot)this.Vt(t);this.ot={},this.Ut&&(this.Ut.dispose(),delete this.Ut),this.Bt&&(this.Bt.dispose(),delete this.Bt),this.Pt&&(this.Pt.dispose(),delete this.Pt),this.kt&&(this.kt.dispose(),delete this.kt),this.It.dispose(),this.picking&&this.picking.dispose()}Gt(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.Yt(n),s=this.Yt(s);const o=n.add(s).Zt(.5);n._sub(o),s._sub(o);const a=this.Kt(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}xt(t){return this.ct[t.id]||this.lt[t.id]||this.ft[t.id]||this.ut[t.id]}has(t){return this.xt(t)||this.st[t.id]}createPntsMesh(t,e,n,i){if(this.lt[e]){const t=this.lt[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.jt(wr,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.lt[e]=T,i(null,{id:e,mesh:[T]}),[T]}createI3DMMesh(t,e,n,i){if(this.ft[e]){const t=this.ft[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.qt(n.$t),{i3dm:o,featureTable:a,gltf:c,batchTable:l,batchTableBin:f,count:u}=t,h=a.INSTANCES_LENGTH,{rtcCenter:_,rtcCoord:d}=t,E=this.jt(wr,d),T=this.Wt(Or,n,_,d);r.mat4.multiply(E,T,E);const{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=[],O=new Float32Array(1),x=new Float32Array(3),M=[],C=[],v=[],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?(qt(S,p,e),qt(I,A,e),r.vec3.cross(w,S,I),r.vec3.normalize(w,w),N(M,S,0),N(M,I,1),N(M,w,2),r.quat.fromMat3(C,M)):R?(qt(B,R,e),r.quat.fromMat3(C,B)):r.quat.identity(C),y?(qt(O,y,e),r.vec3.set(v,O[0],O[0],O[0])):g?(qt(x,g,e),r.vec3.set(v,...x)):r.vec3.set(v,1,1,1),r.mat4.fromRotationTranslationScale(U,C,t,v),$t(b.instance_vectorA,e,U,0),$t(b.instance_vectorB,e,U,1),$t(b.instance_vectorC,e,U,2)}));const L={};for(const t in b)L[t]={buffer:this.nt.buffer({dimension:b[t].length/h,data:b[t]}),divisor:1};const P=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.Jt(t,i,o,a,n,!0,P);_&&!_.isReady()&&(F=!1,D++);const d=new r.reshader.InstancedMesh(L,h,c,_);d.properties.magic="i3dm",d.properties.id=e,d.properties.count=u,d.properties.batchTable=l,d.properties.batchTableBin=f;const T=this.Qt(t,c,_,n.Mt,a),m=r.mat4.identity([]);if(t.matrices&&t.matrices.length)for(let e=0;e<t.matrices.length;e++)r.mat4.multiply(m,m,t.matrices[e]);r.mat4.multiply(m,s,m),d.setPositionMatrix(m),d.setLocalTransform(r.mat4.copy([],E)),d.setDefines(T),d.properties.polygonOffset={offset:0,factor:0},G.push(d)})),F?(this.ft[e]=G,i(null,{id:e,mesh:G})):(this.st[e]={meshes:G,count:D},G.te=i),G}createB3DMMesh(t,e,n,s){if(this.ct[e]||this.st[e]){const t=this.ct[e];return console.warn(`mesh with id(${e}) was already created.`),this.st[e]||s(null,{id:e,mesh:t}),t}let o;if(n.maxExtent){const t=new i.Extent(n.maxExtent).convertTo((t=>this._pointToPrj(t)));o=[t.xmin,t.ymin,t.xmax,t.ymax]}const a=t.gltf,{projCenter:c}=a.extensions.MAPTALKS_RTC,{rtcCoord:l,center:f}=a.extensions.CESIUM_RTC,u=this.qt(n.$t);let h;h=a.asset&&a.asset.sharePosition?this.jt(wr,l):this.ee(wr,l,c,n.Mt);const _=this.tt.options.services[n.Mt].shader||"phong",d=[];let E=0,T=!0;return jt(a,((i,s,a,c)=>{let{geometry:m,material:A}=this.Jt(i,s,a,c,n,!1,_);A&&!A.isReady()&&(T=!1,E++);const p=new r.reshader.Mesh(m,A);p.properties.magic="b3dm",p.properties.id=e,p.properties.batchTable=t.batchTable,p.properties.batchTableBin=t.batchTableBin,p.properties.count=t.featureTable.BATCH_LENGTH;const y=this.Qt(i,m,A,n.Mt,c);p.setDefines(y),o&&(y.USE_MAX_EXTENT=1,p.setUniform("maxPrjExtent",o));let g=r.mat4.identity([]);if(c.asset.sharePosition&&i.matrices&&i.matrices.length)for(let t=0;t<i.matrices.length;t++)r.mat4.multiply(g,g,i.matrices[t]);if(c.asset.sharePosition){const t=this.Wt(Or,n,f,l);r.mat4.multiply(g,u,g),r.mat4.multiply(g,h,g),r.mat4.multiply(g,t,g)}else r.mat4.multiply(g,h,g);p.setLocalTransform(g),d.push(p)})),T?(this.ct[e]=d,s(null,{id:e,mesh:d})):(this.st[e]={meshes:d,count:E},d.te=s),d}Wt(t,e,n,s){const o=this.getMap(),a=this.tt.options.services[e.Mt].heightOffset||0,c=new i.Coordinate(s);let l;l=o.altitudeToPoint?this.St:o.distanceToPointAtRes(100,100,o.getGLRes(),c).y/100;let f=e.matrix?r.mat4.copy(t,e.matrix):r.mat4.identity(t);if(n){Fe(f,r.vec3.transformMat4(Rr,n,f),f)}const u=function(t,e,r,n,i,s,o){e=G(Ye,e);const a=ee(Ye,e[0]*tr,e[1]*tr,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(Ke,0,0,-6378137):ae(Ke,c),Je.x=f[0],Je.y=f[1];const u=n.project(Je,Qe);je[0]=u.x/i,je[1]=u.y/i,je[2]=(f[2]+o)*s;const h=Ge(a,l,We),_=function(t,e){var r=e[0],n=e[1],i=e[2],s=e[3],o=e[4],a=e[5],c=e[6],l=e[7],f=e[8],u=e[9],h=e[10],_=e[11],d=e[12],E=e[13],T=e[14],m=e[15],A=r*a-n*o,p=r*c-i*o,y=r*l-s*o,g=n*c-i*a,R=n*l-s*a,b=i*l-s*c,I=f*E-u*d,N=f*T-h*d,S=f*m-_*d,w=u*T-h*E,O=u*m-_*E,x=h*m-_*T,M=A*x-p*O+y*w+g*S-R*N+b*I;return M?(M=1/M,t[0]=(a*x-c*O+l*w)*M,t[1]=(i*O-n*x-s*w)*M,t[2]=(E*b-T*R+m*g)*M,t[3]=(h*R-u*b-_*g)*M,t[4]=(c*S-o*x-l*N)*M,t[5]=(r*x-i*S+s*N)*M,t[6]=(T*y-d*b-m*p)*M,t[7]=(f*b-h*y+_*p)*M,t[8]=(o*O-a*S+l*I)*M,t[9]=(n*S-r*O-s*I)*M,t[10]=(d*R-E*y+m*A)*M,t[11]=(u*y-f*R-_*A)*M,t[12]=(a*N-o*w-c*I)*M,t[13]=(r*w-n*N+i*I)*M,t[14]=(E*p-d*g-T*A)*M,t[15]=(f*g-u*p+h*A)*M,t):null}(qe,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}($e,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,O=i*A+a*p+f*y,x=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]=O,r[10]=x,r[11]=0,r[12]=t[12],r[13]=t[13],r[14]=t[14],r[15]=t[15],r}(_,d,t);return Fe(t,je,E),t}(f,s,f,o.getProjection(),o.getGLRes(),l,a),h=function(t,e){return k(t,e[12],e[13],e[14]),t}(Sr,u);let _=this.tt.options.offset;if(m(_)){_=_(this.tt.re(e.id).center)}return r.vec3.set(Nr,_[0],_[1],0),r.vec3.sub(h,h,Nr),Fe(u,h,u),u}createCMPTMesh(t,e,r,n){if(this.ut[e]){const t=this.ut[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.ut[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.Ut:this.Bt).getGeometryDefines(e);return i.asset&&"S3M"===i.asset.generator&&this.ne(s,e,i),e.data.uvRegion&&(s.HAS_I3S_UVREGION=1),s}ne(t,e,r){e.data.aNormal&&(t.VertexNormal=1),e.data.instanceId&&(t.Instance=1),e.data.aTexCoord0&&(t.TexCoord=1),e.data.aColor&&(t.VertexColor=1),e.data.aTexCoord1&&(t.TexCoord2=1),e.data.uv2&&(t.InstanceBim=1),e.data.aTexCoord0&&r.textures.length&&(t.COMPUTE_TEXCOORD=1)}Jt(t,e,r,n,i,s,o){let a=!1;n.asset&&"S3M"===n.asset.generator&&(a=!0,n.extensions=n.extensions||{},n.extensions.KHR_techniques_webgl=er);const c=n.url+"-"+e+"-"+r;if(this.ht[c])return this.ht[c].refCount++,this.ht[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.ie(t,n,s,a);l=e.material,f=e.geometry;this.tt.options.services[i.Mt].fillEmptyDataInMissingAttribute&&(f.desc.fillEmptyDataInMissingAttribute=!0)}else{f=this.se(t,s,xr);const e=this.tt.options.services[i.Mt].material;l=this.oe(t.material,n,o,e||Tr)}l&&!l.isReady()?l.ae=i.id:l||(l=this.Rt);const h={refCount:1,geometry:f,material:l};return f.properties.url=c,this.ht[c]=h,h}ie(t,e,r,n){const{geometry:i,material:s}=this.It.createMesh(t,e,r,n);return{geometry:i,material:s}}se(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=cr(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,pickingIdAttribute:n._BATCHID,primitive:void 0===t.mode?"triangles":ar(t.mode)});return o.generateBuffers(this.nt,{excludeElementsInVAO:e}),o}ee(t,e,n,i){const s=r.mat4.identity(t),o=this.getMap();br.x=n[0],br.y=n[1];const a=this._prjToPoint(br),c=this.ce(),l=1/(o.getGLZoom?o.getResolution(o.getGLZoom()):o.getGLRes());let f;br.x=e[0],br.y=e[1],f=o.altitudeToPoint?this.St:o.distanceToPointAtRes(100,100,o.getGLRes(),br).y/100;let u=this.tt.options.offset;m(u)&&(u=u(br));const h=this.tt.options.services[i].heightOffset||0;return r.vec3.set(Sr,a.x-u[0],a.y-u[1],f*n[2]+f*h),r.mat4.translate(s,s,Sr),r.vec3.set(c,l,l,f),r.mat4.scale(s,s,c),s}jt(t,e){const n=r.mat4.identity(t),i=this.getMap(),s=this.ce();br.x=e[0],br.y=e[1];const o=i.distanceToPointAtRes(100,100,i.getGLRes(),br);let a;return a=i.altitudeToPoint?this.St:o.y/100,r.vec3.set(s,o.x/100*1.01,o.y/100*1.01,a),r.mat4.scale(n,n,s),n}bt(){const t={x:0,y:0,width:()=>this.et?this.et.width:1,height:()=>this.et?this.et.height:1};this.kt=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.Pt=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.Nt();this.Ut=new r.reshader.PhongShader({extraCommandProps:i}),this.Bt=new r.reshader.pbr.StandardShader({extraCommandProps:i});const s=this.tt;ur(s.getRenderer().canvas,this.nt,s.getMap()),this.picking=new r.reshader.FBORayPicking(this.it,{vert:this.Bt.vert,extraCommandProps:i,uniforms:this.Bt.uniforms,defines:{"PICKING_MODE":1,"ENABLE_PICKING":1,"HAS_PICKING_ID":1}},this.pickingFBO)}Nt(){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||gr,cull:{enable:!0,face:(t,e)=>e.cullFace||"back"},stencil:{enable:(t,e)=>!0===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}}}Ht(t){return{projViewMatrix:this.getMap().projViewMatrix,color:t&&t.color||[0,1,0]}}Lt(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)}}Ot(){const t=this.getMap(),e=this.tt.getRenderer().canvas,{iblTexes:r,dfgLUT:n}=_r(e),i=dr(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}oe(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.O(t)),o.baseColorFactor=t&&t.image.color||s.baseColorFactor||[1,1,1,1],r&&(o.baseColorTexture=r)}else{if(s.normalTexture){const t=this.O(e.textures[s.normalTexture.index]),r=s.normalTexture.scale||1;o.normalTexture=t,o.normalMapFactor=r}if(s.occlusionTexture){const t=this.O(e.textures[s.occlusionTexture.index]),r=s.occlusionTexture.strength||1;o.occlusionTexture=t,o.occlusionFactor=r}if(s.emissiveTexture){const t=this.O(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.O(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.O(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.yt),a}O(t){const e={type:t.type?sr(t.type):"uint8",format:t.format?or(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=rr(i.magFilter)),i.minFilter&&(e.min=nr(i.minFilter)),i.wrapS&&(e.wrapS=ir(i.wrapS)),i.wrapT&&(e.wrapT=ir(i.wrapT))),new r.reshader.Texture2D(e,this.At)}le(t){const e=t.image,r=window.URL||window.webkitURL,n=new Blob([e.array],{type:e.mimeType});return r.createObjectURL(n)}gt({target:t}){const e=t.ae,r=this.st[e];if(r.count--,!r.count){const t=r.meshes;this.ct[e]=t,delete this.st[e];const n=t.te;delete t.te,n(null,{mesh:r.meshes,id:e})}}ce(){return mr}Yt(t){return this.tt.Yt(t)}Kt(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(),Ir)}qt(t){return"Y"===t?lr:"X"===t?fr:Ar}pick(t,e,r=3){const n=this.tt;if(!n||!n.options.picking)return[];if(!this.pickingFBO||!this.picking)return[];const i=this.getMap(),s=this.Ot(),o=this.picking;o.render(this._t.getMeshes(),s,!0);let a={};o.getRenderedMeshes().length&&(a=o.pick(t,e,r,s,{viewMatrix:i.viewMatrix,projMatrix:i.projMatrix,returnPoint:n.options.pickingPoint}));const{meshId:c,pickingId:l,point:f}=a,u=(0===c||c)&&o.getMeshAt(c);if(!u||!u.geometry)return[];const h=u.properties;f&&f.length&&(f[0]=Math.round(1e5*f[0])/1e5,f[1]=Math.round(1e5*f[1])/1e5,f[2]=Math.round(1e5*f[2])/1e5);const _={batchId:l};if(h&&h.batchTable){const{batchTable:t,batchTableBin:e,count:r}=h,n=l;for(const i in t)void 0!==t[i].byteOffset?_[i]=be(t[i],e,r,n):_[i]=t[i][n]}return[{data:_,point:f}]}}
|
|
19
19
|
/*!
|
|
20
20
|
* @maptalks/gl v0.68.1
|
|
21
21
|
* LICENSE : UNLICENSED
|
|
22
22
|
* (c) 2016-2022 maptalks.com
|
|
23
|
-
*/const Cr=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")},vr=Cr(),Ur=vr.gl_trans__coders=vr.gl_trans__coders||{};function Br(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Ur.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=vr.gl_trans__coders=vr.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Cr.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},Ur.registerTranscoder=function(t,e){Ur[t]=e},Ur.getTranscoder=function(t){return Ur[t]};const Lr=[];class Pr{constructor(t,e,r,n){this.fe=t,this.Mt=e,this.ue=n,this.he=r.version,t.indexOf("i3s:tileset:")<0?(this.he<=1.6?this._e="root":this._e=0,r.version=this.he):(this._e=t.substring("i3s:tileset:".length),this.he>1.6&&(this._e=parseInt(this._e))),this.fe=t,this.de=r}load(){const t=this.de,e=t.layerScene.baseUrl;if(this.he<=1.6)return t[this._e]&&t[this._e].lodSelection?(this.Ee=t[this._e],this.Te()):new Promise((r=>{let n=e+"/nodes/"+this._e;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.ue(this.Mt,n,(()=>{this.Ee=t[this._e],r(this.Te())}))}));if(this.he>=1.7){if(t[this._e])return this.Ee=t[this._e],this.Te();const r=Math.floor(this._e/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.ue(this.Mt,i,(()=>{this.Ee=t[this._e],n(this.Te())}))}))}return null}getTileset(){return this.me}getChildrenURL(){return this.Ae}Te(){const t=this.de,e=t.layerScene.baseUrl,r=this.Ee.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.he<=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.ue(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.ue(this.Mt,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.pe())):this.pe()}pe(){return Promise.resolve(this.ye())}ge(t){Br(this.de,t)}ye(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Re(this.Ee,!0)}}Re(t){const e=this.he,r=this.de,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Dr([],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=Dr([],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(Lr,e,r,n);const o=q(Lr);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.de;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Re(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.Ee}}function Dr(t,e,r,n){return ee(t,p(e),p(r),n)}const Fr=!!Ur.ktx2,Gr=r.mat4.identity([]),kr=(()=>{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 Hr(t){return t.indexOf("i3s:mesh")>=0}const Vr="i3s:mesh:".length;function zr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Vr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const u=Gr;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=Ur.draco&&f?o[1]:o[0],d=Ur.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};if(i&&kr&&f&&!Ur.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 Xr(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 Xr(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=Yr(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])&&Xr(t[o],e,r,n,i,s)}function Yr(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&&Fr)return t[r]}return null}const Zr=[];class Kr extends i.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Kt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.be={},this.Ie=[],this.ue=this.Ne.bind(this)}getAnalysisMeshes(){if(!this.painter)return Zr;const t=this.painter.getPaintedMeshes();if(!t)return Zr;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&M(e,r),n.length&&M(e,n),i.length&&M(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Ie.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.Se(),this.we();const{selectedTiles:o,leaves:a,requests:c}=this.Oe(n,i);c.length&&this.loadTiles(c),this.xe(o,a,e),this.Me(),c.length||this.completeRender()}Oe(t,e){let r=[];this.Ce();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.Ue(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.Be(i))o=!0;else{this.Le(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Pe(t)),r.length>1&&(r.sort(jr),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}Pe(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.De===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.De=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}Be(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}Le(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Fe+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.Ge(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Fe<=r&&n.push(i[s])}}return e}xe(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(O(e)){const r=x(e);return void this.ke(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.Mt,n=this.He[r];return new Pr(e,r,n,this.ue).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Hr(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.be[e],r?this.ke(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.be[e],this.onTileError(r,t)})),this.be[e]=s}else this.ke(e,null,t)}ke(t,e,n){let i=this.l;i||(i=r.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.l=i);const s=this.layer.options.services[n.Mt];s.isSuperMapiServer&&(t=function(t,e){const r=t.substring(e.length).split("/"),n=[];for(let t=0;t<r.length;t++)n.push(encodeURIComponent(r[t]));return e+n.join("/")}(t,n.baseUrl));const o={url:t=this.layer.getTileUrl(t,n.baseUrl,s),arraybuffer:e,rootIdx:n.Mt,upAxis:n.$t,transform:n.matrix,supportedFormats:i};if(Hr(t)){const e=this.He[n.Mt];if(o.i3sInfo=zr(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},n)}this.workerConn.loadTile(this.layer.getId(),o,((e,r)=>{if(e)return void this.onTileError(e,n);const{magic:i}=r;"b3dm"===i||"pnts"===i||"i3dm"===i||"cmpt"===i?this.Ie.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}we(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.Ie.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.Ie.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})),r++}}Ve(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.ze(n);e.memorySize=r,this.onTileLoad(t,e)}}ze(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.ze(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.Xe(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.Ye(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,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Ze(t,e){const r={loadTime:i.Util.now(),current:!0,error:e,node:t};this.tileCache.add(t.id,r)}Xe(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.be[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.be[e]}Ce(){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},n=this.canvas.gl&&this.canvas.gl.wrap;n?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.Ke(this.canvas,e)),this.regl=this.regl||r.createREGL({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),n&&(this.canvas.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height)),this.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height),this.painter=new Mr(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.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),(t=>{if(t)throw t})),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.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.je||(this.je=Date.now());const e=Date.now();if(t||!(e-this.je<this.layer.options.retireInterval)){this.je=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}Ke(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}Ue(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)}Se(){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.He[s];if(e){t.nodes?Br(e,t.nodes):(e[t.id]=t,Br(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)}Ne(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()}Ye(t,e,r){this.He||(this.He=[]);const n=e.Mt;this.He[n]||(this.He[n]={});const i=this.He[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,e.endsWith(".json")){const t=n.lastIndexOf("/");e=t<0?"./":n.substring(0,t)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new Pr(n,e,i,s).load()}(t,n,0,r,i,this.ue).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}}function jr(t,e){return t.Ft-e.Ft}function Wr(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function qr(t,e,r){return Math.sqrt(function(t,e,r){var n=V($r,r,t),i=Wr(Jr,e,0),s=Wr(Qr,e,1),o=Wr(tn,e,2),a=q(i),c=q(s),l=q(o);Y(i,i),Y(s,s),Y(o,o);var f=en;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 $r=[],Jr=[],Qr=[],tn=[],en=[];const rn=2*Math.PI;class nn{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+=rn,r<0&&(r+=rn)),(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 sn=[0,0,1];function on(t,e){return ee(e,t[0],t[1],t[2])}class an{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 cn=[],ln=[],fn=[],un=[],hn=[],_n=[],dn=[],En=[],Tn=[],mn=[],An=new an([1,0,0],0),pn=[];class yn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new nn(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var n,i,s,o=0;if(!nn.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(pn,t,a),d=r.vec3.dot(_,l),E=r.vec3.dot(_,f),T=r.vec3.subtract(pn,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;on(nn.southwest(t,ln),e.southwestCornerCartesian),on(nn.northeast(t,ln),e.northeastCornerCartesian),cn[0]=t.west,cn[1]=.5*(t.south+t.north),cn[2]=0;var n=on(cn,fn),i=r.vec3.cross(hn,n,sn);r.vec3.normalize(e.westNormal,i),cn[0]=t.east;var s=on(cn,En),o=r.vec3.cross(hn,sn,s);r.vec3.normalize(e.eastNormal,o);var a,c=r.vec3.subtract(hn,n,s),l=r.vec3.normalize(un,c),f=t.south;if(f>0){cn[0]=.5*(t.west+t.east),cn[1]=f;var u=on(cn,Tn);r.vec3.copy(mn,l);var h=an.fromPointNormal(e.southwestCornerCartesian,e.westNormal,An);gn(Tn,mn,h,e.southwestCornerCartesian),a=he(u,_n)}else a=_e(nn.southeast(t,ln),_n);var _=r.vec3.cross(dn,a,c);r.vec3.normalize(e.southNormal,_);var d,E=t.north;if(E<0){cn[0]=.5*(t.west+t.east),cn[1]=E;var T=on(cn,Tn);r.vec3.scale(mn,l,-1);var m=an.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,An);gn(Tn,mn,m,e.northeastCornerCartesian),d=he(T,_n)}else d=_e(nn.northwest(t,ln),_n);var A=r.vec3.cross(dn,c,d);r.vec3.normalize(e.northNormal,A)}}function gn(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 Rn=new i.Extent(0,0,0,0),bn=new i.Extent(0,0,0,0),In=[],Nn=[],Sn=[],wn=[],On=new i.Point(0,0),xn=[],Mn=new i.Coordinate(0,0),Cn=r.mat4.identity([]);class vn extends i.Layer{constructor(t,e){super(t,e),this.qe(),this.be={},this.$e=[]}qe(){let t=this.options.services.map((t=>t.url));this.Je=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,Fe:0}}(t,e))),this.fire("rootready",{roots:this.Je.slice(0)})}getTileUrl(t){return t}getExtent(t){if(!t&&0!==t){const t=new i.Extent;for(let e=0;e<this.Je.length;e++)if(this.Je[e].boundingVolume){const r=this.boundingVolumeToExtent(this.Je[e]);t._combine(r)}return t}return this.Je[t]&&this.Je[t].boundingVolume?this.boundingVolumeToExtent(this.Je[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.Qe?Cn: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.Je}getTiles(){const t=this.getRenderer();if(!t.ready)return this.tr(),{tiles:wn};const e=this.getMap(),n=e.cameraPosition;let i,s;if(e.getGLZoom)s=e.pointToDistance(n[2],0,e.getGLZoom()),Mn.set(n[0],n[1]),i=e.pointToCoord(Mn,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(n[2],0,t),Mn.set(n[0],n[1]),i=e.pointAtResToCoord(Mn,t)}this.er=this.er||[],r.vec3.set(this.er,p(i.x),p(i.y),s),this.rr=ee(this.rr||[],this.er[0],this.er[1],this.er[2]),this.nr=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.Je.length;e++){let r=1/0;const n=[this.Je[e]],i=this.ir(e);for(;n.length>0;){const e=n.pop();for(e.id||this.sr(e);c.level>=e.Fe;)c=c.parent;const s=this.ar(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.cr(l,t);if(!1===this.options.services[e.Mt].alwaysShow)continue;if(!(0===s&&e.Fe<=r))continue;e.content&&(r=e.Fe)}e.Ft<1/0&&this.lr(e);const a=this.Ge(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.cr(l,a),u){h&&"add"===e.refine&&this.cr(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&&404!==e.error.status)continue;i=!0}else{i=!0,f[s].parent=e,f[s].$t=e.$t,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(O(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.cr(l,a)}}}return{root:a,tiles:l}}cr(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 Un(r,e);if(r.box)return 0===Bn(r,e)}return!1}(this.er,this.rr,r)||t.push(e)}Ge(t,e){return{id:t.id,node:t,children:[],level:t.Fe,parent:e,content:t.content&&t.content.url}}sr(t){t.id=i.Util.GUID(),t.matrix=t.transform||r.mat4.identity([]),t.ur=this.hr(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.Fe&&(t.Fe=t.parent.Fe+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._r(t)}_r(t){const e=t.boundingVolume;if(!e||e.Qe)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,Cn)&&!s)return;const{region:o,box:a,sphere:c}=e;if(o){const t=this.dr([y(o[0]),y(o[1])]);o[0]=p(t.x),o[1]=p(t.y);const e=this.dr([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(In,e,t.matrix),s=ae(Nn,i),o=this.dr([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.Qe=!0}hr(t){return void 0===t.geometricError||!t.boundingVolume}lr(t){let e=t.parent;for(;e&&e.ur&&!(e.Ft<=t.Ft);)e.Ft=t.Ft,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=this.options.services[e.Mt],s=(t.asset&&t.asset.gltfUpAxis||e&&e.$t||i.upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const o=n.indexOf("realspace/")>-1;0===e.Fe&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.$t=s,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?a||(e.matrix=r.mat4.multiply([],e.parent.matrix,i)):e.matrix=i),this._r(e),e.Er=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.ur=this.hr(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),a||!s||O(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.tr(),this.fire("loadtileset",{tileset:t,index:e.Mt,url:n})}ar(t,e,r){if(t.Ft=1/0,0===t.Fe||t.ur)return 1;if(!this.Tr(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.mr(t);return 0===i&&t.parent&&(i=.5*(t.parent.Ar||0)),i>=n?1:0}Yt(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)}Tr(t,e,n){const s=t.id;let o=this.$e[s];const{boundingVolume:c}=t,l=c.sphere,_=c.region,E=c.box;if(!o){let e,n,a;if(_){e=Rn.set(y(_[0]),y(_[1]),y(_[2]),y(_[3]));const t=e.getCenter(),r=this.pr(t);e=e.convertTo((t=>this.Yt(t,On)),bn),a=_[4],n=_[5],o=this.$e[s]=[[e.xmin,e.ymin,a*r[2]],[e.xmax,e.ymax,n*r[2]]],o.center=t}else if(l){const t=ae(In,l),e=new i.Coordinate(t),r=this.Yt(e,On).toArray(),n=this.pr(e);r.push(t[2]*n[2]),o=this.$e[s]=[r,l[3]*n[2]],o.center=e}else if(E){const e=ae(In,E),n=new i.Coordinate(e),a=this.Yt(n,On).toArray(),c=this.pr(n);a.push(e[2]*c[2]);const l=E.slice(3);r.mat4.exactEquals(t.matrix,Cn)||r.mat3.multiply(l,r.mat3.fromMat4(xn,t.matrix),l);for(let t=0;t<l.length;t++)l[t]*=c[t%3],E[3+t]=l[t];o=this.$e[s]=[...a,...l],o.center=n}}if(e){if(_)Rn.xmin=o[0][0],Rn.ymin=o[0][1],Rn.xmax=o[1][0],Rn.ymax=o[1][1];else if(l){const t=o[2];Rn.xmin=o[0][0]-t,Rn.ymin=o[0][1]-t,Rn.xmax=o[0][0]+t,Rn.ymax=o[0][1]+t}else if(E){const t=o[1],e=o[2];Rn.xmin=o[0][0]-t,Rn.ymin=o[0][1]-e,Rn.xmax=o[0][0]+t,Rn.ymax=o[0][1]+e}if(!e.intersects(Rn))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)}pr(t){const e=this.getMap(),n=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let i;return i=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:n.y/100,r.vec3.set(Sn,n.x/100*1.01,n.y/100*1.01,i),Sn}dr(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}ir(t){const e=this.options.services[t].maxExtent;if(!e)return null;const r=this.Je[t];return r.maxExtent||(r.maxExtent=new i.Extent(e).convertTo((t=>this.Yt(t)))),r.maxExtent}mr(t){const e=this.nr,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.yr||(t.yr=new yn(t.boundingVolume.region));return t.yr.distanceToCamera(e,r)}(t,this.rr,this.er):t.boundingVolume.sphere?i=Un(t.boundingVolume,this.rr):t.boundingVolume.box&&(i=Bn(t.boundingVolume,this.rr));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Ft=i,t.Ar=o,o}tr(){const t=this.getRenderer();t&&t.setToRedraw()}re(t){return this.$e[t]}identifyAtPoint(t,e={}){const r=this.getMap(),n=this.getRenderer();if(!r||!n)return[];const i=r.getDevicePixelRatio();return n.pick(t.x*i,t.y*i,e)}}function Un(t,e){const n=t.sphere,i=r.vec3.dist(n,e),s=t.sphere[3];return i<s?0:i-s}function Bn(t,e){const n=t.box;return qr(r.vec3.set(In,n[0],n[1],n[2]),r.mat3.set(xn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}vn.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]}),vn.registerRenderer("gl",Kr),vn.registerJSONType("Geo3DTilesLayer");class Ln{constructor(t,e,r){this.o=t,this.gr=e||Pt,this.l=r,this.Rr={"image/crn":Ur.crn&&Ur.crn(),"image/ktx2":Ur.ktx2&&Ur.ktx2(),"image/cttf":Ur.ktx2&&Ur.ktx2(),"draco":Ur.draco&&Ur.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.br(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Ir(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.gr(a,o.glb,{transferable:!0,requestImage:this.o,decoders:this.Rr,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}}))}Ir(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}}}Nr(){return null}}class Pn{constructor(t,e,r,n){this.o=t,this.gr=e||Pt,this.l=r,this.Rr={"image/crn":Ur.crn&&Ur.crn(),"image/ktx2":Ur.ktx2&&Ur.ktx2(),"image/cttf":Ur.ktx2&&Ur.ktx2(),"draco":Ur.draco&&Ur.draco()},this.Sr=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.br(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n,i){return this.wr(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Or(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})}))}wr(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.o,decoders:this.Rr,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.Mr(n,{buffer:t.data,byteOffset:0},o))):At.getJSON(n,{}).then((t=>this.Mr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Mr(t,n,o)}}Mr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.gr(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}}))}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}=Me(i,32+e,o),u={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;u.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;u.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Cr(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.vr(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.vr(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}}vr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Dn(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}Cr(t,e,r){return xe(new Float32Array(t.length),t,e,r)}Nr(){return null}}function Dn(t,e,r,n){if(t[0]=Fn(e,n),t[1]=Fn(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]))*Gn(e),t[1]=(1-Math.abs(e))*Gn(t[1])}return Y(t,t)}function Fn(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 Gn(t){return t<0?-1:1}class kn{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.br(t,e,r,n)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n){return this.Ur(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}))}Ur(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Me(i,e+28,o),u=a.QUANTIZED_VOLUME_OFFSET,h=a.QUANTIZED_VOLUME_SCALE,_=a.POINTS_LENGTH;let d,E={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){E=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,E.byteOffset+c.offset,E.byteLength);const e={attributes:E.properties,useUniqueIDs:!1};return this.Br||(this.Br=Ur.draco()),this.Br(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.Lr(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:Oe(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=Hn(_);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.Lr(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=Hn(_);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})}Lr(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.Cr(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}Cr(t,e,r){return xe(new Float32Array(t.length),t,e,r)}Nr(){return null}}function Hn(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:Oe(e),array:r}}class Vn{constructor(t,e){this.o=t,this.gr=e||Pt}load(t,e,r=0,n=0,i){return e?this.br(t,e,r,n,i):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.br(t,i,r,n)}))}br(t,e,r,n,i){n||(n=e.byteLength);const s=this.Pr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Ln(this.o,this.gr);else if("i3dm"===s[r].magic)n=new Pn(this.o,this.gr);else if("pnts"===s[r].magic)n=new kn;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Vn(this.o,this.gr)}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})))}Pr(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=Ln,t.CMPTLoader=Vn,t.Geo3DTilesLayer=vn,t.Geo3DTilesUtil=C,t.Geo3DTransform=de,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.18.0")}));
|
|
23
|
+
*/const Cr=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")},vr=Cr(),Ur=vr.gl_trans__coders=vr.gl_trans__coders||{};function Br(t,e){if(e)for(let r=0;r<e.length;r++){t[e[r].id||e[r].index]=e[r]}}Ur.inject=function(t){const e=t.toString(),r=e.indexOf("{")+1,n=e.substring(0,r),i=vr.gl_trans__coders=vr.gl_trans__coders||{};let s=`${n}\n const _____getGlobal = ${Cr.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},Ur.registerTranscoder=function(t,e){Ur[t]=e},Ur.getTranscoder=function(t){return Ur[t]};const Lr=[];class Pr{constructor(t,e,r,n){this.fe=t,this.Mt=e,this.ue=n,this.he=r.version,t.indexOf("i3s:tileset:")<0?(this.he<=1.6?this._e="root":this._e=0,r.version=this.he):(this._e=t.substring("i3s:tileset:".length),this.he>1.6&&(this._e=parseInt(this._e))),this.fe=t,this.de=r}load(){const t=this.de,e=t.layerScene.baseUrl;if(this.he<=1.6)return t[this._e]&&t[this._e].lodSelection?(this.Ee=t[this._e],this.Te()):new Promise((r=>{let n=e+"/nodes/"+this._e;t.layerScene.eslpk&&(n+="/3dNodeIndexDocument.json"),this.ue(this.Mt,n,(()=>{this.Ee=t[this._e],r(this.Te())}))}));if(this.he>=1.7){if(t[this._e])return this.Ee=t[this._e],this.Te();const r=Math.floor(this._e/t.nodesPerPage);return new Promise((n=>{let i=e+"/nodepages/"+r;t.layerScene.eslpk&&(i+=".json"),this.ue(this.Mt,i,(()=>{this.Ee=t[this._e],n(this.Te())}))}))}return null}getTileset(){return this.me}getChildrenURL(){return this.Ae}Te(){const t=this.de,e=t.layerScene.baseUrl,r=this.Ee.children,n=[],i={};if(r)for(let s=0;s<r.length;s++)if(this.he<=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.ue(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.ue(this.Mt,n,(()=>{r()}))})),n.push(i[a]))}return n.length?Promise.all(n).then((()=>this.pe())):this.pe()}pe(){return Promise.resolve(this.ye())}ge(t){Br(this.de,t)}ye(){return{asset:{i3s:!0,version:"1.0",gltfUpAxis:"Z"},geometricError:Number.MAX_VALUE,root:this.Re(this.Ee,!0)}}Re(t){const e=this.he,r=this.de,n=t;var i,s=n.obb,o=n.mbs,a={};if(o)i=Dr([],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=Dr([],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(Lr,e,r,n);const o=q(Lr);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.de;for(let r=0;r<_.length;r++){const n=e<=1.6?_[r].id:_[r];if(!t[n]){d=null;break}d.push(this.Re(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.Ee}}function Dr(t,e,r,n){return ee(t,p(e),p(r),n)}const Fr=!!Ur.ktx2,Gr=r.mat4.identity([]),kr=(()=>{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 Hr(t){return t.indexOf("i3s:mesh")>=0}const Vr="i3s:mesh:".length;function zr(t,e,r,n,i){const s=e.layerScene.eslpk,o=function(t,e){const r=e.substring(Vr);return t>=1.7?parseInt(r):r}(e.version,t),a=e[o],c=e.layerScene.baseUrl,l=[];let f=!1;const u=Gr;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=Ur.draco&&f?o[1]:o[0],d=Ur.draco&&f?1:0;let E=c+`/nodes/${h.resource}/geometries/`+d;s&&(E+=".bin");const T={geometry:{url:E,info:u}};if(i&&kr&&f&&!Ur.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 Xr(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 Xr(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=Yr(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])&&Xr(t[o],e,r,n,i,s)}function Yr(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&&Fr)return t[r]}return null}const Zr=[];class Kr extends i.renderer.CanvasRenderer{constructor(t){super(t),this.prepareWorker(),this.tilesLoading={},this.tileCache=new Kt(1024*t.options.maxGPUMemory*1024,this.deleteTile.bind(this)),this.be={},this.Ie=[],this.ue=this.Ne.bind(this)}getAnalysisMeshes(){if(!this.painter)return Zr;const t=this.painter.getPaintedMeshes();if(!t)return Zr;const e=[],{b3dmMeshes:r,pntsMeshes:n,i3dmMeshes:i}=t;return r.length&&M(e,r),n.length&&M(e,n),i.length&&M(e,i),e}needToRedraw(){return!!this.getMap().isInteracting()||(!!this.Ie.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.Se(),this.we();const{selectedTiles:o,leaves:a,requests:c}=this.Oe(n,i);c.length&&this.loadTiles(c),this.xe(o,a,e),this.Me(),c.length||this.completeRender()}Oe(t,e){let r=[];this.Ce();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.Ue(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.Be(i))o=!0;else{this.Le(i).length&&(o=!0)}}let c=[],l={};if(o&&({selectedTiles:c,leaves:l}=this.Pe(t)),r.length>1&&(r.sort(jr),i)){const t=i-n;r=t>0?r.slice(0,t):[]}return{loading:a,requests:r,selectedTiles:c,leaves:l}}Pe(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.De===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.De=i.length}for(let t=0;t<o.length;t++)i.push(o[t])}return{selectedTiles:e,leaves:r}}Be(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}Le(t){const e=[];if(!t.node.children||!t.node.children.length)return e;const r=t.Fe+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.Ge(i[s],t);r.selected=!0,r.data=this.tileCache.get(o),t.children.push(r),e.push(r)}else i[s].Fe<=r&&n.push(i[s])}}return e}xe(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(O(e)){const r=x(e);return void this.ke(e,r,t)}if(function(t){return t.indexOf("i3s:tileset")>=0}(e)){const r=t.Mt,n=this.He[r];return new Pr(e,r,n,this.ue).load().then((r=>{this.onTilesetLoad(r,t,e)}))}t&&-1===e.indexOf("http://")&&-1===e.indexOf("https://")&&!Hr(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.be[e],r?this.ke(e,r.data,t):this.onTileError(null,t)})).catch((r=>{delete this.be[e],this.onTileError(r,t)})),this.be[e]=s}else this.ke(e,null,t)}ke(t,e,n){let i=this.l;i||(i=r.reshader.Util.getSupportedFormats(this.gl.gl||this.gl),this.l=i);const s=this.layer.options.services[n.Mt];s.isSuperMapiServer&&(t=function(t,e){const r=t.substring(e.length).split("/"),n=[];for(let t=0;t<r.length;t++)n.push(encodeURIComponent(r[t]));return e+n.join("/")}(t,n.baseUrl));const o={url:t=this.layer.getTileUrl(t,n.baseUrl,s),arraybuffer:e,rootIdx:n.Mt,upAxis:n.$t,transform:n.matrix,supportedFormats:i};if(Hr(t)){const e=this.He[n.Mt];if(o.i3sInfo=zr(t,e,this.regl,this.layer.options.enableI3SCompressedGeometry,this.layer.options.forceI3SCompressedGeometry),!o.i3sInfo)return void this.onTileError({status:404},n)}this.workerConn.loadTile(this.layer.getId(),o,((e,r)=>{if(e)return void this.onTileError(e,n);const{magic:i}=r;"b3dm"===i||"pnts"===i||"i3dm"===i||"cmpt"===i?this.Ie.push({data:r,tile:n}):this.onTilesetLoad(r,n,t)}))}we(){const t=this.getMap(),e=this.layer.options.meshLimitPerFrame;let r=0;for(;this.Ie.length&&(r<e||!t.isInteracting());){const{data:t,tile:e}=this.Ie.shift(),{magic:n}=t;"b3dm"===n?this.painter.createB3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"pnts"===n?this.painter.createPntsMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"i3dm"===n?this.painter.createI3DMMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})):"cmpt"===n&&this.painter.createCMPTMesh(t,e.id,e,((r,{mesh:n})=>{this.Ve(t,e,r,n)})),r++}}Ve(t,e,r,n){if(r)this.onTileError(r,e);else{const r=this.ze(n);e.memorySize=r,this.onTileLoad(t,e)}}ze(t){let e=0;if(Array.isArray(t))for(let r=0;r<t.length;r++)t[r]&&(e+=this.ze(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.Xe(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.Ye(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,t),this.setToRedraw(),this.layer.fire("tileerror",{node:e,error:t})}getCachedTile(t){return this.tileCache.get(t)}Ze(t,e){const r={loadTime:i.Util.now(),current:!0,error:e,node:t};this.tileCache.add(t.id,r)}Xe(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.be[e];t&&t.abort()}else this.workerConn.abortTileLoading(this.layer.getId(),e);delete this.be[e]}Ce(){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},n=this.canvas.gl&&this.canvas.gl.wrap;n?(this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl):(this.glOptions=e,this.gl=this.Ke(this.canvas,e)),this.regl=this.regl||r.createREGL({gl:this.gl,attributes:e,extensions:["OES_element_index_uint"],optionalExtensions:t.options.optionalExtensions||[]}),n&&(this.canvas.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height)),this.pickingFBO=this.canvas.pickingFBO||this.regl.framebuffer(this.canvas.width,this.canvas.height),this.painter=new Mr(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.pickingFBO&&(this.canvas.pickingFBO||this.pickingFBO.destroy(),delete this.pickingFBO),this.workerConn&&(this.workerConn.removeLayer(this.layer.getId(),(t=>{if(t)throw t})),this.workerConn.remove(),delete this.workerConn),this.clear(),delete this.tileCache,super.onRemove()}clear(){this.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.je||(this.je=Date.now());const e=Date.now();if(t||!(e-this.je<this.layer.options.retireInterval)){this.je=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}Ke(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}Ue(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)}Se(){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.He[s];if(e){t.nodes?Br(e,t.nodes):(e[t.id]=t,Br(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)}Ne(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()}Ye(t,e,r){this.He||(this.He=[]);const n=e.Mt;this.He[n]||(this.He[n]={});const i=this.He[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,e.endsWith(".json")){const t=n.lastIndexOf("/");e=t<0?"./":n.substring(0,t)}i.layerScene.baseUrl=function(t){return t.split("?")[0]}(e)}return new Pr(n,e,i,s).load()}(t,n,0,r,i,this.ue).then((t=>{this.onTilesetLoad(t,e,r)}))}pick(t,e,r){return this.painter?this.painter.pick(t,e,r&&r.tolerance):[]}}function jr(t,e){return t.Ft-e.Ft}function Wr(t,e,r){return t[0]=e[r],t[1]=e[r+3],t[2]=e[r+6],t}function qr(t,e,r){return Math.sqrt(function(t,e,r){var n=V($r,r,t),i=Wr(Jr,e,0),s=Wr(Qr,e,1),o=Wr(tn,e,2),a=q(i),c=q(s),l=q(o);Y(i,i),Y(s,s),Y(o,o);var f=en;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 $r=[],Jr=[],Qr=[],tn=[],en=[];const rn=2*Math.PI;class nn{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+=rn,r<0&&(r+=rn)),(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 sn=[0,0,1];function on(t,e){return ee(e,t[0],t[1],t[2])}class an{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 cn=[],ln=[],fn=[],un=[],hn=[],_n=[],dn=[],En=[],Tn=[],mn=[],An=new an([1,0,0],0),pn=[];class yn{constructor(t){this.southwestCornerCartesian=[],this.northeastCornerCartesian=[],this.westNormal=[],this.eastNormal=[],this.southNormal=[],this.northNormal=[],this.rectangle=new nn(...t),this.minimumHeight=t[4],this.maximumHeight=t[5],this.computeBox(this.rectangle)}distanceToCamera(t,e){var n,i,s,o=0;if(!nn.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(pn,t,a),d=r.vec3.dot(_,l),E=r.vec3.dot(_,f),T=r.vec3.subtract(pn,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;on(nn.southwest(t,ln),e.southwestCornerCartesian),on(nn.northeast(t,ln),e.northeastCornerCartesian),cn[0]=t.west,cn[1]=.5*(t.south+t.north),cn[2]=0;var n=on(cn,fn),i=r.vec3.cross(hn,n,sn);r.vec3.normalize(e.westNormal,i),cn[0]=t.east;var s=on(cn,En),o=r.vec3.cross(hn,sn,s);r.vec3.normalize(e.eastNormal,o);var a,c=r.vec3.subtract(hn,n,s),l=r.vec3.normalize(un,c),f=t.south;if(f>0){cn[0]=.5*(t.west+t.east),cn[1]=f;var u=on(cn,Tn);r.vec3.copy(mn,l);var h=an.fromPointNormal(e.southwestCornerCartesian,e.westNormal,An);gn(Tn,mn,h,e.southwestCornerCartesian),a=he(u,_n)}else a=_e(nn.southeast(t,ln),_n);var _=r.vec3.cross(dn,a,c);r.vec3.normalize(e.southNormal,_);var d,E=t.north;if(E<0){cn[0]=.5*(t.west+t.east),cn[1]=E;var T=on(cn,Tn);r.vec3.scale(mn,l,-1);var m=an.fromPointNormal(e.northeastCornerCartesian,e.eastNormal,An);gn(Tn,mn,m,e.northeastCornerCartesian),d=he(T,_n)}else d=_e(nn.northwest(t,ln),_n);var A=r.vec3.cross(dn,c,d);r.vec3.normalize(e.northNormal,A)}}function gn(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 Rn=new i.Extent(0,0,0,0),bn=new i.Extent(0,0,0,0),In=[],Nn=[],Sn=[],wn=[],On=new i.Point(0,0),xn=[],Mn=new i.Coordinate(0,0),Cn=r.mat4.identity([]);class vn extends i.Layer{constructor(t,e){super(t,e),this.qe(),this.be={},this.$e=[]}qe(){let t=this.options.services.map((t=>t.url));this.Je=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,Fe:0}}(t,e))),this.fire("rootready",{roots:this.Je.slice(0)})}getTileUrl(t){return t}getExtent(t){if(!t&&0!==t){const t=new i.Extent;for(let e=0;e<this.Je.length;e++)if(this.Je[e].boundingVolume){const r=this.boundingVolumeToExtent(this.Je[e]);t._combine(r)}return t}return this.Je[t]&&this.Je[t].boundingVolume?this.boundingVolumeToExtent(this.Je[t]):null}boundingVolumeToExtent(t){const e=t.boundingVolume.Qe?Cn: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.Je}getTiles(){const t=this.getRenderer();if(!t.ready)return this.tr(),{tiles:wn};const e=this.getMap(),n=e.cameraPosition;let i,s;if(e.getGLZoom)s=e.pointToDistance(n[2],0,e.getGLZoom()),Mn.set(n[0],n[1]),i=e.pointToCoord(Mn,e.getGLZoom());else{const t=e.getGLRes();s=e.pointAtResToDistance(n[2],0,t),Mn.set(n[0],n[1]),i=e.pointAtResToCoord(Mn,t)}this.er=this.er||[],r.vec3.set(this.er,p(i.x),p(i.y),s),this.rr=ee(this.rr||[],this.er[0],this.er[1],this.er[2]),this.nr=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.Je.length;e++){let r=1/0;const n=[this.Je[e]],i=this.ir(e);for(;n.length>0;){const e=n.pop();for(e.id||this.sr(e);c.level>=e.Fe;)c=c.parent;const s=this.ar(e,i,o);if(s<1){let t=c;for(;t&&!t.content;)t=t.parent;0===s&&t&&t.content&&this.cr(l,t);if(!1===this.options.services[e.Mt].alwaysShow)continue;if(!(0===s&&e.Fe<=r))continue;e.content&&(r=e.Fe)}e.Ft<1/0&&this.lr(e);const a=this.Ge(e,c);c.children.push(a);const f=e.children,u=f&&f.length,h=a.content;if(!u&&h&&this.cr(l,a),u){h&&"add"===e.refine&&this.cr(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&&404!==e.error.status)continue;i=!0}else{i=!0,f[s].parent=e,f[s].$t=e.$t,f[s].baseUrl=e.baseUrl;const t=f[s].content&&(f[s].content.url||f[s].content.uri);t&&(O(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.cr(l,a)}}}return{root:a,tiles:l}}cr(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 Un(r,e);if(r.box)return 0===Bn(r,e)}return!1}(this.er,this.rr,r)||t.push(e)}Ge(t,e){return{id:t.id,node:t,children:[],level:t.Fe,parent:e,content:t.content&&t.content.url}}sr(t){t.id=i.Util.GUID(),t.matrix=t.transform||r.mat4.identity([]),t.ur=this.hr(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.Fe&&(t.Fe=t.parent.Fe+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._r(t)}_r(t){const e=t.boundingVolume;if(!e||e.Qe)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,Cn)&&!s)return;const{region:o,box:a,sphere:c}=e;if(o){const t=this.dr([y(o[0]),y(o[1])]);o[0]=p(t.x),o[1]=p(t.y);const e=this.dr([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(In,e,t.matrix),s=ae(Nn,i),o=this.dr([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.Qe=!0}hr(t){return void 0===t.geometricError||!t.boundingVolume}lr(t){let e=t.parent;for(;e&&e.ur&&!(e.Ft<=t.Ft);)e.Ft=t.Ft,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=this.options.services[e.Mt],s=(t.asset&&t.asset.gltfUpAxis||e&&e.$t||i.upAxis||"Y").toUpperCase();t.root.baseUrl=n.substring(0,n.lastIndexOf("/")+1);const o=n.indexOf("realspace/")>-1;0===e.Fe&&(t.asset&&t.asset.s3mType&&o||i.isSuperMapiServer)&&(t.root.baseUrl+="data/path/");const a=t.asset.i3s;if(t.root.$t=s,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?a||(e.matrix=r.mat4.multiply([],e.parent.matrix,i)):e.matrix=i),this._r(e),e.Er=e.content,delete e.content,t.root.content&&(e.content=t.root.content),e.ur=this.hr(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),a||!s||O(s)||-1!==s.indexOf("http://")||-1!==s.indexOf("https://")||(e.content.url=e.baseUrl+s)}this.tr(),this.fire("loadtileset",{tileset:t,index:e.Mt,url:n})}ar(t,e,r){if(t.Ft=1/0,0===t.Fe||t.ur)return 1;if(!this.Tr(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.mr(t);return 0===i&&t.parent&&(i=.5*(t.parent.Ar||0)),i>=n?1:0}Yt(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)}Tr(t,e,n){const s=t.id;let o=this.$e[s];const{boundingVolume:c}=t,l=c.sphere,_=c.region,E=c.box;if(!o){let e,n,a;if(_){e=Rn.set(y(_[0]),y(_[1]),y(_[2]),y(_[3]));const t=e.getCenter(),r=this.pr(t);e=e.convertTo((t=>this.Yt(t,On)),bn),a=_[4],n=_[5],o=this.$e[s]=[[e.xmin,e.ymin,a*r[2]],[e.xmax,e.ymax,n*r[2]]],o.center=t}else if(l){const t=ae(In,l),e=new i.Coordinate(t),r=this.Yt(e,On).toArray(),n=this.pr(e);r.push(t[2]*n[2]),o=this.$e[s]=[r,l[3]*n[2]],o.center=e}else if(E){const e=ae(In,E),n=new i.Coordinate(e),a=this.Yt(n,On).toArray(),c=this.pr(n);a.push(e[2]*c[2]);const l=E.slice(3);r.mat4.exactEquals(t.matrix,Cn)||r.mat3.multiply(l,r.mat3.fromMat4(xn,t.matrix),l);for(let t=0;t<l.length;t++)l[t]*=c[t%3],E[3+t]=l[t];o=this.$e[s]=[...a,...l],o.center=n}}if(e){if(_)Rn.xmin=o[0][0],Rn.ymin=o[0][1],Rn.xmax=o[1][0],Rn.ymax=o[1][1];else if(l){const t=o[2];Rn.xmin=o[0][0]-t,Rn.ymin=o[0][1]-t,Rn.xmax=o[0][0]+t,Rn.ymax=o[0][1]+t}else if(E){const t=o[1],e=o[2];Rn.xmin=o[0][0]-t,Rn.ymin=o[0][1]-e,Rn.xmax=o[0][0]+t,Rn.ymax=o[0][1]+e}if(!e.intersects(Rn))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)}pr(t){const e=this.getMap(),n=e.distanceToPointAtRes(100,100,e.getGLRes(),t);let i;return i=e.altitudeToPoint?e.altitudeToPoint(100,e.getGLRes())/100:n.y/100,r.vec3.set(Sn,n.x/100*1.01,n.y/100*1.01,i),Sn}dr(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}ir(t){const e=this.options.services[t].maxExtent;if(!e)return null;const r=this.Je[t];return r.maxExtent||(r.maxExtent=new i.Extent(e).convertTo((t=>this.Yt(t)))),r.maxExtent}mr(t){const e=this.nr,r=t.geometricError;if(0===r)return 0;const n=this.getMap();let i;t.boundingVolume.region?i=function(t,e,r){t.yr||(t.yr=new yn(t.boundingVolume.region));return t.yr.distanceToCamera(e,r)}(t,this.rr,this.er):t.boundingVolume.sphere?i=Un(t.boundingVolume,this.rr):t.boundingVolume.box&&(i=Bn(t.boundingVolume,this.rr));const s=Math.max(Math.abs(i),1e-7),o=r*n.height/(s*e);return t.Ft=i,t.Ar=o,o}tr(){const t=this.getRenderer();t&&t.setToRedraw()}re(t){return this.$e[t]}identifyAtPoint(t,e={}){const r=this.getMap(),n=this.getRenderer();if(!r||!n)return[];const i=r.getDevicePixelRatio();return n.pick(t.x*i,t.y*i,e)}}function Un(t,e){const n=t.sphere,i=r.vec3.dist(n,e),s=t.sphere[3];return i<s?0:i-s}function Bn(t,e){const n=t.box;return qr(r.vec3.set(In,n[0],n[1],n[2]),r.mat3.set(xn,n[3],n[4],n[5],n[6],n[7],n[8],n[9],n[10],n[11]),e)}vn.mergeOptions({"maxGPUMemory":512,"retireInterval":2e3,"loadingLimitOnInteracting":5,"loadingLimit":0,"renderer":"gl","forceRenderOnZooming":!0,"forceRenderOnRotating":!0,"forceRenderOnMoving":!0,"debug":!1,"debugOutline":[0,1,0],"meshLimitPerFrame":1,"i3sNodepageLimitPerFrame":1,"enableI3SCompressedGeometry":!0,"forceI3SCompressedGeometry":!0,"picking":!0,"pickingPoint":!0,"geometryEvents":!1,"antialias":!1,"optionalExtensions":["ANGLE_instanced_arrays","OES_element_index_uint","OES_standard_derivatives","OES_vertex_array_object","OES_texture_half_float","OES_texture_half_float_linear","OES_texture_float","OES_texture_float_linear","WEBGL_depth_texture","EXT_shader_texture_lod","WEBGL_compressed_texture_astc","WEBGL_compressed_texture_etc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_compressed_texture_s3tc_srgb"],"offset":[0,0]}),vn.registerRenderer("gl",Kr),vn.registerJSONType("Geo3DTilesLayer");class Ln{constructor(t,e,r){this.o=t,this.gr=e||Pt,this.l=r,this.Rr={"image/crn":Ur.crn&&Ur.crn(),"image/ktx2":Ur.ktx2&&Ur.ktx2(),"image/cttf":Ur.ktx2&&Ur.ktx2(),"draco":Ur.draco&&Ur.draco()}}static createEmptyB3DM(){return{featureTable:null,batchTable:null,gltf:{}}}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.br(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n,i){const s=i&&i.maxTextureSize,o=this.Ir(e,r,n,t);if(o.error)return Promise.resolve(o);const a=t.substring(0,t.lastIndexOf("/")),c=new this.gr(a,o.glb,{transferable:!0,requestImage:this.o,decoders:this.Rr,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}}))}Ir(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}}}Nr(){return null}}class Pn{constructor(t,e,r,n){this.o=t,this.gr=e||Pt,this.l=r,this.Rr={"image/crn":Ur.crn&&Ur.crn(),"image/ktx2":Ur.ktx2&&Ur.ktx2(),"image/cttf":Ur.ktx2&&Ur.ktx2(),"draco":Ur.draco&&Ur.draco()},this.Sr=n}load(t,e,r=0,n=0,i){return e?(n||(n=e.byteLength),this.br(t,e,r,n,i)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n,i){return this.wr(t,e,r,n,i).then((({gltf:i,transferables:s})=>{const o=this.Or(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})}))}wr(t,e,r,n,i){const s=i&&i.maxTextureSize,o={transferable:!0,requestImage:this.o,decoders:this.Rr,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.Mr(n,{buffer:t.data,byteOffset:0},o))):At.getJSON(n,{}).then((t=>this.Mr(n,t,o)))}{const n={buffer:e,byteOffset:c+r,byteLength:a.byteLength-c};return this.Mr(t,n,o)}}Mr(t,e,r){const n=t.substring(0,t.lastIndexOf("/")),i=new this.gr(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}}))}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}=Me(i,32+e,o),u={},h=a.INSTANCES_LENGTH;if(a.POSITION){const{byteOffset:e}=a.POSITION;u.POSITION={byteStride:0,byteOffset:0,itemSize:3,count:h,componentType:5126,array:new Float32Array(t,e+c.offset,3*h).slice()},o.push(u.POSITION.array.buffer)}else if(a.POSITION_QUANTIZED){const e=a.QUANTIZED_VOLUME_OFFSET,r=a.QUANTIZED_VOLUME_SCALE,{byteOffset:n}=a.POSITION_QUANTIZED;u.POSITION={byteStride:12,byteOffset:0,itemSize:3,count:h,componentType:5126,array:this.Cr(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.vr(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.vr(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}}vr(t){const e=t.length/2,r=new Float32Array(3*e),n=[];for(let i=0;i<e;i++)Dn(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}Cr(t,e,r){return xe(new Float32Array(t.length),t,e,r)}Nr(){return null}}function Dn(t,e,r,n){if(t[0]=Fn(e,n),t[1]=Fn(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]))*Gn(e),t[1]=(1-Math.abs(e))*Gn(t[1])}return Y(t,t)}function Fn(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 Gn(t){return t<0?-1:1}class kn{constructor(){}load(t,e,r=0,n=0){return e?(n||(n=e.byteLength),this.br(t,e,r,n)):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return n||(n=i.byteLength),this.br(t,i,r,n)}))}br(t,e,r,n){return this.Ur(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}))}Ur(t,e,r,n){const i=new DataView(t,e,r),s=i.getUint32(4,!0);if(1!==s){const t="Unsupported pnts version: "+s+", url:"+n;return console.warn(t),{error:t}}if(i.getUint32(8,!0)!==i.byteLength){const t="Length in pnts header is inconsistent with pnts's byte length, url: "+n;return console.warn(t),{error:t}}const o=[t],{featureTable:a,featureTableBin:c,batchTable:l,batchTableBin:f}=Me(i,e+28,o),u=a.QUANTIZED_VOLUME_OFFSET,h=a.QUANTIZED_VOLUME_SCALE,_=a.POINTS_LENGTH;let d,E={};if(a.extensions&&a.extensions["3DTILES_draco_point_compression"]){E=a.extensions["3DTILES_draco_point_compression"],d=new DataView(t,E.byteOffset+c.offset,E.byteLength);const e={attributes:E.properties,useUniqueIDs:!1};return this.Br||(this.Br=Ur.draco()),this.Br(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.Lr(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:Oe(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=Hn(_);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.Lr(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=Hn(_);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})}Lr(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.Cr(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}Cr(t,e,r){return xe(new Float32Array(t.length),t,e,r)}Nr(){return null}}function Hn(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:Oe(e),array:r}}class Vn{constructor(t,e){this.o=t,this.gr=e||Pt}load(t,e,r=0,n=0,i){return e?this.br(t,e,r,n,i):At.getArrayBuffer(t,{}).then((e=>{const i=e.data;return this.br(t,i,r,n)}))}br(t,e,r,n,i){n||(n=e.byteLength);const s=this.Pr(e,t,r,n),o=[];for(let r=0;r<s.length;r++){let n;if("b3dm"===s[r].magic)n=new Ln(this.o,this.gr);else if("i3dm"===s[r].magic)n=new Pn(this.o,this.gr);else if("pnts"===s[r].magic)n=new kn;else{if("cmpt"!==s[r].magic){console.warn("Unsupported magic in CMPT tile:",s[r].magic);continue}n=new Vn(this.o,this.gr)}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})))}Pr(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=Ln,t.CMPTLoader=Vn,t.Geo3DTilesLayer=vn,t.Geo3DTilesUtil=C,t.Geo3DTransform=de,Object.defineProperty(t,"t",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/3dtiles v0.18.1")}));
|