@loaders.gl/3d-tiles 4.0.0-alpha.8 → 4.0.0-beta.1

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 (170) hide show
  1. package/dist/3d-tiles-archive/3d-tiles-archive-archive.d.ts +30 -0
  2. package/dist/3d-tiles-archive/3d-tiles-archive-archive.d.ts.map +1 -0
  3. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts +10 -0
  4. package/dist/3d-tiles-archive/3d-tiles-archive-parser.d.ts.map +1 -0
  5. package/dist/3d-tiles-archive-loader.d.ts +13 -0
  6. package/dist/3d-tiles-archive-loader.d.ts.map +1 -0
  7. package/dist/cesium-ion-loader.d.ts +2 -2
  8. package/dist/cesium-ion-loader.d.ts.map +1 -1
  9. package/dist/dist.min.js +10981 -4462
  10. package/dist/es5/3d-tiles-archive/3d-tiles-archive-archive.js +126 -0
  11. package/dist/es5/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -0
  12. package/dist/es5/3d-tiles-archive/3d-tiles-archive-parser.js +69 -0
  13. package/dist/es5/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -0
  14. package/dist/es5/3d-tiles-archive-loader.js +50 -0
  15. package/dist/es5/3d-tiles-archive-loader.js.map +1 -0
  16. package/dist/es5/cesium-ion-loader.js.map +1 -1
  17. package/dist/es5/index.js +14 -0
  18. package/dist/es5/index.js.map +1 -1
  19. package/dist/es5/lib/filesystems/tiles-3d-archive-file-system.js +151 -0
  20. package/dist/es5/lib/filesystems/tiles-3d-archive-file-system.js.map +1 -0
  21. package/dist/es5/lib/ion/ion.js +3 -9
  22. package/dist/es5/lib/ion/ion.js.map +1 -1
  23. package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js +63 -38
  24. package/dist/es5/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -1
  25. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js +3 -3
  26. package/dist/es5/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
  27. package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js +70 -55
  28. package/dist/es5/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -1
  29. package/dist/es5/lib/parsers/parse-3d-tile-composite.js +3 -1
  30. package/dist/es5/lib/parsers/parse-3d-tile-composite.js.map +1 -1
  31. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js +14 -12
  32. package/dist/es5/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
  33. package/dist/es5/lib/parsers/parse-3d-tile-header.js +14 -12
  34. package/dist/es5/lib/parsers/parse-3d-tile-header.js.map +1 -1
  35. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js +6 -6
  36. package/dist/es5/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
  37. package/dist/es5/lib/parsers/parse-3d-tile.js +3 -1
  38. package/dist/es5/lib/parsers/parse-3d-tile.js.map +1 -1
  39. package/dist/es5/lib/utils/version.js +1 -1
  40. package/dist/es5/lib/utils/version.js.map +1 -1
  41. package/dist/es5/tile-3d-subtree-loader.js.map +1 -1
  42. package/dist/es5/tile-3d-writer.js.map +1 -1
  43. package/dist/es5/tiles-3d-loader.js +2 -0
  44. package/dist/es5/tiles-3d-loader.js.map +1 -1
  45. package/dist/es5/types.js.map +1 -1
  46. package/dist/esm/3d-tiles-archive/3d-tiles-archive-archive.js +46 -0
  47. package/dist/esm/3d-tiles-archive/3d-tiles-archive-archive.js.map +1 -0
  48. package/dist/esm/3d-tiles-archive/3d-tiles-archive-parser.js +23 -0
  49. package/dist/esm/3d-tiles-archive/3d-tiles-archive-parser.js.map +1 -0
  50. package/dist/esm/3d-tiles-archive-loader.js +20 -0
  51. package/dist/esm/3d-tiles-archive-loader.js.map +1 -0
  52. package/dist/esm/cesium-ion-loader.js.map +1 -1
  53. package/dist/esm/index.js +2 -0
  54. package/dist/esm/index.js.map +1 -1
  55. package/dist/esm/lib/filesystems/tiles-3d-archive-file-system.js +49 -0
  56. package/dist/esm/lib/filesystems/tiles-3d-archive-file-system.js.map +1 -0
  57. package/dist/esm/lib/ion/ion.js +3 -9
  58. package/dist/esm/lib/ion/ion.js.map +1 -1
  59. package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js +45 -23
  60. package/dist/esm/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +1 -1
  61. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js +5 -6
  62. package/dist/esm/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +1 -1
  63. package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js +18 -24
  64. package/dist/esm/lib/parsers/helpers/parse-3d-tile-subtree.js.map +1 -1
  65. package/dist/esm/lib/parsers/parse-3d-tile-composite.js +3 -1
  66. package/dist/esm/lib/parsers/parse-3d-tile-composite.js.map +1 -1
  67. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js +7 -8
  68. package/dist/esm/lib/parsers/parse-3d-tile-gltf.js.map +1 -1
  69. package/dist/esm/lib/parsers/parse-3d-tile-header.js +8 -5
  70. package/dist/esm/lib/parsers/parse-3d-tile-header.js.map +1 -1
  71. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js +2 -4
  72. package/dist/esm/lib/parsers/parse-3d-tile-point-cloud.js.map +1 -1
  73. package/dist/esm/lib/parsers/parse-3d-tile.js +3 -1
  74. package/dist/esm/lib/parsers/parse-3d-tile.js.map +1 -1
  75. package/dist/esm/lib/utils/version.js +1 -1
  76. package/dist/esm/lib/utils/version.js.map +1 -1
  77. package/dist/esm/tile-3d-subtree-loader.js.map +1 -1
  78. package/dist/esm/tile-3d-writer.js.map +1 -1
  79. package/dist/esm/tiles-3d-loader.js +2 -0
  80. package/dist/esm/tiles-3d-loader.js.map +1 -1
  81. package/dist/esm/types.js.map +1 -1
  82. package/dist/index.d.ts +3 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts +32 -0
  85. package/dist/lib/filesystems/tiles-3d-archive-file-system.d.ts.map +1 -0
  86. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -1
  87. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
  88. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  89. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
  90. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
  91. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  92. package/dist/lib/parsers/parse-3d-tile-header.d.ts +30 -2
  93. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  94. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +1 -1
  95. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  96. package/dist/lib/parsers/parse-3d-tile.d.ts +1 -1
  97. package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
  98. package/dist/tile-3d-subtree-loader.d.ts +3 -3
  99. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  100. package/dist/tile-3d-writer.d.ts +2 -2
  101. package/dist/tile-3d-writer.d.ts.map +1 -1
  102. package/dist/tiles-3d-loader.d.ts +2 -1
  103. package/dist/tiles-3d-loader.d.ts.map +1 -1
  104. package/dist/types.d.ts +49 -8
  105. package/dist/types.d.ts.map +1 -1
  106. package/package.json +10 -8
  107. package/src/3d-tiles-archive/3d-tiles-archive-archive.ts +85 -0
  108. package/src/3d-tiles-archive/3d-tiles-archive-parser.ts +52 -0
  109. package/src/3d-tiles-archive-loader.ts +47 -0
  110. package/src/cesium-ion-loader.ts +2 -3
  111. package/src/index.ts +3 -0
  112. package/src/lib/filesystems/tiles-3d-archive-file-system.ts +97 -0
  113. package/src/lib/ion/ion.ts +3 -3
  114. package/src/lib/parsers/helpers/parse-3d-implicit-tiles.ts +76 -32
  115. package/src/lib/parsers/helpers/parse-3d-tile-gltf-view.ts +8 -3
  116. package/src/lib/parsers/helpers/parse-3d-tile-subtree.ts +44 -62
  117. package/src/lib/parsers/parse-3d-tile-composite.ts +1 -1
  118. package/src/lib/parsers/parse-3d-tile-gltf.ts +11 -10
  119. package/src/lib/parsers/parse-3d-tile-header.ts +39 -6
  120. package/src/lib/parsers/parse-3d-tile-point-cloud.ts +10 -3
  121. package/src/lib/parsers/parse-3d-tile.ts +2 -2
  122. package/src/tile-3d-subtree-loader.ts +3 -3
  123. package/src/tile-3d-writer.ts +2 -2
  124. package/src/tiles-3d-loader.ts +16 -4
  125. package/src/types.ts +52 -9
  126. package/dist/bundle.js +0 -5
  127. package/dist/cesium-ion-loader.js +0 -41
  128. package/dist/index.js +0 -26
  129. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js +0 -113
  130. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +0 -197
  131. package/dist/lib/classes/tile-3d-batch-table.js +0 -245
  132. package/dist/lib/classes/tile-3d-feature-table.js +0 -72
  133. package/dist/lib/constants.js +0 -26
  134. package/dist/lib/encoders/encode-3d-tile-batched-model.js +0 -46
  135. package/dist/lib/encoders/encode-3d-tile-composite.js +0 -24
  136. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +0 -38
  137. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +0 -39
  138. package/dist/lib/encoders/encode-3d-tile.js +0 -33
  139. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +0 -30
  140. package/dist/lib/ion/ion.js +0 -68
  141. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +0 -65
  142. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +0 -30
  143. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +0 -42
  144. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +0 -266
  145. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +0 -96
  146. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +0 -28
  147. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +0 -104
  148. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +0 -93
  149. package/dist/lib/parsers/helpers/parse-utils.js +0 -32
  150. package/dist/lib/parsers/parse-3d-tile-batched-model.js +0 -33
  151. package/dist/lib/parsers/parse-3d-tile-composite.js +0 -24
  152. package/dist/lib/parsers/parse-3d-tile-gltf.js +0 -28
  153. package/dist/lib/parsers/parse-3d-tile-header.js +0 -192
  154. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +0 -172
  155. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +0 -433
  156. package/dist/lib/parsers/parse-3d-tile.js +0 -33
  157. package/dist/lib/utils/obb/s2-corners-to-obb.js +0 -37
  158. package/dist/lib/utils/s2/converters/s2-to-boundary.js +0 -61
  159. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +0 -36
  160. package/dist/lib/utils/s2/converters/s2-to-region.js +0 -59
  161. package/dist/lib/utils/s2/index.js +0 -23
  162. package/dist/lib/utils/s2/s2-geometry-functions.js +0 -29
  163. package/dist/lib/utils/s2/s2-token-functions.js +0 -68
  164. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +0 -32
  165. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +0 -260
  166. package/dist/lib/utils/version.js +0 -7
  167. package/dist/tile-3d-subtree-loader.js +0 -23
  168. package/dist/tile-3d-writer.js +0 -27
  169. package/dist/tiles-3d-loader.js +0 -76
  170. package/dist/types.js +0 -2
