@loaders.gl/3d-tiles 4.0.0-alpha.23 → 4.0.0-alpha.25

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/cesium-ion-loader.d.ts +2 -2
  2. package/dist/cesium-ion-loader.d.ts.map +1 -1
  3. package/dist/dist.min.js +421 -270
  4. package/dist/es5/3d-tiles-archive-loader.js +1 -1
  5. package/dist/es5/cesium-ion-loader.js.map +1 -1
  6. package/dist/es5/lib/utils/version.js +1 -1
  7. package/dist/es5/tile-3d-subtree-loader.js.map +1 -1
  8. package/dist/es5/tile-3d-writer.js.map +1 -1
  9. package/dist/es5/types.js.map +1 -1
  10. package/dist/esm/3d-tiles-archive-loader.js +1 -1
  11. package/dist/esm/cesium-ion-loader.js.map +1 -1
  12. package/dist/esm/lib/utils/version.js +1 -1
  13. package/dist/esm/tile-3d-subtree-loader.js.map +1 -1
  14. package/dist/esm/tile-3d-writer.js.map +1 -1
  15. package/dist/esm/types.js.map +1 -1
  16. package/dist/tile-3d-subtree-loader.d.ts +3 -3
  17. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  18. package/dist/tile-3d-writer.d.ts +2 -2
  19. package/dist/tile-3d-writer.d.ts.map +1 -1
  20. package/dist/types.d.ts +2 -5
  21. package/dist/types.d.ts.map +1 -1
  22. package/package.json +8 -8
  23. package/src/cesium-ion-loader.ts +2 -2
  24. package/src/tile-3d-subtree-loader.ts +3 -3
  25. package/src/tile-3d-writer.ts +2 -2
  26. package/src/types.ts +3 -5
  27. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +0 -72
  28. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +0 -33
  29. package/dist/3d-tiles-archive-loader.js +0 -31
  30. package/dist/bundle.js +0 -5
  31. package/dist/cesium-ion-loader.js +0 -40
  32. package/dist/index.js +0 -30
  33. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +0 -113
  34. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +0 -197
  35. package/dist/lib/classes/tile-3d-batch-table.js +0 -245
  36. package/dist/lib/classes/tile-3d-feature-table.js +0 -72
  37. package/dist/lib/constants.js +0 -26
  38. package/dist/lib/encoders/encode-3d-tile-batched-model.js +0 -46
  39. package/dist/lib/encoders/encode-3d-tile-composite.js +0 -24
  40. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +0 -38
  41. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +0 -39
  42. package/dist/lib/encoders/encode-3d-tile.js +0 -33
  43. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +0 -30
  44. package/dist/lib/filesystems/tiles-3d-archive-file-system.js +0 -75
  45. package/dist/lib/ion/ion.js +0 -68
  46. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
  47. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -30
  48. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -42
  49. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -303
  50. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -96
  51. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +0 -28
  52. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -87
  53. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +0 -93
  54. package/dist/lib/parsers/helpers/parse-utils.js +0 -32
  55. package/dist/lib/parsers/parse-3d-tile-batched-model.js +0 -33
  56. package/dist/lib/parsers/parse-3d-tile-composite.js +0 -24
  57. package/dist/lib/parsers/parse-3d-tile-gltf.js +0 -29
  58. package/dist/lib/parsers/parse-3d-tile-header.js +0 -194
  59. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +0 -172
  60. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +0 -441
  61. package/dist/lib/parsers/parse-3d-tile.js +0 -33
  62. package/dist/lib/utils/obb/s2-corners-to-obb.js +0 -37
  63. package/dist/lib/utils/s2/converters/s2-to-boundary.js +0 -61
  64. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +0 -36
  65. package/dist/lib/utils/s2/converters/s2-to-region.js +0 -59
  66. package/dist/lib/utils/s2/index.js +0 -23
  67. package/dist/lib/utils/s2/s2-geometry-functions.js +0 -29
  68. package/dist/lib/utils/s2/s2-token-functions.js +0 -68
  69. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -32
  70. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +0 -260
  71. package/dist/lib/utils/version.js +0 -7
  72. package/dist/tile-3d-subtree-loader.js +0 -23
  73. package/dist/tile-3d-writer.js +0 -27
  74. package/dist/tiles-3d-loader.js +0 -80
  75. package/dist/types.js +0 -2
