@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,230 +1,254 @@
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
1
6
  import { assert } from '@loaders.gl/loader-utils';
2
7
  import { createTypedArrayFromAccessor } from "./helpers/tile-3d-accessor-utils.js";
3
8
  import { initializeHierarchy, traverseHierarchy } from "./tile-3d-batch-table-hierarchy.js";
4
9
  function defined(x) {
5
- return x !== undefined && x !== null;
10
+ return x !== undefined && x !== null;
6
11
  }
7
12
  const clone = (x, y) => x;
13
+ // These top level fields in the batch table json are not properties
8
14
  const IGNORED_PROPERTY_FIELDS = {
9
- HIERARCHY: true,
10
- extensions: true,
11
- extras: true
15
+ HIERARCHY: true, // Deprecated HIERARCHY property
16
+ extensions: true,
17
+ extras: true
12
18
  };
19
+ // The size of this array equals the maximum instance count among all loaded tiles, which has the potential to be large.
13
20
  export default class Tile3DBatchTableParser {
14
- constructor(json, binary, featureCount) {
15
- var _this$json;
16
- let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
17
- this.json = void 0;
18
- this.binary = void 0;
19
- this.featureCount = void 0;
20
- this._extensions = void 0;
21
- this._properties = void 0;
22
- this._binaryProperties = void 0;
23
- this._hierarchy = void 0;
24
- assert(featureCount >= 0);
25
- this.json = json || {};
26
- this.binary = binary;
27
- this.featureCount = featureCount;
28
- this._extensions = ((_this$json = this.json) === null || _this$json === void 0 ? void 0 : _this$json.extensions) || {};
29
- this._properties = {};
30
- for (const propertyName in this.json) {
31
- if (!IGNORED_PROPERTY_FIELDS[propertyName]) {
32
- this._properties[propertyName] = this.json[propertyName];
33
- }
34
- }
35
- this._binaryProperties = this._initializeBinaryProperties();
36
- if (options['3DTILES_batch_table_hierarchy']) {
37
- this._hierarchy = initializeHierarchy(this, this.json, this.binary);
38
- }
39
- }
40
- getExtension(extensionName) {
41
- return this.json && this.json.extensions && this.json.extensions[extensionName];
42
- }
43
- memorySizeInBytes() {
44
- return 0;
45
- }
46
- isClass(batchId, className) {
47
- this._checkBatchId(batchId);
48
- assert(typeof className === 'string', className);
49
- if (this._hierarchy) {
50
- const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
51
- const classId = hierarchy.classIds[instanceIndex];
52
- const instanceClass = hierarchy.classes[classId];
53
- return instanceClass.name === className;
54
- });
55
- return defined(result);
56
- }
57
- return false;
58
- }
59
- isExactClass(batchId, className) {
60
- assert(typeof className === 'string', className);
61
- return this.getExactClassName(batchId) === className;
62
- }
63
- getExactClassName(batchId) {
64
- this._checkBatchId(batchId);
65
- if (this._hierarchy) {
66
- const classId = this._hierarchy.classIds[batchId];
67
- const instanceClass = this._hierarchy.classes[classId];
68
- return instanceClass.name;
69
- }
70
- return undefined;
71
- }
72
- hasProperty(batchId, name) {
73
- this._checkBatchId(batchId);
74
- assert(typeof name === 'string', name);
75
- return defined(this._properties[name]) || this._hasPropertyInHierarchy(batchId, name);
76
- }
77
- getPropertyNames(batchId, results) {
78
- this._checkBatchId(batchId);
79
- results = defined(results) ? results : [];
80
- results.length = 0;
81
- const propertyNames = Object.keys(this._properties);
82
- results.push(...propertyNames);
83
- if (this._hierarchy) {
84
- this._getPropertyNamesInHierarchy(batchId, results);
85
- }
86
- return results;
87
- }
88
- getProperty(batchId, name) {
89
- this._checkBatchId(batchId);
90
- assert(typeof name === 'string', name);
91
- if (this._binaryProperties) {
92
- const binaryProperty = this._binaryProperties[name];
93
- if (defined(binaryProperty)) {
94
- return this._getBinaryProperty(binaryProperty, batchId);
95
- }
96
- }
97
- const propertyValues = this._properties[name];
98
- if (defined(propertyValues)) {
99
- return clone(propertyValues[batchId], true);
100
- }
101
- if (this._hierarchy) {
102
- const hierarchyProperty = this._getHierarchyProperty(batchId, name);
103
- if (defined(hierarchyProperty)) {
104
- return hierarchyProperty;
105
- }
106
- }
107
- return undefined;
108
- }
109
- setProperty(batchId, name, value) {
110
- const featureCount = this.featureCount;
111
- this._checkBatchId(batchId);
112
- assert(typeof name === 'string', name);
113
- if (this._binaryProperties) {
114
- const binaryProperty = this._binaryProperties[name];
115
- if (binaryProperty) {
116
- this._setBinaryProperty(binaryProperty, batchId, value);
117
- return;
118
- }
119
- }
120
- if (this._hierarchy) {
121
- if (this._setHierarchyProperty(this, batchId, name, value)) {
122
- return;
123
- }
124
- }
125
- let propertyValues = this._properties[name];
126
- if (!defined(propertyValues)) {
127
- this._properties[name] = new Array(featureCount);
128
- propertyValues = this._properties[name];
129
- }
130
- propertyValues[batchId] = clone(value, true);
131
- }
132
- _checkBatchId(batchId) {
133
- const valid = batchId >= 0 && batchId < this.featureCount;
134
- if (!valid) {
135
- throw new Error('batchId not in range [0, featureCount - 1].');
136
- }
137
- }
138
- _getBinaryProperty(binaryProperty, index) {
139
- return binaryProperty.unpack(binaryProperty.typedArray, index);
140
- }
141
- _setBinaryProperty(binaryProperty, index, value) {
142
- binaryProperty.pack(value, binaryProperty.typedArray, index);
143
- }
144
- _initializeBinaryProperties() {
145
- let binaryProperties = null;
146
- for (const name in this._properties) {
147
- const property = this._properties[name];
148
- const binaryProperty = this._initializeBinaryProperty(name, property);
149
- if (binaryProperty) {
150
- binaryProperties = binaryProperties || {};
151
- binaryProperties[name] = binaryProperty;
152
- }
153
- }
154
- return binaryProperties;
155
- }
156
- _initializeBinaryProperty(name, property) {
157
- if ('byteOffset' in property) {
158
- const tile3DAccessor = property;
159
- assert(this.binary, `Property ${name} requires a batch table binary.`);
160
- assert(tile3DAccessor.type, `Property ${name} requires a type.`);
161
- const accessor = createTypedArrayFromAccessor(tile3DAccessor, this.binary.buffer, this.binary.byteOffset | 0, this.featureCount);
162
- return {
163
- typedArray: accessor.values,
164
- componentCount: accessor.size,
165
- unpack: accessor.unpacker,
166
- pack: accessor.packer
167
- };
168
- }
169
- return null;
170
- }
171
- _hasPropertyInHierarchy(batchId, name) {
172
- if (!this._hierarchy) {
173
- return false;
174
- }
175
- const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
176
- const classId = hierarchy.classIds[instanceIndex];
177
- const instances = hierarchy.classes[classId].instances;
178
- return defined(instances[name]);
179
- });
180
- return defined(result);
181
- }
182
- _getPropertyNamesInHierarchy(batchId, results) {
183
- traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
184
- const classId = hierarchy.classIds[instanceIndex];
185
- const instances = hierarchy.classes[classId].instances;
186
- for (const name in instances) {
187
- if (instances.hasOwnProperty(name)) {
188
- if (results.indexOf(name) === -1) {
189
- results.push(name);
190
- }
21
+ json;
22
+ binary;
23
+ featureCount;
24
+ _extensions;
25
+ // Copy all top-level property fields from the json object, ignoring special fields
26
+ _properties;
27
+ _binaryProperties;
28
+ // TODO: hierarchy support is only partially implemented and not tested
29
+ _hierarchy;
30
+ constructor(json, binary, featureCount, options = {}) {
31
+ assert(featureCount >= 0);
32
+ this.json = json || {};
33
+ this.binary = binary;
34
+ this.featureCount = featureCount;
35
+ this._extensions = this.json?.extensions || {};
36
+ // Copy all top-level property fields from the json object, ignoring special fields
37
+ this._properties = {};
38
+ for (const propertyName in this.json) {
39
+ if (!IGNORED_PROPERTY_FIELDS[propertyName]) {
40
+ this._properties[propertyName] = this.json[propertyName];
41
+ }
191
42
  }
192
- }
193
- });
194
- }
195
- _getHierarchyProperty(batchId, name) {
196
- return traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
197
- const classId = hierarchy.classIds[instanceIndex];
198
- const instanceClass = hierarchy.classes[classId];
199
- const indexInClass = hierarchy.classIndexes[instanceIndex];
200
- const propertyValues = instanceClass.instances[name];
201
- if (defined(propertyValues)) {
202
- if (defined(propertyValues.typedArray)) {
203
- return this._getBinaryProperty(propertyValues, indexInClass);
43
+ this._binaryProperties = this._initializeBinaryProperties();
44
+ // TODO: hierarchy support is only partially implemented and not tested
45
+ if (options['3DTILES_batch_table_hierarchy']) {
46
+ this._hierarchy = initializeHierarchy(this, this.json, this.binary);
204
47
  }
205
- return clone(propertyValues[indexInClass], true);
206
- }
207
- return null;
208
- });
209
- }
210
- _setHierarchyProperty(batchTable, batchId, name, value) {
211
- const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
212
- const classId = hierarchy.classIds[instanceIndex];
213
- const instanceClass = hierarchy.classes[classId];
214
- const indexInClass = hierarchy.classIndexes[instanceIndex];
215
- const propertyValues = instanceClass.instances[name];
216
- if (defined(propertyValues)) {
217
- assert(instanceIndex === batchId, `Inherited property "${name}" is read-only.`);
218
- if (defined(propertyValues.typedArray)) {
219
- this._setBinaryProperty(propertyValues, indexInClass, value);
220
- } else {
221
- propertyValues[indexInClass] = clone(value, true);
48
+ }
49
+ getExtension(extensionName) {
50
+ return this.json && this.json.extensions && this.json.extensions[extensionName];
51
+ }
52
+ memorySizeInBytes() {
53
+ return 0;
54
+ }
55
+ isClass(batchId, className) {
56
+ this._checkBatchId(batchId);
57
+ assert(typeof className === 'string', className);
58
+ // extension: 3DTILES_batch_table_hierarchy
59
+ if (this._hierarchy) {
60
+ // PERFORMANCE_IDEA : cache results in the ancestor classes
61
+ // to speed up this check if this area becomes a hotspot
62
+ // PERFORMANCE_IDEA : treat class names as integers for faster comparisons
63
+ const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
64
+ const classId = hierarchy.classIds[instanceIndex];
65
+ const instanceClass = hierarchy.classes[classId];
66
+ return instanceClass.name === className;
67
+ });
68
+ return defined(result);
69
+ }
70
+ return false;
71
+ }
72
+ isExactClass(batchId, className) {
73
+ assert(typeof className === 'string', className);
74
+ return this.getExactClassName(batchId) === className;
75
+ }
76
+ getExactClassName(batchId) {
77
+ this._checkBatchId(batchId);
78
+ // extension: 3DTILES_batch_table_hierarchy
79
+ if (this._hierarchy) {
80
+ const classId = this._hierarchy.classIds[batchId];
81
+ const instanceClass = this._hierarchy.classes[classId];
82
+ return instanceClass.name;
83
+ }
84
+ return undefined;
85
+ }
86
+ hasProperty(batchId, name) {
87
+ this._checkBatchId(batchId);
88
+ assert(typeof name === 'string', name);
89
+ return defined(this._properties[name]) || this._hasPropertyInHierarchy(batchId, name);
90
+ }
91
+ getPropertyNames(batchId, results) {
92
+ this._checkBatchId(batchId);
93
+ results = defined(results) ? results : [];
94
+ results.length = 0;
95
+ const propertyNames = Object.keys(this._properties);
96
+ results.push(...propertyNames);
97
+ if (this._hierarchy) {
98
+ this._getPropertyNamesInHierarchy(batchId, results);
99
+ }
100
+ return results;
101
+ }
102
+ getProperty(batchId, name) {
103
+ this._checkBatchId(batchId);
104
+ assert(typeof name === 'string', name);
105
+ if (this._binaryProperties) {
106
+ const binaryProperty = this._binaryProperties[name];
107
+ if (defined(binaryProperty)) {
108
+ return this._getBinaryProperty(binaryProperty, batchId);
109
+ }
110
+ }
111
+ const propertyValues = this._properties[name];
112
+ if (defined(propertyValues)) {
113
+ return clone(propertyValues[batchId], true);
114
+ }
115
+ // EXTENSION: 3DTILES_batch_table_hierarchy
116
+ if (this._hierarchy) {
117
+ const hierarchyProperty = this._getHierarchyProperty(batchId, name);
118
+ if (defined(hierarchyProperty)) {
119
+ return hierarchyProperty;
120
+ }
121
+ }
122
+ return undefined;
123
+ }
124
+ setProperty(batchId, name, value) {
125
+ const featureCount = this.featureCount;
126
+ this._checkBatchId(batchId);
127
+ assert(typeof name === 'string', name);
128
+ if (this._binaryProperties) {
129
+ const binaryProperty = this._binaryProperties[name];
130
+ if (binaryProperty) {
131
+ this._setBinaryProperty(binaryProperty, batchId, value);
132
+ return;
133
+ }
134
+ }
135
+ // EXTENSION: 3DTILES_batch_table_hierarchy
136
+ if (this._hierarchy) {
137
+ if (this._setHierarchyProperty(this, batchId, name, value)) {
138
+ return;
139
+ }
222
140
  }
223
- return true;
224
- }
225
- return false;
226
- });
227
- return defined(result);
228
- }
141
+ let propertyValues = this._properties[name];
142
+ if (!defined(propertyValues)) {
143
+ // Property does not exist. Create it.
144
+ this._properties[name] = new Array(featureCount);
145
+ propertyValues = this._properties[name];
146
+ }
147
+ propertyValues[batchId] = clone(value, true);
148
+ }
149
+ // PRIVATE METHODS
150
+ _checkBatchId(batchId) {
151
+ const valid = batchId >= 0 && batchId < this.featureCount;
152
+ if (!valid) {
153
+ throw new Error('batchId not in range [0, featureCount - 1].');
154
+ }
155
+ }
156
+ _getBinaryProperty(binaryProperty, index) {
157
+ return binaryProperty.unpack(binaryProperty.typedArray, index);
158
+ }
159
+ _setBinaryProperty(binaryProperty, index, value) {
160
+ binaryProperty.pack(value, binaryProperty.typedArray, index);
161
+ }
162
+ _initializeBinaryProperties() {
163
+ let binaryProperties = null;
164
+ for (const name in this._properties) {
165
+ const property = this._properties[name];
166
+ const binaryProperty = this._initializeBinaryProperty(name, property);
167
+ // Store any information needed to access the binary data, including the typed array,
168
+ // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
169
+ if (binaryProperty) {
170
+ binaryProperties = binaryProperties || {};
171
+ binaryProperties[name] = binaryProperty;
172
+ }
173
+ }
174
+ return binaryProperties;
175
+ }
176
+ _initializeBinaryProperty(name, property) {
177
+ if ('byteOffset' in property) {
178
+ // This is a binary property
179
+ const tile3DAccessor = property;
180
+ assert(this.binary, `Property ${name} requires a batch table binary.`);
181
+ assert(tile3DAccessor.type, `Property ${name} requires a type.`);
182
+ const accessor = createTypedArrayFromAccessor(tile3DAccessor, this.binary.buffer, this.binary.byteOffset | 0, this.featureCount);
183
+ // Store any information needed to access the binary data, including the typed array,
184
+ // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
185
+ return {
186
+ typedArray: accessor.values,
187
+ componentCount: accessor.size,
188
+ unpack: accessor.unpacker,
189
+ pack: accessor.packer
190
+ };
191
+ }
192
+ return null;
193
+ }
194
+ // EXTENSION SUPPORT: 3DTILES_batch_table_hierarchy
195
+ _hasPropertyInHierarchy(batchId, name) {
196
+ if (!this._hierarchy) {
197
+ return false;
198
+ }
199
+ const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
200
+ const classId = hierarchy.classIds[instanceIndex];
201
+ const instances = hierarchy.classes[classId].instances;
202
+ return defined(instances[name]);
203
+ });
204
+ return defined(result);
205
+ }
206
+ _getPropertyNamesInHierarchy(batchId, results) {
207
+ traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
208
+ const classId = hierarchy.classIds[instanceIndex];
209
+ const instances = hierarchy.classes[classId].instances;
210
+ for (const name in instances) {
211
+ if (instances.hasOwnProperty(name)) {
212
+ if (results.indexOf(name) === -1) {
213
+ results.push(name);
214
+ }
215
+ }
216
+ }
217
+ });
218
+ }
219
+ _getHierarchyProperty(batchId, name) {
220
+ return traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
221
+ const classId = hierarchy.classIds[instanceIndex];
222
+ const instanceClass = hierarchy.classes[classId];
223
+ const indexInClass = hierarchy.classIndexes[instanceIndex];
224
+ const propertyValues = instanceClass.instances[name];
225
+ if (defined(propertyValues)) {
226
+ if (defined(propertyValues.typedArray)) {
227
+ return this._getBinaryProperty(propertyValues, indexInClass);
228
+ }
229
+ return clone(propertyValues[indexInClass], true);
230
+ }
231
+ return null;
232
+ });
233
+ }
234
+ _setHierarchyProperty(batchTable, batchId, name, value) {
235
+ const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
236
+ const classId = hierarchy.classIds[instanceIndex];
237
+ const instanceClass = hierarchy.classes[classId];
238
+ const indexInClass = hierarchy.classIndexes[instanceIndex];
239
+ const propertyValues = instanceClass.instances[name];
240
+ if (defined(propertyValues)) {
241
+ assert(instanceIndex === batchId, `Inherited property "${name}" is read-only.`);
242
+ if (defined(propertyValues.typedArray)) {
243
+ this._setBinaryProperty(propertyValues, indexInClass, value);
244
+ }
245
+ else {
246
+ propertyValues[indexInClass] = clone(value, true);
247
+ }
248
+ return true;
249
+ }
250
+ return false;
251
+ });
252
+ return defined(result);
253
+ }
229
254
  }
