@loaders.gl/3d-tiles 4.2.0-alpha.4 → 4.2.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 (141) hide show
  1. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +66 -41
  2. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +1 -1
  3. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -1
  4. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +26 -16
  5. package/dist/3d-tiles-archive-loader.js +25 -14
  6. package/dist/cesium-ion-loader.js +34 -30
  7. package/dist/dist.dev.js +1963 -1037
  8. package/dist/dist.min.js +32 -0
  9. package/dist/index.cjs +122 -337
  10. package/dist/index.cjs.map +7 -0
  11. package/dist/index.d.ts +13 -13
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +7 -1
  14. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +103 -87
  15. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +179 -155
  16. package/dist/lib/classes/tile-3d-batch-table.js +232 -217
  17. package/dist/lib/classes/tile-3d-feature-table.js +62 -59
  18. package/dist/lib/constants.js +19 -15
  19. package/dist/lib/encoders/encode-3d-tile-batched-model.js +40 -35
  20. package/dist/lib/encoders/encode-3d-tile-composite.js +19 -17
  21. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +32 -31
  22. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +31 -32
  23. package/dist/lib/encoders/encode-3d-tile.js +23 -19
  24. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +23 -23
  25. package/dist/lib/ion/ion.js +55 -54
  26. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +1 -1
  27. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
  28. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +57 -51
  29. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +1 -1
  30. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
  31. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +21 -18
  32. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +35 -20
  33. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -4
  34. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
  35. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +269 -234
  36. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +2 -2
  37. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  38. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +83 -55
  39. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +1 -1
  40. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
  41. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +23 -14
  42. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +1 -1
  43. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
  44. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +82 -54
  45. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +2 -2
  46. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
  47. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +79 -68
  48. package/dist/lib/parsers/helpers/parse-utils.js +19 -14
  49. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +2 -2
  50. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
  51. package/dist/lib/parsers/parse-3d-tile-batched-model.js +21 -17
  52. package/dist/lib/parsers/parse-3d-tile-composite.d.ts +2 -2
  53. package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
  54. package/dist/lib/parsers/parse-3d-tile-composite.js +18 -14
  55. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
  56. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  57. package/dist/lib/parsers/parse-3d-tile-gltf.js +22 -14
  58. package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -2
  59. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  60. package/dist/lib/parsers/parse-3d-tile-header.js +168 -159
  61. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -2
  62. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
  63. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +153 -123
  64. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +2 -2
  65. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  66. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +380 -174
  67. package/dist/lib/parsers/parse-3d-tile.d.ts +2 -2
  68. package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
  69. package/dist/lib/parsers/parse-3d-tile.js +24 -24
  70. package/dist/lib/utils/obb/s2-corners-to-obb.js +29 -16
  71. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +1 -1
  72. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -1
  73. package/dist/lib/utils/s2/converters/s2-to-boundary.js +55 -35
  74. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +31 -20
  75. package/dist/lib/utils/s2/converters/s2-to-region.d.ts +1 -1
  76. package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -1
  77. package/dist/lib/utils/s2/converters/s2-to-region.js +51 -35
  78. package/dist/lib/utils/s2/index.d.ts +7 -7
  79. package/dist/lib/utils/s2/index.d.ts.map +1 -1
  80. package/dist/lib/utils/s2/index.js +3 -1
  81. package/dist/lib/utils/s2/s2-geometry-functions.js +19 -5
  82. package/dist/lib/utils/s2/s2-token-functions.js +51 -22
  83. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +1 -1
  84. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -1
  85. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +23 -9
  86. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +218 -157
  87. package/dist/lib/utils/version.js +3 -1
  88. package/dist/tile-3d-subtree-loader.d.ts +1 -1
  89. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  90. package/dist/tile-3d-subtree-loader.js +15 -10
  91. package/dist/tile-3d-writer.js +19 -14
  92. package/dist/tiles-3d-loader.js +65 -55
  93. package/dist/types.js +3 -1
  94. package/package.json +11 -10
  95. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
  96. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
  97. package/dist/3d-tiles-archive-loader.js.map +0 -1
  98. package/dist/cesium-ion-loader.js.map +0 -1
  99. package/dist/index.js.map +0 -1
  100. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
  101. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
  102. package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
  103. package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
  104. package/dist/lib/constants.js.map +0 -1
  105. package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
  106. package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
  107. package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
  108. package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
  109. package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
  110. package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
  111. package/dist/lib/ion/ion.js.map +0 -1
  112. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
  113. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
  114. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
  115. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
  116. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
  117. package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
  118. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
  119. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
  120. package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
  121. package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
  122. package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
  123. package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
  124. package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
  125. package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
  126. package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
  127. package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
  128. package/dist/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
  129. package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
  130. package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
  131. package/dist/lib/utils/s2/converters/s2-to-region.js.map +0 -1
  132. package/dist/lib/utils/s2/index.js.map +0 -1
  133. package/dist/lib/utils/s2/s2-geometry-functions.js.map +0 -1
  134. package/dist/lib/utils/s2/s2-token-functions.js.map +0 -1
  135. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
  136. package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
  137. package/dist/lib/utils/version.js.map +0 -1
  138. package/dist/tile-3d-subtree-loader.js.map +0 -1
  139. package/dist/tile-3d-writer.js.map +0 -1
  140. package/dist/tiles-3d-loader.js.map +0 -1
  141. package/dist/types.js.map +0 -1
