@loaders.gl/tile-converter 3.2.7 → 3.3.0-alpha.3

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 (77) hide show
  1. package/dist/3d-tiles-attributes-worker.js +3 -3
  2. package/dist/3d-tiles-attributes-worker.js.map +1 -1
  3. package/dist/converter-cli.js +30 -7
  4. package/dist/converter.min.js +1 -1
  5. package/dist/dist.min.js +1105 -621
  6. package/dist/es5/3d-tiles-attributes-worker.js +1 -1
  7. package/dist/es5/3d-tiles-attributes-worker.js.map +1 -1
  8. package/dist/es5/converter-cli.js +42 -12
  9. package/dist/es5/converter-cli.js.map +1 -1
  10. package/dist/es5/i3s-attributes-worker.js +1 -1
  11. package/dist/es5/i3s-attributes-worker.js.map +1 -1
  12. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js +146 -0
  13. package/dist/es5/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  14. package/dist/es5/i3s-converter/helpers/feature-attributes.js +60 -0
  15. package/dist/es5/i3s-converter/helpers/feature-attributes.js.map +1 -0
  16. package/dist/es5/i3s-converter/helpers/geometry-attributes.js +39 -7
  17. package/dist/es5/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  18. package/dist/es5/i3s-converter/helpers/geometry-converter.js +177 -59
  19. package/dist/es5/i3s-converter/helpers/geometry-converter.js.map +1 -1
  20. package/dist/es5/i3s-converter/helpers/gltf-attributes.js +15 -1
  21. package/dist/es5/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  22. package/dist/es5/i3s-converter/i3s-converter.js +50 -51
  23. package/dist/es5/i3s-converter/i3s-converter.js.map +1 -1
  24. package/dist/es5/lib/utils/write-queue.js +3 -5
  25. package/dist/es5/lib/utils/write-queue.js.map +1 -1
  26. package/dist/es5/pgm-loader.js +1 -1
  27. package/dist/es5/pgm-loader.js.map +1 -1
  28. package/dist/esm/3d-tiles-attributes-worker.js +1 -1
  29. package/dist/esm/3d-tiles-attributes-worker.js.map +1 -1
  30. package/dist/esm/converter-cli.js +37 -7
  31. package/dist/esm/converter-cli.js.map +1 -1
  32. package/dist/esm/i3s-attributes-worker.js +1 -1
  33. package/dist/esm/i3s-attributes-worker.js.map +1 -1
  34. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js +128 -0
  35. package/dist/esm/i3s-converter/helpers/batch-ids-extensions.js.map +1 -0
  36. package/dist/esm/i3s-converter/helpers/feature-attributes.js +34 -0
  37. package/dist/esm/i3s-converter/helpers/feature-attributes.js.map +1 -0
  38. package/dist/esm/i3s-converter/helpers/geometry-attributes.js +23 -7
  39. package/dist/esm/i3s-converter/helpers/geometry-attributes.js.map +1 -1
  40. package/dist/esm/i3s-converter/helpers/geometry-converter.js +145 -38
  41. package/dist/esm/i3s-converter/helpers/geometry-converter.js.map +1 -1
  42. package/dist/esm/i3s-converter/helpers/gltf-attributes.js +15 -1
  43. package/dist/esm/i3s-converter/helpers/gltf-attributes.js.map +1 -1
  44. package/dist/esm/i3s-converter/i3s-converter.js +21 -27
  45. package/dist/esm/i3s-converter/i3s-converter.js.map +1 -1
  46. package/dist/esm/lib/utils/write-queue.js +3 -5
  47. package/dist/esm/lib/utils/write-queue.js.map +1 -1
  48. package/dist/esm/pgm-loader.js +1 -1
  49. package/dist/esm/pgm-loader.js.map +1 -1
  50. package/dist/i3s-attributes-worker.js +3 -3
  51. package/dist/i3s-attributes-worker.js.map +3 -3
  52. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts +12 -0
  53. package/dist/i3s-converter/helpers/batch-ids-extensions.d.ts.map +1 -0
  54. package/dist/i3s-converter/helpers/batch-ids-extensions.js +138 -0
  55. package/dist/i3s-converter/helpers/feature-attributes.d.ts +24 -0
  56. package/dist/i3s-converter/helpers/feature-attributes.d.ts.map +1 -0
  57. package/dist/i3s-converter/helpers/feature-attributes.js +55 -0
  58. package/dist/i3s-converter/helpers/geometry-attributes.js +26 -7
  59. package/dist/i3s-converter/helpers/geometry-converter.d.ts +9 -2
  60. package/dist/i3s-converter/helpers/geometry-converter.d.ts.map +1 -1
  61. package/dist/i3s-converter/helpers/geometry-converter.js +140 -44
  62. package/dist/i3s-converter/helpers/gltf-attributes.d.ts.map +1 -1
  63. package/dist/i3s-converter/helpers/gltf-attributes.js +13 -0
  64. package/dist/i3s-converter/i3s-converter.d.ts +7 -14
  65. package/dist/i3s-converter/i3s-converter.d.ts.map +1 -1
  66. package/dist/i3s-converter/i3s-converter.js +44 -35
  67. package/dist/lib/utils/write-queue.d.ts.map +1 -1
  68. package/dist/lib/utils/write-queue.js +3 -4
  69. package/package.json +15 -15
  70. package/src/converter-cli.ts +33 -7
  71. package/src/i3s-converter/helpers/batch-ids-extensions.ts +199 -0
  72. package/src/i3s-converter/helpers/feature-attributes.ts +65 -0
  73. package/src/i3s-converter/helpers/geometry-attributes.ts +30 -7
  74. package/src/i3s-converter/helpers/geometry-converter.ts +187 -48
  75. package/src/i3s-converter/helpers/gltf-attributes.ts +15 -0
  76. package/src/i3s-converter/i3s-converter.ts +38 -41
  77. package/src/lib/utils/write-queue.ts +7 -5