@@ -1,441 +0,0 @@
1
- "use strict";
2
- // This file is derived from the Cesium code base under Apache 2 license
3
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
4
- var __importDefault = (this && this.__importDefault) || function (mod) {
5
- return (mod && mod.__esModule) ? mod : { "default": mod };
6
- };
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.loadDraco = exports.parsePointCloud3DTile = void 0;
9
- const draco_1 = require("@loaders.gl/draco");
10
- const loader_utils_1 = require("@loaders.gl/loader-utils");
11
- const math_1 = require("@loaders.gl/math");
12
- const core_1 = require("@math.gl/core");
13
- const tile_3d_feature_table_1 = __importDefault(require("../classes/tile-3d-feature-table"));
14
- const tile_3d_batch_table_1 = __importDefault(require("../classes/tile-3d-batch-table"));
15
- const parse_3d_tile_header_1 = require("./helpers/parse-3d-tile-header");
16
- const parse_3d_tile_tables_1 = require("./helpers/parse-3d-tile-tables");
17
- const normalize_3d_tile_colors_1 = require("./helpers/normalize-3d-tile-colors");
18
- const normalize_3d_tile_normals_1 = require("./helpers/normalize-3d-tile-normals");
19
- const normalize_3d_tile_positions_1 = require("./helpers/normalize-3d-tile-positions");
20
- async function parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context) {
21
- byteOffset = (0, parse_3d_tile_header_1.parse3DTileHeaderSync)(tile, arrayBuffer, byteOffset);
22
- byteOffset = (0, parse_3d_tile_tables_1.parse3DTileTablesHeaderSync)(tile, arrayBuffer, byteOffset);
23
- byteOffset = (0, parse_3d_tile_tables_1.parse3DTileTablesSync)(tile, arrayBuffer, byteOffset, options);
24
- initializeTile(tile);
25
- const { featureTable, batchTable } = parsePointCloudTables(tile);
26
- await parseDraco(tile, featureTable, batchTable, options, context);
27
- parsePositions(tile, featureTable, options);
28
- // @ts-expect-error TODO - do we need to assert on the batch table?
29
- parseColors(tile, featureTable, batchTable);
30
- parseNormals(tile, featureTable);
31
- return byteOffset;
32
- }
33
- exports.parsePointCloud3DTile = parsePointCloud3DTile;
34
- function initializeTile(tile) {
35
- // Initialize point cloud tile defaults
36
- tile.attributes = {
37
- positions: null,
38
- colors: null,
39
- normals: null,
40
- batchIds: null
41
- };
42
- tile.isQuantized = false;
43
- tile.isTranslucent = false;
44
- tile.isRGB565 = false;
45
- tile.isOctEncoded16P = false;
46
- }
47
- function parsePointCloudTables(tile) {
48
- const featureTable = new tile_3d_feature_table_1.default(tile.featureTableJson, tile.featureTableBinary);
49
- const pointsLength = featureTable.getGlobalProperty('POINTS_LENGTH');
50
- if (!Number.isFinite(pointsLength)) {
51
- throw new Error('POINTS_LENGTH must be defined');
52
- }
53
- featureTable.featuresLength = pointsLength;
54
- tile.featuresLength = pointsLength;
55
- tile.pointsLength = pointsLength;
56
- tile.pointCount = pointsLength;
57
- tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', math_1.GL.FLOAT, 3);
58
- const batchTable = parseBatchIds(tile, featureTable);
59
- return { featureTable, batchTable };
60
- }
61
- function parsePositions(tile, featureTable, options) {
62
- tile.attributes = tile.attributes || {
63
- positions: null,
64
- colors: null,
65
- normals: null,
66
- batchIds: null
67
- };
68
- if (!tile.attributes.positions) {
69
- if (featureTable.hasProperty('POSITION')) {
70
- tile.attributes.positions = featureTable.getPropertyArray('POSITION', math_1.GL.FLOAT, 3);
71
- }
72
- else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
73
- const positions = featureTable.getPropertyArray('POSITION_QUANTIZED', math_1.GL.UNSIGNED_SHORT, 3);
74
- tile.isQuantized = true;
75
- tile.quantizedRange = (1 << 16) - 1;
76
- tile.quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', math_1.GL.FLOAT, 3);
77
- if (!tile.quantizedVolumeScale) {
78
- throw new Error('QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
79
- }
80
- tile.quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', math_1.GL.FLOAT, 3);
81
- if (!tile.quantizedVolumeOffset) {
82
- throw new Error('QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
83
- }
84
- tile.attributes.positions = (0, normalize_3d_tile_positions_1.normalize3DTilePositionAttribute)(tile, positions, options);
85
- }
86
- }
87
- if (!tile.attributes.positions) {
88
- throw new Error('Either POSITION or POSITION_QUANTIZED must be defined.');
89
- }
90
- }
91
- function parseColors(tile, featureTable, batchTable) {
92
- tile.attributes = tile.attributes || {
93
- positions: null,
94
- colors: null,
95
- normals: null,
96
- batchIds: null
97
- };
98
- if (!tile.attributes.colors) {
99
- let colors = null;
100
- if (featureTable.hasProperty('RGBA')) {
101
- colors = featureTable.getPropertyArray('RGBA', math_1.GL.UNSIGNED_BYTE, 4);
102
- tile.isTranslucent = true;
103
- }
104
- else if (featureTable.hasProperty('RGB')) {
105
- colors = featureTable.getPropertyArray('RGB', math_1.GL.UNSIGNED_BYTE, 3);
106
- }
107
- else if (featureTable.hasProperty('RGB565')) {
108
- colors = featureTable.getPropertyArray('RGB565', math_1.GL.UNSIGNED_SHORT, 1);
109
- tile.isRGB565 = true;
110
- }
111
- tile.attributes.colors = (0, normalize_3d_tile_colors_1.normalize3DTileColorAttribute)(tile, colors, batchTable);
112
- }
113
- if (featureTable.hasProperty('CONSTANT_RGBA')) {
114
- tile.constantRGBA = featureTable.getGlobalProperty('CONSTANT_RGBA', math_1.GL.UNSIGNED_BYTE, 4);
115
- }
116
- }
117
- function parseNormals(tile, featureTable) {
118
- tile.attributes = tile.attributes || {
119
- positions: null,
120
- colors: null,
121
- normals: null,
122
- batchIds: null
123
- };
124
- if (!tile.attributes.normals) {
125
- let normals = null;
126
- if (featureTable.hasProperty('NORMAL')) {
127
- normals = featureTable.getPropertyArray('NORMAL', math_1.GL.FLOAT, 3);
128
- }
129
- else if (featureTable.hasProperty('NORMAL_OCT16P')) {
130
- normals = featureTable.getPropertyArray('NORMAL_OCT16P', math_1.GL.UNSIGNED_BYTE, 2);
131
- tile.isOctEncoded16P = true;
132
- }
133
- tile.attributes.normals = (0, normalize_3d_tile_normals_1.normalize3DTileNormalAttribute)(tile, normals);
134
- }
135
- }
136
- function parseBatchIds(tile, featureTable) {
137
- let batchTable = null;
138
- if (!tile.batchIds && featureTable.hasProperty('BATCH_ID')) {
139
- tile.batchIds = featureTable.getPropertyArray('BATCH_ID', math_1.GL.UNSIGNED_SHORT, 1);
140
- if (tile.batchIds) {
141
- const batchFeatureLength = featureTable.getGlobalProperty('BATCH_LENGTH');
142
- if (!batchFeatureLength) {
143
- throw new Error('Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.');
144
- }
145
- const { batchTableJson, batchTableBinary } = tile;
146
- batchTable = new tile_3d_batch_table_1.default(batchTableJson, batchTableBinary, batchFeatureLength);
147
- }
148
- }
149
- return batchTable;
150
- }
151
- // eslint-disable-next-line complexity
152
- async function parseDraco(tile, featureTable, batchTable, options, context) {
153
- let dracoBuffer;
154
- let dracoFeatureTableProperties;
155
- let dracoBatchTableProperties;
156
- const batchTableDraco = tile.batchTableJson &&
157
- tile.batchTableJson.extensions &&
158
- tile.batchTableJson.extensions['3DTILES_draco_point_compression'];
159
- if (batchTableDraco) {
160
- dracoBatchTableProperties = batchTableDraco.properties;
161
- }
162
- const featureTableDraco = featureTable.getExtension('3DTILES_draco_point_compression');
163
- if (featureTableDraco) {
164
- dracoFeatureTableProperties = featureTableDraco.properties;
165
- const dracoByteOffset = featureTableDraco.byteOffset;
166
- const dracoByteLength = featureTableDraco.byteLength;
167
- if (!dracoFeatureTableProperties || !Number.isFinite(dracoByteOffset) || !dracoByteLength) {
168
- throw new Error('Draco properties, byteOffset, and byteLength must be defined');
169
- }
170
- dracoBuffer = (tile.featureTableBinary || []).slice(dracoByteOffset, dracoByteOffset + dracoByteLength);
171
- tile.hasPositions = Number.isFinite(dracoFeatureTableProperties.POSITION);
172
- tile.hasColors =
173
- Number.isFinite(dracoFeatureTableProperties.RGB) ||
174
- Number.isFinite(dracoFeatureTableProperties.RGBA);
175
- tile.hasNormals = Number.isFinite(dracoFeatureTableProperties.NORMAL);
176
- tile.hasBatchIds = Number.isFinite(dracoFeatureTableProperties.BATCH_ID);
177
- tile.isTranslucent = Number.isFinite(dracoFeatureTableProperties.RGBA);
178
- }
179
- if (!dracoBuffer) {
180
- return true;
181
- }
182
- const dracoData = {
183
- buffer: dracoBuffer,
184
- properties: { ...dracoFeatureTableProperties, ...dracoBatchTableProperties },
185
- featureTableProperties: dracoFeatureTableProperties,
186
- batchTableProperties: dracoBatchTableProperties,
187
- dequantizeInShader: false
188
- };
189
- return await loadDraco(tile, dracoData, options, context);
190
- }
191
- // eslint-disable-next-line complexity, max-statements
192
- async function loadDraco(tile, dracoData, options, context) {
193
- if (!context) {
194
- return;
195
- }
196
- const dracoOptions = {
197
- ...options,
198
- draco: {
199
- ...options?.draco,
200
- extraAttributes: dracoData.batchTableProperties || {}
201
- }
202
- };
203
- // The entire tileset might be included, too expensive to serialize
204
- delete dracoOptions['3d-tiles'];
205
- const data = await (0, loader_utils_1.parseFromContext)(dracoData.buffer, draco_1.DracoLoader, dracoOptions, context);
206
- const decodedPositions = data.attributes.POSITION && data.attributes.POSITION.value;
207
- const decodedColors = data.attributes.COLOR_0 && data.attributes.COLOR_0.value;
208
- const decodedNormals = data.attributes.NORMAL && data.attributes.NORMAL.value;
209
- const decodedBatchIds = data.attributes.BATCH_ID && data.attributes.BATCH_ID.value;
210
- // @ts-expect-error
211
- const isQuantizedDraco = decodedPositions && data.attributes.POSITION.value.quantization;
212
- // @ts-expect-error
213
- const isOctEncodedDraco = decodedNormals && data.attributes.NORMAL.value.quantization;
214
- if (isQuantizedDraco) {
215
- // Draco quantization range == quantized volume scale - size in meters of the quantized volume
216
- // Internal quantized range is the range of values of the quantized data, e.g. 255 for 8-bit, 1023 for 10-bit, etc
217
- // @ts-expect-error This doesn't look right
218
- const quantization = data.POSITION.data.quantization;
219
- const range = quantization.range;
220
- tile.quantizedVolumeScale = new core_1.Vector3(range, range, range);
221
- tile.quantizedVolumeOffset = new core_1.Vector3(quantization.minValues);
222
- tile.quantizedRange = (1 << quantization.quantizationBits) - 1.0;
223
- tile.isQuantizedDraco = true;
224
- }
225
- if (isOctEncodedDraco) {
226
- // @ts-expect-error This doesn't look right
227
- tile.octEncodedRange = (1 << data.NORMAL.data.quantization.quantizationBits) - 1.0;
228
- tile.isOctEncodedDraco = true;
229
- }
230
- // Extra batch table attributes
231
- const batchTableAttributes = {};
232
- if (dracoData.batchTableProperties) {
233
- for (const attributeName of Object.keys(dracoData.batchTableProperties)) {
234
- if (data.attributes[attributeName] && data.attributes[attributeName].value) {
235
- batchTableAttributes[attributeName.toLowerCase()] = data.attributes[attributeName].value;
236
- }
237
- }
238
- }
239
- tile.attributes = {
240
- // @ts-expect-error
241
- positions: decodedPositions,
242
- // @ts-expect-error
243
- colors: (0, normalize_3d_tile_colors_1.normalize3DTileColorAttribute)(tile, decodedColors, undefined),
244
- // @ts-expect-error
245
- normals: decodedNormals,
246
- // @ts-expect-error
247
- batchIds: decodedBatchIds,
248
- ...batchTableAttributes
249
- };
250
- }
251
- exports.loadDraco = loadDraco;
252
- // TODO - this is the remaining code from Cesium's parser
253
- /*
254
- const batchTable = new Tile3DBatchTable(tile);
255
-
256
- // parseDracoBuffer(tile, featureTable, batchTable);
257
-
258
- if (!tile.attributes.positions) {
259
- throw new Error('Either POSITION or POSITION_QUANTIZED must be defined.');
260
- }
261
- }
262
- /*
263
-
264
- if (!tile.attributes.positions) {
265
- if (featureTable.hasProperty('POSITION')) {
266
- tile.attributes.positions = featureTable.getPropertyArray('POSITION', GL.FLOAT, 3);
267
- } else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
268
- tile.attributes.positions = featureTable.getPropertyArray('POSITION_QUANTIZED', GL.UNSIGNED_SHORT, 3);
269
-
270
-
271
- if (!tile.colors) {
272
- if (featureTable.hasProperty('RGBA')) {
273
- tile.colors = featureTable.getPropertyArray('RGBA', GL.UNSIGNED_BYTE, 4);
274
- tile.isTranslucent = true;
275
- } else if (featureTable.hasProperty('RGB')) {
276
- tile.colors = featureTable.getPropertyArray('RGB', GL.UNSIGNED_BYTE, 3);
277
- } else if (featureTable.hasPropertry('RGB565')) {
278
- tile.colors = featureTable.getPropertyArray('RGB565', GL.UNSIGNED_SHORT, 1);
279
- tile.isRGB565 = true;
280
- }
281
- }
282
-
283
- if (!tile.attributes.normals) {
284
- if (featureTable.getPropertry('NORMAL')) {
285
- tile.attributes.normals = featureTable.getPropertyArray('NORMAL', GL.FLOAT, 3);
286
- } else if (featureTable.getProperty('NORMAL_OCT16P')) {
287
- tile.attributes.normals = featureTable.getPropertyArray('NORMAL_OCT16P', GL.UNSIGNED_BYTE, 2);
288
- tile.isOctEncoded16P = true;
289
- }
290
- }
291
-
292
- if (!tile.batchIds) {
293
- if (featureTable.hasProperty('BATCH_ID')) {
294
- tile.batchIds = featureTable.getPropertyArray('BATCH_ID', GL.UNSIGNED_SHORT, 1);
295
- }
296
- }
297
-
298
- if (!tile.attributes.positions) {
299
- throw new Error('Either POSITION or POSITION_QUANTIZED must be defined.');
300
- }
301
-
302
- if (featureTable.getPropertry('CONSTANT_RGBA')) {
303
- tile.constantRGBA = featureTable.getGlobalProperty('CONSTANT_RGBA', GL.UNSIGNED_BYTE, 4);
304
- }
305
-
306
- if (tile.batchIds) {
307
- const batchLength = featureTable.getGlobalProperty('BATCH_LENGTH');
308
- if (!defined(batchLength)) {
309
- throw new Error('Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.');
310
- }
311
-
312
- if (defined(batchTableBinary)) {
313
- // Copy the batchTableBinary section and let the underlying ArrayBuffer be freed
314
- batchTableBinary = new Uint8Array(batchTableBinary);
315
- }
316
-
317
- if (defined(pointCloud._batchTableLoaded)) {
318
- pointCloud._batchTableLoaded(batchLength, batchTableJson, batchTableBinary);
319
- }
320
- }
321
-
322
- // If points are not batched and there are per-point properties, use these properties for styling purposes
323
- var styleableProperties;
324
- if (!hasBatchIds && defined(batchTableBinary)) {
325
- tile.styleableProperties = Cesium3DTileBatchTable.getBinaryProperties(
326
- pointsLength,
327
- batchTableJson,
328
- batchTableBinary
329
- );
330
- }
331
-
332
- tile.draco = draco;
333
- }
334
-
335
- // Separate parsing and decoding of Draco
336
- export function parseDracoBuffer(tile, featureTable, batchTable) {
337
- let dracoBuffer;
338
- let dracoFeatureTableProperties;
339
- let dracoBatchTableProperties;
340
-
341
- const batchTableDraco = batchTable.getExtension('3DTILES_draco_point_compression');
342
- if (batchTableDraco) {
343
- dracoBatchTableProperties = batchTableDraco.properties;
344
- }
345
-
346
- const featureTableDraco = featureTable.getExtension('3DTILES_draco_point_compression');
347
- if (featureTableDraco) {
348
- dracoFeatureTableProperties = featureTableDraco.properties;
349
- const dracoByteOffset = featureTableDraco.byteOffset;
350
- const dracoByteLength = featureTableDraco.byteLength;
351
- if (!dracoFeatureTableProperties || !dracoByteOffset || !dracoByteLength) {
352
- throw new Error('Draco properties, byteOffset, and byteLength must be defined');
353
- }
354
-
355
- dracoBuffer = arraySlice(
356
- featureTableBinary,
357
- dracoByteOffset,
358
- dracoByteOffset + dracoByteLength
359
- );
360
- tile.hasPositions = dracoFeatureTableProperties.POSITION;
361
- tile.hasColors = dracoFeatureTableProperties.RGB || dracoFeatureTableProperties.RGBA;
362
- tile.hasNormals = dracoFeatureTableProperties.NORMAL;
363
- tile.hasBatchIds = dracoFeatureTableProperties.BATCH_ID;
364
- tile.isTranslucent = dracoFeatureTableProperties.RGBA;
365
- }
366
-
367
- if (dracoBuffer) {
368
- tile.draco = {
369
- buffer: dracoBuffer,
370
- properties: {...dracoFeatureTableProperties, ...dracoBatchTableProperties},
371
- featureTableProperties: dracoFeatureTableProperties,
372
- batchTableProperties: dracoBatchTableProperties,
373
- dequantizeInShader: false
374
- };
375
-
376
- tile.decodingState = DECODING_STATE.NEEDS_DECODE;
377
- }
378
- }
379
-
380
- /*
381
- function decodeDraco(tile, context) {
382
- if (tile.decodingState === DECODING_STATE.READY) {
383
- return false;
384
- }
385
- if (tile.decodingState === DECODING_STATE.NEEDS_DECODE) {
386
- var parsedContent = tile._parsedContent;
387
- var draco = parsedContent.draco;
388
- var decodePromise = DracoLoader.decodePointCloud(draco, context);
389
- if (defined(decodePromise)) {
390
- tile.decodingState = DECODING_STATE.DECODING;
391
- decodePromise.then(function(result) {
392
- tile.decodingState = DECODING_STATE.READY;
393
- var decodedPositions = defined(result.POSITION) ? result.POSITION.array : undefined;
394
- var decodedRgb = defined(result.RGB) ? result.RGB.array : undefined;
395
- var decodedRgba = defined(result.RGBA) ? result.RGBA.array : undefined;
396
- var decodedNormals = defined(result.NORMAL) ? result.NORMAL.array : undefined;
397
- var decodedBatchIds = defined(result.BATCH_ID) ? result.BATCH_ID.array : undefined;
398
- var isQuantizedDraco = defined(decodedPositions) && defined(result.POSITION.data.quantization);
399
- var isOctEncodedDraco = defined(decodedNormals) && defined(result.NORMAL.data.quantization);
400
- if (isQuantizedDraco) {
401
- // Draco quantization range == quantized volume scale - size in meters of the quantized volume
402
- // Internal quantized range is the range of values of the quantized data, e.g. 255 for 8-bit, 1023 for 10-bit, etc
403
- var quantization = result.POSITION.data.quantization;
404
- var range = quantization.range;
405
- tile._quantizedVolumeScale = Cartesian3.fromElements(range, range, range);
406
- tile._quantizedVolumeOffset = Cartesian3.unpack(quantization.minValues);
407
- tile._quantizedRange = (1 << quantization.quantizationBits) - 1.0;
408
- tile._isQuantizedDraco = true;
409
- }
410
- if (isOctEncodedDraco) {
411
- tile._octEncodedRange = (1 << result.NORMAL.data.quantization.quantizationBits) - 1.0;
412
- tile._isOctEncodedDraco = true;
413
- }
414
- var styleableProperties = parsedContent.styleableProperties;
415
- var batchTableProperties = draco.batchTableProperties;
416
- for (var name in batchTableProperties) {
417
- if (batchTableProperties.hasOwnProperty(name)) {
418
- var property = result[name];
419
- if (!defined(styleableProperties)) {
420
- styleableProperties = {};
421
- }
422
- styleableProperties[name] = {
423
- typedArray : property.array,
424
- componentCount : property.data.componentsPerAttribute
425
- };
426
- }
427
- }
428
- parsedContent.positions = defaultValue(decodedPositions, parsedContent.positions);
429
- parsedContent.colors = defaultValue(defaultValue(decodedRgba, decodedRgb), parsedContent.colors);
430
- parsedContent.normals = defaultValue(decodedNormals, parsedContent.normals);
431
- parsedContent.batchIds = defaultValue(decodedBatchIds, parsedContent.batchIds);
432
- parsedContent.styleableProperties = styleableProperties;
433
- }).otherwise(function(error) {
434
- tile.decodingState = DECODING_STATE.FAILED;
435
- tile._readyPromise.reject(error);
436
- });
437
- }
438
- }
439
- return true;
440
- }
441
- */
@@ -1,33 +0,0 @@
1
- "use strict";
2
- // This file is derived from the Cesium code base under Apache 2 license
3
- // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.parse3DTile = void 0;
6
- const constants_1 = require("../constants");
7
- const parse_utils_1 = require("./helpers/parse-utils");
8
- const parse_3d_tile_point_cloud_1 = require("./parse-3d-tile-point-cloud");
9
- const parse_3d_tile_batched_model_1 = require("./parse-3d-tile-batched-model");
10
- const parse_3d_tile_instanced_model_1 = require("./parse-3d-tile-instanced-model");
11
- const parse_3d_tile_composite_1 = require("./parse-3d-tile-composite");
12
- const parse_3d_tile_gltf_1 = require("./parse-3d-tile-gltf");
13
- // Extracts
14
- async function parse3DTile(arrayBuffer, byteOffset = 0, options, context, tile = { shape: 'tile3d' }) {
15
- tile.byteOffset = byteOffset;
16
- tile.type = (0, parse_utils_1.getMagicString)(arrayBuffer, byteOffset);
17
- switch (tile.type) {
18
- case constants_1.TILE3D_TYPE.COMPOSITE:
19
- // Note: We pass this function as argument so that embedded tiles can be parsed recursively
20
- return await (0, parse_3d_tile_composite_1.parseComposite3DTile)(tile, arrayBuffer, byteOffset, options, context, parse3DTile);
21
- case constants_1.TILE3D_TYPE.BATCHED_3D_MODEL:
22
- return await (0, parse_3d_tile_batched_model_1.parseBatchedModel3DTile)(tile, arrayBuffer, byteOffset, options, context);
23
- case constants_1.TILE3D_TYPE.GLTF:
24
- return await (0, parse_3d_tile_gltf_1.parseGltf3DTile)(tile, arrayBuffer, options, context);
25
- case constants_1.TILE3D_TYPE.INSTANCED_3D_MODEL:
26
- return await (0, parse_3d_tile_instanced_model_1.parseInstancedModel3DTile)(tile, arrayBuffer, byteOffset, options, context);
27
- case constants_1.TILE3D_TYPE.POINT_CLOUD:
28
- return await (0, parse_3d_tile_point_cloud_1.parsePointCloud3DTile)(tile, arrayBuffer, byteOffset, options, context);
29
- default:
30
- throw new Error(`3DTileLoader: unknown type ${tile.type}`); // eslint-disable-line
31
- }
32
- }
33
- exports.parse3DTile = parse3DTile;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertS2BoundingVolumetoOBB = void 0;
4
- const core_1 = require("@math.gl/core");
5
- const culling_1 = require("@math.gl/culling");
6
- const index_1 = require("../../utils/s2/index");
7
- const index_2 = require("../../utils/s2/index");
8
- const geospatial_1 = require("@math.gl/geospatial");
9
- /**
10
- * Converts S2VolumeInfo to OrientedBoundingBox
11
- * @param {S2VolumeInfo} s2VolumeInfo - s2 volume to convert
12
- * @returns Oriented Bounding Box of type Box
13
- */
14
- function convertS2BoundingVolumetoOBB(s2VolumeInfo) {
15
- const token = s2VolumeInfo.token;
16
- const heightInfo = {
17
- minimumHeight: s2VolumeInfo.minimumHeight,
18
- maximumHeight: s2VolumeInfo.maximumHeight
19
- };
20
- const corners = (0, index_1.getS2OrientedBoundingBoxCornerPoints)(token, heightInfo);
21
- // Add a point that doesn't allow the box dive under the Earth
22
- const center = (0, index_2.getS2LngLat)(token);
23
- const centerLng = center[0];
24
- const centerLat = center[1];
25
- const point = geospatial_1.Ellipsoid.WGS84.cartographicToCartesian([
26
- centerLng,
27
- centerLat,
28
- heightInfo.maximumHeight
29
- ]);
30
- const centerPointAdditional = new core_1.Vector3(point[0], point[1], point[2]);
31
- corners.push(centerPointAdditional);
32
- // corners should be an array of Vector3 (XYZ)
33
- const obb = (0, culling_1.makeOrientedBoundingBoxFromPoints)(corners);
34
- const box = [...obb.center, ...obb.halfAxes];
35
- return box;
36
- }
37
- exports.convertS2BoundingVolumetoOBB = convertS2BoundingVolumetoOBB;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getS2BoundaryFlatFromS2Cell = void 0;
4
- const s2_geometry_1 = require("../s2geometry/s2-geometry");
5
- const MAX_RESOLUTION = 100;
6
- /**
7
- * Get a polygon with corner coordinates for an S2 cell
8
- * @param s2cell {S2Cell} S2 cell
9
- * @return {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
10
- * - the polygon is closed, i.e. last coordinate is a copy of the first coordinate
11
- */
12
- // eslint-disable-next-line max-statements
13
- function getS2BoundaryFlatFromS2Cell(s2cell) {
14
- const { face, ij, level } = s2cell;
15
- const offsets = [
16
- [0, 0],
17
- [0, 1],
18
- [1, 1],
19
- [1, 0],
20
- [0, 0]
21
- ];
22
- // The S2 cell edge is curved: http://s2geometry.io/
23
- // This is more prominent at lower levels
24
- // resolution is the number of segments to generate per edge.
25
- // We exponentially reduce resolution as level increases so it doesn't affect perf
26
- // when there are a large number of cells
27
- const resolution = Math.max(1, Math.ceil(MAX_RESOLUTION * Math.pow(2, -level)));
28
- const result = new Float64Array(4 * resolution * 2 + 2);
29
- let ptIndex = 0;
30
- let prevLng = 0;
31
- for (let i = 0; i < 4; i++) {
32
- const offset = offsets[i].slice(0);
33
- const nextOffset = offsets[i + 1];
34
- const stepI = (nextOffset[0] - offset[0]) / resolution;
35
- const stepJ = (nextOffset[1] - offset[1]) / resolution;
36
- for (let j = 0; j < resolution; j++) {
37
- offset[0] += stepI;
38
- offset[1] += stepJ;
39
- // Cell can be represented by coordinates IJ, ST, UV, XYZ
40
- // http://s2geometry.io/devguide/s2cell_hierarchy#coordinate-systems
41
- const st = (0, s2_geometry_1.IJToST)(ij, level, offset);
42
- const uv = (0, s2_geometry_1.STToUV)(st);
43
- const xyz = (0, s2_geometry_1.FaceUVToXYZ)(face, uv);
44
- const lngLat = (0, s2_geometry_1.XYZToLngLat)(xyz);
45
- // Adjust longitude for Web Mercator projection
46
- if (Math.abs(lngLat[1]) > 89.999) {
47
- lngLat[0] = prevLng;
48
- }
49
- const deltaLng = lngLat[0] - prevLng;
50
- lngLat[0] += deltaLng > 180 ? -360 : deltaLng < -180 ? 360 : 0;
51
- result[ptIndex++] = lngLat[0];
52
- result[ptIndex++] = lngLat[1];
53
- prevLng = lngLat[0];
54
- }
55
- }
56
- // close the loop
57
- result[ptIndex++] = result[0];
58
- result[ptIndex++] = result[1];
59
- return result;
60
- }
61
- exports.getS2BoundaryFlatFromS2Cell = getS2BoundaryFlatFromS2Cell;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getS2OrientedBoundingBoxCornerPoints = void 0;
4
- const s2_cell_utils_1 = require("../s2geometry/s2-cell-utils");
5
- const s2_to_region_1 = require("./s2-to-region");
6
- const core_1 = require("@math.gl/core");
7
- /**
8
- * Converts S2HeightInfo to corner points of an oriented bounding box
9
- * Can be used to constuct an OrientedBoundingBox instance
10
- * @param tokenOrKey {string} A string that is the cell's hex token or the Hilbert quad key (containing /)
11
- * @param heightInfo {S2HeightInfo} min and max height of the box
12
- * @returns corner points of the oriented bounding box
13
- */
14
- function getS2OrientedBoundingBoxCornerPoints(tokenOrKey, // This can be an S2 key or token
15
- heightInfo) {
16
- const min = heightInfo?.minimumHeight || 0;
17
- const max = heightInfo?.maximumHeight || 0;
18
- const s2cell = (0, s2_cell_utils_1.getS2Cell)(tokenOrKey);
19
- const region = (0, s2_to_region_1.getS2Region)(s2cell);
20
- // region lng/lat are in degrees
21
- const W = region.west;
22
- const S = region.south;
23
- const E = region.east;
24
- const N = region.north;
25
- const points = [];
26
- points.push(new core_1.Vector3(W, N, min));
27
- points.push(new core_1.Vector3(E, N, min));
28
- points.push(new core_1.Vector3(E, S, min));
29
- points.push(new core_1.Vector3(W, S, min));
30
- points.push(new core_1.Vector3(W, N, max));
31
- points.push(new core_1.Vector3(E, N, max));
32
- points.push(new core_1.Vector3(E, S, max));
33
- points.push(new core_1.Vector3(W, S, max));
34
- return points;
35
- }
36
- exports.getS2OrientedBoundingBoxCornerPoints = getS2OrientedBoundingBoxCornerPoints;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getS2Region = void 0;
4
- const s2_to_boundary_1 = require("./s2-to-boundary");
5
- const s2_cell_utils_1 = require("../s2geometry/s2-cell-utils");
6
- /**
7
- * Converts S2 cell to the 2D region
8
- * @param s2cell {S2Cell} S2 cell to convert to 2D region
9
- * @returns 2D region as an object containing: west, north, east, south in degrees
10
- */
11
- function getS2Region(s2cell) {
12
- let region;
13
- if (s2cell.face === 2 || s2cell.face === 5) {
14
- // let corners: Float64Array;
15
- let corners = null;
16
- let len = 0;
17
- for (let i = 0; i < 4; i++) {
18
- const key = `${s2cell.face}/${i}`;
19
- const cell = (0, s2_cell_utils_1.getS2Cell)(key);
20
- const corns = (0, s2_to_boundary_1.getS2BoundaryFlatFromS2Cell)(cell);
21
- if (typeof corners === 'undefined' || corners === null)
22
- corners = new Float64Array(4 * corns.length);
23
- corners.set(corns, len);
24
- len += corns.length;
25
- }
26
- region = get2DRegionFromS2Corners(corners);
27
- }
28
- else {
29
- const corners = (0, s2_to_boundary_1.getS2BoundaryFlatFromS2Cell)(s2cell);
30
- region = get2DRegionFromS2Corners(corners);
31
- }
32
- return region;
33
- }
34
- exports.getS2Region = getS2Region;
35
- /**
36
- * Converts the S2 cell defined by its corners to the 2D region
37
- * @param corners {Float64Array} - a simple polygon in flat array format: [lng0, lat0, lng1, lat1, ...]
38
- * @returns 2D region as an object containing: west, north, east, south in degrees
39
- */
40
- function get2DRegionFromS2Corners(corners) {
41
- if (corners.length % 2 !== 0) {
42
- throw new Error('Invalid corners');
43
- }
44
- const longitudes = [];
45
- const latitudes = [];
46
- for (let i = 0; i < corners.length; i += 2) {
47
- longitudes.push(corners[i]);
48
- latitudes.push(corners[i + 1]);
49
- }
50
- longitudes.sort((a, b) => a - b);
51
- latitudes.sort((a, b) => a - b);
52
- // Return the region in degrees
53
- return {
54
- west: longitudes[0],
55
- east: longitudes[longitudes.length - 1],
56
- north: latitudes[latitudes.length - 1],
57
- south: latitudes[0]
58
- };
59
- }