@loaders.gl/3d-tiles 4.0.0-alpha.6 → 4.0.0-alpha.7

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 (57) hide show
  1. package/dist/dist.min.js +1462 -1354
  2. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js +7 -5
  3. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
  4. package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -1
  5. package/dist/es5/lib/parsers/parse-3d-tile-composite.js +4 -4
  6. package/dist/es5/lib/parsers/parse-3d-tile-composite.js.map +1 -1
  7. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +5 -3
  8. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
  9. package/dist/es5/lib/parsers/parse-3d-tile-header.js +1 -1
  10. package/dist/es5/lib/parsers/parse-3d-tile-header.js.map +1 -1
  11. package/dist/es5/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -1
  12. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
  13. package/dist/es5/lib/utils/version.js +1 -1
  14. package/dist/es5/tiles-3d-loader.js +60 -56
  15. package/dist/es5/tiles-3d-loader.js.map +1 -1
  16. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js +4 -2
  17. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
  18. package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -1
  19. package/dist/esm/lib/parsers/parse-3d-tile-composite.js.map +1 -1
  20. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js +4 -2
  21. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
  22. package/dist/esm/lib/parsers/parse-3d-tile-header.js +1 -1
  23. package/dist/esm/lib/parsers/parse-3d-tile-header.js.map +1 -1
  24. package/dist/esm/lib/parsers/parse-3d-tile-instanced-model.js.map +1 -1
  25. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
  26. package/dist/esm/lib/utils/version.js +1 -1
  27. package/dist/esm/tiles-3d-loader.js +26 -28
  28. package/dist/esm/tiles-3d-loader.js.map +1 -1
  29. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  30. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +3 -1
  31. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +1 -1
  32. package/dist/lib/parsers/parse-3d-tile-composite.d.ts +6 -1
  33. package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
  34. package/dist/lib/parsers/parse-3d-tile-composite.js +0 -2
  35. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +3 -1
  36. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  37. package/dist/lib/parsers/parse-3d-tile-gltf.js +3 -1
  38. package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -1
  39. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  40. package/dist/lib/parsers/parse-3d-tile-header.js +1 -1
  41. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +3 -1
  42. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
  43. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +4 -2
  44. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  45. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +1 -0
  46. package/dist/tiles-3d-loader.d.ts +15 -1
  47. package/dist/tiles-3d-loader.d.ts.map +1 -1
  48. package/dist/tiles-3d-loader.js +34 -32
  49. package/package.json +8 -8
  50. package/src/lib/parsers/helpers/parse-3d-tile-gltf-view.ts +4 -2
  51. package/src/lib/parsers/helpers/parse-3d-tile-subtree.ts +1 -1
  52. package/src/lib/parsers/parse-3d-tile-composite.ts +17 -6
  53. package/src/lib/parsers/parse-3d-tile-gltf.ts +12 -3
  54. package/src/lib/parsers/parse-3d-tile-header.ts +3 -2
  55. package/src/lib/parsers/parse-3d-tile-instanced-model.ts +17 -3
  56. package/src/lib/parsers/parse-3d-tile-point-cloud.ts +37 -10
  57. package/src/tiles-3d-loader.ts +65 -33
@@ -1,4 +1,18 @@
1
- import type { LoaderWithParser } from '@loaders.gl/loader-utils';
1
+ import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
2
+ import type { DracoLoaderOptions } from '@loaders.gl/draco';
3
+ import type { ImageLoaderOptions } from '@loaders.gl/images';
4
+ export type Tiles3DLoaderOptions = LoaderOptions & DracoLoaderOptions & ImageLoaderOptions & {
5
+ '3d-tiles'?: {
6
+ /** Whether to parse any embedded glTF binaries (or extract memory for independent glTF parsing) */
7
+ loadGLTF?: boolean;
8
+ /** If renderer doesn't support quantized positions, loader can decode them on CPU */
9
+ decodeQuantizedPositions?: boolean;
10
+ /** Whether this is a tileset or a tile */
11
+ isTileset?: boolean | 'auto';
12
+ /** Controls which axis is "up" in glTF files */
13
+ assetGltfUpAxis?: 'x' | 'y' | 'z' | null;
14
+ };
15
+ };
2
16
  /**
3
17
  * Loader for 3D Tiles
4
18
  */
