@loaders.gl/tile-converter 3.4.13 → 3.4.15

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 (100) hide show
  1. package/dist/3d-tiles-attributes-worker.js +1 -1
  2. package/dist/converter.min.js +78 -77
  3. package/dist/dist.min.js +2081 -1557
  4. package/dist/es5/3d-tiles-attributes-worker.js +3 -3
  5. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
  6. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js +203 -417
  7. package/dist/es5/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  8. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js +197 -266
  9. package/dist/es5/3d-tiles-converter/helpers/b3dm-converter.js.map +1 -1
  10. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js +4 -6
  11. package/dist/es5/3d-tiles-converter/helpers/i3s-obb-to-3d-tiles-obb.js.map +1 -1
  12. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js +12 -12
  13. package/dist/es5/3d-tiles-converter/helpers/texture-atlas.js.map +1 -1
  14. package/dist/es5/3d-tiles-converter/json-templates/tileset.js +35 -51
  15. package/dist/es5/3d-tiles-converter/json-templates/tileset.js.map +1 -1
  16. package/dist/es5/bundle.js +1 -1
  17. package/dist/es5/bundle.js.map +1 -1
  18. package/dist/es5/constants.js +1 -1
  19. package/dist/es5/constants.js.map +1 -1
  20. package/dist/es5/converter-cli.js +78 -133
  21. package/dist/es5/converter-cli.js.map +1 -1
  22. package/dist/es5/deps-installer/deps-installer.js +38 -110
  23. package/dist/es5/deps-installer/deps-installer.js.map +1 -1
  24. package/dist/es5/i3s-attributes-worker.js +3 -3
  25. package/dist/es5/i3s-attributes-worker.js.map +1 -1
  26. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +31 -36
  27. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  28. package/dist/es5/i3s-converter/helpers/coordinate-converter.js +23 -23
  29. package/dist/es5/i3s-converter/helpers/coordinate-converter.js.map +1 -1
  30. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js +9 -27
  31. package/dist/es5/i3s-converter/helpers/create-scene-server-path.js.map +1 -1
  32. package/dist/es5/i3s-converter/helpers/feature-attributes.js +27 -42
  33. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -1
  34. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +97 -114
  35. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  36. package/dist/es5/i3s-converter/helpers/geometry-converter.js +524 -799
  37. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  38. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +24 -25
  39. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  40. package/dist/es5/i3s-converter/helpers/node-debug.js +27 -25
  41. package/dist/es5/i3s-converter/helpers/node-debug.js.map +1 -1
  42. package/dist/es5/i3s-converter/helpers/node-index-document.js +165 -461
  43. package/dist/es5/i3s-converter/helpers/node-index-document.js.map +1 -1
  44. package/dist/es5/i3s-converter/helpers/node-pages.js +169 -474
  45. package/dist/es5/i3s-converter/helpers/node-pages.js.map +1 -1
  46. package/dist/es5/i3s-converter/i3s-converter.js +663 -1401
  47. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  48. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js +82 -92
  49. package/dist/es5/i3s-converter/json-templates/geometry-definitions.js.map +1 -1
  50. package/dist/es5/i3s-converter/json-templates/layers.js +130 -152
  51. package/dist/es5/i3s-converter/json-templates/layers.js.map +1 -1
  52. package/dist/es5/i3s-converter/json-templates/metadata.js +21 -23
  53. package/dist/es5/i3s-converter/json-templates/metadata.js.map +1 -1
  54. package/dist/es5/i3s-converter/json-templates/node.js +78 -89
  55. package/dist/es5/i3s-converter/json-templates/node.js.map +1 -1
  56. package/dist/es5/i3s-converter/json-templates/scene-server.js +27 -31
  57. package/dist/es5/i3s-converter/json-templates/scene-server.js.map +1 -1
  58. package/dist/es5/i3s-converter/json-templates/shared-resources.js +110 -152
  59. package/dist/es5/i3s-converter/json-templates/shared-resources.js.map +1 -1
  60. package/dist/es5/i3s-converter/json-templates/store.js +2 -4
  61. package/dist/es5/i3s-converter/json-templates/store.js.map +1 -1
  62. package/dist/es5/i3s-server/app.js +6 -6
  63. package/dist/es5/i3s-server/app.js.map +1 -1
  64. package/dist/es5/i3s-server/controllers/index-controller.js +20 -49
  65. package/dist/es5/i3s-server/controllers/index-controller.js.map +1 -1
  66. package/dist/es5/i3s-server/routes/index.js +14 -33
  67. package/dist/es5/i3s-server/routes/index.js.map +1 -1
  68. package/dist/es5/index.js +2 -2
  69. package/dist/es5/lib/utils/compress-util.js +127 -295
  70. package/dist/es5/lib/utils/compress-util.js.map +1 -1
  71. package/dist/es5/lib/utils/file-utils.js +65 -174
  72. package/dist/es5/lib/utils/file-utils.js.map +1 -1
  73. package/dist/es5/lib/utils/lod-conversion-utils.js +9 -9
  74. package/dist/es5/lib/utils/lod-conversion-utils.js.map +1 -1
  75. package/dist/es5/lib/utils/queue.js +13 -38
  76. package/dist/es5/lib/utils/queue.js.map +1 -1
  77. package/dist/es5/lib/utils/statistic-utills.js +39 -117
  78. package/dist/es5/lib/utils/statistic-utills.js.map +1 -1
  79. package/dist/es5/lib/utils/write-queue.js +74 -195
  80. package/dist/es5/lib/utils/write-queue.js.map +1 -1
  81. package/dist/es5/pgm-loader.js +3 -22
  82. package/dist/es5/pgm-loader.js.map +1 -1
  83. package/dist/es5/workers/3d-tiles-attributes-worker.js +5 -22
  84. package/dist/es5/workers/3d-tiles-attributes-worker.js.map +1 -1
  85. package/dist/es5/workers/i3s-attributes-worker.js +4 -25
  86. package/dist/es5/workers/i3s-attributes-worker.js.map +1 -1
  87. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  88. package/dist/esm/deps-installer/deps-installer.js +1 -1
  89. package/dist/esm/i3s-attributes-worker.js +1 -1
  90. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -1
  91. package/dist/esm/i3s-converter/helpers/geometry-converter.js +1 -1
  92. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  93. package/dist/esm/pgm-loader.js +1 -1
  94. package/dist/i3s-attributes-worker.js +2 -2
  95. package/dist/i3s-attributes-worker.js.map +3 -3
  96. package/dist/i3s-converter/helpers/geometry-converter.d.ts +1 -1
  97. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  98. package/package.json +15 -15
  99. package/src/i3s-converter/helpers/batch-ids-extensions.ts +1 -1
  100. package/src/i3s-converter/helpers/geometry-converter.ts +14 -14
