@loaders.gl/3d-tiles 4.0.0-alpha.9 → 4.0.0-beta.2

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 (170) hide show
  1. package/dist/3d-tiles-archive/3d-tiles-archive-archive.d.ts +30 -0
  2. package/dist/3d-tiles-archive/3d-tiles-archive-archive.d.ts.map +1 -0
  3. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +10 -0
  4. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -0
  5. package/dist/3d-tiles-archive-loader.d.ts +13 -0
  6. package/dist/3d-tiles-archive-loader.d.ts.map +1 -0
  7. package/dist/cesium-ion-loader.d.ts +2 -2
  8. package/dist/cesium-ion-loader.d.ts.map +1 -1
  9. package/dist/dist.min.js +10981 -4462
  10. package/dist/es5/3d-tiles-archive/3d-tiles-archive-archive.js +126 -0
  11. package/dist/es5/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -0
  12. package/dist/es5/3d-tiles-archive/3d-tiles-archive-parser.js +69 -0
  13. package/dist/es5/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -0
  14. package/dist/es5/3d-tiles-archive-loader.js +50 -0
  15. package/dist/es5/3d-tiles-archive-loader.js.map +1 -0
  16. package/dist/es5/cesium-ion-loader.js.map +1 -1
  17. package/dist/es5/index.js +14 -0
  18. package/dist/es5/index.js.map +1 -1
  19. package/dist/es5/lib/filesystems/tiles-3d-archive-file-system.js +151 -0
  20. package/dist/es5/lib/filesystems/tiles-3d-archive-file-system.js.map +1 -0
  21. package/dist/es5/lib/ion/ion.js +3 -9
  22. package/dist/es5/lib/ion/ion.js.map +1 -1
  23. package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js +63 -38
  24. package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -1
  25. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js +3 -3
  26. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
  27. package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js +70 -55
  28. package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -1
  29. package/dist/es5/lib/parsers/parse-3d-tile-composite.js +3 -1
  30. package/dist/es5/lib/parsers/parse-3d-tile-composite.js.map +1 -1
  31. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +14 -12
  32. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
  33. package/dist/es5/lib/parsers/parse-3d-tile-header.js +14 -12
  34. package/dist/es5/lib/parsers/parse-3d-tile-header.js.map +1 -1
  35. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js +6 -6
  36. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
  37. package/dist/es5/lib/parsers/parse-3d-tile.js +3 -1
  38. package/dist/es5/lib/parsers/parse-3d-tile.js.map +1 -1
  39. package/dist/es5/lib/utils/version.js +1 -1
  40. package/dist/es5/lib/utils/version.js.map +1 -1
  41. package/dist/es5/tile-3d-subtree-loader.js.map +1 -1
  42. package/dist/es5/tile-3d-writer.js.map +1 -1
  43. package/dist/es5/tiles-3d-loader.js +2 -0
  44. package/dist/es5/tiles-3d-loader.js.map +1 -1
  45. package/dist/es5/types.js.map +1 -1
  46. package/dist/esm/3d-tiles-archive/3d-tiles-archive-archive.js +46 -0
  47. package/dist/esm/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -0
  48. package/dist/esm/3d-tiles-archive/3d-tiles-archive-parser.js +23 -0
  49. package/dist/esm/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -0
  50. package/dist/esm/3d-tiles-archive-loader.js +20 -0
  51. package/dist/esm/3d-tiles-archive-loader.js.map +1 -0
  52. package/dist/esm/cesium-ion-loader.js.map +1 -1
  53. package/dist/esm/index.js +2 -0
  54. package/dist/esm/index.js.map +1 -1
  55. package/dist/esm/lib/filesystems/tiles-3d-archive-file-system.js +49 -0
  56. package/dist/esm/lib/filesystems/tiles-3d-archive-file-system.js.map +1 -0
  57. package/dist/esm/lib/ion/ion.js +3 -9
  58. package/dist/esm/lib/ion/ion.js.map +1 -1
  59. package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js +45 -23
  60. package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -1
  61. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js +5 -6
  62. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
  63. package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js +18 -24
  64. package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -1
  65. package/dist/esm/lib/parsers/parse-3d-tile-composite.js +3 -1
  66. package/dist/esm/lib/parsers/parse-3d-tile-composite.js.map +1 -1
  67. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js +7 -8
  68. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
  69. package/dist/esm/lib/parsers/parse-3d-tile-header.js +8 -5
  70. package/dist/esm/lib/parsers/parse-3d-tile-header.js.map +1 -1
  71. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js +2 -4
  72. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
  73. package/dist/esm/lib/parsers/parse-3d-tile.js +3 -1
  74. package/dist/esm/lib/parsers/parse-3d-tile.js.map +1 -1
  75. package/dist/esm/lib/utils/version.js +1 -1
  76. package/dist/esm/lib/utils/version.js.map +1 -1
  77. package/dist/esm/tile-3d-subtree-loader.js.map +1 -1
  78. package/dist/esm/tile-3d-writer.js.map +1 -1
  79. package/dist/esm/tiles-3d-loader.js +2 -0
  80. package/dist/esm/tiles-3d-loader.js.map +1 -1
  81. package/dist/esm/types.js.map +1 -1
  82. package/dist/index.d.ts +3 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts +32 -0
  85. package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts.map +1 -0
  86. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -1
  87. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
  88. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  89. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
  90. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
  91. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  92. package/dist/lib/parsers/parse-3d-tile-header.d.ts +30 -2
  93. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  94. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +1 -1
  95. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  96. package/dist/lib/parsers/parse-3d-tile.d.ts +1 -1
  97. package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
  98. package/dist/tile-3d-subtree-loader.d.ts +3 -3
  99. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  100. package/dist/tile-3d-writer.d.ts +2 -2
  101. package/dist/tile-3d-writer.d.ts.map +1 -1
  102. package/dist/tiles-3d-loader.d.ts +2 -1
  103. package/dist/tiles-3d-loader.d.ts.map +1 -1
  104. package/dist/types.d.ts +49 -8
  105. package/dist/types.d.ts.map +1 -1
  106. package/package.json +9 -7
  107. package/src/3d-tiles-archive/3d-tiles-archive-archive.ts +85 -0
  108. package/src/3d-tiles-archive/3d-tiles-archive-parser.ts +52 -0
  109. package/src/3d-tiles-archive-loader.ts +47 -0
  110. package/src/cesium-ion-loader.ts +2 -3
  111. package/src/index.ts +3 -0
  112. package/src/lib/filesystems/tiles-3d-archive-file-system.ts +97 -0
  113. package/src/lib/ion/ion.ts +3 -3
  114. package/src/lib/parsers/helpers/parse-3d-implicit-tiles.ts +76 -32
  115. package/src/lib/parsers/helpers/parse-3d-tile-gltf-view.ts +8 -3
  116. package/src/lib/parsers/helpers/parse-3d-tile-subtree.ts +44 -62
  117. package/src/lib/parsers/parse-3d-tile-composite.ts +1 -1
  118. package/src/lib/parsers/parse-3d-tile-gltf.ts +11 -10
  119. package/src/lib/parsers/parse-3d-tile-header.ts +39 -6
  120. package/src/lib/parsers/parse-3d-tile-point-cloud.ts +10 -3
  121. package/src/lib/parsers/parse-3d-tile.ts +2 -2
  122. package/src/tile-3d-subtree-loader.ts +3 -3
  123. package/src/tile-3d-writer.ts +2 -2
  124. package/src/tiles-3d-loader.ts +16 -4
  125. package/src/types.ts +52 -9
  126. package/dist/bundle.js +0 -5
  127. package/dist/cesium-ion-loader.js +0 -41
  128. package/dist/index.js +0 -26
  129. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +0 -113
  130. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +0 -197
  131. package/dist/lib/classes/tile-3d-batch-table.js +0 -245
  132. package/dist/lib/classes/tile-3d-feature-table.js +0 -72
  133. package/dist/lib/constants.js +0 -26
  134. package/dist/lib/encoders/encode-3d-tile-batched-model.js +0 -46
  135. package/dist/lib/encoders/encode-3d-tile-composite.js +0 -24
  136. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +0 -38
  137. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +0 -39
  138. package/dist/lib/encoders/encode-3d-tile.js +0 -33
  139. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +0 -30
  140. package/dist/lib/ion/ion.js +0 -68
  141. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
  142. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -30
  143. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -42
  144. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -266
  145. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -96
  146. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +0 -28
  147. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -104
  148. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +0 -93
  149. package/dist/lib/parsers/helpers/parse-utils.js +0 -32
  150. package/dist/lib/parsers/parse-3d-tile-batched-model.js +0 -33
  151. package/dist/lib/parsers/parse-3d-tile-composite.js +0 -24
  152. package/dist/lib/parsers/parse-3d-tile-gltf.js +0 -28
  153. package/dist/lib/parsers/parse-3d-tile-header.js +0 -192
  154. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +0 -172
  155. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +0 -433
  156. package/dist/lib/parsers/parse-3d-tile.js +0 -33
  157. package/dist/lib/utils/obb/s2-corners-to-obb.js +0 -37
  158. package/dist/lib/utils/s2/converters/s2-to-boundary.js +0 -61
  159. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +0 -36
  160. package/dist/lib/utils/s2/converters/s2-to-region.js +0 -59
  161. package/dist/lib/utils/s2/index.js +0 -23
  162. package/dist/lib/utils/s2/s2-geometry-functions.js +0 -29
  163. package/dist/lib/utils/s2/s2-token-functions.js +0 -68
  164. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -32
  165. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +0 -260
  166. package/dist/lib/utils/version.js +0 -7
  167. package/dist/tile-3d-subtree-loader.js +0 -23
  168. package/dist/tile-3d-writer.js +0 -27
  169. package/dist/tiles-3d-loader.js +0 -76
  170. package/dist/types.js +0 -2
