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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js +66 -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 +1963 -1037
  8. package/dist/dist.min.js +32 -0
  9. package/dist/index.cjs +122 -337
  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.js +103 -87
  15. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js +179 -155
  16. package/dist/lib/classes/tile-3d-batch-table.js +232 -217
  17. package/dist/lib/classes/tile-3d-feature-table.js +62 -59
  18. package/dist/lib/constants.js +19 -15
  19. package/dist/lib/encoders/encode-3d-tile-batched-model.js +40 -35
  20. package/dist/lib/encoders/encode-3d-tile-composite.js +19 -17
  21. package/dist/lib/encoders/encode-3d-tile-instanced-model.js +32 -31
  22. package/dist/lib/encoders/encode-3d-tile-point-cloud.js +31 -32
  23. package/dist/lib/encoders/encode-3d-tile.js +23 -19
  24. package/dist/lib/encoders/helpers/encode-3d-tile-header.js +23 -23
  25. package/dist/lib/ion/ion.js +55 -54
  26. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts +1 -1
  27. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.d.ts.map +1 -1
  28. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js +57 -51
  29. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts +1 -1
  30. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.d.ts.map +1 -1
  31. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js +21 -18
  32. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js +35 -20
  33. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts +4 -4
  34. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.d.ts.map +1 -1
  35. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js +269 -234
  36. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts +2 -2
  37. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.d.ts.map +1 -1
  38. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js +83 -55
  39. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts +1 -1
  40. package/dist/lib/parsers/helpers/parse-3d-tile-header.d.ts.map +1 -1
  41. package/dist/lib/parsers/helpers/parse-3d-tile-header.js +23 -14
  42. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts +1 -1
  43. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.d.ts.map +1 -1
  44. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js +82 -54
  45. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts +2 -2
  46. package/dist/lib/parsers/helpers/parse-3d-tile-tables.d.ts.map +1 -1
  47. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js +79 -68
  48. package/dist/lib/parsers/helpers/parse-utils.js +19 -14
  49. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts +2 -2
  50. package/dist/lib/parsers/parse-3d-tile-batched-model.d.ts.map +1 -1
  51. package/dist/lib/parsers/parse-3d-tile-batched-model.js +21 -17
  52. package/dist/lib/parsers/parse-3d-tile-composite.d.ts +2 -2
  53. package/dist/lib/parsers/parse-3d-tile-composite.d.ts.map +1 -1
  54. package/dist/lib/parsers/parse-3d-tile-composite.js +18 -14
  55. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts +2 -2
  56. package/dist/lib/parsers/parse-3d-tile-gltf.d.ts.map +1 -1
  57. package/dist/lib/parsers/parse-3d-tile-gltf.js +22 -14
  58. package/dist/lib/parsers/parse-3d-tile-header.d.ts +2 -2
  59. package/dist/lib/parsers/parse-3d-tile-header.d.ts.map +1 -1
  60. package/dist/lib/parsers/parse-3d-tile-header.js +168 -159
  61. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts +2 -2
  62. package/dist/lib/parsers/parse-3d-tile-instanced-model.d.ts.map +1 -1
  63. package/dist/lib/parsers/parse-3d-tile-instanced-model.js +153 -123
  64. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts +2 -2
  65. package/dist/lib/parsers/parse-3d-tile-point-cloud.d.ts.map +1 -1
  66. package/dist/lib/parsers/parse-3d-tile-point-cloud.js +380 -174
  67. package/dist/lib/parsers/parse-3d-tile.d.ts +2 -2
  68. package/dist/lib/parsers/parse-3d-tile.d.ts.map +1 -1
  69. package/dist/lib/parsers/parse-3d-tile.js +24 -24
  70. package/dist/lib/utils/obb/s2-corners-to-obb.js +29 -16
  71. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts +1 -1
  72. package/dist/lib/utils/s2/converters/s2-to-boundary.d.ts.map +1 -1
  73. package/dist/lib/utils/s2/converters/s2-to-boundary.js +55 -35
  74. package/dist/lib/utils/s2/converters/s2-to-obb-points.js +31 -20
  75. package/dist/lib/utils/s2/converters/s2-to-region.d.ts +1 -1
  76. package/dist/lib/utils/s2/converters/s2-to-region.d.ts.map +1 -1
  77. package/dist/lib/utils/s2/converters/s2-to-region.js +51 -35
  78. package/dist/lib/utils/s2/index.d.ts +7 -7
  79. package/dist/lib/utils/s2/index.d.ts.map +1 -1
  80. package/dist/lib/utils/s2/index.js +3 -1
  81. package/dist/lib/utils/s2/s2-geometry-functions.js +19 -5
  82. package/dist/lib/utils/s2/s2-token-functions.js +51 -22
  83. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts +1 -1
  84. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.d.ts.map +1 -1
  85. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js +23 -9
  86. package/dist/lib/utils/s2/s2geometry/s2-geometry.js +218 -157
  87. package/dist/lib/utils/version.js +4 -2
  88. package/dist/tile-3d-subtree-loader.d.ts +1 -1
  89. package/dist/tile-3d-subtree-loader.d.ts.map +1 -1
  90. package/dist/tile-3d-subtree-loader.js +15 -10
  91. package/dist/tile-3d-writer.js +19 -14
  92. package/dist/tiles-3d-loader.js +65 -55
  93. package/dist/types.js +3 -1
  94. package/package.json +11 -10
  95. package/dist/3d-tiles-archive/3d-tiles-archive-archive.js.map +0 -1
  96. package/dist/3d-tiles-archive/3d-tiles-archive-parser.js.map +0 -1
  97. package/dist/3d-tiles-archive-loader.js.map +0 -1
  98. package/dist/cesium-ion-loader.js.map +0 -1
  99. package/dist/index.js.map +0 -1
  100. package/dist/lib/classes/helpers/tile-3d-accessor-utils.js.map +0 -1
  101. package/dist/lib/classes/tile-3d-batch-table-hierarchy.js.map +0 -1
  102. package/dist/lib/classes/tile-3d-batch-table.js.map +0 -1
  103. package/dist/lib/classes/tile-3d-feature-table.js.map +0 -1
  104. package/dist/lib/constants.js.map +0 -1
  105. package/dist/lib/encoders/encode-3d-tile-batched-model.js.map +0 -1
  106. package/dist/lib/encoders/encode-3d-tile-composite.js.map +0 -1
  107. package/dist/lib/encoders/encode-3d-tile-instanced-model.js.map +0 -1
  108. package/dist/lib/encoders/encode-3d-tile-point-cloud.js.map +0 -1
  109. package/dist/lib/encoders/encode-3d-tile.js.map +0 -1
  110. package/dist/lib/encoders/helpers/encode-3d-tile-header.js.map +0 -1
  111. package/dist/lib/ion/ion.js.map +0 -1
  112. package/dist/lib/parsers/helpers/normalize-3d-tile-colors.js.map +0 -1
  113. package/dist/lib/parsers/helpers/normalize-3d-tile-normals.js.map +0 -1
  114. package/dist/lib/parsers/helpers/normalize-3d-tile-positions.js.map +0 -1
  115. package/dist/lib/parsers/helpers/parse-3d-implicit-tiles.js.map +0 -1
  116. package/dist/lib/parsers/helpers/parse-3d-tile-gltf-view.js.map +0 -1
  117. package/dist/lib/parsers/helpers/parse-3d-tile-header.js.map +0 -1
  118. package/dist/lib/parsers/helpers/parse-3d-tile-subtree.js.map +0 -1
  119. package/dist/lib/parsers/helpers/parse-3d-tile-tables.js.map +0 -1
  120. package/dist/lib/parsers/helpers/parse-utils.js.map +0 -1
  121. package/dist/lib/parsers/parse-3d-tile-batched-model.js.map +0 -1
  122. package/dist/lib/parsers/parse-3d-tile-composite.js.map +0 -1
  123. package/dist/lib/parsers/parse-3d-tile-gltf.js.map +0 -1
  124. package/dist/lib/parsers/parse-3d-tile-header.js.map +0 -1
  125. package/dist/lib/parsers/parse-3d-tile-instanced-model.js.map +0 -1
  126. package/dist/lib/parsers/parse-3d-tile-point-cloud.js.map +0 -1
  127. package/dist/lib/parsers/parse-3d-tile.js.map +0 -1
  128. package/dist/lib/utils/obb/s2-corners-to-obb.js.map +0 -1
  129. package/dist/lib/utils/s2/converters/s2-to-boundary.js.map +0 -1
  130. package/dist/lib/utils/s2/converters/s2-to-obb-points.js.map +0 -1
  131. package/dist/lib/utils/s2/converters/s2-to-region.js.map +0 -1
  132. package/dist/lib/utils/s2/index.js.map +0 -1
  133. package/dist/lib/utils/s2/s2-geometry-functions.js.map +0 -1
  134. package/dist/lib/utils/s2/s2-token-functions.js.map +0 -1
  135. package/dist/lib/utils/s2/s2geometry/s2-cell-utils.js.map +0 -1
  136. package/dist/lib/utils/s2/s2geometry/s2-geometry.js.map +0 -1
  137. package/dist/lib/utils/version.js.map +0 -1
  138. package/dist/tile-3d-subtree-loader.js.map +0 -1
  139. package/dist/tile-3d-writer.js.map +0 -1
  140. package/dist/tiles-3d-loader.js.map +0 -1
  141. package/dist/types.js.map +0 -1
