(function webpackUniversalModuleDefinition(root, factory) { if (typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if (typeof define === 'function' && define.amd) define([], factory); else if (typeof exports === 'object') exports['loaders'] = factory(); else root['loaders'] = factory();})(globalThis, function () { "use strict";var __exports__=(()=>{var de=Object.create;var U=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var ge=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty;var pe=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),Ee=(s,e)=>{for(var r in e)U(s,r,{get:e[r],enumerable:!0})},q=(s,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of me(e))!_e.call(s,n)&&n!==r&&U(s,n,{get:()=>e[n],enumerable:!(t=fe(e,n))||t.enumerable});return s},D=(s,e,r)=>(q(s,e,"default"),r&&q(r,e,"default")),Te=(s,e,r)=>(r=s!=null?de(ge(s)):{},q(e||!s||!s.__esModule?U(r,"default",{value:s,enumerable:!0}):r,s)),xe=s=>q(U({},"__esModule",{value:!0}),s);var se=pe((Re,ne)=>{ne.exports=globalThis.loaders});var v={};Ee(v,{QuantizedMeshLoader:()=>ke,QuantizedMeshWorkerLoader:()=>te,TerrainLoader:()=>ce,TerrainWorkerLoader:()=>ee,parseTerrain:()=>le});D(v,Te(se(),1));async function J(s,e,r,t){return t._parse(s,e,r,t)}function B(...s){let e=s,r=e&&e.length>1&&e[0].constructor||null;if(!r)throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types');let t=e.reduce((o,a)=>o+a.length,0),n=new r(t),i=0;for(let o of e)n.set(o,i),i+=o.length;return n}function L(s){let e=1/0,r=1/0,t=1/0,n=-1/0,i=-1/0,o=-1/0,a=s.POSITION?s.POSITION.value:[],l=a&&a.length;for(let c=0;cn?h:n,i=u>i?u:i,o=f>o?f:o}return[[e,r,t],[n,i,o]]}var ye=new Map([["centerX",Float64Array.BYTES_PER_ELEMENT],["centerY",Float64Array.BYTES_PER_ELEMENT],["centerZ",Float64Array.BYTES_PER_ELEMENT],["minHeight",Float32Array.BYTES_PER_ELEMENT],["maxHeight",Float32Array.BYTES_PER_ELEMENT],["boundingSphereCenterX",Float64Array.BYTES_PER_ELEMENT],["boundingSphereCenterY",Float64Array.BYTES_PER_ELEMENT],["boundingSphereCenterZ",Float64Array.BYTES_PER_ELEMENT],["boundingSphereRadius",Float64Array.BYTES_PER_ELEMENT],["horizonOcclusionPointX",Float64Array.BYTES_PER_ELEMENT],["horizonOcclusionPointY",Float64Array.BYTES_PER_ELEMENT],["horizonOcclusionPointZ",Float64Array.BYTES_PER_ELEMENT]]);function $(s){return s>>1^-(s&1)}function Se(s){let e=0,r={};for(let[t,n]of ye){let i=n===8?s.getFloat64:s.getFloat32;r[t]=i.call(s,e,!0),e+=n}return{header:r,headerEndPosition:e}}function Ae(s,e){let r=e,t=3,n=s.getUint32(r,!0),i=new Uint16Array(n*t);r+=Uint32Array.BYTES_PER_ELEMENT;let o=Uint16Array.BYTES_PER_ELEMENT,a=n*o,l=r,c=l+a,h=c+a,u=0,f=0,d=0;for(let g=0;g65536?Uint32Array.BYTES_PER_ELEMENT:Uint16Array.BYTES_PER_ELEMENT;t%o!==0&&(t+=o-t%o);let a=s.getUint32(t,!0);t+=Uint32Array.BYTES_PER_ELEMENT;let l=a*3,c=F(s.buffer,t,l,o);return t+=l*o,{triangleIndicesEndPosition:t,triangleIndices:c}}function be(s,e,r){let t=r,n=3,o=e.length/n>65536?Uint32Array.BYTES_PER_ELEMENT:Uint16Array.BYTES_PER_ELEMENT,a=s.getUint32(t,!0);t+=Uint32Array.BYTES_PER_ELEMENT;let l=F(s.buffer,t,a,o,!1);t+=a*o;let c=s.getUint32(t,!0);t+=Uint32Array.BYTES_PER_ELEMENT;let h=F(s.buffer,t,c,o,!1);t+=c*o;let u=s.getUint32(t,!0);t+=Uint32Array.BYTES_PER_ELEMENT;let f=F(s.buffer,t,u,o,!1);t+=u*o;let d=s.getUint32(t,!0);t+=Uint32Array.BYTES_PER_ELEMENT;let g=F(s.buffer,t,d,o,!1);return t+=d*o,{edgeIndicesEndPosition:t,westIndices:l,southIndices:h,eastIndices:f,northIndices:g}}function Me(s){return new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}function Pe(s){return s.buffer.slice(s.byteOffset,s.byteOffset+s.byteLength)}function we(s,e){let r={};if(s.byteLength<=e)return{extensions:r,extensionsEndPosition:e};let t=e;for(;tMath.min(...n)-Math.min(...i)||Math.max(...n)-Math.max(...i));let r=[],t=0;for(;te[3*t+1]-e[3*n+1]),s.eastIndices.sort((t,n)=>e[3*n+1]-e[3*t+1]),s.southIndices.sort((t,n)=>e[3*n]-e[3*t]),s.northIndices.sort((t,n)=>e[3*t]-e[3*n]);let r=[];for(let t in s){let n=s[t];for(let i=0;i>=1)>1;){let f=i+a>>1,d=o+l>>1;n&1?(a=i,l=o,i=c,o=h):(i=a,o=l,a=c,l=h),c=f,h=d}let u=t*4;this.coords[u+0]=i,this.coords[u+1]=o,this.coords[u+2]=a,this.coords[u+3]=l}}createTile(e){return new K(e,this)}},K=class{constructor(e,r){let t=r.gridSize;if(e.length!==t*t)throw new Error(`Expected terrain data of length ${t*t} (${t} x ${t}), got ${e.length}.`);this.terrain=e,this.martini=r,this.errors=new Float32Array(e.length),this.update()}update(){let{numTriangles:e,numParentTriangles:r,coords:t,gridSize:n}=this.martini,{terrain:i,errors:o}=this;for(let a=e-1;a>=0;a--){let l=a*4,c=t[l+0],h=t[l+1],u=t[l+2],f=t[l+3],d=c+u>>1,g=h+f>>1,m=d+g-h,_=g+c-d,E=(i[h*n+c]+i[f*n+u])/2,p=g*n+d,T=Math.abs(E-i[p]);if(o[p]=Math.max(o[p],T),a>1)*n+(c+m>>1),y=(f+_>>1)*n+(u+m>>1);o[p]=Math.max(o[p],o[x],o[y])}}}getMesh(e=0){let{gridSize:r,indices:t}=this.martini,{errors:n}=this,i=0,o=0,a=r-1;t.fill(0);function l(d,g,m,_,E,p){let T=d+m>>1,x=g+_>>1;Math.abs(d-E)+Math.abs(g-p)>1&&n[x*r+T]>e?(l(E,p,d,g,T,x),l(m,_,E,p,T,x)):(t[g*r+d]=t[g*r+d]||++i,t[_*r+m]=t[_*r+m]||++i,t[p*r+E]=t[p*r+E]||++i,o++)}l(0,0,a,a,a,0),l(a,a,0,0,0,a);let c=new Uint16Array(i*2),h=new Uint32Array(o*3),u=0;function f(d,g,m,_,E,p){let T=d+m>>1,x=g+_>>1;if(Math.abs(d-E)+Math.abs(g-p)>1&&n[x*r+T]>e)f(E,p,d,g,T,x),f(m,_,E,p,T,x);else{let y=t[g*r+d]-1,S=t[_*r+m]-1,I=t[p*r+E]-1;c[2*y]=d,c[2*y+1]=g,c[2*S]=m,c[2*S+1]=_,c[2*I]=E,c[2*I+1]=p,h[u++]=y,h[u++]=S,h[u++]=I}}return f(0,0,a,a,a,0),f(a,a,0,0,0,a),{vertices:c,triangles:h}}};var O=class{constructor(e,r,t=r){this.data=e,this.width=r,this.height=t,this.coords=[],this.triangles=[],this._halfedges=[],this._candidates=[],this._queueIndices=[],this._queue=[],this._errors=[],this._rms=[],this._pending=[],this._pendingLen=0,this._rmsSum=0;let n=r-1,i=t-1,o=this._addPoint(0,0),a=this._addPoint(n,0),l=this._addPoint(0,i),c=this._addPoint(n,i),h=this._addTriangle(c,o,l,-1,-1,-1);this._addTriangle(o,c,a,h,-1,-1),this._flush()}run(e=1){for(;this.getMaxError()>e;)this.refine()}refine(){this._step(),this._flush()}getMaxError(){return this._errors[0]}getRMSD(){return this._rmsSum>0?Math.sqrt(this._rmsSum/(this.width*this.height)):0}heightAt(e,r){return this.data[this.width*r+e]}_flush(){let e=this.coords;for(let r=0;r=0&&j>=0&&Z>=0){re=!0;let ue=S*Q+I*j+he*Z,R=Math.abs(ue-this.heightAt(C,k));W+=R*R,R>z&&(z=R,P=C,w=k)}else if(re)break;Q+=E,j+=T,Z+=m}f+=p,d+=x,g+=_}(P===e&&w===r||P===t&&w===n||P===i&&w===o)&&(z=0),this._candidates[2*a]=P,this._candidates[2*a+1]=w,this._rms[a]=W,this._queuePush(a,z,W)}_step(){let e=this._queuePop(),r=e*3+0,t=e*3+1,n=e*3+2,i=this.triangles[r],o=this.triangles[t],a=this.triangles[n],l=this.coords[2*i],c=this.coords[2*i+1],h=this.coords[2*o],u=this.coords[2*o+1],f=this.coords[2*a],d=this.coords[2*a+1],g=this._candidates[2*e],m=this._candidates[2*e+1],_=this._addPoint(g,m);if(M(l,c,h,u,g,m)===0)this._handleCollinear(_,r);else if(M(h,u,f,d,g,m)===0)this._handleCollinear(_,t);else if(M(f,d,l,c,g,m)===0)this._handleCollinear(_,n);else{let E=this._halfedges[r],p=this._halfedges[t],T=this._halfedges[n],x=this._addTriangle(i,o,_,E,-1,-1,r),y=this._addTriangle(o,a,_,p,-1,x+1),S=this._addTriangle(a,i,_,T,x+2,y+1);this._legalize(x),this._legalize(y),this._legalize(S)}}_addPoint(e,r){let t=this.coords.length>>1;return this.coords.push(e,r),t}_addTriangle(e,r,t,n,i,o,a=this.triangles.length){let l=a/3;return this.triangles[a+0]=e,this.triangles[a+1]=r,this.triangles[a+2]=t,this._halfedges[a+0]=n,this._halfedges[a+1]=i,this._halfedges[a+2]=o,n>=0&&(this._halfedges[n]=a+0),i>=0&&(this._halfedges[i]=a+1),o>=0&&(this._halfedges[o]=a+2),this._candidates[2*l+0]=0,this._candidates[2*l+1]=0,this._queueIndices[l]=-1,this._rms[l]=0,this._pending[this._pendingLen++]=l,a}_legalize(e){let r=this._halfedges[e];if(r<0)return;let t=e-e%3,n=r-r%3,i=t+(e+1)%3,o=t+(e+2)%3,a=n+(r+2)%3,l=n+(r+1)%3,c=this.triangles[o],h=this.triangles[e],u=this.triangles[i],f=this.triangles[a],d=this.coords;if(!ve(d[2*c],d[2*c+1],d[2*h],d[2*h+1],d[2*u],d[2*u+1],d[2*f],d[2*f+1]))return;let g=this._halfedges[i],m=this._halfedges[o],_=this._halfedges[a],E=this._halfedges[l];this._queueRemove(t/3),this._queueRemove(n/3);let p=this._addTriangle(c,f,u,-1,_,g,t),T=this._addTriangle(f,c,h,p,m,E,n);this._legalize(p+1),this._legalize(T+2)}_handleCollinear(e,r){let t=r-r%3,n=t+(r+1)%3,i=t+(r+2)%3,o=this.triangles[i],a=this.triangles[r],l=this.triangles[n],c=this._halfedges[n],h=this._halfedges[i],u=this._halfedges[r];if(u<0){let S=this._addTriangle(e,o,a,-1,h,-1,t),I=this._addTriangle(o,e,l,S,-1,c);this._legalize(S+1),this._legalize(I+2);return}let f=u-u%3,d=f+(u+2)%3,g=f+(u+1)%3,m=this.triangles[d],_=this._halfedges[d],E=this._halfedges[g];this._queueRemove(f/3);let p=this._addTriangle(o,a,e,h,-1,-1,t),T=this._addTriangle(a,m,e,E,-1,p+1,f),x=this._addTriangle(m,l,e,_,-1,T+1),y=this._addTriangle(l,o,e,c,p+2,x+1);this._legalize(p),this._legalize(T),this._legalize(x),this._legalize(y)}_queuePush(e,r,t){let n=this._queue.length;this._queueIndices[e]=n,this._queue.push(e),this._errors.push(r),this._rmsSum+=t,this._queueUp(n)}_queuePop(){let e=this._queue.length-1;return this._queueSwap(0,e),this._queueDown(0,e),this._queuePopBack()}_queuePopBack(){let e=this._queue.pop();return this._errors.pop(),this._rmsSum-=this._rms[e],this._queueIndices[e]=-1,e}_queueRemove(e){let r=this._queueIndices[e];if(r<0){let n=this._pending.indexOf(e);if(n!==-1)this._pending[n]=this._pending[--this._pendingLen];else throw new Error("Broken triangulation (something went wrong).");return}let t=this._queue.length-1;t!==r&&(this._queueSwap(r,t),this._queueDown(r,t)||this._queueUp(r)),this._queuePopBack()}_queueLess(e,r){return this._errors[e]>this._errors[r]}_queueSwap(e,r){let t=this._queue[e],n=this._queue[r];this._queue[e]=n,this._queue[r]=t,this._queueIndices[t]=r,this._queueIndices[n]=e;let i=this._errors[e];this._errors[e]=this._errors[r],this._errors[r]=i}_queueUp(e){let r=e;for(;;){let t=r-1>>1;if(t===r||!this._queueLess(r,t))break;this._queueSwap(t,r),r=t}}_queueDown(e,r){let t=e;for(;;){let n=2*t+1;if(n>=r||n<0)break;let i=n+1,o=n;if(ie}};function M(s,e,r,t,n,i){return(r-n)*(e-i)-(t-i)*(s-n)}function ve(s,e,r,t,n,i,o,a){let l=s-o,c=e-a,h=r-o,u=t-a,f=n-o,d=i-a,g=l*l+c*c,m=h*h+u*u,_=f*f+d*d;return l*(u*_-m*d)-c*(h*_-m*f)+g*(h*d-u*f)<0}function ae(s,e){let{meshMaxError:r,bounds:t,elevationDecoder:n}=e,{data:i,width:o,height:a}=s,l,c;switch(e.tesselator){case"martini":l=X(i,o,a,n,e.tesselator),c=oe(r,o,l);break;case"delatin":l=X(i,o,a,n,e.tesselator),c=ie(r,o,a,l);break;default:o===a&&!(a&o-1)?(l=X(i,o,a,n,"martini"),c=oe(r,o,l)):(l=X(i,o,a,n,"delatin"),c=ie(r,o,a,l));break}let{vertices:h}=c,{triangles:u}=c,f=ze(h,l,o,a,t),d=L(f);if(e.skirtHeight){let{attributes:g,triangles:m}=Y(f,u,e.skirtHeight);f=g,u=m}return{loaderData:{header:{}},header:{vertexCount:u.length,boundingBox:d},mode:4,indices:{value:Uint32Array.from(u),size:1},attributes:f}}function oe(s,e,r){let t=e+1,i=new N(t).createTile(r),{vertices:o,triangles:a}=i.getMesh(s);return{vertices:o,triangles:a}}function ie(s,e,r,t){let n=new O(t,e+1,r+1);n.run(s);let{coords:i,triangles:o}=n;return{vertices:i,triangles:o}}function X(s,e,r,t,n){let{rScaler:i,bScaler:o,gScaler:a,offset:l}=t,c=new Float32Array((e+1)*(r+1));for(let h=0,u=0;uV(s,e?.["quantized-mesh"]),parse:async(s,e)=>V(s,e?.["quantized-mesh"])};return xe(v);})(); return __exports__; });