@@ -1,11 +1,13 @@
1
1
  import type {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
2
2
  import type {LoaderOptions} from '@loaders.gl/loader-utils';
3
+ import {path} from '@loaders.gl/loader-utils';
3
4
  import {Tile3DSubtreeLoader} from '../../tile-3d-subtree-loader';
4
5
  import {load} from '@loaders.gl/core';
5
6
  import {LOD_METRIC_TYPE, TILE_REFINEMENT, TILE_TYPE} from '@loaders.gl/tiles';
6
7
  import {
7
8
  ImplicitTilingExensionData,
8
9
  Subtree,
10
+ Tile3DBoundingVolume,
9
11
  Tiles3DTileContentJSON,
10
12
  Tiles3DTileJSON,
11
13
  Tiles3DTileJSONPostprocessed,
@@ -16,6 +18,34 @@ import {parseImplicitTiles, replaceContentUrlTemplate} from './helpers/parse-3d-
16
18
  import type {S2VolumeInfo} from '../utils/obb/s2-corners-to-obb';
17
19
  import {convertS2BoundingVolumetoOBB} from '../utils/obb/s2-corners-to-obb';
18
20
 
21
+ /** Options for recursive loading implicit subtrees */
22
+ export type ImplicitOptions = {
23
+ /** Template of the full url of the content template */
24
+ contentUrlTemplate: string;
25
+ /** Template of the full url of the subtree */
26
+ subtreesUriTemplate: string;
27
+ /** Implicit subdivision scheme */
28
+ subdivisionScheme: 'QUADTREE' | 'OCTREE' | string;
29
+ /** Levels per subtree */
30
+ subtreeLevels: number;
31
+ /** Maximum implicit level through all subtrees */
32
+ maximumLevel?: number;
33
+ /** 3DTiles refine method (add/replace) */
34
+ refine?: string;
35
+ /** Tileset base path */
36
+ basePath: string;
37
+ /** 3DTiles LOD metric type */
38
+ lodMetricType: LOD_METRIC_TYPE.GEOMETRIC_ERROR;
39
+ /** Root metric value of the root tile of the implicit subtrees */
40
+ rootLodMetricValue: number;
41
+ /** Bounding volume of the root tile of the implicit subtrees */
42
+ rootBoundingVolume: Tile3DBoundingVolume;
43
+ /** Function that detects TILE_TYPE by tile metadata and content URL */
44
+ getTileType: (tile: Tiles3DTileJSON, tileContentUrl?: string) => TILE_TYPE | string;
45
+ /** Function that converts string refine method to enum value */
46
+ getRefine: (refine?: string) => TILE_REFINEMENT | string | undefined;
47
+ };
48
+
19
49
  function getTileType(tile: Tiles3DTileJSON, tileContentUrl: string = ''): TILE_TYPE | string {
20
50
  if (!tileContentUrl) {
21
51
  return TILE_TYPE.EMPTY;
@@ -60,7 +90,7 @@ function resolveUri(uri: string = '', basePath: string): string {
60
90
  return uri;
61
91
  }
62
92
 
63
- return `${basePath}/${uri}`;
93
+ return path.resolve(basePath, uri);
64
94
  }
65
95
 
66
96
  export function normalizeTileData(
@@ -158,6 +188,7 @@ export async function normalizeImplicitTileHeaders(
158
188
  const {
159
189
  subdivisionScheme,
160
190
  maximumLevel,
191
+ availableLevels,
161
192
  subtreeLevels,
162
193
  subtrees: {uri: subtreesUriTemplate}
163
194
  } = implicitTilingExtension;
@@ -179,12 +210,12 @@ export async function normalizeImplicitTileHeaders(
179
210
 
180
211
  const rootBoundingVolume = tile.boundingVolume;
181
212
 
182
- const implicitOptions = {
213
+ const implicitOptions: ImplicitOptions = {
183
214
  contentUrlTemplate,
184
215
  subtreesUriTemplate,
185
216
  subdivisionScheme,
186
217
  subtreeLevels,
187
- maximumLevel,
218
+ maximumLevel: Number.isFinite(availableLevels) ? availableLevels - 1 : maximumLevel,
188
219
  refine,
189
220
  basePath,
190
221
  lodMetricType: LOD_METRIC_TYPE.GEOMETRIC_ERROR,
@@ -194,7 +225,7 @@ export async function normalizeImplicitTileHeaders(
194
225
  getRefine
195
226
  };
196
227
 
197
- return await normalizeImplicitTileData(tile, basePath, subtree, implicitOptions);
228
+ return await normalizeImplicitTileData(tile, basePath, subtree, implicitOptions, options);
198
229
  }
199
230
 
200
231
  /**
@@ -208,7 +239,8 @@ export async function normalizeImplicitTileData(
208
239
  tile: Tiles3DTileJSON,
209
240
  basePath: string,
210
241
  rootSubtree: Subtree,
211
- options: any
242
+ implicitOptions: ImplicitOptions,
243
+ loaderOptions: Tiles3DLoaderOptions
212
244
  ): Promise<Tiles3DTileJSONPostprocessed | null> {
213
245
  if (!tile) {
214
246
  return null;
@@ -216,7 +248,8 @@ export async function normalizeImplicitTileData(
216
248
 
217
249
  const {children, contentUrl} = await parseImplicitTiles({
218
250
  subtree: rootSubtree,
219
- options
251
+ implicitOptions,
252
+ loaderOptions
220
253
  });
221
254
 
222
255
  let tileContentUrl: string | undefined;
@@ -2,6 +2,7 @@
2
2
  // See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
3
3
 
4
4
  import {DracoLoader} from '@loaders.gl/draco';
5
+ import {LoaderContext, parseFromContext} from '@loaders.gl/loader-utils';
5
6
  import {GL} from '@loaders.gl/math';
6
7
  import {Vector3} from '@math.gl/core';
7
8
 
@@ -13,7 +14,6 @@ import {normalize3DTileColorAttribute} from './helpers/normalize-3d-tile-colors'
13
14
  import {normalize3DTileNormalAttribute} from './helpers/normalize-3d-tile-normals';
14
15
  import {normalize3DTilePositionAttribute} from './helpers/normalize-3d-tile-positions';
15
16
  import {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
16
- import {LoaderContext} from '@loaders.gl/loader-utils';
17
17
  import {Tiles3DTileContent} from '../../types';
18
18
 
19
19
  export async function parsePointCloud3DTile(
@@ -262,7 +262,6 @@ export async function loadDraco(
262
262
  if (!context) {
263
263
  return;
264
264
  }
265
- const {parse} = context;
266
265
  const dracoOptions = {
267
266
  ...options,
268
267
  draco: {
@@ -274,17 +273,20 @@ export async function loadDraco(
274
273
  // The entire tileset might be included, too expensive to serialize
275
274
  delete dracoOptions['3d-tiles'];
276
275
 
277
- const data = await parse(dracoData.buffer, DracoLoader, dracoOptions);
276
+ const data = await parseFromContext(dracoData.buffer, DracoLoader, dracoOptions, context);
278
277
 
279
278
  const decodedPositions = data.attributes.POSITION && data.attributes.POSITION.value;
280
279
  const decodedColors = data.attributes.COLOR_0 && data.attributes.COLOR_0.value;
281
280
  const decodedNormals = data.attributes.NORMAL && data.attributes.NORMAL.value;
282
281
  const decodedBatchIds = data.attributes.BATCH_ID && data.attributes.BATCH_ID.value;
282
+ // @ts-expect-error
283
283
  const isQuantizedDraco = decodedPositions && data.attributes.POSITION.value.quantization;
284
+ // @ts-expect-error
284
285
  const isOctEncodedDraco = decodedNormals && data.attributes.NORMAL.value.quantization;
285
286
  if (isQuantizedDraco) {
286
287
  // Draco quantization range == quantized volume scale - size in meters of the quantized volume
287
288
  // Internal quantized range is the range of values of the quantized data, e.g. 255 for 8-bit, 1023 for 10-bit, etc
289
+ // @ts-expect-error This doesn't look right
288
290
  const quantization = data.POSITION.data.quantization;
289
291
  const range = quantization.range;
290
292
  tile.quantizedVolumeScale = new Vector3(range, range, range);
@@ -293,6 +295,7 @@ export async function loadDraco(
293
295
  tile.isQuantizedDraco = true;
294
296
  }
295
297
  if (isOctEncodedDraco) {
298
+ // @ts-expect-error This doesn't look right
296
299
  tile.octEncodedRange = (1 << data.NORMAL.data.quantization.quantizationBits) - 1.0;
297
300
  tile.isOctEncodedDraco = true;
298
301
  }
@@ -308,9 +311,13 @@ export async function loadDraco(
308
311
  }
309
312
 
310
313
  tile.attributes = {
314
+ // @ts-expect-error
311
315
  positions: decodedPositions,
316
+ // @ts-expect-error
312
317
  colors: normalize3DTileColorAttribute(tile, decodedColors, undefined),
318
+ // @ts-expect-error
313
319
  normals: decodedNormals,
320
+ // @ts-expect-error
314
321
  batchIds: decodedBatchIds,
315
322
  ...batchTableAttributes
316
323
  };
@@ -19,8 +19,8 @@ export async function parse3DTile(
19
19
  byteOffset = 0,
20
20
  options: Tiles3DLoaderOptions | undefined,
21
21
  context: LoaderContext | undefined,
22
- tile: Tiles3DTileContent = {}
23
- ) {
22
+ tile: Tiles3DTileContent = {shape: 'tile3d'}
23
+ ): Promise<number> {
24
24
  tile.byteOffset = byteOffset;
25
25
  tile.type = getMagicString(arrayBuffer, byteOffset);
26
26
 
@@ -1,12 +1,12 @@
1
- import type {LoaderWithParser} from '@loaders.gl/loader-utils';
1
+ import type {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
2
+ import type {Subtree} from './types';
2
3
  import parse3DTilesSubtree from './lib/parsers/helpers/parse-3d-tile-subtree';
3
4
  import {VERSION} from './lib/utils/version';
4
5
 
5
6
  /**
6
7
  * Loader for 3D Tiles Subtree
7
- *
8
8
  */
9
- export const Tile3DSubtreeLoader: LoaderWithParser = {
9
+ export const Tile3DSubtreeLoader: LoaderWithParser<Subtree, never, LoaderOptions> = {
10
10
  id: '3d-tiles-subtree',
11
11
  name: '3D Tiles Subtree',
12
12
  module: '3d-tiles',
@@ -1,11 +1,11 @@
1
- import type {Writer} from '@loaders.gl/loader-utils';
1
+ import type {Writer, WriterOptions} from '@loaders.gl/loader-utils';
2
2
  import {VERSION} from './lib/utils/version';
3
3
  import encode3DTile from './lib/encoders/encode-3d-tile';
4
4
 
5
5
  /**
6
6
  * Exporter for 3D Tiles
7
7
  */
8
- export const Tile3DWriter: Writer = {
8
+ export const Tile3DWriter: Writer<unknown, never, WriterOptions> = {
9
9
  name: '3D Tile',
10
10
  id: '3d-tiles',
11
11
  module: '3d-tiles',
@@ -8,7 +8,7 @@ import {TILESET_TYPE, LOD_METRIC_TYPE} from '@loaders.gl/tiles';
8
8
  import {VERSION} from './lib/utils/version';
9
9
  import {parse3DTile} from './lib/parsers/parse-3d-tile';
10
10
  import {normalizeTileHeaders} from './lib/parsers/parse-3d-tile-header';
11
- import {Tiles3DTilesetJSON, Tiles3DTilesetJSONPostprocessed} from './types';
11
+ import {Tiles3DTilesetJSON, Tiles3DTileContent, Tiles3DTilesetJSONPostprocessed} from './types';
12
12
 
13
13
  export type Tiles3DLoaderOptions = LoaderOptions &
14
14
  // GLTFLoaderOptions & - TODO not yet exported
@@ -29,7 +29,11 @@ export type Tiles3DLoaderOptions = LoaderOptions &
29
29
  /**
30
30
  * Loader for 3D Tiles
31
31
  */
32
- export const Tiles3DLoader: LoaderWithParser = {
32
+ export const Tiles3DLoader: LoaderWithParser<
33
+ any, // Tiles3DTileContent | Tiles3DTilesetJSONPostprocessed,
34
+ never,
35
+ Tiles3DLoaderOptions
36
+ > = {
33
37
  id: '3d-tiles',
34
38
  name: '3D Tiles',
35
39
  module: '3d-tiles',
@@ -49,7 +53,11 @@ export const Tiles3DLoader: LoaderWithParser = {
49
53
  };
50
54
 
51
55
  /** Parses a tileset or tile */
52
- async function parse(data, options: Tiles3DLoaderOptions = {}, context?: LoaderContext) {
56
+ async function parse(
57
+ data,
58
+ options: Tiles3DLoaderOptions = {},
59
+ context?: LoaderContext
60
+ ): Promise<Tiles3DTileContent | Tiles3DTilesetJSONPostprocessed> {
53
61
  // auto detect file type
54
62
  const loaderOptions = options['3d-tiles'] || {};
55
63
  let isTileset;
@@ -75,6 +83,7 @@ async function parseTileset(
75
83
  const normalizedRoot = await normalizeTileHeaders(tilesetJson, basePath, options || {});
76
84
  const tilesetJsonPostprocessed: Tiles3DTilesetJSONPostprocessed = {
77
85
  ...tilesetJson,
86
+ shape: 'tileset3d',
78
87
  loader: Tiles3DLoader,
79
88
  url: tilesetUrl,
80
89
  queryString: context?.queryString || '',
@@ -92,14 +101,17 @@ async function parseTile(
92
101
  arrayBuffer: ArrayBuffer,
93
102
  options?: Tiles3DLoaderOptions,
94
103
  context?: LoaderContext
95
- ) {
104
+ ): Promise<Tiles3DTileContent> {
96
105
  const tile = {
97
106
  content: {
107
+ shape: 'tile3d',
98
108
  featureIds: null
99
109
  }
100
110
  };
101
111
  const byteOffset = 0;
112
+ // @ts-expect-error
102
113
  await parse3DTile(arrayBuffer, byteOffset, options, context, tile.content);
114
+ // @ts-expect-error
103
115
  return tile.content;
104
116
  }
105
117
 
package/src/types.ts CHANGED
@@ -1,12 +1,10 @@
1
- import type {GLTFPostprocessed} from '@loaders.gl/gltf';
1
+ import type {GLTFPostprocessed, FeatureTableJson} from '@loaders.gl/gltf';
2
+ export type {FeatureTableJson};
3
+
2
4
  import {LoaderWithParser} from '@loaders.gl/loader-utils';
3
5
  import {Matrix4, Vector3} from '@math.gl/core';
4
6
  import {TILESET_TYPE, LOD_METRIC_TYPE, TILE_TYPE, TILE_REFINEMENT} from '@loaders.gl/tiles';
5
7
 
6
- export type FeatureTableJson = {
7
- [key: string]: any[];
8
- };
9
-
10
8
  export type B3DMContent = {
11
9
  batchTableJson?: FeatureTableJson;
12
10
  byteLength: number;
@@ -42,6 +40,7 @@ export type GLTFHeader = {
42
40
  * https://github.com/CesiumGS/3d-tiles/tree/main/specification#property-reference
43
41
  */
44
42
  export type Tiles3DTilesetJSON = {
43
+ shape: 'tileset3d';
45
44
  /** Metadata about the entire tileset.
46
45
  * https://github.com/CesiumGS/3d-tiles/tree/main/specification#asset
47
46
  */
@@ -202,6 +201,8 @@ export type TilesetProperty = {
202
201
  };
203
202
 
204
203
  export type Tiles3DTileContent = {
204
+ shape: 'tile3d';
205
+
205
206
  /** Common properties */
206
207
  byteOffset?: number;
207
208
  type?: string;
@@ -294,20 +295,57 @@ export type Tiles3DTileContent = {
294
295
 
295
296
  /**
296
297
  * 3DTILES_implicit_tiling types
297
- * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling#subtree-file-format
298
+ * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling
299
+ * JSON Schema v1.1 https://github.com/CesiumGS/3d-tiles/blob/8e5e67e078850cc8ce15bd1873fe54f11bbee02f/specification/schema/Subtree/subtree.schema.json
300
+ * JSON Schema vNext https://github.com/CesiumGS/3d-tiles/blob/8e5e67e078850cc8ce15bd1873fe54f11bbee02f/extensions/3DTILES_implicit_tiling/schema/subtree/subtree.schema.json
298
301
  */
299
302
  export type Subtree = {
303
+ /** An array of buffers. */
300
304
  buffers: Buffer[];
305
+ /** An array of buffer views. */
301
306
  bufferViews: BufferView[];
307
+ /** The availability of tiles in the subtree. The availability bitstream is a 1D boolean array where tiles are ordered by their level in the subtree and Morton index
308
+ * within that level. A tile's availability is determined by a single bit, 1 meaning a tile exists at that spatial index, and 0 meaning it does not.
309
+ * The number of elements in the array is `(N^subtreeLevels - 1)/(N - 1)` where N is 4 for subdivision scheme `QUADTREE` and 8 for `OCTREE`.
310
+ * Availability may be stored in a buffer view or as a constant value that applies to all tiles. If a non-root tile's availability is 1 its parent
311
+ * tile's availability shall also be 1. `tileAvailability.constant: 0` is disallowed, as subtrees shall have at least one tile.
312
+ */
302
313
  tileAvailability: Availability;
303
- contentAvailability: Availability;
314
+ /** It is array by spec but there are tiles that has a single object
315
+ * An array of content availability objects. If the tile has a single content this array will have one element; if the tile has multiple contents -
316
+ * as supported by 3DTILES_multiple_contents and 3D Tiles 1.1 - this array will have multiple elements.
317
+ */
318
+ contentAvailability: Availability | Availability[];
319
+ /** The availability of children subtrees. The availability bitstream is a 1D boolean array where subtrees are ordered by their Morton index in the level of the tree
320
+ * immediately below the bottom row of the subtree. A child subtree's availability is determined by a single bit, 1 meaning a subtree exists at that spatial index,
321
+ * and 0 meaning it does not. The number of elements in the array is `N^subtreeLevels` where N is 4 for subdivision scheme `QUADTREE` and 8 for `OCTREE`.
322
+ * Availability may be stored in a buffer view or as a constant value that applies to all child subtrees. If availability is 0 for all child subtrees,
323
+ * then the tileset does not subdivide further.
324
+ */
304
325
  childSubtreeAvailability: Availability;
326
+ // TODO: These are unused properties. Improve types when they are required
327
+ propertyTables: unknown;
328
+ tileMetadata: unknown;
329
+ contentMetadata: unknown;
330
+ subtreeMetadata: unknown;
305
331
  };
306
332
 
307
333
  export type Availability = {
334
+ /** Integer indicating whether all of the elements are available (1) or all are unavailable (0). */
308
335
  constant?: 0 | 1;
336
+ /** Index of a buffer view that indicates whether each element is available. The bitstream conforms to the boolean array encoding described
337
+ * in the 3D Metadata specification. If an element is available, its bit is 1, and if it is unavailable, its bit is 0. */
338
+ bitstream?: number;
339
+ /**
340
+ * v1.1 https://github.com/CesiumGS/3d-tiles/blob/8e5e67e078850cc8ce15bd1873fe54f11bbee02f/specification/schema/Subtree/availability.schema.json
341
+ * vNext https://github.com/CesiumGS/3d-tiles/blob/8e5e67e078850cc8ce15bd1873fe54f11bbee02f/extensions/3DTILES_implicit_tiling/schema/subtree/availability.schema.json
342
+ * The schemas of vNext and 1.1 are same but there are tiles with `bufferView` property instead of `bitstream`
343
+ */
309
344
  bufferView?: number;
310
- // Internal bitstream type
345
+ /**
346
+ * Postprocessing property
347
+ * contain availability bits loaded from the bufferView
348
+ */
311
349
  explicitBitstream?: ExplicitBitstream;
312
350
  };
313
351
 
@@ -324,7 +362,8 @@ type Buffer = {
324
362
  byteLength: number;
325
363
  };
326
364
 
327
- type BufferView = {
365
+ /** Subtree buffer view */
366
+ export type BufferView = {
328
367
  buffer: number;
329
368
  byteOffset: number;
330
369
  byteLength: number;
@@ -334,6 +373,10 @@ type BufferView = {
334
373
  * Spec - https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_implicit_tiling
335
374
  */
336
375
  export type ImplicitTilingExensionData = ImplicitTilingData & {
376
+ /** This property is not part of the schema
377
+ * https://github.com/CesiumGS/3d-tiles/blob/main/extensions/3DTILES_implicit_tiling/schema/tile.3DTILES_implicit_tiling.schema.json
378
+ * But it can be seen in some test datasets. It is handled as substitute of `availableLevels`
379
+ */
337
380
  maximumLevel?: number;
338
381
  };
339
382
 
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CesiumIonLoader = void 0;
4
- const tiles_3d_loader_1 = require("./tiles-3d-loader");
5
- const ion_1 = require("./lib/ion/ion");
6
- async function preload(url, options = {}) {
7
- options = options['cesium-ion'] || {};
8
- // @ts-ignore
9
- const { accessToken } = options;
10
- // @ts-ignore
11
- let assetId = options.assetId;
12
- if (!Number.isFinite(assetId)) {
13
- const matched = url.match(/\/([0-9]+)\/tileset.json/);
14
- assetId = matched && matched[1];
15
- }
16
- return (0, ion_1.getIonTilesetMetadata)(accessToken, assetId);
17
- }
18
- /**
19
- * Loader for 3D tiles from Cesium ION
20
- */
21
- exports.CesiumIonLoader = {
22
- ...tiles_3d_loader_1.Tiles3DLoader,
23
- id: 'cesium-ion',
24
- name: 'Cesium Ion',
25
- // @ts-ignore
26
- preload,
27
- parse: async (data, options, context) => {
28
- options = { ...options };
29
- options['3d-tiles'] = options['cesium-ion'];
30
- // @ts-ignore
31
- options.loader = exports.CesiumIonLoader;
32
- return tiles_3d_loader_1.Tiles3DLoader.parse(data, options, context); // , loader);
33
- },
34
- options: {
35
- 'cesium-ion': {
36
- // @ts-expect-error
37
- ...tiles_3d_loader_1.Tiles3DLoader.options['3d-tiles'],
38
- accessToken: null
39
- }
40
- }
41
- };
package/dist/index.js DELETED
@@ -1,26 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports._getIonTilesetMetadata = exports.TILE3D_TYPE = exports.Tile3DBatchTable = exports.Tile3DFeatureTable = exports.Tile3DWriter = exports.Tile3DSubtreeLoader = exports.CesiumIonLoader = exports.Tiles3DLoader = void 0;
7
- // LOADERS
8
- var tiles_3d_loader_1 = require("./tiles-3d-loader");
9
- Object.defineProperty(exports, "Tiles3DLoader", { enumerable: true, get: function () { return tiles_3d_loader_1.Tiles3DLoader; } });
10
- var cesium_ion_loader_1 = require("./cesium-ion-loader");
11
- Object.defineProperty(exports, "CesiumIonLoader", { enumerable: true, get: function () { return cesium_ion_loader_1.CesiumIonLoader; } });
12
- var tile_3d_subtree_loader_1 = require("./tile-3d-subtree-loader");
13
- Object.defineProperty(exports, "Tile3DSubtreeLoader", { enumerable: true, get: function () { return tile_3d_subtree_loader_1.Tile3DSubtreeLoader; } });
14
- // WRITERS
15
- var tile_3d_writer_1 = require("./tile-3d-writer");
16
- Object.defineProperty(exports, "Tile3DWriter", { enumerable: true, get: function () { return tile_3d_writer_1.Tile3DWriter; } });
17
- // CLASSES
18
- var tile_3d_feature_table_1 = require("./lib/classes/tile-3d-feature-table");
19
- Object.defineProperty(exports, "Tile3DFeatureTable", { enumerable: true, get: function () { return __importDefault(tile_3d_feature_table_1).default; } });
20
- var tile_3d_batch_table_1 = require("./lib/classes/tile-3d-batch-table");
21
- Object.defineProperty(exports, "Tile3DBatchTable", { enumerable: true, get: function () { return __importDefault(tile_3d_batch_table_1).default; } });
22
- // EXPERIMENTAL
23
- var constants_1 = require("./lib/constants");
24
- Object.defineProperty(exports, "TILE3D_TYPE", { enumerable: true, get: function () { return constants_1.TILE3D_TYPE; } });
25
- var ion_1 = require("./lib/ion/ion");
26
- Object.defineProperty(exports, "_getIonTilesetMetadata", { enumerable: true, get: function () { return ion_1.getIonTilesetMetadata; } });
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTypedArrayFromAccessor = void 0;
4
- const math_1 = require("@loaders.gl/math"); // '@math.gl/geometry';
5
- const loader_utils_1 = require("@loaders.gl/loader-utils");
6
- const COMPONENTS_PER_ATTRIBUTE = {
7
- SCALAR: 1,
8
- VEC2: 2,
9
- VEC3: 3,
10
- VEC4: 4,
11
- MAT2: 4,
12
- MAT3: 9,
13
- MAT4: 16
14
- };
15
- // TODO - could just return typed array views...
16
- // prettier-ignore
17
- const UNPACKER = {
18
- SCALAR: (values, i) => values[i],
19
- VEC2: (values, i) => [values[2 * i + 0], values[2 * i + 1]],
20
- VEC3: (values, i) => [values[3 * i + 0], values[3 * i + 1], values[3 * i + 2]],
21
- VEC4: (values, i) => [values[4 * i + 0], values[4 * i + 1], values[4 * i + 2], values[4 * i + 3]],
22
- // TODO: check column major
23
- MAT2: (values, i) => [
24
- values[4 * i + 0], values[4 * i + 1],
25
- values[4 * i + 2], values[4 * i + 3]
26
- ],
27
- MAT3: (values, i) => [
28
- values[9 * i + 0], values[9 * i + 1], values[9 * i + 2],
29
- values[9 * i + 3], values[9 * i + 4], values[9 * i + 5],
30
- values[9 * i + 6], values[9 * i + 7], values[9 * i + 8]
31
- ],
32
- MAT4: (values, i) => [
33
- values[16 * i + 0], values[16 * i + 1], values[16 * i + 2], values[16 * i + 3],
34
- values[16 * i + 4], values[16 * i + 5], values[16 * i + 6], values[16 * i + 7],
35
- values[16 * i + 8], values[16 * i + 9], values[16 * i + 10], values[16 * i + 11],
36
- values[16 * i + 12], values[16 * i + 13], values[16 * i + 14], values[16 * i + 15]
37
- ]
38
- };
39
- const PACKER = {
40
- SCALAR: (x, values, i) => {
41
- values[i] = x;
42
- },
43
- VEC2: (x, values, i) => {
44
- values[2 * i + 0] = x[0];
45
- values[2 * i + 1] = x[1];
46
- },
47
- VEC3: (x, values, i) => {
48
- values[3 * i + 0] = x[0];
49
- values[3 * i + 1] = x[1];
50
- values[3 * i + 2] = x[2];
51
- },
52
- VEC4: (x, values, i) => {
53
- values[4 * i + 0] = x[0];
54
- values[4 * i + 1] = x[1];
55
- values[4 * i + 2] = x[2];
56
- values[4 * i + 3] = x[3];
57
- },
58
- // TODO: check column major correctness
59
- MAT2: (x, values, i) => {
60
- values[4 * i + 0] = x[0];
61
- values[4 * i + 1] = x[1];
62
- values[4 * i + 2] = x[2];
63
- values[4 * i + 3] = x[3];
64
- },
65
- MAT3: (x, values, i) => {
66
- values[9 * i + 0] = x[0];
67
- values[9 * i + 1] = x[1];
68
- values[9 * i + 2] = x[2];
69
- values[9 * i + 3] = x[3];
70
- values[9 * i + 4] = x[4];
71
- values[9 * i + 5] = x[5];
72
- values[9 * i + 6] = x[6];
73
- values[9 * i + 7] = x[7];
74
- values[9 * i + 8] = x[8];
75
- values[9 * i + 9] = x[9];
76
- },
77
- MAT4: (x, values, i) => {
78
- values[16 * i + 0] = x[0];
79
- values[16 * i + 1] = x[1];
80
- values[16 * i + 2] = x[2];
81
- values[16 * i + 3] = x[3];
82
- values[16 * i + 4] = x[4];
83
- values[16 * i + 5] = x[5];
84
- values[16 * i + 6] = x[6];
85
- values[16 * i + 7] = x[7];
86
- values[16 * i + 8] = x[8];
87
- values[16 * i + 9] = x[9];
88
- values[16 * i + 10] = x[10];
89
- values[16 * i + 11] = x[11];
90
- values[16 * i + 12] = x[12];
91
- values[16 * i + 13] = x[13];
92
- values[16 * i + 14] = x[14];
93
- values[16 * i + 15] = x[15];
94
- }
95
- };
96
- function createTypedArrayFromAccessor(tile3DAccessor, buffer, byteOffset, length) {
97
- const { componentType } = tile3DAccessor;
98
- (0, loader_utils_1.assert)(tile3DAccessor.componentType);
99
- const type = typeof componentType === 'string' ? math_1.GLType.fromName(componentType) : componentType;
100
- const size = COMPONENTS_PER_ATTRIBUTE[tile3DAccessor.type];
101
- const unpacker = UNPACKER[tile3DAccessor.type];
102
- const packer = PACKER[tile3DAccessor.type];
103
- byteOffset += tile3DAccessor.byteOffset;
104
- const values = math_1.GLType.createTypedArray(type, buffer, byteOffset, size * length);
105
- return {
106
- values,
107
- type,
108
- size,
109
- unpacker,
110
- packer
111
- };
112
- }
113
- exports.createTypedArrayFromAccessor = createTypedArrayFromAccessor;