@loaders.gl/i3s 3.1.0-beta.5 → 3.1.2

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 (91) hide show
  1. package/dist/bundle.js +5 -10364
  2. package/dist/dist.min.js +10371 -0
  3. package/dist/es5/bundle.js +1 -1
  4. package/dist/es5/bundle.js.map +1 -1
  5. package/dist/es5/i3s-attribute-loader.js +147 -62
  6. package/dist/es5/i3s-attribute-loader.js.map +1 -1
  7. package/dist/es5/i3s-building-scene-layer-loader.js +36 -8
  8. package/dist/es5/i3s-building-scene-layer-loader.js.map +1 -1
  9. package/dist/es5/i3s-content-loader.js +36 -10
  10. package/dist/es5/i3s-content-loader.js.map +1 -1
  11. package/dist/es5/i3s-loader.js +175 -51
  12. package/dist/es5/i3s-loader.js.map +1 -1
  13. package/dist/es5/i3s-node-page-loader.js +51 -8
  14. package/dist/es5/i3s-node-page-loader.js.map +1 -1
  15. package/dist/es5/index.js +6 -6
  16. package/dist/es5/index.js.map +1 -1
  17. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +328 -173
  18. package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
  19. package/dist/es5/lib/parsers/constants.js +9 -28
  20. package/dist/es5/lib/parsers/constants.js.map +1 -1
  21. package/dist/es5/lib/parsers/parse-i3s-attribute.js +69 -27
  22. package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +1 -1
  23. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js +62 -28
  24. package/dist/es5/lib/parsers/parse-i3s-building-scene-layer.js.map +1 -1
  25. package/dist/es5/lib/parsers/parse-i3s-tile-content.js +416 -314
  26. package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  27. package/dist/es5/lib/parsers/parse-i3s.js +109 -49
  28. package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
  29. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +8 -4
  30. package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -1
  31. package/dist/es5/lib/utils/url-utils.js +14 -17
  32. package/dist/es5/lib/utils/url-utils.js.map +1 -1
  33. package/dist/es5/types.js +10 -2
  34. package/dist/es5/types.js.map +1 -1
  35. package/dist/esm/i3s-attribute-loader.js +1 -1
  36. package/dist/esm/i3s-attribute-loader.js.map +1 -1
  37. package/dist/esm/i3s-building-scene-layer-loader.js +1 -1
  38. package/dist/esm/i3s-building-scene-layer-loader.js.map +1 -1
  39. package/dist/esm/i3s-content-loader.js +1 -1
  40. package/dist/esm/i3s-content-loader.js.map +1 -1
  41. package/dist/esm/i3s-loader.js +1 -1
  42. package/dist/esm/i3s-loader.js.map +1 -1
  43. package/dist/esm/i3s-node-page-loader.js +1 -1
  44. package/dist/esm/i3s-node-page-loader.js.map +1 -1
  45. package/dist/esm/index.js.map +1 -1
  46. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js +33 -23
  47. package/dist/esm/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
  48. package/dist/esm/lib/parsers/constants.js +2 -18
  49. package/dist/esm/lib/parsers/constants.js.map +1 -1
  50. package/dist/esm/lib/parsers/parse-i3s-tile-content.js +44 -61
  51. package/dist/esm/lib/parsers/parse-i3s-tile-content.js.map +1 -1
  52. package/dist/esm/lib/parsers/parse-i3s.js +40 -25
  53. package/dist/esm/lib/parsers/parse-i3s.js.map +1 -1
  54. package/dist/esm/lib/utils/url-utils.js +2 -3
  55. package/dist/esm/lib/utils/url-utils.js.map +1 -1
  56. package/dist/esm/types.js +7 -0
  57. package/dist/esm/types.js.map +1 -1
  58. package/dist/i3s-building-scene-layer-loader.js +1 -1
  59. package/dist/i3s-content-loader.js +1 -1
  60. package/dist/i3s-content-worker.js +106 -95
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts +20 -20
  64. package/dist/lib/helpers/i3s-nodepages-tiles.d.ts.map +1 -1
  65. package/dist/lib/helpers/i3s-nodepages-tiles.js +33 -32
  66. package/dist/lib/parsers/constants.d.ts +1 -17
  67. package/dist/lib/parsers/constants.d.ts.map +1 -1
  68. package/dist/lib/parsers/constants.js +3 -21
  69. package/dist/lib/parsers/parse-i3s-attribute.d.ts +1 -1
  70. package/dist/lib/parsers/parse-i3s-tile-content.d.ts +2 -2
  71. package/dist/lib/parsers/parse-i3s-tile-content.d.ts.map +1 -1
  72. package/dist/lib/parsers/parse-i3s-tile-content.js +35 -61
  73. package/dist/lib/parsers/parse-i3s.d.ts +5 -3
  74. package/dist/lib/parsers/parse-i3s.d.ts.map +1 -1
  75. package/dist/lib/parsers/parse-i3s.js +37 -32
  76. package/dist/lib/utils/url-utils.d.ts +6 -6
  77. package/dist/lib/utils/url-utils.d.ts.map +1 -1
  78. package/dist/lib/utils/url-utils.js +5 -5
  79. package/dist/types.d.ts +289 -74
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/types.js +6 -1
  82. package/package.json +10 -10
  83. package/src/i3s-building-scene-layer-loader.ts +1 -1
  84. package/src/i3s-content-loader.ts +1 -1
  85. package/src/index.ts +3 -3
  86. package/src/lib/helpers/i3s-nodepages-tiles.ts +71 -55
  87. package/src/lib/parsers/constants.ts +2 -22
  88. package/src/lib/parsers/parse-i3s-tile-content.ts +74 -103
  89. package/src/lib/parsers/parse-i3s.ts +48 -37
  90. package/src/lib/utils/url-utils.ts +7 -7
  91. package/src/types.ts +302 -93
@@ -7,6 +7,14 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
14
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
+
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
10
18
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
19
 
12
20
  var _core = require("@loaders.gl/core");
@@ -19,8 +27,21 @@ var _parseI3s = require("../parsers/parse-i3s");
19
27
 
20
28
  var _urlUtils = require("../utils/url-utils");
21
29
 