@@ -1 +1 @@
1
- {"version":3,"file":"tiles-3d-loader.d.ts","sourceRoot":"","sources":["../src/tiles-3d-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAO/D;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,gBAiB3B,CAAC"}
1
+ {"version":3,"file":"tiles-3d-loader.d.ts","sourceRoot":"","sources":["../src/tiles-3d-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAgB,MAAM,0BAA0B,CAAC;AAE7F,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAQ3D,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAE9C,kBAAkB,GAClB,kBAAkB,GAAG;IACnB,UAAU,CAAC,EAAE;QACX,mGAAmG;QACnG,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,qFAAqF;QACrF,wBAAwB,CAAC,EAAE,OAAO,CAAC;QACnC,0CAA0C;QAC1C,SAAS,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;QAC7B,gDAAgD;QAChD,eAAe,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;KAC1C,CAAC;CACH,CAAC;AAEJ;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,gBAiB3B,CAAC"}
@@ -27,47 +27,49 @@ exports.Tiles3DLoader = {
27
27
  }
28
28
  }
29
29
  };
30
- function getBaseUri(tileset) {
31
- return loader_utils_1.path.dirname(tileset.url);
32
- }
33
- async function parseTile(arrayBuffer, options, context) {
34
- const tile = {
35
- content: {
36
- featureIds: null
37
- }
38
- };
39
- const byteOffset = 0;
40
- await (0, parse_3d_tile_1.parse3DTile)(arrayBuffer, byteOffset, options, context, tile.content);
41
- return tile.content;
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 (await isTileset)
42
+ ? parseTileset(data, options, context)
43
+ : parseTile(data, options, context);
42
44
  }
45
+ /** Parse a tileset */
43
46
  async function parseTileset(data, options, context) {
44
47
  const tilesetJson = JSON.parse(new TextDecoder().decode(data));
45
48
  // eslint-disable-next-line no-use-before-define
46
- tilesetJson.loader = options.loader || exports.Tiles3DLoader;
47
- tilesetJson.url = context.url;
49
+ tilesetJson.loader = options?.loader || exports.Tiles3DLoader;
50
+ tilesetJson.url = context?.url || '';
51
+ tilesetJson.queryString = context?.queryString || '';
48
52
  // base path that non-absolute paths in tileset are relative to.
49
53
  tilesetJson.basePath = getBaseUri(tilesetJson);
50
- tilesetJson.root = await (0, parse_3d_tile_header_1.normalizeTileHeaders)(tilesetJson, options);
54
+ // TODO - check option types in normalizeTileHeaders
55
+ tilesetJson.root = await (0, parse_3d_tile_header_1.normalizeTileHeaders)(tilesetJson, options || {});
51
56
  tilesetJson.type = tiles_1.TILESET_TYPE.TILES3D;
52
57
  tilesetJson.lodMetricType = tiles_1.LOD_METRIC_TYPE.GEOMETRIC_ERROR;
53
58
  tilesetJson.lodMetricValue = tilesetJson.root?.lodMetricValue || 0;
54
59
  return tilesetJson;
55
60
  }
