@loaders.gl/3d-tiles 4.0.0-alpha.22 → 4.0.0-alpha.24
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.
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.d.ts +2 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.d.ts.map +1 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +1 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -1
- package/dist/3d-tiles-archive-loader.d.ts +1 -1
- package/dist/3d-tiles-archive-loader.d.ts.map +1 -1
- package/dist/cesium-ion-loader.d.ts +2 -2
- package/dist/cesium-ion-loader.d.ts.map +1 -1
- package/dist/dist.min.js +2074 -1483
- package/dist/es5/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -1
- package/dist/es5/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -1
- package/dist/es5/3d-tiles-archive-loader.js +3 -3
- package/dist/es5/3d-tiles-archive-loader.js.map +1 -1
- package/dist/es5/cesium-ion-loader.js.map +1 -1
- package/dist/es5/lib/filesystems/tiles-3d-archive-file-system.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile-composite.js +3 -1
- package/dist/es5/lib/parsers/parse-3d-tile-composite.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +3 -1
- package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
- package/dist/es5/lib/parsers/parse-3d-tile.js +3 -1
- package/dist/es5/lib/parsers/parse-3d-tile.js.map +1 -1
- package/dist/es5/lib/utils/version.js +1 -1
- package/dist/es5/tile-3d-subtree-loader.js.map +1 -1
- package/dist/es5/tile-3d-writer.js.map +1 -1
- package/dist/es5/tiles-3d-loader.js +2 -0
- package/dist/es5/tiles-3d-loader.js.map +1 -1
- package/dist/es5/types.js.map +1 -1
- package/dist/esm/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -1
- package/dist/esm/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -1
- package/dist/esm/3d-tiles-archive-loader.js +2 -2
- package/dist/esm/3d-tiles-archive-loader.js.map +1 -1
- package/dist/esm/cesium-ion-loader.js.map +1 -1
- package/dist/esm/lib/filesystems/tiles-3d-archive-file-system.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile-composite.js +3 -1
- package/dist/esm/lib/parsers/parse-3d-tile-composite.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile-gltf.js +2 -1
- package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
- package/dist/esm/lib/parsers/parse-3d-tile.js +3 -1
- package/dist/esm/lib/parsers/parse-3d-tile.js.map +1 -1
- package/dist/esm/lib/utils/version.js +1 -1
- package/dist/esm/tile-3d-subtree-loader.js.map +1 -1
- package/dist/esm/tile-3d-writer.js.map +1 -1
- package/dist/esm/tiles-3d-loader.js +2 -0
- package/dist/esm/tiles-3d-loader.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts +2 -1
- package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +1 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile.d.ts +1 -1
- package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
- package/dist/tile-3d-subtree-loader.d.ts +3 -3
- package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
- package/dist/tile-3d-writer.d.ts +2 -2
- package/dist/tile-3d-writer.d.ts.map +1 -1
- package/dist/tiles-3d-loader.d.ts +2 -1
- package/dist/tiles-3d-loader.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/3d-tiles-archive/3d-tiles-archive-archive.ts +2 -1
- package/src/3d-tiles-archive/3d-tiles-archive-parser.ts +1 -1
- package/src/3d-tiles-archive-loader.ts +2 -2
- package/src/cesium-ion-loader.ts +2 -3
- package/src/lib/filesystems/tiles-3d-archive-file-system.ts +1 -1
- package/src/lib/parsers/parse-3d-tile-composite.ts +1 -1
- package/src/lib/parsers/parse-3d-tile-gltf.ts +3 -2
- package/src/lib/parsers/parse-3d-tile.ts +2 -2
- package/src/tile-3d-subtree-loader.ts +3 -3
- package/src/tile-3d-writer.ts +2 -2
- package/src/tiles-3d-loader.ts +16 -4
- package/src/types.ts +3 -0
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +0 -72
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +0 -33
- package/dist/3d-tiles-archive-loader.js +0 -31
- package/dist/bundle.js +0 -5
- package/dist/cesium-ion-loader.js +0 -41
- package/dist/index.js +0 -30
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +0 -113
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +0 -197
- package/dist/lib/classes/tile-3d-batch-table.js +0 -245
- package/dist/lib/classes/tile-3d-feature-table.js +0 -72
- package/dist/lib/constants.js +0 -26
- package/dist/lib/encoders/encode-3d-tile-batched-model.js +0 -46
- package/dist/lib/encoders/encode-3d-tile-composite.js +0 -24
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js +0 -38
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js +0 -39
- package/dist/lib/encoders/encode-3d-tile.js +0 -33
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js +0 -30
- package/dist/lib/filesystems/tiles-3d-archive-file-system.js +0 -75
- package/dist/lib/ion/ion.js +0 -68
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -30
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -42
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -303
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -96
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js +0 -28
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -87
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +0 -93
- package/dist/lib/parsers/helpers/parse-utils.js +0 -32
- package/dist/lib/parsers/parse-3d-tile-batched-model.js +0 -33
- package/dist/lib/parsers/parse-3d-tile-composite.js +0 -24
- package/dist/lib/parsers/parse-3d-tile-gltf.js +0 -28
- package/dist/lib/parsers/parse-3d-tile-header.js +0 -194
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js +0 -172
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js +0 -441
- package/dist/lib/parsers/parse-3d-tile.js +0 -33
- package/dist/lib/utils/obb/s2-corners-to-obb.js +0 -37
- package/dist/lib/utils/s2/converters/s2-to-boundary.js +0 -61
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js +0 -36
- package/dist/lib/utils/s2/converters/s2-to-region.js +0 -59
- package/dist/lib/utils/s2/index.js +0 -23
- package/dist/lib/utils/s2/s2-geometry-functions.js +0 -29
- package/dist/lib/utils/s2/s2-token-functions.js +0 -68
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -32
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js +0 -260
- package/dist/lib/utils/version.js +0 -7
- package/dist/tile-3d-subtree-loader.js +0 -23
- package/dist/tile-3d-writer.js +0 -27
- package/dist/tiles-3d-loader.js +0 -76
- package/dist/types.js +0 -2
|
@@ -10,7 +10,7 @@ export async function parseGltf3DTile(
|
|
|
10
10
|
arrayBuffer: ArrayBuffer,
|
|
11
11
|
options?: Tiles3DLoaderOptions,
|
|
12
12
|
context?: LoaderContext
|
|
13
|
-
): Promise<
|
|
13
|
+
): Promise<number> {
|
|
14
14
|
// Set flags
|
|
15
15
|
// glTF models need to be rotated from Y to Z up
|
|
16
16
|
// https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up
|
|
@@ -22,7 +22,7 @@ export async function parseGltf3DTile(
|
|
|
22
22
|
|
|
23
23
|
if (options?.['3d-tiles']?.loadGLTF) {
|
|
24
24
|
if (!context) {
|
|
25
|
-
return;
|
|
25
|
+
return arrayBuffer.byteLength;
|
|
26
26
|
}
|
|
27
27
|
const gltfWithBuffers = await parseFromContext(arrayBuffer, GLTFLoader, options, context);
|
|
28
28
|
tile.gltf = postProcessGLTF(gltfWithBuffers);
|
|
@@ -30,4 +30,5 @@ export async function parseGltf3DTile(
|
|
|
30
30
|
} else {
|
|
31
31
|
tile.gltfArrayBuffer = arrayBuffer;
|
|
32
32
|
}
|
|
33
|
+
return arrayBuffer.byteLength;
|
|
33
34
|
}
|
|
@@ -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',
|
package/src/tile-3d-writer.ts
CHANGED
|
@@ -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',
|
package/src/tiles-3d-loader.ts
CHANGED
|
@@ -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(
|
|
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
|
@@ -42,6 +42,7 @@ export type GLTFHeader = {
|
|
|
42
42
|
* https://github.com/CesiumGS/3d-tiles/tree/main/specification#property-reference
|
|
43
43
|
*/
|
|
44
44
|
export type Tiles3DTilesetJSON = {
|
|
45
|
+
shape: 'tileset3d';
|
|
45
46
|
/** Metadata about the entire tileset.
|
|
46
47
|
* https://github.com/CesiumGS/3d-tiles/tree/main/specification#asset
|
|
47
48
|
*/
|
|
@@ -202,6 +203,8 @@ export type TilesetProperty = {
|
|
|
202
203
|
};
|
|
203
204
|
|
|
204
205
|
export type Tiles3DTileContent = {
|
|
206
|
+
shape: 'tile3d';
|
|
207
|
+
|
|
205
208
|
/** Common properties */
|
|
206
209
|
byteOffset?: number;
|
|
207
210
|
type?: string;
|
|
@@ -1,72 +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.Tiles3DArchive = 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: (data) => new compression_1.NoCompression().decompress(data),
|
|
16
|
-
/** Deflation */
|
|
17
|
-
8: (data) => new compression_1.DeflateCompression({ raw: true }).decompress(data)
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Class for handling information about 3tz file
|
|
21
|
-
*/
|
|
22
|
-
class Tiles3DArchive {
|
|
23
|
-
/**
|
|
24
|
-
* creates Tiles3DArchive handler
|
|
25
|
-
* @param fileProvider - FileProvider with the whole file
|
|
26
|
-
* @param hashFile - hash info
|
|
27
|
-
*/
|
|
28
|
-
constructor(fileProvider, hashFile) {
|
|
29
|
-
this.fileProvider = fileProvider;
|
|
30
|
-
this.hashArray = hashFile;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Returns file with the given path from 3tz archive
|
|
34
|
-
* @param path - path inside the 3tz
|
|
35
|
-
* @returns buffer with ready to use file
|
|
36
|
-
*/
|
|
37
|
-
async getFile(path) {
|
|
38
|
-
// sometimes paths are not in lower case when hash file is created,
|
|
39
|
-
// so first we're looking for lower case file name and then for original one
|
|
40
|
-
let data = await this.getFileBytes(path.toLocaleLowerCase());
|
|
41
|
-
if (!data) {
|
|
42
|
-
data = await this.getFileBytes(path);
|
|
43
|
-
}
|
|
44
|
-
if (!data) {
|
|
45
|
-
throw new Error('No such file in the archive');
|
|
46
|
-
}
|
|
47
|
-
return data;
|
|
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.fileProvider);
|
|
61
|
-
if (!localFileHeader) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const compressedFile = await this.fileProvider.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.Tiles3DArchive = Tiles3DArchive;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parse3DTilesArchive = void 0;
|
|
4
|
-
const zip_1 = require("@loaders.gl/zip");
|
|
5
|
-
const _3d_tiles_archive_archive_1 = require("./3d-tiles-archive-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 parse3DTilesArchive = 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 _3d_tiles_archive_archive_1.Tiles3DArchive(fileProvider, hashData);
|
|
32
|
-
};
|
|
33
|
-
exports.parse3DTilesArchive = parse3DTilesArchive;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Tiles3DArchiveFileLoader = void 0;
|
|
4
|
-
const zip_1 = require("@loaders.gl/zip");
|
|
5
|
-
const _3d_tiles_archive_parser_1 = require("./3d-tiles-archive/3d-tiles-archive-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.Tiles3DArchiveFileLoader = {
|
|
13
|
-
name: '3tz',
|
|
14
|
-
id: '3tz',
|
|
15
|
-
module: '3d-tiles',
|
|
16
|
-
version: VERSION,
|
|
17
|
-
mimeTypes: ['application/octet-stream', 'application/vnd.maxar.archive.3tz+zip'],
|
|
18
|
-
parse: parse3DTilesArchive,
|
|
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 parse3DTilesArchive(data, options = {}) {
|
|
29
|
-
const archive = await (0, _3d_tiles_archive_parser_1.parse3DTilesArchive)(new zip_1.DataViewFile(new DataView(data)));
|
|
30
|
-
return archive.getFile(options['3d-tiles-archive']?.path ?? '');
|
|
31
|
-
}
|
package/dist/bundle.js
DELETED
|
@@ -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,30 +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.Tiles3DArchiveFileSystem = exports.Tiles3DArchiveFileLoader = 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
|
-
var _3d_tiles_archive_loader_1 = require("./3d-tiles-archive-loader");
|
|
15
|
-
Object.defineProperty(exports, "Tiles3DArchiveFileLoader", { enumerable: true, get: function () { return _3d_tiles_archive_loader_1.Tiles3DArchiveFileLoader; } });
|
|
16
|
-
var tiles_3d_archive_file_system_1 = require("./lib/filesystems/tiles-3d-archive-file-system");
|
|
17
|
-
Object.defineProperty(exports, "Tiles3DArchiveFileSystem", { enumerable: true, get: function () { return tiles_3d_archive_file_system_1.Tiles3DArchiveFileSystem; } });
|
|
18
|
-
// WRITERS
|
|
19
|
-
var tile_3d_writer_1 = require("./tile-3d-writer");
|
|
20
|
-
Object.defineProperty(exports, "Tile3DWriter", { enumerable: true, get: function () { return tile_3d_writer_1.Tile3DWriter; } });
|
|
21
|
-
// CLASSES
|
|
22
|
-
var tile_3d_feature_table_1 = require("./lib/classes/tile-3d-feature-table");
|
|
23
|
-
Object.defineProperty(exports, "Tile3DFeatureTable", { enumerable: true, get: function () { return __importDefault(tile_3d_feature_table_1).default; } });
|
|
24
|
-
var tile_3d_batch_table_1 = require("./lib/classes/tile-3d-batch-table");
|
|
25
|
-
Object.defineProperty(exports, "Tile3DBatchTable", { enumerable: true, get: function () { return __importDefault(tile_3d_batch_table_1).default; } });
|
|
26
|
-
// EXPERIMENTAL
|
|
27
|
-
var constants_1 = require("./lib/constants");
|
|
28
|
-
Object.defineProperty(exports, "TILE3D_TYPE", { enumerable: true, get: function () { return constants_1.TILE3D_TYPE; } });
|
|
29
|
-
var ion_1 = require("./lib/ion/ion");
|
|
30
|
-
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;
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// This file is derived from the Cesium code base under Apache 2 license
|
|
3
|
-
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.traverseHierarchy = exports.initializeHierarchy = void 0;
|
|
6
|
-
// TODO - Finish hierarchy suypport: this file is only half ported
|
|
7
|
-
/* eslint-disable */
|
|
8
|
-
// @ts-nocheck
|
|
9
|
-
const defined = (x) => x !== undefined;
|
|
10
|
-
function initializeHierarchy(batchTable, jsonHeader, binaryBody) {
|
|
11
|
-
if (!jsonHeader) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
let hierarchy = batchTable.getExtension('3DTILES_batch_table_hierarchy');
|
|
15
|
-
const legacyHierarchy = jsonHeader.HIERARCHY;
|
|
16
|
-
if (legacyHierarchy) {
|
|
17
|
-
// eslint-disable-next-line
|
|
18
|
-
console.warn('3D Tile Parser: HIERARCHY is deprecated. Use 3DTILES_batch_table_hierarchy.');
|
|
19
|
-
jsonHeader.extensions = jsonHeader.extensions || {};
|
|
20
|
-
jsonHeader.extensions['3DTILES_batch_table_hierarchy'] = legacyHierarchy;
|
|
21
|
-
hierarchy = legacyHierarchy;
|
|
22
|
-
}
|
|
23
|
-
if (!hierarchy) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
return initializeHierarchyValues(hierarchy, binaryBody);
|
|
27
|
-
}
|
|
28
|
-
exports.initializeHierarchy = initializeHierarchy;
|
|
29
|
-
// eslint-disable-next-line max-statements
|
|
30
|
-
function initializeHierarchyValues(hierarchyJson, binaryBody) {
|
|
31
|
-
let i;
|
|
32
|
-
let classId;
|
|
33
|
-
let binaryAccessor;
|
|
34
|
-
const instancesLength = hierarchyJson.instancesLength;
|
|
35
|
-
const classes = hierarchyJson.classes;
|
|
36
|
-
let classIds = hierarchyJson.classIds;
|
|
37
|
-
let parentCounts = hierarchyJson.parentCounts;
|
|
38
|
-
let parentIds = hierarchyJson.parentIds;
|
|
39
|
-
let parentIdsLength = instancesLength;
|
|
40
|
-
if (defined(classIds.byteOffset)) {
|
|
41
|
-
classIds.componentType = defaultValue(classIds.componentType, GL.UNSIGNED_SHORT);
|
|
42
|
-
classIds.type = AttributeType.SCALAR;
|
|
43
|
-
binaryAccessor = getBinaryAccessor(classIds);
|
|
44
|
-
classIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + classIds.byteOffset, instancesLength);
|
|
45
|
-
}
|
|
46
|
-
let parentIndexes;
|
|
47
|
-
if (defined(parentCounts)) {
|
|
48
|
-
if (defined(parentCounts.byteOffset)) {
|
|
49
|
-
parentCounts.componentType = defaultValue(parentCounts.componentType, GL.UNSIGNED_SHORT);
|
|
50
|
-
parentCounts.type = AttributeType.SCALAR;
|
|
51
|
-
binaryAccessor = getBinaryAccessor(parentCounts);
|
|
52
|
-
parentCounts = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentCounts.byteOffset, instancesLength);
|
|
53
|
-
}
|
|
54
|
-
parentIndexes = new Uint16Array(instancesLength);
|
|
55
|
-
parentIdsLength = 0;
|
|
56
|
-
for (i = 0; i < instancesLength; ++i) {
|
|
57
|
-
parentIndexes[i] = parentIdsLength;
|
|
58
|
-
parentIdsLength += parentCounts[i];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (defined(parentIds) && defined(parentIds.byteOffset)) {
|
|
62
|
-
parentIds.componentType = defaultValue(parentIds.componentType, GL.UNSIGNED_SHORT);
|
|
63
|
-
parentIds.type = AttributeType.SCALAR;
|
|
64
|
-
binaryAccessor = getBinaryAccessor(parentIds);
|
|
65
|
-
parentIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentIds.byteOffset, parentIdsLength);
|
|
66
|
-
}
|
|
67
|
-
const classesLength = classes.length;
|
|
68
|
-
for (i = 0; i < classesLength; ++i) {
|
|
69
|
-
const classInstancesLength = classes[i].length;
|
|
70
|
-
const properties = classes[i].instances;
|
|
71
|
-
const binaryProperties = getBinaryProperties(classInstancesLength, properties, binaryBody);
|
|
72
|
-
classes[i].instances = combine(binaryProperties, properties);
|
|
73
|
-
}
|
|
74
|
-
const classCounts = new Array(classesLength).fill(0);
|
|
75
|
-
const classIndexes = new Uint16Array(instancesLength);
|
|
76
|
-
for (i = 0; i < instancesLength; ++i) {
|
|
77
|
-
classId = classIds[i];
|
|
78
|
-
classIndexes[i] = classCounts[classId];
|
|
79
|
-
++classCounts[classId];
|
|
80
|
-
}
|
|
81
|
-
const hierarchy = {
|
|
82
|
-
classes,
|
|
83
|
-
classIds,
|
|
84
|
-
classIndexes,
|
|
85
|
-
parentCounts,
|
|
86
|
-
parentIndexes,
|
|
87
|
-
parentIds
|
|
88
|
-
};
|
|
89
|
-
validateHierarchy(hierarchy);
|
|
90
|
-
return hierarchy;
|
|
91
|
-
}
|
|
92
|
-
// HELPER CODE
|
|
93
|
-
// Traverse over the hierarchy and process each instance with the endConditionCallback.
|
|
94
|
-
// When the endConditionCallback returns a value, the traversal stops and that value is returned.
|
|
95
|
-
function traverseHierarchy(hierarchy, instanceIndex, endConditionCallback) {
|
|
96
|
-
if (!hierarchy) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const parentCounts = hierarchy.parentCounts;
|
|
100
|
-
const parentIds = hierarchy.parentIds;
|
|
101
|
-
if (parentIds) {
|
|
102
|
-
return endConditionCallback(hierarchy, instanceIndex);
|
|
103
|
-
}
|
|
104
|
-
if (parentCounts > 0) {
|
|
105
|
-
return traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback);
|
|
106
|
-
}
|
|
107
|
-
return traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback);
|
|
108
|
-
}
|
|
109
|
-
exports.traverseHierarchy = traverseHierarchy;
|
|
110
|
-
// eslint-disable-next-line max-statements
|
|
111
|
-
function traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback) {
|
|
112
|
-
const classIds = hierarchy.classIds;
|
|
113
|
-
const parentCounts = hierarchy.parentCounts;
|
|
114
|
-
const parentIds = hierarchy.parentIds;
|
|
115
|
-
const parentIndexes = hierarchy.parentIndexes;
|
|
116
|
-
const instancesLength = classIds.length;
|
|
117
|
-
// Ignore instances that have already been visited. This occurs in diamond inheritance situations.
|
|
118
|
-
// Use a marker value to indicate that an instance has been visited, which increments with each run.
|
|
119
|
-
// This is more efficient than clearing the visited array every time.
|
|
120
|
-
const visited = scratchVisited;
|
|
121
|
-
visited.length = Math.max(visited.length, instancesLength);
|
|
122
|
-
const visitedMarker = ++marker;
|
|
123
|
-
const stack = scratchStack;
|
|
124
|
-
stack.length = 0;
|
|
125
|
-
stack.push(instanceIndex);
|
|
126
|
-
while (stack.length > 0) {
|
|
127
|
-
instanceIndex = stack.pop();
|
|
128
|
-
if (visited[instanceIndex] === visitedMarker) {
|
|
129
|
-
// This instance has already been visited, stop traversal
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
visited[instanceIndex] = visitedMarker;
|
|
133
|
-
const result = endConditionCallback(hierarchy, instanceIndex);
|
|
134
|
-
if (defined(result)) {
|
|
135
|
-
// The end condition was met, stop the traversal and return the result
|
|
136
|
-
return result;
|
|
137
|
-
}
|
|
138
|
-
const parentCount = parentCounts[instanceIndex];
|
|
139
|
-
const parentIndex = parentIndexes[instanceIndex];
|
|
140
|
-
for (let i = 0; i < parentCount; ++i) {
|
|
141
|
-
const parentId = parentIds[parentIndex + i];
|
|
142
|
-
// Stop the traversal when the instance has no parent (its parentId equals itself)
|
|
143
|
-
// else add the parent to the stack to continue the traversal.
|
|
144
|
-
if (parentId !== instanceIndex) {
|
|
145
|
-
stack.push(parentId);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
function traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback) {
|
|
152
|
-
let hasParent = true;
|
|
153
|
-
while (hasParent) {
|
|
154
|
-
const result = endConditionCallback(hierarchy, instanceIndex);
|
|
155
|
-
if (defined(result)) {
|
|
156
|
-
// The end condition was met, stop the traversal and return the result
|
|
157
|
-
return result;
|
|
158
|
-
}
|
|
159
|
-
const parentId = hierarchy.parentIds[instanceIndex];
|
|
160
|
-
hasParent = parentId !== instanceIndex;
|
|
161
|
-
instanceIndex = parentId;
|
|
162
|
-
}
|
|
163
|
-
throw new Error('traverseHierarchySingleParent');
|
|
164
|
-
}
|
|
165
|
-
// DEBUG CODE
|
|
166
|
-
function validateHierarchy(hierarchy) {
|
|
167
|
-
const scratchValidateStack = [];
|
|
168
|
-
const classIds = hierarchy.classIds;
|
|
169
|
-
const instancesLength = classIds.length;
|
|
170
|
-
for (let i = 0; i < instancesLength; ++i) {
|
|
171
|
-
validateInstance(hierarchy, i, stack);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function validateInstance(hierarchy, instanceIndex, stack) {
|
|
175
|
-
const parentCounts = hierarchy.parentCounts;
|
|
176
|
-
const parentIds = hierarchy.parentIds;
|
|
177
|
-
const parentIndexes = hierarchy.parentIndexes;
|
|
178
|
-
const classIds = hierarchy.classIds;
|
|
179
|
-
const instancesLength = classIds.length;
|
|
180
|
-
if (!defined(parentIds)) {
|
|
181
|
-
// No need to validate if there are no parents
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
assert(instanceIndex < instancesLength, `Parent index ${instanceIndex} exceeds the total number of instances: ${instancesLength}`);
|
|
185
|
-
assert(stack.indexOf(instanceIndex) === -1, 'Circular dependency detected in the batch table hierarchy.');
|
|
186
|
-
stack.push(instanceIndex);
|
|
187
|
-
const parentCount = defined(parentCounts) ? parentCounts[instanceIndex] : 1;
|
|
188
|
-
const parentIndex = defined(parentCounts) ? parentIndexes[instanceIndex] : instanceIndex;
|
|
189
|
-
for (let i = 0; i < parentCount; ++i) {
|
|
190
|
-
const parentId = parentIds[parentIndex + i];
|
|
191
|
-
// Stop the traversal when the instance has no parent (its parentId equals itself), else continue the traversal.
|
|
192
|
-
if (parentId !== instanceIndex) {
|
|
193
|
-
validateInstance(hierarchy, parentId, stack);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
stack.pop(instanceIndex);
|
|
197
|
-
}
|