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

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.
@@ -0,0 +1,72 @@
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.TZ3Archive = void 0;
7
+ const md5_1 = __importDefault(require("md5"));
8
+ const zip_1 = require("@loaders.gl/zip");
9
+ const compression_1 = require("@loaders.gl/compression");
10
+ /**
11
+ * Handling different compression types in zip
12
+ */
13
+ const COMPRESSION_METHODS = {
14
+ /** No compression */
15
+ 0: async (compressedFile) => compressedFile,
16
+ /** Deflation */
17
+ 8: async (compressedFile) => {
18
+ const compression = new compression_1.DeflateCompression({ raw: true });
19
+ const decompressedData = await compression.decompress(compressedFile);
20
+ return decompressedData;
21
+ }
22
+ };
23
+ /**
24
+ * Class for handling information about 3tz file
25
+ */
26
+ class TZ3Archive {
27
+ constructor(tz3Archive, hashFile) {
28
+ this.tz3Archive = tz3Archive;
29
+ this.hashArray = hashFile;
30
+ }
31
+ /**
32
+ * Returns file with the given path from 3tz archive
33
+ * @param path - path inside the 3tz
34
+ * @returns buffer with ready to use file
35
+ */
36
+ async getFile(path) {
37
+ // sometimes paths are not in lower case when hash file is created,
38
+ // so first we're looking for lower case file name and then for original one
39
+ let data = await this.getFileBytes(path.toLocaleLowerCase());
40
+ if (!data) {
41
+ data = await this.getFileBytes(path);
42
+ }
43
+ if (!data) {
44
+ throw new Error('No such file in the archieve');
45
+ }
46
+ const decompressedFile = Buffer.from(data);
47
+ return decompressedFile;
48
+ }
49
+ /**
50
+ * Trying to get raw file data by adress
51
+ * @param path - path inside the archive
52
+ * @returns buffer with the raw file data
53
+ */
54
+ async getFileBytes(path) {
55
+ const nameHash = Buffer.from((0, md5_1.default)(path), 'hex');
56
+ const fileInfo = (0, zip_1.findBin)(nameHash, this.hashArray); // implement binary search
57
+ if (!fileInfo) {
58
+ return null;
59
+ }
60
+ const localFileHeader = await (0, zip_1.parseZipLocalFileHeader)(fileInfo.offset, this.tz3Archive);
61
+ if (!localFileHeader) {
62
+ return null;
63
+ }
64
+ const compressedFile = await this.tz3Archive.slice(localFileHeader.fileDataOffset, localFileHeader.fileDataOffset + localFileHeader.compressedSize);
65
+ const compressionMethod = COMPRESSION_METHODS[localFileHeader.compressionMethod];
66
+ if (!compressionMethod) {
67
+ throw Error('Only Deflation compression is supported');
68
+ }
69
+ return compressionMethod(compressedFile);
70
+ }
71
+ }
72
+ exports.TZ3Archive = TZ3Archive;
@@ -0,0 +1,10 @@
1
+ import { FileProvider } from '@loaders.gl/zip';
2
+ import { TZ3Archive } from './tz3-archive';
3
+ /**
4
+ * Creates 3tz file handler from raw file
5
+ * @param fileProvider raw file data
6
+ * @param cb is called with information message during parsing
7
+ * @returns 3tz file handler
8
+ */
9
+ export declare const parse3tz: (fileProvider: FileProvider, cb?: ((msg: string) => void) | undefined) => Promise<TZ3Archive>;
10
+ //# sourceMappingURL=tz3-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tz3-parser.d.ts","sourceRoot":"","sources":["../../src/tz3/tz3-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAQb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AAEzC;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,iBACL,YAAY,cACf,MAAM,KAAK,IAAI,kBACzB,QAAQ,UAAU,CA8BpB,CAAC"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parse3tz = void 0;
4
+ const zip_1 = require("@loaders.gl/zip");
5
+ const tz3_archive_1 = require("./tz3-archive");
6
+ /**
7
+ * Creates 3tz file handler from raw file
8
+ * @param fileProvider raw file data
9
+ * @param cb is called with information message during parsing
10
+ * @returns 3tz file handler
11
+ */
12
+ const parse3tz = async (fileProvider, cb) => {
13
+ const hashCDOffset = await (0, zip_1.searchFromTheEnd)(fileProvider, zip_1.cdSignature);
14
+ const cdFileHeader = await (0, zip_1.parseZipCDFileHeader)(hashCDOffset, fileProvider);
15
+ let hashData;
16
+ if (cdFileHeader?.fileName !== '@3dtilesIndex1@') {
17
+ cb?.('3tz doesnt contain hash file');
18
+ hashData = await (0, zip_1.generateHashInfo)(fileProvider);
19
+ cb?.('hash info has been composed according to central directory records');
20
+ }
21
+ else {
22
+ cb?.('3tz contains hash file');
23
+ const localFileHeader = await (0, zip_1.parseZipLocalFileHeader)(cdFileHeader.localHeaderOffset, fileProvider);
24
+ if (!localFileHeader) {
25
+ throw new Error('corrupted 3tz');
26
+ }
27
+ const fileDataOffset = localFileHeader.fileDataOffset;
28
+ const hashFile = await fileProvider.slice(fileDataOffset, fileDataOffset + localFileHeader.compressedSize);
29
+ hashData = (0, zip_1.parseHashFile)(hashFile);
30
+ }
31
+ return new tz3_archive_1.TZ3Archive(fileProvider, hashData);
32
+ };
33
+ exports.parse3tz = parse3tz;
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import { LoaderOptions, LoaderWithParser } from '@loaders.gl/loader-utils';
3
+ /** options to load data from 3tz */
4
+ export type TZ3LoaderOptions = LoaderOptions & {
5
+ tz3?: {
6
+ /** path inside the 3tz archive */
7
+ path?: string;
8
+ };
9
+ };
10
+ /**
11
+ * Loader for 3tz packages
12
+ */
13
+ export declare const TZ3Loader: LoaderWithParser<Buffer, never, TZ3LoaderOptions>;
14
+ //# sourceMappingURL=tz3-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tz3-loader.d.ts","sourceRoot":"","sources":["../src/tz3-loader.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAQzE,oCAAoC;AACpC,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,GAAG,CAAC,EAAE;QACJ,kCAAkC;QAClC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,gBAAgB,CASvE,CAAC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TZ3Loader = void 0;
4
+ const zip_1 = require("@loaders.gl/zip");
5
+ const tz3_parser_1 = require("./tz3/tz3-parser");
6
+ // __VERSION__ is injected by babel-plugin-version-inline
7
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
8
+ const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
9
+ /**
10
+ * Loader for 3tz packages
11
+ */
12
+ exports.TZ3Loader = {
13
+ name: '3tz',
14
+ id: '3tz',
15
+ module: 'i3s',
16
+ version: VERSION,
17
+ mimeTypes: ['application/octet-stream'],
18
+ parse: parse3tz,
19
+ extensions: ['3tz'],
20
+ options: {}
21
+ };
22
+ /**
23
+ * returns a single file from the 3tz archive
24
+ * @param data 3tz archive data
25
+ * @param options options
26
+ * @returns requested file
27
+ */
28
+ async function parse3tz(data, options = {}) {
29
+ return (await (0, tz3_parser_1.parse3tz)(new zip_1.DataViewFile(new DataView(data)))).getFile(options.tz3?.path ?? '');
30
+ }
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.21",
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,11 @@
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.21",
38
+ "@loaders.gl/gltf": "4.0.0-alpha.21",
39
+ "@loaders.gl/loader-utils": "4.0.0-alpha.21",
40
+ "@loaders.gl/math": "4.0.0-alpha.21",
41
+ "@loaders.gl/tiles": "4.0.0-alpha.21",
42
42
  "@math.gl/core": "^3.5.1",