230
- //# sourceMappingURL=tile-3d-batch-table.js.map
@@ -1,69 +1,74 @@
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
1
6
  import { GL, GLType } from '@loaders.gl/math';
7
+ // Reference:
8
+ // https://github.com/AnalyticalGraphicsInc/cesium/blob/1de96d087f0b17575eb1a3f736407b348c765d59/Source/Scene/Cesium3DTileFeatureTable.js
2
9
  export default class Tile3DFeatureTable {
3
- constructor(featureTableJson, featureTableBinary) {
4
- this.json = void 0;
5
- this.buffer = void 0;
6
- this.featuresLength = 0;
7
- this._cachedTypedArrays = {};
8
- this.json = featureTableJson;
9
- this.buffer = featureTableBinary;
10
- }
11
- getExtension(extensionName) {
12
- return this.json.extensions && this.json.extensions[extensionName];
13
- }
14
- hasProperty(propertyName) {
15
- return Boolean(this.json[propertyName]);
16
- }
17
- getGlobalProperty(propertyName) {
18
- let componentType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : GL.UNSIGNED_INT;
19
- let componentLength = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
20
- const jsonValue = this.json[propertyName];
21
- if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
22
- return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, 1, jsonValue.byteOffset);
10
+ json;
11
+ buffer;
12
+ featuresLength = 0;
13
+ _cachedTypedArrays = {};
14
+ constructor(featureTableJson, featureTableBinary) {
15
+ this.json = featureTableJson;
16
+ this.buffer = featureTableBinary;
23
17
  }
24
- return jsonValue;
25
- }
26
- getPropertyArray(propertyName, componentType, componentLength) {
27
- const jsonValue = this.json[propertyName];
28
- if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
29
- if ('componentType' in jsonValue) {
30
- componentType = GLType.fromName(jsonValue.componentType);
31
- }
32
- return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, this.featuresLength, jsonValue.byteOffset);
18
+ getExtension(extensionName) {
19
+ return this.json.extensions && this.json.extensions[extensionName];
33
20
  }
