@loaders.gl/3d-tiles 4.0.0-alpha.20 → 4.0.0-alpha.22

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 (74) hide show
  1. package/dist/3d-tiles-archive/3d-tiles-archive-archive.d.ts +29 -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-archive.js +72 -0
  4. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +10 -0
  5. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -0
  6. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +33 -0
  7. package/dist/3d-tiles-archive-loader.d.ts +13 -0
  8. package/dist/3d-tiles-archive-loader.d.ts.map +1 -0
  9. package/dist/3d-tiles-archive-loader.js +31 -0
  10. package/dist/dist.min.js +5429 -215
  11. package/dist/es5/3d-tiles-archive/3d-tiles-archive-archive.js +126 -0
  12. package/dist/es5/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -0
  13. package/dist/es5/3d-tiles-archive/3d-tiles-archive-parser.js +69 -0
  14. package/dist/es5/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -0
  15. package/dist/es5/3d-tiles-archive-loader.js +50 -0
  16. package/dist/es5/3d-tiles-archive-loader.js.map +1 -0
  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/parsers/helpers/parse-3d-tile-gltf-view.js +3 -3
  22. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
  23. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +12 -12
  24. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
  25. package/dist/es5/lib/parsers/parse-3d-tile-header.js +2 -1
  26. package/dist/es5/lib/parsers/parse-3d-tile-header.js.map +1 -1
  27. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js +6 -6
  28. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
  29. package/dist/es5/lib/utils/version.js +1 -1
  30. package/dist/esm/3d-tiles-archive/3d-tiles-archive-archive.js +46 -0
  31. package/dist/esm/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -0
  32. package/dist/esm/3d-tiles-archive/3d-tiles-archive-parser.js +23 -0
  33. package/dist/esm/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -0
  34. package/dist/esm/3d-tiles-archive-loader.js +20 -0
  35. package/dist/esm/3d-tiles-archive-loader.js.map +1 -0
  36. package/dist/esm/index.js +2 -0
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/lib/filesystems/tiles-3d-archive-file-system.js +49 -0
  39. package/dist/esm/lib/filesystems/tiles-3d-archive-file-system.js.map +1 -0
  40. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js +5 -6
  41. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
  42. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js +5 -7
  43. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
  44. package/dist/esm/lib/parsers/parse-3d-tile-header.js +2 -1
  45. package/dist/esm/lib/parsers/parse-3d-tile-header.js.map +1 -1
  46. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js +2 -4
  47. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
  48. package/dist/esm/lib/utils/version.js +1 -1
  49. package/dist/index.d.ts +3 -0
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +5 -1
  52. package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts +31 -0
  53. package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts.map +1 -0
  54. package/dist/lib/filesystems/tiles-3d-archive-file-system.js +75 -0
  55. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  56. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +2 -2
  57. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +1 -1
  58. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  59. package/dist/lib/parsers/parse-3d-tile-gltf.js +6 -6
  60. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  61. package/dist/lib/parsers/parse-3d-tile-header.js +2 -1
  62. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +1 -1
  63. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  64. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +10 -2
  65. package/package.json +8 -7
  66. package/src/3d-tiles-archive/3d-tiles-archive-archive.ts +84 -0
  67. package/src/3d-tiles-archive/3d-tiles-archive-parser.ts +52 -0
  68. package/src/3d-tiles-archive-loader.ts +47 -0
  69. package/src/index.ts +3 -0
  70. package/src/lib/filesystems/tiles-3d-archive-file-system.ts +97 -0
  71. package/src/lib/parsers/helpers/parse-3d-tile-gltf-view.ts +8 -3
  72. package/src/lib/parsers/parse-3d-tile-gltf.ts +8 -8
  73. package/src/lib/parsers/parse-3d-tile-header.ts +2 -1
  74. package/src/lib/parsers/parse-3d-tile-point-cloud.ts +10 -3