@@ -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;
@@ -1,72 +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 math_1 = require("@loaders.gl/math");
6
- // Reference:
7
- // https://github.com/AnalyticalGraphicsInc/cesium/blob/1de96d087f0b17575eb1a3f736407b348c765d59/Source/Scene/Cesium3DTileFeatureTable.js
8
- class Tile3DFeatureTable {
9
- constructor(featureTableJson, featureTableBinary) {
10
- this.featuresLength = 0;
11
- this._cachedTypedArrays = {};
12
- this.json = featureTableJson;
13
- this.buffer = featureTableBinary;
14
- }
15
- getExtension(extensionName) {
16
- return this.json.extensions && this.json.extensions[extensionName];
17
- }
18
- hasProperty(propertyName) {
19
- return Boolean(this.json[propertyName]);
20
- }
21
- getGlobalProperty(propertyName, componentType = math_1.GL.UNSIGNED_INT, componentLength = 1) {
22
- const jsonValue = this.json[propertyName];
23
- if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
24
- return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, 1, jsonValue.byteOffset);
25
- }
26
- return jsonValue;
27
- }
28
- getPropertyArray(propertyName, componentType, componentLength) {
29
- const jsonValue = this.json[propertyName];
30
- if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
31
- if ('componentType' in jsonValue) {
32
- componentType = math_1.GLType.fromName(jsonValue.componentType);
33
- }
34
- return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, this.featuresLength, jsonValue.byteOffset);
35
- }
36
- return this._getTypedArrayFromArray(propertyName, componentType, jsonValue);
37
- }
38
- getProperty(propertyName, componentType, componentLength, featureId, result) {
39
- const jsonValue = this.json[propertyName];
40
- if (!jsonValue) {
41
- return jsonValue;
42
- }
43
- const typedArray = this.getPropertyArray(propertyName, componentType, componentLength);
44
- if (componentLength === 1) {
45
- return typedArray[featureId];
46
- }
47
- for (let i = 0; i < componentLength; ++i) {
48
- result[i] = typedArray[componentLength * featureId + i];
49
- }
50
- return result;
51
- }
52
- // HELPERS
53
- _getTypedArrayFromBinary(propertyName, componentType, componentLength, count, byteOffset) {
54
- const cachedTypedArrays = this._cachedTypedArrays;
55
- let typedArray = cachedTypedArrays[propertyName];
56
- if (!typedArray) {
57
- typedArray = math_1.GLType.createTypedArray(componentType, this.buffer.buffer, this.buffer.byteOffset + byteOffset, count * componentLength);
58
- cachedTypedArrays[propertyName] = typedArray;
59
- }
60
- return typedArray;
61
- }
62
- _getTypedArrayFromArray(propertyName, componentType, array) {
63
- const cachedTypedArrays = this._cachedTypedArrays;
64
- let typedArray = cachedTypedArrays[propertyName];
65
- if (!typedArray) {
66
- typedArray = math_1.GLType.createTypedArray(componentType, array);
67
- cachedTypedArrays[propertyName] = typedArray;
68
- }
69
- return typedArray;
70
- }
71
- }
72
- exports.default = Tile3DFeatureTable;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- // TILE TYPES
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.TILE3D_OPTIMIZATION_HINT = exports.MAGIC_ARRAY = exports.TILE3D_TYPES = exports.TILE3D_TYPE = void 0;
5
- exports.TILE3D_TYPE = {
6
- COMPOSITE: 'cmpt',
7
- POINT_CLOUD: 'pnts',
8
- BATCHED_3D_MODEL: 'b3dm',
9
- INSTANCED_3D_MODEL: 'i3dm',
10
- GEOMETRY: 'geom',
11
- VECTOR: 'vect',
12
- GLTF: 'glTF'
13
- };
14
- exports.TILE3D_TYPES = Object.keys(exports.TILE3D_TYPE);
15
- exports.MAGIC_ARRAY = {
16
- BATCHED_MODEL: [98, 51, 100, 109],
17
- INSTANCED_MODEL: [105, 51, 100, 109],
18
- POINT_CLOUD: [112, 110, 116, 115],
19
- COMPOSITE: [99, 109, 112, 116]
20
- };
21
- // TILE CONSTANTS
22
- exports.TILE3D_OPTIMIZATION_HINT = {
23
- NOT_COMPUTED: -1,
24
- USE_OPTIMIZATION: 1,
25
- SKIP_OPTIMIZATION: 0
26
- };
@@ -1,46 +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.encodeBatchedModel3DTile = void 0;
6
- const loader_utils_1 = require("@loaders.gl/loader-utils");
7
- const constants_1 = require("../constants");
8
- const encode_3d_tile_header_1 = require("./helpers/encode-3d-tile-header");
9
- // Procedurally encode the tile array dataView for testing purposes
10
- function encodeBatchedModel3DTile(tile, dataView, byteOffset, options) {
11
- const { featuresLength = 0, batchTable } = tile;
12
- const featureTableJson = {
13
- BATCH_LENGTH: featuresLength
14
- };
15
- const featureTableJsonString = JSON.stringify(featureTableJson);
16
- const batchTableJsonString = batchTable ? JSON.stringify(batchTable) : '';
17
- const featureTableJsonByteLength = (0, loader_utils_1.padToNBytes)(featureTableJsonString.length, 8);
18
- const batchTableJsonByteLength = batchTableJsonString
19
- ? (0, loader_utils_1.padToNBytes)(batchTableJsonString.length, 8)
20
- : 0;
21
- // Add default magic for this tile type
22
- tile = { magic: constants_1.MAGIC_ARRAY.BATCHED_MODEL, ...tile };
23
- const byteOffsetStart = byteOffset;
24
- byteOffset = (0, encode_3d_tile_header_1.encode3DTileHeader)(tile, dataView, byteOffset);
25
- if (dataView) {
26
- dataView.setUint32(12, featureTableJsonByteLength, true); // featureTableJsonByteLength
27
- dataView.setUint32(16, 0, true); // featureTableBinaryByteLength
28
- dataView.setUint32(20, batchTableJsonByteLength, true); // batchTableJsonByteLength
29
- dataView.setUint32(24, 0, true); // batchTableBinaryByteLength
30
- }
31
- byteOffset += 16;
32
- // TODO feature table binary
33
- byteOffset = (0, loader_utils_1.copyPaddedStringToDataView)(dataView, byteOffset, featureTableJsonString, 8);
34
- if (batchTable) {
35
- byteOffset = (0, loader_utils_1.copyPaddedStringToDataView)(dataView, byteOffset, batchTableJsonString, 8);
36
- }
37
- // Add encoded GLTF to the end of data
38
- const gltfEncoded = tile.gltfEncoded;
39
- if (gltfEncoded) {
40
- byteOffset = (0, loader_utils_1.copyBinaryToDataView)(dataView, byteOffset, gltfEncoded, gltfEncoded.byteLength);
41
- }
42
- // Go "back" and rewrite the tile's `byteLength` now that we know the value
43
- (0, encode_3d_tile_header_1.encode3DTileByteLength)(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
44
- return byteOffset;
45
- }
46
- exports.encodeBatchedModel3DTile = encodeBatchedModel3DTile;
@@ -1,24 +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.encodeComposite3DTile = void 0;
6
- const constants_1 = require("../constants");
7
- const encode_3d_tile_header_1 = require("./helpers/encode-3d-tile-header");
8
- function encodeComposite3DTile(tile, dataView, byteOffset, options, encode3DTile) {
9
- // Add default magic for this tile type
10
- tile = { magic: constants_1.MAGIC_ARRAY.COMPOSITE, tiles: [], ...tile };
11
- const byteOffsetStart = byteOffset;
12
- byteOffset += (0, encode_3d_tile_header_1.encode3DTileHeader)(tile, dataView, byteOffset);
13
- if (dataView) {
14
- dataView.setUint32(byteOffset, tile.tiles.length, true); // tilesLength
15
- }
16
- byteOffset += 4;
17
- for (let i = 0; i < tile.tiles.length; ++i) {
18
- byteOffset += encode3DTile(tile.tiles[i], dataView, byteOffset, options);
19
- }
20
- // Go "back" and rewrite the tile's `byteLength` now that we know the value
21
- (0, encode_3d_tile_header_1.encode3DTileByteLength)(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
22
- return byteOffset;
23
- }
24
- exports.encodeComposite3DTile = encodeComposite3DTile;
@@ -1,38 +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.encodeInstancedModel3DTile = void 0;
6
- const loader_utils_1 = require("@loaders.gl/loader-utils");
7
- const constants_1 = require("../constants");
8
- const encode_3d_tile_header_1 = require("./helpers/encode-3d-tile-header");
9
- // Procedurally encode the tile array buffer for testing purposes
10
- // eslint-disable-next-line max-statements
11
- function encodeInstancedModel3DTile(tile, dataView, byteOffset, options) {
12
- const { featuresLength = 1, gltfFormat = 1, gltfUri = '' } = tile;
13
- const gltfUriByteLength = gltfUri.length;
14
- const featureTableJson = {
15
- INSTANCES_LENGTH: featuresLength,
16
- POSITION: new Array(featuresLength * 3).fill(0)
17
- };
18
- const featureTableJsonString = JSON.stringify(featureTableJson);
19
- const featureTableJsonByteLength = featureTableJsonString.length;
20
- // Add default magic for this tile type
21
- tile = { magic: constants_1.MAGIC_ARRAY.INSTANCED_MODEL, ...tile };
22
- const byteOffsetStart = byteOffset;
23
- byteOffset = (0, encode_3d_tile_header_1.encode3DTileHeader)(tile, dataView, 0);
24
- if (dataView) {
25
- dataView.setUint32(12, featureTableJsonByteLength, true); // featureTableJsonByteLength
26
- dataView.setUint32(16, 0, true); // featureTableBinaryByteLength
27
- dataView.setUint32(20, 0, true); // batchTableJsonByteLength
28
- dataView.setUint32(24, 0, true); // batchTableBinaryByteLength
29
- dataView.setUint32(28, gltfFormat, true); // gltfFormat
30
- }
31
- byteOffset += 20;
32
- byteOffset += (0, loader_utils_1.copyStringToDataView)(dataView, byteOffset, featureTableJsonString, featureTableJsonByteLength);
33
- byteOffset += (0, loader_utils_1.copyStringToDataView)(dataView, byteOffset, gltfUri, gltfUriByteLength);
34
- // Go "back" and rewrite the tile's `byteLength` now that we know the value
35
- (0, encode_3d_tile_header_1.encode3DTileByteLength)(dataView, byteOffsetStart, byteOffset - byteOffsetStart);
36
- return byteOffset;
37
- }
38
- exports.encodeInstancedModel3DTile = encodeInstancedModel3DTile;