@loaders.gl/tile-converter 4.1.1 → 4.2.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts +11 -0
  2. package/dist/3d-tiles-converter/3d-tiles-converter.d.ts.map +1 -1
  3. package/dist/3d-tiles-converter/3d-tiles-converter.js +77 -27
  4. package/dist/3d-tiles-converter/3d-tiles-converter.js.map +1 -1
  5. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts +22 -1
  6. package/dist/3d-tiles-converter/helpers/load-i3s.d.ts.map +1 -1
  7. package/dist/3d-tiles-converter/helpers/load-i3s.js +49 -4
  8. package/dist/3d-tiles-converter/helpers/load-i3s.js.map +1 -1
  9. package/dist/converter-cli.js +2 -1
  10. package/dist/converter-cli.js.map +1 -1
  11. package/dist/converter.min.cjs +137 -130
  12. package/dist/deps-installer/deps-installer.js +1 -1
  13. package/dist/deps-installer/deps-installer.js.map +1 -1
  14. package/dist/i3s-converter/helpers/attribute-metadata-info.d.ts +10 -0
  15. package/dist/i3s-converter/helpers/attribute-metadata-info.d.ts.map +1 -1
  16. package/dist/i3s-converter/helpers/attribute-metadata-info.js +5 -0
  17. package/dist/i3s-converter/helpers/attribute-metadata-info.js.map +1 -1
  18. package/dist/i3s-converter/helpers/load-3d-tiles.d.ts.map +1 -1
  19. package/dist/i3s-converter/helpers/load-3d-tiles.js +22 -2
  20. package/dist/i3s-converter/helpers/load-3d-tiles.js.map +1 -1
  21. package/dist/i3s-converter/helpers/node-index-document.d.ts +2 -1
  22. package/dist/i3s-converter/helpers/node-index-document.d.ts.map +1 -1
  23. package/dist/i3s-converter/helpers/node-index-document.js +6 -8
  24. package/dist/i3s-converter/helpers/node-index-document.js.map +1 -1
  25. package/dist/i3s-converter/i3s-converter.d.ts +18 -0
  26. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  27. package/dist/i3s-converter/i3s-converter.js +121 -24
  28. package/dist/i3s-converter/i3s-converter.js.map +1 -1
  29. package/dist/i3s-server/bin/i3s-server.min.cjs +86 -86
  30. package/dist/index.cjs +792 -101
  31. package/dist/lib/json-schemas/conversion-dump-json-schema.d.ts +463 -0
  32. package/dist/lib/json-schemas/conversion-dump-json-schema.d.ts.map +1 -0
  33. package/dist/lib/json-schemas/conversion-dump-json-schema.js +463 -0
  34. package/dist/lib/json-schemas/conversion-dump-json-schema.js.map +1 -0
  35. package/dist/lib/utils/conversion-dump.d.ts +65 -8
  36. package/dist/lib/utils/conversion-dump.d.ts.map +1 -1
  37. package/dist/lib/utils/conversion-dump.js +98 -18
  38. package/dist/lib/utils/conversion-dump.js.map +1 -1
  39. package/dist/lib/utils/file-utils.d.ts +6 -0
  40. package/dist/lib/utils/file-utils.d.ts.map +1 -1
  41. package/dist/lib/utils/file-utils.js +7 -0
  42. package/dist/lib/utils/file-utils.js.map +1 -1
  43. package/dist/pgm-loader.js +1 -1
  44. package/dist/pgm-loader.js.map +1 -1
  45. package/package.json +15 -14
  46. package/src/3d-tiles-converter/3d-tiles-converter.ts +104 -31
  47. package/src/3d-tiles-converter/helpers/load-i3s.ts +86 -7
  48. package/src/converter-cli.ts +2 -1
  49. package/src/i3s-converter/helpers/attribute-metadata-info.ts +16 -0
  50. package/src/i3s-converter/helpers/load-3d-tiles.ts +52 -2
  51. package/src/i3s-converter/helpers/node-index-document.ts +18 -8
  52. package/src/i3s-converter/i3s-converter.ts +198 -41
  53. package/src/lib/json-schemas/conversion-dump-json-schema.ts +285 -0
  54. package/src/lib/utils/conversion-dump.ts +200 -26
  55. package/src/lib/utils/file-utils.ts +13 -0