43
43
  "@math.gl/geospatial": "^3.5.1",
44
44
  "@probe.gl/log": "^4.0.4",
@@ -47,5 +47,5 @@
47
47
  "peerDependencies": {
48
48
  "@loaders.gl/core": "^4.0.0-alpha.8"
49
49
  },
50
- "gitHead": "ac122e83102657c38207d59c631a5ce4e7aa46bd"
50
+ "gitHead": "df5d670b136192b26941396e944f9c46be788e83"
51
51
  }
package/src/index.ts CHANGED
@@ -2,6 +2,8 @@
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 {TZ3LoaderOptions} from './tz3-loader';
6
+ export {TZ3Loader} from './tz3-loader';
5
7
 
6
8
  // WRITERS
7
9
  export {Tile3DWriter} from './tile-3d-writer';
@@ -0,0 +1,82 @@
1
+ import md5 from 'md5';
2
+ import {FileProvider, parseZipLocalFileHeader, HashElement, findBin} from '@loaders.gl/zip';
3
+ import {DeflateCompression} 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: async (compressedFile) => compressedFile,
13
+
14
+ /** Deflation */
15
+ 8: async (compressedFile) => {
16
+ const compression = new DeflateCompression({raw: true});
17
+ const decompressedData = await compression.decompress(compressedFile);
18
+ return decompressedData;
19
+ }
20
+ };
21
+
22
+ /**
23
+ * Class for handling information about 3tz file
24
+ */
25
+ export class TZ3Archive {
26
+ private tz3Archive: FileProvider;
27
+ private hashArray: HashElement[];
28
+ constructor(tz3Archive: FileProvider, hashFile: HashElement[]) {
29
+ this.tz3Archive = tz3Archive;
30
+ this.hashArray = hashFile;
31
+ }
32
+
33
+ /**
34
+ * Returns file with the given path from 3tz archive
35
+ * @param path - path inside the 3tz
36
+ * @returns buffer with ready to use file
37
+ */
38
+ async getFile(path: string): Promise<Buffer> {
39
+ // sometimes paths are not in lower case when hash file is created,
40
+ // so first we're looking for lower case file name and then for original one
41
+ let data = await this.getFileBytes(path.toLocaleLowerCase());
42
+ if (!data) {
43
+ data = await this.getFileBytes(path);
44
+ }
45
+ if (!data) {
46
+ throw new Error('No such file in the archieve');
47
+ }
48
+ const decompressedFile = Buffer.from(data);
49
+
50
+ return decompressedFile;
51
+ }
52
+
53
+ /**
54
+ * Trying to get raw file data by adress
55
+ * @param path - path inside the archive
56
+ * @returns buffer with the raw file data
57
+ */
58
+ private async getFileBytes(path: string): Promise<ArrayBuffer | null> {
59
+ const nameHash = Buffer.from(md5(path), 'hex');
60
+ const fileInfo = findBin(nameHash, this.hashArray); // implement binary search
61
+ if (!fileInfo) {
62
+ return null;
63
+ }
64
+
65
+ const localFileHeader = await parseZipLocalFileHeader(fileInfo.offset, this.tz3Archive);
66
+ if (!localFileHeader) {
67
+ return null;
68
+ }
69
+
70
+ const compressedFile = await this.tz3Archive.slice(
71
+ localFileHeader.fileDataOffset,
72
+ localFileHeader.fileDataOffset + localFileHeader.compressedSize
73
+ );
74
+
75
+ const compressionMethod = COMPRESSION_METHODS[localFileHeader.compressionMethod];
76
+ if (!compressionMethod) {
77
+ throw Error('Only Deflation compression is supported');
78
+ }
79
+
80
+ return compressionMethod(compressedFile);
81
+ }
82
+ }
@@ -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 {TZ3Archive} from './tz3-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 parse3tz = async (
20
+ fileProvider: FileProvider,
21
+ cb?: (msg: string) => void
22
+ ): Promise<TZ3Archive> => {
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 TZ3Archive(fileProvider, hashData);
52
+ };
@@ -0,0 +1,41 @@
1
+ import {LoaderOptions, LoaderWithParser} from '@loaders.gl/loader-utils';
2
+ import {DataViewFile} from '@loaders.gl/zip';
3
+ import {parse3tz as parse3tzFromProvider} from './tz3/tz3-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 TZ3LoaderOptions = LoaderOptions & {
11
+ tz3?: {
12
+ /** path inside the 3tz archive */
13
+ path?: string;
14
+ };
15
+ };
16
+
17
+ /**
18
+ * Loader for 3tz packages
19
+ */
20
+ export const TZ3Loader: LoaderWithParser<Buffer, never, TZ3LoaderOptions> = {
21
+ name: '3tz',
22
+ id: '3tz',
23
+ module: 'i3s',
24
+ version: VERSION,
25
+ mimeTypes: ['application/octet-stream'],
26
+ parse: parse3tz,
27
+ extensions: ['3tz'],
28
+ options: {}
29
+ };
30
+
31
+ /**
32
+ * returns a single file from the 3tz archive
33
+ * @param data 3tz archive data
34
+ * @param options options
35
+ * @returns requested file
36
+ */
37
+ async function parse3tz(data: ArrayBuffer, options: TZ3LoaderOptions = {}) {
38
+ return (await parse3tzFromProvider(new DataViewFile(new DataView(data)))).getFile(
39
+ options.tz3?.path ?? ''
40
+ );
41
+ }