@loaders.gl/terrain 3.1.0-alpha.3 → 4.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/decode-quantized-mesh.js.map +1 -1
- package/dist/lib/delatin/index.js.map +1 -1
- package/dist/lib/helpers/skirt.js +1 -1
- package/dist/lib/helpers/skirt.js.map +1 -1
- package/dist/lib/parse-quantized-mesh.js.map +1 -1
- package/dist/lib/parse-terrain.js.map +1 -1
- package/dist/lib/utils/version.js +1 -1
- package/dist/quantized-mesh-worker.js +1218 -2
- package/dist/terrain-worker.js +1218 -2
- package/dist/workers/quantized-mesh-worker.js +3 -3
- package/dist/workers/quantized-mesh-worker.js.map +1 -0
- package/dist/workers/terrain-worker.js +3 -3
- package/dist/workers/terrain-worker.js.map +1 -0
- package/package.json +7 -7
- package/src/lib/decode-quantized-mesh.ts +325 -0
- package/src/lib/delatin/index.js +2 -0
- package/src/lib/helpers/skirt.ts +168 -0
- package/src/lib/parse-quantized-mesh.ts +98 -0
- package/src/lib/parse-terrain.ts +212 -0
- package/src/workers/quantized-mesh-worker.ts +4 -0
- package/src/workers/terrain-worker.ts +4 -0
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/quantized-mesh-worker.js.map +0 -1
- package/dist/terrain-worker.js.map +0 -1
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import {getMeshBoundingBox} from '@loaders.gl/schema';
|
|
2
|
+
import Martini from '@mapbox/martini';
|
|
3
|
+
import Delatin from './delatin';
|
|
4
|
+
import {addSkirt} from './helpers/skirt';
|
|
5
|
+
|
|
6
|
+
type TerrainOptions = {
|
|
7
|
+
meshMaxError: number;
|
|
8
|
+
bounds: number[];
|
|
9
|
+
elevationDecoder: ElevationDecoder;
|
|
10
|
+
tesselator: 'martini' | 'delatin';
|
|
11
|
+
skirtHeight?: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type TerrainImage = {
|
|
15
|
+
data: Uint8Array;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type ElevationDecoder = {
|
|
21
|
+
rScaler: any;
|
|
22
|
+
bScaler: any;
|
|
23
|
+
gScaler: any;
|
|
24
|
+
offset: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function getTerrain(
|
|
28
|
+
imageData: Uint8Array,
|
|
29
|
+
width: number,
|
|
30
|
+
height: number,
|
|
31
|
+
elevationDecoder: ElevationDecoder,
|
|
32
|
+
tesselator: 'martini' | 'delatin'
|
|
33
|
+
) {
|
|
34
|
+
const {rScaler, bScaler, gScaler, offset} = elevationDecoder;
|
|
35
|
+
|
|
36
|
+
// From Martini demo
|
|
37
|
+
// https://observablehq.com/@mourner/martin-real-time-rtin-terrain-mesh
|
|
38
|
+
const terrain = new Float32Array((width + 1) * (height + 1));
|
|
39
|
+
// decode terrain values
|
|
40
|
+
for (let i = 0, y = 0; y < height; y++) {
|
|
41
|
+
for (let x = 0; x < width; x++, i++) {
|
|
42
|
+
const k = i * 4;
|
|
43
|
+
const r = imageData[k + 0];
|
|
44
|
+
const g = imageData[k + 1];
|
|
45
|
+
const b = imageData[k + 2];
|
|
46
|
+
terrain[i + y] = r * rScaler + g * gScaler + b * bScaler + offset;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (tesselator === 'martini') {
|
|
51
|
+
// backfill bottom border
|
|
52
|
+
for (let i = (width + 1) * width, x = 0; x < width; x++, i++) {
|
|
53
|
+
terrain[i] = terrain[i - width - 1];
|
|
54
|
+
}
|
|
55
|
+
// backfill right border
|
|
56
|
+
for (let i = height, y = 0; y < height + 1; y++, i += height + 1) {
|
|
57
|
+
terrain[i] = terrain[i - 1];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return terrain;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getMeshAttributes(
|
|
65
|
+
vertices,
|
|
66
|
+
terrain: Uint8Array,
|
|
67
|
+
width: number,
|
|
68
|
+
height: number,
|
|
69
|
+
bounds: number[]
|
|
70
|
+
) {
|
|
71
|
+
const gridSize = width + 1;
|
|
72
|
+
const numOfVerticies = vertices.length / 2;
|
|
73
|
+
// vec3. x, y in pixels, z in meters
|
|
74
|
+
const positions = new Float32Array(numOfVerticies * 3);
|
|
75
|
+
// vec2. 1 to 1 relationship with position. represents the uv on the texture image. 0,0 to 1,1.
|
|
76
|
+
const texCoords = new Float32Array(numOfVerticies * 2);
|
|
77
|
+
|
|
78
|
+
const [minX, minY, maxX, maxY] = bounds || [0, 0, width, height];
|
|
79
|
+
const xScale = (maxX - minX) / width;
|
|
80
|
+
const yScale = (maxY - minY) / height;
|
|
81
|
+
|
|
82
|
+
for (let i = 0; i < numOfVerticies; i++) {
|
|
83
|
+
const x = vertices[i * 2];
|
|
84
|
+
const y = vertices[i * 2 + 1];
|
|
85
|
+
const pixelIdx = y * gridSize + x;
|
|
86
|
+
|
|
87
|
+
positions[3 * i + 0] = x * xScale + minX;
|
|
88
|
+
positions[3 * i + 1] = -y * yScale + maxY;
|
|
89
|
+
positions[3 * i + 2] = terrain[pixelIdx];
|
|
90
|
+
|
|
91
|
+
texCoords[2 * i + 0] = x / width;
|
|
92
|
+
texCoords[2 * i + 1] = y / height;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
POSITION: {value: positions, size: 3},
|
|
97
|
+
TEXCOORD_0: {value: texCoords, size: 2}
|
|
98
|
+
// NORMAL: {}, - optional, but creates the high poly look with lighting
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Returns generated mesh object from image data
|
|
104
|
+
*
|
|
105
|
+
* @param {object} terrainImage terrain image data
|
|
106
|
+
* @param {object} terrainOptions terrain options
|
|
107
|
+
* @returns mesh object
|
|
108
|
+
*/
|
|
109
|
+
function getMesh(terrainImage: TerrainImage, terrainOptions: TerrainOptions) {
|
|
110
|
+
if (terrainImage === null) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
const {meshMaxError, bounds, elevationDecoder} = terrainOptions;
|
|
114
|
+
|
|
115
|
+
const {data, width, height} = terrainImage;
|
|
116
|
+
|
|
117
|
+
let terrain;
|
|
118
|
+
let mesh;
|
|
119
|
+
switch (terrainOptions.tesselator) {
|
|
120
|
+
case 'martini':
|
|
121
|
+
terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
|
|
122
|
+
mesh = getMartiniTileMesh(meshMaxError, width, terrain);
|
|
123
|
+
break;
|
|
124
|
+
case 'delatin':
|
|
125
|
+
terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);
|
|
126
|
+
mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
|
|
127
|
+
break;
|
|
128
|
+
// auto
|
|
129
|
+
default:
|
|
130
|
+
if (width === height && !(height & (width - 1))) {
|
|
131
|
+
terrain = getTerrain(data, width, height, elevationDecoder, 'martini');
|
|
132
|
+
mesh = getMartiniTileMesh(meshMaxError, width, terrain);
|
|
133
|
+
} else {
|
|
134
|
+
terrain = getTerrain(data, width, height, elevationDecoder, 'delatin');
|
|
135
|
+
mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const {vertices} = mesh;
|
|
141
|
+
let {triangles} = mesh;
|
|
142
|
+
let attributes = getMeshAttributes(vertices, terrain, width, height, bounds);
|
|
143
|
+
|
|
144
|
+
// Compute bounding box before adding skirt so that z values are not skewed
|
|
145
|
+
const boundingBox = getMeshBoundingBox(attributes);
|
|
146
|
+
|
|
147
|
+
if (terrainOptions.skirtHeight) {
|
|
148
|
+
const {attributes: newAttributes, triangles: newTriangles} = addSkirt(
|
|
149
|
+
attributes,
|
|
150
|
+
triangles,
|
|
151
|
+
terrainOptions.skirtHeight
|
|
152
|
+
);
|
|
153
|
+
attributes = newAttributes;
|
|
154
|
+
triangles = newTriangles;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
// Data return by this loader implementation
|
|
159
|
+
loaderData: {
|
|
160
|
+
header: {}
|
|
161
|
+
},
|
|
162
|
+
header: {
|
|
163
|
+
vertexCount: triangles.length,
|
|
164
|
+
boundingBox
|
|
165
|
+
},
|
|
166
|
+
mode: 4, // TRIANGLES
|
|
167
|
+
indices: {value: Uint32Array.from(triangles), size: 1},
|
|
168
|
+
attributes
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Get Martini generated vertices and triangles
|
|
174
|
+
*
|
|
175
|
+
* @param {number} meshMaxError threshold for simplifying mesh
|
|
176
|
+
* @param {number} width width of the input data
|
|
177
|
+
* @param {number[] | Float32Array} terrain elevation data
|
|
178
|
+
* @returns {{vertices: Uint16Array, triangles: Uint32Array}} vertices and triangles data
|
|
179
|
+
*/
|
|
180
|
+
function getMartiniTileMesh(meshMaxError, width, terrain) {
|
|
181
|
+
const gridSize = width + 1;
|
|
182
|
+
const martini = new Martini(gridSize);
|
|
183
|
+
const tile = martini.createTile(terrain);
|
|
184
|
+
const {vertices, triangles} = tile.getMesh(meshMaxError);
|
|
185
|
+
|
|
186
|
+
return {vertices, triangles};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get Delatin generated vertices and triangles
|
|
191
|
+
*
|
|
192
|
+
* @param {number} meshMaxError threshold for simplifying mesh
|
|
193
|
+
* @param {number} width width of the input data array
|
|
194
|
+
* @param {number} height height of the input data array
|
|
195
|
+
* @param {number[] | Float32Array} terrain elevation data
|
|
196
|
+
* @returns {{vertices: number[], triangles: number[]}} vertices and triangles data
|
|
197
|
+
*/
|
|
198
|
+
function getDelatinTileMesh(meshMaxError, width, height, terrain) {
|
|
199
|
+
const tin = new Delatin(terrain, width + 1, height + 1);
|
|
200
|
+
tin.run(meshMaxError);
|
|
201
|
+
const {coords, triangles} = tin;
|
|
202
|
+
const vertices = coords;
|
|
203
|
+
return {vertices, triangles};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export default async function loadTerrain(arrayBuffer, options, context) {
|
|
207
|
+
options.image = options.image || {};
|
|
208
|
+
options.image.type = 'data';
|
|
209
|
+
const image = await context.parse(arrayBuffer, options, options.baseUri);
|
|
210
|
+
// Extend function to support additional mesh generation options (square grid or delatin)
|
|
211
|
+
return getMesh(image, options.terrain);
|
|
212
|
+
}
|
package/dist/dist.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!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=2)}([function(e,t){},,function(e,t,n){const i=n(3);globalThis.loaders=globalThis.loaders||{},e.exports=Object.assign(globalThis.loaders,i)},function(e,t,n){"use strict";function i(e){let t=1/0,n=1/0,i=1/0,s=-1/0,r=-1/0,o=-1/0;const a=e.POSITION?e.POSITION.value:[],h=a&&a.length;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]]}n.r(t),n.d(t,"TerrainWorkerLoader",(function(){return x})),n.d(t,"TerrainLoader",(function(){return O})),n.d(t,"_typecheckTerrainLoader",(function(){return q})),n.d(t,"QuantizedMeshWorkerLoader",(function(){return v})),n.d(t,"QuantizedMeshLoader",(function(){return A})),n.d(t,"_typecheckQuantizedMeshLoader",(function(){return L}));const s=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 r(e){return e>>1^-(1&e)}function o(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 a(e){return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}const h=1,u=2,l=3,c=4,d={maxDecodingStep:c};function g(e,t){const n=Object.assign({},d,t),i=new DataView(e),{header:g,headerEndPosition:_}=function(e){let t=0;const n={};for(const[i,r]of s){const s=8===r?e.getFloat64:e.getFloat32;n[i]=s.call(e,t,!0),t+=r}return{header:n,headerEndPosition:t}}(i);if(n.maxDecodingStep<h)return{header:g};const{vertexData:f,vertexDataEndPosition:E}=function(e,t){let n=t;const i=e.getUint32(n,!0),s=new Uint16Array(3*i);n+=Uint32Array.BYTES_PER_ELEMENT;const o=Uint16Array.BYTES_PER_ELEMENT,a=i*o,h=n,u=h+a,l=u+a;let c=0,d=0,g=0;for(let t=0;t<i;t++)c+=r(e.getUint16(h+o*t,!0)),d+=r(e.getUint16(u+o*t,!0)),g+=r(e.getUint16(l+o*t,!0)),s[t]=c,s[t+i]=d,s[t+2*i]=g;return n+=3*a,{vertexData:s,vertexDataEndPosition:n}}(i,_);if(n.maxDecodingStep<u)return{header:g,vertexData:f};const{triangleIndices:T,triangleIndicesEndPosition:p}=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 a=3*r,h=o(e.buffer,i,a,s);return i+=a*s,{triangleIndicesEndPosition:i,triangleIndices:h}}(i,f,E);if(n.maxDecodingStep<l)return{header:g,vertexData:f,triangleIndices:T};const{westIndices:m,southIndices:y,eastIndices:b,northIndices:S,edgeIndicesEndPosition:w}=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 a=o(e.buffer,i,r,s,!1);i+=r*s;const h=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const u=o(e.buffer,i,h,s,!1);i+=h*s;const l=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const c=o(e.buffer,i,l,s,!1);i+=l*s;const d=e.getUint32(i,!0);i+=Uint32Array.BYTES_PER_ELEMENT;const g=o(e.buffer,i,d,s,!1);return i+=d*s,{edgeIndicesEndPosition:i,westIndices:a,southIndices:u,eastIndices:c,northIndices:g}}(i,f,p);if(n.maxDecodingStep<c)return{header:g,vertexData:f,triangleIndices:T,westIndices:m,northIndices:S,eastIndices:b,southIndices:y};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=a(o)}i+=r}var s;return{extensions:n,extensionsEndPosition:i}}(i,w);return{header:g,vertexData:f,triangleIndices:T,westIndices:m,northIndices:S,eastIndices:b,southIndices:y,extensions:P}}n(0);function _(...e){const t=e,n=t&&t.length>1&&t[0].constructor||null;if(!n)throw new Error('"concatenateTypedArrays" - incorrect quantity of arguments or arguments have incompatible data types');const i=new n(t.reduce((e,t)=>e+t.length,0));let s=0;for(const e of t)i.set(e,s),s+=e.length;return i}function f(e,t,n,i=null){const s=i?function(e,t){e.westIndices.sort((e,n)=>t[3*e+1]-t[3*n+1]),e.eastIndices.sort((e,n)=>t[3*n+1]-t[3*e+1]),e.southIndices.sort((e,n)=>t[3*n]-t[3*e]),e.northIndices.sort((e,n)=>t[3*e]-t[3*n]);const n=[];for(const t in e){const i=e[t];for(let e=0;e<i.length-1;e++)n.push([i[e],i[e+1]])}return n}(i,e.POSITION.value):function(e){const t=[];for(let n=0;n<e.length;n+=3)t.push([e[n],e[n+1]]),t.push([e[n+1],e[n+2]]),t.push([e[n+2],e[n]]);t.sort((e,t)=>Math.min(...e)-Math.min(...t)||Math.max(...e)-Math.max(...t));const n=[];let i=1;for(;i<t.length;)t[i][0]===t[i-1][1]&&t[i][1]===t[i-1][0]?i+=2:(n.push(t[i-1]),i++);return n}(t),r=new e.POSITION.value.constructor(6*s.length),o=new e.TEXCOORD_0.value.constructor(4*s.length),a=new t.constructor(6*s.length);for(let t=0;t<s.length;t++){E({edge:s[t],edgeIndex:t,attributes:e,skirtHeight:n,newPosition:r,newTexcoord0:o,newTriangles:a})}e.POSITION.value=_(e.POSITION.value,r),e.TEXCOORD_0.value=_(e.TEXCOORD_0.value,o);return{attributes:e,triangles:t instanceof Array?t.concat(a):_(t,a)}}function E({edge:e,edgeIndex:t,attributes:n,skirtHeight:i,newPosition:s,newTexcoord0:r,newTriangles:o}){const a=n.POSITION.value.length,h=2*t,u=2*t+1;s.set(n.POSITION.value.subarray(3*e[0],3*e[0]+3),3*h),s[3*h+2]=s[3*h+2]-i,s.set(n.POSITION.value.subarray(3*e[1],3*e[1]+3),3*u),s[3*u+2]=s[3*u+2]-i,r.set(n.TEXCOORD_0.value.subarray(2*e[0],2*e[0]+2),2*h),r.set(n.TEXCOORD_0.value.subarray(2*e[1],2*e[1]+2),2*u);const l=2*t*3;o[l]=e[0],o[l+1]=e[1],o[l+2]=a/3+u,o[l+3]=a/3+u,o[l+4]=a/3+h,o[l+5]=e[0]}function T(e,t){if(!e)return null;const{bounds:n}=t,{header:s,vertexData:r,triangleIndices:o,westIndices:a,northIndices:h,eastIndices:l,southIndices:c}=g(e,u);let d=o,_=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,c=s-i,d=e.length/3,g=new Float32Array(3*d),_=new Float32Array(2*d);for(let t=0;t<d;t++){const n=e[t]/32767,s=e[t+d]/32767,a=e[t+2*d]/32767;g[3*t+0]=n*u+r,g[3*t+1]=s*l+o,g[3*t+2]=a*c+i,_[2*t+0]=n,_[2*t+1]=s}return{POSITION:{value:g,size:3},TEXCOORD_0:{value:_,size:2}}}(r,s,n);const E=i(_);if(t.skirtHeight){const{attributes:e,triangles:n}=f(_,d,t.skirtHeight,{westIndices:a,northIndices:h,eastIndices:l,southIndices:c});_=e,d=n}return{loaderData:{header:{}},header:{vertexCount:d.length,boundingBox:E},mode:4,indices:{value:d,size:1},attributes:_}}function p(e,t){return T(e,t["quantized-mesh"])}class m{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 y(e,this)}}class y{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],c=a+u>>1,d=h+l>>1,g=c+d-h,_=d+a-c,f=(s[h*i+a]+s[l*i+u])/2,E=d*i+c,T=Math.abs(f-s[E]);if(r[E]=Math.max(r[E],T),o<t){const e=(h+_>>1)*i+(a+g>>1),t=(l+_>>1)*i+(u+g>>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,c,d){const g=o+u>>1,_=h+l>>1;Math.abs(o-c)+Math.abs(h-d)>1&&i[_*t+g]>e?(a(c,d,o,h,g,_),a(u,l,c,d,g,_)):(n[h*t+o]=n[h*t+o]||++s,n[l*t+u]=n[l*t+u]||++s,n[d*t+c]=n[d*t+c]||++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 c(s,r,o,a,d,g){const _=s+o>>1,f=r+a>>1;if(Math.abs(s-d)+Math.abs(r-g)>1&&i[f*t+_]>e)c(d,g,s,r,_,f),c(o,a,d,g,_,f);else{const e=n[r*t+s]-1,i=n[a*t+o]-1,c=n[g*t+d]-1;h[2*e]=s,h[2*e+1]=r,h[2*i]=o,h[2*i+1]=a,h[2*c]=d,h[2*c+1]=g,u[l++]=e,u[l++]=i,u[l++]=c}}return c(0,0,o,o,o,0),c(o,o,0,0,0,o),{vertices:h,triangles:u}}}class b{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 a=Math.min(e,n,s),h=Math.min(t,i,r),u=Math.max(e,n,s),l=Math.max(t,i,r);let c=S(n,i,s,r,a,h),d=S(s,r,e,t,a,h),g=S(e,t,n,i,a,h);const _=i-t,f=e-n,E=r-i,T=n-s,p=t-r,m=s-e,y=S(e,t,n,i,s,r),b=this.heightAt(e,t)/y,w=this.heightAt(n,i)/y,P=this.heightAt(s,r)/y;let I=0,M=0,x=0,v=0;for(let e=h;e<=l;e++){let t=0;c<0&&0!==E&&(t=Math.max(t,Math.floor(-c/E))),d<0&&0!==p&&(t=Math.max(t,Math.floor(-d/p))),g<0&&0!==_&&(t=Math.max(t,Math.floor(-g/_)));let n=c+E*t,i=d+p*t,s=g+_*t,r=!1;for(let o=a+t;o<=u;o++){if(n>=0&&i>=0&&s>=0){r=!0;const t=b*n+w*i+P*s,a=Math.abs(t-this.heightAt(o,e));v+=a*a,a>I&&(I=a,M=o,x=e)}else if(r)break;n+=E,i+=p,s+=_}c+=T,d+=m,g+=f}(M===e&&x===t||M===n&&x===i||M===s&&x===r)&&(I=0),this._candidates[2*o]=M,this._candidates[2*o+1]=x,this._rms[o]=v,this._queuePush(o,I,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],a=this.coords[2*s],h=this.coords[2*s+1],u=this.coords[2*r],l=this.coords[2*r+1],c=this.coords[2*o],d=this.coords[2*o+1],g=this._candidates[2*e],_=this._candidates[2*e+1],f=this._addPoint(g,_);if(0===S(a,h,u,l,g,_))this._handleCollinear(f,t);else if(0===S(u,l,c,d,g,_))this._handleCollinear(f,n);else if(0===S(c,d,a,h,g,_))this._handleCollinear(f,i);else{const e=this._halfedges[t],a=this._halfedges[n],h=this._halfedges[i],u=this._addTriangle(s,r,f,e,-1,-1,t),l=this._addTriangle(r,o,f,a,-1,u+1),c=this._addTriangle(o,s,f,h,u+2,l+1);this._legalize(u),this._legalize(l),this._legalize(c)}}_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],c=this.triangles[o],d=this.coords;if(!function(e,t,n,i,s,r,o,a){const h=e-o,u=t-a,l=n-o,c=i-a,d=s-o,g=r-a,_=l*l+c*c,f=d*d+g*g;return h*(c*f-_*g)-u*(l*f-_*d)+(h*h+u*u)*(l*g-c*d)<0}(d[2*h],d[2*h+1],d[2*u],d[2*u+1],d[2*l],d[2*l+1],d[2*c],d[2*c+1]))return;const g=this._halfedges[s],_=this._halfedges[r],f=this._halfedges[o],E=this._halfedges[a];this._queueRemove(n/3),this._queueRemove(i/3);const T=this._addTriangle(h,c,l,-1,f,g,n),p=this._addTriangle(c,h,u,T,_,E,i);this._legalize(T+1),this._legalize(p+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 c=l-l%3,d=c+(l+2)%3,g=c+(l+1)%3,_=this.triangles[d],f=this._halfedges[d],E=this._halfedges[g];this._queueRemove(c/3);const T=this._addTriangle(r,o,e,u,-1,-1,n),p=this._addTriangle(o,_,e,E,-1,T+1,c),m=this._addTriangle(_,a,e,f,-1,p+1),y=this._addTriangle(a,r,e,h,T+2,m+1);this._legalize(T),this._legalize(p),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 S(e,t,n,i,s,r){return(n-s)*(t-r)-(i-r)*(e-s)}function w(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],c=e[t+2];u[i+s]=n*r+l*a+c*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 P(e,t){if(null===e)return null;const{meshMaxError:n,bounds:s,elevationDecoder:r}=t,{data:o,width:a,height:h}=e;let u,l;switch(t.tesselator){case"martini":u=w(o,a,h,r,t.tesselator),l=I(n,a,u);break;case"delatin":u=w(o,a,h,r,t.tesselator),l=M(n,a,h,u);break;default:a!==h||h&a-1?(u=w(o,a,h,r,"delatin"),l=M(n,a,h,u)):(u=w(o,a,h,r,"martini"),l=I(n,a,u))}const{vertices:c}=l;let{triangles:d}=l,g=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,c,d]=s||[0,0,n,i],g=(c-u)/n,_=(d-l)/i;for(let s=0;s<o;s++){const o=e[2*s],l=e[2*s+1],c=l*r+o;a[3*s+0]=o*g+u,a[3*s+1]=-l*_+d,a[3*s+2]=t[c],h[2*s+0]=o/n,h[2*s+1]=l/i}return{POSITION:{value:a,size:3},TEXCOORD_0:{value:h,size:2}}}(c,u,a,h,s);const _=i(g);if(t.skirtHeight){const{attributes:e,triangles:n}=f(g,d,t.skirtHeight);g=e,d=n}return{loaderData:{header:{}},header:{vertexCount:d.length,boundingBox:_},mode:4,indices:{value:Uint32Array.from(d),size:1},attributes:g}}function I(e,t,n){const i=new m(t+1).createTile(n),{vertices:s,triangles:r}=i.getMesh(e);return{vertices:s,triangles:r}}function M(e,t,n,i){const s=new b(i,t+1,n+1);s.run(e);const{coords:r,triangles:o}=s;return{vertices:r,triangles:o}}const x={name:"Terrain",id:"terrain",module:"terrain",version:"3.1.0-alpha.3",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},skirtHeight:null}}},v={name:"Quantized Mesh",id:"quantized-mesh",module:"terrain",version:"3.1.0-alpha.3",worker:!0,extensions:["terrain"],mimeTypes:["application/vnd.quantized-mesh"],options:{"quantized-mesh":{bounds:[0,0,1,1],skirtHeight:null}}},O={...x,parse:async function(e,t,n){return t.image=t.image||{},t.image.type="data",P(await n.parse(e,t,t.baseUri),t.terrain)}},q=O,A={...v,parseSync:p,parse:async(e,t)=>p(e,t)},L=A}])}));
|
|
2
|
-
//# sourceMappingURL=dist.min.js.map
|
package/dist/dist.min.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap","webpack:///./src/bundle.ts","webpack:///../schema/src/category/mesh/mesh-utils.ts","webpack:///./src/lib/decode-quantized-mesh.js","webpack:///../loader-utils/src/lib/binary-utils/array-buffer-utils.ts","webpack:///./src/lib/helpers/skirt.js","webpack:///./src/lib/parse-quantized-mesh.js","webpack:////home/user/apps/loaders.gl/node_modules/@mapbox/martini/index.js","webpack:///./src/lib/delatin/index.js","webpack:///./src/lib/parse-terrain.js","webpack:///./src/lib/utils/version.js","webpack:///./src/terrain-loader.ts","webpack:///./src/quantized-mesh-loader.ts","webpack:///./src/index.ts"],"names":["root","factory","exports","module","define","amd","a","i","window","installedModules","__webpack_require__","moduleId","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","moduleExports","require","globalThis","loaders","assign","getMeshBoundingBox","attributes","minX","Infinity","minY","minZ","maxX","maxY","maxZ","positions","POSITION","len","length","x","y","z","QUANTIZED_MESH_HEADER","Map","Float64Array","BYTES_PER_ELEMENT","Float32Array","decodeZigZag","decodeIndex","buffer","position","indicesCount","bytesPerIndex","encoded","indices","Uint16Array","Uint32Array","highest","code","decodeWaterMaskExtension","extensionDataView","slice","byteOffset","byteLength","DECODING_STEPS","DEFAULT_OPTIONS","maxDecodingStep","decode","data","userOptions","options","view","DataView","header","headerEndPosition","dataView","bytesCount","getFloat64","getFloat32","decodeHeader","vertexData","vertexDataEndPosition","vertexCount","getUint32","bytesPerArrayElement","elementArrayLength","uArrayStartPosition","vArrayStartPosition","heightArrayStartPosition","u","v","height","getUint16","decodeVertexData","triangleIndices","triangleIndicesEndPosition","triangleCount","triangleIndicesCount","decodeTriangleIndices","westIndices","southIndices","eastIndices","northIndices","edgeIndicesEndPosition","westVertexCount","southVertexCount","eastVertexCount","northVertexCount","decodeEdgeIndices","extensions","indicesEndPosition","extensionsEndPosition","extensionId","getUint8","Uint8Array","extensionLength","extensionView","vertexNormals","waterMask","decodeExtensions","concatenateTypedArrays","typedArrays","arrays","TypedArrayConstructor","constructor","Error","result","reduce","acc","offset","array","set","addSkirt","triangles","skirtHeight","outsideIndices","outsideEdges","sort","b","edges","index","indexGroup","push","getOutsideEdgesFromIndices","Math","min","max","getOutsideEdgesFromTriangles","newPosition","newTexcoord0","TEXCOORD_0","newTriangles","updateAttributesForNewEdge","edge","edgeIndex","Array","concat","positionsLength","vertex1Offset","vertex2Offset","subarray","triangle1Offset","getTileMesh","arrayBuffer","bounds","originalTriangleIndices","minHeight","maxHeight","xScale","yScale","zScale","nCoords","texCoords","size","getMeshAttributes","boundingBox","newAttributes","loaderData","loadQuantizedMesh","Martini","gridSize","this","tileSize","numTriangles","numParentTriangles","coords","id","ax","ay","bx","by","cx","cy","mx","my","k","terrain","Tile","martini","errors","update","interpolatedHeight","middleIndex","middleError","abs","leftChildIndex","rightChildIndex","maxError","numVertices","countElements","fill","vertices","triIndex","processTriangle","Delatin","width","_halfedges","_candidates","_queueIndices","_queue","_errors","_rms","_pending","_pendingLen","_rmsSum","x1","y1","p0","_addPoint","p1","p2","p3","t0","_addTriangle","_flush","run","getMaxError","refine","_step","getRMSD","sqrt","heightAt","_findCandidate","p0x","p0y","p1x","p1y","p2x","p2y","w00","orient","w01","w02","a01","b01","a12","b12","a20","b20","z0","z1","z2","rms","dx","floor","w0","w1","w2","wasInside","dz","_queuePush","_queuePop","e0","e1","e2","px","py","pn","_handleCollinear","h0","h1","h2","t1","t2","_legalize","ab","bc","ca","e","a0","b0","al","ar","bl","br","pr","pl","dy","ex","ey","fx","fy","bp","cp","inCircle","hal","har","hbl","hbr","_queueRemove","t3","error","_queueUp","_queueSwap","_queueDown","_queuePopBack","pop","it","indexOf","_queueLess","j","pi","pj","j0","i0","j1","j2","getTerrain","imageData","elevationDecoder","tesselator","rScaler","bScaler","gScaler","g","getMesh","terrainImage","terrainOptions","meshMaxError","mesh","getMartiniTileMesh","getDelatinTileMesh","numOfVerticies","pixelIdx","from","tile","createTile","tin","TerrainLoader","version","worker","mimeTypes","QuantizedMeshLoader","TerrainWorkerLoader","parse","async","context","image","type","baseUri","_typecheckTerrainLoader","QuantizedMeshWorkerLoader","parseSync","parseQuantizedMesh","_typecheckQuantizedMeshLoader"],"mappings":"CAAA,SAA2CA,EAAMC,GAChD,GAAsB,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,SACb,GAAqB,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,OACP,CACJ,IAAIK,EAAIL,IACR,IAAI,IAAIM,KAAKD,GAAuB,iBAAZJ,QAAuBA,QAAUF,GAAMO,GAAKD,EAAEC,IAPxE,CASGC,QAAQ,WACX,O,YCTE,IAAIC,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUT,QAGnC,IAAIC,EAASM,EAAiBE,GAAY,CACzCJ,EAAGI,EACHC,GAAG,EACHV,QAAS,IAUV,OANAW,EAAQF,GAAUG,KAAKX,EAAOD,QAASC,EAAQA,EAAOD,QAASQ,GAG/DP,EAAOS,GAAI,EAGJT,EAAOD,QA0Df,OArDAQ,EAAoBK,EAAIF,EAGxBH,EAAoBM,EAAIP,EAGxBC,EAAoBO,EAAI,SAASf,EAASgB,EAAMC,GAC3CT,EAAoBU,EAAElB,EAASgB,IAClCG,OAAOC,eAAepB,EAASgB,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhET,EAAoBe,EAAI,SAASvB,GACX,oBAAXwB,QAA0BA,OAAOC,aAC1CN,OAAOC,eAAepB,EAASwB,OAAOC,YAAa,CAAEC,MAAO,WAE7DP,OAAOC,eAAepB,EAAS,aAA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G,EAAG,EAAG,GAClB9B,YAAa,QCNNsN,EAAgB,IACxBK,EACHC,MJ+JaC,eAA2BhM,EAAa7F,EAAS8R,GAK9D,OAJA9R,EAAQ+R,MAAQ/R,EAAQ+R,OAAS,GACjC/R,EAAQ+R,MAAMC,KAAO,OAGdvB,QAFaqB,EAAQF,MAAM/L,EAAa7F,EAASA,EAAQiS,SAE1CjS,EAAQ8H,WIjKnBoK,EAA4CZ,EAS5CI,EAAsB,IAC9BS,EACHC,UAAWC,EACXT,MAAOC,MAAOhM,EAAa7F,IAAYqS,EAAmBxM,EAAa7F,IAG5DsS,EAAkDZ","file":"dist.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n","// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n","// Mesh category utilities\n// TODO - move to mesh category module, or to math.gl/geometry module\nimport {TypedArray} from '../../types';\nimport {MeshAttributes} from './mesh-types';\n\ntype TypedArrays = {[key: string]: TypedArray};\n\n/**\n * Holds an axis aligned bounding box\n * TODO - make sure AxisAlignedBoundingBox in math.gl/culling understands this format (or change this format)\n */\ntype BoundingBox = [[number, number, number], [number, number, number]];\n\n/**\n * Get number of vertices in mesh\n * @param attributes\n */\nexport function getMeshSize(attributes: TypedArrays): number {\n let size = 0;\n for (const attributeName in attributes) {\n const attribute = attributes[attributeName];\n if (ArrayBuffer.isView(attribute)) {\n // @ts-ignore DataView doesn't have BYTES_PER_ELEMENT\n size += attribute.byteLength * attribute.BYTES_PER_ELEMENT;\n }\n }\n return size;\n}\n\n/**\n * Get the (axis aligned) bounding box of a mesh\n * @param attributes\n * @returns array of two vectors representing the axis aligned bounding box\n */\n// eslint-disable-next-line complexity\nexport function getMeshBoundingBox(attributes: MeshAttributes): BoundingBox {\n let minX = Infinity;\n let minY = Infinity;\n let minZ = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n let maxZ = -Infinity;\n\n const positions = attributes.POSITION ? attributes.POSITION.value : [];\n const len = positions && positions.length;\n\n for (let i = 0; i < len; i += 3) {\n const x = positions[i];\n const y = positions[i + 1];\n const z = positions[i + 2];\n\n minX = x < minX ? x : minX;\n minY = y < minY ? y : minY;\n minZ = z < minZ ? z : minZ;\n\n maxX = x > maxX ? x : maxX;\n maxY = y > maxY ? y : maxY;\n maxZ = z > maxZ ? z : maxZ;\n }\n return [\n [minX, minY, minZ],\n [maxX, maxY, maxZ]\n ];\n}\n","// Copyright (C) 2018-2019 HERE Europe B.V.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n// SOFTWARE.\n\nconst QUANTIZED_MESH_HEADER = new Map([\n ['centerX', Float64Array.BYTES_PER_ELEMENT],\n ['centerY', Float64Array.BYTES_PER_ELEMENT],\n ['centerZ', Float64Array.BYTES_PER_ELEMENT],\n\n ['minHeight', Float32Array.BYTES_PER_ELEMENT],\n ['maxHeight', Float32Array.BYTES_PER_ELEMENT],\n\n ['boundingSphereCenterX', Float64Array.BYTES_PER_ELEMENT],\n ['boundingSphereCenterY', Float64Array.BYTES_PER_ELEMENT],\n ['boundingSphereCenterZ', Float64Array.BYTES_PER_ELEMENT],\n ['boundingSphereRadius', Float64Array.BYTES_PER_ELEMENT],\n\n ['horizonOcclusionPointX', Float64Array.BYTES_PER_ELEMENT],\n ['horizonOcclusionPointY', Float64Array.BYTES_PER_ELEMENT],\n ['horizonOcclusionPointZ', Float64Array.BYTES_PER_ELEMENT]\n]);\n\nfunction decodeZigZag(value) {\n return (value >> 1) ^ -(value & 1);\n}\n\nfunction decodeHeader(dataView) {\n let position = 0;\n const header = {};\n\n for (const [key, bytesCount] of QUANTIZED_MESH_HEADER) {\n const getter = bytesCount === 8 ? dataView.getFloat64 : dataView.getFloat32;\n\n header[key] = getter.call(dataView, position, true);\n position += bytesCount;\n }\n\n return {header, headerEndPosition: position};\n}\n\nfunction decodeVertexData(dataView, headerEndPosition) {\n let position = headerEndPosition;\n const elementsPerVertex = 3;\n const vertexCount = dataView.getUint32(position, true);\n const vertexData = new Uint16Array(vertexCount * elementsPerVertex);\n\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const bytesPerArrayElement = Uint16Array.BYTES_PER_ELEMENT;\n const elementArrayLength = vertexCount * bytesPerArrayElement;\n const uArrayStartPosition = position;\n const vArrayStartPosition = uArrayStartPosition + elementArrayLength;\n const heightArrayStartPosition = vArrayStartPosition + elementArrayLength;\n\n let u = 0;\n let v = 0;\n let height = 0;\n\n for (let i = 0; i < vertexCount; i++) {\n u += decodeZigZag(dataView.getUint16(uArrayStartPosition + bytesPerArrayElement * i, true));\n v += decodeZigZag(dataView.getUint16(vArrayStartPosition + bytesPerArrayElement * i, true));\n height += decodeZigZag(\n dataView.getUint16(heightArrayStartPosition + bytesPerArrayElement * i, true)\n );\n\n vertexData[i] = u;\n vertexData[i + vertexCount] = v;\n vertexData[i + vertexCount * 2] = height;\n }\n\n position += elementArrayLength * 3;\n\n return {vertexData, vertexDataEndPosition: position};\n}\n\nfunction decodeIndex(buffer, position, indicesCount, bytesPerIndex, encoded = true) {\n let indices;\n\n if (bytesPerIndex === 2) {\n indices = new Uint16Array(buffer, position, indicesCount);\n } else {\n indices = new Uint32Array(buffer, position, indicesCount);\n }\n\n if (!encoded) {\n return indices;\n }\n\n let highest = 0;\n\n for (let i = 0; i < indices.length; ++i) {\n const code = indices[i];\n\n indices[i] = highest - code;\n\n if (code === 0) {\n ++highest;\n }\n }\n\n return indices;\n}\n\nfunction decodeTriangleIndices(dataView, vertexData, vertexDataEndPosition) {\n let position = vertexDataEndPosition;\n const elementsPerVertex = 3;\n const vertexCount = vertexData.length / elementsPerVertex;\n const bytesPerIndex =\n vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;\n\n if (position % bytesPerIndex !== 0) {\n position += bytesPerIndex - (position % bytesPerIndex);\n }\n\n const triangleCount = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const triangleIndicesCount = triangleCount * 3;\n const triangleIndices = decodeIndex(\n dataView.buffer,\n position,\n triangleIndicesCount,\n bytesPerIndex\n );\n position += triangleIndicesCount * bytesPerIndex;\n\n return {\n triangleIndicesEndPosition: position,\n triangleIndices\n };\n}\n\nfunction decodeEdgeIndices(dataView, vertexData, triangleIndicesEndPosition) {\n let position = triangleIndicesEndPosition;\n const elementsPerVertex = 3;\n const vertexCount = vertexData.length / elementsPerVertex;\n const bytesPerIndex =\n vertexCount > 65536 ? Uint32Array.BYTES_PER_ELEMENT : Uint16Array.BYTES_PER_ELEMENT;\n\n const westVertexCount = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const westIndices = decodeIndex(dataView.buffer, position, westVertexCount, bytesPerIndex, false);\n position += westVertexCount * bytesPerIndex;\n\n const southVertexCount = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const southIndices = decodeIndex(\n dataView.buffer,\n position,\n southVertexCount,\n bytesPerIndex,\n false\n );\n position += southVertexCount * bytesPerIndex;\n\n const eastVertexCount = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const eastIndices = decodeIndex(dataView.buffer, position, eastVertexCount, bytesPerIndex, false);\n position += eastVertexCount * bytesPerIndex;\n\n const northVertexCount = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const northIndices = decodeIndex(\n dataView.buffer,\n position,\n northVertexCount,\n bytesPerIndex,\n false\n );\n position += northVertexCount * bytesPerIndex;\n\n return {\n edgeIndicesEndPosition: position,\n westIndices,\n southIndices,\n eastIndices,\n northIndices\n };\n}\n\nfunction decodeVertexNormalsExtension(extensionDataView) {\n return new Uint8Array(\n extensionDataView.buffer,\n extensionDataView.byteOffset,\n extensionDataView.byteLength\n );\n}\n\nfunction decodeWaterMaskExtension(extensionDataView) {\n return extensionDataView.buffer.slice(\n extensionDataView.byteOffset,\n extensionDataView.byteOffset + extensionDataView.byteLength\n );\n}\n\nfunction decodeExtensions(dataView, indicesEndPosition) {\n const extensions = {};\n\n if (dataView.byteLength <= indicesEndPosition) {\n return {extensions, extensionsEndPosition: indicesEndPosition};\n }\n\n let position = indicesEndPosition;\n\n while (position < dataView.byteLength) {\n const extensionId = dataView.getUint8(position, true);\n position += Uint8Array.BYTES_PER_ELEMENT;\n\n const extensionLength = dataView.getUint32(position, true);\n position += Uint32Array.BYTES_PER_ELEMENT;\n\n const extensionView = new DataView(dataView.buffer, position, extensionLength);\n\n switch (extensionId) {\n case 1: {\n extensions.vertexNormals = decodeVertexNormalsExtension(extensionView);\n\n break;\n }\n case 2: {\n extensions.waterMask = decodeWaterMaskExtension(extensionView);\n\n break;\n }\n default: {\n // console.warn(`Unknown extension with id ${extensionId}`)\n }\n }\n\n position += extensionLength;\n }\n\n return {extensions, extensionsEndPosition: position};\n}\n\nexport const DECODING_STEPS = {\n header: 0,\n vertices: 1,\n triangleIndices: 2,\n edgeIndices: 3,\n extensions: 4\n};\n\nconst DEFAULT_OPTIONS = {\n maxDecodingStep: DECODING_STEPS.extensions\n};\n\nexport default function decode(data, userOptions) {\n const options = Object.assign({}, DEFAULT_OPTIONS, userOptions);\n const view = new DataView(data);\n const {header, headerEndPosition} = decodeHeader(view);\n\n if (options.maxDecodingStep < DECODING_STEPS.vertices) {\n return {header};\n }\n\n const {vertexData, vertexDataEndPosition} = decodeVertexData(view, headerEndPosition);\n\n if (options.maxDecodingStep < DECODING_STEPS.triangleIndices) {\n return {header, vertexData};\n }\n\n const {triangleIndices, triangleIndicesEndPosition} = decodeTriangleIndices(\n view,\n vertexData,\n vertexDataEndPosition\n );\n\n if (options.maxDecodingStep < DECODING_STEPS.edgeIndices) {\n return {header, vertexData, triangleIndices};\n }\n\n const {westIndices, southIndices, eastIndices, northIndices, edgeIndicesEndPosition} =\n decodeEdgeIndices(view, vertexData, triangleIndicesEndPosition);\n\n if (options.maxDecodingStep < DECODING_STEPS.extensions) {\n return {\n header,\n vertexData,\n triangleIndices,\n westIndices,\n northIndices,\n eastIndices,\n southIndices\n };\n }\n\n const {extensions} = decodeExtensions(view, edgeIndicesEndPosition);\n\n return {\n header,\n vertexData,\n triangleIndices,\n westIndices,\n northIndices,\n eastIndices,\n southIndices,\n extensions\n };\n}\n","import {TypedArray} from '../../types';\nimport {isBuffer, bufferToArrayBuffer} from './buffer-utils';\n\n/**\n * Convert an object to an array buffer\n */\nexport function toArrayBuffer(data: any): ArrayBuffer {\n // Note: Should be called first, Buffers can trigger other detections below\n if (isBuffer(data)) {\n return bufferToArrayBuffer(data);\n }\n\n if (data instanceof ArrayBuffer) {\n return data;\n }\n\n // Careful - Node Buffers look like Uint8Arrays (keep after isBuffer)\n if (ArrayBuffer.isView(data)) {\n if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {\n return data.buffer;\n }\n return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);\n }\n\n if (typeof data === 'string') {\n const text = data;\n const uint8Array = new TextEncoder().encode(text);\n return uint8Array.buffer;\n }\n\n // HACK to support Blob polyfill\n if (data && typeof data === 'object' && data._toArrayBuffer) {\n return data._toArrayBuffer();\n }\n\n throw new Error('toArrayBuffer');\n}\n\n/**\n * compare two binary arrays for equality\n * @param {ArrayBuffer} a\n * @param {ArrayBuffer} b\n * @param {number} byteLength\n */\nexport function compareArrayBuffers(\n arrayBuffer1: ArrayBuffer,\n arrayBuffer2: ArrayBuffer,\n byteLength?: number\n): boolean {\n byteLength = byteLength || arrayBuffer1.byteLength;\n if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {\n return false;\n }\n const array1 = new Uint8Array(arrayBuffer1);\n const array2 = new Uint8Array(arrayBuffer2);\n for (let i = 0; i < array1.length; ++i) {\n if (array1[i] !== array2[i]) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Concatenate a sequence of ArrayBuffers\n * @return A concatenated ArrayBuffer\n */\nexport function concatenateArrayBuffers(...sources: (ArrayBuffer | Uint8Array)[]): ArrayBuffer {\n // Make sure all inputs are wrapped in typed arrays\n const sourceArrays = sources.map((source2) =>\n source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2\n );\n\n // Get length of all inputs\n const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);\n\n // Allocate array with space for all inputs\n const result = new Uint8Array(byteLength);\n\n // Copy the subarrays\n let offset = 0;\n for (const sourceArray of sourceArrays) {\n result.set(sourceArray, offset);\n offset += sourceArray.byteLength;\n }\n\n // We work with ArrayBuffers, discard the typed array wrapper\n return result.buffer;\n}\n\n/**\n * Concatenate arbitrary count of typed arrays\n * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays\n * @param {...*} arrays - list of arrays. All arrays should be the same type\n * @return A concatenated TypedArray\n */\nexport function concatenateTypedArrays<T>(...typedArrays: T[]): T {\n // @ts-ignore\n const arrays = typedArrays as TypedArray[];\n // @ts-ignore\n const TypedArrayConstructor = (arrays && arrays.length > 1 && arrays[0].constructor) || null;\n if (!TypedArrayConstructor) {\n throw new Error(\n '\"concatenateTypedArrays\" - incorrect quantity of arguments or arguments have incompatible data types'\n );\n }\n\n const sumLength = arrays.reduce((acc, value) => acc + value.length, 0);\n // @ts-ignore typescript does not like dynamic constructors\n const result = new TypedArrayConstructor(sumLength);\n let offset = 0;\n for (const array of arrays) {\n result.set(array, offset);\n offset += array.length;\n }\n return result;\n}\n\n/**\n * Copy a view of an ArrayBuffer into new ArrayBuffer with byteOffset = 0\n * @param arrayBuffer\n * @param byteOffset\n * @param byteLength\n */\nexport function sliceArrayBuffer(\n arrayBuffer: ArrayBuffer,\n byteOffset: number,\n byteLength?: number\n): ArrayBuffer {\n const subArray =\n byteLength !== undefined\n ? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength)\n : new Uint8Array(arrayBuffer).subarray(byteOffset);\n const arrayCopy = new Uint8Array(subArray);\n return arrayCopy.buffer;\n}\n","import {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\n/**\n * Add skirt to existing mesh\n * @param {object} attributes - POSITION and TEXCOOD_0 attributes data\n * @param {any} triangles - indices array of the mesh geometry\n * @param {number} skirtHeight - height of the skirt geometry\n * @param {object} outsideIndices - edge indices from quantized mesh data\n * @returns - geometry data with added skirt\n */\nexport function addSkirt(attributes, triangles, skirtHeight, outsideIndices = null) {\n const outsideEdges = outsideIndices\n ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value)\n : getOutsideEdgesFromTriangles(triangles);\n\n // 2 new vertices for each outside edge\n const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);\n const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);\n\n // 2 new triangles for each outside edge\n const newTriangles = new triangles.constructor(outsideEdges.length * 6);\n\n for (let i = 0; i < outsideEdges.length; i++) {\n const edge = outsideEdges[i];\n\n updateAttributesForNewEdge({\n edge,\n edgeIndex: i,\n attributes,\n skirtHeight,\n newPosition,\n newTexcoord0,\n newTriangles\n });\n }\n\n attributes.POSITION.value = concatenateTypedArrays(attributes.POSITION.value, newPosition);\n attributes.TEXCOORD_0.value = concatenateTypedArrays(attributes.TEXCOORD_0.value, newTexcoord0);\n const resultTriangles =\n triangles instanceof Array\n ? triangles.concat(newTriangles)\n : concatenateTypedArrays(triangles, newTriangles);\n\n return {\n attributes,\n triangles: resultTriangles\n };\n}\n\n/**\n * Get geometry edges that located on a border of the mesh\n * @param {any} triangles - indices array of the mesh geometry\n * @returns {number[][]} - outside edges data\n */\nfunction getOutsideEdgesFromTriangles(triangles) {\n const edges = [];\n for (let i = 0; i < triangles.length; i += 3) {\n edges.push([triangles[i], triangles[i + 1]]);\n edges.push([triangles[i + 1], triangles[i + 2]]);\n edges.push([triangles[i + 2], triangles[i]]);\n }\n\n edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));\n\n const outsideEdges = [];\n let index = 1;\n while (index < edges.length) {\n if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {\n index += 2;\n } else {\n outsideEdges.push(edges[index - 1]);\n index++;\n }\n }\n return outsideEdges;\n}\n\n/**\n * Get geometry edges that located on a border of the mesh\n * @param {object} indices - edge indices from quantized mesh data\n * @param {TypedArray} position - position attribute geometry data\n * @returns {number[][]} - outside edges data\n */\nfunction getOutsideEdgesFromIndices(indices, position) {\n // Sort skirt indices to create adjacent triangles\n indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);\n // Reverse (b - a) to match triangle winding\n indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);\n indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);\n // Reverse (b - a) to match triangle winding\n indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);\n\n const edges = [];\n for (const index in indices) {\n const indexGroup = indices[index];\n for (let i = 0; i < indexGroup.length - 1; i++) {\n edges.push([indexGroup[i], indexGroup[i + 1]]);\n }\n }\n return edges;\n}\n\n/**\n * Get geometry edges that located on a border of the mesh\n * @param {object} args\n * @param {number[]} args.edge - edge indices in geometry\n * @param {number} args.edgeIndex - edge index in outsideEdges array\n * @param {object} args.attributes - POSITION and TEXCOORD_0 attributes\n * @param {number} args.skirtHeight - height of the skirt geometry\n * @param {TypedArray} args.newPosition - POSITION array for skirt data\n * @param {TypedArray} args.newTexcoord0 - TEXCOORD_0 array for skirt data\n * @param {TypedArray | Array} args.newTriangles - trinagle indices array for skirt data\n * @returns {void}\n */\nfunction updateAttributesForNewEdge({\n edge,\n edgeIndex,\n attributes,\n skirtHeight,\n newPosition,\n newTexcoord0,\n newTriangles\n}) {\n const positionsLength = attributes.POSITION.value.length;\n const vertex1Offset = edgeIndex * 2;\n const vertex2Offset = edgeIndex * 2 + 1;\n\n // Define POSITION for new 1st vertex\n newPosition.set(\n attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3),\n vertex1Offset * 3\n );\n newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight; // put down elevation on the skirt height\n\n // Define POSITION for new 2nd vertex\n newPosition.set(\n attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3),\n vertex2Offset * 3\n );\n newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight; // put down elevation on the skirt height\n\n // Use same TEXCOORDS for skirt vertices\n newTexcoord0.set(\n attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2),\n vertex1Offset * 2\n );\n newTexcoord0.set(\n attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2),\n vertex2Offset * 2\n );\n\n // Define new triangles\n const triangle1Offset = edgeIndex * 2 * 3;\n newTriangles[triangle1Offset] = edge[0];\n newTriangles[triangle1Offset + 1] = edge[1];\n newTriangles[triangle1Offset + 2] = positionsLength / 3 + vertex2Offset;\n\n newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;\n newTriangles[triangle1Offset + 4] = positionsLength / 3 + vertex1Offset;\n newTriangles[triangle1Offset + 5] = edge[0];\n}\n","import {getMeshBoundingBox} from '@loaders.gl/schema';\nimport decode, {DECODING_STEPS} from './decode-quantized-mesh';\nimport {addSkirt} from './helpers/skirt';\n\nfunction getMeshAttributes(vertexData, header, bounds) {\n const {minHeight, maxHeight} = header;\n const [minX, minY, maxX, maxY] = bounds || [0, 0, 1, 1];\n const xScale = maxX - minX;\n const yScale = maxY - minY;\n const zScale = maxHeight - minHeight;\n\n const nCoords = vertexData.length / 3;\n // vec3. x, y defined by bounds, z in meters\n const positions = new Float32Array(nCoords * 3);\n\n // vec2. 1 to 1 relationship with position. represents the uv on the texture image. 0,0 to 1,1.\n const texCoords = new Float32Array(nCoords * 2);\n\n // Data is not interleaved; all u, then all v, then all heights\n for (let i = 0; i < nCoords; i++) {\n const x = vertexData[i] / 32767;\n const y = vertexData[i + nCoords] / 32767;\n const z = vertexData[i + nCoords * 2] / 32767;\n\n positions[3 * i + 0] = x * xScale + minX;\n positions[3 * i + 1] = y * yScale + minY;\n positions[3 * i + 2] = z * zScale + minHeight;\n\n texCoords[2 * i + 0] = x;\n texCoords[2 * i + 1] = y;\n }\n\n return {\n POSITION: {value: positions, size: 3},\n TEXCOORD_0: {value: texCoords, size: 2}\n // TODO: Parse normals if they exist in the file\n // NORMAL: {}, - optional, but creates the high poly look with lighting\n };\n}\n\nfunction getTileMesh(arrayBuffer, options) {\n if (!arrayBuffer) {\n return null;\n }\n const {bounds} = options;\n // Don't parse edge indices or format extensions\n const {\n header,\n vertexData,\n triangleIndices: originalTriangleIndices,\n westIndices,\n northIndices,\n eastIndices,\n southIndices\n } = decode(arrayBuffer, DECODING_STEPS.triangleIndices);\n let triangleIndices = originalTriangleIndices;\n let attributes = getMeshAttributes(vertexData, header, bounds);\n\n // Compute bounding box before adding skirt so that z values are not skewed\n // TODO: Find bounding box from header, instead of doing extra pass over\n // vertices.\n const boundingBox = getMeshBoundingBox(attributes);\n\n if (options.skirtHeight) {\n const {attributes: newAttributes, triangles: newTriangles} = addSkirt(\n attributes,\n triangleIndices,\n options.skirtHeight,\n {\n westIndices,\n northIndices,\n eastIndices,\n southIndices\n }\n );\n attributes = newAttributes;\n triangleIndices = newTriangles;\n }\n\n return {\n // Data return by this loader implementation\n loaderData: {\n header: {}\n },\n header: {\n // @ts-ignore\n vertexCount: triangleIndices.length,\n boundingBox\n },\n mode: 4, // TRIANGLES\n indices: {value: triangleIndices, size: 1},\n attributes\n };\n}\n\nexport default function loadQuantizedMesh(arrayBuffer, options) {\n return getTileMesh(arrayBuffer, options['quantized-mesh']);\n}\n","\nexport default class Martini {\n constructor(gridSize = 257) {\n this.gridSize = gridSize;\n const tileSize = gridSize - 1;\n if (tileSize & (tileSize - 1)) throw new Error(\n `Expected grid size to be 2^n+1, got ${gridSize}.`);\n\n this.numTriangles = tileSize * tileSize * 2 - 2;\n this.numParentTriangles = this.numTriangles - tileSize * tileSize;\n\n this.indices = new Uint32Array(this.gridSize * this.gridSize);\n\n // coordinates for all possible triangles in an RTIN tile\n this.coords = new Uint16Array(this.numTriangles * 4);\n\n // get triangle coordinates from its index in an implicit binary tree\n for (let i = 0; i < this.numTriangles; i++) {\n let id = i + 2;\n let ax = 0, ay = 0, bx = 0, by = 0, cx = 0, cy = 0;\n if (id & 1) {\n bx = by = cx = tileSize; // bottom-left triangle\n } else {\n ax = ay = cy = tileSize; // top-right triangle\n }\n while ((id >>= 1) > 1) {\n const mx = (ax + bx) >> 1;\n const my = (ay + by) >> 1;\n\n if (id & 1) { // left half\n bx = ax; by = ay;\n ax = cx; ay = cy;\n } else { // right half\n ax = bx; ay = by;\n bx = cx; by = cy;\n }\n cx = mx; cy = my;\n }\n const k = i * 4;\n this.coords[k + 0] = ax;\n this.coords[k + 1] = ay;\n this.coords[k + 2] = bx;\n this.coords[k + 3] = by;\n }\n }\n\n createTile(terrain) {\n return new Tile(terrain, this);\n }\n}\n\nclass Tile {\n constructor(terrain, martini) {\n const size = martini.gridSize;\n if (terrain.length !== size * size) throw new Error(\n `Expected terrain data of length ${size * size} (${size} x ${size}), got ${terrain.length}.`);\n\n this.terrain = terrain;\n this.martini = martini;\n this.errors = new Float32Array(terrain.length);\n this.update();\n }\n\n update() {\n const {numTriangles, numParentTriangles, coords, gridSize: size} = this.martini;\n const {terrain, errors} = this;\n\n // iterate over all possible triangles, starting from the smallest level\n for (let i = numTriangles - 1; i >= 0; i--) {\n const k = i * 4;\n const ax = coords[k + 0];\n const ay = coords[k + 1];\n const bx = coords[k + 2];\n const by = coords[k + 3];\n const mx = (ax + bx) >> 1;\n const my = (ay + by) >> 1;\n const cx = mx + my - ay;\n const cy = my + ax - mx;\n\n // calculate error in the middle of the long edge of the triangle\n const interpolatedHeight = (terrain[ay * size + ax] + terrain[by * size + bx]) / 2;\n const middleIndex = my * size + mx;\n const middleError = Math.abs(interpolatedHeight - terrain[middleIndex]);\n\n errors[middleIndex] = Math.max(errors[middleIndex], middleError);\n\n if (i < numParentTriangles) { // bigger triangles; accumulate error with children\n const leftChildIndex = ((ay + cy) >> 1) * size + ((ax + cx) >> 1);\n const rightChildIndex = ((by + cy) >> 1) * size + ((bx + cx) >> 1);\n errors[middleIndex] = Math.max(errors[middleIndex], errors[leftChildIndex], errors[rightChildIndex]);\n }\n }\n }\n\n getMesh(maxError = 0) {\n const {gridSize: size, indices} = this.martini;\n const {errors} = this;\n let numVertices = 0;\n let numTriangles = 0;\n const max = size - 1;\n\n // use an index grid to keep track of vertices that were already used to avoid duplication\n indices.fill(0);\n\n // retrieve mesh in two stages that both traverse the error map:\n // - countElements: find used vertices (and assign each an index), and count triangles (for minimum allocation)\n // - processTriangle: fill the allocated vertices & triangles typed arrays\n\n function countElements(ax, ay, bx, by, cx, cy) {\n const mx = (ax + bx) >> 1;\n const my = (ay + by) >> 1;\n\n if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {\n countElements(cx, cy, ax, ay, mx, my);\n countElements(bx, by, cx, cy, mx, my);\n } else {\n indices[ay * size + ax] = indices[ay * size + ax] || ++numVertices;\n indices[by * size + bx] = indices[by * size + bx] || ++numVertices;\n indices[cy * size + cx] = indices[cy * size + cx] || ++numVertices;\n numTriangles++;\n }\n }\n countElements(0, 0, max, max, max, 0);\n countElements(max, max, 0, 0, 0, max);\n\n const vertices = new Uint16Array(numVertices * 2);\n const triangles = new Uint32Array(numTriangles * 3);\n let triIndex = 0;\n\n function processTriangle(ax, ay, bx, by, cx, cy) {\n const mx = (ax + bx) >> 1;\n const my = (ay + by) >> 1;\n\n if (Math.abs(ax - cx) + Math.abs(ay - cy) > 1 && errors[my * size + mx] > maxError) {\n // triangle doesn't approximate the surface well enough; drill down further\n processTriangle(cx, cy, ax, ay, mx, my);\n processTriangle(bx, by, cx, cy, mx, my);\n\n } else {\n // add a triangle\n const a = indices[ay * size + ax] - 1;\n const b = indices[by * size + bx] - 1;\n const c = indices[cy * size + cx] - 1;\n\n vertices[2 * a] = ax;\n vertices[2 * a + 1] = ay;\n\n vertices[2 * b] = bx;\n vertices[2 * b + 1] = by;\n\n vertices[2 * c] = cx;\n vertices[2 * c + 1] = cy;\n\n triangles[triIndex++] = a;\n triangles[triIndex++] = b;\n triangles[triIndex++] = c;\n }\n }\n processTriangle(0, 0, max, max, max, 0);\n processTriangle(max, max, 0, 0, 0, max);\n\n return {vertices, triangles};\n }\n}\n","// ISC License\n\n// Copyright(c) 2019, Michael Fogleman, Vladimir Agafonkin\n\n// Permission to use, copy, modify, and / or distribute this software for any purpose\n// with or without fee is hereby granted, provided that the above copyright notice\n// and this permission notice appear in all copies.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n// FITNESS.IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n// OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n// THIS SOFTWARE.\n\n/* eslint-disable complexity, max-params, max-statements, max-depth, no-constant-condition */\nexport default class Delatin {\n constructor(data, width, height = width) {\n this.data = data; // height data\n this.width = width;\n this.height = height;\n\n this.coords = []; // vertex coordinates (x, y)\n this.triangles = []; // mesh triangle indices\n\n // additional triangle data\n this._halfedges = [];\n this._candidates = [];\n this._queueIndices = [];\n\n this._queue = []; // queue of added triangles\n this._errors = [];\n this._rms = [];\n this._pending = []; // triangles pending addition to queue\n this._pendingLen = 0;\n\n this._rmsSum = 0;\n\n const x1 = width - 1;\n const y1 = height - 1;\n const p0 = this._addPoint(0, 0);\n const p1 = this._addPoint(x1, 0);\n const p2 = this._addPoint(0, y1);\n const p3 = this._addPoint(x1, y1);\n\n // add initial two triangles\n const t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);\n this._addTriangle(p0, p3, p1, t0, -1, -1);\n this._flush();\n }\n\n // refine the mesh until its maximum error gets below the given one\n run(maxError = 1) {\n while (this.getMaxError() > maxError) {\n this.refine();\n }\n }\n\n // refine the mesh with a single point\n refine() {\n this._step();\n this._flush();\n }\n\n // max error of the current mesh\n getMaxError() {\n return this._errors[0];\n }\n\n // root-mean-square deviation of the current mesh\n getRMSD() {\n return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;\n }\n\n // height value at a given position\n heightAt(x, y) {\n return this.data[this.width * y + x];\n }\n\n // rasterize and queue all triangles that got added or updated in _step\n _flush() {\n const coords = this.coords;\n for (let i = 0; i < this._pendingLen; i++) {\n const t = this._pending[i];\n // rasterize triangle to find maximum pixel error\n const a = 2 * this.triangles[t * 3 + 0];\n const b = 2 * this.triangles[t * 3 + 1];\n const c = 2 * this.triangles[t * 3 + 2];\n this._findCandidate(\n coords[a],\n coords[a + 1],\n coords[b],\n coords[b + 1],\n coords[c],\n coords[c + 1],\n t\n );\n }\n this._pendingLen = 0;\n }\n\n // rasterize a triangle, find its max error, and queue it for processing\n _findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {\n // triangle bounding box\n const minX = Math.min(p0x, p1x, p2x);\n const minY = Math.min(p0y, p1y, p2y);\n const maxX = Math.max(p0x, p1x, p2x);\n const maxY = Math.max(p0y, p1y, p2y);\n\n // forward differencing variables\n let w00 = orient(p1x, p1y, p2x, p2y, minX, minY);\n let w01 = orient(p2x, p2y, p0x, p0y, minX, minY);\n let w02 = orient(p0x, p0y, p1x, p1y, minX, minY);\n const a01 = p1y - p0y;\n const b01 = p0x - p1x;\n const a12 = p2y - p1y;\n const b12 = p1x - p2x;\n const a20 = p0y - p2y;\n const b20 = p2x - p0x;\n\n // pre-multiplied z values at vertices\n const a = orient(p0x, p0y, p1x, p1y, p2x, p2y);\n const z0 = this.heightAt(p0x, p0y) / a;\n const z1 = this.heightAt(p1x, p1y) / a;\n const z2 = this.heightAt(p2x, p2y) / a;\n\n // iterate over pixels in bounding box\n let maxError = 0;\n let mx = 0;\n let my = 0;\n let rms = 0;\n for (let y = minY; y <= maxY; y++) {\n // compute starting offset\n let dx = 0;\n if (w00 < 0 && a12 !== 0) {\n dx = Math.max(dx, Math.floor(-w00 / a12));\n }\n if (w01 < 0 && a20 !== 0) {\n dx = Math.max(dx, Math.floor(-w01 / a20));\n }\n if (w02 < 0 && a01 !== 0) {\n dx = Math.max(dx, Math.floor(-w02 / a01));\n }\n\n let w0 = w00 + a12 * dx;\n let w1 = w01 + a20 * dx;\n let w2 = w02 + a01 * dx;\n\n let wasInside = false;\n\n for (let x = minX + dx; x <= maxX; x++) {\n // check if inside triangle\n if (w0 >= 0 && w1 >= 0 && w2 >= 0) {\n wasInside = true;\n\n // compute z using barycentric coordinates\n const z = z0 * w0 + z1 * w1 + z2 * w2;\n const dz = Math.abs(z - this.heightAt(x, y));\n rms += dz * dz;\n if (dz > maxError) {\n maxError = dz;\n mx = x;\n my = y;\n }\n } else if (wasInside) {\n break;\n }\n\n w0 += a12;\n w1 += a20;\n w2 += a01;\n }\n\n w00 += b12;\n w01 += b20;\n w02 += b01;\n }\n\n if ((mx === p0x && my === p0y) || (mx === p1x && my === p1y) || (mx === p2x && my === p2y)) {\n maxError = 0;\n }\n\n // update triangle metadata\n this._candidates[2 * t] = mx;\n this._candidates[2 * t + 1] = my;\n this._rms[t] = rms;\n\n // add triangle to priority queue\n this._queuePush(t, maxError, rms);\n }\n\n // process the next triangle in the queue, splitting it with a new point\n _step() {\n // pop triangle with highest error from priority queue\n const t = this._queuePop();\n\n const e0 = t * 3 + 0;\n const e1 = t * 3 + 1;\n const e2 = t * 3 + 2;\n\n const p0 = this.triangles[e0];\n const p1 = this.triangles[e1];\n const p2 = this.triangles[e2];\n\n const ax = this.coords[2 * p0];\n const ay = this.coords[2 * p0 + 1];\n const bx = this.coords[2 * p1];\n const by = this.coords[2 * p1 + 1];\n const cx = this.coords[2 * p2];\n const cy = this.coords[2 * p2 + 1];\n const px = this._candidates[2 * t];\n const py = this._candidates[2 * t + 1];\n\n const pn = this._addPoint(px, py);\n\n if (orient(ax, ay, bx, by, px, py) === 0) {\n this._handleCollinear(pn, e0);\n } else if (orient(bx, by, cx, cy, px, py) === 0) {\n this._handleCollinear(pn, e1);\n } else if (orient(cx, cy, ax, ay, px, py) === 0) {\n this._handleCollinear(pn, e2);\n } else {\n const h0 = this._halfedges[e0];\n const h1 = this._halfedges[e1];\n const h2 = this._halfedges[e2];\n\n const t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);\n const t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);\n const t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);\n\n this._legalize(t0);\n this._legalize(t1);\n this._legalize(t2);\n }\n }\n\n // add coordinates for a new vertex\n _addPoint(x, y) {\n const i = this.coords.length >> 1;\n this.coords.push(x, y);\n return i;\n }\n\n // add or update a triangle in the mesh\n _addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) {\n const t = e / 3; // new triangle index\n\n // add triangle vertices\n this.triangles[e + 0] = a;\n this.triangles[e + 1] = b;\n this.triangles[e + 2] = c;\n\n // add triangle halfedges\n this._halfedges[e + 0] = ab;\n this._halfedges[e + 1] = bc;\n this._halfedges[e + 2] = ca;\n\n // link neighboring halfedges\n if (ab >= 0) {\n this._halfedges[ab] = e + 0;\n }\n if (bc >= 0) {\n this._halfedges[bc] = e + 1;\n }\n if (ca >= 0) {\n this._halfedges[ca] = e + 2;\n }\n\n // init triangle metadata\n this._candidates[2 * t + 0] = 0;\n this._candidates[2 * t + 1] = 0;\n this._queueIndices[t] = -1;\n this._rms[t] = 0;\n\n // add triangle to pending queue for later rasterization\n this._pending[this._pendingLen++] = t;\n\n // return first halfedge index\n return e;\n }\n\n _legalize(a) {\n // if the pair of triangles doesn't satisfy the Delaunay condition\n // (p1 is inside the circumcircle of [p0, pl, pr]), flip them,\n // then do the same check/flip recursively for the new pair of triangles\n //\n // pl pl\n // /||\\ / \\\n // al/ || \\bl al/ \\a\n // / || \\ / \\\n // / a||b \\ flip /___ar___\\\n // p0\\ || /p1 => p0\\---bl---/p1\n // \\ || / \\ /\n // ar\\ || /br b\\ /br\n // \\||/ \\ /\n // pr pr\n\n const b = this._halfedges[a];\n\n if (b < 0) {\n return;\n }\n\n const a0 = a - (a % 3);\n const b0 = b - (b % 3);\n const al = a0 + ((a + 1) % 3);\n const ar = a0 + ((a + 2) % 3);\n const bl = b0 + ((b + 2) % 3);\n const br = b0 + ((b + 1) % 3);\n const p0 = this.triangles[ar];\n const pr = this.triangles[a];\n const pl = this.triangles[al];\n const p1 = this.triangles[bl];\n const coords = this.coords;\n\n if (\n !inCircle(\n coords[2 * p0],\n coords[2 * p0 + 1],\n coords[2 * pr],\n coords[2 * pr + 1],\n coords[2 * pl],\n coords[2 * pl + 1],\n coords[2 * p1],\n coords[2 * p1 + 1]\n )\n ) {\n return;\n }\n\n const hal = this._halfedges[al];\n const har = this._halfedges[ar];\n const hbl = this._halfedges[bl];\n const hbr = this._halfedges[br];\n\n this._queueRemove(a0 / 3);\n this._queueRemove(b0 / 3);\n\n const t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);\n const t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);\n\n this._legalize(t0 + 1);\n this._legalize(t1 + 2);\n }\n\n // handle a case where new vertex is on the edge of a triangle\n _handleCollinear(pn, a) {\n const a0 = a - (a % 3);\n const al = a0 + ((a + 1) % 3);\n const ar = a0 + ((a + 2) % 3);\n const p0 = this.triangles[ar];\n const pr = this.triangles[a];\n const pl = this.triangles[al];\n const hal = this._halfedges[al];\n const har = this._halfedges[ar];\n\n const b = this._halfedges[a];\n\n if (b < 0) {\n const t0 = this._addTriangle(pn, p0, pr, -1, har, -1, a0);\n const t1 = this._addTriangle(p0, pn, pl, t0, -1, hal);\n this._legalize(t0 + 1);\n this._legalize(t1 + 2);\n return;\n }\n\n const b0 = b - (b % 3);\n const bl = b0 + ((b + 2) % 3);\n const br = b0 + ((b + 1) % 3);\n const p1 = this.triangles[bl];\n const hbl = this._halfedges[bl];\n const hbr = this._halfedges[br];\n\n this._queueRemove(b0 / 3);\n\n const t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);\n const t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);\n const t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);\n const t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);\n\n this._legalize(t0);\n this._legalize(t1);\n this._legalize(t2);\n this._legalize(t3);\n }\n\n // priority queue methods\n\n _queuePush(t, error, rms) {\n const i = this._queue.length;\n this._queueIndices[t] = i;\n this._queue.push(t);\n this._errors.push(error);\n this._rmsSum += rms;\n this._queueUp(i);\n }\n\n _queuePop() {\n const n = this._queue.length - 1;\n this._queueSwap(0, n);\n this._queueDown(0, n);\n return this._queuePopBack();\n }\n\n _queuePopBack() {\n const t = this._queue.pop();\n this._errors.pop();\n this._rmsSum -= this._rms[t];\n this._queueIndices[t] = -1;\n return t;\n }\n\n _queueRemove(t) {\n const i = this._queueIndices[t];\n if (i < 0) {\n const it = this._pending.indexOf(t);\n if (it !== -1) {\n this._pending[it] = this._pending[--this._pendingLen];\n } else {\n throw new Error('Broken triangulation (something went wrong).');\n }\n return;\n }\n const n = this._queue.length - 1;\n if (n !== i) {\n this._queueSwap(i, n);\n if (!this._queueDown(i, n)) {\n this._queueUp(i);\n }\n }\n this._queuePopBack();\n }\n\n _queueLess(i, j) {\n return this._errors[i] > this._errors[j];\n }\n\n _queueSwap(i, j) {\n const pi = this._queue[i];\n const pj = this._queue[j];\n this._queue[i] = pj;\n this._queue[j] = pi;\n this._queueIndices[pi] = j;\n this._queueIndices[pj] = i;\n const e = this._errors[i];\n this._errors[i] = this._errors[j];\n this._errors[j] = e;\n }\n\n _queueUp(j0) {\n let j = j0;\n while (true) {\n const i = (j - 1) >> 1;\n if (i === j || !this._queueLess(j, i)) {\n break;\n }\n this._queueSwap(i, j);\n j = i;\n }\n }\n\n _queueDown(i0, n) {\n let i = i0;\n while (true) {\n const j1 = 2 * i + 1;\n if (j1 >= n || j1 < 0) {\n break;\n }\n const j2 = j1 + 1;\n let j = j1;\n if (j2 < n && this._queueLess(j2, j1)) {\n j = j2;\n }\n if (!this._queueLess(j, i)) {\n break;\n }\n this._queueSwap(i, j);\n i = j;\n }\n return i > i0;\n }\n}\n\nfunction orient(ax, ay, bx, by, cx, cy) {\n return (bx - cx) * (ay - cy) - (by - cy) * (ax - cx);\n}\n\nfunction inCircle(ax, ay, bx, by, cx, cy, px, py) {\n const dx = ax - px;\n const dy = ay - py;\n const ex = bx - px;\n const ey = by - py;\n const fx = cx - px;\n const fy = cy - py;\n\n const ap = dx * dx + dy * dy;\n const bp = ex * ex + ey * ey;\n const cp = fx * fx + fy * fy;\n\n return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;\n}\n","import {getMeshBoundingBox} from '@loaders.gl/schema';\nimport Martini from '@mapbox/martini';\nimport Delatin from './delatin';\nimport {addSkirt} from './helpers/skirt';\n\nfunction getTerrain(imageData, width, height, elevationDecoder, tesselator) {\n const {rScaler, bScaler, gScaler, offset} = elevationDecoder;\n\n // From Martini demo\n // https://observablehq.com/@mourner/martin-real-time-rtin-terrain-mesh\n const terrain = new Float32Array((width + 1) * (height + 1));\n // decode terrain values\n for (let i = 0, y = 0; y < height; y++) {\n for (let x = 0; x < width; x++, i++) {\n const k = i * 4;\n const r = imageData[k + 0];\n const g = imageData[k + 1];\n const b = imageData[k + 2];\n terrain[i + y] = r * rScaler + g * gScaler + b * bScaler + offset;\n }\n }\n\n if (tesselator === 'martini') {\n // backfill bottom border\n for (let i = (width + 1) * width, x = 0; x < width; x++, i++) {\n terrain[i] = terrain[i - width - 1];\n }\n // backfill right border\n for (let i = height, y = 0; y < height + 1; y++, i += height + 1) {\n terrain[i] = terrain[i - 1];\n }\n }\n\n return terrain;\n}\n\nfunction getMeshAttributes(vertices, terrain, width, height, bounds) {\n const gridSize = width + 1;\n const numOfVerticies = vertices.length / 2;\n // vec3. x, y in pixels, z in meters\n const positions = new Float32Array(numOfVerticies * 3);\n // vec2. 1 to 1 relationship with position. represents the uv on the texture image. 0,0 to 1,1.\n const texCoords = new Float32Array(numOfVerticies * 2);\n\n const [minX, minY, maxX, maxY] = bounds || [0, 0, width, height];\n const xScale = (maxX - minX) / width;\n const yScale = (maxY - minY) / height;\n\n for (let i = 0; i < numOfVerticies; i++) {\n const x = vertices[i * 2];\n const y = vertices[i * 2 + 1];\n const pixelIdx = y * gridSize + x;\n\n positions[3 * i + 0] = x * xScale + minX;\n positions[3 * i + 1] = -y * yScale + maxY;\n positions[3 * i + 2] = terrain[pixelIdx];\n\n texCoords[2 * i + 0] = x / width;\n texCoords[2 * i + 1] = y / height;\n }\n\n return {\n POSITION: {value: positions, size: 3},\n TEXCOORD_0: {value: texCoords, size: 2}\n // NORMAL: {}, - optional, but creates the high poly look with lighting\n };\n}\n\n/**\n * Returns generated mesh object from image data\n *\n * @param {object} terrainImage terrain image data\n * @param {object} terrainOptions terrain options\n * @returns mesh object\n */\nfunction getMesh(terrainImage, terrainOptions) {\n if (terrainImage === null) {\n return null;\n }\n const {meshMaxError, bounds, elevationDecoder} = terrainOptions;\n\n const {data, width, height} = terrainImage;\n\n let terrain;\n let mesh;\n switch (terrainOptions.tesselator) {\n case 'martini':\n terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);\n mesh = getMartiniTileMesh(meshMaxError, width, terrain);\n break;\n case 'delatin':\n terrain = getTerrain(data, width, height, elevationDecoder, terrainOptions.tesselator);\n mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);\n break;\n // auto\n default:\n if (width === height && !(height & (width - 1))) {\n terrain = getTerrain(data, width, height, elevationDecoder, 'martini');\n mesh = getMartiniTileMesh(meshMaxError, width, terrain);\n } else {\n terrain = getTerrain(data, width, height, elevationDecoder, 'delatin');\n mesh = getDelatinTileMesh(meshMaxError, width, height, terrain);\n }\n break;\n }\n\n const {vertices} = mesh;\n let {triangles} = mesh;\n let attributes = getMeshAttributes(vertices, terrain, width, height, bounds);\n\n // Compute bounding box before adding skirt so that z values are not skewed\n const boundingBox = getMeshBoundingBox(attributes);\n\n if (terrainOptions.skirtHeight) {\n const {attributes: newAttributes, triangles: newTriangles} = addSkirt(\n attributes,\n triangles,\n terrainOptions.skirtHeight\n );\n attributes = newAttributes;\n triangles = newTriangles;\n }\n\n return {\n // Data return by this loader implementation\n loaderData: {\n header: {}\n },\n header: {\n vertexCount: triangles.length,\n boundingBox\n },\n mode: 4, // TRIANGLES\n indices: {value: Uint32Array.from(triangles), size: 1},\n attributes\n };\n}\n\n/**\n * Get Martini generated vertices and triangles\n *\n * @param {number} meshMaxError threshold for simplifying mesh\n * @param {number} width width of the input data\n * @param {number[] | Float32Array} terrain elevation data\n * @returns {{vertices: Uint16Array, triangles: Uint32Array}} vertices and triangles data\n */\nfunction getMartiniTileMesh(meshMaxError, width, terrain) {\n const gridSize = width + 1;\n const martini = new Martini(gridSize);\n const tile = martini.createTile(terrain);\n const {vertices, triangles} = tile.getMesh(meshMaxError);\n\n return {vertices, triangles};\n}\n\n/**\n * Get Delatin generated vertices and triangles\n *\n * @param {number} meshMaxError threshold for simplifying mesh\n * @param {number} width width of the input data array\n * @param {number} height height of the input data array\n * @param {number[] | Float32Array} terrain elevation data\n * @returns {{vertices: number[], triangles: number[]}} vertices and triangles data\n */\nfunction getDelatinTileMesh(meshMaxError, width, height, terrain) {\n const tin = new Delatin(terrain, width + 1, height + 1);\n tin.run(meshMaxError);\n const {coords, triangles} = tin;\n const vertices = coords;\n return {vertices, triangles};\n}\n\nexport default async function loadTerrain(arrayBuffer, options, context) {\n options.image = options.image || {};\n options.image.type = 'data';\n const image = await context.parse(arrayBuffer, options, options.baseUri);\n // Extend function to support additional mesh generation options (square grid or delatin)\n return getMesh(image, options.terrain);\n}\n","// Version constant cannot be imported, it needs to correspond to the build version of **this** module.\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n","import type {Loader} from '@loaders.gl/loader-utils';\nimport {VERSION} from './lib/utils/version';\n\n/**\n * Worker loader for quantized meshes\n */\nexport const TerrainLoader = {\n name: 'Terrain',\n id: 'terrain',\n module: 'terrain',\n version: VERSION,\n worker: true,\n extensions: ['png', 'pngraw'],\n mimeTypes: ['image/png'],\n options: {\n terrain: {\n tesselator: 'auto',\n bounds: null,\n meshMaxError: 10,\n elevationDecoder: {\n rScaler: 1,\n gScaler: 0,\n bScaler: 0,\n offset: 0\n },\n skirtHeight: null\n }\n }\n};\n\n/**\n * Loader for quantized meshes\n */\nexport const _typecheckTerrainWorkerLoader: Loader = TerrainLoader;\n","import type {Loader} from '@loaders.gl/loader-utils';\nimport {VERSION} from './lib/utils/version';\n\n/**\n * Worker loader for quantized meshes\n */\nexport const QuantizedMeshLoader = {\n name: 'Quantized Mesh',\n id: 'quantized-mesh',\n module: 'terrain',\n version: VERSION,\n worker: true,\n extensions: ['terrain'],\n mimeTypes: ['application/vnd.quantized-mesh'],\n options: {\n 'quantized-mesh': {\n bounds: [0, 0, 1, 1],\n skirtHeight: null\n }\n }\n};\n\nexport const _typecheckQuantizedMeshLoader: Loader = QuantizedMeshLoader;\n","import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport parseQuantizedMesh from './lib/parse-quantized-mesh';\nimport loadTerrain from './lib/parse-terrain';\n\nimport {TerrainLoader as TerrainWorkerLoader} from './terrain-loader';\nimport {QuantizedMeshLoader as QuantizedMeshWorkerLoader} from './quantized-mesh-loader';\n\n// TerrainLoader\n\nexport {TerrainWorkerLoader};\n\nexport const TerrainLoader = {\n ...TerrainWorkerLoader,\n parse: loadTerrain\n};\n\nexport const _typecheckTerrainLoader: LoaderWithParser = TerrainLoader; // eslint-disable-line\n\n// QuantizedMeshLoader\n\nexport {QuantizedMeshWorkerLoader};\n\n/**\n * Loader for quantized meshes\n */\nexport const QuantizedMeshLoader = {\n ...QuantizedMeshWorkerLoader,\n parseSync: parseQuantizedMesh,\n parse: async (arrayBuffer, options) => parseQuantizedMesh(arrayBuffer, options)\n};\n\nexport const _typecheckQuantizedMeshLoader: LoaderWithParser = QuantizedMeshLoader;\n"],"sourceRoot":""}
|