@@ -1 +1 @@
1
- {"version":3,"file":"parse-3d-tile-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile-gltf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAAC,kBAAkB,EAAC,MAAM,aAAa,CAAC;AAE/C,wBAAsB,eAAe,CACnC,IAAI,EAAE,kBAAkB,EACxB,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,oBAAoB,EAC9B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,IAAI,CAAC,CAsBf"}
1
+ {"version":3,"file":"parse-3d-tile-gltf.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile-gltf.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAEzE,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAC,kBAAkB,EAAC,MAAM,aAAa,CAAC;AAE/C,wBAAsB,eAAe,CACnC,IAAI,EAAE,kBAAkB,EACxB,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,oBAAoB,EAC9B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,IAAI,CAAC,CAoBf"}
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
+ // loaders.gl, MIT license
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.parseGltf3DTile = void 0;
5
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
4
6
  const gltf_1 = require("@loaders.gl/gltf");
5
7
  async function parseGltf3DTile(tile, arrayBuffer, options, context) {
6
8
  // Set flags
@@ -8,16 +10,14 @@ async function parseGltf3DTile(tile, arrayBuffer, options, context) {
8
10
  // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
9
11
  tile.rotateYtoZ = true;
10
12
  // Save gltf up axis
11
- tile.gltfUpAxis =
12
- options?.['3d-tiles'] && options['3d-tiles'].assetGltfUpAxis
13
- ? options['3d-tiles'].assetGltfUpAxis
14
- : 'Y';
13
+ tile.gltfUpAxis = options?.['3d-tiles']?.assetGltfUpAxis
14
+ ? options['3d-tiles'].assetGltfUpAxis
15
+ : 'Y';
15
16
  if (options?.['3d-tiles']?.loadGLTF) {
16
17
  if (!context) {
17
18
  return;
18
19
  }
19
- const { parse } = context;
20
- const gltfWithBuffers = await parse(arrayBuffer, gltf_1.GLTFLoader, options, context);
20
+ const gltfWithBuffers = await (0, loader_utils_1.parseFromContext)(arrayBuffer, gltf_1.GLTFLoader, options, context);
21
21
  tile.gltf = (0, gltf_1.postProcessGLTF)(gltfWithBuffers);
22
22
  tile.gpuMemoryUsageInBytes = (0, gltf_1._getMemoryUsageGLTF)(tile.gltf);
23
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"parse-3d-tile-header.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile-header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAG5D,OAAO,EAAC,eAAe,EAAE,eAAe,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EACL,0BAA0B,EAC1B,OAAO,EACP,oBAAoB,EAEpB,eAAe,EACf,4BAA4B,EAC5B,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAMrB,sDAAsD;AACtD,MAAM,MAAM,eAAe,GAAG;IAC5B,uDAAuD;IACvD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,+CAA+C;IAC/C,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kCAAkC;IAClC,iBAAiB,EAAE,UAAU,GAAG,QAAQ,GAAG,MAAM,CAAC;IAClD,yBAAyB;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wBAAwB;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,aAAa,EAAE,eAAe,CAAC,eAAe,CAAC;IAC/C,kEAAkE;IAClE,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gEAAgE;IAChE,kBAAkB,EAAE,oBAAoB,CAAC;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B,CAChD,IAAI,EAAE,eAAe,EACrB,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,EAAE,MAAM,EAChB,uBAAuB,EAAE,0BAA0B,EACnD,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC,CA0C9C;AAED;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,eAAe,EACrB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,OAAO,EACpB,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,oBAAoB,GAClC,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC,CA+B9C"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeImplicitTileData = exports.normalizeImplicitTileHeaders = exports.normalizeTileHeaders = exports.normalizeTileData = void 0;
4
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
4
5
  const tile_3d_subtree_loader_1 = require("../../tile-3d-subtree-loader");
5
6
  const core_1 = require("@loaders.gl/core");
6
7
  const tiles_1 = require("@loaders.gl/tiles");
@@ -46,7 +47,7 @@ function resolveUri(uri = '', basePath) {
46
47
  else if (uri.startsWith('/')) {
47
48
  return uri;
48
49
  }
49
- return `${basePath}/${uri}`;
50
+ return loader_utils_1.path.resolve(basePath, uri);
50
51
  }
51
52
  function normalizeTileData(tile, basePath) {
52
53
  if (!tile) {
@@ -1,5 +1,5 @@
1
- import { Tiles3DLoaderOptions } from '../../tiles-3d-loader';
2
1
  import { LoaderContext } from '@loaders.gl/loader-utils';
2
+ import { Tiles3DLoaderOptions } from '../../tiles-3d-loader';
3
3
  import { Tiles3DTileContent } from '../../types';
4
4
  export declare function parsePointCloud3DTile(tile: Tiles3DTileContent, arrayBuffer: ArrayBuffer, byteOffset: number, options?: Tiles3DLoaderOptions, context?: LoaderContext): Promise<number>;
5
5
  export declare function loadDraco(tile: Tiles3DTileContent, dracoData: any, options?: Tiles3DLoaderOptions, context?: LoaderContext): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"parse-3d-tile-point-cloud.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile-point-cloud.ts"],"names":[],"mappings":"AAcA,OAAO,EAAC,oBAAoB,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAC,kBAAkB,EAAC,MAAM,aAAa,CAAC;AAE/C,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,kBAAkB,EACxB,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,oBAAoB,EAC9B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAuND,wBAAsB,SAAS,CAC7B,IAAI,EAAE,kBAAkB,EACxB,SAAS,KAAA,EACT,OAAO,CAAC,EAAE,oBAAoB,EAC9B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,IAAI,CAAC,CAwDf"}
1
+ {"version":3,"file":"parse-3d-tile-point-cloud.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-3d-tile-point-cloud.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,aAAa,EAAmB,MAAM,0BAA0B,CAAC;AAWzE,OAAO,EAAC,oBAAoB,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAC,kBAAkB,EAAC,MAAM,aAAa,CAAC;AAE/C,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,kBAAkB,EACxB,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,oBAAoB,EAC9B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAuND,wBAAsB,SAAS,CAC7B,IAAI,EAAE,kBAAkB,EACxB,SAAS,KAAA,EACT,OAAO,CAAC,EAAE,oBAAoB,EAC9B,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,IAAI,CAAC,CA+Df"}
@@ -7,6 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.loadDraco = exports.parsePointCloud3DTile = void 0;
9
9
  const draco_1 = require("@loaders.gl/draco");
10
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
10
11
  const math_1 = require("@loaders.gl/math");
11
12
  const core_1 = require("@math.gl/core");
12
13
  const tile_3d_feature_table_1 = __importDefault(require("../classes/tile-3d-feature-table"));
@@ -192,7 +193,6 @@ async function loadDraco(tile, dracoData, options, context) {
192
193
  if (!context) {
193
194
  return;
194
195
  }
195
- const { parse } = context;
196
196
  const dracoOptions = {
197
197
  ...options,
198
198
  draco: {
@@ -202,16 +202,19 @@ async function loadDraco(tile, dracoData, options, context) {
202
202
  };
203
203
  // The entire tileset might be included, too expensive to serialize
204
204
  delete dracoOptions['3d-tiles'];
205
- const data = await parse(dracoData.buffer, draco_1.DracoLoader, dracoOptions);
205
+ const data = await (0, loader_utils_1.parseFromContext)(dracoData.buffer, draco_1.DracoLoader, dracoOptions, context);
206
206
  const decodedPositions = data.attributes.POSITION && data.attributes.POSITION.value;
207
207
  const decodedColors = data.attributes.COLOR_0 && data.attributes.COLOR_0.value;
208
208
  const decodedNormals = data.attributes.NORMAL && data.attributes.NORMAL.value;
209
209
  const decodedBatchIds = data.attributes.BATCH_ID && data.attributes.BATCH_ID.value;
210
+ // @ts-expect-error
210
211
  const isQuantizedDraco = decodedPositions && data.attributes.POSITION.value.quantization;
212
+ // @ts-expect-error
211
213
  const isOctEncodedDraco = decodedNormals && data.attributes.NORMAL.value.quantization;
212
214
  if (isQuantizedDraco) {
213
215
  // Draco quantization range == quantized volume scale - size in meters of the quantized volume
214
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
215
218
  const quantization = data.POSITION.data.quantization;
216
219
  const range = quantization.range;
217
220
  tile.quantizedVolumeScale = new core_1.Vector3(range, range, range);
@@ -220,6 +223,7 @@ async function loadDraco(tile, dracoData, options, context) {
220
223
  tile.isQuantizedDraco = true;
221
224
  }
222
225
  if (isOctEncodedDraco) {
226
+ // @ts-expect-error This doesn't look right
223
227
  tile.octEncodedRange = (1 << data.NORMAL.data.quantization.quantizationBits) - 1.0;
224
228
  tile.isOctEncodedDraco = true;
225
229
  }
@@ -233,9 +237,13 @@ async function loadDraco(tile, dracoData, options, context) {
233
237
  }
234
238
  }
235
239
  tile.attributes = {
240
+ // @ts-expect-error
236
241
  positions: decodedPositions,
242
+ // @ts-expect-error
237
243
  colors: (0, normalize_3d_tile_colors_1.normalize3DTileColorAttribute)(tile, decodedColors, undefined),
244
+ // @ts-expect-error
238
245
  normals: decodedNormals,
246
+ // @ts-expect-error
239
247
  batchIds: decodedBatchIds,
240
248
  ...batchTableAttributes
241
249
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/3d-tiles",
3
- "version": "4.0.0-alpha.20",
3
+ "version": "4.0.0-alpha.22",
4
4
  "description": "3D Tiles, an open standard for streaming massive heterogeneous 3D geospatial datasets.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -34,11 +34,12 @@
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.20",
38
- "@loaders.gl/gltf": "4.0.0-alpha.20",
39
- "@loaders.gl/loader-utils": "4.0.0-alpha.20",
40
- "@loaders.gl/math": "4.0.0-alpha.20",
41
- "@loaders.gl/tiles": "4.0.0-alpha.20",
37
+ "@loaders.gl/draco": "4.0.0-alpha.22",
38
+ "@loaders.gl/gltf": "4.0.0-alpha.22",
39
+ "@loaders.gl/loader-utils": "4.0.0-alpha.22",
40
+ "@loaders.gl/math": "4.0.0-alpha.22",
41
+ "@loaders.gl/tiles": "4.0.0-alpha.22",
42
+ "@loaders.gl/zip": "4.0.0-alpha.22",
42
43
  "@math.gl/core": "^3.5.1",
43
44
  "@math.gl/geospatial": "^3.5.1",
44
45
  "@probe.gl/log": "^4.0.4",
@@ -47,5 +48,5 @@
47
48
  "peerDependencies": {
48
49
  "@loaders.gl/core": "^4.0.0-alpha.8"
49
50
  },
50
- "gitHead": "ac122e83102657c38207d59c631a5ce4e7aa46bd"
51
+ "gitHead": "0da838c506d1275383f2fd3d244d9c72b25397d2"
51
52
  }
@@ -0,0 +1,84 @@
1
+ import md5 from 'md5';
2
+ import {FileProvider, parseZipLocalFileHeader, HashElement, findBin} from '@loaders.gl/zip';
3
+ import {DeflateCompression, NoCompression} from '@loaders.gl/compression';
4
+
5
+ type CompressionHandler = (compressedFile: ArrayBuffer) => Promise<ArrayBuffer>;
6
+
7
+ /**
8
+ * Handling different compression types in zip
9
+ */
10
+ const COMPRESSION_METHODS: {[key: number]: CompressionHandler} = {
11
+ /** No compression */
12
+ 0: (data) => new NoCompression().decompress(data),
13
+ /** Deflation */
14
+ 8: (data) => new DeflateCompression({raw: true}).decompress(data)
15
+ };
16
+
17
+ /**
18
+ * Class for handling information about 3tz file
19
+ */
20
+ export class Tiles3DArchive {
21
+ /** FileProvider with whe whole file */
22
+ private fileProvider: FileProvider;
23
+ /** hash info */
24
+ private hashArray: HashElement[];
25
+
26
+ /**
27
+ * creates Tiles3DArchive handler
28
+ * @param fileProvider - FileProvider with the whole file
29
+ * @param hashFile - hash info
30
+ */
31
+ constructor(fileProvider: FileProvider, hashFile: HashElement[]) {
32
+ this.fileProvider = fileProvider;
33
+ this.hashArray = hashFile;
34
+ }
35
+
36
+ /**
37
+ * Returns file with the given path from 3tz archive
38
+ * @param path - path inside the 3tz
39
+ * @returns buffer with ready to use file
40
+ */
41
+ async getFile(path: string): Promise<ArrayBuffer> {
42
+ // sometimes paths are not in lower case when hash file is created,
43
+ // so first we're looking for lower case file name and then for original one
44
+ let data = await this.getFileBytes(path.toLocaleLowerCase());
45
+ if (!data) {
46
+ data = await this.getFileBytes(path);
47
+ }
48
+ if (!data) {
49
+ throw new Error('No such file in the archive');
50
+ }
51
+
52
+ return data;
53
+ }
54
+
55
+ /**
56
+ * Trying to get raw file data by adress
57
+ * @param path - path inside the archive
58
+ * @returns buffer with the raw file data
59
+ */
60
+ private async getFileBytes(path: string): Promise<ArrayBuffer | null> {
61
+ const nameHash = Buffer.from(md5(path), 'hex');
62
+ const fileInfo = findBin(nameHash, this.hashArray); // implement binary search
63
+ if (!fileInfo) {
64
+ return null;
65
+ }
66
+
67
+ const localFileHeader = await parseZipLocalFileHeader(fileInfo.offset, this.fileProvider);
68
+ if (!localFileHeader) {
69
+ return null;
70
+ }
71
+
72
+ const compressedFile = await this.fileProvider.slice(
73
+ localFileHeader.fileDataOffset,
74
+ localFileHeader.fileDataOffset + localFileHeader.compressedSize
75
+ );
76
+
77
+ const compressionMethod = COMPRESSION_METHODS[localFileHeader.compressionMethod];
78
+ if (!compressionMethod) {
79
+ throw Error('Only Deflation compression is supported');
80
+ }
81
+
82
+ return compressionMethod(compressedFile);
83
+ }
84
+ }
@@ -0,0 +1,52 @@
1
+ import {
2
+ FileProvider,
3
+ HashElement,
4
+ cdSignature as cdHeaderSignature,
5
+ generateHashInfo,
6
+ parseHashFile,
7
+ parseZipCDFileHeader,
8
+ parseZipLocalFileHeader,
9
+ searchFromTheEnd
10
+ } from '@loaders.gl/zip';
11
+ import {Tiles3DArchive} from './3d-tiles-archive-archive';
12
+
13
+ /**
14
+ * Creates 3tz file handler from raw file
15
+ * @param fileProvider raw file data
16
+ * @param cb is called with information message during parsing
17
+ * @returns 3tz file handler
18
+ */
19
+ export const parse3DTilesArchive = async (
20
+ fileProvider: FileProvider,
21
+ cb?: (msg: string) => void
22
+ ): Promise<Tiles3DArchive> => {
23
+ const hashCDOffset = await searchFromTheEnd(fileProvider, cdHeaderSignature);
24
+
25
+ const cdFileHeader = await parseZipCDFileHeader(hashCDOffset, fileProvider);
26
+
27
+ let hashData: HashElement[];
28
+ if (cdFileHeader?.fileName !== '@3dtilesIndex1@') {
29
+ cb?.('3tz doesnt contain hash file');
30
+ hashData = await generateHashInfo(fileProvider);
31
+ cb?.('hash info has been composed according to central directory records');
32
+ } else {
33
+ cb?.('3tz contains hash file');
34
+ const localFileHeader = await parseZipLocalFileHeader(
35
+ cdFileHeader.localHeaderOffset,
36
+ fileProvider
37
+ );
38
+ if (!localFileHeader) {
39
+ throw new Error('corrupted 3tz');
40
+ }
41
+
42
+ const fileDataOffset = localFileHeader.fileDataOffset;
43
+ const hashFile = await fileProvider.slice(
44
+ fileDataOffset,
45
+ fileDataOffset + localFileHeader.compressedSize
46
+ );
47
+
48
+ hashData = parseHashFile(hashFile);
49
+ }
50
+
51
+ return new Tiles3DArchive(fileProvider, hashData);
52
+ };
@@ -0,0 +1,47 @@
1
+ import {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
2
+ import {DataViewFile} from '@loaders.gl/zip';
3
+ import {parse3DTilesArchive as parse3DTilesArchiveFromProvider} from './3d-tiles-archive/3d-tiles-archive-parser';
4
+
5
+ // __VERSION__ is injected by babel-plugin-version-inline
6
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
8
+
9
+ /** options to load data from 3tz */
10
+ export type Tiles3DArchiveFileLoaderOptions = LoaderOptions & {
11
+ '3d-tiles-archive'?: {
12
+ /** path inside the 3tz archive */
13
+ path?: string;
14
+ };
15
+ };
16
+
17
+ /**
18
+ * Loader for 3tz packages
19
+ */
20
+ export const Tiles3DArchiveFileLoader: LoaderWithParser<
21
+ ArrayBuffer,
22
+ never,
23
+ Tiles3DArchiveFileLoaderOptions
24
+ > = {
25
+ name: '3tz',
26
+ id: '3tz',
27
+ module: '3d-tiles',
28
+ version: VERSION,
29
+ mimeTypes: ['application/octet-stream', 'application/vnd.maxar.archive.3tz+zip'],
30
+ parse: parse3DTilesArchive,
31
+ extensions: ['3tz'],
32
+ options: {}
33
+ };
34
+
35
+ /**
36
+ * returns a single file from the 3tz archive
37
+ * @param data 3tz archive data
38
+ * @param options options
39
+ * @returns requested file
40
+ */
41
+ async function parse3DTilesArchive(
42
+ data: ArrayBuffer,
43
+ options: Tiles3DArchiveFileLoaderOptions = {}
44
+ ): Promise<ArrayBuffer> {
45
+ const archive = await parse3DTilesArchiveFromProvider(new DataViewFile(new DataView(data)));
46
+ return archive.getFile(options['3d-tiles-archive']?.path ?? '');
47
+ }
package/src/index.ts CHANGED
@@ -2,6 +2,9 @@
2
2
  export {Tiles3DLoader} from './tiles-3d-loader';
3
3
  export {CesiumIonLoader} from './cesium-ion-loader';
4
4
  export {Tile3DSubtreeLoader} from './tile-3d-subtree-loader';
5
+ export type {Tiles3DArchiveFileLoaderOptions} from './3d-tiles-archive-loader';
6
+ export {Tiles3DArchiveFileLoader} from './3d-tiles-archive-loader';
7
+ export {Tiles3DArchiveFileSystem} from './lib/filesystems/tiles-3d-archive-file-system';
5
8
 
6
9
  // WRITERS
7
10
  export {Tile3DWriter} from './tile-3d-writer';
@@ -0,0 +1,97 @@
1
+ import {
2
+ FileProvider,
3
+ ZipFileSystem,
4
+ cdSignature as cdHeaderSignature,
5
+ searchFromTheEnd,
6
+ parseZipCDFileHeader,
7
+ HashElement,
8
+ parseHashFile,
9
+ parseZipLocalFileHeader
10
+ } from '@loaders.gl/zip';
11
+ import {Tiles3DArchive} from '../../3d-tiles-archive/3d-tiles-archive-archive';
12
+
13
+ /**
14
+ * FileSystem adapter for a 3tz (3D tiles archive format) file
15
+ * Holds FileProvider object that provides random access to archived files.
16
+ * The difference from ZipFileSystem is usage of `@3dtilesIndex1@` index file that increases
17
+ * access speed to archived files
18
+ * @see https://github.com/erikdahlstrom/3tz-specification/blob/master/Specification.md
19
+ */
20
+ export class Tiles3DArchiveFileSystem extends ZipFileSystem {
21
+ hashData?: HashElement[] | null;
22
+
23
+ /**
24
+ * Constructor
25
+ * @param file - instance of FileProvider or file path string
26
+ */
27
+ constructor(file: FileProvider | string) {
28
+ super(file);
29
+ }
30
+
31
+ /**
32
+ * Implementation of fetch against this file system.
33
+ * It tries to take `@3dtilesIndex1@` file from the archive and use it
34
+ * for faster access to archived files
35
+ * @param filename - name of a file
36
+ * @returns - Response with file data
37
+ */
38
+ async fetch(filename: string): Promise<Response> {
39
+ const fileProvider = await this.fileProvider;
40
+ if (!fileProvider) {
41
+ throw new Error('No data detected in the zip archive');
42
+ }
43
+ await this.parseHashFile();
44
+ if (this.hashData) {
45
+ const archive = new Tiles3DArchive(fileProvider, this.hashData);
46
+
47
+ const fileData = await archive.getFile(filename);
48
+ const response = new Response(fileData);
49
+ Object.defineProperty(response, 'url', {value: `${this.fileName || ''}/${filename}`});
50
+ return response;
51
+ }
52
+ return super.fetch(filename);
53
+ }
54
+
55
+ /**
56
+ * Try to get and parse '@3dtilesIndex1@' file, that allows to get direct access
57
+ * to files inside the archive
58
+ * @returns void
59
+ */
60
+ private async parseHashFile(): Promise<void> {
61
+ if (this.hashData !== undefined) {
62
+ return;
63
+ }
64
+
65
+ const fileProvider = await this.fileProvider;
66
+ if (!fileProvider) {
67
+ throw new Error('No data detected in the zip archive');
68
+ }
69
+
70
+ const hashCDOffset = await searchFromTheEnd(fileProvider, cdHeaderSignature);
71
+
72
+ const cdFileHeader = await parseZipCDFileHeader(hashCDOffset, fileProvider);
73
+
74
+ // '@3dtilesIndex1@' is index file that must be the last in the archive. It allows
75
+ // to improve load and read performance when the archive contains a very large number
76
+ // of files.
77
+ if (cdFileHeader?.fileName === '@3dtilesIndex1@') {
78
+ const localFileHeader = await parseZipLocalFileHeader(
79
+ cdFileHeader.localHeaderOffset,
80
+ fileProvider
81
+ );
82
+ if (!localFileHeader) {
83
+ throw new Error('corrupted 3tz');
84
+ }
85
+
86
+ const fileDataOffset = localFileHeader.fileDataOffset;
87
+ const hashFile = await fileProvider.slice(
88
+ fileDataOffset,
89
+ fileDataOffset + localFileHeader.compressedSize
90
+ );
91
+
92
+ this.hashData = parseHashFile(hashFile);
93
+ } else {
94
+ this.hashData = null;
95
+ }
96
+ }
97
+ }
@@ -8,7 +8,7 @@
8
8
  // - Also, should we have hard dependency on gltf module or use injection or auto-discovery for gltf parser?
9
9
 
10
10
  import {GLTFLoader, postProcessGLTF, _getMemoryUsageGLTF} from '@loaders.gl/gltf';
11
- import {LoaderContext, sliceArrayBuffer} from '@loaders.gl/loader-utils';
11
+ import {LoaderContext, sliceArrayBuffer, parseFromContext} from '@loaders.gl/loader-utils';
12
12
  import {Tiles3DTileContent} from '../../../types';
13
13
  import {Tiles3DLoaderOptions} from '../../../tiles-3d-loader';
14
14
 
@@ -74,15 +74,20 @@ export async function extractGLTF(
74
74
  if (!context) {
75
75
  return;
76
76
  }
77
- const {parse, fetch} = context;
78
77
  if (tile.gltfUrl) {
78
+ const {fetch} = context;
79
79
  const response = await fetch(tile.gltfUrl, options);
80
80
  tile.gltfArrayBuffer = await response.arrayBuffer();
81
81
  tile.gltfByteOffset = 0;
82
82
  }
83
83
  if (tile.gltfArrayBuffer) {
84
84
  // TODO - Should handle byteOffset... However, not used now...
85
- const gltfWithBuffers = await parse(tile.gltfArrayBuffer, GLTFLoader, options, context);
85
+ const gltfWithBuffers = await parseFromContext(
86
+ tile.gltfArrayBuffer,
87
+ GLTFLoader,
88
+ options,
89
+ context
90
+ );
86
91
  tile.gltf = postProcessGLTF(gltfWithBuffers);
87
92
  tile.gpuMemoryUsageInBytes = _getMemoryUsageGLTF(tile.gltf);
88
93
  delete tile.gltfArrayBuffer;
@@ -1,6 +1,8 @@
1
- import type {LoaderContext} from '@loaders.gl/loader-utils';
2
- import type {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
1
+ // loaders.gl, MIT license
2
+
3
+ import {parseFromContext, LoaderContext} from '@loaders.gl/loader-utils';
3
4
  import {_getMemoryUsageGLTF, GLTFLoader, postProcessGLTF} from '@loaders.gl/gltf';
5
+ import type {Tiles3DLoaderOptions} from '../../tiles-3d-loader';
4
6
  import {Tiles3DTileContent} from '../../types';
5
7
 
6
8
  export async function parseGltf3DTile(
@@ -14,17 +16,15 @@ export async function parseGltf3DTile(
14
16
  // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
15
17
  tile.rotateYtoZ = true;
16
18
  // Save gltf up axis
17
- tile.gltfUpAxis =
18
- options?.['3d-tiles'] && options['3d-tiles'].assetGltfUpAxis
19
- ? options['3d-tiles'].assetGltfUpAxis
20
- : 'Y';
19
+ tile.gltfUpAxis = options?.['3d-tiles']?.assetGltfUpAxis
20
+ ? options['3d-tiles'].assetGltfUpAxis
21
+ : 'Y';
21
22
 
22
23
  if (options?.['3d-tiles']?.loadGLTF) {
23
24
  if (!context) {
24
25
  return;
25
26
  }
26
- const {parse} = context;
27
- const gltfWithBuffers = await parse(arrayBuffer, GLTFLoader, options, context);
27
+ const gltfWithBuffers = await parseFromContext(arrayBuffer, GLTFLoader, options, context);
28
28
  tile.gltf = postProcessGLTF(gltfWithBuffers);
29
29
  tile.gpuMemoryUsageInBytes = _getMemoryUsageGLTF(tile.gltf);
30
30
  } else {
@@ -1,5 +1,6 @@
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';
@@ -89,7 +90,7 @@ function resolveUri(uri: string = '', basePath: string): string {
89
90
  return uri;
90
91
  }
91
92
 
92
- return `${basePath}/${uri}`;
93
+ return path.resolve(basePath, uri);
93
94
  }
94
95
 
95
96
  export function normalizeTileData(
@@ -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
  };