56
- async function parse(data, options, context) {
57
- // auto detect file type
58
- const loaderOptions = options['3d-tiles'] || {};
59
- let isTileset;
60
- if (loaderOptions.isTileset === 'auto') {
61
- isTileset = context.url && context.url.indexOf('.json') !== -1;
62
- }
63
- else {
64
- isTileset = loaderOptions.isTileset;
65
- }
66
- if (isTileset) {
67
- data = await parseTileset(data, options, context);
68
- }
69
- else {
70
- data = await parseTile(data, options, context);
71
- }
72
- return data;
61
+ /** Parse a tile */
62
+ async function parseTile(arrayBuffer, options, context) {
63
+ const tile = {
64
+ content: {
65
+ featureIds: null
66
+ }
67
+ };
68
+ const byteOffset = 0;
69
+ await (0, parse_3d_tile_1.parse3DTile)(arrayBuffer, byteOffset, options, context, tile.content);
70
+ return tile.content;
71
+ }
72
+ /** Get base name */
73
+ function getBaseUri(tileset) {
74
+ return loader_utils_1.path.dirname(tileset.url);
73
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/3d-tiles",
3
- "version": "4.0.0-alpha.6",
3
+ "version": "4.0.0-alpha.7",
4
4
  "description": "3D Tiles, an open standard for streaming massive heterogeneous 3D geospatial datasets.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -34,17 +34,17 @@
34
34
  "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js"
35
35
  },
36
36
  "dependencies": {
37
- "@loaders.gl/draco": "4.0.0-alpha.6",
38
- "@loaders.gl/gltf": "4.0.0-alpha.6",
39
- "@loaders.gl/loader-utils": "4.0.0-alpha.6",
40
- "@loaders.gl/math": "4.0.0-alpha.6",
41
- "@loaders.gl/tiles": "4.0.0-alpha.6",
37
+ "@loaders.gl/draco": "4.0.0-alpha.7",
38
+ "@loaders.gl/gltf": "4.0.0-alpha.7",
39
+ "@loaders.gl/loader-utils": "4.0.0-alpha.7",
40
+ "@loaders.gl/math": "4.0.0-alpha.7",
41
+ "@loaders.gl/tiles": "4.0.0-alpha.7",
42
42
  "@math.gl/core": "^3.5.1",
43
43
  "@math.gl/geospatial": "^3.5.1",
44
44
  "long": "^5.2.1"
45
45
  },
46
46
  "peerDependencies": {
47
- "@loaders.gl/core": "4.0.0-alpha.5"
47
+ "@loaders.gl/core": "4.0.0-alpha.6"
48
48
  },
49
- "gitHead": "acc1985050dfaa0f1f0c066f8da5bce7454a046c"
49
+ "gitHead": "afb59c4d8e5d8ebb9c28f111cb0c96c5527d0ffd"
50
50
  }
@@ -7,7 +7,7 @@
7
7
  // - Do we add an option to control this?
8
8
  // - Also, should we have hard dependency on gltf module or use injection or auto-discovery for gltf parser?
9
9
 
10
- import {GLTFLoader} from '@loaders.gl/gltf';
10
+ import {GLTFLoader, postProcessGLTF, _getMemoryUsageGLTF} from '@loaders.gl/gltf';
11
11
  import {sliceArrayBuffer} from '@loaders.gl/loader-utils';
12
12
 