22
- class I3SNodePagesTiles {
23
- constructor(tileset, options) {
30
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
31
+
32
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
33
+
34
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
35
+
36
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
37
+
38
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
39
+
40
+ var I3SNodePagesTiles = function () {
41
+ function I3SNodePagesTiles(tileset, options) {
42
+ var _tileset$nodePages, _tileset$nodePages2;
43
+
44
+ (0, _classCallCheck2.default)(this, I3SNodePagesTiles);
24
45
  (0, _defineProperty2.default)(this, "tileset", void 0);
25
46
  (0, _defineProperty2.default)(this, "nodePages", []);
26
47
  (0, _defineProperty2.default)(this, "pendingNodePages", []);
@@ -29,210 +50,344 @@ class I3SNodePagesTiles {
29
50
  (0, _defineProperty2.default)(this, "lodSelectionMetricType", void 0);
30
51
  (0, _defineProperty2.default)(this, "textureDefinitionsSelectedFormats", []);
31
52
  (0, _defineProperty2.default)(this, "textureLoaderOptions", {});
32
- this.tileset = { ...tileset
33
- };
34
- this.nodesPerPage = tileset.nodePages.nodesPerPage;
35
- this.lodSelectionMetricType = tileset.nodePages.lodSelectionMetricType;
53
+ this.tileset = _objectSpread({}, tileset);
54
+ this.nodesPerPage = ((_tileset$nodePages = tileset.nodePages) === null || _tileset$nodePages === void 0 ? void 0 : _tileset$nodePages.nodesPerPage) || 64;
55
+ this.lodSelectionMetricType = (_tileset$nodePages2 = tileset.nodePages) === null || _tileset$nodePages2 === void 0 ? void 0 : _tileset$nodePages2.lodSelectionMetricType;
36
56
  this.options = options;
37
57
  this.initSelectedFormatsForTextureDefinitions(tileset);
38
58
  }
39
59
 
40
- async getNodeById(id) {
41
- const pageIndex = Math.floor(id / this.nodesPerPage);
42
-
43
- if (!this.nodePages[pageIndex] && !this.pendingNodePages[pageIndex]) {
44
- var _this$options$i3s;
45
-
46
- const nodePageUrl = (0, _urlUtils.getUrlWithToken)("".concat(this.tileset.url, "/nodepages/").concat(pageIndex), (_this$options$i3s = this.options.i3s) === null || _this$options$i3s === void 0 ? void 0 : _this$options$i3s.token);
47
- this.pendingNodePages[pageIndex] = {
48
- status: 'Pending',
49
- promise: (0, _core.load)(nodePageUrl, _i3sNodePageLoader.I3SNodePageLoader, this.options)
50
- };
51
- this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
52
- this.pendingNodePages[pageIndex].status = 'Done';
53
- }
54
-
55
- if (this.pendingNodePages[pageIndex].status === 'Pending') {
56
- this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;
57
- }
58
-
59
- const nodeIndex = id % this.nodesPerPage;
60
- return this.nodePages[pageIndex].nodes[nodeIndex];
61
- }
62
-
63
- async formTileFromNodePages(id) {
64
- const node = await this.getNodeById(id);
65
- const children = [];
66
-
67
- for (const child of node.children || []) {
68
- const childNode = await this.getNodeById(child);
69
- children.push({
70
- id: child,
71
- obb: childNode.obb
72
- });
73
- }
74
-
75
- let contentUrl = null;
76
- let textureUrl = null;
77
- let materialDefinition = null;
78
- let textureFormat = 'jpeg';
79
- let attributeUrls = [];
80
- let isDracoGeometry = false;
81
-
82
- if (node && node.mesh) {
83
- const {
84
- url,
85
- isDracoGeometry: isDracoGeometryResult
86
- } = node.mesh.geometry && this.getContentUrl(node.mesh.geometry) || {
87
- url: null,
88
- isDracoGeometry: null
89
- };
90
- contentUrl = url;
91
- isDracoGeometry = isDracoGeometryResult;
92
- const [textureData, nodeMaterialDefinition] = this.getInformationFromMaterial(node.mesh.material);
93
- materialDefinition = nodeMaterialDefinition;
94
- textureFormat = textureData.format || textureFormat;
95
-
96
- if (textureData.name) {
97
- textureUrl = "".concat(this.tileset.url, "/nodes/").concat(node.mesh.material.resource, "/textures/").concat(textureData.name);
60
+ (0, _createClass2.default)(I3SNodePagesTiles, [{
61
+ key: "getNodeById",
62
+ value: function () {
63
+ var _getNodeById = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(id) {
64
+ var pageIndex, _this$options$i3s, nodePageUrl, nodeIndex;
65
+
66
+ return _regenerator.default.wrap(function _callee$(_context) {
67
+ while (1) {
68
+ switch (_context.prev = _context.next) {
69
+ case 0:
70
+ pageIndex = Math.floor(id / this.nodesPerPage);
71
+
72
+ if (!(!this.nodePages[pageIndex] && !this.pendingNodePages[pageIndex])) {
73
+ _context.next = 8;
74
+ break;
75
+ }
76
+
77
+ nodePageUrl = (0, _urlUtils.getUrlWithToken)("".concat(this.tileset.url, "/nodepages/").concat(pageIndex), (_this$options$i3s = this.options.i3s) === null || _this$options$i3s === void 0 ? void 0 : _this$options$i3s.token);
78
+ this.pendingNodePages[pageIndex] = {
79
+ status: 'Pending',
80
+ promise: (0, _core.load)(nodePageUrl, _i3sNodePageLoader.I3SNodePageLoader, this.options)
81
+ };
82
+ _context.next = 6;
83
+ return this.pendingNodePages[pageIndex].promise;
84
+
85
+ case 6:
86
+ this.nodePages[pageIndex] = _context.sent;
87
+ this.pendingNodePages[pageIndex].status = 'Done';
88
+
89
+ case 8:
90
+ if (!(this.pendingNodePages[pageIndex].status === 'Pending')) {
91
+ _context.next = 12;
92
+ break;
93
+ }
94
+
95
+ _context.next = 11;
96
+ return this.pendingNodePages[pageIndex].promise;
97
+
98
+ case 11:
99
+ this.nodePages[pageIndex] = _context.sent;
100
+
101
+ case 12:
102
+ nodeIndex = id % this.nodesPerPage;
103
+ return _context.abrupt("return", this.nodePages[pageIndex].nodes[nodeIndex]);
104
+
105
+ case 14:
106
+ case "end":
107
+ return _context.stop();
108
+ }
109
+ }
110
+ }, _callee, this);
111
+ }));
112
+
113
+ function getNodeById(_x) {
114
+ return _getNodeById.apply(this, arguments);
98
115
  }
99
116
 
100
- if (this.tileset.attributeStorageInfo) {
101
- attributeUrls = (0, _urlUtils.generateTilesetAttributeUrls)(this.tileset, node.mesh.attribute.resource);
117
+ return getNodeById;
118
+ }()
119
+ }, {
120
+ key: "formTileFromNodePages",
121
+ value: function () {
122
+ var _formTileFromNodePages = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(id) {
123
+ var node, children, _iterator, _step, child, childNode, contentUrl, textureUrl, materialDefinition, textureFormat, attributeUrls, isDracoGeometry, _ref, url, isDracoGeometryResult, _this$getInformationF, textureData, nodeMaterialDefinition, lodSelection;
124
+
125
+ return _regenerator.default.wrap(function _callee2$(_context2) {
126
+ while (1) {
127
+ switch (_context2.prev = _context2.next) {
128
+ case 0:
129
+ _context2.next = 2;
130
+ return this.getNodeById(id);
131
+
132
+ case 2:
133
+ node = _context2.sent;
134
+ children = [];
135
+ _iterator = _createForOfIteratorHelper(node.children || []);
136
+ _context2.prev = 5;
137
+
138
+ _iterator.s();
139
+
140
+ case 7:
141
+ if ((_step = _iterator.n()).done) {
142
+ _context2.next = 15;
143
+ break;
144
+ }
145
+
146
+ child = _step.value;
147
+ _context2.next = 11;
148
+ return this.getNodeById(child);
149
+
150
+ case 11:
151
+ childNode = _context2.sent;
152
+ children.push({
153
+ id: child.toString(),
154
+ obb: childNode.obb
155
+ });
156
+
157
+ case 13:
158
+ _context2.next = 7;
159
+ break;
160
+
161
+ case 15:
162
+ _context2.next = 20;
163
+ break;
164
+
165
+ case 17:
166
+ _context2.prev = 17;
167
+ _context2.t0 = _context2["catch"](5);
168
+
169
+ _iterator.e(_context2.t0);
170
+
171
+ case 20:
172
+ _context2.prev = 20;
173
+
174
+ _iterator.f();
175
+
176
+ return _context2.finish(20);
177
+
178
+ case 23:
179
+ textureFormat = 'jpg';
180
+ attributeUrls = [];
181
+ isDracoGeometry = false;
182
+
183
+ if (node && node.mesh) {
184
+ _ref = node.mesh.geometry && this.getContentUrl(node.mesh.geometry) || {
185
+ isDracoGeometry: false
186
+ }, url = _ref.url, isDracoGeometryResult = _ref.isDracoGeometry;
187
+ contentUrl = url;
188
+ isDracoGeometry = isDracoGeometryResult;
189
+ _this$getInformationF = this.getInformationFromMaterial(node.mesh.material), textureData = _this$getInformationF.textureData, nodeMaterialDefinition = _this$getInformationF.materialDefinition;
190
+ materialDefinition = nodeMaterialDefinition;
191
+ textureFormat = textureData.format || textureFormat;
192
+
193
+ if (textureData.name) {
194
+ textureUrl = "".concat(this.tileset.url, "/nodes/").concat(node.mesh.material.resource, "/textures/").concat(textureData.name);
195
+ }
196
+
197
+ if (this.tileset.attributeStorageInfo) {
198
+ attributeUrls = (0, _urlUtils.generateTilesetAttributeUrls)(this.tileset, node.mesh.attribute.resource);
199
+ }
200
+ }
201
+
202
+ lodSelection = this.getLodSelection(node);
203
+ return _context2.abrupt("return", (0, _parseI3s.normalizeTileNonUrlData)({
204
+ id: id.toString(),
205
+ lodSelection: lodSelection,
206
+ obb: node.obb,
207
+ contentUrl: contentUrl,
208
+ textureUrl: textureUrl,
209
+ attributeUrls: attributeUrls,
210
+ materialDefinition: materialDefinition,
211
+ textureFormat: textureFormat,
212
+ textureLoaderOptions: this.textureLoaderOptions,
213
+ children: children,
214
+ isDracoGeometry: isDracoGeometry
215
+ }));
216
+
217
+ case 29:
218
+ case "end":
219
+ return _context2.stop();
220
+ }
221
+ }
222
+ }, _callee2, this, [[5, 17, 20, 23]]);
223
+ }));
224
+
225
+ function formTileFromNodePages(_x2) {
226
+ return _formTileFromNodePages.apply(this, arguments);
102
227
  }
103
- }
104
-
105
- const lodSelection = this.getLodSelection(node);
106
- return (0, _parseI3s.normalizeTileNonUrlData)({
107
- id,
108
- lodSelection,
109
- obb: node.obb,
110
- contentUrl,
111
- textureUrl,
112
- attributeUrls,
113
- materialDefinition,
114
- textureFormat,
115
- textureLoaderOptions: this.textureLoaderOptions,
116
- children,
117
- isDracoGeometry
118
- });
119
- }
120
228
 
121
- getContentUrl(meshGeometryData) {
122
- let result = {};
123
- const geometryDefinition = this.tileset.geometryDefinitions[meshGeometryData.definition];
124
- let geometryIndex = -1;
229
+ return formTileFromNodePages;
230
+ }()
231
+ }, {
232
+ key: "getContentUrl",
233
+ value: function getContentUrl(meshGeometryData) {
234
+ var result = null;
235
+ var geometryDefinition = this.tileset.geometryDefinitions[meshGeometryData.definition];
236
+ var geometryIndex = -1;
237
+
238
+ if (this.options.i3s && this.options.i3s.useDracoGeometry) {
239
+ geometryIndex = geometryDefinition.geometryBuffers.findIndex(function (buffer) {
240
+ return buffer.compressedAttributes && buffer.compressedAttributes.encoding === 'draco';
241
+ });
242
+ }
125
243
 
126
- if (this.options.i3s && this.options.i3s.useDracoGeometry) {
127
- geometryIndex = geometryDefinition.geometryBuffers.findIndex(buffer => buffer.compressedAttributes && buffer.compressedAttributes.encoding === 'draco');
128
- }
244
+ if (geometryIndex === -1) {
245
+ geometryIndex = geometryDefinition.geometryBuffers.findIndex(function (buffer) {
246
+ return !buffer.compressedAttributes;
247
+ });
248
+ }
129
249
 
130
- if (geometryIndex === -1) {
131
- geometryIndex = geometryDefinition.geometryBuffers.findIndex(buffer => !buffer.compressedAttributes);
132
- }
250
+ if (geometryIndex !== -1) {
251
+ var isDracoGeometry = Boolean(geometryDefinition.geometryBuffers[geometryIndex].compressedAttributes);
252
+ result = {
253
+ url: "".concat(this.tileset.url, "/nodes/").concat(meshGeometryData.resource, "/geometries/").concat(geometryIndex),
254
+ isDracoGeometry: isDracoGeometry
255
+ };
256
+ }
133
257
 
134
- if (geometryIndex !== -1) {
135
- const isDracoGeometry = Boolean(geometryDefinition.geometryBuffers[geometryIndex].compressedAttributes);
136
- result = {
137
- url: "".concat(this.tileset.url, "/nodes/").concat(meshGeometryData.resource, "/geometries/").concat(geometryIndex),
138
- isDracoGeometry
139
- };
258
+ return result;
140
259
  }
260
+ }, {
261
+ key: "getLodSelection",
262
+ value: function getLodSelection(node) {
263
+ var lodSelection = [];
264
+
265
+ if (this.lodSelectionMetricType === 'maxScreenThresholdSQ') {
266
+ lodSelection.push({
267
+ metricType: 'maxScreenThreshold',
268
+ maxError: Math.sqrt(node.lodThreshold / (Math.PI * 0.25))
269
+ });
270
+ }
141
271
 
142
- return result;
143
- }
144
-
145
- getLodSelection(node) {
146
- const lodSelection = [];
147
-
148
- if (this.lodSelectionMetricType === 'maxScreenThresholdSQ') {
149
272
  lodSelection.push({
150
- metricType: 'maxScreenThreshold',
151
- maxError: Math.sqrt(node.lodThreshold / (Math.PI * 0.25))
273
+ metricType: this.lodSelectionMetricType,
274
+ maxError: node.lodThreshold
152
275
  });
276
+ return lodSelection;
153
277
  }
278
+ }, {
279
+ key: "getInformationFromMaterial",
280
+ value: function getInformationFromMaterial(material) {
281
+ var informationFromMaterial = {
282
+ textureData: {
283
+ name: null
284
+ }
285
+ };
154
286
 
155
- lodSelection.push({
156
- metricType: this.lodSelectionMetricType,
157
- maxError: node.lodThreshold
158
- });
159
- return lodSelection;
160
- }
161
-
162
- getInformationFromMaterial(material) {
163
- const textureDataDefault = {
164
- name: null,
165
- format: null
166
- };
167
-
168
- if (material) {
169
- const materialDefinition = this.tileset.materialDefinitions[material.definition];
170
- const textureSetDefinitionIndex = materialDefinition && materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.baseColorTexture && materialDefinition.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId;
171
-
172
- if (textureSetDefinitionIndex || textureSetDefinitionIndex === 0) {
173
- const textureData = this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] || textureDataDefault;
174
- return [textureData, materialDefinition];
175
- }
176
-
177
- return [textureDataDefault, materialDefinition];
178
- }
179
-
180
- return [textureDataDefault, null];
181
- }
287
+ if (material) {
288
+ var _this$tileset$materia;
182
289
 
183
- initSelectedFormatsForTextureDefinitions(tileset) {
184
- this.textureDefinitionsSelectedFormats = [];
185
- const possibleI3sFormats = this.getSupportedTextureFormats();
186
- const textureSetDefinitions = tileset.textureSetDefinitions || [];
290
+ var materialDefinition = (_this$tileset$materia = this.tileset.materialDefinitions) === null || _this$tileset$materia === void 0 ? void 0 : _this$tileset$materia[material.definition];
187
291
 
188
- for (const textureSetDefinition of textureSetDefinitions) {
189
- const formats = textureSetDefinition && textureSetDefinition.formats || [];
190
- let selectedFormat = null;
292
+ if (materialDefinition) {
293
+ var _materialDefinition$p, _materialDefinition$p2;
191
294
 
192
- for (const i3sFormat of possibleI3sFormats) {
193
- const format = formats.find(value => value.format === i3sFormat);
295
+ informationFromMaterial.materialDefinition = materialDefinition;
296
+ var textureSetDefinitionIndex = materialDefinition === null || materialDefinition === void 0 ? void 0 : (_materialDefinition$p = materialDefinition.pbrMetallicRoughness) === null || _materialDefinition$p === void 0 ? void 0 : (_materialDefinition$p2 = _materialDefinition$p.baseColorTexture) === null || _materialDefinition$p2 === void 0 ? void 0 : _materialDefinition$p2.textureSetDefinitionId;
194
297
 
195
- if (format) {
196
- selectedFormat = format;
197
- break;
298
+ if (typeof textureSetDefinitionIndex === 'number') {
299
+ informationFromMaterial.textureData = this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] || informationFromMaterial.textureData;
300
+ }
198
301
  }
199
302
  }
200
303
 
201
- if (selectedFormat && selectedFormat.format === 'ktx2') {
202
- this.textureLoaderOptions.basis = {
203
- format: (0, _textures.selectSupportedBasisFormat)(),
204
- containerFormat: 'ktx2',
205
- module: 'encoder'
206
- };
304
+ return informationFromMaterial;
305
+ }
306
+ }, {
307
+ key: "initSelectedFormatsForTextureDefinitions",
308
+ value: function initSelectedFormatsForTextureDefinitions(tileset) {
309
+ this.textureDefinitionsSelectedFormats = [];
310
+ var possibleI3sFormats = this.getSupportedTextureFormats();
311
+ var textureSetDefinitions = tileset.textureSetDefinitions || [];
312
+
313
+ var _iterator2 = _createForOfIteratorHelper(textureSetDefinitions),
314
+ _step2;
315
+
316
+ try {
317
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
318
+ var textureSetDefinition = _step2.value;
319
+ var formats = textureSetDefinition && textureSetDefinition.formats || [];
320
+ var selectedFormat = null;
321
+
322
+ var _iterator3 = _createForOfIteratorHelper(possibleI3sFormats),
323
+ _step3;
324
+
325
+ try {
326
+ var _loop = function _loop() {
327
+ var i3sFormat = _step3.value;
328
+ var format = formats.find(function (value) {
329
+ return value.format === i3sFormat;
330
+ });
331
+
332
+ if (format) {
333
+ selectedFormat = format;
334
+ return "break";
335
+ }
336
+ };
337
+
338
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
339
+ var _ret = _loop();
340
+
341
+ if (_ret === "break") break;
342
+ }
343
+ } catch (err) {
344
+ _iterator3.e(err);
345
+ } finally {
346
+ _iterator3.f();
347
+ }
348
+
349
+ if (selectedFormat && selectedFormat.format === 'ktx2') {
350
+ this.textureLoaderOptions.basis = {
351
+ format: (0, _textures.selectSupportedBasisFormat)(),
352
+ containerFormat: 'ktx2',
353
+ module: 'encoder'
354
+ };
355
+ }
356
+
357
+ this.textureDefinitionsSelectedFormats.push(selectedFormat);
358
+ }
359
+ } catch (err) {
360
+ _iterator2.e(err);
361
+ } finally {
362
+ _iterator2.f();
207
363
  }
208
-
209
- this.textureDefinitionsSelectedFormats.push(selectedFormat);
210
364
  }
211
- }
365
+ }, {
366
+ key: "getSupportedTextureFormats",
367
+ value: function getSupportedTextureFormats() {
368
+ var formats = [];
212
369
 
213
- getSupportedTextureFormats() {
214
- const formats = [];
370
+ if (!this.options.i3s || this.options.i3s.useCompressedTextures) {
371
+ var supportedCompressedFormats = (0, _textures.getSupportedGPUTextureFormats)();
215
372
 
216
- if (!this.options.i3s || this.options.i3s.useCompressedTextures) {
217
- const supportedCompressedFormats = (0, _textures.getSupportedGPUTextureFormats)();
373
+ if (supportedCompressedFormats.has('etc2')) {
374
+ formats.push('ktx-etc2');
375
+ }
218
376
 
219
- if (supportedCompressedFormats.has('etc2')) {
220
- formats.push('ktx-etc2');
221
- }
377
+ if (supportedCompressedFormats.has('dxt')) {
378
+ formats.push('dds');
379
+ }
222
380
 
223
- if (supportedCompressedFormats.has('dxt')) {
224
- formats.push('dds');
381
+ formats.push('ktx2');
225
382
  }
226
383
 
227
- formats.push('ktx2');
384
+ formats.push('jpg');
385
+ formats.push('png');
386
+ return formats;
228
387
  }
229
-
230
- formats.push('jpg');
231
- formats.push('png');
232
- return formats;
233
- }
234
-
235
- }
388
+ }]);
389
+ return I3SNodePagesTiles;
390
+ }();
236
391
 
237
392
  exports.default = I3SNodePagesTiles;
238
393
  //# sourceMappingURL=i3s-nodepages-tiles.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/helpers/i3s-nodepages-tiles.ts"],"names":["I3SNodePagesTiles","constructor","tileset","options","nodesPerPage","nodePages","lodSelectionMetricType","initSelectedFormatsForTextureDefinitions","getNodeById","id","pageIndex","Math","floor","pendingNodePages","nodePageUrl","url","i3s","token","status","promise","I3SNodePageLoader","nodeIndex","nodes","formTileFromNodePages","node","children","child","childNode","push","obb","contentUrl","textureUrl","materialDefinition","textureFormat","attributeUrls","isDracoGeometry","mesh","isDracoGeometryResult","geometry","getContentUrl","textureData","nodeMaterialDefinition","getInformationFromMaterial","material","format","name","resource","attributeStorageInfo","attribute","lodSelection","getLodSelection","textureLoaderOptions","meshGeometryData","result","geometryDefinition","geometryDefinitions","definition","geometryIndex","useDracoGeometry","geometryBuffers","findIndex","buffer","compressedAttributes","encoding","Boolean","metricType","maxError","sqrt","lodThreshold","PI","textureDataDefault","materialDefinitions","textureSetDefinitionIndex","pbrMetallicRoughness","baseColorTexture","textureSetDefinitionId","textureDefinitionsSelectedFormats","possibleI3sFormats","getSupportedTextureFormats","textureSetDefinitions","textureSetDefinition","formats","selectedFormat","i3sFormat","find","value","basis","containerFormat","module","useCompressedTextures","supportedCompressedFormats","has"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AAKe,MAAMA,iBAAN,CAAwB;AAgBrCC,EAAAA,WAAW,CAACC,OAAD,EAAmBC,OAAnB,EAAoC;AAAA;AAAA,qDAdvB,EAcuB;AAAA,4DAbgC,EAahC;AAAA;AAAA;AAAA;AAAA,6EATJ,EASI;AAAA,gEARM,EAQN;AAC7C,SAAKD,OAAL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ChC1C,UAAAA,MAAM,EAAE,2CADwB;AAEhC2C,UAAAA,eAAe,EAAE,MAFe;AAGhCC,UAAAA,MAAM,EAAE;AAHwB,SAAlC;AAKD;;AAED,WAAKZ,iCAAL,CAAuChD,IAAvC,CAA4CsD,cAA5C;AACD;AACF;;AAMOJ,EAAAA,0BAA0B,GAAa;AAC7C,UAAMG,OAAiB,GAAG,EAA1B;;AACA,QAAI,CAAC,KAAK9E,OAAL,CAAaa,GAAd,IAAqB,KAAKb,OAAL,CAAaa,GAAb,CAAiByE,qBAA1C,EAAiE;AAE/D,YAAMC,0BAA0B,GAAG,8CAAnC;;AAGA,UAAIA,0BAA0B,CAACC,GAA3B,CAA+B,MAA/B,CAAJ,EAA4C;AAC1CV,QAAAA,OAAO,CAACrD,IAAR,CAAa,UAAb;AACD;;AACD,UAAI8D,0BAA0B,CAACC,GAA3B,CAA+B,KAA/B,CAAJ,EAA2C;AACzCV,QAAAA,OAAO,CAACrD,IAAR,CAAa,KAAb;AACD;;AAIDqD,MAAAA,OAAO,CAACrD,IAAR,CAAa,MAAb;AACD;;AAEDqD,IAAAA,OAAO,CAACrD,IAAR,CAAa,KAAb;AACAqD,IAAAA,OAAO,CAACrD,IAAR,CAAa,KAAb;AACA,WAAOqD,OAAP;AACD;;AA7PoC","sourcesContent":["import {load} from '@loaders.gl/core';\nimport {getSupportedGPUTextureFormats, selectSupportedBasisFormat} from '@loaders.gl/textures';\nimport {Tileset, NodePage} from '../../types';\nimport {I3SNodePageLoader} from '../../i3s-node-page-loader';\nimport {normalizeTileNonUrlData} from '../parsers/parse-i3s';\nimport {getUrlWithToken, generateTilesetAttributeUrls} from '../utils/url-utils';\n\n/**\n * class I3SNodePagesTiles - loads nodePages and form i3s tiles from them\n */\nexport default class I3SNodePagesTiles {\n tileset: Tileset;\n nodePages: NodePage[] = [];\n pendingNodePages: {promise: Promise<NodePage>; status: 'Pending' | 'Done'}[] = [];\n nodesPerPage: number;\n options: {[key: string]: any};\n lodSelectionMetricType: any;\n textureDefinitionsSelectedFormats: any[] = [];\n private textureLoaderOptions: {[key: string]: any} = {};\n\n /**\n * @constructs\n * Create a I3SNodePagesTiles instance.\n * @param tileset - i3s tileset header ('layers/0')\n * @param options - i3s loader options\n */\n constructor(tileset: Tileset, options: object) {\n this.tileset = {...tileset}; // spread the tileset to avoid circular reference\n this.nodesPerPage = tileset.nodePages.nodesPerPage;\n this.lodSelectionMetricType = tileset.nodePages.lodSelectionMetricType;\n this.options = options;\n\n this.initSelectedFormatsForTextureDefinitions(tileset);\n }\n\n /**\n * Loads some nodePage and return a particular node from it\n * @param id - id of node through all node pages\n */\n async getNodeById(id: number) {\n const pageIndex = Math.floor(id / this.nodesPerPage);\n if (!this.nodePages[pageIndex] && !this.pendingNodePages[pageIndex]) {\n const nodePageUrl = getUrlWithToken(\n `${this.tileset.url}/nodepages/${pageIndex}`,\n this.options.i3s?.token\n );\n this.pendingNodePages[pageIndex] = {\n status: 'Pending',\n promise: load(nodePageUrl, I3SNodePageLoader, this.options)\n };\n this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;\n this.pendingNodePages[pageIndex].status = 'Done';\n }\n if (this.pendingNodePages[pageIndex].status === 'Pending') {\n this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;\n }\n const nodeIndex = id % this.nodesPerPage;\n return this.nodePages[pageIndex].nodes[nodeIndex];\n }\n\n /**\n * Forms tile header using node and tileset data\n * @param id - id of node through all node pages\n */\n // eslint-disable-next-line complexity\n async formTileFromNodePages(id: number) {\n const node = await this.getNodeById(id);\n const children: any[] = [];\n for (const child of node.children || []) {\n const childNode = await this.getNodeById(child);\n children.push({\n id: child,\n obb: childNode.obb\n });\n }\n\n let contentUrl = null;\n let textureUrl: string | null = null;\n let materialDefinition = null;\n let textureFormat = 'jpeg';\n let attributeUrls: string[] = [];\n let isDracoGeometry = false;\n\n if (node && node.mesh) {\n // Get geometry resource URL and type (compressed / non-compressed)\n const {url, isDracoGeometry: isDracoGeometryResult} = (node.mesh.geometry &&\n this.getContentUrl(node.mesh.geometry)) || {url: null, isDracoGeometry: null};\n contentUrl = url;\n isDracoGeometry = isDracoGeometryResult;\n\n const [textureData, nodeMaterialDefinition] = this.getInformationFromMaterial(\n node.mesh.material\n );\n materialDefinition = nodeMaterialDefinition;\n textureFormat = textureData.format || textureFormat;\n if (textureData.name) {\n textureUrl = `${this.tileset.url}/nodes/${node.mesh.material.resource}/textures/${textureData.name}`;\n }\n\n if (this.tileset.attributeStorageInfo) {\n attributeUrls = generateTilesetAttributeUrls(this.tileset, node.mesh.attribute.resource);\n }\n }\n\n const lodSelection = this.getLodSelection(node);\n\n return normalizeTileNonUrlData({\n id,\n lodSelection,\n obb: node.obb,\n contentUrl,\n textureUrl,\n attributeUrls,\n materialDefinition,\n textureFormat,\n textureLoaderOptions: this.textureLoaderOptions,\n children,\n isDracoGeometry\n });\n }\n\n /**\n * Forms url and type of geometry resource by nodepage's data and `geometryDefinitions` in the tileset\n * @param {Object} meshGeometryData - data about the node's mesh from the nodepage\n * @returns {Object} -\n * {string} url - url to the geometry resource\n * {boolean} isDracoGeometry - whether the geometry resource contain DRACO compressed geometry\n */\n private getContentUrl(meshGeometryData) {\n let result = {};\n const geometryDefinition = this.tileset.geometryDefinitions[meshGeometryData.definition];\n let geometryIndex = -1;\n // Try to find DRACO geometryDefinition of `useDracoGeometry` option is set\n if (this.options.i3s && this.options.i3s.useDracoGeometry) {\n geometryIndex = geometryDefinition.geometryBuffers.findIndex(\n (buffer) => buffer.compressedAttributes && buffer.compressedAttributes.encoding === 'draco'\n );\n }\n // If DRACO geometry is not applicable try to select non-compressed geometry\n if (geometryIndex === -1) {\n geometryIndex = geometryDefinition.geometryBuffers.findIndex(\n (buffer) => !buffer.compressedAttributes\n );\n }\n if (geometryIndex !== -1) {\n const isDracoGeometry = Boolean(\n geometryDefinition.geometryBuffers[geometryIndex].compressedAttributes\n );\n result = {\n url: `${this.tileset.url}/nodes/${meshGeometryData.resource}/geometries/${geometryIndex}`,\n isDracoGeometry\n };\n }\n return result;\n }\n\n /**\n * Forms 1.6 compatible LOD selection object from a nodepage's node data\n * @param {Object} node - a node from nodepage\n * @returns {Object[]} - Array of object of following properties:\n * {string} metricType - the label of the LOD metric\n * {number} maxError - the value of the metric\n */\n private getLodSelection(node): object[] {\n const lodSelection: object[] = [];\n if (this.lodSelectionMetricType === 'maxScreenThresholdSQ') {\n lodSelection.push({\n metricType: 'maxScreenThreshold',\n maxError: Math.sqrt(node.lodThreshold / (Math.PI * 0.25))\n });\n }\n lodSelection.push({\n metricType: this.lodSelectionMetricType,\n maxError: node.lodThreshold\n });\n return lodSelection;\n }\n\n /**\n * Returns information about texture and material from `materialDefinitions`\n * @param {Object} material - material data from nodepage\n * @returns {Object[]} - Couple [textureData, materialDefinition]\n * {string} textureData.name - path name of the texture\n * {string} textureData.format - format of the texture\n * materialDefinition - PBR-like material definition from `materialDefinitions`\n */\n private getInformationFromMaterial(material) {\n const textureDataDefault = {name: null, format: null};\n if (material) {\n const materialDefinition = this.tileset.materialDefinitions[material.definition];\n const textureSetDefinitionIndex =\n materialDefinition &&\n materialDefinition.pbrMetallicRoughness &&\n materialDefinition.pbrMetallicRoughness.baseColorTexture &&\n materialDefinition.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId;\n if (textureSetDefinitionIndex || textureSetDefinitionIndex === 0) {\n const textureData =\n this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] || textureDataDefault;\n return [textureData, materialDefinition];\n }\n return [textureDataDefault, materialDefinition];\n }\n return [textureDataDefault, null];\n }\n\n /**\n * Sets preferable and supported format for each textureDefinition of the tileset\n * @param {Object} tileset - I3S layer data\n * @returns {void}\n */\n private initSelectedFormatsForTextureDefinitions(tileset) {\n this.textureDefinitionsSelectedFormats = [];\n const possibleI3sFormats = this.getSupportedTextureFormats();\n const textureSetDefinitions = tileset.textureSetDefinitions || [];\n for (const textureSetDefinition of textureSetDefinitions) {\n const formats = (textureSetDefinition && textureSetDefinition.formats) || [];\n let selectedFormat: {format: string; name: string} | null = null;\n for (const i3sFormat of possibleI3sFormats) {\n const format = formats.find((value) => value.format === i3sFormat);\n if (format) {\n selectedFormat = format;\n break;\n }\n }\n // For I3S 1.8 need to define basis target format to decode\n if (selectedFormat && selectedFormat.format === 'ktx2') {\n this.textureLoaderOptions.basis = {\n format: selectSupportedBasisFormat(),\n containerFormat: 'ktx2',\n module: 'encoder'\n };\n }\n\n this.textureDefinitionsSelectedFormats.push(selectedFormat);\n }\n }\n\n /**\n * Returns the array of supported texture format\n * @returns list of format strings\n */\n private getSupportedTextureFormats(): string[] {\n const formats: string[] = [];\n if (!this.options.i3s || this.options.i3s.useCompressedTextures) {\n // I3S 1.7 selection\n const supportedCompressedFormats = getSupportedGPUTextureFormats();\n // List of possible in i3s formats:\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md\n if (supportedCompressedFormats.has('etc2')) {\n formats.push('ktx-etc2');\n }\n if (supportedCompressedFormats.has('dxt')) {\n formats.push('dds');\n }\n\n // I3S 1.8 selection\n // ktx2 wraps basis texture which at the edge case can be decoded as uncompressed image\n formats.push('ktx2');\n }\n\n formats.push('jpg');\n formats.push('png');\n return formats;\n }\n}\n"],"file":"i3s-nodepages-tiles.js"}
1
+ {"version":3,"sources":["../../../../src/lib/helpers/i3s-nodepages-tiles.ts"],"names":["I3SNodePagesTiles","tileset","options","nodesPerPage","nodePages","lodSelectionMetricType","initSelectedFormatsForTextureDefinitions","id","pageIndex","Math","floor","pendingNodePages","nodePageUrl","url","i3s","token","status","promise","I3SNodePageLoader","nodeIndex","nodes","getNodeById","node","children","child","childNode","push","toString","obb","textureFormat","attributeUrls","isDracoGeometry","mesh","geometry","getContentUrl","isDracoGeometryResult","contentUrl","getInformationFromMaterial","material","textureData","nodeMaterialDefinition","materialDefinition","format","name","textureUrl","resource","attributeStorageInfo","attribute","lodSelection","getLodSelection","textureLoaderOptions","meshGeometryData","result","geometryDefinition","geometryDefinitions","definition","geometryIndex","useDracoGeometry","geometryBuffers","findIndex","buffer","compressedAttributes","encoding","Boolean","metricType","maxError","sqrt","lodThreshold","PI","informationFromMaterial","materialDefinitions","textureSetDefinitionIndex","pbrMetallicRoughness","baseColorTexture","textureSetDefinitionId","textureDefinitionsSelectedFormats","possibleI3sFormats","getSupportedTextureFormats","textureSetDefinitions","textureSetDefinition","formats","selectedFormat","i3sFormat","find","value","basis","containerFormat","module","useCompressedTextures","supportedCompressedFormats","has"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;IAkBqBA,iB;AAgBnB,6BAAYC,OAAZ,EAAuCC,OAAvC,EAA+D;AAAA;;AAAA;AAAA;AAAA,qDAdvC,EAcuC;AAAA,4DAbgB,EAahB;AAAA;AAAA;AAAA;AAAA,6EAT0B,EAS1B;AAAA,gEARV,EAQU;AAC7D,SAAKD,OAAL,qBAAmBA,OAAnB;AACA,SAAKE,YAAL,GAAoB,uBAAAF,OAAO,CAACG,SAAR,0EAAmBD,YAAnB,KAAmC,EAAvD;AACA,SAAKE,sBAAL,0BAA8BJ,OAAO,CAACG,SAAtC,wDAA8B,oBAAmBC,sBAAjD;AACA,SAAKH,OAAL,GAAeA,OAAf;AAEA,SAAKI,wCAAL,CAA8CL,OAA9C;AACD;;;;;mFAMD,iBAAkBM,EAAlB;AAAA;;AAAA;AAAA;AAAA;AAAA;AACQC,gBAAAA,SADR,GACoBC,IAAI,CAACC,KAAL,CAAWH,EAAE,GAAG,KAAKJ,YAArB,CADpB;;AAAA,sBAEM,CAAC,KAAKC,SAAL,CAAeI,SAAf,CAAD,IAA8B,CAAC,KAAKG,gBAAL,CAAsBH,SAAtB,CAFrC;AAAA;AAAA;AAAA;;AAGUI,gBAAAA,WAHV,GAGwB,yCACf,KAAKX,OAAL,CAAaY,GADE,wBACeL,SADf,wBAElB,KAAKN,OAAL,CAAaY,GAFK,sDAElB,kBAAkBC,KAFA,CAHxB;AAOI,qBAA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ACtD,iBAAKQ,oBAAL,CAA0BmC,KAA1B,GAAkC;AAChC3C,cAAAA,MAAM,EAAE,2CADwB;AAEhC4C,cAAAA,eAAe,EAAE,MAFe;AAGhCC,cAAAA,MAAM,EAAE;AAHwB,aAAlC;AAKD;;AAED,eAAKZ,iCAAL,CAAuCjD,IAAvC,CAA4CuD,cAA5C;AACD;AAxB+E;AAAA;AAAA;AAAA;AAAA;AAyBjF;;;WAMD,sCAAyD;AACvD,UAAMD,OAA2B,GAAG,EAApC;;AACA,UAAI,CAAC,KAAK9E,OAAL,CAAaY,GAAd,IAAqB,KAAKZ,OAAL,CAAaY,GAAb,CAAiB0E,qBAA1C,EAAiE;AAE/D,YAAMC,0BAA0B,GAAG,8CAAnC;;AAGA,YAAIA,0BAA0B,CAACC,GAA3B,CAA+B,MAA/B,CAAJ,EAA4C;AAC1CV,UAAAA,OAAO,CAACtD,IAAR,CAAa,UAAb;AACD;;AACD,YAAI+D,0BAA0B,CAACC,GAA3B,CAA+B,KAA/B,CAAJ,EAA2C;AACzCV,UAAAA,OAAO,CAACtD,IAAR,CAAa,KAAb;AACD;;AAIDsD,QAAAA,OAAO,CAACtD,IAAR,CAAa,MAAb;AACD;;AAEDsD,MAAAA,OAAO,CAACtD,IAAR,CAAa,KAAb;AACAsD,MAAAA,OAAO,CAACtD,IAAR,CAAa,KAAb;AACA,aAAOsD,OAAP;AACD","sourcesContent":["import {load} from '@loaders.gl/core';\nimport {getSupportedGPUTextureFormats, selectSupportedBasisFormat} from '@loaders.gl/textures';\nimport {I3SNodePageLoader} from '../../i3s-node-page-loader';\nimport {normalizeTileNonUrlData} from '../parsers/parse-i3s';\nimport {getUrlWithToken, generateTilesetAttributeUrls} from '../utils/url-utils';\nimport type {LoaderOptions} from '@loaders.gl/loader-utils';\nimport {\n I3STilesetHeader,\n LodSelection,\n NodePage,\n NodeInPage,\n Obb,\n MeshMaterial,\n I3SMaterialDefinition,\n I3STextureFormat,\n MeshGeometry,\n I3STileHeader\n} from '../../types';\n\n/**\n * class I3SNodePagesTiles - loads nodePages and form i3s tiles from them\n */\nexport default class I3SNodePagesTiles {\n tileset: I3STilesetHeader;\n nodePages: NodePage[] = [];\n pendingNodePages: {promise: Promise<NodePage>; status: 'Pending' | 'Done'}[] = [];\n nodesPerPage: number;\n options: LoaderOptions;\n lodSelectionMetricType?: string;\n textureDefinitionsSelectedFormats: ({format: I3STextureFormat; name: string} | null)[] = [];\n private textureLoaderOptions: {[key: string]: any} = {};\n\n /**\n * @constructs\n * Create a I3SNodePagesTiles instance.\n * @param tileset - i3s tileset header ('layers/0')\n * @param options - i3s loader options\n */\n constructor(tileset: I3STilesetHeader, options: LoaderOptions) {\n this.tileset = {...tileset}; // spread the tileset to avoid circular reference\n this.nodesPerPage = tileset.nodePages?.nodesPerPage || 64;\n this.lodSelectionMetricType = tileset.nodePages?.lodSelectionMetricType;\n this.options = options;\n\n this.initSelectedFormatsForTextureDefinitions(tileset);\n }\n\n /**\n * Loads some nodePage and return a particular node from it\n * @param id - id of node through all node pages\n */\n async getNodeById(id: number): Promise<NodeInPage> {\n const pageIndex = Math.floor(id / this.nodesPerPage);\n if (!this.nodePages[pageIndex] && !this.pendingNodePages[pageIndex]) {\n const nodePageUrl = getUrlWithToken(\n `${this.tileset.url}/nodepages/${pageIndex}`,\n this.options.i3s?.token\n );\n this.pendingNodePages[pageIndex] = {\n status: 'Pending',\n promise: load(nodePageUrl, I3SNodePageLoader, this.options)\n };\n this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;\n this.pendingNodePages[pageIndex].status = 'Done';\n }\n if (this.pendingNodePages[pageIndex].status === 'Pending') {\n this.nodePages[pageIndex] = await this.pendingNodePages[pageIndex].promise;\n }\n const nodeIndex = id % this.nodesPerPage;\n return this.nodePages[pageIndex].nodes[nodeIndex];\n }\n\n /**\n * Forms tile header using node and tileset data\n * @param id - id of node through all node pages\n */\n // eslint-disable-next-line complexity\n async formTileFromNodePages(id: number): Promise<I3STileHeader> {\n const node: NodeInPage = await this.getNodeById(id);\n const children: {id: string; obb: Obb}[] = [];\n for (const child of node.children || []) {\n const childNode = await this.getNodeById(child);\n children.push({\n id: child.toString(),\n obb: childNode.obb\n });\n }\n\n let contentUrl: string | undefined;\n let textureUrl: string | undefined;\n let materialDefinition: I3SMaterialDefinition | undefined;\n let textureFormat: I3STextureFormat = 'jpg';\n let attributeUrls: string[] = [];\n let isDracoGeometry: boolean = false;\n\n if (node && node.mesh) {\n // Get geometry resource URL and type (compressed / non-compressed)\n const {url, isDracoGeometry: isDracoGeometryResult} = (node.mesh.geometry &&\n this.getContentUrl(node.mesh.geometry)) || {isDracoGeometry: false};\n contentUrl = url;\n isDracoGeometry = isDracoGeometryResult;\n\n const {textureData, materialDefinition: nodeMaterialDefinition} =\n this.getInformationFromMaterial(node.mesh.material);\n materialDefinition = nodeMaterialDefinition;\n textureFormat = textureData.format || textureFormat;\n if (textureData.name) {\n textureUrl = `${this.tileset.url}/nodes/${node.mesh.material.resource}/textures/${textureData.name}`;\n }\n\n if (this.tileset.attributeStorageInfo) {\n attributeUrls = generateTilesetAttributeUrls(this.tileset, node.mesh.attribute.resource);\n }\n }\n\n const lodSelection = this.getLodSelection(node);\n\n return normalizeTileNonUrlData({\n id: id.toString(),\n lodSelection,\n obb: node.obb,\n contentUrl,\n textureUrl,\n attributeUrls,\n materialDefinition,\n textureFormat,\n textureLoaderOptions: this.textureLoaderOptions,\n children,\n isDracoGeometry\n });\n }\n\n /**\n * Forms url and type of geometry resource by nodepage's data and `geometryDefinitions` in the tileset\n * @param - data about the node's mesh from the nodepage\n * @returns -\n * {string} url - url to the geometry resource\n * {boolean} isDracoGeometry - whether the geometry resource contain DRACO compressed geometry\n */\n private getContentUrl(meshGeometryData: MeshGeometry) {\n let result: {url: string; isDracoGeometry: boolean} | null = null;\n // @ts-ignore\n const geometryDefinition = this.tileset.geometryDefinitions[meshGeometryData.definition];\n let geometryIndex = -1;\n // Try to find DRACO geometryDefinition of `useDracoGeometry` option is set\n if (this.options.i3s && this.options.i3s.useDracoGeometry) {\n geometryIndex = geometryDefinition.geometryBuffers.findIndex(\n (buffer) => buffer.compressedAttributes && buffer.compressedAttributes.encoding === 'draco'\n );\n }\n // If DRACO geometry is not applicable try to select non-compressed geometry\n if (geometryIndex === -1) {\n geometryIndex = geometryDefinition.geometryBuffers.findIndex(\n (buffer) => !buffer.compressedAttributes\n );\n }\n if (geometryIndex !== -1) {\n const isDracoGeometry = Boolean(\n geometryDefinition.geometryBuffers[geometryIndex].compressedAttributes\n );\n result = {\n url: `${this.tileset.url}/nodes/${meshGeometryData.resource}/geometries/${geometryIndex}`,\n isDracoGeometry\n };\n }\n return result;\n }\n\n /**\n * Forms 1.6 compatible LOD selection object from a nodepage's node data\n * @param node - a node from nodepage\n * @returns- Array of LodSelection\n */\n private getLodSelection(node: NodeInPage): LodSelection[] {\n const lodSelection: LodSelection[] = [];\n if (this.lodSelectionMetricType === 'maxScreenThresholdSQ') {\n lodSelection.push({\n metricType: 'maxScreenThreshold',\n // @ts-ignore\n maxError: Math.sqrt(node.lodThreshold / (Math.PI * 0.25))\n });\n }\n lodSelection.push({\n metricType: this.lodSelectionMetricType,\n // @ts-ignore\n maxError: node.lodThreshold\n });\n return lodSelection;\n }\n\n /**\n * Returns information about texture and material from `materialDefinitions`\n * @param material - material data from nodepage\n * @returns - Couple {textureData, materialDefinition}\n * {string} textureData.name - path name of the texture\n * {string} textureData.format - format of the texture\n * materialDefinition - PBR-like material definition from `materialDefinitions`\n */\n private getInformationFromMaterial(material: MeshMaterial) {\n const informationFromMaterial: {\n textureData: {name: string | null; format?: I3STextureFormat};\n materialDefinition?: I3SMaterialDefinition;\n } = {textureData: {name: null}};\n\n if (material) {\n const materialDefinition = this.tileset.materialDefinitions?.[material.definition];\n if (materialDefinition) {\n informationFromMaterial.materialDefinition = materialDefinition;\n const textureSetDefinitionIndex =\n materialDefinition?.pbrMetallicRoughness?.baseColorTexture?.textureSetDefinitionId;\n\n if (typeof textureSetDefinitionIndex === 'number') {\n informationFromMaterial.textureData =\n this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] ||\n informationFromMaterial.textureData;\n }\n }\n }\n return informationFromMaterial;\n }\n\n /**\n * Sets preferable and supported format for each textureDefinition of the tileset\n * @param tileset - I3S layer data\n * @returns\n */\n private initSelectedFormatsForTextureDefinitions(tileset: I3STilesetHeader): void {\n this.textureDefinitionsSelectedFormats = [];\n const possibleI3sFormats = this.getSupportedTextureFormats();\n const textureSetDefinitions = tileset.textureSetDefinitions || [];\n for (const textureSetDefinition of textureSetDefinitions) {\n const formats = (textureSetDefinition && textureSetDefinition.formats) || [];\n let selectedFormat: {name: string; format: I3STextureFormat} | null = null;\n for (const i3sFormat of possibleI3sFormats) {\n const format = formats.find((value) => value.format === i3sFormat);\n if (format) {\n selectedFormat = format;\n break;\n }\n }\n // For I3S 1.8 need to define basis target format to decode\n if (selectedFormat && selectedFormat.format === 'ktx2') {\n this.textureLoaderOptions.basis = {\n format: selectSupportedBasisFormat(),\n containerFormat: 'ktx2',\n module: 'encoder'\n };\n }\n\n this.textureDefinitionsSelectedFormats.push(selectedFormat);\n }\n }\n\n /**\n * Returns the array of supported texture format\n * @returns list of format strings\n */\n private getSupportedTextureFormats(): I3STextureFormat[] {\n const formats: I3STextureFormat[] = [];\n if (!this.options.i3s || this.options.i3s.useCompressedTextures) {\n // I3S 1.7 selection\n const supportedCompressedFormats = getSupportedGPUTextureFormats();\n // List of possible in i3s formats:\n // https://github.com/Esri/i3s-spec/blob/master/docs/1.7/textureSetDefinitionFormat.cmn.md\n if (supportedCompressedFormats.has('etc2')) {\n formats.push('ktx-etc2');\n }\n if (supportedCompressedFormats.has('dxt')) {\n formats.push('dds');\n }\n\n // I3S 1.8 selection\n // ktx2 wraps basis texture which at the edge case can be decoded as uncompressed image\n formats.push('ktx2');\n }\n\n formats.push('jpg');\n formats.push('png');\n return formats;\n }\n}\n"],"file":"i3s-nodepages-tiles.js"}