@loaders.gl/3d-tiles 4.2.0-alpha.4 → 4.2.0-alpha.6

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 (144) hide show
  1. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +68 -41
  2. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +1 -1
  3. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -1
  4. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js +26 -16
  5. package/dist/3d-tiles-archive-loader.js +26 -15
  6. package/dist/cesium-ion-loader.js +34 -30
  7. package/dist/dist.dev.js +8824 -6420
  8. package/dist/dist.min.js +32 -0
  9. package/dist/index.cjs +138 -340
  10. package/dist/index.cjs.map +7 -0
  11. package/dist/index.d.ts +13 -13
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +7 -1
  14. package/dist/lib/classes/helpers/tile-3d-accessor-utils.d.ts +1 -1
  15. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +103 -87
  16. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +179 -155
  17. package/dist/lib/classes/tile-3d-batch-table.d.ts +1 -1
  18. package/dist/lib/classes/tile-3d-batch-table.js +241 -217
  19. package/dist/lib/classes/tile-3d-feature-table.js +64 -59
  20. package/dist/lib/constants.js +19 -15
  21. package/dist/lib/encoders/encode-3d-tile-batched-model.js +40 -35
  22. package/dist/lib/encoders/encode-3d-tile-composite.js +19 -17
  23. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +32 -31
  24. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +31 -32
  25. package/dist/lib/encoders/encode-3d-tile.js +23 -19
  26. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +23 -23
  27. package/dist/lib/ion/ion.js +55 -54
  28. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +1 -1
  29. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
  30. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +57 -51
  31. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +1 -1
  32. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
  33. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +21 -18
  34. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +35 -20
  35. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -4
  36. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
  37. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +269 -234
  38. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +2 -2
  39. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  40. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +83 -55
  41. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +1 -1
  42. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
  43. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +23 -14
  44. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +1 -1
  45. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
  46. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +82 -54
  47. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +2 -2
  48. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
  49. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +79 -68
  50. package/dist/lib/parsers/helpers/parse-utils.js +19 -14
  51. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +2 -2
  52. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
  53. package/dist/lib/parsers/parse-3d-tile-batched-model.js +21 -17
  54. package/dist/lib/parsers/parse-3d-tile-composite.d.ts +2 -2
  55. package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
  56. package/dist/lib/parsers/parse-3d-tile-composite.js +18 -14
  57. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
  58. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  59. package/dist/lib/parsers/parse-3d-tile-gltf.js +22 -14
  60. package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -2
  61. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  62. package/dist/lib/parsers/parse-3d-tile-header.js +168 -159
  63. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -2
  64. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
  65. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +153 -123
  66. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +2 -2
  67. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  68. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +380 -174
  69. package/dist/lib/parsers/parse-3d-tile.d.ts +2 -2
  70. package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
  71. package/dist/lib/parsers/parse-3d-tile.js +24 -24
  72. package/dist/lib/utils/obb/s2-corners-to-obb.js +29 -16
  73. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +1 -1
  74. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -1
  75. package/dist/lib/utils/s2/converters/s2-to-boundary.js +55 -35
  76. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +31 -20
  77. package/dist/lib/utils/s2/converters/s2-to-region.d.ts +1 -1
  78. package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -1
  79. package/dist/lib/utils/s2/converters/s2-to-region.js +51 -35
  80. package/dist/lib/utils/s2/index.d.ts +7 -7
  81. package/dist/lib/utils/s2/index.d.ts.map +1 -1
  82. package/dist/lib/utils/s2/index.js +3 -1
  83. package/dist/lib/utils/s2/s2-geometry-functions.js +19 -5
  84. package/dist/lib/utils/s2/s2-token-functions.js +51 -22
  85. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +1 -1
  86. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -1
  87. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +23 -9
  88. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +218 -157
  89. package/dist/lib/utils/version.js +4 -2
  90. package/dist/tile-3d-subtree-loader.d.ts +1 -1
  91. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  92. package/dist/tile-3d-subtree-loader.js +15 -10
  93. package/dist/tile-3d-writer.js +19 -14
  94. package/dist/tiles-3d-loader.js +65 -55
  95. package/dist/types.js +3 -1
  96. package/package.json +17 -12
  97. package/src/lib/parsers/helpers/parse-3d-implicit-tiles.ts +1 -1
  98. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
  99. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
  100. package/dist/3d-tiles-archive-loader.js.map +0 -1
  101. package/dist/cesium-ion-loader.js.map +0 -1
  102. package/dist/index.js.map +0 -1
  103. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
  104. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
  105. package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
  106. package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
  107. package/dist/lib/constants.js.map +0 -1
  108. package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
  109. package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
  110. package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
  111. package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
  112. package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
  113. package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
  114. package/dist/lib/ion/ion.js.map +0 -1
  115. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
  116. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
  117. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
  118. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
  119. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
  120. package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
  121. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
  122. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
  123. package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
  124. package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
  125. package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
  126. package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
  127. package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
  128. package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
  129. package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
  130. package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
  131. package/dist/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
  132. package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
  133. package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
  134. package/dist/lib/utils/s2/converters/s2-to-region.js.map +0 -1
  135. package/dist/lib/utils/s2/index.js.map +0 -1
  136. package/dist/lib/utils/s2/s2-geometry-functions.js.map +0 -1
  137. package/dist/lib/utils/s2/s2-token-functions.js.map +0 -1
  138. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
  139. package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
  140. package/dist/lib/utils/version.js.map +0 -1
  141. package/dist/tile-3d-subtree-loader.js.map +0 -1
  142. package/dist/tile-3d-writer.js.map +0 -1
  143. package/dist/tiles-3d-loader.js.map +0 -1
  144. package/dist/types.js.map +0 -1