13
13
  export const GLTF_FORMAT = {
@@ -66,7 +66,9 @@ export async function extractGLTF(tile, gltfFormat, options, context) {
66
66
  }
67
67
  if (tile.gltfArrayBuffer) {
68
68
  // TODO - Should handle byteOffset... However, not used now...
69
- tile.gltf = await parse(tile.gltfArrayBuffer, GLTFLoader, options, context);
69
+ const gltfWithBuffers = await parse(tile.gltfArrayBuffer, GLTFLoader, options, context);
70
+ tile.gltf = postProcessGLTF(gltfWithBuffers);
71
+ tile.gpuMemoryUsageInBytes = _getMemoryUsageGLTF(tile.gltf);
70
72
  delete tile.gltfArrayBuffer;
71
73
  delete tile.gltfByteOffset;
72
74
  delete tile.gltfByteLength;
@@ -75,7 +75,7 @@ export default async function parse3DTilesSubtree(
75
75
  /**
76
76
  * Get url for bitstream downloading
77
77
  * @param bitstreamRelativeUri
78
- * @param baseUri
78
+ * @param basePath
79
79
  * @returns
80
80
  */
81
81
  function resolveBufferUri(bitstreamRelativeUri: string, basePath: string): string {
@@ -4,17 +4,28 @@
4
4
  // Reference code:
5
5
  // https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/Composite3DTileContent.js#L182
6
6
 
7
+ import type {LoaderContext} from '@loaders.gl/loader-utils';
8
+ import type {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
7
9
  import {parse3DTileHeaderSync} from './helpers/parse-3d-tile-header';
8
10
 
11
+ /** Resolve circulate dependency by passing in parsing function as argument */
12
+ type Parse3DTile = (
13
+ arrayBuffer: ArrayBuffer,
14
+ byteOffset: number,
15
+ options: Tiles3DLoaderOptions,
16
+ context: LoaderContext,
17
+ subtile
18
+ ) => Promise<number>;
19
+
9
20
  // eslint-disable-next-line max-params
10
21
  export async function parseComposite3DTile(
11
22
  tile,
12
- arrayBuffer,
13
- byteOffset,
14
- options,
15
- context,
16
- parse3DTile
17
- ) {
23
+ arrayBuffer: ArrayBuffer,
24
+ byteOffset: number,
25
+ options: Tiles3DLoaderOptions,
26
+ context: LoaderContext,
27
+ parse3DTile: Parse3DTile
28
+ ): Promise<number> {
18
29
  byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
19
30
 
20
31
  const view = new DataView(arrayBuffer);
@@ -1,6 +1,13 @@
1
- import {GLTFLoader} from '@loaders.gl/gltf';
1
+ import type {LoaderContext} from '@loaders.gl/loader-utils';
2
+ import type {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
3
+ import {_getMemoryUsageGLTF, GLTFLoader, postProcessGLTF} from '@loaders.gl/gltf';
2
4
 
3
- export async function parseGltf3DTile(tile, arrayBuffer, options, context) {
5
+ export async function parseGltf3DTile(
6
+ tile,
7
+ arrayBuffer: ArrayBuffer,
8
+ options: Tiles3DLoaderOptions,
9
+ context: LoaderContext
10
+ ): Promise<void> {
4
11
  // Set flags
5
12
  // glTF models need to be rotated from Y to Z up
6
13
  // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
@@ -12,5 +19,7 @@ export async function parseGltf3DTile(tile, arrayBuffer, options, context) {
12
19
  : 'Y';
13
20
 
14
21
  const {parse} = context;
15
- tile.gltf = await parse(arrayBuffer, GLTFLoader, options, context);
22
+ const gltfWithBuffers = await parse(arrayBuffer, GLTFLoader, options, context);
23
+ tile.gltf = postProcessGLTF(gltfWithBuffers);
24
+ tile.gpuMemoryUsageInBytes = _getMemoryUsageGLTF(tile.gltf);
16
25
  }
@@ -1,3 +1,4 @@
1
+ import type {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
1
2
  import type {LoaderOptions} from '@loaders.gl/loader-utils';
2
3
  import {Tile3DSubtreeLoader} from '../../tile-3d-subtree-loader';
3
4
  import {load} from '@loaders.gl/core';
@@ -13,7 +14,7 @@ function getTileType(tile) {
13
14
  return TILE_TYPE.EMPTY;
14
15
  }
15
16
 
16
- const contentUrl = tile.contentUrl;
17
+ const contentUrl = tile.contentUrl.split('?')[0]; // Discard query string
17
18
  const fileExtension = contentUrl.split('.').pop();
18
19
  switch (fileExtension) {
19
20
  case 'pnts':
@@ -128,7 +129,7 @@ export async function normalizeImplicitTileHeaders(
128
129
  tile: Tile3D,
129
130
  tileset: Tileset3D,
130
131
  implicitTilingExtension: ImplicitTilingExtension,
131
- options: LoaderOptions
132
+ options: Tiles3DLoaderOptions
132
133
  ) {
133
134
  const basePath = tileset.basePath;
134
135
  const {
@@ -10,14 +10,28 @@ import Tile3DBatchTable from '../classes/tile-3d-batch-table';
10
10
  import {parse3DTileHeaderSync} from './helpers/parse-3d-tile-header';
11
11
  import {parse3DTileTablesHeaderSync, parse3DTileTablesSync} from './helpers/parse-3d-tile-tables';
12
12
  import {parse3DTileGLTFViewSync, extractGLTF} from './helpers/parse-3d-tile-gltf-view';
13
-
14
- export async function parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
13
+ import {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
14
+ import {LoaderContext} from '@loaders.gl/loader-utils';
15
+
16
+ export async function parseInstancedModel3DTile(
17
+ tile,
18
+ arrayBuffer: ArrayBuffer,
19
+ byteOffset: number,
20
+ options: Tiles3DLoaderOptions,
21
+ context: LoaderContext
22
+ ): Promise<number> {
15
23
  byteOffset = parseInstancedModel(tile, arrayBuffer, byteOffset, options, context);
16
24
  await extractGLTF(tile, tile.gltfFormat, options, context);
17
25
  return byteOffset;
18
26
  }
19
27
 
20
- function parseInstancedModel(tile, arrayBuffer, byteOffset, options, context) {
28
+ function parseInstancedModel(
29
+ tile,
30
+ arrayBuffer: ArrayBuffer,
31
+ byteOffset: number,
32
+ options: Tiles3DLoaderOptions,
33
+ context: LoaderContext
34
+ ): number {
21
35
  byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
22
36
  if (tile.version !== 1) {
23
37
  throw new Error(`Instanced 3D Model version ${tile.version} is not supported`);
@@ -12,8 +12,16 @@ import {parse3DTileTablesHeaderSync, parse3DTileTablesSync} from './helpers/pars
12
12
  import {normalize3DTileColorAttribute} from './helpers/normalize-3d-tile-colors';
13
13
  import {normalize3DTileNormalAttribute} from './helpers/normalize-3d-tile-normals';
14
14
  import {normalize3DTilePositionAttribute} from './helpers/normalize-3d-tile-positions';
15
-
16
- export async function parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context) {
15
+ import {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
16
+ import {LoaderContext} from '@loaders.gl/loader-utils';
17
+
18
+ export async function parsePointCloud3DTile(
19
+ tile,
20
+ arrayBuffer: ArrayBuffer,
21
+ byteOffset: number,
22
+ options: Tiles3DLoaderOptions,
23
+ context: LoaderContext
24
+ ): Promise<number> {
17
25
  byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
18
26
  byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
19
27
  byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options);
@@ -24,13 +32,14 @@ export async function parsePointCloud3DTile(tile, arrayBuffer, byteOffset, optio
24
32
  await parseDraco(tile, featureTable, batchTable, options, context);
25
33
 
26
34
  parsePositions(tile, featureTable, options);
35
+ // @ts-expect-error TODO - do we need to assert on the batch table?
27
36
  parseColors(tile, featureTable, batchTable);
28
37
  parseNormals(tile, featureTable);
29
38
 
30
39
  return byteOffset;
31
40
  }
32
41
 
33
- function initializeTile(tile) {
42
+ function initializeTile(tile): void {
34
43
  // Initialize point cloud tile defaults
35
44
  tile.attributes = {
36
45
  positions: null,
@@ -44,7 +53,10 @@ function initializeTile(tile) {
44
53
  tile.isOctEncoded16P = false;
45
54
  }
46
55
 
47
- function parsePointCloudTables(tile) {
56
+ function parsePointCloudTables(tile): {
57
+ featureTable: Tile3DFeatureTable;
58
+ batchTable: Tile3DBatchTable | null;
59
+ } {
48
60
  const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
49
61
 
50
62
  const pointsLength = featureTable.getGlobalProperty('POINTS_LENGTH');
@@ -64,7 +76,11 @@ function parsePointCloudTables(tile) {
64
76
  return {featureTable, batchTable};
65
77
  }
66
78
 
67
- function parsePositions(tile, featureTable, options) {
79
+ function parsePositions(
80
+ tile,
81
+ featureTable: Tile3DFeatureTable,
82
+ options: Tiles3DLoaderOptions
83
+ ): void {
68
84
  if (!tile.attributes.positions) {
69
85
  if (featureTable.hasProperty('POSITION')) {
70
86
  tile.attributes.positions = featureTable.getPropertyArray('POSITION', GL.FLOAT, 3);
@@ -101,7 +117,7 @@ function parsePositions(tile, featureTable, options) {
101
117
  }
102
118
  }
103
119
 
104
- function parseColors(tile, featureTable, batchTable) {
120
+ function parseColors(tile, featureTable: Tile3DFeatureTable, batchTable: Tile3DBatchTable): void {
105
121
  if (!tile.attributes.colors) {
106
122
  let colors = null;
107
123
  if (featureTable.hasProperty('RGBA')) {
@@ -122,7 +138,7 @@ function parseColors(tile, featureTable, batchTable) {
122
138
  }
123
139
  }
124
140
 
125
- function parseNormals(tile, featureTable) {
141
+ function parseNormals(tile, featureTable: Tile3DFeatureTable): void {
126
142
  if (!tile.attributes.normals) {
127
143
  let normals = null;
128
144
  if (featureTable.hasProperty('NORMAL')) {
@@ -136,7 +152,7 @@ function parseNormals(tile, featureTable) {
136
152
  }
137
153
  }
138
154
 
139
- function parseBatchIds(tile, featureTable) {
155
+ function parseBatchIds(tile, featureTable: Tile3DFeatureTable): Tile3DBatchTable | null {
140
156
  let batchTable: Tile3DBatchTable | null = null;
141
157
  if (!tile.batchIds && featureTable.hasProperty('BATCH_ID')) {
142
158
  tile.batchIds = featureTable.getPropertyArray('BATCH_ID', GL.UNSIGNED_SHORT, 1);
@@ -154,7 +170,13 @@ function parseBatchIds(tile, featureTable) {
154
170
  }
155
171
 
156
172
  // eslint-disable-next-line complexity
157
- async function parseDraco(tile, featureTable, batchTable, options, context) {
173
+ async function parseDraco(
174
+ tile,
175
+ featureTable: Tile3DFeatureTable,
176
+ batchTable,
177
+ options: Tiles3DLoaderOptions,
178
+ context: LoaderContext
179
+ ) {
158
180
  let dracoBuffer;
159
181
  let dracoFeatureTableProperties;
160
182
  let dracoBatchTableProperties;
@@ -202,7 +224,12 @@ async function parseDraco(tile, featureTable, batchTable, options, context) {
202
224
  }
203
225
 
204
226
  // eslint-disable-next-line complexity, max-statements
205
- export async function loadDraco(tile, dracoData, options, context) {
227
+ export async function loadDraco(
228
+ tile,
229
+ dracoData,
230
+ options: Tiles3DLoaderOptions,
231
+ context: LoaderContext
232
+ ) {
206
233
  const {parse} = context;
207
234
  const dracoOptions = {
208
235
  ...options,
@@ -1,10 +1,30 @@
1
- import type {LoaderWithParser} from '@loaders.gl/loader-utils';
1
+ import type {LoaderWithParser, LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
2
+ // / import type { GLTFLoaderOptions } from '@loaders.gl/gltf';
3
+ import type {DracoLoaderOptions} from '@loaders.gl/draco';
4
+ import type {ImageLoaderOptions} from '@loaders.gl/images';
5
+
2
6
  import {path} from '@loaders.gl/loader-utils';
3
7
  import {TILESET_TYPE, LOD_METRIC_TYPE} from '@loaders.gl/tiles';
4
8
  import {VERSION} from './lib/utils/version';
5
9
  import {parse3DTile} from './lib/parsers/parse-3d-tile';
6
10
  import {normalizeTileHeaders} from './lib/parsers/parse-3d-tile-header';
7
11
 
12
+ export type Tiles3DLoaderOptions = LoaderOptions &
13
+ // GLTFLoaderOptions & - TODO not yet exported
14
+ DracoLoaderOptions &
15
+ ImageLoaderOptions & {
16
+ '3d-tiles'?: {
17
+ /** Whether to parse any embedded glTF binaries (or extract memory for independent glTF parsing) */
18
+ loadGLTF?: boolean;
19
+ /** If renderer doesn't support quantized positions, loader can decode them on CPU */
20
+ decodeQuantizedPositions?: boolean;
21
+ /** Whether this is a tileset or a tile */
22
+ isTileset?: boolean | 'auto';
23
+ /** Controls which axis is "up" in glTF files */
24
+ assetGltfUpAxis?: 'x' | 'y' | 'z' | null;
25
+ };
26
+ };
27
+
8
28
  /**
9
29
  * Loader for 3D Tiles
10
30
  */
@@ -27,29 +47,39 @@ export const Tiles3DLoader: LoaderWithParser = {
27
47
  }
28
48
  };
29
49
 
30
- function getBaseUri(tileset) {
31
- return path.dirname(tileset.url);
32
- }
50
+ /** Parses a tileset or tile */
51
+ async function parse(data, options: Tiles3DLoaderOptions = {}, context?: LoaderContext) {
52
+ // auto detect file type
53
+ const loaderOptions = options['3d-tiles'] || {};
54
+ let isTileset;
55
+ if (loaderOptions.isTileset === 'auto') {
56
+ isTileset = context?.url && context.url.indexOf('.json') !== -1;
57
+ } else {
58
+ isTileset = loaderOptions.isTileset;
59
+ }
33
60
 
34
- async function parseTile(arrayBuffer, options, context) {
35
- const tile = {
36
- content: {
37
- featureIds: null
38
- }
39
- };
40
- const byteOffset = 0;
41
- await parse3DTile(arrayBuffer, byteOffset, options, context, tile.content);
42
- return tile.content;
61
+ return (await isTileset)
62
+ ? parseTileset(data, options, context)
63
+ : parseTile(data, options, context);
43
64
  }
44
65
 
45
- async function parseTileset(data, options, context) {
66
+ /** Parse a tileset */
67
+ async function parseTileset(
68
+ data: ArrayBuffer,
69
+ options?: Tiles3DLoaderOptions,
70
+ context?: LoaderContext
71
+ ) {
46
72
  const tilesetJson = JSON.parse(new TextDecoder().decode(data));
73
+
47
74
  // eslint-disable-next-line no-use-before-define
48
- tilesetJson.loader = options.loader || Tiles3DLoader;
49
- tilesetJson.url = context.url;
75
+ tilesetJson.loader = options?.loader || Tiles3DLoader;
76
+ tilesetJson.url = context?.url || '';
77
+ tilesetJson.queryString = context?.queryString || '';
78
+
50
79
  // base path that non-absolute paths in tileset are relative to.
51
80
  tilesetJson.basePath = getBaseUri(tilesetJson);
52
- tilesetJson.root = await normalizeTileHeaders(tilesetJson, options);
81
+ // TODO - check option types in normalizeTileHeaders
82
+ tilesetJson.root = await normalizeTileHeaders(tilesetJson, options || {});
53
83
 
54
84
  tilesetJson.type = TILESET_TYPE.TILES3D;
55
85
 
@@ -59,21 +89,23 @@ async function parseTileset(data, options, context) {
59
89
  return tilesetJson;
60
90
  }
61
91
 
62
- async function parse(data, options, context) {
63
- // auto detect file type
64
- const loaderOptions = options['3d-tiles'] || {};
65
- let isTileset;
66
- if (loaderOptions.isTileset === 'auto') {
67
- isTileset = context.url && context.url.indexOf('.json') !== -1;
68
- } else {
69
- isTileset = loaderOptions.isTileset;
70
- }
71
-
72
- if (isTileset) {
73
- data = await parseTileset(data, options, context);
74
- } else {
75
- data = await parseTile(data, options, context);
76
- }
92
+ /** Parse a tile */
93
+ async function parseTile(
94
+ arrayBuffer: ArrayBuffer,
95
+ options?: Tiles3DLoaderOptions,
96
+ context?: LoaderContext
97
+ ) {
98
+ const tile = {
99
+ content: {
100
+ featureIds: null
101
+ }
102
+ };
103
+ const byteOffset = 0;
104
+ await parse3DTile(arrayBuffer, byteOffset, options, context, tile.content);
105
+ return tile.content;
106
+ }
77
107
 
78
- return data;
108
+ /** Get base name */
109
+ function getBaseUri(tileset) {
110
+ return path.dirname(tileset.url);
79
111
  }