@loaders.gl/i3s 3.0.13 → 3.0.14
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.
- package/dist/dist.es5.min.js +1 -1
- package/dist/dist.es5.min.js.map +1 -1
- package/dist/dist.min.js +1 -1
- package/dist/dist.min.js.map +1 -1
- package/dist/es5/bundle.js +2 -2
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/i3s-attribute-loader.js +132 -53
- package/dist/es5/i3s-attribute-loader.js.map +1 -1
- package/dist/es5/i3s-content-loader.js +36 -10
- package/dist/es5/i3s-content-loader.js.map +1 -1
- package/dist/es5/i3s-loader.js +175 -51
- package/dist/es5/i3s-loader.js.map +1 -1
- package/dist/es5/i3s-node-page-loader.js +51 -8
- package/dist/es5/i3s-node-page-loader.js.map +1 -1
- package/dist/es5/index.js +4 -4
- package/dist/es5/lib/helpers/i3s-nodepages-tiles.js +313 -163
- package/dist/es5/lib/helpers/i3s-nodepages-tiles.js.map +1 -1
- package/dist/es5/lib/parsers/constants.js +9 -9
- package/dist/es5/lib/parsers/constants.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s-attribute.js +68 -26
- package/dist/es5/lib/parsers/parse-i3s-attribute.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js +405 -276
- package/dist/es5/lib/parsers/parse-i3s-tile-content.js.map +1 -1
- package/dist/es5/lib/parsers/parse-i3s.js +70 -31
- package/dist/es5/lib/parsers/parse-i3s.js.map +1 -1
- package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js +8 -4
- package/dist/es5/lib/utils/convert-i3s-obb-to-mbs.js.map +1 -1
- package/dist/es5/lib/utils/url-utils.js +14 -17
- package/dist/es5/lib/utils/url-utils.js.map +1 -1
- package/dist/esm/i3s-attribute-loader.js +1 -1
- package/dist/esm/i3s-content-loader.js +1 -1
- package/dist/esm/i3s-loader.js +1 -1
- package/dist/esm/i3s-node-page-loader.js +1 -1
- package/dist/i3s-content-worker.js +1 -1
- package/dist/i3s-content-worker.js.map +1 -1
- package/package.json +9 -9
|
@@ -7,6 +7,16 @@ 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 _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
+
|
|
16
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
17
|
+
|
|
18
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
19
|
+
|
|
10
20
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
21
|
|
|
12
22
|
var _core = require("@loaders.gl/core");
|
|
@@ -19,16 +29,26 @@ var _parseI3s = require("../parsers/parse-i3s");
|
|
|
19
29
|
|
|
20
30
|
var _urlUtils = require("../utils/url-utils");
|
|
21
31
|
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
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; } } }; }
|
|
33
|
+
|
|
34
|
+
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); }
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
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; }
|
|
39
|
+
|
|
40
|
+
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; }
|
|
41
|
+
|
|
42
|
+
var I3SNodePagesTiles = function () {
|
|
43
|
+
function I3SNodePagesTiles(tileset, options) {
|
|
44
|
+
(0, _classCallCheck2.default)(this, I3SNodePagesTiles);
|
|
24
45
|
(0, _defineProperty2.default)(this, "tileset", void 0);
|
|
25
46
|
(0, _defineProperty2.default)(this, "nodePages", void 0);
|
|
26
47
|
(0, _defineProperty2.default)(this, "nodesPerPage", void 0);
|
|
27
48
|
(0, _defineProperty2.default)(this, "options", void 0);
|
|
28
49
|
(0, _defineProperty2.default)(this, "lodSelectionMetricType", void 0);
|
|
29
50
|
(0, _defineProperty2.default)(this, "textureDefinitionsSelectedFormats", void 0);
|
|
30
|
-
this.tileset = {
|
|
31
|
-
};
|
|
51
|
+
this.tileset = _objectSpread({}, tileset);
|
|
32
52
|
this.nodesPerPage = tileset.nodePages.nodesPerPage;
|
|
33
53
|
this.lodSelectionMetricType = tileset.nodePages.lodSelectionMetricType;
|
|
34
54
|
this.options = options;
|
|
@@ -38,192 +58,322 @@ class I3SNodePagesTiles {
|
|
|
38
58
|
this._initSelectedFormatsForTextureDefinitions(tileset);
|
|
39
59
|
}
|
|
40
60
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
materialDefinition = nodeMaterialDefinition;
|
|
93
|
-
textureFormat = textureData.format || textureFormat;
|
|
94
|
-
|
|
95
|
-
if (textureData.name) {
|
|
96
|
-
textureUrl = "".concat(this.tileset.url, "/nodes/").concat(node.mesh.material.resource, "/textures/").concat(textureData.name);
|
|
61
|
+
(0, _createClass2.default)(I3SNodePagesTiles, [{
|
|
62
|
+
key: "getNodeById",
|
|
63
|
+
value: function () {
|
|
64
|
+
var _getNodeById = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(id) {
|
|
65
|
+
var pageIndex, _this$options$i3s, nodePageUrl, nodeIndex;
|
|
66
|
+
|
|
67
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
68
|
+
while (1) {
|
|
69
|
+
switch (_context.prev = _context.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
pageIndex = Math.floor(id / this.nodesPerPage);
|
|
72
|
+
|
|
73
|
+
if (this.nodePages[pageIndex]) {
|
|
74
|
+
_context.next = 7;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
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);
|
|
79
|
+
this.nodePages[pageIndex] = (0, _core.load)(nodePageUrl, _i3sNodePageLoader.I3SNodePageLoader, this.options);
|
|
80
|
+
_context.next = 6;
|
|
81
|
+
return this.nodePages[pageIndex];
|
|
82
|
+
|
|
83
|
+
case 6:
|
|
84
|
+
this.nodePages[pageIndex] = _context.sent;
|
|
85
|
+
|
|
86
|
+
case 7:
|
|
87
|
+
if (!(this.nodePages[pageIndex] instanceof Promise)) {
|
|
88
|
+
_context.next = 11;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
_context.next = 10;
|
|
93
|
+
return this.nodePages[pageIndex];
|
|
94
|
+
|
|
95
|
+
case 10:
|
|
96
|
+
this.nodePages[pageIndex] = _context.sent;
|
|
97
|
+
|
|
98
|
+
case 11:
|
|
99
|
+
nodeIndex = id % this.nodesPerPage;
|
|
100
|
+
return _context.abrupt("return", this.nodePages[pageIndex].nodes[nodeIndex]);
|
|
101
|
+
|
|
102
|
+
case 13:
|
|
103
|
+
case "end":
|
|
104
|
+
return _context.stop();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, _callee, this);
|
|
108
|
+
}));
|
|
109
|
+
|
|
110
|
+
function getNodeById(_x) {
|
|
111
|
+
return _getNodeById.apply(this, arguments);
|
|
97
112
|
}
|
|
98
113
|
|
|
99
|
-
|
|
100
|
-
|
|
114
|
+
return getNodeById;
|
|
115
|
+
}()
|
|
116
|
+
}, {
|
|
117
|
+
key: "formTileFromNodePages",
|
|
118
|
+
value: function () {
|
|
119
|
+
var _formTileFromNodePages = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(id) {
|
|
120
|
+
var node, children, _iterator, _step, child, childNode, contentUrl, textureUrl, materialDefinition, textureFormat, attributeUrls, isDracoGeometry, _ref, url, isDracoGeometryResult, _this$_getInformation, _this$_getInformation2, textureData, nodeMaterialDefinition, lodSelection;
|
|
121
|
+
|
|
122
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
123
|
+
while (1) {
|
|
124
|
+
switch (_context2.prev = _context2.next) {
|
|
125
|
+
case 0:
|
|
126
|
+
_context2.next = 2;
|
|
127
|
+
return this.getNodeById(id);
|
|
128
|
+
|
|
129
|
+
case 2:
|
|
130
|
+
node = _context2.sent;
|
|
131
|
+
children = [];
|
|
132
|
+
_iterator = _createForOfIteratorHelper(node.children || []);
|
|
133
|
+
_context2.prev = 5;
|
|
134
|
+
|
|
135
|
+
_iterator.s();
|
|
136
|
+
|
|
137
|
+
case 7:
|
|
138
|
+
if ((_step = _iterator.n()).done) {
|
|
139
|
+
_context2.next = 15;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
child = _step.value;
|
|
144
|
+
_context2.next = 11;
|
|
145
|
+
return this.getNodeById(child);
|
|
146
|
+
|
|
147
|
+
case 11:
|
|
148
|
+
childNode = _context2.sent;
|
|
149
|
+
children.push({
|
|
150
|
+
id: child,
|
|
151
|
+
obb: childNode.obb
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
case 13:
|
|
155
|
+
_context2.next = 7;
|
|
156
|
+
break;
|
|
157
|
+
|
|
158
|
+
case 15:
|
|
159
|
+
_context2.next = 20;
|
|
160
|
+
break;
|
|
161
|
+
|
|
162
|
+
case 17:
|
|
163
|
+
_context2.prev = 17;
|
|
164
|
+
_context2.t0 = _context2["catch"](5);
|
|
165
|
+
|
|
166
|
+
_iterator.e(_context2.t0);
|
|
167
|
+
|
|
168
|
+
case 20:
|
|
169
|
+
_context2.prev = 20;
|
|
170
|
+
|
|
171
|
+
_iterator.f();
|
|
172
|
+
|
|
173
|
+
return _context2.finish(20);
|
|
174
|
+
|
|
175
|
+
case 23:
|
|
176
|
+
contentUrl = null;
|
|
177
|
+
textureUrl = null;
|
|
178
|
+
materialDefinition = null;
|
|
179
|
+
textureFormat = 'jpeg';
|
|
180
|
+
attributeUrls = [];
|
|
181
|
+
isDracoGeometry = false;
|
|
182
|
+
|
|
183
|
+
if (node && node.mesh) {
|
|
184
|
+
_ref = node.mesh.geometry && this._getContentUrl(node.mesh.geometry) || {
|
|
185
|
+
url: null,
|
|
186
|
+
isDracoGeometry: null
|
|
187
|
+
}, url = _ref.url, isDracoGeometryResult = _ref.isDracoGeometry;
|
|
188
|
+
contentUrl = url;
|
|
189
|
+
isDracoGeometry = isDracoGeometryResult;
|
|
190
|
+
_this$_getInformation = this._getInformationFromMaterial(node.mesh.material), _this$_getInformation2 = (0, _slicedToArray2.default)(_this$_getInformation, 2), textureData = _this$_getInformation2[0], nodeMaterialDefinition = _this$_getInformation2[1];
|
|
191
|
+
materialDefinition = nodeMaterialDefinition;
|
|
192
|
+
textureFormat = textureData.format || textureFormat;
|
|
193
|
+
|
|
194
|
+
if (textureData.name) {
|
|
195
|
+
textureUrl = "".concat(this.tileset.url, "/nodes/").concat(node.mesh.material.resource, "/textures/").concat(textureData.name);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (this.tileset.attributeStorageInfo) {
|
|
199
|
+
attributeUrls = (0, _urlUtils.generateTilesetAttributeUrls)(this.tileset, node.mesh.attribute.resource);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
lodSelection = this._getLodSelection(node);
|
|
204
|
+
return _context2.abrupt("return", (0, _parseI3s.normalizeTileNonUrlData)({
|
|
205
|
+
id: id,
|
|
206
|
+
lodSelection: lodSelection,
|
|
207
|
+
obb: node.obb,
|
|
208
|
+
contentUrl: contentUrl,
|
|
209
|
+
textureUrl: textureUrl,
|
|
210
|
+
attributeUrls: attributeUrls,
|
|
211
|
+
materialDefinition: materialDefinition,
|
|
212
|
+
textureFormat: textureFormat,
|
|
213
|
+
children: children,
|
|
214
|
+
isDracoGeometry: isDracoGeometry
|
|
215
|
+
}));
|
|
216
|
+
|
|
217
|
+
case 32:
|
|
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);
|
|
101
227
|
}
|
|
102
|
-
}
|
|
103
228
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
_getContentUrl(meshGeometryData) {
|
|
121
|
-
let result = {};
|
|
122
|
-
const geometryDefinition = this.tileset.geometryDefinitions[meshGeometryData.definition];
|
|
123
|
-
let geometryIndex = -1;
|
|
229
|
+
return formTileFromNodePages;
|
|
230
|
+
}()
|
|
231
|
+
}, {
|
|
232
|
+
key: "_getContentUrl",
|
|
233
|
+
value: function _getContentUrl(meshGeometryData) {
|
|
234
|
+
var result = {};
|
|
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
|
+
}
|
|
124
243
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
244
|
+
if (geometryIndex === -1) {
|
|
245
|
+
geometryIndex = geometryDefinition.geometryBuffers.findIndex(function (buffer) {
|
|
246
|
+
return !buffer.compressedAttributes;
|
|
247
|
+
});
|
|
248
|
+
}
|
|
128
249
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
+
}
|
|
132
257
|
|
|
133
|
-
|
|
134
|
-
const isDracoGeometry = Boolean(geometryDefinition.geometryBuffers[geometryIndex].compressedAttributes);
|
|
135
|
-
result = {
|
|
136
|
-
url: "".concat(this.tileset.url, "/nodes/").concat(meshGeometryData.resource, "/geometries/").concat(geometryIndex),
|
|
137
|
-
isDracoGeometry
|
|
138
|
-
};
|
|
258
|
+
return result;
|
|
139
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
|
+
}
|
|
140
271
|
|
|
141
|
-
return result;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
_getLodSelection(node) {
|
|
145
|
-
const lodSelection = [];
|
|
146
|
-
|
|
147
|
-
if (this.lodSelectionMetricType === 'maxScreenThresholdSQ') {
|
|
148
272
|
lodSelection.push({
|
|
149
|
-
metricType:
|
|
150
|
-
maxError:
|
|
273
|
+
metricType: this.lodSelectionMetricType,
|
|
274
|
+
maxError: node.lodThreshold
|
|
151
275
|
});
|
|
276
|
+
return lodSelection;
|
|
152
277
|
}
|
|
278
|
+
}, {
|
|
279
|
+
key: "_getInformationFromMaterial",
|
|
280
|
+
value: function _getInformationFromMaterial(material) {
|
|
281
|
+
var textureDataDefault = {
|
|
282
|
+
name: null,
|
|
283
|
+
format: null
|
|
284
|
+
};
|
|
153
285
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
});
|
|
158
|
-
return lodSelection;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
_getInformationFromMaterial(material) {
|
|
162
|
-
const textureDataDefault = {
|
|
163
|
-
name: null,
|
|
164
|
-
format: null
|
|
165
|
-
};
|
|
286
|
+
if (material) {
|
|
287
|
+
var materialDefinition = this.tileset.materialDefinitions[material.definition];
|
|
288
|
+
var textureSetDefinitionIndex = materialDefinition && materialDefinition.pbrMetallicRoughness && materialDefinition.pbrMetallicRoughness.baseColorTexture && materialDefinition.pbrMetallicRoughness.baseColorTexture.textureSetDefinitionId;
|
|
166
289
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
290
|
+
if (textureSetDefinitionIndex || textureSetDefinitionIndex === 0) {
|
|
291
|
+
var textureData = this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] || textureDataDefault;
|
|
292
|
+
return [textureData, materialDefinition];
|
|
293
|
+
}
|
|
170
294
|
|
|
171
|
-
|
|
172
|
-
const textureData = this.textureDefinitionsSelectedFormats[textureSetDefinitionIndex] || textureDataDefault;
|
|
173
|
-
return [textureData, materialDefinition];
|
|
295
|
+
return [textureDataDefault, materialDefinition];
|
|
174
296
|
}
|
|
175
297
|
|
|
176
|
-
return [textureDataDefault,
|
|
298
|
+
return [textureDataDefault, null];
|
|
177
299
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
300
|
+
}, {
|
|
301
|
+
key: "_initSelectedFormatsForTextureDefinitions",
|
|
302
|
+
value: function _initSelectedFormatsForTextureDefinitions(tileset) {
|
|
303
|
+
this.textureDefinitionsSelectedFormats = [];
|
|
304
|
+
|
|
305
|
+
var possibleI3sFormats = this._getSupportedTextureFormats();
|
|
306
|
+
|
|
307
|
+
var textureSetDefinitions = tileset.textureSetDefinitions || [];
|
|
308
|
+
|
|
309
|
+
var _iterator2 = _createForOfIteratorHelper(textureSetDefinitions),
|
|
310
|
+
_step2;
|
|
311
|
+
|
|
312
|
+
try {
|
|
313
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
314
|
+
var textureSetDefinition = _step2.value;
|
|
315
|
+
var formats = textureSetDefinition && textureSetDefinition.formats || [];
|
|
316
|
+
var selectedFormat = null;
|
|
317
|
+
|
|
318
|
+
var _iterator3 = _createForOfIteratorHelper(possibleI3sFormats),
|
|
319
|
+
_step3;
|
|
320
|
+
|
|
321
|
+
try {
|
|
322
|
+
var _loop = function _loop() {
|
|
323
|
+
var i3sFormat = _step3.value;
|
|
324
|
+
var format = formats.find(function (value) {
|
|
325
|
+
return value.format === i3sFormat;
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
if (format) {
|
|
329
|
+
selectedFormat = format;
|
|
330
|
+
return "break";
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
335
|
+
var _ret = _loop();
|
|
336
|
+
|
|
337
|
+
if (_ret === "break") break;
|
|
338
|
+
}
|
|
339
|
+
} catch (err) {
|
|
340
|
+
_iterator3.e(err);
|
|
341
|
+
} finally {
|
|
342
|
+
_iterator3.f();
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
this.textureDefinitionsSelectedFormats.push(selectedFormat);
|
|
199
346
|
}
|
|
347
|
+
} catch (err) {
|
|
348
|
+
_iterator2.e(err);
|
|
349
|
+
} finally {
|
|
350
|
+
_iterator2.f();
|
|
200
351
|
}
|
|
201
|
-
|
|
202
|
-
this.textureDefinitionsSelectedFormats.push(selectedFormat);
|
|
203
352
|
}
|
|
204
|
-
}
|
|
353
|
+
}, {
|
|
354
|
+
key: "_getSupportedTextureFormats",
|
|
355
|
+
value: function _getSupportedTextureFormats() {
|
|
356
|
+
var formats = [];
|
|
205
357
|
|
|
206
|
-
|
|
207
|
-
|
|
358
|
+
if (!this.options.i3s || this.options.i3s.useCompressedTextures) {
|
|
359
|
+
var supportedCompressedFormats = (0, _textures.getSupportedGPUTextureFormats)();
|
|
208
360
|
|
|
209
|
-
|
|
210
|
-
|
|
361
|
+
if (supportedCompressedFormats.has('etc2')) {
|
|
362
|
+
formats.push('ktx-etc2');
|
|
363
|
+
}
|
|
211
364
|
|
|
212
|
-
|
|
213
|
-
|
|
365
|
+
if (supportedCompressedFormats.has('dxt')) {
|
|
366
|
+
formats.push('dds');
|
|
367
|
+
}
|
|
214
368
|
}
|
|
215
369
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
370
|
+
formats.push('jpg');
|
|
371
|
+
formats.push('png');
|
|
372
|
+
return formats;
|
|
219
373
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return formats;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
}
|
|
374
|
+
}]);
|
|
375
|
+
return I3SNodePagesTiles;
|
|
376
|
+
}();
|
|
227
377
|
|
|
228
378
|
exports.default = I3SNodePagesTiles;
|
|
229
379
|
//# 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","textureDefinitionsSelectedFormats","_initSelectedFormatsForTextureDefinitions","getNodeById","id","pageIndex","Math","floor","nodePageUrl","url","i3s","token","I3SNodePageLoader","Promise","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","meshGeometryData","result","geometryDefinition","geometryDefinitions","definition","geometryIndex","useDracoGeometry","geometryBuffers","findIndex","buffer","compressedAttributes","encoding","Boolean","metricType","maxError","sqrt","lodThreshold","PI","textureDataDefault","materialDefinitions","textureSetDefinitionIndex","pbrMetallicRoughness","baseColorTexture","textureSetDefinitionId","possibleI3sFormats","_getSupportedTextureFormats","textureSetDefinitions","textureSetDefinition","formats","selectedFormat","i3sFormat","find","value","useCompressedTextures","supportedCompressedFormats","has"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;AAKe,MAAMA,iBAAN,CAAwB;AAcrCC,EAAAA,WAAW,CAACC,OAAD,EAAmBC,OAAnB,EAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAC7C,SAAKD,OAAL,GAAe,EAAC,GAAG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AC1CP,QAAAA,OAAO,CAACnD,IAAR,CAAa,UAAb;AACD;;AACD,UAAIyD,0BAA0B,CAACC,GAA3B,CAA+B,KAA/B,CAAJ,EAA2C;AACzCP,QAAAA,OAAO,CAACnD,IAAR,CAAa,KAAb;AACD;AACF;;AAEDmD,IAAAA,OAAO,CAACnD,IAAR,CAAa,KAAb;AACAmD,IAAAA,OAAO,CAACnD,IAAR,CAAa,KAAb;AACA,WAAOmD,OAAP;AACD;;AA1OoC","sourcesContent":["import {load} from '@loaders.gl/core';\nimport {getSupportedGPUTextureFormats} 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 nodesPerPage: number;\n options: {[key: string]: any};\n lodSelectionMetricType: any;\n textureDefinitionsSelectedFormats: 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 this.nodePages = [];\n this.textureDefinitionsSelectedFormats = [];\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]) {\n const nodePageUrl = getUrlWithToken(\n `${this.tileset.url}/nodepages/${pageIndex}`,\n this.options.i3s?.token\n );\n this.nodePages[pageIndex] = load(nodePageUrl, I3SNodePageLoader, this.options);\n this.nodePages[pageIndex] = await this.nodePages[pageIndex];\n }\n if (this.nodePages[pageIndex] instanceof Promise) {\n this.nodePages[pageIndex] = await this.nodePages[pageIndex];\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 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 _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 _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 _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 _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 = 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 this.textureDefinitionsSelectedFormats.push(selectedFormat);\n }\n }\n\n /**\n * Returns the array of supported texture format\n * @returns list of format strings\n */\n _getSupportedTextureFormats(): string[] {\n const formats: string[] = [];\n if (!this.options.i3s || this.options.i3s.useCompressedTextures) {\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\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","textureDefinitionsSelectedFormats","_initSelectedFormatsForTextureDefinitions","id","pageIndex","Math","floor","nodePageUrl","url","i3s","token","I3SNodePageLoader","Promise","nodeIndex","nodes","getNodeById","node","children","child","childNode","push","obb","contentUrl","textureUrl","materialDefinition","textureFormat","attributeUrls","isDracoGeometry","mesh","geometry","_getContentUrl","isDracoGeometryResult","_getInformationFromMaterial","material","textureData","nodeMaterialDefinition","format","name","resource","attributeStorageInfo","attribute","lodSelection","_getLodSelection","meshGeometryData","result","geometryDefinition","geometryDefinitions","definition","geometryIndex","useDracoGeometry","geometryBuffers","findIndex","buffer","compressedAttributes","encoding","Boolean","metricType","maxError","sqrt","lodThreshold","PI","textureDataDefault","materialDefinitions","textureSetDefinitionIndex","pbrMetallicRoughness","baseColorTexture","textureSetDefinitionId","possibleI3sFormats","_getSupportedTextureFormats","textureSetDefinitions","textureSetDefinition","formats","selectedFormat","i3sFormat","find","value","useCompressedTextures","supportedCompressedFormats","has"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AACA;;AACA;;;;;;;;;;;;IAKqBA,iB;AAcnB,6BAAYC,OAAZ,EAA8BC,OAA9B,EAA+C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAC7C,SAAKD,OAAL,qBAAmBA,OAAnB;AACA,SAAKE,YAAL,GAAoBF,OAAO,CAACG,SAAR,CAAkBD,YAAtC;AACA,SAAKE,sBAAL,GAA8BJ,OAAO,CAACG,SAAR,CAAkBC,sBAAhD;AACA,SAAKH,OAAL,GAAeA,OAAf;AACA,SAAKE,SAAL,GAAiB,EAAjB;AACA,SAAKE,iCAAL,GAAyC,EAAzC;;AAEA,SAAKC,yCAAL,CAA+CN,OAA/C;AACD;;;;;mFAMD,iBAAkBO,EAAlB;AAAA;;AAAA;AAAA;AAAA;AAAA;AACQC,gBAAAA,SADR,GACoBC,IAAI,CAACC,KAAL,CAAWH,EAAE,GAAG,KAAKL,YAArB,CADpB;;AAAA,oBAEO,KAAKC,SAAL,CAAeK,SAAf,CAFP;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;AAfgD;AAAA;AAAA;AAAA;AAAA;AAgBlD;;;WAMD,uCAAwC;AACtC,UAAMD,OAAiB,GAAG,EAA1B;;AACA,UAAI,CAAC,KAAK1E,OAAL,CAAaY,GAAd,IAAqB,KAAKZ,OAAL,CAAaY,GAAb,CAAiBmE,qBAA1C,EAAiE;AAC/D,YAAMC,0BAA0B,GAAG,8CAAnC;;AAGA,YAAIA,0BAA0B,CAACC,GAA3B,CAA+B,MAA/B,CAAJ,EAA4C;AAC1CP,UAAAA,OAAO,CAACnD,IAAR,CAAa,UAAb;AACD;;AACD,YAAIyD,0BAA0B,CAACC,GAA3B,CAA+B,KAA/B,CAAJ,EAA2C;AACzCP,UAAAA,OAAO,CAACnD,IAAR,CAAa,KAAb;AACD;AACF;;AAEDmD,MAAAA,OAAO,CAACnD,IAAR,CAAa,KAAb;AACAmD,MAAAA,OAAO,CAACnD,IAAR,CAAa,KAAb;AACA,aAAOmD,OAAP;AACD","sourcesContent":["import {load} from '@loaders.gl/core';\nimport {getSupportedGPUTextureFormats} 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 nodesPerPage: number;\n options: {[key: string]: any};\n lodSelectionMetricType: any;\n textureDefinitionsSelectedFormats: 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 this.nodePages = [];\n this.textureDefinitionsSelectedFormats = [];\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]) {\n const nodePageUrl = getUrlWithToken(\n `${this.tileset.url}/nodepages/${pageIndex}`,\n this.options.i3s?.token\n );\n this.nodePages[pageIndex] = load(nodePageUrl, I3SNodePageLoader, this.options);\n this.nodePages[pageIndex] = await this.nodePages[pageIndex];\n }\n if (this.nodePages[pageIndex] instanceof Promise) {\n this.nodePages[pageIndex] = await this.nodePages[pageIndex];\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 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 _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 _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 _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 _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 = 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 this.textureDefinitionsSelectedFormats.push(selectedFormat);\n }\n }\n\n /**\n * Returns the array of supported texture format\n * @returns list of format strings\n */\n _getSupportedTextureFormats(): string[] {\n const formats: string[] = [];\n if (!this.options.i3s || this.options.i3s.useCompressedTextures) {\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\n formats.push('jpg');\n formats.push('png');\n return formats;\n }\n}\n"],"file":"i3s-nodepages-tiles.js"}
|