@loaders.gl/tile-converter 4.2.0-alpha.5 → 4.2.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +1 -1
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +42 -22
  4. package/dist/3d-tiles-converter/helpers/b3dm-converter.d.ts.map +1 -1
  5. package/dist/3d-tiles-converter/helpers/b3dm-converter.js +4 -0
  6. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -1
  7. package/dist/3d-tiles-converter/helpers/load-i3s.js +3 -28
  8. package/dist/converter-cli.js +4 -2
  9. package/dist/converter.min.cjs +95 -95
  10. package/dist/deps-installer/deps-installer.d.ts.map +1 -1
  11. package/dist/deps-installer/deps-installer.js +6 -1
  12. package/dist/i3s-converter/helpers/attribute-metadata-info.js +4 -1
  13. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -1
  14. package/dist/i3s-converter/helpers/batch-ids-extensions.js +2 -1
  15. package/dist/i3s-converter/helpers/coordinate-converter.js +2 -2
  16. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -1
  17. package/dist/i3s-converter/helpers/feature-attributes.js +4 -2
  18. package/dist/i3s-converter/helpers/geometry-attributes.js +6 -5
  19. package/dist/i3s-converter/helpers/geometry-converter.d.ts +15 -1
  20. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  21. package/dist/i3s-converter/helpers/geometry-converter.js +52 -12
  22. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  23. package/dist/i3s-converter/helpers/gltf-attributes.js +12 -14
  24. package/dist/i3s-converter/helpers/node-index-document.d.ts +8 -1
  25. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  26. package/dist/i3s-converter/helpers/node-index-document.js +18 -11
  27. package/dist/i3s-converter/helpers/node-pages.d.ts.map +1 -1
  28. package/dist/i3s-converter/helpers/node-pages.js +27 -26
  29. package/dist/i3s-converter/helpers/preprocess-3d-tiles.d.ts.map +1 -1
  30. package/dist/i3s-converter/helpers/progress.d.ts.map +1 -1
  31. package/dist/i3s-converter/helpers/progress.js +23 -18
  32. package/dist/i3s-converter/helpers/tileset-traversal.d.ts +8 -1
  33. package/dist/i3s-converter/helpers/tileset-traversal.d.ts.map +1 -1
  34. package/dist/i3s-converter/helpers/tileset-traversal.js +12 -3
  35. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  36. package/dist/i3s-converter/i3s-converter.js +190 -66
  37. package/dist/i3s-converter/json-templates/node.js +1 -1
  38. package/dist/i3s-server/bin/i3s-server.min.cjs +69 -69
  39. package/dist/i3s-server/bin/www.js +6 -4
  40. package/dist/i3s-server/controllers/slpk-controller.d.ts.map +1 -1
  41. package/dist/i3s-server/controllers/slpk-controller.js +3 -1
  42. package/dist/i3s-server/routes/index.js +11 -8
  43. package/dist/i3s-server/routes/slpk-router.d.ts.map +1 -1
  44. package/dist/i3s-server/routes/slpk-router.js +24 -18
  45. package/dist/i3s-server/utils/server-utils.d.ts.map +1 -1
  46. package/dist/i3s-server/utils/server-utils.js +8 -5
  47. package/dist/index.cjs +419 -211
  48. package/dist/index.cjs.map +3 -3
  49. package/dist/lib/utils/cli-utils.d.ts.map +1 -1
  50. package/dist/lib/utils/cli-utils.js +2 -0
  51. package/dist/lib/utils/conversion-dump.d.ts +9 -1
  52. package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
  53. package/dist/lib/utils/conversion-dump.js +44 -21
  54. package/dist/lib/utils/file-utils.d.ts +1 -1
  55. package/dist/lib/utils/file-utils.d.ts.map +1 -1
  56. package/dist/lib/utils/file-utils.js +10 -12
  57. package/dist/lib/utils/statistic-utills.d.ts.map +1 -1
  58. package/dist/lib/utils/statistic-utills.js +5 -7
  59. package/dist/lib/utils/write-queue.d.ts.map +1 -1
  60. package/dist/lib/utils/write-queue.js +7 -3
  61. package/dist/pgm-loader.js +1 -1
  62. package/dist/slpk-extractor/slpk-extractor.d.ts.map +1 -1
  63. package/dist/slpk-extractor/slpk-extractor.js +2 -1
  64. package/dist/slpk-extractor-cli.d.ts.map +1 -1
  65. package/dist/slpk-extractor-cli.js +16 -8
  66. package/dist/slpk-extractor.min.cjs +1 -1
  67. package/package.json +23 -22
  68. package/src/3d-tiles-converter/3d-tiles-converter.ts +21 -10
  69. package/src/3d-tiles-converter/helpers/b3dm-converter.ts +1 -0
  70. package/src/3d-tiles-converter/helpers/load-i3s.ts +3 -27
  71. package/src/converter-cli.ts +4 -2
  72. package/src/deps-installer/deps-installer.ts +7 -0
  73. package/src/i3s-converter/helpers/attribute-metadata-info.ts +1 -1
  74. package/src/i3s-converter/helpers/batch-ids-extensions.ts +3 -1
  75. package/src/i3s-converter/helpers/coordinate-converter.ts +2 -2
  76. package/src/i3s-converter/helpers/feature-attributes.ts +5 -2
  77. package/src/i3s-converter/helpers/geometry-attributes.ts +6 -5
  78. package/src/i3s-converter/helpers/geometry-converter.ts +118 -72
  79. package/src/i3s-converter/helpers/gltf-attributes.ts +12 -13
  80. package/src/i3s-converter/helpers/node-index-document.ts +18 -10
  81. package/src/i3s-converter/helpers/node-pages.ts +27 -29
  82. package/src/i3s-converter/helpers/preprocess-3d-tiles.ts +1 -0
  83. package/src/i3s-converter/helpers/progress.ts +1 -0
  84. package/src/i3s-converter/helpers/tileset-traversal.ts +22 -13
  85. package/src/i3s-converter/i3s-converter.ts +173 -114
  86. package/src/i3s-converter/json-templates/node.ts +1 -1
  87. package/src/i3s-server/bin/www.ts +6 -4
  88. package/src/i3s-server/controllers/slpk-controller.ts +4 -2
  89. package/src/i3s-server/routes/index.ts +10 -7
  90. package/src/i3s-server/routes/slpk-router.ts +22 -16
  91. package/src/i3s-server/utils/server-utils.ts +6 -4
  92. package/src/lib/utils/cli-utils.ts +2 -0
  93. package/src/lib/utils/conversion-dump.ts +35 -20
  94. package/src/lib/utils/file-utils.ts +11 -11
  95. package/src/lib/utils/statistic-utills.ts +5 -6
  96. package/src/lib/utils/write-queue.ts +2 -2
  97. package/src/slpk-extractor/slpk-extractor.ts +2 -1
  98. package/src/slpk-extractor-cli.ts +16 -8
  99. package/src/lib/utils/statistic-utills.d.ts +0 -25
package/dist/index.cjs CHANGED
@@ -67,6 +67,9 @@ var ResourceType;
67
67
 
68
68
  // dist/i3s-converter/helpers/attribute-metadata-info.js
