@loaders.gl/3d-tiles 4.2.0-alpha.4 → 4.2.0-alpha.5
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.js +66 -41
- 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/3d-tiles-archive-parser.js +26 -16
- package/dist/3d-tiles-archive-loader.js +25 -14
- package/dist/cesium-ion-loader.js +34 -30
- package/dist/dist.dev.js +1963 -1037
- package/dist/dist.min.js +32 -0
- package/dist/index.cjs +122 -337
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +103 -87
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +179 -155
- package/dist/lib/classes/tile-3d-batch-table.js +232 -217
- package/dist/lib/classes/tile-3d-feature-table.js +62 -59
- package/dist/lib/constants.js +19 -15
- package/dist/lib/encoders/encode-3d-tile-batched-model.js +40 -35
- package/dist/lib/encoders/encode-3d-tile-composite.js +19 -17
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js +32 -31
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js +31 -32
- package/dist/lib/encoders/encode-3d-tile.js +23 -19
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js +23 -23
- package/dist/lib/ion/ion.js +55 -54
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +57 -51
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +21 -18
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +35 -20
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -4
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +269 -234
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +2 -2
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +83 -55
- package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js +23 -14
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +82 -54
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +2 -2
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +79 -68
- package/dist/lib/parsers/helpers/parse-utils.js +19 -14
- package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-batched-model.js +21 -17
- package/dist/lib/parsers/parse-3d-tile-composite.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js +18 -14
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.js +22 -14
- package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-header.js +168 -159
- package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js +153 -123
- package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js +380 -174
- package/dist/lib/parsers/parse-3d-tile.d.ts +2 -2
- package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
- package/dist/lib/parsers/parse-3d-tile.js +24 -24
- package/dist/lib/utils/obb/s2-corners-to-obb.js +29 -16
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js +55 -35
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js +31 -20
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts +1 -1
- package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -1
- package/dist/lib/utils/s2/converters/s2-to-region.js +51 -35
- package/dist/lib/utils/s2/index.d.ts +7 -7
- package/dist/lib/utils/s2/index.d.ts.map +1 -1
- package/dist/lib/utils/s2/index.js +3 -1
- package/dist/lib/utils/s2/s2-geometry-functions.js +19 -5
- package/dist/lib/utils/s2/s2-token-functions.js +51 -22
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +1 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +23 -9
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js +218 -157
- package/dist/lib/utils/version.js +3 -1
- package/dist/tile-3d-subtree-loader.d.ts +1 -1
- package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
- package/dist/tile-3d-subtree-loader.js +15 -10
- package/dist/tile-3d-writer.js +19 -14
- package/dist/tiles-3d-loader.js +65 -55
- package/dist/types.js +3 -1
- package/package.json +11 -10
- package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
- package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
- package/dist/3d-tiles-archive-loader.js.map +0 -1
- package/dist/cesium-ion-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
- package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
- package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
- package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
- package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
- package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
- package/dist/lib/ion/ion.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
- package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
- package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
- package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
- package/dist/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
- package/dist/lib/utils/s2/converters/s2-to-region.js.map +0 -1
- package/dist/lib/utils/s2/index.js.map +0 -1
- package/dist/lib/utils/s2/s2-geometry-functions.js.map +0 -1
- package/dist/lib/utils/s2/s2-token-functions.js.map +0 -1
- package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
- package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
- package/dist/lib/utils/version.js.map +0 -1
- package/dist/tile-3d-subtree-loader.js.map +0 -1
- package/dist/tile-3d-writer.js.map +0 -1
- package/dist/tiles-3d-loader.js.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,96 +1,112 @@
|
|
|
1
|
-
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
import { GLType } from '@loaders.gl/math'; // '@math.gl/geometry';
|
|
2
5
|
import { assert } from '@loaders.gl/loader-utils';
|
|
3
6
|
const COMPONENTS_PER_ATTRIBUTE = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
SCALAR: 1,
|
|
8
|
+
VEC2: 2,
|
|
9
|
+
VEC3: 3,
|
|
10
|
+
VEC4: 4,
|
|
11
|
+
MAT2: 4,
|
|
12
|
+
MAT3: 9,
|
|
13
|
+
MAT4: 16
|
|
11
14
|
};
|
|
15
|
+
// TODO - could just return typed array views...
|
|
16
|
+
// prettier-ignore
|
|
12
17
|
const UNPACKER = {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
]
|
|
20
38
|
};
|
|
21
39
|
const PACKER = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
values
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
values
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
values
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
+
}
|
|
76
95
|
};
|
|
77
96
|
export function createTypedArrayFromAccessor(tile3DAccessor, buffer, byteOffset, length) {
|
|
78
|
-
|
|
79
|
-
componentType
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
packer
|
|
94
|
-
};
|
|
97
|
+
const { componentType } = tile3DAccessor;
|
|
98
|
+
assert(tile3DAccessor.componentType);
|
|
99
|
+
const type = typeof componentType === 'string' ? 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 = GLType.createTypedArray(type, buffer, byteOffset, size * length);
|
|
105
|
+
return {
|
|
106
|
+
values,
|
|
107
|
+
type,
|
|
108
|
+
size,
|
|
109
|
+
unpacker,
|
|
110
|
+
packer
|
|
111
|
+
};
|
|
95
112
|
}
|
|
96
|
-
//# sourceMappingURL=tile-3d-accessor-utils.js.map
|
|
@@ -1,171 +1,195 @@
|
|
|
1
|
-
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT AND Apache-2.0
|
|
3
|
+
// Copyright vis.gl contributors
|
|
4
|
+
// This file is derived from the Cesium code base under Apache 2 license
|
|
5
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
6
|
+
// TODO - Finish hierarchy suypport: this file is only half ported
|
|
7
|
+
/* eslint-disable */
|
|
8
|
+
// @ts-nocheck
|
|
9
|
+
const defined = (x) => x !== undefined;
|
|
2
10
|
export function initializeHierarchy(batchTable, jsonHeader, binaryBody) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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);
|
|
18
27
|
}
|
|
28
|
+
// eslint-disable-next-line max-statements
|
|
19
29
|
function initializeHierarchyValues(hierarchyJson, binaryBody) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
let i;
|
|
31
|
+
let classId;
|
|
32
|
+
let binaryAccessor;
|
|
33
|
+
const instancesLength = hierarchyJson.instancesLength;
|
|
34
|
+
const classes = hierarchyJson.classes;
|
|
35
|
+
let classIds = hierarchyJson.classIds;
|
|
36
|
+
let parentCounts = hierarchyJson.parentCounts;
|
|
37
|
+
let parentIds = hierarchyJson.parentIds;
|
|
38
|
+
let parentIdsLength = instancesLength;
|
|
39
|
+
if (defined(classIds.byteOffset)) {
|
|
40
|
+
classIds.componentType = defaultValue(classIds.componentType, GL.UNSIGNED_SHORT);
|
|
41
|
+
classIds.type = AttributeType.SCALAR;
|
|
42
|
+
binaryAccessor = getBinaryAccessor(classIds);
|
|
43
|
+
classIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + classIds.byteOffset, instancesLength);
|
|
44
|
+
}
|
|
45
|
+
let parentIndexes;
|
|
46
|
+
if (defined(parentCounts)) {
|
|
47
|
+
if (defined(parentCounts.byteOffset)) {
|
|
48
|
+
parentCounts.componentType = defaultValue(parentCounts.componentType, GL.UNSIGNED_SHORT);
|
|
49
|
+
parentCounts.type = AttributeType.SCALAR;
|
|
50
|
+
binaryAccessor = getBinaryAccessor(parentCounts);
|
|
51
|
+
parentCounts = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentCounts.byteOffset, instancesLength);
|
|
52
|
+
}
|
|
53
|
+
parentIndexes = new Uint16Array(instancesLength);
|
|
54
|
+
parentIdsLength = 0;
|
|
55
|
+
for (i = 0; i < instancesLength; ++i) {
|
|
56
|
+
parentIndexes[i] = parentIdsLength;
|
|
57
|
+
parentIdsLength += parentCounts[i];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (defined(parentIds) && defined(parentIds.byteOffset)) {
|
|
61
|
+
parentIds.componentType = defaultValue(parentIds.componentType, GL.UNSIGNED_SHORT);
|
|
62
|
+
parentIds.type = AttributeType.SCALAR;
|
|
63
|
+
binaryAccessor = getBinaryAccessor(parentIds);
|
|
64
|
+
parentIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentIds.byteOffset, parentIdsLength);
|
|
65
|
+
}
|
|
66
|
+
const classesLength = classes.length;
|
|
67
|
+
for (i = 0; i < classesLength; ++i) {
|
|
68
|
+
const classInstancesLength = classes[i].length;
|
|
69
|
+
const properties = classes[i].instances;
|
|
70
|
+
const binaryProperties = getBinaryProperties(classInstancesLength, properties, binaryBody);
|
|
71
|
+
classes[i].instances = combine(binaryProperties, properties);
|
|
72
|
+
}
|
|
73
|
+
const classCounts = new Array(classesLength).fill(0);
|
|
74
|
+
const classIndexes = new Uint16Array(instancesLength);
|
|
45
75
|
for (i = 0; i < instancesLength; ++i) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const binaryProperties = getBinaryProperties(classInstancesLength, properties, binaryBody);
|
|
61
|
-
classes[i].instances = combine(binaryProperties, properties);
|
|
62
|
-
}
|
|
63
|
-
const classCounts = new Array(classesLength).fill(0);
|
|
64
|
-
const classIndexes = new Uint16Array(instancesLength);
|
|
65
|
-
for (i = 0; i < instancesLength; ++i) {
|
|
66
|
-
classId = classIds[i];
|
|
67
|
-
classIndexes[i] = classCounts[classId];
|
|
68
|
-
++classCounts[classId];
|
|
69
|
-
}
|
|
70
|
-
const hierarchy = {
|
|
71
|
-
classes,
|
|
72
|
-
classIds,
|
|
73
|
-
classIndexes,
|
|
74
|
-
parentCounts,
|
|
75
|
-
parentIndexes,
|
|
76
|
-
parentIds
|
|
77
|
-
};
|
|
78
|
-
validateHierarchy(hierarchy);
|
|
79
|
-
return hierarchy;
|
|
76
|
+
classId = classIds[i];
|
|
77
|
+
classIndexes[i] = classCounts[classId];
|
|
78
|
+
++classCounts[classId];
|
|
79
|
+
}
|
|
80
|
+
const hierarchy = {
|
|
81
|
+
classes,
|
|
82
|
+
classIds,
|
|
83
|
+
classIndexes,
|
|
84
|
+
parentCounts,
|
|
85
|
+
parentIndexes,
|
|
86
|
+
parentIds
|
|
87
|
+
};
|
|
88
|
+
validateHierarchy(hierarchy);
|
|
89
|
+
return hierarchy;
|
|
80
90
|
}
|
|
91
|
+
// HELPER CODE
|
|
92
|
+
// Traverse over the hierarchy and process each instance with the endConditionCallback.
|
|
93
|
+
// When the endConditionCallback returns a value, the traversal stops and that value is returned.
|
|
81
94
|
export function traverseHierarchy(hierarchy, instanceIndex, endConditionCallback) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
if (!hierarchy) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const parentCounts = hierarchy.parentCounts;
|
|
99
|
+
const parentIds = hierarchy.parentIds;
|
|
100
|
+
if (parentIds) {
|
|
101
|
+
return endConditionCallback(hierarchy, instanceIndex);
|
|
102
|
+
}
|
|
103
|
+
if (parentCounts > 0) {
|
|
104
|
+
return traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback);
|
|
105
|
+
}
|
|
106
|
+
return traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback);
|
|
94
107
|
}
|
|
108
|
+
// eslint-disable-next-line max-statements
|
|
95
109
|
function traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
110
|
+
const classIds = hierarchy.classIds;
|
|
111
|
+
const parentCounts = hierarchy.parentCounts;
|
|
112
|
+
const parentIds = hierarchy.parentIds;
|
|
113
|
+
const parentIndexes = hierarchy.parentIndexes;
|
|
114
|
+
const instancesLength = classIds.length;
|
|
115
|
+
// Ignore instances that have already been visited. This occurs in diamond inheritance situations.
|
|
116
|
+
// Use a marker value to indicate that an instance has been visited, which increments with each run.
|
|
117
|
+
// This is more efficient than clearing the visited array every time.
|
|
118
|
+
const visited = scratchVisited;
|
|
119
|
+
visited.length = Math.max(visited.length, instancesLength);
|
|
120
|
+
const visitedMarker = ++marker;
|
|
121
|
+
const stack = scratchStack;
|
|
122
|
+
stack.length = 0;
|
|
123
|
+
stack.push(instanceIndex);
|
|
124
|
+
while (stack.length > 0) {
|
|
125
|
+
instanceIndex = stack.pop();
|
|
126
|
+
if (visited[instanceIndex] === visitedMarker) {
|
|
127
|
+
// This instance has already been visited, stop traversal
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
visited[instanceIndex] = visitedMarker;
|
|
131
|
+
const result = endConditionCallback(hierarchy, instanceIndex);
|
|
132
|
+
if (defined(result)) {
|
|
133
|
+
// The end condition was met, stop the traversal and return the result
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
const parentCount = parentCounts[instanceIndex];
|
|
137
|
+
const parentIndex = parentIndexes[instanceIndex];
|
|
138
|
+
for (let i = 0; i < parentCount; ++i) {
|
|
139
|
+
const parentId = parentIds[parentIndex + i];
|
|
140
|
+
// Stop the traversal when the instance has no parent (its parentId equals itself)
|
|
141
|
+
// else add the parent to the stack to continue the traversal.
|
|
142
|
+
if (parentId !== instanceIndex) {
|
|
143
|
+
stack.push(parentId);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
124
146
|
}
|
|
125
|
-
|
|
126
|
-
return null;
|
|
147
|
+
return null;
|
|
127
148
|
}
|
|
128
149
|
function traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
150
|
+
let hasParent = true;
|
|
151
|
+
while (hasParent) {
|
|
152
|
+
const result = endConditionCallback(hierarchy, instanceIndex);
|
|
153
|
+
if (defined(result)) {
|
|
154
|
+
// The end condition was met, stop the traversal and return the result
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
const parentId = hierarchy.parentIds[instanceIndex];
|
|
158
|
+
hasParent = parentId !== instanceIndex;
|
|
159
|
+
instanceIndex = parentId;
|
|
160
|
+
}
|
|
161
|
+
throw new Error('traverseHierarchySingleParent');
|
|
140
162
|
}
|
|
163
|
+
// DEBUG CODE
|
|
141
164
|
function validateHierarchy(hierarchy) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
165
|
+
const scratchValidateStack = [];
|
|
166
|
+
const classIds = hierarchy.classIds;
|
|
167
|
+
const instancesLength = classIds.length;
|
|
168
|
+
for (let i = 0; i < instancesLength; ++i) {
|
|
169
|
+
validateInstance(hierarchy, i, stack);
|
|
170
|
+
}
|
|
148
171
|
}
|
|
149
172
|
function validateInstance(hierarchy, instanceIndex, stack) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
const parentCounts = hierarchy.parentCounts;
|
|
174
|
+
const parentIds = hierarchy.parentIds;
|
|
175
|
+
const parentIndexes = hierarchy.parentIndexes;
|
|
176
|
+
const classIds = hierarchy.classIds;
|
|
177
|
+
const instancesLength = classIds.length;
|
|
178
|
+
if (!defined(parentIds)) {
|
|
179
|
+
// No need to validate if there are no parents
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
assert(instanceIndex < instancesLength, `Parent index ${instanceIndex} exceeds the total number of instances: ${instancesLength}`);
|
|
183
|
+
assert(stack.indexOf(instanceIndex) === -1, 'Circular dependency detected in the batch table hierarchy.');
|
|
184
|
+
stack.push(instanceIndex);
|
|
185
|
+
const parentCount = defined(parentCounts) ? parentCounts[instanceIndex] : 1;
|
|
186
|
+
const parentIndex = defined(parentCounts) ? parentIndexes[instanceIndex] : instanceIndex;
|
|
187
|
+
for (let i = 0; i < parentCount; ++i) {
|
|
188
|
+
const parentId = parentIds[parentIndex + i];
|
|
189
|
+
// Stop the traversal when the instance has no parent (its parentId equals itself), else continue the traversal.
|
|
190
|
+
if (parentId !== instanceIndex) {
|
|
191
|
+
validateInstance(hierarchy, parentId, stack);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
stack.pop(instanceIndex);
|
|
170
195
|
}
|
|
171
|
-
//# sourceMappingURL=tile-3d-batch-table-hierarchy.js.map
|