@@ -1,186 +1,247 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT AND ISC
3
+ // Copyright vis.gl contributors
4
+ /*
5
+ Adapted from s2-geometry under ISC License (ISC)
6
+ Copyright (c) 2012-2016, Jon Atkins <github@jonatkins.com>
7
+ Copyright (c) 2016, AJ ONeal <aj@daplie.com>
8
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
10
+ */
1
11
  import Long from 'long';
12
+ //
13
+ // Functional Style
14
+ //
2
15
  const FACE_BITS = 3;
3
16
  const MAX_LEVEL = 30;
4
- const POS_BITS = 2 * MAX_LEVEL + 1;
17
+ const POS_BITS = 2 * MAX_LEVEL + 1; // 61 (60 bits of data, 1 bit lsb marker)
5
18
  const RADIAN_TO_DEGREE = 180 / Math.PI;
19
+ /**
20
+ * Return the S2Cell
21
+ * @param hilbertQuadkey {string} A string that is the Hilbert quad key (containing /)
22
+ * @returns {@link S2Cell}
23
+ */
24
+ // eslint-disable-next-line max-statements
6
25
  export function getS2CellFromQuadKey(hilbertQuadkey) {
7
- if (hilbertQuadkey.length === 0) {
8
- throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
9
- }
10
- const parts = hilbertQuadkey.split('/');
11
- const face = parseInt(parts[0], 10);
12
- const position = parts[1];
13
- const maxLevel = position.length;
14
- let level = 0;
15
- const point = [0, 0];
16
- for (let i = maxLevel - 1; i >= 0; i--) {
17
- level = maxLevel - i;
18
- const bit = position[i];
19
- let rx = 0;
20
- let ry = 0;
21
- if (bit === '1') {
22
- ry = 1;
23
- } else if (bit === '2') {
24
- rx = 1;
25
- ry = 1;
26
- } else if (bit === '3') {
27
- rx = 1;
26
+ if (hilbertQuadkey.length === 0) {
27
+ throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
28
+ }
29
+ const parts = hilbertQuadkey.split('/');
30
+ const face = parseInt(parts[0], 10); // face is in the range [0..5]
31
+ const position = parts[1]; // position is in the range [0..4**30-1]
32
+ const maxLevel = position.length;
33
+ let level = 0;
34
+ const point = [0, 0];
35
+ for (let i = maxLevel - 1; i >= 0; i--) {
36
+ level = maxLevel - i;
37
+ const bit = position[i];
38
+ let rx = 0;
39
+ let ry = 0;
40
+ if (bit === '1') {
41
+ ry = 1;
42
+ }
43
+ else if (bit === '2') {
44
+ rx = 1;
45
+ ry = 1;
46
+ }
47
+ else if (bit === '3') {
48
+ rx = 1;
49
+ }
50
+ const val = Math.pow(2, level - 1);
51
+ rotateAndFlipQuadrant(val, point, rx, ry);
52
+ point[0] += val * rx;
53
+ point[1] += val * ry;
28
54
  }
29
- const val = Math.pow(2, level - 1);
30
- rotateAndFlipQuadrant(val, point, rx, ry);
31
- point[0] += val * rx;
32
- point[1] += val * ry;
33
- }
34
- if (face % 2 === 1) {
35
- const t = point[0];
36
- point[0] = point[1];
37
- point[1] = t;
38
- }
39
- return {
40
- face,
41
- ij: point,
42
- level
43
- };
55
+ if (face % 2 === 1) {
56
+ const t = point[0];
57
+ point[0] = point[1];
58
+ point[1] = t;
59
+ }
60
+ return { face, ij: point, level };
44
61
  }
62
+ /**
63
+ * Convets S2 cell ID to the Hilbert quad key
64
+ * @param cellId {Long} Cell id that is a 64-bit encoding of a face and a Hilbert curve parameter on that face
65
+ * @returns {string} the Hilbert quad key (containing /) as a string in the format 'face/pos', where
66
+ * - face is a 10-base representation of the face number
67
+ * - pos is a 4-base representation of the position along the Hilbert curve. For example,
68
+ * pos == '13' means the following:
69
+ * The face is divided two times. After the first time the child cell with position 1 will be selected.
70
+ * Then, this cell will be divided the second time, and the child cell with position 3 will be selected.
71
+ */
45
72
  export function getS2QuadkeyFromCellId(cellId) {
46
- if (cellId.isZero()) {
47
- return '';
48
- }
49
- let bin = cellId.toString(2);
50
- while (bin.length < FACE_BITS + POS_BITS) {
51
- bin = '0' + bin;
52
- }
53
- const lsbIndex = bin.lastIndexOf('1');
54
- const faceB = bin.substring(0, 3);
55
- const posB = bin.substring(3, lsbIndex);
56
- const levelN = posB.length / 2;
57
- const faceS = Long.fromString(faceB, true, 2).toString(10);
58
- let posS = '';
59
- if (levelN !== 0) {
60
- posS = Long.fromString(posB, true, 2).toString(4);
61
- while (posS.length < levelN) {
62
- posS = '0' + posS;
73
+ if (cellId.isZero()) {
74
+ // Invalid token
75
+ return '';
76
+ }
77
+ let bin = cellId.toString(2);
78
+ while (bin.length < FACE_BITS + POS_BITS) {
79
+ // eslint-disable-next-line prefer-template
80
+ bin = '0' + bin;
63
81
  }
64
- }
65
- return `${faceS}/${posS}`;
82
+ // MUST come AFTER binstr has been left-padded with '0's
83
+ const lsbIndex = bin.lastIndexOf('1');
84
+ // substring(start, end) // includes start, does not include end
85
+ const faceB = bin.substring(0, 3);
86
+ // posB will always be a multiple of 2 (or it's invalid)
87
+ const posB = bin.substring(3, lsbIndex);
88
+ const levelN = posB.length / 2;
89
+ const faceS = Long.fromString(faceB, true, 2).toString(10);
90
+ /*
91
+ Here is a fix for the case when posB is an empty string that causes an exception in Long.fromString
92
+ */
93
+ let posS = '';
94
+ if (levelN !== 0) {
95
+ // posB is not an empty string, because levelN !== 0
96
+ posS = Long.fromString(posB, true, 2).toString(4);
97
+ while (posS.length < levelN) {
98
+ // eslint-disable-next-line prefer-template
99
+ posS = '0' + posS;
100
+ }
101
+ }
102
+ // Note, posS will be "" for the level==0, which corresponds to the full face.
103
+ // Example: Full face 0 (No subdivision, so level==0): Returns "0/"
104
+ // TODO: Is it ok?
105
+ return `${faceS}/${posS}`;
66
106
  }
107
+ /**
108
+ * Convets S2 the Hilbert quad key to cell ID.
109
+ * @param quadkey {string} The Hilbert quad key (containing /) as a string in the format 'face/pos'
110
+ * @returns {Long} Cell id that is a 64-bit encoding of a face and a Hilbert curve parameter on that face
111
+ */
112
+ /* eslint complexity: ["error", { "max": 14 }] */
67
113
  export function getS2CellIdFromQuadkey(hilbertQuadkey) {
68
- if (hilbertQuadkey.length === 0 || hilbertQuadkey.indexOf('/') !== 1) {
69
- throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
70
- }
71
- let idS = '';
72
- const faceS = hilbertQuadkey[0];
73
- switch (faceS) {
74
- case '0':
75
- idS += '000';
76
- break;
77
- case '1':
78
- idS += '001';
79
- break;
80
- case '2':
81
- idS += '010';
82
- break;
83
- case '3':
84
- idS += '011';
85
- break;
86
- case '4':
87
- idS += '100';
88
- break;
89
- case '5':
90
- idS += '101';
91
- break;
92
- default:
93
- throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
94
- }
95
- const maxLevel = hilbertQuadkey.length;
96
- for (let i = 2; i < maxLevel; i++) {
97
- const p = hilbertQuadkey[i];
98
- switch (p) {
99
- case '0':
100
- idS += '00';
101
- break;
102
- case '1':
103
- idS += '01';
104
- break;
105
- case '2':
106
- idS += '10';
107
- break;
108
- case '3':
109
- idS += '11';
110
- break;
111
- default:
114
+ if (hilbertQuadkey.length === 0 || hilbertQuadkey.indexOf('/') !== 1) {
112
115
  throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
113
116
  }
114
- }
115
- idS += '1';
116
- const paddedId = idS.padEnd(64, '0');
117
- const id = Long.fromString(paddedId, true, 2);
118
- return id;
117
+ let idS = '';
118
+ const faceS = hilbertQuadkey[0];
119
+ switch (faceS) {
120
+ case '0':
121
+ idS += '000';
122
+ break;
123
+ case '1':
124
+ idS += '001';
125
+ break;
126
+ case '2':
127
+ idS += '010';
128
+ break;
129
+ case '3':
130
+ idS += '011';
131
+ break;
132
+ case '4':
133
+ idS += '100';
134
+ break;
135
+ case '5':
136
+ idS += '101';
137
+ break;
138
+ default:
139
+ throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
140
+ }
141
+ const maxLevel = hilbertQuadkey.length;
142
+ // Don't convert position to Long, because it can contain leading zeros, which makes you handle it later.
143
+ for (let i = 2; i < maxLevel; i++) {
144
+ // The first char is a face, the second char is '/'
145
+ const p = hilbertQuadkey[i];
146
+ switch (p) {
147
+ case '0':
148
+ idS += '00';
149
+ break;
150
+ case '1':
151
+ idS += '01';
152
+ break;
153
+ case '2':
154
+ idS += '10';
155
+ break;
156
+ case '3':
157
+ idS += '11';
158
+ break;
159
+ default:
160
+ throw new Error(`Invalid Hilbert quad key ${hilbertQuadkey}`);
161
+ }
162
+ }
163
+ // Append the sentinel bit
164
+ idS += '1';
165
+ const paddedId = idS.padEnd(64, '0');
166
+ const id = Long.fromString(paddedId, true, 2);
167
+ return id;
119
168
  }
120
169
  export function IJToST(ij, level, offsets) {
121
- const maxSize = 1 << level;
122
- return [(ij[0] + offsets[0]) / maxSize, (ij[1] + offsets[1]) / maxSize];
170
+ const maxSize = 1 << level;
171
+ return [(ij[0] + offsets[0]) / maxSize, (ij[1] + offsets[1]) / maxSize];
123
172
  }
124
173
  function singleSTtoUV(st) {
125
- if (st >= 0.5) {
126
- return 1 / 3.0 * (4 * st * st - 1);
127
- }
128
- return 1 / 3.0 * (1 - 4 * (1 - st) * (1 - st));
174
+ if (st >= 0.5) {
175
+ return (1 / 3.0) * (4 * st * st - 1);
176
+ }
177
+ return (1 / 3.0) * (1 - 4 * (1 - st) * (1 - st));
129
178
  }
130
179
  export function STToUV(st) {
131
- return [singleSTtoUV(st[0]), singleSTtoUV(st[1])];
180
+ return [singleSTtoUV(st[0]), singleSTtoUV(st[1])];
132
181
  }
133
- export function FaceUVToXYZ(face, _ref) {
134
- let [u, v] = _ref;
135
- switch (face) {
136
- case 0:
137
- return [1, u, v];
138
- case 1:
139
- return [-u, 1, v];
140
- case 2:
141
- return [-u, -v, 1];
142
- case 3:
143
- return [-1, -v, -u];
144
- case 4:
145
- return [v, -1, -u];
146
- case 5:
147
- return [v, u, -1];
148
- default:
149
- throw new Error('Invalid face');
150
- }
182
+ export function FaceUVToXYZ(face, [u, v]) {
183
+ switch (face) {
184
+ case 0:
185
+ return [1, u, v];
186
+ case 1:
187
+ return [-u, 1, v];
188
+ case 2:
189
+ return [-u, -v, 1];
190
+ case 3:
191
+ return [-1, -v, -u];
192
+ case 4:
193
+ return [v, -1, -u];
194
+ case 5:
195
+ return [v, u, -1];
196
+ default:
197
+ throw new Error('Invalid face');
198
+ }
151
199
  }
152
- export function XYZToLngLat(_ref2) {
153
- let [x, y, z] = _ref2;
154
- const lat = Math.atan2(z, Math.sqrt(x * x + y * y));
155
- const lng = Math.atan2(y, x);
156
- return [lng * RADIAN_TO_DEGREE, lat * RADIAN_TO_DEGREE];
200
+ export function XYZToLngLat([x, y, z]) {
201
+ const lat = Math.atan2(z, Math.sqrt(x * x + y * y));
202
+ const lng = Math.atan2(y, x);
203
+ return [lng * RADIAN_TO_DEGREE, lat * RADIAN_TO_DEGREE];
157
204
  }
158
205
  function rotateAndFlipQuadrant(n, point, rx, ry) {
159
- if (ry === 0) {
160
- if (rx === 1) {
161
- point[0] = n - 1 - point[0];
162
- point[1] = n - 1 - point[1];
206
+ if (ry === 0) {
207
+ if (rx === 1) {
208
+ point[0] = n - 1 - point[0];
209
+ point[1] = n - 1 - point[1];
210
+ }
211
+ const x = point[0];
212
+ point[0] = point[1];
213
+ point[1] = x;
163
214
  }
164
- const x = point[0];
165
- point[0] = point[1];
166
- point[1] = x;
167
- }
168
215
  }
216
+ /**
217
+ * Retrieve S2 geometry center
218
+ * @param s2cell {S2Cell} S2 cell
219
+ * @returns {[number, number]} Longitude and Latitude coordinates of the S2 cell's center
220
+ */
169
221
  export function getS2LngLatFromS2Cell(s2Cell) {
170
- const st = IJToST(s2Cell.ij, s2Cell.level, [0.5, 0.5]);
171
- const uv = STToUV(st);
172
- const xyz = FaceUVToXYZ(s2Cell.face, uv);
173
- return XYZToLngLat(xyz);
174
- }
175
- export function getCornerLngLats(s2Cell) {
176
- const result = [];
177
- const offsets = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]];
178
- for (let i = 0; i < 4; i++) {
179
- const st = IJToST(s2Cell.ij, s2Cell.level, offsets[i]);
222
+ const st = IJToST(s2Cell.ij, s2Cell.level, [0.5, 0.5]);
180
223
  const uv = STToUV(st);
181
224
  const xyz = FaceUVToXYZ(s2Cell.face, uv);
182
- result.push(XYZToLngLat(xyz));
183
- }
184
- return result;
225
+ return XYZToLngLat(xyz);
226
+ }
227
+ /**
228
+ * Return longitude and latitude of four corners of the cell.
229
+ * @param s2Cell {S2Cell} S2 cell
230
+ * @returns {Array<[number, number]>} Array of longitude and latitude pairs (in degrees) for four corners of the cell.
231
+ */
232
+ export function getCornerLngLats(s2Cell) {
233
+ const result = [];
234
+ const offsets = [
235
+ [0.0, 0.0],
236
+ [0.0, 1.0],
237
+ [1.0, 1.0],
238
+ [1.0, 0.0]
239
+ ];
240
+ for (let i = 0; i < 4; i++) {
241
+ const st = IJToST(s2Cell.ij, s2Cell.level, offsets[i]);
242
+ const uv = STToUV(st);
243
+ const xyz = FaceUVToXYZ(s2Cell.face, uv);
244
+ result.push(XYZToLngLat(xyz));
245
+ }
246
+ return result;
185
247
  }
186
- //# sourceMappingURL=s2-geometry.js.map
@@ -1,2 +1,4 @@
1
+ // Version constant cannot be imported, it needs to correspond to the build version of **this** module.
2
+ // __VERSION__ is injected by babel-plugin-version-inline
3
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
1
4
  export const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest';
2
- //# sourceMappingURL=version.js.map
@@ -1,5 +1,5 @@
1
1
  import type { LoaderOptions, LoaderWithParser } from '@loaders.gl/loader-utils';
2
- import type { Subtree } from './types';
2
+ import type { Subtree } from "./types.js";
3
3
  /**
4
4
  * Loader for 3D Tiles Subtree
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"tile-3d-subtree-loader.d.ts","sourceRoot":"","sources":["../src/tile-3d-subtree-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAIrC;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAU/E,CAAC"}
1
+ {"version":3,"file":"tile-3d-subtree-loader.d.ts","sourceRoot":"","sources":["../src/tile-3d-subtree-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAC,OAAO,EAAC,mBAAgB;AAIrC;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAU/E,CAAC"}
@@ -1,14 +1,19 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  import parse3DTilesSubtree from "./lib/parsers/helpers/parse-3d-tile-subtree.js";
2
5
  import { VERSION } from "./lib/utils/version.js";
6
+ /**
7
+ * Loader for 3D Tiles Subtree
8
+ */
3
9
  export const Tile3DSubtreeLoader = {
4
- id: '3d-tiles-subtree',
5
- name: '3D Tiles Subtree',
6
- module: '3d-tiles',
7
- version: VERSION,
8
- extensions: ['subtree'],
9
- mimeTypes: ['application/octet-stream'],
10
- tests: ['subtree'],
11
- parse: parse3DTilesSubtree,
12
- options: {}
10
+ id: '3d-tiles-subtree',
11
+ name: '3D Tiles Subtree',
12
+ module: '3d-tiles',
13
+ version: VERSION,
14
+ extensions: ['subtree'],
15
+ mimeTypes: ['application/octet-stream'],
16
+ tests: ['subtree'],
17
+ parse: parse3DTilesSubtree,
18
+ options: {}
13
19
  };
14
- //# sourceMappingURL=tile-3d-subtree-loader.js.map
@@ -1,20 +1,25 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  import { VERSION } from "./lib/utils/version.js";
2
5
  import encode3DTile from "./lib/encoders/encode-3d-tile.js";
6
+ /**
7
+ * Exporter for 3D Tiles
8
+ */
3
9
  export const Tile3DWriter = {
4
- name: '3D Tile',
5
- id: '3d-tiles',
6
- module: '3d-tiles',
7
- version: VERSION,
8
- extensions: ['cmpt', 'pnts', 'b3dm', 'i3dm'],
9
- mimeTypes: ['application/octet-stream'],
10
- binary: true,
11
- options: {
12
- ['3d-tiles']: {}
13
- },
14
- encode: async (tile, options) => encodeSync(tile, options),
15
- encodeSync
10
+ name: '3D Tile',
11
+ id: '3d-tiles',
12
+ module: '3d-tiles',
13
+ version: VERSION,
14
+ extensions: ['cmpt', 'pnts', 'b3dm', 'i3dm'],
15
+ mimeTypes: ['application/octet-stream'],
16
+ binary: true,
17
+ options: {
18
+ ['3d-tiles']: {}
19
+ },
20
+ encode: async (tile, options) => encodeSync(tile, options),
21
+ encodeSync
16
22
  };
17
23
  function encodeSync(tile, options) {
18
- return encode3DTile(tile, options);
24
+ return encode3DTile(tile, options);
19
25
  }
20
- //# sourceMappingURL=tile-3d-writer.js.map
@@ -1,70 +1,80 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  import { path } from '@loaders.gl/loader-utils';
2
5
  import { TILESET_TYPE, LOD_METRIC_TYPE } from '@loaders.gl/tiles';
3
6
  import { VERSION } from "./lib/utils/version.js";
4
7
  import { parse3DTile } from "./lib/parsers/parse-3d-tile.js";
5
8
  import { normalizeTileHeaders } from "./lib/parsers/parse-3d-tile-header.js";
9
+ /**
10
+ * Loader for 3D Tiles
11
+ */
6
12
  export const Tiles3DLoader = {
7
- id: '3d-tiles',
8
- name: '3D Tiles',
9
- module: '3d-tiles',
10
- version: VERSION,
11
- extensions: ['cmpt', 'pnts', 'b3dm', 'i3dm'],
12
- mimeTypes: ['application/octet-stream'],
13
- tests: ['cmpt', 'pnts', 'b3dm', 'i3dm'],
14
- parse,
15
- options: {
16
- '3d-tiles': {
17
- loadGLTF: true,
18
- decodeQuantizedPositions: false,
19
- isTileset: 'auto',
20
- assetGltfUpAxis: null
13
+ id: '3d-tiles',
14
+ name: '3D Tiles',
15
+ module: '3d-tiles',
16
+ version: VERSION,
17
+ extensions: ['cmpt', 'pnts', 'b3dm', 'i3dm'],
18
+ mimeTypes: ['application/octet-stream'],
19
+ tests: ['cmpt', 'pnts', 'b3dm', 'i3dm'],
20
+ parse,
21
+ options: {
22
+ '3d-tiles': {
23
+ loadGLTF: true,
24
+ decodeQuantizedPositions: false,
25
+ isTileset: 'auto',
26
+ assetGltfUpAxis: null
27
+ }
21
28
  }
22
- }
23
29
  };
24
- async function parse(data) {
25
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
26
- let context = arguments.length > 2 ? arguments[2] : undefined;
27
- const loaderOptions = options['3d-tiles'] || {};
28
- let isTileset;
29
- if (loaderOptions.isTileset === 'auto') {
30
- isTileset = (context === null || context === void 0 ? void 0 : context.url) && context.url.indexOf('.json') !== -1;
31
- } else {
32
- isTileset = loaderOptions.isTileset;
33
- }
34
- return isTileset ? parseTileset(data, options, context) : parseTile(data, options, context);
30
+ /** Parses a tileset or tile */
31
+ async function parse(data, options = {}, context) {
32
+ // auto detect file type
33
+ const loaderOptions = options['3d-tiles'] || {};
34
+ let isTileset;
35
+ if (loaderOptions.isTileset === 'auto') {
36
+ isTileset = context?.url && context.url.indexOf('.json') !== -1;
37
+ }
38
+ else {
39
+ isTileset = loaderOptions.isTileset;
40
+ }
41
+ return isTileset ? parseTileset(data, options, context) : parseTile(data, options, context);
35
42
  }
43
+ /** Parse a tileset */
36
44
  async function parseTileset(data, options, context) {
37
- var _tilesetJson$root;
38
- const tilesetJson = JSON.parse(new TextDecoder().decode(data));
39
- const tilesetUrl = (context === null || context === void 0 ? void 0 : context.url) || '';
40
- const basePath = getBaseUri(tilesetUrl);
41
- const normalizedRoot = await normalizeTileHeaders(tilesetJson, basePath, options || {});
42
- const tilesetJsonPostprocessed = {
43
- ...tilesetJson,
44
- shape: 'tileset3d',
45
- loader: Tiles3DLoader,
46
- url: tilesetUrl,
47
- queryString: (context === null || context === void 0 ? void 0 : context.queryString) || '',
48
- basePath,
49
- root: normalizedRoot || tilesetJson.root,
50
- type: TILESET_TYPE.TILES3D,
51
- lodMetricType: LOD_METRIC_TYPE.GEOMETRIC_ERROR,
52
- lodMetricValue: ((_tilesetJson$root = tilesetJson.root) === null || _tilesetJson$root === void 0 ? void 0 : _tilesetJson$root.geometricError) || 0
53
- };
54
- return tilesetJsonPostprocessed;
45
+ const tilesetJson = JSON.parse(new TextDecoder().decode(data));
46
+ const tilesetUrl = context?.url || '';
47
+ const basePath = getBaseUri(tilesetUrl);
48
+ const normalizedRoot = await normalizeTileHeaders(tilesetJson, basePath, options || {});
49
+ const tilesetJsonPostprocessed = {
50
+ ...tilesetJson,
51
+ shape: 'tileset3d',
52
+ loader: Tiles3DLoader,
53
+ url: tilesetUrl,
54
+ queryString: context?.queryString || '',
55
+ basePath,
56
+ root: normalizedRoot || tilesetJson.root,
57
+ type: TILESET_TYPE.TILES3D,
58
+ lodMetricType: LOD_METRIC_TYPE.GEOMETRIC_ERROR,
59
+ lodMetricValue: tilesetJson.root?.geometricError || 0
60
+ };
61
+ return tilesetJsonPostprocessed;
55
62
  }
63
+ /** Parse a tile */
56
64
  async function parseTile(arrayBuffer, options, context) {
57
- const tile = {
58
- content: {
59
- shape: 'tile3d',
60
- featureIds: null
61
- }
62
- };
63
- const byteOffset = 0;
64
- await parse3DTile(arrayBuffer, byteOffset, options, context, tile.content);
65
- return tile.content;
65
+ const tile = {
66
+ content: {
67
+ shape: 'tile3d',
68
+ featureIds: null
69
+ }
70
+ };
71
+ const byteOffset = 0;
72
+ // @ts-expect-error
73
+ await parse3DTile(arrayBuffer, byteOffset, options, context, tile.content);
74
+ // @ts-expect-error
75
+ return tile.content;
66
76
  }
77
+ /** Get base name */
67
78
  function getBaseUri(tilesetUrl) {
68
- return path.dirname(tilesetUrl);
79
+ return path.dirname(tilesetUrl);
69
80
  }
70
- //# sourceMappingURL=tiles-3d-loader.js.map
package/dist/types.js CHANGED
@@ -1,2 +1,4 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
1
4
  export {};
2
- //# sourceMappingURL=types.js.map