@@ -5,11 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
9
  var _path = require("path");
15
10
  var _process = _interopRequireDefault(require("process"));
@@ -27,15 +22,9 @@ var _coordinateConverter = require("../i3s-converter/helpers/coordinate-converte
27
22
  var _dTilesAttributesWorker = require("../3d-tiles-attributes-worker");
28
23
  var _workerUtils = require("@loaders.gl/worker-utils");
29
24
  var _constants = require("../constants");
30
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
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
- 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); }
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
- var I3S = 'I3S';
36
- var Tiles3DConverter = function () {
37
- function Tiles3DConverter() {
38
- (0, _classCallCheck2.default)(this, Tiles3DConverter);
25
+ const I3S = 'I3S';
26
+ class Tiles3DConverter {
27
+ constructor() {
39
28
  (0, _defineProperty2.default)(this, "options", void 0);
40
29
  (0, _defineProperty2.default)(this, "tilesetPath", void 0);
41
30
  (0, _defineProperty2.default)(this, "vertexCounter", void 0);
@@ -53,418 +42,215 @@ var Tiles3DConverter = function () {
53
42
  this.attributeStorageInfo = null;
54
43
  this.workerSource = {};
55
44
  }
56
- (0, _createClass2.default)(Tiles3DConverter, [{
57
- key: "convert",
58
- value: function () {
59
- var _convert = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(options) {
60
- var inputUrl, outputPath, tilesetName, maxDepth, egmFilePath, sourceTilesetJson, rootNode, rootTile, tileset, workerFarm;
61
- return _regenerator.default.wrap(function _callee$(_context) {
62
- while (1) switch (_context.prev = _context.next) {
63
- case 0:
64
- if (!_core.isBrowser) {
65
- _context.next = 3;
66
- break;
67
- }
68
- console.log(_constants.BROWSER_ERROR_MESSAGE);
69
- return _context.abrupt("return", _constants.BROWSER_ERROR_MESSAGE);
70
- case 3:
71
- inputUrl = options.inputUrl, outputPath = options.outputPath, tilesetName = options.tilesetName, maxDepth = options.maxDepth, egmFilePath = options.egmFilePath;
72
- this.conversionStartTime = _process.default.hrtime();
73
- this.options = {
74
- maxDepth: maxDepth
75
- };
76
- console.log('Loading egm file...');
77
- _context.next = 9;
78
- return (0, _core.load)(egmFilePath, _pgmLoader.PGMLoader);
79
- case 9:
80
- this.geoidHeightModel = _context.sent;
81
- console.log('Loading egm file completed!');
82
- _context.next = 13;
83
- return this.loadWorkers();
84
- case 13:
85
- _context.next = 15;
86
- return (0, _core.load)(inputUrl, _i3s.I3SLoader, {});
87
- case 15:
88
- sourceTilesetJson = _context.sent;
89
- this.sourceTileset = new _tiles.Tileset3D(sourceTilesetJson, {
90
- loadOptions: {
91
- _nodeWorkers: true,
92
- reuseWorkers: true,
93
- 'i3s-content-nodejs': {
94
- workerUrl: './modules/i3s/dist/i3s-content-nodejs-worker.js'
95
- },
96
- i3s: {
97
- coordinateSystem: _i3s.COORDINATE_SYSTEM.LNGLAT_OFFSETS,
98
- decodeTextures: false
99
- }
100
- }
101
- });
102
- _context.next = 19;
103
- return this.sourceTileset.tilesetInitializationPromise;
104
- case 19:
105
- rootNode = this.sourceTileset.root;
106
- if (!rootNode.header.obb) {
107
- rootNode.header.obb = (0, _coordinateConverter.createObbFromMbs)(rootNode.header.mbs);
108
- }
109
- this.tilesetPath = (0, _path.join)("".concat(outputPath), "".concat(tilesetName));
110
- this.attributeStorageInfo = sourceTilesetJson.attributeStorageInfo;
111
- _context.prev = 23;
112
- _context.next = 26;
113
- return (0, _fileUtils.removeDir)(this.tilesetPath);
114
- case 26:
115
- _context.next = 30;
116
- break;
117
- case 28:
118
- _context.prev = 28;
119
- _context.t0 = _context["catch"](23);
120
- case 30:
121
- rootTile = {
122
- boundingVolume: {
123
- box: (0, _i3sObbTo3dTilesObb.i3sObbTo3dTilesObb)(rootNode.header.obb, this.geoidHeightModel)
124
- },
125
- geometricError: (0, _lodConversionUtils.convertScreenThresholdToGeometricError)(rootNode),
126
- children: []
127
- };
128
- _context.next = 33;
129
- return this._addChildren(rootNode, rootTile, 1);
130
- case 33:
131
- tileset = (0, _jsonMapTransform.default)({
132
- root: rootTile
133
- }, (0, _tileset.TILESET)());
134
- _context.next = 36;
135
- return (0, _fileUtils.writeFile)(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');
136
- case 36:
137
- this._finishConversion({
138
- slpk: false,
139
- outputPath: outputPath,
140
- tilesetName: tilesetName
141
- });
142
- workerFarm = _workerUtils.WorkerFarm.getWorkerFarm({});
143
- workerFarm.destroy();
144
- case 39:
145
- case "end":
146
- return _context.stop();
147
- }
148
- }, _callee, this, [[23, 28]]);
149
- }));
150
- function convert(_x) {
151
- return _convert.apply(this, arguments);
152
- }
153
- return convert;
154
- }()
155
- }, {
156
- key: "convertChildNode",
157
- value: function () {
158
- var _convertChildNode = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(parentSourceNode, parentNode, level, childNodeInfo) {
159
- var sourceChild, _sourceChild$header, featureAttributes, boundingVolume, child, i3sAttributesData, b3dm;
160
- return _regenerator.default.wrap(function _callee2$(_context2) {
161
- while (1) switch (_context2.prev = _context2.next) {
162
- case 0:
163
- _context2.next = 2;
164
- return this._loadChildNode(parentSourceNode, childNodeInfo);
165
- case 2:
166
- sourceChild = _context2.sent;
167
- parentSourceNode.children.push(sourceChild);
168
- if (!sourceChild.contentUrl) {
169
- _context2.next = 29;
170
- break;
171
- }
172
- _context2.next = 7;
173
- return this.sourceTileset._loadTile(sourceChild);
174
- case 7:
175
- this.vertexCounter += sourceChild.content.vertexCount;
176
- featureAttributes = null;
177
- if (!this.attributeStorageInfo) {
178
- _context2.next = 13;
179
- break;
180
- }
181
- _context2.next = 12;
182
- return this._loadChildAttributes(sourceChild, this.attributeStorageInfo);
183
- case 12:
184
- featureAttributes = _context2.sent;
185
- case 13:
186
- if (!sourceChild.header.obb) {
187
- sourceChild.header.obb = (0, _coordinateConverter.createObbFromMbs)(sourceChild.header.mbs);
188
- }
189
- boundingVolume = {
190
- box: (0, _i3sObbTo3dTilesObb.i3sObbTo3dTilesObb)(sourceChild.header.obb, this.geoidHeightModel)
191
- };
192
- child = {
193
- boundingVolume: boundingVolume,
194
- geometricError: (0, _lodConversionUtils.convertScreenThresholdToGeometricError)(sourceChild),
195
- children: []
196
- };
197
- i3sAttributesData = {
198
- tileContent: sourceChild.content,
199
- textureFormat: sourceChild === null || sourceChild === void 0 ? void 0 : (_sourceChild$header = sourceChild.header) === null || _sourceChild$header === void 0 ? void 0 : _sourceChild$header.textureFormat
200
- };
201
- _context2.next = 19;
202
- return (0, _dTilesAttributesWorker.transform3DTilesAttributesOnWorker)(i3sAttributesData, {
203
- source: this.workerSource.tile3dWorkerSource,
204
- featureAttributes: featureAttributes
205
- });
206
- case 19:
207
- b3dm = _context2.sent;
208
- child.content = {
209
- uri: "".concat(sourceChild.id, ".b3dm"),
210
- boundingVolume: boundingVolume
211
- };
212
- _context2.next = 23;
213
- return (0, _fileUtils.writeFile)(this.tilesetPath, new Uint8Array(b3dm), "".concat(sourceChild.id, ".b3dm"));
214
- case 23:
215
- parentNode.children.push(child);
216
- sourceChild.unloadContent();
217
- _context2.next = 27;
218
- return this._addChildren(sourceChild, child, level + 1);
219
- case 27:
220
- _context2.next = 31;
221
- break;
222
- case 29:
223
- _context2.next = 31;
224
- return this._addChildren(sourceChild, parentNode, level + 1);
225
- case 31:
226
- case "end":
227
- return _context2.stop();
228
- }
229
- }, _callee2, this);
230
- }));
231
- function convertChildNode(_x2, _x3, _x4, _x5) {
232
- return _convertChildNode.apply(this, arguments);
233
- }
234
- return convertChildNode;
235
- }()
236
- }, {
237
- key: "_addChildren",
238
- value: function () {
239
- var _addChildren2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(parentSourceNode, parentNode, level) {
240
- var promises, _iterator, _step, childNodeInfo;
241
- return _regenerator.default.wrap(function _callee3$(_context3) {
242
- while (1) switch (_context3.prev = _context3.next) {
243
- case 0:
244
- if (!(this.options.maxDepth && level > this.options.maxDepth)) {
245
- _context3.next = 2;
246
- break;
247
- }
248
- return _context3.abrupt("return");
249
- case 2:
250
- promises = [];
251
- _iterator = _createForOfIteratorHelper(parentSourceNode.header.children || []);
252
- try {
253
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
254
- childNodeInfo = _step.value;
255
- promises.push(this.convertChildNode(parentSourceNode, parentNode, level, childNodeInfo));
256
- }
257
- } catch (err) {
258
- _iterator.e(err);
259
- } finally {
260
- _iterator.f();
261
- }
262
- _context3.next = 7;
263
- return Promise.all(promises);
264
- case 7:
265
- case "end":
266
- return _context3.stop();
267
- }
268
- }, _callee3, this);
269
- }));
270
- function _addChildren(_x6, _x7, _x8) {
271
- return _addChildren2.apply(this, arguments);
272
- }
273
- return _addChildren;
274
- }()
275
- }, {
276
- key: "_loadChildNode",
277
- value: function () {
278
- var _loadChildNode2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee4(parentNode, childNodeInfo) {
279
- var header, _ref, loader, nodeUrl, options;
280
- return _regenerator.default.wrap(function _callee4$(_context4) {
281
- while (1) switch (_context4.prev = _context4.next) {
282
- case 0:
283
- if (!this.sourceTileset.tileset.nodePages) {
284
- _context4.next = 7;
285
- break;
286
- }
287
- console.log("Node conversion: ".concat(childNodeInfo.id));
288
- _context4.next = 4;
289
- return this.sourceTileset.tileset.nodePagesTile.formTileFromNodePages(childNodeInfo.id);
290
- case 4:
291
- header = _context4.sent;
292
- _context4.next = 14;
293
- break;
294
- case 7:
295
- _ref = this.sourceTileset, loader = _ref.loader;
296
- nodeUrl = this._relativeUrlToFullUrl(parentNode.url, childNodeInfo.href);
297
- options = {
298
- i3s: _objectSpread(_objectSpread({}, this.sourceTileset.loadOptions), {}, {
299
- isTileHeader: true,
300
- loadContent: false
301
- })
302
- };
303
- console.log("Node conversion: ".concat(nodeUrl));
304
- _context4.next = 13;
305
- return (0, _core.load)(nodeUrl, loader, options);
306
- case 13:
307
- header = _context4.sent;
308
- case 14:
309
- return _context4.abrupt("return", new _tiles.Tile3D(this.sourceTileset, header, parentNode));
310
- case 15:
311
- case "end":
312
- return _context4.stop();
313
- }
314
- }, _callee4, this);
315
- }));
316
- function _loadChildNode(_x9, _x10) {
317
- return _loadChildNode2.apply(this, arguments);
318
- }
319
- return _loadChildNode;
320
- }()
321
- }, {
322
- key: "_relativeUrlToFullUrl",
323
- value: function _relativeUrlToFullUrl(baseUrl, relativeUrl) {
324
- var resultArray = baseUrl.split('/');
325
- var relativeUrlArray = relativeUrl.split('/');
326
- var _iterator2 = _createForOfIteratorHelper(relativeUrlArray),
327
- _step2;
328
- try {
329
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
330
- var folder = _step2.value;
331
- switch (folder) {
332
- case '.':
333
- continue;
334
- case '..':
335
- resultArray = resultArray.slice(0, -1);
336
- break;
337
- default:
338
- resultArray.push(folder);
339
- }
45
+ async convert(options) {
46
+ if (_core.isBrowser) {
47
+ console.log(_constants.BROWSER_ERROR_MESSAGE);
48
+ return _constants.BROWSER_ERROR_MESSAGE;
49
+ }
50
+ const {
51
+ inputUrl,
52
+ outputPath,
53
+ tilesetName,
54
+ maxDepth,
55
+ egmFilePath
56
+ } = options;
57
+ this.conversionStartTime = _process.default.hrtime();
58
+ this.options = {
59
+ maxDepth
60
+ };
61
+ console.log('Loading egm file...');
62
+ this.geoidHeightModel = await (0, _core.load)(egmFilePath, _pgmLoader.PGMLoader);
63
+ console.log('Loading egm file completed!');
64
+ await this.loadWorkers();
65
+ const sourceTilesetJson = await (0, _core.load)(inputUrl, _i3s.I3SLoader, {});
66
+ this.sourceTileset = new _tiles.Tileset3D(sourceTilesetJson, {
67
+ loadOptions: {
68
+ _nodeWorkers: true,
69
+ reuseWorkers: true,
70
+ 'i3s-content-nodejs': {
71
+ workerUrl: './modules/i3s/dist/i3s-content-nodejs-worker.js'
72
+ },
73
+ i3s: {
74
+ coordinateSystem: _i3s.COORDINATE_SYSTEM.LNGLAT_OFFSETS,
75
+ decodeTextures: false
340
76
  }
341
- } catch (err) {
342
- _iterator2.e(err);
343
- } finally {
344
- _iterator2.f();
345
77
  }
346
- return resultArray.join('/');
78
+ });
79
+ await this.sourceTileset.tilesetInitializationPromise;
80
+ const rootNode = this.sourceTileset.root;
81
+ if (!rootNode.header.obb) {
82
+ rootNode.header.obb = (0, _coordinateConverter.createObbFromMbs)(rootNode.header.mbs);
347
83
  }
348
- }, {
349
- key: "_loadChildAttributes",
350
- value: function () {
351
- var _loadChildAttributes2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee5(sourceChild, attributeStorageInfo) {
352
- var promises, attributeUrls, index, inputUrl, attribute, options, attributesList;
353
- return _regenerator.default.wrap(function _callee5$(_context5) {
354
- while (1) switch (_context5.prev = _context5.next) {
355
- case 0:
356
- promises = [];
357
- attributeUrls = sourceChild.header.attributeUrls;
358
- for (index = 0; index < attributeUrls.length; index++) {
359
- inputUrl = attributeUrls[index];
360
- attribute = attributeStorageInfo[index];
361
- options = {
362
- attributeName: attribute.name,
363
- attributeType: this._getAttributeType(attribute)
364
- };
365
- promises.push((0, _core.load)(inputUrl, _i3s.I3SAttributeLoader, options));
366
- }
367
- _context5.next = 5;
368
- return Promise.all(promises);
369
- case 5:
370
- attributesList = _context5.sent;
371
- this._replaceNestedArrays(attributesList);
372
- return _context5.abrupt("return", Object.assign.apply(Object, [{}].concat((0, _toConsumableArray2.default)(attributesList))));
373
- case 8:
374
- case "end":
375
- return _context5.stop();
376
- }
377
- }, _callee5, this);
378
- }));
379
- function _loadChildAttributes(_x11, _x12) {
380
- return _loadChildAttributes2.apply(this, arguments);
84
+ this.tilesetPath = (0, _path.join)("".concat(outputPath), "".concat(tilesetName));
85
+ this.attributeStorageInfo = sourceTilesetJson.attributeStorageInfo;
86
+ try {
87
+ await (0, _fileUtils.removeDir)(this.tilesetPath);
88
+ } catch (e) {}
89
+ const rootTile = {
90
+ boundingVolume: {
91
+ box: (0, _i3sObbTo3dTilesObb.i3sObbTo3dTilesObb)(rootNode.header.obb, this.geoidHeightModel)
92
+ },
93
+ geometricError: (0, _lodConversionUtils.convertScreenThresholdToGeometricError)(rootNode),
94
+ children: []
95
+ };
96
+ await this._addChildren(rootNode, rootTile, 1);
97
+ const tileset = (0, _jsonMapTransform.default)({
98
+ root: rootTile
99
+ }, (0, _tileset.TILESET)());
100
+ await (0, _fileUtils.writeFile)(this.tilesetPath, JSON.stringify(tileset), 'tileset.json');
101
+ this._finishConversion({
102
+ slpk: false,
103
+ outputPath,
104
+ tilesetName
105
+ });
106
+ const workerFarm = _workerUtils.WorkerFarm.getWorkerFarm({});
107
+ workerFarm.destroy();
108
+ }
109
+ async convertChildNode(parentSourceNode, parentNode, level, childNodeInfo) {
110
+ const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);
111
+ parentSourceNode.children.push(sourceChild);
112
+ if (sourceChild.contentUrl) {
113
+ var _sourceChild$header;
114
+ await this.sourceTileset._loadTile(sourceChild);
115
+ this.vertexCounter += sourceChild.content.vertexCount;
116
+ let featureAttributes = null;
117
+ if (this.attributeStorageInfo) {
118
+ featureAttributes = await this._loadChildAttributes(sourceChild, this.attributeStorageInfo);
381
119
  }
382
- return _loadChildAttributes;
383
- }()
384
- }, {
385
- key: "_getAttributeType",
386
- value: function _getAttributeType(attribute) {
387
- if (attribute.attributeValues) {
388
- return attribute.attributeValues.valueType;
389
- } else if (attribute.objectIds) {
390
- return 'Oid32';
120
+ if (!sourceChild.header.obb) {
121
+ sourceChild.header.obb = (0, _coordinateConverter.createObbFromMbs)(sourceChild.header.mbs);
391
122
  }
392
- return '';
123
+ const boundingVolume = {
124
+ box: (0, _i3sObbTo3dTilesObb.i3sObbTo3dTilesObb)(sourceChild.header.obb, this.geoidHeightModel)
125
+ };
126
+ const child = {
127
+ boundingVolume,
128
+ geometricError: (0, _lodConversionUtils.convertScreenThresholdToGeometricError)(sourceChild),
129
+ children: []
130
+ };
131
+ const i3sAttributesData = {
132
+ tileContent: sourceChild.content,
133
+ textureFormat: sourceChild === null || sourceChild === void 0 ? void 0 : (_sourceChild$header = sourceChild.header) === null || _sourceChild$header === void 0 ? void 0 : _sourceChild$header.textureFormat
134
+ };
135
+ const b3dm = await (0, _dTilesAttributesWorker.transform3DTilesAttributesOnWorker)(i3sAttributesData, {
136
+ source: this.workerSource.tile3dWorkerSource,
137
+ featureAttributes
138
+ });
139
+ child.content = {
140
+ uri: "".concat(sourceChild.id, ".b3dm"),
141
+ boundingVolume
142
+ };
143
+ await (0, _fileUtils.writeFile)(this.tilesetPath, new Uint8Array(b3dm), "".concat(sourceChild.id, ".b3dm"));
144
+ parentNode.children.push(child);
145
+ sourceChild.unloadContent();
146
+ await this._addChildren(sourceChild, child, level + 1);
147
+ } else {
148
+ await this._addChildren(sourceChild, parentNode, level + 1);
393
149
  }
394
- }, {
395
- key: "_replaceNestedArrays",
396
- value: function _replaceNestedArrays(attributesList) {
397
- for (var index = 0; index < attributesList.length; index++) {
398
- var attributeObject = attributesList[index];
399
- for (var _key in attributeObject) {
400
- attributeObject[_key] = Array.from(attributeObject[_key]);
150
+ }
151
+ async _addChildren(parentSourceNode, parentNode, level) {
152
+ if (this.options.maxDepth && level > this.options.maxDepth) {
153
+ return;
154
+ }
155
+ const promises = [];
156
+ for (const childNodeInfo of parentSourceNode.header.children || []) {
157
+ promises.push(this.convertChildNode(parentSourceNode, parentNode, level, childNodeInfo));
158
+ }
159
+ await Promise.all(promises);
160
+ }
161
+ async _loadChildNode(parentNode, childNodeInfo) {
162
+ let header;
163
+ if (this.sourceTileset.tileset.nodePages) {
164
+ console.log("Node conversion: ".concat(childNodeInfo.id));
165
+ header = await this.sourceTileset.tileset.nodePagesTile.formTileFromNodePages(childNodeInfo.id);
166
+ } else {
167
+ const {
168
+ loader
169
+ } = this.sourceTileset;
170
+ const nodeUrl = this._relativeUrlToFullUrl(parentNode.url, childNodeInfo.href);
171
+ const options = {
172
+ i3s: {
173
+ ...this.sourceTileset.loadOptions,
174
+ isTileHeader: true,
175
+ loadContent: false
401
176
  }
402
- }
177
+ };
178
+ console.log("Node conversion: ".concat(nodeUrl));
179
+ header = await (0, _core.load)(nodeUrl, loader, options);
403
180
  }
404
- }, {
405
- key: "_finishConversion",
406
- value: function () {
407
- var _finishConversion2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee6(params) {
408
- var filesSize, diff, conversionTime;
409
- return _regenerator.default.wrap(function _callee6$(_context6) {
410
- while (1) switch (_context6.prev = _context6.next) {
411
- case 0:
412
- _context6.next = 2;
413
- return (0, _statisticUtills.calculateFilesSize)(params);
414
- case 2:
415
- filesSize = _context6.sent;
416
- diff = _process.default.hrtime(this.conversionStartTime);
417
- conversionTime = (0, _statisticUtills.timeConverter)(diff);
418
- console.log("------------------------------------------------");
419
- console.log("Finish conversion of ".concat(I3S));
420
- console.log("Total conversion time: ".concat(conversionTime));
421
- console.log("Vertex count: ", this.vertexCounter);
422
- console.log("File(s) size: ", filesSize, ' bytes');
423
- console.log("------------------------------------------------");
424
- case 11:
425
- case "end":
426
- return _context6.stop();
427
- }
428
- }, _callee6, this);
429
- }));
430
- function _finishConversion(_x13) {
431
- return _finishConversion2.apply(this, arguments);
181
+ return new _tiles.Tile3D(this.sourceTileset, header, parentNode);
182
+ }
183
+ _relativeUrlToFullUrl(baseUrl, relativeUrl) {
184
+ let resultArray = baseUrl.split('/');
185
+ const relativeUrlArray = relativeUrl.split('/');
186
+ for (const folder of relativeUrlArray) {
187
+ switch (folder) {
188
+ case '.':
189
+ continue;
190
+ case '..':
191
+ resultArray = resultArray.slice(0, -1);
192
+ break;
193
+ default:
194
+ resultArray.push(folder);
432
195
  }
433
- return _finishConversion;
434
- }()
435
- }, {
436
- key: "loadWorkers",
437
- value: function () {
438
- var _loadWorkers = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee7() {
439
- var tile3dAttributesWorkerUrl, sourceResponse, source;
440
- return _regenerator.default.wrap(function _callee7$(_context7) {
441
- while (1) switch (_context7.prev = _context7.next) {
442
- case 0:
443
- console.log("Loading workers source...");
444
- tile3dAttributesWorkerUrl = (0, _workerUtils.getWorkerURL)(_dTilesAttributesWorker.Tile3dAttributesWorker, _objectSpread({}, (0, _core.getLoaderOptions)()));
445
- _context7.next = 4;
446
- return (0, _core.fetchFile)(tile3dAttributesWorkerUrl);
447
- case 4:
448
- sourceResponse = _context7.sent;
449
- _context7.next = 7;
450
- return sourceResponse.text();
451
- case 7:
452
- source = _context7.sent;
453
- this.workerSource.tile3dWorkerSource = source;
454
- console.log("Loading workers source completed!");
455
- case 10:
456
- case "end":
457
- return _context7.stop();
458
- }
459
- }, _callee7, this);
460
- }));
461
- function loadWorkers() {
462
- return _loadWorkers.apply(this, arguments);
196
+ }
197
+ return resultArray.join('/');
198
+ }
199
+ async _loadChildAttributes(sourceChild, attributeStorageInfo) {
200
+ const promises = [];
201
+ const {
202
+ attributeUrls
203
+ } = sourceChild.header;
204
+ for (let index = 0; index < attributeUrls.length; index++) {
205
+ const inputUrl = attributeUrls[index];
206
+ const attribute = attributeStorageInfo[index];
207
+ const options = {
208
+ attributeName: attribute.name,
209
+ attributeType: this._getAttributeType(attribute)
210
+ };
211
+ promises.push((0, _core.load)(inputUrl, _i3s.I3SAttributeLoader, options));
212
+ }
213
+ const attributesList = await Promise.all(promises);
214
+ this._replaceNestedArrays(attributesList);
215
+ return Object.assign({}, ...attributesList);
216
+ }
217
+ _getAttributeType(attribute) {
218
+ if (attribute.attributeValues) {
219
+ return attribute.attributeValues.valueType;
220
+ } else if (attribute.objectIds) {
221
+ return 'Oid32';
222
+ }
223
+ return '';
224
+ }
225
+ _replaceNestedArrays(attributesList) {
226
+ for (let index = 0; index < attributesList.length; index++) {
227
+ const attributeObject = attributesList[index];
228
+ for (const key in attributeObject) {
229
+ attributeObject[key] = Array.from(attributeObject[key]);
463
230
  }
464
- return loadWorkers;
465
- }()
466
- }]);
467
- return Tiles3DConverter;
468
- }();
231
+ }
232
+ }
233
+ async _finishConversion(params) {
234
+ const filesSize = await (0, _statisticUtills.calculateFilesSize)(params);
235
+ const diff = _process.default.hrtime(this.conversionStartTime);
236
+ const conversionTime = (0, _statisticUtills.timeConverter)(diff);
237
+ console.log("------------------------------------------------");
238
+ console.log("Finish conversion of ".concat(I3S));
239
+ console.log("Total conversion time: ".concat(conversionTime));
240
+ console.log("Vertex count: ", this.vertexCounter);
241
+ console.log("File(s) size: ", filesSize, ' bytes');
242
+ console.log("------------------------------------------------");
243
+ }
244
+ async loadWorkers() {
245
+ console.log("Loading workers source...");
246
+ const tile3dAttributesWorkerUrl = (0, _workerUtils.getWorkerURL)(_dTilesAttributesWorker.Tile3dAttributesWorker, {
247
+ ...(0, _core.getLoaderOptions)()
248
+ });
249
+ const sourceResponse = await (0, _core.fetchFile)(tile3dAttributesWorkerUrl);
250
+ const source = await sourceResponse.text();
251
+ this.workerSource.tile3dWorkerSource = source;
252
+ console.log("Loading workers source completed!");
253
+ }
254
+ }
469
255
  exports.default = Tiles3DConverter;
470
256
  //# sourceMappingURL=3d-tiles-converter.js.map