34
- return this._getTypedArrayFromArray(propertyName, componentType, jsonValue);
35
- }
36
- getProperty(propertyName, componentType, componentLength, featureId, result) {
37
- const jsonValue = this.json[propertyName];
38
- if (!jsonValue) {
39
- return jsonValue;
21
+ hasProperty(propertyName) {
22
+ return Boolean(this.json[propertyName]);
40
23
  }
41
- const typedArray = this.getPropertyArray(propertyName, componentType, componentLength);
42
- if (componentLength === 1) {
43
- return typedArray[featureId];
24
+ getGlobalProperty(propertyName, componentType = GL.UNSIGNED_INT, componentLength = 1) {
25
+ const jsonValue = this.json[propertyName];
26
+ if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
27
+ return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, 1, jsonValue.byteOffset);
28
+ }
29
+ return jsonValue;
44
30
  }
45
- for (let i = 0; i < componentLength; ++i) {
46
- result[i] = typedArray[componentLength * featureId + i];
31
+ getPropertyArray(propertyName, componentType, componentLength) {
32
+ const jsonValue = this.json[propertyName];
33
+ if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
34
+ if ('componentType' in jsonValue) {
35
+ componentType = GLType.fromName(jsonValue.componentType);
36
+ }
37
+ return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, this.featuresLength, jsonValue.byteOffset);
38
+ }
39
+ return this._getTypedArrayFromArray(propertyName, componentType, jsonValue);
47
40
  }