@@ -7,6 +7,8 @@ import md5 from 'md5';
7
7
  import { generateAttributes } from './geometry-attributes';
8
8
  import { createBoundingVolumesFromGeometry } from './coordinate-converter';
9
9
  import { prepareDataForAttributesConversion } from './gltf-attributes';
10
+ import { handleBatchIdsExtensions } from './batch-ids-extensions';
11
+ import { checkPropertiesLength, flattenPropertyTableByFeatureIds } from './feature-attributes';
10
12
  const DEFAULT_ROUGHNESS_FACTOR = 1;
11
13
  const DEFAULT_METALLIC_FACTOR = 1;
12
14
  const VALUES_PER_VERTEX = 3;
@@ -17,8 +19,10 @@ const SHORT_INT_TYPE = 'Int32';
17
19
  const DOUBLE_TYPE = 'Float64';
18
20
  const OBJECT_ID_TYPE = 'Oid32';
19
21
  const BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES = ['CUSTOM_ATTRIBUTE_2', '_BATCHID', 'BATCHID'];
22
+ const EXT_FEATURE_METADATA = 'EXT_feature_metadata';
23
+ const EXT_MESH_FEATURES = 'EXT_mesh_features';
20
24
  let scratchVector = new Vector3();
21
- export default async function convertB3dmToI3sGeometry(tileContent, nodeId, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel, workerSource) {
25
+ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, propertyTable, featuresHashArray, attributeStorageInfo, draco, generateBoundingVolumes, geoidHeightModel, workerSource) {
22
26
  var _tileContent$gltf;
23
27
 
24
28
  const useCartesianPositions = generateBoundingVolumes;
@@ -74,6 +78,7 @@ export default async function convertB3dmToI3sGeometry(tileContent, nodeId, feat
74
78
  tileContent,
75
79
  nodeId: nodesCounter,
76
80
  featuresHashArray,
81
+ propertyTable,
77
82
  attributeStorageInfo,
78
83
  draco,
79
84
  workerSource
@@ -111,6 +116,7 @@ async function _makeNodeResources({
111
116
  tileContent,
112
117
  nodeId,
113
118
  featuresHashArray,
119
+ propertyTable,
114
120
  attributeStorageInfo,
115
121
  draco,
116
122
  workerSource
@@ -145,7 +151,12 @@ async function _makeNodeResources({
145
151
  featureIds,
146
152
  faceRange
147
153
  }, workerSource.draco) : null;
148
- const attributes = convertBatchTableToAttributeBuffers(tileContent.batchTableJson, featureIds, attributeStorageInfo);
154
+ let attributes = [];
155
+
156
+ if (attributeStorageInfo && propertyTable) {
157
+ attributes = convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo);
158
+ }
159
+
149
160
  return {
150
161
  geometry: fileBuffer,
151
162
  compressedGeometry,
@@ -244,15 +255,16 @@ function getCompositeTransformationMatrix(node, matrix) {
244
255
  function convertNode(node, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
245
256
  const transformationMatrix = getCompositeTransformationMatrix(node, matrix);
246
257
  const mesh = node.mesh;
258
+ const images = node.images;
247
259
 
248
260
  if (mesh) {
249
- convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
261
+ convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
250
262
  }
251
263
 
252
264
  convertNodes(node.children || [], cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions, transformationMatrix);
253
265
  }
254
266
 
255
- function convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions = false, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
267
+ function convertMesh(mesh, images, cartographicOrigin, cartesianModelMatrix, attributesMap, useCartesianPositions = false, matrix = new Matrix4([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])) {
256
268
  for (const primitive of mesh.primitives) {
257
269
  var _primitive$indices, _primitive$indices2, _primitive$indices3, _primitive$indices4, _primitive$indices5;
258
270
 
@@ -292,7 +304,7 @@ function convertMesh(mesh, cartographicOrigin, cartesianModelMatrix, attributesM
292
304
  outputAttributes.texCoords = concatenateTypedArrays(outputAttributes.texCoords, flattenTexCoords(attributes.TEXCOORD_0 && attributes.TEXCOORD_0.value, (_primitive$indices3 = primitive.indices) === null || _primitive$indices3 === void 0 ? void 0 : _primitive$indices3.value));
293
305
  outputAttributes.colors = concatenateTypedArrays(outputAttributes.colors, flattenColors(attributes.COLOR_0, (_primitive$indices4 = primitive.indices) === null || _primitive$indices4 === void 0 ? void 0 : _primitive$indices4.value));
294
306
  outputAttributes.featureIndicesGroups = outputAttributes.featureIndicesGroups || [];
295
- outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIdsByAttributeName(attributes), (_primitive$indices5 = primitive.indices) === null || _primitive$indices5 === void 0 ? void 0 : _primitive$indices5.value));
307
+ outputAttributes.featureIndicesGroups.push(flattenBatchIds(getBatchIds(attributes, primitive, images), (_primitive$indices5 = primitive.indices) === null || _primitive$indices5 === void 0 ? void 0 : _primitive$indices5.value));
296
308
  }
297
309
  }
298
310
 
@@ -417,19 +429,22 @@ function flattenBatchIds(batchedIds, indices) {
417
429
  return newBatchIds;
418
430
  }
419
431
 
420
- function getBatchIdsByAttributeName(attributes) {
421
- let batchIds = [];
432
+ function getBatchIds(attributes, primitive, images) {
433
+ const batchIds = handleBatchIdsExtensions(attributes, primitive, images);
434
+
435
+ if (batchIds.length) {
436
+ return batchIds;
437
+ }
422
438
 
423
439
  for (let index = 0; index < BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES.length; index++) {
424
440
  const possibleBatchIdAttributeName = BATCHED_ID_POSSIBLE_ATTRIBUTE_NAMES[index];
425
441
 
426
442
  if (attributes[possibleBatchIdAttributeName] && attributes[possibleBatchIdAttributeName].value) {
427
- batchIds = attributes[possibleBatchIdAttributeName].value;
428
- break;
443
+ return attributes[possibleBatchIdAttributeName].value;
429
444
  }
430
445
  }
431
446
 
432
- return batchIds;
447
+ return [];
433
448
  }
434
449
 
435
450
  function convertMaterials(sourceMaterials = []) {
@@ -657,44 +672,47 @@ function replaceIndicesByUnique(indicesArray, featureMap) {
657
672
  }
658
673
  }
659
674
 
660
- function convertBatchTableToAttributeBuffers(batchTable, featureIds, attributeStorageInfo) {
675
+ function convertPropertyTableToAttributeBuffers(featureIds, propertyTable, attributeStorageInfo) {
661
676
  const attributeBuffers = [];
677
+ const needFlattenPropertyTable = checkPropertiesLength(featureIds, propertyTable);
678
+ const properties = needFlattenPropertyTable ? flattenPropertyTableByFeatureIds(featureIds, propertyTable) : propertyTable;
679
+ const propertyTableWithObjectIds = {
680
+ OBJECTID: featureIds,
681
+ ...properties
682
+ };
662
683
 
663
- if (batchTable) {
664
- const batchTableWithFeatureIds = {
665
- OBJECTID: featureIds,
666
- ...batchTable
667
- };
684
+ for (const propertyName in propertyTableWithObjectIds) {
685
+ const type = getAttributeType(propertyName, attributeStorageInfo);
686
+ const value = propertyTableWithObjectIds[propertyName];
687
+ const attributeBuffer = generateAttributeBuffer(type, value);
688
+ attributeBuffers.push(attributeBuffer);
689
+ }
668
690
 
669
- for (const key in batchTableWithFeatureIds) {
670
- const type = getAttributeType(key, attributeStorageInfo);
671
- let attributeBuffer = null;
691
+ return attributeBuffers;
692
+ }
672
693
 
673
- switch (type) {
674
- case OBJECT_ID_TYPE:
675
- case SHORT_INT_TYPE:
676
- attributeBuffer = generateShortIntegerAttributeBuffer(batchTableWithFeatureIds[key]);
677
- break;
694
+ function generateAttributeBuffer(type, value) {
695
+ let attributeBuffer;
678
696
 
679
- case DOUBLE_TYPE:
680
- attributeBuffer = generateDoubleAttributeBuffer(batchTableWithFeatureIds[key]);
681
- break;
697
+ switch (type) {
698
+ case OBJECT_ID_TYPE:
699
+ case SHORT_INT_TYPE:
700
+ attributeBuffer = generateShortIntegerAttributeBuffer(value);
701
+ break;
682
702
 
683
- case STRING_TYPE:
684
- attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
685
- break;
703
+ case DOUBLE_TYPE:
704
+ attributeBuffer = generateDoubleAttributeBuffer(value);
705
+ break;
686
706
 
687
- default:
688
- attributeBuffer = generateStringAttributeBuffer(batchTableWithFeatureIds[key]);
689
- }
707
+ case STRING_TYPE:
708
+ attributeBuffer = generateStringAttributeBuffer(value);
709
+ break;
690
710
 
691
- if (attributeBuffer) {
692
- attributeBuffers.push(attributeBuffer);
693
- }
694
- }
711
+ default:
712
+ attributeBuffer = generateStringAttributeBuffer(value);
695
713
  }
696
714
 
697
- return attributeBuffers;
715
+ return attributeBuffer;
698
716
  }
699
717
 
700
718
  function getAttributeType(key, attributeStorageInfo) {
@@ -806,4 +824,93 @@ function generateFeatureIndexAttribute(featureIndex, faceRange) {
806
824
 
807
825
  return orderedFeatureIndices;
808
826
  }
827
+
828
+ export function getPropertyTable(sourceTile) {
829
+ var _sourceTile$content;
830
+
831
+ const batchTableJson = sourceTile === null || sourceTile === void 0 ? void 0 : (_sourceTile$content = sourceTile.content) === null || _sourceTile$content === void 0 ? void 0 : _sourceTile$content.batchTableJson;
832
+
833
+ if (batchTableJson) {
834
+ return batchTableJson;
835
+ }
836
+
837
+ const {
838
+ extensionName,
839
+ extension
840
+ } = getPropertyTableExtension(sourceTile);
841
+
842
+ switch (extensionName) {
843
+ case EXT_MESH_FEATURES:
844
+ {
845
+ console.warn('The I3S converter does not yet support the EXT_mesh_features extension');
846
+ return null;
847
+ }
848
+
849
+ case EXT_FEATURE_METADATA:
850
+ {
851
+ return getPropertyTableFromExtFeatureMetadata(extension);
852
+ }
853
+
854
+ default:
855
+ return null;
856
+ }
857
+ }
858
+
859
+ function getPropertyTableExtension(sourceTile) {
860
+ var _sourceTile$content2, _sourceTile$content2$, _sourceTile$content4, _sourceTile$content4$, _sourceTile$content4$2;
861
+
862
+ const extensionsWithPropertyTables = [EXT_FEATURE_METADATA, EXT_MESH_FEATURES];
863
+ const extensionsUsed = sourceTile === null || sourceTile === void 0 ? void 0 : (_sourceTile$content2 = sourceTile.content) === null || _sourceTile$content2 === void 0 ? void 0 : (_sourceTile$content2$ = _sourceTile$content2.gltf) === null || _sourceTile$content2$ === void 0 ? void 0 : _sourceTile$content2$.extensionsUsed;
864
+
865
+ if (!extensionsUsed) {
866
+ return {
867
+ extensionName: null,
868
+ extension: null
869
+ };
870
+ }
871
+
872
+ let extensionName = '';
873
+
874
+ for (const extensionItem of sourceTile === null || sourceTile === void 0 ? void 0 : (_sourceTile$content3 = sourceTile.content) === null || _sourceTile$content3 === void 0 ? void 0 : (_sourceTile$content3$ = _sourceTile$content3.gltf) === null || _sourceTile$content3$ === void 0 ? void 0 : _sourceTile$content3$.extensionsUsed) {
875
+ var _sourceTile$content3, _sourceTile$content3$;
876
+
877
+ if (extensionsWithPropertyTables.includes(extensionItem)) {
878
+ extensionName = extensionItem;
879
+ break;
880
+ }
881
+ }
882
+
883
+ const extension = sourceTile === null || sourceTile === void 0 ? void 0 : (_sourceTile$content4 = sourceTile.content) === null || _sourceTile$content4 === void 0 ? void 0 : (_sourceTile$content4$ = _sourceTile$content4.gltf) === null || _sourceTile$content4$ === void 0 ? void 0 : (_sourceTile$content4$2 = _sourceTile$content4$.extensions) === null || _sourceTile$content4$2 === void 0 ? void 0 : _sourceTile$content4$2[extensionName];
884
+ return {
885
+ extensionName,
886
+ extension
887
+ };
888
+ }
889
+
890
+ function getPropertyTableFromExtFeatureMetadata(extension) {
891
+ if (extension !== null && extension !== void 0 && extension.featureTextures) {
892
+ console.warn('The I3S converter does not yet support the EXT_feature_metadata feature textures');
893
+ return null;
894
+ }
895
+
896
+ if (extension !== null && extension !== void 0 && extension.featureTables) {
897
+ var _Object$keys;
898
+
899
+ const firstFeatureTableName = (_Object$keys = Object.keys(extension.featureTables)) === null || _Object$keys === void 0 ? void 0 : _Object$keys[0];
900
+
901
+ if (firstFeatureTableName) {
902
+ const featureTable = extension === null || extension === void 0 ? void 0 : extension.featureTables[firstFeatureTableName];
903
+ const propertyTable = {};
904
+
905
+ for (const propertyName in featureTable.properties) {
906
+ propertyTable[propertyName] = featureTable.properties[propertyName].data;
907
+ }
908
+
909
+ return propertyTable;
910
+ }
911
+ }
912
+
913
+ console.warn("The I3S converter couldn't handle EXT_feature_metadata extension");
914
+ return null;
915
+ }
809
916
  //# sourceMappingURL=geometry-converter.js.map