@@ -1,96 +1,112 @@
1
- import { GLType } from '@loaders.gl/math';
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
- SCALAR: 1,
5
- VEC2: 2,
6
- VEC3: 3,
7
- VEC4: 4,
8
- MAT2: 4,
9
- MAT3: 9,
10
- MAT4: 16
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
- SCALAR: (values, i) => values[i],
14
- VEC2: (values, i) => [values[2 * i + 0], values[2 * i + 1]],
15
- VEC3: (values, i) => [values[3 * i + 0], values[3 * i + 1], values[3 * i + 2]],
16
- VEC4: (values, i) => [values[4 * i + 0], values[4 * i + 1], values[4 * i + 2], values[4 * i + 3]],
17
- MAT2: (values, i) => [values[4 * i + 0], values[4 * i + 1], values[4 * i + 2], values[4 * i + 3]],
18
- MAT3: (values, i) => [values[9 * i + 0], values[9 * i + 1], values[9 * i + 2], values[9 * i + 3], values[9 * i + 4], values[9 * i + 5], values[9 * i + 6], values[9 * i + 7], values[9 * i + 8]],
19
- MAT4: (values, i) => [values[16 * i + 0], values[16 * i + 1], values[16 * i + 2], values[16 * i + 3], values[16 * i + 4], values[16 * i + 5], values[16 * i + 6], values[16 * i + 7], values[16 * i + 8], values[16 * i + 9], values[16 * i + 10], values[16 * i + 11], values[16 * i + 12], values[16 * i + 13], values[16 * i + 14], values[16 * i + 15]]
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
- SCALAR: (x, values, i) => {
23
- values[i] = x;
24
- },
25
- VEC2: (x, values, i) => {
26
- values[2 * i + 0] = x[0];
27
- values[2 * i + 1] = x[1];
28
- },
29
- VEC3: (x, values, i) => {
30
- values[3 * i + 0] = x[0];
31
- values[3 * i + 1] = x[1];
32
- values[3 * i + 2] = x[2];
33
- },
34
- VEC4: (x, values, i) => {
35
- values[4 * i + 0] = x[0];
36
- values[4 * i + 1] = x[1];
37
- values[4 * i + 2] = x[2];
38
- values[4 * i + 3] = x[3];
39
- },
40
- MAT2: (x, values, i) => {
41
- values[4 * i + 0] = x[0];
42
- values[4 * i + 1] = x[1];
43
- values[4 * i + 2] = x[2];
44
- values[4 * i + 3] = x[3];
45
- },
46
- MAT3: (x, values, i) => {
47
- values[9 * i + 0] = x[0];
48
- values[9 * i + 1] = x[1];
49
- values[9 * i + 2] = x[2];
50
- values[9 * i + 3] = x[3];
51
- values[9 * i + 4] = x[4];
52
- values[9 * i + 5] = x[5];
53
- values[9 * i + 6] = x[6];
54
- values[9 * i + 7] = x[7];
55
- values[9 * i + 8] = x[8];
56
- values[9 * i + 9] = x[9];
57
- },
58
- MAT4: (x, values, i) => {
59
- values[16 * i + 0] = x[0];
60
- values[16 * i + 1] = x[1];
61
- values[16 * i + 2] = x[2];
62
- values[16 * i + 3] = x[3];
63
- values[16 * i + 4] = x[4];
64
- values[16 * i + 5] = x[5];
65
- values[16 * i + 6] = x[6];
66
- values[16 * i + 7] = x[7];
67
- values[16 * i + 8] = x[8];
68
- values[16 * i + 9] = x[9];
69
- values[16 * i + 10] = x[10];
70
- values[16 * i + 11] = x[11];
71
- values[16 * i + 12] = x[12];
72
- values[16 * i + 13] = x[13];
73
- values[16 * i + 14] = x[14];
74
- values[16 * i + 15] = x[15];
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
- const {
79
- componentType
80
- } = tile3DAccessor;
81
- assert(tile3DAccessor.componentType);
82
- const type = typeof componentType === 'string' ? GLType.fromName(componentType) : componentType;
83
- const size = COMPONENTS_PER_ATTRIBUTE[tile3DAccessor.type];
84
- const unpacker = UNPACKER[tile3DAccessor.type];
85
- const packer = PACKER[tile3DAccessor.type];
86
- byteOffset += tile3DAccessor.byteOffset;
87
- const values = GLType.createTypedArray(type, buffer, byteOffset, size * length);
88
- return {
89
- values,
90
- type,
91
- size,
92
- unpacker,
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
- const defined = x => x !== undefined;
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
- if (!jsonHeader) {
4
- return null;
5
- }
6
- let hierarchy = batchTable.getExtension('3DTILES_batch_table_hierarchy');
7
- const legacyHierarchy = jsonHeader.HIERARCHY;
8
- if (legacyHierarchy) {
9
- console.warn('3D Tile Parser: HIERARCHY is deprecated. Use 3DTILES_batch_table_hierarchy.');
10
- jsonHeader.extensions = jsonHeader.extensions || {};
11
- jsonHeader.extensions['3DTILES_batch_table_hierarchy'] = legacyHierarchy;
12
- hierarchy = legacyHierarchy;
13
- }
14
- if (!hierarchy) {
15
- return null;
16
- }
17
- return initializeHierarchyValues(hierarchy, 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);
18
27
  }
28
+ // eslint-disable-next-line max-statements
19
29
  function initializeHierarchyValues(hierarchyJson, binaryBody) {
20
- let i;
21
- let classId;
22
- let binaryAccessor;
23
- const instancesLength = hierarchyJson.instancesLength;
24
- const classes = hierarchyJson.classes;
25
- let classIds = hierarchyJson.classIds;
26
- let parentCounts = hierarchyJson.parentCounts;
27
- let parentIds = hierarchyJson.parentIds;
28
- let parentIdsLength = instancesLength;
29
- if (defined(classIds.byteOffset)) {
30
- classIds.componentType = defaultValue(classIds.componentType, GL.UNSIGNED_SHORT);
31
- classIds.type = AttributeType.SCALAR;
32
- binaryAccessor = getBinaryAccessor(classIds);
33
- classIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + classIds.byteOffset, instancesLength);
34
- }
35
- let parentIndexes;
36
- if (defined(parentCounts)) {
37
- if (defined(parentCounts.byteOffset)) {
38
- parentCounts.componentType = defaultValue(parentCounts.componentType, GL.UNSIGNED_SHORT);
39
- parentCounts.type = AttributeType.SCALAR;
40
- binaryAccessor = getBinaryAccessor(parentCounts);
41
- parentCounts = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentCounts.byteOffset, instancesLength);
42
- }
43
- parentIndexes = new Uint16Array(instancesLength);
44
- parentIdsLength = 0;
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
- parentIndexes[i] = parentIdsLength;
47
- parentIdsLength += parentCounts[i];
48
- }
49
- }
50
- if (defined(parentIds) && defined(parentIds.byteOffset)) {
51
- parentIds.componentType = defaultValue(parentIds.componentType, GL.UNSIGNED_SHORT);
52
- parentIds.type = AttributeType.SCALAR;
53
- binaryAccessor = getBinaryAccessor(parentIds);
54
- parentIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentIds.byteOffset, parentIdsLength);
55
- }
56
- const classesLength = classes.length;
57
- for (i = 0; i < classesLength; ++i) {
58
- const classInstancesLength = classes[i].length;
59
- const properties = classes[i].instances;
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
- if (!hierarchy) {
83
- return;
84
- }
85
- const parentCounts = hierarchy.parentCounts;
86
- const parentIds = hierarchy.parentIds;
87
- if (parentIds) {
88
- return endConditionCallback(hierarchy, instanceIndex);
89
- }
90
- if (parentCounts > 0) {
91
- return traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback);
92
- }
93
- return traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback);
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
- const classIds = hierarchy.classIds;
97
- const parentCounts = hierarchy.parentCounts;
98
- const parentIds = hierarchy.parentIds;
99
- const parentIndexes = hierarchy.parentIndexes;
100
- const instancesLength = classIds.length;
101
- const visited = scratchVisited;
102
- visited.length = Math.max(visited.length, instancesLength);
103
- const visitedMarker = ++marker;
104
- const stack = scratchStack;
105
- stack.length = 0;
106
- stack.push(instanceIndex);
107
- while (stack.length > 0) {
108
- instanceIndex = stack.pop();
109
- if (visited[instanceIndex] === visitedMarker) {
110
- continue;
111
- }
112
- visited[instanceIndex] = visitedMarker;
113
- const result = endConditionCallback(hierarchy, instanceIndex);
114
- if (defined(result)) {
115
- return result;
116
- }
117
- const parentCount = parentCounts[instanceIndex];
118
- const parentIndex = parentIndexes[instanceIndex];
119
- for (let i = 0; i < parentCount; ++i) {
120
- const parentId = parentIds[parentIndex + i];
121
- if (parentId !== instanceIndex) {
122
- stack.push(parentId);
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
- let hasParent = true;
130
- while (hasParent) {
131
- const result = endConditionCallback(hierarchy, instanceIndex);
132
- if (defined(result)) {
133
- return result;
134
- }
135
- const parentId = hierarchy.parentIds[instanceIndex];
136
- hasParent = parentId !== instanceIndex;
137
- instanceIndex = parentId;
138
- }
139
- throw new Error('traverseHierarchySingleParent');
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
- const scratchValidateStack = [];
143
- const classIds = hierarchy.classIds;
144
- const instancesLength = classIds.length;
145
- for (let i = 0; i < instancesLength; ++i) {
146
- validateInstance(hierarchy, i, stack);
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
- const parentCounts = hierarchy.parentCounts;
151
- const parentIds = hierarchy.parentIds;
152
- const parentIndexes = hierarchy.parentIndexes;
153
- const classIds = hierarchy.classIds;
154
- const instancesLength = classIds.length;
155
- if (!defined(parentIds)) {
156
- return;
157
- }
158
- assert(instanceIndex < instancesLength, `Parent index ${instanceIndex} exceeds the total number of instances: ${instancesLength}`);
159
- assert(stack.indexOf(instanceIndex) === -1, 'Circular dependency detected in the batch table hierarchy.');
160
- stack.push(instanceIndex);
161
- const parentCount = defined(parentCounts) ? parentCounts[instanceIndex] : 1;
162
- const parentIndex = defined(parentCounts) ? parentIndexes[instanceIndex] : instanceIndex;
163
- for (let i = 0; i < parentCount; ++i) {
164
- const parentId = parentIds[parentIndex + i];
165
- if (parentId !== instanceIndex) {
166
- validateInstance(hierarchy, parentId, stack);
167
- }
168
- }
169
- stack.pop(instanceIndex);
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
@@ -21,7 +21,7 @@ export default class Tile3DBatchTableParser {
21
21
  _setBinaryProperty(binaryProperty: any, index: any, value: any): void;
22
22
  _initializeBinaryProperties(): Record<string, any> | null;
23
23
  _initializeBinaryProperty(name: any, property: any): {
24
- typedArray: import("@math.gl/types").TypedArray;
24
+ typedArray: import("@math.gl/core").TypedArray;
25
25
  componentCount: any;
26
26
  unpack: any;
27
27
  pack: any;