48
- return result;
49
- }
50
- _getTypedArrayFromBinary(propertyName, componentType, componentLength, count, byteOffset) {
51
- const cachedTypedArrays = this._cachedTypedArrays;
52
- let typedArray = cachedTypedArrays[propertyName];
53
- if (!typedArray) {
54
- typedArray = GLType.createTypedArray(componentType, this.buffer.buffer, this.buffer.byteOffset + byteOffset, count * componentLength);
55
- cachedTypedArrays[propertyName] = typedArray;
41
+ getProperty(propertyName, componentType, componentLength, featureId, result) {
42
+ const jsonValue = this.json[propertyName];
43
+ if (!jsonValue) {
44
+ return jsonValue;
45
+ }
46
+ const typedArray = this.getPropertyArray(propertyName, componentType, componentLength);
47
+ if (componentLength === 1) {
48
+ return typedArray[featureId];
49
+ }
50
+ for (let i = 0; i < componentLength; ++i) {
51
+ result[i] = typedArray[componentLength * featureId + i];
52
+ }
53
+ return result;
56
54
  }
57
- return typedArray;
58
- }
59
- _getTypedArrayFromArray(propertyName, componentType, array) {
60
- const cachedTypedArrays = this._cachedTypedArrays;
61
- let typedArray = cachedTypedArrays[propertyName];
62
- if (!typedArray) {
63
- typedArray = GLType.createTypedArray(componentType, array);
64
- cachedTypedArrays[propertyName] = typedArray;
55
+ // HELPERS
56
+ _getTypedArrayFromBinary(propertyName, componentType, componentLength, count, byteOffset) {
57
+ const cachedTypedArrays = this._cachedTypedArrays;
58
+ let typedArray = cachedTypedArrays[propertyName];
59
+ if (!typedArray) {
60
+ typedArray = GLType.createTypedArray(componentType, this.buffer.buffer, this.buffer.byteOffset + byteOffset, count * componentLength);
61
+ cachedTypedArrays[propertyName] = typedArray;
62
+ }
63
+ return typedArray;
64
+ }
65
+ _getTypedArrayFromArray(propertyName, componentType, array) {
66
+ const cachedTypedArrays = this._cachedTypedArrays;
67
+ let typedArray = cachedTypedArrays[propertyName];
68
+ if (!typedArray) {
69
+ typedArray = GLType.createTypedArray(componentType, array);
70
+ cachedTypedArrays[propertyName] = typedArray;
71
+ }
72
+ return typedArray;
65
73
  }
66
- return typedArray;
67
- }
68
74
  }
69
- //# sourceMappingURL=tile-3d-feature-table.js.map
@@ -1,22 +1,26 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright vis.gl contributors
4
+ // TILE TYPES
1
5
  export const TILE3D_TYPE = {
2
- COMPOSITE: 'cmpt',
3
- POINT_CLOUD: 'pnts',
4
- BATCHED_3D_MODEL: 'b3dm',
5
- INSTANCED_3D_MODEL: 'i3dm',
6
- GEOMETRY: 'geom',
7
- VECTOR: 'vect',
8
- GLTF: 'glTF'
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'
9
13
  };
10
14
  export const TILE3D_TYPES = Object.keys(TILE3D_TYPE);
11
15
  export const MAGIC_ARRAY = {
12
- BATCHED_MODEL: [98, 51, 100, 109],
13
- INSTANCED_MODEL: [105, 51, 100, 109],
14
- POINT_CLOUD: [112, 110, 116, 115],
15
- COMPOSITE: [99, 109, 112, 116]
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]
16
20
  };
21
+ // TILE CONSTANTS
17
22
  export const TILE3D_OPTIMIZATION_HINT = {
18
- NOT_COMPUTED: -1,
19
- USE_OPTIMIZATION: 1,
20
- SKIP_OPTIMIZATION: 0
23
+ NOT_COMPUTED: -1,
24
+ USE_OPTIMIZATION: 1,
25
+ SKIP_OPTIMIZATION: 0
21
26
  };
22
- //# sourceMappingURL=constants.js.map