@loaders.gl/3d-tiles 4.0.0-alpha.23 → 4.0.0-alpha.25

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 (75) hide show
  1. package/dist/cesium-ion-loader.d.ts +2 -2
  2. package/dist/cesium-ion-loader.d.ts.map +1 -1
  3. package/dist/dist.min.js +421 -270
  4. package/dist/es5/3d-tiles-archive-loader.js +1 -1
  5. package/dist/es5/cesium-ion-loader.js.map +1 -1
  6. package/dist/es5/lib/utils/version.js +1 -1
  7. package/dist/es5/tile-3d-subtree-loader.js.map +1 -1
  8. package/dist/es5/tile-3d-writer.js.map +1 -1
  9. package/dist/es5/types.js.map +1 -1
  10. package/dist/esm/3d-tiles-archive-loader.js +1 -1
  11. package/dist/esm/cesium-ion-loader.js.map +1 -1
  12. package/dist/esm/lib/utils/version.js +1 -1
  13. package/dist/esm/tile-3d-subtree-loader.js.map +1 -1
  14. package/dist/esm/tile-3d-writer.js.map +1 -1
  15. package/dist/esm/types.js.map +1 -1
  16. package/dist/tile-3d-subtree-loader.d.ts +3 -3
  17. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  18. package/dist/tile-3d-writer.d.ts +2 -2
  19. package/dist/tile-3d-writer.d.ts.map +1 -1
  20. package/dist/types.d.ts +2 -5
  21. package/dist/types.d.ts.map +1 -1
  22. package/package.json +8 -8
  23. package/src/cesium-ion-loader.ts +2 -2
  24. package/src/tile-3d-subtree-loader.ts +3 -3
  25. package/src/tile-3d-writer.ts +2 -2
  26. package/src/types.ts +3 -5
  27. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +0 -72
  28. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +0 -33
  29. package/dist/3d-tiles-archive-loader.js +0 -31
  30. package/dist/bundle.js +0 -5
  31. package/dist/cesium-ion-loader.js +0 -40
  32. package/dist/index.js +0 -30
  33. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +0 -113
  34. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +0 -197
  35. package/dist/lib/classes/tile-3d-batch-table.js +0 -245
  36. package/dist/lib/classes/tile-3d-feature-table.js +0 -72
  37. package/dist/lib/constants.js +0 -26
  38. package/dist/lib/encoders/encode-3d-tile-batched-model.js +0 -46
  39. package/dist/lib/encoders/encode-3d-tile-composite.js +0 -24
  40. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +0 -38
  41. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +0 -39
  42. package/dist/lib/encoders/encode-3d-tile.js +0 -33
  43. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +0 -30
  44. package/dist/lib/filesystems/tiles-3d-archive-file-system.js +0 -75
  45. package/dist/lib/ion/ion.js +0 -68
  46. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
  47. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -30
  48. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -42
  49. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -303
  50. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -96
  51. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +0 -28
  52. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -87
  53. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +0 -93
  54. package/dist/lib/parsers/helpers/parse-utils.js +0 -32
  55. package/dist/lib/parsers/parse-3d-tile-batched-model.js +0 -33
  56. package/dist/lib/parsers/parse-3d-tile-composite.js +0 -24
  57. package/dist/lib/parsers/parse-3d-tile-gltf.js +0 -29
  58. package/dist/lib/parsers/parse-3d-tile-header.js +0 -194
  59. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +0 -172
  60. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +0 -441
  61. package/dist/lib/parsers/parse-3d-tile.js +0 -33
  62. package/dist/lib/utils/obb/s2-corners-to-obb.js +0 -37
  63. package/dist/lib/utils/s2/converters/s2-to-boundary.js +0 -61
  64. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +0 -36
  65. package/dist/lib/utils/s2/converters/s2-to-region.js +0 -59
  66. package/dist/lib/utils/s2/index.js +0 -23
  67. package/dist/lib/utils/s2/s2-geometry-functions.js +0 -29
  68. package/dist/lib/utils/s2/s2-token-functions.js +0 -68
  69. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -32
  70. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +0 -260
  71. package/dist/lib/utils/version.js +0 -7
  72. package/dist/tile-3d-subtree-loader.js +0 -23
  73. package/dist/tile-3d-writer.js +0 -27
  74. package/dist/tiles-3d-loader.js +0 -80
  75. package/dist/types.js +0 -2
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tiles3DArchiveFileLoader = void 0;
4
- const loader_utils_1 = require("@loaders.gl/loader-utils");
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 loader_utils_1.DataViewFile(new DataView(data)));
30
- return archive.getFile(options['3d-tiles-archive']?.path ?? '');
31
- }
package/dist/bundle.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- const moduleExports = require('./index');
4
- globalThis.loaders = globalThis.loaders || {};
5
- module.exports = Object.assign(globalThis.loaders, moduleExports);
@@ -1,40 +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
- ...tiles_3d_loader_1.Tiles3DLoader.options['3d-tiles'],
37
- accessToken: null
38
- }
39
- }
40
- };
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
- }
@@ -1,245 +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
- const loader_utils_1 = require("@loaders.gl/loader-utils");
6
- const tile_3d_accessor_utils_1 = require("./helpers/tile-3d-accessor-utils");
7
- const tile_3d_batch_table_hierarchy_1 = require("./tile-3d-batch-table-hierarchy");
8
- function defined(x) {
9
- return x !== undefined && x !== null;
10
- }
11
- const clone = (x, y) => x;
12
- // These top level fields in the batch table json are not properties
13
- const IGNORED_PROPERTY_FIELDS = {
14
- HIERARCHY: true,
15
- extensions: true,
16
- extras: true
17
- };
18
- // The size of this array equals the maximum instance count among all loaded tiles, which has the potential to be large.
19
- class Tile3DBatchTableParser {
20
- constructor(json, binary, featureCount, options = {}) {
21
- (0, loader_utils_1.assert)(featureCount >= 0);
22
- this.json = json || {};
23
- this.binary = binary;
24
- this.featureCount = featureCount;
25
- this._extensions = this.json?.extensions || {};
26
- // Copy all top-level property fields from the json object, ignoring special fields
27
- this._properties = {};
28
- for (const propertyName in this.json) {
29
- if (!IGNORED_PROPERTY_FIELDS[propertyName]) {
30
- this._properties[propertyName] = this.json[propertyName];
31
- }
32
- }
33
- this._binaryProperties = this._initializeBinaryProperties();
34
- // TODO: hierarchy support is only partially implemented and not tested
35
- if (options['3DTILES_batch_table_hierarchy']) {
36
- this._hierarchy = (0, tile_3d_batch_table_hierarchy_1.initializeHierarchy)(this, this.json, this.binary);
37
- }
38
- }
39
- getExtension(extensionName) {
40
- return this.json && this.json.extensions && this.json.extensions[extensionName];
41
- }
42
- memorySizeInBytes() {
43
- return 0;
44
- }
45
- isClass(batchId, className) {
46
- this._checkBatchId(batchId);
47
- (0, loader_utils_1.assert)(typeof className === 'string', className);
48
- // extension: 3DTILES_batch_table_hierarchy
49
- if (this._hierarchy) {
50
- // PERFORMANCE_IDEA : cache results in the ancestor classes
51
- // to speed up this check if this area becomes a hotspot
52
- // PERFORMANCE_IDEA : treat class names as integers for faster comparisons
53
- const result = (0, tile_3d_batch_table_hierarchy_1.traverseHierarchy)(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
54
- const classId = hierarchy.classIds[instanceIndex];
55
- const instanceClass = hierarchy.classes[classId];
56
- return instanceClass.name === className;
57
- });
58
- return defined(result);
59
- }
60
- return false;
61
- }
62
- isExactClass(batchId, className) {
63
- (0, loader_utils_1.assert)(typeof className === 'string', className);
64
- return this.getExactClassName(batchId) === className;
65
- }
66
- getExactClassName(batchId) {
67
- this._checkBatchId(batchId);
68
- // extension: 3DTILES_batch_table_hierarchy
69
- if (this._hierarchy) {
70
- const classId = this._hierarchy.classIds[batchId];
71
- const instanceClass = this._hierarchy.classes[classId];
72
- return instanceClass.name;
73
- }
74
- return undefined;
75
- }
76
- hasProperty(batchId, name) {
77
- this._checkBatchId(batchId);
78
- (0, loader_utils_1.assert)(typeof name === 'string', name);
79
- return defined(this._properties[name]) || this._hasPropertyInHierarchy(batchId, name);
80
- }
81
- getPropertyNames(batchId, results) {
82
- this._checkBatchId(batchId);
83
- results = defined(results) ? results : [];
84
- results.length = 0;
85
- const propertyNames = Object.keys(this._properties);
86
- results.push(...propertyNames);
87
- if (this._hierarchy) {
88
- this._getPropertyNamesInHierarchy(batchId, results);
89
- }
90
- return results;
91
- }
92
- getProperty(batchId, name) {
93
- this._checkBatchId(batchId);
94
- (0, loader_utils_1.assert)(typeof name === 'string', name);
95
- if (this._binaryProperties) {
96
- const binaryProperty = this._binaryProperties[name];
97
- if (defined(binaryProperty)) {
98
- return this._getBinaryProperty(binaryProperty, batchId);
99
- }
100
- }
101
- const propertyValues = this._properties[name];
102
- if (defined(propertyValues)) {
103
- return clone(propertyValues[batchId], true);
104
- }
105
- // EXTENSION: 3DTILES_batch_table_hierarchy
106
- if (this._hierarchy) {
107
- const hierarchyProperty = this._getHierarchyProperty(batchId, name);
108
- if (defined(hierarchyProperty)) {
109
- return hierarchyProperty;
110
- }
111
- }
112
- return undefined;
113
- }
114
- setProperty(batchId, name, value) {
115
- const featureCount = this.featureCount;
116
- this._checkBatchId(batchId);
117
- (0, loader_utils_1.assert)(typeof name === 'string', name);
118
- if (this._binaryProperties) {
119
- const binaryProperty = this._binaryProperties[name];
120
- if (binaryProperty) {
121
- this._setBinaryProperty(binaryProperty, batchId, value);
122
- return;
123
- }
124
- }
125
- // EXTENSION: 3DTILES_batch_table_hierarchy
126
- if (this._hierarchy) {
127
- if (this._setHierarchyProperty(this, batchId, name, value)) {
128
- return;
129
- }
130
- }
131
- let propertyValues = this._properties[name];
132
- if (!defined(propertyValues)) {
133
- // Property does not exist. Create it.
134
- this._properties[name] = new Array(featureCount);
135
- propertyValues = this._properties[name];
136
- }
137
- propertyValues[batchId] = clone(value, true);
138
- }
139
- // PRIVATE METHODS
140
- _checkBatchId(batchId) {
141
- const valid = batchId >= 0 && batchId < this.featureCount;
142
- if (!valid) {
143
- throw new Error('batchId not in range [0, featureCount - 1].');
144
- }
145
- }
146
- _getBinaryProperty(binaryProperty, index) {
147
- return binaryProperty.unpack(binaryProperty.typedArray, index);
148
- }
149
- _setBinaryProperty(binaryProperty, index, value) {
150
- binaryProperty.pack(value, binaryProperty.typedArray, index);
151
- }
152
- _initializeBinaryProperties() {
153
- let binaryProperties = null;
154
- for (const name in this._properties) {
155
- const property = this._properties[name];
156
- const binaryProperty = this._initializeBinaryProperty(name, property);
157
- // Store any information needed to access the binary data, including the typed array,
158
- // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
159
- if (binaryProperty) {
160
- binaryProperties = binaryProperties || {};
161
- binaryProperties[name] = binaryProperty;
162
- }
163
- }
164
- return binaryProperties;
165
- }
166
- _initializeBinaryProperty(name, property) {
167
- if ('byteOffset' in property) {
168
- // This is a binary property
169
- const tile3DAccessor = property;
170
- (0, loader_utils_1.assert)(this.binary, `Property ${name} requires a batch table binary.`);
171
- (0, loader_utils_1.assert)(tile3DAccessor.type, `Property ${name} requires a type.`);
172
- const accessor = (0, tile_3d_accessor_utils_1.createTypedArrayFromAccessor)(tile3DAccessor, this.binary.buffer, this.binary.byteOffset | 0, this.featureCount);
173
- // Store any information needed to access the binary data, including the typed array,
174
- // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
175
- return {
176
- typedArray: accessor.values,
177
- componentCount: accessor.size,
178
- unpack: accessor.unpacker,
179
- pack: accessor.packer
180
- };
181
- }
182
- return null;
183
- }
184
- // EXTENSION SUPPORT: 3DTILES_batch_table_hierarchy
185
- _hasPropertyInHierarchy(batchId, name) {
186
- if (!this._hierarchy) {
187
- return false;
188
- }
189
- const result = (0, tile_3d_batch_table_hierarchy_1.traverseHierarchy)(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
190
- const classId = hierarchy.classIds[instanceIndex];
191
- const instances = hierarchy.classes[classId].instances;
192
- return defined(instances[name]);
193
- });
194
- return defined(result);
195
- }
196
- _getPropertyNamesInHierarchy(batchId, results) {
197
- (0, tile_3d_batch_table_hierarchy_1.traverseHierarchy)(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
198
- const classId = hierarchy.classIds[instanceIndex];
199
- const instances = hierarchy.classes[classId].instances;
200
- for (const name in instances) {
201
- if (instances.hasOwnProperty(name)) {
202
- if (results.indexOf(name) === -1) {
203
- results.push(name);
204
- }
205
- }
206
- }
207
- });
208
- }
209
- _getHierarchyProperty(batchId, name) {
210
- return (0, tile_3d_batch_table_hierarchy_1.traverseHierarchy)(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
211
- const classId = hierarchy.classIds[instanceIndex];
212
- const instanceClass = hierarchy.classes[classId];
213
- const indexInClass = hierarchy.classIndexes[instanceIndex];
214
- const propertyValues = instanceClass.instances[name];
215
- if (defined(propertyValues)) {
216
- if (defined(propertyValues.typedArray)) {
217
- return this._getBinaryProperty(propertyValues, indexInClass);
218
- }
219
- return clone(propertyValues[indexInClass], true);
220
- }
221
- return null;
222
- });
223
- }
224
- _setHierarchyProperty(batchTable, batchId, name, value) {
225
- const result = (0, tile_3d_batch_table_hierarchy_1.traverseHierarchy)(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
226
- const classId = hierarchy.classIds[instanceIndex];
227
- const instanceClass = hierarchy.classes[classId];
228
- const indexInClass = hierarchy.classIndexes[instanceIndex];
229
- const propertyValues = instanceClass.instances[name];
230
- if (defined(propertyValues)) {
231
- (0, loader_utils_1.assert)(instanceIndex === batchId, `Inherited property "${name}" is read-only.`);
232
- if (defined(propertyValues.typedArray)) {
233
- this._setBinaryProperty(propertyValues, indexInClass, value);
234
- }
235
- else {
236
- propertyValues[indexInClass] = clone(value, true);
237
- }
238
- return true;
239
- }
240
- return false;
241
- });
242
- return defined(result);
243
- }
244
- }
245
- exports.default = Tile3DBatchTableParser;