@maptalks/transform-control 0.98.0 → 0.98.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/transform-control v0.98.
|
|
2
|
+
* @maptalks/transform-control v0.98.1
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2024 maptalks.org
|
|
5
5
|
*/
|
|
@@ -1871,5 +1871,5 @@ eA.mergeOptions({
|
|
|
1871
1871
|
|
|
1872
1872
|
export { eA as TransformControl };
|
|
1873
1873
|
|
|
1874
|
-
"undefined" != typeof console && console.log("@maptalks/transform-control v0.98.
|
|
1874
|
+
"undefined" != typeof console && console.log("@maptalks/transform-control v0.98.1");
|
|
1875
1875
|
//# sourceMappingURL=transform-control.es.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @maptalks/transform-control v0.98.
|
|
2
|
+
* @maptalks/transform-control v0.98.1
|
|
3
3
|
* LICENSE : UNLICENSED
|
|
4
4
|
* (c) 2016-2024 maptalks.org
|
|
5
5
|
*/
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* LICENSE : UNLICENSED
|
|
10
10
|
* (c) 2016-2024 maptalks.org
|
|
11
11
|
*/
|
|
12
|
-
let P=0;function b(A){return null==A}function D(A){return!b(A)}function y(A){return!b(A)&&("string"==typeof A||null!==A.constructor&&A.constructor===String)}function B(A){for(let t=1;t<arguments.length;t++){const e=arguments[t];for(const t in e)A[t]=e[t]}return A}function d(A){switch(A){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: "+A)}function p(A){return 0===A.indexOf("data:")&&A.indexOf("base64,")>0}function v(A){const t=function(A){return"undefined"!=typeof self?self.atob(A):window.atob(A)}(A.substring(A.indexOf(",")+1)),e=t.length,s=new Uint8Array(e);for(let A=0;A<e;A++)s[A]=t.charCodeAt(A);return s.buffer}const M=[],L=[],E=[],O=[0,0,0],x=function(A){return A[0]=0,A[1]=0,A[2]=0,A[3]=1,A}([]),F=[1,1,1];function U(A,t,e,s,n,i,r){const o=d(r),a=o.BYTES_PER_ELEMENT;if((0===n||n===s*a)&&i%a==0){const n=new o(t,i,e*s);return A.set(n),A}0===n&&(n=s*a);const h=new Uint8Array(s*a);for(let r=0;r<e;r++){let e=null;const I=new Uint8Array(t,n*r+i,s*a);h.set(I),e=new o(h.buffer,0,s);for(let t=0;t<s;t++)A[r*s+t]=e[t]}return A}const V="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function T(A,t,e){const s=new Uint8Array(A,t,e);return V.decode(s)}const S={get:function(A,t={},e){t||(t={});const s=new AbortController,n=s.signal,i=B({},t);i.signal=n,i.method||(i.method="GET"),i.referrerPolicy=i.referrerPolicy||"origin","undefined"==typeof window||i.referrer||(i.referrer=window.location.href),e&&(A=e(A));const r=fetch(A,i).then((A=>{const e=this.A(A,t.responseType);return e.message?e:e.then((e=>"arraybuffer"===t.responseType?{data:e,cacheControl:A.headers.get("Cache-Control"),expires:A.headers.get("Expires"),contentType:A.headers.get("Content-Type")}:e)).catch((A=>{if(!A.code||A.code!==DOMException.ABORT_ERR)throw A}))})).catch((A=>{if(!A.code||A.code!==DOMException.ABORT_ERR)throw A}));return r.xhr=s,r},A:(A,t)=>200!==A.status?{status:A.status,statusText:A.statusText,message:`incorrect http request with status code(${A.status}): ${A.statusText}`}:"arraybuffer"===t?A.arrayBuffer():"json"===t?A.json():A.text(),getArrayBuffer:(A,t={},e)=>(t||(t={}),t.responseType="arraybuffer",S.get(A,t,e)),getJSON:function(A,t={},e){return t&&t.jsonp?S.jsonp(A):((t=t||{}).responseType="json",S.get(A,t,e))},jsonp:function(A){const t="_maptalks_jsonp_"+P++;A.match(/\?/)?A+="&callback="+t:A+="?callback="+t;let e=document.createElement("script");return e.type="text/javascript",e.src=A,new Promise((A=>{window[t]=function(s){document.getElementsByTagName("head")[0].removeChild(e),e=null,delete window[t],A(s)},document.getElementsByTagName("head")[0].appendChild(e)}))}};class k{constructor(A,t,e,s,n){this.t=A,this.decoders=t,this.i=e,this.images={},this.o={},this.h=s||{},this.I=n}requestImageFromBufferURI(A,t,e){if(this.buffers[A.id]){const s=this.buffers[A.id],n=this.u(t,s);return this.getImageByBuffer(n,e)}if(this.o[A.id])return this.o[A.id].then((()=>{const s=this.buffers[A.id],n=this.u(t,s);return this.getImageByBuffer(n,e)}));if(p(A.uri)){const s=this.buffers[A.id]=v(A.uri),n=this.u(t,s);return this.getImageByBuffer(n,e)}let s;const n=A.uri.indexOf("blob:")>=0;return s=A.uri.indexOf("://")>0||n?A.uri:this.rootPath+"/"+A.uri,this.o[A.id]=S.getArrayBuffer(s,this.h,this.I).then((s=>{const n=this.buffers[A.id]=s.data,i=this.u(t,n);return this.getImageByBuffer(i,e)}))}getImageByBuffer(A,t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=this.decoders;return e[t.mimeType]?e[t.mimeType](A,{supportedFormats:this.i}):"image/crn"===t.mimeType||"image/ktx2"===t.mimeType||"image/cttf"===t.mimeType?(console.warn("missing transcoder for "+t.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.C(t.id,A)}requestExternalImage(A){if(this.images[A.id])return Promise.resolve(this.images[A.id]);const t=0===A.uri.indexOf("data:image/")?A.uri:this.rootPath+"/"+A.uri;return this.o[A.id]?this.o[A.id].then((()=>this.images[A.id])):this.o[A.id]=this.C(A.id,t)}C(A,t){return new Promise(((e,s)=>{let n=t;this.I&&(n=this.I(t)),this.t(n,this.h,((n,i)=>{n?s(n):(URL.revokeObjectURL(t),this.images[A]=i,e(this.images[A]))}))}))}}const _=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],N=[];class R{constructor(A,t,e,s,n){this.rootPath=A,this.gltf=t,this.l=!1,this.glbBuffer=e,this.buffers={},this.requests={},this.accessors={},this.m(),this.h=s,this.I=n}P(A,t){const e=this.gltf,s=e.accessors[t];if(void 0===s.bufferView)return this.accessors[s.id]=this.D(A,t,null,0),Promise.resolve(this.accessors[s.id]);if(s&&this.accessors[s.id])return Promise.resolve(this.accessors[s.id]);const n=e.bufferViews[s.bufferView];return this.B(n).then((e=>{const{buffer:n,byteOffset:i}=e;return this.accessors[s.id]=this.D(A,t,n,i)}))}B(A){const t=this.gltf.buffers[A.buffer];if(this.buffers[t.id]){const A=this.buffers[t.id];return Promise.resolve({buffer:A,byteOffset:0})}if(this.requests[t.id])return this.requests[t.id].then((()=>{const A=this.buffers[t.id];return Promise.resolve({buffer:A,byteOffset:0})}));if("binary_glTF"!==A.buffer&&"KHR_binary_glTF"!==A.buffer&&t.uri){if(p(t.uri)){const A=this.buffers[t.id]=v(t.uri);return Promise.resolve({buffer:A,byteOffset:0})}let A;const e=t.uri.indexOf("blob:")>=0;return A=t.uri.indexOf("://")>0||e?t.uri:this.rootPath+"/"+t.uri,this.requests[t.id]=S.getArrayBuffer(A,this.h,!e&&this.I).then((s=>(e&&URL.revokeObjectURL(A),{buffer:this.buffers[t.id]=s.data,byteOffset:0})))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}D(A,t,e,s=0){const n=this.gltf,i=n.accessors[t],r=void 0!==i.bufferView?n.bufferViews[i.bufferView]:{},o=(r.byteOffset||0)+s,a=this.p(i.type),h=d(i.componentType),I=r.byteStride||0,c={array:void 0,name:A,accessorName:t,byteLength:i.count*a*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:a,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(c.min=i.min),i.max&&(c.max=i.max),e)if(this.l)c.byteStride=I,c.byteOffset=o+(i.byteOffset||0),!I||I===a*h.BYTES_PER_ELEMENT||"indices"===A||"input"===A||"output"===A||A.indexOf("morph")>=0?(c.array=this.v(e,i.count,a,o+(i.byteOffset||0),h),c.array.buffer.byteLength===c.byteLength&&(c.byteOffset=0)):c.array=new Uint8Array(e,o,r.byteLength);else if(i.interleaved){c.byteStride=0,c.byteOffset=0;const A=new h(i.count*a);if(c.array=U(A,e,i.count,a,I,o+(i.byteOffset||0),i.componentType),c.extensions&&c.extensions.WEB3D_quantized_attributes&&a>2){const A=new Float32Array(c.array.length),{decodeMatrix:t}=c.extensions.WEB3D_quantized_attributes;for(let e=0;e<c.array.length;e+=a){N[0]=c.array[e],N[1]=c.array[e+1],N[2]=c.array[e+2],N[3]=1;const s=C(N,N,t);A[e]=s[0],A[e+1]=s[1],A[e+2]=s[2]}c.componentType=5126,c.array=A}}else c.byteStride=0,c.array=this.v(e,i.count,a,o+(i.byteOffset||0),h),c.byteOffset=c.array.byteOffset;else{c.array=new h(i.count);const A=c.min||c.max;A&&(c.array[0]=A[0],c.array[1]=A[1],c.array[2]=A[2])}return c}m(){const A=this.gltf.accessors;if(Array.isArray(A))for(let t=0;t<A.length;t++)for(let e=0;e<A.length;e++)t!==e&&A[t].bufferView===A[e].bufferView&&(A[t].interleaved=A[e].interleaved=!0);else for(const t in A)for(const e in A)t!==e&&A[t].bufferView===A[e].bufferView&&(A[t].interleaved=A[e].interleaved=!0)}v(A,t,e,s,n){return s%n.BYTES_PER_ELEMENT!=0&&(A=A.slice(s,s+t*e*n.BYTES_PER_ELEMENT),s=0),new n(A,s,e*t)}p(A){const t=_.indexOf(A);return _[t+1]}requestKHRTechniquesWebgl(A){const{shaders:t}=A,e=t.map((A=>{if(void 0!==A.bufferView){const t=this.gltf.bufferViews[A.bufferView],{byteLength:e}=t;return this.B(t).then((s=>{const{buffer:n,byteOffset:i}=s,r=T(n,i+(t.byteOffset||0),e);return A.content=r,A}))}if(A.uri){if(p(A.uri)){const t=v(A.uri),e=T(t,0,t.byteLength);return A.content=e,Promise.resolve(A)}{const t=this.rootPath+"/"+A.uri;return S.get(t,this.h,this.I).then((t=>(A.content=t,A)))}}return Promise.resolve(A)}));return Promise.all(e).then((()=>A))}}class H extends k{constructor(A,t,e,s,n,i,r,o){super(s,n,i,r,o),this.rootPath=A,this.gltf=t,this.requests={},this.buffers={},this.glbBuffer=e,this.accessor=new R(A,t,e,r,o)}iterate(A,t){const e=this.gltf[t];if(!e)return;let s=0;for(const t in e)A(t,e[t],s++)}createNode(A){const t={};if(D(A.name)&&(t.name=A.name),D(A.children)&&(t.children=A.children),D(A.jointName)&&(t.jointName=A.jointName),D(A.matrix)&&(t.matrix=A.matrix),D(A.rotation)&&(t.rotation=A.rotation),D(A.scale)&&(t.scale=A.scale),D(A.translation)&&(t.translation=A.translation),D(A.extras)&&(t.extras=A.extras),D(A.meshes)&&(t.mesh=A.meshes[0]),t.translation||t.rotation||t.scale){const A=function(A,t){if(t.matrix)return t.matrix;if(t.translation||t.scale||t.rotation){const e=function(A,t){return A[0]=1,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=1,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1,A[11]=0,A[12]=t[0],A[13]=t[1],A[14]=t[2],A[15]=1,A}(M,t.translation||O),s=function(A,t){var e=t[0],s=t[1],n=t[2],i=t[3],r=e+e,o=s+s,a=n+n,h=e*r,I=s*r,c=s*o,g=n*r,f=n*o,u=n*a,C=i*r,l=i*o,w=i*a;return A[0]=1-c-u,A[1]=I+w,A[2]=g-l,A[3]=0,A[4]=I-w,A[5]=1-h-u,A[6]=f+C,A[7]=0,A[8]=g+l,A[9]=f-C,A[10]=1-h-c,A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(L,t.rotation||x),n=function(A,t){return A[0]=t[0],A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=t[1],A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=t[2],A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(E,t.scale||F);return o(n,s,n),o(A,e,n)}return function(A){return A[0]=1,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=1,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1,A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(A)}([],t);delete t.translation,delete t.rotation,delete t.scale,t.matrix=A}return t}M(A){const t={};for(const e in A){const s=A[e];let n,i;s.instanceTechnique&&s.instanceTechnique.values?(n=s.instanceTechnique,i=n.values.diffuse):(n=s,i=n.values.tex||n.values.diffuseTex||n.values.diffuse);const r={baseColorTexture:{index:i}};s.name&&(r.name=s.name),s.extensions&&(r.extensions=s.extensions),s.extras&&(r.extras=s.extras),t[e]=r}return t}L(A){if(A.bufferView||A.extensions&&(A.extensions.KHR_binary_glTF||A.extensions.binary_glTF)){const t=A.bufferView?A:A.extensions.KHR_binary_glTF||A.extensions.binary_glTF;A.extensions&&(A.mimeType=t.mimeType,A.width=t.width,A.height=t.height);const e=this.gltf.bufferViews[t.bufferView],s=(e.byteOffset||0)+this.glbBuffer.byteOffset,n=e.byteLength,i=this.buffers[t.bufferView]=new Uint8Array(this.glbBuffer.buffer,s,n);return this.getImageByBuffer(i,A)}return this.requestExternalImage(A)}O(A){const t=this.gltf.textures[A];if(!t)return null;const e=this.gltf.images[t.source];return this.L(e).then((A=>{const s=this.gltf.samplers[t.sampler];return{image:{array:A.data,width:A.width,height:A.height,index:t.source,mimeType:e.mimeType,name:e.name,extras:e.extras},sampler:s}}))}getBaseColorTexture(A){const t=this.gltf.materials[A];let e,s;if(t.instanceTechnique&&t.instanceTechnique.values?(e=t.instanceTechnique,s=e.values.diffuse):(e=t,s=e.values.tex||e.values.diffuseTex||e.values.diffuse),void 0===s||void 0===this.gltf.textures)return null;const n=this.gltf.textures[s];if(!n)return null;const i=this.gltf.samplers[n.sampler];return{format:n.format||6408,internalFormat:n.internalFormat||6408,type:n.type||5121,sampler:i,source:this.gltf.images[n.source]}}getMaterial(){return null}getAnimations(){return null}}const J=9729;class K extends k{constructor(A,t,e,s,n,i,r,o){super(s,n,i,r,o),this.rootPath=A,this.gltf=t,this.glbBuffer=e,this.buffers={},this.requests={},this.accessor=new R(A,t,e,r,o)}iterate(A,t){const e=this.gltf[t];if(e)for(let t=0;t<e.length;t++)A(t,e[t],t)}createNode(A){const t={};return B(t,A),!D(A.weights)&&this.gltf.meshes&&D(t.mesh)?t.weights=this.gltf.meshes[t.mesh].weights:A.weights&&(t.weights=A.weights),t}O(A){const t=this.gltf.textures[A];if(!t)return null;let e=t.source;if(t.extensions&&t.extensions.EXT_texture_webp&&(e=t.extensions.EXT_texture_webp.source),!D(e))return null;const s=this.gltf.images[e];return this.L(s).then((A=>{if(!A)return null;const e={image:{array:A.data,mipmap:A.mipmap,width:A.width,height:A.height,index:t.source,mimeType:s.mimeType,name:s.name,extensions:s.extensions,extras:s.extras}};B(e,t);const n=D(t.sampler)?this.gltf.samplers[t.sampler]:void 0;if(n&&(e.sampler=n,e.sampler.magFilter=n.magFilter||J,e.sampler.minFilter=n.minFilter||J,e.sampler.wrapS=n.wrapS||10497,e.sampler.wrapT=n.wrapT||10497),!e.mipmap&&e.sampler.minFilter!==J&&9728!==e.sampler.minFilter){const A=e.sampler.minFilter;e.sampler.minFilter=9984===A||9986===A?9728:J}return A.format&&(e.format=A.format),e}))}L(A){if(!D(A.bufferView))return this.requestExternalImage(A);{const t=this.gltf.bufferViews[A.bufferView],e=this.gltf.buffers[t.buffer];if(e.uri)return this.requestImageFromBufferURI(e,t,A);if(this.glbBuffer)return this.F(t,A)}return null}F(A,t){const e=this.u(A,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(e,t)}u(A,t,e){e=e||0;const s=(A.byteOffset||0)+e,n=A.byteLength;return new Uint8Array(t,s,n)}U(A,t){const e=new Array(A.byteLength);for(let t=0;t<A.byteLength;t++)e[t]=String.fromCharCode(A[t]);e.join("");const s="data:"+(t=t||"image/png")+";base64,"+function(A){return"undefined"!=typeof self?self.btoa(A):window.btoa(A)}(unescape(encodeURIComponent(e)));return s}getAnimations(A){const t=[];return A.forEach((A=>{t.push(this.getSamplers(A.samplers))})),Promise.all(t).then((t=>{for(let e=0;e<t.length;e++)A[e].samplers=t[e];return A}))}getSamplers(A){const t=[];for(let e=0;e<A.length;e++)(D(A[e].input)||D(A[e].output))&&(t.push(this.accessor.P("input",A[e].input)),t.push(this.accessor.P("output",A[e].output)));return Promise.all(t).then((t=>{for(let e=0;e<t.length/2;e++)A[e].input=t[2*e],A[e].output=t[2*e+1],A[e].interpolation||(A[e].interpolation="LINEAR");return A}))}}const j="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class z{static read(A,t=0,e=0){e||(e=A.byteLength);const s=new DataView(A,t,e),n=s.getUint32(4,!0);if(1===n)return z.readV1(s,t);if(2===n)return z.readV2(A,t);throw new Error("Unsupported glb version : "+n)}static readV1(A,t){const e=A.getUint32(8,!0),s=A.getUint32(12,!0);if(e!==A.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const n=G(A.buffer,20+t,s);return{json:JSON.parse(n),glbBuffer:{byteOffset:20+t+s,buffer:A.buffer,byteLength:e}}}static readV2(A,t){let e,s,n;const i=new DataView(A,t+12);let r=0;for(;r<i.byteLength;){const o=i.getUint32(r,!0);r+=4;const a=i.getUint32(r,!0);if(r+=4,1313821514===a)e=G(A,t+12+r,o);else if(5130562===a){n=t+12+r,s=o;break}r+=o}return{json:JSON.parse(e),glbBuffer:{byteOffset:n,buffer:A,byteLength:s}}}}function G(A,t,e){if(j){const s=new Uint8Array(A,t,e);return j.decode(s)}return function(A){const t=A.length;let e="";for(let s=0;s<t;){let n=A[s++];if(128&n){let e=Z[n>>3&7];if(!(64&n)||!e||s+e>t)return null;for(n&=63>>e;e>0;e-=1){const t=A[s++];if(128!=(192&t))return null;n=n<<6|63&t}}e+=String.fromCharCode(n)}return e}(new Uint8Array(A,t,e))}const Z=[1,1,1,1,2,2,3,0],Y=[0,0,0],q=[0,0,0,1],W=[1,1,1],X={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},$={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},AA={V(A,t,e,s,n,i,r,o){const a=D(A)?t.animations:[t.animations[0]],h={};for(let t=0;t<a.length;t++){const c=a[t],g=c.name||t;if(D(A)&&g!==A)continue;const f=c.channelsMap[e];if(f)for(let A=0;A<f.length;A++){const t=f[A];"translation"===t.target.path?(this.T(n,c.samplers[t.sampler],s,1),h.translation=I(Y,n)):"rotation"===t.target.path?(this.S(i,c.samplers[t.sampler],s,1),h.rotation=m(q,i)):"scale"===t.target.path?(this.T(r,c.samplers[t.sampler],s,1),h.scale=I(W,r)):"weights"===t.target.path&&o&&(this.T(o,c.samplers[t.sampler],s,o.length),h.weights=o)}}return h},T(A,t,e,s){switch(t.interpolation){case"LINEAR":{const n=this.k($,t,e,1*s);n&&(A=function(A,t,e,s){for(let n=0;n<A.length;n++)A[n]=t[n]+s*(e[n]-t[n]);return A}(A,n.PREVIOUS,n.NEXT,n.INTERPOLATION));break}case"STEP":{const n=this.k($,t,e,1*s);n&&(A=function(A,t){for(let e=0;e<A.length;e++)A[e]=t[e];return A}(A,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this.k($,t,e,3*s);n&&(A=this._(A,n,t.input.array,3*s));break}}return A},S(A,t,e){switch(t.interpolation){case"LINEAR":{const s=this.k($,t,e,1);s&&w(A,s.PREVIOUS,s.NEXT,s.INTERPOLATION);break}case"STEP":{const s=this.k($,t,e,1);s&&(A=u(A,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.k($,t,e,3);if(s){for(let A=0;A<s.PREVIOUS.length;A++)s.PREVIOUS[A]=Math.acos(s.PREVIOUS[A]),s.NEXT[A]=Math.acos(s.NEXT[A]);A=this._(A,s,t.input.array,3);for(let t=0;t<A.length;t++)A[t]=Math.cos(A[t])}break}}return A},N(A,t){const e=A.length;let s,n,i,r=0,o=e-1,a=Math.floor((r+o)/2);for(;r<=e-1&&o>=0;){if(r===o)return null;if(A[a]<=t&&t<=A[a+1]){const e=A[a];return s=a,n=a+1,i=(t-e)/(A[a+1]-e),{preIndx:s,nextIndex:n,interpolation:i}}t<A[a]?(o=a,a=Math.floor((r+o)/2)):A[a+1]<t&&(r=a,a=Math.floor((r+o)/2))}return null},k(A,t,e,s){const n=t.input.array,i=t.output.array,r=t.output.itemSize;(e<n[0]||e>n[n.length-1])&&(e=Math.max(n[0],Math.min(n[n.length-1],e))),e===n[n.length-1]&&(e=n[0]);const o=this.N(n,e);if(!o||!o.nextIndex)return null;const{preIndx:a,nextIndex:h,interpolation:I}=o;A.PREINDEX=a,A.NEXTINDEX=h,A.INTERPOLATION=I;const c=r*s;return A.PREVIOUS=i.subarray(A.PREINDEX*c,(A.PREINDEX+1)*c),A.NEXT=i.subarray(A.NEXTINDEX*c,(A.NEXTINDEX+1)*c),A},_(A,t,e,s){const n=t.INTERPOLATION,i=e[t.PREINDEX],r=e[t.NEXTINDEX];for(let e=0;e<3;e++){const o=t.PREVIOUS[s+e],a=(r-i)*t.PREVIOUS[2*s+e],h=t.NEXT[3+e],I=(r-i)*t.NEXT[e],c=(2*Math.pow(n,3)-3*Math.pow(n,2)+1)*o+(Math.pow(n,3)-2*Math.pow(n,2)+n)*a+(2*-Math.pow(n,3)+3*Math.pow(n,2))*h+(Math.pow(n,3)-Math.pow(n,2))*I;A[e]=c}return A},getAnimationClip(A,t,e,s){const n=A.nodes[t]&&A.nodes[t].weights;return c(Y,...X.TRANSLATION),u(q,...X.ROTATION),c(W,...X.SCALE),this.V(s,A,t,e,Y,q,W,n)},getTimeSpan(A){if(!A.animations)return null;if(A.timeSpan)return A.timeSpan;const t=A.animations;return A.timeSpan={},t.forEach(((t,e)=>{let s=-1/0,n=1/0;const i=t.channels;for(let A=0;A<i.length;A++){const e=i[A],r=t.samplers[e.sampler].input.array;r[r.length-1]>s&&(s=r[r.length-1]),r[0]<n&&(n=r[0])}const r=t.name||e;A.timeSpan[r]={max:s,min:n}})),A.timeSpan},getTimeSpanByName(A,t){const e=this.getTimeSpan(A);return e?D(t)?e[t]:e[Object.keys(e)[0]]:null}};let tA=!1;if("undefined"!=typeof OffscreenCanvas){let A;try{A=new OffscreenCanvas(2,2).getContext("2d")}catch(A){}A&&"undefined"!=typeof createImageBitmap&&(tA=!0)}const eA="undefined"==typeof document?null:document.createElement("canvas");class sA{constructor(A,t,e){if(this.options=e||{},this.options.decoders||(this.options.decoders={}),this.h=this.options.fetchOptions||{},t.buffer instanceof ArrayBuffer){const{json:e,glbBuffer:s}=z.read(t.buffer,t.byteOffset,t.byteLength);this.R(A,e,s)}else this.R(A,t);this.H=new R(this.rootPath,this.gltf,this.glbBuffer,this.h,this.options.urlModifier),this.J()}J(){const A=this.gltf.extensionsRequired;if(A){if(A.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(A.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders["image/ktx2"])throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded");if(A.indexOf("EXT_meshopt_compression")>=0)throw new Error("EXT_meshopt_compression extension is not supported yet.")}}K(){const A=this.gltf.extensions;return A&&A.KHR_techniques_webgl?this.H.requestKHRTechniquesWebgl(A.KHR_techniques_webgl).then((t=>(A.KHR_techniques_webgl=t,A))):Promise.resolve(A)}load(A){A=A||{};const t=this.j(A),e=this.G(),s=this.Z(),n=this.K();return Promise.all([t,e,s,n]).then((A=>(A[0].animations=A[1],A[0].textures=A[2],A[0].extensions=A[3],A[0].transferables=this.transferables||[],this.createChannelsMap(A[0]),A[0])))}createChannelsMap(A){const t=A.animations;if(t)for(let A=0;A<t.length;A++){const e=t[A];e.channelsMap={};for(let A=0;A<e.channels.length;A++){const t=e.channels[A];e.channelsMap[t.target.node]||(e.channelsMap[t.target.node]=[]),e.channelsMap[t.target.node].push(t)}}}getExternalResources(){const A=[];if(this.gltf){const{buffers:t,images:e}=this.gltf;for(let e=0;e<t.length;e++)t[e].uri&&t[e].uri.indexOf("data:application/octet-stream;base64")<0&&A.push({type:"buffer",uri:t[e].uri});for(let t=0;t<e.length;t++)e[t].uri&&e[t].uri.indexOf("data:image/")<0&&A.push({type:"image",uri:e[t].uri})}return A}static getAnimationClip(A,t,e,s){return AA.getAnimationClip(A,t,e,s)}static getAnimationTimeSpan(A,t){return AA.getTimeSpanByName(A,t)}static getTypedArrayCtor(A){return d(A)}static readInterleavedArray(A,t,e,s,n,i,r){return U(A,t,e,s,n,i,r)}R(A,t,e){this.gltf=t,this.glbBuffer=e,this.version=t.asset?+t.asset.version:1,this.rootPath=A,this.buffers={},this.requests={},this.options.requestImage=tA?IA.bind(this):this.options.requestImage||nA,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new K(A,t,e,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.h,this.options.urlModifier),this.adapter.iterate(((A,t,e)=>{t.id="buffer_"+e}),"buffers"),this.adapter.iterate(((A,t,e)=>{t.id="image_"+e}),"images"),this.adapter.iterate(((A,t,e)=>{t.id="accessor_"+e}),"accessors")):(this.adapter=new H(A,t,e,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.h,this.options.urlModifier),this.adapter.iterate(((A,t,e)=>{t.id="accessor_"+e}),"accessors"),this.adapter.iterate(((A,t,e)=>{t.id="image_"+e}),"images"))}Y(A,t){if(A.children&&A.children.length>0){if(!("number"==typeof(e=A.children[0])&&isFinite(e)||y(A.children[0])))return A;const s=A.children.map((A=>{const e=t[A];return e.nodeIndex=A,this.Y(e,t)}));A.children=s}var e;return A}j(A){return this.q(A).then((A=>{const t=this.scenes=[];let e;for(const t in A)A[t]=this.Y(A[t],A),A[t].nodeIndex=Number(t)?Number(t):t;this.adapter.iterate(((s,n,i)=>{const r={};n.name&&(r.name=n.name),n.nodes&&(r.nodes=n.nodes.map((t=>A[t]))),this.gltf.scene===s&&(e=i),t.push(r)}),"scenes");const s={textures:this.gltf.textures,asset:this.gltf.asset,scene:e,scenes:t,nodes:A,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(s.extensions=this.gltf.extensions),1===this.version){const A=this.adapter.M(this.gltf.materials);s.materials=A}return delete this.gltf.buffers,s.json=this.gltf,s}))}q(A){return this.W(A).then((()=>{const A=this.nodes={};return this.adapter.iterate(((t,e)=>{const s=this.adapter.createNode(e,this.meshes,this.skins);A[t]=s}),"nodes"),A}))}X(){this.skins=[];const A=[];return this.adapter.iterate(((t,e,s)=>{A.push(this.$(e).then((A=>{A.index=s,this.skins.push(A)})))}),"skins"),A}$(A){const t=A.inverseBindMatrices;return this.adapter.accessor.P("inverseBindMatrices",t).then((t=>(A.inverseBindMatrices=t,t&&t.buffer&&this.transferables&&this.transferables.indexOf(t.buffer)<0&&this.transferables.push(t.buffer),A)))}G(){const A=this.gltf.animations;return D(A)?this.adapter.getAnimations(A):null}W(A){this.meshes={};let t=[];return this.adapter.iterate(((e,s,n)=>{t.push(this.AA(s,A).then((A=>{A.index=n,this.meshes[e]=A})))}),"meshes"),t=t.concat(this.X()),Promise.all(t)}AA(A,t){const e=A.primitives.map((A=>this.tA(A,t))).filter((A=>!!A));return Promise.all(e).then((t=>{const e={};return B(e,A),e.primitives=t,e}))}Z(){const A=this.gltf.textures;if(!A)return null;const t=[];for(const e in A)t.push(this.adapter.O(e));return Promise.all(t).then((t=>{if(this.transferables)for(let A=0;A<t.length;A++){const e=t[A]&&t[A].image.array;if(e){let A;A=e instanceof ImageBitmap?e:e.buffer,A&&this.transferables.indexOf(A)<0&&this.transferables.push(A)}}if(!Array.isArray(A)){const e={},s=Object.keys(A);for(let A=0;A<t.length;A++)t[A]&&(e[s[A]]=t[A]);return e}return t}))}tA(A,t){let e;const s=[],n=A.extensions;if(D(A.targets))for(let t=0;t<A.targets.length;t++){const e=A.targets[t];for(const A in e){const n=this.adapter.accessor.P(`morphTargets_${A}_${t}`,e[A]);n&&s.push(n)}}if(n&&n.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const A=this.options.decoders.draco,{bufferView:i,attributes:r}=n.KHR_draco_mesh_compression,o=this.gltf.bufferViews[i],a=this.H.B(o).then((e=>{const{buffer:s,byteOffset:n}=e;let{byteOffset:i}=o;const a=o.byteLength;i||(i=0);const h=new DataView(s,n+i,a),I={attributes:r,useUniqueIDs:!1,skipAttributeTransform:t.skipAttributeTransform};return A(h,I).then((A=>{const t=Object.values(A.attributes);return A.indices&&t.push(A.indices),t}))}));s.push(a),e=Promise.all(s)}else{const t=A.attributes;for(const A in t){const e=this.adapter.accessor.P(A,t[A]);e&&s.push(e)}if(D(A.indices)){const t=this.adapter.accessor.P("indices",A.indices);t&&s.push(t)}e=Promise.all(s)}return e.then((t=>{if(n&&n.KHR_draco_mesh_compression){const e=A.targets?A.targets.length:0;t[e]=t[e].concat(t.slice(0,e)),t=t[e]}let e,s;const i={attributes:t.reduce(((A,t)=>{if("indices"===t.name)e=t;else if(t.name.indexOf("morphTargets_")>-1)s=s||{},s[t.name.slice(13)]=t;else{if(!("POSITION"!==t.name||t.min&&t.max)){const A=[1/0,1/0,1/0],e=[-1/0,-1/0,-1/0],{itemSize:s,array:n}=t,i=n.length/s;for(let t=0;t<i;t++)for(let i=0;i<s;i++){const r=t*s+i;n[r]<A[i]&&(A[i]=n[r]),n[r]>e[i]&&(e[i]=n[r])}if(t.quantization){const s=t.quantization,n=s.range/(1<<s.quantizationBits),i=s.minValues;f(A,A,n),g(A,A,i),f(e,e,n),g(e,e,i)}t.min=A,t.max=e}A[t.name]=t}return this.transferables&&t.array.buffer&&this.transferables.indexOf(t.array.buffer)<0&&this.transferables.push(t.array.buffer),A}),{}),material:A.material};return e&&(i.indices=e),s&&(i.morphTargets=s),i.mode=D(A.mode)?A.mode:4,D(A.extras)&&(i.extras=A.extras),i}))}}function nA(A,t,e){const s=new Image;s.crossOrigin="",s.onload=()=>{if(!eA)return void e(new Error("There is no canvas to draw image!"));eA.width=s.width,eA.height=s.height;const A=eA.getContext("2d",{willReadFrequently:!0});A.drawImage(s,0,0,s.width,s.height);const t=A.getImageData(0,0,s.width,s.height),n={width:s.width,height:s.height,data:new Uint8Array(t.data)};e(null,n)},s.onerror=function(A){e(A)},s.src=A}const iA=[],rA=[],oA=10;let aA,hA;function IA(A,t,e){aA||(aA=new OffscreenCanvas(2,2),hA=aA.getContext("2d",{willReadFrequently:!0}));let s=null;if(y(A))this.options.urlModifier&&(A=this.options.urlModifier(A)),iA.push([A,t,e,this]),cA();else{const t=new Blob([A]);s=createImageBitmap(t),s.then(gA.bind(this)).then((A=>{e(null,A)})).catch((A=>{console.warn(A),e(A)}))}}function cA(){if(!iA.length||rA.length>oA)return;const A=iA.shift(),[t,e,s,n]=A;rA.push(A),fetch(t,e).then((A=>A.arrayBuffer())).then((A=>{const t=new Blob([new Uint8Array(A)]);return createImageBitmap(t)})).then(gA.bind(n)).then((t=>{s.call(n,null,t);const e=rA.indexOf(A);rA.splice(e,1),cA()})).catch((t=>{console.warn(t),s.call(n,t);const e=rA.indexOf(A);rA.splice(e,1),cA()}))}function gA(A){let{width:t,height:e}=A;fA(t)||(t=uA(t)),fA(e)||(e=uA(e));const s=this.options.maxTextureSize;s&&(t=Math.min(s,t),e=Math.min(s,e)),aA.width=t,aA.height=e,hA.drawImage(A,0,0,t,e),A.close();const n=hA.getImageData(0,0,t,e);return{width:t,height:e,data:new Uint8Array(n.data)}}function fA(A){return!(A&A-1)&&0!==A}function uA(A){return Math.pow(2,Math.floor(Math.log(A)/Math.LN2))}function CA(A,e,s,n,r,o){const a=[],h=t.quat.fromEuler([],s[0],s[1],s[2]),I=t.mat4.fromRotationTranslationScale([],h,e,n),c=function(A){return new sA("",JSON.parse(JSON.stringify(i[A]))).load().then((A=>A))}(A);return c.then((A=>{t.reshader.GLTFHelper.exportGLTFPack(A).getMeshesInfo().forEach(((A,i)=>{const h=new t.reshader.Material({color:r||A.materialInfo.baseColorFactor}),c=new t.reshader.Mesh(A.geometry,h);c.setUniform("uPickingId",o+i);const g=c.getDefines();g.HAS_PICKING_ID=2,c.setDefines(g),c.translate=e,c.rotation=s,c.scaling=n,t.mat4.multiply(c.localTransform,I,A.nodeMatrix),c.originTransform=t.mat4.copy([],c.localTransform),c.originColor=r||A.materialInfo.baseColorFactor,a.push(c)})),o>100&&(a[0].properties.relatedMeshes=a.slice(1,2),a[1].properties.relatedMeshes=a.slice(0,1),a[2].properties.relatedMeshes=a.slice(3,4),a[3].properties.relatedMeshes=a.slice(2,3),a[4].properties.relatedMeshes=a.slice(5,6),a[5].properties.relatedMeshes=a.slice(4,5),a[6].properties.relatedMeshes=a.slice(0,6))})),a}function lA(A,t){return Math.abs(A)*Math.sign(t)}function wA(A,e){const s=A.getCoordinates(),i=e.coordinateToPointAtRes(s,e.getGLRes()),r=[i.x,i.y,0],o=QA(e,A.getTranslation());t.vec3.add(r,r,o);const a=function(A,t,e,s){return A._pointAtResToContainerPoint(t,e,s)}(e,new n.Point(r[0],r[1]),e.getGLRes());a.x+=85;const h=function(A,t,e,s){{const s=A.containerPointToCoordinate(t);return A.coordinateToPointAtRes(s,e)}}(e,a,e.getGLRes());return Math.sqrt(Math.pow(h.x-r[0],2)+Math.pow(h.y-r[1],2))/5.272881136101205}function QA(A,e){if(!A)return e;const s=A.distanceToPointAtRes(e[0],e[1],A.getGLRes()),n=A.altitudeToPoint(e[2],A.getGLRes());return t.vec3.set([],lA(s.x,e[0]),lA(s.y,e[1]),lA(n,e[2]))}class mA{constructor(A){this.eA=A,this._meshes=this.sA()}setCoordinate(A){this.eA=A}sA(){const A=[],t=340/177,e=CA("jiantou",[1.2*t,0,0],[0,0,90],[t,t,t],[89/255,206/255,147/255,0],7),s=CA("jiantou",[0,1.2*t,0],[0,0,180],[t,t,t],[89/255,206/255,147/255,0],8),n=CA("jiantou",[-1.2*t,0,0],[0,0,270],[t,t,t],[89/255,206/255,147/255,0],9),i=CA("jiantou",[0,-1.2*t,0],[0,0,0],[t,t,t],[89/255,206/255,147/255,0],10);return A.push(e,s,n,i),A}getMeshes(){return this._meshes}}class PA{constructor(A){this.eA=A,this._meshes=this.sA()}setCoordinate(A){this.eA=A}sA(){const A=[],t=340/177,e=CA("xuanzhuan",[0,0,0],[180,0,0],[.5*t,.5*t,.5*t],[50/255,130/255,184/255,.8],11);return A.push(e),A}getMeshes(){return this._meshes}}class bA{constructor(A){this.eA=A,this._meshes=this.sA()}setCoordinate(A){this.eA=A}sA(){const A=[],t=340/177,e=CA("yuanhuan",[0,0,0],[0,0,0],[.5*t,.5*t,.5*t],[149/255,179/255,199/255,.5],12);return A.push(e),A}getMeshes(){return this._meshes}}class DA{constructor(A){this.eA=A,this._meshes=this.sA()}setCoordinate(A){this.eA=A}sA(){const A=[],t=CA("plane",[0,0,0],[0,0,0],[10,10,10],[1,0,0,.5],16);return A.push(t),A}getMeshes(){return this._meshes}}class yA{constructor(A){this.eA=A,this._meshes=this.sA()}setCoordinate(A){this.eA=A}sA(){const A=[],t=CA("xyzScale",[0,0,0],[0,0,0],[2,2,2],null,113);return A.push(t),A}getMeshes(){return this._meshes}}const BA=[],dA=[],pA=[],vA=[],MA=[],LA=[177/170,177/170,177/170],EA=[],OA=[1,2,3,4,12];class xA{constructor(){this.translate=new mA,this.rotation=new PA,this.scaling=new bA,this.planeHelper=new DA,this.xyzScaleHelper=new yA,this._meshes=this.sA(),this.nA=!0}sA(){const A={};A.translate=this.translate.getMeshes(),A.rotation=this.rotation.getMeshes(),A.scaling=this.scaling.getMeshes(),A.planeHelper=this.planeHelper.getMeshes(),A.xyzScale=this.xyzScaleHelper.getMeshes();const t=340/177,e=CA("yuanhuan41",[-2.745*t,2.745*t,0],[90,0,0],[.5*t,.5*t,.5*t],[149/255,179/255,199/255,.6],1),s=CA("yuanhuan41",[2.745*t,2.745*t,0],[-90,0,180],[.5*t,.5*t,.5*t],[50/255,130/255,184/255,.5],2),n=CA("yuanhuan41",[2.745*t,-2.745*t,0],[90,0,180],[.5*t,.5*t,.5*t],[149/255,179/255,199/255,.6],3),i=CA("yuanhuan41",[-2.745*t,-2.745*t,0],[-90,0,0],[.5*t,.5*t,.5*t],[50/255,130/255,184/255,.5],4),r=CA("yuanpan",[0,0,0],[90,0,0],[.5*t,.5*t,.5*t],[89/255,206/255,147/255,.5],5),o=CA("zzhou",[0,0,6.5],[90,0,0],[1,1,1],[14/255,127/255,191/255,1],6);return A.translate.push(e,s,n,i,r,o),A}updateMatrix(A,e,s,n,i){const r=e.getCoordinates(),o=A.coordinateToPointAtRes(r,A.getGLRes()),a=e.iA();t.vec3.set(dA,o.x,o.y,a);const h=t.vec3.copy(BA,i),I=QA(A,e.getTranslation());t.vec3.add(dA,dA,I),t.vec3.add(dA,dA,h);for(const i in this._meshes)for(let r=0;r<this._meshes[i].length;r++){const o=this._meshes[i][r];for(let r=0;r<o.length;r++){const a=o[r],h=a.getUniform("uPickingId"),I=t.vec3.copy(BA,a.translate);let c=t.vec3.copy(EA,a.rotation);const g=a.scaling;if(11===h&&(this.nA?(c[2]+=s,a.rotation[2]+=s):this.nA||(c[2]+=s,a.rotation[2]+=s,c[0]=360,c[2]-=90)),h>100&&1===e.getTargets().length&&(c=e.getTargets()[0].getRotation()),OA.indexOf(h)>-1)if(12!==h)g[0]+=n,g[1]+=n,g[2]+=n;else{const A=this._meshes.translate[4][0];g[0]=1.2*A.scaling[0],g[1]=1.2*A.scaling[0],g[2]=1.2*A.scaling[0]}let f=wA(e,A);if(f=t.vec3.set(pA,f,f,f),t.vec3.multiply(I,I,f),t.vec3.multiply(f,f,g),1===h||2===h||3===h||4===h){const A=t.vec3.multiply(MA,g,LA);t.vec3.multiply(I,I,A)}const u=t.quat.fromEuler(vA,c[0],c[1],c[2]);if(t.vec3.add(I,I,dA),"xyzScale"===i){const A=t.mat4.fromRotationTranslationScale([],u,I,f);t.mat4.multiply(a.localTransform,A,a.originTransform)}else t.mat4.fromRotationTranslationScale(a.localTransform,u,I,f)}}}getMeshes(A){const t={};return A?("xyzScale"===A?t[A]=this._meshes[A]:(t.translate=this._meshes.translate,"translate"!==A&&(t[A]=this._meshes[A])),t):t}rA(A){this.nA=A}dispose(){for(const A in this._meshes)for(let t=0;t<this._meshes[A].length;t++){const e=this._meshes[A][t];for(let A=0;A<e.length;A++){const t=e[A];t.geometry.dispose(),t.dispose()}}}}const FA=[],UA=[],VA=[],TA=new e.Point(0,0),SA=[],kA=[],_A=[],NA=[0,0,0];class RA{constructor(){this.oA=[],this.aA=[0,0,0],this.hA=[1,1,1],this.IA=[0,0,0]}cA(A){Array.isArray(A)?A.forEach((A=>{this.cA(A)})):(A.on("remove",this.gA,this),A.fA={coordinate:A.getCoordinates(),translation:A.getTranslation(),rotation:A.getRotation(),scale:A.getScale()},this.oA.push(A))}uA(){this.oA.forEach((A=>{A.off("remove",this.gA,this)})),this.oA=[]}CA(A,e,s,n,i,r,o){for(let o=0;o<this.oA.length;o++){const a=this.oA[o],h=a.getRotation(),I=a.getScale(),c=this.lA(r,a,n,s,e);let g=null;g=n>=0?n:n*(this.options&&this.options.scaleStrength||1);const f=t.vec3.add(_A,t.vec3.set(FA,g*I[0],g*I[1],g*I[2]),I),u=Math.min(...f);if(Math.abs(u)<i){const A=Math.abs(u);f[0]=f[0]*(i/A),f[1]=f[1]*(i/A),f[2]=f[2]*(i/A)}const C=t.vec3.add(h,s,h);a.setCoordinates(c),this.wA(A,f,I);const l=a.getTranslation();a.setTRS(l,C,f)}t.vec3.set(_A,n,n,n),t.vec3.add(this.IA,s,this.IA),t.vec3.add(this.hA,_A,this.hA),t.vec3.add(this.aA,e,this.aA),A.indexOf("translate")>-1?o.fire("positionchange",{action:A,type:"positionchange",target:this.oA,center:this.getCoordinates(),scale:this.hA,rotation:this.IA,translation:this.aA,deltaTranslate:e,deltaRotation:s,deltaScale:n}):o.fire("transforming",{action:A,type:"transforming",target:this.oA,center:this.oA[0].getTransformOrigin(),scale:this.hA,rotation:this.IA,translation:this.aA,deltaTranslate:e,deltaRotation:s,deltaScale:n})}lA(A,e,s,n,i){const r=e.getCenter(),o=e.getTransformOrigin(),a=A.getGLRes(),h=A.coordinateToPointAtRes(r,a,TA);h.z=A.altitudeToPoint(r.z,a),t.vec3.set(SA,h.x,h.y,h.z||0);const I=A.coordinateToPointAtRes(o,a,TA);I.z=A.altitudeToPoint(o.z,a),t.vec3.set(kA,I.x,I.y,I.z||0);const c=t.vec3.sub(FA,SA,kA),g=t.quat.fromEuler(UA,0,0,n[2]);t.vec3.set(_A,s+1,s+1,s+1);const f=t.mat4.fromRotationTranslationScale(VA,g,i,_A);t.vec3.transformMat4(c,c,f),t.vec3.add(c,c,kA),TA.set(c[0],c[1]);const u=A.pointAtResToCoordinate(TA,a);return u.z=c[2]/A.altitudeToPoint(1,a),u}wA(A,t,e){return"x-scale"===A&&(t[1]=e[1],t[2]=e[2]),"y-scale"===A&&(t[0]=e[0],t[2]=e[2]),"z-scale"===A&&(t[0]=e[0],t[1]=e[1]),t}QA(){this.oA.forEach((A=>{if(A.fA){const{coordinate:t,translation:e,rotation:s,scale:n}=A.fA;A.setCoordinates(t),A.setTRS(e,s,n)}}))}getScale(){return this.hA}getTranslation(){return 1===this.oA.length&&this.oA[0].getTranslation()||NA}getRotation(){return this.IA}mA(){return this.oA[0]?this.oA[0].getLayer():null}getCoordinates(){let A=0,t=0,s=0;const n=this.oA.length;if(!n)return null;for(let e=0;e<n;e++){const n=this.oA[e].getCenter();A+=n.x,t+=n.y,s+=n.z||0}A/=n,t/=n,s/=n;const i=new e.Coordinate(A,t,s);for(let A=0;A<n;A++)this.oA[A].setTransformOrigin(i);return i}gA(A){const t=A.target,e=this.oA.indexOf(t);e>-1&&(delete t.fA,this.oA.splice(e,1))}getTargets(){return this.oA}iA(){let A=0;const t=this.oA.length;for(let e=0;e<t;e++){A+=this.oA[e].getPointZ()}return A/=t,A}PA(){for(let A=0;A<this.oA.length;A++)if(this.oA[A].isVisible())return!0;return!1}}const HA=[5,6,7,8,9,10],JA=[5,7,8,9,10],KA=[2,4,11],jA=[1,3,12],zA=[12,16],GA=[1,2,3,4],ZA=[1,2,3,4,12],YA=[],qA=[],WA=[],XA=[],$A=[],At=[],tt=[];class et extends(e.Eventable(e.Handlerable(e.Class))){constructor(A={}){super(A),this.options=A,this.mouseAction="moving",this.bA=this.options.mode||"translate",this.DA=!0,this.TransformHelper=new xA,this.yA=new RA,this.helperScene=new t.reshader.Scene([]),this.addToMapCount=0}enable(){return this.DA=!0,this.layerRenderer&&this.layerRenderer.setToRedraw(),this}disable(){return this.DA=!1,this.layerRenderer&&this.layerRenderer.setToRedraw(),this.map&&this.map.resetCursor(),this}setMode(A){this.bA=A,this.BA(),this.layerRenderer&&this.layerRenderer.setToRedraw(),this.fire("modechange",{mode:A,type:"modechange"})}getMode(){return this.bA}isEnable(){return this.DA}dA(A){HA.indexOf(A)>-1?this.bA="translate":KA.indexOf(A)>-1?this.bA="rotation":jA.indexOf(A)>-1?this.bA="scaling":"xyzScale"!==this.bA&&(this.bA="translate")}pA(){return this.bA}addTo(A){this.map&&(this.vA(),console.warn("transform control has been added to a map, it suggest remove from the map before")),this.addToMapCount++,this.map=A,this.container=A.getContainer(),A.on("dom:mousemove",this.MA,this),A.on("dom:mousedown",this.LA,this),A.on("dom:mouseup",this.EA,this),A.on("zooming moving dragrotating",this.OA,this),this.xA()}remove(){this.map&&this.container&&this.layerRenderer&&(this.vA(),this.TransformHelper.dispose(),this.layerRenderer.setToRedraw(),delete this.map,delete this.layer,delete this.layerRenderer,delete this.container,delete this.yA)}vA(){this.container&&this.map&&(this.map.off("dom:mousemove",this.MA,this),this.map.off("dom:mousedown",this.LA,this),this.map.off("dom:mouseup",this.EA,this),this.map.off("zooming moving dragrotating",this.OA,this),this.layer&&this.layer.off("renderend",this.render,this))}MA(A){if(this.FA()){if(this.currentMousePosition={x:A.containerPoint.x,y:A.containerPoint.y},"moving"===this.mouseAction){const A=this.UA();this.currentPickingObject=this.VA(this.currentMousePosition,A,"meshes"),this.currentPickingObject&&null!=this.currentPickingObject.pickingId?(this.dA(this.currentPickingObject.pickingId),6===this.currentPickingObject.pickingId?this.TA(!0):this.TA(!1)):(this.TA(!1),this.dA()),this.SA()}this.kA(this.currentMousePosition)}}LA(A){if(!this.FA()||0!==A.domEvent.button)return;const t=this.UA();this.currentMousePosition={x:A.containerPoint.x,y:A.containerPoint.y},this._A=!0,this.currentPickingObject=this.VA(this.currentMousePosition,t,"meshes"),this.firstDownPoint=this.VA(this.currentMousePosition,t,"meshes"),this.currentPickingObject&&null!=this.currentPickingObject.meshId?(this.mouseAction="transform",this.NA(this.currentPickingObject.pickingId),this.map.config("zoomable",!1),this.map.config("draggable",!1),this.layerRenderer&&this.layerRenderer.setToRedraw()):(this.mouseAction="pan",this.map.config("zoomable",!0),this.map.config("draggable",!0),this.BA()),this.lastMousePosition=this.currentMousePosition,this.lastPickingObject=this.currentPickingObject,this.lastPickingMesh=t[this.currentPickingObject.meshId]}EA(){"transform"===this.mouseAction&&(this.firstDownPoint=null,this.BA(),this._A=!0,this.fire("transformend",{action:this.RA,type:"transformend"})),this.mouseAction="moving","xyzScale"!==this.bA&&(this.bA="translate"),this.map.config("zoomable",!0),this.map.config("draggable",!0),this.layerRenderer&&this.layerRenderer.setToRedraw()}OA(){const A=this.TransformHelper.planeHelper.getMeshes()[0][0],t=this.map.getBearing();A.rotation[2]=-t,this.HA()}HA(){this.FA()&&(this.TransformHelper.updateMatrix(this.map,this.yA,0,0,[0,0,0]),this._A=!0)}picked(A){if(!this.layerRenderer)return!1;const t=this.UA(),s=this.map;let n=A;A instanceof e.Point||(n=s.coordinateToContainerPoint(new e.Coordinate(A)));const i=this.VA(n,t,"picked");return!(!i||null===i.meshId)}BA(){const A=this.TransformHelper.getMeshes("scaling").scaling[0][0],t=340/177;A.scaling=[.6*t,.6*t,.6*t],this.layerRenderer&&(this.JA(A),this.KA())}KA(){this.TransformHelper._meshes.translate.forEach((A=>{for(let t=0;t<A.length;t++){const e=A[t];GA.indexOf(e.getUniform("uPickingId"))>-1&&e.material.set("color",e.originColor)}}))}JA(A){const e=this.yA.getCoordinates(),s=this.map.coordinateToPointAtRes(e,this.map.getGLRes()),n=[s.x,s.y,0],i=QA(this.map,this.yA.getTranslation());t.vec3.add(n,n,i);const r=t.vec3.copy([],A.translate),o=A.scaling;let a=wA(this.yA,this.map);a=t.vec3.set([],a,a,a),t.vec3.multiply(r,r,a),t.vec3.multiply(a,a,o),t.vec3.add(r,r,n),t.mat4.fromRotationTranslationScale(A.localTransform,[0,0,0,1],r,a);this.UA().forEach((A=>{const e=A.getUniform("uPickingId");if(1===e||3===e||2===e||4===e){const e=t.vec3.copy([],A.translate),s=170/177;A.scaling=[s,s,s];const i=A.scaling,r=A.rotation;let o=wA(this.yA,this.map);o=t.vec3.set([],o,o,o),t.vec3.multiply(e,e,o),t.vec3.multiply(o,o,i),t.vec3.add(e,e,n);const a=t.quat.fromEuler([],r[0],r[1],r[2]);t.mat4.fromRotationTranslationScale(A.localTransform,a,e,o)}}))}jA(A){const t=this.map.containerPointToCoordinate(A),e=this.map.coordinateToPointAtRes(t,this.map.getGLRes());return{point:[e.x,e.y]}}kA(A){if("transform"===this.mouseAction){const A=this.pA(),s=QA(this.map,this.yA.getTranslation()),n=this.yA.iA();let i=null,r=null;if(s[2]+n<.01&&"z-translate"!==this.RA)i=this.jA(this.currentMousePosition),r=this.jA(this.lastMousePosition);else{const A=this.TransformHelper.planeHelper.getMeshes()[0];if(i=this.VA(this.currentMousePosition,A,"plane"),r=this.VA(this.lastMousePosition,A,"plane"),!i||null===i.meshId||!r||null===r.meshId)return}const o=[0,0,0],a=[0,0,0];let h=0,I=0,c=0;if("translate"===A){if("xy-translate"===this.RA){const A=i.point[0]-r.point[0],t=i.point[1]-r.point[1];o[0]=A,o[1]=t}else if("x-translate"===this.RA){const A=i.point[0]-r.point[0];o[0]=A}else if("y-translate"===this.RA){const A=i.point[1]-r.point[1];o[1]=A}else if("z-translate"===this.RA){let A=0;if(this.zA()){const s=this.map.getGLRes(),n=this.map._pointAtResToContainerPoint(new e.Point(r.point[0],r.point[1]),s),o=this.map._pointAtResToContainerPoint(new e.Point(i.point[0],i.point[1]),s),a=t.vec2.length(t.vec2.set(XA,i.point[0]-r.point[0],i.point[1]-r.point[1]));A=o.y<n.y?a:-a}else A=i.point[2]-r.point[2];o[2]=A}}else if("rotation"===A)I=this.GA(i.point,r.point),I>=0?this.TransformHelper.rA(!0):this.TransformHelper.rA(!1),a[2]+=I;else if("scaling"===A||"xyzScale"===A){const A=this.ZA(),e=t.vec2.length(t.vec2.set(XA,this.firstDownPoint.point[0]-A[0],this.firstDownPoint.point[1]-A[1])),s=t.vec2.length(t.vec2.set(XA,r.point[0]-A[0],r.point[1]-A[1]));h=this.YA(i.point,r.point,A,s),c=this.YA(i.point,r.point,A,e)}this.TransformHelper.updateMatrix(this.map,this.yA,I,c,o),this.yA.CA(this.RA,o,a,h,.01,this.map,this)}this.lastMousePosition=A,this.lastPickingObject=this.currentPickingObject;const s=this.UA();this.lastPickingMesh=s[this.currentPickingObject.meshId]}YA(A,e,s,n,i){const r=(t.vec2.length(t.vec2.set(XA,A[0]-s[0],A[1]-s[1]))-t.vec2.length(t.vec2.set(XA,e[0]-s[0],e[1]-s[1])))/n;return i?(i[0]-.01)*r:r}ZA(){const A=this.map,e=this.yA.getCoordinates(),s=A.coordinateToPointAtRes(e,A.getGLRes()),n=t.vec3.set($A,s.x,s.y,0),i=QA(A,this.yA.getTranslation());return t.vec3.add(n,n,i),n}TA(A){const e=this.TransformHelper.planeHelper.getMeshes()[0][0],s=t.mat4.getTranslation(WA,e.localTransform),n=t.mat4.getScaling(qA,e.localTransform);let i=t.quat.fromEuler(YA,0,0,0);const r=this.map.getBearing();A&&!this.zA()?(i=t.quat.fromEuler(YA,90,0,-r),0===e.rotation[0]&&(this._A=!0),t.vec3.set(e.rotation,90,0,-r)):(90===e.rotation[0]&&(this._A=!0),t.vec3.set(e.rotation,0,0,-r)),t.mat4.fromRotationTranslationScale(e.localTransform,i,s,n)}zA(){if(this.map.getPitch())return!1;const A=this.map.cameraPosition,e=this.map.coordinateToPointAtRes(this.map.getCenter(),this.map.getGLRes());t.vec3.set(e,e.x,e.y,0);const s=this.yA.getCoordinates(),n=this.map.coordinateToPointAtRes(s,this.map.getGLRes()),i=QA(this.map,this.yA.getTranslation()),r=t.vec3.set(WA,n.x,n.y,0),o=t.vec3.add(r,r,i),a=t.vec3.subtract([],A,o),h=t.vec3.subtract([],A,e);return t.vec3.angle(a,h)<1/180*Math.PI}SA(){const A=this.UA();if(this.currentPickingObject&&null!=this.currentPickingObject.meshId){this.qA(),this.lastPickingObject&&null!=this.lastPickingObject.meshId&&this.lastPickingObject.meshId!==this.currentPickingObject.meshId&&this.WA();const t=A[this.currentPickingObject.meshId];if(t&&zA.indexOf(this.currentPickingObject.pickingId)<0)if(this.currentPickingObject.pickingId>100)this.XA(t);else{const A=[t.originColor[0],t.originColor[1],t.originColor[2],.8];t.material.set("color",A),this.$A(t,.5)}this.layerRenderer.setToRedraw()}else this.lastPickingObject&&null!=this.lastPickingObject.meshId&&(this.map.resetCursor(),this.WA(),this.layerRenderer.setToRedraw())}XA(A){const t=[1,179/255,2/255,1];A.material.set("color",t),A.properties.relatedMeshes&&A.properties.relatedMeshes.forEach((A=>{A.material.set("color",t)}))}qA(){6===this.currentPickingObject.pickingId?this.map.setCursor("ns-resize"):JA.indexOf(this.currentPickingObject.pickingId)>-1?this.map.setCursor("move"):this.map.setCursor("pointer")}WA(){const A=this.lastPickingMesh;if(!A)return;const t=A.getUniform("uPickingId"),e=this.UA();JA.indexOf(t)>-1?e.forEach((A=>{JA.indexOf(A.getUniform("uPickingId"))>-1&&A.material.set("color",A.originColor)})):ZA.indexOf(t)>-1?e.forEach((A=>{const t=A.getUniform("uPickingId");GA.indexOf(t)>-1&&A.material.set("color",A.originColor)})):11===t&&e.forEach((A=>{GA.indexOf(A.getUniform("uPickingId"))>-1&&A.material.set("color",A.originColor)})),A.material.set("color",A.originColor),A.properties.relatedMeshes&&A.properties.relatedMeshes.forEach((A=>{A.material.set("color",A.originColor)}))}$A(A,t){const e=A.getUniform("uPickingId"),s=this.UA();JA.indexOf(e)>-1?s.forEach((e=>{if(JA.indexOf(e.getUniform("uPickingId"))>-1&&e.getUniform("uPickingId")!==A.getUniform("uPickingId")){const A=[e.originColor[0],e.originColor[1],e.originColor[2],t];e.material.set("color",A)}})):"scaling"===this.bA?s.forEach((A=>{const t=A.getUniform("uPickingId");if(1===t||3===t||2===t||4===t){const t=[149/255,179/255,199/255,.8];A.material.set("color",t)}})):"rotation"===this.bA&&s.forEach((A=>{const t=A.getUniform("uPickingId");if(1===t||3===t||2===t||4===t){const t=A.originColor;A.material.set("color",[t[0],t[1],t[2],0])}}))}reset(){this.map&&this.yA&&(this.yA.QA(),this.TransformHelper.updateMatrix(this.map,this.yA,0,0,[0,0,0]))}GA(A,e){const s=this.ZA(),n=t.vec2.set(At,e[0]-s[0],e[1]-s[1]),i=t.vec2.set(tt,A[0]-s[0],A[1]-s[1]),r=Math.atan2(n[1],n[0]);return(Math.atan2(i[1],i[0])-r)/Math.PI*180}NA(A){return this.RA=113===A||114===A?"x-scale":115===A||116===A?"z-scale":117===A||118===A?"y-scale":119===A?"xyz-scale":5===A?"xy-translate":6===A?"z-translate":7===A||9===A?"x-translate":8===A||10===A?"y-translate":11===A?"z-rotate":"scale",this.RA}transform(A){if(!A)return;if(this.layerRenderer&&this.layerRenderer.layer&&(this.layerRenderer.layer.off("renderend",this.render),this.layerRenderer.layer.off("resizeCanvas",this.At)),!this.map)return void console.error("should add to a target first");if(this.yA&&(this.yA.uA(),this.yA.cA(A)),!this.yA.getTargets().length)return;const t=this.map;this.TransformHelper.updateMatrix(t,this.yA,0,0,[0,0,0]),this.tt(),this._A=!0}getTransformTarget(){return this.yA}gA(){delete this.yA}tt(){const A=this.yA.mA();A&&(A.off("renderend",this.render),A.off("resizeCanvas",this.At));const e=this.map.getLayers();let s=null;for(let A=0;A<e.length;A++)if(e[A]instanceof t.GroupGLLayer){s=e[A];break}if(!s)return;const n=s.getLayers(),i=n.indexOf(A);if(i<0)return;n.splice(i,1),n.push(A);const r=this.map,o=A.getRenderer();this.layerRenderer=o,this.regl=o.regl,this.renderer=o.renderer,this.et=this.layerRenderer.getFBORayPicking(),this.st={projViewMatrix:r.projViewMatrix,projMatrix:r.projMatrix,viewMatrix:r.viewMatrix,pointSize:1},A.on("renderend",this.render,this),A.on("resizeCanvas",this.At,this),o.setToRedraw()}At(){this.et.clear(),this._A=!0}VA(A,t,e){const s=this.map;if(!(s&&this.et&&this.layerRenderer&&this.layerRenderer.canvas))return null;const n=s.getDevicePixelRatio(),i=A.x*n,r=A.y*n,o=this.st,a=this.layerRenderer.canvas.gl&&this.layerRenderer.canvas.gl.wrap;(this._A||a||!this.nt||this.nt!==e)&&(this.et.render(t,o,!0),this.nt=e,this._A=!1);return this.et.pick(i,r,10,o,{viewMatrix:this.map.viewMatrix,projMatrix:this.map.projMatrix,returnPoint:!0})}xA(){const A=this.map.getDevicePixelRatio(),e={x:0,y:0,width:()=>this.map?this.map.width*A:1,height:()=>this.map?this.map.height*A:1};this.it=new t.reshader.MeshShader({vert:"attribute vec3 aPosition;\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main()\n\n{\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n\n\n}\n\n",frag:"precision mediump float;\n\nuniform vec4 color;\n\n\n\nvoid main() {\n\n gl_FragColor = color;\n\n}\n\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:function(A,e){return t.mat4.multiply([],e.projViewMatrix,e.modelMatrix)}}],extraCommandProps:{viewport:e,depth:{enable:!0,func:"always",mask:!0,range:[0,0]},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"}},defines:{}})}render(){if(!this.FA())return;const A=this.UA();this.helperScene.setMeshes(A);const t=this.layerRenderer.getFrameContext();if(t&&t.renderTarget&&this.layerRenderer.getFrameTimestamp()!==t.timestamp)return;this.HA(),this.it.filter=t&&t.sceneFilter;const e=t&&t.renderTarget&&t.renderTarget.fbo;this.renderer.render(this.it,this.st,this.helperScene,e)}UA(){let A=[];const t=this.TransformHelper.getMeshes(this.bA);for(const e in t){if("translate"===e)continue;const s=t[e];for(let t=0;t<s.length;t++)A=A.concat(s[t])}const e=t.translate;if(e)for(let t=0;t<e.length;t++)A=A.concat(e[t]);return A}FA(){const A=this.layerRenderer,t=A&&A.layer;return A&&this.yA&&t&&t.isVisible()&&this.yA.PA()&&this.regl&&this.DA}}et.mergeOptions({scaleStrength:2}),A.TransformControl=et,"undefined"!=typeof console&&console.log("@maptalks/transform-control v0.98.0")}));
|
|
12
|
+
let P=0;function b(A){return null==A}function D(A){return!b(A)}function y(A){return!b(A)&&("string"==typeof A||null!==A.constructor&&A.constructor===String)}function B(A){for(let t=1;t<arguments.length;t++){const e=arguments[t];for(const t in e)A[t]=e[t]}return A}function d(A){switch(A){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: "+A)}function p(A){return 0===A.indexOf("data:")&&A.indexOf("base64,")>0}function v(A){const t=function(A){return"undefined"!=typeof self?self.atob(A):window.atob(A)}(A.substring(A.indexOf(",")+1)),e=t.length,s=new Uint8Array(e);for(let A=0;A<e;A++)s[A]=t.charCodeAt(A);return s.buffer}const M=[],L=[],E=[],O=[0,0,0],x=function(A){return A[0]=0,A[1]=0,A[2]=0,A[3]=1,A}([]),F=[1,1,1];function U(A,t,e,s,n,i,r){const o=d(r),a=o.BYTES_PER_ELEMENT;if((0===n||n===s*a)&&i%a==0){const n=new o(t,i,e*s);return A.set(n),A}0===n&&(n=s*a);const h=new Uint8Array(s*a);for(let r=0;r<e;r++){let e=null;const I=new Uint8Array(t,n*r+i,s*a);h.set(I),e=new o(h.buffer,0,s);for(let t=0;t<s;t++)A[r*s+t]=e[t]}return A}const V="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function T(A,t,e){const s=new Uint8Array(A,t,e);return V.decode(s)}const S={get:function(A,t={},e){t||(t={});const s=new AbortController,n=s.signal,i=B({},t);i.signal=n,i.method||(i.method="GET"),i.referrerPolicy=i.referrerPolicy||"origin","undefined"==typeof window||i.referrer||(i.referrer=window.location.href),e&&(A=e(A));const r=fetch(A,i).then((A=>{const e=this.A(A,t.responseType);return e.message?e:e.then((e=>"arraybuffer"===t.responseType?{data:e,cacheControl:A.headers.get("Cache-Control"),expires:A.headers.get("Expires"),contentType:A.headers.get("Content-Type")}:e)).catch((A=>{if(!A.code||A.code!==DOMException.ABORT_ERR)throw A}))})).catch((A=>{if(!A.code||A.code!==DOMException.ABORT_ERR)throw A}));return r.xhr=s,r},A:(A,t)=>200!==A.status?{status:A.status,statusText:A.statusText,message:`incorrect http request with status code(${A.status}): ${A.statusText}`}:"arraybuffer"===t?A.arrayBuffer():"json"===t?A.json():A.text(),getArrayBuffer:(A,t={},e)=>(t||(t={}),t.responseType="arraybuffer",S.get(A,t,e)),getJSON:function(A,t={},e){return t&&t.jsonp?S.jsonp(A):((t=t||{}).responseType="json",S.get(A,t,e))},jsonp:function(A){const t="_maptalks_jsonp_"+P++;A.match(/\?/)?A+="&callback="+t:A+="?callback="+t;let e=document.createElement("script");return e.type="text/javascript",e.src=A,new Promise((A=>{window[t]=function(s){document.getElementsByTagName("head")[0].removeChild(e),e=null,delete window[t],A(s)},document.getElementsByTagName("head")[0].appendChild(e)}))}};class k{constructor(A,t,e,s,n){this.t=A,this.decoders=t,this.i=e,this.images={},this.o={},this.h=s||{},this.I=n}requestImageFromBufferURI(A,t,e){if(this.buffers[A.id]){const s=this.buffers[A.id],n=this.u(t,s);return this.getImageByBuffer(n,e)}if(this.o[A.id])return this.o[A.id].then((()=>{const s=this.buffers[A.id],n=this.u(t,s);return this.getImageByBuffer(n,e)}));if(p(A.uri)){const s=this.buffers[A.id]=v(A.uri),n=this.u(t,s);return this.getImageByBuffer(n,e)}let s;const n=A.uri.indexOf("blob:")>=0;return s=A.uri.indexOf("://")>0||n?A.uri:this.rootPath+"/"+A.uri,this.o[A.id]=S.getArrayBuffer(s,this.h,this.I).then((s=>{const n=this.buffers[A.id]=s.data,i=this.u(t,n);return this.getImageByBuffer(i,e)}))}getImageByBuffer(A,t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const e=this.decoders;return e[t.mimeType]?e[t.mimeType](A,{supportedFormats:this.i}):"image/crn"===t.mimeType||"image/ktx2"===t.mimeType||"image/cttf"===t.mimeType?(console.warn("missing transcoder for "+t.mimeType,", visit https://maptalks.com/docs/transcoders for details"),Promise.resolve(null)):this.C(t.id,A)}requestExternalImage(A){if(this.images[A.id])return Promise.resolve(this.images[A.id]);const t=0===A.uri.indexOf("data:image/")?A.uri:this.rootPath+"/"+A.uri;return this.o[A.id]?this.o[A.id].then((()=>this.images[A.id])):this.o[A.id]=this.C(A.id,t)}C(A,t){return new Promise(((e,s)=>{let n=t;this.I&&(n=this.I(t)),this.t(n,this.h,((n,i)=>{n?s(n):(URL.revokeObjectURL(t),this.images[A]=i,e(this.images[A]))}))}))}}const _=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],N=[];class R{constructor(A,t,e,s,n){this.rootPath=A,this.gltf=t,this.l=!1,this.glbBuffer=e,this.buffers={},this.requests={},this.accessors={},this.m(),this.h=s,this.I=n}P(A,t){const e=this.gltf,s=e.accessors[t];if(void 0===s.bufferView)return this.accessors[s.id]=this.D(A,t,null,0),Promise.resolve(this.accessors[s.id]);if(s&&this.accessors[s.id])return Promise.resolve(this.accessors[s.id]);const n=e.bufferViews[s.bufferView];return this.B(n).then((e=>{const{buffer:n,byteOffset:i}=e;return this.accessors[s.id]=this.D(A,t,n,i)}))}B(A){const t=this.gltf.buffers[A.buffer];if(this.buffers[t.id]){const A=this.buffers[t.id];return Promise.resolve({buffer:A,byteOffset:0})}if(this.requests[t.id])return this.requests[t.id].then((()=>{const A=this.buffers[t.id];return Promise.resolve({buffer:A,byteOffset:0})}));if("binary_glTF"!==A.buffer&&"KHR_binary_glTF"!==A.buffer&&t.uri){if(p(t.uri)){const A=this.buffers[t.id]=v(t.uri);return Promise.resolve({buffer:A,byteOffset:0})}let A;const e=t.uri.indexOf("blob:")>=0;return A=t.uri.indexOf("://")>0||e?t.uri:this.rootPath+"/"+t.uri,this.requests[t.id]=S.getArrayBuffer(A,this.h,!e&&this.I).then((s=>(e&&URL.revokeObjectURL(A),{buffer:this.buffers[t.id]=s.data,byteOffset:0})))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}D(A,t,e,s=0){const n=this.gltf,i=n.accessors[t],r=void 0!==i.bufferView?n.bufferViews[i.bufferView]:{},o=(r.byteOffset||0)+s,a=this.p(i.type),h=d(i.componentType),I=r.byteStride||0,c={array:void 0,name:A,accessorName:t,byteLength:i.count*a*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:a,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(c.min=i.min),i.max&&(c.max=i.max),e)if(this.l)c.byteStride=I,c.byteOffset=o+(i.byteOffset||0),!I||I===a*h.BYTES_PER_ELEMENT||"indices"===A||"input"===A||"output"===A||A.indexOf("morph")>=0?(c.array=this.v(e,i.count,a,o+(i.byteOffset||0),h),c.array.buffer.byteLength===c.byteLength&&(c.byteOffset=0)):c.array=new Uint8Array(e,o,r.byteLength);else if(i.interleaved){c.byteStride=0,c.byteOffset=0;const A=new h(i.count*a);if(c.array=U(A,e,i.count,a,I,o+(i.byteOffset||0),i.componentType),c.extensions&&c.extensions.WEB3D_quantized_attributes&&a>2){const A=new Float32Array(c.array.length),{decodeMatrix:t}=c.extensions.WEB3D_quantized_attributes;for(let e=0;e<c.array.length;e+=a){N[0]=c.array[e],N[1]=c.array[e+1],N[2]=c.array[e+2],N[3]=1;const s=C(N,N,t);A[e]=s[0],A[e+1]=s[1],A[e+2]=s[2]}c.componentType=5126,c.array=A}}else c.byteStride=0,c.array=this.v(e,i.count,a,o+(i.byteOffset||0),h),c.byteOffset=c.array.byteOffset;else{c.array=new h(i.count);const A=c.min||c.max;A&&(c.array[0]=A[0],c.array[1]=A[1],c.array[2]=A[2])}return c}m(){const A=this.gltf.accessors;if(Array.isArray(A))for(let t=0;t<A.length;t++)for(let e=0;e<A.length;e++)t!==e&&A[t].bufferView===A[e].bufferView&&(A[t].interleaved=A[e].interleaved=!0);else for(const t in A)for(const e in A)t!==e&&A[t].bufferView===A[e].bufferView&&(A[t].interleaved=A[e].interleaved=!0)}v(A,t,e,s,n){return s%n.BYTES_PER_ELEMENT!=0&&(A=A.slice(s,s+t*e*n.BYTES_PER_ELEMENT),s=0),new n(A,s,e*t)}p(A){const t=_.indexOf(A);return _[t+1]}requestKHRTechniquesWebgl(A){const{shaders:t}=A,e=t.map((A=>{if(void 0!==A.bufferView){const t=this.gltf.bufferViews[A.bufferView],{byteLength:e}=t;return this.B(t).then((s=>{const{buffer:n,byteOffset:i}=s,r=T(n,i+(t.byteOffset||0),e);return A.content=r,A}))}if(A.uri){if(p(A.uri)){const t=v(A.uri),e=T(t,0,t.byteLength);return A.content=e,Promise.resolve(A)}{const t=this.rootPath+"/"+A.uri;return S.get(t,this.h,this.I).then((t=>(A.content=t,A)))}}return Promise.resolve(A)}));return Promise.all(e).then((()=>A))}}class H extends k{constructor(A,t,e,s,n,i,r,o){super(s,n,i,r,o),this.rootPath=A,this.gltf=t,this.requests={},this.buffers={},this.glbBuffer=e,this.accessor=new R(A,t,e,r,o)}iterate(A,t){const e=this.gltf[t];if(!e)return;let s=0;for(const t in e)A(t,e[t],s++)}createNode(A){const t={};if(D(A.name)&&(t.name=A.name),D(A.children)&&(t.children=A.children),D(A.jointName)&&(t.jointName=A.jointName),D(A.matrix)&&(t.matrix=A.matrix),D(A.rotation)&&(t.rotation=A.rotation),D(A.scale)&&(t.scale=A.scale),D(A.translation)&&(t.translation=A.translation),D(A.extras)&&(t.extras=A.extras),D(A.meshes)&&(t.mesh=A.meshes[0]),t.translation||t.rotation||t.scale){const A=function(A,t){if(t.matrix)return t.matrix;if(t.translation||t.scale||t.rotation){const e=function(A,t){return A[0]=1,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=1,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1,A[11]=0,A[12]=t[0],A[13]=t[1],A[14]=t[2],A[15]=1,A}(M,t.translation||O),s=function(A,t){var e=t[0],s=t[1],n=t[2],i=t[3],r=e+e,o=s+s,a=n+n,h=e*r,I=s*r,c=s*o,g=n*r,f=n*o,u=n*a,C=i*r,l=i*o,w=i*a;return A[0]=1-c-u,A[1]=I+w,A[2]=g-l,A[3]=0,A[4]=I-w,A[5]=1-h-u,A[6]=f+C,A[7]=0,A[8]=g+l,A[9]=f-C,A[10]=1-h-c,A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(L,t.rotation||x),n=function(A,t){return A[0]=t[0],A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=t[1],A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=t[2],A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(E,t.scale||F);return o(n,s,n),o(A,e,n)}return function(A){return A[0]=1,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=1,A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1,A[11]=0,A[12]=0,A[13]=0,A[14]=0,A[15]=1,A}(A)}([],t);delete t.translation,delete t.rotation,delete t.scale,t.matrix=A}return t}M(A){const t={};for(const e in A){const s=A[e];let n,i;s.instanceTechnique&&s.instanceTechnique.values?(n=s.instanceTechnique,i=n.values.diffuse):(n=s,i=n.values.tex||n.values.diffuseTex||n.values.diffuse);const r={baseColorTexture:{index:i}};s.name&&(r.name=s.name),s.extensions&&(r.extensions=s.extensions),s.extras&&(r.extras=s.extras),t[e]=r}return t}L(A){if(A.bufferView||A.extensions&&(A.extensions.KHR_binary_glTF||A.extensions.binary_glTF)){const t=A.bufferView?A:A.extensions.KHR_binary_glTF||A.extensions.binary_glTF;A.extensions&&(A.mimeType=t.mimeType,A.width=t.width,A.height=t.height);const e=this.gltf.bufferViews[t.bufferView],s=(e.byteOffset||0)+this.glbBuffer.byteOffset,n=e.byteLength,i=this.buffers[t.bufferView]=new Uint8Array(this.glbBuffer.buffer,s,n);return this.getImageByBuffer(i,A)}return this.requestExternalImage(A)}O(A){const t=this.gltf.textures[A];if(!t)return null;const e=this.gltf.images[t.source];return this.L(e).then((A=>{const s=this.gltf.samplers[t.sampler];return{image:{array:A.data,width:A.width,height:A.height,index:t.source,mimeType:e.mimeType,name:e.name,extras:e.extras},sampler:s}}))}getBaseColorTexture(A){const t=this.gltf.materials[A];let e,s;if(t.instanceTechnique&&t.instanceTechnique.values?(e=t.instanceTechnique,s=e.values.diffuse):(e=t,s=e.values.tex||e.values.diffuseTex||e.values.diffuse),void 0===s||void 0===this.gltf.textures)return null;const n=this.gltf.textures[s];if(!n)return null;const i=this.gltf.samplers[n.sampler];return{format:n.format||6408,internalFormat:n.internalFormat||6408,type:n.type||5121,sampler:i,source:this.gltf.images[n.source]}}getMaterial(){return null}getAnimations(){return null}}const J=9729;class K extends k{constructor(A,t,e,s,n,i,r,o){super(s,n,i,r,o),this.rootPath=A,this.gltf=t,this.glbBuffer=e,this.buffers={},this.requests={},this.accessor=new R(A,t,e,r,o)}iterate(A,t){const e=this.gltf[t];if(e)for(let t=0;t<e.length;t++)A(t,e[t],t)}createNode(A){const t={};return B(t,A),!D(A.weights)&&this.gltf.meshes&&D(t.mesh)?t.weights=this.gltf.meshes[t.mesh].weights:A.weights&&(t.weights=A.weights),t}O(A){const t=this.gltf.textures[A];if(!t)return null;let e=t.source;if(t.extensions&&t.extensions.EXT_texture_webp&&(e=t.extensions.EXT_texture_webp.source),!D(e))return null;const s=this.gltf.images[e];return this.L(s).then((A=>{if(!A)return null;const e={image:{array:A.data,mipmap:A.mipmap,width:A.width,height:A.height,index:t.source,mimeType:s.mimeType,name:s.name,extensions:s.extensions,extras:s.extras}};B(e,t);const n=D(t.sampler)?this.gltf.samplers[t.sampler]:void 0;if(n&&(e.sampler=n,e.sampler.magFilter=n.magFilter||J,e.sampler.minFilter=n.minFilter||J,e.sampler.wrapS=n.wrapS||10497,e.sampler.wrapT=n.wrapT||10497),!e.mipmap&&e.sampler.minFilter!==J&&9728!==e.sampler.minFilter){const A=e.sampler.minFilter;e.sampler.minFilter=9984===A||9986===A?9728:J}return A.format&&(e.format=A.format),e}))}L(A){if(!D(A.bufferView))return this.requestExternalImage(A);{const t=this.gltf.bufferViews[A.bufferView],e=this.gltf.buffers[t.buffer];if(e.uri)return this.requestImageFromBufferURI(e,t,A);if(this.glbBuffer)return this.F(t,A)}return null}F(A,t){const e=this.u(A,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(e,t)}u(A,t,e){e=e||0;const s=(A.byteOffset||0)+e,n=A.byteLength;return new Uint8Array(t,s,n)}U(A,t){const e=new Array(A.byteLength);for(let t=0;t<A.byteLength;t++)e[t]=String.fromCharCode(A[t]);e.join("");const s="data:"+(t=t||"image/png")+";base64,"+function(A){return"undefined"!=typeof self?self.btoa(A):window.btoa(A)}(unescape(encodeURIComponent(e)));return s}getAnimations(A){const t=[];return A.forEach((A=>{t.push(this.getSamplers(A.samplers))})),Promise.all(t).then((t=>{for(let e=0;e<t.length;e++)A[e].samplers=t[e];return A}))}getSamplers(A){const t=[];for(let e=0;e<A.length;e++)(D(A[e].input)||D(A[e].output))&&(t.push(this.accessor.P("input",A[e].input)),t.push(this.accessor.P("output",A[e].output)));return Promise.all(t).then((t=>{for(let e=0;e<t.length/2;e++)A[e].input=t[2*e],A[e].output=t[2*e+1],A[e].interpolation||(A[e].interpolation="LINEAR");return A}))}}const j="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class z{static read(A,t=0,e=0){e||(e=A.byteLength);const s=new DataView(A,t,e),n=s.getUint32(4,!0);if(1===n)return z.readV1(s,t);if(2===n)return z.readV2(A,t);throw new Error("Unsupported glb version : "+n)}static readV1(A,t){const e=A.getUint32(8,!0),s=A.getUint32(12,!0);if(e!==A.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const n=G(A.buffer,20+t,s);return{json:JSON.parse(n),glbBuffer:{byteOffset:20+t+s,buffer:A.buffer,byteLength:e}}}static readV2(A,t){let e,s,n;const i=new DataView(A,t+12);let r=0;for(;r<i.byteLength;){const o=i.getUint32(r,!0);r+=4;const a=i.getUint32(r,!0);if(r+=4,1313821514===a)e=G(A,t+12+r,o);else if(5130562===a){n=t+12+r,s=o;break}r+=o}return{json:JSON.parse(e),glbBuffer:{byteOffset:n,buffer:A,byteLength:s}}}}function G(A,t,e){if(j){const s=new Uint8Array(A,t,e);return j.decode(s)}return function(A){const t=A.length;let e="";for(let s=0;s<t;){let n=A[s++];if(128&n){let e=Z[n>>3&7];if(!(64&n)||!e||s+e>t)return null;for(n&=63>>e;e>0;e-=1){const t=A[s++];if(128!=(192&t))return null;n=n<<6|63&t}}e+=String.fromCharCode(n)}return e}(new Uint8Array(A,t,e))}const Z=[1,1,1,1,2,2,3,0],Y=[0,0,0],q=[0,0,0,1],W=[1,1,1],X={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},$={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},AA={V(A,t,e,s,n,i,r,o){const a=D(A)?t.animations:[t.animations[0]],h={};for(let t=0;t<a.length;t++){const c=a[t],g=c.name||t;if(D(A)&&g!==A)continue;const f=c.channelsMap[e];if(f)for(let A=0;A<f.length;A++){const t=f[A];"translation"===t.target.path?(this.T(n,c.samplers[t.sampler],s,1),h.translation=I(Y,n)):"rotation"===t.target.path?(this.S(i,c.samplers[t.sampler],s,1),h.rotation=m(q,i)):"scale"===t.target.path?(this.T(r,c.samplers[t.sampler],s,1),h.scale=I(W,r)):"weights"===t.target.path&&o&&(this.T(o,c.samplers[t.sampler],s,o.length),h.weights=o)}}return h},T(A,t,e,s){switch(t.interpolation){case"LINEAR":{const n=this.k($,t,e,1*s);n&&(A=function(A,t,e,s){for(let n=0;n<A.length;n++)A[n]=t[n]+s*(e[n]-t[n]);return A}(A,n.PREVIOUS,n.NEXT,n.INTERPOLATION));break}case"STEP":{const n=this.k($,t,e,1*s);n&&(A=function(A,t){for(let e=0;e<A.length;e++)A[e]=t[e];return A}(A,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this.k($,t,e,3*s);n&&(A=this._(A,n,t.input.array,3*s));break}}return A},S(A,t,e){switch(t.interpolation){case"LINEAR":{const s=this.k($,t,e,1);s&&w(A,s.PREVIOUS,s.NEXT,s.INTERPOLATION);break}case"STEP":{const s=this.k($,t,e,1);s&&(A=u(A,...s.PREVIOUS));break}case"CUBICSPLINE":{const s=this.k($,t,e,3);if(s){for(let A=0;A<s.PREVIOUS.length;A++)s.PREVIOUS[A]=Math.acos(s.PREVIOUS[A]),s.NEXT[A]=Math.acos(s.NEXT[A]);A=this._(A,s,t.input.array,3);for(let t=0;t<A.length;t++)A[t]=Math.cos(A[t])}break}}return A},N(A,t){const e=A.length;let s,n,i,r=0,o=e-1,a=Math.floor((r+o)/2);for(;r<=e-1&&o>=0;){if(r===o)return null;if(A[a]<=t&&t<=A[a+1]){const e=A[a];return s=a,n=a+1,i=(t-e)/(A[a+1]-e),{preIndx:s,nextIndex:n,interpolation:i}}t<A[a]?(o=a,a=Math.floor((r+o)/2)):A[a+1]<t&&(r=a,a=Math.floor((r+o)/2))}return null},k(A,t,e,s){const n=t.input.array,i=t.output.array,r=t.output.itemSize;(e<n[0]||e>n[n.length-1])&&(e=Math.max(n[0],Math.min(n[n.length-1],e))),e===n[n.length-1]&&(e=n[0]);const o=this.N(n,e);if(!o||!o.nextIndex)return null;const{preIndx:a,nextIndex:h,interpolation:I}=o;A.PREINDEX=a,A.NEXTINDEX=h,A.INTERPOLATION=I;const c=r*s;return A.PREVIOUS=i.subarray(A.PREINDEX*c,(A.PREINDEX+1)*c),A.NEXT=i.subarray(A.NEXTINDEX*c,(A.NEXTINDEX+1)*c),A},_(A,t,e,s){const n=t.INTERPOLATION,i=e[t.PREINDEX],r=e[t.NEXTINDEX];for(let e=0;e<3;e++){const o=t.PREVIOUS[s+e],a=(r-i)*t.PREVIOUS[2*s+e],h=t.NEXT[3+e],I=(r-i)*t.NEXT[e],c=(2*Math.pow(n,3)-3*Math.pow(n,2)+1)*o+(Math.pow(n,3)-2*Math.pow(n,2)+n)*a+(2*-Math.pow(n,3)+3*Math.pow(n,2))*h+(Math.pow(n,3)-Math.pow(n,2))*I;A[e]=c}return A},getAnimationClip(A,t,e,s){const n=A.nodes[t]&&A.nodes[t].weights;return c(Y,...X.TRANSLATION),u(q,...X.ROTATION),c(W,...X.SCALE),this.V(s,A,t,e,Y,q,W,n)},getTimeSpan(A){if(!A.animations)return null;if(A.timeSpan)return A.timeSpan;const t=A.animations;return A.timeSpan={},t.forEach(((t,e)=>{let s=-1/0,n=1/0;const i=t.channels;for(let A=0;A<i.length;A++){const e=i[A],r=t.samplers[e.sampler].input.array;r[r.length-1]>s&&(s=r[r.length-1]),r[0]<n&&(n=r[0])}const r=t.name||e;A.timeSpan[r]={max:s,min:n}})),A.timeSpan},getTimeSpanByName(A,t){const e=this.getTimeSpan(A);return e?D(t)?e[t]:e[Object.keys(e)[0]]:null}};let tA=!1;if("undefined"!=typeof OffscreenCanvas){let A;try{A=new OffscreenCanvas(2,2).getContext("2d")}catch(A){}A&&"undefined"!=typeof createImageBitmap&&(tA=!0)}const eA="undefined"==typeof document?null:document.createElement("canvas");class sA{constructor(A,t,e){if(this.options=e||{},this.options.decoders||(this.options.decoders={}),this.h=this.options.fetchOptions||{},t.buffer instanceof ArrayBuffer){const{json:e,glbBuffer:s}=z.read(t.buffer,t.byteOffset,t.byteLength);this.R(A,e,s)}else this.R(A,t);this.H=new R(this.rootPath,this.gltf,this.glbBuffer,this.h,this.options.urlModifier),this.J()}J(){const A=this.gltf.extensionsRequired;if(A){if(A.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(A.indexOf("KHR_texture_basisu")>=0&&!this.options.decoders["image/ktx2"])throw new Error("KHR_texture_basisu is required but @maptalks/transcoders.ktx2 is not loaded");if(A.indexOf("EXT_meshopt_compression")>=0)throw new Error("EXT_meshopt_compression extension is not supported yet.")}}K(){const A=this.gltf.extensions;return A&&A.KHR_techniques_webgl?this.H.requestKHRTechniquesWebgl(A.KHR_techniques_webgl).then((t=>(A.KHR_techniques_webgl=t,A))):Promise.resolve(A)}load(A){A=A||{};const t=this.j(A),e=this.G(),s=this.Z(),n=this.K();return Promise.all([t,e,s,n]).then((A=>(A[0].animations=A[1],A[0].textures=A[2],A[0].extensions=A[3],A[0].transferables=this.transferables||[],this.createChannelsMap(A[0]),A[0])))}createChannelsMap(A){const t=A.animations;if(t)for(let A=0;A<t.length;A++){const e=t[A];e.channelsMap={};for(let A=0;A<e.channels.length;A++){const t=e.channels[A];e.channelsMap[t.target.node]||(e.channelsMap[t.target.node]=[]),e.channelsMap[t.target.node].push(t)}}}getExternalResources(){const A=[];if(this.gltf){const{buffers:t,images:e}=this.gltf;for(let e=0;e<t.length;e++)t[e].uri&&t[e].uri.indexOf("data:application/octet-stream;base64")<0&&A.push({type:"buffer",uri:t[e].uri});for(let t=0;t<e.length;t++)e[t].uri&&e[t].uri.indexOf("data:image/")<0&&A.push({type:"image",uri:e[t].uri})}return A}static getAnimationClip(A,t,e,s){return AA.getAnimationClip(A,t,e,s)}static getAnimationTimeSpan(A,t){return AA.getTimeSpanByName(A,t)}static getTypedArrayCtor(A){return d(A)}static readInterleavedArray(A,t,e,s,n,i,r){return U(A,t,e,s,n,i,r)}R(A,t,e){this.gltf=t,this.glbBuffer=e,this.version=t.asset?+t.asset.version:1,this.rootPath=A,this.buffers={},this.requests={},this.options.requestImage=tA?IA.bind(this):this.options.requestImage||nA,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new K(A,t,e,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.h,this.options.urlModifier),this.adapter.iterate(((A,t,e)=>{t.id="buffer_"+e}),"buffers"),this.adapter.iterate(((A,t,e)=>{t.id="image_"+e}),"images"),this.adapter.iterate(((A,t,e)=>{t.id="accessor_"+e}),"accessors")):(this.adapter=new H(A,t,e,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this.h,this.options.urlModifier),this.adapter.iterate(((A,t,e)=>{t.id="accessor_"+e}),"accessors"),this.adapter.iterate(((A,t,e)=>{t.id="image_"+e}),"images"))}Y(A,t){if(A.children&&A.children.length>0){if(!("number"==typeof(e=A.children[0])&&isFinite(e)||y(A.children[0])))return A;const s=A.children.map((A=>{const e=t[A];return e.nodeIndex=A,this.Y(e,t)}));A.children=s}var e;return A}j(A){return this.q(A).then((A=>{const t=this.scenes=[];let e;for(const t in A)A[t]=this.Y(A[t],A),A[t].nodeIndex=Number(t)?Number(t):t;this.adapter.iterate(((s,n,i)=>{const r={};n.name&&(r.name=n.name),n.nodes&&(r.nodes=n.nodes.map((t=>A[t]))),this.gltf.scene===s&&(e=i),t.push(r)}),"scenes");const s={textures:this.gltf.textures,asset:this.gltf.asset,scene:e,scenes:t,nodes:A,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(s.extensions=this.gltf.extensions),1===this.version){const A=this.adapter.M(this.gltf.materials);s.materials=A}return delete this.gltf.buffers,s.json=this.gltf,s}))}q(A){return this.W(A).then((()=>{const A=this.nodes={};return this.adapter.iterate(((t,e)=>{const s=this.adapter.createNode(e,this.meshes,this.skins);A[t]=s}),"nodes"),A}))}X(){this.skins=[];const A=[];return this.adapter.iterate(((t,e,s)=>{A.push(this.$(e).then((A=>{A.index=s,this.skins.push(A)})))}),"skins"),A}$(A){const t=A.inverseBindMatrices;return this.adapter.accessor.P("inverseBindMatrices",t).then((t=>(A.inverseBindMatrices=t,t&&t.buffer&&this.transferables&&this.transferables.indexOf(t.buffer)<0&&this.transferables.push(t.buffer),A)))}G(){const A=this.gltf.animations;return D(A)?this.adapter.getAnimations(A):null}W(A){this.meshes={};let t=[];return this.adapter.iterate(((e,s,n)=>{t.push(this.AA(s,A).then((A=>{A.index=n,this.meshes[e]=A})))}),"meshes"),t=t.concat(this.X()),Promise.all(t)}AA(A,t){const e=A.primitives.map((A=>this.tA(A,t))).filter((A=>!!A));return Promise.all(e).then((t=>{const e={};return B(e,A),e.primitives=t,e}))}Z(){const A=this.gltf.textures;if(!A)return null;const t=[];for(const e in A)t.push(this.adapter.O(e));return Promise.all(t).then((t=>{if(this.transferables)for(let A=0;A<t.length;A++){const e=t[A]&&t[A].image.array;if(e){let A;A=e instanceof ImageBitmap?e:e.buffer,A&&this.transferables.indexOf(A)<0&&this.transferables.push(A)}}if(!Array.isArray(A)){const e={},s=Object.keys(A);for(let A=0;A<t.length;A++)t[A]&&(e[s[A]]=t[A]);return e}return t}))}tA(A,t){let e;const s=[],n=A.extensions;if(D(A.targets))for(let t=0;t<A.targets.length;t++){const e=A.targets[t];for(const A in e){const n=this.adapter.accessor.P(`morphTargets_${A}_${t}`,e[A]);n&&s.push(n)}}if(n&&n.KHR_draco_mesh_compression){if(!this.options.decoders.draco&&(!this.gltf.extensionsRequired||!this.gltf.extensionsRequired.indexOf("KHR_draco_mesh_compression")<0))return null;const A=this.options.decoders.draco,{bufferView:i,attributes:r}=n.KHR_draco_mesh_compression,o=this.gltf.bufferViews[i],a=this.H.B(o).then((e=>{const{buffer:s,byteOffset:n}=e;let{byteOffset:i}=o;const a=o.byteLength;i||(i=0);const h=new DataView(s,n+i,a),I={attributes:r,useUniqueIDs:!1,skipAttributeTransform:t.skipAttributeTransform};return A(h,I).then((A=>{const t=Object.values(A.attributes);return A.indices&&t.push(A.indices),t}))}));s.push(a),e=Promise.all(s)}else{const t=A.attributes;for(const A in t){const e=this.adapter.accessor.P(A,t[A]);e&&s.push(e)}if(D(A.indices)){const t=this.adapter.accessor.P("indices",A.indices);t&&s.push(t)}e=Promise.all(s)}return e.then((t=>{if(n&&n.KHR_draco_mesh_compression){const e=A.targets?A.targets.length:0;t[e]=t[e].concat(t.slice(0,e)),t=t[e]}let e,s;const i={attributes:t.reduce(((A,t)=>{if("indices"===t.name)e=t;else if(t.name.indexOf("morphTargets_")>-1)s=s||{},s[t.name.slice(13)]=t;else{if(!("POSITION"!==t.name||t.min&&t.max)){const A=[1/0,1/0,1/0],e=[-1/0,-1/0,-1/0],{itemSize:s,array:n}=t,i=n.length/s;for(let t=0;t<i;t++)for(let i=0;i<s;i++){const r=t*s+i;n[r]<A[i]&&(A[i]=n[r]),n[r]>e[i]&&(e[i]=n[r])}if(t.quantization){const s=t.quantization,n=s.range/(1<<s.quantizationBits),i=s.minValues;f(A,A,n),g(A,A,i),f(e,e,n),g(e,e,i)}t.min=A,t.max=e}A[t.name]=t}return this.transferables&&t.array.buffer&&this.transferables.indexOf(t.array.buffer)<0&&this.transferables.push(t.array.buffer),A}),{}),material:A.material};return e&&(i.indices=e),s&&(i.morphTargets=s),i.mode=D(A.mode)?A.mode:4,D(A.extras)&&(i.extras=A.extras),i}))}}function nA(A,t,e){const s=new Image;s.crossOrigin="",s.onload=()=>{if(!eA)return void e(new Error("There is no canvas to draw image!"));eA.width=s.width,eA.height=s.height;const A=eA.getContext("2d",{willReadFrequently:!0});A.drawImage(s,0,0,s.width,s.height);const t=A.getImageData(0,0,s.width,s.height),n={width:s.width,height:s.height,data:new Uint8Array(t.data)};e(null,n)},s.onerror=function(A){e(A)},s.src=A}const iA=[],rA=[],oA=10;let aA,hA;function IA(A,t,e){aA||(aA=new OffscreenCanvas(2,2),hA=aA.getContext("2d",{willReadFrequently:!0}));let s=null;if(y(A))this.options.urlModifier&&(A=this.options.urlModifier(A)),iA.push([A,t,e,this]),cA();else{const t=new Blob([A]);s=createImageBitmap(t),s.then(gA.bind(this)).then((A=>{e(null,A)})).catch((A=>{console.warn(A),e(A)}))}}function cA(){if(!iA.length||rA.length>oA)return;const A=iA.shift(),[t,e,s,n]=A;rA.push(A),fetch(t,e).then((A=>A.arrayBuffer())).then((A=>{const t=new Blob([new Uint8Array(A)]);return createImageBitmap(t)})).then(gA.bind(n)).then((t=>{s.call(n,null,t);const e=rA.indexOf(A);rA.splice(e,1),cA()})).catch((t=>{console.warn(t),s.call(n,t);const e=rA.indexOf(A);rA.splice(e,1),cA()}))}function gA(A){let{width:t,height:e}=A;fA(t)||(t=uA(t)),fA(e)||(e=uA(e));const s=this.options.maxTextureSize;s&&(t=Math.min(s,t),e=Math.min(s,e)),aA.width=t,aA.height=e,hA.drawImage(A,0,0,t,e),A.close();const n=hA.getImageData(0,0,t,e);return{width:t,height:e,data:new Uint8Array(n.data)}}function fA(A){return!(A&A-1)&&0!==A}function uA(A){return Math.pow(2,Math.floor(Math.log(A)/Math.LN2))}function CA(A,e,s,n,r,o){const a=[],h=t.quat.fromEuler([],s[0],s[1],s[2]),I=t.mat4.fromRotationTranslationScale([],h,e,n),c=function(A){return new sA("",JSON.parse(JSON.stringify(i[A]))).load().then((A=>A))}(A);return c.then((A=>{t.reshader.GLTFHelper.exportGLTFPack(A).getMeshesInfo().forEach(((A,i)=>{const h=new t.reshader.Material({color:r||A.materialInfo.baseColorFactor}),c=new t.reshader.Mesh(A.geometry,h);c.setUniform("uPickingId",o+i);const g=c.getDefines();g.HAS_PICKING_ID=2,c.setDefines(g),c.translate=e,c.rotation=s,c.scaling=n,t.mat4.multiply(c.localTransform,I,A.nodeMatrix),c.originTransform=t.mat4.copy([],c.localTransform),c.originColor=r||A.materialInfo.baseColorFactor,a.push(c)})),o>100&&(a[0].properties.relatedMeshes=a.slice(1,2),a[1].properties.relatedMeshes=a.slice(0,1),a[2].properties.relatedMeshes=a.slice(3,4),a[3].properties.relatedMeshes=a.slice(2,3),a[4].properties.relatedMeshes=a.slice(5,6),a[5].properties.relatedMeshes=a.slice(4,5),a[6].properties.relatedMeshes=a.slice(0,6))})),a}function lA(A,t){return Math.abs(A)*Math.sign(t)}function wA(A,e){const s=A.getCoordinates(),i=e.coordinateToPointAtRes(s,e.getGLRes()),r=[i.x,i.y,0],o=QA(e,A.getTranslation());t.vec3.add(r,r,o);const a=function(A,t,e,s){return A._pointAtResToContainerPoint(t,e,s)}(e,new n.Point(r[0],r[1]),e.getGLRes());a.x+=85;const h=function(A,t,e,s){{const s=A.containerPointToCoordinate(t);return A.coordinateToPointAtRes(s,e)}}(e,a,e.getGLRes());return Math.sqrt(Math.pow(h.x-r[0],2)+Math.pow(h.y-r[1],2))/5.272881136101205}function QA(A,e){if(!A)return e;const s=A.distanceToPointAtRes(e[0],e[1],A.getGLRes()),n=A.altitudeToPoint(e[2],A.getGLRes());return t.vec3.set([],lA(s.x,e[0]),lA(s.y,e[1]),lA(n,e[2]))}class mA{constructor(A){this.eA=A,this._meshes=this.sA()}setCoordinate(A){this.eA=A}sA(){const A=[],t=340/177,e=CA("jiantou",[1.2*t,0,0],[0,0,90],[t,t,t],[89/255,206/255,147/255,0],7),s=CA("jiantou",[0,1.2*t,0],[0,0,180],[t,t,t],[89/255,206/255,147/255,0],8),n=CA("jiantou",[-1.2*t,0,0],[0,0,270],[t,t,t],[89/255,206/255,147/255,0],9),i=CA("jiantou",[0,-1.2*t,0],[0,0,0],[t,t,t],[89/255,206/255,147/255,0],10);return A.push(e,s,n,i),A}getMeshes(){return this._meshes}}class PA{constructor(A){this.eA=A,this._meshes=this.sA()}setCoordinate(A){this.eA=A}sA(){const A=[],t=340/177,e=CA("xuanzhuan",[0,0,0],[180,0,0],[.5*t,.5*t,.5*t],[50/255,130/255,184/255,.8],11);return A.push(e),A}getMeshes(){return this._meshes}}class bA{constructor(A){this.eA=A,this._meshes=this.sA()}setCoordinate(A){this.eA=A}sA(){const A=[],t=340/177,e=CA("yuanhuan",[0,0,0],[0,0,0],[.5*t,.5*t,.5*t],[149/255,179/255,199/255,.5],12);return A.push(e),A}getMeshes(){return this._meshes}}class DA{constructor(A){this.eA=A,this._meshes=this.sA()}setCoordinate(A){this.eA=A}sA(){const A=[],t=CA("plane",[0,0,0],[0,0,0],[10,10,10],[1,0,0,.5],16);return A.push(t),A}getMeshes(){return this._meshes}}class yA{constructor(A){this.eA=A,this._meshes=this.sA()}setCoordinate(A){this.eA=A}sA(){const A=[],t=CA("xyzScale",[0,0,0],[0,0,0],[2,2,2],null,113);return A.push(t),A}getMeshes(){return this._meshes}}const BA=[],dA=[],pA=[],vA=[],MA=[],LA=[177/170,177/170,177/170],EA=[],OA=[1,2,3,4,12];class xA{constructor(){this.translate=new mA,this.rotation=new PA,this.scaling=new bA,this.planeHelper=new DA,this.xyzScaleHelper=new yA,this._meshes=this.sA(),this.nA=!0}sA(){const A={};A.translate=this.translate.getMeshes(),A.rotation=this.rotation.getMeshes(),A.scaling=this.scaling.getMeshes(),A.planeHelper=this.planeHelper.getMeshes(),A.xyzScale=this.xyzScaleHelper.getMeshes();const t=340/177,e=CA("yuanhuan41",[-2.745*t,2.745*t,0],[90,0,0],[.5*t,.5*t,.5*t],[149/255,179/255,199/255,.6],1),s=CA("yuanhuan41",[2.745*t,2.745*t,0],[-90,0,180],[.5*t,.5*t,.5*t],[50/255,130/255,184/255,.5],2),n=CA("yuanhuan41",[2.745*t,-2.745*t,0],[90,0,180],[.5*t,.5*t,.5*t],[149/255,179/255,199/255,.6],3),i=CA("yuanhuan41",[-2.745*t,-2.745*t,0],[-90,0,0],[.5*t,.5*t,.5*t],[50/255,130/255,184/255,.5],4),r=CA("yuanpan",[0,0,0],[90,0,0],[.5*t,.5*t,.5*t],[89/255,206/255,147/255,.5],5),o=CA("zzhou",[0,0,6.5],[90,0,0],[1,1,1],[14/255,127/255,191/255,1],6);return A.translate.push(e,s,n,i,r,o),A}updateMatrix(A,e,s,n,i){const r=e.getCoordinates(),o=A.coordinateToPointAtRes(r,A.getGLRes()),a=e.iA();t.vec3.set(dA,o.x,o.y,a);const h=t.vec3.copy(BA,i),I=QA(A,e.getTranslation());t.vec3.add(dA,dA,I),t.vec3.add(dA,dA,h);for(const i in this._meshes)for(let r=0;r<this._meshes[i].length;r++){const o=this._meshes[i][r];for(let r=0;r<o.length;r++){const a=o[r],h=a.getUniform("uPickingId"),I=t.vec3.copy(BA,a.translate);let c=t.vec3.copy(EA,a.rotation);const g=a.scaling;if(11===h&&(this.nA?(c[2]+=s,a.rotation[2]+=s):this.nA||(c[2]+=s,a.rotation[2]+=s,c[0]=360,c[2]-=90)),h>100&&1===e.getTargets().length&&(c=e.getTargets()[0].getRotation()),OA.indexOf(h)>-1)if(12!==h)g[0]+=n,g[1]+=n,g[2]+=n;else{const A=this._meshes.translate[4][0];g[0]=1.2*A.scaling[0],g[1]=1.2*A.scaling[0],g[2]=1.2*A.scaling[0]}let f=wA(e,A);if(f=t.vec3.set(pA,f,f,f),t.vec3.multiply(I,I,f),t.vec3.multiply(f,f,g),1===h||2===h||3===h||4===h){const A=t.vec3.multiply(MA,g,LA);t.vec3.multiply(I,I,A)}const u=t.quat.fromEuler(vA,c[0],c[1],c[2]);if(t.vec3.add(I,I,dA),"xyzScale"===i){const A=t.mat4.fromRotationTranslationScale([],u,I,f);t.mat4.multiply(a.localTransform,A,a.originTransform)}else t.mat4.fromRotationTranslationScale(a.localTransform,u,I,f)}}}getMeshes(A){const t={};return A?("xyzScale"===A?t[A]=this._meshes[A]:(t.translate=this._meshes.translate,"translate"!==A&&(t[A]=this._meshes[A])),t):t}rA(A){this.nA=A}dispose(){for(const A in this._meshes)for(let t=0;t<this._meshes[A].length;t++){const e=this._meshes[A][t];for(let A=0;A<e.length;A++){const t=e[A];t.geometry.dispose(),t.dispose()}}}}const FA=[],UA=[],VA=[],TA=new e.Point(0,0),SA=[],kA=[],_A=[],NA=[0,0,0];class RA{constructor(){this.oA=[],this.aA=[0,0,0],this.hA=[1,1,1],this.IA=[0,0,0]}cA(A){Array.isArray(A)?A.forEach((A=>{this.cA(A)})):(A.on("remove",this.gA,this),A.fA={coordinate:A.getCoordinates(),translation:A.getTranslation(),rotation:A.getRotation(),scale:A.getScale()},this.oA.push(A))}uA(){this.oA.forEach((A=>{A.off("remove",this.gA,this)})),this.oA=[]}CA(A,e,s,n,i,r,o){for(let o=0;o<this.oA.length;o++){const a=this.oA[o],h=a.getRotation(),I=a.getScale(),c=this.lA(r,a,n,s,e);let g=null;g=n>=0?n:n*(this.options&&this.options.scaleStrength||1);const f=t.vec3.add(_A,t.vec3.set(FA,g*I[0],g*I[1],g*I[2]),I),u=Math.min(...f);if(Math.abs(u)<i){const A=Math.abs(u);f[0]=f[0]*(i/A),f[1]=f[1]*(i/A),f[2]=f[2]*(i/A)}const C=t.vec3.add(h,s,h);a.setCoordinates(c),this.wA(A,f,I);const l=a.getTranslation();a.setTRS(l,C,f)}t.vec3.set(_A,n,n,n),t.vec3.add(this.IA,s,this.IA),t.vec3.add(this.hA,_A,this.hA),t.vec3.add(this.aA,e,this.aA),A.indexOf("translate")>-1?o.fire("positionchange",{action:A,type:"positionchange",target:this.oA,center:this.getCoordinates(),scale:this.hA,rotation:this.IA,translation:this.aA,deltaTranslate:e,deltaRotation:s,deltaScale:n}):o.fire("transforming",{action:A,type:"transforming",target:this.oA,center:this.oA[0].getTransformOrigin(),scale:this.hA,rotation:this.IA,translation:this.aA,deltaTranslate:e,deltaRotation:s,deltaScale:n})}lA(A,e,s,n,i){const r=e.getCenter(),o=e.getTransformOrigin(),a=A.getGLRes(),h=A.coordinateToPointAtRes(r,a,TA);h.z=A.altitudeToPoint(r.z,a),t.vec3.set(SA,h.x,h.y,h.z||0);const I=A.coordinateToPointAtRes(o,a,TA);I.z=A.altitudeToPoint(o.z,a),t.vec3.set(kA,I.x,I.y,I.z||0);const c=t.vec3.sub(FA,SA,kA),g=t.quat.fromEuler(UA,0,0,n[2]);t.vec3.set(_A,s+1,s+1,s+1);const f=t.mat4.fromRotationTranslationScale(VA,g,i,_A);t.vec3.transformMat4(c,c,f),t.vec3.add(c,c,kA),TA.set(c[0],c[1]);const u=A.pointAtResToCoordinate(TA,a);return u.z=c[2]/A.altitudeToPoint(1,a),u}wA(A,t,e){return"x-scale"===A&&(t[1]=e[1],t[2]=e[2]),"y-scale"===A&&(t[0]=e[0],t[2]=e[2]),"z-scale"===A&&(t[0]=e[0],t[1]=e[1]),t}QA(){this.oA.forEach((A=>{if(A.fA){const{coordinate:t,translation:e,rotation:s,scale:n}=A.fA;A.setCoordinates(t),A.setTRS(e,s,n)}}))}getScale(){return this.hA}getTranslation(){return 1===this.oA.length&&this.oA[0].getTranslation()||NA}getRotation(){return this.IA}mA(){return this.oA[0]?this.oA[0].getLayer():null}getCoordinates(){let A=0,t=0,s=0;const n=this.oA.length;if(!n)return null;for(let e=0;e<n;e++){const n=this.oA[e].getCenter();A+=n.x,t+=n.y,s+=n.z||0}A/=n,t/=n,s/=n;const i=new e.Coordinate(A,t,s);for(let A=0;A<n;A++)this.oA[A].setTransformOrigin(i);return i}gA(A){const t=A.target,e=this.oA.indexOf(t);e>-1&&(delete t.fA,this.oA.splice(e,1))}getTargets(){return this.oA}iA(){let A=0;const t=this.oA.length;for(let e=0;e<t;e++){A+=this.oA[e].getPointZ()}return A/=t,A}PA(){for(let A=0;A<this.oA.length;A++)if(this.oA[A].isVisible())return!0;return!1}}const HA=[5,6,7,8,9,10],JA=[5,7,8,9,10],KA=[2,4,11],jA=[1,3,12],zA=[12,16],GA=[1,2,3,4],ZA=[1,2,3,4,12],YA=[],qA=[],WA=[],XA=[],$A=[],At=[],tt=[];class et extends(e.Eventable(e.Handlerable(e.Class))){constructor(A={}){super(A),this.options=A,this.mouseAction="moving",this.bA=this.options.mode||"translate",this.DA=!0,this.TransformHelper=new xA,this.yA=new RA,this.helperScene=new t.reshader.Scene([]),this.addToMapCount=0}enable(){return this.DA=!0,this.layerRenderer&&this.layerRenderer.setToRedraw(),this}disable(){return this.DA=!1,this.layerRenderer&&this.layerRenderer.setToRedraw(),this.map&&this.map.resetCursor(),this}setMode(A){this.bA=A,this.BA(),this.layerRenderer&&this.layerRenderer.setToRedraw(),this.fire("modechange",{mode:A,type:"modechange"})}getMode(){return this.bA}isEnable(){return this.DA}dA(A){HA.indexOf(A)>-1?this.bA="translate":KA.indexOf(A)>-1?this.bA="rotation":jA.indexOf(A)>-1?this.bA="scaling":"xyzScale"!==this.bA&&(this.bA="translate")}pA(){return this.bA}addTo(A){this.map&&(this.vA(),console.warn("transform control has been added to a map, it suggest remove from the map before")),this.addToMapCount++,this.map=A,this.container=A.getContainer(),A.on("dom:mousemove",this.MA,this),A.on("dom:mousedown",this.LA,this),A.on("dom:mouseup",this.EA,this),A.on("zooming moving dragrotating",this.OA,this),this.xA()}remove(){this.map&&this.container&&this.layerRenderer&&(this.vA(),this.TransformHelper.dispose(),this.layerRenderer.setToRedraw(),delete this.map,delete this.layer,delete this.layerRenderer,delete this.container,delete this.yA)}vA(){this.container&&this.map&&(this.map.off("dom:mousemove",this.MA,this),this.map.off("dom:mousedown",this.LA,this),this.map.off("dom:mouseup",this.EA,this),this.map.off("zooming moving dragrotating",this.OA,this),this.layer&&this.layer.off("renderend",this.render,this))}MA(A){if(this.FA()){if(this.currentMousePosition={x:A.containerPoint.x,y:A.containerPoint.y},"moving"===this.mouseAction){const A=this.UA();this.currentPickingObject=this.VA(this.currentMousePosition,A,"meshes"),this.currentPickingObject&&null!=this.currentPickingObject.pickingId?(this.dA(this.currentPickingObject.pickingId),6===this.currentPickingObject.pickingId?this.TA(!0):this.TA(!1)):(this.TA(!1),this.dA()),this.SA()}this.kA(this.currentMousePosition)}}LA(A){if(!this.FA()||0!==A.domEvent.button)return;const t=this.UA();this.currentMousePosition={x:A.containerPoint.x,y:A.containerPoint.y},this._A=!0,this.currentPickingObject=this.VA(this.currentMousePosition,t,"meshes"),this.firstDownPoint=this.VA(this.currentMousePosition,t,"meshes"),this.currentPickingObject&&null!=this.currentPickingObject.meshId?(this.mouseAction="transform",this.NA(this.currentPickingObject.pickingId),this.map.config("zoomable",!1),this.map.config("draggable",!1),this.layerRenderer&&this.layerRenderer.setToRedraw()):(this.mouseAction="pan",this.map.config("zoomable",!0),this.map.config("draggable",!0),this.BA()),this.lastMousePosition=this.currentMousePosition,this.lastPickingObject=this.currentPickingObject,this.lastPickingMesh=t[this.currentPickingObject.meshId]}EA(){"transform"===this.mouseAction&&(this.firstDownPoint=null,this.BA(),this._A=!0,this.fire("transformend",{action:this.RA,type:"transformend"})),this.mouseAction="moving","xyzScale"!==this.bA&&(this.bA="translate"),this.map.config("zoomable",!0),this.map.config("draggable",!0),this.layerRenderer&&this.layerRenderer.setToRedraw()}OA(){const A=this.TransformHelper.planeHelper.getMeshes()[0][0],t=this.map.getBearing();A.rotation[2]=-t,this.HA()}HA(){this.FA()&&(this.TransformHelper.updateMatrix(this.map,this.yA,0,0,[0,0,0]),this._A=!0)}picked(A){if(!this.layerRenderer)return!1;const t=this.UA(),s=this.map;let n=A;A instanceof e.Point||(n=s.coordinateToContainerPoint(new e.Coordinate(A)));const i=this.VA(n,t,"picked");return!(!i||null===i.meshId)}BA(){const A=this.TransformHelper.getMeshes("scaling").scaling[0][0],t=340/177;A.scaling=[.6*t,.6*t,.6*t],this.layerRenderer&&(this.JA(A),this.KA())}KA(){this.TransformHelper._meshes.translate.forEach((A=>{for(let t=0;t<A.length;t++){const e=A[t];GA.indexOf(e.getUniform("uPickingId"))>-1&&e.material.set("color",e.originColor)}}))}JA(A){const e=this.yA.getCoordinates(),s=this.map.coordinateToPointAtRes(e,this.map.getGLRes()),n=[s.x,s.y,0],i=QA(this.map,this.yA.getTranslation());t.vec3.add(n,n,i);const r=t.vec3.copy([],A.translate),o=A.scaling;let a=wA(this.yA,this.map);a=t.vec3.set([],a,a,a),t.vec3.multiply(r,r,a),t.vec3.multiply(a,a,o),t.vec3.add(r,r,n),t.mat4.fromRotationTranslationScale(A.localTransform,[0,0,0,1],r,a);this.UA().forEach((A=>{const e=A.getUniform("uPickingId");if(1===e||3===e||2===e||4===e){const e=t.vec3.copy([],A.translate),s=170/177;A.scaling=[s,s,s];const i=A.scaling,r=A.rotation;let o=wA(this.yA,this.map);o=t.vec3.set([],o,o,o),t.vec3.multiply(e,e,o),t.vec3.multiply(o,o,i),t.vec3.add(e,e,n);const a=t.quat.fromEuler([],r[0],r[1],r[2]);t.mat4.fromRotationTranslationScale(A.localTransform,a,e,o)}}))}jA(A){const t=this.map.containerPointToCoordinate(A),e=this.map.coordinateToPointAtRes(t,this.map.getGLRes());return{point:[e.x,e.y]}}kA(A){if("transform"===this.mouseAction){const A=this.pA(),s=QA(this.map,this.yA.getTranslation()),n=this.yA.iA();let i=null,r=null;if(s[2]+n<.01&&"z-translate"!==this.RA)i=this.jA(this.currentMousePosition),r=this.jA(this.lastMousePosition);else{const A=this.TransformHelper.planeHelper.getMeshes()[0];if(i=this.VA(this.currentMousePosition,A,"plane"),r=this.VA(this.lastMousePosition,A,"plane"),!i||null===i.meshId||!r||null===r.meshId)return}const o=[0,0,0],a=[0,0,0];let h=0,I=0,c=0;if("translate"===A){if("xy-translate"===this.RA){const A=i.point[0]-r.point[0],t=i.point[1]-r.point[1];o[0]=A,o[1]=t}else if("x-translate"===this.RA){const A=i.point[0]-r.point[0];o[0]=A}else if("y-translate"===this.RA){const A=i.point[1]-r.point[1];o[1]=A}else if("z-translate"===this.RA){let A=0;if(this.zA()){const s=this.map.getGLRes(),n=this.map._pointAtResToContainerPoint(new e.Point(r.point[0],r.point[1]),s),o=this.map._pointAtResToContainerPoint(new e.Point(i.point[0],i.point[1]),s),a=t.vec2.length(t.vec2.set(XA,i.point[0]-r.point[0],i.point[1]-r.point[1]));A=o.y<n.y?a:-a}else A=i.point[2]-r.point[2];o[2]=A}}else if("rotation"===A)I=this.GA(i.point,r.point),I>=0?this.TransformHelper.rA(!0):this.TransformHelper.rA(!1),a[2]+=I;else if("scaling"===A||"xyzScale"===A){const A=this.ZA(),e=t.vec2.length(t.vec2.set(XA,this.firstDownPoint.point[0]-A[0],this.firstDownPoint.point[1]-A[1])),s=t.vec2.length(t.vec2.set(XA,r.point[0]-A[0],r.point[1]-A[1]));h=this.YA(i.point,r.point,A,s),c=this.YA(i.point,r.point,A,e)}this.TransformHelper.updateMatrix(this.map,this.yA,I,c,o),this.yA.CA(this.RA,o,a,h,.01,this.map,this)}this.lastMousePosition=A,this.lastPickingObject=this.currentPickingObject;const s=this.UA();this.lastPickingMesh=s[this.currentPickingObject.meshId]}YA(A,e,s,n,i){const r=(t.vec2.length(t.vec2.set(XA,A[0]-s[0],A[1]-s[1]))-t.vec2.length(t.vec2.set(XA,e[0]-s[0],e[1]-s[1])))/n;return i?(i[0]-.01)*r:r}ZA(){const A=this.map,e=this.yA.getCoordinates(),s=A.coordinateToPointAtRes(e,A.getGLRes()),n=t.vec3.set($A,s.x,s.y,0),i=QA(A,this.yA.getTranslation());return t.vec3.add(n,n,i),n}TA(A){const e=this.TransformHelper.planeHelper.getMeshes()[0][0],s=t.mat4.getTranslation(WA,e.localTransform),n=t.mat4.getScaling(qA,e.localTransform);let i=t.quat.fromEuler(YA,0,0,0);const r=this.map.getBearing();A&&!this.zA()?(i=t.quat.fromEuler(YA,90,0,-r),0===e.rotation[0]&&(this._A=!0),t.vec3.set(e.rotation,90,0,-r)):(90===e.rotation[0]&&(this._A=!0),t.vec3.set(e.rotation,0,0,-r)),t.mat4.fromRotationTranslationScale(e.localTransform,i,s,n)}zA(){if(this.map.getPitch())return!1;const A=this.map.cameraPosition,e=this.map.coordinateToPointAtRes(this.map.getCenter(),this.map.getGLRes());t.vec3.set(e,e.x,e.y,0);const s=this.yA.getCoordinates(),n=this.map.coordinateToPointAtRes(s,this.map.getGLRes()),i=QA(this.map,this.yA.getTranslation()),r=t.vec3.set(WA,n.x,n.y,0),o=t.vec3.add(r,r,i),a=t.vec3.subtract([],A,o),h=t.vec3.subtract([],A,e);return t.vec3.angle(a,h)<1/180*Math.PI}SA(){const A=this.UA();if(this.currentPickingObject&&null!=this.currentPickingObject.meshId){this.qA(),this.lastPickingObject&&null!=this.lastPickingObject.meshId&&this.lastPickingObject.meshId!==this.currentPickingObject.meshId&&this.WA();const t=A[this.currentPickingObject.meshId];if(t&&zA.indexOf(this.currentPickingObject.pickingId)<0)if(this.currentPickingObject.pickingId>100)this.XA(t);else{const A=[t.originColor[0],t.originColor[1],t.originColor[2],.8];t.material.set("color",A),this.$A(t,.5)}this.layerRenderer.setToRedraw()}else this.lastPickingObject&&null!=this.lastPickingObject.meshId&&(this.map.resetCursor(),this.WA(),this.layerRenderer.setToRedraw())}XA(A){const t=[1,179/255,2/255,1];A.material.set("color",t),A.properties.relatedMeshes&&A.properties.relatedMeshes.forEach((A=>{A.material.set("color",t)}))}qA(){6===this.currentPickingObject.pickingId?this.map.setCursor("ns-resize"):JA.indexOf(this.currentPickingObject.pickingId)>-1?this.map.setCursor("move"):this.map.setCursor("pointer")}WA(){const A=this.lastPickingMesh;if(!A)return;const t=A.getUniform("uPickingId"),e=this.UA();JA.indexOf(t)>-1?e.forEach((A=>{JA.indexOf(A.getUniform("uPickingId"))>-1&&A.material.set("color",A.originColor)})):ZA.indexOf(t)>-1?e.forEach((A=>{const t=A.getUniform("uPickingId");GA.indexOf(t)>-1&&A.material.set("color",A.originColor)})):11===t&&e.forEach((A=>{GA.indexOf(A.getUniform("uPickingId"))>-1&&A.material.set("color",A.originColor)})),A.material.set("color",A.originColor),A.properties.relatedMeshes&&A.properties.relatedMeshes.forEach((A=>{A.material.set("color",A.originColor)}))}$A(A,t){const e=A.getUniform("uPickingId"),s=this.UA();JA.indexOf(e)>-1?s.forEach((e=>{if(JA.indexOf(e.getUniform("uPickingId"))>-1&&e.getUniform("uPickingId")!==A.getUniform("uPickingId")){const A=[e.originColor[0],e.originColor[1],e.originColor[2],t];e.material.set("color",A)}})):"scaling"===this.bA?s.forEach((A=>{const t=A.getUniform("uPickingId");if(1===t||3===t||2===t||4===t){const t=[149/255,179/255,199/255,.8];A.material.set("color",t)}})):"rotation"===this.bA&&s.forEach((A=>{const t=A.getUniform("uPickingId");if(1===t||3===t||2===t||4===t){const t=A.originColor;A.material.set("color",[t[0],t[1],t[2],0])}}))}reset(){this.map&&this.yA&&(this.yA.QA(),this.TransformHelper.updateMatrix(this.map,this.yA,0,0,[0,0,0]))}GA(A,e){const s=this.ZA(),n=t.vec2.set(At,e[0]-s[0],e[1]-s[1]),i=t.vec2.set(tt,A[0]-s[0],A[1]-s[1]),r=Math.atan2(n[1],n[0]);return(Math.atan2(i[1],i[0])-r)/Math.PI*180}NA(A){return this.RA=113===A||114===A?"x-scale":115===A||116===A?"z-scale":117===A||118===A?"y-scale":119===A?"xyz-scale":5===A?"xy-translate":6===A?"z-translate":7===A||9===A?"x-translate":8===A||10===A?"y-translate":11===A?"z-rotate":"scale",this.RA}transform(A){if(!A)return;if(this.layerRenderer&&this.layerRenderer.layer&&(this.layerRenderer.layer.off("renderend",this.render),this.layerRenderer.layer.off("resizeCanvas",this.At)),!this.map)return void console.error("should add to a target first");if(this.yA&&(this.yA.uA(),this.yA.cA(A)),!this.yA.getTargets().length)return;const t=this.map;this.TransformHelper.updateMatrix(t,this.yA,0,0,[0,0,0]),this.tt(),this._A=!0}getTransformTarget(){return this.yA}gA(){delete this.yA}tt(){const A=this.yA.mA();A&&(A.off("renderend",this.render),A.off("resizeCanvas",this.At));const e=this.map.getLayers();let s=null;for(let A=0;A<e.length;A++)if(e[A]instanceof t.GroupGLLayer){s=e[A];break}if(!s)return;const n=s.getLayers(),i=n.indexOf(A);if(i<0)return;n.splice(i,1),n.push(A);const r=this.map,o=A.getRenderer();this.layerRenderer=o,this.regl=o.regl,this.renderer=o.renderer,this.et=this.layerRenderer.getFBORayPicking(),this.st={projViewMatrix:r.projViewMatrix,projMatrix:r.projMatrix,viewMatrix:r.viewMatrix,pointSize:1},A.on("renderend",this.render,this),A.on("resizeCanvas",this.At,this),o.setToRedraw()}At(){this.et.clear(),this._A=!0}VA(A,t,e){const s=this.map;if(!(s&&this.et&&this.layerRenderer&&this.layerRenderer.canvas))return null;const n=s.getDevicePixelRatio(),i=A.x*n,r=A.y*n,o=this.st,a=this.layerRenderer.canvas.gl&&this.layerRenderer.canvas.gl.wrap;(this._A||a||!this.nt||this.nt!==e)&&(this.et.render(t,o,!0),this.nt=e,this._A=!1);return this.et.pick(i,r,10,o,{viewMatrix:this.map.viewMatrix,projMatrix:this.map.projMatrix,returnPoint:!0})}xA(){const A=this.map.getDevicePixelRatio(),e={x:0,y:0,width:()=>this.map?this.map.width*A:1,height:()=>this.map?this.map.height*A:1};this.it=new t.reshader.MeshShader({vert:"attribute vec3 aPosition;\n\nuniform mat4 projViewModelMatrix;\n\n\n\nvoid main()\n\n{\n\n gl_Position = projViewModelMatrix * vec4(aPosition, 1.0);\n\n\n\n}\n\n",frag:"precision mediump float;\n\nuniform vec4 color;\n\n\n\nvoid main() {\n\n gl_FragColor = color;\n\n}\n\n",uniforms:["color",{name:"projViewModelMatrix",type:"function",fn:function(A,e){return t.mat4.multiply([],e.projViewMatrix,e.modelMatrix)}}],extraCommandProps:{viewport:e,depth:{enable:!0,func:"always",mask:!0,range:[0,0]},blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"}},defines:{}})}render(){if(!this.FA())return;const A=this.UA();this.helperScene.setMeshes(A);const t=this.layerRenderer.getFrameContext();if(t&&t.renderTarget&&this.layerRenderer.getFrameTimestamp()!==t.timestamp)return;this.HA(),this.it.filter=t&&t.sceneFilter;const e=t&&t.renderTarget&&t.renderTarget.fbo;this.renderer.render(this.it,this.st,this.helperScene,e)}UA(){let A=[];const t=this.TransformHelper.getMeshes(this.bA);for(const e in t){if("translate"===e)continue;const s=t[e];for(let t=0;t<s.length;t++)A=A.concat(s[t])}const e=t.translate;if(e)for(let t=0;t<e.length;t++)A=A.concat(e[t]);return A}FA(){const A=this.layerRenderer,t=A&&A.layer;return A&&this.yA&&t&&t.isVisible()&&this.yA.PA()&&this.regl&&this.DA}}et.mergeOptions({scaleStrength:2}),A.TransformControl=et,"undefined"!=typeof console&&console.log("@maptalks/transform-control v0.98.1")}));
|
|
13
13
|
//# sourceMappingURL=transform-control.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maptalks/transform-control",
|
|
3
|
-
"version": "0.98.
|
|
3
|
+
"version": "0.98.1",
|
|
4
4
|
"description": "a plugin to control model's translate、rotation and scale",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"rollup": "^4.17.2"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"maptalks": "1.0.0-rc.
|
|
29
|
+
"maptalks": "1.0.0-rc.35",
|
|
30
30
|
"@maptalks/gl": "0.98.0",
|
|
31
31
|
"@maptalks/gltf-loader": "0.98.0"
|
|
32
32
|
},
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"clean": "rimraf dist",
|
|
36
36
|
"dev": "rollup -w -c rollup.config.js",
|
|
37
|
-
"build": "npm run clean && rollup --environment BUILD:production -c rollup.config.js",
|
|
37
|
+
"build": "npm run clean && npm run lint && rollup --environment BUILD:production -c rollup.config.js",
|
|
38
38
|
"build-dev": "rollup -c rollup.config.js",
|
|
39
39
|
"pretest": "npm run lint && npm run build",
|
|
40
40
|
"tdd": "karma start --no-single-run",
|