@maptalks/gl
Version:
WebGL infrastrcture for maptalks
125 lines (108 loc) • 1.36 MB
JavaScript
/*!
* @maptalks/gl v0.118.1
* LICENSE : UNLICENSED
* (c) 2016-2025 maptalks.com
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('maptalks')) :
typeof define === 'function' && define.amd ? define(['exports', 'maptalks'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.maptalks = global.maptalks || {}, global.maptalks));
})(this, (function (exports, e$2) { 'use strict';
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var e__namespace = /*#__PURE__*/_interopNamespaceDefault(e$2);
const getGlobal = function () {
if (typeof globalThis !== 'undefined') { return globalThis; }
if (typeof self !== 'undefined') { return self; }
if (typeof window !== 'undefined') { return window; }
if (typeof global !== 'undefined') { return global; }
throw new Error('unable to locate global object');
};
const globals = getGlobal();
const transcoders = globals['gl_trans__coders'] = globals['gl_trans__coders'] || {};
function inject(chunk) {
// 奇怪的变量名是为了避免与worker源代码中的变量名冲突
const fnString = chunk.toString();
const prefixIndex = fnString.indexOf('{') + 1;
const prefix = fnString.substring(0, prefixIndex);
const transcoders = globals['gl_trans__coders'] = globals['gl_trans__coders'] || {};
let injected = `${prefix}
const _____getGlobal = ${getGlobal.toString()};
const g___lobals = _____getGlobal()
const tran_____scoders = g___lobals['gl_trans__coders'] = g___lobals['gl_trans__coders'] || {};`;
for (const p in transcoders) {
if (p === 'inject' || p === 'getTranscoder' || p === 'registerTranscoder') {
continue;
}
injected += 'tran_____scoders["' + p + '"] =' + transcoders[p].toString() + '\n;';
}
const gltfBundle = getGlobal()['maptalks_gltf_loader_bundle'];
injected += '\n(' + gltfBundle.toString() + ')({});\n';
injected += '\n' + fnString.substring(prefix.length);
return injected;
}
transcoders['inject'] = inject;
function getTranscoder(name/*, options*/) {
return transcoders[name];
}
function registerTranscoder(name, fn) {
transcoders[name] = fn;
}
function registerGLTFLoaderBundle(fn) {
getGlobal()['maptalks_gltf_loader_bundle'] = fn;
}
transcoders.registerTranscoder = registerTranscoder;
transcoders.getTranscoder = getTranscoder;
function gltfLoaderExport(e){var t=function(){return "undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0};if(t().maptalks_gltf_loader)return;
/*!
* @maptalks/gltf-loader v0.118.1
* LICENSE : UNLICENSED
* (c) 2016-2025 maptalks.org
*/var s="undefined"!=typeof Float32Array?Float32Array:Array;function r(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 n(){var e=new s(3);return s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function i(e,t,r){var n=new s(3);return n[0]=e,n[1]=t,n[2]=r,n}function a(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e}function o(e,t,s,r){return e[0]=t,e[1]=s,e[2]=r,e}function f(e,t,s){return e[0]=t[0]+s[0],e[1]=t[1]+s[1],e[2]=t[2]+s[2],e}function u(e,t,s){return e[0]=t[0]*s,e[1]=t[1]*s,e[2]=t[2]*s,e}function h(e,t,s,r,n){return e[0]=t,e[1]=s,e[2]=r,e[3]=n,e}function c(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 l(){var e=new s(4);return s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e[3]=1,e}Math.hypot||(Math.hypot=function(){for(var e=0,t=arguments.length;t--;)e+=arguments[t]*arguments[t];return Math.sqrt(e)}),n(),function(){var e;e=new s(4),s!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0);}();var d,m=function(e,t){return e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e};n(),i(1,0,0),i(0,1,0),l(),l(),d=new s(9),s!=Float32Array&&(d[1]=0,d[2]=0,d[3]=0,d[5]=0,d[6]=0,d[7]=0),d[0]=1,d[4]=1,d[8]=1;let g=0;function p(e){return null==e}function b(e){return !p(e)}function _(e){return !p(e)&&("string"==typeof e||null!==e.constructor&&e.constructor===String)}function y(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 x(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 w(e){return 0===e.indexOf("data:")&&e.indexOf("base64,")>0}function T(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 E=[],O=[],I=[],R=[0,0,0],A=function(e){return e[0]=0,e[1]=0,e[2]=0,e[3]=1,e}([]),q=[1,1,1];function B(e,t,s,r,n,i,a){const o=x(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 N="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;function v(e,t,s){const r=new Uint8Array(e,t,s);return N.decode(r)}const P={get:function(e,t={},s){t||(t={});const r=new AbortController,n=r.signal,i=y({},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))},jsonp:function(e){const t="_maptalks_jsonp_"+g++;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 M{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(w(e.uri)){const r=this.buffers[e.id]=T(e.uri),n=this._createDataView(t,r);return this.getImageByBuffer(n,s)}let r;const n=e.uri.indexOf("blob:")>=0;return r=e.uri.indexOf("://")>0||n?e.uri:this.rootPath+"/"+e.uri,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;return this._imgRequests[e.id]?this._imgRequests[e.id].then((()=>this.images[e.id])):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 S=["SCALAR",1,"VEC2",2,"VEC3",3,"VEC4",4,"MAT2",4,"MAT3",9,"MAT4",16],V=[];class L{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(w(t.uri)){const e=this.buffers[t.id]=T(t.uri);return Promise.resolve({buffer:e,byteOffset:0})}let e;const s=t.uri.indexOf("blob:")>=0;return e=t.uri.indexOf("://")>0||s?t.uri:this.rootPath+"/"+t.uri,this.requests[t.id]=P.getArrayBuffer(e,this._fetchOptions,!s&&this._urlModifier).then((r=>(s&&URL.revokeObjectURL(e),{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),u=x(i.componentType),h=a.byteStride||0,l={array:void 0,name:e,accessorName:t,byteLength:i.count*f*u.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=h,l.byteOffset=o+(i.byteOffset||0),!h||h===f*u.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),u),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 u(i.count*f);if(l.array=B(e,s,i.count,f,h,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){V[0]=l.array[s],V[1]=l.array[s+1],V[2]=l.array[s+2],V[3]=1;const r=c(V,V,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),u),l.byteOffset=l.array.byteOffset;else {l.array=new u(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=S.indexOf(e);return S[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=v(n,i+(t.byteOffset||0),s);return e.content=a,e}))}if(e.uri){if(w(e.uri)){const t=T(e.uri),s=v(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 M{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 L(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 t={};if(b(e.name)&&(t.name=e.name),b(e.children)&&(t.children=e.children),b(e.jointName)&&(t.jointName=e.jointName),b(e.matrix)&&(t.matrix=e.matrix),b(e.rotation)&&(t.rotation=e.rotation),b(e.scale)&&(t.scale=e.scale),b(e.translation)&&(t.translation=e.translation),b(e.extras)&&(t.extras=e.extras),b(e.meshes)&&(t.mesh=e.meshes[0]),t.translation||t.rotation||t.scale){const e=function(e,t){if(t.matrix)return t.matrix;if(t.translation||t.scale||t.rotation){const s=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}(E,t.translation||R),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,t.rotation||A),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}(I,t.scale||q);return r(i,n,i),r(e,s,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)}([],t);delete t.translation,delete t.rotation,delete t.scale,t.matrix=e;}return t}_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 C extends M{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 L(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 y(t,e),!b(e.weights)&&this.gltf.meshes&&b(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),!b(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}};y(s,t);const n=b(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(!b(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++)(b(e[s].input)||b(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 F="undefined"!=typeof TextDecoder?new TextDecoder("utf-8"):null;class k{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 k.readV1(r,t);if(2===n)return k.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=X(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,1313821514===f)s=X(e,t+12+a,o);else if(5130562===f){n=t+12+a,r=o;break}a+=o;}return {json:JSON.parse(s),glbBuffer:{byteOffset:n,buffer:e,byteLength:r}}}}function X(e,t,s){if(F){const r=new Uint8Array(e,t,s);return F.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=K[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 K=[1,1,1,1,2,2,3,0],H=[0,0,0],j=[0,0,0,1],z=[1,1,1],W={TRANSLATION:[0,0,0],ROTATION:[0,0,0,1],SCALE:[1,1,1]},G={PREVIOUS:null,NEXT:null,PREINDEX:null,NEXTINDEX:null,INTERPOLATION:null},Y={_getTRSW(e,t,s,r,n,i,o,f){const u=b(e)?t.animations:[t.animations[0]],h={};for(let t=0;t<u.length;t++){const c=u[t],l=c.name||t;if(b(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(n,c.samplers[t.sampler],r,1),h.translation=a(H,n)):"rotation"===t.target.path?(this._getQuaternion(i,c.samplers[t.sampler],r,1),h.rotation=m(j,i)):"scale"===t.target.path?(this._getAnimateData(o,c.samplers[t.sampler],r,1),h.scale=a(z,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&&function(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];(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,r.PREVIOUS,r.NEXT,r.INTERPOLATION);break}case"STEP":{const r=this._getPreNext(G,t,s,1);r&&(e=h(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;return o(H,...W.TRANSLATION),h(j,...W.ROTATION),o(z,...W.SCALE),this._getTRSW(r,e,t,s,H,j,z,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?b(t)?s[t]:s[Object.keys(s)[0]]:null}};let $=!1;if("undefined"!=typeof OffscreenCanvas){let e;try{e=new OffscreenCanvas(2,2).getContext("2d");}catch(s){}e&&"undefined"!=typeof createImageBitmap&&($=!0);}const J="undefined"==typeof document?null:document.createElement("canvas");function Q(e,t,s){const r=new Image;r.crossOrigin="",r.onload=()=>{if(!J)return void s(new Error("There is no canvas to draw image!"));J.width=r.width,J.height=r.height;const e=J.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 Z=[],ee=[],te=30;let se,re;function ne(e,t,s){se||(se=new OffscreenCanvas(2,2),re=se.getContext("2d",{willReadFrequently:!0}));let r=null;if(_(e))this.options.urlModifier&&(e=this.options.urlModifier(e)),Z.push([e,t,s,this]),ie();else {const t=new Blob([e]);r=createImageBitmap(t),r.then(ae.bind(this)).then((e=>{s(null,e);})).catch((e=>{console.warn(e),s(e);}));}}function ie(){if(!Z.length||ee.length>te)return;const e=Z.shift(),[t,s,r,n]=e;ee.push(e),fetch(t,s).then((e=>e.arrayBuffer())).then((e=>{const t=new Blob([new Uint8Array(e)]);return createImageBitmap(t)})).then(ae.bind(n)).then((t=>{r.call(n,null,t);const s=ee.indexOf(e);ee.splice(s,1),ie();})).catch((t=>{console.warn(t),r.call(n,t);const s=ee.indexOf(e);ee.splice(s,1),ie();}));}function ae(e){let{width:t,height:s}=e;oe(t)||(t=fe(t)),oe(s)||(s=fe(s));const r=this.options.maxTextureSize;r&&(t=Math.min(r,t),s=Math.min(r,s)),se.width=t,se.height=s,re.drawImage(e,0,0,t,s),e.close();const n=re.getImageData(0,0,t,s);return {width:t,height:s,data:new Uint8Array(n.data)}}function oe(e){return !(e&e-1)&&0!==e}function fe(e){return Math.pow(2,Math.floor(Math.log(e)/Math.LN2))}function ue(e,t){for(const s in e)if(e[s]===t)return s;return t}e.Ajax=P,e.GLTFLoader=class{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}=k.read(t.buffer,t.byteOffset,t.byteLength);this._init(e,s,r);}else this._init(e,t);this._accessor=new L(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=ue(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 Y.getAnimationClip(e,t,s,r)}static getAnimationTimeSpan(e,t){return Y.getTimeSpanByName(e,t)}static getTypedArrayCtor(e){return x(e)}static readInterleavedArray(e,t,s,r,n,i,a){return B(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=$?ne.bind(this):this.options.requestImage||Q,this.options.transferable&&(this.transferables=[]),2===this.version?(this.adapter=new C(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(!("number"==typeof(s=e.children[0])&&isFinite(s)||_(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 b(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 y(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(b(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(b(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;u(e,e,n),f(e,e,i),u(s,s,n),f(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=b(e.mode)?e.mode:4,b(e.extras)&&(i.extras=e.extras),i}))}},t().maptalks_gltf_loader=e;}gltfLoaderExport({});
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
var regl_min = {exports: {}};
(function (module, exports) {
(function(U,X){module.exports=X();})(commonjsGlobal,function(){function U(a,b){this.id=Cb++;this.type=a;this.data=b;}function X(a){if(0===a.length)return [];var b=a.charAt(0),c=a.charAt(a.length-1);if(1<a.length&&b===c&&('"'===b||"'"===b))return ['"'+a.substr(1,a.length-2).replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'];if(b=/\[(false|true|null|\d+|'[^']*'|"[^"]*")\]/.exec(a))return X(a.substr(0,
b.index)).concat(X(b[1])).concat(X(a.substr(b.index+b[0].length)));b=a.split(".");if(1===b.length)return ['"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'];a=[];for(c=0;c<b.length;++c)a=a.concat(X(b[c]));return a}function ab(a){return "["+X(a).join("][")+"]"}function bb(a,b){if("function"===typeof a)return new U(0,a);if("number"===typeof a||"boolean"===typeof a)return new U(5,a);if(Array.isArray(a))return new U(6,a.map(function(a,e){return bb(a)}));if(a instanceof U)return a}function Db(){var a=
{"":0},b=[""];return {id:function(c){var e=a[c];if(e)return e;e=a[c]=b.length;b.push(c);return e},str:function(a){return b[a]}}}function Eb(a,b,c){function e(){var b=window.innerWidth,e=window.innerHeight;a!==document.body&&(e=a.getBoundingClientRect(),b=e.right-e.left,e=e.bottom-e.top);f.width=c*b;f.height=c*e;F(f.style,{width:b+"px",height:e+"px"});}var f=document.createElement("canvas");F(f.style,{border:0,margin:0,padding:0,top:0,left:0});a.appendChild(f);a===document.body&&(f.style.position="absolute",
F(a.style,{margin:0,padding:0}));var d;a!==document.body&&"function"===typeof ResizeObserver?(d=new ResizeObserver(function(){setTimeout(e);}),d.observe(a)):window.addEventListener("resize",e,!1);e();return {canvas:f,onDestroy:function(){d?d.disconnect():window.removeEventListener("resize",e);a.removeChild(f);}}}function Fb(a,b){function c(c){try{return a.getContext(c,b)}catch(f){return null}}return c("webgl")||c("experimental-webgl")||c("webgl-experimental")}function cb(a){return "string"===typeof a?
a.split():a}function db(a){return "string"===typeof a?document.querySelector(a):a}function Gb(a){var b=a||{},c,e,f,d;a={};var p=[],r=[],v="undefined"===typeof window?1:window.devicePixelRatio,m=!1,u=function(a){},n=function(){};"string"===typeof b?c=document.querySelector(b):"object"===typeof b&&("string"===typeof b.nodeName&&"function"===typeof b.appendChild&&"function"===typeof b.getBoundingClientRect?c=b:"function"===typeof b.drawArrays||"function"===typeof b.drawElements?(d=b,f=d.canvas):("gl"in
b?d=b.gl:"canvas"in b?f=db(b.canvas):"container"in b&&(e=db(b.container)),"attributes"in b&&(a=b.attributes),"extensions"in b&&(p=cb(b.extensions)),"optionalExtensions"in b&&(r=cb(b.optionalExtensions)),"onDone"in b&&(u=b.onDone),"profile"in b&&(m=!!b.profile),"pixelRatio"in b&&(v=+b.pixelRatio)));c&&("canvas"===c.nodeName.toLowerCase()?f=c:e=c);if(!d){if(!f){c=Eb(e||document.body,u,v);if(!c)return null;f=c.canvas;n=c.onDestroy;}void 0===a.premultipliedAlpha&&(a.premultipliedAlpha=!0);d=Fb(f,a);}return d?
{gl:d,canvas:f,container:e,extensions:p,optionalExtensions:r,pixelRatio:v,profile:m,onDone:u,onDestroy:n}:(n(),u("webgl not supported, try upgrading your browser or graphics drivers http://get.webgl.org"),null)}function Hb(a,b){function c(b){b=b.toLowerCase();var c;try{c=e[b]=a.getExtension(b);}catch(f){}return !!c}for(var e={},f=0;f<b.extensions.length;++f){var d=b.extensions[f];if(!c(d))return b.onDestroy(),b.onDone('"'+d+'" extension is not supported by the current WebGL context, try upgrading your system or a different browser'),
null}b.optionalExtensions.forEach(c);return {extensions:e,restore:function(){Object.keys(e).forEach(function(a){if(e[a]&&!c(a))throw Error("(regl): error restoring extension "+a);});}}}function J(a,b){for(var c=Array(a),e=0;e<a;++e)c[e]=b(e);return c}function eb(a){var b,c;b=(65535<a)<<4;a>>>=b;c=(255<a)<<3;a>>>=c;b|=c;c=(15<a)<<2;a>>>=c;b|=c;c=(3<a)<<1;return b|c|a>>>c>>1}function fb(){function a(a){a:{for(var b=16;268435456>=b;b*=16)if(a<=b){a=b;break a}a=0;}b=c[eb(a)>>2];return 0<b.length?b.pop():
new ArrayBuffer(a)}function b(a){c[eb(a.byteLength)>>2].push(a);}var c=J(8,function(){return []});return {alloc:a,free:b,allocType:function(b,c){var d=null;switch(b){case 5120:d=new Int8Array(a(c),0,c);break;case 5121:d=new Uint8Array(a(c),0,c);break;case 5122:d=new Int16Array(a(2*c),0,c);break;case 5123:d=new Uint16Array(a(2*c),0,c);break;case 5124:d=new Int32Array(a(4*c),0,c);break;case 5125:d=new Uint32Array(a(4*c),0,c);break;case 5126:d=new Float32Array(a(4*c),0,c);break;default:return null}return d.length!==
c?d.subarray(0,c):d},freeType:function(a){b(a.buffer);}}}function ga(a){return !!a&&"object"===typeof a&&Array.isArray(a.shape)&&Array.isArray(a.stride)&&"number"===typeof a.offset&&a.shape.length===a.stride.length&&(Array.isArray(a.data)||K(a.data))}function gb(a,b,c,e,f,d){for(var p=0;p<b;++p)for(var r=a[p],v=0;v<c;++v)for(var m=r[v],u=0;u<e;++u)f[d++]=m[u];}function hb(a,b,c,e,f){for(var d=1,p=c+1;p<b.length;++p)d*=b[p];var r=b[c];if(4===b.length-c){var v=b[c+1],m=b[c+2];b=b[c+3];for(p=0;p<r;++p)gb(a[p],
v,m,b,e,f),f+=d;}else for(p=0;p<r;++p)hb(a[p],b,c+1,e,f),f+=d;}function Fa(a){return Ga[Object.prototype.toString.call(a)]|0}function ib(a,b){for(var c=0;c<b.length;++c)a[c]=b[c];}function jb(a,b,c,e,f,d,p){for(var r=0,v=0;v<c;++v)for(var m=0;m<e;++m)a[r++]=b[f*v+d*m+p];}function Ib(a,b,c,e){function f(b){this.id=v++;this.buffer=a.createBuffer();this.type=b;this.usage=35044;this.byteLength=0;this.dimension=1;this.dtype=5121;this.persistentData=null;c.profile&&(this.stats={size:0});}function d(b,c,q){b.byteLength=
c.byteLength;a.bufferData(b.type,c,q);}function p(a,b,c,g,k,h){a.usage=c;if(Array.isArray(b)){if(a.dtype=g||5126,0<b.length)if(Array.isArray(b[0])){k=kb(b);for(var l=g=1;l<k.length;++l)g*=k[l];a.dimension=g;b=Sa(b,k,a.dtype);d(a,b,c);h?a.persistentData=b:D.freeType(b);}else "number"===typeof b[0]?(a.dimension=k,k=D.allocType(a.dtype,b.length),ib(k,b),d(a,k,c),h?a.persistentData=k:D.freeType(k)):K(b[0])&&(a.dimension=b[0].length,a.dtype=g||Fa(b[0])||5126,b=Sa(b,[b.length,b[0].length],a.dtype),d(a,b,c),
h?a.persistentData=b:D.freeType(b));}else if(K(b))a.dtype=g||Fa(b),a.dimension=k,d(a,b,c),h&&(a.persistentData=new Uint8Array(new Uint8Array(b.buffer)));else if(ga(b)){k=b.shape;var e=b.stride,l=b.offset,t=0,ka=0,f=0,m=0;1===k.length?(t=k[0],ka=1,f=e[0],m=0):2===k.length&&(t=k[0],ka=k[1],f=e[0],m=e[1]);a.dtype=g||Fa(b.data)||5126;a.dimension=ka;k=D.allocType(a.dtype,t*ka);jb(k,b.data,t,ka,f,m,l);d(a,k,c);h?a.persistentData=k:D.freeType(k);}else b instanceof ArrayBuffer&&(a.dtype=5121,a.dimension=k,
d(a,b,c),h&&(a.persistentData=new Uint8Array(new Uint8Array(b))));}function r(c){b.bufferCount--;e(c);a.deleteBuffer(c.buffer);c.buffer=null;delete m[c.id];}var v=0,m={};f.prototype.bind=function(){a.bindBuffer(this.type,this.buffer);};f.prototype.destroy=function(){r(this);};var u=[];c.profile&&(b.getTotalBufferSize=function(){var a=0;Object.keys(m).forEach(function(b){a+=m[b].stats.size;});return a});return {create:function(n,e,d,g){function k(b){var n=35044,t=null,e=0,d=0,f=h&&h.dimension||1;Array.isArray(b)||
K(b)||ga(b)||b instanceof ArrayBuffer?t=b:"number"===typeof b?e=b|0:b&&("data"in b&&(t=b.data),"usage"in b&&(n=lb[b.usage]),"type"in b&&(d=Ha[b.type]),"dimension"in b&&(f=b.dimension|0),"length"in b&&(e=b.length|0));h.bind();t?p(h,t,n,d,f,g):(e&&a.bufferData(h.type,e,n),h.dtype=d||5121,h.usage=n,h.dimension=f,h.byteLength=e);c.profile&&(h.stats.size=h.byteLength*ha[h.dtype]);return k}b.bufferCount++;var h=new f(e);m[h.id]=h;d||k(n);k._reglType="buffer";k._buffer=h;k.subdata=function(b,c){var t=(c||
0)|0,n;h.bind();if(K(b)||b instanceof ArrayBuffer)a.bufferSubData(h.type,t,b);else if(Array.isArray(b)){if(0<b.length)if("number"===typeof b[0]){var e=D.allocType(h.dtype,b.length);ib(e,b);a.bufferSubData(h.type,t,e);D.freeType(e);}else if(Array.isArray(b[0])||K(b[0]))n=kb(b),e=Sa(b,n,h.dtype),a.bufferSubData(h.type,t,e),D.freeType(e);}else if(ga(b)){n=b.shape;var d=b.stride,g=e=0,f=0,E=0;1===n.length?(e=n[0],g=1,f=d[0],E=0):2===n.length&&(e=n[0],g=n[1],f=d[0],E=d[1]);n=Array.isArray(b.data)?h.dtype:
Fa(b.data);n=D.allocType(n,e*g);jb(n,b.data,e,g,f,E,b.offset);a.bufferSubData(h.type,t,n);D.freeType(n);}return k};c.profile&&(k.stats=h.stats);k.destroy=function(){r(h);};return k},createStream:function(a,b){var c=u.pop();c||(c=new f(a));c.bind();p(c,b,35040,0,1,!1);return c},destroyStream:function(a){u.push(a);},clear:function(){S(m).forEach(r);u.forEach(r);},getBuffer:function(a){return a&&a._buffer instanceof f?a._buffer:null},restore:function(){S(m).forEach(function(b){b.buffer=a.createBuffer();
a.bindBuffer(b.type,b.buffer);a.bufferData(b.type,b.persistentData||b.byteLength,b.usage);});},_initBuffer:p}}function Jb(a,b,c,e){function f(a){this.id=v++;r[this.id]=this;this.buffer=a;this.primType=4;this.type=this.vertCount=0;}function d(e,d,f,g,k,h,l){e.buffer.bind();var m;d?((m=l)||K(d)&&(!ga(d)||K(d.data))||(m=b.oes_element_index_uint?5125:5123),c._initBuffer(e.buffer,d,f,m,3)):(a.bufferData(34963,h,f),e.buffer.dtype=m||5121,e.buffer.usage=f,e.buffer.dimension=3,e.buffer.byteLength=h);m=l;if(!l){switch(e.buffer.dtype){case 5121:case 5120:m=
5121;break;case 5123:case 5122:m=5123;break;case 5125:case 5124:m=5125;}e.buffer.dtype=m;}e.type=m;d=k;0>d&&(d=e.buffer.byteLength,5123===m?d>>=1:5125===m&&(d>>=2));e.vertCount=d;d=g;0>g&&(d=4,g=e.buffer.dimension,1===g&&(d=0),2===g&&(d=1),3===g&&(d=4));e.primType=d;}function p(a){e.elementsCount--;delete r[a.id];a.buffer.destroy();a.buffer=null;}var r={},v=0,m={uint8:5121,uint16:5123};b.oes_element_index_uint&&(m.uint32=5125);f.prototype.bind=function(){this.buffer.bind();};var u=[];return {create:function(a,
b){function q(a){if(a)if("number"===typeof a)g(a),k.primType=4,k.vertCount=a|0,k.type=5121;else {var b=null,c=35044,e=-1,f=-1,n=0,r=0;if(Array.isArray(a)||K(a)||ga(a))b=a;else if("data"in a&&(b=a.data),"usage"in a&&(c=lb[a.usage]),"primitive"in a&&(e=Ia[a.primitive]),"count"in a&&(f=a.count|0),"type"in a&&(r=m[a.type]),"length"in a)n=a.length|0;else if(n=f,5123===r||5122===r)n*=2;else if(5125===r||5124===r)n*=4;d(k,b,c,e,f,n,r);}else g(),k.primType=4,k.vertCount=0,k.type=5121;return q}var g=c.create(null,
34963,!0),k=new f(g._buffer);e.elementsCount++;q(a);q._reglType="elements";q._elements=k;q.subdata=function(a,b){g.subdata(a,b);return q};q.destroy=function(){p(k);};return q},createStream:function(a){var b=u.pop();b||(b=new f(c.create(null,34963,!0,!1)._buffer));d(b,a,35040,-1,-1,0,0);return b},destroyStream:function(a){u.push(a);},getElements:function(a){return "function"===typeof a&&a._elements instanceof f?a._elements:null},clear:function(){S(r).forEach(p);}}}function mb(a){for(var b=D.allocType(5123,
a.length),c=0;c<a.length;++c)if(isNaN(a[c]))b[c]=65535;else if(Infinity===a[c])b[c]=31744;else if(-Infinity===a[c])b[c]=64512;else {nb[0]=a[c];var e=Kb[0],f=e>>>31<<15,d=(e<<1>>>24)-127,e=e>>13&1023;b[c]=-24>d?f:-14>d?f+(e+1024>>-14-d):15<d?f+31744:f+(d+15<<10)+e;}return b}function pa(a){return Array.isArray(a)||K(a)}function qa(a){return "[object "+a+"]"}function ob(a){return Array.isArray(a)&&(0===a.length||"number"===typeof a[0])}function pb(a){return Array.isArray(a)&&0!==a.length&&pa(a[0])?!0:!1}
function ia(a){return Object.prototype.toString.call(a)}function Ta(a){if(!a)return !1;var b=ia(a);return 0<=Lb.indexOf(b)?!0:ob(a)||pb(a)||ga(a)}function qb(a,b){36193===a.type?(a.data=mb(b),D.freeType(b)):a.data=b;}function Ja(a,b,c,e,f,d){a="undefined"!==typeof H[a]?H[a]:R[a]*ra[b];d&&(a*=6);if(f){for(e=0;1<=c;)e+=a*c*c,c/=2;return e}return a*c*e}function Mb(a,b,c,e,f,d,p){function r(){this.format=this.internalformat=6408;this.type=5121;this.flipY=this.premultiplyAlpha=this.compressed=!1;this.unpackAlignment=
1;this.colorSpace=37444;this.channels=this.height=this.width=0;}function v(a,b){a.internalformat=b.internalformat;a.format=b.format;a.type=b.type;a.compressed=b.compressed;a.premultiplyAlpha=b.premultiplyAlpha;a.flipY=b.flipY;a.unpackAlignment=b.unpackAlignment;a.colorSpace=b.colorSpace;a.width=b.width;a.height=b.height;a.channels=b.channels;}function m(a,b){if("object"===typeof b&&b){"premultiplyAlpha"in b&&(a.premultiplyAlpha=b.premultiplyAlpha);"flipY"in b&&(a.flipY=b.flipY);"alignment"in b&&(a.unpackAlignment=
b.alignment);"colorSpace"in b&&(a.colorSpace=Nb[b.colorSpace]);"type"in b&&(a.type=O[b.type]);var c=a.width,e=a.height,d=a.channels,k=!1;"shape"in b?(c=b.shape[0],e=b.shape[1],3===b.shape.length&&(d=b.shape[2],k=!0)):("radius"in b&&(c=e=b.radius),"width"in b&&(c=b.width),"height"in b&&(e=b.height),"channels"in b&&(d=b.channels,k=!0));a.width=c|0;a.height=e|0;a.channels=d|0;c=!1;"format"in b&&(c=b.format,e=a.internalformat=G[c],a.format=x[e],c in O&&!("type"in b)&&(a.type=O[c]),c in V&&(a.compressed=
!0),c=!0);!k&&c?a.channels=R[a.format]:k&&!c&&a.channels!==Ma[a.format]&&(a.format=a.internalformat=Ma[a.channels]);}}function u(b){a.pixelStorei(37440,b.flipY);a.pixelStorei(37441,b.premultiplyAlpha);a.pixelStorei(37443,b.colorSpace);a.pixelStorei(3317,b.unpackAlignment);}function n(){r.call(this);this.yOffset=this.xOffset=0;this.data=null;this.needsFree=!1;this.element=null;this.needsCopy=!1;}function z(a,b){var c=null;Ta(b)?c=b:b&&(m(a,b),"x"in b&&(a.xOffset=b.x|0),"y"in b&&(a.yOffset=b.y|0),Ta(b.data)&&
(c=b.data));if(b.copy){var e=f.viewportWidth,d=f.viewportHeight;a.width=a.width||e-a.xOffset;a.height=a.height||d-a.yOffset;a.needsCop