@loaders.gl/terrain 3.1.3 → 4.0.0-alpha.5

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.
Files changed (75) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/bundle.js.map +1 -0
  3. package/dist/index.js +14 -24
  4. package/dist/index.js.map +1 -0
  5. package/dist/lib/decode-quantized-mesh.js +241 -200
  6. package/dist/lib/decode-quantized-mesh.js.map +1 -0
  7. package/dist/lib/delatin/index.js +443 -397
  8. package/dist/lib/delatin/index.js.map +1 -0
  9. package/dist/lib/helpers/skirt.js +91 -119
  10. package/dist/lib/helpers/skirt.js.map +1 -0
  11. package/dist/lib/parse-quantized-mesh.js +90 -89
  12. package/dist/lib/parse-quantized-mesh.js.map +1 -0
  13. package/dist/lib/parse-terrain.js +166 -148
  14. package/dist/lib/parse-terrain.js.map +1 -0
  15. package/dist/lib/utils/version.js +2 -7
  16. package/dist/lib/utils/version.js.map +1 -0
  17. package/dist/quantized-mesh-loader.js +16 -21
  18. package/dist/quantized-mesh-loader.js.map +1 -0
  19. package/dist/quantized-mesh-worker.js +1 -1
  20. package/dist/terrain-loader.js +24 -32
  21. package/dist/terrain-loader.js.map +1 -0
  22. package/dist/terrain-worker.js +1 -1
  23. package/dist/workers/quantized-mesh-worker.js +4 -5
  24. package/dist/workers/quantized-mesh-worker.js.map +1 -0
  25. package/dist/workers/terrain-worker.js +4 -5
  26. package/dist/workers/terrain-worker.js.map +1 -0
  27. package/package.json +8 -8
  28. package/dist/es5/bundle.js +0 -7
  29. package/dist/es5/bundle.js.map +0 -1
  30. package/dist/es5/index.js +0 -77
  31. package/dist/es5/index.js.map +0 -1
  32. package/dist/es5/lib/decode-quantized-mesh.js +0 -299
  33. package/dist/es5/lib/decode-quantized-mesh.js.map +0 -1
  34. package/dist/es5/lib/delatin/index.js +0 -506
  35. package/dist/es5/lib/delatin/index.js.map +0 -1
  36. package/dist/es5/lib/helpers/skirt.js +0 -120
  37. package/dist/es5/lib/helpers/skirt.js.map +0 -1
  38. package/dist/es5/lib/parse-quantized-mesh.js +0 -119
  39. package/dist/es5/lib/parse-quantized-mesh.js.map +0 -1
  40. package/dist/es5/lib/parse-terrain.js +0 -219
  41. package/dist/es5/lib/parse-terrain.js.map +0 -1
  42. package/dist/es5/lib/utils/version.js +0 -9
  43. package/dist/es5/lib/utils/version.js.map +0 -1
  44. package/dist/es5/quantized-mesh-loader.js +0 -28
  45. package/dist/es5/quantized-mesh-loader.js.map +0 -1
  46. package/dist/es5/terrain-loader.js +0 -36
  47. package/dist/es5/terrain-loader.js.map +0 -1
  48. package/dist/es5/workers/quantized-mesh-worker.js +0 -8
  49. package/dist/es5/workers/quantized-mesh-worker.js.map +0 -1
  50. package/dist/es5/workers/terrain-worker.js +0 -8
  51. package/dist/es5/workers/terrain-worker.js.map +0 -1
  52. package/dist/esm/bundle.js +0 -5
  53. package/dist/esm/bundle.js.map +0 -1
  54. package/dist/esm/index.js +0 -16
  55. package/dist/esm/index.js.map +0 -1
  56. package/dist/esm/lib/decode-quantized-mesh.js +0 -268
  57. package/dist/esm/lib/decode-quantized-mesh.js.map +0 -1
  58. package/dist/esm/lib/delatin/index.js +0 -464
  59. package/dist/esm/lib/delatin/index.js.map +0 -1
  60. package/dist/esm/lib/helpers/skirt.js +0 -99
  61. package/dist/esm/lib/helpers/skirt.js.map +0 -1
  62. package/dist/esm/lib/parse-quantized-mesh.js +0 -96
  63. package/dist/esm/lib/parse-quantized-mesh.js.map +0 -1
  64. package/dist/esm/lib/parse-terrain.js +0 -180
  65. package/dist/esm/lib/parse-terrain.js.map +0 -1
  66. package/dist/esm/lib/utils/version.js +0 -2
  67. package/dist/esm/lib/utils/version.js.map +0 -1
  68. package/dist/esm/quantized-mesh-loader.js +0 -18
  69. package/dist/esm/quantized-mesh-loader.js.map +0 -1
  70. package/dist/esm/terrain-loader.js +0 -26
  71. package/dist/esm/terrain-loader.js.map +0 -1
  72. package/dist/esm/workers/quantized-mesh-worker.js +0 -4
  73. package/dist/esm/workers/quantized-mesh-worker.js.map +0 -1
  74. package/dist/esm/workers/terrain-worker.js +0 -4
  75. package/dist/esm/workers/terrain-worker.js.map +0 -1