@@ -1,230 +1,245 @@
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
+ constructor(json, binary, featureCount, options = {}) {
22
+ assert(featureCount >= 0);
23
+ this.json = json || {};
24
+ this.binary = binary;
25
+ this.featureCount = featureCount;
26
+ this._extensions = this.json?.extensions || {};
27
+ // Copy all top-level property fields from the json object, ignoring special fields
28
+ this._properties = {};
29
+ for (const propertyName in this.json) {
30
+ if (!IGNORED_PROPERTY_FIELDS[propertyName]) {
31
+ this._properties[propertyName] = this.json[propertyName];
32
+ }
191
33
  }
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);
34
+ this._binaryProperties = this._initializeBinaryProperties();
35
+ // TODO: hierarchy support is only partially implemented and not tested
36
+ if (options['3DTILES_batch_table_hierarchy']) {
37
+ this._hierarchy = initializeHierarchy(this, this.json, this.binary);
204
38
  }
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);
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
+ // extension: 3DTILES_batch_table_hierarchy
50
+ if (this._hierarchy) {
51
+ // PERFORMANCE_IDEA : cache results in the ancestor classes
52
+ // to speed up this check if this area becomes a hotspot
53
+ // PERFORMANCE_IDEA : treat class names as integers for faster comparisons
54
+ const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
55
+ const classId = hierarchy.classIds[instanceIndex];
56
+ const instanceClass = hierarchy.classes[classId];
57
+ return instanceClass.name === className;
58
+ });
59
+ return defined(result);
60
+ }
61
+ return false;
62
+ }
63
+ isExactClass(batchId, className) {
64
+ assert(typeof className === 'string', className);
65
+ return this.getExactClassName(batchId) === className;
66
+ }
67
+ getExactClassName(batchId) {
68
+ this._checkBatchId(batchId);
69
+ // extension: 3DTILES_batch_table_hierarchy
70
+ if (this._hierarchy) {
71
+ const classId = this._hierarchy.classIds[batchId];
72
+ const instanceClass = this._hierarchy.classes[classId];
73
+ return instanceClass.name;
74
+ }
75
+ return undefined;
76
+ }
77
+ hasProperty(batchId, name) {
78
+ this._checkBatchId(batchId);
79
+ assert(typeof name === 'string', name);
80
+ return defined(this._properties[name]) || this._hasPropertyInHierarchy(batchId, name);
81
+ }
82
+ getPropertyNames(batchId, results) {
83
+ this._checkBatchId(batchId);
84
+ results = defined(results) ? results : [];
85
+ results.length = 0;
86
+ const propertyNames = Object.keys(this._properties);
87
+ results.push(...propertyNames);
88
+ if (this._hierarchy) {
89
+ this._getPropertyNamesInHierarchy(batchId, results);
90
+ }
91
+ return results;
92
+ }
93
+ getProperty(batchId, name) {
94
+ this._checkBatchId(batchId);
95
+ assert(typeof name === 'string', name);
96
+ if (this._binaryProperties) {
97
+ const binaryProperty = this._binaryProperties[name];
98
+ if (defined(binaryProperty)) {
99
+ return this._getBinaryProperty(binaryProperty, batchId);
100
+ }
101
+ }
102
+ const propertyValues = this._properties[name];
103
+ if (defined(propertyValues)) {
104
+ return clone(propertyValues[batchId], true);
105
+ }
106
+ // EXTENSION: 3DTILES_batch_table_hierarchy
107
+ if (this._hierarchy) {
108
+ const hierarchyProperty = this._getHierarchyProperty(batchId, name);
109
+ if (defined(hierarchyProperty)) {
110
+ return hierarchyProperty;
111
+ }
112
+ }
113
+ return undefined;
114
+ }
115
+ setProperty(batchId, name, value) {
116
+ const featureCount = this.featureCount;
117
+ this._checkBatchId(batchId);
118
+ assert(typeof name === 'string', name);
119
+ if (this._binaryProperties) {
120
+ const binaryProperty = this._binaryProperties[name];
121
+ if (binaryProperty) {
122
+ this._setBinaryProperty(binaryProperty, batchId, value);
123
+ return;
124
+ }
125
+ }
126
+ // EXTENSION: 3DTILES_batch_table_hierarchy
127
+ if (this._hierarchy) {
128
+ if (this._setHierarchyProperty(this, batchId, name, value)) {
129
+ return;
130
+ }
222
131
  }
223
- return true;
224
- }
225
- return false;
226
- });
227
- return defined(result);
228
- }
132
+ let propertyValues = this._properties[name];
133
+ if (!defined(propertyValues)) {
134
+ // Property does not exist. Create it.
135
+ this._properties[name] = new Array(featureCount);
136
+ propertyValues = this._properties[name];
137
+ }
138
+ propertyValues[batchId] = clone(value, true);
139
+ }
140
+ // PRIVATE METHODS
141
+ _checkBatchId(batchId) {
142
+ const valid = batchId >= 0 && batchId < this.featureCount;
143
+ if (!valid) {
144
+ throw new Error('batchId not in range [0, featureCount - 1].');
145
+ }
146
+ }
147
+ _getBinaryProperty(binaryProperty, index) {
148
+ return binaryProperty.unpack(binaryProperty.typedArray, index);
149
+ }
150
+ _setBinaryProperty(binaryProperty, index, value) {
151
+ binaryProperty.pack(value, binaryProperty.typedArray, index);
152
+ }
153
+ _initializeBinaryProperties() {
154
+ let binaryProperties = null;
155
+ for (const name in this._properties) {
156
+ const property = this._properties[name];
157
+ const binaryProperty = this._initializeBinaryProperty(name, property);
158
+ // Store any information needed to access the binary data, including the typed array,
159
+ // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
160
+ if (binaryProperty) {
161
+ binaryProperties = binaryProperties || {};
162
+ binaryProperties[name] = binaryProperty;
163
+ }
164
+ }
165
+ return binaryProperties;
166
+ }
167
+ _initializeBinaryProperty(name, property) {
168
+ if ('byteOffset' in property) {
169
+ // This is a binary property
170
+ const tile3DAccessor = property;
171
+ assert(this.binary, `Property ${name} requires a batch table binary.`);
172
+ assert(tile3DAccessor.type, `Property ${name} requires a type.`);
173
+ const accessor = createTypedArrayFromAccessor(tile3DAccessor, this.binary.buffer, this.binary.byteOffset | 0, this.featureCount);
174
+ // Store any information needed to access the binary data, including the typed array,
175
+ // componentCount (e.g. a VEC4 would be 4), and the type used to pack and unpack (e.g. Cartesian4).
176
+ return {
177
+ typedArray: accessor.values,
178
+ componentCount: accessor.size,
179
+ unpack: accessor.unpacker,
180
+ pack: accessor.packer
181
+ };
182
+ }
183
+ return null;
184
+ }
185
+ // EXTENSION SUPPORT: 3DTILES_batch_table_hierarchy
186
+ _hasPropertyInHierarchy(batchId, name) {
187
+ if (!this._hierarchy) {
188
+ return false;
189
+ }
190
+ const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
191
+ const classId = hierarchy.classIds[instanceIndex];
192
+ const instances = hierarchy.classes[classId].instances;
193
+ return defined(instances[name]);
194
+ });
195
+ return defined(result);
196
+ }
197
+ _getPropertyNamesInHierarchy(batchId, results) {
198
+ traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
199
+ const classId = hierarchy.classIds[instanceIndex];
200
+ const instances = hierarchy.classes[classId].instances;
201
+ for (const name in instances) {
202
+ if (instances.hasOwnProperty(name)) {
203
+ if (results.indexOf(name) === -1) {
204
+ results.push(name);
205
+ }
206
+ }
207
+ }
208
+ });
209
+ }
210
+ _getHierarchyProperty(batchId, name) {
211
+ return 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
+ if (defined(propertyValues.typedArray)) {
218
+ return this._getBinaryProperty(propertyValues, indexInClass);
219
+ }
220
+ return clone(propertyValues[indexInClass], true);
221
+ }
222
+ return null;
223
+ });
224
+ }
225
+ _setHierarchyProperty(batchTable, batchId, name, value) {
226
+ const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
227
+ const classId = hierarchy.classIds[instanceIndex];
228
+ const instanceClass = hierarchy.classes[classId];
229
+ const indexInClass = hierarchy.classIndexes[instanceIndex];
230
+ const propertyValues = instanceClass.instances[name];
231
+ if (defined(propertyValues)) {
232
+ assert(instanceIndex === batchId, `Inherited property "${name}" is read-only.`);
233
+ if (defined(propertyValues.typedArray)) {
234
+ this._setBinaryProperty(propertyValues, indexInClass, value);
235
+ }
236
+ else {
237
+ propertyValues[indexInClass] = clone(value, true);
238
+ }
239
+ return true;
240
+ }
241
+ return false;
242
+ });
243
+ return defined(result);
244
+ }
229
245
  }
