🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@maptalks/gltf-loader

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@maptalks/gltf-loader - npm Package Compare versions

Comparing version
0.121.0
to
0.122.0
+2
-2
dist/gltf-loader.es.js
/*!
* @maptalks/gltf-loader v0.121.0
* @maptalks/gltf-loader v0.122.0
* LICENSE : UNLICENSED
* (c) 2016-2026 maptalks.org
*/
var e="undefined"!=typeof Float32Array?Float32Array:Array;function t(e,t,s){var r=t[0],n=t[1],i=t[2],a=t[3],o=t[4],f=t[5],u=t[6],h=t[7],c=t[8],l=t[9],m=t[10],d=t[11],g=t[12],p=t[13],b=t[14],_=t[15],y=s[0],x=s[1],w=s[2],T=s[3];return e[0]=y*r+x*o+w*c+T*g,e[1]=y*n+x*f+w*l+T*p,e[2]=y*i+x*u+w*m+T*b,e[3]=y*a+x*h+w*d+T*_,y=s[4],x=s[5],w=s[6],T=s[7],e[4]=y*r+x*o+w*c+T*g,e[5]=y*n+x*f+w*l+T*p,e[6]=y*i+x*u+w*m+T*b,e[7]=y*a+x*h+w*d+T*_,y=s[8],x=s[9],w=s[10],T=s[11],e[8]=y*r+x*o+w*c+T*g,e[9]=y*n+x*f+w*l+T*p,e[10]=y*i+x*u+w*m+T*b,e[11]=y*a+x*h+w*d+T*_,y=s[12],x=s[13],w=s[14],T=s[15],e[12]=y*r+x*o+w*c+T*g,e[13]=y*n+x*f+w*l+T*p,e[14]=y*i+x*u+w*m+T*b,e[15]=y*a+x*h+w*d+T*_,e}function s(){var t=new e(3);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function r(t,s,r){var n=new e(3);return n[0]=t,n[1]=s,n[2]=r,n}function n(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function i(e,t,s,r){return e[0]=t,e[1]=s,e[2]=r,e}function a(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e}function o(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function f(e,t,s,r,n){return e[0]=t,e[1]=s,e[2]=r,e[3]=n,e}function u(e,t,s){var r=t[0],n=t[1],i=t[2],a=t[3];return e[0]=s[0]*r+s[4]*n+s[8]*i+s[12]*a,e[1]=s[1]*r+s[5]*n+s[9]*i+s[13]*a,e[2]=s[2]*r+s[6]*n+s[10]*i+s[14]*a,e[3]=s[3]*r+s[7]*n+s[11]*i+s[15]*a,e}function h(){var t=new e(4);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function c(e,t,s,r){var n,i,a,o,f,u=t[0],h=t[1],c=t[2],l=t[3],m=s[0],d=s[1],g=s[2],p=s[3];return(i=u*m+h*d+c*g+l*p)<0&&(i=-i,m=-m,d=-d,g=-g,p=-p),1-i>1e-6?(n=Math.acos(i),a=Math.sin(n),o=Math.sin((1-r)*n)/a,f=Math.sin(r*n)/a):(o=1-r,f=r),e[0]=o*u+f*m,e[1]=o*h+f*d,e[2]=o*c+f*g,e[3]=o*l+f*p,e}s(),function(){var t,s=(t=new e(4),e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var l,m=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e};s(),r(1,0,0),r(0,1,0),h(),h(),l=new e(9),e!=Float32Array&&(l[1]=0,l[2]=0,l[3]=0,l[5]=0,l[6]=0,l[7]=0),l[0]=1,l[4]=1,l[8]=1;let d=0;function g(e){return null==e}function p(e){return!g(e)}function b(e){return!g(e)&&("string"==typeof e||null!==e.constructor&&e.constructor===String)}function _(e){for(let t=1;t<arguments.length;t++){const s=arguments[t];for(const t in s)e[t]=s[t]}return e}function y(e){switch(e){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: "+e)}function x(e){return 0===e.indexOf("data:")&&e.indexOf("base64,")>0}function w(e){const t=function(e){return"undefined"!=typeof self?self.atob(e):window.atob(e)}(e.substring(e.indexOf(",")+1)),s=t.length,r=new Uint8Array(s);for(let e=0;e<s;e++)r[e]=t.charCodeAt(e);return r.buffer}const T=[],E=[],O=[],I=[0,0,0],R=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}([]),A=[1,1,1];function q(e,t,s,r,n,i,a){const o=y(a),f=o.BYTES_PER_ELEMENT;if((0===n||n===r*f)&&i%f==0){const n=new o(t,i,s*r);return e.set(n),e}0===n&&(n=r*f);const u=new Uint8Array(r*f);for(let a=0;a<s;a++){let s=null;const h=new Uint8Array(t,n*a+i,r*f);u.set(h),s=new o(u.buffer,0,r);for(let t=0;t<r;t++)e[a*r+t]=s[t]}return e}const B="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function N(e,t,s){const r=new Uint8Array(e,t,s);return B.decode(r)}const v={get:function(e,t={},s){t||(t={}),t=_({},t);const r=new AbortController,n=r.signal,i=_({},t);i.signal=n,i.method||(i.method="GET"),i.referrerPolicy=i.referrerPolicy||"origin","undefined"==typeof window||i.referrer||(i.referrer=window.location.href),s&&(e=s(e));const a=fetch(e,i).then((e=>{const s=this._parseResponse(e,t.responseType);return s.message?s:s.then((s=>"arraybuffer"===t.responseType?{data:s,cacheControl:e.headers.get("Cache-Control"),expires:e.headers.get("Expires"),contentType:e.headers.get("Content-Type")}:s)).catch((e=>{if(!e.code||e.code!==DOMException.ABORT_ERR)throw e}))})).catch((e=>{if(!e.code||e.code!==DOMException.ABORT_ERR)throw e}));return a.xhr=r,a},_parseResponse:(e,t)=>200!==e.status?{status:e.status,statusText:e.statusText,message:`incorrect http request with status code(${e.status}): ${e.statusText}`}:"arraybuffer"===t?e.arrayBuffer():"json"===t?e.json():e.text(),getArrayBuffer:(e,t={},s)=>(t||(t={}),t.responseType="arraybuffer",v.get(e,t,s)),getJSON:function(e,t={},s){return t&&t.jsonp?v.jsonp(e):((t=t||{}).responseType="json",v.get(e,t,s))}};v.jsonp=function(e){const t="_maptalks_jsonp_"+d++;e.match(/\?/)?e+="&callback="+t:e+="?callback="+t;let s=document.createElement("script");return s.type="text/javascript",s.src=e,new Promise((e=>{window[t]=function(r){document.getElementsByTagName("head")[0].removeChild(s),s=null,delete window[t],e(r)},document.getElementsByTagName("head")[0].appendChild(s)}))};class P{constructor(e,t,s,r,n){this._requestImage=e,this.decoders=t,this._supportedFormats=s,this.images={},this._imgRequests={},this._fetchOptions=r||{},this._urlModifier=n}requestImageFromBufferURI(e,t,s){if(this.buffers[e.id]){const r=this.buffers[e.id],n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}if(this._imgRequests[e.id])return this._imgRequests[e.id].then((()=>{const r=this.buffers[e.id],n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}));if(x(e.uri)){const r=this.buffers[e.id]=w(e.uri),n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}let r;const n=e.uri.indexOf("blob:")>=0;r=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri;return this._imgRequests[e.id]=v.getArrayBuffer(r,this._fetchOptions,this._urlModifier).then((r=>{const n=this.buffers[e.id]=r.data,i=this._createDataView(t,n);return this.getImageByBuffer(i,s)}))}getImageByBuffer(e,t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const s=this.decoders;if(s[t.mimeType])return s[t.mimeType](e,{supportedFormats:this._supportedFormats});if("image/crn"===t.mimeType||"image/ktx2"===t.mimeType||"image/cttf"===t.mimeType)throw new Error("missing transcoder for "+t.mimeType,"");return this._getImageInfo(t.id,e)}requestExternalImage(e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const t=0===e.uri.indexOf("data:image/")?e.uri:this.rootPath+"/"+e.uri;if(this._imgRequests[e.id])return this._imgRequests[e.id].then((()=>this.images[e.id]));return this._imgRequests[e.id]=this._getImageInfo(e.id,t)}_getImageInfo(e,t){return new Promise(((s,r)=>{let n=t;this._urlModifier&&(n=this._urlModifier(t)),this._requestImage(n,this._fetchOptions,((n,i)=>{n?r(n):(URL.revokeObjectURL(t),this.images[e]=i,s(this.images[e]))}))}))}}const M=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],S=[];class V{constructor(e,t,s,r,n){this.rootPath=e,this.gltf=t,this._enableInterleave=!1,this.glbBuffer=s,this.buffers={},this.requests={},this.accessors={},this._compareAccessor(),this._fetchOptions=r,this._urlModifier=n}_requestData(e,t){const s=this.gltf,r=s.accessors[t];if(void 0===r.bufferView)return this.accessors[r.id]=this._toBufferData(e,t,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const n=s.bufferViews[r.bufferView];return this._requestBufferOfBufferView(n).then((s=>{const{buffer:n,byteOffset:i}=s;return this.accessors[r.id]=this._toBufferData(e,t,n,i)}))}_requestBufferOfBufferView(e){const t=this.gltf.buffers[e.buffer];if(this.buffers[t.id]){const e=this.buffers[t.id];return Promise.resolve({buffer:e,byteOffset:0})}if(this.requests[t.id])return this.requests[t.id].then((()=>{const e=this.buffers[t.id];return Promise.resolve({buffer:e,byteOffset:0})}));if("binary_glTF"!==e.buffer&&"KHR_binary_glTF"!==e.buffer&&t.uri){if(x(t.uri)){const e=this.buffers[t.id]=w(t.uri);return Promise.resolve({buffer:e,byteOffset:0})}let e;const s=t.uri.indexOf("blob:")>=0;e=t.uri.indexOf("://")>0||s?t.uri:this.rootPath+"/"+t.uri;return this.requests[t.id]=v.getArrayBuffer(e,this._fetchOptions,!s&&this._urlModifier).then((r=>{s&&URL.revokeObjectURL(e);return{buffer:this.buffers[t.id]=r.data,byteOffset:0}}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}_toBufferData(e,t,s,r=0){const n=this.gltf,i=n.accessors[t],a=void 0!==i.bufferView?n.bufferViews[i.bufferView]:{},o=(a.byteOffset||0)+r,f=this._getTypeItemSize(i.type),h=y(i.componentType),c=a.byteStride||0;const l={array:undefined,name:e,accessorName:t,byteLength:i.count*f*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:f,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(l.min=i.min),i.max&&(l.max=i.max),s)if(this._enableInterleave)l.byteStride=c,l.byteOffset=o+(i.byteOffset||0),!c||c===f*h.BYTES_PER_ELEMENT||"indices"===e||"input"===e||"output"===e||e.indexOf("morph")>=0?(l.array=this._typedArray(s,i.count,f,o+(i.byteOffset||0),h),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(s,o,a.byteLength);else if(i.interleaved){l.byteStride=0,l.byteOffset=0;const e=new h(i.count*f);if(l.array=q(e,s,i.count,f,c,o+(i.byteOffset||0),i.componentType),l.extensions&&l.extensions.WEB3D_quantized_attributes&&f>2){const e=new Float32Array(l.array.length),{decodeMatrix:t}=l.extensions.WEB3D_quantized_attributes;for(let s=0;s<l.array.length;s+=f){S[0]=l.array[s],S[1]=l.array[s+1],S[2]=l.array[s+2],S[3]=1;const r=u(S,S,t);e[s]=r[0],e[s+1]=r[1],e[s+2]=r[2]}l.componentType=5126,l.array=e}}else l.byteStride=0,l.array=this._typedArray(s,i.count,f,o+(i.byteOffset||0),h),l.byteOffset=l.array.byteOffset;else{l.array=new h(i.count);const e=l.min||l.max;e&&(l.array[0]=e[0],l.array[1]=e[1],l.array[2]=e[2])}return l}_compareAccessor(){const e=this.gltf.accessors;if(Array.isArray(e))for(let t=0;t<e.length;t++)for(let s=0;s<e.length;s++)t!==s&&e[t].bufferView===e[s].bufferView&&(e[t].interleaved=e[s].interleaved=!0);else for(const t in e)for(const s in e)t!==s&&e[t].bufferView===e[s].bufferView&&(e[t].interleaved=e[s].interleaved=!0)}_typedArray(e,t,s,r,n){return r%n.BYTES_PER_ELEMENT!=0&&(e=e.slice(r,r+t*s*n.BYTES_PER_ELEMENT),r=0),new n(e,r,s*t)}_getTypeItemSize(e){const t=M.indexOf(e);return M[t+1]}requestKHRTechniquesWebgl(e){const{shaders:t}=e,s=t.map((e=>{if(void 0!==e.bufferView){const t=this.gltf.bufferViews[e.bufferView],{byteLength:s}=t;return this._requestBufferOfBufferView(t).then((r=>{const{buffer:n,byteOffset:i}=r,a=N(n,i+(t.byteOffset||0),s);return e.content=a,e}))}if(e.uri){if(x(e.uri)){const t=w(e.uri),s=N(t,0,t.byteLength);return e.content=s,Promise.resolve(e)}{const t=this.rootPath+"/"+e.uri;return v.get(t,this._fetchOptions,this._urlModifier).then((t=>(e.content=t,e)))}}return Promise.resolve(e)}));return Promise.all(s).then((()=>e))}}class D extends P{constructor(e,t,s,r,n,i,a,o){super(r,n,i,a,o),this.rootPath=e,this.gltf=t,this.requests={},this.buffers={},this.glbBuffer=s,this.accessor=new V(e,t,s,a,o)}iterate(e,t){const s=this.gltf[t];if(!s)return;let r=0;for(const t in s)e(t,s[t],r++)}createNode(e){const s={};if(p(e.name)&&(s.name=e.name),p(e.children)&&(s.children=e.children),p(e.jointName)&&(s.jointName=e.jointName),p(e.matrix)&&(s.matrix=e.matrix),p(e.rotation)&&(s.rotation=e.rotation),p(e.scale)&&(s.scale=e.scale),p(e.translation)&&(s.translation=e.translation),p(e.extras)&&(s.extras=e.extras),p(e.meshes)&&(s.mesh=e.meshes[0]),s.translation||s.rotation||s.scale){const e=function(e,s){if(s.matrix)return s.matrix;if(s.translation||s.scale||s.rotation){const r=function(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}(T,s.translation||I),n=function(e,t){var s=t[0],r=t[1],n=t[2],i=t[3],a=s+s,o=r+r,f=n+n,u=s*a,h=r*a,c=r*o,l=n*a,m=n*o,d=n*f,g=i*a,p=i*o,b=i*f;return e[0]=1-c-d,e[1]=h+b,e[2]=l-p,e[3]=0,e[4]=h-b,e[5]=1-u-d,e[6]=m+g,e[7]=0,e[8]=l+p,e[9]=m-g,e[10]=1-u-c,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(E,s.rotation||R),i=function(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(O,s.scale||A);return t(i,n,i),t(e,r,i)}return function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(e)}([],s);delete s.translation,delete s.rotation,delete s.scale,s.matrix=e}return s}_loadMaterials(e){const t={};for(const s in e){const r=e[s];let n,i;r.instanceTechnique&&r.instanceTechnique.values?(n=r.instanceTechnique,i=n.values.diffuse):(n=r,i=n.values.tex||n.values.diffuseTex||n.values.diffuse);const a={baseColorTexture:{index:i}};r.name&&(a.name=r.name),r.extensions&&(a.extensions=r.extensions),r.extras&&(a.extras=r.extras),t[s]=a}return t}_loadImage(e){if(e.bufferView||e.extensions&&(e.extensions.KHR_binary_glTF||e.extensions.binary_glTF)){const t=e.bufferView?e:e.extensions.KHR_binary_glTF||e.extensions.binary_glTF;e.extensions&&(e.mimeType=t.mimeType,e.width=t.width,e.height=t.height);const s=this.gltf.bufferViews[t.bufferView],r=(s.byteOffset||0)+this.glbBuffer.byteOffset,n=s.byteLength,i=this.buffers[t.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,n);return this.getImageByBuffer(i,e)}return this.requestExternalImage(e)}_getTexture(e){const t=this.gltf.textures[e];if(!t)return null;const s=this.gltf.images[t.source];return this._loadImage(s).then((e=>{const r=this.gltf.samplers[t.sampler];return{image:{array:e.data,width:e.width,height:e.height,index:t.source,mimeType:s.mimeType,name:s.name,extras:s.extras},sampler:r}}))}getBaseColorTexture(e){const t=this.gltf.materials[e];let s,r;if(t.instanceTechnique&&t.instanceTechnique.values?(s=t.instanceTechnique,r=s.values.diffuse):(s=t,r=s.values.tex||s.values.diffuseTex||s.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const n=this.gltf.textures[r];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 L=9729;class U extends P{constructor(e,t,s,r,n,i,a,o){super(r,n,i,a,o),this.rootPath=e,this.gltf=t,this.glbBuffer=s,this.buffers={},this.requests={},this.accessor=new V(e,t,s,a,o)}iterate(e,t){const s=this.gltf[t];if(s)for(let t=0;t<s.length;t++)e(t,s[t],t)}createNode(e){const t={};return _(t,e),!p(e.weights)&&this.gltf.meshes&&p(t.mesh)?t.weights=this.gltf.meshes[t.mesh].weights:e.weights&&(t.weights=e.weights),t}_getTexture(e){const t=this.gltf.textures[e];if(!t)return null;let s=t.source;if(t.extensions&&t.extensions.EXT_texture_webp?s=t.extensions.EXT_texture_webp.source:t.extensions&&t.extensions.KHR_texture_basisu&&(s=t.extensions.KHR_texture_basisu.source),!p(s))return null;const r=this.gltf.images[s];return this._loadImage(r).then((e=>{if(!e)return null;const s={image:{array:e.data,mipmap:e.mipmap,width:e.width,height:e.height,index:t.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};_(s,t);const n=p(t.sampler)?this.gltf.samplers[t.sampler]:void 0;if(n&&(s.sampler=n,s.sampler.magFilter=n.magFilter||L,s.sampler.minFilter=n.minFilter||9987,s.sampler.wrapS=n.wrapS||10497,s.sampler.wrapT=n.wrapT||10497),"image/ktx2"===s.image.mimeType&&!s.image.mipmap&&s.sampler&&s.sampler.minFilter!==L&&9728!==s.sampler.minFilter){const e=s.sampler.minFilter;s.sampler.minFilter=9984===e||9986===e?9728:L}if(e.format&&(s.format=e.format),6407===s.format){const e=s.image.array&&s.image.array.length;e&&e===s.image.width*s.image.height*4&&(s.format=6408)}return s}))}_loadImage(e){if(!p(e.bufferView))return this.requestExternalImage(e);{const t=this.gltf.bufferViews[e.bufferView],s=this.gltf.buffers[t.buffer];if(s.uri)return this.requestImageFromBufferURI(s,t,e);if(this.glbBuffer)return this._requestFromGlbBuffer(t,e)}return null}_requestFromGlbBuffer(e,t){const s=this._createDataView(e,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(s,t)}_createDataView(e,t,s){s=s||0;const r=(e.byteOffset||0)+s,n=e.byteLength;return new Uint8Array(t,r,n)}_transformArrayBufferToBase64(e,t){const s=new Array(e.byteLength);for(let t=0;t<e.byteLength;t++)s[t]=String.fromCharCode(e[t]);s.join("");const r="data:"+(t=t||"image/png")+";base64,"+function(e){return"undefined"!=typeof self?self.btoa(e):window.btoa(e)}(unescape(encodeURIComponent(s)));return r}getAnimations(e){const t=[];return e.forEach((e=>{t.push(this.getSamplers(e.samplers))})),Promise.all(t).then((t=>{for(let s=0;s<t.length;s++)e[s].samplers=t[s];return e}))}getSamplers(e){const t=[];for(let s=0;s<e.length;s++)(p(e[s].input)||p(e[s].output))&&(t.push(this.accessor._requestData("input",e[s].input)),t.push(this.accessor._requestData("output",e[s].output)));return Promise.all(t).then((t=>{for(let s=0;s<t.length/2;s++)e[s].input=t[2*s],e[s].output=t[2*s+1],e[s].interpolation||(e[s].interpolation="LINEAR");return e}))}}const C="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null,F=1313821514,k=5130562;class X{static read(e,t=0,s=0){s||(s=e.byteLength);const r=new DataView(e,t,s),n=r.getUint32(4,!0);if(1===n)return X.readV1(r,t);if(2===n)return X.readV2(e,t);throw new Error("Unsupported glb version : "+n)}static readV1(e,t){const s=e.getUint32(8,!0),r=e.getUint32(12,!0);if(s!==e.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const n=K(e.buffer,20+t,r);return{json:JSON.parse(n),glbBuffer:{byteOffset:20+t+r,buffer:e.buffer,byteLength:s}}}static readV2(e,t){let s,r,n;const i=new DataView(e,t+12);let a=0;for(;a+8<i.byteLength;){const o=i.getUint32(a,!0);a+=4;const f=i.getUint32(a,!0);if(a+=4,f===F)s=K(e,t+12+a,o);else if(f===k){n=t+12+a,r=o;break}a+=o}return{json:JSON.parse(s),glbBuffer:{byteOffset:n,buffer:e,byteLength:r}}}}function K(e,t,s){if(C){const r=new Uint8Array(e,t,s);return C.decode(r)}return function(e){const t=e.length;let s="";for(let r=0;r<t;){let n=e[r++];if(128&n){let s=H[n>>3&7];if(!(64&n)||!s||r+s>t)return null;for(n&=63>>s;s>0;s-=1){const t=e[r++];if(128!=(192&t))return null;n=n<<6|63&t}}s+=String.fromCharCode(n)}return s}(new Uint8Array(e,t,s))}const H=[1,1,1,1,2,2,3,0];const j=[0,0,0],z=[0,0,0,1],W=[1,1,1],Y={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},G={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},$={_getTRSW(e,t,s,r,i,a,o,f){const u=p(e)?t.animations:[t.animations[0]],h={};for(let t=0;t<u.length;t++){const c=u[t],l=c.name||t;if(p(e)&&l!==e)continue;const d=c.channelsMap[s];if(d)for(let e=0;e<d.length;e++){const t=d[e];"translation"===t.target.path?(this._getAnimateData(i,c.samplers[t.sampler],r,1),h.translation=n(j,i)):"rotation"===t.target.path?(this._getQuaternion(a,c.samplers[t.sampler],r,1),h.rotation=m(z,a)):"scale"===t.target.path?(this._getAnimateData(o,c.samplers[t.sampler],r,1),h.scale=n(W,o)):"weights"===t.target.path&&f&&(this._getAnimateData(f,c.samplers[t.sampler],r,f.length),h.weights=f)}}return h},_getAnimateData(e,t,s,r){switch(t.interpolation){case"LINEAR":{const n=this._getPreNext(G,t,s,1*r);n&&(e=function(e,t,s,r){for(let n=0;n<e.length;n++)e[n]=t[n]+r*(s[n]-t[n]);return e}(e,n.PREVIOUS,n.NEXT,n.INTERPOLATION));break}case"STEP":{const n=this._getPreNext(G,t,s,1*r);n&&(e=function(e,t){for(let s=0;s<e.length;s++)e[s]=t[s];return e}(e,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this._getPreNext(G,t,s,3*r);n&&(e=this._getCubicSpline(e,n,t.input.array,3*r));break}}return e},_getQuaternion(e,t,s){switch(t.interpolation){case"LINEAR":{const r=this._getPreNext(G,t,s,1);r&&c(e,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this._getPreNext(G,t,s,1);r&&(e=f(e,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this._getPreNext(G,t,s,3);if(r){for(let e=0;e<r.PREVIOUS.length;e++)r.PREVIOUS[e]=Math.acos(r.PREVIOUS[e]),r.NEXT[e]=Math.acos(r.NEXT[e]);e=this._getCubicSpline(e,r,t.input.array,3);for(let t=0;t<e.length;t++)e[t]=Math.cos(e[t])}break}}return e},_search(e,t){const s=e.length;let r,n,i,a=0,o=s-1,f=Math.floor((a+o)/2);for(;a<=s-1&&o>=0;){if(a===o)return null;if(e[f]<=t&&t<=e[f+1]){const s=e[f];return r=f,n=f+1,i=(t-s)/(e[f+1]-s),{preIndx:r,nextIndex:n,interpolation:i}}t<e[f]?(o=f,f=Math.floor((a+o)/2)):e[f+1]<t&&(a=f,f=Math.floor((a+o)/2))}return null},_getPreNext(e,t,s,r){const n=t.input.array,i=t.output.array,a=t.output.itemSize;(s<n[0]||s>n[n.length-1])&&(s=Math.max(n[0],Math.min(n[n.length-1],s))),s===n[n.length-1]&&(s=n[0]);const o=this._search(n,s);if(!o||!o.nextIndex)return null;const{preIndx:f,nextIndex:u,interpolation:h}=o;e.PREINDEX=f,e.NEXTINDEX=u,e.INTERPOLATION=h;const c=a*r;return e.PREVIOUS=i.subarray(e.PREINDEX*c,(e.PREINDEX+1)*c),e.NEXT=i.subarray(e.NEXTINDEX*c,(e.NEXTINDEX+1)*c),e},_getCubicSpline(e,t,s,r){const n=t.INTERPOLATION,i=s[t.PREINDEX],a=s[t.NEXTINDEX];for(let s=0;s<3;s++){const o=t.PREVIOUS[r+s],f=(a-i)*t.PREVIOUS[2*r+s],u=t.NEXT[3+s],h=(a-i)*t.NEXT[s],c=(2*Math.pow(n,3)-3*Math.pow(n,2)+1)*o+(Math.pow(n,3)-2*Math.pow(n,2)+n)*f+(2*-Math.pow(n,3)+3*Math.pow(n,2))*u+(Math.pow(n,3)-Math.pow(n,2))*h;e[s]=c}return e},getAnimationClip(e,t,s,r){const n=e.nodes[t]&&e.nodes[t].weights;i(j,...Y.TRANSLATION),f(z,...Y.ROTATION),i(W,...Y.SCALE);return this._getTRSW(r,e,t,s,j,z,W,n)},getTimeSpan(e){if(!e.animations)return null;if(e.timeSpan)return e.timeSpan;const t=e.animations;return e.timeSpan={},t.forEach(((t,s)=>{let r=-1/0,n=1/0;const i=t.channels;for(let e=0;e<i.length;e++){const s=i[e],a=t.samplers[s.sampler].input.array;a[a.length-1]>r&&(r=a[a.length-1]),a[0]<n&&(n=a[0])}const a=t.name||s;e.timeSpan[a]={max:r,min:n}})),e.timeSpan},getTimeSpanByName(e,t){const s=this.getTimeSpan(e);return s?p(t)?s[t]:s[Object.keys(s)[0]]:null}};let J=!1;if("undefined"!=typeof OffscreenCanvas){let e;try{e=new OffscreenCanvas(2,2).getContext("2d")}catch(e){}e&&"undefined"!=typeof createImageBitmap&&(J=!0)}const Q="undefined"==typeof document?null:document.createElement("canvas");class Z{constructor(e,t,s){if(this.options=s||{},this.options.decoders||(this.options.decoders={}),this._fetchOptions=this.options.fetchOptions||{},t.buffer instanceof ArrayBuffer){const{json:s,glbBuffer:r}=X.read(t.buffer,t.byteOffset,t.byteLength);this._init(e,s,r)}else this._init(e,t);this._accessor=new V(this.rootPath,this.gltf,this.glbBuffer,this._fetchOptions,this.options.urlModifier),this._checkExtensions()}_checkExtensions(){const e=this.gltf.extensionsRequired;if(e){if(e.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(e.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(e.indexOf("EXT_meshopt_compression")>=0)throw new Error("EXT_meshopt_compression extension is not supported yet.")}}_loadExtensions(){const e=this.gltf.extensions;return e&&e.KHR_techniques_webgl?this._accessor.requestKHRTechniquesWebgl(e.KHR_techniques_webgl).then((t=>(e.KHR_techniques_webgl=t,e))):Promise.resolve(e)}_convertKhrTechiqueToTechiques(){if(!Array.isArray(this.gltf.programs))return;const e=this.gltf.materials;for(let t=0;t<e.length;t++)e[t]&&e[t].extensions&&e[t].extensions.KHR_technique_webgl&&(e[t].extensions.KHR_techniques_webgl=e[t].extensions.KHR_technique_webgl,delete e[t].extensions.KHR_technique_webgl);const t=this.gltf.extensions||{},s=this.gltf.techniques;t.KHR_techniques_webgl={programs:this.gltf.programs,shaders:this.gltf.shaders,techniques:s};for(let t=0;t<e.length;t++){const n=(r=e[t])&&r.extensions&&r.extensions.KHR_techniques_webgl;if(n){const{values:e,technique:t}=n,r=s[t];if(!r||!e)continue;const{uniforms:i,parameters:a}=r,o={};for(const t in e){const s=ce(i,t);o[s]=e[t],a[t]&&35678===a[t].type&&(o[s]={index:e[t]})}n.values=o}}var r;for(let e=0;e<s.length;e++){const t=s[e];if(!t)continue;const{attributes:r,uniforms:n,parameters:i}=t;if(r)for(const e in r){const t=r[e];r[e]=i[t]}if(n)for(const e in n){const t=n[e];n[e]=i[t]}delete t.parameters}return delete this.gltf.programs,delete this.gltf.shaders,delete this.gltf.techniques,this.gltf.extensions=t,t}load(e){e=e||{},this._convertKhrTechiqueToTechiques();const t=this._loadScene(e),s=this._loadAnimations(),r=this._loadTextures(),n=this._loadExtensions();return Promise.all([t,s,r,n]).then((e=>(e[0].animations=e[1],e[0].textures=e[2],e[0].extensions=e[3],e[0].transferables=this.transferables||[],this.createChannelsMap(e[0]),e[0])))}createChannelsMap(e){const t=e.animations;if(t)for(let e=0;e<t.length;e++){const s=t[e];s.channelsMap={};for(let e=0;e<s.channels.length;e++){const t=s.channels[e];s.channelsMap[t.target.node]||(s.channelsMap[t.target.node]=[]),s.channelsMap[t.target.node].push(t)}}}getExternalResources(){const e=[];if(this.gltf){const{buffers:t,images:s}=this.gltf;for(let s=0;s<t.length;s++)t[s].uri&&t[s].uri.indexOf("data:application/octet-stream;base64")<0&&e.push({type:"buffer",uri:t[s].uri});for(let t=0;t<s.length;t++)s[t].uri&&s[t].uri.indexOf("data:image/")<0&&e.push({type:"image",uri:s[t].uri})}return e}static getAnimationClip(e,t,s,r){return $.getAnimationClip(e,t,s,r)}static getAnimationTimeSpan(e,t){return $.getTimeSpanByName(e,t)}static getTypedArrayCtor(e){return y(e)}static readInterleavedArray(e,t,s,r,n,i,a){return q(e,t,s,r,n,i,a)}_init(e,t,s){this.gltf=t,this.glbBuffer=s,this.version=t.asset?+t.asset.version:1,this.rootPath=e,this.buffers={},this.requests={},this.options.requestImage=J?ae.bind(this):this.options.requestImage||ee,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new U(e,t,s,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this._fetchOptions,this.options.urlModifier),this.adapter.iterate(((e,t,s)=>{t.id="buffer_"+s}),"buffers"),this.adapter.iterate(((e,t,s)=>{t.id="image_"+s}),"images"),this.adapter.iterate(((e,t,s)=>{t.id="accessor_"+s}),"accessors")):(this.adapter=new D(e,t,s,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this._fetchOptions,this.options.urlModifier),this.adapter.iterate(((e,t,s)=>{t.id="accessor_"+s}),"accessors"),this.adapter.iterate(((e,t,s)=>{t.id="image_"+s}),"images"))}_parseNodes(e,t){if(e.children&&e.children.length>0){if(!(s=e.children[0],"number"==typeof s&&isFinite(s)||b(e.children[0])))return e;const r=e.children.map((e=>{const s=t[e];return s.nodeIndex=e,this._parseNodes(s,t)}));e.children=r}var s;return e}_loadScene(e){return this._loadNodes(e).then((e=>{const t=this.scenes=[];let s;for(const t in e)e[t]=this._parseNodes(e[t],e),e[t].nodeIndex=Number(t)?Number(t):t;this.adapter.iterate(((r,n,i)=>{const a={};n.name&&(a.name=n.name),n.nodes&&(a.nodes=n.nodes.map((t=>e[t]))),this.gltf.scene===r&&(s=i),t.push(a)}),"scenes");const r={textures:this.gltf.textures,asset:this.gltf.asset,scene:s,scenes:t,nodes:e,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(r.extensions=this.gltf.extensions),1===this.version){const e=this.adapter._loadMaterials(this.gltf.materials);r.materials=e}return delete this.gltf.buffers,r.json=this.gltf,r}))}_loadNodes(e){return this._loadMeshes(e).then((()=>{const e=this.nodes={};return this.adapter.iterate(((t,s)=>{const r=this.adapter.createNode(s,this.meshes,this.skins);e[t]=r}),"nodes"),e}))}_loadSkins(){this.skins=[];const e=[];return this.adapter.iterate(((t,s,r)=>{e.push(this._loadSkin(s).then((e=>{e.index=r,this.skins.push(e)})))}),"skins"),e}_loadSkin(e){const t=e.inverseBindMatrices;return this.adapter.accessor._requestData("inverseBindMatrices",t).then((t=>(e.inverseBindMatrices=t,t&&t.buffer&&this.transferables&&this.transferables.indexOf(t.buffer)<0&&this.transferables.push(t.buffer),e)))}_loadAnimations(){const e=this.gltf.animations;return p(e)?this.adapter.getAnimations(e):null}_loadMeshes(e){this.meshes={};let t=[];return this.adapter.iterate(((s,r,n)=>{t.push(this._loadMesh(r,e).then((e=>{e.index=n,this.meshes[s]=e})))}),"meshes"),t=t.concat(this._loadSkins()),Promise.all(t)}_loadMesh(e,t){const s=e.primitives.map((e=>this._loadPrimitive(e,t))).filter((e=>!!e));return Promise.all(s).then((t=>{const s={};return _(s,e),s.primitives=t,s}))}_loadTextures(){const e=this.gltf.textures;if(!e)return null;const t=[];for(const s in e)t.push(this.adapter._getTexture(s));return Promise.all(t).then((t=>{if(this.transferables)for(let e=0;e<t.length;e++){const s=t[e]&&t[e].image.array;if(s){let e;e=s instanceof ImageBitmap?s:s.buffer,e&&this.transferables.indexOf(e)<0&&this.transferables.push(e)}}if(!Array.isArray(e)){const s={},r=Object.keys(e);for(let e=0;e<t.length;e++)t[e]&&(s[r[e]]=t[e]);return s}return t}))}_loadPrimitive(e,t){let s;const r=[],n=e.extensions;if(p(e.targets))for(let t=0;t<e.targets.length;t++){const s=e.targets[t];for(const e in s){const n=this.adapter.accessor._requestData(`morphTargets_${e}_${t}`,s[e]);n&&r.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 e=this.options.decoders.draco,{bufferView:i,attributes:a}=n.KHR_draco_mesh_compression,o=this.gltf.bufferViews[i],f=this._accessor._requestBufferOfBufferView(o).then((s=>{const{buffer:r,byteOffset:n}=s;let{byteOffset:i}=o;const f=o.byteLength;i||(i=0);const u=new DataView(r,n+i,f),h={attributes:a,useUniqueIDs:!1,skipAttributeTransform:t.skipAttributeTransform};return e(u,h).then((e=>{const t=Object.values(e.attributes);return e.indices&&t.push(e.indices),t}))}));r.push(f),s=Promise.all(r)}else{const t=e.attributes;for(const e in t){const s=this.adapter.accessor._requestData(e,t[e]);s&&r.push(s)}if(p(e.indices)){const t=this.adapter.accessor._requestData("indices",e.indices);t&&r.push(t)}s=Promise.all(r)}return s.then((t=>{if(n&&n.KHR_draco_mesh_compression){const s=e.targets?e.targets.length:0;t[s]=t[s].concat(t.slice(0,s)),t=t[s]}let s,r;const i={attributes:t.reduce(((e,t)=>{if("indices"===t.name)s=t;else if(t.name.indexOf("morphTargets_")>-1)r=r||{},r[t.name.slice(13)]=t;else{if(!("POSITION"!==t.name||t.min&&t.max)){const e=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0],{itemSize:r,array:n}=t,i=n.length/r;for(let t=0;t<i;t++)for(let i=0;i<r;i++){const a=t*r+i;n[a]<e[i]&&(e[i]=n[a]),n[a]>s[i]&&(s[i]=n[a])}if(t.quantization){const r=t.quantization,n=r.range/(1<<r.quantizationBits),i=r.minValues;o(e,e,n),a(e,e,i),o(s,s,n),a(s,s,i)}t.min=e,t.max=s}e[t.name]=t}return this.transferables&&t.array.buffer&&this.transferables.indexOf(t.array.buffer)<0&&this.transferables.push(t.array.buffer),e}),{}),material:e.material};return s&&(i.indices=s),r&&(i.morphTargets=r),i.mode=p(e.mode)?e.mode:4,p(e.extras)&&(i.extras=e.extras),i}))}}function ee(e,t,s){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!Q)return void s(new Error("There is no canvas to draw image!"));Q.width=r.width,Q.height=r.height;const e=Q.getContext("2d",{willReadFrequently:!0});e.drawImage(r,0,0,r.width,r.height);const t=e.getImageData(0,0,r.width,r.height),n={width:r.width,height:r.height,data:new Uint8Array(t.data)};s(null,n)},r.onerror=function(e){s(e)},r.src=e}const te=[],se=[],re=30;let ne,ie;function ae(e,t,s){ne||(ne=new OffscreenCanvas(2,2),ie=ne.getContext("2d",{willReadFrequently:!0}));let r=null;if(b(e))this.options.urlModifier&&(e=this.options.urlModifier(e)),te.push([e,t,s,this]),oe();else{const t=new Blob([e]);r=createImageBitmap(t),r.then(fe.bind(this)).then((e=>{s(null,e)})).catch((e=>{console.warn(e),s(e)}))}}function oe(){if(!te.length||se.length>re)return;const e=te.shift(),[t,s,r,n]=e;se.push(e),fetch(t,s).then((e=>e.arrayBuffer())).then((e=>{const t=new Blob([new Uint8Array(e)]);return createImageBitmap(t)})).then(fe.bind(n)).then((t=>{r.call(n,null,t);const s=se.indexOf(e);se.splice(s,1),oe()})).catch((t=>{console.warn(t),r.call(n,t);const s=se.indexOf(e);se.splice(s,1),oe()}))}function fe(e){let{width:t,height:s}=e;ue(t)||(t=he(t)),ue(s)||(s=he(s));const r=this.options.maxTextureSize;r&&(t=Math.min(r,t),s=Math.min(r,s)),ne.width=t,ne.height=s,ie.drawImage(e,0,0,t,s),e.close();const n=ie.getImageData(0,0,t,s);return{width:t,height:s,data:new Uint8Array(n.data)}}function ue(e){return!(e&e-1)&&0!==e}function he(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))}function ce(e,t){for(const s in e)if(e[s]===t)return s;return t}export{v as Ajax,Z as GLTFLoader};
var e="undefined"!=typeof Float32Array?Float32Array:Array;function t(e,t,s){var r=t[0],n=t[1],i=t[2],a=t[3],o=t[4],f=t[5],u=t[6],h=t[7],c=t[8],l=t[9],d=t[10],m=t[11],g=t[12],p=t[13],b=t[14],_=t[15],y=s[0],x=s[1],w=s[2],T=s[3];return e[0]=y*r+x*o+w*c+T*g,e[1]=y*n+x*f+w*l+T*p,e[2]=y*i+x*u+w*d+T*b,e[3]=y*a+x*h+w*m+T*_,y=s[4],x=s[5],w=s[6],T=s[7],e[4]=y*r+x*o+w*c+T*g,e[5]=y*n+x*f+w*l+T*p,e[6]=y*i+x*u+w*d+T*b,e[7]=y*a+x*h+w*m+T*_,y=s[8],x=s[9],w=s[10],T=s[11],e[8]=y*r+x*o+w*c+T*g,e[9]=y*n+x*f+w*l+T*p,e[10]=y*i+x*u+w*d+T*b,e[11]=y*a+x*h+w*m+T*_,y=s[12],x=s[13],w=s[14],T=s[15],e[12]=y*r+x*o+w*c+T*g,e[13]=y*n+x*f+w*l+T*p,e[14]=y*i+x*u+w*d+T*b,e[15]=y*a+x*h+w*m+T*_,e}function s(){var t=new e(3);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function r(t,s,r){var n=new e(3);return n[0]=t,n[1]=s,n[2]=r,n}function n(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function i(e,t,s,r){return e[0]=t,e[1]=s,e[2]=r,e}function a(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e}function o(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)});function f(e,t,s,r,n){return e[0]=t,e[1]=s,e[2]=r,e[3]=n,e}function u(e,t,s){var r=t[0],n=t[1],i=t[2],a=t[3];return e[0]=s[0]*r+s[4]*n+s[8]*i+s[12]*a,e[1]=s[1]*r+s[5]*n+s[9]*i+s[13]*a,e[2]=s[2]*r+s[6]*n+s[10]*i+s[14]*a,e[3]=s[3]*r+s[7]*n+s[11]*i+s[15]*a,e}function h(){var t=new e(4);return e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function c(e,t,s,r){var n,i,a,o,f,u=t[0],h=t[1],c=t[2],l=t[3],d=s[0],m=s[1],g=s[2],p=s[3];return(i=u*d+h*m+c*g+l*p)<0&&(i=-i,d=-d,m=-m,g=-g,p=-p),1-i>1e-6?(n=Math.acos(i),a=Math.sin(n),o=Math.sin((1-r)*n)/a,f=Math.sin(r*n)/a):(o=1-r,f=r),e[0]=o*u+f*d,e[1]=o*h+f*m,e[2]=o*c+f*g,e[3]=o*l+f*p,e}s(),function(){var t,s=(t=new e(4),e!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();var l,d=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e};s(),r(1,0,0),r(0,1,0),h(),h(),l=new e(9),e!=Float32Array&&(l[1]=0,l[2]=0,l[3]=0,l[5]=0,l[6]=0,l[7]=0),l[0]=1,l[4]=1,l[8]=1;let m=0;function g(e){return null==e}function p(e){return!g(e)}function b(e){return!g(e)&&("string"==typeof e||null!==e.constructor&&e.constructor===String)}function _(e){for(let t=1;t<arguments.length;t++){const s=arguments[t];for(const t in s)e[t]=s[t]}return e}function y(e){switch(e){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: "+e)}function x(e){return 0===e.indexOf("data:")&&e.indexOf("base64,")>0}function w(e){const t=function(e){return"undefined"!=typeof self?self.atob(e):window.atob(e)}(e.substring(e.indexOf(",")+1)),s=t.length,r=new Uint8Array(s);for(let e=0;e<s;e++)r[e]=t.charCodeAt(e);return r.buffer}const T=[],O=[],E=[],I=[0,0,0],R=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}([]),A=[1,1,1];function q(e,t,s,r,n,i,a){const o=y(a),f=o.BYTES_PER_ELEMENT;if((0===n||n===r*f)&&i%f==0){const n=new o(t,i,s*r);return e.set(n),e}0===n&&(n=r*f);const u=new Uint8Array(r*f);for(let a=0;a<s;a++){let s=null;const h=new Uint8Array(t,n*a+i,r*f);u.set(h),s=new o(u.buffer,0,r);for(let t=0;t<r;t++)e[a*r+t]=s[t]}return e}const v="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function B(e,t,s){const r=new Uint8Array(e,t,s);return v.decode(r)}const P={get:function(e,t={},s){t||(t={}),t=_({},t);const r=new AbortController,n=r.signal,i=_({},t);i.signal=n,i.method||(i.method="GET"),i.referrerPolicy=i.referrerPolicy||"origin","undefined"==typeof window||i.referrer||(i.referrer=window.location.href),s&&(e=s(e));const a=fetch(e,i).then((e=>{const s=this._parseResponse(e,t.responseType);return s.message?s:s.then((s=>"arraybuffer"===t.responseType?{data:s,cacheControl:e.headers.get("Cache-Control"),expires:e.headers.get("Expires"),contentType:e.headers.get("Content-Type")}:s)).catch((e=>{if(!e.code||e.code!==DOMException.ABORT_ERR)throw e}))})).catch((e=>{if(!e.code||e.code!==DOMException.ABORT_ERR)throw e}));return a.xhr=r,a},_parseResponse:(e,t)=>200!==e.status?{status:e.status,statusText:e.statusText,message:`incorrect http request with status code(${e.status}): ${e.statusText}`}:"arraybuffer"===t?e.arrayBuffer():"json"===t?e.json():e.text(),getArrayBuffer:(e,t={},s)=>(t||(t={}),t.responseType="arraybuffer",P.get(e,t,s)),getJSON:function(e,t={},s){return t&&t.jsonp?P.jsonp(e):((t=t||{}).responseType="json",P.get(e,t,s))}};P.jsonp=function(e){const t="_maptalks_jsonp_"+m++;e.match(/\?/)?e+="&callback="+t:e+="?callback="+t;let s=document.createElement("script");return s.type="text/javascript",s.src=e,new Promise((e=>{window[t]=function(r){document.getElementsByTagName("head")[0].removeChild(s),s=null,delete window[t],e(r)},document.getElementsByTagName("head")[0].appendChild(s)}))};class N{constructor(e,t,s,r,n){this._requestImage=e,this.decoders=t,this._supportedFormats=s,this.images={},this._imgRequests={},this._fetchOptions=r||{},this._urlModifier=n}requestImageFromBufferURI(e,t,s){if(this.buffers[e.id]){const r=this.buffers[e.id],n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}if(this._imgRequests[e.id])return this._imgRequests[e.id].then((()=>{const r=this.buffers[e.id],n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}));if(x(e.uri)){const r=this.buffers[e.id]=w(e.uri),n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}let r;const n=e.uri.indexOf("blob:")>=0;r=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri;return this._imgRequests[e.id]=P.getArrayBuffer(r,this._fetchOptions,this._urlModifier).then((r=>{const n=this.buffers[e.id]=r.data,i=this._createDataView(t,n);return this.getImageByBuffer(i,s)}))}getImageByBuffer(e,t){if(this.images[t.id])return Promise.resolve(this.images[t.id]);const s=this.decoders;if(s[t.mimeType])return s[t.mimeType](e,{supportedFormats:this._supportedFormats});if("image/crn"===t.mimeType||"image/ktx2"===t.mimeType||"image/cttf"===t.mimeType)throw new Error("missing transcoder for "+t.mimeType,"");return this._getImageInfo(t.id,e)}requestExternalImage(e){if(this.images[e.id])return Promise.resolve(this.images[e.id]);const t=0===e.uri.indexOf("data:image/")?e.uri:this.rootPath+"/"+e.uri;if(this._imgRequests[e.id])return this._imgRequests[e.id].then((()=>this.images[e.id]));return this._imgRequests[e.id]=this._getImageInfo(e.id,t)}_getImageInfo(e,t){return new Promise(((s,r)=>{let n=t;this._urlModifier&&(n=this._urlModifier(t)),this._requestImage(n,this._fetchOptions,((n,i)=>{n?r(n):(URL.revokeObjectURL(t),this.images[e]=i,s(this.images[e]))}))}))}}const M=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],S=[];class V{constructor(e,t,s,r,n){this.rootPath=e,this.gltf=t,this._enableInterleave=!1,this.glbBuffer=s,this.buffers={},this.requests={},this.accessors={},this._compareAccessor(),this._fetchOptions=r,this._urlModifier=n}_requestData(e,t){const s=this.gltf,r=s.accessors[t];if(void 0===r.bufferView)return this.accessors[r.id]=this._toBufferData(e,t,null,0),Promise.resolve(this.accessors[r.id]);if(r&&this.accessors[r.id])return Promise.resolve(this.accessors[r.id]);const n=s.bufferViews[r.bufferView];return this._requestBufferOfBufferView(n).then((s=>{const{buffer:n,byteOffset:i}=s;return this.accessors[r.id]=this._toBufferData(e,t,n,i)}))}_requestBufferOfBufferView(e){const t=this.gltf.buffers[e.buffer];if(this.buffers[t.id]){const e=this.buffers[t.id];return Promise.resolve({buffer:e,byteOffset:0})}if(this.requests[t.id])return this.requests[t.id].then((()=>{const e=this.buffers[t.id];return Promise.resolve({buffer:e,byteOffset:0})}));if("binary_glTF"!==e.buffer&&"KHR_binary_glTF"!==e.buffer&&t.uri){if(x(t.uri)){const e=this.buffers[t.id]=w(t.uri);return Promise.resolve({buffer:e,byteOffset:0})}let e;const s=t.uri.indexOf("blob:")>=0;e=t.uri.indexOf("://")>0||s?t.uri:this.rootPath+"/"+t.uri;return this.requests[t.id]=P.getArrayBuffer(e,this._fetchOptions,!s&&this._urlModifier).then((r=>{s&&URL.revokeObjectURL(e);return{buffer:this.buffers[t.id]=r.data,byteOffset:0}}))}return Promise.resolve({buffer:this.glbBuffer.buffer,byteOffset:this.glbBuffer.byteOffset})}_toBufferData(e,t,s,r=0){const n=this.gltf,i=n.accessors[t],a=void 0!==i.bufferView?n.bufferViews[i.bufferView]:{},o=(a.byteOffset||0)+r,f=this._getTypeItemSize(i.type),h=y(i.componentType),c=a.byteStride||0;const l={array:undefined,name:e,accessorName:t,byteLength:i.count*f*h.BYTES_PER_ELEMENT,componentType:i.componentType,count:i.count,type:i.type,itemSize:f,max:i.max,min:i.min,extensions:i.extensions};if(i.min&&(l.min=i.min),i.max&&(l.max=i.max),s)if(this._enableInterleave)l.byteStride=c,l.byteOffset=o+(i.byteOffset||0),!c||c===f*h.BYTES_PER_ELEMENT||"indices"===e||"input"===e||"output"===e||e.indexOf("morph")>=0?(l.array=this._typedArray(s,i.count,f,o+(i.byteOffset||0),h),l.array.buffer.byteLength===l.byteLength&&(l.byteOffset=0)):l.array=new Uint8Array(s,o,a.byteLength);else if(i.interleaved){l.byteStride=0,l.byteOffset=0;const e=new h(i.count*f);if(l.array=q(e,s,i.count,f,c,o+(i.byteOffset||0),i.componentType),l.extensions&&l.extensions.WEB3D_quantized_attributes&&f>2){const e=new Float32Array(l.array.length),{decodeMatrix:t}=l.extensions.WEB3D_quantized_attributes;for(let s=0;s<l.array.length;s+=f){S[0]=l.array[s],S[1]=l.array[s+1],S[2]=l.array[s+2],S[3]=1;const r=u(S,S,t);e[s]=r[0],e[s+1]=r[1],e[s+2]=r[2]}l.componentType=5126,l.array=e}}else l.byteStride=0,l.array=this._typedArray(s,i.count,f,o+(i.byteOffset||0),h),l.byteOffset=l.array.byteOffset;else{l.array=new h(i.count);const e=l.min||l.max;e&&(l.array[0]=e[0],l.array[1]=e[1],l.array[2]=e[2])}return l}_compareAccessor(){const e=this.gltf.accessors;if(Array.isArray(e))for(let t=0;t<e.length;t++)for(let s=0;s<e.length;s++)t!==s&&e[t].bufferView===e[s].bufferView&&(e[t].interleaved=e[s].interleaved=!0);else for(const t in e)for(const s in e)t!==s&&e[t].bufferView===e[s].bufferView&&(e[t].interleaved=e[s].interleaved=!0)}_typedArray(e,t,s,r,n){return r%n.BYTES_PER_ELEMENT!=0&&(e=e.slice(r,r+t*s*n.BYTES_PER_ELEMENT),r=0),new n(e,r,s*t)}_getTypeItemSize(e){const t=M.indexOf(e);return M[t+1]}requestKHRTechniquesWebgl(e){const{shaders:t}=e,s=t.map((e=>{if(void 0!==e.bufferView){const t=this.gltf.bufferViews[e.bufferView],{byteLength:s}=t;return this._requestBufferOfBufferView(t).then((r=>{const{buffer:n,byteOffset:i}=r,a=B(n,i+(t.byteOffset||0),s);return e.content=a,e}))}if(e.uri){if(x(e.uri)){const t=w(e.uri),s=B(t,0,t.byteLength);return e.content=s,Promise.resolve(e)}{const t=this.rootPath+"/"+e.uri;return P.get(t,this._fetchOptions,this._urlModifier).then((t=>(e.content=t,e)))}}return Promise.resolve(e)}));return Promise.all(s).then((()=>e))}}class D extends N{constructor(e,t,s,r,n,i,a,o){super(r,n,i,a,o),this.rootPath=e,this.gltf=t,this.requests={},this.buffers={},this.glbBuffer=s,this.accessor=new V(e,t,s,a,o)}iterate(e,t){const s=this.gltf[t];if(!s)return;let r=0;for(const t in s)e(t,s[t],r++)}createNode(e){const s={};if(p(e.name)&&(s.name=e.name),p(e.children)&&(s.children=e.children),p(e.jointName)&&(s.jointName=e.jointName),p(e.matrix)&&(s.matrix=e.matrix),p(e.rotation)&&(s.rotation=e.rotation),p(e.scale)&&(s.scale=e.scale),p(e.translation)&&(s.translation=e.translation),p(e.extras)&&(s.extras=e.extras),p(e.meshes)&&(s.mesh=e.meshes[0]),s.translation||s.rotation||s.scale){const e=function(e,s){if(s.matrix)return s.matrix;if(s.translation||s.scale||s.rotation){const r=function(e,t){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=t[0],e[13]=t[1],e[14]=t[2],e[15]=1,e}(T,s.translation||I),n=function(e,t){var s=t[0],r=t[1],n=t[2],i=t[3],a=s+s,o=r+r,f=n+n,u=s*a,h=r*a,c=r*o,l=n*a,d=n*o,m=n*f,g=i*a,p=i*o,b=i*f;return e[0]=1-c-m,e[1]=h+b,e[2]=l-p,e[3]=0,e[4]=h-b,e[5]=1-u-m,e[6]=d+g,e[7]=0,e[8]=l+p,e[9]=d-g,e[10]=1-u-c,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(O,s.rotation||R),i=function(e,t){return e[0]=t[0],e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=t[1],e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=t[2],e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(E,s.scale||A);return t(i,n,i),t(e,r,i)}return function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}(e)}([],s);delete s.translation,delete s.rotation,delete s.scale,s.matrix=e}return s}_loadMaterials(e){const t={};for(const s in e){const r=e[s];let n,i;r.instanceTechnique&&r.instanceTechnique.values?(n=r.instanceTechnique,i=n.values.diffuse):(n=r,i=n.values.tex||n.values.diffuseTex||n.values.diffuse);const a={baseColorTexture:{index:i}};r.name&&(a.name=r.name),r.extensions&&(a.extensions=r.extensions),r.extras&&(a.extras=r.extras),t[s]=a}return t}_loadImage(e){if(e.bufferView||e.extensions&&(e.extensions.KHR_binary_glTF||e.extensions.binary_glTF)){const t=e.bufferView?e:e.extensions.KHR_binary_glTF||e.extensions.binary_glTF;e.extensions&&(e.mimeType=t.mimeType,e.width=t.width,e.height=t.height);const s=this.gltf.bufferViews[t.bufferView],r=(s.byteOffset||0)+this.glbBuffer.byteOffset,n=s.byteLength,i=this.buffers[t.bufferView]=new Uint8Array(this.glbBuffer.buffer,r,n);return this.getImageByBuffer(i,e)}return this.requestExternalImage(e)}_getTexture(e){const t=this.gltf.textures[e];if(!t)return null;const s=this.gltf.images[t.source];return this._loadImage(s).then((e=>{const r=this.gltf.samplers[t.sampler];return{image:{array:e.data,width:e.width,height:e.height,index:t.source,mimeType:s.mimeType,name:s.name,extras:s.extras},sampler:r}}))}getBaseColorTexture(e){const t=this.gltf.materials[e];let s,r;if(t.instanceTechnique&&t.instanceTechnique.values?(s=t.instanceTechnique,r=s.values.diffuse):(s=t,r=s.values.tex||s.values.diffuseTex||s.values.diffuse),void 0===r||void 0===this.gltf.textures)return null;const n=this.gltf.textures[r];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 U=9729;class L extends N{constructor(e,t,s,r,n,i,a,o){super(r,n,i,a,o),this.rootPath=e,this.gltf=t,this.glbBuffer=s,this.buffers={},this.requests={},this.accessor=new V(e,t,s,a,o)}iterate(e,t){const s=this.gltf[t];if(s)for(let t=0;t<s.length;t++)e(t,s[t],t)}createNode(e){const t={};return _(t,e),!p(e.weights)&&this.gltf.meshes&&p(t.mesh)?t.weights=this.gltf.meshes[t.mesh].weights:e.weights&&(t.weights=e.weights),t}_getTexture(e){const t=this.gltf.textures[e];if(!t)return null;let s=t.source;if(t.extensions&&t.extensions.EXT_texture_webp?s=t.extensions.EXT_texture_webp.source:t.extensions&&t.extensions.KHR_texture_basisu&&(s=t.extensions.KHR_texture_basisu.source),!p(s))return null;const r=this.gltf.images[s];return this._loadImage(r).then((e=>{if(!e)return null;const s={image:{array:e.data,mipmap:e.mipmap,width:e.width,height:e.height,index:t.source,mimeType:r.mimeType,name:r.name,extensions:r.extensions,extras:r.extras}};_(s,t);const n=p(t.sampler)?this.gltf.samplers[t.sampler]:void 0;if(n&&(s.sampler=n,s.sampler.magFilter=n.magFilter||U,s.sampler.minFilter=n.minFilter||9987,s.sampler.wrapS=n.wrapS||10497,s.sampler.wrapT=n.wrapT||10497),"image/ktx2"===s.image.mimeType&&!s.image.mipmap&&s.sampler&&s.sampler.minFilter!==U&&9728!==s.sampler.minFilter){const e=s.sampler.minFilter;s.sampler.minFilter=9984===e||9986===e?9728:U}if(e.format&&(s.format=e.format),6407===s.format){const e=s.image.array&&s.image.array.length;e&&e===s.image.width*s.image.height*4&&(s.format=6408)}return s}))}_loadImage(e){if(!p(e.bufferView))return this.requestExternalImage(e);{const t=this.gltf.bufferViews[e.bufferView],s=this.gltf.buffers[t.buffer];if(s.uri)return this.requestImageFromBufferURI(s,t,e);if(this.glbBuffer)return this._requestFromGlbBuffer(t,e)}return null}_requestFromGlbBuffer(e,t){const s=this._createDataView(e,this.glbBuffer.buffer,this.glbBuffer.byteOffset);return this.getImageByBuffer(s,t)}_createDataView(e,t,s){s=s||0;const r=(e.byteOffset||0)+s,n=e.byteLength;return new Uint8Array(t,r,n)}_transformArrayBufferToBase64(e,t){const s=new Array(e.byteLength);for(let t=0;t<e.byteLength;t++)s[t]=String.fromCharCode(e[t]);s.join("");const r="data:"+(t=t||"image/png")+";base64,"+function(e){return"undefined"!=typeof self?self.btoa(e):window.btoa(e)}(unescape(encodeURIComponent(s)));return r}getAnimations(e){const t=[];return e.forEach((e=>{t.push(this.getSamplers(e.samplers))})),Promise.all(t).then((t=>{for(let s=0;s<t.length;s++)e[s].samplers=t[s];return e}))}getSamplers(e){const t=[];for(let s=0;s<e.length;s++)(p(e[s].input)||p(e[s].output))&&(t.push(this.accessor._requestData("input",e[s].input)),t.push(this.accessor._requestData("output",e[s].output)));return Promise.all(t).then((t=>{for(let s=0;s<t.length/2;s++)e[s].input=t[2*s],e[s].output=t[2*s+1],e[s].interpolation||(e[s].interpolation="LINEAR");return e}))}}const C="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null,F=1313821514,k=5130562;class X{static read(e,t=0,s=0){s||(s=e.byteLength);const r=new DataView(e,t,s),n=r.getUint32(4,!0);if(1===n)return X.readV1(r,t);if(2===n)return X.readV2(e,t);throw new Error("Unsupported glb version : "+n)}static readV1(e,t){const s=e.getUint32(8,!0),r=e.getUint32(12,!0);if(s!==e.byteLength)throw new Error("Length in GLB header is inconsistent with glb's byte length.");const n=K(e.buffer,20+t,r);return{json:JSON.parse(n),glbBuffer:{byteOffset:20+t+r,buffer:e.buffer,byteLength:s}}}static readV2(e,t){let s,r,n;const i=new DataView(e,t+12);let a=0;for(;a+8<i.byteLength;){const o=i.getUint32(a,!0);a+=4;const f=i.getUint32(a,!0);if(a+=4,f===F)s=K(e,t+12+a,o);else if(f===k){n=t+12+a,r=o;break}a+=o}return{json:JSON.parse(s),glbBuffer:{byteOffset:n,buffer:e,byteLength:r}}}}function K(e,t,s){if(C){const r=new Uint8Array(e,t,s);return C.decode(r)}return function(e){const t=e.length;let s="";for(let r=0;r<t;){let n=e[r++];if(128&n){let s=H[n>>3&7];if(!(64&n)||!s||r+s>t)return null;for(n&=63>>s;s>0;s-=1){const t=e[r++];if(128!=(192&t))return null;n=n<<6|63&t}}s+=String.fromCharCode(n)}return s}(new Uint8Array(e,t,s))}const H=[1,1,1,1,2,2,3,0];const j=[0,0,0],z=[0,0,0,1],W=[1,1,1],G={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},Y={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},J={_getTRSW(e,t,s,r,i,a,o,f){const u=p(e)?t.animations:[t.animations[0]],h={};for(let t=0;t<u.length;t++){const c=u[t],l=c.name||t;if(p(e)&&l!==e)continue;const m=c.channelsMap[s];if(m)for(let e=0;e<m.length;e++){const t=m[e];"translation"===t.target.path?(this._getAnimateData(i,c.samplers[t.sampler],r,1),h.translation=n(j,i)):"rotation"===t.target.path?(this._getQuaternion(a,c.samplers[t.sampler],r,1),h.rotation=d(z,a)):"scale"===t.target.path?(this._getAnimateData(o,c.samplers[t.sampler],r,1),h.scale=n(W,o)):"weights"===t.target.path&&f&&(this._getAnimateData(f,c.samplers[t.sampler],r,f.length),h.weights=f)}}return h},_getAnimateData(e,t,s,r){switch(t.interpolation){case"LINEAR":{const n=this._getPreNext(Y,t,s,1*r);n&&(e=function(e,t,s,r){for(let n=0;n<e.length;n++)e[n]=t[n]+r*(s[n]-t[n]);return e}(e,n.PREVIOUS,n.NEXT,n.INTERPOLATION));break}case"STEP":{const n=this._getPreNext(Y,t,s,1*r);n&&(e=function(e,t){for(let s=0;s<e.length;s++)e[s]=t[s];return e}(e,...n.PREVIOUS));break}case"CUBICSPLINE":{const n=this._getPreNext(Y,t,s,3*r);n&&(e=this._getCubicSpline(e,n,t.input.array,3*r));break}}return e},_getQuaternion(e,t,s){switch(t.interpolation){case"LINEAR":{const r=this._getPreNext(Y,t,s,1);r&&c(e,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this._getPreNext(Y,t,s,1);r&&(e=f(e,...r.PREVIOUS));break}case"CUBICSPLINE":{const r=this._getPreNext(Y,t,s,3);if(r){for(let e=0;e<r.PREVIOUS.length;e++)r.PREVIOUS[e]=Math.acos(r.PREVIOUS[e]),r.NEXT[e]=Math.acos(r.NEXT[e]);e=this._getCubicSpline(e,r,t.input.array,3);for(let t=0;t<e.length;t++)e[t]=Math.cos(e[t])}break}}return e},_search(e,t){const s=e.length;let r,n,i,a=0,o=s-1,f=Math.floor((a+o)/2);for(;a<=s-1&&o>=0;){if(a===o)return null;if(e[f]<=t&&t<=e[f+1]){const s=e[f];return r=f,n=f+1,i=(t-s)/(e[f+1]-s),{preIndx:r,nextIndex:n,interpolation:i}}t<e[f]?(o=f,f=Math.floor((a+o)/2)):e[f+1]<t&&(a=f,f=Math.floor((a+o)/2))}return null},_getPreNext(e,t,s,r){const n=t.input.array,i=t.output.array,a=t.output.itemSize;(s<n[0]||s>n[n.length-1])&&(s=Math.max(n[0],Math.min(n[n.length-1],s))),s===n[n.length-1]&&(s=n[0]);const o=this._search(n,s);if(!o||!o.nextIndex)return null;const{preIndx:f,nextIndex:u,interpolation:h}=o;e.PREINDEX=f,e.NEXTINDEX=u,e.INTERPOLATION=h;const c=a*r;return e.PREVIOUS=i.subarray(e.PREINDEX*c,(e.PREINDEX+1)*c),e.NEXT=i.subarray(e.NEXTINDEX*c,(e.NEXTINDEX+1)*c),e},_getCubicSpline(e,t,s,r){const n=t.INTERPOLATION,i=s[t.PREINDEX],a=s[t.NEXTINDEX];for(let s=0;s<3;s++){const o=t.PREVIOUS[r+s],f=(a-i)*t.PREVIOUS[2*r+s],u=t.NEXT[3+s],h=(a-i)*t.NEXT[s],c=(2*Math.pow(n,3)-3*Math.pow(n,2)+1)*o+(Math.pow(n,3)-2*Math.pow(n,2)+n)*f+(2*-Math.pow(n,3)+3*Math.pow(n,2))*u+(Math.pow(n,3)-Math.pow(n,2))*h;e[s]=c}return e},getAnimationClip(e,t,s,r){const n=e.nodes[t]&&e.nodes[t].weights;i(j,...G.TRANSLATION),f(z,...G.ROTATION),i(W,...G.SCALE);return this._getTRSW(r,e,t,s,j,z,W,n)},getTimeSpan(e){if(!e.animations)return null;if(e.timeSpan)return e.timeSpan;const t=e.animations;return e.timeSpan={},t.forEach(((t,s)=>{let r=-1/0,n=1/0;const i=t.channels;for(let e=0;e<i.length;e++){const s=i[e],a=t.samplers[s.sampler].input.array;a[a.length-1]>r&&(r=a[a.length-1]),a[0]<n&&(n=a[0])}const a=t.name||s;e.timeSpan[a]={max:r,min:n}})),e.timeSpan},getTimeSpanByName(e,t){const s=this.getTimeSpan(e);return s?p(t)?s[t]:s[Object.keys(s)[0]]:null}},$="EXT_mesh_gpu_instancing";const Q="EXT_structural_metadata";let Z=!1;if("undefined"!=typeof OffscreenCanvas){let e;try{e=new OffscreenCanvas(2,2).getContext("2d")}catch(e){}e&&"undefined"!=typeof createImageBitmap&&(Z=!0)}const ee="undefined"==typeof document?null:document.createElement("canvas");class te{constructor(e,t,s){if(this.options=s||{},this.options.decoders||(this.options.decoders={}),this._fetchOptions=this.options.fetchOptions||{},t.buffer instanceof ArrayBuffer){const{json:s,glbBuffer:r}=X.read(t.buffer,t.byteOffset,t.byteLength);this._init(e,s,r)}else this._init(e,t);this._accessor=new V(this.rootPath,this.gltf,this.glbBuffer,this._fetchOptions,this.options.urlModifier),this._checkExtensions()}_checkExtensions(){const e=this.gltf.extensionsRequired;if(e){if(e.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(e.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(e.indexOf("EXT_meshopt_compression")>=0)throw new Error("EXT_meshopt_compression extension is not supported yet.")}}_loadExtensions(){const e=this.gltf.extensions;return e&&e.KHR_techniques_webgl?this._accessor.requestKHRTechniquesWebgl(e.KHR_techniques_webgl).then((t=>(e.KHR_techniques_webgl=t,e))):Promise.resolve(e)}_convertKhrTechiqueToTechiques(){if(!Array.isArray(this.gltf.programs))return;const e=this.gltf.materials;for(let t=0;t<e.length;t++)e[t]&&e[t].extensions&&e[t].extensions.KHR_technique_webgl&&(e[t].extensions.KHR_techniques_webgl=e[t].extensions.KHR_technique_webgl,delete e[t].extensions.KHR_technique_webgl);const t=this.gltf.extensions||{},s=this.gltf.techniques;t.KHR_techniques_webgl={programs:this.gltf.programs,shaders:this.gltf.shaders,techniques:s};for(let t=0;t<e.length;t++){const n=(r=e[t])&&r.extensions&&r.extensions.KHR_techniques_webgl;if(n){const{values:e,technique:t}=n,r=s[t];if(!r||!e)continue;const{uniforms:i,parameters:a}=r,o={};for(const t in e){const s=de(i,t);o[s]=e[t],a[t]&&35678===a[t].type&&(o[s]={index:e[t]})}n.values=o}}var r;for(let e=0;e<s.length;e++){const t=s[e];if(!t)continue;const{attributes:r,uniforms:n,parameters:i}=t;if(r)for(const e in r){const t=r[e];r[e]=i[t]}if(n)for(const e in n){const t=n[e];n[e]=i[t]}delete t.parameters}return delete this.gltf.programs,delete this.gltf.shaders,delete this.gltf.techniques,this.gltf.extensions=t,t}load(e){e=e||{},this._convertKhrTechiqueToTechiques();const t=this._loadScene(e),s=this._loadAnimations(),r=this._loadTextures(),n=this._loadExtensions(),i=this._loadStructuralMetadata();return Promise.all([t,s,r,n,i]).then((e=>(e[0].animations=e[1],e[0].textures=e[2],e[0].extensions=e[3],e[0].transferables=this.transferables||[],e[0].structuralMetadata=e[4],this.createChannelsMap(e[0]),e[0])))}createChannelsMap(e){const t=e.animations;if(t)for(let e=0;e<t.length;e++){const s=t[e];s.channelsMap={};for(let e=0;e<s.channels.length;e++){const t=s.channels[e];s.channelsMap[t.target.node]||(s.channelsMap[t.target.node]=[]),s.channelsMap[t.target.node].push(t)}}}getExternalResources(){const e=[];if(this.gltf){const{buffers:t,images:s}=this.gltf;for(let s=0;s<t.length;s++)t[s].uri&&t[s].uri.indexOf("data:application/octet-stream;base64")<0&&e.push({type:"buffer",uri:t[s].uri});for(let t=0;t<s.length;t++)s[t].uri&&s[t].uri.indexOf("data:image/")<0&&e.push({type:"image",uri:s[t].uri})}return e}static getAnimationClip(e,t,s,r){return J.getAnimationClip(e,t,s,r)}static getAnimationTimeSpan(e,t){return J.getTimeSpanByName(e,t)}static getTypedArrayCtor(e){return y(e)}static readInterleavedArray(e,t,s,r,n,i,a){return q(e,t,s,r,n,i,a)}_init(e,t,s){this.gltf=t,this.glbBuffer=s,this.version=t.asset?+t.asset.version:1,this.rootPath=e,this.buffers={},this.requests={},this.options.requestImage=Z?fe.bind(this):this.options.requestImage||se,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new L(e,t,s,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this._fetchOptions,this.options.urlModifier),this.adapter.iterate(((e,t,s)=>{t.id="buffer_"+s}),"buffers"),this.adapter.iterate(((e,t,s)=>{t.id="image_"+s}),"images"),this.adapter.iterate(((e,t,s)=>{t.id="accessor_"+s}),"accessors")):(this.adapter=new D(e,t,s,this.options.requestImage,this.options.decoders||{},this.options.supportedFormats||{},this._fetchOptions,this.options.urlModifier),this.adapter.iterate(((e,t,s)=>{t.id="accessor_"+s}),"accessors"),this.adapter.iterate(((e,t,s)=>{t.id="image_"+s}),"images"))}_parseNodes(e,t){if(e.children&&e.children.length>0){if(!(s=e.children[0],"number"==typeof s&&isFinite(s)||b(e.children[0])))return e;const r=e.children.map((e=>{const s=t[e];return s.nodeIndex=e,this._parseNodes(s,t)}));e.children=r}var s;return e}_loadScene(e){return this._loadNodes(e).then((e=>{const t=this.scenes=[];let s;for(const t in e)e[t]=this._parseNodes(e[t],e),e[t].nodeIndex=Number(t)?Number(t):t;this.adapter.iterate(((r,n,i)=>{const a={};n.name&&(a.name=n.name),n.nodes&&(a.nodes=n.nodes.map((t=>e[t]))),this.gltf.scene===r&&(s=i),t.push(a)}),"scenes");const r={textures:this.gltf.textures,asset:this.gltf.asset,scene:s,scenes:t,nodes:e,meshes:this.meshes,materials:this.gltf.materials,skins:this.skins,extensionsRequired:this.gltf.extensionsRequired,extensionsUsed:this.gltf.extensionsUsed};if(this.gltf.extensions&&(r.extensions=this.gltf.extensions),1===this.version){const e=this.adapter._loadMaterials(this.gltf.materials);r.materials=e}return delete this.gltf.buffers,r.json=this.gltf,r}))}_loadNodes(e){return this._loadMeshes(e).then((()=>{const e=this.nodes={},t=[];return this.adapter.iterate(((s,r)=>{const n=this.adapter.createNode(r,this.meshes,this.skins);e[s]=n;const i=function(e){return e?.extensions?.[$]}(r);if(i){const e=this._loadGpuInstancingData(i).then((e=>{n.extensions||(n.extensions={}),n.extensions[$]=e}));t.push(e)}}),"nodes"),Promise.all(t).then((()=>e))}))}_loadGpuInstancingData(e){const t=function(e){return e?.attributes?Object.entries(e.attributes).map((([e,t])=>({name:e,accessorIndex:t}))):[]}(e);if(0===t.length)return Promise.resolve({attributes:{}});const s=t.map((({name:e,accessorIndex:t})=>this.adapter.accessor._requestData(e,t).then((t=>(t&&t.array&&t.array.buffer&&this.transferables&&this.transferables.indexOf(t.array.buffer)<0&&this.transferables.push(t.array.buffer),{name:e,data:t})))));return Promise.all(s).then((e=>{const t={};return e.forEach((({name:e,data:s})=>{t[e]=s})),{attributes:t}}))}_loadSkins(){this.skins=[];const e=[];return this.adapter.iterate(((t,s,r)=>{e.push(this._loadSkin(s).then((e=>{e.index=r,this.skins.push(e)})))}),"skins"),e}_loadSkin(e){const t=e.inverseBindMatrices;return this.adapter.accessor._requestData("inverseBindMatrices",t).then((t=>(e.inverseBindMatrices=t,t&&t.buffer&&this.transferables&&this.transferables.indexOf(t.buffer)<0&&this.transferables.push(t.buffer),e)))}_loadAnimations(){const e=this.gltf.animations;return p(e)?this.adapter.getAnimations(e):null}_loadMeshes(e){this.meshes={};let t=[];return this.adapter.iterate(((s,r,n)=>{t.push(this._loadMesh(r,e).then((e=>{e.index=n,this.meshes[s]=e})))}),"meshes"),t=t.concat(this._loadSkins()),Promise.all(t)}_loadMesh(e,t){const s=e.primitives.map((e=>this._loadPrimitive(e,t))).filter((e=>!!e));return Promise.all(s).then((t=>{const s={};return _(s,e),s.primitives=t,s}))}_loadTextures(){const e=this.gltf.textures;if(!e)return null;const t=[];for(const s in e)t.push(this.adapter._getTexture(s));return Promise.all(t).then((t=>{if(this.transferables)for(let e=0;e<t.length;e++){const s=t[e]&&t[e].image.array;if(s){let e;e=s instanceof ImageBitmap?s:s.buffer,e&&this.transferables.indexOf(e)<0&&this.transferables.push(e)}}if(!Array.isArray(e)){const s={},r=Object.keys(e);for(let e=0;e<t.length;e++)t[e]&&(s[r[e]]=t[e]);return s}return t}))}_loadPrimitive(e,t){let s;const r=[],n=e.extensions;if(p(e.targets))for(let t=0;t<e.targets.length;t++){const s=e.targets[t];for(const e in s){const n=this.adapter.accessor._requestData(`morphTargets_${e}_${t}`,s[e]);n&&r.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 e=this.options.decoders.draco,{bufferView:i,attributes:a}=n.KHR_draco_mesh_compression,o=this.gltf.bufferViews[i],f=this._accessor._requestBufferOfBufferView(o).then((s=>{const{buffer:r,byteOffset:n}=s;let{byteOffset:i}=o;const f=o.byteLength;i||(i=0);const u=new DataView(r,n+i,f),h={attributes:a,useUniqueIDs:!1,skipAttributeTransform:t.skipAttributeTransform};return e(u,h).then((e=>{const t=Object.values(e.attributes);return e.indices&&t.push(e.indices),t}))}));r.push(f),s=Promise.all(r)}else{const t=e.attributes;for(const e in t){const s=this.adapter.accessor._requestData(e,t[e]);s&&r.push(s)}if(p(e.indices)){const t=this.adapter.accessor._requestData("indices",e.indices);t&&r.push(t)}s=Promise.all(r)}return s.then((t=>{if(n&&n.KHR_draco_mesh_compression){const s=e.targets?e.targets.length:0;t[s]=t[s].concat(t.slice(0,s)),t=t[s]}let s,r;const i={attributes:t.reduce(((e,t)=>{if("indices"===t.name)s=t;else if(t.name.indexOf("morphTargets_")>-1)r=r||{},r[t.name.slice(13)]=t;else{if(!("POSITION"!==t.name||t.min&&t.max)){const e=[1/0,1/0,1/0],s=[-1/0,-1/0,-1/0],{itemSize:r,array:n}=t,i=n.length/r;for(let t=0;t<i;t++)for(let i=0;i<r;i++){const a=t*r+i;n[a]<e[i]&&(e[i]=n[a]),n[a]>s[i]&&(s[i]=n[a])}if(t.quantization){const r=t.quantization,n=r.range/(1<<r.quantizationBits),i=r.minValues;o(e,e,n),a(e,e,i),o(s,s,n),a(s,s,i)}t.min=e,t.max=s}e[t.name]=t}return this.transferables&&t.array.buffer&&this.transferables.indexOf(t.array.buffer)<0&&this.transferables.push(t.array.buffer),e}),{}),material:e.material};return s&&(i.indices=s),r&&(i.morphTargets=r),i.mode=p(e.mode)?e.mode:4,p(e.extras)&&(i.extras=e.extras),e.extensions&&(i.extensions=e.extensions),i}))}_loadStructuralMetadata(){const e=this.gltf.extensionsUsed||[],t=e.includes("EXT_mesh_features"),s=e.includes(Q);if(!t&&!s)return Promise.resolve();const r=[];if(s){const e=this.gltf.extensions?.[Q];e?.propertyTables&&r.push(this._loadPropertyTableBuffers(e.propertyTables))}return Promise.all(r).then((e=>{const t=e[0]||[];if(s)return async function(e,t,s,r,n){const i=e?.extensions?.[Q];if(!i)return null;if(i.schemaUri){let e=i.schemaUri;return e.includes("://")||e.startsWith("blob:")||(e=s+e),{schema:await P.getJSON(e,r,n),propertyTables:i.propertyTables||[],buffers:t}}return{schema:i.schema,propertyTables:i.propertyTables||[],buffers:t}}(this.gltf,t,this.rootPath,this._fetchOptions,this.options.urlModifier).then((e=>(e&&t.forEach((e=>{e&&this.transferables.indexOf(e)<0&&this.transferables.push(e)})),e)))}))}_loadPropertyTableBuffers(e){const t=this.gltf.bufferViews||[],s=function(e){const t=new Set;if(!e)return t;for(const s of e){const e=s.properties;if(e)for(const s of Object.values(e))void 0!==s.values&&t.add(s.values),void 0!==s.arrayOffsets&&t.add(s.arrayOffsets),void 0!==s.stringOffsets&&t.add(s.stringOffsets)}return t}(e),r=new Array(t.length).fill(null),n=[];return s.forEach((e=>{const s=t[e];if(!s)return;const i=this._accessor._requestBufferOfBufferView(s).then((t=>{const{buffer:n,byteOffset:i}=t,a=(s.byteOffset||0)+i;r[e]=n.slice(a,a+s.byteLength)}));n.push(i)})),Promise.all(n).then((()=>r))}}function se(e,t,s){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!ee)return void s(new Error("There is no canvas to draw image!"));ee.width=r.width,ee.height=r.height;const e=ee.getContext("2d",{willReadFrequently:!0});e.drawImage(r,0,0,r.width,r.height);const t=e.getImageData(0,0,r.width,r.height),n={width:r.width,height:r.height,data:new Uint8Array(t.data)};s(null,n)},r.onerror=function(e){s(e)},r.src=e}const re=[],ne=[],ie=30;let ae,oe;function fe(e,t,s){ae||(ae=new OffscreenCanvas(2,2),oe=ae.getContext("2d",{willReadFrequently:!0}));let r=null;if(b(e))this.options.urlModifier&&(e=this.options.urlModifier(e)),re.push([e,t,s,this]),ue();else{const t=new Blob([e]);r=createImageBitmap(t),r.then(he.bind(this)).then((e=>{s(null,e)})).catch((e=>{console.warn(e),s(e)}))}}function ue(){if(!re.length||ne.length>ie)return;const e=re.shift(),[t,s,r,n]=e;ne.push(e),fetch(t,s).then((e=>e.arrayBuffer())).then((e=>{const t=new Blob([new Uint8Array(e)]);return createImageBitmap(t)})).then(he.bind(n)).then((t=>{r.call(n,null,t);const s=ne.indexOf(e);ne.splice(s,1),ue()})).catch((t=>{console.warn(t),r.call(n,t);const s=ne.indexOf(e);ne.splice(s,1),ue()}))}function he(e){let{width:t,height:s}=e;ce(t)||(t=le(t)),ce(s)||(s=le(s));const r=this.options.maxTextureSize;r&&(t=Math.min(r,t),s=Math.min(r,s)),ae.width=t,ae.height=s,oe.drawImage(e,0,0,t,s),e.close();const n=oe.getImageData(0,0,t,s);return{width:t,height:s,data:new Uint8Array(n.data)}}function ce(e){return!(e&e-1)&&0!==e}function le(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))}function de(e,t){for(const s in e)if(e[s]===t)return s;return t}export{P as Ajax,te as GLTFLoader};
//# sourceMappingURL=gltf-loader.es.js.map
{
"name": "@maptalks/gltf-loader",
"version": "0.121.0",
"version": "0.122.0",
"description": "",

@@ -5,0 +5,0 @@ "module": "dist/gltf-loader.es.js",

Sorry, the diff of this file is too big to display