69
69
  var AttributeMetadataInfo = class {
70
+ _attributeStorageInfo;
71
+ _fields;
72
+ _popupInfo;
70
73
  constructor() {
71
74
  this._attributeStorageInfo = [];
72
75
  this._fields = [];
@@ -127,7 +130,7 @@ var AttributeMetadataInfo = class {
127
130
  }
128
131
  if (isUpdated) {
129
132
  const attributeNames = [];
130
- for (let info of this._attributeStorageInfo) {
133
+ for (const info of this._attributeStorageInfo) {
131
134
  attributeNames.push(info.name);
132
135
  }
133
136
  this._popupInfo = this.createPopupInfo(attributeNames);
@@ -364,14 +367,12 @@ async function writeFileForSlpk(path, data, fileName = "index.json", compress =
364
367
  if (!compressList.includes(pathFile)) {
365
368
  compressList.push(pathFile);
366
369
  return `${pathFile}.gz`;
367
- } else {
368
- return null;
369
370
  }
370
- } else {
371
- const pathGzFile = await compressFileWithGzip(pathFile);
372
- await removeFile(pathFile);
373
- return pathGzFile;
371
+ return null;
374
372
  }
373
+ const pathGzFile = await compressFileWithGzip(pathFile);
374
+ await removeFile(pathFile);
375
+ return pathGzFile;
375
376
  }
376
377
  return pathFile;
377
378
  }
@@ -421,6 +422,12 @@ async function renameFile(oldPath, newPath) {
421
422
 
422
423
  // dist/i3s-converter/helpers/node-pages.js
423
424
  var NodePages = class {
425
+ nodesPerPage;
426
+ nodesCounter;
427
+ writeFile;
428
+ converter;
429
+ nodePages;
430
+ length = 0;
424
431
  /**
425
432
  * @constructs
426
433
  * Create a nodePages instance.
@@ -428,7 +435,6 @@ var NodePages = class {
428
435
  * @param nodesPerPage - length limit for one nodePage. An additional nodePage is created when this limit is met
429
436
  */
430
437
  constructor(writeFileFunc, nodesPerPage, converter) {
431
- this.length = 0;
432
438
  this.nodesPerPage = nodesPerPage;
433
439
  this.nodesCounter = 0;
434
440
  this.nodePages = [{}];
@@ -472,9 +478,8 @@ var NodePages = class {
472
478
  if (await isFileExists(fullName)) {
473
479
  console.log(`load ${fullName}.`);
474
480
  return await openJson(filePath, fileName);
475
- } else {
476
- return { nodes: [] };
477
481
  }
482
+ return { nodes: [] };
478
483
  }
479
484
  /**
480
485
  * Get nodepage id by node id
@@ -548,27 +553,26 @@ var NodePages = class {
548
553
  async saveNode(node) {
549
554
  if (!this.converter.options.instantNodeWriting) {
550
555
  return;
556
+ }
557
+ const nodePageIndex = this.getPageIndexByNodeId(node.index);
558
+ const nodePage = await this.getPageByNodeId(node.index);
559
+ const { filePath, fileName } = this.getNodePageFileName(nodePageIndex);
560
+ const nodeToUpdate = await this.getNodeById(node.index, nodePage);
561
+ if (nodeToUpdate) {
562
+ NodePages.updateAll(nodeToUpdate, node);
551
563
  } else {
552
- const nodePageIndex = this.getPageIndexByNodeId(node.index);
553
- const nodePage = await this.getPageByNodeId(node.index);
554
- const { filePath, fileName } = this.getNodePageFileName(nodePageIndex);
555
- const nodeToUpdate = await this.getNodeById(node.index, nodePage);
556
- if (nodeToUpdate) {
557
- NodePages.updateAll(nodeToUpdate, node);
558
- } else {
559
- nodePage.nodes.push(node);
560
- }
561
- const nodePageStr = JSON.stringify(nodePage);
562
- if (this.converter.options.slpk) {
563
- await this.converter.writeQueue.enqueue({
564
- archiveKey: `nodePages/${nodePageIndex.toString()}.json.gz`,
565
- writePromise: () => this.writeFile(filePath, nodePageStr, fileName, true, this.converter.compressList)
566
- }, true);
567
- } else {
568
- await this.converter.writeQueue.enqueue({
569
- writePromise: () => this.writeFile(filePath, nodePageStr)
570
- }, true);
571
- }
564
+ nodePage.nodes.push(node);
565
+ }
566
+ const nodePageStr = JSON.stringify(nodePage);
567
+ if (this.converter.options.slpk) {
568
+ await this.converter.writeQueue.enqueue({
569
+ archiveKey: `nodePages/${nodePageIndex.toString()}.json.gz`,
570
+ writePromise: () => this.writeFile(filePath, nodePageStr, fileName, true, this.converter.compressList)
571
+ }, true);
572
+ } else {
573
+ await this.converter.writeQueue.enqueue({
574
+ writePromise: () => this.writeFile(filePath, nodePageStr)
575
+ }, true);
572
576
  }
573
577
  }
574
578
  /**
@@ -695,15 +699,14 @@ var import_fs3 = require("fs");
695
699
  function timeConverter(time) {
696
700
  if (typeof time === "number") {
697
701
  const milliSecondsInSecond = 1e3;
698
- const timeInSeconds = Math.floor(time / milliSecondsInSecond);
699
- const milliseconds = time - timeInSeconds * milliSecondsInSecond;
700
- return timeConverterFromSecondsAndMilliseconds(timeInSeconds, milliseconds);
701
- } else {
702
- const nanoSecondsInMillisecond = 1e6;
703
- const timeInSeconds = time[0];
704
- const milliseconds = time[1] / nanoSecondsInMillisecond;
705
- return timeConverterFromSecondsAndMilliseconds(timeInSeconds, milliseconds);
706
- }
702
+ const timeInSeconds2 = Math.floor(time / milliSecondsInSecond);
703
+ const milliseconds2 = time - timeInSeconds2 * milliSecondsInSecond;
704
+ return timeConverterFromSecondsAndMilliseconds(timeInSeconds2, milliseconds2);
705
+ }
706
+ const nanoSecondsInMillisecond = 1e6;
707
+ const timeInSeconds = time[0];
708
+ const milliseconds = time[1] / nanoSecondsInMillisecond;
709
+ return timeConverterFromSecondsAndMilliseconds(timeInSeconds, milliseconds);
707
710
  }
708
711
  function timeConverterFromSecondsAndMilliseconds(timeInSeconds, milliseconds) {
709
712
  const hours = Math.floor(timeInSeconds / 3600);
@@ -833,11 +836,11 @@ function getFrequentValue(values) {
833
836
  function makeAttributeObjects(attributes) {
834
837
  const { featureIds, positions, normals, colors, uvRegions, texCoords, faceRange = new Uint32Array(0) } = attributes;
835
838
  const groupedData = [];
836
- let positionsList = new Float32Array(positions);
837
- let normalsList = new Float32Array(normals);
838
- let colorsList = new Uint8Array(colors);
839
- let texCoordsList = new Float32Array(texCoords);
840
- let uvRegionsList = new Uint16Array(uvRegions);
839
+ const positionsList = new Float32Array(positions);
840
+ const normalsList = new Float32Array(normals);
841
+ const colorsList = new Uint8Array(colors);
842
+ const texCoordsList = new Float32Array(texCoords);
843
+ const uvRegionsList = new Uint16Array(uvRegions);
841
844
  let positionsOffset = 0;
842
845
  let normalsOffset = 0;
843
846
  let colorsOffset = 0;
@@ -980,8 +983,8 @@ function createBoundingVolumesFromGeometry(cartesianPositions, geoidHeightModel)
980
983
  const positionVectors = convertPositionsToVectors(cartesianPositions);
981
984
  const geometryObb = (0, import_culling.makeOrientedBoundingBoxFromPoints)(positionVectors);
982
985
  const geometryMbs = (0, import_culling.makeBoundingSphereFromPoints)(positionVectors);
983
- let mbsCenter = import_geospatial.Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new import_core2.Vector3());
984
- let obbCenter = import_geospatial.Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new import_core2.Vector3());
986
+ const mbsCenter = import_geospatial.Ellipsoid.WGS84.cartesianToCartographic(geometryMbs.center, new import_core2.Vector3());
987
+ const obbCenter = import_geospatial.Ellipsoid.WGS84.cartesianToCartographic(geometryObb.center, new import_core2.Vector3());
985
988
  mbsCenter[2] = mbsCenter[2] - geoidHeightModel.getHeight(mbsCenter[1], mbsCenter[0]);
986
989
  obbCenter[2] = obbCenter[2] - geoidHeightModel.getHeight(obbCenter[1], obbCenter[0]);
987
990
  return {
@@ -1033,24 +1036,23 @@ var import_core3 = require("@math.gl/core");
1033
1036
  var import_geospatial2 = require("@math.gl/geospatial");
1034
1037
  function prepareDataForAttributesConversion(tileContent, tileTransform, boundingVolume) {
1035
1038
  var _a2, _b, _c, _d, _e, _f, _g, _h;
1036
- let nodes = ((_b = (_a2 = tileContent.gltf) == null ? void 0 : _a2.scene) == null ? void 0 : _b.nodes) || ((_e = (_d = (_c = tileContent.gltf) == null ? void 0 : _c.scenes) == null ? void 0 : _d[0]) == null ? void 0 : _e.nodes) || ((_f = tileContent.gltf) == null ? void 0 : _f.nodes) || [];
1039
+ const nodes = ((_b = (_a2 = tileContent.gltf) == null ? void 0 : _a2.scene) == null ? void 0 : _b.nodes) || ((_e = (_d = (_c = tileContent.gltf) == null ? void 0 : _c.scenes) == null ? void 0 : _d[0]) == null ? void 0 : _e.nodes) || ((_f = tileContent.gltf) == null ? void 0 : _f.nodes) || [];
1037
1040
  const images = ((_h = (_g = tileContent.gltf) == null ? void 0 : _g.images) == null ? void 0 : _h.map((imageObject) => {
1038
1041
  var _a3, _b2;
1039
1042
  if ((_a3 = imageObject == null ? void 0 : imageObject.image) == null ? void 0 : _a3.compressed) {
1040
1043
  return null;
1041
- } else {
1042
- const data = (_b2 = imageObject == null ? void 0 : imageObject.image) == null ? void 0 : _b2.data;
1043
- const dataCopy = new Uint8Array(data.length);
1044
- dataCopy.set(data);
1045
- return {
1046
- data: dataCopy,
1047
- compressed: false,
1048
- height: imageObject.image.height,
1049
- width: imageObject.image.width,
1050
- components: imageObject.image.components,
1051
- mimeType: imageObject.mimeType
1052
- };
1053
1044
  }
1045
+ const data = (_b2 = imageObject == null ? void 0 : imageObject.image) == null ? void 0 : _b2.data;
1046
+ const dataCopy = new Uint8Array(data.length);
1047
+ dataCopy.set(data);
1048
+ return {
1049
+ data: dataCopy,
1050
+ compressed: false,
1051
+ height: imageObject.image.height,
1052
+ width: imageObject.image.width,
1053
+ components: imageObject.image.components,
1054
+ mimeType: imageObject.mimeType
1055
+ };
1054
1056
  })) || [];
1055
1057
  prepareNodes(nodes);
1056
1058
  const { cartographicOrigin, modelMatrix: cartesianModelMatrix } = calculateTransformProps(tileContent, tileTransform, boundingVolume);
@@ -1160,7 +1162,7 @@ function handleBatchIdsExtensions(attributes, primitive, images, featureTexture)
1160
1162
  return [];
1161
1163
  }
1162
1164
  function handleExtMeshFeaturesExtension(attributes, extMeshFeatures) {
1163
- for (let ids of extMeshFeatures.featureIds) {
1165
+ for (const ids of extMeshFeatures.featureIds) {
1164
1166
  if (typeof ids.propertyTable !== "undefined") {
1165
1167
  return ids.data;
1166
1168
  }
@@ -1295,7 +1297,7 @@ var getAttributeTypesMapFromSchema = (gltfJson, metadataClass) => {
1295
1297
  const attributeTypesMap = {};
1296
1298
  const extFeatureMetadataSchemaClass = (_d = (_c = (_b = (_a2 = gltfJson.extensions) == null ? void 0 : _a2[import_gltf2.EXT_FEATURE_METADATA]) == null ? void 0 : _b.schema) == null ? void 0 : _c.classes) == null ? void 0 : _d[metadataClass];
1297
1299
  if (extFeatureMetadataSchemaClass) {
1298
- for (let propertyName in extFeatureMetadataSchemaClass.properties) {
1300
+ for (const propertyName in extFeatureMetadataSchemaClass.properties) {
1299
1301
  const property = extFeatureMetadataSchemaClass.properties[propertyName];
1300
1302
  const attributeProperty = getAttributeTypeFromExtFeatureMetadata(property);
1301
1303
  attributeTypesMap[propertyName] = attributeProperty;
@@ -1304,7 +1306,7 @@ var getAttributeTypesMapFromSchema = (gltfJson, metadataClass) => {
1304
1306
  }
1305
1307
  const extStructuralMetadataSchemaClass = (_h = (_g = (_f = (_e = gltfJson.extensions) == null ? void 0 : _e[import_gltf2.EXT_STRUCTURAL_METADATA]) == null ? void 0 : _f.schema) == null ? void 0 : _g.classes) == null ? void 0 : _h[metadataClass];
1306
1308
  if (extStructuralMetadataSchemaClass) {
1307
- for (let propertyName in extStructuralMetadataSchemaClass.properties) {
1309
+ for (const propertyName in extStructuralMetadataSchemaClass.properties) {
1308
1310
  const property = extStructuralMetadataSchemaClass.properties[propertyName];
1309
1311
  const attributeProperty = getAttributeTypeFromExtStructuralMetadata(property);
1310
1312
  attributeTypesMap[propertyName] = attributeProperty;
@@ -1397,7 +1399,7 @@ var DOUBLE_TYPE = "Float64";
1397
1399
  var OBJECT_ID_TYPE = "Oid32";
1398
1400
  var BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ["CUSTOM_ATTRIBUTE_2", "_BATCHID", "BATCHID"];
1399
1401
  var scratchVector = new import_core4.Vector3();
1400
- async function convertB3dmToI3sGeometry(tileContent, tileTransform, tileBoundingVolume, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, libraries, metadataClass) {
1402
+ async function convertB3dmToI3sGeometry({ tileContent, tileTransform, tileBoundingVolume, addNodeToNodePage, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, shouldMergeMaterials, geoidHeightModel, libraries, metadataClass }) {
1401
1403
  var _a2;
1402
1404
  const useCartesianPositions = generateBoundingVolumes;
1403
1405
  const materialAndTextureList = await convertMaterials((_a2 = tileContent.gltf) == null ? void 0 : _a2.materials, shouldMergeMaterials);
@@ -1510,7 +1512,15 @@ async function convertAttributes(attributesData, materialAndTextureList, useCart
1510
1512
  attributesMap.set(mergedMaterial.originalMaterialId, attributes);
1511
1513
  }
1512
1514
  }
1513
- convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, void 0, featureTexture);
1515
+ convertNodes({
1516
+ nodes,
1517
+ images,
1518
+ cartographicOrigin,
1519
+ cartesianModelMatrix,
1520
+ attributesMap,
1521
+ useCartesianPositions,
1522
+ featureTexture
1523
+ });
1514
1524
  for (const attrKey of attributesMap.keys()) {
1515
1525
  const attributes = attributesMap.get(attrKey);
1516
1526
  if (!attributes) {
@@ -1527,10 +1537,19 @@ async function convertAttributes(attributesData, materialAndTextureList, useCart
1527
1537
  }
1528
1538
  return attributesMap;
1529
1539
  }
1530
- function convertNodes(nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new import_core4.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]), featureTexture) {
1540
+ function convertNodes({ nodes, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new import_core4.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]), featureTexture }) {
1531
1541
  if (nodes) {
1532
1542
  for (const node of nodes) {
1533
- convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix, featureTexture);
1543
+ convertNode({
1544
+ node,
1545
+ images,
1546
+ cartographicOrigin,
1547
+ cartesianModelMatrix,
1548
+ attributesMap,
1549
+ useCartesianPositions,
1550
+ matrix,
1551
+ featureTexture
1552
+ });
1534
1553
  }
1535
1554
  }
1536
1555
  }
@@ -1551,15 +1570,33 @@ function getCompositeTransformationMatrix(node, matrix) {
1551
1570
  }
1552
1571
  return transformationMatrix;
1553
1572
  }
1554
- function convertNode(node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new import_core4.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]), featureTexture) {
1573
+ function convertNode({ node, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new import_core4.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]), featureTexture }) {
1555
1574
  const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
1556
1575
  const mesh = node.mesh;
1557
1576
  if (mesh) {
1558
- convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix, featureTexture);
1577
+ convertMesh({
1578
+ mesh,
1579
+ images,
1580
+ cartographicOrigin,
1581
+ cartesianModelMatrix,
1582
+ attributesMap,
1583
+ useCartesianPositions,
1584
+ matrix: transformationMatrix,
1585
+ featureTexture
1586
+ });
1559
1587
  }
1560
- convertNodes(node.children || [], images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix, featureTexture);
1588
+ convertNodes({
1589
+ nodes: node.children || [],
1590
+ images,
1591
+ cartographicOrigin,
1592
+ cartesianModelMatrix,
1593
+ attributesMap,
1594
+ useCartesianPositions,
1595
+ matrix: transformationMatrix,
1596
+ featureTexture
1597
+ });
1561
1598
  }
1562
- function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions = false, matrix = new import_core4.Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]), featureTexture) {
1599
+ function convertMesh({ mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions = false, matrix, featureTexture }) {
1563
1600
  var _a2;
1564
1601
  for (const primitive of mesh.primitives) {
1565
1602
  let outputAttributes = null;
@@ -1834,7 +1871,7 @@ function convertMaterial(sourceMaterial) {
1834
1871
  };
1835
1872
  }
1836
1873
  sourceMaterial.id = Number.isFinite(sourceMaterial.id) ? sourceMaterial.id : (0, import_uuid.v4)();
1837
- let mergedMaterials = [{ originalMaterialId: sourceMaterial.id }];
1874
+ const mergedMaterials = [{ originalMaterialId: sourceMaterial.id }];
1838
1875
  if (!texture) {
1839
1876
  const baseColorFactor = (_e = sourceMaterial == null ? void 0 : sourceMaterial.pbrMetallicRoughness) == null ? void 0 : _e.baseColorFactor;
1840
1877
  material.pbrMetallicRoughness.baseColorFactor = baseColorFactor && baseColorFactor.map((c) => Math.round(c * 255)) || void 0;
@@ -2305,7 +2342,7 @@ function convertScreenThresholdToGeometricError(node) {
2305
2342
 
2306
2343
  // dist/pgm-loader.js
2307
2344
  var import_geoid = require("@math.gl/geoid");
2308
- var VERSION = true ? "4.2.0-alpha.4" : "latest";
2345
+ var VERSION = true ? "4.2.0-alpha.5" : "latest";
2309
2346
  var PGMLoader = {
2310
2347
  name: "PGM - Netpbm grayscale image format",
2311
2348
  id: "pgm",
@@ -2931,10 +2968,15 @@ var Queue = class extends Array {
2931
2968
  var import_process = __toESM(require("process"), 1);
2932
2969
  var MEMORY_LIMIT = 4 * 1024 * 1024 * 1024;
2933
2970
  var WriteQueue = class extends Queue {
2971
+ intervalId;
2972
+ // eslint-disable-line no-undef
2973
+ conversionDump;
2974
+ writePromise = null;
2975
+ fileMap = {};
2976
+ listeningInterval;
2977
+ writeConcurrency;
2934
2978
  constructor(conversionDump, listeningInterval = 2e3, writeConcurrency = 400) {
2935
2979
  super();
2936
- this.writePromise = null;
2937
- this.fileMap = {};
2938
2980
  this.conversionDump = conversionDump;
2939
2981
  this.listeningInterval = listeningInterval;
2940
2982
  this.writeConcurrency = writeConcurrency;
@@ -2954,7 +2996,7 @@ var WriteQueue = class extends Queue {
2954
2996
  }
2955
2997
  }
2956
2998
  startListening() {
2957
- this.intervalId = setInterval(this.startWrite.bind(this), this.listeningInterval);
2999
+ this.intervalId = setInterval(() => this.startWrite.bind(this), this.listeningInterval);
2958
3000
  }
2959
3001
  stopListening() {
2960
3002
  if (this.intervalId) {
@@ -3098,6 +3140,21 @@ var NODE = () => ({
3098
3140
 
3099
3141
  // dist/i3s-converter/helpers/node-index-document.js
3100
3142
  var NodeIndexDocument = class {
3143
+ /** Node id */
3144
+ id;
3145
+ /** Id in node pages */
3146
+ inPageId;
3147
+ /** 3DNodeIndexDocument data */
3148
+ data = null;
3149
+ /** children */
3150
+ children = [];
3151
+ /** converter instance */
3152
+ converter;
3153
+ /**
3154
+ * Finalized property. It means that all child nodes are saved and their data
3155
+ * is unloaded
3156
+ */
3157
+ _finalized = false;
3101
3158
  get finalized() {
3102
3159
  return this._finalized;
3103
3160
  }
@@ -3107,9 +3164,6 @@ var NodeIndexDocument = class {
3107
3164
  * @param converter - converter instance
3108
3165
  */
3109
3166
  constructor(id, converter) {
3110
- this.data = null;
3111
- this.children = [];
3112
- this._finalized = false;
3113
3167
  this.inPageId = id;
3114
3168
  this.id = id === 0 ? "root" : id.toString();
3115
3169
  this.converter = converter;
@@ -3256,7 +3310,7 @@ var NodeIndexDocument = class {
3256
3310
  * @param converter - I3SConverter instance
3257
3311
  * @returns NodeIndexDocument instance
3258
3312
  */
3259
- static async createNode(parentNode, boundingVolumes, lodSelection, nodeInPage, resources, converter) {
3313
+ static async createNode({ parentNode, boundingVolumes, lodSelection, nodeInPage, resources, converter }) {
3260
3314
  const data = await NodeIndexDocument.createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources);
3261
3315
  const node = await new NodeIndexDocument(nodeInPage.index, converter).addData(data);
3262
3316
  return node;
@@ -3297,6 +3351,7 @@ var NodeIndexDocument = class {
3297
3351
  * @param resources.attributes - feature attributes
3298
3352
  * @return 3DNodeIndexDocument https://github.com/Esri/i3s-spec/blob/master/docs/1.7/3DNodeIndexDocument.cmn.md object
3299
3353
  */
3354
+ // eslint-disable-next-line complexity
3300
3355
  static async createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources) {
3301
3356
  var _a2, _b, _c, _d, _e;
3302
3357
  const nodeId = nodeInPage.index;
@@ -3428,7 +3483,7 @@ var import_core10 = require("@math.gl/core");
3428
3483
  var import_tiles = require("@loaders.gl/tiles");
3429
3484
 
3430
3485
  // dist/i3s-converter/helpers/tileset-traversal.js
3431
- var traverseDatasetWith = async (tile, traversalProps, processTile, postprocessTile, maxDepth, level = 0) => {
3486
+ var traverseDatasetWith = async ({ tile, traversalProps, processTile, postprocessTile, maxDepth, level = 0 }) => {
3432
3487
  if (maxDepth && level > maxDepth) {
3433
3488
  return;
3434
3489
  }
@@ -3436,9 +3491,18 @@ var traverseDatasetWith = async (tile, traversalProps, processTile, postprocessT
3436
3491
  const newTraversalProps = await processTile(tile, traversalProps);
3437
3492
  processResults.push(newTraversalProps);
3438
3493
  for (const childTile of tile.children) {
3439
- await traverseDatasetWith(childTile, newTraversalProps, processTile, postprocessTile, maxDepth, level + 1);
3494
+ await traverseDatasetWith({
3495
+ tile: childTile,
3496
+ traversalProps: newTraversalProps,
3497
+ processTile,
3498
+ postprocessTile,
3499
+ maxDepth,
3500
+ level: level + 1
3501
+ });
3502
+ }
3503
+ if (postprocessTile) {
3504
+ await postprocessTile(processResults, traversalProps);
3440
3505
  }
3441
- postprocessTile && await postprocessTile(processResults, traversalProps);
3442
3506
  };
3443
3507
 
3444
3508
  // dist/i3s-converter/helpers/preprocess-3d-tiles.js
@@ -3526,15 +3590,29 @@ var mergePreprocessData = (object1, object2) => {
3526
3590
  var import_process2 = __toESM(require("process"), 1);
3527
3591
  var THRESHOLD_DEFAULT = 0.2;
3528
3592
  var Progress = class {
3593
+ /** Total amount of work, e.g. number of files to save or number of bytes to send */
3594
+ _stepsTotal = 0;
3595
+ /** Amount of work already done */
3596
+ _stepsDone = 0;
3597
+ /** Time in milli-seconds when the process started */
3598
+ startTime = 0;
3599
+ /** Time in milli-seconds when the process stopped */
3600
+ stopTime = 0;
3601
+ /** Time in milli-seconds when stepsDone was updated */
3602
+ timeOfUpdatingStepsDone = 0;
3603
+ /** Time in milli-seconds spent for performing one step*/
3604
+ milliSecForOneStep = 0;
3605
+ trust = false;
3606
+ /**
3607
+ * The number of digits to appear after decimal point in the string representation of the count of steps already done.
3608
+ * It's calculated based on the total count of steps.
3609
+ */
3610
+ numberOfDigitsInPercentage = 0;
3611
+ /** Defines a threshold that is used to check if the process velocity can be consifered trust. */
3612
+ threshold;
3613
+ /** Function that is used to get the time stamp */
3614
+ getTime;
3529
3615
  constructor(options = {}) {
3530
- this._stepsTotal = 0;
3531
- this._stepsDone = 0;
3532
- this.startTime = 0;
3533
- this.stopTime = 0;
3534
- this.timeOfUpdatingStepsDone = 0;
3535
- this.milliSecForOneStep = 0;
3536
- this.trust = false;
3537
- this.numberOfDigitsInPercentage = 0;
3538
3616
  this.getTime = options.getTime || import_process2.default.hrtime.bigint;
3539
3617
  this.threshold = options.threshold || THRESHOLD_DEFAULT;
3540
3618
  }
@@ -3948,8 +4026,19 @@ var dumpJsonSchema = {
3948
4026
 
3949
4027
  // dist/lib/utils/conversion-dump.js
3950
4028
  var ConversionDump = class {
4029
+ /** Restored/resumed dump indicator */
4030
+ restored = false;
4031
+ /** Conversion options */
4032
+ options;
4033
+ /** Tiles conversion progress status map */
4034
+ tilesConverted;
4035
+ /** Textures formats definitions */
4036
+ textureSetDefinitions;
4037
+ /** Attributes Metadata */
4038
+ attributeMetadataInfo;
4039
+ /** Array of materials definitions */
4040
+ materialDefinitions;
3951
4041
  constructor() {
3952
- this.restored = false;
3953
4042
  this.tilesConverted = {};
3954
4043
  }
3955
4044
  /**
@@ -4113,27 +4202,38 @@ var ConversionDump = class {
4113
4202
  for (let i = 0; i < changedRecords.length; i++) {
4114
4203
  if (changedRecords[i] && "value" in writeResults[i]) {
4115
4204
  const { sourceId, resourceType, outputId } = changedRecords[i];
4116
- if (!sourceId || !resourceType || !outputId)
4117
- continue;
4118
- for (const node of this.tilesConverted[sourceId].nodes) {
4119
- if (node.nodeId === outputId && node.progress) {
4120
- node.progress[resourceType] = true;
4121
- let done = false;
4122
- for (const key in node.progress) {
4123
- done = node.progress[key];
4124
- if (!done)
4125
- break;
4126
- }
4127
- node.done = done;
4128
- if (node.done) {
4129
- delete node.progress;
4130
- }
4205
+ this.updateNodes(sourceId, outputId, resourceType);
4206
+ }
4207
+ }
4208
+ await this.updateDumpFile();
4209
+ }
4210
+ /**
4211
+ * Update done status for a node
4212
+ * @param sourceId - source resource Id
4213
+ * @param outputId - output node/tile Id
4214
+ * @param resourceType - type of resource
4215
+ * @returns void
4216
+ */
4217
+ updateNodes(sourceId, outputId, resourceType) {
4218
+ if (!sourceId || !resourceType || !outputId) {
4219
+ return;
4220
+ }
4221
+ for (const node of this.tilesConverted[sourceId].nodes) {
4222
+ if (node.nodeId === outputId && node.progress) {
4223
+ node.progress[resourceType] = true;
4224
+ let done = false;
4225
+ for (const key in node.progress) {
4226
+ done = node.progress[key];
4227
+ if (!done)
4131
4228
  break;
4132
- }
4133
4229
  }
4230
+ node.done = done;
4231
+ if (node.done) {
4232
+ delete node.progress;
4233
+ }
4234
+ break;
4134
4235
  }
4135
4236
  }
4136
- await this.updateDumpFile();
4137
4237
  }
4138
4238
  /**
4139
4239
  * Update 3d-tiles-converter dump file
@@ -4184,35 +4284,52 @@ var REFRESH_TOKEN_TIMEOUT = 1800;
4184
4284
  var CESIUM_DATASET_PREFIX = "https://";
4185
4285
  var PROGRESS_PHASE1_COUNT = "phase1-count";
4186
4286
  var I3SConverter = class {
4187
- constructor() {
4188
- this.boundingVolumeWarnings = [];
4189
- this.conversionStartTime = [0, 0];
4190
- this.refreshTokenTime = [0, 0];
4191
- this.sourceTileset = null;
4192
- this.loadOptions = {
4193
- _nodeWorkers: true,
4194
- reuseWorkers: true,
4195
- useLocalLibraries: true,
4196
- basis: {
4197
- format: "rgba32",
4198
- // We need to load local fs workers because nodejs can't load workers from the Internet
4199
- workerUrl: "./modules/textures/dist/basis-worker-node.js"
4200
- },
4287
+ attributeMetadataInfo;
4288
+ nodePages;
4289
+ options;
4290
+ layers0Path;
4291
+ materialMap;
4292
+ materialDefinitions;
4293
+ geometryMap;
4294
+ geometryConfigs;
4295
+ vertexCounter;
4296
+ layers0;
4297
+ featuresHashArray;
4298
+ refinementCounter;
4299
+ validate;
4300
+ boundingVolumeWarnings = [];
4301
+ conversionStartTime = [0, 0];
4302
+ refreshTokenTime = [0, 0];
4303
+ sourceTileset = null;
4304
+ loadOptions = {
4305
+ _nodeWorkers: true,
4306
+ reuseWorkers: true,
4307
+ useLocalLibraries: true,
4308
+ basis: {
4309
+ format: "rgba32",
4201
4310
  // We need to load local fs workers because nodejs can't load workers from the Internet
4202
- draco: { workerUrl: "./modules/draco/dist/draco-worker-node.js" },
4203
- fetch: {},
4204
- modules: {}
4205
- };
4206
- this.geoidHeightModel = null;
4207
- this.Loader = import_d_tiles2.Tiles3DLoader;
4208
- this.workerSource = {};
4209
- this.writeQueue = new WriteQueue(new ConversionDump());
4210
- this.compressList = null;
4211
- this.preprocessData = {
4212
- meshTopologyTypes: /* @__PURE__ */ new Set(),
4213
- metadataClasses: /* @__PURE__ */ new Set()
4214
- };
4215
- this.progresses = {};
4311
+ workerUrl: "./modules/textures/dist/basis-worker-node.js"
4312
+ },
4313
+ // We need to load local fs workers because nodejs can't load workers from the Internet
4314
+ draco: { workerUrl: "./modules/draco/dist/draco-worker-node.js" },
4315
+ fetch: {},
4316
+ modules: {}
4317
+ };
4318
+ geoidHeightModel = null;
4319
+ Loader = import_d_tiles2.Tiles3DLoader;
4320
+ generateTextures;
4321
+ generateBoundingVolumes;
4322
+ layersHasTexture;
4323
+ workerSource = {};
4324
+ writeQueue = new WriteQueue(new ConversionDump());
4325
+ compressList = null;
4326
+ preprocessData = {
4327
+ meshTopologyTypes: /* @__PURE__ */ new Set(),
4328
+ metadataClasses: /* @__PURE__ */ new Set()
4329
+ };
4330
+ progresses = {};
4331
+ conversionDump;
4332
+ constructor() {
4216
4333
  this.attributeMetadataInfo = new AttributeMetadataInfo();
4217
4334
  this.nodePages = new NodePages(writeFile, HARDCODED_NODES_PER_PAGE, this);
4218
4335
  this.options = {};
@@ -4252,6 +4369,7 @@ var I3SConverter = class {
4252
4369
  * @param options.generateBoundingVolumes - generate bounding volumes from vertices coordinates instead of source tiles bounding volumes
4253
4370
  * @param options.instantNodeWriting - Keep created 3DNodeIndexDocument files on disk instead of memory. This option reduce memory usage but decelerates conversion speed
4254
4371
  */
4372
+ // eslint-disable-next-line max-statements, complexity
4255
4373
  async convert(options) {
4256
4374
  if (import_core9.isBrowser) {
4257
4375
  console.log(BROWSER_ERROR_MESSAGE);
@@ -4321,12 +4439,18 @@ var I3SConverter = class {
4321
4439
  * @returns true - the conversion is possible, false - the tileset's content is not supported
4322
4440
  */
4323
4441
  async preprocessConversion() {
4324
- console.log(`Analyze source tileset`);
4442
+ console.log("Analyze source tileset");
4325
4443
  const sourceRootTile = this.sourceTileset.root;
4326
- await traverseDatasetWith(sourceRootTile, null, this.analyzeTile.bind(this), void 0, this.options.maxDepth);
4444
+ await traverseDatasetWith({
4445
+ tile: sourceRootTile,
4446
+ traversalProps: null,
4447
+ processTile: this.analyzeTile.bind(this),
4448
+ postprocessTile: void 0,
4449
+ maxDepth: this.options.maxDepth
4450
+ });
4327
4451
  const { meshTopologyTypes, metadataClasses } = this.preprocessData;
4328
- console.log(`------------------------------------------------`);
4329
- console.log(`Preprocess results:`);
4452
+ console.log("------------------------------------------------");
4453
+ console.log("Preprocess results:");
4330
4454
  console.log(`Tile count: ${this.progresses[PROGRESS_PHASE1_COUNT].stepsTotal}`);
4331
4455
  console.log(`glTF mesh topology types: ${Array.from(meshTopologyTypes).join(", ")}`);
4332
4456
  if (metadataClasses.size) {
@@ -4336,10 +4460,10 @@ var I3SConverter = class {
4336
4460
  }
4337
4461
  if (!meshTopologyTypes.has(GLTFPrimitiveModeString.TRIANGLES) && !meshTopologyTypes.has(GLTFPrimitiveModeString.TRIANGLE_STRIP)) {
4338
4462
  console.log("The tileset is of unsupported mesh topology types. The conversion will be interrupted.");
4339
- console.log(`------------------------------------------------`);
4463
+ console.log("------------------------------------------------");
4340
4464
  return false;
4341
4465
  }
4342
- console.log(`------------------------------------------------`);
4466
+ console.log("------------------------------------------------");
4343
4467
  return true;
4344
4468
  }
4345
4469
  /**
@@ -4394,7 +4518,7 @@ var I3SConverter = class {
4394
4518
  console.log(`${result.metadataClass} has been selected`);
4395
4519
  } else {
4396
4520
  console.log(`A feature metadata class has not been selected. Start the converter with option "--metadata-class". For example, "npx tile-converter ... --metadata-class ${Array.from(metadataClasses)[0]}"`);
4397
- console.log(`------------------------------------------------`);
4521
+ console.log("------------------------------------------------");
4398
4522
  return false;
4399
4523
  }
4400
4524
  }
@@ -4405,6 +4529,7 @@ var I3SConverter = class {
4405
4529
  * @param outputPath - path to save output data
4406
4530
  * @param tilesetName - new tileset path
4407
4531
  */
4532
+ // eslint-disable-next-line max-statements, complexity
4408
4533
  async _createAndSaveTileset(outputPath, tilesetName) {
4409
4534
  var _a2, _b, _c;
4410
4535
  const tilesetPath = (0, import_path7.join)(`${outputPath}`, `${tilesetName}`);
@@ -4451,10 +4576,16 @@ var I3SConverter = class {
4451
4576
  });
4452
4577
  this.progresses[PROGRESS_PHASE1_COUNT].startMonitoring();
4453
4578
  const rootNode = await NodeIndexDocument.createRootNode(boundingVolumes, this);
4454
- await traverseDatasetWith(sourceRootTile, {
4455
- transform: new import_core10.Matrix4(sourceRootTile.transform),
4456
- parentNodes: [rootNode]
4457
- }, this.convertTile.bind(this), this.finalizeTile.bind(this), this.options.maxDepth);
4579
+ await traverseDatasetWith({
4580
+ tile: sourceRootTile,
4581
+ traversalProps: {
4582
+ transform: new import_core10.Matrix4(sourceRootTile.transform),
4583
+ parentNodes: [rootNode]
4584
+ },
4585
+ processTile: this.convertTile.bind(this),
4586
+ postprocessTile: this.finalizeTile.bind(this),
4587
+ maxDepth: this.options.maxDepth
4588
+ });
4458
4589
  this.progresses[PROGRESS_PHASE1_COUNT].stopMonitoring();
4459
4590
  console.log(`[finalizing conversion]`);
4460
4591
  this.layers0.attributeStorageInfo = this.attributeMetadataInfo.attributeStorageInfo;
@@ -4558,6 +4689,7 @@ var I3SConverter = class {
4558
4689
  * @param traversalProps - traversal properties calculated recursively
4559
4690
  * @returns - traversal properties for the child tiles
4560
4691
  */
4692
+ // eslint-disable-next-line max-statements
4561
4693
  async convertTile(sourceTile, traversalProps) {
4562
4694
  const isTileset = isNestedTileset(sourceTile);
4563
4695
  if (isTileset || sourceTile.type === "empty") {
@@ -4659,7 +4791,7 @@ var I3SConverter = class {
4659
4791
  await this._updateTilesetOptions();
4660
4792
  if (this.conversionDump.restored && sourceTile.id && this.conversionDump.isFileConversionComplete(sourceTile.id)) {
4661
4793
  const sourceBoundingVolume = (0, import_tiles.createBoundingVolume)(sourceTile.boundingVolume, transformationMatrix, null);
4662
- let boundingVolumes = createBoundingVolumes(sourceBoundingVolume, this.geoidHeightModel);
4794
+ const boundingVolumes = createBoundingVolumes(sourceBoundingVolume, this.geoidHeightModel);
4663
4795
  const nodes = [];
4664
4796
  for (const convertedNode of this.conversionDump.tilesConverted[sourceTile.id].nodes) {
4665
4797
  const { node } = await this._generateNodeIndexDocument(boundingVolumes, {
@@ -4682,6 +4814,7 @@ var I3SConverter = class {
4682
4814
  * transform of all parent tiles and transform of the current tile
4683
4815
  * @param level - tree level
4684
4816
  */
4817
+ // eslint-disable-next-line max-statements
4685
4818
  async _createNode(parentNode, sourceTile, transformationMatrix) {
4686
4819
  var _a2;
4687
4820
  this._checkAddRefinementTypeForTile(sourceTile);
@@ -4693,7 +4826,7 @@ var I3SConverter = class {
4693
4826
  console.log(`[warning]: Failed to load ${sourceTile.contentUrl}`);
4694
4827
  }
4695
4828
  const sourceBoundingVolume = (0, import_tiles.createBoundingVolume)(sourceTile.boundingVolume, transformationMatrix, null);
4696
- let boundingVolumes = createBoundingVolumes(sourceBoundingVolume, this.geoidHeightModel);
4829
+ const boundingVolumes = createBoundingVolumes(sourceBoundingVolume, this.geoidHeightModel);
4697
4830
  const propertyTable = getPropertyTable(tileContent, this.options.metadataClass);
4698
4831
  this.createAttributeStorageInfo(tileContent, propertyTable);
4699
4832
  this.conversionDump.attributeMetadataInfo = {
@@ -4701,7 +4834,14 @@ var I3SConverter = class {
4701
4834
  fields: this.attributeMetadataInfo.fields,
4702
4835
  popupInfo: this.attributeMetadataInfo.popupInfo
4703
4836
  };
4704
- const resourcesData = await this._convertResources(sourceTile, transformationMatrix, sourceBoundingVolume, tileContent, parentNode.inPageId, propertyTable);
4837
+ const resourcesData = await this._convertResources({
4838
+ sourceTile,
4839
+ transformationMatrix,
4840
+ boundingVolume: sourceBoundingVolume,
4841
+ tileContent,
4842
+ parentId: parentNode.inPageId,
4843
+ propertyTable
4844
+ });
4705
4845
  const nodes = [];
4706
4846
  const nodeIds = [];
4707
4847
  const nodesInPage = [];
@@ -4759,7 +4899,7 @@ var I3SConverter = class {
4759
4899
  * @param propertyTable - batch table from b3dm / feature properties from EXT_FEATURE_METADATA, EXT_MESH_FEATURES or EXT_STRUCTURAL_METADATA
4760
4900
  * @returns - converted node resources
4761
4901
  */
4762
- async _convertResources(sourceTile, transformationMatrix, boundingVolume, tileContent, parentId, propertyTable) {
4902
+ async _convertResources({ sourceTile, transformationMatrix, boundingVolume, tileContent, parentId, propertyTable }) {
4763
4903
  if (!this.isContentSupported(sourceTile) || !tileContent) {
4764
4904
  return null;
4765
4905
  }
@@ -4768,7 +4908,21 @@ var I3SConverter = class {
4768
4908
  halfSize: [],
4769
4909
  quaternion: []
4770
4910
  };
4771
- const resourcesData = await convertB3dmToI3sGeometry(tileContent, transformationMatrix, boundingVolume, async () => (await this.nodePages.push({ index: 0, obb: draftObb }, parentId)).index, propertyTable, this.featuresHashArray, this.attributeMetadataInfo.attributeStorageInfo, this.options.draco, this.generateBoundingVolumes, this.options.mergeMaterials, this.geoidHeightModel, this.loadOptions.modules, this.options.metadataClass);
4911
+ const resourcesData = await convertB3dmToI3sGeometry({
4912
+ tileContent,
4913
+ tileTransform: transformationMatrix,
4914
+ tileBoundingVolume: boundingVolume,
4915
+ addNodeToNodePage: async () => (await this.nodePages.push({ index: 0, obb: draftObb }, parentId)).index,
4916
+ propertyTable,
4917
+ featuresHashArray: this.featuresHashArray,
4918
+ attributeStorageInfo: this.attributeMetadataInfo.attributeStorageInfo,
4919
+ draco: this.options.draco,
4920
+ generateBoundingVolumes: this.generateBoundingVolumes,
4921
+ shouldMergeMaterials: this.options.mergeMaterials,
4922
+ geoidHeightModel: this.geoidHeightModel,
4923
+ libraries: this.loadOptions.modules,
4924
+ metadataClass: this.options.metadataClass
4925
+ });
4772
4926
  return resourcesData;
4773
4927
  }
4774
4928
  /**
@@ -4786,6 +4940,7 @@ var I3SConverter = class {
4786
4940
  * @param resources.geometry - Uint8Array with geometry attributes
4787
4941
  * @return the node object in node pages
4788
4942
  */
4943
+ // eslint-disable-next-line max-statements, complexity
4789
4944
  async _updateNodeInNodePages(maxScreenThresholdSQ, boundingVolumes, sourceTile, parentId, resources) {
4790
4945
  const { vertexCount, featureCount, geometry, hasUvRegions } = resources;
4791
4946
  const nodeInPage = {
@@ -4808,7 +4963,7 @@ var I3SConverter = class {
4808
4963
  }
4809
4964
  };
4810
4965
  }
4811
- let nodeId = "nodeId" in resources ? resources.nodeId : void 0;
4966
+ const nodeId = "nodeId" in resources ? resources.nodeId : void 0;
4812
4967
  let node;
4813
4968
  if (!nodeId) {
4814
4969
  node = await this.nodePages.push(nodeInPage, parentId);
@@ -4857,8 +5012,22 @@ var I3SConverter = class {
4857
5012
  const { geometry: geometryBuffer, compressedGeometry, texture, sharedResources, attributes } = resources;
4858
5013
  const childPath = (0, import_path7.join)(this.layers0Path, "nodes", nodePath);
4859
5014
  const slpkChildPath = (0, import_path7.join)("nodes", nodePath);
4860
- await this._writeGeometries(geometryBuffer, compressedGeometry, childPath, slpkChildPath, sourceTile.id || "", parseInt(nodePath));
4861
- await this._writeShared(sharedResources, childPath, slpkChildPath, nodePath, sourceTile.id || "", parseInt(nodePath));
5015
+ await this._writeGeometries({
5016
+ geometryBuffer,
5017
+ compressedGeometry,
5018
+ childPath,
5019
+ slpkChildPath,
5020
+ sourceId: sourceTile.id || "",
5021
+ nodeId: parseInt(nodePath)
5022
+ });
5023
+ await this._writeShared({
5024
+ sharedResources,
5025
+ childPath,
5026
+ slpkChildPath,
5027
+ nodePath,
5028
+ sourceId: sourceTile.id || "",
5029
+ nodeId: parseInt(nodePath)
5030
+ });
4862
5031
  await this._writeTexture(texture, childPath, slpkChildPath, sourceTile.id || "", parseInt(nodePath));
4863
5032
  await this._writeAttributes(attributes, childPath, slpkChildPath, sourceTile.id || "", parseInt(nodePath));
4864
5033
  }
@@ -4871,7 +5040,10 @@ var I3SConverter = class {
4871
5040
  * @param sourceId - source filename
4872
5041
  * @param nodeId - nodeId of a converted node for the writing
4873
5042
  */
4874
- async _writeGeometries(geometryBuffer, compressedGeometry, childPath, slpkChildPath, sourceId, nodeId) {
5043
+ async _writeGeometries({ geometryBuffer, compressedGeometry, childPath, slpkChildPath, sourceId, nodeId }) {
5044
+ if (!geometryBuffer) {
5045
+ return;
5046
+ }
4875
5047
  this.conversionDump.updateDoneStatus(sourceId, nodeId, ResourceType.GEOMETRY, false);
4876
5048
  if (this.options.slpk) {
4877
5049
  const slpkGeometryPath = (0, import_path7.join)(childPath, "geometries");
@@ -4891,7 +5063,7 @@ var I3SConverter = class {
4891
5063
  writePromise: () => writeFile(geometryPath, geometryBuffer, "index.bin")
4892
5064
  });
4893
5065
  }
4894
- if (this.options.draco) {
5066
+ if (this.options.draco && compressedGeometry) {
4895
5067
  this.conversionDump.updateDoneStatus(sourceId, nodeId, ResourceType.DRACO_GEOMETRY, false);
4896
5068
  if (this.options.slpk) {
4897
5069
  const slpkCompressedGeometryPath = (0, import_path7.join)(childPath, "geometries");
@@ -4922,7 +5094,7 @@ var I3SConverter = class {
4922
5094
  * @param sourceId - source filename
4923
5095
  * @param nodeId - nodeId of a converted node for the writing
4924
5096
  */
4925
- async _writeShared(sharedResources, childPath, slpkChildPath, nodePath, sourceId, nodeId) {
5097
+ async _writeShared({ sharedResources, childPath, slpkChildPath, nodePath, sourceId, nodeId }) {
4926
5098
  if (!sharedResources) {
4927
5099
  return;
4928
5100
  }
@@ -4957,6 +5129,7 @@ var I3SConverter = class {
4957
5129
  * @param sourceId - source filename
4958
5130
  * @param nodeId - nodeId of a converted node for the writing
4959
5131
  */
5132
+ // eslint-disable-next-line max-statements
4960
5133
  async _writeTexture(texture, childPath, slpkChildPath, sourceId, nodeId) {
4961
5134
  if (texture) {
4962
5135
  const format = this._getFormatByMimeType(texture == null ? void 0 : texture.mimeType);
@@ -4967,7 +5140,15 @@ var I3SConverter = class {
4967
5140
  case "png": {
4968
5141
  formats.push({ name: "0", format });
4969
5142
  this.conversionDump.updateDoneStatus(sourceId, nodeId, `${ResourceType.TEXTURE}/${format}`, false);
4970
- await this.writeTextureFile(textureData, "0", format, childPath, slpkChildPath, sourceId, nodeId);
5143
+ await this.writeTextureFile({
5144
+ textureData,
5145
+ name: "0",
5146
+ format,
5147
+ childPath,
5148
+ slpkChildPath,
5149
+ sourceId,
5150
+ nodeId
5151
+ });
4971
5152
  if (this.generateTextures) {
4972
5153
  formats.push({ name: "1", format: "ktx2" });
4973
5154
  const copyArrayBuffer = texture.image.data.subarray();
@@ -4988,21 +5169,47 @@ var I3SConverter = class {
4988
5169
  }
4989
5170
  );
4990
5171
  this.conversionDump.updateDoneStatus(sourceId, nodeId, `${ResourceType.TEXTURE}/ktx2`, false);
4991
- await this.writeTextureFile(ktx2TextureData, "1", "ktx2", childPath, slpkChildPath, sourceId, nodeId);
5172
+ await this.writeTextureFile({
5173
+ textureData: ktx2TextureData,
5174
+ name: "1",
5175
+ format: "ktx2",
5176
+ childPath,
5177
+ slpkChildPath,
5178
+ sourceId,
5179
+ nodeId
5180
+ });
4992
5181
  }
4993
5182
  break;
4994
5183
  }
4995
5184
  case "ktx2": {
4996
5185
  formats.push({ name: "1", format });
4997
5186
  this.conversionDump.updateDoneStatus(sourceId, nodeId, `${ResourceType.TEXTURE}/${format}`, false);
4998
- await this.writeTextureFile(textureData, "1", format, childPath, slpkChildPath, sourceId, nodeId);
5187
+ await this.writeTextureFile({
5188
+ textureData,
5189
+ name: "1",
5190
+ format,
5191
+ childPath,
5192
+ slpkChildPath,
5193
+ sourceId,
5194
+ nodeId
5195
+ });
4999
5196
  if (this.generateTextures) {
5000
5197
  formats.push({ name: "0", format: "jpg" });
5001
5198
  const decodedFromKTX2TextureData = (0, import_core9.encode)(texture.image.data[0], import_images.ImageWriter);
5002
5199
  this.conversionDump.updateDoneStatus(sourceId, nodeId, `${ResourceType.TEXTURE}/jpg`, false);
5003
- await this.writeTextureFile(decodedFromKTX2TextureData, "0", "jpg", childPath, slpkChildPath, sourceId, nodeId);
5200
+ await this.writeTextureFile({
5201
+ textureData: decodedFromKTX2TextureData,
5202
+ name: "0",
5203
+ format: "jpg",
5204
+ childPath,
5205
+ slpkChildPath,
5206
+ sourceId,
5207
+ nodeId
5208
+ });
5004
5209
  }
5210
+ break;
5005
5211
  }
5212
+ default:
5006
5213
  }
5007
5214
  if (!this.layers0.textureSetDefinitions.length) {
5008
5215
  this.layers0.textureSetDefinitions.push({ formats });
@@ -5023,7 +5230,7 @@ var I3SConverter = class {
5023
5230
  * @param sourceId
5024
5231
  * @param nodeId
5025
5232
  */
5026
- async writeTextureFile(textureData, name, format, childPath, slpkChildPath, sourceId, nodeId) {
5233
+ async writeTextureFile({ textureData, name, format, childPath, slpkChildPath, sourceId, nodeId }) {
5027
5234
  if (this.options.slpk) {
5028
5235
  const slpkTexturePath = (0, import_path7.join)(childPath, "textures");
5029
5236
  const compress = false;
@@ -5155,13 +5362,13 @@ var I3SConverter = class {
5155
5362
  const filesSize = await calculateFilesSize(params);
5156
5363
  const diff = import_process4.default.hrtime(this.conversionStartTime);
5157
5364
  const conversionTime = timeConverter(diff);
5158
- console.log(`------------------------------------------------`);
5365
+ console.log("------------------------------------------------");
5159
5366
  console.log(`Finishing conversion of ${_3D_TILES}`);
5160
5367
  console.log(`Total conversion time: ${conversionTime}`);
5161
- console.log(`Vertex count: `, this.vertexCounter);
5162
- console.log(`File(s) size: `, filesSize, " bytes");
5163
- console.log(`Percentage of tiles with "ADD" refinement type:`, addRefinementPercentage, "%");
5164
- console.log(`------------------------------------------------`);
5368
+ console.log("Vertex count: ", this.vertexCounter);
5369
+ console.log("File(s) size: ", filesSize, " bytes");
5370
+ console.log('Percentage of tiles with "ADD" refinement type:', addRefinementPercentage, "%");
5371
+ console.log("------------------------------------------------");
5165
5372
  }
5166
5373
  /**
5167
5374
  * Fetch preload options for ION tileset
@@ -5199,7 +5406,7 @@ var I3SConverter = class {
5199
5406
  * @param tile
5200
5407
  */
5201
5408
  _checkAddRefinementTypeForTile(tile) {
5202
- const ADD_TILE_REFINEMENT = 1;
5409
+ const ADD_TILE_REFINEMENT = import_tiles.TILE_REFINEMENT.ADD;
5203
5410
  if (tile.refine === ADD_TILE_REFINEMENT) {
5204
5411
  this.refinementCounter.tilesWithAddRefineCount += 1;
5205
5412
  console.warn('This tile uses "ADD" type of refinement');
@@ -5327,6 +5534,9 @@ var KHR_MATERIALS_UNLIT = "KHR_materials_unlit";
5327
5534
  var METALLIC_FACTOR_DEFAULT = 1;
5328
5535
  var ROUGHNESS_FACTOR_DEFAULT = 1;
5329
5536
  var B3dmConverter = class {
5537
+ // @ts-expect-error
5538
+ rtcCenter;
5539
+ i3sTile;
5330
5540
  /**
5331
5541
  * The starter of content conversion
5332
5542
  * @param i3sTile - Tile3D instance for I3S node
@@ -5347,6 +5557,7 @@ var B3dmConverter = class {
5347
5557
  * @param i3sTile - Tile3D instance for I3S node
5348
5558
  * @returns - encoded glb content
5349
5559
  */
5560
+ // eslint-disable-next-line max-statements
5350
5561
  async buildGLTF(i3sAttributesData, featureAttributes) {
5351
5562
  const { tileContent, textureFormat, box } = i3sAttributesData;
5352
5563
  const { material, attributes, indices: originalIndices, modelMatrix } = tileContent;
@@ -5613,21 +5824,18 @@ var loadI3SContent = async (sourceTileset, sourceTile, tilesetLoadOptions, slpkF
5613
5824
  };
5614
5825
  async function openSLPK(url) {
5615
5826
  const slpkUrlParts = url.split(".slpk");
5616
- const { slpkFileName } = getSlpkUrlParts(url) || {};
5617
- if (slpkFileName) {
5618
- const slpkFileName2 = `${slpkUrlParts[0]}.slpk`;
5619
- const fileProvider = new import_loader_utils5.FileHandleFile(slpkFileName2);
5620
- const archive = await (0, import_i3s.parseSLPKArchive)(fileProvider, void 0, slpkFileName2);
5827
+ if (slpkUrlParts.length === 2) {
5828
+ const slpkFileName = `${slpkUrlParts[0]}.slpk`;
5829
+ const fileProvider = new import_loader_utils5.FileHandleFile(slpkFileName);
5830
+ const archive = await (0, import_i3s.parseSLPKArchive)(fileProvider, void 0, slpkFileName);
5621
5831
  const fileSystem = new import_zip3.ZipFileSystem(archive);
5622
5832
  return fileSystem;
5623
5833
  }
5624
5834
  return null;
5625
5835
  }
5626
5836
  async function loadFromArchive2(url, loader, loadOptions, fileSystem) {
5627
- const slpkUrlParts = getSlpkUrlParts(url);
5628
- if (fileSystem !== null && slpkUrlParts !== null) {
5629
- const { internalFileName } = slpkUrlParts;
5630
- const content = await (0, import_core14.load)(internalFileName, loader, {
5837
+ if (fileSystem !== null) {
5838
+ const content = await (0, import_core14.load)(url, loader, {
5631
5839
  ...loadOptions,
5632
5840
  fetch: fileSystem.fetch.bind(fileSystem)
5633
5841
  });
@@ -5635,18 +5843,6 @@ async function loadFromArchive2(url, loader, loadOptions, fileSystem) {
5635
5843
  }
5636
5844
  return await (0, import_core14.load)(url, loader, loadOptions);
5637
5845
  }
5638
- function getSlpkUrlParts(url) {
5639
- const slpkUrlParts = url.split(".slpk");
5640
- let result;
5641
- if (slpkUrlParts.length === 1) {
5642
- result = null;
5643
- } else if (slpkUrlParts.length === 2) {
5644
- result = { slpkFileName: `${slpkUrlParts[0]}.slpk`, internalFileName: slpkUrlParts[1].slice(1) };
5645
- } else {
5646
- throw new Error("Unexpected URL format");
5647
- }
5648
- return result;
5649
- }
5650
5846
  async function getNodeCount(fileSystem) {
5651
5847
  if (!(fileSystem == null ? void 0 : fileSystem.fileProvider)) {
5652
5848
  return 0;
@@ -5665,20 +5861,29 @@ async function getNodeCount(fileSystem) {
5665
5861
  // dist/3d-tiles-converter/3d-tiles-converter.js
5666
5862
  var I3S = "I3S";
5667
5863
  var Tiles3DConverter = class {
5864
+ options;
5865
+ tilesetPath;
5866
+ vertexCounter;
5867
+ conversionStartTime;
5868
+ geoidHeightModel;
5869
+ sourceTileset;
5870
+ attributeStorageInfo;
5871
+ workerSource = {};
5872
+ slpkFilesystem = null;
5873
+ loaderOptions = {
5874
+ _nodeWorkers: true,
5875
+ reuseWorkers: true,
5876
+ // TODO: converter freezes in the end because of i3s-content-worker
5877
+ worker: false,
5878
+ i3s: { coordinateSystem: import_i3s2.COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false },
5879
+ // We need to load local fs workers because nodejs can't load workers from the Internet
5880
+ "i3s-content": {
5881
+ workerUrl: "./modules/i3s/dist/i3s-content-worker-node.js"
5882
+ }
5883
+ };
5884
+ conversionDump;
5885
+ progress;
5668
5886
  constructor() {
5669
- this.workerSource = {};
5670
- this.slpkFilesystem = null;
5671
- this.loaderOptions = {
5672
- _nodeWorkers: true,
5673
- reuseWorkers: true,
5674
- // TODO: converter freezes in the end because of i3s-content-worker
5675
- worker: false,
5676
- i3s: { coordinateSystem: import_i3s2.COORDINATE_SYSTEM.LNGLAT_OFFSETS, decodeTextures: false },
5677
- // We need to load local fs workers because nodejs can't load workers from the Internet
5678
- "i3s-content": {
5679
- workerUrl: "./modules/i3s/dist/i3s-content-worker-node.js"
5680
- }
5681
- };
5682
5887
  this.options = {};
5683
5888
  this.tilesetPath = "";
5684
5889
  this.vertexCounter = 0;
@@ -5699,6 +5904,7 @@ var Tiles3DConverter = class {
5699
5904
  * @param options.egmFilePath location of *.pgm file to convert heights from ellipsoidal to gravity-related format
5700
5905
  * @param options.maxDepth The max tree depth of conversion
5701
5906
  */
5907
+ // eslint-disable-next-line complexity, max-statements
5702
5908
  async convert(options) {
5703
5909
  var _a2;
5704
5910
  if (import_core15.isBrowser) {
@@ -5716,7 +5922,7 @@ var Tiles3DConverter = class {
5716
5922
  if (analyze || this.slpkFilesystem) {
5717
5923
  preprocessResult = await this.preprocessConversion();
5718
5924
  if (!preprocessResult || analyze) {
5719
- return;
5925
+ return void 0;
5720
5926
  }
5721
5927
  }
5722
5928
  this.progress.startMonitoring();
@@ -5726,7 +5932,7 @@ var Tiles3DConverter = class {
5726
5932
  i3s: { ...this.loaderOptions.i3s, isTileset: true }
5727
5933
  }, this.slpkFilesystem);
5728
5934
  if (!this.sourceTileset) {
5729
- return;
5935
+ return void 0;
5730
5936
  }
5731
5937
  const rootNode = (_a2 = this.sourceTileset) == null ? void 0 : _a2.root;
5732
5938
  if (!rootNode.obb) {
@@ -5772,28 +5978,29 @@ var Tiles3DConverter = class {
5772
5978
  }
5773
5979
  const workerFarm = import_worker_utils2.WorkerFarm.getWorkerFarm({});
5774
5980
  workerFarm.destroy();
5981
+ return void 0;
5775
5982
  }
5776
5983
  /**
5777
5984
  * Preprocess stage of the tile converter. Calculate number of nodes
5778
5985
  * @returns true - the conversion is possible, false - the tileset's content is not supported
5779
5986
  */
5780
5987
  async preprocessConversion() {
5781
- console.log(`Analyze source layer`);
5988
+ console.log("Analyze source layer");
5782
5989
  const nodesCount = await getNodeCount(this.slpkFilesystem);
5783
5990
  this.progress.stepsTotal = nodesCount;
5784
- console.log(`------------------------------------------------`);
5785
- console.log(`Preprocess results:`);
5991
+ console.log("------------------------------------------------");
5992
+ console.log("Preprocess results:");
5786
5993
  if (this.slpkFilesystem) {
5787
5994
  console.log(`Node count: ${nodesCount}`);
5788
5995
  if (nodesCount === 0) {
5789
5996
  console.log("Node count is 0. The conversion will be interrupted.");
5790
- console.log(`------------------------------------------------`);
5997
+ console.log("------------------------------------------------");
5791
5998
  return false;
5792
5999
  }
5793
6000
  } else {
5794
- console.log(`Node count cannot be calculated for the remote dataset`);
6001
+ console.log("Node count cannot be calculated for the remote dataset");
5795
6002
  }
5796
- console.log(`------------------------------------------------`);
6003
+ console.log("------------------------------------------------");
5797
6004
  return true;
5798
6005
  }
5799
6006
  /**
@@ -5803,6 +6010,7 @@ var Tiles3DConverter = class {
5803
6010
  * @param level a current level of a tree depth
5804
6011
  * @param childNodeInfo child node to convert
5805
6012
  */
6013
+ // eslint-disable-next-line complexity, max-statements
5806
6014
  async convertChildNode(parentSourceNode, parentNode, level, childNodeInfo) {
5807
6015
  let nextParentNode = parentNode;
5808
6016
  const sourceChild = await this._loadChildNode(parentSourceNode, childNodeInfo);