@@ -1,464 +0,0 @@
1
- export default class Delatin {
2
- constructor(data, width, height = width) {
3
- this.data = data;
4
- this.width = width;
5
- this.height = height;
6
- this.coords = [];
7
- this.triangles = [];
8
- this._halfedges = [];
9
- this._candidates = [];
10
- this._queueIndices = [];
11
- this._queue = [];
12
- this._errors = [];
13
- this._rms = [];
14
- this._pending = [];
15
- this._pendingLen = 0;
16
- this._rmsSum = 0;
17
- const x1 = width - 1;
18
- const y1 = height - 1;
19
-
20
- const p0 = this._addPoint(0, 0);
21
-
22
- const p1 = this._addPoint(x1, 0);
23
-
24
- const p2 = this._addPoint(0, y1);
25
-
26
- const p3 = this._addPoint(x1, y1);
27
-
28
- const t0 = this._addTriangle(p3, p0, p2, -1, -1, -1);
29
-
30
- this._addTriangle(p0, p3, p1, t0, -1, -1);
31
-
32
- this._flush();
33
- }
34
-
35
- run(maxError = 1) {
36
- while (this.getMaxError() > maxError) {
37
- this.refine();
38
- }
39
- }
40
-
41
- refine() {
42
- this._step();
43
-
44
- this._flush();
45
- }
46
-
47
- getMaxError() {
48
- return this._errors[0];
49
- }
50
-
51
- getRMSD() {
52
- return this._rmsSum > 0 ? Math.sqrt(this._rmsSum / (this.width * this.height)) : 0;
53
- }
54
-
55
- heightAt(x, y) {
56
- return this.data[this.width * y + x];
57
- }
58
-
59
- _flush() {
60
- const coords = this.coords;
61
-
62
- for (let i = 0; i < this._pendingLen; i++) {
63
- const t = this._pending[i];
64
- const a = 2 * this.triangles[t * 3 + 0];
65
- const b = 2 * this.triangles[t * 3 + 1];
66
- const c = 2 * this.triangles[t * 3 + 2];
67
-
68
- this._findCandidate(coords[a], coords[a + 1], coords[b], coords[b + 1], coords[c], coords[c + 1], t);
69
- }
70
-
71
- this._pendingLen = 0;
72
- }
73
-
74
- _findCandidate(p0x, p0y, p1x, p1y, p2x, p2y, t) {
75
- const minX = Math.min(p0x, p1x, p2x);
76
- const minY = Math.min(p0y, p1y, p2y);
77
- const maxX = Math.max(p0x, p1x, p2x);
78
- const maxY = Math.max(p0y, p1y, p2y);
79
- let w00 = orient(p1x, p1y, p2x, p2y, minX, minY);
80
- let w01 = orient(p2x, p2y, p0x, p0y, minX, minY);
81
- let w02 = orient(p0x, p0y, p1x, p1y, minX, minY);
82
- const a01 = p1y - p0y;
83
- const b01 = p0x - p1x;
84
- const a12 = p2y - p1y;
85
- const b12 = p1x - p2x;
86
- const a20 = p0y - p2y;
87
- const b20 = p2x - p0x;
88
- const a = orient(p0x, p0y, p1x, p1y, p2x, p2y);
89
- const z0 = this.heightAt(p0x, p0y) / a;
90
- const z1 = this.heightAt(p1x, p1y) / a;
91
- const z2 = this.heightAt(p2x, p2y) / a;
92
- let maxError = 0;
93
- let mx = 0;
94
- let my = 0;
95
- let rms = 0;
96
-
97
- for (let y = minY; y <= maxY; y++) {
98
- let dx = 0;
99
-
100
- if (w00 < 0 && a12 !== 0) {
101
- dx = Math.max(dx, Math.floor(-w00 / a12));
102
- }
103
-
104
- if (w01 < 0 && a20 !== 0) {
105
- dx = Math.max(dx, Math.floor(-w01 / a20));
106
- }
107
-
108
- if (w02 < 0 && a01 !== 0) {
109
- dx = Math.max(dx, Math.floor(-w02 / a01));
110
- }
111
-
112
- let w0 = w00 + a12 * dx;
113
- let w1 = w01 + a20 * dx;
114
- let w2 = w02 + a01 * dx;
115
- let wasInside = false;
116
-
117
- for (let x = minX + dx; x <= maxX; x++) {
118
- if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
119
- wasInside = true;
120
- const z = z0 * w0 + z1 * w1 + z2 * w2;
121
- const dz = Math.abs(z - this.heightAt(x, y));
122
- rms += dz * dz;
123
-
124
- if (dz > maxError) {
125
- maxError = dz;
126
- mx = x;
127
- my = y;
128
- }
129
- } else if (wasInside) {
130
- break;
131
- }
132
-
133
- w0 += a12;
134
- w1 += a20;
135
- w2 += a01;
136
- }
137
-
138
- w00 += b12;
139
- w01 += b20;
140
- w02 += b01;
141
- }
142
-
143
- if (mx === p0x && my === p0y || mx === p1x && my === p1y || mx === p2x && my === p2y) {
144
- maxError = 0;
145
- }
146
-
147
- this._candidates[2 * t] = mx;
148
- this._candidates[2 * t + 1] = my;
149
- this._rms[t] = rms;
150
-
151
- this._queuePush(t, maxError, rms);
152
- }
153
-
154
- _step() {
155
- const t = this._queuePop();
156
-
157
- const e0 = t * 3 + 0;
158
- const e1 = t * 3 + 1;
159
- const e2 = t * 3 + 2;
160
- const p0 = this.triangles[e0];
161
- const p1 = this.triangles[e1];
162
- const p2 = this.triangles[e2];
163
- const ax = this.coords[2 * p0];
164
- const ay = this.coords[2 * p0 + 1];
165
- const bx = this.coords[2 * p1];
166
- const by = this.coords[2 * p1 + 1];
167
- const cx = this.coords[2 * p2];
168
- const cy = this.coords[2 * p2 + 1];
169
- const px = this._candidates[2 * t];
170
- const py = this._candidates[2 * t + 1];
171
-
172
- const pn = this._addPoint(px, py);
173
-
174
- if (orient(ax, ay, bx, by, px, py) === 0) {
175
- this._handleCollinear(pn, e0);
176
- } else if (orient(bx, by, cx, cy, px, py) === 0) {
177
- this._handleCollinear(pn, e1);
178
- } else if (orient(cx, cy, ax, ay, px, py) === 0) {
179
- this._handleCollinear(pn, e2);
180
- } else {
181
- const h0 = this._halfedges[e0];
182
- const h1 = this._halfedges[e1];
183
- const h2 = this._halfedges[e2];
184
-
185
- const t0 = this._addTriangle(p0, p1, pn, h0, -1, -1, e0);
186
-
187
- const t1 = this._addTriangle(p1, p2, pn, h1, -1, t0 + 1);
188
-
189
- const t2 = this._addTriangle(p2, p0, pn, h2, t0 + 2, t1 + 1);
190
-
191
- this._legalize(t0);
192
-
193
- this._legalize(t1);
194
-
195
- this._legalize(t2);
196
- }
197
- }
198
-
199
- _addPoint(x, y) {
200
- const i = this.coords.length >> 1;
201
- this.coords.push(x, y);
202
- return i;
203
- }
204
-
205
- _addTriangle(a, b, c, ab, bc, ca, e = this.triangles.length) {
206
- const t = e / 3;
207
- this.triangles[e + 0] = a;
208
- this.triangles[e + 1] = b;
209
- this.triangles[e + 2] = c;
210
- this._halfedges[e + 0] = ab;
211
- this._halfedges[e + 1] = bc;
212
- this._halfedges[e + 2] = ca;
213
-
214
- if (ab >= 0) {
215
- this._halfedges[ab] = e + 0;
216
- }
217
-
218
- if (bc >= 0) {
219
- this._halfedges[bc] = e + 1;
220
- }
221
-
222
- if (ca >= 0) {
223
- this._halfedges[ca] = e + 2;
224
- }
225
-
226
- this._candidates[2 * t + 0] = 0;
227
- this._candidates[2 * t + 1] = 0;
228
- this._queueIndices[t] = -1;
229
- this._rms[t] = 0;
230
- this._pending[this._pendingLen++] = t;
231
- return e;
232
- }
233
-
234
- _legalize(a) {
235
- const b = this._halfedges[a];
236
-
237
- if (b < 0) {
238
- return;
239
- }
240
-
241
- const a0 = a - a % 3;
242
- const b0 = b - b % 3;
243
- const al = a0 + (a + 1) % 3;
244
- const ar = a0 + (a + 2) % 3;
245
- const bl = b0 + (b + 2) % 3;
246
- const br = b0 + (b + 1) % 3;
247
- const p0 = this.triangles[ar];
248
- const pr = this.triangles[a];
249
- const pl = this.triangles[al];
250
- const p1 = this.triangles[bl];
251
- const coords = this.coords;
252
-
253
- if (!inCircle(coords[2 * p0], coords[2 * p0 + 1], coords[2 * pr], coords[2 * pr + 1], coords[2 * pl], coords[2 * pl + 1], coords[2 * p1], coords[2 * p1 + 1])) {
254
- return;
255
- }
256
-
257
- const hal = this._halfedges[al];
258
- const har = this._halfedges[ar];
259
- const hbl = this._halfedges[bl];
260
- const hbr = this._halfedges[br];
261
-
262
- this._queueRemove(a0 / 3);
263
-
264
- this._queueRemove(b0 / 3);
265
-
266
- const t0 = this._addTriangle(p0, p1, pl, -1, hbl, hal, a0);
267
-
268
- const t1 = this._addTriangle(p1, p0, pr, t0, har, hbr, b0);
269
-
270
- this._legalize(t0 + 1);
271
-
272
- this._legalize(t1 + 2);
273
- }
274
-
275
- _handleCollinear(pn, a) {
276
- const a0 = a - a % 3;
277
- const al = a0 + (a + 1) % 3;
278
- const ar = a0 + (a + 2) % 3;
279
- const p0 = this.triangles[ar];
280
- const pr = this.triangles[a];
281
- const pl = this.triangles[al];
282
- const hal = this._halfedges[al];
283
- const har = this._halfedges[ar];
284
- const b = this._halfedges[a];
285
-
286
- if (b < 0) {
287
- const t0 = this._addTriangle(pn, p0, pr, -1, har, -1, a0);
288
-
289
- const t1 = this._addTriangle(p0, pn, pl, t0, -1, hal);
290
-
291
- this._legalize(t0 + 1);
292
-
293
- this._legalize(t1 + 2);
294
-
295
- return;
296
- }
297
-
298
- const b0 = b - b % 3;
299
- const bl = b0 + (b + 2) % 3;
300
- const br = b0 + (b + 1) % 3;
301
- const p1 = this.triangles[bl];
302
- const hbl = this._halfedges[bl];
303
- const hbr = this._halfedges[br];
304
-
305
- this._queueRemove(b0 / 3);
306
-
307
- const t0 = this._addTriangle(p0, pr, pn, har, -1, -1, a0);
308
-
309
- const t1 = this._addTriangle(pr, p1, pn, hbr, -1, t0 + 1, b0);
310
-
311
- const t2 = this._addTriangle(p1, pl, pn, hbl, -1, t1 + 1);
312
-
313
- const t3 = this._addTriangle(pl, p0, pn, hal, t0 + 2, t2 + 1);
314
-
315
- this._legalize(t0);
316
-
317
- this._legalize(t1);
318
-
319
- this._legalize(t2);
320
-
321
- this._legalize(t3);
322
- }
323
-
324
- _queuePush(t, error, rms) {
325
- const i = this._queue.length;
326
- this._queueIndices[t] = i;
327
-
328
- this._queue.push(t);
329
-
330
- this._errors.push(error);
331
-
332
- this._rmsSum += rms;
333
-
334
- this._queueUp(i);
335
- }
336
-
337
- _queuePop() {
338
- const n = this._queue.length - 1;
339
-
340
- this._queueSwap(0, n);
341
-
342
- this._queueDown(0, n);
343
-
344
- return this._queuePopBack();
345
- }
346
-
347
- _queuePopBack() {
348
- const t = this._queue.pop();
349
-
350
- this._errors.pop();
351
-
352
- this._rmsSum -= this._rms[t];
353
- this._queueIndices[t] = -1;
354
- return t;
355
- }
356
-
357
- _queueRemove(t) {
358
- const i = this._queueIndices[t];
359
-
360
- if (i < 0) {
361
- const it = this._pending.indexOf(t);
362
-
363
- if (it !== -1) {
364
- this._pending[it] = this._pending[--this._pendingLen];
365
- } else {
366
- throw new Error('Broken triangulation (something went wrong).');
367
- }
368
-
369
- return;
370
- }
371
-
372
- const n = this._queue.length - 1;
373
-
374
- if (n !== i) {
375
- this._queueSwap(i, n);
376
-
377
- if (!this._queueDown(i, n)) {
378
- this._queueUp(i);
379
- }
380
- }
381
-
382
- this._queuePopBack();
383
- }
384
-
385
- _queueLess(i, j) {
386
- return this._errors[i] > this._errors[j];
387
- }
388
-
389
- _queueSwap(i, j) {
390
- const pi = this._queue[i];
391
- const pj = this._queue[j];
392
- this._queue[i] = pj;
393
- this._queue[j] = pi;
394
- this._queueIndices[pi] = j;
395
- this._queueIndices[pj] = i;
396
- const e = this._errors[i];
397
- this._errors[i] = this._errors[j];
398
- this._errors[j] = e;
399
- }
400
-
401
- _queueUp(j0) {
402
- let j = j0;
403
-
404
- while (true) {
405
- const i = j - 1 >> 1;
406
-
407
- if (i === j || !this._queueLess(j, i)) {
408
- break;
409
- }
410
-
411
- this._queueSwap(i, j);
412
-
413
- j = i;
414
- }
415
- }
416
-
417
- _queueDown(i0, n) {
418
- let i = i0;
419
-
420
- while (true) {
421
- const j1 = 2 * i + 1;
422
-
423
- if (j1 >= n || j1 < 0) {
424
- break;
425
- }
426
-
427
- const j2 = j1 + 1;
428
- let j = j1;
429
-
430
- if (j2 < n && this._queueLess(j2, j1)) {
431
- j = j2;
432
- }
433
-
434
- if (!this._queueLess(j, i)) {
435
- break;
436
- }
437
-
438
- this._queueSwap(i, j);
439
-
440
- i = j;
441
- }
442
-
443
- return i > i0;
444
- }
445
-
446
- }
447
-
448
- function orient(ax, ay, bx, by, cx, cy) {
449
- return (bx - cx) * (ay - cy) - (by - cy) * (ax - cx);
450
- }
451
-
452
- function inCircle(ax, ay, bx, by, cx, cy, px, py) {
453
- const dx = ax - px;
454
- const dy = ay - py;
455
- const ex = bx - px;
456
- const ey = by - py;
457
- const fx = cx - px;
458
- const fy = cy - py;
459
- const ap = dx * dx + dy * dy;
460
- const bp = ex * ex + ey * ey;
461
- const cp = fx * fx + fy * fy;
462
- return dx * (ey * cp - bp * fy) - dy * (ex * cp - bp * fx) + ap * (ex * fy - ey * fx) < 0;
463
- }
464
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/lib/delatin/index.ts"],"names":["Delatin","constructor","data","width","height","coords","triangles","_halfedges","_candidates","_queueIndices","_queue","_errors","_rms","_pending","_pendingLen","_rmsSum","x1","y1","p0","_addPoint","p1","p2","p3","t0","_addTriangle","_flush","run","maxError","getMaxError","refine","_step","getRMSD","Math","sqrt","heightAt","x","y","i","t","a","b","c","_findCandidate","p0x","p0y","p1x","p1y","p2x","p2y","minX","min","minY","maxX","max","maxY","w00","orient","w01","w02","a01","b01","a12","b12","a20","b20","z0","z1","z2","mx","my","rms","dx","floor","w0","w1","w2","wasInside","z","dz","abs","_queuePush","_queuePop","e0","e1","e2","ax","ay","bx","by","cx","cy","px","py","pn","_handleCollinear","h0","h1","h2","t1","t2","_legalize","length","push","ab","bc","ca","e","a0","b0","al","ar","bl","br","pr","pl","inCircle","hal","har","hbl","hbr","_queueRemove","t3","error","_queueUp","n","_queueSwap","_queueDown","_queuePopBack","pop","it","indexOf","Error","_queueLess","j","pi","pj","j0","i0","j1","j2","dy","ex","ey","fx","fy","ap","bp","cp"],"mappings":"AAmBA,eAAe,MAAMA,OAAN,CAAc;AAC3BC,EAAAA,WAAW,CAACC,IAAD,EAAOC,KAAP,EAAcC,MAAM,GAAGD,KAAvB,EAA8B;AACvC,SAAKD,IAAL,GAAYA,IAAZ;AACA,SAAKC,KAAL,GAAaA,KAAb;AACA,SAAKC,MAAL,GAAcA,MAAd;AAEA,SAAKC,MAAL,GAAc,EAAd;AAC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AAlB,EAAsBC,EAAtB,EAA0BC,EAA1B,EAA8BC,EAA9B,EAAkCC,EAAlC,EAAsCC,EAAtC,EAA0CC,EAA1C,EAA8CC,EAA9C,EAAkD;AAChD,QAAMrB,EAAE,GAAGc,EAAE,GAAGM,EAAhB;AACA,QAAMiD,EAAE,GAAGtD,EAAE,GAAGM,EAAhB;AACA,QAAMiD,EAAE,GAAGtD,EAAE,GAAGI,EAAhB;AACA,QAAMmD,EAAE,GAAGtD,EAAE,GAAGI,EAAhB;AACA,QAAMmD,EAAE,GAAGtD,EAAE,GAAGE,EAAhB;AACA,QAAMqD,EAAE,GAAGtD,EAAE,GAAGE,EAAhB;AAEA,QAAMqD,EAAE,GAAG1E,EAAE,GAAGA,EAAL,GAAUqE,EAAE,GAAGA,EAA1B;AACA,QAAMM,EAAE,GAAGL,EAAE,GAAGA,EAAL,GAAUC,EAAE,GAAGA,EAA1B;AACA,QAAMK,EAAE,GAAGJ,EAAE,GAAGA,EAAL,GAAUC,EAAE,GAAGA,EAA1B;AAEA,SAAOzE,EAAE,IAAIuE,EAAE,GAAGK,EAAL,GAAUD,EAAE,GAAGF,EAAnB,CAAF,GAA2BJ,EAAE,IAAIC,EAAE,GAAGM,EAAL,GAAUD,EAAE,GAAGH,EAAnB,CAA7B,GAAsDE,EAAE,IAAIJ,EAAE,GAAGG,EAAL,GAAUF,EAAE,GAAGC,EAAnB,CAAxD,GAAiF,CAAxF;AACD","sourcesContent":["// 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// @ts-nocheck\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"],"file":"index.js"}
@@ -1,99 +0,0 @@
1
- import { concatenateTypedArrays } from '@loaders.gl/loader-utils';
2
- export function addSkirt(attributes, triangles, skirtHeight, outsideIndices) {
3
- const outsideEdges = outsideIndices ? getOutsideEdgesFromIndices(outsideIndices, attributes.POSITION.value) : getOutsideEdgesFromTriangles(triangles);
4
- const newPosition = new attributes.POSITION.value.constructor(outsideEdges.length * 6);
5
- const newTexcoord0 = new attributes.TEXCOORD_0.value.constructor(outsideEdges.length * 4);
6
- const newTriangles = new triangles.constructor(outsideEdges.length * 6);
7
-
8
- for (let i = 0; i < outsideEdges.length; i++) {
9
- const edge = outsideEdges[i];
10
- updateAttributesForNewEdge({
11
- edge,
12
- edgeIndex: i,
13
- attributes,
14
- skirtHeight,
15
- newPosition,
16
- newTexcoord0,
17
- newTriangles
18
- });
19
- }
20
-
21
- attributes.POSITION.value = concatenateTypedArrays(attributes.POSITION.value, newPosition);
22
- attributes.TEXCOORD_0.value = concatenateTypedArrays(attributes.TEXCOORD_0.value, newTexcoord0);
23
- const resultTriangles = triangles instanceof Array ? triangles.concat(newTriangles) : concatenateTypedArrays(triangles, newTriangles);
24
- return {
25
- attributes,
26
- triangles: resultTriangles
27
- };
28
- }
29
-
30
- function getOutsideEdgesFromTriangles(triangles) {
31
- const edges = [];
32
-
33
- for (let i = 0; i < triangles.length; i += 3) {
34
- edges.push([triangles[i], triangles[i + 1]]);
35
- edges.push([triangles[i + 1], triangles[i + 2]]);
36
- edges.push([triangles[i + 2], triangles[i]]);
37
- }
38
-
39
- edges.sort((a, b) => Math.min(...a) - Math.min(...b) || Math.max(...a) - Math.max(...b));
40
- const outsideEdges = [];
41
- let index = 1;
42
-
43
- while (index < edges.length) {
44
- if (edges[index][0] === edges[index - 1][1] && edges[index][1] === edges[index - 1][0]) {
45
- index += 2;
46
- } else {
47
- outsideEdges.push(edges[index - 1]);
48
- index++;
49
- }
50
- }
51
-
52
- return outsideEdges;
53
- }
54
-
55
- function getOutsideEdgesFromIndices(indices, position) {
56
- indices.westIndices.sort((a, b) => position[3 * a + 1] - position[3 * b + 1]);
57
- indices.eastIndices.sort((a, b) => position[3 * b + 1] - position[3 * a + 1]);
58
- indices.southIndices.sort((a, b) => position[3 * b] - position[3 * a]);
59
- indices.northIndices.sort((a, b) => position[3 * a] - position[3 * b]);
60
- const edges = [];
61
-
62
- for (const index in indices) {
63
- const indexGroup = indices[index];
64
-
65
- for (let i = 0; i < indexGroup.length - 1; i++) {
66
- edges.push([indexGroup[i], indexGroup[i + 1]]);
67
- }
68
- }
69
-
70
- return edges;
71
- }
72
-
73
- function updateAttributesForNewEdge({
74
- edge,
75
- edgeIndex,
76
- attributes,
77
- skirtHeight,
78
- newPosition,
79
- newTexcoord0,
80
- newTriangles
81
- }) {
82
- const positionsLength = attributes.POSITION.value.length;
83
- const vertex1Offset = edgeIndex * 2;
84
- const vertex2Offset = edgeIndex * 2 + 1;
85
- newPosition.set(attributes.POSITION.value.subarray(edge[0] * 3, edge[0] * 3 + 3), vertex1Offset * 3);
86
- newPosition[vertex1Offset * 3 + 2] = newPosition[vertex1Offset * 3 + 2] - skirtHeight;
87
- newPosition.set(attributes.POSITION.value.subarray(edge[1] * 3, edge[1] * 3 + 3), vertex2Offset * 3);
88
- newPosition[vertex2Offset * 3 + 2] = newPosition[vertex2Offset * 3 + 2] - skirtHeight;
89
- newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[0] * 2, edge[0] * 2 + 2), vertex1Offset * 2);
90
- newTexcoord0.set(attributes.TEXCOORD_0.value.subarray(edge[1] * 2, edge[1] * 2 + 2), vertex2Offset * 2);
91
- const triangle1Offset = edgeIndex * 2 * 3;
92
- newTriangles[triangle1Offset] = edge[0];
93
- newTriangles[triangle1Offset + 1] = edge[1];
94
- newTriangles[triangle1Offset + 2] = positionsLength / 3 + vertex2Offset;
95
- newTriangles[triangle1Offset + 3] = positionsLength / 3 + vertex2Offset;
96
- newTriangles[triangle1Offset + 4] = positionsLength / 3 + vertex1Offset;
97
- newTriangles[triangle1Offset + 5] = edge[0];
98
- }
99
- //# sourceMappingURL=skirt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/lib/helpers/skirt.ts"],"names":["concatenateTypedArrays","addSkirt","attributes","triangles","skirtHeight","outsideIndices","outsideEdges","getOutsideEdgesFromIndices","POSITION","value","getOutsideEdgesFromTriangles","newPosition","constructor","length","newTexcoord0","TEXCOORD_0","newTriangles","i","edge","updateAttributesForNewEdge","edgeIndex","resultTriangles","Array","concat","edges","push","sort","a","b","Math","min","max","index","indices","position","westIndices","eastIndices","southIndices","northIndices","indexGroup","positionsLength","vertex1Offset","vertex2Offset","set","subarray","triangle1Offset"],"mappings":"AAAA,SAAQA,sBAAR,QAAqC,0BAArC;AAiBA,OAAO,SAASC,QAAT,CAAkBC,UAAlB,EAA8BC,SAA9B,EAAyCC,WAAzC,EAA8DC,cAA9D,EAA4F;AACjG,QAAMC,YAAY,GAAGD,cAAc,GAC/BE,0BAA0B,CAACF,cAAD,EAAiBH,UAAU,CAACM,QAAX,CAAoBC,KAArC,CADK,GAE/BC,4BAA4B,CAACP,SAAD,CAFhC;AAKA,QAAMQ,WAAW,GAAG,IAAIT,UAAU,CAACM,QAAX,CAAoBC,KAApB,CAA0BG,WAA9B,CAA0CN,YAAY,CAACO,MAAb,GAAsB,CAAhE,CAApB;AACA,QAAMC,YAAY,GAAG,IAAIZ,UAAU,CAACa,UAAX,CAAsBN,KAAtB,CAA4BG,WAAhC,CAA4CN,YAAY,CAACO,MAAb,GAAsB,CAAlE,CAArB;AAGA,QAAMG,YAAY,GAAG,IAAIb,SAAS,CAACS,WAAd,CAA0BN,YAAY,CAACO,MAAb,GAAsB,CAAhD,CAArB;;AAEA,OAAK,IAAII,CAAC,GAAG,CAAb,EAA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c,CAAhE,CADF,EAEEwB,aAAa,GAAG,CAFlB;AAMA,QAAMG,eAAe,GAAGzB,SAAS,GAAG,CAAZ,GAAgB,CAAxC;AACAJ,EAAAA,YAAY,CAAC6B,eAAD,CAAZ,GAAgC3B,IAAI,CAAC,CAAD,CAApC;AACAF,EAAAA,YAAY,CAAC6B,eAAe,GAAG,CAAnB,CAAZ,GAAoC3B,IAAI,CAAC,CAAD,CAAxC;AACAF,EAAAA,YAAY,CAAC6B,eAAe,GAAG,CAAnB,CAAZ,GAAoCL,eAAe,GAAG,CAAlB,GAAsBE,aAA1D;AAEA1B,EAAAA,YAAY,CAAC6B,eAAe,GAAG,CAAnB,CAAZ,GAAoCL,eAAe,GAAG,CAAlB,GAAsBE,aAA1D;AACA1B,EAAAA,YAAY,CAAC6B,eAAe,GAAG,CAAnB,CAAZ,GAAoCL,eAAe,GAAG,CAAlB,GAAsBC,aAA1D;AACAzB,EAAAA,YAAY,CAAC6B,eAAe,GAAG,CAAnB,CAAZ,GAAoC3B,IAAI,CAAC,CAAD,CAAxC;AACD","sourcesContent":["import {concatenateTypedArrays} from '@loaders.gl/loader-utils';\n\nexport type EdgeIndices = {\n westIndices: number[];\n northIndices: number[];\n eastIndices: number[];\n southIndices: number[];\n};\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 skirtHeight - height of the skirt geometry\n * @param outsideIndices - edge indices from quantized mesh data\n * @returns - geometry data with added skirt\n */\nexport function addSkirt(attributes, triangles, skirtHeight: number, outsideIndices?: EdgeIndices) {\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: number[][] = [];\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: number[][] = [];\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: EdgeIndices, 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: number[][] = [];\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"],"file":"skirt.js"}