@@ -166,7 +166,6 @@ export default class I3SConverter {
166
166
  if (slpk) {
167
167
  this.nodePages.useWriteFunction(writeFileForSlpk);
168
168
  }
169
- await this.conversionDump.createDumpFile(options);
170
169
  try {
171
170
  const preloadOptions = await this._fetchPreloadOptions();
172
171
  let tilesetUrl = inputUrl;
@@ -279,12 +278,34 @@ export default class I3SConverter {
279
278
  async _createAndSaveTileset(outputPath, tilesetName) {
280
279
  var _this$sourceTileset, _this$sourceTileset$r, _this$sourceTileset$r2;
281
280
  const tilesetPath = join(`${outputPath}`, `${tilesetName}`);
281
+ await this.conversionDump.createDump(this.options);
282
+ if (this.conversionDump.restored && this.options.inquirer) {
283
+ const result = await this.options.inquirer.prompt([{
284
+ name: 'resumeConversion',
285
+ type: 'confirm',
286
+ message: 'Dump file of the previous conversion exists, do you want to resume that conversion?'
287
+ }]);
288
+ if (!result.resumeConversion) {
289
+ this.conversionDump.reset();
290
+ }
291
+ }
292
+ this.layers0Path = join(tilesetPath, 'SceneServer', 'layers', '0');
293
+ const removePath = this.conversionDump.restored ? join(this.layers0Path, 'nodepages') : tilesetPath;
282
294
  try {
283
- await removeDir(tilesetPath);
295
+ await removeDir(removePath);
284
296
  } catch (e) {}
285
- this.layers0Path = join(tilesetPath, 'SceneServer', 'layers', '0');
297
+ if (this.conversionDump.restored && this.conversionDump.attributeMetadataInfo) {
298
+ this.attributeMetadataInfo.fromObject(this.conversionDump.attributeMetadataInfo);
299
+ }
286
300
  this.materialDefinitions = [];
287
301
  this.materialMap = new Map();
302
+ if (this.conversionDump.restored && this.conversionDump.materialDefinitions) {
303
+ for (let i = 0; i < this.conversionDump.materialDefinitions.length; i++) {
304
+ const hash = md5(JSON.stringify(this.conversionDump.materialDefinitions[i]));
305
+ this.materialMap.set(hash, i);
306
+ }
307
+ this.materialDefinitions = this.conversionDump.materialDefinitions;
308
+ }
288
309
  const sourceRootTile = this.sourceTileset.root;
289
310
  const sourceBoundingVolume = createBoundingVolume(sourceRootTile.boundingVolume, new Matrix4(sourceRootTile.transform), null);
290
311
  this._formLayers0(tilesetName, sourceBoundingVolume, (_this$sourceTileset = this.sourceTileset) === null || _this$sourceTileset === void 0 ? void 0 : (_this$sourceTileset$r = _this$sourceTileset.root) === null || _this$sourceTileset$r === void 0 ? void 0 : (_this$sourceTileset$r2 = _this$sourceTileset$r.boundingVolume) === null || _this$sourceTileset$r2 === void 0 ? void 0 : _this$sourceTileset$r2.region);
@@ -309,6 +330,9 @@ export default class I3SConverter {
309
330
  if (this.attributeMetadataInfo.attributeStorageInfo.length) {
310
331
  this.layers0.layerType = _3D_OBJECT_LAYER_TYPE;
311
332
  }
333
+ if (this.conversionDump.restored && this.conversionDump.textureSetDefinitions) {
334
+ this.layers0.textureSetDefinitions = this.conversionDump.textureSetDefinitions;
335
+ }
312
336
  this.layers0.materialDefinitions = this.materialDefinitions;
313
337
  this.layers0.geometryDefinitions = transform(this.geometryConfigs.map(config => ({
314
338
  geometryConfig: {
@@ -406,7 +430,13 @@ export default class I3SConverter {
406
430
  transformationMatrix = transformationMatrix.multiplyRight(sourceTile.transform);
407
431
  }
408
432
  const parentNode = parentNodes[0];
409
- const childNodes = await this._createNode(parentNode, sourceTile, transformationMatrix);
433
+ const restoreResult = await this._restoreNode(parentNode, sourceTile, transformationMatrix);
434
+ let childNodes;
435
+ if (restoreResult === null) {
436
+ childNodes = await this._createNode(parentNode, sourceTile, transformationMatrix);
437
+ } else {
438
+ childNodes = restoreResult;
439
+ }
410
440
  await parentNode.addChildren(childNodes);
411
441
  const newTraversalProps = {
412
442
  transform: transformationMatrix,
@@ -435,6 +465,57 @@ export default class I3SConverter {
435
465
  await node.save();
436
466
  }
437
467
  }
468
+ async _generateNodeIndexDocument(boundingVolumes, resources, parentNode, sourceTile, isDumped) {
469
+ this.layersHasTexture = this.layersHasTexture || Boolean('texture' in resources && resources.texture || 'texelCountHint' in resources && resources.texelCountHint);
470
+ if (this.generateBoundingVolumes && resources.boundingVolumes) {
471
+ boundingVolumes = resources.boundingVolumes;
472
+ }
473
+ const lodSelection = convertGeometricErrorToScreenThreshold(sourceTile, boundingVolumes);
474
+ const maxScreenThresholdSQ = lodSelection.find(val => val.metricType === 'maxScreenThresholdSQ') || {
475
+ maxError: 0
476
+ };
477
+ if (isDumped) {
478
+ const draftObb = {
479
+ center: [],
480
+ halfSize: [],
481
+ quaternion: []
482
+ };
483
+ await this.nodePages.push({
484
+ index: 0,
485
+ obb: draftObb
486
+ }, parentNode.inPageId);
487
+ }
488
+ const nodeInPage = await this._updateNodeInNodePages(maxScreenThresholdSQ, boundingVolumes, sourceTile, parentNode.inPageId, resources);
489
+ const nodeData = await NodeIndexDocument.createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources);
490
+ const node = await new NodeIndexDocument(nodeInPage.index, this).addData(nodeData);
491
+ return {
492
+ node,
493
+ nodeInPage,
494
+ nodeData
495
+ };
496
+ }
497
+ async _restoreNode(parentNode, sourceTile, transformationMatrix) {
498
+ this._checkAddRefinementTypeForTile(sourceTile);
499
+ await this._updateTilesetOptions();
500
+ if (this.conversionDump.restored && sourceTile.id && this.conversionDump.isFileConversionComplete(sourceTile.id)) {
501
+ const sourceBoundingVolume = createBoundingVolume(sourceTile.boundingVolume, transformationMatrix, null);
502
+ let boundingVolumes = createBoundingVolumes(sourceBoundingVolume, this.geoidHeightModel);
503
+ const nodes = [];
504
+ for (const convertedNode of this.conversionDump.tilesConverted[sourceTile.id].nodes) {
505
+ const {
506
+ node
507
+ } = await this._generateNodeIndexDocument(boundingVolumes, {
508
+ ...convertedNode.dumpMetadata,
509
+ nodeId: convertedNode.nodeId
510
+ }, parentNode, sourceTile, true);
511
+ nodes.push(node);
512
+ }
513
+ return nodes;
514
+ } else if (this.conversionDump.restored && sourceTile.id) {
515
+ this.conversionDump.clearDumpRecord(sourceTile.id);
516
+ }
517
+ return null;
518
+ }
438
519
  async _createNode(parentNode, sourceTile, transformationMatrix) {
439
520
  this._checkAddRefinementTypeForTile(sourceTile);
440
521
  await this._updateTilesetOptions();
@@ -448,6 +529,11 @@ export default class I3SConverter {
448
529
  let boundingVolumes = createBoundingVolumes(sourceBoundingVolume, this.geoidHeightModel);
449
530
  const propertyTable = getPropertyTable(tileContent, this.options.metadataClass);
450
531
  this.createAttributeStorageInfo(tileContent, propertyTable);
532
+ this.conversionDump.attributeMetadataInfo = {
533
+ attributeStorageInfo: this.attributeMetadataInfo.attributeStorageInfo,
534
+ fields: this.attributeMetadataInfo.fields,
535
+ popupInfo: this.attributeMetadataInfo.popupInfo
536
+ };
451
537
  const resourcesData = await this._convertResources(sourceTile, transformationMatrix, sourceBoundingVolume, tileContent, parentNode.inPageId, propertyTable);
452
538
  const nodes = [];
453
539
  const nodeIds = [];
@@ -465,21 +551,27 @@ export default class I3SConverter {
465
551
  boundingVolumes: null
466
552
  };
467
553
  for (const resources of resourcesData || [emptyResources]) {
468
- this.layersHasTexture = this.layersHasTexture || Boolean(resources.texture);
469
- if (this.generateBoundingVolumes && resources.boundingVolumes) {
470
- boundingVolumes = resources.boundingVolumes;
471
- }
472
- const lodSelection = convertGeometricErrorToScreenThreshold(sourceTile, boundingVolumes);
473
- const maxScreenThresholdSQ = lodSelection.find(val => val.metricType === 'maxScreenThresholdSQ') || {
474
- maxError: 0
475
- };
476
- const nodeInPage = await this._updateNodeInNodePages(maxScreenThresholdSQ, boundingVolumes, sourceTile, parentNode.inPageId, resources);
477
- const nodeData = await NodeIndexDocument.createNodeIndexDocument(parentNode, boundingVolumes, lodSelection, nodeInPage, resources);
478
- const node = await new NodeIndexDocument(nodeInPage.index, this).addData(nodeData);
554
+ const {
555
+ node,
556
+ nodeInPage,
557
+ nodeData
558
+ } = await this._generateNodeIndexDocument(boundingVolumes, resources, parentNode, sourceTile, false);
479
559
  nodes.push(node);
480
560
  if (nodeInPage.mesh) {
481
561
  if (sourceTile.id) {
482
- await this.conversionDump.addNode(sourceTile.id, nodeInPage.index);
562
+ var _resources$attributes;
563
+ const dumpMetadata = {
564
+ boundingVolumes: resources.boundingVolumes,
565
+ attributesCount: (_resources$attributes = resources.attributes) === null || _resources$attributes === void 0 ? void 0 : _resources$attributes.length,
566
+ featureCount: resources.featureCount,
567
+ geometry: Boolean(resources.geometry),
568
+ hasUvRegions: resources.hasUvRegions,
569
+ materialId: nodeInPage.mesh.material.definition,
570
+ texelCountHint: nodeInPage.mesh.material.texelCountHint,
571
+ vertexCount: resources.vertexCount
572
+ };
573
+ this.conversionDump.setMaterialsDefinitions(this.materialDefinitions);
574
+ await this.conversionDump.addNode(sourceTile.id, nodeInPage.index, dumpMetadata);
483
575
  }
484
576
  await this._writeResources(resources, node.id, sourceTile);
485
577
  }
@@ -511,8 +603,6 @@ export default class I3SConverter {
511
603
  }
512
604
  async _updateNodeInNodePages(maxScreenThresholdSQ, boundingVolumes, sourceTile, parentId, resources) {
513
605
  const {
514
- meshMaterial,
515
- texture,
516
606
  vertexCount,
517
607
  featureCount,
518
608
  geometry,
@@ -527,7 +617,7 @@ export default class I3SConverter {
527
617
  if (geometry && this.isContentSupported(sourceTile)) {
528
618
  nodeInPage.mesh = {
529
619
  geometry: {
530
- definition: this.findOrCreateGeometryDefinition(Boolean(texture), hasUvRegions),
620
+ definition: this.findOrCreateGeometryDefinition(Boolean('texture' in resources && resources.texture || 'texelCountHint' in resources && resources.texelCountHint), hasUvRegions),
531
621
  resource: 0
532
622
  },
533
623
  attribute: {
@@ -538,7 +628,7 @@ export default class I3SConverter {
538
628
  }
539
629
  };
540
630
  }
541
- let nodeId = resources.nodeId;
631
+ let nodeId = 'nodeId' in resources ? resources.nodeId : undefined;
542
632
  let node;
543
633
  if (!nodeId) {
544
634
  node = await this.nodePages.push(nodeInPage, parentId);
@@ -549,12 +639,16 @@ export default class I3SConverter {
549
639
  console.log(`[warning]: node ${node.index} is created with empty content`);
550
640
  }
551
641
  NodePages.updateAll(node, nodeInPage);
552
- if (meshMaterial) {
553
- NodePages.updateMaterialByNodeId(node, this._findOrCreateMaterial(meshMaterial));
642
+ if ('meshMaterial' in resources && resources.meshMaterial) {
643
+ NodePages.updateMaterialByNodeId(node, this._findOrCreateMaterial(resources.meshMaterial));
644
+ } else if ('materialId' in resources && resources.materialId !== null) {
645
+ NodePages.updateMaterialByNodeId(node, resources.materialId);
554
646
  }
555
- if (texture) {
556
- const texelCountHint = texture.image.height * texture.image.width;
647
+ if ('texture' in resources && resources.texture) {
648
+ const texelCountHint = resources.texture.image.height * resources.texture.image.width;
557
649
  NodePages.updateTexelCountHintByNodeId(node, texelCountHint);
650
+ } else if ('texelCountHint' in resources && resources.texelCountHint) {
651
+ NodePages.updateTexelCountHintByNodeId(node, resources.texelCountHint);
558
652
  }
559
653
  if (vertexCount) {
560
654
  this.vertexCounter += vertexCount;
@@ -717,6 +811,9 @@ export default class I3SConverter {
717
811
  formats,
718
812
  atlas: true
719
813
  });
814
+ if (this.layers0.textureSetDefinitions) {
815
+ this.conversionDump.addTexturesDefinitions(this.layers0.textureSetDefinitions);
816
+ }
720
817
  }
721
818
  }
722
819
  }