230
- //# sourceMappingURL=tile-3d-batch-table.js.map
@@ -1,69 +1,72 @@
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
+ constructor(featureTableJson, featureTableBinary) {
11
+ this.featuresLength = 0;
12
+ this._cachedTypedArrays = {};
13
+ this.json = featureTableJson;
14
+ this.buffer = featureTableBinary;
23
15
  }
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);
16
+ getExtension(extensionName) {
17
+ return this.json.extensions && this.json.extensions[extensionName];
33
18
  }
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;
19
+ hasProperty(propertyName) {
20
+ return Boolean(this.json[propertyName]);
40
21
  }
41
- const typedArray = this.getPropertyArray(propertyName, componentType, componentLength);
42
- if (componentLength === 1) {
43
- return typedArray[featureId];
22
+ getGlobalProperty(propertyName, componentType = GL.UNSIGNED_INT, componentLength = 1) {
23
+ const jsonValue = this.json[propertyName];
24
+ if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
25
+ return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, 1, jsonValue.byteOffset);
26
+ }
27
+ return jsonValue;
44
28
  }
45
- for (let i = 0; i < componentLength; ++i) {
46
- result[i] = typedArray[componentLength * featureId + i];
29
+ getPropertyArray(propertyName, componentType, componentLength) {
30
+ const jsonValue = this.json[propertyName];
31
+ if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
32
+ if ('componentType' in jsonValue) {
33
+ componentType = GLType.fromName(jsonValue.componentType);
34
+ }
35
+ return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, this.featuresLength, jsonValue.byteOffset);
36
+ }
37
+ return this._getTypedArrayFromArray(propertyName, componentType, jsonValue);
47
38
  }
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;
39
+ getProperty(propertyName, componentType, componentLength, featureId, result) {
40
+ const jsonValue = this.json[propertyName];
41
+ if (!jsonValue) {
42
+ return jsonValue;
43
+ }
44
+ const typedArray = this.getPropertyArray(propertyName, componentType, componentLength);
45
+ if (componentLength === 1) {
46
+ return typedArray[featureId];
47
+ }
48
+ for (let i = 0; i < componentLength; ++i) {
49
+ result[i] = typedArray[componentLength * featureId + i];
50
+ }
51
+ return result;
56
52
  }
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;
53
+ // HELPERS
54
+ _getTypedArrayFromBinary(propertyName, componentType, componentLength, count, byteOffset) {
55
+ const cachedTypedArrays = this._cachedTypedArrays;
56
+ let typedArray = cachedTypedArrays[propertyName];
57
+ if (!typedArray) {
58
+ typedArray = GLType.createTypedArray(componentType, this.buffer.buffer, this.buffer.byteOffset + byteOffset, count * componentLength);
59
+ cachedTypedArrays[propertyName] = typedArray;
60
+ }
61
+ return typedArray;
62
+ }
63
+ _getTypedArrayFromArray(propertyName, componentType, array) {
64
+ const cachedTypedArrays = this._cachedTypedArrays;
65
+ let typedArray = cachedTypedArrays[propertyName];
66
+ if (!typedArray) {
67
+ typedArray = GLType.createTypedArray(componentType, array);
68
+ cachedTypedArrays[propertyName] = typedArray;
69
+ }
70
+ return typedArray;
65
71
  }
66
- return typedArray;
67
- }
68
72
  }
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