Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@loaders.gl/terrain

Package Overview
Dependencies
Maintainers
7
Versions
271
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@loaders.gl/terrain - npm Package Compare versions

Comparing version 3.0.0-alpha.20 to 3.0.0-alpha.21

2

dist/dist.min.js

@@ -1,2 +0,2 @@

!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(window,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(i,s,function(t){return e[t]}.bind(null,s));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([,function(e,t,n){(function(t){const i=n(3),s="undefined"==typeof window?t:window;s.loaders=s.loaders||{},e.exports=Object.assign(s.loaders,i)}).call(this,n(2))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";n.r(t),n.d(t,"TerrainLoader",(function(){return _})),n.d(t,"TerrainWorkerLoader",(function(){return c})),n.d(t,"QuantizedMeshLoader",(function(){return q})),n.d(t,"QuantizedMeshWorkerLoader",(function(){return x}));function i(e){if(!e||!e.POSITION)return null;let t=1/0,n=1/0,i=1/0,s=-1/0,r=-1/0,o=-1/0;const a=e.POSITION.value,h=a&&a.length;if(!h)return null;for(let e=0;e<h;e+=3){const h=a[e],u=a[e+1],l=a[e+2];t=h<t?h:t,n=u<n?u:n,i=l<i?l:i,s=h>s?h:s,r=u>r?u:r,o=l>o?l:o}return[[t,n,i],[s,r,o]]}class s{constructor(e=257){this.gridSize=e;const t=e-1;if(t&t-1)throw new Error(`Expected grid size to be 2^n+1, got ${e}.`);this.numTriangles=t*t*2-2,this.numParentTriangles=this.numTriangles-t*t,this.indices=new Uint32Array(this.gridSize*this.gridSize),this.coords=new Uint16Array(4*this.numTriangles);for(let e=0;e<this.numTriangles;e++){let n=e+2,i=0,s=0,r=0,o=0,a=0,h=0;for(1&n?r=o=a=t:i=s=h=t;(n>>=1)>1;){const e=i+r>>1,t=s+o>>1;1&n?(r=i,o=s,i=a,s=h):(i=r,s=o,r=a,o=h),a=e,h=t}const u=4*e;this.coords[u+0]=i,this.coords[u+1]=s,this.coords[u+2]=r,this.coords[u+3]=o}}createTile(e){return new r(e,this)}}class r{constructor(e,t){const n=t.gridSize;if(e.length!==n*n)throw new Error(`Expected terrain data of length ${n*n} (${n} x ${n}), got ${e.length}.`);this.terrain=e,this.martini=t,this.errors=new Float32Array(e.length),this.update()}update(){const{numTriangles:e,numParentTriangles:t,coords:n,gridSize:i}=this.martini,{terrain:s,errors:r}=this;for(let o=e-1;o>=0;o--){const e=4*o,a=n[e+0],h=n[e+1],u=n[e+2],l=n[e+3],d=a+u>>1,c=h+l>>1,_=d+c-h,g=c+a-d,f=(s[h*i+a]+s[l*i+u])/2,E=c*i+d,p=Math.abs(f-s[E]);if(r[E]=Math.max(r[E],p),o<t){const e=(h+g>>1)*i+(a+_>>1),t=(l+g>>1)*i+(u+_>>1);r[E]=Math.max(r[E],r[e],r[t])}}}getMesh(e=0){const{gridSize:t,indices:n}=this.martini,{errors:i}=this;let s=0,r=0;const o=t-1;function a(o,h,u,l,d,c){const _=o+u>>1,g=h+l>>1;Math.abs(o-d)+Math.abs(h-c)>1&&i[g*t+_]>e?(a(d,c,o,h,_,g),a(u,l,d,c,_,g)):(n[h*t+o]=n[h*t+o]||++s,n[l*t+u]=n[l*t+u]||++s,n[c*t+d]=n[c*t+d]||++s,r++)}n.fill(0),a(0,0,o,o,o,0),a(o,o,0,0,0,o);const h=new Uint16Array(2*s),u=new Uint32Array(3*r);let l=0;function d(s,r,o,a,c,_){const g=s+o>>1,f=r+a>>1;if(Math.abs(s-c)+Math.abs(r-_)>1&&i[f*t+g]>e)d(c,_,s,r,g,f),d(o,a,c,_,g,f);else{const e=n[r*t+s]-1,i=n[a*t+o]-1,d=n[_*t+c]-1;h[2*e]=s,h[2*e+1]=r,h[2*i]=o,h[2*i+1]=a,h[2*d]=c,h[2*d+1]=_,u[l++]=e,u[l++]=i,u[l++]=d}}return d(0,0,o,o,o,0),d(o,o,0,0,0,o),{vertices:h,triangles:u}}}class o{constructor(e,t,n=t){this.data=e,this.width=t,this.height=n,this.coords=[],this.triangles=[],this._halfedges=[],this._candidates=[],this._queueIndices=[],this._queue=[],this._errors=[],this._rms=[],this._pending=[],this._pendingLen=0,this._rmsSum=0;const i=t-1,s=n-1,r=this._addPoint(0,0),o=this._addPoint(i,0),a=this._addPoint(0,s),h=this._addPoint(i,s),u=this._addTriangle(h,r,a,-1,-1,-1);this._addTriangle(r,h,o,u,-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,t){return this.data[this.width*t+e]}_flush(){const e=this.coords;for(let t=0;t<this._pendingLen;t++){const n=this._pending[t],i=2*this.triangles[3*n+0],s=2*this.triangles[3*n+1],r=2*this.triangles[3*n+2];this._findCandidate(e[i],e[i+1],e[s],e[s+1],e[r],e[r+1],n)}this._pendingLen=0}_findCandidate(e,t,n,i,s,r,o){const h=Math.min(e,n,s),u=Math.min(t,i,r),l=Math.max(e,n,s),d=Math.max(t,i,r);let c=a(n,i,s,r,h,u),_=a(s,r,e,t,h,u),g=a(e,t,n,i,h,u);const f=i-t,E=e-n,p=r-i,T=n-s,m=t-r,y=s-e,S=a(e,t,n,i,s,r),w=this.heightAt(e,t)/S,b=this.heightAt(n,i)/S,P=this.heightAt(s,r)/S;let M=0,x=0,q=0,v=0;for(let e=u;e<=d;e++){let t=0;c<0&&0!==p&&(t=Math.max(t,Math.floor(-c/p))),_<0&&0!==m&&(t=Math.max(t,Math.floor(-_/m))),g<0&&0!==f&&(t=Math.max(t,Math.floor(-g/f)));let n=c+p*t,i=_+m*t,s=g+f*t,r=!1;for(let o=h+t;o<=l;o++){if(n>=0&&i>=0&&s>=0){r=!0;const t=w*n+b*i+P*s,a=Math.abs(t-this.heightAt(o,e));v+=a*a,a>M&&(M=a,x=o,q=e)}else if(r)break;n+=p,i+=m,s+=f}c+=T,_+=y,g+=E}(x===e&&q===t||x===n&&q===i||x===s&&q===r)&&(M=0),this._candidates[2*o]=x,this._candidates[2*o+1]=q,this._rms[o]=v,this._queuePush(o,M,v)}_step(){const e=this._queuePop(),t=3*e+0,n=3*e+1,i=3*e+2,s=this.triangles[t],r=this.triangles[n],o=this.triangles[i],h=this.coords[2*s],u=this.coords[2*s+1],l=this.coords[2*r],d=this.coords[2*r+1],c=this.coords[2*o],_=this.coords[2*o+1],g=this._candidates[2*e],f=this._candidates[2*e+1],E=this._addPoint(g,f);if(0===a(h,u,l,d,g,f))this._handleCollinear(E,t);else if(0===a(l,d,c,_,g,f))this._handleCollinear(E,n);else if(0===a(c,_,h,u,g,f))this._handleCollinear(E,i);else{const e=this._halfedges[t],a=this._halfedges[n],h=this._halfedges[i],u=this._addTriangle(s,r,E,e,-1,-1,t),l=this._addTriangle(r,o,E,a,-1,u+1),d=this._addTriangle(o,s,E,h,u+2,l+1);this._legalize(u),this._legalize(l),this._legalize(d)}}_addPoint(e,t){const n=this.coords.length>>1;return this.coords.push(e,t),n}_addTriangle(e,t,n,i,s,r,o=this.triangles.length){const a=o/3;return this.triangles[o+0]=e,this.triangles[o+1]=t,this.triangles[o+2]=n,this._halfedges[o+0]=i,this._halfedges[o+1]=s,this._halfedges[o+2]=r,i>=0&&(this._halfedges[i]=o+0),s>=0&&(this._halfedges[s]=o+1),r>=0&&(this._halfedges[r]=o+2),this._candidates[2*a+0]=0,this._candidates[2*a+1]=0,this._queueIndices[a]=-1,this._rms[a]=0,this._pending[this._pendingLen++]=a,o}_legalize(e){const t=this._halfedges[e];if(t<0)return;const n=e-e%3,i=t-t%3,s=n+(e+1)%3,r=n+(e+2)%3,o=i+(t+2)%3,a=i+(t+1)%3,h=this.triangles[r],u=this.triangles[e],l=this.triangles[s],d=this.triangles[o],c=this.coords;if(!function(e,t,n,i,s,r,o,a){const h=e-o,u=t-a,l=n-o,d=i-a,c=s-o,_=r-a,g=l*l+d*d,f=c*c+_*_;return h*(d*f-g*_)-u*(l*f-g*c)+(h*h+u*u)*(l*_-d*c)<0}(c[2*h],c[2*h+1],c[2*u],c[2*u+1],c[2*l],c[2*l+1],c[2*d],c[2*d+1]))return;const _=this._halfedges[s],g=this._halfedges[r],f=this._halfedges[o],E=this._halfedges[a];this._queueRemove(n/3),this._queueRemove(i/3);const p=this._addTriangle(h,d,l,-1,f,_,n),T=this._addTriangle(d,h,u,p,g,E,i);this._legalize(p+1),this._legalize(T+2)}_handleCollinear(e,t){const n=t-t%3,i=n+(t+1)%3,s=n+(t+2)%3,r=this.triangles[s],o=this.triangles[t],a=this.triangles[i],h=this._halfedges[i],u=this._halfedges[s],l=this._halfedges[t];if(l<0){const t=this._addTriangle(e,r,o,-1,u,-1,n),i=this._addTriangle(r,e,a,t,-1,h);return this._legalize(t+1),void this._legalize(i+2)}const d=l-l%3,c=d+(l+2)%3,_=d+(l+1)%3,g=this.triangles[c],f=this._halfedges[c],E=this._halfedges[_];this._queueRemove(d/3);const p=this._addTriangle(r,o,e,u,-1,-1,n),T=this._addTriangle(o,g,e,E,-1,p+1,d),m=this._addTriangle(g,a,e,f,-1,T+1),y=this._addTriangle(a,r,e,h,p+2,m+1);this._legalize(p),this._legalize(T),this._legalize(m),this._legalize(y)}_queuePush(e,t,n){const i=this._queue.length;this._queueIndices[e]=i,this._queue.push(e),this._errors.push(t),this._rmsSum+=n,this._queueUp(i)}_queuePop(){const e=this._queue.length-1;return this._queueSwap(0,e),this._queueDown(0,e),this._queuePopBack()}_queuePopBack(){const e=this._queue.pop();return this._errors.pop(),this._rmsSum-=this._rms[e],this._queueIndices[e]=-1,e}_queueRemove(e){const t=this._queueIndices[e];if(t<0){const t=this._pending.indexOf(e);if(-1===t)throw new Error("Broken triangulation (something went wrong).");return void(this._pending[t]=this._pending[--this._pendingLen])}const n=this._queue.length-1;n!==t&&(this._queueSwap(t,n),this._queueDown(t,n)||this._queueUp(t)),this._queuePopBack()}_queueLess(e,t){return this._errors[e]>this._errors[t]}_queueSwap(e,t){const n=this._queue[e],i=this._queue[t];this._queue[e]=i,this._queue[t]=n,this._queueIndices[n]=t,this._queueIndices[i]=e;const s=this._errors[e];this._errors[e]=this._errors[t],this._errors[t]=s}_queueUp(e){let t=e;for(;;){const e=t-1>>1;if(e===t||!this._queueLess(t,e))break;this._queueSwap(e,t),t=e}}_queueDown(e,t){let n=e;for(;;){const e=2*n+1;if(e>=t||e<0)break;const i=e+1;let s=e;if(i<t&&this._queueLess(i,e)&&(s=i),!this._queueLess(s,n))break;this._queueSwap(n,s),n=s}return n>e}}function a(e,t,n,i,s,r){return(n-s)*(t-r)-(i-r)*(e-s)}function h(e,t,n,i,s){const{rScaler:r,bScaler:o,gScaler:a,offset:h}=i,u=new Float32Array((t+1)*(n+1));for(let i=0,s=0;s<n;s++)for(let n=0;n<t;n++,i++){const t=4*i,n=e[t+0],l=e[t+1],d=e[t+2];u[i+s]=n*r+l*a+d*o+h}if("martini"===s){for(let e=(t+1)*t,n=0;n<t;n++,e++)u[e]=u[e-t-1];for(let e=n,t=0;t<n+1;t++,e+=n+1)u[e]=u[e-1]}return u}function u(e,t){if(null===e)return null;const{meshMaxError:n,bounds:s,elevationDecoder:r}=t,{data:o,width:a,height:u}=e;let c,_;switch(t.tesselator){case"martini":c=h(o,a,u,r,t.tesselator),_=l(n,a,c);break;case"delatin":c=h(o,a,u,r,t.tesselator),_=d(n,a,u,c);break;default:a!==u||u&a-1?(c=h(o,a,u,r,"delatin"),_=d(n,a,u,c)):(c=h(o,a,u,r,"martini"),_=l(n,a,c))}const{vertices:g,triangles:f}=_,E=function(e,t,n,i,s){const r=n+1,o=e.length/2,a=new Float32Array(3*o),h=new Float32Array(2*o),[u,l,d,c]=s||[0,0,n,i],_=(d-u)/n,g=(c-l)/i;for(let s=0;s<o;s++){const o=e[2*s],l=e[2*s+1],d=l*r+o;a[3*s+0]=o*_+u,a[3*s+1]=-l*g+c,a[3*s+2]=t[d],h[2*s+0]=o/n,h[2*s+1]=l/i}return{POSITION:{value:a,size:3},TEXCOORD_0:{value:h,size:2}}}(g,c,a,u,s);return{loaderData:{header:{}},header:{vertexCount:f.length,boundingBox:i(E)},mode:4,indices:{value:Uint32Array.from(f),size:1},attributes:E}}function l(e,t,n){const i=new s(t+1).createTile(n),{vertices:r,triangles:o}=i.getMesh(e);return{vertices:r,triangles:o}}function d(e,t,n,i){const s=new o(i,t+1,n+1);s.run(e);const{coords:r,triangles:a}=s;return{vertices:r,triangles:a}}const c={name:"Terrain",id:"terrain",module:"terrain",version:"3.0.0-alpha.20",worker:!0,extensions:["png","pngraw"],mimeTypes:["image/png"],options:{terrain:{tesselator:"auto",bounds:null,meshMaxError:10,elevationDecoder:{rScaler:1,gScaler:0,bScaler:0,offset:0}}}},_={...c,parse:async function(e,t,n){return t.image=t.image||{},t.image.type="data",u(await n.parse(e,t,t.baseUri),t.terrain)}},g=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 f(e){return e>>1^-(1&e)}function E(e,t,n,i,s=!0){let r;if(r=2===i?new Uint16Array(e,t,n):new Uint32Array(e,t,n),!s)return r;let o=0;for(let e=0;e<r.length;++e){const t=r[e];r[e]=o-t,0===t&&++o}return r}function p(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}const T=1,m=2,y=3,S=4,w={maxDecodingStep:S};function b(e,t){const n=Object.assign({},w,t),i=new DataView(e),{header:s,headerEndPosition:r}=function(e){let t=0;const n={};for(const[i,s]of g){const r=8===s?e.getFloat64:e.getFloat32;n[i]=r.call(e,t,!0),t+=s}return{header:n,headerEndPosition:t}}(i);if(n.maxDecodingStep<T)return{header:s};const{vertexData:o,vertexDataEndPosition:a}=function(e,t){let n=t;const i=e.getUint32(n,!0),s=new Uint16Array(3*i);n+=Uint32Array.BYTES_PER_ELEMENT;const r=Uint16Array.BYTES_PER_ELEMENT,o=i*r,a=n,h=a+o,u=h+o;let l=0,d=0,c=0;for(let t=0;t<i;t++)l+=f(e.getUint16(a+r*t,!0)),d+=f(e.getUint16(h+r*t,!0)),c+=f(e.getUint16(u+r*t,!0)),s[t]=l,s[t+i]=d,s[t+2*i]=c;return n+=3*o,{vertexData:s,vertexDataEndPosition:n}}(i,r);if(n.maxDecodingStep<m)return{header:s,vertexData:o};const{triangleIndices:h,triangleIndicesEndPosition:u}=function(e,t,n){let i=n;const s=t.length/3>65536?Uint32Array.BYTES_PER_ELEMENT:Uint16Array.BYTES_PER_ELEMENT;i%s!=0&&(i+=s-i%s);const r=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const o=3*r,a=E(e.buffer,i,o,s);return i+=o*s,{triangleIndicesEndPosition:i,triangleIndices:a}}(i,o,a);if(n.maxDecodingStep<y)return{header:s,vertexData:o,triangleIndices:h};const{westIndices:l,southIndices:d,eastIndices:c,northIndices:_,edgeIndicesEndPosition:b}=function(e,t,n){let i=n;const s=t.length/3>65536?Uint32Array.BYTES_PER_ELEMENT:Uint16Array.BYTES_PER_ELEMENT,r=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const o=E(e.buffer,i,r,s,!1);i+=r*s;const a=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const h=E(e.buffer,i,a,s,!1);i+=a*s;const u=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const l=E(e.buffer,i,u,s,!1);i+=u*s;const d=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const c=E(e.buffer,i,d,s,!1);return i+=d*s,{edgeIndicesEndPosition:i,westIndices:o,southIndices:h,eastIndices:l,northIndices:c}}(i,o,u);if(n.maxDecodingStep<S)return{header:s,vertexData:o,triangleIndices:h,westIndices:l,northIndices:_,eastIndices:c,southIndices:d};const{extensions:P}=function(e,t){const n={};if(e.byteLength<=t)return{extensions:n,extensionsEndPosition:t};let i=t;for(;i<e.byteLength;){const t=e.getUint8(i,!0);i+=Uint8Array.BYTES_PER_ELEMENT;const r=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const o=new DataView(e.buffer,i,r);switch(t){case 1:n.vertexNormals=(s=o,new Uint8Array(s.buffer,s.byteOffset,s.byteLength));break;case 2:n.waterMask=p(o)}i+=r}var s;return{extensions:n,extensionsEndPosition:i}}(i,b);return{header:s,vertexData:o,triangleIndices:h,westIndices:l,northIndices:_,eastIndices:c,southIndices:d,extensions:P}}function P(e,t){if(!e)return null;const{bounds:n}=t,{header:s,vertexData:r,triangleIndices:o}=b(e,m),a=function(e,t,n){const{minHeight:i,maxHeight:s}=t,[r,o,a,h]=n||[0,0,1,1],u=a-r,l=h-o,d=s-i,c=e.length/3,_=new Float32Array(3*c),g=new Float32Array(2*c);for(let t=0;t<c;t++){const n=e[t]/32767,s=e[t+c]/32767,a=e[t+2*c]/32767;_[3*t+0]=n*u+r,_[3*t+1]=s*l+o,_[3*t+2]=a*d+i,g[2*t+0]=n,g[2*t+1]=s}return{POSITION:{value:_,size:3},TEXCOORD_0:{value:g,size:2}}}(r,s,n);return{loaderData:{header:{}},header:{vertexCount:o.length,boundingBox:i(a)},mode:4,indices:{value:o,size:1},attributes:a}}function M(e,t){return P(e,t["quantized-mesh"])}const x={name:"Quantized Mesh",id:"quantized-mesh",module:"terrain",version:"3.0.0-alpha.20",worker:!0,extensions:["terrain"],mimeTypes:["application/vnd.quantized-mesh"],options:{"quantized-mesh":{bounds:[0,0,1,1]}}},q={...x,parseSync:M,parse:async(e,t)=>M(e,t)}}])}));
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(window,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(i,s,function(t){return e[t]}.bind(null,s));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([,function(e,t,n){(function(t){const i=n(3),s="undefined"==typeof window?t:window;s.loaders=s.loaders||{},e.exports=Object.assign(s.loaders,i)}).call(this,n(2))},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";n.r(t),n.d(t,"TerrainLoader",(function(){return _})),n.d(t,"TerrainWorkerLoader",(function(){return c})),n.d(t,"QuantizedMeshLoader",(function(){return q})),n.d(t,"QuantizedMeshWorkerLoader",(function(){return x}));function i(e){if(!e||!e.POSITION)return null;let t=1/0,n=1/0,i=1/0,s=-1/0,r=-1/0,o=-1/0;const a=e.POSITION.value,h=a&&a.length;if(!h)return null;for(let e=0;e<h;e+=3){const h=a[e],u=a[e+1],l=a[e+2];t=h<t?h:t,n=u<n?u:n,i=l<i?l:i,s=h>s?h:s,r=u>r?u:r,o=l>o?l:o}return[[t,n,i],[s,r,o]]}class s{constructor(e=257){this.gridSize=e;const t=e-1;if(t&t-1)throw new Error(`Expected grid size to be 2^n+1, got ${e}.`);this.numTriangles=t*t*2-2,this.numParentTriangles=this.numTriangles-t*t,this.indices=new Uint32Array(this.gridSize*this.gridSize),this.coords=new Uint16Array(4*this.numTriangles);for(let e=0;e<this.numTriangles;e++){let n=e+2,i=0,s=0,r=0,o=0,a=0,h=0;for(1&n?r=o=a=t:i=s=h=t;(n>>=1)>1;){const e=i+r>>1,t=s+o>>1;1&n?(r=i,o=s,i=a,s=h):(i=r,s=o,r=a,o=h),a=e,h=t}const u=4*e;this.coords[u+0]=i,this.coords[u+1]=s,this.coords[u+2]=r,this.coords[u+3]=o}}createTile(e){return new r(e,this)}}class r{constructor(e,t){const n=t.gridSize;if(e.length!==n*n)throw new Error(`Expected terrain data of length ${n*n} (${n} x ${n}), got ${e.length}.`);this.terrain=e,this.martini=t,this.errors=new Float32Array(e.length),this.update()}update(){const{numTriangles:e,numParentTriangles:t,coords:n,gridSize:i}=this.martini,{terrain:s,errors:r}=this;for(let o=e-1;o>=0;o--){const e=4*o,a=n[e+0],h=n[e+1],u=n[e+2],l=n[e+3],d=a+u>>1,c=h+l>>1,_=d+c-h,g=c+a-d,f=(s[h*i+a]+s[l*i+u])/2,E=c*i+d,p=Math.abs(f-s[E]);if(r[E]=Math.max(r[E],p),o<t){const e=(h+g>>1)*i+(a+_>>1),t=(l+g>>1)*i+(u+_>>1);r[E]=Math.max(r[E],r[e],r[t])}}}getMesh(e=0){const{gridSize:t,indices:n}=this.martini,{errors:i}=this;let s=0,r=0;const o=t-1;function a(o,h,u,l,d,c){const _=o+u>>1,g=h+l>>1;Math.abs(o-d)+Math.abs(h-c)>1&&i[g*t+_]>e?(a(d,c,o,h,_,g),a(u,l,d,c,_,g)):(n[h*t+o]=n[h*t+o]||++s,n[l*t+u]=n[l*t+u]||++s,n[c*t+d]=n[c*t+d]||++s,r++)}n.fill(0),a(0,0,o,o,o,0),a(o,o,0,0,0,o);const h=new Uint16Array(2*s),u=new Uint32Array(3*r);let l=0;function d(s,r,o,a,c,_){const g=s+o>>1,f=r+a>>1;if(Math.abs(s-c)+Math.abs(r-_)>1&&i[f*t+g]>e)d(c,_,s,r,g,f),d(o,a,c,_,g,f);else{const e=n[r*t+s]-1,i=n[a*t+o]-1,d=n[_*t+c]-1;h[2*e]=s,h[2*e+1]=r,h[2*i]=o,h[2*i+1]=a,h[2*d]=c,h[2*d+1]=_,u[l++]=e,u[l++]=i,u[l++]=d}}return d(0,0,o,o,o,0),d(o,o,0,0,0,o),{vertices:h,triangles:u}}}class o{constructor(e,t,n=t){this.data=e,this.width=t,this.height=n,this.coords=[],this.triangles=[],this._halfedges=[],this._candidates=[],this._queueIndices=[],this._queue=[],this._errors=[],this._rms=[],this._pending=[],this._pendingLen=0,this._rmsSum=0;const i=t-1,s=n-1,r=this._addPoint(0,0),o=this._addPoint(i,0),a=this._addPoint(0,s),h=this._addPoint(i,s),u=this._addTriangle(h,r,a,-1,-1,-1);this._addTriangle(r,h,o,u,-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,t){return this.data[this.width*t+e]}_flush(){const e=this.coords;for(let t=0;t<this._pendingLen;t++){const n=this._pending[t],i=2*this.triangles[3*n+0],s=2*this.triangles[3*n+1],r=2*this.triangles[3*n+2];this._findCandidate(e[i],e[i+1],e[s],e[s+1],e[r],e[r+1],n)}this._pendingLen=0}_findCandidate(e,t,n,i,s,r,o){const h=Math.min(e,n,s),u=Math.min(t,i,r),l=Math.max(e,n,s),d=Math.max(t,i,r);let c=a(n,i,s,r,h,u),_=a(s,r,e,t,h,u),g=a(e,t,n,i,h,u);const f=i-t,E=e-n,p=r-i,T=n-s,m=t-r,y=s-e,S=a(e,t,n,i,s,r),w=this.heightAt(e,t)/S,b=this.heightAt(n,i)/S,P=this.heightAt(s,r)/S;let M=0,x=0,q=0,v=0;for(let e=u;e<=d;e++){let t=0;c<0&&0!==p&&(t=Math.max(t,Math.floor(-c/p))),_<0&&0!==m&&(t=Math.max(t,Math.floor(-_/m))),g<0&&0!==f&&(t=Math.max(t,Math.floor(-g/f)));let n=c+p*t,i=_+m*t,s=g+f*t,r=!1;for(let o=h+t;o<=l;o++){if(n>=0&&i>=0&&s>=0){r=!0;const t=w*n+b*i+P*s,a=Math.abs(t-this.heightAt(o,e));v+=a*a,a>M&&(M=a,x=o,q=e)}else if(r)break;n+=p,i+=m,s+=f}c+=T,_+=y,g+=E}(x===e&&q===t||x===n&&q===i||x===s&&q===r)&&(M=0),this._candidates[2*o]=x,this._candidates[2*o+1]=q,this._rms[o]=v,this._queuePush(o,M,v)}_step(){const e=this._queuePop(),t=3*e+0,n=3*e+1,i=3*e+2,s=this.triangles[t],r=this.triangles[n],o=this.triangles[i],h=this.coords[2*s],u=this.coords[2*s+1],l=this.coords[2*r],d=this.coords[2*r+1],c=this.coords[2*o],_=this.coords[2*o+1],g=this._candidates[2*e],f=this._candidates[2*e+1],E=this._addPoint(g,f);if(0===a(h,u,l,d,g,f))this._handleCollinear(E,t);else if(0===a(l,d,c,_,g,f))this._handleCollinear(E,n);else if(0===a(c,_,h,u,g,f))this._handleCollinear(E,i);else{const e=this._halfedges[t],a=this._halfedges[n],h=this._halfedges[i],u=this._addTriangle(s,r,E,e,-1,-1,t),l=this._addTriangle(r,o,E,a,-1,u+1),d=this._addTriangle(o,s,E,h,u+2,l+1);this._legalize(u),this._legalize(l),this._legalize(d)}}_addPoint(e,t){const n=this.coords.length>>1;return this.coords.push(e,t),n}_addTriangle(e,t,n,i,s,r,o=this.triangles.length){const a=o/3;return this.triangles[o+0]=e,this.triangles[o+1]=t,this.triangles[o+2]=n,this._halfedges[o+0]=i,this._halfedges[o+1]=s,this._halfedges[o+2]=r,i>=0&&(this._halfedges[i]=o+0),s>=0&&(this._halfedges[s]=o+1),r>=0&&(this._halfedges[r]=o+2),this._candidates[2*a+0]=0,this._candidates[2*a+1]=0,this._queueIndices[a]=-1,this._rms[a]=0,this._pending[this._pendingLen++]=a,o}_legalize(e){const t=this._halfedges[e];if(t<0)return;const n=e-e%3,i=t-t%3,s=n+(e+1)%3,r=n+(e+2)%3,o=i+(t+2)%3,a=i+(t+1)%3,h=this.triangles[r],u=this.triangles[e],l=this.triangles[s],d=this.triangles[o],c=this.coords;if(!function(e,t,n,i,s,r,o,a){const h=e-o,u=t-a,l=n-o,d=i-a,c=s-o,_=r-a,g=l*l+d*d,f=c*c+_*_;return h*(d*f-g*_)-u*(l*f-g*c)+(h*h+u*u)*(l*_-d*c)<0}(c[2*h],c[2*h+1],c[2*u],c[2*u+1],c[2*l],c[2*l+1],c[2*d],c[2*d+1]))return;const _=this._halfedges[s],g=this._halfedges[r],f=this._halfedges[o],E=this._halfedges[a];this._queueRemove(n/3),this._queueRemove(i/3);const p=this._addTriangle(h,d,l,-1,f,_,n),T=this._addTriangle(d,h,u,p,g,E,i);this._legalize(p+1),this._legalize(T+2)}_handleCollinear(e,t){const n=t-t%3,i=n+(t+1)%3,s=n+(t+2)%3,r=this.triangles[s],o=this.triangles[t],a=this.triangles[i],h=this._halfedges[i],u=this._halfedges[s],l=this._halfedges[t];if(l<0){const t=this._addTriangle(e,r,o,-1,u,-1,n),i=this._addTriangle(r,e,a,t,-1,h);return this._legalize(t+1),void this._legalize(i+2)}const d=l-l%3,c=d+(l+2)%3,_=d+(l+1)%3,g=this.triangles[c],f=this._halfedges[c],E=this._halfedges[_];this._queueRemove(d/3);const p=this._addTriangle(r,o,e,u,-1,-1,n),T=this._addTriangle(o,g,e,E,-1,p+1,d),m=this._addTriangle(g,a,e,f,-1,T+1),y=this._addTriangle(a,r,e,h,p+2,m+1);this._legalize(p),this._legalize(T),this._legalize(m),this._legalize(y)}_queuePush(e,t,n){const i=this._queue.length;this._queueIndices[e]=i,this._queue.push(e),this._errors.push(t),this._rmsSum+=n,this._queueUp(i)}_queuePop(){const e=this._queue.length-1;return this._queueSwap(0,e),this._queueDown(0,e),this._queuePopBack()}_queuePopBack(){const e=this._queue.pop();return this._errors.pop(),this._rmsSum-=this._rms[e],this._queueIndices[e]=-1,e}_queueRemove(e){const t=this._queueIndices[e];if(t<0){const t=this._pending.indexOf(e);if(-1===t)throw new Error("Broken triangulation (something went wrong).");return void(this._pending[t]=this._pending[--this._pendingLen])}const n=this._queue.length-1;n!==t&&(this._queueSwap(t,n),this._queueDown(t,n)||this._queueUp(t)),this._queuePopBack()}_queueLess(e,t){return this._errors[e]>this._errors[t]}_queueSwap(e,t){const n=this._queue[e],i=this._queue[t];this._queue[e]=i,this._queue[t]=n,this._queueIndices[n]=t,this._queueIndices[i]=e;const s=this._errors[e];this._errors[e]=this._errors[t],this._errors[t]=s}_queueUp(e){let t=e;for(;;){const e=t-1>>1;if(e===t||!this._queueLess(t,e))break;this._queueSwap(e,t),t=e}}_queueDown(e,t){let n=e;for(;;){const e=2*n+1;if(e>=t||e<0)break;const i=e+1;let s=e;if(i<t&&this._queueLess(i,e)&&(s=i),!this._queueLess(s,n))break;this._queueSwap(n,s),n=s}return n>e}}function a(e,t,n,i,s,r){return(n-s)*(t-r)-(i-r)*(e-s)}function h(e,t,n,i,s){const{rScaler:r,bScaler:o,gScaler:a,offset:h}=i,u=new Float32Array((t+1)*(n+1));for(let i=0,s=0;s<n;s++)for(let n=0;n<t;n++,i++){const t=4*i,n=e[t+0],l=e[t+1],d=e[t+2];u[i+s]=n*r+l*a+d*o+h}if("martini"===s){for(let e=(t+1)*t,n=0;n<t;n++,e++)u[e]=u[e-t-1];for(let e=n,t=0;t<n+1;t++,e+=n+1)u[e]=u[e-1]}return u}function u(e,t){if(null===e)return null;const{meshMaxError:n,bounds:s,elevationDecoder:r}=t,{data:o,width:a,height:u}=e;let c,_;switch(t.tesselator){case"martini":c=h(o,a,u,r,t.tesselator),_=l(n,a,c);break;case"delatin":c=h(o,a,u,r,t.tesselator),_=d(n,a,u,c);break;default:a!==u||u&a-1?(c=h(o,a,u,r,"delatin"),_=d(n,a,u,c)):(c=h(o,a,u,r,"martini"),_=l(n,a,c))}const{vertices:g,triangles:f}=_,E=function(e,t,n,i,s){const r=n+1,o=e.length/2,a=new Float32Array(3*o),h=new Float32Array(2*o),[u,l,d,c]=s||[0,0,n,i],_=(d-u)/n,g=(c-l)/i;for(let s=0;s<o;s++){const o=e[2*s],l=e[2*s+1],d=l*r+o;a[3*s+0]=o*_+u,a[3*s+1]=-l*g+c,a[3*s+2]=t[d],h[2*s+0]=o/n,h[2*s+1]=l/i}return{POSITION:{value:a,size:3},TEXCOORD_0:{value:h,size:2}}}(g,c,a,u,s);return{loaderData:{header:{}},header:{vertexCount:f.length,boundingBox:i(E)},mode:4,indices:{value:Uint32Array.from(f),size:1},attributes:E}}function l(e,t,n){const i=new s(t+1).createTile(n),{vertices:r,triangles:o}=i.getMesh(e);return{vertices:r,triangles:o}}function d(e,t,n,i){const s=new o(i,t+1,n+1);s.run(e);const{coords:r,triangles:a}=s;return{vertices:r,triangles:a}}const c={name:"Terrain",id:"terrain",module:"terrain",version:"3.0.0-alpha.21",worker:!0,extensions:["png","pngraw"],mimeTypes:["image/png"],options:{terrain:{tesselator:"auto",bounds:null,meshMaxError:10,elevationDecoder:{rScaler:1,gScaler:0,bScaler:0,offset:0}}}},_={...c,parse:async function(e,t,n){return t.image=t.image||{},t.image.type="data",u(await n.parse(e,t,t.baseUri),t.terrain)}},g=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 f(e){return e>>1^-(1&e)}function E(e,t,n,i,s=!0){let r;if(r=2===i?new Uint16Array(e,t,n):new Uint32Array(e,t,n),!s)return r;let o=0;for(let e=0;e<r.length;++e){const t=r[e];r[e]=o-t,0===t&&++o}return r}function p(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}const T=1,m=2,y=3,S=4,w={maxDecodingStep:S};function b(e,t){const n=Object.assign({},w,t),i=new DataView(e),{header:s,headerEndPosition:r}=function(e){let t=0;const n={};for(const[i,s]of g){const r=8===s?e.getFloat64:e.getFloat32;n[i]=r.call(e,t,!0),t+=s}return{header:n,headerEndPosition:t}}(i);if(n.maxDecodingStep<T)return{header:s};const{vertexData:o,vertexDataEndPosition:a}=function(e,t){let n=t;const i=e.getUint32(n,!0),s=new Uint16Array(3*i);n+=Uint32Array.BYTES_PER_ELEMENT;const r=Uint16Array.BYTES_PER_ELEMENT,o=i*r,a=n,h=a+o,u=h+o;let l=0,d=0,c=0;for(let t=0;t<i;t++)l+=f(e.getUint16(a+r*t,!0)),d+=f(e.getUint16(h+r*t,!0)),c+=f(e.getUint16(u+r*t,!0)),s[t]=l,s[t+i]=d,s[t+2*i]=c;return n+=3*o,{vertexData:s,vertexDataEndPosition:n}}(i,r);if(n.maxDecodingStep<m)return{header:s,vertexData:o};const{triangleIndices:h,triangleIndicesEndPosition:u}=function(e,t,n){let i=n;const s=t.length/3>65536?Uint32Array.BYTES_PER_ELEMENT:Uint16Array.BYTES_PER_ELEMENT;i%s!=0&&(i+=s-i%s);const r=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const o=3*r,a=E(e.buffer,i,o,s);return i+=o*s,{triangleIndicesEndPosition:i,triangleIndices:a}}(i,o,a);if(n.maxDecodingStep<y)return{header:s,vertexData:o,triangleIndices:h};const{westIndices:l,southIndices:d,eastIndices:c,northIndices:_,edgeIndicesEndPosition:b}=function(e,t,n){let i=n;const s=t.length/3>65536?Uint32Array.BYTES_PER_ELEMENT:Uint16Array.BYTES_PER_ELEMENT,r=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const o=E(e.buffer,i,r,s,!1);i+=r*s;const a=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const h=E(e.buffer,i,a,s,!1);i+=a*s;const u=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const l=E(e.buffer,i,u,s,!1);i+=u*s;const d=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const c=E(e.buffer,i,d,s,!1);return i+=d*s,{edgeIndicesEndPosition:i,westIndices:o,southIndices:h,eastIndices:l,northIndices:c}}(i,o,u);if(n.maxDecodingStep<S)return{header:s,vertexData:o,triangleIndices:h,westIndices:l,northIndices:_,eastIndices:c,southIndices:d};const{extensions:P}=function(e,t){const n={};if(e.byteLength<=t)return{extensions:n,extensionsEndPosition:t};let i=t;for(;i<e.byteLength;){const t=e.getUint8(i,!0);i+=Uint8Array.BYTES_PER_ELEMENT;const r=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const o=new DataView(e.buffer,i,r);switch(t){case 1:n.vertexNormals=(s=o,new Uint8Array(s.buffer,s.byteOffset,s.byteLength));break;case 2:n.waterMask=p(o)}i+=r}var s;return{extensions:n,extensionsEndPosition:i}}(i,b);return{header:s,vertexData:o,triangleIndices:h,westIndices:l,northIndices:_,eastIndices:c,southIndices:d,extensions:P}}function P(e,t){if(!e)return null;const{bounds:n}=t,{header:s,vertexData:r,triangleIndices:o}=b(e,m),a=function(e,t,n){const{minHeight:i,maxHeight:s}=t,[r,o,a,h]=n||[0,0,1,1],u=a-r,l=h-o,d=s-i,c=e.length/3,_=new Float32Array(3*c),g=new Float32Array(2*c);for(let t=0;t<c;t++){const n=e[t]/32767,s=e[t+c]/32767,a=e[t+2*c]/32767;_[3*t+0]=n*u+r,_[3*t+1]=s*l+o,_[3*t+2]=a*d+i,g[2*t+0]=n,g[2*t+1]=s}return{POSITION:{value:_,size:3},TEXCOORD_0:{value:g,size:2}}}(r,s,n);return{loaderData:{header:{}},header:{vertexCount:o.length,boundingBox:i(a)},mode:4,indices:{value:o,size:1},attributes:a}}function M(e,t){return P(e,t["quantized-mesh"])}const x={name:"Quantized Mesh",id:"quantized-mesh",module:"terrain",version:"3.0.0-alpha.21",worker:!0,extensions:["terrain"],mimeTypes:["application/vnd.quantized-mesh"],options:{"quantized-mesh":{bounds:[0,0,1,1]}}},q={...x,parseSync:M,parse:async(e,t)=>M(e,t)}}])}));
//# sourceMappingURL=dist.min.js.map

@@ -7,4 +7,4 @@ "use strict";

exports.VERSION = void 0;
var VERSION = typeof "3.0.0-alpha.20" !== 'undefined' ? "3.0.0-alpha.20" : 'latest';
var VERSION = typeof "3.0.0-alpha.21" !== 'undefined' ? "3.0.0-alpha.21" : 'latest';
exports.VERSION = VERSION;
//# sourceMappingURL=version.js.map

@@ -1,2 +0,2 @@

export var VERSION = typeof "3.0.0-alpha.20" !== 'undefined' ? "3.0.0-alpha.20" : 'latest';
export var VERSION = typeof "3.0.0-alpha.21" !== 'undefined' ? "3.0.0-alpha.21" : 'latest';
//# sourceMappingURL=version.js.map
{
"name": "@loaders.gl/terrain",
"version": "3.0.0-alpha.20",
"version": "3.0.0-alpha.21",
"description": "Framework-independent loader for terrain raster formats",

@@ -37,6 +37,6 @@ "license": "MIT",

"@babel/runtime": "^7.3.1",
"@loaders.gl/loader-utils": "3.0.0-alpha.20",
"@loaders.gl/loader-utils": "3.0.0-alpha.21",
"@mapbox/martini": "^0.2.0"
},
"gitHead": "a21d85019d34c9045feae797e22ee7ce7f34d648"
"gitHead": "c1f7d7bec911c704a190dbcf6b392a07a555771b"
}

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

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc